Exemplo n.º 1
0
static gboolean
enslave_slave (NMDevice *device, NMDevice *slave, NMConnection *connection)
{
	gboolean success;
	NMSettingBridgePort *s_port;
	const char *iface = nm_device_get_ip_iface (device);
	const char *slave_iface = nm_device_get_ip_iface (slave);

	success = nm_system_bridge_attach (nm_device_get_ip_ifindex (device),
	                                   iface,
	                                   nm_device_get_ip_ifindex (slave),
	                                   slave_iface);
	if (!success)
		return FALSE;

	/* Set port properties */
	s_port = nm_connection_get_setting_bridge_port (connection);
	if (s_port) {
		set_sysfs_uint (slave_iface, G_OBJECT (s_port), NM_SETTING_BRIDGE_PORT_PRIORITY, "brport", "priority", TRUE, FALSE);
		set_sysfs_uint (slave_iface, G_OBJECT (s_port), NM_SETTING_BRIDGE_PORT_PATH_COST, "brport", "path_cost", TRUE, FALSE);
		set_sysfs_uint (slave_iface, G_OBJECT (s_port), NM_SETTING_BRIDGE_PORT_HAIRPIN_MODE, "brport", "hairpin_mode", FALSE, FALSE);
	}

	nm_log_info (LOGD_BRIDGE, "(%s): attached bridge port %s", iface, slave_iface);

	g_object_notify (G_OBJECT (device), NM_DEVICE_BRIDGE_SLAVES);

	return TRUE;
}
static void
nmt_page_bridge_port_constructed (GObject *object)
{
	NmtPageBridgePort *bridge = NMT_PAGE_BRIDGE_PORT (object);
	NmtEditorSection *section;
	NmtEditorGrid *grid;
	NMSettingBridgePort *s_port;
	NmtNewtWidget *widget;
	NMConnection *conn;

	conn = nmt_editor_page_get_connection (NMT_EDITOR_PAGE (bridge));
	s_port = nm_connection_get_setting_bridge_port (conn);
	if (!s_port) {
		nm_connection_add_setting (conn, nm_setting_bridge_port_new ());
		s_port = nm_connection_get_setting_bridge_port (conn);
	}

	section = nmt_editor_section_new (_("BRIDGE PORT"), NULL, TRUE);
	grid = nmt_editor_section_get_body (section);

	widget = nmt_newt_entry_numeric_new (10, 0, 63);
	g_object_bind_property (s_port, NM_SETTING_BRIDGE_PORT_PRIORITY,
	                        widget, "text",
	                        G_BINDING_BIDIRECTIONAL | G_BINDING_SYNC_CREATE);
	nmt_editor_grid_append (grid, _("Priority"), widget, NULL);

	widget = nmt_newt_entry_numeric_new (10, 1, 65535);
	g_object_bind_property (s_port, NM_SETTING_BRIDGE_PORT_PATH_COST,
	                        widget, "text",
	                        G_BINDING_BIDIRECTIONAL | G_BINDING_SYNC_CREATE);
	nmt_editor_grid_append (grid, _("Path cost"), widget, NULL);

	widget = nmt_newt_checkbox_new (_("Hairpin mode"));
	g_object_bind_property (s_port, NM_SETTING_BRIDGE_PORT_HAIRPIN_MODE,
	                        widget, "active",
	                        G_BINDING_BIDIRECTIONAL | G_BINDING_SYNC_CREATE);
	nmt_editor_grid_append (grid, NULL, widget, NULL);

	nmt_editor_page_add_section (NMT_EDITOR_PAGE (bridge), section);

	G_OBJECT_CLASS (nmt_page_bridge_port_parent_class)->constructed (object);
}
Exemplo n.º 3
0
static gboolean
master_update_slave_connection (NMDevice *device,
                                NMDevice *slave,
                                NMConnection *connection,
                                GError **error)
{
	NMDeviceBridge *self = NM_DEVICE_BRIDGE (device);
	NMSettingConnection *s_con;
	NMSettingBridgePort *s_port;
	int ifindex_slave = nm_device_get_ifindex (slave);
	const char *iface = nm_device_get_iface (device);
	const Option *option;

	g_return_val_if_fail (ifindex_slave > 0, FALSE);

	s_con = nm_connection_get_setting_connection (connection);
	s_port = nm_connection_get_setting_bridge_port (connection);
	if (!s_port) {
		s_port = (NMSettingBridgePort *) nm_setting_bridge_port_new ();
		nm_connection_add_setting (connection, NM_SETTING (s_port));
	}

	for (option = slave_options; option->name; option++) {
		gs_free char *str = nm_platform_sysctl_slave_get_option (NM_PLATFORM_GET, ifindex_slave, 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_port, option->name, value, NULL);
		} else
			_LOGW (LOGD_BRIDGE, "failed to read bridge port setting '%s'", option->sysname);
	}

	g_object_set (s_con,
	              NM_SETTING_CONNECTION_MASTER, iface,
	              NM_SETTING_CONNECTION_SLAVE_TYPE, NM_SETTING_BRIDGE_SETTING_NAME,
	              NULL);
	return TRUE;
}
Exemplo n.º 4
0
static gboolean
enslave_slave (NMDevice *device,
               NMDevice *slave,
               NMConnection *connection,
               gboolean configure)
{
	if (configure) {
		if (!nm_platform_link_enslave (nm_device_get_ip_ifindex (device), nm_device_get_ip_ifindex (slave)))
			return FALSE;

		commit_slave_options (slave, nm_connection_get_setting_bridge_port (connection));
	}

	nm_log_info (LOGD_BRIDGE, "(%s): attached bridge port %s",
	             nm_device_get_ip_iface (device),
	             nm_device_get_ip_iface (slave));
	g_object_notify (G_OBJECT (device), NM_DEVICE_BRIDGE_SLAVES);

	return TRUE;
}
CEPage *
ce_page_bridge_port_new (NMConnectionEditor *editor,
                         NMConnection *connection,
                         GtkWindow *parent_window,
                         NMClient *client,
                         const char **out_secrets_setting_name,
                         GError **error)
{
	CEPageBridgePort *self;
	CEPageBridgePortPrivate *priv;

	self = CE_PAGE_BRIDGE_PORT (ce_page_new (CE_TYPE_PAGE_BRIDGE_PORT,
	                                         editor,
	                                         connection,
	                                         parent_window,
	                                         client,
	                                         UIDIR "/ce-page-bridge-port.ui",
	                                         "BridgePortPage",
	                                         /* Translators: a "Bridge Port" is a network
	                                          * device that is part of a bridge.
	                                          */
	                                         _("Bridge Port")));
	if (!self) {
		g_set_error_literal (error, NMA_ERROR, NMA_ERROR_GENERIC, _("Could not load bridge port user interface."));
		return NULL;
	}

	bridge_port_private_init (self);
	priv = CE_PAGE_BRIDGE_PORT_GET_PRIVATE (self);

	priv->setting = nm_connection_get_setting_bridge_port (connection);
	if (!priv->setting) {
		priv->setting = NM_SETTING_BRIDGE_PORT (nm_setting_bridge_port_new ());
		nm_connection_add_setting (connection, NM_SETTING (priv->setting));
	}

	g_signal_connect (self, "initialized", G_CALLBACK (finish_setup), NULL);

	return CE_PAGE (self);
}
Exemplo n.º 6
0
static gboolean
enslave_slave (NMDevice *device,
               NMDevice *slave,
               NMConnection *connection,
               gboolean configure)
{
	NMDeviceBridge *self = NM_DEVICE_BRIDGE (device);

	if (configure) {
		if (!nm_platform_link_enslave (NM_PLATFORM_GET, nm_device_get_ip_ifindex (device), nm_device_get_ip_ifindex (slave)))
			return FALSE;

		commit_slave_options (slave, nm_connection_get_setting_bridge_port (connection));

		_LOGI (LOGD_BRIDGE, "attached bridge port %s",
		       nm_device_get_ip_iface (slave));
	} else {
		_LOGI (LOGD_BRIDGE, "bridge port %s was attached",
		       nm_device_get_ip_iface (slave));
	}

	return TRUE;
}
Exemplo n.º 7
0
/**
 * nm_bridge_update_slave_connection:
 * @slave: the slave #NMDevice, is *not* necessarily a bridge interface
 * @connection: the #NMConnection to update with the bridge port settings
 *
 * Reads bridge port configuration and updates @connection with those
 * properties.
 *
 * Returns: %TRUE if the port configuration was read and @connection updated,
 * %FALSE if not.
 */
gboolean
nm_bridge_update_slave_connection (NMDevice *slave, NMConnection *connection)
{
	NMSettingBridgePort *s_port;
	int ifindex = nm_device_get_ifindex (slave);
	const Option *option;

	g_return_val_if_fail (NM_IS_DEVICE (slave), FALSE);
	g_return_val_if_fail (NM_IS_CONNECTION (connection), FALSE);

	s_port = nm_connection_get_setting_bridge_port (connection);
	if (!s_port) {
		s_port = (NMSettingBridgePort *) nm_setting_bridge_port_new ();
		nm_connection_add_setting (connection, NM_SETTING (s_port));
	}

	for (option = slave_options; option->name; option++) {
		gs_free char *str = nm_platform_slave_get_option (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_port, option->name, value, NULL);
		} else {
			nm_log_warn (LOGD_BRIDGE, "(%s): failed to read bridge port setting '%s'",
			             nm_device_get_iface (slave), option->sysname);
		}
	}

	return TRUE;
}