diff options
author | David Lamparter <equinox@opensourcerouting.org> | 2022-01-05 16:23:23 +0100 |
---|---|---|
committer | David Lamparter <equinox@opensourcerouting.org> | 2022-01-14 11:57:46 +0100 |
commit | 2c5b4d80efc507f7244303d959f99af8061dacf3 (patch) | |
tree | a0435f4662282c8e0bdd228dc53932db8abc6631 /lib/prefix.c | |
parent | tools: disable printf ext checks in checkpatch (diff) | |
download | frr-2c5b4d80efc507f7244303d959f99af8061dacf3.tar.xz frr-2c5b4d80efc507f7244303d959f99af8061dacf3.zip |
lib: add `s` option to `pI4`/`pI6`/`pIA` printfrr
Adding an `s` after these printfrr specifiers replaces 0.0.0.0 / :: in
the output with a star (`*`). This is primarily intended for use with
multicast, e.g. to print `(*,G)`.
Signed-off-by: David Lamparter <equinox@opensourcerouting.org>
Diffstat (limited to 'lib/prefix.c')
-rw-r--r-- | lib/prefix.c | 46 |
1 files changed, 46 insertions, 0 deletions
diff --git a/lib/prefix.c b/lib/prefix.c index d3e8a612e..4e9d41836 100644 --- a/lib/prefix.c +++ b/lib/prefix.c @@ -1374,10 +1374,36 @@ static ssize_t printfrr_ia(struct fbuf *buf, struct printfrr_eargs *ea, { const struct ipaddr *ipa = ptr; char cbuf[INET6_ADDRSTRLEN]; + bool use_star = false; + + if (ea->fmt[0] == 's') { + use_star = true; + ea->fmt++; + } if (!ipa) return bputs(buf, "(null)"); + if (use_star) { + struct in_addr zero4 = {}; + struct in6_addr zero6 = {}; + + switch (ipa->ipa_type) { + case IPADDR_V4: + if (!memcmp(&ipa->ip.addr, &zero4, sizeof(zero4))) + return bputch(buf, '*'); + break; + + case IPADDR_V6: + if (!memcmp(&ipa->ip.addr, &zero6, sizeof(zero6))) + return bputch(buf, '*'); + break; + + default: + break; + } + } + ipaddr2str(ipa, cbuf, sizeof(cbuf)); return bputs(buf, cbuf); } @@ -1387,10 +1413,20 @@ static ssize_t printfrr_i4(struct fbuf *buf, struct printfrr_eargs *ea, const void *ptr) { char cbuf[INET_ADDRSTRLEN]; + bool use_star = false; + struct in_addr zero = {}; + + if (ea->fmt[0] == 's') { + use_star = true; + ea->fmt++; + } if (!ptr) return bputs(buf, "(null)"); + if (use_star && !memcmp(ptr, &zero, sizeof(zero))) + return bputch(buf, '*'); + inet_ntop(AF_INET, ptr, cbuf, sizeof(cbuf)); return bputs(buf, cbuf); } @@ -1400,10 +1436,20 @@ static ssize_t printfrr_i6(struct fbuf *buf, struct printfrr_eargs *ea, const void *ptr) { char cbuf[INET6_ADDRSTRLEN]; + bool use_star = false; + struct in6_addr zero = {}; + + if (ea->fmt[0] == 's') { + use_star = true; + ea->fmt++; + } if (!ptr) return bputs(buf, "(null)"); + if (use_star && !memcmp(ptr, &zero, sizeof(zero))) + return bputch(buf, '*'); + inet_ntop(AF_INET6, ptr, cbuf, sizeof(cbuf)); return bputs(buf, cbuf); } |