1 /* SPDX-License-Identifier: (GPL-2.0 WITH Linux-syscall-note) */
2 /* Copyright (C) B.A.T.M.A.N. contributors:
4 * Marek Lindner, Simon Wunderlich
7 #ifndef _UAPI_LINUX_BATADV_PACKET_H_
8 #define _UAPI_LINUX_BATADV_PACKET_H_
10 #include <asm/byteorder.h>
11 #include <linux/if_ether.h>
12 #include <linux/types.h>
15 * batadv_tp_is_error() - Check throughput meter return code for error
16 * @n: throughput meter return code
18 * Return: 0 when not error was detected, != 0 otherwise
20 #define batadv_tp_is_error(n) ((__u8)(n) > 127 ? 1 : 0)
23 * enum batadv_packettype - types for batman-adv encapsulated packets
24 * @BATADV_IV_OGM: originator messages for B.A.T.M.A.N. IV
25 * @BATADV_BCAST: broadcast packets carrying broadcast payload
26 * @BATADV_CODED: network coded packets
27 * @BATADV_ELP: echo location packets for B.A.T.M.A.N. V
28 * @BATADV_OGM2: originator messages for B.A.T.M.A.N. V
29 * @BATADV_MCAST: multicast packet with multiple destination addresses
31 * @BATADV_UNICAST: unicast packets carrying unicast payload traffic
32 * @BATADV_UNICAST_FRAG: unicast packets carrying a fragment of the original
34 * @BATADV_UNICAST_4ADDR: unicast packet including the originator address of
36 * @BATADV_ICMP: unicast packet like IP ICMP used for ping or traceroute
37 * @BATADV_UNICAST_TVLV: unicast packet carrying TVLV containers
39 enum batadv_packettype {
40 /* 0x00 - 0x3f: local packets or special rules for handling */
47 /* 0x40 - 0x7f: unicast */
48 #define BATADV_UNICAST_MIN 0x40
49 BATADV_UNICAST = 0x40,
50 BATADV_UNICAST_FRAG = 0x41,
51 BATADV_UNICAST_4ADDR = 0x42,
53 BATADV_UNICAST_TVLV = 0x44,
54 #define BATADV_UNICAST_MAX 0x7f
55 /* 0x80 - 0xff: reserved */
59 * enum batadv_subtype - packet subtype for unicast4addr
60 * @BATADV_P_DATA: user payload
61 * @BATADV_P_DAT_DHT_GET: DHT request message
62 * @BATADV_P_DAT_DHT_PUT: DHT store message
63 * @BATADV_P_DAT_CACHE_REPLY: ARP reply generated by DAT
67 BATADV_P_DAT_DHT_GET = 0x02,
68 BATADV_P_DAT_DHT_PUT = 0x03,
69 BATADV_P_DAT_CACHE_REPLY = 0x04,
72 /* this file is included by batctl which needs these defines */
73 #define BATADV_COMPAT_VERSION 15
76 * enum batadv_iv_flags - flags used in B.A.T.M.A.N. IV OGM packets
77 * @BATADV_NOT_BEST_NEXT_HOP: flag is set when the ogm packet is forwarded and
78 * was previously received from someone other than the best neighbor.
79 * @BATADV_PRIMARIES_FIRST_HOP: flag unused.
80 * @BATADV_DIRECTLINK: flag is for the first hop or if rebroadcasted from a
81 * one hop neighbor on the interface where it was originally received.
83 enum batadv_iv_flags {
84 BATADV_NOT_BEST_NEXT_HOP = 1UL << 0,
85 BATADV_PRIMARIES_FIRST_HOP = 1UL << 1,
86 BATADV_DIRECTLINK = 1UL << 2,
90 * enum batadv_icmp_packettype - ICMP message types
91 * @BATADV_ECHO_REPLY: success reply to BATADV_ECHO_REQUEST
92 * @BATADV_DESTINATION_UNREACHABLE: failure when route to destination not found
93 * @BATADV_ECHO_REQUEST: request BATADV_ECHO_REPLY from destination
94 * @BATADV_TTL_EXCEEDED: error after BATADV_ECHO_REQUEST traversed too many hops
95 * @BATADV_PARAMETER_PROBLEM: return code for malformed messages
96 * @BATADV_TP: throughput meter packet
98 enum batadv_icmp_packettype {
99 BATADV_ECHO_REPLY = 0,
100 BATADV_DESTINATION_UNREACHABLE = 3,
101 BATADV_ECHO_REQUEST = 8,
102 BATADV_TTL_EXCEEDED = 11,
103 BATADV_PARAMETER_PROBLEM = 12,
108 * enum batadv_mcast_flags - flags for multicast capabilities and settings
109 * @BATADV_MCAST_WANT_ALL_UNSNOOPABLES: we want all packets destined for
110 * 224.0.0.0/24 or ff02::1
111 * @BATADV_MCAST_WANT_ALL_IPV4: we want all IPv4 multicast packets
112 * (both link-local and routable ones)
113 * @BATADV_MCAST_WANT_ALL_IPV6: we want all IPv6 multicast packets
114 * (both link-local and routable ones)
115 * @BATADV_MCAST_WANT_NO_RTR4: we have no IPv4 multicast router and therefore
116 * only need routable IPv4 multicast packets we signed up for explicitly
117 * @BATADV_MCAST_WANT_NO_RTR6: we have no IPv6 multicast router and therefore
118 * only need routable IPv6 multicast packets we signed up for explicitly
120 enum batadv_mcast_flags {
121 BATADV_MCAST_WANT_ALL_UNSNOOPABLES = 1UL << 0,
122 BATADV_MCAST_WANT_ALL_IPV4 = 1UL << 1,
123 BATADV_MCAST_WANT_ALL_IPV6 = 1UL << 2,
124 BATADV_MCAST_WANT_NO_RTR4 = 1UL << 3,
125 BATADV_MCAST_WANT_NO_RTR6 = 1UL << 4,
128 /* tt data subtypes */
129 #define BATADV_TT_DATA_TYPE_MASK 0x0F
132 * enum batadv_tt_data_flags - flags for tt data tvlv
133 * @BATADV_TT_OGM_DIFF: TT diff propagated through OGM
134 * @BATADV_TT_REQUEST: TT request message
135 * @BATADV_TT_RESPONSE: TT response message
136 * @BATADV_TT_FULL_TABLE: contains full table to replace existing table
138 enum batadv_tt_data_flags {
139 BATADV_TT_OGM_DIFF = 1UL << 0,
140 BATADV_TT_REQUEST = 1UL << 1,
141 BATADV_TT_RESPONSE = 1UL << 2,
142 BATADV_TT_FULL_TABLE = 1UL << 4,
146 * enum batadv_vlan_flags - flags for the four MSB of any vlan ID field
147 * @BATADV_VLAN_HAS_TAG: whether the field contains a valid vlan tag or not
149 enum batadv_vlan_flags {
150 BATADV_VLAN_HAS_TAG = 1UL << 15,
154 * enum batadv_bla_claimframe - claim frame types for the bridge loop avoidance
155 * @BATADV_CLAIM_TYPE_CLAIM: claim of a client mac address
156 * @BATADV_CLAIM_TYPE_UNCLAIM: unclaim of a client mac address
157 * @BATADV_CLAIM_TYPE_ANNOUNCE: announcement of backbone with current crc
158 * @BATADV_CLAIM_TYPE_REQUEST: request of full claim table
159 * @BATADV_CLAIM_TYPE_LOOPDETECT: mesh-traversing loop detect packet
161 enum batadv_bla_claimframe {
162 BATADV_CLAIM_TYPE_CLAIM = 0x00,
163 BATADV_CLAIM_TYPE_UNCLAIM = 0x01,
164 BATADV_CLAIM_TYPE_ANNOUNCE = 0x02,
165 BATADV_CLAIM_TYPE_REQUEST = 0x03,
166 BATADV_CLAIM_TYPE_LOOPDETECT = 0x04,
170 * enum batadv_tvlv_type - tvlv type definitions
171 * @BATADV_TVLV_GW: gateway tvlv
172 * @BATADV_TVLV_DAT: distributed arp table tvlv
173 * @BATADV_TVLV_NC: network coding tvlv
174 * @BATADV_TVLV_TT: translation table tvlv
175 * @BATADV_TVLV_ROAM: roaming advertisement tvlv
176 * @BATADV_TVLV_MCAST: multicast capability tvlv
178 enum batadv_tvlv_type {
179 BATADV_TVLV_GW = 0x01,
180 BATADV_TVLV_DAT = 0x02,
181 BATADV_TVLV_NC = 0x03,
182 BATADV_TVLV_TT = 0x04,
183 BATADV_TVLV_ROAM = 0x05,
184 BATADV_TVLV_MCAST = 0x06,
188 /* the destination hardware field in the ARP frame is used to
189 * transport the claim type and the group id
191 struct batadv_bla_claim_dst {
192 __u8 magic[3]; /* FF:43:05 */
193 __u8 type; /* bla_claimframe */
194 __be16 group; /* group id */
198 * struct batadv_ogm_packet - ogm (routing protocol) packet
199 * @packet_type: batman-adv packet type, part of the general header
200 * @version: batman-adv protocol version, part of the general header
201 * @ttl: time to live for this packet, part of the general header
202 * @flags: contains routing relevant flags - see enum batadv_iv_flags
203 * @seqno: sequence identification
204 * @orig: address of the source node
205 * @prev_sender: address of the previous sender
206 * @reserved: reserved byte for alignment
207 * @tq: transmission quality
208 * @tvlv_len: length of tvlv data following the ogm header
210 struct batadv_ogm_packet {
217 __u8 prev_sender[ETH_ALEN];
223 #define BATADV_OGM_HLEN sizeof(struct batadv_ogm_packet)
226 * struct batadv_ogm2_packet - ogm2 (routing protocol) packet
227 * @packet_type: batman-adv packet type, part of the general header
228 * @version: batman-adv protocol version, part of the general header
229 * @ttl: time to live for this packet, part of the general header
230 * @flags: reserved for routing relevant flags - currently always 0
231 * @seqno: sequence number
232 * @orig: originator mac address
233 * @tvlv_len: length of the appended tvlv buffer (in bytes)
234 * @throughput: the currently flooded path throughput
236 struct batadv_ogm2_packet {
247 #define BATADV_OGM2_HLEN sizeof(struct batadv_ogm2_packet)
250 * struct batadv_elp_packet - elp (neighbor discovery) packet
251 * @packet_type: batman-adv packet type, part of the general header
252 * @version: batman-adv protocol version, part of the general header
253 * @orig: originator mac address
254 * @seqno: sequence number
255 * @elp_interval: currently used ELP sending interval in ms
257 struct batadv_elp_packet {
265 #define BATADV_ELP_HLEN sizeof(struct batadv_elp_packet)
268 * struct batadv_icmp_header - common members among all the ICMP packets
269 * @packet_type: batman-adv packet type, part of the general header
270 * @version: batman-adv protocol version, part of the general header
271 * @ttl: time to live for this packet, part of the general header
272 * @msg_type: ICMP packet type
273 * @dst: address of the destination node
274 * @orig: address of the source node
275 * @uid: local ICMP socket identifier
276 * @align: not used - useful for alignment purposes only
278 * This structure is used for ICMP packet parsing only and it is never sent
279 * over the wire. The alignment field at the end is there to ensure that
280 * members are padded the same way as they are in real packets.
282 struct batadv_icmp_header {
286 __u8 msg_type; /* see ICMP message types above */
294 * struct batadv_icmp_packet - ICMP packet
295 * @packet_type: batman-adv packet type, part of the general header
296 * @version: batman-adv protocol version, part of the general header
297 * @ttl: time to live for this packet, part of the general header
298 * @msg_type: ICMP packet type
299 * @dst: address of the destination node
300 * @orig: address of the source node
301 * @uid: local ICMP socket identifier
302 * @reserved: not used - useful for alignment
303 * @seqno: ICMP sequence number
305 struct batadv_icmp_packet {
309 __u8 msg_type; /* see ICMP message types above */
318 * struct batadv_icmp_tp_packet - ICMP TP Meter packet
319 * @packet_type: batman-adv packet type, part of the general header
320 * @version: batman-adv protocol version, part of the general header
321 * @ttl: time to live for this packet, part of the general header
322 * @msg_type: ICMP packet type
323 * @dst: address of the destination node
324 * @orig: address of the source node
325 * @uid: local ICMP socket identifier
326 * @subtype: TP packet subtype (see batadv_icmp_tp_subtype)
327 * @session: TP session identifier
328 * @seqno: the TP sequence number
329 * @timestamp: time when the packet has been sent. This value is filled in a
330 * TP_MSG and echoed back in the next TP_ACK so that the sender can compute the
331 * RTT. Since it is read only by the host which wrote it, there is no need to
332 * store it using network order
334 struct batadv_icmp_tp_packet {
338 __u8 msg_type; /* see ICMP message types above */
349 * enum batadv_icmp_tp_subtype - ICMP TP Meter packet subtypes
350 * @BATADV_TP_MSG: Msg from sender to receiver
351 * @BATADV_TP_ACK: acknowledgment from receiver to sender
353 enum batadv_icmp_tp_subtype {
358 #define BATADV_RR_LEN 16
361 * struct batadv_icmp_packet_rr - ICMP RouteRecord packet
362 * @packet_type: batman-adv packet type, part of the general header
363 * @version: batman-adv protocol version, part of the general header
364 * @ttl: time to live for this packet, part of the general header
365 * @msg_type: ICMP packet type
366 * @dst: address of the destination node
367 * @orig: address of the source node
368 * @uid: local ICMP socket identifier
369 * @rr_cur: number of entries the rr array
370 * @seqno: ICMP sequence number
371 * @rr: route record array
373 struct batadv_icmp_packet_rr {
377 __u8 msg_type; /* see ICMP message types above */
383 __u8 rr[BATADV_RR_LEN][ETH_ALEN];
386 #define BATADV_ICMP_MAX_PACKET_SIZE sizeof(struct batadv_icmp_packet_rr)
388 /* All packet headers in front of an ethernet header have to be completely
389 * divisible by 2 but not by 4 to make the payload after the ethernet
390 * header again 4 bytes boundary aligned.
392 * A packing of 2 is necessary to avoid extra padding at the end of the struct
393 * caused by a structure member which is larger than two bytes. Otherwise
394 * the structure would not fulfill the previously mentioned rule to avoid the
395 * misalignment of the payload after the ethernet header. It may also lead to
396 * leakage of information when the padding it not initialized before sending.
400 * struct batadv_unicast_packet - unicast packet for network payload
401 * @packet_type: batman-adv packet type, part of the general header
402 * @version: batman-adv protocol version, part of the general header
403 * @ttl: time to live for this packet, part of the general header
404 * @ttvn: translation table version number
405 * @dest: originator destination of the unicast packet
407 struct batadv_unicast_packet {
411 __u8 ttvn; /* destination translation table version number */
413 /* "4 bytes boundary + 2 bytes" long to make the payload after the
414 * following ethernet header again 4 bytes boundary aligned
419 * struct batadv_unicast_4addr_packet - extended unicast packet
420 * @u: common unicast packet header
421 * @src: address of the source
422 * @subtype: packet subtype
423 * @reserved: reserved byte for alignment
425 struct batadv_unicast_4addr_packet {
426 struct batadv_unicast_packet u;
430 /* "4 bytes boundary + 2 bytes" long to make the payload after the
431 * following ethernet header again 4 bytes boundary aligned
436 * struct batadv_frag_packet - fragmented packet
437 * @packet_type: batman-adv packet type, part of the general header
438 * @version: batman-adv protocol version, part of the general header
439 * @ttl: time to live for this packet, part of the general header
440 * @dest: final destination used when routing fragments
441 * @orig: originator of the fragment used when merging the packet
442 * @no: fragment number within this sequence
443 * @priority: priority of frame, from ToS IP precedence or 802.1p
444 * @reserved: reserved byte for alignment
445 * @seqno: sequence identification
446 * @total_size: size of the merged packet
448 struct batadv_frag_packet {
450 __u8 version; /* batman version field */
452 #if defined(__BIG_ENDIAN_BITFIELD)
456 #elif defined(__LITTLE_ENDIAN_BITFIELD)
461 #error "unknown bitfield endianness"
470 * struct batadv_bcast_packet - broadcast packet for network payload
471 * @packet_type: batman-adv packet type, part of the general header
472 * @version: batman-adv protocol version, part of the general header
473 * @ttl: time to live for this packet, part of the general header
474 * @reserved: reserved byte for alignment
475 * @seqno: sequence identification
476 * @orig: originator of the broadcast packet
478 struct batadv_bcast_packet {
480 __u8 version; /* batman version field */
485 /* "4 bytes boundary + 2 bytes" long to make the payload after the
486 * following ethernet header again 4 bytes boundary aligned
491 * struct batadv_coded_packet - network coded packet
492 * @packet_type: batman-adv packet type, part of the general header
493 * @version: batman-adv protocol version, part of the general header
494 * @ttl: time to live for this packet, part of the general header
495 * @first_source: original source of first included packet
496 * @first_orig_dest: original destination of first included packet
497 * @first_crc: checksum of first included packet
498 * @first_ttvn: tt-version number of first included packet
499 * @second_ttl: ttl of second packet
500 * @second_dest: second receiver of this coded packet
501 * @second_source: original source of second included packet
502 * @second_orig_dest: original destination of second included packet
503 * @second_crc: checksum of second included packet
504 * @second_ttvn: tt version number of second included packet
505 * @coded_len: length of network coded part of the payload
507 struct batadv_coded_packet {
509 __u8 version; /* batman version field */
512 /* __u8 first_dest[ETH_ALEN]; - saved in mac header destination */
513 __u8 first_source[ETH_ALEN];
514 __u8 first_orig_dest[ETH_ALEN];
518 __u8 second_dest[ETH_ALEN];
519 __u8 second_source[ETH_ALEN];
520 __u8 second_orig_dest[ETH_ALEN];
526 * struct batadv_unicast_tvlv_packet - generic unicast packet with tvlv payload
527 * @packet_type: batman-adv packet type, part of the general header
528 * @version: batman-adv protocol version, part of the general header
529 * @ttl: time to live for this packet, part of the general header
530 * @reserved: reserved field (for packet alignment)
531 * @src: address of the source
532 * @dst: address of the destination
533 * @tvlv_len: length of tvlv data following the unicast tvlv header
534 * @align: 2 bytes to align the header to a 4 byte boundary
536 struct batadv_unicast_tvlv_packet {
538 __u8 version; /* batman version field */
548 * struct batadv_tvlv_hdr - base tvlv header struct
549 * @type: tvlv container type (see batadv_tvlv_type)
550 * @version: tvlv container version
551 * @len: tvlv container length
553 struct batadv_tvlv_hdr {
560 * struct batadv_tvlv_gateway_data - gateway data propagated through gw tvlv
562 * @bandwidth_down: advertised uplink download bandwidth
563 * @bandwidth_up: advertised uplink upload bandwidth
565 struct batadv_tvlv_gateway_data {
566 __be32 bandwidth_down;
571 * struct batadv_tvlv_tt_data - tt data propagated through the tt tvlv container
572 * @flags: translation table flags (see batadv_tt_data_flags)
573 * @ttvn: translation table version number
574 * @num_vlan: number of announced VLANs. In the TVLV this struct is followed by
575 * one batadv_tvlv_tt_vlan_data object per announced vlan
577 struct batadv_tvlv_tt_data {
584 * struct batadv_tvlv_tt_vlan_data - vlan specific tt data propagated through
585 * the tt tvlv container
586 * @crc: crc32 checksum of the entries belonging to this vlan
587 * @vid: vlan identifier
588 * @reserved: unused, useful for alignment purposes
590 struct batadv_tvlv_tt_vlan_data {
597 * struct batadv_tvlv_tt_change - translation table diff data
598 * @flags: status indicators concerning the non-mesh client (see
599 * batadv_tt_client_flags)
600 * @reserved: reserved field - useful for alignment purposes only
601 * @addr: mac address of non-mesh client that triggered this tt change
602 * @vid: VLAN identifier
604 struct batadv_tvlv_tt_change {
612 * struct batadv_tvlv_roam_adv - roaming advertisement
613 * @client: mac address of roaming client
614 * @vid: VLAN identifier
616 struct batadv_tvlv_roam_adv {
617 __u8 client[ETH_ALEN];
622 * struct batadv_tvlv_mcast_data - payload of a multicast tvlv
623 * @flags: multicast flags announced by the orig node
624 * @reserved: reserved field
626 struct batadv_tvlv_mcast_data {
633 #endif /* _UAPI_LINUX_BATADV_PACKET_H_ */