Commit Graph

62 Commits

Author SHA1 Message Date
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
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
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
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
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
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
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
Donatas Abraitis
2dbe669bdf :* Convert prefix2str to %pFX
Signed-off-by: Donatas Abraitis <donatas.abraitis@gmail.com>
2020-10-22 09:07:41 +03: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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
Donald Sharp
a36898e755
Revert "Ospf missing interface handling 2" 2019-06-23 19:46:39 -04:00
Philippe Guibert
a41c4e1b1f *: change interface structure, from vrf_id to vrf
Field vrf_id is replaced by the pointer of the struct vrf *.
For that all other code referencing to (interface)->vrf_id is replaced.
This work should not change the behaviour.
It is just a continuation work toward having an interface API handling
vrf pointer only.

some new generic functions are created in vrf:
vrf_to_id, vrf_to_name,

a zebra function is also created:
zvrf_info_lookup

an ospf function is also created:
ospf_lookup_by_vrf

it is to be noted that now that interface has a vrf pointer, some more
optimisations could be thought through all the rest of the code. as
example, many structure store the vrf_id. those structures could get
the exact vrf structure if inherited from an interface vrf context.

Signed-off-by: Philippe Guibert <philippe.guibert@6wind.com>
2019-06-12 14:10:28 +02:00
Philippe Guibert
da85f5e038 lib, bgpd, ospfd, pimd, zebra, rip, ripng, bfd: change if_update_to_new_vrf() api
vrf_id parameter is replaced with struct vrf * parameter. It is
needed to create vrf structure before entering in the fuction.
an error is generated in case the vrf parameter is missing.

Signed-off-by: Philippe Guibert <philippe.guibert@6wind.com>
2019-06-12 08:37:58 +02: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
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
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
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
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
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
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
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
Rafael Zalamena
d245e522f0 bfdd: implement session interface observer
Allow `bfdd` to configure inexisting interfaces / VRF and only activate
them once the interface/VRF start existing. This implementation doesn't
handle dynamic VRFs yet.

Signed-off-by: Rafael Zalamena <rzalamena@opensourcerouting.org>
2019-02-14 14:18:23 -02:00
Rafael Zalamena
b333abc295 bfdd: refactor session lookup
Use internal data to lookup sessions. This approach has two main
advantages:

  * it uses less memory because it doesn't use strings for interface /
    vrf, it uses OS indexes instead;
  * prepares code to support VRF;

Signed-off-by: Rafael Zalamena <rzalamena@opensourcerouting.org>
2019-02-14 14:17:29 -02:00