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
<= (int)ZEBRA_NUM_OF(errmsgs
))
83 snprintf(buf
, sizeof(buf
), "Unknown error %d", ret
);
86 vty_outln (vty
, "%% %s", 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_outln (vty
, "%% Invalid value %s", name
);
108 return CMD_WARNING_CONFIG_FAILED
;;
113 DEFUN(show_debugging_nhrp
, show_debugging_nhrp_cmd
,
114 "show debugging nhrp",
116 "Debugging information\n"
117 "NHRP configuration\n")
121 vty_outln (vty
, "NHRP debugging status:");
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_outln (vty
, " NHRP %s debugging is on",
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_outln (vty
, "debug nhrp all");
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_outln (vty
, "debug nhrp %s",
171 debug_flags_desc
[i
].str
);
174 vty_outln (vty
, "!");
175 #endif /* NO_DEBUG */
177 if (nhrp_event_socket_path
) {
178 vty_outln (vty
, "nhrp event socket %s",
179 nhrp_event_socket_path
);
181 if (netlink_nflog_group
) {
182 vty_outln (vty
, "nhrp nflog-group %d",
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_outln (vty
, "%-8s %-8s %-24s %-24s %-6s %s",
611 vty_outln(ctx
->vty
, "%-8s %-8s %-24s %-24s %c%c%c %s",
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_outln (vty
, "%-8s %-24s %-16s %-16s",
637 vty_outln (vty
, "%-8s %-24s %-16s %-16s",
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_outln (vty
, "%-8s %-24s %-24s %s",
664 vty_outln(ctx
->vty
, "%-8s %-24s %-24s %s",
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 struct vty
*vty
= ctx
->vty
;
675 char buf
[SU_ADDRSTRLEN
];
677 if (ctx
->afi
!= family2afi(sockunion_family(&c
->remote_addr
)))
683 "Protocol-Address: %s/%zu",
684 nhrp_cache_type_str
[c
->cur
.type
],
686 (c
->cur
.peer
&& c
->cur
.peer
->online
) ? " up": "",
687 c
->used
? " used": "",
689 sockunion2str(&c
->remote_addr
, buf
, sizeof buf
),
690 8 * family2addrsize(sockunion_family(&c
->remote_addr
)));
695 sockunion2str(&c
->cur
.peer
->vc
->remote
.nbma
,
699 if (sockunion_family(&c
->cur
.remote_nbma_natoa
) != AF_UNSPEC
) {
701 "NBMA-NAT-OA-Address: %s",
702 sockunion2str(&c
->cur
.remote_nbma_natoa
, buf
, sizeof buf
));
705 vty_outln(ctx
->vty
, VTYNL
);
708 DEFUN(show_ip_nhrp
, show_ip_nhrp_cmd
,
709 "show " AFI_CMD
" nhrp [cache|nhs|shortcut|opennhrp]",
713 "Forwarding cache information\n"
714 "Next hop server information\n"
715 "Shortcut information\n"
716 "opennhrpctl style cache dump\n")
718 struct listnode
*node
;
719 struct interface
*ifp
;
720 struct info_ctx ctx
= {
722 .afi
= cmd_to_afi(argv
[1]),
725 if (argc
<= 3 || argv
[3]->text
[0] == 'c') {
726 for (ALL_LIST_ELEMENTS_RO(vrf_iflist(VRF_DEFAULT
), node
, ifp
))
727 nhrp_cache_foreach(ifp
, show_ip_nhrp_cache
, &ctx
);
728 } else if (argv
[3]->text
[0] == 'n') {
729 for (ALL_LIST_ELEMENTS_RO(vrf_iflist(VRF_DEFAULT
), node
, ifp
))
730 nhrp_nhs_foreach(ifp
, ctx
.afi
, show_ip_nhrp_nhs
, &ctx
);
731 } else if (argv
[3]->text
[0] == 's') {
732 nhrp_shortcut_foreach(ctx
.afi
, show_ip_nhrp_shortcut
, &ctx
);
734 vty_outln (vty
, "Status: ok%s", VTYNL
);
736 for (ALL_LIST_ELEMENTS_RO(vrf_iflist(VRF_DEFAULT
), node
, ifp
))
737 nhrp_cache_foreach(ifp
, show_ip_opennhrp_cache
, &ctx
);
741 vty_outln (vty
, "%% No entries");
748 static void show_dmvpn_entry(struct nhrp_vc
*vc
, void *ctx
)
750 struct vty
*vty
= ctx
;
751 char buf
[2][SU_ADDRSTRLEN
];
753 vty_outln (vty
, "%-24s %-24s %c %-4d %-24s",
754 sockunion2str(&vc
->local
.nbma
, buf
[0], sizeof buf
[0]),
755 sockunion2str(&vc
->remote
.nbma
, buf
[1], sizeof buf
[1]),
756 notifier_active(&vc
->notifier_list
) ? 'n' : ' ',
761 DEFUN(show_dmvpn
, show_dmvpn_cmd
,
764 "DMVPN information\n")
766 vty_outln (vty
, "%-24s %-24s %-6s %-4s %-24s",
773 nhrp_vc_foreach(show_dmvpn_entry
, vty
);
778 static void clear_nhrp_cache(struct nhrp_cache
*c
, void *data
)
780 struct info_ctx
*ctx
= data
;
781 if (c
->cur
.type
<= NHRP_CACHE_CACHED
) {
782 nhrp_cache_update_binding(c
, c
->cur
.type
, -1, NULL
, 0, NULL
);
787 static void clear_nhrp_shortcut(struct nhrp_shortcut
*s
, void *data
)
789 struct info_ctx
*ctx
= data
;
790 nhrp_shortcut_purge(s
, 1);
794 DEFUN(clear_nhrp
, clear_nhrp_cmd
,
795 "clear " AFI_CMD
" nhrp <cache|shortcut>",
799 "Dynamic cache entries\n"
800 "Shortcut entries\n")
802 struct listnode
*node
;
803 struct interface
*ifp
;
804 struct info_ctx ctx
= {
806 .afi
= cmd_to_afi(argv
[1]),
810 if (argc
<= 3 || argv
[3]->text
[0] == 'c') {
811 for (ALL_LIST_ELEMENTS_RO(vrf_iflist(VRF_DEFAULT
), node
, ifp
))
812 nhrp_cache_foreach(ifp
, clear_nhrp_cache
, &ctx
);
814 nhrp_shortcut_foreach(ctx
.afi
, clear_nhrp_shortcut
, &ctx
);
818 vty_outln (vty
, "%% No entries");
822 vty_outln (vty
, "%% %d entries cleared", ctx
.count
);
826 struct write_map_ctx
{
832 static void interface_config_write_nhrp_map(struct nhrp_cache
*c
, void *data
)
834 struct write_map_ctx
*ctx
= data
;
835 struct vty
*vty
= ctx
->vty
;
836 char buf
[2][SU_ADDRSTRLEN
];
839 if (sockunion_family(&c
->remote_addr
) != ctx
->family
) return;
841 vty_outln (vty
, " %s nhrp map %s %s",
843 sockunion2str(&c
->remote_addr
, buf
[0], sizeof buf
[0]),
844 c
->cur
.type
== NHRP_CACHE_LOCAL
? "local" : sockunion2str(&c
->cur
.peer
->vc
->remote
.nbma
, buf
[1], sizeof buf
[1]));
847 static int interface_config_write(struct vty
*vty
)
849 struct write_map_ctx mapctx
;
850 struct listnode
*node
;
851 struct interface
*ifp
;
852 struct nhrp_interface
*nifp
;
853 struct nhrp_nhs
*nhs
;
856 char buf
[SU_ADDRSTRLEN
];
859 for (ALL_LIST_ELEMENTS_RO(vrf_iflist(VRF_DEFAULT
), node
, ifp
)) {
860 vty_outln (vty
, "interface %s", ifp
->name
);
862 vty_outln (vty
, " description %s", ifp
->desc
);
865 if (nifp
->ipsec_profile
) {
866 vty_out(vty
, " tunnel protection vici profile %s",
867 nifp
->ipsec_profile
);
868 if (nifp
->ipsec_fallback_profile
)
869 vty_out(vty
, " fallback-profile %s",
870 nifp
->ipsec_fallback_profile
);
871 vty_out (vty
, VTYNL
);
874 vty_outln (vty
, " tunnel source %s",
877 for (afi
= 0; afi
< AFI_MAX
; afi
++) {
878 struct nhrp_afi_data
*ad
= &nifp
->afi
[afi
];
880 aficmd
= afi_to_cmd(afi
);
883 vty_outln (vty
, " %s nhrp network-id %u",
884 aficmd
,ad
->network_id
);
886 if (ad
->holdtime
!= NHRPD_DEFAULT_HOLDTIME
)
887 vty_outln (vty
, " %s nhrp holdtime %u",
888 aficmd
,ad
->holdtime
);
890 if (ad
->configured_mtu
< 0)
891 vty_outln (vty
, " %s nhrp mtu opennhrp",
893 else if (ad
->configured_mtu
)
894 vty_outln (vty
, " %s nhrp mtu %u",
895 aficmd
,ad
->configured_mtu
);
897 for (i
= 0; interface_flags_desc
[i
].str
!= NULL
; i
++) {
898 if (!(ad
->flags
& interface_flags_desc
[i
].key
))
900 vty_outln (vty
, " %s nhrp %s",
901 aficmd
, interface_flags_desc
[i
].str
);
904 mapctx
= (struct write_map_ctx
) {
906 .family
= afi2family(afi
),
909 nhrp_cache_foreach(ifp
, interface_config_write_nhrp_map
, &mapctx
);
911 list_for_each_entry(nhs
, &ad
->nhslist_head
, nhslist_entry
) {
912 vty_outln (vty
, " %s nhrp nhs %s nbma %s",
914 sockunion_family(&nhs
->proto_addr
) == AF_UNSPEC
? "dynamic" : sockunion2str(&nhs
->proto_addr
, buf
, sizeof buf
),
919 vty_outln (vty
, "!");
925 void nhrp_config_init(void)
927 install_node(&zebra_node
, nhrp_config_write
);
928 install_default(ZEBRA_NODE
);
930 /* access-list commands */
933 /* global commands */
934 install_element(VIEW_NODE
, &show_debugging_nhrp_cmd
);
935 install_element(VIEW_NODE
, &show_ip_nhrp_cmd
);
936 install_element(VIEW_NODE
, &show_dmvpn_cmd
);
937 install_element(ENABLE_NODE
, &clear_nhrp_cmd
);
939 install_element(ENABLE_NODE
, &debug_nhrp_cmd
);
940 install_element(ENABLE_NODE
, &no_debug_nhrp_cmd
);
942 install_element(CONFIG_NODE
, &debug_nhrp_cmd
);
943 install_element(CONFIG_NODE
, &no_debug_nhrp_cmd
);
945 install_element(CONFIG_NODE
, &nhrp_event_socket_cmd
);
946 install_element(CONFIG_NODE
, &no_nhrp_event_socket_cmd
);
947 install_element(CONFIG_NODE
, &nhrp_nflog_group_cmd
);
948 install_element(CONFIG_NODE
, &no_nhrp_nflog_group_cmd
);
950 /* interface specific commands */
951 install_node(&nhrp_interface_node
, interface_config_write
);
954 install_element(INTERFACE_NODE
, &tunnel_protection_cmd
);
955 install_element(INTERFACE_NODE
, &no_tunnel_protection_cmd
);
956 install_element(INTERFACE_NODE
, &tunnel_source_cmd
);
957 install_element(INTERFACE_NODE
, &no_tunnel_source_cmd
);
958 install_element(INTERFACE_NODE
, &if_nhrp_network_id_cmd
);
959 install_element(INTERFACE_NODE
, &if_no_nhrp_network_id_cmd
);
960 install_element(INTERFACE_NODE
, &if_nhrp_holdtime_cmd
);
961 install_element(INTERFACE_NODE
, &if_no_nhrp_holdtime_cmd
);
962 install_element(INTERFACE_NODE
, &if_nhrp_mtu_cmd
);
963 install_element(INTERFACE_NODE
, &if_no_nhrp_mtu_cmd
);
964 install_element(INTERFACE_NODE
, &if_nhrp_flags_cmd
);
965 install_element(INTERFACE_NODE
, &if_no_nhrp_flags_cmd
);
966 install_element(INTERFACE_NODE
, &if_nhrp_reg_flags_cmd
);
967 install_element(INTERFACE_NODE
, &if_no_nhrp_reg_flags_cmd
);
968 install_element(INTERFACE_NODE
, &if_nhrp_map_cmd
);
969 install_element(INTERFACE_NODE
, &if_no_nhrp_map_cmd
);
970 install_element(INTERFACE_NODE
, &if_nhrp_nhs_cmd
);
971 install_element(INTERFACE_NODE
, &if_no_nhrp_nhs_cmd
);