1 --- a/arch/mips/include/asm/checksum.h
2 +++ b/arch/mips/include/asm/checksum.h
3 @@ -104,26 +104,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 @@ -192,69 +196,4 @@ 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, unsigned short proto,
56 - " .set push # csum_ipv6_magic\n"
57 - " .set noreorder \n"
59 - " addu %0, %5 # proto (long in network byte order)\n"
60 - " sltu $1, %0, %5 \n"
63 - " addu %0, %6 # csum\n"
64 - " sltu $1, %0, %6 \n"
65 - " lw %1, 0(%2) # four words source address\n"
68 - " sltu $1, %0, %1 \n"
73 - " sltu $1, %0, %1 \n"
78 - " sltu $1, %0, %1 \n"
83 - " sltu $1, %0, %1 \n"
88 - " sltu $1, %0, %1 \n"
93 - " sltu $1, %0, %1 \n"
98 - " sltu $1, %0, %1 \n"
100 - " lw %1, 12(%3) \n"
103 - " sltu $1, %0, %1 \n"
105 - " addu %0, $1 # Add final carry\n"
107 - : "=r" (sum), "=r" (proto)
108 - : "r" (saddr), "r" (daddr),
109 - "0" (htonl(len)), "1" (htonl(proto)), "r" (sum));
111 - return csum_fold(sum);
114 #endif /* _ASM_CHECKSUM_H */
115 --- a/include/uapi/linux/ip.h
116 +++ b/include/uapi/linux/ip.h
117 @@ -102,7 +102,7 @@ struct iphdr {
120 /*The options start here. */
122 +} __attribute__((packed, aligned(2)));
126 --- a/include/uapi/linux/ipv6.h
127 +++ b/include/uapi/linux/ipv6.h
128 @@ -123,7 +123,7 @@ struct ipv6hdr {
130 struct in6_addr saddr;
131 struct in6_addr daddr;
133 +} __attribute__((packed, aligned(2)));
136 /* index values for the variables in ipv6_devconf */
137 --- a/include/uapi/linux/tcp.h
138 +++ b/include/uapi/linux/tcp.h
139 @@ -54,7 +54,7 @@ struct tcphdr {
144 +} __attribute__((packed, aligned(2)));
147 * The union cast uses a gcc extension to avoid aliasing problems
148 @@ -64,7 +64,7 @@ struct tcphdr {
153 +} __attribute__((packed, aligned(2)));
155 #define tcp_flag_word(tp) ( ((union tcp_word_hdr *)(tp))->words [3])
157 --- a/include/uapi/linux/udp.h
158 +++ b/include/uapi/linux/udp.h
159 @@ -24,7 +24,7 @@ struct udphdr {
164 +} __attribute__((packed, aligned(2)));
166 /* UDP socket options */
167 #define UDP_CORK 1 /* Never send partially complete segments */
168 --- a/net/ipv4/netfilter/nf_conntrack_l3proto_ipv4.c
169 +++ b/net/ipv4/netfilter/nf_conntrack_l3proto_ipv4.c
170 @@ -39,8 +39,8 @@ static bool ipv4_pkt_to_tuple(const stru
174 - tuple->src.u3.ip = ap[0];
175 - tuple->dst.u3.ip = ap[1];
176 + tuple->src.u3.ip = net_hdr_word(ap++);
177 + tuple->dst.u3.ip = net_hdr_word(ap);
181 --- a/include/uapi/linux/icmp.h
182 +++ b/include/uapi/linux/icmp.h
183 @@ -80,7 +80,7 @@ struct icmphdr {
188 +} __attribute__((packed, aligned(2)));
192 --- a/net/ipv4/tcp_input.c
193 +++ b/net/ipv4/tcp_input.c
194 @@ -3868,13 +3868,14 @@ static bool tcp_parse_aligned_timestamp(
196 const __be32 *ptr = (const __be32 *)(th + 1);
198 - if (*ptr == htonl((TCPOPT_NOP << 24) | (TCPOPT_NOP << 16)
199 - | (TCPOPT_TIMESTAMP << 8) | TCPOLEN_TIMESTAMP)) {
200 + if (net_hdr_word(ptr) ==
201 + htonl((TCPOPT_NOP << 24) | (TCPOPT_NOP << 16) |
202 + (TCPOPT_TIMESTAMP << 8) | TCPOLEN_TIMESTAMP)) {
203 tp->rx_opt.saw_tstamp = 1;
205 - tp->rx_opt.rcv_tsval = ntohl(*ptr);
206 + tp->rx_opt.rcv_tsval = get_unaligned_be32(ptr);
208 - tp->rx_opt.rcv_tsecr = ntohl(*ptr);
209 + tp->rx_opt.rcv_tsecr = get_unaligned_be32(ptr);
213 --- a/include/uapi/linux/in6.h
214 +++ b/include/uapi/linux/in6.h
215 @@ -36,7 +36,7 @@ struct in6_addr {
216 #define s6_addr in6_u.u6_addr8
217 #define s6_addr16 in6_u.u6_addr16
218 #define s6_addr32 in6_u.u6_addr32
220 +} __attribute__((packed, aligned(2)));
222 /* IPv6 Wildcard Address (::) and Loopback Address (::1) defined in RFC2553
223 * NOTE: Be aware the IN6ADDR_* constants and in6addr_* externals are defined
224 --- a/net/ipv6/af_inet6.c
225 +++ b/net/ipv6/af_inet6.c
229 #include <asm/uaccess.h>
230 +#include <asm/unaligned.h>
231 #include <linux/mroute6.h>
233 MODULE_AUTHOR("Cast of dozens");
234 @@ -688,7 +689,7 @@ bool ipv6_opt_accepted(const struct sock
235 if ((opt->hop && (np->rxopt.bits.hopopts ||
236 np->rxopt.bits.ohopopts)) ||
237 ((IPV6_FLOWINFO_MASK &
238 - *(__be32 *)skb_network_header(skb)) &&
239 + net_hdr_word(skb_network_header(skb))) &&
240 np->rxopt.bits.rxflow) ||
241 (opt->srcrt && (np->rxopt.bits.srcrt ||
242 np->rxopt.bits.osrcrt)) ||
243 --- a/net/ipv6/route.c
244 +++ b/net/ipv6/route.c
245 @@ -995,7 +995,7 @@ void ip6_route_input(struct sk_buff *skb
246 .flowi6_iif = skb->dev->ifindex,
249 - .flowlabel = (* (__be32 *) iph) & IPV6_FLOWINFO_MASK,
250 + .flowlabel = net_hdr_word(iph) & IPV6_FLOWINFO_MASK,
251 .flowi6_mark = skb->mark,
252 .flowi6_proto = iph->nexthdr,
254 @@ -1159,7 +1159,7 @@ void ip6_update_pmtu(struct sk_buff *skb
255 fl6.flowi6_flags = 0;
256 fl6.daddr = iph->daddr;
257 fl6.saddr = iph->saddr;
258 - fl6.flowlabel = (*(__be32 *) iph) & IPV6_FLOWINFO_MASK;
259 + fl6.flowlabel = net_hdr_word(iph) & IPV6_FLOWINFO_MASK,
261 dst = ip6_route_output(net, NULL, &fl6);
263 @@ -1187,7 +1187,7 @@ void ip6_redirect(struct sk_buff *skb, s
264 fl6.flowi6_flags = 0;
265 fl6.daddr = iph->daddr;
266 fl6.saddr = iph->saddr;
267 - fl6.flowlabel = (*(__be32 *) iph) & IPV6_FLOWINFO_MASK;
268 + fl6.flowlabel = net_hdr_word(iph) & IPV6_FLOWINFO_MASK,
270 dst = ip6_route_output(net, NULL, &fl6);
272 --- a/net/ipv6/tcp_ipv6.c
273 +++ b/net/ipv6/tcp_ipv6.c
275 #include <net/secure_seq.h>
276 #include <net/tcp_memcontrol.h>
278 +#include <asm/unaligned.h>
279 #include <asm/uaccess.h>
281 #include <linux/proc_fs.h>
282 @@ -763,10 +764,10 @@ static void tcp_v6_send_response(struct
283 topt = (__be32 *)(t1 + 1);
286 - *topt++ = htonl((TCPOPT_NOP << 24) | (TCPOPT_NOP << 16) |
287 - (TCPOPT_TIMESTAMP << 8) | TCPOLEN_TIMESTAMP);
288 - *topt++ = htonl(tcp_time_stamp);
289 - *topt++ = htonl(ts);
290 + put_unaligned_be32((TCPOPT_NOP << 24) | (TCPOPT_NOP << 16) |
291 + (TCPOPT_TIMESTAMP << 8) | TCPOLEN_TIMESTAMP, topt++);
292 + put_unaligned_be32(tcp_time_stamp, topt++);
293 + put_unaligned_be32(ts, topt++);
296 #ifdef CONFIG_TCP_MD5SIG
297 --- a/include/linux/ipv6.h
298 +++ b/include/linux/ipv6.h
300 #include <uapi/linux/ipv6.h>
302 #define ipv6_optlen(p) (((p)->hdrlen+1) << 3)
305 * This structure contains configuration options per IPv6 link.
307 @@ -79,7 +80,7 @@ static inline struct ipv6hdr *ipipv6_hdr
309 static inline __u8 ipv6_tclass(const struct ipv6hdr *iph)
311 - return (ntohl(*(__be32 *)iph) >> 20) & 0xff;
312 + return (ntohl(net_hdr_word(iph)) >> 20) & 0xff;
316 --- a/net/ipv6/datagram.c
317 +++ b/net/ipv6/datagram.c
318 @@ -360,12 +360,12 @@ int ipv6_recv_error(struct sock *sk, str
319 *(struct in6_addr *)(nh + serr->addr_offset);
322 - (*(__be32 *)(nh + serr->addr_offset - 24) &
323 - IPV6_FLOWINFO_MASK);
324 + net_hdr_word(nh + serr->addr_offset - 24) &
325 + IPV6_FLOWINFO_MASK;
326 if (ipv6_addr_type(&sin->sin6_addr) & IPV6_ADDR_LINKLOCAL)
327 sin->sin6_scope_id = IP6CB(skb)->iif;
329 - ipv6_addr_set_v4mapped(*(__be32 *)(nh + serr->addr_offset),
330 + ipv6_addr_set_v4mapped(net_hdr_word(nh + serr->addr_offset),
334 @@ -493,9 +493,10 @@ int ip6_datagram_recv_ctl(struct sock *s
335 put_cmsg(msg, SOL_IPV6, IPV6_TCLASS, sizeof(tclass), &tclass);
338 - if (np->rxopt.bits.rxflow && (*(__be32 *)nh & IPV6_FLOWINFO_MASK)) {
339 - __be32 flowinfo = *(__be32 *)nh & IPV6_FLOWINFO_MASK;
340 - put_cmsg(msg, SOL_IPV6, IPV6_FLOWINFO, sizeof(flowinfo), &flowinfo);
341 + if (np->rxopt.bits.rxflow) {
342 + __be32 flowinfo = net_hdr_word(nh) & IPV6_FLOWINFO_MASK;
344 + put_cmsg(msg, SOL_IPV6, IPV6_FLOWINFO, sizeof(flowinfo), &flowinfo);
347 /* HbH is allowed only once */
348 @@ -682,12 +683,12 @@ int ip6_datagram_send_ctl(struct net *ne
351 if (fl6->flowlabel&IPV6_FLOWINFO_MASK) {
352 - if ((fl6->flowlabel^*(__be32 *)CMSG_DATA(cmsg))&~IPV6_FLOWINFO_MASK) {
353 + if ((fl6->flowlabel^net_hdr_word(CMSG_DATA(cmsg)))&~IPV6_FLOWINFO_MASK) {
358 - fl6->flowlabel = IPV6_FLOWINFO_MASK & *(__be32 *)CMSG_DATA(cmsg);
359 + fl6->flowlabel = IPV6_FLOWINFO_MASK & net_hdr_word(CMSG_DATA(cmsg));
362 case IPV6_2292HOPOPTS:
363 --- a/net/ipv6/ip6_gre.c
364 +++ b/net/ipv6/ip6_gre.c
365 @@ -430,7 +430,7 @@ static void ip6gre_err(struct sk_buff *s
367 t = ip6gre_tunnel_lookup(skb->dev, &ipv6h->daddr, &ipv6h->saddr,
369 - *(((__be32 *)p) + (grehlen / 4) - 1) : 0,
370 + net_hdr_word(((__be32 *)p) + (grehlen / 4) - 1) : 0,
374 @@ -522,11 +522,11 @@ static int ip6gre_rcv(struct sk_buff *sk
378 - key = *(__be32 *)(h + offset);
379 + key = net_hdr_word(h + offset);
383 - seqno = ntohl(*(__be32 *)(h + offset));
384 + seqno = ntohl(net_hdr_word(h + offset));
388 @@ -772,7 +772,7 @@ static netdev_tx_t ip6gre_xmit2(struct s
389 * Push down and install the IP header.
391 ipv6h = ipv6_hdr(skb);
392 - *(__be32 *)ipv6h = fl6->flowlabel | htonl(0x60000000);
393 + net_hdr_word(ipv6h) = fl6->flowlabel | htonl(0x60000000);
394 dsfield = INET_ECN_encapsulate(0, dsfield);
395 ipv6_change_dsfield(ipv6h, ~INET_ECN_MASK, dsfield);
396 ipv6h->hop_limit = tunnel->parms.hop_limit;
397 @@ -789,7 +789,7 @@ static netdev_tx_t ip6gre_xmit2(struct s
399 if (tunnel->parms.o_flags&GRE_SEQ) {
401 - *ptr = htonl(tunnel->o_seqno);
402 + net_hdr_word(ptr) = htonl(tunnel->o_seqno);
405 if (tunnel->parms.o_flags&GRE_KEY) {
406 @@ -897,9 +897,9 @@ static inline int ip6gre_xmit_ipv6(struc
408 dsfield = ipv6_get_dsfield(ipv6h);
409 if (t->parms.flags & IP6_TNL_F_USE_ORIG_TCLASS)
410 - fl6.flowlabel |= (*(__be32 *) ipv6h & IPV6_TCLASS_MASK);
411 + fl6.flowlabel |= net_hdr_word(ipv6h) & IPV6_TCLASS_MASK;
412 if (t->parms.flags & IP6_TNL_F_USE_ORIG_FLOWLABEL)
413 - fl6.flowlabel |= (*(__be32 *) ipv6h & IPV6_FLOWLABEL_MASK);
414 + fl6.flowlabel |= net_hdr_word(ipv6h) & IPV6_FLOWLABEL_MASK;
415 if (t->parms.flags & IP6_TNL_F_USE_ORIG_FWMARK)
416 fl6.flowi6_mark = skb->mark;
418 @@ -1240,7 +1240,7 @@ static int ip6gre_header(struct sk_buff
419 struct ipv6hdr *ipv6h = (struct ipv6hdr *)skb_push(skb, t->hlen);
420 __be16 *p = (__be16 *)(ipv6h+1);
422 - *(__be32 *)ipv6h = t->fl.u.ip6.flowlabel | htonl(0x60000000);
423 + net_hdr_word(ipv6h) = t->fl.u.ip6.flowlabel | htonl(0x60000000);
424 ipv6h->hop_limit = t->parms.hop_limit;
425 ipv6h->nexthdr = NEXTHDR_GRE;
426 ipv6h->saddr = t->parms.laddr;
427 --- a/net/ipv6/ip6_output.c
428 +++ b/net/ipv6/ip6_output.c
429 @@ -216,7 +216,7 @@ int ip6_xmit(struct sock *sk, struct sk_
431 hlimit = ip6_dst_hoplimit(dst);
433 - *(__be32 *)hdr = htonl(0x60000000 | (tclass << 20)) | fl6->flowlabel;
434 + net_hdr_word(hdr) = htonl(0x60000000 | (tclass << 20)) | fl6->flowlabel;
436 hdr->payload_len = htons(seg_len);
437 hdr->nexthdr = proto;
438 --- a/net/ipv6/ip6_tunnel.c
439 +++ b/net/ipv6/ip6_tunnel.c
440 @@ -1136,9 +1136,9 @@ ip6ip6_tnl_xmit(struct sk_buff *skb, str
442 dsfield = ipv6_get_dsfield(ipv6h);
443 if (t->parms.flags & IP6_TNL_F_USE_ORIG_TCLASS)
444 - fl6.flowlabel |= (*(__be32 *) ipv6h & IPV6_TCLASS_MASK);
445 + fl6.flowlabel |= net_hdr_word(ipv6h) & IPV6_TCLASS_MASK;
446 if (t->parms.flags & IP6_TNL_F_USE_ORIG_FLOWLABEL)
447 - fl6.flowlabel |= (*(__be32 *) ipv6h & IPV6_FLOWLABEL_MASK);
448 + fl6.flowlabel |= net_hdr_word(ipv6h) & IPV6_FLOWLABEL_MASK;
449 if (t->parms.flags & IP6_TNL_F_USE_ORIG_FWMARK)
450 fl6.flowi6_mark = skb->mark;
452 --- a/net/ipv6/exthdrs.c
453 +++ b/net/ipv6/exthdrs.c
454 @@ -578,7 +578,7 @@ static bool ipv6_hop_jumbo(struct sk_buf
458 - pkt_len = ntohl(*(__be32 *)(nh + optoff + 2));
459 + pkt_len = ntohl(net_hdr_word(nh + optoff + 2));
460 if (pkt_len <= IPV6_MAXPLEN) {
461 IP6_INC_STATS_BH(net, ipv6_skb_idev(skb),
462 IPSTATS_MIB_INHDRERRORS);
463 --- a/include/linux/types.h
464 +++ b/include/linux/types.h
465 @@ -212,5 +212,11 @@ struct callback_head {
467 #define rcu_head callback_head
469 +struct net_hdr_word {
471 +} __attribute__((packed, aligned(2)));
473 +#define net_hdr_word(_p) (((struct net_hdr_word *) (_p))->words[0])
475 #endif /* __ASSEMBLY__ */
476 #endif /* _LINUX_TYPES_H */
477 --- a/net/ipv4/af_inet.c
478 +++ b/net/ipv4/af_inet.c
479 @@ -1396,8 +1396,8 @@ static struct sk_buff **inet_gro_receive
480 if (unlikely(ip_fast_csum((u8 *)iph, 5)))
483 - id = ntohl(*(__be32 *)&iph->id);
484 - flush = (u16)((ntohl(*(__be32 *)iph) ^ skb_gro_len(skb)) | (id ^ IP_DF));
485 + id = ntohl(net_hdr_word(&iph->id));
486 + flush = (u16)((ntohl(net_hdr_word(iph)) ^ skb_gro_len(skb)) | (id ^ IP_DF));
489 for (p = *head; p; p = p->next) {
490 --- a/net/ipv4/route.c
491 +++ b/net/ipv4/route.c
492 @@ -465,7 +465,7 @@ static struct neighbour *ipv4_neigh_look
494 pkey = &ip_hdr(skb)->daddr;
496 - n = __ipv4_neigh_lookup(dev, *(__force u32 *)pkey);
497 + n = __ipv4_neigh_lookup(dev, net_hdr_word(pkey));
500 return neigh_create(&arp_tbl, pkey, dev);
501 --- a/net/ipv4/tcp_output.c
502 +++ b/net/ipv4/tcp_output.c
503 @@ -456,15 +456,17 @@ static void tcp_options_write(__be32 *pt
505 if (unlikely(OPTION_MD5 & options)) {
506 if (unlikely(OPTION_COOKIE_EXTENSION & options)) {
507 - *ptr++ = htonl((TCPOPT_COOKIE << 24) |
508 - (TCPOLEN_COOKIE_BASE << 16) |
509 - (TCPOPT_MD5SIG << 8) |
511 + net_hdr_word(ptr++) =
512 + htonl((TCPOPT_COOKIE << 24) |
513 + (TCPOLEN_COOKIE_BASE << 16) |
514 + (TCPOPT_MD5SIG << 8) |
517 - *ptr++ = htonl((TCPOPT_NOP << 24) |
518 - (TCPOPT_NOP << 16) |
519 - (TCPOPT_MD5SIG << 8) |
521 + net_hdr_word(ptr++) =
522 + htonl((TCPOPT_NOP << 24) |
523 + (TCPOPT_NOP << 16) |
524 + (TCPOPT_MD5SIG << 8) |
527 options &= ~OPTION_COOKIE_EXTENSION;
528 /* overload cookie hash location */
529 @@ -473,26 +475,28 @@ static void tcp_options_write(__be32 *pt
532 if (unlikely(opts->mss)) {
533 - *ptr++ = htonl((TCPOPT_MSS << 24) |
534 - (TCPOLEN_MSS << 16) |
536 + net_hdr_word(ptr++) =
537 + htonl((TCPOPT_MSS << 24) | (TCPOLEN_MSS << 16) |
541 if (likely(OPTION_TS & options)) {
542 if (unlikely(OPTION_SACK_ADVERTISE & options)) {
543 - *ptr++ = htonl((TCPOPT_SACK_PERM << 24) |
544 - (TCPOLEN_SACK_PERM << 16) |
545 - (TCPOPT_TIMESTAMP << 8) |
546 - TCPOLEN_TIMESTAMP);
547 + net_hdr_word(ptr++) =
548 + htonl((TCPOPT_SACK_PERM << 24) |
549 + (TCPOLEN_SACK_PERM << 16) |
550 + (TCPOPT_TIMESTAMP << 8) |
551 + TCPOLEN_TIMESTAMP);
552 options &= ~OPTION_SACK_ADVERTISE;
554 - *ptr++ = htonl((TCPOPT_NOP << 24) |
555 - (TCPOPT_NOP << 16) |
556 - (TCPOPT_TIMESTAMP << 8) |
557 - TCPOLEN_TIMESTAMP);
558 + net_hdr_word(ptr++) =
559 + htonl((TCPOPT_NOP << 24) |
560 + (TCPOPT_NOP << 16) |
561 + (TCPOPT_TIMESTAMP << 8) |
562 + TCPOLEN_TIMESTAMP);
564 - *ptr++ = htonl(opts->tsval);
565 - *ptr++ = htonl(opts->tsecr);
566 + net_hdr_word(ptr++) = htonl(opts->tsval);
567 + net_hdr_word(ptr++) = htonl(opts->tsecr);
570 /* Specification requires after timestamp, so do it now.
571 @@ -512,19 +516,20 @@ static void tcp_options_write(__be32 *pt
572 __u8 *p = (__u8 *)ptr;
574 /* 16-bit multiple */
575 - *p++ = TCPOPT_COOKIE;
576 - *p++ = TCPOLEN_COOKIE_BASE + cookie_size;
577 - *p++ = *cookie_copy++;
578 - *p++ = *cookie_copy++;
579 + net_hdr_word(p++) = TCPOPT_COOKIE;
580 + net_hdr_word(p++) = TCPOLEN_COOKIE_BASE + cookie_size;
581 + net_hdr_word(p++) = *cookie_copy++;
582 + net_hdr_word(p++) = *cookie_copy++;
586 /* 32-bit multiple */
587 - *ptr++ = htonl(((TCPOPT_NOP << 24) |
588 - (TCPOPT_NOP << 16) |
589 - (TCPOPT_COOKIE << 8) |
590 - TCPOLEN_COOKIE_BASE) +
592 + net_hdr_word(ptr++) =
593 + htonl(((TCPOPT_NOP << 24) |
594 + (TCPOPT_NOP << 16) |
595 + (TCPOPT_COOKIE << 8) |
596 + TCPOLEN_COOKIE_BASE) +
600 if (cookie_size > 0) {
601 @@ -534,17 +539,19 @@ static void tcp_options_write(__be32 *pt
604 if (unlikely(OPTION_SACK_ADVERTISE & options)) {
605 - *ptr++ = htonl((TCPOPT_NOP << 24) |
606 - (TCPOPT_NOP << 16) |
607 - (TCPOPT_SACK_PERM << 8) |
608 - TCPOLEN_SACK_PERM);
609 + net_hdr_word(ptr++) =
610 + htonl((TCPOPT_NOP << 24) |
611 + (TCPOPT_NOP << 16) |
612 + (TCPOPT_SACK_PERM << 8) |
613 + TCPOLEN_SACK_PERM);
616 if (unlikely(OPTION_WSCALE & options)) {
617 - *ptr++ = htonl((TCPOPT_NOP << 24) |
618 - (TCPOPT_WINDOW << 16) |
619 - (TCPOLEN_WINDOW << 8) |
621 + net_hdr_word(ptr++) =
622 + htonl((TCPOPT_NOP << 24) |
623 + (TCPOPT_WINDOW << 16) |
624 + (TCPOLEN_WINDOW << 8) |
628 if (unlikely(opts->num_sack_blocks)) {
629 @@ -552,16 +559,17 @@ static void tcp_options_write(__be32 *pt
630 tp->duplicate_sack : tp->selective_acks;
633 - *ptr++ = htonl((TCPOPT_NOP << 24) |
634 - (TCPOPT_NOP << 16) |
635 - (TCPOPT_SACK << 8) |
636 - (TCPOLEN_SACK_BASE + (opts->num_sack_blocks *
637 + net_hdr_word(ptr++) =
638 + htonl((TCPOPT_NOP << 24) |
639 + (TCPOPT_NOP << 16) |
640 + (TCPOPT_SACK << 8) |
641 + (TCPOLEN_SACK_BASE + (opts->num_sack_blocks *
642 TCPOLEN_SACK_PERBLOCK)));
644 for (this_sack = 0; this_sack < opts->num_sack_blocks;
646 - *ptr++ = htonl(sp[this_sack].start_seq);
647 - *ptr++ = htonl(sp[this_sack].end_seq);
648 + net_hdr_word(ptr++) = htonl(sp[this_sack].start_seq);
649 + net_hdr_word(ptr++) = htonl(sp[this_sack].end_seq);
652 tp->rx_opt.dsack = 0;
653 @@ -570,9 +578,10 @@ static void tcp_options_write(__be32 *pt
654 if (unlikely(OPTION_FAST_OPEN_COOKIE & options)) {
655 struct tcp_fastopen_cookie *foc = opts->fastopen_cookie;
657 - *ptr++ = htonl((TCPOPT_EXP << 24) |
658 - ((TCPOLEN_EXP_FASTOPEN_BASE + foc->len) << 16) |
659 - TCPOPT_FASTOPEN_MAGIC);
660 + net_hdr_word(ptr++) =
661 + htonl((TCPOPT_EXP << 24) |
662 + ((TCPOLEN_EXP_FASTOPEN_BASE + foc->len) << 16) |
663 + TCPOPT_FASTOPEN_MAGIC);
665 memcpy(ptr, foc->val, foc->len);
666 if ((foc->len & 3) == 2) {
667 --- a/net/ipv4/igmp.c
668 +++ b/net/ipv4/igmp.c
669 @@ -470,7 +470,7 @@ static struct sk_buff *add_grec(struct s
672 psrc = (__be32 *)skb_put(skb, sizeof(__be32));
673 - *psrc = psf->sf_inaddr;
674 + net_hdr_word(psrc) = psf->sf_inaddr;
676 if ((type == IGMPV3_ALLOW_NEW_SOURCES ||
677 type == IGMPV3_BLOCK_OLD_SOURCES) && psf->sf_crcount) {
678 --- a/net/ipv4/ip_gre.c
679 +++ b/net/ipv4/ip_gre.c
680 @@ -518,7 +518,7 @@ static void ipgre_err(struct sk_buff *sk
684 - key = *(((__be32 *)p) + (grehlen / 4) - 1);
685 + key = net_hdr_word(((__be32 *)p) + (grehlen / 4) - 1);
689 --- a/include/uapi/linux/igmp.h
690 +++ b/include/uapi/linux/igmp.h
691 @@ -32,7 +32,7 @@ struct igmphdr {
692 __u8 code; /* For newer IGMP */
696 +} __attribute__((packed, aligned(2)));
698 /* V3 group record types [grec_type] */
699 #define IGMPV3_MODE_IS_INCLUDE 1
700 @@ -48,7 +48,7 @@ struct igmpv3_grec {
705 +} __attribute__((packed, aligned(2)));
707 struct igmpv3_report {
709 @@ -57,7 +57,7 @@ struct igmpv3_report {
712 struct igmpv3_grec grec[0];
714 +} __attribute__((packed, aligned(2)));
716 struct igmpv3_query {
718 @@ -78,7 +78,7 @@ struct igmpv3_query {
723 +} __attribute__((packed, aligned(2)));
725 #define IGMP_HOST_MEMBERSHIP_QUERY 0x11 /* From RFC1112 */
726 #define IGMP_HOST_MEMBERSHIP_REPORT 0x12 /* Ditto */
727 --- a/net/core/flow_dissector.c
728 +++ b/net/core/flow_dissector.c
729 @@ -137,7 +137,7 @@ ipv6:
731 ports = skb_header_pointer(skb, nhoff, sizeof(_ports), &_ports);
733 - flow->ports = *ports;
734 + flow->ports = net_hdr_word(ports);
738 --- a/include/uapi/linux/icmpv6.h
739 +++ b/include/uapi/linux/icmpv6.h
740 @@ -76,7 +76,7 @@ struct icmp6hdr {
741 #define icmp6_addrconf_other icmp6_dataun.u_nd_ra.other
742 #define icmp6_rt_lifetime icmp6_dataun.u_nd_ra.rt_lifetime
743 #define icmp6_router_pref icmp6_dataun.u_nd_ra.router_pref
745 +} __attribute__((packed, aligned(2)));
748 #define ICMPV6_ROUTER_PREF_LOW 0x3
749 --- a/include/net/ndisc.h
750 +++ b/include/net/ndisc.h
751 @@ -76,7 +76,7 @@ struct ra_msg {
752 struct icmp6hdr icmph;
753 __be32 reachable_time;
754 __be32 retrans_timer;
756 +} __attribute__((packed, aligned(2)));
759 struct icmp6hdr icmph;
760 @@ -142,10 +142,10 @@ static inline u32 ndisc_hashfn(const voi
762 const u32 *p32 = pkey;
764 - return (((p32[0] ^ hash32_ptr(dev)) * hash_rnd[0]) +
765 - (p32[1] * hash_rnd[1]) +
766 - (p32[2] * hash_rnd[2]) +
767 - (p32[3] * hash_rnd[3]));
768 + return (((net_hdr_word(&p32[0]) ^ hash32_ptr(dev)) * hash_rnd[0]) +
769 + (net_hdr_word(&p32[1]) * hash_rnd[1]) +
770 + (net_hdr_word(&p32[2]) * hash_rnd[2]) +
771 + (net_hdr_word(&p32[3]) * hash_rnd[3]));
774 static inline struct neighbour *__ipv6_neigh_lookup(struct neigh_table *tbl, struct net_device *dev, const void *pkey)
775 @@ -163,8 +163,10 @@ static inline struct neighbour *__ipv6_n
776 n = rcu_dereference_bh(n->next)) {
777 u32 *n32 = (u32 *) n->primary_key;
779 - ((n32[0] ^ p32[0]) | (n32[1] ^ p32[1]) |
780 - (n32[2] ^ p32[2]) | (n32[3] ^ p32[3])) == 0) {
781 + ((n32[0] ^ net_hdr_word(&p32[0])) |
782 + (n32[1] ^ net_hdr_word(&p32[1])) |
783 + (n32[2] ^ net_hdr_word(&p32[2])) |
784 + (n32[3] ^ net_hdr_word(&p32[3]))) == 0) {
785 if (!atomic_inc_not_zero(&n->refcnt))
788 --- a/net/sched/cls_u32.c
789 +++ b/net/sched/cls_u32.c
790 @@ -142,7 +142,7 @@ next_knode:
791 data = skb_header_pointer(skb, toff, 4, &hdata);
794 - if ((*data ^ key->val) & key->mask) {
795 + if ((net_hdr_word(data) ^ key->val) & key->mask) {
799 @@ -193,8 +193,8 @@ check_terminal:
803 - sel = ht->divisor & u32_hash_fold(*data, &n->sel,
805 + sel = ht->divisor & u32_hash_fold(net_hdr_word(data),
806 + &n->sel, n->fshift);
808 if (!(n->sel.flags & (TC_U32_VAROFFSET | TC_U32_OFFSET | TC_U32_EAT)))
810 --- a/net/ipv6/ip6_offload.c
811 +++ b/net/ipv6/ip6_offload.c
812 @@ -200,7 +200,7 @@ static struct sk_buff **ipv6_gro_receive
816 - first_word = *(__be32 *)iph ^ *(__be32 *)iph2 ;
817 + first_word = net_hdr_word(iph) ^ net_hdr_word(iph2);
819 /* All fields must match except length and Traffic Class. */
820 if (nlen != skb_network_header_len(p) ||
821 --- a/include/net/addrconf.h
822 +++ b/include/net/addrconf.h
823 @@ -39,7 +39,7 @@ struct prefix_info {
826 struct in6_addr prefix;
828 +} __attribute__((packed, aligned(2)));
831 #include <linux/netdevice.h>
832 --- a/include/net/inet_ecn.h
833 +++ b/include/net/inet_ecn.h
834 @@ -115,13 +115,13 @@ static inline int IP6_ECN_set_ce(struct
836 if (INET_ECN_is_not_ect(ipv6_get_dsfield(iph)))
838 - *(__be32*)iph |= htonl(INET_ECN_CE << 20);
839 + net_hdr_word(iph) |= htonl(INET_ECN_CE << 20);
843 static inline void IP6_ECN_clear(struct ipv6hdr *iph)
845 - *(__be32*)iph &= ~htonl(INET_ECN_MASK << 20);
846 + net_hdr_word(iph) &= ~htonl(INET_ECN_MASK << 20);
849 static inline void ipv6_copy_dscp(unsigned int dscp, struct ipv6hdr *inner)
850 --- a/include/net/ipv6.h
851 +++ b/include/net/ipv6.h
852 @@ -107,7 +107,7 @@ struct frag_hdr {
855 __be32 identification;
857 +} __attribute__((packed, aligned(2)));
859 #define IP6_MF 0x0001
861 @@ -386,6 +386,8 @@ static inline bool __ipv6_prefix_equal(c
862 unsigned int prefixlen)
864 unsigned int pdw, pbi;
865 + /* Used for last <32-bit fraction of prefix */
868 /* check complete u32 in prefix */
869 pdw = prefixlen >> 5;
870 @@ -394,7 +396,9 @@ static inline bool __ipv6_prefix_equal(c
872 /* check incomplete u32 in prefix */
873 pbi = prefixlen & 0x1f;
874 - if (pbi && ((a1[pdw] ^ a2[pdw]) & htonl((0xffffffff) << (32 - pbi))))
875 + pbia1 = net_hdr_word(&a1[pdw]);
876 + pbia2 = net_hdr_word(&a2[pdw]);
877 + if (pbi && ((pbia1 ^ pbia2) & htonl((0xffffffff) << (32 - pbi))))
881 @@ -521,13 +525,13 @@ static inline void ipv6_addr_set_v4mappe
883 static inline int __ipv6_addr_diff(const void *token1, const void *token2, int addrlen)
885 - const __be32 *a1 = token1, *a2 = token2;
886 + const struct in6_addr *a1 = token1, *a2 = token2;
891 for (i = 0; i < addrlen; i++) {
892 - __be32 xb = a1[i] ^ a2[i];
893 + __be32 xb = a1->s6_addr32[i] ^ a2->s6_addr32[i];
895 return i * 32 + 31 - __fls(ntohl(xb));
897 --- a/include/net/secure_seq.h
898 +++ b/include/net/secure_seq.h
900 #define _NET_SECURE_SEQ
902 #include <linux/types.h>
903 +#include <linux/in6.h>
905 extern __u32 secure_ip_id(__be32 daddr);
906 extern __u32 secure_ipv6_id(const __be32 daddr[4]);
907 --- a/include/uapi/linux/in.h
908 +++ b/include/uapi/linux/in.h
909 @@ -55,7 +55,7 @@ enum {
910 /* Internet address. */
914 +} __attribute__((packed, aligned(2)));
918 --- a/include/uapi/linux/xfrm.h
919 +++ b/include/uapi/linux/xfrm.h
925 +} __attribute__((packed, aligned(2))) xfrm_address_t;
927 /* Ident of a specific xfrm_state. It is used on input to lookup
928 * the state by (spi,daddr,ah/esp) or to store information about
929 --- a/net/core/secure_seq.c
930 +++ b/net/core/secure_seq.c
931 @@ -43,10 +43,11 @@ __u32 secure_tcpv6_sequence_number(const
932 u32 secret[MD5_MESSAGE_BYTES / 4];
933 u32 hash[MD5_DIGEST_WORDS];
935 + const struct in6_addr *daddr6 = (struct in6_addr *) daddr;
937 memcpy(hash, saddr, 16);
938 for (i = 0; i < 4; i++)
939 - secret[i] = net_secret[i] + (__force u32)daddr[i];
940 + secret[i] = net_secret[i] + (__force u32)daddr6->s6_addr32[i];
941 secret[4] = net_secret[4] +
942 (((__force u16)sport << 16) + (__force u16)dport);
943 for (i = 5; i < MD5_MESSAGE_BYTES / 4; i++)
944 @@ -64,10 +65,11 @@ u32 secure_ipv6_port_ephemeral(const __b
945 u32 secret[MD5_MESSAGE_BYTES / 4];
946 u32 hash[MD5_DIGEST_WORDS];
948 + const struct in6_addr *daddr6 = (struct in6_addr *) daddr;
950 memcpy(hash, saddr, 16);
951 for (i = 0; i < 4; i++)
952 - secret[i] = net_secret[i] + (__force u32) daddr[i];
953 + secret[i] = net_secret[i] + (__force u32) daddr6->s6_addr32[i];
954 secret[4] = net_secret[4] + (__force u32)dport;
955 for (i = 5; i < MD5_MESSAGE_BYTES / 4; i++)
956 secret[i] = net_secret[i];
957 @@ -165,10 +167,11 @@ u64 secure_dccpv6_sequence_number(__be32
958 u32 hash[MD5_DIGEST_WORDS];
961 + const struct in6_addr *daddr6 = (struct in6_addr *) daddr;
963 memcpy(hash, saddr, 16);
964 for (i = 0; i < 4; i++)
965 - secret[i] = net_secret[i] + daddr[i];
966 + secret[i] = net_secret[i] + daddr6->s6_addr32[i];
967 secret[4] = net_secret[4] +
968 (((__force u16)sport << 16) + (__force u16)dport);
969 for (i = 5; i < MD5_MESSAGE_BYTES / 4; i++)
970 --- a/net/ipv6/ip6_fib.c
971 +++ b/net/ipv6/ip6_fib.c
972 @@ -144,7 +144,7 @@ static __inline__ __be32 addr_bit_set(co
973 * See include/asm-generic/bitops/le.h.
975 return (__force __be32)(1 << ((~fn_bit ^ BITOP_BE32_SWIZZLE) & 0x1f)) &
977 + net_hdr_word(&addr[fn_bit >> 5]);
980 static __inline__ struct fib6_node * node_alloc(void)
981 --- a/net/netfilter/nf_conntrack_proto_tcp.c
982 +++ b/net/netfilter/nf_conntrack_proto_tcp.c
983 @@ -452,7 +452,7 @@ static void tcp_sack(const struct sk_buf
985 /* Fast path for timestamp-only option */
986 if (length == TCPOLEN_TSTAMP_ALIGNED
987 - && *(__be32 *)ptr == htonl((TCPOPT_NOP << 24)
988 + && net_hdr_word(ptr) == htonl((TCPOPT_NOP << 24)
990 | (TCPOPT_TIMESTAMP << 8)
991 | TCPOLEN_TIMESTAMP))
992 --- a/net/netfilter/xt_LOG.c
993 +++ b/net/netfilter/xt_LOG.c
994 @@ -521,9 +521,9 @@ static void dump_ipv6_packet(struct sbuf
995 /* Max length: 44 "LEN=65535 TC=255 HOPLIMIT=255 FLOWLBL=FFFFF " */
996 sb_add(m, "LEN=%Zu TC=%u HOPLIMIT=%u FLOWLBL=%u ",
997 ntohs(ih->payload_len) + sizeof(struct ipv6hdr),
998 - (ntohl(*(__be32 *)ih) & 0x0ff00000) >> 20,
999 + (ntohl(net_hdr_word(ih)) & 0x0ff00000) >> 20,
1001 - (ntohl(*(__be32 *)ih) & 0x000fffff));
1002 + (ntohl(net_hdr_word(ih)) & 0x000fffff));
1005 ptr = ip6hoff + sizeof(struct ipv6hdr);
1006 --- a/net/xfrm/xfrm_input.c
1007 +++ b/net/xfrm/xfrm_input.c
1008 @@ -77,8 +77,8 @@ int xfrm_parse_spi(struct sk_buff *skb,
1009 if (!pskb_may_pull(skb, hlen))
1012 - *spi = *(__be32*)(skb_transport_header(skb) + offset);
1013 - *seq = *(__be32*)(skb_transport_header(skb) + offset_seq);
1014 + *spi = net_hdr_word(skb_transport_header(skb) + offset);
1015 + *seq = net_hdr_word(skb_transport_header(skb) + offset_seq);