From: Amaury Denoyelle Date: Thu, 19 Oct 2023 07:25:20 +0000 (+0200) Subject: MINOR: listener: add nbconn kw for reverse connect X-Git-Tag: v2.9-dev8~10 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=3222047a148880a6e6270f7bc78b47a9ae5fb7d9;p=thirdparty%2Fhaproxy.git MINOR: listener: add nbconn kw for reverse connect Previously, maxconn keyword was reused for a specific usage on reverse HTTP binds to specify the number of active connect to proceed. To avoid confusion, introduce a new dedicated keyword 'nbconn' which is specific to reverse HTTP bind. This new keyword is forbidden for non-reverse listener. A fatal error is emitted during config parsing if this rule is not respected. It's safe because it's also forbidden to mix standard and reverse addresses on the same bind line. Internally, nbconn value will be reassigned to 'maxconn' member of bind_conf structure. This ensures that listener layer will automatically reenable the preconnect task each time a connection is closed. --- diff --git a/doc/configuration.txt b/doc/configuration.txt index 5f8d47323d..25683f4847 100644 --- a/doc/configuration.txt +++ b/doc/configuration.txt @@ -15332,6 +15332,11 @@ namespace a namespace different from the default one. Please refer to your operating system's documentation to find more details about network namespaces. +nbconn + This setting is only valid for listener instances which uses reverse HTTP. + This will define the count of connections which will be mounted in parallel. + If not specified, a default value of 1 is used. + nice Sets the 'niceness' of connections initiated from the socket. Value must be in the range -1024..1024 inclusive, and defaults to zero. Positive values diff --git a/include/haproxy/listener-t.h b/include/haproxy/listener-t.h index 8f7cbb13e7..bb43131769 100644 --- a/include/haproxy/listener-t.h +++ b/include/haproxy/listener-t.h @@ -209,6 +209,7 @@ struct bind_conf { char *file; /* file where the section appears */ int line; /* line where the section appears */ char *reverse_srvname; /* name of server when using "rev@" address */ + int reverse_nbconn; /* count of connections to initiate in parallel */ __decl_thread(HA_RWLOCK_T sni_lock); /* lock the SNI trees during add/del operations */ struct thread_set thread_set; /* entire set of the allowed threads (0=no restriction) */ struct rx_settings settings; /* all the settings needed for the listening socket */ diff --git a/src/listener.c b/src/listener.c index da483702ed..f812d9fad7 100644 --- a/src/listener.c +++ b/src/listener.c @@ -2241,6 +2241,33 @@ static int bind_parse_name(char **args, int cur_arg, struct proxy *px, struct bi return 0; } +/* parse the "nbconn" bind keyword */ +static int bind_parse_nbconn(char **args, int cur_arg, struct proxy *px, struct bind_conf *conf, char **err) +{ + int val; + const struct listener *l; + + l = LIST_NEXT(&conf->listeners, struct listener *, by_bind); + if (l->rx.addr.ss_family != AF_CUST_REV_SRV) { + memprintf(err, "'%s' : only valid for reverse HTTP listeners.", args[cur_arg]); + return ERR_ALERT | ERR_FATAL; + } + + if (!*args[cur_arg + 1]) { + memprintf(err, "'%s' : missing value.", args[cur_arg]); + return ERR_ALERT | ERR_FATAL; + } + + val = atol(args[cur_arg + 1]); + if (val <= 0) { + memprintf(err, "'%s' : invalid value %d, must be > 0.", args[cur_arg], val); + return ERR_ALERT | ERR_FATAL; + } + + conf->reverse_nbconn = val; + return 0; +} + /* parse the "nice" bind keyword */ static int bind_parse_nice(char **args, int cur_arg, struct proxy *px, struct bind_conf *conf, char **err) { @@ -2402,6 +2429,7 @@ static struct bind_kw_list bind_kws = { "ALL", { }, { { "id", bind_parse_id, 1 }, /* set id of listening socket */ { "maxconn", bind_parse_maxconn, 1 }, /* set maxconn of listening socket */ { "name", bind_parse_name, 1 }, /* set name of listening socket */ + { "nbconn", bind_parse_nbconn, 1 }, /* set number of connection on active preconnect */ { "nice", bind_parse_nice, 1 }, /* set nice of listening socket */ { "process", bind_parse_process, 1 }, /* set list of allowed process for this socket */ { "proto", bind_parse_proto, 1 }, /* set the proto to use for all incoming connections */ diff --git a/src/proto_reverse_connect.c b/src/proto_reverse_connect.c index ef9e40f469..293c13418e 100644 --- a/src/proto_reverse_connect.c +++ b/src/proto_reverse_connect.c @@ -204,9 +204,12 @@ int rev_bind_listener(struct listener *listener, char *errmsg, int errlen) listener->rx.reverse_connect.task = task; listener->rx.reverse_connect.state = LI_PRECONN_ST_STOP; - /* Set a default maxconn to 1. This ensures listener is properly - * reenable each time we fall back below it on connection error. + /* Set maxconn which is defined via the special kw nbconn for reverse + * connect. Use a default value of 1 if not set. This guarantees that + * listener will be automatically reenable each time it fell back below + * it due to a connection error. */ + listener->bind_conf->maxconn = listener->bind_conf->reverse_nbconn; if (!listener->bind_conf->maxconn) listener->bind_conf->maxconn = 1; @@ -286,7 +289,7 @@ void rev_disable_listener(struct listener *l) { if (l->rx.reverse_connect.state < LI_PRECONN_ST_FULL) { send_log(l->bind_conf->frontend, LOG_INFO, - "preconnect %s::%s: Reaching maxconn %d.\n", + "preconnect %s::%s: Running with nbconn %d reached.\n", l->bind_conf->frontend->id, l->bind_conf->reverse_srvname, l->bind_conf->maxconn); l->rx.reverse_connect.state = LI_PRECONN_ST_FULL;