]> git.proxmox.com Git - mirror_frr.git/blame - bfdd/bfddp_packet.h
Merge pull request #12191 from manojvn/463777
[mirror_frr.git] / bfdd / bfddp_packet.h
CommitLineData
fe744cec
RZ
1/*
2 * BFD Data Plane protocol messages header.
3 *
4 * Copyright (C) 2020 Network Device Education Foundation, Inc. ("NetDEF")
5 * Rafael F. Zalamena
6 *
7 * Permission is hereby granted, free of charge, to any person obtaining a copy
8 * of this software and associated documentation files (the “Software”), to
9 * deal in the Software without restriction, including without limitation the
10 * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
11 * sell copies of the Software, and to permit persons to whom the Software is
12 * furnished to do so, subject to the following conditions:
13 *
14 * The above copyright notice and this permission notice shall be included in
15 * all copies or substantial portions of the Software.
16 *
17 * THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
22 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
23 * IN THE SOFTWARE.
24 */
25
26/**
27 * \file bfddp_packet.h
28 */
29#ifndef BFD_DP_PACKET_H
30#define BFD_DP_PACKET_H
31
32#include <netinet/in.h>
33
34#include <stdint.h>
35
36/*
37 * Protocol definitions.
38 */
39
40/**
41 * BFD protocol version as defined in RFC5880 Section 4.1 Generic BFD Control
42 * Packet Format.
43 */
44#define BFD_PROTOCOL_VERSION 1
45
46/** Default data plane port. */
47#define BFD_DATA_PLANE_DEFAULT_PORT 50700
48
49/** BFD single hop UDP port, as defined in RFC 5881 Section 4. Encapsulation. */
50#define BFD_SINGLE_HOP_PORT 3784
51
52/** BFD multi hop UDP port, as defined in RFC 5883 Section 5. Encapsulation. */
53#define BFD_MULTI_HOP_PORT 4784
54
55/** Default slow start multiplier. */
56#define SLOWSTART_DMULT 3
57/** Default slow start transmission speed. */
58#define SLOWSTART_TX 1000000u
59/** Default slow start receive speed. */
60#define SLOWSTART_RX 1000000u
61/** Default slow start echo receive speed. */
62#define SLOWSTART_ERX 0u
63
64/*
65 * BFD single hop source UDP ports. As defined in RFC 5881 Section 4.
66 * Encapsulation.
67 */
68#define BFD_SOURCE_PORT_BEGIN 49152
69#define BFD_SOURCE_PORT_END 65535
70
71/** BFD data plane protocol version. */
72#define BFD_DP_VERSION 1
73
74/** BFD data plane message types. */
75enum bfddp_message_type {
76 /** Ask for BFD daemon or data plane for echo packet. */
77 ECHO_REQUEST = 0,
78 /** Answer a ECHO_REQUEST packet. */
79 ECHO_REPLY = 1,
80 /** Add or update BFD peer session. */
81 DP_ADD_SESSION = 2,
82 /** Delete BFD peer session. */
83 DP_DELETE_SESSION = 3,
84 /** Tell BFD daemon state changed: timer expired or session down. */
85 BFD_STATE_CHANGE = 4,
86
87 /** Ask for BFD session counters. */
88 DP_REQUEST_SESSION_COUNTERS = 5,
89 /** Tell BFD daemon about counters values. */
90 BFD_SESSION_COUNTERS = 6,
91};
92
93/**
94 * `ECHO_REQUEST`/`ECHO_REPLY` data payload.
95 *
96 * Data plane might use whatever precision it wants for `dp_time`
97 * field, however if you want to be able to tell the delay between
98 * data plane packet send and BFD daemon packet processing you should
99 * use `gettimeofday()` and have the data plane clock synchronized with
100 * BFD daemon (not a problem if data plane runs in the same system).
101 *
102 * Normally data plane will only check the time stamp it sent to determine
103 * the whole packet trip time.
104 */
105struct bfddp_echo {
106 /** Filled by data plane. */
107 uint64_t dp_time;
108 /** Filled by BFD daemon. */
109 uint64_t bfdd_time;
110};
111
112
113/** BFD session flags. */
114enum bfddp_session_flag {
115 /** Set when using multi hop. */
116 SESSION_MULTIHOP = (1 << 0),
117 /** Set when using demand mode. */
118 SESSION_DEMAND = (1 << 1),
119 /** Set when using cbit (Control Plane Independent). */
120 SESSION_CBIT = (1 << 2),
121 /** Set when using echo mode. */
122 SESSION_ECHO = (1 << 3),
123 /** Set when using IPv6. */
124 SESSION_IPV6 = (1 << 4),
125 /** Set when using passive mode. */
126 SESSION_PASSIVE = (1 << 5),
127 /** Set when session is administrative down. */
128 SESSION_SHUTDOWN = (1 << 6),
129};
130
131/**
132 * `DP_ADD_SESSION`/`DP_DELETE_SESSION` data payload.
133 *
134 * `lid` is unique in BFD daemon so it might be used as key for data
135 * structures lookup.
136 */
137struct bfddp_session {
138 /** Important session flags. \see bfddp_session_flag. */
139 uint32_t flags;
140 /**
141 * Session source address.
142 *
143 * Check `flags` field for `SESSION_IPV6` before using as IPv6.
144 */
145 struct in6_addr src;
146 /**
147 * Session destination address.
148 *
149 * Check `flags` field for `SESSION_IPV6` before using as IPv6.
150 */
151 struct in6_addr dst;
152
153 /** Local discriminator. */
154 uint32_t lid;
155 /**
156 * Minimum desired transmission interval (in microseconds) without
157 * jitter.
158 */
159 uint32_t min_tx;
160 /**
161 * Required minimum receive interval rate (in microseconds) without
162 * jitter.
163 */
164 uint32_t min_rx;
4df3e31c
IR
165 /**
166 * Minimum desired echo transmission interval (in microseconds)
167 * without jitter.
168 */
169 uint32_t min_echo_tx;
fe744cec
RZ
170 /**
171 * Required minimum echo receive interval rate (in microseconds)
172 * without jitter.
173 */
174 uint32_t min_echo_rx;
175 /** Amount of milliseconds to wait before starting the session */
176 uint32_t hold_time;
177
178 /** Minimum TTL. */
179 uint8_t ttl;
180 /** Detection multiplier. */
181 uint8_t detect_mult;
182 /** Reserved / zeroed. */
183 uint16_t zero;
184
185 /** Interface index (set to `0` when unavailable). */
186 uint32_t ifindex;
187 /** Interface name (empty when unavailable). */
188 char ifname[64];
189
190 /* TODO: missing authentication. */
191};
192
193/** BFD packet state values as defined in RFC 5880, Section 4.1. */
194enum bfd_state_value {
195 /** Session is administratively down. */
196 STATE_ADMINDOWN = 0,
197 /** Session is down or went down. */
198 STATE_DOWN = 1,
199 /** Session is initializing. */
200 STATE_INIT = 2,
201 /** Session is up. */
202 STATE_UP = 3,
203};
204
205/** BFD diagnostic field values as defined in RFC 5880, Section 4.1. */
206enum bfd_diagnostic_value {
207 /** Nothing was diagnosed. */
208 DIAG_NOTHING = 0,
209 /** Control detection time expired. */
210 DIAG_CONTROL_EXPIRED = 1,
211 /** Echo function failed. */
212 DIAG_ECHO_FAILED = 2,
213 /** Neighbor signaled down. */
214 DIAG_DOWN = 3,
215 /** Forwarding plane reset. */
216 DIAG_FP_RESET = 4,
217 /** Path down. */
218 DIAG_PATH_DOWN = 5,
219 /** Concatenated path down. */
220 DIAG_CONCAT_PATH_DOWN = 6,
221 /** Administratively down. */
222 DIAG_ADMIN_DOWN = 7,
223 /** Reverse concatenated path down. */
224 DIAG_REV_CONCAT_PATH_DOWN = 8,
225};
226
227/** BFD remote state flags. */
228enum bfd_remote_flags {
229 /** Control Plane Independent bit. */
230 RBIT_CPI = (1 << 0),
231 /** Demand mode bit. */
232 RBIT_DEMAND = (1 << 1),
233 /** Multipoint bit. */
234 RBIT_MP = (1 << 2),
235};
236
237/**
238 * `BFD_STATE_CHANGE` data payload.
239 */
240struct bfddp_state_change {
241 /** Local discriminator. */
242 uint32_t lid;
243 /** Remote discriminator. */
244 uint32_t rid;
245 /** Remote configurations/bits set. \see bfd_remote_flags. */
246 uint32_t remote_flags;
247 /** Remote minimum desired transmission interval. */
248 uint32_t desired_tx;
249 /** Remote minimum receive interval. */
250 uint32_t required_rx;
251 /** Remote minimum echo receive interval. */
252 uint32_t required_echo_rx;
253 /** Remote state. \see bfd_state_values.*/
254 uint8_t state;
255 /** Remote diagnostics (if any) */
256 uint8_t diagnostics;
257 /** Remote detection multiplier. */
258 uint8_t detection_multiplier;
259};
260
261/**
262 * BFD control packet state bits definition.
263 */
264enum bfddp_control_state_bits {
265 /** Used to request connection establishment signal. */
266 STATE_POLL_BIT = (1 << 5),
267 /** Finalizes the connection establishment signal. */
268 STATE_FINAL_BIT = (1 << 4),
269 /** Signalizes that forward plane doesn't depend on control plane. */
270 STATE_CPI_BIT = (1 << 3),
271 /** Signalizes the use of authentication. */
272 STATE_AUTH_BIT = (1 << 2),
273 /** Signalizes that peer is using demand mode. */
274 STATE_DEMAND_BIT = (1 << 1),
275 /** Used in RFC 8562 implementation. */
276 STATE_MULTI_BIT = (1 << 0),
277};
278
279/**
280 * BFD control packet.
281 *
282 * As defined in 'RFC 5880 Section 4.1 Generic BFD Control Packet Format'.
283 */
284struct bfddp_control_packet {
285 /** (3 bits version << 5) | (5 bits diag). */
286 uint8_t version_diag;
287 /**
288 * (2 bits state << 6) | (6 bits flags)
289 *
290 * \see bfd_state_value, bfddp_control_state_bits.
291 */
292 uint8_t state_bits;
293 /** Detection multiplier. */
294 uint8_t detection_multiplier;
295 /** Packet length in bytes. */
296 uint8_t length;
297 /** Our discriminator. */
298 uint32_t local_id;
299 /** Remote system discriminator. */
300 uint32_t remote_id;
301 /** Desired minimum send interval in microseconds. */
302 uint32_t desired_tx;
303 /** Desired minimum receive interval in microseconds. */
304 uint32_t required_rx;
305 /** Desired minimum echo receive interval in microseconds. */
306 uint32_t required_echo_rx;
307};
308
309/**
310 * The protocol wire message header structure.
311 */
312struct bfddp_message_header {
313 /** Protocol version format. \see BFD_DP_VERSION. */
314 uint8_t version;
315 /** Reserved / zero field. */
316 uint8_t zero;
317 /** Message contents type. \see bfddp_message_type. */
318 uint16_t type;
319 /**
320 * Message identification (to pair request/response).
321 *
322 * The ID `0` is reserved for asynchronous messages (e.g. unrequested
323 * messages).
324 */
325 uint16_t id;
326 /** Message length. */
327 uint16_t length;
328};
329
330/**
331 * Data plane session counters request.
332 *
333 * Message type: `DP_REQUEST_SESSION_COUNTERS`.
334 */
335struct bfddp_request_counters {
336 /** Session local discriminator. */
337 uint32_t lid;
338};
339
340/**
341 * BFD session counters reply.
342 *
343 * Message type: `BFD_SESSION_COUNTERS`.
344 */
345struct bfddp_session_counters {
346 /** Session local discriminator. */
347 uint32_t lid;
348
349 /** Control packet bytes input. */
350 uint64_t control_input_bytes;
351 /** Control packets input. */
352 uint64_t control_input_packets;
353 /** Control packet bytes output. */
354 uint64_t control_output_bytes;
355 /** Control packets output. */
356 uint64_t control_output_packets;
357
358 /** Echo packet bytes input. */
359 uint64_t echo_input_bytes;
360 /** Echo packets input. */
361 uint64_t echo_input_packets;
362 /** Echo packet bytes output. */
363 uint64_t echo_output_bytes;
364 /** Echo packets output. */
365 uint64_t echo_output_packets;
366};
367
368/**
369 * The protocol wire messages structure.
370 */
371struct bfddp_message {
372 /** Message header. \see bfddp_message_header. */
373 struct bfddp_message_header header;
374
375 /** Message payload. \see bfddp_message_type. */
376 union {
377 struct bfddp_echo echo;
378 struct bfddp_session session;
379 struct bfddp_state_change state;
380 struct bfddp_control_packet control;
381 struct bfddp_request_counters counters_req;
382 struct bfddp_session_counters session_counters;
383 } data;
384};
385
386#endif /* BFD_DP_PACKET_H */