コード例 #1
0
static void
update_connection (NMDevice *device, NMConnection *connection)
{
	NMDeviceIPTunnel *self = NM_DEVICE_IP_TUNNEL (device);
	NMDeviceIPTunnelPrivate *priv = NM_DEVICE_IP_TUNNEL_GET_PRIVATE (self);
	NMSettingIPTunnel *s_ip_tunnel = nm_connection_get_setting_ip_tunnel (connection);
	NMDevice *parent = NULL;
	const char *setting_parent, *new_parent;

	if (!s_ip_tunnel) {
		s_ip_tunnel = (NMSettingIPTunnel *) nm_setting_ip_tunnel_new ();
		nm_connection_add_setting (connection, (NMSetting *) s_ip_tunnel);
	}

	if (nm_setting_ip_tunnel_get_mode (s_ip_tunnel) != priv->mode)
		g_object_set (G_OBJECT (s_ip_tunnel), NM_SETTING_IP_TUNNEL_MODE, priv->mode, NULL);

	if (priv->parent_ifindex > 0)
		parent = nm_manager_get_device_by_ifindex (nm_manager_get (), priv->parent_ifindex);

	/* Update parent in the connection; default to parent's interface name */
	if (parent) {
		new_parent = nm_device_get_iface (parent);
		setting_parent = nm_setting_ip_tunnel_get_parent (s_ip_tunnel);
		if (setting_parent && nm_utils_is_uuid (setting_parent)) {
			NMConnection *parent_connection;

			/* Don't change a parent specified by UUID if it's still valid */
			parent_connection = nm_connection_provider_get_connection_by_uuid (nm_connection_provider_get (),
			                                                                   setting_parent);
			if (parent_connection && nm_device_check_connection_compatible (parent, parent_connection))
				new_parent = NULL;
		}
		if (new_parent)
			g_object_set (s_ip_tunnel, NM_SETTING_IP_TUNNEL_PARENT, new_parent, NULL);
	} else
		g_object_set (s_ip_tunnel, NM_SETTING_IP_TUNNEL_PARENT, NULL, NULL);

	if (!address_equal_pp (priv->addr_family,
	                       nm_setting_ip_tunnel_get_local (s_ip_tunnel),
	                       priv->local))
		g_object_set (G_OBJECT (s_ip_tunnel), NM_SETTING_IP_TUNNEL_LOCAL, priv->local, NULL);

	if (!address_equal_pp (priv->addr_family,
	                       nm_setting_ip_tunnel_get_remote (s_ip_tunnel),
	                       priv->remote))
		g_object_set (G_OBJECT (s_ip_tunnel), NM_SETTING_IP_TUNNEL_REMOTE, priv->remote, NULL);

	if (nm_setting_ip_tunnel_get_ttl (s_ip_tunnel) != priv->ttl)
		g_object_set (G_OBJECT (s_ip_tunnel), NM_SETTING_IP_TUNNEL_TTL, priv->ttl, NULL);

	if (nm_setting_ip_tunnel_get_tos (s_ip_tunnel) != priv->tos)
		g_object_set (G_OBJECT (s_ip_tunnel), NM_SETTING_IP_TUNNEL_TOS, priv->tos, NULL);

	if (nm_setting_ip_tunnel_get_path_mtu_discovery (s_ip_tunnel) != priv->path_mtu_discovery) {
		g_object_set (G_OBJECT (s_ip_tunnel),
		              NM_SETTING_IP_TUNNEL_PATH_MTU_DISCOVERY,
		              priv->path_mtu_discovery,
		              NULL);
	}

	if (nm_setting_ip_tunnel_get_encapsulation_limit (s_ip_tunnel) != priv->encap_limit) {
		g_object_set (G_OBJECT (s_ip_tunnel),
		                        NM_SETTING_IP_TUNNEL_ENCAPSULATION_LIMIT,
		                        priv->encap_limit,
		                        NULL);
	}

	if (nm_setting_ip_tunnel_get_flow_label (s_ip_tunnel) != priv->flow_label) {
		g_object_set (G_OBJECT (s_ip_tunnel),
		                        NM_SETTING_IP_TUNNEL_FLOW_LABEL,
		                        priv->flow_label,
		                        NULL);
	}

	if (priv->mode == NM_IP_TUNNEL_MODE_GRE || priv->mode == NM_IP_TUNNEL_MODE_IP6GRE) {
		if (g_strcmp0 (nm_setting_ip_tunnel_get_input_key (s_ip_tunnel), priv->input_key)) {
			g_object_set (G_OBJECT (s_ip_tunnel),
			              NM_SETTING_IP_TUNNEL_INPUT_KEY,
			              priv->input_key,
			              NULL);
		}
		if (g_strcmp0 (nm_setting_ip_tunnel_get_output_key (s_ip_tunnel), priv->output_key)) {
			g_object_set (G_OBJECT (s_ip_tunnel),
			              NM_SETTING_IP_TUNNEL_OUTPUT_KEY,
			              priv->output_key,
			              NULL);
		}
	}
}
コード例 #2
0
static void
nmt_page_ip_tunnel_constructed (GObject *object)
{
	NmtPageIPTunnel *ip_tunnel = NMT_PAGE_IP_TUNNEL (object);
	NmtPageIPTunnelPrivate *priv = NMT_PAGE_IP_TUNNEL_GET_PRIVATE (ip_tunnel);
	NmtEditorSection *section;
	NmtEditorGrid *grid;
	NMSettingIPTunnel *s_ip_tunnel;
	NmtNewtWidget *widget, *parent;
	NMConnection *conn;
	GClosure *s2w, *w2s;

	conn = nmt_editor_page_get_connection (NMT_EDITOR_PAGE (ip_tunnel));
	s_ip_tunnel = nm_connection_get_setting_ip_tunnel (conn);
	if (!s_ip_tunnel) {
		nm_connection_add_setting (conn, nm_setting_ip_tunnel_new ());
		s_ip_tunnel = nm_connection_get_setting_ip_tunnel (conn);
	}

	/* Initialize the mode for new connections */
	if (nm_setting_ip_tunnel_get_mode (s_ip_tunnel) == NM_IP_TUNNEL_MODE_UNKNOWN) {
		g_object_set (s_ip_tunnel,
		              NM_SETTING_IP_TUNNEL_MODE, (guint) NM_IP_TUNNEL_MODE_IPIP,
		              NULL);
	}

	section = nmt_editor_section_new (_("IP tunnel"), NULL, TRUE);
	grid = nmt_editor_section_get_body (section);

	/* To convert between widget index (0-based) and setting index (1-based) */
	s2w = g_cclosure_new (G_CALLBACK (add_offset), GINT_TO_POINTER (-1), NULL);
	w2s = g_cclosure_new (G_CALLBACK (add_offset), GINT_TO_POINTER (1), NULL);

	widget = nmt_newt_popup_new (tunnel_mode);
	g_object_bind_property_with_closures (s_ip_tunnel, NM_SETTING_IP_TUNNEL_MODE,
	                        widget, "active",
	                        G_BINDING_BIDIRECTIONAL | G_BINDING_SYNC_CREATE,
	                        s2w, w2s);
	nmt_editor_grid_append (grid, _("Mode"), widget, NULL);

	widget = parent = nmt_device_entry_new (_("Parent"), 40, G_TYPE_NONE);
	g_object_bind_property (s_ip_tunnel, NM_SETTING_IP_TUNNEL_PARENT,
	                        widget, "interface-name",
	                        G_BINDING_BIDIRECTIONAL | G_BINDING_SYNC_CREATE);
	nmt_editor_grid_append (grid, NULL, widget, NULL);

	widget = nmt_newt_entry_new (40, 0);
	nmt_editor_grid_append (grid, _("Local IP"), widget, NULL);
	g_object_bind_property (s_ip_tunnel, NM_SETTING_IP_TUNNEL_LOCAL,
	                        widget, "text",
	                        G_BINDING_SYNC_CREATE | G_BINDING_BIDIRECTIONAL);

	widget = nmt_newt_entry_new (40, 0);
	nmt_editor_grid_append (grid, _("Remote IP"), widget, NULL);
	g_object_bind_property (s_ip_tunnel, NM_SETTING_IP_TUNNEL_REMOTE,
	                        widget, "text",
	                        G_BINDING_SYNC_CREATE | G_BINDING_BIDIRECTIONAL);

	widget = nmt_newt_entry_new (40, 0);
	nmt_editor_grid_append (grid, _("Input key"), widget, NULL);
	g_object_bind_property (s_ip_tunnel, NM_SETTING_IP_TUNNEL_INPUT_KEY,
	                        widget, "text",
	                        G_BINDING_SYNC_CREATE | G_BINDING_BIDIRECTIONAL);
	priv->input_key = NMT_NEWT_ENTRY (widget);

	widget = nmt_newt_entry_new (40, 0);
	nmt_editor_grid_append (grid, _("Output key"), widget, NULL);
	g_object_bind_property (s_ip_tunnel, NM_SETTING_IP_TUNNEL_OUTPUT_KEY,
	                        widget, "text",
	                        G_BINDING_SYNC_CREATE | G_BINDING_BIDIRECTIONAL);
	priv->output_key = NMT_NEWT_ENTRY (widget);

	widget = nmt_mtu_entry_new ();
	g_object_bind_property (s_ip_tunnel, NM_SETTING_IP_TUNNEL_MTU,
	                        widget, "mtu",
	                        G_BINDING_BIDIRECTIONAL | G_BINDING_SYNC_CREATE);
	nmt_editor_grid_append (grid, _("MTU"), widget, NULL);

	g_signal_connect (s_ip_tunnel, "notify::" NM_SETTING_IP_TUNNEL_MODE,
	                  G_CALLBACK (mode_changed), ip_tunnel);
	mode_changed (G_OBJECT (s_ip_tunnel), NULL, ip_tunnel);

	nmt_editor_page_add_section (NMT_EDITOR_PAGE (ip_tunnel), section);

	G_OBJECT_CLASS (nmt_page_ip_tunnel_parent_class)->constructed (object);
}