]> git.puffer.fish Git - mirror/frr.git/commitdiff
lib: align prefixevpn2str output with bgp_evpn_route2str
authorPat Ruddy <pat@voltanet.io>
Thu, 15 Oct 2020 11:24:51 +0000 (12:24 +0100)
committerPat Ruddy <pat@voltanet.io>
Thu, 15 Oct 2020 13:28:51 +0000 (14:28 +0100)
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>
lib/prefix.c

index 0a88f9eca6892590bf330b2aceeb505e47113f59..78f66467355cf68d40f7a679e4b12afd2ff2c007 100644 (file)
@@ -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");