2013-09-16 21:57:40 +00:00
|
|
|
/*
|
|
|
|
* BIRD -- Bidirectional Forwarding Detection (BFD)
|
|
|
|
*
|
|
|
|
* Can be freely distributed and used under the terms of the GNU GPL.
|
|
|
|
*/
|
2013-09-10 10:09:36 +00:00
|
|
|
|
|
|
|
#ifndef _BIRD_BFD_H_
|
|
|
|
#define _BIRD_BFD_H_
|
|
|
|
|
2013-09-16 21:57:40 +00:00
|
|
|
#include <pthread.h>
|
|
|
|
|
|
|
|
#include "nest/bird.h"
|
|
|
|
#include "nest/cli.h"
|
|
|
|
#include "nest/iface.h"
|
|
|
|
#include "nest/protocol.h"
|
2023-10-29 15:25:01 +00:00
|
|
|
#include "nest/route.h"
|
2016-10-30 22:51:23 +00:00
|
|
|
#include "nest/password.h"
|
2013-09-16 21:57:40 +00:00
|
|
|
#include "conf/conf.h"
|
|
|
|
#include "lib/hash.h"
|
2021-06-19 18:50:18 +00:00
|
|
|
#include "lib/io-loop.h"
|
2013-09-16 21:57:40 +00:00
|
|
|
#include "lib/resource.h"
|
|
|
|
#include "lib/socket.h"
|
|
|
|
#include "lib/string.h"
|
|
|
|
|
2013-11-19 21:33:48 +00:00
|
|
|
#include "nest/bfd.h"
|
2013-09-16 21:57:40 +00:00
|
|
|
|
|
|
|
|
2013-09-10 10:09:36 +00:00
|
|
|
#define BFD_CONTROL_PORT 3784
|
|
|
|
#define BFD_ECHO_PORT 3785
|
|
|
|
#define BFD_MULTI_CTL_PORT 4784
|
|
|
|
|
2013-11-22 20:59:43 +00:00
|
|
|
#define BFD_DEFAULT_MIN_RX_INT (10 MS_)
|
|
|
|
#define BFD_DEFAULT_MIN_TX_INT (100 MS_)
|
|
|
|
#define BFD_DEFAULT_IDLE_TX_INT (1 S_)
|
2013-09-10 10:09:36 +00:00
|
|
|
#define BFD_DEFAULT_MULTIPLIER 5
|
|
|
|
|
|
|
|
|
2013-11-19 21:33:48 +00:00
|
|
|
struct bfd_iface_config;
|
|
|
|
|
2013-09-10 10:09:36 +00:00
|
|
|
struct bfd_config
|
|
|
|
{
|
|
|
|
struct proto_config c;
|
2013-11-19 21:33:48 +00:00
|
|
|
list patt_list; /* List of iface configs (struct bfd_iface_config) */
|
|
|
|
list neigh_list; /* List of configured neighbors (struct bfd_neighbor) */
|
|
|
|
struct bfd_iface_config *multihop; /* Multihop pseudoiface config */
|
2020-01-28 17:07:25 +00:00
|
|
|
u8 accept_ipv4;
|
|
|
|
u8 accept_ipv6;
|
|
|
|
u8 accept_direct;
|
|
|
|
u8 accept_multihop;
|
2022-04-07 17:33:40 +00:00
|
|
|
u8 strict_bind;
|
2013-09-10 10:09:36 +00:00
|
|
|
};
|
|
|
|
|
2013-11-19 21:33:48 +00:00
|
|
|
struct bfd_iface_config
|
2013-09-10 10:09:36 +00:00
|
|
|
{
|
2013-11-19 21:33:48 +00:00
|
|
|
struct iface_patt i;
|
2013-09-10 10:09:36 +00:00
|
|
|
u32 min_rx_int;
|
|
|
|
u32 min_tx_int;
|
|
|
|
u32 idle_tx_int;
|
|
|
|
u8 multiplier;
|
|
|
|
u8 passive;
|
2016-10-30 22:51:23 +00:00
|
|
|
u8 auth_type; /* Authentication type (BFD_AUTH_*) */
|
|
|
|
list *passwords; /* Passwords for authentication */
|
2013-09-10 10:09:36 +00:00
|
|
|
};
|
|
|
|
|
2020-11-08 14:33:22 +00:00
|
|
|
struct bfd_session_config
|
|
|
|
{
|
|
|
|
u32 min_rx_int;
|
|
|
|
u32 min_tx_int;
|
|
|
|
u32 idle_tx_int;
|
|
|
|
u8 multiplier;
|
|
|
|
u8 passive;
|
|
|
|
};
|
|
|
|
|
2013-09-10 10:09:36 +00:00
|
|
|
struct bfd_neighbor
|
|
|
|
{
|
|
|
|
node n;
|
|
|
|
ip_addr addr;
|
|
|
|
ip_addr local;
|
|
|
|
struct iface *iface;
|
|
|
|
|
2013-11-19 21:33:48 +00:00
|
|
|
struct neighbor *neigh;
|
|
|
|
struct bfd_request *req;
|
|
|
|
|
|
|
|
u8 multihop;
|
|
|
|
u8 active;
|
2013-09-10 10:09:36 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
struct bfd_proto
|
|
|
|
{
|
|
|
|
struct proto p;
|
2021-06-19 18:50:18 +00:00
|
|
|
|
2013-09-16 21:57:40 +00:00
|
|
|
pthread_spinlock_t lock;
|
2021-06-19 18:50:18 +00:00
|
|
|
|
|
|
|
pool *tpool;
|
|
|
|
|
2013-11-19 21:33:48 +00:00
|
|
|
node bfd_node;
|
2013-09-10 10:09:36 +00:00
|
|
|
|
|
|
|
slab *session_slab;
|
|
|
|
HASH(struct bfd_session) session_hash_id;
|
|
|
|
HASH(struct bfd_session) session_hash_ip;
|
|
|
|
|
2022-09-20 15:14:31 +00:00
|
|
|
event notify_event;
|
2013-09-16 21:57:40 +00:00
|
|
|
list notify_list;
|
|
|
|
|
2016-01-07 10:29:05 +00:00
|
|
|
sock *rx4_1;
|
|
|
|
sock *rx6_1;
|
|
|
|
sock *rx4_m;
|
|
|
|
sock *rx6_m;
|
2013-11-19 21:33:48 +00:00
|
|
|
list iface_list;
|
2013-09-10 10:09:36 +00:00
|
|
|
};
|
|
|
|
|
2013-11-19 21:33:48 +00:00
|
|
|
struct bfd_iface
|
2013-09-10 10:09:36 +00:00
|
|
|
{
|
|
|
|
node n;
|
2013-11-19 21:33:48 +00:00
|
|
|
ip_addr local;
|
|
|
|
struct iface *iface;
|
|
|
|
struct bfd_iface_config *cf;
|
|
|
|
struct bfd_proto *bfd;
|
|
|
|
|
2013-09-10 10:09:36 +00:00
|
|
|
sock *sk;
|
2022-04-07 17:33:40 +00:00
|
|
|
sock *rx;
|
2013-09-10 10:09:36 +00:00
|
|
|
u32 uc;
|
2013-11-19 21:33:48 +00:00
|
|
|
u8 changed;
|
2013-09-10 10:09:36 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
struct bfd_session
|
|
|
|
{
|
|
|
|
node n;
|
2013-09-16 21:57:40 +00:00
|
|
|
ip_addr addr; /* Address of session */
|
2013-11-19 21:33:48 +00:00
|
|
|
struct bfd_iface *ifa; /* Iface associated with session */
|
2013-09-10 10:09:36 +00:00
|
|
|
struct bfd_session *next_id; /* Next in bfd.session_hash_id */
|
|
|
|
struct bfd_session *next_ip; /* Next in bfd.session_hash_ip */
|
|
|
|
|
2013-11-19 21:33:48 +00:00
|
|
|
u8 opened_unused;
|
2013-09-16 21:57:40 +00:00
|
|
|
u8 passive;
|
2013-09-10 10:09:36 +00:00
|
|
|
u8 poll_active;
|
|
|
|
u8 poll_scheduled;
|
2016-10-30 22:51:23 +00:00
|
|
|
|
2013-09-10 10:09:36 +00:00
|
|
|
u8 loc_state;
|
|
|
|
u8 rem_state;
|
|
|
|
u8 loc_diag;
|
2013-09-16 21:57:40 +00:00
|
|
|
u8 rem_diag;
|
2013-09-10 10:09:36 +00:00
|
|
|
u32 loc_id; /* Local session ID (local discriminator) */
|
|
|
|
u32 rem_id; /* Remote session ID (remote discriminator) */
|
2020-11-08 14:33:22 +00:00
|
|
|
|
|
|
|
struct bfd_session_config cf; /* Static configuration parameters */
|
|
|
|
|
2013-09-10 10:09:36 +00:00
|
|
|
u32 des_min_tx_int; /* Desired min rx interval, local option */
|
|
|
|
u32 des_min_tx_new; /* Used for des_min_tx_int change */
|
|
|
|
u32 req_min_rx_int; /* Required min tx interval, local option */
|
|
|
|
u32 req_min_rx_new; /* Used for req_min_rx_int change */
|
|
|
|
u32 rem_min_tx_int; /* Last received des_min_tx_int */
|
|
|
|
u32 rem_min_rx_int; /* Last received req_min_rx_int */
|
|
|
|
u8 demand_mode; /* Currently unused */
|
|
|
|
u8 rem_demand_mode;
|
|
|
|
u8 detect_mult; /* Announced detect_mult, local option */
|
|
|
|
u8 rem_detect_mult; /* Last received detect_mult */
|
|
|
|
|
2021-01-10 14:29:02 +00:00
|
|
|
uint ifindex; /* Iface index, for hashing in bfd.session_hash_ip */
|
2013-09-16 21:57:40 +00:00
|
|
|
btime last_tx; /* Time of last sent periodic control packet */
|
|
|
|
btime last_rx; /* Time of last received valid control packet */
|
2013-09-10 10:09:36 +00:00
|
|
|
|
2017-11-28 16:43:20 +00:00
|
|
|
timer *tx_timer; /* Periodic control packet timer */
|
|
|
|
timer *hold_timer; /* Timer for session down detection time */
|
2013-09-16 21:57:40 +00:00
|
|
|
|
2013-11-19 21:33:48 +00:00
|
|
|
list request_list; /* List of client requests (struct bfd_request) */
|
2017-06-06 14:47:30 +00:00
|
|
|
btime last_state_change; /* Time of last state change */
|
2016-10-30 22:51:23 +00:00
|
|
|
|
|
|
|
u8 rx_csn_known; /* Received crypto sequence number is known */
|
|
|
|
u32 rx_csn; /* Last received crypto sequence number */
|
|
|
|
u32 tx_csn; /* Last transmitted crypto sequence number */
|
|
|
|
u32 tx_csn_time; /* Timestamp of last tx_csn change */
|
2013-09-10 10:09:36 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2013-10-05 18:12:28 +00:00
|
|
|
extern const char *bfd_state_names[];
|
2013-09-10 10:09:36 +00:00
|
|
|
|
|
|
|
#define BFD_STATE_ADMIN_DOWN 0
|
|
|
|
#define BFD_STATE_DOWN 1
|
|
|
|
#define BFD_STATE_INIT 2
|
|
|
|
#define BFD_STATE_UP 3
|
|
|
|
|
|
|
|
#define BFD_DIAG_NOTHING 0
|
|
|
|
#define BFD_DIAG_TIMEOUT 1
|
|
|
|
#define BFD_DIAG_ECHO_FAILED 2
|
|
|
|
#define BFD_DIAG_NEIGHBOR_DOWN 3
|
|
|
|
#define BFD_DIAG_FWD_RESET 4
|
|
|
|
#define BFD_DIAG_PATH_DOWN 5
|
|
|
|
#define BFD_DIAG_C_PATH_DOWN 6
|
|
|
|
#define BFD_DIAG_ADMIN_DOWN 7
|
|
|
|
#define BFD_DIAG_RC_PATH_DOWN 8
|
|
|
|
|
|
|
|
#define BFD_POLL_TX 1
|
|
|
|
#define BFD_POLL_RX 2
|
|
|
|
|
2013-10-05 18:12:28 +00:00
|
|
|
#define BFD_FLAGS 0x3f
|
2013-09-16 21:57:40 +00:00
|
|
|
#define BFD_FLAG_POLL (1 << 5)
|
|
|
|
#define BFD_FLAG_FINAL (1 << 4)
|
|
|
|
#define BFD_FLAG_CPI (1 << 3)
|
|
|
|
#define BFD_FLAG_AP (1 << 2)
|
|
|
|
#define BFD_FLAG_DEMAND (1 << 1)
|
|
|
|
#define BFD_FLAG_MULTIPOINT (1 << 0)
|
|
|
|
|
2016-10-30 22:51:23 +00:00
|
|
|
#define BFD_AUTH_NONE 0
|
|
|
|
#define BFD_AUTH_SIMPLE 1
|
|
|
|
#define BFD_AUTH_KEYED_MD5 2
|
|
|
|
#define BFD_AUTH_METICULOUS_KEYED_MD5 3
|
|
|
|
#define BFD_AUTH_KEYED_SHA1 4
|
|
|
|
#define BFD_AUTH_METICULOUS_KEYED_SHA1 5
|
|
|
|
|
|
|
|
extern const u8 bfd_auth_type_to_hash_alg[];
|
|
|
|
|
2013-09-16 21:57:40 +00:00
|
|
|
|
|
|
|
static inline void bfd_lock_sessions(struct bfd_proto *p) { pthread_spin_lock(&p->lock); }
|
|
|
|
static inline void bfd_unlock_sessions(struct bfd_proto *p) { pthread_spin_unlock(&p->lock); }
|
|
|
|
|
|
|
|
/* bfd.c */
|
|
|
|
struct bfd_session * bfd_find_session_by_id(struct bfd_proto *p, u32 id);
|
2021-01-10 14:29:02 +00:00
|
|
|
struct bfd_session * bfd_find_session_by_addr(struct bfd_proto *p, ip_addr addr, uint ifindex);
|
2013-09-16 21:57:40 +00:00
|
|
|
void bfd_session_process_ctl(struct bfd_session *s, u8 flags, u32 old_tx_int, u32 old_rx_int);
|
|
|
|
void bfd_show_sessions(struct proto *P);
|
2013-09-10 10:09:36 +00:00
|
|
|
|
2013-09-16 21:57:40 +00:00
|
|
|
/* packets.c */
|
|
|
|
void bfd_send_ctl(struct bfd_proto *p, struct bfd_session *s, int final);
|
2016-01-07 10:29:05 +00:00
|
|
|
sock * bfd_open_rx_sk(struct bfd_proto *p, int multihop, int inet_version);
|
2022-04-07 17:33:40 +00:00
|
|
|
sock * bfd_open_rx_sk_bound(struct bfd_proto *p, ip_addr local, struct iface *ifa);
|
2013-11-19 21:33:48 +00:00
|
|
|
sock * bfd_open_tx_sk(struct bfd_proto *p, ip_addr local, struct iface *ifa);
|
2013-09-10 10:09:36 +00:00
|
|
|
|
|
|
|
|
2013-09-16 21:57:40 +00:00
|
|
|
#endif /* _BIRD_BFD_H_ */
|