]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: listener: move maxaccept from listener to bind_conf
authorWilly Tarreau <w@1wt.eu>
Thu, 12 Jan 2023 17:52:23 +0000 (18:52 +0100)
committerWilly Tarreau <w@1wt.eu>
Fri, 3 Feb 2023 17:00:20 +0000 (18:00 +0100)
Like for previous values, maxaccept is really per-bind_conf, so let's
move it there. Some frontends (peers, log) set it to 1 so the assignment
was slightly moved.

include/haproxy/listener-t.h
src/cfgparse.c
src/listener.c
src/log.c

index 45083975c10c5d48314824d049cc3a07e01a0dc4..7a6aeccaec4478fa794b03e6163f11d32452ee75 100644 (file)
@@ -200,6 +200,7 @@ struct bind_conf {
        unsigned int analysers;    /* bitmap of required protocol analysers */
        int maxseg;                /* for TCP, advertised MSS */
        int tcp_ut;                /* for TCP, user timeout */
+       int maxaccept;             /* if set, max number of connections accepted at once (-1 when disabled) */
        int level;                 /* stats access level (ACCESS_LVL_*) */
        int severity_output;       /* default severity output format in cli feedback messages */
        struct list listeners;     /* list of listeners using this bind config */
@@ -243,7 +244,6 @@ struct listener {
        int nbconn;                     /* current number of connections on this listener */
        int maxconn;                    /* maximum connections allowed on this listener */
        unsigned int backlog;           /* if set, listen backlog */
-       int maxaccept;         /* if set, max number of connections accepted at once (-1 when disabled) */
        int (*accept)(struct connection *conn); /* upper layer's accept() */
        enum obj_type *default_target;  /* default target to use for accepted sessions or NULL */
        /* cache line boundary */
index cc5c96698ec91a765bd0ffe7ad64b7dd4854284a..ed9c85c5b9a61dfed0829a8723b0900f31855adf 100644 (file)
@@ -714,6 +714,9 @@ int cfg_parse_peers(const char *file, int linenum, char **args, int kwm)
                        err_code |= ERR_FATAL;
                        goto out;
                }
+
+               bind_conf->maxaccept = 1;
+
                if (*args[0] == 'b') {
                        struct listener *l;
 
@@ -743,7 +746,6 @@ int cfg_parse_peers(const char *file, int linenum, char **args, int kwm)
                         * Newly allocated listener is at the end of the list
                         */
                        l = LIST_ELEM(bind_conf->listeners.p, typeof(l), by_bind);
-                       l->maxaccept = 1;
                        l->accept = session_accept_fd;
                        l->default_target = curpeers->peers_fe->default_target;
                        l->options |= LI_O_UNLIMITED; /* don't make the peers subject to global limits */
@@ -946,6 +948,8 @@ int cfg_parse_peers(const char *file, int linenum, char **args, int kwm)
                        goto out;
                }
 
+               bind_conf->maxaccept = 1;
+
                if (!LIST_ISEMPTY(&bind_conf->listeners)) {
                        ha_alert("parsing [%s:%d] : One listener per \"peers\" section is authorized but another is already configured at [%s:%d].\n", file, linenum, bind_conf->file, bind_conf->line);
                        err_code |= ERR_FATAL;
@@ -967,7 +971,6 @@ int cfg_parse_peers(const char *file, int linenum, char **args, int kwm)
                 * Newly allocated listener is at the end of the list
                 */
                l = LIST_ELEM(bind_conf->listeners.p, typeof(l), by_bind);
-               l->maxaccept = 1;
                l->accept = session_accept_fd;
                l->default_target = curpeers->peers_fe->default_target;
                l->options |= LI_O_UNLIMITED; /* don't make the peers subject to global limits */
@@ -4284,6 +4287,8 @@ init_proxies_list_stage2:
                            bind_conf->xprt->prepare_bind_conf(bind_conf) < 0)
                                cfgerr++;
                        bind_conf->analysers |= curproxy->fe_req_ana;
+                       if (!bind_conf->maxaccept)
+                               bind_conf->maxaccept = global.tune.maxaccept ? global.tune.maxaccept : MAX_ACCEPT;
                }
 
                /* adjust this proxy's listeners */
