zebra: convert table range command to NB

Signed-off-by: Igor Ryzhov <iryzhov@nfware.com>
This commit is contained in:
Igor Ryzhov 2024-01-27 05:00:27 +02:00
parent 2117faf1cf
commit 86855aed78
7 changed files with 211 additions and 73 deletions

View File

@ -2824,6 +2824,31 @@ module frr-zebra {
Removing the leaf sets it back to the default value for the profile.";
}
container netns {
description
"Configuration for netns VRF backend.";
container table-range {
presence "Activates table-range configuration.";
description
"The range of tables to use for this netns.";
leaf start {
type uint32;
mandatory true;
description
"The first table to use.";
}
leaf end {
type uint32;
mandatory true;
must ". >= ../start" {
error-message "End table must be greater than or equal to start table";
}
description
"The last table to use.";
}
}
}
uses ribs;
uses vrf-vni-mapping;

View File

@ -24,21 +24,6 @@
#include "zebra/table_manager.h"
#include "zebra/zebra_errors.h"
/* routing table identifiers
*
*/
#if !defined(GNU_LINUX)
/* BSD systems
*/
#else
/* Linux Systems
*/
#define RT_TABLE_ID_LOCAL 255
#define RT_TABLE_ID_MAIN 254
#define RT_TABLE_ID_DEFAULT 253
#define RT_TABLE_ID_COMPAT 252
#define RT_TABLE_ID_UNSPEC 0
#endif /* !def(GNU_LINUX) */
#define RT_TABLE_ID_UNRESERVED_MIN 1
#define RT_TABLE_ID_UNRESERVED_MAX 0xffffffff
@ -279,52 +264,17 @@ void table_manager_disable(struct zebra_vrf *zvrf)
zvrf->tbl_mgr = NULL;
}
int table_manager_range(struct vty *vty, bool add, struct zebra_vrf *zvrf,
const char *start_table_str, const char *end_table_str)
void table_manager_range(bool add, struct zebra_vrf *zvrf, uint32_t start,
uint32_t end)
{
uint32_t start;
uint32_t end;
if (add) {
if (!start_table_str || !end_table_str) {
vty_out(vty, "%% Labels not specified\n");
return CMD_WARNING_CONFIG_FAILED;
}
start = atoi(start_table_str);
end = atoi(end_table_str);
if (end < start) {
vty_out(vty, "%% End table is less than Start table\n");
return CMD_WARNING_CONFIG_FAILED;
}
if (zvrf->tbl_mgr &&
((zvrf->tbl_mgr->start && zvrf->tbl_mgr->start != start) ||
(zvrf->tbl_mgr->end && zvrf->tbl_mgr->end != end)))
zlog_info(
"%% New range will be taken into account at restart");
#if !defined(GNU_LINUX)
/* BSD systems
*/
#else
/* Linux Systems
*/
if ((start >= RT_TABLE_ID_COMPAT && start <= RT_TABLE_ID_LOCAL)
|| (end >= RT_TABLE_ID_COMPAT
&& end <= RT_TABLE_ID_LOCAL)) {
vty_out(vty, "%% Values forbidden in range [%u;%u]\n",
RT_TABLE_ID_COMPAT, RT_TABLE_ID_LOCAL);
return CMD_WARNING_CONFIG_FAILED;
}
if (start < RT_TABLE_ID_COMPAT && end > RT_TABLE_ID_LOCAL) {
vty_out(vty,
"%% Range overlaps range [%u;%u] forbidden\n",
RT_TABLE_ID_COMPAT, RT_TABLE_ID_LOCAL);
return CMD_WARNING_CONFIG_FAILED;
}
#endif
if (zvrf->tbl_mgr
&& ((zvrf->tbl_mgr->start && zvrf->tbl_mgr->start != start)
|| (zvrf->tbl_mgr->end && zvrf->tbl_mgr->end != end))) {
vty_out(vty,
"%% New range will be taken into account at restart\n");
}
table_range_add(zvrf, start, end);
} else
table_range_add(zvrf, 0, 0);
return CMD_SUCCESS;
}

View File

