platform: refactor ip4_address_get_all() and ip6_address_get_all()
Signed-off-by: Thomas Haller <thaller@redhat.com>
This commit is contained in:
@@ -2900,24 +2900,13 @@ link_get_wake_on_lan (NMPlatform *platform, int ifindex)
|
|||||||
|
|
||||||
/******************************************************************/
|
/******************************************************************/
|
||||||
|
|
||||||
static int
|
static gboolean
|
||||||
ip_address_mark_all (NMPlatform *platform, int family, int ifindex)
|
_address_match (struct rtnl_addr *addr, int family, int ifindex)
|
||||||
{
|
{
|
||||||
NMLinuxPlatformPrivate *priv = NM_LINUX_PLATFORM_GET_PRIVATE (platform);
|
g_return_val_if_fail (addr, FALSE);
|
||||||
struct nl_object *object;
|
|
||||||
int count = 0;
|
|
||||||
|
|
||||||
for (object = nl_cache_get_first (priv->address_cache); object; object = nl_cache_get_next (object)) {
|
return rtnl_addr_get_family (addr) == family &&
|
||||||
nl_object_unmark (object);
|
rtnl_addr_get_ifindex (addr) == ifindex;
|
||||||
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++;
|
|
||||||
}
|
|
||||||
|
|
||||||
return count;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static GArray *
|
static GArray *
|
||||||
@@ -2927,18 +2916,15 @@ ip4_address_get_all (NMPlatform *platform, int ifindex)
|
|||||||
GArray *addresses;
|
GArray *addresses;
|
||||||
NMPlatformIP4Address address;
|
NMPlatformIP4Address address;
|
||||||
struct nl_object *object;
|
struct nl_object *object;
|
||||||
int count;
|
|
||||||
|
|
||||||
count = ip_address_mark_all (platform, AF_INET, ifindex);
|
addresses = g_array_new (TRUE, FALSE, sizeof (NMPlatformIP4Address));
|
||||||
addresses = g_array_sized_new (TRUE, TRUE, sizeof (NMPlatformIP4Address), count);
|
|
||||||
|
|
||||||
for (object = nl_cache_get_first (priv->address_cache); object; object = nl_cache_get_next (object)) {
|
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)) {
|
if (init_ip4_address (&address, (struct rtnl_addr *) object)) {
|
||||||
address.source = NM_PLATFORM_SOURCE_KERNEL;
|
address.source = NM_PLATFORM_SOURCE_KERNEL;
|
||||||
g_array_append_val (addresses, address);
|
g_array_append_val (addresses, address);
|
||||||
}
|
}
|
||||||
nl_object_unmark (object);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -2952,18 +2938,15 @@ ip6_address_get_all (NMPlatform *platform, int ifindex)
|
|||||||
GArray *addresses;
|
GArray *addresses;
|
||||||
NMPlatformIP6Address address;
|
NMPlatformIP6Address address;
|
||||||
struct nl_object *object;
|
struct nl_object *object;
|
||||||
int count;
|
|
||||||
|
|
||||||
count = ip_address_mark_all (platform, AF_INET6, ifindex);
|
addresses = g_array_new (TRUE, FALSE, sizeof (NMPlatformIP6Address));
|
||||||
addresses = g_array_sized_new (TRUE, TRUE, sizeof (NMPlatformIP6Address), count);
|
|
||||||
|
|
||||||
for (object = nl_cache_get_first (priv->address_cache); object; object = nl_cache_get_next (object)) {
|
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)) {
|
if (init_ip6_address (&address, (struct rtnl_addr *) object)) {
|
||||||
address.source = NM_PLATFORM_SOURCE_KERNEL;
|
address.source = NM_PLATFORM_SOURCE_KERNEL;
|
||||||
g_array_append_val (addresses, address);
|
g_array_append_val (addresses, address);
|
||||||
}
|
}
|
||||||
nl_object_unmark (object);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user