diff options
author | Pat Ruddy <pat@voltanet.io> | 2020-10-15 13:24:51 +0200 |
---|---|---|
committer | Pat Ruddy <pat@voltanet.io> | 2020-10-15 15:28:51 +0200 |
commit | 8d78eeb54b6094f65577af815971a4d5dc1e6f00 (patch) | |
tree | 48d6e9ad526ead75f25a481abe570ef27f37b2fc /lib/prefix.c | |
parent | Merge pull request #6016 from sarav511/ppend (diff) | |
download | frr-8d78eeb54b6094f65577af815971a4d5dc1e6f00.tar.xz frr-8d78eeb54b6094f65577af815971a4d5dc1e6f00.zip |
lib: align prefixevpn2str output with bgp_evpn_route2str
We have 2 different routines to turn an evpn route into a string.
This commit aligns the two to the latest maintained version as a
first step in removing one of them.
Signed-off-by: Pat Ruddy <pat@voltanet.io>
Diffstat (limited to 'lib/prefix.c')
-rw-r--r-- | lib/prefix.c | 91 |
1 files changed, 42 insertions, 49 deletions
diff --git a/lib/prefix.c b/lib/prefix.c index 0a88f9eca..78f664673 100644 --- a/lib/prefix.c +++ b/lib/prefix.c @@ -909,7 +909,14 @@ int str2prefix(const char *str, struct prefix *p) static const char *prefixevpn_ead2str(const struct prefix_evpn *p, char *str, int size) { - snprintf(str, size, "Unsupported EVPN prefix"); + char buf[ESI_STR_LEN]; + + snprintf(str, size, "[%d]:[%u]:[%s]:[%d]:[%s]", p->prefix.route_type, + p->prefix.ead_addr.eth_tag, + esi_to_str(&p->prefix.ead_addr.esi, buf, sizeof(buf)), + is_evpn_prefix_ipaddr_v4(p) ? IPV4_MAX_BITLEN + : IPV6_MAX_BITLEN, + inet_ntoa(p->prefix.ead_addr.ip.ipaddr_v4)); return str; } @@ -917,27 +924,24 @@ static const char *prefixevpn_macip2str(const struct prefix_evpn *p, char *str, int size) { uint8_t family; - char buf[PREFIX2STR_BUFFER]; - char buf2[ETHER_ADDR_STRLEN]; + char buf1[ETHER_ADDR_STRLEN]; + char buf2[PREFIX2STR_BUFFER]; if (is_evpn_prefix_ipaddr_none(p)) - snprintf(str, size, "[%d]:[%s]/%d", - p->prefix.route_type, - prefix_mac2str(&p->prefix.macip_addr.mac, - buf2, sizeof(buf2)), - p->prefixlen); + snprintf(str, size, "[%d]:[%d]:[%d]:[%s]", p->prefix.route_type, + p->prefix.macip_addr.eth_tag, 8 * ETH_ALEN, + prefix_mac2str(&p->prefix.macip_addr.mac, buf1, + sizeof(buf1))); else { - family = is_evpn_prefix_ipaddr_v4(p) - ? AF_INET - : AF_INET6; - snprintf(str, size, "[%d]:[%s]:[%s]/%d", - p->prefix.route_type, - prefix_mac2str(&p->prefix.macip_addr.mac, - buf2, sizeof(buf2)), - inet_ntop(family, - &p->prefix.macip_addr.ip.ip.addr, - buf, PREFIX2STR_BUFFER), - p->prefixlen); + family = is_evpn_prefix_ipaddr_v4(p) ? AF_INET : AF_INET6; + snprintf(str, size, "[%d]:[%d]:[%d]:[%s]:[%d]:[%s]", + p->prefix.route_type, p->prefix.macip_addr.eth_tag, + 8 * ETH_ALEN, + prefix_mac2str(&p->prefix.macip_addr.mac, buf1, + sizeof(buf1)), + family == AF_INET ? IPV4_MAX_BITLEN : IPV6_MAX_BITLEN, + inet_ntop(family, &p->prefix.macip_addr.ip.ip.addr, + buf2, PREFIX2STR_BUFFER)); } return str; } @@ -945,17 +949,12 @@ static const char *prefixevpn_macip2str(const struct prefix_evpn *p, char *str, static const char *prefixevpn_imet2str(const struct prefix_evpn *p, char *str, int size) { - uint8_t family; - char buf[PREFIX2STR_BUFFER]; + snprintf(str, size, "[%d]:[%d]:[%d]:[%s]", p->prefix.route_type, + p->prefix.imet_addr.eth_tag, + is_evpn_prefix_ipaddr_v4(p) ? IPV4_MAX_BITLEN + : IPV6_MAX_BITLEN, + inet_ntoa(p->prefix.imet_addr.ip.ipaddr_v4)); - family = is_evpn_prefix_ipaddr_v4(p) - ? AF_INET - : AF_INET6; - snprintf(str, size, "[%d]:[%s]/%d", p->prefix.route_type, - inet_ntop(family, - &p->prefix.imet_addr.ip.ip.addr, buf, - PREFIX2STR_BUFFER), - p->prefixlen); return str; } @@ -964,30 +963,24 @@ static const char *prefixevpn_es2str(const struct prefix_evpn *p, char *str, { char buf[ESI_STR_LEN]; - snprintf(str, size, "[%d]:[%s]:[%s]/%d", p->prefix.route_type, + snprintf(str, size, "[%d]:[%s]:[%d]:[%s]", p->prefix.route_type, esi_to_str(&p->prefix.es_addr.esi, buf, sizeof(buf)), - inet_ntoa(p->prefix.es_addr.ip.ipaddr_v4), - p->prefixlen); + is_evpn_prefix_ipaddr_v4(p) ? IPV4_MAX_BITLEN + : IPV6_MAX_BITLEN, + inet_ntoa(p->prefix.es_addr.ip.ipaddr_v4)); + return str; } static const char *prefixevpn_prefix2str(const struct prefix_evpn *p, char *str, int size) { - uint8_t family; - char buf[PREFIX2STR_BUFFER]; - - family = is_evpn_prefix_ipaddr_v4(p) - ? AF_INET - : AF_INET6; - snprintf(str, size, "[%d]:[%u]:[%s/%d]/%d", - p->prefix.route_type, + snprintf(str, size, "[%d]:[%d]:[%d]:[%s]", p->prefix.route_type, p->prefix.prefix_addr.eth_tag, - inet_ntop(family, - &p->prefix.prefix_addr.ip.ip.addr, buf, - PREFIX2STR_BUFFER), p->prefix.prefix_addr.ip_prefix_length, - p->prefixlen); + is_evpn_prefix_ipaddr_v4(p) + ? inet_ntoa(p->prefix.prefix_addr.ip.ipaddr_v4) + : inet6_ntoa(p->prefix.prefix_addr.ip.ipaddr_v6)); return str; } @@ -995,15 +988,15 @@ static const char *prefixevpn2str(const struct prefix_evpn *p, char *str, int size) { switch (p->prefix.route_type) { - case 1: + case BGP_EVPN_AD_ROUTE: return prefixevpn_ead2str(p, str, size); - case 2: + case BGP_EVPN_MAC_IP_ROUTE: return prefixevpn_macip2str(p, str, size); - case 3: + case BGP_EVPN_IMET_ROUTE: return prefixevpn_imet2str(p, str, size); - case 4: + case BGP_EVPN_ES_ROUTE: return prefixevpn_es2str(p, str, size); - case 5: + case BGP_EVPN_IP_PREFIX_ROUTE: return prefixevpn_prefix2str(p, str, size); default: snprintf(str, size, "Unsupported EVPN prefix"); |