2 * BIRD -- Bidirectional Forwarding Detection (BFD)
4 * Can be freely distributed and used under the terms of the GNU GPL.
12 #include "nest/bird.h"
14 #include "nest/iface.h"
15 #include "nest/protocol.h"
16 #include "nest/route.h"
17 #include "conf/conf.h"
19 #include "lib/resource.h"
20 #include "lib/socket.h"
21 #include "lib/string.h"
27 #define BFD_CONTROL_PORT 3784
28 #define BFD_ECHO_PORT 3785
29 #define BFD_MULTI_CTL_PORT 4784
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
37 struct bfd_iface_config
;
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 */
47 struct bfd_iface_config
64 struct neighbor
*neigh
;
65 struct bfd_request
*req
;
74 struct birdloop
*loop
;
76 pthread_spinlock_t lock
;
80 HASH(struct bfd_session
) session_hash_id
;
81 HASH(struct bfd_session
) session_hash_ip
;
99 struct bfd_iface_config
*cf
;
100 struct bfd_proto
*bfd
;
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 */
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 */
134 u8 detect_mult
; /* Announced detect_mult, local option */
135 u8 rem_detect_mult
; /* Last received detect_mult */
137 btime last_tx
; /* Time of last sent periodic control packet */
138 btime last_rx
; /* Time of last received valid control packet */
140 timer2
*tx_timer
; /* Periodic control packet timer */
141 timer2
*hold_timer
; /* Timer for session down detection time */
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 */
149 extern const char *bfd_state_names
[];
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
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
166 #define BFD_POLL_TX 1
167 #define BFD_POLL_RX 2
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)
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
); }
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
);
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
);
193 #endif /* _BIRD_BFD_H_ */