MINOR: tevt/connection: Add dedicated termination events for lower locations

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.
This commit is contained in:
Christopher Faulet 2025-01-20 08:35:36 +01:00
parent 9cbc3229ec
commit f2778ccc7d
7 changed files with 56 additions and 31 deletions

View 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,

View 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;

View 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;
}

View 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;

View 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);

View 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);

View 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;
}