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"}, {NHRP_DEBUG_COMMON
, "common"},
44 {NHRP_DEBUG_IF
, "interface"}, {NHRP_DEBUG_KERNEL
, "kernel"},
45 {NHRP_DEBUG_ROUTE
, "route"}, {NHRP_DEBUG_VICI
, "vici"},
46 {NHRP_DEBUG_EVENT
, "event"}, {0}};
48 static const struct message interface_flags_desc
[] = {
49 {NHRP_IFF_SHORTCUT
, "shortcut"},
50 {NHRP_IFF_REDIRECT
, "redirect"},
51 {NHRP_IFF_REG_NO_UNIQUE
, "registration no-unique"},
54 static int nhrp_vty_return(struct vty
*vty
, int ret
)
56 static const char *const errmsgs
[] = {
57 [NHRP_ERR_FAIL
] = "Command failed",
58 [NHRP_ERR_NO_MEMORY
] = "Out of memory",
59 [NHRP_ERR_UNSUPPORTED_INTERFACE
] =
60 "NHRP not supported on this interface",
61 [NHRP_ERR_NHRP_NOT_ENABLED
] =
62 "NHRP not enabled (set 'nhrp network-id' first)",
63 [NHRP_ERR_ENTRY_EXISTS
] = "Entry exists already",
64 [NHRP_ERR_ENTRY_NOT_FOUND
] = "Entry not found",
65 [NHRP_ERR_PROTOCOL_ADDRESS_MISMATCH
] =
66 "Protocol address family does not match command (ip/ipv6 mismatch)",
68 const char *str
= NULL
;
74 if (ret
> 0 && ret
<= NHRP_ERR_MAX
)
80 snprintf(buf
, sizeof(buf
), "Unknown error %d", ret
);
83 vty_out(vty
, "%% %s\n", str
);
85 return CMD_WARNING_CONFIG_FAILED
;
89 static int toggle_flag(struct vty
*vty
, const struct message
*flag_desc
,
90 const char *name
, int on_off
, unsigned *flags
)
94 for (i
= 0; flag_desc
[i
].str
!= NULL
; i
++) {
95 if (strcmp(flag_desc
[i
].str
, name
) != 0)
98 *flags
|= flag_desc
[i
].key
;
100 *flags
&= ~flag_desc
[i
].key
;
104 vty_out(vty
, "%% Invalid value %s\n", name
);
105 return CMD_WARNING_CONFIG_FAILED
;
111 DEFUN_NOSH(show_debugging_nhrp
, show_debugging_nhrp_cmd
,
112 "show debugging [nhrp]",
114 "Debugging information\n"
115 "NHRP configuration\n")
119 vty_out(vty
, "NHRP debugging status:\n");
121 for (i
= 0; debug_flags_desc
[i
].str
!= NULL
; i
++) {
122 if (debug_flags_desc
[i
].key
== NHRP_DEBUG_ALL
)
124 if (!(debug_flags_desc
[i
].key
& debug_flags
))
127 vty_out(vty
, " NHRP %s debugging is on\n",
128 debug_flags_desc
[i
].str
);
134 DEFUN(debug_nhrp
, debug_nhrp_cmd
,
135 "debug nhrp " NHRP_DEBUG_FLAGS_CMD
,
136 "Enable debug messages for specific or all parts.\n"
138 NHRP_DEBUG_FLAGS_STR
)
140 return toggle_flag(vty
, debug_flags_desc
, argv
[2]->text
, 1,
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
[3]->text
, 0,
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
);
175 #endif /* NO_DEBUG */
177 if (nhrp_event_socket_path
) {
178 vty_out(vty
, "nhrp event socket %s\n", nhrp_event_socket_path
);
180 if (netlink_nflog_group
) {
181 vty_out(vty
, "nhrp nflog-group %d\n", netlink_nflog_group
);
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 struct cmd_token
*tok
)
195 return strcmp(tok
->text
, "ipv6") == 0 ? AFI_IP6
: AFI_IP
;
198 static const char *afi_to_cmd(afi_t afi
)
205 DEFUN(nhrp_event_socket
, nhrp_event_socket_cmd
,
206 "nhrp event socket SOCKET",
208 "Event Manager commands\n"
209 "Event Manager unix socket path\n"
210 "Unix path for the socket\n")
212 evmgr_set_socket(argv
[3]->arg
);
216 DEFUN(no_nhrp_event_socket
, no_nhrp_event_socket_cmd
,
217 "no nhrp event socket [SOCKET]",
220 "Event Manager commands\n"
221 "Event Manager unix socket path\n"
222 "Unix path for the socket\n")
224 evmgr_set_socket(NULL
);
228 DEFUN(nhrp_nflog_group
, nhrp_nflog_group_cmd
,
229 "nhrp nflog-group (1-65535)",
231 "Specify NFLOG group number\n"
232 "NFLOG group number\n")
236 nfgroup
= strtoul(argv
[2]->arg
, NULL
, 10);
237 netlink_set_nflog_group(nfgroup
);
242 DEFUN(no_nhrp_nflog_group
, no_nhrp_nflog_group_cmd
,
243 "no nhrp nflog-group [(1-65535)]",
246 "Specify NFLOG group number\n"
247 "NFLOG group number\n")
249 netlink_set_nflog_group(0);
253 DEFUN(tunnel_protection
, tunnel_protection_cmd
,
254 "tunnel protection vici profile PROFILE [fallback-profile FALLBACK]",
255 "NHRP/GRE integration\n"
257 "VICI (StrongSwan)\n"
259 "IPsec profile name\n"
260 "Fallback IPsec profile\n"
261 "Fallback IPsec profile name\n")
263 VTY_DECLVAR_CONTEXT(interface
, ifp
);
265 nhrp_interface_set_protection(ifp
, argv
[4]->arg
,
266 argc
> 6 ? argv
[6]->arg
: NULL
);
270 DEFUN(no_tunnel_protection
, no_tunnel_protection_cmd
,
271 "no tunnel protection",
273 "NHRP/GRE integration\n"
274 "IPsec protection\n")
276 VTY_DECLVAR_CONTEXT(interface
, ifp
);
278 nhrp_interface_set_protection(ifp
, NULL
, NULL
);
282 DEFUN(tunnel_source
, tunnel_source_cmd
,
283 "tunnel source INTERFACE",
284 "NHRP/GRE integration\n"
285 "Tunnel device binding tracking\n"
288 VTY_DECLVAR_CONTEXT(interface
, ifp
);
289 nhrp_interface_set_source(ifp
, argv
[2]->arg
);
293 DEFUN(no_tunnel_source
, no_tunnel_source_cmd
,
295 "NHRP/GRE integration\n"
296 "Tunnel device binding tracking\n"
299 VTY_DECLVAR_CONTEXT(interface
, ifp
);
300 nhrp_interface_set_source(ifp
, NULL
);
304 DEFUN(if_nhrp_network_id
, if_nhrp_network_id_cmd
,
305 AFI_CMD
" nhrp network-id (1-4294967295)",
308 "Enable NHRP and specify network-id\n"
309 "System local ID to specify interface group\n")
311 VTY_DECLVAR_CONTEXT(interface
, ifp
);
312 struct nhrp_interface
*nifp
= ifp
->info
;
313 afi_t afi
= cmd_to_afi(argv
[0]);
315 nifp
->afi
[afi
].network_id
= strtoul(argv
[3]->arg
, NULL
, 10);
316 nhrp_interface_update(ifp
);
321 DEFUN(if_no_nhrp_network_id
, if_no_nhrp_network_id_cmd
,
322 "no " AFI_CMD
" nhrp network-id [(1-4294967295)]",
326 "Enable NHRP and specify network-id\n"
327 "System local ID to specify interface group\n")
329 VTY_DECLVAR_CONTEXT(interface
, ifp
);
330 struct nhrp_interface
*nifp
= ifp
->info
;
331 afi_t afi
= cmd_to_afi(argv
[1]);
333 nifp
->afi
[afi
].network_id
= 0;
334 nhrp_interface_update(ifp
);
339 DEFUN(if_nhrp_flags
, if_nhrp_flags_cmd
,
340 AFI_CMD
" nhrp <shortcut|redirect>",
343 "Allow shortcut establishment\n"
344 "Send redirect notifications\n")
346 VTY_DECLVAR_CONTEXT(interface
, ifp
);
347 struct nhrp_interface
*nifp
= ifp
->info
;
348 afi_t afi
= cmd_to_afi(argv
[0]);
350 return toggle_flag(vty
, interface_flags_desc
, argv
[2]->text
, 1,
351 &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,
367 &nifp
->afi
[afi
].flags
);
370 DEFUN(if_nhrp_reg_flags
, if_nhrp_reg_flags_cmd
,
371 AFI_CMD
" nhrp registration no-unique",
374 "Registration configuration\n"
375 "Don't set unique flag\n")
377 VTY_DECLVAR_CONTEXT(interface
, ifp
);
378 struct nhrp_interface
*nifp
= ifp
->info
;
379 afi_t afi
= cmd_to_afi(argv
[0]);
381 snprintf(name
, sizeof(name
), "registration %s", argv
[3]->text
);
382 return toggle_flag(vty
, interface_flags_desc
, name
, 1,
383 &nifp
->afi
[afi
].flags
);
386 DEFUN(if_no_nhrp_reg_flags
, if_no_nhrp_reg_flags_cmd
,
387 "no " AFI_CMD
" nhrp registration no-unique",
391 "Registration configuration\n"
392 "Don't set unique flag\n")
394 VTY_DECLVAR_CONTEXT(interface
, ifp
);
395 struct nhrp_interface
*nifp
= ifp
->info
;
396 afi_t afi
= cmd_to_afi(argv
[1]);
398 snprintf(name
, sizeof(name
), "registration %s", argv
[4]->text
);
399 return toggle_flag(vty
, interface_flags_desc
, name
, 0,
400 &nifp
->afi
[afi
].flags
);
403 DEFUN(if_nhrp_holdtime
, if_nhrp_holdtime_cmd
,
404 AFI_CMD
" nhrp holdtime (1-65000)",
407 "Specify NBMA address validity time\n"
408 "Time in seconds that NBMA addresses are advertised valid\n")
410 VTY_DECLVAR_CONTEXT(interface
, ifp
);
411 struct nhrp_interface
*nifp
= ifp
->info
;
412 afi_t afi
= cmd_to_afi(argv
[0]);
414 nifp
->afi
[afi
].holdtime
= strtoul(argv
[3]->arg
, NULL
, 10);
415 nhrp_interface_update(ifp
);
420 DEFUN(if_no_nhrp_holdtime
, if_no_nhrp_holdtime_cmd
,
421 "no " AFI_CMD
" nhrp holdtime [(1-65000)]",
425 "Specify NBMA address validity time\n"
426 "Time in seconds that NBMA addresses are advertised valid\n")
428 VTY_DECLVAR_CONTEXT(interface
, ifp
);
429 struct nhrp_interface
*nifp
= ifp
->info
;
430 afi_t afi
= cmd_to_afi(argv
[1]);
432 nifp
->afi
[afi
].holdtime
= NHRPD_DEFAULT_HOLDTIME
;
433 nhrp_interface_update(ifp
);
438 DEFUN(if_nhrp_mtu
, if_nhrp_mtu_cmd
,
439 "ip nhrp mtu <(576-1500)|opennhrp>",
442 "Configure NHRP advertised MTU\n"
444 "Advertise bound interface MTU similar to OpenNHRP\n")
446 VTY_DECLVAR_CONTEXT(interface
, ifp
);
447 struct nhrp_interface
*nifp
= ifp
->info
;
449 if (argv
[3]->arg
[0] == 'o') {
450 nifp
->afi
[AFI_IP
].configured_mtu
= -1;
452 nifp
->afi
[AFI_IP
].configured_mtu
=
453 strtoul(argv
[3]->arg
, NULL
, 10);
455 nhrp_interface_update_mtu(ifp
, AFI_IP
);
460 DEFUN(if_no_nhrp_mtu
, if_no_nhrp_mtu_cmd
,
461 "no ip nhrp mtu [(576-1500)|opennhrp]",
465 "Configure NHRP advertised MTU\n"
467 "Advertise bound interface MTU similar to OpenNHRP\n")
469 VTY_DECLVAR_CONTEXT(interface
, ifp
);
470 struct nhrp_interface
*nifp
= ifp
->info
;
472 nifp
->afi
[AFI_IP
].configured_mtu
= 0;
473 nhrp_interface_update_mtu(ifp
, AFI_IP
);
477 DEFUN(if_nhrp_map
, if_nhrp_map_cmd
,
478 AFI_CMD
" nhrp map <A.B.C.D|X:X::X:X> <A.B.C.D|local>",
481 "Nexthop Server configuration\n"
482 "IPv4 protocol address\n"
483 "IPv6 protocol address\n"
484 "IPv4 NBMA address\n"
485 "Handle protocol address locally\n")
487 VTY_DECLVAR_CONTEXT(interface
, ifp
);
488 afi_t afi
= cmd_to_afi(argv
[0]);
489 union sockunion proto_addr
, nbma_addr
;
490 struct nhrp_cache
*c
;
492 if (str2sockunion(argv
[3]->arg
, &proto_addr
) < 0
493 || afi2family(afi
) != sockunion_family(&proto_addr
))
494 return nhrp_vty_return(vty
, NHRP_ERR_PROTOCOL_ADDRESS_MISMATCH
);
496 c
= nhrp_cache_get(ifp
, &proto_addr
, 1);
498 return nhrp_vty_return(vty
, NHRP_ERR_FAIL
);
501 if (strmatch(argv
[4]->text
, "local")) {
502 nhrp_cache_update_binding(c
, NHRP_CACHE_LOCAL
, 0, NULL
, 0,
505 if (str2sockunion(argv
[4]->arg
, &nbma_addr
) < 0)
506 return nhrp_vty_return(vty
, NHRP_ERR_FAIL
);
507 nhrp_cache_update_binding(c
, NHRP_CACHE_STATIC
, 0,
508 nhrp_peer_get(ifp
, &nbma_addr
), 0,
515 DEFUN(if_no_nhrp_map
, if_no_nhrp_map_cmd
,
516 "no " AFI_CMD
" nhrp map <A.B.C.D|X:X::X:X>",
520 "Nexthop Server configuration\n"
521 "IPv4 protocol address\n"
522 "IPv6 protocol address\n")
524 VTY_DECLVAR_CONTEXT(interface
, ifp
);
525 afi_t afi
= cmd_to_afi(argv
[1]);
526 union sockunion proto_addr
;
527 struct nhrp_cache
*c
;
529 if (str2sockunion(argv
[4]->arg
, &proto_addr
) < 0
530 || afi2family(afi
) != sockunion_family(&proto_addr
))
531 return nhrp_vty_return(vty
, NHRP_ERR_PROTOCOL_ADDRESS_MISMATCH
);
533 c
= nhrp_cache_get(ifp
, &proto_addr
, 0);
535 return nhrp_vty_return(vty
, NHRP_ERR_ENTRY_NOT_FOUND
);
537 nhrp_cache_update_binding(c
, c
->cur
.type
, -1, NULL
, 0, NULL
);
541 DEFUN(if_nhrp_nhs
, if_nhrp_nhs_cmd
,
542 AFI_CMD
" nhrp nhs <A.B.C.D|X:X::X:X|dynamic> nbma <A.B.C.D|FQDN>",
545 "Nexthop Server configuration\n"
546 "IPv4 protocol address\n"
547 "IPv6 protocol address\n"
548 "Automatic detection of protocol address\n"
550 "IPv4 NBMA address\n"
551 "Fully qualified domain name for NBMA address(es)\n")
553 VTY_DECLVAR_CONTEXT(interface
, ifp
);
554 afi_t afi
= cmd_to_afi(argv
[0]);
555 union sockunion proto_addr
;
558 if (str2sockunion(argv
[3]->arg
, &proto_addr
) < 0)
559 sockunion_family(&proto_addr
) = AF_UNSPEC
;
561 ret
= nhrp_nhs_add(ifp
, afi
, &proto_addr
, argv
[5]->arg
);
562 return nhrp_vty_return(vty
, ret
);
565 DEFUN(if_no_nhrp_nhs
, if_no_nhrp_nhs_cmd
,
566 "no " AFI_CMD
" nhrp nhs <A.B.C.D|X:X::X:X|dynamic> nbma <A.B.C.D|FQDN>",
570 "Nexthop Server configuration\n"
571 "IPv4 protocol address\n"
572 "IPv6 protocol address\n"
573 "Automatic detection of protocol address\n"
575 "IPv4 NBMA address\n"
576 "Fully qualified domain name for NBMA address(es)\n")
578 VTY_DECLVAR_CONTEXT(interface
, ifp
);
579 afi_t afi
= cmd_to_afi(argv
[1]);
580 union sockunion proto_addr
;
583 if (str2sockunion(argv
[4]->arg
, &proto_addr
) < 0)
584 sockunion_family(&proto_addr
) = AF_UNSPEC
;
586 ret
= nhrp_nhs_del(ifp
, afi
, &proto_addr
, argv
[6]->arg
);
587 return nhrp_vty_return(vty
, ret
);
596 static void show_ip_nhrp_cache(struct nhrp_cache
*c
, void *pctx
)
598 struct info_ctx
*ctx
= pctx
;
599 struct vty
*vty
= ctx
->vty
;
600 char buf
[2][SU_ADDRSTRLEN
];
602 if (ctx
->afi
!= family2afi(sockunion_family(&c
->remote_addr
)))
606 vty_out(vty
, "%-8s %-8s %-24s %-24s %-6s %s\n", "Iface", "Type",
607 "Protocol", "NBMA", "Flags", "Identity");
611 vty_out(ctx
->vty
, "%-8s %-8s %-24s %-24s %c%c%c %s\n", c
->ifp
->name
,
612 nhrp_cache_type_str
[c
->cur
.type
],
613 sockunion2str(&c
->remote_addr
, buf
[0], sizeof buf
[0]),
614 c
->cur
.peer
? sockunion2str(&c
->cur
.peer
->vc
->remote
.nbma
,
615 buf
[1], sizeof buf
[1])
617 c
->used
? 'U' : ' ', 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
,
625 struct info_ctx
*ctx
= pctx
;
626 struct vty
*vty
= ctx
->vty
;
627 char buf
[2][SU_ADDRSTRLEN
];
630 vty_out(vty
, "%-8s %-24s %-16s %-16s\n", "Iface", "FQDN",
635 vty_out(vty
, "%-8s %-24s %-16s %-16s\n", n
->ifp
->name
, n
->nbma_fqdn
,
636 (reg
&& reg
->peer
) ? sockunion2str(®
->peer
->vc
->remote
.nbma
,
637 buf
[0], sizeof buf
[0])
639 sockunion2str(reg
? ®
->proto_addr
: &n
->proto_addr
, buf
[1],
643 static void show_ip_nhrp_shortcut(struct nhrp_shortcut
*s
, void *pctx
)
645 struct info_ctx
*ctx
= pctx
;
646 struct nhrp_cache
*c
;
647 struct vty
*vty
= ctx
->vty
;
648 char buf1
[PREFIX_STRLEN
], buf2
[SU_ADDRSTRLEN
];
651 vty_out(vty
, "%-8s %-24s %-24s %s\n", "Type", "Prefix", "Via",
657 vty_out(ctx
->vty
, "%-8s %-24s %-24s %s\n", nhrp_cache_type_str
[s
->type
],
658 prefix2str(s
->p
, buf1
, sizeof buf1
),
659 c
? sockunion2str(&c
->remote_addr
, buf2
, sizeof buf2
) : "",
660 (c
&& c
->cur
.peer
) ? c
->cur
.peer
->vc
->remote
.id
: "");
663 static void show_ip_opennhrp_cache(struct nhrp_cache
*c
, void *pctx
)
665 struct info_ctx
*ctx
= pctx
;
666 char buf
[SU_ADDRSTRLEN
];
668 if (ctx
->afi
!= family2afi(sockunion_family(&c
->remote_addr
)))
674 "Protocol-Address: %s/%zu\n",
675 nhrp_cache_type_str
[c
->cur
.type
],
676 (c
->cur
.peer
&& c
->cur
.peer
->online
) ? " up" : "",
677 c
->used
? " used" : "",
678 sockunion2str(&c
->remote_addr
, buf
, sizeof buf
),
679 8 * family2addrsize(sockunion_family(&c
->remote_addr
)));
682 vty_out(ctx
->vty
, "NBMA-Address: %s\n",
683 sockunion2str(&c
->cur
.peer
->vc
->remote
.nbma
, buf
,
687 if (sockunion_family(&c
->cur
.remote_nbma_natoa
) != AF_UNSPEC
) {
688 vty_out(ctx
->vty
, "NBMA-NAT-OA-Address: %s\n",
689 sockunion2str(&c
->cur
.remote_nbma_natoa
, buf
,
693 vty_out(ctx
->vty
, "\n\n");
696 DEFUN(show_ip_nhrp
, show_ip_nhrp_cmd
,
697 "show " AFI_CMD
" nhrp [cache|nhs|shortcut|opennhrp]",
701 "Forwarding cache information\n"
702 "Next hop server information\n"
703 "Shortcut information\n"
704 "opennhrpctl style cache dump\n")
706 struct vrf
*vrf
= vrf_lookup_by_id(VRF_DEFAULT
);
707 struct interface
*ifp
;
708 struct info_ctx ctx
= {
709 .vty
= vty
, .afi
= cmd_to_afi(argv
[1]),
712 if (argc
<= 3 || argv
[3]->text
[0] == 'c') {
713 FOR_ALL_INTERFACES (vrf
, ifp
)
714 nhrp_cache_foreach(ifp
, show_ip_nhrp_cache
, &ctx
);
715 } else if (argv
[3]->text
[0] == 'n') {
716 FOR_ALL_INTERFACES (vrf
, ifp
)
717 nhrp_nhs_foreach(ifp
, ctx
.afi
, show_ip_nhrp_nhs
, &ctx
);
718 } else if (argv
[3]->text
[0] == 's') {
719 nhrp_shortcut_foreach(ctx
.afi
, show_ip_nhrp_shortcut
, &ctx
);
721 vty_out(vty
, "Status: ok\n\n");
723 FOR_ALL_INTERFACES (vrf
, ifp
)
724 nhrp_cache_foreach(ifp
, show_ip_opennhrp_cache
, &ctx
);
728 vty_out(vty
, "%% No entries\n");
735 static void show_dmvpn_entry(struct nhrp_vc
*vc
, void *ctx
)
737 struct vty
*vty
= ctx
;
738 char buf
[2][SU_ADDRSTRLEN
];
740 vty_out(vty
, "%-24s %-24s %c %-4d %-24s\n",
741 sockunion2str(&vc
->local
.nbma
, buf
[0], sizeof buf
[0]),
742 sockunion2str(&vc
->remote
.nbma
, buf
[1], sizeof buf
[1]),
743 notifier_active(&vc
->notifier_list
) ? 'n' : ' ', vc
->ipsec
,
747 DEFUN(show_dmvpn
, show_dmvpn_cmd
,
750 "DMVPN information\n")
752 vty_out(vty
, "%-24s %-24s %-6s %-4s %-24s\n", "Src", "Dst", "Flags",
755 nhrp_vc_foreach(show_dmvpn_entry
, vty
);
760 static void clear_nhrp_cache(struct nhrp_cache
*c
, void *data
)
762 struct info_ctx
*ctx
= data
;
763 if (c
->cur
.type
<= NHRP_CACHE_CACHED
) {
764 nhrp_cache_update_binding(c
, c
->cur
.type
, -1, NULL
, 0, NULL
);
769 static void clear_nhrp_shortcut(struct nhrp_shortcut
*s
, void *data
)
771 struct info_ctx
*ctx
= data
;
772 nhrp_shortcut_purge(s
, 1);
776 DEFUN(clear_nhrp
, clear_nhrp_cmd
,
777 "clear " AFI_CMD
" nhrp <cache|shortcut>",
781 "Dynamic cache entries\n"
782 "Shortcut entries\n")
784 struct vrf
*vrf
= vrf_lookup_by_id(VRF_DEFAULT
);
785 struct interface
*ifp
;
786 struct info_ctx ctx
= {
787 .vty
= vty
, .afi
= cmd_to_afi(argv
[1]), .count
= 0,
790 if (argc
<= 3 || argv
[3]->text
[0] == 'c') {
791 FOR_ALL_INTERFACES (vrf
, ifp
)
792 nhrp_cache_foreach(ifp
, clear_nhrp_cache
, &ctx
);
794 nhrp_shortcut_foreach(ctx
.afi
, clear_nhrp_shortcut
, &ctx
);
798 vty_out(vty
, "%% No entries\n");
802 vty_out(vty
, "%% %d entries cleared\n", ctx
.count
);
806 struct write_map_ctx
{
812 static void interface_config_write_nhrp_map(struct nhrp_cache
*c
, void *data
)
814 struct write_map_ctx
*ctx
= data
;
815 struct vty
*vty
= ctx
->vty
;
816 char buf
[2][SU_ADDRSTRLEN
];
820 if (sockunion_family(&c
->remote_addr
) != ctx
->family
)
823 vty_out(vty
, " %s nhrp map %s %s\n", ctx
->aficmd
,
824 sockunion2str(&c
->remote_addr
, buf
[0], sizeof buf
[0]),
825 c
->cur
.type
== NHRP_CACHE_LOCAL
827 : sockunion2str(&c
->cur
.peer
->vc
->remote
.nbma
, buf
[1],
831 static int interface_config_write(struct vty
*vty
)
833 struct vrf
*vrf
= vrf_lookup_by_id(VRF_DEFAULT
);
834 struct write_map_ctx mapctx
;
835 struct interface
*ifp
;
836 struct nhrp_interface
*nifp
;
837 struct nhrp_nhs
*nhs
;
840 char buf
[SU_ADDRSTRLEN
];
843 FOR_ALL_INTERFACES (vrf
, ifp
) {
844 vty_frame(vty
, "interface %s\n", ifp
->name
);
846 vty_out(vty
, " description %s\n", ifp
->desc
);
849 if (nifp
->ipsec_profile
) {
850 vty_out(vty
, " tunnel protection vici profile %s",
851 nifp
->ipsec_profile
);
852 if (nifp
->ipsec_fallback_profile
)
853 vty_out(vty
, " fallback-profile %s",
854 nifp
->ipsec_fallback_profile
);
858 vty_out(vty
, " tunnel source %s\n", nifp
->source
);
860 for (afi
= 0; afi
< AFI_MAX
; afi
++) {
861 struct nhrp_afi_data
*ad
= &nifp
->afi
[afi
];
863 aficmd
= afi_to_cmd(afi
);
866 vty_out(vty
, " %s nhrp network-id %u\n", aficmd
,
869 if (ad
->holdtime
!= NHRPD_DEFAULT_HOLDTIME
)
870 vty_out(vty
, " %s nhrp holdtime %u\n", aficmd
,
873 if (ad
->configured_mtu
< 0)
874 vty_out(vty
, " %s nhrp mtu opennhrp\n", aficmd
);
875 else if (ad
->configured_mtu
)
876 vty_out(vty
, " %s nhrp mtu %u\n", aficmd
,
879 for (i
= 0; interface_flags_desc
[i
].str
!= NULL
; i
++) {
880 if (!(ad
->flags
& interface_flags_desc
[i
].key
))
882 vty_out(vty
, " %s nhrp %s\n", aficmd
,
883 interface_flags_desc
[i
].str
);
886 mapctx
= (struct write_map_ctx
){
888 .family
= afi2family(afi
),
891 nhrp_cache_foreach(ifp
, interface_config_write_nhrp_map
,
894 list_for_each_entry(nhs
, &ad
->nhslist_head
,
897 vty_out(vty
, " %s nhrp nhs %s nbma %s\n",
899 sockunion_family(&nhs
->proto_addr
)
903 &nhs
->proto_addr
, buf
,
909 vty_endframe(vty
, "!\n");
915 void nhrp_config_init(void)
917 install_node(&zebra_node
, nhrp_config_write
);
918 install_default(ZEBRA_NODE
);
920 /* access-list commands */
923 /* global commands */
924 install_element(VIEW_NODE
, &show_debugging_nhrp_cmd
);
925 install_element(VIEW_NODE
, &show_ip_nhrp_cmd
);
926 install_element(VIEW_NODE
, &show_dmvpn_cmd
);
927 install_element(ENABLE_NODE
, &clear_nhrp_cmd
);
929 install_element(ENABLE_NODE
, &debug_nhrp_cmd
);
930 install_element(ENABLE_NODE
, &no_debug_nhrp_cmd
);
932 install_element(CONFIG_NODE
, &debug_nhrp_cmd
);
933 install_element(CONFIG_NODE
, &no_debug_nhrp_cmd
);
935 install_element(CONFIG_NODE
, &nhrp_event_socket_cmd
);
936 install_element(CONFIG_NODE
, &no_nhrp_event_socket_cmd
);
937 install_element(CONFIG_NODE
, &nhrp_nflog_group_cmd
);
938 install_element(CONFIG_NODE
, &no_nhrp_nflog_group_cmd
);
940 /* interface specific commands */
941 install_node(&nhrp_interface_node
, interface_config_write
);
944 install_element(INTERFACE_NODE
, &tunnel_protection_cmd
);
945 install_element(INTERFACE_NODE
, &no_tunnel_protection_cmd
);
946 install_element(INTERFACE_NODE
, &tunnel_source_cmd
);
947 install_element(INTERFACE_NODE
, &no_tunnel_source_cmd
);
948 install_element(INTERFACE_NODE
, &if_nhrp_network_id_cmd
);
949 install_element(INTERFACE_NODE
, &if_no_nhrp_network_id_cmd
);
950 install_element(INTERFACE_NODE
, &if_nhrp_holdtime_cmd
);
951 install_element(INTERFACE_NODE
, &if_no_nhrp_holdtime_cmd
);
952 install_element(INTERFACE_NODE
, &if_nhrp_mtu_cmd
);
953 install_element(INTERFACE_NODE
, &if_no_nhrp_mtu_cmd
);
954 install_element(INTERFACE_NODE
, &if_nhrp_flags_cmd
);
955 install_element(INTERFACE_NODE
, &if_no_nhrp_flags_cmd
);
956 install_element(INTERFACE_NODE
, &if_nhrp_reg_flags_cmd
);
957 install_element(INTERFACE_NODE
, &if_no_nhrp_reg_flags_cmd
);
958 install_element(INTERFACE_NODE
, &if_nhrp_map_cmd
);
959 install_element(INTERFACE_NODE
, &if_no_nhrp_map_cmd
);
960 install_element(INTERFACE_NODE
, &if_nhrp_nhs_cmd
);
961 install_element(INTERFACE_NODE
, &if_no_nhrp_nhs_cmd
);