summaryrefslogtreecommitdiff
path: root/bfdd/bfd.c
AgeCommit message (Collapse)Author
2025-04-16bfdd, bgpd: clean up clang warningsMark Stapp
Clean up some clang compiler warnings. Signed-off-by: Mark Stapp <mjs@cisco.com>
2025-04-15Merge pull request #18592 from zmw12306/bfd_set_shutdownRuss White
bfdd: Set bfd.LocalDiag when transitioning to AdminDown
2025-04-06bfdd: Set bfd.LocalDiag when transitioning to AdminDownzmw12306
RFC 5880 6.8.16, need to set LocalDiag when transitioning to AdminDown state. Signed-off-by: zmw12306 <zmw12306@gmail.com>
2025-04-05bfdd: Fix demultiplexing to rely solely on Your Discriminator as per RFC 5880.zmw12306
According to RFC 5880 Section 6.3, once the remote peer reflects back the local discriminator, the receiver MUST demultiplex subsequent BFD packets based solely on the Your Discriminator field. The source IP or interface MUST NOT be used in demultiplexing once the session is established. Signed-off-by: zmw12306 <zmw12306@gmail.com>
2025-03-03bfdd: Add BFD "log-session-changes" feature.Acee Lindem
Add the BFD "log-session-changes" via the YANG and northbound API. Also add the configured value to show and operational state. Signed-off-by: Acee Lindem <acee@lindem.com>
2025-02-12Merge pull request #18125 from donaldsharp/bfd_fd_zeroMark Stapp
bfdd: 0 is a valid fd.
2025-02-12bfdd: 0 is a valid fd.Donald Sharp
It's unlikely that this would ever get a 0 fd to use but let's just let the code assume it is ok. Signed-off-by: Donald Sharp <sharpd@nvidia.com>
2025-02-05bfdd: Use pass by reference for bfd_key_deleteDonald Sharp
Coverity is pointing out that bfd_key_delete is passing by value instead of reference for a very large structure. Double plus not good. Signed-off-by: Donald Sharp <sharpd@nvidia.com>
2025-02-05bfdd: Use pass by reference instead of pass by value for a structDonald Sharp
The function bfd_key_lookup is currently sending by value for a now very large structure. Let's convert this over to pass by reference. This is noticed by coverity. Signed-off-by: Donald Sharp <sharpd@nvidia.com>
2025-01-23bfdd: enable sbfd sessionwumu.zsl
1) create socket to send sbfd packets 2) integrate sbfd logic with existing BFD Signed-off-by: wumu.zsl <wumu.zsl@alibaba-inc.com>
2025-01-23bfdd: add sbfd state machine functionswumu.zsl
Signed-off-by: wumu.zsl <wumu.zsl@alibaba-inc.com>
2025-01-23bfdd: create a hash table for local sbfd reflector infowumu.zsl
Signed-off-by: wumu.zsl <wumu.zsl@alibaba-inc.com>
2025-01-23bfdd: support sbfd session create and destroywumu.zsl
refactor bfd_session_create and bfd_session_destroy to support SBFD Signed-off-by: wumu.zsl <wumu.zsl@alibaba-inc.com>
2025-01-22bfdd: add bfdname in bfd_keywumu.zsl
sbfd will use bfdname for key hash, We introduced a bfd-name for every sbfd session, normal BFD sessions can leave it as NULL. A unique bfd-name can be used to identify a sbfd session quickly. This is quite useful in our Srv6 deployment for path protection case. For example, if use the sbfd session to protect the SRv6 path A-B-D, we would assign the name 'path-a-b-d' or 'a-b-d' to the session. Signed-off-by: wumu.zsl <wumu.zsl@alibaba-inc.com>
2024-11-12bfdd: disable echo socket when not using itRafael Zalamena
Lets avoid a performance penalty in forwarding when not using the BFD echo feature. The echo socket uses raw packet capturing along with a BPF filter which causes performance issues. While here change code to use `-1` for closed sockets instead of valid FD number `0`. Signed-off-by: Rafael Zalamena <rzalamena@opensourcerouting.org>
2024-07-25bfdd: remove control socket obsolete codeRafael Zalamena
Let's remove the obsolete BFD control socket. If the functionality is needed then YANG/northbound notifications / getting should be used instead. Signed-off-by: Rafael Zalamena <rzalamena@opensourcerouting.org>
2024-07-16bfdd: changes for code maintainabilitysri-mohan1
these changes are for improving the code maintainability and readability Signed-off-by: sri-mohan1 <sri.mohan@samsung.com>
2023-03-24*: Convert THREAD_XXX macros to EVENT_XXX macrosDonald Sharp
Signed-off-by: Donald Sharp <sharpd@nvidia.com>
2023-03-24*: Convert thread_add_XXX functions to event_add_XXXDonald Sharp
Signed-off-by: Donald Sharp <sharpd@nvidia.com>
2023-03-24*: Rename `struct thread` to `struct event`Donald Sharp
Effectively a massive search and replace of `struct thread` to `struct event`. Using the term `thread` gives people the thought that this event system is a pthread when it is not Signed-off-by: Donald Sharp <sharpd@nvidia.com>
2023-02-09*: auto-convert to SPDX License IDsDavid Lamparter
Done with a combination of regex'ing and banging my head against a wall. Signed-off-by: David Lamparter <equinox@opensourcerouting.org>
2022-09-05bfdd: changes for code maintainabilitysri-mohan1
these changes are for improving the code maintainability Signed-off-by: sri-mohan1 <sri.mohan@samsung.com>
2022-08-09Merge pull request #11668 from rampxxxx/bfd_rtt_in_echo_pktRafael Zalamena
BFDD: Add RTT to BFD IPV4 Echo packet processing
2022-08-02BFDD: Add RTT to BFD IPV4 Echo packet processinglynnemorrison
Add a send time into the BFD Echo packet. When the BFD Echo packet is received back store time it took in usec. When user issues a show bfd peer(s) command calculate and display minimum, average, and max time it took for the BFD Echo packet to be looped back. Signed-off-by: Lynne Morrison <lynne.morrison@ibm.com>
2022-07-19bfdd: allow l3vrf bfd sessions without udp leakingPhilippe Guibert
Until now, when in vrf-lite mode, the BFD implementation creates a single UDP socket and relies on the following sysctl value to 1: echo 1 > /proc/sys/net/ipv4/udp_l3mdev_accept With this setting, the incoming BFD packets from a given vrf, would leak to the default vrf, and would match the UDP socket. The drawback of this solution is that udp packets received on a given vrf may leak to an other vrf. This may be a security concern. The commit addresses this issue by avoiding this leak mechanism. An UDP socket is created for each vrf, and each socket uses new setsockopt option: SO_REUSEADDR + SO_REUSEPORT. With this option, the incoming UDP packets are distributed on the available sockets. The impact of those options with l3mdev devices is unknown. It has been observed that this option is not needed, until the default vrf sockets are created. To ensure the BFD packets are correctly routed to the appropriate socket, a BPF filter has been put in place and attached to the sockets : SO_ATTACH_REUSEPORT_CBPF. This option adds a criterium to force the packet to choose a given socket. If initial criteria from the default distribution algorithm were not good, at least two sockets would be available, and the CBPF would force the selection to the same socket. This would come to the situation where an incoming packet would be processed on a different vrf. The bpf code is the following one: struct sock_filter code[] = { { BPF_RET | BPF_K, 0, 0, 0 }, }; struct sock_fprog p = { .len = sizeof(code)/sizeof(struct sock_filter), .filter = code, }; if (setsockopt(sd, SOL_SOCKET, SO_ATTACH_REUSEPORT_CBPF, &p, sizeof(p))) { zlog_warn("unable to set SO_ATTACH_REUSEPORT_CBPF on socket: %s", strerror(errno)); return -1; } Some tests have been done with by creating vrf contexts, and by using the below vtysh configuration: ip route 2.2.2.2/32 10.126.0.2 vrf vrf2 ip route 2.2.2.2/32 10.126.0.2 ! interface ntfp2 ip address 10.126.0.1/24 ! interface ntfp3 vrf vrf4 ip address 10.126.0.1/24 ! interface ntfp2 vrf vrf1 ip address 10.126.0.1/24 ! interface ntfp2.100 vrf vrf2 ip address 10.126.0.1/24 ! interface ntfp2.200 vrf vrf3 ip address 10.126.0.1/24 ! line vty ! bfd peer 10.126.0.2 vrf vrf2 ! peer 10.126.0.2 vrf vrf3 ! peer 10.126.0.2 ! peer 10.126.0.2 vrf vrf4 ! peer 2.2.2.2 multihop local-address 1.1.1.1 ! peer 2.2.2.2 multihop local-address 1.1.1.1 vrf vrf2 transmit-interval 1500 receive-interval 1500 ! The results showed no issue related to packets received by the wrong vrf. Even changing the udp_l3mdev_accept flag to 1 did not change the test results. Signed-off-by: Philippe Guibert <philippe.guibert@6wind.com>
2022-06-27bfdd: add IPv4 BFD Echo support that matches RFClynnemorrison
Modify the existing BFD Echo code to send an Echo message that will be looped in the peers forwarding plane. The existing Echo code only works with other FRR implementations because the Echo packet must go up to BFD to be turned around and forwarded back to the local router. The new BFD Echo code sets the src/dst IP of the packet to be the local router's IP and sets the dest MAC to be the peers MAC address. The peer receives the packet and because it is not it's IP address it forwards it back to the local router. Signed-off-by: Lynne Morrison <lynne.morrison@ibm.com>
2022-04-19*: Fix spelling of overridenDonald Sharp
Signed-off-by: Donald Sharp <sharpd@nvidia.com>
2022-02-23*: Change thread->func to return void instead of intDonald Sharp
The int return value is never used. Modify the code base to just return a void instead. Signed-off-by: Donald Sharp <sharpd@nvidia.com>
2022-02-22bfdd: Fix overflow possibility with time statementsDonald Sharp
If time ( a uint64_t ) is large enough doing division and subtraction can still lead to situations where the resulting number is greater than a uint32_t. Just use uint32_t as an intermediate storage spot. This is unlikely to every occur in a time frame I could possibly care about but makes Coverity happy. Signed-off-by: Donald Sharp <sharpd@nvidia.com>
2022-02-02bfdd: fix broken FSM in passive modeanlan_cs
Problem: One is with active mode, the other is with passive mode. Sometimes the one with active mode is in `Down` stauts, but the other one with passive mode is unluckily stuck in `Init` status: It doesn't answer its peer with any packets, even receiving continuous `Down` packets. Root Cause: bfdd with passive mode answers its peer only *one* packet in `Down` status, then it enters into `Init` status and ignores subsequent `Down` packets. Unluckily that *one* answered packet is lost, at that moment its peer with active mode can only have to send `Down` packets. Fix: 1) With passive mode, bfdd should start xmittimer after received `Down` packet. Refer to RFC5880: "A system taking the Passive role MUST NOT begin sending BFD packets for a particular session until it has received a BFD packet for that session, and thus has learned the remote system's discriminator value." 2) Currently this added xmittimer for passive mode can be safely removed except receiving `AdminDown` packet: - `bfd_session_enable/bfd_set_passive_mode` doesn't start xmittimer - `ptm_bfd_sess_dn/bfd_set_shutdown` can remove xmittimer Per RFC5880, receiving `AdminDown` packet should be also regarded as `Down`, so just call `ptm_bfd_sess_dn`, which will safely remove the added xmittimer for passive mode. In summary, call `ptm_bfd_sess_dn` for two status changes on receiving `AdminDown`: `Init`->`Down` and `Up`->`Down`. Signed-off-by: anlan_cs <vic.lan@pica8.com>
2021-12-21*: rework renaming the default VRFIgor Ryzhov
Currently, it is possible to rename the default VRF either by passing `-o` option to zebra or by creating a file in `/var/run/netns` and binding it to `/proc/self/ns/net`. In both cases, only zebra knows about the rename and other daemons learn about it only after they connect to zebra. This is a problem, because daemons may read their config before they connect to zebra. To handle this rename after the config is read, we have some special code in every single daemon, which is not very bad but not desirable in my opinion. But things are getting worse when we need to handle this in northbound layer as we have to manually rewrite the config nodes. This approach is already hacky, but still works as every daemon handles its own NB structures. But it is completely incompatible with the central management daemon architecture we are aiming for, as mgmtd doesn't even have a connection with zebra to learn from it. And it shouldn't have it, because operational state changes should never affect configuration. To solve the problem and simplify the code, I propose to expand the `-o` option to all daemons. By using the startup option, we let daemons know about the rename before they read their configs so we don't need any special code to deal with it. There's an easy way to pass the option to all daemons by using `frr_global_options` variable. Unfortunately, the second way of renaming by creating a file in `/var/run/netns` is incompatible with the new mgmtd architecture. Theoretically, we could force daemons to read their configs only after they connect to zebra, but it means adding even more code to handle a very specific use-case. And anyway this won't work for mgmtd as it doesn't have a connection with zebra. So I had to remove this option. Signed-off-by: Igor Ryzhov <iryzhov@nfware.com>
2021-12-07Merge pull request #10186 from idryzhov/bfd-receive-timer-cbMark Stapp
bfdd: remove unnecessary receive timer restart
2021-12-06bfdd: remove unnecessary receive timer restartIgor Ryzhov
When the detection time expires, we put the session down and restart the timer. As the comment in the code says, it's needed to zero the remote discriminator after the second expiration. But the RFC clearly says that this must be done on the first expiration: bfd.RemoteDiscr The remote discriminator for this BFD session. This is the discriminator chosen by the remote system, and is totally opaque to the local system. This MUST be initialized to zero. If a period of a Detection Time passes without the receipt of a valid, authenticated BFD packet from the remote system, this variable MUST be set to zero. And we actually already do it in `ptm_bfd_sess_dn`, so there's no need to reset the timer and wait for it twice. Signed-off-by: Igor Ryzhov <iryzhov@nfware.com>
2021-12-03bfdd: fix detection timeout updateIgor Ryzhov
Per RFC 5880 section 6.8.12, the use of a Poll Sequence is not necessary when the Detect Multiplier is changed. Currently, we update the Detection Timeout only when a Poll Sequence is terminated, therefore we ignore the Detect Multiplier change if it's not accompanied with RX/TX timer change. To fix the problem, we should update the Detection Timeout on every received packet. Signed-off-by: Igor Ryzhov <iryzhov@nfware.com>
2021-11-05Merge pull request #9833 from idryzhov/cleanup-if-by-index-all-vrfRuss White
*: fix usage of if_lookup_by_index_all_vrf
2021-10-15bfdd: cleanup bfd_session_enableIgor Ryzhov
Well, there are some weird and duplicated checks there... All we need is two simple checks: - VRF existence. We must have it to enable the session. - Interface existence. If it's configured for the session, we have to bind the session to the interface. This commit implements these checks and removes unnecessary duplication. Signed-off-by: Igor Ryzhov <iryzhov@nfware.com>
2021-10-14bfdd: cleanup vrf handling in packet receiveIgor Ryzhov
We get the pointer to the interface on which the packet was received right at the beginning of bfd_recv_cb. So let's use this pointer and don't perform additional interface lookups. Also explain in more detail how we process VRF id with different backends. Signed-off-by: Igor Ryzhov <iryzhov@nfware.com>
2021-05-13lib: adapt to version 2 of libyangChristian Hopps
Compile with v2.0.0 tag of `libyang2` branch of: https://github.com/CESNET/libyang staticd init load time of 10k routes now 6s vs ly1 time of 150s Signed-off-by: Christian Hopps <chopps@labn.net>
2021-04-01bfdd: remove profiles when removing bfd nodeIgor Ryzhov
Fixes #8379. Signed-off-by: Igor Ryzhov <iryzhov@nfware.com>
2021-03-22Merge pull request #8121 from opensourcerouting/macro-cleanupDonatas Abraitis
*: require ISO C11 + semicolons after file-scope macros
2021-03-17Merge pull request #8225 from idryzhov/bfd-echo-modeRafael Zalamena
bfdd: fix echo receive timer and disable echo mode
2021-03-17*: require semicolon after DEFINE_MTYPE & coDavid Lamparter
Back when I put this together in 2015, ISO C11 was still reasonably new and we couldn't require it just yet. Without ISO C11, there is no "good" way (only bad hacks) to require a semicolon after a macro that ends with a function definition. And if you added one anyway, you'd get "spurious semicolon" warnings on some compilers... With C11, `_Static_assert()` at the end of a macro will make it so that the semicolon is properly required, consumed, and not warned about. Consistently requiring semicolons after "file-level" macros matches Linux kernel coding style and helps some editors against mis-syntax'ing these macros. Signed-off-by: David Lamparter <equinox@diac24.net>
2021-03-16bfdd: separate echo rx/tx timersIgor Ryzhov
Currently there is a single interval for both RX and TX echo functions. This commit introduces separate RX and TX timers for echo packets. The main advantage is to be able to set the receive interval to zero when we don't want to receive echo packets from the remote system. Signed-off-by: Igor Ryzhov <iryzhov@nfware.com>
2021-03-16bfdd: fix starting echo receive timerIgor Ryzhov
Currently this timer is only started when we receive the first echo packet. If we never receive the packet, the timer is never started and the user falsely assumes that echo function is working. Signed-off-by: Igor Ryzhov <iryzhov@nfware.com>
2021-03-15bfdd: make sessions administratively up by defaultIgor Ryzhov
Current behavior is inconsistent. When the session is created by another daemon, it is up by default. When we later configure peer in bfdd, the session is still up, but the NB layer thinks that it is down. More than that, even when the session is created in bfdd using peer command, it is created in DOWN state, not ADM_DOWN. And it actually starts sending and receiving packets. The sessions is marked with SHUTDOWN flag only when we try to reconfigure some parameter. This behavior is also very unexpected. Fixes #7780. Signed-off-by: Igor Ryzhov <iryzhov@nfware.com>
2021-03-09bfdd: fix detect timeoutIgor Ryzhov
RFC 5880 Section 6.8.4: In Asynchronous mode, the Detection Time calculated in the local system is equal to the value of Detect Mult received from the remote system, multiplied by the agreed transmit interval of the remote system (the greater of bfd.RequiredMinRxInterval and the last received Desired Min TX Interval). Signed-off-by: Igor Ryzhov <iryzhov@nfware.com>
2021-02-04bfdd: fix session lookupIgor Ryzhov
BFD key has optional fields "local" and "ifname" which can be empty when the BFD session is created. In this case, the hash key will be calculated with these fields filled with zeroes. Later, when we're looking for the BFD session using the key with fields "local" and "ifname" populated with actual values, the hash key will be different. To work around this issue, we're doing multiple hash lookups, first with full key, then with fields "local" and "ifname" filled with zeroes. But there may be another case when the initial key has the actual values for "local" and "ifname", but the key we're using for lookup has empty values. This case is covered for IPv4 by using additional hash walk with bfd_key_lookup_ignore_partial_walker function but is not covered for IPv6. Instead of introducing more hacks and workarounds, the following solution is proposed: - the hash key is always calculated in bfd_key_hash_do using only required fields - the hash data is compared in bfd_key_hash_cmp, taking into account the fact that fields "local" and "ifname" may be empty Using this solution, it's enough to make only one hash lookup. Signed-off-by: Igor Ryzhov <iryzhov@nfware.com>
2021-01-09bfdd: improve some debug messages related to zebra notificationsPhilippe Guibert
when receiving interface and address notifications, one may be puzzled by the information since for example, the presence of an interface is not enough to use it in a bfd session, simply because the interface is in the wrong vrf. add VRF information on those traces. Signed-off-by: Philippe Guibert <philippe.guibert@6wind.com>
2021-01-09bfdd: enable bfd session if vrf interface availablePhilippe Guibert
The vrf interface notification and interface notifications are separated on zapi interface between the system (zebra daemon) and other daemons (bfd for instance). In the case of bfd, the initial code was waiting for vrf notification to create the socket. Actually, in vrf-lite world, we need to wait the vrf interface to be present, in order to create the socket and bind to the vrf interface (this is the usual way to work with vrf-lite). On bfd, the changes consist in delaying the socket creation first, then when interface is created, check the interface name presence instead of checking the interface configuration. Signed-off-by: Philippe Guibert <philippe.guibert@6wind.com>
2020-12-04bfd: fix session lookupIgor Ryzhov
local-address is optional for both IPv4 and IPv6. Signed-off-by: Igor Ryzhov <iryzhov@nfware.com>