aboutsummaryrefslogtreecommitdiffstats
path: root/net
diff options
context:
space:
mode:
authorAntonio Quartulli <antonio@meshcoding.com>2013-12-05 09:33:00 -0500
committerAntonio Quartulli <antonio@meshcoding.com>2013-12-28 06:51:16 -0500
commit27a417e6badac911487c10990e04f5ccbb11b1b2 (patch)
tree7c3910eb29b61fdc3cea7e9c8eea14a2e0e1771c /net
parenta40d9b075c21f06872de3f05cc2eb3d06665e2ff (diff)
batman-adv: fix size of batadv_icmp_header
struct batadv_icmp_header currently has a size of 17, which will be padded to 20 on some architectures. Fix this by unrolling the header into the parent structures. Moreover keep the ICMP parsing functions as generic as they are now by using a stub icmp_header struct during packet parsing. Signed-off-by: Antonio Quartulli <antonio@meshcoding.com> Signed-off-by: Marek Lindner <mareklindner@neomailbox.ch>
Diffstat (limited to 'net')
-rw-r--r--net/batman-adv/main.c4
-rw-r--r--net/batman-adv/packet.h40
-rw-r--r--net/batman-adv/routing.c14
3 files changed, 44 insertions, 14 deletions
diff --git a/net/batman-adv/main.c b/net/batman-adv/main.c
index d87778b9c5b4..1511f64a6cea 100644
--- a/net/batman-adv/main.c
+++ b/net/batman-adv/main.c
@@ -426,8 +426,8 @@ static void batadv_recv_handler_init(void)
426 BUILD_BUG_ON(offsetof(struct batadv_unicast_packet, dest) != 4); 426 BUILD_BUG_ON(offsetof(struct batadv_unicast_packet, dest) != 4);
427 BUILD_BUG_ON(offsetof(struct batadv_unicast_tvlv_packet, dst) != 4); 427 BUILD_BUG_ON(offsetof(struct batadv_unicast_tvlv_packet, dst) != 4);
428 BUILD_BUG_ON(offsetof(struct batadv_frag_packet, dest) != 4); 428 BUILD_BUG_ON(offsetof(struct batadv_frag_packet, dest) != 4);
429 BUILD_BUG_ON(offsetof(struct batadv_icmp_packet, icmph.dst) != 4); 429 BUILD_BUG_ON(offsetof(struct batadv_icmp_packet, dst) != 4);
430 BUILD_BUG_ON(offsetof(struct batadv_icmp_packet_rr, icmph.dst) != 4); 430 BUILD_BUG_ON(offsetof(struct batadv_icmp_packet_rr, dst) != 4);
431 431
432 /* broadcast packet */ 432 /* broadcast packet */
433 batadv_rx_handler[BATADV_BCAST] = batadv_recv_bcast_packet; 433 batadv_rx_handler[BATADV_BCAST] = batadv_recv_bcast_packet;
diff --git a/net/batman-adv/packet.h b/net/batman-adv/packet.h
index 175ce7d721d6..2a857ed006fd 100644
--- a/net/batman-adv/packet.h
+++ b/net/batman-adv/packet.h
@@ -191,7 +191,7 @@ struct batadv_ogm_packet {
191#define BATADV_OGM_HLEN sizeof(struct batadv_ogm_packet) 191#define BATADV_OGM_HLEN sizeof(struct batadv_ogm_packet)
192 192
193/** 193/**
194 * batadv_icmp_header - common ICMP header 194 * batadv_icmp_header - common members among all the ICMP packets
195 * @packet_type: batman-adv packet type, part of the general header 195 * @packet_type: batman-adv packet type, part of the general header
196 * @version: batman-adv protocol version, part of the genereal 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 197 * @ttl: time to live for this packet, part of the genereal header
@@ -199,6 +199,11 @@ struct batadv_ogm_packet {
199 * @dst: address of the destination node 199 * @dst: address of the destination node
200 * @orig: address of the source node 200 * @orig: address of the source node
201 * @uid: local ICMP socket identifier 201 * @uid: local ICMP socket identifier
202 * @align: not used - useful for alignment purposes only
203 *
204 * This structure is used for ICMP packets parsing only and it is never sent
205 * over the wire. The alignment field at the end is there to ensure that
206 * members are padded the same way as they are in real packets.
202 */ 207 */
203struct batadv_icmp_header { 208struct batadv_icmp_header {
204 uint8_t packet_type; 209 uint8_t packet_type;
@@ -208,16 +213,29 @@ struct batadv_icmp_header {
208 uint8_t dst[ETH_ALEN]; 213 uint8_t dst[ETH_ALEN];
209 uint8_t orig[ETH_ALEN]; 214 uint8_t orig[ETH_ALEN];
210 uint8_t uid; 215 uint8_t uid;
216 uint8_t align[3];
211}; 217};
212 218
213/** 219/**
214 * batadv_icmp_packet - ICMP packet 220 * batadv_icmp_packet - ICMP packet
215 * @icmph: common ICMP header 221 * @packet_type: batman-adv packet type, part of the general header
222 * @version: batman-adv protocol version, part of the genereal header
223 * @ttl: time to live for this packet, part of the genereal header
224 * @msg_type: ICMP packet type
225 * @dst: address of the destination node
226 * @orig: address of the source node
227 * @uid: local ICMP socket identifier
216 * @reserved: not used - useful for alignment 228 * @reserved: not used - useful for alignment
217 * @seqno: ICMP sequence number 229 * @seqno: ICMP sequence number
218 */ 230 */
219struct batadv_icmp_packet { 231struct batadv_icmp_packet {
220 struct batadv_icmp_header icmph; 232 uint8_t packet_type;
233 uint8_t version;
234 uint8_t ttl;
235 uint8_t msg_type; /* see ICMP message types above */
236 uint8_t dst[ETH_ALEN];
237 uint8_t orig[ETH_ALEN];
238 uint8_t uid;
221 uint8_t reserved; 239 uint8_t reserved;
222 __be16 seqno; 240 __be16 seqno;
223}; 241};
@@ -226,13 +244,25 @@ struct batadv_icmp_packet {
226 244
227/** 245/**
228 * batadv_icmp_packet_rr - ICMP RouteRecord packet 246 * batadv_icmp_packet_rr - ICMP RouteRecord packet
229 * @icmph: common ICMP header 247 * @packet_type: batman-adv packet type, part of the general header
248 * @version: batman-adv protocol version, part of the genereal header
249 * @ttl: time to live for this packet, part of the genereal header
250 * @msg_type: ICMP packet type
251 * @dst: address of the destination node
252 * @orig: address of the source node
253 * @uid: local ICMP socket identifier
230 * @rr_cur: number of entries the rr array 254 * @rr_cur: number of entries the rr array
231 * @seqno: ICMP sequence number 255 * @seqno: ICMP sequence number
232 * @rr: route record array 256 * @rr: route record array
233 */ 257 */
234struct batadv_icmp_packet_rr { 258struct batadv_icmp_packet_rr {
235 struct batadv_icmp_header icmph; 259 uint8_t packet_type;
260 uint8_t version;
261 uint8_t ttl;
262 uint8_t msg_type; /* see ICMP message types above */
263 uint8_t dst[ETH_ALEN];
264 uint8_t orig[ETH_ALEN];
265 uint8_t uid;
236 uint8_t rr_cur; 266 uint8_t rr_cur;
237 __be16 seqno; 267 __be16 seqno;
238 uint8_t rr[BATADV_RR_LEN][ETH_ALEN]; 268 uint8_t rr[BATADV_RR_LEN][ETH_ALEN];
diff --git a/net/batman-adv/routing.c b/net/batman-adv/routing.c
index 5b52d718a6eb..46278bfb8fdb 100644
--- a/net/batman-adv/routing.c
+++ b/net/batman-adv/routing.c
@@ -338,9 +338,9 @@ static int batadv_recv_icmp_ttl_exceeded(struct batadv_priv *bat_priv,
338 icmp_packet = (struct batadv_icmp_packet *)skb->data; 338 icmp_packet = (struct batadv_icmp_packet *)skb->data;
339 339
340 /* send TTL exceeded if packet is an echo request (traceroute) */ 340 /* send TTL exceeded if packet is an echo request (traceroute) */
341 if (icmp_packet->icmph.msg_type != BATADV_ECHO_REQUEST) { 341 if (icmp_packet->msg_type != BATADV_ECHO_REQUEST) {
342 pr_debug("Warning - can't forward icmp packet from %pM to %pM: ttl exceeded\n", 342 pr_debug("Warning - can't forward icmp packet from %pM to %pM: ttl exceeded\n",
343 icmp_packet->icmph.orig, icmp_packet->icmph.dst); 343 icmp_packet->orig, icmp_packet->dst);
344 goto out; 344 goto out;
345 } 345 }
346 346
@@ -349,7 +349,7 @@ static int batadv_recv_icmp_ttl_exceeded(struct batadv_priv *bat_priv,
349 goto out; 349 goto out;
350 350
351 /* get routing information */ 351 /* get routing information */
352 orig_node = batadv_orig_hash_find(bat_priv, icmp_packet->icmph.orig); 352 orig_node = batadv_orig_hash_find(bat_priv, icmp_packet->orig);
353 if (!orig_node) 353 if (!orig_node)
354 goto out; 354 goto out;
355 355
@@ -359,11 +359,11 @@ static int batadv_recv_icmp_ttl_exceeded(struct batadv_priv *bat_priv,
359 359
360 icmp_packet = (struct batadv_icmp_packet *)skb->data; 360 icmp_packet = (struct batadv_icmp_packet *)skb->data;
361 361
362 memcpy(icmp_packet->icmph.dst, icmp_packet->icmph.orig, ETH_ALEN); 362 memcpy(icmp_packet->dst, icmp_packet->orig, ETH_ALEN);
363 memcpy(icmp_packet->icmph.orig, primary_if->net_dev->dev_addr, 363 memcpy(icmp_packet->orig, primary_if->net_dev->dev_addr,
364 ETH_ALEN); 364 ETH_ALEN);
365 icmp_packet->icmph.msg_type = BATADV_TTL_EXCEEDED; 365 icmp_packet->msg_type = BATADV_TTL_EXCEEDED;
366 icmp_packet->icmph.ttl = BATADV_TTL; 366 icmp_packet->ttl = BATADV_TTL;
367 367
368 if (batadv_send_skb_to_orig(skb, orig_node, NULL) != NET_XMIT_DROP) 368 if (batadv_send_skb_to_orig(skb, orig_node, NULL) != NET_XMIT_DROP)
369 ret = NET_RX_SUCCESS; 369 ret = NET_RX_SUCCESS;