#include "if_rmap.h"
#include "privs.h"
#include "lib_errors.h"
+#include "northbound_cli.h"
#include "ripngd/ripngd.h"
#include "ripngd/ripng_route.h"
struct in6_addr address;
};
-static int ripng_route_rte(struct ripng_info *rinfo)
+int ripng_route_rte(struct ripng_info *rinfo)
{
return (rinfo->type == ZEBRA_ROUTE_RIPNG
&& rinfo->sub_type == RIPNG_ROUTE_RTE);
}
/* Create ripng socket. */
-static int ripng_make_socket(void)
+int ripng_make_socket(void)
{
int ret;
int sock;
sock = socket(AF_INET6, SOCK_DGRAM, 0);
if (sock < 0) {
- flog_err_sys(LIB_ERR_SOCKET, "Can't make ripng socket");
+ flog_err_sys(EC_LIB_SOCKET, "Can't make ripng socket");
return sock;
}
if (ret < 0) {
if (to)
- flog_err_sys(LIB_ERR_SOCKET,
+ flog_err_sys(EC_LIB_SOCKET,
"RIPng send fail on %s to %s: %s",
ifp->name, inet6_ntoa(to->sin6_addr),
safe_strerror(errno));
else
- flog_err_sys(LIB_ERR_SOCKET,
- "RIPng send fail on %s: %s", ifp->name,
- safe_strerror(errno));
+ flog_err_sys(EC_LIB_SOCKET, "RIPng send fail on %s: %s",
+ ifp->name, safe_strerror(errno));
}
return ret;
/* Unlock route_node. */
listnode_delete(rp->info, rinfo);
if (list_isempty((struct list *)rp->info)) {
- list_delete_and_null((struct list **)&rp->info);
+ list_delete((struct list **)&rp->info);
agg_unlock_node(rp);
}
&& rinfo->suppress == 0) {
/* If no route-map are applied, the RTE will be these
* following
- * informations.
+ * information.
*/
p = (struct prefix_ipv6 *)&rp->p;
rinfo->metric_out = rinfo->metric;
&& aggregate->suppress == 0) {
/* If no route-map are applied, the RTE will be these
* following
- * informations.
+ * information.
*/
p = (struct prefix_ipv6 *)&rp->p;
aggregate->metric_set = 0;
}
/* Create new RIPng instance and set it to global variable. */
-static int ripng_create(void)
+int ripng_create(int socket)
{
/* ripng should be NULL. */
assert(ripng == NULL);
/* Default version and timer values. */
ripng->version = RIPNG_V1;
- ripng->update_time = RIPNG_UPDATE_TIMER_DEFAULT;
- ripng->timeout_time = RIPNG_TIMEOUT_TIMER_DEFAULT;
- ripng->garbage_time = RIPNG_GARBAGE_TIMER_DEFAULT;
- ripng->default_metric = RIPNG_DEFAULT_METRIC_DEFAULT;
+ ripng->update_time = yang_get_default_uint32(
+ "%s/timers/update-interval", RIPNG_INSTANCE);
+ ripng->timeout_time = yang_get_default_uint32(
+ "%s/timers/holddown-interval", RIPNG_INSTANCE);
+ ripng->garbage_time = yang_get_default_uint32(
+ "%s/timers/flush-interval", RIPNG_INSTANCE);
+ ripng->default_metric =
+ yang_get_default_uint8("%s/default-metric", RIPNG_INSTANCE);
+ ripng->ecmp = yang_get_default_bool("%s/allow-ecmp", RIPNG_INSTANCE);
/* Make buffer. */
ripng->ibuf = stream_new(RIPNG_MAX_PACKET_SIZE * 5);
/* Initialize RIPng routig table. */
ripng->table = agg_table_init();
- ripng->route = agg_table_init();
- ripng->aggregate = agg_table_init();
/* Make socket. */
- ripng->sock = ripng_make_socket();
- if (ripng->sock < 0)
- return ripng->sock;
+ ripng->sock = socket;
/* Threads. */
ripng_event(RIPNG_READ, ripng->sock);
return CMD_SUCCESS;
vty_out(vty, "Routing Protocol is \"RIPng\"\n");
- vty_out(vty, " Sending updates every %ld seconds with +/-50%%,",
+ vty_out(vty, " Sending updates every %u seconds with +/-50%%,",
ripng->update_time);
vty_out(vty, " next due in %lu seconds\n",
thread_timer_remain_second(ripng->t_update));
- vty_out(vty, " Timeout after %ld seconds,", ripng->timeout_time);
- vty_out(vty, " garbage collect after %ld seconds\n",
+ vty_out(vty, " Timeout after %u seconds,", ripng->timeout_time);
+ vty_out(vty, " garbage collect after %u seconds\n",
ripng->garbage_time);
/* Filtering status show. */
/* Redistribute information. */
vty_out(vty, " Redistributing:");
- ripng_redistribute_write(vty, 0);
+ ripng_redistribute_write(vty);
vty_out(vty, "\n");
vty_out(vty, " Default version control: send version %d,",
}
vty_out(vty, " Routing for Networks:\n");
- ripng_network_write(vty, 0);
+ ripng_network_write(vty);
vty_out(vty, " Routing Information Sources:\n");
vty_out(vty,
return CMD_SUCCESS;
}
-DEFUN (clear_ipv6_rip,
- clear_ipv6_rip_cmd,
- "clear ipv6 ripng",
- CLEAR_STR
- IPV6_STR
- "Clear IPv6 RIP database\n")
-{
- struct agg_node *rp;
- struct ripng_info *rinfo;
- struct list *list;
- struct listnode *listnode;
-
- /* Clear received RIPng routes */
- for (rp = agg_route_top(ripng->table); rp; rp = agg_route_next(rp)) {
- list = rp->info;
- if (list == NULL)
- continue;
-
- for (ALL_LIST_ELEMENTS_RO(list, listnode, rinfo)) {
- if (!ripng_route_rte(rinfo))
- continue;
-
- if (CHECK_FLAG(rinfo->flags, RIPNG_RTF_FIB))
- ripng_zebra_ipv6_delete(rp);
- break;
- }
-
- if (rinfo) {
- RIPNG_TIMER_OFF(rinfo->t_timeout);
- RIPNG_TIMER_OFF(rinfo->t_garbage_collect);
- listnode_delete(list, rinfo);
- ripng_info_free(rinfo);
- }
-
- if (list_isempty(list)) {
- list_delete_and_null(&list);
- rp->info = NULL;
- agg_unlock_node(rp);
- }
- }
-
- return CMD_SUCCESS;
-}
-
-DEFUN_NOSH (router_ripng,
- router_ripng_cmd,
- "router ripng",
- "Enable a routing process\n"
- "Make RIPng instance command\n")
-{
- int ret;
-
- vty->node = RIPNG_NODE;
-
- if (!ripng) {
- ret = ripng_create();
-
- /* Notice to user we couldn't create RIPng. */
- if (ret < 0) {
- zlog_warn("can't create RIPng");
- return CMD_WARNING_CONFIG_FAILED;
- }
- }
-
- return CMD_SUCCESS;
-}
-
-DEFUN (no_router_ripng,
- no_router_ripng_cmd,
- "no router ripng",
- NO_STR
- "Enable a routing process\n"
- "Make RIPng instance command\n")
-{
- if (ripng)
- ripng_clean();
- return CMD_SUCCESS;
-}
-
-DEFUN (ripng_route,
- ripng_route_cmd,
- "route IPV6ADDR",
- "Static route setup\n"
- "Set static RIPng route announcement\n")
-{
- int idx_ipv6addr = 1;
- int ret;
- struct prefix_ipv6 p;
- struct agg_node *rp;
-
- ret = str2prefix_ipv6(argv[idx_ipv6addr]->arg,
- (struct prefix_ipv6 *)&p);
- if (ret <= 0) {
- vty_out(vty, "Malformed address\n");
- return CMD_WARNING_CONFIG_FAILED;
- }
- apply_mask_ipv6(&p);
-
- rp = agg_node_get(ripng->route, (struct prefix *)&p);
- if (rp->info) {
- vty_out(vty, "There is already same static route.\n");
- agg_unlock_node(rp);
- return CMD_WARNING;
- }
- rp->info = (void *)1;
-
- ripng_redistribute_add(ZEBRA_ROUTE_RIPNG, RIPNG_ROUTE_STATIC, &p, 0,
- NULL, 0);
-
- return CMD_SUCCESS;
-}
-
-DEFUN (no_ripng_route,
- no_ripng_route_cmd,
- "no route IPV6ADDR",
- NO_STR
- "Static route setup\n"
- "Delete static RIPng route announcement\n")
-{
- int idx_ipv6addr = 2;
- int ret;
- struct prefix_ipv6 p;
- struct agg_node *rp;
-
- ret = str2prefix_ipv6(argv[idx_ipv6addr]->arg,
- (struct prefix_ipv6 *)&p);
- if (ret <= 0) {
- vty_out(vty, "Malformed address\n");
- return CMD_WARNING_CONFIG_FAILED;
- }
- apply_mask_ipv6(&p);
-
- rp = agg_node_lookup(ripng->route, (struct prefix *)&p);
- if (!rp) {
- vty_out(vty, "Can't find static route.\n");
- return CMD_WARNING_CONFIG_FAILED;
- }
-
- ripng_redistribute_delete(ZEBRA_ROUTE_RIPNG, RIPNG_ROUTE_STATIC, &p, 0);
- agg_unlock_node(rp);
-
- rp->info = NULL;
- agg_unlock_node(rp);
-
- return CMD_SUCCESS;
-}
-
-DEFUN (ripng_aggregate_address,
- ripng_aggregate_address_cmd,
- "aggregate-address X:X::X:X/M",
- "Set aggregate RIPng route announcement\n"
- "Aggregate network\n")
-{
- int idx_ipv6_prefixlen = 1;
- int ret;
- struct prefix p;
- struct agg_node *node;
-
- ret = str2prefix_ipv6(argv[idx_ipv6_prefixlen]->arg,
- (struct prefix_ipv6 *)&p);
- if (ret <= 0) {
- vty_out(vty, "Malformed address\n");
- return CMD_WARNING_CONFIG_FAILED;
- }
-
- /* Check aggregate alredy exist or not. */
- node = agg_node_get(ripng->aggregate, &p);
- if (node->info) {
- vty_out(vty, "There is already same aggregate route.\n");
- agg_unlock_node(node);
- return CMD_WARNING;
- }
- node->info = (void *)1;
-
- ripng_aggregate_add(&p);
-
- return CMD_SUCCESS;
-}
-
-DEFUN (no_ripng_aggregate_address,
- no_ripng_aggregate_address_cmd,
- "no aggregate-address X:X::X:X/M",
- NO_STR
- "Delete aggregate RIPng route announcement\n"
- "Aggregate network\n")
-{
- int idx_ipv6_prefixlen = 2;
- int ret;
- struct prefix p;
- struct agg_node *rn;
-
- ret = str2prefix_ipv6(argv[idx_ipv6_prefixlen]->arg,
- (struct prefix_ipv6 *)&p);
- if (ret <= 0) {
- vty_out(vty, "Malformed address\n");
- return CMD_WARNING_CONFIG_FAILED;
- }
-
- rn = agg_node_lookup(ripng->aggregate, &p);
- if (!rn) {
- vty_out(vty, "Can't find aggregate route.\n");
- return CMD_WARNING_CONFIG_FAILED;
- }
- agg_unlock_node(rn);
- rn->info = NULL;
- agg_unlock_node(rn);
-
- ripng_aggregate_delete(&p);
-
- return CMD_SUCCESS;
-}
-
-DEFUN (ripng_default_metric,
- ripng_default_metric_cmd,
- "default-metric (1-16)",
- "Set a metric of redistribute routes\n"
- "Default metric\n")
-{
- int idx_number = 1;
- if (ripng) {
- ripng->default_metric = atoi(argv[idx_number]->arg);
- }
- return CMD_SUCCESS;
-}
-
-DEFUN (no_ripng_default_metric,
- no_ripng_default_metric_cmd,
- "no default-metric [(1-16)]",
- NO_STR
- "Set a metric of redistribute routes\n"
- "Default metric\n")
-{
- if (ripng) {
- ripng->default_metric = RIPNG_DEFAULT_METRIC_DEFAULT;
- }
- return CMD_SUCCESS;
-}
-
-
#if 0
/* RIPng update timer setup. */
DEFUN (ripng_update_timer,
}
#endif /* 0 */
-DEFUN (ripng_timers,
- ripng_timers_cmd,
- "timers basic (0-65535) (0-65535) (0-65535)",
- "RIPng timers setup\n"
- "Basic timer\n"
- "Routing table update timer value in second. Default is 30.\n"
- "Routing information timeout timer. Default is 180.\n"
- "Garbage collection timer. Default is 120.\n")
-{
- int idx_number = 2;
- int idx_number_2 = 3;
- int idx_number_3 = 4;
- unsigned long update;
- unsigned long timeout;
- unsigned long garbage;
-
- update = strtoul(argv[idx_number]->arg, NULL, 10);
- timeout = strtoul(argv[idx_number_2]->arg, NULL, 10);
- garbage = strtoul(argv[idx_number_3]->arg, NULL, 10);
-
- /* Set each timer value. */
- ripng->update_time = update;
- ripng->timeout_time = timeout;
- ripng->garbage_time = garbage;
-
- /* Reset update timer thread. */
- ripng_event(RIPNG_UPDATE_EVENT, 0);
-
- return CMD_SUCCESS;
-}
-
-DEFUN (no_ripng_timers,
- no_ripng_timers_cmd,
- "no timers basic [(0-65535) (0-65535) (0-65535)]",
- NO_STR
- "RIPng timers setup\n"
- "Basic timer\n"
- "Routing table update timer value in second. Default is 30.\n"
- "Routing information timeout timer. Default is 180.\n"
- "Garbage collection timer. Default is 120.\n")
-{
- /* Set each timer value to the default. */
- ripng->update_time = RIPNG_UPDATE_TIMER_DEFAULT;
- ripng->timeout_time = RIPNG_TIMEOUT_TIMER_DEFAULT;
- ripng->garbage_time = RIPNG_GARBAGE_TIMER_DEFAULT;
-
- /* Reset update timer thread. */
- ripng_event(RIPNG_UPDATE_EVENT, 0);
-
- return CMD_SUCCESS;
-}
-
#if 0
DEFUN (show_ipv6_protocols,
show_ipv6_protocols_cmd,
}
#endif
-/* Please be carefull to use this command. */
-DEFUN (ripng_default_information_originate,
- ripng_default_information_originate_cmd,
- "default-information originate",
- "Default route information\n"
- "Distribute default route\n")
-{
- struct prefix_ipv6 p;
-
- if (!ripng->default_information) {
- ripng->default_information = 1;
-
- str2prefix_ipv6("::/0", &p);
- ripng_redistribute_add(ZEBRA_ROUTE_RIPNG, RIPNG_ROUTE_DEFAULT,
- &p, 0, NULL, 0);
- }
-
- return CMD_SUCCESS;
-}
-
-DEFUN (no_ripng_default_information_originate,
- no_ripng_default_information_originate_cmd,
- "no default-information originate",
- NO_STR
- "Default route information\n"
- "Distribute default route\n")
-{
- struct prefix_ipv6 p;
-
- if (ripng->default_information) {
- ripng->default_information = 0;
-
- str2prefix_ipv6("::/0", &p);
- ripng_redistribute_delete(ZEBRA_ROUTE_RIPNG,
- RIPNG_ROUTE_DEFAULT, &p, 0);
- }
-
- return CMD_SUCCESS;
-}
-
/* Update ECMP routes to zebra when ECMP is disabled. */
-static void ripng_ecmp_disable(void)
+void ripng_ecmp_disable(void)
{
struct agg_node *rp;
struct ripng_info *rinfo, *tmp_rinfo;
}
}
-DEFUN (ripng_allow_ecmp,
- ripng_allow_ecmp_cmd,
- "allow-ecmp",
- "Allow Equal Cost MultiPath\n")
-{
- if (ripng->ecmp) {
- vty_out(vty, "ECMP is already enabled.\n");
- return CMD_WARNING;
- }
-
- ripng->ecmp = 1;
- zlog_info("ECMP is enabled.");
- return CMD_SUCCESS;
-}
-
-DEFUN (no_ripng_allow_ecmp,
- no_ripng_allow_ecmp_cmd,
- "no allow-ecmp",
- NO_STR
- "Allow Equal Cost MultiPath\n")
-{
- if (!ripng->ecmp) {
- vty_out(vty, "ECMP is already disabled.\n");
- return CMD_WARNING;
- }
-
- ripng->ecmp = 0;
- zlog_info("ECMP is disabled.");
- ripng_ecmp_disable();
- return CMD_SUCCESS;
-}
-
/* RIPng configuration write function. */
static int ripng_config_write(struct vty *vty)
{
- int ripng_network_write(struct vty *, int);
- void ripng_redistribute_write(struct vty *, int);
+ struct lyd_node *dnode;
int write = 0;
- struct agg_node *rp;
- if (ripng) {
+ dnode = yang_dnode_get(running_config->dnode,
+ "/frr-ripngd:ripngd/instance");
+ if (dnode) {
+ nb_cli_show_dnode_cmds(vty, dnode, false);
- /* RIPng router. */
- vty_out(vty, "router ripng\n");
-
- if (ripng->default_information)
- vty_out(vty, " default-information originate\n");
-
- ripng_network_write(vty, 1);
-
- /* RIPng default metric configuration */
- if (ripng->default_metric != RIPNG_DEFAULT_METRIC_DEFAULT)
- vty_out(vty, " default-metric %d\n",
- ripng->default_metric);
-
- ripng_redistribute_write(vty, 1);
-
- /* RIP offset-list configuration. */
- config_write_ripng_offset_list(vty);
-
- /* RIPng aggregate routes. */
- for (rp = agg_route_top(ripng->aggregate); rp;
- rp = agg_route_next(rp))
- if (rp->info != NULL)
- vty_out(vty, " aggregate-address %s/%d\n",
- inet6_ntoa(rp->p.u.prefix6),
- rp->p.prefixlen);
-
- /* ECMP configuration. */
- if (ripng->ecmp)
- vty_out(vty, " allow-ecmp\n");
-
- /* RIPng static routes. */
- for (rp = agg_route_top(ripng->route); rp;
- rp = agg_route_next(rp))
- if (rp->info != NULL)
- vty_out(vty, " route %s/%d\n",
- inet6_ntoa(rp->p.u.prefix6),
- rp->p.prefixlen);
-
- /* RIPng timers configuration. */
- if (ripng->update_time != RIPNG_UPDATE_TIMER_DEFAULT
- || ripng->timeout_time != RIPNG_TIMEOUT_TIMER_DEFAULT
- || ripng->garbage_time != RIPNG_GARBAGE_TIMER_DEFAULT) {
- vty_out(vty, " timers basic %ld %ld %ld\n",
- ripng->update_time, ripng->timeout_time,
- ripng->garbage_time);
- }
-#if 0
- if (ripng->update_time != RIPNG_UPDATE_TIMER_DEFAULT)
- vty_out (vty, " update-timer %d\n", ripng->update_time);
- if (ripng->timeout_time != RIPNG_TIMEOUT_TIMER_DEFAULT)
- vty_out (vty, " timeout-timer %d\n", ripng->timeout_time);
- if (ripng->garbage_time != RIPNG_GARBAGE_TIMER_DEFAULT)
- vty_out (vty, " garbage-timer %d\n", ripng->garbage_time);
-#endif /* 0 */
+ config_write_distribute(vty);
- write += config_write_distribute(vty);
+ config_write_if_rmap(vty);
- write += config_write_if_rmap(vty);
-
- write++;
+ write = 1;
}
+
return write;
}
rinfo->t_garbage_collect);
ripng_info_free(rinfo);
}
- list_delete_and_null(&list);
+ list_delete(&list);
rp->info = NULL;
agg_unlock_node(rp);
}
ripng->sock = -1;
}
- /* Static RIPng route configuration. */
- for (rp = agg_route_top(ripng->route); rp;
- rp = agg_route_next(rp))
- if (rp->info) {
- rp->info = NULL;
- agg_unlock_node(rp);
- }
-
- /* RIPng aggregated prefixes */
- for (rp = agg_route_top(ripng->aggregate); rp;
- rp = agg_route_next(rp))
- if (rp->info) {
- rp->info = NULL;
- agg_unlock_node(rp);
- }
-
for (i = 0; i < ZEBRA_ROUTE_MAX; i++)
if (ripng->route_map[i].name)
free(ripng->route_map[i].name);
- XFREE(MTYPE_ROUTE_TABLE, ripng->table);
- XFREE(MTYPE_ROUTE_TABLE, ripng->route);
- XFREE(MTYPE_ROUTE_TABLE, ripng->aggregate);
+ agg_table_finish(ripng->table);
stream_free(ripng->ibuf);
stream_free(ripng->obuf);
ripng_redistribute_clean();
}
-/* Reset all values to the default settings. */
-void ripng_reset()
-{
- /* Call ripd related reset functions. */
- ripng_debug_reset();
- ripng_route_map_reset();
-
- /* Call library reset functions. */
- vty_reset();
- access_list_reset();
- prefix_list_reset();
-
- distribute_list_reset();
-
- ripng_interface_reset();
-
- ripng_zclient_reset();
-}
-
static void ripng_if_rmap_update(struct if_rmap *if_rmap)
{
struct interface *ifp;
install_element(VIEW_NODE, &show_ipv6_ripng_cmd);
install_element(VIEW_NODE, &show_ipv6_ripng_status_cmd);
- install_element(ENABLE_NODE, &clear_ipv6_rip_cmd);
-
- install_element(CONFIG_NODE, &router_ripng_cmd);
- install_element(CONFIG_NODE, &no_router_ripng_cmd);
-
install_default(RIPNG_NODE);
- install_element(RIPNG_NODE, &ripng_route_cmd);
- install_element(RIPNG_NODE, &no_ripng_route_cmd);
- install_element(RIPNG_NODE, &ripng_aggregate_address_cmd);
- install_element(RIPNG_NODE, &no_ripng_aggregate_address_cmd);
-
- install_element(RIPNG_NODE, &ripng_default_metric_cmd);
- install_element(RIPNG_NODE, &no_ripng_default_metric_cmd);
- install_element(RIPNG_NODE, &ripng_timers_cmd);
- install_element(RIPNG_NODE, &no_ripng_timers_cmd);
#if 0
install_element (VIEW_NODE, &show_ipv6_protocols_cmd);
install_element (RIPNG_NODE, &ripng_update_timer_cmd);
install_element (RIPNG_NODE, &no_ripng_garbage_timer_cmd);
#endif /* 0 */
- install_element(RIPNG_NODE, &ripng_default_information_originate_cmd);
- install_element(RIPNG_NODE,
- &no_ripng_default_information_originate_cmd);
-
- install_element(RIPNG_NODE, &ripng_allow_ecmp_cmd);
- install_element(RIPNG_NODE, &no_ripng_allow_ecmp_cmd);
-
ripng_if_init();
ripng_debug_init();