summaryrefslogtreecommitdiffstats
path: root/lib/distribute.c
diff options
context:
space:
mode:
authorChristian Hopps <chopps@labn.net>2024-01-21 14:12:39 +0100
committerChristian Hopps <chopps@labn.net>2024-01-22 12:32:29 +0100
commiteba64f79cc9090a1a706291442dc02597e359cac (patch)
treece1496abb764e47efaca16071a8e794aeb297b98 /lib/distribute.c
parentlib: cleanup yang lint warnings (diff)
downloadfrr-eba64f79cc9090a1a706291442dc02597e359cac.tar.xz
frr-eba64f79cc9090a1a706291442dc02597e359cac.zip
lib: add northbound support to distribute-list code.
Signed-off-by: Christian Hopps <chopps@labn.net>
Diffstat (limited to 'lib/distribute.c')
-rw-r--r--lib/distribute.c123
1 files changed, 122 insertions, 1 deletions
diff --git a/lib/distribute.c b/lib/distribute.c
index 65487676d..719bac4fa 100644
--- a/lib/distribute.c
+++ b/lib/distribute.c
@@ -274,7 +274,8 @@ int distribute_list_no_parser(struct vty *vty, bool prefix, bool v4,
ret = distfn(ctx, ifname, type, list);
if (!ret) {
- vty_out(vty, "distribute list doesn't exist\n");
+ if (vty)
+ vty_out(vty, "distribute list doesn't exist\n");
return CMD_WARNING_CONFIG_FAILED;
}
@@ -443,6 +444,126 @@ int config_write_distribute(struct vty *vty,
return write;
}
+/* ---------- */
+/* Northbound */
+/* ---------- */
+
+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); */
+ return NB_OK;
+}
+
+/*
+ * XPath: /frr-ripd:ripd/instance/distribute-lists/distribute-list/{in,out}/{access,prefix}-list
+ */
+
+int group_distribute_list_destroy(struct nb_cb_destroy_args *args)
+{
+ nb_running_unset_entry(args->dnode);
+ return NB_OK;
+}
+
+static int distribute_list_leaf_update(const struct lyd_node *dnode,
+ int ip_version, bool no)
+{
+ 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); */
+
+ prefix = dnode->schema->name[0] == 'p' ? true : false;
+ if (no)
+ distribute_list_no_parser(NULL, prefix, ipv4,
+ dir_node->schema->name,
+ lyd_get_value(dnode),
+ lyd_get_value(intf_key));
+ else
+ distribute_list_parser(prefix, ipv4,
+ dir_node->schema->name,
+ lyd_get_value(dnode),
+ lyd_get_value(intf_key));
+ return NB_OK;
+}
+
+static int distribute_list_leaf_modify(struct nb_cb_modify_args *args,
+ int ip_version)
+{
+ if (args->event != NB_EV_APPLY)
+ return NB_OK;
+ return distribute_list_leaf_update(args->dnode, ip_version, false);
+}
+
+static int distribute_list_leaf_destroy(struct nb_cb_destroy_args *args,
+ int ip_version)
+{
+ if (args->event != NB_EV_APPLY)
+ return NB_OK;
+ return distribute_list_leaf_update(args->dnode, ip_version, true);
+}
+
+int group_distribute_list_ipv4_modify(struct nb_cb_modify_args *args)
+{
+ return distribute_list_leaf_modify(args, 4);
+}
+int group_distribute_list_ipv4_destroy(struct nb_cb_destroy_args *args)
+{
+ return distribute_list_leaf_destroy(args, 4);
+}
+int group_distribute_list_ipv6_modify(struct nb_cb_modify_args *args)
+{
+ return distribute_list_leaf_modify(args, 6);
+}
+int group_distribute_list_ipv6_destroy(struct nb_cb_destroy_args *args)
+{
+ return distribute_list_leaf_destroy(args, 6);
+}
+
+static int distribute_list_leaf_cli_show(struct vty *vty,
+ const struct lyd_node *dnode,
+ int ip_version)
+{
+ 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 ipv6 = ip_version == 6 ? true : false;
+ bool prefix;
+
+ prefix = dnode->schema->name[0] == 'p' ? true : false;
+ vty_out(vty,
+ " %sdistribute-list %s%s %s %s\n",
+ ipv6 ? "ipv6 " : "",
+ prefix ? "prefix " : "",
+ lyd_get_value(dnode),
+ dir_node->schema->name,
+ lyd_get_value(intf_key));
+
+ return NB_OK;
+}
+
+void group_distribute_list_ipv4_cli_show(struct vty *vty,
+ const struct lyd_node *dnode,
+ bool show_defaults)
+{
+ distribute_list_leaf_cli_show(vty, dnode, 4);
+}
+void group_distribute_list_ipv6_cli_show(struct vty *vty,
+ const struct lyd_node *dnode,
+ bool show_defaults)
+{
+ distribute_list_leaf_cli_show(vty, dnode, 6);
+}
+
+/* ------------- */
+/* Setup/Cleanup */
+/* ------------- */
+
void distribute_list_delete(struct distribute_ctx **ctx)
{
hash_clean_and_free(&(*ctx)->disthash,