]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: listener: move LI_O_UNLIMITED and LI_O_NOSTOP to bind_conf
authorWilly Tarreau <w@1wt.eu>
Thu, 12 Jan 2023 18:58:42 +0000 (19:58 +0100)
committerWilly Tarreau <w@1wt.eu>
Fri, 3 Feb 2023 17:00:20 +0000 (18:00 +0100)
These two flags are entirely for internal use and are even per proxy
in practice since they're used for peers and CLI to indicate (for the
first one) that the listener(s) are not subject to connection limits,
and for the second that the listener(s) should not be stopped on
soft-stop. No need to keep them in the listeners, let's move them to
the bind_conf under names BC_O_UNLIMITED and BC_O_NOSTOP.

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

index 338ab9de677bb54ece8f478058eac34e191b5982..7f0b28603e13423242eff9936c296e2d7dafe438 100644 (file)
@@ -100,16 +100,16 @@ enum li_status {
 #define LI_O_TCP_L5_RULES       0x0020  /* run TCP L5 rules checks on the incoming session */
 /* unused                       0x0040  */
 /* unused                       0x0080  */
-#define LI_O_UNLIMITED          0x0100  /* listener not subject to global limits (peers & stats socket) */
+/* unused                       0x0100  */
 /* unused                       0x0200  */
 /* unused                       0x0400  */
 /* unused                       0x0800  */
 /* unused                       0x1000  */
 /* unused                       0x2000  */
 /* unused                       0x4000  */
-#define LI_O_NOSTOP             0x8000  /* keep the listener active even after a soft stop */
+/* unused                       0x8000  */
 
-/* Note: if a listener uses LI_O_UNLIMITED, it is highly recommended that it adds its own
+/* Note: if a bind_conf uses BC_O_UNLIMITED, it is highly recommended that it adds its own
  * maxconn setting to the global.maxsock value so that its resources are reserved.
  */
 
@@ -127,6 +127,8 @@ enum li_status {
 #define BC_O_TCP_FO             0x00000400 /* enable TCP Fast Open (linux >= 3.7) */
 #define BC_O_ACC_PROXY          0x00000800 /* find the proxied address in the first request line */
 #define BC_O_ACC_CIP            0x00001000 /* find the proxied address in the NetScaler Client IP header */
+#define BC_O_UNLIMITED          0x00002000 /* listeners not subject to global limits (peers & stats socket) */
+#define BC_O_NOSTOP             0x00004000 /* keep the listeners active even after a soft stop */
 
 
 /* flags used with bind_conf->ssl_options */
index b98f64529561a3820b08394574765df7ff274152..4d788dd8f0bf9876a09ef5e70b52860863c8fb54 100644 (file)
@@ -690,7 +690,6 @@ int cfg_parse_peers(const char *file, int linenum, char **args, int kwm)
        struct peer *newpeer = NULL;
        const char *err;
        struct bind_conf *bind_conf;
-       struct listener *l;
        int err_code = 0;
        char *errmsg = NULL;
        static int bind_line, peer_line;
@@ -717,6 +716,7 @@ int cfg_parse_peers(const char *file, int linenum, char **args, int kwm)
 
                bind_conf->maxaccept = 1;
                bind_conf->accept = session_accept_fd;
+               bind_conf->options |= BC_O_UNLIMITED; /* don't make the peers subject to global limits */
 
                if (*args[0] == 'b') {
                        struct listener *l;
@@ -743,11 +743,12 @@ int cfg_parse_peers(const char *file, int linenum, char **args, int kwm)
                                err_code |= ERR_FATAL;
                                goto out;
                        }
+
                        /*
                         * Newly allocated listener is at the end of the list
                         */
                        l = LIST_ELEM(bind_conf->listeners.p, typeof(l), by_bind);
-                       l->options |= LI_O_UNLIMITED; /* don't make the peers subject to global limits */
+
                        global.maxsock++; /* for the listening socket */
 
                        bind_line = 1;
@@ -949,6 +950,7 @@ int cfg_parse_peers(const char *file, int linenum, char **args, int kwm)
 
                bind_conf->maxaccept = 1;
                bind_conf->accept = session_accept_fd;
+               bind_conf->options |= BC_O_UNLIMITED; /* don't make the peers subject to global limits */
 
                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);
@@ -967,11 +969,6 @@ int cfg_parse_peers(const char *file, int linenum, char **args, int kwm)
                        goto out;
                }
 
