1 /* Copyright (C) 2007-2013 B.A.T.M.A.N. contributors:
3 * Marek Lindner, Simon Wunderlich
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.
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.
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
20 #ifndef _NET_BATMAN_ADV_PACKET_H_
21 #define _NET_BATMAN_ADV_PACKET_H_
24 * enum batadv_packettype - types for batman-adv encapsulated packets
25 * @BATADV_UNICAST_TVLV: unicast packet carrying TVLV containers
27 enum batadv_packettype {
30 BATADV_UNICAST = 0x03,
33 BATADV_UNICAST_FRAG = 0x06,
34 BATADV_ROAM_ADV = 0x08,
35 BATADV_UNICAST_4ADDR = 0x09,
37 BATADV_UNICAST_TVLV = 0x0b,
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
49 BATADV_P_DAT_DHT_GET = 0x02,
50 BATADV_P_DAT_DHT_PUT = 0x03,
51 BATADV_P_DAT_CACHE_REPLY = 0x04,
54 /* this file is included by batctl which needs these defines */
55 #define BATADV_COMPAT_VERSION 15
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),
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,
74 enum batadv_vis_packettype {
75 BATADV_VIS_TYPE_SERVER_SYNC = 0,
76 BATADV_VIS_TYPE_CLIENT_UPDATE = 1,
79 /* fragmentation defines */
80 enum batadv_unicast_frag_flags {
81 BATADV_UNI_FRAG_HEAD = BIT(0),
82 BATADV_UNI_FRAG_LARGETAIL = BIT(1),
85 /* tt data subtypes */
86 #define BATADV_TT_DATA_TYPE_MASK 0x0F
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
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),
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
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),
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,
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
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,
138 /* the destination hardware field in the ARP frame is used to
139 * transport the claim type and the group id
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 */
147 struct batadv_header {
149 uint8_t version; /* batman version field */
151 /* the parent struct has to add a byte after the header to make
152 * everything 4 bytes aligned again
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
161 struct batadv_ogm_packet {
162 struct batadv_header header;
163 uint8_t flags; /* 0x40: DIRECTLINK flag, 0x20 VIS_SERVER flag... */
165 uint8_t orig[ETH_ALEN];
166 uint8_t prev_sender[ETH_ALEN];
172 #define BATADV_OGM_HLEN sizeof(struct batadv_ogm_packet)
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];
184 #define BATADV_RR_LEN 16
186 /* icmp_packet_rr must start with all fields from imcp_packet
187 * as this is assumed by code that handles ICMP packets
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];
197 uint8_t rr[BATADV_RR_LEN][ETH_ALEN];
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.
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.
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
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
227 struct batadv_unicast_4addr_packet {
228 struct batadv_unicast_packet u;
229 uint8_t src[ETH_ALEN];
232 /* "4 bytes boundary + 2 bytes" long to make the payload after the
233 * following ethernet header again 4 bytes boundary aligned
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];
243 uint8_t orig[ETH_ALEN];
247 struct batadv_bcast_packet {
248 struct batadv_header header;
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
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 */
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 */
270 struct batadv_roam_adv_packet {
271 struct batadv_header header;
273 uint8_t dst[ETH_ALEN];
274 uint8_t src[ETH_ALEN];
275 uint8_t client[ETH_ALEN];
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
294 struct batadv_coded_packet {
295 struct batadv_header header;
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];
303 uint8_t second_dest[ETH_ALEN];
304 uint8_t second_source[ETH_ALEN];
305 uint8_t second_orig_dest[ETH_ALEN];
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
319 struct batadv_unicast_tvlv_packet {
320 struct batadv_header header;
322 uint8_t dst[ETH_ALEN];
323 uint8_t src[ETH_ALEN];
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
334 struct batadv_tvlv_hdr {
341 * struct batadv_tvlv_gateway_data - gateway data propagated through gw tvlv
343 * @bandwidth_down: advertised uplink download bandwidth
344 * @bandwidth_up: advertised uplink upload bandwidth
346 struct batadv_tvlv_gateway_data {
347 __be32 bandwidth_down;
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
357 struct batadv_tvlv_tt_data {
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
370 struct batadv_tvlv_tt_change {
373 uint8_t addr[ETH_ALEN];
376 #endif /* _NET_BATMAN_ADV_PACKET_H_ */