Commit graph

424 commits

Author SHA1 Message Date
Igor Ryzhov 632f36100c bfdd: forbid creation of the same peer with and without interface name
Currently it is possible to configure the same peer with and without
interface name:
```
bfd
 peer 1.1.1.1
 !
 peer 1.1.1.1 interface enp0s3
 !
```

There are multiple problems with that:
1. Both nodes actually control the same BFD session. So the config is
   either duplicated or, even worse, different - and there is no way to
   say which one actually works.
2. When the user deletes both nodes, the session is not actually freed,
   because its refcount is always greater than 1.

Such configuration must be forbidden. User should either have single
node with wildcard name or multiple nodes with actual names.

Signed-off-by: Igor Ryzhov <iryzhov@nfware.com>
2021-03-03 23:10:19 +03:00
Igor Ryzhov 5e4d0fbc93 bfdd: actually return validation error instead of logging
Before:
```
(config-bfd)# peer fe80::a00:27ff:fea2:5803 multihop local-address fe80::a00:27ff:fea2:5802
% Configuration failed.

Error type: validation
```

After:
```
(config-bfd)# peer fe80::a00:27ff:fea2:5803 multihop local-address fe80::a00:27ff:fea2:5802
% Configuration failed.

Error type: validation
Error description: When using link-local you must specify an interface
```

Signed-off-by: Igor Ryzhov <iryzhov@nfware.com>
2021-03-03 19:43:00 +03:00
Igor Ryzhov 4cce733fc2 bfdd: require local-address when using multihop
If local-address is not supplied, then an incorrect xpath is generated
which is not expected by NB CLI.

Fixes #7465.

Signed-off-by: Igor Ryzhov <iryzhov@nfware.com>
2021-03-03 19:38:38 +03:00
David Lamparter f1db813dbb *: fix format string SNAFUs
Signed-off-by: David Lamparter <equinox@diac24.net>
2021-02-16 00:47:51 +01:00
Philippe Guibert 35da69f154
Merge pull request #8006 from idryzhov/fix-bfd-lookup
bfdd: fix session lookup
2021-02-12 18:25:09 +01:00
Donald Sharp 14b3514806 bfdd: Prevent use after free ( again )
Valgrind is still reporting:

466020-==466020==    by 0x11B9F4: main (bfdd.c:403)
466020-==466020==  Address 0x5a7d544 is 84 bytes inside a block of size 272 free'd
466020:==466020==    at 0x48399AB: free (vg_replace_malloc.c:538)
466020-==466020==    by 0x490A947: qfree (memory.c:140)
466020-==466020==    by 0x48F2AE8: if_delete (if.c:322)
466020-==466020==    by 0x48F250D: if_destroy_via_zapi (if.c:195)
466020-==466020==    by 0x497071E: zclient_interface_delete (zclient.c:2040)
466020-==466020==    by 0x49745F6: zclient_read (zclient.c:3687)
466020-==466020==    by 0x4955AEC: thread_call (thread.c:1684)
466020-==466020==    by 0x48FF64E: frr_run (libfrr.c:1126)
466020-==466020==    by 0x11B9F4: main (bfdd.c:403)
466020-==466020==  Block was alloc'd at
466020:==466020==    at 0x483AB65: calloc (vg_replace_malloc.c:760)
466020-==466020==    by 0x490A805: qcalloc (memory.c:115)
466020-==466020==    by 0x48F23D6: if_new (if.c:160)
466020-==466020==    by 0x48F257F: if_create_name (if.c:214)
466020-==466020==    by 0x48F3493: if_get_by_name (if.c:558)
466020-==466020==    by 0x49705F2: zclient_interface_add (zclient.c:1989)
466020-==466020==    by 0x49745E0: zclient_read (zclient.c:3684)
466020-==466020==    by 0x4955AEC: thread_call (thread.c:1684)
466020-==466020==    by 0x48FF64E: frr_run (libfrr.c:1126)
466020-==466020==    by 0x11B9F4: main (bfdd.c:403)

Apparently the bs->ifp pointer is being set even in cases when
the bs->key.ifname is not being set.  So go through and just
match the interface pointer and cut-to-the-chase.

Signed-off-by: Donald Sharp <sharpd@nvidia.com>
2021-02-07 15:03:51 -05:00
Igor Ryzhov 6cfcb775ef bfdd: fix session lookup
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-02-04 01:22:29 +03:00
Donald Sharp c882c9dd80 bfdd: Prevent storage of ifp pointer that has been deleted
On shutdown, interfaces are deleted but if the bfd session
is down we retain the interface pointer.  Remove the retained
pointer.

Signed-off-by: Donald Sharp <sharpd@nvidia.com>
2021-01-30 15:41:35 -05:00
Donald Sharp f91d3ae36c bfdd: Prevent unininited data transmittal
Valgrind reports:

2052866-==2052866==
2052866-==2052866== Syscall param sendmsg(msg.msg_name) points to uninitialised byte(s)
2052866:==2052866==    at 0x49C8E13: sendmsg (sendmsg.c:28)
2052866-==2052866==    by 0x11DC08: bp_udp_send (bfd_packet.c:823)
2052866-==2052866==    by 0x11DD76: ptm_bfd_echo_snd (bfd_packet.c:179)
2052866-==2052866==    by 0x114C2D: ptm_bfd_echo_xmt_TO (bfd.c:469)
2052866-==2052866==    by 0x114C2D: ptm_bfd_echo_start (bfd.c:498)
2052866-==2052866==    by 0x114C2D: bs_echo_timer_handler (bfd.c:1199)
2052866-==2052866==    by 0x11E478: bfd_recv_cb (bfd_packet.c:702)
2052866-==2052866==    by 0x4904846: thread_call (thread.c:1681)
2052866-==2052866==    by 0x48CB4DF: frr_run (libfrr.c:1126)
2052866-==2052866==    by 0x113044: main (bfdd.c:403)
2052866-==2052866==  Address 0x1ffefff3e8 is on thread 1's stack

In ptm_bfd_echo_snd, for the v4 case we were memsetting the v6 memory
then setting the v4 memory.  Just fix it.

Signed-off-by: Donald Sharp <sharpd@nvidia.com>
2021-01-30 14:31:47 -05:00
Donald Sharp 74dd7f6da6 bfdd: Remove #if 0
We do have a bunch of old code that is never used.

Signed-off-by: Donald Sharp <sharpd@nvidia.com>
2021-01-28 13:58:34 -05:00
Philippe Guibert 99950bc559 bfdd: improve some debug messages related to zebra notifications
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-09 13:29:45 +00:00
Philippe Guibert 134a53ec48 bfdd: update vrf of received packet
on vrf-lite environment, all incoming bfd packets are received by the
same socket on the default namespace. the vrfid is not relevant and
needs to be updated based on the incoming interface where traffic has
been received. If the traffic is received from an interface belonging to
a separate vrf, update the vrfid value accordingly.

Signed-off-by: Philippe Guibert <philippe.guibert@6wind.com>
2021-01-09 13:29:45 +00:00
Philippe Guibert 039c8158f3 bfdd: enable bfd session if vrf interface available
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>
2021-01-09 13:29:42 +00:00
Philippe Guibert 031705c9fc bfdd: socket should be bound to vrf interface by default
When running in vrf-lite mode, the socket used in a vrf environment
should be bound to an interface belonging to the vrf. If no one is
selected, then the vrf interface itself should be bound to that socket,
so that outgoing packets are being applied routing rules for that vrf.

Signed-off-by: Philippe Guibert <philippe.guibert@6wind.com>
2021-01-09 13:07:18 +00:00
Igor Ryzhov 0a731a72ee bfd: fix session lookup
local-address is optional for both IPv4 and IPv6.

Signed-off-by: Igor Ryzhov <iryzhov@nfware.com>
2020-12-04 14:38:30 +03:00
Donald Sharp 0fb4ab0388
Merge pull request #6950 from opensourcerouting/bfd-distributed-v3
bfdd: distributed BFD
2020-12-02 20:50:47 -05:00
Rafael Zalamena 7d2de131ce bfdd: session specific command type checks
Replace the unclear error message:

```
% Failed to edit configuration.

YANG error(s):
 Schema node not found.
 YANG path: /frr-bfdd:bfdd/bfd/sessions/single-hop[dest-addr='192.168.253.6'][interface=''][vrf='default']/minimum-ttl
```

With:

```
frr(config-bfd-peer)# minimum-ttl 250
% Minimum TTL is only available for multi hop sessions.

! or

frr(config-bfd-peer)# echo
% Echo mode is only available for single hop sessions.
frr(config-bfd-peer)# echo-interval 300
% Echo mode is only available for single hop sessions.
```

Reported-by: Trae Santiago
Signed-off-by: Rafael Zalamena <rzalamena@opensourcerouting.org>
2020-12-01 08:01:37 -03:00
Rafael Zalamena ec62c60fc8 bfdd: move interface/vrf reset code
Don't reset interface/vrf pointer everytime a session is disabled
instead only do it when it was explicitly removed.

