]> git.puffer.fish Git - matthieu/frr.git/commitdiff
vrrpd: allow configuring global defaults
authorQuentin Young <qlyoung@cumulusnetworks.com>
Mon, 25 Feb 2019 21:43:36 +0000 (21:43 +0000)
committerQuentin Young <qlyoung@cumulusnetworks.com>
Fri, 17 May 2019 00:27:08 +0000 (00:27 +0000)
Allow configuring the following as global defaults:

- Priority
- Advertisement interval
- Preempt mode
- Administrative shutdown

Signed-off-by: Quentin Young <qlyoung@cumulusnetworks.com>
vrrpd/vrrp.c
vrrpd/vrrp.h
vrrpd/vrrp_vty.c

index 89de0525dc8c74576abde63e7b2bbfd12d262105..06c3bbfd10750d371a39b832867283bb0ef23883 100644 (file)
@@ -46,6 +46,8 @@ struct hash *vrrp_vrouters_hash;
 bool vrrp_autoconfig_is_on;
 int vrrp_autoconfig_version;
 
+struct vrrp_defaults vd;
+
 const char *vrrp_state_names[3] = {
        [VRRP_STATE_INITIALIZE] = "Initialize",
        [VRRP_STATE_MASTER] = "Master",
@@ -531,14 +533,15 @@ struct vrrp_vrouter *vrrp_vrouter_create(struct interface *ifp, uint8_t vrid,
        vr->ifp = ifp;
        vr->version = version;
        vr->vrid = vrid;
-       vr->priority = VRRP_DEFAULT_PRIORITY;
-       vr->preempt_mode = true;
-       vr->accept_mode = true;
+       vr->priority = vd.priority;
+       vr->preempt_mode = vd.preempt_mode;
+       vr->accept_mode = vd.accept_mode;
+       vr->shutdown = vd.shutdown;
 
        vr->v4 = vrrp_router_create(vr, AF_INET);
        vr->v6 = vrrp_router_create(vr, AF_INET6);
 
-       vrrp_set_advertisement_interval(vr, VRRP_DEFAULT_ADVINT);
+       vrrp_set_advertisement_interval(vr, vd.advertisement_interval);
 
        hash_get(vrrp_vrouters_hash, vr, hash_alloc_intern);
 
@@ -2009,23 +2012,26 @@ int vrrp_config_write_interface(struct vty *vty)
                        vr->version == 2 ? " version 2" : "");
                ++writes;
 
-               if (vr->shutdown && ++writes)
-                       vty_out(vty, " vrrp %" PRIu8 " shutdown\n", vr->vrid);
+               if (vr->shutdown != vd.shutdown && ++writes)
+                       vty_out(vty, " %svrrp %" PRIu8 " shutdown\n",
+                               vr->shutdown ? "" : "no ", vr->vrid);
 
-               if (!vr->preempt_mode && ++writes)
-                       vty_out(vty, " no vrrp %" PRIu8 " preempt\n", vr->vrid);
+               if (vr->preempt_mode != vd.preempt_mode && ++writes)
+                       vty_out(vty, " %svrrp %" PRIu8 " preempt\n",
+                               vr->preempt_mode ? "" : "no ", vr->vrid);
 
-               if (vr->accept_mode && ++writes)
-                       vty_out(vty, " vrrp %" PRIu8 " accept\n", vr->vrid);
+               if (vr->accept_mode != vd.accept_mode && ++writes)
+                       vty_out(vty, " %svrrp %" PRIu8 " accept\n",
+                               vr->accept_mode ? "" : "no ", vr->vrid);
 
-               if (vr->advertisement_interval != VRRP_DEFAULT_ADVINT
+               if (vr->advertisement_interval != vd.advertisement_interval
                    && ++writes)
                        vty_out(vty,
                                " vrrp %" PRIu8
                                " advertisement-interval %" PRIu16 "\n",
                                vr->vrid, vr->advertisement_interval);
 
-               if (vr->priority != VRRP_DEFAULT_PRIORITY && ++writes)
+               if (vr->priority != vd.priority && ++writes)
                        vty_out(vty, " vrrp %" PRIu8 " priority %" PRIu8 "\n",
                                vr->vrid, vr->priority);
 
@@ -2053,11 +2059,33 @@ int vrrp_config_write_interface(struct vty *vty)
 
 int vrrp_config_write_global(struct vty *vty)
 {
-       if (vrrp_autoconfig_is_on)
+       unsigned int writes = 0;
+
+       if (vrrp_autoconfig_is_on && ++writes)
                vty_out(vty, "vrrp autoconfigure%s\n",
                        vrrp_autoconfig_version == 2 ? " version 2" : "");
 
-       return 1;
+       if (vd.priority != VRRP_DEFAULT_PRIORITY && ++writes)
+               vty_out(vty, "vrrp default priority %" PRIu8 "\n", vd.priority);
+
+       if (vd.advertisement_interval != VRRP_DEFAULT_ADVINT && ++writes)
+               vty_out(vty,
+                       "vrrp default advertisement-interval %" PRIu16 "\n",
+                       vd.advertisement_interval);
+
+       if (vd.preempt_mode != VRRP_DEFAULT_PREEMPT && ++writes)
+               vty_out(vty, "%svrrp default preempt\n",
+                       !vd.preempt_mode ? "no " : "");
+
+       if (vd.accept_mode != VRRP_DEFAULT_ACCEPT && ++writes)
+               vty_out(vty, "%svrrp default accept\n",
+                       !vd.accept_mode ? "no " : "");
+
+       if (vd.shutdown != VRRP_DEFAULT_SHUTDOWN && ++writes)
+               vty_out(vty, "%svrrp default shutdown\n",
+                       !vd.shutdown ? "no " : "");
+
+       return writes;
 }
 
 static unsigned int vrrp_hash_key(void *arg)
@@ -2085,6 +2113,13 @@ static bool vrrp_hash_cmp(const void *arg1, const void *arg2)
 
 void vrrp_init(void)
 {
+       /* Set default defaults */
+       vd.priority = VRRP_DEFAULT_PRIORITY;
+       vd.advertisement_interval = VRRP_DEFAULT_ADVINT;
+       vd.preempt_mode = VRRP_DEFAULT_PREEMPT;
+       vd.accept_mode = VRRP_DEFAULT_ACCEPT;
+       vd.shutdown = VRRP_DEFAULT_SHUTDOWN;
+
        vrrp_autoconfig_version = 3;
        vrrp_vrouters_hash = hash_create(&vrrp_hash_key, vrrp_hash_cmp,
                                         "VRRP virtual router hash");
index 94cd1ca3f60a1837f0954a3d0227b37c247a1da5..4ea1a3737769a1cff7e498d6605598d2e2889be3 100644 (file)
@@ -33,8 +33,6 @@
 #include "lib/vty.h"
 
 /* Global definitions */
-#define VRRP_DEFAULT_ADVINT 100
-#define VRRP_DEFAULT_PRIORITY 100
 #define VRRP_RADV_INT 16
 #define VRRP_PRIO_MASTER 255
 #define VRRP_MCASTV4_GROUP_STR "224.0.0.18"
 
 #define VRRP_LOGPFX_VRID "[VRID: %u] "
 
+/* Default defaults */
+#define VRRP_DEFAULT_PRIORITY 100
+#define VRRP_DEFAULT_ADVINT 100
+#define VRRP_DEFAULT_PREEMPT true
+#define VRRP_DEFAULT_ACCEPT true
+#define VRRP_DEFAULT_SHUTDOWN false
+
+/* Configured defaults */
+struct vrrp_defaults {
+       uint8_t priority;
+       uint16_t advertisement_interval;
+       bool preempt_mode;
+       bool accept_mode;
+       bool shutdown;
+};
+
+extern struct vrrp_defaults vd;
+
 /* threadmaster */
 extern struct thread_master *master;
 
index 426aac4cd2c42f15f026414fe1522f0a056d797d..daf373d3947f2ee4c79b932d4fd99d77b13749b0 100644 (file)
@@ -126,7 +126,7 @@ DEFPY(vrrp_priority,
        VTY_DECLVAR_CONTEXT(interface, ifp);
 
        struct vrrp_vrouter *vr;
-       uint8_t newprio = no ? VRRP_DEFAULT_PRIORITY : priority;
+       uint8_t newprio = no ? vd.priority : priority;
 
        VROUTER_GET_VTY(vty, ifp, vrid, vr);
 
@@ -144,7 +144,8 @@ DEFPY(vrrp_advertisement_interval,
        VTY_DECLVAR_CONTEXT(interface, ifp);
 
        struct vrrp_vrouter *vr;
-       uint16_t newadvint = no ? VRRP_DEFAULT_ADVINT : advertisement_interval;
+       uint16_t newadvint = no ? vd.advertisement_interval :
+                                 advertisement_interval;
 
        VROUTER_GET_VTY(vty, ifp, vrid, vr);
        vrrp_set_advertisement_interval(vr, newadvint);
@@ -300,6 +301,31 @@ DEFPY(vrrp_autoconfigure,
        return CMD_SUCCESS;
 }
 
+DEFPY(vrrp_default,
+      vrrp_default_cmd,
+      "[no] vrrp default <advertisement-interval$adv (1-4096)$advint|preempt$p|priority$prio (1-254)$prioval|shutdown$s>",
+      NO_STR
+      VRRP_STR
+      "Configure defaults for new VRRP instances\n"
+      VRRP_ADVINT_STR
+      "Advertisement interval in centiseconds\n"
+      "Preempt mode\n"
+      VRRP_PRIORITY_STR
+      "Priority value\n"
+      "Force VRRP router into administrative shutdown\n")
+{
+       if (adv)
+               vd.advertisement_interval = no ? VRRP_DEFAULT_ADVINT : advint;
+       if (p)
+               vd.preempt_mode = !no;
+       if (prio)
+               vd.priority = no ? VRRP_DEFAULT_PRIORITY : prioval;
+       if (s)
+               vd.shutdown = !no;
+
+       return CMD_SUCCESS;
+}
+
 /* clang-format on */
 
 /*
@@ -606,6 +632,7 @@ void vrrp_vty_init(void)
        install_element(VIEW_NODE, &debug_vrrp_cmd);
        install_element(CONFIG_NODE, &debug_vrrp_cmd);
        install_element(CONFIG_NODE, &vrrp_autoconfigure_cmd);
+       install_element(CONFIG_NODE, &vrrp_default_cmd);
        install_element(INTERFACE_NODE, &vrrp_vrid_cmd);
        install_element(INTERFACE_NODE, &vrrp_shutdown_cmd);
        install_element(INTERFACE_NODE, &vrrp_priority_cmd);