diff options
author | Thomas Haller <thaller@redhat.com> | 2020-07-20 14:30:30 +0200 |
---|---|---|
committer | Thomas Haller <thaller@redhat.com> | 2020-07-23 15:29:24 +0200 |
commit | d32074e2b6e637aab7e64c985c6da35a748344cc (patch) | |
tree | 29b5035be082d42c3ed66b07fbb594f12bbb6ac6 | |
parent | 5c273efb36b506d5fab326d0d45491a09222d232 (diff) | |
download | NetworkManager-d32074e2b6e637aab7e64c985c6da35a748344cc.tar.gz |
device: simplify device_ip_link_changed() for setting ip_iface
_ip_iface_update() only had one caller. The code is simpler to
understand by inlining it.
Also, it is relevant where and how we set ip_iface_ and ip_ifindex_
fields. Keep the places few and easily understandable.
-rw-r--r-- | src/devices/nm-device.c | 55 |
1 files changed, 22 insertions, 33 deletions
diff --git a/src/devices/nm-device.c b/src/devices/nm-device.c index 797de61488..a5eface7e4 100644 --- a/src/devices/nm-device.c +++ b/src/devices/nm-device.c @@ -2003,36 +2003,6 @@ nm_device_set_ip_iface (NMDevice *self, const char *ifname) return ifindex > 0; } -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 @@ -4469,23 +4439,42 @@ device_ip_link_changed (NMDevice *self) { NMDevicePrivate *priv = NM_DEVICE_GET_PRIVATE (self); const NMPlatformLink *pllink; + const char *ip_iface; priv->device_ip_link_changed_id = 0; - if (!priv->ip_ifindex) + if (priv->ip_ifindex <= 0) return G_SOURCE_REMOVE; + nm_assert (priv->ip_iface); + pllink = nm_platform_link_get (nm_device_get_platform (self), priv->ip_ifindex); if (!pllink) return G_SOURCE_REMOVE; - if (priv->ifindex <= 0 && pllink->mtu) + if ( priv->ifindex <= 0 + && pllink->mtu) _set_mtu (self, pllink->mtu); _stats_update_counters_from_pllink (self, pllink); - if (_ip_iface_update (self, pllink->name)) + ip_iface = pllink->name; + + if (!ip_iface[0]) + return FALSE; + + if (!nm_streq (priv->ip_iface, ip_iface)) { + _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); + nm_device_update_dynamic_ip_setup (self); + } return G_SOURCE_REMOVE; } |