]> git.proxmox.com Git - mirror_frr.git/blobdiff - bfdd/bfdd_nb_config.c
Merge pull request #12310 from kuldeepkash/pim_v6
[mirror_frr.git] / bfdd / bfdd_nb_config.c
index c8dd5cc3f63653dc79b750ed42e09477e935ce08..e4e97404d8b9cc8140a951de5ceb2aa7a2cd3b9b 100644 (file)
@@ -1,23 +1,9 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
 /*
  * BFD daemon northbound implementation.
  *
  * Copyright (C) 2019 Network Device Education Foundation, Inc. ("NetDEF")
  *                    Rafael Zalamena
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
- * 02110-1301 USA.
  */
 
 #include <zebra.h>
@@ -45,11 +31,13 @@ static void bfd_session_get_key(bool mhop, const struct lyd_node *dnode,
        if (yang_dnode_exists(dnode, "./source-addr"))
                strtosa(yang_dnode_get_string(dnode, "./source-addr"), &lsa);
 
-       ifname = yang_dnode_get_string(dnode, "./interface");
        vrfname = yang_dnode_get_string(dnode, "./vrf");
 
-       if (strcmp(ifname, "*") == 0)
-               ifname = NULL;
+       if (!mhop) {
+               ifname = yang_dnode_get_string(dnode, "./interface");
+               if (strcmp(ifname, "*") == 0)
+                       ifname = NULL;
+       }
 
        /* Generate the corresponding key. */
        gen_bfd_key(bk, &psa, &lsa, mhop, ifname, vrfname);
@@ -80,7 +68,6 @@ static int bfd_session_create(struct nb_cb_create_args *args, bool mhop)
        const struct lyd_node *sess_dnode;
        struct session_iter iter;
        struct bfd_session *bs;
-       const char *source;
        const char *dest;
        const char *ifname;
        const char *vrfname;
@@ -89,13 +76,27 @@ static int bfd_session_create(struct nb_cb_create_args *args, bool mhop)
 
        switch (args->event) {
        case NB_EV_VALIDATE:
+               yang_dnode_get_prefix(&p, args->dnode, "./dest-addr");
+
+               if (mhop) {
+                       /*
+                        * Do not allow IPv6 link-local address for multihop.
+                        */
+                       if (p.family == AF_INET6
+                           && IN6_IS_ADDR_LINKLOCAL(&p.u.prefix6)) {
+                               snprintf(
+                                       args->errmsg, args->errmsg_len,
+                                       "Cannot use link-local address for multihop sessions");
+                               return NB_ERR_VALIDATION;
+                       }
+                       return NB_OK;
+               }
+
                /*
                 * When `dest-addr` is IPv6 and link-local we must
                 * require interface name, otherwise we can't figure
                 * which interface to use to send the packets.
                 */
-               yang_dnode_get_prefix(&p, args->dnode, "./dest-addr");
-
                ifname = yang_dnode_get_string(args->dnode, "./interface");
 
                if (p.family == AF_INET6 && IN6_IS_ADDR_LINKLOCAL(&p.u.prefix6)
@@ -114,17 +115,9 @@ static int bfd_session_create(struct nb_cb_create_args *args, bool mhop)
                dest = yang_dnode_get_string(args->dnode, "./dest-addr");
                vrfname = yang_dnode_get_string(args->dnode, "./vrf");
 
-               if (mhop) {
-                       source = yang_dnode_get_string(args->dnode, "./source-addr");
-
-                       yang_dnode_iterate(session_iter_cb, &iter, sess_dnode,
-                                          "./multi-hop[source-addr='%s'][dest-addr='%s'][vrf='%s']",
-                                          source, dest, vrfname);
-               } else {
-                       yang_dnode_iterate(session_iter_cb, &iter, sess_dnode,
-                                          "./single-hop[dest-addr='%s'][vrf='%s']",
-                                          dest, vrfname);
-               }
+               yang_dnode_iterate(session_iter_cb, &iter, sess_dnode,
+                                  "./single-hop[dest-addr='%s'][vrf='%s']",
+                                  dest, vrfname);
 
                if (iter.wildcard && iter.count > 1) {
                        snprintf(
@@ -229,7 +222,15 @@ static int bfd_session_destroy(enum nb_event event,
  */
 int bfdd_bfd_create(struct nb_cb_create_args *args)
 {
-       /* NOTHING */
+       if (args->event != NB_EV_APPLY)
+               return NB_OK;
+
+       /*
+        * Set any non-NULL value to be able to call
+        * nb_running_unset_entry in bfdd_bfd_destroy.
+        */
+       nb_running_set_entry(args->dnode, (void *)0x1);
+
        return NB_OK;
 }
 
@@ -245,7 +246,14 @@ int bfdd_bfd_destroy(struct nb_cb_destroy_args *args)
                return NB_OK;
 
        case NB_EV_APPLY:
+               /*
+                * We need to call this to unset pointers from
+                * the child nodes - sessions and profiles.
+                */
+               nb_running_unset_entry(args->dnode);
+
                bfd_sessions_remove_manual();
+               bfd_profiles_remove();
                break;
 
        case NB_EV_ABORT:
@@ -311,13 +319,9 @@ int bfdd_bfd_profile_desired_transmission_interval_modify(
        struct nb_cb_modify_args *args)
 {
        struct bfd_profile *bp;
-       uint32_t min_tx;
 
        switch (args->event) {
        case NB_EV_VALIDATE:
-               min_tx = yang_dnode_get_uint32(args->dnode, NULL);
-               if (min_tx < 10000 || min_tx > 60000000)
-                       return NB_ERR_VALIDATION;
                break;
 
        case NB_EV_PREPARE:
@@ -325,12 +329,8 @@ int bfdd_bfd_profile_desired_transmission_interval_modify(
                break;
 
        case NB_EV_APPLY:
-               min_tx = yang_dnode_get_uint32(args->dnode, NULL);
                bp = nb_running_get_entry(args->dnode, NULL, true);
-               if (bp->min_tx == min_tx)
-                       return NB_OK;
-
-               bp->min_tx = min_tx;
+               bp->min_tx = yang_dnode_get_uint32(args->dnode, NULL);
                bfd_profile_update(bp);
                break;
 
@@ -349,13 +349,9 @@ int bfdd_bfd_profile_required_receive_interval_modify(
        struct nb_cb_modify_args *args)
 {
        struct bfd_profile *bp;
-       uint32_t min_rx;
 
        switch (args->event) {
        case NB_EV_VALIDATE:
-               min_rx = yang_dnode_get_uint32(args->dnode, NULL);
-               if (min_rx < 10000 || min_rx > 60000000)
-                       return NB_ERR_VALIDATION;
                break;
 
        case NB_EV_PREPARE:
@@ -363,12 +359,8 @@ int bfdd_bfd_profile_required_receive_interval_modify(
                break;
 
        case NB_EV_APPLY:
-               min_rx = yang_dnode_get_uint32(args->dnode, NULL);
                bp = nb_running_get_entry(args->dnode, NULL, true);
-               if (bp->min_rx == min_rx)
-                       return NB_OK;
-
-               bp->min_rx = min_rx;
+               bp->min_rx = yang_dnode_get_uint32(args->dnode, NULL);
                bfd_profile_update(bp);
                break;
 
@@ -386,17 +378,12 @@ int bfdd_bfd_profile_required_receive_interval_modify(
 int bfdd_bfd_profile_administrative_down_modify(struct nb_cb_modify_args *args)
 {
        struct bfd_profile *bp;
-       bool shutdown;
 
        if (args->event != NB_EV_APPLY)
                return NB_OK;
 
-       shutdown = yang_dnode_get_bool(args->dnode, NULL);
        bp = nb_running_get_entry(args->dnode, NULL, true);
-       if (bp->admin_shutdown == shutdown)
-               return NB_OK;
-
-       bp->admin_shutdown = shutdown;
+       bp->admin_shutdown = yang_dnode_get_bool(args->dnode, NULL);
        bfd_profile_update(bp);
 
        return NB_OK;
@@ -408,17 +395,12 @@ int bfdd_bfd_profile_administrative_down_modify(struct nb_cb_modify_args *args)
 int bfdd_bfd_profile_passive_mode_modify(struct nb_cb_modify_args *args)
 {
        struct bfd_profile *bp;
-       bool passive;
 
        if (args->event != NB_EV_APPLY)
                return NB_OK;
 
-       passive = yang_dnode_get_bool(args->dnode, NULL);
        bp = nb_running_get_entry(args->dnode, NULL, true);
-       if (bp->passive == passive)
-               return NB_OK;
-
-       bp->passive = passive;
+       bp->passive = yang_dnode_get_bool(args->dnode, NULL);
        bfd_profile_update(bp);
 
        return NB_OK;
@@ -430,17 +412,12 @@ int bfdd_bfd_profile_passive_mode_modify(struct nb_cb_modify_args *args)
 int bfdd_bfd_profile_minimum_ttl_modify(struct nb_cb_modify_args *args)
 {
        struct bfd_profile *bp;
-       uint8_t minimum_ttl;
 
        if (args->event != NB_EV_APPLY)
                return NB_OK;
 
-       minimum_ttl = yang_dnode_get_uint8(args->dnode, NULL);
        bp = nb_running_get_entry(args->dnode, NULL, true);
-       if (bp->minimum_ttl == minimum_ttl)
-               return NB_OK;
-
-       bp->minimum_ttl = minimum_ttl;
+       bp->minimum_ttl = yang_dnode_get_uint8(args->dnode, NULL);
        bfd_profile_update(bp);
 
        return NB_OK;
@@ -483,19 +460,15 @@ int bfdd_bfd_profile_echo_mode_modify(struct nb_cb_modify_args *args)
 }
 
 /*
- * XPath: /frr-bfdd:bfdd/bfd/profile/desired-echo-echo-transmission-interval
+ * XPath: /frr-bfdd:bfdd/bfd/profile/desired-echo-transmission-interval
  */
 int bfdd_bfd_profile_desired_echo_transmission_interval_modify(
        struct nb_cb_modify_args *args)
 {
        struct bfd_profile *bp;
-       uint32_t min_rx;
 
        switch (args->event) {
        case NB_EV_VALIDATE:
-               min_rx = yang_dnode_get_uint32(args->dnode, NULL);
-               if (min_rx < 10000 || min_rx > 60000000)
-                       return NB_ERR_VALIDATION;
                break;
 
        case NB_EV_PREPARE:
@@ -503,12 +476,38 @@ int bfdd_bfd_profile_desired_echo_transmission_interval_modify(
                break;
 
        case NB_EV_APPLY:
-               min_rx = yang_dnode_get_uint32(args->dnode, NULL);
                bp = nb_running_get_entry(args->dnode, NULL, true);
-               if (bp->min_echo_rx == min_rx)
-                       return NB_OK;
+               bp->min_echo_tx = yang_dnode_get_uint32(args->dnode, NULL);
+               bfd_profile_update(bp);
+               break;
+
+       case NB_EV_ABORT:
+               /* NOTHING */
+               break;
+       }
+
+       return NB_OK;
+}
 
-               bp->min_echo_rx = min_rx;
+/*
+ * XPath: /frr-bfdd:bfdd/bfd/profile/required-echo-receive-interval
+ */
+int bfdd_bfd_profile_required_echo_receive_interval_modify(
+       struct nb_cb_modify_args *args)
+{
+       struct bfd_profile *bp;
+
+       switch (args->event) {
+       case NB_EV_VALIDATE:
+               break;
+
+       case NB_EV_PREPARE:
+               /* NOTHING */
+               break;
+
+       case NB_EV_APPLY:
+               bp = nb_running_get_entry(args->dnode, NULL, true);
+               bp->min_echo_rx = yang_dnode_get_uint32(args->dnode, NULL);
                bfd_profile_update(bp);
                break;
 
@@ -615,13 +614,10 @@ int bfdd_bfd_sessions_single_hop_detection_multiplier_modify(
 int bfdd_bfd_sessions_single_hop_desired_transmission_interval_modify(
        struct nb_cb_modify_args *args)
 {
-       uint32_t tx_interval = yang_dnode_get_uint32(args->dnode, NULL);
        struct bfd_session *bs;
 
        switch (args->event) {
        case NB_EV_VALIDATE:
-               if (tx_interval < 10000 || tx_interval > 60000000)
-                       return NB_ERR_VALIDATION;
                break;
 
        case NB_EV_PREPARE:
@@ -630,10 +626,8 @@ int bfdd_bfd_sessions_single_hop_desired_transmission_interval_modify(
 
        case NB_EV_APPLY:
                bs = nb_running_get_entry(args->dnode, NULL, true);
-               if (tx_interval == bs->timers.desired_min_tx)
-                       return NB_OK;
-
-               bs->peer_profile.min_tx = tx_interval;
+               bs->peer_profile.min_tx =
+                       yang_dnode_get_uint32(args->dnode, NULL);
                bfd_session_apply(bs);
                break;
 
@@ -651,13 +645,10 @@ int bfdd_bfd_sessions_single_hop_desired_transmission_interval_modify(
 int bfdd_bfd_sessions_single_hop_required_receive_interval_modify(
        struct nb_cb_modify_args *args)
 {
-       uint32_t rx_interval = yang_dnode_get_uint32(args->dnode, NULL);
        struct bfd_session *bs;
 
        switch (args->event) {
        case NB_EV_VALIDATE:
-               if (rx_interval < 10000 || rx_interval > 60000000)
-                       return NB_ERR_VALIDATION;
                break;
 
        case NB_EV_PREPARE:
@@ -666,10 +657,8 @@ int bfdd_bfd_sessions_single_hop_required_receive_interval_modify(
 
        case NB_EV_APPLY:
                bs = nb_running_get_entry(args->dnode, NULL, true);
-               if (rx_interval == bs->timers.required_min_rx)
-                       return NB_OK;
-
-               bs->peer_profile.min_rx = rx_interval;
+               bs->peer_profile.min_rx =
+                       yang_dnode_get_uint32(args->dnode, NULL);
                bfd_session_apply(bs);
                break;
 
@@ -774,13 +763,10 @@ int bfdd_bfd_sessions_single_hop_echo_mode_modify(
 int bfdd_bfd_sessions_single_hop_desired_echo_transmission_interval_modify(
        struct nb_cb_modify_args *args)
 {
-       uint32_t echo_interval = yang_dnode_get_uint32(args->dnode, NULL);
        struct bfd_session *bs;
 
        switch (args->event) {
        case NB_EV_VALIDATE:
-               if (echo_interval < 10000 || echo_interval > 60000000)
-                       return NB_ERR_VALIDATION;
                break;
 
        case NB_EV_PREPARE:
@@ -789,10 +775,40 @@ int bfdd_bfd_sessions_single_hop_desired_echo_transmission_interval_modify(
 
        case NB_EV_APPLY:
                bs = nb_running_get_entry(args->dnode, NULL, true);
-               if (echo_interval == bs->timers.required_min_echo)
-                       return NB_OK;
+               bs->peer_profile.min_echo_tx =
+                       yang_dnode_get_uint32(args->dnode, NULL);
+               bfd_session_apply(bs);
+               break;
 
-               bs->peer_profile.min_echo_rx = echo_interval;
+       case NB_EV_ABORT:
+               /* NOTHING */
+               break;
+       }
+
+       return NB_OK;
+}
+
+/*
+ * XPath:
+ * /frr-bfdd:bfdd/bfd/sessions/single-hop/required-echo-receive-interval
+ */
+int bfdd_bfd_sessions_single_hop_required_echo_receive_interval_modify(
+       struct nb_cb_modify_args *args)
+{
+       struct bfd_session *bs;
+
+       switch (args->event) {
+       case NB_EV_VALIDATE:
+               break;
+
+       case NB_EV_PREPARE:
+               /* NOTHING */
+               break;
+
+       case NB_EV_APPLY:
+               bs = nb_running_get_entry(args->dnode, NULL, true);
+               bs->peer_profile.min_echo_rx =
+                       yang_dnode_get_uint32(args->dnode, NULL);
                bfd_session_apply(bs);
                break;