Skip to content

Commit eb45741

Browse files
authored
Merge pull request #18316 from donaldsharp/ipforwarding_modify
Ipforwarding modify
2 parents 0f5fde7 + 2371561 commit eb45741

File tree

6 files changed

+63
-105
lines changed

6 files changed

+63
-105
lines changed

tests/topotests/zebra_operational_data/test_zebra_operational.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,13 +48,13 @@ def test_zebra_operationalr(tgen):
4848

4949
r1 = tgen.gears["r1"]
5050

51-
output = json.loads(r1.vtysh_cmd("show mgmt get-data /frr-zebra:zebra"))
51+
output = json.loads(r1.vtysh_cmd("show mgmt get-data /frr-zebra:zebra/state"))
5252

5353
logger.info("Output")
5454
logger.info(output)
5555

5656
logger.info("Ensuring that the max-multipath value is returned")
57-
assert "max-multipath" in output["frr-zebra:zebra"].keys()
57+
assert "max-multipath" in output["frr-zebra:zebra"]["state"].keys()
5858

5959
logger.info("Checking IP forwarding states")
6060
state = output["frr-zebra:zebra"]["state"]

yang/frr-zebra.yang

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3080,17 +3080,6 @@ module frr-zebra {
30803080
container zebra {
30813081
description
30823082
"Data model for the Zebra daemon.";
3083-
leaf max-multipath {
3084-
type uint16 {
3085-
range "1..65535";
3086-
}
3087-
config false;
3088-
description
3089-
"The maximum number of nexthops for a route. At this point it
3090-
is unlikely that a multipath number will ever get larger then
3091-
1024 but to allow for future expansions, the yang returns a
3092-
16 bit number";
3093-
}
30943083
leaf ip-forwarding {
30953084
type boolean;
30963085
description
@@ -3193,6 +3182,16 @@ module frr-zebra {
31933182
config false;
31943183
description
31953184
"Operational data.";
3185+
leaf max-multipath {
3186+
type uint16 {
3187+
range "1..65535";
3188+
}
3189+
description
3190+
"The maximum number of nexthops for a route. At this point it
3191+
is unlikely that a multipath number will ever get larger then
3192+
1024 but to allow for future expansions, the yang returns a
3193+
16 bit number";
3194+
}
31963195
leaf ip-forwarding {
31973196
type boolean;
31983197
description

zebra/zebra_nb.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ const struct frr_yang_module_info frr_zebra_info = {
2626
.features = features,
2727
.nodes = {
2828
{
29-
.xpath = "/frr-zebra:zebra/max-multipath",
29+
.xpath = "/frr-zebra:zebra/state/max-multipath",
3030
.cbs = {
3131
.get_elem = zebra_max_multipath_get_elem,
3232
}

zebra/zebra_nb_config.c

Lines changed: 31 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -30,19 +30,28 @@
3030
#include "zebra/zebra_routemap.h"
3131
#include "zebra/zebra_rnh.h"
3232
#include "zebra/table_manager.h"
33+
#include "zebra/ipforward.h"
3334

3435
/*
3536
* XPath: /frr-zebra:zebra/ip-forwarding
3637
*/
3738
int zebra_ip_forwarding_modify(struct nb_cb_modify_args *args)
3839
{
39-
switch (args->event) {
40-
case NB_EV_VALIDATE:
41-
case NB_EV_PREPARE:
42-
case NB_EV_ABORT:
43-
case NB_EV_APPLY:
44-
/* TODO: implement me. */
45-
break;
40+
bool forwarding;
41+
int ret;
42+
43+
if (args->event != NB_EV_APPLY)
44+
return NB_OK;
45+
46+
forwarding = yang_dnode_get_bool(args->dnode, NULL);
47+
48+
ret = ipforward();
49+
if (ret == 0) {
50+
if (forwarding)
51+
ipforward_on();
52+
} else {
53+
if (!forwarding)
54+
ipforward_off();
4655
}
4756

4857
return NB_OK;
@@ -67,13 +76,21 @@ int zebra_ip_forwarding_destroy(struct nb_cb_destroy_args *args)
6776
*/
6877
int zebra_ipv6_forwarding_modify(struct nb_cb_modify_args *args)
6978
{
70-
switch (args->event) {
71-
case NB_EV_VALIDATE:
72-
case NB_EV_PREPARE:
73-
case NB_EV_ABORT:
74-
case NB_EV_APPLY:
75-
/* TODO: implement me. */
76-
break;
79+
bool forwarding;
80+
int ret;
81+
82+
if (args->event != NB_EV_APPLY)
83+
return NB_OK;
84+
85+
forwarding = yang_dnode_get_bool(args->dnode, NULL);
86+
ret = ipforward_ipv6();
87+
88+
if (ret == 0) {
89+
if (forwarding)
90+
ipforward_ipv6_on();
91+
} else {
92+
if (!forwarding)
93+
ipforward_ipv6_off();
7794
}
7895

7996
return NB_OK;

zebra/zebra_nb_state.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1177,7 +1177,7 @@ lib_vrf_zebra_ribs_rib_route_route_entry_nexthop_group_nexthop_weight_get_elem(
11771177

11781178
/*
11791179
* XPath:
1180-
* /frr-zebra:zebra/max-multipath
1180+
* /frr-zebra:zebra/state/max-multipath
11811181
*/
11821182
struct yang_data *zebra_max_multipath_get_elem(struct nb_cb_get_elem_args *args)
11831183
{

zebra/zebra_vty.c

Lines changed: 18 additions & 76 deletions
Original file line numberDiff line numberDiff line change
@@ -3849,45 +3849,17 @@ DEFUN (show_zebra,
38493849
return CMD_SUCCESS;
38503850
}
38513851

3852-
DEFUN (ip_forwarding,
3853-
ip_forwarding_cmd,
3854-
"ip forwarding",
3855-
IP_STR
3856-
"Turn on IP forwarding\n")
3857-
{
3858-
int ret;
3859-
3860-
ret = ipforward();
3861-
if (ret == 0)
3862-
ret = ipforward_on();
3863-
3864-
if (ret == 0) {
3865-
vty_out(vty, "Can't turn on IP forwarding\n");
3866-
return CMD_WARNING_CONFIG_FAILED;
3867-
}
3868-
3869-
return CMD_SUCCESS;
3870-
}
3871-
3872-
DEFUN (no_ip_forwarding,
3873-
no_ip_forwarding_cmd,
3874-
"no ip forwarding",
3875-
NO_STR
3876-
IP_STR
3877-
"Turn off IP forwarding\n")
3852+
DEFPY_YANG (ip_forwarding,
3853+
ip_forwarding_cmd,
3854+
"[no] ip forwarding",
3855+
NO_STR
3856+
IP_STR
3857+
"Turn on IP forwarding\n")
38783858
{
3879-
int ret;
3859+
nb_cli_enqueue_change(vty, "/frr-zebra:zebra/ip-forwarding", NB_OP_MODIFY,
3860+
no ? "false" : "true");
38803861

3881-
ret = ipforward();
3882-
if (ret != 0)
3883-
ret = ipforward_off();
3884-
3885-
if (ret != 0) {
3886-
vty_out(vty, "Can't turn off IP forwarding\n");
3887-
return CMD_WARNING_CONFIG_FAILED;
3888-
}
3889-
3890-
return CMD_SUCCESS;
3862+
return nb_cli_apply_changes(vty, NULL);
38913863
}
38923864

38933865
/* Only display ip forwarding is enabled or not. */
@@ -3938,45 +3910,17 @@ DEFUN (show_ipv6_forwarding,
39383910
return CMD_SUCCESS;
39393911
}
39403912

3941-
DEFUN (ipv6_forwarding,
3942-
ipv6_forwarding_cmd,
3943-
"ipv6 forwarding",
3944-
IPV6_STR
3945-
"Turn on IPv6 forwarding\n")
3946-
{
3947-
int ret;
3948-
3949-
ret = ipforward_ipv6();
3950-
if (ret == 0)
3951-
ret = ipforward_ipv6_on();
3952-
3953-
if (ret == 0) {
3954-
vty_out(vty, "Can't turn on IPv6 forwarding\n");
3955-
return CMD_WARNING_CONFIG_FAILED;
3956-
}
3957-
3958-
return CMD_SUCCESS;
3959-
}
3960-
3961-
DEFUN (no_ipv6_forwarding,
3962-
no_ipv6_forwarding_cmd,
3963-
"no ipv6 forwarding",
3964-
NO_STR
3965-
IPV6_STR
3966-
"Turn off IPv6 forwarding\n")
3913+
DEFPY_YANG (ipv6_forwarding,
3914+
ipv6_forwarding_cmd,
3915+
"[no] ipv6 forwarding",
3916+
NO_STR
3917+
IPV6_STR
3918+
"Turn on IPv6 forwarding\n")
39673919
{
3968-
int ret;
3920+
nb_cli_enqueue_change(vty, "/frr-zebra:zebra/ipv6-forwarding", NB_OP_MODIFY,
3921+
no ? "false" : "true");
39693922

3970-
ret = ipforward_ipv6();
3971-
if (ret != 0)
3972-
ret = ipforward_ipv6_off();
3973-
3974-
if (ret != 0) {
3975-
vty_out(vty, "Can't turn off IPv6 forwarding\n");
3976-
return CMD_WARNING_CONFIG_FAILED;
3977-
}
3978-
3979-
return CMD_SUCCESS;
3923+
return nb_cli_apply_changes(vty, NULL);
39803924
}
39813925

39823926
/* Display dataplane info */
@@ -4269,12 +4213,10 @@ void zebra_vty_init(void)
42694213

42704214
install_element(VIEW_NODE, &show_ip_forwarding_cmd);
42714215
install_element(CONFIG_NODE, &ip_forwarding_cmd);
4272-
install_element(CONFIG_NODE, &no_ip_forwarding_cmd);
42734216
install_element(ENABLE_NODE, &show_zebra_cmd);
42744217

42754218
install_element(VIEW_NODE, &show_ipv6_forwarding_cmd);
42764219
install_element(CONFIG_NODE, &ipv6_forwarding_cmd);
4277-
install_element(CONFIG_NODE, &no_ipv6_forwarding_cmd);
42784220

42794221
/* Route-map */
42804222
zebra_route_map_init();

0 commit comments

Comments
 (0)