From 9bba0f61438bc128c0b442101ccb4620ae583a9b Mon Sep 17 00:00:00 2001 From: Elizabeth Myers Date: Sat, 2 Apr 2016 03:33:12 -0500 Subject: [PATCH] opm: add adjustable timeout values --- doc/ircd.conf.example | 7 +++++++ doc/reference.conf | 7 +++++++ ircd/newconf.c | 27 +++++++++++++++++++++++---- 3 files changed, 37 insertions(+), 4 deletions(-) diff --git a/doc/ircd.conf.example b/doc/ircd.conf.example index 0ad8bf32..f048d207 100644 --- a/doc/ircd.conf.example +++ b/doc/ircd.conf.example @@ -466,6 +466,13 @@ opm { */ 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 * with other scan types. Sensible defaults are given below. */ diff --git a/doc/reference.conf b/doc/reference.conf index 5d37ed5e..1acc1db4 100644 --- a/doc/reference.conf +++ b/doc/reference.conf @@ -941,6 +941,13 @@ opm { */ 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 * with other scan types. Sensible defaults are given below. */ diff --git a/ircd/newconf.c b/ircd/newconf.c index c3a8fb00..d605bfdd 100644 --- a/ircd/newconf.c +++ b/ircd/newconf.c @@ -63,6 +63,7 @@ static char *yy_opm_address_ipv4 = NULL; static char *yy_opm_address_ipv6 = NULL; static uint16_t yy_opm_port_ipv4 = 0; static uint16_t yy_opm_port_ipv6 = 0; +static int yy_opm_timeout = 0; static rb_dlink_list yy_opm_scanner_list; static char *yy_privset_extends = NULL; @@ -382,9 +383,9 @@ static struct mode_table shared_table[] = { "kline", SHARED_PKLINE|SHARED_TKLINE }, { "xline", SHARED_PXLINE|SHARED_TXLINE }, { "resv", SHARED_PRESV|SHARED_TRESV }, - { "dline", SHARED_PDLINE|SHARED_TDLINE }, - { "tdline", SHARED_TDLINE }, - { "pdline", SHARED_PDLINE }, + { "dline", SHARED_PDLINE|SHARED_TDLINE }, + { "tdline", SHARED_TDLINE }, + { "pdline", SHARED_PDLINE }, { "undline", SHARED_UNDLINE }, { "tkline", SHARED_TKLINE }, { "unkline", SHARED_UNKLINE }, @@ -2041,7 +2042,7 @@ static int conf_begin_opm(struct TopConf *tc) { 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; } @@ -2089,6 +2090,10 @@ conf_end_opm(struct TopConf *tc) /* If there's no listeners... */ 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: RB_DLINK_FOREACH_SAFE(ptr, nptr, yy_opm_scanner_list.head) { @@ -2106,6 +2111,19 @@ end: 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 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_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_ipv6", CF_QSTRING, conf_set_opm_listen_address_ipv6); add_conf_item("opm", "port_v4", CF_INT, conf_set_opm_listen_port_ipv4);