mirror of
https://gitlab.freedesktop.org/NetworkManager/NetworkManager.git
synced 2026-04-20 00:10:37 +02:00
device: move tracking of peer device from NMDeviceVeth to NMDevice
This commit is contained in:
parent
6df235df74
commit
992beb4f34
1 changed files with 28 additions and 48 deletions
|
|
@ -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);
|
||||
NMDevice *peer;
|
||||
int ifindex, peer_ifindex;
|
||||
|
||||
if (!priv->peer) {
|
||||
priv->ever_had_peer = TRUE;
|
||||
priv->peer = peer;
|
||||
g_object_add_weak_pointer (G_OBJECT (peer), (gpointer *) &priv->peer);
|
||||
ifindex = nm_device_get_ifindex (device);
|
||||
|
||||
_notify (self, PROP_PEER);
|
||||
}
|
||||
}
|
||||
if (!nm_platform_link_veth_get_properties (NM_PLATFORM_GET, ifindex, &peer_ifindex))
|
||||
peer_ifindex = 0;
|
||||
|
||||
static NMDevice *
|
||||
get_peer (NMDeviceVeth *self)
|
||||
{
|
||||
NMDeviceVethPrivate *priv = NM_DEVICE_VETH_GET_PRIVATE (self);
|
||||
NMDevice *device = NM_DEVICE (self), *peer = NULL;
|
||||
int peer_ifindex;
|
||||
nm_device_parent_set_ifindex (device, peer_ifindex);
|
||||
|
||||
if (priv->ever_had_peer)
|
||||
return priv->peer;
|
||||
|
||||
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 (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, "", "",
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue