ar71xx: fix a compile bug in 902-unaligned_access_hacks.patch
[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 @@
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 @@
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 @@
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 @@
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 @@
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 @@
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 @@
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 @@
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 @@
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 @@
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 @@ -833,10 +834,10 @@
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 @@ -374,7 +374,7 @@
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 @@ -712,12 +712,12 @@
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 @@ -393,7 +393,7 @@
267  
268         t = ip6gre_tunnel_lookup(skb->dev, &ipv6h->daddr, &ipv6h->saddr,
269                                 flags & GRE_KEY ?
270 -                               *(((__be32 *)p) + (grehlen / 4) - 1) : 0,
271 +                               net_hdr_word(((__be32 *)p) + (grehlen / 4) - 1) : 0,
272                                 p[1]);
273         if (t == NULL)
274                 return;
275 @@ -475,11 +475,11 @@
276                         offset += 4;
277                 }
278                 if (flags&GRE_KEY) {
279 -                       key = *(__be32 *)(h + offset);
280 +                       key = net_hdr_word(h + offset);
281                         offset += 4;
282                 }
283                 if (flags&GRE_SEQ) {
284 -                       seqno = ntohl(*(__be32 *)(h + offset));
285 +                       seqno = ntohl(net_hdr_word(h + offset));
286                         offset += 4;
287                 }
288         }
289 @@ -744,7 +744,7 @@
290  
291                 if (tunnel->parms.o_flags&GRE_SEQ) {
292                         ++tunnel->o_seqno;
293 -                       *ptr = htonl(tunnel->o_seqno);
294 +                       net_hdr_word(ptr) = htonl(tunnel->o_seqno);
295                         ptr--;
296                 }
297                 if (tunnel->parms.o_flags&GRE_KEY) {
298 @@ -840,7 +840,7 @@
299  
300         dsfield = ipv6_get_dsfield(ipv6h);
301         if (t->parms.flags & IP6_TNL_F_USE_ORIG_TCLASS)
302 -               fl6.flowlabel |= (*(__be32 *) ipv6h & IPV6_TCLASS_MASK);
303 +               fl6.flowlabel |= net_hdr_word(ipv6h) & IPV6_TCLASS_MASK;
304         if (t->parms.flags & IP6_TNL_F_USE_ORIG_FLOWLABEL)
305                 fl6.flowlabel |= ip6_flowlabel(ipv6h);
306         if (t->parms.flags & IP6_TNL_F_USE_ORIG_FWMARK)
307 --- a/net/ipv6/ip6_tunnel.c
308 +++ b/net/ipv6/ip6_tunnel.c
309 @@ -1291,7 +1291,7 @@
310  
311         dsfield = ipv6_get_dsfield(ipv6h);
312         if (t->parms.flags & IP6_TNL_F_USE_ORIG_TCLASS)
313 -               fl6.flowlabel |= (*(__be32 *) ipv6h & IPV6_TCLASS_MASK);
314 +               fl6.flowlabel |= net_hdr_word(ipv6h) & IPV6_TCLASS_MASK;
315         if (t->parms.flags & IP6_TNL_F_USE_ORIG_FLOWLABEL)
316                 fl6.flowlabel |= ip6_flowlabel(ipv6h);
317         if (t->parms.flags & IP6_TNL_F_USE_ORIG_FWMARK)
318 --- a/net/ipv6/exthdrs.c
319 +++ b/net/ipv6/exthdrs.c
320 @@ -573,7 +573,7 @@
321                 goto drop;
322         }
323  
324 -       pkt_len = ntohl(*(__be32 *)(nh + optoff + 2));
325 +       pkt_len = ntohl(net_hdr_word(nh + optoff + 2));
326         if (pkt_len <= IPV6_MAXPLEN) {
327                 IP6_INC_STATS_BH(net, ipv6_skb_idev(skb),
328                                  IPSTATS_MIB_INHDRERRORS);
329 --- a/include/linux/types.h
330 +++ b/include/linux/types.h
331 @@ -213,5 +213,11 @@
332  };
333  #define rcu_head callback_head
334  
335 +struct net_hdr_word {
336 +       u32 words[1];
337 +} __attribute__((packed, aligned(2)));
338 +
339 +#define net_hdr_word(_p) (((struct net_hdr_word *) (_p))->words[0])
340 +
341  #endif /*  __ASSEMBLY__ */
342  #endif /* _LINUX_TYPES_H */
343 --- a/net/ipv4/af_inet.c
344 +++ b/net/ipv4/af_inet.c
345 @@ -1324,8 +1324,8 @@
346         if (unlikely(ip_fast_csum((u8 *)iph, 5)))
347                 goto out_unlock;
348  
349 -       id = ntohl(*(__be32 *)&iph->id);
350 -       flush = (u16)((ntohl(*(__be32 *)iph) ^ skb_gro_len(skb)) | (id & ~IP_DF));
351 +       id = ntohl(net_hdr_word(&iph->id));
352 +       flush = (u16)((ntohl(net_hdr_word(iph)) ^ skb_gro_len(skb)) | (id & ~IP_DF));
353         id >>= 16;
354  
355         for (p = *head; p; p = p->next) {
356 --- a/net/ipv4/route.c
357 +++ b/net/ipv4/route.c
358 @@ -454,7 +454,7 @@
359         else if (skb)
360                 pkey = &ip_hdr(skb)->daddr;
361  
362 -       n = __ipv4_neigh_lookup(dev, *(__force u32 *)pkey);
363 +       n = __ipv4_neigh_lookup(dev, net_hdr_word(pkey));
364         if (n)
365                 return n;
366         return neigh_create(&arp_tbl, pkey, dev);
367 --- a/net/ipv4/tcp_output.c
368 +++ b/net/ipv4/tcp_output.c
369 @@ -446,48 +446,53 @@
370         u16 options = opts->options;    /* mungable copy */
371  
372         if (unlikely(OPTION_MD5 & options)) {
373 -               *ptr++ = htonl((TCPOPT_NOP << 24) | (TCPOPT_NOP << 16) |
374 -                              (TCPOPT_MD5SIG << 8) | TCPOLEN_MD5SIG);
375 +               net_hdr_word(ptr++) =
376 +                       htonl((TCPOPT_NOP << 24) | (TCPOPT_NOP << 16) |
377 +                             (TCPOPT_MD5SIG << 8) | TCPOLEN_MD5SIG);
378                 /* overload cookie hash location */
379                 opts->hash_location = (__u8 *)ptr;
380                 ptr += 4;
381         }
382  
383         if (unlikely(opts->mss)) {
384 -               *ptr++ = htonl((TCPOPT_MSS << 24) |
385 -                              (TCPOLEN_MSS << 16) |
386 -                              opts->mss);
387 +               net_hdr_word(ptr++) =
388 +                       htonl((TCPOPT_MSS << 24) | (TCPOLEN_MSS << 16) |
389 +                             opts->mss);
390         }
391  
392         if (likely(OPTION_TS & options)) {
393                 if (unlikely(OPTION_SACK_ADVERTISE & options)) {
394 -                       *ptr++ = htonl((TCPOPT_SACK_PERM << 24) |
395 -                                      (TCPOLEN_SACK_PERM << 16) |
396 -                                      (TCPOPT_TIMESTAMP << 8) |
397 -                                      TCPOLEN_TIMESTAMP);
398 +                       net_hdr_word(ptr++) =
399 +                               htonl((TCPOPT_SACK_PERM << 24) |
400 +                                     (TCPOLEN_SACK_PERM << 16) |
401 +                                     (TCPOPT_TIMESTAMP << 8) |
402 +                                     TCPOLEN_TIMESTAMP);
403                         options &= ~OPTION_SACK_ADVERTISE;
404                 } else {
405 -                       *ptr++ = htonl((TCPOPT_NOP << 24) |
406 -                                      (TCPOPT_NOP << 16) |
407 -                                      (TCPOPT_TIMESTAMP << 8) |
408 -                                      TCPOLEN_TIMESTAMP);
409 +                       net_hdr_word(ptr++) =
410 +                               htonl((TCPOPT_NOP << 24) |
411 +                                     (TCPOPT_NOP << 16) |
412 +                                     (TCPOPT_TIMESTAMP << 8) |
413 +                                     TCPOLEN_TIMESTAMP);
414                 }
415 -               *ptr++ = htonl(opts->tsval);
416 -               *ptr++ = htonl(opts->tsecr);
417 +               net_hdr_word(ptr++) = htonl(opts->tsval);
418 +               net_hdr_word(ptr++) = htonl(opts->tsecr);
419         }
420  
421         if (unlikely(OPTION_SACK_ADVERTISE & options)) {
422 -               *ptr++ = htonl((TCPOPT_NOP << 24) |
423 -                              (TCPOPT_NOP << 16) |
424 -                              (TCPOPT_SACK_PERM << 8) |
425 -                              TCPOLEN_SACK_PERM);
426 +               net_hdr_word(ptr++) =
427 +                       htonl((TCPOPT_NOP << 24) |
428 +                             (TCPOPT_NOP << 16) |
429 +                             (TCPOPT_SACK_PERM << 8) |
430 +                             TCPOLEN_SACK_PERM);
431         }
432  
433         if (unlikely(OPTION_WSCALE & options)) {
434 -               *ptr++ = htonl((TCPOPT_NOP << 24) |
435 -                              (TCPOPT_WINDOW << 16) |
436 -                              (TCPOLEN_WINDOW << 8) |
437 -                              opts->ws);
438 +               net_hdr_word(ptr++) =
439 +                       htonl((TCPOPT_NOP << 24) |
440 +                             (TCPOPT_WINDOW << 16) |
441 +                             (TCPOLEN_WINDOW << 8) |
442 +                             opts->ws);
443         }
444  
445         if (unlikely(opts->num_sack_blocks)) {
446 @@ -495,16 +500,17 @@
447                         tp->duplicate_sack : tp->selective_acks;
448                 int this_sack;
449  
450 -               *ptr++ = htonl((TCPOPT_NOP  << 24) |
451 -                              (TCPOPT_NOP  << 16) |
452 -                              (TCPOPT_SACK <<  8) |
453 -                              (TCPOLEN_SACK_BASE + (opts->num_sack_blocks *
454 +               net_hdr_word(ptr++) =
455 +                       htonl((TCPOPT_NOP << 24) |
456 +                             (TCPOPT_NOP << 16) |
457 +                             (TCPOPT_SACK << 8) |
458 +                             (TCPOLEN_SACK_BASE + (opts->num_sack_blocks *
459                                                      TCPOLEN_SACK_PERBLOCK)));
460  
461                 for (this_sack = 0; this_sack < opts->num_sack_blocks;
462                      ++this_sack) {
463 -                       *ptr++ = htonl(sp[this_sack].start_seq);
464 -                       *ptr++ = htonl(sp[this_sack].end_seq);
465 +                       net_hdr_word(ptr++) = htonl(sp[this_sack].start_seq);
466 +                       net_hdr_word(ptr++) = htonl(sp[this_sack].end_seq);
467                 }
468  
469                 tp->rx_opt.dsack = 0;
470 @@ -513,9 +519,10 @@
471         if (unlikely(OPTION_FAST_OPEN_COOKIE & options)) {
472                 struct tcp_fastopen_cookie *foc = opts->fastopen_cookie;
473  
474 -               *ptr++ = htonl((TCPOPT_EXP << 24) |
475 -                              ((TCPOLEN_EXP_FASTOPEN_BASE + foc->len) << 16) |
476 -                              TCPOPT_FASTOPEN_MAGIC);
477 +               net_hdr_word(ptr++) =
478 +                       htonl((TCPOPT_EXP << 24) |
479 +                             ((TCPOLEN_EXP_FASTOPEN_BASE + foc->len) << 16) |
480 +                             TCPOPT_FASTOPEN_MAGIC);
481  
482                 memcpy(ptr, foc->val, foc->len);
483                 if ((foc->len & 3) == 2) {
484 --- a/net/ipv4/igmp.c
485 +++ b/net/ipv4/igmp.c
486 @@ -495,7 +495,7 @@
487                 if (!skb)
488                         return NULL;
489                 psrc = (__be32 *)skb_put(skb, sizeof(__be32));
490 -               *psrc = psf->sf_inaddr;
491 +               net_hdr_word(psrc) = psf->sf_inaddr;
492                 scount++; stotal++;
493                 if ((type == IGMPV3_ALLOW_NEW_SOURCES ||
494                      type == IGMPV3_BLOCK_OLD_SOURCES) && psf->sf_crcount) {
495 --- a/include/uapi/linux/igmp.h
496 +++ b/include/uapi/linux/igmp.h
497 @@ -32,7 +32,7 @@
498         __u8 code;              /* For newer IGMP */
499         __sum16 csum;
500         __be32 group;
501 -};
502 +} __attribute__((packed, aligned(2)));
503  
504  /* V3 group record types [grec_type] */
505  #define IGMPV3_MODE_IS_INCLUDE         1
506 @@ -48,7 +48,7 @@
507         __be16  grec_nsrcs;
508         __be32  grec_mca;
509         __be32  grec_src[0];
510 -};
511 +} __attribute__((packed, aligned(2)));
512  
513  struct igmpv3_report {
514         __u8 type;
515 @@ -57,7 +57,7 @@
516         __be16 resv2;
517         __be16 ngrec;
518         struct igmpv3_grec grec[0];
519 -};
520 +} __attribute__((packed, aligned(2)));
521  
522  struct igmpv3_query {
523         __u8 type;
524 @@ -78,7 +78,7 @@
525         __u8 qqic;
526         __be16 nsrcs;
527         __be32 srcs[0];
528 -};
529 +} __attribute__((packed, aligned(2)));
530  
531  #define IGMP_HOST_MEMBERSHIP_QUERY     0x11    /* From RFC1112 */
532  #define IGMP_HOST_MEMBERSHIP_REPORT    0x12    /* Ditto */
533 --- a/net/core/flow_dissector.c
534 +++ b/net/core/flow_dissector.c
535 @@ -53,7 +53,7 @@
536                 ports = __skb_header_pointer(skb, thoff + poff,
537                                              sizeof(_ports), data, hlen, &_ports);
538                 if (ports)
539 -                       return *ports;
540 +                       return (__be32)net_hdr_word(ports);
541         }
542  
543         return 0;
544 --- a/include/uapi/linux/icmpv6.h
545 +++ b/include/uapi/linux/icmpv6.h
546 @@ -76,7 +76,7 @@
547  #define icmp6_addrconf_other   icmp6_dataun.u_nd_ra.other
548  #define icmp6_rt_lifetime      icmp6_dataun.u_nd_ra.rt_lifetime
549  #define icmp6_router_pref      icmp6_dataun.u_nd_ra.router_pref
550 -};
551 +} __attribute__((packed, aligned(2)));
552  
553  
554  #define ICMPV6_ROUTER_PREF_LOW         0x3
555 --- a/include/net/ndisc.h
556 +++ b/include/net/ndisc.h
557 @@ -76,7 +76,7 @@
558          struct icmp6hdr                icmph;
559         __be32                  reachable_time;
560         __be32                  retrans_timer;
561 -};
562 +} __attribute__((packed, aligned(2)));
563  
564  struct rd_msg {
565         struct icmp6hdr icmph;
566 @@ -148,10 +148,10 @@
567  {
568         const u32 *p32 = pkey;
569  
570 -       return (((p32[0] ^ hash32_ptr(dev)) * hash_rnd[0]) +
571 -               (p32[1] * hash_rnd[1]) +
572 -               (p32[2] * hash_rnd[2]) +
573 -               (p32[3] * hash_rnd[3]));
574 +       return (((net_hdr_word(&p32[0]) ^ hash32_ptr(dev)) * hash_rnd[0]) +
575 +               (net_hdr_word(&p32[1]) * hash_rnd[1]) +
576 +               (net_hdr_word(&p32[2]) * hash_rnd[2]) +
577 +               (net_hdr_word(&p32[3]) * hash_rnd[3]));
578  }
579  
580  static inline struct neighbour *__ipv6_neigh_lookup_noref(struct net_device *dev, const void *pkey)
581 @@ -168,8 +168,10 @@
582              n = rcu_dereference_bh(n->next)) {
583                 u32 *n32 = (u32 *) n->primary_key;
584                 if (n->dev == dev &&
585 -                   ((n32[0] ^ p32[0]) | (n32[1] ^ p32[1]) |
586 -                    (n32[2] ^ p32[2]) | (n32[3] ^ p32[3])) == 0)
587 +                   ((n32[0] ^ net_hdr_word(&p32[0])) |
588 +                        (n32[1] ^ net_hdr_word(&p32[1])) |
589 +                    (n32[2] ^ net_hdr_word(&p32[2])) |
590 +                        (n32[3] ^ net_hdr_word(&p32[3]))) == 0)
591                         return n;
592         }
593  
594 --- a/net/sched/cls_u32.c
595 +++ b/net/sched/cls_u32.c
596 @@ -148,7 +148,7 @@
597                         data = skb_header_pointer(skb, toff, 4, &hdata);
598                         if (!data)
599                                 goto out;
600 -                       if ((*data ^ key->val) & key->mask) {
601 +                       if ((net_hdr_word(data) ^ key->val) & key->mask) {
602                                 n = rcu_dereference_bh(n->next);
603                                 goto next_knode;
604                         }
605 @@ -201,8 +201,8 @@
606                                                   &hdata);
607                         if (!data)
608                                 goto out;
609 -                       sel = ht->divisor & u32_hash_fold(*data, &n->sel,
610 -                                                         n->fshift);
611 +                       sel = ht->divisor & u32_hash_fold(net_hdr_word(data),
612 +                                                         &n->sel, n->fshift);
613                 }
614                 if (!(n->sel.flags & (TC_U32_VAROFFSET | TC_U32_OFFSET | TC_U32_EAT)))
615                         goto next_ht;
616 --- a/net/ipv6/ip6_offload.c
617 +++ b/net/ipv6/ip6_offload.c
618 @@ -221,7 +221,7 @@
619                         continue;
620  
621                 iph2 = (struct ipv6hdr *)(p->data + off);
622 -               first_word = *(__be32 *)iph ^ *(__be32 *)iph2;
623 +               first_word = net_hdr_word(iph) ^ net_hdr_word(iph2);
624  
625                 /* All fields must match except length and Traffic Class.
626                  * XXX skbs on the gro_list have all been parsed and pulled
627 --- a/include/net/addrconf.h
628 +++ b/include/net/addrconf.h
629 @@ -43,7 +43,7 @@
630         __be32                  reserved2;
631  
632         struct in6_addr         prefix;
633 -};
634 +} __attribute__((packed, aligned(2)));
635  
636  
637  #include <linux/netdevice.h>
638 --- a/include/net/inet_ecn.h
639 +++ b/include/net/inet_ecn.h
640 @@ -115,13 +115,13 @@
641  {
642         if (INET_ECN_is_not_ect(ipv6_get_dsfield(iph)))
643                 return 0;
644 -       *(__be32*)iph |= htonl(INET_ECN_CE << 20);
645 +       net_hdr_word(iph) |= htonl(INET_ECN_CE << 20);
646         return 1;
647  }
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 @@ -109,7 +109,7 @@
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 @@ -398,8 +398,8 @@
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 @@ -458,6 +458,8 @@
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 @@ -466,7 +468,9 @@
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 @@ -609,13 +613,13 @@
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 @@ -739,17 +743,18 @@
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 @@ -78,7 +78,7 @@
749  /* Internet address. */
750  struct in_addr {
751         __be32  s_addr;
752 -};
753 +} __attribute__((packed, aligned(2)));
754  
755  #define IP_TOS         1
756  #define IP_TTL         2
757 --- a/net/core/secure_seq.c
758 +++ b/net/core/secure_seq.c
759 @@ -46,11 +46,12 @@
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 @@
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 @@ -150,11 +152,12 @@
788         u32 hash[MD5_DIGEST_WORDS];
789         u64 seq;
790         u32 i;
791 +       const struct in6_addr *daddr6 = (struct in6_addr *) daddr;
792  
793         net_secret_init();
794         memcpy(hash, saddr, 16);
795         for (i = 0; i < 4; i++)
796 -               secret[i] = net_secret[i] + daddr[i];
797 +               secret[i] = net_secret[i] +  daddr6->s6_addr32[i];
798         secret[4] = net_secret[4] +
799                 (((__force u16)sport << 16) + (__force u16)dport);
800         for (i = 5; i < MD5_MESSAGE_BYTES / 4; i++)
801 --- a/net/ipv6/ip6_fib.c
802 +++ b/net/ipv6/ip6_fib.c
803 @@ -137,7 +137,7 @@
804          * See include/asm-generic/bitops/le.h.
805          */
806         return (__force __be32)(1 << ((~fn_bit ^ BITOP_BE32_SWIZZLE) & 0x1f)) &
807 -              addr[fn_bit >> 5];
808 +              net_hdr_word(&addr[fn_bit >> 5]);
809  }
810  
811  static struct fib6_node *node_alloc(void)
812 --- a/net/netfilter/nf_conntrack_proto_tcp.c
813 +++ b/net/netfilter/nf_conntrack_proto_tcp.c
814 @@ -456,7 +456,7 @@
815  
816         /* Fast path for timestamp-only option */
817         if (length == TCPOLEN_TSTAMP_ALIGNED
818 -           && *(__be32 *)ptr == htonl((TCPOPT_NOP << 24)
819 +           && net_hdr_word(ptr) == htonl((TCPOPT_NOP << 24)
820                                        | (TCPOPT_NOP << 16)
821                                        | (TCPOPT_TIMESTAMP << 8)
822                                        | TCPOLEN_TIMESTAMP))
823 --- a/net/xfrm/xfrm_input.c
824 +++ b/net/xfrm/xfrm_input.c
825 @@ -152,8 +152,8 @@
826         if (!pskb_may_pull(skb, hlen))
827                 return -EINVAL;
828  
829 -       *spi = *(__be32 *)(skb_transport_header(skb) + offset);
830 -       *seq = *(__be32 *)(skb_transport_header(skb) + offset_seq);
831 +       *spi = net_hdr_word(skb_transport_header(skb) + offset);
832 +       *seq = net_hdr_word(skb_transport_header(skb) + offset_seq);
833         return 0;
834  }
835  
836 --- a/net/ipv4/tcp_input.c
837 +++ b/net/ipv4/tcp_input.c
838 @@ -3677,14 +3677,16 @@
839  {
840         const __be32 *ptr = (const __be32 *)(th + 1);
841  
842 -       if (*ptr == htonl((TCPOPT_NOP << 24) | (TCPOPT_NOP << 16)
843 -                         | (TCPOPT_TIMESTAMP << 8) | TCPOLEN_TIMESTAMP)) {
844 +       if (net_hdr_word(ptr) ==
845 +           htonl((TCPOPT_NOP << 24) | (TCPOPT_NOP << 16) |
846 +                 (TCPOPT_TIMESTAMP << 8) | TCPOLEN_TIMESTAMP)) {
847                 tp->rx_opt.saw_tstamp = 1;
848                 ++ptr;
849 -               tp->rx_opt.rcv_tsval = ntohl(*ptr);
850 +               tp->rx_opt.rcv_tsval = get_unaligned_be32(ptr);
851                 ++ptr;
852 -               if (*ptr)
853 -                       tp->rx_opt.rcv_tsecr = ntohl(*ptr) - tp->tsoffset;
854 +               if (net_hdr_word(ptr))
855 +                       tp->rx_opt.rcv_tsecr = get_unaligned_be32(ptr) -
856 +                                              tp->tsoffset;
857                 else
858                         tp->rx_opt.rcv_tsecr = 0;
859                 return true;
860 --- a/include/uapi/linux/if_pppox.h
861 +++ b/include/uapi/linux/if_pppox.h
862 @@ -47,6 +47,7 @@
863   */
864  struct pptp_addr {
865         __u16           call_id;
866 +       __u16           pad;
867         struct in_addr  sin_addr;
868  };
869  
870 --- a/net/ipv6/netfilter/nf_log_ipv6.c
871 +++ b/net/ipv6/netfilter/nf_log_ipv6.c
872 @@ -63,9 +63,10 @@
873         /* Max length: 44 "LEN=65535 TC=255 HOPLIMIT=255 FLOWLBL=FFFFF " */
874         nf_log_buf_add(m, "LEN=%Zu TC=%u HOPLIMIT=%u FLOWLBL=%u ",
875                ntohs(ih->payload_len) + sizeof(struct ipv6hdr),
876 +              (ntohl(net_hdr_word(ih)) & 0x0ff00000) >> 20,
877                (ntohl(*(__be32 *)ih) & 0x0ff00000) >> 20,
878                ih->hop_limit,
879 -              (ntohl(*(__be32 *)ih) & 0x000fffff));
880 +              (ntohl(net_hdr_word(ih)) & 0x000fffff));
881  
882         fragment = 0;
883         ptr = ip6hoff + sizeof(struct ipv6hdr);