summaryrefslogtreecommitdiffstats
path: root/vrrpd/vrrp_vty.c
diff options
context:
space:
mode:
Diffstat (limited to 'vrrpd/vrrp_vty.c')
-rw-r--r--vrrpd/vrrp_vty.c265
1 files changed, 123 insertions, 142 deletions
diff --git a/vrrpd/vrrp_vty.c b/vrrpd/vrrp_vty.c
index 239b02ee7..4ccccc43a 100644
--- a/vrrpd/vrrp_vty.c
+++ b/vrrpd/vrrp_vty.c
@@ -23,6 +23,7 @@
#include "lib/if.h"
#include "lib/ipaddr.h"
#include "lib/json.h"
+#include "lib/northbound_cli.h"
#include "lib/prefix.h"
#include "lib/termtable.h"
#include "lib/vty.h"
@@ -54,8 +55,13 @@
} \
} while (0)
+#define VRRP_XPATH_ENTRY VRRP_XPATH "[virtual-router-id='%ld']"
+
/* clang-format off */
+/*
+ * XPath: /frr-interface:lib/interface/frr-vrrpd:vrrp/vrrp-group
+ */
DEFPY(vrrp_vrid,
vrrp_vrid_cmd,
"[no] vrrp (1-255)$vrid [version (2-3)]",
@@ -65,27 +71,42 @@ DEFPY(vrrp_vrid,
VRRP_VERSION_STR
VRRP_VERSION_STR)
{
- VTY_DECLVAR_CONTEXT(interface, ifp);
+ char valbuf[8];
- struct vrrp_vrouter *vr = vrrp_lookup(ifp, vrid);
+ snprintf(valbuf, sizeof(valbuf), "%ld", version ? version : vd.version);
- if (version == 0)
- version = 3;
+ if (no)
+ nb_cli_enqueue_change(vty, ".", NB_OP_DESTROY, NULL);
+ else {
+ nb_cli_enqueue_change(vty, ".", NB_OP_CREATE, NULL);
+ nb_cli_enqueue_change(vty, "./version", NB_OP_MODIFY, valbuf);
+ }
- if (no && vr)
- vrrp_vrouter_destroy(vr);
- else if (no && !vr)
- vty_out(vty, "%% VRRP instance %ld does not exist on %s\n",
- vrid, ifp->name);
- else if (!vr)
- vrrp_vrouter_create(ifp, vrid, version);
- else if (vr)
- vty_out(vty, "%% VRRP instance %ld already exists on %s\n",
- vrid, ifp->name);
+ return nb_cli_apply_changes(vty, VRRP_XPATH_ENTRY, vrid);
+}
- return CMD_SUCCESS;
+void cli_show_vrrp(struct vty *vty, struct lyd_node *dnode, bool show_defaults)
+{
+ const char *vrid = yang_dnode_get_string(dnode, "./virtual-router-id");
+ const char *ver = yang_dnode_get_string(dnode, "./version");
+ const char *dver =
+ yang_get_default_string("%s/version", VRRP_XPATH_FULL);
+
+ char verstr[16] = {};
+
+ if (strmatch(dver, ver)) {
+ if (show_defaults)
+ snprintf(verstr, sizeof(verstr), "version %s", dver);
+ } else {
+ snprintf(verstr, sizeof(verstr), "version %s", ver);
+ }
+
+ vty_out(vty, " vrrp %s %s\n", vrid, verstr);
}
+/*
+ * XPath: /frr-interface:lib/interface/frr-vrrpd:vrrp/vrrp-group/shutdown
+ */
DEFPY(vrrp_shutdown,
vrrp_shutdown_cmd,
"[no] vrrp (1-255)$vrid shutdown",
@@ -94,26 +115,24 @@ DEFPY(vrrp_shutdown,
VRRP_VRID_STR
"Force VRRP router into administrative shutdown\n")
{
- VTY_DECLVAR_CONTEXT(interface, ifp);
-
- struct vrrp_vrouter *vr;
+ nb_cli_enqueue_change(vty, "./shutdown", NB_OP_MODIFY,
+ no ? "false" : "true");
- VROUTER_GET_VTY(vty, ifp, vrid, vr);
+ return nb_cli_apply_changes(vty, VRRP_XPATH_ENTRY, vrid);
+}
- if (!no) {
- if (vr->v4->fsm.state != VRRP_STATE_INITIALIZE)
- vrrp_event(vr->v4, VRRP_EVENT_SHUTDOWN);
- if (vr->v6->fsm.state != VRRP_STATE_INITIALIZE)
- vrrp_event(vr->v6, VRRP_EVENT_SHUTDOWN);
- vr->shutdown = true;
- } else {
- vr->shutdown = false;
- vrrp_check_start(vr);
- }
+void cli_show_shutdown(struct vty *vty, struct lyd_node *dnode,
+ bool show_defaults)
+{
+ const char *vrid = yang_dnode_get_string(dnode, "../virtual-router-id");
+ const bool shut = yang_dnode_get_bool(dnode, NULL);
- return CMD_SUCCESS;
+ vty_out(vty, " %svrrp %s shutdown\n", shut ? "" : "no ", vrid);
}
+/*
+ * XPath: /frr-interface:lib/interface/frr-vrrpd:vrrp/vrrp-group/priority
+ */
DEFPY(vrrp_priority,
vrrp_priority_cmd,
"[no] vrrp (1-255)$vrid priority (1-254)",
@@ -123,45 +142,60 @@ DEFPY(vrrp_priority,
VRRP_PRIORITY_STR
"Priority value")
{
- VTY_DECLVAR_CONTEXT(interface, ifp);
+ const char *val = no ? NULL : priority_str;
- struct vrrp_vrouter *vr;
- uint8_t newprio = no ? vd.priority : priority;
+ nb_cli_enqueue_change(vty, "./priority", NB_OP_MODIFY, val);
- VROUTER_GET_VTY(vty, ifp, vrid, vr);
+ return nb_cli_apply_changes(vty, VRRP_XPATH_ENTRY, vrid);
+}
- vrrp_set_priority(vr, newprio);
+void cli_show_priority(struct vty *vty, struct lyd_node *dnode,
+ bool show_defaults)
+{
+ const char *vrid = yang_dnode_get_string(dnode, "../virtual-router-id");
+ const char *prio = yang_dnode_get_string(dnode, NULL);
- return CMD_SUCCESS;
+ vty_out(vty, " vrrp %s priority %s\n", vrid, prio);
}
+/*
+ * XPath:
+ * /frr-interface:lib/interface/frr-vrrpd:vrrp/vrrp-group/advertisement-interval
+ */
DEFPY(vrrp_advertisement_interval,
vrrp_advertisement_interval_cmd,
"[no] vrrp (1-255)$vrid advertisement-interval (10-40950)",
NO_STR VRRP_STR VRRP_VRID_STR VRRP_ADVINT_STR
"Advertisement interval in milliseconds; must be multiple of 10")
{
- VTY_DECLVAR_CONTEXT(interface, ifp);
+ char valbuf[8];
+ const char *val;
- struct vrrp_vrouter *vr;
- uint16_t newadvint =
- no ? vd.advertisement_interval * CS2MS : advertisement_interval;
+ /* all internal computations are in centiseconds */
+ advertisement_interval /= CS2MS;
+ snprintf(valbuf, sizeof(valbuf), "%ld", advertisement_interval);
- if (newadvint % CS2MS != 0) {
- vty_out(vty, "%% Value must be a multiple of %u\n",
- (unsigned int)CS2MS);
- return CMD_WARNING_CONFIG_FAILED;
- }
+ val = no ? NULL : valbuf;
- /* all internal computations are in centiseconds */
- newadvint /= CS2MS;
+ nb_cli_enqueue_change(vty, "./advertisement-interval", NB_OP_MODIFY,
+ val);
- VROUTER_GET_VTY(vty, ifp, vrid, vr);
- vrrp_set_advertisement_interval(vr, newadvint);
+ return nb_cli_apply_changes(vty, VRRP_XPATH_ENTRY, vrid);
+}
- return CMD_SUCCESS;
+void cli_show_advertisement_interval(struct vty *vty, struct lyd_node *dnode,
+ bool show_defaults)
+{
+ const char *vrid = yang_dnode_get_string(dnode, "../virtual-router-id");
+ const char *advi = yang_dnode_get_string(dnode, NULL);
+
+ vty_out(vty, " vrrp %s advertisement-interval %s\n", vrid, advi);
}
+/*
+ * XPath:
+ * /frr-interface:lib/interface/frr-vrrpd:vrrp/vrrp-group/v4/virtual-address
+ */
DEFPY(vrrp_ip,
vrrp_ip_cmd,
"[no] vrrp (1-255)$vrid ip A.B.C.D",
@@ -171,51 +205,25 @@ DEFPY(vrrp_ip,
"Add IPv4 address\n"
VRRP_IP_STR)
{
- VTY_DECLVAR_CONTEXT(interface, ifp);
+ int op = no ? NB_OP_DESTROY : NB_OP_CREATE;
+ nb_cli_enqueue_change(vty, "./v4/virtual-address", op, ip_str);
- struct vrrp_vrouter *vr;
- bool deactivated = false;
- bool activated = false;
- bool failed = false;
- int ret = CMD_SUCCESS;
- int oldstate;
-
- VROUTER_GET_VTY(vty, ifp, vrid, vr);
-
- bool will_activate = (vr->v4->fsm.state == VRRP_STATE_INITIALIZE);
-
- if (no) {
- oldstate = vr->v4->fsm.state;
- failed = vrrp_del_ipv4(vr, ip);
- vrrp_check_start(vr);
- deactivated = (vr->v4->fsm.state == VRRP_STATE_INITIALIZE
- && oldstate != VRRP_STATE_INITIALIZE);
- } else {
- oldstate = vr->v4->fsm.state;
- failed = vrrp_add_ipv4(vr, ip);
- vrrp_check_start(vr);
- activated = (vr->v4->fsm.state != VRRP_STATE_INITIALIZE
- && oldstate == VRRP_STATE_INITIALIZE);
- }
+ return nb_cli_apply_changes(vty, VRRP_XPATH_ENTRY, vrid);
+}
- if (activated)
- vty_out(vty, "%% Activated IPv4 Virtual Router %ld\n", vrid);
- if (deactivated)
- vty_out(vty, "%% Deactivated IPv4 Virtual Router %ld\n", vrid);
- if (failed) {
- vty_out(vty, "%% Failed to %s virtual IP\n",
- no ? "remove" : "add");
- ret = CMD_WARNING_CONFIG_FAILED;
- if (will_activate && !activated) {
- vty_out(vty,
- "%% Failed to activate IPv4 Virtual Router %ld\n",
- vrid);
- }
- }
+void cli_show_ip(struct vty *vty, struct lyd_node *dnode, bool show_defaults)
+{
+ const char *vrid =
+ yang_dnode_get_string(dnode, "../../virtual-router-id");
+ const char *ipv4 = yang_dnode_get_string(dnode, NULL);
- return ret;
+ vty_out(vty, " vrrp %s ip %s\n", vrid, ipv4);
}
+/*
+ * XPath:
+ * /frr-interface:lib/interface/frr-vrrpd:vrrp/vrrp-group/v6/virtual-address
+ */
DEFPY(vrrp_ip6,
vrrp_ip6_cmd,
"[no] vrrp (1-255)$vrid ipv6 X:X::X:X",
@@ -225,57 +233,24 @@ DEFPY(vrrp_ip6,
"Add IPv6 address\n"
VRRP_IP_STR)
{
- VTY_DECLVAR_CONTEXT(interface, ifp);
-
- struct vrrp_vrouter *vr;
- bool deactivated = false;
- bool activated = false;
- bool failed = false;
- int ret = CMD_SUCCESS;
- int oldstate;
-
- VROUTER_GET_VTY(vty, ifp, vrid, vr);
-
- if (vr->version != 3) {
- vty_out(vty,
- "%% Cannot add IPv6 address to VRRPv2 virtual router\n");
- return CMD_WARNING_CONFIG_FAILED;
- }
+ int op = no ? NB_OP_DESTROY : NB_OP_CREATE;
+ nb_cli_enqueue_change(vty, "./v6/virtual-address", op, ipv6_str);
- bool will_activate = (vr->v6->fsm.state == VRRP_STATE_INITIALIZE);
-
- if (no) {
- oldstate = vr->v6->fsm.state;
- failed = vrrp_del_ipv6(vr, ipv6);
- vrrp_check_start(vr);
- deactivated = (vr->v6->fsm.state == VRRP_STATE_INITIALIZE
- && oldstate != VRRP_STATE_INITIALIZE);
- } else {
- oldstate = vr->v6->fsm.state;
- failed = vrrp_add_ipv6(vr, ipv6);
- vrrp_check_start(vr);
- activated = (vr->v6->fsm.state != VRRP_STATE_INITIALIZE
- && oldstate == VRRP_STATE_INITIALIZE);
- }
+ return nb_cli_apply_changes(vty, VRRP_XPATH_ENTRY, vrid);
+}
- if (activated)
- vty_out(vty, "%% Activated IPv6 Virtual Router %ld\n", vrid);
- if (deactivated)
- vty_out(vty, "%% Deactivated IPv6 Virtual Router %ld\n", vrid);
- if (failed) {
- vty_out(vty, "%% Failed to %s virtual IP\n",
- no ? "remove" : "add");
- ret = CMD_WARNING_CONFIG_FAILED;
- if (will_activate && !activated) {
- vty_out(vty,
- "%% Failed to activate IPv6 Virtual Router %ld\n",
- vrid);
- }
- }
+void cli_show_ipv6(struct vty *vty, struct lyd_node *dnode, bool show_defaults)
+{
+ const char *vrid =
+ yang_dnode_get_string(dnode, "../../virtual-router-id");
+ const char *ipv6 = yang_dnode_get_string(dnode, NULL);
- return ret;
+ vty_out(vty, " vrrp %s ipv6 %s\n", vrid, ipv6);
}
+/*
+ * XPath: /frr-interface:lib/interface/frr-vrrpd:vrrp/vrrp-group/preempt
+ */
DEFPY(vrrp_preempt,
vrrp_preempt_cmd,
"[no] vrrp (1-255)$vrid preempt",
@@ -284,17 +259,22 @@ DEFPY(vrrp_preempt,
VRRP_VRID_STR
"Preempt mode\n")
{
- VTY_DECLVAR_CONTEXT(interface, ifp);
-
- struct vrrp_vrouter *vr;
+ nb_cli_enqueue_change(vty, "./preempt", NB_OP_MODIFY,
+ no ? "false" : "true");
- VROUTER_GET_VTY(vty, ifp, vrid, vr);
+ return nb_cli_apply_changes(vty, VRRP_XPATH_ENTRY, vrid);
+}
- vr->preempt_mode = !no;
+void cli_show_preempt(struct vty *vty, struct lyd_node *dnode,
+ bool show_defaults)
+{
+ const char *vrid = yang_dnode_get_string(dnode, "../virtual-router-id");
+ const bool pre = yang_dnode_get_bool(dnode, NULL);
- return CMD_SUCCESS;
+ vty_out(vty, " %svrrp %s preempt\n", pre ? "" : "no ", vrid);
}
+/* XXX: yang conversion */
DEFPY(vrrp_autoconfigure,
vrrp_autoconfigure_cmd,
"[no] vrrp autoconfigure [version (2-3)]",
@@ -314,6 +294,7 @@ DEFPY(vrrp_autoconfigure,
return CMD_SUCCESS;
}
+/* XXX: yang conversion */
DEFPY(vrrp_default,
vrrp_default_cmd,
"[no] vrrp default <advertisement-interval$adv (10-40950)$advint|preempt$p|priority$prio (1-254)$prioval|shutdown$s>",