core: add nm_utils_ipx_address_clear_host_address() util

This commit is contained in:
Thomas Haller
2016-04-12 15:55:44 +02:00
parent 3c67a1ec5e
commit 5fe99a1d1a
3 changed files with 23 additions and 18 deletions

View File

@@ -199,6 +199,27 @@ nm_ethernet_address_is_valid (gconstpointer addr, gssize len)
return TRUE;
}
gconstpointer
nm_utils_ipx_address_clear_host_address (int family, gpointer dst, gconstpointer src, guint8 plen)
{
g_return_val_if_fail (src, NULL);
g_return_val_if_fail (dst, NULL);
switch (family) {
case AF_INET:
g_return_val_if_fail (plen <= 32, NULL);
*((guint32 *) dst) = nm_utils_ip4_address_clear_host_address (*((guint32 *) src), plen);
break;
case AF_INET6:
g_return_val_if_fail (plen <= 128, NULL);
nm_utils_ip6_address_clear_host_address (dst, src, plen);
break;
default:
g_return_val_if_reached (NULL);
}
return dst;
}
/* nm_utils_ip4_address_clear_host_address:
* @addr: source ip6 address
* @plen: prefix length of network

View File

@@ -93,6 +93,7 @@ GETTER (void) \
gboolean nm_ethernet_address_is_valid (gconstpointer addr, gssize len);
gconstpointer nm_utils_ipx_address_clear_host_address (int family, gpointer dst, gconstpointer src, guint8 plen);
in_addr_t nm_utils_ip4_address_clear_host_address (in_addr_t addr, guint8 plen);
const struct in6_addr *nm_utils_ip6_address_clear_host_address (struct in6_addr *dst, const struct in6_addr *src, guint8 plen);
gboolean nm_utils_ip6_address_same_prefix (const struct in6_addr *addr_a, const struct in6_addr *addr_b, guint8 plen);

View File

@@ -308,23 +308,6 @@ _support_user_ipv6ll_detect (struct nlattr **tb)
* Various utilities
******************************************************************/
static void
clear_host_address (int family, const void *network, guint8 plen, void *dst)
{
g_return_if_fail (network);
switch (family) {
case AF_INET:
*((in_addr_t *) dst) = nm_utils_ip4_address_clear_host_address (*((in_addr_t *) network), plen);
break;
case AF_INET6:
nm_utils_ip6_address_clear_host_address ((struct in6_addr *) dst, (const struct in6_addr *) network, plen);
break;
default:
g_assert_not_reached ();
}
}
static int
_vlan_qos_mapping_cmp_from (gconstpointer a, gconstpointer b, gpointer user_data)
{
@@ -2285,7 +2268,7 @@ _nl_msg_new_route (int nlmsg_type,
addr_len = family == AF_INET ? sizeof (in_addr_t) : sizeof (struct in6_addr);
clear_host_address (family, network, plen, &network_clean);
nm_utils_ipx_address_clear_host_address (family, &network_clean, network, plen);
NLA_PUT (msg, RTA_DST, addr_len, &network_clean);
NLA_PUT_U32 (msg, RTA_PRIORITY, metric);