mirror of
https://git.proxmox.com/git/mirror_frr
synced 2025-08-08 10:56:37 +00:00
lib: use prefix bit length macros
This commit is contained in:
parent
ce3cdcfbed
commit
9ed79b53eb
14
lib/prefix.c
14
lib/prefix.c
@ -2460,8 +2460,8 @@ prefix_cmp (const struct prefix *p1, const struct prefix *p2)
|
|||||||
if (p1->family != p2->family || p1->prefixlen != p2->prefixlen)
|
if (p1->family != p2->family || p1->prefixlen != p2->prefixlen)
|
||||||
return 1;
|
return 1;
|
||||||
|
|
||||||
offset = p1->prefixlen / 8;
|
offset = p1->prefixlen / PNBBY;
|
||||||
shift = p1->prefixlen % 8;
|
shift = p1->prefixlen % PNBBY;
|
||||||
|
|
||||||
if (shift)
|
if (shift)
|
||||||
if (maskbit[shift] & (pp1[offset] ^ pp2[offset]))
|
if (maskbit[shift] & (pp1[offset] ^ pp2[offset]))
|
||||||
@ -2598,7 +2598,7 @@ str2prefix_ipv4 (const char *str, struct prefix_ipv4 *p)
|
|||||||
void
|
void
|
||||||
masklen2ip (const int masklen, struct in_addr *netmask)
|
masklen2ip (const int masklen, struct in_addr *netmask)
|
||||||
{
|
{
|
||||||
assert (masklen >= 0 && masklen <= 32);
|
assert (masklen >= 0 && masklen <= IPV4_MAX_BITLEN);
|
||||||
netmask->s_addr = maskbytes_network[masklen];
|
netmask->s_addr = maskbytes_network[masklen];
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -2683,7 +2683,7 @@ str2prefix_ipv6 (const char *str, struct prefix_ipv6 *p)
|
|||||||
if (ret == 0)
|
if (ret == 0)
|
||||||
return 0;
|
return 0;
|
||||||
plen = (u_char) atoi (++pnt);
|
plen = (u_char) atoi (++pnt);
|
||||||
if (plen > 128)
|
if (plen > IPV6_MAX_BITLEN)
|
||||||
return 0;
|
return 0;
|
||||||
p->prefixlen = plen;
|
p->prefixlen = plen;
|
||||||
}
|
}
|
||||||
@ -2703,13 +2703,13 @@ ip6_masklen (struct in6_addr netmask)
|
|||||||
|
|
||||||
pnt = (unsigned char *) & netmask;
|
pnt = (unsigned char *) & netmask;
|
||||||
|
|
||||||
while ((*pnt == 0xff) && len < 128)
|
while ((*pnt == 0xff) && len < IPV6_MAX_BITLEN)
|
||||||
{
|
{
|
||||||
len += 8;
|
len += 8;
|
||||||
pnt++;
|
pnt++;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (len < 128)
|
if (len < IPV6_MAX_BITLEN)
|
||||||
{
|
{
|
||||||
val = *pnt;
|
val = *pnt;
|
||||||
while (val)
|
while (val)
|
||||||
@ -2724,7 +2724,7 @@ ip6_masklen (struct in6_addr netmask)
|
|||||||
void
|
void
|
||||||
masklen2ip6 (const int masklen, struct in6_addr *netmask)
|
masklen2ip6 (const int masklen, struct in6_addr *netmask)
|
||||||
{
|
{
|
||||||
assert (masklen >=0 && masklen <= 128);
|
assert (masklen >= 0 && masklen <= IPV6_MAX_BITLEN);
|
||||||
memcpy (netmask, maskbytes6 + masklen, sizeof (struct in6_addr));
|
memcpy (netmask, maskbytes6 + masklen, sizeof (struct in6_addr));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user