Skip to content

Commit

Permalink
lib, mgmtd, zebra: cleanup of zebra conversion to mgmtd
Browse files Browse the repository at this point in the history
- fix zebra interface oper path
- use `apply_finish` callback when possible to avoid multiple applies per commit
- move table range working to the CLI handler
- remove unnecessary conditional compilation
- remove unnecessary boolean conversion

Signed-off-by: Igor Ryzhov <[email protected]>
  • Loading branch information
idryzhov committed Jan 28, 2024
1 parent 3900813 commit 930ac82
Show file tree
Hide file tree
Showing 8 changed files with 103 additions and 129 deletions.
1 change: 1 addition & 0 deletions lib/northbound.h
Original file line number Diff line number Diff line change
Expand Up @@ -630,6 +630,7 @@ struct frr_yang_module_info {

/*
* The NULL-terminated list of supported features.
* Features are defined with "feature" statements in the YANG model.
* Use ["*", NULL] to enable all features.
* Use NULL to disable all features.
*/
Expand Down
2 changes: 1 addition & 1 deletion mgmtd/mgmt_be_adapter.c
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ static const char *const zebra_config_xpaths[] = {
};

static const char *const zebra_oper_xpaths[] = {
"/frr-interface:lib/interface",
"/frr-interface:lib/interface/frr-zebra:zebra",
"/frr-vrf:lib/vrf/frr-zebra:zebra",
"/frr-zebra:zebra",
NULL,
Expand Down
15 changes: 0 additions & 15 deletions zebra/interface.c
Original file line number Diff line number Diff line change
Expand Up @@ -3792,27 +3792,16 @@ void link_param_cmd_set_uint32(struct interface *ifp, uint32_t *field,
if (IS_PARAM_UNSET(ifp->link_params, type) || *field != value) {
*field = value;
SET_PARAM(ifp->link_params, type);

/* force protocols to update LINK STATE due to parameters change
*/
if (if_is_operative(ifp))
zebra_interface_parameters_update(ifp);
}
}

void link_param_cmd_set_float(struct interface *ifp, float *field,
uint32_t type, float value)
{

/* Update field as needed */
if (IS_PARAM_UNSET(ifp->link_params, type) || *field != value) {
*field = value;
SET_PARAM(ifp->link_params, type);

/* force protocols to update LINK STATE due to parameters change
*/
if (if_is_operative(ifp))
zebra_interface_parameters_update(ifp);
}
}

Expand All @@ -3823,10 +3812,6 @@ void link_param_cmd_unset(struct interface *ifp, uint32_t type)

/* Unset field */
UNSET_PARAM(ifp->link_params, type);

/* force protocols to update LINK STATE due to parameters change */
if (if_is_operative(ifp))
zebra_interface_parameters_update(ifp);
}

void if_ip_address_install(struct interface *ifp, struct prefix *prefix,
Expand Down
10 changes: 2 additions & 8 deletions zebra/table_manager.c
Original file line number Diff line number Diff line change
Expand Up @@ -267,14 +267,8 @@ void table_manager_disable(struct zebra_vrf *zvrf)
void table_manager_range(bool add, struct zebra_vrf *zvrf, uint32_t start,
uint32_t end)
{
if (add) {
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 (add)
table_range_add(zvrf, start, end);
} else
else
table_range_add(zvrf, 0, 0);
}
42 changes: 37 additions & 5 deletions zebra/zebra_cli.c
Original file line number Diff line number Diff line change
Expand Up @@ -2212,7 +2212,10 @@ DEFPY_YANG (vrf_netns,
"Attach VRF to a Namespace\n"
"The file name in " NS_RUN_DIR ", or a full pathname\n")
{
return CMD_SUCCESS;
vty_out(vty, "%% This command doesn't do anything.\n");
vty_out(vty,
"%% VRF is linked to a netns automatically based on its name.\n");
return CMD_WARNING;
}

DEFPY_YANG (ip_table_range, ip_table_range_cmd,
Expand All @@ -2224,6 +2227,39 @@ DEFPY_YANG (ip_table_range, ip_table_range_cmd,
"End Routing Table\n")
{
if (!no) {
const struct lyd_node *start_node;
const struct lyd_node *end_node;

if (vty->node == CONFIG_NODE) {
start_node =
yang_dnode_getf(vty->candidate_config->dnode,
"/frr-vrf:lib/vrf[name='%s']/frr-zebra:zebra/netns/table-range/start",
VRF_DEFAULT_NAME);
end_node =
yang_dnode_getf(vty->candidate_config->dnode,
"/frr-vrf:lib/vrf[name='%s']/frr-zebra:zebra/netns/table-range/end",
VRF_DEFAULT_NAME);
} else {
start_node =
yang_dnode_getf(vty->candidate_config->dnode,
"%s/frr-zebra:zebra/netns/table-range/start",
VTY_CURR_XPATH);
end_node =
yang_dnode_getf(vty->candidate_config->dnode,
"%s/frr-zebra:zebra/netns/table-range/end",
VTY_CURR_XPATH);
}

if (start_node && end_node) {
if (yang_dnode_get_uint32(start_node, NULL) != start ||
yang_dnode_get_uint32(end_node, NULL) != end) {
vty_out(vty,
"%% New range will be taken into account at restart.\n");
vty_out(vty,
"%% Don't forget to save your configuration.\n");
}
}

nb_cli_enqueue_change(vty, "./frr-zebra:zebra/netns/table-range",
NB_OP_CREATE, NULL);
nb_cli_enqueue_change(vty,
Expand Down Expand Up @@ -2546,7 +2582,6 @@ DEFPY_YANG(
return nb_cli_apply_changes(vty, NULL);
}

#if HAVE_BFDD == 0 || defined(HAVE_RTADV)
const char *features[] = {
#if HAVE_BFDD == 0
"ptm-bfd",
Expand All @@ -2556,15 +2591,12 @@ const char *features[] = {
#endif
NULL
};
#endif

/* clang-format off */
const struct frr_yang_module_info frr_zebra_cli_info = {
.name = "frr-zebra",
.ignore_cfg_cbs = true,
#if HAVE_BFDD == 0 || defined(HAVE_RTADV)
.features = features,
#endif
.nodes = {
#if HAVE_BFDD == 0
{
Expand Down
7 changes: 3 additions & 4 deletions zebra/zebra_nb.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
#include "libfrr.h"
#include "zebra_nb.h"

#if HAVE_BFDD == 0 || defined(HAVE_RTADV)
const char *features[] = {
#if HAVE_BFDD == 0
"ptm-bfd",
Expand All @@ -20,14 +19,11 @@ const char *features[] = {
#endif
NULL
};
#endif

/* clang-format off */
const struct frr_yang_module_info frr_zebra_info = {
.name = "frr-zebra",
#if HAVE_BFDD == 0 || defined(HAVE_RTADV)
.features = features,
#endif
.nodes = {
{
.xpath = "/frr-zebra:zebra/mcast-rpf-lookup",
Expand Down Expand Up @@ -392,6 +388,7 @@ const struct frr_yang_module_info frr_zebra_info = {
.cbs = {
.create = lib_interface_zebra_link_params_create,
.destroy = lib_interface_zebra_link_params_destroy,
.apply_finish = lib_interface_zebra_link_params_apply_finish,
}
},
{
Expand Down Expand Up @@ -808,6 +805,7 @@ const struct frr_yang_module_info frr_zebra_info = {
.cbs = {
.create = lib_vrf_zebra_filter_protocol_create,
.destroy = lib_vrf_zebra_filter_protocol_destroy,
.apply_finish = lib_vrf_zebra_filter_protocol_apply_finish,
}
},
{
Expand All @@ -821,6 +819,7 @@ const struct frr_yang_module_info frr_zebra_info = {
.cbs = {
.create = lib_vrf_zebra_filter_nht_create,
.destroy = lib_vrf_zebra_filter_nht_destroy,
.apply_finish = lib_vrf_zebra_filter_nht_apply_finish,
}
},
{
Expand Down
5 changes: 5 additions & 0 deletions zebra/zebra_nb.h
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,8 @@ int lib_interface_zebra_mpls_modify(struct nb_cb_modify_args *args);
int lib_interface_zebra_mpls_destroy(struct nb_cb_destroy_args *args);
int lib_interface_zebra_link_params_create(struct nb_cb_create_args *args);
int lib_interface_zebra_link_params_destroy(struct nb_cb_destroy_args *args);
void lib_interface_zebra_link_params_apply_finish(
struct nb_cb_apply_finish_args *args);
int lib_interface_zebra_link_params_metric_modify(struct nb_cb_modify_args *args);
int lib_interface_zebra_link_params_metric_destroy(
struct nb_cb_destroy_args *args);
Expand Down Expand Up @@ -283,10 +285,13 @@ int lib_vrf_zebra_ipv6_router_id_modify(struct nb_cb_modify_args *args);
int lib_vrf_zebra_ipv6_router_id_destroy(struct nb_cb_destroy_args *args);
int lib_vrf_zebra_filter_protocol_create(struct nb_cb_create_args *args);
int lib_vrf_zebra_filter_protocol_destroy(struct nb_cb_destroy_args *args);
void lib_vrf_zebra_filter_protocol_apply_finish(
struct nb_cb_apply_finish_args *args);
int lib_vrf_zebra_filter_protocol_route_map_modify(
struct nb_cb_modify_args *args);
int lib_vrf_zebra_filter_nht_create(struct nb_cb_create_args *args);
int lib_vrf_zebra_filter_nht_destroy(struct nb_cb_destroy_args *args);
void lib_vrf_zebra_filter_nht_apply_finish(struct nb_cb_apply_finish_args *args);
int lib_vrf_zebra_filter_nht_route_map_modify(struct nb_cb_modify_args *args);
int lib_vrf_zebra_resolve_via_default_modify(struct nb_cb_modify_args *args);
int lib_vrf_zebra_resolve_via_default_destroy(struct nb_cb_destroy_args *args);
Expand Down
Loading

0 comments on commit 930ac82

Please sign in to comment.