902-unaligned_access_hacks.patch 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879
  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;
  5. unsigned int csum;
  6. int carry;
  7. + unsigned int w;
  8. - csum = word[0];
  9. - csum += word[1];
  10. - carry = (csum < word[1]);
  11. + csum = net_hdr_word(word++);
  12. +
  13. + w = net_hdr_word(word++);
  14. + csum += w;
  15. + carry = (csum < w);
  16. csum += carry;
  17. - csum += word[2];
  18. - carry = (csum < word[2]);
  19. + w = net_hdr_word(word++);
  20. + csum += w;
  21. + carry = (csum < w);
  22. csum += carry;
  23. - csum += word[3];
  24. - carry = (csum < word[3]);
  25. + w = net_hdr_word(word++);
  26. + csum += w;
  27. + carry = (csum < w);
  28. csum += carry;
  29. - word += 4;
  30. do {
  31. - csum += *word;
  32. - carry = (csum < *word);
  33. + w = net_hdr_word(word++);
  34. + csum += w;
  35. + carry = (csum < w);
  36. csum += carry;
  37. - word++;
  38. } while (word != stop);
  39. return csum_fold(csum);
  40. @@ -222,69 +226,4 @@ static inline __sum16 ip_compute_csum(co
  41. return csum_fold(csum_partial(buff, len, 0));
  42. }
  43. -#define _HAVE_ARCH_IPV6_CSUM
  44. -static __inline__ __sum16 csum_ipv6_magic(const struct in6_addr *saddr,
  45. - const struct in6_addr *daddr,
  46. - __u32 len, unsigned short proto,
  47. - __wsum sum)
  48. -{
  49. - __asm__(
  50. - " .set push # csum_ipv6_magic\n"
  51. - " .set noreorder \n"
  52. - " .set noat \n"
  53. - " addu %0, %5 # proto (long in network byte order)\n"
  54. - " sltu $1, %0, %5 \n"
  55. - " addu %0, $1 \n"
  56. -
  57. - " addu %0, %6 # csum\n"
  58. - " sltu $1, %0, %6 \n"
  59. - " lw %1, 0(%2) # four words source address\n"
  60. - " addu %0, $1 \n"
  61. - " addu %0, %1 \n"
  62. - " sltu $1, %0, %1 \n"
  63. -
  64. - " lw %1, 4(%2) \n"
  65. - " addu %0, $1 \n"
  66. - " addu %0, %1 \n"
  67. - " sltu $1, %0, %1 \n"
  68. -
  69. - " lw %1, 8(%2) \n"
  70. - " addu %0, $1 \n"
  71. - " addu %0, %1 \n"
  72. - " sltu $1, %0, %1 \n"
  73. -
  74. - " lw %1, 12(%2) \n"
  75. - " addu %0, $1 \n"
  76. - " addu %0, %1 \n"
  77. - " sltu $1, %0, %1 \n"
  78. -
  79. - " lw %1, 0(%3) \n"
  80. - " addu %0, $1 \n"
  81. - " addu %0, %1 \n"
  82. - " sltu $1, %0, %1 \n"
  83. -
  84. - " lw %1, 4(%3) \n"
  85. - " addu %0, $1 \n"
  86. - " addu %0, %1 \n"
  87. - " sltu $1, %0, %1 \n"
  88. -
  89. - " lw %1, 8(%3) \n"
  90. - " addu %0, $1 \n"
  91. - " addu %0, %1 \n"
  92. - " sltu $1, %0, %1 \n"
  93. -
  94. - " lw %1, 12(%3) \n"
  95. - " addu %0, $1 \n"
  96. - " addu %0, %1 \n"
  97. - " sltu $1, %0, %1 \n"
  98. -
  99. - " addu %0, $1 # Add final carry\n"
  100. - " .set pop"
  101. - : "=r" (sum), "=r" (proto)
  102. - : "r" (saddr), "r" (daddr),
  103. - "0" (htonl(len)), "1" (htonl(proto)), "r" (sum));
  104. -
  105. - return csum_fold(sum);
  106. -}
  107. -
  108. #endif /* _ASM_CHECKSUM_H */
  109. --- a/include/uapi/linux/ip.h
  110. +++ b/include/uapi/linux/ip.h
  111. @@ -102,7 +102,7 @@ struct iphdr {
  112. __be32 saddr;
  113. __be32 daddr;
  114. /*The options start here. */
  115. -};
  116. +} __attribute__((packed, aligned(2)));
  117. struct ip_auth_hdr {
  118. --- a/include/uapi/linux/ipv6.h
  119. +++ b/include/uapi/linux/ipv6.h
  120. @@ -125,7 +125,7 @@ struct ipv6hdr {
  121. struct in6_addr saddr;
  122. struct in6_addr daddr;
  123. -};
  124. +} __attribute__((packed, aligned(2)));
  125. /* index values for the variables in ipv6_devconf */
  126. --- a/include/uapi/linux/tcp.h
  127. +++ b/include/uapi/linux/tcp.h
  128. @@ -54,7 +54,7 @@ struct tcphdr {
  129. __be16 window;
  130. __sum16 check;
  131. __be16 urg_ptr;
  132. -};
  133. +} __attribute__((packed, aligned(2)));
  134. /*
  135. * The union cast uses a gcc extension to avoid aliasing problems
  136. @@ -64,7 +64,7 @@ struct tcphdr {
  137. union tcp_word_hdr {
  138. struct tcphdr hdr;
  139. __be32 words[5];
  140. -};
  141. +} __attribute__((packed, aligned(2)));
  142. #define tcp_flag_word(tp) ( ((union tcp_word_hdr *)(tp))->words [3])
  143. --- a/include/uapi/linux/udp.h
  144. +++ b/include/uapi/linux/udp.h
  145. @@ -24,7 +24,7 @@ struct udphdr {
  146. __be16 dest;
  147. __be16 len;
  148. __sum16 check;
  149. -};
  150. +} __attribute__((packed, aligned(2)));
  151. /* UDP socket options */
  152. #define UDP_CORK 1 /* Never send partially complete segments */
  153. --- a/net/ipv4/netfilter/nf_conntrack_l3proto_ipv4.c
  154. +++ b/net/ipv4/netfilter/nf_conntrack_l3proto_ipv4.c
  155. @@ -41,8 +41,8 @@ static bool ipv4_pkt_to_tuple(const stru
  156. if (ap == NULL)
  157. return false;
  158. - tuple->src.u3.ip = ap[0];
  159. - tuple->dst.u3.ip = ap[1];
  160. + tuple->src.u3.ip = net_hdr_word(ap++);
  161. + tuple->dst.u3.ip = net_hdr_word(ap);
  162. return true;
  163. }
  164. --- a/include/uapi/linux/icmp.h
  165. +++ b/include/uapi/linux/icmp.h
  166. @@ -80,7 +80,7 @@ struct icmphdr {
  167. __be16 mtu;
  168. } frag;
  169. } un;
  170. -};
  171. +} __attribute__((packed, aligned(2)));
  172. /*
  173. --- a/include/uapi/linux/in6.h
  174. +++ b/include/uapi/linux/in6.h
  175. @@ -42,7 +42,7 @@ struct in6_addr {
  176. #define s6_addr16 in6_u.u6_addr16
  177. #define s6_addr32 in6_u.u6_addr32
  178. #endif
  179. -};
  180. +} __attribute__((packed, aligned(2)));
  181. #endif /* __UAPI_DEF_IN6_ADDR */
  182. #if __UAPI_DEF_SOCKADDR_IN6
  183. --- a/net/ipv6/tcp_ipv6.c
  184. +++ b/net/ipv6/tcp_ipv6.c
  185. @@ -39,6 +39,7 @@
  186. #include <linux/ipsec.h>
  187. #include <linux/times.h>
  188. #include <linux/slab.h>
  189. +#include <asm/unaligned.h>
  190. #include <linux/uaccess.h>
  191. #include <linux/ipv6.h>
  192. #include <linux/icmpv6.h>
  193. @@ -844,10 +845,10 @@ static void tcp_v6_send_response(struct
  194. topt = (__be32 *)(t1 + 1);
  195. if (tsecr) {
  196. - *topt++ = htonl((TCPOPT_NOP << 24) | (TCPOPT_NOP << 16) |
  197. - (TCPOPT_TIMESTAMP << 8) | TCPOLEN_TIMESTAMP);
  198. - *topt++ = htonl(tsval);
  199. - *topt++ = htonl(tsecr);
  200. + put_unaligned_be32((TCPOPT_NOP << 24) | (TCPOPT_NOP << 16) |
  201. + (TCPOPT_TIMESTAMP << 8) | TCPOLEN_TIMESTAMP, topt++);
  202. + put_unaligned_be32(tsval, topt++);
  203. + put_unaligned_be32(tsecr, topt++);
  204. }
  205. #ifdef CONFIG_TCP_MD5SIG
  206. --- a/include/linux/ipv6.h
  207. +++ b/include/linux/ipv6.h
  208. @@ -5,6 +5,7 @@
  209. #define ipv6_optlen(p) (((p)->hdrlen+1) << 3)
  210. #define ipv6_authlen(p) (((p)->hdrlen+2) << 2)
  211. +
  212. /*
  213. * This structure contains configuration options per IPv6 link.
  214. */
  215. --- a/net/ipv6/datagram.c
  216. +++ b/net/ipv6/datagram.c
  217. @@ -390,7 +390,7 @@ int ipv6_recv_error(struct sock *sk, str
  218. ipv6_iface_scope_id(&sin->sin6_addr,
  219. IP6CB(skb)->iif);
  220. } else {
  221. - ipv6_addr_set_v4mapped(*(__be32 *)(nh + serr->addr_offset),
  222. + ipv6_addr_set_v4mapped(net_hdr_word(nh + serr->addr_offset),
  223. &sin->sin6_addr);
  224. sin->sin6_scope_id = 0;
  225. }
  226. @@ -724,12 +724,12 @@ int ip6_datagram_send_ctl(struct net *ne
  227. }
  228. if (fl6->flowlabel&IPV6_FLOWINFO_MASK) {
  229. - if ((fl6->flowlabel^*(__be32 *)CMSG_DATA(cmsg))&~IPV6_FLOWINFO_MASK) {
  230. + if ((fl6->flowlabel^net_hdr_word(CMSG_DATA(cmsg)))&~IPV6_FLOWINFO_MASK) {
  231. err = -EINVAL;
  232. goto exit_f;
  233. }
  234. }
  235. - fl6->flowlabel = IPV6_FLOWINFO_MASK & *(__be32 *)CMSG_DATA(cmsg);
  236. + fl6->flowlabel = IPV6_FLOWINFO_MASK & net_hdr_word(CMSG_DATA(cmsg));
  237. break;
  238. case IPV6_2292HOPOPTS:
  239. --- a/net/ipv6/ip6_gre.c
  240. +++ b/net/ipv6/ip6_gre.c
  241. @@ -482,11 +482,11 @@ static int ip6gre_rcv(struct sk_buff *sk
  242. offset += 4;
  243. }
  244. if (flags&GRE_KEY) {
  245. - key = *(__be32 *)(h + offset);
  246. + key = net_hdr_word(h + offset);
  247. offset += 4;
  248. }
  249. if (flags&GRE_SEQ) {
  250. - seqno = ntohl(*(__be32 *)(h + offset));
  251. + seqno = ntohl(net_hdr_word(h + offset));
  252. offset += 4;
  253. }
  254. }
  255. @@ -751,7 +751,7 @@ static netdev_tx_t ip6gre_xmit2(struct s
  256. if (tunnel->parms.o_flags&GRE_SEQ) {
  257. ++tunnel->o_seqno;
  258. - *ptr = htonl(tunnel->o_seqno);
  259. + net_hdr_word(ptr) = htonl(tunnel->o_seqno);
  260. ptr--;
  261. }
  262. if (tunnel->parms.o_flags&GRE_KEY) {
  263. @@ -847,7 +847,7 @@ static inline int ip6gre_xmit_ipv6(struc
  264. dsfield = ipv6_get_dsfield(ipv6h);
  265. if (t->parms.flags & IP6_TNL_F_USE_ORIG_TCLASS)
  266. - fl6.flowlabel |= (*(__be32 *) ipv6h & IPV6_TCLASS_MASK);
  267. + fl6.flowlabel |= net_hdr_word(ipv6h) & IPV6_TCLASS_MASK;
  268. if (t->parms.flags & IP6_TNL_F_USE_ORIG_FLOWLABEL)
  269. fl6.flowlabel |= ip6_flowlabel(ipv6h);
  270. if (t->parms.flags & IP6_TNL_F_USE_ORIG_FWMARK)
  271. --- a/net/ipv6/ip6_tunnel.c
  272. +++ b/net/ipv6/ip6_tunnel.c
  273. @@ -1301,7 +1301,7 @@ ip6ip6_tnl_xmit(struct sk_buff *skb, str
  274. dsfield = ipv6_get_dsfield(ipv6h);
  275. if (t->parms.flags & IP6_TNL_F_USE_ORIG_TCLASS)
  276. - fl6.flowlabel |= (*(__be32 *) ipv6h & IPV6_TCLASS_MASK);
  277. + fl6.flowlabel |= net_hdr_word(ipv6h) & IPV6_TCLASS_MASK;
  278. if (t->parms.flags & IP6_TNL_F_USE_ORIG_FLOWLABEL)
  279. fl6.flowlabel |= ip6_flowlabel(ipv6h);
  280. if (t->parms.flags & IP6_TNL_F_USE_ORIG_FWMARK)
  281. --- a/net/ipv6/exthdrs.c
  282. +++ b/net/ipv6/exthdrs.c
  283. @@ -573,7 +573,7 @@ static bool ipv6_hop_jumbo(struct sk_buf
  284. goto drop;
  285. }
  286. - pkt_len = ntohl(*(__be32 *)(nh + optoff + 2));
  287. + pkt_len = ntohl(net_hdr_word(nh + optoff + 2));
  288. if (pkt_len <= IPV6_MAXPLEN) {
  289. IP6_INC_STATS_BH(net, ipv6_skb_idev(skb),
  290. IPSTATS_MIB_INHDRERRORS);
  291. --- a/include/linux/types.h
  292. +++ b/include/linux/types.h
  293. @@ -213,5 +213,11 @@ struct callback_head {
  294. };
  295. #define rcu_head callback_head
  296. +struct net_hdr_word {
  297. + u32 words[1];
  298. +} __attribute__((packed, aligned(2)));
  299. +
  300. +#define net_hdr_word(_p) (((struct net_hdr_word *) (_p))->words[0])
  301. +
  302. #endif /* __ASSEMBLY__ */
  303. #endif /* _LINUX_TYPES_H */
  304. --- a/net/ipv4/af_inet.c
  305. +++ b/net/ipv4/af_inet.c
  306. @@ -1329,8 +1329,8 @@ static struct sk_buff **inet_gro_receive
  307. if (unlikely(ip_fast_csum((u8 *)iph, 5)))
  308. goto out_unlock;
  309. - id = ntohl(*(__be32 *)&iph->id);
  310. - flush = (u16)((ntohl(*(__be32 *)iph) ^ skb_gro_len(skb)) | (id & ~IP_DF));
  311. + id = ntohl(net_hdr_word(&iph->id));
  312. + flush = (u16)((ntohl(net_hdr_word(iph)) ^ skb_gro_len(skb)) | (id & ~IP_DF));
  313. id >>= 16;
  314. for (p = *head; p; p = p->next) {
  315. --- a/net/ipv4/route.c
  316. +++ b/net/ipv4/route.c
  317. @@ -454,7 +454,7 @@ static struct neighbour *ipv4_neigh_look
  318. else if (skb)
  319. pkey = &ip_hdr(skb)->daddr;
  320. - n = __ipv4_neigh_lookup(dev, *(__force u32 *)pkey);
  321. + n = __ipv4_neigh_lookup(dev, net_hdr_word(pkey));
  322. if (n)
  323. return n;
  324. return neigh_create(&arp_tbl, pkey, dev);
  325. --- a/net/ipv4/tcp_output.c
  326. +++ b/net/ipv4/tcp_output.c
  327. @@ -446,48 +446,53 @@ static void tcp_options_write(__be32 *pt
  328. u16 options = opts->options; /* mungable copy */
  329. if (unlikely(OPTION_MD5 & options)) {
  330. - *ptr++ = htonl((TCPOPT_NOP << 24) | (TCPOPT_NOP << 16) |
  331. - (TCPOPT_MD5SIG << 8) | TCPOLEN_MD5SIG);
  332. + net_hdr_word(ptr++) =
  333. + htonl((TCPOPT_NOP << 24) | (TCPOPT_NOP << 16) |
  334. + (TCPOPT_MD5SIG << 8) | TCPOLEN_MD5SIG);
  335. /* overload cookie hash location */
  336. opts->hash_location = (__u8 *)ptr;
  337. ptr += 4;
  338. }
  339. if (unlikely(opts->mss)) {
  340. - *ptr++ = htonl((TCPOPT_MSS << 24) |
  341. - (TCPOLEN_MSS << 16) |
  342. - opts->mss);
  343. + net_hdr_word(ptr++) =
  344. + htonl((TCPOPT_MSS << 24) | (TCPOLEN_MSS << 16) |
  345. + opts->mss);
  346. }
  347. if (likely(OPTION_TS & options)) {
  348. if (unlikely(OPTION_SACK_ADVERTISE & options)) {
  349. - *ptr++ = htonl((TCPOPT_SACK_PERM << 24) |
  350. - (TCPOLEN_SACK_PERM << 16) |
  351. - (TCPOPT_TIMESTAMP << 8) |
  352. - TCPOLEN_TIMESTAMP);
  353. + net_hdr_word(ptr++) =
  354. + htonl((TCPOPT_SACK_PERM << 24) |
  355. + (TCPOLEN_SACK_PERM << 16) |
  356. + (TCPOPT_TIMESTAMP << 8) |
  357. + TCPOLEN_TIMESTAMP);
  358. options &= ~OPTION_SACK_ADVERTISE;
  359. } else {
  360. - *ptr++ = htonl((TCPOPT_NOP << 24) |
  361. - (TCPOPT_NOP << 16) |
  362. - (TCPOPT_TIMESTAMP << 8) |
  363. - TCPOLEN_TIMESTAMP);
  364. + net_hdr_word(ptr++) =
  365. + htonl((TCPOPT_NOP << 24) |
  366. + (TCPOPT_NOP << 16) |
  367. + (TCPOPT_TIMESTAMP << 8) |
  368. + TCPOLEN_TIMESTAMP);
  369. }
  370. - *ptr++ = htonl(opts->tsval);
  371. - *ptr++ = htonl(opts->tsecr);
  372. + net_hdr_word(ptr++) = htonl(opts->tsval);
  373. + net_hdr_word(ptr++) = htonl(opts->tsecr);
  374. }
  375. if (unlikely(OPTION_SACK_ADVERTISE & options)) {
  376. - *ptr++ = htonl((TCPOPT_NOP << 24) |
  377. - (TCPOPT_NOP << 16) |
  378. - (TCPOPT_SACK_PERM << 8) |
  379. - TCPOLEN_SACK_PERM);
  380. + net_hdr_word(ptr++) =
  381. + htonl((TCPOPT_NOP << 24) |
  382. + (TCPOPT_NOP << 16) |
  383. + (TCPOPT_SACK_PERM << 8) |
  384. + TCPOLEN_SACK_PERM);
  385. }
  386. if (unlikely(OPTION_WSCALE & options)) {
  387. - *ptr++ = htonl((TCPOPT_NOP << 24) |
  388. - (TCPOPT_WINDOW << 16) |
  389. - (TCPOLEN_WINDOW << 8) |
  390. - opts->ws);
  391. + net_hdr_word(ptr++) =
  392. + htonl((TCPOPT_NOP << 24) |
  393. + (TCPOPT_WINDOW << 16) |
  394. + (TCPOLEN_WINDOW << 8) |
  395. + opts->ws);
  396. }
  397. if (unlikely(opts->num_sack_blocks)) {
  398. @@ -495,16 +500,17 @@ static void tcp_options_write(__be32 *pt
  399. tp->duplicate_sack : tp->selective_acks;
  400. int this_sack;
  401. - *ptr++ = htonl((TCPOPT_NOP << 24) |
  402. - (TCPOPT_NOP << 16) |
  403. - (TCPOPT_SACK << 8) |
  404. - (TCPOLEN_SACK_BASE + (opts->num_sack_blocks *
  405. + net_hdr_word(ptr++) =
  406. + htonl((TCPOPT_NOP << 24) |
  407. + (TCPOPT_NOP << 16) |
  408. + (TCPOPT_SACK << 8) |
  409. + (TCPOLEN_SACK_BASE + (opts->num_sack_blocks *
  410. TCPOLEN_SACK_PERBLOCK)));
  411. for (this_sack = 0; this_sack < opts->num_sack_blocks;
  412. ++this_sack) {
  413. - *ptr++ = htonl(sp[this_sack].start_seq);
  414. - *ptr++ = htonl(sp[this_sack].end_seq);
  415. + net_hdr_word(ptr++) = htonl(sp[this_sack].start_seq);
  416. + net_hdr_word(ptr++) = htonl(sp[this_sack].end_seq);
  417. }
  418. tp->rx_opt.dsack = 0;
  419. @@ -513,9 +519,10 @@ static void tcp_options_write(__be32 *pt
  420. if (unlikely(OPTION_FAST_OPEN_COOKIE & options)) {
  421. struct tcp_fastopen_cookie *foc = opts->fastopen_cookie;
  422. - *ptr++ = htonl((TCPOPT_EXP << 24) |
  423. - ((TCPOLEN_EXP_FASTOPEN_BASE + foc->len) << 16) |
  424. - TCPOPT_FASTOPEN_MAGIC);
  425. + net_hdr_word(ptr++) =
  426. + htonl((TCPOPT_EXP << 24) |
  427. + ((TCPOLEN_EXP_FASTOPEN_BASE + foc->len) << 16) |
  428. + TCPOPT_FASTOPEN_MAGIC);
  429. memcpy(ptr, foc->val, foc->len);
  430. if ((foc->len & 3) == 2) {
  431. --- a/net/ipv4/igmp.c
  432. +++ b/net/ipv4/igmp.c
  433. @@ -495,7 +495,7 @@ static struct sk_buff *add_grec(struct s
  434. if (!skb)
  435. return NULL;
  436. psrc = (__be32 *)skb_put(skb, sizeof(__be32));
  437. - *psrc = psf->sf_inaddr;
  438. + net_hdr_word(psrc) = psf->sf_inaddr;
  439. scount++; stotal++;
  440. if ((type == IGMPV3_ALLOW_NEW_SOURCES ||
  441. type == IGMPV3_BLOCK_OLD_SOURCES) && psf->sf_crcount) {
  442. --- a/include/uapi/linux/igmp.h
  443. +++ b/include/uapi/linux/igmp.h
  444. @@ -32,7 +32,7 @@ struct igmphdr {
  445. __u8 code; /* For newer IGMP */
  446. __sum16 csum;
  447. __be32 group;
  448. -};
  449. +} __attribute__((packed, aligned(2)));
  450. /* V3 group record types [grec_type] */
  451. #define IGMPV3_MODE_IS_INCLUDE 1
  452. @@ -48,7 +48,7 @@ struct igmpv3_grec {
  453. __be16 grec_nsrcs;
  454. __be32 grec_mca;
  455. __be32 grec_src[0];
  456. -};
  457. +} __attribute__((packed, aligned(2)));
  458. struct igmpv3_report {
  459. __u8 type;
  460. @@ -57,7 +57,7 @@ struct igmpv3_report {
  461. __be16 resv2;
  462. __be16 ngrec;
  463. struct igmpv3_grec grec[0];
  464. -};
  465. +} __attribute__((packed, aligned(2)));
  466. struct igmpv3_query {
  467. __u8 type;
  468. @@ -78,7 +78,7 @@ struct igmpv3_query {
  469. __u8 qqic;
  470. __be16 nsrcs;
  471. __be32 srcs[0];
  472. -};
  473. +} __attribute__((packed, aligned(2)));
  474. #define IGMP_HOST_MEMBERSHIP_QUERY 0x11 /* From RFC1112 */
  475. #define IGMP_HOST_MEMBERSHIP_REPORT 0x12 /* Ditto */
  476. --- a/net/core/flow_dissector.c
  477. +++ b/net/core/flow_dissector.c
  478. @@ -53,7 +53,7 @@ __be32 __skb_flow_get_ports(const struct
  479. ports = __skb_header_pointer(skb, thoff + poff,
  480. sizeof(_ports), data, hlen, &_ports);
  481. if (ports)
  482. - return *ports;
  483. + return (__be32)net_hdr_word(ports);
  484. }
  485. return 0;
  486. --- a/include/uapi/linux/icmpv6.h
  487. +++ b/include/uapi/linux/icmpv6.h
  488. @@ -76,7 +76,7 @@ struct icmp6hdr {
  489. #define icmp6_addrconf_other icmp6_dataun.u_nd_ra.other
  490. #define icmp6_rt_lifetime icmp6_dataun.u_nd_ra.rt_lifetime
  491. #define icmp6_router_pref icmp6_dataun.u_nd_ra.router_pref
  492. -};
  493. +} __attribute__((packed, aligned(2)));
  494. #define ICMPV6_ROUTER_PREF_LOW 0x3
  495. --- a/include/net/ndisc.h
  496. +++ b/include/net/ndisc.h
  497. @@ -76,7 +76,7 @@ struct ra_msg {
  498. struct icmp6hdr icmph;
  499. __be32 reachable_time;
  500. __be32 retrans_timer;
  501. -};
  502. +} __attribute__((packed, aligned(2)));
  503. struct rd_msg {
  504. struct icmp6hdr icmph;
  505. @@ -148,10 +148,10 @@ static inline u32 ndisc_hashfn(const voi
  506. {
  507. const u32 *p32 = pkey;
  508. - return (((p32[0] ^ hash32_ptr(dev)) * hash_rnd[0]) +
  509. - (p32[1] * hash_rnd[1]) +
  510. - (p32[2] * hash_rnd[2]) +
  511. - (p32[3] * hash_rnd[3]));
  512. + return (((net_hdr_word(&p32[0]) ^ hash32_ptr(dev)) * hash_rnd[0]) +
  513. + (net_hdr_word(&p32[1]) * hash_rnd[1]) +
  514. + (net_hdr_word(&p32[2]) * hash_rnd[2]) +
  515. + (net_hdr_word(&p32[3]) * hash_rnd[3]));
  516. }
  517. static inline struct neighbour *__ipv6_neigh_lookup_noref(struct net_device *dev, const void *pkey)
  518. @@ -168,8 +168,10 @@ static inline struct neighbour *__ipv6_n
  519. n = rcu_dereference_bh(n->next)) {
  520. u32 *n32 = (u32 *) n->primary_key;
  521. if (n->dev == dev &&
  522. - ((n32[0] ^ p32[0]) | (n32[1] ^ p32[1]) |
  523. - (n32[2] ^ p32[2]) | (n32[3] ^ p32[3])) == 0)
  524. + ((n32[0] ^ net_hdr_word(&p32[0])) |
  525. + (n32[1] ^ net_hdr_word(&p32[1])) |
  526. + (n32[2] ^ net_hdr_word(&p32[2])) |
  527. + (n32[3] ^ net_hdr_word(&p32[3]))) == 0)
  528. return n;
  529. }
  530. --- a/net/sched/cls_u32.c
  531. +++ b/net/sched/cls_u32.c
  532. @@ -151,7 +151,7 @@ next_knode:
  533. data = skb_header_pointer(skb, toff, 4, &hdata);
  534. if (!data)
  535. goto out;
  536. - if ((*data ^ key->val) & key->mask) {
  537. + if ((net_hdr_word(data) ^ key->val) & key->mask) {
  538. n = rcu_dereference_bh(n->next);
  539. goto next_knode;
  540. }
  541. @@ -204,8 +204,8 @@ check_terminal:
  542. &hdata);
  543. if (!data)
  544. goto out;
  545. - sel = ht->divisor & u32_hash_fold(*data, &n->sel,
  546. - n->fshift);
  547. + sel = ht->divisor & u32_hash_fold(net_hdr_word(data),
  548. + &n->sel, n->fshift);
  549. }
  550. if (!(n->sel.flags & (TC_U32_VAROFFSET | TC_U32_OFFSET | TC_U32_EAT)))
  551. goto next_ht;
  552. --- a/net/ipv6/ip6_offload.c
  553. +++ b/net/ipv6/ip6_offload.c
  554. @@ -224,7 +224,7 @@ static struct sk_buff **ipv6_gro_receive
  555. continue;
  556. iph2 = (struct ipv6hdr *)(p->data + off);
  557. - first_word = *(__be32 *)iph ^ *(__be32 *)iph2;
  558. + first_word = net_hdr_word(iph) ^ net_hdr_word(iph2);
  559. /* All fields must match except length and Traffic Class.
  560. * XXX skbs on the gro_list have all been parsed and pulled
  561. --- a/include/net/addrconf.h
  562. +++ b/include/net/addrconf.h
  563. @@ -45,7 +45,7 @@ struct prefix_info {
  564. __be32 reserved2;
  565. struct in6_addr prefix;
  566. -};
  567. +} __attribute__((packed, aligned(2)));
  568. #include <linux/netdevice.h>
  569. --- a/include/net/inet_ecn.h
  570. +++ b/include/net/inet_ecn.h
  571. @@ -124,9 +124,9 @@ static inline int IP6_ECN_set_ce(struct
  572. if (INET_ECN_is_not_ect(ipv6_get_dsfield(iph)))
  573. return 0;
  574. - from = *(__be32 *)iph;
  575. + from = net_hdr_word(iph);
  576. to = from | htonl(INET_ECN_CE << 20);
  577. - *(__be32 *)iph = to;
  578. + net_hdr_word(iph) = to;
  579. if (skb->ip_summed == CHECKSUM_COMPLETE)
  580. skb->csum = csum_add(csum_sub(skb->csum, from), to);
  581. return 1;
  582. @@ -134,7 +134,7 @@ static inline int IP6_ECN_set_ce(struct
  583. static inline void IP6_ECN_clear(struct ipv6hdr *iph)
  584. {
  585. - *(__be32*)iph &= ~htonl(INET_ECN_MASK << 20);
  586. + net_hdr_word(iph) &= ~htonl(INET_ECN_MASK << 20);
  587. }
  588. static inline void ipv6_copy_dscp(unsigned int dscp, struct ipv6hdr *inner)
  589. --- a/include/net/ipv6.h
  590. +++ b/include/net/ipv6.h
  591. @@ -109,7 +109,7 @@ struct frag_hdr {
  592. __u8 reserved;
  593. __be16 frag_off;
  594. __be32 identification;
  595. -};
  596. +} __attribute__((packed, aligned(2)));
  597. #define IP6_MF 0x0001
  598. #define IP6_OFFSET 0xFFF8
  599. @@ -417,8 +417,8 @@ static inline void __ipv6_addr_set_half(
  600. }
  601. #endif
  602. #endif
  603. - addr[0] = wh;
  604. - addr[1] = wl;
  605. + net_hdr_word(&addr[0]) = wh;
  606. + net_hdr_word(&addr[1]) = wl;
  607. }
  608. static inline void ipv6_addr_set(struct in6_addr *addr,
  609. @@ -477,6 +477,8 @@ static inline bool ipv6_prefix_equal(con
  610. const __be32 *a1 = addr1->s6_addr32;
  611. const __be32 *a2 = addr2->s6_addr32;
  612. unsigned int pdw, pbi;
  613. + /* Used for last <32-bit fraction of prefix */
  614. + u32 pbia1, pbia2;
  615. /* check complete u32 in prefix */
  616. pdw = prefixlen >> 5;
  617. @@ -485,7 +487,9 @@ static inline bool ipv6_prefix_equal(con
  618. /* check incomplete u32 in prefix */
  619. pbi = prefixlen & 0x1f;
  620. - if (pbi && ((a1[pdw] ^ a2[pdw]) & htonl((0xffffffff) << (32 - pbi))))
  621. + pbia1 = net_hdr_word(&a1[pdw]);
  622. + pbia2 = net_hdr_word(&a2[pdw]);
  623. + if (pbi && ((pbia1 ^ pbia2) & htonl((0xffffffff) << (32 - pbi))))
  624. return false;
  625. return true;
  626. @@ -629,13 +633,13 @@ static inline void ipv6_addr_set_v4mappe
  627. */
  628. static inline int __ipv6_addr_diff32(const void *token1, const void *token2, int addrlen)
  629. {
  630. - const __be32 *a1 = token1, *a2 = token2;
  631. + const struct in6_addr *a1 = token1, *a2 = token2;
  632. int i;
  633. addrlen >>= 2;
  634. for (i = 0; i < addrlen; i++) {
  635. - __be32 xb = a1[i] ^ a2[i];
  636. + __be32 xb = a1->s6_addr32[i] ^ a2->s6_addr32[i];
  637. if (xb)
  638. return i * 32 + 31 - __fls(ntohl(xb));
  639. }
  640. @@ -759,17 +763,18 @@ static inline __be32 ip6_make_flowlabel(
  641. static inline void ip6_flow_hdr(struct ipv6hdr *hdr, unsigned int tclass,
  642. __be32 flowlabel)
  643. {
  644. - *(__be32 *)hdr = htonl(0x60000000 | (tclass << 20)) | flowlabel;
  645. + net_hdr_word((__be32 *)hdr) =
  646. + htonl(0x60000000 | (tclass << 20)) | flowlabel;
  647. }
  648. static inline __be32 ip6_flowinfo(const struct ipv6hdr *hdr)
  649. {
  650. - return *(__be32 *)hdr & IPV6_FLOWINFO_MASK;
  651. + return net_hdr_word((__be32 *)hdr) & IPV6_FLOWINFO_MASK;
  652. }
  653. static inline __be32 ip6_flowlabel(const struct ipv6hdr *hdr)
  654. {
  655. - return *(__be32 *)hdr & IPV6_FLOWLABEL_MASK;
  656. + return net_hdr_word((__be32 *)hdr) & IPV6_FLOWLABEL_MASK;
  657. }
  658. static inline u8 ip6_tclass(__be32 flowinfo)
  659. --- a/include/net/secure_seq.h
  660. +++ b/include/net/secure_seq.h
  661. @@ -2,6 +2,7 @@
  662. #define _NET_SECURE_SEQ
  663. #include <linux/types.h>
  664. +#include <linux/in6.h>
  665. u32 secure_ipv4_port_ephemeral(__be32 saddr, __be32 daddr, __be16 dport);
  666. u32 secure_ipv6_port_ephemeral(const __be32 *saddr, const __be32 *daddr,
  667. --- a/include/uapi/linux/in.h
  668. +++ b/include/uapi/linux/in.h
  669. @@ -78,7 +78,7 @@ enum {
  670. /* Internet address. */
  671. struct in_addr {
  672. __be32 s_addr;
  673. -};
  674. +} __attribute__((packed, aligned(2)));
  675. #define IP_TOS 1
  676. #define IP_TTL 2
  677. --- a/net/core/secure_seq.c
  678. +++ b/net/core/secure_seq.c
  679. @@ -46,11 +46,12 @@ __u32 secure_tcpv6_sequence_number(const
  680. u32 secret[MD5_MESSAGE_BYTES / 4];
  681. u32 hash[MD5_DIGEST_WORDS];
  682. u32 i;
  683. + const struct in6_addr *daddr6 = (struct in6_addr *) daddr;
  684. net_secret_init();
  685. memcpy(hash, saddr, 16);
  686. for (i = 0; i < 4; i++)
  687. - secret[i] = net_secret[i] + (__force u32)daddr[i];
  688. + secret[i] = net_secret[i] + (__force u32)daddr6->s6_addr32[i];
  689. secret[4] = net_secret[4] +
  690. (((__force u16)sport << 16) + (__force u16)dport);
  691. for (i = 5; i < MD5_MESSAGE_BYTES / 4; i++)
  692. @@ -68,11 +69,12 @@ u32 secure_ipv6_port_ephemeral(const __b
  693. u32 secret[MD5_MESSAGE_BYTES / 4];
  694. u32 hash[MD5_DIGEST_WORDS];
  695. u32 i;
  696. + const struct in6_addr *daddr6 = (struct in6_addr *) daddr;
  697. net_secret_init();
  698. memcpy(hash, saddr, 16);
  699. for (i = 0; i < 4; i++)
  700. - secret[i] = net_secret[i] + (__force u32) daddr[i];
  701. + secret[i] = net_secret[i] + (__force u32) daddr6->s6_addr32[i];
  702. secret[4] = net_secret[4] + (__force u32)dport;
  703. for (i = 5; i < MD5_MESSAGE_BYTES / 4; i++)
  704. secret[i] = net_secret[i];
  705. @@ -150,11 +152,12 @@ u64 secure_dccpv6_sequence_number(__be32
  706. u32 hash[MD5_DIGEST_WORDS];
  707. u64 seq;
  708. u32 i;
  709. + const struct in6_addr *daddr6 = (struct in6_addr *) daddr;
  710. net_secret_init();
  711. memcpy(hash, saddr, 16);
  712. for (i = 0; i < 4; i++)
  713. - secret[i] = net_secret[i] + daddr[i];
  714. + secret[i] = net_secret[i] + daddr6->s6_addr32[i];
  715. secret[4] = net_secret[4] +
  716. (((__force u16)sport << 16) + (__force u16)dport);
  717. for (i = 5; i < MD5_MESSAGE_BYTES / 4; i++)
  718. --- a/net/ipv6/ip6_fib.c
  719. +++ b/net/ipv6/ip6_fib.c
  720. @@ -137,7 +137,7 @@ static __be32 addr_bit_set(const void *t
  721. * See include/asm-generic/bitops/le.h.
  722. */
  723. return (__force __be32)(1 << ((~fn_bit ^ BITOP_BE32_SWIZZLE) & 0x1f)) &
  724. - addr[fn_bit >> 5];
  725. + net_hdr_word(&addr[fn_bit >> 5]);
  726. }
  727. static struct fib6_node *node_alloc(void)
  728. --- a/net/netfilter/nf_conntrack_proto_tcp.c
  729. +++ b/net/netfilter/nf_conntrack_proto_tcp.c
  730. @@ -456,7 +456,7 @@ static void tcp_sack(const struct sk_buf
  731. /* Fast path for timestamp-only option */
  732. if (length == TCPOLEN_TSTAMP_ALIGNED
  733. - && *(__be32 *)ptr == htonl((TCPOPT_NOP << 24)
  734. + && net_hdr_word(ptr) == htonl((TCPOPT_NOP << 24)
  735. | (TCPOPT_NOP << 16)
  736. | (TCPOPT_TIMESTAMP << 8)
  737. | TCPOLEN_TIMESTAMP))
  738. --- a/net/xfrm/xfrm_input.c
  739. +++ b/net/xfrm/xfrm_input.c
  740. @@ -154,8 +154,8 @@ int xfrm_parse_spi(struct sk_buff *skb,
  741. if (!pskb_may_pull(skb, hlen))
  742. return -EINVAL;
  743. - *spi = *(__be32 *)(skb_transport_header(skb) + offset);
  744. - *seq = *(__be32 *)(skb_transport_header(skb) + offset_seq);
  745. + *spi = net_hdr_word(skb_transport_header(skb) + offset);
  746. + *seq = net_hdr_word(skb_transport_header(skb) + offset_seq);
  747. return 0;
  748. }
  749. --- a/net/ipv4/tcp_input.c
  750. +++ b/net/ipv4/tcp_input.c
  751. @@ -3682,14 +3682,16 @@ static bool tcp_parse_aligned_timestamp(
  752. {
  753. const __be32 *ptr = (const __be32 *)(th + 1);
  754. - if (*ptr == htonl((TCPOPT_NOP << 24) | (TCPOPT_NOP << 16)
  755. - | (TCPOPT_TIMESTAMP << 8) | TCPOLEN_TIMESTAMP)) {
  756. + if (net_hdr_word(ptr) ==
  757. + htonl((TCPOPT_NOP << 24) | (TCPOPT_NOP << 16) |
  758. + (TCPOPT_TIMESTAMP << 8) | TCPOLEN_TIMESTAMP)) {
  759. tp->rx_opt.saw_tstamp = 1;
  760. ++ptr;
  761. - tp->rx_opt.rcv_tsval = ntohl(*ptr);
  762. + tp->rx_opt.rcv_tsval = get_unaligned_be32(ptr);
  763. ++ptr;
  764. - if (*ptr)
  765. - tp->rx_opt.rcv_tsecr = ntohl(*ptr) - tp->tsoffset;
  766. + if (net_hdr_word(ptr))
  767. + tp->rx_opt.rcv_tsecr = get_unaligned_be32(ptr) -
  768. + tp->tsoffset;
  769. else
  770. tp->rx_opt.rcv_tsecr = 0;
  771. return true;
  772. --- a/include/uapi/linux/if_pppox.h
  773. +++ b/include/uapi/linux/if_pppox.h
  774. @@ -47,6 +47,7 @@ struct pppoe_addr {
  775. */
  776. struct pptp_addr {
  777. __u16 call_id;
  778. + __u16 pad;
  779. struct in_addr sin_addr;
  780. };
  781. --- a/net/ipv6/netfilter/nf_log_ipv6.c
  782. +++ b/net/ipv6/netfilter/nf_log_ipv6.c
  783. @@ -63,9 +63,9 @@ static void dump_ipv6_packet(struct nf_l
  784. /* Max length: 44 "LEN=65535 TC=255 HOPLIMIT=255 FLOWLBL=FFFFF " */
  785. nf_log_buf_add(m, "LEN=%Zu TC=%u HOPLIMIT=%u FLOWLBL=%u ",
  786. ntohs(ih->payload_len) + sizeof(struct ipv6hdr),
  787. - (ntohl(*(__be32 *)ih) & 0x0ff00000) >> 20,
  788. + (ntohl(net_hdr_word(ih)) & 0x0ff00000) >> 20,
  789. ih->hop_limit,
  790. - (ntohl(*(__be32 *)ih) & 0x000fffff));
  791. + (ntohl(net_hdr_word(ih)) & 0x000fffff));
  792. fragment = 0;
  793. ptr = ip6hoff + sizeof(struct ipv6hdr);