summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThomas Haller <thaller@redhat.com>2017-01-02 09:57:43 +0100
committerThomas Haller <thaller@redhat.com>2017-01-04 14:18:01 +0100
commitb8bfdd99afce6ab71ea5425297994b5749c5d4c3 (patch)
tree9c2f0ccc2a58f5af9e3e6ef2ecf299e6490b8335
parent31682f7a3b9455ceca0974c669f04adac7b9f744 (diff)
downloadNetworkManager-b8bfdd99afce6ab71ea5425297994b5749c5d4c3.tar.gz
device: move tracking of parent device from NMDeviceVlan to NMDevice
-rw-r--r--src/devices/nm-device-vlan.c157
-rw-r--r--src/devices/nm-device-vlan.h4
2 files changed, 65 insertions, 96 deletions
diff --git a/src/devices/nm-device-vlan.c b/src/devices/nm-device-vlan.c
index af4413f199..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) {
@@ -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,7 +624,6 @@ 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->link_changed = link_changed;
@@ -660,18 +632,13 @@ nm_device_vlan_class_init (NMDeviceVlanClass *klass)
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;