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;
11 - carry = (csum < word[1]);
12 + csum = net_hdr_word(word++);
14 + w = net_hdr_word(word++);
20 - carry = (csum < word[2]);
21 + w = net_hdr_word(word++);
27 - carry = (csum < word[3]);
28 + w = net_hdr_word(word++);
36 - carry = (csum < *word);
37 + w = net_hdr_word(word++);
42 } while (word != stop);
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));
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,
58 - " .set push # csum_ipv6_magic\n"
59 - " .set noreorder \n"
61 - " addu %0, %5 # proto (long in network byte order)\n"
62 - " sltu $1, %0, %5 \n"
65 - " addu %0, %6 # csum\n"
66 - " sltu $1, %0, %6 \n"
67 - " lw %1, 0(%2) # four words source address\n"
70 - " sltu $1, %0, %1 \n"
75 - " sltu $1, %0, %1 \n"
80 - " sltu $1, %0, %1 \n"
85 - " sltu $1, %0, %1 \n"
90 - " sltu $1, %0, %1 \n"
95 - " sltu $1, %0, %1 \n"
100 - " sltu $1, %0, %1 \n"
102 - " lw %1, 12(%3) \n"
105 - " sltu $1, %0, %1 \n"
107 - " addu %0, $1 # Add final carry\n"
109 - : "=&r" (sum), "=&r" (tmp)
110 - : "r" (saddr), "r" (daddr),
111 - "0" (htonl(len)), "r" (htonl(proto)), "r" (sum)
114 - return csum_fold(sum);
117 #include <asm-generic/checksum.h>
118 #endif /* CONFIG_GENERIC_CSUM */
120 --- a/include/uapi/linux/ip.h
121 +++ b/include/uapi/linux/ip.h
122 @@ -106,7 +106,7 @@ struct iphdr {
125 /*The options start here. */
127 +} __attribute__((packed, aligned(2)));
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;
138 +} __attribute__((packed, aligned(2)));
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 {
149 +} __attribute__((packed, aligned(2)));
152 * The union cast uses a gcc extension to avoid aliasing problems
153 @@ -65,7 +65,7 @@ struct tcphdr {
158 +} __attribute__((packed, aligned(2)));
160 #define tcp_flag_word(tp) ( ((union tcp_word_hdr *)(tp))->words [3])
162 --- a/include/uapi/linux/udp.h
163 +++ b/include/uapi/linux/udp.h
164 @@ -25,7 +25,7 @@ struct udphdr {
169 +} __attribute__((packed, aligned(2)));
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
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);
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 {
193 +} __attribute__((packed, aligned(2)));
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
204 +} __attribute__((packed, aligned(2)));
205 #endif /* __UAPI_DEF_IN6_ADDR */
207 #if __UAPI_DEF_SOCKADDR_IN6
208 --- a/net/ipv6/tcp_ipv6.c
209 +++ b/net/ipv6/tcp_ipv6.c
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);
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++);
232 #ifdef CONFIG_TCP_MD5SIG
233 --- a/include/linux/ipv6.h
234 +++ b/include/linux/ipv6.h
237 #define ipv6_optlen(p) (((p)->hdrlen+1) << 3)
238 #define ipv6_authlen(p) (((p)->hdrlen+2) << 2)
241 * This structure contains configuration options per IPv6 link.
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,
249 - ipv6_addr_set_v4mapped(*(__be32 *)(nh + serr->addr_offset),
250 + ipv6_addr_set_v4mapped(net_hdr_word(nh + serr->addr_offset),
252 sin->sin6_scope_id = 0;
254 @@ -846,12 +846,12 @@ int ip6_datagram_send_ctl(struct net *ne
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) {
264 - fl6->flowlabel = IPV6_FLOWINFO_MASK & *(__be32 *)CMSG_DATA(cmsg);
265 + fl6->flowlabel = IPV6_FLOWINFO_MASK & net_hdr_word(CMSG_DATA(cmsg));
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
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);
286 +struct net_hdr_word {
288 +} __attribute__((packed, aligned(2)));
290 +#define net_hdr_word(_p) (((struct net_hdr_word *) (_p))->words[0])
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)))
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));
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 */
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;
323 if (unlikely(opts->mss)) {
324 - *ptr++ = htonl((TCPOPT_MSS << 24) |
325 - (TCPOLEN_MSS << 16) |
327 + net_hdr_word(ptr++) =
328 + htonl((TCPOPT_MSS << 24) | (TCPOLEN_MSS << 16) |
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;
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);
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);
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);
373 if (unlikely(OPTION_WSCALE & options)) {
374 - *ptr++ = htonl((TCPOPT_NOP << 24) |
375 - (TCPOPT_WINDOW << 16) |
376 - (TCPOLEN_WINDOW << 8) |
378 + net_hdr_word(ptr++) =
379 + htonl((TCPOPT_NOP << 24) |
380 + (TCPOPT_WINDOW << 16) |
381 + (TCPOLEN_WINDOW << 8) |
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;
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)));
401 for (this_sack = 0; this_sack < opts->num_sack_blocks;
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);
409 tp->rx_opt.dsack = 0;
410 @@ -679,13 +685,14 @@ static void tcp_options_write(__be32 *pt
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;
420 len = TCPOLEN_FASTOPEN_BASE + foc->len;
421 - *p++ = TCPOPT_FASTOPEN;
423 + net_hdr_word(p++) = TCPOPT_FASTOPEN;
424 + net_hdr_word(p++) = len;
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 */
435 +} __attribute__((packed, aligned(2)));
437 /* V3 group record types [grec_type] */
438 #define IGMPV3_MODE_IS_INCLUDE 1
439 @@ -49,7 +49,7 @@ struct igmpv3_grec {
444 +} __attribute__((packed, aligned(2)));
446 struct igmpv3_report {
448 @@ -58,7 +58,7 @@ struct igmpv3_report {
451 struct igmpv3_grec grec[0];
453 +} __attribute__((packed, aligned(2)));
455 struct igmpv3_query {
457 @@ -79,7 +79,7 @@ struct igmpv3_query {
462 +} __attribute__((packed, aligned(2)));
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);
473 + return (__be32)net_hdr_word(ports);
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
484 +} __attribute__((packed, aligned(2)));
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;
495 +} __attribute__((packed, aligned(2)));
498 struct icmp6hdr icmph;
499 @@ -372,10 +372,10 @@ static inline u32 ndisc_hashfn(const voi
501 const u32 *p32 = pkey;
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]));
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);
520 - if ((*data ^ key->val) & key->mask) {
521 + if ((net_hdr_word(data) ^ key->val) & key->mask) {
522 n = rcu_dereference_bh(n->next);
525 @@ -206,8 +206,8 @@ check_terminal:
529 - sel = ht->divisor & u32_hash_fold(*data, &n->sel,
531 + sel = ht->divisor & u32_hash_fold(net_hdr_word(data),
532 + &n->sel, n->fshift);
534 if (!(n->sel.flags & (TC_U32_VAROFFSET | TC_U32_OFFSET | TC_U32_EAT)))
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 *
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);
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 {
552 struct in6_addr prefix;
554 +} __attribute__((packed, aligned(2)));
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)))
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),
572 --- a/include/net/ipv6.h
573 +++ b/include/net/ipv6.h
574 @@ -146,7 +146,7 @@ struct frag_hdr {
577 __be32 identification;
579 +} __attribute__((packed, aligned(2)));
581 #define IP6_MF 0x0001
582 #define IP6_OFFSET 0xFFF8
583 @@ -560,8 +560,8 @@ static inline void __ipv6_addr_set_half(
589 + net_hdr_word(&addr[0]) = wh;
590 + net_hdr_word(&addr[1]) = wl;
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 */
601 /* check complete u32 in prefix */
602 pdw = prefixlen >> 5;
603 @@ -628,7 +630,9 @@ static inline bool ipv6_prefix_equal(con
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))))
614 @@ -745,13 +749,13 @@ static inline void ipv6_addr_set_v4mappe
616 static inline int __ipv6_addr_diff32(const void *token1, const void *token2, int addrlen)
618 - const __be32 *a1 = token1, *a2 = token2;
619 + const struct in6_addr *a1 = token1, *a2 = token2;
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];
628 return i * 32 + 31 - __fls(ntohl(xb));
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,
634 - *(__be32 *)hdr = htonl(0x60000000 | (tclass << 20)) | flowlabel;
635 + net_hdr_word((__be32 *)hdr) =
636 + htonl(0x60000000 | (tclass << 20)) | flowlabel;
639 static inline __be32 ip6_flowinfo(const struct ipv6hdr *hdr)
641 - return *(__be32 *)hdr & IPV6_FLOWINFO_MASK;
642 + return net_hdr_word((__be32 *)hdr) & IPV6_FLOWINFO_MASK;
645 static inline __be32 ip6_flowlabel(const struct ipv6hdr *hdr)
647 - return *(__be32 *)hdr & IPV6_FLOWLABEL_MASK;
648 + return net_hdr_word((__be32 *)hdr) & IPV6_FLOWLABEL_MASK;
651 static inline u8 ip6_tclass(__be32 flowinfo)
652 --- a/include/net/secure_seq.h
653 +++ b/include/net/secure_seq.h
655 #define _NET_SECURE_SEQ
657 #include <linux/types.h>
658 +#include <linux/in6.h>
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. */
669 +} __attribute__((packed, aligned(2)));
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.
678 return (__force __be32)(1 << ((~fn_bit ^ BITOP_BE32_SWIZZLE) & 0x1f)) &
680 + net_hdr_word(&addr[fn_bit >> 5]);
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
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)
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))
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);
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(
712 const __be32 *ptr = (const __be32 *)(th + 1);
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;
721 - tp->rx_opt.rcv_tsval = ntohl(*ptr);
722 + tp->rx_opt.rcv_tsval = get_unaligned_be32(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) -
730 tp->rx_opt.rcv_tsecr = 0;
732 --- a/include/uapi/linux/if_pppox.h
733 +++ b/include/uapi/linux/if_pppox.h
734 @@ -51,6 +51,7 @@ struct pppoe_addr {
739 struct in_addr sin_addr;
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,
751 - (ntohl(*(__be32 *)ih) & 0x000fffff));
752 + (ntohl(net_hdr_word(ih)) & 0x000fffff));
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;
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;
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 {
778 +} __attribute__((aligned(4)));
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 *
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]),
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
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
812 @@ -534,11 +534,12 @@ static inline unsigned long compare_ethe
813 fold |= *(unsigned long *)(a + 6) ^ *(unsigned long *)(b + 6);
816 - u32 *a32 = (u32 *)((u8 *)a + 2);
817 - u32 *b32 = (u32 *)((u8 *)b + 2);
818 + const u16 *a16 = a;
819 + const u16 *b16 = b;
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]) |
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
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;
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);
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;
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));
860 ret = ip6t_do_table(skb, state, state->net->ipv6.ip6table_mangle);
862 @@ -56,7 +56,7 @@ ip6t_mangle_out(struct sk_buff *skb, con
863 !ipv6_addr_equal(&ipv6_hdr(skb)->daddr, &daddr) ||
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);
870 ret = NF_DROP_ERR(err);