]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MEDIUM: xprt: Add a "get_capability" method.
authorOlivier Houchard <ohouchard@haproxy.com>
Wed, 13 Aug 2025 13:39:26 +0000 (13:39 +0000)
committerOlivier Houchard <cognet@ci0.org>
Wed, 20 Aug 2025 16:33:10 +0000 (18:33 +0200)
Add a new method to xprts, get_capability, that can be used to query if
an xprt supports something or not.
The first capability implemented is XPRT_CAN_SPLICE, to know if the xprt
will be able to use splicing for the provided connection.
The possible answers are XPRT_CONN_CAN_NOT_SPLICE, which indicates
splicing will never be possible for that connection,
XPRT_CONN_COULD_SPLICE, which indicates that splicing is not usable
right now, but may be in the future, and XPRT_CONN_CAN_SPLICE, that
means we can splice right away.

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

index 69a41d74e8e9515bcaa44012372a8a0932d8db10..35b7eaf3461ea510669bd04f4ce2f7df7b1f2e0a 100644 (file)
@@ -433,6 +433,16 @@ union conn_handle {
        int fd;                 /* file descriptor, for regular sockets (CO_FL_FDLESS=0) */
 };
 
+enum xprt_capabilities {
+       XPRT_CAN_SPLICE,
+};
+
+enum xprt_splice_cap {
+       XPRT_CONN_CAN_NOT_SPLICE, /* This connection can't, and won't ever be able to splice */
+       XPRT_CONN_COULD_SPLICE, /* This connection can't splice, but may later */
+       XPRT_CONN_CAN_SPLICE /* This connection can splice */
+};
+
 /* xprt_ops describes transport-layer operations for a connection. They
  * generally run over a socket-based control layer, but not always. Some
  * of them are used for data transfer with the upper layer (rcv_*, snd_*)
@@ -464,6 +474,12 @@ struct xprt_ops {
        struct ssl_sock_ctx *(*get_ssl_sock_ctx)(struct connection *); /* retrieve the ssl_sock_ctx in use, or NULL if none */
        int (*show_fd)(struct buffer *, const struct connection *, const void *ctx); /* append some data about xprt for "show fd"; returns non-zero if suspicious */
        void (*dump_info)(struct buffer *, const struct connection *);
+       /*
+        * Returns the value for various capabilities.
+        * Returns 0 if the capability is known, iwth the actual value in arg,
+        * or -1 otherwise
+        */
+       int (*get_capability)(struct connection *connection, void *xprt_ctx, enum xprt_capabilities, void *arg);
 };
 
 /* mux_ops describes the mux operations, which are to be performed at the
index a769c20f492a472f728c1ca91221df2b322bfdaa..ddfe0e464d89d8e52e88f963e434693fc88f1f26 100644 (file)
@@ -506,6 +506,19 @@ static int raw_sock_remove_xprt(struct connection *conn, void *xprt_ctx, void *t
        return -1;
 }
 
+static int raw_sock_get_capability(struct connection *conn, void *xprt_ctx, enum xprt_capabilities cap, void *arg)
+{
+       int *ret;
+
+       switch (cap) {
+               case XPRT_CAN_SPLICE:
+                       ret = arg;
+                       *ret = XPRT_CONN_CAN_SPLICE;
+                       return 0;
+       }
+       return -1;
+}
+
 /* transport-layer operations for RAW sockets */
 static struct xprt_ops raw_sock = {
        .snd_buf  = raw_sock_from_buf,
@@ -517,6 +530,7 @@ static struct xprt_ops raw_sock = {
        .rcv_pipe = raw_sock_to_pipe,
        .snd_pipe = raw_sock_from_pipe,
 #endif
+       .get_capability = raw_sock_get_capability,
        .shutr    = NULL,
        .shutw    = NULL,
        .close    = raw_sock_close,
index f67e30b0dd1dd0e1b65ac85b6c79c73d459e387c..de4de74498d8407e46562b29931cba019166c60a 100644 (file)
@@ -6981,6 +6981,18 @@ yield:
 }
 #endif
 
+static int ssl_sock_get_capability(struct connection *conn, void *xprt_ctx, enum xprt_capabilities cap, void *arg)
+{
+       int *ret;
+
+       switch (cap) {
+               case XPRT_CAN_SPLICE:
+                       ret = arg;
+                       *ret = XPRT_CONN_CAN_NOT_SPLICE;
+                       return 0;
+       }
+       return -1;
+}
 
 /* register cli keywords */
 static struct cli_kw_list cli_kws = {{ },{
@@ -7011,6 +7023,7 @@ struct xprt_ops ssl_sock = {
        .close    = ssl_sock_close,
        .init     = ssl_sock_init,
        .start    = ssl_sock_start,
+       .get_capability = ssl_sock_get_capability,
        .prepare_bind_conf = ssl_sock_prepare_bind_conf,
        .destroy_bind_conf = ssl_sock_destroy_bind_conf,
        .prepare_srv = ssl_sock_prepare_srv_ctx,