summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--bgpd/bgp_evpn.c75
-rw-r--r--bgpd/bgp_evpn.h2
-rw-r--r--bgpd/bgp_evpn_vty.c24
-rw-r--r--bgpd/bgp_route.c30
-rw-r--r--lib/prefix.c37
5 files changed, 50 insertions, 118 deletions
diff --git a/bgpd/bgp_evpn.c b/bgpd/bgp_evpn.c
index 0703853354..63e29fa2c5 100644
--- a/bgpd/bgp_evpn.c
+++ b/bgpd/bgp_evpn.c
@@ -4594,81 +4594,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)
*/
void bgp_evpn_encode_prefix(struct stream *s, const struct prefix *p,
diff --git a/bgpd/bgp_evpn.h b/bgpd/bgp_evpn.h
index 8535f1fa31..ba43191ebf 100644
--- a/bgpd/bgp_evpn.h
+++ b/bgpd/bgp_evpn.h
@@ -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,
diff --git a/bgpd/bgp_evpn_vty.c b/bgpd/bgp_evpn_vty.c
index 016339ef83..2e1e9d635f 100644
--- a/bgpd/bgp_evpn_vty.c
+++ b/bgpd/bgp_evpn_vty.c
@@ -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;
diff --git a/bgpd/bgp_route.c b/bgpd/bgp_route.c
index 8977b1651a..5986f08a78 100644
--- a/bgpd/bgp_route.c
+++ b/bgpd/bgp_route.c
@@ -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)) :
diff --git a/lib/prefix.c b/lib/prefix.c
index 78f6646735..24def1bac4 100644
--- a/lib/prefix.c
+++ b/lib/prefix.c
@@ -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;
}