Line data Source code
1 : /* SPDX-License-Identifier: GPL-2.0-or-later */ 2 : /* QUIC kernel implementation 3 : * (C) Copyright Red Hat Corp. 2023 4 : * 5 : * This file is part of the QUIC kernel implementation 6 : * 7 : * Written or modified by: 8 : * Xin Long <lucien.xin@gmail.com> 9 : */ 10 : 11 : struct quic_packet { 12 : struct quic_conn_id dcid; /* Dest Connection ID from received packet */ 13 : struct quic_conn_id scid; /* Source Connection ID from received packet */ 14 : union quic_addr daddr; /* Dest address from received packet */ 15 : union quic_addr saddr; /* Source address from received packet */ 16 : 17 : struct list_head frame_list; /* List of frames to pack into packet for send */ 18 : struct sk_buff *head; /* Head skb for packet bundling on send */ 19 : u16 frame_len; /* Length of all ack-eliciting frames excluding PING */ 20 : u8 taglen[2]; /* Tag length for short and long packets */ 21 : u32 version; /* QUIC version used/selected during handshake */ 22 : u8 errframe; /* Frame type causing packet processing failure */ 23 : u8 overhead; /* QUIC header length excluding frames */ 24 : u16 errcode; /* Error code on packet processing failure */ 25 : u16 frames; /* Number of ack-eliciting frames excluding PING */ 26 : u16 mss[2]; /* MSS for datagram and non-datagram packets */ 27 : u16 hlen; /* UDP + IP header length for sending */ 28 : u16 len; /* QUIC packet length excluding taglen for sending */ 29 : 30 : u8 ack_eliciting:1; /* Packet contains ack-eliciting frames to send */ 31 : u8 ack_requested:1; /* Packet contains ack-eliciting frames received */ 32 : u8 ack_immediate:1; /* Send ACK immediately (skip ack_delay timer) */ 33 : u8 non_probing:1; /* Packet has ack-eliciting frames excluding NEW_CONNECTION_ID */ 34 : u8 has_sack:1; /* Packet has ACK frames received */ 35 : u8 ipfragok:1; /* Allow IP fragmentation */ 36 : u8 padding:1; /* Packet has padding frames */ 37 : u8 path:1; /* Path identifier used to send this packet */ 38 : u8 level; /* Encryption level used */ 39 : }; 40 : 41 : struct quic_packet_sent { 42 : struct list_head list; /* Link in sent packet list for ACK tracking */ 43 : u32 sent_time; /* Time when packet was sent */ 44 : u16 frame_len; /* Combined length of all frames held */ 45 : u16 frames; /* Number of frames held */ 46 : 47 : s64 number; /* Packet number */ 48 : u8 level; /* Packet number space */ 49 : u8 ecn:2; /* ECN bits */ 50 : 51 : struct quic_frame *frame_array[]; /* Array of pointers to held frames */ 52 : }; 53 : 54 : #define QUIC_PACKET_INITIAL_V1 0 55 : #define QUIC_PACKET_0RTT_V1 1 56 : #define QUIC_PACKET_HANDSHAKE_V1 2 57 : #define QUIC_PACKET_RETRY_V1 3 58 : 59 : #define QUIC_PACKET_INITIAL_V2 1 60 : #define QUIC_PACKET_0RTT_V2 2 61 : #define QUIC_PACKET_HANDSHAKE_V2 3 62 : #define QUIC_PACKET_RETRY_V2 0 63 : 64 : #define QUIC_PACKET_INITIAL QUIC_PACKET_INITIAL_V1 65 : #define QUIC_PACKET_0RTT QUIC_PACKET_0RTT_V1 66 : #define QUIC_PACKET_HANDSHAKE QUIC_PACKET_HANDSHAKE_V1 67 : #define QUIC_PACKET_RETRY QUIC_PACKET_RETRY_V1 68 : 69 : #define QUIC_VERSION_LEN 4 70 : 71 15522883 : static inline u8 quic_packet_taglen(struct quic_packet *packet) 72 : { 73 15522883 : return packet->taglen[!!packet->level]; 74 : } 75 : 76 4 : static inline void quic_packet_set_taglen(struct quic_packet *packet, u8 taglen) 77 : { 78 4 : packet->taglen[0] = taglen; 79 4 : } 80 : 81 2662113 : static inline u32 quic_packet_mss(struct quic_packet *packet) 82 : { 83 2662113 : return packet->mss[0] - packet->taglen[!!packet->level]; 84 : } 85 : 86 10257158 : static inline u32 quic_packet_max_payload(struct quic_packet *packet) 87 : { 88 10257158 : return packet->mss[0] - packet->overhead - packet->taglen[!!packet->level]; 89 : } 90 : 91 12 : static inline u32 quic_packet_max_payload_dgram(struct quic_packet *packet) 92 : { 93 12 : return packet->mss[1] - packet->overhead - packet->taglen[!!packet->level]; 94 : } 95 : 96 28920071 : static inline int quic_packet_empty(struct quic_packet *packet) 97 : { 98 28920071 : return list_empty(&packet->frame_list); 99 : } 100 : 101 6576445 : static inline void quic_packet_reset(struct quic_packet *packet) 102 : { 103 6576445 : packet->level = 0; 104 6576445 : packet->errcode = 0; 105 6576445 : packet->errframe = 0; 106 6576445 : packet->has_sack = 0; 107 6576445 : packet->non_probing = 0; 108 6576445 : packet->ack_requested = 0; 109 6576445 : packet->ack_immediate = 0; 110 : } 111 : 112 : int quic_packet_tail(struct sock *sk, struct quic_frame *frame); 113 : int quic_packet_process(struct sock *sk, struct sk_buff *skb); 114 : int quic_packet_config(struct sock *sk, u8 level, u8 path); 115 : 116 : int quic_packet_xmit(struct sock *sk, struct sk_buff *skb); 117 : int quic_packet_create(struct sock *sk); 118 : int quic_packet_route(struct sock *sk); 119 : 120 : void quic_packet_mss_update(struct sock *sk, u32 mss); 121 : void quic_packet_flush(struct sock *sk); 122 : void quic_packet_init(struct sock *sk); 123 : 124 : int quic_packet_get_dcid(struct quic_conn_id *dcid, struct sk_buff *skb); 125 : int quic_packet_select_version(struct sock *sk, u32 *versions, u8 count); 126 : u32 *quic_packet_compatible_versions(u32 version); 127 : 128 : void quic_packet_rcv_err_pmtu(struct sock *sk); 129 : int quic_packet_rcv(struct sk_buff *skb, u8 err);