]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: proxy: only check abortonclose through a dedicated function
authorWilly Tarreau <w@1wt.eu>
Tue, 7 Oct 2025 13:36:54 +0000 (15:36 +0200)
committerWilly Tarreau <w@1wt.eu>
Wed, 8 Oct 2025 08:29:41 +0000 (10:29 +0200)
In order to prepare for changing the way abortonclose works, let's
replace the direct flag check with a similarly named function
(proxy_abrt_close) which returns the on/off status of the directive
for the proxy. For now it simply reflects the flag's state.

include/haproxy/proxy.h
src/backend.c
src/http_ana.c
src/ssl_sock.c
src/stconn.c
src/stream.c

index f3ab984c9c7eb5ac779a41d78a0c4d9244210aca..46f5df84bdfbf51b595a977d525e85864aef6eb5 100644 (file)
@@ -141,6 +141,12 @@ static inline void proxy_reset_timeouts(struct proxy *proxy)
        proxy->timeout.tunnel = TICK_ETERNITY;
 }
 
+/* return proxy's abortonclose status: 0=off, non-zero=on */
+static inline int proxy_abrt_close(const struct proxy *px)
+{
+       return !!(px->options & PR_O_ABRT_CLOSE);
+}
+
 /* increase the number of cumulated connections received on the designated frontend */
 static inline void proxy_inc_fe_conn_ctr(struct listener *l, struct proxy *fe)
 {
index 69842e343601d607dbe4f223f4a117c27832e1bd..d0c1b8077a25eeb46857fbea714cee07ecf69688 100644 (file)
@@ -2387,7 +2387,7 @@ static int back_may_abort_req(struct channel *req, struct stream *s)
 {
        return ((s->scf->flags & SC_FL_ERROR) ||
                ((s->scb->flags & (SC_FL_SHUT_WANTED|SC_FL_SHUT_DONE)) &&  /* empty and client aborted */
-                (!co_data(req) || (s->be->options & PR_O_ABRT_CLOSE))));
+                (!co_data(req) || proxy_abrt_close(s->be))));
 }
 
 /* Update back stream connector status for input states SC_ST_ASS, SC_ST_QUE,
@@ -2679,7 +2679,7 @@ void back_handle_st_con(struct stream *s)
        /* the client might want to abort */
        if ((s->scf->flags & SC_FL_SHUT_DONE) ||
            ((s->scb->flags & SC_FL_SHUT_WANTED) &&
-            (!co_data(req) || (s->be->options & PR_O_ABRT_CLOSE)))) {
+            (!co_data(req) || proxy_abrt_close(s->be)))) {
                sc->flags |= SC_FL_NOLINGER;
                sc_shutdown(sc);
                s->conn_err_type |= STRM_ET_CONN_ABRT;
@@ -2904,7 +2904,7 @@ void back_handle_st_rdy(struct stream *s)
                /* client abort ? */
                if ((s->scf->flags & SC_FL_SHUT_DONE) ||
                    ((s->scb->flags & SC_FL_SHUT_WANTED) &&
-                    (!co_data(req) || (s->be->options & PR_O_ABRT_CLOSE)))) {
+                    (!co_data(req) || proxy_abrt_close(s->be)))) {
                        /* give up */
                        sc->flags |= SC_FL_NOLINGER;
                        sc_shutdown(sc);
index 3184c69ec7e912be634c4968a139ed9ac4582e7a..3598787054a6ebafd89210c94f5b024e00eb8106 100644 (file)
@@ -1055,7 +1055,7 @@ int http_request_forward_body(struct stream *s, struct channel *req, int an_bit)
         * server, which will decide whether to close or to go on processing the
         * request. We only do that in tunnel mode, and not in other modes since
         * it can be abused to exhaust source ports. */
-       if (s->be->options & PR_O_ABRT_CLOSE) {
+       if (proxy_abrt_close(s->be)) {
                channel_auto_read(req);
                if ((s->scf->flags & (SC_FL_ABRT_DONE|SC_FL_EOS)) && !(txn->flags & TX_CON_WANT_TUN))
                        s->scb->flags |= SC_FL_NOLINGER;
@@ -2806,7 +2806,7 @@ static enum rule_result http_req_get_intercept_rule(struct proxy *px, struct lis
 
        if ((s->scf->flags & SC_FL_ERROR) ||
            ((s->scf->flags & (SC_FL_EOS|SC_FL_ABRT_DONE)) &&
-            (px->options & PR_O_ABRT_CLOSE)))
+            proxy_abrt_close(px)))
                act_opts |= ACT_OPT_FINAL | ACT_OPT_FINAL_EARLY;
 
        /* If "the current_rule_list" match the executed rule list, we are in
@@ -2994,7 +2994,7 @@ static enum rule_result http_res_get_intercept_rule(struct proxy *px, struct lis
                act_opts |= ACT_OPT_FINAL;
        if ((s->scf->flags & SC_FL_ERROR) ||
            ((s->scf->flags & (SC_FL_EOS|SC_FL_ABRT_DONE)) &&
-            (px->options & PR_O_ABRT_CLOSE)))
+            proxy_abrt_close(px)))
                act_opts |= ACT_OPT_FINAL | ACT_OPT_FINAL_EARLY;
 
        /* If "the current_rule_list" match the executed rule list, we are in
@@ -4457,7 +4457,7 @@ static void http_end_request(struct stream *s)
                 * buffers, otherwise a close could cause an RST on some systems
                 * (eg: Linux).
                 */
-               if (!(s->be->options & PR_O_ABRT_CLOSE) && txn->meth != HTTP_METH_POST)
+               if (!proxy_abrt_close(s->be) && txn->meth != HTTP_METH_POST)
                        channel_dont_read(chn);
 
                /* if the server closes the connection, we want to immediately react
@@ -4536,7 +4536,7 @@ static void http_end_request(struct stream *s)
                if (txn->rsp.flags & HTTP_MSGF_XFER_LEN)
                        s->scb->flags |= SC_FL_NOLINGER;  /* we want to close ASAP */
                /* see above in MSG_DONE why we only do this in these states */
-               if (!(s->be->options & PR_O_ABRT_CLOSE))
+               if (!proxy_abrt_close(s->be))
                        channel_dont_read(chn);
                goto end;
        }
index 107732250f54d1b18657ca92cf94a24f4605eff8..6fa65952fb826c3c1909ed966a20a1a43ad5f85b 100644 (file)
@@ -385,7 +385,7 @@ static int ha_ssl_read(BIO *h, char *buf, int size)
 
        if (ctx->conn->flags & CO_FL_SSL_WAIT_HS &&
            !conn_is_back(ctx->conn) &&
-           ((struct session *)ctx->conn->owner)->fe->options & PR_O_ABRT_CLOSE)
+           proxy_abrt_close(((struct session *)ctx->conn->owner)->fe))
                detect_shutr = 1;
        else
                detect_shutr = 0;