Signed-off-by: Rafael Zalamena <rzalamena@opensourcerouting.org>
2020-11-24 07:55:07 -03:00
Rafael Zalamena 6655b43d51 bfdd: support connecting to BFD data plane
Add option to connect to a data plane server instead of receiving
connections.

Signed-off-by: Rafael Zalamena <rzalamena@opensourcerouting.org>
2020-11-24 07:55:07 -03:00
Rafael Zalamena 400632a9a2 bfdd: distributed BFD show commands
Show BFD sessions updated counters by asking the data plane for this
information and show data plane statistics.

Signed-off-by: Rafael Zalamena <rzalamena@opensourcerouting.org>
2020-11-24 07:54:07 -03:00
Rafael Zalamena efd04d60ca bfdd: integrate distributed BFD
Add hooks in the correct places so the BFD daemon uses the data plane
instead of the software packet sending implementation to monitor the
session.

This code also adds some handlers to support fallback to FRR BFD session
handling, however since this complicates the code it won't work at the
moment (the BFD sockets are disabled by default when using data plane).

Signed-off-by: Rafael Zalamena <rzalamena@opensourcerouting.org>
2020-11-24 07:54:07 -03:00
Rafael Zalamena 29397ec1ab bfdd: disable sockets when using distributed BFD
The current distributed BFD implementantion doesn't support falling back
to software implementation in FRR, so to keep the code simple lets give
the data plane full control of the BFD packet handling (helps running a
software data plane for testing too otherwise it would fail with 'address
in use' error).

Signed-off-by: Rafael Zalamena <rzalamena@opensourcerouting.org>
2020-11-24 07:54:07 -03:00
Rafael Zalamena 8ba709dd1c bfdd: distributed BFD debugging knob
Add a knob to show/hide the distributed BFD (data plane) debug messages.

Signed-off-by: Rafael Zalamena <rzalamena@opensourcerouting.org>
2020-11-24 07:54:07 -03:00
Rafael Zalamena 230aefe258 bfdd: import distributed BFD implementation
Distributed BFD is a term used for BFD implementations that do not run
on the routing engine, instead it is run on a data plane (software or
hardware based).

The current code implements the basic communication between FRR BFD
daemon with an external BFD data plane and defines the protocol format
in the file `bfddp_packet.h`.

To enable/use data plane you need to start BFD daemon with the command
line `--dplaneaddr <type>:<address>`, then a socket will be opened to
listen for incoming data plane connections.

Signed-off-by: Rafael Zalamena <rzalamena@opensourcerouting.org>
2020-11-24 07:54:07 -03:00
Rafael Zalamena fe744cec64 bfdd: import data plane protocol header
The BFD data plane header has definitions for the data plane
communication protocol that will be used to implement the distributed
BFD feature.

Signed-off-by: Rafael Zalamena <rzalamena@opensourcerouting.org>
2020-11-24 07:54:07 -03:00
Rafael Zalamena 4c4faa474e bfdd: fix multiple links same address
Allows users with multiple links using same IPv6 address (same VRF) to
work.

Reported-by: Matti Suuronen
Signed-off-by: Rafael Zalamena <rzalamena@opensourcerouting.org>
2020-11-18 16:06:16 -03:00
Russ White a1a41d5c6b
Merge pull request #7476 from opensourcerouting/bfd-fixes
bfdd,lib: integration fixes
2020-11-17 07:34:29 -05:00
Donald Sharp 8affc28e91 bfdd: On interface address delete we are leaking memory
The interface address delete callback from zebra was not
deleting the ifc that was created as per normal work methodologies

Signed-off-by: Donald Sharp <sharpd@nvidia.com>
2020-11-14 18:16:39 -05:00
Rafael Zalamena 270f9c682c bfdd: missing BFD integration debug value
Show the TTL value sent by the routing protocol.

Signed-off-by: Rafael Zalamena <rzalamena@opensourcerouting.org>
2020-11-08 12:06:32 -03:00
Rafael Zalamena 4b983eef2c bfdd,lib: simplify integration protocol
Let the integration protocol always send the full configuration
instead of saving a few bytes. It will also allow protocols to specify
source address for IPv4 single hop connections and interface for multi
hop configuration.

Signed-off-by: Rafael Zalamena <rzalamena@opensourcerouting.org>
2020-11-08 12:06:32 -03:00
Donald Sharp 3bb43118ec
Merge pull request #7473 from eololab/fix-crash-bfdd-show-counters-json
bfdd: fix crash on show bfd peers counters json
2020-11-06 18:40:07 -05:00
Emanuele Bovisio 1d923374f6 bfdd: fix crash on show bfd peers counters json
wrong pointer passed to bfd_id_iterate function

Signed-off-by: Emanuele Bovisio <emanuele.bovisio@eolo.it>
2020-11-06 17:34:56 +01:00
Igor Ryzhov 1db60b576b bfdd: fix possible null dereference
bs->ifp may be null, so we should check it before dereferencing.

Signed-off-by: Igor Ryzhov <iryzhov@nfware.com>
2020-11-05 19:46:27 +03:00
Mark Stapp b3d6bc6ef0 * : update signature of thread_cancel api
Change thread_cancel to take a ** to an event, NULL-check
before dereferencing, and NULL the caller's pointer. Update
many callers to use the new signature.

Signed-off-by: Mark Stapp <mjs@voltanet.io>
2020-10-23 08:59:34 -04:00
Donatas Abraitis 2dbe669bdf :* Convert prefix2str to %pFX
Signed-off-by: Donatas Abraitis <donatas.abraitis@gmail.com>
2020-10-22 09:07:41 +03:00
Igor Ryzhov d7b86ae4fe vtysh: dynamically generate the list of daemons for commands
Some daemons were actually missing from the static definitions: nhrpd,
babeld, eigrpd and bfdd.

Signed-off-by: Igor Ryzhov <iryzhov@nfware.com>
2020-10-02 15:06:27 +03:00
Tashana Mehta-Wilson d0df29bae8 bfdd: Make new multihop peer if local-address is unique
Previously if there were two multihop peers created that had the same
peer address but different local addresses then the second peer to be
created would be merged with the first one and niether would be able to
be deleted. This was due to an issue in the function bfd_key_lookup().
When the second peer was created its key would be sent into the lookup
function and would reach the last section, even though it shouldn't
have. A check has been placed around the section so that it will not be
entered if a peer is multihop.

Signed-off-by: Tashana Mehta-Wilson <tashana.mehta-wilson@alliedtelesis.co.nz>
2020-09-29 15:30:56 +13:00
Renato Westphal e4d09f608d
Merge pull request #7063 from idryzhov/yang-leafref
yang: use leafref instead of string
2020-09-26 15:12:13 -03:00
Igor Ryzhov 3704ff5608 *: move all userdata when changing node xpath
The same thing was done for interfaces in commit f7c20aa1f.

Signed-off-by: Igor Ryzhov <iryzhov@nfware.com>
2020-09-24 21:05:32 +03:00
Igor Ryzhov 4ec8e74bd9 bfdd: use * as a placeholder for an empty interface name in northbound
Signed-off-by: Igor Ryzhov <iryzhov@nfware.com>
2020-09-24 20:43:38 +03:00
Igor Ryzhov 2e8d292578 bfdd: interface and vrf are mandatory leafs
Signed-off-by: Igor Ryzhov <iryzhov@nfware.com>
2020-09-24 20:23:21 +03:00
Igor Ryzhov 463d46a38a bfdd: add missing includes
Signed-off-by: Igor Ryzhov <iryzhov@nfware.com>
2020-09-22 12:00:21 +03:00
Igor Ryzhov e6426ace1e bfdd: fix parameter length
There is no space reserved for "[source-addr='']".

Signed-off-by: Igor Ryzhov <iryzhov@nfware.com>
2020-08-24 18:45:53 +03:00
Donald Sharp f1446f9885 bfdd: Allow it to work when V6 is completely turned off
Experimental patch to allow us to discuss if we should
allow bfdd to work when v6 is turned off in the kernel.

Signed-off-by: Donald Sharp <sharpd@cumulusnetworks.com>
2020-08-14 09:20:09 -04:00
Rafael Zalamena 262e1d2528 bfdd: implement minimum TTL
Initial BFD protocol implementation had a hard coded value of maximum 5
hops, now we have a configurable hop amount with a safe default of 1
hop.

Signed-off-by: Rafael Zalamena <rzalamena@opensourcerouting.org>
2020-08-11 21:22:39 -03:00
Rafael Zalamena 4e38f82a0a bfdd: simplify and remove duplicated code
Move the session configuration application logic to a single function.

Signed-off-by: Rafael Zalamena <rzalamena@opensourcerouting.org>
2020-08-11 16:46:10 -03:00
Rafael Zalamena 1a2e2fff35 bfdd: implement passive mode
The passive mode is briefly described in the RFC 5880 Bidirectional
Forwarding Detection (BFD), Section 6.1. Overview:

> A system may take either an Active role or a Passive role in session
> initialization.  A system taking the Active role MUST send BFD
> Control packets for a particular session, regardless of whether it
> has received any BFD packets for that session.  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.  At least one
> system MUST take the Active role (possibly both).  The role that a
> system takes is specific to the application of BFD, and is outside
> the scope of this specification.

Signed-off-by: Rafael Zalamena <rzalamena@opensourcerouting.org>
2020-08-11 16:46:10 -03:00
Renato Westphal ca77b518bd *: introduce DEFPY_YANG & friends
DEFPY_YANG will allow the CLI to identify which commands are
YANG-modeled or not before executing them. This is going to be
useful for the upcoming configuration back-off timer work that
needs to commit pending configuration changes before executing a
command that isn't YANG-modeled.

Signed-off-by: Renato Westphal <renato@opensourcerouting.org>
2020-08-03 15:17:03 -03:00
Donald Sharp 3eb15671ee
Merge pull request #6731 from opensourcerouting/style-string-prep
*: string coding style
2020-07-15 20:06:55 -04:00
David Lamparter 6cde4b4552 *: remove PRI[udx](8|16|32)
These are completely pointless and break coccinelle string replacements.

Scripted commit, idempotent to running:
```
python3 tools/stringmangle.py --pri8-16-32 `git ls-files | egrep '\.[ch]$'`
```

Signed-off-by: David Lamparter <equinox@diac24.net>
2020-07-14 10:43:40 +02:00
David Lamparter 3efd0893d0 *: un-split strings across lines
Remove mid-string line breaks, cf. workflow doc:

  .. [#tool_style_conflicts] For example, lines over 80 characters are allowed
     for text strings to make it possible to search the code for them: please
     see `Linux kernel style (breaking long lines and strings)
     <https://www.kernel.org/doc/html/v4.10/process/coding-style.html#breaking-long-lines-and-strings>`_
     and `Issue #1794 <https://github.com/FRRouting/frr/issues/1794>`_.

Scripted commit, idempotent to running:
```
python3 tools/stringmangle.py --unwrap `git ls-files | egrep '\.[ch]$'`
```

Signed-off-by: David Lamparter <equinox@diac24.net>
2020-07-14 10:37:25 +02:00
Rafael Zalamena 2975f578de bfdd: update detect multiplier on profile change
Add missing profile update hook for detection multiplier change.

Signed-off-by: Rafael Zalamena <rzalamena@opensourcerouting.org>
2020-07-13 10:12:18 -03:00
Mark Stapp dd8bc21d2f bfdd: Use XFREE, clean up SA warning for bfd profiles
Use XFREE instead of raw free, clean up SA warning in bfd
profile delete.

Signed-off-by: Mark Stapp <mjs@voltanet.io>
2020-07-03 11:50:34 -04:00
Donald Sharp 7799deeed6
Merge pull request #6437 from opensourcerouting/bfd-profiles-bgp
bfdd,bgpd: profiles integration support
2020-07-02 12:22:44 -04:00
Russ White cba183561b
Merge pull request #6390 from opensourcerouting/bfd-cp-fix
bfdd: tell peer when our control plane is dead
2020-06-16 07:56:03 -04:00
Rafael Zalamena c2aab69336 *: add filter northbound support
Allow all daemons to work with filter northbound.

Signed-off-by: Rafael Zalamena <rzalamena@opensourcerouting.org>
2020-06-05 14:31:26 -03:00
Rafael Zalamena f3e1d2241e bfdd: don't update peers settings on shutdown
During the shutdown phase don't attempt to apply settings to peers
as it is useless and will crash if the peer hash is gone.

Signed-off-by: Rafael Zalamena <rzalamena@opensourcerouting.org>
2020-05-29 17:55:40 -03:00
Rafael Zalamena 18322efd13 bfdd,lib: implement protocol profile selection
Implement the infrastructure for other protocols daemon (e.g. `bgpd`,
`ospfd`, `isisd` etc...) to communicate to BFD daemon which profile
they want to use with their peers.

It was also added the ability for protocols to change profile while
running (no need to remove the registration and then register again).

The protocols message building function was rewritten to support
multiple arguments through `struct bfd_session_arg`, so we can
implement new features without the need of changing function
prototypes. The old function was also rewritten to keep
compatibility.

The profile message part is only available for BFD daemon at the
moment.

Signed-off-by: Rafael Zalamena <rzalamena@opensourcerouting.org>
2020-05-29 17:48:14 -03:00
Rafael Zalamena f6dfa24739 bfdd: remove profile pointers on removal
Remove all profile references on removal and free all resources on shutdown.

Signed-off-by: Rafael Zalamena <rzalamena@opensourcerouting.org>
2020-05-20 15:18:06 -03:00
Rafael Zalamena ccc9ada868 bfdd: implement BFD session configuration profiles
Allow user to pre-configure peers with a profile. If a peer is using a
profile any configuration made to the peer will take precedence over
the profile configuration.

In order to track the peer configuration we have now an extra copy of
the peer configuration in `peer_profile` inside `struct bfd_session`.
This information will help the profile functions to detect user
configurations and avoid overriding what the user configured. This is
especially important for peers created via other protocols where the
default `shutdown` state is disabled (peers created manually are
`shutdown` by default).

Profiles can be used before they exist: if no profile exists then it
will use the default configuration.

Signed-off-by: Rafael Zalamena <rzalamena@opensourcerouting.org>
2020-05-20 15:18:00 -03:00
Rafael Zalamena d40d6c2274 bfdd,lib,vtysh: new command node for BFD profiles
Add the necessary code to implement the BFD profile command node.

Signed-off-by: Rafael Zalamena <rzalamena@opensourcerouting.org>
2020-05-20 10:39:34 -03:00
Rafael Zalamena 4d12e1f90e bfdd: remove duplicated code
Move echo/shutdown toggle code to a function and remove the duplicated
logic.

Signed-off-by: Rafael Zalamena <rzalamena@opensourcerouting.org>
2020-05-15 11:32:47 -03:00
Rafael Zalamena 29191d3183 bfdd: tell peer when our control plane is dead
Simplify and fix the code that handles session teardown on control
plane shutdown (either failure or graceful).

- Don't move the `NULL` check inside `free` functions that expect
  data: it creates harder to understand flows.
- Add some new debug messages to aid visualizing session deletions.
- Add sanity check error message (if it ever happens).

Signed-off-by: Rafael Zalamena <rzalamena@opensourcerouting.org>
2020-05-13 19:41:50 -03:00
Rafael Zalamena c516ebf90f
Merge pull request #6301 from pguibert6WIND/bfd_debug_show
bfdd: display debugging status of bfd
2020-04-27 15:12:07 -03:00
Philippe Guibert 9be4b18a2f bfdd: display debugging status of bfd
display debugging status of bfd.

Signed-off-by: Philippe Guibert <philippe.guibert@6wind.com>
2020-04-27 17:22:13 +02:00
David Lamparter 189be3996d bfdd: fix frr-format false warning
Dealing with PRIu64 is unfortunately a bit hacky in the frr-format
plugin, as in, it works correctly with snprintfrr, but breaks on plain
snprintf.  There's no good solution unfortunately :/.

Signed-off-by: David Lamparter <equinox@opensourcerouting.org>
2020-04-27 09:52:41 +02:00
David Lamparter 94cfb0692e build: make clippy Makefile rules nicer
These are easy to get subtly wrong, and doing so can cause
nondeterministic failures when racing in parallel builds.

Signed-off-by: David Lamparter <equinox@opensourcerouting.org>
2020-04-27 09:52:41 +02:00
David Lamparter 2768748b88 build: use VPATH for vtysh_scan
No need to put $(top_srcdir) everywhere.

Signed-off-by: David Lamparter <equinox@opensourcerouting.org>
2020-04-27 09:30:01 +02:00
Renato Westphal 60ee8be107 *: change the signature of the northbound callbacks to be more flexible
Having a fixed set of parameters for each northbound callback isn't a
good idea since it makes it difficult to add new parameters whenever
that becomes necessary, as several hundreds or thousands of existing
callbacks need to be updated accordingly.

To remediate this issue, this commit changes the signature of all
northbound callbacks to have a single parameter: a pointer to a
'nb_cb_x_args' structure (where x is different for each type
of callback). These structures encapsulate all real parameters
(both input and output) the callbacks need to have access to. And
adding a new parameter to a given callback is as simple as adding
a new field to the corresponding 'nb_cb_x_args' structure, without
needing to update any instance of that callback in any daemon.

This commit includes a .cocci semantic patch that can be used to
update old code to the new format automatically.

Signed-off-by: Renato Westphal <renato@opensourcerouting.org>
2020-04-23 10:14:32 -03:00
Rafael Zalamena 5920b3eb38 *: replace all random() calls
Replace all `random()` calls with a function called `frr_weak_random()`
and make it clear that it is only supposed to be used for weak random
applications.

Use the annotation described by the Coverity Scan documentation to
ignore `random()` call warnings.

Signed-off-by: Rafael Zalamena <rzalamena@opensourcerouting.org>
2020-04-17 20:57:43 -03:00
Donald Sharp a83014ccd6
Merge pull request #6247 from FRRouting/nb_conversions
Merge nb_converions branch to master
2020-04-16 19:39:14 -04:00
Donald Sharp 2ff99507ad
Merge pull request #6135 from opensourcerouting/cli-node-cleanup
*: clean up the mess that is CLI command nodes
2020-04-16 19:24:56 -04:00
Chirag Shah 6fd8972aef *: include vrf northbound module in init
Signed-off-by: Chirag Shah <chirag@cumulusnetworks.com>
2020-04-16 08:00:15 -07:00
Santosh P K 09133ff4f7
Merge pull request #5451 from opensourcerouting/rcu-log
logging subsystem rewrite
2020-04-16 20:23:44 +05:30
David Lamparter f4b8291fcb *: move CLI node names to cmd_node->name
And again for the name.  Why on earth would we centralize this, just so
people can forget to update it?

Signed-off-by: David Lamparter <equinox@diac24.net>
2020-04-16 12:53:59 +02:00
David Lamparter 243895805a *: move CLI parent data to cmd_node->parent_node
Same as before, instead of shoving this into a big central list we can
just put the parent node in cmd_node.

Signed-off-by: David Lamparter <equinox@diac24.net>
2020-04-16 12:53:00 +02:00
David Lamparter 612c2c15d8 *: remove second parameter on install_node()
There is really no reason to not put this in the cmd_node.

And while we're add it, rename from pointless ".func" to ".config_write".

[v2: fix forgotten ldpd config_write]

Signed-off-by: David Lamparter <equinox@diac24.net>
2020-04-16 12:53:00 +02:00
David Lamparter 249a771b63 *: remove cmd_node->vtysh
The only nodes that have this as 0 don't have a "->func" anyway, so the
entire thing is really just pointless.

Signed-off-by: David Lamparter <equinox@diac24.net>
2020-04-16 12:53:00 +02:00
David Lamparter 62b346eefa *: clean up cmd_node initializers
... and use named assignments everywhere (so I can change the struct.)

Signed-off-by: David Lamparter <equinox@diac24.net>
2020-04-16 12:53:00 +02:00
Rafael Zalamena 24843702a0 bfdd: add more zebra debug messages
Uncomment old debug about relayed messages from zebra.

Signed-off-by: Rafael Zalamena <rzalamena@opensourcerouting.org>
2020-04-14 09:35:08 -03:00
Rafael Zalamena 6e10bd9772 bfdd: constify satostr
Detect modifications to the `sockaddr_any` struct.

Signed-off-by: Rafael Zalamena <rzalamena@opensourcerouting.org>
2020-04-14 09:35:08 -03:00
Rafael Zalamena 869dada534 bfdd: remove time calculation debugs
These were disabled by default and not used by a long time.

Signed-off-by: Rafael Zalamena <rzalamena@opensourcerouting.org>
2020-04-14 09:35:08 -03:00
Rafael Zalamena 08de92aff3 bfdd: simplify code flow
Don't attempt to handle out-of-memory situations: XMALLOC/XCALLOC will
`assert` if there is no memory left.

Signed-off-by: Rafael Zalamena <rzalamena@opensourcerouting.org>
2020-04-14 09:35:08 -03:00
Rafael Zalamena 48da2c3169 bfdd: add debug fine tuning capabilities
Move most of the log messages to debug guards so they only get activated
if the user configured the proper debug level.

Current debug levels:
- Peer events.
- Zebra events.
- Network layer debugs.

Signed-off-by: Rafael Zalamena <rzalamena@opensourcerouting.org>
2020-04-14 09:35:08 -03:00
Rafael Zalamena 259b64ebb5 bfdd: use standard log macros
Remove old log_* macros and standardize on FRR's logging infrastructure.

Signed-off-by: Rafael Zalamena <rzalamena@opensourcerouting.org>
2020-04-10 11:06:22 -03:00
Rafael Zalamena 4caf638833 bfdd: fix transmission timer calculation
According to the RFC 5880 the transmission time should be mandated by
the slowest system.

Signed-off-by: Rafael Zalamena <rzalamena@opensourcerouting.org>
2020-04-09 17:46:02 -03:00
Rafael Zalamena bfea10110c bfdd: initialize packet data with zeroes
Lets avoid garbage data on packets by zeroing the packet before setting
the fields/flags.

Signed-off-by: Rafael Zalamena <rzalamena@opensourcerouting.org>
2020-04-09 17:44:56 -03:00
Rafael Zalamena b88113ef73 bfdd: remove BFD_*_FLAG macros
Lets use what FRR provide us instead of implementing a new macros.

Signed-off-by: Rafael Zalamena <rzalamena@opensourcerouting.org>
2020-04-09 16:54:11 -03:00
David Lamparter 0bdeb5e58d lib: rewrite zlog lock-free & TLS-buffered
This is a full rewrite of the "back end" logging code.  It now uses a
lock-free list to iterate over logging targets, and the targets
themselves are as lock-free as possible.  (syslog() may have a hidden
internal mutex in the C library;  the file/fd targets use a single
write() call which should ensure atomicity kernel-side.)

Note that some functionality is lost in this patch:
- Solaris printstack() backtraces are ditched (unlikely to come back)
- the `log-filter` machinery is gone (re-added in followup commit)
- `terminal monitor` is temporarily stubbed out.  The old code had a
  race condition with VTYs going away.  It'll likely come back rewritten
  and with vtysh support.
- The `zebra_ext_log` hook is gone.  Instead, it's now much easier to
  add a "proper" logging target.

v2: TLS buffer to get some actual performance

Signed-off-by: David Lamparter <equinox@diac24.net>
2020-04-01 06:53:26 +02:00
Ruben Kerkhof 0cd61f8d24 bfdd: fix -Wundef warning
Signed-off-by: Ruben Kerkhof <ruben@rubenkerkhof.com>
2020-03-30 11:22:58 +02:00
David Lamparter 566bdaf68c *: fix format string warnings
Signed-off-by: David Lamparter <equinox@diac24.net>
2020-03-29 10:45:46 +02:00
David Lamparter d6951e5ef9 *: remove tabs from log messages
Some logging systems are, er, "allergic" to tabs in log messages.
(RFC5424: "The syslog application SHOULD avoid octet values below 32")

Signed-off-by: David Lamparter <equinox@opensourcerouting.org>
2020-03-24 18:47:12 +01:00
Donatas Abraitis a8f58eb6a5 *: Use short version of bool expressions
Signed-off-by: Donatas Abraitis <donatas.abraitis@gmail.com>
2020-03-04 15:04:23 +02:00
Donald Sharp 7f5818fbd6 *: change hash_backet to hash_bucket
It's been a year search and destroy.

Signed-off-by: Donald Sharp <sharpd@cumulusnetworks.com>
Signed-off-by: Quentin Young <qlyoung@cumulusnetworks.com>
2020-02-28 13:59:13 -05:00
Jafar Al-Gharaibeh 4d67e75282 Revert "*: change hash_backet to hash_bucket"
This reverts commit 3895c42a2e.

LabN CI update needs to be coordinated before merging this

Signed-off-by: Jafar Al-Gharaibeh <jafar@atcorp.com>
2020-02-27 09:52:02 -06:00
Donald Sharp 3895c42a2e *: change hash_backet to hash_bucket
It's been a year search and destroy.

Signed-off-by: Donald Sharp <sharpd@cumulusnetworks.com>
2020-02-26 20:03:34 -05:00
Quentin Young b3ba5dc7fe *: don't null after XFREE; XFREE does this itself
Signed-off-by: Quentin Young <qlyoung@cumulusnetworks.com>
2020-02-03 11:22:13 -05:00
Russ White 6fe6a8b544
Merge pull request #5716 from opensourcerouting/bfdd-log
bfdd: remove logging shim & fix warnings
2020-01-28 10:25:56 -05:00
Quentin Young abe5af1774
Merge pull request #5412 from opensourcerouting/bfdd-vrf-fix
bfdd: fix multiple VRF handling
2020-01-22 14:14:21 -05:00
David Lamparter b7b3d466eb bfdd: fix format strings
... now that we get warnings about them ...

Signed-off-by: David Lamparter <equinox@diac24.net>
2020-01-21 16:35:00 +01:00
David Lamparter d85b048d48 bfdd: remove logging shim
This does exactly nothing, other than hiding format warnings...

Signed-off-by: David Lamparter <equinox@diac24.net>
2020-01-21 16:35:00 +01:00
David Lamparter 429576883e doc: rename man pages to frr-*
The vrrpd one conflicts with the standalone vrrpd package; also we're
installing daemons to /usr/lib/frr on some systems so they're not on
PATH.

Signed-off-by: David Lamparter <equinox@diac24.net>
2020-01-15 14:05:11 +01:00
SumitAgarwal123 1d0a11e6cf bfdd: Json fields for multiplier
Adding fields "detect-multiplier" and "remote-detect-multiplier"
for JSON to to reflect changes in "show bfd peers output"

Signed-off-by: Sayed Mohd Saquib sayed.saquib@broadcom.com
2019-12-03 21:20:31 -05:00
SumitAgarwal123 fa6e709f3f bfdd: Adding new CLI, show bfd peers brief
Added new CLI to display all BFD peer in brief format

Signed-off-by: Sayed Mohd Saquib <sayed.saquib@broadcom.com>
2019-12-03 21:20:28 -05:00
SumitAgarwal123 d679003308 bfdd: Adding new cli, clear bfd counters
Adding new CLI clear bfd counters,
This CLI wil only reset Rx/Tx counters,
it will not reset session UP/DOWN and Zebra event count

Signed-off-by: Sayed Mohd Saquib <sayed.saquib@broadcom.com>
2019-12-03 21:14:36 -05:00
SumitAgarwal123 825e3b9457 bfdd: Adding new fields to display show bfd peer
Adding 2 two new fields
1. Peer type, configured/dynamic
2. Detect multiplier

Signed-off-by: Sayed Mohd Saquib <sayed.saquib@broadcom.com>
2019-12-03 21:14:36 -05:00
David Lamparter 2b64873d24 *: generously apply const
const const const your boat, merrily down the stream...

Signed-off-by: David Lamparter <equinox@diac24.net>
2019-12-02 15:01:29 +01:00
David Lamparter 0d8c7a26a1 *: make frr_yang_module_info const
Signed-off-by: David Lamparter <equinox@diac24.net>
2019-11-30 00:38:32 +01:00
Rafael Zalamena d1ca89aead bfdd: fix multiple VRF handling
Use the interface VRF information instead of relying on the VRF specific
socket information.

Signed-off-by: Rafael Zalamena <rzalamena@opensourcerouting.org>
(cherry picked from commit c05c48621c)
2019-11-22 08:37:18 -03:00
Russ White 1157238115
Merge pull request #5274 from opensourcerouting/bfdd-vrf-socket
bfdd: VRF security improvement
2019-11-19 11:41:06 -05:00
Mark Stapp f7b3ca193b bfdd: remove unused initialization sa warning
There's a variable initialization that's triggering an SA
warning - don't do that.

Signed-off-by: Mark Stapp <mjs@voltanet.io>
2019-11-14 08:29:09 -05:00
Rafael Zalamena 4a9feb66b9 bfdd: bind VRF sockets to devices
Always bind the created sockets to their respective VRF devices. With
this it should be possible to run BFD on VRFs without needing to weaken
the security setting `net.ipv4.udp_l3mdev_accept=1`.

Signed-off-by: Rafael Zalamena <rzalamena@opensourcerouting.org>
2019-11-04 09:50:54 -03:00
Renato Westphal 6c57402944 bfdd: split northbound callbacks into multiple files
Rearrange the bfdd northbound callbacks as following:
* bfd_nb.h: prototypes of all northbound callbacks.
* bfd_nb.c: definition of all northbound callbacks and their
  associated YANG data paths.
* bfd_nb_config.c: implementation of YANG configuration nodes.
* bfd_nb_state.c: implementation of YANG state nodes.

This should help to keep to code more organized and easier to
maintain.

No behavior changes intended.

Signed-off-by: Renato Westphal <renato@opensourcerouting.org>
2019-10-30 10:32:51 -03:00
Rafael Zalamena 37cdb6e91d
Merge pull request #5197 from SumitAgarwal123/BFD_ADMIN_DOWN
bfdd: Handling local and remote admin-down
2019-10-29 12:12:27 -03:00
SumitAgarwal123 7555dc6116 bfdd: Handling local and remote admin-down
Scenarios where this code change is required:

1. BFD is un-configured from BGP at remote end.

Neighbour BFD sends ADMIN_DOWN state, but BFD on local side will send
DOWN to BGP, resulting in BGP session DOWN.
Removing BFD session administratively shouldn't bring DOWN BGP session
at local or remote.

2. BFD is un-configured from BGP or shutdown locally.

BFD will send state DOWN to BGP resulting in BGP session DOWN.
(This is akin to saying do not use BFD for BGP)
Removing BFD session administratively shouldn't bring DOWN BGP session at
local or remote.

Signed-off-by: Sayed Mohd Saquib sayed.saquib@broadcom.com
2019-10-28 21:38:20 -07:00
Donald Sharp 102e215737 bfdd: VRF and Coverity
Fixup a couple of Coverity issues surrounding pointers

Signed-off-by: Donald Sharp <sharpd@cumulusnetworks.com>
2019-10-25 20:26:29 -04:00
Rafael Zalamena 38e9efd85f bfdd: don't allow link-local without interface
When using link-local addresses we must provide scope-id to the
operating system so it knows where to send packets.

Spotted by Pavel Ivashchenko (@zays26).

Signed-off-by: Rafael Zalamena <rzalamena@opensourcerouting.org>
2019-10-11 16:54:51 -03:00
Rafael Zalamena ced291deb7 bfdd: simplify session observers code
Don't be selective about what to observe, always observe all possible
aspects of the session that may change on run-time (i.e. bind address,
interface and VRF existence).

Signed-off-by: Rafael Zalamena <rzalamena@opensourcerouting.org>
2019-10-11 16:13:24 -03:00
Rafael Zalamena 8ee0862e80 bfdd: set session down after disabling it
If a session is no longer able to send/receive packets, it is very
likely it will be down in a few milliseconds so lets speed up the
process and correctly mark it as down.

Signed-off-by: Rafael Zalamena <rzalamena@opensourcerouting.org>
2019-10-11 16:12:49 -03:00
Rafael Zalamena 507d75d453 bfdd: disable sockets polling before closing it
Otherwise the `thread_read` will keep waking us up to handle closing
sockets which are never unregistered.

Signed-off-by: Rafael Zalamena <rzalamena@opensourcerouting.org>
2019-10-11 11:15:56 -03:00
Philippe Guibert c7666ae7a1 bfdd: upon vrf disable, unlink bfd session with vrf
bfd session has a vrf pointer that needs to be reset, when vrf is
disabled.

Signed-off-by: Philippe Guibert <philippe.guibert@6wind.com>
2019-10-11 11:12:21 -03:00
SumitAgarwal123 13044b6f6f bfdd: Fixing coredump in log
Param missing in debug log, leading to coredump

Signed-off-by: Sayed Mohd Saquib <sayed.saquib@broadcom.com>
2019-10-11 10:59:20 -03:00
Igor Ryzhov 1e81afc365 *: remove redundant brackets in commands
Signed-off-by: Igor Ryzhov <iryzhov@nfware.com>
2019-10-08 15:31:40 +03:00
Russ White 9898a2fb34
Merge pull request #5009 from donaldsharp/interface_deletion
lib, zebra: Allow for interface deletion when kernel event happens
2019-09-30 07:46:19 -04:00
Igor Ryzhov e429a2a0cc *: fix missing VRF autocompletions
Current autocompletion works only for simple "vrf NAME" case.

This commit expands it also for the following cases:
- "nexthop-vrf NAME" in staticd
- usage of $varname in many daemons

All daemons are updated to use single varname "$vrf_name".

Signed-off-by: Igor Ryzhov <iryzhov@nfware.com>
2019-09-24 19:51:46 +03:00
Donald Sharp 3c3c325203 *: Convert zapi->interface_delete to ifp callback
Convert the callback of the interface_delete to the new
ifp callback.

Signed-off-by: Donald Sharp <sharpd@cumulusnetworks.com>
2019-09-19 13:34:06 -04:00
Donald Sharp ef7bd2a3d5 *: Switch all zclient->interface_add to interface create callback
Switch the zclient->interface_add functionality to have everyone
use the interface create callback in lib/if.c

Signed-off-by: Donald Sharp <sharpd@cumulusnetworks.com>
2019-09-19 13:34:06 -04:00
Donald Sharp 138c5a7450 *: Add infrastructure to support zapi interface callbacks
Start the conversion to allow zapi interface callbacks to be
controlled like vrf creation/destruction/change callbacks.

This will allow us to consolidate control into the interface.c
instead of having each daemon read the stream and react accordingly.
This will hopefully reduce a bunch of cut-n-paste stuff

Create 4 new callback functions that will be controlled by
lib/if.c

create -> A upper level protocol receives an interface creation event
The ifp is brand spanking newly created in the system.
up -> A upper level protocol receives a interface up event
This means the interface is up and ready to go.
down -> A upper level protocol receives a interface down
destroy -> A upper level protocol receives a destroy event
This means to delete the pointers associated with it.

At this point this is just boilerplate setup for future commits.
There is no new functionality.

Signed-off-by: Donald Sharp <sharpd@cumulusnetworks.com>
2019-09-19 13:34:06 -04:00
Renato Westphal 8685be73e0 Revert "lib: introduce a read-write lock for northbound configurations"
Adding a lock to protect the global running configuration doesn't
help much since the FRR daemons are not prepared to process
configuration changes in a pthread that is not the main one (a
whole lot of new protections would be necessary to prevent race
conditions).

This means the lock added by commit 83981138 only adds more
complexity for no benefit. Remove it now to simplify the code.

All northbound clients, including the gRPC one, should either run
in the main pthread or use synchronization primitives to process
configuration transactions in the main pthread.

This reverts commit 83981138fe.
2019-09-18 14:35:10 -03:00
Russ White fe8d933c2c
Merge pull request #4564 from pguibert6WIND/misc_vrf_update_name
Misc vrf update name
2019-09-17 07:22:22 -04:00
Quentin Young 9dcb41a65c
Merge pull request #4604 from opensourcerouting/mutex-sugar
mutex syntactic sugar
2019-09-03 14:55:14 -04:00
David Lamparter 0cf6db21ec *: frr_elevate_privs -> frr_with_privs
Signed-off-by: David Lamparter <equinox@opensourcerouting.org>
2019-09-03 17:18:35 +02:00
Philippe Guibert 8cf3c21737 bfdd: close bfd echo sockets, upon vrf disable
upon vrf disable, an event informs bfd daemon that the vrf contexts
should be removed. in the case a vrf backend is netns based, all sockets
opened under that netns have to be closed. otherwise it is impossible
for the system to completely close the network namespace. that implies
that some interfaces may not be deleted, and may not be given back to
default vrf.

PR=65291
Signed-off-by: Philippe Guibert <philippe.guibert@6wind.com>
Acked-by: Julien Floret <julien.floret@6wind.com>
2019-09-03 17:06:52 +02:00
Philippe Guibert 955d3ad8a8 bfdd: change vrf name with bypassing nb api
bfd operational & config data may already applied and available, while
an external event requests for changing the vrf name. this change
updates the config and operational context of yang.

Signed-off-by: Philippe Guibert <philippe.guibert@6wind.com>
2019-08-27 16:58:47 +02:00
Philippe Guibert f06e248c53 bfdd: update vrf name of bfd session if necessary
if the bfd session is already enabled, then dynamically change the vrf
name if the vrf where bfd is executed changed its name.

Signed-off-by: Philippe Guibert <philippe.guibert@6wind.com>
2019-08-27 15:08:50 +02:00
Philippe Guibert 43ba41c1a3 bfdd: add the vrf update hook in case vrf name changes
in case vrf name changes, use a hook to be notified about the vrf
change.

Signed-off-by: Philippe Guibert <philippe.guibert@6wind.com>
2019-08-27 15:08:50 +02:00
Philippe Guibert e0f36c91e2 bfdd: if no vrfname is passed, use default vrf name
default vrf name is used to forge the key that permits storing the
session.

Signed-off-by: Philippe Guibert <philippe.guibert@6wind.com>
2019-08-27 15:08:50 +02:00
Philippe Guibert 3a20889ff6 bfdd: add vrf information as key element for bfd session search
the default vrf is looked up, in the search list algorithm.

Signed-off-by: Philippe Guibert <philippe.guibert@6wind.com>
2019-08-27 15:08:50 +02:00
Rafael Zalamena 284062bf17 bfdd: keep source information for single hop
Add source address to northbound when creating sessions with this
information. It is not possible to change source address after the
session was created, but we should be able to set it to make IPv6 work.

Spotted by Philippe Guibert.

Signed-off-by: Rafael Zalamena <rzalamena@opensourcerouting.org>
2019-07-09 09:49:45 -03:00
Rafael Zalamena 307fc4259a bfdd: fix some CI warnings
Use `static` functions for file local functions to please `check_patch.pl`.

Signed-off-by: Rafael Zalamena <rzalamena@opensourcerouting.org>
2019-07-02 13:05:27 -03:00
Rafael Zalamena fdf8ac87f8 bfdd: convert bfd command to northbound
This helps northbound to create the `bfd` node on the configuration
output sooner than adding a peer.

Signed-off-by: Rafael Zalamena <rzalamena@opensourcerouting.org>
2019-06-25 09:34:14 -03:00
Rafael Zalamena 77452ad263 bfdd: small tweaks on northbound
* Change `ERR_VALIDATION` to `ERR_INCONSISTENCY` to error on
    inconsistent state.
  * Duplicated sanity checks:
    * Remove detection multiplier sanity check.
    * Remove duplicated session sanity check.

Signed-off-by: Rafael Zalamena <rzalamena@opensourcerouting.org>
2019-06-25 09:06:48 -03:00
Rafael Zalamena 8e0c84ff27 bfdd: fix compilation warnings on OmniOS
Build will fail with `Werror` enabled with:

```
  CC       bfdd/bfdd_cli.o
In file included from ./lib/frratomic.h:21:0,
                 from ./lib/memory.h:22,
                 from ./lib/vector.h:25,
                 from ./lib/command.h:25,
                 from bfdd/bfdd_cli.c:23:
./config.h:665:0: error: "_FILE_OFFSET_BITS" redefined [-Werror]
 #define _FILE_OFFSET_BITS 64
 ^
In file included from /usr/include/iso/stdlib_iso.h:49:0,
                 from /usr/include/stdlib.h:37,
                 from ./lib/memory.h:20,
                 from ./lib/vector.h:25,
                 from ./lib/command.h:25,
                 from bfdd/bfdd_cli.c:23:
/opt/gcc-5.1.0/lib/gcc/i386-pc-solaris2.11/5.1.0/include-fixed/sys/feature_tests.h:231:0: note: this is the location of the previous definition
 #define _FILE_OFFSET_BITS 32
 ^
In file included from ./lib/thread.h:24:0,
                 from ./lib/vty.h:27,
                 from ./lib/command.h:26,
                 from bfdd/bfdd_cli.c:23:
./lib/zebra.h:271:2: error: #warning "assuming 4-byte alignment for CMSG_SPACE" [-Werror=cpp]
 #warning "assuming 4-byte alignment for CMSG_SPACE"
  ^
./lib/zebra.h:277:2: error: #warning "assuming 4-byte alignment for CMSG_LEN" [-Werror=cpp]
 #warning "assuming 4-byte alignment for CMSG_LEN"
  ^
cc1: all warnings being treated as errors
Makefile:6876: recipe for target 'bfdd/bfdd_cli.o' failed
gmake[1]: *** [bfdd/bfdd_cli.o] Error 1
```

Signed-off-by: Rafael Zalamena <rzalamena@opensourcerouting.org>
2019-06-24 13:42:40 -03:00
Rafael Zalamena eefca51eb3 bfdd: fix compilation warnings on OpenBSD
Build will fail with `Werror` enabled with:

```
bfdd/bfdd_northbound.c:876: warning: initialized field overwritten
bfdd/bfdd_northbound.c:876: warning: (near initialization for 'frr_bfdd_info.nodes[0].cbs')
...
cc1: error: unrecognized command line option "-Wno-unused-result"
gmake[1]: *** [Makefile:6875: bfdd/bfdd_northbound.o] Error 1
```

Signed-off-by: Rafael Zalamena <rzalamena@opensourcerouting.org>
2019-06-24 11:46:29 -03:00
Philippe Guibert f7bb830439 bfdd: authorise multihop and interface setting
the restriction to authorise multihop and interface setting has no
meaning here.

Signed-off-by: Philippe Guibert <philippe.guibert@6wind.com>
2019-06-22 10:10:56 -03:00
Philippe Guibert 7818c5fba0 bfdd: add not '\n' to shutdown help string
help string had not a '\n' at the end of the line for bfd shutdown help
command.

Signed-off-by: Philippe Guibert <philippe.guibert@6wind.com>
2019-06-22 10:10:56 -03:00
Rafael Zalamena 8a676ce6b1 bfdd: use microseconds timers in YANG
Lets allow specification to accept microseconds, but limit the timers
configuration in FRR to milliseconds (minimum is 10 ms and maximum is 60
seconds).

This matches the RFC 5880 and the IETF BFD YANG draft model.

Signed-off-by: Rafael Zalamena <rzalamena@opensourcerouting.org>
2019-06-22 10:10:56 -03:00
Rafael Zalamena 2a573ff672 bfdd: support global BFD reset
Add command 'no bfd' to remove all BFD sessions configuration and fix
other daemon integration.

Signed-off-by: Rafael Zalamena <rzalamena@opensourcerouting.org>
2019-06-22 10:10:56 -03:00
Rafael Zalamena 47a7b00c2d bfdd: fix daemon warning on startup
```
warnings: BFD: [EC 100663317] YANG model "frr-bfdd@*" not embedded, trying external file
```

Embed the YANG model into the binary to avoid reading an external file.

Signed-off-by: Rafael Zalamena <rzalamena@opensourcerouting.org>
2019-06-22 10:10:56 -03:00
Rafael Zalamena 49cc9e7b64 bfdd: implement configuration reload
Reload configuration on SIGHUP using the northbound.

Signed-off-by: Rafael Zalamena <rzalamena@opensourcerouting.org>
2019-06-22 10:10:56 -03:00
Rafael Zalamena 0030482f5e bfdd: fix northbound remote-discriminator display
When the remote discriminator hasn't been assigned yet, then we can't
return a value of 0. The value '0' is an invalid discriminator and the
yang handlers will complain about it.

Signed-off-by: Rafael Zalamena <rzalamena@opensourcerouting.org>
2019-06-22 10:10:56 -03:00
Rafael Zalamena 0287a64a6e bfdd: implement write_config using northbound
Move all the `show running-config` logic to the new northbound
implementation.

Signed-off-by: Rafael Zalamena <rzalamena@opensourcerouting.org>
2019-06-22 10:10:56 -03:00
Rafael Zalamena adc26455bf 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>
2019-06-22 10:10:56 -03:00
Rafael Zalamena 3e4e7405ff bfdd: remove the label command
This command has no use for CLI and is relevant for the control socket only.

Signed-off-by: Rafael Zalamena <rzalamena@opensourcerouting.org>
2019-06-22 10:08:33 -03:00
Rafael Zalamena 014cab13bf bfdd: export some private functions
These functions are going to be used by the future northbound
implementation to handle BFD sessions.

Signed-off-by: Rafael Zalamena <rzalamena@opensourcerouting.org>
2019-06-22 10:08:33 -03:00
Donald Sharp 574fa9a597
Merge pull request #4536 from pguibert6WIND/bfd_startup_does_not_work
bfdd: avoid double socket initialisation on same netns
2019-06-21 19:41:02 -04:00
Philippe Guibert 30c5d21ee3 bfdd: avoid double socket initialisation on same netns
when working with a standard vrf backend, bfdd ignores that and tries to
create and configure bfd sockets for each vrf, which will fail for the
second vrf discovered, since the network namespace used is the same, and
it is not possible to use same socket settings twice. Handle this case,
and avoids to reinitialise sockets.
This patch however does not leverage bfd support for vrf-lite.

Signed-off-by: Philippe Guibert <philippe.guibert@6wind.com>
2019-06-21 09:21:03 +02:00
David Lamparter 1b88c3cb4c bfdd: use MTYPE_STATIC
MTYPE definitions should be local to the file using them whereever
possible.  Also remove some superfluous ;

Signed-off-by: David Lamparter <equinox@opensourcerouting.org>
2019-06-21 08:54:25 +02:00
Mark Stapp fa3bf3a21b lib,bgpd,babeld,ripngd,nhrpd,bfdd: clean up SA warnings
Clean up several SA warnings.

Signed-off-by: Mark Stapp <mjs@voltanet.io>
2019-06-06 13:13:15 -04:00
Rafael Zalamena 9e8238f5d6
Merge pull request #4431 from donaldsharp/mad_gainz
Switch over to `-N FOO` adding FOO to the various directories/files we open up
2019-06-05 11:30:19 -03:00
Donald Sharp 9f95a33ad0 bfdd: Modify bfdd to quietly accept access-lists
The `access-list ...` command was causing bfdd to return
'unknown commands'.  Make bfdd at least cognizant of
access-lists enough to not create strange error messages

Signed-off-by: Donald Sharp <sharpd@cumulusnetworks.com>
2019-06-04 21:38:11 -04:00
Donald Sharp 89277ebf76 bfdd: Allow -N to influence BFDD_CONTROL_SOCKET
When selecting to run bfdd with -N allow the namespace passed
in to be added to the $frr_statedir/<namespace name>/bfdd.sock

If --bfdctl is passed in that will override the -N option.

If neither --bfdctl or -N is passed in then the default
of  $frr_statedir/bfdd.sock is used.

Signed-off-by: Donald Sharp <sharpd@cumulusnetworks.com>
2019-06-04 10:37:19 -04:00
Russ White ace430f0db
Merge pull request #4144 from pguibert6WIND/bfd_cbit
BFD CBIT
2019-05-16 10:13:26 -04:00
Quentin Young d8b87afe7c lib: hashing functions should take const arguments
It doesn't make much sense for a hash function to modify its argument,
so const the hash input.

BGP does it in a couple places, those cast away the const. Not great but
not any worse than it was.

Signed-off-by: Quentin Young <qlyoung@cumulusnetworks.com>
2019-05-14 21:23:08 +00:00
Philippe Guibert 9beff0bda9 bfdd, lib, bgpd: add bfd cbit usage
bfd cbit is a value carried out in bfd messages, that permit to keep or
not, the independence between control plane and dataplane. In other
words, while most of the cases plan to flush entries, when bfd goes
down, there are some cases where that bfd event should be ignored. this
is the case with non stop forwarding mechanisms where entries may be
kept. this is the case for BGP, when graceful restart capability is
used. If BFD event down happens, and bgp is in graceful restart mode, it
is wished to ignore the BFD event while waiting for the remote router to
restart.
The changes take into account the following:
- add a config flag across zebra layer so that daemon can set or not the
  cbit capability.
- ability for daemons to read the remote bfd capability associated to a bfd
  notification.
- in bfdd, according to the value, the cbit value is set
- in bfdd, the received value is retrived and stored in the bfd session
  context.
- by default, the local cbit announced to remote is set to 1 while
  preservation of the local path is not set.

Signed-off-by: Philippe Guibert <philippe.guibert@6wind.com>
2019-05-14 16:49:49 +02:00
Philippe Guibert f21536d2f0 bfd: add bfdd_privs to the bglobal structure
this structure contains the bfdd_privs structure in charge of the
privilege settings. The initialisation has moved a bit, in order that
the preinit settings are done.

Signed-off-by: Philippe Guibert <philippe.guibert@6wind.com>
2019-05-07 16:01:47 +02:00
Philippe Guibert 533ba31ff4 bfdd: show bfd [vrf NAME] peer command change
the vrf keyword is possible through show bfd command. However, there is
a change with previous version, since that show command was accepting
vrf keyword, only after peer keyword. Now, the vrf keyword is accepted,
but before peer keyword.

Signed-off-by: Philippe Guibert <philippe.guibert@6wind.com>
2019-05-07 16:01:47 +02:00
Philippe Guibert 6f37416509 bfdd: add show bfd [vrf NAME] counters command
that command permits to filter bfd peer counter contexts per vrf.

Signed-off-by: Philippe Guibert <philippe.guibert@6wind.com>
2019-05-07 16:01:47 +02:00
Philippe Guibert 9146cc2a10 bfdd: add show bfd [vrf NAME] peers command
this command permits to filter among the list of bfd peers which one is
to be displayed.

Signed-off-by: Philippe Guibert <philippe.guibert@6wind.com>
2019-05-07 16:01:47 +02:00
Philippe Guibert 5ef92a2b20 bfdd: avoid creating duplicate peer contexts
when configuring bfd peers, some parameters may or may not be taken into
account to search for a previous context. This has as consequence that
the result is different with the order of vty commands:

bfd
peer 4.5.6.7 vrf AAAA local-address 1.2.3.5
end
peer 4.5.6.7 vrf AAAA   <--- should not create new session
end

Similarly, the user thinks it has overwritten some key parameters like
local address, whereas it is wrong.
here, some informational message should be present.

bfd
peer 4.5.6.7 vrf AAAA
end
peer 4.5.6.7 vrf AAAA local-address 1.2.3.5
<--- should inform that the key lookup 1.2.3.5 is wrong
end

Signed-off-by: Philippe Guibert <philippe.guibert@6wind.com>
2019-05-07 16:01:42 +02:00
Philippe Guibert 3e60827a3b bfdd: do not insert obs entry in the list, once disabled
the bfd entry has not to be inserted in the obs list again.

Signed-off-by: Philippe Guibert <philippe.guibert@6wind.com>
2019-05-07 15:54:30 +02:00
Philippe Guibert b433551595 bfdd: check bfd on upon interface presence from separate vrf
if a separate vrf detects a new interface, then some bfd sessions may be
run.

Signed-off-by: Philippe Guibert <philippe.guibert@6wind.com>
2019-05-07 15:54:30 +02:00
Philippe Guibert d24af713c1 bfdd: upon vrf enable/disable, update bs and obs list
parse observer list, and update bs context if vrf pointer is not yet populated.
this is helpful for validation, but also will permit bfd to send
notification to remote daemon.

Signed-off-by: Philippe Guibert <philippe.guibert@6wind.com>
2019-05-07 15:54:30 +02:00
Philippe Guibert 54aadda13d bfdd: register to interfaces from other vrfs
registration for new interfaces is done.

Signed-off-by: Philippe Guibert <philippe.guibert@6wind.com>
2019-05-07 15:53:07 +02:00
Philippe Guibert 45b000d085 bfdd, zebra: pass the vrf identifier between zebra and bfdd
messages from daemons to bfd daemons go through zebra. zebra reuses the
vrf identifier to send messages to bfd.

Signed-off-by: Philippe Guibert <philippe.guibert@6wind.com>
2019-05-07 15:53:07 +02:00
Philippe Guibert 7bcadbaefe bfdd: socket handling per vrf context
sockets are created foreach network namespace context enabled.

Signed-off-by: Philippe Guibert <philippe.guibert@6wind.com>
2019-05-07 15:49:39 +02:00
Philippe Guibert 9fc0bc5cfc bfdd: add vrf framework
vrf initialisation is done. hooks are installed. no specific action is
done, except the vrf initialisation.

Signed-off-by: Philippe Guibert <philippe.guibert@6wind.com>
2019-05-07 15:49:39 +02:00
Philippe Guibert 1f4b73e54c bfdd: use vrf api for creation socket with binding with vrf lite
in the case vrf-lite is used, it is possible to call SO_BINDTODVICE, by
using vrf_socket() call.

Signed-off-by: Philippe Guibert <philippe.guibert@6wind.com>
2019-05-07 15:49:39 +02:00
Philippe Guibert 218afa3671 bfdd: permit to configure both iface and vrf
it is possible to configure both iface and vrfname. also, the
appropriate vrf is used, in case an iface is given.

Signed-off-by: Philippe Guibert <philippe.guibert@6wind.com>
2019-05-07 15:49:39 +02:00
Philippe Guibert 4e6b48d3db bfdd: add sys_admin capability and net_raw capability
in order to be able to create sockets on separate namespaces, add the
privs setting needed.
the former capability is needed to use SO_BINDTODEVICE option.

Signed-off-by: Philippe Guibert <philippe.guibert@6wind.com>
2019-05-07 15:49:39 +02:00
Philippe Guibert e52a638341 bfdd: socket creation in a vrf can be done
vrf_socket() call is performed instead of socket() call.

Signed-off-by: Philippe Guibert <philippe.guibert@6wind.com>
2019-05-07 15:49:39 +02:00
Philippe Guibert 5764d816d3 bfdd: remove the constraint of bfd vrf and multihop
there is no specific constraints that should prevent from configuring a
multihop bfd session within a bfd session.

Signed-off-by: Philippe Guibert <philippe.guibert@6wind.com>
2019-05-07 15:49:39 +02:00
Philippe Guibert bc50bcc83c bfdd: move bfd_ses_[xx] to bfd_sess_[xx] like other routines
this is a change to be more consistent with function naming convention
in bfd. a small change for 3 functions.

Signed-off-by: Philippe Guibert <philippe.guibert@6wind.com>
2019-05-07 15:49:39 +02:00
Philippe Guibert 1ac865e7d4 bfdd: use logging convention for remaining zlog_debug
zlog_debug is being replaced with log_debug, because all bfdd code uses
that way of logging information.

Signed-off-by: Philippe Guibert <philippe.guibert@6wind.com>
2019-05-07 15:49:39 +02:00
Quentin Young 121f9dee7c *: use ZAPI_CALLBACK_ARGS macro for zapi handlers
This macro:
- Marks ZAPI callbacks for readability
- Standardizes argument names
- Makes it simple to add ZAPI arguments in the future
- Ensures proper types
- Looks better
- Shortens function declarations

Signed-off-by: Quentin Young <qlyoung@cumulusnetworks.com>
2019-05-03 20:57:35 +00:00
Russ White a34fd5b9f1
Merge pull request #4155 from pguibert6WIND/bfd_increase_config
bfdd: avoid having bfd config inherited from operation context
2019-04-25 18:48:35 -04:00
Rafael Zalamena 545d3f7046 bfdd: fix UDP source port range
RFC 5881 Section 4 tells us that the BFD source port must be between
49152 and 65535 inclusive.

Spotted by Lucian Cristian.

Signed-off-by: Rafael Zalamena <rzalamena@opensourcerouting.org>
2019-04-25 14:41:44 -03:00
Philippe Guibert 4c741971a5 bfdd: remove operational bfd sessions from remote daemons
when a remote daemon wants to get rid of a session, a request is sent,
but the deletion of the bfd session was not done. The flush is done,
provided that there is not someone else that is using that session.

Signed-off-by: Philippe Guibert <philippe.guibert@6wind.com>
2019-04-18 11:48:16 +02:00
Philippe Guibert 6bdb4a42ac bfdd: avoid having bfd config inherited from operation context
there are cases where bfd sessions are created from remote daemons. in
that case, the bfd daemon were appearing in both operational and
configuration contexts of bfd. Change that by only keeping operational
contexts.

Signed-off-by: Philippe Guibert <philippe.guibert@6wind.com>
2019-04-18 11:48:16 +02:00
Renato Westphal 84cffea04f
Merge pull request #4042 from donaldsharp/bfd_sa
bfdd: Clean up assignment without being used SA issue
2019-03-30 00:19:24 -03:00
Donald Sharp 9d6c33eadf bfdd, nhrpd, pimd: When deleting an interface clean up
When we delete an interface, we need to set the interface
ifindex to an internal value so that we don't end up in
a state where the re-addition of the same ifindex, due to
a rename operation, causes an infinite loop.

Fixes:#4007
Fix-Suggested-by: Saravanan K
Signed-off-by: Donald Sharp <sharpd@cumulusnetworks.com>
2019-03-29 12:44:05 -04:00
Donald Sharp 3cef9b7ffd bfdd: Clean up assignment without being used SA issue
Clang's SA is reporting that we have a assignment without
subsuquent use.  Modify the code such that we no-longer
do this.

Signed-off-by: Donald Sharp <sharpd@cumulusnetworks.com>
2019-03-29 11:35:07 -04:00
Donald Sharp ed74032b7f bfdd: Prevent uninited use of data
Running valgrind w/ bfdd and shut/no shuting interfaces
can result in this valgrind issue:

==20279== Conditional jump or move depends on uninitialised value(s)
==20279==    at 0x115848: bfdd_sessions_enable_address (ptm_adapter.c:644)
==20279==    by 0x115848: bfdd_interface_address_update (ptm_adapter.c:674)
==20279==    by 0x48D8CAB: zclient_read (zclient.c:2698)
==20279==    by 0x48CCEE3: thread_call (thread.c:1603)
==20279==    by 0x48A84EF: frr_run (libfrr.c:1011)
==20279==    by 0x10DAC3: main (bfdd.c:236)
==20279==

When creating the bso data structure set the bso_isaddress to false
as a default value.

Signed-off-by: Donald Sharp <sharpd@cumulusnetworks.com>
2019-03-20 10:32:58 -04:00
Rafael Zalamena 4cf4e83297 bfdd: fix echo loopback function
Add the address family to the sockaddr structure otherwise `sendmsg`
will fail with `EAFNOSUPPORT`.

Signed-off-by: Rafael Zalamena <rzalamena@opensourcerouting.org>
2019-03-19 17:25:00 -03:00
Rafael Zalamena 5ff7d1be75 bfdd: fix JSON API local-address translation
Get the local-address from the right key struct member.

Signed-off-by: Rafael Zalamena <rzalamena@opensourcerouting.org>
2019-03-19 17:22:58 -03:00
Rafael Zalamena 261e0ba94d bfdd: don't enable sessions without local-address
When the local-address configured by the peer doesn't exist, then we
must observe the session until the mentioned address comes up.

Signed-off-by: Rafael Zalamena <rzalamena@opensourcerouting.org>
2019-03-11 22:03:29 -03:00
Rafael Zalamena 79b4a6fceb bfdd: change session lookup data structure
Use simplier data structure key to avoid having to do complex and
error-prone key building (e.g. avoid expecting caller to know IPv6
scope id, interface index, vrf index etc...).

Signed-off-by: Rafael Zalamena <rzalamena@opensourcerouting.org>
2019-03-11 22:03:23 -03:00
Rafael Zalamena 2435b7defe bfdd: fix single hop IPv6 configurations
Don't assume IPv6 will always be multi hop and handle the single hop
link-local address case.

Signed-off-by: Rafael Zalamena <rzalamena@opensourcerouting.org>
2019-03-06 17:50:04 -03:00
Quentin Young 76f0146890 *: do not check XMALLOC / XCALLOC for null ret
They never return NULL

Signed-off-by: Quentin Young <qlyoung@cumulusnetworks.com>
2019-02-25 23:00:44 +00:00
Quentin Young d8729f8cb5 *: use proper bool initializers & fix comparisons
- bools should be initialized with true/false
- bools do not need to be compared

Signed-off-by: Quentin Young <qlyoung@cumulusnetworks.com>
2019-02-25 23:00:16 +00:00