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")
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")
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_nhrp_nhs
, if_nhrp_nhs_cmd
,
507 AFI_CMD
" nhrp nhs (A.B.C.D|X:X::X:X|dynamic) nbma (A.B.C.D|FQDN)",
510 "Nexthop Server configuration\n"
511 "IPv4 protocol address\n"
512 "IPv6 protocol address\n"
513 "Automatic detection of protocol address\n"
514 "IPv4 NBMA address\n"
515 "Fully qualified domain name for NBMA address(es)\n")
517 struct interface
*ifp
= vty
->index
;
518 afi_t afi
= cmd_to_afi(argv
[0]);
519 union sockunion proto_addr
;
522 if (str2sockunion(argv
[1], &proto_addr
) < 0)
523 sockunion_family(&proto_addr
) = AF_UNSPEC
;
525 ret
= nhrp_nhs_add(ifp
, afi
, &proto_addr
, argv
[2]);
526 return nhrp_vty_return(vty
, ret
);
529 DEFUN(if_no_nhrp_nhs
, if_no_nhrp_nhs_cmd
,
530 "no " AFI_CMD
" nhrp nhs (A.B.C.D|X:X::X:X|dynamic) nbma (A.B.C.D|FQDN)",
534 "Nexthop Server configuration\n"
535 "IPv4 protocol address\n"
536 "IPv6 protocol address\n"
537 "Automatic detection of protocol address\n"
538 "IPv4 NBMA address\n"
539 "Fully qualified domain name for NBMA address(es)\n")
541 struct interface
*ifp
= vty
->index
;
542 afi_t afi
= cmd_to_afi(argv
[0]);
543 union sockunion proto_addr
;
546 if (str2sockunion(argv
[1], &proto_addr
) < 0)
547 sockunion_family(&proto_addr
) = AF_UNSPEC
;
549 ret
= nhrp_nhs_del(ifp
, afi
, &proto_addr
, argv
[2]);
550 return nhrp_vty_return(vty
, ret
);
559 static void show_ip_nhrp_cache(struct nhrp_cache
*c
, void *pctx
)
561 struct info_ctx
*ctx
= pctx
;
562 struct vty
*vty
= ctx
->vty
;
563 char buf
[2][SU_ADDRSTRLEN
];
565 if (ctx
->afi
!= family2afi(sockunion_family(&c
->remote_addr
)))
569 vty_out(vty
, "%-8s %-8s %-24s %-24s %-6s %s%s",
580 vty_out(ctx
->vty
, "%-8s %-8s %-24s %-24s %c%c%c %s%s",
582 nhrp_cache_type_str
[c
->cur
.type
],
583 sockunion2str(&c
->remote_addr
, buf
[0], sizeof buf
[0]),
584 c
->cur
.peer
? sockunion2str(&c
->cur
.peer
->vc
->remote
.nbma
, buf
[1], sizeof buf
[1]) : "-",
586 c
->t_timeout
? 'T' : ' ',
587 c
->t_auth
? 'A' : ' ',
588 c
->cur
.peer
? c
->cur
.peer
->vc
->remote
.id
: "-",
592 static void show_ip_opennhrp_cache(struct nhrp_cache
*c
, void *pctx
)
594 struct info_ctx
*ctx
= pctx
;
595 struct vty
*vty
= ctx
->vty
;
596 char buf
[SU_ADDRSTRLEN
];
598 if (ctx
->afi
!= family2afi(sockunion_family(&c
->remote_addr
)))
604 "Protocol-Address: %s/%zu%s",
605 nhrp_cache_type_str
[c
->cur
.type
],
607 (c
->cur
.peer
&& c
->cur
.peer
->online
) ? " up": "",
608 c
->used
? " used": "",
610 sockunion2str(&c
->remote_addr
, buf
, sizeof buf
),
611 8 * family2addrsize(sockunion_family(&c
->remote_addr
)),
616 "NBMA-Address: %s%s",
617 sockunion2str(&c
->cur
.peer
->vc
->remote
.nbma
, buf
, sizeof buf
),
621 if (sockunion_family(&c
->cur
.remote_nbma_natoa
) != AF_UNSPEC
) {
623 "NBMA-NAT-OA-Address: %s%s",
624 sockunion2str(&c
->cur
.remote_nbma_natoa
, buf
, sizeof buf
),
628 vty_out(ctx
->vty
, "%s", VTY_NEWLINE
);
631 static void show_ip_nhrp_shortcut(struct nhrp_shortcut
*s
, void *pctx
)
633 struct info_ctx
*ctx
= pctx
;
634 struct nhrp_cache
*c
;
635 struct vty
*vty
= ctx
->vty
;
636 char buf1
[PREFIX_STRLEN
], buf2
[SU_ADDRSTRLEN
];
639 vty_out(vty
, "%-8s %-24s %-24s %s%s",
649 vty_out(ctx
->vty
, "%-8s %-24s %-24s %s%s",
650 nhrp_cache_type_str
[s
->type
],
651 prefix2str(s
->p
, buf1
, sizeof buf1
),
652 c
? sockunion2str(&c
->remote_addr
, buf2
, sizeof buf2
) : "",
653 (c
&& c
->cur
.peer
) ? c
->cur
.peer
->vc
->remote
.id
: "",
657 DEFUN(show_ip_nhrp
, show_ip_nhrp_cmd
,
658 "show " AFI_CMD
" nhrp (cache|shortcut|opennhrp|)",
662 "Forwarding cache information\n"
663 "Shortcut information\n"
664 "opennhrpctl style cache dump\n")
666 struct listnode
*node
;
667 struct interface
*ifp
;
668 struct info_ctx ctx
= {
670 .afi
= cmd_to_afi(argv
[0]),
673 if (!argv
[1] || argv
[1][0] == 'c') {
674 for (ALL_LIST_ELEMENTS_RO(iflist
, node
, ifp
))
675 nhrp_cache_foreach(ifp
, show_ip_nhrp_cache
, &ctx
);
676 } else if (argv
[1][0] == 'o') {
677 vty_out(vty
, "Status: ok%s%s", VTY_NEWLINE
, VTY_NEWLINE
);
679 for (ALL_LIST_ELEMENTS_RO(iflist
, node
, ifp
))
680 nhrp_cache_foreach(ifp
, show_ip_opennhrp_cache
, &ctx
);
682 nhrp_shortcut_foreach(ctx
.afi
, show_ip_nhrp_shortcut
, &ctx
);
686 vty_out(vty
, "%% No entries%s", VTY_NEWLINE
);
693 static void show_dmvpn_entry(struct nhrp_vc
*vc
, void *ctx
)
695 struct vty
*vty
= ctx
;
696 char buf
[2][SU_ADDRSTRLEN
];
698 vty_out(vty
, "%-24s %-24s %c %-4d %-24s%s",
699 sockunion2str(&vc
->local
.nbma
, buf
[0], sizeof buf
[0]),
700 sockunion2str(&vc
->remote
.nbma
, buf
[1], sizeof buf
[1]),
701 notifier_active(&vc
->notifier_list
) ? 'n' : ' ',
707 DEFUN(show_dmvpn
, show_dmvpn_cmd
,
710 "DMVPN information\n")
712 vty_out(vty
, "%-24s %-24s %-6s %-4s %-24s%s",
720 nhrp_vc_foreach(show_dmvpn_entry
, vty
);
725 static void clear_nhrp_cache(struct nhrp_cache
*c
, void *data
)
727 struct info_ctx
*ctx
= data
;
728 if (c
->cur
.type
<= NHRP_CACHE_CACHED
) {
729 nhrp_cache_update_binding(c
, c
->cur
.type
, -1, NULL
, 0, NULL
);
734 static void clear_nhrp_shortcut(struct nhrp_shortcut
*s
, void *data
)
736 struct info_ctx
*ctx
= data
;
737 nhrp_shortcut_purge(s
, 1);
741 DEFUN(clear_nhrp
, clear_nhrp_cmd
,
742 "clear " AFI_CMD
" nhrp (cache|shortcut)",
746 "Dynamic cache entries\n"
747 "Shortcut entries\n")
749 struct listnode
*node
;
750 struct interface
*ifp
;
751 struct info_ctx ctx
= {
753 .afi
= cmd_to_afi(argv
[0]),
757 if (!argv
[1] || argv
[1][0] == 'c') {
758 for (ALL_LIST_ELEMENTS_RO(iflist
, node
, ifp
))
759 nhrp_cache_foreach(ifp
, clear_nhrp_cache
, &ctx
);
761 nhrp_shortcut_foreach(ctx
.afi
, clear_nhrp_shortcut
, &ctx
);
765 vty_out(vty
, "%% No entries%s", VTY_NEWLINE
);
769 vty_out(vty
, "%% %d entries cleared%s", ctx
.count
, VTY_NEWLINE
);
773 struct write_map_ctx
{
779 static void interface_config_write_nhrp_map(struct nhrp_cache
*c
, void *data
)
781 struct write_map_ctx
*ctx
= data
;
782 struct vty
*vty
= ctx
->vty
;
783 char buf
[2][SU_ADDRSTRLEN
];
786 if (sockunion_family(&c
->remote_addr
) != ctx
->family
) return;
788 vty_out(vty
, " %s nhrp map %s %s%s",
790 sockunion2str(&c
->remote_addr
, buf
[0], sizeof buf
[0]),
791 c
->cur
.type
== NHRP_CACHE_LOCAL
? "local" :
792 sockunion2str(&c
->cur
.peer
->vc
->remote
.nbma
, buf
[1], sizeof buf
[1]),
796 static int interface_config_write(struct vty
*vty
)
798 struct write_map_ctx mapctx
;
799 struct listnode
*node
;
800 struct interface
*ifp
;
801 struct nhrp_interface
*nifp
;
802 struct nhrp_nhs
*nhs
;
805 char buf
[SU_ADDRSTRLEN
];
808 for (ALL_LIST_ELEMENTS_RO(iflist
, node
, ifp
)) {
809 vty_out(vty
, "interface %s%s", ifp
->name
, VTY_NEWLINE
);
811 vty_out(vty
, " description %s%s", ifp
->desc
, VTY_NEWLINE
);
814 if (nifp
->ipsec_profile
) {
815 vty_out(vty
, " tunnel protection vici profile %s",
816 nifp
->ipsec_profile
);
817 if (nifp
->ipsec_fallback_profile
)
818 vty_out(vty
, " fallback-profile %s",
819 nifp
->ipsec_fallback_profile
);
820 vty_out(vty
, "%s", VTY_NEWLINE
);
823 vty_out(vty
, " tunnel source %s%s",
824 nifp
->source
, VTY_NEWLINE
);
826 for (afi
= 0; afi
< AFI_MAX
; afi
++) {
827 struct nhrp_afi_data
*ad
= &nifp
->afi
[afi
];
829 aficmd
= afi_to_cmd(afi
);
832 vty_out(vty
, " %s nhrp network-id %u%s",
833 aficmd
, ad
->network_id
,
836 if (ad
->holdtime
!= NHRPD_DEFAULT_HOLDTIME
)
837 vty_out(vty
, " %s nhrp holdtime %u%s",
838 aficmd
, ad
->holdtime
,
841 if (ad
->configured_mtu
< 0)
842 vty_out(vty
, " %s nhrp mtu opennhrp%s",
843 aficmd
, VTY_NEWLINE
);
844 else if (ad
->configured_mtu
)
845 vty_out(vty
, " %s nhrp mtu %u%s",
846 aficmd
, ad
->configured_mtu
,
849 for (i
= 0; interface_flags_desc
[i
].str
!= NULL
; i
++) {
850 if (!(ad
->flags
& interface_flags_desc
[i
].key
))
852 vty_out(vty
, " %s nhrp %s%s",
853 aficmd
, interface_flags_desc
[i
].str
, VTY_NEWLINE
);
856 mapctx
= (struct write_map_ctx
) {
858 .family
= afi2family(afi
),
861 nhrp_cache_foreach(ifp
, interface_config_write_nhrp_map
, &mapctx
);
863 list_for_each_entry(nhs
, &ad
->nhslist_head
, nhslist_entry
) {
864 vty_out(vty
, " %s nhrp nhs %s nbma %s%s",
866 sockunion_family(&nhs
->proto_addr
) == AF_UNSPEC
? "dynamic" : sockunion2str(&nhs
->proto_addr
, buf
, sizeof buf
),
872 vty_out (vty
, "!%s", VTY_NEWLINE
);
878 void nhrp_config_init(void)
880 install_node(&zebra_node
, nhrp_config_write
);
881 install_default(ZEBRA_NODE
);
883 /* global commands */
884 install_element(VIEW_NODE
, &show_debugging_nhrp_cmd
);
885 install_element(VIEW_NODE
, &show_ip_nhrp_cmd
);
886 install_element(VIEW_NODE
, &show_dmvpn_cmd
);
887 install_element(ENABLE_NODE
, &show_debugging_nhrp_cmd
);
888 install_element(ENABLE_NODE
, &show_ip_nhrp_cmd
);
889 install_element(ENABLE_NODE
, &show_dmvpn_cmd
);
890 install_element(ENABLE_NODE
, &clear_nhrp_cmd
);
892 install_element(ENABLE_NODE
, &debug_nhrp_cmd
);
893 install_element(ENABLE_NODE
, &no_debug_nhrp_cmd
);
895 install_element(CONFIG_NODE
, &debug_nhrp_cmd
);
896 install_element(CONFIG_NODE
, &no_debug_nhrp_cmd
);
898 install_element(CONFIG_NODE
, &nhrp_event_socket_cmd
);
899 install_element(CONFIG_NODE
, &no_nhrp_event_socket_cmd
);
900 install_element(CONFIG_NODE
, &nhrp_nflog_group_cmd
);
901 install_element(CONFIG_NODE
, &no_nhrp_nflog_group_cmd
);
903 /* interface specific commands */
904 install_node(&nhrp_interface_node
, interface_config_write
);
905 install_default(INTERFACE_NODE
);
907 install_element(CONFIG_NODE
, &interface_cmd
);
908 install_element(CONFIG_NODE
, &no_interface_cmd
);
909 install_element(INTERFACE_NODE
, &interface_cmd
);
910 install_element(INTERFACE_NODE
, &no_interface_cmd
);
911 install_element(INTERFACE_NODE
, &tunnel_protection_cmd
);
912 install_element(INTERFACE_NODE
, &no_tunnel_protection_cmd
);
913 install_element(INTERFACE_NODE
, &tunnel_source_cmd
);
914 install_element(INTERFACE_NODE
, &no_tunnel_source_cmd
);
915 install_element(INTERFACE_NODE
, &if_nhrp_network_id_cmd
);
916 install_element(INTERFACE_NODE
, &if_no_nhrp_network_id_cmd
);
917 install_element(INTERFACE_NODE
, &if_nhrp_holdtime_cmd
);
918 install_element(INTERFACE_NODE
, &if_no_nhrp_holdtime_cmd
);
919 install_element(INTERFACE_NODE
, &if_nhrp_mtu_cmd
);
920 install_element(INTERFACE_NODE
, &if_no_nhrp_mtu_cmd
);
921 install_element(INTERFACE_NODE
, &if_nhrp_flags_cmd
);
922 install_element(INTERFACE_NODE
, &if_no_nhrp_flags_cmd
);
923 install_element(INTERFACE_NODE
, &if_nhrp_reg_flags_cmd
);
924 install_element(INTERFACE_NODE
, &if_no_nhrp_reg_flags_cmd
);
925 install_element(INTERFACE_NODE
, &if_nhrp_map_cmd
);
926 install_element(INTERFACE_NODE
, &if_nhrp_nhs_cmd
);
927 install_element(INTERFACE_NODE
, &if_no_nhrp_nhs_cmd
);