summaryrefslogtreecommitdiffstats
path: root/vrrpd
diff options
context:
space:
mode:
authorQuentin Young <qlyoung@cumulusnetworks.com>2019-02-13 20:56:40 +0100
committerQuentin Young <qlyoung@cumulusnetworks.com>2019-05-17 02:27:08 +0200
commitf828842a69edee4f43e7ef2a298fdb9f7fe48df4 (patch)
treee78713c4bb44d97abbdaf7f2d88b1c4c0db2b965 /vrrpd
parentvrrpd: remove ifindex from hash key computation (diff)
downloadfrr-f828842a69edee4f43e7ef2a298fdb9f7fe48df4.tar.xz
frr-f828842a69edee4f43e7ef2a298fdb9f7fe48df4.zip
vrrpd: add support for configuration writing
Signed-off-by: Quentin Young <qlyoung@cumulusnetworks.com>
Diffstat (limited to 'vrrpd')
-rw-r--r--vrrpd/vrrp.c64
-rw-r--r--vrrpd/vrrp.h23
-rw-r--r--vrrpd/vrrp_debug.c2
-rw-r--r--vrrpd/vrrp_debug.h2
-rw-r--r--vrrpd/vrrp_vty.c12
5 files changed, 94 insertions, 9 deletions
diff --git a/vrrpd/vrrp.c b/vrrpd/vrrp.c
index 92caaeff3..658dc098a 100644
--- a/vrrpd/vrrp.c
+++ b/vrrpd/vrrp.c
@@ -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;
diff --git a/vrrpd/vrrp.h b/vrrpd/vrrp.h
index ed68b6a81..eabb23fe7 100644
--- a/vrrpd/vrrp.h
+++ b/vrrpd/vrrp.h
@@ -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
@@ -559,6 +560,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
*/
struct vrrp_vrouter *vrrp_lookup(struct interface *ifp, uint8_t vrid);
diff --git a/vrrpd/vrrp_debug.c b/vrrpd/vrrp_debug.c
index cea2bbff7..b841bca78 100644
--- a/vrrpd/vrrp_debug.c
+++ b/vrrpd/vrrp_debug.c
@@ -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);
}
diff --git a/vrrpd/vrrp_debug.h b/vrrpd/vrrp_debug.h
index c54b20e5b..20f993095 100644
--- a/vrrpd/vrrp_debug.h
+++ b/vrrpd/vrrp_debug.h
@@ -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.
diff --git a/vrrpd/vrrp_vty.c b/vrrpd/vrrp_vty.c
index df21e7da9..d19f9adeb 100644
--- a/vrrpd/vrrp_vty.c
+++ b/vrrpd/vrrp_vty.c
@@ -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);