]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: tevt/connection: Add dedicated termination events for lower locations
authorChristopher Faulet <cfaulet@haproxy.com>
Mon, 20 Jan 2025 07:35:36 +0000 (08:35 +0100)
committerChristopher Faulet <cfaulet@haproxy.com>
Fri, 31 Jan 2025 09:41:50 +0000 (10:41 +0100)
To be able to add more accurate termination events for each location, the
enum will be splitted by location. Indeed, there are at most 16 possbile
events. It will be pretty confusing to use same termination events for the
different locations. So the best is to split them.

In this patch, the termination events for the fd, hs and xprt locations are
introduced. For now some holes are added to keep similar events aligned
across enums. But this may change in future.

include/haproxy/connection-t.h
include/haproxy/connection.h
src/connection.c
src/raw_sock.c
src/sock.c
src/ssl_sock.c
src/tcp_rules.c

index b1c8d94bd8069934c404f655a16fcbbe3b976dce..7b54e8e00879a5e5b6801e65493249eff78932ca 100644 (file)
@@ -559,7 +559,32 @@ enum term_event_loc {
        tevt_loc_strm  = 6,
 };
 
-/* Types for termination event logs (4-bits) */
+/* Types for termination event logs (4-bits) per location */
+enum fd_term_event_type {
+       fd_tevt_type_shutw       = 1,
+       fd_tevt_type_shutr       = 2,
+       fd_tevt_type_rcv_err     = 3,
+       fd_tevt_type_snd_err     = 4,
+       /* unused: 5, 6 */
+       fd_tevt_type_connect_err = 7,
+       fd_tevt_type_intercepted = 8,
+};
+
+enum hs_term_event_type {
+       /* unused: 1, 2, 3 */
+       hs_tevt_type_snd_err           = 4,
+       hs_tevt_type_truncated_shutr   = 5,
+       hs_tevt_type_truncated_rcv_err = 6,
+};
+
+enum xprt_term_event_type {
+       xprt_tevt_type_shutw   = 1,
+       xprt_tevt_type_shutr   = 2,
+       xprt_tevt_type_rcv_err = 3,
+       xprt_tevt_type_snd_err = 4,
+};
+
+
 enum term_event_type {
        /* Events emitted by haproxy */
        tevt_type_shutw            =  1,
index a5f032785732340bc641b09aa8dd53041b1ddfe9..c0ed51e5db8176f98ab2eb9642c912b471d7d0c9 100644 (file)
@@ -107,7 +107,7 @@ const char *conn_err_code_str(struct connection *c);
 int xprt_add_hs(struct connection *conn);
 void register_mux_proto(struct mux_proto_list *list);
 
-static inline void conn_report_term_evt(struct connection *conn, enum term_event_loc loc, enum term_event_type type);
+static inline void conn_report_term_evt(struct connection *conn, enum term_event_loc loc, unsigned char type);
 
 extern struct idle_conns idle_conns[MAX_THREADS];
 
@@ -256,7 +256,7 @@ static inline void conn_sock_shutw(struct connection *c, int clean)
                if (!(c->flags & CO_FL_SOCK_RD_SH) && clean)
                        shutdown(c->handle.fd, SHUT_WR);
        }
-       conn_report_term_evt(c, tevt_loc_fd, tevt_type_shutw);
+       conn_report_term_evt(c, tevt_loc_fd, fd_tevt_type_shutw);
 }
 
 static inline void conn_xprt_shutw(struct connection *c)
@@ -790,7 +790,7 @@ static inline const char *tevt_evts2str(uint32_t evts)
 }
 
 /* Report a connection event. <loc> may be "tevt_loc_fd", "tevt_loc_hs" or "tevt_loc_xprt" */
