mirror of
https://git.proxmox.com/git/mirror_frr
synced 2025-08-08 12:49:18 +00:00
lib: optimize apply_mask_ipv4()
This commit is contained in:
parent
3062d2dab6
commit
ed7a62efea
21
lib/prefix.c
21
lib/prefix.c
@ -545,27 +545,12 @@ ip_masklen (struct in_addr netmask)
|
|||||||
return len;
|
return len;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Apply mask to IPv4 prefix. */
|
/* Apply mask to IPv4 prefix (network byte order). */
|
||||||
void
|
void
|
||||||
apply_mask_ipv4 (struct prefix_ipv4 *p)
|
apply_mask_ipv4 (struct prefix_ipv4 *p)
|
||||||
{
|
{
|
||||||
u_char *pnt;
|
assert (p->prefixlen >= 0 && p->prefixlen <= IPV4_MAX_BITLEN);
|
||||||
int index;
|
p->prefix.s_addr &= maskbytes_network[p->prefixlen];
|
||||||
int offset;
|
|
||||||
|
|
||||||
index = p->prefixlen / 8;
|
|
||||||
|
|
||||||
if (index < 4)
|
|
||||||
{
|
|
||||||
pnt = (u_char *) &p->prefix;
|
|
||||||
offset = p->prefixlen % 8;
|
|
||||||
|
|
||||||
pnt[index] &= maskbit[offset];
|
|
||||||
index++;
|
|
||||||
|
|
||||||
while (index < 4)
|
|
||||||
pnt[index++] = 0;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* If prefix is 0.0.0.0/0 then return 1 else return 0. */
|
/* If prefix is 0.0.0.0/0 then return 1 else return 0. */
|
||||||
|
Loading…
Reference in New Issue
Block a user