Commit graph

424 commits

Author SHA1 Message Date
lynnemorrison d63ccc9248 bfdd: add additional parameters to json command
Add parameters to the "show bfd peers json" command to
display interface and type of BFD session.

Signed-off-by: Lynne Morrison <lynne.morrison@ibm.com>
2023-07-28 11:45:23 -04:00
Igor Ryzhov 5b28833d38
Merge pull request #13675 from zmw12306/bfd_version_check
bfd:fix version bits check
2023-06-11 14:16:50 +03:00
Donatas Abraitis f158bb770d
Merge pull request #13364 from zmw12306/bfd_auth
bfd: fix missing Authentication in control pkt
2023-06-08 20:12:29 +03:00
zmw12306 3f658e8b1c bfdd: fix version bits check.
The version of bfd pkt is represented by 3 bits in B[0].
Signed-off-by: zmw12306 <zmw12306@gmail.com>
2023-06-03 15:08:34 -04:00
Igor Ryzhov f7884aedf7 bfdd: remove redundant nb destroy callbacks
Fixes warning logs:
```
2023/05/29 20:11:50 BFD: [ZKB8W-3S2Q4][EC 100663330] unneeded 'destroy' callback for '/frr-bfdd:bfdd/bfd/profile/minimum-ttl'
2023/05/29 20:11:50 BFD: [ZKB8W-3S2Q4][EC 100663330] unneeded 'destroy' callback for '/frr-bfdd:bfdd/bfd/sessions/multi-hop/minimum-ttl'
```

Signed-off-by: Igor Ryzhov <iryzhov@nfware.com>
2023-05-31 15:28:08 +03:00
Russ White 7b7da41def
Merge pull request #13556 from donaldsharp/token_to_desc
memory desciprtion shortening
2023-05-23 08:21:51 -04:00
Donald Sharp 4257390892 bfdd: Use shorter memory names so that they fit in vty output
Signed-off-by: Donald Sharp <sharpd@nvidia.com>
2023-05-19 21:31:35 -04:00
anlan_cs b17c179664 bfdd: Fix malformed session with vrf
With this configuration:

```
bfd
 peer 33:33::66 local-address 33:33::88 vrf vrf8 interface enp1s0
 exit
 !
exit
```

The bfd session can't be established with error:

```
bfdd[18663]: [YA0Q5-C0BPV] control-packet: wrong vrfid. [mhop:no peer:33:33::66 local:33:33::88 port:2 vrf:61]
```

The vrf check should use the carefully adjusted `vrfid`, which is
based on globally/reliable interface.  We can't believe the
`bvrf->vrf->vrf_id` because the `/proc/sys/net/ipv4/udp_l3mdev_accept`
maybe is set "1" in VRF-lite backend even with security drawback.

Just correct the vrf check.

Signed-off-by: anlan_cs <vic.lan@pica8.com>
2023-05-11 10:22:40 +08:00
zmw12306 98707b04d4 bfd: fix missing Authentication in control pkt
According RFC 5880, add a simpilfed version handling authentication
Signed-off-by: zmw12306 <zmw12306@gmail.com>
2023-04-25 13:48:18 -04:00
Donald Sharp 24a58196dd *: Convert event.h to frrevent.h
We should probably prevent any type of namespace collision
with something else.

Signed-off-by: Donald Sharp <sharpd@nvidia.com>
2023-03-24 08:32:17 -04:00
Donald Sharp cd9d053741 *: Convert struct event_master to struct event_loop
Let's find a better name for it.

Signed-off-by: Donald Sharp <sharpd@nvidia.com>
2023-03-24 08:32:17 -04:00
Donald Sharp e16d030c65 *: Convert THREAD_XXX macros to EVENT_XXX macros
Signed-off-by: Donald Sharp <sharpd@nvidia.com>
2023-03-24 08:32:17 -04:00
Donald Sharp 2453d15dbf *: Convert struct thread_master to struct event_master and it's ilk
Convert the `struct thread_master` to `struct event_master`
across the code base.

Signed-off-by: Donald Sharp <sharpd@nvidia.com>
2023-03-24 08:32:17 -04:00
Donald Sharp 332beb64b8 *: Convert thread_cancelXXX to event_cancelXXX
Modify the code base so that thread_cancel becomes event_cancel

