]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: quic: Flag the connection as being attached to a listener
authorFrédéric Lécaille <flecaille@haproxy.com>
Mon, 10 Jan 2022 11:10:10 +0000 (12:10 +0100)
committerFrédéric Lécaille <flecaille@haproxy.com>
Tue, 11 Jan 2022 15:12:31 +0000 (16:12 +0100)
We do not rely on connection objects to know if we are a listener or not.

include/haproxy/xprt_quic-t.h
include/haproxy/xprt_quic.h
src/xprt_quic.c

index c6e4354edc669acb97004a7db49b8bb780ba4798..878e8bcad05390b83d2f162ded74080f219f2d14 100644 (file)
@@ -623,6 +623,7 @@ struct rxbuf {
 #define QUIC_FL_CONN_IO_CB_WAKEUP (1U << QUIC_FL_CONN_IO_CB_WAKEUP_BIT)
 
 #define QUIC_FL_POST_HANDSHAKE_FRAMES_BUILT     (1U << 2)
+#define QUIC_FL_CONN_LISTENER                   (1U << 3)
 #define QUIC_FL_CONN_IMMEDIATE_CLOSE            (1U << 31)
 struct quic_conn {
        /* The quic_conn instance is refcounted as it can be used by threads
index e1418fe1842f23f1d8f68b50a6bd80d20db65f46..2c41355ba6728cb6a4655fcaeb3fef56bc6f98ff 100644 (file)
@@ -51,6 +51,11 @@ extern struct pool_head *pool_head_quic_connection_id;
 
 int ssl_quic_initial_ctx(struct bind_conf *bind_conf);
 
+static inline int qc_is_listener(struct quic_conn *qc)
+{
+       return qc->flags & QUIC_FL_CONN_LISTENER;
+}
+
 /* Update the mux stream-related transport parameters from <qc> connection */
 static inline void quic_transport_params_update(struct quic_conn *qc)
 {
index e63cf83706b6d61b42eed0f1bce49c50477d0d72..92de7fad42547cefe2a96b6c3f13d81e5324a12c 100644 (file)
@@ -1866,7 +1866,7 @@ static inline int qc_provide_cdata(struct quic_enc_level *el,
                }
 
                TRACE_PROTO("SSL handshake OK", QUIC_EV_CONN_HDSHK, qc, &state);
-               if (objt_listener(ctx->conn->target))
+               if (qc_is_listener(ctx->qc))
                        HA_ATOMIC_STORE(&qc->state, QUIC_HS_ST_CONFIRMED);
                else
                        HA_ATOMIC_STORE(&qc->state, QUIC_HS_ST_COMPLETE);
@@ -2286,7 +2286,7 @@ static int qc_parse_pkt_frms(struct quic_rx_packet *pkt, struct ssl_sock_ctx *ct
                                        /* Nothing to do */
                                        TRACE_PROTO("Already received CRYPTO data",
                                                    QUIC_EV_CONN_ELRXPKTS, qc, pkt, &cfdebug);
-                                       if (objt_listener(ctx->conn->target) &&
+                                       if (qc_is_listener(ctx->qc) &&
                                            qel == &qc->els[QUIC_TLS_ENC_LEVEL_INITIAL])
                                                fast_retrans = 1;
                                        break;
@@ -2340,7 +2340,7 @@ static int qc_parse_pkt_frms(struct quic_rx_packet *pkt, struct ssl_sock_ctx *ct
                {
                        struct quic_stream *stream = &frm.stream;
 
-                       if (objt_listener(ctx->conn->target)) {
+                       if (qc_is_listener(ctx->qc)) {
                                if (stream->id & QUIC_STREAM_FRAME_ID_INITIATOR_BIT)
                                        goto err;
                        } else if (!(stream->id & QUIC_STREAM_FRAME_ID_INITIATOR_BIT))
@@ -2369,7 +2369,7 @@ static int qc_parse_pkt_frms(struct quic_rx_packet *pkt, struct ssl_sock_ctx *ct
                        tasklet_wakeup(qc->qcc->wait_event.tasklet);
                        break;
                case QUIC_FT_HANDSHAKE_DONE:
-                       if (objt_listener(ctx->conn->target))
+                       if (qc_is_listener(ctx->qc))
                                goto err;
 
                        HA_ATOMIC_STORE(&qc->state, QUIC_HS_ST_CONFIRMED);
@@ -2389,7 +2389,7 @@ static int qc_parse_pkt_frms(struct quic_rx_packet *pkt, struct ssl_sock_ctx *ct
         * has successfully parse a Handshake packet. The Initial encryption must also
         * be discarded.
         */
-       if (pkt->type == QUIC_PACKET_TYPE_HANDSHAKE && objt_listener(ctx->conn->target)) {
+       if (pkt->type == QUIC_PACKET_TYPE_HANDSHAKE && qc_is_listener(ctx->qc)) {
            int state = HA_ATOMIC_LOAD(&qc->state);
 
            if (state >= QUIC_HS_ST_SERVER_INITIAL) {
@@ -2498,7 +2498,7 @@ static int qc_prep_pkts(struct quic_conn *qc, struct qring *qr,
                if (!prv_pkt) {
                        /* Leave room for the datagram header */
                        pos += dg_headlen;
-                       if (!quic_peer_validated_addr(qc) && objt_listener(qc->conn->target)) {
+                       if (!quic_peer_validated_addr(qc) && qc_is_listener(qc)) {
                                end = pos + QUIC_MIN(qc->path->mtu, 3 * qc->rx.bytes - qc->tx.prep_bytes);
                        }
                        else {
@@ -2949,7 +2949,7 @@ static inline void qc_rm_hp_pkts(struct quic_conn *qc, struct quic_enc_level *el
        TRACE_ENTER(QUIC_EV_CONN_ELRMHP, qc);
        app_qel = &qc->els[QUIC_TLS_ENC_LEVEL_APP];
        /* A server must not process incoming 1-RTT packets before the handshake is complete. */
-       if (el == app_qel && objt_listener(qc->conn->target) &&
+       if (el == app_qel && qc_is_listener(qc) &&
            HA_ATOMIC_LOAD(&qc->state) < QUIC_HS_ST_COMPLETE) {
                TRACE_PROTO("hp not removed (handshake not completed)",
                            QUIC_EV_CONN_ELRMHP, qc);
@@ -3366,7 +3366,7 @@ static struct task *process_timer(struct task *task, void *ctx, unsigned int sta
        st = HA_ATOMIC_LOAD(&qc->state);
        if (qc->path->in_flight) {
                pktns = quic_pto_pktns(qc, st >= QUIC_HS_ST_COMPLETE, NULL);
-               if (objt_listener(qc->conn->target) &&
+               if (qc_is_listener(qc) &&
                    pktns == &qc->pktns[QUIC_TLS_PKTNS_HANDSHAKE] &&
                    qc->pktns[QUIC_TLS_PKTNS_INITIAL].tx.in_flight)
                    qc->pktns[QUIC_TLS_PKTNS_INITIAL].tx.pto_probe = 1;
@@ -3439,6 +3439,7 @@ static struct quic_conn *qc_new_conn(unsigned int version, int ipv4,
        if (server) {
                l = owner;
 
+               qc->flags |= QUIC_FL_CONN_LISTENER;
                HA_ATOMIC_STORE(&qc->state, QUIC_HS_ST_SERVER_INITIAL);
                /* Copy the initial DCID with the address. */
                qc->odcid.len = dcid_len;