]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: quic: use signed char type for ALPN manipulation
authorAmaury Denoyelle <adenoyelle@haproxy.com>
Tue, 3 Mar 2026 08:02:44 +0000 (09:02 +0100)
committerAmaury Denoyelle <adenoyelle@haproxy.com>
Tue, 3 Mar 2026 15:11:58 +0000 (16:11 +0100)
In most of haproxy code, ALPN is used as a signed char pointer. In QUIC
code instead, it is manipulated as unsigned.

Unifies this by using signed type in QUIC code. This allows to remove a
bunch of unnecessary casts.

include/haproxy/quic_conn.h
src/quic_conn.c
src/quic_ssl.c
src/ssl_sock.c

index 92e6c1c74033e28f8ffda538df1f95af598dc499..c34681e7d4fabf9021b104092e6d76293e7d08e6 100644 (file)
@@ -84,7 +84,7 @@ void qc_check_close_on_released_mux(struct quic_conn *qc);
 int quic_stateless_reset_token_cpy(unsigned char *pos, size_t len,
                                    const unsigned char *salt, size_t saltlen);
 int quic_reuse_srv_params(struct quic_conn *qc,
-                          const unsigned char *alpn,
+                          const char *alpn,
                           const struct quic_early_transport_params *etps);
 
 /* Returns true if <qc> is used on the backed side (as a client). */
@@ -204,7 +204,7 @@ static inline void *qc_counters(enum obj_type *o, const struct stats_module *m)
 void chunk_frm_appendf(struct buffer *buf, const struct quic_frame *frm);
 void quic_set_connection_close(struct quic_conn *qc, const struct quic_err err);
 void quic_set_tls_alert(struct quic_conn *qc, int alert);
-int quic_set_app_ops(struct quic_conn *qc, const unsigned char *alpn, size_t alpn_len);
+int quic_set_app_ops(struct quic_conn *qc, const char *alpn, int alpn_len);
 int qc_check_dcid(struct quic_conn *qc, unsigned char *dcid, size_t dcid_len);
 
 void qc_notify_err(struct quic_conn *qc);
index ac4cf2a84026ca5441a3065fa5a6ae23cb1f9abf..61552e905c931c5b7100ac390cf6698c8afae24e 100644 (file)
@@ -272,7 +272,7 @@ void quic_set_tls_alert(struct quic_conn *qc, int alert)
 /* Set the application for <qc> QUIC connection.
  * Return 1 if succeeded, 0 if not.
  */
-int quic_set_app_ops(struct quic_conn *qc, const unsigned char *alpn, size_t alpn_len)
+int quic_set_app_ops(struct quic_conn *qc, const char *alpn, int alpn_len)
 {
        if (alpn_len >= 2 && memcmp(alpn, "h3", 2) == 0)
                qc->app_ops = &h3_ops;
@@ -290,14 +290,14 @@ int quic_set_app_ops(struct quic_conn *qc, const unsigned char *alpn, size_t alp
  * Return 1 if succeeded, 0 if not.
  */
 int quic_reuse_srv_params(struct quic_conn *qc,
-                          const unsigned char *alpn,
+                          const char *alpn,
                           const struct quic_early_transport_params *etps)
 {
        int ret = 0;
 
        TRACE_ENTER(QUIC_EV_CONN_NEW, qc);
 
-       if (!alpn || !quic_set_app_ops(qc, alpn, strlen((char *)alpn)))
+       if (!alpn || !quic_set_app_ops(qc, alpn, strlen(alpn)))
                goto err;
 
        qc_early_transport_params_reuse(qc, &qc->tx.params, etps);
index ad3c3c509717dcc7fcbcffa20efc16cccb6ffa6b..88f3268d0a300d1a4dd11831f7fe06734ff810b4 100644 (file)
@@ -1011,11 +1011,11 @@ int qc_ssl_do_hanshake(struct quic_conn *qc, struct ssl_sock_ctx *ctx)
                        }
                }
                else if (qc->conn) {
-                       const unsigned char *alpn;
-                       size_t alpn_len;
+                       const char *alpn;
+                       int alpn_len;
 
                        qc->conn->flags &= ~(CO_FL_SSL_WAIT_HS | CO_FL_WAIT_L6_CONN);
-                       if (!ssl_sock_get_alpn(qc->conn, ctx, (const char **)&alpn, (int *)&alpn_len) ||
+                       if (!ssl_sock_get_alpn(qc->conn, ctx, &alpn, &alpn_len) ||
                            !quic_set_app_ops(qc, alpn, alpn_len)) {
                                TRACE_ERROR("No negotiated ALPN", QUIC_EV_CONN_IO_CB, qc, &state);
                                quic_set_tls_alert(qc, SSL_AD_NO_APPLICATION_PROTOCOL);
@@ -1358,7 +1358,7 @@ int qc_alloc_ssl_sock_ctx(struct quic_conn *qc, void *target)
 #if (HA_OPENSSL_VERSION_NUMBER >= 0x10101000L) && defined(HAVE_SSL_0RTT_QUIC)
                if ((srv->ssl_ctx.options & SRV_SSL_O_EARLY_DATA)) {
                        int ret;
-                       unsigned char *alpn;
+                       char *alpn;
                        struct quic_early_transport_params *etps;
                        /* This code is called by connect_server() by way of
                         * conn_prepare().
@@ -1374,7 +1374,7 @@ int qc_alloc_ssl_sock_ctx(struct quic_conn *qc, void *target)
                         * able to send data at early-data level.
                         */
                        HA_RWLOCK_RDLOCK(SERVER_LOCK, &srv->path_params.param_lock);
-                       alpn = (unsigned char *)srv->path_params.nego_alpn;
+                       alpn = srv->path_params.nego_alpn;
                        etps = &srv->path_params.tps;
                        ret = quic_reuse_srv_params(qc, alpn, etps);
                        HA_RWLOCK_RDUNLOCK(SERVER_LOCK, &srv->path_params.param_lock);
index 483532bf349b9ea9556b846d3883f4b433969798..ff266f0ea60f7483b310b6b5dcda30a6390cf2f3 100644 (file)
@@ -2242,7 +2242,7 @@ static int ssl_sock_advertise_alpn_protos(SSL *s, const unsigned char **out,
        }
 
 #ifdef USE_QUIC
-       if (qc && !quic_set_app_ops(qc, *out, *outlen)) {
+       if (qc && !quic_set_app_ops(qc, (const char *)*out, *outlen)) {
                quic_set_tls_alert(qc, SSL_AD_NO_APPLICATION_PROTOCOL);
                return SSL_TLSEXT_ERR_NOACK;
        }