@ -18,6 +18,22 @@
extern "C" {
#endif
/* routing table identifiers
*
*/
#if !defined(GNU_LINUX)
/* BSD systems
*/
#else
/* Linux Systems
*/
#define RT_TABLE_ID_LOCAL 255
#define RT_TABLE_ID_MAIN 254
#define RT_TABLE_ID_DEFAULT 253
#define RT_TABLE_ID_COMPAT 252
#define RT_TABLE_ID_UNSPEC 0
#endif /* !def(GNU_LINUX) */
/*
* Table chunk struct
* Client daemon which the chunk belongs to can be identified by either
@ -56,8 +72,8 @@ int release_table_chunk(uint8_t proto, uint16_t instance, uint32_t start,
uint32_t end, struct zebra_vrf *zvrf);
int release_daemon_table_chunks(struct zserv *client);
void table_manager_disable(struct zebra_vrf *zvrf);
int table_manager_range(struct vty *vty, bool add, struct zebra_vrf *zvrf,
const char *min, const char *max);
void table_manager_range(bool add, struct zebra_vrf *zvrf, uint32_t start,
uint32_t end);
#ifdef __cplusplus
}

View File

@ -893,6 +893,25 @@ const struct frr_yang_module_info frr_zebra_info = {
.destroy = lib_vrf_zebra_ipv6_resolve_via_default_destroy,
}
},
{
.xpath = "/frr-vrf:lib/vrf/frr-zebra:zebra/netns/table-range",
.cbs = {
.create = lib_vrf_zebra_netns_table_range_create,
.destroy = lib_vrf_zebra_netns_table_range_destroy,
}
},
{
.xpath = "/frr-vrf:lib/vrf/frr-zebra:zebra/netns/table-range/start",
.cbs = {
.modify = lib_vrf_zebra_netns_table_range_start_modify,
}
},
{
.xpath = "/frr-vrf:lib/vrf/frr-zebra:zebra/netns/table-range/end",
.cbs = {
.modify = lib_vrf_zebra_netns_table_range_end_modify,
}
},
{
.xpath = "/frr-vrf:lib/vrf/frr-zebra:zebra/ribs/rib",
.cbs = {

View File

@ -433,6 +433,10 @@ int lib_vrf_zebra_resolve_via_default_destroy(struct nb_cb_destroy_args *args);
int lib_vrf_zebra_ipv6_resolve_via_default_modify(struct nb_cb_modify_args *args);
int lib_vrf_zebra_ipv6_resolve_via_default_destroy(
struct nb_cb_destroy_args *args);
int lib_vrf_zebra_netns_table_range_create(struct nb_cb_create_args *args);
int lib_vrf_zebra_netns_table_range_destroy(struct nb_cb_destroy_args *args);
int lib_vrf_zebra_netns_table_range_start_modify(struct nb_cb_modify_args *args);
int lib_vrf_zebra_netns_table_range_end_modify(struct nb_cb_modify_args *args);
const void *lib_vrf_zebra_ribs_rib_get_next(struct nb_cb_get_next_args *args);
int lib_vrf_zebra_ribs_rib_get_keys(struct nb_cb_get_keys_args *args);
const void *

View File

@ -28,6 +28,7 @@
#include "zebra/router-id.h"
#include "zebra/zebra_routemap.h"
#include "zebra/zebra_rnh.h"
#include "zebra/table_manager.h"
/*
* XPath: /frr-zebra:zebra/mcast-rpf-lookup
@ -3630,6 +3631,125 @@ int lib_vrf_zebra_ipv6_resolve_via_default_destroy(struct nb_cb_destroy_args *ar
return NB_OK;
}
/*
* XPath: /frr-vrf:lib/vrf/frr-zebra:zebra/netns/table-range
*/
static int table_range_validate(uint32_t start, uint32_t end, char *errmsg,
size_t errmsg_len)
{
#if defined(GNU_LINUX)
if ((start >= RT_TABLE_ID_COMPAT && start <= RT_TABLE_ID_LOCAL) ||
(end >= RT_TABLE_ID_COMPAT && end <= RT_TABLE_ID_LOCAL)) {
snprintfrr(errmsg, errmsg_len,
"Values forbidden in range [%u;%u]",
RT_TABLE_ID_COMPAT, RT_TABLE_ID_LOCAL);
return NB_ERR_VALIDATION;
}
if (start < RT_TABLE_ID_COMPAT && end > RT_TABLE_ID_LOCAL) {
snprintfrr(errmsg, errmsg_len,
"Range overlaps range [%u;%u] forbidden",
RT_TABLE_ID_COMPAT, RT_TABLE_ID_LOCAL);
return NB_ERR_VALIDATION;
}
#endif
return NB_OK;
}
int lib_vrf_zebra_netns_table_range_create(struct nb_cb_create_args *args)
{
struct vrf *vrf;
uint32_t start, end;
const char *vrf_name;
start = yang_dnode_get_uint32(args->dnode, "start");
end = yang_dnode_get_uint32(args->dnode, "end");
if (args->event == NB_EV_VALIDATE) {
vrf_name = yang_dnode_get_string(args->dnode, "../../../name");
if (!vrf_is_backend_netns() &&
strcmp(vrf_name, VRF_DEFAULT_NAME)) {
snprintfrr(args->errmsg, args->errmsg_len,
"Configuration is not available in non-default VRFs when using VRF-lite backend.");
return NB_ERR_VALIDATION;
}
return table_range_validate(start, end, args->errmsg,
args->errmsg_len);
}
if (args->event != NB_EV_APPLY)
return NB_OK;
vrf = nb_running_get_entry(args->dnode, NULL, true);
table_manager_range(true, vrf->info, start, end);
return NB_OK;
}
int lib_vrf_zebra_netns_table_range_destroy(struct nb_cb_destroy_args *args)
{
struct vrf *vrf;
if (args->event != NB_EV_APPLY)
return NB_OK;
vrf = nb_running_get_entry(args->dnode, NULL, true);
table_manager_range(false, vrf->info, 0, 0);
return NB_OK;
}
/*
* XPath: /frr-vrf:lib/vrf/frr-zebra:zebra/netns/table-range/start
*/
int lib_vrf_zebra_netns_table_range_start_modify(struct nb_cb_modify_args *args)
{
struct vrf *vrf;
uint32_t start, end;
start = yang_dnode_get_uint32(args->dnode, NULL);
end = yang_dnode_get_uint32(args->dnode, "../end");
if (args->event == NB_EV_VALIDATE)
return table_range_validate(start, end, args->errmsg,
args->errmsg_len);
if (args->event != NB_EV_APPLY)
return NB_OK;
vrf = nb_running_get_entry(args->dnode, NULL, true);
table_manager_range(true, vrf->info, start, end);
return NB_OK;
}
/*
* XPath: /frr-vrf:lib/vrf/frr-zebra:zebra/netns/table-range/end
*/
int lib_vrf_zebra_netns_table_range_end_modify(struct nb_cb_modify_args *args)
{
struct vrf *vrf;
uint32_t start, end;
start = yang_dnode_get_uint32(args->dnode, "../start");
end = yang_dnode_get_uint32(args->dnode, NULL);
if (args->event == NB_EV_VALIDATE)
return table_range_validate(start, end, args->errmsg,
args->errmsg_len);
if (args->event != NB_EV_APPLY)
return NB_OK;
vrf = nb_running_get_entry(args->dnode, NULL, true);
table_manager_range(true, vrf->info, start, end);
return NB_OK;
}
/*
* XPath: /frr-vrf:lib/vrf/frr-zebra:zebra/l3vni-id
*/

View File

@ -4394,29 +4394,33 @@ DEFPY (no_zebra_protodown_bit,
#endif /* HAVE_NETLINK */
DEFUN(ip_table_range, ip_table_range_cmd,
"[no] ip table range (1-4294967295) (1-4294967295)",
DEFPY_YANG (ip_table_range, ip_table_range_cmd,
"[no] ip table range ![(1-4294967295)$start (1-4294967295)$end]",
NO_STR IP_STR
"table configuration\n"
"Configure table range\n"
"Start Routing Table\n"
"End Routing Table\n")
{
ZEBRA_DECLVAR_CONTEXT_VRF(vrf, zvrf);
if (!zvrf)
return CMD_WARNING;
if (zvrf_id(zvrf) != VRF_DEFAULT && !vrf_is_backend_netns()) {
vty_out(vty,
"VRF subcommand does not make any sense in l3mdev based vrf's\n");
return CMD_WARNING;
if (!no) {
nb_cli_enqueue_change(vty, "./frr-zebra:zebra/netns/table-range",
NB_OP_CREATE, NULL);
nb_cli_enqueue_change(vty,
"./frr-zebra:zebra/netns/table-range/start",
NB_OP_MODIFY, start_str);
nb_cli_enqueue_change(vty,
"./frr-zebra:zebra/netns/table-range/end",
NB_OP_MODIFY, end_str);
} else {
nb_cli_enqueue_change(vty, "./frr-zebra:zebra/netns/table-range",
NB_OP_DESTROY, NULL);
}
if (strmatch(argv[0]->text, "no"))
return table_manager_range(vty, false, zvrf, NULL, NULL);
if (vty->node == CONFIG_NODE)
return nb_cli_apply_changes(vty, "/frr-vrf:lib/vrf[name='%s']",
VRF_DEFAULT_NAME);
return table_manager_range(vty, true, zvrf, argv[3]->arg, argv[4]->arg);
return nb_cli_apply_changes(vty, NULL);
}
#ifdef HAVE_SCRIPTING