diff options
Diffstat (limited to 'src/devices/nm-device-veth.c')
| -rw-r--r-- | src/devices/nm-device-veth.c | 95 |
1 files changed, 37 insertions, 58 deletions
diff --git a/src/devices/nm-device-veth.c b/src/devices/nm-device-veth.c index c16df6d8..a5a87a2d 100644 --- a/src/devices/nm-device-veth.c +++ b/src/devices/nm-device-veth.c @@ -23,17 +23,14 @@ #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" #include "nm-manager.h" -#include "nm-platform.h" +#include "platform/nm-platform.h" #include "nm-device-factory.h" -#include "nmdbus-device-veth.h" +#include "introspection/org.freedesktop.NetworkManager.Device.Veth.h" #include "nm-device-logging.h" _LOG_DECLARE_SELF(NMDeviceVeth); @@ -41,8 +38,6 @@ _LOG_DECLARE_SELF(NMDeviceVeth); /*****************************************************************************/ typedef struct { - NMDevice *peer; - gboolean ever_had_peer; } NMDeviceVethPrivate; struct _NMDeviceVeth { @@ -51,7 +46,7 @@ struct _NMDeviceVeth { }; struct _NMDeviceVethClass { - NMDeviceEthernetClass parent_class; + NMDeviceEthernetClass parent; }; NM_GOBJECT_PROPERTIES_DEFINE (NMDeviceVeth, @@ -67,42 +62,23 @@ G_DEFINE_TYPE (NMDeviceVeth, nm_device_veth, NM_TYPE_DEVICE_ETHERNET) /*****************************************************************************/ static void -set_peer (NMDeviceVeth *self, NMDevice *peer) -{ - 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); - } -} - -static NMDevice * -get_peer (NMDeviceVeth *self) +update_properties (NMDevice *device) { - NMDeviceVethPrivate *priv = NM_DEVICE_VETH_GET_PRIVATE (self); - NMDevice *device = NM_DEVICE (self), *peer = NULL; - int peer_ifindex; + NMDevice *peer; + int ifindex, peer_ifindex; - if (priv->ever_had_peer) - return priv->peer; + ifindex = nm_device_get_ifindex (device); - 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; - } + if (!nm_platform_link_veth_get_properties (NM_PLATFORM_GET, ifindex, &peer_ifindex)) + peer_ifindex = 0; - 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); - } + nm_device_parent_set_ifindex (device, peer_ifindex); - 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,7 +91,15 @@ 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 nm_device_veth_init (NMDeviceVeth *self) @@ -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, "", "", @@ -180,10 +160,10 @@ nm_device_veth_class_init (NMDeviceVethClass *klass) NULL); } -/*************************************************************/ +/*****************************************************************************/ -#define NM_TYPE_VETH_FACTORY (nm_veth_factory_get_type ()) -#define NM_VETH_FACTORY(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), NM_TYPE_VETH_FACTORY, NMVethFactory)) +#define NM_TYPE_VETH_DEVICE_FACTORY (nm_veth_device_factory_get_type ()) +#define NM_VETH_DEVICE_FACTORY(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), NM_TYPE_VETH_DEVICE_FACTORY, NMVethDeviceFactory)) static NMDevice * create_device (NMDeviceFactory *factory, @@ -202,6 +182,5 @@ create_device (NMDeviceFactory *factory, NM_DEVICE_FACTORY_DEFINE_INTERNAL (VETH, Veth, veth, NM_DEVICE_FACTORY_DECLARE_LINK_TYPES (NM_LINK_TYPE_VETH), - factory_iface->create_device = create_device; - ) - + factory_class->create_device = create_device; +); |