From: Quentin Young Date: Wed, 13 Feb 2019 19:56:40 +0000 (+0000) Subject: vrrpd: add support for configuration writing X-Git-Tag: base_7.2~330^2~84 X-Git-Url: https://git.puffer.fish/?a=commitdiff_plain;h=f828842a69edee4f43e7ef2a298fdb9f7fe48df4;p=matthieu%2Ffrr.git vrrpd: add support for configuration writing Signed-off-by: Quentin Young --- diff --git a/lib/command.c b/lib/command.c index b7a323e358..73bb9580cd 100644 --- a/lib/command.c +++ b/lib/command.c @@ -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 */ diff --git a/lib/command.h b/lib/command.h index a5f9616dbf..d96ec97e67 100644 --- a/lib/command.h +++ b/lib/command.h @@ -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 */ }; diff --git a/vrrpd/vrrp.c b/vrrpd/vrrp.c index 92caaeff3b..658dc098a2 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 ed68b6a812..eabb23fe75 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 @@ -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 */ diff --git a/vrrpd/vrrp_debug.c b/vrrpd/vrrp_debug.c index cea2bbff79..b841bca78a 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 c54b20e5b8..20f9930955 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 df21e7da9a..d19f9adebc 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);