1
0

tcp-fastopen.patch 7.9 KB

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