]> git.puffer.fish Git - mirror/frr.git/commitdiff
bgpd: replace bgp_evpn_route2str with prefix2str 7317/head
authorPat Ruddy <pat@voltanet.io>
Thu, 15 Oct 2020 13:25:26 +0000 (14:25 +0100)
committerPat Ruddy <pat@voltanet.io>
Fri, 16 Oct 2020 10:54:30 +0000 (11:54 +0100)
Remove bgp_evpn_route2str and replace calls with prefix2str

Signed-off-by: Pat Ruddy <pat@voltanet.io>
bgpd/bgp_evpn.c
bgpd/bgp_evpn.h
bgpd/bgp_evpn_vty.c
bgpd/bgp_route.c
lib/prefix.c

index 0703853354fcdaabad4b1253576b2392f83b2c70..63e29fa2c532e1c6d8a51035e858ef0340214378 100644 (file)
@@ -4593,81 +4593,6 @@ void bgp_evpn_route2json(const struct prefix_evpn *p, json_object *json)
        }
 }
 
-/*
- * Function to convert evpn route to string.
- * NOTE: We don't use prefix2str as the output here is a bit different.
- */
-char *bgp_evpn_route2str(const struct prefix_evpn *p, char *buf, int len)
-{
-       char buf1[ETHER_ADDR_STRLEN];
-       char buf2[PREFIX2STR_BUFFER];
-       char buf3[ESI_STR_LEN];
-
-       if (p->prefix.route_type == BGP_EVPN_IMET_ROUTE) {
-               snprintf(buf, len, "[%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));
-       } else if (p->prefix.route_type == BGP_EVPN_MAC_IP_ROUTE) {
-               if (is_evpn_prefix_ipaddr_none(p))
-                       snprintf(buf, len, "[%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 {
-                       uint8_t family;
-
-                       family = is_evpn_prefix_ipaddr_v4(p) ? AF_INET
-                                                            : AF_INET6;
-                       snprintf(buf, len, "[%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));
-               }
-       } else if (p->prefix.route_type == BGP_EVPN_IP_PREFIX_ROUTE) {
-               snprintf(buf, len, "[%d]:[%d]:[%d]:[%s]",
-                        p->prefix.route_type,
-                        p->prefix.prefix_addr.eth_tag,
-                        p->prefix.prefix_addr.ip_prefix_length,
-                        is_evpn_prefix_ipaddr_v4(p)
-                                ? inet_ntoa(p->prefix.prefix_addr.ip.ipaddr_v4)
-                                : inet6_ntoa(p->prefix.prefix_addr.ip.ipaddr_v6));
-       } else if (p->prefix.route_type == BGP_EVPN_ES_ROUTE) {
-               snprintf(buf, len, "[%d]:[%s]:[%d]:[%s]",
-                        p->prefix.route_type,
-                        esi_to_str(&p->prefix.es_addr.esi, buf3, sizeof(buf3)),
-                        is_evpn_prefix_ipaddr_v4(p) ? IPV4_MAX_BITLEN
-                                                    : IPV6_MAX_BITLEN,
-                        inet_ntoa(p->prefix.es_addr.ip.ipaddr_v4));
-       } else if (p->prefix.route_type == BGP_EVPN_AD_ROUTE) {
-               snprintf(buf, len, "[%d]:[%u]:[%s]:[%d]:[%s]",
-                        p->prefix.route_type,
-                        p->prefix.ead_addr.eth_tag,
-                        esi_to_str(&p->prefix.ead_addr.esi,
-                                       buf3, sizeof(buf3)),
-                        is_evpn_prefix_ipaddr_v4(p) ? IPV4_MAX_BITLEN
-                                                    : IPV6_MAX_BITLEN,
-                        inet_ntoa(p->prefix.ead_addr.ip.ipaddr_v4));
-       } else {
-               /* For EVPN route types not supported yet. */
-               snprintf(buf, len, "(unsupported route type %d)",
-                        p->prefix.route_type);
-       }
-
-       return (buf);
-}
-
 /*
  * Encode EVPN prefix in Update (MP_REACH)
  */
index 8535f1fa31e195adc3c2ffcb023f1cd8ed632e91..ba43191ebf356fdb55040f8a31e606c3aa27c178 100644 (file)
@@ -154,8 +154,6 @@ extern void bgp_evpn_vrf_delete(struct bgp *bgp_vrf);
 extern void bgp_evpn_handle_router_id_update(struct bgp *bgp, int withdraw);
 extern char *bgp_evpn_label2str(mpls_label_t *label, uint32_t num_labels,
                                char *buf, int len);
-extern char *bgp_evpn_route2str(const struct prefix_evpn *p, char *buf,
-                               int len);
 extern void bgp_evpn_route2json(const struct prefix_evpn *p, json_object *json);
 extern void bgp_evpn_encode_prefix(struct stream *s, const struct prefix *p,
                                   const struct prefix_rd *prd,
index 016339ef835888c2fe4ec0ee583d380352cc353e..2e1e9d635f8e12828954cf570225810866be33dc 100644 (file)
@@ -611,8 +611,8 @@ static void show_esi_routes(struct bgp *bgp,
                json_object *json_prefix = NULL;
                const struct prefix *p = bgp_dest_get_prefix(dest);
 
-               bgp_evpn_route2str((struct prefix_evpn *)p, prefix_str,
-                                  sizeof(prefix_str));
+               prefix2str((struct prefix_evpn *)p, prefix_str,
+                          sizeof(prefix_str));
 
                if (json)
                        json_prefix = json_object_new_object();
@@ -706,9 +706,8 @@ static void show_vni_routes(struct bgp *bgp, struct bgpevpn *vpn, int type,
                json_object *json_prefix = NULL;
                const struct prefix *p = bgp_dest_get_prefix(dest);
 
-               bgp_evpn_route2str(
-                       (struct prefix_evpn *)bgp_dest_get_prefix(dest),
-                       prefix_str, sizeof(prefix_str));
+               prefix2str((struct prefix_evpn *)bgp_dest_get_prefix(dest),
+                          prefix_str, sizeof(prefix_str));
 
                if (type && evp->prefix.route_type != type)
                        continue;
@@ -1250,9 +1249,8 @@ static int bgp_show_ethernet_vpn(struct vty *vty, struct prefix_rd *prd,
 
                                json_object_string_add(
                                        json_prefix_info, "prefix",
-                                       bgp_evpn_route2str(
-                                               (struct prefix_evpn *)p, buf,
-                                               BUFSIZ));
+                                       prefix2str((struct prefix_evpn *)p, buf,
+                                                  BUFSIZ));
 
                                json_object_int_add(json_prefix_info,
                                                    "prefixLen", p->prefixlen);
@@ -2441,7 +2439,7 @@ static void evpn_show_route_rd_macip(struct vty *vty, struct bgp *bgp,
                return;
        }
 
-       bgp_evpn_route2str(&p, prefix_str, sizeof(prefix_str));
+       prefix2str(&p, prefix_str, sizeof(prefix_str));
 
        /* Prefix and num paths displayed once per prefix. */
        route_vty_out_detail_header(vty, bgp, dest, prd, afi, safi, json);
@@ -2522,8 +2520,8 @@ static void evpn_show_route_rd(struct vty *vty, struct bgp *bgp,
                char prefix_str[BUFSIZ];
                int add_prefix_to_json = 0;
 
-               bgp_evpn_route2str((struct prefix_evpn *)evp, prefix_str,
-                                  sizeof(prefix_str));
+               prefix2str((struct prefix_evpn *)evp, prefix_str,
+                          sizeof(prefix_str));
 
                if (type && evp->prefix.route_type != type)
                        continue;
@@ -2668,8 +2666,8 @@ static void evpn_show_all_routes(struct vty *vty, struct bgp *bgp, int type,
                        int add_prefix_to_json = 0;
                        const struct prefix *p = bgp_dest_get_prefix(dest);
 
-                       bgp_evpn_route2str((struct prefix_evpn *)p, prefix_str,
-                                          sizeof(prefix_str));
+                       prefix2str((struct prefix_evpn *)p, prefix_str,
+                                  sizeof(prefix_str));
 
                        if (type && evp->prefix.route_type != type)
                                continue;
index 8977b1651a6a121c936340a6645e25a30a99c5aa..5986f08a78292df3301b62ce5b878150c8cfc9d7 100644 (file)
@@ -7628,10 +7628,9 @@ static void route_vty_out_route(const struct prefix *p, struct vty *vty,
                len = vty_out(vty, "%s", buf);
        } else if (p->family == AF_EVPN) {
                if (!json)
-                       len = vty_out(
-                               vty, "%s",
-                               bgp_evpn_route2str((struct prefix_evpn *)p, buf,
-                                                  BUFSIZ));
+                       len = vty_out(vty, "%s",
+                                     prefix2str((struct prefix_evpn *)p, buf,
+                                                BUFSIZ));
                else
                        bgp_evpn_route2json((struct prefix_evpn *)p, json);
        } else if (p->family == AF_FLOWSPEC) {
@@ -8985,10 +8984,9 @@ void route_vty_out_detail(struct vty *vty, struct bgp *bgp,
                }
                if (safi == SAFI_EVPN) {
                        if (!json_paths) {
-                               bgp_evpn_route2str(
-                                       (struct prefix_evpn *)
-                                               bgp_dest_get_prefix(bn),
-                                       buf2, sizeof(buf2));
+                               prefix2str((struct prefix_evpn *)
+                                                  bgp_dest_get_prefix(bn),
+                                          buf2, sizeof(buf2));
                                vty_out(vty, "  Route %s", buf2);
                                if (tag_buf[0] != '\0')
                                        vty_out(vty, " VNI %s", tag_buf);
@@ -9013,11 +9011,10 @@ void route_vty_out_detail(struct vty *vty, struct bgp *bgp,
                                                pdest),
                                        buf1, sizeof(buf1));
                                if (is_pi_family_evpn(parent_ri)) {
-                                       bgp_evpn_route2str(
-                                               (struct prefix_evpn *)
-                                                       bgp_dest_get_prefix(
-                                                               dest),
-                                               buf2, sizeof(buf2));
+                                       prefix2str((struct prefix_evpn *)
+                                                          bgp_dest_get_prefix(
+                                                                  dest),
+                                                  buf2, sizeof(buf2));
                                        vty_out(vty, "  Imported from %s:%s, VNI %s\n", buf1, buf2, tag_buf);
                                } else
                                        vty_out(vty, "  Imported from %s:%s\n", buf1, buf2);
@@ -10369,9 +10366,10 @@ void route_vty_out_detail_header(struct vty *vty, struct bgp *bgp,
                if (!json) {
                        vty_out(vty, "BGP routing table entry for %s%s%s\n",
                                prd ? prefix_rd2str(prd, buf1, sizeof(buf1))
-                               : "", prd ? ":" : "",
-                               bgp_evpn_route2str((struct prefix_evpn *)p,
-                               buf3, sizeof(buf3)));
+                                   : "",
+                               prd ? ":" : "",
+                               prefix2str((struct prefix_evpn *)p, buf3,
+                                          sizeof(buf3)));
                } else {
                        json_object_string_add(json, "rd",
                                prd ? prefix_rd2str(prd, buf1, sizeof(buf1)) :
index 78f66467355cf68d40f7a679e4b12afd2ff2c007..24def1bac4dc41894a67a9933f6840435106a8a4 100644 (file)
@@ -909,14 +909,17 @@ int str2prefix(const char *str, struct prefix *p)
 static const char *prefixevpn_ead2str(const struct prefix_evpn *p, char *str,
                                      int size)
 {
+       uint8_t family;
        char buf[ESI_STR_LEN];
+       char buf1[INET6_ADDRSTRLEN];
 
+       family = IS_IPADDR_V4(&p->prefix.ead_addr.ip) ? AF_INET : AF_INET6;
        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));
+                (family == AF_INET) ? IPV4_MAX_BITLEN : IPV6_MAX_BITLEN,
+                inet_ntop(family, &p->prefix.ead_addr.ip.ipaddr_v4, buf1,
+                          sizeof(buf1)));
        return str;
 }
 
@@ -949,11 +952,15 @@ 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[INET6_ADDRSTRLEN];
+
+       family = IS_IPADDR_V4(&p->prefix.imet_addr.ip) ? AF_INET : AF_INET6;
        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 == AF_INET) ? IPV4_MAX_BITLEN : IPV6_MAX_BITLEN,
+                inet_ntop(family, &p->prefix.imet_addr.ip.ipaddr_v4, buf,
+                          sizeof(buf)));
 
        return str;
 }
@@ -961,13 +968,16 @@ static const char *prefixevpn_imet2str(const struct prefix_evpn *p, char *str,
 static const char *prefixevpn_es2str(const struct prefix_evpn *p, char *str,
                                     int size)
 {
+       uint8_t family;
        char buf[ESI_STR_LEN];
+       char buf1[INET6_ADDRSTRLEN];
 
+       family = IS_IPADDR_V4(&p->prefix.es_addr.ip) ? AF_INET : AF_INET6;
        snprintf(str, size, "[%d]:[%s]:[%d]:[%s]", p->prefix.route_type,
                 esi_to_str(&p->prefix.es_addr.esi, buf, sizeof(buf)),
-                is_evpn_prefix_ipaddr_v4(p) ? IPV4_MAX_BITLEN
-                                            : IPV6_MAX_BITLEN,
-                inet_ntoa(p->prefix.es_addr.ip.ipaddr_v4));
+                (family == AF_INET) ? IPV4_MAX_BITLEN : IPV6_MAX_BITLEN,
+                inet_ntop(family, &p->prefix.es_addr.ip.ipaddr_v4, buf1,
+                          sizeof(buf1)));
 
        return str;
 }
@@ -975,12 +985,15 @@ static const char *prefixevpn_es2str(const struct prefix_evpn *p, char *str,
 static const char *prefixevpn_prefix2str(const struct prefix_evpn *p, char *str,
                                         int size)
 {
+       uint8_t family;
+       char buf[INET6_ADDRSTRLEN];
+
+       family = IS_IPADDR_V4(&p->prefix.prefix_addr.ip) ? AF_INET : AF_INET6;
        snprintf(str, size, "[%d]:[%d]:[%d]:[%s]", p->prefix.route_type,
                 p->prefix.prefix_addr.eth_tag,
                 p->prefix.prefix_addr.ip_prefix_length,
-                is_evpn_prefix_ipaddr_v4(p)
-                        ? inet_ntoa(p->prefix.prefix_addr.ip.ipaddr_v4)
-                        : inet6_ntoa(p->prefix.prefix_addr.ip.ipaddr_v6));
+                inet_ntop(family, &p->prefix.prefix_addr.ip.ipaddr_v4, buf,
+                          sizeof(buf)));
        return str;
 }