]>
git.proxmox.com Git - mirror_frr.git/blob - ripngd/ripng_nb_config.c
1 // SPDX-License-Identifier: GPL-2.0-or-later
3 * Copyright (C) 1998 Kunihiro Ishiguro
4 * Copyright (C) 2018 NetDEF, Inc.
17 #include "agg_table.h"
18 #include "northbound.h"
21 #include "ripngd/ripngd.h"
22 #include "ripngd/ripng_nb.h"
23 #include "ripngd/ripng_debug.h"
24 #include "ripngd/ripng_route.h"
27 * XPath: /frr-ripngd:ripngd/instance
29 int ripngd_instance_create(struct nb_cb_create_args
*args
)
36 vrf_name
= yang_dnode_get_string(args
->dnode
, "./vrf");
37 vrf
= vrf_lookup_by_name(vrf_name
);
40 * Try to create a RIPng socket only if the VRF is enabled, otherwise
41 * create a disabled RIPng instance and wait for the VRF to be enabled.
43 switch (args
->event
) {
47 if (!vrf
|| !vrf_is_enabled(vrf
))
50 socket
= ripng_make_socket(vrf
);
52 return NB_ERR_RESOURCE
;
53 args
->resource
->fd
= socket
;
56 if (!vrf
|| !vrf_is_enabled(vrf
))
59 socket
= args
->resource
->fd
;
63 if (vrf
&& vrf_is_enabled(vrf
))
64 socket
= args
->resource
->fd
;
68 ripng
= ripng_create(vrf_name
, vrf
, socket
);
69 nb_running_set_entry(args
->dnode
, ripng
);
76 int ripngd_instance_destroy(struct nb_cb_destroy_args
*args
)
80 if (args
->event
!= NB_EV_APPLY
)
83 ripng
= nb_running_unset_entry(args
->dnode
);
89 const void *ripngd_instance_get_next(struct nb_cb_get_next_args
*args
)
91 struct ripng
*ripng
= (struct ripng
*)args
->list_entry
;
93 if (args
->list_entry
== NULL
)
94 ripng
= RB_MIN(ripng_instance_head
, &ripng_instances
);
96 ripng
= RB_NEXT(ripng_instance_head
, ripng
);
101 int ripngd_instance_get_keys(struct nb_cb_get_keys_args
*args
)
103 const struct ripng
*ripng
= args
->list_entry
;
106 strlcpy(args
->keys
->key
[0], ripng
->vrf_name
,
107 sizeof(args
->keys
->key
[0]));
112 const void *ripngd_instance_lookup_entry(struct nb_cb_lookup_entry_args
*args
)
114 const char *vrf_name
= args
->keys
->key
[0];
116 return ripng_lookup_by_vrf_name(vrf_name
);
120 * XPath: /frr-ripngd:ripngd/instance/allow-ecmp
122 int ripngd_instance_allow_ecmp_modify(struct nb_cb_modify_args
*args
)
126 if (args
->event
!= NB_EV_APPLY
)
129 ripng
= nb_running_get_entry(args
->dnode
, NULL
, true);
130 ripng
->ecmp
= yang_dnode_get_bool(args
->dnode
, NULL
);
132 ripng_ecmp_disable(ripng
);
138 * XPath: /frr-ripngd:ripngd/instance/default-information-originate
140 int ripngd_instance_default_information_originate_modify(
141 struct nb_cb_modify_args
*args
)
144 bool default_information
;
145 struct prefix_ipv6 p
;
147 if (args
->event
!= NB_EV_APPLY
)
150 ripng
= nb_running_get_entry(args
->dnode
, NULL
, true);
151 default_information
= yang_dnode_get_bool(args
->dnode
, NULL
);
153 (void)str2prefix_ipv6("::/0", &p
);
154 if (default_information
) {
155 ripng_redistribute_add(ripng
, ZEBRA_ROUTE_RIPNG
,
156 RIPNG_ROUTE_DEFAULT
, &p
, 0, NULL
, 0);
158 ripng_redistribute_delete(ripng
, ZEBRA_ROUTE_RIPNG
,
159 RIPNG_ROUTE_DEFAULT
, &p
, 0);
166 * XPath: /frr-ripngd:ripngd/instance/default-metric
168 int ripngd_instance_default_metric_modify(struct nb_cb_modify_args
*args
)
172 if (args
->event
!= NB_EV_APPLY
)
175 ripng
= nb_running_get_entry(args
->dnode
, NULL
, true);
176 ripng
->default_metric
= yang_dnode_get_uint8(args
->dnode
, NULL
);
182 * XPath: /frr-ripngd:ripngd/instance/network
184 int ripngd_instance_network_create(struct nb_cb_create_args
*args
)
189 if (args
->event
!= NB_EV_APPLY
)
192 ripng
= nb_running_get_entry(args
->dnode
, NULL
, true);
193 yang_dnode_get_ipv6p(&p
, args
->dnode
, NULL
);
194 apply_mask_ipv6((struct prefix_ipv6
*)&p
);
196 return ripng_enable_network_add(ripng
, &p
);
199 int ripngd_instance_network_destroy(struct nb_cb_destroy_args
*args
)
204 if (args
->event
!= NB_EV_APPLY
)
207 ripng
= nb_running_get_entry(args
->dnode
, NULL
, true);
208 yang_dnode_get_ipv6p(&p
, args
->dnode
, NULL
);
209 apply_mask_ipv6((struct prefix_ipv6
*)&p
);
211 return ripng_enable_network_delete(ripng
, &p
);
215 * XPath: /frr-ripngd:ripngd/instance/interface
217 int ripngd_instance_interface_create(struct nb_cb_create_args
*args
)
222 if (args
->event
!= NB_EV_APPLY
)
225 ripng
= nb_running_get_entry(args
->dnode
, NULL
, true);
226 ifname
= yang_dnode_get_string(args
->dnode
, NULL
);
228 return ripng_enable_if_add(ripng
, ifname
);
231 int ripngd_instance_interface_destroy(struct nb_cb_destroy_args
*args
)
236 if (args
->event
!= NB_EV_APPLY
)
239 ripng
= nb_running_get_entry(args
->dnode
, NULL
, true);
240 ifname
= yang_dnode_get_string(args
->dnode
, NULL
);
242 return ripng_enable_if_delete(ripng
, ifname
);
246 * XPath: /frr-ripngd:ripngd/instance/offset-list
248 int ripngd_instance_offset_list_create(struct nb_cb_create_args
*args
)
252 struct ripng_offset_list
*offset
;
254 if (args
->event
!= NB_EV_APPLY
)
257 ripng
= nb_running_get_entry(args
->dnode
, NULL
, true);
258 ifname
= yang_dnode_get_string(args
->dnode
, "./interface");
260 offset
= ripng_offset_list_new(ripng
, ifname
);
261 nb_running_set_entry(args
->dnode
, offset
);
266 int ripngd_instance_offset_list_destroy(struct nb_cb_destroy_args
*args
)
269 struct ripng_offset_list
*offset
;
271 if (args
->event
!= NB_EV_APPLY
)
274 direct
= yang_dnode_get_enum(args
->dnode
, "./direction");
276 offset
= nb_running_unset_entry(args
->dnode
);
277 if (offset
->direct
[direct
].alist_name
) {
278 free(offset
->direct
[direct
].alist_name
);
279 offset
->direct
[direct
].alist_name
= NULL
;
281 if (offset
->direct
[RIPNG_OFFSET_LIST_IN
].alist_name
== NULL
282 && offset
->direct
[RIPNG_OFFSET_LIST_OUT
].alist_name
== NULL
)
283 ripng_offset_list_del(offset
);
289 * XPath: /frr-ripngd:ripngd/instance/offset-list/access-list
291 int ripngd_instance_offset_list_access_list_modify(
292 struct nb_cb_modify_args
*args
)
295 struct ripng_offset_list
*offset
;
296 const char *alist_name
;
298 if (args
->event
!= NB_EV_APPLY
)
301 direct
= yang_dnode_get_enum(args
->dnode
, "../direction");
302 alist_name
= yang_dnode_get_string(args
->dnode
, NULL
);
304 offset
= nb_running_get_entry(args
->dnode
, NULL
, true);
305 if (offset
->direct
[direct
].alist_name
)
306 free(offset
->direct
[direct
].alist_name
);
307 offset
->direct
[direct
].alist_name
= strdup(alist_name
);
313 * XPath: /frr-ripngd:ripngd/instance/offset-list/metric
315 int ripngd_instance_offset_list_metric_modify(struct nb_cb_modify_args
*args
)
319 struct ripng_offset_list
*offset
;
321 if (args
->event
!= NB_EV_APPLY
)
324 direct
= yang_dnode_get_enum(args
->dnode
, "../direction");
325 metric
= yang_dnode_get_uint8(args
->dnode
, NULL
);
327 offset
= nb_running_get_entry(args
->dnode
, NULL
, true);
328 offset
->direct
[direct
].metric
= metric
;
334 * XPath: /frr-ripngd:ripngd/instance/passive-interface
336 int ripngd_instance_passive_interface_create(struct nb_cb_create_args
*args
)
341 if (args
->event
!= NB_EV_APPLY
)
344 ripng
= nb_running_get_entry(args
->dnode
, NULL
, true);
345 ifname
= yang_dnode_get_string(args
->dnode
, NULL
);
347 return ripng_passive_interface_set(ripng
, ifname
);
350 int ripngd_instance_passive_interface_destroy(struct nb_cb_destroy_args
*args
)
355 if (args
->event
!= NB_EV_APPLY
)
358 ripng
= nb_running_get_entry(args
->dnode
, NULL
, true);
359 ifname
= yang_dnode_get_string(args
->dnode
, NULL
);
361 return ripng_passive_interface_unset(ripng
, ifname
);
365 * XPath: /frr-ripngd:ripngd/instance/redistribute
367 int ripngd_instance_redistribute_create(struct nb_cb_create_args
*args
)
372 if (args
->event
!= NB_EV_APPLY
)
375 ripng
= nb_running_get_entry(args
->dnode
, NULL
, true);
376 type
= yang_dnode_get_enum(args
->dnode
, "./protocol");
378 ripng
->redist
[type
].enabled
= true;
383 int ripngd_instance_redistribute_destroy(struct nb_cb_destroy_args
*args
)
388 if (args
->event
!= NB_EV_APPLY
)
391 ripng
= nb_running_get_entry(args
->dnode
, NULL
, true);
392 type
= yang_dnode_get_enum(args
->dnode
, "./protocol");
394 ripng
->redist
[type
].enabled
= false;
395 if (ripng
->redist
[type
].route_map
.name
) {
396 free(ripng
->redist
[type
].route_map
.name
);
397 ripng
->redist
[type
].route_map
.name
= NULL
;
398 ripng
->redist
[type
].route_map
.map
= NULL
;
400 ripng
->redist
[type
].metric_config
= false;
401 ripng
->redist
[type
].metric
= 0;
404 ripng_redistribute_conf_delete(ripng
, type
);
409 void ripngd_instance_redistribute_apply_finish(
410 struct nb_cb_apply_finish_args
*args
)
415 ripng
= nb_running_get_entry(args
->dnode
, NULL
, true);
416 type
= yang_dnode_get_enum(args
->dnode
, "./protocol");
419 ripng_redistribute_conf_update(ripng
, type
);
423 * XPath: /frr-ripngd:ripngd/instance/redistribute/route-map
425 int ripngd_instance_redistribute_route_map_modify(
426 struct nb_cb_modify_args
*args
)
430 const char *rmap_name
;
432 if (args
->event
!= NB_EV_APPLY
)
435 ripng
= nb_running_get_entry(args
->dnode
, NULL
, true);
436 type
= yang_dnode_get_enum(args
->dnode
, "../protocol");
437 rmap_name
= yang_dnode_get_string(args
->dnode
, NULL
);
439 if (ripng
->redist
[type
].route_map
.name
)
440 free(ripng
->redist
[type
].route_map
.name
);
441 ripng
->redist
[type
].route_map
.name
= strdup(rmap_name
);
442 ripng
->redist
[type
].route_map
.map
= route_map_lookup_by_name(rmap_name
);
447 int ripngd_instance_redistribute_route_map_destroy(
448 struct nb_cb_destroy_args
*args
)
453 if (args
->event
!= NB_EV_APPLY
)
456 ripng
= nb_running_get_entry(args
->dnode
, NULL
, true);
457 type
= yang_dnode_get_enum(args
->dnode
, "../protocol");
459 free(ripng
->redist
[type
].route_map
.name
);
460 ripng
->redist
[type
].route_map
.name
= NULL
;
461 ripng
->redist
[type
].route_map
.map
= NULL
;
467 * XPath: /frr-ripngd:ripngd/instance/redistribute/metric
469 int ripngd_instance_redistribute_metric_modify(struct nb_cb_modify_args
*args
)
475 if (args
->event
!= NB_EV_APPLY
)
478 ripng
= nb_running_get_entry(args
->dnode
, NULL
, true);
479 type
= yang_dnode_get_enum(args
->dnode
, "../protocol");
480 metric
= yang_dnode_get_uint8(args
->dnode
, NULL
);
482 ripng
->redist
[type
].metric_config
= true;
483 ripng
->redist
[type
].metric
= metric
;
488 int ripngd_instance_redistribute_metric_destroy(struct nb_cb_destroy_args
*args
)
493 if (args
->event
!= NB_EV_APPLY
)
496 ripng
= nb_running_get_entry(args
->dnode
, NULL
, true);
497 type
= yang_dnode_get_enum(args
->dnode
, "../protocol");
499 ripng
->redist
[type
].metric_config
= false;
500 ripng
->redist
[type
].metric
= 0;
506 * XPath: /frr-ripngd:ripngd/instance/static-route
508 int ripngd_instance_static_route_create(struct nb_cb_create_args
*args
)
511 struct prefix_ipv6 p
;
513 if (args
->event
!= NB_EV_APPLY
)
516 ripng
= nb_running_get_entry(args
->dnode
, NULL
, true);
517 yang_dnode_get_ipv6p(&p
, args
->dnode
, NULL
);
520 ripng_redistribute_add(ripng
, ZEBRA_ROUTE_RIPNG
, RIPNG_ROUTE_STATIC
, &p
,
526 int ripngd_instance_static_route_destroy(struct nb_cb_destroy_args
*args
)
529 struct prefix_ipv6 p
;
531 if (args
->event
!= NB_EV_APPLY
)
534 ripng
= nb_running_get_entry(args
->dnode
, NULL
, true);
535 yang_dnode_get_ipv6p(&p
, args
->dnode
, NULL
);
538 ripng_redistribute_delete(ripng
, ZEBRA_ROUTE_RIPNG
, RIPNG_ROUTE_STATIC
,
545 * XPath: /frr-ripngd:ripngd/instance/aggregate-address
547 int ripngd_instance_aggregate_address_create(struct nb_cb_create_args
*args
)
550 struct prefix_ipv6 p
;
552 if (args
->event
!= NB_EV_APPLY
)
555 ripng
= nb_running_get_entry(args
->dnode
, NULL
, true);
556 yang_dnode_get_ipv6p(&p
, args
->dnode
, NULL
);
559 ripng_aggregate_add(ripng
, (struct prefix
*)&p
);
564 int ripngd_instance_aggregate_address_destroy(struct nb_cb_destroy_args
*args
)
567 struct prefix_ipv6 p
;
569 if (args
->event
!= NB_EV_APPLY
)
572 ripng
= nb_running_get_entry(args
->dnode
, NULL
, true);
573 yang_dnode_get_ipv6p(&p
, args
->dnode
, NULL
);
576 ripng_aggregate_delete(ripng
, (struct prefix
*)&p
);
582 * XPath: /frr-ripngd:ripngd/instance/timers
584 void ripngd_instance_timers_apply_finish(struct nb_cb_apply_finish_args
*args
)
588 ripng
= nb_running_get_entry(args
->dnode
, NULL
, true);
590 /* Reset update timer thread. */
591 ripng_event(ripng
, RIPNG_UPDATE_EVENT
, 0);
595 * XPath: /frr-ripngd:ripngd/instance/timers/flush-interval
597 int ripngd_instance_timers_flush_interval_modify(struct nb_cb_modify_args
*args
)
601 if (args
->event
!= NB_EV_APPLY
)
604 ripng
= nb_running_get_entry(args
->dnode
, NULL
, true);
605 ripng
->garbage_time
= yang_dnode_get_uint16(args
->dnode
, NULL
);
611 * XPath: /frr-ripngd:ripngd/instance/timers/holddown-interval
613 int ripngd_instance_timers_holddown_interval_modify(
614 struct nb_cb_modify_args
*args
)
618 if (args
->event
!= NB_EV_APPLY
)
621 ripng
= nb_running_get_entry(args
->dnode
, NULL
, true);
622 ripng
->timeout_time
= yang_dnode_get_uint16(args
->dnode
, NULL
);
628 * XPath: /frr-ripngd:ripngd/instance/timers/update-interval
630 int ripngd_instance_timers_update_interval_modify(
631 struct nb_cb_modify_args
*args
)
635 if (args
->event
!= NB_EV_APPLY
)
638 ripng
= nb_running_get_entry(args
->dnode
, NULL
, true);
639 ripng
->update_time
= yang_dnode_get_uint16(args
->dnode
, NULL
);
645 * XPath: /frr-interface:lib/interface/frr-ripngd:ripng/split-horizon
647 int lib_interface_ripng_split_horizon_modify(struct nb_cb_modify_args
*args
)
649 struct interface
*ifp
;
650 struct ripng_interface
*ri
;
652 if (args
->event
!= NB_EV_APPLY
)
655 ifp
= nb_running_get_entry(args
->dnode
, NULL
, true);
657 ri
->split_horizon
= yang_dnode_get_enum(args
->dnode
, NULL
);