diff options
author | Thomas Haller <thaller@redhat.com> | 2016-04-12 15:55:44 +0200 |
---|---|---|
committer | Thomas Haller <thaller@redhat.com> | 2016-04-28 12:53:21 +0200 |
commit | 5fe99a1d1a247d950fa975e7865afd096d71df4c (patch) | |
tree | cee559fbc74fe6e0fad205b9f1fa2abee5fbde05 | |
parent | 3c67a1ec5e8ef35169bba961faff6bfdfacc1cfa (diff) | |
download | NetworkManager-5fe99a1d1a247d950fa975e7865afd096d71df4c.tar.gz |
core: add nm_utils_ipx_address_clear_host_address() util
-rw-r--r-- | src/nm-core-utils.c | 21 | ||||
-rw-r--r-- | src/nm-core-utils.h | 1 | ||||
-rw-r--r-- | src/platform/nm-linux-platform.c | 19 |
3 files changed, 23 insertions, 18 deletions
diff --git a/src/nm-core-utils.c b/src/nm-core-utils.c index 90031646f1..cc15c7830d 100644 --- a/src/nm-core-utils.c +++ b/src/nm-core-utils.c @@ -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 diff --git a/src/nm-core-utils.h b/src/nm-core-utils.h index 7d9cc44b77..a7172a5b3b 100644 --- a/src/nm-core-utils.h +++ b/src/nm-core-utils.h @@ -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); diff --git a/src/platform/nm-linux-platform.c b/src/platform/nm-linux-platform.c index 118df9918d..4f32d39c35 100644 --- a/src/platform/nm-linux-platform.c +++ b/src/platform/nm-linux-platform.c @@ -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); |