bgpd, lib: few more prefixlen updated

* Cast when assigning should be to uint16_t
* Restored comment documenting strange behavior
* Further increased PREFIX_STRLEN to 80 chars

Signed-off-by: Quentin Young <qlyoung@cumulusnetworks.com>
This commit is contained in:
Quentin Young 2018-10-25 20:24:25 +00:00
parent f93eee447e
commit 61be6e94ab
3 changed files with 8 additions and 5 deletions

View File

@ -267,13 +267,13 @@ extern int bgp_build_evpn_prefix(int evpn_type, uint32_t eth_tag,
memcpy(&p_evpn_p->prefix_addr.ip.ipaddr_v4,
&src->u.prefix4,
sizeof(struct in_addr));
dst->prefixlen = (uint8_t)PREFIX_LEN_ROUTE_TYPE_5_IPV4;
dst->prefixlen = (uint16_t)PREFIX_LEN_ROUTE_TYPE_5_IPV4;
} else {
SET_IPADDR_V6(&p_evpn_p->prefix_addr.ip);
memcpy(&p_evpn_p->prefix_addr.ip.ipaddr_v6,
&src->u.prefix6,
sizeof(struct in6_addr));
dst->prefixlen = (uint8_t)PREFIX_LEN_ROUTE_TYPE_5_IPV6;
dst->prefixlen = (uint16_t)PREFIX_LEN_ROUTE_TYPE_5_IPV6;
}
} else
return -1;

View File

@ -971,6 +971,10 @@ uint8_t ip_masklen(struct in_addr netmask)
{
uint32_t tmp = ~ntohl(netmask.s_addr);
/*
* clz: count leading zeroes. sadly, the behaviour of this builtin is
* undefined for a 0 argument, even though most CPUs give 32
*/
return tmp ? __builtin_clz(tmp) : 32;
}

View File

@ -304,9 +304,8 @@ union prefixconstptr {
#define INET6_BUFSIZ 53
#endif /* INET6_BUFSIZ */
/* Maximum prefix string length (IPv6) */
/* dead:beef:dead:beef:dead:beef:dead:beef:255.255.255.255 + / + 65535 + \0 */
#define PREFIX_STRLEN 53
/* Maximum string length of the result of prefix2str */
#define PREFIX_STRLEN 80
/* Max bit/byte length of IPv4 address. */
#define IPV4_MAX_BYTELEN 4