git ssb

0+

cel / sslh



Commit 414ed7de1108da241c640db0319e0b18a3d5b4c8

Support keepalive for connections on the connecting side

Yves Rutschle committed on 2/4/2016, 8:19:54 AM
Parent: 1b9937b293a932bf394da6623075b35b5e7bd9d2

Files changed

ChangeLogchanged
common.cchanged
probe.cchanged
probe.hchanged
sslh-main.cchanged
ChangeLogView
@@ -14,8 +14,9 @@
1414 example.cfg)
1515 Added 'log_level' option to each protocol, which
1616 allows to turn off generation of log at each
1717 connection.
18+ Added 'keepalive' option.
1819
1920 v1.17: 09MAR2015
2021 Support RFC5952-style IPv6 addresses, e.g. [::]:443.
2122
common.cView
@@ -154,9 +154,9 @@
154154 {
155155 struct addrinfo *a, from;
156156 struct sockaddr_storage ss;
157157 char buf[NI_MAXHOST];
158- int fd, res;
158+ int fd, res, one;
159159
160160 memset(&from, 0, sizeof(from));
161161 from.ai_addr = (struct sockaddr*)&ss;
162162 from.ai_addrlen = sizeof(ss);
@@ -188,8 +188,14 @@
188188 log_message(LOG_ERR, "forward to %s failed:connect: %s\n",
189189 cnx->proto->description, strerror(errno));
190190 close(fd);
191191 } else {
192+ if (cnx->proto->keepalive) {
193+ one = 1;
194+ res = setsockopt(fd, SOL_SOCKET, SO_KEEPALIVE, (char*)&one, sizeof(one));
195+ CHECK_RES_RETURN(res, "setsockopt(SO_KEEPALIVE)");
196+ printf("set up keepalive\n");
197+ }
192198 return fd;
193199 }
194200 }
195201 }
probe.cView
@@ -44,18 +44,18 @@
4444
4545 /* Table of protocols that have a built-in probe
4646 */
4747 static struct proto builtins[] = {
48- /* description service saddr log_level probe */
49- { "ssh", "sshd", NULL, 1, is_ssh_protocol},
50- { "openvpn", NULL, NULL, 1, is_openvpn_protocol },
51- { "tinc", NULL, NULL, 1, is_tinc_protocol },
52- { "xmpp", NULL, NULL, 1, is_xmpp_protocol },
53- { "http", NULL, NULL, 1, is_http_protocol },
54- { "ssl", NULL, NULL, 1, is_tls_protocol },
55- { "tls", NULL, NULL, 1, is_tls_protocol },
56- { "adb", NULL, NULL, 1, is_adb_protocol },
57- { "anyprot", NULL, NULL, 1, is_true }
48+ /* description service saddr log_level keepalive probe */
49+ { "ssh", "sshd", NULL, 1, 0, is_ssh_protocol},
50+ { "openvpn", NULL, NULL, 1, 0, is_openvpn_protocol },
51+ { "tinc", NULL, NULL, 1, 0, is_tinc_protocol },
52+ { "xmpp", NULL, NULL, 1, 0, is_xmpp_protocol },
53+ { "http", NULL, NULL, 1, 0, is_http_protocol },
54+ { "ssl", NULL, NULL, 1, 0, is_tls_protocol },
55+ { "tls", NULL, NULL, 1, 0, is_tls_protocol },
56+ { "adb", NULL, NULL, 1, 0, is_adb_protocol },
57+ { "anyprot", NULL, NULL, 1, 0, is_true }
5858 };
5959
6060 static struct proto *protocols;
6161 static char* on_timeout = "ssh";
probe.hView
@@ -22,8 +22,9 @@
2222 struct addrinfo *saddr; /* list of addresses to try and switch that protocol */
2323 int log_level; /* 0: No logging of connection
2424 * 1: Log incoming connection
2525 */
26+ int keepalive; /* 0: No keepalive ; 1: Set Keepalive for this connection */
2627
2728 /* function to probe that protocol; parameters are buffer and length
2829 * containing the data to probe, and a pointer to the protocol structure */
2930 T_PROBE* probe;
sslh-main.cView
@@ -122,22 +122,23 @@
122122 struct proto *p;
123123
124124 for (p = get_first_protocol(); p; p = p->next) {
125125 fprintf(stderr,
126- "%s addr: %s. libwrap service: %s log_level: %d family %d %d\n",
126+ "%s addr: %s. libwrap service: %s log_level: %d family %d %d [%s]\n",
127127 p->description,
128128 sprintaddr(buf, sizeof(buf), p->saddr),
129129 p->service,
130130 p->log_level,
131131 p->saddr->ai_family,
132- p->saddr->ai_addr->sa_family);
132+ p->saddr->ai_addr->sa_family,
133+ p->keepalive ? "keepalive" : "");
133134 }
134135 fprintf(stderr, "listening on:\n");
135136 for (a = addr_listen; a; a = a->ai_next) {
136137 fprintf(stderr,
137- "\t%s\t[keepalive: %d]\n",
138+ "\t%s\t[%s]\n",
138139 sprintaddr(buf, sizeof(buf), a),
139- a->ai_flags & SO_KEEPALIVE ? 1 : 0);
140+ a->ai_flags & SO_KEEPALIVE ? "keepalive" : "");
140141 }
141142 fprintf(stderr, "timeout: %d\non-timeout: %s\n", probing_timeout,
142143 timeout_protocol()->description);
143144 }
@@ -298,8 +299,9 @@
298299 config_setting_lookup_string(prot, "port", &port)
299300 )) {
300301 p->description = name;
301302 config_setting_lookup_string(prot, "service", &(p->service));
303+ config_setting_lookup_bool(prot, "keepalive", &p->keepalive);
302304
303305 if (config_setting_lookup_int(prot, "log_level", &p->log_level) == CONFIG_FALSE) {
304306 p->log_level = 1;
305307 }

Built with git-ssb-web