1 /* SPDX-License-Identifier: (GPL-2.0 WITH Linux-syscall-note) */
2 /* Copyright (C) 2007-2019 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
30 * @BATADV_UNICAST: unicast packets carrying unicast payload traffic
31 * @BATADV_UNICAST_FRAG: unicast packets carrying a fragment of the original
33 * @BATADV_UNICAST_4ADDR: unicast packet including the originator address of
35 * @BATADV_ICMP: unicast packet like IP ICMP used for ping or traceroute
36 * @BATADV_UNICAST_TVLV: unicast packet carrying TVLV containers
38 enum batadv_packettype {
39 /* 0x00 - 0x3f: local packets or special rules for handling */
45 /* 0x40 - 0x7f: unicast */
46 #define BATADV_UNICAST_MIN 0x40
47 BATADV_UNICAST = 0x40,
48 BATADV_UNICAST_FRAG = 0x41,
49 BATADV_UNICAST_4ADDR = 0x42,
51 BATADV_UNICAST_TVLV = 0x44,
52 #define BATADV_UNICAST_MAX 0x7f
53 /* 0x80 - 0xff: reserved */
57 * enum batadv_subtype - packet subtype for unicast4addr
58 * @BATADV_P_DATA: user payload
59 * @BATADV_P_DAT_DHT_GET: DHT request message
60 * @BATADV_P_DAT_DHT_PUT: DHT store message
61 * @BATADV_P_DAT_CACHE_REPLY: ARP reply generated by DAT
65 BATADV_P_DAT_DHT_GET = 0x02,
66 BATADV_P_DAT_DHT_PUT = 0x03,
67 BATADV_P_DAT_CACHE_REPLY = 0x04,
70 /* this file is included by batctl which needs these defines */
71 #define BATADV_COMPAT_VERSION 15
74 * enum batadv_iv_flags - flags used in B.A.T.M.A.N. IV OGM packets
75 * @BATADV_NOT_BEST_NEXT_HOP: flag is set when ogm packet is forwarded and was
76 * previously received from someone else than the best neighbor.
77 * @BATADV_PRIMARIES_FIRST_HOP: flag unused.
78 * @BATADV_DIRECTLINK: flag is for the first hop or if rebroadcasted from a
79 * one hop neighbor on the interface where it was originally received.
81 enum batadv_iv_flags {
82 BATADV_NOT_BEST_NEXT_HOP = 1UL << 0,
83 BATADV_PRIMARIES_FIRST_HOP = 1UL << 1,
84 BATADV_DIRECTLINK = 1UL << 2,
88 * enum batadv_icmp_packettype - ICMP message types
89 * @BATADV_ECHO_REPLY: success reply to BATADV_ECHO_REQUEST
90 * @BATADV_DESTINATION_UNREACHABLE: failure when route to destination not found
91 * @BATADV_ECHO_REQUEST: request BATADV_ECHO_REPLY from destination
92 * @BATADV_TTL_EXCEEDED: error after BATADV_ECHO_REQUEST traversed too many hops
93 * @BATADV_PARAMETER_PROBLEM: return code for malformed messages
94 * @BATADV_TP: throughput meter packet
96 enum batadv_icmp_packettype {
97 BATADV_ECHO_REPLY = 0,
98 BATADV_DESTINATION_UNREACHABLE = 3,
99 BATADV_ECHO_REQUEST = 8,
100 BATADV_TTL_EXCEEDED = 11,
101 BATADV_PARAMETER_PROBLEM = 12,
106 * enum batadv_mcast_flags - flags for multicast capabilities and settings
107 * @BATADV_MCAST_WANT_ALL_UNSNOOPABLES: we want all packets destined for
108 * 224.0.0.0/24 or ff02::1
109 * @BATADV_MCAST_WANT_ALL_IPV4: we want all IPv4 multicast packets
110 * (both link-local and routable ones)
111 * @BATADV_MCAST_WANT_ALL_IPV6: we want all IPv6 multicast packets
112 * (both link-local and routable ones)
113 * @BATADV_MCAST_WANT_NO_RTR4: we have no IPv4 multicast router and therefore
114 * only need routable IPv4 multicast packets we signed up for explicitly
115 * @BATADV_MCAST_WANT_NO_RTR6: we have no IPv6 multicast router and therefore
116 * only need routable IPv6 multicast packets we signed up for explicitly
118 enum batadv_mcast_flags {
119 BATADV_MCAST_WANT_ALL_UNSNOOPABLES = 1UL << 0,
120 BATADV_MCAST_WANT_ALL_IPV4 = 1UL << 1,
121 BATADV_MCAST_WANT_ALL_IPV6 = 1UL << 2,
122 BATADV_MCAST_WANT_NO_RTR4 = 1UL << 3,
123 BATADV_MCAST_WANT_NO_RTR6 = 1UL << 4,
126 /* tt data subtypes */
127 #define BATADV_TT_DATA_TYPE_MASK 0x0F
130 * enum batadv_tt_data_flags - flags for tt data tvlv
131 * @BATADV_TT_OGM_DIFF: TT diff propagated through OGM
132 * @BATADV_TT_REQUEST: TT request message
133 * @BATADV_TT_RESPONSE: TT response message
134 * @BATADV_TT_FULL_TABLE: contains full table to replace existing table
136 enum batadv_tt_data_flags {
137 BATADV_TT_OGM_DIFF = 1UL << 0,
138 BATADV_TT_REQUEST = 1UL << 1,
139 BATADV_TT_RESPONSE = 1UL << 2,
140 BATADV_TT_FULL_TABLE = 1UL << 4,
144 * enum batadv_vlan_flags - flags for the four MSB of any vlan ID field
145 * @BATADV_VLAN_HAS_TAG: whether the field contains a valid vlan tag or not
147 enum batadv_vlan_flags {
148 BATADV_VLAN_HAS_TAG = 1UL << 15,
152 * enum batadv_bla_claimframe - claim frame types for the bridge loop avoidance
153 * @BATADV_CLAIM_TYPE_CLAIM: claim of a client mac address
154 * @BATADV_CLAIM_TYPE_UNCLAIM: unclaim of a client mac address
155 * @BATADV_CLAIM_TYPE_ANNOUNCE: announcement of backbone with current crc
156 * @BATADV_CLAIM_TYPE_REQUEST: request of full claim table
157 * @BATADV_CLAIM_TYPE_LOOPDETECT: mesh-traversing loop detect packet
159 enum batadv_bla_claimframe {
160 BATADV_CLAIM_TYPE_CLAIM = 0x00,
161 BATADV_CLAIM_TYPE_UNCLAIM = 0x01,
162 BATADV_CLAIM_TYPE_ANNOUNCE = 0x02,
163 BATADV_CLAIM_TYPE_REQUEST = 0x03,
164 BATADV_CLAIM_TYPE_LOOPDETECT = 0x04,
168 * enum batadv_tvlv_type - tvlv type definitions
169 * @BATADV_TVLV_GW: gateway tvlv
170 * @BATADV_TVLV_DAT: distributed arp table tvlv
171 * @BATADV_TVLV_NC: network coding tvlv
172 * @BATADV_TVLV_TT: translation table tvlv
173 * @BATADV_TVLV_ROAM: roaming advertisement tvlv
174 * @BATADV_TVLV_MCAST: multicast capability tvlv
176 enum batadv_tvlv_type {
177 BATADV_TVLV_GW = 0x01,
178 BATADV_TVLV_DAT = 0x02,
179 BATADV_TVLV_NC = 0x03,
180 BATADV_TVLV_TT = 0x04,
181 BATADV_TVLV_ROAM = 0x05,
182 BATADV_TVLV_MCAST = 0x06,
186 /* the destination hardware field in the ARP frame is used to
187 * transport the claim type and the group id
189 struct batadv_bla_claim_dst {
190 __u8 magic[3]; /* FF:43:05 */
191 __u8 type; /* bla_claimframe */
192 __be16 group; /* group id */
196 * struct batadv_ogm_packet - ogm (routing protocol) packet
197 * @packet_type: batman-adv packet type, part of the general header
198 * @version: batman-adv protocol version, part of the genereal header
199 * @ttl: time to live for this packet, part of the genereal header
200 * @flags: contains routing relevant flags - see enum batadv_iv_flags
201 * @seqno: sequence identification
202 * @orig: address of the source node
203 * @prev_sender: address of the previous sender
204 * @reserved: reserved byte for alignment
205 * @tq: transmission quality
206 * @tvlv_len: length of tvlv data following the ogm header
208 struct batadv_ogm_packet {
215 __u8 prev_sender[ETH_ALEN];
221 #define BATADV_OGM_HLEN sizeof(struct batadv_ogm_packet)
224 * struct batadv_ogm2_packet - ogm2 (routing protocol) packet
225 * @packet_type: batman-adv packet type, part of the general header
226 * @version: batman-adv protocol version, part of the general header
227 * @ttl: time to live for this packet, part of the general header
228 * @flags: reserved for routing relevant flags - currently always 0
229 * @seqno: sequence number
230 * @orig: originator mac address
231 * @tvlv_len: length of the appended tvlv buffer (in bytes)
232 * @throughput: the currently flooded path throughput
234 struct batadv_ogm2_packet {
245 #define BATADV_OGM2_HLEN sizeof(struct batadv_ogm2_packet)
248 * struct batadv_elp_packet - elp (neighbor discovery) packet
249 * @packet_type: batman-adv packet type, part of the general header
250 * @version: batman-adv protocol version, part of the genereal header
251 * @orig: originator mac address
252 * @seqno: sequence number
253 * @elp_interval: currently used ELP sending interval in ms
255 struct batadv_elp_packet {
263 #define BATADV_ELP_HLEN sizeof(struct batadv_elp_packet)
266 * struct batadv_icmp_header - common members among all the ICMP packets
267 * @packet_type: batman-adv packet type, part of the general header
268 * @version: batman-adv protocol version, part of the genereal header
269 * @ttl: time to live for this packet, part of the genereal header
270 * @msg_type: ICMP packet type
271 * @dst: address of the destination node
272 * @orig: address of the source node
273 * @uid: local ICMP socket identifier
274 * @align: not used - useful for alignment purposes only
276 * This structure is used for ICMP packets parsing only and it is never sent
277 * over the wire. The alignment field at the end is there to ensure that
278 * members are padded the same way as they are in real packets.
280 struct batadv_icmp_header {
284 __u8 msg_type; /* see ICMP message types above */
292 * struct batadv_icmp_packet - ICMP packet
293 * @packet_type: batman-adv packet type, part of the general header
294 * @version: batman-adv protocol version, part of the genereal header
295 * @ttl: time to live for this packet, part of the genereal header
296 * @msg_type: ICMP packet type
297 * @dst: address of the destination node
298 * @orig: address of the source node
299 * @uid: local ICMP socket identifier
300 * @reserved: not used - useful for alignment
301 * @seqno: ICMP sequence number
303 struct batadv_icmp_packet {
307 __u8 msg_type; /* see ICMP message types above */
316 * struct batadv_icmp_tp_packet - ICMP TP Meter packet
317 * @packet_type: batman-adv packet type, part of the general header
318 * @version: batman-adv protocol version, part of the genereal header
319 * @ttl: time to live for this packet, part of the genereal header
320 * @msg_type: ICMP packet type
321 * @dst: address of the destination node
322 * @orig: address of the source node
323 * @uid: local ICMP socket identifier
324 * @subtype: TP packet subtype (see batadv_icmp_tp_subtype)
325 * @session: TP session identifier
326 * @seqno: the TP sequence number
327 * @timestamp: time when the packet has been sent. This value is filled in a
328 * TP_MSG and echoed back in the next TP_ACK so that the sender can compute the
329 * RTT. Since it is read only by the host which wrote it, there is no need to
330 * store it using network order
332 struct batadv_icmp_tp_packet {
336 __u8 msg_type; /* see ICMP message types above */
347 * enum batadv_icmp_tp_subtype - ICMP TP Meter packet subtypes
348 * @BATADV_TP_MSG: Msg from sender to receiver
349 * @BATADV_TP_ACK: acknowledgment from receiver to sender
351 enum batadv_icmp_tp_subtype {
356 #define BATADV_RR_LEN 16
359 * struct batadv_icmp_packet_rr - ICMP RouteRecord packet
360 * @packet_type: batman-adv packet type, part of the general header
361 * @version: batman-adv protocol version, part of the genereal header
362 * @ttl: time to live for this packet, part of the genereal header
363 * @msg_type: ICMP packet type
364 * @dst: address of the destination node
365 * @orig: address of the source node
366 * @uid: local ICMP socket identifier
367 * @rr_cur: number of entries the rr array
368 * @seqno: ICMP sequence number
369 * @rr: route record array
371 struct batadv_icmp_packet_rr {
375 __u8 msg_type; /* see ICMP message types above */
381 __u8 rr[BATADV_RR_LEN][ETH_ALEN];
384 #define BATADV_ICMP_MAX_PACKET_SIZE sizeof(struct batadv_icmp_packet_rr)
386 /* All packet headers in front of an ethernet header have to be completely
387 * divisible by 2 but not by 4 to make the payload after the ethernet
388 * header again 4 bytes boundary aligned.
390 * A packing of 2 is necessary to avoid extra padding at the end of the struct
391 * caused by a structure member which is larger than two bytes. Otherwise
392 * the structure would not fulfill the previously mentioned rule to avoid the
393 * misalignment of the payload after the ethernet header. It may also lead to
394 * leakage of information when the padding it not initialized before sending.
398 * struct batadv_unicast_packet - unicast packet for network payload
399 * @packet_type: batman-adv packet type, part of the general header
400 * @version: batman-adv protocol version, part of the genereal header
401 * @ttl: time to live for this packet, part of the genereal header
402 * @ttvn: translation table version number
403 * @dest: originator destination of the unicast packet
405 struct batadv_unicast_packet {
409 __u8 ttvn; /* destination translation table version number */
411 /* "4 bytes boundary + 2 bytes" long to make the payload after the
412 * following ethernet header again 4 bytes boundary aligned
417 * struct batadv_unicast_4addr_packet - extended unicast packet
418 * @u: common unicast packet header
419 * @src: address of the source
420 * @subtype: packet subtype
421 * @reserved: reserved byte for alignment
423 struct batadv_unicast_4addr_packet {
424 struct batadv_unicast_packet u;
428 /* "4 bytes boundary + 2 bytes" long to make the payload after the
429 * following ethernet header again 4 bytes boundary aligned
434 * struct batadv_frag_packet - fragmented packet
435 * @packet_type: batman-adv packet type, part of the general header
436 * @version: batman-adv protocol version, part of the genereal header
437 * @ttl: time to live for this packet, part of the genereal header
438 * @dest: final destination used when routing fragments
439 * @orig: originator of the fragment used when merging the packet
440 * @no: fragment number within this sequence
441 * @priority: priority of frame, from ToS IP precedence or 802.1p
442 * @reserved: reserved byte for alignment
443 * @seqno: sequence identification
444 * @total_size: size of the merged packet
446 struct batadv_frag_packet {
448 __u8 version; /* batman version field */
450 #if defined(__BIG_ENDIAN_BITFIELD)
454 #elif defined(__LITTLE_ENDIAN_BITFIELD)
459 #error "unknown bitfield endianness"
468 * struct batadv_bcast_packet - broadcast packet for network payload
469 * @packet_type: batman-adv packet type, part of the general header
470 * @version: batman-adv protocol version, part of the genereal header
471 * @ttl: time to live for this packet, part of the genereal header
472 * @reserved: reserved byte for alignment
473 * @seqno: sequence identification
474 * @orig: originator of the broadcast packet
476 struct batadv_bcast_packet {
478 __u8 version; /* batman version field */
483 /* "4 bytes boundary + 2 bytes" long to make the payload after the
484 * following ethernet header again 4 bytes boundary aligned
489 * struct batadv_coded_packet - network coded packet
490 * @packet_type: batman-adv packet type, part of the general header
491 * @version: batman-adv protocol version, part of the genereal header
492 * @ttl: time to live for this packet, part of the genereal header
493 * @first_source: original source of first included packet
494 * @first_orig_dest: original destinal of first included packet
495 * @first_crc: checksum of first included packet
496 * @first_ttvn: tt-version number of first included packet
497 * @second_ttl: ttl of second packet
498 * @second_dest: second receiver of this coded packet
499 * @second_source: original source of second included packet
500 * @second_orig_dest: original destination of second included packet
501 * @second_crc: checksum of second included packet
502 * @second_ttvn: tt version number of second included packet
503 * @coded_len: length of network coded part of the payload
505 struct batadv_coded_packet {
507 __u8 version; /* batman version field */
510 /* __u8 first_dest[ETH_ALEN]; - saved in mac header destination */
511 __u8 first_source[ETH_ALEN];
512 __u8 first_orig_dest[ETH_ALEN];
516 __u8 second_dest[ETH_ALEN];
517 __u8 second_source[ETH_ALEN];
518 __u8 second_orig_dest[ETH_ALEN];
524 * struct batadv_unicast_tvlv_packet - generic unicast packet with tvlv payload
525 * @packet_type: batman-adv packet type, part of the general header
526 * @version: batman-adv protocol version, part of the genereal header
527 * @ttl: time to live for this packet, part of the genereal header
528 * @reserved: reserved field (for packet alignment)
529 * @src: address of the source
530 * @dst: address of the destination
531 * @tvlv_len: length of tvlv data following the unicast tvlv header
532 * @align: 2 bytes to align the header to a 4 byte boundary
534 struct batadv_unicast_tvlv_packet {
536 __u8 version; /* batman version field */
546 * struct batadv_tvlv_hdr - base tvlv header struct
547 * @type: tvlv container type (see batadv_tvlv_type)
548 * @version: tvlv container version
549 * @len: tvlv container length
551 struct batadv_tvlv_hdr {
558 * struct batadv_tvlv_gateway_data - gateway data propagated through gw tvlv
560 * @bandwidth_down: advertised uplink download bandwidth
561 * @bandwidth_up: advertised uplink upload bandwidth
563 struct batadv_tvlv_gateway_data {
564 __be32 bandwidth_down;
569 * struct batadv_tvlv_tt_data - tt data propagated through the tt tvlv container
570 * @flags: translation table flags (see batadv_tt_data_flags)
571 * @ttvn: translation table version number
572 * @num_vlan: number of announced VLANs. In the TVLV this struct is followed by
573 * one batadv_tvlv_tt_vlan_data object per announced vlan
575 struct batadv_tvlv_tt_data {
582 * struct batadv_tvlv_tt_vlan_data - vlan specific tt data propagated through
583 * the tt tvlv container
584 * @crc: crc32 checksum of the entries belonging to this vlan
585 * @vid: vlan identifier
586 * @reserved: unused, useful for alignment purposes
588 struct batadv_tvlv_tt_vlan_data {
595 * struct batadv_tvlv_tt_change - translation table diff data
596 * @flags: status indicators concerning the non-mesh client (see
597 * batadv_tt_client_flags)
598 * @reserved: reserved field - useful for alignment purposes only
599 * @addr: mac address of non-mesh client that triggered this tt change
600 * @vid: VLAN identifier
602 struct batadv_tvlv_tt_change {
610 * struct batadv_tvlv_roam_adv - roaming advertisement
611 * @client: mac address of roaming client
612 * @vid: VLAN identifier
614 struct batadv_tvlv_roam_adv {
615 __u8 client[ETH_ALEN];
620 * struct batadv_tvlv_mcast_data - payload of a multicast tvlv
621 * @flags: multicast flags announced by the orig node
622 * @reserved: reserved field
624 struct batadv_tvlv_mcast_data {
631 #endif /* _UAPI_LINUX_BATADV_PACKET_H_ */