From fe47e8dfc5bd4541a6a487f00ffe5e966133a8e8 Mon Sep 17 00:00:00 2001 From: Willy Tarreau Date: Tue, 7 Oct 2025 15:36:54 +0200 Subject: [PATCH] MINOR: proxy: only check abortonclose through a dedicated function 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 | 6 ++++++ src/backend.c | 6 +++--- src/http_ana.c | 10 +++++----- src/ssl_sock.c | 2 +- src/stconn.c | 3 ++- src/stream.c | 4 ++-- 6 files changed, 19 insertions(+), 12 deletions(-) diff --git a/include/haproxy/proxy.h b/include/haproxy/proxy.h index f3ab984c9..46f5df84b 100644 --- a/include/haproxy/proxy.h +++ b/include/haproxy/proxy.h @@ -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) { diff --git a/src/backend.c b/src/backend.c index 69842e343..d0c1b8077 100644 --- a/src/backend.c +++ b/src/backend.c @@ -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); diff --git a/src/http_ana.c b/src/http_ana.c index 3184c69ec..359878705 100644 --- a/src/http_ana.c +++ b/src/http_ana.c @@ -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; } diff --git a/src/ssl_sock.c b/src/ssl_sock.c index 107732250..6fa65952f 100644 --- a/src/ssl_sock.c +++ b/src/ssl_sock.c @@ -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; diff --git a/src/stconn.c b/src/stconn.c index f9eda533f..ff439d190 100644 --- a/src/stconn.c +++ b/src/stconn.c @@ -19,6 +19,7 @@ #include #include #include +#include #include #include #include @@ -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 diff --git a/src/stream.c b/src/stream.c index 7454b2b9a..852d042e7 100644 --- a/src/stream.c +++ b/src/stream.c @@ -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); }