diff options
author | Thomas Haller <thaller@redhat.com> | 2015-06-20 12:05:01 +0200 |
---|---|---|
committer | Thomas Haller <thaller@redhat.com> | 2015-06-21 12:53:48 +0200 |
commit | e8e455817b340f60b396ba5d41425ed4de4c8554 (patch) | |
tree | eabf5d6dfcf2ac2f35d92e7f6069f6d98f562d65 /src/devices | |
parent | ae824f582b0dbb9fe49e1aa7fb1d27319028892b (diff) | |
download | NetworkManager-e8e455817b340f60b396ba5d41425ed4de4c8554.tar.gz |
platform: refactor virtual methods for link objects in NMPlatform
Change nm_platform_link_get() to return the cached NMPlatformLink
instance. Now what all our implementations (fake and linux) have such a
cache internal object, let's just expose it directly.
Note that the lifetime of the exposed link object is possibly quite
short. A caller must copy the returned value if he intends to preserve
it for later.
Also add nm_platform_link_get_by_ifname() and modify nm_platform_link_get_by_address()
to return the instance.
Certain functions, such as nm_platform_link_get_name(),
nm_platform_link_get_ifindex(), etc. are solely implemented based
on looking at the returned NMPlatformLink object. No longer implement
them as virtual functions but instead implement them in the base class
(nm-platform.c).
This removes code and eliminates the redundancy of the exposed
NMPlatformLink instance and the nm_platform_link_get_*() accessors.
Thereby also fix a bug in NMFakePlatform that tracked the link address
in a separate "address" field, instead of using "link.addr". That was
a case where the redundancy actually led to a bug in fake platform.
Also remove some stub implementations in NMFakePlatform that just
bail out. Instead allow for a missing virtual functions and perform
the "default" action in the accessor.
An example for that is nm_platform_link_get_permanent_address().
Diffstat (limited to 'src/devices')
-rw-r--r-- | src/devices/nm-device.c | 17 |
1 files changed, 11 insertions, 6 deletions
diff --git a/src/devices/nm-device.c b/src/devices/nm-device.c index 17da4947a8..c8356c53c1 100644 --- a/src/devices/nm-device.c +++ b/src/devices/nm-device.c @@ -1346,14 +1346,18 @@ device_link_changed (NMDevice *self) gboolean platform_unmanaged = FALSE; const char *udi; NMPlatformLink info; + const NMPlatformLink *pllink; int ifindex; priv->device_link_changed_id = 0; ifindex = nm_device_get_ifindex (self); - if (!nm_platform_link_get (NM_PLATFORM_GET, ifindex, &info)) + pllink = nm_platform_link_get (NM_PLATFORM_GET, ifindex); + if (!pllink) return G_SOURCE_REMOVE; + info = *pllink; + udi = nm_platform_link_get_udi (NM_PLATFORM_GET, info.ifindex); if (udi && g_strcmp0 (udi, priv->udi)) { /* Update UDI to what udev gives us */ @@ -1485,21 +1489,22 @@ static gboolean device_ip_link_changed (NMDevice *self) { NMDevicePrivate *priv = NM_DEVICE_GET_PRIVATE (self); - NMPlatformLink info; + const NMPlatformLink *pllink; int ip_ifindex; priv->device_ip_link_changed_id = 0; ip_ifindex = nm_device_get_ip_ifindex (self); - if (!nm_platform_link_get (NM_PLATFORM_GET, ip_ifindex, &info)) + pllink = nm_platform_link_get (NM_PLATFORM_GET, ip_ifindex); + if (!pllink) return G_SOURCE_REMOVE; - if (info.name[0] && g_strcmp0 (priv->ip_iface, info.name)) { + 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, info.name); + priv->ip_iface, pllink->name); g_free (priv->ip_iface); - priv->ip_iface = g_strdup (info.name); + priv->ip_iface = g_strdup (pllink->name); g_object_notify (G_OBJECT (self), NM_DEVICE_IP_IFACE); update_for_ip_ifname_change (self); |