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