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/stddef.h>
13 #include <linux/types.h>
16 * batadv_tp_is_error() - Check throughput meter return code for error
17 * @n: throughput meter return code
19 * Return: 0 when not error was detected, != 0 otherwise
21 #define batadv_tp_is_error(n) ((__u8)(n) > 127 ? 1 : 0)
24 * enum batadv_packettype - types for batman-adv encapsulated packets
25 * @BATADV_IV_OGM: originator messages for B.A.T.M.A.N. IV
26 * @BATADV_BCAST: broadcast packets carrying broadcast payload
27 * @BATADV_CODED: network coded packets
28 * @BATADV_ELP: echo location packets for B.A.T.M.A.N. V
29 * @BATADV_OGM2: originator messages for B.A.T.M.A.N. V
30 * @BATADV_MCAST: multicast packet with multiple destination addresses
32 * @BATADV_UNICAST: unicast packets carrying unicast payload traffic
33 * @BATADV_UNICAST_FRAG: unicast packets carrying a fragment of the original
35 * @BATADV_UNICAST_4ADDR: unicast packet including the originator address of
37 * @BATADV_ICMP: unicast packet like IP ICMP used for ping or traceroute
38 * @BATADV_UNICAST_TVLV: unicast packet carrying TVLV containers
40 enum batadv_packettype
{
41 /* 0x00 - 0x3f: local packets or special rules for handling */
48 /* 0x40 - 0x7f: unicast */
49 #define BATADV_UNICAST_MIN 0x40
50 BATADV_UNICAST
= 0x40,
51 BATADV_UNICAST_FRAG
= 0x41,
52 BATADV_UNICAST_4ADDR
= 0x42,
54 BATADV_UNICAST_TVLV
= 0x44,
55 #define BATADV_UNICAST_MAX 0x7f
56 /* 0x80 - 0xff: reserved */
60 * enum batadv_subtype - packet subtype for unicast4addr
61 * @BATADV_P_DATA: user payload
62 * @BATADV_P_DAT_DHT_GET: DHT request message
63 * @BATADV_P_DAT_DHT_PUT: DHT store message
64 * @BATADV_P_DAT_CACHE_REPLY: ARP reply generated by DAT
68 BATADV_P_DAT_DHT_GET
= 0x02,
69 BATADV_P_DAT_DHT_PUT
= 0x03,
70 BATADV_P_DAT_CACHE_REPLY
= 0x04,
73 /* this file is included by batctl which needs these defines */
74 #define BATADV_COMPAT_VERSION 15
77 * enum batadv_iv_flags - flags used in B.A.T.M.A.N. IV OGM packets
78 * @BATADV_NOT_BEST_NEXT_HOP: flag is set when the ogm packet is forwarded and
79 * was previously received from someone other than the best neighbor.
80 * @BATADV_PRIMARIES_FIRST_HOP: flag unused.
81 * @BATADV_DIRECTLINK: flag is for the first hop or if rebroadcasted from a
82 * one hop neighbor on the interface where it was originally received.
84 enum batadv_iv_flags
{
85 BATADV_NOT_BEST_NEXT_HOP
= 1UL << 0,
86 BATADV_PRIMARIES_FIRST_HOP
= 1UL << 1,
87 BATADV_DIRECTLINK
= 1UL << 2,
91 * enum batadv_icmp_packettype - ICMP message types
92 * @BATADV_ECHO_REPLY: success reply to BATADV_ECHO_REQUEST
93 * @BATADV_DESTINATION_UNREACHABLE: failure when route to destination not found
94 * @BATADV_ECHO_REQUEST: request BATADV_ECHO_REPLY from destination
95 * @BATADV_TTL_EXCEEDED: error after BATADV_ECHO_REQUEST traversed too many hops
96 * @BATADV_PARAMETER_PROBLEM: return code for malformed messages
97 * @BATADV_TP: throughput meter packet
99 enum batadv_icmp_packettype
{
100 BATADV_ECHO_REPLY
= 0,
101 BATADV_DESTINATION_UNREACHABLE
= 3,
102 BATADV_ECHO_REQUEST
= 8,
103 BATADV_TTL_EXCEEDED
= 11,
104 BATADV_PARAMETER_PROBLEM
= 12,
109 * enum batadv_mcast_flags - flags for multicast capabilities and settings
110 * @BATADV_MCAST_WANT_ALL_UNSNOOPABLES: we want all packets destined for
111 * 224.0.0.0/24 or ff02::1
112 * @BATADV_MCAST_WANT_ALL_IPV4: we want all IPv4 multicast packets
113 * (both link-local and routable ones)
114 * @BATADV_MCAST_WANT_ALL_IPV6: we want all IPv6 multicast packets
115 * (both link-local and routable ones)
116 * @BATADV_MCAST_WANT_NO_RTR4: we have no IPv4 multicast router and therefore
117 * only need routable IPv4 multicast packets we signed up for explicitly
118 * @BATADV_MCAST_WANT_NO_RTR6: we have no IPv6 multicast router and therefore
119 * only need routable IPv6 multicast packets we signed up for explicitly
120 * @BATADV_MCAST_HAVE_MC_PTYPE_CAPA: we can parse, receive and forward
121 * batman-adv multicast packets with a multicast tracker TVLV. And all our
122 * hard interfaces have an MTU of at least 1280 bytes.
124 enum batadv_mcast_flags
{
125 BATADV_MCAST_WANT_ALL_UNSNOOPABLES
= 1UL << 0,
126 BATADV_MCAST_WANT_ALL_IPV4
= 1UL << 1,
127 BATADV_MCAST_WANT_ALL_IPV6
= 1UL << 2,
128 BATADV_MCAST_WANT_NO_RTR4
= 1UL << 3,
129 BATADV_MCAST_WANT_NO_RTR6
= 1UL << 4,
130 BATADV_MCAST_HAVE_MC_PTYPE_CAPA
= 1UL << 5,
133 /* tt data subtypes */
134 #define BATADV_TT_DATA_TYPE_MASK 0x0F
137 * enum batadv_tt_data_flags - flags for tt data tvlv
138 * @BATADV_TT_OGM_DIFF: TT diff propagated through OGM
139 * @BATADV_TT_REQUEST: TT request message
140 * @BATADV_TT_RESPONSE: TT response message
141 * @BATADV_TT_FULL_TABLE: contains full table to replace existing table
143 enum batadv_tt_data_flags
{
144 BATADV_TT_OGM_DIFF
= 1UL << 0,
145 BATADV_TT_REQUEST
= 1UL << 1,
146 BATADV_TT_RESPONSE
= 1UL << 2,
147 BATADV_TT_FULL_TABLE
= 1UL << 4,
151 * enum batadv_vlan_flags - flags for the four MSB of any vlan ID field
152 * @BATADV_VLAN_HAS_TAG: whether the field contains a valid vlan tag or not
154 enum batadv_vlan_flags
{
155 BATADV_VLAN_HAS_TAG
= 1UL << 15,
159 * enum batadv_bla_claimframe - claim frame types for the bridge loop avoidance
160 * @BATADV_CLAIM_TYPE_CLAIM: claim of a client mac address
161 * @BATADV_CLAIM_TYPE_UNCLAIM: unclaim of a client mac address
162 * @BATADV_CLAIM_TYPE_ANNOUNCE: announcement of backbone with current crc
163 * @BATADV_CLAIM_TYPE_REQUEST: request of full claim table
164 * @BATADV_CLAIM_TYPE_LOOPDETECT: mesh-traversing loop detect packet
166 enum batadv_bla_claimframe
{
167 BATADV_CLAIM_TYPE_CLAIM
= 0x00,
168 BATADV_CLAIM_TYPE_UNCLAIM
= 0x01,
169 BATADV_CLAIM_TYPE_ANNOUNCE
= 0x02,
170 BATADV_CLAIM_TYPE_REQUEST
= 0x03,
171 BATADV_CLAIM_TYPE_LOOPDETECT
= 0x04,
175 * enum batadv_tvlv_type - tvlv type definitions
176 * @BATADV_TVLV_GW: gateway tvlv
177 * @BATADV_TVLV_DAT: distributed arp table tvlv
178 * @BATADV_TVLV_NC: network coding tvlv
179 * @BATADV_TVLV_TT: translation table tvlv
180 * @BATADV_TVLV_ROAM: roaming advertisement tvlv
181 * @BATADV_TVLV_MCAST: multicast capability tvlv
182 * @BATADV_TVLV_MCAST_TRACKER: multicast tracker tvlv
184 enum batadv_tvlv_type
{
185 BATADV_TVLV_GW
= 0x01,
186 BATADV_TVLV_DAT
= 0x02,
187 BATADV_TVLV_NC
= 0x03,
188 BATADV_TVLV_TT
= 0x04,
189 BATADV_TVLV_ROAM
= 0x05,
190 BATADV_TVLV_MCAST
= 0x06,
191 BATADV_TVLV_MCAST_TRACKER
= 0x07,
195 /* the destination hardware field in the ARP frame is used to
196 * transport the claim type and the group id
198 struct batadv_bla_claim_dst
{
199 __u8 magic
[3]; /* FF:43:05 */
200 __u8 type
; /* bla_claimframe */
201 __be16 group
; /* group id */
205 * struct batadv_ogm_packet - ogm (routing protocol) packet
206 * @packet_type: batman-adv packet type, part of the general header
207 * @version: batman-adv protocol version, part of the general header
208 * @ttl: time to live for this packet, part of the general header
209 * @flags: contains routing relevant flags - see enum batadv_iv_flags
210 * @seqno: sequence identification
211 * @orig: address of the source node
212 * @prev_sender: address of the previous sender
213 * @reserved: reserved byte for alignment
214 * @tq: transmission quality
215 * @tvlv_len: length of tvlv data following the ogm header
217 struct batadv_ogm_packet
{
224 __u8 prev_sender
[ETH_ALEN
];
230 #define BATADV_OGM_HLEN sizeof(struct batadv_ogm_packet)
233 * struct batadv_ogm2_packet - ogm2 (routing protocol) packet
234 * @packet_type: batman-adv packet type, part of the general header
235 * @version: batman-adv protocol version, part of the general header
236 * @ttl: time to live for this packet, part of the general header
237 * @flags: reserved for routing relevant flags - currently always 0
238 * @seqno: sequence number
239 * @orig: originator mac address
240 * @tvlv_len: length of the appended tvlv buffer (in bytes)
241 * @throughput: the currently flooded path throughput
243 struct batadv_ogm2_packet
{
254 #define BATADV_OGM2_HLEN sizeof(struct batadv_ogm2_packet)
257 * struct batadv_elp_packet - elp (neighbor discovery) packet
258 * @packet_type: batman-adv packet type, part of the general header
259 * @version: batman-adv protocol version, part of the general header
260 * @orig: originator mac address
261 * @seqno: sequence number
262 * @elp_interval: currently used ELP sending interval in ms
264 struct batadv_elp_packet
{
272 #define BATADV_ELP_HLEN sizeof(struct batadv_elp_packet)
275 * struct batadv_icmp_header - common members among all the ICMP packets
276 * @packet_type: batman-adv packet type, part of the general header
277 * @version: batman-adv protocol version, part of the general header
278 * @ttl: time to live for this packet, part of the general header
279 * @msg_type: ICMP packet type
280 * @dst: address of the destination node
281 * @orig: address of the source node
282 * @uid: local ICMP socket identifier
283 * @align: not used - useful for alignment purposes only
285 * This structure is used for ICMP packet parsing only and it is never sent
286 * over the wire. The alignment field at the end is there to ensure that
287 * members are padded the same way as they are in real packets.
289 struct batadv_icmp_header
{
293 __u8 msg_type
; /* see ICMP message types above */
301 * struct batadv_icmp_packet - ICMP packet
302 * @packet_type: batman-adv packet type, part of the general header
303 * @version: batman-adv protocol version, part of the general header
304 * @ttl: time to live for this packet, part of the general header
305 * @msg_type: ICMP packet type
306 * @dst: address of the destination node
307 * @orig: address of the source node
308 * @uid: local ICMP socket identifier
309 * @reserved: not used - useful for alignment
310 * @seqno: ICMP sequence number
312 struct batadv_icmp_packet
{
316 __u8 msg_type
; /* see ICMP message types above */
325 * struct batadv_icmp_tp_packet - ICMP TP Meter packet
326 * @packet_type: batman-adv packet type, part of the general header
327 * @version: batman-adv protocol version, part of the general header
328 * @ttl: time to live for this packet, part of the general header
329 * @msg_type: ICMP packet type
330 * @dst: address of the destination node
331 * @orig: address of the source node
332 * @uid: local ICMP socket identifier
333 * @subtype: TP packet subtype (see batadv_icmp_tp_subtype)
334 * @session: TP session identifier
335 * @seqno: the TP sequence number
336 * @timestamp: time when the packet has been sent. This value is filled in a
337 * TP_MSG and echoed back in the next TP_ACK so that the sender can compute the
338 * RTT. Since it is read only by the host which wrote it, there is no need to
339 * store it using network order
341 struct batadv_icmp_tp_packet
{
345 __u8 msg_type
; /* see ICMP message types above */
356 * enum batadv_icmp_tp_subtype - ICMP TP Meter packet subtypes
357 * @BATADV_TP_MSG: Msg from sender to receiver
358 * @BATADV_TP_ACK: acknowledgment from receiver to sender
360 enum batadv_icmp_tp_subtype
{
365 #define BATADV_RR_LEN 16
368 * struct batadv_icmp_packet_rr - ICMP RouteRecord packet
369 * @packet_type: batman-adv packet type, part of the general header
370 * @version: batman-adv protocol version, part of the general header
371 * @ttl: time to live for this packet, part of the general header
372 * @msg_type: ICMP packet type
373 * @dst: address of the destination node
374 * @orig: address of the source node
375 * @uid: local ICMP socket identifier
376 * @rr_cur: number of entries the rr array
377 * @seqno: ICMP sequence number
378 * @rr: route record array
380 struct batadv_icmp_packet_rr
{
384 __u8 msg_type
; /* see ICMP message types above */
390 __u8 rr
[BATADV_RR_LEN
][ETH_ALEN
];
393 #define BATADV_ICMP_MAX_PACKET_SIZE sizeof(struct batadv_icmp_packet_rr)
395 /* All packet headers in front of an ethernet header have to be completely
396 * divisible by 2 but not by 4 to make the payload after the ethernet
397 * header again 4 bytes boundary aligned.
399 * A packing of 2 is necessary to avoid extra padding at the end of the struct
400 * caused by a structure member which is larger than two bytes. Otherwise
401 * the structure would not fulfill the previously mentioned rule to avoid the
402 * misalignment of the payload after the ethernet header. It may also lead to
403 * leakage of information when the padding it not initialized before sending.
407 * struct batadv_unicast_packet - unicast packet for network payload
408 * @packet_type: batman-adv packet type, part of the general header
409 * @version: batman-adv protocol version, part of the general header
410 * @ttl: time to live for this packet, part of the general header
411 * @ttvn: translation table version number
412 * @dest: originator destination of the unicast packet
414 struct batadv_unicast_packet
{
418 __u8 ttvn
; /* destination translation table version number */
420 /* "4 bytes boundary + 2 bytes" long to make the payload after the
421 * following ethernet header again 4 bytes boundary aligned
426 * struct batadv_unicast_4addr_packet - extended unicast packet
427 * @u: common unicast packet header
428 * @src: address of the source
429 * @subtype: packet subtype
430 * @reserved: reserved byte for alignment
432 struct batadv_unicast_4addr_packet
{
433 struct batadv_unicast_packet u
;
437 /* "4 bytes boundary + 2 bytes" long to make the payload after the
438 * following ethernet header again 4 bytes boundary aligned
443 * struct batadv_frag_packet - fragmented packet
444 * @packet_type: batman-adv packet type, part of the general header
445 * @version: batman-adv protocol version, part of the general header
446 * @ttl: time to live for this packet, part of the general header
447 * @dest: final destination used when routing fragments
448 * @orig: originator of the fragment used when merging the packet
449 * @no: fragment number within this sequence
450 * @priority: priority of frame, from ToS IP precedence or 802.1p
451 * @reserved: reserved byte for alignment
452 * @seqno: sequence identification
453 * @total_size: size of the merged packet
455 struct batadv_frag_packet
{
457 __u8 version
; /* batman version field */
459 #if defined(__BIG_ENDIAN_BITFIELD)
463 #elif defined(__LITTLE_ENDIAN_BITFIELD)
468 #error "unknown bitfield endianness"
477 * struct batadv_bcast_packet - broadcast packet for network payload
478 * @packet_type: batman-adv packet type, part of the general header
479 * @version: batman-adv protocol version, part of the general header
480 * @ttl: time to live for this packet, part of the general header
481 * @reserved: reserved byte for alignment
482 * @seqno: sequence identification
483 * @orig: originator of the broadcast packet
485 struct batadv_bcast_packet
{
487 __u8 version
; /* batman version field */
492 /* "4 bytes boundary + 2 bytes" long to make the payload after the
493 * following ethernet header again 4 bytes boundary aligned
498 * struct batadv_mcast_packet - multicast packet for network payload
499 * @packet_type: batman-adv packet type, part of the general header
500 * @version: batman-adv protocol version, part of the general header
501 * @ttl: time to live for this packet, part of the general header
502 * @reserved: reserved byte for alignment
503 * @tvlv_len: length of the appended tvlv buffer (in bytes)
505 struct batadv_mcast_packet
{
511 /* "4 bytes boundary + 2 bytes" long to make the payload after the
512 * following ethernet header again 4 bytes boundary aligned
517 * struct batadv_coded_packet - network coded packet
518 * @packet_type: batman-adv packet type, part of the general header
519 * @version: batman-adv protocol version, part of the general header
520 * @ttl: time to live for this packet, part of the general header
521 * @first_source: original source of first included packet
522 * @first_orig_dest: original destination of first included packet
523 * @first_crc: checksum of first included packet
524 * @first_ttvn: tt-version number of first included packet
525 * @second_ttl: ttl of second packet
526 * @second_dest: second receiver of this coded packet
527 * @second_source: original source of second included packet
528 * @second_orig_dest: original destination of second included packet
529 * @second_crc: checksum of second included packet
530 * @second_ttvn: tt version number of second included packet
531 * @coded_len: length of network coded part of the payload
533 struct batadv_coded_packet
{
535 __u8 version
; /* batman version field */
538 /* __u8 first_dest[ETH_ALEN]; - saved in mac header destination */
539 __u8 first_source
[ETH_ALEN
];
540 __u8 first_orig_dest
[ETH_ALEN
];
544 __u8 second_dest
[ETH_ALEN
];
545 __u8 second_source
[ETH_ALEN
];
546 __u8 second_orig_dest
[ETH_ALEN
];
552 * struct batadv_unicast_tvlv_packet - generic unicast packet with tvlv payload
553 * @packet_type: batman-adv packet type, part of the general header
554 * @version: batman-adv protocol version, part of the general header
555 * @ttl: time to live for this packet, part of the general header
556 * @reserved: reserved field (for packet alignment)
557 * @src: address of the source
558 * @dst: address of the destination
559 * @tvlv_len: length of tvlv data following the unicast tvlv header
560 * @align: 2 bytes to align the header to a 4 byte boundary
562 struct batadv_unicast_tvlv_packet
{
564 __u8 version
; /* batman version field */
574 * struct batadv_tvlv_hdr - base tvlv header struct
575 * @type: tvlv container type (see batadv_tvlv_type)
576 * @version: tvlv container version
577 * @len: tvlv container length
579 struct batadv_tvlv_hdr
{
586 * struct batadv_tvlv_gateway_data - gateway data propagated through gw tvlv
588 * @bandwidth_down: advertised uplink download bandwidth
589 * @bandwidth_up: advertised uplink upload bandwidth
591 struct batadv_tvlv_gateway_data
{
592 __be32 bandwidth_down
;
597 * struct batadv_tvlv_tt_vlan_data - vlan specific tt data propagated through
598 * the tt tvlv container
599 * @crc: crc32 checksum of the entries belonging to this vlan
600 * @vid: vlan identifier
601 * @reserved: unused, useful for alignment purposes
603 struct batadv_tvlv_tt_vlan_data
{
610 * struct batadv_tvlv_tt_data - tt data propagated through the tt tvlv container
611 * @flags: translation table flags (see batadv_tt_data_flags)
612 * @ttvn: translation table version number
613 * @num_vlan: number of announced VLANs. In the TVLV this struct is followed by
614 * one batadv_tvlv_tt_vlan_data object per announced vlan
615 * @vlan_data: array of batadv_tvlv_tt_vlan_data objects
617 struct batadv_tvlv_tt_data
{
621 struct batadv_tvlv_tt_vlan_data vlan_data
[] __counted_by_be(num_vlan
);
625 * struct batadv_tvlv_tt_change - translation table diff data
626 * @flags: status indicators concerning the non-mesh client (see
627 * batadv_tt_client_flags)
628 * @reserved: reserved field - useful for alignment purposes only
629 * @addr: mac address of non-mesh client that triggered this tt change
630 * @vid: VLAN identifier
632 struct batadv_tvlv_tt_change
{
640 * struct batadv_tvlv_roam_adv - roaming advertisement
641 * @client: mac address of roaming client
642 * @vid: VLAN identifier
644 struct batadv_tvlv_roam_adv
{
645 __u8 client
[ETH_ALEN
];
650 * struct batadv_tvlv_mcast_data - payload of a multicast tvlv
651 * @flags: multicast flags announced by the orig node
652 * @reserved: reserved field
654 struct batadv_tvlv_mcast_data
{
660 * struct batadv_tvlv_mcast_tracker - payload of a multicast tracker tvlv
661 * @num_dests: number of subsequent destination originator MAC addresses
663 struct batadv_tvlv_mcast_tracker
{
669 #endif /* _UAPI_LINUX_BATADV_PACKET_H_ */