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/northbound_cli.h"
27 #include "lib/prefix.h"
28 #include "lib/termtable.h"
33 #include "vrrp_debug.h"
35 #include "vrrp_zebra.h"
36 #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 IP address\n"
44 #define VRRP_VERSION_STR "VRRP protocol version\n"
46 #define VRRP_XPATH_ENTRY VRRP_XPATH "[virtual-router-id='%ld']"
48 /* clang-format off */
51 * XPath: /frr-interface:lib/interface/frr-vrrpd:vrrp/vrrp-group
55 "[no] vrrp (1-255)$vrid [version (2-3)]",
64 snprintf(valbuf
, sizeof(valbuf
), "%ld", version
? version
: vd
.version
);
67 nb_cli_enqueue_change(vty
, ".", NB_OP_DESTROY
, NULL
);
69 nb_cli_enqueue_change(vty
, ".", NB_OP_CREATE
, NULL
);
70 nb_cli_enqueue_change(vty
, "./version", NB_OP_MODIFY
, valbuf
);
73 return nb_cli_apply_changes(vty
, VRRP_XPATH_ENTRY
, vrid
);
76 void cli_show_vrrp(struct vty
*vty
, const struct lyd_node
*dnode
, bool show_defaults
)
78 const char *vrid
= yang_dnode_get_string(dnode
, "./virtual-router-id");
79 const char *ver
= yang_dnode_get_string(dnode
, "./version");
81 vty_out(vty
, " vrrp %s", vrid
);
82 if (show_defaults
|| !yang_dnode_is_default(dnode
, "./version"))
83 vty_out(vty
, " version %s", ver
);
88 * XPath: /frr-interface:lib/interface/frr-vrrpd:vrrp/vrrp-group/shutdown
90 DEFPY_YANG(vrrp_shutdown
,
92 "[no] vrrp (1-255)$vrid shutdown",
96 "Force VRRP router into administrative shutdown\n")
98 nb_cli_enqueue_change(vty
, "./shutdown", NB_OP_MODIFY
,
99 no
? "false" : "true");
101 return nb_cli_apply_changes(vty
, VRRP_XPATH_ENTRY
, vrid
);
104 void cli_show_shutdown(struct vty
*vty
, const struct lyd_node
*dnode
,
107 const char *vrid
= yang_dnode_get_string(dnode
, "../virtual-router-id");
108 const bool shut
= yang_dnode_get_bool(dnode
, NULL
);
110 vty_out(vty
, " %svrrp %s shutdown\n", shut
? "" : "no ", vrid
);
114 * XPath: /frr-interface:lib/interface/frr-vrrpd:vrrp/vrrp-group/priority
116 DEFPY_YANG(vrrp_priority
,
118 "vrrp (1-255)$vrid priority (1-254)",
124 nb_cli_enqueue_change(vty
, "./priority", NB_OP_MODIFY
, priority_str
);
126 return nb_cli_apply_changes(vty
, VRRP_XPATH_ENTRY
, vrid
);
130 * XPath: /frr-interface:lib/interface/frr-vrrpd:vrrp/vrrp-group/priority
132 DEFPY_YANG(no_vrrp_priority
,
133 no_vrrp_priority_cmd
,
134 "no vrrp (1-255)$vrid priority [(1-254)]",
141 nb_cli_enqueue_change(vty
, "./priority", NB_OP_MODIFY
, NULL
);
143 return nb_cli_apply_changes(vty
, VRRP_XPATH_ENTRY
, vrid
);
146 void cli_show_priority(struct vty
*vty
, const struct lyd_node
*dnode
,
149 const char *vrid
= yang_dnode_get_string(dnode
, "../virtual-router-id");
150 const char *prio
= yang_dnode_get_string(dnode
, NULL
);
152 vty_out(vty
, " vrrp %s priority %s\n", vrid
, prio
);
157 * /frr-interface:lib/interface/frr-vrrpd:vrrp/vrrp-group/advertisement-interval
159 DEFPY_YANG(vrrp_advertisement_interval
,
160 vrrp_advertisement_interval_cmd
,
161 "vrrp (1-255)$vrid advertisement-interval (10-40950)",
162 VRRP_STR VRRP_VRID_STR VRRP_ADVINT_STR
163 "Advertisement interval in milliseconds; must be multiple of 10\n")
167 /* all internal computations are in centiseconds */
168 advertisement_interval
/= CS2MS
;
169 snprintf(val
, sizeof(val
), "%ld", advertisement_interval
);
170 nb_cli_enqueue_change(vty
, "./advertisement-interval", NB_OP_MODIFY
,
173 return nb_cli_apply_changes(vty
, VRRP_XPATH_ENTRY
, vrid
);
178 * /frr-interface:lib/interface/frr-vrrpd:vrrp/vrrp-group/advertisement-interval
180 DEFPY_YANG(no_vrrp_advertisement_interval
,
181 no_vrrp_advertisement_interval_cmd
,
182 "no vrrp (1-255)$vrid advertisement-interval [(10-40950)]",
183 NO_STR VRRP_STR VRRP_VRID_STR VRRP_ADVINT_STR
184 "Advertisement interval in milliseconds; must be multiple of 10\n")
186 nb_cli_enqueue_change(vty
, "./advertisement-interval", NB_OP_MODIFY
,
189 return nb_cli_apply_changes(vty
, VRRP_XPATH_ENTRY
, vrid
);
192 void cli_show_advertisement_interval(struct vty
*vty
, const struct lyd_node
*dnode
,
195 const char *vrid
= yang_dnode_get_string(dnode
, "../virtual-router-id");
196 uint16_t advint
= yang_dnode_get_uint16(dnode
, NULL
);
198 vty_out(vty
, " vrrp %s advertisement-interval %u\n", vrid
,
204 * /frr-interface:lib/interface/frr-vrrpd:vrrp/vrrp-group/v4/virtual-address
208 "[no] vrrp (1-255)$vrid ip A.B.C.D",
215 int op
= no
? NB_OP_DESTROY
: NB_OP_CREATE
;
216 nb_cli_enqueue_change(vty
, "./v4/virtual-address", op
, ip_str
);
218 return nb_cli_apply_changes(vty
, VRRP_XPATH_ENTRY
, vrid
);
221 void cli_show_ip(struct vty
*vty
, const struct lyd_node
*dnode
, bool show_defaults
)
224 yang_dnode_get_string(dnode
, "../../virtual-router-id");
225 const char *ipv4
= yang_dnode_get_string(dnode
, NULL
);
227 vty_out(vty
, " vrrp %s ip %s\n", vrid
, ipv4
);
232 * /frr-interface:lib/interface/frr-vrrpd:vrrp/vrrp-group/v6/virtual-address
236 "[no] vrrp (1-255)$vrid ipv6 X:X::X:X",
243 int op
= no
? NB_OP_DESTROY
: NB_OP_CREATE
;
244 nb_cli_enqueue_change(vty
, "./v6/virtual-address", op
, ipv6_str
);
246 return nb_cli_apply_changes(vty
, VRRP_XPATH_ENTRY
, vrid
);
249 void cli_show_ipv6(struct vty
*vty
, const struct lyd_node
*dnode
, bool show_defaults
)
252 yang_dnode_get_string(dnode
, "../../virtual-router-id");
253 const char *ipv6
= yang_dnode_get_string(dnode
, NULL
);
255 vty_out(vty
, " vrrp %s ipv6 %s\n", vrid
, ipv6
);
259 * XPath: /frr-interface:lib/interface/frr-vrrpd:vrrp/vrrp-group/preempt
261 DEFPY_YANG(vrrp_preempt
,
263 "[no] vrrp (1-255)$vrid preempt",
269 nb_cli_enqueue_change(vty
, "./preempt", NB_OP_MODIFY
,
270 no
? "false" : "true");
272 return nb_cli_apply_changes(vty
, VRRP_XPATH_ENTRY
, vrid
);
275 void cli_show_preempt(struct vty
*vty
, const struct lyd_node
*dnode
,
278 const char *vrid
= yang_dnode_get_string(dnode
, "../virtual-router-id");
279 const bool pre
= yang_dnode_get_bool(dnode
, NULL
);
281 vty_out(vty
, " %svrrp %s preempt\n", pre
? "" : "no ", vrid
);
284 /* XXX: yang conversion */
285 DEFPY_YANG(vrrp_autoconfigure
,
286 vrrp_autoconfigure_cmd
,
287 "[no] vrrp autoconfigure [version (2-3)]",
290 "Automatically set up VRRP instances on VRRP-compatible interfaces\n"
291 "Version for automatically configured instances\n"
294 version
= version
? version
: 3;
297 vrrp_autoconfig_on(version
);
299 vrrp_autoconfig_off();
304 /* XXX: yang conversion */
305 DEFPY_YANG(vrrp_default
,
307 "[no] vrrp default <advertisement-interval$adv (10-40950)$advint|preempt$p|priority$prio (1-254)$prioval|shutdown$s>",
310 "Configure defaults for new VRRP instances\n"
312 "Advertisement interval in milliseconds\n"
316 "Force VRRP router into administrative shutdown\n")
319 if (advint
% CS2MS
!= 0) {
320 vty_out(vty
, "%% Value must be a multiple of %u\n",
321 (unsigned int)CS2MS
);
322 return CMD_WARNING_CONFIG_FAILED
;
324 /* all internal computations are in centiseconds */
326 vd
.advertisement_interval
= no
? VRRP_DEFAULT_ADVINT
: advint
;
329 vd
.preempt_mode
= !no
;
331 vd
.priority
= no
? VRRP_DEFAULT_PRIORITY
: prioval
;
338 /* clang-format on */
341 * Build JSON representation of VRRP instance.
344 * VRRP router to build json object from
347 * JSON representation of VRRP instance. Must be freed by caller.
349 static struct json_object
*vrrp_build_json(struct vrrp_vrouter
*vr
)
351 char ethstr4
[ETHER_ADDR_STRLEN
];
352 char ethstr6
[ETHER_ADDR_STRLEN
];
353 char ipstr
[INET6_ADDRSTRLEN
];
354 const char *stastr4
= vrrp_state_names
[vr
->v4
->fsm
.state
];
355 const char *stastr6
= vrrp_state_names
[vr
->v6
->fsm
.state
];
356 char sipstr4
[INET6_ADDRSTRLEN
] = {};
357 char sipstr6
[INET6_ADDRSTRLEN
] = {};
360 struct json_object
*j
= json_object_new_object();
361 struct json_object
*v4
= json_object_new_object();
362 struct json_object
*v4_stats
= json_object_new_object();
363 struct json_object
*v4_addrs
= json_object_new_array();
364 struct json_object
*v6
= json_object_new_object();
365 struct json_object
*v6_stats
= json_object_new_object();
366 struct json_object
*v6_addrs
= json_object_new_array();
368 prefix_mac2str(&vr
->v4
->vmac
, ethstr4
, sizeof(ethstr4
));
369 prefix_mac2str(&vr
->v6
->vmac
, ethstr6
, sizeof(ethstr6
));
371 json_object_int_add(j
, "vrid", vr
->vrid
);
372 json_object_int_add(j
, "version", vr
->version
);
373 json_object_boolean_add(j
, "autoconfigured", vr
->autoconf
);
374 json_object_boolean_add(j
, "shutdown", vr
->shutdown
);
375 json_object_boolean_add(j
, "preemptMode", vr
->preempt_mode
);
376 json_object_boolean_add(j
, "acceptMode", vr
->accept_mode
);
377 json_object_string_add(j
, "interface", vr
->ifp
->name
);
378 json_object_int_add(j
, "advertisementInterval",
379 vr
->advertisement_interval
* CS2MS
);
381 json_object_string_add(v4
, "interface",
382 vr
->v4
->mvl_ifp
? vr
->v4
->mvl_ifp
->name
: "");
383 json_object_string_add(v4
, "vmac", ethstr4
);
384 ipaddr2str(&vr
->v4
->src
, sipstr4
, sizeof(sipstr4
));
385 json_object_string_add(v4
, "primaryAddress", sipstr4
);
386 json_object_string_add(v4
, "status", stastr4
);
387 json_object_int_add(v4
, "effectivePriority", vr
->v4
->priority
);
388 json_object_int_add(v4
, "masterAdverInterval",
389 vr
->v4
->master_adver_interval
* CS2MS
);
390 json_object_int_add(v4
, "skewTime", vr
->v4
->skew_time
* CS2MS
);
391 json_object_int_add(v4
, "masterDownInterval",
392 vr
->v4
->master_down_interval
* CS2MS
);
394 json_object_int_add(v4_stats
, "adverTx", vr
->v4
->stats
.adver_tx_cnt
);
395 json_object_int_add(v4_stats
, "adverRx", vr
->v4
->stats
.adver_rx_cnt
);
396 json_object_int_add(v4_stats
, "garpTx", vr
->v4
->stats
.garp_tx_cnt
);
397 json_object_int_add(v4_stats
, "transitions", vr
->v4
->stats
.trans_cnt
);
398 json_object_object_add(v4
, "stats", v4_stats
);
400 if (vr
->v4
->addrs
->count
) {
401 for (ALL_LIST_ELEMENTS_RO(vr
->v4
->addrs
, ln
, ip
)) {
402 inet_ntop(vr
->v4
->family
, &ip
->ipaddr_v4
, ipstr
,
404 json_object_array_add(v4_addrs
,
405 json_object_new_string(ipstr
));
408 json_object_object_add(v4
, "addresses", v4_addrs
);
409 json_object_object_add(j
, "v4", v4
);
412 json_object_string_add(v6
, "interface",
413 vr
->v6
->mvl_ifp
? vr
->v6
->mvl_ifp
->name
: "");
414 json_object_string_add(v6
, "vmac", ethstr6
);
415 ipaddr2str(&vr
->v6
->src
, sipstr6
, sizeof(sipstr6
));
416 if (strlen(sipstr6
) == 0 && vr
->v6
->src
.ip
.addr
== 0x00)
417 strlcat(sipstr6
, "::", sizeof(sipstr6
));
418 json_object_string_add(v6
, "primaryAddress", sipstr6
);
419 json_object_string_add(v6
, "status", stastr6
);
420 json_object_int_add(v6
, "effectivePriority", vr
->v6
->priority
);
421 json_object_int_add(v6
, "masterAdverInterval",
422 vr
->v6
->master_adver_interval
* CS2MS
);
423 json_object_int_add(v6
, "skewTime", vr
->v6
->skew_time
* CS2MS
);
424 json_object_int_add(v6
, "masterDownInterval",
425 vr
->v6
->master_down_interval
* CS2MS
);
427 json_object_int_add(v6_stats
, "adverTx", vr
->v6
->stats
.adver_tx_cnt
);
428 json_object_int_add(v6_stats
, "adverRx", vr
->v6
->stats
.adver_rx_cnt
);
429 json_object_int_add(v6_stats
, "neighborAdverTx",
430 vr
->v6
->stats
.una_tx_cnt
);
431 json_object_int_add(v6_stats
, "transitions", vr
->v6
->stats
.trans_cnt
);
432 json_object_object_add(v6
, "stats", v6_stats
);
434 if (vr
->v6
->addrs
->count
) {
435 for (ALL_LIST_ELEMENTS_RO(vr
->v6
->addrs
, ln
, ip
)) {
436 inet_ntop(vr
->v6
->family
, &ip
->ipaddr_v6
, ipstr
,
438 json_object_array_add(v6_addrs
,
439 json_object_new_string(ipstr
));
442 json_object_object_add(v6
, "addresses", v6_addrs
);
443 json_object_object_add(j
, "v6", v6
);
449 * Dump VRRP instance status to VTY.
455 * VRRP router to dump
457 static void vrrp_show(struct vty
*vty
, struct vrrp_vrouter
*vr
)
459 char ethstr4
[ETHER_ADDR_STRLEN
];
460 char ethstr6
[ETHER_ADDR_STRLEN
];
461 char ipstr
[INET6_ADDRSTRLEN
];
462 const char *stastr4
= vrrp_state_names
[vr
->v4
->fsm
.state
];
463 const char *stastr6
= vrrp_state_names
[vr
->v6
->fsm
.state
];
464 char sipstr4
[INET6_ADDRSTRLEN
] = {};
465 char sipstr6
[INET6_ADDRSTRLEN
] = {};
469 struct ttable
*tt
= ttable_new(&ttable_styles
[TTSTYLE_BLANK
]);
471 ttable_add_row(tt
, "%s|%u", "Virtual Router ID", vr
->vrid
);
472 ttable_add_row(tt
, "%s|%hhu", "Protocol Version", vr
->version
);
473 ttable_add_row(tt
, "%s|%s", "Autoconfigured",
474 vr
->autoconf
? "Yes" : "No");
475 ttable_add_row(tt
, "%s|%s", "Shutdown", vr
->shutdown
? "Yes" : "No");
476 ttable_add_row(tt
, "%s|%s", "Interface", vr
->ifp
->name
);
477 prefix_mac2str(&vr
->v4
->vmac
, ethstr4
, sizeof(ethstr4
));
478 prefix_mac2str(&vr
->v6
->vmac
, ethstr6
, sizeof(ethstr6
));
479 ttable_add_row(tt
, "%s|%s", "VRRP interface (v4)",
480 vr
->v4
->mvl_ifp
? vr
->v4
->mvl_ifp
->name
: "None");
481 ttable_add_row(tt
, "%s|%s", "VRRP interface (v6)",
482 vr
->v6
->mvl_ifp
? vr
->v6
->mvl_ifp
->name
: "None");
483 ipaddr2str(&vr
->v4
->src
, sipstr4
, sizeof(sipstr4
));
484 ipaddr2str(&vr
->v6
->src
, sipstr6
, sizeof(sipstr6
));
485 if (strlen(sipstr6
) == 0 && vr
->v6
->src
.ip
.addr
== 0x00)
486 strlcat(sipstr6
, "::", sizeof(sipstr6
));
487 ttable_add_row(tt
, "%s|%s", "Primary IP (v4)", sipstr4
);
488 ttable_add_row(tt
, "%s|%s", "Primary IP (v6)", sipstr6
);
489 ttable_add_row(tt
, "%s|%s", "Virtual MAC (v4)", ethstr4
);
490 ttable_add_row(tt
, "%s|%s", "Virtual MAC (v6)", ethstr6
);
491 ttable_add_row(tt
, "%s|%s", "Status (v4)", stastr4
);
492 ttable_add_row(tt
, "%s|%s", "Status (v6)", stastr6
);
493 ttable_add_row(tt
, "%s|%hhu", "Priority", vr
->priority
);
494 ttable_add_row(tt
, "%s|%hhu", "Effective Priority (v4)",
496 ttable_add_row(tt
, "%s|%hhu", "Effective Priority (v6)",
498 ttable_add_row(tt
, "%s|%s", "Preempt Mode",
499 vr
->preempt_mode
? "Yes" : "No");
500 ttable_add_row(tt
, "%s|%s", "Accept Mode",
501 vr
->accept_mode
? "Yes" : "No");
502 ttable_add_row(tt
, "%s|%d ms", "Advertisement Interval",
503 vr
->advertisement_interval
* CS2MS
);
504 ttable_add_row(tt
, "%s|%d ms (stale)",
505 "Master Advertisement Interval (v4) Rx",
506 vr
->v4
->master_adver_interval
* CS2MS
);
507 ttable_add_row(tt
, "%s|%d ms (stale)",
508 "Master Advertisement Interval (v6) Rx",
509 vr
->v6
->master_adver_interval
* CS2MS
);
510 ttable_add_row(tt
, "%s|%u", "Advertisements Tx (v4)",
511 vr
->v4
->stats
.adver_tx_cnt
);
512 ttable_add_row(tt
, "%s|%u", "Advertisements Tx (v6)",
513 vr
->v6
->stats
.adver_tx_cnt
);
514 ttable_add_row(tt
, "%s|%u", "Advertisements Rx (v4)",
515 vr
->v4
->stats
.adver_rx_cnt
);
516 ttable_add_row(tt
, "%s|%u", "Advertisements Rx (v6)",
517 vr
->v6
->stats
.adver_rx_cnt
);
518 ttable_add_row(tt
, "%s|%u", "Gratuitous ARP Tx (v4)",
519 vr
->v4
->stats
.garp_tx_cnt
);
520 ttable_add_row(tt
, "%s|%u", "Neigh. Adverts Tx (v6)",
521 vr
->v6
->stats
.una_tx_cnt
);
522 ttable_add_row(tt
, "%s|%u", "State transitions (v4)",
523 vr
->v4
->stats
.trans_cnt
);
524 ttable_add_row(tt
, "%s|%u", "State transitions (v6)",
525 vr
->v6
->stats
.trans_cnt
);
526 ttable_add_row(tt
, "%s|%d ms", "Skew Time (v4)",
527 vr
->v4
->skew_time
* CS2MS
);
528 ttable_add_row(tt
, "%s|%d ms", "Skew Time (v6)",
529 vr
->v6
->skew_time
* CS2MS
);
530 ttable_add_row(tt
, "%s|%d ms", "Master Down Interval (v4)",
531 vr
->v4
->master_down_interval
* CS2MS
);
532 ttable_add_row(tt
, "%s|%d ms", "Master Down Interval (v6)",
533 vr
->v6
->master_down_interval
* CS2MS
);
534 ttable_add_row(tt
, "%s|%u", "IPv4 Addresses", vr
->v4
->addrs
->count
);
538 memset(fill
, '.', sizeof(fill
));
539 fill
[sizeof(fill
) - 1] = 0x00;
540 if (vr
->v4
->addrs
->count
) {
541 for (ALL_LIST_ELEMENTS_RO(vr
->v4
->addrs
, ln
, ip
)) {
542 inet_ntop(vr
->v4
->family
, &ip
->ipaddr_v4
, ipstr
,
544 ttable_add_row(tt
, "%s|%s", fill
, ipstr
);
548 ttable_add_row(tt
, "%s|%u", "IPv6 Addresses", vr
->v6
->addrs
->count
);
550 if (vr
->v6
->addrs
->count
) {
551 for (ALL_LIST_ELEMENTS_RO(vr
->v6
->addrs
, ln
, ip
)) {
552 inet_ntop(vr
->v6
->family
, &ip
->ipaddr_v6
, ipstr
,
554 ttable_add_row(tt
, "%s|%s", fill
, ipstr
);
558 char *table
= ttable_dump(tt
, "\n");
560 vty_out(vty
, "\n%s\n", table
);
561 XFREE(MTYPE_TMP
, table
);
566 * Sort comparator, used when sorting VRRP instances for display purposes.
568 * Sorts by interface name first, then by VRID ascending.
570 static int vrrp_instance_display_sort_cmp(const void **d1
, const void **d2
)
572 const struct vrrp_vrouter
*vr1
= *d1
;
573 const struct vrrp_vrouter
*vr2
= *d2
;
576 result
= strcmp(vr1
->ifp
->name
, vr2
->ifp
->name
);
577 result
+= !result
* (vr1
->vrid
- vr2
->vrid
);
582 /* clang-format off */
584 DEFPY_YANG(vrrp_vrid_show
,
586 "show vrrp [interface INTERFACE$ifn] [(1-255)$vrid] [json$json]",
590 "Only show VRRP instances on this interface\n"
594 struct vrrp_vrouter
*vr
;
596 struct list
*ll
= hash_to_list(vrrp_vrouters_hash
);
597 struct json_object
*j
= json_object_new_array();
599 list_sort(ll
, vrrp_instance_display_sort_cmp
);
601 for (ALL_LIST_ELEMENTS_RO(ll
, ln
, vr
)) {
602 if (ifn
&& !strmatch(ifn
, vr
->ifp
->name
))
604 if (vrid
&& ((uint8_t) vrid
) != vr
->vrid
)
610 json_object_array_add(j
, vrrp_build_json(vr
));
615 json_object_to_json_string_ext(
616 j
, JSON_C_TO_STRING_PRETTY
));
625 DEFPY_YANG(vrrp_vrid_show_summary
,
626 vrrp_vrid_show_summary_cmd
,
627 "show vrrp [interface INTERFACE$ifn] [(1-255)$vrid] summary",
631 "Only show VRRP instances on this interface\n"
633 "Summarize all VRRP instances\n")
635 struct vrrp_vrouter
*vr
;
637 struct list
*ll
= hash_to_list(vrrp_vrouters_hash
);
639 list_sort(ll
, vrrp_instance_display_sort_cmp
);
641 struct ttable
*tt
= ttable_new(&ttable_styles
[TTSTYLE_BLANK
]);
644 tt
, "Interface|VRID|Priority|IPv4|IPv6|State (v4)|State (v6)");
645 ttable_rowseps(tt
, 0, BOTTOM
, true, '-');
647 for (ALL_LIST_ELEMENTS_RO(ll
, ln
, vr
)) {
648 if (ifn
&& !strmatch(ifn
, vr
->ifp
->name
))
650 if (vrid
&& ((uint8_t)vrid
) != vr
->vrid
)
654 tt
, "%s|%u|%hhu|%d|%d|%s|%s",
655 vr
->ifp
->name
, vr
->vrid
, vr
->priority
,
656 vr
->v4
->addrs
->count
, vr
->v6
->addrs
->count
,
657 vr
->v4
->fsm
.state
== VRRP_STATE_MASTER
? "Master"
659 vr
->v6
->fsm
.state
== VRRP_STATE_MASTER
? "Master"
663 char *table
= ttable_dump(tt
, "\n");
665 vty_out(vty
, "\n%s\n", table
);
666 XFREE(MTYPE_TMP
, table
);
675 DEFPY_YANG(debug_vrrp
,
677 "[no] debug vrrp [{protocol$proto|autoconfigure$ac|packets$pkt|sockets$sock|ndisc$ndisc|arp$arp|zebra$zebra}]",
681 "Debug protocol state\n"
682 "Debug autoconfiguration\n"
683 "Debug sent and received packets\n"
684 "Debug socket creation and configuration\n"
685 "Debug Neighbor Discovery\n"
687 "Debug Zebra events\n")
689 /* If no specific are given on/off them all */
690 if (strmatch(argv
[argc
- 1]->text
, "vrrp"))
691 vrrp_debug_set(NULL
, 0, vty
->node
, !no
, true, true, true, true,
694 vrrp_debug_set(NULL
, 0, vty
->node
, !no
, !!proto
, !!ac
, !!pkt
,
695 !!sock
, !!ndisc
, !!arp
, !!zebra
);
700 DEFUN_NOSH (show_debugging_vrrp
,
701 show_debugging_vrrp_cmd
,
702 "show debugging [vrrp]",
705 "VRRP information\n")
707 vty_out(vty
, "VRRP debugging status:\n");
709 vrrp_debug_status_write(vty
);
711 cmd_show_lib_debugs(vty
);
716 /* clang-format on */
718 static struct cmd_node debug_node
= {
722 .config_write
= vrrp_config_write_debug
,
725 static struct cmd_node vrrp_node
= {
729 .config_write
= vrrp_config_write_global
,
732 void vrrp_vty_init(void)
734 install_node(&debug_node
);
735 install_node(&vrrp_node
);
737 if_cmd_init_default();
739 install_element(VIEW_NODE
, &vrrp_vrid_show_cmd
);
740 install_element(VIEW_NODE
, &vrrp_vrid_show_summary_cmd
);
741 install_element(ENABLE_NODE
, &show_debugging_vrrp_cmd
);
742 install_element(ENABLE_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
, &no_vrrp_priority_cmd
);
750 install_element(INTERFACE_NODE
, &vrrp_advertisement_interval_cmd
);
751 install_element(INTERFACE_NODE
, &no_vrrp_advertisement_interval_cmd
);
752 install_element(INTERFACE_NODE
, &vrrp_ip_cmd
);
753 install_element(INTERFACE_NODE
, &vrrp_ip6_cmd
);
754 install_element(INTERFACE_NODE
, &vrrp_preempt_cmd
);