5b23b11fc6d40603f7f8b35719a6096121c26c6b
[openwrt/svn-archive/archive.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 @@ -3871,13 +3871,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 @@ -994,7 +994,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 @@ -756,10 +757,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 --- a/net/ipv6/datagram.c
308 +++ b/net/ipv6/datagram.c
309 @@ -360,12 +360,12 @@ int ipv6_recv_error(struct sock *sk, str
310 *(struct in6_addr *)(nh + serr->addr_offset);
311 if (np->sndflow)
312 sin->sin6_flowinfo =
313 - (*(__be32 *)(nh + serr->addr_offset - 24) &
314 - IPV6_FLOWINFO_MASK);
315 + net_hdr_word(nh + serr->addr_offset - 24) &
316 + IPV6_FLOWINFO_MASK;
317 if (ipv6_addr_type(&sin->sin6_addr) & IPV6_ADDR_LINKLOCAL)
318 sin->sin6_scope_id = IP6CB(skb)->iif;
319 } else {
320 - ipv6_addr_set_v4mapped(*(__be32 *)(nh + serr->addr_offset),
321 + ipv6_addr_set_v4mapped(net_hdr_word(nh + serr->addr_offset),
322 &sin->sin6_addr);
323 }
324 }
325 @@ -493,9 +493,10 @@ int ip6_datagram_recv_ctl(struct sock *s
326 put_cmsg(msg, SOL_IPV6, IPV6_TCLASS, sizeof(tclass), &tclass);
327 }
328
329 - if (np->rxopt.bits.rxflow && (*(__be32 *)nh & IPV6_FLOWINFO_MASK)) {
330 - __be32 flowinfo = *(__be32 *)nh & IPV6_FLOWINFO_MASK;
331 - put_cmsg(msg, SOL_IPV6, IPV6_FLOWINFO, sizeof(flowinfo), &flowinfo);
332 + if (np->rxopt.bits.rxflow) {
333 + __be32 flowinfo = net_hdr_word(nh) & IPV6_FLOWINFO_MASK;
334 + if (flowinfo)
335 + put_cmsg(msg, SOL_IPV6, IPV6_FLOWINFO, sizeof(flowinfo), &flowinfo);
336 }
337
338 /* HbH is allowed only once */
339 @@ -682,12 +683,12 @@ int ip6_datagram_send_ctl(struct net *ne
340 }
341
342 if (fl6->flowlabel&IPV6_FLOWINFO_MASK) {
343 - if ((fl6->flowlabel^*(__be32 *)CMSG_DATA(cmsg))&~IPV6_FLOWINFO_MASK) {
344 + if ((fl6->flowlabel^net_hdr_word(CMSG_DATA(cmsg)))&~IPV6_FLOWINFO_MASK) {
345 err = -EINVAL;
346 goto exit_f;
347 }
348 }
349 - fl6->flowlabel = IPV6_FLOWINFO_MASK & *(__be32 *)CMSG_DATA(cmsg);
350 + fl6->flowlabel = IPV6_FLOWINFO_MASK & net_hdr_word(CMSG_DATA(cmsg));
351 break;
352
353 case IPV6_2292HOPOPTS:
354 --- a/net/ipv6/ip6_gre.c
355 +++ b/net/ipv6/ip6_gre.c
356 @@ -430,7 +430,7 @@ static void ip6gre_err(struct sk_buff *s
357
358 t = ip6gre_tunnel_lookup(skb->dev, &ipv6h->daddr, &ipv6h->saddr,
359 flags & GRE_KEY ?
360 - *(((__be32 *)p) + (grehlen / 4) - 1) : 0,
361 + net_hdr_word(((__be32 *)p) + (grehlen / 4) - 1) : 0,
362 p[1]);
363 if (t == NULL)
364 return;
365 @@ -522,11 +522,11 @@ static int ip6gre_rcv(struct sk_buff *sk
366 offset += 4;
367 }
368 if (flags&GRE_KEY) {
369 - key = *(__be32 *)(h + offset);
370 + key = net_hdr_word(h + offset);
371 offset += 4;
372 }
373 if (flags&GRE_SEQ) {
374 - seqno = ntohl(*(__be32 *)(h + offset));
375 + seqno = ntohl(net_hdr_word(h + offset));
376 offset += 4;
377 }
378 }
379 @@ -772,7 +772,7 @@ static netdev_tx_t ip6gre_xmit2(struct s
380 * Push down and install the IP header.
381 */
382 ipv6h = ipv6_hdr(skb);
383 - *(__be32 *)ipv6h = fl6->flowlabel | htonl(0x60000000);
384 + net_hdr_word(ipv6h) = fl6->flowlabel | htonl(0x60000000);
385 dsfield = INET_ECN_encapsulate(0, dsfield);
386 ipv6_change_dsfield(ipv6h, ~INET_ECN_MASK, dsfield);
387 ipv6h->hop_limit = tunnel->parms.hop_limit;
388 @@ -789,7 +789,7 @@ static netdev_tx_t ip6gre_xmit2(struct s
389
390 if (tunnel->parms.o_flags&GRE_SEQ) {
391 ++tunnel->o_seqno;
392 - *ptr = htonl(tunnel->o_seqno);
393 + net_hdr_word(ptr) = htonl(tunnel->o_seqno);
394 ptr--;
395 }
396 if (tunnel->parms.o_flags&GRE_KEY) {
397 @@ -897,9 +897,9 @@ static inline int ip6gre_xmit_ipv6(struc
398
399 dsfield = ipv6_get_dsfield(ipv6h);
400 if (t->parms.flags & IP6_TNL_F_USE_ORIG_TCLASS)
401 - fl6.flowlabel |= (*(__be32 *) ipv6h & IPV6_TCLASS_MASK);
402 + fl6.flowlabel |= net_hdr_word(ipv6h) & IPV6_TCLASS_MASK;
403 if (t->parms.flags & IP6_TNL_F_USE_ORIG_FLOWLABEL)
404 - fl6.flowlabel |= (*(__be32 *) ipv6h & IPV6_FLOWLABEL_MASK);
405 + fl6.flowlabel |= net_hdr_word(ipv6h) & IPV6_FLOWLABEL_MASK;
406 if (t->parms.flags & IP6_TNL_F_USE_ORIG_FWMARK)
407 fl6.flowi6_mark = skb->mark;
408
409 @@ -1240,7 +1240,7 @@ static int ip6gre_header(struct sk_buff
410 struct ipv6hdr *ipv6h = (struct ipv6hdr *)skb_push(skb, t->hlen);
411 __be16 *p = (__be16 *)(ipv6h+1);
412
413 - *(__be32 *)ipv6h = t->fl.u.ip6.flowlabel | htonl(0x60000000);
414 + net_hdr_word(ipv6h) = t->fl.u.ip6.flowlabel | htonl(0x60000000);
415 ipv6h->hop_limit = t->parms.hop_limit;
416 ipv6h->nexthdr = NEXTHDR_GRE;
417 ipv6h->saddr = t->parms.laddr;
418 --- a/net/ipv6/ip6_output.c
419 +++ b/net/ipv6/ip6_output.c
420 @@ -216,7 +216,7 @@ int ip6_xmit(struct sock *sk, struct sk_
421 if (hlimit < 0)
422 hlimit = ip6_dst_hoplimit(dst);
423
424 - *(__be32 *)hdr = htonl(0x60000000 | (tclass << 20)) | fl6->flowlabel;
425 + net_hdr_word(hdr) = htonl(0x60000000 | (tclass << 20)) | fl6->flowlabel;
426
427 hdr->payload_len = htons(seg_len);
428 hdr->nexthdr = proto;
429 --- a/net/ipv6/ip6_tunnel.c
430 +++ b/net/ipv6/ip6_tunnel.c
431 @@ -1136,9 +1136,9 @@ ip6ip6_tnl_xmit(struct sk_buff *skb, str
432
433 dsfield = ipv6_get_dsfield(ipv6h);
434 if (t->parms.flags & IP6_TNL_F_USE_ORIG_TCLASS)
435 - fl6.flowlabel |= (*(__be32 *) ipv6h & IPV6_TCLASS_MASK);
436 + fl6.flowlabel |= net_hdr_word(ipv6h) & IPV6_TCLASS_MASK;
437 if (t->parms.flags & IP6_TNL_F_USE_ORIG_FLOWLABEL)
438 - fl6.flowlabel |= (*(__be32 *) ipv6h & IPV6_FLOWLABEL_MASK);
439 + fl6.flowlabel |= net_hdr_word(ipv6h) & IPV6_FLOWLABEL_MASK;
440 if (t->parms.flags & IP6_TNL_F_USE_ORIG_FWMARK)
441 fl6.flowi6_mark = skb->mark;
442
443 --- a/net/ipv6/exthdrs.c
444 +++ b/net/ipv6/exthdrs.c
445 @@ -578,7 +578,7 @@ static bool ipv6_hop_jumbo(struct sk_buf
446 goto drop;
447 }
448
449 - pkt_len = ntohl(*(__be32 *)(nh + optoff + 2));
450 + pkt_len = ntohl(net_hdr_word(nh + optoff + 2));
451 if (pkt_len <= IPV6_MAXPLEN) {
452 IP6_INC_STATS_BH(net, ipv6_skb_idev(skb),
453 IPSTATS_MIB_INHDRERRORS);
454 --- a/include/linux/types.h
455 +++ b/include/linux/types.h
456 @@ -212,5 +212,11 @@ struct callback_head {
457 };
458 #define rcu_head callback_head
459
460 +struct net_hdr_word {
461 + u32 words[1];
462 +} __attribute__((packed, aligned(2)));
463 +
464 +#define net_hdr_word(_p) (((struct net_hdr_word *) (_p))->words[0])
465 +
466 #endif /* __ASSEMBLY__ */
467 #endif /* _LINUX_TYPES_H */
468 --- a/net/ipv4/af_inet.c
469 +++ b/net/ipv4/af_inet.c
470 @@ -1391,8 +1391,8 @@ static struct sk_buff **inet_gro_receive
471 if (unlikely(ip_fast_csum((u8 *)iph, 5)))
472 goto out_unlock;
473
474 - id = ntohl(*(__be32 *)&iph->id);
475 - flush = (u16)((ntohl(*(__be32 *)iph) ^ skb_gro_len(skb)) | (id ^ IP_DF));
476 + id = ntohl(net_hdr_word(&iph->id));
477 + flush = (u16)((ntohl(net_hdr_word(iph)) ^ skb_gro_len(skb)) | (id ^ IP_DF));
478 id >>= 16;
479
480 for (p = *head; p; p = p->next) {
481 --- a/net/ipv4/route.c
482 +++ b/net/ipv4/route.c
483 @@ -465,7 +465,7 @@ static struct neighbour *ipv4_neigh_look
484 else if (skb)
485 pkey = &ip_hdr(skb)->daddr;
486
487 - n = __ipv4_neigh_lookup(dev, *(__force u32 *)pkey);
488 + n = __ipv4_neigh_lookup(dev, net_hdr_word(pkey));
489 if (n)
490 return n;
491 return neigh_create(&arp_tbl, pkey, dev);
492 --- a/net/ipv4/tcp_output.c
493 +++ b/net/ipv4/tcp_output.c
494 @@ -456,15 +456,17 @@ static void tcp_options_write(__be32 *pt
495 */
496 if (unlikely(OPTION_MD5 & options)) {
497 if (unlikely(OPTION_COOKIE_EXTENSION & options)) {
498 - *ptr++ = htonl((TCPOPT_COOKIE << 24) |
499 - (TCPOLEN_COOKIE_BASE << 16) |
500 - (TCPOPT_MD5SIG << 8) |
501 - TCPOLEN_MD5SIG);
502 + net_hdr_word(ptr++) =
503 + htonl((TCPOPT_COOKIE << 24) |
504 + (TCPOLEN_COOKIE_BASE << 16) |
505 + (TCPOPT_MD5SIG << 8) |
506 + TCPOLEN_MD5SIG);
507 } else {
508 - *ptr++ = htonl((TCPOPT_NOP << 24) |
509 - (TCPOPT_NOP << 16) |
510 - (TCPOPT_MD5SIG << 8) |
511 - TCPOLEN_MD5SIG);
512 + net_hdr_word(ptr++) =
513 + htonl((TCPOPT_NOP << 24) |
514 + (TCPOPT_NOP << 16) |
515 + (TCPOPT_MD5SIG << 8) |
516 + TCPOLEN_MD5SIG);
517 }
518 options &= ~OPTION_COOKIE_EXTENSION;
519 /* overload cookie hash location */
520 @@ -473,26 +475,28 @@ static void tcp_options_write(__be32 *pt
521 }
522
523 if (unlikely(opts->mss)) {
524 - *ptr++ = htonl((TCPOPT_MSS << 24) |
525 - (TCPOLEN_MSS << 16) |
526 - opts->mss);
527 + net_hdr_word(ptr++) =
528 + htonl((TCPOPT_MSS << 24) | (TCPOLEN_MSS << 16) |
529 + opts->mss);
530 }
531
532 if (likely(OPTION_TS & options)) {
533 if (unlikely(OPTION_SACK_ADVERTISE & options)) {
534 - *ptr++ = htonl((TCPOPT_SACK_PERM << 24) |
535 - (TCPOLEN_SACK_PERM << 16) |
536 - (TCPOPT_TIMESTAMP << 8) |
537 - TCPOLEN_TIMESTAMP);
538 + net_hdr_word(ptr++) =
539 + htonl((TCPOPT_SACK_PERM << 24) |
540 + (TCPOLEN_SACK_PERM << 16) |
541 + (TCPOPT_TIMESTAMP << 8) |
542 + TCPOLEN_TIMESTAMP);
543 options &= ~OPTION_SACK_ADVERTISE;
544 } else {
545 - *ptr++ = htonl((TCPOPT_NOP << 24) |
546 - (TCPOPT_NOP << 16) |
547 - (TCPOPT_TIMESTAMP << 8) |
548 - TCPOLEN_TIMESTAMP);
549 + net_hdr_word(ptr++) =
550 + htonl((TCPOPT_NOP << 24) |
551 + (TCPOPT_NOP << 16) |
552 + (TCPOPT_TIMESTAMP << 8) |
553 + TCPOLEN_TIMESTAMP);
554 }
555 - *ptr++ = htonl(opts->tsval);
556 - *ptr++ = htonl(opts->tsecr);
557 + net_hdr_word(ptr++) = htonl(opts->tsval);
558 + net_hdr_word(ptr++) = htonl(opts->tsecr);
559 }
560
561 /* Specification requires after timestamp, so do it now.
562 @@ -512,19 +516,20 @@ static void tcp_options_write(__be32 *pt
563 __u8 *p = (__u8 *)ptr;
564
565 /* 16-bit multiple */
566 - *p++ = TCPOPT_COOKIE;
567 - *p++ = TCPOLEN_COOKIE_BASE + cookie_size;
568 - *p++ = *cookie_copy++;
569 - *p++ = *cookie_copy++;
570 + net_hdr_word(p++) = TCPOPT_COOKIE;
571 + net_hdr_word(p++) = TCPOLEN_COOKIE_BASE + cookie_size;
572 + net_hdr_word(p++) = *cookie_copy++;
573 + net_hdr_word(p++) = *cookie_copy++;
574 ptr++;
575 cookie_size -= 2;
576 } else {
577 /* 32-bit multiple */
578 - *ptr++ = htonl(((TCPOPT_NOP << 24) |
579 - (TCPOPT_NOP << 16) |
580 - (TCPOPT_COOKIE << 8) |
581 - TCPOLEN_COOKIE_BASE) +
582 - cookie_size);
583 + net_hdr_word(ptr++) =
584 + htonl(((TCPOPT_NOP << 24) |
585 + (TCPOPT_NOP << 16) |
586 + (TCPOPT_COOKIE << 8) |
587 + TCPOLEN_COOKIE_BASE) +
588 + cookie_size);
589 }
590
591 if (cookie_size > 0) {
592 @@ -534,17 +539,19 @@ static void tcp_options_write(__be32 *pt
593 }
594
595 if (unlikely(OPTION_SACK_ADVERTISE & options)) {
596 - *ptr++ = htonl((TCPOPT_NOP << 24) |
597 - (TCPOPT_NOP << 16) |
598 - (TCPOPT_SACK_PERM << 8) |
599 - TCPOLEN_SACK_PERM);
600 + net_hdr_word(ptr++) =
601 + htonl((TCPOPT_NOP << 24) |
602 + (TCPOPT_NOP << 16) |
603 + (TCPOPT_SACK_PERM << 8) |
604 + TCPOLEN_SACK_PERM);
605 }
606
607 if (unlikely(OPTION_WSCALE & options)) {
608 - *ptr++ = htonl((TCPOPT_NOP << 24) |
609 - (TCPOPT_WINDOW << 16) |
610 - (TCPOLEN_WINDOW << 8) |
611 - opts->ws);
612 + net_hdr_word(ptr++) =
613 + htonl((TCPOPT_NOP << 24) |
614 + (TCPOPT_WINDOW << 16) |
615 + (TCPOLEN_WINDOW << 8) |
616 + opts->ws);
617 }
618
619 if (unlikely(opts->num_sack_blocks)) {
620 @@ -552,16 +559,17 @@ static void tcp_options_write(__be32 *pt
621 tp->duplicate_sack : tp->selective_acks;
622 int this_sack;
623
624 - *ptr++ = htonl((TCPOPT_NOP << 24) |
625 - (TCPOPT_NOP << 16) |
626 - (TCPOPT_SACK << 8) |
627 - (TCPOLEN_SACK_BASE + (opts->num_sack_blocks *
628 + net_hdr_word(ptr++) =
629 + htonl((TCPOPT_NOP << 24) |
630 + (TCPOPT_NOP << 16) |
631 + (TCPOPT_SACK << 8) |
632 + (TCPOLEN_SACK_BASE + (opts->num_sack_blocks *
633 TCPOLEN_SACK_PERBLOCK)));
634
635 for (this_sack = 0; this_sack < opts->num_sack_blocks;
636 ++this_sack) {
637 - *ptr++ = htonl(sp[this_sack].start_seq);
638 - *ptr++ = htonl(sp[this_sack].end_seq);
639 + net_hdr_word(ptr++) = htonl(sp[this_sack].start_seq);
640 + net_hdr_word(ptr++) = htonl(sp[this_sack].end_seq);
641 }
642
643 tp->rx_opt.dsack = 0;
644 @@ -570,9 +578,10 @@ static void tcp_options_write(__be32 *pt
645 if (unlikely(OPTION_FAST_OPEN_COOKIE & options)) {
646 struct tcp_fastopen_cookie *foc = opts->fastopen_cookie;
647
648 - *ptr++ = htonl((TCPOPT_EXP << 24) |
649 - ((TCPOLEN_EXP_FASTOPEN_BASE + foc->len) << 16) |
650 - TCPOPT_FASTOPEN_MAGIC);
651 + net_hdr_word(ptr++) =
652 + htonl((TCPOPT_EXP << 24) |
653 + ((TCPOLEN_EXP_FASTOPEN_BASE + foc->len) << 16) |
654 + TCPOPT_FASTOPEN_MAGIC);
655
656 memcpy(ptr, foc->val, foc->len);
657 if ((foc->len & 3) == 2) {
658 --- a/net/ipv4/igmp.c
659 +++ b/net/ipv4/igmp.c
660 @@ -470,7 +470,7 @@ static struct sk_buff *add_grec(struct s
661 if (!skb)
662 return NULL;
663 psrc = (__be32 *)skb_put(skb, sizeof(__be32));
664 - *psrc = psf->sf_inaddr;
665 + net_hdr_word(psrc) = psf->sf_inaddr;
666 scount++; stotal++;
667 if ((type == IGMPV3_ALLOW_NEW_SOURCES ||
668 type == IGMPV3_BLOCK_OLD_SOURCES) && psf->sf_crcount) {
669 --- a/net/ipv4/ip_gre.c
670 +++ b/net/ipv4/ip_gre.c
671 @@ -518,7 +518,7 @@ static void ipgre_err(struct sk_buff *sk
672 return;
673
674 if (flags & GRE_KEY)
675 - key = *(((__be32 *)p) + (grehlen / 4) - 1);
676 + key = net_hdr_word(((__be32 *)p) + (grehlen / 4) - 1);
677
678 switch (type) {
679 default:
680 --- a/include/uapi/linux/igmp.h
681 +++ b/include/uapi/linux/igmp.h
682 @@ -32,7 +32,7 @@ struct igmphdr {
683 __u8 code; /* For newer IGMP */
684 __sum16 csum;
685 __be32 group;
686 -};
687 +} __attribute__((packed, aligned(2)));
688
689 /* V3 group record types [grec_type] */
690 #define IGMPV3_MODE_IS_INCLUDE 1
691 @@ -48,7 +48,7 @@ struct igmpv3_grec {
692 __be16 grec_nsrcs;
693 __be32 grec_mca;
694 __be32 grec_src[0];
695 -};
696 +} __attribute__((packed, aligned(2)));
697
698 struct igmpv3_report {
699 __u8 type;
700 @@ -57,7 +57,7 @@ struct igmpv3_report {
701 __be16 resv2;
702 __be16 ngrec;
703 struct igmpv3_grec grec[0];
704 -};
705 +} __attribute__((packed, aligned(2)));
706
707 struct igmpv3_query {
708 __u8 type;
709 @@ -78,7 +78,7 @@ struct igmpv3_query {
710 __u8 qqic;
711 __be16 nsrcs;
712 __be32 srcs[0];
713 -};
714 +} __attribute__((packed, aligned(2)));
715
716 #define IGMP_HOST_MEMBERSHIP_QUERY 0x11 /* From RFC1112 */
717 #define IGMP_HOST_MEMBERSHIP_REPORT 0x12 /* Ditto */
718 --- a/net/core/flow_dissector.c
719 +++ b/net/core/flow_dissector.c
720 @@ -137,7 +137,7 @@ ipv6:
721 nhoff += poff;
722 ports = skb_header_pointer(skb, nhoff, sizeof(_ports), &_ports);
723 if (ports)
724 - flow->ports = *ports;
725 + flow->ports = net_hdr_word(ports);
726 }
727
728 return true;
729 --- a/include/uapi/linux/icmpv6.h
730 +++ b/include/uapi/linux/icmpv6.h
731 @@ -76,7 +76,7 @@ struct icmp6hdr {
732 #define icmp6_addrconf_other icmp6_dataun.u_nd_ra.other
733 #define icmp6_rt_lifetime icmp6_dataun.u_nd_ra.rt_lifetime
734 #define icmp6_router_pref icmp6_dataun.u_nd_ra.router_pref
735 -};
736 +} __attribute__((packed, aligned(2)));
737
738
739 #define ICMPV6_ROUTER_PREF_LOW 0x3
740 --- a/include/net/ndisc.h
741 +++ b/include/net/ndisc.h
742 @@ -142,10 +142,10 @@ static inline u32 ndisc_hashfn(const voi
743 {
744 const u32 *p32 = pkey;
745
746 - return (((p32[0] ^ hash32_ptr(dev)) * hash_rnd[0]) +
747 - (p32[1] * hash_rnd[1]) +
748 - (p32[2] * hash_rnd[2]) +
749 - (p32[3] * hash_rnd[3]));
750 + return (((net_hdr_word(&p32[0]) ^ hash32_ptr(dev)) * hash_rnd[0]) +
751 + (net_hdr_word(&p32[1]) * hash_rnd[1]) +
752 + (net_hdr_word(&p32[2]) * hash_rnd[2]) +
753 + (net_hdr_word(&p32[3]) * hash_rnd[3]));
754 }
755
756 static inline struct neighbour *__ipv6_neigh_lookup(struct neigh_table *tbl, struct net_device *dev, const void *pkey)
757 --- a/net/sched/cls_u32.c
758 +++ b/net/sched/cls_u32.c
759 @@ -142,7 +142,7 @@ next_knode:
760 data = skb_header_pointer(skb, toff, 4, &hdata);
761 if (!data)
762 goto out;
763 - if ((*data ^ key->val) & key->mask) {
764 + if ((net_hdr_word(data) ^ key->val) & key->mask) {
765 n = n->next;
766 goto next_knode;
767 }
768 @@ -193,8 +193,8 @@ check_terminal:
769 &hdata);
770 if (!data)
771 goto out;
772 - sel = ht->divisor & u32_hash_fold(*data, &n->sel,
773 - n->fshift);
774 + sel = ht->divisor & u32_hash_fold(net_hdr_word(data),
775 + &n->sel, n->fshift);
776 }
777 if (!(n->sel.flags & (TC_U32_VAROFFSET | TC_U32_OFFSET | TC_U32_EAT)))
778 goto next_ht;
779 --- a/net/ipv6/ip6_offload.c
780 +++ b/net/ipv6/ip6_offload.c
781 @@ -200,7 +200,7 @@ static struct sk_buff **ipv6_gro_receive
782 continue;
783
784 iph2 = ipv6_hdr(p);
785 - first_word = *(__be32 *)iph ^ *(__be32 *)iph2 ;
786 + first_word = net_hdr_word(iph) ^ net_hdr_word(iph2);
787
788 /* All fields must match except length and Traffic Class. */
789 if (nlen != skb_network_header_len(p) ||