9eb1324d264a303dcabb9b4d0aa4025eb23c2adf
[openwrt/openwrt.git] / target / linux / ar71xx / patches-3.8 / 902-unaligned_access_hacks.patch
1 --- a/arch/mips/include/asm/checksum.h
2 +++ b/arch/mips/include/asm/checksum.h
3 @@ -104,26 +104,30 @@ static inline __sum16 ip_fast_csum(const
4 const unsigned int *stop = word + ihl;
5 unsigned int csum;
6 int carry;
7 + unsigned int w;
8
9 - csum = word[0];
10 - csum += word[1];
11 - carry = (csum < word[1]);
12 + csum = net_hdr_word(word++);
13 +
14 + w = net_hdr_word(word++);
15 + csum += w;
16 + carry = (csum < w);
17 csum += carry;
18
19 - csum += word[2];
20 - carry = (csum < word[2]);
21 + w = net_hdr_word(word++);
22 + csum += w;
23 + carry = (csum < w);
24 csum += carry;
25
26 - csum += word[3];
27 - carry = (csum < word[3]);
28 + w = net_hdr_word(word++);
29 + csum += w;
30 + carry = (csum < w);
31 csum += carry;
32
33 - word += 4;
34 do {
35 - csum += *word;
36 - carry = (csum < *word);
37 + w = net_hdr_word(word++);
38 + csum += w;
39 + carry = (csum < w);
40 csum += carry;
41 - word++;
42 } while (word != stop);
43
44 return csum_fold(csum);
45 @@ -192,69 +196,4 @@ static inline __sum16 ip_compute_csum(co
46 return csum_fold(csum_partial(buff, len, 0));
47 }
48
49 -#define _HAVE_ARCH_IPV6_CSUM
50 -static __inline__ __sum16 csum_ipv6_magic(const struct in6_addr *saddr,
51 - const struct in6_addr *daddr,
52 - __u32 len, unsigned short proto,
53 - __wsum sum)
54 -{
55 - __asm__(
56 - " .set push # csum_ipv6_magic\n"
57 - " .set noreorder \n"
58 - " .set noat \n"
59 - " addu %0, %5 # proto (long in network byte order)\n"
60 - " sltu $1, %0, %5 \n"
61 - " addu %0, $1 \n"
62 -
63 - " addu %0, %6 # csum\n"
64 - " sltu $1, %0, %6 \n"
65 - " lw %1, 0(%2) # four words source address\n"
66 - " addu %0, $1 \n"
67 - " addu %0, %1 \n"
68 - " sltu $1, %0, %1 \n"
69 -
70 - " lw %1, 4(%2) \n"
71 - " addu %0, $1 \n"
72 - " addu %0, %1 \n"
73 - " sltu $1, %0, %1 \n"
74 -
75 - " lw %1, 8(%2) \n"
76 - " addu %0, $1 \n"
77 - " addu %0, %1 \n"
78 - " sltu $1, %0, %1 \n"
79 -
80 - " lw %1, 12(%2) \n"
81 - " addu %0, $1 \n"
82 - " addu %0, %1 \n"
83 - " sltu $1, %0, %1 \n"
84 -
85 - " lw %1, 0(%3) \n"
86 - " addu %0, $1 \n"
87 - " addu %0, %1 \n"
88 - " sltu $1, %0, %1 \n"
89 -
90 - " lw %1, 4(%3) \n"
91 - " addu %0, $1 \n"
92 - " addu %0, %1 \n"
93 - " sltu $1, %0, %1 \n"
94 -
95 - " lw %1, 8(%3) \n"
96 - " addu %0, $1 \n"
97 - " addu %0, %1 \n"
98 - " sltu $1, %0, %1 \n"
99 -
100 - " lw %1, 12(%3) \n"
101 - " addu %0, $1 \n"
102 - " addu %0, %1 \n"
103 - " sltu $1, %0, %1 \n"
104 -
105 - " addu %0, $1 # Add final carry\n"
106 - " .set pop"
107 - : "=r" (sum), "=r" (proto)
108 - : "r" (saddr), "r" (daddr),
109 - "0" (htonl(len)), "1" (htonl(proto)), "r" (sum));
110 -
111 - return csum_fold(sum);
112 -}
113 -
114 #endif /* _ASM_CHECKSUM_H */
115 --- a/include/uapi/linux/ip.h
116 +++ b/include/uapi/linux/ip.h
117 @@ -102,7 +102,7 @@ struct iphdr {
118 __be32 saddr;
119 __be32 daddr;
120 /*The options start here. */
121 -};
122 +} __attribute__((packed, aligned(2)));
123
124
125 struct ip_auth_hdr {
126 --- a/include/uapi/linux/ipv6.h
127 +++ b/include/uapi/linux/ipv6.h
128 @@ -123,7 +123,7 @@ struct ipv6hdr {
129
130 struct in6_addr saddr;
131 struct in6_addr daddr;
132 -};
133 +} __attribute__((packed, aligned(2)));
134
135
136 /* index values for the variables in ipv6_devconf */
137 --- a/include/uapi/linux/tcp.h
138 +++ b/include/uapi/linux/tcp.h
139 @@ -54,7 +54,7 @@ struct tcphdr {
140 __be16 window;
141 __sum16 check;
142 __be16 urg_ptr;
143 -};
144 +} __attribute__((packed, aligned(2)));
145
146 /*
147 * The union cast uses a gcc extension to avoid aliasing problems
148 @@ -64,7 +64,7 @@ struct tcphdr {
149 union tcp_word_hdr {
150 struct tcphdr hdr;
151 __be32 words[5];
152 -};
153 +} __attribute__((packed, aligned(2)));
154
155 #define tcp_flag_word(tp) ( ((union tcp_word_hdr *)(tp))->words [3])
156
157 --- a/include/uapi/linux/udp.h
158 +++ b/include/uapi/linux/udp.h
159 @@ -24,7 +24,7 @@ struct udphdr {
160 __be16 dest;
161 __be16 len;
162 __sum16 check;
163 -};
164 +} __attribute__((packed, aligned(2)));
165
166 /* UDP socket options */
167 #define UDP_CORK 1 /* Never send partially complete segments */
168 --- a/net/ipv4/netfilter/nf_conntrack_l3proto_ipv4.c
169 +++ b/net/ipv4/netfilter/nf_conntrack_l3proto_ipv4.c
170 @@ -39,8 +39,8 @@ static bool ipv4_pkt_to_tuple(const stru
171 if (ap == NULL)
172 return false;
173
174 - tuple->src.u3.ip = ap[0];
175 - tuple->dst.u3.ip = ap[1];
176 + tuple->src.u3.ip = net_hdr_word(ap++);
177 + tuple->dst.u3.ip = net_hdr_word(ap);
178
179 return true;
180 }
181 --- a/include/uapi/linux/icmp.h
182 +++ b/include/uapi/linux/icmp.h
183 @@ -80,7 +80,7 @@ struct icmphdr {
184 __be16 mtu;
185 } frag;
186 } un;
187 -};
188 +} __attribute__((packed, aligned(2)));
189
190
191 /*
192 --- a/net/ipv4/tcp_input.c
193 +++ b/net/ipv4/tcp_input.c
194 @@ -3896,13 +3896,14 @@ static bool tcp_parse_aligned_timestamp(
195 {
196 const __be32 *ptr = (const __be32 *)(th + 1);
197
198 - if (*ptr == htonl((TCPOPT_NOP << 24) | (TCPOPT_NOP << 16)
199 - | (TCPOPT_TIMESTAMP << 8) | TCPOLEN_TIMESTAMP)) {
200 + if (net_hdr_word(ptr) ==
201 + htonl((TCPOPT_NOP << 24) | (TCPOPT_NOP << 16) |
202 + (TCPOPT_TIMESTAMP << 8) | TCPOLEN_TIMESTAMP)) {
203 tp->rx_opt.saw_tstamp = 1;
204 ++ptr;
205 - tp->rx_opt.rcv_tsval = ntohl(*ptr);
206 + tp->rx_opt.rcv_tsval = get_unaligned_be32(ptr);
207 ++ptr;
208 - tp->rx_opt.rcv_tsecr = ntohl(*ptr);
209 + tp->rx_opt.rcv_tsecr = get_unaligned_be32(ptr);
210 return true;
211 }
212 return false;
213 --- a/include/uapi/linux/in6.h
214 +++ b/include/uapi/linux/in6.h
215 @@ -36,7 +36,7 @@ struct in6_addr {
216 #define s6_addr in6_u.u6_addr8
217 #define s6_addr16 in6_u.u6_addr16
218 #define s6_addr32 in6_u.u6_addr32
219 -};
220 +} __attribute__((packed, aligned(2)));
221
222 /* IPv6 Wildcard Address (::) and Loopback Address (::1) defined in RFC2553
223 * NOTE: Be aware the IN6ADDR_* constants and in6addr_* externals are defined
224 --- a/net/ipv6/af_inet6.c
225 +++ b/net/ipv6/af_inet6.c
226 @@ -61,6 +61,7 @@
227 #endif
228
229 #include <asm/uaccess.h>
230 +#include <asm/unaligned.h>
231 #include <linux/mroute6.h>
232
233 MODULE_AUTHOR("Cast of dozens");
234 @@ -688,7 +689,7 @@ bool ipv6_opt_accepted(const struct sock
235 if ((opt->hop && (np->rxopt.bits.hopopts ||
236 np->rxopt.bits.ohopopts)) ||
237 ((IPV6_FLOWINFO_MASK &
238 - *(__be32 *)skb_network_header(skb)) &&
239 + net_hdr_word(skb_network_header(skb))) &&
240 np->rxopt.bits.rxflow) ||
241 (opt->srcrt && (np->rxopt.bits.srcrt ||
242 np->rxopt.bits.osrcrt)) ||
243 --- a/net/ipv6/route.c
244 +++ b/net/ipv6/route.c
245 @@ -995,7 +995,7 @@ void ip6_route_input(struct sk_buff *skb
246 .flowi6_iif = skb->dev->ifindex,
247 .daddr = iph->daddr,
248 .saddr = iph->saddr,
249 - .flowlabel = (* (__be32 *) iph) & IPV6_FLOWINFO_MASK,
250 + .flowlabel = net_hdr_word(iph) & IPV6_FLOWINFO_MASK,
251 .flowi6_mark = skb->mark,
252 .flowi6_proto = iph->nexthdr,
253 };
254 @@ -1159,7 +1159,7 @@ void ip6_update_pmtu(struct sk_buff *skb
255 fl6.flowi6_flags = 0;
256 fl6.daddr = iph->daddr;
257 fl6.saddr = iph->saddr;
258 - fl6.flowlabel = (*(__be32 *) iph) & IPV6_FLOWINFO_MASK;
259 + fl6.flowlabel = net_hdr_word(iph) & IPV6_FLOWINFO_MASK,
260
261 dst = ip6_route_output(net, NULL, &fl6);
262 if (!dst->error)
263 @@ -1187,7 +1187,7 @@ void ip6_redirect(struct sk_buff *skb, s
264 fl6.flowi6_flags = 0;
265 fl6.daddr = iph->daddr;
266 fl6.saddr = iph->saddr;
267 - fl6.flowlabel = (*(__be32 *) iph) & IPV6_FLOWINFO_MASK;
268 + fl6.flowlabel = net_hdr_word(iph) & IPV6_FLOWINFO_MASK,
269
270 dst = ip6_route_output(net, NULL, &fl6);
271 if (!dst->error)
272 --- a/net/ipv6/tcp_ipv6.c
273 +++ b/net/ipv6/tcp_ipv6.c
274 @@ -64,6 +64,7 @@
275 #include <net/secure_seq.h>
276 #include <net/tcp_memcontrol.h>
277
278 +#include <asm/unaligned.h>
279 #include <asm/uaccess.h>
280
281 #include <linux/proc_fs.h>
282 @@ -764,10 +765,10 @@ static void tcp_v6_send_response(struct
283 topt = (__be32 *)(t1 + 1);
284
285 if (ts) {
286 - *topt++ = htonl((TCPOPT_NOP << 24) | (TCPOPT_NOP << 16) |
287 - (TCPOPT_TIMESTAMP << 8) | TCPOLEN_TIMESTAMP);
288 - *topt++ = htonl(tcp_time_stamp);
289 - *topt++ = htonl(ts);
290 + put_unaligned_be32((TCPOPT_NOP << 24) | (TCPOPT_NOP << 16) |
291 + (TCPOPT_TIMESTAMP << 8) | TCPOLEN_TIMESTAMP, topt++);
292 + put_unaligned_be32(tcp_time_stamp, topt++);
293 + put_unaligned_be32(ts, topt++);
294 }
295
296 #ifdef CONFIG_TCP_MD5SIG
297 --- a/include/linux/ipv6.h
298 +++ b/include/linux/ipv6.h
299 @@ -4,6 +4,7 @@
300 #include <uapi/linux/ipv6.h>
301
302 #define ipv6_optlen(p) (((p)->hdrlen+1) << 3)
303 +
304 /*
305 * This structure contains configuration options per IPv6 link.
306 */
307 @@ -79,7 +80,7 @@ static inline struct ipv6hdr *ipipv6_hdr
308
309 static inline __u8 ipv6_tclass(const struct ipv6hdr *iph)
310 {
311 - return (ntohl(*(__be32 *)iph) >> 20) & 0xff;
312 + return (ntohl(net_hdr_word(iph)) >> 20) & 0xff;
313 }
314
315 /*
316 --- a/net/ipv6/datagram.c
317 +++ b/net/ipv6/datagram.c
318 @@ -360,12 +360,12 @@ int ipv6_recv_error(struct sock *sk, str
319 *(struct in6_addr *)(nh + serr->addr_offset);
320 if (np->sndflow)
321 sin->sin6_flowinfo =
322 - (*(__be32 *)(nh + serr->addr_offset - 24) &
323 - IPV6_FLOWINFO_MASK);
324 + net_hdr_word(nh + serr->addr_offset - 24) &
325 + IPV6_FLOWINFO_MASK;
326 if (ipv6_addr_type(&sin->sin6_addr) & IPV6_ADDR_LINKLOCAL)
327 sin->sin6_scope_id = IP6CB(skb)->iif;
328 } else {
329 - ipv6_addr_set_v4mapped(*(__be32 *)(nh + serr->addr_offset),
330 + ipv6_addr_set_v4mapped(net_hdr_word(nh + serr->addr_offset),
331 &sin->sin6_addr);
332 }
333 }
334 @@ -493,9 +493,10 @@ int ip6_datagram_recv_ctl(struct sock *s
335 put_cmsg(msg, SOL_IPV6, IPV6_TCLASS, sizeof(tclass), &tclass);
336 }
337
338 - if (np->rxopt.bits.rxflow && (*(__be32 *)nh & IPV6_FLOWINFO_MASK)) {
339 - __be32 flowinfo = *(__be32 *)nh & IPV6_FLOWINFO_MASK;
340 - put_cmsg(msg, SOL_IPV6, IPV6_FLOWINFO, sizeof(flowinfo), &flowinfo);
341 + if (np->rxopt.bits.rxflow) {
342 + __be32 flowinfo = net_hdr_word(nh) & IPV6_FLOWINFO_MASK;
343 + if (flowinfo)
344 + put_cmsg(msg, SOL_IPV6, IPV6_FLOWINFO, sizeof(flowinfo), &flowinfo);
345 }
346
347 /* HbH is allowed only once */
348 @@ -682,12 +683,12 @@ int ip6_datagram_send_ctl(struct net *ne
349 }
350
351 if (fl6->flowlabel&IPV6_FLOWINFO_MASK) {
352 - if ((fl6->flowlabel^*(__be32 *)CMSG_DATA(cmsg))&~IPV6_FLOWINFO_MASK) {
353 + if ((fl6->flowlabel^net_hdr_word(CMSG_DATA(cmsg)))&~IPV6_FLOWINFO_MASK) {
354 err = -EINVAL;
355 goto exit_f;
356 }
357 }
358 - fl6->flowlabel = IPV6_FLOWINFO_MASK & *(__be32 *)CMSG_DATA(cmsg);
359 + fl6->flowlabel = IPV6_FLOWINFO_MASK & net_hdr_word(CMSG_DATA(cmsg));
360 break;
361
362 case IPV6_2292HOPOPTS:
363 --- a/net/ipv6/ip6_gre.c
364 +++ b/net/ipv6/ip6_gre.c
365 @@ -430,7 +430,7 @@ static void ip6gre_err(struct sk_buff *s
366
367 t = ip6gre_tunnel_lookup(skb->dev, &ipv6h->daddr, &ipv6h->saddr,
368 flags & GRE_KEY ?
369 - *(((__be32 *)p) + (grehlen / 4) - 1) : 0,
370 + net_hdr_word(((__be32 *)p) + (grehlen / 4) - 1) : 0,
371 p[1]);
372 if (t == NULL)
373 return;
374 @@ -522,11 +522,11 @@ static int ip6gre_rcv(struct sk_buff *sk
375 offset += 4;
376 }
377 if (flags&GRE_KEY) {
378 - key = *(__be32 *)(h + offset);
379 + key = net_hdr_word(h + offset);
380 offset += 4;
381 }
382 if (flags&GRE_SEQ) {
383 - seqno = ntohl(*(__be32 *)(h + offset));
384 + seqno = ntohl(net_hdr_word(h + offset));
385 offset += 4;
386 }
387 }
388 @@ -772,7 +772,7 @@ static netdev_tx_t ip6gre_xmit2(struct s
389 * Push down and install the IP header.
390 */
391 ipv6h = ipv6_hdr(skb);
392 - *(__be32 *)ipv6h = fl6->flowlabel | htonl(0x60000000);
393 + net_hdr_word(ipv6h) = fl6->flowlabel | htonl(0x60000000);
394 dsfield = INET_ECN_encapsulate(0, dsfield);
395 ipv6_change_dsfield(ipv6h, ~INET_ECN_MASK, dsfield);
396 ipv6h->hop_limit = tunnel->parms.hop_limit;
397 @@ -789,7 +789,7 @@ static netdev_tx_t ip6gre_xmit2(struct s
398
399 if (tunnel->parms.o_flags&GRE_SEQ) {
400 ++tunnel->o_seqno;
401 - *ptr = htonl(tunnel->o_seqno);
402 + net_hdr_word(ptr) = htonl(tunnel->o_seqno);
403 ptr--;
404 }
405 if (tunnel->parms.o_flags&GRE_KEY) {
406 @@ -897,9 +897,9 @@ static inline int ip6gre_xmit_ipv6(struc
407
408 dsfield = ipv6_get_dsfield(ipv6h);
409 if (t->parms.flags & IP6_TNL_F_USE_ORIG_TCLASS)
410 - fl6.flowlabel |= (*(__be32 *) ipv6h & IPV6_TCLASS_MASK);
411 + fl6.flowlabel |= net_hdr_word(ipv6h) & IPV6_TCLASS_MASK;
412 if (t->parms.flags & IP6_TNL_F_USE_ORIG_FLOWLABEL)
413 - fl6.flowlabel |= (*(__be32 *) ipv6h & IPV6_FLOWLABEL_MASK);
414 + fl6.flowlabel |= net_hdr_word(ipv6h) & IPV6_FLOWLABEL_MASK;
415 if (t->parms.flags & IP6_TNL_F_USE_ORIG_FWMARK)
416 fl6.flowi6_mark = skb->mark;
417
418 @@ -1240,7 +1240,7 @@ static int ip6gre_header(struct sk_buff
419 struct ipv6hdr *ipv6h = (struct ipv6hdr *)skb_push(skb, t->hlen);
420 __be16 *p = (__be16 *)(ipv6h+1);
421
422 - *(__be32 *)ipv6h = t->fl.u.ip6.flowlabel | htonl(0x60000000);
423 + net_hdr_word(ipv6h) = t->fl.u.ip6.flowlabel | htonl(0x60000000);
424 ipv6h->hop_limit = t->parms.hop_limit;
425 ipv6h->nexthdr = NEXTHDR_GRE;
426 ipv6h->saddr = t->parms.laddr;
427 --- a/net/ipv6/ip6_output.c
428 +++ b/net/ipv6/ip6_output.c
429 @@ -216,7 +216,7 @@ int ip6_xmit(struct sock *sk, struct sk_
430 if (hlimit < 0)
431 hlimit = ip6_dst_hoplimit(dst);
432
433 - *(__be32 *)hdr = htonl(0x60000000 | (tclass << 20)) | fl6->flowlabel;
434 + net_hdr_word(hdr) = htonl(0x60000000 | (tclass << 20)) | fl6->flowlabel;
435
436 hdr->payload_len = htons(seg_len);
437 hdr->nexthdr = proto;
438 --- a/net/ipv6/ip6_tunnel.c
439 +++ b/net/ipv6/ip6_tunnel.c
440 @@ -1136,9 +1136,9 @@ ip6ip6_tnl_xmit(struct sk_buff *skb, str
441
442 dsfield = ipv6_get_dsfield(ipv6h);
443 if (t->parms.flags & IP6_TNL_F_USE_ORIG_TCLASS)
444 - fl6.flowlabel |= (*(__be32 *) ipv6h & IPV6_TCLASS_MASK);
445 + fl6.flowlabel |= net_hdr_word(ipv6h) & IPV6_TCLASS_MASK;
446 if (t->parms.flags & IP6_TNL_F_USE_ORIG_FLOWLABEL)
447 - fl6.flowlabel |= (*(__be32 *) ipv6h & IPV6_FLOWLABEL_MASK);
448 + fl6.flowlabel |= net_hdr_word(ipv6h) & IPV6_FLOWLABEL_MASK;
449 if (t->parms.flags & IP6_TNL_F_USE_ORIG_FWMARK)
450 fl6.flowi6_mark = skb->mark;
451
452 --- a/net/ipv6/exthdrs.c
453 +++ b/net/ipv6/exthdrs.c
454 @@ -578,7 +578,7 @@ static bool ipv6_hop_jumbo(struct sk_buf
455 goto drop;
456 }
457
458 - pkt_len = ntohl(*(__be32 *)(nh + optoff + 2));
459 + pkt_len = ntohl(net_hdr_word(nh + optoff + 2));
460 if (pkt_len <= IPV6_MAXPLEN) {
461 IP6_INC_STATS_BH(net, ipv6_skb_idev(skb),
462 IPSTATS_MIB_INHDRERRORS);
463 --- a/include/linux/types.h
464 +++ b/include/linux/types.h
465 @@ -212,5 +212,11 @@ struct callback_head {
466 };
467 #define rcu_head callback_head
468
469 +struct net_hdr_word {
470 + u32 words[1];
471 +} __attribute__((packed, aligned(2)));
472 +
473 +#define net_hdr_word(_p) (((struct net_hdr_word *) (_p))->words[0])
474 +
475 #endif /* __ASSEMBLY__ */
476 #endif /* _LINUX_TYPES_H */
477 --- a/net/ipv4/af_inet.c
478 +++ b/net/ipv4/af_inet.c
479 @@ -1396,8 +1396,8 @@ static struct sk_buff **inet_gro_receive
480 if (unlikely(ip_fast_csum((u8 *)iph, 5)))
481 goto out_unlock;
482
483 - id = ntohl(*(__be32 *)&iph->id);
484 - flush = (u16)((ntohl(*(__be32 *)iph) ^ skb_gro_len(skb)) | (id ^ IP_DF));
485 + id = ntohl(net_hdr_word(&iph->id));
486 + flush = (u16)((ntohl(net_hdr_word(iph)) ^ skb_gro_len(skb)) | (id ^ IP_DF));
487 id >>= 16;
488
489 for (p = *head; p; p = p->next) {
490 --- a/net/ipv4/route.c
491 +++ b/net/ipv4/route.c
492 @@ -465,7 +465,7 @@ static struct neighbour *ipv4_neigh_look
493 else if (skb)
494 pkey = &ip_hdr(skb)->daddr;
495
496 - n = __ipv4_neigh_lookup(dev, *(__force u32 *)pkey);
497 + n = __ipv4_neigh_lookup(dev, net_hdr_word(pkey));
498 if (n)
499 return n;
500 return neigh_create(&arp_tbl, pkey, dev);
501 --- a/net/ipv4/tcp_output.c
502 +++ b/net/ipv4/tcp_output.c
503 @@ -456,15 +456,17 @@ static void tcp_options_write(__be32 *pt
504 */
505 if (unlikely(OPTION_MD5 & options)) {
506 if (unlikely(OPTION_COOKIE_EXTENSION & options)) {
507 - *ptr++ = htonl((TCPOPT_COOKIE << 24) |
508 - (TCPOLEN_COOKIE_BASE << 16) |
509 - (TCPOPT_MD5SIG << 8) |
510 - TCPOLEN_MD5SIG);
511 + net_hdr_word(ptr++) =
512 + htonl((TCPOPT_COOKIE << 24) |
513 + (TCPOLEN_COOKIE_BASE << 16) |
514 + (TCPOPT_MD5SIG << 8) |
515 + TCPOLEN_MD5SIG);
516 } else {
517 - *ptr++ = htonl((TCPOPT_NOP << 24) |
518 - (TCPOPT_NOP << 16) |
519 - (TCPOPT_MD5SIG << 8) |
520 - TCPOLEN_MD5SIG);
521 + net_hdr_word(ptr++) =
522 + htonl((TCPOPT_NOP << 24) |
523 + (TCPOPT_NOP << 16) |
524 + (TCPOPT_MD5SIG << 8) |
525 + TCPOLEN_MD5SIG);
526 }
527 options &= ~OPTION_COOKIE_EXTENSION;
528 /* overload cookie hash location */
529 @@ -473,26 +475,28 @@ static void tcp_options_write(__be32 *pt
530 }
531
532 if (unlikely(opts->mss)) {
533 - *ptr++ = htonl((TCPOPT_MSS << 24) |
534 - (TCPOLEN_MSS << 16) |
535 - opts->mss);
536 + net_hdr_word(ptr++) =
537 + htonl((TCPOPT_MSS << 24) | (TCPOLEN_MSS << 16) |
538 + opts->mss);
539 }
540
541 if (likely(OPTION_TS & options)) {
542 if (unlikely(OPTION_SACK_ADVERTISE & options)) {
543 - *ptr++ = htonl((TCPOPT_SACK_PERM << 24) |
544 - (TCPOLEN_SACK_PERM << 16) |
545 - (TCPOPT_TIMESTAMP << 8) |
546 - TCPOLEN_TIMESTAMP);
547 + net_hdr_word(ptr++) =
548 + htonl((TCPOPT_SACK_PERM << 24) |
549 + (TCPOLEN_SACK_PERM << 16) |
550 + (TCPOPT_TIMESTAMP << 8) |
551 + TCPOLEN_TIMESTAMP);
552 options &= ~OPTION_SACK_ADVERTISE;
553 } else {
554 - *ptr++ = htonl((TCPOPT_NOP << 24) |
555 - (TCPOPT_NOP << 16) |
556 - (TCPOPT_TIMESTAMP << 8) |
557 - TCPOLEN_TIMESTAMP);
558 + net_hdr_word(ptr++) =
559 + htonl((TCPOPT_NOP << 24) |
560 + (TCPOPT_NOP << 16) |
561 + (TCPOPT_TIMESTAMP << 8) |
562 + TCPOLEN_TIMESTAMP);
563 }
564 - *ptr++ = htonl(opts->tsval);
565 - *ptr++ = htonl(opts->tsecr);
566 + net_hdr_word(ptr++) = htonl(opts->tsval);
567 + net_hdr_word(ptr++) = htonl(opts->tsecr);
568 }
569
570 /* Specification requires after timestamp, so do it now.
571 @@ -512,19 +516,20 @@ static void tcp_options_write(__be32 *pt
572 __u8 *p = (__u8 *)ptr;
573
574 /* 16-bit multiple */
575 - *p++ = TCPOPT_COOKIE;
576 - *p++ = TCPOLEN_COOKIE_BASE + cookie_size;
577 - *p++ = *cookie_copy++;
578 - *p++ = *cookie_copy++;
579 + net_hdr_word(p++) = TCPOPT_COOKIE;
580 + net_hdr_word(p++) = TCPOLEN_COOKIE_BASE + cookie_size;
581 + net_hdr_word(p++) = *cookie_copy++;
582 + net_hdr_word(p++) = *cookie_copy++;
583 ptr++;
584 cookie_size -= 2;
585 } else {
586 /* 32-bit multiple */
587 - *ptr++ = htonl(((TCPOPT_NOP << 24) |
588 - (TCPOPT_NOP << 16) |
589 - (TCPOPT_COOKIE << 8) |
590 - TCPOLEN_COOKIE_BASE) +
591 - cookie_size);
592 + net_hdr_word(ptr++) =
593 + htonl(((TCPOPT_NOP << 24) |
594 + (TCPOPT_NOP << 16) |
595 + (TCPOPT_COOKIE << 8) |
596 + TCPOLEN_COOKIE_BASE) +
597 + cookie_size);
598 }
599
600 if (cookie_size > 0) {
601 @@ -534,17 +539,19 @@ static void tcp_options_write(__be32 *pt
602 }
603
604 if (unlikely(OPTION_SACK_ADVERTISE & options)) {
605 - *ptr++ = htonl((TCPOPT_NOP << 24) |
606 - (TCPOPT_NOP << 16) |
607 - (TCPOPT_SACK_PERM << 8) |
608 - TCPOLEN_SACK_PERM);
609 + net_hdr_word(ptr++) =
610 + htonl((TCPOPT_NOP << 24) |
611 + (TCPOPT_NOP << 16) |
612 + (TCPOPT_SACK_PERM << 8) |
613 + TCPOLEN_SACK_PERM);
614 }
615
616 if (unlikely(OPTION_WSCALE & options)) {
617 - *ptr++ = htonl((TCPOPT_NOP << 24) |
618 - (TCPOPT_WINDOW << 16) |
619 - (TCPOLEN_WINDOW << 8) |
620 - opts->ws);
621 + net_hdr_word(ptr++) =
622 + htonl((TCPOPT_NOP << 24) |
623 + (TCPOPT_WINDOW << 16) |
624 + (TCPOLEN_WINDOW << 8) |
625 + opts->ws);
626 }
627
628 if (unlikely(opts->num_sack_blocks)) {
629 @@ -552,16 +559,17 @@ static void tcp_options_write(__be32 *pt
630 tp->duplicate_sack : tp->selective_acks;
631 int this_sack;
632
633 - *ptr++ = htonl((TCPOPT_NOP << 24) |
634 - (TCPOPT_NOP << 16) |
635 - (TCPOPT_SACK << 8) |
636 - (TCPOLEN_SACK_BASE + (opts->num_sack_blocks *
637 + net_hdr_word(ptr++) =
638 + htonl((TCPOPT_NOP << 24) |
639 + (TCPOPT_NOP << 16) |
640 + (TCPOPT_SACK << 8) |
641 + (TCPOLEN_SACK_BASE + (opts->num_sack_blocks *
642 TCPOLEN_SACK_PERBLOCK)));
643
644 for (this_sack = 0; this_sack < opts->num_sack_blocks;
645 ++this_sack) {
646 - *ptr++ = htonl(sp[this_sack].start_seq);
647 - *ptr++ = htonl(sp[this_sack].end_seq);
648 + net_hdr_word(ptr++) = htonl(sp[this_sack].start_seq);
649 + net_hdr_word(ptr++) = htonl(sp[this_sack].end_seq);
650 }
651
652 tp->rx_opt.dsack = 0;
653 @@ -570,9 +578,10 @@ static void tcp_options_write(__be32 *pt
654 if (unlikely(OPTION_FAST_OPEN_COOKIE & options)) {
655 struct tcp_fastopen_cookie *foc = opts->fastopen_cookie;
656
657 - *ptr++ = htonl((TCPOPT_EXP << 24) |
658 - ((TCPOLEN_EXP_FASTOPEN_BASE + foc->len) << 16) |
659 - TCPOPT_FASTOPEN_MAGIC);
660 + net_hdr_word(ptr++) =
661 + htonl((TCPOPT_EXP << 24) |
662 + ((TCPOLEN_EXP_FASTOPEN_BASE + foc->len) << 16) |
663 + TCPOPT_FASTOPEN_MAGIC);
664
665 memcpy(ptr, foc->val, foc->len);
666 if ((foc->len & 3) == 2) {
667 --- a/net/ipv4/igmp.c
668 +++ b/net/ipv4/igmp.c
669 @@ -470,7 +470,7 @@ static struct sk_buff *add_grec(struct s
670 if (!skb)
671 return NULL;
672 psrc = (__be32 *)skb_put(skb, sizeof(__be32));
673 - *psrc = psf->sf_inaddr;
674 + net_hdr_word(psrc) = psf->sf_inaddr;
675 scount++; stotal++;
676 if ((type == IGMPV3_ALLOW_NEW_SOURCES ||
677 type == IGMPV3_BLOCK_OLD_SOURCES) && psf->sf_crcount) {
678 --- a/net/ipv4/ip_gre.c
679 +++ b/net/ipv4/ip_gre.c
680 @@ -518,7 +518,7 @@ static void ipgre_err(struct sk_buff *sk
681 return;
682
683 if (flags & GRE_KEY)
684 - key = *(((__be32 *)p) + (grehlen / 4) - 1);
685 + key = net_hdr_word(((__be32 *)p) + (grehlen / 4) - 1);
686
687 switch (type) {
688 default:
689 --- a/include/uapi/linux/igmp.h
690 +++ b/include/uapi/linux/igmp.h
691 @@ -32,7 +32,7 @@ struct igmphdr {
692 __u8 code; /* For newer IGMP */
693 __sum16 csum;
694 __be32 group;
695 -};
696 +} __attribute__((packed, aligned(2)));
697
698 /* V3 group record types [grec_type] */
699 #define IGMPV3_MODE_IS_INCLUDE 1
700 @@ -48,7 +48,7 @@ struct igmpv3_grec {
701 __be16 grec_nsrcs;
702 __be32 grec_mca;
703 __be32 grec_src[0];
704 -};
705 +} __attribute__((packed, aligned(2)));
706
707 struct igmpv3_report {
708 __u8 type;
709 @@ -57,7 +57,7 @@ struct igmpv3_report {
710 __be16 resv2;
711 __be16 ngrec;
712 struct igmpv3_grec grec[0];
713 -};
714 +} __attribute__((packed, aligned(2)));
715
716 struct igmpv3_query {
717 __u8 type;
718 @@ -78,7 +78,7 @@ struct igmpv3_query {
719 __u8 qqic;
720 __be16 nsrcs;
721 __be32 srcs[0];
722 -};
723 +} __attribute__((packed, aligned(2)));
724
725 #define IGMP_HOST_MEMBERSHIP_QUERY 0x11 /* From RFC1112 */
726 #define IGMP_HOST_MEMBERSHIP_REPORT 0x12 /* Ditto */
727 --- a/net/core/flow_dissector.c
728 +++ b/net/core/flow_dissector.c
729 @@ -137,7 +137,7 @@ ipv6:
730 nhoff += poff;
731 ports = skb_header_pointer(skb, nhoff, sizeof(_ports), &_ports);
732 if (ports)
733 - flow->ports = *ports;
734 + flow->ports = net_hdr_word(ports);
735 }
736
737 return true;
738 --- a/include/uapi/linux/icmpv6.h
739 +++ b/include/uapi/linux/icmpv6.h
740 @@ -76,7 +76,7 @@ struct icmp6hdr {
741 #define icmp6_addrconf_other icmp6_dataun.u_nd_ra.other
742 #define icmp6_rt_lifetime icmp6_dataun.u_nd_ra.rt_lifetime
743 #define icmp6_router_pref icmp6_dataun.u_nd_ra.router_pref
744 -};
745 +} __attribute__((packed, aligned(2)));
746
747
748 #define ICMPV6_ROUTER_PREF_LOW 0x3
749 --- a/include/net/ndisc.h
750 +++ b/include/net/ndisc.h
751 @@ -76,7 +76,7 @@ struct ra_msg {
752 struct icmp6hdr icmph;
753 __be32 reachable_time;
754 __be32 retrans_timer;
755 -};
756 +} __attribute__((packed, aligned(2)));
757
758 struct rd_msg {
759 struct icmp6hdr icmph;
760 @@ -142,10 +142,10 @@ static inline u32 ndisc_hashfn(const voi
761 {
762 const u32 *p32 = pkey;
763
764 - return (((p32[0] ^ hash32_ptr(dev)) * hash_rnd[0]) +
765 - (p32[1] * hash_rnd[1]) +
766 - (p32[2] * hash_rnd[2]) +
767 - (p32[3] * hash_rnd[3]));
768 + return (((net_hdr_word(&p32[0]) ^ hash32_ptr(dev)) * hash_rnd[0]) +
769 + (net_hdr_word(&p32[1]) * hash_rnd[1]) +
770 + (net_hdr_word(&p32[2]) * hash_rnd[2]) +
771 + (net_hdr_word(&p32[3]) * hash_rnd[3]));
772 }
773
774 static inline struct neighbour *__ipv6_neigh_lookup(struct neigh_table *tbl, struct net_device *dev, const void *pkey)
775 @@ -163,8 +163,10 @@ static inline struct neighbour *__ipv6_n
776 n = rcu_dereference_bh(n->next)) {
777 u32 *n32 = (u32 *) n->primary_key;
778 if (n->dev == dev &&
779 - ((n32[0] ^ p32[0]) | (n32[1] ^ p32[1]) |
780 - (n32[2] ^ p32[2]) | (n32[3] ^ p32[3])) == 0) {
781 + ((n32[0] ^ net_hdr_word(&p32[0])) |
782 + (n32[1] ^ net_hdr_word(&p32[1])) |
783 + (n32[2] ^ net_hdr_word(&p32[2])) |
784 + (n32[3] ^ net_hdr_word(&p32[3]))) == 0) {
785 if (!atomic_inc_not_zero(&n->refcnt))
786 n = NULL;
787 break;
788 --- a/net/sched/cls_u32.c
789 +++ b/net/sched/cls_u32.c
790 @@ -142,7 +142,7 @@ next_knode:
791 data = skb_header_pointer(skb, toff, 4, &hdata);
792 if (!data)
793 goto out;
794 - if ((*data ^ key->val) & key->mask) {
795 + if ((net_hdr_word(data) ^ key->val) & key->mask) {
796 n = n->next;
797 goto next_knode;
798 }
799 @@ -193,8 +193,8 @@ check_terminal:
800 &hdata);
801 if (!data)
802 goto out;
803 - sel = ht->divisor & u32_hash_fold(*data, &n->sel,
804 - n->fshift);
805 + sel = ht->divisor & u32_hash_fold(net_hdr_word(data),
806 + &n->sel, n->fshift);
807 }
808 if (!(n->sel.flags & (TC_U32_VAROFFSET | TC_U32_OFFSET | TC_U32_EAT)))
809 goto next_ht;
810 --- a/net/ipv6/ip6_offload.c
811 +++ b/net/ipv6/ip6_offload.c
812 @@ -200,7 +200,7 @@ static struct sk_buff **ipv6_gro_receive
813 continue;
814
815 iph2 = ipv6_hdr(p);
816 - first_word = *(__be32 *)iph ^ *(__be32 *)iph2 ;
817 + first_word = net_hdr_word(iph) ^ net_hdr_word(iph2);
818
819 /* All fields must match except length and Traffic Class. */
820 if (nlen != skb_network_header_len(p) ||
821 --- a/include/net/addrconf.h
822 +++ b/include/net/addrconf.h
823 @@ -39,7 +39,7 @@ struct prefix_info {
824 __be32 reserved2;
825
826 struct in6_addr prefix;
827 -};
828 +} __attribute__((packed, aligned(2)));
829
830
831 #include <linux/netdevice.h>
832 --- a/include/net/inet_ecn.h
833 +++ b/include/net/inet_ecn.h
834 @@ -115,13 +115,13 @@ static inline int IP6_ECN_set_ce(struct
835 {
836 if (INET_ECN_is_not_ect(ipv6_get_dsfield(iph)))
837 return 0;
838 - *(__be32*)iph |= htonl(INET_ECN_CE << 20);
839 + net_hdr_word(iph) |= htonl(INET_ECN_CE << 20);
840 return 1;
841 }
842
843 static inline void IP6_ECN_clear(struct ipv6hdr *iph)
844 {
845 - *(__be32*)iph &= ~htonl(INET_ECN_MASK << 20);
846 + net_hdr_word(iph) &= ~htonl(INET_ECN_MASK << 20);
847 }
848
849 static inline void ipv6_copy_dscp(unsigned int dscp, struct ipv6hdr *inner)
850 --- a/include/net/ipv6.h
851 +++ b/include/net/ipv6.h
852 @@ -107,7 +107,7 @@ struct frag_hdr {
853 __u8 reserved;
854 __be16 frag_off;
855 __be32 identification;
856 -};
857 +} __attribute__((packed, aligned(2)));
858
859 #define IP6_MF 0x0001
860
861 @@ -386,6 +386,8 @@ static inline bool __ipv6_prefix_equal(c
862 unsigned int prefixlen)
863 {
864 unsigned int pdw, pbi;
865 + /* Used for last <32-bit fraction of prefix */
866 + u32 pbia1, pbia2;
867
868 /* check complete u32 in prefix */
869 pdw = prefixlen >> 5;
870 @@ -394,7 +396,9 @@ static inline bool __ipv6_prefix_equal(c
871
872 /* check incomplete u32 in prefix */
873 pbi = prefixlen & 0x1f;
874 - if (pbi && ((a1[pdw] ^ a2[pdw]) & htonl((0xffffffff) << (32 - pbi))))
875 + pbia1 = net_hdr_word(&a1[pdw]);
876 + pbia2 = net_hdr_word(&a2[pdw]);
877 + if (pbi && ((pbia1 ^ pbia2) & htonl((0xffffffff) << (32 - pbi))))
878 return false;
879
880 return true;
881 @@ -521,13 +525,13 @@ static inline void ipv6_addr_set_v4mappe
882 */
883 static inline int __ipv6_addr_diff(const void *token1, const void *token2, int addrlen)
884 {
885 - const __be32 *a1 = token1, *a2 = token2;
886 + const struct in6_addr *a1 = token1, *a2 = token2;
887 int i;
888
889 addrlen >>= 2;
890
891 for (i = 0; i < addrlen; i++) {
892 - __be32 xb = a1[i] ^ a2[i];
893 + __be32 xb = a1->s6_addr32[i] ^ a2->s6_addr32[i];
894 if (xb)
895 return i * 32 + 31 - __fls(ntohl(xb));
896 }
897 --- a/include/net/secure_seq.h
898 +++ b/include/net/secure_seq.h
899 @@ -2,6 +2,7 @@
900 #define _NET_SECURE_SEQ
901
902 #include <linux/types.h>
903 +#include <linux/in6.h>
904
905 extern __u32 secure_ip_id(__be32 daddr);
906 extern __u32 secure_ipv6_id(const __be32 daddr[4]);
907 --- a/include/uapi/linux/in.h
908 +++ b/include/uapi/linux/in.h
909 @@ -55,7 +55,7 @@ enum {
910 /* Internet address. */
911 struct in_addr {
912 __be32 s_addr;
913 -};
914 +} __attribute__((packed, aligned(2)));
915
916 #define IP_TOS 1
917 #define IP_TTL 2
918 --- a/net/core/secure_seq.c
919 +++ b/net/core/secure_seq.c
920 @@ -43,10 +43,11 @@ __u32 secure_tcpv6_sequence_number(const
921 u32 secret[MD5_MESSAGE_BYTES / 4];
922 u32 hash[MD5_DIGEST_WORDS];
923 u32 i;
924 + const struct in6_addr *daddr6 = (struct in6_addr *) daddr;
925
926 memcpy(hash, saddr, 16);
927 for (i = 0; i < 4; i++)
928 - secret[i] = net_secret[i] + (__force u32)daddr[i];
929 + secret[i] = net_secret[i] + (__force u32)daddr6->s6_addr32[i];
930 secret[4] = net_secret[4] +
931 (((__force u16)sport << 16) + (__force u16)dport);
932 for (i = 5; i < MD5_MESSAGE_BYTES / 4; i++)
933 @@ -64,10 +65,11 @@ u32 secure_ipv6_port_ephemeral(const __b
934 u32 secret[MD5_MESSAGE_BYTES / 4];
935 u32 hash[MD5_DIGEST_WORDS];
936 u32 i;
937 + const struct in6_addr *daddr6 = (struct in6_addr *) daddr;
938
939 memcpy(hash, saddr, 16);
940 for (i = 0; i < 4; i++)
941 - secret[i] = net_secret[i] + (__force u32) daddr[i];
942 + secret[i] = net_secret[i] + (__force u32) daddr6->s6_addr32[i];
943 secret[4] = net_secret[4] + (__force u32)dport;
944 for (i = 5; i < MD5_MESSAGE_BYTES / 4; i++)
945 secret[i] = net_secret[i];
946 @@ -165,10 +167,11 @@ u64 secure_dccpv6_sequence_number(__be32
947 u32 hash[MD5_DIGEST_WORDS];
948 u64 seq;
949 u32 i;
950 + const struct in6_addr *daddr6 = (struct in6_addr *) daddr;
951
952 memcpy(hash, saddr, 16);
953 for (i = 0; i < 4; i++)
954 - secret[i] = net_secret[i] + daddr[i];
955 + secret[i] = net_secret[i] + daddr6->s6_addr32[i];
956 secret[4] = net_secret[4] +
957 (((__force u16)sport << 16) + (__force u16)dport);
958 for (i = 5; i < MD5_MESSAGE_BYTES / 4; i++)
959 --- a/net/ipv6/ip6_fib.c
960 +++ b/net/ipv6/ip6_fib.c
961 @@ -144,7 +144,7 @@ static __inline__ __be32 addr_bit_set(co
962 * See include/asm-generic/bitops/le.h.
963 */
964 return (__force __be32)(1 << ((~fn_bit ^ BITOP_BE32_SWIZZLE) & 0x1f)) &
965 - addr[fn_bit >> 5];
966 + net_hdr_word(&addr[fn_bit >> 5]);
967 }
968
969 static __inline__ struct fib6_node * node_alloc(void)
970 --- a/net/netfilter/nf_conntrack_proto_tcp.c
971 +++ b/net/netfilter/nf_conntrack_proto_tcp.c
972 @@ -452,7 +452,7 @@ static void tcp_sack(const struct sk_buf
973
974 /* Fast path for timestamp-only option */
975 if (length == TCPOLEN_TSTAMP_ALIGNED
976 - && *(__be32 *)ptr == htonl((TCPOPT_NOP << 24)
977 + && net_hdr_word(ptr) == htonl((TCPOPT_NOP << 24)
978 | (TCPOPT_NOP << 16)
979 | (TCPOPT_TIMESTAMP << 8)
980 | TCPOLEN_TIMESTAMP))
981 --- a/net/netfilter/xt_LOG.c
982 +++ b/net/netfilter/xt_LOG.c
983 @@ -521,9 +521,9 @@ static void dump_ipv6_packet(struct sbuf
984 /* Max length: 44 "LEN=65535 TC=255 HOPLIMIT=255 FLOWLBL=FFFFF " */
985 sb_add(m, "LEN=%Zu TC=%u HOPLIMIT=%u FLOWLBL=%u ",
986 ntohs(ih->payload_len) + sizeof(struct ipv6hdr),
987 - (ntohl(*(__be32 *)ih) & 0x0ff00000) >> 20,
988 + (ntohl(net_hdr_word(ih)) & 0x0ff00000) >> 20,
989 ih->hop_limit,
990 - (ntohl(*(__be32 *)ih) & 0x000fffff));
991 + (ntohl(net_hdr_word(ih)) & 0x000fffff));
992
993 fragment = 0;
994 ptr = ip6hoff + sizeof(struct ipv6hdr);
995 --- a/net/xfrm/xfrm_input.c
996 +++ b/net/xfrm/xfrm_input.c
997 @@ -77,8 +77,8 @@ int xfrm_parse_spi(struct sk_buff *skb,
998 if (!pskb_may_pull(skb, hlen))
999 return -EINVAL;
1000
1001 - *spi = *(__be32*)(skb_transport_header(skb) + offset);
1002 - *seq = *(__be32*)(skb_transport_header(skb) + offset_seq);
1003 + *spi = net_hdr_word(skb_transport_header(skb) + offset);
1004 + *seq = net_hdr_word(skb_transport_header(skb) + offset_seq);
1005 return 0;
1006 }
1007