]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: listener: add nbconn kw for reverse connect
authorAmaury Denoyelle <adenoyelle@haproxy.com>
Thu, 19 Oct 2023 07:25:20 +0000 (09:25 +0200)
committerAmaury Denoyelle <adenoyelle@haproxy.com>
Fri, 20 Oct 2023 12:44:37 +0000 (14:44 +0200)
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.

doc/configuration.txt
include/haproxy/listener-t.h
src/listener.c
src/proto_reverse_connect.c

index 5f8d47323d7a83aefd3dec7b58b48b2db5eb91c2..25683f4847f2d17140eda73ade44a2eca0dfa9a8 100644 (file)
@@ -15332,6 +15332,11 @@ namespace <name>
   a namespace different from the default one. Please refer to your operating
   system's documentation to find more details about network namespaces.
 
+nbconn <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 <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
index 8f7cbb13e7a38c2f1651cacd21ed700dc11ce7b4..bb431317693364c255591ffc97e33b86ba979824 100644 (file)
@@ -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 */
index da483702ed7194c84ec054a0ef7c373374518fa1..f812d9fad736188fa9776deb942b8e0e0dac5ca2 100644 (file)
@@ -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 */
index ef9e40f469acc76b9cbe53d630c52c74194ac375..293c13418ea4b459705d2a355678305719362ee5 100644 (file)
@@ -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;