mirror of
https://github.com/yrutschle/sslh.git
synced 2025-04-18 17:57:39 +03:00
Support keepalive for connections on the connecting side
This commit is contained in:
parent
1b9937b293
commit
414ed7de11
@ -15,6 +15,7 @@ vNEXT:
|
|||||||
Added 'log_level' option to each protocol, which
|
Added 'log_level' option to each protocol, which
|
||||||
allows to turn off generation of log at each
|
allows to turn off generation of log at each
|
||||||
connection.
|
connection.
|
||||||
|
Added 'keepalive' option.
|
||||||
|
|
||||||
v1.17: 09MAR2015
|
v1.17: 09MAR2015
|
||||||
Support RFC5952-style IPv6 addresses, e.g. [::]:443.
|
Support RFC5952-style IPv6 addresses, e.g. [::]:443.
|
||||||
|
8
common.c
8
common.c
@ -155,7 +155,7 @@ int connect_addr(struct connection *cnx, int fd_from)
|
|||||||
struct addrinfo *a, from;
|
struct addrinfo *a, from;
|
||||||
struct sockaddr_storage ss;
|
struct sockaddr_storage ss;
|
||||||
char buf[NI_MAXHOST];
|
char buf[NI_MAXHOST];
|
||||||
int fd, res;
|
int fd, res, one;
|
||||||
|
|
||||||
memset(&from, 0, sizeof(from));
|
memset(&from, 0, sizeof(from));
|
||||||
from.ai_addr = (struct sockaddr*)&ss;
|
from.ai_addr = (struct sockaddr*)&ss;
|
||||||
@ -189,6 +189,12 @@ int connect_addr(struct connection *cnx, int fd_from)
|
|||||||
cnx->proto->description, strerror(errno));
|
cnx->proto->description, strerror(errno));
|
||||||
close(fd);
|
close(fd);
|
||||||
} else {
|
} else {
|
||||||
|
if (cnx->proto->keepalive) {
|
||||||
|
one = 1;
|
||||||
|
res = setsockopt(fd, SOL_SOCKET, SO_KEEPALIVE, (char*)&one, sizeof(one));
|
||||||
|
CHECK_RES_RETURN(res, "setsockopt(SO_KEEPALIVE)");
|
||||||
|
printf("set up keepalive\n");
|
||||||
|
}
|
||||||
return fd;
|
return fd;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
20
probe.c
20
probe.c
@ -45,16 +45,16 @@ static int is_true(const char *p, int len, struct proto* proto) { return 1; }
|
|||||||
/* Table of protocols that have a built-in probe
|
/* Table of protocols that have a built-in probe
|
||||||
*/
|
*/
|
||||||
static struct proto builtins[] = {
|
static struct proto builtins[] = {
|
||||||
/* description service saddr log_level probe */
|
/* description service saddr log_level keepalive probe */
|
||||||
{ "ssh", "sshd", NULL, 1, is_ssh_protocol},
|
{ "ssh", "sshd", NULL, 1, 0, is_ssh_protocol},
|
||||||
{ "openvpn", NULL, NULL, 1, is_openvpn_protocol },
|
{ "openvpn", NULL, NULL, 1, 0, is_openvpn_protocol },
|
||||||
{ "tinc", NULL, NULL, 1, is_tinc_protocol },
|
{ "tinc", NULL, NULL, 1, 0, is_tinc_protocol },
|
||||||
{ "xmpp", NULL, NULL, 1, is_xmpp_protocol },
|
{ "xmpp", NULL, NULL, 1, 0, is_xmpp_protocol },
|
||||||
{ "http", NULL, NULL, 1, is_http_protocol },
|
{ "http", NULL, NULL, 1, 0, is_http_protocol },
|
||||||
{ "ssl", NULL, NULL, 1, is_tls_protocol },
|
{ "ssl", NULL, NULL, 1, 0, is_tls_protocol },
|
||||||
{ "tls", NULL, NULL, 1, is_tls_protocol },
|
{ "tls", NULL, NULL, 1, 0, is_tls_protocol },
|
||||||
{ "adb", NULL, NULL, 1, is_adb_protocol },
|
{ "adb", NULL, NULL, 1, 0, is_adb_protocol },
|
||||||
{ "anyprot", NULL, NULL, 1, is_true }
|
{ "anyprot", NULL, NULL, 1, 0, is_true }
|
||||||
};
|
};
|
||||||
|
|
||||||
static struct proto *protocols;
|
static struct proto *protocols;
|
||||||
|
1
probe.h
1
probe.h
@ -23,6 +23,7 @@ struct proto {
|
|||||||
int log_level; /* 0: No logging of connection
|
int log_level; /* 0: No logging of connection
|
||||||
* 1: Log incoming connection
|
* 1: Log incoming connection
|
||||||
*/
|
*/
|
||||||
|
int keepalive; /* 0: No keepalive ; 1: Set Keepalive for this connection */
|
||||||
|
|
||||||
/* function to probe that protocol; parameters are buffer and length
|
/* function to probe that protocol; parameters are buffer and length
|
||||||
* containing the data to probe, and a pointer to the protocol structure */
|
* containing the data to probe, and a pointer to the protocol structure */
|
||||||
|
10
sslh-main.c
10
sslh-main.c
@ -123,20 +123,21 @@ static void printsettings(void)
|
|||||||
|
|
||||||
for (p = get_first_protocol(); p; p = p->next) {
|
for (p = get_first_protocol(); p; p = p->next) {
|
||||||
fprintf(stderr,
|
fprintf(stderr,
|
||||||
"%s addr: %s. libwrap service: %s log_level: %d family %d %d\n",
|
"%s addr: %s. libwrap service: %s log_level: %d family %d %d [%s]\n",
|
||||||
p->description,
|
p->description,
|
||||||
sprintaddr(buf, sizeof(buf), p->saddr),
|
sprintaddr(buf, sizeof(buf), p->saddr),
|
||||||
p->service,
|
p->service,
|
||||||
p->log_level,
|
p->log_level,
|
||||||
p->saddr->ai_family,
|
p->saddr->ai_family,
|
||||||
p->saddr->ai_addr->sa_family);
|
p->saddr->ai_addr->sa_family,
|
||||||
|
p->keepalive ? "keepalive" : "");
|
||||||
}
|
}
|
||||||
fprintf(stderr, "listening on:\n");
|
fprintf(stderr, "listening on:\n");
|
||||||
for (a = addr_listen; a; a = a->ai_next) {
|
for (a = addr_listen; a; a = a->ai_next) {
|
||||||
fprintf(stderr,
|
fprintf(stderr,
|
||||||
"\t%s\t[keepalive: %d]\n",
|
"\t%s\t[%s]\n",
|
||||||
sprintaddr(buf, sizeof(buf), a),
|
sprintaddr(buf, sizeof(buf), a),
|
||||||
a->ai_flags & SO_KEEPALIVE ? 1 : 0);
|
a->ai_flags & SO_KEEPALIVE ? "keepalive" : "");
|
||||||
}
|
}
|
||||||
fprintf(stderr, "timeout: %d\non-timeout: %s\n", probing_timeout,
|
fprintf(stderr, "timeout: %d\non-timeout: %s\n", probing_timeout,
|
||||||
timeout_protocol()->description);
|
timeout_protocol()->description);
|
||||||
@ -299,6 +300,7 @@ static int config_protocols(config_t *config, struct proto **prots)
|
|||||||
)) {
|
)) {
|
||||||
p->description = name;
|
p->description = name;
|
||||||
config_setting_lookup_string(prot, "service", &(p->service));
|
config_setting_lookup_string(prot, "service", &(p->service));
|
||||||
|
config_setting_lookup_bool(prot, "keepalive", &p->keepalive);
|
||||||
|
|
||||||
if (config_setting_lookup_int(prot, "log_level", &p->log_level) == CONFIG_FALSE) {
|
if (config_setting_lookup_int(prot, "log_level", &p->log_level) == CONFIG_FALSE) {
|
||||||
p->log_level = 1;
|
p->log_level = 1;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user