Signed-off-by: Donald Sharp <sharpd@nvidia.com>
2023-03-24 08:32:17 -04:00
Donald Sharp 907a2395f4 *: Convert thread_add_XXX functions to event_add_XXX
Signed-off-by: Donald Sharp <sharpd@nvidia.com>
2023-03-24 08:32:17 -04:00
Donald Sharp e6685141aa *: Rename struct thread to struct event
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-03-24 08:32:17 -04:00
Donald Sharp cb37cb336a *: Rename thread.[ch] to event.[ch]
This is a first in a series of commits, whose goal is to rename
the thread system in FRR to an event system.  There is a continual
problem where people are confusing `struct thread` with a true
pthread.  In reality, our entire thread.c is an event system.

In this commit rename the thread.[ch] files to event.[ch].

Signed-off-by: Donald Sharp <sharpd@nvidia.com>
2023-03-24 08:32:16 -04:00
anlan_cs c9aac2c38a bfdd: Remove useless check for ECHO packet
The check with `ip->daddr == ip->saddr` in `bfd_recv_ipv4_fp()` is
useless, instead of it the ECHO packets should simply exit with
TTL checking failure regardless of this condition check.

Just remove the check.

Signed-off-by: anlan_cs <vic.lan@pica8.com>
2023-03-03 18:25:12 +08:00
David Lamparter acddc0ed3c *: auto-convert to SPDX License IDs
Done with a combination of regex'ing and banging my head against a wall.

Signed-off-by: David Lamparter <equinox@opensourcerouting.org>
2023-02-09 14:09:11 +01:00
David Lamparter 47a3a82770 *: manual SPDX License ID conversions
The files converted in this commit either had some random misspelling or
formatting weirdness that made them escape automated replacement, or
have a particularly "weird" licensing setup (e.g. dual-licensed.)

This also marks a bunch of "public domain" files as SPDX License "NONE".

Signed-off-by: David Lamparter <equinox@opensourcerouting.org>
2023-02-09 14:09:07 +01:00
David Lamparter d131cca998 bfdd: fix size_t format string
Signed-off-by: David Lamparter <equinox@opensourcerouting.org>
2023-01-27 12:01:20 +01:00
David Lamparter 0f9de11a11 *: apply proper format string attributes
So that we get warnings about broken format strings.

Signed-off-by: David Lamparter <equinox@opensourcerouting.org>
2023-01-27 12:01:17 +01:00
Mark Stapp f067ab5d9f bfdd: validate incoming control message length
Apply upper bound on incoming control messages, drop invalid
messages.

Signed-off-by: Mark Stapp <mjs@labn.net>
2023-01-10 08:03:09 -05:00
Rafael Zalamena f68114c1c3 bfdd: fix IPv4 socket source selection
The imported BFD code had some logic to ignore the source address when
using single hop IPv4. The BFD peer socket function should allow the
source to be selected so we can:
1. Select the source address in the outgoing packets
2. Only receive packets from that specific source

Signed-off-by: Rafael Zalamena <rzalamena@opensourcerouting.org>
2022-11-24 11:16:18 -03:00
David Lamparter 89cb86aeb0 build, vtysh: extract vtysh commands from .xref
Rather than running selected source files through the preprocessor and a
bunch of perl regex'ing to get the list of all DEFUNs, use the data
collected in frr.xref.

This not only eliminates issues we've been having with preprocessor
failures due to nonexistent header files, but is also much faster.
Where extract.pl would take 5s, this now finishes in 0.2s.  And since
this is a non-parallelizable build step towards the end of the build
(dependent on a lot of other things being done already), the speedup is
actually noticeable.

Also files containing CLI no longer need to be listed in `vtysh_scan`
since the .xref data covers everything.  `#ifndef VTYSH_EXTRACT_PL`
checks are equally obsolete.

Signed-off-by: David Lamparter <equinox@opensourcerouting.org>
2022-10-26 17:12:34 +01:00
Donald Sharp cf00164b69 *: Create and use infrastructure to show debugs in lib
There are lib debugs being set but never show up in
`show debug` commands because there was no way to show
that they were being used.  Add a bit of infrastructure
to allow this and then use it for `debug route-map`

Signed-off-by: Donald Sharp <sharpd@nvidia.com>
2022-10-07 12:39:05 -04:00
sri-mohan1 9e5fc01f00 bfdd: changes for code maintainability
these changes are for improving the code maintainability

