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