CC: brcm2708-gpu-fw: update md5sum in Makefile
[15.05/openwrt.git] / target / linux / ar71xx / patches-3.18 / 902-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 @@ -222,69 +226,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 @@ -125,7 +125,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 @@ -41,8 +41,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/include/uapi/linux/in6.h
193 +++ b/include/uapi/linux/in6.h
194 @@ -42,7 +42,7 @@ struct in6_addr {
195  #define s6_addr16              in6_u.u6_addr16
196  #define s6_addr32              in6_u.u6_addr32
197  #endif
198 -};
199 +} __attribute__((packed, aligned(2)));
200  #endif /* __UAPI_DEF_IN6_ADDR */
201  
202  #if __UAPI_DEF_SOCKADDR_IN6
203 --- a/net/ipv6/tcp_ipv6.c
204 +++ b/net/ipv6/tcp_ipv6.c
205 @@ -39,6 +39,7 @@
206  #include <linux/ipsec.h>
207  #include <linux/times.h>
208  #include <linux/slab.h>
209 +#include <asm/unaligned.h>
210  #include <linux/uaccess.h>
211  #include <linux/ipv6.h>
212  #include <linux/icmpv6.h>
213 @@ -844,10 +845,10 @@ static void tcp_v6_send_response(struct
214         topt = (__be32 *)(t1 + 1);
215  
216         if (tsecr) {
217 -               *topt++ = htonl((TCPOPT_NOP << 24) | (TCPOPT_NOP << 16) |
218 -                               (TCPOPT_TIMESTAMP << 8) | TCPOLEN_TIMESTAMP);
219 -               *topt++ = htonl(tsval);
220 -               *topt++ = htonl(tsecr);
221 +               put_unaligned_be32((TCPOPT_NOP << 24) | (TCPOPT_NOP << 16) |
222 +                               (TCPOPT_TIMESTAMP << 8) | TCPOLEN_TIMESTAMP, topt++);
223 +               put_unaligned_be32(tsval, topt++);
224 +               put_unaligned_be32(tsecr, topt++);
225         }
226  
227  #ifdef CONFIG_TCP_MD5SIG
228 --- a/include/linux/ipv6.h
229 +++ b/include/linux/ipv6.h
230 @@ -5,6 +5,7 @@
231  
232  #define ipv6_optlen(p)  (((p)->hdrlen+1) << 3)
233  #define ipv6_authlen(p) (((p)->hdrlen+2) << 2)
234 +
235  /*
236   * This structure contains configuration options per IPv6 link.
237   */
238 --- a/net/ipv6/datagram.c
239 +++ b/net/ipv6/datagram.c
240 @@ -390,7 +390,7 @@ int ipv6_recv_error(struct sock *sk, str
241                                 ipv6_iface_scope_id(&sin->sin6_addr,
242                                                     IP6CB(skb)->iif);
243                 } else {
244 -                       ipv6_addr_set_v4mapped(*(__be32 *)(nh + serr->addr_offset),
245 +                       ipv6_addr_set_v4mapped(net_hdr_word(nh + serr->addr_offset),
246                                                &sin->sin6_addr);
247                         sin->sin6_scope_id = 0;
248                 }
249 @@ -724,12 +724,12 @@ int ip6_datagram_send_ctl(struct net *ne
250                         }
251  
252                         if (fl6->flowlabel&IPV6_FLOWINFO_MASK) {
253 -                               if ((fl6->flowlabel^*(__be32 *)CMSG_DATA(cmsg))&~IPV6_FLOWINFO_MASK) {
254 +                               if ((fl6->flowlabel^net_hdr_word(CMSG_DATA(cmsg)))&~IPV6_FLOWINFO_MASK) {
255                                         err = -EINVAL;
256                                         goto exit_f;
257                                 }
258                         }
259 -                       fl6->flowlabel = IPV6_FLOWINFO_MASK & *(__be32 *)CMSG_DATA(cmsg);
260 +                       fl6->flowlabel = IPV6_FLOWINFO_MASK & net_hdr_word(CMSG_DATA(cmsg));
261                         break;
262  
263                 case IPV6_2292HOPOPTS:
264 --- a/net/ipv6/ip6_gre.c
265 +++ b/net/ipv6/ip6_gre.c
266 @@ -479,11 +479,11 @@ static int ip6gre_rcv(struct sk_buff *sk
267                         offset += 4;
268                 }
269                 if (flags&GRE_KEY) {
270 -                       key = *(__be32 *)(h + offset);
271 +                       key = net_hdr_word(h + offset);
272                         offset += 4;
273                 }
274                 if (flags&GRE_SEQ) {
275 -                       seqno = ntohl(*(__be32 *)(h + offset));
276 +                       seqno = ntohl(net_hdr_word(h + offset));
277                         offset += 4;
278                 }
279         }
280 @@ -748,7 +748,7 @@ static netdev_tx_t ip6gre_xmit2(struct s
281  
282                 if (tunnel->parms.o_flags&GRE_SEQ) {
283                         ++tunnel->o_seqno;
284 -                       *ptr = htonl(tunnel->o_seqno);
285 +                       net_hdr_word(ptr) = htonl(tunnel->o_seqno);
286                         ptr--;
287                 }
288                 if (tunnel->parms.o_flags&GRE_KEY) {
289 @@ -844,7 +844,7 @@ static inline int ip6gre_xmit_ipv6(struc
290  
291         dsfield = ipv6_get_dsfield(ipv6h);
292         if (t->parms.flags & IP6_TNL_F_USE_ORIG_TCLASS)
293 -               fl6.flowlabel |= (*(__be32 *) ipv6h & IPV6_TCLASS_MASK);
294 +               fl6.flowlabel |= net_hdr_word(ipv6h) & IPV6_TCLASS_MASK;
295         if (t->parms.flags & IP6_TNL_F_USE_ORIG_FLOWLABEL)
296                 fl6.flowlabel |= ip6_flowlabel(ipv6h);
297         if (t->parms.flags & IP6_TNL_F_USE_ORIG_FWMARK)
298 --- a/net/ipv6/ip6_tunnel.c
299 +++ b/net/ipv6/ip6_tunnel.c
300 @@ -1301,7 +1301,7 @@ ip6ip6_tnl_xmit(struct sk_buff *skb, str
301  
302         dsfield = ipv6_get_dsfield(ipv6h);
303         if (t->parms.flags & IP6_TNL_F_USE_ORIG_TCLASS)
304 -               fl6.flowlabel |= (*(__be32 *) ipv6h & IPV6_TCLASS_MASK);
305 +               fl6.flowlabel |= net_hdr_word(ipv6h) & IPV6_TCLASS_MASK;
306         if (t->parms.flags & IP6_TNL_F_USE_ORIG_FLOWLABEL)
307                 fl6.flowlabel |= ip6_flowlabel(ipv6h);
308         if (t->parms.flags & IP6_TNL_F_USE_ORIG_FWMARK)
309 --- a/net/ipv6/exthdrs.c
310 +++ b/net/ipv6/exthdrs.c
311 @@ -573,7 +573,7 @@ static bool ipv6_hop_jumbo(struct sk_buf
312                 goto drop;
313         }
314  
315 -       pkt_len = ntohl(*(__be32 *)(nh + optoff + 2));
316 +       pkt_len = ntohl(net_hdr_word(nh + optoff + 2));
317         if (pkt_len <= IPV6_MAXPLEN) {
318                 IP6_INC_STATS_BH(net, ipv6_skb_idev(skb),
319                                  IPSTATS_MIB_INHDRERRORS);
320 --- a/include/linux/types.h
321 +++ b/include/linux/types.h
322 @@ -213,5 +213,11 @@ struct callback_head {
323  };
324  #define rcu_head callback_head
325  
326 +struct net_hdr_word {
327 +       u32 words[1];
328 +} __attribute__((packed, aligned(2)));
329 +
330 +#define net_hdr_word(_p) (((struct net_hdr_word *) (_p))->words[0])
331 +
332  #endif /*  __ASSEMBLY__ */
333  #endif /* _LINUX_TYPES_H */
334 --- a/net/ipv4/af_inet.c
335 +++ b/net/ipv4/af_inet.c
336 @@ -1329,8 +1329,8 @@ static struct sk_buff **inet_gro_receive
337         if (unlikely(ip_fast_csum((u8 *)iph, 5)))
338                 goto out_unlock;
339  
340 -       id = ntohl(*(__be32 *)&iph->id);
341 -       flush = (u16)((ntohl(*(__be32 *)iph) ^ skb_gro_len(skb)) | (id & ~IP_DF));
342 +       id = ntohl(net_hdr_word(&iph->id));
343 +       flush = (u16)((ntohl(net_hdr_word(iph)) ^ skb_gro_len(skb)) | (id & ~IP_DF));
344         id >>= 16;
345  
346         for (p = *head; p; p = p->next) {
347 --- a/net/ipv4/route.c
348 +++ b/net/ipv4/route.c
349 @@ -454,7 +454,7 @@ static struct neighbour *ipv4_neigh_look
350         else if (skb)
351                 pkey = &ip_hdr(skb)->daddr;
352  
353 -       n = __ipv4_neigh_lookup(dev, *(__force u32 *)pkey);
354 +       n = __ipv4_neigh_lookup(dev, net_hdr_word(pkey));
355         if (n)
356                 return n;
357         return neigh_create(&arp_tbl, pkey, dev);
358 --- a/net/ipv4/tcp_output.c
359 +++ b/net/ipv4/tcp_output.c
360 @@ -446,48 +446,53 @@ static void tcp_options_write(__be32 *pt
361         u16 options = opts->options;    /* mungable copy */
362  
363         if (unlikely(OPTION_MD5 & options)) {
364 -               *ptr++ = htonl((TCPOPT_NOP << 24) | (TCPOPT_NOP << 16) |
365 -                              (TCPOPT_MD5SIG << 8) | TCPOLEN_MD5SIG);
366 +               net_hdr_word(ptr++) =
367 +                       htonl((TCPOPT_NOP << 24) | (TCPOPT_NOP << 16) |
368 +                             (TCPOPT_MD5SIG << 8) | TCPOLEN_MD5SIG);
369                 /* overload cookie hash location */
370                 opts->hash_location = (__u8 *)ptr;
371                 ptr += 4;
372         }
373  
374         if (unlikely(opts->mss)) {
375 -               *ptr++ = htonl((TCPOPT_MSS << 24) |
376 -                              (TCPOLEN_MSS << 16) |
377 -                              opts->mss);
378 +               net_hdr_word(ptr++) =
379 +                       htonl((TCPOPT_MSS << 24) | (TCPOLEN_MSS << 16) |
380 +                             opts->mss);
381         }
382  
383         if (likely(OPTION_TS & options)) {
384                 if (unlikely(OPTION_SACK_ADVERTISE & options)) {
385 -                       *ptr++ = htonl((TCPOPT_SACK_PERM << 24) |
386 -                                      (TCPOLEN_SACK_PERM << 16) |
387 -                                      (TCPOPT_TIMESTAMP << 8) |
388 -                                      TCPOLEN_TIMESTAMP);
389 +                       net_hdr_word(ptr++) =
390 +                               htonl((TCPOPT_SACK_PERM << 24) |
391 +                                     (TCPOLEN_SACK_PERM << 16) |
392 +                                     (TCPOPT_TIMESTAMP << 8) |
393 +                                     TCPOLEN_TIMESTAMP);
394                         options &= ~OPTION_SACK_ADVERTISE;
395                 } else {
396 -                       *ptr++ = htonl((TCPOPT_NOP << 24) |
397 -                                      (TCPOPT_NOP << 16) |
398 -                                      (TCPOPT_TIMESTAMP << 8) |
399 -                                      TCPOLEN_TIMESTAMP);
400 +                       net_hdr_word(ptr++) =
401 +                               htonl((TCPOPT_NOP << 24) |
402 +                                     (TCPOPT_NOP << 16) |
403 +                                     (TCPOPT_TIMESTAMP << 8) |
404 +                                     TCPOLEN_TIMESTAMP);
405                 }
406 -               *ptr++ = htonl(opts->tsval);
407 -               *ptr++ = htonl(opts->tsecr);
408 +               net_hdr_word(ptr++) = htonl(opts->tsval);
409 +               net_hdr_word(ptr++) = htonl(opts->tsecr);
410         }
411  
412         if (unlikely(OPTION_SACK_ADVERTISE & options)) {
413 -               *ptr++ = htonl((TCPOPT_NOP << 24) |
414 -                              (TCPOPT_NOP << 16) |
415 -                              (TCPOPT_SACK_PERM << 8) |
416 -                              TCPOLEN_SACK_PERM);
417 +               net_hdr_word(ptr++) =
418 +                       htonl((TCPOPT_NOP << 24) |
419 +                             (TCPOPT_NOP << 16) |
420 +                             (TCPOPT_SACK_PERM << 8) |
421 +                             TCPOLEN_SACK_PERM);
422         }
423  
424         if (unlikely(OPTION_WSCALE & options)) {
425 -               *ptr++ = htonl((TCPOPT_NOP << 24) |
426 -                              (TCPOPT_WINDOW << 16) |
427 -                              (TCPOLEN_WINDOW << 8) |
428 -                              opts->ws);
429 +               net_hdr_word(ptr++) =
430 +                       htonl((TCPOPT_NOP << 24) |
431 +                             (TCPOPT_WINDOW << 16) |
432 +                             (TCPOLEN_WINDOW << 8) |
433 +                             opts->ws);
434         }
435  
436         if (unlikely(opts->num_sack_blocks)) {
437 @@ -495,16 +500,17 @@ static void tcp_options_write(__be32 *pt
438                         tp->duplicate_sack : tp->selective_acks;
439                 int this_sack;
440  
441 -               *ptr++ = htonl((TCPOPT_NOP  << 24) |
442 -                              (TCPOPT_NOP  << 16) |
443 -                              (TCPOPT_SACK <<  8) |
444 -                              (TCPOLEN_SACK_BASE + (opts->num_sack_blocks *
445 +               net_hdr_word(ptr++) =
446 +                       htonl((TCPOPT_NOP << 24) |
447 +                             (TCPOPT_NOP << 16) |
448 +                             (TCPOPT_SACK << 8) |
449 +                             (TCPOLEN_SACK_BASE + (opts->num_sack_blocks *
450                                                      TCPOLEN_SACK_PERBLOCK)));
451  
452                 for (this_sack = 0; this_sack < opts->num_sack_blocks;
453                      ++this_sack) {
454 -                       *ptr++ = htonl(sp[this_sack].start_seq);
455 -                       *ptr++ = htonl(sp[this_sack].end_seq);
456 +                       net_hdr_word(ptr++) = htonl(sp[this_sack].start_seq);
457 +                       net_hdr_word(ptr++) = htonl(sp[this_sack].end_seq);
458                 }
459  
460                 tp->rx_opt.dsack = 0;
461 @@ -513,9 +519,10 @@ static void tcp_options_write(__be32 *pt
462         if (unlikely(OPTION_FAST_OPEN_COOKIE & options)) {
463                 struct tcp_fastopen_cookie *foc = opts->fastopen_cookie;
464  
465 -               *ptr++ = htonl((TCPOPT_EXP << 24) |
466 -                              ((TCPOLEN_EXP_FASTOPEN_BASE + foc->len) << 16) |
467 -                              TCPOPT_FASTOPEN_MAGIC);
468 +               net_hdr_word(ptr++) =
469 +                       htonl((TCPOPT_EXP << 24) |
470 +                             ((TCPOLEN_EXP_FASTOPEN_BASE + foc->len) << 16) |
471 +                             TCPOPT_FASTOPEN_MAGIC);
472  
473                 memcpy(ptr, foc->val, foc->len);
474                 if ((foc->len & 3) == 2) {
475 --- a/net/ipv4/igmp.c
476 +++ b/net/ipv4/igmp.c
477 @@ -495,7 +495,7 @@ static struct sk_buff *add_grec(struct s
478                 if (!skb)
479                         return NULL;
480                 psrc = (__be32 *)skb_put(skb, sizeof(__be32));
481 -               *psrc = psf->sf_inaddr;
482 +               net_hdr_word(psrc) = psf->sf_inaddr;
483                 scount++; stotal++;
484                 if ((type == IGMPV3_ALLOW_NEW_SOURCES ||
485                      type == IGMPV3_BLOCK_OLD_SOURCES) && psf->sf_crcount) {
486 --- a/include/uapi/linux/igmp.h
487 +++ b/include/uapi/linux/igmp.h
488 @@ -32,7 +32,7 @@ struct igmphdr {
489         __u8 code;              /* For newer IGMP */
490         __sum16 csum;
491         __be32 group;
492 -};
493 +} __attribute__((packed, aligned(2)));
494  
495  /* V3 group record types [grec_type] */
496  #define IGMPV3_MODE_IS_INCLUDE         1
497 @@ -48,7 +48,7 @@ struct igmpv3_grec {
498         __be16  grec_nsrcs;
499         __be32  grec_mca;
500         __be32  grec_src[0];
501 -};
502 +} __attribute__((packed, aligned(2)));
503  
504  struct igmpv3_report {
505         __u8 type;
506 @@ -57,7 +57,7 @@ struct igmpv3_report {
507         __be16 resv2;
508         __be16 ngrec;
509         struct igmpv3_grec grec[0];
510 -};
511 +} __attribute__((packed, aligned(2)));
512  
513  struct igmpv3_query {
514         __u8 type;
515 @@ -78,7 +78,7 @@ struct igmpv3_query {
516         __u8 qqic;
517         __be16 nsrcs;
518         __be32 srcs[0];
519 -};
520 +} __attribute__((packed, aligned(2)));
521  
522  #define IGMP_HOST_MEMBERSHIP_QUERY     0x11    /* From RFC1112 */
523  #define IGMP_HOST_MEMBERSHIP_REPORT    0x12    /* Ditto */
524 --- a/net/core/flow_dissector.c
525 +++ b/net/core/flow_dissector.c
526 @@ -53,7 +53,7 @@ __be32 __skb_flow_get_ports(const struct
527                 ports = __skb_header_pointer(skb, thoff + poff,
528                                              sizeof(_ports), data, hlen, &_ports);
529                 if (ports)
530 -                       return *ports;
531 +                       return (__be32)net_hdr_word(ports);
532         }
533  
534         return 0;
535 --- a/include/uapi/linux/icmpv6.h
536 +++ b/include/uapi/linux/icmpv6.h
537 @@ -76,7 +76,7 @@ struct icmp6hdr {
538  #define icmp6_addrconf_other   icmp6_dataun.u_nd_ra.other
539  #define icmp6_rt_lifetime      icmp6_dataun.u_nd_ra.rt_lifetime
540  #define icmp6_router_pref      icmp6_dataun.u_nd_ra.router_pref
541 -};
542 +} __attribute__((packed, aligned(2)));
543  
544  
545  #define ICMPV6_ROUTER_PREF_LOW         0x3
546 --- a/include/net/ndisc.h
547 +++ b/include/net/ndisc.h
548 @@ -76,7 +76,7 @@ struct ra_msg {
549          struct icmp6hdr                icmph;
550         __be32                  reachable_time;
551         __be32                  retrans_timer;
552 -};
553 +} __attribute__((packed, aligned(2)));
554  
555  struct rd_msg {
556         struct icmp6hdr icmph;
557 @@ -148,10 +148,10 @@ static inline u32 ndisc_hashfn(const voi
558  {
559         const u32 *p32 = pkey;
560  
561 -       return (((p32[0] ^ hash32_ptr(dev)) * hash_rnd[0]) +
562 -               (p32[1] * hash_rnd[1]) +
563 -               (p32[2] * hash_rnd[2]) +
564 -               (p32[3] * hash_rnd[3]));
565 +       return (((net_hdr_word(&p32[0]) ^ hash32_ptr(dev)) * hash_rnd[0]) +
566 +               (net_hdr_word(&p32[1]) * hash_rnd[1]) +
567 +               (net_hdr_word(&p32[2]) * hash_rnd[2]) +
568 +               (net_hdr_word(&p32[3]) * hash_rnd[3]));
569  }
570  
571  static inline struct neighbour *__ipv6_neigh_lookup_noref(struct net_device *dev, const void *pkey)
572 @@ -168,8 +168,10 @@ static inline struct neighbour *__ipv6_n
573              n = rcu_dereference_bh(n->next)) {
574                 u32 *n32 = (u32 *) n->primary_key;
575                 if (n->dev == dev &&
576 -                   ((n32[0] ^ p32[0]) | (n32[1] ^ p32[1]) |
577 -                    (n32[2] ^ p32[2]) | (n32[3] ^ p32[3])) == 0)
578 +                   ((n32[0] ^ net_hdr_word(&p32[0])) |
579 +                        (n32[1] ^ net_hdr_word(&p32[1])) |
580 +                    (n32[2] ^ net_hdr_word(&p32[2])) |
581 +                        (n32[3] ^ net_hdr_word(&p32[3]))) == 0)
582                         return n;
583         }
584  
585 --- a/net/sched/cls_u32.c
586 +++ b/net/sched/cls_u32.c
587 @@ -151,7 +151,7 @@ next_knode:
588                         data = skb_header_pointer(skb, toff, 4, &hdata);
589                         if (!data)
590                                 goto out;
591 -                       if ((*data ^ key->val) & key->mask) {
592 +                       if ((net_hdr_word(data) ^ key->val) & key->mask) {
593                                 n = rcu_dereference_bh(n->next);
594                                 goto next_knode;
595                         }
596 @@ -204,8 +204,8 @@ check_terminal:
597                                                   &hdata);
598                         if (!data)
599                                 goto out;
600 -                       sel = ht->divisor & u32_hash_fold(*data, &n->sel,
601 -                                                         n->fshift);
602 +                       sel = ht->divisor & u32_hash_fold(net_hdr_word(data),
603 +                                                         &n->sel, n->fshift);
604                 }
605                 if (!(n->sel.flags & (TC_U32_VAROFFSET | TC_U32_OFFSET | TC_U32_EAT)))
606                         goto next_ht;
607 --- a/net/ipv6/ip6_offload.c
608 +++ b/net/ipv6/ip6_offload.c
609 @@ -224,7 +224,7 @@ static struct sk_buff **ipv6_gro_receive
610                         continue;
611  
612                 iph2 = (struct ipv6hdr *)(p->data + off);
613 -               first_word = *(__be32 *)iph ^ *(__be32 *)iph2;
614 +               first_word = net_hdr_word(iph) ^ net_hdr_word(iph2);
615  
616                 /* All fields must match except length and Traffic Class.
617                  * XXX skbs on the gro_list have all been parsed and pulled
618 --- a/include/net/addrconf.h
619 +++ b/include/net/addrconf.h
620 @@ -45,7 +45,7 @@ struct prefix_info {
621         __be32                  reserved2;
622  
623         struct in6_addr         prefix;
624 -};
625 +} __attribute__((packed, aligned(2)));
626  
627  
628  #include <linux/netdevice.h>
629 --- a/include/net/inet_ecn.h
630 +++ b/include/net/inet_ecn.h
631 @@ -124,9 +124,9 @@ static inline int IP6_ECN_set_ce(struct
632         if (INET_ECN_is_not_ect(ipv6_get_dsfield(iph)))
633                 return 0;
634  
635 -       from = *(__be32 *)iph;
636 +       from = net_hdr_word(iph);
637         to = from | htonl(INET_ECN_CE << 20);
638 -       *(__be32 *)iph = to;
639 +       net_hdr_word(iph) = to;
640         if (skb->ip_summed == CHECKSUM_COMPLETE)
641                 skb->csum = csum_add(csum_sub(skb->csum, from), to);
642         return 1;
643 @@ -134,7 +134,7 @@ static inline int IP6_ECN_set_ce(struct
644  
645  static inline void IP6_ECN_clear(struct ipv6hdr *iph)
646  {
647 -       *(__be32*)iph &= ~htonl(INET_ECN_MASK << 20);
648 +       net_hdr_word(iph) &= ~htonl(INET_ECN_MASK << 20);
649  }
650  
651  static inline void ipv6_copy_dscp(unsigned int dscp, struct ipv6hdr *inner)
652 --- a/include/net/ipv6.h
653 +++ b/include/net/ipv6.h
654 @@ -109,7 +109,7 @@ struct frag_hdr {
655         __u8    reserved;
656         __be16  frag_off;
657         __be32  identification;
658 -};
659 +} __attribute__((packed, aligned(2)));
660  
661  #define        IP6_MF          0x0001
662  #define        IP6_OFFSET      0xFFF8
663 @@ -417,8 +417,8 @@ static inline void __ipv6_addr_set_half(
664         }
665  #endif
666  #endif
667 -       addr[0] = wh;
668 -       addr[1] = wl;
669 +       net_hdr_word(&addr[0]) = wh;
670 +       net_hdr_word(&addr[1]) = wl;
671  }
672  
673  static inline void ipv6_addr_set(struct in6_addr *addr, 
674 @@ -477,6 +477,8 @@ static inline bool ipv6_prefix_equal(con
675         const __be32 *a1 = addr1->s6_addr32;
676         const __be32 *a2 = addr2->s6_addr32;
677         unsigned int pdw, pbi;
678 +       /* Used for last <32-bit fraction of prefix */
679 +       u32 pbia1, pbia2;
680  
681         /* check complete u32 in prefix */
682         pdw = prefixlen >> 5;
683 @@ -485,7 +487,9 @@ static inline bool ipv6_prefix_equal(con
684  
685         /* check incomplete u32 in prefix */
686         pbi = prefixlen & 0x1f;
687 -       if (pbi && ((a1[pdw] ^ a2[pdw]) & htonl((0xffffffff) << (32 - pbi))))
688 +       pbia1 = net_hdr_word(&a1[pdw]);
689 +       pbia2 = net_hdr_word(&a2[pdw]);
690 +       if (pbi && ((pbia1 ^ pbia2) & htonl((0xffffffff) << (32 - pbi))))
691                 return false;
692  
693         return true;
694 @@ -629,13 +633,13 @@ static inline void ipv6_addr_set_v4mappe
695   */
696  static inline int __ipv6_addr_diff32(const void *token1, const void *token2, int addrlen)
697  {
698 -       const __be32 *a1 = token1, *a2 = token2;
699 +       const struct in6_addr *a1 = token1, *a2 = token2;
700         int i;
701  
702         addrlen >>= 2;
703  
704         for (i = 0; i < addrlen; i++) {
705 -               __be32 xb = a1[i] ^ a2[i];
706 +               __be32 xb = a1->s6_addr32[i] ^ a2->s6_addr32[i];
707                 if (xb)
708                         return i * 32 + 31 - __fls(ntohl(xb));
709         }
710 @@ -759,17 +763,18 @@ static inline __be32 ip6_make_flowlabel(
711  static inline void ip6_flow_hdr(struct ipv6hdr *hdr, unsigned int tclass,
712                                 __be32 flowlabel)
713  {
714 -       *(__be32 *)hdr = htonl(0x60000000 | (tclass << 20)) | flowlabel;
715 +       net_hdr_word((__be32 *)hdr) =
716 +               htonl(0x60000000 | (tclass << 20)) | flowlabel;
717  }
718  
719  static inline __be32 ip6_flowinfo(const struct ipv6hdr *hdr)
720  {
721 -       return *(__be32 *)hdr & IPV6_FLOWINFO_MASK;
722 +       return net_hdr_word((__be32 *)hdr) & IPV6_FLOWINFO_MASK;
723  }
724  
725  static inline __be32 ip6_flowlabel(const struct ipv6hdr *hdr)
726  {
727 -       return *(__be32 *)hdr & IPV6_FLOWLABEL_MASK;
728 +       return net_hdr_word((__be32 *)hdr) & IPV6_FLOWLABEL_MASK;
729  }
730  
731  static inline u8 ip6_tclass(__be32 flowinfo)
732 --- a/include/net/secure_seq.h
733 +++ b/include/net/secure_seq.h
734 @@ -2,6 +2,7 @@
735  #define _NET_SECURE_SEQ
736  
737  #include <linux/types.h>
738 +#include <linux/in6.h>
739  
740  u32 secure_ipv4_port_ephemeral(__be32 saddr, __be32 daddr, __be16 dport);
741  u32 secure_ipv6_port_ephemeral(const __be32 *saddr, const __be32 *daddr,
742 --- a/include/uapi/linux/in.h
743 +++ b/include/uapi/linux/in.h
744 @@ -78,7 +78,7 @@ enum {
745  /* Internet address. */
746  struct in_addr {
747         __be32  s_addr;
748 -};
749 +} __attribute__((packed, aligned(2)));
750  
751  #define IP_TOS         1
752  #define IP_TTL         2
753 --- a/net/core/secure_seq.c
754 +++ b/net/core/secure_seq.c
755 @@ -46,11 +46,12 @@ __u32 secure_tcpv6_sequence_number(const
756         u32 secret[MD5_MESSAGE_BYTES / 4];
757         u32 hash[MD5_DIGEST_WORDS];
758         u32 i;
759 +       const struct in6_addr *daddr6 = (struct in6_addr *) daddr;
760  
761         net_secret_init();
762         memcpy(hash, saddr, 16);
763         for (i = 0; i < 4; i++)
764 -               secret[i] = net_secret[i] + (__force u32)daddr[i];
765 +               secret[i] = net_secret[i] + (__force u32)daddr6->s6_addr32[i];
766         secret[4] = net_secret[4] +
767                 (((__force u16)sport << 16) + (__force u16)dport);
768         for (i = 5; i < MD5_MESSAGE_BYTES / 4; i++)
769 @@ -68,11 +69,12 @@ u32 secure_ipv6_port_ephemeral(const __b
770         u32 secret[MD5_MESSAGE_BYTES / 4];
771         u32 hash[MD5_DIGEST_WORDS];
772         u32 i;
773 +       const struct in6_addr *daddr6 = (struct in6_addr *) daddr;
774  
775         net_secret_init();
776         memcpy(hash, saddr, 16);
777         for (i = 0; i < 4; i++)
778 -               secret[i] = net_secret[i] + (__force u32) daddr[i];
779 +               secret[i] = net_secret[i] + (__force u32) daddr6->s6_addr32[i];
780         secret[4] = net_secret[4] + (__force u32)dport;
781         for (i = 5; i < MD5_MESSAGE_BYTES / 4; i++)
782                 secret[i] = net_secret[i];
783 @@ -150,11 +152,12 @@ u64 secure_dccpv6_sequence_number(__be32
784         u32 hash[MD5_DIGEST_WORDS];
785         u64 seq;
786         u32 i;
787 +       const struct in6_addr *daddr6 = (struct in6_addr *) daddr;
788  
789         net_secret_init();
790         memcpy(hash, saddr, 16);
791         for (i = 0; i < 4; i++)
792 -               secret[i] = net_secret[i] + daddr[i];
793 +               secret[i] = net_secret[i] +  daddr6->s6_addr32[i];
794         secret[4] = net_secret[4] +
795                 (((__force u16)sport << 16) + (__force u16)dport);
796         for (i = 5; i < MD5_MESSAGE_BYTES / 4; i++)
797 --- a/net/ipv6/ip6_fib.c
798 +++ b/net/ipv6/ip6_fib.c
799 @@ -137,7 +137,7 @@ static __be32 addr_bit_set(const void *t
800          * See include/asm-generic/bitops/le.h.
801          */
802         return (__force __be32)(1 << ((~fn_bit ^ BITOP_BE32_SWIZZLE) & 0x1f)) &
803 -              addr[fn_bit >> 5];
804 +              net_hdr_word(&addr[fn_bit >> 5]);
805  }
806  
807  static struct fib6_node *node_alloc(void)
808 --- a/net/netfilter/nf_conntrack_proto_tcp.c
809 +++ b/net/netfilter/nf_conntrack_proto_tcp.c
810 @@ -456,7 +456,7 @@ static void tcp_sack(const struct sk_buf
811  
812         /* Fast path for timestamp-only option */
813         if (length == TCPOLEN_TSTAMP_ALIGNED
814 -           && *(__be32 *)ptr == htonl((TCPOPT_NOP << 24)
815 +           && net_hdr_word(ptr) == htonl((TCPOPT_NOP << 24)
816                                        | (TCPOPT_NOP << 16)
817                                        | (TCPOPT_TIMESTAMP << 8)
818                                        | TCPOLEN_TIMESTAMP))
819 --- a/net/xfrm/xfrm_input.c
820 +++ b/net/xfrm/xfrm_input.c
821 @@ -154,8 +154,8 @@ int xfrm_parse_spi(struct sk_buff *skb,
822         if (!pskb_may_pull(skb, hlen))
823                 return -EINVAL;
824  
825 -       *spi = *(__be32 *)(skb_transport_header(skb) + offset);
826 -       *seq = *(__be32 *)(skb_transport_header(skb) + offset_seq);
827 +       *spi = net_hdr_word(skb_transport_header(skb) + offset);
828 +       *seq = net_hdr_word(skb_transport_header(skb) + offset_seq);
829         return 0;
830  }
831  
832 --- a/net/ipv4/tcp_input.c
833 +++ b/net/ipv4/tcp_input.c
834 @@ -3682,14 +3682,16 @@ static bool tcp_parse_aligned_timestamp(
835  {
836         const __be32 *ptr = (const __be32 *)(th + 1);
837  
838 -       if (*ptr == htonl((TCPOPT_NOP << 24) | (TCPOPT_NOP << 16)
839 -                         | (TCPOPT_TIMESTAMP << 8) | TCPOLEN_TIMESTAMP)) {
840 +       if (net_hdr_word(ptr) ==
841 +           htonl((TCPOPT_NOP << 24) | (TCPOPT_NOP << 16) |
842 +                 (TCPOPT_TIMESTAMP << 8) | TCPOLEN_TIMESTAMP)) {
843                 tp->rx_opt.saw_tstamp = 1;
844                 ++ptr;
845 -               tp->rx_opt.rcv_tsval = ntohl(*ptr);
846 +               tp->rx_opt.rcv_tsval = get_unaligned_be32(ptr);
847                 ++ptr;
848 -               if (*ptr)
849 -                       tp->rx_opt.rcv_tsecr = ntohl(*ptr) - tp->tsoffset;
850 +               if (net_hdr_word(ptr))
851 +                       tp->rx_opt.rcv_tsecr = get_unaligned_be32(ptr) -
852 +                                              tp->tsoffset;
853                 else
854                         tp->rx_opt.rcv_tsecr = 0;
855                 return true;
856 --- a/include/uapi/linux/if_pppox.h
857 +++ b/include/uapi/linux/if_pppox.h
858 @@ -47,6 +47,7 @@ struct pppoe_addr {
859   */
860  struct pptp_addr {
861         __u16           call_id;
862 +       __u16           pad;
863         struct in_addr  sin_addr;
864  };
865  
866 --- a/net/ipv6/netfilter/nf_log_ipv6.c
867 +++ b/net/ipv6/netfilter/nf_log_ipv6.c
868 @@ -63,9 +63,9 @@ static void dump_ipv6_packet(struct nf_l
869         /* Max length: 44 "LEN=65535 TC=255 HOPLIMIT=255 FLOWLBL=FFFFF " */
870         nf_log_buf_add(m, "LEN=%Zu TC=%u HOPLIMIT=%u FLOWLBL=%u ",
871                ntohs(ih->payload_len) + sizeof(struct ipv6hdr),
872 -              (ntohl(*(__be32 *)ih) & 0x0ff00000) >> 20,
873 +              (ntohl(net_hdr_word(ih)) & 0x0ff00000) >> 20,
874                ih->hop_limit,
875 -              (ntohl(*(__be32 *)ih) & 0x000fffff));
876 +              (ntohl(net_hdr_word(ih)) & 0x000fffff));
877  
878         fragment = 0;
879         ptr = ip6hoff + sizeof(struct ipv6hdr);