diff options
author | Thomas Haller <thaller@redhat.com> | 2017-01-04 14:18:09 +0100 |
---|---|---|
committer | Thomas Haller <thaller@redhat.com> | 2017-01-04 14:18:09 +0100 |
commit | 719d4902d8c32ba88417dd86bc06ca833cc62dd8 (patch) | |
tree | 9864dff2ee95c130d9b544410831f79790aa7a30 | |
parent | 9473943ef30005b3bcfba0be51254b1e2932174d (diff) | |
parent | 2a14a1c7bd250f584532ffd3b9a6f00ce87d6f84 (diff) | |
download | NetworkManager-719d4902d8c32ba88417dd86bc06ca833cc62dd8.tar.gz |
device: merge branch 'th/device-parent-bgo776719'
https://bugzilla.gnome.org/show_bug.cgi?id=776719
-rw-r--r-- | src/devices/nm-device-ethernet.c | 20 | ||||
-rw-r--r-- | src/devices/nm-device-ip-tunnel.c | 51 | ||||
-rw-r--r-- | src/devices/nm-device-ip-tunnel.h | 4 | ||||
-rw-r--r-- | src/devices/nm-device-logging.h | 2 | ||||
-rw-r--r-- | src/devices/nm-device-macvlan.c | 146 | ||||
-rw-r--r-- | src/devices/nm-device-macvlan.h | 4 | ||||
-rw-r--r-- | src/devices/nm-device-tun.c | 18 | ||||
-rw-r--r-- | src/devices/nm-device-veth.c | 76 | ||||
-rw-r--r-- | src/devices/nm-device-vlan.c | 165 | ||||
-rw-r--r-- | src/devices/nm-device-vlan.h | 4 | ||||
-rw-r--r-- | src/devices/nm-device-vxlan.c | 78 | ||||
-rw-r--r-- | src/devices/nm-device-vxlan.h | 4 | ||||
-rw-r--r-- | src/devices/nm-device.c | 310 | ||||
-rw-r--r-- | src/devices/nm-device.h | 28 | ||||
-rw-r--r-- | src/nm-iface-helper.c | 7 | ||||
-rw-r--r-- | src/nm-manager.c | 41 | ||||
-rw-r--r-- | src/platform/nm-platform-utils.c | 28 | ||||
-rw-r--r-- | src/platform/nm-platform-utils.h | 3 | ||||
-rw-r--r-- | src/platform/nm-platform.c | 16 | ||||
-rw-r--r-- | src/platform/nm-platform.h | 3 | ||||
-rw-r--r-- | src/settings/plugins/ifcfg-rh/nms-ifcfg-rh-connection.c | 4 |
21 files changed, 536 insertions, 476 deletions
diff --git a/src/devices/nm-device-ethernet.c b/src/devices/nm-device-ethernet.c index d458fffa22..07f60d05b8 100644 --- a/src/devices/nm-device-ethernet.c +++ b/src/devices/nm-device-ethernet.c @@ -260,18 +260,6 @@ _update_s390_subchannels (NMDeviceEthernet *self) } static void -constructed (GObject *object) -{ - const NMPlatformLink *pllink; - - G_OBJECT_CLASS (nm_device_ethernet_parent_class)->constructed (object); - - pllink = nm_platform_link_get (NM_PLATFORM_GET, nm_device_get_ifindex ((NMDevice *) object)); - if (pllink && pllink->initialized) - _update_s390_subchannels ((NMDeviceEthernet *) object); -} - -static void clear_secrets_tries (NMDevice *device) { NMActRequest *req; @@ -1679,10 +1667,11 @@ carrier_changed (NMDevice *device, gboolean carrier) } static void -link_changed (NMDevice *device, NMPlatformLink *info) +link_changed (NMDevice *device, + const NMPlatformLink *pllink) { - NM_DEVICE_CLASS (nm_device_ethernet_parent_class)->link_changed (device, info); - if (info->initialized) + NM_DEVICE_CLASS (nm_device_ethernet_parent_class)->link_changed (device, pllink); + if (pllink->initialized) _update_s390_subchannels ((NMDeviceEthernet *) device); } @@ -1772,7 +1761,6 @@ nm_device_ethernet_class_init (NMDeviceEthernetClass *klass) NM_DEVICE_CLASS_DECLARE_TYPES (klass, NM_SETTING_WIRED_SETTING_NAME, NM_LINK_TYPE_ETHERNET) - object_class->constructed = constructed; object_class->dispose = dispose; object_class->finalize = finalize; object_class->get_property = get_property; diff --git a/src/devices/nm-device-ip-tunnel.c b/src/devices/nm-device-ip-tunnel.c index f51c9f35a0..718876086e 100644 --- a/src/devices/nm-device-ip-tunnel.c +++ b/src/devices/nm-device-ip-tunnel.c @@ -46,7 +46,6 @@ _LOG_DECLARE_SELF(NMDeviceIPTunnel); NM_GOBJECT_PROPERTIES_DEFINE (NMDeviceIPTunnel, PROP_MODE, - PROP_PARENT, PROP_LOCAL, PROP_REMOTE, PROP_TTL, @@ -60,8 +59,6 @@ NM_GOBJECT_PROPERTIES_DEFINE (NMDeviceIPTunnel, typedef struct { NMIPTunnelMode mode; - NMDevice *parent; - int parent_ifindex; char *local; char *remote; guint8 ttl; @@ -126,8 +123,7 @@ update_properties_from_ifindex (NMDevice *device, int ifindex) { NMDeviceIPTunnel *self = NM_DEVICE_IP_TUNNEL (device); NMDeviceIPTunnelPrivate *priv = NM_DEVICE_IP_TUNNEL_GET_PRIVATE (self); - NMDevice *parent; - int parent_ifindex; + int parent_ifindex = 0; in_addr_t local4, remote4; struct in6_addr local6, remote6; guint8 ttl = 0, tos = 0, encap_limit = 0; @@ -137,11 +133,7 @@ update_properties_from_ifindex (NMDevice *device, int ifindex) if (ifindex <= 0) { clear: - if (priv->parent || priv->parent_ifindex) { - g_clear_object (&priv->parent); - priv->parent_ifindex = 0; - _notify (self, PROP_PARENT); - } + nm_device_parent_set_ifindex (device, 0); if (priv->local) { g_clear_pointer (&priv->local, g_free); _notify (self, PROP_LOCAL); @@ -257,14 +249,7 @@ clear: } else g_return_if_reached (); - if (priv->parent_ifindex != parent_ifindex) { - g_clear_object (&priv->parent); - priv->parent_ifindex = parent_ifindex; - parent = nm_manager_get_device_by_ifindex (nm_manager_get (), parent_ifindex); - if (parent) - priv->parent = g_object_ref (parent); - _notify (self, PROP_PARENT); - } + nm_device_parent_set_ifindex (device, parent_ifindex); if (priv->addr_family == AF_INET) { if (!address_equal_pn (AF_INET, priv->local, &local4)) { @@ -331,9 +316,10 @@ update_properties (NMDevice *device) } static void -link_changed (NMDevice *device, NMPlatformLink *info) +link_changed (NMDevice *device, + const NMPlatformLink *pllink) { - NM_DEVICE_CLASS (nm_device_ip_tunnel_parent_class)->link_changed (device, info); + NM_DEVICE_CLASS (nm_device_ip_tunnel_parent_class)->link_changed (device, pllink); update_properties (device); } @@ -382,8 +368,7 @@ update_connection (NMDevice *device, NMConnection *connection) if (nm_setting_ip_tunnel_get_mode (s_ip_tunnel) != priv->mode) g_object_set (G_OBJECT (s_ip_tunnel), NM_SETTING_IP_TUNNEL_MODE, priv->mode, NULL); - if (priv->parent_ifindex > 0) - parent = nm_manager_get_device_by_ifindex (nm_manager_get (), priv->parent_ifindex); + parent = nm_device_parent_get_device (device); /* Update parent in the connection; default to parent's interface name */ if (parent) { @@ -512,7 +497,7 @@ check_connection_compatible (NMDevice *device, NMConnection *connection) /* Check parent interface; could be an interface name or a UUID */ parent = nm_setting_ip_tunnel_get_parent (s_ip_tunnel); if (parent) { - if (!match_parent (priv->parent, parent)) + if (!match_parent (nm_device_parent_get_device (device), parent)) return FALSE; } @@ -760,14 +745,6 @@ create_and_realize (NMDevice *device, } static void -realize_start_notify (NMDevice *device, const NMPlatformLink *plink) -{ - NM_DEVICE_CLASS (nm_device_ip_tunnel_parent_class)->realize_start_notify (device, plink); - - update_properties (device); -} - -static void ip4_config_pre_commit (NMDevice *device, NMIP4Config *config) { NMConnection *connection; @@ -806,16 +783,11 @@ get_property (GObject *object, guint prop_id, GValue *value, GParamSpec *pspec) { NMDeviceIPTunnelPrivate *priv = NM_DEVICE_IP_TUNNEL_GET_PRIVATE ((NMDeviceIPTunnel *) object); - NMDevice *parent; switch (prop_id) { case PROP_MODE: g_value_set_uint (value, priv->mode); break; - case PROP_PARENT: - parent = nm_manager_get_device_by_ifindex (nm_manager_get (), priv->parent_ifindex); - nm_utils_g_value_set_object_path (value, parent); - break; case PROP_LOCAL: g_value_set_string (value, priv->local); break; @@ -902,7 +874,6 @@ nm_device_ip_tunnel_class_init (NMDeviceIPTunnelClass *klass) device_class->create_and_realize = create_and_realize; device_class->get_generic_capabilities = get_generic_capabilities; device_class->ip4_config_pre_commit = ip4_config_pre_commit; - device_class->realize_start_notify = realize_start_notify; device_class->unrealize_notify = unrealize_notify; NM_DEVICE_CLASS_DECLARE_TYPES (klass, @@ -919,12 +890,6 @@ nm_device_ip_tunnel_class_init (NMDeviceIPTunnelClass *klass) G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS); - obj_properties[PROP_PARENT] = - g_param_spec_string (NM_DEVICE_IP_TUNNEL_PARENT, "", "", - NULL, - G_PARAM_READABLE | - G_PARAM_STATIC_STRINGS); - obj_properties[PROP_LOCAL] = g_param_spec_string (NM_DEVICE_IP_TUNNEL_LOCAL, "", "", NULL, diff --git a/src/devices/nm-device-ip-tunnel.h b/src/devices/nm-device-ip-tunnel.h index 5027a27b07..4bff6e33e8 100644 --- a/src/devices/nm-device-ip-tunnel.h +++ b/src/devices/nm-device-ip-tunnel.h @@ -32,7 +32,6 @@ #define NM_DEVICE_IP_TUNNEL_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), NM_TYPE_DEVICE_IP_TUNNEL, NMDeviceIPTunnelClass)) #define NM_DEVICE_IP_TUNNEL_MODE "mode" -#define NM_DEVICE_IP_TUNNEL_PARENT "parent" #define NM_DEVICE_IP_TUNNEL_LOCAL "local" #define NM_DEVICE_IP_TUNNEL_REMOTE "remote" #define NM_DEVICE_IP_TUNNEL_TTL "ttl" @@ -43,6 +42,9 @@ #define NM_DEVICE_IP_TUNNEL_ENCAPSULATION_LIMIT "encapsulation-limit" #define NM_DEVICE_IP_TUNNEL_FLOW_LABEL "flow-label" +/* defined in the parent class, but exposed on D-Bus by the subclass. */ +#define NM_DEVICE_IP_TUNNEL_PARENT NM_DEVICE_PARENT + typedef struct _NMDeviceIPTunnel NMDeviceIPTunnel; typedef struct _NMDeviceIPTunnelClass NMDeviceIPTunnelClass; diff --git a/src/devices/nm-device-logging.h b/src/devices/nm-device-logging.h index fac92eaca8..b7ec58fd8f 100644 --- a/src/devices/nm-device-logging.h +++ b/src/devices/nm-device-logging.h @@ -24,7 +24,7 @@ #include "nm-device.h" #define _LOG_DECLARE_SELF(t) \ -inline static NMDevice * \ +_nm_unused inline static NMDevice * \ _nm_device_log_self_to_device (t *self) \ { \ return (NMDevice *) self; \ diff --git a/src/devices/nm-device-macvlan.c b/src/devices/nm-device-macvlan.c index 7b0e844367..9d3c3c370b 100644 --- a/src/devices/nm-device-macvlan.c +++ b/src/devices/nm-device-macvlan.c @@ -44,16 +44,13 @@ _LOG_DECLARE_SELF(NMDeviceMacvlan); /*****************************************************************************/ NM_GOBJECT_PROPERTIES_DEFINE (NMDeviceMacvlan, - PROP_PARENT, PROP_MODE, PROP_NO_PROMISC, PROP_TAP, ); typedef struct { - int parent_ifindex; gulong parent_state_id; - NMDevice *parent; NMPlatformLnkMacvlan props; } NMDeviceMacvlanPrivate; @@ -141,21 +138,24 @@ parent_state_changed (NMDevice *parent, } static void -nm_device_macvlan_set_parent (NMDeviceMacvlan *self, NMDevice *parent) - { +parent_changed_notify (NMDevice *device, + int old_ifindex, + NMDevice *old_parent, + int new_ifindex, + NMDevice *new_parent) +{ + NMDeviceMacvlan *self = NM_DEVICE_MACVLAN (device); NMDeviceMacvlanPrivate *priv = NM_DEVICE_MACVLAN_GET_PRIVATE (self); - NMDevice *device = NM_DEVICE (self); - if (parent == priv->parent) - return; - - nm_clear_g_signal_handler (priv->parent, &priv->parent_state_id); + NM_DEVICE_CLASS (nm_device_macvlan_parent_class)->parent_changed_notify (device, old_ifindex, old_parent, new_ifindex, new_parent); - g_clear_object (&priv->parent); + /* note that @self doesn't have to clear @parent_state_id on dispose, + * because NMDevice's dispose() will unset the parent, which in turn calls + * parent_changed_notify(). */ + nm_clear_g_signal_handler (old_parent, &priv->parent_state_id); - if (parent) { - priv->parent = g_object_ref (parent); - priv->parent_state_id = g_signal_connect (priv->parent, + if (new_parent) { + priv->parent_state_id = g_signal_connect (new_parent, "state-changed", G_CALLBACK (parent_state_changed), device); @@ -163,15 +163,16 @@ nm_device_macvlan_set_parent (NMDeviceMacvlan *self, NMDevice *parent) /* Set parent-dependent unmanaged flag */ nm_device_set_unmanaged_by_flags (device, NM_UNMANAGED_PARENT, - !nm_device_get_managed (parent, FALSE), + !nm_device_get_managed (new_parent, FALSE), NM_DEVICE_STATE_REASON_PARENT_MANAGED_CHANGED); } - /* Recheck availability now that the parent has changed */ - nm_device_queue_recheck_available (device, - NM_DEVICE_STATE_REASON_PARENT_CHANGED, - NM_DEVICE_STATE_REASON_PARENT_CHANGED); - _notify (self, PROP_PARENT); + if (new_ifindex > 0) { + /* Recheck availability now that the parent has changed */ + nm_device_queue_recheck_available (device, + NM_DEVICE_STATE_REASON_PARENT_CHANGED, + NM_DEVICE_STATE_REASON_PARENT_CHANGED); + } } static void @@ -182,7 +183,6 @@ update_properties (NMDevice *device) GObject *object = G_OBJECT (device); const NMPlatformLnkMacvlan *props; const NMPlatformLink *plink; - NMDevice *parent = NULL; if (priv->props.tap) props = nm_platform_link_get_lnk_macvtap (NM_PLATFORM_GET, nm_device_get_ifindex (device), &plink); @@ -196,25 +196,22 @@ update_properties (NMDevice *device) g_object_freeze_notify (object); - if (priv->parent_ifindex != plink->parent) { - parent = nm_manager_get_device_by_ifindex (nm_manager_get (), plink->parent); - nm_device_macvlan_set_parent (self, parent); - } + nm_device_parent_set_ifindex (device, plink->parent); if (priv->props.mode != props->mode) _notify (self, PROP_MODE); if (priv->props.no_promisc != props->no_promisc) _notify (self, PROP_NO_PROMISC); - priv->parent_ifindex = plink->parent; priv->props = *props; g_object_thaw_notify (object); } static void -link_changed (NMDevice *device, NMPlatformLink *info) +link_changed (NMDevice *device, + const NMPlatformLink *pllink) { - NM_DEVICE_CLASS (nm_device_macvlan_parent_class)->link_changed (device, info); + NM_DEVICE_CLASS (nm_device_macvlan_parent_class)->link_changed (device, pllink); update_properties (device); } @@ -232,17 +229,17 @@ create_and_realize (NMDevice *device, int parent_ifindex; s_macvlan = nm_connection_get_setting_macvlan (connection); - g_assert (s_macvlan); + g_return_val_if_fail (s_macvlan, FALSE); + + parent_ifindex = parent ? nm_device_get_ifindex (parent) : 0; - if (!parent) { + if (parent_ifindex <= 0) { g_set_error (error, NM_DEVICE_ERROR, NM_DEVICE_ERROR_FAILED, "MACVLAN devices can not be created without a parent interface"); + g_return_val_if_fail (!parent, FALSE); return FALSE; } - parent_ifindex = nm_device_get_ifindex (parent); - g_warn_if_fail (parent_ifindex > 0); - lnk.mode = setting_mode_to_platform (nm_setting_macvlan_get_mode (s_macvlan)); if (!lnk.mode) { g_set_error (error, NM_DEVICE_ERROR, NM_DEVICE_ERROR_FAILED, @@ -282,45 +279,23 @@ get_generic_capabilities (NMDevice *dev) static gboolean is_available (NMDevice *device, NMDeviceCheckDevAvailableFlags flags) { - if (!NM_DEVICE_MACVLAN_GET_PRIVATE ((NMDeviceMacvlan *) device)->parent) + if (!nm_device_parent_get_device (device)) return FALSE; - return NM_DEVICE_CLASS (nm_device_macvlan_parent_class)->is_available (device, flags); } -static void -notify_new_device_added (NMDevice *device, NMDevice *new_device) -{ - NMDeviceMacvlan *self = NM_DEVICE_MACVLAN (device); - NMDeviceMacvlanPrivate *priv = NM_DEVICE_MACVLAN_GET_PRIVATE (self); - - if (priv->parent) - return; - - if (!nm_device_is_real (device)) - return; - - update_properties (device); - - if ( priv->parent_ifindex <= 0 - || nm_device_get_ifindex (new_device) != priv->parent_ifindex) - return; - - priv->parent_ifindex = nm_device_get_ifindex (new_device); - nm_device_macvlan_set_parent (self, new_device); -} - /*****************************************************************************/ static gboolean match_parent (NMDeviceMacvlan *self, const char *parent) { - NMDeviceMacvlanPrivate *priv = NM_DEVICE_MACVLAN_GET_PRIVATE (self); + NMDevice *parent_device; g_return_val_if_fail (parent != NULL, FALSE); - if (!priv->parent) + parent_device = nm_device_parent_get_device (NM_DEVICE (self)); + if (!parent_device) return FALSE; if (nm_utils_is_uuid (parent)) { @@ -331,7 +306,7 @@ match_parent (NMDeviceMacvlan *self, const char *parent) * device has that connection activated. */ - parent_req = nm_device_get_act_request (priv->parent); + parent_req = nm_device_get_act_request (parent_device); if (!parent_req) return FALSE; @@ -343,7 +318,7 @@ match_parent (NMDeviceMacvlan *self, const char *parent) return FALSE; } else { /* interface name */ - if (g_strcmp0 (parent, nm_device_get_ip_iface (priv->parent)) != 0) + if (g_strcmp0 (parent, nm_device_get_ip_iface (parent_device)) != 0) return FALSE; } @@ -353,8 +328,8 @@ match_parent (NMDeviceMacvlan *self, const char *parent) static gboolean match_hwaddr (NMDevice *device, NMConnection *connection, gboolean fail_if_no_hwaddr) { - NMDeviceMacvlanPrivate *priv = NM_DEVICE_MACVLAN_GET_PRIVATE ((NMDeviceMacvlan *) device); NMSettingWired *s_wired; + NMDevice *parent_device; const char *setting_mac; const char *parent_mac; @@ -366,10 +341,11 @@ match_hwaddr (NMDevice *device, NMConnection *connection, gboolean fail_if_no_hw if (!setting_mac) return !fail_if_no_hwaddr; - if (!priv->parent) + parent_device = nm_device_parent_get_device (device); + if (!parent_device) return !fail_if_no_hwaddr; - parent_mac = nm_device_get_permanent_hw_address (priv->parent); + parent_mac = nm_device_get_permanent_hw_address (parent_device); return parent_mac && nm_utils_hwaddr_matches (setting_mac, -1, parent_mac, -1); } @@ -457,6 +433,7 @@ update_connection (NMDevice *device, NMConnection *connection) { NMDeviceMacvlanPrivate *priv = NM_DEVICE_MACVLAN_GET_PRIVATE ((NMDeviceMacvlan *) device); NMSettingMacvlan *s_macvlan = nm_connection_get_setting_macvlan (connection); + NMDevice *parent_device; const char *setting_parent, *new_parent; int new_mode; @@ -477,15 +454,16 @@ update_connection (NMDevice *device, NMConnection *connection) g_object_set (s_macvlan, NM_SETTING_MACVLAN_TAP, !!priv->props.tap, NULL); /* Update parent in the connection; default to parent's interface name */ - if (priv->parent) { - new_parent = nm_device_get_iface (priv->parent); + parent_device = nm_device_parent_get_device (device); + if (parent_device) { + new_parent = nm_device_get_iface (parent_device); setting_parent = nm_setting_macvlan_get_parent (s_macvlan); if (setting_parent && nm_utils_is_uuid (setting_parent)) { NMConnection *parent_connection; /* Don't change a parent specified by UUID if it's still valid */ parent_connection = (NMConnection *) nm_settings_get_connection_by_uuid (nm_device_get_settings (device), setting_parent); - if (parent_connection && nm_device_check_connection_compatible (priv->parent, parent_connection)) + if (parent_connection && nm_device_check_connection_compatible (parent_device, parent_connection)) new_parent = NULL; } if (new_parent) @@ -529,14 +507,6 @@ ip4_config_pre_commit (NMDevice *device, NMIP4Config *config) } } -static void -realize_start_notify (NMDevice *device, const NMPlatformLink *plink) -{ - NM_DEVICE_CLASS (nm_device_macvlan_parent_class)->realize_start_notify (device, plink); - - update_properties (device); -} - /*****************************************************************************/ static void @@ -544,16 +514,8 @@ get_property (GObject *object, guint prop_id, GValue *value, GParamSpec *pspec) { NMDeviceMacvlanPrivate *priv = NM_DEVICE_MACVLAN_GET_PRIVATE ((NMDeviceMacvlan *) object); - NMDevice *parent; switch (prop_id) { - case PROP_PARENT: - if (priv->parent_ifindex > 0) - parent = nm_manager_get_device_by_ifindex (nm_manager_get (), priv->parent_ifindex); - else - parent = NULL; - nm_utils_g_value_set_object_path (value, parent); - break; case PROP_MODE: g_value_set_string (value, platform_mode_to_string (priv->props.mode)); break; @@ -592,14 +554,6 @@ nm_device_macvlan_init (NMDeviceMacvlan *self) } static void -dispose (GObject *object) -{ - nm_device_macvlan_set_parent (NM_DEVICE_MACVLAN (object), NULL); - - G_OBJECT_CLASS (nm_device_macvlan_parent_class)->dispose (object); -} - -static void nm_device_macvlan_class_init (NMDeviceMacvlanClass *klass) { GObjectClass *object_class = G_OBJECT_CLASS (klass); @@ -607,7 +561,6 @@ nm_device_macvlan_class_init (NMDeviceMacvlanClass *klass) NM_DEVICE_CLASS_DECLARE_TYPES (klass, NULL, NM_LINK_TYPE_MACVLAN, NM_LINK_TYPE_MACVTAP) - object_class->dispose = dispose; object_class->get_property = get_property; object_class->set_property = set_property; @@ -620,16 +573,9 @@ nm_device_macvlan_class_init (NMDeviceMacvlanClass *klass) device_class->ip4_config_pre_commit = ip4_config_pre_commit; device_class->is_available = is_available; device_class->link_changed = link_changed; - device_class->notify_new_device_added = notify_new_device_added; - device_class->realize_start_notify = realize_start_notify; + device_class->parent_changed_notify = parent_changed_notify; device_class->update_connection = update_connection; - obj_properties[PROP_PARENT] = - g_param_spec_string (NM_DEVICE_MACVLAN_PARENT, "", "", - NULL, - G_PARAM_READABLE | - G_PARAM_STATIC_STRINGS); - obj_properties[PROP_MODE] = g_param_spec_string (NM_DEVICE_MACVLAN_MODE, "", "", NULL, diff --git a/src/devices/nm-device-macvlan.h b/src/devices/nm-device-macvlan.h index 13dac7d792..e6d3a33321 100644 --- a/src/devices/nm-device-macvlan.h +++ b/src/devices/nm-device-macvlan.h @@ -30,11 +30,13 @@ #define NM_IS_DEVICE_MACVLAN_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), NM_TYPE_DEVICE_MACVLAN)) #define NM_DEVICE_MACVLAN_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), NM_TYPE_DEVICE_MACVLAN, NMDeviceMacvlanClass)) -#define NM_DEVICE_MACVLAN_PARENT "parent" #define NM_DEVICE_MACVLAN_MODE "mode" #define NM_DEVICE_MACVLAN_NO_PROMISC "no-promisc" #define NM_DEVICE_MACVLAN_TAP "tap" +/* defined in the parent class, but exposed on D-Bus by the subclass. */ +#define NM_DEVICE_MACVLAN_PARENT NM_DEVICE_PARENT + typedef struct _NMDeviceMacvlan NMDeviceMacvlan; typedef struct _NMDeviceMacvlanClass NMDeviceMacvlanClass; diff --git a/src/devices/nm-device-tun.c b/src/devices/nm-device-tun.c index ea70f1a539..bb66c50f80 100644 --- a/src/devices/nm-device-tun.c +++ b/src/devices/nm-device-tun.c @@ -71,7 +71,7 @@ G_DEFINE_TYPE (NMDeviceTun, nm_device_tun, NM_TYPE_DEVICE) /*****************************************************************************/ static void -reload_tun_properties (NMDeviceTun *self) +update_properties (NMDeviceTun *self) { NMDeviceTunPrivate *priv = NM_DEVICE_TUN_GET_PRIVATE (self); GObject *object = G_OBJECT (self); @@ -122,11 +122,11 @@ get_generic_capabilities (NMDevice *dev) } static void -link_changed (NMDevice *device, NMPlatformLink *info) +link_changed (NMDevice *device, + const NMPlatformLink *pllink) { - NM_DEVICE_CLASS (nm_device_tun_parent_class)->link_changed (device, info); - - reload_tun_properties (NM_DEVICE_TUN (device)); + NM_DEVICE_CLASS (nm_device_tun_parent_class)->link_changed (device, pllink); + update_properties (NM_DEVICE_TUN (device)); } static gboolean @@ -251,13 +251,6 @@ create_and_realize (NMDevice *device, return TRUE; } -static void -realize_start_notify (NMDevice *device, const NMPlatformLink *plink) -{ - NM_DEVICE_CLASS (nm_device_tun_parent_class)->realize_start_notify (device, plink); - reload_tun_properties ((NMDeviceTun *) device); -} - static gboolean check_connection_compatible (NMDevice *device, NMConnection *connection) { @@ -438,7 +431,6 @@ nm_device_tun_class_init (NMDeviceTunClass *klass) device_class->check_connection_compatible = check_connection_compatible; device_class->create_and_realize = create_and_realize; device_class->get_generic_capabilities = get_generic_capabilities; - device_class->realize_start_notify = realize_start_notify; device_class->unrealize_notify = unrealize_notify; device_class->update_connection = update_connection; device_class->act_stage1_prepare = act_stage1_prepare; diff --git a/src/devices/nm-device-veth.c b/src/devices/nm-device-veth.c index a2fae62a32..a5a87a2ddd 100644 --- a/src/devices/nm-device-veth.c +++ b/src/devices/nm-device-veth.c @@ -23,9 +23,6 @@ #include <errno.h> #include <stdlib.h> #include <string.h> -#include <unistd.h> -#include <linux/sockios.h> -#include <sys/ioctl.h> #include "nm-device-veth.h" #include "nm-device-private.h" @@ -41,8 +38,6 @@ _LOG_DECLARE_SELF(NMDeviceVeth); /*****************************************************************************/ typedef struct { - NMDevice *peer; - gboolean ever_had_peer; } NMDeviceVethPrivate; struct _NMDeviceVeth { @@ -67,42 +62,23 @@ G_DEFINE_TYPE (NMDeviceVeth, nm_device_veth, NM_TYPE_DEVICE_ETHERNET) /*****************************************************************************/ static void -set_peer (NMDeviceVeth *self, NMDevice *peer) +update_properties (NMDevice *device) { - NMDeviceVethPrivate *priv = NM_DEVICE_VETH_GET_PRIVATE (self); - - if (!priv->peer) { - priv->ever_had_peer = TRUE; - priv->peer = peer; - g_object_add_weak_pointer (G_OBJECT (peer), (gpointer *) &priv->peer); - - _notify (self, PROP_PEER); - } -} + NMDevice *peer; + int ifindex, peer_ifindex; -static NMDevice * -get_peer (NMDeviceVeth *self) -{ - NMDeviceVethPrivate *priv = NM_DEVICE_VETH_GET_PRIVATE (self); - NMDevice *device = NM_DEVICE (self), *peer = NULL; - int peer_ifindex; + ifindex = nm_device_get_ifindex (device); - if (priv->ever_had_peer) - return priv->peer; + if (!nm_platform_link_veth_get_properties (NM_PLATFORM_GET, ifindex, &peer_ifindex)) + peer_ifindex = 0; - if (!nm_platform_link_veth_get_properties (NM_PLATFORM_GET, nm_device_get_ifindex (device), &peer_ifindex)) { - _LOGW (LOGD_PLATFORM, "could not read veth properties"); - return NULL; - } + nm_device_parent_set_ifindex (device, peer_ifindex); - if (peer_ifindex > 0) - peer = nm_manager_get_device_by_ifindex (nm_manager_get (), peer_ifindex); - if (peer && NM_IS_DEVICE_VETH (peer)) { - set_peer (self, peer); - set_peer (NM_DEVICE_VETH (peer), device); - } - - return priv->peer; + peer = nm_device_parent_get_device (device); + if ( peer + && NM_IS_DEVICE_VETH (peer) + && nm_device_parent_get_ifindex (peer) <= 0) + update_properties (peer); } static gboolean @@ -115,6 +91,14 @@ can_unmanaged_external_down (NMDevice *self) return FALSE; } +static void +link_changed (NMDevice *device, + const NMPlatformLink *pllink) +{ + NM_DEVICE_CLASS (nm_device_veth_parent_class)->link_changed (device, pllink); + update_properties (device); +} + /*****************************************************************************/ static void @@ -123,17 +107,10 @@ nm_device_veth_init (NMDeviceVeth *self) } static void -dispose (GObject *object) +notify (GObject *object, GParamSpec *pspec) { - NMDeviceVeth *self = NM_DEVICE_VETH (object); - NMDeviceVethPrivate *priv = NM_DEVICE_VETH_GET_PRIVATE (self); - - if (priv->peer) { - g_object_remove_weak_pointer (G_OBJECT (priv->peer), (gpointer *) &priv->peer); - priv->peer = NULL; - } - - G_OBJECT_CLASS (nm_device_veth_parent_class)->dispose (object); + if (nm_streq (pspec->name, NM_DEVICE_PARENT)) + _notify (NM_DEVICE_VETH (object), PROP_PEER); } static void @@ -145,7 +122,9 @@ get_property (GObject *object, guint prop_id, switch (prop_id) { case PROP_PEER: - peer = get_peer (self); + peer = nm_device_parent_get_device (NM_DEVICE (self)); + if (peer && !NM_IS_DEVICE_VETH (peer)) + peer = NULL; nm_utils_g_value_set_object_path (value, peer); break; default: @@ -163,9 +142,10 @@ nm_device_veth_class_init (NMDeviceVethClass *klass) NM_DEVICE_CLASS_DECLARE_TYPES (klass, NULL, NM_LINK_TYPE_VETH) object_class->get_property = get_property; - object_class->dispose = dispose; + object_class->notify = notify; device_class->can_unmanaged_external_down = can_unmanaged_external_down; + device_class->link_changed = link_changed; obj_properties[PROP_PEER] = g_param_spec_string (NM_DEVICE_VETH_PEER, "", "", diff --git a/src/devices/nm-device-vlan.c b/src/devices/nm-device-vlan.c index 2e2d74b6d6..d07e831850 100644 --- a/src/devices/nm-device-vlan.c +++ b/src/devices/nm-device-vlan.c @@ -45,12 +45,10 @@ _LOG_DECLARE_SELF(NMDeviceVlan); /*****************************************************************************/ NM_GOBJECT_PROPERTIES_DEFINE (NMDeviceVlan, - PROP_PARENT, PROP_VLAN_ID, ); typedef struct { - NMDevice *parent; gulong parent_state_id; gulong parent_hwaddr_id; guint vlan_id; @@ -128,41 +126,46 @@ parent_hwaddr_maybe_changed (NMDevice *parent, } static void -nm_device_vlan_set_parent (NMDeviceVlan *self, NMDevice *parent) +parent_changed_notify (NMDevice *device, + int old_ifindex, + NMDevice *old_parent, + int new_ifindex, + NMDevice *new_parent) { + NMDeviceVlan *self = NM_DEVICE_VLAN (device); NMDeviceVlanPrivate *priv = NM_DEVICE_VLAN_GET_PRIVATE (self); - NMDevice *device = NM_DEVICE (self); - if (parent == priv->parent) - return; + NM_DEVICE_CLASS (nm_device_vlan_parent_class)->parent_changed_notify (device, old_ifindex, old_parent, new_ifindex, new_parent); - nm_clear_g_signal_handler (priv->parent, &priv->parent_state_id); - nm_clear_g_signal_handler (priv->parent, &priv->parent_hwaddr_id); - g_clear_object (&priv->parent); + /* note that @self doesn't have to clear @parent_state_id on dispose, + * because NMDevice's dispose() will unset the parent, which in turn calls + * parent_changed_notify(). */ + nm_clear_g_signal_handler (old_parent, &priv->parent_state_id); + nm_clear_g_signal_handler (old_parent, &priv->parent_hwaddr_id); - if (parent) { - priv->parent = g_object_ref (parent); - priv->parent_state_id = g_signal_connect (priv->parent, + if (new_parent) { + priv->parent_state_id = g_signal_connect (new_parent, NM_DEVICE_STATE_CHANGED, G_CALLBACK (parent_state_changed), device); - priv->parent_hwaddr_id = g_signal_connect (priv->parent, "notify::" NM_DEVICE_HW_ADDRESS, + priv->parent_hwaddr_id = g_signal_connect (new_parent, "notify::" NM_DEVICE_HW_ADDRESS, G_CALLBACK (parent_hwaddr_maybe_changed), device); - parent_hwaddr_maybe_changed (parent, NULL, self); + parent_hwaddr_maybe_changed (new_parent, NULL, self); /* Set parent-dependent unmanaged flag */ nm_device_set_unmanaged_by_flags (device, NM_UNMANAGED_PARENT, - !nm_device_get_managed (parent, FALSE), + !nm_device_get_managed (new_parent, FALSE), NM_DEVICE_STATE_REASON_PARENT_MANAGED_CHANGED); } /* Recheck availability now that the parent has changed */ - nm_device_queue_recheck_available (device, - NM_DEVICE_STATE_REASON_PARENT_CHANGED, - NM_DEVICE_STATE_REASON_PARENT_CHANGED); - _notify (self, PROP_PARENT); + if (new_ifindex > 0) { + nm_device_queue_recheck_available (device, + NM_DEVICE_STATE_REASON_PARENT_CHANGED, + NM_DEVICE_STATE_REASON_PARENT_CHANGED); + } } static void @@ -171,8 +174,8 @@ update_properties (NMDevice *device) NMDeviceVlanPrivate *priv; const NMPlatformLink *plink = NULL; const NMPlatformLnkVlan *plnk = NULL; - NMDevice *parent = NULL; int ifindex; + int parent_ifindex = 0; guint vlan_id; g_return_if_fail (NM_IS_DEVICE_VLAN (device)); @@ -183,14 +186,14 @@ update_properties (NMDevice *device) if (ifindex > 0) plnk = nm_platform_link_get_lnk_vlan (NM_PLATFORM_GET, ifindex, &plink); + if ( plnk - && plink->parent - && plink->parent != NM_PLATFORM_LINK_OTHER_NETNS) - parent = nm_manager_get_device_by_ifindex (nm_manager_get (), plink->parent); + && plink->parent > 0) + parent_ifindex = plink->parent; g_object_freeze_notify ((GObject *) device); - nm_device_vlan_set_parent ((NMDeviceVlan *) device, parent); + nm_device_parent_set_ifindex (device, parent_ifindex); vlan_id = plnk ? plnk->id : 0; if (vlan_id != priv->vlan_id) { @@ -202,10 +205,10 @@ update_properties (NMDevice *device) } static void -realize_start_notify (NMDevice *device, const NMPlatformLink *plink) +link_changed (NMDevice *device, + const NMPlatformLink *pllink) { - NM_DEVICE_CLASS (nm_device_vlan_parent_class)->realize_start_notify (device, plink); - + NM_DEVICE_CLASS (nm_device_vlan_parent_class)->link_changed (device, pllink); update_properties (device); } @@ -260,8 +263,7 @@ create_and_realize (NMDevice *device, return FALSE; } - g_warn_if_fail (priv->parent == NULL); - nm_device_vlan_set_parent (NM_DEVICE_VLAN (device), parent); + nm_device_parent_set_ifindex (device, parent_ifindex); if (vlan_id != priv->vlan_id) { priv->vlan_id = vlan_id; _notify ((NMDeviceVlan *) device, PROP_VLAN_ID); @@ -273,17 +275,21 @@ create_and_realize (NMDevice *device, static void unrealize_notify (NMDevice *device) { + NMDeviceVlan *self = NM_DEVICE_VLAN (device); + NMDeviceVlanPrivate *priv = NM_DEVICE_VLAN_GET_PRIVATE (self); + NM_DEVICE_CLASS (nm_device_vlan_parent_class)->unrealize_notify (device); - NM_DEVICE_VLAN_GET_PRIVATE ((NMDeviceVlan *) device)->vlan_id = 0; - _notify ((NMDeviceVlan *) device, PROP_VLAN_ID); - nm_device_vlan_set_parent (NM_DEVICE_VLAN (device), NULL); + if (priv->vlan_id != 0) { + priv->vlan_id = 0; + _notify (self, PROP_VLAN_ID); + } } /*****************************************************************************/ static NMDeviceCapabilities -get_generic_capabilities (NMDevice *dev) +get_generic_capabilities (NMDevice *device) { /* We assume VLAN interfaces always support carrier detect */ return NM_DEVICE_CAP_CARRIER_DETECT | NM_DEVICE_CAP_IS_SOFTWARE; @@ -294,47 +300,22 @@ get_generic_capabilities (NMDevice *dev) static gboolean is_available (NMDevice *device, NMDeviceCheckDevAvailableFlags flags) { - if (!NM_DEVICE_VLAN_GET_PRIVATE ((NMDeviceVlan *) device)->parent) + if (!nm_device_parent_get_device (device)) return FALSE; - return NM_DEVICE_CLASS (nm_device_vlan_parent_class)->is_available (device, flags); } -static void -notify_new_device_added (NMDevice *device, NMDevice *new_device) -{ - NMDeviceVlan *self = NM_DEVICE_VLAN (device); - NMDeviceVlanPrivate *priv = NM_DEVICE_VLAN_GET_PRIVATE (self); - const NMPlatformLink *plink; - const NMPlatformLnkVlan *plnk; - - if (priv->parent) - return; - - if (!nm_device_is_real (device)) - return; - - plnk = nm_platform_link_get_lnk_vlan (NM_PLATFORM_GET, nm_device_get_ifindex (device), &plink); - if (!plnk) - return; - - if ( plink->parent <= 0 - || nm_device_get_ifindex (new_device) != plink->parent) - return; - - nm_device_vlan_set_parent (self, new_device); -} - /*****************************************************************************/ static gboolean match_parent (NMDeviceVlan *self, const char *parent) { - NMDeviceVlanPrivate *priv = NM_DEVICE_VLAN_GET_PRIVATE (self); + NMDevice *parent_device; g_return_val_if_fail (parent != NULL, FALSE); - if (!priv->parent) + parent_device = nm_device_parent_get_device (NM_DEVICE (self)); + if (!parent_device) return FALSE; if (nm_utils_is_uuid (parent)) { @@ -345,7 +326,7 @@ match_parent (NMDeviceVlan *self, const char *parent) * device has that connection activated. */ - parent_req = nm_device_get_act_request (priv->parent); + parent_req = nm_device_get_act_request (parent_device); if (!parent_req) return FALSE; @@ -357,7 +338,7 @@ match_parent (NMDeviceVlan *self, const char *parent) return FALSE; } else { /* interface name */ - if (g_strcmp0 (parent, nm_device_get_ip_iface (priv->parent)) != 0) + if (g_strcmp0 (parent, nm_device_get_ip_iface (parent_device)) != 0) return FALSE; } @@ -367,8 +348,8 @@ match_parent (NMDeviceVlan *self, const char *parent) static gboolean match_hwaddr (NMDevice *device, NMConnection *connection, gboolean fail_if_no_hwaddr) { - NMDeviceVlanPrivate *priv; NMSettingWired *s_wired; + NMDevice *parent_device; const char *setting_mac; const char *parent_mac; @@ -380,11 +361,11 @@ match_hwaddr (NMDevice *device, NMConnection *connection, gboolean fail_if_no_hw if (!setting_mac) return !fail_if_no_hwaddr; - priv = NM_DEVICE_VLAN_GET_PRIVATE ((NMDeviceVlan *) device); - if (!priv->parent) + parent_device = nm_device_parent_get_device (device); + if (!parent_device) return !fail_if_no_hwaddr; - parent_mac = nm_device_get_permanent_hw_address (priv->parent); + parent_mac = nm_device_get_permanent_hw_address (parent_device); return parent_mac && nm_utils_hwaddr_matches (setting_mac, -1, parent_mac, -1); } @@ -481,6 +462,7 @@ update_connection (NMDevice *device, NMConnection *connection) const char *setting_parent, *new_parent; const NMPlatformLink *plink; const NMPObject *polnk; + NMDevice *parent_device; guint vlan_id; guint vlan_flags; @@ -499,18 +481,19 @@ update_connection (NMDevice *device, NMConnection *connection) g_object_set (s_vlan, NM_SETTING_VLAN_ID, vlan_id, NULL); /* Update parent in the connection; default to parent's interface name */ - if ( priv->parent + parent_device = nm_device_parent_get_device (device); + if ( parent_device && polnk && plink->parent > 0 - && nm_device_get_ifindex (priv->parent) == plink->parent) { - new_parent = nm_device_get_iface (priv->parent); + && nm_device_get_ifindex (parent_device) == plink->parent) { + new_parent = nm_device_get_iface (parent_device); setting_parent = nm_setting_vlan_get_parent (s_vlan); if (setting_parent && nm_utils_is_uuid (setting_parent)) { NMConnection *parent_connection; /* Don't change a parent specified by UUID if it's still valid */ parent_connection = (NMConnection *) nm_settings_get_connection_by_uuid (nm_device_get_settings (device), setting_parent); - if (parent_connection && nm_device_check_connection_compatible (priv->parent, parent_connection)) + if (parent_connection && nm_device_check_connection_compatible (parent_device, parent_connection)) new_parent = NULL; } if (new_parent) @@ -539,26 +522,27 @@ update_connection (NMDevice *device, NMConnection *connection) } static NMActStageReturn -act_stage1_prepare (NMDevice *dev, NMDeviceStateReason *reason) +act_stage1_prepare (NMDevice *device, NMDeviceStateReason *reason) { - NMDeviceVlanPrivate *priv = NM_DEVICE_VLAN_GET_PRIVATE ((NMDeviceVlan *) dev); + NMDevice *parent_device; NMSettingVlan *s_vlan; NMActStageReturn ret; g_return_val_if_fail (reason != NULL, NM_ACT_STAGE_RETURN_FAILURE); - ret = NM_DEVICE_CLASS (nm_device_vlan_parent_class)->act_stage1_prepare (dev, reason); + ret = NM_DEVICE_CLASS (nm_device_vlan_parent_class)->act_stage1_prepare (device, reason); if (ret != NM_ACT_STAGE_RETURN_SUCCESS) return ret; - if (!nm_device_hw_addr_set_cloned (dev, nm_device_get_applied_connection (dev), FALSE)) + if (!nm_device_hw_addr_set_cloned (device, nm_device_get_applied_connection (device), FALSE)) return NM_ACT_STAGE_RETURN_FAILURE; /* Change MAC address to parent's one if needed */ - if (priv->parent) - parent_hwaddr_maybe_changed (priv->parent, NULL, dev); + parent_device = nm_device_parent_get_device (device); + if (parent_device) + parent_hwaddr_maybe_changed (parent_device, NULL, device); - s_vlan = (NMSettingVlan *) nm_device_get_applied_setting (dev, NM_TYPE_SETTING_VLAN); + s_vlan = (NMSettingVlan *) nm_device_get_applied_setting (device, NM_TYPE_SETTING_VLAN); if (s_vlan) { gs_free NMVlanQosMapping *ingress_map = NULL; gs_free NMVlanQosMapping *egress_map = NULL; @@ -574,7 +558,7 @@ act_stage1_prepare (NMDevice *dev, NMDeviceStateReason *reason) &n_egress_map); nm_platform_link_vlan_change (NM_PLATFORM_GET, - nm_device_get_ifindex (dev), + nm_device_get_ifindex (device), NM_VLAN_FLAGS_ALL, nm_setting_vlan_get_flags (s_vlan), TRUE, @@ -615,9 +599,6 @@ get_property (GObject *object, guint prop_id, NMDeviceVlanPrivate *priv = NM_DEVICE_VLAN_GET_PRIVATE ((NMDeviceVlan *) object); switch (prop_id) { - case PROP_PARENT: - nm_utils_g_value_set_object_path (value, priv->parent); - break; case PROP_VLAN_ID: g_value_set_uint (value, priv->vlan_id); break; @@ -635,14 +616,6 @@ nm_device_vlan_init (NMDeviceVlan * self) } static void -dispose (GObject *object) -{ - nm_device_vlan_set_parent (NM_DEVICE_VLAN (object), NULL); - - G_OBJECT_CLASS (nm_device_vlan_parent_class)->dispose (object); -} - -static void nm_device_vlan_class_init (NMDeviceVlanClass *klass) { GObjectClass *object_class = G_OBJECT_CLASS (klass); @@ -651,27 +624,21 @@ nm_device_vlan_class_init (NMDeviceVlanClass *klass) NM_DEVICE_CLASS_DECLARE_TYPES (klass, NM_SETTING_VLAN_SETTING_NAME, NM_LINK_TYPE_VLAN) object_class->get_property = get_property; - object_class->dispose = dispose; parent_class->create_and_realize = create_and_realize; - parent_class->realize_start_notify = realize_start_notify; + parent_class->link_changed = link_changed; parent_class->unrealize_notify = unrealize_notify; parent_class->get_generic_capabilities = get_generic_capabilities; parent_class->act_stage1_prepare = act_stage1_prepare; parent_class->ip4_config_pre_commit = ip4_config_pre_commit; parent_class->is_available = is_available; - parent_class->notify_new_device_added = notify_new_device_added; + parent_class->parent_changed_notify = parent_changed_notify; parent_class->check_connection_compatible = check_connection_compatible; parent_class->check_connection_available = check_connection_available; parent_class->complete_connection = complete_connection; parent_class->update_connection = update_connection; - obj_properties[PROP_PARENT] = - g_param_spec_string (NM_DEVICE_VLAN_PARENT, "", "", - NULL, - G_PARAM_READABLE | - G_PARAM_STATIC_STRINGS); obj_properties[PROP_VLAN_ID] = g_param_spec_uint (NM_DEVICE_VLAN_ID, "", "", 0, 4095, 0, diff --git a/src/devices/nm-device-vlan.h b/src/devices/nm-device-vlan.h index f587f4f60b..0d788940ee 100644 --- a/src/devices/nm-device-vlan.h +++ b/src/devices/nm-device-vlan.h @@ -37,9 +37,11 @@ typedef enum { } NMVlanError; /* D-Bus exported properties */ -#define NM_DEVICE_VLAN_PARENT "parent" #define NM_DEVICE_VLAN_ID "vlan-id" +/* defined in the parent class, but exposed on D-Bus by the subclass. */ +#define NM_DEVICE_VLAN_PARENT NM_DEVICE_PARENT + typedef struct _NMDeviceVlan NMDeviceVlan; typedef struct _NMDeviceVlanClass NMDeviceVlanClass; diff --git a/src/devices/nm-device-vxlan.c b/src/devices/nm-device-vxlan.c index cd95a876be..63961ae5a6 100644 --- a/src/devices/nm-device-vxlan.c +++ b/src/devices/nm-device-vxlan.c @@ -43,7 +43,6 @@ _LOG_DECLARE_SELF(NMDeviceVxlan); /*****************************************************************************/ NM_GOBJECT_PROPERTIES_DEFINE (NMDeviceVxlan, - PROP_PARENT, PROP_ID, PROP_LOCAL, PROP_GROUP, @@ -62,7 +61,6 @@ NM_GOBJECT_PROPERTIES_DEFINE (NMDeviceVxlan, ); typedef struct { - NMDevice *parent; NMPlatformLnkVxlan props; } NMDeviceVxlanPrivate; @@ -88,7 +86,6 @@ update_properties (NMDevice *device) NMDeviceVxlanPrivate *priv = NM_DEVICE_VXLAN_GET_PRIVATE (self); GObject *object = G_OBJECT (device); const NMPlatformLnkVxlan *props; - NMDevice *parent; props = nm_platform_link_get_lnk_vxlan (NM_PLATFORM_GET, nm_device_get_ifindex (device), NULL); if (!props) { @@ -98,13 +95,8 @@ update_properties (NMDevice *device) g_object_freeze_notify (object); - if (priv->props.parent_ifindex != props->parent_ifindex) { - g_clear_object (&priv->parent); - parent = nm_manager_get_device_by_ifindex (nm_manager_get (), props->parent_ifindex); - if (parent) - priv->parent = g_object_ref (parent); - _notify (self, PROP_PARENT); - } + if (priv->props.parent_ifindex != props->parent_ifindex) + nm_device_parent_set_ifindex (device, props->parent_ifindex); if (priv->props.id != props->id) _notify (self, PROP_ID); if (priv->props.local != props->local) @@ -152,19 +144,10 @@ get_generic_capabilities (NMDevice *dev) } static void -link_changed (NMDevice *device, NMPlatformLink *info) +link_changed (NMDevice *device, + const NMPlatformLink *pllink) { - NM_DEVICE_CLASS (nm_device_vxlan_parent_class)->link_changed (device, info); - update_properties (device); -} - -static void -realize_start_notify (NMDevice *device, const NMPlatformLink *plink) -{ - g_assert (plink->type == NM_LINK_TYPE_VXLAN); - - NM_DEVICE_CLASS (nm_device_vxlan_parent_class)->realize_start_notify (device, plink); - + NM_DEVICE_CLASS (nm_device_vxlan_parent_class)->link_changed (device, pllink); update_properties (device); } @@ -250,11 +233,12 @@ create_and_realize (NMDevice *device, static gboolean match_parent (NMDeviceVxlan *self, const char *parent) { - NMDeviceVxlanPrivate *priv = NM_DEVICE_VXLAN_GET_PRIVATE (self); + NMDevice *parent_device; g_return_val_if_fail (parent != NULL, FALSE); - if (!priv->parent) + parent_device = nm_device_parent_get_device (NM_DEVICE (self)); + if (!parent_device) return FALSE; if (nm_utils_is_uuid (parent)) { @@ -264,7 +248,7 @@ match_parent (NMDeviceVxlan *self, const char *parent) /* If the parent is a UUID, the connection matches if our parent * device has that connection activated. */ - parent_req = nm_device_get_act_request (priv->parent); + parent_req = nm_device_get_act_request (parent_device); if (!parent_req) return FALSE; @@ -276,7 +260,7 @@ match_parent (NMDeviceVxlan *self, const char *parent) return FALSE; } else { /* interface name */ - if (g_strcmp0 (parent, nm_device_get_ip_iface (priv->parent)) != 0) + if (g_strcmp0 (parent, nm_device_get_ip_iface (parent_device)) != 0) return FALSE; } @@ -401,8 +385,9 @@ update_connection (NMDevice *device, NMConnection *connection) { NMDeviceVxlanPrivate *priv = NM_DEVICE_VXLAN_GET_PRIVATE ((NMDeviceVxlan *) device); NMSettingVxlan *s_vxlan = nm_connection_get_setting_vxlan (connection); - NMDevice *parent = NULL; - const char *setting_parent, *new_parent; + NMDevice *parent_device; + const char *setting_parent; + const char *new_parent = NULL; if (!s_vxlan) { s_vxlan = (NMSettingVxlan *) nm_setting_vxlan_new (); @@ -412,12 +397,11 @@ update_connection (NMDevice *device, NMConnection *connection) if (priv->props.id != nm_setting_vxlan_get_id (s_vxlan)) g_object_set (G_OBJECT (s_vxlan), NM_SETTING_VXLAN_ID, priv->props.id, NULL); - if (priv->props.parent_ifindex != NM_PLATFORM_LINK_OTHER_NETNS) - parent = nm_manager_get_device_by_ifindex (nm_manager_get (), priv->props.parent_ifindex); + parent_device = nm_device_parent_get_device (device); /* Update parent in the connection; default to parent's interface name */ - if (parent) { - new_parent = nm_device_get_iface (parent); + if (parent_device) { + new_parent = nm_device_get_iface (parent_device); setting_parent = nm_setting_vxlan_get_parent (s_vxlan); if (setting_parent && nm_utils_is_uuid (setting_parent)) { NMConnection *parent_connection; @@ -425,13 +409,11 @@ update_connection (NMDevice *device, NMConnection *connection) /* Don't change a parent specified by UUID if it's still valid */ parent_connection = (NMConnection *) nm_settings_get_connection_by_uuid (nm_device_get_settings (device), setting_parent); - if (parent_connection && nm_device_check_connection_compatible (parent, parent_connection)) + if (parent_connection && nm_device_check_connection_compatible (parent_device, parent_connection)) new_parent = NULL; } - if (new_parent) - g_object_set (s_vxlan, NM_SETTING_VXLAN_PARENT, new_parent, NULL); - } else - g_object_set (s_vxlan, NM_SETTING_VXLAN_PARENT, NULL, NULL); + } + g_object_set (s_vxlan, NM_SETTING_VXLAN_PARENT, new_parent, NULL); if (!address_matches (nm_setting_vxlan_get_remote (s_vxlan), priv->props.group, &priv->props.group6)) { if (priv->props.group) { @@ -555,13 +537,8 @@ get_property (GObject *object, guint prop_id, GValue *value, GParamSpec *pspec) { NMDeviceVxlanPrivate *priv = NM_DEVICE_VXLAN_GET_PRIVATE ((NMDeviceVxlan *) object); - NMDevice *parent; switch (prop_id) { - case PROP_PARENT: - parent = nm_manager_get_device_by_ifindex (nm_manager_get (), priv->props.parent_ifindex); - nm_utils_g_value_set_object_path (value, parent); - break; case PROP_ID: g_value_set_uint (value, priv->props.id); break; @@ -627,15 +604,6 @@ nm_device_vxlan_init (NMDeviceVxlan *self) } static void -dispose (GObject *object) -{ - NMDeviceVxlanPrivate *priv = NM_DEVICE_VXLAN_GET_PRIVATE ((NMDeviceVxlan *) object); - - g_clear_object (&priv->parent); - G_OBJECT_CLASS (nm_device_vxlan_parent_class)->dispose (object); -} - -static void nm_device_vxlan_class_init (NMDeviceVxlanClass *klass) { GObjectClass *object_class = G_OBJECT_CLASS (klass); @@ -644,10 +612,8 @@ nm_device_vxlan_class_init (NMDeviceVxlanClass *klass) NM_DEVICE_CLASS_DECLARE_TYPES (klass, NULL, NM_LINK_TYPE_VXLAN) object_class->get_property = get_property; - object_class->dispose = dispose; device_class->link_changed = link_changed; - device_class->realize_start_notify = realize_start_notify; device_class->unrealize_notify = unrealize_notify; device_class->connection_type = NM_SETTING_VXLAN_SETTING_NAME; device_class->create_and_realize = create_and_realize; @@ -658,12 +624,6 @@ nm_device_vxlan_class_init (NMDeviceVxlanClass *klass) device_class->act_stage1_prepare = act_stage1_prepare; device_class->ip4_config_pre_commit = ip4_config_pre_commit; - obj_properties[PROP_PARENT] = - g_param_spec_string (NM_DEVICE_VXLAN_PARENT, "", "", - NULL, - G_PARAM_READABLE | - G_PARAM_STATIC_STRINGS); - obj_properties[PROP_ID] = g_param_spec_uint (NM_DEVICE_VXLAN_ID, "", "", 0, G_MAXUINT32, 0, diff --git a/src/devices/nm-device-vxlan.h b/src/devices/nm-device-vxlan.h index 82e5c604e9..6f0102dc04 100644 --- a/src/devices/nm-device-vxlan.h +++ b/src/devices/nm-device-vxlan.h @@ -30,7 +30,6 @@ #define NM_IS_DEVICE_VXLAN_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), NM_TYPE_DEVICE_VXLAN)) #define NM_DEVICE_VXLAN_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), NM_TYPE_DEVICE_VXLAN, NMDeviceVxlanClass)) -#define NM_DEVICE_VXLAN_PARENT "parent" #define NM_DEVICE_VXLAN_ID "id" #define NM_DEVICE_VXLAN_GROUP "group" #define NM_DEVICE_VXLAN_LOCAL "local" @@ -47,6 +46,9 @@ #define NM_DEVICE_VXLAN_L2MISS "l2miss" #define NM_DEVICE_VXLAN_L3MISS "l3miss" +/* defined in the parent class, but exposed on D-Bus by the subclass. */ +#define NM_DEVICE_VXLAN_PARENT NM_DEVICE_PARENT + typedef struct _NMDeviceVxlan NMDeviceVxlan; typedef struct _NMDeviceVxlanClass NMDeviceVxlanClass; diff --git a/src/devices/nm-device.c b/src/devices/nm-device.c index c980133466..b6b464caa9 100644 --- a/src/devices/nm-device.c +++ b/src/devices/nm-device.c @@ -123,6 +123,7 @@ NM_GOBJECT_PROPERTIES_DEFINE (NMDevice, PROP_PHYSICAL_PORT_ID, PROP_IS_MASTER, PROP_MASTER, + PROP_PARENT, PROP_HW_ADDRESS, PROP_PERM_HW_ADDRESS, PROP_HAS_PENDING_ACTION, @@ -225,10 +226,14 @@ typedef struct _NMDevicePrivate { GSList *pending_actions; GSList *dad6_failed_addrs; + NMDevice *parent_device; + char * udi; char * iface; /* may change, could be renamed by user */ int ifindex; + int parent_ifindex; + union { const guint8 hw_addr_len; /* read-only */ guint8 hw_addr_len_; @@ -790,43 +795,212 @@ void nm_device_set_ip_iface (NMDevice *self, const char *iface) { NMDevicePrivate *priv; - char *old_ip_iface; + int ifindex; g_return_if_fail (NM_IS_DEVICE (self)); priv = NM_DEVICE_GET_PRIVATE (self); - if (!g_strcmp0 (iface, priv->ip_iface)) - return; - - old_ip_iface = priv->ip_iface; - priv->ip_ifindex = 0; - - priv->ip_iface = g_strdup (iface); - if (priv->ip_iface) { - priv->ip_ifindex = nm_platform_link_get_ifindex (NM_PLATFORM_GET, priv->ip_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_streq0 (iface, priv->ip_iface)) { + if (!iface) + return; + ifindex = nm_platform_if_nametoindex (NM_PLATFORM_GET, iface); + if ( ifindex <= 0 + || priv->ip_ifindex == ifindex) + return; - if (!nm_platform_link_is_up (NM_PLATFORM_GET, priv->ip_ifindex)) - nm_platform_link_set_up (NM_PLATFORM_GET, priv->ip_ifindex, NULL); + priv->ip_ifindex = ifindex; + _LOGD (LOGD_DEVICE, "ip-ifname: update ifindex for ifname '%s': %d", iface, priv->ip_ifindex); + } else { + g_free (priv->ip_iface); + priv->ip_iface = g_strdup (iface); + + if (iface) { + /* The @iface name is not in sync with the platform cache. + * So, there is no point asking the platform cache to resolve + * the ifindex. Instead, we can only hope that the interface + * with this name still exists and we resolve the ifindex + * anew. + */ + priv->ip_ifindex = nm_platform_if_nametoindex (NM_PLATFORM_GET, iface); + if (priv->ip_ifindex > 0) + _LOGD (LOGD_DEVICE, "ip-ifname: set ifname '%s', ifindex %d", iface, priv->ip_ifindex); + else + _LOGW (LOGD_DEVICE, "ip-ifname: set ifname '%s', unknown ifindex", iface); } else { - /* Device IP interface must always be a kernel network interface */ - _LOGW (LOGD_PLATFORM, "failed to look up interface index"); + priv->ip_ifindex = 0; + _LOGD (LOGD_DEVICE, "ip-ifname: clear ifname"); } } + 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_link_is_up (NM_PLATFORM_GET, priv->ip_ifindex)) + nm_platform_link_set_up (NM_PLATFORM_GET, priv->ip_ifindex, NULL); + } /* We don't care about any saved values from the old iface */ g_hash_table_remove_all (priv->ip6_saved_properties); - /* Emit change notification */ - if (g_strcmp0 (old_ip_iface, priv->ip_iface)) { - if (priv->ip_ifindex) - priv->ip_mtu = nm_platform_link_get_mtu (NM_PLATFORM_GET, priv->ip_ifindex); - _notify (self, PROP_IP_IFACE); + if (priv->ip_ifindex) + priv->ip_mtu = nm_platform_link_get_mtu (NM_PLATFORM_GET, priv->ip_ifindex); + + _notify (self, PROP_IP_IFACE); +} + +static gboolean +_ip_iface_update (NMDevice *self, const char *ip_iface) +{ + NMDevicePrivate *priv; + + g_return_val_if_fail (NM_IS_DEVICE (self), FALSE); + + priv = NM_DEVICE_GET_PRIVATE (self); + + g_return_val_if_fail (priv->ip_iface, FALSE); + g_return_val_if_fail (priv->ip_ifindex > 0, FALSE); + g_return_val_if_fail (ip_iface, FALSE); + + if (!ip_iface[0]) + return FALSE; + + if (nm_streq (priv->ip_iface, ip_iface)) + return FALSE; + + _LOGI (LOGD_DEVICE, "ip-ifname: interface index %d renamed ip_iface (%d) from '%s' to '%s'", + priv->ifindex, priv->ip_ifindex, + priv->ip_iface, ip_iface); + g_free (priv->ip_iface); + priv->ip_iface = g_strdup (ip_iface); + _notify (self, PROP_IP_IFACE); + return TRUE; +} + +/*****************************************************************************/ + +int +nm_device_parent_get_ifindex (NMDevice *self) +{ + NMDevicePrivate *priv; + + g_return_val_if_fail (NM_IS_DEVICE (self), 0); + + priv = NM_DEVICE_GET_PRIVATE (self); + return priv->parent_ifindex; +} + +NMDevice * +nm_device_parent_get_device (NMDevice *self) +{ + NMDevicePrivate *priv; + + g_return_val_if_fail (NM_IS_DEVICE (self), NULL); + + priv = NM_DEVICE_GET_PRIVATE (self); + return priv->parent_device; +} + +static void +parent_changed_notify (NMDevice *self, + int old_ifindex, + NMDevice *old_parent, + int new_ifindex, + NMDevice *new_parent) +{ + /* empty handler to allow subclasses to always chain up the virtual function. */ +} + +static gboolean +_parent_set_ifindex (NMDevice *self, + int parent_ifindex, + gboolean force_check) +{ + NMDevicePrivate *priv; + NMDevice *parent_device; + gboolean changed = FALSE; + int old_ifindex; + NMDevice *old_device; + + g_return_val_if_fail (NM_IS_DEVICE (self), FALSE); + + priv = NM_DEVICE_GET_PRIVATE (self); + + if (parent_ifindex <= 0) + parent_ifindex = 0; + + old_ifindex = priv->parent_ifindex; + old_device = priv->parent_device; + + if (priv->parent_ifindex == parent_ifindex) { + if (parent_ifindex > 0) { + if ( !force_check + && priv->parent_device + && nm_device_get_ifindex (priv->parent_device) == parent_ifindex) + return FALSE; + } else { + if (!priv->parent_device) + return FALSE; + } + } else { + priv->parent_ifindex = parent_ifindex; + changed = TRUE; + } + + if (parent_ifindex > 0) { + parent_device = nm_manager_get_device_by_ifindex (nm_manager_get (), parent_ifindex); + if (parent_device == self) + parent_device = NULL; + } else + parent_device = NULL; + + if (parent_device != priv->parent_device) { + priv->parent_device = parent_device; + changed = TRUE; } - g_free (old_ip_iface); + + if (changed) { + if (priv->parent_ifindex <= 0) + _LOGD (LOGD_DEVICE, "parent: clear"); + else if (!priv->parent_device) + _LOGD (LOGD_DEVICE, "parent: ifindex %d, no device", priv->parent_ifindex); + else { + _LOGD (LOGD_DEVICE, "parent: ifindex %d, device %p, %s", priv->parent_ifindex, + priv->parent_device, nm_device_get_iface (priv->parent_device)); + } + + NM_DEVICE_GET_CLASS (self)->parent_changed_notify (self, old_ifindex, old_device, priv->parent_ifindex, priv->parent_device); + + _notify (self, PROP_PARENT); + } + return changed; +} + +void +nm_device_parent_set_ifindex (NMDevice *self, + int parent_ifindex) +{ + _parent_set_ifindex (self, parent_ifindex, FALSE); +} + +gboolean +nm_device_parent_notify_changed (NMDevice *self, + NMDevice *change_candidate, + gboolean device_removed) +{ + NMDevicePrivate *priv; + + nm_assert (NM_IS_DEVICE (self)); + nm_assert (NM_IS_DEVICE (change_candidate)); + + priv = NM_DEVICE_GET_PRIVATE (self); + + if (priv->parent_ifindex > 0) { + if ( priv->parent_device == change_candidate + || priv->parent_ifindex == nm_device_get_ifindex (change_candidate)) + return _parent_set_ifindex (self, priv->parent_ifindex, device_removed); + } + return FALSE; } /*****************************************************************************/ @@ -1981,8 +2155,12 @@ device_link_changed (NMDevice *self) _LOGD (LOGD_DEVICE, "IPv6 tokenized identifier present on device %s", priv->iface); } - if (klass->link_changed) - klass->link_changed (self, &info); + /* Update carrier from link event if applicable. */ + if ( nm_device_has_capability (self, NM_DEVICE_CAP_CARRIER_DETECT) + && !nm_device_has_capability (self, NM_DEVICE_CAP_NONSTANDARD_CARRIER)) + nm_device_set_carrier (self, pllink->connected); + + klass->link_changed (self, &info); /* Update DHCP, etc, if needed */ if (ip_ifname_changed) @@ -2075,16 +2253,8 @@ device_ip_link_changed (NMDevice *self) if (priv->ip_mtu != pllink->mtu) priv->ip_mtu = pllink->mtu; - if (pllink->name[0] && g_strcmp0 (priv->ip_iface, pllink->name)) { - _LOGI (LOGD_DEVICE, "interface index %d renamed ip_iface (%d) from '%s' to '%s'", - priv->ifindex, nm_device_get_ip_ifindex (self), - priv->ip_iface, pllink->name); - g_free (priv->ip_iface); - priv->ip_iface = g_strdup (pllink->name); - - _notify (self, PROP_IP_IFACE); + if (_ip_iface_update (self, pllink->name)) nm_device_update_dynamic_ip_setup (self); - } return G_SOURCE_REMOVE; } @@ -2119,12 +2289,9 @@ link_changed_cb (NMPlatform *platform, } static void -link_changed (NMDevice *self, NMPlatformLink *info) +link_changed (NMDevice *self, const NMPlatformLink *pllink) { - /* Update carrier from link event if applicable. */ - if ( nm_device_has_capability (self, NM_DEVICE_CAP_CARRIER_DETECT) - && !nm_device_has_capability (self, NM_DEVICE_CAP_NONSTANDARD_CARRIER)) - nm_device_set_carrier (self, info->connected); + /* stub implementation of virtual function to allow subclasses to chain up. */ } static gboolean @@ -2284,8 +2451,10 @@ update_device_from_platform_link (NMDevice *self, const NMPlatformLink *plink) _notify (self, PROP_IFACE); } - priv->ifindex = plink->ifindex; - _notify (self, PROP_IFINDEX); + if (priv->ifindex != plink->ifindex) { + priv->ifindex = plink->ifindex; + _notify (self, PROP_IFINDEX); + } priv->up = NM_FLAGS_HAS (plink->n_ifi_flags, IFF_UP); if (plink->driver && g_strcmp0 (plink->driver, priv->driver) != 0) { @@ -2319,11 +2488,12 @@ check_carrier (NMDevice *self) } static void -realize_start_notify (NMDevice *self, const NMPlatformLink *plink) +realize_start_notify (NMDevice *self, + const NMPlatformLink *pllink) { - /* Stub implementation for realize_start_notify(). It does nothing, - * but allows derived classes to uniformly invoke the parent - * implementation. */ + /* the default implementation of realize_start_notify() just calls + * link_changed() -- which by default does nothing. */ + NM_DEVICE_GET_CLASS (self)->link_changed (self, pllink); } /** @@ -2583,15 +2753,16 @@ nm_device_unrealize (NMDevice *self, gboolean remove_resources, GError **error) NM_DEVICE_GET_CLASS (self)->unrealize_notify (self); + _parent_set_ifindex (self, 0, FALSE); + if (priv->ifindex > 0) { priv->ifindex = 0; _notify (self, PROP_IFINDEX); } priv->ip_ifindex = 0; - if (priv->ip_iface) { - g_clear_pointer (&priv->ip_iface, g_free); + if (nm_clear_g_free (&priv->ip_iface)) _notify (self, PROP_IP_IFACE); - } + if (priv->driver_version) { g_clear_pointer (&priv->driver_version, g_free); _notify (self, PROP_DRIVER_VERSION); @@ -2659,27 +2830,6 @@ nm_device_unrealize (NMDevice *self, gboolean remove_resources, GError **error) } /** - * nm_device_notify_new_device_added(): - * @self: the #NMDevice - * @device: the newly added device - * - * Called by the manager to notify the device that a new device has - * been found and added. - */ -void -nm_device_notify_new_device_added (NMDevice *self, NMDevice *device) -{ - NMDeviceClass *klass; - - g_return_if_fail (NM_IS_DEVICE (self)); - g_return_if_fail (NM_IS_DEVICE (device)); - - klass = NM_DEVICE_GET_CLASS (self); - if (klass->notify_new_device_added) - klass->notify_new_device_added (self, device); -} - -/** * nm_device_notify_component_added(): * @self: the #NMDevice * @component: the component being added by a plugin @@ -3710,9 +3860,9 @@ recheck_available (gpointer user_data) if (new_state > NM_DEVICE_STATE_UNKNOWN) { _LOGD (LOGD_DEVICE, "is %savailable, %s %s", - now_available ? "" : "not ", - new_state == NM_DEVICE_STATE_UNAVAILABLE ? "no change required for" : "will transition to", - state_to_string (new_state == NM_DEVICE_STATE_UNAVAILABLE ? state : new_state)); + now_available ? "" : "not ", + new_state == NM_DEVICE_STATE_UNAVAILABLE ? "no change required for" : "will transition to", + state_to_string (new_state == NM_DEVICE_STATE_UNAVAILABLE ? state : new_state)); priv->recheck_available.available_reason = NM_DEVICE_STATE_REASON_NONE; priv->recheck_available.unavailable_reason = NM_DEVICE_STATE_REASON_NONE; @@ -12684,6 +12834,8 @@ dispose (GObject *object) _LOGD (LOGD_DEVICE, "disposing"); + _parent_set_ifindex (self, 0, FALSE); + platform = NM_PLATFORM_GET; 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); @@ -12720,6 +12872,11 @@ dispose (GObject *object) link_disconnect_action_cancel (self); + if (priv->ifindex > 0) { + priv->ifindex = 0; + _notify (self, PROP_IFINDEX); + } + if (priv->settings) { g_signal_handlers_disconnect_by_func (priv->settings, cp_connection_added, self); g_signal_handlers_disconnect_by_func (priv->settings, cp_connection_updated, self); @@ -12998,6 +13155,9 @@ get_property (GObject *object, guint prop_id, case PROP_MASTER: g_value_set_object (value, nm_device_get_master (self)); break; + case PROP_PARENT: + nm_utils_g_value_set_object_path (value, priv->parent_device); + break; case PROP_HW_ADDRESS: g_value_set_string (value, priv->hw_addr); break; @@ -13102,6 +13262,7 @@ nm_device_class_init (NMDeviceClass *klass) klass->get_ip_iface_identifier = get_ip_iface_identifier; klass->unmanaged_on_quit = unmanaged_on_quit; klass->deactivate_reset_hw_addr = deactivate_reset_hw_addr; + klass->parent_changed_notify = parent_changed_notify; obj_properties[PROP_UDI] = g_param_spec_string (NM_DEVICE_UDI, "", "", @@ -13256,6 +13417,11 @@ nm_device_class_init (NMDeviceClass *klass) NM_TYPE_DEVICE, G_PARAM_READABLE | G_PARAM_STATIC_STRINGS); + obj_properties[PROP_PARENT] = + g_param_spec_string (NM_DEVICE_PARENT, "", "", + NULL, + G_PARAM_READABLE | + G_PARAM_STATIC_STRINGS); obj_properties[PROP_HW_ADDRESS] = g_param_spec_string (NM_DEVICE_HW_ADDRESS, "", "", NULL, diff --git a/src/devices/nm-device.h b/src/devices/nm-device.h index ab6852e40e..904c7d2390 100644 --- a/src/devices/nm-device.h +++ b/src/devices/nm-device.h @@ -66,6 +66,9 @@ #define NM_DEVICE_LLDP_NEIGHBORS "lldp-neighbors" #define NM_DEVICE_REAL "real" +/* "parent" is exposed on D-Bus by subclasses like NMDeviceIPTunnel */ +#define NM_DEVICE_PARENT "parent" + /* the "slaves" property is internal in the parent class, but exposed * by the derived classes NMDeviceBond, NMDeviceBridge and NMDeviceTeam. * It is thus important that the property name matches. */ @@ -153,7 +156,8 @@ typedef struct { NMDeviceState old_state, NMDeviceStateReason reason); - void (* link_changed) (NMDevice *self, NMPlatformLink *info); + void (* link_changed) (NMDevice *self, + const NMPlatformLink *pllink); /** * create_and_realize(): @@ -181,12 +185,15 @@ typedef struct { /** * realize_start_notify(): * @self: the #NMDevice - * @plink: the #NMPlatformLink if backed by a kernel netdevice + * @pllink: the #NMPlatformLink if backed by a kernel netdevice * * Hook for derived classes to be notfied during realize_start_setup() * and perform additional setup. + * + * The default implemention of NMDevice calls link_changed(). */ - void (*realize_start_notify) (NMDevice *self, const NMPlatformLink *plink); + void (*realize_start_notify) (NMDevice *self, + const NMPlatformLink *pllink); /** * unrealize(): @@ -310,7 +317,11 @@ typedef struct { gboolean (* have_any_ready_slaves) (NMDevice *self, const GSList *slaves); - void (* notify_new_device_added) (NMDevice *self, NMDevice *new_device); + void (* parent_changed_notify) (NMDevice *self, + int old_ifindex, + NMDevice *old_parent, + int new_ifindex, + NMDevice *new_parent); /** * component_added: @@ -386,6 +397,14 @@ void nm_device_replace_vpn6_config (NMDevice *dev, void nm_device_capture_initial_config (NMDevice *dev); +int nm_device_parent_get_ifindex (NMDevice *dev); +NMDevice *nm_device_parent_get_device (NMDevice *dev); +void nm_device_parent_set_ifindex (NMDevice *self, + int parent_ifindex); +gboolean nm_device_parent_notify_changed (NMDevice *self, + NMDevice *change_candidate, + gboolean device_removed); + /* Master */ gboolean nm_device_is_master (NMDevice *dev); @@ -575,7 +594,6 @@ gboolean nm_device_check_connection_available (NMDevice *device, NMDeviceCheckConAvailableFlags flags, const char *specific_object); -void nm_device_notify_new_device_added (NMDevice *self, NMDevice *new_device); gboolean nm_device_notify_component_added (NMDevice *device, GObject *component); gboolean nm_device_owns_iface (NMDevice *device, const char *iface); diff --git a/src/nm-iface-helper.c b/src/nm-iface-helper.c index 393e8acc57..f7c43d2bb3 100644 --- a/src/nm-iface-helper.c +++ b/src/nm-iface-helper.c @@ -32,13 +32,10 @@ #include <sys/stat.h> #include <signal.h> -/* Cannot include <net/if.h> due to conflict with <linux/if.h>. - * Forward declare if_nametoindex. */ -extern unsigned int if_nametoindex (const char *__ifname); - #include "main-utils.h" #include "NetworkManagerUtils.h" #include "platform/nm-linux-platform.h" +#include "platform/nm-platform-utils.h" #include "dhcp/nm-dhcp-manager.h" #include "ndisc/nm-ndisc.h" #include "ndisc/nm-lndp-ndisc.h" @@ -394,7 +391,7 @@ main (int argc, char *argv[]) return 1; } - gl.ifindex = if_nametoindex (global_opt.ifname); + gl.ifindex = nmp_utils_if_nametoindex (global_opt.ifname); if (gl.ifindex <= 0) { fprintf (stderr, _("Failed to find interface index for %s (%s)\n"), global_opt.ifname, strerror (errno)); return 1; diff --git a/src/nm-manager.c b/src/nm-manager.c index f35c485d97..2f0d66ee08 100644 --- a/src/nm-manager.c +++ b/src/nm-manager.c @@ -950,6 +950,26 @@ settings_startup_complete_changed (NMSettings *settings, } static void +_parent_notify_changed (NMManager *self, + NMDevice *device, + gboolean device_removed) +{ + GSList *iter; + + nm_assert (NM_IS_DEVICE (device)); + nm_assert (NM_IS_MANAGER (self)); + + for (iter = NM_MANAGER_GET_PRIVATE (self)->devices; iter; ) { + if (nm_device_parent_notify_changed (iter->data, device, device_removed)) { + /* in the unlikely event that this changes anything, we start iterating + * again, to be sure that the device list is up-to-date. */ + iter = NM_MANAGER_GET_PRIVATE (self)->devices; + } else + iter = iter->next; + } +} + +static void remove_device (NMManager *self, NMDevice *device, gboolean quitting, @@ -985,6 +1005,8 @@ remove_device (NMManager *self, nm_settings_device_removed (priv->settings, device, quitting); priv->devices = g_slist_remove (priv->devices, device); + _parent_notify_changed (self, device, TRUE); + if (nm_device_is_real (device)) { gboolean unconfigure_ip_config = !quitting || unmanage; @@ -1861,6 +1883,14 @@ recheck_assume_connection_cb (NMDevice *device, gpointer user_data) } static void +device_ifindex_changed (NMDevice *device, + GParamSpec *pspec, + NMManager *self) +{ + _parent_notify_changed (self, device, FALSE); +} + +static void device_ip_iface_changed (NMDevice *device, GParamSpec *pspec, NMManager *self) @@ -1998,6 +2028,10 @@ add_device (NMManager *self, NMDevice *device, GError **error) G_CALLBACK (device_ip_iface_changed), self); + g_signal_connect (device, "notify::" NM_DEVICE_IFINDEX, + G_CALLBACK (device_ifindex_changed), + self); + g_signal_connect (device, "notify::" NM_DEVICE_IFACE, G_CALLBACK (device_iface_changed), self); @@ -2040,12 +2074,7 @@ add_device (NMManager *self, NMDevice *device, GError **error) g_signal_emit (self, signals[INTERNAL_DEVICE_ADDED], 0, device); _notify (self, PROP_ALL_DEVICES); - for (iter = priv->devices; iter; iter = iter->next) { - NMDevice *d = iter->data; - - if (d != device) - nm_device_notify_new_device_added (d, device); - } + _parent_notify_changed (self, device, FALSE); /* Virtual connections may refer to the new device as * parent device, retry to activate them. diff --git a/src/platform/nm-platform-utils.c b/src/platform/nm-platform-utils.c index 8b6994e20e..22e723626e 100644 --- a/src/platform/nm-platform-utils.c +++ b/src/platform/nm-platform-utils.c @@ -38,7 +38,29 @@ #include "nm-core-utils.h" +/****************************************************************** + * utils + ******************************************************************/ + extern char *if_indextoname (unsigned int __ifindex, char *__ifname); +unsigned int if_nametoindex (const char *__ifname); + +const char * +nmp_utils_if_indextoname (int ifindex, char *out_ifname/*IFNAMSIZ*/) +{ + g_return_val_if_fail (ifindex > 0, NULL); + g_return_val_if_fail (out_ifname, NULL); + + return if_indextoname (ifindex, out_ifname); +} + +int +nmp_utils_if_nametoindex (const char *ifname) +{ + g_return_val_if_fail (ifname, 0); + + return if_nametoindex (ifname); +} /****************************************************************** * ethtool @@ -91,7 +113,7 @@ ethtool_get (int ifindex, gpointer edata) * This does not solve the renaming race, but it minimizes the time for * the race to happen as much as possible. */ - if (!if_indextoname (ifindex, ifname)) { + if (!nmp_utils_if_indextoname (ifindex, ifname)) { nm_log_trace (LOGD_PLATFORM, "ethtool[%d]: %s: request fails resolving ifindex: %s", ifindex, _ethtool_data_to_string (edata, sbuf, sizeof (sbuf)), @@ -461,7 +483,7 @@ nmp_utils_mii_supports_carrier_detect (int ifindex) g_return_val_if_fail (ifindex > 0, FALSE); - if (!if_indextoname (ifindex, ifname)) { + if (!nmp_utils_if_indextoname (ifindex, ifname)) { nm_log_trace (LOGD_PLATFORM, "mii[%d]: carrier-detect no: request fails resolving ifindex: %s", ifindex, g_strerror (errno)); return FALSE; } @@ -696,7 +718,7 @@ nmp_utils_sysctl_open_netdir (int ifindex, int fd; if (!ifname) { - ifname = if_indextoname (ifindex, ifname_buf); + ifname = nmp_utils_if_indextoname (ifindex, ifname_buf); if (!ifname) return -1; } diff --git a/src/platform/nm-platform-utils.h b/src/platform/nm-platform-utils.h index ea9607e6a3..699e80c698 100644 --- a/src/platform/nm-platform-utils.h +++ b/src/platform/nm-platform-utils.h @@ -74,6 +74,9 @@ NMIPConfigSource nmp_utils_ip_config_source_coerce_from_rtprot (NMIPConfigSource NMIPConfigSource nmp_utils_ip_config_source_round_trip_rtprot (NMIPConfigSource source) _nm_const; const char * nmp_utils_ip_config_source_to_string (NMIPConfigSource source, char *buf, gsize len); +const char *nmp_utils_if_indextoname (int ifindex, char *out_ifname/*IFNAMSIZ*/); +int nmp_utils_if_nametoindex (const char *ifname); + int nmp_utils_sysctl_open_netdir (int ifindex, const char *ifname_guess, char *out_ifname); diff --git a/src/platform/nm-platform.c b/src/platform/nm-platform.c index d0b65adf08..9d972a5897 100644 --- a/src/platform/nm-platform.c +++ b/src/platform/nm-platform.c @@ -770,6 +770,22 @@ nm_platform_link_get_ifindex (NMPlatform *self, const char *name) return pllink ? pllink->ifindex : 0; } +const char * +nm_platform_if_indextoname (NMPlatform *self, int ifindex, char *out_ifname/* of size IFNAMSIZ */) +{ + _CHECK_SELF_NETNS (self, klass, netns, FALSE); + + return nmp_utils_if_indextoname (ifindex, out_ifname); +} + +int +nm_platform_if_nametoindex (NMPlatform *self, const char *ifname) +{ + _CHECK_SELF_NETNS (self, klass, netns, FALSE); + + return nmp_utils_if_nametoindex (ifname); +} + /** * nm_platform_link_get_name: * @self: platform instance diff --git a/src/platform/nm-platform.h b/src/platform/nm-platform.h index 55d7a6f20e..91f8ab5d6f 100644 --- a/src/platform/nm-platform.h +++ b/src/platform/nm-platform.h @@ -738,6 +738,9 @@ gint64 nm_platform_sysctl_get_int_checked (NMPlatform *self, const char *pathid, gboolean nm_platform_sysctl_set_ip6_hop_limit_safe (NMPlatform *self, const char *iface, int value); +const char *nm_platform_if_indextoname (NMPlatform *self, int ifindex, char *out_ifname/* of size IFNAMSIZ */); +int nm_platform_if_nametoindex (NMPlatform *self, const char *ifname); + const NMPlatformLink *nm_platform_link_get (NMPlatform *self, int ifindex); const NMPlatformLink *nm_platform_link_get_by_ifname (NMPlatform *self, const char *ifname); const NMPlatformLink *nm_platform_link_get_by_address (NMPlatform *self, gconstpointer address, size_t length); diff --git a/src/settings/plugins/ifcfg-rh/nms-ifcfg-rh-connection.c b/src/settings/plugins/ifcfg-rh/nms-ifcfg-rh-connection.c index 92593644d7..33f4847ed1 100644 --- a/src/settings/plugins/ifcfg-rh/nms-ifcfg-rh-connection.c +++ b/src/settings/plugins/ifcfg-rh/nms-ifcfg-rh-connection.c @@ -197,8 +197,8 @@ nm_ifcfg_connection_check_devtimeout (NMIfcfgConnection *self) devtimeout, ifname, nm_connection_get_id (NM_CONNECTION (self))); priv->devtimeout_link_changed_handler = - g_signal_connect (NM_PLATFORM_GET, NM_PLATFORM_SIGNAL_LINK_CHANGED, - G_CALLBACK (link_changed), self); + g_signal_connect (NM_PLATFORM_GET, NM_PLATFORM_SIGNAL_LINK_CHANGED, + G_CALLBACK (link_changed), self); priv->devtimeout_timeout_id = g_timeout_add_seconds (devtimeout, devtimeout_expired, self); } |