]> git.ipfire.org Git - thirdparty/bird.git/blame - proto/bfd/bfd.h
BFD: split of v4/v6 sockets
[thirdparty/bird.git] / proto / bfd / bfd.h
CommitLineData
6a8d3f1c
OZ
1/*
2 * BIRD -- Bidirectional Forwarding Detection (BFD)
3 *
4 * Can be freely distributed and used under the terms of the GNU GPL.
5 */
bf139664
OZ
6
7#ifndef _BIRD_BFD_H_
8#define _BIRD_BFD_H_
9
6a8d3f1c
OZ
10#include <pthread.h>
11
12#include "nest/bird.h"
13#include "nest/cli.h"
14#include "nest/iface.h"
15#include "nest/protocol.h"
16#include "nest/route.h"
17#include "conf/conf.h"
18#include "lib/hash.h"
19#include "lib/resource.h"
20#include "lib/socket.h"
21#include "lib/string.h"
22
1ec52253 23#include "nest/bfd.h"
6a8d3f1c
OZ
24#include "io.h"
25
26
bf139664
OZ
27#define BFD_CONTROL_PORT 3784
28#define BFD_ECHO_PORT 3785
29#define BFD_MULTI_CTL_PORT 4784
30
41f8bf57
OZ
31#define BFD_DEFAULT_MIN_RX_INT (10 MS_)
32#define BFD_DEFAULT_MIN_TX_INT (100 MS_)
33#define BFD_DEFAULT_IDLE_TX_INT (1 S_)
bf139664
OZ
34#define BFD_DEFAULT_MULTIPLIER 5
35
36
1ec52253
OZ
37struct bfd_iface_config;
38
bf139664
OZ
39struct bfd_config
40{
41 struct proto_config c;
1ec52253
OZ
42 list patt_list; /* List of iface configs (struct bfd_iface_config) */
43 list neigh_list; /* List of configured neighbors (struct bfd_neighbor) */
44 struct bfd_iface_config *multihop; /* Multihop pseudoiface config */
bf139664
OZ
45};
46
1ec52253 47struct bfd_iface_config
bf139664 48{
1ec52253 49 struct iface_patt i;
bf139664
OZ
50 u32 min_rx_int;
51 u32 min_tx_int;
52 u32 idle_tx_int;
53 u8 multiplier;
bf139664
OZ
54 u8 passive;
55};
56
57struct bfd_neighbor
58{
59 node n;
60 ip_addr addr;
61 ip_addr local;
62 struct iface *iface;
bf139664 63
1ec52253
OZ
64 struct neighbor *neigh;
65 struct bfd_request *req;
66
67 u8 multihop;
68 u8 active;
bf139664
OZ
69};
70
71struct bfd_proto
72{
73 struct proto p;
6a8d3f1c
OZ
74 struct birdloop *loop;
75 pool *tpool;
76 pthread_spinlock_t lock;
1ec52253 77 node bfd_node;
bf139664
OZ
78
79 slab *session_slab;
80 HASH(struct bfd_session) session_hash_id;
81 HASH(struct bfd_session) session_hash_ip;
82
6a8d3f1c
OZ
83 sock *notify_rs;
84 sock *notify_ws;
85 list notify_list;
86
5b218c3d
MM
87 sock *rx4_1;
88 sock *rx6_1;
89 sock *rx4_m;
90 sock *rx6_m;
1ec52253 91 list iface_list;
bf139664
OZ
92};
93
1ec52253 94struct bfd_iface
bf139664
OZ
95{
96 node n;
1ec52253
OZ
97 ip_addr local;
98 struct iface *iface;
99 struct bfd_iface_config *cf;
100 struct bfd_proto *bfd;
101
bf139664
OZ
102 sock *sk;
103 u32 uc;
1ec52253 104 u8 changed;
bf139664
OZ
105};
106
107struct bfd_session
108{
109 node n;
6a8d3f1c 110 ip_addr addr; /* Address of session */
1ec52253 111 struct bfd_iface *ifa; /* Iface associated with session */
bf139664
OZ
112 struct bfd_session *next_id; /* Next in bfd.session_hash_id */
113 struct bfd_session *next_ip; /* Next in bfd.session_hash_ip */
114
1ec52253 115 u8 opened_unused;
6a8d3f1c 116 u8 passive;
bf139664
OZ
117 u8 poll_active;
118 u8 poll_scheduled;
119
120 u8 loc_state;
121 u8 rem_state;
122 u8 loc_diag;
6a8d3f1c 123 u8 rem_diag;
bf139664
OZ
124 u32 loc_id; /* Local session ID (local discriminator) */
125 u32 rem_id; /* Remote session ID (remote discriminator) */
126 u32 des_min_tx_int; /* Desired min rx interval, local option */
127 u32 des_min_tx_new; /* Used for des_min_tx_int change */
128 u32 req_min_rx_int; /* Required min tx interval, local option */
129 u32 req_min_rx_new; /* Used for req_min_rx_int change */
130 u32 rem_min_tx_int; /* Last received des_min_tx_int */
131 u32 rem_min_rx_int; /* Last received req_min_rx_int */
132 u8 demand_mode; /* Currently unused */
133 u8 rem_demand_mode;
134 u8 detect_mult; /* Announced detect_mult, local option */
135 u8 rem_detect_mult; /* Last received detect_mult */
136
6a8d3f1c
OZ
137 btime last_tx; /* Time of last sent periodic control packet */
138 btime last_rx; /* Time of last received valid control packet */
bf139664
OZ
139
140 timer2 *tx_timer; /* Periodic control packet timer */
141 timer2 *hold_timer; /* Timer for session down detection time */
6a8d3f1c 142
1ec52253
OZ
143 list request_list; /* List of client requests (struct bfd_request) */
144 bird_clock_t last_state_change; /* Time of last state change */
145 u8 notify_running; /* 1 if notify hooks are running */
bf139664
OZ
146};
147
148
0e175f9f 149extern const char *bfd_state_names[];
bf139664
OZ
150
151#define BFD_STATE_ADMIN_DOWN 0
152#define BFD_STATE_DOWN 1
153#define BFD_STATE_INIT 2
154#define BFD_STATE_UP 3
155
156#define BFD_DIAG_NOTHING 0
157#define BFD_DIAG_TIMEOUT 1
158#define BFD_DIAG_ECHO_FAILED 2
159#define BFD_DIAG_NEIGHBOR_DOWN 3
160#define BFD_DIAG_FWD_RESET 4
161#define BFD_DIAG_PATH_DOWN 5
162#define BFD_DIAG_C_PATH_DOWN 6
163#define BFD_DIAG_ADMIN_DOWN 7
164#define BFD_DIAG_RC_PATH_DOWN 8
165
166#define BFD_POLL_TX 1
167#define BFD_POLL_RX 2
168
0e175f9f 169#define BFD_FLAGS 0x3f
6a8d3f1c
OZ
170#define BFD_FLAG_POLL (1 << 5)
171#define BFD_FLAG_FINAL (1 << 4)
172#define BFD_FLAG_CPI (1 << 3)
173#define BFD_FLAG_AP (1 << 2)
174#define BFD_FLAG_DEMAND (1 << 1)
175#define BFD_FLAG_MULTIPOINT (1 << 0)
176
177
178static inline void bfd_lock_sessions(struct bfd_proto *p) { pthread_spin_lock(&p->lock); }
179static inline void bfd_unlock_sessions(struct bfd_proto *p) { pthread_spin_unlock(&p->lock); }
180
181/* bfd.c */
182struct bfd_session * bfd_find_session_by_id(struct bfd_proto *p, u32 id);
183struct bfd_session * bfd_find_session_by_addr(struct bfd_proto *p, ip_addr addr);
184void bfd_session_process_ctl(struct bfd_session *s, u8 flags, u32 old_tx_int, u32 old_rx_int);
185void bfd_show_sessions(struct proto *P);
bf139664 186
6a8d3f1c
OZ
187/* packets.c */
188void bfd_send_ctl(struct bfd_proto *p, struct bfd_session *s, int final);
5b218c3d 189sock * bfd_open_rx_sk(struct bfd_proto *p, int multihop, int inet_version);
1ec52253 190sock * bfd_open_tx_sk(struct bfd_proto *p, ip_addr local, struct iface *ifa);
bf139664
OZ
191
192
6a8d3f1c 193#endif /* _BIRD_BFD_H_ */