]> git.puffer.fish Git - matthieu/frr.git/commitdiff
nhrpd: implement 'show ip nhrp nhs'
authorTimo Teräs <timo.teras@iki.fi>
Sat, 25 Mar 2017 15:27:24 +0000 (17:27 +0200)
committerDonald Sharp <sharpd@cumulusnetworks.com>
Tue, 25 Apr 2017 12:32:46 +0000 (08:32 -0400)
nhrpd/nhrp_nhs.c
nhrpd/nhrp_vty.c
nhrpd/nhrpd.h

index 10245d308a509845e71c1b2433f99f22c105977c..555c0d1de1fdd8fe72e78aed3d0a4c5f4ddd8320 100644 (file)
@@ -18,19 +18,6 @@ DEFINE_MTYPE_STATIC(NHRPD, NHRP_NHS, "NHRP next hop server")
 DEFINE_MTYPE_STATIC(NHRPD, NHRP_REGISTRATION, "NHRP registration entries")
 
 static int nhrp_nhs_resolve(struct thread *t);
-
-struct nhrp_registration {
-       struct list_head reglist_entry;
-       struct thread *t_register;
-       struct nhrp_nhs *nhs;
-       struct nhrp_reqid reqid;
-       unsigned int timeout;
-       unsigned mark : 1;
-       union sockunion proto_addr;
-       struct nhrp_peer *peer;
-       struct notifier_block peer_notifier;
-};
-
 static int nhrp_reg_send_req(struct thread *t);
 
 static void nhrp_reg_reply(struct nhrp_reqid *reqid, void *arg)
@@ -370,3 +357,18 @@ void nhrp_nhs_terminate(void)
                }
        }
 }
+
+void nhrp_nhs_foreach(struct interface *ifp, afi_t afi, void (*cb)(struct nhrp_nhs *, struct nhrp_registration *, void *), void *ctx)
+{
+       struct nhrp_interface *nifp = ifp->info;
+       struct nhrp_nhs *nhs;
+       struct nhrp_registration *reg;
+
+       list_for_each_entry(nhs, &nifp->afi[afi].nhslist_head, nhslist_entry) {
+               if (!list_empty(&nhs->reglist_head)) {
+                       list_for_each_entry(reg, &nhs->reglist_head, reglist_entry)
+                               cb(nhs, reg, ctx);
+               } else
+                       cb(nhs, 0, ctx);
+       }
+}
index 2e3164410c02bc0e9f68af5516f02cb57b698faf..f127d24dc83e855f3d7aa8536409d9121edf419c 100644 (file)
@@ -592,6 +592,56 @@ static void show_ip_nhrp_cache(struct nhrp_cache *c, void *pctx)
                VTY_NEWLINE);
 }
 
+static void show_ip_nhrp_nhs(struct nhrp_nhs *n, struct nhrp_registration *reg, void *pctx)
+{
+       struct info_ctx *ctx = pctx;
+       struct vty *vty = ctx->vty;
+       char buf[2][SU_ADDRSTRLEN];
+
+       if (!ctx->count) {
+               vty_out(vty, "%-8s %-24s %-16s %-16s%s",
+                       "Iface",
+                       "FQDN",
+                       "NBMA",
+                       "Protocol",
+                       VTY_NEWLINE);
+       }
+       ctx->count++;
+
+       vty_out(vty, "%-8s %-24s %-16s %-16s%s",
+               n->ifp->name,
+               n->nbma_fqdn,
+               (reg && reg->peer) ? sockunion2str(&reg->peer->vc->remote.nbma, buf[0], sizeof buf[0]) : "-",
+               sockunion2str(reg ? &reg->proto_addr : &n->proto_addr, buf[1], sizeof buf[1]),
+               VTY_NEWLINE);
+}
+
+static void show_ip_nhrp_shortcut(struct nhrp_shortcut *s, void *pctx)
+{
+       struct info_ctx *ctx = pctx;
+       struct nhrp_cache *c;
+       struct vty *vty = ctx->vty;
+       char buf1[PREFIX_STRLEN], buf2[SU_ADDRSTRLEN];
+
+       if (!ctx->count) {
+               vty_out(vty, "%-8s %-24s %-24s %s%s",
+                       "Type",
+                       "Prefix",
+                       "Via",
+                       "Identity",
+                       VTY_NEWLINE);
+       }
+       ctx->count++;
+
+       c = s->cache;
+       vty_out(ctx->vty, "%-8s %-24s %-24s %s%s",
+               nhrp_cache_type_str[s->type],
+               prefix2str(s->p, buf1, sizeof buf1),
+               c ? sockunion2str(&c->remote_addr, buf2, sizeof buf2) : "",
+               (c && c->cur.peer) ? c->cur.peer->vc->remote.id : "",
+               VTY_NEWLINE);
+}
+
 static void show_ip_opennhrp_cache(struct nhrp_cache *c, void *pctx)
 {
        struct info_ctx *ctx = pctx;
@@ -631,38 +681,13 @@ static void show_ip_opennhrp_cache(struct nhrp_cache *c, void *pctx)
        vty_out(ctx->vty, "%s", VTY_NEWLINE);
 }
 
