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.
19 static struct cmd_node zebra_node
= {
21 .prompt
= "%s(config-router)# ",
25 static struct cmd_node nhrp_interface_node
= {
26 .node
= INTERFACE_NODE
,
27 .prompt
= "%s(config-if)# ",
31 #define NHRP_DEBUG_FLAGS_CMD "<all|common|event|interface|kernel|route|vici>"
33 #define NHRP_DEBUG_FLAGS_STR \
35 "Common messages (default)\n" \
36 "Event manager messages\n" \
37 "Interface messages\n" \
42 static const struct message debug_flags_desc
[] = {
43 { NHRP_DEBUG_ALL
, "all" },
44 { NHRP_DEBUG_COMMON
, "common" },
45 { NHRP_DEBUG_IF
, "interface" },
46 { NHRP_DEBUG_KERNEL
, "kernel" },
47 { NHRP_DEBUG_ROUTE
, "route" },
48 { NHRP_DEBUG_VICI
, "vici" },
49 { NHRP_DEBUG_EVENT
, "event" },
53 static const struct message interface_flags_desc
[] = {
54 { NHRP_IFF_SHORTCUT
, "shortcut" },
55 { NHRP_IFF_REDIRECT
, "redirect" },
56 { NHRP_IFF_REG_NO_UNIQUE
, "registration no-unique" },
60 static int nhrp_vty_return(struct vty
*vty
, int ret
)
62 static const char * const errmsgs
[] = {
63 [NHRP_ERR_FAIL
] = "Command failed",
64 [NHRP_ERR_NO_MEMORY
] = "Out of memory",
65 [NHRP_ERR_UNSUPPORTED_INTERFACE
] = "NHRP not supported on this interface",
66 [NHRP_ERR_NHRP_NOT_ENABLED
] = "NHRP not enabled (set 'nhrp network-id' first)",
67 [NHRP_ERR_ENTRY_EXISTS
] = "Entry exists already",
68 [NHRP_ERR_ENTRY_NOT_FOUND
] = "Entry not found",
69 [NHRP_ERR_PROTOCOL_ADDRESS_MISMATCH
] = "Protocol address family does not match command (ip/ipv6 mismatch)",
71 const char *str
= NULL
;
77 if (ret
> 0 && ret
<= NHRP_ERR_MAX
)
83 snprintf(buf
, sizeof(buf
), "Unknown error %d", ret
);
86 vty_out (vty
, "%% %s\n", str
);
88 return CMD_WARNING_CONFIG_FAILED
;;
91 static int toggle_flag(
92 struct vty
*vty
, const struct message
*flag_desc
,
93 const char *name
, int on_off
, unsigned *flags
)
97 for (i
= 0; flag_desc
[i
].str
!= NULL
; i
++) {
98 if (strcmp(flag_desc
[i
].str
, name
) != 0)
101 *flags
|= flag_desc
[i
].key
;
103 *flags
&= ~flag_desc
[i
].key
;
107 vty_out (vty
, "%% Invalid value %s\n", name
);
108 return CMD_WARNING_CONFIG_FAILED
;;
113 DEFUN_NOSH(show_debugging_nhrp
, show_debugging_nhrp_cmd
,
114 "show debugging [nhrp]",
116 "Debugging information\n"
117 "NHRP configuration\n")
121 vty_out (vty
, "NHRP debugging status:\n");
123 for (i
= 0; debug_flags_desc
[i
].str
!= NULL
; i
++) {
124 if (debug_flags_desc
[i
].key
== NHRP_DEBUG_ALL
)
126 if (!(debug_flags_desc
[i
].key
& debug_flags
))
129 vty_out (vty
, " NHRP %s debugging is on\n",
130 debug_flags_desc
[i
].str
);
136 DEFUN(debug_nhrp
, debug_nhrp_cmd
,
137 "debug nhrp " NHRP_DEBUG_FLAGS_CMD
,
138 "Enable debug messages for specific or all parts.\n"
140 NHRP_DEBUG_FLAGS_STR
)
142 return toggle_flag(vty
, debug_flags_desc
, argv
[2]->text
, 1, &debug_flags
);
145 DEFUN(no_debug_nhrp
, no_debug_nhrp_cmd
,
146 "no debug nhrp " NHRP_DEBUG_FLAGS_CMD
,
148 "Disable debug messages for specific or all parts.\n"
150 NHRP_DEBUG_FLAGS_STR
)
152 return toggle_flag(vty
, debug_flags_desc
, argv
[3]->text
, 0, &debug_flags
);
155 #endif /* NO_DEBUG */
157 static int nhrp_config_write(struct vty
*vty
)
160 if (debug_flags
== NHRP_DEBUG_ALL
) {
161 vty_out (vty
, "debug nhrp all\n");
165 for (i
= 0; debug_flags_desc
[i
].str
!= NULL
; i
++) {
166 if (debug_flags_desc
[i
].key
== NHRP_DEBUG_ALL
)
168 if (!(debug_flags
& debug_flags_desc
[i
].key
))
170 vty_out (vty
, "debug nhrp %s\n",
171 debug_flags_desc
[i
].str
);
174 vty_out (vty
, "!\n");
175 #endif /* NO_DEBUG */
177 if (nhrp_event_socket_path
) {
178 vty_out (vty
, "nhrp event socket %s\n",
179 nhrp_event_socket_path
);
181 if (netlink_nflog_group
) {
182 vty_out (vty
, "nhrp nflog-group %d\n",
183 netlink_nflog_group
);
189 #define IP_STR "IP information\n"
190 #define IPV6_STR "IPv6 information\n"
191 #define AFI_CMD "<ip|ipv6>"
192 #define AFI_STR IP_STR IPV6_STR
193 #define NHRP_STR "Next Hop Resolution Protocol functions\n"
195 static afi_t
cmd_to_afi(const struct cmd_token
*tok
)
197 return strcmp(tok
->text
, "ipv6") == 0 ? AFI_IP6
: AFI_IP
;
200 static const char *afi_to_cmd(afi_t afi
)
202 if (afi
== AFI_IP6
) return "ipv6";
206 DEFUN(nhrp_event_socket
, nhrp_event_socket_cmd
,
207 "nhrp event socket SOCKET",
209 "Event Manager commands\n"
210 "Event Manager unix socket path\n"
211 "Unix path for the socket\n")
213 evmgr_set_socket(argv
[3]->arg
);
217 DEFUN(no_nhrp_event_socket
, no_nhrp_event_socket_cmd
,
218 "no nhrp event socket [SOCKET]",
221 "Event Manager commands\n"
222 "Event Manager unix socket path\n"
223 "Unix path for the socket\n")
225 evmgr_set_socket(NULL
);
229 DEFUN(nhrp_nflog_group
, nhrp_nflog_group_cmd
,
230 "nhrp nflog-group (1-65535)",
232 "Specify NFLOG group number\n"
233 "NFLOG group number\n")
237 nfgroup
= strtoul(argv
[2]->arg
, NULL
, 10);
238 netlink_set_nflog_group(nfgroup
);
243 DEFUN(no_nhrp_nflog_group
, no_nhrp_nflog_group_cmd
,
244 "no nhrp nflog-group [(1-65535)]",
247 "Specify NFLOG group number\n"
248 "NFLOG group number\n")
250 netlink_set_nflog_group(0);
254 DEFUN(tunnel_protection
, tunnel_protection_cmd
,
255 "tunnel protection vici profile PROFILE [fallback-profile FALLBACK]",
256 "NHRP/GRE integration\n"
258 "VICI (StrongSwan)\n"
260 "IPsec profile name\n"
261 "Fallback IPsec profile\n"
262 "Fallback IPsec profile name\n")
264 VTY_DECLVAR_CONTEXT(interface
, ifp
);
266 nhrp_interface_set_protection(ifp
, argv
[4]->arg
,
267 argc
> 6 ? argv
[6]->arg
: NULL
);
271 DEFUN(no_tunnel_protection
, no_tunnel_protection_cmd
,
272 "no tunnel protection",
274 "NHRP/GRE integration\n"
275 "IPsec protection\n")
277 VTY_DECLVAR_CONTEXT(interface
, ifp
);
279 nhrp_interface_set_protection(ifp
, NULL
, NULL
);
283 DEFUN(tunnel_source
, tunnel_source_cmd
,
284 "tunnel source INTERFACE",
285 "NHRP/GRE integration\n"
286 "Tunnel device binding tracking\n"
289 VTY_DECLVAR_CONTEXT(interface
, ifp
);
290 nhrp_interface_set_source(ifp
, argv
[2]->arg
);
294 DEFUN(no_tunnel_source
, no_tunnel_source_cmd
,
296 "NHRP/GRE integration\n"
297 "Tunnel device binding tracking\n"
300 VTY_DECLVAR_CONTEXT(interface
, ifp
);
301 nhrp_interface_set_source(ifp
, NULL
);
305 DEFUN(if_nhrp_network_id
, if_nhrp_network_id_cmd
,
306 AFI_CMD
" nhrp network-id (1-4294967295)",
309 "Enable NHRP and specify network-id\n"
310 "System local ID to specify interface group\n")
312 VTY_DECLVAR_CONTEXT(interface
, ifp
);
313 struct nhrp_interface
*nifp
= ifp
->info
;
314 afi_t afi
= cmd_to_afi(argv
[0]);
316 nifp
->afi
[afi
].network_id
= strtoul(argv
[3]->arg
, NULL
, 10);
317 nhrp_interface_update(ifp
);
322 DEFUN(if_no_nhrp_network_id
, if_no_nhrp_network_id_cmd
,
323 "no " AFI_CMD
" nhrp network-id [(1-4294967295)]",
327 "Enable NHRP and specify network-id\n"
328 "System local ID to specify interface group\n")
330 VTY_DECLVAR_CONTEXT(interface
, ifp
);
331 struct nhrp_interface
*nifp
= ifp
->info
;
332 afi_t afi
= cmd_to_afi(argv
[1]);
334 nifp
->afi
[afi
].network_id
= 0;
335 nhrp_interface_update(ifp
);
340 DEFUN(if_nhrp_flags
, if_nhrp_flags_cmd
,
341 AFI_CMD
" nhrp <shortcut|redirect>",
344 "Allow shortcut establishment\n"
345 "Send redirect notifications\n")
347 VTY_DECLVAR_CONTEXT(interface
, ifp
);
348 struct nhrp_interface
*nifp
= ifp
->info
;
349 afi_t afi
= cmd_to_afi(argv
[0]);
351 return toggle_flag(vty
, interface_flags_desc
, argv
[2]->text
, 1, &nifp
->afi
[afi
].flags
);
354 DEFUN(if_no_nhrp_flags
, if_no_nhrp_flags_cmd
,
355 "no " AFI_CMD
" nhrp <shortcut|redirect>",
359 "Allow shortcut establishment\n"
360 "Send redirect notifications\n")
362 VTY_DECLVAR_CONTEXT(interface
, ifp
);
363 struct nhrp_interface
*nifp
= ifp
->info
;
364 afi_t afi
= cmd_to_afi(argv
[1]);
366 return toggle_flag(vty
, interface_flags_desc
, argv
[3]->text
, 0, &nifp
->afi
[afi
].flags
);
369 DEFUN(if_nhrp_reg_flags
, if_nhrp_reg_flags_cmd
,
370 AFI_CMD
" nhrp registration no-unique",
373 "Registration configuration\n"
374 "Don't set unique flag\n")
376 VTY_DECLVAR_CONTEXT(interface
, ifp
);
377 struct nhrp_interface
*nifp
= ifp
->info
;
378 afi_t afi
= cmd_to_afi(argv
[0]);
380 snprintf(name
, sizeof(name
), "registration %s", argv
[3]->text
);
381 return toggle_flag(vty
, interface_flags_desc
, name
, 1, &nifp
->afi
[afi
].flags
);
384 DEFUN(if_no_nhrp_reg_flags
, if_no_nhrp_reg_flags_cmd
,
385 "no " AFI_CMD
" nhrp registration no-unique",
389 "Registration configuration\n"
390 "Don't set unique flag\n")
392 VTY_DECLVAR_CONTEXT(interface
, ifp
);
393 struct nhrp_interface
*nifp
= ifp
->info
;
394 afi_t afi
= cmd_to_afi(argv
[1]);
396 snprintf(name
, sizeof(name
), "registration %s", argv
[4]->text
);
397 return toggle_flag(vty
, interface_flags_desc
, name
, 0, &nifp
->afi
[afi
].flags
);
400 DEFUN(if_nhrp_holdtime
, if_nhrp_holdtime_cmd
,
401 AFI_CMD
" nhrp holdtime (1-65000)",
404 "Specify NBMA address validity time\n"
405 "Time in seconds that NBMA addresses are advertised valid\n")
407 VTY_DECLVAR_CONTEXT(interface
, ifp
);
408 struct nhrp_interface
*nifp
= ifp
->info
;
409 afi_t afi
= cmd_to_afi(argv
[0]);
411 nifp
->afi
[afi
].holdtime
= strtoul(argv
[3]->arg
, NULL
, 10);
412 nhrp_interface_update(ifp
);
417 DEFUN(if_no_nhrp_holdtime
, if_no_nhrp_holdtime_cmd
,
418 "no " AFI_CMD
" nhrp holdtime [(1-65000)]",
422 "Specify NBMA address validity time\n"
423 "Time in seconds that NBMA addresses are advertised valid\n")
425 VTY_DECLVAR_CONTEXT(interface
, ifp
);
426 struct nhrp_interface
*nifp
= ifp
->info
;
427 afi_t afi
= cmd_to_afi(argv
[1]);
429 nifp
->afi
[afi
].holdtime
= NHRPD_DEFAULT_HOLDTIME
;
430 nhrp_interface_update(ifp
);
435 DEFUN(if_nhrp_mtu
, if_nhrp_mtu_cmd
,
436 "ip nhrp mtu <(576-1500)|opennhrp>",
439 "Configure NHRP advertised MTU\n"
441 "Advertise bound interface MTU similar to OpenNHRP")
443 VTY_DECLVAR_CONTEXT(interface
, ifp
);
444 struct nhrp_interface
*nifp
= ifp
->info
;
446 if (argv
[3]->arg
[0] == 'o') {
447 nifp
->afi
[AFI_IP
].configured_mtu
= -1;
449 nifp
->afi
[AFI_IP
].configured_mtu
= strtoul(argv
[3]->arg
, NULL
,
452 nhrp_interface_update_mtu(ifp
, AFI_IP
);
457 DEFUN(if_no_nhrp_mtu
, if_no_nhrp_mtu_cmd
,
458 "no ip nhrp mtu [(576-1500)|opennhrp]",
462 "Configure NHRP advertised MTU\n"
464 "Advertise bound interface MTU similar to OpenNHRP")
466 VTY_DECLVAR_CONTEXT(interface
, ifp
);
467 struct nhrp_interface
*nifp
= ifp
->info
;
469 nifp
->afi
[AFI_IP
].configured_mtu
= 0;
470 nhrp_interface_update_mtu(ifp
, AFI_IP
);
474 DEFUN(if_nhrp_map
, if_nhrp_map_cmd
,
475 AFI_CMD
" nhrp map <A.B.C.D|X:X::X:X> <A.B.C.D|local>",
478 "Nexthop Server configuration\n"
479 "IPv4 protocol address\n"
480 "IPv6 protocol address\n"
481 "IPv4 NBMA address\n"
482 "Handle protocol address locally\n")
484 VTY_DECLVAR_CONTEXT(interface
, ifp
);
485 afi_t afi
= cmd_to_afi(argv
[0]);
486 union sockunion proto_addr
, nbma_addr
;
487 struct nhrp_cache
*c
;
489 if (str2sockunion(argv
[3]->arg
, &proto_addr
) < 0 ||
490 afi2family(afi
) != sockunion_family(&proto_addr
))
491 return nhrp_vty_return(vty
, NHRP_ERR_PROTOCOL_ADDRESS_MISMATCH
);
493 c
= nhrp_cache_get(ifp
, &proto_addr
, 1);
495 return nhrp_vty_return(vty
, NHRP_ERR_FAIL
);
498 if (strmatch(argv
[4]->text
, "local")) {
499 nhrp_cache_update_binding(c
, NHRP_CACHE_LOCAL
, 0, NULL
, 0, NULL
);
501 if (str2sockunion(argv
[4]->arg
, &nbma_addr
) < 0)
502 return nhrp_vty_return(vty
, NHRP_ERR_FAIL
);
503 nhrp_cache_update_binding(c
, NHRP_CACHE_STATIC
, 0,
504 nhrp_peer_get(ifp
, &nbma_addr
), 0, NULL
);
510 DEFUN(if_no_nhrp_map
, if_no_nhrp_map_cmd
,
511 "no " AFI_CMD
" nhrp map <A.B.C.D|X:X::X:X>",
515 "Nexthop Server configuration\n"
516 "IPv4 protocol address\n"
517 "IPv6 protocol address\n")
519 VTY_DECLVAR_CONTEXT(interface
,ifp
);
520 afi_t afi
= cmd_to_afi(argv
[1]);
521 union sockunion proto_addr
;
522 struct nhrp_cache
*c
;
524 if (str2sockunion(argv
[4]->arg
, &proto_addr
) < 0 ||
525 afi2family(afi
) != sockunion_family(&proto_addr
))
526 return nhrp_vty_return(vty
, NHRP_ERR_PROTOCOL_ADDRESS_MISMATCH
);
528 c
= nhrp_cache_get(ifp
, &proto_addr
, 0);
530 return nhrp_vty_return(vty
, NHRP_ERR_ENTRY_NOT_FOUND
);
532 nhrp_cache_update_binding(c
, c
->cur
.type
, -1, NULL
, 0, NULL
);
536 DEFUN(if_nhrp_nhs
, if_nhrp_nhs_cmd
,
537 AFI_CMD
" nhrp nhs <A.B.C.D|X:X::X:X|dynamic> nbma <A.B.C.D|FQDN>",
540 "Nexthop Server configuration\n"
541 "IPv4 protocol address\n"
542 "IPv6 protocol address\n"
543 "Automatic detection of protocol address\n"
545 "IPv4 NBMA address\n"
546 "Fully qualified domain name for NBMA address(es)\n")
548 VTY_DECLVAR_CONTEXT(interface
, ifp
);
549 afi_t afi
= cmd_to_afi(argv
[0]);
550 union sockunion proto_addr
;
553 if (str2sockunion(argv
[3]->arg
, &proto_addr
) < 0)
554 sockunion_family(&proto_addr
) = AF_UNSPEC
;
556 ret
= nhrp_nhs_add(ifp
, afi
, &proto_addr
, argv
[5]->arg
);
557 return nhrp_vty_return(vty
, ret
);
560 DEFUN(if_no_nhrp_nhs
, if_no_nhrp_nhs_cmd
,
561 "no " AFI_CMD
" nhrp nhs <A.B.C.D|X:X::X:X|dynamic> nbma <A.B.C.D|FQDN>",
565 "Nexthop Server configuration\n"
566 "IPv4 protocol address\n"
567 "IPv6 protocol address\n"
568 "Automatic detection of protocol address\n"
570 "IPv4 NBMA address\n"
571 "Fully qualified domain name for NBMA address(es)\n")
573 VTY_DECLVAR_CONTEXT(interface
, ifp
);
574 afi_t afi
= cmd_to_afi(argv
[1]);
575 union sockunion proto_addr
;
578 if (str2sockunion(argv
[4]->arg
, &proto_addr
) < 0)
579 sockunion_family(&proto_addr
) = AF_UNSPEC
;
581 ret
= nhrp_nhs_del(ifp
, afi
, &proto_addr
, argv
[6]->arg
);
582 return nhrp_vty_return(vty
, ret
);
591 static void show_ip_nhrp_cache(struct nhrp_cache
*c
, void *pctx
)
593 struct info_ctx
*ctx
= pctx
;
594 struct vty
*vty
= ctx
->vty
;
595 char buf
[2][SU_ADDRSTRLEN
];
597 if (ctx
->afi
!= family2afi(sockunion_family(&c
->remote_addr
)))
601 vty_out (vty
, "%-8s %-8s %-24s %-24s %-6s %s\n",
611 vty_out(ctx
->vty
, "%-8s %-8s %-24s %-24s %c%c%c %s\n",
613 nhrp_cache_type_str
[c
->cur
.type
],
614 sockunion2str(&c
->remote_addr
, buf
[0], sizeof buf
[0]),
615 c
->cur
.peer
? sockunion2str(&c
->cur
.peer
->vc
->remote
.nbma
, buf
[1], sizeof buf
[1]) : "-",
617 c
->t_timeout
? 'T' : ' ',
618 c
->t_auth
? 'A' : ' ',
619 c
->cur
.peer
? c
->cur
.peer
->vc
->remote
.id
: "-");
622 static void show_ip_nhrp_nhs(struct nhrp_nhs
*n
, struct nhrp_registration
*reg
, void *pctx
)
624 struct info_ctx
*ctx
= pctx
;
625 struct vty
*vty
= ctx
->vty
;
626 char buf
[2][SU_ADDRSTRLEN
];
629 vty_out (vty
, "%-8s %-24s %-16s %-16s\n",
637 vty_out (vty
, "%-8s %-24s %-16s %-16s\n",
640 (reg
&& reg
->peer
) ? sockunion2str(®
->peer
->vc
->remote
.nbma
,
641 buf
[0], sizeof buf
[0])
643 sockunion2str(reg
? ®
->proto_addr
: &n
->proto_addr
,
644 buf
[1], sizeof buf
[1]));
647 static void show_ip_nhrp_shortcut(struct nhrp_shortcut
*s
, void *pctx
)
649 struct info_ctx
*ctx
= pctx
;
650 struct nhrp_cache
*c
;
651 struct vty
*vty
= ctx
->vty
;
652 char buf1
[PREFIX_STRLEN
], buf2
[SU_ADDRSTRLEN
];
655 vty_out (vty
, "%-8s %-24s %-24s %s\n",
664 vty_out(ctx
->vty
, "%-8s %-24s %-24s %s\n",
665 nhrp_cache_type_str
[s
->type
],
666 prefix2str(s
->p
, buf1
, sizeof buf1
),
667 c
? sockunion2str(&c
->remote_addr
, buf2
, sizeof buf2
) : "",
668 (c
&& c
->cur
.peer
) ? c
->cur
.peer
->vc
->remote
.id
: "");
671 static void show_ip_opennhrp_cache(struct nhrp_cache
*c
, void *pctx
)
673 struct info_ctx
*ctx
= pctx
;
674 char buf
[SU_ADDRSTRLEN
];
676 if (ctx
->afi
!= family2afi(sockunion_family(&c
->remote_addr
)))
682 "Protocol-Address: %s/%zu\n",
683 nhrp_cache_type_str
[c
->cur
.type
],
684 (c
->cur
.peer
&& c
->cur
.peer
->online
) ? " up": "",
685 c
->used
? " used": "",
686 sockunion2str(&c
->remote_addr
, buf
, sizeof buf
),
687 8 * family2addrsize(sockunion_family(&c
->remote_addr
)));
691 "NBMA-Address: %s\n",
692 sockunion2str(&c
->cur
.peer
->vc
->remote
.nbma
,
696 if (sockunion_family(&c
->cur
.remote_nbma_natoa
) != AF_UNSPEC
) {
698 "NBMA-NAT-OA-Address: %s\n",
699 sockunion2str(&c
->cur
.remote_nbma_natoa
, buf
, sizeof buf
));
702 vty_out(ctx
->vty
, "\n\n");
705 DEFUN(show_ip_nhrp
, show_ip_nhrp_cmd
,
706 "show " AFI_CMD
" nhrp [cache|nhs|shortcut|opennhrp]",
710 "Forwarding cache information\n"
711 "Next hop server information\n"
712 "Shortcut information\n"
713 "opennhrpctl style cache dump\n")
715 struct listnode
*node
;
716 struct interface
*ifp
;
717 struct info_ctx ctx
= {
719 .afi
= cmd_to_afi(argv
[1]),
722 if (argc
<= 3 || argv
[3]->text
[0] == 'c') {
723 for (ALL_LIST_ELEMENTS_RO(vrf_iflist(VRF_DEFAULT
), node
, ifp
))
724 nhrp_cache_foreach(ifp
, show_ip_nhrp_cache
, &ctx
);
725 } else if (argv
[3]->text
[0] == 'n') {
726 for (ALL_LIST_ELEMENTS_RO(vrf_iflist(VRF_DEFAULT
), node
, ifp
))
727 nhrp_nhs_foreach(ifp
, ctx
.afi
, show_ip_nhrp_nhs
, &ctx
);
728 } else if (argv
[3]->text
[0] == 's') {
729 nhrp_shortcut_foreach(ctx
.afi
, show_ip_nhrp_shortcut
, &ctx
);
731 vty_out (vty
, "Status: ok\n\n");
733 for (ALL_LIST_ELEMENTS_RO(vrf_iflist(VRF_DEFAULT
), node
, ifp
))
734 nhrp_cache_foreach(ifp
, show_ip_opennhrp_cache
, &ctx
);
738 vty_out (vty
, "%% No entries\n");
745 static void show_dmvpn_entry(struct nhrp_vc
*vc
, void *ctx
)
747 struct vty
*vty
= ctx
;
748 char buf
[2][SU_ADDRSTRLEN
];
750 vty_out (vty
, "%-24s %-24s %c %-4d %-24s\n",
751 sockunion2str(&vc
->local
.nbma
, buf
[0], sizeof buf
[0]),
752 sockunion2str(&vc
->remote
.nbma
, buf
[1], sizeof buf
[1]),
753 notifier_active(&vc
->notifier_list
) ? 'n' : ' ',
758 DEFUN(show_dmvpn
, show_dmvpn_cmd
,
761 "DMVPN information\n")
763 vty_out (vty
, "%-24s %-24s %-6s %-4s %-24s\n",
770 nhrp_vc_foreach(show_dmvpn_entry
, vty
);
775 static void clear_nhrp_cache(struct nhrp_cache
*c
, void *data
)
777 struct info_ctx
*ctx
= data
;
778 if (c
->cur
.type
<= NHRP_CACHE_CACHED
) {
779 nhrp_cache_update_binding(c
, c
->cur
.type
, -1, NULL
, 0, NULL
);
784 static void clear_nhrp_shortcut(struct nhrp_shortcut
*s
, void *data
)
786 struct info_ctx
*ctx
= data
;
787 nhrp_shortcut_purge(s
, 1);
791 DEFUN(clear_nhrp
, clear_nhrp_cmd
,
792 "clear " AFI_CMD
" nhrp <cache|shortcut>",
796 "Dynamic cache entries\n"
797 "Shortcut entries\n")
799 struct listnode
*node
;
800 struct interface
*ifp
;
801 struct info_ctx ctx
= {
803 .afi
= cmd_to_afi(argv
[1]),
807 if (argc
<= 3 || argv
[3]->text
[0] == 'c') {
808 for (ALL_LIST_ELEMENTS_RO(vrf_iflist(VRF_DEFAULT
), node
, ifp
))
809 nhrp_cache_foreach(ifp
, clear_nhrp_cache
, &ctx
);
811 nhrp_shortcut_foreach(ctx
.afi
, clear_nhrp_shortcut
, &ctx
);
815 vty_out (vty
, "%% No entries\n");
819 vty_out (vty
, "%% %d entries cleared\n", ctx
.count
);
823 struct write_map_ctx
{
829 static void interface_config_write_nhrp_map(struct nhrp_cache
*c
, void *data
)
831 struct write_map_ctx
*ctx
= data
;
832 struct vty
*vty
= ctx
->vty
;
833 char buf
[2][SU_ADDRSTRLEN
];
836 if (sockunion_family(&c
->remote_addr
) != ctx
->family
) return;
838 vty_out (vty
, " %s nhrp map %s %s\n",
840 sockunion2str(&c
->remote_addr
, buf
[0], sizeof buf
[0]),
841 c
->cur
.type
== NHRP_CACHE_LOCAL
? "local" : sockunion2str(&c
->cur
.peer
->vc
->remote
.nbma
, buf
[1], sizeof buf
[1]));
844 static int interface_config_write(struct vty
*vty
)
846 struct write_map_ctx mapctx
;
847 struct listnode
*node
;
848 struct interface
*ifp
;
849 struct nhrp_interface
*nifp
;
850 struct nhrp_nhs
*nhs
;
853 char buf
[SU_ADDRSTRLEN
];
856 for (ALL_LIST_ELEMENTS_RO(vrf_iflist(VRF_DEFAULT
), node
, ifp
)) {
857 vty_frame(vty
, "interface %s\n", ifp
->name
);
859 vty_out (vty
, " description %s\n", ifp
->desc
);
862 if (nifp
->ipsec_profile
) {
863 vty_out(vty
, " tunnel protection vici profile %s",
864 nifp
->ipsec_profile
);
865 if (nifp
->ipsec_fallback_profile
)
866 vty_out(vty
, " fallback-profile %s",
867 nifp
->ipsec_fallback_profile
);
871 vty_out (vty
, " tunnel source %s\n",
874 for (afi
= 0; afi
< AFI_MAX
; afi
++) {
875 struct nhrp_afi_data
*ad
= &nifp
->afi
[afi
];
877 aficmd
= afi_to_cmd(afi
);
880 vty_out (vty
, " %s nhrp network-id %u\n",
881 aficmd
,ad
->network_id
);
883 if (ad
->holdtime
!= NHRPD_DEFAULT_HOLDTIME
)
884 vty_out (vty
, " %s nhrp holdtime %u\n",
885 aficmd
,ad
->holdtime
);
887 if (ad
->configured_mtu
< 0)
888 vty_out (vty
, " %s nhrp mtu opennhrp\n",
890 else if (ad
->configured_mtu
)
891 vty_out (vty
, " %s nhrp mtu %u\n",
892 aficmd
,ad
->configured_mtu
);
894 for (i
= 0; interface_flags_desc
[i
].str
!= NULL
; i
++) {
895 if (!(ad
->flags
& interface_flags_desc
[i
].key
))
897 vty_out (vty
, " %s nhrp %s\n",
898 aficmd
, interface_flags_desc
[i
].str
);
901 mapctx
= (struct write_map_ctx
) {
903 .family
= afi2family(afi
),
906 nhrp_cache_foreach(ifp
, interface_config_write_nhrp_map
, &mapctx
);
908 list_for_each_entry(nhs
, &ad
->nhslist_head
, nhslist_entry
) {
909 vty_out (vty
, " %s nhrp nhs %s nbma %s\n",
911 sockunion_family(&nhs
->proto_addr
) == AF_UNSPEC
? "dynamic" : sockunion2str(&nhs
->proto_addr
, buf
, sizeof buf
),
916 vty_endframe(vty
, "!\n");
922 void nhrp_config_init(void)
924 install_node(&zebra_node
, nhrp_config_write
);
925 install_default(ZEBRA_NODE
);
927 /* access-list commands */
930 /* global commands */
931 install_element(VIEW_NODE
, &show_debugging_nhrp_cmd
);
932 install_element(VIEW_NODE
, &show_ip_nhrp_cmd
);
933 install_element(VIEW_NODE
, &show_dmvpn_cmd
);
934 install_element(ENABLE_NODE
, &clear_nhrp_cmd
);
936 install_element(ENABLE_NODE
, &debug_nhrp_cmd
);
937 install_element(ENABLE_NODE
, &no_debug_nhrp_cmd
);
939 install_element(CONFIG_NODE
, &debug_nhrp_cmd
);
940 install_element(CONFIG_NODE
, &no_debug_nhrp_cmd
);
942 install_element(CONFIG_NODE
, &nhrp_event_socket_cmd
);
943 install_element(CONFIG_NODE
, &no_nhrp_event_socket_cmd
);
944 install_element(CONFIG_NODE
, &nhrp_nflog_group_cmd
);
945 install_element(CONFIG_NODE
, &no_nhrp_nflog_group_cmd
);
947 /* interface specific commands */
948 install_node(&nhrp_interface_node
, interface_config_write
);
951 install_element(INTERFACE_NODE
, &tunnel_protection_cmd
);
952 install_element(INTERFACE_NODE
, &no_tunnel_protection_cmd
);
953 install_element(INTERFACE_NODE
, &tunnel_source_cmd
);
954 install_element(INTERFACE_NODE
, &no_tunnel_source_cmd
);
955 install_element(INTERFACE_NODE
, &if_nhrp_network_id_cmd
);
956 install_element(INTERFACE_NODE
, &if_no_nhrp_network_id_cmd
);
957 install_element(INTERFACE_NODE
, &if_nhrp_holdtime_cmd
);
958 install_element(INTERFACE_NODE
, &if_no_nhrp_holdtime_cmd
);
959 install_element(INTERFACE_NODE
, &if_nhrp_mtu_cmd
);
960 install_element(INTERFACE_NODE
, &if_no_nhrp_mtu_cmd
);
961 install_element(INTERFACE_NODE
, &if_nhrp_flags_cmd
);
962 install_element(INTERFACE_NODE
, &if_no_nhrp_flags_cmd
);
963 install_element(INTERFACE_NODE
, &if_nhrp_reg_flags_cmd
);
964 install_element(INTERFACE_NODE
, &if_no_nhrp_reg_flags_cmd
);
965 install_element(INTERFACE_NODE
, &if_nhrp_map_cmd
);
966 install_element(INTERFACE_NODE
, &if_no_nhrp_map_cmd
);
967 install_element(INTERFACE_NODE
, &if_nhrp_nhs_cmd
);
968 install_element(INTERFACE_NODE
, &if_no_nhrp_nhs_cmd
);