]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: proxy: introduce proxy_abrt_close_def() to pass the desired default
authorWilly Tarreau <w@1wt.eu>
Wed, 8 Oct 2025 08:27:45 +0000 (10:27 +0200)
committerWilly Tarreau <w@1wt.eu>
Wed, 8 Oct 2025 08:29:41 +0000 (10:29 +0200)
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.

include/haproxy/proxy.h
src/http_ana.c

index 7be5a55d5cdc8618fe259b9d3c7f98eece000adb..0288d6d412b03d9cf4be00095689bdc3d141c989 100644 (file)
@@ -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
+ * <def> 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 */
index 3598787054a6ebafd89210c94f5b024e00eb8106..532a4860de83fb972ed73a535cc8cf46d5b2921e 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 (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;
        }