2 * Copyright (C) 1998 Kunihiro Ishiguro
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
30 #include "northbound.h"
33 #include "ripngd/ripngd.h"
34 #include "ripngd/ripng_cli.h"
37 * XPath: /frr-ripngd:ripngd/instance
39 static int ripngd_instance_create(enum nb_event event
,
40 const struct lyd_node
*dnode
,
41 union nb_resource
*resource
)
49 socket
= ripng_make_socket();
51 return NB_ERR_RESOURCE
;
52 resource
->fd
= socket
;
55 socket
= resource
->fd
;
59 socket
= resource
->fd
;
67 static int ripngd_instance_delete(enum nb_event event
,
68 const struct lyd_node
*dnode
)
70 if (event
!= NB_EV_APPLY
)
79 * XPath: /frr-ripngd:ripngd/instance/allow-ecmp
81 static int ripngd_instance_allow_ecmp_modify(enum nb_event event
,
82 const struct lyd_node
*dnode
,
83 union nb_resource
*resource
)
85 if (event
!= NB_EV_APPLY
)
88 ripng
->ecmp
= yang_dnode_get_bool(dnode
, NULL
);
96 * XPath: /frr-ripngd:ripngd/instance/default-information-originate
98 static int ripngd_instance_default_information_originate_modify(
99 enum nb_event event
, const struct lyd_node
*dnode
,
100 union nb_resource
*resource
)
102 bool default_information
;
103 struct prefix_ipv6 p
;
105 if (event
!= NB_EV_APPLY
)
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
,
114 ripng_redistribute_delete(ZEBRA_ROUTE_RIPNG
,
115 RIPNG_ROUTE_DEFAULT
, &p
, 0);
122 * XPath: /frr-ripngd:ripngd/instance/default-metric
124 static int ripngd_instance_default_metric_modify(enum nb_event event
,
125 const struct lyd_node
*dnode
,
126 union nb_resource
*resource
)
128 if (event
!= NB_EV_APPLY
)
131 ripng
->default_metric
= yang_dnode_get_uint8(dnode
, NULL
);
137 * XPath: /frr-ripngd:ripngd/instance/network
139 static int ripngd_instance_network_create(enum nb_event event
,
140 const struct lyd_node
*dnode
,
141 union nb_resource
*resource
)
145 if (event
!= NB_EV_APPLY
)
148 yang_dnode_get_ipv6p(&p
, dnode
, NULL
);
149 apply_mask_ipv6((struct prefix_ipv6
*)&p
);
151 return ripng_enable_network_add(&p
);
154 static int ripngd_instance_network_delete(enum nb_event event
,
155 const struct lyd_node
*dnode
)
159 if (event
!= NB_EV_APPLY
)
162 yang_dnode_get_ipv6p(&p
, dnode
, NULL
);
163 apply_mask_ipv6((struct prefix_ipv6
*)&p
);
165 return ripng_enable_network_delete(&p
);
169 * XPath: /frr-ripngd:ripngd/instance/interface
171 static int ripngd_instance_interface_create(enum nb_event event
,
172 const struct lyd_node
*dnode
,
173 union nb_resource
*resource
)
177 if (event
!= NB_EV_APPLY
)
180 ifname
= yang_dnode_get_string(dnode
, NULL
);
182 return ripng_enable_if_add(ifname
);
185 static int ripngd_instance_interface_delete(enum nb_event event
,
186 const struct lyd_node
*dnode
)
190 if (event
!= NB_EV_APPLY
)
193 ifname
= yang_dnode_get_string(dnode
, NULL
);
195 return ripng_enable_if_delete(ifname
);
199 * XPath: /frr-ripngd:ripngd/instance/offset-list
201 static int ripngd_instance_offset_list_create(enum nb_event event
,
202 const struct lyd_node
*dnode
,
203 union nb_resource
*resource
)
206 struct ripng_offset_list
*offset
;
208 if (event
!= NB_EV_APPLY
)
211 ifname
= yang_dnode_get_string(dnode
, "./interface");
213 offset
= ripng_offset_list_new(ifname
);
214 yang_dnode_set_entry(dnode
, offset
);
219 static int ripngd_instance_offset_list_delete(enum nb_event event
,
220 const struct lyd_node
*dnode
)
223 struct ripng_offset_list
*offset
;
225 if (event
!= NB_EV_APPLY
)
228 direct
= yang_dnode_get_enum(dnode
, "./direction");
230 offset
= yang_dnode_get_entry(dnode
, true);
231 if (offset
->direct
[direct
].alist_name
) {
232 free(offset
->direct
[direct
].alist_name
);
233 offset
->direct
[direct
].alist_name
= NULL
;
235 if (offset
->direct
[RIPNG_OFFSET_LIST_IN
].alist_name
== NULL
236 && offset
->direct
[RIPNG_OFFSET_LIST_OUT
].alist_name
== NULL
)
237 ripng_offset_list_del(offset
);
243 * XPath: /frr-ripngd:ripngd/instance/offset-list/access-list
246 ripngd_instance_offset_list_access_list_modify(enum nb_event event
,
247 const struct lyd_node
*dnode
,
248 union nb_resource
*resource
)
251 struct ripng_offset_list
*offset
;
252 const char *alist_name
;
254 if (event
!= NB_EV_APPLY
)
257 direct
= yang_dnode_get_enum(dnode
, "../direction");
258 alist_name
= yang_dnode_get_string(dnode
, NULL
);
260 offset
= yang_dnode_get_entry(dnode
, true);
261 if (offset
->direct
[direct
].alist_name
)
262 free(offset
->direct
[direct
].alist_name
);
263 offset
->direct
[direct
].alist_name
= strdup(alist_name
);
269 * XPath: /frr-ripngd:ripngd/instance/offset-list/metric
272 ripngd_instance_offset_list_metric_modify(enum nb_event event
,
273 const struct lyd_node
*dnode
,
274 union nb_resource
*resource
)
278 struct ripng_offset_list
*offset
;
280 if (event
!= NB_EV_APPLY
)
283 direct
= yang_dnode_get_enum(dnode
, "../direction");
284 metric
= yang_dnode_get_uint8(dnode
, NULL
);
286 offset
= yang_dnode_get_entry(dnode
, true);
287 offset
->direct
[direct
].metric
= metric
;
293 * XPath: /frr-ripngd:ripngd/instance/passive-interface
296 ripngd_instance_passive_interface_create(enum nb_event event
,
297 const struct lyd_node
*dnode
,
298 union nb_resource
*resource
)
302 if (event
!= NB_EV_APPLY
)
305 ifname
= yang_dnode_get_string(dnode
, NULL
);
307 return ripng_passive_interface_set(ifname
);
311 ripngd_instance_passive_interface_delete(enum nb_event event
,
312 const struct lyd_node
*dnode
)
316 if (event
!= NB_EV_APPLY
)
319 ifname
= yang_dnode_get_string(dnode
, NULL
);
321 return ripng_passive_interface_unset(ifname
);
325 * XPath: /frr-ripngd:ripngd/instance/redistribute
327 static int ripngd_instance_redistribute_create(enum nb_event event
,
328 const struct lyd_node
*dnode
,
329 union nb_resource
*resource
)
331 /* TODO: implement me. */
335 static int ripngd_instance_redistribute_delete(enum nb_event event
,
336 const struct lyd_node
*dnode
)
338 /* TODO: implement me. */
343 * XPath: /frr-ripngd:ripngd/instance/redistribute/route-map
346 ripngd_instance_redistribute_route_map_modify(enum nb_event event
,
347 const struct lyd_node
*dnode
,
348 union nb_resource
*resource
)
350 /* TODO: implement me. */
355 ripngd_instance_redistribute_route_map_delete(enum nb_event event
,
356 const struct lyd_node
*dnode
)
358 /* TODO: implement me. */
363 * XPath: /frr-ripngd:ripngd/instance/redistribute/metric
366 ripngd_instance_redistribute_metric_modify(enum nb_event event
,
367 const struct lyd_node
*dnode
,
368 union nb_resource
*resource
)
370 /* TODO: implement me. */
375 ripngd_instance_redistribute_metric_delete(enum nb_event event
,
376 const struct lyd_node
*dnode
)
378 /* TODO: implement me. */
383 * XPath: /frr-ripngd:ripngd/instance/static-route
385 static int ripngd_instance_static_route_create(enum nb_event event
,
386 const struct lyd_node
*dnode
,
387 union nb_resource
*resource
)
389 /* TODO: implement me. */
393 static int ripngd_instance_static_route_delete(enum nb_event event
,
394 const struct lyd_node
*dnode
)
396 /* TODO: implement me. */
401 * XPath: /frr-ripngd:ripngd/instance/aggregate-address
404 ripngd_instance_aggregate_address_create(enum nb_event event
,
405 const struct lyd_node
*dnode
,
406 union nb_resource
*resource
)
408 /* TODO: implement me. */
413 ripngd_instance_aggregate_address_delete(enum nb_event event
,
414 const struct lyd_node
*dnode
)
416 /* TODO: implement me. */
421 * XPath: /frr-ripngd:ripngd/instance/timers/flush-interval
424 ripngd_instance_timers_flush_interval_modify(enum nb_event event
,
425 const struct lyd_node
*dnode
,
426 union nb_resource
*resource
)
428 /* TODO: implement me. */
433 * XPath: /frr-ripngd:ripngd/instance/timers/holddown-interval
436 ripngd_instance_timers_holddown_interval_modify(enum nb_event event
,
437 const struct lyd_node
*dnode
,
438 union nb_resource
*resource
)
440 /* TODO: implement me. */
445 * XPath: /frr-ripngd:ripngd/instance/timers/update-interval
448 ripngd_instance_timers_update_interval_modify(enum nb_event event
,
449 const struct lyd_node
*dnode
,
450 union nb_resource
*resource
)
452 /* TODO: implement me. */
457 * XPath: /frr-ripngd:ripngd/state/neighbors/neighbor
460 ripngd_state_neighbors_neighbor_get_next(const void *parent_list_entry
,
461 const void *list_entry
)
463 /* TODO: implement me. */
467 static int ripngd_state_neighbors_neighbor_get_keys(const void *list_entry
,
468 struct yang_list_keys
*keys
)
470 /* TODO: implement me. */
475 ripngd_state_neighbors_neighbor_lookup_entry(const void *parent_list_entry
,
476 const struct yang_list_keys
*keys
)
478 /* TODO: implement me. */
483 * XPath: /frr-ripngd:ripngd/state/neighbors/neighbor/address
485 static struct yang_data
*
486 ripngd_state_neighbors_neighbor_address_get_elem(const char *xpath
,
487 const void *list_entry
)
489 /* TODO: implement me. */
494 * XPath: /frr-ripngd:ripngd/state/neighbors/neighbor/last-update
496 static struct yang_data
*
497 ripngd_state_neighbors_neighbor_last_update_get_elem(const char *xpath
,
498 const void *list_entry
)
500 /* TODO: implement me. */
505 * XPath: /frr-ripngd:ripngd/state/neighbors/neighbor/bad-packets-rcvd
507 static struct yang_data
*
508 ripngd_state_neighbors_neighbor_bad_packets_rcvd_get_elem(
509 const char *xpath
, const void *list_entry
)
511 /* TODO: implement me. */
516 * XPath: /frr-ripngd:ripngd/state/neighbors/neighbor/bad-routes-rcvd
518 static struct yang_data
*
519 ripngd_state_neighbors_neighbor_bad_routes_rcvd_get_elem(const char *xpath
,
520 const void *list_entry
)
522 /* TODO: implement me. */
527 * XPath: /frr-ripngd:ripngd/state/routes/route
530 ripngd_state_routes_route_get_next(const void *parent_list_entry
,
531 const void *list_entry
)
533 /* TODO: implement me. */
537 static int ripngd_state_routes_route_get_keys(const void *list_entry
,
538 struct yang_list_keys
*keys
)
540 /* TODO: implement me. */
545 ripngd_state_routes_route_lookup_entry(const void *parent_list_entry
,
546 const struct yang_list_keys
*keys
)
548 /* TODO: implement me. */
553 * XPath: /frr-ripngd:ripngd/state/routes/route/prefix
555 static struct yang_data
*
556 ripngd_state_routes_route_prefix_get_elem(const char *xpath
,
557 const void *list_entry
)
559 /* TODO: implement me. */
564 * XPath: /frr-ripngd:ripngd/state/routes/route/next-hop
566 static struct yang_data
*
567 ripngd_state_routes_route_next_hop_get_elem(const char *xpath
,
568 const void *list_entry
)
570 /* TODO: implement me. */
575 * XPath: /frr-ripngd:ripngd/state/routes/route/interface
577 static struct yang_data
*
578 ripngd_state_routes_route_interface_get_elem(const char *xpath
,
579 const void *list_entry
)
581 /* TODO: implement me. */
586 * XPath: /frr-ripngd:ripngd/state/routes/route/metric
588 static struct yang_data
*
589 ripngd_state_routes_route_metric_get_elem(const char *xpath
,
590 const void *list_entry
)
592 /* TODO: implement me. */
597 * XPath: /frr-ripngd:clear-ripng-route
599 static int clear_ripng_route_rpc(const char *xpath
, const struct list
*input
,
602 /* TODO: implement me. */
607 * XPath: /frr-interface:lib/interface/frr-ripngd:ripng/split-horizon
610 lib_interface_ripng_split_horizon_modify(enum nb_event event
,
611 const struct lyd_node
*dnode
,
612 union nb_resource
*resource
)
614 /* TODO: implement me. */
618 /* clang-format off */
619 const struct frr_yang_module_info frr_ripngd_info
= {
620 .name
= "frr-ripngd",
623 .xpath
= "/frr-ripngd:ripngd/instance",
624 .cbs
.create
= ripngd_instance_create
,
625 .cbs
.delete = ripngd_instance_delete
,
626 .cbs
.cli_show
= cli_show_router_ripng
,
629 .xpath
= "/frr-ripngd:ripngd/instance/allow-ecmp",
630 .cbs
.modify
= ripngd_instance_allow_ecmp_modify
,
631 .cbs
.cli_show
= cli_show_ripng_allow_ecmp
,
634 .xpath
= "/frr-ripngd:ripngd/instance/default-information-originate",
635 .cbs
.modify
= ripngd_instance_default_information_originate_modify
,
636 .cbs
.cli_show
= cli_show_ripng_default_information_originate
,
639 .xpath
= "/frr-ripngd:ripngd/instance/default-metric",
640 .cbs
.modify
= ripngd_instance_default_metric_modify
,
641 .cbs
.cli_show
= cli_show_ripng_default_metric
,
644 .xpath
= "/frr-ripngd:ripngd/instance/network",
645 .cbs
.create
= ripngd_instance_network_create
,
646 .cbs
.delete = ripngd_instance_network_delete
,
647 .cbs
.cli_show
= cli_show_ripng_network_prefix
,
650 .xpath
= "/frr-ripngd:ripngd/instance/interface",
651 .cbs
.create
= ripngd_instance_interface_create
,
652 .cbs
.delete = ripngd_instance_interface_delete
,
653 .cbs
.cli_show
= cli_show_ripng_network_interface
,
656 .xpath
= "/frr-ripngd:ripngd/instance/offset-list",
657 .cbs
.create
= ripngd_instance_offset_list_create
,
658 .cbs
.delete = ripngd_instance_offset_list_delete
,
659 .cbs
.cli_show
= cli_show_ripng_offset_list
,
662 .xpath
= "/frr-ripngd:ripngd/instance/offset-list/access-list",
663 .cbs
.modify
= ripngd_instance_offset_list_access_list_modify
,
666 .xpath
= "/frr-ripngd:ripngd/instance/offset-list/metric",
667 .cbs
.modify
= ripngd_instance_offset_list_metric_modify
,
670 .xpath
= "/frr-ripngd:ripngd/instance/passive-interface",
671 .cbs
.create
= ripngd_instance_passive_interface_create
,
672 .cbs
.delete = ripngd_instance_passive_interface_delete
,
673 .cbs
.cli_show
= cli_show_ripng_passive_interface
,
676 .xpath
= "/frr-ripngd:ripngd/instance/redistribute",
677 .cbs
.create
= ripngd_instance_redistribute_create
,
678 .cbs
.delete = ripngd_instance_redistribute_delete
,
681 .xpath
= "/frr-ripngd:ripngd/instance/redistribute/route-map",
682 .cbs
.modify
= ripngd_instance_redistribute_route_map_modify
,
683 .cbs
.delete = ripngd_instance_redistribute_route_map_delete
,
686 .xpath
= "/frr-ripngd:ripngd/instance/redistribute/metric",
687 .cbs
.modify
= ripngd_instance_redistribute_metric_modify
,
688 .cbs
.delete = ripngd_instance_redistribute_metric_delete
,
691 .xpath
= "/frr-ripngd:ripngd/instance/static-route",
692 .cbs
.create
= ripngd_instance_static_route_create
,
693 .cbs
.delete = ripngd_instance_static_route_delete
,
696 .xpath
= "/frr-ripngd:ripngd/instance/aggregate-address",
697 .cbs
.create
= ripngd_instance_aggregate_address_create
,
698 .cbs
.delete = ripngd_instance_aggregate_address_delete
,
701 .xpath
= "/frr-ripngd:ripngd/instance/timers/flush-interval",
702 .cbs
.modify
= ripngd_instance_timers_flush_interval_modify
,
705 .xpath
= "/frr-ripngd:ripngd/instance/timers/holddown-interval",
706 .cbs
.modify
= ripngd_instance_timers_holddown_interval_modify
,
709 .xpath
= "/frr-ripngd:ripngd/instance/timers/update-interval",
710 .cbs
.modify
= ripngd_instance_timers_update_interval_modify
,
713 .xpath
= "/frr-ripngd:ripngd/state/neighbors/neighbor",
714 .cbs
.get_next
= ripngd_state_neighbors_neighbor_get_next
,
715 .cbs
.get_keys
= ripngd_state_neighbors_neighbor_get_keys
,
716 .cbs
.lookup_entry
= ripngd_state_neighbors_neighbor_lookup_entry
,
719 .xpath
= "/frr-ripngd:ripngd/state/neighbors/neighbor/address",
720 .cbs
.get_elem
= ripngd_state_neighbors_neighbor_address_get_elem
,
723 .xpath
= "/frr-ripngd:ripngd/state/neighbors/neighbor/last-update",
724 .cbs
.get_elem
= ripngd_state_neighbors_neighbor_last_update_get_elem
,
727 .xpath
= "/frr-ripngd:ripngd/state/neighbors/neighbor/bad-packets-rcvd",
728 .cbs
.get_elem
= ripngd_state_neighbors_neighbor_bad_packets_rcvd_get_elem
,
731 .xpath
= "/frr-ripngd:ripngd/state/neighbors/neighbor/bad-routes-rcvd",
732 .cbs
.get_elem
= ripngd_state_neighbors_neighbor_bad_routes_rcvd_get_elem
,
735 .xpath
= "/frr-ripngd:ripngd/state/routes/route",
736 .cbs
.get_next
= ripngd_state_routes_route_get_next
,
737 .cbs
.get_keys
= ripngd_state_routes_route_get_keys
,
738 .cbs
.lookup_entry
= ripngd_state_routes_route_lookup_entry
,
741 .xpath
= "/frr-ripngd:ripngd/state/routes/route/prefix",
742 .cbs
.get_elem
= ripngd_state_routes_route_prefix_get_elem
,
745 .xpath
= "/frr-ripngd:ripngd/state/routes/route/next-hop",
746 .cbs
.get_elem
= ripngd_state_routes_route_next_hop_get_elem
,
749 .xpath
= "/frr-ripngd:ripngd/state/routes/route/interface",
750 .cbs
.get_elem
= ripngd_state_routes_route_interface_get_elem
,
753 .xpath
= "/frr-ripngd:ripngd/state/routes/route/metric",
754 .cbs
.get_elem
= ripngd_state_routes_route_metric_get_elem
,
757 .xpath
= "/frr-ripngd:clear-ripng-route",
758 .cbs
.rpc
= clear_ripng_route_rpc
,
761 .xpath
= "/frr-interface:lib/interface/frr-ripngd:ripng/split-horizon",
762 .cbs
.modify
= lib_interface_ripng_split_horizon_modify
,