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;
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 @@ -214,73 +218,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));
113 - return csum_fold(sum);
116 #include <asm-generic/checksum.h>
117 #endif /* CONFIG_GENERIC_CSUM */
119 --- a/include/uapi/linux/ip.h
120 +++ b/include/uapi/linux/ip.h
121 @@ -103,7 +103,7 @@ struct iphdr {
124 /*The options start here. */
126 +} __attribute__((packed, aligned(2)));
130 --- a/include/uapi/linux/ipv6.h
131 +++ b/include/uapi/linux/ipv6.h
132 @@ -131,7 +131,7 @@ struct ipv6hdr {
134 struct in6_addr saddr;
135 struct in6_addr daddr;
137 +} __attribute__((packed, aligned(2)));
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 {
148 +} __attribute__((packed, aligned(2)));
151 * The union cast uses a gcc extension to avoid aliasing problems
152 @@ -65,7 +65,7 @@ struct tcphdr {
157 +} __attribute__((packed, aligned(2)));
159 #define tcp_flag_word(tp) ( ((union tcp_word_hdr *)(tp))->words [3])
161 --- a/include/uapi/linux/udp.h
162 +++ b/include/uapi/linux/udp.h
163 @@ -25,7 +25,7 @@ struct udphdr {
168 +} __attribute__((packed, aligned(2)));
170 /* UDP socket options */
171 #define UDP_CORK 1 /* Never send partially complete segments */
172 --- a/net/ipv4/netfilter/nf_conntrack_l3proto_ipv4.c
173 +++ b/net/ipv4/netfilter/nf_conntrack_l3proto_ipv4.c
174 @@ -48,8 +48,8 @@ static bool ipv4_pkt_to_tuple(const stru
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);
185 --- a/include/uapi/linux/icmp.h
186 +++ b/include/uapi/linux/icmp.h
187 @@ -82,7 +82,7 @@ struct icmphdr {
192 +} __attribute__((packed, aligned(2)));
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
203 +} __attribute__((packed, aligned(2)));
204 #endif /* __UAPI_DEF_IN6_ADDR */
206 #if __UAPI_DEF_SOCKADDR_IN6
207 --- a/net/ipv6/tcp_ipv6.c
208 +++ b/net/ipv6/tcp_ipv6.c
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 @@ -819,10 +820,10 @@ static void tcp_v6_send_response(const s
218 topt = (__be32 *)(t1 + 1);
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++);
231 #ifdef CONFIG_TCP_MD5SIG
232 --- a/include/linux/ipv6.h
233 +++ b/include/linux/ipv6.h
236 #define ipv6_optlen(p) (((p)->hdrlen+1) << 3)
237 #define ipv6_authlen(p) (((p)->hdrlen+2) << 2)
240 * This structure contains configuration options per IPv6 link.
242 --- a/net/ipv6/datagram.c
243 +++ b/net/ipv6/datagram.c
244 @@ -485,7 +485,7 @@ int ipv6_recv_error(struct sock *sk, str
245 ipv6_iface_scope_id(&sin->sin6_addr,
248 - ipv6_addr_set_v4mapped(*(__be32 *)(nh + serr->addr_offset),
249 + ipv6_addr_set_v4mapped(net_hdr_word(nh + serr->addr_offset),
251 sin->sin6_scope_id = 0;
253 @@ -836,12 +836,12 @@ int ip6_datagram_send_ctl(struct net *ne
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) {
263 - fl6->flowlabel = IPV6_FLOWINFO_MASK & *(__be32 *)CMSG_DATA(cmsg);
264 + fl6->flowlabel = IPV6_FLOWINFO_MASK & net_hdr_word(CMSG_DATA(cmsg));
267 case IPV6_2292HOPOPTS:
268 --- a/net/ipv6/ip6_gre.c
269 +++ b/net/ipv6/ip6_gre.c
270 @@ -397,7 +397,7 @@ static void ip6gre_err(struct sk_buff *s
272 ipv6h = (const struct ipv6hdr *)skb->data;
273 greh = (const struct gre_base_hdr *)(skb->data + offset);
274 - key = key_off ? *(__be32 *)(skb->data + key_off) : 0;
275 + key = key_off ? net_hdr_word((__be32 *)(skb->data + key_off)) : 0;
277 t = ip6gre_tunnel_lookup(skb->dev, &ipv6h->daddr, &ipv6h->saddr,
278 key, greh->protocol);
279 --- a/net/ipv6/exthdrs.c
280 +++ b/net/ipv6/exthdrs.c
281 @@ -733,7 +733,7 @@ static bool ipv6_hop_jumbo(struct sk_buf
285 - pkt_len = ntohl(*(__be32 *)(nh + optoff + 2));
286 + pkt_len = ntohl(net_hdr_word(nh + optoff + 2));
287 if (pkt_len <= IPV6_MAXPLEN) {
288 __IP6_INC_STATS(net, ipv6_skb_idev(skb),
289 IPSTATS_MIB_INHDRERRORS);
290 --- a/include/linux/types.h
291 +++ b/include/linux/types.h
292 @@ -229,5 +229,11 @@ struct callback_head {
293 typedef void (*rcu_callback_t)(struct rcu_head *head);
294 typedef void (*call_rcu_func_t)(struct rcu_head *head, rcu_callback_t func);
296 +struct net_hdr_word {
298 +} __attribute__((packed, aligned(2)));
300 +#define net_hdr_word(_p) (((struct net_hdr_word *) (_p))->words[0])
302 #endif /* __ASSEMBLY__ */
303 #endif /* _LINUX_TYPES_H */
304 --- a/net/ipv4/af_inet.c
305 +++ b/net/ipv4/af_inet.c
306 @@ -1351,8 +1351,8 @@ struct sk_buff **inet_gro_receive(struct
307 if (unlikely(ip_fast_csum((u8 *)iph, 5)))
310 - id = ntohl(*(__be32 *)&iph->id);
311 - flush = (u16)((ntohl(*(__be32 *)iph) ^ skb_gro_len(skb)) | (id & ~IP_DF));
312 + id = ntohl(net_hdr_word(&iph->id));
313 + flush = (u16)((ntohl(net_hdr_word(iph)) ^ skb_gro_len(skb)) | (id & ~IP_DF));
316 for (p = *head; p; p = p->next) {
317 --- a/net/ipv4/route.c
318 +++ b/net/ipv4/route.c
319 @@ -465,7 +465,7 @@ static struct neighbour *ipv4_neigh_look
321 pkey = &ip_hdr(skb)->daddr;
323 - n = __ipv4_neigh_lookup(dev, *(__force u32 *)pkey);
324 + n = __ipv4_neigh_lookup(dev, net_hdr_word(pkey));
327 return neigh_create(&arp_tbl, pkey, dev);
328 --- a/net/ipv4/tcp_output.c
329 +++ b/net/ipv4/tcp_output.c
330 @@ -454,48 +454,53 @@ static void tcp_options_write(__be32 *pt
331 u16 options = opts->options; /* mungable copy */
333 if (unlikely(OPTION_MD5 & options)) {
334 - *ptr++ = htonl((TCPOPT_NOP << 24) | (TCPOPT_NOP << 16) |
335 - (TCPOPT_MD5SIG << 8) | TCPOLEN_MD5SIG);
336 + net_hdr_word(ptr++) =
337 + htonl((TCPOPT_NOP << 24) | (TCPOPT_NOP << 16) |
338 + (TCPOPT_MD5SIG << 8) | TCPOLEN_MD5SIG);
339 /* overload cookie hash location */
340 opts->hash_location = (__u8 *)ptr;
344 if (unlikely(opts->mss)) {
345 - *ptr++ = htonl((TCPOPT_MSS << 24) |
346 - (TCPOLEN_MSS << 16) |
348 + net_hdr_word(ptr++) =
349 + htonl((TCPOPT_MSS << 24) | (TCPOLEN_MSS << 16) |
353 if (likely(OPTION_TS & options)) {
354 if (unlikely(OPTION_SACK_ADVERTISE & options)) {
355 - *ptr++ = htonl((TCPOPT_SACK_PERM << 24) |
356 - (TCPOLEN_SACK_PERM << 16) |
357 - (TCPOPT_TIMESTAMP << 8) |
358 - TCPOLEN_TIMESTAMP);
359 + net_hdr_word(ptr++) =
360 + htonl((TCPOPT_SACK_PERM << 24) |
361 + (TCPOLEN_SACK_PERM << 16) |
362 + (TCPOPT_TIMESTAMP << 8) |
363 + TCPOLEN_TIMESTAMP);
364 options &= ~OPTION_SACK_ADVERTISE;
366 - *ptr++ = htonl((TCPOPT_NOP << 24) |
367 - (TCPOPT_NOP << 16) |
368 - (TCPOPT_TIMESTAMP << 8) |
369 - TCPOLEN_TIMESTAMP);
370 + net_hdr_word(ptr++) =
371 + htonl((TCPOPT_NOP << 24) |
372 + (TCPOPT_NOP << 16) |
373 + (TCPOPT_TIMESTAMP << 8) |
374 + TCPOLEN_TIMESTAMP);
376 - *ptr++ = htonl(opts->tsval);
377 - *ptr++ = htonl(opts->tsecr);
378 + net_hdr_word(ptr++) = htonl(opts->tsval);
379 + net_hdr_word(ptr++) = htonl(opts->tsecr);
382 if (unlikely(OPTION_SACK_ADVERTISE & options)) {
383 - *ptr++ = htonl((TCPOPT_NOP << 24) |
384 - (TCPOPT_NOP << 16) |
385 - (TCPOPT_SACK_PERM << 8) |
386 - TCPOLEN_SACK_PERM);
387 + net_hdr_word(ptr++) =
388 + htonl((TCPOPT_NOP << 24) |
389 + (TCPOPT_NOP << 16) |
390 + (TCPOPT_SACK_PERM << 8) |
391 + TCPOLEN_SACK_PERM);
394 if (unlikely(OPTION_WSCALE & options)) {
395 - *ptr++ = htonl((TCPOPT_NOP << 24) |
396 - (TCPOPT_WINDOW << 16) |
397 - (TCPOLEN_WINDOW << 8) |
399 + net_hdr_word(ptr++) =
400 + htonl((TCPOPT_NOP << 24) |
401 + (TCPOPT_WINDOW << 16) |
402 + (TCPOLEN_WINDOW << 8) |
406 if (unlikely(opts->num_sack_blocks)) {
407 @@ -503,16 +508,17 @@ static void tcp_options_write(__be32 *pt
408 tp->duplicate_sack : tp->selective_acks;
411 - *ptr++ = htonl((TCPOPT_NOP << 24) |
412 - (TCPOPT_NOP << 16) |
413 - (TCPOPT_SACK << 8) |
414 - (TCPOLEN_SACK_BASE + (opts->num_sack_blocks *
415 + net_hdr_word(ptr++) =
416 + htonl((TCPOPT_NOP << 24) |
417 + (TCPOPT_NOP << 16) |
418 + (TCPOPT_SACK << 8) |
419 + (TCPOLEN_SACK_BASE + (opts->num_sack_blocks *
420 TCPOLEN_SACK_PERBLOCK)));
422 for (this_sack = 0; this_sack < opts->num_sack_blocks;
424 - *ptr++ = htonl(sp[this_sack].start_seq);
425 - *ptr++ = htonl(sp[this_sack].end_seq);
426 + net_hdr_word(ptr++) = htonl(sp[this_sack].start_seq);
427 + net_hdr_word(ptr++) = htonl(sp[this_sack].end_seq);
430 tp->rx_opt.dsack = 0;
431 @@ -525,13 +531,14 @@ static void tcp_options_write(__be32 *pt
434 len = TCPOLEN_EXP_FASTOPEN_BASE + foc->len;
435 - *ptr = htonl((TCPOPT_EXP << 24) | (len << 16) |
436 + net_hdr_word(ptr) =
437 + htonl((TCPOPT_EXP << 24) | (len << 16) |
438 TCPOPT_FASTOPEN_MAGIC);
439 p += TCPOLEN_EXP_FASTOPEN_BASE;
441 len = TCPOLEN_FASTOPEN_BASE + foc->len;
442 - *p++ = TCPOPT_FASTOPEN;
444 + net_hdr_word(p++) = TCPOPT_FASTOPEN;
445 + net_hdr_word(p++) = len;
448 memcpy(p, foc->val, foc->len);
449 --- a/include/uapi/linux/igmp.h
450 +++ b/include/uapi/linux/igmp.h
451 @@ -33,7 +33,7 @@ struct igmphdr {
452 __u8 code; /* For newer IGMP */
456 +} __attribute__((packed, aligned(2)));
458 /* V3 group record types [grec_type] */
459 #define IGMPV3_MODE_IS_INCLUDE 1
460 @@ -49,7 +49,7 @@ struct igmpv3_grec {
465 +} __attribute__((packed, aligned(2)));
467 struct igmpv3_report {
469 @@ -58,7 +58,7 @@ struct igmpv3_report {
472 struct igmpv3_grec grec[0];
474 +} __attribute__((packed, aligned(2)));
476 struct igmpv3_query {
478 @@ -79,7 +79,7 @@ struct igmpv3_query {
483 +} __attribute__((packed, aligned(2)));
485 #define IGMP_HOST_MEMBERSHIP_QUERY 0x11 /* From RFC1112 */
486 #define IGMP_HOST_MEMBERSHIP_REPORT 0x12 /* Ditto */
487 --- a/net/core/flow_dissector.c
488 +++ b/net/core/flow_dissector.c
489 @@ -108,7 +108,7 @@ __be32 __skb_flow_get_ports(const struct
490 ports = __skb_header_pointer(skb, thoff + poff,
491 sizeof(_ports), data, hlen, &_ports);
494 + return (__be32)net_hdr_word(ports);
498 --- a/include/uapi/linux/icmpv6.h
499 +++ b/include/uapi/linux/icmpv6.h
500 @@ -77,7 +77,7 @@ struct icmp6hdr {
501 #define icmp6_addrconf_other icmp6_dataun.u_nd_ra.other
502 #define icmp6_rt_lifetime icmp6_dataun.u_nd_ra.rt_lifetime
503 #define icmp6_router_pref icmp6_dataun.u_nd_ra.router_pref
505 +} __attribute__((packed, aligned(2)));
508 #define ICMPV6_ROUTER_PREF_LOW 0x3
509 --- a/include/net/ndisc.h
510 +++ b/include/net/ndisc.h
511 @@ -89,7 +89,7 @@ struct ra_msg {
512 struct icmp6hdr icmph;
513 __be32 reachable_time;
514 __be32 retrans_timer;
516 +} __attribute__((packed, aligned(2)));
519 struct icmp6hdr icmph;
520 @@ -368,10 +368,10 @@ static inline u32 ndisc_hashfn(const voi
522 const u32 *p32 = pkey;
524 - return (((p32[0] ^ hash32_ptr(dev)) * hash_rnd[0]) +
525 - (p32[1] * hash_rnd[1]) +
526 - (p32[2] * hash_rnd[2]) +
527 - (p32[3] * hash_rnd[3]));
528 + return (((net_hdr_word(&p32[0]) ^ hash32_ptr(dev)) * hash_rnd[0]) +
529 + (net_hdr_word(&p32[1]) * hash_rnd[1]) +
530 + (net_hdr_word(&p32[2]) * hash_rnd[2]) +
531 + (net_hdr_word(&p32[3]) * hash_rnd[3]));
534 static inline struct neighbour *__ipv6_neigh_lookup_noref(struct net_device *dev, const void *pkey)
535 --- a/net/sched/cls_u32.c
536 +++ b/net/sched/cls_u32.c
537 @@ -165,7 +165,7 @@ next_knode:
538 data = skb_header_pointer(skb, toff, 4, &hdata);
541 - if ((*data ^ key->val) & key->mask) {
542 + if ((net_hdr_word(data) ^ key->val) & key->mask) {
543 n = rcu_dereference_bh(n->next);
546 @@ -218,8 +218,8 @@ check_terminal:
550 - sel = ht->divisor & u32_hash_fold(*data, &n->sel,
552 + sel = ht->divisor & u32_hash_fold(net_hdr_word(data),
553 + &n->sel, n->fshift);
555 if (!(n->sel.flags & (TC_U32_VAROFFSET | TC_U32_OFFSET | TC_U32_EAT)))
557 --- a/net/ipv6/ip6_offload.c
558 +++ b/net/ipv6/ip6_offload.c
559 @@ -220,7 +220,7 @@ static struct sk_buff **ipv6_gro_receive
562 iph2 = (struct ipv6hdr *)(p->data + off);
563 - first_word = *(__be32 *)iph ^ *(__be32 *)iph2;
564 + first_word = net_hdr_word(iph) ^ net_hdr_word(iph2);
566 /* All fields must match except length and Traffic Class.
567 * XXX skbs on the gro_list have all been parsed and pulled
568 --- a/include/net/addrconf.h
569 +++ b/include/net/addrconf.h
570 @@ -47,7 +47,7 @@ struct prefix_info {
573 struct in6_addr prefix;
575 +} __attribute__((packed, aligned(2)));
577 #include <linux/netdevice.h>
578 #include <net/if_inet6.h>
579 --- a/include/net/inet_ecn.h
580 +++ b/include/net/inet_ecn.h
581 @@ -125,9 +125,9 @@ static inline int IP6_ECN_set_ce(struct
582 if (INET_ECN_is_not_ect(ipv6_get_dsfield(iph)))
585 - from = *(__be32 *)iph;
586 + from = net_hdr_word(iph);
587 to = from | htonl(INET_ECN_CE << 20);
588 - *(__be32 *)iph = to;
589 + net_hdr_word(iph) = to;
590 if (skb->ip_summed == CHECKSUM_COMPLETE)
591 skb->csum = csum_add(csum_sub(skb->csum, (__force __wsum)from),
593 @@ -136,7 +136,7 @@ static inline int IP6_ECN_set_ce(struct
595 static inline void IP6_ECN_clear(struct ipv6hdr *iph)
597 - *(__be32*)iph &= ~htonl(INET_ECN_MASK << 20);
598 + net_hdr_word(iph) &= ~htonl(INET_ECN_MASK << 20);
601 static inline void ipv6_copy_dscp(unsigned int dscp, struct ipv6hdr *inner)
602 --- a/include/net/ipv6.h
603 +++ b/include/net/ipv6.h
604 @@ -108,7 +108,7 @@ struct frag_hdr {
607 __be32 identification;
609 +} __attribute__((packed, aligned(2)));
611 #define IP6_MF 0x0001
612 #define IP6_OFFSET 0xFFF8
613 @@ -451,8 +451,8 @@ static inline void __ipv6_addr_set_half(
619 + net_hdr_word(&addr[0]) = wh;
620 + net_hdr_word(&addr[1]) = wl;
623 static inline void ipv6_addr_set(struct in6_addr *addr,
624 @@ -511,6 +511,8 @@ static inline bool ipv6_prefix_equal(con
625 const __be32 *a1 = addr1->s6_addr32;
626 const __be32 *a2 = addr2->s6_addr32;
627 unsigned int pdw, pbi;
628 + /* Used for last <32-bit fraction of prefix */
631 /* check complete u32 in prefix */
632 pdw = prefixlen >> 5;
633 @@ -519,7 +521,9 @@ static inline bool ipv6_prefix_equal(con
635 /* check incomplete u32 in prefix */
636 pbi = prefixlen & 0x1f;
637 - if (pbi && ((a1[pdw] ^ a2[pdw]) & htonl((0xffffffff) << (32 - pbi))))
638 + pbia1 = net_hdr_word(&a1[pdw]);
639 + pbia2 = net_hdr_word(&a2[pdw]);
640 + if (pbi && ((pbia1 ^ pbia2) & htonl((0xffffffff) << (32 - pbi))))
644 @@ -663,13 +667,13 @@ static inline void ipv6_addr_set_v4mappe
646 static inline int __ipv6_addr_diff32(const void *token1, const void *token2, int addrlen)
648 - const __be32 *a1 = token1, *a2 = token2;
649 + const struct in6_addr *a1 = token1, *a2 = token2;
654 for (i = 0; i < addrlen; i++) {
655 - __be32 xb = a1[i] ^ a2[i];
656 + __be32 xb = a1->s6_addr32[i] ^ a2->s6_addr32[i];
658 return i * 32 + 31 - __fls(ntohl(xb));
660 @@ -838,17 +842,18 @@ static inline int ip6_default_np_autolab
661 static inline void ip6_flow_hdr(struct ipv6hdr *hdr, unsigned int tclass,
664 - *(__be32 *)hdr = htonl(0x60000000 | (tclass << 20)) | flowlabel;
665 + net_hdr_word((__be32 *)hdr) =
666 + htonl(0x60000000 | (tclass << 20)) | flowlabel;
669 static inline __be32 ip6_flowinfo(const struct ipv6hdr *hdr)
671 - return *(__be32 *)hdr & IPV6_FLOWINFO_MASK;
672 + return net_hdr_word((__be32 *)hdr) & IPV6_FLOWINFO_MASK;
675 static inline __be32 ip6_flowlabel(const struct ipv6hdr *hdr)
677 - return *(__be32 *)hdr & IPV6_FLOWLABEL_MASK;
678 + return net_hdr_word((__be32 *)hdr) & IPV6_FLOWLABEL_MASK;
681 static inline u8 ip6_tclass(__be32 flowinfo)
682 --- a/include/net/secure_seq.h
683 +++ b/include/net/secure_seq.h
685 #define _NET_SECURE_SEQ
687 #include <linux/types.h>
688 +#include <linux/in6.h>
690 u32 secure_ipv4_port_ephemeral(__be32 saddr, __be32 daddr, __be16 dport);
691 u32 secure_ipv6_port_ephemeral(const __be32 *saddr, const __be32 *daddr,
692 --- a/include/uapi/linux/in.h
693 +++ b/include/uapi/linux/in.h
694 @@ -84,7 +84,7 @@ enum {
695 /* Internet address. */
699 +} __attribute__((packed, aligned(2)));
703 --- a/net/ipv6/ip6_fib.c
704 +++ b/net/ipv6/ip6_fib.c
705 @@ -137,7 +137,7 @@ static __be32 addr_bit_set(const void *t
706 * See include/asm-generic/bitops/le.h.
708 return (__force __be32)(1 << ((~fn_bit ^ BITOP_BE32_SWIZZLE) & 0x1f)) &
710 + net_hdr_word(&addr[fn_bit >> 5]);
713 static struct fib6_node *node_alloc(void)
714 --- a/net/netfilter/nf_conntrack_proto_tcp.c
715 +++ b/net/netfilter/nf_conntrack_proto_tcp.c
716 @@ -447,7 +447,7 @@ static void tcp_sack(const struct sk_buf
718 /* Fast path for timestamp-only option */
719 if (length == TCPOLEN_TSTAMP_ALIGNED
720 - && *(__be32 *)ptr == htonl((TCPOPT_NOP << 24)
721 + && net_hdr_word(ptr) == htonl((TCPOPT_NOP << 24)
723 | (TCPOPT_TIMESTAMP << 8)
724 | TCPOLEN_TIMESTAMP))
725 --- a/net/xfrm/xfrm_input.c
726 +++ b/net/xfrm/xfrm_input.c
727 @@ -193,8 +193,8 @@ int xfrm_parse_spi(struct sk_buff *skb,
728 if (!pskb_may_pull(skb, hlen))
731 - *spi = *(__be32 *)(skb_transport_header(skb) + offset);
732 - *seq = *(__be32 *)(skb_transport_header(skb) + offset_seq);
733 + *spi = net_hdr_word(skb_transport_header(skb) + offset);
734 + *seq = net_hdr_word(skb_transport_header(skb) + offset_seq);
737 EXPORT_SYMBOL(xfrm_parse_spi);
738 --- a/net/ipv4/tcp_input.c
739 +++ b/net/ipv4/tcp_input.c
740 @@ -3858,14 +3858,16 @@ static bool tcp_parse_aligned_timestamp(
742 const __be32 *ptr = (const __be32 *)(th + 1);
744 - if (*ptr == htonl((TCPOPT_NOP << 24) | (TCPOPT_NOP << 16)
745 - | (TCPOPT_TIMESTAMP << 8) | TCPOLEN_TIMESTAMP)) {
746 + if (net_hdr_word(ptr) ==
747 + htonl((TCPOPT_NOP << 24) | (TCPOPT_NOP << 16) |
748 + (TCPOPT_TIMESTAMP << 8) | TCPOLEN_TIMESTAMP)) {
749 tp->rx_opt.saw_tstamp = 1;
751 - tp->rx_opt.rcv_tsval = ntohl(*ptr);
752 + tp->rx_opt.rcv_tsval = get_unaligned_be32(ptr);
755 - tp->rx_opt.rcv_tsecr = ntohl(*ptr) - tp->tsoffset;
756 + if (net_hdr_word(ptr))
757 + tp->rx_opt.rcv_tsecr = get_unaligned_be32(ptr) -
760 tp->rx_opt.rcv_tsecr = 0;
762 --- a/include/uapi/linux/if_pppox.h
763 +++ b/include/uapi/linux/if_pppox.h
764 @@ -51,6 +51,7 @@ struct pppoe_addr {
769 struct in_addr sin_addr;
772 --- a/net/ipv6/netfilter/nf_log_ipv6.c
773 +++ b/net/ipv6/netfilter/nf_log_ipv6.c
774 @@ -66,9 +66,9 @@ static void dump_ipv6_packet(struct nf_l
775 /* Max length: 44 "LEN=65535 TC=255 HOPLIMIT=255 FLOWLBL=FFFFF " */
776 nf_log_buf_add(m, "LEN=%zu TC=%u HOPLIMIT=%u FLOWLBL=%u ",
777 ntohs(ih->payload_len) + sizeof(struct ipv6hdr),
778 - (ntohl(*(__be32 *)ih) & 0x0ff00000) >> 20,
779 + (ntohl(net_hdr_word(ih)) & 0x0ff00000) >> 20,
781 - (ntohl(*(__be32 *)ih) & 0x000fffff));
782 + (ntohl(net_hdr_word(ih)) & 0x000fffff));
785 ptr = ip6hoff + sizeof(struct ipv6hdr);
786 --- a/include/net/neighbour.h
787 +++ b/include/net/neighbour.h
788 @@ -265,8 +265,10 @@ static inline bool neigh_key_eq128(const
789 const u32 *n32 = (const u32 *)n->primary_key;
790 const u32 *p32 = pkey;
792 - return ((n32[0] ^ p32[0]) | (n32[1] ^ p32[1]) |
793 - (n32[2] ^ p32[2]) | (n32[3] ^ p32[3])) == 0;
794 + return ((n32[0] ^ net_hdr_word(&p32[0])) |
795 + (n32[1] ^ net_hdr_word(&p32[1])) |
796 + (n32[2] ^ net_hdr_word(&p32[2])) |
797 + (n32[3] ^ net_hdr_word(&p32[3]))) == 0;
800 static inline struct neighbour *___neigh_lookup_noref(
801 --- a/include/uapi/linux/netfilter_arp/arp_tables.h
802 +++ b/include/uapi/linux/netfilter_arp/arp_tables.h
803 @@ -70,7 +70,7 @@ struct arpt_arp {
808 +} __attribute__((aligned(4)));
810 /* Values for "flag" field in struct arpt_ip (general arp structure).
811 * No flags defined yet.
812 --- a/net/core/utils.c
813 +++ b/net/core/utils.c
814 @@ -424,8 +424,14 @@ void inet_proto_csum_replace16(__sum16 *
818 - ~from[0], ~from[1], ~from[2], ~from[3],
819 - to[0], to[1], to[2], to[3],
820 + ~net_hdr_word(&from[0]),
821 + ~net_hdr_word(&from[1]),
822 + ~net_hdr_word(&from[2]),
823 + ~net_hdr_word(&from[3]),
824 + net_hdr_word(&to[0]),
825 + net_hdr_word(&to[1]),
826 + net_hdr_word(&to[2]),
827 + net_hdr_word(&to[3]),
829 if (skb->ip_summed != CHECKSUM_PARTIAL) {
830 *sum = csum_fold(csum_partial(diff, sizeof(diff),
831 --- a/include/linux/etherdevice.h
832 +++ b/include/linux/etherdevice.h
833 @@ -480,7 +480,7 @@ static inline bool is_etherdev_addr(cons
834 * @b: Pointer to Ethernet header
836 * Compare two Ethernet headers, returns 0 if equal.
837 - * This assumes that the network header (i.e., IP header) is 4-byte
838 + * This assumes that the network header (i.e., IP header) is 2-byte
839 * aligned OR the platform can handle unaligned access. This is the
840 * case for all packets coming into netif_receive_skb or similar
842 @@ -503,11 +503,12 @@ static inline unsigned long compare_ethe
843 fold |= *(unsigned long *)(a + 6) ^ *(unsigned long *)(b + 6);
846 - u32 *a32 = (u32 *)((u8 *)a + 2);
847 - u32 *b32 = (u32 *)((u8 *)b + 2);
848 + const u16 *a16 = a;
849 + const u16 *b16 = b;
851 - return (*(u16 *)a ^ *(u16 *)b) | (a32[0] ^ b32[0]) |
852 - (a32[1] ^ b32[1]) | (a32[2] ^ b32[2]);
853 + return (a16[0] ^ b16[0]) | (a16[1] ^ b16[1]) | (a16[2] ^ b16[2]) |
854 + (a16[3] ^ b16[3]) | (a16[4] ^ b16[4]) | (a16[5] ^ b16[5]) |
859 --- a/net/ipv4/tcp_offload.c
860 +++ b/net/ipv4/tcp_offload.c
861 @@ -226,7 +226,7 @@ struct sk_buff **tcp_gro_receive(struct
865 - if (*(u32 *)&th->source ^ *(u32 *)&th2->source) {
866 + if (net_hdr_word(&th->source) ^ net_hdr_word(&th2->source)) {
867 NAPI_GRO_CB(p)->same_flow = 0;
870 @@ -244,8 +244,8 @@ found:
871 ~(TCP_FLAG_CWR | TCP_FLAG_FIN | TCP_FLAG_PSH));
872 flush |= (__force int)(th->ack_seq ^ th2->ack_seq);
873 for (i = sizeof(*th); i < thlen; i += 4)
874 - flush |= *(u32 *)((u8 *)th + i) ^
875 - *(u32 *)((u8 *)th2 + i);
876 + flush |= net_hdr_word((u8 *)th + i) ^
877 + net_hdr_word((u8 *)th2 + i);
879 /* When we receive our second frame we can made a decision on if we
880 * continue this flow as an atomic flow with a fixed ID or if we use
881 --- a/net/ipv6/netfilter/ip6table_mangle.c
882 +++ b/net/ipv6/netfilter/ip6table_mangle.c
883 @@ -50,7 +50,7 @@ ip6t_mangle_out(struct sk_buff *skb, con
884 hop_limit = ipv6_hdr(skb)->hop_limit;
886 /* flowlabel and prio (includes version, which shouldn't change either */
887 - flowlabel = *((u_int32_t *)ipv6_hdr(skb));
888 + flowlabel = net_hdr_word(ipv6_hdr(skb));
890 ret = ip6t_do_table(skb, state, state->net->ipv6.ip6table_mangle);
892 @@ -59,7 +59,7 @@ ip6t_mangle_out(struct sk_buff *skb, con
893 !ipv6_addr_equal(&ipv6_hdr(skb)->daddr, &daddr) ||
895 ipv6_hdr(skb)->hop_limit != hop_limit ||
896 - flowlabel != *((u_int32_t *)ipv6_hdr(skb)))) {
897 + flowlabel != net_hdr_word(ipv6_hdr(skb)))) {
898 err = ip6_route_me_harder(state->net, skb);
900 ret = NF_DROP_ERR(err);