2 * Copyright (C) 1997, 1998, 1999 Kunihiro Ishiguro <kunihiro@zebra.org>
3 * Copyright (C) 2018 NetDEF, Inc.
6 * This program is free software; you can redistribute it and/or modify it
7 * under the terms of the GNU General Public License as published by the Free
8 * Software Foundation; either version 2 of the License, or (at your option)
11 * This program is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
16 * You should have received a copy of the GNU General Public License along
17 * with this program; see the file COPYING; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
28 #include "northbound_cli.h"
31 #include "ripd/ripd.h"
32 #include "ripd/rip_cli.h"
33 #ifndef VTYSH_EXTRACT_PL
34 #include "ripd/rip_cli_clippy.c"
38 * XPath: /frr-ripd:ripd/instance
40 DEFPY_NOSH (router_rip
,
43 "Enable a routing process\n"
44 "Routing Information Protocol (RIP)\n")
48 struct cli_config_change changes
[] = {
50 .xpath
= "/frr-ripd:ripd/instance",
51 .operation
= NB_OP_CREATE
,
56 ret
= nb_cli_cfg_change(vty
, NULL
, changes
, array_size(changes
));
57 if (ret
== CMD_SUCCESS
)
58 VTY_PUSH_XPATH(RIP_NODE
, changes
[0].xpath
);
67 "Enable a routing process\n"
68 "Routing Information Protocol (RIP)\n")
70 struct cli_config_change changes
[] = {
72 .xpath
= "/frr-ripd:ripd/instance",
73 .operation
= NB_OP_DELETE
,
78 return nb_cli_cfg_change(vty
, NULL
, changes
, array_size(changes
));
81 void cli_show_router_rip(struct vty
*vty
, struct lyd_node
*dnode
,
85 vty_out(vty
, "router rip\n");
89 * XPath: /frr-ripd:ripd/instance/allow-ecmp
91 DEFPY (rip_allow_ecmp
,
95 "Allow Equal Cost MultiPath\n")
97 struct cli_config_change changes
[] = {
99 .xpath
= "./allow-ecmp",
100 .operation
= NB_OP_MODIFY
,
101 .value
= no
? "false" : "true",
105 return nb_cli_cfg_change(vty
, NULL
, changes
, array_size(changes
));
108 void cli_show_rip_allow_ecmp(struct vty
*vty
, struct lyd_node
*dnode
,
111 if (!yang_dnode_get_bool(dnode
, NULL
))
114 vty_out(vty
, " allow-ecmp\n");
118 * XPath: /frr-ripd:ripd/instance/default-information-originate
120 DEFPY (rip_default_information_originate
,
121 rip_default_information_originate_cmd
,
122 "[no] default-information originate",
124 "Control distribution of default route\n"
125 "Distribute a default route\n")
127 struct cli_config_change changes
[] = {
129 .xpath
= "./default-information-originate",
130 .operation
= NB_OP_MODIFY
,
131 .value
= no
? "false" : "true",
135 return nb_cli_cfg_change(vty
, NULL
, changes
, array_size(changes
));
138 void cli_show_rip_default_information_originate(struct vty
*vty
,
139 struct lyd_node
*dnode
,
142 if (!yang_dnode_get_bool(dnode
, NULL
))
145 vty_out(vty
, " default-information originate\n");
149 * XPath: /frr-ripd:ripd/instance/default-metric
151 DEFPY (rip_default_metric
,
152 rip_default_metric_cmd
,
153 "default-metric (1-16)",
154 "Set a metric of redistribute routes\n"
157 struct cli_config_change changes
[] = {
159 .xpath
= "./default-metric",
160 .operation
= NB_OP_MODIFY
,
161 .value
= default_metric_str
,
165 return nb_cli_cfg_change(vty
, NULL
, changes
, array_size(changes
));
168 DEFPY (no_rip_default_metric
,
169 no_rip_default_metric_cmd
,
170 "no default-metric [(1-16)]",
172 "Set a metric of redistribute routes\n"
175 struct cli_config_change changes
[] = {
177 .xpath
= "./default-metric",
178 .operation
= NB_OP_MODIFY
,
183 return nb_cli_cfg_change(vty
, NULL
, changes
, array_size(changes
));
186 void cli_show_rip_default_metric(struct vty
*vty
, struct lyd_node
*dnode
,
189 vty_out(vty
, " default-metric %s\n",
190 yang_dnode_get_string(dnode
, NULL
));
194 * XPath: /frr-ripd:ripd/instance/distance/default
199 "Administrative distance\n"
202 struct cli_config_change changes
[] = {
204 .xpath
= "./distance/default",
205 .operation
= NB_OP_MODIFY
,
206 .value
= distance_str
,
210 return nb_cli_cfg_change(vty
, NULL
, changes
, array_size(changes
));
213 DEFPY (no_rip_distance
,
215 "no distance [(1-255)]",
217 "Administrative distance\n"
220 struct cli_config_change changes
[] = {
222 .xpath
= "./distance/default",
223 .operation
= NB_OP_MODIFY
,
228 return nb_cli_cfg_change(vty
, NULL
, changes
, array_size(changes
));
231 void cli_show_rip_distance(struct vty
*vty
, struct lyd_node
*dnode
,
234 vty_out(vty
, " distance %s\n", yang_dnode_get_string(dnode
, NULL
));
238 * XPath: /frr-ripd:ripd/instance/distance/source
240 DEFPY (rip_distance_source
,
241 rip_distance_source_cmd
,
242 "distance (1-255) A.B.C.D/M$prefix [WORD$acl]",
243 "Administrative distance\n"
246 "Access list name\n")
248 char xpath_list
[XPATH_MAXLEN
];
249 struct cli_config_change changes
[] = {
252 .operation
= NB_OP_CREATE
,
255 .xpath
= "./distance",
256 .operation
= NB_OP_MODIFY
,
257 .value
= distance_str
,
260 .xpath
= "./access-list",
261 .operation
= acl
? NB_OP_MODIFY
: NB_OP_DELETE
,
266 snprintf(xpath_list
, sizeof(xpath_list
),
267 "./distance/source[prefix='%s']", prefix_str
);
269 return nb_cli_cfg_change(vty
, xpath_list
, changes
, array_size(changes
));
272 DEFPY (no_rip_distance_source
,
273 no_rip_distance_source_cmd
,
274 "no distance (1-255) A.B.C.D/M$prefix [WORD$acl]",
276 "Administrative distance\n"
279 "Access list name\n")
281 char xpath_list
[XPATH_MAXLEN
];
282 struct cli_config_change changes
[] = {
285 .operation
= NB_OP_DELETE
,
289 snprintf(xpath_list
, sizeof(xpath_list
),
290 "./distance/source[prefix='%s']", prefix_str
);
292 return nb_cli_cfg_change(vty
, xpath_list
, changes
, 1);
295 void cli_show_rip_distance_source(struct vty
*vty
, struct lyd_node
*dnode
,
298 vty_out(vty
, " distance %s %s",
299 yang_dnode_get_string(dnode
, "./distance"),
300 yang_dnode_get_string(dnode
, "./prefix"));
301 if (yang_dnode_exists(dnode
, "./access-list"))
303 yang_dnode_get_string(dnode
, "./access-list"));
308 * XPath: /frr-ripd:ripd/instance/explicit-neighbor
312 "[no] neighbor A.B.C.D",
314 "Specify a neighbor router\n"
315 "Neighbor address\n")
317 struct cli_config_change changes
[] = {
319 .xpath
= "./explicit-neighbor",
320 .operation
= no
? NB_OP_DELETE
: NB_OP_CREATE
,
321 .value
= neighbor_str
,
325 return nb_cli_cfg_change(vty
, NULL
, changes
, array_size(changes
));
328 void cli_show_rip_neighbor(struct vty
*vty
, struct lyd_node
*dnode
,
331 vty_out(vty
, " neighbor %s\n", yang_dnode_get_string(dnode
, NULL
));
335 * XPath: /frr-ripd:ripd/instance/network
337 DEFPY (rip_network_prefix
,
338 rip_network_prefix_cmd
,
339 "[no] network A.B.C.D/M",
341 "Enable routing on an IP network\n"
342 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
344 struct cli_config_change changes
[] = {
346 .xpath
= "./network",
347 .operation
= no
? NB_OP_DELETE
: NB_OP_CREATE
,
348 .value
= network_str
,
352 return nb_cli_cfg_change(vty
, NULL
, changes
, array_size(changes
));
355 void cli_show_rip_network_prefix(struct vty
*vty
, struct lyd_node
*dnode
,
358 vty_out(vty
, " network %s\n", yang_dnode_get_string(dnode
, NULL
));
362 * XPath: /frr-ripd:ripd/instance/interface
364 DEFPY (rip_network_if
,
368 "Enable routing on an IP network\n"
371 struct cli_config_change changes
[] = {
373 .xpath
= "./interface",
374 .operation
= no
? NB_OP_DELETE
: NB_OP_CREATE
,
379 return nb_cli_cfg_change(vty
, NULL
, changes
, array_size(changes
));
382 void cli_show_rip_network_interface(struct vty
*vty
, struct lyd_node
*dnode
,
385 vty_out(vty
, " network %s\n", yang_dnode_get_string(dnode
, NULL
));
389 * XPath: /frr-ripd:ripd/instance/offset-list
391 DEFPY (rip_offset_list
,
393 "offset-list WORD$acl <in|out>$direction (0-16)$metric [IFNAME]",
394 "Modify RIP metric\n"
396 "For incoming updates\n"
397 "For outgoing updates\n"
399 "Interface to match\n")
401 char xpath_list
[XPATH_MAXLEN
];
402 struct cli_config_change changes
[] = {
405 .operation
= NB_OP_CREATE
,
408 .xpath
= "./access-list",
409 .operation
= NB_OP_MODIFY
,
414 .operation
= NB_OP_MODIFY
,
419 snprintf(xpath_list
, sizeof(xpath_list
),
420 "./offset-list[interface='%s'][direction='%s']",
421 ifname
? ifname
: "*", direction
);
423 return nb_cli_cfg_change(vty
, xpath_list
, changes
, array_size(changes
));
426 DEFPY (no_rip_offset_list
,
427 no_rip_offset_list_cmd
,
428 "no offset-list WORD$acl <in|out>$direction (0-16)$metric [IFNAME]",
430 "Modify RIP metric\n"
432 "For incoming updates\n"
433 "For outgoing updates\n"
435 "Interface to match\n")
437 char xpath_list
[XPATH_MAXLEN
];
438 struct cli_config_change changes
[] = {
441 .operation
= NB_OP_DELETE
,
445 snprintf(xpath_list
, sizeof(xpath_list
),
446 "./offset-list[interface='%s'][direction='%s']",
447 ifname
? ifname
: "*", direction
);
449 return nb_cli_cfg_change(vty
, xpath_list
, changes
, array_size(changes
));
452 void cli_show_rip_offset_list(struct vty
*vty
, struct lyd_node
*dnode
,
455 const char *interface
;
457 interface
= yang_dnode_get_string(dnode
, "./interface");
459 vty_out(vty
, " offset-list %s %s %s",
460 yang_dnode_get_string(dnode
, "./access-list"),
461 yang_dnode_get_string(dnode
, "./direction"),
462 yang_dnode_get_string(dnode
, "./metric"));
463 if (!strmatch(interface
, "*"))
464 vty_out(vty
, " %s", interface
);
468 void rip_cli_init(void)
470 install_element(CONFIG_NODE
, &router_rip_cmd
);
471 install_element(CONFIG_NODE
, &no_router_rip_cmd
);
473 install_element(RIP_NODE
, &rip_allow_ecmp_cmd
);
474 install_element(RIP_NODE
, &rip_default_information_originate_cmd
);
475 install_element(RIP_NODE
, &rip_default_metric_cmd
);
476 install_element(RIP_NODE
, &no_rip_default_metric_cmd
);
477 install_element(RIP_NODE
, &rip_distance_cmd
);
478 install_element(RIP_NODE
, &no_rip_distance_cmd
);
479 install_element(RIP_NODE
, &rip_distance_source_cmd
);
480 install_element(RIP_NODE
, &no_rip_distance_source_cmd
);
481 install_element(RIP_NODE
, &rip_neighbor_cmd
);
482 install_element(RIP_NODE
, &rip_network_prefix_cmd
);
483 install_element(RIP_NODE
, &rip_network_if_cmd
);
484 install_element(RIP_NODE
, &rip_offset_list_cmd
);
485 install_element(RIP_NODE
, &no_rip_offset_list_cmd
);