Skip to content

Instantly share code, notes, and snippets.

@lkarsten
Created January 16, 2019 12:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lkarsten/0ca6d4bc4a6f01465da68b18b64503f1 to your computer and use it in GitHub Desktop.
Save lkarsten/0ca6d4bc4a6f01465da68b18b64503f1 to your computer and use it in GitHub Desktop.
From ebc04e28ee9aeff26e913c9c3982a4662bfe908e Mon Sep 17 00:00:00 2001
From: Lasse Karstensen <lasse.karstensen@gmail.com>
Date: Tue, 11 Dec 2018 16:17:43 +0100
Subject: [PATCH] WIP
---
src/configuration.c | 9 ++++++++-
src/configuration.h | 1 +
src/hitch.c | 22 +++++++++++++++++++---
3 files changed, 28 insertions(+), 4 deletions(-)
diff --git a/src/configuration.c b/src/configuration.c
index a43483a..60ac47f 100644
--- a/src/configuration.c
+++ b/src/configuration.c
@@ -78,6 +78,7 @@
#define CFG_SNI_NOMATCH_ABORT "sni-nomatch-abort"
#define CFG_OCSP_DIR "ocsp-dir"
#define CFG_TLS_PROTOS "tls-protos"
+#define CFG_FASTOPEN_ENABLED "enable-fastopen"
#ifdef USE_SHARED_CACHE
#define CFG_SHARED_CACHE "shared-cache"
@@ -228,6 +229,7 @@ config_new(void)
r->SYSLOG = 0;
r->SYSLOG_FACILITY = LOG_DAEMON;
r->TCP_KEEPALIVE_TIME = 3600;
+ r->TCP_FASTOPEN_ENABLED = -1;
r->BACKEND_REFRESH_TIME = 0;
r->DAEMONIZE = 0;
r->PREFER_SERVER_CIPHERS = 0;
@@ -856,6 +858,8 @@ config_param_validate(char *k, char *v, hitch_config *cfg,
r = config_param_val_int(v, &cfg->BACKLOG, 0);
} else if (strcmp(k, CFG_KEEPALIVE) == 0) {
r = config_param_val_int(v, &cfg->TCP_KEEPALIVE_TIME, 1);
+ } else if (strcmp(k, CFG_FASTOPEN_ENABLED) == 0) {
+ r = config_param_val_bool(v, &cfg->TCP_FASTOPEN_ENABLED);
} else if (strcmp(k, CFG_BACKEND_REFRESH) == 0) {
r = config_param_val_int(v, &cfg->BACKEND_REFRESH_TIME, 1);
}
@@ -1196,6 +1200,7 @@ config_print_usage_fd(char *prog, FILE *out)
fprintf(out, " (Note: brackets are mandatory in endpoint specifiers.)\n");
fprintf(out, " --recv-bufsize=SIZE Receive buffer size on client socket (Default: %d)\n", cfg->RECV_BUFSIZE);
fprintf(out, " --send-bufsize=SIZE Send buffer size on client socket (Default: %d)\n", cfg->SEND_BUFSIZE);
+ fprintf(out, " --enable-fastopen Turn on client-side TCP fastopen (TFO)\n");
#ifdef USE_SHARED_CACHE
fprintf(out, "\n");
@@ -1356,6 +1361,7 @@ config_parse_cli(int argc, char **argv, hitch_config *cfg)
#endif
{ CFG_PIDFILE, 1, NULL, 'p' },
{ CFG_KEEPALIVE, 1, NULL, 'k' },
+ { CFG_FASTOPEN_ENABLED, 0, NULL, 'F' },
{ CFG_BACKEND_REFRESH, 1, NULL, 'R' },
{ CFG_CHROOT, 1, NULL, 'r' },
{ CFG_USER, 1, NULL, 'u' },
@@ -1381,7 +1387,7 @@ config_parse_cli(int argc, char **argv, hitch_config *cfg)
{ "help", 0, NULL, 'h' },
{ 0, 0, 0, 0 }
};
-#define SHORT_OPTS "c:e:Ob:f:n:B:l:L:C:U:p:P:M:k:r:u:g:qstVho:R:"
+#define SHORT_OPTS "c:e:Ob:f:n:B:l:L:C:U:p:P:M:k:r:u:g:qstVho:R:F:"
if (argc == 1) {
config_print_usage(argv[0]);
@@ -1466,6 +1472,7 @@ CFG_ON('q', CFG_QUIET);
CFG_ARG('l', CFG_LOG_FILENAME);
CFG_ARG('L', CFG_LOG_LEVEL);
CFG_ON('s', CFG_SYSLOG);
+CFG_ON('F', CFG_FASTOPEN_ENABLED);
#undef CFG_ARG
#undef CFG_ON
case 't':
diff --git a/src/configuration.h b/src/configuration.h
index a441228..2058f58 100644
--- a/src/configuration.h
+++ b/src/configuration.h
@@ -131,6 +131,7 @@ struct __hitch_config {
int SYSLOG;
int SYSLOG_FACILITY;
int TCP_KEEPALIVE_TIME;
+ int TCP_FASTOPEN_ENABLED;
int BACKEND_REFRESH_TIME;
int DAEMONIZE;
int PREFER_SERVER_CIPHERS;
diff --git a/src/hitch.c b/src/hitch.c
index 5c05ce9..513e647 100644
--- a/src/hitch.c
+++ b/src/hitch.c
@@ -2401,10 +2401,26 @@ handle_accept(struct ev_loop *loop, ev_io *w, int revents)
}
#endif
+ LOG("{core} enabling fastopen: %i\n", CONFIG->TCP_FASTOPEN_ENABLED);
+ fprintf(stderr, "{core} enabling fastopen: %i\n", CONFIG->TCP_FASTOPEN_ENABLED);
+
#ifdef TCP_FASTOPEN
- int optval = 5;
- if (setsockopt(client, SOL_TCP, TCP_FASTOPEN, &optval, sizeof(optval)) < 0) {
- SOCKERR("Couldn't setsockopt on client (TCP_FASTOPEN)");
+ if (CONFIG->TCP_FASTOPEN_ENABLED >= 0) {
+
+ socklen_t ret;
+ getsockopt(client, SOL_TCP, TCP_FASTOPEN, &ret, 4);
+// int setsockopt(int sockfd, int level, int optname, const void *optval, socklen_t optlen);
+
+ fprintf(stderr, "{core} optval: %ul\n", ret);
+
+ int optval = 5;
+ if (setsockopt(client, SOL_TCP, TCP_FASTOPEN, &optval, sizeof(optval)) < 0) {
+ SOCKERR("Couldn't setsockopt on client (TCP_FASTOPEN)");
+ }
+/* getsockopt(client, SOL_TCP, TCP_FASTOPEN, &ret, ret);
+ fprintf(stderr, "{core} optval2: %ul\n", ret);
+ */
+
}
#endif
--
2.20.1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment