kernel: backport flow dissector batman-adv support
[openwrt/openwrt.git] / target / linux / generic / backport-4.14 / 273-batman-adv-Convert-packet.h-to-uapi-header.patch
1 From: Sven Eckelmann <sven.eckelmann@openmesh.com>
2 Date: Thu, 21 Dec 2017 10:17:41 +0100
3 Subject: [PATCH] batman-adv: Convert packet.h to uapi header
4
5 The header file is used by different userspace programs to inject packets
6 or to decode sniffed packets. It should therefore be available to them as
7 userspace header.
8
9 Also other components in the kernel (like the flow dissector) require
10 access to the packet definitions to be able to decode ETH_P_BATMAN ethernet
11 packets.
12
13 Signed-off-by: Sven Eckelmann <sven.eckelmann@openmesh.com>
14 Signed-off-by: David S. Miller <davem@davemloft.net>
15 ---
16 rename net/batman-adv/packet.h => include/uapi/linux/batadv_packet.h (99%)
17
18 --- a/MAINTAINERS
19 +++ b/MAINTAINERS
20 @@ -2551,6 +2551,7 @@ S: Maintained
21 F: Documentation/ABI/testing/sysfs-class-net-batman-adv
22 F: Documentation/ABI/testing/sysfs-class-net-mesh
23 F: Documentation/networking/batman-adv.rst
24 +F: include/uapi/linux/batadv_packet.h
25 F: include/uapi/linux/batman_adv.h
26 F: net/batman-adv/
27
28 --- a/net/batman-adv/bat_iv_ogm.c
29 +++ b/net/batman-adv/bat_iv_ogm.c
30 @@ -51,6 +51,7 @@
31 #include <linux/workqueue.h>
32 #include <net/genetlink.h>
33 #include <net/netlink.h>
34 +#include <uapi/linux/batadv_packet.h>
35 #include <uapi/linux/batman_adv.h>
36
37 #include "bat_algo.h"
38 @@ -62,7 +63,6 @@
39 #include "netlink.h"
40 #include "network-coding.h"
41 #include "originator.h"
42 -#include "packet.h"
43 #include "routing.h"
44 #include "send.h"
45 #include "translation-table.h"
46 --- a/net/batman-adv/bat_v.c
47 +++ b/net/batman-adv/bat_v.c
48 @@ -37,6 +37,7 @@
49 #include <linux/workqueue.h>
50 #include <net/genetlink.h>
51 #include <net/netlink.h>
52 +#include <uapi/linux/batadv_packet.h>
53 #include <uapi/linux/batman_adv.h>
54
55 #include "bat_algo.h"
56 @@ -49,7 +50,6 @@
57 #include "log.h"
58 #include "netlink.h"
59 #include "originator.h"
60 -#include "packet.h"
61
62 struct sk_buff;
63
64 --- a/net/batman-adv/bat_v_elp.c
65 +++ b/net/batman-adv/bat_v_elp.c
66 @@ -41,13 +41,13 @@
67 #include <linux/types.h>
68 #include <linux/workqueue.h>
69 #include <net/cfg80211.h>
70 +#include <uapi/linux/batadv_packet.h>
71
72 #include "bat_algo.h"
73 #include "bat_v_ogm.h"
74 #include "hard-interface.h"
75 #include "log.h"
76 #include "originator.h"
77 -#include "packet.h"
78 #include "routing.h"
79 #include "send.h"
80
81 --- a/net/batman-adv/bat_v_ogm.c
82 +++ b/net/batman-adv/bat_v_ogm.c
83 @@ -38,13 +38,13 @@
84 #include <linux/string.h>
85 #include <linux/types.h>
86 #include <linux/workqueue.h>
87 +#include <uapi/linux/batadv_packet.h>
88
89 #include "bat_algo.h"
90 #include "hard-interface.h"
91 #include "hash.h"
92 #include "log.h"
93 #include "originator.h"
94 -#include "packet.h"
95 #include "routing.h"
96 #include "send.h"
97 #include "translation-table.h"
98 --- a/net/batman-adv/bridge_loop_avoidance.c
99 +++ b/net/batman-adv/bridge_loop_avoidance.c
100 @@ -49,6 +49,7 @@
101 #include <net/genetlink.h>
102 #include <net/netlink.h>
103 #include <net/sock.h>
104 +#include <uapi/linux/batadv_packet.h>
105 #include <uapi/linux/batman_adv.h>
106
107 #include "hard-interface.h"
108 @@ -56,7 +57,6 @@
109 #include "log.h"
110 #include "netlink.h"
111 #include "originator.h"
112 -#include "packet.h"
113 #include "soft-interface.h"
114 #include "sysfs.h"
115 #include "translation-table.h"
116 --- a/net/batman-adv/distributed-arp-table.h
117 +++ b/net/batman-adv/distributed-arp-table.h
118 @@ -23,9 +23,9 @@
119 #include <linux/compiler.h>
120 #include <linux/netdevice.h>
121 #include <linux/types.h>
122 +#include <uapi/linux/batadv_packet.h>
123
124 #include "originator.h"
125 -#include "packet.h"
126
127 struct seq_file;
128 struct sk_buff;
129 --- a/net/batman-adv/fragmentation.c
130 +++ b/net/batman-adv/fragmentation.c
131 @@ -32,10 +32,10 @@
132 #include <linux/slab.h>
133 #include <linux/spinlock.h>
134 #include <linux/string.h>
135 +#include <uapi/linux/batadv_packet.h>
136
137 #include "hard-interface.h"
138 #include "originator.h"
139 -#include "packet.h"
140 #include "routing.h"
141 #include "send.h"
142 #include "soft-interface.h"
143 --- a/net/batman-adv/gateway_client.c
144 +++ b/net/batman-adv/gateway_client.c
145 @@ -43,6 +43,7 @@
146 #include <linux/stddef.h>
147 #include <linux/udp.h>
148 #include <net/sock.h>
149 +#include <uapi/linux/batadv_packet.h>
150 #include <uapi/linux/batman_adv.h>
151
152 #include "gateway_common.h"
153 @@ -50,7 +51,6 @@
154 #include "log.h"
155 #include "netlink.h"
156 #include "originator.h"
157 -#include "packet.h"
158 #include "routing.h"
159 #include "soft-interface.h"
160 #include "sysfs.h"
161 --- a/net/batman-adv/gateway_common.c
162 +++ b/net/batman-adv/gateway_common.c
163 @@ -26,10 +26,10 @@
164 #include <linux/netdevice.h>
165 #include <linux/stddef.h>
166 #include <linux/string.h>
167 +#include <uapi/linux/batadv_packet.h>
168
169 #include "gateway_client.h"
170 #include "log.h"
171 -#include "packet.h"
172 #include "tvlv.h"
173
174 /**
175 --- a/net/batman-adv/hard-interface.c
176 +++ b/net/batman-adv/hard-interface.c
177 @@ -36,6 +36,7 @@
178 #include <linux/spinlock.h>
179 #include <net/net_namespace.h>
180 #include <net/rtnetlink.h>
181 +#include <uapi/linux/batadv_packet.h>
182
183 #include "bat_v.h"
184 #include "bridge_loop_avoidance.h"
185 @@ -44,7 +45,6 @@
186 #include "gateway_client.h"
187 #include "log.h"
188 #include "originator.h"
189 -#include "packet.h"
190 #include "send.h"
191 #include "soft-interface.h"
192 #include "sysfs.h"
193 --- a/net/batman-adv/icmp_socket.c
194 +++ b/net/batman-adv/icmp_socket.c
195 @@ -42,11 +42,11 @@
196 #include <linux/string.h>
197 #include <linux/uaccess.h>
198 #include <linux/wait.h>
199 +#include <uapi/linux/batadv_packet.h>
200
201 #include "hard-interface.h"
202 #include "log.h"
203 #include "originator.h"
204 -#include "packet.h"
205 #include "send.h"
206
207 static struct batadv_socket_client *batadv_socket_client_hash[256];
208 --- a/net/batman-adv/main.c
209 +++ b/net/batman-adv/main.c
210 @@ -45,6 +45,7 @@
211 #include <linux/workqueue.h>
212 #include <net/dsfield.h>
213 #include <net/rtnetlink.h>
214 +#include <uapi/linux/batadv_packet.h>
215 #include <uapi/linux/batman_adv.h>
216
217 #include "bat_algo.h"
218 @@ -62,7 +63,6 @@
219 #include "netlink.h"
220 #include "network-coding.h"
221 #include "originator.h"
222 -#include "packet.h"
223 #include "routing.h"
224 #include "send.h"
225 #include "soft-interface.h"
226 --- a/net/batman-adv/main.h
227 +++ b/net/batman-adv/main.h
228 @@ -190,8 +190,8 @@ enum batadv_uev_type {
229 #include <linux/jiffies.h>
230 #include <linux/percpu.h>
231 #include <linux/types.h>
232 +#include <uapi/linux/batadv_packet.h>
233
234 -#include "packet.h"
235 #include "types.h"
236
237 struct net_device;
238 --- a/net/batman-adv/multicast.c
239 +++ b/net/batman-adv/multicast.c
240 @@ -54,11 +54,11 @@
241 #include <net/if_inet6.h>
242 #include <net/ip.h>
243 #include <net/ipv6.h>
244 +#include <uapi/linux/batadv_packet.h>
245
246 #include "hard-interface.h"
247 #include "hash.h"
248 #include "log.h"
249 -#include "packet.h"
250 #include "translation-table.h"
251 #include "tvlv.h"
252
253 --- a/net/batman-adv/netlink.c
254 +++ b/net/batman-adv/netlink.c
255 @@ -39,6 +39,7 @@
256 #include <net/genetlink.h>
257 #include <net/netlink.h>
258 #include <net/sock.h>
259 +#include <uapi/linux/batadv_packet.h>
260 #include <uapi/linux/batman_adv.h>
261
262 #include "bat_algo.h"
263 @@ -46,7 +47,6 @@
264 #include "gateway_client.h"
265 #include "hard-interface.h"
266 #include "originator.h"
267 -#include "packet.h"
268 #include "soft-interface.h"
269 #include "tp_meter.h"
270 #include "translation-table.h"
271 --- a/net/batman-adv/network-coding.c
272 +++ b/net/batman-adv/network-coding.c
273 @@ -47,12 +47,12 @@
274 #include <linux/stddef.h>
275 #include <linux/string.h>
276 #include <linux/workqueue.h>
277 +#include <uapi/linux/batadv_packet.h>
278
279 #include "hard-interface.h"
280 #include "hash.h"
281 #include "log.h"
282 #include "originator.h"
283 -#include "packet.h"
284 #include "routing.h"
285 #include "send.h"
286 #include "tvlv.h"
287 --- a/net/batman-adv/packet.h
288 +++ /dev/null
289 @@ -1,622 +0,0 @@
290 -/* Copyright (C) 2007-2017 B.A.T.M.A.N. contributors:
291 - *
292 - * Marek Lindner, Simon Wunderlich
293 - *
294 - * This program is free software; you can redistribute it and/or
295 - * modify it under the terms of version 2 of the GNU General Public
296 - * License as published by the Free Software Foundation.
297 - *
298 - * This program is distributed in the hope that it will be useful, but
299 - * WITHOUT ANY WARRANTY; without even the implied warranty of
300 - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
301 - * General Public License for more details.
302 - *
303 - * You should have received a copy of the GNU General Public License
304 - * along with this program; if not, see <http://www.gnu.org/licenses/>.
305 - */
306 -
307 -#ifndef _NET_BATMAN_ADV_PACKET_H_
308 -#define _NET_BATMAN_ADV_PACKET_H_
309 -
310 -#include <asm/byteorder.h>
311 -#include <linux/if_ether.h>
312 -#include <linux/types.h>
313 -
314 -#define batadv_tp_is_error(n) ((__u8)(n) > 127 ? 1 : 0)
315 -
316 -/**
317 - * enum batadv_packettype - types for batman-adv encapsulated packets
318 - * @BATADV_IV_OGM: originator messages for B.A.T.M.A.N. IV
319 - * @BATADV_BCAST: broadcast packets carrying broadcast payload
320 - * @BATADV_CODED: network coded packets
321 - * @BATADV_ELP: echo location packets for B.A.T.M.A.N. V
322 - * @BATADV_OGM2: originator messages for B.A.T.M.A.N. V
323 - *
324 - * @BATADV_UNICAST: unicast packets carrying unicast payload traffic
325 - * @BATADV_UNICAST_FRAG: unicast packets carrying a fragment of the original
326 - * payload packet
327 - * @BATADV_UNICAST_4ADDR: unicast packet including the originator address of
328 - * the sender
329 - * @BATADV_ICMP: unicast packet like IP ICMP used for ping or traceroute
330 - * @BATADV_UNICAST_TVLV: unicast packet carrying TVLV containers
331 - */
332 -enum batadv_packettype {
333 - /* 0x00 - 0x3f: local packets or special rules for handling */
334 - BATADV_IV_OGM = 0x00,
335 - BATADV_BCAST = 0x01,
336 - BATADV_CODED = 0x02,
337 - BATADV_ELP = 0x03,
338 - BATADV_OGM2 = 0x04,
339 - /* 0x40 - 0x7f: unicast */
340 -#define BATADV_UNICAST_MIN 0x40
341 - BATADV_UNICAST = 0x40,
342 - BATADV_UNICAST_FRAG = 0x41,
343 - BATADV_UNICAST_4ADDR = 0x42,
344 - BATADV_ICMP = 0x43,
345 - BATADV_UNICAST_TVLV = 0x44,
346 -#define BATADV_UNICAST_MAX 0x7f
347 - /* 0x80 - 0xff: reserved */
348 -};
349 -
350 -/**
351 - * enum batadv_subtype - packet subtype for unicast4addr
352 - * @BATADV_P_DATA: user payload
353 - * @BATADV_P_DAT_DHT_GET: DHT request message
354 - * @BATADV_P_DAT_DHT_PUT: DHT store message
355 - * @BATADV_P_DAT_CACHE_REPLY: ARP reply generated by DAT
356 - */
357 -enum batadv_subtype {
358 - BATADV_P_DATA = 0x01,
359 - BATADV_P_DAT_DHT_GET = 0x02,
360 - BATADV_P_DAT_DHT_PUT = 0x03,
361 - BATADV_P_DAT_CACHE_REPLY = 0x04,
362 -};
363 -
364 -/* this file is included by batctl which needs these defines */
365 -#define BATADV_COMPAT_VERSION 15
366 -
367 -/**
368 - * enum batadv_iv_flags - flags used in B.A.T.M.A.N. IV OGM packets
369 - * @BATADV_NOT_BEST_NEXT_HOP: flag is set when ogm packet is forwarded and was
370 - * previously received from someone else than the best neighbor.
371 - * @BATADV_PRIMARIES_FIRST_HOP: flag unused.
372 - * @BATADV_DIRECTLINK: flag is for the first hop or if rebroadcasted from a
373 - * one hop neighbor on the interface where it was originally received.
374 - */
375 -enum batadv_iv_flags {
376 - BATADV_NOT_BEST_NEXT_HOP = 1UL << 0,
377 - BATADV_PRIMARIES_FIRST_HOP = 1UL << 1,
378 - BATADV_DIRECTLINK = 1UL << 2,
379 -};
380 -
381 -/* ICMP message types */
382 -enum batadv_icmp_packettype {
383 - BATADV_ECHO_REPLY = 0,
384 - BATADV_DESTINATION_UNREACHABLE = 3,
385 - BATADV_ECHO_REQUEST = 8,
386 - BATADV_TTL_EXCEEDED = 11,
387 - BATADV_PARAMETER_PROBLEM = 12,
388 - BATADV_TP = 15,
389 -};
390 -
391 -/**
392 - * enum batadv_mcast_flags - flags for multicast capabilities and settings
393 - * @BATADV_MCAST_WANT_ALL_UNSNOOPABLES: we want all packets destined for
394 - * 224.0.0.0/24 or ff02::1
395 - * @BATADV_MCAST_WANT_ALL_IPV4: we want all IPv4 multicast packets
396 - * @BATADV_MCAST_WANT_ALL_IPV6: we want all IPv6 multicast packets
397 - */
398 -enum batadv_mcast_flags {
399 - BATADV_MCAST_WANT_ALL_UNSNOOPABLES = 1UL << 0,
400 - BATADV_MCAST_WANT_ALL_IPV4 = 1UL << 1,
401 - BATADV_MCAST_WANT_ALL_IPV6 = 1UL << 2,
402 -};
403 -
404 -/* tt data subtypes */
405 -#define BATADV_TT_DATA_TYPE_MASK 0x0F
406 -
407 -/**
408 - * enum batadv_tt_data_flags - flags for tt data tvlv
409 - * @BATADV_TT_OGM_DIFF: TT diff propagated through OGM
410 - * @BATADV_TT_REQUEST: TT request message
411 - * @BATADV_TT_RESPONSE: TT response message
412 - * @BATADV_TT_FULL_TABLE: contains full table to replace existing table
413 - */
414 -enum batadv_tt_data_flags {
415 - BATADV_TT_OGM_DIFF = 1UL << 0,
416 - BATADV_TT_REQUEST = 1UL << 1,
417 - BATADV_TT_RESPONSE = 1UL << 2,
418 - BATADV_TT_FULL_TABLE = 1UL << 4,
419 -};
420 -
421 -/**
422 - * enum batadv_vlan_flags - flags for the four MSB of any vlan ID field
423 - * @BATADV_VLAN_HAS_TAG: whether the field contains a valid vlan tag or not
424 - */
425 -enum batadv_vlan_flags {
426 - BATADV_VLAN_HAS_TAG = 1UL << 15,
427 -};
428 -
429 -/* claim frame types for the bridge loop avoidance */
430 -enum batadv_bla_claimframe {
431 - BATADV_CLAIM_TYPE_CLAIM = 0x00,
432 - BATADV_CLAIM_TYPE_UNCLAIM = 0x01,
433 - BATADV_CLAIM_TYPE_ANNOUNCE = 0x02,
434 - BATADV_CLAIM_TYPE_REQUEST = 0x03,
435 - BATADV_CLAIM_TYPE_LOOPDETECT = 0x04,
436 -};
437 -
438 -/**
439 - * enum batadv_tvlv_type - tvlv type definitions
440 - * @BATADV_TVLV_GW: gateway tvlv
441 - * @BATADV_TVLV_DAT: distributed arp table tvlv
442 - * @BATADV_TVLV_NC: network coding tvlv
443 - * @BATADV_TVLV_TT: translation table tvlv
444 - * @BATADV_TVLV_ROAM: roaming advertisement tvlv
445 - * @BATADV_TVLV_MCAST: multicast capability tvlv
446 - */
447 -enum batadv_tvlv_type {
448 - BATADV_TVLV_GW = 0x01,
449 - BATADV_TVLV_DAT = 0x02,
450 - BATADV_TVLV_NC = 0x03,
451 - BATADV_TVLV_TT = 0x04,
452 - BATADV_TVLV_ROAM = 0x05,
453 - BATADV_TVLV_MCAST = 0x06,
454 -};
455 -
456 -#pragma pack(2)
457 -/* the destination hardware field in the ARP frame is used to
458 - * transport the claim type and the group id
459 - */
460 -struct batadv_bla_claim_dst {
461 - __u8 magic[3]; /* FF:43:05 */
462 - __u8 type; /* bla_claimframe */
463 - __be16 group; /* group id */
464 -};
465 -
466 -#pragma pack()
467 -
468 -/**
469 - * struct batadv_ogm_packet - ogm (routing protocol) packet
470 - * @packet_type: batman-adv packet type, part of the general header
471 - * @version: batman-adv protocol version, part of the genereal header
472 - * @ttl: time to live for this packet, part of the genereal header
473 - * @flags: contains routing relevant flags - see enum batadv_iv_flags
474 - * @seqno: sequence identification
475 - * @orig: address of the source node
476 - * @prev_sender: address of the previous sender
477 - * @reserved: reserved byte for alignment
478 - * @tq: transmission quality
479 - * @tvlv_len: length of tvlv data following the ogm header
480 - */
481 -struct batadv_ogm_packet {
482 - __u8 packet_type;
483 - __u8 version;
484 - __u8 ttl;
485 - __u8 flags;
486 - __be32 seqno;
487 - __u8 orig[ETH_ALEN];
488 - __u8 prev_sender[ETH_ALEN];
489 - __u8 reserved;
490 - __u8 tq;
491 - __be16 tvlv_len;
492 - /* __packed is not needed as the struct size is divisible by 4,
493 - * and the largest data type in this struct has a size of 4.
494 - */
495 -};
496 -
497 -#define BATADV_OGM_HLEN sizeof(struct batadv_ogm_packet)
498 -
499 -/**
500 - * struct batadv_ogm2_packet - ogm2 (routing protocol) packet
501 - * @packet_type: batman-adv packet type, part of the general header
502 - * @version: batman-adv protocol version, part of the general header
503 - * @ttl: time to live for this packet, part of the general header
504 - * @flags: reseved for routing relevant flags - currently always 0
505 - * @seqno: sequence number
506 - * @orig: originator mac address
507 - * @tvlv_len: length of the appended tvlv buffer (in bytes)
508 - * @throughput: the currently flooded path throughput
509 - */
510 -struct batadv_ogm2_packet {
511 - __u8 packet_type;
512 - __u8 version;
513 - __u8 ttl;
514 - __u8 flags;
515 - __be32 seqno;
516 - __u8 orig[ETH_ALEN];
517 - __be16 tvlv_len;
518 - __be32 throughput;
519 - /* __packed is not needed as the struct size is divisible by 4,
520 - * and the largest data type in this struct has a size of 4.
521 - */
522 -};
523 -
524 -#define BATADV_OGM2_HLEN sizeof(struct batadv_ogm2_packet)
525 -
526 -/**
527 - * struct batadv_elp_packet - elp (neighbor discovery) packet
528 - * @packet_type: batman-adv packet type, part of the general header
529 - * @version: batman-adv protocol version, part of the genereal header
530 - * @orig: originator mac address
531 - * @seqno: sequence number
532 - * @elp_interval: currently used ELP sending interval in ms
533 - */
534 -struct batadv_elp_packet {
535 - __u8 packet_type;
536 - __u8 version;
537 - __u8 orig[ETH_ALEN];
538 - __be32 seqno;
539 - __be32 elp_interval;
540 -};
541 -
542 -#define BATADV_ELP_HLEN sizeof(struct batadv_elp_packet)
543 -
544 -/**
545 - * struct batadv_icmp_header - common members among all the ICMP packets
546 - * @packet_type: batman-adv packet type, part of the general header
547 - * @version: batman-adv protocol version, part of the genereal header
548 - * @ttl: time to live for this packet, part of the genereal header
549 - * @msg_type: ICMP packet type
550 - * @dst: address of the destination node
551 - * @orig: address of the source node
552 - * @uid: local ICMP socket identifier
553 - * @align: not used - useful for alignment purposes only
554 - *
555 - * This structure is used for ICMP packets parsing only and it is never sent
556 - * over the wire. The alignment field at the end is there to ensure that
557 - * members are padded the same way as they are in real packets.
558 - */
559 -struct batadv_icmp_header {
560 - __u8 packet_type;
561 - __u8 version;
562 - __u8 ttl;
563 - __u8 msg_type; /* see ICMP message types above */
564 - __u8 dst[ETH_ALEN];
565 - __u8 orig[ETH_ALEN];
566 - __u8 uid;
567 - __u8 align[3];
568 -};
569 -
570 -/**
571 - * struct batadv_icmp_packet - ICMP packet
572 - * @packet_type: batman-adv packet type, part of the general header
573 - * @version: batman-adv protocol version, part of the genereal header
574 - * @ttl: time to live for this packet, part of the genereal header
575 - * @msg_type: ICMP packet type
576 - * @dst: address of the destination node
577 - * @orig: address of the source node
578 - * @uid: local ICMP socket identifier
579 - * @reserved: not used - useful for alignment
580 - * @seqno: ICMP sequence number
581 - */
582 -struct batadv_icmp_packet {
583 - __u8 packet_type;
584 - __u8 version;
585 - __u8 ttl;
586 - __u8 msg_type; /* see ICMP message types above */
587 - __u8 dst[ETH_ALEN];
588 - __u8 orig[ETH_ALEN];
589 - __u8 uid;
590 - __u8 reserved;
591 - __be16 seqno;
592 -};
593 -
594 -/**
595 - * struct batadv_icmp_tp_packet - ICMP TP Meter packet
596 - * @packet_type: batman-adv packet type, part of the general header
597 - * @version: batman-adv protocol version, part of the genereal header
598 - * @ttl: time to live for this packet, part of the genereal header
599 - * @msg_type: ICMP packet type
600 - * @dst: address of the destination node
601 - * @orig: address of the source node
602 - * @uid: local ICMP socket identifier
603 - * @subtype: TP packet subtype (see batadv_icmp_tp_subtype)
604 - * @session: TP session identifier
605 - * @seqno: the TP sequence number
606 - * @timestamp: time when the packet has been sent. This value is filled in a
607 - * TP_MSG and echoed back in the next TP_ACK so that the sender can compute the
608 - * RTT. Since it is read only by the host which wrote it, there is no need to
609 - * store it using network order
610 - */
611 -struct batadv_icmp_tp_packet {
612 - __u8 packet_type;
613 - __u8 version;
614 - __u8 ttl;
615 - __u8 msg_type; /* see ICMP message types above */
616 - __u8 dst[ETH_ALEN];
617 - __u8 orig[ETH_ALEN];
618 - __u8 uid;
619 - __u8 subtype;
620 - __u8 session[2];
621 - __be32 seqno;
622 - __be32 timestamp;
623 -};
624 -
625 -/**
626 - * enum batadv_icmp_tp_subtype - ICMP TP Meter packet subtypes
627 - * @BATADV_TP_MSG: Msg from sender to receiver
628 - * @BATADV_TP_ACK: acknowledgment from receiver to sender
629 - */
630 -enum batadv_icmp_tp_subtype {
631 - BATADV_TP_MSG = 0,
632 - BATADV_TP_ACK,
633 -};
634 -
635 -#define BATADV_RR_LEN 16
636 -
637 -/**
638 - * struct batadv_icmp_packet_rr - ICMP RouteRecord packet
639 - * @packet_type: batman-adv packet type, part of the general header
640 - * @version: batman-adv protocol version, part of the genereal header
641 - * @ttl: time to live for this packet, part of the genereal header
642 - * @msg_type: ICMP packet type
643 - * @dst: address of the destination node
644 - * @orig: address of the source node
645 - * @uid: local ICMP socket identifier
646 - * @rr_cur: number of entries the rr array
647 - * @seqno: ICMP sequence number
648 - * @rr: route record array
649 - */
650 -struct batadv_icmp_packet_rr {
651 - __u8 packet_type;
652 - __u8 version;
653 - __u8 ttl;
654 - __u8 msg_type; /* see ICMP message types above */
655 - __u8 dst[ETH_ALEN];
656 - __u8 orig[ETH_ALEN];
657 - __u8 uid;
658 - __u8 rr_cur;
659 - __be16 seqno;
660 - __u8 rr[BATADV_RR_LEN][ETH_ALEN];
661 -};
662 -
663 -#define BATADV_ICMP_MAX_PACKET_SIZE sizeof(struct batadv_icmp_packet_rr)
664 -
665 -/* All packet headers in front of an ethernet header have to be completely
666 - * divisible by 2 but not by 4 to make the payload after the ethernet
667 - * header again 4 bytes boundary aligned.
668 - *
669 - * A packing of 2 is necessary to avoid extra padding at the end of the struct
670 - * caused by a structure member which is larger than two bytes. Otherwise
671 - * the structure would not fulfill the previously mentioned rule to avoid the
672 - * misalignment of the payload after the ethernet header. It may also lead to
673 - * leakage of information when the padding it not initialized before sending.
674 - */
675 -#pragma pack(2)
676 -
677 -/**
678 - * struct batadv_unicast_packet - unicast packet for network payload
679 - * @packet_type: batman-adv packet type, part of the general header
680 - * @version: batman-adv protocol version, part of the genereal header
681 - * @ttl: time to live for this packet, part of the genereal header
682 - * @ttvn: translation table version number
683 - * @dest: originator destination of the unicast packet
684 - */
685 -struct batadv_unicast_packet {
686 - __u8 packet_type;
687 - __u8 version;
688 - __u8 ttl;
689 - __u8 ttvn; /* destination translation table version number */
690 - __u8 dest[ETH_ALEN];
691 - /* "4 bytes boundary + 2 bytes" long to make the payload after the
692 - * following ethernet header again 4 bytes boundary aligned
693 - */
694 -};
695 -
696 -/**
697 - * struct batadv_unicast_4addr_packet - extended unicast packet
698 - * @u: common unicast packet header
699 - * @src: address of the source
700 - * @subtype: packet subtype
701 - * @reserved: reserved byte for alignment
702 - */
703 -struct batadv_unicast_4addr_packet {
704 - struct batadv_unicast_packet u;
705 - __u8 src[ETH_ALEN];
706 - __u8 subtype;
707 - __u8 reserved;
708 - /* "4 bytes boundary + 2 bytes" long to make the payload after the
709 - * following ethernet header again 4 bytes boundary aligned
710 - */
711 -};
712 -
713 -/**
714 - * struct batadv_frag_packet - fragmented packet
715 - * @packet_type: batman-adv packet type, part of the general header
716 - * @version: batman-adv protocol version, part of the genereal header
717 - * @ttl: time to live for this packet, part of the genereal header
718 - * @dest: final destination used when routing fragments
719 - * @orig: originator of the fragment used when merging the packet
720 - * @no: fragment number within this sequence
721 - * @priority: priority of frame, from ToS IP precedence or 802.1p
722 - * @reserved: reserved byte for alignment
723 - * @seqno: sequence identification
724 - * @total_size: size of the merged packet
725 - */
726 -struct batadv_frag_packet {
727 - __u8 packet_type;
728 - __u8 version; /* batman version field */
729 - __u8 ttl;
730 -#if defined(__BIG_ENDIAN_BITFIELD)
731 - __u8 no:4;
732 - __u8 priority:3;
733 - __u8 reserved:1;
734 -#elif defined(__LITTLE_ENDIAN_BITFIELD)
735 - __u8 reserved:1;
736 - __u8 priority:3;
737 - __u8 no:4;
738 -#else
739 -#error "unknown bitfield endianness"
740 -#endif
741 - __u8 dest[ETH_ALEN];
742 - __u8 orig[ETH_ALEN];
743 - __be16 seqno;
744 - __be16 total_size;
745 -};
746 -
747 -/**
748 - * struct batadv_bcast_packet - broadcast packet for network payload
749 - * @packet_type: batman-adv packet type, part of the general header
750 - * @version: batman-adv protocol version, part of the genereal header
751 - * @ttl: time to live for this packet, part of the genereal header
752 - * @reserved: reserved byte for alignment
753 - * @seqno: sequence identification
754 - * @orig: originator of the broadcast packet
755 - */
756 -struct batadv_bcast_packet {
757 - __u8 packet_type;
758 - __u8 version; /* batman version field */
759 - __u8 ttl;
760 - __u8 reserved;
761 - __be32 seqno;
762 - __u8 orig[ETH_ALEN];
763 - /* "4 bytes boundary + 2 bytes" long to make the payload after the
764 - * following ethernet header again 4 bytes boundary aligned
765 - */
766 -};
767 -
768 -/**
769 - * struct batadv_coded_packet - network coded packet
770 - * @packet_type: batman-adv packet type, part of the general header
771 - * @version: batman-adv protocol version, part of the genereal header
772 - * @ttl: time to live for this packet, part of the genereal header
773 - * @first_source: original source of first included packet
774 - * @first_orig_dest: original destinal of first included packet
775 - * @first_crc: checksum of first included packet
776 - * @first_ttvn: tt-version number of first included packet
777 - * @second_ttl: ttl of second packet
778 - * @second_dest: second receiver of this coded packet
779 - * @second_source: original source of second included packet
780 - * @second_orig_dest: original destination of second included packet
781 - * @second_crc: checksum of second included packet
782 - * @second_ttvn: tt version number of second included packet
783 - * @coded_len: length of network coded part of the payload
784 - */
785 -struct batadv_coded_packet {
786 - __u8 packet_type;
787 - __u8 version; /* batman version field */
788 - __u8 ttl;
789 - __u8 first_ttvn;
790 - /* __u8 first_dest[ETH_ALEN]; - saved in mac header destination */
791 - __u8 first_source[ETH_ALEN];
792 - __u8 first_orig_dest[ETH_ALEN];
793 - __be32 first_crc;
794 - __u8 second_ttl;
795 - __u8 second_ttvn;
796 - __u8 second_dest[ETH_ALEN];
797 - __u8 second_source[ETH_ALEN];
798 - __u8 second_orig_dest[ETH_ALEN];
799 - __be32 second_crc;
800 - __be16 coded_len;
801 -};
802 -
803 -#pragma pack()
804 -
805 -/**
806 - * struct batadv_unicast_tvlv_packet - generic unicast packet with tvlv payload
807 - * @packet_type: batman-adv packet type, part of the general header
808 - * @version: batman-adv protocol version, part of the genereal header
809 - * @ttl: time to live for this packet, part of the genereal header
810 - * @reserved: reserved field (for packet alignment)
811 - * @src: address of the source
812 - * @dst: address of the destination
813 - * @tvlv_len: length of tvlv data following the unicast tvlv header
814 - * @align: 2 bytes to align the header to a 4 byte boundary
815 - */
816 -struct batadv_unicast_tvlv_packet {
817 - __u8 packet_type;
818 - __u8 version; /* batman version field */
819 - __u8 ttl;
820 - __u8 reserved;
821 - __u8 dst[ETH_ALEN];
822 - __u8 src[ETH_ALEN];
823 - __be16 tvlv_len;
824 - __u16 align;
825 -};
826 -
827 -/**
828 - * struct batadv_tvlv_hdr - base tvlv header struct
829 - * @type: tvlv container type (see batadv_tvlv_type)
830 - * @version: tvlv container version
831 - * @len: tvlv container length
832 - */
833 -struct batadv_tvlv_hdr {
834 - __u8 type;
835 - __u8 version;
836 - __be16 len;
837 -};
838 -
839 -/**
840 - * struct batadv_tvlv_gateway_data - gateway data propagated through gw tvlv
841 - * container
842 - * @bandwidth_down: advertised uplink download bandwidth
843 - * @bandwidth_up: advertised uplink upload bandwidth
844 - */
845 -struct batadv_tvlv_gateway_data {
846 - __be32 bandwidth_down;
847 - __be32 bandwidth_up;
848 -};
849 -
850 -/**
851 - * struct batadv_tvlv_tt_data - tt data propagated through the tt tvlv container
852 - * @flags: translation table flags (see batadv_tt_data_flags)
853 - * @ttvn: translation table version number
854 - * @num_vlan: number of announced VLANs. In the TVLV this struct is followed by
855 - * one batadv_tvlv_tt_vlan_data object per announced vlan
856 - */
857 -struct batadv_tvlv_tt_data {
858 - __u8 flags;
859 - __u8 ttvn;
860 - __be16 num_vlan;
861 -};
862 -
863 -/**
864 - * struct batadv_tvlv_tt_vlan_data - vlan specific tt data propagated through
865 - * the tt tvlv container
866 - * @crc: crc32 checksum of the entries belonging to this vlan
867 - * @vid: vlan identifier
868 - * @reserved: unused, useful for alignment purposes
869 - */
870 -struct batadv_tvlv_tt_vlan_data {
871 - __be32 crc;
872 - __be16 vid;
873 - __u16 reserved;
874 -};
875 -
876 -/**
877 - * struct batadv_tvlv_tt_change - translation table diff data
878 - * @flags: status indicators concerning the non-mesh client (see
879 - * batadv_tt_client_flags)
880 - * @reserved: reserved field - useful for alignment purposes only
881 - * @addr: mac address of non-mesh client that triggered this tt change
882 - * @vid: VLAN identifier
883 - */
884 -struct batadv_tvlv_tt_change {
885 - __u8 flags;
886 - __u8 reserved[3];
887 - __u8 addr[ETH_ALEN];
888 - __be16 vid;
889 -};
890 -
891 -/**
892 - * struct batadv_tvlv_roam_adv - roaming advertisement
893 - * @client: mac address of roaming client
894 - * @vid: VLAN identifier
895 - */
896 -struct batadv_tvlv_roam_adv {
897 - __u8 client[ETH_ALEN];
898 - __be16 vid;
899 -};
900 -
901 -/**
902 - * struct batadv_tvlv_mcast_data - payload of a multicast tvlv
903 - * @flags: multicast flags announced by the orig node
904 - * @reserved: reserved field
905 - */
906 -struct batadv_tvlv_mcast_data {
907 - __u8 flags;
908 - __u8 reserved[3];
909 -};
910 -
911 -#endif /* _NET_BATMAN_ADV_PACKET_H_ */
912 --- a/net/batman-adv/routing.c
913 +++ b/net/batman-adv/routing.c
914 @@ -33,6 +33,7 @@
915 #include <linux/skbuff.h>
916 #include <linux/spinlock.h>
917 #include <linux/stddef.h>
918 +#include <uapi/linux/batadv_packet.h>
919
920 #include "bitarray.h"
921 #include "bridge_loop_avoidance.h"
922 @@ -43,7 +44,6 @@
923 #include "log.h"
924 #include "network-coding.h"
925 #include "originator.h"
926 -#include "packet.h"
927 #include "send.h"
928 #include "soft-interface.h"
929 #include "tp_meter.h"
930 --- a/net/batman-adv/send.h
931 +++ b/net/batman-adv/send.h
932 @@ -23,8 +23,7 @@
933 #include <linux/compiler.h>
934 #include <linux/spinlock.h>
935 #include <linux/types.h>
936 -
937 -#include "packet.h"
938 +#include <uapi/linux/batadv_packet.h>
939
940 struct sk_buff;
941
942 --- a/net/batman-adv/soft-interface.c
943 +++ b/net/batman-adv/soft-interface.c
944 @@ -48,6 +48,7 @@
945 #include <linux/stddef.h>
946 #include <linux/string.h>
947 #include <linux/types.h>
948 +#include <uapi/linux/batadv_packet.h>
949
950 #include "bat_algo.h"
951 #include "bridge_loop_avoidance.h"
952 @@ -59,7 +60,6 @@
953 #include "multicast.h"
954 #include "network-coding.h"
955 #include "originator.h"
956 -#include "packet.h"
957 #include "send.h"
958 #include "sysfs.h"
959 #include "translation-table.h"
960 --- a/net/batman-adv/sysfs.c
961 +++ b/net/batman-adv/sysfs.c
962 @@ -37,6 +37,7 @@
963 #include <linux/string.h>
964 #include <linux/stringify.h>
965 #include <linux/workqueue.h>
966 +#include <uapi/linux/batadv_packet.h>
967
968 #include "bridge_loop_avoidance.h"
969 #include "distributed-arp-table.h"
970 @@ -45,7 +46,6 @@
971 #include "hard-interface.h"
972 #include "log.h"
973 #include "network-coding.h"
974 -#include "packet.h"
975 #include "soft-interface.h"
976
977 static struct net_device *batadv_kobj_to_netdev(struct kobject *obj)
978 --- a/net/batman-adv/tp_meter.c
979 +++ b/net/batman-adv/tp_meter.c
980 @@ -48,13 +48,13 @@
981 #include <linux/timer.h>
982 #include <linux/wait.h>
983 #include <linux/workqueue.h>
984 +#include <uapi/linux/batadv_packet.h>
985 #include <uapi/linux/batman_adv.h>
986
987 #include "hard-interface.h"
988 #include "log.h"
989 #include "netlink.h"
990 #include "originator.h"
991 -#include "packet.h"
992 #include "send.h"
993
994 /**
995 --- a/net/batman-adv/translation-table.c
996 +++ b/net/batman-adv/translation-table.c
997 @@ -50,6 +50,7 @@
998 #include <net/genetlink.h>
999 #include <net/netlink.h>
1000 #include <net/sock.h>
1001 +#include <uapi/linux/batadv_packet.h>
1002 #include <uapi/linux/batman_adv.h>
1003
1004 #include "bridge_loop_avoidance.h"
1005 @@ -58,7 +59,6 @@
1006 #include "log.h"
1007 #include "netlink.h"
1008 #include "originator.h"
1009 -#include "packet.h"
1010 #include "soft-interface.h"
1011 #include "tvlv.h"
1012
1013 --- a/net/batman-adv/tvlv.c
1014 +++ b/net/batman-adv/tvlv.c
1015 @@ -35,9 +35,9 @@
1016 #include <linux/stddef.h>
1017 #include <linux/string.h>
1018 #include <linux/types.h>
1019 +#include <uapi/linux/batadv_packet.h>
1020
1021 #include "originator.h"
1022 -#include "packet.h"
1023 #include "send.h"
1024 #include "tvlv.h"
1025
1026 --- a/net/batman-adv/types.h
1027 +++ b/net/batman-adv/types.h
1028 @@ -34,10 +34,9 @@
1029 #include <linux/types.h>
1030 #include <linux/wait.h>
1031 #include <linux/workqueue.h>
1032 +#include <uapi/linux/batadv_packet.h>
1033 #include <uapi/linux/batman_adv.h>
1034
1035 -#include "packet.h"
1036 -
1037 struct seq_file;
1038
1039 #ifdef CONFIG_BATMAN_ADV_DAT
1040 --- /dev/null
1041 +++ b/include/uapi/linux/batadv_packet.h
1042 @@ -0,0 +1,623 @@
1043 +/* SPDX-License-Identifier: (GPL-2.0 WITH Linux-syscall-note) */
1044 +/* Copyright (C) 2007-2017 B.A.T.M.A.N. contributors:
1045 + *
1046 + * Marek Lindner, Simon Wunderlich
1047 + *
1048 + * This program is free software; you can redistribute it and/or
1049 + * modify it under the terms of version 2 of the GNU General Public
1050 + * License as published by the Free Software Foundation.
1051 + *
1052 + * This program is distributed in the hope that it will be useful, but
1053 + * WITHOUT ANY WARRANTY; without even the implied warranty of
1054 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
1055 + * General Public License for more details.
1056 + *
1057 + * You should have received a copy of the GNU General Public License
1058 + * along with this program; if not, see <http://www.gnu.org/licenses/>.
1059 + */
1060 +
1061 +#ifndef _UAPI_LINUX_BATADV_PACKET_H_
1062 +#define _UAPI_LINUX_BATADV_PACKET_H_
1063 +
1064 +#include <asm/byteorder.h>
1065 +#include <linux/if_ether.h>
1066 +#include <linux/types.h>
1067 +
1068 +#define batadv_tp_is_error(n) ((__u8)(n) > 127 ? 1 : 0)
1069 +
1070 +/**
1071 + * enum batadv_packettype - types for batman-adv encapsulated packets
1072 + * @BATADV_IV_OGM: originator messages for B.A.T.M.A.N. IV
1073 + * @BATADV_BCAST: broadcast packets carrying broadcast payload
1074 + * @BATADV_CODED: network coded packets
1075 + * @BATADV_ELP: echo location packets for B.A.T.M.A.N. V
1076 + * @BATADV_OGM2: originator messages for B.A.T.M.A.N. V
1077 + *
1078 + * @BATADV_UNICAST: unicast packets carrying unicast payload traffic
1079 + * @BATADV_UNICAST_FRAG: unicast packets carrying a fragment of the original
1080 + * payload packet
1081 + * @BATADV_UNICAST_4ADDR: unicast packet including the originator address of
1082 + * the sender
1083 + * @BATADV_ICMP: unicast packet like IP ICMP used for ping or traceroute
1084 + * @BATADV_UNICAST_TVLV: unicast packet carrying TVLV containers
1085 + */
1086 +enum batadv_packettype {
1087 + /* 0x00 - 0x3f: local packets or special rules for handling */
1088 + BATADV_IV_OGM = 0x00,
1089 + BATADV_BCAST = 0x01,
1090 + BATADV_CODED = 0x02,
1091 + BATADV_ELP = 0x03,
1092 + BATADV_OGM2 = 0x04,
1093 + /* 0x40 - 0x7f: unicast */
1094 +#define BATADV_UNICAST_MIN 0x40
1095 + BATADV_UNICAST = 0x40,
1096 + BATADV_UNICAST_FRAG = 0x41,
1097 + BATADV_UNICAST_4ADDR = 0x42,
1098 + BATADV_ICMP = 0x43,
1099 + BATADV_UNICAST_TVLV = 0x44,
1100 +#define BATADV_UNICAST_MAX 0x7f
1101 + /* 0x80 - 0xff: reserved */
1102 +};
1103 +
1104 +/**
1105 + * enum batadv_subtype - packet subtype for unicast4addr
1106 + * @BATADV_P_DATA: user payload
1107 + * @BATADV_P_DAT_DHT_GET: DHT request message
1108 + * @BATADV_P_DAT_DHT_PUT: DHT store message
1109 + * @BATADV_P_DAT_CACHE_REPLY: ARP reply generated by DAT
1110 + */
1111 +enum batadv_subtype {
1112 + BATADV_P_DATA = 0x01,
1113 + BATADV_P_DAT_DHT_GET = 0x02,
1114 + BATADV_P_DAT_DHT_PUT = 0x03,
1115 + BATADV_P_DAT_CACHE_REPLY = 0x04,
1116 +};
1117 +
1118 +/* this file is included by batctl which needs these defines */
1119 +#define BATADV_COMPAT_VERSION 15
1120 +
1121 +/**
1122 + * enum batadv_iv_flags - flags used in B.A.T.M.A.N. IV OGM packets
1123 + * @BATADV_NOT_BEST_NEXT_HOP: flag is set when ogm packet is forwarded and was
1124 + * previously received from someone else than the best neighbor.
1125 + * @BATADV_PRIMARIES_FIRST_HOP: flag unused.
1126 + * @BATADV_DIRECTLINK: flag is for the first hop or if rebroadcasted from a
1127 + * one hop neighbor on the interface where it was originally received.
1128 + */
1129 +enum batadv_iv_flags {
1130 + BATADV_NOT_BEST_NEXT_HOP = 1UL << 0,
1131 + BATADV_PRIMARIES_FIRST_HOP = 1UL << 1,
1132 + BATADV_DIRECTLINK = 1UL << 2,
1133 +};
1134 +
1135 +/* ICMP message types */
1136 +enum batadv_icmp_packettype {
1137 + BATADV_ECHO_REPLY = 0,
1138 + BATADV_DESTINATION_UNREACHABLE = 3,
1139 + BATADV_ECHO_REQUEST = 8,
1140 + BATADV_TTL_EXCEEDED = 11,
1141 + BATADV_PARAMETER_PROBLEM = 12,
1142 + BATADV_TP = 15,
1143 +};
1144 +
1145 +/**
1146 + * enum batadv_mcast_flags - flags for multicast capabilities and settings
1147 + * @BATADV_MCAST_WANT_ALL_UNSNOOPABLES: we want all packets destined for
1148 + * 224.0.0.0/24 or ff02::1
1149 + * @BATADV_MCAST_WANT_ALL_IPV4: we want all IPv4 multicast packets
1150 + * @BATADV_MCAST_WANT_ALL_IPV6: we want all IPv6 multicast packets
1151 + */
1152 +enum batadv_mcast_flags {
1153 + BATADV_MCAST_WANT_ALL_UNSNOOPABLES = 1UL << 0,
1154 + BATADV_MCAST_WANT_ALL_IPV4 = 1UL << 1,
1155 + BATADV_MCAST_WANT_ALL_IPV6 = 1UL << 2,
1156 +};
1157 +
1158 +/* tt data subtypes */
1159 +#define BATADV_TT_DATA_TYPE_MASK 0x0F
1160 +
1161 +/**
1162 + * enum batadv_tt_data_flags - flags for tt data tvlv
1163 + * @BATADV_TT_OGM_DIFF: TT diff propagated through OGM
1164 + * @BATADV_TT_REQUEST: TT request message
1165 + * @BATADV_TT_RESPONSE: TT response message
1166 + * @BATADV_TT_FULL_TABLE: contains full table to replace existing table
1167 + */
1168 +enum batadv_tt_data_flags {
1169 + BATADV_TT_OGM_DIFF = 1UL << 0,
1170 + BATADV_TT_REQUEST = 1UL << 1,
1171 + BATADV_TT_RESPONSE = 1UL << 2,
1172 + BATADV_TT_FULL_TABLE = 1UL << 4,
1173 +};
1174 +
1175 +/**
1176 + * enum batadv_vlan_flags - flags for the four MSB of any vlan ID field
1177 + * @BATADV_VLAN_HAS_TAG: whether the field contains a valid vlan tag or not
1178 + */
1179 +enum batadv_vlan_flags {
1180 + BATADV_VLAN_HAS_TAG = 1UL << 15,
1181 +};
1182 +
1183 +/* claim frame types for the bridge loop avoidance */
1184 +enum batadv_bla_claimframe {
1185 + BATADV_CLAIM_TYPE_CLAIM = 0x00,
1186 + BATADV_CLAIM_TYPE_UNCLAIM = 0x01,
1187 + BATADV_CLAIM_TYPE_ANNOUNCE = 0x02,
1188 + BATADV_CLAIM_TYPE_REQUEST = 0x03,
1189 + BATADV_CLAIM_TYPE_LOOPDETECT = 0x04,
1190 +};
1191 +
1192 +/**
1193 + * enum batadv_tvlv_type - tvlv type definitions
1194 + * @BATADV_TVLV_GW: gateway tvlv
1195 + * @BATADV_TVLV_DAT: distributed arp table tvlv
1196 + * @BATADV_TVLV_NC: network coding tvlv
1197 + * @BATADV_TVLV_TT: translation table tvlv
1198 + * @BATADV_TVLV_ROAM: roaming advertisement tvlv
1199 + * @BATADV_TVLV_MCAST: multicast capability tvlv
1200 + */
1201 +enum batadv_tvlv_type {
1202 + BATADV_TVLV_GW = 0x01,
1203 + BATADV_TVLV_DAT = 0x02,
1204 + BATADV_TVLV_NC = 0x03,
1205 + BATADV_TVLV_TT = 0x04,
1206 + BATADV_TVLV_ROAM = 0x05,
1207 + BATADV_TVLV_MCAST = 0x06,
1208 +};
1209 +
1210 +#pragma pack(2)
1211 +/* the destination hardware field in the ARP frame is used to
1212 + * transport the claim type and the group id
1213 + */
1214 +struct batadv_bla_claim_dst {
1215 + __u8 magic[3]; /* FF:43:05 */
1216 + __u8 type; /* bla_claimframe */
1217 + __be16 group; /* group id */
1218 +};
1219 +
1220 +#pragma pack()
1221 +
1222 +/**
1223 + * struct batadv_ogm_packet - ogm (routing protocol) packet
1224 + * @packet_type: batman-adv packet type, part of the general header
1225 + * @version: batman-adv protocol version, part of the genereal header
1226 + * @ttl: time to live for this packet, part of the genereal header
1227 + * @flags: contains routing relevant flags - see enum batadv_iv_flags
1228 + * @seqno: sequence identification
1229 + * @orig: address of the source node
1230 + * @prev_sender: address of the previous sender
1231 + * @reserved: reserved byte for alignment
1232 + * @tq: transmission quality
1233 + * @tvlv_len: length of tvlv data following the ogm header
1234 + */
1235 +struct batadv_ogm_packet {
1236 + __u8 packet_type;
1237 + __u8 version;
1238 + __u8 ttl;
1239 + __u8 flags;
1240 + __be32 seqno;
1241 + __u8 orig[ETH_ALEN];
1242 + __u8 prev_sender[ETH_ALEN];
1243 + __u8 reserved;
1244 + __u8 tq;
1245 + __be16 tvlv_len;
1246 + /* __packed is not needed as the struct size is divisible by 4,
1247 + * and the largest data type in this struct has a size of 4.
1248 + */
1249 +};
1250 +
1251 +#define BATADV_OGM_HLEN sizeof(struct batadv_ogm_packet)
1252 +
1253 +/**
1254 + * struct batadv_ogm2_packet - ogm2 (routing protocol) packet
1255 + * @packet_type: batman-adv packet type, part of the general header
1256 + * @version: batman-adv protocol version, part of the general header
1257 + * @ttl: time to live for this packet, part of the general header
1258 + * @flags: reseved for routing relevant flags - currently always 0
1259 + * @seqno: sequence number
1260 + * @orig: originator mac address
1261 + * @tvlv_len: length of the appended tvlv buffer (in bytes)
1262 + * @throughput: the currently flooded path throughput
1263 + */
1264 +struct batadv_ogm2_packet {
1265 + __u8 packet_type;
1266 + __u8 version;
1267 + __u8 ttl;
1268 + __u8 flags;
1269 + __be32 seqno;
1270 + __u8 orig[ETH_ALEN];
1271 + __be16 tvlv_len;
1272 + __be32 throughput;
1273 + /* __packed is not needed as the struct size is divisible by 4,
1274 + * and the largest data type in this struct has a size of 4.
1275 + */
1276 +};
1277 +
1278 +#define BATADV_OGM2_HLEN sizeof(struct batadv_ogm2_packet)
1279 +
1280 +/**
1281 + * struct batadv_elp_packet - elp (neighbor discovery) packet
1282 + * @packet_type: batman-adv packet type, part of the general header
1283 + * @version: batman-adv protocol version, part of the genereal header
1284 + * @orig: originator mac address
1285 + * @seqno: sequence number
1286 + * @elp_interval: currently used ELP sending interval in ms
1287 + */
1288 +struct batadv_elp_packet {
1289 + __u8 packet_type;
1290 + __u8 version;
1291 + __u8 orig[ETH_ALEN];
1292 + __be32 seqno;
1293 + __be32 elp_interval;
1294 +};
1295 +
1296 +#define BATADV_ELP_HLEN sizeof(struct batadv_elp_packet)
1297 +
1298 +/**
1299 + * struct batadv_icmp_header - common members among all the ICMP packets
1300 + * @packet_type: batman-adv packet type, part of the general header
1301 + * @version: batman-adv protocol version, part of the genereal header
1302 + * @ttl: time to live for this packet, part of the genereal header
1303 + * @msg_type: ICMP packet type
1304 + * @dst: address of the destination node
1305 + * @orig: address of the source node
1306 + * @uid: local ICMP socket identifier
1307 + * @align: not used - useful for alignment purposes only
1308 + *
1309 + * This structure is used for ICMP packets parsing only and it is never sent
1310 + * over the wire. The alignment field at the end is there to ensure that
1311 + * members are padded the same way as they are in real packets.
1312 + */
1313 +struct batadv_icmp_header {
1314 + __u8 packet_type;
1315 + __u8 version;
1316 + __u8 ttl;
1317 + __u8 msg_type; /* see ICMP message types above */
1318 + __u8 dst[ETH_ALEN];
1319 + __u8 orig[ETH_ALEN];
1320 + __u8 uid;
1321 + __u8 align[3];
1322 +};
1323 +
1324 +/**
1325 + * struct batadv_icmp_packet - ICMP packet
1326 + * @packet_type: batman-adv packet type, part of the general header
1327 + * @version: batman-adv protocol version, part of the genereal header
1328 + * @ttl: time to live for this packet, part of the genereal header
1329 + * @msg_type: ICMP packet type
1330 + * @dst: address of the destination node
1331 + * @orig: address of the source node
1332 + * @uid: local ICMP socket identifier
1333 + * @reserved: not used - useful for alignment
1334 + * @seqno: ICMP sequence number
1335 + */
1336 +struct batadv_icmp_packet {
1337 + __u8 packet_type;
1338 + __u8 version;
1339 + __u8 ttl;
1340 + __u8 msg_type; /* see ICMP message types above */
1341 + __u8 dst[ETH_ALEN];
1342 + __u8 orig[ETH_ALEN];
1343 + __u8 uid;
1344 + __u8 reserved;
1345 + __be16 seqno;
1346 +};
1347 +
1348 +/**
1349 + * struct batadv_icmp_tp_packet - ICMP TP Meter packet
1350 + * @packet_type: batman-adv packet type, part of the general header
1351 + * @version: batman-adv protocol version, part of the genereal header
1352 + * @ttl: time to live for this packet, part of the genereal header
1353 + * @msg_type: ICMP packet type
1354 + * @dst: address of the destination node
1355 + * @orig: address of the source node
1356 + * @uid: local ICMP socket identifier
1357 + * @subtype: TP packet subtype (see batadv_icmp_tp_subtype)
1358 + * @session: TP session identifier
1359 + * @seqno: the TP sequence number
1360 + * @timestamp: time when the packet has been sent. This value is filled in a
1361 + * TP_MSG and echoed back in the next TP_ACK so that the sender can compute the
1362 + * RTT. Since it is read only by the host which wrote it, there is no need to
1363 + * store it using network order
1364 + */
1365 +struct batadv_icmp_tp_packet {
1366 + __u8 packet_type;
1367 + __u8 version;
1368 + __u8 ttl;
1369 + __u8 msg_type; /* see ICMP message types above */
1370 + __u8 dst[ETH_ALEN];
1371 + __u8 orig[ETH_ALEN];
1372 + __u8 uid;
1373 + __u8 subtype;
1374 + __u8 session[2];
1375 + __be32 seqno;
1376 + __be32 timestamp;
1377 +};
1378 +
1379 +/**
1380 + * enum batadv_icmp_tp_subtype - ICMP TP Meter packet subtypes
1381 + * @BATADV_TP_MSG: Msg from sender to receiver
1382 + * @BATADV_TP_ACK: acknowledgment from receiver to sender
1383 + */
1384 +enum batadv_icmp_tp_subtype {
1385 + BATADV_TP_MSG = 0,
1386 + BATADV_TP_ACK,
1387 +};
1388 +
1389 +#define BATADV_RR_LEN 16
1390 +
1391 +/**
1392 + * struct batadv_icmp_packet_rr - ICMP RouteRecord packet
1393 + * @packet_type: batman-adv packet type, part of the general header
1394 + * @version: batman-adv protocol version, part of the genereal header
1395 + * @ttl: time to live for this packet, part of the genereal header
1396 + * @msg_type: ICMP packet type
1397 + * @dst: address of the destination node
1398 + * @orig: address of the source node
1399 + * @uid: local ICMP socket identifier
1400 + * @rr_cur: number of entries the rr array
1401 + * @seqno: ICMP sequence number
1402 + * @rr: route record array
1403 + */
1404 +struct batadv_icmp_packet_rr {
1405 + __u8 packet_type;
1406 + __u8 version;
1407 + __u8 ttl;
1408 + __u8 msg_type; /* see ICMP message types above */
1409 + __u8 dst[ETH_ALEN];
1410 + __u8 orig[ETH_ALEN];
1411 + __u8 uid;
1412 + __u8 rr_cur;
1413 + __be16 seqno;
1414 + __u8 rr[BATADV_RR_LEN][ETH_ALEN];
1415 +};
1416 +
1417 +#define BATADV_ICMP_MAX_PACKET_SIZE sizeof(struct batadv_icmp_packet_rr)
1418 +
1419 +/* All packet headers in front of an ethernet header have to be completely
1420 + * divisible by 2 but not by 4 to make the payload after the ethernet
1421 + * header again 4 bytes boundary aligned.
1422 + *
1423 + * A packing of 2 is necessary to avoid extra padding at the end of the struct
1424 + * caused by a structure member which is larger than two bytes. Otherwise
1425 + * the structure would not fulfill the previously mentioned rule to avoid the
1426 + * misalignment of the payload after the ethernet header. It may also lead to
1427 + * leakage of information when the padding it not initialized before sending.
1428 + */
1429 +#pragma pack(2)
1430 +
1431 +/**
1432 + * struct batadv_unicast_packet - unicast packet for network payload
1433 + * @packet_type: batman-adv packet type, part of the general header
1434 + * @version: batman-adv protocol version, part of the genereal header
1435 + * @ttl: time to live for this packet, part of the genereal header
1436 + * @ttvn: translation table version number
1437 + * @dest: originator destination of the unicast packet
1438 + */
1439 +struct batadv_unicast_packet {
1440 + __u8 packet_type;
1441 + __u8 version;
1442 + __u8 ttl;
1443 + __u8 ttvn; /* destination translation table version number */
1444 + __u8 dest[ETH_ALEN];
1445 + /* "4 bytes boundary + 2 bytes" long to make the payload after the
1446 + * following ethernet header again 4 bytes boundary aligned
1447 + */
1448 +};
1449 +
1450 +/**
1451 + * struct batadv_unicast_4addr_packet - extended unicast packet
1452 + * @u: common unicast packet header
1453 + * @src: address of the source
1454 + * @subtype: packet subtype
1455 + * @reserved: reserved byte for alignment
1456 + */
1457 +struct batadv_unicast_4addr_packet {
1458 + struct batadv_unicast_packet u;
1459 + __u8 src[ETH_ALEN];
1460 + __u8 subtype;
1461 + __u8 reserved;
1462 + /* "4 bytes boundary + 2 bytes" long to make the payload after the
1463 + * following ethernet header again 4 bytes boundary aligned
1464 + */
1465 +};
1466 +
1467 +/**
1468 + * struct batadv_frag_packet - fragmented packet
1469 + * @packet_type: batman-adv packet type, part of the general header
1470 + * @version: batman-adv protocol version, part of the genereal header
1471 + * @ttl: time to live for this packet, part of the genereal header
1472 + * @dest: final destination used when routing fragments
1473 + * @orig: originator of the fragment used when merging the packet
1474 + * @no: fragment number within this sequence
1475 + * @priority: priority of frame, from ToS IP precedence or 802.1p
1476 + * @reserved: reserved byte for alignment
1477 + * @seqno: sequence identification
1478 + * @total_size: size of the merged packet
1479 + */
1480 +struct batadv_frag_packet {
1481 + __u8 packet_type;
1482 + __u8 version; /* batman version field */
1483 + __u8 ttl;
1484 +#if defined(__BIG_ENDIAN_BITFIELD)
1485 + __u8 no:4;
1486 + __u8 priority:3;
1487 + __u8 reserved:1;
1488 +#elif defined(__LITTLE_ENDIAN_BITFIELD)
1489 + __u8 reserved:1;
1490 + __u8 priority:3;
1491 + __u8 no:4;
1492 +#else
1493 +#error "unknown bitfield endianness"
1494 +#endif
1495 + __u8 dest[ETH_ALEN];
1496 + __u8 orig[ETH_ALEN];
1497 + __be16 seqno;
1498 + __be16 total_size;
1499 +};
1500 +
1501 +/**
1502 + * struct batadv_bcast_packet - broadcast packet for network payload
1503 + * @packet_type: batman-adv packet type, part of the general header
1504 + * @version: batman-adv protocol version, part of the genereal header
1505 + * @ttl: time to live for this packet, part of the genereal header
1506 + * @reserved: reserved byte for alignment
1507 + * @seqno: sequence identification
1508 + * @orig: originator of the broadcast packet
1509 + */
1510 +struct batadv_bcast_packet {
1511 + __u8 packet_type;
1512 + __u8 version; /* batman version field */
1513 + __u8 ttl;
1514 + __u8 reserved;
1515 + __be32 seqno;
1516 + __u8 orig[ETH_ALEN];
1517 + /* "4 bytes boundary + 2 bytes" long to make the payload after the
1518 + * following ethernet header again 4 bytes boundary aligned
1519 + */
1520 +};
1521 +
1522 +/**
1523 + * struct batadv_coded_packet - network coded packet
1524 + * @packet_type: batman-adv packet type, part of the general header
1525 + * @version: batman-adv protocol version, part of the genereal header
1526 + * @ttl: time to live for this packet, part of the genereal header
1527 + * @first_source: original source of first included packet
1528 + * @first_orig_dest: original destinal of first included packet
1529 + * @first_crc: checksum of first included packet
1530 + * @first_ttvn: tt-version number of first included packet
1531 + * @second_ttl: ttl of second packet
1532 + * @second_dest: second receiver of this coded packet
1533 + * @second_source: original source of second included packet
1534 + * @second_orig_dest: original destination of second included packet
1535 + * @second_crc: checksum of second included packet
1536 + * @second_ttvn: tt version number of second included packet
1537 + * @coded_len: length of network coded part of the payload
1538 + */
1539 +struct batadv_coded_packet {
1540 + __u8 packet_type;
1541 + __u8 version; /* batman version field */
1542 + __u8 ttl;
1543 + __u8 first_ttvn;
1544 + /* __u8 first_dest[ETH_ALEN]; - saved in mac header destination */
1545 + __u8 first_source[ETH_ALEN];
1546 + __u8 first_orig_dest[ETH_ALEN];
1547 + __be32 first_crc;
1548 + __u8 second_ttl;
1549 + __u8 second_ttvn;
1550 + __u8 second_dest[ETH_ALEN];
1551 + __u8 second_source[ETH_ALEN];
1552 + __u8 second_orig_dest[ETH_ALEN];
1553 + __be32 second_crc;
1554 + __be16 coded_len;
1555 +};
1556 +
1557 +#pragma pack()
1558 +
1559 +/**
1560 + * struct batadv_unicast_tvlv_packet - generic unicast packet with tvlv payload
1561 + * @packet_type: batman-adv packet type, part of the general header
1562 + * @version: batman-adv protocol version, part of the genereal header
1563 + * @ttl: time to live for this packet, part of the genereal header
1564 + * @reserved: reserved field (for packet alignment)
1565 + * @src: address of the source
1566 + * @dst: address of the destination
1567 + * @tvlv_len: length of tvlv data following the unicast tvlv header
1568 + * @align: 2 bytes to align the header to a 4 byte boundary
1569 + */
1570 +struct batadv_unicast_tvlv_packet {
1571 + __u8 packet_type;
1572 + __u8 version; /* batman version field */
1573 + __u8 ttl;
1574 + __u8 reserved;
1575 + __u8 dst[ETH_ALEN];
1576 + __u8 src[ETH_ALEN];
1577 + __be16 tvlv_len;
1578 + __u16 align;
1579 +};
1580 +
1581 +/**
1582 + * struct batadv_tvlv_hdr - base tvlv header struct
1583 + * @type: tvlv container type (see batadv_tvlv_type)
1584 + * @version: tvlv container version
1585 + * @len: tvlv container length
1586 + */
1587 +struct batadv_tvlv_hdr {
1588 + __u8 type;
1589 + __u8 version;
1590 + __be16 len;
1591 +};
1592 +
1593 +/**
1594 + * struct batadv_tvlv_gateway_data - gateway data propagated through gw tvlv
1595 + * container
1596 + * @bandwidth_down: advertised uplink download bandwidth
1597 + * @bandwidth_up: advertised uplink upload bandwidth
1598 + */
1599 +struct batadv_tvlv_gateway_data {
1600 + __be32 bandwidth_down;
1601 + __be32 bandwidth_up;
1602 +};
1603 +
1604 +/**
1605 + * struct batadv_tvlv_tt_data - tt data propagated through the tt tvlv container
1606 + * @flags: translation table flags (see batadv_tt_data_flags)
1607 + * @ttvn: translation table version number
1608 + * @num_vlan: number of announced VLANs. In the TVLV this struct is followed by
1609 + * one batadv_tvlv_tt_vlan_data object per announced vlan
1610 + */
1611 +struct batadv_tvlv_tt_data {
1612 + __u8 flags;
1613 + __u8 ttvn;
1614 + __be16 num_vlan;
1615 +};
1616 +
1617 +/**
1618 + * struct batadv_tvlv_tt_vlan_data - vlan specific tt data propagated through
1619 + * the tt tvlv container
1620 + * @crc: crc32 checksum of the entries belonging to this vlan
1621 + * @vid: vlan identifier
1622 + * @reserved: unused, useful for alignment purposes
1623 + */
1624 +struct batadv_tvlv_tt_vlan_data {
1625 + __be32 crc;
1626 + __be16 vid;
1627 + __u16 reserved;
1628 +};
1629 +
1630 +/**
1631 + * struct batadv_tvlv_tt_change - translation table diff data
1632 + * @flags: status indicators concerning the non-mesh client (see
1633 + * batadv_tt_client_flags)
1634 + * @reserved: reserved field - useful for alignment purposes only
1635 + * @addr: mac address of non-mesh client that triggered this tt change
1636 + * @vid: VLAN identifier
1637 + */
1638 +struct batadv_tvlv_tt_change {
1639 + __u8 flags;
1640 + __u8 reserved[3];
1641 + __u8 addr[ETH_ALEN];
1642 + __be16 vid;
1643 +};
1644 +
1645 +/**
1646 + * struct batadv_tvlv_roam_adv - roaming advertisement
1647 + * @client: mac address of roaming client
1648 + * @vid: VLAN identifier
1649 + */
1650 +struct batadv_tvlv_roam_adv {
1651 + __u8 client[ETH_ALEN];
1652 + __be16 vid;
1653 +};
1654 +
1655 +/**
1656 + * struct batadv_tvlv_mcast_data - payload of a multicast tvlv
1657 + * @flags: multicast flags announced by the orig node
1658 + * @reserved: reserved field
1659 + */
1660 +struct batadv_tvlv_mcast_data {
1661 + __u8 flags;
1662 + __u8 reserved[3];
1663 +};
1664 +
1665 +#endif /* _UAPI_LINUX_BATADV_PACKET_H_ */