Signed-off-by: sri-mohan1 <sri.mohan@samsung.com>
2022-09-05 14:12:25 +05:30
Rafael Zalamena ac2f410c37
Merge pull request #11668 from rampxxxx/bfd_rtt_in_echo_pkt
BFDD: Add RTT to BFD IPV4 Echo packet processing
2022-08-09 15:20:24 +00:00
Donald Sharp 97739c280f bfdd: Some interfaces don't have mac addresses
When an interface does not have a mac address, don't
try to retrieve the mac address ( for it to just fail ).

Example interface:
sharpd@eva [2]> ip link show tun100
21: tun100@NONE: <POINTOPOINT,NOARP,UP,LOWER_UP> mtu 1480 qdisc noqueue state UNKNOWN mode DEFAULT group default qlen 1000
    link/ipip 192.168.119.224 peer 192.168.119.120

Let's just notice that there is a NOARP flag and abort the call.

Fixes: #11733
Signed-off-by: Donald Sharp <sharpd@nvidia.com>
2022-08-06 08:41:47 -04:00
lynnemorrison 618a06fe11 BFDD: Add RTT to BFD IPV4 Echo packet processing
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-08-02 10:09:01 -04:00
Rafael Zalamena b8443f7ad3
Merge pull request #11565 from pguibert6WIND/bfd_vrf_lite_support
bfdd: allow l3vrf bfd sessions without udp leaking
2022-07-22 14:12:17 +00:00
Philippe Guibert edc3f63167 bfdd: allow l3vrf bfd sessions without udp leaking
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-07-19 21:35:23 +02:00
lynnemorrison 5609e9d791 BFDD: Cleanup warning
Signed-off-by: Lynne Morrison <lynne.morrison@ibm.com>
2022-07-19 15:23:50 -04:00
Rafael Zalamena f14233edbd bfdd: fix coverity memory overrun
Use the destination for the operator `sizeof()` instead of the source
which could (and is) be bigger than destination.

We are not truncating any data here it just happens that the zebra
interface data structure hardware address can be bigger due to different
types of interface.

Signed-off-by: Rafael Zalamena <rzalamena@opensourcerouting.org>
2022-07-06 07:52:17 -03:00
Rafael Zalamena 500fe387a0 bfdd: fix coverity scan resource leak
Close the descriptor if something fails and we don't return it.

Signed-off-by: Rafael Zalamena <rzalamena@opensourcerouting.org>
2022-07-06 07:49:56 -03:00
lynnemorrison 57485b0b4f bfdd: add IPv4 BFD Echo support that matches RFC
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-06-27 16:21:08 -04:00
Donald Sharp e51c0f771d bfdd: Prevent coverity from thinking values are uninited
Coverity is claiming that bfdd is able got have bglobal.bg_use_dplane
can be true, while dplane_addr can be uninitialized.  Not really
possible since global variables are initialized to all 0's.  In
any event.  Force it to think it can't go there.

Signed-off-by: Donald Sharp <sharpd@nvidia.com>
2022-05-12 16:58:29 -04:00
anlan_cs 7ffd0b80aa bfdd: fix override between sessions
After two single-hop sessions (*no local address are configured*) on two
interfaces are UP, remove one address of one interface, both of them
(actually, quite independent sessions) come to be DOWN, not just one.

Consider two boxes: A with `a1` and `a2` adddress on two interfaces,
and B with `b1` and `b2`.
Two sessions are set up and ok: `s1` with <a1,b1> and `s2` with <a2,b2>.
After `a1` of A is removed, there is an unhappy coincidence:
1) On A: `s1` changes local address, and sends <a2,b1> packets with help
of route.
2) On B: wrongly regarded <a2,b1> packets with non-zero remote descriminator
as part of `s2`, and are dropped for mismatched remote remote descriminator.
3) On A: `s1` sends <a2,b1> packets with zero remote descriminator to
initialize this session.
4) On B: wrongly regarded <a2,b1> packets with zero remote descriminator as
part of `s2`. Then `s2` will vibrate.

So the good sessions are overridden.

In this case, the <a2,b1> packets with zero remote descriminator won't take
effect until the current good sessions become bad.

Since single-hop sessions are allowed to be set without bound inteface in
current code, this commit adds one check in `bfd_recv_cb()` to avoid wrong
override.