-static void show_ip_nhrp_shortcut(struct nhrp_shortcut *s, void *pctx)
-{
-       struct info_ctx *ctx = pctx;
-       struct nhrp_cache *c;
-       struct vty *vty = ctx->vty;
-       char buf1[PREFIX_STRLEN], buf2[SU_ADDRSTRLEN];
-
-       if (!ctx->count) {
-               vty_out(vty, "%-8s %-24s %-24s %s%s",
-                       "Type",
-                       "Prefix",
-                       "Via",
-                       "Identity",
-                       VTY_NEWLINE);
-       }
-       ctx->count++;
-
-       c = s->cache;
-       vty_out(ctx->vty, "%-8s %-24s %-24s %s%s",
-               nhrp_cache_type_str[s->type],
-               prefix2str(s->p, buf1, sizeof buf1),
-               c ? sockunion2str(&c->remote_addr, buf2, sizeof buf2) : "",
-               (c && c->cur.peer) ? c->cur.peer->vc->remote.id : "",
-               VTY_NEWLINE);
-}
-
 DEFUN(show_ip_nhrp, show_ip_nhrp_cmd,
-       "show " AFI_CMD " nhrp [cache|shortcut|opennhrp]",
+       "show " AFI_CMD " nhrp [cache|nhs|shortcut|opennhrp]",
        SHOW_STR
        AFI_STR
        "NHRP information\n"
        "Forwarding cache information\n"
+       "Next hop server information\n"
        "Shortcut information\n"
        "opennhrpctl style cache dump\n")
 {
@@ -676,13 +701,16 @@ DEFUN(show_ip_nhrp, show_ip_nhrp_cmd,
        if (argc <= 3 || argv[3]->text[0] == 'c') {
                for (ALL_LIST_ELEMENTS_RO(vrf_iflist(VRF_DEFAULT), node, ifp))
                        nhrp_cache_foreach(ifp, show_ip_nhrp_cache, &ctx);
-       } else if (argv[3]->text[0] == 'o') {
+       } else if (argv[3]->text[0] == 'n') {
+               for (ALL_LIST_ELEMENTS_RO(vrf_iflist(VRF_DEFAULT), node, ifp))
+                       nhrp_nhs_foreach(ifp, ctx.afi, show_ip_nhrp_nhs, &ctx);
+       } else if (argv[3]->text[0] == 's') {
+               nhrp_shortcut_foreach(ctx.afi, show_ip_nhrp_shortcut, &ctx);
+       } else {
                vty_out(vty, "Status: ok%s%s", VTY_NEWLINE, VTY_NEWLINE);
                ctx.count++;
                for (ALL_LIST_ELEMENTS_RO(vrf_iflist(VRF_DEFAULT), node, ifp))
                        nhrp_cache_foreach(ifp, show_ip_opennhrp_cache, &ctx);
-       } else {
-               nhrp_shortcut_foreach(ctx.afi, show_ip_nhrp_shortcut, &ctx);
        }
 
        if (!ctx.count) {
index cd2b0d5580f6f9894c988c9a022fa76d04ec7937..9a4f26d57710999a0639ef6c18bfbe29f8185d36 100644 (file)
@@ -254,6 +254,18 @@ struct nhrp_nhs {
        struct list_head reglist_head;
 };
 
+struct nhrp_registration {
+       struct list_head reglist_entry;
+       struct thread *t_register;
+       struct nhrp_nhs *nhs;
+       struct nhrp_reqid reqid;
+       unsigned int timeout;
+       unsigned mark : 1;
+       union sockunion proto_addr;
+       struct nhrp_peer *peer;
+       struct notifier_block peer_notifier;
+};
+
 #define NHRP_IFF_SHORTCUT              0x0001
 #define NHRP_IFF_REDIRECT              0x0002
 #define NHRP_IFF_REG_NO_UNIQUE         0x0100
@@ -311,6 +323,7 @@ int nhrp_nhs_add(struct interface *ifp, afi_t afi, union sockunion *proto_addr,
 int nhrp_nhs_del(struct interface *ifp, afi_t afi, union sockunion *proto_addr, const char *nbma_fqdn);
 int nhrp_nhs_free(struct nhrp_nhs *nhs);
 void nhrp_nhs_terminate(void);
+void nhrp_nhs_foreach(struct interface *ifp, afi_t afi, void (*cb)(struct nhrp_nhs *, struct nhrp_registration *, void *), void *ctx);
 
 void nhrp_route_update_nhrp(const struct prefix *p, struct interface *ifp);
 void nhrp_route_announce(int add, enum nhrp_cache_type type, const struct prefix *p, struct interface *ifp, const union sockunion *nexthop, uint32_t mtu);