3 * Copyright (C) 2018-2019 Cumulus Networks, Inc.
6 * This program is free software; you can redistribute it and/or modify it
7 * under the terms of the GNU General Public License as published by the Free
8 * Software Foundation; either version 2 of the License, or (at your option)
11 * This program is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
16 * You should have received a copy of the GNU General Public License along
17 * with this program; see the file COPYING; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
22 #include "lib/command.h"
24 #include "lib/ipaddr.h"
26 #include "lib/prefix.h"
27 #include "lib/termtable.h"
31 #include "vrrp_debug.h"
33 #include "vrrp_zebra.h"
34 #ifndef VTYSH_EXTRACT_PL
35 #include "vrrpd/vrrp_vty_clippy.c"
39 #define VRRP_STR "Virtual Router Redundancy Protocol\n"
40 #define VRRP_VRID_STR "Virtual Router ID\n"
41 #define VRRP_PRIORITY_STR "Virtual Router Priority\n"
42 #define VRRP_ADVINT_STR "Virtual Router Advertisement Interval\n"
43 #define VRRP_IP_STR "Virtual Router IPv4 address\n"
44 #define VRRP_VERSION_STR "VRRP protocol version\n"
46 #define VROUTER_GET_VTY(_vty, _ifp, _vrid, _vr) \
48 _vr = vrrp_lookup(_ifp, _vrid); \
51 "%% Please configure VRRP instance %u\n", \
52 (unsigned int)_vrid); \
53 return CMD_WARNING_CONFIG_FAILED; \
57 /* clang-format off */
61 "[no] vrrp (1-255)$vrid [version (2-3)]",
68 VTY_DECLVAR_CONTEXT(interface
, ifp
);
70 struct vrrp_vrouter
*vr
= vrrp_lookup(ifp
, vrid
);
76 vrrp_vrouter_destroy(vr
);
78 vty_out(vty
, "%% VRRP instance %ld does not exist on %s\n",
81 vrrp_vrouter_create(ifp
, vrid
, version
);
83 vty_out(vty
, "%% VRRP instance %ld already exists on %s\n",
91 "[no] vrrp (1-255)$vrid shutdown",
95 "Force VRRP router into administrative shutdown\n")
97 VTY_DECLVAR_CONTEXT(interface
, ifp
);
99 struct vrrp_vrouter
*vr
;
101 VROUTER_GET_VTY(vty
, ifp
, vrid
, vr
);
104 if (vr
->v4
->fsm
.state
!= VRRP_STATE_INITIALIZE
)
105 vrrp_event(vr
->v4
, VRRP_EVENT_SHUTDOWN
);
106 if (vr
->v6
->fsm
.state
!= VRRP_STATE_INITIALIZE
)
107 vrrp_event(vr
->v6
, VRRP_EVENT_SHUTDOWN
);
110 vr
->shutdown
= false;
111 vrrp_check_start(vr
);
119 "[no] vrrp (1-255)$vrid priority (1-254)",
126 VTY_DECLVAR_CONTEXT(interface
, ifp
);
128 struct vrrp_vrouter
*vr
;
129 uint8_t newprio
= no
? vd
.priority
: priority
;
131 VROUTER_GET_VTY(vty
, ifp
, vrid
, vr
);
133 vrrp_set_priority(vr
, newprio
);
138 DEFPY(vrrp_advertisement_interval
,
139 vrrp_advertisement_interval_cmd
,
140 "[no] vrrp (1-255)$vrid advertisement-interval (10-40950)",
141 NO_STR VRRP_STR VRRP_VRID_STR VRRP_ADVINT_STR
142 "Advertisement interval in milliseconds; must be multiple of 10")
144 VTY_DECLVAR_CONTEXT(interface
, ifp
);
146 struct vrrp_vrouter
*vr
;
148 no
? vd
.advertisement_interval
* CS2MS
: advertisement_interval
;
150 if (newadvint
% CS2MS
!= 0) {
151 vty_out(vty
, "%% Value must be a multiple of %u\n",
152 (unsigned int)CS2MS
);
153 return CMD_WARNING_CONFIG_FAILED
;
156 /* all internal computations are in centiseconds */
159 VROUTER_GET_VTY(vty
, ifp
, vrid
, vr
);
160 vrrp_set_advertisement_interval(vr
, newadvint
);
167 "[no] vrrp (1-255)$vrid ip A.B.C.D",
174 VTY_DECLVAR_CONTEXT(interface
, ifp
);
176 struct vrrp_vrouter
*vr
;
177 bool deactivated
= false;
178 bool activated
= false;
180 int ret
= CMD_SUCCESS
;
183 VROUTER_GET_VTY(vty
, ifp
, vrid
, vr
);
185 bool will_activate
= (vr
->v4
->fsm
.state
== VRRP_STATE_INITIALIZE
);
188 oldstate
= vr
->v4
->fsm
.state
;
189 failed
= vrrp_del_ipv4(vr
, ip
);
190 vrrp_check_start(vr
);
191 deactivated
= (vr
->v4
->fsm
.state
== VRRP_STATE_INITIALIZE
192 && oldstate
!= VRRP_STATE_INITIALIZE
);
194 oldstate
= vr
->v4
->fsm
.state
;
195 failed
= vrrp_add_ipv4(vr
, ip
);
196 vrrp_check_start(vr
);
197 activated
= (vr
->v4
->fsm
.state
!= VRRP_STATE_INITIALIZE
198 && oldstate
== VRRP_STATE_INITIALIZE
);
202 vty_out(vty
, "%% Activated IPv4 Virtual Router %ld\n", vrid
);
204 vty_out(vty
, "%% Deactivated IPv4 Virtual Router %ld\n", vrid
);
206 vty_out(vty
, "%% Failed to %s virtual IP\n",
207 no
? "remove" : "add");
208 ret
= CMD_WARNING_CONFIG_FAILED
;
209 if (will_activate
&& !activated
) {
211 "%% Failed to activate IPv4 Virtual Router %ld\n",
221 "[no] vrrp (1-255)$vrid ipv6 X:X::X:X",
228 VTY_DECLVAR_CONTEXT(interface
, ifp
);
230 struct vrrp_vrouter
*vr
;
231 bool deactivated
= false;
232 bool activated
= false;
234 int ret
= CMD_SUCCESS
;
237 VROUTER_GET_VTY(vty
, ifp
, vrid
, vr
);
239 if (vr
->version
!= 3) {
241 "%% Cannot add IPv6 address to VRRPv2 virtual router\n");
242 return CMD_WARNING_CONFIG_FAILED
;
245 bool will_activate
= (vr
->v6
->fsm
.state
== VRRP_STATE_INITIALIZE
);
248 oldstate
= vr
->v6
->fsm
.state
;
249 failed
= vrrp_del_ipv6(vr
, ipv6
);
250 vrrp_check_start(vr
);
251 deactivated
= (vr
->v6
->fsm
.state
== VRRP_STATE_INITIALIZE
252 && oldstate
!= VRRP_STATE_INITIALIZE
);
254 oldstate
= vr
->v6
->fsm
.state
;
255 failed
= vrrp_add_ipv6(vr
, ipv6
);
256 vrrp_check_start(vr
);
257 activated
= (vr
->v6
->fsm
.state
!= VRRP_STATE_INITIALIZE
258 && oldstate
== VRRP_STATE_INITIALIZE
);
262 vty_out(vty
, "%% Activated IPv6 Virtual Router %ld\n", vrid
);
264 vty_out(vty
, "%% Deactivated IPv6 Virtual Router %ld\n", vrid
);
266 vty_out(vty
, "%% Failed to %s virtual IP\n",
267 no
? "remove" : "add");
268 ret
= CMD_WARNING_CONFIG_FAILED
;
269 if (will_activate
&& !activated
) {
271 "%% Failed to activate IPv6 Virtual Router %ld\n",
281 "[no] vrrp (1-255)$vrid preempt",
287 VTY_DECLVAR_CONTEXT(interface
, ifp
);
289 struct vrrp_vrouter
*vr
;
291 VROUTER_GET_VTY(vty
, ifp
, vrid
, vr
);
293 vr
->preempt_mode
= !no
;
298 DEFPY(vrrp_autoconfigure
,
299 vrrp_autoconfigure_cmd
,
300 "[no] vrrp autoconfigure [version (2-3)]",
303 "Automatically set up VRRP instances on VRRP-compatible interfaces\n"
304 "Version for automatically configured instances\n"
307 version
= version
? version
: 3;
310 vrrp_autoconfig_on(version
);
312 vrrp_autoconfig_off();
319 "[no] vrrp default <advertisement-interval$adv (10-40950)$advint|preempt$p|priority$prio (1-254)$prioval|shutdown$s>",
322 "Configure defaults for new VRRP instances\n"
324 "Advertisement interval in milliseconds\n"
328 "Force VRRP router into administrative shutdown\n")
331 if (advint
% CS2MS
!= 0) {
332 vty_out(vty
, "%% Value must be a multiple of %u\n",
333 (unsigned int)CS2MS
);
334 return CMD_WARNING_CONFIG_FAILED
;
336 /* all internal computations are in centiseconds */
338 vd
.advertisement_interval
= no
? VRRP_DEFAULT_ADVINT
: advint
;
341 vd
.preempt_mode
= !no
;
343 vd
.priority
= no
? VRRP_DEFAULT_PRIORITY
: prioval
;
350 /* clang-format on */
353 * Build JSON representation of VRRP instance.
356 * VRRP router to build json object from
359 * JSON representation of VRRP instance. Must be freed by caller.
361 static struct json_object
*vrrp_build_json(struct vrrp_vrouter
*vr
)
363 char ethstr4
[ETHER_ADDR_STRLEN
];
364 char ethstr6
[ETHER_ADDR_STRLEN
];
365 char ipstr
[INET6_ADDRSTRLEN
];
366 const char *stastr4
= vrrp_state_names
[vr
->v4
->fsm
.state
];
367 const char *stastr6
= vrrp_state_names
[vr
->v6
->fsm
.state
];
368 char sipstr4
[INET6_ADDRSTRLEN
] = {};
369 char sipstr6
[INET6_ADDRSTRLEN
] = {};
372 struct json_object
*j
= json_object_new_object();
373 struct json_object
*v4
= json_object_new_object();
374 struct json_object
*v4_stats
= json_object_new_object();
375 struct json_object
*v4_addrs
= json_object_new_array();
376 struct json_object
*v6
= json_object_new_object();
377 struct json_object
*v6_stats
= json_object_new_object();
378 struct json_object
*v6_addrs
= json_object_new_array();
380 prefix_mac2str(&vr
->v4
->vmac
, ethstr4
, sizeof(ethstr4
));
381 prefix_mac2str(&vr
->v6
->vmac
, ethstr6
, sizeof(ethstr6
));
383 json_object_int_add(j
, "vrid", vr
->vrid
);
384 json_object_int_add(j
, "version", vr
->version
);
385 json_object_boolean_add(j
, "autoconfigured", vr
->autoconf
);
386 json_object_boolean_add(j
, "shutdown", vr
->shutdown
);
387 json_object_boolean_add(j
, "preemptMode", vr
->preempt_mode
);
388 json_object_boolean_add(j
, "acceptMode", vr
->accept_mode
);
389 json_object_string_add(j
, "interface", vr
->ifp
->name
);
390 json_object_int_add(j
, "advertisementInterval",
391 vr
->advertisement_interval
* CS2MS
);
393 json_object_string_add(v4
, "interface",
394 vr
->v4
->mvl_ifp
? vr
->v4
->mvl_ifp
->name
: "");
395 json_object_string_add(v4
, "vmac", ethstr4
);
396 ipaddr2str(&vr
->v4
->src
, sipstr4
, sizeof(sipstr4
));
397 json_object_string_add(v4
, "primaryAddress", sipstr4
);
398 json_object_string_add(v4
, "status", stastr4
);
399 json_object_int_add(v4
, "effectivePriority", vr
->v4
->priority
);
400 json_object_int_add(v4
, "masterAdverInterval",
401 vr
->v4
->master_adver_interval
* CS2MS
);
402 json_object_int_add(v4
, "skewTime", vr
->v4
->skew_time
* CS2MS
);
403 json_object_int_add(v4
, "masterDownInterval",
404 vr
->v4
->master_down_interval
* CS2MS
);
406 json_object_int_add(v4_stats
, "adverTx", vr
->v4
->stats
.adver_tx_cnt
);
407 json_object_int_add(v4_stats
, "adverRx", vr
->v4
->stats
.adver_rx_cnt
);
408 json_object_int_add(v4_stats
, "garpTx", vr
->v4
->stats
.garp_tx_cnt
);
409 json_object_int_add(v4_stats
, "transitions", vr
->v4
->stats
.trans_cnt
);
410 json_object_object_add(v4
, "stats", v4_stats
);
412 if (vr
->v4
->addrs
->count
) {
413 for (ALL_LIST_ELEMENTS_RO(vr
->v4
->addrs
, ln
, ip
)) {
414 inet_ntop(vr
->v4
->family
, &ip
->ipaddr_v4
, ipstr
,
416 json_object_array_add(v4_addrs
,
417 json_object_new_string(ipstr
));
420 json_object_object_add(v4
, "addresses", v4_addrs
);
421 json_object_object_add(j
, "v4", v4
);
424 json_object_string_add(v6
, "interface",
425 vr
->v6
->mvl_ifp
? vr
->v6
->mvl_ifp
->name
: "");
426 json_object_string_add(v6
, "vmac", ethstr6
);
427 ipaddr2str(&vr
->v6
->src
, sipstr6
, sizeof(sipstr6
));
428 if (strlen(sipstr6
) == 0 && vr
->v6
->src
.ip
.addr
== 0x00)
429 strlcat(sipstr6
, "::", sizeof(sipstr6
));
430 json_object_string_add(v6
, "primaryAddress", sipstr6
);
431 json_object_string_add(v6
, "status", stastr6
);
432 json_object_int_add(v6
, "effectivePriority", vr
->v6
->priority
);
433 json_object_int_add(v6
, "masterAdverInterval",
434 vr
->v6
->master_adver_interval
* CS2MS
);
435 json_object_int_add(v6
, "skewTime", vr
->v6
->skew_time
* CS2MS
);
436 json_object_int_add(v6
, "masterDownInterval",
437 vr
->v6
->master_down_interval
* CS2MS
);
439 json_object_int_add(v6_stats
, "adverTx", vr
->v6
->stats
.adver_tx_cnt
);
440 json_object_int_add(v6_stats
, "adverRx", vr
->v6
->stats
.adver_rx_cnt
);
441 json_object_int_add(v6_stats
, "neighborAdverTx",
442 vr
->v6
->stats
.una_tx_cnt
);
443 json_object_int_add(v6_stats
, "transitions", vr
->v6
->stats
.trans_cnt
);
444 json_object_object_add(v6
, "stats", v6_stats
);
446 if (vr
->v6
->addrs
->count
) {
447 for (ALL_LIST_ELEMENTS_RO(vr
->v6
->addrs
, ln
, ip
)) {
448 inet_ntop(vr
->v6
->family
, &ip
->ipaddr_v6
, ipstr
,
450 json_object_array_add(v6_addrs
,
451 json_object_new_string(ipstr
));
454 json_object_object_add(v6
, "addresses", v6_addrs
);
455 json_object_object_add(j
, "v6", v6
);
461 * Dump VRRP instance status to VTY.
467 * VRRP router to dump
469 static void vrrp_show(struct vty
*vty
, struct vrrp_vrouter
*vr
)
471 char ethstr4
[ETHER_ADDR_STRLEN
];
472 char ethstr6
[ETHER_ADDR_STRLEN
];
473 char ipstr
[INET6_ADDRSTRLEN
];
474 const char *stastr4
= vrrp_state_names
[vr
->v4
->fsm
.state
];
475 const char *stastr6
= vrrp_state_names
[vr
->v6
->fsm
.state
];
476 char sipstr4
[INET6_ADDRSTRLEN
] = {};
477 char sipstr6
[INET6_ADDRSTRLEN
] = {};
481 struct ttable
*tt
= ttable_new(&ttable_styles
[TTSTYLE_BLANK
]);
483 ttable_add_row(tt
, "%s|%" PRIu32
, "Virtual Router ID", vr
->vrid
);
484 ttable_add_row(tt
, "%s|%" PRIu8
, "Protocol Version", vr
->version
);
485 ttable_add_row(tt
, "%s|%s", "Autoconfigured",
486 vr
->autoconf
? "Yes" : "No");
487 ttable_add_row(tt
, "%s|%s", "Shutdown", vr
->shutdown
? "Yes" : "No");
488 ttable_add_row(tt
, "%s|%s", "Interface", vr
->ifp
->name
);
489 prefix_mac2str(&vr
->v4
->vmac
, ethstr4
, sizeof(ethstr4
));
490 prefix_mac2str(&vr
->v6
->vmac
, ethstr6
, sizeof(ethstr6
));
491 ttable_add_row(tt
, "%s|%s", "VRRP interface (v4)",
492 vr
->v4
->mvl_ifp
? vr
->v4
->mvl_ifp
->name
: "None");
493 ttable_add_row(tt
, "%s|%s", "VRRP interface (v6)",
494 vr
->v6
->mvl_ifp
? vr
->v6
->mvl_ifp
->name
: "None");
495 ipaddr2str(&vr
->v4
->src
, sipstr4
, sizeof(sipstr4
));
496 ipaddr2str(&vr
->v6
->src
, sipstr6
, sizeof(sipstr6
));
497 if (strlen(sipstr6
) == 0 && vr
->v6
->src
.ip
.addr
== 0x00)
498 strlcat(sipstr6
, "::", sizeof(sipstr6
));
499 ttable_add_row(tt
, "%s|%s", "Primary IP (v4)", sipstr4
);
500 ttable_add_row(tt
, "%s|%s", "Primary IP (v6)", sipstr6
);
501 ttable_add_row(tt
, "%s|%s", "Virtual MAC (v4)", ethstr4
);
502 ttable_add_row(tt
, "%s|%s", "Virtual MAC (v6)", ethstr6
);
503 ttable_add_row(tt
, "%s|%s", "Status (v4)", stastr4
);
504 ttable_add_row(tt
, "%s|%s", "Status (v6)", stastr6
);
505 ttable_add_row(tt
, "%s|%" PRIu8
, "Priority", vr
->priority
);
506 ttable_add_row(tt
, "%s|%" PRIu8
, "Effective Priority (v4)",
508 ttable_add_row(tt
, "%s|%" PRIu8
, "Effective Priority (v6)",
510 ttable_add_row(tt
, "%s|%s", "Preempt Mode",
511 vr
->preempt_mode
? "Yes" : "No");
512 ttable_add_row(tt
, "%s|%s", "Accept Mode",
513 vr
->accept_mode
? "Yes" : "No");
514 ttable_add_row(tt
, "%s|%d ms", "Advertisement Interval",
515 vr
->advertisement_interval
* CS2MS
);
516 ttable_add_row(tt
, "%s|%d ms",
517 "Master Advertisement Interval (v4)",
518 vr
->v4
->master_adver_interval
* CS2MS
);
519 ttable_add_row(tt
, "%s|%d ms",
520 "Master Advertisement Interval (v6)",
521 vr
->v6
->master_adver_interval
* CS2MS
);
522 ttable_add_row(tt
, "%s|%" PRIu32
, "Advertisements Tx (v4)",
523 vr
->v4
->stats
.adver_tx_cnt
);
524 ttable_add_row(tt
, "%s|%" PRIu32
, "Advertisements Tx (v6)",
525 vr
->v6
->stats
.adver_tx_cnt
);
526 ttable_add_row(tt
, "%s|%" PRIu32
, "Advertisements Rx (v4)",
527 vr
->v4
->stats
.adver_rx_cnt
);
528 ttable_add_row(tt
, "%s|%" PRIu32
, "Advertisements Rx (v6)",
529 vr
->v6
->stats
.adver_rx_cnt
);
530 ttable_add_row(tt
, "%s|%" PRIu32
, "Gratuitous ARP Tx (v4)",
531 vr
->v4
->stats
.garp_tx_cnt
);
532 ttable_add_row(tt
, "%s|%" PRIu32
, "Neigh. Adverts Tx (v6)",
533 vr
->v6
->stats
.una_tx_cnt
);
534 ttable_add_row(tt
, "%s|%" PRIu32
, "State transitions (v4)",
535 vr
->v4
->stats
.trans_cnt
);
536 ttable_add_row(tt
, "%s|%" PRIu32
, "State transitions (v6)",
537 vr
->v6
->stats
.trans_cnt
);
538 ttable_add_row(tt
, "%s|%d ms", "Skew Time (v4)",
539 vr
->v4
->skew_time
* CS2MS
);
540 ttable_add_row(tt
, "%s|%d ms", "Skew Time (v6)",
541 vr
->v6
->skew_time
* CS2MS
);
542 ttable_add_row(tt
, "%s|%d ms", "Master Down Interval (v4)",
543 vr
->v4
->master_down_interval
* CS2MS
);
544 ttable_add_row(tt
, "%s|%d ms", "Master Down Interval (v6)",
545 vr
->v6
->master_down_interval
* CS2MS
);
546 ttable_add_row(tt
, "%s|%u", "IPv4 Addresses", vr
->v4
->addrs
->count
);
550 memset(fill
, '.', sizeof(fill
));
551 fill
[sizeof(fill
) - 1] = 0x00;
552 if (vr
->v4
->addrs
->count
) {
553 for (ALL_LIST_ELEMENTS_RO(vr
->v4
->addrs
, ln
, ip
)) {
554 inet_ntop(vr
->v4
->family
, &ip
->ipaddr_v4
, ipstr
,
556 ttable_add_row(tt
, "%s|%s", fill
, ipstr
);
560 ttable_add_row(tt
, "%s|%u", "IPv6 Addresses", vr
->v6
->addrs
->count
);
562 if (vr
->v6
->addrs
->count
) {
563 for (ALL_LIST_ELEMENTS_RO(vr
->v6
->addrs
, ln
, ip
)) {
564 inet_ntop(vr
->v6
->family
, &ip
->ipaddr_v6
, ipstr
,
566 ttable_add_row(tt
, "%s|%s", fill
, ipstr
);
570 char *table
= ttable_dump(tt
, "\n");
572 vty_out(vty
, "\n%s\n", table
);
573 XFREE(MTYPE_TMP
, table
);
578 * Sort comparator, used when sorting VRRP instances for display purposes.
580 * Sorts by interface name first, then by VRID ascending.
582 static int vrrp_instance_display_sort_cmp(const void **d1
, const void **d2
)
584 const struct vrrp_vrouter
*vr1
= *d1
;
585 const struct vrrp_vrouter
*vr2
= *d2
;
588 result
= strcmp(vr1
->ifp
->name
, vr2
->ifp
->name
);
589 result
+= !result
* (vr1
->vrid
- vr2
->vrid
);
594 /* clang-format off */
596 DEFPY(vrrp_vrid_show
,
598 "show vrrp [interface INTERFACE$ifn] [(1-255)$vrid] [json$json]",
602 "Only show VRRP instances on this interface\n"
606 struct vrrp_vrouter
*vr
;
608 struct list
*ll
= hash_to_list(vrrp_vrouters_hash
);
609 struct json_object
*j
= json_object_new_array();
611 list_sort(ll
, vrrp_instance_display_sort_cmp
);
613 for (ALL_LIST_ELEMENTS_RO(ll
, ln
, vr
)) {
614 if (ifn
&& !strmatch(ifn
, vr
->ifp
->name
))
616 if (vrid
&& ((uint8_t) vrid
) != vr
->vrid
)
622 json_object_array_add(j
, vrrp_build_json(vr
));
627 json_object_to_json_string_ext(
628 j
, JSON_C_TO_STRING_PRETTY
));
637 DEFPY(vrrp_vrid_show_summary
,
638 vrrp_vrid_show_summary_cmd
,
639 "show vrrp [interface INTERFACE$ifn] [(1-255)$vrid] summary",
643 "Only show VRRP instances on this interface\n"
645 "Summarize all VRRP instances\n")
647 struct vrrp_vrouter
*vr
;
649 struct list
*ll
= hash_to_list(vrrp_vrouters_hash
);
651 list_sort(ll
, vrrp_instance_display_sort_cmp
);
653 struct ttable
*tt
= ttable_new(&ttable_styles
[TTSTYLE_BLANK
]);
656 tt
, "Interface|VRID|Priority|IPv4|IPv6|State (v4)|State (v6)");
657 ttable_rowseps(tt
, 0, BOTTOM
, true, '-');
659 for (ALL_LIST_ELEMENTS_RO(ll
, ln
, vr
)) {
660 if (ifn
&& !strmatch(ifn
, vr
->ifp
->name
))
662 if (vrid
&& ((uint8_t)vrid
) != vr
->vrid
)
666 tt
, "%s|%" PRIu8
"|%" PRIu8
"|%d|%d|%s|%s",
667 vr
->ifp
->name
, vr
->vrid
, vr
->priority
,
668 vr
->v4
->addrs
->count
, vr
->v6
->addrs
->count
,
669 vr
->v4
->fsm
.state
== VRRP_STATE_MASTER
? "Master"
671 vr
->v6
->fsm
.state
== VRRP_STATE_MASTER
? "Master"
675 char *table
= ttable_dump(tt
, "\n");
677 vty_out(vty
, "\n%s\n", table
);
678 XFREE(MTYPE_TMP
, table
);
689 "[no] debug vrrp [{protocol$proto|autoconfigure$ac|packets$pkt|sockets$sock|ndisc$ndisc|arp$arp|zebra$zebra}]",
693 "Debug protocol state\n"
694 "Debug autoconfiguration\n"
695 "Debug sent and received packets\n"
696 "Debug socket creation and configuration\n"
697 "Debug Neighbor Discovery\n"
699 "Debug Zebra events\n")
701 /* If no specific are given on/off them all */
702 if (strmatch(argv
[argc
- 1]->text
, "vrrp"))
703 vrrp_debug_set(NULL
, 0, vty
->node
, !no
, true, true, true, true,
706 vrrp_debug_set(NULL
, 0, vty
->node
, !no
, !!proto
, !!ac
, !!pkt
,
707 !!sock
, !!ndisc
, !!arp
, !!zebra
);
712 DEFUN_NOSH (show_debugging_vrrp
,
713 show_debugging_vrrp_cmd
,
714 "show debugging [vrrp]",
717 "VRRP information\n")
719 vty_out(vty
, "VRRP debugging status:\n");
721 vrrp_debug_status_write(vty
);
726 /* clang-format on */
728 static struct cmd_node interface_node
= {INTERFACE_NODE
, "%s(config-if)# ", 1};
729 static struct cmd_node debug_node
= {DEBUG_NODE
, "", 1};
730 static struct cmd_node vrrp_node
= {VRRP_NODE
, "", 1};
732 void vrrp_vty_init(void)
734 install_node(&debug_node
, vrrp_config_write_debug
);
735 install_node(&interface_node
, vrrp_config_write_interface
);
736 install_node(&vrrp_node
, vrrp_config_write_global
);
739 install_element(VIEW_NODE
, &vrrp_vrid_show_cmd
);
740 install_element(VIEW_NODE
, &vrrp_vrid_show_summary_cmd
);
741 install_element(VIEW_NODE
, &show_debugging_vrrp_cmd
);
742 install_element(VIEW_NODE
, &debug_vrrp_cmd
);
743 install_element(CONFIG_NODE
, &debug_vrrp_cmd
);
744 install_element(CONFIG_NODE
, &vrrp_autoconfigure_cmd
);
745 install_element(CONFIG_NODE
, &vrrp_default_cmd
);
746 install_element(INTERFACE_NODE
, &vrrp_vrid_cmd
);
747 install_element(INTERFACE_NODE
, &vrrp_shutdown_cmd
);
748 install_element(INTERFACE_NODE
, &vrrp_priority_cmd
);
749 install_element(INTERFACE_NODE
, &vrrp_advertisement_interval_cmd
);
750 install_element(INTERFACE_NODE
, &vrrp_ip_cmd
);
751 install_element(INTERFACE_NODE
, &vrrp_ip6_cmd
);
752 install_element(INTERFACE_NODE
, &vrrp_preempt_cmd
);