]>
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" | |
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 |
37 | struct bfd_iface_config; |
38 | ||
bf139664 OZ |
39 | struct 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 | 47 | struct 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 | ||
57 | struct 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 | ||
71 | struct 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 | ||
87 | sock *rx_1; | |
88 | sock *rx_m; | |
1ec52253 | 89 | list iface_list; |
bf139664 OZ |
90 | }; |
91 | ||
1ec52253 | 92 | struct bfd_iface |
bf139664 OZ |
93 | { |
94 | node n; | |
1ec52253 OZ |
95 | ip_addr local; |
96 | struct iface *iface; | |
97 | struct bfd_iface_config *cf; | |
98 | struct bfd_proto *bfd; | |
99 | ||
bf139664 OZ |
100 | sock *sk; |
101 | u32 uc; | |
1ec52253 | 102 | u8 changed; |
bf139664 OZ |
103 | }; |
104 | ||
105 | struct bfd_session | |
106 | { | |
107 | node n; | |
6a8d3f1c | 108 | ip_addr addr; /* Address of session */ |
1ec52253 | 109 | struct bfd_iface *ifa; /* Iface associated with session */ |
bf139664 OZ |
110 | struct bfd_session *next_id; /* Next in bfd.session_hash_id */ |
111 | struct bfd_session *next_ip; /* Next in bfd.session_hash_ip */ | |
112 | ||
1ec52253 | 113 | u8 opened_unused; |
6a8d3f1c | 114 | u8 passive; |
bf139664 OZ |
115 | u8 poll_active; |
116 | u8 poll_scheduled; | |
117 | ||
118 | u8 loc_state; | |
119 | u8 rem_state; | |
120 | u8 loc_diag; | |
6a8d3f1c | 121 | u8 rem_diag; |
bf139664 OZ |
122 | u32 loc_id; /* Local session ID (local discriminator) */ |
123 | u32 rem_id; /* Remote session ID (remote discriminator) */ | |
124 | u32 des_min_tx_int; /* Desired min rx interval, local option */ | |
125 | u32 des_min_tx_new; /* Used for des_min_tx_int change */ | |
126 | u32 req_min_rx_int; /* Required min tx interval, local option */ | |
127 | u32 req_min_rx_new; /* Used for req_min_rx_int change */ | |
128 | u32 rem_min_tx_int; /* Last received des_min_tx_int */ | |
129 | u32 rem_min_rx_int; /* Last received req_min_rx_int */ | |
130 | u8 demand_mode; /* Currently unused */ | |
131 | u8 rem_demand_mode; | |
132 | u8 detect_mult; /* Announced detect_mult, local option */ | |
133 | u8 rem_detect_mult; /* Last received detect_mult */ | |
134 | ||
6a8d3f1c OZ |
135 | btime last_tx; /* Time of last sent periodic control packet */ |
136 | btime last_rx; /* Time of last received valid control packet */ | |
bf139664 OZ |
137 | |
138 | timer2 *tx_timer; /* Periodic control packet timer */ | |
139 | timer2 *hold_timer; /* Timer for session down detection time */ | |
6a8d3f1c | 140 | |
1ec52253 OZ |
141 | list request_list; /* List of client requests (struct bfd_request) */ |
142 | bird_clock_t last_state_change; /* Time of last state change */ | |
143 | u8 notify_running; /* 1 if notify hooks are running */ | |
bf139664 OZ |
144 | }; |
145 | ||
146 | ||
0e175f9f | 147 | extern const char *bfd_state_names[]; |
bf139664 OZ |
148 | |
149 | #define BFD_STATE_ADMIN_DOWN 0 | |
150 | #define BFD_STATE_DOWN 1 | |
151 | #define BFD_STATE_INIT 2 | |
152 | #define BFD_STATE_UP 3 | |
153 | ||
154 | #define BFD_DIAG_NOTHING 0 | |
155 | #define BFD_DIAG_TIMEOUT 1 | |
156 | #define BFD_DIAG_ECHO_FAILED 2 | |
157 | #define BFD_DIAG_NEIGHBOR_DOWN 3 | |
158 | #define BFD_DIAG_FWD_RESET 4 | |
159 | #define BFD_DIAG_PATH_DOWN 5 | |
160 | #define BFD_DIAG_C_PATH_DOWN 6 | |
161 | #define BFD_DIAG_ADMIN_DOWN 7 | |
162 | #define BFD_DIAG_RC_PATH_DOWN 8 | |
163 | ||
164 | #define BFD_POLL_TX 1 | |
165 | #define BFD_POLL_RX 2 | |
166 | ||
0e175f9f | 167 | #define BFD_FLAGS 0x3f |
6a8d3f1c OZ |
168 | #define BFD_FLAG_POLL (1 << 5) |
169 | #define BFD_FLAG_FINAL (1 << 4) | |
170 | #define BFD_FLAG_CPI (1 << 3) | |
171 | #define BFD_FLAG_AP (1 << 2) | |
172 | #define BFD_FLAG_DEMAND (1 << 1) | |
173 | #define BFD_FLAG_MULTIPOINT (1 << 0) | |
174 | ||
175 | ||
176 | static inline void bfd_lock_sessions(struct bfd_proto *p) { pthread_spin_lock(&p->lock); } | |
177 | static inline void bfd_unlock_sessions(struct bfd_proto *p) { pthread_spin_unlock(&p->lock); } | |
178 | ||
179 | /* bfd.c */ | |
180 | struct bfd_session * bfd_find_session_by_id(struct bfd_proto *p, u32 id); | |
181 | struct bfd_session * bfd_find_session_by_addr(struct bfd_proto *p, ip_addr addr); | |
182 | void bfd_session_process_ctl(struct bfd_session *s, u8 flags, u32 old_tx_int, u32 old_rx_int); | |
183 | void bfd_show_sessions(struct proto *P); | |
bf139664 | 184 | |
6a8d3f1c OZ |
185 | /* packets.c */ |
186 | void bfd_send_ctl(struct bfd_proto *p, struct bfd_session *s, int final); | |
187 | sock * bfd_open_rx_sk(struct bfd_proto *p, int multihop); | |
1ec52253 | 188 | sock * bfd_open_tx_sk(struct bfd_proto *p, ip_addr local, struct iface *ifa); |
bf139664 OZ |
189 | |
190 | ||
6a8d3f1c | 191 | #endif /* _BIRD_BFD_H_ */ |