make udp timeout configurable per protocol

This commit is contained in:
yrutschle 2021-07-08 14:13:04 +02:00
parent e7df8eeaa1
commit de0ec959d9
7 changed files with 42 additions and 21 deletions

View File

@ -1,5 +1,5 @@
/* Generated by conf2struct (https://www.rutschle.net/tech/conf2struct/README)
* on Wed Jun 23 11:46:47 2021.
* on Thu Jul 8 13:25:39 2021.
# conf2struct: generate libconf parsers that read to structs
# Copyright (C) 2018-2019 Yves Rutschle

View File

@ -1,5 +1,5 @@
/* Generated by conf2struct (https://www.rutschle.net/tech/conf2struct/README)
* on Wed Jun 23 11:46:47 2021.
* on Thu Jul 8 13:25:39 2021.
# conf2struct: generate libconf parsers that read to structs
# Copyright (C) 2018-2019 Yves Rutschle

View File

@ -1,5 +1,5 @@
/* Generated by conf2struct (https://www.rutschle.net/tech/conf2struct/README)
* on Wed Jun 23 11:46:45 2021.
* on Thu Jul 8 13:25:38 2021.
# conf2struct: generate libconf parsers that read to structs
# Copyright (C) 2018-2019 Yves Rutschle
@ -462,7 +462,7 @@ struct arg_file* sslhcfg_conffile;
struct arg_str* sslhcfg_anyprot;
struct arg_end* sslhcfg_end;
static struct config_desc table_sslhcfg_protocols[] = {
@ -546,6 +546,22 @@ static struct config_desc table_sslhcfg_protocols[] = {
/* default_val*/ .default_val.def_bool = 0
},
{
/* name */ "udp_timeout",
/* type */ CFG_INT,
/* sub_group*/ NULL,
/* arg_cl */ NULL,
/* base_addr */ NULL,
/* offset */ offsetof(struct sslhcfg_protocols_item, udp_timeout),
/* offset_len */ 0,
/* offset_present */ 0,
/* size */ sizeof(int),
/* array_type */ -1,
/* mandatory */ 0,
/* optional */ 0,
/* default_val*/ .default_val.def_int = 60
},
{
/* name */ "fork",
/* type */ CFG_BOOL,
@ -993,7 +1009,7 @@ static struct compound_cl_target sslhcfg_anyprot_targets [] = {
{ & table_sslhcfg_protocols[0], 0, .value.def_string = "anyprot" },
{ & table_sslhcfg_protocols[1], 1, .value.def_string = "0" },
{ & table_sslhcfg_protocols[2], 2, .value.def_string = "0" },
{ & table_sslhcfg_protocols[8], 0, .value.def_int = 1 },
{ & table_sslhcfg_protocols[9], 0, .value.def_int = 1 },
{ 0 }
};
@ -1001,7 +1017,7 @@ static struct compound_cl_target sslhcfg_socks5_targets [] = {
{ & table_sslhcfg_protocols[0], 0, .value.def_string = "socks5" },
{ & table_sslhcfg_protocols[1], 1, .value.def_string = "0" },
{ & table_sslhcfg_protocols[2], 2, .value.def_string = "0" },
{ & table_sslhcfg_protocols[8], 0, .value.def_int = 1 },
{ & table_sslhcfg_protocols[9], 0, .value.def_int = 1 },
{ 0 }
};
@ -1009,7 +1025,7 @@ static struct compound_cl_target sslhcfg_adb_targets [] = {
{ & table_sslhcfg_protocols[0], 0, .value.def_string = "adb" },
{ & table_sslhcfg_protocols[1], 1, .value.def_string = "0" },
{ & table_sslhcfg_protocols[2], 2, .value.def_string = "0" },
{ & table_sslhcfg_protocols[8], 0, .value.def_int = 1 },
{ & table_sslhcfg_protocols[9], 0, .value.def_int = 1 },
{ 0 }
};
@ -1017,7 +1033,7 @@ static struct compound_cl_target sslhcfg_http_targets [] = {
{ & table_sslhcfg_protocols[0], 0, .value.def_string = "http" },
{ & table_sslhcfg_protocols[1], 1, .value.def_string = "0" },
{ & table_sslhcfg_protocols[2], 2, .value.def_string = "0" },
{ & table_sslhcfg_protocols[8], 0, .value.def_int = 1 },
{ & table_sslhcfg_protocols[9], 0, .value.def_int = 1 },
{ 0 }
};
@ -1025,7 +1041,7 @@ static struct compound_cl_target sslhcfg_xmpp_targets [] = {
{ & table_sslhcfg_protocols[0], 0, .value.def_string = "xmpp" },
{ & table_sslhcfg_protocols[1], 1, .value.def_string = "0" },
{ & table_sslhcfg_protocols[2], 2, .value.def_string = "0" },
{ & table_sslhcfg_protocols[8], 0, .value.def_int = 1 },
{ & table_sslhcfg_protocols[9], 0, .value.def_int = 1 },
{ 0 }
};
@ -1033,8 +1049,8 @@ static struct compound_cl_target sslhcfg_tinc_targets [] = {
{ & table_sslhcfg_protocols[0], 0, .value.def_string = "tinc" },
{ & table_sslhcfg_protocols[1], 1, .value.def_string = "0" },
{ & table_sslhcfg_protocols[2], 2, .value.def_string = "0" },
{ & table_sslhcfg_protocols[8], 0, .value.def_int = 1 },
{ & table_sslhcfg_protocols[6], 0, .value.def_bool = 1 },
{ & table_sslhcfg_protocols[9], 0, .value.def_int = 1 },
{ & table_sslhcfg_protocols[7], 0, .value.def_bool = 1 },
{ 0 }
};
@ -1042,8 +1058,8 @@ static struct compound_cl_target sslhcfg_openvpn_targets [] = {
{ & table_sslhcfg_protocols[0], 0, .value.def_string = "openvpn" },
{ & table_sslhcfg_protocols[1], 1, .value.def_string = "0" },
{ & table_sslhcfg_protocols[2], 2, .value.def_string = "0" },
{ & table_sslhcfg_protocols[8], 0, .value.def_int = 1 },
{ & table_sslhcfg_protocols[6], 0, .value.def_bool = 1 },
{ & table_sslhcfg_protocols[9], 0, .value.def_int = 1 },
{ & table_sslhcfg_protocols[7], 0, .value.def_bool = 1 },
{ 0 }
};
@ -1051,8 +1067,8 @@ static struct compound_cl_target sslhcfg_tls_targets [] = {
{ & table_sslhcfg_protocols[0], 0, .value.def_string = "tls" },
{ & table_sslhcfg_protocols[1], 1, .value.def_string = "0" },
{ & table_sslhcfg_protocols[2], 2, .value.def_string = "0" },
{ & table_sslhcfg_protocols[8], 0, .value.def_int = 1 },
{ & table_sslhcfg_protocols[6], 0, .value.def_bool = 1 },
{ & table_sslhcfg_protocols[9], 0, .value.def_int = 1 },
{ & table_sslhcfg_protocols[7], 0, .value.def_bool = 1 },
{ 0 }
};
@ -1060,9 +1076,9 @@ static struct compound_cl_target sslhcfg_ssh_targets [] = {
{ & table_sslhcfg_protocols[0], 0, .value.def_string = "ssh" },
{ & table_sslhcfg_protocols[1], 1, .value.def_string = "0" },
{ & table_sslhcfg_protocols[2], 2, .value.def_string = "0" },
{ & table_sslhcfg_protocols[5], 0, .value.def_bool = 1 },
{ & table_sslhcfg_protocols[8], 0, .value.def_int = 1 },
{ & table_sslhcfg_protocols[6], 0, .value.def_bool = 1 },
{ & table_sslhcfg_protocols[9], 0, .value.def_int = 1 },
{ & table_sslhcfg_protocols[7], 0, .value.def_bool = 1 },
{ 0 }
};
@ -1886,6 +1902,9 @@ static void sslhcfg_protocols_fprint(
fprintf(out, "is_udp: %d", sslhcfg_protocols->is_udp);
fprintf(out, "\n");
indent(out, depth);
fprintf(out, "udp_timeout: %d", sslhcfg_protocols->udp_timeout);
fprintf(out, "\n");
indent(out, depth);
fprintf(out, "fork: %d", sslhcfg_protocols->fork);
fprintf(out, "\n");
indent(out, depth);

View File

@ -1,5 +1,5 @@
/* Generated by conf2struct (https://www.rutschle.net/tech/conf2struct/README)
* on Wed Jun 23 11:46:45 2021.
* on Thu Jul 8 13:25:38 2021.
# conf2struct: generate libconf parsers that read to structs
# Copyright (C) 2018-2019 Yves Rutschle
@ -54,6 +54,7 @@ struct sslhcfg_protocols_item {
int service_is_present;
char* service;
int is_udp;
int udp_timeout;
int fork;
int tfo_ok;
int transparent;

View File

@ -77,6 +77,7 @@ config: {
{ name: "port"; type: "string"; var: true; },
{ name: "service"; type: "string"; optional: true; },
{ name: "is_udp"; type: "bool"; default: false },
{ name: "udp_timeout"; type: "int"; default: 60 },
{ name: "fork"; type: "bool"; default: false },
{ name: "tfo_ok"; type: "bool"; default: false;
description: "Set to true if this protocol supports TCP FAST OPEN" },

View File

@ -1,7 +1,7 @@
# Configuration file for testing (use both by sslh under
# test and the test script `t`)
verbose: 3;
verbose: 4;
foreground: true;
inetd: false;
numeric: true;
@ -32,6 +32,7 @@ protocols:
{ name: "xmpp"; host: "localhost"; port: "9009"; },
{ name: "adb"; host: "localhost"; port: "9010"; },
{ name: "regex"; host: "ip4-localhost"; is_udp: true; port: "9020";
udp_timeout: 30;
regex_patterns: [ "^foo" ];
},
{ name: "regex"; host: "localhost"; port: "9011";

View File

@ -130,14 +130,13 @@ void udp_s2c_forward(struct connection* cnx)
/* Checks if a connection timed out, in which case close the socket and return
* 1; otherwise return 0. */
#define UDP_TIMEOUT 60 /* Timeout before forgetting the connection, in seconds */
int udp_timedout(struct connection* cnx)
{
time_t now = time(NULL);
if (cnx->type != SOCK_DGRAM) return 0; /* Not a UDP connection */
if ((now - cnx->last_active > UDP_TIMEOUT)) {
if ((now - cnx->last_active > cnx->proto->udp_timeout)) {
close(cnx->target_sock);
if (cfg.verbose > 3)
fprintf(stderr, "disconnect timed out UDP %d\n", cnx->target_sock);