Skip to content

Commit

Permalink
ripd: use new distribute-list northbound code.
Browse files Browse the repository at this point in the history
Signed-off-by: Christian Hopps <[email protected]>
  • Loading branch information
choppsv1 committed Jan 22, 2024
1 parent a993b8e commit 8f7a935
Show file tree
Hide file tree
Showing 6 changed files with 118 additions and 41 deletions.
85 changes: 49 additions & 36 deletions ripd/rip_cli.c
Original file line number Diff line number Diff line change
Expand Up @@ -1128,46 +1128,59 @@ DEFPY_YANG (clear_ip_rip,
return ret;
}

DEFUN (rip_distribute_list,
rip_distribute_list_cmd,
"distribute-list [prefix] 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"
"Interface name\n")
DEFPY_YANG(
rip_distribute_list, rip_distribute_list_cmd,
"distribute-list [prefix]$prefix ACCESSLIST4_NAME$name <in|out>$dir [WORD$ifname]",
"Filter networks in routing updates\n"
"Specify a prefix list\n"
"access-list or prefix-list name\n"
"Filter incoming routing updates\n"
"Filter outgoing routing updates\n"
"Interface name\n")
{
const char *ifname = NULL;
int prefix = (argv[1]->type == WORD_TKN) ? 1 : 0;

if (argv[argc - 1]->type == VARIABLE_TKN)
ifname = argv[argc - 1]->arg;
char xpath[XPATH_MAXLEN];

return distribute_list_parser(NULL, prefix, true, argv[2 + prefix]->text,
argv[1 + prefix]->arg, ifname);
snprintf(xpath, sizeof(xpath),
"./distribute-list[interface='%s']/%s/%s-list",
ifname ? ifname : "", dir, prefix ? "prefix" : "access");
/* 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);
}

DEFUN (rip_no_distribute_list,
rip_no_distribute_list_cmd,
"no distribute-list [prefix] 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"
"Interface name\n")
{
const char *ifname = NULL;
int prefix = (argv[2]->type == WORD_TKN) ? 1 : 0;

if (argv[argc - 1]->type == VARIABLE_TKN)
ifname = argv[argc - 1]->arg;
DEFPY_YANG(no_rip_distribute_list,
no_rip_distribute_list_cmd,
"no distribute-list [prefix]$prefix [ACCESSLIST4_NAME$name] <in|out>$dir [WORD$ifname]",
NO_STR
"Filter networks in routing updates\n"
"Specify a prefix list\n"
"access-list or 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];

return distribute_list_no_parser(NULL, vty, prefix, true,
argv[3 + prefix]->text,
argv[2 + prefix]->arg, ifname);
snprintf(xpath, sizeof(xpath),
"./distribute-list[interface='%s']/%s/%s-list",
ifname ? ifname : "", dir, prefix ? "prefix" : "access");
/*
* 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);
}

void rip_cli_init(void)
Expand All @@ -1176,7 +1189,7 @@ void rip_cli_init(void)
install_element(CONFIG_NODE, &no_router_rip_cmd);

install_element(RIP_NODE, &rip_distribute_list_cmd);
install_element(RIP_NODE, &rip_no_distribute_list_cmd);
install_element(RIP_NODE, &no_rip_distribute_list_cmd);

install_element(RIP_NODE, &rip_allow_ecmp_cmd);
install_element(RIP_NODE, &no_rip_allow_ecmp_cmd);
Expand Down
44 changes: 42 additions & 2 deletions ripd/rip_nb.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,12 @@

#include <zebra.h>

#include "northbound.h"
#include "distribute.h"
#include "if_rmap.h"
#include "libfrr.h"
#include "northbound.h"

#include "ripd/rip_nb.h"
#include "lib/if_rmap.h"

/* clang-format off */
const struct frr_yang_module_info frr_ripd_info = {
Expand Down Expand Up @@ -143,6 +144,45 @@ const struct frr_yang_module_info frr_ripd_info = {
.destroy = ripd_instance_non_passive_interface_destroy,
},
},
{
.xpath = "/frr-ripd:ripd/instance/distribute-list",
.cbs = {
.create = ripd_instance_distribute_list_create,
.destroy = group_distribute_list_destroy,
}
},
{
.xpath = "/frr-ripd:ripd/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-ripd:ripd/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-ripd:ripd/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-ripd:ripd/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-ripd:ripd/instance/redistribute",
.cbs = {
Expand Down
4 changes: 4 additions & 0 deletions ripd/rip_nb.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
#ifndef _FRR_RIP_NB_H_
#define _FRR_RIP_NB_H_

#include "northbound.h"

extern const struct frr_yang_module_info frr_ripd_info;

/* Mandatory callbacks. */
Expand Down Expand Up @@ -45,6 +47,8 @@ int ripd_instance_passive_interface_destroy(struct nb_cb_destroy_args *args);
int ripd_instance_non_passive_interface_create(struct nb_cb_create_args *args);
int ripd_instance_non_passive_interface_destroy(
struct nb_cb_destroy_args *args);
int ripd_instance_distribute_list_create(struct nb_cb_create_args *args);
int ripd_instance_distribute_list_destroy(struct nb_cb_destroy_args *args);
int ripd_instance_redistribute_create(struct nb_cb_create_args *args);
int ripd_instance_redistribute_destroy(struct nb_cb_destroy_args *args);
int ripd_instance_redistribute_route_map_modify(struct nb_cb_modify_args *args);
Expand Down
17 changes: 17 additions & 0 deletions ripd/rip_nb_config.c
Original file line number Diff line number Diff line change
Expand Up @@ -548,6 +548,23 @@ int ripd_instance_non_passive_interface_destroy(struct nb_cb_destroy_args *args)
return rip_passive_nondefault_unset(rip, ifname);
}


/*
* XPath: /frr-ripd:ripd/instance/distribute-list
*/
int ripd_instance_distribute_list_create(struct nb_cb_create_args *args)
{
struct rip *rip;

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

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

return NB_OK;
}

/*
* XPath: /frr-ripd:ripd/instance/redistribute
*/
Expand Down
3 changes: 0 additions & 3 deletions ripd/ripd.c
Original file line number Diff line number Diff line change
Expand Up @@ -3271,9 +3271,6 @@ static int config_write_rip(struct vty *vty)

nb_cli_show_dnode_cmds(vty, dnode, false);

/* Distribute configuration. */
config_write_distribute(vty, rip->distribute_ctx);

vty_out(vty, "exit\n");

write = 1;
Expand Down
6 changes: 6 additions & 0 deletions yang/frr-ripd.yang
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ module frr-ripd {
import frr-bfdd {
prefix frr-bfdd;
}
import frr-filter {
prefix frr-filter;
}
import frr-interface {
prefix frr-interface;
}
Expand Down Expand Up @@ -258,6 +261,9 @@ module frr-ripd {
"A list of interfaces where the sending of RIP packets
is enabled.";
}

uses frr-filter:distribute-list-group;

list redistribute {
key "protocol";
description
Expand Down

0 comments on commit 8f7a935

Please sign in to comment.