Skip to content

Commit

Permalink
Merge pull request #15194 from idryzhov/dist-list-fixes
Browse files Browse the repository at this point in the history
distribute-list fixes and improvements
  • Loading branch information
choppsv1 authored Jan 23, 2024
2 parents 22d1ad7 + 83a698d commit 296cda5
Show file tree
Hide file tree
Showing 9 changed files with 384 additions and 95 deletions.
73 changes: 60 additions & 13 deletions babeld/babeld.c
Original file line number Diff line number Diff line change
Expand Up @@ -696,9 +696,8 @@ DEFPY (babel_set_smoothing_half_life,

DEFUN (babel_distribute_list,
babel_distribute_list_cmd,
"distribute-list [prefix] ACCESSLIST4_NAME <in|out> [WORD]",
"distribute-list ACCESSLIST4_NAME <in|out> [WORD]",
"Filter networks in routing updates\n"
"Specify a prefix\n"
"Access-list name\n"
"Filter incoming routing updates\n"
"Filter outgoing routing updates\n"
Expand All @@ -710,16 +709,26 @@ DEFUN (babel_distribute_list,
if (argv[argc - 1]->type == VARIABLE_TKN)
ifname = argv[argc - 1]->arg;

return distribute_list_parser(NULL, prefix, true, argv[2 + prefix]->text,
return distribute_list_parser(babel_routing_process->distribute_ctx,
prefix, true, argv[2 + prefix]->text,
argv[1 + prefix]->arg, ifname);
}

ALIAS (babel_distribute_list,
babel_distribute_list_prefix_cmd,
"distribute-list prefix PREFIXLIST4_NAME <in|out> [WORD]",
"Filter networks in routing updates\n"
"Specify a prefix list\n"
"Prefix-list name\n"
"Filter incoming routing updates\n"
"Filter outgoing routing updates\n"
"Interface name\n")

DEFUN (babel_no_distribute_list,
babel_no_distribute_list_cmd,
"no distribute-list [prefix] ACCESSLIST4_NAME <in|out> [WORD]",
"no distribute-list ACCESSLIST4_NAME <in|out> [WORD]",
NO_STR
"Filter networks in routing updates\n"
"Specify a prefix\n"
"Access-list name\n"
"Filter incoming routing updates\n"
"Filter outgoing routing updates\n"
Expand All @@ -731,17 +740,28 @@ DEFUN (babel_no_distribute_list,
if (argv[argc - 1]->type == VARIABLE_TKN)
ifname = argv[argc - 1]->arg;

return distribute_list_no_parser(NULL, vty, prefix, true,
return distribute_list_no_parser(babel_routing_process->distribute_ctx,
vty, prefix, true,
argv[3 + prefix]->text,
argv[2 + prefix]->arg, ifname);
}

ALIAS (babel_no_distribute_list,
babel_no_distribute_list_prefix_cmd,
"no distribute-list prefix PREFIXLIST4_NAME <in|out> [WORD]",
NO_STR
"Filter networks in routing updates\n"
"Specify a prefix list\n"
"Prefix-list name\n"
"Filter incoming routing updates\n"
"Filter outgoing routing updates\n"
"Interface name\n")

DEFUN (babel_ipv6_distribute_list,
babel_ipv6_distribute_list_cmd,
"ipv6 distribute-list [prefix] ACCESSLIST6_NAME <in|out> [WORD]",
"ipv6 distribute-list ACCESSLIST6_NAME <in|out> [WORD]",
"IPv6\n"
"Filter networks in routing updates\n"
"Specify a prefix\n"
"Access-list name\n"
"Filter incoming routing updates\n"
"Filter outgoing routing updates\n"
Expand All @@ -753,18 +773,28 @@ DEFUN (babel_ipv6_distribute_list,
if (argv[argc - 1]->type == VARIABLE_TKN)
ifname = argv[argc - 1]->arg;

return distribute_list_parser(NULL, prefix, false,
argv[3 + prefix]->text,
return distribute_list_parser(babel_routing_process->distribute_ctx,
prefix, false, argv[3 + prefix]->text,
argv[2 + prefix]->arg, ifname);
}

ALIAS (babel_ipv6_distribute_list,
babel_ipv6_distribute_list_prefix_cmd,
"ipv6 distribute-list prefix PREFIXLIST6_NAME <in|out> [WORD]",
"IPv6\n"
"Filter networks in routing updates\n"
"Specify a prefix list\n"
"Prefix-list name\n"
"Filter incoming routing updates\n"
"Filter outgoing routing updates\n"
"Interface name\n")

DEFUN (babel_no_ipv6_distribute_list,
babel_no_ipv6_distribute_list_cmd,
"no ipv6 distribute-list [prefix] ACCESSLIST6_NAME <in|out> [WORD]",
"no ipv6 distribute-list ACCESSLIST6_NAME <in|out> [WORD]",
NO_STR
"IPv6\n"
"Filter networks in routing updates\n"
"Specify a prefix\n"
"Access-list name\n"
"Filter incoming routing updates\n"
"Filter outgoing routing updates\n"
Expand All @@ -776,11 +806,24 @@ DEFUN (babel_no_ipv6_distribute_list,
if (argv[argc - 1]->type == VARIABLE_TKN)
ifname = argv[argc - 1]->arg;

return distribute_list_no_parser(NULL, vty, prefix, false,
return distribute_list_no_parser(babel_routing_process->distribute_ctx,
vty, prefix, false,
argv[4 + prefix]->text,
argv[3 + prefix]->arg, ifname);
}

ALIAS (babel_no_ipv6_distribute_list,
babel_no_ipv6_distribute_list_prefix_cmd,
"no ipv6 distribute-list prefix PREFIXLIST6_NAME <in|out> [WORD]",
NO_STR
"IPv6\n"
"Filter networks in routing updates\n"
"Specify a prefix list\n"
"Prefix-list name\n"
"Filter incoming routing updates\n"
"Filter outgoing routing updates\n"
"Interface name\n")

void
babeld_quagga_init(void)
{
Expand All @@ -798,9 +841,13 @@ babeld_quagga_init(void)
install_element(BABEL_NODE, &babel_set_smoothing_half_life_cmd);

install_element(BABEL_NODE, &babel_distribute_list_cmd);
install_element(BABEL_NODE, &babel_distribute_list_prefix_cmd);
install_element(BABEL_NODE, &babel_no_distribute_list_cmd);
install_element(BABEL_NODE, &babel_no_distribute_list_prefix_cmd);
install_element(BABEL_NODE, &babel_ipv6_distribute_list_cmd);
install_element(BABEL_NODE, &babel_ipv6_distribute_list_prefix_cmd);
install_element(BABEL_NODE, &babel_no_ipv6_distribute_list_cmd);
install_element(BABEL_NODE, &babel_no_ipv6_distribute_list_prefix_cmd);

vrf_cmd_init(NULL);

Expand Down
115 changes: 115 additions & 0 deletions eigrpd/eigrp_cli.c
Original file line number Diff line number Diff line change
Expand Up @@ -401,6 +401,117 @@ void eigrp_cli_show_neighbor(struct vty *vty, const struct lyd_node *dnode,
vty_out(vty, " neighbor %s\n", prefix);
}

/*
* XPath: /frr-eigrpd:eigrpd/instance/distribute-list
*/
DEFPY_YANG (eigrp_distribute_list,
eigrp_distribute_list_cmd,
"distribute-list ACCESSLIST4_NAME$name <in|out>$dir [WORD$ifname]",
"Filter networks in routing updates\n"
"Access-list name\n"
"Filter incoming routing updates\n"
"Filter outgoing routing updates\n"
"Interface name\n")
{
char xpath[XPATH_MAXLEN];

snprintf(xpath, sizeof(xpath),
"./distribute-list[interface='%s']/%s/access-list",
ifname ? ifname : "", dir);
/* nb_cli_enqueue_change(vty, ".", NB_OP_CREATE, NULL); */
nb_cli_enqueue_change(vty, xpath, NB_OP_MODIFY, name);
return nb_cli_apply_changes(vty, NULL);
}

DEFPY_YANG (eigrp_distribute_list_prefix,
eigrp_distribute_list_prefix_cmd,
"distribute-list prefix PREFIXLIST4_NAME$name <in|out>$dir [WORD$ifname]",
"Filter networks in routing updates\n"
"Specify a prefix list\n"
"Prefix-list name\n"
"Filter incoming routing updates\n"
"Filter outgoing routing updates\n"
"Interface name\n")
{
char xpath[XPATH_MAXLEN];

snprintf(xpath, sizeof(xpath),
"./distribute-list[interface='%s']/%s/prefix-list",
ifname ? ifname : "", dir);
/* nb_cli_enqueue_change(vty, ".", NB_OP_CREATE, NULL); */
nb_cli_enqueue_change(vty, xpath, NB_OP_MODIFY, name);
return nb_cli_apply_changes(vty, NULL);
}

DEFPY_YANG (eigrp_no_distribute_list,
eigrp_no_distribute_list_cmd,
"no distribute-list [ACCESSLIST4_NAME$name] <in|out>$dir [WORD$ifname]",
NO_STR
"Filter networks in routing updates\n"
"Access-list name\n"
"Filter incoming routing updates\n"
"Filter outgoing routing updates\n"
"Interface name\n")
{
const struct lyd_node *value_node;
char xpath[XPATH_MAXLEN];

snprintf(xpath, sizeof(xpath),
"./distribute-list[interface='%s']/%s/access-list",
ifname ? ifname : "", dir);
/*
* See if the user has specified specific list so check it exists.
*
* NOTE: Other FRR CLI commands do not do this sort of verification and
* there may be an official decision not to.
*/
if (name) {
value_node = yang_dnode_getf(vty->candidate_config->dnode, "%s/%s",
VTY_CURR_XPATH, xpath);
if (!value_node || strcmp(name, lyd_get_value(value_node))) {
vty_out(vty, "distribute list doesn't exist\n");
return CMD_WARNING_CONFIG_FAILED;
}
}
nb_cli_enqueue_change(vty, xpath, NB_OP_DESTROY, NULL);
return nb_cli_apply_changes(vty, NULL);
}

DEFPY_YANG (eigrp_no_distribute_list_prefix,
eigrp_no_distribute_list_prefix_cmd,
"no distribute-list prefix [PREFIXLIST4_NAME$name] <in|out>$dir [WORD$ifname]",
NO_STR
"Filter networks in routing updates\n"
"Specify a prefix list\n"
"Prefix-list name\n"
"Filter incoming routing updates\n"
"Filter outgoing routing updates\n"
"Interface name\n")
{
const struct lyd_node *value_node;
char xpath[XPATH_MAXLEN];

snprintf(xpath, sizeof(xpath),
"./distribute-list[interface='%s']/%s/prefix-list",
ifname ? ifname : "", dir);
/*
* See if the user has specified specific list so check it exists.
*
* NOTE: Other FRR CLI commands do not do this sort of verification and
* there may be an official decision not to.
*/
if (name) {
value_node = yang_dnode_getf(vty->candidate_config->dnode, "%s/%s",
VTY_CURR_XPATH, xpath);
if (!value_node || strcmp(name, lyd_get_value(value_node))) {
vty_out(vty, "distribute list doesn't exist\n");
return CMD_WARNING_CONFIG_FAILED;
}
}
nb_cli_enqueue_change(vty, xpath, NB_OP_DESTROY, NULL);
return nb_cli_apply_changes(vty, NULL);
}

/*
* XPath: /frr-eigrpd:eigrpd/instance/redistribute
* XPath: /frr-eigrpd:eigrpd/instance/redistribute/route-map
Expand Down Expand Up @@ -875,6 +986,10 @@ eigrp_cli_init(void)
install_element(EIGRP_NODE, &no_eigrp_metric_weights_cmd);
install_element(EIGRP_NODE, &eigrp_network_cmd);
install_element(EIGRP_NODE, &eigrp_neighbor_cmd);
install_element(EIGRP_NODE, &eigrp_distribute_list_cmd);
install_element(EIGRP_NODE, &eigrp_distribute_list_prefix_cmd);
install_element(EIGRP_NODE, &eigrp_no_distribute_list_cmd);
install_element(EIGRP_NODE, &eigrp_no_distribute_list_prefix_cmd);
install_element(EIGRP_NODE, &eigrp_redistribute_source_metric_cmd);

vrf_cmd_init(NULL);
Expand Down
56 changes: 56 additions & 0 deletions eigrpd/eigrp_northbound.c
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
#include "lib/table.h"
#include "lib/vrf.h"
#include "lib/zclient.h"
#include "lib/distribute.h"

#include "eigrp_structs.h"
#include "eigrpd.h"
Expand Down Expand Up @@ -701,6 +702,22 @@ static int eigrpd_instance_neighbor_destroy(struct nb_cb_destroy_args *args)
return NB_OK;
}

/*
* XPath: /frr-eigrpd:eigrpd/instance/distribute-list
*/
static int eigrpd_instance_distribute_list_create(struct nb_cb_create_args *args)
{
struct eigrp *eigrp;

if (args->event != NB_EV_APPLY)
return NB_OK;

eigrp = nb_running_get_entry(args->dnode, NULL, true);
group_distribute_list_create_helper(args, eigrp->distribute_ctx);

return NB_OK;
}

/*
* XPath: /frr-eigrpd:eigrpd/instance/redistribute
*/
Expand Down Expand Up @@ -1402,6 +1419,45 @@ const struct frr_yang_module_info frr_eigrpd_info = {
.cli_show = eigrp_cli_show_neighbor,
}
},
{
.xpath = "/frr-eigrpd:eigrpd/instance/distribute-list",
.cbs = {
.create = eigrpd_instance_distribute_list_create,
.destroy = group_distribute_list_destroy,
}
},
{
.xpath = "/frr-eigrpd:eigrpd/instance/distribute-list/in/access-list",
.cbs = {
.modify = group_distribute_list_ipv4_modify,
.destroy = group_distribute_list_ipv4_destroy,
.cli_show = group_distribute_list_ipv4_cli_show,
}
},
{
.xpath = "/frr-eigrpd:eigrpd/instance/distribute-list/out/access-list",
.cbs = {
.modify = group_distribute_list_ipv4_modify,
.destroy = group_distribute_list_ipv4_destroy,
.cli_show = group_distribute_list_ipv4_cli_show,
}
},
{
.xpath = "/frr-eigrpd:eigrpd/instance/distribute-list/in/prefix-list",
.cbs = {
.modify = group_distribute_list_ipv4_modify,
.destroy = group_distribute_list_ipv4_destroy,
.cli_show = group_distribute_list_ipv4_cli_show,
}
},
{
.xpath = "/frr-eigrpd:eigrpd/instance/distribute-list/out/prefix-list",
.cbs = {
.modify = group_distribute_list_ipv4_modify,
.destroy = group_distribute_list_ipv4_destroy,
.cli_show = group_distribute_list_ipv4_cli_show,
}
},
{
.xpath = "/frr-eigrpd:eigrpd/instance/redistribute",
.cbs = {
Expand Down
Loading

0 comments on commit 296cda5

Please sign in to comment.