From 0ca036b4569d695cfe668a0d9efbe7da94016673 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Timo=20Ter=C3=A4s?= Date: Sat, 25 Mar 2017 17:27:24 +0200 Subject: [PATCH] nhrpd: implement 'show ip nhrp nhs' --- nhrpd/nhrp_nhs.c | 28 ++++++++------- nhrpd/nhrp_vty.c | 88 +++++++++++++++++++++++++++++++----------------- nhrpd/nhrpd.h | 13 +++++++ 3 files changed, 86 insertions(+), 43 deletions(-) diff --git a/nhrpd/nhrp_nhs.c b/nhrpd/nhrp_nhs.c index 10245d308a..555c0d1de1 100644 --- a/nhrpd/nhrp_nhs.c +++ b/nhrpd/nhrp_nhs.c @@ -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); + } +} diff --git a/nhrpd/nhrp_vty.c b/nhrpd/nhrp_vty.c index 2e3164410c..f127d24dc8 100644 --- a/nhrpd/nhrp_vty.c +++ b/nhrpd/nhrp_vty.c @@ -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(®->peer->vc->remote.nbma, buf[0], sizeof buf[0]) : "-", + sockunion2str(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) { diff --git a/nhrpd/nhrpd.h b/nhrpd/nhrpd.h index cd2b0d5580..9a4f26d577 100644 --- a/nhrpd/nhrpd.h +++ b/nhrpd/nhrpd.h @@ -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); -- 2.39.5