]>
Commit | Line | Data |
---|---|---|
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" | |
e03dc6a9 | 17 | #include "nest/password.h" |
6a8d3f1c OZ |
18 | #include "conf/conf.h" |
19 | #include "lib/hash.h" | |
20 | #include "lib/resource.h" | |
21 | #include "lib/socket.h" | |
22 | #include "lib/string.h" | |
23 | ||
1ec52253 | 24 | #include "nest/bfd.h" |
6a8d3f1c OZ |
25 | #include "io.h" |
26 | ||
27 | ||
bf139664 OZ |
28 | #define BFD_CONTROL_PORT 3784 |
29 | #define BFD_ECHO_PORT 3785 | |
30 | #define BFD_MULTI_CTL_PORT 4784 | |
31 | ||
41f8bf57 OZ |
32 | #define BFD_DEFAULT_MIN_RX_INT (10 MS_) |
33 | #define BFD_DEFAULT_MIN_TX_INT (100 MS_) | |
34 | #define BFD_DEFAULT_IDLE_TX_INT (1 S_) | |
bf139664 OZ |
35 | #define BFD_DEFAULT_MULTIPLIER 5 |
36 | ||
37 | ||
1ec52253 OZ |
38 | struct bfd_iface_config; |
39 | ||
bf139664 OZ |
40 | struct bfd_config |
41 | { | |
42 | struct proto_config c; | |
1ec52253 OZ |
43 | list patt_list; /* List of iface configs (struct bfd_iface_config) */ |
44 | list neigh_list; /* List of configured neighbors (struct bfd_neighbor) */ | |
45 | struct bfd_iface_config *multihop; /* Multihop pseudoiface config */ | |
7f9adafc OZ |
46 | u8 accept_ipv4; |
47 | u8 accept_ipv6; | |
48 | u8 accept_direct; | |
49 | u8 accept_multihop; | |
692055e3 | 50 | u8 strict_bind; |
bf139664 OZ |
51 | }; |
52 | ||
1ec52253 | 53 | struct bfd_iface_config |
bf139664 | 54 | { |
1ec52253 | 55 | struct iface_patt i; |
bf139664 OZ |
56 | u32 min_rx_int; |
57 | u32 min_tx_int; | |
58 | u32 idle_tx_int; | |
59 | u8 multiplier; | |
bf139664 | 60 | u8 passive; |
e03dc6a9 OZ |
61 | u8 auth_type; /* Authentication type (BFD_AUTH_*) */ |
62 | list *passwords; /* Passwords for authentication */ | |
bf139664 OZ |
63 | }; |
64 | ||
9d3fc306 OZ |
65 | struct bfd_session_config |
66 | { | |
67 | u32 min_rx_int; | |
68 | u32 min_tx_int; | |
69 | u32 idle_tx_int; | |
70 | u8 multiplier; | |
71 | u8 passive; | |
e6dbde68 KK |
72 | u8 auth_type; /* Authentication type (BFD_AUTH_*) */ |
73 | list *passwords; /* Passwords for authentication */ | |
9d3fc306 OZ |
74 | }; |
75 | ||
bf139664 OZ |
76 | struct bfd_neighbor |
77 | { | |
78 | node n; | |
79 | ip_addr addr; | |
80 | ip_addr local; | |
81 | struct iface *iface; | |
bf139664 | 82 | |
1ec52253 OZ |
83 | struct neighbor *neigh; |
84 | struct bfd_request *req; | |
85 | ||
86 | u8 multihop; | |
87 | u8 active; | |
bf139664 OZ |
88 | }; |
89 | ||
90 | struct bfd_proto | |
91 | { | |
92 | struct proto p; | |
6a8d3f1c OZ |
93 | struct birdloop *loop; |
94 | pool *tpool; | |
95 | pthread_spinlock_t lock; | |
1ec52253 | 96 | node bfd_node; |
bf139664 OZ |
97 | |
98 | slab *session_slab; | |
99 | HASH(struct bfd_session) session_hash_id; | |
100 | HASH(struct bfd_session) session_hash_ip; | |
101 | ||
6a8d3f1c OZ |
102 | sock *notify_rs; |
103 | sock *notify_ws; | |
104 | list notify_list; | |
105 | ||
5b218c3d JMM |
106 | sock *rx4_1; |
107 | sock *rx6_1; | |
108 | sock *rx4_m; | |
109 | sock *rx6_m; | |
1ec52253 | 110 | list iface_list; |
bf139664 OZ |
111 | }; |
112 | ||
1ec52253 | 113 | struct bfd_iface |
bf139664 OZ |
114 | { |
115 | node n; | |
1ec52253 OZ |
116 | ip_addr local; |
117 | struct iface *iface; | |
118 | struct bfd_iface_config *cf; | |
119 | struct bfd_proto *bfd; | |
120 | ||
bf139664 | 121 | sock *sk; |
692055e3 | 122 | sock *rx; |
bf139664 | 123 | u32 uc; |
1ec52253 | 124 | u8 changed; |
bf139664 OZ |
125 | }; |
126 | ||
127 | struct bfd_session | |
128 | { | |
129 | node n; | |
6a8d3f1c | 130 | ip_addr addr; /* Address of session */ |
1ec52253 | 131 | struct bfd_iface *ifa; /* Iface associated with session */ |
bf139664 OZ |
132 | struct bfd_session *next_id; /* Next in bfd.session_hash_id */ |
133 | struct bfd_session *next_ip; /* Next in bfd.session_hash_ip */ | |
134 | ||
1ec52253 | 135 | u8 opened_unused; |
6a8d3f1c | 136 | u8 passive; |
bf139664 OZ |
137 | u8 poll_active; |
138 | u8 poll_scheduled; | |
e03dc6a9 | 139 | |
bf139664 OZ |
140 | u8 loc_state; |
141 | u8 rem_state; | |
142 | u8 loc_diag; | |
6a8d3f1c | 143 | u8 rem_diag; |
bf139664 OZ |
144 | u32 loc_id; /* Local session ID (local discriminator) */ |
145 | u32 rem_id; /* Remote session ID (remote discriminator) */ | |
9d3fc306 OZ |
146 | |
147 | struct bfd_session_config cf; /* Static configuration parameters */ | |
148 | ||
bf139664 OZ |
149 | u32 des_min_tx_int; /* Desired min rx interval, local option */ |
150 | u32 des_min_tx_new; /* Used for des_min_tx_int change */ | |
151 | u32 req_min_rx_int; /* Required min tx interval, local option */ | |
152 | u32 req_min_rx_new; /* Used for req_min_rx_int change */ | |
153 | u32 rem_min_tx_int; /* Last received des_min_tx_int */ | |
154 | u32 rem_min_rx_int; /* Last received req_min_rx_int */ | |
155 | u8 demand_mode; /* Currently unused */ | |
156 | u8 rem_demand_mode; | |
157 | u8 detect_mult; /* Announced detect_mult, local option */ | |
158 | u8 rem_detect_mult; /* Last received detect_mult */ | |
159 | ||
910adaa0 | 160 | uint ifindex; /* Iface index, for hashing in bfd.session_hash_ip */ |
6a8d3f1c OZ |
161 | btime last_tx; /* Time of last sent periodic control packet */ |
162 | btime last_rx; /* Time of last received valid control packet */ | |
bf139664 | 163 | |
a6f79ca5 OZ |
164 | timer *tx_timer; /* Periodic control packet timer */ |
165 | timer *hold_timer; /* Timer for session down detection time */ | |
6a8d3f1c | 166 | |
1ec52253 | 167 | list request_list; /* List of client requests (struct bfd_request) */ |
f047271c | 168 | btime last_state_change; /* Time of last state change */ |
1ec52253 | 169 | u8 notify_running; /* 1 if notify hooks are running */ |
e03dc6a9 OZ |
170 | |
171 | u8 rx_csn_known; /* Received crypto sequence number is known */ | |
172 | u32 rx_csn; /* Last received crypto sequence number */ | |
173 | u32 tx_csn; /* Last transmitted crypto sequence number */ | |
174 | u32 tx_csn_time; /* Timestamp of last tx_csn change */ | |
bf139664 OZ |
175 | }; |
176 | ||
26dd61ee OZ |
177 | struct bfd_show_sessions_cmd { |
178 | net_addr address; | |
179 | struct iface *iface; | |
180 | struct symbol *name; | |
181 | u8 verbose; | |
182 | u8 ipv4; | |
183 | u8 ipv6; | |
184 | u8 direct; | |
185 | u8 multihop; | |
186 | }; | |
187 | ||
bf139664 | 188 | |
0e175f9f | 189 | extern const char *bfd_state_names[]; |
bf139664 OZ |
190 | |
191 | #define BFD_STATE_ADMIN_DOWN 0 | |
192 | #define BFD_STATE_DOWN 1 | |
193 | #define BFD_STATE_INIT 2 | |
194 | #define BFD_STATE_UP 3 | |
195 | ||
196 | #define BFD_DIAG_NOTHING 0 | |
197 | #define BFD_DIAG_TIMEOUT 1 | |
198 | #define BFD_DIAG_ECHO_FAILED 2 | |
199 | #define BFD_DIAG_NEIGHBOR_DOWN 3 | |
200 | #define BFD_DIAG_FWD_RESET 4 | |
201 | #define BFD_DIAG_PATH_DOWN 5 | |
202 | #define BFD_DIAG_C_PATH_DOWN 6 | |
203 | #define BFD_DIAG_ADMIN_DOWN 7 | |
204 | #define BFD_DIAG_RC_PATH_DOWN 8 | |
205 | ||
206 | #define BFD_POLL_TX 1 | |
207 | #define BFD_POLL_RX 2 | |
208 | ||
0e175f9f | 209 | #define BFD_FLAGS 0x3f |
6a8d3f1c OZ |
210 | #define BFD_FLAG_POLL (1 << 5) |
211 | #define BFD_FLAG_FINAL (1 << 4) | |
212 | #define BFD_FLAG_CPI (1 << 3) | |
213 | #define BFD_FLAG_AP (1 << 2) | |
214 | #define BFD_FLAG_DEMAND (1 << 1) | |
215 | #define BFD_FLAG_MULTIPOINT (1 << 0) | |
216 | ||
e03dc6a9 OZ |
217 | #define BFD_AUTH_NONE 0 |
218 | #define BFD_AUTH_SIMPLE 1 | |
219 | #define BFD_AUTH_KEYED_MD5 2 | |
220 | #define BFD_AUTH_METICULOUS_KEYED_MD5 3 | |
221 | #define BFD_AUTH_KEYED_SHA1 4 | |
222 | #define BFD_AUTH_METICULOUS_KEYED_SHA1 5 | |
223 | ||
224 | extern const u8 bfd_auth_type_to_hash_alg[]; | |
225 | ||
6a8d3f1c OZ |
226 | |
227 | static inline void bfd_lock_sessions(struct bfd_proto *p) { pthread_spin_lock(&p->lock); } | |
228 | static inline void bfd_unlock_sessions(struct bfd_proto *p) { pthread_spin_unlock(&p->lock); } | |
229 | ||
230 | /* bfd.c */ | |
231 | struct bfd_session * bfd_find_session_by_id(struct bfd_proto *p, u32 id); | |
910adaa0 | 232 | struct bfd_session * bfd_find_session_by_addr(struct bfd_proto *p, ip_addr addr, uint ifindex); |
6a8d3f1c | 233 | void bfd_session_process_ctl(struct bfd_session *s, u8 flags, u32 old_tx_int, u32 old_rx_int); |
26dd61ee | 234 | void bfd_show_sessions(struct proto *P, struct bfd_show_sessions_cmd *args); |
bf139664 | 235 | |
6a8d3f1c OZ |
236 | /* packets.c */ |
237 | void bfd_send_ctl(struct bfd_proto *p, struct bfd_session *s, int final); | |
5b218c3d | 238 | sock * bfd_open_rx_sk(struct bfd_proto *p, int multihop, int inet_version); |
692055e3 | 239 | sock * bfd_open_rx_sk_bound(struct bfd_proto *p, ip_addr local, struct iface *ifa); |
1ec52253 | 240 | sock * bfd_open_tx_sk(struct bfd_proto *p, ip_addr local, struct iface *ifa); |
bf139664 OZ |
241 | |
242 | ||
6a8d3f1c | 243 | #endif /* _BIRD_BFD_H_ */ |