diff options
author | Thomas Haller <thaller@redhat.com> | 2014-03-07 16:25:28 +0100 |
---|---|---|
committer | Thomas Haller <thaller@redhat.com> | 2014-05-03 01:03:06 +0200 |
commit | a4d2d71409f6733bb9344bc37b9bcb936f4dc93d (patch) | |
tree | 4577a59d105e5c7d68333728090d67cccce14809 | |
parent | 9ef23947cc8f074767bd63b984b73740766377b0 (diff) | |
download | NetworkManager-a4d2d71409f6733bb9344bc37b9bcb936f4dc93d.tar.gz |
platform: refactor ip4_address_get_all() and ip6_address_get_all()
Signed-off-by: Thomas Haller <thaller@redhat.com>
-rw-r--r-- | src/platform/nm-linux-platform.c | 35 |
1 files changed, 9 insertions, 26 deletions
diff --git a/src/platform/nm-linux-platform.c b/src/platform/nm-linux-platform.c index 46430d6cbd..b9a8c8605d 100644 --- a/src/platform/nm-linux-platform.c +++ b/src/platform/nm-linux-platform.c @@ -2900,24 +2900,13 @@ link_get_wake_on_lan (NMPlatform *platform, int ifindex) /******************************************************************/ -static int -ip_address_mark_all (NMPlatform *platform, int family, int ifindex) +static gboolean +_address_match (struct rtnl_addr *addr, int family, int ifindex) { - NMLinuxPlatformPrivate *priv = NM_LINUX_PLATFORM_GET_PRIVATE (platform); - struct nl_object *object; - int count = 0; - - for (object = nl_cache_get_first (priv->address_cache); object; object = nl_cache_get_next (object)) { - nl_object_unmark (object); - if (rtnl_addr_get_family ((struct rtnl_addr *) object) != family) - continue; - if (rtnl_addr_get_ifindex ((struct rtnl_addr *) object) != ifindex) - continue; - nl_object_mark (object); - count++; - } + g_return_val_if_fail (addr, FALSE); - return count; + return rtnl_addr_get_family (addr) == family && + rtnl_addr_get_ifindex (addr) == ifindex; } static GArray * @@ -2927,18 +2916,15 @@ ip4_address_get_all (NMPlatform *platform, int ifindex) GArray *addresses; NMPlatformIP4Address address; struct nl_object *object; - int count; - count = ip_address_mark_all (platform, AF_INET, ifindex); - addresses = g_array_sized_new (TRUE, TRUE, sizeof (NMPlatformIP4Address), count); + addresses = g_array_new (TRUE, FALSE, sizeof (NMPlatformIP4Address)); for (object = nl_cache_get_first (priv->address_cache); object; object = nl_cache_get_next (object)) { - if (nl_object_is_marked (object)) { + if (_address_match ((struct rtnl_addr *) object, AF_INET, ifindex)) { if (init_ip4_address (&address, (struct rtnl_addr *) object)) { address.source = NM_PLATFORM_SOURCE_KERNEL; g_array_append_val (addresses, address); } - nl_object_unmark (object); } } @@ -2952,18 +2938,15 @@ ip6_address_get_all (NMPlatform *platform, int ifindex) GArray *addresses; NMPlatformIP6Address address; struct nl_object *object; - int count; - count = ip_address_mark_all (platform, AF_INET6, ifindex); - addresses = g_array_sized_new (TRUE, TRUE, sizeof (NMPlatformIP6Address), count); + addresses = g_array_new (TRUE, FALSE, sizeof (NMPlatformIP6Address)); for (object = nl_cache_get_first (priv->address_cache); object; object = nl_cache_get_next (object)) { - if (nl_object_is_marked (object)) { + if (_address_match ((struct rtnl_addr *) object, AF_INET6, ifindex)) { if (init_ip6_address (&address, (struct rtnl_addr *) object)) { address.source = NM_PLATFORM_SOURCE_KERNEL; g_array_append_val (addresses, address); } - nl_object_unmark (object); } } |