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
119 * @BATADV_MCAST_HAVE_MC_PTYPE_CAPA: we can parse, receive and forward
120 * batman-adv multicast packets with a multicast tracker TVLV. And all our
121 * hard interfaces have an MTU of at least 1280 bytes.
123 enum batadv_mcast_flags {
124 BATADV_MCAST_WANT_ALL_UNSNOOPABLES = 1UL << 0,
125 BATADV_MCAST_WANT_ALL_IPV4 = 1UL << 1,
126 BATADV_MCAST_WANT_ALL_IPV6 = 1UL << 2,
127 BATADV_MCAST_WANT_NO_RTR4 = 1UL << 3,
128 BATADV_MCAST_WANT_NO_RTR6 = 1UL << 4,
129 BATADV_MCAST_HAVE_MC_PTYPE_CAPA = 1UL << 5,
132 /* tt data subtypes */
133 #define BATADV_TT_DATA_TYPE_MASK 0x0F
136 * enum batadv_tt_data_flags - flags for tt data tvlv
137 * @BATADV_TT_OGM_DIFF: TT diff propagated through OGM
138 * @BATADV_TT_REQUEST: TT request message
139 * @BATADV_TT_RESPONSE: TT response message
140 * @BATADV_TT_FULL_TABLE: contains full table to replace existing table
142 enum batadv_tt_data_flags {
143 BATADV_TT_OGM_DIFF = 1UL << 0,
144 BATADV_TT_REQUEST = 1UL << 1,
145 BATADV_TT_RESPONSE = 1UL << 2,
146 BATADV_TT_FULL_TABLE = 1UL << 4,
150 * enum batadv_vlan_flags - flags for the four MSB of any vlan ID field
151 * @BATADV_VLAN_HAS_TAG: whether the field contains a valid vlan tag or not
153 enum batadv_vlan_flags {
154 BATADV_VLAN_HAS_TAG = 1UL << 15,
158 * enum batadv_bla_claimframe - claim frame types for the bridge loop avoidance
159 * @BATADV_CLAIM_TYPE_CLAIM: claim of a client mac address
160 * @BATADV_CLAIM_TYPE_UNCLAIM: unclaim of a client mac address
161 * @BATADV_CLAIM_TYPE_ANNOUNCE: announcement of backbone with current crc
162 * @BATADV_CLAIM_TYPE_REQUEST: request of full claim table
163 * @BATADV_CLAIM_TYPE_LOOPDETECT: mesh-traversing loop detect packet
165 enum batadv_bla_claimframe {
166 BATADV_CLAIM_TYPE_CLAIM = 0x00,
167 BATADV_CLAIM_TYPE_UNCLAIM = 0x01,
168 BATADV_CLAIM_TYPE_ANNOUNCE = 0x02,
169 BATADV_CLAIM_TYPE_REQUEST = 0x03,
170 BATADV_CLAIM_TYPE_LOOPDETECT = 0x04,
174 * enum batadv_tvlv_type - tvlv type definitions
175 * @BATADV_TVLV_GW: gateway tvlv
176 * @BATADV_TVLV_DAT: distributed arp table tvlv
177 * @BATADV_TVLV_NC: network coding tvlv
178 * @BATADV_TVLV_TT: translation table tvlv
179 * @BATADV_TVLV_ROAM: roaming advertisement tvlv
180 * @BATADV_TVLV_MCAST: multicast capability tvlv
181 * @BATADV_TVLV_MCAST_TRACKER: multicast tracker tvlv
183 enum batadv_tvlv_type {
184 BATADV_TVLV_GW = 0x01,
185 BATADV_TVLV_DAT = 0x02,
186 BATADV_TVLV_NC = 0x03,
187 BATADV_TVLV_TT = 0x04,
188 BATADV_TVLV_ROAM = 0x05,
189 BATADV_TVLV_MCAST = 0x06,
190 BATADV_TVLV_MCAST_TRACKER = 0x07,
194 /* the destination hardware field in the ARP frame is used to
195 * transport the claim type and the group id
197 struct batadv_bla_claim_dst {
198 __u8 magic[3]; /* FF:43:05 */
199 __u8 type; /* bla_claimframe */
200 __be16 group; /* group id */
204 * struct batadv_ogm_packet - ogm (routing protocol) packet
205 * @packet_type: batman-adv packet type, part of the general header
206 * @version: batman-adv protocol version, part of the general header
207 * @ttl: time to live for this packet, part of the general header
208 * @flags: contains routing relevant flags - see enum batadv_iv_flags
209 * @seqno: sequence identification
210 * @orig: address of the source node
211 * @prev_sender: address of the previous sender
212 * @reserved: reserved byte for alignment
213 * @tq: transmission quality
214 * @tvlv_len: length of tvlv data following the ogm header
216 struct batadv_ogm_packet {
223 __u8 prev_sender[ETH_ALEN];
229 #define BATADV_OGM_HLEN sizeof(struct batadv_ogm_packet)
232 * struct batadv_ogm2_packet - ogm2 (routing protocol) packet
233 * @packet_type: batman-adv packet type, part of the general header
234 * @version: batman-adv protocol version, part of the general header
235 * @ttl: time to live for this packet, part of the general header
236 * @flags: reserved for routing relevant flags - currently always 0
237 * @seqno: sequence number
238 * @orig: originator mac address
239 * @tvlv_len: length of the appended tvlv buffer (in bytes)
240 * @throughput: the currently flooded path throughput
242 struct batadv_ogm2_packet {
253 #define BATADV_OGM2_HLEN sizeof(struct batadv_ogm2_packet)
256 * struct batadv_elp_packet - elp (neighbor discovery) packet
257 * @packet_type: batman-adv packet type, part of the general header
258 * @version: batman-adv protocol version, part of the general header
259 * @orig: originator mac address
260 * @seqno: sequence number
261 * @elp_interval: currently used ELP sending interval in ms
263 struct batadv_elp_packet {
271 #define BATADV_ELP_HLEN sizeof(struct batadv_elp_packet)
274 * struct batadv_icmp_header - common members among all the ICMP packets
275 * @packet_type: batman-adv packet type, part of the general header
276 * @version: batman-adv protocol version, part of the general header
277 * @ttl: time to live for this packet, part of the general header
278 * @msg_type: ICMP packet type
279 * @dst: address of the destination node
280 * @orig: address of the source node
281 * @uid: local ICMP socket identifier
282 * @align: not used - useful for alignment purposes only
284 * This structure is used for ICMP packet parsing only and it is never sent
285 * over the wire. The alignment field at the end is there to ensure that
286 * members are padded the same way as they are in real packets.
288 struct batadv_icmp_header {
292 __u8 msg_type; /* see ICMP message types above */
300 * struct batadv_icmp_packet - ICMP packet
301 * @packet_type: batman-adv packet type, part of the general header
302 * @version: batman-adv protocol version, part of the general header
303 * @ttl: time to live for this packet, part of the general header
304 * @msg_type: ICMP packet type
305 * @dst: address of the destination node
306 * @orig: address of the source node
307 * @uid: local ICMP socket identifier
308 * @reserved: not used - useful for alignment
309 * @seqno: ICMP sequence number
311 struct batadv_icmp_packet {
315 __u8 msg_type; /* see ICMP message types above */
324 * struct batadv_icmp_tp_packet - ICMP TP Meter packet
325 * @packet_type: batman-adv packet type, part of the general header
326 * @version: batman-adv protocol version, part of the general header
327 * @ttl: time to live for this packet, part of the general header
328 * @msg_type: ICMP packet type
329 * @dst: address of the destination node
330 * @orig: address of the source node
331 * @uid: local ICMP socket identifier
332 * @subtype: TP packet subtype (see batadv_icmp_tp_subtype)
333 * @session: TP session identifier
334 * @seqno: the TP sequence number
335 * @timestamp: time when the packet has been sent. This value is filled in a
336 * TP_MSG and echoed back in the next TP_ACK so that the sender can compute the
337 * RTT. Since it is read only by the host which wrote it, there is no need to
338 * store it using network order
340 struct batadv_icmp_tp_packet {
344 __u8 msg_type; /* see ICMP message types above */
355 * enum batadv_icmp_tp_subtype - ICMP TP Meter packet subtypes
356 * @BATADV_TP_MSG: Msg from sender to receiver
357 * @BATADV_TP_ACK: acknowledgment from receiver to sender
359 enum batadv_icmp_tp_subtype {
364 #define BATADV_RR_LEN 16
367 * struct batadv_icmp_packet_rr - ICMP RouteRecord packet
368 * @packet_type: batman-adv packet type, part of the general header
369 * @version: batman-adv protocol version, part of the general header
370 * @ttl: time to live for this packet, part of the general header
371 * @msg_type: ICMP packet type
372 * @dst: address of the destination node
373 * @orig: address of the source node
374 * @uid: local ICMP socket identifier
375 * @rr_cur: number of entries the rr array
376 * @seqno: ICMP sequence number
377 * @rr: route record array
379 struct batadv_icmp_packet_rr {
383 __u8 msg_type; /* see ICMP message types above */
389 __u8 rr[BATADV_RR_LEN][ETH_ALEN];
392 #define BATADV_ICMP_MAX_PACKET_SIZE sizeof(struct batadv_icmp_packet_rr)
394 /* All packet headers in front of an ethernet header have to be completely
395 * divisible by 2 but not by 4 to make the payload after the ethernet
396 * header again 4 bytes boundary aligned.
398 * A packing of 2 is necessary to avoid extra padding at the end of the struct
399 * caused by a structure member which is larger than two bytes. Otherwise
400 * the structure would not fulfill the previously mentioned rule to avoid the
401 * misalignment of the payload after the ethernet header. It may also lead to
402 * leakage of information when the padding it not initialized before sending.
406 * struct batadv_unicast_packet - unicast packet for network payload
407 * @packet_type: batman-adv packet type, part of the general header
408 * @version: batman-adv protocol version, part of the general header
409 * @ttl: time to live for this packet, part of the general header
410 * @ttvn: translation table version number
411 * @dest: originator destination of the unicast packet
413 struct batadv_unicast_packet {
417 __u8 ttvn; /* destination translation table version number */
419 /* "4 bytes boundary + 2 bytes" long to make the payload after the
420 * following ethernet header again 4 bytes boundary aligned
425 * struct batadv_unicast_4addr_packet - extended unicast packet
426 * @u: common unicast packet header
427 * @src: address of the source
428 * @subtype: packet subtype
429 * @reserved: reserved byte for alignment
431 struct batadv_unicast_4addr_packet {
432 struct batadv_unicast_packet u;
436 /* "4 bytes boundary + 2 bytes" long to make the payload after the
437 * following ethernet header again 4 bytes boundary aligned
442 * struct batadv_frag_packet - fragmented packet
443 * @packet_type: batman-adv packet type, part of the general header
444 * @version: batman-adv protocol version, part of the general header
445 * @ttl: time to live for this packet, part of the general header
446 * @dest: final destination used when routing fragments
447 * @orig: originator of the fragment used when merging the packet
448 * @no: fragment number within this sequence
449 * @priority: priority of frame, from ToS IP precedence or 802.1p
450 * @reserved: reserved byte for alignment
451 * @seqno: sequence identification
452 * @total_size: size of the merged packet
454 struct batadv_frag_packet {
456 __u8 version; /* batman version field */
458 #if defined(__BIG_ENDIAN_BITFIELD)
462 #elif defined(__LITTLE_ENDIAN_BITFIELD)
467 #error "unknown bitfield endianness"
476 * struct batadv_bcast_packet - broadcast packet for network payload
477 * @packet_type: batman-adv packet type, part of the general header
478 * @version: batman-adv protocol version, part of the general header
479 * @ttl: time to live for this packet, part of the general header
480 * @reserved: reserved byte for alignment
481 * @seqno: sequence identification
482 * @orig: originator of the broadcast packet
484 struct batadv_bcast_packet {
486 __u8 version; /* batman version field */
491 /* "4 bytes boundary + 2 bytes" long to make the payload after the
492 * following ethernet header again 4 bytes boundary aligned
497 * struct batadv_mcast_packet - multicast packet for network payload
498 * @packet_type: batman-adv packet type, part of the general header
499 * @version: batman-adv protocol version, part of the general header
500 * @ttl: time to live for this packet, part of the general header
501 * @reserved: reserved byte for alignment
502 * @tvlv_len: length of the appended tvlv buffer (in bytes)
504 struct batadv_mcast_packet {
510 /* "4 bytes boundary + 2 bytes" long to make the payload after the
511 * following ethernet header again 4 bytes boundary aligned
516 * struct batadv_coded_packet - network coded packet
517 * @packet_type: batman-adv packet type, part of the general header
518 * @version: batman-adv protocol version, part of the general header
519 * @ttl: time to live for this packet, part of the general header
520 * @first_source: original source of first included packet
521 * @first_orig_dest: original destination of first included packet
522 * @first_crc: checksum of first included packet
523 * @first_ttvn: tt-version number of first included packet
524 * @second_ttl: ttl of second packet
525 * @second_dest: second receiver of this coded packet
526 * @second_source: original source of second included packet
527 * @second_orig_dest: original destination of second included packet
528 * @second_crc: checksum of second included packet
529 * @second_ttvn: tt version number of second included packet
530 * @coded_len: length of network coded part of the payload
532 struct batadv_coded_packet {
534 __u8 version; /* batman version field */
537 /* __u8 first_dest[ETH_ALEN]; - saved in mac header destination */
538 __u8 first_source[ETH_ALEN];
539 __u8 first_orig_dest[ETH_ALEN];
543 __u8 second_dest[ETH_ALEN];
544 __u8 second_source[ETH_ALEN];
545 __u8 second_orig_dest[ETH_ALEN];
551 * struct batadv_unicast_tvlv_packet - generic unicast packet with tvlv payload
552 * @packet_type: batman-adv packet type, part of the general header
553 * @version: batman-adv protocol version, part of the general header
554 * @ttl: time to live for this packet, part of the general header
555 * @reserved: reserved field (for packet alignment)
556 * @src: address of the source
557 * @dst: address of the destination
558 * @tvlv_len: length of tvlv data following the unicast tvlv header
559 * @align: 2 bytes to align the header to a 4 byte boundary
561 struct batadv_unicast_tvlv_packet {
563 __u8 version; /* batman version field */
573 * struct batadv_tvlv_hdr - base tvlv header struct
574 * @type: tvlv container type (see batadv_tvlv_type)
575 * @version: tvlv container version
576 * @len: tvlv container length
578 struct batadv_tvlv_hdr {
585 * struct batadv_tvlv_gateway_data - gateway data propagated through gw tvlv
587 * @bandwidth_down: advertised uplink download bandwidth
588 * @bandwidth_up: advertised uplink upload bandwidth
590 struct batadv_tvlv_gateway_data {
591 __be32 bandwidth_down;
596 * struct batadv_tvlv_tt_data - tt data propagated through the tt tvlv container
597 * @flags: translation table flags (see batadv_tt_data_flags)
598 * @ttvn: translation table version number
599 * @num_vlan: number of announced VLANs. In the TVLV this struct is followed by
600 * one batadv_tvlv_tt_vlan_data object per announced vlan
602 struct batadv_tvlv_tt_data {
609 * struct batadv_tvlv_tt_vlan_data - vlan specific tt data propagated through
610 * the tt tvlv container
611 * @crc: crc32 checksum of the entries belonging to this vlan
612 * @vid: vlan identifier
613 * @reserved: unused, useful for alignment purposes
615 struct batadv_tvlv_tt_vlan_data {
622 * struct batadv_tvlv_tt_change - translation table diff data
623 * @flags: status indicators concerning the non-mesh client (see
624 * batadv_tt_client_flags)
625 * @reserved: reserved field - useful for alignment purposes only
626 * @addr: mac address of non-mesh client that triggered this tt change
627 * @vid: VLAN identifier
629 struct batadv_tvlv_tt_change {
637 * struct batadv_tvlv_roam_adv - roaming advertisement
638 * @client: mac address of roaming client
639 * @vid: VLAN identifier
641 struct batadv_tvlv_roam_adv {
642 __u8 client[ETH_ALEN];
647 * struct batadv_tvlv_mcast_data - payload of a multicast tvlv
648 * @flags: multicast flags announced by the orig node
649 * @reserved: reserved field
651 struct batadv_tvlv_mcast_data {
657 * struct batadv_tvlv_mcast_tracker - payload of a multicast tracker tvlv
658 * @num_dests: number of subsequent destination originator MAC addresses
660 struct batadv_tvlv_mcast_tracker {
666 #endif /* _UAPI_LINUX_BATADV_PACKET_H_ */