]> git.puffer.fish Git - matthieu/frr.git/commitdiff
vrrpd: add support for configuration writing
authorQuentin Young <qlyoung@cumulusnetworks.com>
Wed, 13 Feb 2019 19:56:40 +0000 (19:56 +0000)
committerQuentin Young <qlyoung@cumulusnetworks.com>
Fri, 17 May 2019 00:27:08 +0000 (00:27 +0000)
Signed-off-by: Quentin Young <qlyoung@cumulusnetworks.com>
lib/command.c
lib/command.h
vrrpd/vrrp.c
vrrpd/vrrp.h
vrrpd/vrrp_debug.c
vrrpd/vrrp_debug.h
vrrpd/vrrp_vty.c

index b7a323e35865c3c891a4830332107b79483be450..73bb9580cdc3b625426150f20e337d5e64735ae3 100644 (file)
@@ -149,6 +149,7 @@ const char *node_names[] = {
        "bfd",                   /* BFD_NODE */
        "bfd peer",              /* BFD_PEER_NODE */
        "openfabric",               // OPENFABRIC_NODE
+       "vrrp",                     // VRRP_NODE
 };
 /* clang-format on */
 
index a5f9616dbf3c74a9989d02fed021bd3a4690c3eb..d96ec97e67998ddfaac53d531e7bffe192448e10 100644 (file)
@@ -147,6 +147,7 @@ enum node_type {
        BFD_NODE,                /* BFD protocol mode. */
        BFD_PEER_NODE,           /* BFD peer configuration mode. */
        OPENFABRIC_NODE,        /* OpenFabric router configuration node */
+       VRRP_NODE,               /* VRRP node */
        NODE_TYPE_MAX, /* maximum */
 };
 
index 92caaeff3b83634f7b7e0177049d70aae2809c70..658dc098a2f54631eee5a30c85a6c03ba801546b 100644 (file)
@@ -29,6 +29,7 @@
 #include "lib/sockopt.h"
 #include "lib/sockunion.h"
 #include "lib/vrf.h"
+#include "lib/vty.h"
 
 #include "vrrp.h"
 #include "vrrp_arp.h"
@@ -1609,6 +1610,69 @@ void vrrp_autoconfig_off(void)
 
 /* 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;
index ed68b6a812d773ad4ed57f9c7009dc640511719f..eabb23fe75a32ee5336a3bcc9156b7205bb4dff2 100644 (file)
@@ -30,6 +30,7 @@
 #include "lib/privs.h"
 #include "lib/stream.h"
 #include "lib/thread.h"
+#include "lib/vty.h"
 
 /* Global definitions */
 #define VRRP_DEFAULT_ADVINT 100
@@ -558,6 +559,28 @@ int vrrp_autoconfig_if_address_del(struct interface *ifp);
 
 /* 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
  */
index cea2bbff79fdce2dab8606622965f00a6c747fa9..b841bca78ae7f4b0a8dac374608c00700c61d6f2 100644 (file)
@@ -89,7 +89,7 @@ static int vrrp_debug_config_write_helper(struct vty *vty, bool config)
        return 0;
 }
 
-int vrrp_debug_config_write(struct vty *vty)
+int vrrp_config_write_debug(struct vty *vty)
 {
        return vrrp_debug_config_write_helper(vty, true);
 }
index c54b20e5b8368a146c967f07e874d77dd22917fa..20f993095564c5bc7d98014adeef6c930e3e0c3a 100644 (file)
@@ -46,7 +46,7 @@ void vrrp_debug_init(void);
  * vty
  *    VTY to print debugging configuration to.
  */
-int vrrp_debug_config_write(struct vty *vty);
+int vrrp_config_write_debug(struct vty *vty);
 
 /*
  * Print VRRP debugging configuration, human readable form.
index df21e7da9a8dc314fed1004d10bb9d9091a37768..d19f9adebc6589ed482547429719cd9f772c15b2 100644 (file)
@@ -416,17 +416,15 @@ DEFUN_NOSH (show_debugging_vrrp,
 
 /* 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);