]> git.puffer.fish Git - matthieu/frr.git/commitdiff
lib: enable multiple instance support with distribute lists
authorChristian Hopps <chopps@labn.net>
Mon, 22 Jan 2024 01:15:38 +0000 (01:15 +0000)
committerChristian Hopps <chopps@labn.net>
Mon, 22 Jan 2024 11:32:29 +0000 (11:32 +0000)
Signed-off-by: Christian Hopps <chopps@labn.net>
babeld/babeld.c
eigrpd/eigrp_routemap.c
lib/distribute.c
lib/distribute.h
ripd/rip_cli.c
ripngd/ripng_cli.c

index 41fac6251147683622151a2edd0b2afb4093e048..797d12478a9fb2f24cb6160f577d232683718c00 100644 (file)
@@ -710,7 +710,7 @@ DEFUN (babel_distribute_list,
        if (argv[argc - 1]->type == VARIABLE_TKN)
                ifname = argv[argc - 1]->arg;
 
-       return distribute_list_parser(prefix, true, argv[2 + prefix]->text,
+       return distribute_list_parser(NULL, prefix, true, argv[2 + prefix]->text,
                                      argv[1 + prefix]->arg, ifname);
 }
 
@@ -731,7 +731,7 @@ DEFUN (babel_no_distribute_list,
        if (argv[argc - 1]->type == VARIABLE_TKN)
                ifname = argv[argc - 1]->arg;
 
-       return distribute_list_no_parser(vty, prefix, true,
+       return distribute_list_no_parser(NULL, vty, prefix, true,
                                         argv[3 + prefix]->text,
                                         argv[2 + prefix]->arg, ifname);
 }
@@ -753,7 +753,8 @@ DEFUN (babel_ipv6_distribute_list,
        if (argv[argc - 1]->type == VARIABLE_TKN)
                ifname = argv[argc - 1]->arg;
 
-       return distribute_list_parser(prefix, false, argv[3 + prefix]->text,
+       return distribute_list_parser(NULL, prefix, false,
+                                     argv[3 + prefix]->text,
                                      argv[2 + prefix]->arg, ifname);
 }
 
@@ -775,7 +776,7 @@ DEFUN (babel_no_ipv6_distribute_list,
        if (argv[argc - 1]->type == VARIABLE_TKN)
                ifname = argv[argc - 1]->arg;
 
-       return distribute_list_no_parser(vty, prefix, false,
+       return distribute_list_no_parser(NULL, vty, prefix, false,
                                         argv[4 + prefix]->text,
                                         argv[3 + prefix]->arg, ifname);
 }
index 84f27d01677eaf33de045337bcfb92172061a80f..5a1634592f67b8d36f45743f6b183581aea61bbd 100644 (file)
@@ -1123,7 +1123,7 @@ DEFUN (eigrp_distribute_list,
        if (argv[argc - 1]->type == VARIABLE_TKN)
                ifname = argv[argc - 1]->arg;
 
-       return distribute_list_parser(prefix, true, argv[2 + prefix]->text,
+       return distribute_list_parser(NULL, prefix, true, argv[2 + prefix]->text,
                                      argv[1 + prefix]->arg, ifname);
 }
 
@@ -1144,14 +1144,14 @@ DEFUN (eigrp_no_distribute_list,
        if (argv[argc - 1]->type == VARIABLE_TKN)
                ifname = argv[argc - 1]->arg;
 
-       return distribute_list_no_parser(vty, prefix, true,
+       return distribute_list_no_parser(NULL, vty, prefix, true,
                                         argv[3 + prefix]->text,
                                         argv[2 + prefix]->arg, ifname);
 }
 
 
 /* Route-map init */
-void eigrp_route_map_init()
+void eigrp_route_map_init(void)
 {
        route_map_init();
        route_map_init_vty();
index 719bac4faaf84963d8c318b737ae9ef71a48cd7c..8d1fca9a9e4e6257af493768b76471db521ee823 100644 (file)
@@ -244,11 +244,13 @@ static enum distribute_type distribute_direction(const char *dir, bool v4)
        __builtin_unreachable();
 }
 
-int distribute_list_parser(bool prefix, bool v4, const char *dir,
-                          const char *list, const char *ifname)
+int distribute_list_parser(struct distribute_ctx *ctx, bool prefix, bool v4,
+                          const char *dir, const char *list, const char *ifname)
 {
        enum distribute_type type = distribute_direction(dir, v4);
-       struct distribute_ctx *ctx = listnode_head(dist_ctx_list);
+
+       if (!ctx)
+               ctx = listnode_head(dist_ctx_list);
 
        void (*distfn)(struct distribute_ctx *, const char *,
                       enum distribute_type, const char *) =
@@ -259,14 +261,17 @@ int distribute_list_parser(bool prefix, bool v4, const char *dir,
        return CMD_SUCCESS;
 }
 
-int distribute_list_no_parser(struct vty *vty, bool prefix, bool v4,
-                             const char *dir, const char *list,
-                             const char *ifname)
+
+int distribute_list_no_parser(struct distribute_ctx *ctx, struct vty *vty,
+                             bool prefix, bool v4, const char *dir,
+                             const char *list, const char *ifname)
 {
        enum distribute_type type = distribute_direction(dir, v4);
-       struct distribute_ctx *ctx = listnode_head(dist_ctx_list);
        int ret;
 
+       if (!ctx)
+               ctx = listnode_head(dist_ctx_list);
+
        int (*distfn)(struct distribute_ctx *, const char *,
                      enum distribute_type, const char *) =
                prefix ? &distribute_list_prefix_unset : &distribute_list_unset;
@@ -451,8 +456,7 @@ int config_write_distribute(struct vty *vty,
 int group_distribute_list_create_helper(
        struct nb_cb_create_args *args, struct distribute_ctx *ctx)
 {
-       /* The code currently doesn't require this as it uses a global */
-       /* nb_running_set_entry(args->dnode, ctx);                     */
+       nb_running_set_entry(args->dnode, ctx);
        return NB_OK;
 }
 
@@ -469,23 +473,23 @@ int group_distribute_list_destroy(struct nb_cb_destroy_args *args)
 static int distribute_list_leaf_update(const struct lyd_node *dnode,
                                       int ip_version, bool no)
 {
+       struct distribute_ctx *ctx;
        struct lyd_node *dir_node = lyd_parent(dnode);
        struct lyd_node_inner *list_node = dir_node->parent;
        struct lyd_node *intf_key = list_node->child;
        bool ipv4 = ip_version == 4 ? true : false;
        bool prefix;
 
-       /* The code currently doesn't require this as it uses a global */
-       /* ctx = nb_running_get_entry_non_rec(&list_node->node, NULL, false); */
+       ctx = nb_running_get_entry_non_rec(&list_node->node, NULL, false);
 
        prefix = dnode->schema->name[0] == 'p' ? true : false;
        if (no)
-               distribute_list_no_parser(NULL, prefix, ipv4,
+               distribute_list_no_parser(ctx, NULL, prefix, ipv4,
                                          dir_node->schema->name,
                                          lyd_get_value(dnode),
                                          lyd_get_value(intf_key));
        else
-               distribute_list_parser(prefix, ipv4,
+               distribute_list_parser(ctx, prefix, ipv4,
                                       dir_node->schema->name,
                                       lyd_get_value(dnode),
                                       lyd_get_value(intf_key));
index 6fe890c045bf7f8ade6cc6ff686b9062f18e18a5..a0bc34898252aef53e7def5f5695da8750097c7d 100644 (file)
@@ -70,9 +70,11 @@ extern enum filter_type distribute_apply_in(struct interface *,
 extern enum filter_type distribute_apply_out(struct interface *,
                                             struct prefix *);
 
-extern int distribute_list_parser(bool prefix, bool v4, const char *dir,
-                                 const char *list, const char *ifname);
-extern int distribute_list_no_parser(struct vty *vty, bool prefix, bool v4,
+extern int distribute_list_parser(struct distribute_ctx *ctx, bool prefix,
+                                 bool v4, const char *dir, const char *list,
+                                 const char *ifname);
+extern int distribute_list_no_parser(struct distribute_ctx *ctx,
+                                    struct vty *vty, bool prefix, bool v4,
                                     const char *dir, const char *list,
                                     const char *ifname);
 
index d545e692cb7e843cab68adee245cc3e1ce015da3..a4d306a4d25041695fed7ce41d516b612f7e89c4 100644 (file)
@@ -1144,7 +1144,7 @@ DEFUN (rip_distribute_list,
        if (argv[argc - 1]->type == VARIABLE_TKN)
                ifname = argv[argc - 1]->arg;
 
-       return distribute_list_parser(prefix, true, argv[2 + prefix]->text,
+       return distribute_list_parser(NULL, prefix, true, argv[2 + prefix]->text,
                                      argv[1 + prefix]->arg, ifname);
 }
 
@@ -1165,7 +1165,7 @@ DEFUN (rip_no_distribute_list,
        if (argv[argc - 1]->type == VARIABLE_TKN)
                ifname = argv[argc - 1]->arg;
 
-       return distribute_list_no_parser(vty, prefix, true,
+       return distribute_list_no_parser(NULL, vty, prefix, true,
                                         argv[3 + prefix]->text,
                                         argv[2 + prefix]->arg, ifname);
 }
index 88b9354d95897c087fcffbf0f4a20c18bb242901..c5ffefe96be9b706d869231e25050cd05bee5205 100644 (file)
@@ -533,7 +533,8 @@ DEFUN (ripng_ipv6_distribute_list,
        if (argv[argc - 1]->type == VARIABLE_TKN)
                ifname = argv[argc - 1]->arg;
 
-       return distribute_list_parser(prefix, false, argv[3 + prefix]->text,
+       return distribute_list_parser(NULL, prefix, false,
+                                     argv[3 + prefix]->text,
                                      argv[2 + prefix]->arg, ifname);
 }
 
@@ -555,7 +556,7 @@ DEFUN (ripng_no_ipv6_distribute_list,
        if (argv[argc - 1]->type == VARIABLE_TKN)
                ifname = argv[argc - 1]->arg;
 
-       return distribute_list_no_parser(vty, prefix, false,
+       return distribute_list_no_parser(NULL, vty, prefix, false,
                                         argv[4 + prefix]->text,
                                         argv[3 + prefix]->arg, ifname);
 }