summaryrefslogtreecommitdiffstats
path: root/vrrpd
diff options
context:
space:
mode:
authorQuentin Young <qlyoung@cumulusnetworks.com>2019-02-25 22:43:36 +0100
committerQuentin Young <qlyoung@cumulusnetworks.com>2019-05-17 02:27:08 +0200
commit8cd1d2779da8c2188e91c518fcbc18740086e300 (patch)
tree63a01831962f42b85d3d8ffcf9742cd7d720ee48 /vrrpd
parentvrrpd: add statistics collection (diff)
downloadfrr-8cd1d2779da8c2188e91c518fcbc18740086e300.tar.xz
frr-8cd1d2779da8c2188e91c518fcbc18740086e300.zip
vrrpd: allow configuring global defaults
Allow configuring the following as global defaults: - Priority - Advertisement interval - Preempt mode - Administrative shutdown Signed-off-by: Quentin Young <qlyoung@cumulusnetworks.com>
Diffstat (limited to 'vrrpd')
-rw-r--r--vrrpd/vrrp.c63
-rw-r--r--vrrpd/vrrp.h20
-rw-r--r--vrrpd/vrrp_vty.c31
3 files changed, 96 insertions, 18 deletions
diff --git a/vrrpd/vrrp.c b/vrrpd/vrrp.c
index 89de0525d..06c3bbfd1 100644
--- a/vrrpd/vrrp.c
+++ b/vrrpd/vrrp.c
@@ -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");
diff --git a/vrrpd/vrrp.h b/vrrpd/vrrp.h
index 94cd1ca3f..4ea1a3737 100644
--- a/vrrpd/vrrp.h
+++ b/vrrpd/vrrp.h
@@ -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"
@@ -45,6 +43,24 @@
#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;
diff --git a/vrrpd/vrrp_vty.c b/vrrpd/vrrp_vty.c
index 426aac4cd..daf373d39 100644
--- a/vrrpd/vrrp_vty.c
+++ b/vrrpd/vrrp_vty.c
@@ -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);