910-unaligned_access_hacks.patch 25 KB

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