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
)
300 /* TODO: implement me. */
305 ripngd_instance_passive_interface_delete(enum nb_event event
,
306 const struct lyd_node
*dnode
)
308 /* TODO: implement me. */
313 * XPath: /frr-ripngd:ripngd/instance/redistribute
315 static int ripngd_instance_redistribute_create(enum nb_event event
,
316 const struct lyd_node
*dnode
,
317 union nb_resource
*resource
)
319 /* TODO: implement me. */
323 static int ripngd_instance_redistribute_delete(enum nb_event event
,
324 const struct lyd_node
*dnode
)
326 /* TODO: implement me. */
331 * XPath: /frr-ripngd:ripngd/instance/redistribute/route-map
334 ripngd_instance_redistribute_route_map_modify(enum nb_event event
,
335 const struct lyd_node
*dnode
,
336 union nb_resource
*resource
)
338 /* TODO: implement me. */
343 ripngd_instance_redistribute_route_map_delete(enum nb_event event
,
344 const struct lyd_node
*dnode
)
346 /* TODO: implement me. */
351 * XPath: /frr-ripngd:ripngd/instance/redistribute/metric
354 ripngd_instance_redistribute_metric_modify(enum nb_event event
,
355 const struct lyd_node
*dnode
,
356 union nb_resource
*resource
)
358 /* TODO: implement me. */
363 ripngd_instance_redistribute_metric_delete(enum nb_event event
,
364 const struct lyd_node
*dnode
)
366 /* TODO: implement me. */
371 * XPath: /frr-ripngd:ripngd/instance/static-route
373 static int ripngd_instance_static_route_create(enum nb_event event
,
374 const struct lyd_node
*dnode
,
375 union nb_resource
*resource
)
377 /* TODO: implement me. */
381 static int ripngd_instance_static_route_delete(enum nb_event event
,
382 const struct lyd_node
*dnode
)
384 /* TODO: implement me. */
389 * XPath: /frr-ripngd:ripngd/instance/aggregate-address
392 ripngd_instance_aggregate_address_create(enum nb_event event
,
393 const struct lyd_node
*dnode
,
394 union nb_resource
*resource
)
396 /* TODO: implement me. */
401 ripngd_instance_aggregate_address_delete(enum nb_event event
,
402 const struct lyd_node
*dnode
)
404 /* TODO: implement me. */
409 * XPath: /frr-ripngd:ripngd/instance/timers/flush-interval
412 ripngd_instance_timers_flush_interval_modify(enum nb_event event
,
413 const struct lyd_node
*dnode
,
414 union nb_resource
*resource
)
416 /* TODO: implement me. */
421 * XPath: /frr-ripngd:ripngd/instance/timers/holddown-interval
424 ripngd_instance_timers_holddown_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/update-interval
436 ripngd_instance_timers_update_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/state/neighbors/neighbor
448 ripngd_state_neighbors_neighbor_get_next(const void *parent_list_entry
,
449 const void *list_entry
)
451 /* TODO: implement me. */
455 static int ripngd_state_neighbors_neighbor_get_keys(const void *list_entry
,
456 struct yang_list_keys
*keys
)
458 /* TODO: implement me. */
463 ripngd_state_neighbors_neighbor_lookup_entry(const void *parent_list_entry
,
464 const struct yang_list_keys
*keys
)
466 /* TODO: implement me. */
471 * XPath: /frr-ripngd:ripngd/state/neighbors/neighbor/address
473 static struct yang_data
*
474 ripngd_state_neighbors_neighbor_address_get_elem(const char *xpath
,
475 const void *list_entry
)
477 /* TODO: implement me. */
482 * XPath: /frr-ripngd:ripngd/state/neighbors/neighbor/last-update
484 static struct yang_data
*
485 ripngd_state_neighbors_neighbor_last_update_get_elem(const char *xpath
,
486 const void *list_entry
)
488 /* TODO: implement me. */
493 * XPath: /frr-ripngd:ripngd/state/neighbors/neighbor/bad-packets-rcvd
495 static struct yang_data
*
496 ripngd_state_neighbors_neighbor_bad_packets_rcvd_get_elem(
497 const char *xpath
, const void *list_entry
)
499 /* TODO: implement me. */
504 * XPath: /frr-ripngd:ripngd/state/neighbors/neighbor/bad-routes-rcvd
506 static struct yang_data
*
507 ripngd_state_neighbors_neighbor_bad_routes_rcvd_get_elem(const char *xpath
,
508 const void *list_entry
)
510 /* TODO: implement me. */
515 * XPath: /frr-ripngd:ripngd/state/routes/route
518 ripngd_state_routes_route_get_next(const void *parent_list_entry
,
519 const void *list_entry
)
521 /* TODO: implement me. */
525 static int ripngd_state_routes_route_get_keys(const void *list_entry
,
526 struct yang_list_keys
*keys
)
528 /* TODO: implement me. */
533 ripngd_state_routes_route_lookup_entry(const void *parent_list_entry
,
534 const struct yang_list_keys
*keys
)
536 /* TODO: implement me. */
541 * XPath: /frr-ripngd:ripngd/state/routes/route/prefix
543 static struct yang_data
*
544 ripngd_state_routes_route_prefix_get_elem(const char *xpath
,
545 const void *list_entry
)
547 /* TODO: implement me. */
552 * XPath: /frr-ripngd:ripngd/state/routes/route/next-hop
554 static struct yang_data
*
555 ripngd_state_routes_route_next_hop_get_elem(const char *xpath
,
556 const void *list_entry
)
558 /* TODO: implement me. */
563 * XPath: /frr-ripngd:ripngd/state/routes/route/interface
565 static struct yang_data
*
566 ripngd_state_routes_route_interface_get_elem(const char *xpath
,
567 const void *list_entry
)
569 /* TODO: implement me. */
574 * XPath: /frr-ripngd:ripngd/state/routes/route/metric
576 static struct yang_data
*
577 ripngd_state_routes_route_metric_get_elem(const char *xpath
,
578 const void *list_entry
)
580 /* TODO: implement me. */
585 * XPath: /frr-ripngd:clear-ripng-route
587 static int clear_ripng_route_rpc(const char *xpath
, const struct list
*input
,
590 /* TODO: implement me. */
595 * XPath: /frr-interface:lib/interface/frr-ripngd:ripng/split-horizon
598 lib_interface_ripng_split_horizon_modify(enum nb_event event
,
599 const struct lyd_node
*dnode
,
600 union nb_resource
*resource
)
602 /* TODO: implement me. */
606 /* clang-format off */
607 const struct frr_yang_module_info frr_ripngd_info
= {
608 .name
= "frr-ripngd",
611 .xpath
= "/frr-ripngd:ripngd/instance",
612 .cbs
.create
= ripngd_instance_create
,
613 .cbs
.delete = ripngd_instance_delete
,
614 .cbs
.cli_show
= cli_show_router_ripng
,
617 .xpath
= "/frr-ripngd:ripngd/instance/allow-ecmp",
618 .cbs
.modify
= ripngd_instance_allow_ecmp_modify
,
619 .cbs
.cli_show
= cli_show_ripng_allow_ecmp
,
622 .xpath
= "/frr-ripngd:ripngd/instance/default-information-originate",
623 .cbs
.modify
= ripngd_instance_default_information_originate_modify
,
624 .cbs
.cli_show
= cli_show_ripng_default_information_originate
,
627 .xpath
= "/frr-ripngd:ripngd/instance/default-metric",
628 .cbs
.modify
= ripngd_instance_default_metric_modify
,
629 .cbs
.cli_show
= cli_show_ripng_default_metric
,
632 .xpath
= "/frr-ripngd:ripngd/instance/network",
633 .cbs
.create
= ripngd_instance_network_create
,
634 .cbs
.delete = ripngd_instance_network_delete
,
635 .cbs
.cli_show
= cli_show_ripng_network_prefix
,
638 .xpath
= "/frr-ripngd:ripngd/instance/interface",
639 .cbs
.create
= ripngd_instance_interface_create
,
640 .cbs
.delete = ripngd_instance_interface_delete
,
641 .cbs
.cli_show
= cli_show_ripng_network_interface
,
644 .xpath
= "/frr-ripngd:ripngd/instance/offset-list",
645 .cbs
.create
= ripngd_instance_offset_list_create
,
646 .cbs
.delete = ripngd_instance_offset_list_delete
,
647 .cbs
.cli_show
= cli_show_ripng_offset_list
,
650 .xpath
= "/frr-ripngd:ripngd/instance/offset-list/access-list",
651 .cbs
.modify
= ripngd_instance_offset_list_access_list_modify
,
654 .xpath
= "/frr-ripngd:ripngd/instance/offset-list/metric",
655 .cbs
.modify
= ripngd_instance_offset_list_metric_modify
,
658 .xpath
= "/frr-ripngd:ripngd/instance/passive-interface",
659 .cbs
.create
= ripngd_instance_passive_interface_create
,
660 .cbs
.delete = ripngd_instance_passive_interface_delete
,
663 .xpath
= "/frr-ripngd:ripngd/instance/redistribute",
664 .cbs
.create
= ripngd_instance_redistribute_create
,
665 .cbs
.delete = ripngd_instance_redistribute_delete
,
668 .xpath
= "/frr-ripngd:ripngd/instance/redistribute/route-map",
669 .cbs
.modify
= ripngd_instance_redistribute_route_map_modify
,
670 .cbs
.delete = ripngd_instance_redistribute_route_map_delete
,
673 .xpath
= "/frr-ripngd:ripngd/instance/redistribute/metric",
674 .cbs
.modify
= ripngd_instance_redistribute_metric_modify
,
675 .cbs
.delete = ripngd_instance_redistribute_metric_delete
,
678 .xpath
= "/frr-ripngd:ripngd/instance/static-route",
679 .cbs
.create
= ripngd_instance_static_route_create
,
680 .cbs
.delete = ripngd_instance_static_route_delete
,
683 .xpath
= "/frr-ripngd:ripngd/instance/aggregate-address",
684 .cbs
.create
= ripngd_instance_aggregate_address_create
,
685 .cbs
.delete = ripngd_instance_aggregate_address_delete
,
688 .xpath
= "/frr-ripngd:ripngd/instance/timers/flush-interval",
689 .cbs
.modify
= ripngd_instance_timers_flush_interval_modify
,
692 .xpath
= "/frr-ripngd:ripngd/instance/timers/holddown-interval",
693 .cbs
.modify
= ripngd_instance_timers_holddown_interval_modify
,
696 .xpath
= "/frr-ripngd:ripngd/instance/timers/update-interval",
697 .cbs
.modify
= ripngd_instance_timers_update_interval_modify
,
700 .xpath
= "/frr-ripngd:ripngd/state/neighbors/neighbor",
701 .cbs
.get_next
= ripngd_state_neighbors_neighbor_get_next
,
702 .cbs
.get_keys
= ripngd_state_neighbors_neighbor_get_keys
,
703 .cbs
.lookup_entry
= ripngd_state_neighbors_neighbor_lookup_entry
,
706 .xpath
= "/frr-ripngd:ripngd/state/neighbors/neighbor/address",
707 .cbs
.get_elem
= ripngd_state_neighbors_neighbor_address_get_elem
,
710 .xpath
= "/frr-ripngd:ripngd/state/neighbors/neighbor/last-update",
711 .cbs
.get_elem
= ripngd_state_neighbors_neighbor_last_update_get_elem
,
714 .xpath
= "/frr-ripngd:ripngd/state/neighbors/neighbor/bad-packets-rcvd",
715 .cbs
.get_elem
= ripngd_state_neighbors_neighbor_bad_packets_rcvd_get_elem
,
718 .xpath
= "/frr-ripngd:ripngd/state/neighbors/neighbor/bad-routes-rcvd",
719 .cbs
.get_elem
= ripngd_state_neighbors_neighbor_bad_routes_rcvd_get_elem
,
722 .xpath
= "/frr-ripngd:ripngd/state/routes/route",
723 .cbs
.get_next
= ripngd_state_routes_route_get_next
,
724 .cbs
.get_keys
= ripngd_state_routes_route_get_keys
,
725 .cbs
.lookup_entry
= ripngd_state_routes_route_lookup_entry
,
728 .xpath
= "/frr-ripngd:ripngd/state/routes/route/prefix",
729 .cbs
.get_elem
= ripngd_state_routes_route_prefix_get_elem
,
732 .xpath
= "/frr-ripngd:ripngd/state/routes/route/next-hop",
733 .cbs
.get_elem
= ripngd_state_routes_route_next_hop_get_elem
,
736 .xpath
= "/frr-ripngd:ripngd/state/routes/route/interface",
737 .cbs
.get_elem
= ripngd_state_routes_route_interface_get_elem
,
740 .xpath
= "/frr-ripngd:ripngd/state/routes/route/metric",
741 .cbs
.get_elem
= ripngd_state_routes_route_metric_get_elem
,
744 .xpath
= "/frr-ripngd:clear-ripng-route",
745 .cbs
.rpc
= clear_ripng_route_rpc
,
748 .xpath
= "/frr-interface:lib/interface/frr-ripngd:ripng/split-horizon",
749 .cbs
.modify
= lib_interface_ripng_split_horizon_modify
,