}
}
-/*
- * 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)
*/
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,
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();
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;
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);
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);
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;
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;
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) {
}
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);
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);
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)) :
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;
}
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;
}
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;
}
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;
}