@@ -4308,8 +4313,6 @@ init_proxies_list_stage2:
 
                        if (curproxy->options & PR_O_TCP_NOLING)
                                listener->options |= LI_O_NOLINGER;
-                       if (!listener->maxaccept)
-                               listener->maxaccept = global.tune.maxaccept ? global.tune.maxaccept : MAX_ACCEPT;
 
                        /* listener accept callback */
                        listener->accept = session_accept_fd;
index 717e8784b6040f9b25dc79977164fca6912f1049..32a11589a1f8d85c6ca6ffadda276535b8de73d0 100644 (file)
@@ -842,10 +842,10 @@ void listener_accept(struct listener *l)
 
        p = l->bind_conf->frontend;
 
-       /* if l->maxaccept is -1, then max_accept is UINT_MAX. It is not really
-        * illimited, but it is probably enough.
+       /* if l->bind_conf->maxaccept is -1, then max_accept is UINT_MAX. It is
+        * not really illimited, but it is probably enough.
         */
-       max_accept = l->maxaccept ? l->maxaccept : 1;
+       max_accept = l->bind_conf->maxaccept ? l->bind_conf->maxaccept : 1;
 
        if (!(l->options & LI_O_UNLIMITED) && global.sps_lim) {
                int max = freq_ctr_remain(&global.sess_per_sec, global.sps_lim, 0);
index a3475ba2ce43ca0e3d362bccc31cf8d195437f4e..91396a3db5108ea4ba82c4340feded40d6e3c767 100644 (file)
--- a/src/log.c
+++ b/src/log.c
@@ -3525,7 +3525,7 @@ void syslog_fd_handler(int fd)
                if (!fd_recv_ready(fd))
                        return;
 
-               max_accept = l->maxaccept ? l->maxaccept : 1;
+               max_accept = l->bind_conf->maxaccept ? l->bind_conf->maxaccept : 1;
 
                do {
                        /* Source address */
@@ -3577,7 +3577,7 @@ static void syslog_io_handler(struct appctx *appctx)
        char *message;
        size_t size;
 
-       max_accept = l->maxaccept ? l->maxaccept : 1;
+       max_accept = l->bind_conf->maxaccept ? l->bind_conf->maxaccept : 1;
        while (co_data(sc_oc(sc))) {
                char c;
 
@@ -3810,6 +3810,8 @@ int cfg_parse_log_forward(const char *file, int linenum, char **args, int kwm)
                        goto out;
                }
 
+               bind_conf->maxaccept = global.tune.maxaccept ? global.tune.maxaccept : MAX_ACCEPT;
+
                if (!str2listener(args[1], cfg_log_forward, bind_conf, file, linenum, &errmsg)) {
                        if (errmsg && *errmsg) {
                                indent_msg(&errmsg, 2);
@@ -3823,7 +3825,6 @@ int cfg_parse_log_forward(const char *file, int linenum, char **args, int kwm)
                        }
                }
                list_for_each_entry(l, &bind_conf->listeners, by_bind) {
-                       l->maxaccept = global.tune.maxaccept ? global.tune.maxaccept : MAX_ACCEPT;
                        l->accept = session_accept_fd;
                        l->default_target = cfg_log_forward->default_target;
                        global.maxsock++;
@@ -3853,6 +3854,8 @@ int cfg_parse_log_forward(const char *file, int linenum, char **args, int kwm)
                        goto out;
                }
 
+               bind_conf->maxaccept = global.tune.maxaccept ? global.tune.maxaccept : MAX_ACCEPT;
+
                if (!str2receiver(args[1], cfg_log_forward, bind_conf, file, linenum, &errmsg)) {
                        if (errmsg && *errmsg) {
                                indent_msg(&errmsg, 2);
@@ -3867,7 +3870,6 @@ int cfg_parse_log_forward(const char *file, int linenum, char **args, int kwm)
                }
                list_for_each_entry(l, &bind_conf->listeners, by_bind) {
                        /* the fact that the sockets are of type dgram is guaranteed by str2receiver() */
-                       l->maxaccept = global.tune.maxaccept ? global.tune.maxaccept : MAX_ACCEPT;
                        l->rx.iocb   = syslog_fd_handler;
                        global.maxsock++;
                }