diff options
author | Simon Wunderlich <sw@simonwunderlich.de> | 2013-12-02 14:38:31 -0500 |
---|---|---|
committer | Antonio Quartulli <antonio@meshcoding.com> | 2013-12-28 06:51:16 -0500 |
commit | a40d9b075c21f06872de3f05cc2eb3d06665e2ff (patch) | |
tree | 85aefae654246aa4f89e046bb0bca6b5b85b76f6 /net/batman-adv/packet.h | |
parent | 46b76e0b8b5e21fa5a2387d6f72b193514e7f722 (diff) |
batman-adv: fix header alignment by unrolling batadv_header
The size of the batadv_header of 3 is problematic on some architectures
which automatically pad all structures to a 32 bit boundary. To not lose
performance by packing this struct, better embed it into the various
host structures.
Reported-by: Russell King <linux@arm.linux.org.uk>
Signed-off-by: Simon Wunderlich <sw@simonwunderlich.de>
Signed-off-by: Marek Lindner <mareklindner@neomailbox.ch>
Signed-off-by: Antonio Quartulli <antonio@meshcoding.com>
Diffstat (limited to 'net/batman-adv/packet.h')
-rw-r--r-- | net/batman-adv/packet.h | 74 |
1 files changed, 53 insertions, 21 deletions
diff --git a/net/batman-adv/packet.h b/net/batman-adv/packet.h index 10597a6729a6..175ce7d721d6 100644 --- a/net/batman-adv/packet.h +++ b/net/batman-adv/packet.h | |||
@@ -164,23 +164,18 @@ struct batadv_bla_claim_dst { | |||
164 | __be16 group; /* group id */ | 164 | __be16 group; /* group id */ |
165 | }; | 165 | }; |
166 | 166 | ||
167 | struct batadv_header { | ||
168 | uint8_t packet_type; | ||
169 | uint8_t version; /* batman version field */ | ||
170 | uint8_t ttl; | ||
171 | /* the parent struct has to add a byte after the header to make | ||
172 | * everything 4 bytes aligned again | ||
173 | */ | ||
174 | }; | ||
175 | |||
176 | /** | 167 | /** |
177 | * struct batadv_ogm_packet - ogm (routing protocol) packet | 168 | * struct batadv_ogm_packet - ogm (routing protocol) packet |
178 | * @header: common batman packet header | 169 | * @packet_type: batman-adv packet type, part of the general header |
170 | * @version: batman-adv protocol version, part of the genereal header | ||
171 | * @ttl: time to live for this packet, part of the genereal header | ||
179 | * @flags: contains routing relevant flags - see enum batadv_iv_flags | 172 | * @flags: contains routing relevant flags - see enum batadv_iv_flags |
180 | * @tvlv_len: length of tvlv data following the ogm header | 173 | * @tvlv_len: length of tvlv data following the ogm header |
181 | */ | 174 | */ |
182 | struct batadv_ogm_packet { | 175 | struct batadv_ogm_packet { |
183 | struct batadv_header header; | 176 | uint8_t packet_type; |
177 | uint8_t version; | ||
178 | uint8_t ttl; | ||
184 | uint8_t flags; | 179 | uint8_t flags; |
185 | __be32 seqno; | 180 | __be32 seqno; |
186 | uint8_t orig[ETH_ALEN]; | 181 | uint8_t orig[ETH_ALEN]; |
@@ -197,14 +192,18 @@ struct batadv_ogm_packet { | |||
197 | 192 | ||
198 | /** | 193 | /** |
199 | * batadv_icmp_header - common ICMP header | 194 | * batadv_icmp_header - common ICMP header |
200 | * @header: common batman header | 195 | * @packet_type: batman-adv packet type, part of the general header |
196 | * @version: batman-adv protocol version, part of the genereal header | ||
197 | * @ttl: time to live for this packet, part of the genereal header | ||
201 | * @msg_type: ICMP packet type | 198 | * @msg_type: ICMP packet type |
202 | * @dst: address of the destination node | 199 | * @dst: address of the destination node |
203 | * @orig: address of the source node | 200 | * @orig: address of the source node |
204 | * @uid: local ICMP socket identifier | 201 | * @uid: local ICMP socket identifier |
205 | */ | 202 | */ |
206 | struct batadv_icmp_header { | 203 | struct batadv_icmp_header { |
207 | struct batadv_header header; | 204 | uint8_t packet_type; |
205 | uint8_t version; | ||
206 | uint8_t ttl; | ||
208 | uint8_t msg_type; /* see ICMP message types above */ | 207 | uint8_t msg_type; /* see ICMP message types above */ |
209 | uint8_t dst[ETH_ALEN]; | 208 | uint8_t dst[ETH_ALEN]; |
210 | uint8_t orig[ETH_ALEN]; | 209 | uint8_t orig[ETH_ALEN]; |
@@ -253,8 +252,18 @@ struct batadv_icmp_packet_rr { | |||
253 | */ | 252 | */ |
254 | #pragma pack(2) | 253 | #pragma pack(2) |
255 | 254 | ||
255 | /** | ||
256 | * struct batadv_unicast_packet - unicast packet for network payload | ||
257 | * @packet_type: batman-adv packet type, part of the general header | ||
258 | * @version: batman-adv protocol version, part of the genereal header | ||
259 | * @ttl: time to live for this packet, part of the genereal header | ||
260 | * @ttvn: translation table version number | ||
261 | * @dest: originator destination of the unicast packet | ||
262 | */ | ||
256 | struct batadv_unicast_packet { | 263 | struct batadv_unicast_packet { |
257 | struct batadv_header header; | 264 | uint8_t packet_type; |
265 | uint8_t version; | ||
266 | uint8_t ttl; | ||
258 | uint8_t ttvn; /* destination translation table version number */ | 267 | uint8_t ttvn; /* destination translation table version number */ |
259 | uint8_t dest[ETH_ALEN]; | 268 | uint8_t dest[ETH_ALEN]; |
260 | /* "4 bytes boundary + 2 bytes" long to make the payload after the | 269 | /* "4 bytes boundary + 2 bytes" long to make the payload after the |
@@ -280,7 +289,9 @@ struct batadv_unicast_4addr_packet { | |||
280 | 289 | ||
281 | /** | 290 | /** |
282 | * struct batadv_frag_packet - fragmented packet | 291 | * struct batadv_frag_packet - fragmented packet |
283 | * @header: common batman packet header with type, compatversion, and ttl | 292 | * @packet_type: batman-adv packet type, part of the general header |
293 | * @version: batman-adv protocol version, part of the genereal header | ||
294 | * @ttl: time to live for this packet, part of the genereal header | ||
284 | * @dest: final destination used when routing fragments | 295 | * @dest: final destination used when routing fragments |
285 | * @orig: originator of the fragment used when merging the packet | 296 | * @orig: originator of the fragment used when merging the packet |
286 | * @no: fragment number within this sequence | 297 | * @no: fragment number within this sequence |
@@ -289,7 +300,9 @@ struct batadv_unicast_4addr_packet { | |||
289 | * @total_size: size of the merged packet | 300 | * @total_size: size of the merged packet |
290 | */ | 301 | */ |
291 | struct batadv_frag_packet { | 302 | struct batadv_frag_packet { |
292 | struct batadv_header header; | 303 | uint8_t packet_type; |
304 | uint8_t version; /* batman version field */ | ||
305 | uint8_t ttl; | ||
293 | #if defined(__BIG_ENDIAN_BITFIELD) | 306 | #if defined(__BIG_ENDIAN_BITFIELD) |
294 | uint8_t no:4; | 307 | uint8_t no:4; |
295 | uint8_t reserved:4; | 308 | uint8_t reserved:4; |
@@ -305,8 +318,19 @@ struct batadv_frag_packet { | |||
305 | __be16 total_size; | 318 | __be16 total_size; |
306 | }; | 319 | }; |
307 | 320 | ||
321 | /** | ||
322 | * struct batadv_bcast_packet - broadcast packet for network payload | ||
323 | * @packet_type: batman-adv packet type, part of the general header | ||
324 | * @version: batman-adv protocol version, part of the genereal header | ||
325 | * @ttl: time to live for this packet, part of the genereal header | ||
326 | * @reserved: reserved byte for alignment | ||
327 | * @seqno: sequence identification | ||
328 | * @orig: originator of the broadcast packet | ||
329 | */ | ||
308 | struct batadv_bcast_packet { | 330 | struct batadv_bcast_packet { |
309 | struct batadv_header header; | 331 | uint8_t packet_type; |
332 | uint8_t version; /* batman version field */ | ||
333 | uint8_t ttl; | ||
310 | uint8_t reserved; | 334 | uint8_t reserved; |
311 | __be32 seqno; | 335 | __be32 seqno; |
312 | uint8_t orig[ETH_ALEN]; | 336 | uint8_t orig[ETH_ALEN]; |
@@ -317,7 +341,9 @@ struct batadv_bcast_packet { | |||
317 | 341 | ||
318 | /** | 342 | /** |
319 | * struct batadv_coded_packet - network coded packet | 343 | * struct batadv_coded_packet - network coded packet |
320 | * @header: common batman packet header and ttl of first included packet | 344 | * @packet_type: batman-adv packet type, part of the general header |
345 | * @version: batman-adv protocol version, part of the genereal header | ||
346 | * @ttl: time to live for this packet, part of the genereal header | ||
321 | * @reserved: Align following fields to 2-byte boundaries | 347 | * @reserved: Align following fields to 2-byte boundaries |
322 | * @first_source: original source of first included packet | 348 | * @first_source: original source of first included packet |
323 | * @first_orig_dest: original destinal of first included packet | 349 | * @first_orig_dest: original destinal of first included packet |
@@ -332,7 +358,9 @@ struct batadv_bcast_packet { | |||
332 | * @coded_len: length of network coded part of the payload | 358 | * @coded_len: length of network coded part of the payload |
333 | */ | 359 | */ |
334 | struct batadv_coded_packet { | 360 | struct batadv_coded_packet { |
335 | struct batadv_header header; | 361 | uint8_t packet_type; |
362 | uint8_t version; /* batman version field */ | ||
363 | uint8_t ttl; | ||
336 | uint8_t first_ttvn; | 364 | uint8_t first_ttvn; |
337 | /* uint8_t first_dest[ETH_ALEN]; - saved in mac header destination */ | 365 | /* uint8_t first_dest[ETH_ALEN]; - saved in mac header destination */ |
338 | uint8_t first_source[ETH_ALEN]; | 366 | uint8_t first_source[ETH_ALEN]; |
@@ -351,7 +379,9 @@ struct batadv_coded_packet { | |||
351 | 379 | ||
352 | /** | 380 | /** |
353 | * struct batadv_unicast_tvlv - generic unicast packet with tvlv payload | 381 | * struct batadv_unicast_tvlv - generic unicast packet with tvlv payload |
354 | * @header: common batman packet header | 382 | * @packet_type: batman-adv packet type, part of the general header |
383 | * @version: batman-adv protocol version, part of the genereal header | ||
384 | * @ttl: time to live for this packet, part of the genereal header | ||
355 | * @reserved: reserved field (for packet alignment) | 385 | * @reserved: reserved field (for packet alignment) |
356 | * @src: address of the source | 386 | * @src: address of the source |
357 | * @dst: address of the destination | 387 | * @dst: address of the destination |
@@ -359,7 +389,9 @@ struct batadv_coded_packet { | |||
359 | * @align: 2 bytes to align the header to a 4 byte boundry | 389 | * @align: 2 bytes to align the header to a 4 byte boundry |
360 | */ | 390 | */ |
361 | struct batadv_unicast_tvlv_packet { | 391 | struct batadv_unicast_tvlv_packet { |
362 | struct batadv_header header; | 392 | uint8_t packet_type; |
393 | uint8_t version; /* batman version field */ | ||
394 | uint8_t ttl; | ||
363 | uint8_t reserved; | 395 | uint8_t reserved; |
364 | uint8_t dst[ETH_ALEN]; | 396 | uint8_t dst[ETH_ALEN]; |
365 | uint8_t src[ETH_ALEN]; | 397 | uint8_t src[ETH_ALEN]; |