diff options
author | Rafael Zalamena <rzalamena@opensourcerouting.org> | 2019-05-23 21:09:24 +0200 |
---|---|---|
committer | Rafael Zalamena <rzalamena@opensourcerouting.org> | 2019-06-22 15:10:56 +0200 |
commit | adc26455bff183ce65d475b058045165826d823f (patch) | |
tree | 82113cf3836bad765a1b331a0fbc315b929e468f | |
parent | bfdd: remove the label command (diff) | |
download | frr-adc26455bff183ce65d475b058045165826d823f.tar.xz frr-adc26455bff183ce65d475b058045165826d823f.zip |
bfdd: migrate session commands to northbound
Lets start using the new BFD yang model and translate the BFD session
configuration commands to use the northbound.
One important change: all sessions will default to use
`VRF_DEFAULT_NAME` (usually "default") when no VRF is configured. All
places which search for BFD sessions must now take this into account.
Signed-off-by: Rafael Zalamena <rzalamena@opensourcerouting.org>
-rw-r--r-- | bfdd/bfd.c | 78 | ||||
-rw-r--r-- | bfdd/bfd.h | 23 | ||||
-rw-r--r-- | bfdd/bfdd.c | 9 | ||||
-rw-r--r-- | bfdd/bfdd_cli.c | 232 | ||||
-rw-r--r-- | bfdd/bfdd_northbound.c | 1060 | ||||
-rw-r--r-- | bfdd/bfdd_vty.c | 264 | ||||
-rw-r--r-- | bfdd/subdir.am | 6 | ||||
-rw-r--r-- | yang/subdir.am | 4 |
8 files changed, 1397 insertions, 279 deletions
diff --git a/bfdd/bfd.c b/bfdd/bfd.c index 5f41d6b70..828059eb4 100644 --- a/bfdd/bfd.c +++ b/bfdd/bfd.c @@ -34,7 +34,6 @@ DEFINE_MTYPE_STATIC(BFDD, BFDD_CONFIG, "long-lived configuration memory") DEFINE_MTYPE_STATIC(BFDD, BFDD_SESSION_OBSERVER, "Session observer") DEFINE_MTYPE_STATIC(BFDD, BFDD_VRF, "BFD VRF") -DEFINE_QOBJ_TYPE(bfd_session) /* * Prototypes @@ -85,6 +84,8 @@ void gen_bfd_key(struct bfd_key *key, struct sockaddr_any *peer, strlcpy(key->ifname, ifname, sizeof(key->ifname)); if (vrfname && vrfname[0]) strlcpy(key->vrfname, vrfname, sizeof(key->vrfname)); + else + strlcpy(key->vrfname, VRF_DEFAULT_NAME, sizeof(key->vrfname)); } struct bfd_session *bs_peer_find(struct bfd_peer_cfg *bpc) @@ -390,17 +391,13 @@ struct bfd_session *ptm_bfd_sess_find(struct bfd_pkt *cp, /* Search for session without using discriminator. */ ifp = if_lookup_by_index(ifindex, vrfid); - if (vrfid == VRF_DEFAULT) { - /* - * Don't use the default vrf, otherwise we won't find - * sessions that doesn't specify it. - */ - vrf = NULL; - } else + if (vrfid != VRF_DEFAULT) vrf = vrf_lookup_by_id(vrfid); + else + vrf = NULL; gen_bfd_key(&key, peer, local, is_mhop, ifp ? ifp->name : NULL, - vrf ? vrf->name : NULL); + vrf ? vrf->name : VRF_DEFAULT_NAME); /* XXX maybe remoteDiscr should be checked for remoteHeard cases. */ return bfd_key_lookup(key); @@ -469,8 +466,6 @@ struct bfd_session *bfd_session_new(void) bs = XCALLOC(MTYPE_BFDD_CONFIG, sizeof(*bs)); - QOBJ_REG(bs, bfd_session); - bs->timers.desired_min_tx = BFD_DEFDESIREDMINTX; bs->timers.required_min_rx = BFD_DEFREQUIREDMINRX; bs->timers.required_min_echo = BFD_DEF_REQ_MIN_ECHO; @@ -644,7 +639,6 @@ void bfd_session_free(struct bfd_session *bs) pl_free(bs->pl); - QOBJ_UNREG(bs); XFREE(MTYPE_BFDD_CONFIG, bs); } @@ -680,6 +674,9 @@ struct bfd_session *ptm_bfd_sess_new(struct bfd_peer_cfg *bpc) if (bpc->bpc_has_vrfname) strlcpy(bfd->key.vrfname, bpc->bpc_vrfname, sizeof(bfd->key.vrfname)); + else + strlcpy(bfd->key.vrfname, VRF_DEFAULT_NAME, + sizeof(bfd->key.vrfname)); /* Copy remaining data. */ if (bpc->bpc_ipv4 == false) @@ -1292,6 +1289,7 @@ static unsigned int bfd_key_hash_do(const void *p); static void _bfd_free(struct hash_bucket *hb, void *arg __attribute__((__unused__))); +int _bfd_session_next(struct hash_bucket *hb, void *arg); /* BFD hash for our discriminator. */ static unsigned int bfd_id_hash_do(const void *p) @@ -1533,6 +1531,62 @@ void bfd_shutdown(void) hash_free(bfd_key_hash); } +struct bfd_session_iterator { + int bsi_stop; + bool bsi_mhop; + const struct bfd_session *bsi_bs; +}; + +int _bfd_session_next(struct hash_bucket *hb, void *arg) +{ + struct bfd_session_iterator *bsi = arg; + struct bfd_session *bs = hb->data; + + /* Previous entry signaled stop. */ + if (bsi->bsi_stop == 1) { + /* Match the single/multi hop sessions. */ + if (bs->key.mhop != bsi->bsi_mhop) + return HASHWALK_CONTINUE; + + bsi->bsi_bs = bs; + return HASHWALK_ABORT; + } + + /* We found the current item, stop in the next one. */ + if (bsi->bsi_bs == hb->data) { + bsi->bsi_stop = 1; + /* Set entry to NULL to signal end of list. */ + bsi->bsi_bs = NULL; + } else if (bsi->bsi_bs == NULL && bsi->bsi_mhop == bs->key.mhop) { + /* We want the first list item. */ + bsi->bsi_stop = 1; + bsi->bsi_bs = hb->data; + return HASHWALK_ABORT; + } + + return HASHWALK_CONTINUE; +} + +/* + * bfd_session_next: uses the current session to find the next. + * + * `bs` might point to NULL to get the first item of the data structure. + */ +const struct bfd_session *bfd_session_next(const struct bfd_session *bs, + bool mhop) +{ + struct bfd_session_iterator bsi; + + bsi.bsi_stop = 0; + bsi.bsi_bs = bs; + bsi.bsi_mhop = mhop; + hash_walk(bfd_key_hash, _bfd_session_next, &bsi); + if (bsi.bsi_stop == 0) + return NULL; + + return bsi.bsi_bs; +} + /* * VRF related functions. */ diff --git a/bfdd/bfd.h b/bfdd/bfd.h index 48f9090ad..7568583f9 100644 --- a/bfdd/bfd.h +++ b/bfdd/bfd.h @@ -252,11 +252,7 @@ struct bfd_session { struct bfd_timers remote_timers; uint64_t refcount; /* number of pointers referencing this. */ - - /* VTY context data. */ - QOBJ_FIELDS }; -DECLARE_QOBJ_TYPE(bfd_session) struct peer_label { TAILQ_ENTRY(peer_label) pl_entry; @@ -552,6 +548,9 @@ void gen_bfd_key(struct bfd_key *key, struct sockaddr_any *peer, struct bfd_session *bfd_session_new(void); struct bfd_session *bs_registrate(struct bfd_session *bs); void bfd_session_free(struct bfd_session *bs); +const struct bfd_session *bfd_session_next(const struct bfd_session *bs, + bool mhop); + /* BFD hash data structures interface */ void bfd_initialize(void); void bfd_shutdown(void); @@ -591,6 +590,14 @@ void bfdd_vty_init(void); /* + * bfdd_cli.c + * + * BFD daemon CLI implementation. + */ +void bfdd_cli_init(void); + + +/* * ptm_adapter.c */ void bfdd_zclient_init(struct zebra_privs_t *bfdd_priv); @@ -602,4 +609,12 @@ void bfdd_sessions_disable_vrf(struct vrf *vrf); int ptm_bfd_notify(struct bfd_session *bs); + +/* + * bfdd_northbound.c + * + * BFD northbound callbacks. + */ +extern const struct frr_yang_module_info frr_bfdd_info; + #endif /* _BFD_H_ */ diff --git a/bfdd/bfdd.c b/bfdd/bfdd.c index 6c277c98f..5a6089f38 100644 --- a/bfdd/bfdd.c +++ b/bfdd/bfdd.c @@ -93,10 +93,17 @@ static struct quagga_signal_t bfd_signals[] = { }, }; +static const struct frr_yang_module_info *bfdd_yang_modules[] = { + &frr_interface_info, + &frr_bfdd_info, +}; + FRR_DAEMON_INFO(bfdd, BFD, .vty_port = 2617, .proghelp = "Implementation of the BFD protocol.", .signals = bfd_signals, .n_signals = array_size(bfd_signals), - .privs = &bglobal.bfdd_privs) + .privs = &bglobal.bfdd_privs, + .yang_modules = bfdd_yang_modules, + .n_yang_modules = array_size(bfdd_yang_modules)) #define OPTION_CTLSOCK 1001 static struct option longopts[] = { diff --git a/bfdd/bfdd_cli.c b/bfdd/bfdd_cli.c new file mode 100644 index 000000000..200ae543c --- /dev/null +++ b/bfdd/bfdd_cli.c @@ -0,0 +1,232 @@ +/* + * BFD daemon CLI 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 "lib/command.h" +#include "lib/log.h" +#include "lib/northbound_cli.h" + +#ifndef VTYSH_EXTRACT_PL +#include "bfdd/bfdd_cli_clippy.c" +#endif /* VTYSH_EXTRACT_PL */ + +#include "bfd.h" + +/* + * Definitions. + */ +#define PEER_STR "Configure peer\n" +#define INTERFACE_NAME_STR "Configure interface name to use\n" +#define PEER_IPV4_STR "IPv4 peer address\n" +#define PEER_IPV6_STR "IPv6 peer address\n" +#define MHOP_STR "Configure multihop\n" +#define LOCAL_STR "Configure local address\n" +#define LOCAL_IPV4_STR "IPv4 local address\n" +#define LOCAL_IPV6_STR "IPv6 local address\n" +#define LOCAL_INTF_STR "Configure local interface name to use\n" +#define VRF_STR "Configure VRF\n" +#define VRF_NAME_STR "Configure VRF name\n" + +/* + * Prototypes. + */ + +/* + * Functions. + */ +DEFPY_NOSH( + bfd_peer_enter, bfd_peer_enter_cmd, + "peer <A.B.C.D|X:X::X:X> [{multihop$multihop|local-address <A.B.C.D|X:X::X:X>|interface IFNAME$ifname|vrf NAME}]", + PEER_STR + PEER_IPV4_STR + PEER_IPV6_STR + MHOP_STR + LOCAL_STR + LOCAL_IPV4_STR + LOCAL_IPV6_STR + INTERFACE_STR + LOCAL_INTF_STR + VRF_STR + VRF_NAME_STR) +{ + int ret, slen; + char xpath[XPATH_MAXLEN]; + char source_str[INET6_ADDRSTRLEN]; + + if (multihop) + snprintf(source_str, sizeof(source_str), "[source-addr='%s']", + local_address_str); + else + source_str[0] = 0; + + slen = snprintf(xpath, sizeof(xpath), + "/frr-bfdd:bfdd/bfd/sessions/%s%s[dest-addr='%s']", + multihop ? "multi-hop" : "single-hop", source_str, + peer_str); + if (ifname) + slen += snprintf(xpath + slen, sizeof(xpath) - slen, + "[interface='%s']", ifname); + else + slen += snprintf(xpath + slen, sizeof(xpath) - slen, + "[interface='']"); + if (vrf) + snprintf(xpath + slen, sizeof(xpath) - slen, "[vrf='%s']", vrf); + else + snprintf(xpath + slen, sizeof(xpath) - slen, "[vrf='%s']", + VRF_DEFAULT_NAME); + + nb_cli_enqueue_change(vty, xpath, NB_OP_CREATE, NULL); + + /* Apply settings immediatly. */ + ret = nb_cli_apply_changes(vty, NULL); + if (ret == CMD_SUCCESS) + VTY_PUSH_XPATH(BFD_PEER_NODE, xpath); + + return ret; +} + +DEFPY( + bfd_no_peer, bfd_no_peer_cmd, + "no peer <A.B.C.D|X:X::X:X> [{multihop$multihop|local-address <A.B.C.D|X:X::X:X>|interface IFNAME$ifname|vrf NAME}]", + NO_STR + PEER_STR + PEER_IPV4_STR + PEER_IPV6_STR + MHOP_STR + LOCAL_STR + LOCAL_IPV4_STR + LOCAL_IPV6_STR + INTERFACE_STR + LOCAL_INTF_STR + VRF_STR + VRF_NAME_STR) +{ + int slen; + char xpath[XPATH_MAXLEN]; + char source_str[INET6_ADDRSTRLEN]; + + if (multihop) + snprintf(source_str, sizeof(source_str), "[source-addr='%s']", + local_address_str); + else + source_str[0] = 0; + + slen = snprintf(xpath, sizeof(xpath), + "/frr-bfdd:bfdd/bfd/sessions/%s%s[dest-addr='%s']", + multihop ? "multi-hop" : "single-hop", source_str, + peer_str); + if (ifname) + slen += snprintf(xpath + slen, sizeof(xpath) - slen, + "[interface='%s']", ifname); + else + slen += snprintf(xpath + slen, sizeof(xpath) - slen, + "[interface='']"); + if (vrf) + snprintf(xpath + slen, sizeof(xpath) - slen, "[vrf='%s']", vrf); + else + snprintf(xpath + slen, sizeof(xpath) - slen, "[vrf='%s']", + VRF_DEFAULT_NAME); + + nb_cli_enqueue_change(vty, xpath, NB_OP_DESTROY, NULL); + + /* Apply settings immediatly. */ + return nb_cli_apply_changes(vty, NULL); +} + +DEFPY( + bfd_peer_shutdown, bfd_peer_shutdown_cmd, + "[no] shutdown", + NO_STR + "Disable BFD peer") +{ + nb_cli_enqueue_change(vty, "./administrative-down", NB_OP_MODIFY, + no ? "false" : "true"); + return nb_cli_apply_changes(vty, NULL); +} + +DEFPY( + bfd_peer_mult, bfd_peer_mult_cmd, + "detect-multiplier (2-255)$multiplier", + "Configure peer detection multiplier\n" + "Configure peer detection multiplier value\n") +{ + nb_cli_enqueue_change(vty, "./detection-multiplier", NB_OP_MODIFY, + multiplier_str); + return nb_cli_apply_changes(vty, NULL); +} + +DEFPY( + bfd_peer_rx, bfd_peer_rx_cmd, + "receive-interval (10-60000)$interval", + "Configure peer receive interval\n" + "Configure peer receive interval value in milliseconds\n") +{ + nb_cli_enqueue_change(vty, "./required-receive-interval", NB_OP_MODIFY, + interval_str); + return nb_cli_apply_changes(vty, NULL); +} + +DEFPY( + bfd_peer_tx, bfd_peer_tx_cmd, + "transmit-interval (10-60000)$interval", + "Configure peer transmit interval\n" + "Configure peer transmit interval value in milliseconds\n") +{ + nb_cli_enqueue_change(vty, "./desired-transmission-interval", + NB_OP_MODIFY, interval_str); + return nb_cli_apply_changes(vty, NULL); +} + +DEFPY( + bfd_peer_echo, bfd_peer_echo_cmd, + "[no] echo-mode", + NO_STR + "Configure echo mode\n") +{ + nb_cli_enqueue_change(vty, "./echo-mode", NB_OP_MODIFY, + no ? "false" : "true"); + return nb_cli_apply_changes(vty, NULL); +} + +DEFPY( + bfd_peer_echo_interval, bfd_peer_echo_interval_cmd, + "echo-interval (10-60000)$interval", + "Configure peer echo interval\n" + "Configure peer echo interval value in milliseconds\n") +{ + nb_cli_enqueue_change(vty, "./desired-echo-transmission-interval", + NB_OP_MODIFY, interval_str); + return nb_cli_apply_changes(vty, NULL); +} + +void +bfdd_cli_init(void) +{ + install_element(BFD_NODE, &bfd_peer_enter_cmd); + install_element(BFD_NODE, &bfd_no_peer_cmd); + + install_element(BFD_PEER_NODE, &bfd_peer_shutdown_cmd); + install_element(BFD_PEER_NODE, &bfd_peer_mult_cmd); + install_element(BFD_PEER_NODE, &bfd_peer_rx_cmd); + install_element(BFD_PEER_NODE, &bfd_peer_tx_cmd); + install_element(BFD_PEER_NODE, &bfd_peer_echo_cmd); + install_element(BFD_PEER_NODE, &bfd_peer_echo_interval_cmd); +} diff --git a/bfdd/bfdd_northbound.c b/bfdd/bfdd_northbound.c new file mode 100644 index 000000000..a22430e6b --- /dev/null +++ b/bfdd/bfdd_northbound.c @@ -0,0 +1,1060 @@ +/* + * 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 "lib/log.h" +#include "lib/northbound.h" + +#include "bfd.h" + +/* + * Prototypes. + */ +void bfd_session_get_key(bool mhop, const struct lyd_node *dnode, + struct bfd_key *bk); +int bfd_session_create(enum nb_event event, const struct lyd_node *dnode, + union nb_resource *resource, bool mhop); +int bfd_session_destroy(enum nb_event event, const struct lyd_node *dnode, + bool mhop); + +/* + * Helpers. + */ +void bfd_session_get_key(bool mhop, const struct lyd_node *dnode, + struct bfd_key *bk) +{ + const char *ifname = NULL, *vrfname = NULL; + struct sockaddr_any psa, lsa; + + /* Required destination parameter. */ + strtosa(yang_dnode_get_string(dnode, "./dest-addr"), &psa); + + /* Get optional source address. */ + memset(&lsa, 0, sizeof(lsa)); + if (yang_dnode_exists(dnode, "./source-addr")) + strtosa(yang_dnode_get_string(dnode, "./source-addr"), &lsa); + + /* Get optional interface and vrf names. */ + if (yang_dnode_exists(dnode, "./interface")) + ifname = yang_dnode_get_string(dnode, "./interface"); + if (yang_dnode_exists(dnode, "./vrf")) + vrfname = yang_dnode_get_string(dnode, "./vrf"); + + /* Generate the corresponding key. */ + gen_bfd_key(bk, &psa, &lsa, mhop, ifname, vrfname); +} + +int bfd_session_create(enum nb_event event, const struct lyd_node *dnode, + union nb_resource *resource, bool mhop) +{ + struct bfd_session *bs; + struct bfd_key bk; + + switch (event) { + case NB_EV_VALIDATE: + bfd_session_get_key(mhop, dnode, &bk); + if (bfd_key_lookup(bk)) + return NB_ERR_VALIDATION; + break; + + case NB_EV_PREPARE: + bs = bfd_session_new(); + if (bs == NULL) + return NB_ERR_RESOURCE; + + /* Fill the session key. */ + bfd_session_get_key(mhop, dnode, &bs->key); + + /* Set configuration flags. */ + BFD_SET_FLAG(bs->flags, BFD_SESS_FLAG_CONFIG); + if (mhop) + BFD_SET_FLAG(bs->flags, BFD_SESS_FLAG_MH); + if (bs->key.family == AF_INET6) + BFD_SET_FLAG(bs->flags, BFD_SESS_FLAG_IPV6); + + resource->ptr = bs; + break; + + case NB_EV_APPLY: + bs = resource->ptr; + if (bs_registrate(bs) == NULL) + return NB_ERR_RESOURCE; + + nb_running_set_entry(dnode, bs); + break; + + case NB_EV_ABORT: + bfd_session_free(resource->ptr); + break; + } + + return NB_OK; +} + +int bfd_session_destroy(enum nb_event event, const struct lyd_node *dnode, + bool mhop) +{ + struct bfd_key bk; + + switch (event) { + case NB_EV_VALIDATE: + bfd_session_get_key(mhop, dnode, &bk); + if (bfd_key_lookup(bk) == NULL) + return NB_ERR_VALIDATION; + break; + + case NB_EV_PREPARE: + /* NOTHING */ + break; + + case NB_EV_APPLY: + bfd_session_free(nb_running_unset_entry(dnode)); + break; + + case NB_EV_ABORT: + /* NOTHING */ + break; + } + + return NB_OK; +} + +/* + * XPath: /frr-bfdd:bfdd/bfd + */ +static int bfdd_bfd_create(enum nb_event event, + const struct lyd_node *dnode + __attribute__((__unused__)), + union nb_resource *resource + __attribute__((__unused__))) +{ + /* NOTHING */ + return NB_OK; +} + +static int bfdd_bfd_destroy(enum nb_event event, const struct lyd_node *dnode) +{ + /* NOTHING */ + return NB_OK; +} + +/* + * XPath: /frr-bfdd:bfdd/bfd/sessions/single-hop + */ +static int bfdd_bfd_sessions_single_hop_create(enum nb_event event, + const struct lyd_node *dnode, + union nb_resource *resource) +{ + return bfd_session_create(event, dnode, resource, false); +} + +static int bfdd_bfd_sessions_single_hop_destroy(enum nb_event event, + const struct lyd_node *dnode) +{ + return bfd_session_destroy(event, dnode, false); +} + +static const void * +bfdd_bfd_sessions_single_hop_get_next(const void *parent_list_entry + __attribute__((__unused__)), + const void *list_entry) +{ + return bfd_session_next(list_entry, false); +} + +static int bfdd_bfd_sessions_single_hop_get_keys(const void *list_entry, + struct yang_list_keys *keys) +{ + const struct bfd_session *bs = list_entry; + char dstbuf[INET6_ADDRSTRLEN]; + + inet_ntop(bs->key.family, &bs->key.peer, dstbuf, sizeof(dstbuf)); + + keys->num = 3; + strlcpy(keys->key[0], dstbuf, sizeof(keys->key[0])); + strlcpy(keys->key[1], bs->key.ifname, sizeof(keys->key[1])); + strlcpy(keys->key[2], bs->key.vrfname, sizeof(keys->key[2])); + + return NB_OK; +} + +static const void * +bfdd_bfd_sessions_single_hop_lookup_entry(const void *parent_list_entry + __attribute__((__unused__)), + const struct yang_list_keys *keys) +{ + const char *dest_addr = keys->key[0]; + const char *ifname = keys->key[1]; + const char *vrf = keys->key[2]; + struct sockaddr_any psa, lsa; + struct bfd_key bk; + + strtosa(dest_addr, &psa); + memset(&lsa, 0, sizeof(lsa)); + gen_bfd_key(&bk, &psa, &lsa, false, ifname, vrf); + + return bfd_key_lookup(bk); +} + +/* + * XPath: /frr-bfdd:bfdd/bfd/sessions/single-hop/source-addr + */ +static int bfdd_bfd_sessions_single_hop_source_addr_modify( + enum nb_event event __attribute__((__unused__)), + const struct lyd_node *dnode __attribute__((__unused__)), + union nb_resource *resource __attribute__((__unused__))) +{ + return NB_OK; +} + +static int bfdd_bfd_sessions_single_hop_source_addr_destroy( + enum nb_event event __attribute__((__unused__)), + const struct lyd_node *dnode __attribute__((__unused__))) +{ + return NB_OK; +} + +/* + * XPath: /frr-bfdd:bfdd/bfd/sessions/single-hop/detection-multiplier + */ +static int bfdd_bfd_sessions_single_hop_detection_multiplier_modify( + enum nb_event event, const struct lyd_node *dnode, + union nb_resource *resource __attribute__((__unused__))) +{ + uint8_t detection_multiplier = yang_dnode_get_uint8(dnode, NULL); + struct bfd_session *bs; + + switch (event) { + case NB_EV_VALIDATE: + if (detection_multiplier == 1) + return NB_ERR_VALIDATION; + break; + + case NB_EV_PREPARE: + /* NOTHING */ + break; + + case NB_EV_APPLY: + bs = nb_running_get_entry(dnode, NULL, true); + bs->detect_mult = detection_multiplier; + break; + + case NB_EV_ABORT: + /* NOTHING */ + break; + } + + return NB_OK; +} + +/* + * XPath: /frr-bfdd:bfdd/bfd/sessions/single-hop/desired-transmission-interval + */ +static int bfdd_bfd_sessions_single_hop_desired_transmission_interval_modify( + enum nb_event event, const struct lyd_node *dnode, + union nb_resource *resource __attribute__((__unused__))) +{ + uint32_t tx_interval = yang_dnode_get_uint32(dnode, NULL); + struct bfd_session *bs; + + switch (event) { + case NB_EV_VALIDATE: + if (tx_interval < 10 || tx_interval > 60000) + return NB_ERR_VALIDATION; + break; + + case NB_EV_PREPARE: + /* NOTHING */ + break; + + case NB_EV_APPLY: + bs = nb_running_get_entry(dnode, NULL, true); + + tx_interval *= 1000; + if (tx_interval == bs->timers.desired_min_tx) + return NB_OK; + + bs->timers.desired_min_tx = tx_interval; + bfd_set_polling(bs); + break; + + case NB_EV_ABORT: + /* NOTHING */ + break; + } + + return NB_OK; +} + +/* + * XPath: /frr-bfdd:bfdd/bfd/sessions/single-hop/required-receive-interval + */ +static int bfdd_bfd_sessions_single_hop_required_receive_interval_modify( + enum nb_event event, const struct lyd_node *dnode, + union nb_resource *resource __attribute__((__unused__))) +{ + uint32_t rx_interval = yang_dnode_get_uint32(dnode, NULL); + struct bfd_session *bs; + + switch (event) { + case NB_EV_VALIDATE: + if (rx_interval < 10 || rx_interval > 60000) + return NB_ERR_VALIDATION; + break; + + case NB_EV_PREPARE: + /* NOTHING */ + break; + + case NB_EV_APPLY: + bs = nb_running_get_entry(dnode, NULL, true); + + rx_interval *= 1000; + if (rx_interval == bs->timers.required_min_rx) + return NB_OK; + + bs->timers.required_min_rx = rx_interval; + bfd_set_polling(bs); + break; + + case NB_EV_ABORT: + /* NOTHING */ + break; + } + + return NB_OK; +} + +/* + * XPath: /frr-bfdd:bfdd/bfd/sessions/single-hop/administrative-down + */ +static int bfdd_bfd_sessions_single_hop_administrative_down_modify( + enum nb_event event, const struct lyd_node *dnode, + union nb_resource *resource __attribute__((__unused__))) +{ + bool shutdown = yang_dnode_get_bool(dnode, NULL); + struct bfd_session *bs; + + switch (event) { + case NB_EV_VALIDATE: + case NB_EV_PREPARE: + return NB_OK; + + case NB_EV_APPLY: + break; + + case NB_EV_ABORT: + return NB_OK; + } + + bs = nb_running_get_entry(dnode, NULL, true); + + if (shutdown == false) { + if (!BFD_CHECK_FLAG(bs->flags, BFD_SESS_FLAG_SHUTDOWN)) + return NB_OK; + + BFD_UNSET_FLAG(bs->flags, BFD_SESS_FLAG_SHUTDOWN); + + /* Change and notify state change. */ + bs->ses_state = PTM_BFD_DOWN; + control_notify(bs); + + /* Enable all timers. */ + bfd_recvtimer_update(bs); + bfd_xmttimer_update(bs, bs->xmt_TO); + if (BFD_CHECK_FLAG(bs->flags, BFD_SESS_FLAG_ECHO)) { + bfd_echo_recvtimer_update(bs); + bfd_echo_xmttimer_update(bs, bs->echo_xmt_TO); + } + } else { + if (BFD_CHECK_FLAG(bs->flags, BFD_SESS_FLAG_SHUTDOWN)) + return NB_OK; + + BFD_SET_FLAG(bs->flags, BFD_SESS_FLAG_SHUTDOWN); + + /* Disable all events. */ + bfd_recvtimer_delete(bs); + bfd_echo_recvtimer_delete(bs); + bfd_xmttimer_delete(bs); + bfd_echo_xmttimer_delete(bs); + + /* Change and notify state change. */ + bs->ses_state = PTM_BFD_ADM_DOWN; + control_notify(bs); + + ptm_bfd_snd(bs, 0); + } + + return NB_OK; +} + +/* + * XPath: /frr-bfdd:bfdd/bfd/sessions/single-hop/echo-mode + */ +static int bfdd_bfd_sessions_single_hop_echo_mode_modify( + enum nb_event event, const struct lyd_node *dnode, + union nb_resource *resource __attribute__((__unused__))) +{ + bool echo = yang_dnode_get_bool(dnode, NULL); + struct bfd_session *bs; + + switch (event) { + case NB_EV_VALIDATE: + case NB_EV_PREPARE: + return NB_OK; + + case NB_EV_APPLY: + break; + + case NB_EV_ABORT: + return NB_OK; + } + + bs = nb_running_get_entry(dnode, NULL, true); + + if (echo == false) { + if (!BFD_CHECK_FLAG(bs->flags, BFD_SESS_FLAG_ECHO)) + return NB_OK; + + BFD_UNSET_FLAG(bs->flags, BFD_SESS_FLAG_ECHO); + ptm_bfd_echo_stop(bs); + } else { + if (BFD_CHECK_FLAG(bs->flags, BFD_SESS_FLAG_ECHO)) + return NB_OK; + + BFD_SET_FLAG(bs->flags, BFD_SESS_FLAG_ECHO); + /* Apply setting immediately. */ + if (!BFD_CHECK_FLAG(bs->flags, BFD_SESS_FLAG_SHUTDOWN)) + bs_echo_timer_handler(bs); + } + + return NB_OK; +} + +/* + * XPath: + * /frr-bfdd:bfdd/bfd/sessions/single-hop/desired-echo-transmission-interval + */ +static int +bfdd_bfd_sessions_single_hop_desired_echo_transmission_interval_modify( + enum nb_event event, const struct lyd_node *dnode, + union nb_resource *resource __attribute__((__unused__))) +{ + uint32_t echo_interval = yang_dnode_get_uint32(dnode, NULL); + struct bfd_session *bs; + + switch (event) { + case NB_EV_VALIDATE: + if (echo_interval < 10 || echo_interval > 60000) + return NB_ERR_VALIDATION; + break; + + case NB_EV_PREPARE: + /* NOTHING */ + break; + + case NB_EV_APPLY: + bs = nb_running_get_entry(dnode, NULL, true); + + echo_interval *= 1000; + if (echo_interval == bs->timers.required_min_echo) + return NB_OK; + + bs->timers.required_min_echo = echo_interval; + break; + + case NB_EV_ABORT: + /* NOTHING */ + break; + } + + return NB_OK; +} + +/* + * XPath: /frr-bfdd:bfdd/bfd/sessions/single-hop/stats/local-discriminator + */ +static struct yang_data * +bfdd_bfd_sessions_single_hop_stats_local_discriminator_get_elem( + const char *xpath, const void *list_entry) +{ + const struct bfd_session *bs = list_entry; + + return yang_data_new_uint32(xpath, bs->discrs.my_discr); +} + +/* + * XPath: /frr-bfdd:bfdd/bfd/sessions/single-hop/stats/local-state + */ +static struct yang_data * +bfdd_bfd_sessions_single_hop_stats_local_state_get_elem(const char *xpath, + const void *list_entry) +{ + const struct bfd_session *bs = list_entry; + + return yang_data_new_enum(xpath, bs->ses_state); +} + +/* + * XPath: /frr-bfdd:bfdd/bfd/sessions/single-hop/stats/local-diagnostic + */ +static struct yang_data * +bfdd_bfd_sessions_single_hop_stats_local_diagnostic_get_elem( + const char *xpath, const void *list_entry) +{ + const struct bfd_session *bs = list_entry; + + return yang_data_new_enum(xpath, bs->local_diag); +} + +/* + * XPath: /frr-bfdd:bfdd/bfd/sessions/single-hop/stats/local-multiplier + */ +static struct yang_data * +bfdd_bfd_sessions_single_hop_stats_local_multiplier_get_elem( + const char *xpath, const void *list_entry) +{ + const struct bfd_session *bs = list_entry; + + return yang_data_new_int8(xpath, bs->detect_mult); +} + +/* + * XPath: /frr-bfdd:bfdd/bfd/sessions/single-hop/stats/remote-discriminator + */ +static struct yang_data * +bfdd_bfd_sessions_single_hop_stats_remote_discriminator_get_elem( + const char *xpath, const void *list_entry) +{ + const struct bfd_session *bs = list_entry; + + return yang_data_new_uint32(xpath, bs->discrs.remote_discr); +} + +/* + * XPath: /frr-bfdd:bfdd/bfd/sessions/single-hop/stats/remote-state + */ +static struct yang_data * +bfdd_bfd_sessions_single_hop_stats_remote_state_get_elem(const char *xpath, + const void *list_entry) +{ + const struct bfd_session *bs = list_entry; + + return yang_data_new_enum(xpath, bs->ses_state); +} + +/* + * XPath: /frr-bfdd:bfdd/bfd/sessions/single-hop/stats/remote-diagnostic + */ +static struct yang_data * +bfdd_bfd_sessions_single_hop_stats_remote_diagnostic_get_elem( + const char *xpath, const void *list_entry) +{ + const struct bfd_session *bs = list_entry; + + return yang_data_new_enum(xpath, bs->remote_diag); +} + +/* + * XPath: /frr-bfdd:bfdd/bfd/sessions/single-hop/stats/remote-multiplier + */ +static struct yang_data * +bfdd_bfd_sessions_single_hop_stats_remote_multiplier_get_elem( + const char *xpath, const void *list_entry) +{ + const struct bfd_session *bs = list_entry; + + return yang_data_new_int8(xpath, bs->remote_detect_mult); +} + +/* + * XPath: + * /frr-bfdd:bfdd/bfd/sessions/single-hop/stats/negotiated-transmission-interval + */ +static struct yang_data * +bfdd_bfd_sessions_single_hop_stats_negotiated_transmission_interval_get_elem( + const char *xpath, const void *list_entry) +{ + const struct bfd_session *bs = list_entry; + + return yang_data_new_uint32(xpath, + bs->remote_timers.desired_min_tx / 1000); +} + +/* + * XPath: + * /frr-bfdd:bfdd/bfd/sessions/single-hop/stats/negotiated-receive-interval + */ +static struct yang_data * +bfdd_bfd_sessions_single_hop_stats_negotiated_receive_interval_get_elem( + const char *xpath, const void *list_entry) +{ + const struct bfd_session *bs = list_entry; + + return yang_data_new_uint32(xpath, + bs->remote_timers.required_min_rx / 1000); +} + +/* + * XPath: /frr-bfdd:bfdd/bfd/sessions/single-hop/stats/detection-mode + */ +static struct yang_data * +bfdd_bfd_sessions_single_hop_stats_detection_mode_get_elem( + const char *xpath, const void *list_entry) +{ + const struct bfd_session *bs = list_entry; + int detection_mode; + + /* + * Detection mode: + * 1. Async with echo + * 2. Async without echo + * 3. Demand with echo + * 4. Demand without echo + * + * TODO: support demand mode. + */ + if (BFD_CHECK_FLAG(bs->flags, BFD_SESS_FLAG_ECHO)) + detection_mode = 1; + else + detection_mode = 2; + + return yang_data_new_enum(xpath, detection_mode); +} + +/* + * XPath: /frr-bfdd:bfdd/bfd/sessions/single-hop/stats/last-down-time + */ +static struct yang_data * +bfdd_bfd_sessions_single_hop_stats_last_down_time_get_elem( + const char *xpath __attribute__((__unused__)), + const void *list_entry __attribute__((__unused__))) +{ + /* + * TODO: implement me. + * + * No yang support for time elements yet. + */ + return NULL; +} + +/* + * XPath: /frr-bfdd:bfdd/bfd/sessions/single-hop/stats/last-up-time + */ +static struct yang_data * +bfdd_bfd_sessions_single_hop_stats_last_up_time_get_elem( + const char *xpath __attribute__((__unused__)), + const void *list_entry __attribute__((__unused__))) +{ + /* + * TODO: implement me. + * + * No yang support for time elements yet. + */ + return NULL; +} + +/* + * XPath: /frr-bfdd:bfdd/bfd/sessions/single-hop/stats/session-down-count + */ +static struct yang_data * +bfdd_bfd_sessions_single_hop_stats_session_down_count_get_elem( + const char *xpath, const void *list_entry) +{ + const struct bfd_session *bs = list_entry; + + return yang_data_new_uint64(xpath, bs->stats.session_down); +} + +/* + * XPath: /frr-bfdd:bfdd/bfd/sessions/single-hop/stats/session-up-count + */ +static struct yang_data * +bfdd_bfd_sessions_single_hop_stats_session_up_count_get_elem( + const char *xpath, const void *list_entry) +{ + const struct bfd_session *bs = list_entry; + + return yang_data_new_uint64(xpath, bs->stats.session_up); +} + +/* + * XPath: + * /frr-bfdd:bfdd/bfd/sessions/single-hop/stats/control-packet-input-count + */ +static struct yang_data * +bfdd_bfd_sessions_single_hop_stats_control_packet_input_count_get_elem( + const char *xpath, const void *list_entry) +{ + const struct bfd_session *bs = list_entry; + + return yang_data_new_uint64(xpath, bs->stats.rx_ctrl_pkt); +} + +/* + * XPath: + * /frr-bfdd:bfdd/bfd/sessions/single-hop/stats/control-packet-output-count + */ +static struct yang_data * +bfdd_bfd_sessions_single_hop_stats_control_packet_output_count_get_elem( + const char *xpath, const void *list_entry) +{ + const struct bfd_session *bs = list_entry; + + return yang_data_new_uint64(xpath, bs->stats.tx_ctrl_pkt); +} + +/* + * XPath: + * /frr-bfdd:bfdd/bfd/sessions/single-hop/stats/negotiated-echo-transmission-interval + */ +static struct yang_data * +bfdd_bfd_sessions_single_hop_stats_negotiated_echo_transmission_interval_get_elem( + const char *xpath, const void *list_entry) +{ + const struct bfd_session *bs = list_entry; + + return yang_data_new_uint32(xpath, + bs->remote_timers.required_min_echo / 1000); +} + +/* + * XPath: /frr-bfdd:bfdd/bfd/sessions/single-hop/stats/echo-packet-input-count + */ +static struct yang_data * +bfdd_bfd_sessions_single_hop_stats_echo_packet_input_count_get_elem( + const char *xpath, const void *list_entry) +{ + const struct bfd_session *bs = list_entry; + + return yang_data_new_uint64(xpath, bs->stats.rx_echo_pkt); +} + +/* + * XPath: /frr-bfdd:bfdd/bfd/sessions/single-hop/stats/echo-packet-output-count + */ +static struct yang_data * +bfdd_bfd_sessions_single_hop_stats_echo_packet_output_count_get_elem( + const char *xpath, const void *list_entry) +{ + const struct bfd_session *bs = list_entry; + + return yang_data_new_uint64(xpath, bs->stats.tx_echo_pkt); +} + +/* + * XPath: /frr-bfdd:bfdd/bfd/sessions/multi-hop + */ +static int bfdd_bfd_sessions_multi_hop_create(enum nb_event event, + const struct lyd_node *dnode, + union nb_resource *resource) +{ + return bfd_session_create(event, dnode, resource, true); +} + +static int bfdd_bfd_sessions_multi_hop_destroy(enum nb_event event, + const struct lyd_node *dnode) +{ + return bfd_session_destroy(event, dnode, true); +} + +static const void * +bfdd_bfd_sessions_multi_hop_get_next(const void *parent_list_entry + __attribute__((__unused__)), + const void *list_entry) +{ + return bfd_session_next(list_entry, true); +} + +static int bfdd_bfd_sessions_multi_hop_get_keys(const void *list_entry, + struct yang_list_keys *keys) +{ + const struct bfd_session *bs = list_entry; + char dstbuf[INET6_ADDRSTRLEN], srcbuf[INET6_ADDRSTRLEN]; + + inet_ntop(bs->key.family, &bs->key.peer, dstbuf, sizeof(dstbuf)); + inet_ntop(bs->key.family, &bs->key.local, srcbuf, sizeof(srcbuf)); + + keys->num = 4; + strlcpy(keys->key[0], srcbuf, sizeof(keys->key[0])); + strlcpy(keys->key[1], dstbuf, sizeof(keys->key[1])); + strlcpy(keys->key[2], bs->key.ifname, sizeof(keys->key[2])); + strlcpy(keys->key[3], bs->key.vrfname, sizeof(keys->key[3])); + + return NB_OK; +} + +static const void * +bfdd_bfd_sessions_multi_hop_lookup_entry(const void *parent_list_entry + __attribute__((__unused__)), + const struct yang_list_keys *keys) +{ + const char *source_addr = keys->key[0]; + const char *dest_addr = keys->key[1]; + const char *ifname = keys->key[2]; + const char *vrf = keys->key[3]; + struct sockaddr_any psa, lsa; + struct bfd_key bk; + + strtosa(dest_addr, &psa); + strtosa(source_addr, &lsa); + gen_bfd_key(&bk, &psa, &lsa, true, ifname, vrf); + + return bfd_key_lookup(bk); +} + +/* clang-format off */ +const struct frr_yang_module_info frr_bfdd_info = { + .name = "frr-bfdd", + .nodes = { + { + .xpath = "/frr-bfdd:bfdd/bfd", + .cbs.create = bfdd_bfd_create, + .cbs.destroy = bfdd_bfd_destroy, + .cbs.cli_show = bfd_cli_show_header, + .cbs.cli_show_end = bfd_cli_show_header_end, + }, + { + .xpath = "/frr-bfdd:bfdd/bfd/sessions/single-hop", + .cbs.create = bfdd_bfd_sessions_single_hop_create, + .cbs.destroy = bfdd_bfd_sessions_single_hop_destroy, + .cbs.get_next = bfdd_bfd_sessions_single_hop_get_next, + .cbs.get_keys = bfdd_bfd_sessions_single_hop_get_keys, + .cbs.lookup_entry = bfdd_bfd_sessions_single_hop_lookup_entry, + }, + { + .xpath = "/frr-bfdd:bfdd/bfd/sessions/single-hop/source-addr", + .cbs.modify = bfdd_bfd_sessions_single_hop_source_addr_modify, + .cbs.destroy = bfdd_bfd_sessions_single_hop_source_addr_destroy, + }, + { + .xpath = "/frr-bfdd:bfdd/bfd/sessions/single-hop/detection-multiplier", + .cbs.modify = bfdd_bfd_sessions_single_hop_detection_multiplier_modify, + }, + { + .xpath = "/frr-bfdd:bfdd/bfd/sessions/single-hop/desired-transmission-interval", + .cbs.modify = bfdd_bfd_sessions_single_hop_desired_transmission_interval_modify, + }, + { + .xpath = "/frr-bfdd:bfdd/bfd/sessions/single-hop/required-receive-interval", + .cbs.modify = bfdd_bfd_sessions_single_hop_required_receive_interval_modify, + }, + { + .xpath = "/frr-bfdd:bfdd/bfd/sessions/single-hop/administrative-down", + .cbs.modify = bfdd_bfd_sessions_single_hop_administrative_down_modify, + }, + { + .xpath = "/frr-bfdd:bfdd/bfd/sessions/single-hop/echo-mode", + .cbs.modify = bfdd_bfd_sessions_single_hop_echo_mode_modify, + }, + { + .xpath = "/frr-bfdd:bfdd/bfd/sessions/single-hop/desired-echo-transmission-interval", + .cbs.modify = bfdd_bfd_sessions_single_hop_desired_echo_transmission_interval_modify, + }, + { + .xpath = "/frr-bfdd:bfdd/bfd/sessions/single-hop/stats/local-discriminator", + .cbs.get_elem = bfdd_bfd_sessions_single_hop_stats_local_discriminator_get_elem, + }, + { + .xpath = "/frr-bfdd:bfdd/bfd/sessions/single-hop/stats/local-state", + .cbs.get_elem = bfdd_bfd_sessions_single_hop_stats_local_state_get_elem, + }, + { + .xpath = "/frr-bfdd:bfdd/bfd/sessions/single-hop/stats/local-diagnostic", + .cbs.get_elem = bfdd_bfd_sessions_single_hop_stats_local_diagnostic_get_elem, + }, + { + .xpath = "/frr-bfdd:bfdd/bfd/sessions/single-hop/stats/local-multiplier", + .cbs.get_elem = bfdd_bfd_sessions_single_hop_stats_local_multiplier_get_elem, + }, + { + .xpath = "/frr-bfdd:bfdd/bfd/sessions/single-hop/stats/remote-discriminator", + .cbs.get_elem = bfdd_bfd_sessions_single_hop_stats_remote_discriminator_get_elem, + }, + { + .xpath = "/frr-bfdd:bfdd/bfd/sessions/single-hop/stats/remote-state", + .cbs.get_elem = bfdd_bfd_sessions_single_hop_stats_remote_state_get_elem, + }, + { + .xpath = "/frr-bfdd:bfdd/bfd/sessions/single-hop/stats/remote-diagnostic", + .cbs.get_elem = bfdd_bfd_sessions_single_hop_stats_remote_diagnostic_get_elem, + }, + { + .xpath = "/frr-bfdd:bfdd/bfd/sessions/single-hop/stats/remote-multiplier", + .cbs.get_elem = bfdd_bfd_sessions_single_hop_stats_remote_multiplier_get_elem, + }, + { + .xpath = "/frr-bfdd:bfdd/bfd/sessions/single-hop/stats/negotiated-transmission-interval", + .cbs.get_elem = bfdd_bfd_sessions_single_hop_stats_negotiated_transmission_interval_get_elem, + }, + { + .xpath = "/frr-bfdd:bfdd/bfd/sessions/single-hop/stats/negotiated-receive-interval", + .cbs.get_elem = bfdd_bfd_sessions_single_hop_stats_negotiated_receive_interval_get_elem, + }, + { + .xpath = "/frr-bfdd:bfdd/bfd/sessions/single-hop/stats/detection-mode", + .cbs.get_elem = bfdd_bfd_sessions_single_hop_stats_detection_mode_get_elem, + }, + { + .xpath = "/frr-bfdd:bfdd/bfd/sessions/single-hop/stats/last-down-time", + .cbs.get_elem = bfdd_bfd_sessions_single_hop_stats_last_down_time_get_elem, + }, + { + .xpath = "/frr-bfdd:bfdd/bfd/sessions/single-hop/stats/last-up-time", + .cbs.get_elem = bfdd_bfd_sessions_single_hop_stats_last_up_time_get_elem, + }, + { + .xpath = "/frr-bfdd:bfdd/bfd/sessions/single-hop/stats/session-down-count", + .cbs.get_elem = bfdd_bfd_sessions_single_hop_stats_session_down_count_get_elem, + }, + { + .xpath = "/frr-bfdd:bfdd/bfd/sessions/single-hop/stats/session-up-count", + .cbs.get_elem = bfdd_bfd_sessions_single_hop_stats_session_up_count_get_elem, + }, + { + .xpath = "/frr-bfdd:bfdd/bfd/sessions/single-hop/stats/control-packet-input-count", + .cbs.get_elem = bfdd_bfd_sessions_single_hop_stats_control_packet_input_count_get_elem, + }, + { + .xpath = "/frr-bfdd:bfdd/bfd/sessions/single-hop/stats/control-packet-output-count", + .cbs.get_elem = bfdd_bfd_sessions_single_hop_stats_control_packet_output_count_get_elem, + }, + { + .xpath = "/frr-bfdd:bfdd/bfd/sessions/single-hop/stats/negotiated-echo-transmission-interval", + .cbs.get_elem = bfdd_bfd_sessions_single_hop_stats_negotiated_echo_transmission_interval_get_elem, + }, + { + .xpath = "/frr-bfdd:bfdd/bfd/sessions/single-hop/stats/echo-packet-input-count", + .cbs.get_elem = bfdd_bfd_sessions_single_hop_stats_echo_packet_input_count_get_elem, + }, + { + .xpath = "/frr-bfdd:bfdd/bfd/sessions/single-hop/stats/echo-packet-output-count", + .cbs.get_elem = bfdd_bfd_sessions_single_hop_stats_echo_packet_output_count_get_elem, + }, + { + .xpath = "/frr-bfdd:bfdd/bfd/sessions/multi-hop", + .cbs.create = bfdd_bfd_sessions_multi_hop_create, + .cbs.destroy = bfdd_bfd_sessions_multi_hop_destroy, + .cbs.get_next = bfdd_bfd_sessions_multi_hop_get_next, + .cbs.get_keys = bfdd_bfd_sessions_multi_hop_get_keys, + .cbs.lookup_entry = bfdd_bfd_sessions_multi_hop_lookup_entry, + }, + { + .xpath = "/frr-bfdd:bfdd/bfd/sessions/multi-hop/detection-multiplier", + .cbs.modify = bfdd_bfd_sessions_single_hop_detection_multiplier_modify, + }, + { + .xpath = "/frr-bfdd:bfdd/bfd/sessions/multi-hop/desired-transmission-interval", + .cbs.modify = bfdd_bfd_sessions_single_hop_desired_transmission_interval_modify, + }, + { + .xpath = "/frr-bfdd:bfdd/bfd/sessions/multi-hop/required-receive-interval", + .cbs.modify = bfdd_bfd_sessions_single_hop_required_receive_interval_modify, + }, + { + .xpath = "/frr-bfdd:bfdd/bfd/sessions/multi-hop/administrative-down", + .cbs.modify = bfdd_bfd_sessions_single_hop_administrative_down_modify, + }, + { + .xpath = "/frr-bfdd:bfdd/bfd/sessions/multi-hop/stats/local-discriminator", + .cbs.get_elem = bfdd_bfd_sessions_single_hop_stats_local_discriminator_get_elem, + }, + { + .xpath = "/frr-bfdd:bfdd/bfd/sessions/multi-hop/stats/local-state", + .cbs.get_elem = bfdd_bfd_sessions_single_hop_stats_local_state_get_elem, + }, + { + .xpath = "/frr-bfdd:bfdd/bfd/sessions/multi-hop/stats/local-diagnostic", + .cbs.get_elem = bfdd_bfd_sessions_single_hop_stats_local_diagnostic_get_elem, + }, + { + .xpath = "/frr-bfdd:bfdd/bfd/sessions/multi-hop/stats/local-multiplier", + .cbs.get_elem = bfdd_bfd_sessions_single_hop_stats_local_multiplier_get_elem, + }, + { + .xpath = "/frr-bfdd:bfdd/bfd/sessions/multi-hop/stats/remote-discriminator", + .cbs.get_elem = bfdd_bfd_sessions_single_hop_stats_remote_discriminator_get_elem, + }, + { + .xpath = "/frr-bfdd:bfdd/bfd/sessions/multi-hop/stats/remote-state", + .cbs.get_elem = bfdd_bfd_sessions_single_hop_stats_remote_state_get_elem, + }, + { + .xpath = "/frr-bfdd:bfdd/bfd/sessions/multi-hop/stats/remote-diagnostic", + .cbs.get_elem = bfdd_bfd_sessions_single_hop_stats_remote_diagnostic_get_elem, + }, + { + .xpath = "/frr-bfdd:bfdd/bfd/sessions/multi-hop/stats/remote-multiplier", + .cbs.get_elem = bfdd_bfd_sessions_single_hop_stats_remote_multiplier_get_elem, + }, + { + .xpath = "/frr-bfdd:bfdd/bfd/sessions/multi-hop/stats/negotiated-transmission-interval", + .cbs.get_elem = bfdd_bfd_sessions_single_hop_stats_negotiated_transmission_interval_get_elem, + }, + { + .xpath = "/frr-bfdd:bfdd/bfd/sessions/multi-hop/stats/negotiated-receive-interval", + .cbs.get_elem = bfdd_bfd_sessions_single_hop_stats_negotiated_receive_interval_get_elem, + }, + { + .xpath = "/frr-bfdd:bfdd/bfd/sessions/multi-hop/stats/detection-mode", + .cbs.get_elem = bfdd_bfd_sessions_single_hop_stats_detection_mode_get_elem, + }, + { + .xpath = "/frr-bfdd:bfdd/bfd/sessions/multi-hop/stats/last-down-time", + .cbs.get_elem = bfdd_bfd_sessions_single_hop_stats_last_down_time_get_elem, + }, + { + .xpath = "/frr-bfdd:bfdd/bfd/sessions/multi-hop/stats/last-up-time", + .cbs.get_elem = bfdd_bfd_sessions_single_hop_stats_last_up_time_get_elem, + }, + { + .xpath = "/frr-bfdd:bfdd/bfd/sessions/multi-hop/stats/session-down-count", + .cbs.get_elem = bfdd_bfd_sessions_single_hop_stats_session_down_count_get_elem, + }, + { + .xpath = "/frr-bfdd:bfdd/bfd/sessions/multi-hop/stats/session-up-count", + .cbs.get_elem = bfdd_bfd_sessions_single_hop_stats_session_up_count_get_elem, + }, + { + .xpath = "/frr-bfdd:bfdd/bfd/sessions/multi-hop/stats/control-packet-input-count", + .cbs.get_elem = bfdd_bfd_sessions_single_hop_stats_control_packet_input_count_get_elem, + }, + { + .xpath = "/frr-bfdd:bfdd/bfd/sessions/multi-hop/stats/control-packet-output-count", + .cbs.get_elem = bfdd_bfd_sessions_single_hop_stats_control_packet_output_count_get_elem, + }, + { + .xpath = "/frr-bfdd:bfdd/bfd/sessions/multi-hop/stats/negotiated-echo-transmission-interval", + .cbs.get_elem = bfdd_bfd_sessions_single_hop_stats_negotiated_echo_transmission_interval_get_elem, + }, + { + .xpath = "/frr-bfdd:bfdd/bfd/sessions/multi-hop/stats/echo-packet-input-count", + .cbs.get_elem = bfdd_bfd_sessions_single_hop_stats_echo_packet_input_count_get_elem, + }, + { + .xpath = "/frr-bfdd:bfdd/bfd/sessions/multi-hop/stats/echo-packet-output-count", + .cbs.get_elem = bfdd_bfd_sessions_single_hop_stats_echo_packet_output_count_get_elem, + }, + { + .xpath = NULL, + }, + } +}; diff --git a/bfdd/bfdd_vty.c b/bfdd/bfdd_vty.c index 6f0b85c41..befb8b0af 100644 --- a/bfdd/bfdd_vty.c +++ b/bfdd/bfdd_vty.c @@ -34,8 +34,6 @@ /* * Commands help string definitions. */ -#define PEER_STR "Configure peer\n" -#define INTERFACE_NAME_STR "Configure interface name to use\n" #define PEER_IPV4_STR "IPv4 peer address\n" #define PEER_IPV6_STR "IPv6 peer address\n" #define MHOP_STR "Configure multihop\n" @@ -43,8 +41,6 @@ #define LOCAL_IPV4_STR "IPv4 local address\n" #define LOCAL_IPV6_STR "IPv6 local address\n" #define LOCAL_INTF_STR "Configure local interface name to use\n" -#define VRF_STR "Configure VRF\n" -#define VRF_NAME_STR "Configure VRF name\n" /* * Prototypes @@ -88,256 +84,6 @@ DEFUN_NOSH(bfd_enter, bfd_enter_cmd, "bfd", "Configure BFD peers\n") return CMD_SUCCESS; } -DEFUN_NOSH( - bfd_peer_enter, bfd_peer_enter_cmd, - "peer <A.B.C.D|X:X::X:X> [{multihop|local-address <A.B.C.D|X:X::X:X>|interface IFNAME|vrf NAME}]", - PEER_STR PEER_IPV4_STR PEER_IPV6_STR - MHOP_STR - LOCAL_STR LOCAL_IPV4_STR LOCAL_IPV6_STR - INTERFACE_STR - LOCAL_INTF_STR - VRF_STR VRF_NAME_STR) -{ - bool mhop; - int idx; - struct bfd_session *bs; - const char *peer, *ifname, *local, *vrfname; - struct bfd_peer_cfg bpc; - struct sockaddr_any psa, lsa, *lsap; - char errormsg[128]; - - vrfname = peer = ifname = local = NULL; - - /* Gather all provided information. */ - peer = argv[1]->arg; - - idx = 0; - mhop = argv_find(argv, argc, "multihop", &idx); - - idx = 0; - if (argv_find(argv, argc, "interface", &idx)) - ifname = argv[idx + 1]->arg; - - idx = 0; - if (argv_find(argv, argc, "local-address", &idx)) - local = argv[idx + 1]->arg; - - idx = 0; - if (argv_find(argv, argc, "vrf", &idx)) - vrfname = argv[idx + 1]->arg; - - strtosa(peer, &psa); - if (local) { - strtosa(local, &lsa); - lsap = &lsa; - } else - lsap = NULL; - - if (bfd_configure_peer(&bpc, mhop, &psa, lsap, ifname, vrfname, - errormsg, sizeof(errormsg)) - != 0) { - vty_out(vty, "%% Invalid peer configuration: %s\n", errormsg); - return CMD_WARNING_CONFIG_FAILED; - } - - bs = bs_peer_find(&bpc); - if (bs == NULL) { - bs = ptm_bfd_sess_new(&bpc); - if (bs == NULL) { - vty_out(vty, "%% Failed to add peer.\n"); - return CMD_WARNING_CONFIG_FAILED; - } - } - - if (!BFD_CHECK_FLAG(bs->flags, BFD_SESS_FLAG_CONFIG)) { - if (bs->refcount) - vty_out(vty, "%% session peer is now configurable via bfd daemon.\n"); - BFD_SET_FLAG(bs->flags, BFD_SESS_FLAG_CONFIG); - } - - VTY_PUSH_CONTEXT(BFD_PEER_NODE, bs); - - return CMD_SUCCESS; -} - -DEFPY(bfd_peer_detectmultiplier, bfd_peer_detectmultiplier_cmd, - "detect-multiplier (2-255)$multiplier", - "Configure peer detection multiplier\n" - "Configure peer detection multiplier value\n") -{ - struct bfd_session *bs; - - bs = VTY_GET_CONTEXT(bfd_session); - if (bs->detect_mult == multiplier) - return CMD_SUCCESS; - - bs->detect_mult = multiplier; - - return CMD_SUCCESS; -} - -DEFPY(bfd_peer_recvinterval, bfd_peer_recvinterval_cmd, - "receive-interval (10-60000)$interval", - "Configure peer receive interval\n" - "Configure peer receive interval value in milliseconds\n") -{ - struct bfd_session *bs; - - bs = VTY_GET_CONTEXT(bfd_session); - if (bs->timers.required_min_rx == (uint32_t)(interval * 1000)) - return CMD_SUCCESS; - - bs->timers.required_min_rx = interval * 1000; - bfd_set_polling(bs); - - return CMD_SUCCESS; -} - -DEFPY(bfd_peer_txinterval, bfd_peer_txinterval_cmd, - "transmit-interval (10-60000)$interval", - "Configure peer transmit interval\n" - "Configure peer transmit interval value in milliseconds\n") -{ - struct bfd_session *bs; - - bs = VTY_GET_CONTEXT(bfd_session); - if (bs->timers.desired_min_tx == (uint32_t)(interval * 1000)) - return CMD_SUCCESS; - - bs->timers.desired_min_tx = interval * 1000; - bfd_set_polling(bs); - - return CMD_SUCCESS; -} - -DEFPY(bfd_peer_echointerval, bfd_peer_echointerval_cmd, - "echo-interval (10-60000)$interval", - "Configure peer echo interval\n" - "Configure peer echo interval value in milliseconds\n") -{ - struct bfd_session *bs; - - bs = VTY_GET_CONTEXT(bfd_session); - if (bs->timers.required_min_echo == (uint32_t)(interval * 1000)) - return CMD_SUCCESS; - - bs->timers.required_min_echo = interval * 1000; - - return CMD_SUCCESS; -} - -DEFPY(bfd_peer_shutdown, bfd_peer_shutdown_cmd, "[no] shutdown", - NO_STR "Disable BFD peer") -{ - struct bfd_session *bs; - - bs = VTY_GET_CONTEXT(bfd_session); - if (no) { - if (!BFD_CHECK_FLAG(bs->flags, BFD_SESS_FLAG_SHUTDOWN)) - return CMD_SUCCESS; - - BFD_UNSET_FLAG(bs->flags, BFD_SESS_FLAG_SHUTDOWN); - - /* Change and notify state change. */ - bs->ses_state = PTM_BFD_DOWN; - control_notify(bs); - - /* Enable all timers. */ - bfd_recvtimer_update(bs); - bfd_xmttimer_update(bs, bs->xmt_TO); - if (BFD_CHECK_FLAG(bs->flags, BFD_SESS_FLAG_ECHO)) { - bfd_echo_recvtimer_update(bs); - bfd_echo_xmttimer_update(bs, bs->echo_xmt_TO); - } - } else { - if (BFD_CHECK_FLAG(bs->flags, BFD_SESS_FLAG_SHUTDOWN)) - return CMD_SUCCESS; - - BFD_SET_FLAG(bs->flags, BFD_SESS_FLAG_SHUTDOWN); - - /* Disable all events. */ - bfd_recvtimer_delete(bs); - bfd_echo_recvtimer_delete(bs); - bfd_xmttimer_delete(bs); - bfd_echo_xmttimer_delete(bs); - - /* Change and notify state change. */ - bs->ses_state = PTM_BFD_ADM_DOWN; - control_notify(bs); - - ptm_bfd_snd(bs, 0); - } - - return CMD_SUCCESS; -} - -DEFPY(bfd_peer_echo, bfd_peer_echo_cmd, "[no] echo-mode", - NO_STR "Configure echo mode\n") -{ - struct bfd_session *bs; - - bs = VTY_GET_CONTEXT(bfd_session); - if (no) { - if (!BFD_CHECK_FLAG(bs->flags, BFD_SESS_FLAG_ECHO)) - return CMD_SUCCESS; - - BFD_UNSET_FLAG(bs->flags, BFD_SESS_FLAG_ECHO); - ptm_bfd_echo_stop(bs); - } else { - if (BFD_CHECK_FLAG(bs->flags, BFD_SESS_FLAG_ECHO)) - return CMD_SUCCESS; - - BFD_SET_FLAG(bs->flags, BFD_SESS_FLAG_ECHO); - /* Apply setting immediately. */ - if (!BFD_CHECK_FLAG(bs->flags, BFD_SESS_FLAG_SHUTDOWN)) - bs_echo_timer_handler(bs); - } - - return CMD_SUCCESS; -} - -DEFPY(bfd_no_peer, bfd_no_peer_cmd, - "no peer <A.B.C.D|X:X::X:X>$peer [{multihop|local-address <A.B.C.D|X:X::X:X>$local|interface IFNAME$ifname|vrf NAME$vrfname}]", - NO_STR - PEER_STR PEER_IPV4_STR PEER_IPV6_STR - MHOP_STR - LOCAL_STR LOCAL_IPV4_STR LOCAL_IPV6_STR - INTERFACE_STR - LOCAL_INTF_STR - VRF_STR VRF_NAME_STR) -{ - int idx; - bool mhop; - struct bfd_peer_cfg bpc; - struct sockaddr_any psa, lsa, *lsap; - char errormsg[128]; - - strtosa(peer_str, &psa); - if (local) { - strtosa(local_str, &lsa); - lsap = &lsa; - } else { - lsap = NULL; - } - - idx = 0; - mhop = argv_find(argv, argc, "multihop", &idx); - - if (bfd_configure_peer(&bpc, mhop, &psa, lsap, ifname, vrfname, - errormsg, sizeof(errormsg)) - != 0) { - vty_out(vty, "%% Invalid peer configuration: %s\n", errormsg); - return CMD_WARNING_CONFIG_FAILED; - } - - if (ptm_bfd_sess_del(&bpc) != 0) { - vty_out(vty, "%% Failed to remove peer.\n"); - return CMD_WARNING_CONFIG_FAILED; - } - - return CMD_SUCCESS; -} - /* * Show commands helper functions @@ -1070,16 +816,10 @@ void bfdd_vty_init(void) /* Install BFD node and commands. */ install_node(&bfd_node, bfdd_write_config); install_default(BFD_NODE); - install_element(BFD_NODE, &bfd_peer_enter_cmd); - install_element(BFD_NODE, &bfd_no_peer_cmd); /* Install BFD peer node. */ install_node(&bfd_peer_node, bfdd_peer_write_config); install_default(BFD_PEER_NODE); - install_element(BFD_PEER_NODE, &bfd_peer_detectmultiplier_cmd); - install_element(BFD_PEER_NODE, &bfd_peer_recvinterval_cmd); - install_element(BFD_PEER_NODE, &bfd_peer_txinterval_cmd); - install_element(BFD_PEER_NODE, &bfd_peer_echointerval_cmd); - install_element(BFD_PEER_NODE, &bfd_peer_shutdown_cmd); - install_element(BFD_PEER_NODE, &bfd_peer_echo_cmd); + + bfdd_cli_init(); } diff --git a/bfdd/subdir.am b/bfdd/subdir.am index e88b982ec..353667349 100644 --- a/bfdd/subdir.am +++ b/bfdd/subdir.am @@ -7,12 +7,15 @@ noinst_LIBRARIES += bfdd/libbfd.a sbin_PROGRAMS += bfdd/bfdd dist_examples_DATA += bfdd/bfdd.conf.sample vtysh_scan += $(top_srcdir)/bfdd/bfdd_vty.c +vtysh_scan += $(top_srcdir)/bfdd/bfdd_cli.c man8 += $(MANBUILD)/bfdd.8 endif bfdd_libbfd_a_SOURCES = \ bfdd/bfd.c \ + bfdd/bfdd_northbound.c \ bfdd/bfdd_vty.c \ + bfdd/bfdd_cli.c \ bfdd/bfd_packet.c \ bfdd/config.c \ bfdd/control.c \ @@ -24,6 +27,9 @@ bfdd_libbfd_a_SOURCES = \ bfdd/bfdd_vty_clippy.c: $(CLIPPY_DEPS) bfdd/bfdd_vty.$(OBJEXT): bfdd/bfdd_vty_clippy.c +bfdd/bfdd_cli_clippy.c: $(CLIPPY_DEPS) +bfdd/bfdd_cli.$(OBJEXT): bfdd/bfdd_cli_clippy.c + noinst_HEADERS += \ bfdd/bfdctl.h \ bfdd/bfd.h \ diff --git a/yang/subdir.am b/yang/subdir.am index c95ec4dbf..4b3baeea9 100644 --- a/yang/subdir.am +++ b/yang/subdir.am @@ -24,6 +24,10 @@ dist_yangmodels_DATA += yang/frr-test-module.yang dist_yangmodels_DATA += yang/frr-interface.yang dist_yangmodels_DATA += yang/frr-route-types.yang +if BFDD +dist_yangmodels_DATA += yang/frr-bfdd.yang +endif + if RIPD dist_yangmodels_DATA += yang/frr-ripd.yang endif |