diff options
-rw-r--r-- | ripd/rip_cli.c | 28 | ||||
-rw-r--r-- | ripd/rip_cli.h | 2 | ||||
-rw-r--r-- | ripd/rip_northbound.c | 25 | ||||
-rw-r--r-- | ripd/ripd.c | 94 | ||||
-rw-r--r-- | ripd/ripd.h | 3 |
5 files changed, 53 insertions, 99 deletions
diff --git a/ripd/rip_cli.c b/ripd/rip_cli.c index 4bbec64f1..00608b026 100644 --- a/ripd/rip_cli.c +++ b/ripd/rip_cli.c @@ -612,6 +612,33 @@ void cli_show_rip_redistribute(struct vty *vty, struct lyd_node *dnode, vty_out(vty, "\n"); } +/* + * XPath: /frr-ripd:ripd/instance/static-route + */ +DEFPY (rip_route, + rip_route_cmd, + "[no] route A.B.C.D/M", + NO_STR + "RIP static route configuration\n" + "IP prefix <network>/<length>\n") +{ + struct cli_config_change changes[] = { + { + .xpath = "./static-route", + .operation = no ? NB_OP_DELETE : NB_OP_CREATE, + .value = route_str, + }, + }; + + return nb_cli_cfg_change(vty, NULL, changes, array_size(changes)); +} + +void cli_show_rip_route(struct vty *vty, struct lyd_node *dnode, + bool show_defaults) +{ + vty_out(vty, " route %s\n", yang_dnode_get_string(dnode, NULL)); +} + void rip_cli_init(void) { install_element(CONFIG_NODE, &router_rip_cmd); @@ -634,4 +661,5 @@ void rip_cli_init(void) install_element(RIP_NODE, &rip_passive_interface_cmd); install_element(RIP_NODE, &rip_redistribute_cmd); install_element(RIP_NODE, &no_rip_redistribute_cmd); + install_element(RIP_NODE, &rip_route_cmd); } diff --git a/ripd/rip_cli.h b/ripd/rip_cli.h index 6625a301e..3d06cc7a4 100644 --- a/ripd/rip_cli.h +++ b/ripd/rip_cli.h @@ -55,5 +55,7 @@ extern void cli_show_rip_non_passive_interface(struct vty *vty, bool show_defaults); extern void cli_show_rip_redistribute(struct vty *vty, struct lyd_node *dnode, bool show_defaults); +extern void cli_show_rip_route(struct vty *vty, struct lyd_node *dnode, + bool show_defaults); #endif /* _FRR_RIP_CLI_H_ */ diff --git a/ripd/rip_northbound.c b/ripd/rip_northbound.c index a57e29437..ffb4a10c9 100644 --- a/ripd/rip_northbound.c +++ b/ripd/rip_northbound.c @@ -660,14 +660,34 @@ static int ripd_instance_static_route_create(enum nb_event event, const struct lyd_node *dnode, union nb_resource *resource) { - /* TODO: implement me. */ + struct nexthop nh; + struct prefix_ipv4 p; + + if (event != NB_EV_APPLY) + return NB_OK; + + yang_dnode_get_ipv4p(&p, dnode, NULL); + + memset(&nh, 0, sizeof(nh)); + nh.type = NEXTHOP_TYPE_IPV4; + rip_redistribute_add(ZEBRA_ROUTE_RIP, RIP_ROUTE_STATIC, &p, &nh, 0, 0, + 0); + return NB_OK; } static int ripd_instance_static_route_delete(enum nb_event event, const struct lyd_node *dnode) { - /* TODO: implement me. */ + struct prefix_ipv4 p; + + if (event != NB_EV_APPLY) + return NB_OK; + + yang_dnode_get_ipv4p(&p, dnode, NULL); + + rip_redistribute_delete(ZEBRA_ROUTE_RIP, RIP_ROUTE_STATIC, &p, 0); + return NB_OK; } @@ -1106,6 +1126,7 @@ const struct frr_yang_module_info frr_ripd_info = { .xpath = "/frr-ripd:ripd/instance/static-route", .cbs.create = ripd_instance_static_route_create, .cbs.delete = ripd_instance_static_route_delete, + .cbs.cli_show = cli_show_rip_route, }, { .xpath = "/frr-ripd:ripd/instance/timers/flush-interval", diff --git a/ripd/ripd.c b/ripd/ripd.c index 26b79e873..806d55eb3 100644 --- a/ripd/ripd.c +++ b/ripd/ripd.c @@ -2689,7 +2689,6 @@ int rip_create(int socket) /* Initialize RIP routig table. */ rip->table = route_table_init(); - rip->route = route_table_init(); rip->neighbor = route_table_init(); /* Make output stream. */ @@ -2835,82 +2834,6 @@ DEFUN (no_rip_version, return CMD_SUCCESS; } - -DEFUN (rip_route, - rip_route_cmd, - "route A.B.C.D/M", - "RIP static route configuration\n" - "IP prefix <network>/<length>\n") -{ - int idx_ipv4_prefixlen = 1; - int ret; - struct nexthop nh; - struct prefix_ipv4 p; - struct route_node *node; - - memset(&nh, 0, sizeof(nh)); - nh.type = NEXTHOP_TYPE_IPV4; - - ret = str2prefix_ipv4(argv[idx_ipv4_prefixlen]->arg, &p); - if (ret < 0) { - vty_out(vty, "Malformed address\n"); - return CMD_WARNING_CONFIG_FAILED; - } - apply_mask_ipv4(&p); - - /* For router rip configuration. */ - node = route_node_get(rip->route, (struct prefix *)&p); - - if (node->info) { - vty_out(vty, "There is already same static route.\n"); - route_unlock_node(node); - return CMD_WARNING; - } - - node->info = (void *)1; - - rip_redistribute_add(ZEBRA_ROUTE_RIP, RIP_ROUTE_STATIC, &p, &nh, 0, 0, - 0); - - return CMD_SUCCESS; -} - -DEFUN (no_rip_route, - no_rip_route_cmd, - "no route A.B.C.D/M", - NO_STR - "RIP static route configuration\n" - "IP prefix <network>/<length>\n") -{ - int idx_ipv4_prefixlen = 2; - int ret; - struct prefix_ipv4 p; - struct route_node *node; - - ret = str2prefix_ipv4(argv[idx_ipv4_prefixlen]->arg, &p); - if (ret < 0) { - vty_out(vty, "Malformed address\n"); - return CMD_WARNING_CONFIG_FAILED; - } - apply_mask_ipv4(&p); - - /* For router rip configuration. */ - node = route_node_lookup(rip->route, (struct prefix *)&p); - if (!node) { - vty_out(vty, "Can't find route %s.\n", - argv[idx_ipv4_prefixlen]->arg); - return CMD_WARNING_CONFIG_FAILED; - } - - rip_redistribute_delete(ZEBRA_ROUTE_RIP, RIP_ROUTE_STATIC, &p, 0); - route_unlock_node(node); - - node->info = NULL; - route_unlock_node(node); - - return CMD_SUCCESS; -} - #if 0 static void rip_update_default_metric (void) @@ -3388,7 +3311,6 @@ DEFUN (show_ip_rip_status, static int config_write_rip(struct vty *vty) { int write = 0; - struct route_node *rn; struct lyd_node *dnode; dnode = yang_dnode_get(running_config->dnode, @@ -3416,13 +3338,6 @@ static int config_write_rip(struct vty *vty) /* Interface routemap configuration */ write += config_write_if_rmap(vty); - - /* RIP static route configuration. */ - for (rn = route_top(rip->route); rn; rn = route_next(rn)) - if (rn->info) - vty_out(vty, " route %s/%d\n", - inet_ntoa(rn->p.u.prefix4), - rn->p.prefixlen); } return write; } @@ -3558,12 +3473,6 @@ void rip_clean(void) } stream_free(rip->obuf); - /* Static RIP route configuration. */ - for (rp = route_top(rip->route); rp; rp = route_next(rp)) - if (rp->info) { - rp->info = NULL; - route_unlock_node(rp); - } /* RIP neighbor configuration. */ for (rp = route_top(rip->neighbor); rp; rp = route_next(rp)) @@ -3577,7 +3486,6 @@ void rip_clean(void) free(rip->route_map[i].name); XFREE(MTYPE_ROUTE_TABLE, rip->table); - XFREE(MTYPE_ROUTE_TABLE, rip->route); XFREE(MTYPE_ROUTE_TABLE, rip->neighbor); XFREE(MTYPE_RIP, rip); @@ -3697,8 +3605,6 @@ void rip_init(void) install_element(RIP_NODE, &no_rip_version_cmd); install_element(RIP_NODE, &rip_timers_cmd); install_element(RIP_NODE, &no_rip_timers_cmd); - install_element(RIP_NODE, &rip_route_cmd); - install_element(RIP_NODE, &no_rip_route_cmd); /* Debug related init. */ rip_debug_init(); diff --git a/ripd/ripd.h b/ripd/ripd.h index 7a1e3837b..5ac2be9ab 100644 --- a/ripd/ripd.h +++ b/ripd/ripd.h @@ -117,9 +117,6 @@ struct rip { /* RIP routing information base. */ struct route_table *table; - /* RIP only static routing information. */ - struct route_table *route; - /* RIP neighbor. */ struct route_table *neighbor; |