The prefix_rd2str uses a buffer size of RD_ADDRSTRLEN.
Modify the code to consistently use this for all of BGP.
Signed-off-by: Donald Sharp <sharpd@cumulusnetworks.com>
static void display_vni(struct vty *vty, struct bgpevpn *vpn, json_object *json)
{
- char buf1[INET6_ADDRSTRLEN];
+ char buf1[RD_ADDRSTRLEN];
char *ecom_str;
struct listnode *node, *nnode;
struct ecommunity *ecom;
is_vni_live(vpn) ? "Yes" : "No");
json_object_string_add(
json, "rd",
- prefix_rd2str(&vpn->prd, buf1, RD_ADDRSTRLEN));
+ prefix_rd2str(&vpn->prd, buf1, sizeof(buf1)));
json_object_string_add(json, "originatorIp",
inet_ntoa(vpn->originator_ip));
json_object_string_add(json, "advertiseGatewayMacip",
vty_out(vty, "\n");
vty_out(vty, " RD: %s\n",
- prefix_rd2str(&vpn->prd, buf1, RD_ADDRSTRLEN));
+ prefix_rd2str(&vpn->prd, buf1, sizeof(buf1)));
vty_out(vty, " Originator IP: %s\n",
inet_ntoa(vpn->originator_ip));
vty_out(vty, " Advertise-gw-macip : %s\n",
json_object *json_export_rtl;
struct bgpevpn *vpn = (struct bgpevpn *)backet->data;
char buf1[10];
- char buf2[INET6_ADDRSTRLEN];
+ char buf2[RD_ADDRSTRLEN];
char rt_buf[25];
char *ecom_str;
struct listnode *node, *nnode;
inet_ntoa(vpn->originator_ip));
json_object_string_add(
json_vni, "rd",
- prefix_rd2str(&vpn->prd, buf2, RD_ADDRSTRLEN));
+ prefix_rd2str(&vpn->prd, buf2, sizeof(buf2)));
} else {
vty_out(vty, "%-1s %-10u %-15s %-21s", buf1, vpn->vni,
inet_ntoa(vpn->originator_ip),
- prefix_rd2str(&vpn->prd, buf2, RD_ADDRSTRLEN));
+ prefix_rd2str(&vpn->prd, buf2, sizeof(buf2)));
}
for (ALL_LIST_ELEMENTS(vpn->import_rtl, node, nnode, ecom)) {
static void write_vni_config(struct vty *vty, struct bgpevpn *vpn)
{
- char buf1[INET6_ADDRSTRLEN];
+ char buf1[RD_ADDRSTRLEN];
char *ecom_str;
struct listnode *node, *nnode;
struct ecommunity *ecom;
vty_out(vty, " vni %d\n", vpn->vni);
if (is_rd_configured(vpn))
vty_out(vty, " rd %s\n",
- prefix_rd2str(&vpn->prd, buf1, RD_ADDRSTRLEN));
+ prefix_rd2str(&vpn->prd, buf1, sizeof(buf1)));
if (is_import_rt_configured(vpn)) {
for (ALL_LIST_ELEMENTS(vpn->import_rtl, node, nnode,
vty_out(vty, " Imported from %s:%s\n",
prefix_rd2str(
(struct prefix_rd *)&prn->p,
- buf1, RD_ADDRSTRLEN),
+ buf1, sizeof(buf1)),
buf2);
}
}
json_peer, "routerId",
inet_ntop(AF_INET,
&binfo->peer->remote_id, buf1,
- BUFSIZ));
+ sizeof(buf1)));
if (binfo->peer->hostname)
json_object_string_add(
inet_ntop(
AF_INET,
&binfo->peer->remote_id,
- buf1, BUFSIZ));
+ buf1, sizeof(buf1)));
}
}
continue;
if (rn->info != NULL) {
struct prefix_rd prd;
- char rd[BUFSIZ];
+ char rd[RD_ADDRSTRLEN];
memcpy(&prd, &(rn->p), sizeof(struct prefix_rd));
- if (prefix_rd2str(&prd, rd, BUFSIZ) == NULL)
- sprintf(rd,
- "Unknown Type: %u",
- decode_rd_type(prd.val));
+ prefix_rd2str(&prd, rd, sizeof(rd));
bgp_show_table(vty, bgp, safi, rn->info, type,
output_arg, use_json,
rd, next == NULL,
struct prefix *p;
struct peer *peer;
struct listnode *node, *nnode;
- char buf1[INET6_ADDRSTRLEN];
+ char buf1[RD_ADDRSTRLEN];
char buf2[INET6_ADDRSTRLEN];
#if defined(HAVE_CUMULUS)
char buf3[EVPN_ROUTE_STRLEN];
#if defined(HAVE_CUMULUS)
if (safi == SAFI_EVPN)
vty_out(vty, "BGP routing table entry for %s%s%s\n",
- prd ? prefix_rd2str(prd, buf1, RD_ADDRSTRLEN)
+ prd ? prefix_rd2str(prd, buf1, sizeof(buf1))
: "",
prd ? ":" : "",
bgp_evpn_route2str((struct prefix_evpn *)p,
vty_out(vty, "BGP routing table entry for %s%s%s/%d\n",
((safi == SAFI_MPLS_VPN || safi == SAFI_ENCAP)
? prefix_rd2str(prd, buf1,
- RD_ADDRSTRLEN)
+ sizeof(buf1))
: ""),
safi == SAFI_MPLS_VPN ? ":" : "",
inet_ntop(p->family, &p->u.prefix, buf2,
vty_out(vty, "BGP routing table entry for %s%s%s/%d\n",
((safi == SAFI_MPLS_VPN || safi == SAFI_ENCAP
|| safi == SAFI_EVPN)
- ? prefix_rd2str(prd, buf1, RD_ADDRSTRLEN)
- : ""),
+ ? prefix_rd2str(prd, buf1, sizeof(buf1))
+ : ""),
((safi == SAFI_MPLS_VPN) || (safi == SAFI_EVPN)) ? ":"
: "",
buf2, p->prefixlen);
prd = (struct prefix_rd *)&prn->p;
/* "network" configuration display. */
- prefix_rd2str(prd, rdbuf, RD_ADDRSTRLEN);
+ prefix_rd2str(prd, rdbuf, sizeof(rdbuf));
label = decode_label(&bgp_static->label);
vty_out(vty, " network %s/%d rd %s",
prd = (struct prefix_rd *)&prn->p;
/* "network" configuration display. */
- prefix_rd2str(prd, rdbuf, RD_ADDRSTRLEN);
+ prefix_rd2str(prd, rdbuf, sizeof(rdbuf));
if (p->u.prefix_evpn.route_type == 5) {
char local_buf[PREFIX_STRLEN];
uint8_t family = IS_EVPN_PREFIX_IPADDR_V4((struct prefix_evpn *)p)
}
if (rfg->rd.prefixlen) {
- char buf[BUFSIZ];
- buf[0] = buf[BUFSIZ - 1] = 0;
+ char buf[RD_ADDRSTRLEN];
if (AF_UNIX == rfg->rd.family) {
vty_out(vty, " rd auto:nh:%d\n",
value);
- } else {
-
- if (!prefix_rd2str(&rfg->rd, buf,
- BUFSIZ)
- || !buf[0] || buf[BUFSIZ - 1]) {
-
- vty_out(vty,
- "!Error: Can't convert rd\n");
- } else {
- vty_out(vty, " rd %s\n", buf);
- }
- }
+ } else
+ vty_out(vty, " rd %s\n",
+ prefix_rd2str(&rfg->rd, buf,
+ sizeof(buf)));
}
if (rfg->rt_import_list && rfg->rt_export_list
vty_out(vty, " vnc defaults\n");
if (hc->default_rd.prefixlen) {
- char buf[BUFSIZ];
- buf[0] = buf[BUFSIZ - 1] = 0;
+ char buf[RD_ADDRSTRLEN];
if (AF_UNIX == hc->default_rd.family) {
uint16_t value = 0;
vty_out(vty, " rd auto:vn:%d\n",
value);
- } else {
-
- if (!prefix_rd2str(&hc->default_rd, buf,
- BUFSIZ)
- || !buf[0] || buf[BUFSIZ - 1]) {
-
- vty_out(vty,
- "!Error: Can't convert rd\n");
- } else {
- vty_out(vty, " rd %s\n", buf);
- }
- }
+ } else
+ vty_out(vty, " rd %s\n",
+ prefix_rd2str(&hc->default_rd,
+ buf,
+ sizeof(buf)));
}
if (hc->default_response_lifetime) {
vty_out(vty, " response-lifetime ");
if (rfg->rd.prefixlen) {
- char buf[BUFSIZ];
- buf[0] = buf[BUFSIZ - 1] = 0;
+ char buf[RD_ADDRSTRLEN];
if (AF_UNIX == rfg->rd.family) {
" rd auto:vn:%d\n",
value);
- } else {
-
- if (!prefix_rd2str(&rfg->rd,
- buf, BUFSIZ)
- || !buf[0]
- || buf[BUFSIZ - 1]) {
-
- vty_out(vty,
- "!Error: Can't convert rd\n");
- } else {
- vty_out(vty,
- " rd %s\n",
- buf);
- }
- }
+ } else
+ vty_out(vty,
+ " rd %s\n",
+ prefix_rd2str(&rfg->rd,
+ buf,
+ sizeof(buf)));
}
if (rfg->flags & RFAPI_RFG_RESPONSE_LIFETIME) {
vty_out(vty, " response-lifetime ");
struct bgp_node *bn;
struct bgp_info *bi;
char buf[PREFIX_STRLEN];
- char buf2[BUFSIZ];
+ char buf2[RD_ADDRSTRLEN];
struct prefix_rd prd0;
prefix2str(p, buf, sizeof(buf));
- prefix_rd2str(prd, buf2, sizeof(buf2));
afi = family2afi(p->family);
assert(afi == AFI_IP || afi == AFI_IP6);
vnc_zlog_debug_verbose(
"%s: peer=%p, prefix=%s, prd=%s afi=%d, safi=%d bn=%p, bn->info=%p",
- __func__, peer, buf, buf2, afi, safi, bn,
+ __func__, peer, buf,
+ prefix_rd2str(prd, buf2, sizeof(buf2)), afi, safi, bn,
(bn ? bn->info : NULL));
for (bi = (bn ? bn->info : NULL); bi; bi = bi->next) {
struct bgp_attr_encap_subtlv *encaptlv;
char buf[PREFIX_STRLEN];
- char buf2[BUFSIZ];
+ char buf2[RD_ADDRSTRLEN];
#if 0 /* unused? */
struct prefix pfx_buf;
#endif
4); /* low order 4 bytes */
}
{
- char buf[BUFSIZ];
- buf[0] = 0;
- prefix_rd2str(rd, buf, BUFSIZ);
- buf[BUFSIZ - 1] = 0;
+ char buf[RD_ADDRSTRLEN];
+
vnc_zlog_debug_verbose("%s: auto-RD is set to %s", __func__,
- buf);
+ prefix_rd2str(rd, buf, sizeof(buf)));
}
return 0;
}
#include "bgpd/bgp_route.h"
#include "bgpd/bgp_mplsvpn.h" /* prefix_rd2str() */
#include "bgpd/bgp_vnc_types.h"
+#include "bgpd/bgp_rd.h"
#include "bgpd/rfapi/rfapi.h"
#include "bgpd/rfapi/bgp_rfapi_cfg.h"
assert(bi->extra);
{
- char buf[BUFSIZ];
- prefix_rd2str(&bi->extra->vnc.import.rd, buf, BUFSIZ);
+ char buf[RD_ADDRSTRLEN];
+
vnc_zlog_debug_verbose("%s: bi %p, peer %p, rd %s", __func__,
- bi, bi->peer, buf);
+ bi, bi->peer,
+ prefix_rd2str(&bi->extra->vnc.import.rd,
+ buf, sizeof(buf)));
}
sl = RFAPI_RDINDEX_W_ALLOC(rn);
for (rc = skiplist_next(sl, (void **)&k, (void **)&v, &cursor); !rc;
rc = skiplist_next(sl, (void **)&k, (void **)&v, &cursor)) {
- char buf[BUFSIZ];
+ char buf[RD_ADDRSTRLEN];
char buf_aux_pfx[PREFIX_STRLEN];
- prefix_rd2str(&k->extra->vnc.import.rd, buf, BUFSIZ);
- buf_aux_pfx[0] = 0;
+ prefix_rd2str(&k->extra->vnc.import.rd, buf, sizeof(buf));
if (k->extra->vnc.import.aux_prefix.family) {
prefix2str(&k->extra->vnc.import.aux_prefix,
- buf_aux_pfx, sizeof(buf));
- } else {
+ buf_aux_pfx, sizeof(buf_aux_pfx));
+ } else
strncpy(buf_aux_pfx, "(none)", PREFIX_STRLEN);
- buf_aux_pfx[PREFIX_STRLEN - 1] = 0;
- }
vnc_zlog_debug_verbose("bi %p, peer %p, rd %s, aux_prefix %s",
k, k->peer, buf, buf_aux_pfx);
#if DEBUG_BI_SEARCH
{
- char buf[BUFSIZ];
+ char buf[RD_ADDRSTRLEN];
char buf_aux_pfx[PREFIX_STRLEN];
- prefix_rd2str(prd, buf, BUFSIZ);
if (aux_prefix) {
prefix2str(aux_prefix, buf_aux_pfx,
sizeof(buf_aux_pfx));
- } else {
- strncpy(buf_aux_pfx, "(nil)", BUFSIZ - 1);
- buf_aux_pfx[BUFSIZ - 1] = 0;
- }
+ } else
+ strncpy(buf_aux_pfx, "(nil)", sizeof(buf_aux_pfx));
vnc_zlog_debug_verbose("%s want prd=%s, peer=%p, aux_prefix=%s",
- __func__, buf, peer, buf_aux_pfx);
+ __func__,
+ prefix_rd2str(prd, buf, sizeof(buf)),
+ peer, buf_aux_pfx);
rfapiItBiIndexDump(rn);
}
#endif
bi_result = bi_result->next) {
#if DEBUG_BI_SEARCH
{
- char buf[BUFSIZ];
- prefix_rd2str(&bi_result->extra->vnc.import.rd,
- buf, BUFSIZ);
+ char buf[RD_ADDRSTRLEN];
+
vnc_zlog_debug_verbose(
"%s: bi has prd=%s, peer=%p", __func__,
- buf, bi_result->peer);
+ prefix_rd2str(&bi_result->extra->vnc.import.rd,
+ buf,
+ sizeof(buf)),
+ bi_result->peer);
}
#endif
if (peer == bi_result->peer
int rc;
{
- char buf[BUFSIZ];
- prefix_rd2str(&bi->extra->vnc.import.rd, buf, BUFSIZ);
+ char buf[RD_ADDRSTRLEN];
+
vnc_zlog_debug_verbose("%s: bi %p, peer %p, rd %s", __func__,
- bi, bi->peer, buf);
+ bi, bi->peer,
+ prefix_rd2str(&bi->extra->vnc.import.rd,
+ buf, sizeof(buf)));
}
sl = RFAPI_RDINDEX(rn);
} else {
- char buf_rd[BUFSIZ];
+ char buf_rd[RD_ADDRSTRLEN];
/* not found: add new route to RIB */
ori = rfapi_info_new();
ri->last_sent_time = rfapi_time(NULL);
#if DEBUG_RIB_SL_RD
{
- char buf_rd[BUFSIZ];
- prefix_rd2str(&ri->rk.rd,
- buf_rd,
- sizeof(buf_rd));
+ char buf_rd[RD_ADDRSTRLEN];
+
vnc_zlog_debug_verbose(
"%s: move route to recently deleted list, rd=%s",
- __func__, buf_rd);
+ __func__,
+ prefix_rd2str(&ri->rk.rd,
+ buf_rd,
+ sizeof(buf_rd)));
}
#endif
char str_lifetime[BUFSIZ];
char str_age[BUFSIZ];
char *p;
- char str_rd[BUFSIZ];
+ char str_rd[RD_ADDRSTRLEN];
++routes_displayed;
str_rd[0] = 0; /* start empty */
#if DEBUG_RIB_SL_RD
- str_rd[0] = ' ';
- prefix_rd2str(&ri->rk.rd, str_rd + 1, BUFSIZ - 1);
+ prefix_rd2str(&ri->rk.rd, str_rd, sizeof(str_rd));
#endif
- fp(out, " %c %-20s %-15s %-15s %-4u %-8s %-8s%s\n",
+ fp(out, " %c %-20s %-15s %-15s %-4u %-8s %-8s %s\n",
deleted ? 'r' : ' ', *printedprefix ? "" : str_pfx, str_vn,
str_un, ri->cost, str_lifetime, str_age, str_rd);
void rfapiPrintRd(struct vty *vty, struct prefix_rd *prd)
{
- char buf[BUFSIZ];
+ char buf[RD_ADDRSTRLEN];
- buf[0] = 0;
prefix_rd2str(prd, buf, BUFSIZ);
- buf[BUFSIZ - 1] = 0;
vty_out(vty, "%s", buf);
}