]>
git.proxmox.com Git - mirror_frr.git/blob - bfdd/bfdd_nb_config.c
2 * BFD daemon northbound implementation.
4 * Copyright (C) 2019 Network Device Education Foundation, Inc. ("NetDEF")
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
26 #include "lib/northbound.h"
34 static void bfd_session_get_key(bool mhop
, const struct lyd_node
*dnode
,
37 const char *ifname
= NULL
, *vrfname
= NULL
;
38 struct sockaddr_any psa
, lsa
;
40 /* Required destination parameter. */
41 strtosa(yang_dnode_get_string(dnode
, "./dest-addr"), &psa
);
43 /* Get optional source address. */
44 memset(&lsa
, 0, sizeof(lsa
));
45 if (yang_dnode_exists(dnode
, "./source-addr"))
46 strtosa(yang_dnode_get_string(dnode
, "./source-addr"), &lsa
);
48 vrfname
= yang_dnode_get_string(dnode
, "./vrf");
51 ifname
= yang_dnode_get_string(dnode
, "./interface");
52 if (strcmp(ifname
, "*") == 0)
56 /* Generate the corresponding key. */
57 gen_bfd_key(bk
, &psa
, &lsa
, mhop
, ifname
, vrfname
);
65 static int session_iter_cb(const struct lyd_node
*dnode
, void *arg
)
67 struct session_iter
*iter
= arg
;
70 ifname
= yang_dnode_get_string(dnode
, "./interface");
72 if (strmatch(ifname
, "*"))
73 iter
->wildcard
= true;
77 return YANG_ITER_CONTINUE
;
80 static int bfd_session_create(struct nb_cb_create_args
*args
, bool mhop
)
82 const struct lyd_node
*sess_dnode
;
83 struct session_iter iter
;
84 struct bfd_session
*bs
;
91 switch (args
->event
) {
93 yang_dnode_get_prefix(&p
, args
->dnode
, "./dest-addr");
97 * Do not allow IPv6 link-local address for multihop.
99 if (p
.family
== AF_INET6
100 && IN6_IS_ADDR_LINKLOCAL(&p
.u
.prefix6
)) {
102 args
->errmsg
, args
->errmsg_len
,
103 "Cannot use link-local address for multihop sessions");
104 return NB_ERR_VALIDATION
;
110 * When `dest-addr` is IPv6 and link-local we must
111 * require interface name, otherwise we can't figure
112 * which interface to use to send the packets.
114 ifname
= yang_dnode_get_string(args
->dnode
, "./interface");
116 if (p
.family
== AF_INET6
&& IN6_IS_ADDR_LINKLOCAL(&p
.u
.prefix6
)
117 && strcmp(ifname
, "*") == 0) {
119 args
->errmsg
, args
->errmsg_len
,
120 "When using link-local you must specify an interface");
121 return NB_ERR_VALIDATION
;
125 iter
.wildcard
= false;
127 sess_dnode
= yang_dnode_get_parent(args
->dnode
, "sessions");
129 dest
= yang_dnode_get_string(args
->dnode
, "./dest-addr");
130 vrfname
= yang_dnode_get_string(args
->dnode
, "./vrf");
132 yang_dnode_iterate(session_iter_cb
, &iter
, sess_dnode
,
133 "./single-hop[dest-addr='%s'][vrf='%s']",
136 if (iter
.wildcard
&& iter
.count
> 1) {
138 args
->errmsg
, args
->errmsg_len
,
139 "It is not allowed to configure the same peer with and without ifname");
140 return NB_ERR_VALIDATION
;
145 bfd_session_get_key(mhop
, args
->dnode
, &bk
);
146 bs
= bfd_key_lookup(bk
);
148 /* This session was already configured by another daemon. */
150 /* Now it is configured also by CLI. */
151 SET_FLAG(bs
->flags
, BFD_SESS_FLAG_CONFIG
);
154 args
->resource
->ptr
= bs
;
158 bs
= bfd_session_new();
160 /* Fill the session key. */
161 bfd_session_get_key(mhop
, args
->dnode
, &bs
->key
);
163 /* Set configuration flags. */
165 SET_FLAG(bs
->flags
, BFD_SESS_FLAG_CONFIG
);
167 SET_FLAG(bs
->flags
, BFD_SESS_FLAG_MH
);
168 if (bs
->key
.family
== AF_INET6
)
169 SET_FLAG(bs
->flags
, BFD_SESS_FLAG_IPV6
);
171 args
->resource
->ptr
= bs
;
175 bs
= args
->resource
->ptr
;
177 /* Only attempt to registrate if freshly allocated. */
178 if (bs
->discrs
.my_discr
== 0 && bs_registrate(bs
) == NULL
)
179 return NB_ERR_RESOURCE
;
181 nb_running_set_entry(args
->dnode
, bs
);
185 bs
= args
->resource
->ptr
;
186 if (bs
->refcount
<= 1)
187 bfd_session_free(bs
);
194 static int bfd_session_destroy(enum nb_event event
,
195 const struct lyd_node
*dnode
, bool mhop
)
197 struct bfd_session
*bs
;
202 bfd_session_get_key(mhop
, dnode
, &bk
);
203 if (bfd_key_lookup(bk
) == NULL
)
204 return NB_ERR_INCONSISTENCY
;
212 bs
= nb_running_unset_entry(dnode
);
213 /* CLI is not using this session anymore. */
214 if (CHECK_FLAG(bs
->flags
, BFD_SESS_FLAG_CONFIG
) == 0)
217 UNSET_FLAG(bs
->flags
, BFD_SESS_FLAG_CONFIG
);
219 /* There are still daemons using it. */
220 if (bs
->refcount
> 0)
223 bfd_session_free(bs
);
235 * XPath: /frr-bfdd:bfdd/bfd
237 int bfdd_bfd_create(struct nb_cb_create_args
*args
)
239 if (args
->event
!= NB_EV_APPLY
)
243 * Set any non-NULL value to be able to call
244 * nb_running_unset_entry in bfdd_bfd_destroy.
246 nb_running_set_entry(args
->dnode
, (void *)0x1);
251 int bfdd_bfd_destroy(struct nb_cb_destroy_args
*args
)
253 switch (args
->event
) {
264 * We need to call this to unset pointers from
265 * the child nodes - sessions and profiles.
267 nb_running_unset_entry(args
->dnode
);
269 bfd_sessions_remove_manual();
270 bfd_profiles_remove();
282 * XPath: /frr-bfdd:bfdd/bfd/profile
284 int bfdd_bfd_profile_create(struct nb_cb_create_args
*args
)
286 struct bfd_profile
*bp
;
289 if (args
->event
!= NB_EV_APPLY
)
292 name
= yang_dnode_get_string(args
->dnode
, "./name");
293 bp
= bfd_profile_new(name
);
294 nb_running_set_entry(args
->dnode
, bp
);
299 int bfdd_bfd_profile_destroy(struct nb_cb_destroy_args
*args
)
301 struct bfd_profile
*bp
;
303 if (args
->event
!= NB_EV_APPLY
)
306 bp
= nb_running_unset_entry(args
->dnode
);
307 bfd_profile_free(bp
);
313 * XPath: /frr-bfdd:bfdd/bfd/profile/detection-multiplier
315 int bfdd_bfd_profile_detection_multiplier_modify(struct nb_cb_modify_args
*args
)
317 struct bfd_profile
*bp
;
319 if (args
->event
!= NB_EV_APPLY
)
322 bp
= nb_running_get_entry(args
->dnode
, NULL
, true);
323 bp
->detection_multiplier
= yang_dnode_get_uint8(args
->dnode
, NULL
);
324 bfd_profile_update(bp
);
330 * XPath: /frr-bfdd:bfdd/bfd/profile/desired-transmission-interval
332 int bfdd_bfd_profile_desired_transmission_interval_modify(
333 struct nb_cb_modify_args
*args
)
335 struct bfd_profile
*bp
;
337 switch (args
->event
) {
346 bp
= nb_running_get_entry(args
->dnode
, NULL
, true);
347 bp
->min_tx
= yang_dnode_get_uint32(args
->dnode
, NULL
);
348 bfd_profile_update(bp
);
360 * XPath: /frr-bfdd:bfdd/bfd/profile/required-receive-interval
362 int bfdd_bfd_profile_required_receive_interval_modify(
363 struct nb_cb_modify_args
*args
)
365 struct bfd_profile
*bp
;
367 switch (args
->event
) {
376 bp
= nb_running_get_entry(args
->dnode
, NULL
, true);
377 bp
->min_rx
= yang_dnode_get_uint32(args
->dnode
, NULL
);
378 bfd_profile_update(bp
);
390 * XPath: /frr-bfdd:bfdd/bfd/profile/administrative-down
392 int bfdd_bfd_profile_administrative_down_modify(struct nb_cb_modify_args
*args
)
394 struct bfd_profile
*bp
;
396 if (args
->event
!= NB_EV_APPLY
)
399 bp
= nb_running_get_entry(args
->dnode
, NULL
, true);
400 bp
->admin_shutdown
= yang_dnode_get_bool(args
->dnode
, NULL
);
401 bfd_profile_update(bp
);
407 * XPath: /frr-bfdd:bfdd/bfd/profile/passive-mode
409 int bfdd_bfd_profile_passive_mode_modify(struct nb_cb_modify_args
*args
)
411 struct bfd_profile
*bp
;
413 if (args
->event
!= NB_EV_APPLY
)
416 bp
= nb_running_get_entry(args
->dnode
, NULL
, true);
417 bp
->passive
= yang_dnode_get_bool(args
->dnode
, NULL
);
418 bfd_profile_update(bp
);
424 * XPath: /frr-bfdd:bfdd/bfd/profile/minimum-ttl
426 int bfdd_bfd_profile_minimum_ttl_modify(struct nb_cb_modify_args
*args
)
428 struct bfd_profile
*bp
;
430 if (args
->event
!= NB_EV_APPLY
)
433 bp
= nb_running_get_entry(args
->dnode
, NULL
, true);
434 bp
->minimum_ttl
= yang_dnode_get_uint8(args
->dnode
, NULL
);
435 bfd_profile_update(bp
);
440 int bfdd_bfd_profile_minimum_ttl_destroy(struct nb_cb_destroy_args
*args
)
442 struct bfd_profile
*bp
;
444 if (args
->event
!= NB_EV_APPLY
)
447 bp
= nb_running_get_entry(args
->dnode
, NULL
, true);
448 bp
->minimum_ttl
= BFD_DEF_MHOP_TTL
;
449 bfd_profile_update(bp
);
455 * XPath: /frr-bfdd:bfdd/bfd/profile/echo-mode
457 int bfdd_bfd_profile_echo_mode_modify(struct nb_cb_modify_args
*args
)
459 struct bfd_profile
*bp
;
462 if (args
->event
!= NB_EV_APPLY
)
465 echo
= yang_dnode_get_bool(args
->dnode
, NULL
);
466 bp
= nb_running_get_entry(args
->dnode
, NULL
, true);
467 if (bp
->echo_mode
== echo
)
470 bp
->echo_mode
= echo
;
471 bfd_profile_update(bp
);
477 * XPath: /frr-bfdd:bfdd/bfd/profile/desired-echo-transmission-interval
479 int bfdd_bfd_profile_desired_echo_transmission_interval_modify(
480 struct nb_cb_modify_args
*args
)
482 struct bfd_profile
*bp
;
484 switch (args
->event
) {
493 bp
= nb_running_get_entry(args
->dnode
, NULL
, true);
494 bp
->min_echo_tx
= yang_dnode_get_uint32(args
->dnode
, NULL
);
495 bfd_profile_update(bp
);
507 * XPath: /frr-bfdd:bfdd/bfd/profile/required-echo-receive-interval
509 int bfdd_bfd_profile_required_echo_receive_interval_modify(
510 struct nb_cb_modify_args
*args
)
512 struct bfd_profile
*bp
;
514 switch (args
->event
) {
523 bp
= nb_running_get_entry(args
->dnode
, NULL
, true);
524 bp
->min_echo_rx
= yang_dnode_get_uint32(args
->dnode
, NULL
);
525 bfd_profile_update(bp
);
537 * XPath: /frr-bfdd:bfdd/bfd/sessions/single-hop
539 int bfdd_bfd_sessions_single_hop_create(struct nb_cb_create_args
*args
)
541 return bfd_session_create(args
, false);
544 int bfdd_bfd_sessions_single_hop_destroy(struct nb_cb_destroy_args
*args
)
546 return bfd_session_destroy(args
->event
, args
->dnode
, false);
550 * XPath: /frr-bfdd:bfdd/bfd/sessions/single-hop/source-addr
552 int bfdd_bfd_sessions_single_hop_source_addr_modify(
553 struct nb_cb_modify_args
*args
)
558 int bfdd_bfd_sessions_single_hop_source_addr_destroy(
559 struct nb_cb_destroy_args
*args
)
565 * XPath: /frr-bfdd:bfdd/bfd/sessions/single-hop/profile
567 int bfdd_bfd_sessions_single_hop_profile_modify(struct nb_cb_modify_args
*args
)
569 struct bfd_session
*bs
;
571 if (args
->event
!= NB_EV_APPLY
)
574 bs
= nb_running_get_entry(args
->dnode
, NULL
, true);
575 bfd_profile_apply(yang_dnode_get_string(args
->dnode
, NULL
), bs
);
580 int bfdd_bfd_sessions_single_hop_profile_destroy(
581 struct nb_cb_destroy_args
*args
)
583 struct bfd_session
*bs
;
585 if (args
->event
!= NB_EV_APPLY
)
588 bs
= nb_running_get_entry(args
->dnode
, NULL
, true);
589 bfd_profile_remove(bs
);
595 * XPath: /frr-bfdd:bfdd/bfd/sessions/single-hop/detection-multiplier
597 int bfdd_bfd_sessions_single_hop_detection_multiplier_modify(
598 struct nb_cb_modify_args
*args
)
600 uint8_t detection_multiplier
= yang_dnode_get_uint8(args
->dnode
, NULL
);
601 struct bfd_session
*bs
;
603 switch (args
->event
) {
612 bs
= nb_running_get_entry(args
->dnode
, NULL
, true);
613 bs
->peer_profile
.detection_multiplier
= detection_multiplier
;
614 bfd_session_apply(bs
);
626 * XPath: /frr-bfdd:bfdd/bfd/sessions/single-hop/desired-transmission-interval
628 int bfdd_bfd_sessions_single_hop_desired_transmission_interval_modify(
629 struct nb_cb_modify_args
*args
)
631 struct bfd_session
*bs
;
633 switch (args
->event
) {
642 bs
= nb_running_get_entry(args
->dnode
, NULL
, true);
643 bs
->peer_profile
.min_tx
=
644 yang_dnode_get_uint32(args
->dnode
, NULL
);
645 bfd_session_apply(bs
);
657 * XPath: /frr-bfdd:bfdd/bfd/sessions/single-hop/required-receive-interval
659 int bfdd_bfd_sessions_single_hop_required_receive_interval_modify(
660 struct nb_cb_modify_args
*args
)
662 struct bfd_session
*bs
;
664 switch (args
->event
) {
673 bs
= nb_running_get_entry(args
->dnode
, NULL
, true);
674 bs
->peer_profile
.min_rx
=
675 yang_dnode_get_uint32(args
->dnode
, NULL
);
676 bfd_session_apply(bs
);
688 * XPath: /frr-bfdd:bfdd/bfd/sessions/single-hop/administrative-down
690 int bfdd_bfd_sessions_single_hop_administrative_down_modify(
691 struct nb_cb_modify_args
*args
)
693 bool shutdown
= yang_dnode_get_bool(args
->dnode
, NULL
);
694 struct bfd_session
*bs
;
696 switch (args
->event
) {
708 bs
= nb_running_get_entry(args
->dnode
, NULL
, true);
709 bs
->peer_profile
.admin_shutdown
= shutdown
;
710 bfd_session_apply(bs
);
716 * XPath: /frr-bfdd:bfdd/bfd/sessions/single-hop/passive-mode
718 int bfdd_bfd_sessions_single_hop_passive_mode_modify(
719 struct nb_cb_modify_args
*args
)
721 struct bfd_session
*bs
;
724 switch (args
->event
) {
736 passive
= yang_dnode_get_bool(args
->dnode
, NULL
);
738 bs
= nb_running_get_entry(args
->dnode
, NULL
, true);
739 bs
->peer_profile
.passive
= passive
;
740 bfd_session_apply(bs
);
746 * XPath: /frr-bfdd:bfdd/bfd/sessions/single-hop/echo-mode
748 int bfdd_bfd_sessions_single_hop_echo_mode_modify(
749 struct nb_cb_modify_args
*args
)
751 bool echo
= yang_dnode_get_bool(args
->dnode
, NULL
);
752 struct bfd_session
*bs
;
754 switch (args
->event
) {
766 bs
= nb_running_get_entry(args
->dnode
, NULL
, true);
767 bs
->peer_profile
.echo_mode
= echo
;
768 bfd_session_apply(bs
);
775 * /frr-bfdd:bfdd/bfd/sessions/single-hop/desired-echo-transmission-interval
777 int bfdd_bfd_sessions_single_hop_desired_echo_transmission_interval_modify(
778 struct nb_cb_modify_args
*args
)
780 struct bfd_session
*bs
;
782 switch (args
->event
) {
791 bs
= nb_running_get_entry(args
->dnode
, NULL
, true);
792 bs
->peer_profile
.min_echo_tx
=
793 yang_dnode_get_uint32(args
->dnode
, NULL
);
794 bfd_session_apply(bs
);
807 * /frr-bfdd:bfdd/bfd/sessions/single-hop/required-echo-receive-interval
809 int bfdd_bfd_sessions_single_hop_required_echo_receive_interval_modify(
810 struct nb_cb_modify_args
*args
)
812 struct bfd_session
*bs
;
814 switch (args
->event
) {
823 bs
= nb_running_get_entry(args
->dnode
, NULL
, true);
824 bs
->peer_profile
.min_echo_rx
=
825 yang_dnode_get_uint32(args
->dnode
, NULL
);
826 bfd_session_apply(bs
);
838 * XPath: /frr-bfdd:bfdd/bfd/sessions/multi-hop
840 int bfdd_bfd_sessions_multi_hop_create(struct nb_cb_create_args
*args
)
842 return bfd_session_create(args
, true);
845 int bfdd_bfd_sessions_multi_hop_destroy(struct nb_cb_destroy_args
*args
)
847 return bfd_session_destroy(args
->event
, args
->dnode
, true);
851 * XPath: /frr-bfdd:bfdd/bfd/sessions/multi-hop/minimum-ttl
853 int bfdd_bfd_sessions_multi_hop_minimum_ttl_modify(
854 struct nb_cb_modify_args
*args
)
856 struct bfd_session
*bs
;
858 switch (args
->event
) {
870 bs
= nb_running_get_entry(args
->dnode
, NULL
, true);
871 bs
->peer_profile
.minimum_ttl
= yang_dnode_get_uint8(args
->dnode
, NULL
);
872 bfd_session_apply(bs
);
877 int bfdd_bfd_sessions_multi_hop_minimum_ttl_destroy(
878 struct nb_cb_destroy_args
*args
)
880 struct bfd_session
*bs
;
882 switch (args
->event
) {
894 bs
= nb_running_get_entry(args
->dnode
, NULL
, true);
895 bs
->peer_profile
.minimum_ttl
= BFD_DEF_MHOP_TTL
;
896 bfd_session_apply(bs
);