Re: [PATCH net-next v10 15/15] quic: add packet parser base
Xin Long <[email protected]> Wed, 4 Mar 2026 19:14:43 -0500
| Newsgroups | dev.linux.lists.quic,dev.linux.lists.kernel-tls-handshake,org.kernel.vger.linux-cifs,org.kernel.vger.netdev |
|---|---|
| Message-ID | <CADvbK_dhG7LZaRnz9JihHtboQmTLmudptGF1P+w5gyi=6Ls_2g@mail.gmail.com> |
On Tue, Mar 3, 2026 at 4:16=E2=80=AFAM Paolo Abeni <[email protected]> wrot= e: > > On 2/25/26 3:34 AM, Xin Long wrote: > > +/* Find the listening QUIC socket for an incoming packet. > > + * > > + * This function searches the QUIC socket table for a listening socket= that matches the dest > > + * address and port, and the ALPN(s) if presented in the ClientHello. = If multiple listening > > + * sockets are bound to the same address, port, and ALPN(s) (e.g., via= SO_REUSEPORT), this > > + * function selects a socket from the reuseport group. > > + * > > + * Return: A pointer to the matching listening socket, or NULL if no m= atch is found. > > + */ > > +struct sock *quic_listen_sock_lookup(struct sk_buff *skb, union quic_a= ddr *sa, union quic_addr *da, > > + struct quic_data *alpns) > > +{ > > + struct net *net =3D sock_net(skb->sk); > > + struct hlist_nulls_node *node; > > + struct sock *sk =3D NULL, *tmp; > > + struct quic_shash_head *head; > > + struct quic_data alpn; > > + union quic_addr *a; > > + u32 hash, len; > > + u64 length; > > + u8 *p; > > + > > + hash =3D quic_listen_sock_hash(net, ntohs(sa->v4.sin_port)); > > + head =3D quic_listen_sock_head(hash); > > + > > + rcu_read_lock(); > > +begin: > > + if (!alpns->len) { /* No ALPN entries present or failed to parse = the ALPNs. */ > > + sk_nulls_for_each_rcu(tmp, node, &head->head) { > > + /* If alpns->data !=3D NULL, TLS parsing succeede= d but no ALPN was found. > > + * In this case, only match sockets that have no = ALPN set. > > + */ > > + a =3D quic_path_saddr(quic_paths(tmp), 0); > > + if (net =3D=3D sock_net(tmp) && quic_cmp_sk_addr(= tmp, a, sa) && > > + quic_path_usock(quic_paths(tmp), 0) =3D=3D sk= b->sk && > > + (!alpns->data || !quic_alpn(tmp)->len)) { > > + sk =3D tmp; > > + if (!quic_is_any_addr(a)) /* Prefer speci= fic address match. */ > > + break; > > + } > > + } > > + goto out; > > + } > > + > > + /* ALPN present: loop through each ALPN entry. */ > > + for (p =3D alpns->data, len =3D alpns->len; len; len -=3D length,= p +=3D length) { > > + quic_get_int(&p, &len, &length, 1); > > + quic_data(&alpn, p, length); > > + sk_nulls_for_each_rcu(tmp, node, &head->head) { > > + a =3D quic_path_saddr(quic_paths(tmp), 0); > > + if (net =3D=3D sock_net(tmp) && quic_cmp_sk_addr(= tmp, a, sa) && > > + quic_path_usock(quic_paths(tmp), 0) =3D=3D sk= b->sk && > > + quic_data_has(quic_alpn(tmp), &alpn)) { > > + sk =3D tmp; > > + if (!quic_is_any_addr(a)) > > + break; > > + } > > + } > > + if (sk) > > + break; > > + } > > +out: > > + /* If the nulls value we got at the end of the iteration is diffe= rent from the expected > > + * one, we must restart the lookup as the list was modified concu= rrently. > > + */ > > + if (!sk && get_nulls_value(node) !=3D hash) > > + goto begin; > > + > > + if (sk && sk->sk_reuseport) > > + sk =3D reuseport_select_sock(sk, quic_addr_hash(net, da),= skb, 1); > > + > > + if (sk && unlikely(!refcount_inc_not_zero(&sk->sk_refcnt))) > > + sk =3D NULL; > > Note that you could avoid the refcount if you keep using the sk in an > RCU critical section. i.e. plain UDP does that. Same consideration for > established lookup. > Doesn't seem easy to adjust the code for this, I will leave it as it is for= now. Thanks.