Signed-off-by: anlan_cs <vic.lan@pica8.com>
2022-05-06 01:28:21 -04:00
Donald Sharp 59ba003346
Merge pull request #11137 from opensourcerouting/if-name-len-fixes
*: standardize interface name maximum length
2022-05-04 07:44:26 -04:00
Rafael Zalamena 3682bd90f3 *: use FRR interface name definition everywhere
Don't rely on the OS interface name length definition and use the FRR
definition instead.

Signed-off-by: Rafael Zalamena <rzalamena@opensourcerouting.org>
2022-05-02 13:00:12 -03:00
ewlumpkin e9cea444a4 bfdd: remove "local_address" of bfd session
The "local_address" of bfd is only used in `show bfd peers brief`
for single hop sessions which are configured without "local address".
Since it is set by destination address of received packet, not
completely correct, so remove it.

Signed-off-by: ewlumpkin <ewlumpkin@gmail.com>
Signed-off-by: anlan_cs <vic.lan@pica8.com>
2022-05-02 10:40:53 -04:00
anlan_cs 6ca4263454 bfdd: fix broken FSM in active mode
With the simple BFD configuration -
(active mode, single hop, without other parameters)
```
!
bfd
 peer 11.11.11.11
 exit
!
```
The interface with 11.11.11.0/24 is a *virtual* interface,
which can be deleted.

After BFD FSM is created and session is ok, do these things:
1) delete this interface
2) create this interface
3) set same ip address in this interface

Now, everything seems completely restored because all configuration
is same. But bad thing happens, BFD session hang on "down" status -
```
root# show bfd peer 11.11.11.11
BFD Peer:
peer 11.11.11.11 vrf default
ID: 638815827
Remote ID: 0
Active mode
Status: down
Downtime: 3 second(s)
Diagnostics: path down <- caused by destroyed interface
Remote diagnostics: ok
```

With the interface creating, `bfdd_sessions_enable_interface()`
wrongly compares added interface with the created, even key of
this `bfd_session` isn't binded with any interface. So this
`bfd_session` will hang on "down" status for ever.

So skip the compare in this case (no interface in key) to wake up
this `bfd_session`.

Signed-off-by: anlan_cs <vic.lan@pica8.com>
2022-04-24 05:23:40 -04:00
Donald Sharp 2b669d3a21 *: Fix spelling of overriden
Signed-off-by: Donald Sharp <sharpd@nvidia.com>
2022-04-19 08:27:02 -04:00
Donald Sharp cc9f21da22 *: Change thread->func to return void instead of int
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-23 19:56:04 -05:00
Donald Sharp 46da676a62 bfdd: Fix overflow possibility with time statements
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-22 11:11:31 -05:00
Donald Sharp b6d2bb07d8 bfdd: Use AF_UNSPEC instead of comparing to 0
Signed-off-by: Donald Sharp <sharpd@nvidia.com>
2022-02-07 13:25:21 -05:00
Igor Ryzhov 249932f969
Merge pull request #10388 from anlancs/bfd-fsm-passive
bfdd: fix broken FSM in passive mode
2022-02-02 13:06:11 +03:00
anlan_cs fd2109e575 bfdd: fix broken FSM in passive mode
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>
2022-02-02 13:03:09 +08:00
anlan_cs ebf8b885de bfdd,yang: optimize nb with YANG
A few optimizations for bfd NB:
    - Remove unuseful checks for parameters with the same values
    - Replace checking values of bfd parameters with YANG's "range"
    - Append "required-echo-receive-interval" with 0 for it can be disabled

Signed-off-by: anlan_cs <vic.lan@pica8.com>
2022-01-25 04:00:49 -05:00
anlan_cs 09e949a64f bfdd: correct one word of comment
Signed-off-by: anlan_cs <vic.lan@pica8.com>
2022-01-23 20:25:25 -05:00
Santosh P K f553a76ba2
Merge pull request #10363 from anlancs/bfd-move-counter
bfdd: fix the possibly wrong counter of control packets
2022-01-19 11:04:28 +05:30
anlan_cs 95fd223cc3 bfdd: fix the possibly wrong counter of control packets
Since control packets may be dropped by ttl check, the counter
operation should be put after all check including ttl check.