-static inline void conn_report_term_evt(struct connection *conn, enum term_event_loc loc, enum term_event_type type)
+static inline void conn_report_term_evt(struct connection *conn, enum term_event_loc loc, unsigned char type)
 {
        if (conn_is_back(conn))
                loc |= 0x08;
index 759f9687779a6995340d0cab1cd9f95908ef8d93..6a9829993816c3a2b19b98d1d20cecb2db0c0189 100644 (file)
@@ -1373,14 +1373,14 @@ int conn_recv_proxy(struct connection *conn, int flag)
        goto fail;
 
  recv_abort:
-       conn_report_term_evt(conn, tevt_loc_hs, tevt_type_truncated_shutr);
+       conn_report_term_evt(conn, tevt_loc_hs, hs_tevt_type_truncated_shutr);
        conn->err_code = CO_ER_PRX_ABORT;
        conn->flags |= CO_FL_SOCK_RD_SH | CO_FL_SOCK_WR_SH;
        goto fail;
 
  fail:
        if (!(conn->flags & CO_FL_SOCK_RD_SH))
-               conn_report_term_evt(conn, tevt_loc_hs, tevt_type_truncated_rcv_err);
+               conn_report_term_evt(conn, tevt_loc_hs, hs_tevt_type_truncated_rcv_err);
        conn->flags |= CO_FL_ERROR;
        return 0;
 }
@@ -1474,7 +1474,7 @@ int conn_send_proxy(struct connection *conn, unsigned int flag)
 
  out_error:
        /* Write error on the file descriptor */
-       conn_report_term_evt(conn, tevt_loc_hs, tevt_type_snd_err);
+       conn_report_term_evt(conn, tevt_loc_hs, hs_tevt_type_snd_err);
        conn->flags |= CO_FL_ERROR;
        return 0;
 
@@ -1677,14 +1677,14 @@ int conn_recv_netscaler_cip(struct connection *conn, int flag)
        goto fail;
 
  recv_abort:
-       conn_report_term_evt(conn, tevt_loc_hs, tevt_type_truncated_shutr);
+       conn_report_term_evt(conn, tevt_loc_hs, hs_tevt_type_truncated_shutr);
        conn->err_code = CO_ER_CIP_ABORT;
        conn->flags |= CO_FL_SOCK_RD_SH | CO_FL_SOCK_WR_SH;
        goto fail;
 
  fail:
        if (!(conn->flags & CO_FL_SOCK_RD_SH))
-               conn_report_term_evt(conn, tevt_loc_hs, tevt_type_truncated_rcv_err);
+               conn_report_term_evt(conn, tevt_loc_hs, hs_tevt_type_truncated_rcv_err);
        conn->flags |= CO_FL_ERROR;
        return 0;
 }
@@ -1758,7 +1758,7 @@ int conn_send_socks4_proxy_request(struct connection *conn)
 
  out_error:
        /* Write error on the file descriptor */
-       conn_report_term_evt(conn, tevt_loc_hs, tevt_type_snd_err);
+       conn_report_term_evt(conn, tevt_loc_hs, hs_tevt_type_snd_err);
        conn->flags |= CO_FL_ERROR;
        if (conn->err_code == CO_ER_NONE) {
                conn->err_code = CO_ER_SOCKS4_SEND;
@@ -1879,7 +1879,7 @@ int conn_recv_socks4_proxy_response(struct connection *conn)
        return 0;
 
  recv_abort:
-       conn_report_term_evt(conn, tevt_loc_hs, tevt_type_truncated_shutr);
+       conn_report_term_evt(conn, tevt_loc_hs, hs_tevt_type_truncated_shutr);
        if (conn->err_code == CO_ER_NONE) {
                conn->err_code = CO_ER_SOCKS4_ABORT;
        }
@@ -1888,7 +1888,7 @@ int conn_recv_socks4_proxy_response(struct connection *conn)
 
  fail:
        if (!(conn->flags & CO_FL_SOCK_RD_SH))
-               conn_report_term_evt(conn, tevt_loc_hs, tevt_type_truncated_rcv_err);
+               conn_report_term_evt(conn, tevt_loc_hs, hs_tevt_type_truncated_rcv_err);
        conn->flags |= CO_FL_ERROR;
        return 0;
 }
