static void
update_connection (NMDevice *device, NMConnection *connection)
{
	NMSettingBridge *s_bridge = nm_connection_get_setting_bridge (connection);
	const char *ifname = nm_device_get_iface (device);
	int ifindex = nm_device_get_ifindex (device);
	const Option *option;

	if (!s_bridge) {
		s_bridge = (NMSettingBridge *) nm_setting_bridge_new ();
		nm_connection_add_setting (connection, (NMSetting *) s_bridge);
		g_object_set (s_bridge, NM_SETTING_BRIDGE_INTERFACE_NAME, ifname, NULL);
	}

	for (option = master_options; option->name; option++) {
		gs_free char *str = nm_platform_master_get_option (ifindex, option->sysname);
		int value = strtol (str, NULL, 10);

		/* See comments in set_sysfs_uint() about centiseconds. */
		if (option->user_hz_compensate)
			value /= 100;

		g_object_set (s_bridge, option->name, value, NULL);
	}
}
static void
update_connection (NMDevice *device, NMConnection *connection)
{
	NMDeviceBridge *self = NM_DEVICE_BRIDGE (device);
	NMSettingBridge *s_bridge = nm_connection_get_setting_bridge (connection);
	int ifindex = nm_device_get_ifindex (device);
	const Option *option;

	if (!s_bridge) {
		s_bridge = (NMSettingBridge *) nm_setting_bridge_new ();
		nm_connection_add_setting (connection, (NMSetting *) s_bridge);
	}

	for (option = master_options; option->name; option++) {
		gs_free char *str = nm_platform_sysctl_master_get_option (NM_PLATFORM_GET, ifindex, option->sysname);
		int value;

		if (str) {
			value = strtol (str, NULL, 10);

			/* See comments in set_sysfs_uint() about centiseconds. */
			if (option->user_hz_compensate)
				value /= 100;

			g_object_set (s_bridge, option->name, value, NULL);
		} else
			_LOGW (LOGD_BRIDGE, "failed to read bridge setting '%s'", option->sysname);
	}
}
static gboolean
complete_connection (NMDevice *device,
                     NMConnection *connection,
                     const char *specific_object,
                     const GSList *existing_connections,
                     GError **error)
{
	NMSettingBridge *s_bridge;

	nm_utils_complete_generic (NM_PLATFORM_GET,
	                           connection,
	                           NM_SETTING_BRIDGE_SETTING_NAME,
	                           existing_connections,
	                           NULL,
	                           _("Bridge connection"),
	                           "bridge",
	                           TRUE);

	s_bridge = nm_connection_get_setting_bridge (connection);
	if (!s_bridge) {
		s_bridge = (NMSettingBridge *) nm_setting_bridge_new ();
		nm_connection_add_setting (connection, NM_SETTING (s_bridge));
	}

	return TRUE;
}
static gboolean
complete_connection (NMDevice *device,
                     NMConnection *connection,
                     const char *specific_object,
                     const GSList *existing_connections,
                     GError **error)
{
	NMSettingBridge *s_bridge, *tmp;
	guint32 i = 0;
	char *name;
	const GSList *iter;
	gboolean found;

	nm_utils_complete_generic (connection,
	                           NM_SETTING_BRIDGE_SETTING_NAME,
	                           existing_connections,
	                           _("Bridge connection %d"),
	                           NULL,
	                           TRUE);

	s_bridge = nm_connection_get_setting_bridge (connection);
	if (!s_bridge) {
		s_bridge = (NMSettingBridge *) nm_setting_bridge_new ();
		nm_connection_add_setting (connection, NM_SETTING (s_bridge));
	}

	/* Grab the first name that doesn't exist in either our connections
	 * or a device on the system.
	 */
	while (i < 500 && !nm_setting_bridge_get_interface_name (s_bridge)) {
		name = g_strdup_printf ("br%u", i);
		/* check interface names */
		if (!nm_platform_link_exists (name)) {
			/* check existing bridge connections */
			for (iter = existing_connections, found = FALSE; iter; iter = g_slist_next (iter)) {
				NMConnection *candidate = iter->data;

				tmp = nm_connection_get_setting_bridge (candidate);
				if (tmp && nm_connection_is_type (candidate, NM_SETTING_BRIDGE_SETTING_NAME)) {
					if (g_strcmp0 (nm_setting_bridge_get_interface_name (tmp), name) == 0) {
						found = TRUE;
						break;
					}
				}
			}

			if (!found)
				g_object_set (G_OBJECT (s_bridge), NM_SETTING_BRIDGE_INTERFACE_NAME, name, NULL);
		}

		g_free (name);
		i++;
	}

	return TRUE;
}
Beispiel #5
0
static void
nmt_page_bridge_constructed (GObject *object)
{
	NmtPageBridge *bridge = NMT_PAGE_BRIDGE (object);
	NmtDeviceEntry *deventry;
	NmtPageGrid *grid;
	NMSettingBridge *s_bridge;
	NmtNewtWidget *widget, *label, *stp;
	NMConnection *conn;

	conn = nmt_editor_page_get_connection (NMT_EDITOR_PAGE (bridge));
	s_bridge = nm_connection_get_setting_bridge (conn);
	if (!s_bridge) {
		nm_connection_add_setting (conn, nm_setting_bridge_new ());
		s_bridge = nm_connection_get_setting_bridge (conn);
	}

	deventry = nmt_page_device_get_device_entry (NMT_PAGE_DEVICE (object));
	g_object_bind_property (s_bridge, NM_SETTING_BRIDGE_INTERFACE_NAME,
	                        deventry, "interface-name",
	                        G_BINDING_BIDIRECTIONAL | G_BINDING_SYNC_CREATE);

	grid = NMT_PAGE_GRID (bridge);

	widget = nmt_newt_separator_new ();
	nmt_page_grid_append (grid, _("Slaves"), widget, NULL);
	nmt_page_grid_set_row_flags (grid, widget, NMT_PAGE_GRID_ROW_LABEL_ALIGN_LEFT);

	widget = nmt_slave_list_new (conn, bridge_connection_type_filter, bridge);
	nmt_page_grid_append (grid, NULL, widget, NULL);

	widget = nmt_newt_entry_numeric_new (10, 0, 1000000);
	g_object_bind_property (s_bridge, NM_SETTING_BRIDGE_AGEING_TIME,
	                        widget, "text",
	                        G_BINDING_BIDIRECTIONAL | G_BINDING_SYNC_CREATE);
	label = nmt_newt_label_new (_("seconds"));
	nmt_page_grid_append (grid, _("Aging time"), widget, label);

	widget = stp = nmt_newt_checkbox_new (_("Enable STP (Spanning Tree Protocol)"));
	g_object_bind_property (s_bridge, NM_SETTING_BRIDGE_STP,
	                        widget, "active",
	                        G_BINDING_BIDIRECTIONAL | G_BINDING_SYNC_CREATE);
	nmt_page_grid_append (grid, NULL, widget, NULL);

	widget = nmt_newt_entry_numeric_new (10, 0, G_MAXINT);
	g_object_bind_property (s_bridge, NM_SETTING_BRIDGE_PRIORITY,
	                        widget, "text",
	                        G_BINDING_BIDIRECTIONAL | G_BINDING_SYNC_CREATE);
	g_object_bind_property (s_bridge, NM_SETTING_BRIDGE_STP,
	                        widget, "sensitive",
	                        G_BINDING_SYNC_CREATE);
	nmt_page_grid_append (grid, _("Priority"), widget, NULL);

	widget = nmt_newt_entry_numeric_new (10, 2, 30);
	g_object_bind_property (s_bridge, NM_SETTING_BRIDGE_FORWARD_DELAY,
	                        widget, "text",
	                        G_BINDING_BIDIRECTIONAL | G_BINDING_SYNC_CREATE);
	g_object_bind_property (s_bridge, NM_SETTING_BRIDGE_STP,
	                        widget, "sensitive",
	                        G_BINDING_SYNC_CREATE);
	label = nmt_newt_label_new (_("seconds"));
	nmt_page_grid_append (grid, _("Forward delay"), widget, label);

	widget = nmt_newt_entry_numeric_new (10, 1, 10);
	g_object_bind_property (s_bridge, NM_SETTING_BRIDGE_HELLO_TIME,
	                        widget, "text",
	                        G_BINDING_BIDIRECTIONAL | G_BINDING_SYNC_CREATE);
	g_object_bind_property (s_bridge, NM_SETTING_BRIDGE_STP,
	                        widget, "sensitive",
	                        G_BINDING_SYNC_CREATE);
	label = nmt_newt_label_new (_("seconds"));
	nmt_page_grid_append (grid, _("Hello time"), widget, label);

	widget = nmt_newt_entry_numeric_new (10, 6, 40);
	g_object_bind_property (s_bridge, NM_SETTING_BRIDGE_MAX_AGE,
	                        widget, "text",
	                        G_BINDING_BIDIRECTIONAL | G_BINDING_SYNC_CREATE);
	g_object_bind_property (s_bridge, NM_SETTING_BRIDGE_STP,
	                        widget, "sensitive",
	                        G_BINDING_SYNC_CREATE);
	label = nmt_newt_label_new (_("seconds"));
	nmt_page_grid_append (grid, _("Max age"), widget, label);

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