Skip to content

Commit

Permalink
zebra, yang, doc: add 'mpls auto' command
Browse files Browse the repository at this point in the history
There is not auto mode for mpls settings, so that
when any labeled route or mpls entry is configured,
then the used interface should automatically turn
on its mpls settings.

Add the following per interface command:

> mpls auto

Change the yang model to replace the mpls boolean
value with an enumerate, which is mapped over the
data values declared under zebra/interface.h.

Signed-off-by: Philippe Guibert <[email protected]>
  • Loading branch information
pguibert6WIND committed Dec 22, 2023
1 parent c9eb206 commit 23ad617
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 15 deletions.
6 changes: 4 additions & 2 deletions doc/user/zebra.rst
Original file line number Diff line number Diff line change
Expand Up @@ -169,13 +169,15 @@ Standard Commands
Set description for the interface.


.. clicmd:: mpls <enable|disable>
.. clicmd:: mpls <enable|disable|auto>

Choose mpls kernel processing value on the interface, for linux. Interfaces
configured with mpls will not automatically turn on if mpls kernel modules do not
happen to be loaded. This command will fail on 3.X linux kernels and does not
work on non-linux systems at all. 'enable' and 'disable' will respectively turn
on and off mpls on the given interface.
on and off mpls on the given interface. The 'auto' mode will enable mpls on the
given interface, if an mpls entry or a labeled route happens to be installed and
needs mpls processing to be turned on.

.. clicmd:: multicast

Expand Down
20 changes: 18 additions & 2 deletions yang/frr-zebra.yang
Original file line number Diff line number Diff line change
Expand Up @@ -1983,9 +1983,25 @@ module frr-zebra {
}

leaf mpls {
type boolean;
description
"Interface MPLS status.";
"Interface MPLS configuration status.";
type enumeration {
enum enable {
value 1;
description
"MPLS configuration is enabled.";
}
enum disable {
value 2;
description
"MPLS configuration is disabled.";
}
enum auto {
value 3;
description
"MPLS configuration is enabled when used.";
}
}
}

leaf bandwidth {
Expand Down
16 changes: 13 additions & 3 deletions zebra/interface.c
Original file line number Diff line number Diff line change
Expand Up @@ -627,6 +627,10 @@ void if_add_update(struct interface *ifp)
dplane_intf_mpls_modify_state(ifp, true);
else if (if_data->mpls_config == IF_ZEBRA_DATA_OFF)
dplane_intf_mpls_modify_state(ifp, false);
else if (if_data->mpls_config == IF_ZEBRA_DATA_AUTO &&
if_data->mpls_dynamic != IF_ZEBRA_DATA_UNSPEC)
dplane_intf_mpls_modify_state(ifp,
if_data->mpls_dynamic);

if (IS_ZEBRA_DEBUG_KERNEL)
zlog_debug(
Expand Down Expand Up @@ -3093,6 +3097,8 @@ static void if_dump_vty_json(struct vty *vty, struct interface *ifp,
json_object_string_add(json_if, "mplsConfig", "mplsEnabled");
else if (zebra_if->mpls_config == IF_ZEBRA_DATA_OFF)
json_object_string_add(json_if, "mplsConfig", "mplsDisabled");
else if (zebra_if->mpls_config == IF_ZEBRA_DATA_AUTO)
json_object_string_add(json_if, "mplsConfig", "mplsAuto");

json_object_boolean_add(json_if, "mplsEnabled", zebra_if->mpls);
json_object_boolean_add(json_if, "linkDown", zebra_if->linkdown);
Expand Down Expand Up @@ -3738,15 +3744,16 @@ DEFUN (multicast,

DEFPY (mpls,
mpls_cmd,
"[no] mpls <enable$on|disable$off>",
"[no] mpls <enable|disable|auto>$state",
NO_STR
MPLS_STR
"Set mpls to be on for the interface\n"
"Set mpls to be off for the interface\n")
"Set mpls to be off for the interface\n"
"Set mpls to be auto for the interface\n")
{
if (!no)
nb_cli_enqueue_change(vty, "./frr-zebra:zebra/mpls",
NB_OP_CREATE, on ? "true" : "false");
NB_OP_CREATE, state);
else
nb_cli_enqueue_change(vty, "./frr-zebra:zebra/mpls",
NB_OP_DESTROY, NULL);
Expand Down Expand Up @@ -5593,6 +5600,9 @@ static int if_config_write(struct vty *vty)
else if (if_data->mpls_config ==
IF_ZEBRA_DATA_OFF)
vty_out(vty, " mpls disable\n");
else if (if_data->mpls_config ==
IF_ZEBRA_DATA_AUTO)
vty_out(vty, " mpls auto\n");
}
}

Expand Down
1 change: 1 addition & 0 deletions zebra/interface.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ extern "C" {
#define IF_ZEBRA_DATA_UNSPEC 0
#define IF_ZEBRA_DATA_ON 1
#define IF_ZEBRA_DATA_OFF 2
#define IF_ZEBRA_DATA_AUTO 3

#define IF_VLAN_BITMAP_MAX 4096

Expand Down
14 changes: 6 additions & 8 deletions zebra/zebra_nb_config.c
Original file line number Diff line number Diff line change
Expand Up @@ -1093,23 +1093,21 @@ int lib_interface_zebra_shutdown_destroy(struct nb_cb_destroy_args *args)
int lib_interface_zebra_mpls_modify(struct nb_cb_modify_args *args)
{
struct interface *ifp;
bool mpls;
struct zebra_if *zif;

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

ifp = nb_running_get_entry(args->dnode, NULL, true);
zif = ifp->info;
mpls = yang_dnode_get_bool(args->dnode, NULL);
zif->mpls_config = yang_dnode_get_enum(args->dnode, NULL);

if (mpls)
zif->mpls_config = IF_ZEBRA_DATA_ON;
else
zif->mpls_config = IF_ZEBRA_DATA_OFF;

dplane_intf_mpls_modify_state(ifp, mpls);
if (zif->mpls_config == IF_ZEBRA_DATA_ON ||
zif->mpls_config == IF_ZEBRA_DATA_OFF)
dplane_intf_mpls_modify_state(ifp, zif->mpls_config ==
IF_ZEBRA_DATA_ON);

/* if auto mode, then let us wait other events */
return NB_OK;
}

Expand Down

0 comments on commit 23ad617

Please sign in to comment.