fc05676b83491e7e0f2148fb6d0769ef1a426530
[openwrt/openwrt.git] / target / linux / ar71xx / patches-3.7 / 902-unaligned_access_hacks.patch
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;
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 @@ -192,69 +196,4 @@ 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, unsigned short proto,
53 - __wsum sum)
54 -{
55 - __asm__(
56 - " .set push # csum_ipv6_magic\n"
57 - " .set noreorder \n"
58 - " .set noat \n"
59 - " addu %0, %5 # proto (long in network byte order)\n"
60 - " sltu $1, %0, %5 \n"
61 - " addu %0, $1 \n"
62 -
63 - " addu %0, %6 # csum\n"
64 - " sltu $1, %0, %6 \n"
65 - " lw %1, 0(%2) # four words source address\n"
66 - " addu %0, $1 \n"
67 - " addu %0, %1 \n"
68 - " sltu $1, %0, %1 \n"
69 -
70 - " lw %1, 4(%2) \n"
71 - " addu %0, $1 \n"
72 - " addu %0, %1 \n"
73 - " sltu $1, %0, %1 \n"
74 -
75 - " lw %1, 8(%2) \n"
76 - " addu %0, $1 \n"
77 - " addu %0, %1 \n"
78 - " sltu $1, %0, %1 \n"
79 -
80 - " lw %1, 12(%2) \n"
81 - " addu %0, $1 \n"
82 - " addu %0, %1 \n"
83 - " sltu $1, %0, %1 \n"
84 -
85 - " lw %1, 0(%3) \n"
86 - " addu %0, $1 \n"
87 - " addu %0, %1 \n"
88 - " sltu $1, %0, %1 \n"
89 -
90 - " lw %1, 4(%3) \n"
91 - " addu %0, $1 \n"
92 - " addu %0, %1 \n"
93 - " sltu $1, %0, %1 \n"
94 -
95 - " lw %1, 8(%3) \n"
96 - " addu %0, $1 \n"
97 - " addu %0, %1 \n"
98 - " sltu $1, %0, %1 \n"
99 -
100 - " lw %1, 12(%3) \n"
101 - " addu %0, $1 \n"
102 - " addu %0, %1 \n"
103 - " sltu $1, %0, %1 \n"
104 -
105 - " addu %0, $1 # Add final carry\n"
106 - " .set pop"
107 - : "=r" (sum), "=r" (proto)
108 - : "r" (saddr), "r" (daddr),
109 - "0" (htonl(len)), "1" (htonl(proto)), "r" (sum));
110 -
111 - return csum_fold(sum);
112 -}
113 -
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 {
118 __be32 saddr;
119 __be32 daddr;
120 /*The options start here. */
121 -};
122 +} __attribute__((packed, aligned(2)));
123
124
125 struct ip_auth_hdr {
126 --- a/include/uapi/linux/ipv6.h
127 +++ b/include/uapi/linux/ipv6.h
128 @@ -123,7 +123,7 @@ struct ipv6hdr {
129
130 struct in6_addr saddr;
131 struct in6_addr daddr;
132 -};
133 +} __attribute__((packed, aligned(2)));
134
135
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 {
140 __be16 window;
141 __sum16 check;
142 __be16 urg_ptr;
143 -};
144 +} __attribute__((packed, aligned(2)));
145
146 /*
147 * The union cast uses a gcc extension to avoid aliasing problems
148 @@ -64,7 +64,7 @@ struct tcphdr {
149 union tcp_word_hdr {
150 struct tcphdr hdr;
151 __be32 words[5];
152 -};
153 +} __attribute__((packed, aligned(2)));
154
155 #define tcp_flag_word(tp) ( ((union tcp_word_hdr *)(tp))->words [3])
156
157 --- a/include/uapi/linux/udp.h
158 +++ b/include/uapi/linux/udp.h
159 @@ -24,7 +24,7 @@ struct udphdr {
160 __be16 dest;
161 __be16 len;
162 __sum16 check;
163 -};
164 +} __attribute__((packed, aligned(2)));
165
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
171 if (ap == NULL)
172 return false;
173
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);
178
179 return true;
180 }
181 --- a/include/uapi/linux/icmp.h
182 +++ b/include/uapi/linux/icmp.h
183 @@ -80,7 +80,7 @@ struct icmphdr {
184 __be16 mtu;
185 } frag;
186 } un;
187 -};
188 +} __attribute__((packed, aligned(2)));
189
190
191 /*
192 --- a/net/ipv4/tcp_input.c
193 +++ b/net/ipv4/tcp_input.c
194 @@ -3842,13 +3842,14 @@ static bool tcp_parse_aligned_timestamp(
195 {
196 const __be32 *ptr = (const __be32 *)(th + 1);
197
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;
204 ++ptr;
205 - tp->rx_opt.rcv_tsval = ntohl(*ptr);
206 + tp->rx_opt.rcv_tsval = get_unaligned_be32(ptr);
207 ++ptr;
208 - tp->rx_opt.rcv_tsecr = ntohl(*ptr);
209 + tp->rx_opt.rcv_tsecr = get_unaligned_be32(ptr);
210 return true;
211 }
212 return false;
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
219 -};
220 +} __attribute__((packed, aligned(2)));
221
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
226 @@ -61,6 +61,7 @@
227 #endif
228
229 #include <asm/uaccess.h>
230 +#include <asm/unaligned.h>
231 #include <linux/mroute6.h>
232
233 MODULE_AUTHOR("Cast of dozens");
234 @@ -687,7 +688,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 @@ -880,7 +881,7 @@ static struct sk_buff **ipv6_gro_receive
244 continue;
245
246 iph2 = ipv6_hdr(p);
247 - first_word = *(__be32 *)iph ^ *(__be32 *)iph2 ;
248 + first_word = net_hdr_word(iph) ^ net_hdr_word(iph2);
249
250 /* All fields must match except length and Traffic Class. */
251 if (nlen != skb_network_header_len(p) ||
252 --- a/net/ipv6/route.c
253 +++ b/net/ipv6/route.c
254 @@ -938,7 +938,7 @@ void ip6_route_input(struct sk_buff *skb
255 .flowi6_iif = skb->dev->ifindex,
256 .daddr = iph->daddr,
257 .saddr = iph->saddr,
258 - .flowlabel = (* (__be32 *) iph) & IPV6_FLOWINFO_MASK,
259 + .flowlabel = net_hdr_word(iph) & IPV6_FLOWINFO_MASK,
260 .flowi6_mark = skb->mark,
261 .flowi6_proto = iph->nexthdr,
262 };
263 @@ -1108,7 +1108,7 @@ void ip6_update_pmtu(struct sk_buff *skb
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,
269
270 dst = ip6_route_output(net, NULL, &fl6);
271 if (!dst->error)
272 @@ -1136,7 +1136,7 @@ void ip6_redirect(struct sk_buff *skb, s
273 fl6.flowi6_flags = 0;
274 fl6.daddr = iph->daddr;
275 fl6.saddr = iph->saddr;
276 - fl6.flowlabel = (*(__be32 *) iph) & IPV6_FLOWINFO_MASK;
277 + fl6.flowlabel = net_hdr_word(iph) & IPV6_FLOWINFO_MASK,
278
279 dst = ip6_route_output(net, NULL, &fl6);
280 if (!dst->error)
281 --- a/net/ipv6/tcp_ipv6.c
282 +++ b/net/ipv6/tcp_ipv6.c
283 @@ -64,6 +64,7 @@
284 #include <net/secure_seq.h>
285 #include <net/tcp_memcontrol.h>
286
287 +#include <asm/unaligned.h>
288 #include <asm/uaccess.h>
289
290 #include <linux/proc_fs.h>
291 @@ -851,10 +852,10 @@ static void tcp_v6_send_response(struct
292 topt = (__be32 *)(t1 + 1);
293
294 if (ts) {
295 - *topt++ = htonl((TCPOPT_NOP << 24) | (TCPOPT_NOP << 16) |
296 - (TCPOPT_TIMESTAMP << 8) | TCPOLEN_TIMESTAMP);
297 - *topt++ = htonl(tcp_time_stamp);
298 - *topt++ = htonl(ts);
299 + put_unaligned_be32((TCPOPT_NOP << 24) | (TCPOPT_NOP << 16) |
300 + (TCPOPT_TIMESTAMP << 8) | TCPOLEN_TIMESTAMP, topt++);
301 + put_unaligned_be32(tcp_time_stamp, topt++);
302 + put_unaligned_be32(ts, topt++);
303 }
304
305 #ifdef CONFIG_TCP_MD5SIG
306 --- a/include/linux/ipv6.h
307 +++ b/include/linux/ipv6.h
308 @@ -4,6 +4,7 @@
309 #include <uapi/linux/ipv6.h>
310
311 #define ipv6_optlen(p) (((p)->hdrlen+1) << 3)
312 +
313 /*
314 * This structure contains configuration options per IPv6 link.
315 */
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);
320 if (np->sndflow)
321 sin->sin6_flowinfo =
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;
328 } else {
329 - ipv6_addr_set_v4mapped(*(__be32 *)(nh + serr->addr_offset),
330 + ipv6_addr_set_v4mapped(net_hdr_word(nh + serr->addr_offset),
331 &sin->sin6_addr);
332 }
333 }
334 @@ -492,9 +492,10 @@ int datagram_recv_ctl(struct sock *sk, s
335 put_cmsg(msg, SOL_IPV6, IPV6_TCLASS, sizeof(tclass), &tclass);
336 }
337
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;
343 + if (flowinfo)
344 + put_cmsg(msg, SOL_IPV6, IPV6_FLOWINFO, sizeof(flowinfo), &flowinfo);
345 }
346
347 /* HbH is allowed only once */
348 @@ -680,12 +681,12 @@ int datagram_send_ctl(struct net *net, s
349 }
350
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) {
354 err = -EINVAL;
355 goto exit_f;
356 }
357 }
358 - fl6->flowlabel = IPV6_FLOWINFO_MASK & *(__be32 *)CMSG_DATA(cmsg);
359 + fl6->flowlabel = IPV6_FLOWINFO_MASK & net_hdr_word(CMSG_DATA(cmsg));
360 break;
361
362 case IPV6_2292HOPOPTS:
363 --- a/net/ipv6/ip6_gre.c
364 +++ b/net/ipv6/ip6_gre.c
365 @@ -445,7 +445,7 @@ static void ip6gre_err(struct sk_buff *s
366
367 t = ip6gre_tunnel_lookup(skb->dev, &ipv6h->daddr, &ipv6h->saddr,
368 flags & GRE_KEY ?
369 - *(((__be32 *)p) + (grehlen / 4) - 1) : 0,
370 + net_hdr_word(((__be32 *)p) + (grehlen / 4) - 1) : 0,
371 p[1]);
372 if (t == NULL)
373 return;
374 @@ -537,11 +537,11 @@ static int ip6gre_rcv(struct sk_buff *sk
375 offset += 4;
376 }
377 if (flags&GRE_KEY) {
378 - key = *(__be32 *)(h + offset);
379 + key = net_hdr_word(h + offset);
380 offset += 4;
381 }
382 if (flags&GRE_SEQ) {
383 - seqno = ntohl(*(__be32 *)(h + offset));
384 + seqno = ntohl(net_hdr_word(h + offset));
385 offset += 4;
386 }
387 }
388 @@ -788,7 +788,7 @@ static netdev_tx_t ip6gre_xmit2(struct s
389 * Push down and install the IP header.
390 */
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 @@ -805,7 +805,7 @@ static netdev_tx_t ip6gre_xmit2(struct s
398
399 if (tunnel->parms.o_flags&GRE_SEQ) {
400 ++tunnel->o_seqno;
401 - *ptr = htonl(tunnel->o_seqno);
402 + net_hdr_word(ptr) = htonl(tunnel->o_seqno);
403 ptr--;
404 }
405 if (tunnel->parms.o_flags&GRE_KEY) {
406 @@ -913,9 +913,9 @@ static inline int ip6gre_xmit_ipv6(struc
407
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;
417
418 @@ -1256,7 +1256,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);
421
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_
430 if (hlimit < 0)
431 hlimit = ip6_dst_hoplimit(dst);
432
433 - *(__be32 *)hdr = htonl(0x60000000 | (tclass << 20)) | fl6->flowlabel;
434 + net_hdr_word(hdr) = htonl(0x60000000 | (tclass << 20)) | fl6->flowlabel;
435
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 @@ -1110,9 +1110,9 @@ ip6ip6_tnl_xmit(struct sk_buff *skb, str
441
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;
451
452 --- a/net/ipv6/exthdrs.c
453 +++ b/net/ipv6/exthdrs.c
454 @@ -622,7 +622,7 @@ static bool ipv6_hop_jumbo(struct sk_buf
455 goto drop;
456 }
457
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 @@ -211,5 +211,11 @@ struct callback_head {
466 };
467 #define rcu_head callback_head
468
469 +struct net_hdr_word {
470 + u32 words[1];
471 +} __attribute__((packed, aligned(2)));
472 +
473 +#define net_hdr_word(_p) (((struct net_hdr_word *) (_p))->words[0])
474 +
475 #endif /* __ASSEMBLY__ */
476 #endif /* _LINUX_TYPES_H */
477 --- a/net/ipv4/af_inet.c
478 +++ b/net/ipv4/af_inet.c
479 @@ -1388,8 +1388,8 @@ static struct sk_buff **inet_gro_receive
480 if (unlikely(ip_fast_csum((u8 *)iph, 5)))
481 goto out_unlock;
482
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));
487 id >>= 16;
488
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
493 else if (skb)
494 pkey = &ip_hdr(skb)->daddr;
495
496 - n = __ipv4_neigh_lookup(dev, *(__force u32 *)pkey);
497 + n = __ipv4_neigh_lookup(dev, net_hdr_word(pkey));
498 if (n)
499 return n;
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
504 */
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) |
510 - TCPOLEN_MD5SIG);
511 + net_hdr_word(ptr++) =
512 + htonl((TCPOPT_COOKIE << 24) |
513 + (TCPOLEN_COOKIE_BASE << 16) |
514 + (TCPOPT_MD5SIG << 8) |
515 + TCPOLEN_MD5SIG);
516 } else {
517 - *ptr++ = htonl((TCPOPT_NOP << 24) |
518 - (TCPOPT_NOP << 16) |
519 - (TCPOPT_MD5SIG << 8) |
520 - TCPOLEN_MD5SIG);
521 + net_hdr_word(ptr++) =
522 + htonl((TCPOPT_NOP << 24) |
523 + (TCPOPT_NOP << 16) |
524 + (TCPOPT_MD5SIG << 8) |
525 + TCPOLEN_MD5SIG);
526 }
527 options &= ~OPTION_COOKIE_EXTENSION;
528 /* overload cookie hash location */
529 @@ -473,26 +475,28 @@ static void tcp_options_write(__be32 *pt
530 }
531
532 if (unlikely(opts->mss)) {
533 - *ptr++ = htonl((TCPOPT_MSS << 24) |
534 - (TCPOLEN_MSS << 16) |
535 - opts->mss);
536 + net_hdr_word(ptr++) =
537 + htonl((TCPOPT_MSS << 24) | (TCPOLEN_MSS << 16) |
538 + opts->mss);
539 }
540
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;
553 } else {
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);
563 }
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);
568 }
569
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;
573
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++;
583 ptr++;
584 cookie_size -= 2;
585 } else {
586 /* 32-bit multiple */
587 - *ptr++ = htonl(((TCPOPT_NOP << 24) |
588 - (TCPOPT_NOP << 16) |
589 - (TCPOPT_COOKIE << 8) |
590 - TCPOLEN_COOKIE_BASE) +
591 - cookie_size);
592 + net_hdr_word(ptr++) =
593 + htonl(((TCPOPT_NOP << 24) |
594 + (TCPOPT_NOP << 16) |
595 + (TCPOPT_COOKIE << 8) |
596 + TCPOLEN_COOKIE_BASE) +
597 + cookie_size);
598 }
599
600 if (cookie_size > 0) {
601 @@ -534,17 +539,19 @@ static void tcp_options_write(__be32 *pt
602 }
603
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);
614 }
615
616 if (unlikely(OPTION_WSCALE & options)) {
617 - *ptr++ = htonl((TCPOPT_NOP << 24) |
618 - (TCPOPT_WINDOW << 16) |
619 - (TCPOLEN_WINDOW << 8) |
620 - opts->ws);
621 + net_hdr_word(ptr++) =
622 + htonl((TCPOPT_NOP << 24) |
623 + (TCPOPT_WINDOW << 16) |
624 + (TCPOLEN_WINDOW << 8) |
625 + opts->ws);
626 }
627
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;
631 int this_sack;
632
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)));
643
644 for (this_sack = 0; this_sack < opts->num_sack_blocks;
645 ++this_sack) {
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);
650 }
651
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;
656
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);
664
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
670 if (!skb)
671 return NULL;
672 psrc = (__be32 *)skb_put(skb, sizeof(__be32));
673 - *psrc = psf->sf_inaddr;
674 + net_hdr_word(psrc) = psf->sf_inaddr;
675 scount++; stotal++;
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 @@ -533,7 +533,7 @@ static void ipgre_err(struct sk_buff *sk
681 return;
682
683 if (flags & GRE_KEY)
684 - key = *(((__be32 *)p) + (grehlen / 4) - 1);
685 + key = net_hdr_word(((__be32 *)p) + (grehlen / 4) - 1);
686
687 switch (type) {
688 default:
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 */
693 __sum16 csum;
694 __be32 group;
695 -};
696 +} __attribute__((packed, aligned(2)));
697
698 /* V3 group record types [grec_type] */
699 #define IGMPV3_MODE_IS_INCLUDE 1
700 @@ -48,7 +48,7 @@ struct igmpv3_grec {
701 __be16 grec_nsrcs;
702 __be32 grec_mca;
703 __be32 grec_src[0];
704 -};
705 +} __attribute__((packed, aligned(2)));
706
707 struct igmpv3_report {
708 __u8 type;
709 @@ -57,7 +57,7 @@ struct igmpv3_report {
710 __be16 resv2;
711 __be16 ngrec;
712 struct igmpv3_grec grec[0];
713 -};
714 +} __attribute__((packed, aligned(2)));
715
716 struct igmpv3_query {
717 __u8 type;
718 @@ -78,7 +78,7 @@ struct igmpv3_query {
719 __u8 qqic;
720 __be16 nsrcs;
721 __be32 srcs[0];
722 -};
723 +} __attribute__((packed, aligned(2)));
724
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:
730 nhoff += poff;
731 ports = skb_header_pointer(skb, nhoff, sizeof(_ports), &_ports);
732 if (ports)
733 - flow->ports = *ports;
734 + flow->ports = net_hdr_word(ports);
735 }
736
737 return true;
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
744 -};
745 +} __attribute__((packed, aligned(2)));
746
747
748 #define ICMPV6_ROUTER_PREF_LOW 0x3
749 --- a/include/net/ndisc.h
750 +++ b/include/net/ndisc.h
751 @@ -142,10 +142,10 @@ static inline u32 ndisc_hashfn(const voi
752 {
753 const u32 *p32 = pkey;
754
755 - return (((p32[0] ^ hash32_ptr(dev)) * hash_rnd[0]) +
756 - (p32[1] * hash_rnd[1]) +
757 - (p32[2] * hash_rnd[2]) +
758 - (p32[3] * hash_rnd[3]));
759 + return (((net_hdr_word(&p32[0]) ^ hash32_ptr(dev)) * hash_rnd[0]) +
760 + (net_hdr_word(&p32[1]) * hash_rnd[1]) +
761 + (net_hdr_word(&p32[2]) * hash_rnd[2]) +
762 + (net_hdr_word(&p32[3]) * hash_rnd[3]));
763 }
764
765 static inline struct neighbour *__ipv6_neigh_lookup(struct neigh_table *tbl, struct net_device *dev, const void *pkey)
766 --- a/net/sched/cls_u32.c
767 +++ b/net/sched/cls_u32.c
768 @@ -142,7 +142,7 @@ next_knode:
769 data = skb_header_pointer(skb, toff, 4, &hdata);
770 if (!data)
771 goto out;
772 - if ((*data ^ key->val) & key->mask) {
773 + if ((net_hdr_word(data) ^ key->val) & key->mask) {
774 n = n->next;
775 goto next_knode;
776 }
777 @@ -193,8 +193,8 @@ check_terminal:
778 &hdata);
779 if (!data)
780 goto out;
781 - sel = ht->divisor & u32_hash_fold(*data, &n->sel,
782 - n->fshift);
783 + sel = ht->divisor & u32_hash_fold(net_hdr_word(data),
784 + &n->sel, n->fshift);
785 }
786 if (!(n->sel.flags & (TC_U32_VAROFFSET | TC_U32_OFFSET | TC_U32_EAT)))
787 goto next_ht;