Signed-off-by: anlan_cs <vic.lan@pica8.com>
2022-01-18 05:19:54 -05:00
Rafael Zalamena 4e4c027803
Merge pull request #10183 from idryzhov/rework-vrf-rename
*: rework renaming the default VRF
2022-01-17 08:45:12 -03:00
Donald Sharp 2d73a32668 bfdd: Clean up some white space snafu's
Found some extra spaces during code inspection.  Let's
get them cleaned up.

Signed-off-by: Donald Sharp <sharpd@nvidia.com>
2022-01-08 07:11:07 -05:00
Igor Ryzhov ac2cb9bf94 *: rework renaming the default VRF
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-21 22:09:29 +03:00
Mark Stapp 8acb2480a7
Merge pull request #10186 from idryzhov/bfd-receive-timer-cb
bfdd: remove unnecessary receive timer restart
2021-12-07 12:21:40 -05:00
Russ White 46565af731
Merge pull request #10120 from idryzhov/bfd-detect-to
bfdd: fix detection timeout update
2021-12-07 06:38:15 -05:00
Igor Ryzhov a0f9b0c7c8 bfdd: remove unnecessary receive timer restart
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-06 19:48:25 +03:00
Igor Ryzhov 074f76812b bfdd: fix detection timeout update
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-12-03 18:30:24 +03:00
Donatas Abraitis 4e37fcb61e bfdd: Convert vty_out to vty_json for JSON
Signed-off-by: Donatas Abraitis <donatas.abraitis@gmail.com>
2021-11-25 17:51:02 +02:00
Igor Ryzhov 096f7609f9 *: cleanup ifp->vrf_id
Since f60a1188 we store a pointer to the VRF in the interface structure.
There's no need anymore to store a separate vrf_id field.

Signed-off-by: Igor Ryzhov <iryzhov@nfware.com>
2021-11-22 20:47:23 +03:00
Donald Sharp 7cc91e67a3 *: Convert quagga_signal_X to frr_signal_X
Naming functions/data structures more appropriately for
the project we are actually in.

Signed-off-by: Donald Sharp <sharpd@nvidia.com>
2021-11-11 14:41:27 -05:00
Igor Ryzhov c3634e4411 bfdd: fix coverity warnings
show/clear DEFUNs always require either peer label or IP address to be
specified, so if `label` is NULL then `peer_str` is definitely not NULL.
But Coverity doesn't know about that, so it complains about possible
NULL dereference of `peer_str`. This commit should make Coverity happy.

Signed-off-by: Igor Ryzhov <iryzhov@nfware.com>
2021-11-10 16:36:15 +03:00
Russ White ed79d896b2
Merge pull request #9833 from idryzhov/cleanup-if-by-index-all-vrf
*: fix usage of if_lookup_by_index_all_vrf
2021-11-05 15:17:31 -04:00
Russ White f727c6ae8a
Merge pull request #9837 from idryzhov/cleanup-if-by-name-vrf-all
*: fix usage of if_lookup_by_name_all_vrf
2021-10-27 15:29:39 -04:00
Russ White a2b52cbeb4
Merge pull request #9854 from opensourcerouting/zapi-call-table
*: convert zclient callbacks to table
2021-10-26 11:33:44 -04:00
Donald Sharp 6f354338f9
Merge pull request #9824 from idryzhov/nb-cli-const-lyd-node
lib: northbound cli show/cmd functions must not modify data nodes
2021-10-25 07:55:39 -04:00
David Lamparter a243d1db93 *: convert zclient callbacks to table
This removes a giant `switch { }` block from lib/zclient.c and
harmonizes all zclient callback function types to be the same (some had
a subset of the args, some had a void return, now they all have
ZAPI_CALLBACK_ARGS and int return.)

Apart from getting rid of the giant switch, this is a minor security
benefit since the function pointers are now in a `const` array, so they
can't be overwritten by e.g. heap overflows for code execution anymore.

Signed-off-by: David Lamparter <equinox@opensourcerouting.org>
2021-10-20 13:28:46 +02:00
Igor Ryzhov 33fc8bc7f3 bfdd: cleanup bfd_session_enable
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-15 03:42:52 +03:00
Igor Ryzhov eb4135bad2 bfdd: cleanup vrf handling in packet receive
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-10-14 18:55:33 +03:00
Donald Sharp c6c39c05b5
Merge pull request #9684 from opensourcerouting/printfrr-false-positive
*: `frr-format` with unmodified GCC
2021-10-14 07:34:20 -04:00
Igor Ryzhov 2560505196 lib: northbound cli show/cmd functions must not modify data nodes
To ensure this, add a const modifier to functions' arguments. Would be
great do this initially and avoid this large code change, but better
late than never.