index f9eda533fc33730c2bee94148ceca1463040af98..ff439d190d759189bab4cb217bbfdf347aa88b75 100644 (file)
@@ -19,6 +19,7 @@
 #include <haproxy/http_ana.h>
 #include <haproxy/pipe.h>
 #include <haproxy/pool.h>
+#include <haproxy/proxy.h>
 #include <haproxy/sample.h>
 #include <haproxy/sc_strm.h>
 #include <haproxy/stconn.h>
@@ -1387,7 +1388,7 @@ int sc_conn_recv(struct stconn *sc)
        /* Instruct the mux it must subscribed for read events */
        if (!(sc->flags & SC_FL_ISBACK) &&                         /* for frontend conns only */
            (sc_opposite(sc)->state != SC_ST_INI) &&               /* before backend connection setup */
-           (__sc_strm(sc)->be->options & PR_O_ABRT_CLOSE))        /* if abortonclose option is set for the current backend */
+           proxy_abrt_close(__sc_strm(sc)->be))                   /* if abortonclose option is set for the current backend */
                flags |= CO_RFL_KEEP_RECV;
 
        /* Important note : if we're called with POLL_IN|POLL_HUP, it means the read polling
index 7454b2b9afee0a7f76e4e654ae5e8ee2e90e09d5..852d042e7567c9b2c046ffbb194505a6e35588ca 100644 (file)
@@ -2355,7 +2355,7 @@ struct task *process_stream(struct task *t, void *context, unsigned int state)
                                    !(s->txn->flags & TX_D_L7_RETRY))
                                        s->txn->flags |= TX_L7_RETRY;
 
-                               if (s->be->options & PR_O_ABRT_CLOSE) {
+                               if (proxy_abrt_close(s->be)) {
                                        struct connection *conn = sc_conn(scf);
 
                                        se_have_more_data(scf->sedesc);
@@ -2425,7 +2425,7 @@ struct task *process_stream(struct task *t, void *context, unsigned int state)
         */
        if (unlikely((req->flags & CF_AUTO_CLOSE) && (scf->flags & (SC_FL_EOS|SC_FL_ABRT_DONE)) &&
                     !(scb->flags & (SC_FL_SHUT_DONE|SC_FL_SHUT_WANTED)) &&
-                    (scb->state != SC_ST_CON || (s->be->options & PR_O_ABRT_CLOSE)))) {
+                    (scb->state != SC_ST_CON || proxy_abrt_close(s->be)))) {
                sc_schedule_shutdown(scb);
        }