zebra: convert interface ipv6 nd suppress-ra command to NB

Signed-off-by: Igor Ryzhov <iryzhov@nfware.com>
This commit is contained in:
Igor Ryzhov 2024-01-23 14:20:49 +02:00
parent 10757acae6
commit d617c9175a
6 changed files with 70 additions and 40 deletions

View File

@ -2264,6 +2264,21 @@ module frr-zebra {
"Uplink to the VxLAN core.";
}
}
container ipv6-router-advertisements {
description
"Support for IPv6 Router Advertisements.";
leaf send-advertisements {
type boolean;
default "false";
description
"A flag indicating whether or not the router sends
periodic Router Advertisements and responds to
Router Solicitations.";
reference
"RFC 4861: Neighbor Discovery for IP version 6 (IPv6)
- AdvSendAdvertisements";
}
}
container state {
config false;
description

View File

@ -21,6 +21,7 @@
#include "vrf.h"
#include "ns.h"
#include "lib_errors.h"
#include "northbound_cli.h"
#include "zebra/interface.h"
#include "zebra/rtadv.h"
@ -1248,8 +1249,8 @@ static void rtadv_start_interface_events(struct zebra_vrf *zvrf,
rtadv_event(zvrf, RTADV_START, 0);
}
static void ipv6_nd_suppress_ra_set(struct interface *ifp,
enum ipv6_nd_suppress_ra_status status)
void ipv6_nd_suppress_ra_set(struct interface *ifp,
enum ipv6_nd_suppress_ra_status status)
{
struct zebra_if *zif;
struct zebra_vrf *zvrf;
@ -1632,49 +1633,23 @@ DEFPY (no_ipv6_nd_ra_retrans_interval,
return CMD_SUCCESS;
}
DEFUN (ipv6_nd_suppress_ra,
DEFPY_YANG (ipv6_nd_suppress_ra,
ipv6_nd_suppress_ra_cmd,
"ipv6 nd suppress-ra",
"Interface IPv6 config commands\n"
"Neighbor discovery\n"
"Suppress Router Advertisement\n")
{
VTY_DECLVAR_CONTEXT(interface, ifp);
struct zebra_if *zif = ifp->info;
if (if_is_loopback(ifp)) {
vty_out(vty,
"Cannot configure IPv6 Router Advertisements on this interface\n");
return CMD_WARNING_CONFIG_FAILED;
}
if (!CHECK_FLAG(zif->rtadv.ra_configured, BGP_RA_CONFIGURED))
ipv6_nd_suppress_ra_set(ifp, RA_SUPPRESS);
UNSET_FLAG(zif->rtadv.ra_configured, VTY_RA_CONFIGURED);
return CMD_SUCCESS;
}
DEFUN (no_ipv6_nd_suppress_ra,
no_ipv6_nd_suppress_ra_cmd,
"no ipv6 nd suppress-ra",
"[no] ipv6 nd suppress-ra",
NO_STR
"Interface IPv6 config commands\n"
"Neighbor discovery\n"
"Suppress Router Advertisement\n")
{
VTY_DECLVAR_CONTEXT(interface, ifp);
struct zebra_if *zif = ifp->info;
if (if_is_loopback(ifp)) {
vty_out(vty,
"Cannot configure IPv6 Router Advertisements on this interface\n");
return CMD_WARNING_CONFIG_FAILED;
}
ipv6_nd_suppress_ra_set(ifp, RA_ENABLE);
SET_FLAG(zif->rtadv.ra_configured, VTY_RA_CONFIGURED);
return CMD_SUCCESS;
if (no)
nb_cli_enqueue_change(vty,
"./frr-zebra:zebra/ipv6-router-advertisements/send-advertisements",
NB_OP_MODIFY, "true");
else
nb_cli_enqueue_change(vty,
"./frr-zebra:zebra/ipv6-router-advertisements/send-advertisements",
NB_OP_DESTROY, NULL);
return nb_cli_apply_changes(vty, NULL);
}
DEFUN (ipv6_nd_ra_interval_msec,
@ -2928,7 +2903,6 @@ void rtadv_cmd_init(void)
install_element(INTERFACE_NODE, &ipv6_nd_ra_hop_limit_cmd);
install_element(INTERFACE_NODE, &no_ipv6_nd_ra_hop_limit_cmd);
install_element(INTERFACE_NODE, &ipv6_nd_suppress_ra_cmd);
install_element(INTERFACE_NODE, &no_ipv6_nd_suppress_ra_cmd);
install_element(INTERFACE_NODE, &ipv6_nd_ra_interval_cmd);
install_element(INTERFACE_NODE, &ipv6_nd_ra_interval_msec_cmd);
install_element(INTERFACE_NODE, &no_ipv6_nd_ra_interval_cmd);

View File

@ -385,6 +385,9 @@ extern void rtadv_if_fini(struct zebra_if *zif);
extern void rtadv_add_prefix(struct zebra_if *zif, const struct prefix_ipv6 *p);
extern void rtadv_delete_prefix(struct zebra_if *zif, const struct prefix *p);
void ipv6_nd_suppress_ra_set(struct interface *ifp,
enum ipv6_nd_suppress_ra_status status);
#else /* !HAVE_RTADV */
struct rtadv {
/* empty structs aren't valid ISO C */

View File

@ -546,6 +546,12 @@ const struct frr_yang_module_info frr_zebra_info = {
.modify = lib_interface_zebra_evpn_mh_uplink_modify,
}
},
{
.xpath = "/frr-interface:lib/interface/frr-zebra:zebra/ipv6-router-advertisements/send-advertisements",
.cbs = {
.modify = lib_interface_zebra_ipv6_router_advertisements_send_advertisements_modify,
}
},
{
.xpath = "/frr-interface:lib/interface/frr-zebra:zebra/state/up-count",
.cbs = {

View File

@ -181,6 +181,8 @@ int lib_interface_zebra_evpn_mh_df_preference_modify(
struct nb_cb_modify_args *args);
int lib_interface_zebra_evpn_mh_bypass_modify(struct nb_cb_modify_args *args);
int lib_interface_zebra_evpn_mh_uplink_modify(struct nb_cb_modify_args *args);
int lib_interface_zebra_ipv6_router_advertisements_send_advertisements_modify(
struct nb_cb_modify_args *args);
struct yang_data *
lib_interface_zebra_state_up_count_get_elem(struct nb_cb_get_elem_args *args);
struct yang_data *

View File

@ -2455,6 +2455,36 @@ int lib_interface_zebra_evpn_mh_uplink_modify(struct nb_cb_modify_args *args)
return NB_OK;
}
/*
* XPath: /frr-interface:lib/interface/frr-zebra:zebra/ipv6-router-advertisements/send-advertisements
*/
int lib_interface_zebra_ipv6_router_advertisements_send_advertisements_modify(
struct nb_cb_modify_args *args)
{
struct interface *ifp;
struct zebra_if *zif;
bool send_adv;
if (args->event != NB_EV_APPLY)
return NB_OK;
ifp = nb_running_get_entry(args->dnode, NULL, true);
zif = ifp->info;
send_adv = yang_dnode_get_bool(args->dnode, NULL);
if (send_adv) {
ipv6_nd_suppress_ra_set(ifp, RA_ENABLE);
SET_FLAG(zif->rtadv.ra_configured, VTY_RA_CONFIGURED);
} else {
if (!CHECK_FLAG(zif->rtadv.ra_configured, BGP_RA_CONFIGURED))
ipv6_nd_suppress_ra_set(ifp, RA_SUPPRESS);
UNSET_FLAG(zif->rtadv.ra_configured, VTY_RA_CONFIGURED);
}
return NB_OK;
}
/*
* XPath: /frr-vrf:lib/vrf/frr-zebra:zebra/l3vni-id
*/