]>
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(enum nb_event event
, const struct lyd_node
*dnode
,
43 union nb_resource
*resource
)
50 vrf_name
= yang_dnode_get_string(dnode
, "./vrf");
51 vrf
= vrf_lookup_by_name(vrf_name
);
54 * Try to create a RIPng socket only if the VRF is enabled, otherwise
55 * create a disabled RIPng instance and wait for the VRF to be enabled.
61 if (!vrf
|| !vrf_is_enabled(vrf
))
64 socket
= ripng_make_socket(vrf
);
66 return NB_ERR_RESOURCE
;
67 resource
->fd
= socket
;
70 if (!vrf
|| !vrf_is_enabled(vrf
))
73 socket
= resource
->fd
;
77 if (vrf
&& vrf_is_enabled(vrf
))
78 socket
= resource
->fd
;
82 ripng
= ripng_create(vrf_name
, vrf
, socket
);
83 nb_running_set_entry(dnode
, ripng
);
90 int ripngd_instance_destroy(enum nb_event event
, const struct lyd_node
*dnode
)
94 if (event
!= NB_EV_APPLY
)
97 ripng
= nb_running_unset_entry(dnode
);
103 const void *ripngd_instance_get_next(const void *parent_list_entry
,
104 const void *list_entry
)
106 struct ripng
*ripng
= (struct ripng
*)list_entry
;
108 if (list_entry
== NULL
)
109 ripng
= RB_MIN(ripng_instance_head
, &ripng_instances
);
111 ripng
= RB_NEXT(ripng_instance_head
, ripng
);
116 int ripngd_instance_get_keys(const void *list_entry
,
117 struct yang_list_keys
*keys
)
119 const struct ripng
*ripng
= list_entry
;
122 strlcpy(keys
->key
[0], ripng
->vrf_name
, sizeof(keys
->key
[0]));
127 const void *ripngd_instance_lookup_entry(const void *parent_list_entry
,
128 const struct yang_list_keys
*keys
)
130 const char *vrf_name
= keys
->key
[0];
132 return ripng_lookup_by_vrf_name(vrf_name
);
136 * XPath: /frr-ripngd:ripngd/instance/allow-ecmp
138 int ripngd_instance_allow_ecmp_modify(enum nb_event event
,
139 const struct lyd_node
*dnode
,
140 union nb_resource
*resource
)
144 if (event
!= NB_EV_APPLY
)
147 ripng
= nb_running_get_entry(dnode
, NULL
, true);
148 ripng
->ecmp
= yang_dnode_get_bool(dnode
, NULL
);
150 ripng_ecmp_disable(ripng
);
156 * XPath: /frr-ripngd:ripngd/instance/default-information-originate
158 int ripngd_instance_default_information_originate_modify(
159 enum nb_event event
, const struct lyd_node
*dnode
,
160 union nb_resource
*resource
)
163 bool default_information
;
164 struct prefix_ipv6 p
;
166 if (event
!= NB_EV_APPLY
)
169 ripng
= nb_running_get_entry(dnode
, NULL
, true);
170 default_information
= yang_dnode_get_bool(dnode
, NULL
);
172 str2prefix_ipv6("::/0", &p
);
173 if (default_information
) {
174 ripng_redistribute_add(ripng
, ZEBRA_ROUTE_RIPNG
,
175 RIPNG_ROUTE_DEFAULT
, &p
, 0, NULL
, 0);
177 ripng_redistribute_delete(ripng
, ZEBRA_ROUTE_RIPNG
,
178 RIPNG_ROUTE_DEFAULT
, &p
, 0);
185 * XPath: /frr-ripngd:ripngd/instance/default-metric
187 int ripngd_instance_default_metric_modify(enum nb_event event
,
188 const struct lyd_node
*dnode
,
189 union nb_resource
*resource
)
193 if (event
!= NB_EV_APPLY
)
196 ripng
= nb_running_get_entry(dnode
, NULL
, true);
197 ripng
->default_metric
= yang_dnode_get_uint8(dnode
, NULL
);
203 * XPath: /frr-ripngd:ripngd/instance/network
205 int ripngd_instance_network_create(enum nb_event event
,
206 const struct lyd_node
*dnode
,
207 union nb_resource
*resource
)
212 if (event
!= NB_EV_APPLY
)
215 ripng
= nb_running_get_entry(dnode
, NULL
, true);
216 yang_dnode_get_ipv6p(&p
, dnode
, NULL
);
217 apply_mask_ipv6((struct prefix_ipv6
*)&p
);
219 return ripng_enable_network_add(ripng
, &p
);
222 int ripngd_instance_network_destroy(enum nb_event event
,
223 const struct lyd_node
*dnode
)
228 if (event
!= NB_EV_APPLY
)
231 ripng
= nb_running_get_entry(dnode
, NULL
, true);
232 yang_dnode_get_ipv6p(&p
, dnode
, NULL
);
233 apply_mask_ipv6((struct prefix_ipv6
*)&p
);
235 return ripng_enable_network_delete(ripng
, &p
);
239 * XPath: /frr-ripngd:ripngd/instance/interface
241 int ripngd_instance_interface_create(enum nb_event event
,
242 const struct lyd_node
*dnode
,
243 union nb_resource
*resource
)
248 if (event
!= NB_EV_APPLY
)
251 ripng
= nb_running_get_entry(dnode
, NULL
, true);
252 ifname
= yang_dnode_get_string(dnode
, NULL
);
254 return ripng_enable_if_add(ripng
, ifname
);
257 int ripngd_instance_interface_destroy(enum nb_event event
,
258 const struct lyd_node
*dnode
)
263 if (event
!= NB_EV_APPLY
)
266 ripng
= nb_running_get_entry(dnode
, NULL
, true);
267 ifname
= yang_dnode_get_string(dnode
, NULL
);
269 return ripng_enable_if_delete(ripng
, ifname
);
273 * XPath: /frr-ripngd:ripngd/instance/offset-list
275 int ripngd_instance_offset_list_create(enum nb_event event
,
276 const struct lyd_node
*dnode
,
277 union nb_resource
*resource
)
281 struct ripng_offset_list
*offset
;
283 if (event
!= NB_EV_APPLY
)
286 ripng
= nb_running_get_entry(dnode
, NULL
, true);
287 ifname
= yang_dnode_get_string(dnode
, "./interface");
289 offset
= ripng_offset_list_new(ripng
, ifname
);
290 nb_running_set_entry(dnode
, offset
);
295 int ripngd_instance_offset_list_destroy(enum nb_event event
,
296 const struct lyd_node
*dnode
)
299 struct ripng_offset_list
*offset
;
301 if (event
!= NB_EV_APPLY
)
304 direct
= yang_dnode_get_enum(dnode
, "./direction");
306 offset
= nb_running_unset_entry(dnode
);
307 if (offset
->direct
[direct
].alist_name
) {
308 free(offset
->direct
[direct
].alist_name
);
309 offset
->direct
[direct
].alist_name
= NULL
;
311 if (offset
->direct
[RIPNG_OFFSET_LIST_IN
].alist_name
== NULL
312 && offset
->direct
[RIPNG_OFFSET_LIST_OUT
].alist_name
== NULL
)
313 ripng_offset_list_del(offset
);
319 * XPath: /frr-ripngd:ripngd/instance/offset-list/access-list
321 int ripngd_instance_offset_list_access_list_modify(enum nb_event event
,
322 const struct lyd_node
*dnode
,
323 union nb_resource
*resource
)
326 struct ripng_offset_list
*offset
;
327 const char *alist_name
;
329 if (event
!= NB_EV_APPLY
)
332 direct
= yang_dnode_get_enum(dnode
, "../direction");
333 alist_name
= yang_dnode_get_string(dnode
, NULL
);
335 offset
= nb_running_get_entry(dnode
, NULL
, true);
336 if (offset
->direct
[direct
].alist_name
)
337 free(offset
->direct
[direct
].alist_name
);
338 offset
->direct
[direct
].alist_name
= strdup(alist_name
);
344 * XPath: /frr-ripngd:ripngd/instance/offset-list/metric
346 int ripngd_instance_offset_list_metric_modify(enum nb_event event
,
347 const struct lyd_node
*dnode
,
348 union nb_resource
*resource
)
352 struct ripng_offset_list
*offset
;
354 if (event
!= NB_EV_APPLY
)
357 direct
= yang_dnode_get_enum(dnode
, "../direction");
358 metric
= yang_dnode_get_uint8(dnode
, NULL
);
360 offset
= nb_running_get_entry(dnode
, NULL
, true);
361 offset
->direct
[direct
].metric
= metric
;
367 * XPath: /frr-ripngd:ripngd/instance/passive-interface
369 int ripngd_instance_passive_interface_create(enum nb_event event
,
370 const struct lyd_node
*dnode
,
371 union nb_resource
*resource
)
376 if (event
!= NB_EV_APPLY
)
379 ripng
= nb_running_get_entry(dnode
, NULL
, true);
380 ifname
= yang_dnode_get_string(dnode
, NULL
);
382 return ripng_passive_interface_set(ripng
, ifname
);
385 int ripngd_instance_passive_interface_destroy(enum nb_event event
,
386 const struct lyd_node
*dnode
)
391 if (event
!= NB_EV_APPLY
)
394 ripng
= nb_running_get_entry(dnode
, NULL
, true);
395 ifname
= yang_dnode_get_string(dnode
, NULL
);
397 return ripng_passive_interface_unset(ripng
, ifname
);
401 * XPath: /frr-ripngd:ripngd/instance/redistribute
403 int ripngd_instance_redistribute_create(enum nb_event event
,
404 const struct lyd_node
*dnode
,
405 union nb_resource
*resource
)
410 if (event
!= NB_EV_APPLY
)
413 ripng
= nb_running_get_entry(dnode
, NULL
, true);
414 type
= yang_dnode_get_enum(dnode
, "./protocol");
416 ripng
->redist
[type
].enabled
= true;
421 int ripngd_instance_redistribute_destroy(enum nb_event event
,
422 const struct lyd_node
*dnode
)
427 if (event
!= NB_EV_APPLY
)
430 ripng
= nb_running_get_entry(dnode
, NULL
, true);
431 type
= yang_dnode_get_enum(dnode
, "./protocol");
433 ripng
->redist
[type
].enabled
= false;
434 if (ripng
->redist
[type
].route_map
.name
) {
435 free(ripng
->redist
[type
].route_map
.name
);
436 ripng
->redist
[type
].route_map
.name
= NULL
;
437 ripng
->redist
[type
].route_map
.map
= NULL
;
439 ripng
->redist
[type
].metric_config
= false;
440 ripng
->redist
[type
].metric
= 0;
443 ripng_redistribute_conf_delete(ripng
, type
);
448 void ripngd_instance_redistribute_apply_finish(const struct lyd_node
*dnode
)
453 ripng
= nb_running_get_entry(dnode
, NULL
, true);
454 type
= yang_dnode_get_enum(dnode
, "./protocol");
457 ripng_redistribute_conf_update(ripng
, type
);
461 * XPath: /frr-ripngd:ripngd/instance/redistribute/route-map
463 int ripngd_instance_redistribute_route_map_modify(enum nb_event event
,
464 const struct lyd_node
*dnode
,
465 union nb_resource
*resource
)
469 const char *rmap_name
;
471 if (event
!= NB_EV_APPLY
)
474 ripng
= nb_running_get_entry(dnode
, NULL
, true);
475 type
= yang_dnode_get_enum(dnode
, "../protocol");
476 rmap_name
= yang_dnode_get_string(dnode
, NULL
);
478 if (ripng
->redist
[type
].route_map
.name
)
479 free(ripng
->redist
[type
].route_map
.name
);
480 ripng
->redist
[type
].route_map
.name
= strdup(rmap_name
);
481 ripng
->redist
[type
].route_map
.map
= route_map_lookup_by_name(rmap_name
);
486 int ripngd_instance_redistribute_route_map_destroy(enum nb_event event
,
487 const struct lyd_node
*dnode
)
492 if (event
!= NB_EV_APPLY
)
495 ripng
= nb_running_get_entry(dnode
, NULL
, true);
496 type
= yang_dnode_get_enum(dnode
, "../protocol");
498 free(ripng
->redist
[type
].route_map
.name
);
499 ripng
->redist
[type
].route_map
.name
= NULL
;
500 ripng
->redist
[type
].route_map
.map
= NULL
;
506 * XPath: /frr-ripngd:ripngd/instance/redistribute/metric
508 int ripngd_instance_redistribute_metric_modify(enum nb_event event
,
509 const struct lyd_node
*dnode
,
510 union nb_resource
*resource
)
516 if (event
!= NB_EV_APPLY
)
519 ripng
= nb_running_get_entry(dnode
, NULL
, true);
520 type
= yang_dnode_get_enum(dnode
, "../protocol");
521 metric
= yang_dnode_get_uint8(dnode
, NULL
);
523 ripng
->redist
[type
].metric_config
= true;
524 ripng
->redist
[type
].metric
= metric
;
529 int ripngd_instance_redistribute_metric_destroy(enum nb_event event
,
530 const struct lyd_node
*dnode
)
535 if (event
!= NB_EV_APPLY
)
538 ripng
= nb_running_get_entry(dnode
, NULL
, true);
539 type
= yang_dnode_get_enum(dnode
, "../protocol");
541 ripng
->redist
[type
].metric_config
= false;
542 ripng
->redist
[type
].metric
= 0;
548 * XPath: /frr-ripngd:ripngd/instance/static-route
550 int ripngd_instance_static_route_create(enum nb_event event
,
551 const struct lyd_node
*dnode
,
552 union nb_resource
*resource
)
555 struct prefix_ipv6 p
;
557 if (event
!= NB_EV_APPLY
)
560 ripng
= nb_running_get_entry(dnode
, NULL
, true);
561 yang_dnode_get_ipv6p(&p
, dnode
, NULL
);
564 ripng_redistribute_add(ripng
, ZEBRA_ROUTE_RIPNG
, RIPNG_ROUTE_STATIC
, &p
,
570 int ripngd_instance_static_route_destroy(enum nb_event event
,
571 const struct lyd_node
*dnode
)
574 struct prefix_ipv6 p
;
576 if (event
!= NB_EV_APPLY
)
579 ripng
= nb_running_get_entry(dnode
, NULL
, true);
580 yang_dnode_get_ipv6p(&p
, dnode
, NULL
);
583 ripng_redistribute_delete(ripng
, ZEBRA_ROUTE_RIPNG
, RIPNG_ROUTE_STATIC
,
590 * XPath: /frr-ripngd:ripngd/instance/aggregate-address
592 int ripngd_instance_aggregate_address_create(enum nb_event event
,
593 const struct lyd_node
*dnode
,
594 union nb_resource
*resource
)
597 struct prefix_ipv6 p
;
599 if (event
!= NB_EV_APPLY
)
602 ripng
= nb_running_get_entry(dnode
, NULL
, true);
603 yang_dnode_get_ipv6p(&p
, dnode
, NULL
);
606 ripng_aggregate_add(ripng
, (struct prefix
*)&p
);
611 int ripngd_instance_aggregate_address_destroy(enum nb_event event
,
612 const struct lyd_node
*dnode
)
615 struct prefix_ipv6 p
;
617 if (event
!= NB_EV_APPLY
)
620 ripng
= nb_running_get_entry(dnode
, NULL
, true);
621 yang_dnode_get_ipv6p(&p
, dnode
, NULL
);
624 ripng_aggregate_delete(ripng
, (struct prefix
*)&p
);
630 * XPath: /frr-ripngd:ripngd/instance/timers
632 void ripngd_instance_timers_apply_finish(const struct lyd_node
*dnode
)
636 ripng
= nb_running_get_entry(dnode
, NULL
, true);
638 /* Reset update timer thread. */
639 ripng_event(ripng
, RIPNG_UPDATE_EVENT
, 0);
643 * XPath: /frr-ripngd:ripngd/instance/timers/flush-interval
645 int ripngd_instance_timers_flush_interval_modify(enum nb_event event
,
646 const struct lyd_node
*dnode
,
647 union nb_resource
*resource
)
651 if (event
!= NB_EV_APPLY
)
654 ripng
= nb_running_get_entry(dnode
, NULL
, true);
655 ripng
->garbage_time
= yang_dnode_get_uint16(dnode
, NULL
);
661 * XPath: /frr-ripngd:ripngd/instance/timers/holddown-interval
663 int ripngd_instance_timers_holddown_interval_modify(
664 enum nb_event event
, const struct lyd_node
*dnode
,
665 union nb_resource
*resource
)
669 if (event
!= NB_EV_APPLY
)
672 ripng
= nb_running_get_entry(dnode
, NULL
, true);
673 ripng
->timeout_time
= yang_dnode_get_uint16(dnode
, NULL
);
679 * XPath: /frr-ripngd:ripngd/instance/timers/update-interval
681 int ripngd_instance_timers_update_interval_modify(enum nb_event event
,
682 const struct lyd_node
*dnode
,
683 union nb_resource
*resource
)
687 if (event
!= NB_EV_APPLY
)
690 ripng
= nb_running_get_entry(dnode
, NULL
, true);
691 ripng
->update_time
= yang_dnode_get_uint16(dnode
, NULL
);
697 * XPath: /frr-interface:lib/interface/frr-ripngd:ripng/split-horizon
699 int lib_interface_ripng_split_horizon_modify(enum nb_event event
,
700 const struct lyd_node
*dnode
,
701 union nb_resource
*resource
)
703 struct interface
*ifp
;
704 struct ripng_interface
*ri
;
706 if (event
!= NB_EV_APPLY
)
709 ifp
= nb_running_get_entry(dnode
, NULL
, true);
711 ri
->split_horizon
= yang_dnode_get_enum(dnode
, NULL
);