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