opm: add adjustable timeout values

This commit is contained in:
Elizabeth Myers 2016-04-02 03:33:12 -05:00
parent 34b88b6571
commit 9bba0f6143
3 changed files with 37 additions and 4 deletions

View file

@ -466,6 +466,13 @@ opm {
*/ */
port = 32000; port = 32000;
/* This sets the timeout in seconds before ending open proxy scans.
* Values less than 1 or greater than 60 are ignored.
* It is advisable to keep it as short as feasible, so clients do not
* get held up by excessively long scan times.
*/
timeout = 5;
/* These are the ports to scan for SOCKS4 proxies on. They may overlap /* These are the ports to scan for SOCKS4 proxies on. They may overlap
* with other scan types. Sensible defaults are given below. * with other scan types. Sensible defaults are given below.
*/ */

View file

@ -941,6 +941,13 @@ opm {
*/ */
port = 32000; port = 32000;
/* This sets the timeout in seconds before ending open proxy scans.
* Values less than 1 or greater than 60 are ignored.
* It is advisable to keep it as short as feasible, so clients do not
* get held up by excessively long scan times.
*/
timeout = 5;
/* These are the ports to scan for SOCKS4 proxies on. They may overlap /* These are the ports to scan for SOCKS4 proxies on. They may overlap
* with other scan types. Sensible defaults are given below. * with other scan types. Sensible defaults are given below.
*/ */

View file

@ -63,6 +63,7 @@ static char *yy_opm_address_ipv4 = NULL;
static char *yy_opm_address_ipv6 = NULL; static char *yy_opm_address_ipv6 = NULL;
static uint16_t yy_opm_port_ipv4 = 0; static uint16_t yy_opm_port_ipv4 = 0;
static uint16_t yy_opm_port_ipv6 = 0; static uint16_t yy_opm_port_ipv6 = 0;
static int yy_opm_timeout = 0;
static rb_dlink_list yy_opm_scanner_list; static rb_dlink_list yy_opm_scanner_list;
static char *yy_privset_extends = NULL; static char *yy_privset_extends = NULL;
@ -382,9 +383,9 @@ static struct mode_table shared_table[] =
{ "kline", SHARED_PKLINE|SHARED_TKLINE }, { "kline", SHARED_PKLINE|SHARED_TKLINE },
{ "xline", SHARED_PXLINE|SHARED_TXLINE }, { "xline", SHARED_PXLINE|SHARED_TXLINE },
{ "resv", SHARED_PRESV|SHARED_TRESV }, { "resv", SHARED_PRESV|SHARED_TRESV },
{ "dline", SHARED_PDLINE|SHARED_TDLINE }, { "dline", SHARED_PDLINE|SHARED_TDLINE },
{ "tdline", SHARED_TDLINE }, { "tdline", SHARED_TDLINE },
{ "pdline", SHARED_PDLINE }, { "pdline", SHARED_PDLINE },
{ "undline", SHARED_UNDLINE }, { "undline", SHARED_UNDLINE },
{ "tkline", SHARED_TKLINE }, { "tkline", SHARED_TKLINE },
{ "unkline", SHARED_UNKLINE }, { "unkline", SHARED_UNKLINE },
@ -2041,7 +2042,7 @@ static int
conf_begin_opm(struct TopConf *tc) conf_begin_opm(struct TopConf *tc)
{ {
yy_opm_address_ipv4 = yy_opm_address_ipv6 = NULL; yy_opm_address_ipv4 = yy_opm_address_ipv6 = NULL;
yy_opm_port_ipv4 = yy_opm_port_ipv6 = 0; yy_opm_port_ipv4 = yy_opm_port_ipv6 = yy_opm_timeout = 0;
return 0; return 0;
} }
@ -2089,6 +2090,10 @@ conf_end_opm(struct TopConf *tc)
/* If there's no listeners... */ /* If there's no listeners... */
fail = (yy_opm_port_ipv4 == 0 || yy_opm_port_ipv6 == 0); fail = (yy_opm_port_ipv4 == 0 || yy_opm_port_ipv6 == 0);
if(!fail && yy_opm_timeout > 0)
/* Send timeout */
set_authd_timeout("opm_timeout", yy_opm_timeout);
end: end:
RB_DLINK_FOREACH_SAFE(ptr, nptr, yy_opm_scanner_list.head) RB_DLINK_FOREACH_SAFE(ptr, nptr, yy_opm_scanner_list.head)
{ {
@ -2106,6 +2111,19 @@ end:
return 0; return 0;
} }
static void
conf_set_opm_timeout(void *data)
{
int timeout = *((int *)data);
if(timeout <= 0 || timeout > 60)
{
conf_report_error("opm::timeout value %d is bogus, ignoring", timeout);
return;
}
yy_opm_timeout = timeout;
}
static void static void
conf_set_opm_listen_address_both(void *data, bool ipv6) conf_set_opm_listen_address_both(void *data, bool ipv6)
@ -2827,6 +2845,7 @@ newconf_init()
add_conf_item("blacklist", "reject_reason", CF_QSTRING, conf_set_blacklist_reason); add_conf_item("blacklist", "reject_reason", CF_QSTRING, conf_set_blacklist_reason);
add_top_conf("opm", conf_begin_opm, conf_end_opm, NULL); add_top_conf("opm", conf_begin_opm, conf_end_opm, NULL);
add_conf_item("opm", "timeout", CF_INT, conf_set_opm_timeout);
add_conf_item("opm", "listen_ipv4", CF_QSTRING, conf_set_opm_listen_address_ipv4); add_conf_item("opm", "listen_ipv4", CF_QSTRING, conf_set_opm_listen_address_ipv4);
add_conf_item("opm", "listen_ipv6", CF_QSTRING, conf_set_opm_listen_address_ipv6); add_conf_item("opm", "listen_ipv6", CF_QSTRING, conf_set_opm_listen_address_ipv6);
add_conf_item("opm", "port_v4", CF_INT, conf_set_opm_listen_port_ipv4); add_conf_item("opm", "port_v4", CF_INT, conf_set_opm_listen_port_ipv4);