2 * Copyright (c) 2014-2015 Timo Teräs
4 * This file is free software: you may copy, redistribute and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation, either version 2 of the License, or
7 * (at your option) any later version.
18 static struct cmd_node zebra_node = {
20 .prompt = "%s(config-router)# ",
24 static struct cmd_node nhrp_interface_node = {
25 .node = INTERFACE_NODE,
26 .prompt = "%s(config-if)# ",
30 #define NHRP_DEBUG_FLAGS_CMD "(all|common|event|interface|kernel|route|vici)"
32 #define NHRP_DEBUG_FLAGS_STR \
34 "Common messages (default)\n" \
35 "Event manager messages\n" \
36 "Interface messages\n" \
41 static const struct message debug_flags_desc[] = {
42 { NHRP_DEBUG_ALL, "all" },
43 { NHRP_DEBUG_COMMON, "common" },
44 { NHRP_DEBUG_IF, "interface" },
45 { NHRP_DEBUG_KERNEL, "kernel" },
46 { NHRP_DEBUG_ROUTE, "route" },
47 { NHRP_DEBUG_VICI, "vici" },
48 { NHRP_DEBUG_EVENT, "event" },
52 static const struct message interface_flags_desc[] = {
53 { NHRP_IFF_SHORTCUT, "shortcut" },
54 { NHRP_IFF_REDIRECT, "redirect" },
55 { NHRP_IFF_REG_NO_UNIQUE, "registration no-unique" },
59 static int nhrp_vty_return(struct vty *vty, int ret)
61 static const char * const errmsgs[] = {
62 [NHRP_ERR_FAIL] = "Command failed",
63 [NHRP_ERR_NO_MEMORY] = "Out of memory",
64 [NHRP_ERR_UNSUPPORTED_INTERFACE] = "NHRP not supported on this interface",
65 [NHRP_ERR_NHRP_NOT_ENABLED] = "NHRP not enabled (set 'nhrp network-id' first)",
66 [NHRP_ERR_ENTRY_EXISTS] = "Entry exists already",
67 [NHRP_ERR_ENTRY_NOT_FOUND] = "Entry not found",
68 [NHRP_ERR_PROTOCOL_ADDRESS_MISMATCH] = "Protocol address family does not match command (ip/ipv6 mismatch)",
70 const char *str = NULL;
76 if (ret > 0 && ret <= (int)ZEBRA_NUM_OF(errmsgs))
82 snprintf(buf, sizeof(buf), "Unknown error %d", ret);
85 vty_out (vty, "%% %s%s", str, VTY_NEWLINE);
90 static int toggle_flag(
91 struct vty *vty, const struct message *flag_desc,
92 const char *name, int on_off, unsigned *flags)
96 for (i = 0; flag_desc[i].str != NULL; i++) {
97 if (strcmp(flag_desc[i].str, name) != 0)
100 *flags |= flag_desc[i].key;
102 *flags &= ~flag_desc[i].key;
106 vty_out(vty, "%% Invalid value %s%s", name, VTY_NEWLINE);
112 DEFUN(show_debugging_nhrp, show_debugging_nhrp_cmd,
113 "show debugging nhrp",
115 "Debugging information\n"
116 "NHRP configuration\n")
120 vty_out(vty, "NHRP debugging status:%s", VTY_NEWLINE);
122 for (i = 0; debug_flags_desc[i].str != NULL; i++) {
123 if (debug_flags_desc[i].key == NHRP_DEBUG_ALL)
125 if (!(debug_flags_desc[i].key & debug_flags))
128 vty_out(vty, " NHRP %s debugging is on%s",
129 debug_flags_desc[i].str, VTY_NEWLINE);
135 DEFUN(debug_nhrp, debug_nhrp_cmd,
136 "debug nhrp " NHRP_DEBUG_FLAGS_CMD,
137 "Enable debug messages for specific or all parts.\n"
139 NHRP_DEBUG_FLAGS_STR)
141 return toggle_flag(vty, debug_flags_desc, argv[0], 1, &debug_flags);
144 DEFUN(no_debug_nhrp, no_debug_nhrp_cmd,
145 "no debug nhrp " NHRP_DEBUG_FLAGS_CMD,
147 "Disable debug messages for specific or all parts.\n"
149 NHRP_DEBUG_FLAGS_STR)
151 return toggle_flag(vty, debug_flags_desc, argv[0], 0, &debug_flags);
154 #endif /* NO_DEBUG */
156 static int nhrp_config_write(struct vty *vty)
159 if (debug_flags == NHRP_DEBUG_ALL) {
160 vty_out(vty, "debug nhrp all%s", VTY_NEWLINE);
164 for (i = 0; debug_flags_desc[i].str != NULL; i++) {
165 if (debug_flags_desc[i].key == NHRP_DEBUG_ALL)
167 if (!(debug_flags & debug_flags_desc[i].key))
169 vty_out(vty, "debug nhrp %s%s", debug_flags_desc[i].str, VTY_NEWLINE);
172 vty_out(vty, "!%s", VTY_NEWLINE);
173 #endif /* NO_DEBUG */
175 if (nhrp_event_socket_path) {
176 vty_out(vty, "nhrp event socket %s%s",
177 nhrp_event_socket_path, VTY_NEWLINE);
179 if (netlink_nflog_group) {
180 vty_out(vty, "nhrp nflog-group %d%s",
181 netlink_nflog_group, VTY_NEWLINE);
187 #define IP_STR "IP information\n"
188 #define IPV6_STR "IPv6 information\n"
189 #define AFI_CMD "(ip|ipv6)"
190 #define AFI_STR IP_STR IPV6_STR
191 #define NHRP_STR "Next Hop Resolution Protocol functions\n"
193 static afi_t cmd_to_afi(const char *cmd)
195 return strncmp(cmd, "ipv6", 4) == 0 ? AFI_IP6 : AFI_IP;
198 static const char *afi_to_cmd(afi_t afi)
200 if (afi == AFI_IP6) return "ipv6";
204 DEFUN(nhrp_event_socket, nhrp_event_socket_cmd,
205 "nhrp event socket SOCKET",
207 "Event Manager commands\n"
208 "Event Manager unix socket path\n"
209 "Unix path for the socket\n")
211 evmgr_set_socket(argv[0]);
215 DEFUN(no_nhrp_event_socket, no_nhrp_event_socket_cmd,
216 "no nhrp event socket [SOCKET]",
219 "Event Manager commands\n"
220 "Event Manager unix socket path\n"
221 "Unix path for the socket\n")
223 evmgr_set_socket(NULL);
227 DEFUN(nhrp_nflog_group, nhrp_nflog_group_cmd,
228 "nhrp nflog-group <1-65535>",
230 "Specify NFLOG group number\n"
231 "NFLOG group number\n")
235 VTY_GET_INTEGER_RANGE("nflog-group", nfgroup, argv[0], 1, 65535);
236 netlink_set_nflog_group(nfgroup);
241 DEFUN(no_nhrp_nflog_group, no_nhrp_nflog_group_cmd,
242 "no nhrp nflog-group [<1-65535>]",
245 "Specify NFLOG group number\n"
246 "NFLOG group number\n")
248 netlink_set_nflog_group(0);
252 DEFUN(tunnel_protection, tunnel_protection_cmd,
253 "tunnel protection vici profile PROFILE {fallback-profile FALLBACK}",
254 "NHRP/GRE integration\n"
256 "VICI (StrongSwan)\n"
258 "IPsec profile name\n"
259 "Fallback IPsec profile\n"
260 "Fallback IPsec profile name\n")
262 struct interface *ifp = vty->index;
264 nhrp_interface_set_protection(ifp, argv[0], argv[1]);
268 DEFUN(no_tunnel_protection, no_tunnel_protection_cmd,
269 "no tunnel protection",
271 "NHRP/GRE integration\n"
272 "IPsec protection\n")
274 struct interface *ifp = vty->index;
276 nhrp_interface_set_protection(ifp, NULL, NULL);
280 DEFUN(tunnel_source, tunnel_source_cmd,
281 "tunnel source INTERFACE",
282 "NHRP/GRE integration\n"
283 "Tunnel device binding tracking\n"
286 struct interface *ifp = vty->index;
287 nhrp_interface_set_source(ifp, argv[0]);
291 DEFUN(no_tunnel_source, no_tunnel_source_cmd,
293 "NHRP/GRE integration\n"
294 "Tunnel device binding tracking\n"
297 struct interface *ifp = vty->index;
298 nhrp_interface_set_source(ifp, NULL);
302 DEFUN(if_nhrp_network_id, if_nhrp_network_id_cmd,
303 AFI_CMD " nhrp network-id <1-4294967295>",
306 "Enable NHRP and specify network-id\n"
307 "System local ID to specify interface group\n")
309 struct interface *ifp = vty->index;
310 struct nhrp_interface *nifp = ifp->info;
311 afi_t afi = cmd_to_afi(argv[0]);
313 VTY_GET_INTEGER_RANGE("network-id", nifp->afi[afi].network_id, argv[1], 1, 4294967295);
314 nhrp_interface_update(ifp);
319 DEFUN(if_no_nhrp_network_id, if_no_nhrp_network_id_cmd,
320 "no " AFI_CMD " nhrp network-id [<1-4294967295>]",
324 "Enable NHRP and specify network-id\n"
325 "System local ID to specify interface group\n")
327 struct interface *ifp = vty->index;
328 struct nhrp_interface *nifp = ifp->info;
329 afi_t afi = cmd_to_afi(argv[0]);
331 nifp->afi[afi].network_id = 0;
332 nhrp_interface_update(ifp);
337 DEFUN(if_nhrp_flags, if_nhrp_flags_cmd,
338 AFI_CMD " nhrp (shortcut|redirect)",
341 "Allow shortcut establishment\n"
342 "Send redirect notifications\n")
344 struct interface *ifp = vty->index;
345 struct nhrp_interface *nifp = ifp->info;
346 afi_t afi = cmd_to_afi(argv[0]);
348 return toggle_flag(vty, interface_flags_desc, argv[1], 1, &nifp->afi[afi].flags);
351 DEFUN(if_no_nhrp_flags, if_no_nhrp_flags_cmd,
352 "no " AFI_CMD " nhrp (shortcut|redirect)",
356 "Allow shortcut establishment\n"
357 "Send redirect notifications\n")
359 struct interface *ifp = vty->index;
360 struct nhrp_interface *nifp = ifp->info;
361 afi_t afi = cmd_to_afi(argv[0]);
363 return toggle_flag(vty, interface_flags_desc, argv[1], 0, &nifp->afi[afi].flags);
366 DEFUN(if_nhrp_reg_flags, if_nhrp_reg_flags_cmd,
367 AFI_CMD " nhrp registration (no-unique)",
370 "Registration configuration\n"
371 "Don't set unique flag\n")
373 struct interface *ifp = vty->index;
374 struct nhrp_interface *nifp = ifp->info;
375 afi_t afi = cmd_to_afi(argv[0]);
377 snprintf(name, sizeof(name), "registration %s", argv[1]);
378 return toggle_flag(vty, interface_flags_desc, name, 1, &nifp->afi[afi].flags);
381 DEFUN(if_no_nhrp_reg_flags, if_no_nhrp_reg_flags_cmd,
382 "no " AFI_CMD " nhrp registration (no-unique)",
386 "Registration configuration\n"
387 "Don't set unique flag\n")
389 struct interface *ifp = vty->index;
390 struct nhrp_interface *nifp = ifp->info;
391 afi_t afi = cmd_to_afi(argv[0]);
393 snprintf(name, sizeof(name), "registration %s", argv[1]);
394 return toggle_flag(vty, interface_flags_desc, name, 0, &nifp->afi[afi].flags);
397 DEFUN(if_nhrp_holdtime, if_nhrp_holdtime_cmd,
398 AFI_CMD " nhrp holdtime <1-65000>",
401 "Specify NBMA address validity time\n"
402 "Time in seconds that NBMA addresses are advertised valid\n")
404 struct interface *ifp = vty->index;
405 struct nhrp_interface *nifp = ifp->info;
406 afi_t afi = cmd_to_afi(argv[0]);
408 VTY_GET_INTEGER_RANGE("holdtime", nifp->afi[afi].holdtime, argv[1], 1, 65000);
409 nhrp_interface_update(ifp);
414 DEFUN(if_no_nhrp_holdtime, if_no_nhrp_holdtime_cmd,
415 "no " AFI_CMD " nhrp holdtime [1-65000]",
419 "Specify NBMA address validity time\n"
420 "Time in seconds that NBMA addresses are advertised valid\n")
422 struct interface *ifp = vty->index;
423 struct nhrp_interface *nifp = ifp->info;
424 afi_t afi = cmd_to_afi(argv[0]);
426 nifp->afi[afi].holdtime = NHRPD_DEFAULT_HOLDTIME;
427 nhrp_interface_update(ifp);
432 DEFUN(if_nhrp_mtu, if_nhrp_mtu_cmd,
433 "ip nhrp mtu (<576-1500>|opennhrp)",
436 "Configure NHRP advertised MTU\n"
438 "Advertise bound interface MTU similar to OpenNHRP")
440 struct interface *ifp = vty->index;
441 struct nhrp_interface *nifp = ifp->info;
443 if (argv[0][0] == 'o') {
444 nifp->afi[AFI_IP].configured_mtu = -1;
446 VTY_GET_INTEGER_RANGE("mtu", nifp->afi[AFI_IP].configured_mtu, argv[0], 576, 1500);
448 nhrp_interface_update_mtu(ifp, AFI_IP);
453 DEFUN(if_no_nhrp_mtu, if_no_nhrp_mtu_cmd,
454 "no ip nhrp mtu [(<576-1500>|opennhrp)]",
458 "Configure NHRP advertised MTU\n"
460 "Advertise bound interface MTU similar to OpenNHRP")
462 struct interface *ifp = vty->index;
463 struct nhrp_interface *nifp = ifp->info;
465 nifp->afi[AFI_IP].configured_mtu = 0;
466 nhrp_interface_update_mtu(ifp, AFI_IP);
470 DEFUN(if_nhrp_map, if_nhrp_map_cmd,
471 AFI_CMD " nhrp map (A.B.C.D|X:X::X:X) (A.B.C.D|local)",
474 "Nexthop Server configuration\n"
475 "IPv4 protocol address\n"
476 "IPv6 protocol address\n"
477 "IPv4 NBMA address\n"
478 "Handle protocol address locally\n")
480 struct interface *ifp = vty->index;
481 afi_t afi = cmd_to_afi(argv[0]);
482 union sockunion proto_addr, nbma_addr;
483 struct nhrp_cache *c;
485 if (str2sockunion(argv[1], &proto_addr) < 0 ||
486 afi2family(afi) != sockunion_family(&proto_addr))
487 return nhrp_vty_return(vty, NHRP_ERR_PROTOCOL_ADDRESS_MISMATCH);
489 c = nhrp_cache_get(ifp, &proto_addr, 1);
491 return nhrp_vty_return(vty, NHRP_ERR_FAIL);
494 if (strcmp(argv[2], "local") == 0) {
495 nhrp_cache_update_binding(c, NHRP_CACHE_LOCAL, 0, NULL, 0, NULL);
497 if (str2sockunion(argv[2], &nbma_addr) < 0)
498 return nhrp_vty_return(vty, NHRP_ERR_FAIL);
499 nhrp_cache_update_binding(c, NHRP_CACHE_STATIC, 0,
500 nhrp_peer_get(ifp, &nbma_addr), 0, NULL);
506 DEFUN(if_no_nhrp_map, if_no_nhrp_map_cmd,
507 "no " AFI_CMD " nhrp map (A.B.C.D|X:X::X:X)",
511 "Nexthop Server configuration\n"
512 "IPv4 protocol address\n"
513 "IPv6 protocol address\n")
515 struct interface *ifp = vty->index;
516 afi_t afi = cmd_to_afi(argv[0]);
517 union sockunion proto_addr;
518 struct nhrp_cache *c;
520 if (str2sockunion(argv[1], &proto_addr) < 0 ||
521 afi2family(afi) != sockunion_family(&proto_addr))
522 return nhrp_vty_return(vty, NHRP_ERR_PROTOCOL_ADDRESS_MISMATCH);
524 c = nhrp_cache_get(ifp, &proto_addr, 0);
526 return nhrp_vty_return(vty, NHRP_ERR_ENTRY_NOT_FOUND);
528 nhrp_cache_update_binding(c, c->cur.type, -1, NULL, 0, NULL);
532 DEFUN(if_nhrp_nhs, if_nhrp_nhs_cmd,
533 AFI_CMD " nhrp nhs (A.B.C.D|X:X::X:X|dynamic) nbma (A.B.C.D|FQDN)",
536 "Nexthop Server configuration\n"
537 "IPv4 protocol address\n"
538 "IPv6 protocol address\n"
539 "Automatic detection of protocol address\n"
540 "IPv4 NBMA address\n"
541 "Fully qualified domain name for NBMA address(es)\n")
543 struct interface *ifp = vty->index;
544 afi_t afi = cmd_to_afi(argv[0]);
545 union sockunion proto_addr;
548 if (str2sockunion(argv[1], &proto_addr) < 0)
549 sockunion_family(&proto_addr) = AF_UNSPEC;
551 ret = nhrp_nhs_add(ifp, afi, &proto_addr, argv[2]);
552 return nhrp_vty_return(vty, ret);
555 DEFUN(if_no_nhrp_nhs, if_no_nhrp_nhs_cmd,
556 "no " AFI_CMD " nhrp nhs (A.B.C.D|X:X::X:X|dynamic) nbma (A.B.C.D|FQDN)",
560 "Nexthop Server configuration\n"
561 "IPv4 protocol address\n"
562 "IPv6 protocol address\n"
563 "Automatic detection of protocol address\n"
564 "IPv4 NBMA address\n"
565 "Fully qualified domain name for NBMA address(es)\n")
567 struct interface *ifp = vty->index;
568 afi_t afi = cmd_to_afi(argv[0]);
569 union sockunion proto_addr;
572 if (str2sockunion(argv[1], &proto_addr) < 0)
573 sockunion_family(&proto_addr) = AF_UNSPEC;
575 ret = nhrp_nhs_del(ifp, afi, &proto_addr, argv[2]);
576 return nhrp_vty_return(vty, ret);
585 static void show_ip_nhrp_cache(struct nhrp_cache *c, void *pctx)
587 struct info_ctx *ctx = pctx;
588 struct vty *vty = ctx->vty;
589 char buf[2][SU_ADDRSTRLEN];
591 if (ctx->afi != family2afi(sockunion_family(&c->remote_addr)))
595 vty_out(vty, "%-8s %-8s %-24s %-24s %-6s %s%s",
606 vty_out(ctx->vty, "%-8s %-8s %-24s %-24s %c%c%c %s%s",
608 nhrp_cache_type_str[c->cur.type],
609 sockunion2str(&c->remote_addr, buf[0], sizeof buf[0]),
610 c->cur.peer ? sockunion2str(&c->cur.peer->vc->remote.nbma, buf[1], sizeof buf[1]) : "-",
612 c->t_timeout ? 'T' : ' ',
613 c->t_auth ? 'A' : ' ',
614 c->cur.peer ? c->cur.peer->vc->remote.id : "-",
618 static void show_ip_nhrp_nhs(struct nhrp_nhs *n, struct nhrp_registration *reg, void *pctx)
620 struct info_ctx *ctx = pctx;
621 struct vty *vty = ctx->vty;
622 char buf[2][SU_ADDRSTRLEN];
625 vty_out(vty, "%-8s %-24s %-16s %-16s%s",
634 vty_out(vty, "%-8s %-24s %-16s %-16s%s",
637 (reg && reg->peer) ? sockunion2str(®->peer->vc->remote.nbma, buf[0], sizeof buf[0]) : "-",
638 sockunion2str(reg ? ®->proto_addr : &n->proto_addr, buf[1], sizeof buf[1]),
642 static void show_ip_nhrp_shortcut(struct nhrp_shortcut *s, void *pctx)
644 struct info_ctx *ctx = pctx;
645 struct nhrp_cache *c;
646 struct vty *vty = ctx->vty;
647 char buf1[PREFIX_STRLEN], buf2[SU_ADDRSTRLEN];
650 vty_out(vty, "%-8s %-24s %-24s %s%s",
660 vty_out(ctx->vty, "%-8s %-24s %-24s %s%s",
661 nhrp_cache_type_str[s->type],
662 prefix2str(s->p, buf1, sizeof buf1),
663 c ? sockunion2str(&c->remote_addr, buf2, sizeof buf2) : "",
664 (c && c->cur.peer) ? c->cur.peer->vc->remote.id : "",
668 static void show_ip_opennhrp_cache(struct nhrp_cache *c, void *pctx)
670 struct info_ctx *ctx = pctx;
671 struct vty *vty = ctx->vty;
672 char buf[SU_ADDRSTRLEN];
674 if (ctx->afi != family2afi(sockunion_family(&c->remote_addr)))
680 "Protocol-Address: %s/%zu%s",
681 nhrp_cache_type_str[c->cur.type],
683 (c->cur.peer && c->cur.peer->online) ? " up": "",
684 c->used ? " used": "",
686 sockunion2str(&c->remote_addr, buf, sizeof buf),
687 8 * family2addrsize(sockunion_family(&c->remote_addr)),
692 "NBMA-Address: %s%s",
693 sockunion2str(&c->cur.peer->vc->remote.nbma, buf, sizeof buf),
697 if (sockunion_family(&c->cur.remote_nbma_natoa) != AF_UNSPEC) {
699 "NBMA-NAT-OA-Address: %s%s",
700 sockunion2str(&c->cur.remote_nbma_natoa, buf, sizeof buf),
704 vty_out(ctx->vty, "%s", VTY_NEWLINE);
707 DEFUN(show_ip_nhrp, show_ip_nhrp_cmd,
708 "show " AFI_CMD " nhrp (cache|nhs|shortcut|opennhrp|)",
712 "Forwarding cache information\n"
713 "Next hop server information\n"
714 "Shortcut information\n"
715 "opennhrpctl style cache dump\n")
717 struct listnode *node;
718 struct interface *ifp;
719 struct info_ctx ctx = {
721 .afi = cmd_to_afi(argv[0]),
724 if (!argv[1] || argv[1][0] == 'c') {
725 for (ALL_LIST_ELEMENTS_RO(iflist, node, ifp))
726 nhrp_cache_foreach(ifp, show_ip_nhrp_cache, &ctx);
727 } else if (argv[1][0] == 'n') {
728 for (ALL_LIST_ELEMENTS_RO(iflist, node, ifp))
729 nhrp_nhs_foreach(ifp, ctx.afi, show_ip_nhrp_nhs, &ctx);
730 } else if (argv[1][0] == 's') {
731 nhrp_shortcut_foreach(ctx.afi, show_ip_nhrp_shortcut, &ctx);
733 vty_out(vty, "Status: ok%s%s", VTY_NEWLINE, VTY_NEWLINE);
735 for (ALL_LIST_ELEMENTS_RO(iflist, node, ifp))
736 nhrp_cache_foreach(ifp, show_ip_opennhrp_cache, &ctx);
740 vty_out(vty, "%% No entries%s", VTY_NEWLINE);
747 static void show_dmvpn_entry(struct nhrp_vc *vc, void *ctx)
749 struct vty *vty = ctx;
750 char buf[2][SU_ADDRSTRLEN];
752 vty_out(vty, "%-24s %-24s %c %-4d %-24s%s",
753 sockunion2str(&vc->local.nbma, buf[0], sizeof buf[0]),
754 sockunion2str(&vc->remote.nbma, buf[1], sizeof buf[1]),
755 notifier_active(&vc->notifier_list) ? 'n' : ' ',
761 DEFUN(show_dmvpn, show_dmvpn_cmd,
764 "DMVPN information\n")
766 vty_out(vty, "%-24s %-24s %-6s %-4s %-24s%s",
774 nhrp_vc_foreach(show_dmvpn_entry, vty);
779 static void clear_nhrp_cache(struct nhrp_cache *c, void *data)
781 struct info_ctx *ctx = data;
782 if (c->cur.type <= NHRP_CACHE_CACHED) {
783 nhrp_cache_update_binding(c, c->cur.type, -1, NULL, 0, NULL);
788 static void clear_nhrp_shortcut(struct nhrp_shortcut *s, void *data)
790 struct info_ctx *ctx = data;
791 nhrp_shortcut_purge(s, 1);
795 DEFUN(clear_nhrp, clear_nhrp_cmd,
796 "clear " AFI_CMD " nhrp (cache|shortcut)",
800 "Dynamic cache entries\n"
801 "Shortcut entries\n")
803 struct listnode *node;
804 struct interface *ifp;
805 struct info_ctx ctx = {
807 .afi = cmd_to_afi(argv[0]),
811 if (!argv[1] || argv[1][0] == 'c') {
812 for (ALL_LIST_ELEMENTS_RO(iflist, node, ifp))
813 nhrp_cache_foreach(ifp, clear_nhrp_cache, &ctx);
815 nhrp_shortcut_foreach(ctx.afi, clear_nhrp_shortcut, &ctx);
819 vty_out(vty, "%% No entries%s", VTY_NEWLINE);
823 vty_out(vty, "%% %d entries cleared%s", ctx.count, VTY_NEWLINE);
827 struct write_map_ctx {
833 static void interface_config_write_nhrp_map(struct nhrp_cache *c, void *data)
835 struct write_map_ctx *ctx = data;
836 struct vty *vty = ctx->vty;
837 char buf[2][SU_ADDRSTRLEN];
840 if (sockunion_family(&c->remote_addr) != ctx->family) return;
842 vty_out(vty, " %s nhrp map %s %s%s",
844 sockunion2str(&c->remote_addr, buf[0], sizeof buf[0]),
845 c->cur.type == NHRP_CACHE_LOCAL ? "local" :
846 sockunion2str(&c->cur.peer->vc->remote.nbma, buf[1], sizeof buf[1]),
850 static int interface_config_write(struct vty *vty)
852 struct write_map_ctx mapctx;
853 struct listnode *node;
854 struct interface *ifp;
855 struct nhrp_interface *nifp;
856 struct nhrp_nhs *nhs;
859 char buf[SU_ADDRSTRLEN];
862 for (ALL_LIST_ELEMENTS_RO(iflist, node, ifp)) {
863 vty_out(vty, "interface %s%s", ifp->name, VTY_NEWLINE);
865 vty_out(vty, " description %s%s", ifp->desc, VTY_NEWLINE);
868 if (nifp->ipsec_profile) {
869 vty_out(vty, " tunnel protection vici profile %s",
870 nifp->ipsec_profile);
871 if (nifp->ipsec_fallback_profile)
872 vty_out(vty, " fallback-profile %s",
873 nifp->ipsec_fallback_profile);
874 vty_out(vty, "%s", VTY_NEWLINE);
877 vty_out(vty, " tunnel source %s%s",
878 nifp->source, VTY_NEWLINE);
880 for (afi = 0; afi < AFI_MAX; afi++) {
881 struct nhrp_afi_data *ad = &nifp->afi[afi];
883 aficmd = afi_to_cmd(afi);
886 vty_out(vty, " %s nhrp network-id %u%s",
887 aficmd, ad->network_id,
890 if (ad->holdtime != NHRPD_DEFAULT_HOLDTIME)
891 vty_out(vty, " %s nhrp holdtime %u%s",
892 aficmd, ad->holdtime,
895 if (ad->configured_mtu < 0)
896 vty_out(vty, " %s nhrp mtu opennhrp%s",
897 aficmd, VTY_NEWLINE);
898 else if (ad->configured_mtu)
899 vty_out(vty, " %s nhrp mtu %u%s",
900 aficmd, ad->configured_mtu,
903 for (i = 0; interface_flags_desc[i].str != NULL; i++) {
904 if (!(ad->flags & interface_flags_desc[i].key))
906 vty_out(vty, " %s nhrp %s%s",
907 aficmd, interface_flags_desc[i].str, VTY_NEWLINE);
910 mapctx = (struct write_map_ctx) {
912 .family = afi2family(afi),
915 nhrp_cache_foreach(ifp, interface_config_write_nhrp_map, &mapctx);
917 list_for_each_entry(nhs, &ad->nhslist_head, nhslist_entry) {
918 vty_out(vty, " %s nhrp nhs %s nbma %s%s",
920 sockunion_family(&nhs->proto_addr) == AF_UNSPEC ? "dynamic" : sockunion2str(&nhs->proto_addr, buf, sizeof buf),
926 vty_out (vty, "!%s", VTY_NEWLINE);
932 void nhrp_config_init(void)
934 install_node(&zebra_node, nhrp_config_write);
935 install_default(ZEBRA_NODE);
937 /* global commands */
938 install_element(VIEW_NODE, &show_debugging_nhrp_cmd);
939 install_element(VIEW_NODE, &show_ip_nhrp_cmd);
940 install_element(VIEW_NODE, &show_dmvpn_cmd);
941 install_element(ENABLE_NODE, &show_debugging_nhrp_cmd);
942 install_element(ENABLE_NODE, &show_ip_nhrp_cmd);
943 install_element(ENABLE_NODE, &show_dmvpn_cmd);
944 install_element(ENABLE_NODE, &clear_nhrp_cmd);
946 install_element(ENABLE_NODE, &debug_nhrp_cmd);
947 install_element(ENABLE_NODE, &no_debug_nhrp_cmd);
949 install_element(CONFIG_NODE, &debug_nhrp_cmd);
950 install_element(CONFIG_NODE, &no_debug_nhrp_cmd);
952 install_element(CONFIG_NODE, &nhrp_event_socket_cmd);
953 install_element(CONFIG_NODE, &no_nhrp_event_socket_cmd);
954 install_element(CONFIG_NODE, &nhrp_nflog_group_cmd);
955 install_element(CONFIG_NODE, &no_nhrp_nflog_group_cmd);
957 /* interface specific commands */
958 install_node(&nhrp_interface_node, interface_config_write);
959 install_default(INTERFACE_NODE);
961 install_element(CONFIG_NODE, &interface_cmd);
962 install_element(CONFIG_NODE, &no_interface_cmd);
963 install_element(INTERFACE_NODE, &interface_cmd);
964 install_element(INTERFACE_NODE, &no_interface_cmd);
965 install_element(INTERFACE_NODE, &tunnel_protection_cmd);
966 install_element(INTERFACE_NODE, &no_tunnel_protection_cmd);
967 install_element(INTERFACE_NODE, &tunnel_source_cmd);
968 install_element(INTERFACE_NODE, &no_tunnel_source_cmd);
969 install_element(INTERFACE_NODE, &if_nhrp_network_id_cmd);
970 install_element(INTERFACE_NODE, &if_no_nhrp_network_id_cmd);
971 install_element(INTERFACE_NODE, &if_nhrp_holdtime_cmd);
972 install_element(INTERFACE_NODE, &if_no_nhrp_holdtime_cmd);
973 install_element(INTERFACE_NODE, &if_nhrp_mtu_cmd);
974 install_element(INTERFACE_NODE, &if_no_nhrp_mtu_cmd);
975 install_element(INTERFACE_NODE, &if_nhrp_flags_cmd);
976 install_element(INTERFACE_NODE, &if_no_nhrp_flags_cmd);
977 install_element(INTERFACE_NODE, &if_nhrp_reg_flags_cmd);
978 install_element(INTERFACE_NODE, &if_no_nhrp_reg_flags_cmd);
979 install_element(INTERFACE_NODE, &if_nhrp_map_cmd);
980 install_element(INTERFACE_NODE, &if_no_nhrp_map_cmd);
981 install_element(INTERFACE_NODE, &if_nhrp_nhs_cmd);
982 install_element(INTERFACE_NODE, &if_no_nhrp_nhs_cmd);