Skip to content

Commit

Permalink
bgpd: Do not start BGP session if BFD profile is in shutdown state
Browse files Browse the repository at this point in the history
If we do:

```
bfd
 profile foo
  shutdown
```

The session is dropped, but immediately established again because we don't
have a proper check on BFD.

If BFD is administratively shutdown, ignore starting the session.

Fixes: FRRouting#16186

Signed-off-by: Donatas Abraitis <[email protected]>
  • Loading branch information
ton31337 committed Jun 11, 2024
1 parent d5b0c76 commit 1e3c712
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 52 deletions.
8 changes: 8 additions & 0 deletions bgpd/bgpd.c
Original file line number Diff line number Diff line change
Expand Up @@ -4507,6 +4507,14 @@ bool peer_active(struct peer *peer)
{
if (BGP_CONNECTION_SU_UNSPEC(peer->connection))
return false;

if (peer->bfd_config) {
struct bfd_session_params *session = peer->bfd_config->session;

if (session->bss.state == BSS_ADMIN_DOWN)
return false;
}

if (peer->afc[AFI_IP][SAFI_UNICAST] || peer->afc[AFI_IP][SAFI_MULTICAST]
|| peer->afc[AFI_IP][SAFI_LABELED_UNICAST]
|| peer->afc[AFI_IP][SAFI_MPLS_VPN] || peer->afc[AFI_IP][SAFI_ENCAP]
Expand Down
52 changes: 0 additions & 52 deletions lib/bfd.c
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,6 @@ DEFINE_MTYPE_STATIC(LIB, BFD_SOURCE, "BFD source cache");
* BFD protocol integration configuration.
*/

/** Events definitions. */
enum bfd_session_event {
/** Remove the BFD session configuration. */
BSE_UNINSTALL,
/** Install the BFD session configuration. */
BSE_INSTALL,
};

/**
* BFD source selection result cache.
*
Expand All @@ -57,50 +49,6 @@ struct bfd_source_cache {
};
SLIST_HEAD(bfd_source_list, bfd_source_cache);

/**
* Data structure to do the necessary tricks to hide the BFD protocol
* integration internals.
*/
struct bfd_session_params {
/** Contains the session parameters and more. */
struct bfd_session_arg args;
/** Contains the session state. */
struct bfd_session_status bss;
/** Protocol implementation status update callback. */
bsp_status_update updatecb;
/** Protocol implementation custom data pointer. */
void *arg;

/**
* Next event.
*
* This variable controls what action to execute when the command batch
* finishes. Normally we'd use `event_add_event` value, however since
* that function is going to be called multiple times and the value
* might be different we'll use this variable to keep track of it.
*/
enum bfd_session_event lastev;
/**
* BFD session configuration event.
*
* Multiple actions might be asked during a command batch (either via
* configuration load or northbound batch), so we'll use this to
* install/uninstall the BFD session parameters only once.
*/
struct event *installev;

/** BFD session installation state. */
bool installed;

/** Automatic source selection. */
bool auto_source;
/** Currently selected source. */
struct bfd_source_cache *source_cache;

/** Global BFD paramaters list. */
TAILQ_ENTRY(bfd_session_params) entry;
};

struct bfd_sessions_global {
/**
* Global BFD session parameters list for (re)installation and update
Expand Down
52 changes: 52 additions & 0 deletions lib/bfd.h
Original file line number Diff line number Diff line change
Expand Up @@ -417,6 +417,58 @@ struct bfd_session_arg {
uint32_t detection_multiplier;
};

/** Events definitions. */
enum bfd_session_event {
/** Remove the BFD session configuration. */
BSE_UNINSTALL,
/** Install the BFD session configuration. */
BSE_INSTALL,
};

/**
* Data structure to do the necessary tricks to hide the BFD protocol
* integration internals.
*/
struct bfd_session_params {
/** Contains the session parameters and more. */
struct bfd_session_arg args;
/** Contains the session state. */
struct bfd_session_status bss;
/** Protocol implementation status update callback. */
bsp_status_update updatecb;
/** Protocol implementation custom data pointer. */
void *arg;

/**
* Next event.
*
* This variable controls what action to execute when the command batch
* finishes. Normally we'd use `event_add_event` value, however since
* that function is going to be called multiple times and the value
* might be different we'll use this variable to keep track of it.
*/
enum bfd_session_event lastev;
/**
* BFD session configuration event.
*
* Multiple actions might be asked during a command batch (either via
* configuration load or northbound batch), so we'll use this to
* install/uninstall the BFD session parameters only once.
*/
struct event *installev;

/** BFD session installation state. */
bool installed;

/** Automatic source selection. */
bool auto_source;
/** Currently selected source. */
struct bfd_source_cache *source_cache;

/** Global BFD paramaters list. */
TAILQ_ENTRY(bfd_session_params) entry;
};

/**
* Send a message to BFD daemon through the zebra client.
*
Expand Down

0 comments on commit 1e3c712

Please sign in to comment.