bgpd, zebra: encode ip addr len as uint16

This is always a 16 bit unsigned value.

- signed int is the wrong type to use
- encoding a signed int as a uint32 is bad practice
- decoding a signed int encoded as a uint32 into a uint16 is bad
  practice

Signed-off-by: Quentin Young <qlyoung@nvidia.com>
This commit is contained in:
Quentin Young 2020-09-23 15:31:52 -04:00
parent d8c3daca19
commit 0ffd0fb536
2 changed files with 4 additions and 4 deletions

View File

@ -586,7 +586,7 @@ static int bgp_zebra_send_remote_macip(struct bgp *bgp, struct bgpevpn *vpn,
uint8_t flags, uint32_t seq, esi_t *esi) uint8_t flags, uint32_t seq, esi_t *esi)
{ {
struct stream *s; struct stream *s;
int ipa_len; uint16_t ipa_len;
static struct in_addr zero_remote_vtep_ip; static struct in_addr zero_remote_vtep_ip;
/* Check socket. */ /* Check socket. */
@ -614,11 +614,11 @@ static int bgp_zebra_send_remote_macip(struct bgp *bgp, struct bgpevpn *vpn,
stream_put(s, &p->prefix.macip_addr.mac.octet, ETH_ALEN); /* Mac Addr */ stream_put(s, &p->prefix.macip_addr.mac.octet, ETH_ALEN); /* Mac Addr */
/* IP address length and IP address, if any. */ /* IP address length and IP address, if any. */
if (is_evpn_prefix_ipaddr_none(p)) if (is_evpn_prefix_ipaddr_none(p))
stream_putl(s, 0); stream_putw(s, 0);
else { else {
ipa_len = is_evpn_prefix_ipaddr_v4(p) ? IPV4_MAX_BYTELEN ipa_len = is_evpn_prefix_ipaddr_v4(p) ? IPV4_MAX_BYTELEN
: IPV6_MAX_BYTELEN; : IPV6_MAX_BYTELEN;
stream_putl(s, ipa_len); stream_putw(s, ipa_len);
stream_put(s, &p->prefix.macip_addr.ip.ip.addr, ipa_len); stream_put(s, &p->prefix.macip_addr.ip.ip.addr, ipa_len);
} }
/* If the ESI is valid that becomes the nexthop; tape out the /* If the ESI is valid that becomes the nexthop; tape out the

View File

@ -3749,7 +3749,7 @@ zebra_vxlan_remote_macip_helper(bool add, struct stream *s, vni_t *vni,
memset(ip, 0, sizeof(*ip)); memset(ip, 0, sizeof(*ip));
STREAM_GETL(s, *vni); STREAM_GETL(s, *vni);
STREAM_GET(macaddr->octet, s, ETH_ALEN); STREAM_GET(macaddr->octet, s, ETH_ALEN);
STREAM_GETL(s, *ipa_len); STREAM_GETW(s, *ipa_len);
if (*ipa_len) { if (*ipa_len) {
if (*ipa_len == IPV4_MAX_BYTELEN) if (*ipa_len == IPV4_MAX_BYTELEN)