summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDonald Sharp <sharpd@cumulusnetworks.com>2020-07-09 11:57:22 -0400
committerDonald Sharp <sharpd@cumulusnetworks.com>2020-07-09 11:57:22 -0400
commit03fba42ebb5947d43728ee5d0e07dbbba009c7cf (patch)
treef7271586fc6ab6fc7b6c1dc33567b92edbe4be02
parent4030687aab47da7ea11ff2420fdda016e0e7f9d5 (diff)
zebra: Allow router-id to be part of the vrf sub node
Modify zebra to accept router-id's as part of the vrf subnode. Signed-off-by: Donald Sharp <sharpd@cumulusnetworks.com>
-rw-r--r--zebra/main.c2
-rw-r--r--zebra/router-id.c121
-rw-r--r--zebra/router-id.h10
-rw-r--r--zebra/zapi_msg.c2
-rw-r--r--zebra/zebra_vrf.c1
-rw-r--r--zebra/zebra_vty.c3
6 files changed, 83 insertions, 56 deletions
diff --git a/zebra/main.c b/zebra/main.c
index 71c7ebb62f..c0921566ed 100644
--- a/zebra/main.c
+++ b/zebra/main.c
@@ -415,12 +415,12 @@ int main(int argc, char **argv)
rib_init();
zebra_if_init();
zebra_debug_init();
- router_id_cmd_init();
/*
* Initialize NS( and implicitly the VRF module), and make kernel
* routing socket. */
zebra_ns_init((const char *)vrf_default_name_configured);
+ router_id_cmd_init();
zebra_vty_init();
access_list_init();
prefix_list_init();
diff --git a/zebra/router-id.c b/zebra/router-id.c
index 710f2f6c27..ba9e721614 100644
--- a/zebra/router-id.c
+++ b/zebra/router-id.c
@@ -69,11 +69,10 @@ static int router_id_bad_address(struct connected *ifc)
return 0;
}
-void router_id_get(struct prefix *p, vrf_id_t vrf_id)
+void router_id_get(struct prefix *p, struct zebra_vrf *zvrf)
{
struct listnode *node;
struct connected *c;
- struct zebra_vrf *zvrf = vrf_info_get(vrf_id);
p->u.prefix4.s_addr = INADDR_ANY;
p->family = AF_INET;
@@ -92,27 +91,18 @@ void router_id_get(struct prefix *p, vrf_id_t vrf_id)
}
}
-static void router_id_set(struct prefix *p, vrf_id_t vrf_id)
+static void router_id_set(struct prefix *p, struct zebra_vrf *zvrf)
{
struct prefix p2;
struct listnode *node;
struct zserv *client;
- struct zebra_vrf *zvrf;
-
- if (p->u.prefix4.s_addr == 0) /* unset */
- {
- zvrf = vrf_info_lookup(vrf_id);
- if (!zvrf)
- return;
- } else /* set */
- zvrf = vrf_info_get(vrf_id);
zvrf->rid_user_assigned.u.prefix4.s_addr = p->u.prefix4.s_addr;
- router_id_get(&p2, vrf_id);
+ router_id_get(&p2, zvrf);
for (ALL_LIST_ELEMENTS_RO(zrouter.client_list, node, client))
- zsend_router_id_update(client, &p2, vrf_id);
+ zsend_router_id_update(client, &p2, zvrf->vrf->vrf_id);
}
void router_id_add_address(struct connected *ifc)
@@ -127,7 +117,7 @@ void router_id_add_address(struct connected *ifc)
if (router_id_bad_address(ifc))
return;
- router_id_get(&before, zvrf_id(zvrf));
+ router_id_get(&before, zvrf);
if (if_is_loopback(ifc->ifp))
l = zvrf->rid_lo_sorted_list;
@@ -137,7 +127,7 @@ void router_id_add_address(struct connected *ifc)
if (!router_id_find_node(l, ifc))
listnode_add_sort(l, ifc);
- router_id_get(&after, zvrf_id(zvrf));
+ router_id_get(&after, zvrf);
if (prefix_same(&before, &after))
return;
@@ -159,7 +149,7 @@ void router_id_del_address(struct connected *ifc)
if (router_id_bad_address(ifc))
return;
- router_id_get(&before, zvrf_id(zvrf));
+ router_id_get(&before, zvrf);
if (if_is_loopback(ifc->ifp))
l = zvrf->rid_lo_sorted_list;
@@ -169,7 +159,7 @@ void router_id_del_address(struct connected *ifc)
if ((c = router_id_find_node(l, ifc)))
listnode_delete(l, c);
- router_id_get(&after, zvrf_id(zvrf));
+ router_id_get(&after, zvrf);
if (prefix_same(&before, &after))
return;
@@ -178,38 +168,30 @@ void router_id_del_address(struct connected *ifc)
zsend_router_id_update(client, &after, zvrf_id(zvrf));
}
-void router_id_write(struct vty *vty)
+void router_id_write(struct vty *vty, struct zebra_vrf *zvrf)
{
- struct vrf *vrf;
- struct zebra_vrf *zvrf;
+ char space[2];
+
+ memset(space, 0, sizeof(space));
+
+ if (zvrf_id(zvrf) != VRF_DEFAULT)
+ snprintf(space, sizeof(space), "%s", " ");
- RB_FOREACH (vrf, vrf_name_head, &vrfs_by_name)
- if ((zvrf = vrf->info) != NULL)
- if (zvrf->rid_user_assigned.u.prefix4.s_addr
- != INADDR_ANY) {
- if (zvrf_id(zvrf) == VRF_DEFAULT)
- vty_out(vty, "router-id %s\n",
- inet_ntoa(
- zvrf->rid_user_assigned
- .u.prefix4));
- else
- vty_out(vty, "router-id %s vrf %s\n",
- inet_ntoa(
- zvrf->rid_user_assigned
- .u.prefix4),
- zvrf_name(zvrf));
- }
+ if (zvrf->rid_user_assigned.u.prefix4.s_addr != INADDR_ANY) {
+ vty_out(vty, "%srouter-id %s\n", space,
+ inet_ntoa(zvrf->rid_user_assigned.u.prefix4));
+ }
}
DEFUN (router_id,
router_id_cmd,
- "router-id A.B.C.D [vrf NAME]",
+ "router-id A.B.C.D vrf NAME",
"Manually set the router-id\n"
- "IP address to use for router-id\n"
- VRF_CMD_HELP_STR)
+ "IP address to use for router-id\n" VRF_CMD_HELP_STR)
{
int idx_ipv4 = 1;
int idx_name = 3;
+ struct zebra_vrf *zvrf;
struct prefix rid;
vrf_id_t vrf_id = VRF_DEFAULT;
@@ -224,23 +206,45 @@ DEFUN (router_id,
if (argc > 2)
VRF_GET_ID(vrf_id, argv[idx_name]->arg, false);
- router_id_set(&rid, vrf_id);
+ zvrf = vrf_info_lookup(vrf_id);
+ router_id_set(&rid, zvrf);
+
+ return CMD_SUCCESS;
+}
+
+DEFUN (router_id_in_vrf,
+ router_id_in_vrf_cmd,
+ "router-id A.B.C.D",
+ "Manuall set the router-id\n"
+ "IP address to use for router-id\n")
+{
+ ZEBRA_DECLVAR_CONTEXT(vrf, zvrf);
+ int idx_ipv4 = 1;
+ struct prefix rid;
+
+ rid.u.prefix4.s_addr = inet_addr(argv[idx_ipv4]->arg);
+ if (!rid.u.prefix4.s_addr)
+ return CMD_WARNING_CONFIG_FAILED;
+
+ rid.prefixlen = 32;
+ rid.family = AF_INET;
+
+ router_id_set(&rid, zvrf);
return CMD_SUCCESS;
}
DEFUN (no_router_id,
no_router_id_cmd,
- "no router-id [A.B.C.D [vrf NAME]]",
+ "no router-id [A.B.C.D vrf NAME]",
NO_STR
"Remove the manually configured router-id\n"
- "IP address to use for router-id\n"
- VRF_CMD_HELP_STR)
+ "IP address to use for router-id\n" VRF_CMD_HELP_STR)
{
int idx_name = 4;
-
struct prefix rid;
vrf_id_t vrf_id = VRF_DEFAULT;
+ struct zebra_vrf *zvrf;
rid.u.prefix4.s_addr = 0;
rid.prefixlen = 0;
@@ -249,7 +253,28 @@ DEFUN (no_router_id,
if (argc > 3)
VRF_GET_ID(vrf_id, argv[idx_name]->arg, false);
- router_id_set(&rid, vrf_id);
+ zvrf = vrf_info_get(vrf_id);
+ router_id_set(&rid, zvrf);
+
+ return CMD_SUCCESS;
+}
+
+DEFUN (no_router_id_in_vrf,
+ no_router_id_in_vrf_cmd,
+ "no router-id [A.B.C.D]",
+ NO_STR
+ "Remove the manually configured router-id\n"
+ "IP address to use for router-id\n")
+{
+ ZEBRA_DECLVAR_CONTEXT(vrf, zvrf);
+
+ struct prefix rid;
+
+ rid.u.prefix4.s_addr = 0;
+ rid.prefixlen = 0;
+ rid.family = AF_INET;
+
+ router_id_set(&rid, zvrf);
return CMD_SUCCESS;
}
@@ -298,6 +323,10 @@ void router_id_cmd_init(void)
{
install_element(CONFIG_NODE, &router_id_cmd);
install_element(CONFIG_NODE, &no_router_id_cmd);
+ install_element(CONFIG_NODE, &router_id_in_vrf_cmd);
+ install_element(VRF_NODE, &router_id_in_vrf_cmd);
+ install_element(CONFIG_NODE, &no_router_id_in_vrf_cmd);
+ install_element(VRF_NODE, &no_router_id_in_vrf_cmd);
install_element(VIEW_NODE, &show_router_id_cmd);
}
diff --git a/zebra/router-id.h b/zebra/router-id.h
index f7d16853f1..c69c321fda 100644
--- a/zebra/router-id.h
+++ b/zebra/router-id.h
@@ -34,12 +34,12 @@
extern "C" {
#endif
-extern void router_id_add_address(struct connected *);
-extern void router_id_del_address(struct connected *);
-extern void router_id_init(struct zebra_vrf *);
+extern void router_id_add_address(struct connected *c);
+extern void router_id_del_address(struct connected *c);
+extern void router_id_init(struct zebra_vrf *zvrf);
extern void router_id_cmd_init(void);
-extern void router_id_write(struct vty *);
-extern void router_id_get(struct prefix *, vrf_id_t);
+extern void router_id_write(struct vty *vty, struct zebra_vrf *zvrf);
+extern void router_id_get(struct prefix *p, struct zebra_vrf *zvrf);
#ifdef __cplusplus
}
diff --git a/zebra/zapi_msg.c b/zebra/zapi_msg.c
index a40aa8b643..e3760ac8e4 100644
--- a/zebra/zapi_msg.c
+++ b/zebra/zapi_msg.c
@@ -1879,7 +1879,7 @@ static void zread_router_id_add(ZAPI_HANDLER_ARGS)
/* Router-id information is needed. */
vrf_bitmap_set(client->ridinfo, zvrf_id(zvrf));
- router_id_get(&p, zvrf_id(zvrf));
+ router_id_get(&p, zvrf);
zsend_router_id_update(client, &p, zvrf_id(zvrf));
}
diff --git a/zebra/zebra_vrf.c b/zebra/zebra_vrf.c
index ee1e251a69..d102b02a21 100644
--- a/zebra/zebra_vrf.c
+++ b/zebra/zebra_vrf.c
@@ -544,6 +544,7 @@ static int vrf_config_write(struct vty *vty)
zebra_routemap_config_write_protocol(vty, zvrf);
+ router_id_write(vty, zvrf);
if (zvrf_id(zvrf) != VRF_DEFAULT)
vty_endframe(vty, " exit-vrf\n!\n");
diff --git a/zebra/zebra_vty.c b/zebra/zebra_vty.c
index 9718b40d9d..a3521a8969 100644
--- a/zebra/zebra_vty.c
+++ b/zebra/zebra_vty.c
@@ -3425,9 +3425,6 @@ static int config_write_table(struct vty *vty)
/* IPForwarding configuration write function. */
static int config_write_forwarding(struct vty *vty)
{
- /* FIXME: Find better place for that. */
- router_id_write(vty);
-
if (!ipforward())
vty_out(vty, "no ip forwarding\n");
if (!ipforward_ipv6())