Signed-off-by: Igor Ryzhov <iryzhov@nfware.com>
2021-10-13 20:12:35 +03:00
Donatas Abraitis 876968a610 bfdd: Do not explicitly set the thread pointer to NULL
FRR should only ever use the appropriate THREAD_ON/THREAD_OFF
semantics.  This is espacially true for the functions we
end up calling the thread for.

Signed-off-by: Donatas Abraitis <donatas.abraitis@gmail.com>
2021-10-04 19:24:28 +03:00
David Lamparter f62de63c6a *: frr-format with unmodified GCC
Since there's very few locations where the `frr-format` actually prints
false positive warnings, consensus seems to be to just work around the
false positives even if the code is correct.

In fact, there is only one pattern of false positives currently, in
`bfdd/dplane.c` which does `vty_out("%"PRIu64, (uint64_t)be64toh(...))`.
The workaround/fix for this is a replacement `be64toh` whose type is
always `uint64_t` regardless of what OS we're on, making the cast
unnecessary.

Signed-off-by: David Lamparter <equinox@opensourcerouting.org>
2021-09-28 11:20:32 +02:00
Christian Hopps d448e2c5f9
Merge pull request #9331 from idryzhov/explicit-exit
*: explicitly print "exit" at the end of every node config
2021-08-26 11:57:33 -04:00
Donatas Abraitis d10bda270e *: Drop break after using frr_help_exit() in switch/case
Signed-off-by: Donatas Abraitis <donatas.abraitis@gmail.com>
2021-08-25 10:49:05 +03:00
Igor Ryzhov 07679ad98a *: explicitly print "exit" at the end of every node config
There is a possibility that the same line can be matched as a command in
some node and its parent node. In this case, when reading the config,
this line is always executed as a command of the child node.

For example, with the following config:
```
router ospf
 network 193.168.0.0/16 area 0
!
mpls ldp
 discovery hello interval 111
!
```
Line `mpls ldp` is processed as command `mpls ldp-sync` inside the
`router ospf` node. This leads to a complete loss of `mpls ldp` node
configuration.

To eliminate this issue and all possible similar issues, let's print an
explicit "exit" at the end of every node config.

This commit also changes indentation for a couple of existing exit
commands so that all existing commands are on the same level as their
corresponding node-entering commands.

Fixes #9206.

Signed-off-by: Igor Ryzhov <iryzhov@nfware.com>
2021-08-23 22:08:20 +03:00
Donatas Abraitis e702605d80 *: Do not check for XMALLOC/XCALLOC against NULLs
We don't check this pattern anywhere in the code basically, so let's
unify the code.

Signed-off-by: Donatas Abraitis <donatas.abraitis@gmail.com>
2021-06-29 22:27:50 +03:00
Rafael Zalamena a36dd4c930
Merge pull request #8758 from idryzhov/bfd-fixes
BFD fixes
2021-06-07 08:34:06 -03:00
Igor Ryzhov 03e3333b11 bfdd: fix bfd key structure
There's a padding byte between "mhop" and "peer" fields in this structure.
This structure is sometimes passed by value to functions and used in
assignments. The standard doesn't guarantee that the padding bytes are
copied on assignments. As this structure is used as a hash key, having
this padding byte with unspecified value can lead to unwanted behavior.

Fix the possible issue by making the "mhop" field to be 2 bytes. Also
make the struct packed as a precaution for future changes.

Signed-off-by: Igor Ryzhov <iryzhov@nfware.com>
2021-06-02 20:58:35 +03:00
Igor Ryzhov 874ca76997 bfdd: forbid setting interface for multihop sessions
Signed-off-by: Igor Ryzhov <iryzhov@nfware.com>
2021-06-01 18:08:29 +03:00
Igor Ryzhov edc3622d82 bfdd: don't store interface pointer for multihop sessions
It breaks "neighbor A.B.C.D update-source" config in BGP.

Signed-off-by: Igor Ryzhov <iryzhov@nfware.com>
2021-06-01 18:08:29 +03:00
Igor Ryzhov b6c87c3576 lib: fix bfd multihop
Never send an interface name/index for multihop sessions. It breaks
"neighbor A.B.C.D update-source" config in BGP.

