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