From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-qt1-f180.google.com (mail-qt1-f180.google.com [209.85.160.180]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 6F7C52E8DFC for ; Wed, 25 Mar 2026 03:50:00 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.160.180 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1774410602; cv=none; b=SjMcGT9PhFPXX7L0Bq+D9QK7PdKUOdewYiD8N8sAX9RonXHVw5HI0chLYB5OU3ZDCueygJp2V6A10H/5vjPbLNsAHFLkiMbJ9ou/hQL/xihVZOjvGfSFxdB4GU2X2wBZ0tgflZSTfGhj+3/AQgMKVkpJEYkIG+t5DHBuXoneKiA= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1774410602; c=relaxed/simple; bh=ZfksrAT35SGjh9S69PtDz1n30eMUvXAa6Z6E76Byvl8=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=PX91zDy0miL5B6prDwqSoOwIHsdtpf067HsSL0aG+5VjS7k5ivkpU1VIUmcYAY6yEtkeROEhgaIBka9pb24NNyxMfJK3X1LZT75BgosmEH8F8gXjWMdbaBjBHMvfLH8GxgS8JffD6h2XP05jYXzqF2veHuHDimmjQlVd40ENm6Q= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=MSc7dZx2; arc=none smtp.client-ip=209.85.160.180 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="MSc7dZx2" Received: by mail-qt1-f180.google.com with SMTP id d75a77b69052e-50b29c4e554so56965751cf.0 for ; Tue, 24 Mar 2026 20:50:00 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1774410599; x=1775015399; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=3DlVwh603yhSMh+vfT6AQhDGntunvnIOcbWXqmoMRzk=; b=MSc7dZx2PfQryGadn5sbRQSLmwDsLNUOPfl/7JRK6UbKO3wEm3EejrA2FcBUpc0+UV NqUg7ClWZgJ3Wn+K6zuqpD/ll6/++WU/uVIzXVsEMIwBNKXGffFmQ7PsTB6inElt3e0u TirtHl7swDRXRt3268hVQnnOzPSC7fqIe3BZavrx0xgqytQUUF0FzukUkWK/Co7A1Rn1 b80wNXlYdO64ahUN5T2OCUg9MXr3igTiUzcHPCYEeEUPLLPkRECwxWPfloHSVbotdqsX 7hQ/x0yBM26dhBv0FlmbJAKIjdJ+sXwo5jo3J0rxs2MW7N9Dzj4Q1N4LfF+8kilmzAF3 K1UQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1774410599; x=1775015399; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=3DlVwh603yhSMh+vfT6AQhDGntunvnIOcbWXqmoMRzk=; b=abeXD0BpptM5I/7xh2g7qPzHbWB53icc97vTJVh1d1qMK0rRW86d35TYZCUr5WIH0u MpnolmHBnnfnqnXl+gv+Q5ZQH4PbvJ6hVfKnXZGh4fG3rmLxlpj+3oUsv84mtqkhMeXn pQea2GTntbjCYKB9LBbPtR9Fl/GVX01IWQshU5vDMsltN5ITZyLvpEovIAKQrnQzVwCd k+mYcT5r9ZFt43lJ1GgGMWJ6SOZdUeV49+jRjAROoNX1uK+L/WKRL393LxsBQfduqxp8 f3Fnz3sc9qlHVItnGnghtNe3HlYkE+BkSB323z6a+krvEK3BG3KJnZIRWYo1wpwL6myp ITYw== X-Gm-Message-State: AOJu0YyjrFgyJosrMTDTbGFFa+n/NxuDnnziQt1s3uJNlh1nYxwy6df5 zHVMZqxSTPVajAQLU0NxzR8jcfdXXA02fY4roKZmSm00a4nXe/PWj3dvy7c6XEwlpFk= X-Gm-Gg: ATEYQzwcfrVZWB/F6aPq910DdjQp8F/mbMASIBJn29lSIdyTx1/gyNBIfXeelxw3AfF wJXqyyug7RPg61p58JHGecgvlqcWknDTHboG2WxT9GPAINpHgy9qnbb0owO70mXctDjXuwFZq1i wdCmcA1yIVzzbvT2I+sR6Xy2+wN7BToNbEzvKeqHGVZmjdRvRYexWKXt7LC76T8ByS/t3ctMXPN KwLqc1NS8Qjp8qpkJ8LdIUFuywb+ffM9jOHQuNgO9N4cDfMj1MoOWjokgXtV2rEGiAUuVPmApD5 Q+4oWab0Qx+A42DSEKwrzCDrbBUUWiiMYb3qgsawL2Tq1wsNYRfTEzPnYEahLnnWsFARsU1NIjb irfoPQxvDKnEaaRqMEVJKX5Ss2dc8aLFOrViJhdV+5W3kufZFNSyrXa8GFfQFCfoJw1K0vZRKu7 9poNNS2nkuFWSGDA0kB21srYiKSxbz7KTngJ8WO3ORgi7sCXILjbSUXfqWorKLP/MN5CDkPNXqy iFoScQBeES5q1MOiTy1HNxRtNjZusEzSUz3r802gTL2EhIGJDah0bVPxfxbaQo0DxxKTj+xIR/c X-Received: by 2002:ac8:5a11:0:b0:50b:346a:d253 with SMTP id d75a77b69052e-50b80e0be45mr32332201cf.43.1774410599030; Tue, 24 Mar 2026 20:49:59 -0700 (PDT) Received: from wsfd-netdev58.anl.eng.rdu2.dc.redhat.com ([66.187.232.140]) by smtp.gmail.com with ESMTPSA id d75a77b69052e-50b36cb2e29sm150093001cf.1.2026.03.24.20.49.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 24 Mar 2026 20:49:58 -0700 (PDT) From: Xin Long To: network dev , quic@lists.linux.dev Cc: davem@davemloft.net, kuba@kernel.org, Eric Dumazet , Paolo Abeni , Simon Horman , Stefan Metzmacher , Moritz Buhl , Tyler Fanelli , Pengtao He , Thomas Dreibholz , linux-cifs@vger.kernel.org, Steve French , Namjae Jeon , Paulo Alcantara , Tom Talpey , kernel-tls-handshake@lists.linux.dev, Chuck Lever , Jeff Layton , Steve Dickson , Hannes Reinecke , Alexander Aring , David Howells , Matthieu Baerts , John Ericson , Cong Wang , "D . Wythe" , Jason Baron , illiliti , Sabrina Dubroca , Marcelo Ricardo Leitner , Daniel Stenberg , Andy Gospodarek , "Marc E . Fiuczynski" Subject: [PATCH net-next v11 14/15] quic: add packet builder base Date: Tue, 24 Mar 2026 23:47:19 -0400 Message-ID: <0e187083845cb83ee1be52bf44bc293b3b918e26.1774410440.git.lucien.xin@gmail.com> X-Mailer: git-send-email 2.47.1 In-Reply-To: References: Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit This patch introduces 'quic_packet' to handle packing of QUIC packets on the transmit (TX) path. It provides functionality for frame packing and packet construction. The packet configuration includes setting the path, calculating overhead, and verifying routing. Frames are appended to the packet before it is created with the queued frames. Once assembled, the packet is encrypted, bundled, and sent out. There is also support to flush the packet when no additional frames remain. Functions to create application (short) and handshake (long) packets are currently placeholders for future implementation. - quic_packet_config(): Set the path, compute overhead, and verify routing. - quic_packet_create_and_xmit(): Create and send the packet with the queued frames. - quic_packet_xmit(): Encrypt, bundle, and send out the packet. - quic_packet_flush(): Send the packet if there's nothing left to bundle. Signed-off-by: Xin Long --- v3: - Adjust global connection and listen socket hashtable operations based on the new hashtable type. - Introduce quic_packet_backlog_schedule() to enqueue Initial packets to quic_net.backlog_list and defer their decryption for ALPN demux to quic_packet_backlog_work() on quic_net.work, since quic_crypto_initial_keys_install()/crypto_aead_setkey() must run in process context. v4: - Update quic_(listen_)sock_lookup() to support lockless socket lookup using hlist_nulls_node APIs. - Use quic_wq for QUIC packet backlog processing work. v5: - Rename quic_packet_create() to quic_packet_create_and_xmit() (suggested by Paolo). - Move the packet parser base code to a separate patch, keeping only the packet builder base in this patch (suggested by Paolo). - Change sent_time timestamp from u32 to u64 to improve accuracy. v8: - Remove the dependency on struct quic_frame by returning NULL in quic_packet_handshake/app_create() and dropping quic_packet_tail() and struct quic_packet_sent. This effectively strips out patch 14 (suggested by Paolo). v9: - Warn on oversized header length in quic_packet_config() (suggested by Paolo). - Factor bundle initialization into a common 'init' goto label in quic_packet_bundle() (suggested by Paolo). - Clarify comment for packet->ipfragok in quic_packet_config(). v10: - Set MSS to QUIC_MIN_UDP_PAYLOAD in quic_packet_init(); it serves only as a default for procfs dumps before a connection exists. - Introduce QUIC_PACKET_INVALID as a return value for invalid packet types used in the later patch. - quic_sock.config.plpmtud_probe_interval has been moved to quic_path_group.plpmtud_interval, so update its usage in quic_packet_route() and quic_packet_config() accordingly. v11: - Set maximum line length to 80 characters. - Change return type of quic_packet_empty() to bool. - Propagate errors from quic_packet_route() in quic_packet_config() (noted by AI review). - Use quic_packet_taglen() instead of open-coded logic in quic_packet_mss(), quic_packet_max_payload(), and quic_packet_max_payload_dgram() (noted by AI review). - Replace some magic numbers with QUIC_PACKET_FORM_SHORT/LONG and QUIC_PACKET_MSS_NORMAL/DGRAM (noted by Paolo). - Use WARN_ON_ONCE() instead of WARN_ON() in quic_packet_xmit(). skb_set_owner_w/r() cannot be used here because it performs memory accounting, which is not desired in this context (noted by Paolo). --- net/quic/Makefile | 2 +- net/quic/packet.c | 268 ++++++++++++++++++++++++++++++++++++++++++++++ net/quic/packet.h | 117 ++++++++++++++++++++ net/quic/socket.c | 1 + net/quic/socket.h | 8 ++ 5 files changed, 395 insertions(+), 1 deletion(-) create mode 100644 net/quic/packet.c create mode 100644 net/quic/packet.h diff --git a/net/quic/Makefile b/net/quic/Makefile index 2ccf01ad9e22..0f903f4a7ff1 100644 --- a/net/quic/Makefile +++ b/net/quic/Makefile @@ -6,4 +6,4 @@ obj-$(CONFIG_IP_QUIC) += quic.o quic-y := common.o family.o protocol.o socket.o stream.o connid.o path.o \ - cong.o pnspace.o crypto.o timer.o + cong.o pnspace.o crypto.o timer.o packet.o diff --git a/net/quic/packet.c b/net/quic/packet.c new file mode 100644 index 000000000000..0805bc77c2a2 --- /dev/null +++ b/net/quic/packet.c @@ -0,0 +1,268 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +/* QUIC kernel implementation + * (C) Copyright Red Hat Corp. 2023 + * + * This file is part of the QUIC kernel implementation + * + * Initialization/cleanup for QUIC protocol support. + * + * Written or modified by: + * Xin Long + */ + +#include "socket.h" + +#define QUIC_HLEN 1 + +/* Make these fixed for easy coding. */ +#define QUIC_PACKET_NUMBER_LEN QUIC_PN_MAX_LEN +#define QUIC_PACKET_LENGTH_LEN 4 + +static struct sk_buff *quic_packet_handshake_create(struct sock *sk) +{ + return NULL; +} + +static int quic_packet_number_check(struct sock *sk) +{ + return 0; +} + +static struct sk_buff *quic_packet_app_create(struct sock *sk) +{ + return NULL; +} + +/* Update the MSS and inform congestion control. */ +void quic_packet_mss_update(struct sock *sk, u32 mss) +{ + struct quic_packet *packet = quic_packet(sk); + struct quic_cong *cong = quic_cong(sk); + + packet->mss[QUIC_PACKET_MSS_NORMAL] = (u16)mss; + quic_cong_set_mss(cong, packet->mss[QUIC_PACKET_MSS_NORMAL] - + packet->taglen[QUIC_PACKET_FORM_SHORT]); +} + +/* Perform routing for the QUIC packet on the specified path, update header + * length and MSS accordingly, reset path and start PMTU timer. + */ +int quic_packet_route(struct sock *sk) +{ + struct quic_path_group *paths = quic_paths(sk); + struct quic_packet *packet = quic_packet(sk); + union quic_addr *sa, *da; + u32 pmtu; + int err; + + da = quic_path_daddr(paths, packet->path); + sa = quic_path_saddr(paths, packet->path); + err = quic_flow_route(sk, da, sa, &paths->fl); + if (err) + return err < 0 ? err : 0; + + packet->hlen = quic_encap_len(da); + pmtu = min_t(u32, dst_mtu(__sk_dst_get(sk)), QUIC_PATH_MAX_PMTU); + quic_packet_mss_update(sk, pmtu - packet->hlen); + + quic_path_pl_reset(paths); + quic_timer_reset(sk, QUIC_TIMER_PMTU, paths->plpmtud_interval); + return 0; +} + +/* 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 *source = quic_source(sk); + struct quic_conn_id_set *dest = quic_dest(sk); + struct quic_packet *packet = quic_packet(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. */ + /* Length byte + SCID length. */ + hlen += 1 + quic_conn_id_active(source)->len; + /* Include token for Initial packets. */ + if (level == QUIC_CRYPTO_INITIAL) + 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. */ + /* Allow fragmentation for handshake packets before PLPMTUD + * probing starts. MTU discovery does not rely on ICMP Packet + * Too Big once PLPMTUD is enabled. + */ + packet->ipfragok = !!quic_paths(sk)->plpmtud_interval; + } + packet->level = level; + packet->len = (u16)hlen; + packet->overhead = (u8)hlen; + DEBUG_NET_WARN_ON_ONCE(hlen > 255); + + if (packet->path != path) { + /* Path changed; update and reset routing cache */ + packet->path = path; + __sk_dst_reset(sk); + } + + /* Perform routing and MSS update for the configured packet. */ + return quic_packet_route(sk); +} + +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. */ + goto init; + + /* If bundling would exceed MSS, flush the current bundle. */ + if (packet->head->len + skb->len >= + packet->mss[QUIC_PACKET_MSS_NORMAL]) { + quic_packet_flush(sk); + goto init; + } + /* Bundle it and update metadata for the aggregate skb. */ + p = packet->head; + head_cb = QUIC_SKB_CB(p); + if (head_cb->last == p) + skb_shinfo(p)->frag_list = skb; + else + head_cb->last->next = skb; + p->data_len += skb->len; + p->truesize += skb->truesize; + p->len += skb->len; + head_cb->last = skb; + head_cb->ecn |= cb->ecn; /* Merge ECN flags. */ + +out: + /* rfc9000#section-12.2: Packets with a short header (Section 17.3) do + * not contain a Length field and so cannot be followed by other + * packets in the same UDP datagram. + * + * so Return 1 to flush if it is a Short header packet. + */ + return !cb->level; +init: + packet->head = skb; + cb->last = skb; + goto out; +} + +/* Transmit a QUIC packet, possibly encrypting and bundling it. */ +int quic_packet_xmit(struct sock *sk, struct sk_buff *skb) +{ + struct quic_packet *packet = quic_packet(sk); + struct quic_skb_cb *cb = QUIC_SKB_CB(skb); + struct net *net = sock_net(sk); + int err; + + /* Skip encryption if taglen == 0 (e.g., disable_1rtt_encryption). */ + if (!packet->taglen[quic_hdr(skb)->form]) + goto xmit; + + cb->crypto_done = quic_packet_encrypt_done; + /* Associate skb with sk to ensure sk is valid during async encryption + * completion. + */ + WARN_ON_ONCE(!skb_set_owner_sk_safe(skb, sk)); + err = quic_crypto_encrypt(quic_crypto(sk, packet->level), skb); + if (err) { + if (err != -EINPROGRESS) { + QUIC_INC_STATS(net, QUIC_MIB_PKT_ENCDROP); + kfree_skb(skb); + return err; + } + QUIC_INC_STATS(net, QUIC_MIB_PKT_ENCBACKLOGS); + return err; + } + if (!cb->resume) /* Encryption completes synchronously. */ + QUIC_INC_STATS(net, QUIC_MIB_PKT_ENCFASTPATHS); + +xmit: + if (quic_packet_bundle(sk, skb)) + quic_packet_flush(sk); + return 0; +} + +/* Create and transmit a new QUIC packet. */ +int quic_packet_create_and_xmit(struct sock *sk) +{ + struct quic_packet *packet = quic_packet(sk); + struct sk_buff *skb; + int err; + + err = quic_packet_number_check(sk); + if (err) + goto err; + + if (packet->level) + skb = quic_packet_handshake_create(sk); + else + skb = quic_packet_app_create(sk); + if (!skb) { + err = -ENOMEM; + goto err; + } + + err = quic_packet_xmit(sk, skb); + if (err && err != -EINPROGRESS) + goto err; + + /* Return 1 if at least one ACK-eliciting (non-PING) frame was sent. */ + return !!packet->frames; +err: + pr_debug("%s: err: %d\n", __func__, err); + return 0; +} + +/* Flush any coalesced/bundled QUIC packets. */ +void quic_packet_flush(struct sock *sk) +{ + struct quic_path_group *paths = quic_paths(sk); + struct quic_packet *packet = quic_packet(sk); + + if (packet->head) { + quic_lower_xmit(sk, packet->head, + quic_path_daddr(paths, packet->path), + &paths->fl); + packet->head = NULL; + } +} + +void quic_packet_init(struct sock *sk) +{ + struct quic_packet *packet = quic_packet(sk); + + INIT_LIST_HEAD(&packet->frame_list); + packet->taglen[QUIC_PACKET_FORM_SHORT] = QUIC_TAG_LEN; + packet->taglen[QUIC_PACKET_FORM_LONG] = QUIC_TAG_LEN; + packet->mss[QUIC_PACKET_MSS_NORMAL] = QUIC_MIN_UDP_PAYLOAD; + packet->mss[QUIC_PACKET_MSS_DGRAM] = QUIC_MIN_UDP_PAYLOAD; + + packet->version = QUIC_VERSION_V1; +} diff --git a/net/quic/packet.h b/net/quic/packet.h new file mode 100644 index 000000000000..834c4f72271b --- /dev/null +++ b/net/quic/packet.h @@ -0,0 +1,117 @@ +/* SPDX-License-Identifier: GPL-2.0-or-later */ +/* QUIC kernel implementation + * (C) Copyright Red Hat Corp. 2023 + * + * This file is part of the QUIC kernel implementation + * + * Written or modified by: + * Xin Long + */ + +struct quic_packet { + struct quic_conn_id dcid; /* Dest Conn ID from received packet */ + struct quic_conn_id scid; /* Source Conn ID from received packet */ + union quic_addr daddr; /* Dest address from received packet */ + union quic_addr saddr; /* Source address from received packet */ + + struct list_head frame_list; /* Frames to pack into packet for send */ + struct sk_buff *head; /* Head skb for packet bundling on send */ + u16 frame_len; /* Length of all ack-eliciting frames excluding PING */ + u8 taglen[2]; /* Tag length for short and long packets */ + u32 version; /* QUIC version used/selected during handshake */ + u8 errframe; /* Frame type causing packet processing failure */ + u8 overhead; /* QUIC header length excluding frames */ + u16 errcode; /* Error code on packet processing failure */ + u16 frames; /* Number of ack-eliciting frames excluding PING */ + u16 mss[2]; /* MSS for datagram and non-datagram packets */ + u16 hlen; /* UDP + IP header length for sending */ + u16 len; /* QUIC packet length excluding taglen for sending */ + + u8 ack_eliciting:1; /* Packet contains ack-eliciting frames to send */ + u8 ack_requested:1; /* Packet contains ack-eliciting frames received */ + u8 ack_immediate:1; /* Send ACK immediately (skip ack_delay timer) */ + u8 non_probing:1; /* Ack-eliciting packet (excl. NEW_CONNECTION_ID) */ + u8 has_sack:1; /* Packet has ACK frames received */ + u8 ipfragok:1; /* Allow IP fragmentation */ + u8 padding:1; /* Packet has padding frames */ + u8 path:1; /* Path identifier used to send this packet */ + u8 level; /* Encryption level used */ +}; + +#define QUIC_PACKET_INITIAL_V1 0 +#define QUIC_PACKET_0RTT_V1 1 +#define QUIC_PACKET_HANDSHAKE_V1 2 +#define QUIC_PACKET_RETRY_V1 3 + +#define QUIC_PACKET_INITIAL_V2 1 +#define QUIC_PACKET_0RTT_V2 2 +#define QUIC_PACKET_HANDSHAKE_V2 3 +#define QUIC_PACKET_RETRY_V2 0 + +#define QUIC_PACKET_INITIAL QUIC_PACKET_INITIAL_V1 +#define QUIC_PACKET_0RTT QUIC_PACKET_0RTT_V1 +#define QUIC_PACKET_HANDSHAKE QUIC_PACKET_HANDSHAKE_V1 +#define QUIC_PACKET_RETRY QUIC_PACKET_RETRY_V1 + +#define QUIC_PACKET_INVALID 0xff + +#define QUIC_VERSION_LEN 4 + +#define QUIC_PACKET_MSS_NORMAL 0 +#define QUIC_PACKET_MSS_DGRAM 1 + +#define QUIC_PACKET_FORM_SHORT 0 +#define QUIC_PACKET_FORM_LONG 1 + +static inline u8 quic_packet_taglen(struct quic_packet *packet) +{ + return packet->taglen[packet->level != QUIC_CRYPTO_APP]; +} + +static inline void quic_packet_set_taglen(struct quic_packet *packet, u8 taglen) +{ + packet->taglen[QUIC_PACKET_FORM_SHORT] = taglen; +} + +static inline u32 quic_packet_mss(struct quic_packet *packet) +{ + return packet->mss[QUIC_PACKET_MSS_NORMAL] - quic_packet_taglen(packet); +} + +static inline u32 quic_packet_max_payload(struct quic_packet *packet) +{ + return packet->mss[QUIC_PACKET_MSS_NORMAL] - packet->overhead - + quic_packet_taglen(packet); +} + +static inline u32 quic_packet_max_payload_dgram(struct quic_packet *packet) +{ + return packet->mss[QUIC_PACKET_MSS_DGRAM] - packet->overhead - + quic_packet_taglen(packet); +} + +static inline bool quic_packet_empty(struct quic_packet *packet) +{ + return list_empty(&packet->frame_list); +} + +static inline void quic_packet_reset(struct quic_packet *packet) +{ + packet->level = 0; + packet->errcode = 0; + packet->errframe = 0; + packet->has_sack = 0; + packet->non_probing = 0; + packet->ack_requested = 0; + packet->ack_immediate = 0; +} + +int quic_packet_config(struct sock *sk, u8 level, u8 path); + +int quic_packet_xmit(struct sock *sk, struct sk_buff *skb); +int quic_packet_create_and_xmit(struct sock *sk); +int quic_packet_route(struct sock *sk); + +void quic_packet_mss_update(struct sock *sk, u32 mss); +void quic_packet_flush(struct sock *sk); +void quic_packet_init(struct sock *sk); diff --git a/net/quic/socket.c b/net/quic/socket.c index c37cc1522254..b9fbc33c0f79 100644 --- a/net/quic/socket.c +++ b/net/quic/socket.c @@ -52,6 +52,7 @@ static int quic_init_sock(struct sock *sk) quic_cong_init(quic_cong(sk)); quic_timer_init(sk); + quic_packet_init(sk); if (quic_stream_init(quic_streams(sk))) return -ENOMEM; diff --git a/net/quic/socket.h b/net/quic/socket.h index c5654fdc06b5..1efc76ec2033 100644 --- a/net/quic/socket.h +++ b/net/quic/socket.h @@ -20,6 +20,8 @@ #include "path.h" #include "cong.h" +#include "packet.h" + #include "protocol.h" #include "timer.h" @@ -74,6 +76,7 @@ struct quic_sock { struct quic_pnspace space[QUIC_PNSPACE_MAX]; struct quic_crypto crypto[QUIC_CRYPTO_MAX]; + struct quic_packet packet; struct quic_timer timers[QUIC_TIMER_MAX]; }; @@ -147,6 +150,11 @@ static inline struct quic_crypto *quic_crypto(const struct sock *sk, u8 level) return &quic_sk(sk)->crypto[level]; } +static inline struct quic_packet *quic_packet(const struct sock *sk) +{ + return &quic_sk(sk)->packet; +} + static inline void *quic_timer(const struct sock *sk, u8 type) { return (void *)&quic_sk(sk)->timers[type]; -- 2.47.1