Re: [PATCH net-next v8 14/15] quic: add packet builder base

Paolo Abeni <[email protected]> Thu, 29 Jan 2026 17:40:49 +0100
Newsgroups dev.linux.lists.quic,dev.linux.lists.kernel-tls-handshake,org.kernel.vger.linux-cifs,org.kernel.vger.netdev
Message-ID <[email protected]>
On 1/26/26 3:51 PM, Xin Long wrote:
> +/* Configure the QUIC packet header and routing based on encryption level and path. */
> +int quic_packet_config(struct sock *sk, u8 level, u8 path)
> +{
> +	struct quic_conn_id_set *dest = quic_dest(sk), *source = quic_source(sk);
> +	struct quic_packet *packet = quic_packet(sk);
> +	struct quic_config *c = quic_config(sk);
> +	u32 hlen = QUIC_HLEN;
> +
> +	/* If packet already has data, no need to reconfigure. */
> +	if (!quic_packet_empty(packet))
> +		return 0;
> +
> +	packet->ack_eliciting = 0;
> +	packet->frame_len = 0;
> +	packet->ipfragok = 0;
> +	packet->padding = 0;
> +	packet->frames = 0;
> +	hlen += QUIC_PACKET_NUMBER_LEN; /* Packet number length. */
> +	hlen += quic_conn_id_choose(dest, path)->len; /* DCID length. */
> +	if (level) {
> +		hlen += 1; /* Length byte for DCID. */
> +		hlen += 1 + quic_conn_id_active(source)->len; /* Length byte + SCID length. */
> +		if (level == QUIC_CRYPTO_INITIAL) /* Include token for Initial packets. */
> +			hlen += quic_var_len(quic_token(sk)->len) + quic_token(sk)->len;
> +		hlen += QUIC_VERSION_LEN; /* Version length. */
> +		hlen += QUIC_PACKET_LENGTH_LEN; /* Packet length field length. */
> +		/* Allow fragmentation if PLPMTUD is enabled, as it no longer relies on ICMP
> +		 * Toobig messages to discover the path MTU.
> +		 */
> +		packet->ipfragok = !!c->plpmtud_probe_interval;
> +	}
> +	packet->level = level;
> +	packet->len = (u16)hlen;
> +	packet->overhead = (u8)hlen;

Given the above math, it looks like hlen can never be > 255, but
possibly a DEBUG_NET_WARN_ON_ONCE() could save from future bug and make
the code more clear?

> +
> +	if (packet->path != path) { /* If the path changed, update and reset routing cache. */
> +		packet->path = path;
> +		__sk_dst_reset(sk);
> +	}
> +
> +	/* Perform routing and MSS update for the configured packet. */
> +	if (quic_packet_route(sk) < 0)
> +		return -1;
> +	return 0;
> +}
> +
> +static void quic_packet_encrypt_done(struct sk_buff *skb, int err)
> +{
> +	/* Free it for now, future patches will implement the actual deferred transmission logic. */
> +	kfree_skb(skb);
> +}
> +
> +/* Coalescing Packets. */
> +static int quic_packet_bundle(struct sock *sk, struct sk_buff *skb)
> +{
> +	struct quic_skb_cb *head_cb, *cb = QUIC_SKB_CB(skb);
> +	struct quic_packet *packet = quic_packet(sk);
> +	struct sk_buff *p;
> +
> +	if (!packet->head) { /* First packet to bundle: initialize the head. */
> +		packet->head = skb;
> +		cb->last = skb;
> +		goto out;
> +	}
> +
> +	/* If bundling would exceed MSS, flush the current bundle. */
> +	if (packet->head->len + skb->len >= packet->mss[0]) {
> +		quic_packet_flush(sk);
> +		packet->head = skb;
> +		cb->last = skb;
> +		goto out;

The same code is duplicate a few lines above; you could reduce
duplication jumping to a common label.

/P