tcp-fastopen.patch 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254
  1. https://lkml.org/lkml/2014/5/5/674
  2. Andi Kleen <ak@linux.intel.com>
  3. diff -Nur linux-3.10.40.orig/include/linux/tcp.h linux-3.10.40/include/linux/tcp.h
  4. --- linux-3.10.40.orig/include/linux/tcp.h 2014-05-13 14:00:04.000000000 +0200
  5. +++ linux-3.10.40/include/linux/tcp.h 2014-05-30 15:41:44.000000000 +0200
  6. @@ -357,6 +357,9 @@
  7. return (struct tcp_timewait_sock *)sk;
  8. }
  9. +extern void tcp_sock_destruct(struct sock *sk);
  10. +
  11. +#ifdef CONFIG_TCP_FASTOPEN
  12. static inline bool tcp_passive_fastopen(const struct sock *sk)
  13. {
  14. return (sk->sk_state == TCP_SYN_RECV &&
  15. @@ -368,8 +371,6 @@
  16. return foc->len != -1;
  17. }
  18. -extern void tcp_sock_destruct(struct sock *sk);
  19. -
  20. static inline int fastopen_init_queue(struct sock *sk, int backlog)
  21. {
  22. struct request_sock_queue *queue =
  23. @@ -389,4 +390,13 @@
  24. return 0;
  25. }
  26. +#else
  27. +static inline bool tcp_passive_fastopen(const struct sock *sk)
  28. +{ return false; }
  29. +static inline bool fastopen_cookie_present(struct tcp_fastopen_cookie *foc)
  30. +{ return false; }
  31. +static inline int fastopen_init_queue(struct sock *sk, int backlog)
  32. +{ return 0; }
  33. +#endif
  34. +
  35. #endif /* _LINUX_TCP_H */
  36. diff -Nur linux-3.10.40.orig/include/net/request_sock.h linux-3.10.40/include/net/request_sock.h
  37. --- linux-3.10.40.orig/include/net/request_sock.h 2014-05-13 14:00:04.000000000 +0200
  38. +++ linux-3.10.40/include/net/request_sock.h 2014-05-30 15:41:44.000000000 +0200
  39. @@ -167,8 +167,14 @@
  40. extern void __reqsk_queue_destroy(struct request_sock_queue *queue);
  41. extern void reqsk_queue_destroy(struct request_sock_queue *queue);
  42. +#ifdef CONFIG_TCP_FASTOPEN
  43. extern void reqsk_fastopen_remove(struct sock *sk,
  44. struct request_sock *req, bool reset);
  45. +#else
  46. +static inline void reqsk_fastopen_remove(struct sock *sk, struct request_sock *req,
  47. + bool reset) {}
  48. +#endif
  49. +
  50. static inline struct request_sock *
  51. reqsk_queue_yank_acceptq(struct request_sock_queue *queue)
  52. diff -Nur linux-3.10.40.orig/include/net/tcp.h linux-3.10.40/include/net/tcp.h
  53. --- linux-3.10.40.orig/include/net/tcp.h 2014-05-13 14:00:04.000000000 +0200
  54. +++ linux-3.10.40/include/net/tcp.h 2014-05-30 15:41:44.000000000 +0200
  55. @@ -257,7 +257,11 @@
  56. extern int sysctl_tcp_retries2;
  57. extern int sysctl_tcp_orphan_retries;
  58. extern int sysctl_tcp_syncookies;
  59. +#ifdef CONFIG_TCP_FASTOPEN
  60. extern int sysctl_tcp_fastopen;
  61. +#else
  62. +#define sysctl_tcp_fastopen 0
  63. +#endif
  64. extern int sysctl_tcp_retrans_collapse;
  65. extern int sysctl_tcp_stdurg;
  66. extern int sysctl_tcp_rfc1337;
  67. @@ -1311,7 +1315,12 @@
  68. size_t size;
  69. int copied; /* queued in tcp_connect() */
  70. };
  71. +
  72. +#ifdef CONFIG_TCP_FASTOPEN
  73. void tcp_free_fastopen_req(struct tcp_sock *tp);
  74. +#else
  75. +static inline void tcp_free_fastopen_req(struct tcp_sock *tp) {}
  76. +#endif
  77. extern struct tcp_fastopen_context __rcu *tcp_fastopen_ctx;
  78. int tcp_fastopen_reset_cipher(void *key, unsigned int len);
  79. diff -Nur linux-3.10.40.orig/net/Kconfig linux-3.10.40/net/Kconfig
  80. --- linux-3.10.40.orig/net/Kconfig 2014-05-13 14:00:04.000000000 +0200
  81. +++ linux-3.10.40/net/Kconfig 2014-05-30 15:41:44.000000000 +0200
  82. @@ -52,8 +52,8 @@
  83. config INET
  84. bool "TCP/IP networking"
  85. - select CRYPTO
  86. - select CRYPTO_AES
  87. + select CRYPTO if TCP_FASTOPEN
  88. + select CRYPTO_AES if TCP_FASTOPEN
  89. ---help---
  90. These are the protocols used on the Internet and on most local
  91. Ethernets. It is highly recommended to say Y here (this will enlarge
  92. diff -Nur linux-3.10.40.orig/net/core/request_sock.c linux-3.10.40/net/core/request_sock.c
  93. --- linux-3.10.40.orig/net/core/request_sock.c 2014-05-13 14:00:04.000000000 +0200
  94. +++ linux-3.10.40/net/core/request_sock.c 2014-05-30 15:41:44.000000000 +0200
  95. @@ -131,6 +131,7 @@
  96. kfree(lopt);
  97. }
  98. +#ifdef CONFIG_TCP_FASTOPEN
  99. /*
  100. * This function is called to set a Fast Open socket's "fastopen_rsk" field
  101. * to NULL when a TFO socket no longer needs to access the request_sock.
  102. @@ -223,3 +224,4 @@
  103. sock_put(lsk);
  104. return;
  105. }
  106. +#endif
  107. diff -Nur linux-3.10.40.orig/net/ipv4/Kconfig linux-3.10.40/net/ipv4/Kconfig
  108. --- linux-3.10.40.orig/net/ipv4/Kconfig 2014-05-13 14:00:04.000000000 +0200
  109. +++ linux-3.10.40/net/ipv4/Kconfig 2014-05-30 15:41:44.000000000 +0200
  110. @@ -328,6 +328,10 @@
  111. the notion of a secure tunnel for IPSEC and then use routing protocol
  112. on top.
  113. +config TCP_FASTOPEN
  114. + bool "Enable TCP fastopen"
  115. + default n
  116. +
  117. config INET_AH
  118. tristate "IP: AH transformation"
  119. select XFRM_ALGO
  120. diff -Nur linux-3.10.40.orig/net/ipv4/Makefile linux-3.10.40/net/ipv4/Makefile
  121. --- linux-3.10.40.orig/net/ipv4/Makefile 2014-05-13 14:00:04.000000000 +0200
  122. +++ linux-3.10.40/net/ipv4/Makefile 2014-05-30 16:58:49.000000000 +0200
  123. @@ -7,7 +7,7 @@
  124. ip_output.o ip_sockglue.o inet_hashtables.o \
  125. inet_timewait_sock.o inet_connection_sock.o \
  126. tcp.o tcp_input.o tcp_output.o tcp_timer.o tcp_ipv4.o \
  127. - tcp_minisocks.o tcp_cong.o tcp_metrics.o tcp_fastopen.o \
  128. + tcp_minisocks.o tcp_cong.o tcp_metrics.o \
  129. datagram.o raw.o udp.o udplite.o \
  130. arp.o icmp.o devinet.o af_inet.o igmp.o \
  131. fib_frontend.o fib_semantics.o fib_trie.o \
  132. @@ -50,6 +50,7 @@
  133. obj-$(CONFIG_TCP_CONG_LP) += tcp_lp.o
  134. obj-$(CONFIG_TCP_CONG_YEAH) += tcp_yeah.o
  135. obj-$(CONFIG_TCP_CONG_ILLINOIS) += tcp_illinois.o
  136. +obj-$(CONFIG_TCP_FASTOPEN) += tcp_fastopen.o
  137. obj-$(CONFIG_MEMCG_KMEM) += tcp_memcontrol.o
  138. obj-$(CONFIG_NETLABEL) += cipso_ipv4.o
  139. diff -Nur linux-3.10.40.orig/net/ipv4/sysctl_net_ipv4.c linux-3.10.40/net/ipv4/sysctl_net_ipv4.c
  140. --- linux-3.10.40.orig/net/ipv4/sysctl_net_ipv4.c 2014-05-13 14:00:04.000000000 +0200
  141. +++ linux-3.10.40/net/ipv4/sysctl_net_ipv4.c 2014-05-30 17:00:16.000000000 +0200
  142. @@ -236,6 +236,7 @@
  143. return 0;
  144. }
  145. +#ifdef CONFIG_TCP_FASTOPEN
  146. static int proc_tcp_fastopen_key(ctl_table *ctl, int write, void __user *buffer,
  147. size_t *lenp, loff_t *ppos)
  148. {
  149. @@ -276,6 +277,7 @@
  150. kfree(tbl.data);
  151. return ret;
  152. }
  153. +#endif
  154. static struct ctl_table ipv4_table[] = {
  155. {
  156. @@ -425,6 +427,7 @@
  157. .proc_handler = proc_dointvec
  158. },
  159. #endif
  160. +#ifdef CONFIG_TCP_FASTOPEN
  161. {
  162. .procname = "tcp_fastopen",
  163. .data = &sysctl_tcp_fastopen,
  164. @@ -438,6 +441,7 @@
  165. .maxlen = ((TCP_FASTOPEN_KEY_LENGTH * 2) + 10),
  166. .proc_handler = proc_tcp_fastopen_key,
  167. },
  168. +#endif
  169. {
  170. .procname = "tcp_tw_recycle",
  171. .data = &tcp_death_row.sysctl_tw_recycle,
  172. diff -Nur linux-3.10.40.orig/net/ipv4/tcp.c linux-3.10.40/net/ipv4/tcp.c
  173. --- linux-3.10.40.orig/net/ipv4/tcp.c 2014-05-13 14:00:04.000000000 +0200
  174. +++ linux-3.10.40/net/ipv4/tcp.c 2014-05-30 15:41:44.000000000 +0200
  175. @@ -993,6 +993,7 @@
  176. return tmp;
  177. }
  178. +#ifdef CONFIG_TCP_FASTOPEN
  179. void tcp_free_fastopen_req(struct tcp_sock *tp)
  180. {
  181. if (tp->fastopen_req != NULL) {
  182. @@ -1026,6 +1027,7 @@
  183. tcp_free_fastopen_req(tp);
  184. return err;
  185. }
  186. +#endif
  187. int tcp_sendmsg(struct kiocb *iocb, struct sock *sk, struct msghdr *msg,
  188. size_t size)
  189. @@ -1041,6 +1043,7 @@
  190. lock_sock(sk);
  191. flags = msg->msg_flags;
  192. +#ifdef CONFIG_TCP_FASTOPEN
  193. if (flags & MSG_FASTOPEN) {
  194. err = tcp_sendmsg_fastopen(sk, msg, &copied_syn, size);
  195. if (err == -EINPROGRESS && copied_syn > 0)
  196. @@ -1049,6 +1052,7 @@
  197. goto out_err;
  198. offset = copied_syn;
  199. }
  200. +#endif
  201. timeo = sock_sndtimeo(sk, flags & MSG_DONTWAIT);
  202. diff -Nur linux-3.10.40.orig/net/ipv4/tcp_ipv4.c linux-3.10.40/net/ipv4/tcp_ipv4.c
  203. --- linux-3.10.40.orig/net/ipv4/tcp_ipv4.c 2014-05-13 14:00:04.000000000 +0200
  204. +++ linux-3.10.40/net/ipv4/tcp_ipv4.c 2014-05-30 15:41:44.000000000 +0200
  205. @@ -1285,6 +1285,7 @@
  206. };
  207. #endif
  208. +#ifdef CONFIG_TCP_FASTOPEN
  209. static bool tcp_fastopen_check(struct sock *sk, struct sk_buff *skb,
  210. struct request_sock *req,
  211. struct tcp_fastopen_cookie *foc,
  212. @@ -1461,6 +1462,23 @@
  213. WARN_ON(req->sk == NULL);
  214. return 0;
  215. }
  216. +#else
  217. +static bool tcp_fastopen_check(struct sock *sk, struct sk_buff *skb,
  218. + struct request_sock *req,
  219. + struct tcp_fastopen_cookie *foc,
  220. + struct tcp_fastopen_cookie *valid_foc)
  221. +{
  222. + return false;
  223. +}
  224. +
  225. +static int tcp_v4_conn_req_fastopen(struct sock *sk,
  226. + struct sk_buff *skb,
  227. + struct sk_buff *skb_synack,
  228. + struct request_sock *req)
  229. +{
  230. + return 0;
  231. +}
  232. +#endif
  233. int tcp_v4_conn_request(struct sock *sk, struct sk_buff *skb)
  234. {