Signed-off-by: Igor Ryzhov <iryzhov@nfware.com>
2021-06-01 18:07:54 +03:00
Christian Hopps 3bb513c399 lib: adapt to version 2 of libyang
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-05-13 16:24:48 -04:00
David Lamparter 9c2a14e753
Merge pull request #8100 from qlyoung/remove-sample-conf-files 2021-04-13 02:20:53 +02:00
Igor Ryzhov 613bcbc5d5 bfdd: fix nb cli show with defaults
The idea of the "with-defaults" flag is to show the default values for
parameters that were not configured by the user. But bfdd incorrectly
shows the default values for all parameters, including the
user-configured ones.

Signed-off-by: Igor Ryzhov <iryzhov@nfware.com>
2021-04-12 14:21:36 +03:00
Quentin Young b832909b42 *: remove *.conf.sample files
Most of these are many, many years out of date. All of them vary
randomly in quality. They show up by default in packages where they
aren't really useful now that we use integrated config. Remove them.

The useful ones have been moved to the docs.

Signed-off-by: Quentin Young <qlyoung@nvidia.com>
2021-04-09 13:14:30 -04:00
Igor Ryzhov 0a01b0f44d bfdd: fix profiles autocompletion
Signed-off-by: Igor Ryzhov <iryzhov@nfware.com>
2021-04-01 15:49:46 +03:00
Igor Ryzhov f13ad7c542 bbfd: clear nb config entries when removing bfd node
When bfd node is removed, we must clear all NB entries set by its
children - sessions and profiles. Let's store some fake data as an entry
for the bfd node to be able to unset it later.

Signed-off-by: Igor Ryzhov <iryzhov@nfware.com>
2021-04-01 15:49:27 +03:00
Igor Ryzhov e93c3c003d bfdd: remove profiles when removing bfd node
Fixes #8379.

Signed-off-by: Igor Ryzhov <iryzhov@nfware.com>
2021-04-01 15:49:18 +03:00
Donatas Abraitis 37916b2b11
Merge pull request #8121 from opensourcerouting/macro-cleanup
*: require ISO C11 + semicolons after file-scope macros
2021-03-22 11:00:34 +02:00
Rafael Zalamena 692b3561df
Merge pull request #8225 from idryzhov/bfd-echo-mode
bfdd: fix echo receive timer and disable echo mode
2021-03-17 10:45:43 +00:00
David Lamparter 80413c2073 *: require semicolon after FRR_DAEMON_INFO & co.
... again ...

Signed-off-by: David Lamparter <equinox@diac24.net>
2021-03-17 06:18:39 +01:00
David Lamparter bf8d3d6aca *: require semicolon after DEFINE_MTYPE & co
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-17 06:18:17 +01:00
Igor Ryzhov 4df3e31c3d bfdd: separate echo rx/tx timers
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-16 22:14:57 +03:00
Igor Ryzhov f1825d571e bfdd: warn users about echo-mode restrictions
Echo-mode implementation is currently broken. Instead of sending packets
to it's own address, bfdd is sending echo packets to the peer's address.
It may seem to work when testing between two FRR instances, because FRR
loops back such packets, but no other implementation is supposed to do
that.

Let's warn users that the current implementation works only between two
FRR instances.

Signed-off-by: Igor Ryzhov <iryzhov@nfware.com>
2021-03-16 17:25:06 +03:00
Igor Ryzhov 5aeb216ea5 bfdd: fix starting echo receive timer
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-16 17:25:06 +03:00
Igor Ryzhov 59dad8137e bfdd: make sessions administratively up by default
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-15 00:44:08 +03:00
Igor Ryzhov 1e9bae0331 bfdd: fix detect timeout
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-03-09 23:08:41 +03:00
Igor Ryzhov 17cb53af25 bfdd: fix echo configuration in profile
It's not currently possible to configure echo mode in profile node:
```
(config)# bfd
(config-bfd)# profile test
(config-bfd-profile)# echo-mode
% Echo mode is only available for single hop sessions.
(config-bfd-profile)# echo-interval 20
% Echo mode is only available for single hop sessions.
```

Signed-off-by: Igor Ryzhov <iryzhov@nfware.com>
2021-03-04 21:17:20 +03:00