summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ripd/rip_cli.c56
-rw-r--r--ripd/rip_cli.h5
-rw-r--r--ripd/rip_interface.c85
-rw-r--r--ripd/rip_northbound.c42
-rw-r--r--ripd/ripd.c3
-rw-r--r--ripd/ripd.h5
6 files changed, 113 insertions, 83 deletions
diff --git a/ripd/rip_cli.c b/ripd/rip_cli.c
index 1d94d02bd7..a22f3054a6 100644
--- a/ripd/rip_cli.c
+++ b/ripd/rip_cli.c
@@ -331,6 +331,60 @@ void cli_show_rip_neighbor(struct vty *vty, struct lyd_node *dnode,
vty_out(vty, " neighbor %s\n", yang_dnode_get_string(dnode, NULL));
}
+/*
+ * XPath: /frr-ripd:ripd/instance/network
+ */
+DEFPY (rip_network_prefix,
+ rip_network_prefix_cmd,
+ "[no] network A.B.C.D/M",
+ NO_STR
+ "Enable routing on an IP network\n"
+ "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
+{
+ struct cli_config_change changes[] = {
+ {
+ .xpath = "./network",
+ .operation = no ? NB_OP_DELETE : NB_OP_CREATE,
+ .value = network_str,
+ },
+ };
+
+ return nb_cli_cfg_change(vty, NULL, changes, array_size(changes));
+}
+
+void cli_show_rip_network_prefix(struct vty *vty, struct lyd_node *dnode,
+ bool show_defaults)
+{
+ vty_out(vty, " network %s\n", yang_dnode_get_string(dnode, NULL));
+}
+
+/*
+ * XPath: /frr-ripd:ripd/instance/interface
+ */
+DEFPY (rip_network_if,
+ rip_network_if_cmd,
+ "[no] network WORD",
+ NO_STR
+ "Enable routing on an IP network\n"
+ "Interface name\n")
+{
+ struct cli_config_change changes[] = {
+ {
+ .xpath = "./interface",
+ .operation = no ? NB_OP_DELETE : NB_OP_CREATE,
+ .value = network,
+ },
+ };
+
+ return nb_cli_cfg_change(vty, NULL, changes, array_size(changes));
+}
+
+void cli_show_rip_network_interface(struct vty *vty, struct lyd_node *dnode,
+ bool show_defaults)
+{
+ vty_out(vty, " network %s\n", yang_dnode_get_string(dnode, NULL));
+}
+
void rip_cli_init(void)
{
install_element(CONFIG_NODE, &router_rip_cmd);
@@ -345,4 +399,6 @@ void rip_cli_init(void)
install_element(RIP_NODE, &rip_distance_source_cmd);
install_element(RIP_NODE, &no_rip_distance_source_cmd);
install_element(RIP_NODE, &rip_neighbor_cmd);
+ install_element(RIP_NODE, &rip_network_prefix_cmd);
+ install_element(RIP_NODE, &rip_network_if_cmd);
}
diff --git a/ripd/rip_cli.h b/ripd/rip_cli.h
index 34cbd646fb..2a05405924 100644
--- a/ripd/rip_cli.h
+++ b/ripd/rip_cli.h
@@ -37,5 +37,10 @@ extern void cli_show_rip_distance_source(struct vty *vty,
bool show_defaults);
extern void cli_show_rip_neighbor(struct vty *vty, struct lyd_node *dnode,
bool show_defaults);
+extern void cli_show_rip_network_prefix(struct vty *vty, struct lyd_node *dnode,
+ bool show_defaults);
+extern void cli_show_rip_network_interface(struct vty *vty,
+ struct lyd_node *dnode,
+ bool show_defaults);
#endif /* _FRR_RIP_CLI_H_ */
diff --git a/ripd/rip_interface.c b/ripd/rip_interface.c
index 4373484a29..1e79e6d275 100644
--- a/ripd/rip_interface.c
+++ b/ripd/rip_interface.c
@@ -762,7 +762,7 @@ int rip_enable_network_lookup2(struct connected *connected)
return -1;
}
/* Add RIP enable network. */
-static int rip_enable_network_add(struct prefix *p)
+int rip_enable_network_add(struct prefix *p)
{
struct route_node *node;
@@ -770,18 +770,18 @@ static int rip_enable_network_add(struct prefix *p)
if (node->info) {
route_unlock_node(node);
- return -1;
+ return NB_ERR_INCONSISTENCY;
} else
node->info = (void *)1;
/* XXX: One should find a better solution than a generic one */
rip_enable_apply_all();
- return 1;
+ return NB_OK;
}
/* Delete RIP enable network. */
-static int rip_enable_network_delete(struct prefix *p)
+int rip_enable_network_delete(struct prefix *p)
{
struct route_node *node;
@@ -798,9 +798,10 @@ static int rip_enable_network_delete(struct prefix *p)
/* XXX: One should find a better solution than a generic one */
rip_enable_apply_all();
- return 1;
+ return NB_OK;
}
- return -1;
+
+ return NB_ERR_INCONSISTENCY;
}
/* Check interface is enabled by ifname statement. */
@@ -817,31 +818,31 @@ static int rip_enable_if_lookup(const char *ifname)
}
/* Add interface to rip_enable_if. */
-static int rip_enable_if_add(const char *ifname)
+int rip_enable_if_add(const char *ifname)
{
int ret;
ret = rip_enable_if_lookup(ifname);
if (ret >= 0)
- return -1;
+ return NB_ERR_INCONSISTENCY;
vector_set(rip_enable_interface,
XSTRDUP(MTYPE_RIP_INTERFACE_STRING, ifname));
rip_enable_apply_all(); /* TODOVJ */
- return 1;
+ return NB_OK;
}
/* Delete interface from rip_enable_if. */
-static int rip_enable_if_delete(const char *ifname)
+int rip_enable_if_delete(const char *ifname)
{
int index;
char *str;
index = rip_enable_if_lookup(ifname);
if (index < 0)
- return -1;
+ return NB_ERR_INCONSISTENCY;
str = vector_slot(rip_enable_interface, index);
XFREE(MTYPE_RIP_INTERFACE_STRING, str);
@@ -849,7 +850,7 @@ static int rip_enable_if_delete(const char *ifname)
rip_enable_apply_all(); /* TODOVJ */
- return 1;
+ return NB_OK;
}
/* Join to multicast group and send request to the interface. */
@@ -1152,63 +1153,6 @@ void rip_passive_nondefault_clean(void)
rip_passive_interface_apply_all();
}
-/* RIP enable network or interface configuration. */
-DEFUN (rip_network,
- rip_network_cmd,
- "network <A.B.C.D/M|WORD>",
- "Enable routing on an IP network\n"
- "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
- "Interface name\n")
-{
- int idx_ipv4_word = 1;
- int ret;
- struct prefix_ipv4 p;
-
- ret = str2prefix_ipv4(argv[idx_ipv4_word]->arg, &p);
-
- if (ret)
- ret = rip_enable_network_add((struct prefix *)&p);
- else
- ret = rip_enable_if_add(argv[idx_ipv4_word]->arg);
-
- if (ret < 0) {
- vty_out(vty, "There is a same network configuration %s\n",
- argv[idx_ipv4_word]->arg);
- return CMD_WARNING_CONFIG_FAILED;
- }
-
- return CMD_SUCCESS;
-}
-
-/* RIP enable network or interface configuration. */
-DEFUN (no_rip_network,
- no_rip_network_cmd,
- "no network <A.B.C.D/M|WORD>",
- NO_STR
- "Enable routing on an IP network\n"
- "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
- "Interface name\n")
-{
- int idx_ipv4_word = 2;
- int ret;
- struct prefix_ipv4 p;
-
- ret = str2prefix_ipv4(argv[idx_ipv4_word]->arg, &p);
-
- if (ret)
- ret = rip_enable_network_delete((struct prefix *)&p);
- else
- ret = rip_enable_if_delete(argv[idx_ipv4_word]->arg);
-
- if (ret < 0) {
- vty_out(vty, "Can't find network configuration %s\n",
- argv[idx_ipv4_word]->arg);
- return CMD_WARNING_CONFIG_FAILED;
- }
-
- return CMD_SUCCESS;
-}
-
DEFUN (ip_rip_receive_version,
ip_rip_receive_version_cmd,
"ip rip receive version <(1-2)|none>",
@@ -1848,9 +1792,6 @@ void rip_if_init(void)
if_cmd_init();
/* Install commands. */
- install_element(RIP_NODE, &rip_network_cmd);
- install_element(RIP_NODE, &no_rip_network_cmd);
-
install_element(RIP_NODE, &rip_passive_interface_cmd);
install_element(RIP_NODE, &no_rip_passive_interface_cmd);
diff --git a/ripd/rip_northbound.c b/ripd/rip_northbound.c
index fdb19a3c14..498aa322cb 100644
--- a/ripd/rip_northbound.c
+++ b/ripd/rip_northbound.c
@@ -310,15 +310,27 @@ static int ripd_instance_network_create(enum nb_event event,
const struct lyd_node *dnode,
union nb_resource *resource)
{
- /* TODO: implement me. */
- return NB_OK;
+ struct prefix p;
+
+ if (event != NB_EV_APPLY)
+ return NB_OK;
+
+ yang_dnode_get_ipv4p(&p, dnode, NULL);
+
+ return rip_enable_network_add(&p);
}
static int ripd_instance_network_delete(enum nb_event event,
const struct lyd_node *dnode)
{
- /* TODO: implement me. */
- return NB_OK;
+ struct prefix p;
+
+ if (event != NB_EV_APPLY)
+ return NB_OK;
+
+ yang_dnode_get_ipv4p(&p, dnode, NULL);
+
+ return rip_enable_network_delete(&p);
}
/*
@@ -328,15 +340,27 @@ static int ripd_instance_interface_create(enum nb_event event,
const struct lyd_node *dnode,
union nb_resource *resource)
{
- /* TODO: implement me. */
- return NB_OK;
+ const char *ifname;
+
+ if (event != NB_EV_APPLY)
+ return NB_OK;
+
+ ifname = yang_dnode_get_string(dnode, NULL);
+
+ return rip_enable_if_add(ifname);
}
static int ripd_instance_interface_delete(enum nb_event event,
const struct lyd_node *dnode)
{
- /* TODO: implement me. */
- return NB_OK;
+ const char *ifname;
+
+ if (event != NB_EV_APPLY)
+ return NB_OK;
+
+ ifname = yang_dnode_get_string(dnode, NULL);
+
+ return rip_enable_if_delete(ifname);
}
/*
@@ -880,11 +904,13 @@ const struct frr_yang_module_info frr_ripd_info = {
.xpath = "/frr-ripd:ripd/instance/network",
.cbs.create = ripd_instance_network_create,
.cbs.delete = ripd_instance_network_delete,
+ .cbs.cli_show = cli_show_rip_network_prefix,
},
{
.xpath = "/frr-ripd:ripd/instance/interface",
.cbs.create = ripd_instance_interface_create,
.cbs.delete = ripd_instance_interface_delete,
+ .cbs.cli_show = cli_show_rip_network_interface,
},
{
.xpath = "/frr-ripd:ripd/instance/offset-list",
diff --git a/ripd/ripd.c b/ripd/ripd.c
index 4dbb47ebd2..027ad878bb 100644
--- a/ripd/ripd.c
+++ b/ripd/ripd.c
@@ -3415,9 +3415,6 @@ static int config_write_rip(struct vty *vty)
/* RIP offset-list configuration. */
config_write_rip_offset_list(vty);
- /* RIP enabled network and interface configuration. */
- config_write_rip_network(vty, 1);
-
/* Distribute configuration. */
write += config_write_distribute(vty);
diff --git a/ripd/ripd.h b/ripd/ripd.h
index fd8762904f..9bd9f53f22 100644
--- a/ripd/ripd.h
+++ b/ripd/ripd.h
@@ -392,6 +392,11 @@ extern int rip_neighbor_lookup(struct sockaddr_in *);
extern int rip_neighbor_add(struct prefix_ipv4 *p);
extern int rip_neighbor_delete(struct prefix_ipv4 *p);
+extern int rip_enable_network_add(struct prefix *p);
+extern int rip_enable_network_delete(struct prefix *p);
+extern int rip_enable_if_add(const char *ifname);
+extern int rip_enable_if_delete(const char *ifname);
+
extern void rip_ecmp_disable(void);
extern int rip_create_socket(void);