From bdb3fa3b9216aede64c5b982011fb04ef25c67f7 Mon Sep 17 00:00:00 2001 From: Louis Scalbert Date: Fri, 21 Apr 2023 11:56:07 +0200 Subject: [PATCH] bgpd, lib: extend the size of the prefix string buffer BGP Link-State prefixes are special prefixes that contains a lot of data. Extend the length of the prefix string buffer in order to display properly this type of prefixes with the next commits. Signed-off-by: Louis Scalbert --- bgpd/bgp_route.c | 10 +++++----- bgpd/bgp_table.c | 2 +- lib/prefix.c | 6 +++--- lib/prefix.h | 5 +++++ 4 files changed, 14 insertions(+), 9 deletions(-) diff --git a/bgpd/bgp_route.c b/bgpd/bgp_route.c index a7e60886db..0171f991c5 100644 --- a/bgpd/bgp_route.c +++ b/bgpd/bgp_route.c @@ -1581,7 +1581,7 @@ static enum filter_type bgp_input_filter(struct peer *peer, done: if (frrtrace_enabled(frr_bgp, input_filter)) { - char pfxprint[PREFIX2STR_BUFFER]; + char pfxprint[PREFIX_STRLEN_EXTENDED]; prefix2str(p, pfxprint, sizeof(pfxprint)); frrtrace(5, frr_bgp, input_filter, peer, pfxprint, afi, safi, @@ -1638,7 +1638,7 @@ static enum filter_type bgp_output_filter(struct peer *peer, } if (frrtrace_enabled(frr_bgp, output_filter)) { - char pfxprint[PREFIX2STR_BUFFER]; + char pfxprint[PREFIX_STRLEN_EXTENDED]; prefix2str(p, pfxprint, sizeof(pfxprint)); frrtrace(5, frr_bgp, output_filter, peer, pfxprint, afi, safi, @@ -2712,7 +2712,7 @@ void bgp_best_selection(struct bgp *bgp, struct bgp_dest *dest, int paths_eq, do_mpath; bool debug; struct list mp_list; - char pfx_buf[PREFIX2STR_BUFFER] = {}; + char pfx_buf[PREFIX_STRLEN_EXTENDED] = {}; char path_buf[PATH_ADDPATH_STR_BUFFER]; bgp_mp_list_init(&mp_list); @@ -4167,7 +4167,7 @@ void bgp_update(struct peer *peer, const struct prefix *p, uint32_t addpath_id, int allowas_in = 0; if (frrtrace_enabled(frr_bgp, process_update)) { - char pfxprint[PREFIX2STR_BUFFER]; + char pfxprint[PREFIX_STRLEN_EXTENDED]; prefix2str(p, pfxprint, sizeof(pfxprint)); frrtrace(6, frr_bgp, process_update, peer, pfxprint, addpath_id, @@ -8773,7 +8773,7 @@ static void route_vty_out_route(struct bgp_dest *dest, const struct prefix *p, struct vty *vty, json_object *json, bool wide) { int len = 0; - char buf[INET6_ADDRSTRLEN]; + char buf[PREFIX_STRLEN_EXTENDED]; if (p->family == AF_INET) { if (!json) { diff --git a/bgpd/bgp_table.c b/bgpd/bgp_table.c index b9265dd81b..e01bf39113 100644 --- a/bgpd/bgp_table.c +++ b/bgpd/bgp_table.c @@ -63,7 +63,7 @@ struct bgp_dest *bgp_dest_lock_node(struct bgp_dest *dest) const char *bgp_dest_get_prefix_str(struct bgp_dest *dest) { const struct prefix *p = NULL; - static char str[PREFIX_STRLEN] = {0}; + static char str[PREFIX_STRLEN_EXTENDED] = {0}; p = bgp_dest_get_prefix(dest); if (p) diff --git a/lib/prefix.c b/lib/prefix.c index 59acc7c22e..35bc3b3b6f 100644 --- a/lib/prefix.c +++ b/lib/prefix.c @@ -1166,7 +1166,7 @@ const char *bgp_linkstate_nlri_type_2str(uint16_t nlri_type) const char *prefix2str(union prefixconstptr pu, char *str, int size) { const struct prefix *p = pu.p; - char buf[PREFIX2STR_BUFFER]; + char buf[PREFIX_STRLEN_EXTENDED]; int byte, tmp, a, b; bool z = false; size_t l; @@ -1234,7 +1234,7 @@ const char *prefix2str(union prefixconstptr pu, char *str, int size) static ssize_t prefixhost2str(struct fbuf *fbuf, union prefixconstptr pu) { const struct prefix *p = pu.p; - char buf[PREFIX2STR_BUFFER]; + char buf[PREFIX_STRLEN_EXTENDED]; switch (p->family) { case AF_INET: @@ -1752,7 +1752,7 @@ static ssize_t printfrr_pfx(struct fbuf *buf, struct printfrr_eargs *ea, if (host_only) return prefixhost2str(buf, (struct prefix *)ptr); else { - char cbuf[PREFIX_STRLEN]; + char cbuf[PREFIX_STRLEN_EXTENDED]; prefix2str(ptr, cbuf, sizeof(cbuf)); return bputs(buf, cbuf); diff --git a/lib/prefix.h b/lib/prefix.h index dacdbf9059..f1aff43689 100644 --- a/lib/prefix.h +++ b/lib/prefix.h @@ -347,6 +347,11 @@ union prefixconstptr { /* Maximum string length of the result of prefix2str */ #define PREFIX_STRLEN 80 +/* Maximum string length of the result of prefix2str for + * long string prefixes (eg. BGP Link-State) + */ +#define PREFIX_STRLEN_EXTENDED 512 + /* * Longest possible length of a (S,G) string is 34 bytes * 123.123.123.123 = 15 * 2 -- 2.39.5