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