ath79: add pinmux node to ar724x.dtsi
[oweals/openwrt.git] / target / linux / ar71xx / patches-4.9 / 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 @@ -214,73 +218,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, __u8 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 @@ -81,7 +81,7 @@ struct icmphdr {
188         } frag;
189         __u8    reserved[4];
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 @@ -796,10 +797,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 @@ -471,7 +471,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 @@ -814,12 +814,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 @@ -397,7 +397,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 --- a/net/ipv6/exthdrs.c
280 +++ b/net/ipv6/exthdrs.c
281 @@ -574,7 +574,7 @@ static bool ipv6_hop_jumbo(struct sk_buf
282                 goto drop;
283         }
284  
285 -       pkt_len = ntohl(*(__be32 *)(nh + optoff + 2));
286 +       pkt_len = ntohl(net_hdr_word(nh + optoff + 2));
287         if (pkt_len <= IPV6_MAXPLEN) {
288                 __IP6_INC_STATS(net, ipv6_skb_idev(skb),
289                                 IPSTATS_MIB_INHDRERRORS);
290 --- a/include/linux/types.h
291 +++ b/include/linux/types.h
292 @@ -231,5 +231,11 @@ typedef void (*call_rcu_func_t)(struct r
293  /* clocksource cycle base type */
294  typedef u64 cycle_t;
295  
296 +struct net_hdr_word {
297 +       u32 words[1];
298 +} __attribute__((packed, aligned(2)));
299 +
300 +#define net_hdr_word(_p) (((struct net_hdr_word *) (_p))->words[0])
301 +
302  #endif /*  __ASSEMBLY__ */
303  #endif /* _LINUX_TYPES_H */
304 --- a/net/ipv4/af_inet.c
305 +++ b/net/ipv4/af_inet.c
306 @@ -1318,8 +1318,8 @@ struct sk_buff **inet_gro_receive(struct
307         if (unlikely(ip_fast_csum((u8 *)iph, 5)))
308                 goto out_unlock;
309  
310 -       id = ntohl(*(__be32 *)&iph->id);
311 -       flush = (u16)((ntohl(*(__be32 *)iph) ^ skb_gro_len(skb)) | (id & ~IP_DF));
312 +       id = ntohl(net_hdr_word(&iph->id));
313 +       flush = (u16)((ntohl(net_hdr_word(iph)) ^ skb_gro_len(skb)) | (id & ~IP_DF));
314         id >>= 16;
315  
316         for (p = *head; p; p = p->next) {
317 --- a/net/ipv4/route.c
318 +++ b/net/ipv4/route.c
319 @@ -461,7 +461,7 @@ static struct neighbour *ipv4_neigh_look
320         else if (skb)
321                 pkey = &ip_hdr(skb)->daddr;
322  
323 -       n = __ipv4_neigh_lookup(dev, *(__force u32 *)pkey);
324 +       n = __ipv4_neigh_lookup(dev, net_hdr_word(pkey));
325         if (n)
326                 return n;
327         return neigh_create(&arp_tbl, pkey, dev);
328 --- a/net/ipv4/tcp_output.c
329 +++ b/net/ipv4/tcp_output.c
330 @@ -448,48 +448,53 @@ static void tcp_options_write(__be32 *pt
331         u16 options = opts->options;    /* mungable copy */
332  
333         if (unlikely(OPTION_MD5 & options)) {
334 -               *ptr++ = htonl((TCPOPT_NOP << 24) | (TCPOPT_NOP << 16) |
335 -                              (TCPOPT_MD5SIG << 8) | TCPOLEN_MD5SIG);
336 +               net_hdr_word(ptr++) =
337 +                       htonl((TCPOPT_NOP << 24) | (TCPOPT_NOP << 16) |
338 +                             (TCPOPT_MD5SIG << 8) | TCPOLEN_MD5SIG);
339                 /* overload cookie hash location */
340                 opts->hash_location = (__u8 *)ptr;
341                 ptr += 4;
342         }
343  
344         if (unlikely(opts->mss)) {
345 -               *ptr++ = htonl((TCPOPT_MSS << 24) |
346 -                              (TCPOLEN_MSS << 16) |
347 -                              opts->mss);
348 +               net_hdr_word(ptr++) =
349 +                       htonl((TCPOPT_MSS << 24) | (TCPOLEN_MSS << 16) |
350 +                             opts->mss);
351         }
352  
353         if (likely(OPTION_TS & options)) {
354                 if (unlikely(OPTION_SACK_ADVERTISE & options)) {
355 -                       *ptr++ = htonl((TCPOPT_SACK_PERM << 24) |
356 -                                      (TCPOLEN_SACK_PERM << 16) |
357 -                                      (TCPOPT_TIMESTAMP << 8) |
358 -                                      TCPOLEN_TIMESTAMP);
359 +                       net_hdr_word(ptr++) =
360 +                               htonl((TCPOPT_SACK_PERM << 24) |
361 +                                     (TCPOLEN_SACK_PERM << 16) |
362 +                                     (TCPOPT_TIMESTAMP << 8) |
363 +                                     TCPOLEN_TIMESTAMP);
364                         options &= ~OPTION_SACK_ADVERTISE;
365                 } else {
366 -                       *ptr++ = htonl((TCPOPT_NOP << 24) |
367 -                                      (TCPOPT_NOP << 16) |
368 -                                      (TCPOPT_TIMESTAMP << 8) |
369 -                                      TCPOLEN_TIMESTAMP);
370 +                       net_hdr_word(ptr++) =
371 +                               htonl((TCPOPT_NOP << 24) |
372 +                                     (TCPOPT_NOP << 16) |
373 +                                     (TCPOPT_TIMESTAMP << 8) |
374 +                                     TCPOLEN_TIMESTAMP);
375                 }
376 -               *ptr++ = htonl(opts->tsval);
377 -               *ptr++ = htonl(opts->tsecr);
378 +               net_hdr_word(ptr++) = htonl(opts->tsval);
379 +               net_hdr_word(ptr++) = htonl(opts->tsecr);
380         }
381  
382         if (unlikely(OPTION_SACK_ADVERTISE & options)) {
383 -               *ptr++ = htonl((TCPOPT_NOP << 24) |
384 -                              (TCPOPT_NOP << 16) |
385 -                              (TCPOPT_SACK_PERM << 8) |
386 -                              TCPOLEN_SACK_PERM);
387 +               net_hdr_word(ptr++) =
388 +                       htonl((TCPOPT_NOP << 24) |
389 +                             (TCPOPT_NOP << 16) |
390 +                             (TCPOPT_SACK_PERM << 8) |
391 +                             TCPOLEN_SACK_PERM);
392         }
393  
394         if (unlikely(OPTION_WSCALE & options)) {
395 -               *ptr++ = htonl((TCPOPT_NOP << 24) |
396 -                              (TCPOPT_WINDOW << 16) |
397 -                              (TCPOLEN_WINDOW << 8) |
398 -                              opts->ws);
399 +               net_hdr_word(ptr++) =
400 +                       htonl((TCPOPT_NOP << 24) |
401 +                             (TCPOPT_WINDOW << 16) |
402 +                             (TCPOLEN_WINDOW << 8) |
403 +                             opts->ws);
404         }
405  
406         if (unlikely(opts->num_sack_blocks)) {
407 @@ -497,16 +502,17 @@ static void tcp_options_write(__be32 *pt
408                         tp->duplicate_sack : tp->selective_acks;
409                 int this_sack;
410  
411 -               *ptr++ = htonl((TCPOPT_NOP  << 24) |
412 -                              (TCPOPT_NOP  << 16) |
413 -                              (TCPOPT_SACK <<  8) |
414 -                              (TCPOLEN_SACK_BASE + (opts->num_sack_blocks *
415 +               net_hdr_word(ptr++) =
416 +                       htonl((TCPOPT_NOP << 24) |
417 +                             (TCPOPT_NOP << 16) |
418 +                             (TCPOPT_SACK << 8) |
419 +                             (TCPOLEN_SACK_BASE + (opts->num_sack_blocks *
420                                                      TCPOLEN_SACK_PERBLOCK)));
421  
422                 for (this_sack = 0; this_sack < opts->num_sack_blocks;
423                      ++this_sack) {
424 -                       *ptr++ = htonl(sp[this_sack].start_seq);
425 -                       *ptr++ = htonl(sp[this_sack].end_seq);
426 +                       net_hdr_word(ptr++) = htonl(sp[this_sack].start_seq);
427 +                       net_hdr_word(ptr++) = htonl(sp[this_sack].end_seq);
428                 }
429  
430                 tp->rx_opt.dsack = 0;
431 @@ -519,13 +525,14 @@ static void tcp_options_write(__be32 *pt
432  
433                 if (foc->exp) {
434                         len = TCPOLEN_EXP_FASTOPEN_BASE + foc->len;
435 -                       *ptr = htonl((TCPOPT_EXP << 24) | (len << 16) |
436 +                       net_hdr_word(ptr) =
437 +                               htonl((TCPOPT_EXP << 24) | (len << 16) |
438                                      TCPOPT_FASTOPEN_MAGIC);
439                         p += TCPOLEN_EXP_FASTOPEN_BASE;
440                 } else {
441                         len = TCPOLEN_FASTOPEN_BASE + foc->len;
442 -                       *p++ = TCPOPT_FASTOPEN;
443 -                       *p++ = len;
444 +                       net_hdr_word(p++) = TCPOPT_FASTOPEN;
445 +                       net_hdr_word(p++) = len;
446                 }
447  
448                 memcpy(p, foc->val, foc->len);
449 --- a/net/ipv4/igmp.c
450 +++ b/net/ipv4/igmp.c
451 @@ -537,7 +537,7 @@ static struct sk_buff *add_grec(struct s
452                 if (!skb)
453                         return NULL;
454                 psrc = (__be32 *)skb_put(skb, sizeof(__be32));
455 -               *psrc = psf->sf_inaddr;
456 +               net_hdr_word(psrc) = psf->sf_inaddr;
457                 scount++; stotal++;
458                 if ((type == IGMPV3_ALLOW_NEW_SOURCES ||
459                      type == IGMPV3_BLOCK_OLD_SOURCES) && psf->sf_crcount) {
460 --- a/include/uapi/linux/igmp.h
461 +++ b/include/uapi/linux/igmp.h
462 @@ -32,7 +32,7 @@ struct igmphdr {
463         __u8 code;              /* For newer IGMP */
464         __sum16 csum;
465         __be32 group;
466 -};
467 +} __attribute__((packed, aligned(2)));
468  
469  /* V3 group record types [grec_type] */
470  #define IGMPV3_MODE_IS_INCLUDE         1
471 @@ -48,7 +48,7 @@ struct igmpv3_grec {
472         __be16  grec_nsrcs;
473         __be32  grec_mca;
474         __be32  grec_src[0];
475 -};
476 +} __attribute__((packed, aligned(2)));
477  
478  struct igmpv3_report {
479         __u8 type;
480 @@ -57,7 +57,7 @@ struct igmpv3_report {
481         __be16 resv2;
482         __be16 ngrec;
483         struct igmpv3_grec grec[0];
484 -};
485 +} __attribute__((packed, aligned(2)));
486  
487  struct igmpv3_query {
488         __u8 type;
489 @@ -78,7 +78,7 @@ struct igmpv3_query {
490         __u8 qqic;
491         __be16 nsrcs;
492         __be32 srcs[0];
493 -};
494 +} __attribute__((packed, aligned(2)));
495  
496  #define IGMP_HOST_MEMBERSHIP_QUERY     0x11    /* From RFC1112 */
497  #define IGMP_HOST_MEMBERSHIP_REPORT    0x12    /* Ditto */
498 --- a/net/core/flow_dissector.c
499 +++ b/net/core/flow_dissector.c
500 @@ -84,7 +84,7 @@ __be32 __skb_flow_get_ports(const struct
501                 ports = __skb_header_pointer(skb, thoff + poff,
502                                              sizeof(_ports), data, hlen, &_ports);
503                 if (ports)
504 -                       return *ports;
505 +                       return (__be32)net_hdr_word(ports);
506         }
507  
508         return 0;
509 --- a/include/uapi/linux/icmpv6.h
510 +++ b/include/uapi/linux/icmpv6.h
511 @@ -76,7 +76,7 @@ struct icmp6hdr {
512  #define icmp6_addrconf_other   icmp6_dataun.u_nd_ra.other
513  #define icmp6_rt_lifetime      icmp6_dataun.u_nd_ra.rt_lifetime
514  #define icmp6_router_pref      icmp6_dataun.u_nd_ra.router_pref
515 -};
516 +} __attribute__((packed, aligned(2)));
517  
518  
519  #define ICMPV6_ROUTER_PREF_LOW         0x3
520 --- a/include/net/ndisc.h
521 +++ b/include/net/ndisc.h
522 @@ -87,7 +87,7 @@ struct ra_msg {
523          struct icmp6hdr                icmph;
524         __be32                  reachable_time;
525         __be32                  retrans_timer;
526 -};
527 +} __attribute__((packed, aligned(2)));
528  
529  struct rd_msg {
530         struct icmp6hdr icmph;
531 @@ -365,10 +365,10 @@ static inline u32 ndisc_hashfn(const voi
532  {
533         const u32 *p32 = pkey;
534  
535 -       return (((p32[0] ^ hash32_ptr(dev)) * hash_rnd[0]) +
536 -               (p32[1] * hash_rnd[1]) +
537 -               (p32[2] * hash_rnd[2]) +
538 -               (p32[3] * hash_rnd[3]));
539 +       return (((net_hdr_word(&p32[0]) ^ hash32_ptr(dev)) * hash_rnd[0]) +
540 +               (net_hdr_word(&p32[1]) * hash_rnd[1]) +
541 +               (net_hdr_word(&p32[2]) * hash_rnd[2]) +
542 +               (net_hdr_word(&p32[3]) * hash_rnd[3]));
543  }
544  
545  static inline struct neighbour *__ipv6_neigh_lookup_noref(struct net_device *dev, const void *pkey)
546 --- a/net/sched/cls_u32.c
547 +++ b/net/sched/cls_u32.c
548 @@ -159,7 +159,7 @@ next_knode:
549                         data = skb_header_pointer(skb, toff, 4, &hdata);
550                         if (!data)
551                                 goto out;
552 -                       if ((*data ^ key->val) & key->mask) {
553 +                       if ((net_hdr_word(data) ^ key->val) & key->mask) {
554                                 n = rcu_dereference_bh(n->next);
555                                 goto next_knode;
556                         }
557 @@ -212,8 +212,8 @@ check_terminal:
558                                                   &hdata);
559                         if (!data)
560                                 goto out;
561 -                       sel = ht->divisor & u32_hash_fold(*data, &n->sel,
562 -                                                         n->fshift);
563 +                       sel = ht->divisor & u32_hash_fold(net_hdr_word(data),
564 +                                                         &n->sel, n->fshift);
565                 }
566                 if (!(n->sel.flags & (TC_U32_VAROFFSET | TC_U32_OFFSET | TC_U32_EAT)))
567                         goto next_ht;
568 --- a/net/ipv6/ip6_offload.c
569 +++ b/net/ipv6/ip6_offload.c
570 @@ -220,7 +220,7 @@ static struct sk_buff **ipv6_gro_receive
571                         continue;
572  
573                 iph2 = (struct ipv6hdr *)(p->data + off);
574 -               first_word = *(__be32 *)iph ^ *(__be32 *)iph2;
575 +               first_word = net_hdr_word(iph) ^ net_hdr_word(iph2);
576  
577                 /* All fields must match except length and Traffic Class.
578                  * XXX skbs on the gro_list have all been parsed and pulled
579 --- a/include/net/addrconf.h
580 +++ b/include/net/addrconf.h
581 @@ -46,7 +46,7 @@ struct prefix_info {
582         __be32                  reserved2;
583  
584         struct in6_addr         prefix;
585 -};
586 +} __attribute__((packed, aligned(2)));
587  
588  
589  #include <linux/netdevice.h>
590 --- a/include/net/inet_ecn.h
591 +++ b/include/net/inet_ecn.h
592 @@ -124,9 +124,9 @@ static inline int IP6_ECN_set_ce(struct
593         if (INET_ECN_is_not_ect(ipv6_get_dsfield(iph)))
594                 return 0;
595  
596 -       from = *(__be32 *)iph;
597 +       from = net_hdr_word(iph);
598         to = from | htonl(INET_ECN_CE << 20);
599 -       *(__be32 *)iph = to;
600 +       net_hdr_word(iph) = to;
601         if (skb->ip_summed == CHECKSUM_COMPLETE)
602                 skb->csum = csum_add(csum_sub(skb->csum, (__force __wsum)from),
603                                      (__force __wsum)to);
604 @@ -135,7 +135,7 @@ static inline int IP6_ECN_set_ce(struct
605  
606  static inline void IP6_ECN_clear(struct ipv6hdr *iph)
607  {
608 -       *(__be32*)iph &= ~htonl(INET_ECN_MASK << 20);
609 +       net_hdr_word(iph) &= ~htonl(INET_ECN_MASK << 20);
610  }
611  
612  static inline void ipv6_copy_dscp(unsigned int dscp, struct ipv6hdr *inner)
613 --- a/include/net/ipv6.h
614 +++ b/include/net/ipv6.h
615 @@ -107,7 +107,7 @@ struct frag_hdr {
616         __u8    reserved;
617         __be16  frag_off;
618         __be32  identification;
619 -};
620 +} __attribute__((packed, aligned(2)));
621  
622  #define        IP6_MF          0x0001
623  #define        IP6_OFFSET      0xFFF8
624 @@ -450,8 +450,8 @@ static inline void __ipv6_addr_set_half(
625         }
626  #endif
627  #endif
628 -       addr[0] = wh;
629 -       addr[1] = wl;
630 +       net_hdr_word(&addr[0]) = wh;
631 +       net_hdr_word(&addr[1]) = wl;
632  }
633  
634  static inline void ipv6_addr_set(struct in6_addr *addr, 
635 @@ -510,6 +510,8 @@ static inline bool ipv6_prefix_equal(con
636         const __be32 *a1 = addr1->s6_addr32;
637         const __be32 *a2 = addr2->s6_addr32;
638         unsigned int pdw, pbi;
639 +       /* Used for last <32-bit fraction of prefix */
640 +       u32 pbia1, pbia2;
641  
642         /* check complete u32 in prefix */
643         pdw = prefixlen >> 5;
644 @@ -518,7 +520,9 @@ static inline bool ipv6_prefix_equal(con
645  
646         /* check incomplete u32 in prefix */
647         pbi = prefixlen & 0x1f;
648 -       if (pbi && ((a1[pdw] ^ a2[pdw]) & htonl((0xffffffff) << (32 - pbi))))
649 +       pbia1 = net_hdr_word(&a1[pdw]);
650 +       pbia2 = net_hdr_word(&a2[pdw]);
651 +       if (pbi && ((pbia1 ^ pbia2) & htonl((0xffffffff) << (32 - pbi))))
652                 return false;
653  
654         return true;
655 @@ -662,13 +666,13 @@ static inline void ipv6_addr_set_v4mappe
656   */
657  static inline int __ipv6_addr_diff32(const void *token1, const void *token2, int addrlen)
658  {
659 -       const __be32 *a1 = token1, *a2 = token2;
660 +       const struct in6_addr *a1 = token1, *a2 = token2;
661         int i;
662  
663         addrlen >>= 2;
664  
665         for (i = 0; i < addrlen; i++) {
666 -               __be32 xb = a1[i] ^ a2[i];
667 +               __be32 xb = a1->s6_addr32[i] ^ a2->s6_addr32[i];
668                 if (xb)
669                         return i * 32 + 31 - __fls(ntohl(xb));
670         }
671 @@ -837,17 +841,18 @@ static inline int ip6_default_np_autolab
672  static inline void ip6_flow_hdr(struct ipv6hdr *hdr, unsigned int tclass,
673                                 __be32 flowlabel)
674  {
675 -       *(__be32 *)hdr = htonl(0x60000000 | (tclass << 20)) | flowlabel;
676 +       net_hdr_word((__be32 *)hdr) =
677 +               htonl(0x60000000 | (tclass << 20)) | flowlabel;
678  }
679  
680  static inline __be32 ip6_flowinfo(const struct ipv6hdr *hdr)
681  {
682 -       return *(__be32 *)hdr & IPV6_FLOWINFO_MASK;
683 +       return net_hdr_word((__be32 *)hdr) & IPV6_FLOWINFO_MASK;
684  }
685  
686  static inline __be32 ip6_flowlabel(const struct ipv6hdr *hdr)
687  {
688 -       return *(__be32 *)hdr & IPV6_FLOWLABEL_MASK;
689 +       return net_hdr_word((__be32 *)hdr) & IPV6_FLOWLABEL_MASK;
690  }
691  
692  static inline u8 ip6_tclass(__be32 flowinfo)
693 --- a/include/net/secure_seq.h
694 +++ b/include/net/secure_seq.h
695 @@ -2,6 +2,7 @@
696  #define _NET_SECURE_SEQ
697  
698  #include <linux/types.h>
699 +#include <linux/in6.h>
700  
701  u32 secure_ipv4_port_ephemeral(__be32 saddr, __be32 daddr, __be16 dport);
702  u32 secure_ipv6_port_ephemeral(const __be32 *saddr, const __be32 *daddr,
703 --- a/include/uapi/linux/in.h
704 +++ b/include/uapi/linux/in.h
705 @@ -83,7 +83,7 @@ enum {
706  /* Internet address. */
707  struct in_addr {
708         __be32  s_addr;
709 -};
710 +} __attribute__((packed, aligned(2)));
711  #endif
712  
713  #define IP_TOS         1
714 --- a/net/core/secure_seq.c
715 +++ b/net/core/secure_seq.c
716 @@ -46,11 +46,12 @@ __u32 secure_tcpv6_sequence_number(const
717         u32 secret[MD5_MESSAGE_BYTES / 4];
718         u32 hash[MD5_DIGEST_WORDS];
719         u32 i;
720 +       const struct in6_addr *daddr6 = (struct in6_addr *) daddr;
721  
722         net_secret_init();
723         memcpy(hash, saddr, 16);
724         for (i = 0; i < 4; i++)
725 -               secret[i] = net_secret[i] + (__force u32)daddr[i];
726 +               secret[i] = net_secret[i] + (__force u32)daddr6->s6_addr32[i];
727         secret[4] = net_secret[4] +
728                 (((__force u16)sport << 16) + (__force u16)dport);
729         for (i = 5; i < MD5_MESSAGE_BYTES / 4; i++)
730 @@ -68,11 +69,12 @@ u32 secure_ipv6_port_ephemeral(const __b
731         u32 secret[MD5_MESSAGE_BYTES / 4];
732         u32 hash[MD5_DIGEST_WORDS];
733         u32 i;
734 +       const struct in6_addr *daddr6 = (struct in6_addr *) daddr;
735  
736         net_secret_init();
737         memcpy(hash, saddr, 16);
738         for (i = 0; i < 4; i++)
739 -               secret[i] = net_secret[i] + (__force u32) daddr[i];
740 +               secret[i] = net_secret[i] + (__force u32) daddr6->s6_addr32[i];
741         secret[4] = net_secret[4] + (__force u32)dport;
742         for (i = 5; i < MD5_MESSAGE_BYTES / 4; i++)
743                 secret[i] = net_secret[i];
744 @@ -146,6 +148,7 @@ EXPORT_SYMBOL(secure_dccp_sequence_numbe
745  u64 secure_dccpv6_sequence_number(__be32 *saddr, __be32 *daddr,
746                                   __be16 sport, __be16 dport)
747  {
748 +       const struct in6_addr *daddr6 = (struct in6_addr *) daddr;
749         u32 secret[MD5_MESSAGE_BYTES / 4];
750         u32 hash[MD5_DIGEST_WORDS];
751         u64 seq;
752 @@ -154,7 +157,7 @@ u64 secure_dccpv6_sequence_number(__be32
753         net_secret_init();
754         memcpy(hash, saddr, 16);
755         for (i = 0; i < 4; i++)
756 -               secret[i] = net_secret[i] + (__force u32)daddr[i];
757 +               secret[i] = net_secret[i] + (__force u32)daddr6->s6_addr32[i];
758         secret[4] = net_secret[4] +
759                 (((__force u16)sport << 16) + (__force u16)dport);
760         for (i = 5; i < MD5_MESSAGE_BYTES / 4; i++)
761 --- a/net/ipv6/ip6_fib.c
762 +++ b/net/ipv6/ip6_fib.c
763 @@ -136,7 +136,7 @@ static __be32 addr_bit_set(const void *t
764          * See include/asm-generic/bitops/le.h.
765          */
766         return (__force __be32)(1 << ((~fn_bit ^ BITOP_BE32_SWIZZLE) & 0x1f)) &
767 -              addr[fn_bit >> 5];
768 +              net_hdr_word(&addr[fn_bit >> 5]);
769  }
770  
771  static struct fib6_node *node_alloc(void)
772 --- a/net/netfilter/nf_conntrack_proto_tcp.c
773 +++ b/net/netfilter/nf_conntrack_proto_tcp.c
774 @@ -452,7 +452,7 @@ static void tcp_sack(const struct sk_buf
775  
776         /* Fast path for timestamp-only option */
777         if (length == TCPOLEN_TSTAMP_ALIGNED
778 -           && *(__be32 *)ptr == htonl((TCPOPT_NOP << 24)
779 +           && net_hdr_word(ptr) == htonl((TCPOPT_NOP << 24)
780                                        | (TCPOPT_NOP << 16)
781                                        | (TCPOPT_TIMESTAMP << 8)
782                                        | TCPOLEN_TIMESTAMP))
783 --- a/net/xfrm/xfrm_input.c
784 +++ b/net/xfrm/xfrm_input.c
785 @@ -154,8 +154,8 @@ int xfrm_parse_spi(struct sk_buff *skb,
786         if (!pskb_may_pull(skb, hlen))
787                 return -EINVAL;
788  
789 -       *spi = *(__be32 *)(skb_transport_header(skb) + offset);
790 -       *seq = *(__be32 *)(skb_transport_header(skb) + offset_seq);
791 +       *spi = net_hdr_word(skb_transport_header(skb) + offset);
792 +       *seq = net_hdr_word(skb_transport_header(skb) + offset_seq);
793         return 0;
794  }
795  
796 --- a/net/ipv4/tcp_input.c
797 +++ b/net/ipv4/tcp_input.c
798 @@ -3894,14 +3894,16 @@ static bool tcp_parse_aligned_timestamp(
799  {
800         const __be32 *ptr = (const __be32 *)(th + 1);
801  
802 -       if (*ptr == htonl((TCPOPT_NOP << 24) | (TCPOPT_NOP << 16)
803 -                         | (TCPOPT_TIMESTAMP << 8) | TCPOLEN_TIMESTAMP)) {
804 +       if (net_hdr_word(ptr) ==
805 +           htonl((TCPOPT_NOP << 24) | (TCPOPT_NOP << 16) |
806 +                 (TCPOPT_TIMESTAMP << 8) | TCPOLEN_TIMESTAMP)) {
807                 tp->rx_opt.saw_tstamp = 1;
808                 ++ptr;
809 -               tp->rx_opt.rcv_tsval = ntohl(*ptr);
810 +               tp->rx_opt.rcv_tsval = get_unaligned_be32(ptr);
811                 ++ptr;
812 -               if (*ptr)
813 -                       tp->rx_opt.rcv_tsecr = ntohl(*ptr) - tp->tsoffset;
814 +               if (net_hdr_word(ptr))
815 +                       tp->rx_opt.rcv_tsecr = get_unaligned_be32(ptr) -
816 +                                              tp->tsoffset;
817                 else
818                         tp->rx_opt.rcv_tsecr = 0;
819                 return true;
820 --- a/include/uapi/linux/if_pppox.h
821 +++ b/include/uapi/linux/if_pppox.h
822 @@ -50,6 +50,7 @@ struct pppoe_addr {
823   */
824  struct pptp_addr {
825         __u16           call_id;
826 +       __u16           pad;
827         struct in_addr  sin_addr;
828  };
829  
830 --- a/net/ipv6/netfilter/nf_log_ipv6.c
831 +++ b/net/ipv6/netfilter/nf_log_ipv6.c
832 @@ -66,9 +66,9 @@ static void dump_ipv6_packet(struct nf_l
833         /* Max length: 44 "LEN=65535 TC=255 HOPLIMIT=255 FLOWLBL=FFFFF " */
834         nf_log_buf_add(m, "LEN=%Zu TC=%u HOPLIMIT=%u FLOWLBL=%u ",
835                ntohs(ih->payload_len) + sizeof(struct ipv6hdr),
836 -              (ntohl(*(__be32 *)ih) & 0x0ff00000) >> 20,
837 +              (ntohl(net_hdr_word(ih)) & 0x0ff00000) >> 20,
838                ih->hop_limit,
839 -              (ntohl(*(__be32 *)ih) & 0x000fffff));
840 +              (ntohl(net_hdr_word(ih)) & 0x000fffff));
841  
842         fragment = 0;
843         ptr = ip6hoff + sizeof(struct ipv6hdr);
844 --- a/include/net/neighbour.h
845 +++ b/include/net/neighbour.h
846 @@ -263,8 +263,10 @@ static inline bool neigh_key_eq128(const
847         const u32 *n32 = (const u32 *)n->primary_key;
848         const u32 *p32 = pkey;
849  
850 -       return ((n32[0] ^ p32[0]) | (n32[1] ^ p32[1]) |
851 -               (n32[2] ^ p32[2]) | (n32[3] ^ p32[3])) == 0;
852 +       return ((n32[0] ^ net_hdr_word(&p32[0])) |
853 +               (n32[1] ^ net_hdr_word(&p32[1])) |
854 +               (n32[2] ^ net_hdr_word(&p32[2])) |
855 +               (n32[3] ^ net_hdr_word(&p32[3]))) == 0;
856  }
857  
858  static inline struct neighbour *___neigh_lookup_noref(
859 --- a/include/uapi/linux/netfilter_arp/arp_tables.h
860 +++ b/include/uapi/linux/netfilter_arp/arp_tables.h
861 @@ -69,7 +69,7 @@ struct arpt_arp {
862         __u8 flags;
863         /* Inverse flags */
864         __u16 invflags;
865 -};
866 +} __attribute__((aligned(4)));
867  
868  /* Values for "flag" field in struct arpt_ip (general arp structure).
869   * No flags defined yet.
870 --- a/net/core/utils.c
871 +++ b/net/core/utils.c
872 @@ -321,8 +321,14 @@ void inet_proto_csum_replace16(__sum16 *
873                                bool pseudohdr)
874  {
875         __be32 diff[] = {
876 -               ~from[0], ~from[1], ~from[2], ~from[3],
877 -               to[0], to[1], to[2], to[3],
878 +               ~net_hdr_word(&from[0]),
879 +               ~net_hdr_word(&from[1]),
880 +               ~net_hdr_word(&from[2]),
881 +               ~net_hdr_word(&from[3]),
882 +               net_hdr_word(&to[0]),
883 +               net_hdr_word(&to[1]),
884 +               net_hdr_word(&to[2]),
885 +               net_hdr_word(&to[3]),
886         };
887         if (skb->ip_summed != CHECKSUM_PARTIAL) {
888                 *sum = csum_fold(csum_partial(diff, sizeof(diff),
889 --- a/drivers/net/vxlan.c
890 +++ b/drivers/net/vxlan.c
891 @@ -1789,15 +1789,15 @@ static int vxlan_build_skb(struct sk_buf
892                 goto out_free;
893  
894         vxh = (struct vxlanhdr *) __skb_push(skb, sizeof(*vxh));
895 -       vxh->vx_flags = VXLAN_HF_VNI;
896 -       vxh->vx_vni = vxlan_vni_field(vni);
897 +       net_hdr_word(&vxh->vx_flags) = VXLAN_HF_VNI;
898 +       net_hdr_word(&vxh->vx_vni) = vxlan_vni_field(vni);
899  
900         if (type & SKB_GSO_TUNNEL_REMCSUM) {
901                 unsigned int start;
902  
903                 start = skb_checksum_start_offset(skb) - sizeof(struct vxlanhdr);
904 -               vxh->vx_vni |= vxlan_compute_rco(start, skb->csum_offset);
905 -               vxh->vx_flags |= VXLAN_HF_RCO;
906 +               net_hdr_word(&vxh->vx_vni) |= vxlan_compute_rco(start, skb->csum_offset);
907 +               net_hdr_word(&vxh->vx_flags) |= VXLAN_HF_RCO;
908  
909                 if (!skb_is_gso(skb)) {
910                         skb->ip_summed = CHECKSUM_NONE;
911 --- a/include/linux/etherdevice.h
912 +++ b/include/linux/etherdevice.h
913 @@ -435,7 +435,7 @@ static inline bool is_etherdev_addr(cons
914   * @b: Pointer to Ethernet header
915   *
916   * Compare two Ethernet headers, returns 0 if equal.
917 - * This assumes that the network header (i.e., IP header) is 4-byte
918 + * This assumes that the network header (i.e., IP header) is 2-byte
919   * aligned OR the platform can handle unaligned access.  This is the
920   * case for all packets coming into netif_receive_skb or similar
921   * entry points.
922 @@ -458,11 +458,12 @@ static inline unsigned long compare_ethe
923         fold |= *(unsigned long *)(a + 6) ^ *(unsigned long *)(b + 6);
924         return fold;
925  #else
926 -       u32 *a32 = (u32 *)((u8 *)a + 2);
927 -       u32 *b32 = (u32 *)((u8 *)b + 2);
928 +       const u16 *a16 = a;
929 +       const u16 *b16 = b;
930  
931 -       return (*(u16 *)a ^ *(u16 *)b) | (a32[0] ^ b32[0]) |
932 -              (a32[1] ^ b32[1]) | (a32[2] ^ b32[2]);
933 +       return (a16[0] ^ b16[0]) | (a16[1] ^ b16[1]) | (a16[2] ^ b16[2]) |
934 +              (a16[3] ^ b16[3]) | (a16[4] ^ b16[4]) | (a16[5] ^ b16[5]) |
935 +              (a16[6] ^ b16[6]);
936  #endif
937  }
938  
939 --- a/net/ipv4/tcp_offload.c
940 +++ b/net/ipv4/tcp_offload.c
941 @@ -218,7 +218,7 @@ struct sk_buff **tcp_gro_receive(struct
942  
943                 th2 = tcp_hdr(p);
944  
945 -               if (*(u32 *)&th->source ^ *(u32 *)&th2->source) {
946 +               if (net_hdr_word(&th->source) ^ net_hdr_word(&th2->source)) {
947                         NAPI_GRO_CB(p)->same_flow = 0;
948                         continue;
949                 }
950 @@ -236,8 +236,8 @@ found:
951                   ~(TCP_FLAG_CWR | TCP_FLAG_FIN | TCP_FLAG_PSH));
952         flush |= (__force int)(th->ack_seq ^ th2->ack_seq);
953         for (i = sizeof(*th); i < thlen; i += 4)
954 -               flush |= *(u32 *)((u8 *)th + i) ^
955 -                        *(u32 *)((u8 *)th2 + i);
956 +               flush |= net_hdr_word((u8 *)th + i) ^
957 +                        net_hdr_word((u8 *)th2 + i);
958  
959         /* When we receive our second frame we can made a decision on if we
960          * continue this flow as an atomic flow with a fixed ID or if we use
961 --- a/net/ipv6/netfilter/ip6table_mangle.c
962 +++ b/net/ipv6/netfilter/ip6table_mangle.c
963 @@ -58,7 +58,7 @@ ip6t_mangle_out(struct sk_buff *skb, con
964         hop_limit = ipv6_hdr(skb)->hop_limit;
965  
966         /* flowlabel and prio (includes version, which shouldn't change either */
967 -       flowlabel = *((u_int32_t *)ipv6_hdr(skb));
968 +       flowlabel = net_hdr_word(ipv6_hdr(skb));
969  
970         ret = ip6t_do_table(skb, state, state->net->ipv6.ip6table_mangle);
971  
972 @@ -67,7 +67,7 @@ ip6t_mangle_out(struct sk_buff *skb, con
973              !ipv6_addr_equal(&ipv6_hdr(skb)->daddr, &daddr) ||
974              skb->mark != mark ||
975              ipv6_hdr(skb)->hop_limit != hop_limit ||
976 -            flowlabel != *((u_int32_t *)ipv6_hdr(skb)))) {
977 +            flowlabel != net_hdr_word(ipv6_hdr(skb)))) {
978                 err = ip6_route_me_harder(state->net, skb);
979                 if (err < 0)
980                         ret = NF_DROP_ERR(err);