]> git.proxmox.com Git - mirror_frr.git/commitdiff
zebra: Allow router-id to be part of the vrf sub node
authorDonald Sharp <sharpd@cumulusnetworks.com>
Thu, 9 Jul 2020 15:57:22 +0000 (11:57 -0400)
committerDonald Sharp <sharpd@cumulusnetworks.com>
Thu, 9 Jul 2020 15:57:22 +0000 (11:57 -0400)
Modify zebra to accept router-id's as part of the
vrf subnode.

Signed-off-by: Donald Sharp <sharpd@cumulusnetworks.com>
zebra/main.c
zebra/router-id.c
zebra/router-id.h
zebra/zapi_msg.c
zebra/zebra_vrf.c
zebra/zebra_vty.c

index 71c7ebb62fbb3906fafdd317cb754ba1a263ac5b..c0921566edae32e9c07583800408cab6d537c044 100644 (file)
@@ -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();
index 710f2f6c2798c24b3b20a7d5f570d720712de85d..ba9e721614b3bc97b1227aa58e64de306e36da2a 100644 (file)
@@ -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);
 }
 
index f7d16853f18e90ffe7103a4a85ca07882f05f3ed..c69c321fdad0f4d41dc0a2df67448198ee06998f 100644 (file)
 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
 }
index a40aa8b64345cc5e921b0ffa629d1d8edef6b7c7..e3760ac8e4c1882f8c7361e8f1525ad18243b849 100644 (file)
@@ -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));
 }
index ee1e251a69900ce71778e368b56a6290e9ea927c..d102b02a21c8b2e2dd8868278ba0def3a485d0a8 100644 (file)
@@ -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");
index 9718b40d9da68ac660984a58a8ca954b07e08ed4..a3521a896906ed4c24d833518372e786f5632cb9 100644 (file)
@@ -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())