index 401e4cee9c11de6555cbd4def939e794e6262ae9..255a8c01a6e865e48907a795b21c5779d9c990a1 100644 (file)
@@ -77,7 +77,7 @@ int raw_sock_to_pipe(struct connection *conn, void *xprt_ctx, struct pipe *pipe,
 
                /* report error on POLL_ERR before connection establishment */
                if ((fdtab[conn->handle.fd].state & FD_POLL_ERR) && (conn->flags & CO_FL_WAIT_L4_CONN)) {
-                       conn_report_term_evt(conn, tevt_loc_fd, tevt_type_rcv_err);
+                       conn_report_term_evt(conn, tevt_loc_fd, fd_tevt_type_rcv_err);
                        conn->flags |= CO_FL_ERROR | CO_FL_SOCK_RD_SH | CO_FL_SOCK_WR_SH;
                        conn_set_errcode(conn, CO_ER_POLLERR);
                        errno = 0; /* let the caller do a getsockopt() if it wants it */
@@ -128,7 +128,7 @@ int raw_sock_to_pipe(struct connection *conn, void *xprt_ctx, struct pipe *pipe,
                                continue;
                        }
                        /* here we have another error */
-                       conn_report_term_evt(conn, tevt_loc_fd, tevt_type_rcv_err);
+                       conn_report_term_evt(conn, tevt_loc_fd, fd_tevt_type_rcv_err);
                        conn->flags |= CO_FL_ERROR;
                        conn_set_errno(conn, errno);
                        break;
@@ -157,7 +157,7 @@ int raw_sock_to_pipe(struct connection *conn, void *xprt_ctx, struct pipe *pipe,
        return retval;
 
  out_read0:
-       conn_report_term_evt(conn, tevt_loc_fd, tevt_type_shutr);
+       conn_report_term_evt(conn, tevt_loc_fd, fd_tevt_type_shutr);
        conn_sock_read0(conn);
        conn->flags &= ~CO_FL_WAIT_L4_CONN;
        goto leave;
@@ -179,7 +179,7 @@ int raw_sock_from_pipe(struct connection *conn, void *xprt_ctx, struct pipe *pip
 
        if (conn->flags & CO_FL_SOCK_WR_SH) {
                /* it's already closed */
-               conn_report_term_evt(conn, tevt_loc_fd, tevt_type_snd_err);
+               conn_report_term_evt(conn, tevt_loc_fd, fd_tevt_type_snd_err);
                conn->flags |= CO_FL_ERROR | CO_FL_SOCK_RD_SH;
                errno = EPIPE;
                conn_set_errno(conn, errno);
@@ -203,7 +203,7 @@ int raw_sock_from_pipe(struct connection *conn, void *xprt_ctx, struct pipe *pip
                                continue;
 
                        /* here we have another error */
-                       conn_report_term_evt(conn, tevt_loc_fd, tevt_type_snd_err);
+                       conn_report_term_evt(conn, tevt_loc_fd, fd_tevt_type_snd_err);
                        conn->flags |= CO_FL_ERROR;
                        conn_set_errno(conn, errno);
                        break;
@@ -256,7 +256,7 @@ static size_t raw_sock_to_buf(struct connection *conn, void *xprt_ctx, struct bu
 
                /* report error on POLL_ERR before connection establishment */
                if ((fdtab[conn->handle.fd].state & FD_POLL_ERR) && (conn->flags & CO_FL_WAIT_L4_CONN)) {
-                       conn_report_term_evt(conn, tevt_loc_fd, tevt_type_rcv_err);
+                       conn_report_term_evt(conn, tevt_loc_fd, fd_tevt_type_rcv_err);
                        conn->flags |= CO_FL_ERROR | CO_FL_SOCK_RD_SH | CO_FL_SOCK_WR_SH;
                        conn_set_errcode(conn, CO_ER_POLLERR);
                        goto leave;
@@ -316,7 +316,7 @@ static size_t raw_sock_to_buf(struct connection *conn, void *xprt_ctx, struct bu
                        break;
                }
                else if (errno != EINTR) {
-                       conn_report_term_evt(conn, tevt_loc_fd, tevt_type_rcv_err);
+                       conn_report_term_evt(conn, tevt_loc_fd, fd_tevt_type_rcv_err);
                        conn->flags |= CO_FL_ERROR | CO_FL_SOCK_RD_SH | CO_FL_SOCK_WR_SH;
                        conn_set_errno(conn, errno);
                        break;
@@ -330,7 +330,7 @@ static size_t raw_sock_to_buf(struct connection *conn, void *xprt_ctx, struct bu
        return done;
 
  read0:
-       conn_report_term_evt(conn, tevt_loc_fd, tevt_type_shutr);
+       conn_report_term_evt(conn, tevt_loc_fd, fd_tevt_type_shutr);
        conn_sock_read0(conn);
        conn->flags &= ~CO_FL_WAIT_L4_CONN;
 
@@ -342,7 +342,7 @@ static size_t raw_sock_to_buf(struct connection *conn, void *xprt_ctx, struct bu
         * an error without checking.
         */
        if (unlikely(!done && fdtab[conn->handle.fd].state & FD_POLL_ERR)) {
-               conn_report_term_evt(conn, tevt_loc_fd, tevt_type_rcv_err);
+               conn_report_term_evt(conn, tevt_loc_fd, fd_tevt_type_rcv_err);
                conn->flags |= CO_FL_ERROR | CO_FL_SOCK_RD_SH | CO_FL_SOCK_WR_SH;
                conn_set_errcode(conn, CO_ER_POLLERR);
        }
@@ -377,7 +377,7 @@ static size_t raw_sock_from_buf(struct connection *conn, void *xprt_ctx, const s
 
        if (unlikely(fdtab[conn->handle.fd].state & FD_POLL_ERR)) {
                /* an error was reported on the FD, we can't send anymore */
-               conn_report_term_evt(conn, tevt_loc_fd, tevt_type_snd_err);
+               conn_report_term_evt(conn, tevt_loc_fd, fd_tevt_type_snd_err);
                conn->flags |= CO_FL_ERROR | CO_FL_SOCK_WR_SH | CO_FL_SOCK_RD_SH;
                conn_set_errcode(conn, CO_ER_POLLERR);
                errno = EPIPE;
@@ -386,7 +386,7 @@ static size_t raw_sock_from_buf(struct connection *conn, void *xprt_ctx, const s
 
        if (conn->flags & CO_FL_SOCK_WR_SH) {
                /* it's already closed */
-               conn_report_term_evt(conn, tevt_loc_fd, tevt_type_snd_err);
+               conn_report_term_evt(conn, tevt_loc_fd, fd_tevt_type_snd_err);
                conn->flags |= CO_FL_ERROR | CO_FL_SOCK_RD_SH;
                errno = EPIPE;
                conn_set_errno(conn, errno);
@@ -427,7 +427,7 @@ static size_t raw_sock_from_buf(struct connection *conn, void *xprt_ctx, const s
                        break;
                }
                else if (errno != EINTR) {
-                       conn_report_term_evt(conn, tevt_loc_fd, tevt_type_snd_err);
+                       conn_report_term_evt(conn, tevt_loc_fd, fd_tevt_type_snd_err);
                        conn->flags |= CO_FL_ERROR | CO_FL_SOCK_RD_SH | CO_FL_SOCK_WR_SH;
                        conn_set_errno(conn, errno);
                        break;
index 6750c1ac9ffdda5a05c4b01279a747eaa7f99898..160016e65e171a39e4891bf7a28e9168142b4ad0 100644 (file)
@@ -1007,7 +1007,7 @@ int sock_conn_check(struct connection *conn)
        /* Write error on the file descriptor. Report it to the connection
         * and disable polling on this FD.
         */
-       conn_report_term_evt(conn, tevt_loc_fd, tevt_type_truncated_rcv_err);
+       conn_report_term_evt(conn, tevt_loc_fd, fd_tevt_type_connect_err);
        conn->flags |= CO_FL_ERROR | CO_FL_SOCK_RD_SH | CO_FL_SOCK_WR_SH;
        HA_ATOMIC_AND(&fdtab[fd].state, ~FD_LINGER_RISK);
        fd_stop_both(fd);
index a76232fae31866c2828381f3144f8a74023f3395..15ca095e9ef7221fdc080a587dc3739d84ef4ffc 100644 (file)
@@ -5533,7 +5533,7 @@ reneg_ok:
 
        /* Report an HS error only on SSL error */
        if (!(conn->flags & (CO_FL_ERROR | CO_FL_SOCK_RD_SH | CO_FL_SOCK_WR_SH)))
-               conn_report_term_evt(conn, tevt_loc_hs, tevt_type_truncated_rcv_err);
+               conn_report_term_evt(conn, tevt_loc_hs, hs_tevt_type_truncated_rcv_err);
 
        /* Fail on all other handshake errors */
        conn->flags |= CO_FL_ERROR;
@@ -5886,12 +5886,12 @@ static size_t ssl_sock_to_buf(struct connection *conn, void *xprt_ctx, struct bu
        ssl_sock_dump_errors(conn, NULL);
        ERR_clear_error();
  read0:
-       conn_report_term_evt(conn, tevt_loc_xprt, tevt_type_shutr);
+       conn_report_term_evt(conn, tevt_loc_xprt, xprt_tevt_type_shutr);
        conn_sock_read0(conn);
        goto leave;
 
  out_error:
-       conn_report_term_evt(conn, tevt_loc_xprt, tevt_type_rcv_err);
+       conn_report_term_evt(conn, tevt_loc_xprt, xprt_tevt_type_rcv_err);
        conn->flags |= CO_FL_ERROR;
        /* Clear openssl global errors stack */
        ssl_sock_dump_errors(conn, NULL);
@@ -6058,7 +6058,7 @@ static size_t ssl_sock_from_buf(struct connection *conn, void *xprt_ctx, const s
        ssl_sock_dump_errors(conn, NULL);
        ERR_clear_error();
 
-       conn_report_term_evt(conn, tevt_loc_xprt, tevt_type_snd_err);
+       conn_report_term_evt(conn, tevt_loc_xprt, xprt_tevt_type_snd_err);
        conn->flags |= CO_FL_ERROR;
        goto leave;
 }
@@ -6149,7 +6149,7 @@ static void ssl_sock_shutw(struct connection *conn, void *xprt_ctx, int clean)
 
        if (conn->flags & (CO_FL_WAIT_XPRT | CO_FL_SSL_WAIT_HS))
                return;
-       conn_report_term_evt(conn, tevt_loc_xprt, tevt_type_shutw);
+       conn_report_term_evt(conn, tevt_loc_xprt, xprt_tevt_type_shutw);
        if (!clean)
                /* don't sent notify on SSL_shutdown */
                SSL_set_quiet_shutdown(ctx->ssl, 1);
index 2a7d0d6ed247f49d56e348b49918a448690c19a5..8771b32e88a437cc0a2ddd414bac8a73c19b5f59 100644 (file)
@@ -579,7 +579,7 @@ int tcp_exec_l4_rules(struct session *sess)
        }
  end:
        if (!result)
-               conn_report_term_evt(conn, tevt_loc_fd, tevt_type_intercepted);
+               conn_report_term_evt(conn, tevt_loc_fd, fd_tevt_type_intercepted);
        return result;
 }