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,
32 BATADV_UNICAST_FRAG
= 0x06,
33 BATADV_UNICAST_4ADDR
= 0x09,
35 BATADV_UNICAST_TVLV
= 0x0b,
39 * enum batadv_subtype - packet subtype for unicast4addr
40 * @BATADV_P_DATA: user payload
41 * @BATADV_P_DAT_DHT_GET: DHT request message
42 * @BATADV_P_DAT_DHT_PUT: DHT store message
43 * @BATADV_P_DAT_CACHE_REPLY: ARP reply generated by DAT
47 BATADV_P_DAT_DHT_GET
= 0x02,
48 BATADV_P_DAT_DHT_PUT
= 0x03,
49 BATADV_P_DAT_CACHE_REPLY
= 0x04,
52 /* this file is included by batctl which needs these defines */
53 #define BATADV_COMPAT_VERSION 15
55 enum batadv_iv_flags
{
56 BATADV_NOT_BEST_NEXT_HOP
= BIT(3),
57 BATADV_PRIMARIES_FIRST_HOP
= BIT(4),
58 BATADV_DIRECTLINK
= BIT(6),
61 /* ICMP message types */
62 enum batadv_icmp_packettype
{
63 BATADV_ECHO_REPLY
= 0,
64 BATADV_DESTINATION_UNREACHABLE
= 3,
65 BATADV_ECHO_REQUEST
= 8,
66 BATADV_TTL_EXCEEDED
= 11,
67 BATADV_PARAMETER_PROBLEM
= 12,
70 /* fragmentation defines */
71 enum batadv_unicast_frag_flags
{
72 BATADV_UNI_FRAG_HEAD
= BIT(0),
73 BATADV_UNI_FRAG_LARGETAIL
= BIT(1),
76 /* tt data subtypes */
77 #define BATADV_TT_DATA_TYPE_MASK 0x0F
80 * enum batadv_tt_data_flags - flags for tt data tvlv
81 * @BATADV_TT_OGM_DIFF: TT diff propagated through OGM
82 * @BATADV_TT_REQUEST: TT request message
83 * @BATADV_TT_RESPONSE: TT response message
84 * @BATADV_TT_FULL_TABLE: contains full table to replace existing table
86 enum batadv_tt_data_flags
{
87 BATADV_TT_OGM_DIFF
= BIT(0),
88 BATADV_TT_REQUEST
= BIT(1),
89 BATADV_TT_RESPONSE
= BIT(2),
90 BATADV_TT_FULL_TABLE
= BIT(4),
93 /* BATADV_TT_CLIENT flags.
94 * Flags from BIT(0) to BIT(7) are sent on the wire, while flags from BIT(8) to
95 * BIT(15) are used for local computation only
97 enum batadv_tt_client_flags
{
98 BATADV_TT_CLIENT_DEL
= BIT(0),
99 BATADV_TT_CLIENT_ROAM
= BIT(1),
100 BATADV_TT_CLIENT_WIFI
= BIT(2),
101 BATADV_TT_CLIENT_NOPURGE
= BIT(8),
102 BATADV_TT_CLIENT_NEW
= BIT(9),
103 BATADV_TT_CLIENT_PENDING
= BIT(10),
104 BATADV_TT_CLIENT_TEMP
= BIT(11),
107 /* claim frame types for the bridge loop avoidance */
108 enum batadv_bla_claimframe
{
109 BATADV_CLAIM_TYPE_CLAIM
= 0x00,
110 BATADV_CLAIM_TYPE_UNCLAIM
= 0x01,
111 BATADV_CLAIM_TYPE_ANNOUNCE
= 0x02,
112 BATADV_CLAIM_TYPE_REQUEST
= 0x03,
116 * enum batadv_tvlv_type - tvlv type definitions
117 * @BATADV_TVLV_GW: gateway tvlv
118 * @BATADV_TVLV_DAT: distributed arp table tvlv
119 * @BATADV_TVLV_NC: network coding tvlv
120 * @BATADV_TVLV_TT: translation table tvlv
121 * @BATADV_TVLV_ROAM: roaming advertisement tvlv
123 enum batadv_tvlv_type
{
124 BATADV_TVLV_GW
= 0x01,
125 BATADV_TVLV_DAT
= 0x02,
126 BATADV_TVLV_NC
= 0x03,
127 BATADV_TVLV_TT
= 0x04,
128 BATADV_TVLV_ROAM
= 0x05,
131 /* the destination hardware field in the ARP frame is used to
132 * transport the claim type and the group id
134 struct batadv_bla_claim_dst
{
135 uint8_t magic
[3]; /* FF:43:05 */
136 uint8_t type
; /* bla_claimframe */
137 __be16 group
; /* group id */
140 struct batadv_header
{
142 uint8_t version
; /* batman version field */
144 /* the parent struct has to add a byte after the header to make
145 * everything 4 bytes aligned again
150 * struct batadv_ogm_packet - ogm (routing protocol) packet
151 * @header: common batman packet header
152 * @tvlv_len: length of tvlv data following the ogm header
154 struct batadv_ogm_packet
{
155 struct batadv_header header
;
156 uint8_t flags
; /* 0x40: DIRECTLINK flag ... */
158 uint8_t orig
[ETH_ALEN
];
159 uint8_t prev_sender
[ETH_ALEN
];
165 #define BATADV_OGM_HLEN sizeof(struct batadv_ogm_packet)
167 struct batadv_icmp_packet
{
168 struct batadv_header header
;
169 uint8_t msg_type
; /* see ICMP message types above */
170 uint8_t dst
[ETH_ALEN
];
171 uint8_t orig
[ETH_ALEN
];
177 #define BATADV_RR_LEN 16
179 /* icmp_packet_rr must start with all fields from imcp_packet
180 * as this is assumed by code that handles ICMP packets
182 struct batadv_icmp_packet_rr
{
183 struct batadv_header header
;
184 uint8_t msg_type
; /* see ICMP message types above */
185 uint8_t dst
[ETH_ALEN
];
186 uint8_t orig
[ETH_ALEN
];
190 uint8_t rr
[BATADV_RR_LEN
][ETH_ALEN
];
193 /* All packet headers in front of an ethernet header have to be completely
194 * divisible by 2 but not by 4 to make the payload after the ethernet
195 * header again 4 bytes boundary aligned.
197 * A packing of 2 is necessary to avoid extra padding at the end of the struct
198 * caused by a structure member which is larger than two bytes. Otherwise
199 * the structure would not fulfill the previously mentioned rule to avoid the
200 * misalignment of the payload after the ethernet header. It may also lead to
201 * leakage of information when the padding it not initialized before sending.
205 struct batadv_unicast_packet
{
206 struct batadv_header header
;
207 uint8_t ttvn
; /* destination translation table version number */
208 uint8_t dest
[ETH_ALEN
];
209 /* "4 bytes boundary + 2 bytes" long to make the payload after the
210 * following ethernet header again 4 bytes boundary aligned
215 * struct batadv_unicast_4addr_packet - extended unicast packet
216 * @u: common unicast packet header
217 * @src: address of the source
218 * @subtype: packet subtype
220 struct batadv_unicast_4addr_packet
{
221 struct batadv_unicast_packet u
;
222 uint8_t src
[ETH_ALEN
];
225 /* "4 bytes boundary + 2 bytes" long to make the payload after the
226 * following ethernet header again 4 bytes boundary aligned
230 struct batadv_unicast_frag_packet
{
231 struct batadv_header header
;
232 uint8_t ttvn
; /* destination translation table version number */
233 uint8_t dest
[ETH_ALEN
];
236 uint8_t orig
[ETH_ALEN
];
240 struct batadv_bcast_packet
{
241 struct batadv_header header
;
244 uint8_t orig
[ETH_ALEN
];
245 /* "4 bytes boundary + 2 bytes" long to make the payload after the
246 * following ethernet header again 4 bytes boundary aligned
253 * struct batadv_coded_packet - network coded packet
254 * @header: common batman packet header and ttl of first included packet
255 * @reserved: Align following fields to 2-byte boundaries
256 * @first_source: original source of first included packet
257 * @first_orig_dest: original destinal of first included packet
258 * @first_crc: checksum of first included packet
259 * @first_ttvn: tt-version number of first included packet
260 * @second_ttl: ttl of second packet
261 * @second_dest: second receiver of this coded packet
262 * @second_source: original source of second included packet
263 * @second_orig_dest: original destination of second included packet
264 * @second_crc: checksum of second included packet
265 * @second_ttvn: tt version number of second included packet
266 * @coded_len: length of network coded part of the payload
268 struct batadv_coded_packet
{
269 struct batadv_header header
;
271 /* uint8_t first_dest[ETH_ALEN]; - saved in mac header destination */
272 uint8_t first_source
[ETH_ALEN
];
273 uint8_t first_orig_dest
[ETH_ALEN
];
277 uint8_t second_dest
[ETH_ALEN
];
278 uint8_t second_source
[ETH_ALEN
];
279 uint8_t second_orig_dest
[ETH_ALEN
];
285 * struct batadv_unicast_tvlv - generic unicast packet with tvlv payload
286 * @header: common batman packet header
287 * @reserved: reserved field (for packet alignment)
288 * @src: address of the source
289 * @dst: address of the destination
290 * @tvlv_len: length of tvlv data following the unicast tvlv header
291 * @align: 2 bytes to align the header to a 4 byte boundry
293 struct batadv_unicast_tvlv_packet
{
294 struct batadv_header header
;
296 uint8_t dst
[ETH_ALEN
];
297 uint8_t src
[ETH_ALEN
];
303 * struct batadv_tvlv_hdr - base tvlv header struct
304 * @type: tvlv container type (see batadv_tvlv_type)
305 * @version: tvlv container version
306 * @len: tvlv container length
308 struct batadv_tvlv_hdr
{
315 * struct batadv_tvlv_gateway_data - gateway data propagated through gw tvlv
317 * @bandwidth_down: advertised uplink download bandwidth
318 * @bandwidth_up: advertised uplink upload bandwidth
320 struct batadv_tvlv_gateway_data
{
321 __be32 bandwidth_down
;
326 * struct batadv_tvlv_tt_data - tt data propagated through the tt tvlv container
327 * @flags: translation table flags (see batadv_tt_data_flags)
328 * @ttvn: translation table version number
329 * @reserved: field reserved for future use
330 * @crc: crc32 checksum of the local translation table
332 struct batadv_tvlv_tt_data
{
340 * struct batadv_tvlv_tt_change - translation table diff data
341 * @flags: status indicators concerning the non-mesh client (see
342 * batadv_tt_client_flags)
343 * @reserved: reserved field
344 * @addr: mac address of non-mesh client that triggered this tt change
346 struct batadv_tvlv_tt_change
{
349 uint8_t addr
[ETH_ALEN
];
353 * struct batadv_tvlv_roam_adv - roaming advertisement
354 * @client: mac address of roaming client
355 * @reserved: field reserved for future use
357 struct batadv_tvlv_roam_adv
{
358 uint8_t client
[ETH_ALEN
];
362 #endif /* _NET_BATMAN_ADV_PACKET_H_ */