]> git.puffer.fish Git - matthieu/frr.git/commitdiff
lib: Add the ability for other people to call a nexthop write line
authorDonald Sharp <sharpd@cumulusnetworks.com>
Sat, 10 Mar 2018 21:15:46 +0000 (16:15 -0500)
committerDonald Sharp <sharpd@cumulusnetworks.com>
Wed, 14 Mar 2018 12:32:39 +0000 (08:32 -0400)
Add code to allow nexthops to be written by people who are
interested in writing their own nexthop line.

Signed-off-by: Donald Sharp <sharpd@cumulusnetworks.com>
lib/nexthop_group.c
lib/nexthop_group.h

index 0cfbeb8f40891afd9c4fe35cda916bbe27e327a7..e486247244c38e3b681673e18c2287a6ea530884 100644 (file)
@@ -315,57 +315,55 @@ struct cmd_node nexthop_group_node = {
        1
 };
 
+void nexthop_group_write_nexthop(struct vty *vty, struct nexthop *nh)
+{
+       char buf[100];
+       struct vrf *vrf;
+
+       vty_out(vty, "  nexthop ");
+
+       switch (nh->type) {
+       case NEXTHOP_TYPE_IFINDEX:
+               vty_out(vty, "%s", ifindex2ifname(nh->ifindex, nh->vrf_id));
+               break;
+       case NEXTHOP_TYPE_IPV4:
+               vty_out(vty, "%s", inet_ntoa(nh->gate.ipv4));
+               break;
+       case NEXTHOP_TYPE_IPV4_IFINDEX:
+               vty_out(vty, "%s %s", inet_ntoa(nh->gate.ipv4),
+                       ifindex2ifname(nh->ifindex, nh->vrf_id));
+               break;
+       case NEXTHOP_TYPE_IPV6:
+               vty_out(vty, "%s",
+                       inet_ntop(AF_INET6, &nh->gate.ipv6, buf, sizeof(buf)));
+               break;
+       case NEXTHOP_TYPE_IPV6_IFINDEX:
+               vty_out(vty, "%s %s",
+                       inet_ntop(AF_INET6, &nh->gate.ipv6, buf, sizeof(buf)),
+                       ifindex2ifname(nh->ifindex, nh->vrf_id));
+               break;
+       case NEXTHOP_TYPE_BLACKHOLE:
+               break;
+       }
+
+       if (nh->vrf_id != VRF_DEFAULT) {
+               vrf = vrf_lookup_by_id(nh->vrf_id);
+               vty_out(vty, " nexthop-vrf %s", vrf->name);
+       }
+       vty_out(vty, "\n");
+}
+
 static int nexthop_group_write(struct vty *vty)
 {
        struct nexthop_group_cmd *nhgc;
        struct nexthop *nh;
-       struct vrf *vrf;
 
        RB_FOREACH (nhgc, nhgc_entry_head, &nhgc_entries) {
-               char buf[100];
-
                vty_out(vty, "nexthop-group %s\n", nhgc->name);
 
-               for (nh = nhgc->nhg.nexthop; nh; nh = nh->next) {
-
-                       vty_out(vty, "  nexthop ");
-
-                       switch (nh->type) {
-                       case NEXTHOP_TYPE_IFINDEX:
-                               vty_out(vty, "%s",
-                                       ifindex2ifname(nh->ifindex,
-                                                      nh->vrf_id));
-                               break;
-                       case NEXTHOP_TYPE_IPV4:
-                               vty_out(vty, "%s", inet_ntoa(nh->gate.ipv4));
-                               break;
-                       case NEXTHOP_TYPE_IPV4_IFINDEX:
-                               vty_out(vty, "%s %s", inet_ntoa(nh->gate.ipv4),
-                                       ifindex2ifname(nh->ifindex,
-                                                      nh->vrf_id));
-                               break;
-                       case NEXTHOP_TYPE_IPV6:
-                               vty_out(vty, "%s",
-                                       inet_ntop(AF_INET6, &nh->gate.ipv6, buf,
-                                                 sizeof(buf)));
-                               break;
-                       case NEXTHOP_TYPE_IPV6_IFINDEX:
-                               vty_out(vty, "%s %s",
-                                       inet_ntop(AF_INET6, &nh->gate.ipv6, buf,
-                                                 sizeof(buf)),
-                                       ifindex2ifname(nh->ifindex,
-                                                      nh->vrf_id));
-                               break;
-                       case NEXTHOP_TYPE_BLACKHOLE:
-                               break;
-                       }
+               for (nh = nhgc->nhg.nexthop; nh; nh = nh->next)
+                       nexthop_group_write_nexthop(vty, nh);
 
-                       if (nh->vrf_id) {
-                               vrf = vrf_lookup_by_id(nh->vrf_id);
-                               vty_out(vty, " nexthop-vrf %s", vrf->name);
-                       }
-                       vty_out(vty, "\n");
-               }
                vty_out(vty, "!\n");
        }
 
index b22e083e6bb0ef5d99225bd8f4dc13244cc8db5d..c2e4c4d7573cc46998fc2cc94398f2bb7bb312e1 100644 (file)
@@ -21,6 +21,8 @@
 #ifndef __NEXTHOP_GROUP__
 #define __NEXTHOP_GROUP__
 
+#include <vty.h>
+
 /*
  * What is a nexthop group?
  *
@@ -88,4 +90,5 @@ extern struct nexthop *nexthop_exists(struct nexthop_group *nhg,
 
 extern struct nexthop_group_cmd *nhgc_find(const char *name);
 
+extern void nexthop_group_write_nexthop(struct vty *vty, struct nexthop *nh);
 #endif