-               /*
-                * Newly allocated listener is at the end of the list
-                */
-               l = LIST_ELEM(bind_conf->listeners.p, typeof(l), by_bind);
-               l->options |= LI_O_UNLIMITED; /* don't make the peers subject to global limits */
                global.maxsock++; /* for the listening socket */
        }
        else if (strcmp(args[0], "shards") == 0) {
index b133b5febf2b62d1102da632c8983eb594107399..679eb5a36f9c5827bd9aa9cca7bc5f8ea0cb948c 100644 (file)
--- a/src/cli.c
+++ b/src/cli.c
@@ -553,9 +553,9 @@ static int cli_parse_global(char **args, int section_type, struct proxy *curpx,
 
                bind_conf->accept = session_accept_fd;
                bind_conf->nice = -64;  /* we want to boost priority for local stats */
+               bind_conf->options |= BC_O_UNLIMITED; /* don't make the peers subject to global limits */
 
                list_for_each_entry(l, &bind_conf->listeners, by_bind) {
-                       l->options |= LI_O_UNLIMITED; /* don't make the peers subject to global limits */
                        global.maxsock++; /* for the listening socket */
                }
        }
@@ -3046,10 +3046,9 @@ struct bind_conf *mworker_cli_proxy_new_listener(char *line)
 
        bind_conf->accept = session_accept_fd;
        bind_conf->nice = -64;  /* we want to boost priority for local stats */
+       bind_conf->options |= BC_O_UNLIMITED; /* don't make the peers subject to global limits */
 
        list_for_each_entry(l, &bind_conf->listeners, by_bind) {
-               /* don't make the peers subject to global limits and don't close it in the master */
-               l->options  |= LI_O_UNLIMITED;
                l->rx.flags |= RX_F_MWORKER; /* we are keeping this FD in the master */
                global.maxsock++; /* for the listening socket */
        }
@@ -3113,9 +3112,9 @@ int mworker_cli_sockpair_new(struct mworker_proc *mworker_proc, int proc)
 
        bind_conf->accept = session_accept_fd;
        bind_conf->nice = -64;  /* we want to boost priority for local stats */
+       bind_conf->options |= BC_O_UNLIMITED | BC_O_NOSTOP;
 
        list_for_each_entry(l, &bind_conf->listeners, by_bind) {
-               l->options |= (LI_O_UNLIMITED | LI_O_NOSTOP);
                HA_ATOMIC_INC(&unstoppable_jobs);
                /* it's a sockpair but we don't want to keep the fd in the master */
                l->rx.flags &= ~RX_F_INHERITED;
index 7ff21f0a77ff63c06c0423a798ed049bc815a5f9..b7b3b2250d6a8d721d2fcf723566725e676edc3b 100644 (file)
@@ -152,7 +152,7 @@ struct task *accept_queue_process(struct task *t, void *context, unsigned int st
                 * may only be done once l->bind_conf->accept() has accepted the
                 * connection.
                 */
-               if (!(li->options & LI_O_UNLIMITED)) {
+               if (!(li->bind_conf->options & BC_O_UNLIMITED)) {
                        HA_ATOMIC_UPDATE_MAX(&global.sps_max,
                                             update_freq_ctr(&global.sess_per_sec, 1));
                        if (li->bind_conf && li->bind_conf->options & BC_O_USE_SSL) {
@@ -345,7 +345,7 @@ void stop_listener(struct listener *l, int lpx, int lpr)
 {
        struct proxy *px = l->bind_conf->frontend;
 
-       if (l->options & LI_O_NOSTOP) {
+       if (l->bind_conf->options & BC_O_NOSTOP) {
                /* master-worker sockpairs are never closed but don't count as a
                 * job.
                 */
@@ -848,7 +848,7 @@ void listener_accept(struct listener *l)
         */
        max_accept = l->bind_conf->maxaccept ? l->bind_conf->maxaccept : 1;
 
-       if (!(l->options & LI_O_UNLIMITED) && global.sps_lim) {
+       if (!(l->bind_conf->options & BC_O_UNLIMITED) && global.sps_lim) {
                int max = freq_ctr_remain(&global.sess_per_sec, global.sps_lim, 0);
 
                if (unlikely(!max)) {
@@ -861,7 +861,7 @@ void listener_accept(struct listener *l)
                        max_accept = max;
        }
 
-       if (!(l->options & LI_O_UNLIMITED) && global.cps_lim) {
+       if (!(l->bind_conf->options & BC_O_UNLIMITED) && global.cps_lim) {
                int max = freq_ctr_remain(&global.conn_per_sec, global.cps_lim, 0);
 
                if (unlikely(!max)) {
@@ -874,7 +874,7 @@ void listener_accept(struct listener *l)
                        max_accept = max;
        }
 #ifdef USE_OPENSSL
-       if (!(l->options & LI_O_UNLIMITED) && global.ssl_lim &&
+       if (!(l->bind_conf->options & BC_O_UNLIMITED) && global.ssl_lim &&
            l->bind_conf && l->bind_conf->options & BC_O_USE_SSL) {
                int max = freq_ctr_remain(&global.ssl_per_sec, global.ssl_lim, 0);
 
@@ -943,7 +943,7 @@ void listener_accept(struct listener *l)
                        } while (!_HA_ATOMIC_CAS(&p->feconn, &count, next_feconn));
                }
 
-               if (!(l->options & LI_O_UNLIMITED)) {
+               if (!(l->bind_conf->options & BC_O_UNLIMITED)) {
                        do {
                                count = actconn;
                                if (unlikely(count >= global.maxconn)) {
@@ -979,7 +979,7 @@ void listener_accept(struct listener *l)
                                _HA_ATOMIC_DEC(&l->nbconn);
                                if (p)
                                        _HA_ATOMIC_DEC(&p->feconn);
-                               if (!(l->options & LI_O_UNLIMITED))
+                               if (!(l->bind_conf->options & BC_O_UNLIMITED))
                                        _HA_ATOMIC_DEC(&actconn);
                                continue;
 
@@ -1001,7 +1001,7 @@ void listener_accept(struct listener *l)
                        proxy_inc_fe_conn_ctr(l, p);
                }
 
-               if (!(l->options & LI_O_UNLIMITED)) {
+               if (!(l->bind_conf->options & BC_O_UNLIMITED)) {
                        count = update_freq_ctr(&global.conn_per_sec, 1);
                        HA_ATOMIC_UPDATE_MAX(&global.cps_max, count);
                }
@@ -1155,12 +1155,12 @@ void listener_accept(struct listener *l)
                 * may only be done once l->bind_conf->accept() has accepted the
                 * connection.
                 */
-               if (!(l->options & LI_O_UNLIMITED)) {
+               if (!(l->bind_conf->options & BC_O_UNLIMITED)) {
                        count = update_freq_ctr(&global.sess_per_sec, 1);
                        HA_ATOMIC_UPDATE_MAX(&global.sps_max, count);
                }
 #ifdef USE_OPENSSL
-               if (!(l->options & LI_O_UNLIMITED) &&
+               if (!(l->bind_conf->options & BC_O_UNLIMITED) &&
                    l->bind_conf && l->bind_conf->options & BC_O_USE_SSL) {
                        count = update_freq_ctr(&global.ssl_per_sec, 1);
                        HA_ATOMIC_UPDATE_MAX(&global.ssl_max, count);
@@ -1237,7 +1237,7 @@ void listener_release(struct listener *l)
 {
        struct proxy *fe = l->bind_conf->frontend;
 
-       if (!(l->options & LI_O_UNLIMITED))
+       if (!(l->bind_conf->options & BC_O_UNLIMITED))
                _HA_ATOMIC_DEC(&actconn);
        if (fe)
                _HA_ATOMIC_DEC(&fe->feconn);