]> git.proxmox.com Git - mirror_frr.git/blob - ripngd/ripng_northbound.c
ripngd: retrofit the 'default-information' command to the new northbound model
[mirror_frr.git] / ripngd / ripng_northbound.c
1 /*
2 * Copyright (C) 1998 Kunihiro Ishiguro
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 "table.h"
28 #include "command.h"
29 #include "routemap.h"
30 #include "northbound.h"
31 #include "libfrr.h"
32
33 #include "ripngd/ripngd.h"
34 #include "ripngd/ripng_cli.h"
35
36 /*
37 * XPath: /frr-ripngd:ripngd/instance
38 */
39 static int ripngd_instance_create(enum nb_event event,
40 const struct lyd_node *dnode,
41 union nb_resource *resource)
42 {
43 int socket;
44
45 switch (event) {
46 case NB_EV_VALIDATE:
47 break;
48 case NB_EV_PREPARE:
49 socket = ripng_make_socket();
50 if (socket < 0)
51 return NB_ERR_RESOURCE;
52 resource->fd = socket;
53 break;
54 case NB_EV_ABORT:
55 socket = resource->fd;
56 close(socket);
57 break;
58 case NB_EV_APPLY:
59 socket = resource->fd;
60 ripng_create(socket);
61 break;
62 }
63
64 return NB_OK;
65 }
66
67 static int ripngd_instance_delete(enum nb_event event,
68 const struct lyd_node *dnode)
69 {
70 if (event != NB_EV_APPLY)
71 return NB_OK;
72
73 ripng_clean();
74
75 return NB_OK;
76 }
77
78 /*
79 * XPath: /frr-ripngd:ripngd/instance/allow-ecmp
80 */
81 static int ripngd_instance_allow_ecmp_modify(enum nb_event event,
82 const struct lyd_node *dnode,
83 union nb_resource *resource)
84 {
85 if (event != NB_EV_APPLY)
86 return NB_OK;
87
88 ripng->ecmp = yang_dnode_get_bool(dnode, NULL);
89 if (!ripng->ecmp)
90 ripng_ecmp_disable();
91
92 return NB_OK;
93 }
94
95 /*
96 * XPath: /frr-ripngd:ripngd/instance/default-information-originate
97 */
98 static int ripngd_instance_default_information_originate_modify(
99 enum nb_event event, const struct lyd_node *dnode,
100 union nb_resource *resource)
101 {
102 bool default_information;
103 struct prefix_ipv6 p;
104
105 if (event != NB_EV_APPLY)
106 return NB_OK;
107
108 default_information = yang_dnode_get_bool(dnode, NULL);
109 str2prefix_ipv6("::/0", &p);
110 if (default_information) {
111 ripng_redistribute_add(ZEBRA_ROUTE_RIPNG, RIPNG_ROUTE_DEFAULT,
112 &p, 0, NULL, 0);
113 } else {
114 ripng_redistribute_delete(ZEBRA_ROUTE_RIPNG,
115 RIPNG_ROUTE_DEFAULT, &p, 0);
116 }
117
118 return NB_OK;
119 }
120
121 /*
122 * XPath: /frr-ripngd:ripngd/instance/default-metric
123 */
124 static int ripngd_instance_default_metric_modify(enum nb_event event,
125 const struct lyd_node *dnode,
126 union nb_resource *resource)
127 {
128 /* TODO: implement me. */
129 return NB_OK;
130 }
131
132 /*
133 * XPath: /frr-ripngd:ripngd/instance/network
134 */
135 static int ripngd_instance_network_create(enum nb_event event,
136 const struct lyd_node *dnode,
137 union nb_resource *resource)
138 {
139 /* TODO: implement me. */
140 return NB_OK;
141 }
142
143 static int ripngd_instance_network_delete(enum nb_event event,
144 const struct lyd_node *dnode)
145 {
146 /* TODO: implement me. */
147 return NB_OK;
148 }
149
150 /*
151 * XPath: /frr-ripngd:ripngd/instance/interface
152 */
153 static int ripngd_instance_interface_create(enum nb_event event,
154 const struct lyd_node *dnode,
155 union nb_resource *resource)
156 {
157 /* TODO: implement me. */
158 return NB_OK;
159 }
160
161 static int ripngd_instance_interface_delete(enum nb_event event,
162 const struct lyd_node *dnode)
163 {
164 /* TODO: implement me. */
165 return NB_OK;
166 }
167
168 /*
169 * XPath: /frr-ripngd:ripngd/instance/offset-list
170 */
171 static int ripngd_instance_offset_list_create(enum nb_event event,
172 const struct lyd_node *dnode,
173 union nb_resource *resource)
174 {
175 /* TODO: implement me. */
176 return NB_OK;
177 }
178
179 static int ripngd_instance_offset_list_delete(enum nb_event event,
180 const struct lyd_node *dnode)
181 {
182 /* TODO: implement me. */
183 return NB_OK;
184 }
185
186 /*
187 * XPath: /frr-ripngd:ripngd/instance/offset-list/access-list
188 */
189 static int
190 ripngd_instance_offset_list_access_list_modify(enum nb_event event,
191 const struct lyd_node *dnode,
192 union nb_resource *resource)
193 {
194 /* TODO: implement me. */
195 return NB_OK;
196 }
197
198 /*
199 * XPath: /frr-ripngd:ripngd/instance/offset-list/metric
200 */
201 static int
202 ripngd_instance_offset_list_metric_modify(enum nb_event event,
203 const struct lyd_node *dnode,
204 union nb_resource *resource)
205 {
206 /* TODO: implement me. */
207 return NB_OK;
208 }
209
210 /*
211 * XPath: /frr-ripngd:ripngd/instance/passive-interface
212 */
213 static int
214 ripngd_instance_passive_interface_create(enum nb_event event,
215 const struct lyd_node *dnode,
216 union nb_resource *resource)
217 {
218 /* TODO: implement me. */
219 return NB_OK;
220 }
221
222 static int
223 ripngd_instance_passive_interface_delete(enum nb_event event,
224 const struct lyd_node *dnode)
225 {
226 /* TODO: implement me. */
227 return NB_OK;
228 }
229
230 /*
231 * XPath: /frr-ripngd:ripngd/instance/redistribute
232 */
233 static int ripngd_instance_redistribute_create(enum nb_event event,
234 const struct lyd_node *dnode,
235 union nb_resource *resource)
236 {
237 /* TODO: implement me. */
238 return NB_OK;
239 }
240
241 static int ripngd_instance_redistribute_delete(enum nb_event event,
242 const struct lyd_node *dnode)
243 {
244 /* TODO: implement me. */
245 return NB_OK;
246 }
247
248 /*
249 * XPath: /frr-ripngd:ripngd/instance/redistribute/route-map
250 */
251 static int
252 ripngd_instance_redistribute_route_map_modify(enum nb_event event,
253 const struct lyd_node *dnode,
254 union nb_resource *resource)
255 {
256 /* TODO: implement me. */
257 return NB_OK;
258 }
259
260 static int
261 ripngd_instance_redistribute_route_map_delete(enum nb_event event,
262 const struct lyd_node *dnode)
263 {
264 /* TODO: implement me. */
265 return NB_OK;
266 }
267
268 /*
269 * XPath: /frr-ripngd:ripngd/instance/redistribute/metric
270 */
271 static int
272 ripngd_instance_redistribute_metric_modify(enum nb_event event,
273 const struct lyd_node *dnode,
274 union nb_resource *resource)
275 {
276 /* TODO: implement me. */
277 return NB_OK;
278 }
279
280 static int
281 ripngd_instance_redistribute_metric_delete(enum nb_event event,
282 const struct lyd_node *dnode)
283 {
284 /* TODO: implement me. */
285 return NB_OK;
286 }
287
288 /*
289 * XPath: /frr-ripngd:ripngd/instance/static-route
290 */
291 static int ripngd_instance_static_route_create(enum nb_event event,
292 const struct lyd_node *dnode,
293 union nb_resource *resource)
294 {
295 /* TODO: implement me. */
296 return NB_OK;
297 }
298
299 static int ripngd_instance_static_route_delete(enum nb_event event,
300 const struct lyd_node *dnode)
301 {
302 /* TODO: implement me. */
303 return NB_OK;
304 }
305
306 /*
307 * XPath: /frr-ripngd:ripngd/instance/aggregate-address
308 */
309 static int
310 ripngd_instance_aggregate_address_create(enum nb_event event,
311 const struct lyd_node *dnode,
312 union nb_resource *resource)
313 {
314 /* TODO: implement me. */
315 return NB_OK;
316 }
317
318 static int
319 ripngd_instance_aggregate_address_delete(enum nb_event event,
320 const struct lyd_node *dnode)
321 {
322 /* TODO: implement me. */
323 return NB_OK;
324 }
325
326 /*
327 * XPath: /frr-ripngd:ripngd/instance/timers/flush-interval
328 */
329 static int
330 ripngd_instance_timers_flush_interval_modify(enum nb_event event,
331 const struct lyd_node *dnode,
332 union nb_resource *resource)
333 {
334 /* TODO: implement me. */
335 return NB_OK;
336 }
337
338 /*
339 * XPath: /frr-ripngd:ripngd/instance/timers/holddown-interval
340 */
341 static int
342 ripngd_instance_timers_holddown_interval_modify(enum nb_event event,
343 const struct lyd_node *dnode,
344 union nb_resource *resource)
345 {
346 /* TODO: implement me. */
347 return NB_OK;
348 }
349
350 /*
351 * XPath: /frr-ripngd:ripngd/instance/timers/update-interval
352 */
353 static int
354 ripngd_instance_timers_update_interval_modify(enum nb_event event,
355 const struct lyd_node *dnode,
356 union nb_resource *resource)
357 {
358 /* TODO: implement me. */
359 return NB_OK;
360 }
361
362 /*
363 * XPath: /frr-ripngd:ripngd/state/neighbors/neighbor
364 */
365 static const void *
366 ripngd_state_neighbors_neighbor_get_next(const void *parent_list_entry,
367 const void *list_entry)
368 {
369 /* TODO: implement me. */
370 return NULL;
371 }
372
373 static int ripngd_state_neighbors_neighbor_get_keys(const void *list_entry,
374 struct yang_list_keys *keys)
375 {
376 /* TODO: implement me. */
377 return NB_OK;
378 }
379
380 static const void *
381 ripngd_state_neighbors_neighbor_lookup_entry(const void *parent_list_entry,
382 const struct yang_list_keys *keys)
383 {
384 /* TODO: implement me. */
385 return NULL;
386 }
387
388 /*
389 * XPath: /frr-ripngd:ripngd/state/neighbors/neighbor/address
390 */
391 static struct yang_data *
392 ripngd_state_neighbors_neighbor_address_get_elem(const char *xpath,
393 const void *list_entry)
394 {
395 /* TODO: implement me. */
396 return NULL;
397 }
398
399 /*
400 * XPath: /frr-ripngd:ripngd/state/neighbors/neighbor/last-update
401 */
402 static struct yang_data *
403 ripngd_state_neighbors_neighbor_last_update_get_elem(const char *xpath,
404 const void *list_entry)
405 {
406 /* TODO: implement me. */
407 return NULL;
408 }
409
410 /*
411 * XPath: /frr-ripngd:ripngd/state/neighbors/neighbor/bad-packets-rcvd
412 */
413 static struct yang_data *
414 ripngd_state_neighbors_neighbor_bad_packets_rcvd_get_elem(
415 const char *xpath, const void *list_entry)
416 {
417 /* TODO: implement me. */
418 return NULL;
419 }
420
421 /*
422 * XPath: /frr-ripngd:ripngd/state/neighbors/neighbor/bad-routes-rcvd
423 */
424 static struct yang_data *
425 ripngd_state_neighbors_neighbor_bad_routes_rcvd_get_elem(const char *xpath,
426 const void *list_entry)
427 {
428 /* TODO: implement me. */
429 return NULL;
430 }
431
432 /*
433 * XPath: /frr-ripngd:ripngd/state/routes/route
434 */
435 static const void *
436 ripngd_state_routes_route_get_next(const void *parent_list_entry,
437 const void *list_entry)
438 {
439 /* TODO: implement me. */
440 return NULL;
441 }
442
443 static int ripngd_state_routes_route_get_keys(const void *list_entry,
444 struct yang_list_keys *keys)
445 {
446 /* TODO: implement me. */
447 return NB_OK;
448 }
449
450 static const void *
451 ripngd_state_routes_route_lookup_entry(const void *parent_list_entry,
452 const struct yang_list_keys *keys)
453 {
454 /* TODO: implement me. */
455 return NULL;
456 }
457
458 /*
459 * XPath: /frr-ripngd:ripngd/state/routes/route/prefix
460 */
461 static struct yang_data *
462 ripngd_state_routes_route_prefix_get_elem(const char *xpath,
463 const void *list_entry)
464 {
465 /* TODO: implement me. */
466 return NULL;
467 }
468
469 /*
470 * XPath: /frr-ripngd:ripngd/state/routes/route/next-hop
471 */
472 static struct yang_data *
473 ripngd_state_routes_route_next_hop_get_elem(const char *xpath,
474 const void *list_entry)
475 {
476 /* TODO: implement me. */
477 return NULL;
478 }
479
480 /*
481 * XPath: /frr-ripngd:ripngd/state/routes/route/interface
482 */
483 static struct yang_data *
484 ripngd_state_routes_route_interface_get_elem(const char *xpath,
485 const void *list_entry)
486 {
487 /* TODO: implement me. */
488 return NULL;
489 }
490
491 /*
492 * XPath: /frr-ripngd:ripngd/state/routes/route/metric
493 */
494 static struct yang_data *
495 ripngd_state_routes_route_metric_get_elem(const char *xpath,
496 const void *list_entry)
497 {
498 /* TODO: implement me. */
499 return NULL;
500 }
501
502 /*
503 * XPath: /frr-ripngd:clear-ripng-route
504 */
505 static int clear_ripng_route_rpc(const char *xpath, const struct list *input,
506 struct list *output)
507 {
508 /* TODO: implement me. */
509 return NB_OK;
510 }
511
512 /*
513 * XPath: /frr-interface:lib/interface/frr-ripngd:ripng/split-horizon
514 */
515 static int
516 lib_interface_ripng_split_horizon_modify(enum nb_event event,
517 const struct lyd_node *dnode,
518 union nb_resource *resource)
519 {
520 /* TODO: implement me. */
521 return NB_OK;
522 }
523
524 /* clang-format off */
525 const struct frr_yang_module_info frr_ripngd_info = {
526 .name = "frr-ripngd",
527 .nodes = {
528 {
529 .xpath = "/frr-ripngd:ripngd/instance",
530 .cbs.create = ripngd_instance_create,
531 .cbs.delete = ripngd_instance_delete,
532 .cbs.cli_show = cli_show_router_ripng,
533 },
534 {
535 .xpath = "/frr-ripngd:ripngd/instance/allow-ecmp",
536 .cbs.modify = ripngd_instance_allow_ecmp_modify,
537 .cbs.cli_show = cli_show_ripng_allow_ecmp,
538 },
539 {
540 .xpath = "/frr-ripngd:ripngd/instance/default-information-originate",
541 .cbs.modify = ripngd_instance_default_information_originate_modify,
542 .cbs.cli_show = cli_show_ripng_default_information_originate,
543 },
544 {
545 .xpath = "/frr-ripngd:ripngd/instance/default-metric",
546 .cbs.modify = ripngd_instance_default_metric_modify,
547 },
548 {
549 .xpath = "/frr-ripngd:ripngd/instance/network",
550 .cbs.create = ripngd_instance_network_create,
551 .cbs.delete = ripngd_instance_network_delete,
552 },
553 {
554 .xpath = "/frr-ripngd:ripngd/instance/interface",
555 .cbs.create = ripngd_instance_interface_create,
556 .cbs.delete = ripngd_instance_interface_delete,
557 },
558 {
559 .xpath = "/frr-ripngd:ripngd/instance/offset-list",
560 .cbs.create = ripngd_instance_offset_list_create,
561 .cbs.delete = ripngd_instance_offset_list_delete,
562 },
563 {
564 .xpath = "/frr-ripngd:ripngd/instance/offset-list/access-list",
565 .cbs.modify = ripngd_instance_offset_list_access_list_modify,
566 },
567 {
568 .xpath = "/frr-ripngd:ripngd/instance/offset-list/metric",
569 .cbs.modify = ripngd_instance_offset_list_metric_modify,
570 },
571 {
572 .xpath = "/frr-ripngd:ripngd/instance/passive-interface",
573 .cbs.create = ripngd_instance_passive_interface_create,
574 .cbs.delete = ripngd_instance_passive_interface_delete,
575 },
576 {
577 .xpath = "/frr-ripngd:ripngd/instance/redistribute",
578 .cbs.create = ripngd_instance_redistribute_create,
579 .cbs.delete = ripngd_instance_redistribute_delete,
580 },
581 {
582 .xpath = "/frr-ripngd:ripngd/instance/redistribute/route-map",
583 .cbs.modify = ripngd_instance_redistribute_route_map_modify,
584 .cbs.delete = ripngd_instance_redistribute_route_map_delete,
585 },
586 {
587 .xpath = "/frr-ripngd:ripngd/instance/redistribute/metric",
588 .cbs.modify = ripngd_instance_redistribute_metric_modify,
589 .cbs.delete = ripngd_instance_redistribute_metric_delete,
590 },
591 {
592 .xpath = "/frr-ripngd:ripngd/instance/static-route",
593 .cbs.create = ripngd_instance_static_route_create,
594 .cbs.delete = ripngd_instance_static_route_delete,
595 },
596 {
597 .xpath = "/frr-ripngd:ripngd/instance/aggregate-address",
598 .cbs.create = ripngd_instance_aggregate_address_create,
599 .cbs.delete = ripngd_instance_aggregate_address_delete,
600 },
601 {
602 .xpath = "/frr-ripngd:ripngd/instance/timers/flush-interval",
603 .cbs.modify = ripngd_instance_timers_flush_interval_modify,
604 },
605 {
606 .xpath = "/frr-ripngd:ripngd/instance/timers/holddown-interval",
607 .cbs.modify = ripngd_instance_timers_holddown_interval_modify,
608 },
609 {
610 .xpath = "/frr-ripngd:ripngd/instance/timers/update-interval",
611 .cbs.modify = ripngd_instance_timers_update_interval_modify,
612 },
613 {
614 .xpath = "/frr-ripngd:ripngd/state/neighbors/neighbor",
615 .cbs.get_next = ripngd_state_neighbors_neighbor_get_next,
616 .cbs.get_keys = ripngd_state_neighbors_neighbor_get_keys,
617 .cbs.lookup_entry = ripngd_state_neighbors_neighbor_lookup_entry,
618 },
619 {
620 .xpath = "/frr-ripngd:ripngd/state/neighbors/neighbor/address",
621 .cbs.get_elem = ripngd_state_neighbors_neighbor_address_get_elem,
622 },
623 {
624 .xpath = "/frr-ripngd:ripngd/state/neighbors/neighbor/last-update",
625 .cbs.get_elem = ripngd_state_neighbors_neighbor_last_update_get_elem,
626 },
627 {
628 .xpath = "/frr-ripngd:ripngd/state/neighbors/neighbor/bad-packets-rcvd",
629 .cbs.get_elem = ripngd_state_neighbors_neighbor_bad_packets_rcvd_get_elem,
630 },
631 {
632 .xpath = "/frr-ripngd:ripngd/state/neighbors/neighbor/bad-routes-rcvd",
633 .cbs.get_elem = ripngd_state_neighbors_neighbor_bad_routes_rcvd_get_elem,
634 },
635 {
636 .xpath = "/frr-ripngd:ripngd/state/routes/route",
637 .cbs.get_next = ripngd_state_routes_route_get_next,
638 .cbs.get_keys = ripngd_state_routes_route_get_keys,
639 .cbs.lookup_entry = ripngd_state_routes_route_lookup_entry,
640 },
641 {
642 .xpath = "/frr-ripngd:ripngd/state/routes/route/prefix",
643 .cbs.get_elem = ripngd_state_routes_route_prefix_get_elem,
644 },
645 {
646 .xpath = "/frr-ripngd:ripngd/state/routes/route/next-hop",
647 .cbs.get_elem = ripngd_state_routes_route_next_hop_get_elem,
648 },
649 {
650 .xpath = "/frr-ripngd:ripngd/state/routes/route/interface",
651 .cbs.get_elem = ripngd_state_routes_route_interface_get_elem,
652 },
653 {
654 .xpath = "/frr-ripngd:ripngd/state/routes/route/metric",
655 .cbs.get_elem = ripngd_state_routes_route_metric_get_elem,
656 },
657 {
658 .xpath = "/frr-ripngd:clear-ripng-route",
659 .cbs.rpc = clear_ripng_route_rpc,
660 },
661 {
662 .xpath = "/frr-interface:lib/interface/frr-ripngd:ripng/split-horizon",
663 .cbs.modify = lib_interface_ripng_split_horizon_modify,
664 },
665 {
666 .xpath = NULL,
667 },
668 }
669 };