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