git ssb

0+

cel / sslh



Commit 1b9937b293a932bf394da6623075b35b5e7bd9d2

Support keepalive for connections on the listening side

Yves Rutschle committed on 2/2/2016, 8:07:47 PM
Parent: 1814bcb43cdf455b847c17f1313eb35d73f94716

Files changed

common.cchanged
example.cfgchanged
sslh-main.cchanged
common.cView
@@ -86,8 +86,14 @@
8686 one = 1;
8787 res = setsockopt((*sockfd)[i], SOL_SOCKET, SO_REUSEADDR, (char*)&one, sizeof(one));
8888 check_res_dumpdie(res, addr, "setsockopt(SO_REUSEADDR)");
8989
90+ if (addr->ai_flags & SO_KEEPALIVE) {
91+ res = setsockopt((*sockfd)[i], SOL_SOCKET, SO_KEEPALIVE, (char*)&one, sizeof(one));
92+ check_res_dumpdie(res, addr, "setsockopt(SO_KEEPALIVE)");
93+ printf("set up keepalive\n");
94+ }
95+
9096 if (IP_FREEBIND) {
9197 res = setsockopt((*sockfd)[i], IPPROTO_IP, IP_FREEBIND, (char*)&one, sizeof(one));
9298 check_res_dumpdie(res, addr, "setsockopt(IP_FREEBIND)");
9399 }
example.cfgView
@@ -13,12 +13,13 @@
1313 pidfile: "/var/run/sslh.pid";
1414
1515
1616 # List of interfaces on which we should listen
17+# Options:
1718 listen:
1819 (
1920 { host: "thelonious"; port: "443"; },
20- { host: "thelonious"; port: "8080"; }
21+ { host: "thelonious"; port: "8080"; keepalive: true; }
2122 );
2223
2324 # List of protocols
2425 #
@@ -27,8 +28,12 @@
2728 # line (ssh -?), plus 'regex' and 'timeout'.
2829
2930 # service: (optional) libwrap service name (see hosts_access(5))
3031 # host, port: where to connect when this probe succeeds
32+# log_level: 0 to turn off logging
33+# 1 to log each incoming connection
34+# keepalive: Should TCP keepalive be on or off for that
35+# connection (default is off)
3136 #
3237 # Probe-specific options:
3338 # tls:
3439 # sni_hostnames: list of FQDN for that target
@@ -47,9 +52,9 @@
4752 # You can specify several of 'regex' and 'tls'.
4853
4954 protocols:
5055 (
51- { name: "ssh"; service: "ssh"; host: "localhost"; port: "22"; },
56+ { name: "ssh"; service: "ssh"; host: "localhost"; port: "22"; keepalive: true; },
5257 { name: "http"; host: "localhost"; port: "80"; },
5358
5459 # match BOTH ALPN/SNI
5560 { name: "tls"; host: "localhost"; port: "5223"; alpn_protocols: [ "xmpp-client" ]; sni_hostnames: [ "im.somethingelse.net" ]; log_level: 0;},
sslh-main.cView
@@ -1,9 +1,9 @@
11 /*
22 # main: processing of config file, command line options and start the main
33 # loop.
44 #
5-# Copyright (C) 2007-2014 Yves Rutschle
5+# Copyright (C) 2007-2016 Yves Rutschle
66 #
77 # This program is free software; you can redistribute it
88 # and/or modify it under the terms of the GNU General Public
99 # License as published by the Free Software Foundation; either
@@ -132,9 +132,12 @@
132132 p->saddr->ai_addr->sa_family);
133133 }
134134 fprintf(stderr, "listening on:\n");
135135 for (a = addr_listen; a; a = a->ai_next) {
136- fprintf(stderr, "\t%s\n", sprintaddr(buf, sizeof(buf), a));
136+ fprintf(stderr,
137+ "\t%s\t[keepalive: %d]\n",
138+ sprintaddr(buf, sizeof(buf), a),
139+ a->ai_flags & SO_KEEPALIVE ? 1 : 0);
137140 }
138141 fprintf(stderr, "timeout: %d\non-timeout: %s\n", probing_timeout,
139142 timeout_protocol()->description);
140143 }
@@ -146,9 +149,9 @@
146149 #ifdef LIBCONFIG
147150 static int config_listen(config_t *config, struct addrinfo **listen)
148151 {
149152 config_setting_t *setting, *addr;
150- int len, i;
153+ int len, i, keepalive;
151154 const char *hostname, *port;
152155
153156 setting = config_lookup(config, "listen");
154157 if (setting) {
@@ -162,14 +165,22 @@
162165 config_setting_source_line(addr));
163166 return -1;
164167 }
165168
169+ keepalive = 0;
170+ config_setting_lookup_bool(addr, "keepalive", &keepalive);
171+
166172 resolve_split_name(listen, hostname, port);
167173
168174 /* getaddrinfo returned a list of addresses corresponding to the
169175 * specification; move the pointer to the end of that list before
170- * processing the next specification */
171- for (; *listen; listen = &((*listen)->ai_next));
176+ * processing the next specification, while setting flags for
177+ * start_listen_sockets() through ai_flags (which is not meant for
178+ * that, but is only used as hint in getaddrinfo, so it's OK) */
179+ for (; *listen; listen = &((*listen)->ai_next)) {
180+ if (keepalive)
181+ (*listen)->ai_flags = SO_KEEPALIVE;
182+ }
172183 }
173184 }
174185
175186 return 0;

Built with git-ssb-web