]> git.proxmox.com Git - mirror_frr.git/blame - bfdd/bfddp_packet.h
Merge pull request #12798 from donaldsharp/rib_match_multicast
[mirror_frr.git] / bfdd / bfddp_packet.h
CommitLineData
47a3a827 1// SPDX-License-Identifier: MIT
fe744cec
RZ
2/*
3 * BFD Data Plane protocol messages header.
4 *
5 * Copyright (C) 2020 Network Device Education Foundation, Inc. ("NetDEF")
6 * Rafael F. Zalamena
fe744cec
RZ
7 */
8
9/**
10 * \file bfddp_packet.h
11 */
12#ifndef BFD_DP_PACKET_H
13#define BFD_DP_PACKET_H
14
15#include <netinet/in.h>
16
17#include <stdint.h>
18
19/*
20 * Protocol definitions.
21 */
22
23/**
24 * BFD protocol version as defined in RFC5880 Section 4.1 Generic BFD Control
25 * Packet Format.
26 */
27#define BFD_PROTOCOL_VERSION 1
28
29/** Default data plane port. */
30#define BFD_DATA_PLANE_DEFAULT_PORT 50700
31
32/** BFD single hop UDP port, as defined in RFC 5881 Section 4. Encapsulation. */
33#define BFD_SINGLE_HOP_PORT 3784
34
35/** BFD multi hop UDP port, as defined in RFC 5883 Section 5. Encapsulation. */
36#define BFD_MULTI_HOP_PORT 4784
37
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
46
47/*
48 * BFD single hop source UDP ports. As defined in RFC 5881 Section 4.
49 * Encapsulation.
50 */
51#define BFD_SOURCE_PORT_BEGIN 49152
52#define BFD_SOURCE_PORT_END 65535
53
54/** BFD data plane protocol version. */
55#define BFD_DP_VERSION 1
56
57/** BFD data plane message types. */
58enum bfddp_message_type {
59 /** Ask for BFD daemon or data plane for echo packet. */
60 ECHO_REQUEST = 0,
61 /** Answer a ECHO_REQUEST packet. */
62 ECHO_REPLY = 1,
63 /** Add or update BFD peer session. */
64 DP_ADD_SESSION = 2,
65 /** Delete BFD peer session. */
66 DP_DELETE_SESSION = 3,
67 /** Tell BFD daemon state changed: timer expired or session down. */
68 BFD_STATE_CHANGE = 4,
69
70 /** Ask for BFD session counters. */
71 DP_REQUEST_SESSION_COUNTERS = 5,
72 /** Tell BFD daemon about counters values. */
73 BFD_SESSION_COUNTERS = 6,
74};
75
76/**
77 * `ECHO_REQUEST`/`ECHO_REPLY` data payload.
78 *
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).
84 *
85 * Normally data plane will only check the time stamp it sent to determine
86 * the whole packet trip time.
87 */
88struct bfddp_echo {
89 /** Filled by data plane. */
90 uint64_t dp_time;
91 /** Filled by BFD daemon. */
92 uint64_t bfdd_time;
93};
94
95
96/** BFD session flags. */
97enum 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),
112};
113
114/**
115 * `DP_ADD_SESSION`/`DP_DELETE_SESSION` data payload.
116 *
117 * `lid` is unique in BFD daemon so it might be used as key for data
118 * structures lookup.
119 */
120struct bfddp_session {
121 /** Important session flags. \see bfddp_session_flag. */
122 uint32_t flags;
123 /**
124 * Session source address.
125 *
126 * Check `flags` field for `SESSION_IPV6` before using as IPv6.
127 */
128 struct in6_addr src;
129 /**
130 * Session destination address.
131 *
132 * Check `flags` field for `SESSION_IPV6` before using as IPv6.
133 */
134 struct in6_addr dst;
135
136 /** Local discriminator. */
137 uint32_t lid;
138 /**
139 * Minimum desired transmission interval (in microseconds) without
140 * jitter.
141 */
142 uint32_t min_tx;
143 /**
144 * Required minimum receive interval rate (in microseconds) without
145 * jitter.
146 */
147 uint32_t min_rx;
4df3e31c
IR
148 /**
149 * Minimum desired echo transmission interval (in microseconds)
150 * without jitter.
151 */
152 uint32_t min_echo_tx;
fe744cec
RZ
153 /**
154 * Required minimum echo receive interval rate (in microseconds)
155 * without jitter.
156 */
157 uint32_t min_echo_rx;
158 /** Amount of milliseconds to wait before starting the session */
159 uint32_t hold_time;
160
161 /** Minimum TTL. */
162 uint8_t ttl;
163 /** Detection multiplier. */
164 uint8_t detect_mult;
165 /** Reserved / zeroed. */
166 uint16_t zero;
167
168 /** Interface index (set to `0` when unavailable). */
169 uint32_t ifindex;
170 /** Interface name (empty when unavailable). */
171 char ifname[64];
172
173 /* TODO: missing authentication. */
174};
175
176/** BFD packet state values as defined in RFC 5880, Section 4.1. */
177enum bfd_state_value {
178 /** Session is administratively down. */
179 STATE_ADMINDOWN = 0,
180 /** Session is down or went down. */
181 STATE_DOWN = 1,
182 /** Session is initializing. */
183 STATE_INIT = 2,
184 /** Session is up. */
185 STATE_UP = 3,
186};
187
188/** BFD diagnostic field values as defined in RFC 5880, Section 4.1. */
189enum bfd_diagnostic_value {
190 /** Nothing was diagnosed. */
191 DIAG_NOTHING = 0,
192 /** Control detection time expired. */
193 DIAG_CONTROL_EXPIRED = 1,
194 /** Echo function failed. */
195 DIAG_ECHO_FAILED = 2,
196 /** Neighbor signaled down. */
197 DIAG_DOWN = 3,
198 /** Forwarding plane reset. */
199 DIAG_FP_RESET = 4,
200 /** Path down. */
201 DIAG_PATH_DOWN = 5,
202 /** Concatenated path down. */
203 DIAG_CONCAT_PATH_DOWN = 6,
204 /** Administratively down. */
205 DIAG_ADMIN_DOWN = 7,
206 /** Reverse concatenated path down. */
207 DIAG_REV_CONCAT_PATH_DOWN = 8,
208};
209
210/** BFD remote state flags. */
211enum bfd_remote_flags {
212 /** Control Plane Independent bit. */
213 RBIT_CPI = (1 << 0),
214 /** Demand mode bit. */
215 RBIT_DEMAND = (1 << 1),
216 /** Multipoint bit. */
217 RBIT_MP = (1 << 2),
218};
219
220/**
221 * `BFD_STATE_CHANGE` data payload.
222 */
223struct bfddp_state_change {
224 /** Local discriminator. */
225 uint32_t lid;
226 /** Remote discriminator. */
227 uint32_t rid;
228 /** Remote configurations/bits set. \see bfd_remote_flags. */
229 uint32_t remote_flags;
230 /** Remote minimum desired transmission interval. */
231 uint32_t desired_tx;
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.*/
237 uint8_t state;
238 /** Remote diagnostics (if any) */
239 uint8_t diagnostics;
240 /** Remote detection multiplier. */
241 uint8_t detection_multiplier;
242};
243
244/**
245 * BFD control packet state bits definition.
246 */
247enum 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),
260};
261
262/**
263 * BFD control packet.
264 *
265 * As defined in 'RFC 5880 Section 4.1 Generic BFD Control Packet Format'.
266 */
267struct bfddp_control_packet {
268 /** (3 bits version << 5) | (5 bits diag). */
269 uint8_t version_diag;
270 /**
271 * (2 bits state << 6) | (6 bits flags)
272 *
273 * \see bfd_state_value, bfddp_control_state_bits.
274 */
275 uint8_t state_bits;
276 /** Detection multiplier. */
277 uint8_t detection_multiplier;
278 /** Packet length in bytes. */
279 uint8_t length;
280 /** Our discriminator. */
281 uint32_t local_id;
282 /** Remote system discriminator. */
283 uint32_t remote_id;
284 /** Desired minimum send interval in microseconds. */
285 uint32_t desired_tx;
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;
290};
291
292/**
293 * The protocol wire message header structure.
294 */
295struct bfddp_message_header {
296 /** Protocol version format. \see BFD_DP_VERSION. */
297 uint8_t version;
298 /** Reserved / zero field. */
299 uint8_t zero;
300 /** Message contents type. \see bfddp_message_type. */
301 uint16_t type;
302 /**
303 * Message identification (to pair request/response).
304 *
305 * The ID `0` is reserved for asynchronous messages (e.g. unrequested
306 * messages).
307 */
308 uint16_t id;
309 /** Message length. */
310 uint16_t length;
311};
312
313/**
314 * Data plane session counters request.
315 *
316 * Message type: `DP_REQUEST_SESSION_COUNTERS`.
317 */
318struct bfddp_request_counters {
319 /** Session local discriminator. */
320 uint32_t lid;
321};
322
323/**
324 * BFD session counters reply.
325 *
326 * Message type: `BFD_SESSION_COUNTERS`.
327 */
328struct bfddp_session_counters {
329 /** Session local discriminator. */
330 uint32_t lid;
331
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;
340
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;
349};
350
351/**
352 * The protocol wire messages structure.
353 */
354struct bfddp_message {
355 /** Message header. \see bfddp_message_header. */
356 struct bfddp_message_header header;
357
358 /** Message payload. \see bfddp_message_type. */
359 union {
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;
366 } data;
367};
368
369#endif /* BFD_DP_PACKET_H */