]> git.proxmox.com Git - mirror_frr.git/blob - ripd/rip_cli.c
Merge pull request #3397 from mjstapp/fix_stream_macros
[mirror_frr.git] / ripd / rip_cli.c
1 /*
2 * Copyright (C) 1997, 1998, 1999 Kunihiro Ishiguro <kunihiro@zebra.org>
3 * Copyright (C) 2018 NetDEF, Inc.
4 * Renato Westphal
5 *
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)
9 * any later version.
10 *
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
14 * more details.
15 *
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
19 */
20
21 #include <zebra.h>
22
23 #include "if.h"
24 #include "vrf.h"
25 #include "log.h"
26 #include "prefix.h"
27 #include "command.h"
28 #include "northbound_cli.h"
29 #include "libfrr.h"
30
31 #include "ripd/ripd.h"
32 #include "ripd/rip_cli.h"
33 #ifndef VTYSH_EXTRACT_PL
34 #include "ripd/rip_cli_clippy.c"
35 #endif
36
37 /*
38 * XPath: /frr-ripd:ripd/instance
39 */
40 DEFPY_NOSH (router_rip,
41 router_rip_cmd,
42 "router rip",
43 "Enable a routing process\n"
44 "Routing Information Protocol (RIP)\n")
45 {
46 int ret;
47
48 nb_cli_enqueue_change(vty, "/frr-ripd:ripd/instance", NB_OP_CREATE,
49 NULL);
50
51 ret = nb_cli_apply_changes(vty, NULL);
52 if (ret == CMD_SUCCESS)
53 VTY_PUSH_XPATH(RIP_NODE, "/frr-ripd:ripd/instance");
54
55 return ret;
56 }
57
58 DEFPY (no_router_rip,
59 no_router_rip_cmd,
60 "no router rip",
61 NO_STR
62 "Enable a routing process\n"
63 "Routing Information Protocol (RIP)\n")
64 {
65 nb_cli_enqueue_change(vty, "/frr-ripd:ripd/instance", NB_OP_DELETE,
66 NULL);
67
68 return nb_cli_apply_changes(vty, NULL);
69 }
70
71 void cli_show_router_rip(struct vty *vty, struct lyd_node *dnode,
72 bool show_defaults)
73 {
74 vty_out(vty, "!\n");
75 vty_out(vty, "router rip\n");
76 }
77
78 /*
79 * XPath: /frr-ripd:ripd/instance/allow-ecmp
80 */
81 DEFPY (rip_allow_ecmp,
82 rip_allow_ecmp_cmd,
83 "[no] allow-ecmp",
84 NO_STR
85 "Allow Equal Cost MultiPath\n")
86 {
87 nb_cli_enqueue_change(vty, "./allow-ecmp", NB_OP_MODIFY,
88 no ? "false" : "true");
89
90 return nb_cli_apply_changes(vty, NULL);
91 }
92
93 void cli_show_rip_allow_ecmp(struct vty *vty, struct lyd_node *dnode,
94 bool show_defaults)
95 {
96 if (!yang_dnode_get_bool(dnode, NULL))
97 vty_out(vty, " no");
98
99 vty_out(vty, " allow-ecmp\n");
100 }
101
102 /*
103 * XPath: /frr-ripd:ripd/instance/default-information-originate
104 */
105 DEFPY (rip_default_information_originate,
106 rip_default_information_originate_cmd,
107 "[no] default-information originate",
108 NO_STR
109 "Control distribution of default route\n"
110 "Distribute a default route\n")
111 {
112 nb_cli_enqueue_change(vty, "./default-information-originate",
113 NB_OP_MODIFY, no ? "false" : "true");
114
115 return nb_cli_apply_changes(vty, NULL);
116 }
117
118 void cli_show_rip_default_information_originate(struct vty *vty,
119 struct lyd_node *dnode,
120 bool show_defaults)
121 {
122 if (!yang_dnode_get_bool(dnode, NULL))
123 vty_out(vty, " no");
124
125 vty_out(vty, " default-information originate\n");
126 }
127
128 /*
129 * XPath: /frr-ripd:ripd/instance/default-metric
130 */
131 DEFPY (rip_default_metric,
132 rip_default_metric_cmd,
133 "default-metric (1-16)",
134 "Set a metric of redistribute routes\n"
135 "Default metric\n")
136 {
137 nb_cli_enqueue_change(vty, "./default-metric", NB_OP_MODIFY,
138 default_metric_str);
139
140 return nb_cli_apply_changes(vty, NULL);
141 }
142
143 DEFPY (no_rip_default_metric,
144 no_rip_default_metric_cmd,
145 "no default-metric [(1-16)]",
146 NO_STR
147 "Set a metric of redistribute routes\n"
148 "Default metric\n")
149 {
150 nb_cli_enqueue_change(vty, "./default-metric", NB_OP_MODIFY, NULL);
151
152 return nb_cli_apply_changes(vty, NULL);
153 }
154
155 void cli_show_rip_default_metric(struct vty *vty, struct lyd_node *dnode,
156 bool show_defaults)
157 {
158 vty_out(vty, " default-metric %s\n",
159 yang_dnode_get_string(dnode, NULL));
160 }
161
162 /*
163 * XPath: /frr-ripd:ripd/instance/distance/default
164 */
165 DEFPY (rip_distance,
166 rip_distance_cmd,
167 "distance (1-255)",
168 "Administrative distance\n"
169 "Distance value\n")
170 {
171 nb_cli_enqueue_change(vty, "./distance/default", NB_OP_MODIFY,
172 distance_str);
173
174 return nb_cli_apply_changes(vty, NULL);
175 }
176
177 DEFPY (no_rip_distance,
178 no_rip_distance_cmd,
179 "no distance [(1-255)]",
180 NO_STR
181 "Administrative distance\n"
182 "Distance value\n")
183 {
184 nb_cli_enqueue_change(vty, "./distance/default", NB_OP_MODIFY, NULL);
185
186 return nb_cli_apply_changes(vty, NULL);
187 }
188
189 void cli_show_rip_distance(struct vty *vty, struct lyd_node *dnode,
190 bool show_defaults)
191 {
192 if (yang_dnode_is_default(dnode, NULL))
193 vty_out(vty, " no distance\n");
194 else
195 vty_out(vty, " distance %s\n",
196 yang_dnode_get_string(dnode, NULL));
197 }
198
199 /*
200 * XPath: /frr-ripd:ripd/instance/distance/source
201 */
202 DEFPY (rip_distance_source,
203 rip_distance_source_cmd,
204 "[no] distance (1-255) A.B.C.D/M$prefix [WORD$acl]",
205 NO_STR
206 "Administrative distance\n"
207 "Distance value\n"
208 "IP source prefix\n"
209 "Access list name\n")
210 {
211 if (!no) {
212 nb_cli_enqueue_change(vty, ".", NB_OP_CREATE, NULL);
213 nb_cli_enqueue_change(vty, "./distance", NB_OP_MODIFY, NULL);
214 nb_cli_enqueue_change(vty, "./access-list",
215 acl ? NB_OP_MODIFY : NB_OP_DELETE, acl);
216 } else
217 nb_cli_enqueue_change(vty, ".", NB_OP_DELETE, NULL);
218
219 return nb_cli_apply_changes(vty, "./distance/source[prefix='%s']",
220 prefix_str);
221 }
222
223 void cli_show_rip_distance_source(struct vty *vty, struct lyd_node *dnode,
224 bool show_defaults)
225 {
226 vty_out(vty, " distance %s %s",
227 yang_dnode_get_string(dnode, "./distance"),
228 yang_dnode_get_string(dnode, "./prefix"));
229 if (yang_dnode_exists(dnode, "./access-list"))
230 vty_out(vty, " %s",
231 yang_dnode_get_string(dnode, "./access-list"));
232 vty_out(vty, "\n");
233 }
234
235 /*
236 * XPath: /frr-ripd:ripd/instance/explicit-neighbor
237 */
238 DEFPY (rip_neighbor,
239 rip_neighbor_cmd,
240 "[no] neighbor A.B.C.D",
241 NO_STR
242 "Specify a neighbor router\n"
243 "Neighbor address\n")
244 {
245 nb_cli_enqueue_change(vty, "./explicit-neighbor",
246 no ? NB_OP_DELETE : NB_OP_CREATE, neighbor_str);
247
248 return nb_cli_apply_changes(vty, NULL);
249 }
250
251 void cli_show_rip_neighbor(struct vty *vty, struct lyd_node *dnode,
252 bool show_defaults)
253 {
254 vty_out(vty, " neighbor %s\n", yang_dnode_get_string(dnode, NULL));
255 }
256
257 /*
258 * XPath: /frr-ripd:ripd/instance/network
259 */
260 DEFPY (rip_network_prefix,
261 rip_network_prefix_cmd,
262 "[no] network A.B.C.D/M",
263 NO_STR
264 "Enable routing on an IP network\n"
265 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
266 {
267 nb_cli_enqueue_change(vty, "./network",
268 no ? NB_OP_DELETE : NB_OP_CREATE, network_str);
269
270 return nb_cli_apply_changes(vty, NULL);
271 }
272
273 void cli_show_rip_network_prefix(struct vty *vty, struct lyd_node *dnode,
274 bool show_defaults)
275 {
276 vty_out(vty, " network %s\n", yang_dnode_get_string(dnode, NULL));
277 }
278
279 /*
280 * XPath: /frr-ripd:ripd/instance/interface
281 */
282 DEFPY (rip_network_if,
283 rip_network_if_cmd,
284 "[no] network WORD",
285 NO_STR
286 "Enable routing on an IP network\n"
287 "Interface name\n")
288 {
289 nb_cli_enqueue_change(vty, "./interface",
290 no ? NB_OP_DELETE : NB_OP_CREATE, network);
291
292 return nb_cli_apply_changes(vty, NULL);
293 }
294
295 void cli_show_rip_network_interface(struct vty *vty, struct lyd_node *dnode,
296 bool show_defaults)
297 {
298 vty_out(vty, " network %s\n", yang_dnode_get_string(dnode, NULL));
299 }
300
301 /*
302 * XPath: /frr-ripd:ripd/instance/offset-list
303 */
304 DEFPY (rip_offset_list,
305 rip_offset_list_cmd,
306 "[no] offset-list WORD$acl <in|out>$direction (0-16)$metric [IFNAME]",
307 NO_STR
308 "Modify RIP metric\n"
309 "Access-list name\n"
310 "For incoming updates\n"
311 "For outgoing updates\n"
312 "Metric value\n"
313 "Interface to match\n")
314 {
315 if (!no) {
316 nb_cli_enqueue_change(vty, ".", NB_OP_CREATE, NULL);
317 nb_cli_enqueue_change(vty, "./access-list", NB_OP_MODIFY, acl);
318 nb_cli_enqueue_change(vty, "./metric", NB_OP_MODIFY,
319 metric_str);
320 } else
321 nb_cli_enqueue_change(vty, ".", NB_OP_DELETE, NULL);
322
323 return nb_cli_apply_changes(
324 vty, "./offset-list[interface='%s'][direction='%s']",
325 ifname ? ifname : "*", direction);
326 }
327
328 void cli_show_rip_offset_list(struct vty *vty, struct lyd_node *dnode,
329 bool show_defaults)
330 {
331 const char *interface;
332
333 interface = yang_dnode_get_string(dnode, "./interface");
334
335 vty_out(vty, " offset-list %s %s %s",
336 yang_dnode_get_string(dnode, "./access-list"),
337 yang_dnode_get_string(dnode, "./direction"),
338 yang_dnode_get_string(dnode, "./metric"));
339 if (!strmatch(interface, "*"))
340 vty_out(vty, " %s", interface);
341 vty_out(vty, "\n");
342 }
343
344 /*
345 * XPath: /frr-ripd:ripd/instance/passive-default
346 */
347 DEFPY (rip_passive_default,
348 rip_passive_default_cmd,
349 "[no] passive-interface default",
350 NO_STR
351 "Suppress routing updates on an interface\n"
352 "default for all interfaces\n")
353 {
354 nb_cli_enqueue_change(vty, "./passive-default", NB_OP_MODIFY,
355 no ? "false" : "true");
356
357 return nb_cli_apply_changes(vty, NULL);
358 }
359
360 void cli_show_rip_passive_default(struct vty *vty, struct lyd_node *dnode,
361 bool show_defaults)
362 {
363 if (!yang_dnode_get_bool(dnode, NULL))
364 vty_out(vty, " no");
365
366 vty_out(vty, " passive-interface default\n");
367 }
368
369 /*
370 * XPath: /frr-ripd:ripd/instance/passive-interface
371 * /frr-ripd:ripd/instance/non-passive-interface
372 */
373 DEFPY (rip_passive_interface,
374 rip_passive_interface_cmd,
375 "[no] passive-interface IFNAME",
376 NO_STR
377 "Suppress routing updates on an interface\n"
378 "Interface name\n")
379 {
380 nb_cli_enqueue_change(vty, "./passive-interface",
381 no ? NB_OP_DELETE : NB_OP_CREATE, ifname);
382 nb_cli_enqueue_change(vty, "./non-passive-interface",
383 no ? NB_OP_CREATE : NB_OP_DELETE, ifname);
384
385 return nb_cli_apply_changes(vty, NULL);
386 }
387
388 void cli_show_rip_passive_interface(struct vty *vty, struct lyd_node *dnode,
389 bool show_defaults)
390 {
391 vty_out(vty, " passive-interface %s\n",
392 yang_dnode_get_string(dnode, NULL));
393 }
394
395 void cli_show_rip_non_passive_interface(struct vty *vty, struct lyd_node *dnode,
396 bool show_defaults)
397 {
398 vty_out(vty, " no passive-interface %s\n",
399 yang_dnode_get_string(dnode, NULL));
400 }
401
402 /*
403 * XPath: /frr-ripd:ripd/instance/redistribute
404 */
405 DEFPY (rip_redistribute,
406 rip_redistribute_cmd,
407 "[no] redistribute " FRR_REDIST_STR_RIPD "$protocol [{metric (0-16)|route-map WORD}]",
408 NO_STR
409 REDIST_STR
410 FRR_REDIST_HELP_STR_RIPD
411 "Metric\n"
412 "Metric value\n"
413 "Route map reference\n"
414 "Pointer to route-map entries\n")
415 {
416 if (!no) {
417 nb_cli_enqueue_change(vty, ".", NB_OP_CREATE, NULL);
418 nb_cli_enqueue_change(vty, "./route-map",
419 route_map ? NB_OP_MODIFY : NB_OP_DELETE,
420 route_map);
421 nb_cli_enqueue_change(vty, "./metric",
422 metric_str ? NB_OP_MODIFY : NB_OP_DELETE,
423 metric_str);
424 } else
425 nb_cli_enqueue_change(vty, ".", NB_OP_DELETE, NULL);
426
427 return nb_cli_apply_changes(vty, "./redistribute[protocol='%s']",
428 protocol);
429 }
430
431 void cli_show_rip_redistribute(struct vty *vty, struct lyd_node *dnode,
432 bool show_defaults)
433 {
434 vty_out(vty, " redistribute %s",
435 yang_dnode_get_string(dnode, "./protocol"));
436 if (yang_dnode_exists(dnode, "./metric"))
437 vty_out(vty, " metric %s",
438 yang_dnode_get_string(dnode, "./metric"));
439 if (yang_dnode_exists(dnode, "./route-map"))
440 vty_out(vty, " route-map %s",
441 yang_dnode_get_string(dnode, "./route-map"));
442 vty_out(vty, "\n");
443 }
444
445 /*
446 * XPath: /frr-ripd:ripd/instance/static-route
447 */
448 DEFPY (rip_route,
449 rip_route_cmd,
450 "[no] route A.B.C.D/M",
451 NO_STR
452 "RIP static route configuration\n"
453 "IP prefix <network>/<length>\n")
454 {
455 nb_cli_enqueue_change(vty, "./static-route",
456 no ? NB_OP_DELETE : NB_OP_CREATE, route_str);
457
458 return nb_cli_apply_changes(vty, NULL);
459 }
460
461 void cli_show_rip_route(struct vty *vty, struct lyd_node *dnode,
462 bool show_defaults)
463 {
464 vty_out(vty, " route %s\n", yang_dnode_get_string(dnode, NULL));
465 }
466
467 /*
468 * XPath: /frr-ripd:ripd/instance/timers
469 */
470 DEFPY (rip_timers,
471 rip_timers_cmd,
472 "timers basic (5-2147483647)$update (5-2147483647)$timeout (5-2147483647)$garbage",
473 "Adjust routing timers\n"
474 "Basic routing protocol update timers\n"
475 "Routing table update timer value in second. Default is 30.\n"
476 "Routing information timeout timer. Default is 180.\n"
477 "Garbage collection timer. Default is 120.\n")
478 {
479 nb_cli_enqueue_change(vty, "./update-interval", NB_OP_MODIFY,
480 update_str);
481 nb_cli_enqueue_change(vty, "./holddown-interval", NB_OP_MODIFY,
482 timeout_str);
483 nb_cli_enqueue_change(vty, "./flush-interval", NB_OP_MODIFY,
484 garbage_str);
485
486 return nb_cli_apply_changes(vty, "./timers");
487 }
488
489 DEFPY (no_rip_timers,
490 no_rip_timers_cmd,
491 "no timers basic [(5-2147483647) (5-2147483647) (5-2147483647)]",
492 NO_STR
493 "Adjust routing timers\n"
494 "Basic routing protocol update timers\n"
495 "Routing table update timer value in second. Default is 30.\n"
496 "Routing information timeout timer. Default is 180.\n"
497 "Garbage collection timer. Default is 120.\n")
498 {
499 nb_cli_enqueue_change(vty, "./update-interval", NB_OP_MODIFY, NULL);
500 nb_cli_enqueue_change(vty, "./holddown-interval", NB_OP_MODIFY, NULL);
501 nb_cli_enqueue_change(vty, "./flush-interval", NB_OP_MODIFY, NULL);
502
503 return nb_cli_apply_changes(vty, "./timers");
504 }
505
506 void cli_show_rip_timers(struct vty *vty, struct lyd_node *dnode,
507 bool show_defaults)
508 {
509 vty_out(vty, " timers basic %s %s %s\n",
510 yang_dnode_get_string(dnode, "./update-interval"),
511 yang_dnode_get_string(dnode, "./holddown-interval"),
512 yang_dnode_get_string(dnode, "./flush-interval"));
513 }
514
515 /*
516 * XPath: /frr-ripd:ripd/instance/version
517 */
518 DEFPY (rip_version,
519 rip_version_cmd,
520 "version (1-2)",
521 "Set routing protocol version\n"
522 "version\n")
523 {
524 nb_cli_enqueue_change(vty, "./version/receive", NB_OP_MODIFY,
525 version_str);
526 nb_cli_enqueue_change(vty, "./version/send", NB_OP_MODIFY, version_str);
527
528 return nb_cli_apply_changes(vty, NULL);
529 }
530
531 DEFPY (no_rip_version,
532 no_rip_version_cmd,
533 "no version [(1-2)]",
534 NO_STR
535 "Set routing protocol version\n"
536 "version\n")
537 {
538 nb_cli_enqueue_change(vty, "./version/receive", NB_OP_MODIFY, NULL);
539 nb_cli_enqueue_change(vty, "./version/send", NB_OP_MODIFY, NULL);
540
541 return nb_cli_apply_changes(vty, NULL);
542 }
543
544 void cli_show_rip_version(struct vty *vty, struct lyd_node *dnode,
545 bool show_defaults)
546 {
547 /*
548 * We have only one "version" command and three possible combinations of
549 * send/receive values.
550 */
551 switch (yang_dnode_get_enum(dnode, "./receive")) {
552 case RI_RIP_VERSION_1:
553 vty_out(vty, " version 1\n");
554 break;
555 case RI_RIP_VERSION_2:
556 vty_out(vty, " version 2\n");
557 break;
558 case RI_RIP_VERSION_1_AND_2:
559 vty_out(vty, " no version\n");
560 break;
561 }
562 }
563
564 /*
565 * XPath: /frr-interface:lib/interface/frr-ripd:rip/split-horizon
566 */
567 DEFPY (ip_rip_split_horizon,
568 ip_rip_split_horizon_cmd,
569 "[no] ip rip split-horizon [poisoned-reverse$poisoned_reverse]",
570 NO_STR
571 IP_STR
572 "Routing Information Protocol\n"
573 "Perform split horizon\n"
574 "With poisoned-reverse\n")
575 {
576 const char *value;
577
578 if (no)
579 value = "disabled";
580 else if (poisoned_reverse)
581 value = "poison-reverse";
582 else
583 value = "simple";
584
585 nb_cli_enqueue_change(vty, "./split-horizon", NB_OP_MODIFY, value);
586
587 return nb_cli_apply_changes(vty, "./frr-ripd:rip");
588 }
589
590 void cli_show_ip_rip_split_horizon(struct vty *vty, struct lyd_node *dnode,
591 bool show_defaults)
592 {
593 int value;
594
595 value = yang_dnode_get_enum(dnode, NULL);
596 switch (value) {
597 case RIP_NO_SPLIT_HORIZON:
598 vty_out(vty, " no ip rip split-horizon\n");
599 break;
600 case RIP_SPLIT_HORIZON:
601 vty_out(vty, " ip rip split-horizon\n");
602 break;
603 case RIP_SPLIT_HORIZON_POISONED_REVERSE:
604 vty_out(vty, " ip rip split-horizon poisoned-reverse\n");
605 break;
606 }
607 }
608
609 /*
610 * XPath: /frr-interface:lib/interface/frr-ripd:rip/v2-broadcast
611 */
612 DEFPY (ip_rip_v2_broadcast,
613 ip_rip_v2_broadcast_cmd,
614 "[no] ip rip v2-broadcast",
615 NO_STR
616 IP_STR
617 "Routing Information Protocol\n"
618 "Send ip broadcast v2 update\n")
619 {
620 nb_cli_enqueue_change(vty, "./v2-broadcast", NB_OP_MODIFY,
621 no ? "false" : "true");
622
623 return nb_cli_apply_changes(vty, "./frr-ripd:rip");
624 }
625
626 void cli_show_ip_rip_v2_broadcast(struct vty *vty, struct lyd_node *dnode,
627 bool show_defaults)
628 {
629 if (!yang_dnode_get_bool(dnode, NULL))
630 vty_out(vty, " no");
631
632 vty_out(vty, " ip rip v2-broadcast\n");
633 }
634
635 /*
636 * XPath: /frr-interface:lib/interface/frr-ripd:rip/version-receive
637 */
638 DEFPY (ip_rip_receive_version,
639 ip_rip_receive_version_cmd,
640 "ip rip receive version <{1$v1|2$v2}|none>",
641 IP_STR
642 "Routing Information Protocol\n"
643 "Advertisement reception\n"
644 "Version control\n"
645 "RIP version 1\n"
646 "RIP version 2\n"
647 "None\n")
648 {
649 const char *value;
650
651 if (v1 && v2)
652 value = "both";
653 else if (v1)
654 value = "1";
655 else if (v2)
656 value = "2";
657 else
658 value = "none";
659
660 nb_cli_enqueue_change(vty, "./version-receive", NB_OP_MODIFY, value);
661
662 return nb_cli_apply_changes(vty, "./frr-ripd:rip");
663 }
664
665 DEFPY (no_ip_rip_receive_version,
666 no_ip_rip_receive_version_cmd,
667 "no ip rip receive version [<{1|2}|none>]",
668 NO_STR
669 IP_STR
670 "Routing Information Protocol\n"
671 "Advertisement reception\n"
672 "Version control\n"
673 "RIP version 1\n"
674 "RIP version 2\n"
675 "None\n")
676 {
677 nb_cli_enqueue_change(vty, "./version-receive", NB_OP_MODIFY, NULL);
678
679 return nb_cli_apply_changes(vty, "./frr-ripd:rip");
680 }
681
682 void cli_show_ip_rip_receive_version(struct vty *vty, struct lyd_node *dnode,
683 bool show_defaults)
684 {
685 switch (yang_dnode_get_enum(dnode, NULL)) {
686 case RI_RIP_UNSPEC:
687 vty_out(vty, " no ip rip receive version\n");
688 break;
689 case RI_RIP_VERSION_1:
690 vty_out(vty, " ip rip receive version 1\n");
691 break;
692 case RI_RIP_VERSION_2:
693 vty_out(vty, " ip rip receive version 2\n");
694 break;
695 case RI_RIP_VERSION_1_AND_2:
696 vty_out(vty, " ip rip receive version 1 2\n");
697 break;
698 case RI_RIP_VERSION_NONE:
699 vty_out(vty, " ip rip receive version none\n");
700 break;
701 }
702 }
703
704 /*
705 * XPath: /frr-interface:lib/interface/frr-ripd:rip/version-send
706 */
707 DEFPY (ip_rip_send_version,
708 ip_rip_send_version_cmd,
709 "ip rip send version <{1$v1|2$v2}|none>",
710 IP_STR
711 "Routing Information Protocol\n"
712 "Advertisement transmission\n"
713 "Version control\n"
714 "RIP version 1\n"
715 "RIP version 2\n"
716 "None\n")
717 {
718 const char *value;
719
720 if (v1 && v2)
721 value = "both";
722 else if (v1)
723 value = "1";
724 else if (v2)
725 value = "2";
726 else
727 value = "none";
728
729 nb_cli_enqueue_change(vty, "./version-send", NB_OP_MODIFY, value);
730
731 return nb_cli_apply_changes(vty, "./frr-ripd:rip");
732 }
733
734 DEFPY (no_ip_rip_send_version,
735 no_ip_rip_send_version_cmd,
736 "no ip rip send version [<{1|2}|none>]",
737 NO_STR
738 IP_STR
739 "Routing Information Protocol\n"
740 "Advertisement transmission\n"
741 "Version control\n"
742 "RIP version 1\n"
743 "RIP version 2\n"
744 "None\n")
745 {
746 nb_cli_enqueue_change(vty, "./version-send", NB_OP_MODIFY, NULL);
747
748 return nb_cli_apply_changes(vty, "./frr-ripd:rip");
749 }
750
751 void cli_show_ip_rip_send_version(struct vty *vty, struct lyd_node *dnode,
752 bool show_defaults)
753 {
754 switch (yang_dnode_get_enum(dnode, NULL)) {
755 case RI_RIP_UNSPEC:
756 vty_out(vty, " no ip rip send version\n");
757 break;
758 case RI_RIP_VERSION_1:
759 vty_out(vty, " ip rip send version 1\n");
760 break;
761 case RI_RIP_VERSION_2:
762 vty_out(vty, " ip rip send version 2\n");
763 break;
764 case RI_RIP_VERSION_1_AND_2:
765 vty_out(vty, " ip rip send version 1 2\n");
766 break;
767 case RI_RIP_VERSION_NONE:
768 vty_out(vty, " ip rip send version none\n");
769 break;
770 }
771 }
772
773 /*
774 * XPath: /frr-interface:lib/interface/frr-ripd:rip/authentication-scheme
775 */
776 DEFPY (ip_rip_authentication_mode,
777 ip_rip_authentication_mode_cmd,
778 "ip rip authentication mode <md5$mode [auth-length <rfc|old-ripd>$auth_length]|text$mode>",
779 IP_STR
780 "Routing Information Protocol\n"
781 "Authentication control\n"
782 "Authentication mode\n"
783 "Keyed message digest\n"
784 "MD5 authentication data length\n"
785 "RFC compatible\n"
786 "Old ripd compatible\n"
787 "Clear text authentication\n")
788 {
789 const char *value = NULL;
790
791 if (auth_length) {
792 if (strmatch(auth_length, "rfc"))
793 value = "16";
794 else
795 value = "20";
796 }
797
798 nb_cli_enqueue_change(vty, "./authentication-scheme/mode", NB_OP_MODIFY,
799 strmatch(mode, "md5") ? "md5" : "plain-text");
800 nb_cli_enqueue_change(vty, "./authentication-scheme/md5-auth-length",
801 NB_OP_MODIFY, value);
802
803 return nb_cli_apply_changes(vty, "./frr-ripd:rip");
804 }
805
806 DEFPY (no_ip_rip_authentication_mode,
807 no_ip_rip_authentication_mode_cmd,
808 "no ip rip authentication mode [<md5 [auth-length <rfc|old-ripd>]|text>]",
809 NO_STR
810 IP_STR
811 "Routing Information Protocol\n"
812 "Authentication control\n"
813 "Authentication mode\n"
814 "Keyed message digest\n"
815 "MD5 authentication data length\n"
816 "RFC compatible\n"
817 "Old ripd compatible\n"
818 "Clear text authentication\n")
819 {
820 nb_cli_enqueue_change(vty, "./authentication-scheme/mode", NB_OP_MODIFY,
821 NULL);
822 nb_cli_enqueue_change(vty, "./authentication-scheme/md5-auth-length",
823 NB_OP_MODIFY, NULL);
824
825 return nb_cli_apply_changes(vty, "./frr-ripd:rip");
826 }
827
828 void cli_show_ip_rip_authentication_scheme(struct vty *vty,
829 struct lyd_node *dnode,
830 bool show_defaults)
831 {
832 switch (yang_dnode_get_enum(dnode, "./mode")) {
833 case RIP_NO_AUTH:
834 vty_out(vty, " no ip rip authentication mode\n");
835 break;
836 case RIP_AUTH_SIMPLE_PASSWORD:
837 vty_out(vty, " ip rip authentication mode text\n");
838 break;
839 case RIP_AUTH_MD5:
840 vty_out(vty, " ip rip authentication mode md5");
841 if (show_defaults
842 || !yang_dnode_is_default(dnode, "./md5-auth-length")) {
843 if (yang_dnode_get_enum(dnode, "./md5-auth-length")
844 == RIP_AUTH_MD5_SIZE)
845 vty_out(vty, " auth-length rfc");
846 else
847 vty_out(vty, " auth-length old-ripd");
848 }
849 vty_out(vty, "\n");
850 break;
851 }
852 }
853
854 /*
855 * XPath: /frr-interface:lib/interface/frr-ripd:rip/authentication-password
856 */
857 DEFPY (ip_rip_authentication_string,
858 ip_rip_authentication_string_cmd,
859 "ip rip authentication string LINE$password",
860 IP_STR
861 "Routing Information Protocol\n"
862 "Authentication control\n"
863 "Authentication string\n"
864 "Authentication string\n")
865 {
866 if (strlen(password) > 16) {
867 vty_out(vty,
868 "%% RIPv2 authentication string must be shorter than 16\n");
869 return CMD_WARNING_CONFIG_FAILED;
870 }
871
872 if (yang_dnode_exists(vty->candidate_config->dnode, "%s%s",
873 VTY_CURR_XPATH,
874 "/frr-ripd:rip/authentication-key-chain")) {
875 vty_out(vty, "%% key-chain configuration exists\n");
876 return CMD_WARNING_CONFIG_FAILED;
877 }
878
879 nb_cli_enqueue_change(vty, "./authentication-password", NB_OP_MODIFY,
880 password);
881
882 return nb_cli_apply_changes(vty, "./frr-ripd:rip");
883 }
884
885 DEFPY (no_ip_rip_authentication_string,
886 no_ip_rip_authentication_string_cmd,
887 "no ip rip authentication string [LINE]",
888 NO_STR
889 IP_STR
890 "Routing Information Protocol\n"
891 "Authentication control\n"
892 "Authentication string\n"
893 "Authentication string\n")
894 {
895 nb_cli_enqueue_change(vty, "./authentication-password", NB_OP_MODIFY,
896 NULL);
897
898 return nb_cli_apply_changes(vty, "./frr-ripd:rip");
899 }
900
901 void cli_show_ip_rip_authentication_string(struct vty *vty,
902 struct lyd_node *dnode,
903 bool show_defaults)
904 {
905 vty_out(vty, " ip rip authentication string %s\n",
906 yang_dnode_get_string(dnode, NULL));
907 }
908
909 /*
910 * XPath: /frr-interface:lib/interface/frr-ripd:rip/authentication-key-chain
911 */
912 DEFPY (ip_rip_authentication_key_chain,
913 ip_rip_authentication_key_chain_cmd,
914 "ip rip authentication key-chain LINE$keychain",
915 IP_STR
916 "Routing Information Protocol\n"
917 "Authentication control\n"
918 "Authentication key-chain\n"
919 "name of key-chain\n")
920 {
921 if (yang_dnode_exists(vty->candidate_config->dnode, "%s%s",
922 VTY_CURR_XPATH,
923 "/frr-ripd:rip/authentication-password")) {
924 vty_out(vty, "%% authentication string configuration exists\n");
925 return CMD_WARNING_CONFIG_FAILED;
926 }
927
928 nb_cli_enqueue_change(vty, "./authentication-key-chain", NB_OP_MODIFY,
929 keychain);
930
931 return nb_cli_apply_changes(vty, "./frr-ripd:rip");
932 }
933
934 DEFPY (no_ip_rip_authentication_key_chain,
935 no_ip_rip_authentication_key_chain_cmd,
936 "no ip rip authentication key-chain [LINE]",
937 NO_STR
938 IP_STR
939 "Routing Information Protocol\n"
940 "Authentication control\n"
941 "Authentication key-chain\n"
942 "name of key-chain\n")
943 {
944 nb_cli_enqueue_change(vty, "./authentication-key-chain", NB_OP_DELETE,
945 NULL);
946
947 return nb_cli_apply_changes(vty, "./frr-ripd:rip");
948 }
949
950 void cli_show_ip_rip_authentication_key_chain(struct vty *vty,
951 struct lyd_node *dnode,
952 bool show_defaults)
953 {
954 vty_out(vty, " ip rip authentication key-chain %s\n",
955 yang_dnode_get_string(dnode, NULL));
956 }
957
958 /*
959 * XPath: /frr-ripd:clear-rip-route
960 */
961 DEFPY (clear_ip_rip,
962 clear_ip_rip_cmd,
963 "clear ip rip",
964 CLEAR_STR
965 IP_STR
966 "Clear IP RIP database\n")
967 {
968 return nb_cli_rpc("/frr-ripd:clear-rip-route", NULL, NULL);
969 }
970
971 void rip_cli_init(void)
972 {
973 install_element(CONFIG_NODE, &router_rip_cmd);
974 install_element(CONFIG_NODE, &no_router_rip_cmd);
975
976 install_element(RIP_NODE, &rip_allow_ecmp_cmd);
977 install_element(RIP_NODE, &rip_default_information_originate_cmd);
978 install_element(RIP_NODE, &rip_default_metric_cmd);
979 install_element(RIP_NODE, &no_rip_default_metric_cmd);
980 install_element(RIP_NODE, &rip_distance_cmd);
981 install_element(RIP_NODE, &no_rip_distance_cmd);
982 install_element(RIP_NODE, &rip_distance_source_cmd);
983 install_element(RIP_NODE, &rip_neighbor_cmd);
984 install_element(RIP_NODE, &rip_network_prefix_cmd);
985 install_element(RIP_NODE, &rip_network_if_cmd);
986 install_element(RIP_NODE, &rip_offset_list_cmd);
987 install_element(RIP_NODE, &rip_passive_default_cmd);
988 install_element(RIP_NODE, &rip_passive_interface_cmd);
989 install_element(RIP_NODE, &rip_redistribute_cmd);
990 install_element(RIP_NODE, &rip_route_cmd);
991 install_element(RIP_NODE, &rip_timers_cmd);
992 install_element(RIP_NODE, &no_rip_timers_cmd);
993 install_element(RIP_NODE, &rip_version_cmd);
994 install_element(RIP_NODE, &no_rip_version_cmd);
995
996 install_element(INTERFACE_NODE, &ip_rip_split_horizon_cmd);
997 install_element(INTERFACE_NODE, &ip_rip_v2_broadcast_cmd);
998 install_element(INTERFACE_NODE, &ip_rip_receive_version_cmd);
999 install_element(INTERFACE_NODE, &no_ip_rip_receive_version_cmd);
1000 install_element(INTERFACE_NODE, &ip_rip_send_version_cmd);
1001 install_element(INTERFACE_NODE, &no_ip_rip_send_version_cmd);
1002 install_element(INTERFACE_NODE, &ip_rip_authentication_mode_cmd);
1003 install_element(INTERFACE_NODE, &no_ip_rip_authentication_mode_cmd);
1004 install_element(INTERFACE_NODE, &ip_rip_authentication_string_cmd);
1005 install_element(INTERFACE_NODE, &no_ip_rip_authentication_string_cmd);
1006 install_element(INTERFACE_NODE, &ip_rip_authentication_key_chain_cmd);
1007 install_element(INTERFACE_NODE,
1008 &no_ip_rip_authentication_key_chain_cmd);
1009
1010 install_element(ENABLE_NODE, &clear_ip_rip_cmd);
1011 }