summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDonald Sharp <sharpd@nvidia.com>2022-06-14 14:42:11 -0400
committerDonald Sharp <sharpd@nvidia.com>2022-06-14 15:40:36 -0400
commitf7a410a7c3653f5943568983d4c6003be5ff3bf4 (patch)
tree92938251a038d8204ca92620f81cd8aba31aa39d
parentf90391998c8a480636e03a412d0cf67533809634 (diff)
lib: Abstract usage of '%pNHs' so that nexthop groups can use it too
Abstract the usage of '%pNHs' so that when nexthop groups get a new special printfrr that it can take advantage of this functionality too. Signed-off-by: Donald Sharp <sharpd@nvidia.com>
-rw-r--r--lib/nexthop.c50
-rw-r--r--lib/nexthop.h1
2 files changed, 30 insertions, 21 deletions
diff --git a/lib/nexthop.c b/lib/nexthop.c
index e17eeb8303..248acd2700 100644
--- a/lib/nexthop.c
+++ b/lib/nexthop.c
@@ -922,6 +922,34 @@ int nexthop_str2backups(const char *str, int *num_backups,
return ret;
}
+ssize_t printfrr_nhs(struct fbuf *buf, const struct nexthop *nexthop)
+{
+ ssize_t ret = 0;
+
+ if (!nexthop)
+ return bputs(buf, "(null)");
+
+ switch (nexthop->type) {
+ case NEXTHOP_TYPE_IFINDEX:
+ ret += bprintfrr(buf, "if %u", nexthop->ifindex);
+ break;
+ case NEXTHOP_TYPE_IPV4:
+ case NEXTHOP_TYPE_IPV4_IFINDEX:
+ ret += bprintfrr(buf, "%pI4 if %u", &nexthop->gate.ipv4,
+ nexthop->ifindex);
+ break;
+ case NEXTHOP_TYPE_IPV6:
+ case NEXTHOP_TYPE_IPV6_IFINDEX:
+ ret += bprintfrr(buf, "%pI6 if %u", &nexthop->gate.ipv6,
+ nexthop->ifindex);
+ break;
+ case NEXTHOP_TYPE_BLACKHOLE:
+ ret += bputs(buf, "blackhole");
+ break;
+ }
+ return ret;
+}
+
/*
* nexthop printing variants:
* %pNHvv
@@ -1010,27 +1038,7 @@ static ssize_t printfrr_nh(struct fbuf *buf, struct printfrr_eargs *ea,
case 's':
ea->fmt++;
- if (!nexthop)
- return bputs(buf, "(null)");
-
- switch (nexthop->type) {
- case NEXTHOP_TYPE_IFINDEX:
- ret += bprintfrr(buf, "if %u", nexthop->ifindex);
- break;
- case NEXTHOP_TYPE_IPV4:
- case NEXTHOP_TYPE_IPV4_IFINDEX:
- ret += bprintfrr(buf, "%pI4 if %u", &nexthop->gate.ipv4,
- nexthop->ifindex);
- break;
- case NEXTHOP_TYPE_IPV6:
- case NEXTHOP_TYPE_IPV6_IFINDEX:
- ret += bprintfrr(buf, "%pI6 if %u", &nexthop->gate.ipv6,
- nexthop->ifindex);
- break;
- case NEXTHOP_TYPE_BLACKHOLE:
- ret += bputs(buf, "blackhole");
- break;
- }
+ ret += printfrr_nhs(buf, nexthop);
return ret;
case 'c':
ea->fmt++;
diff --git a/lib/nexthop.h b/lib/nexthop.h
index 320b46315e..c13f1b1376 100644
--- a/lib/nexthop.h
+++ b/lib/nexthop.h
@@ -260,6 +260,7 @@ int nexthop_str2backups(const char *str, int *num_backups,
#pragma FRR printfrr_ext "%pNH" (struct nexthop *)
#endif
+ssize_t printfrr_nhs(struct fbuf *buf, const struct nexthop *nh);
#ifdef __cplusplus
}
#endif