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