diff options
author | Thomas Haller <thaller@redhat.com> | 2017-04-18 15:52:01 +0200 |
---|---|---|
committer | Thomas Haller <thaller@redhat.com> | 2017-04-18 15:52:01 +0200 |
commit | a31ddcfca5abf13d5a6522615d2411692167eadf (patch) | |
tree | 626cc638bd866242a2c280e20e7d57d1d2eee46b | |
parent | df537d2eac44cffe4512214c87f3f303c5a350d3 (diff) | |
parent | 41148caba8dc6df6c9025680e53c1c88f048dc73 (diff) | |
download | NetworkManager-a31ddcfca5abf13d5a6522615d2411692167eadf.tar.gz |
core: merge branch 'th/netns-singleton-rh1440089'
https://bugzilla.redhat.com/show_bug.cgi?id=1440089
45 files changed, 657 insertions, 351 deletions
diff --git a/Makefile.am b/Makefile.am index 43c8a592a2..755315267b 100644 --- a/Makefile.am +++ b/Makefile.am @@ -1445,6 +1445,8 @@ src_libNetworkManager_la_SOURCES = \ src/nm-connectivity.h \ src/nm-dcb.c \ src/nm-dcb.h \ + src/nm-netns.c \ + src/nm-netns.h \ src/nm-default-route-manager.c \ src/nm-default-route-manager.h \ src/nm-dhcp4-config.c \ diff --git a/src/devices/adsl/nm-device-adsl.c b/src/devices/adsl/nm-device-adsl.c index a953a19243..fe622bdf8b 100644 --- a/src/devices/adsl/nm-device-adsl.c +++ b/src/devices/adsl/nm-device-adsl.c @@ -129,7 +129,7 @@ complete_connection (NMDevice *device, if (s_adsl && !nm_setting_verify (NM_SETTING (s_adsl), NULL, error)) return FALSE; - nm_utils_complete_generic (NM_PLATFORM_GET, + nm_utils_complete_generic (nm_device_get_platform (device), connection, NM_SETTING_ADSL_SETTING_NAME, existing_connections, @@ -273,14 +273,14 @@ pppoe_vcc_config (NMDeviceAdsl *self) return FALSE; /* Watch for the 'nas' interface going away */ - g_signal_connect (NM_PLATFORM_GET, NM_PLATFORM_SIGNAL_LINK_CHANGED, + g_signal_connect (nm_device_get_platform (device), NM_PLATFORM_SIGNAL_LINK_CHANGED, G_CALLBACK (link_changed_cb), self); _LOGD (LOGD_ADSL, "ATM setup successful"); /* otherwise we're good for stage3 */ - nm_platform_link_set_up (NM_PLATFORM_GET, priv->nas_ifindex, NULL); + nm_platform_link_set_up (nm_device_get_platform (device), priv->nas_ifindex, NULL); return TRUE; } @@ -306,7 +306,7 @@ nas_update_cb (gpointer user_data) } g_warn_if_fail (priv->nas_ifindex < 0); - priv->nas_ifindex = nm_platform_link_get_ifindex (NM_PLATFORM_GET, priv->nas_ifname); + priv->nas_ifindex = nm_platform_link_get_ifindex (nm_device_get_platform (device), priv->nas_ifname); if (priv->nas_ifindex < 0) { /* Keep waiting for it to appear */ return G_SOURCE_CONTINUE; @@ -508,7 +508,7 @@ adsl_cleanup (NMDeviceAdsl *self) g_clear_object (&priv->ppp_manager); } - g_signal_handlers_disconnect_by_func (NM_PLATFORM_GET, G_CALLBACK (link_changed_cb), self); + g_signal_handlers_disconnect_by_func (nm_device_get_platform (NM_DEVICE (self)), G_CALLBACK (link_changed_cb), self); if (priv->brfd >= 0) { close (priv->brfd); @@ -542,7 +542,7 @@ carrier_update_cb (gpointer user_data) path = g_strdup_printf ("/sys/class/atm/%s/carrier", NM_ASSERT_VALID_PATH_COMPONENT (nm_device_get_iface (NM_DEVICE (self)))); - carrier = (int) nm_platform_sysctl_get_int_checked (NM_PLATFORM_GET, NMP_SYSCTL_PATHID_ABSOLUTE (path), 10, 0, 1, -1); + carrier = (int) nm_platform_sysctl_get_int_checked (nm_device_get_platform (NM_DEVICE (self)), NMP_SYSCTL_PATHID_ABSOLUTE (path), 10, 0, 1, -1); g_free (path); if (carrier != -1) diff --git a/src/devices/bluetooth/nm-device-bt.c b/src/devices/bluetooth/nm-device-bt.c index 1f040d5294..4ee7148928 100644 --- a/src/devices/bluetooth/nm-device-bt.c +++ b/src/devices/bluetooth/nm-device-bt.c @@ -328,7 +328,7 @@ complete_connection (NMDevice *device, return FALSE; } - nm_utils_complete_generic (NM_PLATFORM_GET, + nm_utils_complete_generic (nm_device_get_platform (device), connection, NM_SETTING_BLUETOOTH_SETTING_NAME, existing_connections, diff --git a/src/devices/nm-device-bond.c b/src/devices/nm-device-bond.c index bcc9959762..3325c9485e 100644 --- a/src/devices/nm-device-bond.c +++ b/src/devices/nm-device-bond.c @@ -101,7 +101,7 @@ complete_connection (NMDevice *device, { NMSettingBond *s_bond; - nm_utils_complete_generic (NM_PLATFORM_GET, + nm_utils_complete_generic (nm_device_get_platform (device), connection, NM_SETTING_BOND_SETTING_NAME, existing_connections, @@ -131,7 +131,7 @@ set_bond_attr (NMDevice *device, NMBondMode mode, const char *attr, const char * if (!_nm_setting_bond_option_supported (attr, mode)) return FALSE; - ret = nm_platform_sysctl_master_set_option (NM_PLATFORM_GET, ifindex, attr, value); + ret = nm_platform_sysctl_master_set_option (nm_device_get_platform (device), ifindex, attr, value); if (!ret) _LOGW (LOGD_PLATFORM, "failed to set bonding attribute '%s' to '%s'", attr, value); return ret; @@ -165,7 +165,7 @@ update_connection (NMDevice *device, NMConnection *connection) /* Read bond options from sysfs and update the Bond setting to match */ options = nm_setting_bond_get_valid_options (s_bond); while (options && *options) { - gs_free char *value = nm_platform_sysctl_master_get_option (NM_PLATFORM_GET, ifindex, *options); + gs_free char *value = nm_platform_sysctl_master_get_option (nm_device_get_platform (device), ifindex, *options); const char *defvalue = nm_setting_bond_get_option_default (s_bond, *options); char *p; @@ -328,7 +328,7 @@ apply_bonding_config (NMDevice *device) set_bond_attr (device, mode, NM_SETTING_BOND_OPTION_PRIMARY, value ? value : ""); /* ARP targets: clear and initialize the list */ - contents = nm_platform_sysctl_master_get_option (NM_PLATFORM_GET, ifindex, + contents = nm_platform_sysctl_master_get_option (nm_device_get_platform (device), ifindex, NM_SETTING_BOND_OPTION_ARP_IP_TARGET); set_arp_targets (device, mode, contents, " \n", "-"); value = nm_setting_bond_get_option_by_name (s_bond, NM_SETTING_BOND_OPTION_ARP_IP_TARGET); @@ -397,7 +397,7 @@ enslave_slave (NMDevice *device, if (configure) { nm_device_take_down (slave, TRUE); - success = nm_platform_link_enslave (NM_PLATFORM_GET, + success = nm_platform_link_enslave (nm_device_get_platform (device), nm_device_get_ip_ifindex (device), nm_device_get_ip_ifindex (slave)); nm_device_bring_up (slave, TRUE, &no_firmware); @@ -416,7 +416,7 @@ enslave_slave (NMDevice *device, if (s_bond) { active = nm_setting_bond_get_option_by_name (s_bond, "active_slave"); if (active && nm_streq0 (active, nm_device_get_iface (slave))) { - nm_platform_sysctl_master_set_option (NM_PLATFORM_GET, + nm_platform_sysctl_master_set_option (nm_device_get_platform (device), nm_device_get_ifindex (device), "active_slave", active); @@ -446,7 +446,7 @@ release_slave (NMDevice *device, */ address = g_strdup (nm_device_get_hw_address (device)); - success = nm_platform_link_release (NM_PLATFORM_GET, + success = nm_platform_link_release (nm_device_get_platform (device), nm_device_get_ip_ifindex (device), nm_device_get_ip_ifindex (slave)); @@ -458,7 +458,7 @@ release_slave (NMDevice *device, nm_device_get_ip_iface (slave)); } - nm_platform_process_events (NM_PLATFORM_GET); + nm_platform_process_events (nm_device_get_platform (device)); if (nm_device_update_hw_address (device)) nm_device_hw_addr_set (device, address, "restore", FALSE); @@ -486,7 +486,7 @@ create_and_realize (NMDevice *device, g_assert (iface); - plerr = nm_platform_link_bond_add (NM_PLATFORM_GET, iface, out_plink); + plerr = nm_platform_link_bond_add (nm_device_get_platform (device), iface, out_plink); if (plerr != NM_PLATFORM_ERROR_SUCCESS) { g_set_error (error, NM_DEVICE_ERROR, NM_DEVICE_ERROR_CREATION_FAILED, "Failed to create bond interface '%s' for '%s': %s", diff --git a/src/devices/nm-device-bridge.c b/src/devices/nm-device-bridge.c index 0ff6e634c1..01c4eb224b 100644 --- a/src/devices/nm-device-bridge.c +++ b/src/devices/nm-device-bridge.c @@ -107,7 +107,7 @@ complete_connection (NMDevice *device, { NMSettingBridge *s_bridge; - nm_utils_complete_generic (NM_PLATFORM_GET, + nm_utils_complete_generic (nm_device_get_platform (device), connection, NM_SETTING_BRIDGE_SETTING_NAME, existing_connections, @@ -197,9 +197,9 @@ commit_option (NMDevice *device, NMSetting *setting, const Option *option, gbool value = g_strdup_printf ("%u", uval); if (slave) - nm_platform_sysctl_slave_set_option (NM_PLATFORM_GET, ifindex, option->sysname, value); + nm_platform_sysctl_slave_set_option (nm_device_get_platform (device), ifindex, option->sysname, value); else - nm_platform_sysctl_master_set_option (NM_PLATFORM_GET, ifindex, option->sysname, value); + nm_platform_sysctl_master_set_option (nm_device_get_platform (device), ifindex, option->sysname, value); } static void @@ -243,7 +243,7 @@ update_connection (NMDevice *device, NMConnection *connection) } for (option = master_options; option->name; option++) { - gs_free char *str = nm_platform_sysctl_master_get_option (NM_PLATFORM_GET, ifindex, option->sysname); + gs_free char *str = nm_platform_sysctl_master_get_option (nm_device_get_platform (device), ifindex, option->sysname); int value; if (str) { @@ -282,7 +282,7 @@ master_update_slave_connection (NMDevice *device, } for (option = slave_options; option->name; option++) { - gs_free char *str = nm_platform_sysctl_slave_get_option (NM_PLATFORM_GET, ifindex_slave, option->sysname); + gs_free char *str = nm_platform_sysctl_slave_get_option (nm_device_get_platform (device), ifindex_slave, option->sysname); int value; if (str) { @@ -333,7 +333,7 @@ enslave_slave (NMDevice *device, 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))) + if (!nm_platform_link_enslave (nm_device_get_platform (device), 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)); @@ -357,7 +357,7 @@ release_slave (NMDevice *device, gboolean success; if (configure) { - success = nm_platform_link_release (NM_PLATFORM_GET, + success = nm_platform_link_release (nm_device_get_platform (device), nm_device_get_ip_ifindex (device), nm_device_get_ip_ifindex (slave)); @@ -401,7 +401,7 @@ create_and_realize (NMDevice *device, } } - plerr = nm_platform_link_bridge_add (NM_PLATFORM_GET, + plerr = nm_platform_link_bridge_add (nm_device_get_platform (device), iface, hwaddr ? mac_address : NULL, hwaddr ? ETH_ALEN : 0, diff --git a/src/devices/nm-device-dummy.c b/src/devices/nm-device-dummy.c index 10975d262d..dce4f7bc56 100644 --- a/src/devices/nm-device-dummy.c +++ b/src/devices/nm-device-dummy.c @@ -62,7 +62,7 @@ complete_connection (NMDevice *device, { NMSettingDummy *s_dummy; - nm_utils_complete_generic (NM_PLATFORM_GET, + nm_utils_complete_generic (nm_device_get_platform (device), connection, NM_SETTING_DUMMY_SETTING_NAME, existing_connections, @@ -106,7 +106,7 @@ create_and_realize (NMDevice *device, s_dummy = nm_connection_get_setting_dummy (connection); g_assert (s_dummy); - plerr = nm_platform_link_dummy_add (NM_PLATFORM_GET, iface, out_plink); + plerr = nm_platform_link_dummy_add (nm_device_get_platform (device), iface, out_plink); if (plerr != NM_PLATFORM_ERROR_SUCCESS) { g_set_error (error, NM_DEVICE_ERROR, NM_DEVICE_ERROR_CREATION_FAILED, "Failed to create dummy interface '%s' for '%s': %s", diff --git a/src/devices/nm-device-ethernet.c b/src/devices/nm-device-ethernet.c index 371738517a..4c5aeb5e1b 100644 --- a/src/devices/nm-device-ethernet.c +++ b/src/devices/nm-device-ethernet.c @@ -172,7 +172,7 @@ _update_s390_subchannels (NMDeviceEthernet *self) } ifindex = nm_device_get_ifindex ((NMDevice *) self); - dev = nm_platform_link_get_udev_device (NM_PLATFORM_GET, ifindex); + dev = nm_platform_link_get_udev_device (nm_device_get_platform (NM_DEVICE (self)), ifindex); if (!dev) return; @@ -209,7 +209,7 @@ _update_s390_subchannels (NMDeviceEthernet *self) gs_free char *path = NULL, *value = NULL; path = g_strdup_printf ("%s/%s", parent_path, item); - value = nm_platform_sysctl_get (NM_PLATFORM_GET, NMP_SYSCTL_PATHID_ABSOLUTE (path)); + value = nm_platform_sysctl_get (nm_device_get_platform (NM_DEVICE (self)), NMP_SYSCTL_PATHID_ABSOLUTE (path)); if ( !strcmp (item, "portname") && !g_strcmp0 (value, "no portname required")) { @@ -304,7 +304,7 @@ get_generic_capabilities (NMDevice *device) int ifindex = nm_device_get_ifindex (device); if (ifindex > 0) { - if (nm_platform_link_supports_carrier_detect (NM_PLATFORM_GET, ifindex)) + if (nm_platform_link_supports_carrier_detect (nm_device_get_platform (device), ifindex)) return NM_DEVICE_CAP_CARRIER_DETECT; else { _LOGI (LOGD_PLATFORM, "driver '%s' does not support carrier detection.", @@ -569,7 +569,7 @@ build_supplicant_config (NMDeviceEthernet *self, connection = nm_device_get_applied_connection (NM_DEVICE (self)); g_assert (connection); con_uuid = nm_connection_get_uuid (connection); - mtu = nm_platform_link_get_mtu (NM_PLATFORM_GET, + mtu = nm_platform_link_get_mtu (nm_device_get_platform (NM_DEVICE (self)), nm_device_get_ifindex (NM_DEVICE (self))); config = nm_supplicant_config_new (); @@ -828,7 +828,7 @@ link_negotiation_set (NMDevice *device) } } - if (!nm_platform_ethtool_get_link_settings (NM_PLATFORM_GET, nm_device_get_ifindex (device), + if (!nm_platform_ethtool_get_link_settings (nm_device_get_platform (device), nm_device_get_ifindex (device), &link_autoneg, &link_speed, &link_duplex)) { _LOGW (LOGD_DEVICE, "set-link: unable to retrieve link negotiation"); return; @@ -852,7 +852,7 @@ link_negotiation_set (NMDevice *device) duplex ? "" : "*"); } - if (!nm_platform_ethtool_set_link_settings (NM_PLATFORM_GET, + if (!nm_platform_ethtool_set_link_settings (nm_device_get_platform (device), nm_device_get_ifindex (device), autoneg, speed, @@ -1124,7 +1124,7 @@ dcb_state (NMDevice *device, gboolean timeout) g_return_if_fail (nm_device_get_state (device) == NM_DEVICE_STATE_CONFIG); - carrier = nm_platform_link_is_connected (NM_PLATFORM_GET, nm_device_get_ifindex (device)); + carrier = nm_platform_link_is_connected (nm_device_get_platform (device), nm_device_get_ifindex (device)); _LOGD (LOGD_DCB, "dcb_state() wait %d carrier %d timeout %d", priv->dcb_wait, carrier, timeout); switch (priv->dcb_wait) { @@ -1242,7 +1242,7 @@ wake_on_lan_enable (NMDevice *device) } wol = NM_SETTING_WIRED_WAKE_ON_LAN_IGNORE; found: - return nm_platform_ethtool_set_wake_on_lan (NM_PLATFORM_GET, nm_device_get_ifindex (device), wol, password); + return nm_platform_ethtool_set_wake_on_lan (nm_device_get_platform (device), nm_device_get_ifindex (device), wol, password); } /*****************************************************************************/ @@ -1285,7 +1285,7 @@ act_stage2_config (NMDevice *device, NMDeviceStateReason *out_failure_reason) s_dcb = (NMSettingDcb *) nm_device_get_applied_setting (device, NM_TYPE_SETTING_DCB); if (s_dcb) { /* lldpad really really wants the carrier to be up */ - if (nm_platform_link_is_connected (NM_PLATFORM_GET, nm_device_get_ifindex (device))) { + if (nm_platform_link_is_connected (nm_device_get_platform (device), nm_device_get_ifindex (device))) { if (!dcb_enable (device)) { NM_SET_OUT (out_failure_reason, NM_DEVICE_STATE_REASON_DCB_FCOE_FAILED); return NM_ACT_STAGE_RETURN_FAILURE; @@ -1321,7 +1321,7 @@ act_stage2_config (NMDevice *device, NMDeviceStateReason *out_failure_reason) if (mxu) { _LOGD (LOGD_PPP, "set MTU to %u (PPP interface MRU %u, MTU %u)", mxu + PPPOE_ENCAP_OVERHEAD, mru, mtu); - nm_platform_link_set_mtu (NM_PLATFORM_GET, + nm_platform_link_set_mtu (nm_device_get_platform (device), nm_device_get_ifindex (device), mxu + PPPOE_ENCAP_OVERHEAD); } @@ -1427,7 +1427,7 @@ complete_connection (NMDevice *device, /* Default to an ethernet-only connection, but if a PPPoE setting was given * then PPPoE should be our connection type. */ - nm_utils_complete_generic (NM_PLATFORM_GET, + nm_utils_complete_generic (nm_device_get_platform (device), connection, s_pppoe ? NM_SETTING_PPPOE_SETTING_NAME : NM_SETTING_WIRED_SETTING_NAME, existing_connections, @@ -1585,7 +1585,7 @@ get_link_speed (NMDevice *device) NMDeviceEthernetPrivate *priv = NM_DEVICE_ETHERNET_GET_PRIVATE (self); guint32 speed; - if (!nm_platform_ethtool_get_link_settings (NM_PLATFORM_GET, nm_device_get_ifindex (device), NULL, &speed, NULL)) + if (!nm_platform_ethtool_get_link_settings (nm_device_get_platform (device), nm_device_get_ifindex (device), NULL, &speed, NULL)) return; if (priv->speed == speed) return; diff --git a/src/devices/nm-device-generic.c b/src/devices/nm-device-generic.c index 2f51c69dd5..f6a670b214 100644 --- a/src/devices/nm-device-generic.c +++ b/src/devices/nm-device-generic.c @@ -54,11 +54,11 @@ G_DEFINE_TYPE (NMDeviceGeneric, nm_device_generic, NM_TYPE_DEVICE) /*****************************************************************************/ static NMDeviceCapabilities -get_generic_capabilities (NMDevice *dev) +get_generic_capabilities (NMDevice *device) { - int ifindex = nm_device_get_ifindex (dev); + int ifindex = nm_device_get_ifindex (device); - if (ifindex > 0 && nm_platform_link_supports_carrier_detect (NM_PLATFORM_GET, ifindex)) + if (ifindex > 0 && nm_platform_link_supports_carrier_detect (nm_device_get_platform (device), ifindex)) return NM_DEVICE_CAP_CARRIER_DETECT; else return NM_DEVICE_CAP_NONE; @@ -84,7 +84,7 @@ realize_start_notify (NMDevice *device, const NMPlatformLink *plink) g_clear_pointer (&priv->type_description, g_free); ifindex = nm_device_get_ip_ifindex (NM_DEVICE (self)); if (ifindex > 0) - priv->type_description = g_strdup (nm_platform_link_get_type_name (NM_PLATFORM_GET, ifindex)); + priv->type_description = g_strdup (nm_platform_link_get_type_name (nm_device_get_platform (device), ifindex)); } static gboolean diff --git a/src/devices/nm-device-infiniband.c b/src/devices/nm-device-infiniband.c index 59a9e6f381..f7875d0992 100644 --- a/src/devices/nm-device-infiniband.c +++ b/src/devices/nm-device-infiniband.c @@ -75,7 +75,7 @@ get_generic_capabilities (NMDevice *device) } static NMActStageReturn -act_stage1_prepare (NMDevice *dev, NMDeviceStateReason *out_failure_reason) +act_stage1_prepare (NMDevice *device, NMDeviceStateReason *out_failure_reason) { nm_auto_close int dirfd = -1; NMActStageReturn ret; @@ -84,16 +84,16 @@ act_stage1_prepare (NMDevice *dev, NMDeviceStateReason *out_failure_reason) const char *transport_mode; gboolean ok, no_firmware = FALSE; - ret = NM_DEVICE_CLASS (nm_device_infiniband_parent_class)->act_stage1_prepare (dev, out_failure_reason); + ret = NM_DEVICE_CLASS (nm_device_infiniband_parent_class)->act_stage1_prepare (device, out_failure_reason); if (ret != NM_ACT_STAGE_RETURN_SUCCESS) return ret; - s_infiniband = (NMSettingInfiniband *) nm_device_get_applied_setting (dev, NM_TYPE_SETTING_INFINIBAND); + s_infiniband = (NMSettingInfiniband *) nm_device_get_applied_setting (device, NM_TYPE_SETTING_INFINIBAND); g_return_val_if_fail (s_infiniband, NM_ACT_STAGE_RETURN_FAILURE); transport_mode = nm_setting_infiniband_get_transport_mode (s_infiniband); - dirfd = nm_platform_sysctl_open_netdir (NM_PLATFORM_GET, nm_device_get_ifindex (dev), ifname_verified); + dirfd = nm_platform_sysctl_open_netdir (nm_device_get_platform (device), nm_device_get_ifindex (device), ifname_verified); if (dirfd < 0) { if (!strcmp (transport_mode, "datagram")) return NM_ACT_STAGE_RETURN_SUCCESS; @@ -104,9 +104,9 @@ act_stage1_prepare (NMDevice *dev, NMDeviceStateReason *out_failure_reason) } /* With some drivers the interface must be down to set transport mode */ - nm_device_take_down (dev, TRUE); - ok = nm_platform_sysctl_set (NM_PLATFORM_GET, NMP_SYSCTL_PATHID_NETDIR (dirfd, ifname_verified, "mode"), transport_mode); - nm_device_bring_up (dev, TRUE, &no_firmware); + nm_device_take_down (device, TRUE); + ok = nm_platform_sysctl_set (nm_device_get_platform (device), NMP_SYSCTL_PATHID_NETDIR (dirfd, ifname_verified, "mode"), transport_mode); + nm_device_bring_up (device, TRUE, &no_firmware); if (!ok) { NM_SET_OUT (out_failure_reason, NM_DEVICE_STATE_REASON_CONFIG_FAILED); @@ -184,7 +184,7 @@ complete_connection (NMDevice *device, const char *setting_mac; const char *hw_address; - nm_utils_complete_generic (NM_PLATFORM_GET, + nm_utils_complete_generic (nm_device_get_platform (device), connection, NM_SETTING_INFINIBAND_SETTING_NAME, existing_connections, @@ -240,7 +240,7 @@ update_connection (NMDevice *device, NMConnection *connection) ifindex = nm_device_get_ifindex (device); if (ifindex > 0) { - if (!nm_platform_link_infiniband_get_properties (NM_PLATFORM_GET, ifindex, NULL, NULL, &transport_mode)) + if (!nm_platform_link_infiniband_get_properties (nm_device_get_platform (device), ifindex, NULL, NULL, &transport_mode)) transport_mode = "datagram"; } g_object_set (G_OBJECT (s_infiniband), NM_SETTING_INFINIBAND_TRANSPORT_MODE, transport_mode, NULL); @@ -289,7 +289,7 @@ create_and_realize (NMDevice *device, return FALSE; } - plerr = nm_platform_link_infiniband_add (NM_PLATFORM_GET, priv->parent_ifindex, priv->p_key, out_plink); + plerr = nm_platform_link_infiniband_add (nm_device_get_platform (device), priv->parent_ifindex, priv->p_key, out_plink); if (plerr != NM_PLATFORM_ERROR_SUCCESS) { g_set_error (error, NM_DEVICE_ERROR, NM_DEVICE_ERROR_CREATION_FAILED, "Failed to create InfiniBand P_Key interface '%s' for '%s': %s", @@ -319,7 +319,7 @@ unrealize (NMDevice *device, GError **error) return FALSE; } - plerr = nm_platform_link_infiniband_delete (NM_PLATFORM_GET, priv->parent_ifindex, priv->p_key); + plerr = nm_platform_link_infiniband_delete (nm_device_get_platform (device), priv->parent_ifindex, priv->p_key); if (plerr != NM_PLATFORM_ERROR_SUCCESS) { g_set_error (error, NM_DEVICE_ERROR, NM_DEVICE_ERROR_CREATION_FAILED, "Failed to remove InfiniBand P_Key interface '%s': %s", diff --git a/src/devices/nm-device-ip-tunnel.c b/src/devices/nm-device-ip-tunnel.c index ab3f34225b..1e62654108 100644 --- a/src/devices/nm-device-ip-tunnel.c +++ b/src/devices/nm-device-ip-tunnel.c @@ -157,7 +157,7 @@ clear: if (priv->mode == NM_IP_TUNNEL_MODE_GRE) { const NMPlatformLnkGre *lnk; - lnk = nm_platform_link_get_lnk_gre (NM_PLATFORM_GET, ifindex, NULL); + lnk = nm_platform_link_get_lnk_gre (nm_device_get_platform (device), ifindex, NULL); if (!lnk) { _LOGW (LOGD_PLATFORM, "could not read %s properties", "gre"); goto clear; @@ -202,7 +202,7 @@ clear: } else if (priv->mode == NM_IP_TUNNEL_MODE_SIT) { const NMPlatformLnkSit *lnk; - lnk = nm_platform_link_get_lnk_sit (NM_PLATFORM_GET, ifindex, NULL); + lnk = nm_platform_link_get_lnk_sit (nm_device_get_platform (device), ifindex, NULL); if (!lnk) { _LOGW (LOGD_PLATFORM, "could not read %s properties", "sit"); goto clear; @@ -217,7 +217,7 @@ clear: } else if (priv->mode == NM_IP_TUNNEL_MODE_IPIP) { const NMPlatformLnkIpIp *lnk; - lnk = nm_platform_link_get_lnk_ipip (NM_PLATFORM_GET, ifindex, NULL); + lnk = nm_platform_link_get_lnk_ipip (nm_device_get_platform (device), ifindex, NULL); if (!lnk) { _LOGW (LOGD_PLATFORM, "could not read %s properties", "ipip"); goto clear; @@ -233,7 +233,7 @@ clear: || priv->mode == NM_IP_TUNNEL_MODE_IP6IP6) { const NMPlatformLnkIp6Tnl *lnk; - lnk = nm_platform_link_get_lnk_ip6tnl (NM_PLATFORM_GET, ifindex, NULL); + lnk = nm_platform_link_get_lnk_ip6tnl (nm_device_get_platform (device), ifindex, NULL); if (!lnk) { _LOGW (LOGD_PLATFORM, "could not read %s properties", "ip6tnl"); goto clear; @@ -332,7 +332,7 @@ complete_connection (NMDevice *device, { NMSettingIPTunnel *s_ip_tunnel; - nm_utils_complete_generic (NM_PLATFORM_GET, + nm_utils_complete_generic (nm_device_get_platform (device), connection, NM_SETTING_IP_TUNNEL_SETTING_NAME, existing_connections, @@ -641,7 +641,7 @@ create_and_realize (NMDevice *device, lnk_gre.output_flags = NM_GRE_KEY; } - plerr = nm_platform_link_gre_add (NM_PLATFORM_GET, iface, &lnk_gre, out_plink); + plerr = nm_platform_link_gre_add (nm_device_get_platform (device), iface, &lnk_gre, out_plink); if (plerr != NM_PLATFORM_ERROR_SUCCESS) { g_set_error (error, NM_DEVICE_ERROR, NM_DEVICE_ERROR_CREATION_FAILED, "Failed to create GRE interface '%s' for '%s': %s", @@ -667,7 +667,7 @@ create_and_realize (NMDevice *device, lnk_sit.tos = nm_setting_ip_tunnel_get_tos (s_ip_tunnel); lnk_sit.path_mtu_discovery = nm_setting_ip_tunnel_get_path_mtu_discovery (s_ip_tunnel); - plerr = nm_platform_link_sit_add (NM_PLATFORM_GET, iface, &lnk_sit, out_plink); + plerr = nm_platform_link_sit_add (nm_device_get_platform (device), iface, &lnk_sit, out_plink); if (plerr != NM_PLATFORM_ERROR_SUCCESS) { g_set_error (error, NM_DEVICE_ERROR, NM_DEVICE_ERROR_CREATION_FAILED, "Failed to create SIT interface '%s' for '%s': %s", @@ -693,7 +693,7 @@ create_and_realize (NMDevice *device, lnk_ipip.tos = nm_setting_ip_tunnel_get_tos (s_ip_tunnel); lnk_ipip.path_mtu_discovery = nm_setting_ip_tunnel_get_path_mtu_discovery (s_ip_tunnel); - plerr = nm_platform_link_ipip_add (NM_PLATFORM_GET, iface, &lnk_ipip, out_plink); + plerr = nm_platform_link_ipip_add (nm_device_get_platform (device), iface, &lnk_ipip, out_plink); if (plerr != NM_PLATFORM_ERROR_SUCCESS) { g_set_error (error, NM_DEVICE_ERROR, NM_DEVICE_ERROR_CREATION_FAILED, "Failed to create IPIP interface '%s' for '%s': %s", @@ -722,7 +722,7 @@ create_and_realize (NMDevice *device, lnk_ip6tnl.flow_label = nm_setting_ip_tunnel_get_flow_label (s_ip_tunnel); lnk_ip6tnl.proto = nm_setting_ip_tunnel_get_mode (s_ip_tunnel) == NM_IP_TUNNEL_MODE_IPIP6 ? IPPROTO_IPIP : IPPROTO_IPV6; - plerr = nm_platform_link_ip6tnl_add (NM_PLATFORM_GET, iface, &lnk_ip6tnl, out_plink); + plerr = nm_platform_link_ip6tnl_add (nm_device_get_platform (device), iface, &lnk_ip6tnl, out_plink); if (plerr != NM_PLATFORM_ERROR_SUCCESS) { g_set_error (error, NM_DEVICE_ERROR, NM_DEVICE_ERROR_CREATION_FAILED, "Failed to create IPIP interface '%s' for '%s': %s", diff --git a/src/devices/nm-device-macsec.c b/src/devices/nm-device-macsec.c index 9a8d847d6e..8add3f6fb8 100644 --- a/src/devices/nm-device-macsec.c +++ b/src/devices/nm-device-macsec.c @@ -173,7 +173,7 @@ update_properties (NMDevice *device) ifindex = nm_device_get_ifindex (device); g_return_if_fail (ifindex > 0); - props = nm_platform_link_get_lnk_macsec (NM_PLATFORM_GET, ifindex, &plink); + props = nm_platform_link_get_lnk_macsec (nm_device_get_platform (device), ifindex, &plink); if (!props) { _LOGW (LOGD_PLATFORM, "could not get macsec properties"); @@ -219,7 +219,7 @@ build_supplicant_config (NMDeviceMacsec *self, GError **error) connection = nm_device_get_applied_connection (NM_DEVICE (self)); g_assert (connection); con_uuid = nm_connection_get_uuid (connection); - mtu = nm_platform_link_get_mtu (NM_PLATFORM_GET, + mtu = nm_platform_link_get_mtu (nm_device_get_platform (NM_DEVICE (self)), nm_device_get_ifindex (NM_DEVICE (self))); config = nm_supplicant_config_new (); @@ -714,7 +714,7 @@ create_and_realize (NMDevice *device, parent_ifindex = nm_device_get_ifindex (parent); g_warn_if_fail (parent_ifindex > 0); - plerr = nm_platform_link_macsec_add (NM_PLATFORM_GET, iface, parent_ifindex, &lnk, out_plink); + plerr = nm_platform_link_macsec_add (nm_device_get_platform (device), iface, parent_ifindex, &lnk, out_plink); if (plerr != NM_PLATFORM_ERROR_SUCCESS) { g_set_error (error, NM_DEVICE_ERROR, NM_DEVICE_ERROR_CREATION_FAILED, "Failed to create macsec interface '%s' for '%s': %s", diff --git a/src/devices/nm-device-macvlan.c b/src/devices/nm-device-macvlan.c index 77adf28ec7..cea2b984fc 100644 --- a/src/devices/nm-device-macvlan.c +++ b/src/devices/nm-device-macvlan.c @@ -185,9 +185,9 @@ update_properties (NMDevice *device) const NMPlatformLink *plink; if (priv->props.tap) - props = nm_platform_link_get_lnk_macvtap (NM_PLATFORM_GET, nm_device_get_ifindex (device), &plink); + props = nm_platform_link_get_lnk_macvtap (nm_device_get_platform (device), nm_device_get_ifindex (device), &plink); else - props = nm_platform_link_get_lnk_macvlan (NM_PLATFORM_GET, nm_device_get_ifindex (device), &plink); + props = nm_platform_link_get_lnk_macvlan (nm_device_get_platform (device), nm_device_get_ifindex (device), &plink); if (!props) { _LOGW (LOGD_PLATFORM, "could not get %s properties", priv->props.tap ? "macvtap" : "macvlan"); @@ -251,7 +251,7 @@ create_and_realize (NMDevice *device, lnk.no_promisc = !nm_setting_macvlan_get_promiscuous (s_macvlan); lnk.tap = nm_setting_macvlan_get_tap (s_macvlan); - plerr = nm_platform_link_macvlan_add (NM_PLATFORM_GET, iface, parent_ifindex, &lnk, out_plink); + plerr = nm_platform_link_macvlan_add (nm_device_get_platform (device), iface, parent_ifindex, &lnk, out_plink); if (plerr != NM_PLATFORM_ERROR_SUCCESS) { g_set_error (error, NM_DEVICE_ERROR, NM_DEVICE_ERROR_CREATION_FAILED, "Failed to create %s interface '%s' for '%s': %s", @@ -399,7 +399,7 @@ complete_connection (NMDevice *device, { NMSettingMacvlan *s_macvlan; - nm_utils_complete_generic (NM_PLATFORM_GET, + nm_utils_complete_generic (nm_device_get_platform (device), connection, NM_SETTING_MACVLAN_SETTING_NAME, existing_connections, diff --git a/src/devices/nm-device-tun.c b/src/devices/nm-device-tun.c index dc95495109..b4af441662 100644 --- a/src/devices/nm-device-tun.c +++ b/src/devices/nm-device-tun.c @@ -80,7 +80,7 @@ update_properties (NMDeviceTun *self) ifindex = nm_device_get_ifindex (NM_DEVICE (self)); if (ifindex > 0) { - if (!nm_platform_link_tun_get_properties (NM_PLATFORM_GET, ifindex, &props)) { + if (!nm_platform_link_tun_get_properties (nm_device_get_platform (NM_DEVICE (self)), ifindex, &props)) { _LOGD (LOGD_DEVICE, "tun-properties: cannot loading tun properties from platform for ifindex %d", ifindex); ifindex = 0; } else if (g_strcmp0 (priv->mode, props.mode) != 0) { @@ -138,7 +138,7 @@ complete_connection (NMDevice *device, { NMSettingTun *s_tun; - nm_utils_complete_generic (NM_PLATFORM_GET, + nm_utils_complete_generic (nm_device_get_platform (device), connection, NM_SETTING_TUN_SETTING_NAME, existing_connections, @@ -181,7 +181,7 @@ update_connection (NMDevice *device, NMConnection *connection) nm_connection_add_setting (connection, (NMSetting *) s_tun); } - if (!nm_platform_link_tun_get_properties (NM_PLATFORM_GET, nm_device_get_ifindex (device), &props)) { + if (!nm_platform_link_tun_get_properties (nm_device_get_platform (device), nm_device_get_ifindex (device), &props)) { _LOGW (LOGD_PLATFORM, "failed to get TUN interface info while updating connection."); return; } @@ -232,7 +232,7 @@ create_and_realize (NMDevice *device, user = _nm_utils_ascii_str_to_int64 (nm_setting_tun_get_owner (s_tun), 10, 0, G_MAXINT32, -1); group = _nm_utils_ascii_str_to_int64 (nm_setting_tun_get_group (s_tun), 10, 0, G_MAXINT32, -1); - plerr = nm_platform_link_tun_add (NM_PLATFORM_GET, iface, + plerr = nm_platform_link_tun_add (nm_device_get_platform (device), iface, nm_setting_tun_get_mode (s_tun) == NM_SETTING_TUN_MODE_TAP, user, group, nm_setting_tun_get_pi (s_tun), diff --git a/src/devices/nm-device-veth.c b/src/devices/nm-device-veth.c index 1971aeebf0..11916c59f3 100644 --- a/src/devices/nm-device-veth.c +++ b/src/devices/nm-device-veth.c @@ -69,7 +69,7 @@ update_properties (NMDevice *device) ifindex = nm_device_get_ifindex (device); - if (!nm_platform_link_veth_get_properties (NM_PLATFORM_GET, ifindex, &peer_ifindex)) + if (!nm_platform_link_veth_get_properties (nm_device_get_platform (device), ifindex, &peer_ifindex)) peer_ifindex = 0; nm_device_parent_set_ifindex (device, peer_ifindex); diff --git a/src/devices/nm-device-vlan.c b/src/devices/nm-device-vlan.c index ada4f3295f..06db644656 100644 --- a/src/devices/nm-device-vlan.c +++ b/src/devices/nm-device-vlan.c @@ -186,7 +186,7 @@ update_properties (NMDevice *device) ifindex = nm_device_get_ifindex (device); if (ifindex > 0) - plnk = nm_platform_link_get_lnk_vlan (NM_PLATFORM_GET, ifindex, &plink); + plnk = nm_platform_link_get_lnk_vlan (nm_device_get_platform (device), ifindex, &plink); if ( plnk && plink->parent > 0) @@ -249,7 +249,7 @@ create_and_realize (NMDevice *device, vlan_id = nm_setting_vlan_get_id (s_vlan); - plerr = nm_platform_link_vlan_add (NM_PLATFORM_GET, + plerr = nm_platform_link_vlan_add (nm_device_get_platform (device), iface, parent_ifindex, vlan_id, @@ -425,7 +425,7 @@ complete_connection (NMDevice *device, { NMSettingVlan *s_vlan; - nm_utils_complete_generic (NM_PLATFORM_GET, + nm_utils_complete_generic (nm_device_get_platform (device), connection, NM_SETTING_VLAN_SETTING_NAME, existing_connections, @@ -472,7 +472,7 @@ update_connection (NMDevice *device, NMConnection *connection) nm_connection_add_setting (connection, (NMSetting *) s_vlan); } - polnk = nm_platform_link_get_lnk (NM_PLATFORM_GET, ifindex, NM_LINK_TYPE_VLAN, &plink); + polnk = nm_platform_link_get_lnk (nm_device_get_platform (device), ifindex, NM_LINK_TYPE_VLAN, &plink); if (polnk) vlan_id = polnk->lnk_vlan.id; @@ -556,7 +556,7 @@ act_stage1_prepare (NMDevice *device, NMDeviceStateReason *out_failure_reason) &egress_map, &n_egress_map); - nm_platform_link_vlan_change (NM_PLATFORM_GET, + nm_platform_link_vlan_change (nm_device_get_platform (device), nm_device_get_ifindex (device), NM_VLAN_FLAGS_ALL, nm_setting_vlan_get_flags (s_vlan), @@ -584,7 +584,7 @@ get_configured_mtu (NMDevice *self, gboolean *out_is_user_config) /* Inherit the MTU from parent device, if any */ ifindex = nm_device_parent_get_ifindex (self); if (ifindex > 0) - mtu = nm_platform_link_get_mtu (NM_PLATFORM_GET, ifindex); + mtu = nm_platform_link_get_mtu (nm_device_get_platform (NM_DEVICE (self)), ifindex); return mtu ?: NM_DEVICE_DEFAULT_MTU_WIRED; } diff --git a/src/devices/nm-device-vxlan.c b/src/devices/nm-device-vxlan.c index 619f573a32..d0b88874c1 100644 --- a/src/devices/nm-device-vxlan.c +++ b/src/devices/nm-device-vxlan.c @@ -87,7 +87,7 @@ update_properties (NMDevice *device) GObject *object = G_OBJECT (device); const NMPlatformLnkVxlan *props; - props = nm_platform_link_get_lnk_vxlan (NM_PLATFORM_GET, nm_device_get_ifindex (device), NULL); + props = nm_platform_link_get_lnk_vxlan (nm_device_get_platform (device), nm_device_get_ifindex (device), NULL); if (!props) { _LOGW (LOGD_PLATFORM, "could not get vxlan properties"); return; @@ -217,7 +217,7 @@ create_and_realize (NMDevice *device, props.l2miss = nm_setting_vxlan_get_l2_miss (s_vxlan); props.l3miss = nm_setting_vxlan_get_l3_miss (s_vxlan); - plerr = nm_platform_link_vxlan_add (NM_PLATFORM_GET, iface, &props, out_plink); + plerr = nm_platform_link_vxlan_add (nm_device_get_platform (device), iface, &props, out_plink); if (plerr != NM_PLATFORM_ERROR_SUCCESS) { g_set_error (error, NM_DEVICE_ERROR, NM_DEVICE_ERROR_CREATION_FAILED, "Failed to create VXLAN interface '%s' for '%s': %s", @@ -361,7 +361,7 @@ complete_connection (NMDevice *device, { NMSettingVxlan *s_vxlan; - nm_utils_complete_generic (NM_PLATFORM_GET, + nm_utils_complete_generic (nm_device_get_platform (device), connection, NM_SETTING_VXLAN_SETTING_NAME, existing_connections, diff --git a/src/devices/nm-device.c b/src/devices/nm-device.c index 0f08f7ce60..29ff3741cf 100644 --- a/src/devices/nm-device.c +++ b/src/devices/nm-device.c @@ -56,6 +56,7 @@ #include "settings/nm-settings-connection.h" #include "settings/nm-settings.h" #include "nm-auth-utils.h" +#include "nm-netns.h" #include "nm-dispatcher.h" #include "nm-config.h" #include "dns/nm-dns-manager.h" @@ -445,6 +446,8 @@ typedef struct _NMDevicePrivate { NMSettings *settings; + NMNetns *netns; + NMLldpListener *lldp_listener; NMConnectivityState connectivity_state; guint concheck_periodic_id; @@ -622,6 +625,18 @@ nm_device_get_settings (NMDevice *self) return NM_DEVICE_GET_PRIVATE (self)->settings; } +NMNetns * +nm_device_get_netns (NMDevice *self) +{ + return NM_DEVICE_GET_PRIVATE (self)->netns; +} + +NMPlatform * +nm_device_get_platform (NMDevice *self) +{ + return nm_netns_get_platform (nm_device_get_netns (self)); +} + /*****************************************************************************/ NM_UTILS_LOOKUP_STR_DEFINE_STATIC (_sys_iface_state_to_str, NMDeviceSysIfaceState, @@ -716,7 +731,7 @@ init_ip6_config_dns_priority (NMDevice *self, NMIP6Config *config) static gboolean nm_device_ipv4_sysctl_set (NMDevice *self, const char *property, const char *value) { - NMPlatform *platform = NM_PLATFORM_GET; + NMPlatform *platform = nm_device_get_platform (self); gs_free char *value_to_free = NULL; const char *value_to_set; @@ -737,7 +752,7 @@ nm_device_ipv4_sysctl_set (NMDevice *self, const char *property, const char *val static guint32 nm_device_ipv4_sysctl_get_uint32 (NMDevice *self, const char *property, guint32 fallback) { - return nm_platform_sysctl_get_int_checked (NM_PLATFORM_GET, + return nm_platform_sysctl_get_int_checked (nm_device_get_platform (self), NMP_SYSCTL_PATHID_ABSOLUTE (nm_utils_ip4_property_path (nm_device_get_ip_iface (self), property)), 10, 0, @@ -748,13 +763,13 @@ nm_device_ipv4_sysctl_get_uint32 (NMDevice *self, const char *property, guint32 gboolean nm_device_ipv6_sysctl_set (NMDevice *self, const char *property, const char *value) { - return nm_platform_sysctl_set (NM_PLATFORM_GET, NMP_SYSCTL_PATHID_ABSOLUTE (nm_utils_ip6_property_path (nm_device_get_ip_iface (self), property)), value); + return nm_platform_sysctl_set (nm_device_get_platform (self), NMP_SYSCTL_PATHID_ABSOLUTE (nm_utils_ip6_property_path (nm_device_get_ip_iface (self), property)), value); } static guint32 nm_device_ipv6_sysctl_get_uint32 (NMDevice *self, const char *property, guint32 fallback) { - return nm_platform_sysctl_get_int_checked (NM_PLATFORM_GET, + return nm_platform_sysctl_get_int_checked (nm_device_get_platform (self), NMP_SYSCTL_PATHID_ABSOLUTE (nm_utils_ip6_property_path (nm_device_get_ip_iface (self), property)), 10, 0, @@ -984,7 +999,7 @@ nm_device_set_ip_iface (NMDevice *self, const char *iface) if (nm_streq0 (iface, priv->ip_iface)) { if (!iface) return FALSE; - ifindex = nm_platform_if_nametoindex (NM_PLATFORM_GET, iface); + ifindex = nm_platform_if_nametoindex (nm_device_get_platform (self), iface); if ( ifindex <= 0 || priv->ip_ifindex == ifindex) return FALSE; @@ -1002,7 +1017,7 @@ nm_device_set_ip_iface (NMDevice *self, const char *iface) * with this name still exists and we resolve the ifindex * anew. */ - priv->ip_ifindex = nm_platform_if_nametoindex (NM_PLATFORM_GET, iface); + priv->ip_ifindex = nm_platform_if_nametoindex (nm_device_get_platform (self), iface); if (priv->ip_ifindex > 0) _LOGD (LOGD_DEVICE, "ip-ifname: set ifname '%s', ifindex %d", iface, priv->ip_ifindex); else @@ -1014,11 +1029,11 @@ nm_device_set_ip_iface (NMDevice *self, const char *iface) } if (priv->ip_ifindex > 0) { - if (nm_platform_check_support_user_ipv6ll (NM_PLATFORM_GET)) - nm_platform_link_set_user_ipv6ll_enabled (NM_PLATFORM_GET, priv->ip_ifindex, TRUE); + if (nm_platform_check_support_user_ipv6ll (nm_device_get_platform (self))) + nm_platform_link_set_user_ipv6ll_enabled (nm_device_get_platform (self), priv->ip_ifindex, TRUE); - if (!nm_platform_link_is_up (NM_PLATFORM_GET, priv->ip_ifindex)) - nm_platform_link_set_up (NM_PLATFORM_GET, priv->ip_ifindex, NULL); + if (!nm_platform_link_is_up (nm_device_get_platform (self), priv->ip_ifindex)) + nm_platform_link_set_up (nm_device_get_platform (self), priv->ip_ifindex, NULL); } /* We don't care about any saved values from the old iface */ @@ -1220,7 +1235,7 @@ _stats_timeout_cb (gpointer user_data) _LOGT (LOGD_DEVICE, "stats: refresh %d", ifindex); if (ifindex > 0) - nm_platform_link_refresh (NM_PLATFORM_GET, ifindex); + nm_platform_link_refresh (nm_device_get_platform (self), ifindex); return G_SOURCE_CONTINUE; } @@ -1277,7 +1292,7 @@ _stats_set_refresh_rate (NMDevice *self, guint refresh_rate_ms) * we don't get the result right away. */ ifindex = nm_device_get_ip_ifindex (self); if (ifindex > 0) - nm_platform_link_refresh (NM_PLATFORM_GET, ifindex); + nm_platform_link_refresh (nm_device_get_platform (self), ifindex); priv->stats.timeout_id = g_timeout_add (refresh_rate_ms, _stats_timeout_cb, self); } @@ -1296,7 +1311,7 @@ get_ip_iface_identifier (NMDevice *self, NMUtilsIPv6IfaceId *out_iid) ifindex = nm_device_get_ip_ifindex (self); g_return_val_if_fail (ifindex > 0, FALSE); - pllink = nm_platform_link_get (NM_PLATFORM_GET, ifindex); + pllink = nm_platform_link_get (nm_device_get_platform (self), ifindex); if ( !pllink || NM_IN_SET (pllink->type, NM_LINK_TYPE_NONE, NM_LINK_TYPE_UNKNOWN)) return FALSE; @@ -1574,9 +1589,9 @@ _update_default_route (NMDevice *self, int addr_family, gboolean has, gboolean i *p_is_assumed = is_assumed; if (addr_family == AF_INET) - nm_default_route_manager_ip4_update_default_route (nm_default_route_manager_get (), self); + nm_default_route_manager_ip4_update_default_route (nm_netns_get_default_route_manager (priv->netns), self); else - nm_default_route_manager_ip6_update_default_route (nm_default_route_manager_get (), self); + nm_default_route_manager_ip6_update_default_route (nm_netns_get_default_route_manager (priv->netns), self); } const NMPlatformIP4Route * @@ -2051,7 +2066,7 @@ is_unmanaged_external_down (NMDevice *self, gboolean consider_can) /* Manage externally-created software interfaces only when they are IFF_UP */ if ( priv->ifindex <= 0 || !priv->up - || !(priv->slaves || nm_platform_link_can_assume (NM_PLATFORM_GET, priv->ifindex))) + || !(priv->slaves || nm_platform_link_can_assume (nm_device_get_platform (self), priv->ifindex))) return NM_UNMAN_FLAG_OP_SET_UNMANAGED; return NM_UNMAN_FLAG_OP_SET_MANAGED; @@ -2123,7 +2138,7 @@ nm_device_update_dynamic_ip_setup (NMDevice *self) if (priv->lldp_listener && nm_lldp_listener_is_running (priv->lldp_listener)) { nm_lldp_listener_stop (priv->lldp_listener); - addr = nm_platform_link_get_address (NM_PLATFORM_GET, priv->ifindex, &addr_length); + addr = nm_platform_link_get_address (nm_device_get_platform (self), priv->ifindex, &addr_length); if (!nm_lldp_listener_start (priv->lldp_listener, nm_device_get_ifindex (self), &error)) { _LOGD (LOGD_DEVICE, "LLDP listener %p could not be restarted: %s", @@ -2295,7 +2310,7 @@ device_recheck_slave_status (NMDevice *self, const NMPlatformLink *plink) } else { _LOGW (LOGD_DEVICE, "enslaved to unknown device %d %s", plink->master, - nm_platform_link_get_name (NM_PLATFORM_GET, plink->master)); + nm_platform_link_get_name (nm_device_get_platform (self), plink->master)); } } } @@ -2386,13 +2401,13 @@ device_link_changed (NMDevice *self) priv->device_link_changed_id = 0; ifindex = nm_device_get_ifindex (self); - pllink = nm_platform_link_get (NM_PLATFORM_GET, ifindex); + pllink = nm_platform_link_get (nm_device_get_platform (self), ifindex); if (!pllink) return G_SOURCE_REMOVE; info = *pllink; - udi = nm_platform_link_get_udi (NM_PLATFORM_GET, info.ifindex); + udi = nm_platform_link_get_udi (nm_device_get_platform (self), info.ifindex); if (udi && g_strcmp0 (udi, priv->udi)) { /* Update UDI to what udev gives us */ g_free (priv->udi); @@ -2540,7 +2555,7 @@ device_ip_link_changed (NMDevice *self) if (!priv->ip_ifindex) return G_SOURCE_REMOVE; - pllink = nm_platform_link_get (NM_PLATFORM_GET, priv->ip_ifindex); + pllink = nm_platform_link_get (nm_device_get_platform (self), priv->ip_ifindex); if (!pllink) return G_SOURCE_REMOVE; @@ -2742,7 +2757,7 @@ nm_device_create_and_realize (NMDevice *self, const NMPlatformLink *plink = NULL; /* Must be set before device is realized */ - priv->is_nm_owned = !nm_platform_link_get_by_ifname (NM_PLATFORM_GET, priv->iface); + priv->is_nm_owned = !nm_platform_link_get_by_ifname (nm_device_get_platform (self), priv->iface); _LOGD (LOGD_DEVICE, "create (is %snm-owned)", priv->is_nm_owned ? "" : "not "); @@ -2773,7 +2788,7 @@ update_device_from_platform_link (NMDevice *self, const NMPlatformLink *plink) g_return_if_fail (plink != NULL); - udi = nm_platform_link_get_udi (NM_PLATFORM_GET, plink->ifindex); + udi = nm_platform_link_get_udi (nm_device_get_platform (self), plink->ifindex); if (udi && !g_strcmp0 (udi, priv->udi)) { g_free (priv->udi); priv->udi = g_strdup (udi); @@ -2819,7 +2834,7 @@ check_carrier (NMDevice *self) int ifindex = nm_device_get_ip_ifindex (self); if (!nm_device_has_capability (self, NM_DEVICE_CAP_NONSTANDARD_CARRIER)) - nm_device_set_carrier (self, nm_platform_link_is_connected (NM_PLATFORM_GET, ifindex)); + nm_device_set_carrier (self, nm_platform_link_is_connected (nm_device_get_platform (self), ifindex)); } static void @@ -2893,21 +2908,21 @@ realize_start_setup (NMDevice *self, } if (priv->ifindex > 0) { - priv->physical_port_id = nm_platform_link_get_physical_port_id (NM_PLATFORM_GET, priv->ifindex); + priv->physical_port_id = nm_platform_link_get_physical_port_id (nm_device_get_platform (self), priv->ifindex); _notify (self, PROP_PHYSICAL_PORT_ID); - priv->dev_id = nm_platform_link_get_dev_id (NM_PLATFORM_GET, priv->ifindex); + priv->dev_id = nm_platform_link_get_dev_id (nm_device_get_platform (self), priv->ifindex); - if (nm_platform_link_is_software (NM_PLATFORM_GET, priv->ifindex)) + if (nm_platform_link_is_software (nm_device_get_platform (self), priv->ifindex)) capabilities |= NM_DEVICE_CAP_IS_SOFTWARE; - mtu = nm_platform_link_get_mtu (NM_PLATFORM_GET, priv->ifindex); + mtu = nm_platform_link_get_mtu (nm_device_get_platform (self), priv->ifindex); if (priv->mtu != mtu) { priv->mtu = mtu; _notify (self, PROP_MTU); } - nm_platform_link_get_driver_info (NM_PLATFORM_GET, + nm_platform_link_get_driver_info (nm_device_get_platform (self), priv->ifindex, NULL, &priv->driver_version, @@ -2917,8 +2932,8 @@ realize_start_setup (NMDevice *self, if (priv->firmware_version) _notify (self, PROP_FIRMWARE_VERSION); - if (nm_platform_check_support_user_ipv6ll (NM_PLATFORM_GET)) - priv->nm_ipv6ll = nm_platform_link_get_user_ipv6ll_enabled (NM_PLATFORM_GET, priv->ifindex); + if (nm_platform_check_support_user_ipv6ll (nm_device_get_platform (self))) + priv->nm_ipv6ll = nm_platform_link_get_user_ipv6ll_enabled (nm_device_get_platform (self), priv->ifindex); } if (klass->get_generic_capabilities) @@ -3107,7 +3122,7 @@ nm_device_unrealize (NMDevice *self, gboolean remove_resources, GError **error) if (!NM_DEVICE_GET_CLASS (self)->unrealize (self, error)) return FALSE; } else if (ifindex > 0) { - nm_platform_link_delete (NM_PLATFORM_GET, ifindex); + nm_platform_link_delete (nm_device_get_platform (self), ifindex); } } @@ -3457,7 +3472,7 @@ nm_device_master_release_slaves (NMDevice *self) if (priv->state == NM_DEVICE_STATE_FAILED) reason = NM_DEVICE_STATE_REASON_DEPENDENCY_FAILED; - if (!nm_platform_link_get (NM_PLATFORM_GET, priv->ifindex)) + if (!nm_platform_link_get (nm_device_get_platform (self), priv->ifindex)) configure = FALSE; while (priv->slaves) { @@ -3897,7 +3912,7 @@ device_has_config (NMDevice *self) return TRUE; /* Master-slave relationship is also a configuration */ - if (priv->slaves || nm_platform_link_get_master (NM_PLATFORM_GET, priv->ifindex) > 0) + if (priv->slaves || nm_platform_link_get_master (nm_device_get_platform (self), priv->ifindex) > 0) return TRUE; return FALSE; @@ -4010,7 +4025,7 @@ nm_device_generate_connection (NMDevice *self, NMDevice *master) s_ip6 = nm_ip6_config_create_setting (priv->ip6_config); nm_connection_add_setting (connection, s_ip6); - pllink = nm_platform_link_get (NM_PLATFORM_GET, priv->ifindex); + pllink = nm_platform_link_get (nm_device_get_platform (self), priv->ifindex); if (pllink && pllink->inet6_token.id) { _LOGD (LOGD_IP6, "IPv6 tokenized identifier present"); g_object_set (s_ip6, @@ -4639,7 +4654,7 @@ lldp_init (NMDevice *self, gboolean restart) } if (!nm_lldp_listener_is_running (priv->lldp_listener)) { - addr = nm_platform_link_get_address (NM_PLATFORM_GET, priv->ifindex, &addr_length); + addr = nm_platform_link_get_address (nm_device_get_platform (self), priv->ifindex, &addr_length); if (nm_lldp_listener_start (priv->lldp_listener, nm_device_get_ifindex (self), &error)) _LOGD (LOGD_DEVICE, "LLDP listener %p started", priv->lldp_listener); @@ -4986,7 +5001,7 @@ ipv4_dad_start (NMDevice *self, NMIP4Config **configs, ArpingCallback cb) } timeout = get_ipv4_dad_timeout (self); - hw_addr = nm_platform_link_get_address (NM_PLATFORM_GET, + hw_addr = nm_platform_link_get_address (nm_device_get_platform (self), nm_device_get_ip_ifindex (self), &hw_addr_len); @@ -5191,7 +5206,7 @@ ipv4ll_start (NMDevice *self) } ifindex = nm_device_get_ip_ifindex (self); - addr = nm_platform_link_get_address (NM_PLATFORM_GET, ifindex, &addr_len); + addr = nm_platform_link_get_address (nm_device_get_platform (self), ifindex, &addr_len); if (!addr || addr_len != ETH_ALEN) { _LOGE (LOGD_AUTOIP4, "IPv4LL: can't retrieve hardware address"); return NM_ACT_STAGE_RETURN_FAILURE; @@ -5238,9 +5253,9 @@ _device_get_default_route_from_platform (NMDevice *self, int addr_family, NMPlat GArray *routes; if (addr_family == AF_INET) - routes = nm_platform_ip4_route_get_all (NM_PLATFORM_GET, ifindex, NM_PLATFORM_GET_ROUTE_FLAGS_WITH_DEFAULT); + routes = nm_platform_ip4_route_get_all (nm_device_get_platform (self), ifindex, NM_PLATFORM_GET_ROUTE_FLAGS_WITH_DEFAULT); else - routes = nm_platform_ip6_route_get_all (NM_PLATFORM_GET, ifindex, NM_PLATFORM_GET_ROUTE_FLAGS_WITH_DEFAULT); + routes = nm_platform_ip6_route_get_all (nm_device_get_platform (self), ifindex, NM_PLATFORM_GET_ROUTE_FLAGS_WITH_DEFAULT); if (routes) { guint route_metric = G_MAXUINT32, m; @@ -5472,7 +5487,7 @@ ip4_config_merge_and_apply (NMDevice *self, */ connection_has_default_route - = nm_default_route_manager_ip4_connection_has_default_route (nm_default_route_manager_get (), + = nm_default_route_manager_ip4_connection_has_default_route (nm_netns_get_default_route_manager (priv->netns), connection, &connection_is_never_default); if ( !priv->v4_commit_first_time @@ -5754,7 +5769,7 @@ dhcp4_start (NMDevice *self, nm_exported_object_clear_and_unexport (&priv->dhcp4.config); priv->dhcp4.config = nm_dhcp4_config_new (); - hw_addr = nm_platform_link_get_address (NM_PLATFORM_GET, nm_device_get_ip_ifindex (self), &hw_addr_len); + hw_addr = nm_platform_link_get_address (nm_device_get_platform (self), nm_device_get_ip_ifindex (self), &hw_addr_len); if (hw_addr_len) { tmp = g_byte_array_sized_new (hw_addr_len); g_byte_array_append (tmp, hw_addr, hw_addr_len); @@ -6219,7 +6234,7 @@ ip6_config_merge_and_apply (NMDevice *self, */ connection_has_default_route - = nm_default_route_manager_ip6_connection_has_default_route (nm_default_route_manager_get (), + = nm_default_route_manager_ip6_connection_has_default_route (nm_netns_get_default_route_manager (priv->netns), connection, &connection_is_never_default); if ( !priv->v6_commit_first_time @@ -6284,7 +6299,7 @@ END_ADD_DEFAULT_ROUTE: NMUtilsIPv6IfaceId iid; if (token && nm_utils_ipv6_interface_identifier_get_from_token (&iid, token)) { - nm_platform_link_set_ipv6_token (NM_PLATFORM_GET, + nm_platform_link_set_ipv6_token (nm_device_get_platform (self), nm_device_get_ip_ifindex (self), iid); } @@ -6560,7 +6575,7 @@ dhcp6_start_with_link_ready (NMDevice *self, NMConnection *connection) return FALSE; } - hw_addr = nm_platform_link_get_address (NM_PLATFORM_GET, nm_device_get_ip_ifindex (self), &hw_addr_len); + hw_addr = nm_platform_link_get_address (nm_device_get_platform (self), nm_device_get_ip_ifindex (self), &hw_addr_len); if (hw_addr_len) { tmp = g_byte_array_sized_new (hw_addr_len); g_byte_array_append (tmp, hw_addr, hw_addr_len); @@ -6880,7 +6895,7 @@ check_and_add_ipv6ll_addr (NMDevice *self) } _LOGD (LOGD_IP6, "linklocal6: adding IPv6LL address %s", nm_utils_inet6_ntop (&lladdr, NULL)); - if (!nm_platform_ip6_address_add (NM_PLATFORM_GET, + if (!nm_platform_ip6_address_add (nm_device_get_platform (self), ip_ifindex, lladdr, 64, @@ -7060,7 +7075,7 @@ _commit_mtu (NMDevice *self, const NMIP4Config *config) mtu_desired_orig = mtu_desired; ip6_mtu_orig = ip6_mtu; - mtu_plat = nm_platform_link_get_mtu (NM_PLATFORM_GET, ifindex); + mtu_plat = nm_platform_link_get_mtu (nm_device_get_platform (self), ifindex); if (ip6_mtu) { ip6_mtu = NM_MAX (1280, ip6_mtu); @@ -7102,7 +7117,7 @@ _commit_mtu (NMDevice *self, const NMIP4Config *config) } if (mtu_desired && mtu_desired != mtu_plat) - nm_platform_link_set_mtu (NM_PLATFORM_GET, ifindex, mtu_desired); + nm_platform_link_set_mtu (nm_device_get_platform (self), ifindex, mtu_desired); if (ip6_mtu && ip6_mtu != _IP6_MTU_SYS ()) { nm_device_ipv6_sysctl_set (self, "mtu", @@ -7127,7 +7142,7 @@ ndisc_config_changed (NMNDisc *ndisc, const NMNDiscData *rdata, guint changed_in * addresses as /128. The reason for the /128 is to prevent the kernel * from adding a prefix route for this address. **/ - system_support = nm_platform_check_support_kernel_extended_ifa_flags (NM_PLATFORM_GET); + system_support = nm_platform_check_support_kernel_extended_ifa_flags (nm_device_get_platform (self)); if (system_support) ifa_flags = IFA_F_NOPREFIXROUTE; @@ -7232,7 +7247,7 @@ ndisc_config_changed (NMNDisc *ndisc, const NMNDiscData *rdata, guint changed_in } if (changed & NM_NDISC_CONFIG_HOP_LIMIT) - nm_platform_sysctl_set_ip6_hop_limit_safe (NM_PLATFORM_GET, nm_device_get_ip_iface (self), rdata->hop_limit); + nm_platform_sysctl_set_ip6_hop_limit_safe (nm_device_get_platform (self), nm_device_get_ip_iface (self), rdata->hop_limit); if (changed & NM_NDISC_CONFIG_MTU) { if (priv->ip6_mtu != rdata->mtu) { @@ -7364,7 +7379,7 @@ addrconf6_start (NMDevice *self, NMSettingIP6ConfigPrivacy use_tempaddr) stable_id = _get_stable_id (self, connection, &stable_type); if (stable_id) { - priv->ndisc = nm_lndp_ndisc_new (NM_PLATFORM_GET, + priv->ndisc = nm_lndp_ndisc_new (nm_device_get_platform (self), nm_device_get_ip_ifindex (self), nm_device_get_ip_iface (self), stable_type, @@ -7382,7 +7397,7 @@ addrconf6_start (NMDevice *self, NMSettingIP6ConfigPrivacy use_tempaddr) priv->ndisc_use_tempaddr = use_tempaddr; if ( NM_IN_SET (use_tempaddr, NM_SETTING_IP6_CONFIG_PRIVACY_PREFER_TEMP_ADDR, NM_SETTING_IP6_CONFIG_PRIVACY_PREFER_PUBLIC_ADDR) - && !nm_platform_check_support_kernel_extended_ifa_flags (NM_PLATFORM_GET)) { + && !nm_platform_check_support_kernel_extended_ifa_flags (nm_device_get_platform (self))) { _LOGW (LOGD_IP6, "The kernel does not support extended IFA_FLAGS needed by NM for " "IPv6 private addresses. This feature is not available"); } @@ -7440,7 +7455,7 @@ save_ip6_properties (NMDevice *self) g_hash_table_remove_all (priv->ip6_saved_properties); for (i = 0; i < G_N_ELEMENTS (ip6_properties_to_save); i++) { - value = nm_platform_sysctl_get (NM_PLATFORM_GET, NMP_SYSCTL_PATHID_ABSOLUTE (nm_utils_ip6_property_path (ifname, ip6_properties_to_save[i]))); + value = nm_platform_sysctl_get (nm_device_get_platform (self), NMP_SYSCTL_PATHID_ABSOLUTE (nm_utils_ip6_property_path (ifname, ip6_properties_to_save[i]))); if (value) { g_hash_table_insert (priv->ip6_saved_properties, (char *) ip6_properties_to_save[i], @@ -7480,7 +7495,7 @@ set_nm_ipv6ll (NMDevice *self, gboolean enable) int ifindex = nm_device_get_ip_ifindex (self); char *value; - if (!nm_platform_check_support_user_ipv6ll (NM_PLATFORM_GET)) + if (!nm_platform_check_support_user_ipv6ll (nm_device_get_platform (self))) return; priv->nm_ipv6ll = enable; @@ -7489,7 +7504,7 @@ set_nm_ipv6ll (NMDevice *self, gboolean enable) const char *detail = enable ? "enable" : "disable"; _LOGD (LOGD_IP6, "will %s userland IPv6LL", detail); - plerr = nm_platform_link_set_user_ipv6ll_enabled (NM_PLATFORM_GET, ifindex, enable); + plerr = nm_platform_link_set_user_ipv6ll_enabled (nm_device_get_platform (self), ifindex, enable); if (plerr != NM_PLATFORM_ERROR_SUCCESS) { _NMLOG (plerr == NM_PLATFORM_ERROR_NOT_FOUND ? LOGL_DEBUG : LOGL_WARN, LOGD_IP6, @@ -7500,7 +7515,7 @@ set_nm_ipv6ll (NMDevice *self, gboolean enable) if (enable) { /* Bounce IPv6 to ensure the kernel stops IPv6LL address generation */ - value = nm_platform_sysctl_get (NM_PLATFORM_GET, + value = nm_platform_sysctl_get (nm_device_get_platform (self), NMP_SYSCTL_PATHID_ABSOLUTE (nm_utils_ip6_property_path (nm_device_get_ip_iface (self), "disable_ipv6"))); if (g_strcmp0 (value, "0") == 0) nm_device_ipv6_sysctl_set (self, "disable_ipv6", "1"); @@ -7567,7 +7582,7 @@ _ip6_privacy_get (NMDevice *self) * Instead of reading static config files in /etc, just read the current sysctl value. * This works as NM only writes to "/proc/sys/net/ipv6/conf/IFNAME/use_tempaddr", but leaves * the "default" entry untouched. */ - ip6_privacy = nm_platform_sysctl_get_int32 (NM_PLATFORM_GET, NMP_SYSCTL_PATHID_ABSOLUTE ("/proc/sys/net/ipv6/conf/default/use_tempaddr"), NM_SETTING_IP6_CONFIG_PRIVACY_UNKNOWN); + ip6_privacy = nm_platform_sysctl_get_int32 (nm_device_get_platform (self), NMP_SYSCTL_PATHID_ABSOLUTE ("/proc/sys/net/ipv6/conf/default/use_tempaddr"), NM_SETTING_IP6_CONFIG_PRIVACY_UNKNOWN); return _ip6_privacy_clamp (ip6_privacy); } @@ -7812,7 +7827,7 @@ activate_stage3_ip_config_start (NMDevice *self) nm_device_state_changed (self, NM_DEVICE_STATE_IP_CONFIG, NM_DEVICE_STATE_REASON_NONE); /* Device should be up before we can do anything with it */ - if (!nm_platform_link_is_up (NM_PLATFORM_GET, nm_device_get_ip_ifindex (self))) + if (!nm_platform_link_is_up (nm_device_get_platform (self), nm_device_get_ip_ifindex (self))) _LOGW (LOGD_DEVICE, "interface %s not up for IP configuration", nm_device_get_ip_iface (self)); /* If the device is a slave, then we don't do any IP configuration but we @@ -8064,7 +8079,7 @@ nm_device_activate_schedule_ip6_config_timeout (NMDevice *self) } static gboolean -share_init (void) +share_init (NMDevice *self) { char *modules[] = { "ip_tables", "iptable_nat", "nf_nat_ftp", "nf_nat_irc", "nf_nat_sip", "nf_nat_tftp", "nf_nat_pptp", "nf_nat_h323", @@ -8072,14 +8087,14 @@ share_init (void) char **iter; int errsv; - if (!nm_platform_sysctl_set (NM_PLATFORM_GET, NMP_SYSCTL_PATHID_ABSOLUTE ("/proc/sys/net/ipv4/ip_forward"), "1")) { + if (!nm_platform_sysctl_set (nm_device_get_platform (self), NMP_SYSCTL_PATHID_ABSOLUTE ("/proc/sys/net/ipv4/ip_forward"), "1")) { errsv = errno; nm_log_err (LOGD_SHARING, "share: error enabling IPv4 forwarding: (%d) %s", errsv, strerror (errsv)); return FALSE; } - if (!nm_platform_sysctl_set (NM_PLATFORM_GET, NMP_SYSCTL_PATHID_ABSOLUTE ("/proc/sys/net/ipv4/ip_dynaddr"), "1")) { + if (!nm_platform_sysctl_set (nm_device_get_platform (self), NMP_SYSCTL_PATHID_ABSOLUTE ("/proc/sys/net/ipv4/ip_dynaddr"), "1")) { errsv = errno; nm_log_err (LOGD_SHARING, "share: error enabling dynamic addresses: (%d) %s", errsv, strerror (errsv)); @@ -8126,7 +8141,7 @@ start_sharing (NMDevice *self, NMIP4Config *config) if (!inet_ntop (AF_INET, &network, str_addr, sizeof (str_addr))) return FALSE; - if (!share_init ()) + if (!share_init (self)) return FALSE; req = nm_device_get_act_request (self); @@ -8182,7 +8197,7 @@ arp_announce (NMDevice *self) arp_cleanup (self); - hw_addr = nm_platform_link_get_address (NM_PLATFORM_GET, + hw_addr = nm_platform_link_get_address (nm_device_get_platform (self), nm_device_get_ip_ifindex (self), &hw_addr_len); @@ -8233,9 +8248,9 @@ activate_stage5_ip4_config_commit (NMDevice *self) /* Interface must be IFF_UP before IP config can be applied */ ip_ifindex = nm_device_get_ip_ifindex (self); - if (!nm_platform_link_is_up (NM_PLATFORM_GET, ip_ifindex) && !nm_device_sys_iface_state_is_external_or_assume (self)) { - nm_platform_link_set_up (NM_PLATFORM_GET, ip_ifindex, NULL); - if (!nm_platform_link_is_up (NM_PLATFORM_GET, ip_ifindex)) + if (!nm_platform_link_is_up (nm_device_get_platform (self), ip_ifindex) && !nm_device_sys_iface_state_is_external_or_assume (self)) { + nm_platform_link_set_up (nm_device_get_platform (self), ip_ifindex, NULL); + if (!nm_platform_link_is_up (nm_device_get_platform (self), ip_ifindex)) _LOGW (LOGD_DEVICE, "interface %s not up for IP configuration", nm_device_get_ip_iface (self)); } @@ -8342,7 +8357,7 @@ dad6_get_pending_addresses (NMDevice *self) num = nm_ip6_config_get_num_addresses (confs[i]); for (j = 0; j < num; j++) { addr = nm_ip6_config_get_address (confs[i], j); - pl_addr = nm_platform_ip6_address_get (NM_PLATFORM_GET, + pl_addr = nm_platform_ip6_address_get (nm_device_get_platform (self), ifindex, addr->address, addr->plen); @@ -8382,9 +8397,9 @@ activate_stage5_ip6_config_commit (NMDevice *self) /* Interface must be IFF_UP before IP config can be applied */ ip_ifindex = nm_device_get_ip_ifindex (self); - if (!nm_platform_link_is_up (NM_PLATFORM_GET, ip_ifindex) && !nm_device_sys_iface_state_is_external_or_assume (self)) { - nm_platform_link_set_up (NM_PLATFORM_GET, ip_ifindex, NULL); - if (!nm_platform_link_is_up (NM_PLATFORM_GET, ip_ifindex)) + if (!nm_platform_link_is_up (nm_device_get_platform (self), ip_ifindex) && !nm_device_sys_iface_state_is_external_or_assume (self)) { + nm_platform_link_set_up (nm_device_get_platform (self), ip_ifindex, NULL); + if (!nm_platform_link_is_up (nm_device_get_platform (self), ip_ifindex)) _LOGW (LOGD_DEVICE, "interface %s not up for IP configuration", nm_device_get_ip_iface (self)); } @@ -8411,7 +8426,7 @@ activate_stage5_ip6_config_commit (NMDevice *self) method = nm_utils_get_ip_config_method (connection, NM_TYPE_SETTING_IP6_CONFIG); if (strcmp (method, NM_SETTING_IP6_CONFIG_METHOD_SHARED) == 0) { - if (!nm_platform_sysctl_set (NM_PLATFORM_GET, NMP_SYSCTL_PATHID_ABSOLUTE ("/proc/sys/net/ipv6/conf/all/forwarding"), "1")) { + if (!nm_platform_sysctl_set (nm_device_get_platform (self), NMP_SYSCTL_PATHID_ABSOLUTE ("/proc/sys/net/ipv6/conf/all/forwarding"), "1")) { errsv = errno; _LOGE (LOGD_SHARING, "share: error enabling IPv6 forwarding: (%d) %s", errsv, strerror (errsv)); nm_device_ip_method_failed (self, AF_INET6, NM_DEVICE_STATE_REASON_SHARED_START_FAILED); @@ -8598,7 +8613,7 @@ delete_on_deactivate_link_delete (gpointer user_data) if (!nm_device_unrealize (data->device, TRUE, &error)) _LOGD (LOGD_DEVICE, "delete_on_deactivate: unrealizing %d failed (%s)", data->ifindex, error->message); } else - nm_platform_link_delete (NM_PLATFORM_GET, data->ifindex); + nm_platform_link_delete (nm_device_get_platform (self), data->ifindex); g_free (data); return FALSE; @@ -9640,7 +9655,10 @@ nm_device_set_ip4_config (NMDevice *self, /* For assumed devices we must not touch the kernel-routes, such as the device-route. * FIXME: this is wrong in case where "assumed" means "take-over-seamlessly". In this * case, we should manage the device route, for example on new DHCP lease. */ - success = nm_ip4_config_commit (new_config, ip_ifindex, + success = nm_ip4_config_commit (new_config, + nm_device_get_platform (self), + nm_netns_get_route_manager (priv->netns), + ip_ifindex, routes_full_sync, assumed ? (gint64) -1 : (gint64) default_route_metric); } @@ -9673,7 +9691,7 @@ nm_device_set_ip4_config (NMDevice *self, g_clear_object (&priv->dev_ip4_config); } - def_route_changed = nm_default_route_manager_ip4_update_default_route (nm_default_route_manager_get (), self); + def_route_changed = nm_default_route_manager_ip4_update_default_route (nm_netns_get_default_route_manager (priv->netns), self); concheck_periodic_update (self); if (!nm_device_sys_iface_state_is_external_or_assume (self)) @@ -9811,6 +9829,8 @@ nm_device_set_ip6_config (NMDevice *self, if (commit && new_config) { _commit_mtu (self, priv->ip4_config); success = nm_ip6_config_commit (new_config, + nm_device_get_platform (self), + nm_netns_get_route_manager (priv->netns), ip_ifindex, routes_full_sync); } @@ -9841,7 +9861,7 @@ nm_device_set_ip6_config (NMDevice *self, nm_exported_object_get_path (NM_EXPORTED_OBJECT (old_config))); } - def_route_changed = nm_default_route_manager_ip6_update_default_route (nm_default_route_manager_get (), self); + def_route_changed = nm_default_route_manager_ip6_update_default_route (nm_netns_get_default_route_manager (priv->netns), self); if (has_changes) { NMSettingsConnection *settings_connection; @@ -10206,7 +10226,7 @@ nm_device_is_up (NMDevice *self) g_return_val_if_fail (NM_IS_DEVICE (self), FALSE); ifindex = nm_device_get_ip_ifindex (self); - return ifindex > 0 ? nm_platform_link_is_up (NM_PLATFORM_GET, ifindex) : TRUE; + return ifindex > 0 ? nm_platform_link_is_up (nm_device_get_platform (self), ifindex) : TRUE; } gboolean @@ -10231,7 +10251,7 @@ nm_device_bring_up (NMDevice *self, gboolean block, gboolean *no_firmware) if (ifindex <= 0) { /* assume success. */ } else { - if (!nm_platform_link_set_up (NM_PLATFORM_GET, ifindex, no_firmware)) + if (!nm_platform_link_set_up (nm_device_get_platform (self), ifindex, no_firmware)) return FALSE; } @@ -10245,7 +10265,7 @@ nm_device_bring_up (NMDevice *self, gboolean block, gboolean *no_firmware) do { g_usleep (200); - if (!nm_platform_link_refresh (NM_PLATFORM_GET, ifindex)) + if (!nm_platform_link_refresh (nm_device_get_platform (self), ifindex)) return FALSE; device_is_up = nm_device_is_up (self); } while (!device_is_up && nm_utils_get_monotonic_timestamp_us () < wait_until); @@ -10310,7 +10330,7 @@ nm_device_take_down (NMDevice *self, gboolean block) return; } - if (!nm_platform_link_set_down (NM_PLATFORM_GET, ifindex)) + if (!nm_platform_link_set_down (nm_device_get_platform (self), ifindex)) return; device_is_up = nm_device_is_up (self); @@ -10319,7 +10339,7 @@ nm_device_take_down (NMDevice *self, gboolean block) do { g_usleep (200); - if (!nm_platform_link_refresh (NM_PLATFORM_GET, ifindex)) + if (!nm_platform_link_refresh (nm_device_get_platform (self), ifindex)) return; device_is_up = nm_device_is_up (self); } while (device_is_up && nm_utils_get_monotonic_timestamp_us () < wait_until); @@ -10502,7 +10522,9 @@ update_ip4_config (NMDevice *self, gboolean initial) /* IPv4 */ g_clear_object (&priv->ext_ip4_config); - priv->ext_ip4_config = nm_ip4_config_capture (ifindex, capture_resolv_conf); + priv->ext_ip4_config = nm_ip4_config_capture (nm_device_get_platform (self), + ifindex, + capture_resolv_conf); if (priv->ext_ip4_config) { if (initial) { g_clear_object (&priv->dev_ip4_config); @@ -10594,7 +10616,7 @@ update_ip6_config (NMDevice *self, gboolean initial) /* IPv6 */ g_clear_object (&priv->ext_ip6_config); g_clear_object (&priv->ext_ip6_config_captured); - priv->ext_ip6_config_captured = nm_ip6_config_capture (ifindex, capture_resolv_conf, NM_SETTING_IP6_CONFIG_PRIVACY_UNKNOWN); + priv->ext_ip6_config_captured = nm_ip6_config_capture (nm_device_get_platform (self), ifindex, capture_resolv_conf, NM_SETTING_IP6_CONFIG_PRIVACY_UNKNOWN); if (priv->ext_ip6_config_captured) { priv->ext_ip6_config = nm_ip6_config_new_cloned (priv->ext_ip6_config_captured); @@ -10692,7 +10714,7 @@ queued_ip6_config_change (gpointer user_data) update_ip6_config (self, FALSE); if (priv->state < NM_DEVICE_STATE_DEACTIVATING - && nm_platform_link_get (NM_PLATFORM_GET, priv->ifindex)) { + && nm_platform_link_get (nm_device_get_platform (self), priv->ifindex)) { /* Handle DAD failures */ for (iter = priv->dad6_failed_addrs; iter; iter = g_slist_next (iter)) { NMPlatformIP6Address *addr = iter->data; @@ -11216,7 +11238,7 @@ nm_device_set_unmanaged_by_user_udev (NMDevice *self) ifindex = self->_priv->ifindex; if ( ifindex <= 0 - || !nm_platform_link_get_unmanaged (NM_PLATFORM_GET, ifindex, &platform_unmanaged)) + || !nm_platform_link_get_unmanaged (nm_device_get_platform (self), ifindex, &platform_unmanaged)) return; nm_device_set_unmanaged_by_flags (self, @@ -11688,7 +11710,7 @@ cp_connection_removed (NMConnectionProvider *cp, NMConnection *connection, gpoin gboolean nm_device_supports_vlans (NMDevice *self) { - return nm_platform_link_supports_vlans (NM_PLATFORM_GET, nm_device_get_ifindex (self)); + return nm_platform_link_supports_vlans (nm_device_get_platform (self), nm_device_get_ifindex (self)); } /** @@ -11968,14 +11990,14 @@ nm_device_cleanup (NMDevice *self, NMDeviceStateReason reason, CleanupType clean /* slave: mark no longer enslaved */ if ( priv->master - && nm_platform_link_get_master (NM_PLATFORM_GET, priv->ifindex) <= 0) + && nm_platform_link_get_master (nm_device_get_platform (self), priv->ifindex) <= 0) nm_device_master_release_one_slave (priv->master, self, FALSE, NM_DEVICE_STATE_REASON_CONNECTION_ASSUMED); /* Take out any entries in the routing table and any IP address the device had. */ ifindex = nm_device_get_ip_ifindex (self); if (ifindex > 0) { - nm_route_manager_route_flush (nm_route_manager_get (), ifindex); - nm_platform_address_flush (NM_PLATFORM_GET, ifindex); + nm_route_manager_route_flush (nm_netns_get_route_manager (priv->netns), ifindex); + nm_platform_address_flush (nm_device_get_platform (self), ifindex); } } @@ -12006,7 +12028,7 @@ nm_device_cleanup (NMDevice *self, NMDeviceStateReason reason, CleanupType clean _LOGT (LOGD_DEVICE, "mtu: reset device-mtu: %u, ipv6-mtu: %u, ifindex: %d", (guint) priv->mtu_initial, (guint) priv->ip6_mtu_initial, ifindex); if (priv->mtu_initial) - nm_platform_link_set_mtu (NM_PLATFORM_GET, ifindex, priv->mtu_initial); + nm_platform_link_set_mtu (nm_device_get_platform (self), ifindex, priv->mtu_initial); if (priv->ip6_mtu_initial) { char sbuf[64]; @@ -12805,7 +12827,7 @@ nm_device_update_hw_address (NMDevice *self) if (priv->ifindex <= 0) return FALSE; - hwaddr = nm_platform_link_get_address (NM_PLATFORM_GET, priv->ifindex, &hwaddrlen); + hwaddr = nm_platform_link_get_address (nm_device_get_platform (self), priv->ifindex, &hwaddrlen); if ( priv->type == NM_DEVICE_TYPE_ETHERNET && hwaddr @@ -12899,7 +12921,7 @@ nm_device_update_permanent_hw_address (NMDevice *self, gboolean force_freeze) /* the user is advised to configure stable MAC addresses for software devices via * UDEV. Thus, check whether the link is fully initialized. */ - pllink = nm_platform_link_get (NM_PLATFORM_GET, ifindex); + pllink = nm_platform_link_get (nm_device_get_platform (self), ifindex); if ( !pllink || !pllink->initialized) { if (!force_freeze) { @@ -12908,7 +12930,7 @@ nm_device_update_permanent_hw_address (NMDevice *self, gboolean force_freeze) return; } /* try to refresh the link just to give UDEV a bit more time... */ - nm_platform_link_refresh (NM_PLATFORM_GET, ifindex); + nm_platform_link_refresh (nm_device_get_platform (self), ifindex); /* maybe the MAC address changed... */ nm_device_update_hw_address (self); } else if (!priv->hw_addr_len) @@ -12922,7 +12944,7 @@ nm_device_update_permanent_hw_address (NMDevice *self, gboolean force_freeze) return; } - success_read = nm_platform_link_get_permanent_address (NM_PLATFORM_GET, ifindex, buf, &len); + success_read = nm_platform_link_get_permanent_address (nm_device_get_platform (self), ifindex, buf, &len); if (success_read && priv->hw_addr_len == len) { priv->hw_addr_perm_fake = FALSE; priv->hw_addr_perm = nm_utils_hwaddr_ntoa (buf, len); @@ -13110,7 +13132,7 @@ _hw_addr_set (NMDevice *self, nm_device_take_down (self, FALSE); } - plerr = nm_platform_link_set_address (NM_PLATFORM_GET, nm_device_get_ip_ifindex (self), addr_bytes, addr_len); + plerr = nm_platform_link_set_address (nm_device_get_platform (self), nm_device_get_ip_ifindex (self), addr_bytes, addr_len); success = (plerr == NM_PLATFORM_ERROR_SUCCESS); if (success) { /* MAC address succesfully changed; update the current MAC to match */ @@ -13141,7 +13163,7 @@ _hw_addr_set (NMDevice *self, poll_end = nm_utils_get_monotonic_timestamp_us () + (100 * 1000); for (;;) { - if (!nm_platform_link_refresh (NM_PLATFORM_GET, nm_device_get_ip_ifindex (self))) + if (!nm_platform_link_refresh (nm_device_get_platform (self), nm_device_get_ip_ifindex (self))) goto handle_fail; if (!nm_device_update_hw_address (self)) goto handle_wait; @@ -13542,6 +13564,8 @@ nm_device_init (NMDevice *self) self->_priv = priv; + priv->netns = g_object_ref (NM_NETNS_GET); + priv->type = NM_DEVICE_TYPE_UNKNOWN; priv->capabilities = NM_DEVICE_CAP_NM_SUPPORTED; priv->state = NM_DEVICE_STATE_UNMANAGED; @@ -13584,7 +13608,7 @@ constructor (GType type, if ( priv->iface && G_LIKELY (!nm_utils_get_testing ())) { - pllink = nm_platform_link_get_by_ifname (NM_PLATFORM_GET, priv->iface); + pllink = nm_platform_link_get_by_ifname (nm_device_get_platform (self), priv->iface); if (pllink && link_type_compatible (self, pllink->type, NULL, NULL)) { priv->ifindex = pllink->ifindex; @@ -13620,14 +13644,14 @@ constructed (GObject *object) priv->capabilities |= NM_DEVICE_GET_CLASS (self)->get_generic_capabilities (self); /* Watch for external IP config changes */ - platform = NM_PLATFORM_GET; + platform = nm_device_get_platform (self); g_signal_connect (platform, NM_PLATFORM_SIGNAL_IP4_ADDRESS_CHANGED, G_CALLBACK (device_ipx_changed), self); g_signal_connect (platform, NM_PLATFORM_SIGNAL_IP6_ADDRESS_CHANGED, G_CALLBACK (device_ipx_changed), self); g_signal_connect (platform, NM_PLATFORM_SIGNAL_IP4_ROUTE_CHANGED, G_CALLBACK (device_ipx_changed), self); g_signal_connect (platform, NM_PLATFORM_SIGNAL_IP6_ROUTE_CHANGED, G_CALLBACK (device_ipx_changed), self); g_signal_connect (platform, NM_PLATFORM_SIGNAL_LINK_CHANGED, G_CALLBACK (link_changed_cb), self); - g_signal_connect (nm_route_manager_get (), NM_ROUTE_MANAGER_IP4_ROUTES_CHANGED, + g_signal_connect (nm_netns_get_route_manager (priv->netns), NM_ROUTE_MANAGER_IP4_ROUTES_CHANGED, G_CALLBACK (ip4_routes_changed_changed_cb), self); priv->settings = g_object_ref (NM_SETTINGS_GET); @@ -13664,11 +13688,11 @@ dispose (GObject *object) _parent_set_ifindex (self, 0, FALSE); - platform = NM_PLATFORM_GET; + platform = nm_device_get_platform (self); g_signal_handlers_disconnect_by_func (platform, G_CALLBACK (device_ipx_changed), self); g_signal_handlers_disconnect_by_func (platform, G_CALLBACK (link_changed_cb), self); - g_signal_handlers_disconnect_by_func (nm_route_manager_get (), + g_signal_handlers_disconnect_by_func (nm_netns_get_route_manager (priv->netns), G_CALLBACK (ip4_routes_changed_changed_cb), self); g_slist_free_full (priv->arping.dad_list, (GDestroyNotify) nm_arping_manager_destroy); @@ -13775,6 +13799,8 @@ finalize (GObject *object) * and thus @settings might be unset. */ if (priv->settings) g_object_unref (priv->settings); + + g_object_unref (priv->netns); } static void diff --git a/src/devices/nm-device.h b/src/devices/nm-device.h index eedd2fcd1c..f70a3e3ef5 100644 --- a/src/devices/nm-device.h +++ b/src/devices/nm-device.h @@ -410,6 +410,9 @@ typedef void (*NMDeviceAuthRequestFunc) (NMDevice *device, GType nm_device_get_type (void); +NMNetns *nm_device_get_netns (NMDevice *self); +NMPlatform *nm_device_get_platform (NMDevice *self); + const char * nm_device_get_udi (NMDevice *dev); const char * nm_device_get_iface (NMDevice *dev); int nm_device_get_ifindex (NMDevice *dev); diff --git a/src/devices/team/nm-device-team.c b/src/devices/team/nm-device-team.c index 6906c759d6..1c4d2ef6d2 100644 --- a/src/devices/team/nm-device-team.c +++ b/src/devices/team/nm-device-team.c @@ -127,7 +127,7 @@ complete_connection (NMDevice *device, { NMSettingTeam *s_team; - nm_utils_complete_generic (NM_PLATFORM_GET, + nm_utils_complete_generic (nm_device_get_platform (device), connection, NM_SETTING_TEAM_SETTING_NAME, existing_connections, @@ -721,7 +721,7 @@ enslave_slave (NMDevice *device, } } } - success = nm_platform_link_enslave (NM_PLATFORM_GET, + success = nm_platform_link_enslave (nm_device_get_platform (device), nm_device_get_ip_ifindex (device), nm_device_get_ip_ifindex (slave)); nm_device_bring_up (slave, TRUE, &no_firmware); @@ -751,7 +751,7 @@ release_slave (NMDevice *device, gboolean success, no_firmware = FALSE; if (configure) { - success = nm_platform_link_release (NM_PLATFORM_GET, + success = nm_platform_link_release (nm_device_get_platform (device), nm_device_get_ip_ifindex (device), nm_device_get_ip_ifindex (slave)); @@ -786,7 +786,7 @@ create_and_realize (NMDevice *device, const char *iface = nm_device_get_iface (device); NMPlatformError plerr; - plerr = nm_platform_link_team_add (NM_PLATFORM_GET, iface, out_plink); + plerr = nm_platform_link_team_add (nm_device_get_platform (device), iface, out_plink); if (plerr != NM_PLATFORM_ERROR_SUCCESS) { g_set_error (error, NM_DEVICE_ERROR, NM_DEVICE_ERROR_CREATION_FAILED, "Failed to create team master interface '%s' for '%s': %s", diff --git a/src/devices/wifi/nm-device-olpc-mesh.c b/src/devices/wifi/nm-device-olpc-mesh.c index 5f33848d4c..248119317e 100644 --- a/src/devices/wifi/nm-device-olpc-mesh.c +++ b/src/devices/wifi/nm-device-olpc-mesh.c @@ -148,7 +148,7 @@ complete_connection (NMDevice *device, } - nm_utils_complete_generic (NM_PLATFORM_GET, + nm_utils_complete_generic (nm_device_get_platform (device), connection, NM_SETTING_OLPC_MESH_SETTING_NAME, existing_connections, @@ -200,10 +200,12 @@ act_stage1_prepare (NMDevice *device, NMDeviceStateReason *out_failure_reason) static void _mesh_set_channel (NMDeviceOlpcMesh *self, guint32 channel) { + NMPlatform *platform; int ifindex = nm_device_get_ifindex (NM_DEVICE (self)); - if (nm_platform_mesh_get_channel (NM_PLATFORM_GET, ifindex) != channel) { - if (nm_platform_mesh_set_channel (NM_PLATFORM_GET, ifindex, channel)) + platform = nm_device_get_platform (NM_DEVICE (self)); + if (nm_platform_mesh_get_channel (platform, ifindex) != channel) { + if (nm_platform_mesh_set_channel (platform, ifindex, channel)) _notify (self, PROP_ACTIVE_CHANNEL); } } @@ -229,7 +231,7 @@ act_stage2_config (NMDevice *device, NMDeviceStateReason *out_failure_reason) _mesh_set_channel (self, channel); ssid = nm_setting_olpc_mesh_get_ssid (s_mesh); - nm_platform_mesh_set_ssid (NM_PLATFORM_GET, + nm_platform_mesh_set_ssid (nm_device_get_platform (device), nm_device_get_ifindex (device), g_bytes_get_data (ssid, NULL), g_bytes_get_size (ssid)); @@ -429,15 +431,16 @@ static void get_property (GObject *object, guint prop_id, GValue *value, GParamSpec *pspec) { - NMDeviceOlpcMesh *device = NM_DEVICE_OLPC_MESH (object); - NMDeviceOlpcMeshPrivate *priv = NM_DEVICE_OLPC_MESH_GET_PRIVATE (device); + NMDeviceOlpcMesh *self = NM_DEVICE_OLPC_MESH (object); + NMDevice *device = NM_DEVICE (self); + NMDeviceOlpcMeshPrivate *priv = NM_DEVICE_OLPC_MESH_GET_PRIVATE (self); switch (prop_id) { case PROP_COMPANION: nm_utils_g_value_set_object_path (value, priv->companion); break; case PROP_ACTIVE_CHANNEL: - g_value_set_uint (value, nm_platform_mesh_get_channel (NM_PLATFORM_GET, nm_device_get_ifindex (NM_DEVICE (device)))); + g_value_set_uint (value, nm_platform_mesh_get_channel (nm_device_get_platform (device), nm_device_get_ifindex (device))); break; default: G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); diff --git a/src/devices/wifi/nm-device-wifi.c b/src/devices/wifi/nm-device-wifi.c index 7cc7ceb2fa..7359be96ea 100644 --- a/src/devices/wifi/nm-device-wifi.c +++ b/src/devices/wifi/nm-device-wifi.c @@ -444,7 +444,7 @@ periodic_update (NMDeviceWifi *self) if (priv->current_ap) { /* Smooth out the strength to work around crappy drivers */ - percent = nm_platform_wifi_get_quality (NM_PLATFORM_GET, ifindex); + percent = nm_platform_wifi_get_quality (nm_device_get_platform (NM_DEVICE (self)), ifindex); if (percent >= 0 || ++priv->invalid_strength_counter > 3) { if (nm_wifi_ap_set_strength (priv->current_ap, (gint8) percent)) { #ifdef NM_MORE_LOGGING @@ -455,7 +455,7 @@ periodic_update (NMDeviceWifi *self) } } - new_rate = nm_platform_wifi_get_rate (NM_PLATFORM_GET, ifindex); + new_rate = nm_platform_wifi_get_rate (nm_device_get_platform (NM_DEVICE (self)), ifindex); if (new_rate != priv->rate) { priv->rate = new_rate; _notify (self, PROP_BITRATE); @@ -541,14 +541,14 @@ deactivate (NMDevice *device) set_current_ap (self, NULL, TRUE); /* Clear any critical protocol notification in the Wi-Fi stack */ - nm_platform_wifi_indicate_addressing_running (NM_PLATFORM_GET, ifindex, FALSE); + nm_platform_wifi_indicate_addressing_running (nm_device_get_platform (device), ifindex, FALSE); /* Ensure we're in infrastructure mode after deactivation; some devices * (usually older ones) don't scan well in adhoc mode. */ - if (nm_platform_wifi_get_mode (NM_PLATFORM_GET, ifindex) != NM_802_11_MODE_INFRA) { + if (nm_platform_wifi_get_mode (nm_device_get_platform (device), ifindex) != NM_802_11_MODE_INFRA) { nm_device_take_down (NM_DEVICE (self), TRUE); - nm_platform_wifi_set_mode (NM_PLATFORM_GET, ifindex, NM_802_11_MODE_INFRA); + nm_platform_wifi_set_mode (nm_device_get_platform (device), ifindex, NM_802_11_MODE_INFRA); nm_device_bring_up (NM_DEVICE (self), TRUE, NULL); } @@ -901,7 +901,7 @@ complete_connection (NMDevice *device, str_ssid = nm_utils_ssid_to_utf8 (ssid->data, ssid->len); - nm_utils_complete_generic (NM_PLATFORM_GET, + nm_utils_complete_generic (nm_device_get_platform (device), connection, NM_SETTING_WIRELESS_SETTING_NAME, existing_connections, @@ -2374,7 +2374,7 @@ build_supplicant_config (NMDeviceWifi *self, if (s_wireless_sec) { NMSetting8021x *s_8021x; const char *con_uuid = nm_connection_get_uuid (connection); - guint32 mtu = nm_platform_link_get_mtu (NM_PLATFORM_GET, + guint32 mtu = nm_platform_link_get_mtu (nm_device_get_platform (NM_DEVICE (self)), nm_device_get_ifindex (NM_DEVICE (self))); g_assert (con_uuid); @@ -2506,6 +2506,7 @@ ensure_hotspot_frequency (NMDeviceWifi *self, NMSettingWireless *s_wifi, NMWifiAP *ap) { + NMDevice *device = NM_DEVICE (self); const char *band = nm_setting_wireless_get_band (s_wifi); const guint32 a_freqs[] = { 5180, 5200, 5220, 5745, 5765, 5785, 5805, 0 }; const guint32 bg_freqs[] = { 2412, 2437, 2462, 2472, 0 }; @@ -2517,9 +2518,9 @@ ensure_hotspot_frequency (NMDeviceWifi *self, return; if (g_strcmp0 (band, "a") == 0) - freq = nm_platform_wifi_find_frequency (NM_PLATFORM_GET, nm_device_get_ifindex (NM_DEVICE (self)), a_freqs); + freq = nm_platform_wifi_find_frequency (nm_device_get_platform (device), nm_device_get_ifindex (device), a_freqs); else - freq = nm_platform_wifi_find_frequency (NM_PLATFORM_GET, nm_device_get_ifindex (NM_DEVICE (self)), bg_freqs); + freq = nm_platform_wifi_find_frequency (nm_device_get_platform (device), nm_device_get_ifindex (device), bg_freqs); if (!freq) freq = (g_strcmp0 (band, "a") == 0) ? 5180 : 2462; @@ -2555,7 +2556,7 @@ set_powersave (NMDevice *device) if (powersave == NM_SETTING_WIRELESS_POWERSAVE_IGNORE) return; - nm_platform_wifi_set_powersave (NM_PLATFORM_GET, + nm_platform_wifi_set_powersave (nm_device_get_platform (device), nm_device_get_ifindex (device), powersave == NM_SETTING_WIRELESS_POWERSAVE_ENABLE); } @@ -2689,7 +2690,7 @@ act_stage3_ip4_config_start (NMDevice *device, /* Indicate that a critical protocol is about to start */ if (strcmp (method, NM_SETTING_IP4_CONFIG_METHOD_AUTO) == 0) - nm_platform_wifi_indicate_addressing_running (NM_PLATFORM_GET, nm_device_get_ifindex (device), TRUE); + nm_platform_wifi_indicate_addressing_running (nm_device_get_platform (device), nm_device_get_ifindex (device), TRUE); return NM_DEVICE_CLASS (nm_device_wifi_parent_class)->act_stage3_ip4_config_start (device, out_config, out_failure_reason); } @@ -2713,7 +2714,7 @@ act_stage3_ip6_config_start (NMDevice *device, /* Indicate that a critical protocol is about to start */ if (strcmp (method, NM_SETTING_IP6_CONFIG_METHOD_AUTO) == 0 || strcmp (method, NM_SETTING_IP6_CONFIG_METHOD_DHCP) == 0) - nm_platform_wifi_indicate_addressing_running (NM_PLATFORM_GET, nm_device_get_ifindex (device), TRUE); + nm_platform_wifi_indicate_addressing_running (nm_device_get_platform (device), nm_device_get_ifindex (device), TRUE); return NM_DEVICE_CLASS (nm_device_wifi_parent_class)->act_stage3_ip6_config_start (device, out_config, out_failure_reason); } @@ -2870,7 +2871,7 @@ activation_success_handler (NMDevice *device) applied_connection = nm_act_request_get_applied_connection (req); /* Clear any critical protocol notification in the wifi stack */ - nm_platform_wifi_indicate_addressing_running (NM_PLATFORM_GET, ifindex, FALSE); + nm_platform_wifi_indicate_addressing_running (nm_device_get_platform (device), ifindex, FALSE); /* Clear wireless secrets tries on success */ g_object_set_qdata (G_OBJECT (applied_connection), wireless_secrets_tries_quark (), NULL); @@ -2893,16 +2894,16 @@ activation_success_handler (NMDevice *device) guint8 bssid[ETH_ALEN] = { 0x0, 0x0, 0x0, 0x0, 0x0, 0x0 }; gs_free char *bssid_str = NULL; - if ( nm_platform_wifi_get_bssid (NM_PLATFORM_GET, ifindex, bssid) + if ( nm_platform_wifi_get_bssid (nm_device_get_platform (device), ifindex, bssid) && nm_ethernet_address_is_valid (bssid, ETH_ALEN)) { bssid_str = nm_utils_hwaddr_ntoa (bssid, ETH_ALEN); ap_changed |= nm_wifi_ap_set_address (priv->current_ap, bssid_str); } } if (!nm_wifi_ap_get_freq (priv->current_ap)) - ap_changed |= nm_wifi_ap_set_freq (priv->current_ap, nm_platform_wifi_get_frequency (NM_PLATFORM_GET, ifindex)); + ap_changed |= nm_wifi_ap_set_freq (priv->current_ap, nm_platform_wifi_get_frequency (nm_device_get_platform (device), ifindex)); if (!nm_wifi_ap_get_max_bitrate (priv->current_ap)) - ap_changed |= nm_wifi_ap_set_max_bitrate (priv->current_ap, nm_platform_wifi_get_rate (NM_PLATFORM_GET, ifindex)); + ap_changed |= nm_wifi_ap_set_max_bitrate (priv->current_ap, nm_platform_wifi_get_rate (nm_device_get_platform (device), ifindex)); if (ap_changed) _ap_dump (self, LOGL_DEBUG, priv->current_ap, "updated", 0); @@ -2932,7 +2933,7 @@ activation_failure_handler (NMDevice *device) g_object_set_qdata (G_OBJECT (applied_connection), wireless_secrets_tries_quark (), NULL); /* Clear any critical protocol notification in the wifi stack */ - nm_platform_wifi_indicate_addressing_running (NM_PLATFORM_GET, nm_device_get_ifindex (device), FALSE); + nm_platform_wifi_indicate_addressing_running (nm_device_get_platform (device), nm_device_get_ifindex (device), FALSE); } static void @@ -2983,7 +2984,7 @@ device_state_changed (NMDevice *device, break; case NM_DEVICE_STATE_IP_CHECK: /* Clear any critical protocol notification in the wifi stack */ - nm_platform_wifi_indicate_addressing_running (NM_PLATFORM_GET, nm_device_get_ifindex (device), FALSE); + nm_platform_wifi_indicate_addressing_running (nm_device_get_platform (device), nm_device_get_ifindex (device), FALSE); break; case NM_DEVICE_STATE_ACTIVATED: activation_success_handler (device); diff --git a/src/devices/wwan/nm-modem.c b/src/devices/wwan/nm-modem.c index c292b635ea..6494b84995 100644 --- a/src/devices/wwan/nm-modem.c +++ b/src/devices/wwan/nm-modem.c @@ -33,6 +33,7 @@ #include "NetworkManagerUtils.h" #include "devices/nm-device-private.h" #include "nm-route-manager.h" +#include "nm-netns.h" #include "nm-act-request.h" #include "nm-ip4-config.h" #include "nm-ip6-config.h" @@ -685,7 +686,7 @@ nm_modem_ip4_pre_commit (NMModem *modem, g_assert (address); if (address->plen == 32) - nm_platform_link_set_noarp (NM_PLATFORM_GET, nm_device_get_ip_ifindex (device)); + nm_platform_link_set_noarp (nm_device_get_platform (device), nm_device_get_ip_ifindex (device)); } } @@ -1068,9 +1069,10 @@ deactivate_cleanup (NMModem *self, NMDevice *device) priv->ip6_method == NM_MODEM_IP_METHOD_AUTO) { ifindex = nm_device_get_ip_ifindex (device); if (ifindex > 0) { - nm_route_manager_route_flush (nm_route_manager_get (), ifindex); - nm_platform_address_flush (NM_PLATFORM_GET, ifindex); - nm_platform_link_set_down (NM_PLATFORM_GET, ifindex); + nm_route_manager_route_flush (nm_netns_get_route_manager (nm_device_get_netns (device)), + ifindex); + nm_platform_address_flush (nm_device_get_platform (device), ifindex); + nm_platform_link_set_down (nm_device_get_platform (device), ifindex); } } } diff --git a/src/main.c b/src/main.c index 04c837cb8f..52f3200e75 100644 --- a/src/main.c +++ b/src/main.c @@ -52,6 +52,7 @@ #include "nm-connectivity.h" #include "dns/nm-dns-manager.h" #include "systemd/nm-sd.h" +#include "nm-netns.h" #if !defined(NM_DIST_VERSION) # define NM_DIST_VERSION VERSION @@ -371,6 +372,11 @@ main (int argc, char *argv[]) #endif ); + /* Set up platform interaction layer */ + nm_linux_platform_setup (); + + NM_UTILS_KEEP_ALIVE (config, nm_netns_get (), "NMConfig-depends-on-NMNetns"); + nm_auth_manager_setup (nm_config_data_get_value_boolean (nm_config_get_data_orig (config), NM_CONFIG_KEYFILE_GROUP_MAIN, NM_CONFIG_KEYFILE_KEY_MAIN_AUTH_POLKIT, @@ -388,10 +394,6 @@ main (int argc, char *argv[]) } } - /* Set up platform interaction layer */ - nm_linux_platform_setup (); - - NM_UTILS_KEEP_ALIVE (config, NM_PLATFORM_GET, "NMConfig-depends-on-NMPlatform"); #if WITH_CONCHECK NM_UTILS_KEEP_ALIVE (nm_manager_get (), nm_connectivity_get (), "NMManager-depends-on-NMConnectivity"); #endif diff --git a/src/nm-default-route-manager.c b/src/nm-default-route-manager.c index 9b68c5e2d4..9ac6d552c0 100644 --- a/src/nm-default-route-manager.c +++ b/src/nm-default-route-manager.c @@ -36,12 +36,16 @@ /*****************************************************************************/ NM_GOBJECT_PROPERTIES_DEFINE_BASE ( + PROP_LOG_WITH_PTR, PROP_PLATFORM, ); typedef struct { GPtrArray *entries_ip4; GPtrArray *entries_ip6; + + NMPlatform *platform; + struct { guint guard; guint backoff_wait_time_ms; @@ -56,9 +60,9 @@ typedef struct { * pointers. * Guard every publicly accessible function to return early if the instance * is already disposing. */ - gboolean disposed; + bool disposed; - NMPlatform *platform; + bool log_with_ptr; } NMDefaultRouteManagerPrivate; struct _NMDefaultRouteManager { @@ -74,8 +78,6 @@ G_DEFINE_TYPE (NMDefaultRouteManager, nm_default_route_manager, G_TYPE_OBJECT) #define NM_DEFAULT_ROUTE_MANAGER_GET_PRIVATE(self) _NM_GET_PRIVATE (self, NMDefaultRouteManager, NM_IS_DEFAULT_ROUTE_MANAGER) -NM_DEFINE_SINGLETON_GETTER (NMDefaultRouteManager, nm_default_route_manager_get, NM_TYPE_DEFAULT_ROUTE_MANAGER); - /*****************************************************************************/ #define _NMLOG_PREFIX_NAME "default-route" @@ -99,7 +101,7 @@ NM_DEFINE_SINGLETON_GETTER (NMDefaultRouteManager, nm_default_route_manager_get, \ _nm_log (__level, __domain, 0, NULL, NULL, \ "%s: " _NM_UTILS_MACRO_FIRST(__VA_ARGS__), \ - self != singleton_instance \ + NM_DEFAULT_ROUTE_MANAGER_GET_PRIVATE (self)->log_with_ptr \ ? nm_sprintf_buf (__prefix_buf, "%s%c[%p]", \ _NMLOG2_PREFIX_NAME, \ __addr_family == AF_INET ? '4' : (__addr_family == AF_INET6 ? '6' : '-'), \ @@ -125,7 +127,7 @@ NM_DEFINE_SINGLETON_GETTER (NMDefaultRouteManager, nm_default_route_manager_get, \ _nm_log (__level, __domain, 0, NULL, NULL, \ "%s: entry[%u/%s:%p:%s:%chas:%csync]: "_NM_UTILS_MACRO_FIRST(__VA_ARGS__), \ - self != singleton_instance \ + NM_DEFAULT_ROUTE_MANAGER_GET_PRIVATE (self)->log_with_ptr \ ? nm_sprintf_buf (__prefix_buf, "%s%c[%p]", \ _NMLOG2_PREFIX_NAME, \ __addr_family == AF_INET ? '4' : (__addr_family == AF_INET6 ? '6' : '-'), \ @@ -1454,6 +1456,10 @@ set_property (GObject *object, guint prop_id, NMDefaultRouteManagerPrivate *priv = NM_DEFAULT_ROUTE_MANAGER_GET_PRIVATE (self); switch (prop_id) { + case PROP_LOG_WITH_PTR: + /* construct-only */ + priv->log_with_ptr = g_value_get_boolean (value); + break; case PROP_PLATFORM: /* construct-only */ priv->platform = g_value_get_object (value) ? : NM_PLATFORM_GET; @@ -1490,9 +1496,10 @@ constructed (GObject *object) } NMDefaultRouteManager * -nm_default_route_manager_new (NMPlatform *platform) +nm_default_route_manager_new (gboolean log_with_ptr, NMPlatform *platform) { return g_object_new (NM_TYPE_DEFAULT_ROUTE_MANAGER, + NM_DEFAULT_ROUTE_MANAGER_LOG_WITH_PTR, log_with_ptr, NM_DEFAULT_ROUTE_MANAGER_PLATFORM, platform, NULL); } @@ -1540,6 +1547,13 @@ nm_default_route_manager_class_init (NMDefaultRouteManagerClass *klass) object_class->dispose = dispose; object_class->set_property = set_property; + obj_properties[PROP_LOG_WITH_PTR] = + g_param_spec_boolean (NM_DEFAULT_ROUTE_MANAGER_LOG_WITH_PTR, "", "", + TRUE, + G_PARAM_WRITABLE | + G_PARAM_CONSTRUCT_ONLY | + G_PARAM_STATIC_STRINGS); + obj_properties[PROP_PLATFORM] = g_param_spec_object (NM_DEFAULT_ROUTE_MANAGER_PLATFORM, "", "", NM_TYPE_PLATFORM, diff --git a/src/nm-default-route-manager.h b/src/nm-default-route-manager.h index 16f742a7ad..bac8a6ebaa 100644 --- a/src/nm-default-route-manager.h +++ b/src/nm-default-route-manager.h @@ -30,14 +30,14 @@ #define NM_IS_DEFAULT_ROUTE_MANAGER_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), NM_TYPE_DEFAULT_ROUTE_MANAGER)) #define NM_DEFAULT_ROUTE_MANAGER_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), NM_TYPE_DEFAULT_ROUTE_MANAGER, NMDefaultRouteManagerClass)) -#define NM_DEFAULT_ROUTE_MANAGER_PLATFORM "platform" +#define NM_DEFAULT_ROUTE_MANAGER_LOG_WITH_PTR "log-with-ptr" +#define NM_DEFAULT_ROUTE_MANAGER_PLATFORM "platform" typedef struct _NMDefaultRouteManagerClass NMDefaultRouteManagerClass; GType nm_default_route_manager_get_type (void); -NMDefaultRouteManager *nm_default_route_manager_get (void); -NMDefaultRouteManager *nm_default_route_manager_new (NMPlatform *platform); +NMDefaultRouteManager *nm_default_route_manager_new (gboolean log_with_ptr, NMPlatform *platform); gboolean nm_default_route_manager_ip4_update_default_route (NMDefaultRouteManager *manager, gpointer source); gboolean nm_default_route_manager_ip6_update_default_route (NMDefaultRouteManager *manager, gpointer source); diff --git a/src/nm-iface-helper.c b/src/nm-iface-helper.c index 221b4ca198..f8df2b9a7f 100644 --- a/src/nm-iface-helper.c +++ b/src/nm-iface-helper.c @@ -42,6 +42,7 @@ #include "nm-utils.h" #include "nm-setting-ip6-config.h" #include "systemd/nm-sd.h" +#include "nm-route-manager.h" #if !defined(NM_DIST_VERSION) # define NM_DIST_VERSION VERSION @@ -97,6 +98,12 @@ static struct { /*****************************************************************************/ +NMRouteManager *route_manager_get (void); + +NM_DEFINE_SINGLETON_GETTER (NMRouteManager, route_manager_get, NM_TYPE_ROUTE_MANAGER); + +/*****************************************************************************/ + static void dhcp4_state_changed (NMDhcpClient *client, NMDhcpState state, @@ -115,12 +122,12 @@ dhcp4_state_changed (NMDhcpClient *client, switch (state) { case NM_DHCP_STATE_BOUND: g_assert (ip4_config); - existing = nm_ip4_config_capture (gl.ifindex, FALSE); + existing = nm_ip4_config_capture (NM_PLATFORM_GET, gl.ifindex, FALSE); if (last_config) nm_ip4_config_subtract (existing, last_config); nm_ip4_config_merge (existing, ip4_config, NM_IP_CONFIG_MERGE_DEFAULT); - if (!nm_ip4_config_commit (existing, gl.ifindex, TRUE, global_opt.priority_v4)) + if (!nm_ip4_config_commit (existing, NM_PLATFORM_GET, route_manager_get (), gl.ifindex, TRUE, global_opt.priority_v4)) _LOGW (LOGD_DHCP4, "failed to apply DHCPv4 config"); if (last_config) @@ -170,7 +177,7 @@ ndisc_config_changed (NMNDisc *ndisc, const NMNDiscData *rdata, guint changed_in ifa_flags |= IFA_F_MANAGETEMPADDR; } - existing = nm_ip6_config_capture (gl.ifindex, FALSE, global_opt.tempaddr); + existing = nm_ip6_config_capture (NM_PLATFORM_GET, gl.ifindex, FALSE, global_opt.tempaddr); if (ndisc_config) nm_ip6_config_subtract (existing, ndisc_config); else @@ -245,7 +252,7 @@ ndisc_config_changed (NMNDisc *ndisc, const NMNDiscData *rdata, guint changed_in } nm_ip6_config_merge (existing, ndisc_config, NM_IP_CONFIG_MERGE_DEFAULT); - if (!nm_ip6_config_commit (existing, gl.ifindex, TRUE)) + if (!nm_ip6_config_commit (existing, NM_PLATFORM_GET, route_manager_get (), gl.ifindex, TRUE)) _LOGW (LOGD_IP6, "failed to apply IPv6 config"); } diff --git a/src/nm-ip4-config.c b/src/nm-ip4-config.c index 6226a305ff..20532e8607 100644 --- a/src/nm-ip4-config.c +++ b/src/nm-ip4-config.c @@ -249,7 +249,7 @@ notify_addresses (NMIP4Config *self) } NMIP4Config * -nm_ip4_config_capture (int ifindex, gboolean capture_resolv_conf) +nm_ip4_config_capture (NMPlatform *platform, int ifindex, gboolean capture_resolv_conf) { NMIP4Config *config; NMIP4ConfigPrivate *priv; @@ -259,7 +259,7 @@ nm_ip4_config_capture (int ifindex, gboolean capture_resolv_conf) gboolean old_has_gateway = FALSE; /* Slaves have no IP configuration */ - if (nm_platform_link_get_master (NM_PLATFORM_GET, ifindex) > 0) + if (nm_platform_link_get_master (platform, ifindex) > 0) return NULL; config = nm_ip4_config_new (ifindex); @@ -268,8 +268,8 @@ nm_ip4_config_capture (int ifindex, gboolean capture_resolv_conf) g_array_unref (priv->addresses); g_array_unref (priv->routes); - priv->addresses = nm_platform_ip4_address_get_all (NM_PLATFORM_GET, ifindex); - priv->routes = nm_platform_ip4_route_get_all (NM_PLATFORM_GET, ifindex, NM_PLATFORM_GET_ROUTE_FLAGS_WITH_DEFAULT | NM_PLATFORM_GET_ROUTE_FLAGS_WITH_NON_DEFAULT); + priv->addresses = nm_platform_ip4_address_get_all (platform, ifindex); + priv->routes = nm_platform_ip4_route_get_all (platform, ifindex, NM_PLATFORM_GET_ROUTE_FLAGS_WITH_DEFAULT | NM_PLATFORM_GET_ROUTE_FLAGS_WITH_NON_DEFAULT); /* Extract gateway from default route */ old_gateway = priv->gateway; @@ -331,7 +331,7 @@ nm_ip4_config_capture (int ifindex, gboolean capture_resolv_conf) } gboolean -nm_ip4_config_commit (const NMIP4Config *config, int ifindex, gboolean routes_full_sync, gint64 default_route_metric) +nm_ip4_config_commit (const NMIP4Config *config, NMPlatform *platform, NMRouteManager *route_manager, int ifindex, gboolean routes_full_sync, gint64 default_route_metric) { const NMIP4ConfigPrivate *priv = NM_IP4_CONFIG_GET_PRIVATE (config); gs_unref_ptrarray GPtrArray *added_addresses = NULL; @@ -340,7 +340,7 @@ nm_ip4_config_commit (const NMIP4Config *config, int ifindex, gboolean routes_fu g_return_val_if_fail (config != NULL, FALSE); /* Addresses */ - nm_platform_ip4_address_sync (NM_PLATFORM_GET, ifindex, priv->addresses, + nm_platform_ip4_address_sync (platform, ifindex, priv->addresses, default_route_metric >= 0 ? &added_addresses : NULL); /* Routes */ @@ -401,9 +401,9 @@ nm_ip4_config_commit (const NMIP4Config *config, int ifindex, gboolean routes_fu g_array_append_vals (routes, route, 1); } - nm_route_manager_ip4_route_register_device_route_purge_list (nm_route_manager_get (), device_route_purge_list); + nm_route_manager_ip4_route_register_device_route_purge_list (route_manager, device_route_purge_list); - success = nm_route_manager_ip4_route_sync (nm_route_manager_get (), ifindex, routes, default_route_metric < 0, routes_full_sync); + success = nm_route_manager_ip4_route_sync (route_manager, ifindex, routes, default_route_metric < 0, routes_full_sync); g_array_unref (routes); if (!success) return FALSE; diff --git a/src/nm-ip4-config.h b/src/nm-ip4-config.h index 58ee4a7de0..ceb52ac547 100644 --- a/src/nm-ip4-config.h +++ b/src/nm-ip4-config.h @@ -59,8 +59,8 @@ NMIP4Config * nm_ip4_config_new (int ifindex); int nm_ip4_config_get_ifindex (const NMIP4Config *config); -NMIP4Config *nm_ip4_config_capture (int ifindex, gboolean capture_resolv_conf); -gboolean nm_ip4_config_commit (const NMIP4Config *config, int ifindex, gboolean routes_full_sync, gint64 default_route_metric); +NMIP4Config *nm_ip4_config_capture (NMPlatform *platform, int ifindex, gboolean capture_resolv_conf); +gboolean nm_ip4_config_commit (const NMIP4Config *config, NMPlatform *platform, NMRouteManager *route_manager, int ifindex, gboolean routes_full_sync, gint64 default_route_metric); void nm_ip4_config_merge_setting (NMIP4Config *config, NMSettingIPConfig *setting, guint32 default_route_metric); NMSetting *nm_ip4_config_create_setting (const NMIP4Config *config); diff --git a/src/nm-ip6-config.c b/src/nm-ip6-config.c index 756fa03233..af88b21c74 100644 --- a/src/nm-ip6-config.c +++ b/src/nm-ip6-config.c @@ -301,7 +301,7 @@ nm_ip6_config_addresses_sort (NMIP6Config *self) } NMIP6Config * -nm_ip6_config_capture (int ifindex, gboolean capture_resolv_conf, NMSettingIP6ConfigPrivacy use_temporary) +nm_ip6_config_capture (NMPlatform *platform, int ifindex, gboolean capture_resolv_conf, NMSettingIP6ConfigPrivacy use_temporary) { NMIP6Config *config; NMIP6ConfigPrivate *priv; @@ -312,7 +312,7 @@ nm_ip6_config_capture (int ifindex, gboolean capture_resolv_conf, NMSettingIP6Co gboolean notify_nameservers = FALSE; /* Slaves have no IP configuration */ - if (nm_platform_link_get_master (NM_PLATFORM_GET, ifindex) > 0) + if (nm_platform_link_get_master (platform, ifindex) > 0) return NULL; config = nm_ip6_config_new (ifindex); @@ -321,8 +321,8 @@ nm_ip6_config_capture (int ifindex, gboolean capture_resolv_conf, NMSettingIP6Co g_array_unref (priv->addresses); g_array_unref (priv->routes); - priv->addresses = nm_platform_ip6_address_get_all (NM_PLATFORM_GET, ifindex); - priv->routes = nm_platform_ip6_route_get_all (NM_PLATFORM_GET, ifindex, NM_PLATFORM_GET_ROUTE_FLAGS_WITH_DEFAULT | NM_PLATFORM_GET_ROUTE_FLAGS_WITH_NON_DEFAULT); + priv->addresses = nm_platform_ip6_address_get_all (platform, ifindex); + priv->routes = nm_platform_ip6_route_get_all (platform, ifindex, NM_PLATFORM_GET_ROUTE_FLAGS_WITH_DEFAULT | NM_PLATFORM_GET_ROUTE_FLAGS_WITH_NON_DEFAULT); /* Extract gateway from default route */ old_gateway = priv->gateway; @@ -386,7 +386,11 @@ nm_ip6_config_capture (int ifindex, gboolean capture_resolv_conf, NMSettingIP6Co } gboolean -nm_ip6_config_commit (const NMIP6Config *config, int ifindex, gboolean routes_full_sync) +nm_ip6_config_commit (const NMIP6Config *config, + NMPlatform *platform, + NMRouteManager *route_manager, + int ifindex, + gboolean routes_full_sync) { const NMIP6ConfigPrivate *priv = NM_IP6_CONFIG_GET_PRIVATE (config); gboolean success; @@ -395,7 +399,7 @@ nm_ip6_config_commit (const NMIP6Config *config, int ifindex, gboolean routes_fu g_return_val_if_fail (config != NULL, FALSE); /* Addresses */ - nm_platform_ip6_address_sync (NM_PLATFORM_GET, ifindex, priv->addresses, TRUE); + nm_platform_ip6_address_sync (platform, ifindex, priv->addresses, TRUE); /* Routes */ { @@ -409,7 +413,7 @@ nm_ip6_config_commit (const NMIP6Config *config, int ifindex, gboolean routes_fu g_array_append_vals (routes, route, 1); } - success = nm_route_manager_ip6_route_sync (nm_route_manager_get (), ifindex, routes, TRUE, routes_full_sync); + success = nm_route_manager_ip6_route_sync (route_manager, ifindex, routes, TRUE, routes_full_sync); g_array_unref (routes); } diff --git a/src/nm-ip6-config.h b/src/nm-ip6-config.h index c196421b3f..557041c958 100644 --- a/src/nm-ip6-config.h +++ b/src/nm-ip6-config.h @@ -61,8 +61,12 @@ NMIP6Config * nm_ip6_config_new_cloned (const NMIP6Config *src); int nm_ip6_config_get_ifindex (const NMIP6Config *config); -NMIP6Config *nm_ip6_config_capture (int ifindex, gboolean capture_resolv_conf, NMSettingIP6ConfigPrivacy use_temporary); -gboolean nm_ip6_config_commit (const NMIP6Config *config, int ifindex, gboolean routes_full_sync); +NMIP6Config *nm_ip6_config_capture (NMPlatform *platform, int ifindex, gboolean capture_resolv_conf, NMSettingIP6ConfigPrivacy use_temporary); +gboolean nm_ip6_config_commit (const NMIP6Config *config, + NMPlatform *platform, + NMRouteManager *route_manager, + int ifindex, + gboolean routes_full_sync); void nm_ip6_config_merge_setting (NMIP6Config *config, NMSettingIPConfig *setting, guint32 default_route_metric); NMSetting *nm_ip6_config_create_setting (const NMIP6Config *config); diff --git a/src/nm-netns.c b/src/nm-netns.c new file mode 100644 index 0000000000..a81aa696ee --- /dev/null +++ b/src/nm-netns.c @@ -0,0 +1,176 @@ +/* -*- Mode: C; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- */ +/* NetworkManager -- Network link manager + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Copyright (C) 2017 Red Hat, Inc. + */ + +#include "nm-default.h" + +#include "nm-netns.h" + +#include "platform/nm-platform.h" +#include "platform/nmp-netns.h" +#include "nm-route-manager.h" +#include "nm-default-route-manager.h" +#include "nm-core-internal.h" +#include "NetworkManagerUtils.h" + +/*****************************************************************************/ + +NM_GOBJECT_PROPERTIES_DEFINE_BASE ( + PROP_PLATFORM, +); + +typedef struct { + NMPlatform *platform; + NMPNetns *platform_netns; + NMRouteManager *route_manager; + NMDefaultRouteManager *default_route_manager; + bool log_with_ptr; +} NMNetnsPrivate; + +struct _NMNetns { + GObject parent; + NMNetnsPrivate _priv; +}; + +struct _NMNetnsClass { + GObjectClass parent; +}; + +G_DEFINE_TYPE (NMNetns, nm_netns, G_TYPE_OBJECT); + +#define NM_NETNS_GET_PRIVATE(self) _NM_GET_PRIVATE (self, NMNetns, NM_IS_NETNS) + +/*****************************************************************************/ + +NM_DEFINE_SINGLETON_GETTER (NMNetns, nm_netns_get, NM_TYPE_NETNS); + +/*****************************************************************************/ + +NMPNetns * +nm_netns_get_platform_netns (NMNetns *self) +{ + return NM_NETNS_GET_PRIVATE (self)->platform_netns; +} + +NMPlatform * +nm_netns_get_platform (NMNetns *self) +{ + return NM_NETNS_GET_PRIVATE (self)->platform; +} + +NMDefaultRouteManager * +nm_netns_get_default_route_manager (NMNetns *self) +{ + return NM_NETNS_GET_PRIVATE (self)->default_route_manager; +} + +NMRouteManager * +nm_netns_get_route_manager (NMNetns *self) +{ + return NM_NETNS_GET_PRIVATE (self)->route_manager; +} + +/*****************************************************************************/ + +static void +set_property (GObject *object, guint prop_id, + const GValue *value, GParamSpec *pspec) +{ + NMNetns *self = NM_NETNS (object); + NMNetnsPrivate *priv = NM_NETNS_GET_PRIVATE (self); + + switch (prop_id) { + case PROP_PLATFORM: + /* construct-only */ + priv->platform = g_value_get_object (value) ?: NM_PLATFORM_GET; + if (!priv->platform) + g_return_if_reached (); + g_object_ref (priv->platform); + break; + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); + break; + } +} + +/*****************************************************************************/ + +static void +nm_netns_init (NMNetns *self) +{ +} + +static void +constructed (GObject *object) +{ + NMNetns *self = NM_NETNS (object); + NMNetnsPrivate *priv = NM_NETNS_GET_PRIVATE (self); + gboolean log_with_ptr; + + if (!priv->platform) + g_return_if_reached (); + + log_with_ptr = nm_platform_get_log_with_ptr (priv->platform); + + priv->platform_netns = nm_platform_netns_get (priv->platform); + priv->route_manager = nm_route_manager_new (log_with_ptr, priv->platform); + priv->default_route_manager = nm_default_route_manager_new (log_with_ptr, priv->platform); + + G_OBJECT_CLASS (nm_netns_parent_class)->constructed (object); +} + +NMNetns * +nm_netns_new (NMPlatform *platform) +{ + return g_object_new (NM_TYPE_NETNS, + NM_NETNS_PLATFORM, platform, + NULL); +} + +static void +dispose (GObject *object) +{ + NMNetns *self = NM_NETNS (object); + NMNetnsPrivate *priv = NM_NETNS_GET_PRIVATE (self); + + g_clear_object (&priv->route_manager); + g_clear_object (&priv->default_route_manager); + g_clear_object (&priv->platform); + + G_OBJECT_CLASS (nm_netns_parent_class)->dispose (object); +} + +static void +nm_netns_class_init (NMNetnsClass *klass) +{ + GObjectClass *object_class = G_OBJECT_CLASS (klass); + + object_class->constructed = constructed; + object_class->set_property = set_property; + object_class->dispose = dispose; + + obj_properties[PROP_PLATFORM] = + g_param_spec_object (NM_NETNS_PLATFORM, "", "", + NM_TYPE_PLATFORM, + G_PARAM_WRITABLE | + G_PARAM_CONSTRUCT_ONLY | + G_PARAM_STATIC_STRINGS); + + g_object_class_install_properties (object_class, _PROPERTY_ENUMS_LAST, obj_properties); +} diff --git a/src/nm-netns.h b/src/nm-netns.h new file mode 100644 index 0000000000..fd5daf47ff --- /dev/null +++ b/src/nm-netns.h @@ -0,0 +1,47 @@ +/* -*- Mode: C; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- */ +/* NetworkManager -- Network link manager + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Copyright (C) 2017 Red Hat, Inc. + */ + +#ifndef __NM_NETNS_H__ +#define __NM_NETNS_H__ + +#define NM_TYPE_NETNS (nm_netns_get_type ()) +#define NM_NETNS(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), NM_TYPE_NETNS, NMNetns)) +#define NM_NETNS_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), NM_TYPE_NETNS, NMNetnsClass)) +#define NM_IS_NETNS(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), NM_TYPE_NETNS)) +#define NM_IS_NETNS_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), NM_TYPE_NETNS)) +#define NM_NETNS_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), NM_TYPE_NETNS, NMNetnsClass)) + +#define NM_NETNS_PLATFORM "platform" + +typedef struct _NMNetnsClass NMNetnsClass; + +GType nm_netns_get_type (void); + +NMNetns *nm_netns_get (void); +NMNetns *nm_netns_new (NMPlatform *platform); + +NMPlatform *nm_netns_get_platform (NMNetns *self); +NMPNetns *nm_netns_get_platform_netns (NMNetns *self); +NMRouteManager *nm_netns_get_route_manager (NMNetns *self); +NMDefaultRouteManager *nm_netns_get_default_route_manager (NMNetns *self); + +#define NM_NETNS_GET (nm_netns_get ()) + +#endif /* __NM_NETNS_H__ */ diff --git a/src/nm-policy.c b/src/nm-policy.c index 80f9caedfa..7ae50e7621 100644 --- a/src/nm-policy.c +++ b/src/nm-policy.c @@ -48,6 +48,7 @@ #include "nm-dhcp4-config.h" #include "nm-dhcp6-config.h" #include "nm-config.h" +#include "nm-netns.h" /*****************************************************************************/ @@ -62,6 +63,7 @@ NM_GOBJECT_PROPERTIES_DEFINE (NMPolicy, typedef struct { NMManager *manager; + NMNetns *netns; NMFirewallManager *firewall_manager; GSList *pending_activation_checks; @@ -373,7 +375,7 @@ get_best_ip4_device (NMPolicy *self, gboolean fully_activated) { NMPolicyPrivate *priv = NM_POLICY_GET_PRIVATE (self); - return nm_default_route_manager_ip4_get_best_device (nm_default_route_manager_get (), + return nm_default_route_manager_ip4_get_best_device (nm_netns_get_default_route_manager (priv->netns), nm_manager_get_devices (priv->manager), fully_activated, priv->default_device4); @@ -384,7 +386,7 @@ get_best_ip6_device (NMPolicy *self, gboolean fully_activated) { NMPolicyPrivate *priv = NM_POLICY_GET_PRIVATE (self); - return nm_default_route_manager_ip6_get_best_device (nm_default_route_manager_get (), + return nm_default_route_manager_ip6_get_best_device (nm_netns_get_default_route_manager (priv->netns), nm_manager_get_devices (priv->manager), fully_activated, priv->default_device6); @@ -793,7 +795,7 @@ get_best_ip4_config (NMPolicy *self, NMDevice **out_device, NMVpnConnection **out_vpn) { - return nm_default_route_manager_ip4_get_best_config (nm_default_route_manager_get (), + return nm_default_route_manager_ip4_get_best_config (nm_netns_get_default_route_manager (NM_POLICY_GET_PRIVATE (self)->netns), ignore_never_default, out_ip_iface, out_ac, @@ -888,7 +890,7 @@ get_best_ip6_config (NMPolicy *self, NMDevice **out_device, NMVpnConnection **out_vpn) { - return nm_default_route_manager_ip6_get_best_config (nm_default_route_manager_get (), + return nm_default_route_manager_ip6_get_best_config (nm_netns_get_default_route_manager (NM_POLICY_GET_PRIVATE (self)->netns), ignore_never_default, out_ip_iface, out_ac, @@ -2289,6 +2291,8 @@ nm_policy_init (NMPolicy *self) NMPolicyPrivate *priv = NM_POLICY_GET_PRIVATE (self); const char *hostname_mode; + priv->netns = g_object_ref (nm_netns_get ()); + hostname_mode = nm_config_data_get_value (NM_CONFIG_GET_DATA_ORIG, NM_CONFIG_KEYFILE_GROUP_MAIN, NM_CONFIG_KEYFILE_KEY_MAIN_HOSTNAME_MODE, @@ -2446,6 +2450,8 @@ finalize (GObject *object) g_hash_table_unref (priv->devices); G_OBJECT_CLASS (nm_policy_parent_class)->finalize (object); + + g_object_unref (priv->netns); } static void diff --git a/src/nm-route-manager.c b/src/nm-route-manager.c index 76c672ee7c..b58cdeb069 100644 --- a/src/nm-route-manager.c +++ b/src/nm-route-manager.c @@ -70,6 +70,7 @@ enum { static guint signals[LAST_SIGNAL] = { 0 }; NM_GOBJECT_PROPERTIES_DEFINE_BASE ( + PROP_LOG_WITH_PTR, PROP_PLATFORM, ); @@ -82,6 +83,8 @@ typedef struct { GHashTable *entries; guint gc_id; } ip4_device_routes; + + bool log_with_ptr; } NMRouteManagerPrivate; struct _NMRouteManager { @@ -99,10 +102,6 @@ G_DEFINE_TYPE (NMRouteManager, nm_route_manager, G_TYPE_OBJECT); /*****************************************************************************/ -NM_DEFINE_SINGLETON_GETTER (NMRouteManager, nm_route_manager_get, NM_TYPE_ROUTE_MANAGER); - -/*****************************************************************************/ - typedef struct { const NMPlatformVTableRoute *vt; @@ -156,7 +155,7 @@ static const VTableIP vtable_v4, vtable_v6; char __ch = __addr_family == AF_INET ? '4' : (__addr_family == AF_INET6 ? '6' : '-'); \ char __prefix[30] = _NMLOG_PREFIX_NAME; \ \ - if ((self) != singleton_instance) \ + if (NM_ROUTE_MANAGER_GET_PRIVATE (self)->log_with_ptr) \ g_snprintf (__prefix, sizeof (__prefix), "%s%c[%p]", _NMLOG_PREFIX_NAME, __ch, (self)); \ else \ __prefix[NM_STRLEN (_NMLOG_PREFIX_NAME)] = __ch; \ @@ -1207,6 +1206,10 @@ set_property (GObject *object, guint prop_id, NMRouteManagerPrivate *priv = NM_ROUTE_MANAGER_GET_PRIVATE (self); switch (prop_id) { + case PROP_LOG_WITH_PTR: + /* construct-only */ + priv->log_with_ptr = g_value_get_boolean (value); + break; case PROP_PLATFORM: /* construct-only */ priv->platform = g_value_get_object (value) ? : NM_PLATFORM_GET; @@ -1242,9 +1245,10 @@ nm_route_manager_init (NMRouteManager *self) } NMRouteManager * -nm_route_manager_new (NMPlatform *platform) +nm_route_manager_new (gboolean log_with_ptr, NMPlatform *platform) { return g_object_new (NM_TYPE_ROUTE_MANAGER, + NM_ROUTE_MANAGER_LOG_WITH_PTR, log_with_ptr, NM_ROUTE_MANAGER_PLATFORM, platform, NULL); } @@ -1291,6 +1295,13 @@ nm_route_manager_class_init (NMRouteManagerClass *klass) object_class->dispose = dispose; object_class->finalize = finalize; + obj_properties[PROP_LOG_WITH_PTR] = + g_param_spec_boolean (NM_ROUTE_MANAGER_LOG_WITH_PTR, "", "", + TRUE, + G_PARAM_WRITABLE | + G_PARAM_CONSTRUCT_ONLY | + G_PARAM_STATIC_STRINGS); + obj_properties[PROP_PLATFORM] = g_param_spec_object (NM_ROUTE_MANAGER_PLATFORM, "", "", NM_TYPE_PLATFORM, diff --git a/src/nm-route-manager.h b/src/nm-route-manager.h index 328fa8cba6..bdf79a09ab 100644 --- a/src/nm-route-manager.h +++ b/src/nm-route-manager.h @@ -28,7 +28,8 @@ #define NM_IS_ROUTE_MANAGER_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), NM_TYPE_ROUTE_MANAGER)) #define NM_ROUTE_MANAGER_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), NM_TYPE_ROUTE_MANAGER, NMRouteManagerClass)) -#define NM_ROUTE_MANAGER_PLATFORM "platform" +#define NM_ROUTE_MANAGER_LOG_WITH_PTR "log-with-ptr" +#define NM_ROUTE_MANAGER_PLATFORM "platform" #define NM_ROUTE_MANAGER_IP4_ROUTES_CHANGED "ip4-routes-changed" @@ -43,7 +44,6 @@ gboolean nm_route_manager_route_flush (NMRouteManager *self, int ifindex); gboolean nm_route_manager_ip4_routes_shadowed (NMRouteManager *self, int ifindex); void nm_route_manager_ip4_route_register_device_route_purge_list (NMRouteManager *self, GArray *device_route_purge_list); -NMRouteManager *nm_route_manager_get (void); -NMRouteManager *nm_route_manager_new (NMPlatform *platform); +NMRouteManager *nm_route_manager_new (gboolean log_with_ptr, NMPlatform *platform); #endif /* __NM_ROUTE_MANAGER_H__ */ diff --git a/src/nm-types.h b/src/nm-types.h index 32f4198ad7..44b4fecbb3 100644 --- a/src/nm-types.h +++ b/src/nm-types.h @@ -46,6 +46,7 @@ typedef struct _NMProxyConfig NMProxyConfig; typedef struct _NMIP4Config NMIP4Config; typedef struct _NMIP6Config NMIP6Config; typedef struct _NMManager NMManager; +typedef struct _NMNetns NMNetns; typedef struct _NMPolicy NMPolicy; typedef struct _NMRfkillManager NMRfkillManager; typedef struct _NMPacrunnerManager NMPacrunnerManager; diff --git a/src/platform/nm-fake-platform.c b/src/platform/nm-fake-platform.c index faa95bbc69..42979ed209 100644 --- a/src/platform/nm-fake-platform.c +++ b/src/platform/nm-fake-platform.c @@ -82,9 +82,9 @@ G_DEFINE_TYPE (NMFakePlatform, nm_fake_platform, NM_TYPE_PLATFORM) if (nm_logging_enabled (__level, __domain)) { \ char __prefix[32]; \ const char *__p_prefix = _NMLOG_PREFIX_NAME; \ - const void *const __self = (self); \ + NMPlatform *const __self = (self); \ \ - if (__self && __self != nm_platform_try_get ()) { \ + if (__self && nm_platform_get_log_with_ptr (self)) { \ g_snprintf (__prefix, sizeof (__prefix), "%s[%p]", _NMLOG_PREFIX_NAME, __self); \ __p_prefix = __prefix; \ } \ @@ -1400,7 +1400,9 @@ nm_fake_platform_setup (void) { NMPlatform *platform; - platform = g_object_new (NM_TYPE_FAKE_PLATFORM, NULL); + platform = g_object_new (NM_TYPE_FAKE_PLATFORM, + NM_PLATFORM_LOG_WITH_PTR, FALSE, + NULL); nm_platform_setup (platform); diff --git a/src/platform/nm-linux-platform.c b/src/platform/nm-linux-platform.c index c3af263040..251bc17f92 100644 --- a/src/platform/nm-linux-platform.c +++ b/src/platform/nm-linux-platform.c @@ -145,9 +145,9 @@ G_STMT_START { \ char __prefix[32]; \ const char *__p_prefix = _NMLOG_PREFIX_NAME; \ - const void *const __self = (self); \ + NMPlatform *const __self = (self); \ \ - if (__self && __self != nm_platform_try_get ()) { \ + if (__self && nm_platform_get_log_with_ptr (__self)) { \ g_snprintf (__prefix, sizeof (__prefix), "%s[%p]", _NMLOG_PREFIX_NAME, __self); \ __p_prefix = __prefix; \ } \ @@ -2583,10 +2583,10 @@ G_DEFINE_TYPE (NMLinuxPlatform, nm_linux_platform, NM_TYPE_PLATFORM) #define NM_LINUX_PLATFORM_GET_PRIVATE(self) _NM_GET_PRIVATE_VOID(self, NMLinuxPlatform, NM_IS_LINUX_PLATFORM) NMPlatform * -nm_linux_platform_new (gboolean netns_support) +nm_linux_platform_new (gboolean log_with_ptr, gboolean netns_support) { return g_object_new (NM_TYPE_LINUX_PLATFORM, - NM_PLATFORM_REGISTER_SINGLETON, FALSE, + NM_PLATFORM_LOG_WITH_PTR, log_with_ptr, NM_PLATFORM_NETNS_SUPPORT, netns_support, NULL); } @@ -2594,10 +2594,7 @@ nm_linux_platform_new (gboolean netns_support) void nm_linux_platform_setup (void) { - g_object_new (NM_TYPE_LINUX_PLATFORM, - NM_PLATFORM_REGISTER_SINGLETON, TRUE, - NM_PLATFORM_NETNS_SUPPORT, FALSE, - NULL); + nm_platform_setup (nm_linux_platform_new (FALSE, FALSE)); } static void diff --git a/src/platform/nm-linux-platform.h b/src/platform/nm-linux-platform.h index b3272aae68..6b66ea699c 100644 --- a/src/platform/nm-linux-platform.h +++ b/src/platform/nm-linux-platform.h @@ -35,7 +35,7 @@ typedef struct _NMLinuxPlatformClass NMLinuxPlatformClass; GType nm_linux_platform_get_type (void); -NMPlatform *nm_linux_platform_new (gboolean netns_support); +NMPlatform *nm_linux_platform_new (gboolean log_with_ptr, gboolean netns_support); void nm_linux_platform_setup (void); diff --git a/src/platform/nm-platform.c b/src/platform/nm-platform.c index bb81749d73..334b94d411 100644 --- a/src/platform/nm-platform.c +++ b/src/platform/nm-platform.c @@ -62,9 +62,9 @@ G_STATIC_ASSERT (G_STRUCT_OFFSET (NMPlatformIPRoute, network_ptr) == G_STRUCT_OF if (nm_logging_enabled (__level, _NMLOG_DOMAIN)) { \ char __prefix[32]; \ const char *__p_prefix = _NMLOG_PREFIX_NAME; \ - const void *const __self = (self); \ + const NMPlatform *const __self = (self); \ \ - if (__self && __self != nm_platform_try_get ()) { \ + if (__self && NM_PLATFORM_GET_PRIVATE (__self)->log_with_ptr) { \ g_snprintf (__prefix, sizeof (__prefix), "%s[%p]", _NMLOG_PREFIX_NAME, __self); \ __p_prefix = __prefix; \ } \ @@ -83,12 +83,12 @@ static guint signals[_NM_PLATFORM_SIGNAL_ID_LAST] = { 0 }; enum { PROP_0, PROP_NETNS_SUPPORT, - PROP_REGISTER_SINGLETON, + PROP_LOG_WITH_PTR, LAST_PROP, }; typedef struct _NMPlatformPrivate { - bool register_singleton:1; + bool log_with_ptr:1; } NMPlatformPrivate; G_DEFINE_TYPE (NMPlatform, nm_platform, G_TYPE_OBJECT) @@ -97,6 +97,14 @@ G_DEFINE_TYPE (NMPlatform, nm_platform, G_TYPE_OBJECT) /*****************************************************************************/ +gboolean +nm_platform_get_log_with_ptr (NMPlatform *self) +{ + return NM_PLATFORM_GET_PRIVATE (self)->log_with_ptr; +} + +/*****************************************************************************/ + guint _nm_platform_signal_id_get (NMPlatformSignalIdType signal_type) { @@ -187,12 +195,6 @@ nm_platform_get () return singleton_instance; } -NMPlatform * -nm_platform_try_get (void) -{ - return singleton_instance; -} - /*****************************************************************************/ /** @@ -4596,9 +4598,9 @@ set_property (GObject *object, guint prop_id, self->_netns = g_object_ref (netns); } break; - case PROP_REGISTER_SINGLETON: + case PROP_LOG_WITH_PTR: /* construct-only */ - priv->register_singleton = g_value_get_boolean (value); + priv->log_with_ptr = g_value_get_boolean (value); break; default: G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); @@ -4607,18 +4609,6 @@ set_property (GObject *object, guint prop_id, } static void -constructed (GObject *object) -{ - NMPlatform *self = NM_PLATFORM (object); - NMPlatformPrivate *priv = NM_PLATFORM_GET_PRIVATE (self); - - G_OBJECT_CLASS (nm_platform_parent_class)->constructed (object); - - if (priv->register_singleton) - nm_platform_setup (self); -} - -static void nm_platform_init (NMPlatform *self) { self->_priv = G_TYPE_INSTANCE_GET_PRIVATE (self, NM_TYPE_PLATFORM, NMPlatformPrivate); @@ -4640,7 +4630,6 @@ nm_platform_class_init (NMPlatformClass *platform_class) g_type_class_add_private (object_class, sizeof (NMPlatformPrivate)); object_class->set_property = set_property; - object_class->constructed = constructed; object_class->finalize = finalize; platform_class->wifi_set_powersave = wifi_set_powersave; @@ -4654,9 +4643,9 @@ nm_platform_class_init (NMPlatformClass *platform_class) G_PARAM_STATIC_STRINGS)); g_object_class_install_property - (object_class, PROP_REGISTER_SINGLETON, - g_param_spec_boolean (NM_PLATFORM_REGISTER_SINGLETON, "", "", - FALSE, + (object_class, PROP_LOG_WITH_PTR, + g_param_spec_boolean (NM_PLATFORM_LOG_WITH_PTR, "", "", + TRUE, G_PARAM_WRITABLE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS)); diff --git a/src/platform/nm-platform.h b/src/platform/nm-platform.h index 0ad15aaa48..202cbe5c59 100644 --- a/src/platform/nm-platform.h +++ b/src/platform/nm-platform.h @@ -45,7 +45,7 @@ /*****************************************************************************/ #define NM_PLATFORM_NETNS_SUPPORT "netns-support" -#define NM_PLATFORM_REGISTER_SINGLETON "register-singleton" +#define NM_PLATFORM_LOG_WITH_PTR "log-with-ptr" /*****************************************************************************/ @@ -719,7 +719,6 @@ GType nm_platform_get_type (void); void nm_platform_setup (NMPlatform *instance); NMPlatform *nm_platform_get (void); -NMPlatform *nm_platform_try_get (void); #define NM_PLATFORM_GET (nm_platform_get ()) @@ -742,6 +741,8 @@ _nm_platform_uint8_inv (guint8 scope) return (guint8) ~scope; } +gboolean nm_platform_get_log_with_ptr (NMPlatform *self); + NMPNetns *nm_platform_netns_get (NMPlatform *self); gboolean nm_platform_netns_push (NMPlatform *platform, NMPNetns **netns); diff --git a/src/platform/tests/test-general.c b/src/platform/tests/test-general.c index 658aad264e..2ccfac7d2c 100644 --- a/src/platform/tests/test-general.c +++ b/src/platform/tests/test-general.c @@ -35,7 +35,7 @@ test_init_linux_platform (void) { gs_unref_object NMPlatform *platform = NULL; - platform = nm_linux_platform_new (NM_PLATFORM_NETNS_SUPPORT_DEFAULT); + platform = nm_linux_platform_new (TRUE, NM_PLATFORM_NETNS_SUPPORT_DEFAULT); } /*****************************************************************************/ @@ -46,7 +46,7 @@ test_link_get_all (void) gs_unref_object NMPlatform *platform = NULL; gs_unref_array GArray *links = NULL; - platform = nm_linux_platform_new (NM_PLATFORM_NETNS_SUPPORT_DEFAULT); + platform = nm_linux_platform_new (TRUE, NM_PLATFORM_NETNS_SUPPORT_DEFAULT); links = nm_platform_link_get_all (platform); } diff --git a/src/platform/tests/test-link.c b/src/platform/tests/test-link.c index b14fdb0644..ed435567f0 100644 --- a/src/platform/tests/test-link.c +++ b/src/platform/tests/test-link.c @@ -1900,7 +1900,7 @@ _test_netns_create_platform (void) netns = nmp_netns_new (); g_assert (NMP_IS_NETNS (netns)); - platform = nm_linux_platform_new (TRUE); + platform = nm_linux_platform_new (TRUE, TRUE); g_assert (NM_IS_LINUX_PLATFORM (platform)); nmp_netns_pop (netns); @@ -1961,7 +1961,7 @@ test_netns_general (gpointer fixture, gconstpointer test_data) if (_test_netns_check_skip ()) return; - platform_1 = nm_linux_platform_new (TRUE); + platform_1 = nm_linux_platform_new (TRUE, TRUE); platform_2 = _test_netns_create_platform (); /* add some dummy devices. The "other-*" devices are there to bump the ifindex */ @@ -2061,7 +2061,7 @@ test_netns_set_netns (gpointer fixture, gconstpointer test_data) if (_test_netns_check_skip ()) return; - platforms[0] = platform_0 = nm_linux_platform_new (TRUE); + platforms[0] = platform_0 = nm_linux_platform_new (TRUE, TRUE); platforms[1] = platform_1 = _test_netns_create_platform (); platforms[2] = platform_2 = _test_netns_create_platform (); @@ -2156,7 +2156,7 @@ test_netns_push (gpointer fixture, gconstpointer test_data) if (_test_netns_check_skip ()) return; - pl[0].platform = platform_0 = nm_linux_platform_new (TRUE); + pl[0].platform = platform_0 = nm_linux_platform_new (TRUE, TRUE); pl[1].platform = platform_1 = _test_netns_create_platform (); pl[2].platform = platform_2 = _test_netns_create_platform (); @@ -2288,7 +2288,7 @@ test_netns_bind_to_path (gpointer fixture, gconstpointer test_data) if (_test_netns_check_skip ()) return; - platforms[0] = platform_0 = nm_linux_platform_new (TRUE); + platforms[0] = platform_0 = nm_linux_platform_new (TRUE, TRUE); platforms[1] = platform_1 = _test_netns_create_platform (); platforms[2] = platform_2 = _test_netns_create_platform (); @@ -2433,7 +2433,7 @@ test_sysctl_netns_switch (void) if (_test_netns_check_skip ()) return; - platforms[0] = platform_0 = nm_linux_platform_new (TRUE); + platforms[0] = platform_0 = nm_linux_platform_new (TRUE, TRUE); platforms[1] = platform_1 = _test_netns_create_platform (); platforms[2] = platform_2 = _test_netns_create_platform (); PL = platforms[nmtst_get_rand_int () % 3]; diff --git a/src/tests/test-route-manager.c b/src/tests/test-route-manager.c index d534075753..6650d26c43 100644 --- a/src/tests/test-route-manager.c +++ b/src/tests/test-route-manager.c @@ -33,6 +33,10 @@ typedef struct { int ifindex0, ifindex1; } test_fixture; +NMRouteManager *route_manager_get (void); + +NM_DEFINE_SINGLETON_GETTER (NMRouteManager, route_manager_get, NM_TYPE_ROUTE_MANAGER); + /*****************************************************************************/ static void @@ -60,7 +64,7 @@ setup_dev0_ip4 (int ifindex, guint mss_of_first_route, guint32 metric_of_second_ route.mss = 0; g_array_append_val (routes, route); - nm_route_manager_ip4_route_sync (nm_route_manager_get (), ifindex, routes, TRUE, TRUE); + nm_route_manager_ip4_route_sync (route_manager_get (), ifindex, routes, TRUE, TRUE); g_array_free (routes, TRUE); } @@ -106,7 +110,7 @@ setup_dev1_ip4 (int ifindex) route.metric = 22; g_array_append_val (routes, route); - nm_route_manager_ip4_route_sync (nm_route_manager_get (), ifindex, routes, TRUE, TRUE); + nm_route_manager_ip4_route_sync (route_manager_get (), ifindex, routes, TRUE, TRUE); g_array_free (routes, TRUE); } @@ -133,7 +137,7 @@ update_dev0_ip4 (int ifindex) route.metric = 21; g_array_append_val (routes, route); - nm_route_manager_ip4_route_sync (nm_route_manager_get (), ifindex, routes, TRUE, TRUE); + nm_route_manager_ip4_route_sync (route_manager_get (), ifindex, routes, TRUE, TRUE); g_array_free (routes, TRUE); } @@ -345,7 +349,7 @@ test_ip4 (test_fixture *fixture, gconstpointer user_data) nmtst_platform_ip4_routes_equal ((NMPlatformIP4Route *) routes->data, state2, routes->len, TRUE); g_array_free (routes, TRUE); - nm_route_manager_route_flush (nm_route_manager_get (), fixture->ifindex0); + nm_route_manager_route_flush (route_manager_get (), fixture->ifindex0); /* 6.6.6.0/24 is now on dev1 * 6.6.6.0/24 is also still on dev1 with bumped metric 21. @@ -357,7 +361,7 @@ test_ip4 (test_fixture *fixture, gconstpointer user_data) nmtst_platform_ip4_routes_equal ((NMPlatformIP4Route *) routes->data, state3, routes->len, TRUE); g_array_free (routes, TRUE); - nm_route_manager_route_flush (nm_route_manager_get (), fixture->ifindex1); + nm_route_manager_route_flush (route_manager_get (), fixture->ifindex1); /* No routes left. */ routes = ip4_routes (fixture); @@ -408,7 +412,7 @@ setup_dev0_ip6 (int ifindex) 0); g_array_append_val (routes, *route); - nm_route_manager_ip6_route_sync (nm_route_manager_get (), ifindex, routes, TRUE, TRUE); + nm_route_manager_ip6_route_sync (route_manager_get (), ifindex, routes, TRUE, TRUE); g_array_free (routes, TRUE); } @@ -466,7 +470,7 @@ setup_dev1_ip6 (int ifindex) 0); g_array_append_val (routes, *route); - nm_route_manager_ip6_route_sync (nm_route_manager_get (), ifindex, routes, TRUE, TRUE); + nm_route_manager_ip6_route_sync (route_manager_get (), ifindex, routes, TRUE, TRUE); g_array_free (routes, TRUE); } @@ -513,7 +517,7 @@ update_dev0_ip6 (int ifindex) 0); g_array_append_val (routes, *route); - nm_route_manager_ip6_route_sync (nm_route_manager_get (), ifindex, routes, TRUE, TRUE); + nm_route_manager_ip6_route_sync (route_manager_get (), ifindex, routes, TRUE, TRUE); g_array_free (routes, TRUE); } @@ -759,7 +763,7 @@ test_ip6 (test_fixture *fixture, gconstpointer user_data) nmtst_platform_ip6_routes_equal ((NMPlatformIP6Route *) routes->data, state2, routes->len, TRUE); g_array_free (routes, TRUE); - nm_route_manager_route_flush (nm_route_manager_get (), fixture->ifindex0); + nm_route_manager_route_flush (route_manager_get (), fixture->ifindex0); /* 2001:db8:abad:c0de::/64 on dev1 is still there, went away from dev0 * 2001:db8:8086::/48 is now on dev1 @@ -771,7 +775,7 @@ test_ip6 (test_fixture *fixture, gconstpointer user_data) nmtst_platform_ip6_routes_equal ((NMPlatformIP6Route *) routes->data, state3, routes->len, TRUE); g_array_free (routes, TRUE); - nm_route_manager_route_flush (nm_route_manager_get (), fixture->ifindex1); + nm_route_manager_route_flush (route_manager_get (), fixture->ifindex1); /* No routes left. */ routes = ip6_routes (fixture); @@ -835,7 +839,7 @@ test_ip4_full_sync (test_fixture *fixture, gconstpointer user_data) g_array_set_size (routes, 2); g_array_index (routes, NMPlatformIP4Route, 0) = r01; g_array_index (routes, NMPlatformIP4Route, 1) = r02; - nm_route_manager_ip4_route_sync (nm_route_manager_get (), fixture->ifindex0, routes, TRUE, TRUE); + nm_route_manager_ip4_route_sync (route_manager_get (), fixture->ifindex0, routes, TRUE, TRUE); _assert_route_check (vtable, TRUE, (const NMPlatformIPXRoute *) &r01); _assert_route_check (vtable, TRUE, (const NMPlatformIPXRoute *) &r02); @@ -847,7 +851,7 @@ test_ip4_full_sync (test_fixture *fixture, gconstpointer user_data) _assert_route_check (vtable, TRUE, (const NMPlatformIPXRoute *) &r02); _assert_route_check (vtable, TRUE, (const NMPlatformIPXRoute *) &r03); - nm_route_manager_ip4_route_sync (nm_route_manager_get (), fixture->ifindex0, routes, TRUE, FALSE); + nm_route_manager_ip4_route_sync (route_manager_get (), fixture->ifindex0, routes, TRUE, FALSE); _assert_route_check (vtable, TRUE, (const NMPlatformIPXRoute *) &r01); _assert_route_check (vtable, TRUE, (const NMPlatformIPXRoute *) &r02); @@ -855,13 +859,13 @@ test_ip4_full_sync (test_fixture *fixture, gconstpointer user_data) g_array_set_size (routes, 1); - nm_route_manager_ip4_route_sync (nm_route_manager_get (), fixture->ifindex0, routes, TRUE, FALSE); + nm_route_manager_ip4_route_sync (route_manager_get (), fixture->ifindex0, routes, TRUE, FALSE); _assert_route_check (vtable, TRUE, (const NMPlatformIPXRoute *) &r01); _assert_route_check (vtable, FALSE, (const NMPlatformIPXRoute *) &r02); _assert_route_check (vtable, TRUE, (const NMPlatformIPXRoute *) &r03); - nm_route_manager_ip4_route_sync (nm_route_manager_get (), fixture->ifindex0, routes, TRUE, TRUE); + nm_route_manager_ip4_route_sync (route_manager_get (), fixture->ifindex0, routes, TRUE, TRUE); _assert_route_check (vtable, TRUE, (const NMPlatformIPXRoute *) &r01); _assert_route_check (vtable, FALSE, (const NMPlatformIPXRoute *) &r02); diff --git a/src/vpn/nm-vpn-connection.c b/src/vpn/nm-vpn-connection.c index 4079195a09..dba3546ff0 100644 --- a/src/vpn/nm-vpn-connection.c +++ b/src/vpn/nm-vpn-connection.c @@ -40,6 +40,7 @@ #include "NetworkManagerUtils.h" #include "settings/nm-settings-connection.h" #include "nm-dispatcher.h" +#include "nm-netns.h" #include "settings/nm-agent-manager.h" #include "nm-core-internal.h" #include "nm-pacrunner-manager.h" @@ -120,8 +121,8 @@ typedef struct { /* Firewall */ NMFirewallManagerCallId fw_call; - NMDefaultRouteManager *default_route_manager; - NMRouteManager *route_manager; + NMNetns *netns; + GDBusProxy *proxy; GCancellable *cancellable; GVariant *connect_hash; @@ -392,9 +393,9 @@ vpn_cleanup (NMVpnConnection *self, NMDevice *parent_dev) NMVpnConnectionPrivate *priv = NM_VPN_CONNECTION_GET_PRIVATE (self); if (priv->ip_ifindex) { - nm_platform_link_set_down (NM_PLATFORM_GET, priv->ip_ifindex); - nm_route_manager_route_flush (priv->route_manager, priv->ip_ifindex); - nm_platform_address_flush (NM_PLATFORM_GET, priv->ip_ifindex); + nm_platform_link_set_down (nm_netns_get_platform (priv->netns), priv->ip_ifindex); + nm_route_manager_route_flush (nm_netns_get_route_manager (priv->netns), priv->ip_ifindex); + nm_platform_address_flush (nm_netns_get_platform (priv->netns), priv->ip_ifindex); } remove_parent_device_config (self, parent_dev); @@ -495,8 +496,8 @@ _set_vpn_state (NMVpnConnection *self, dispatcher_cleanup (self); - nm_default_route_manager_ip4_update_default_route (priv->default_route_manager, self); - nm_default_route_manager_ip6_update_default_route (priv->default_route_manager, self); + nm_default_route_manager_ip4_update_default_route (nm_netns_get_default_route_manager (priv->netns), self); + nm_default_route_manager_ip6_update_default_route (nm_netns_get_default_route_manager (priv->netns), self); /* The connection gets destroyed by the VPN manager when it enters the * disconnected/failed state, but we need to keep it around for a bit @@ -1090,10 +1091,13 @@ nm_vpn_connection_apply_config (NMVpnConnection *self) NMVpnConnectionPrivate *priv = NM_VPN_CONNECTION_GET_PRIVATE (self); if (priv->ip_ifindex > 0) { - nm_platform_link_set_up (NM_PLATFORM_GET, priv->ip_ifindex, NULL); + nm_platform_link_set_up (nm_netns_get_platform (priv->netns), priv->ip_ifindex, NULL); if (priv->ip4_config) { - if (!nm_ip4_config_commit (priv->ip4_config, priv->ip_ifindex, + if (!nm_ip4_config_commit (priv->ip4_config, + nm_netns_get_platform (priv->netns), + nm_netns_get_route_manager (priv->netns), + priv->ip_ifindex, TRUE, nm_vpn_connection_get_ip4_route_metric (self))) return FALSE; @@ -1101,19 +1105,21 @@ nm_vpn_connection_apply_config (NMVpnConnection *self) if (priv->ip6_config) { if (!nm_ip6_config_commit (priv->ip6_config, + nm_netns_get_platform (priv->netns), + nm_netns_get_route_manager (priv->netns), priv->ip_ifindex, TRUE)) return FALSE; } - if (priv->mtu && priv->mtu != nm_platform_link_get_mtu (NM_PLATFORM_GET, priv->ip_ifindex)) - nm_platform_link_set_mtu (NM_PLATFORM_GET, priv->ip_ifindex, priv->mtu); + if (priv->mtu && priv->mtu != nm_platform_link_get_mtu (nm_netns_get_platform (priv->netns), priv->ip_ifindex)) + nm_platform_link_set_mtu (nm_netns_get_platform (priv->netns), priv->ip_ifindex, priv->mtu); } apply_parent_device_config (self); - nm_default_route_manager_ip4_update_default_route (priv->default_route_manager, self); - nm_default_route_manager_ip6_update_default_route (priv->default_route_manager, self); + nm_default_route_manager_ip4_update_default_route (nm_netns_get_default_route_manager (priv->netns), self); + nm_default_route_manager_ip6_update_default_route (nm_netns_get_default_route_manager (priv->netns), self); _LOGI ("VPN connection: (IP Config Get) complete"); if (priv->vpn_state < STATE_PRE_UP) @@ -1266,10 +1272,10 @@ process_generic_config (NMVpnConnection *self, GVariant *dict) if (priv->ip_iface) { /* Grab the interface index for address/routing operations */ - priv->ip_ifindex = nm_platform_link_get_ifindex (NM_PLATFORM_GET, priv->ip_iface); + priv->ip_ifindex = nm_platform_link_get_ifindex (nm_netns_get_platform (priv->netns), priv->ip_iface); if (priv->ip_ifindex <= 0) { - nm_platform_process_events (NM_PLATFORM_GET); - priv->ip_ifindex = nm_platform_link_get_ifindex (NM_PLATFORM_GET, priv->ip_iface); + nm_platform_process_events (nm_netns_get_platform (priv->netns)); + priv->ip_ifindex = nm_platform_link_get_ifindex (nm_netns_get_platform (priv->netns), priv->ip_iface); } if (priv->ip_ifindex <= 0) { _LOGE ("failed to look up VPN interface index for \"%s\"", priv->ip_iface); @@ -2614,8 +2620,7 @@ nm_vpn_connection_init (NMVpnConnection *self) priv->vpn_state = STATE_WAITING; priv->secrets_idx = SECRETS_REQ_SYSTEM; - priv->default_route_manager = g_object_ref (nm_default_route_manager_get ()); - priv->route_manager = g_object_ref (nm_route_manager_get ()); + priv->netns = g_object_ref (nm_netns_get ()); } static void @@ -2645,9 +2650,6 @@ dispose (GObject *object) fw_call_cleanup (self); G_OBJECT_CLASS (nm_vpn_connection_parent_class)->dispose (object); - - g_clear_object (&priv->default_route_manager); - g_clear_object (&priv->route_manager); } static void @@ -2662,6 +2664,8 @@ finalize (GObject *object) g_free (priv->ip6_external_gw); G_OBJECT_CLASS (nm_vpn_connection_parent_class)->finalize (object); + + g_clear_object (&priv->netns); } static gboolean |