From: Willy Tarreau Date: Wed, 8 Oct 2025 08:27:45 +0000 (+0200) Subject: MINOR: proxy: introduce proxy_abrt_close_def() to pass the desired default X-Git-Tag: v3.3-dev10~61 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=75103e7701a24f37fcd1dfe19450fa3ab8ce4964;p=thirdparty%2Fhaproxy.git MINOR: proxy: introduce proxy_abrt_close_def() to pass the desired default With this function we can now pass the desired default value for the abortonclose option when neither the option nor its opposite were set. Let's also take this opportunity for using it directly from the HTTP analyser since there's no point in re-checking the proxy's mode there. --- diff --git a/include/haproxy/proxy.h b/include/haproxy/proxy.h index 7be5a55d5..0288d6d41 100644 --- a/include/haproxy/proxy.h +++ b/include/haproxy/proxy.h @@ -141,18 +141,26 @@ static inline void proxy_reset_timeouts(struct proxy *proxy) proxy->timeout.tunnel = TICK_ETERNITY; } -/* return proxy's abortonclose status: 0=off, non-zero=on. - * Considers the proxy's mode when neither on/off was set, - * and HTTP mode defaults to on. +/* Return proxy's abortonclose status: 0=off, non-zero=on, with a default to + * when neither choice was forced. */ -static inline int proxy_abrt_close(const struct proxy *px) +static inline int proxy_abrt_close_def(const struct proxy *px, int def) { if (px->options & PR_O_ABRT_CLOSE) return 1; else if (px->no_options & PR_O_ABRT_CLOSE) return 0; /* When unset: 1 for HTTP, 0 for TCP */ - return px->mode == PR_MODE_HTTP; + return def; +} + +/* return proxy's abortonclose status: 0=off, non-zero=on. + * Considers the proxy's mode when neither on/off was set, + * and HTTP mode defaults to on. + */ +static inline int proxy_abrt_close(const struct proxy *px) +{ + return proxy_abrt_close_def(px, px->mode == PR_MODE_HTTP); } /* increase the number of cumulated connections received on the designated frontend */ diff --git a/src/http_ana.c b/src/http_ana.c index 359878705..532a4860d 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 (proxy_abrt_close(s->be)) { + if (proxy_abrt_close_def(s->be, 1)) { 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)) && - proxy_abrt_close(px))) + proxy_abrt_close_def(px, 1))) 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)) && - proxy_abrt_close(px))) + proxy_abrt_close_def(px, 1))) 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 (!proxy_abrt_close(s->be) && txn->meth != HTTP_METH_POST) + if (!proxy_abrt_close_def(s->be, 1) && 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 (!proxy_abrt_close(s->be)) + if (!proxy_abrt_close_def(s->be, 1)) channel_dont_read(chn); goto end; }