network: Add option for connection sharing

Introduce a new IP{4,6} config method to allow sharing the default
network (usually the Internet) through the wired interface.
This is needed because the control-panel is lacking this feature backed
by nm and currently the only way to enable the connection sharing is by
using nm-connection-editor.
This commit is contained in:
Carlo Caione 2018-07-11 19:36:54 +01:00 committed by Robert Ancell
parent 408f2775ec
commit dfb54d0cad
4 changed files with 57 additions and 3 deletions

View file

@ -53,6 +53,7 @@ struct _CEPageIP4
GtkBox *routes_box;
GtkSizeGroup *routes_metric_sizegroup;
GtkSizeGroup *routes_sizegroup;
GtkRadioButton *shared_radio;
NMSettingIPConfig *setting;
@ -85,7 +86,8 @@ method_changed (CEPageIP4 *self)
gboolean dns_enabled;
gboolean routes_enabled;
if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (self->disabled_radio))) {
if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (self->disabled_radio)) ||
gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (self->shared_radio))) {
addr_enabled = FALSE;
dns_enabled = FALSE;
routes_enabled = FALSE;
@ -521,6 +523,11 @@ connect_ip4_page (CEPageIP4 *self)
self->content_box, "sensitive",
G_BINDING_SYNC_CREATE | G_BINDING_INVERT_BOOLEAN);
g_signal_connect_swapped (self->shared_radio, "notify::active", G_CALLBACK (ce_page_changed), self);
g_object_bind_property (self->shared_radio, "active",
self->content_box, "sensitive",
G_BINDING_SYNC_CREATE | G_BINDING_INVERT_BOOLEAN);
method = IP4_METHOD_AUTO;
if (g_strcmp0 (str_method, NM_SETTING_IP4_CONFIG_METHOD_LINK_LOCAL) == 0) {
method = IP4_METHOD_LINK_LOCAL;
@ -551,6 +558,9 @@ connect_ip4_page (CEPageIP4 *self)
case IP4_METHOD_MANUAL:
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (self->manual_radio), TRUE);
break;
case IP4_METHOD_SHARED:
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (self->shared_radio), TRUE);
break;
case IP4_METHOD_DISABLED:
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (self->disabled_radio), TRUE);
break;
@ -612,6 +622,8 @@ ui_to_setting (CEPageIP4 *self)
method = NM_SETTING_IP4_CONFIG_METHOD_LINK_LOCAL;
else if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (self->manual_radio)))
method = NM_SETTING_IP4_CONFIG_METHOD_MANUAL;
else if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (self->shared_radio)))
method = NM_SETTING_IP4_CONFIG_METHOD_SHARED;
addresses = g_ptr_array_new_with_free_func ((GDestroyNotify) nm_ip_address_unref);
if (g_str_equal (method, NM_SETTING_IP4_CONFIG_METHOD_MANUAL))
@ -887,6 +899,7 @@ ce_page_ip4_class_init (CEPageIP4Class *klass)
gtk_widget_class_bind_template_child (widget_class, CEPageIP4, routes_box);
gtk_widget_class_bind_template_child (widget_class, CEPageIP4, routes_metric_sizegroup);
gtk_widget_class_bind_template_child (widget_class, CEPageIP4, routes_sizegroup);
gtk_widget_class_bind_template_child (widget_class, CEPageIP4, shared_radio);
}
static void