1 // SPDX-License-Identifier: MIT
3 * BFD Data Plane protocol messages header.
5 * Copyright (C) 2020 Network Device Education Foundation, Inc. ("NetDEF")
10 * \file bfddp_packet.h
12 #ifndef BFD_DP_PACKET_H
13 #define BFD_DP_PACKET_H
15 #include <netinet/in.h>
20 * Protocol definitions.
24 * BFD protocol version as defined in RFC5880 Section 4.1 Generic BFD Control
27 #define BFD_PROTOCOL_VERSION 1
29 /** Default data plane port. */
30 #define BFD_DATA_PLANE_DEFAULT_PORT 50700
32 /** BFD single hop UDP port, as defined in RFC 5881 Section 4. Encapsulation. */
33 #define BFD_SINGLE_HOP_PORT 3784
35 /** BFD multi hop UDP port, as defined in RFC 5883 Section 5. Encapsulation. */
36 #define BFD_MULTI_HOP_PORT 4784
38 /** Default slow start multiplier. */
39 #define SLOWSTART_DMULT 3
40 /** Default slow start transmission speed. */
41 #define SLOWSTART_TX 1000000u
42 /** Default slow start receive speed. */
43 #define SLOWSTART_RX 1000000u
44 /** Default slow start echo receive speed. */
45 #define SLOWSTART_ERX 0u
48 * BFD single hop source UDP ports. As defined in RFC 5881 Section 4.
51 #define BFD_SOURCE_PORT_BEGIN 49152
52 #define BFD_SOURCE_PORT_END 65535
54 /** BFD data plane protocol version. */
55 #define BFD_DP_VERSION 1
57 /** BFD data plane message types. */
58 enum bfddp_message_type
{
59 /** Ask for BFD daemon or data plane for echo packet. */
61 /** Answer a ECHO_REQUEST packet. */
63 /** Add or update BFD peer session. */
65 /** Delete BFD peer session. */
66 DP_DELETE_SESSION
= 3,
67 /** Tell BFD daemon state changed: timer expired or session down. */
70 /** Ask for BFD session counters. */
71 DP_REQUEST_SESSION_COUNTERS
= 5,
72 /** Tell BFD daemon about counters values. */
73 BFD_SESSION_COUNTERS
= 6,
77 * `ECHO_REQUEST`/`ECHO_REPLY` data payload.
79 * Data plane might use whatever precision it wants for `dp_time`
80 * field, however if you want to be able to tell the delay between
81 * data plane packet send and BFD daemon packet processing you should
82 * use `gettimeofday()` and have the data plane clock synchronized with
83 * BFD daemon (not a problem if data plane runs in the same system).
85 * Normally data plane will only check the time stamp it sent to determine
86 * the whole packet trip time.
89 /** Filled by data plane. */
91 /** Filled by BFD daemon. */
96 /** BFD session flags. */
97 enum bfddp_session_flag
{
98 /** Set when using multi hop. */
99 SESSION_MULTIHOP
= (1 << 0),
100 /** Set when using demand mode. */
101 SESSION_DEMAND
= (1 << 1),
102 /** Set when using cbit (Control Plane Independent). */
103 SESSION_CBIT
= (1 << 2),
104 /** Set when using echo mode. */
105 SESSION_ECHO
= (1 << 3),
106 /** Set when using IPv6. */
107 SESSION_IPV6
= (1 << 4),
108 /** Set when using passive mode. */
109 SESSION_PASSIVE
= (1 << 5),
110 /** Set when session is administrative down. */
111 SESSION_SHUTDOWN
= (1 << 6),
115 * `DP_ADD_SESSION`/`DP_DELETE_SESSION` data payload.
117 * `lid` is unique in BFD daemon so it might be used as key for data
120 struct bfddp_session
{
121 /** Important session flags. \see bfddp_session_flag. */
124 * Session source address.
126 * Check `flags` field for `SESSION_IPV6` before using as IPv6.
130 * Session destination address.
132 * Check `flags` field for `SESSION_IPV6` before using as IPv6.
136 /** Local discriminator. */
139 * Minimum desired transmission interval (in microseconds) without
144 * Required minimum receive interval rate (in microseconds) without
149 * Minimum desired echo transmission interval (in microseconds)
152 uint32_t min_echo_tx
;
154 * Required minimum echo receive interval rate (in microseconds)
157 uint32_t min_echo_rx
;
158 /** Amount of milliseconds to wait before starting the session */
163 /** Detection multiplier. */
165 /** Reserved / zeroed. */
168 /** Interface index (set to `0` when unavailable). */
170 /** Interface name (empty when unavailable). */
173 /* TODO: missing authentication. */
176 /** BFD packet state values as defined in RFC 5880, Section 4.1. */
177 enum bfd_state_value
{
178 /** Session is administratively down. */
180 /** Session is down or went down. */
182 /** Session is initializing. */
184 /** Session is up. */
188 /** BFD diagnostic field values as defined in RFC 5880, Section 4.1. */
189 enum bfd_diagnostic_value
{
190 /** Nothing was diagnosed. */
192 /** Control detection time expired. */
193 DIAG_CONTROL_EXPIRED
= 1,
194 /** Echo function failed. */
195 DIAG_ECHO_FAILED
= 2,
196 /** Neighbor signaled down. */
198 /** Forwarding plane reset. */
202 /** Concatenated path down. */
203 DIAG_CONCAT_PATH_DOWN
= 6,
204 /** Administratively down. */
206 /** Reverse concatenated path down. */
207 DIAG_REV_CONCAT_PATH_DOWN
= 8,
210 /** BFD remote state flags. */
211 enum bfd_remote_flags
{
212 /** Control Plane Independent bit. */
214 /** Demand mode bit. */
215 RBIT_DEMAND
= (1 << 1),
216 /** Multipoint bit. */
221 * `BFD_STATE_CHANGE` data payload.
223 struct bfddp_state_change
{
224 /** Local discriminator. */
226 /** Remote discriminator. */
228 /** Remote configurations/bits set. \see bfd_remote_flags. */
229 uint32_t remote_flags
;
230 /** Remote minimum desired transmission interval. */
232 /** Remote minimum receive interval. */
233 uint32_t required_rx
;
234 /** Remote minimum echo receive interval. */
235 uint32_t required_echo_rx
;
236 /** Remote state. \see bfd_state_values.*/
238 /** Remote diagnostics (if any) */
240 /** Remote detection multiplier. */
241 uint8_t detection_multiplier
;
245 * BFD control packet state bits definition.
247 enum bfddp_control_state_bits
{
248 /** Used to request connection establishment signal. */
249 STATE_POLL_BIT
= (1 << 5),
250 /** Finalizes the connection establishment signal. */
251 STATE_FINAL_BIT
= (1 << 4),
252 /** Signalizes that forward plane doesn't depend on control plane. */
253 STATE_CPI_BIT
= (1 << 3),
254 /** Signalizes the use of authentication. */
255 STATE_AUTH_BIT
= (1 << 2),
256 /** Signalizes that peer is using demand mode. */
257 STATE_DEMAND_BIT
= (1 << 1),
258 /** Used in RFC 8562 implementation. */
259 STATE_MULTI_BIT
= (1 << 0),
263 * BFD control packet.
265 * As defined in 'RFC 5880 Section 4.1 Generic BFD Control Packet Format'.
267 struct bfddp_control_packet
{
268 /** (3 bits version << 5) | (5 bits diag). */
269 uint8_t version_diag
;
271 * (2 bits state << 6) | (6 bits flags)
273 * \see bfd_state_value, bfddp_control_state_bits.
276 /** Detection multiplier. */
277 uint8_t detection_multiplier
;
278 /** Packet length in bytes. */
280 /** Our discriminator. */
282 /** Remote system discriminator. */
284 /** Desired minimum send interval in microseconds. */
286 /** Desired minimum receive interval in microseconds. */
287 uint32_t required_rx
;
288 /** Desired minimum echo receive interval in microseconds. */
289 uint32_t required_echo_rx
;
293 * The protocol wire message header structure.
295 struct bfddp_message_header
{
296 /** Protocol version format. \see BFD_DP_VERSION. */
298 /** Reserved / zero field. */
300 /** Message contents type. \see bfddp_message_type. */
303 * Message identification (to pair request/response).
305 * The ID `0` is reserved for asynchronous messages (e.g. unrequested
309 /** Message length. */
314 * Data plane session counters request.
316 * Message type: `DP_REQUEST_SESSION_COUNTERS`.
318 struct bfddp_request_counters
{
319 /** Session local discriminator. */
324 * BFD session counters reply.
326 * Message type: `BFD_SESSION_COUNTERS`.
328 struct bfddp_session_counters
{
329 /** Session local discriminator. */
332 /** Control packet bytes input. */
333 uint64_t control_input_bytes
;
334 /** Control packets input. */
335 uint64_t control_input_packets
;
336 /** Control packet bytes output. */
337 uint64_t control_output_bytes
;
338 /** Control packets output. */
339 uint64_t control_output_packets
;
341 /** Echo packet bytes input. */
342 uint64_t echo_input_bytes
;
343 /** Echo packets input. */
344 uint64_t echo_input_packets
;
345 /** Echo packet bytes output. */
346 uint64_t echo_output_bytes
;
347 /** Echo packets output. */
348 uint64_t echo_output_packets
;
352 * The protocol wire messages structure.
354 struct bfddp_message
{
355 /** Message header. \see bfddp_message_header. */
356 struct bfddp_message_header header
;
358 /** Message payload. \see bfddp_message_type. */
360 struct bfddp_echo echo
;
361 struct bfddp_session session
;
362 struct bfddp_state_change state
;
363 struct bfddp_control_packet control
;
364 struct bfddp_request_counters counters_req
;
365 struct bfddp_session_counters session_counters
;
369 #endif /* BFD_DP_PACKET_H */