From 990a050affe44fb6498b7ba2762751147cf10d4d Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Mon, 14 Aug 2017 18:13:10 +0200 Subject: [PATCH] platform: cleanup and renaming of nm_platform_address_flush() function Rename to nm_platform_ip_address_flush(), it's more consistent with naming for other platform functions. Also, pass an address family argument. Sometimes I feel an option makes it clearer what the function does. Otherwise, from the name it's not clear which address families are affected. As an API, it feels more correct to me. We soon also get a nm_platform_ip_route_flush() function, which will look similar. --- src/devices/nm-device.c | 2 +- src/devices/wwan/nm-modem.c | 2 +- src/platform/nm-platform.c | 17 ++++++++++++++--- src/platform/nm-platform.h | 4 +++- src/vpn/nm-vpn-connection.c | 2 +- 5 files changed, 20 insertions(+), 7 deletions(-) diff --git a/src/devices/nm-device.c b/src/devices/nm-device.c index 006d4e9227..29b20f790a 100644 --- a/src/devices/nm-device.c +++ b/src/devices/nm-device.c @@ -12202,7 +12202,7 @@ nm_device_cleanup (NMDevice *self, NMDeviceStateReason reason, CleanupType clean ifindex = nm_device_get_ip_ifindex (self); if (ifindex > 0) { nm_route_manager_route_flush (nm_netns_get_route_manager (priv->netns), ifindex); - nm_platform_address_flush (nm_device_get_platform (self), ifindex); + nm_platform_ip_address_flush (nm_device_get_platform (self), AF_UNSPEC, ifindex); } } diff --git a/src/devices/wwan/nm-modem.c b/src/devices/wwan/nm-modem.c index 76df89e58b..b6bcc25fbb 100644 --- a/src/devices/wwan/nm-modem.c +++ b/src/devices/wwan/nm-modem.c @@ -1068,7 +1068,7 @@ deactivate_cleanup (NMModem *self, NMDevice *device) if (ifindex > 0) { nm_route_manager_route_flush (nm_netns_get_route_manager (nm_device_get_netns (device)), ifindex); - nm_platform_address_flush (nm_device_get_platform (device), ifindex); + nm_platform_ip_address_flush (nm_device_get_platform (device), AF_UNSPEC, ifindex); nm_platform_link_set_down (nm_device_get_platform (device), ifindex); } } diff --git a/src/platform/nm-platform.c b/src/platform/nm-platform.c index ba325ca883..705e54fa5e 100644 --- a/src/platform/nm-platform.c +++ b/src/platform/nm-platform.c @@ -3461,12 +3461,23 @@ nm_platform_ip6_address_sync (NMPlatform *self, } gboolean -nm_platform_address_flush (NMPlatform *self, int ifindex) +nm_platform_ip_address_flush (NMPlatform *self, + int addr_family, + int ifindex) { + gboolean success = TRUE; + _CHECK_SELF (self, klass, FALSE); - return nm_platform_ip4_address_sync (self, ifindex, NULL) - && nm_platform_ip6_address_sync (self, ifindex, NULL, FALSE); + nm_assert (NM_IN_SET (addr_family, AF_UNSPEC, + AF_INET, + AF_INET6)); + + if (NM_IN_SET (addr_family, AF_UNSPEC, AF_INET)) + success &= nm_platform_ip4_address_sync (self, ifindex, NULL); + if (NM_IN_SET (addr_family, AF_UNSPEC, AF_INET6)) + success &= nm_platform_ip6_address_sync (self, ifindex, NULL, FALSE); + return success; } /*****************************************************************************/ diff --git a/src/platform/nm-platform.h b/src/platform/nm-platform.h index 6e45b9c09a..ce5b56a6a9 100644 --- a/src/platform/nm-platform.h +++ b/src/platform/nm-platform.h @@ -1113,7 +1113,9 @@ gboolean nm_platform_ip4_address_delete (NMPlatform *self, int ifindex, in_addr_ gboolean nm_platform_ip6_address_delete (NMPlatform *self, int ifindex, struct in6_addr address, guint8 plen); gboolean nm_platform_ip4_address_sync (NMPlatform *self, int ifindex, GPtrArray *known_addresse); gboolean nm_platform_ip6_address_sync (NMPlatform *self, int ifindex, const GPtrArray *known_addresses, gboolean keep_link_local); -gboolean nm_platform_address_flush (NMPlatform *self, int ifindex); +gboolean nm_platform_ip_address_flush (NMPlatform *self, + int addr_family, + int ifindex); gboolean nm_platform_ip_route_add (NMPlatform *self, NMPNlmFlags flags, diff --git a/src/vpn/nm-vpn-connection.c b/src/vpn/nm-vpn-connection.c index 63692cffbc..912df081e4 100644 --- a/src/vpn/nm-vpn-connection.c +++ b/src/vpn/nm-vpn-connection.c @@ -396,7 +396,7 @@ vpn_cleanup (NMVpnConnection *self, NMDevice *parent_dev) if (priv->ip_ifindex) { nm_platform_link_set_down (nm_netns_get_platform (priv->netns), priv->ip_ifindex); nm_route_manager_route_flush (nm_netns_get_route_manager (priv->netns), priv->ip_ifindex); - nm_platform_address_flush (nm_netns_get_platform (priv->netns), priv->ip_ifindex); + nm_platform_ip_address_flush (nm_netns_get_platform (priv->netns), AF_UNSPEC, priv->ip_ifindex); } remove_parent_device_config (self, parent_dev);