diff options
Diffstat (limited to 'src/devices/nm-device-bridge.c')
| -rw-r--r-- | src/devices/nm-device-bridge.c | 123 |
1 files changed, 106 insertions, 17 deletions
diff --git a/src/devices/nm-device-bridge.c b/src/devices/nm-device-bridge.c index 01c4eb22..74689aef 100644 --- a/src/devices/nm-device-bridge.c +++ b/src/devices/nm-device-bridge.c @@ -49,6 +49,10 @@ G_DEFINE_TYPE (NMDeviceBridge, nm_device_bridge, NM_TYPE_DEVICE) /*****************************************************************************/ +const NMBtVTableNetworkServer *nm_bt_vtable_network_server = NULL; + +/*****************************************************************************/ + static NMDeviceCapabilities get_generic_capabilities (NMDevice *dev) { @@ -56,20 +60,23 @@ get_generic_capabilities (NMDevice *dev) } static gboolean -is_available (NMDevice *dev, NMDeviceCheckDevAvailableFlags flags) -{ - return TRUE; -} - -static gboolean check_connection_available (NMDevice *device, NMConnection *connection, NMDeviceCheckConAvailableFlags flags, const char *specific_object) { - /* Connections are always available because the carrier state is determined - * by the bridge port carrier states, not the bridge's state. - */ + NMSettingBluetooth *s_bt; + + if (!NM_DEVICE_CLASS (nm_device_bridge_parent_class)->check_connection_available (device, connection, flags, specific_object)) + return FALSE; + + s_bt = _nm_connection_get_setting_bluetooth_for_nap (connection); + if (s_bt) { + return nm_bt_vtable_network_server + && nm_bt_vtable_network_server->is_available (nm_bt_vtable_network_server, + nm_setting_bluetooth_get_bdaddr (s_bt)); + } + return TRUE; } @@ -83,9 +90,17 @@ check_connection_compatible (NMDevice *device, NMConnection *connection) return FALSE; s_bridge = nm_connection_get_setting_bridge (connection); - if (!s_bridge || !nm_connection_is_type (connection, NM_SETTING_BRIDGE_SETTING_NAME)) + if (!s_bridge) return FALSE; + if (!nm_connection_is_type (connection, NM_SETTING_BRIDGE_SETTING_NAME)) { + if ( nm_connection_is_type (connection, NM_SETTING_BLUETOOTH_SETTING_NAME) + && _nm_connection_get_setting_bluetooth_for_nap (connection)) { + /* a bluetooth NAP connection is handled by the bridge */ + } else + return FALSE; + } + mac_address = nm_setting_bridge_get_mac_address (s_bridge); if (mac_address && nm_device_is_real (device)) { const char *hw_addr; @@ -141,6 +156,7 @@ static const Option master_options[] = { { NM_SETTING_BRIDGE_HELLO_TIME, "hello_time", TRUE, TRUE }, { NM_SETTING_BRIDGE_MAX_AGE, "max_age", TRUE, TRUE }, { NM_SETTING_BRIDGE_AGEING_TIME, "ageing_time", TRUE, TRUE }, + { NM_SETTING_BRIDGE_GROUP_FORWARD_MASK, "group_fwd_mask", TRUE, FALSE }, { NM_SETTING_BRIDGE_MULTICAST_SNOOPING, "multicast_snooping", FALSE, FALSE }, { NULL, NULL } }; @@ -324,6 +340,40 @@ act_stage1_prepare (NMDevice *device, NMDeviceStateReason *out_failure_reason) return NM_ACT_STAGE_RETURN_SUCCESS; } +static NMActStageReturn +act_stage2_config (NMDevice *device, NMDeviceStateReason *out_failure_reason) +{ + NMConnection *connection; + NMSettingBluetooth *s_bt; + + connection = nm_device_get_applied_connection (device); + + s_bt = _nm_connection_get_setting_bluetooth_for_nap (connection); + if (s_bt) { + if ( !nm_bt_vtable_network_server + || !nm_bt_vtable_network_server->register_bridge (nm_bt_vtable_network_server, + nm_setting_bluetooth_get_bdaddr (s_bt), + device)) { + /* The HCI we could use is no longer present. */ + *out_failure_reason = NM_DEVICE_STATE_REASON_REMOVED; + return NM_ACT_STAGE_RETURN_FAILURE; + } + } + + return NM_ACT_STAGE_RETURN_SUCCESS; +} + +static void +deactivate (NMDevice *device) +{ + if (nm_bt_vtable_network_server) { + /* always call unregister. It does nothing if the device + * isn't registered as a hotspot bridge. */ + nm_bt_vtable_network_server->unregister_bridge (nm_bt_vtable_network_server, + device); + } +} + static gboolean enslave_slave (NMDevice *device, NMDevice *slave, @@ -384,20 +434,32 @@ create_and_realize (NMDevice *device, NMSettingBridge *s_bridge; const char *iface = nm_device_get_iface (device); const char *hwaddr; + gs_free char *hwaddr_cloned = NULL; guint8 mac_address[NM_UTILS_HWADDR_LEN_MAX]; NMPlatformError plerr; - g_assert (iface); + nm_assert (iface); s_bridge = nm_connection_get_setting_bridge (connection); - g_assert (s_bridge); + nm_assert (s_bridge); + hwaddr = nm_setting_bridge_get_mac_address (s_bridge); + if ( !hwaddr + && nm_device_hw_addr_get_cloned (device, connection, FALSE, + &hwaddr_cloned, NULL, NULL)) { + /* The cloned MAC address might by dynamic, for example with stable-id="${RANDOM}". + * It's a bit odd that we first create the device with one dynamic address, + * and later on may reset it to another. That is, because we don't cache + * the dynamic address in @device, like we do during nm_device_hw_addr_set_cloned(). */ + hwaddr = hwaddr_cloned; + } + if (hwaddr) { if (!nm_utils_hwaddr_aton (hwaddr, mac_address, ETH_ALEN)) { g_set_error (error, NM_DEVICE_ERROR, NM_DEVICE_ERROR_FAILED, "Invalid hardware address '%s'", hwaddr); - return FALSE; + g_return_val_if_reached (FALSE); } } @@ -411,7 +473,7 @@ create_and_realize (NMDevice *device, "Failed to create bridge interface '%s' for '%s': %s", iface, nm_connection_get_id (connection), - nm_platform_error_to_string (plerr)); + nm_platform_error_to_string_a (plerr)); return FALSE; } @@ -423,6 +485,7 @@ create_and_realize (NMDevice *device, static void nm_device_bridge_init (NMDeviceBridge * self) { + nm_assert (nm_device_is_master (NM_DEVICE (self))); } static void @@ -432,8 +495,8 @@ nm_device_bridge_class_init (NMDeviceBridgeClass *klass) NM_DEVICE_CLASS_DECLARE_TYPES (klass, NM_SETTING_BRIDGE_SETTING_NAME, NM_LINK_TYPE_BRIDGE) + parent_class->is_master = TRUE; parent_class->get_generic_capabilities = get_generic_capabilities; - parent_class->is_available = is_available; parent_class->check_connection_compatible = check_connection_compatible; parent_class->check_connection_available = check_connection_available; parent_class->complete_connection = complete_connection; @@ -443,6 +506,8 @@ nm_device_bridge_class_init (NMDeviceBridgeClass *klass) parent_class->create_and_realize = create_and_realize; parent_class->act_stage1_prepare = act_stage1_prepare; + parent_class->act_stage2_config = act_stage2_config; + parent_class->deactivate = deactivate; parent_class->enslave_slave = enslave_slave; parent_class->release_slave = release_slave; parent_class->get_configured_mtu = nm_device_get_configured_mtu_for_wired; @@ -470,12 +535,36 @@ create_device (NMDeviceFactory *factory, NM_DEVICE_TYPE_DESC, "Bridge", NM_DEVICE_DEVICE_TYPE, NM_DEVICE_TYPE_BRIDGE, NM_DEVICE_LINK_TYPE, NM_LINK_TYPE_BRIDGE, - NM_DEVICE_IS_MASTER, TRUE, NULL); } +static gboolean +match_connection (NMDeviceFactory *factory, + NMConnection *connection) +{ + const char *type = nm_connection_get_connection_type (connection); + + if (nm_streq (type, NM_SETTING_BRIDGE_SETTING_NAME)) + return TRUE; + + nm_assert (nm_streq (type, NM_SETTING_BLUETOOTH_SETTING_NAME)); + + if (!_nm_connection_get_setting_bluetooth_for_nap (connection)) + return FALSE; + + if (!g_type_from_name ("NMBluezManager")) { + /* bluetooth NAP connections are handled by bridge factory. However, + * it needs help from the bluetooth plugin, so if the plugin is not loaded, + * we claim not to support it. */ + return FALSE; + } + + return TRUE; +} + NM_DEVICE_FACTORY_DEFINE_INTERNAL (BRIDGE, Bridge, bridge, NM_DEVICE_FACTORY_DECLARE_LINK_TYPES (NM_LINK_TYPE_BRIDGE) - NM_DEVICE_FACTORY_DECLARE_SETTING_TYPES (NM_SETTING_BRIDGE_SETTING_NAME), + NM_DEVICE_FACTORY_DECLARE_SETTING_TYPES (NM_SETTING_BRIDGE_SETTING_NAME, NM_SETTING_BLUETOOTH_SETTING_NAME), factory_class->create_device = create_device; + factory_class->match_connection = match_connection; ); |