#include "lib/sockopt.h"
#include "lib/sockunion.h"
#include "lib/vrf.h"
+#include "lib/vty.h"
#include "vrrp.h"
#include "vrrp_arp.h"
/* Other ------------------------------------------------------------------- */
+int vrrp_config_write_interface(struct vty *vty)
+{
+ struct list *vrs = hash_to_list(vrrp_vrouters_hash);
+ struct listnode *ln;
+ struct vrrp_vrouter *vr;
+ int writes = 0;
+
+ for (ALL_LIST_ELEMENTS_RO(vrs, ln, vr)) {
+ vty_frame(vty, "interface %s\n", vr->ifp->name);
+ ++writes;
+
+ vty_out(vty, " vrrp %" PRIu8 "%s\n", vr->vrid,
+ vr->version == 2 ? " version 2" : "");
+ ++writes;
+
+ if (!vr->preempt_mode && ++writes)
+ vty_out(vty, " no vrrp %" PRIu8 " preempt\n", vr->vrid);
+
+ if (vr->accept_mode && ++writes)
+ vty_out(vty, " vrrp %" PRIu8 " accept\n", vr->vrid);
+
+ if (vr->advertisement_interval != VRRP_DEFAULT_ADVINT
+ && ++writes)
+ vty_out(vty,
+ " vrrp %" PRIu8
+ " advertisement-interval %" PRIu16 "\n",
+ vr->vrid, vr->advertisement_interval);
+
+ if (vr->priority != VRRP_DEFAULT_PRIORITY && ++writes)
+ vty_out(vty, " vrrp %" PRIu8 " priority %" PRIu8 "\n",
+ vr->vrid, vr->priority);
+
+ ln = NULL;
+ struct ipaddr *ip;
+
+ for (ALL_LIST_ELEMENTS_RO(vr->v4->addrs, ln, ip)) {
+ char ipbuf[INET6_ADDRSTRLEN];
+ ipaddr2str(ip, ipbuf, sizeof(ipbuf));
+ vty_out(vty, " vrrp %" PRIu8 " ip %s\n", vr->vrid,
+ ipbuf);
+ ++writes;
+ }
+ for (ALL_LIST_ELEMENTS_RO(vr->v6->addrs, ln, ip)) {
+ char ipbuf[INET6_ADDRSTRLEN];
+ ipaddr2str(ip, ipbuf, sizeof(ipbuf));
+ vty_out(vty, " vrrp %" PRIu8 " ipv6 %s\n", vr->vrid,
+ ipbuf);
+ ++writes;
+ }
+ }
+
+ return writes;
+}
+
+int vrrp_config_write_global(struct vty *vty)
+{
+ if (vrrp_autoconfig_is_on)
+ vty_out(vty, "vrrp autoconfigure%s\n",
+ vrrp_autoconfig_version == 2 ? " version 2" : "");
+
+ return 1;
+}
+
static unsigned int vrrp_hash_key(void *arg)
{
struct vrrp_vrouter *vr = arg;
#include "lib/privs.h"
#include "lib/stream.h"
#include "lib/thread.h"
+#include "lib/vty.h"
/* Global definitions */
#define VRRP_DEFAULT_ADVINT 100
/* Other ------------------------------------------------------------------- */
+/*
+ * Write interface block-level configuration to vty.
+ *
+ * vty
+ * vty to write config to
+ *
+ * Returns:
+ * # of lines written
+ */
+int vrrp_config_write_interface(struct vty *vty);
+
+/*
+ * Write global level configuration to vty.
+ *
+ * vty
+ * vty to write config to
+ *
+ * Returns:
+ * # of lines written
+ */
+int vrrp_config_write_global(struct vty *vty);
+
/*
* Find VRRP Virtual Router by Virtual Router ID
*/
/* clang-format on */
-static struct cmd_node interface_node = {
- INTERFACE_NODE,
- "%s(config-if)# ", 1
-};
-
+static struct cmd_node interface_node = {INTERFACE_NODE, "%s(config-if)# ", 1};
static struct cmd_node debug_node = {DEBUG_NODE, "", 1};
+static struct cmd_node vrrp_node = {VRRP_NODE, "", 1};
void vrrp_vty_init(void)
{
- install_node(&debug_node, vrrp_debug_config_write);
- install_node(&interface_node, NULL);
+ install_node(&debug_node, vrrp_config_write_debug);
+ install_node(&interface_node, vrrp_config_write_interface);
+ install_node(&vrrp_node, vrrp_config_write_global);
if_cmd_init();
install_element(VIEW_NODE, &vrrp_vrid_show_cmd);