]>
git.proxmox.com Git - mirror_frr.git/blob - ripngd/ripng_nb_config.c
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 "agg_table.h"
31 #include "northbound.h"
34 #include "ripngd/ripngd.h"
35 #include "ripngd/ripng_nb.h"
36 #include "ripngd/ripng_debug.h"
37 #include "ripngd/ripng_route.h"
40 * XPath: /frr-ripngd:ripngd/instance
42 int ripngd_instance_create(struct nb_cb_create_args
*args
)
49 vrf_name
= yang_dnode_get_string(args
->dnode
, "./vrf");
50 vrf
= vrf_lookup_by_name(vrf_name
);
53 * Try to create a RIPng socket only if the VRF is enabled, otherwise
54 * create a disabled RIPng instance and wait for the VRF to be enabled.
56 switch (args
->event
) {
60 if (!vrf
|| !vrf_is_enabled(vrf
))
63 socket
= ripng_make_socket(vrf
);
65 return NB_ERR_RESOURCE
;
66 args
->resource
->fd
= socket
;
69 if (!vrf
|| !vrf_is_enabled(vrf
))
72 socket
= args
->resource
->fd
;
76 if (vrf
&& vrf_is_enabled(vrf
))
77 socket
= args
->resource
->fd
;
81 ripng
= ripng_create(vrf_name
, vrf
, socket
);
82 nb_running_set_entry(args
->dnode
, ripng
);
89 int ripngd_instance_destroy(struct nb_cb_destroy_args
*args
)
93 if (args
->event
!= NB_EV_APPLY
)
96 ripng
= nb_running_unset_entry(args
->dnode
);
102 const void *ripngd_instance_get_next(struct nb_cb_get_next_args
*args
)
104 struct ripng
*ripng
= (struct ripng
*)args
->list_entry
;
106 if (args
->list_entry
== NULL
)
107 ripng
= RB_MIN(ripng_instance_head
, &ripng_instances
);
109 ripng
= RB_NEXT(ripng_instance_head
, ripng
);
114 int ripngd_instance_get_keys(struct nb_cb_get_keys_args
*args
)
116 const struct ripng
*ripng
= args
->list_entry
;
119 strlcpy(args
->keys
->key
[0], ripng
->vrf_name
,
120 sizeof(args
->keys
->key
[0]));
125 const void *ripngd_instance_lookup_entry(struct nb_cb_lookup_entry_args
*args
)
127 const char *vrf_name
= args
->keys
->key
[0];
129 return ripng_lookup_by_vrf_name(vrf_name
);
133 * XPath: /frr-ripngd:ripngd/instance/allow-ecmp
135 int ripngd_instance_allow_ecmp_modify(struct nb_cb_modify_args
*args
)
139 if (args
->event
!= NB_EV_APPLY
)
142 ripng
= nb_running_get_entry(args
->dnode
, NULL
, true);
143 ripng
->ecmp
= yang_dnode_get_bool(args
->dnode
, NULL
);
145 ripng_ecmp_disable(ripng
);
151 * XPath: /frr-ripngd:ripngd/instance/default-information-originate
153 int ripngd_instance_default_information_originate_modify(
154 struct nb_cb_modify_args
*args
)
157 bool default_information
;
158 struct prefix_ipv6 p
;
160 if (args
->event
!= NB_EV_APPLY
)
163 ripng
= nb_running_get_entry(args
->dnode
, NULL
, true);
164 default_information
= yang_dnode_get_bool(args
->dnode
, NULL
);
166 (void)str2prefix_ipv6("::/0", &p
);
167 if (default_information
) {
168 ripng_redistribute_add(ripng
, ZEBRA_ROUTE_RIPNG
,
169 RIPNG_ROUTE_DEFAULT
, &p
, 0, NULL
, 0);
171 ripng_redistribute_delete(ripng
, ZEBRA_ROUTE_RIPNG
,
172 RIPNG_ROUTE_DEFAULT
, &p
, 0);
179 * XPath: /frr-ripngd:ripngd/instance/default-metric
181 int ripngd_instance_default_metric_modify(struct nb_cb_modify_args
*args
)
185 if (args
->event
!= NB_EV_APPLY
)
188 ripng
= nb_running_get_entry(args
->dnode
, NULL
, true);
189 ripng
->default_metric
= yang_dnode_get_uint8(args
->dnode
, NULL
);
195 * XPath: /frr-ripngd:ripngd/instance/network
197 int ripngd_instance_network_create(struct nb_cb_create_args
*args
)
202 if (args
->event
!= NB_EV_APPLY
)
205 ripng
= nb_running_get_entry(args
->dnode
, NULL
, true);
206 yang_dnode_get_ipv6p(&p
, args
->dnode
, NULL
);
207 apply_mask_ipv6((struct prefix_ipv6
*)&p
);
209 return ripng_enable_network_add(ripng
, &p
);
212 int ripngd_instance_network_destroy(struct nb_cb_destroy_args
*args
)
217 if (args
->event
!= NB_EV_APPLY
)
220 ripng
= nb_running_get_entry(args
->dnode
, NULL
, true);
221 yang_dnode_get_ipv6p(&p
, args
->dnode
, NULL
);
222 apply_mask_ipv6((struct prefix_ipv6
*)&p
);
224 return ripng_enable_network_delete(ripng
, &p
);
228 * XPath: /frr-ripngd:ripngd/instance/interface
230 int ripngd_instance_interface_create(struct nb_cb_create_args
*args
)
235 if (args
->event
!= NB_EV_APPLY
)
238 ripng
= nb_running_get_entry(args
->dnode
, NULL
, true);
239 ifname
= yang_dnode_get_string(args
->dnode
, NULL
);
241 return ripng_enable_if_add(ripng
, ifname
);
244 int ripngd_instance_interface_destroy(struct nb_cb_destroy_args
*args
)
249 if (args
->event
!= NB_EV_APPLY
)
252 ripng
= nb_running_get_entry(args
->dnode
, NULL
, true);
253 ifname
= yang_dnode_get_string(args
->dnode
, NULL
);
255 return ripng_enable_if_delete(ripng
, ifname
);
259 * XPath: /frr-ripngd:ripngd/instance/offset-list
261 int ripngd_instance_offset_list_create(struct nb_cb_create_args
*args
)
265 struct ripng_offset_list
*offset
;
267 if (args
->event
!= NB_EV_APPLY
)
270 ripng
= nb_running_get_entry(args
->dnode
, NULL
, true);
271 ifname
= yang_dnode_get_string(args
->dnode
, "./interface");
273 offset
= ripng_offset_list_new(ripng
, ifname
);
274 nb_running_set_entry(args
->dnode
, offset
);
279 int ripngd_instance_offset_list_destroy(struct nb_cb_destroy_args
*args
)
282 struct ripng_offset_list
*offset
;
284 if (args
->event
!= NB_EV_APPLY
)
287 direct
= yang_dnode_get_enum(args
->dnode
, "./direction");
289 offset
= nb_running_unset_entry(args
->dnode
);
290 if (offset
->direct
[direct
].alist_name
) {
291 free(offset
->direct
[direct
].alist_name
);
292 offset
->direct
[direct
].alist_name
= NULL
;
294 if (offset
->direct
[RIPNG_OFFSET_LIST_IN
].alist_name
== NULL
295 && offset
->direct
[RIPNG_OFFSET_LIST_OUT
].alist_name
== NULL
)
296 ripng_offset_list_del(offset
);
302 * XPath: /frr-ripngd:ripngd/instance/offset-list/access-list
304 int ripngd_instance_offset_list_access_list_modify(
305 struct nb_cb_modify_args
*args
)
308 struct ripng_offset_list
*offset
;
309 const char *alist_name
;
311 if (args
->event
!= NB_EV_APPLY
)
314 direct
= yang_dnode_get_enum(args
->dnode
, "../direction");
315 alist_name
= yang_dnode_get_string(args
->dnode
, NULL
);
317 offset
= nb_running_get_entry(args
->dnode
, NULL
, true);
318 if (offset
->direct
[direct
].alist_name
)
319 free(offset
->direct
[direct
].alist_name
);
320 offset
->direct
[direct
].alist_name
= strdup(alist_name
);
326 * XPath: /frr-ripngd:ripngd/instance/offset-list/metric
328 int ripngd_instance_offset_list_metric_modify(struct nb_cb_modify_args
*args
)
332 struct ripng_offset_list
*offset
;
334 if (args
->event
!= NB_EV_APPLY
)
337 direct
= yang_dnode_get_enum(args
->dnode
, "../direction");
338 metric
= yang_dnode_get_uint8(args
->dnode
, NULL
);
340 offset
= nb_running_get_entry(args
->dnode
, NULL
, true);
341 offset
->direct
[direct
].metric
= metric
;
347 * XPath: /frr-ripngd:ripngd/instance/passive-interface
349 int ripngd_instance_passive_interface_create(struct nb_cb_create_args
*args
)
354 if (args
->event
!= NB_EV_APPLY
)
357 ripng
= nb_running_get_entry(args
->dnode
, NULL
, true);
358 ifname
= yang_dnode_get_string(args
->dnode
, NULL
);
360 return ripng_passive_interface_set(ripng
, ifname
);
363 int ripngd_instance_passive_interface_destroy(struct nb_cb_destroy_args
*args
)
368 if (args
->event
!= NB_EV_APPLY
)
371 ripng
= nb_running_get_entry(args
->dnode
, NULL
, true);
372 ifname
= yang_dnode_get_string(args
->dnode
, NULL
);
374 return ripng_passive_interface_unset(ripng
, ifname
);
378 * XPath: /frr-ripngd:ripngd/instance/redistribute
380 int ripngd_instance_redistribute_create(struct nb_cb_create_args
*args
)
385 if (args
->event
!= NB_EV_APPLY
)
388 ripng
= nb_running_get_entry(args
->dnode
, NULL
, true);
389 type
= yang_dnode_get_enum(args
->dnode
, "./protocol");
391 ripng
->redist
[type
].enabled
= true;
396 int ripngd_instance_redistribute_destroy(struct nb_cb_destroy_args
*args
)
401 if (args
->event
!= NB_EV_APPLY
)
404 ripng
= nb_running_get_entry(args
->dnode
, NULL
, true);
405 type
= yang_dnode_get_enum(args
->dnode
, "./protocol");
407 ripng
->redist
[type
].enabled
= false;
408 if (ripng
->redist
[type
].route_map
.name
) {
409 free(ripng
->redist
[type
].route_map
.name
);
410 ripng
->redist
[type
].route_map
.name
= NULL
;
411 ripng
->redist
[type
].route_map
.map
= NULL
;
413 ripng
->redist
[type
].metric_config
= false;
414 ripng
->redist
[type
].metric
= 0;
417 ripng_redistribute_conf_delete(ripng
, type
);
422 void ripngd_instance_redistribute_apply_finish(
423 struct nb_cb_apply_finish_args
*args
)
428 ripng
= nb_running_get_entry(args
->dnode
, NULL
, true);
429 type
= yang_dnode_get_enum(args
->dnode
, "./protocol");
432 ripng_redistribute_conf_update(ripng
, type
);
436 * XPath: /frr-ripngd:ripngd/instance/redistribute/route-map
438 int ripngd_instance_redistribute_route_map_modify(
439 struct nb_cb_modify_args
*args
)
443 const char *rmap_name
;
445 if (args
->event
!= NB_EV_APPLY
)
448 ripng
= nb_running_get_entry(args
->dnode
, NULL
, true);
449 type
= yang_dnode_get_enum(args
->dnode
, "../protocol");
450 rmap_name
= yang_dnode_get_string(args
->dnode
, NULL
);
452 if (ripng
->redist
[type
].route_map
.name
)
453 free(ripng
->redist
[type
].route_map
.name
);
454 ripng
->redist
[type
].route_map
.name
= strdup(rmap_name
);
455 ripng
->redist
[type
].route_map
.map
= route_map_lookup_by_name(rmap_name
);
460 int ripngd_instance_redistribute_route_map_destroy(
461 struct nb_cb_destroy_args
*args
)
466 if (args
->event
!= NB_EV_APPLY
)
469 ripng
= nb_running_get_entry(args
->dnode
, NULL
, true);
470 type
= yang_dnode_get_enum(args
->dnode
, "../protocol");
472 free(ripng
->redist
[type
].route_map
.name
);
473 ripng
->redist
[type
].route_map
.name
= NULL
;
474 ripng
->redist
[type
].route_map
.map
= NULL
;
480 * XPath: /frr-ripngd:ripngd/instance/redistribute/metric
482 int ripngd_instance_redistribute_metric_modify(struct nb_cb_modify_args
*args
)
488 if (args
->event
!= NB_EV_APPLY
)
491 ripng
= nb_running_get_entry(args
->dnode
, NULL
, true);
492 type
= yang_dnode_get_enum(args
->dnode
, "../protocol");
493 metric
= yang_dnode_get_uint8(args
->dnode
, NULL
);
495 ripng
->redist
[type
].metric_config
= true;
496 ripng
->redist
[type
].metric
= metric
;
501 int ripngd_instance_redistribute_metric_destroy(struct nb_cb_destroy_args
*args
)
506 if (args
->event
!= NB_EV_APPLY
)
509 ripng
= nb_running_get_entry(args
->dnode
, NULL
, true);
510 type
= yang_dnode_get_enum(args
->dnode
, "../protocol");
512 ripng
->redist
[type
].metric_config
= false;
513 ripng
->redist
[type
].metric
= 0;
519 * XPath: /frr-ripngd:ripngd/instance/static-route
521 int ripngd_instance_static_route_create(struct nb_cb_create_args
*args
)
524 struct prefix_ipv6 p
;
526 if (args
->event
!= NB_EV_APPLY
)
529 ripng
= nb_running_get_entry(args
->dnode
, NULL
, true);
530 yang_dnode_get_ipv6p(&p
, args
->dnode
, NULL
);
533 ripng_redistribute_add(ripng
, ZEBRA_ROUTE_RIPNG
, RIPNG_ROUTE_STATIC
, &p
,
539 int ripngd_instance_static_route_destroy(struct nb_cb_destroy_args
*args
)
542 struct prefix_ipv6 p
;
544 if (args
->event
!= NB_EV_APPLY
)
547 ripng
= nb_running_get_entry(args
->dnode
, NULL
, true);
548 yang_dnode_get_ipv6p(&p
, args
->dnode
, NULL
);
551 ripng_redistribute_delete(ripng
, ZEBRA_ROUTE_RIPNG
, RIPNG_ROUTE_STATIC
,
558 * XPath: /frr-ripngd:ripngd/instance/aggregate-address
560 int ripngd_instance_aggregate_address_create(struct nb_cb_create_args
*args
)
563 struct prefix_ipv6 p
;
565 if (args
->event
!= NB_EV_APPLY
)
568 ripng
= nb_running_get_entry(args
->dnode
, NULL
, true);
569 yang_dnode_get_ipv6p(&p
, args
->dnode
, NULL
);
572 ripng_aggregate_add(ripng
, (struct prefix
*)&p
);
577 int ripngd_instance_aggregate_address_destroy(struct nb_cb_destroy_args
*args
)
580 struct prefix_ipv6 p
;
582 if (args
->event
!= NB_EV_APPLY
)
585 ripng
= nb_running_get_entry(args
->dnode
, NULL
, true);
586 yang_dnode_get_ipv6p(&p
, args
->dnode
, NULL
);
589 ripng_aggregate_delete(ripng
, (struct prefix
*)&p
);
595 * XPath: /frr-ripngd:ripngd/instance/timers
597 void ripngd_instance_timers_apply_finish(struct nb_cb_apply_finish_args
*args
)
601 ripng
= nb_running_get_entry(args
->dnode
, NULL
, true);
603 /* Reset update timer thread. */
604 ripng_event(ripng
, RIPNG_UPDATE_EVENT
, 0);
608 * XPath: /frr-ripngd:ripngd/instance/timers/flush-interval
610 int ripngd_instance_timers_flush_interval_modify(struct nb_cb_modify_args
*args
)
614 if (args
->event
!= NB_EV_APPLY
)
617 ripng
= nb_running_get_entry(args
->dnode
, NULL
, true);
618 ripng
->garbage_time
= yang_dnode_get_uint16(args
->dnode
, NULL
);
624 * XPath: /frr-ripngd:ripngd/instance/timers/holddown-interval
626 int ripngd_instance_timers_holddown_interval_modify(
627 struct nb_cb_modify_args
*args
)
631 if (args
->event
!= NB_EV_APPLY
)
634 ripng
= nb_running_get_entry(args
->dnode
, NULL
, true);
635 ripng
->timeout_time
= yang_dnode_get_uint16(args
->dnode
, NULL
);
641 * XPath: /frr-ripngd:ripngd/instance/timers/update-interval
643 int ripngd_instance_timers_update_interval_modify(
644 struct nb_cb_modify_args
*args
)
648 if (args
->event
!= NB_EV_APPLY
)
651 ripng
= nb_running_get_entry(args
->dnode
, NULL
, true);
652 ripng
->update_time
= yang_dnode_get_uint16(args
->dnode
, NULL
);
658 * XPath: /frr-interface:lib/interface/frr-ripngd:ripng/split-horizon
660 int lib_interface_ripng_split_horizon_modify(struct nb_cb_modify_args
*args
)
662 struct interface
*ifp
;
663 struct ripng_interface
*ri
;
665 if (args
->event
!= NB_EV_APPLY
)
668 ifp
= nb_running_get_entry(args
->dnode
, NULL
, true);
670 ri
->split_horizon
= yang_dnode_get_enum(args
->dnode
, NULL
);