[PATCH 1 of 1] Added support for TCP_FASTOPEN supported in Linux >= 3.7.1
Mathew Rodley
mathew at rodley.com.au
Sun Dec 1 20:28:57 UTC 2013
# HG changeset patch
# User Mathew Rodley <mathew at rodley.com.au>
# Date 1383380887 25200
# Sat Nov 02 01:28:07 2013 -0700
# Node ID 39e094bd562ab019846906227b1fb0f8337a4ac7
# Parent dea321e5c0216efccbb23e84bbce7cf3e28f130c
Added support for TCP_FASTOPEN supported in Linux >= 3.7.1
---
auto/unix | 12 ++++++++++++
src/core/ngx_connection.c | 32 ++++++++++++++++++++++++++++++++
src/core/ngx_connection.h | 4 ++++
src/http/ngx_http.c | 4 ++++
src/http/ngx_http_core_module.c | 21 +++++++++++++++++++++
src/http/ngx_http_core_module.h | 3 +++
6 files changed, 76 insertions(+)
diff -r dea321e5c021 -r 39e094bd562a auto/unix
--- a/auto/unix Thu Oct 31 18:23:49 2013 +0400
+++ b/auto/unix Sat Nov 02 01:28:07 2013 -0700
@@ -344,6 +344,18 @@
. auto/feature
+ngx_feature="TCP_FASTOPEN"
+ngx_feature_name="NGX_HAVE_TCPFASTOPEN"
+ngx_feature_run=no
+ngx_feature_incs="#include <sys/socket.h>
+ #include <netinet/in.h>
+ #include <netinet/tcp.h>"
+ngx_feature_path=
+ngx_feature_libs=
+ngx_feature_test="setsockopt(0, IPPROTO_TCP, TCP_FASTOPEN, NULL, 0)"
+. auto/feature
+
+
ngx_feature="TCP_INFO"
ngx_feature_name="NGX_HAVE_TCP_INFO"
ngx_feature_run=no
diff -r dea321e5c021 -r 39e094bd562a src/core/ngx_connection.c
--- a/src/core/ngx_connection.c Thu Oct 31 18:23:49 2013 +0400
+++ b/src/core/ngx_connection.c Sat Nov 02 01:28:07 2013 -0700
@@ -82,6 +82,10 @@
ls->setfib = -1;
#endif
+#if (NGX_HAVE_TCPFASTOPEN)
+ ls->fastopen = -1;
+#endif
+
return ls;
}
@@ -209,6 +213,21 @@
#endif
#endif
+#if (NGX_HAVE_TCPFASTOPEN)
+
+ if (getsockopt(ls[i].fastopen, IPPROTO_TCP, TCP_FASTOPEN,
+ (void *) &ls[i].fastopen, &olen)
+ == -1)
+ {
+ ngx_log_error(NGX_LOG_ALERT, cycle->log, ngx_socket_errno,
+ "getsockopt(TCP_FASTOPEN) %V failed, ignored",
+ &ls[i].addr_text);
+
+ ls[i].fastopen = -1;
+ }
+
+#endif
+
#if (NGX_HAVE_DEFERRED_ACCEPT && defined SO_ACCEPTFILTER)
ngx_memzero(&af, sizeof(struct accept_filter_arg));
@@ -582,6 +601,19 @@
}
#endif
+#if (NGX_HAVE_TCPFASTOPEN)
+ if (ls[i].fastopen != -1) {
+ if (setsockopt(ls[i].fd, IPPROTO_TCP, TCP_FASTOPEN,
+ (const int*) &ls[i].fastopen, sizeof(int))
+ == -1)
+ {
+ ngx_log_error(NGX_LOG_ALERT, cycle->log, ngx_socket_errno,
+ "setsockopt(TCP_FASTOPEN, %d) %V failed, ignored",
+ ls[i].fastopen, &ls[i].addr_text);
+ }
+ }
+#endif
+
#if 0
if (1) {
int tcp_nodelay = 1;
diff -r dea321e5c021 -r 39e094bd562a src/core/ngx_connection.h
--- a/src/core/ngx_connection.h Thu Oct 31 18:23:49 2013 +0400
+++ b/src/core/ngx_connection.h Sat Nov 02 01:28:07 2013 -0700
@@ -80,6 +80,10 @@
int setfib;
#endif
+#if (NGX_HAVE_TCPFASTOPEN)
+ int fastopen;
+#endif
+
};
diff -r dea321e5c021 -r 39e094bd562a src/http/ngx_http.c
--- a/src/http/ngx_http.c Thu Oct 31 18:23:49 2013 +0400
+++ b/src/http/ngx_http.c Sat Nov 02 01:28:07 2013 -0700
@@ -1811,6 +1811,10 @@
ls->setfib = addr->opt.setfib;
#endif
+#if (NGX_HAVE_TCPFASTOPEN)
+ ls->fastopen = addr->opt.fastopen;
+#endif
+
return ls;
}
diff -r dea321e5c021 -r 39e094bd562a src/http/ngx_http_core_module.c
--- a/src/http/ngx_http_core_module.c Thu Oct 31 18:23:49 2013 +0400
+++ b/src/http/ngx_http_core_module.c Sat Nov 02 01:28:07 2013 -0700
@@ -3041,6 +3041,9 @@
#if (NGX_HAVE_SETFIB)
lsopt.setfib = -1;
#endif
+#if (NGX_HAVE_TCPFASTOPEN)
+ lsopt.fastopen = -1;
+#endif
lsopt.wildcard = 1;
(void) ngx_sock_ntop(&lsopt.u.sockaddr, lsopt.socklen, lsopt.addr,
@@ -3989,6 +3992,9 @@
#if (NGX_HAVE_SETFIB)
lsopt.setfib = -1;
#endif
+#if (NGX_HAVE_TCPFASTOPEN)
+ lsopt.fastopen = -1;
+#endif
lsopt.wildcard = u.wildcard;
#if (NGX_HAVE_INET6 && defined IPV6_V6ONLY)
lsopt.ipv6only = 1;
@@ -4025,6 +4031,21 @@
continue;
}
#endif
+
+#if (NGX_HAVE_TCPFASTOPEN)
+ if (ngx_strncmp(value[n].data, "fastopen=", 9) == 0) {
+ lsopt.fastopen = ngx_atoi(value[n].data + 9, value[n].len - 9);
+
+ if (lsopt.fastopen == NGX_ERROR) {
+ ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
+ "invalid fastopen \"%V\"", &value[n]);
+ return NGX_CONF_ERROR;
+ }
+
+ continue;
+ }
+#endif
+
if (ngx_strncmp(value[n].data, "backlog=", 8) == 0) {
lsopt.backlog = ngx_atoi(value[n].data + 8, value[n].len - 8);
lsopt.set = 1;
diff -r dea321e5c021 -r 39e094bd562a src/http/ngx_http_core_module.h
--- a/src/http/ngx_http_core_module.h Thu Oct 31 18:23:49 2013 +0400
+++ b/src/http/ngx_http_core_module.h Sat Nov 02 01:28:07 2013 -0700
@@ -89,6 +89,9 @@
#if (NGX_HAVE_SETFIB)
int setfib;
#endif
+#if (NGX_HAVE_TCPFASTOPEN)
+ int fastopen;
+#endif
#if (NGX_HAVE_KEEPALIVE_TUNABLE)
int tcp_keepidle;
int tcp_keepintvl;
More information about the nginx-devel
mailing list