]> git.ipfire.org Git - thirdparty/bird.git/blob - proto/bfd/bfd.h
BFD: split of v4/v6 sockets
[thirdparty/bird.git] / proto / bfd / bfd.h
1 /*
2 * BIRD -- Bidirectional Forwarding Detection (BFD)
3 *
4 * Can be freely distributed and used under the terms of the GNU GPL.
5 */
6
7 #ifndef _BIRD_BFD_H_
8 #define _BIRD_BFD_H_
9
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
23 #include "nest/bfd.h"
24 #include "io.h"
25
26
27 #define BFD_CONTROL_PORT 3784
28 #define BFD_ECHO_PORT 3785
29 #define BFD_MULTI_CTL_PORT 4784
30
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_)
34 #define BFD_DEFAULT_MULTIPLIER 5
35
36
37 struct bfd_iface_config;
38
39 struct bfd_config
40 {
41 struct proto_config c;
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 */
45 };
46
47 struct bfd_iface_config
48 {
49 struct iface_patt i;
50 u32 min_rx_int;
51 u32 min_tx_int;
52 u32 idle_tx_int;
53 u8 multiplier;
54 u8 passive;
55 };
56
57 struct bfd_neighbor
58 {
59 node n;
60 ip_addr addr;
61 ip_addr local;
62 struct iface *iface;
63
64 struct neighbor *neigh;
65 struct bfd_request *req;
66
67 u8 multihop;
68 u8 active;
69 };
70
71 struct bfd_proto
72 {
73 struct proto p;
74 struct birdloop *loop;
75 pool *tpool;
76 pthread_spinlock_t lock;
77 node bfd_node;
78
79 slab *session_slab;
80 HASH(struct bfd_session) session_hash_id;
81 HASH(struct bfd_session) session_hash_ip;
82
83 sock *notify_rs;
84 sock *notify_ws;
85 list notify_list;
86
87 sock *rx4_1;
88 sock *rx6_1;
89 sock *rx4_m;
90 sock *rx6_m;
91 list iface_list;
92 };
93
94 struct bfd_iface
95 {
96 node n;
97 ip_addr local;
98 struct iface *iface;
99 struct bfd_iface_config *cf;
100 struct bfd_proto *bfd;
101
102 sock *sk;
103 u32 uc;
104 u8 changed;
105 };
106
107 struct bfd_session
108 {
109 node n;
110 ip_addr addr; /* Address of session */
111 struct bfd_iface *ifa; /* Iface associated with session */
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
115 u8 opened_unused;
116 u8 passive;
117 u8 poll_active;
118 u8 poll_scheduled;
119
120 u8 loc_state;
121 u8 rem_state;
122 u8 loc_diag;
123 u8 rem_diag;
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
137 btime last_tx; /* Time of last sent periodic control packet */
138 btime last_rx; /* Time of last received valid control packet */
139
140 timer2 *tx_timer; /* Periodic control packet timer */
141 timer2 *hold_timer; /* Timer for session down detection time */
142
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 */
146 };
147
148
149 extern const char *bfd_state_names[];
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
169 #define BFD_FLAGS 0x3f
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
178 static inline void bfd_lock_sessions(struct bfd_proto *p) { pthread_spin_lock(&p->lock); }
179 static inline void bfd_unlock_sessions(struct bfd_proto *p) { pthread_spin_unlock(&p->lock); }
180
181 /* bfd.c */
182 struct bfd_session * bfd_find_session_by_id(struct bfd_proto *p, u32 id);
183 struct bfd_session * bfd_find_session_by_addr(struct bfd_proto *p, ip_addr addr);
184 void bfd_session_process_ctl(struct bfd_session *s, u8 flags, u32 old_tx_int, u32 old_rx_int);
185 void bfd_show_sessions(struct proto *P);
186
187 /* packets.c */
188 void bfd_send_ctl(struct bfd_proto *p, struct bfd_session *s, int final);
189 sock * bfd_open_rx_sk(struct bfd_proto *p, int multihop, int inet_version);
190 sock * bfd_open_tx_sk(struct bfd_proto *p, ip_addr local, struct iface *ifa);
191
192
193 #endif /* _BIRD_BFD_H_ */