summaryrefslogtreecommitdiff
path: root/bgpd/bgp_table.c
diff options
context:
space:
mode:
authorDavid Lamparter <equinox@diac24.net>2021-02-18 22:52:23 +0100
committerDavid Lamparter <equinox@diac24.net>2021-03-27 16:56:55 +0100
commit212e04e5a7f682594dab26cd8354bc4fa040b61f (patch)
tree59a09a812b868332f073985494ee0a61910da9fd /bgpd/bgp_table.c
parentbcf9d7d8aa77c66ac2e99f75ae11e276accecb1d (diff)
lib: rework printfrr extensions to output directly
Allowing printfrr extensions to directly write to the output buffer has a few advantages: - there is no arbitrary length limit imposed (previously 64) - the output doesn't need to be copied another time - the extension can directly use bprintfrr() to put together pieces The downside is that the theoretical length (regardless of available buffer space) must be computed correctly. Extended unit tests to test these paths a bit more thoroughly. Signed-off-by: David Lamparter <equinox@diac24.net>
Diffstat (limited to 'bgpd/bgp_table.c')
-rw-r--r--bgpd/bgp_table.c17
1 files changed, 8 insertions, 9 deletions
diff --git a/bgpd/bgp_table.c b/bgpd/bgp_table.c
index 7e3aa2a48a..50123c608b 100644
--- a/bgpd/bgp_table.c
+++ b/bgpd/bgp_table.c
@@ -201,18 +201,17 @@ struct bgp_node *bgp_table_subtree_lookup(const struct bgp_table *table,
}
printfrr_ext_autoreg_p("BD", printfrr_bd)
-static ssize_t printfrr_bd(char *buf, size_t bsz, const char *fmt,
+static ssize_t printfrr_bd(struct fbuf *buf, const char **fmt,
int prec, const void *ptr)
{
const struct bgp_dest *dest = ptr;
- const struct prefix *p;
+ const struct prefix *p = bgp_dest_get_prefix(dest);
+ char cbuf[PREFIX_STRLEN];
- if (dest) {
- p = bgp_dest_get_prefix(dest);
- prefix2str(p, buf, bsz);
- } else {
- strlcpy(buf, "NULL", bsz);
- }
+ if (!dest)
+ return bputs(buf, "NULL");
- return 2;
+ /* need to get the real length even if buffer too small */
+ prefix2str(p, cbuf, sizeof(cbuf));
+ return bputs(buf, cbuf);
}