]> git.karo-electronics.de Git - karo-tx-linux.git/blob - net/batman-adv/packet.h
batman-adv: tvlv - convert tt query packet to use tvlv unicast packets
[karo-tx-linux.git] / net / batman-adv / packet.h
1 /* Copyright (C) 2007-2013 B.A.T.M.A.N. contributors:
2  *
3  * Marek Lindner, Simon Wunderlich
4  *
5  * This program is free software; you can redistribute it and/or
6  * modify it under the terms of version 2 of the GNU General Public
7  * License as published by the Free Software Foundation.
8  *
9  * This program is distributed in the hope that it will be useful, but
10  * WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12  * General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program; if not, write to the Free Software
16  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
17  * 02110-1301, USA
18  */
19
20 #ifndef _NET_BATMAN_ADV_PACKET_H_
21 #define _NET_BATMAN_ADV_PACKET_H_
22
23 /**
24  * enum batadv_packettype - types for batman-adv encapsulated packets
25  * @BATADV_UNICAST_TVLV: unicast packet carrying TVLV containers
26  */
27 enum batadv_packettype {
28         BATADV_IV_OGM           = 0x01,
29         BATADV_ICMP             = 0x02,
30         BATADV_UNICAST          = 0x03,
31         BATADV_BCAST            = 0x04,
32         BATADV_VIS              = 0x05,
33         BATADV_UNICAST_FRAG     = 0x06,
34         BATADV_ROAM_ADV         = 0x08,
35         BATADV_UNICAST_4ADDR    = 0x09,
36         BATADV_CODED            = 0x0a,
37         BATADV_UNICAST_TVLV     = 0x0b,
38 };
39
40 /**
41  * enum batadv_subtype - packet subtype for unicast4addr
42  * @BATADV_P_DATA: user payload
43  * @BATADV_P_DAT_DHT_GET: DHT request message
44  * @BATADV_P_DAT_DHT_PUT: DHT store message
45  * @BATADV_P_DAT_CACHE_REPLY: ARP reply generated by DAT
46  */
47 enum batadv_subtype {
48         BATADV_P_DATA                   = 0x01,
49         BATADV_P_DAT_DHT_GET            = 0x02,
50         BATADV_P_DAT_DHT_PUT            = 0x03,
51         BATADV_P_DAT_CACHE_REPLY        = 0x04,
52 };
53
54 /* this file is included by batctl which needs these defines */
55 #define BATADV_COMPAT_VERSION 15
56
57 enum batadv_iv_flags {
58         BATADV_NOT_BEST_NEXT_HOP   = BIT(3),
59         BATADV_PRIMARIES_FIRST_HOP = BIT(4),
60         BATADV_VIS_SERVER          = BIT(5),
61         BATADV_DIRECTLINK          = BIT(6),
62 };
63
64 /* ICMP message types */
65 enum batadv_icmp_packettype {
66         BATADV_ECHO_REPLY              = 0,
67         BATADV_DESTINATION_UNREACHABLE = 3,
68         BATADV_ECHO_REQUEST            = 8,
69         BATADV_TTL_EXCEEDED            = 11,
70         BATADV_PARAMETER_PROBLEM       = 12,
71 };
72
73 /* vis defines */
74 enum batadv_vis_packettype {
75         BATADV_VIS_TYPE_SERVER_SYNC   = 0,
76         BATADV_VIS_TYPE_CLIENT_UPDATE = 1,
77 };
78
79 /* fragmentation defines */
80 enum batadv_unicast_frag_flags {
81         BATADV_UNI_FRAG_HEAD      = BIT(0),
82         BATADV_UNI_FRAG_LARGETAIL = BIT(1),
83 };
84
85 /* tt data subtypes */
86 #define BATADV_TT_DATA_TYPE_MASK 0x0F
87
88 /**
89  * enum batadv_tt_data_flags - flags for tt data tvlv
90  * @BATADV_TT_OGM_DIFF: TT diff propagated through OGM
91  * @BATADV_TT_REQUEST: TT request message
92  * @BATADV_TT_RESPONSE: TT response message
93  * @BATADV_TT_FULL_TABLE: contains full table to replace existing table
94  */
95 enum batadv_tt_data_flags {
96         BATADV_TT_OGM_DIFF   = BIT(0),
97         BATADV_TT_REQUEST    = BIT(1),
98         BATADV_TT_RESPONSE   = BIT(2),
99         BATADV_TT_FULL_TABLE = BIT(4),
100 };
101
102 /* BATADV_TT_CLIENT flags.
103  * Flags from BIT(0) to BIT(7) are sent on the wire, while flags from BIT(8) to
104  * BIT(15) are used for local computation only
105  */
106 enum batadv_tt_client_flags {
107         BATADV_TT_CLIENT_DEL     = BIT(0),
108         BATADV_TT_CLIENT_ROAM    = BIT(1),
109         BATADV_TT_CLIENT_WIFI    = BIT(2),
110         BATADV_TT_CLIENT_TEMP    = BIT(3),
111         BATADV_TT_CLIENT_NOPURGE = BIT(8),
112         BATADV_TT_CLIENT_NEW     = BIT(9),
113         BATADV_TT_CLIENT_PENDING = BIT(10),
114 };
115
116 /* claim frame types for the bridge loop avoidance */
117 enum batadv_bla_claimframe {
118         BATADV_CLAIM_TYPE_CLAIM         = 0x00,
119         BATADV_CLAIM_TYPE_UNCLAIM       = 0x01,
120         BATADV_CLAIM_TYPE_ANNOUNCE      = 0x02,
121         BATADV_CLAIM_TYPE_REQUEST       = 0x03,
122 };
123
124 /**
125  * enum batadv_tvlv_type - tvlv type definitions
126  * @BATADV_TVLV_GW: gateway tvlv
127  * @BATADV_TVLV_DAT: distributed arp table tvlv
128  * @BATADV_TVLV_NC: network coding tvlv
129  * @BATADV_TVLV_TT: translation table tvlv
130  */
131 enum batadv_tvlv_type {
132         BATADV_TVLV_GW          = 0x01,
133         BATADV_TVLV_DAT         = 0x02,
134         BATADV_TVLV_NC          = 0x03,
135         BATADV_TVLV_TT          = 0x04,
136 };
137
138 /* the destination hardware field in the ARP frame is used to
139  * transport the claim type and the group id
140  */
141 struct batadv_bla_claim_dst {
142         uint8_t magic[3];       /* FF:43:05 */
143         uint8_t type;           /* bla_claimframe */
144         __be16 group;           /* group id */
145 };
146
147 struct batadv_header {
148         uint8_t  packet_type;
149         uint8_t  version;  /* batman version field */
150         uint8_t  ttl;
151         /* the parent struct has to add a byte after the header to make
152          * everything 4 bytes aligned again
153          */
154 };
155
156 /**
157  * struct batadv_ogm_packet - ogm (routing protocol) packet
158  * @header: common batman packet header
159  * @tvlv_len: length of tvlv data following the ogm header
160  */
161 struct batadv_ogm_packet {
162         struct batadv_header header;
163         uint8_t  flags;    /* 0x40: DIRECTLINK flag, 0x20 VIS_SERVER flag... */
164         __be32   seqno;
165         uint8_t  orig[ETH_ALEN];
166         uint8_t  prev_sender[ETH_ALEN];
167         uint8_t  reserved;
168         uint8_t  tq;
169         __be16   tvlv_len;
170 } __packed;
171
172 #define BATADV_OGM_HLEN sizeof(struct batadv_ogm_packet)
173
174 struct batadv_icmp_packet {
175         struct batadv_header header;
176         uint8_t  msg_type; /* see ICMP message types above */
177         uint8_t  dst[ETH_ALEN];
178         uint8_t  orig[ETH_ALEN];
179         __be16   seqno;
180         uint8_t  uid;
181         uint8_t  reserved;
182 };
183
184 #define BATADV_RR_LEN 16
185
186 /* icmp_packet_rr must start with all fields from imcp_packet
187  * as this is assumed by code that handles ICMP packets
188  */
189 struct batadv_icmp_packet_rr {
190         struct batadv_header header;
191         uint8_t  msg_type; /* see ICMP message types above */
192         uint8_t  dst[ETH_ALEN];
193         uint8_t  orig[ETH_ALEN];
194         __be16   seqno;
195         uint8_t  uid;
196         uint8_t  rr_cur;
197         uint8_t  rr[BATADV_RR_LEN][ETH_ALEN];
198 };
199
200 /* All packet headers in front of an ethernet header have to be completely
201  * divisible by 2 but not by 4 to make the payload after the ethernet
202  * header again 4 bytes boundary aligned.
203  *
204  * A packing of 2 is necessary to avoid extra padding at the end of the struct
205  * caused by a structure member which is larger than two bytes. Otherwise
206  * the structure would not fulfill the previously mentioned rule to avoid the
207  * misalignment of the payload after the ethernet header. It may also lead to
208  * leakage of information when the padding it not initialized before sending.
209  */
210 #pragma pack(2)
211
212 struct batadv_unicast_packet {
213         struct batadv_header header;
214         uint8_t  ttvn; /* destination translation table version number */
215         uint8_t  dest[ETH_ALEN];
216         /* "4 bytes boundary + 2 bytes" long to make the payload after the
217          * following ethernet header again 4 bytes boundary aligned
218          */
219 };
220
221 /**
222  * struct batadv_unicast_4addr_packet - extended unicast packet
223  * @u: common unicast packet header
224  * @src: address of the source
225  * @subtype: packet subtype
226  */
227 struct batadv_unicast_4addr_packet {
228         struct batadv_unicast_packet u;
229         uint8_t src[ETH_ALEN];
230         uint8_t subtype;
231         uint8_t reserved;
232         /* "4 bytes boundary + 2 bytes" long to make the payload after the
233          * following ethernet header again 4 bytes boundary aligned
234          */
235 };
236
237 struct batadv_unicast_frag_packet {
238         struct batadv_header header;
239         uint8_t  ttvn; /* destination translation table version number */
240         uint8_t  dest[ETH_ALEN];
241         uint8_t  flags;
242         uint8_t  align;
243         uint8_t  orig[ETH_ALEN];
244         __be16   seqno;
245 } __packed;
246
247 struct batadv_bcast_packet {
248         struct batadv_header header;
249         uint8_t  reserved;
250         __be32   seqno;
251         uint8_t  orig[ETH_ALEN];
252         /* "4 bytes boundary + 2 bytes" long to make the payload after the
253          * following ethernet header again 4 bytes boundary aligned
254          */
255 };
256
257 #pragma pack()
258
259 struct batadv_vis_packet {
260         struct batadv_header header;
261         uint8_t  vis_type;       /* which type of vis-participant sent this? */
262         __be32   seqno;          /* sequence number */
263         uint8_t  entries;        /* number of entries behind this struct */
264         uint8_t  reserved;
265         uint8_t  vis_orig[ETH_ALEN];    /* originator reporting its neighbors */
266         uint8_t  target_orig[ETH_ALEN]; /* who should receive this packet */
267         uint8_t  sender_orig[ETH_ALEN]; /* who sent or forwarded this packet */
268 };
269
270 struct batadv_roam_adv_packet {
271         struct batadv_header header;
272         uint8_t  reserved;
273         uint8_t  dst[ETH_ALEN];
274         uint8_t  src[ETH_ALEN];
275         uint8_t  client[ETH_ALEN];
276 } __packed;
277
278 /**
279  * struct batadv_coded_packet - network coded packet
280  * @header: common batman packet header and ttl of first included packet
281  * @reserved: Align following fields to 2-byte boundaries
282  * @first_source: original source of first included packet
283  * @first_orig_dest: original destinal of first included packet
284  * @first_crc: checksum of first included packet
285  * @first_ttvn: tt-version number of first included packet
286  * @second_ttl: ttl of second packet
287  * @second_dest: second receiver of this coded packet
288  * @second_source: original source of second included packet
289  * @second_orig_dest: original destination of second included packet
290  * @second_crc: checksum of second included packet
291  * @second_ttvn: tt version number of second included packet
292  * @coded_len: length of network coded part of the payload
293  */
294 struct batadv_coded_packet {
295         struct batadv_header header;
296         uint8_t  first_ttvn;
297         /* uint8_t  first_dest[ETH_ALEN]; - saved in mac header destination */
298         uint8_t  first_source[ETH_ALEN];
299         uint8_t  first_orig_dest[ETH_ALEN];
300         __be32   first_crc;
301         uint8_t  second_ttl;
302         uint8_t  second_ttvn;
303         uint8_t  second_dest[ETH_ALEN];
304         uint8_t  second_source[ETH_ALEN];
305         uint8_t  second_orig_dest[ETH_ALEN];
306         __be32   second_crc;
307         __be16   coded_len;
308 };
309
310 /**
311  * struct batadv_unicast_tvlv - generic unicast packet with tvlv payload
312  * @header: common batman packet header
313  * @reserved: reserved field (for packet alignment)
314  * @src: address of the source
315  * @dst: address of the destination
316  * @tvlv_len: length of tvlv data following the unicast tvlv header
317  * @align: 2 bytes to align the header to a 4 byte boundry
318  */
319 struct batadv_unicast_tvlv_packet {
320         struct batadv_header header;
321         uint8_t  reserved;
322         uint8_t  dst[ETH_ALEN];
323         uint8_t  src[ETH_ALEN];
324         __be16   tvlv_len;
325         uint16_t align;
326 };
327
328 /**
329  * struct batadv_tvlv_hdr - base tvlv header struct
330  * @type: tvlv container type (see batadv_tvlv_type)
331  * @version: tvlv container version
332  * @len: tvlv container length
333  */
334 struct batadv_tvlv_hdr {
335         uint8_t type;
336         uint8_t version;
337         __be16  len;
338 };
339
340 /**
341  * struct batadv_tvlv_gateway_data - gateway data propagated through gw tvlv
342  *  container
343  * @bandwidth_down: advertised uplink download bandwidth
344  * @bandwidth_up: advertised uplink upload bandwidth
345  */
346 struct batadv_tvlv_gateway_data {
347         __be32 bandwidth_down;
348         __be32 bandwidth_up;
349 };
350
351 /**
352  * struct batadv_tvlv_tt_data - tt data propagated through the tt tvlv container
353  * @flags: translation table flags (see batadv_tt_data_flags)
354  * @ttvn: translation table version number
355  * @crc: crc16 checksum of the local translation table
356  */
357 struct batadv_tvlv_tt_data {
358         uint8_t flags;
359         uint8_t ttvn;
360         __be16  crc;
361 };
362
363 /**
364  * struct batadv_tvlv_tt_change - translation table diff data
365  * @flags: status indicators concerning the non-mesh client (see
366  *  batadv_tt_client_flags)
367  * @reserved: reserved field
368  * @addr: mac address of non-mesh client that triggered this tt change
369  */
370 struct batadv_tvlv_tt_change {
371         uint8_t flags;
372         uint8_t reserved;
373         uint8_t addr[ETH_ALEN];
374 };
375
376 #endif /* _NET_BATMAN_ADV_PACKET_H_ */