mirror of
https://gitlab.freedesktop.org/NetworkManager/NetworkManager.git
synced 2026-02-27 11:40:36 +01:00
glib-aux: add assertions for valid prefix length
(cherry picked from commit9ce4a16523) (cherry picked from commit0180a9fca5)
This commit is contained in:
parent
2e6d70e51f
commit
b7a5d41ffe
3 changed files with 4 additions and 7 deletions
|
|
@ -6320,9 +6320,10 @@ nm_utils_ip6_address_same_prefix_cmp(const struct in6_addr *addr_a,
|
|||
int nbytes;
|
||||
guint8 va, vb, m;
|
||||
|
||||
if (plen >= 128)
|
||||
if (plen >= 128) {
|
||||
nm_assert(plen == 128);
|
||||
NM_CMP_DIRECT_MEMCMP(addr_a, addr_b, sizeof(struct in6_addr));
|
||||
else {
|
||||
} else {
|
||||
nbytes = plen / 8;
|
||||
if (nbytes)
|
||||
NM_CMP_DIRECT_MEMCMP(addr_a, addr_b, nbytes);
|
||||
|
|
|
|||
|
|
@ -398,6 +398,7 @@ gboolean nm_utils_get_ipv6_interface_identifier(NMLinkType link_type,
|
|||
static inline in_addr_t
|
||||
_nm_utils_ip4_prefix_to_netmask(guint32 prefix)
|
||||
{
|
||||
nm_assert(prefix <= 32);
|
||||
return prefix < 32 ? ~htonl(0xFFFFFFFFu >> prefix) : 0xFFFFFFFFu;
|
||||
}
|
||||
|
||||
|
|
@ -455,8 +456,6 @@ nm_utils_ip_address_same_prefix_cmp(int addr_family,
|
|||
gconstpointer addr_b,
|
||||
guint8 plen)
|
||||
{
|
||||
nm_assert_addr_family(addr_family);
|
||||
|
||||
NM_CMP_SELF(addr_a, addr_b);
|
||||
|
||||
if (NM_IS_IPv4(addr_family)) {
|
||||
|
|
|
|||
|
|
@ -283,9 +283,6 @@ test_nm_utils_ip4_prefix_to_netmask(void)
|
|||
g_assert_cmpint(_nm_utils_ip4_prefix_to_netmask(32),
|
||||
==,
|
||||
nmtst_inet4_from_string("255.255.255.255"));
|
||||
g_assert_cmpint(_nm_utils_ip4_prefix_to_netmask(33),
|
||||
==,
|
||||
nmtst_inet4_from_string("255.255.255.255"));
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue