]> git.puffer.fish Git - mirror/frr.git/commitdiff
lib: Abstract usage of '%pNHs' so that nexthop groups can use it too
authorDonald Sharp <sharpd@nvidia.com>
Tue, 14 Jun 2022 18:42:11 +0000 (14:42 -0400)
committerDonald Sharp <sharpd@nvidia.com>
Tue, 14 Jun 2022 19:40:36 +0000 (15:40 -0400)
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>
lib/nexthop.c
lib/nexthop.h

index e17eeb8303ac2abbccb649ada315d1417dd93f14..248acd270078d1594ae615864c6786f9fb6f99f0 100644 (file)
@@ -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++;
index 320b46315e1c653ad4fb4fe977d3504338fc98ae..c13f1b137686be0c8f0b3c118a84d93c9b429a38 100644 (file)
@@ -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