Commit 414ed7de1108da241c640db0319e0b18a3d5b4c8
Support keepalive for connections on the connecting side
Yves Rutschle committed on 2/4/2016, 8:19:54 AMParent: 1b9937b293a932bf394da6623075b35b5e7bd9d2
Files changed
ChangeLog | changed |
common.c | changed |
probe.c | changed |
probe.h | changed |
sslh-main.c | changed |
ChangeLog | ||
---|---|---|
@@ -14,8 +14,9 @@ | ||
14 | 14 | example.cfg) |
15 | 15 | Added 'log_level' option to each protocol, which |
16 | 16 | allows to turn off generation of log at each |
17 | 17 | connection. |
18 | + Added 'keepalive' option. | |
18 | 19 | |
19 | 20 | v1.17: 09MAR2015 |
20 | 21 | Support RFC5952-style IPv6 addresses, e.g. [::]:443. |
21 | 22 |
common.c | ||
---|---|---|
@@ -154,9 +154,9 @@ | ||
154 | 154 | { |
155 | 155 | struct addrinfo *a, from; |
156 | 156 | struct sockaddr_storage ss; |
157 | 157 | char buf[NI_MAXHOST]; |
158 | - int fd, res; | |
158 | + int fd, res, one; | |
159 | 159 | |
160 | 160 | memset(&from, 0, sizeof(from)); |
161 | 161 | from.ai_addr = (struct sockaddr*)&ss; |
162 | 162 | from.ai_addrlen = sizeof(ss); |
@@ -188,8 +188,14 @@ | ||
188 | 188 | log_message(LOG_ERR, "forward to %s failed:connect: %s\n", |
189 | 189 | cnx->proto->description, strerror(errno)); |
190 | 190 | close(fd); |
191 | 191 | } 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 | + } | |
192 | 198 | return fd; |
193 | 199 | } |
194 | 200 | } |
195 | 201 | } |
probe.c | ||
---|---|---|
@@ -44,18 +44,18 @@ | ||
44 | 44 | |
45 | 45 | /* Table of protocols that have a built-in probe |
46 | 46 | */ |
47 | 47 | 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 } | |
58 | 58 | }; |
59 | 59 | |
60 | 60 | static struct proto *protocols; |
61 | 61 | static char* on_timeout = "ssh"; |
probe.h | ||
---|---|---|
@@ -22,8 +22,9 @@ | ||
22 | 22 | struct addrinfo *saddr; /* list of addresses to try and switch that protocol */ |
23 | 23 | int log_level; /* 0: No logging of connection |
24 | 24 | * 1: Log incoming connection |
25 | 25 | */ |
26 | + int keepalive; /* 0: No keepalive ; 1: Set Keepalive for this connection */ | |
26 | 27 | |
27 | 28 | /* function to probe that protocol; parameters are buffer and length |
28 | 29 | * containing the data to probe, and a pointer to the protocol structure */ |
29 | 30 | T_PROBE* probe; |
sslh-main.c | ||
---|---|---|
@@ -122,22 +122,23 @@ | ||
122 | 122 | struct proto *p; |
123 | 123 | |
124 | 124 | for (p = get_first_protocol(); p; p = p->next) { |
125 | 125 | 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", | |
127 | 127 | p->description, |
128 | 128 | sprintaddr(buf, sizeof(buf), p->saddr), |
129 | 129 | p->service, |
130 | 130 | p->log_level, |
131 | 131 | p->saddr->ai_family, |
132 | - p->saddr->ai_addr->sa_family); | |
132 | + p->saddr->ai_addr->sa_family, | |
133 | + p->keepalive ? "keepalive" : ""); | |
133 | 134 | } |
134 | 135 | fprintf(stderr, "listening on:\n"); |
135 | 136 | for (a = addr_listen; a; a = a->ai_next) { |
136 | 137 | fprintf(stderr, |
137 | - "\t%s\t[keepalive: %d]\n", | |
138 | + "\t%s\t[%s]\n", | |
138 | 139 | sprintaddr(buf, sizeof(buf), a), |
139 | - a->ai_flags & SO_KEEPALIVE ? 1 : 0); | |
140 | + a->ai_flags & SO_KEEPALIVE ? "keepalive" : ""); | |
140 | 141 | } |
141 | 142 | fprintf(stderr, "timeout: %d\non-timeout: %s\n", probing_timeout, |
142 | 143 | timeout_protocol()->description); |
143 | 144 | } |
@@ -298,8 +299,9 @@ | ||
298 | 299 | config_setting_lookup_string(prot, "port", &port) |
299 | 300 | )) { |
300 | 301 | p->description = name; |
301 | 302 | config_setting_lookup_string(prot, "service", &(p->service)); |
303 | + config_setting_lookup_bool(prot, "keepalive", &p->keepalive); | |
302 | 304 | |
303 | 305 | if (config_setting_lookup_int(prot, "log_level", &p->log_level) == CONFIG_FALSE) { |
304 | 306 | p->log_level = 1; |
305 | 307 | } |
Built with git-ssb-web