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