diff options
| author | David Lamparter <equinox@diac24.net> | 2021-02-18 22:52:23 +0100 |
|---|---|---|
| committer | David Lamparter <equinox@diac24.net> | 2021-03-27 16:56:55 +0100 |
| commit | 212e04e5a7f682594dab26cd8354bc4fa040b61f (patch) | |
| tree | 59a09a812b868332f073985494ee0a61910da9fd /lib/srcdest_table.c | |
| parent | bcf9d7d8aa77c66ac2e99f75ae11e276accecb1d (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 'lib/srcdest_table.c')
| -rw-r--r-- | lib/srcdest_table.c | 16 |
1 files changed, 8 insertions, 8 deletions
diff --git a/lib/srcdest_table.c b/lib/srcdest_table.c index a115507192..ca48d56e4d 100644 --- a/lib/srcdest_table.c +++ b/lib/srcdest_table.c @@ -307,20 +307,20 @@ const char *srcdest_rnode2str(const struct route_node *rn, char *str, int size) } printfrr_ext_autoreg_p("RN", printfrr_rn) -static ssize_t printfrr_rn(char *buf, size_t bsz, const char *fmt, +static ssize_t printfrr_rn(struct fbuf *buf, const char **fmt, int prec, const void *ptr) { const struct route_node *rn = ptr; const struct prefix *dst_p, *src_p; + char cbuf[PREFIX_STRLEN * 2 + 6]; - if (rn) { - srcdest_rnode_prefixes(rn, &dst_p, &src_p); - srcdest2str(dst_p, (const struct prefix_ipv6 *)src_p, buf, bsz); - } else { - strlcpy(buf, "NULL", bsz); - } + if (!rn) + return bputs(buf, "NULL"); - return 2; + srcdest_rnode_prefixes(rn, &dst_p, &src_p); + srcdest2str(dst_p, (const struct prefix_ipv6 *)src_p, + cbuf, sizeof(cbuf)); + return bputs(buf, cbuf); } struct route_table *srcdest_srcnode_table(struct route_node *rn) |
