From patchwork Fri Oct 4 19:16:40 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Dumazet X-Patchwork-Id: 13822881 X-Patchwork-Delegate: kuba@kernel.org Received: from mail-yw1-f201.google.com (mail-yw1-f201.google.com [209.85.128.201]) (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 3B1B41D89E3 for ; Fri, 4 Oct 2024 19:16:50 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1728069411; cv=none; b=PxrpoGe+Ob54ujI+sw/5MrM5GLn51mPii64LJcTpAWb4HkKbH/XN46iZdVZAdcCvIIWhijPNM59m3TZED3i/JYoZ/o6Uy5YDphO6JUJrOGRdIWkO3DUXWJZLd3GpZ322remxl6laEYVf1X5EcB3NDSpy5ascE4GIPr5Rr7+IfHk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1728069411; c=relaxed/simple; bh=rTCD9ejq9MFBN2es73b/PZLWoyvSmBIWX5nySeKvVHk=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=Pa8dSCCQleIEG8RVTI7ibxgSTqVN+Ai9Z2kHhYwlfn+S7bGTIzPBRRQk9f9r1TXVDVbdUuD0Jwqlq4ZwOTsmaXYxfVhvrmmvfW1+EbfvRqWzgH6DoyRtyQpZI1uShossMsEwBS1+C+bGfnYOyZKtk9j5kds6VOzPZfazi+HYFQI= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--edumazet.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=eIGPwlL6; arc=none smtp.client-ip=209.85.128.201 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--edumazet.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="eIGPwlL6" Received: by mail-yw1-f201.google.com with SMTP id 00721157ae682-6e2d1860a62so14320307b3.0 for ; Fri, 04 Oct 2024 12:16:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1728069409; x=1728674209; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=G/CDj+TbYDNeuPFKYt3YFNfSKaDL3LjUTUjPD2KZNno=; b=eIGPwlL6Qh8cfB37/tIlrsIRfYNEFQgAG+eDM7KIsaXDeKEIB4GK1IhXHIA2LRG34r +fxBuA01H0CwMud8tZBx217qvkpkTiuBVeXo9xfFQJ7iJyVr/Aq6ZX3bBJCF+tXDuwRD QDmHMDh96MlZuv0JZSk4LfXfM2RFhfVWSWJf6ycOdU06aYOOFCQqXtXVi8vEf7OOJP9h fo3DkZNL4BIngv5QJY+q/ayt6jQJ/WazibN446YNxMrL6WxmDcLoWr3fQXAfzTutXGdk etCNQpEACHpAEWFFQN1CsuKBqDS3LSWL/91vDTuH8KQcwOLRYhtkecYz2VA/xcp/HKT1 JhZg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1728069409; x=1728674209; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=G/CDj+TbYDNeuPFKYt3YFNfSKaDL3LjUTUjPD2KZNno=; b=iRdNz1QG5akv/PMNNP/71Ys5D1pUk45wP9ReMLMjcohkDl6ksRLriQRo+W2G9tauTa +6A7W677y9IZkB/767X6WU3euNq3UPE/ARP7cpDnRW7WkF9OCLDH5iOLC9CHB9do4/Xk Y4OIbfrNWpvXUKOjUcWEQKShqGcD3jygsR1Im/F+80+Q6hAxxeKZVEy3uLIN6RmVziNq mK7rRLkuRoTkTB2+x2RLulSXyg9eT/QIuIQxZXmcKVhPF6gXdh54n5W9FSoKJviZEYBv q4M4IChM6pI7dmZ/bGhotte0/CgxVpskBdnUfRw6UXV+sNyCAH3dDDrns2wSrdHIb9JI OGXA== X-Gm-Message-State: AOJu0YyrdsxRAeoPB2PpkuMLBWtJTHok4IKOl8nT0w6nnKEhV61upgbs vaj8La3qCnnxfRHF3JTXW9worSLxGonwsgxgBE6JCb5q0zo738POlxV9sppPY8TDPdVYuPWPsId NTeV4rrnFxQ== X-Google-Smtp-Source: AGHT+IE3YGh73IUKt3tF3dvy7/GbTQEhVEzQDTI+ZlOSwQg4lIVOEJq0o3dEVeO0MAQ7cNP9Qriaq9jzNHZ/jQ== X-Received: from edumazet1.c.googlers.com ([fda3:e722:ac3:cc00:f7:ea0b:ac12:11d6]) (user=edumazet job=sendgmr) by 2002:a25:d003:0:b0:e24:a28e:9399 with SMTP id 3f1490d57ef6-e28936d2d3bmr2275276.4.1728069409213; Fri, 04 Oct 2024 12:16:49 -0700 (PDT) Date: Fri, 4 Oct 2024 19:16:40 +0000 In-Reply-To: <20241004191644.1687638-1-edumazet@google.com> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20241004191644.1687638-1-edumazet@google.com> X-Mailer: git-send-email 2.47.0.rc0.187.ge670bccf7e-goog Message-ID: <20241004191644.1687638-2-edumazet@google.com> Subject: [PATCH net-next 1/5] net: add TIME_WAIT logic to sk_to_full_sk() From: Eric Dumazet To: "David S . Miller" , Jakub Kicinski , Paolo Abeni , Martin KaFai Lau Cc: netdev@vger.kernel.org, eric.dumazet@gmail.com, Eric Dumazet X-Patchwork-Delegate: kuba@kernel.org TCP will soon attach TIME_WAIT sockets to some ACK and RST. Make sure sk_to_full_sk() detects this and does not return a non full socket. Signed-off-by: Eric Dumazet --- include/net/inet_sock.h | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/include/net/inet_sock.h b/include/net/inet_sock.h index 394c3b66065e20d34594d6e2a2010c55bb457810..cec093b78151b9a3b95ad4b3672a72b0aa9a8305 100644 --- a/include/net/inet_sock.h +++ b/include/net/inet_sock.h @@ -319,8 +319,10 @@ static inline unsigned long inet_cmsg_flags(const struct inet_sock *inet) static inline struct sock *sk_to_full_sk(struct sock *sk) { #ifdef CONFIG_INET - if (sk && sk->sk_state == TCP_NEW_SYN_RECV) + if (sk && READ_ONCE(sk->sk_state) == TCP_NEW_SYN_RECV) sk = inet_reqsk(sk)->rsk_listener; + if (sk && READ_ONCE(sk->sk_state) == TCP_TIME_WAIT) + sk = NULL; #endif return sk; } From patchwork Fri Oct 4 19:16:41 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Dumazet X-Patchwork-Id: 13822882 X-Patchwork-Delegate: kuba@kernel.org Received: from mail-yb1-f201.google.com (mail-yb1-f201.google.com [209.85.219.201]) (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 8458E1D8A0C for ; Fri, 4 Oct 2024 19:16:51 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.219.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1728069413; cv=none; b=oGpSJT0sIZ+abEDyf+upnabdwQHESWV6dK0VO2tlF96+dVfxc0/76mo16iX8A/sQMM1qFWXQOTSR+WTJt8dkjz6C1ibFPXLAEyZAUE7Ftfm0HQ3ER9D0OgRVii8K/U5dNAzp8Rqb9q9k0xj5e06G1C7m8MSCGdZrKR99Uqdd0Ss= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1728069413; c=relaxed/simple; bh=N4M61e3JYLkPo6uIbpUbLgwLHGmqhlnd0TWTpFQokCw=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=k2EK9nV5lUTxgkjwECFwB0sIjsjolvEcyOoNZyVXY23Bgyn1j/W2RM1BWtZuAWJz5yivqBYqTaVoDlOWupvhs+aX6+z/q1DasTr3pZDEjoNCYRq+CyF3VmZDeWGT7dADSx4MLTmOn3VF0fdp6suqdELcJAusjbJJEdu+1NYla0A= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--edumazet.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=CLG9Sa3J; arc=none smtp.client-ip=209.85.219.201 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--edumazet.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="CLG9Sa3J" Received: by mail-yb1-f201.google.com with SMTP id 3f1490d57ef6-e25cc76cae1so4155094276.0 for ; Fri, 04 Oct 2024 12:16:51 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1728069410; x=1728674210; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=X02LKrEzBetALa4655biF39hq5nD0knlWwI7YeSXzOg=; b=CLG9Sa3JM7Oqh70IFJMPyGK68na7G6T+HbSE6HkrFKBiRomZHutXj5YwTNDOW9UXzp xm4p04Se5q5dG8w3foDXIvkY/pklWzodGL0IzMfJBfSq4Eg7OIong34fwP9nBJ2GkIm5 BYPZ3VtZ20sExmetbUxmO2xZh5zm3X2eRbx9aZD1jUfqAlsMiGfvZlVuFWbC5EcDTkXH iwu0c6MYlt+3MZCj4ACDbT0/z4yGoPla0ae7x6PfuFYNqWqmcq2hPmgHuc4aXuOqonji Zv8YRdDU++PWCSKW0bxEK/hjU8YOdvpXlh311cRsV/a1pctiZmnY/IhqPeGUZErcOay2 LTwA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1728069410; x=1728674210; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=X02LKrEzBetALa4655biF39hq5nD0knlWwI7YeSXzOg=; b=OvsbNBNKep3rzgU80NKOfFRDi8gSE7tbWf09G025jtTYRN0qtVzc76vPnmWfHhdL1f 0VJrjCmfMYBelC3h9ktuvfPkDt+6rLIUBzsR9fYYUKmmOkrYrSXc0CVHF8fUrdo1rIIJ 17bOgsEfDdqP5WO9chdfgnASomsh6ejPznnmAjmWxr6EEso6hKeS1HyUqL2jJnfuU3XY Wg6xvRL1GYrYLMIccdj6YDV4ZiJ8F2kXisIK6fWELB1YxpPfcx2WW6H+jdMUItYxGnvu fiq4Qp7xL9j3EHDQc7Y7TjxQGE2vYRjaZLnZv4PTMMDNJRwbR2S0H5+F3zaX9N7xFFhp HX8g== X-Gm-Message-State: AOJu0Yzcr+aBKonRRMpecBk89IEyyj/ti+k8er4WZ+VcvmIPDWxb7KlJ Wa5ZsjGNMKrmzEJsW4vNLAXgf4ExfMNzcmlPFPcCUE1zNA2t/iVF3NgfZL5PPZDlZEYgXHYXT/x AyFbmPE+yag== X-Google-Smtp-Source: AGHT+IFLrYh0eYD+e++ldgxfoKeFKOxDenCp5VtUXqKee7SXLWEHIkR6D3DYQvj6Opt7ErgePEsPJvDqZNQX5g== X-Received: from edumazet1.c.googlers.com ([fda3:e722:ac3:cc00:f7:ea0b:ac12:11d6]) (user=edumazet job=sendgmr) by 2002:a25:b293:0:b0:e28:6ae8:9af1 with SMTP id 3f1490d57ef6-e28930742b8mr41547276.3.1728069410549; Fri, 04 Oct 2024 12:16:50 -0700 (PDT) Date: Fri, 4 Oct 2024 19:16:41 +0000 In-Reply-To: <20241004191644.1687638-1-edumazet@google.com> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20241004191644.1687638-1-edumazet@google.com> X-Mailer: git-send-email 2.47.0.rc0.187.ge670bccf7e-goog Message-ID: <20241004191644.1687638-3-edumazet@google.com> Subject: [PATCH net-next 2/5] net_sched: sch_fq: prepare for TIME_WAIT sockets From: Eric Dumazet To: "David S . Miller" , Jakub Kicinski , Paolo Abeni , Martin KaFai Lau Cc: netdev@vger.kernel.org, eric.dumazet@gmail.com, Eric Dumazet X-Patchwork-Delegate: kuba@kernel.org TCP stack is not attaching skb to TIME_WAIT sockets yet, but we would like to allow this in the future. Add sk_listener_or_tw() helper to detect the three states that FQ needs to take care. Like NEW_SYN_RECV, TIME_WAIT are not full sockets and do not contain sk->sk_pacing_status, sk->sk_pacing_rate. Signed-off-by: Eric Dumazet --- include/net/sock.h | 10 ++++++++++ net/sched/sch_fq.c | 3 ++- 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/include/net/sock.h b/include/net/sock.h index c58ca8dd561b7312ffc0836585c04d9fe917a124..c868b8b57e3489cd81efafa3856da09397059080 100644 --- a/include/net/sock.h +++ b/include/net/sock.h @@ -2784,6 +2784,16 @@ static inline bool sk_listener(const struct sock *sk) return (1 << sk->sk_state) & (TCPF_LISTEN | TCPF_NEW_SYN_RECV); } +/* This helper checks if a socket is a LISTEN or NEW_SYN_RECV or TIME_WAIT + * TCP SYNACK messages can be attached to LISTEN or NEW_SYN_RECV (depending on SYNCOOKIE) + * TCP RST and ACK can be attached to TIME_WAIT. + */ +static inline bool sk_listener_or_tw(const struct sock *sk) +{ + return (1 << READ_ONCE(sk->sk_state)) & + (TCPF_LISTEN | TCPF_NEW_SYN_RECV | TCPF_TIME_WAIT); +} + void sock_enable_timestamp(struct sock *sk, enum sock_flags flag); int sock_recv_errqueue(struct sock *sk, struct msghdr *msg, int len, int level, int type); diff --git a/net/sched/sch_fq.c b/net/sched/sch_fq.c index 19a49af5a9e527ed0371a3bb96e0113755375eac..e10e94fa5f9bc17a086173abaacb57269bc506a8 100644 --- a/net/sched/sch_fq.c +++ b/net/sched/sch_fq.c @@ -361,8 +361,9 @@ static struct fq_flow *fq_classify(struct Qdisc *sch, struct sk_buff *skb, * 3) We do not want to rate limit them (eg SYNFLOOD attack), * especially if the listener set SO_MAX_PACING_RATE * 4) We pretend they are orphaned + * TCP can also associate TIME_WAIT sockets with RST or ACK packets. */ - if (!sk || sk_listener(sk)) { + if (!sk || sk_listener_or_tw(sk)) { unsigned long hash = skb_get_hash(skb) & q->orphan_mask; /* By forcing low order bit to 1, we make sure to not From patchwork Fri Oct 4 19:16:42 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Dumazet X-Patchwork-Id: 13822883 X-Patchwork-Delegate: kuba@kernel.org Received: from mail-yw1-f201.google.com (mail-yw1-f201.google.com [209.85.128.201]) (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 38A251D89E3 for ; Fri, 4 Oct 2024 19:16:53 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1728069414; cv=none; b=FaDkAtwgYJWe6i9d69/uthGGVTzGtfxlWMT09f8/PABqRURw7jvppxgfmtzVijg174u8w2wKGvLgzMLXpyFxjgZvZH1aalErJwDxZ2yyq5t2quupQs2smvdtN0Vw80InH+eMeqLtq1OvEzz3WjVyB6fuU4i3TFZSl2B9P5F+Vuw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1728069414; c=relaxed/simple; bh=YX2xiHUcOWw6p941/qNR30xo2Wcqd7/MFQUvcn8jSd4=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=HqjUFl6bqkrS/tqFaCf8Gje35UwacQloc2NRjCbLAPWH3UF9CaqfYt2ywD64+tG5vg7pTTljcHkgI6LIqQ/iS4rASq60rXnDu0wX5uEnZq/BD+iUbjt1CsAwr93sHZ1NeAK/TAdp4Zcerbj2yqPDLmauvDnkTEWhZDjcYotJaQY= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--edumazet.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=g+HHRkIG; arc=none smtp.client-ip=209.85.128.201 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--edumazet.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="g+HHRkIG" Received: by mail-yw1-f201.google.com with SMTP id 00721157ae682-6e26ba37314so38987837b3.0 for ; Fri, 04 Oct 2024 12:16:52 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1728069412; x=1728674212; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=OL+8Wei0Hl/fpXNg0qcOSx2N31q/ONluFFFu9ekOhMI=; b=g+HHRkIGcPBDSrPf3CY8LpBBsMcsArLuNBYMHezFfMzYFwXgdXCL9VTNyKfFKQZ66L oTvZNsNPZqxnkQvAmMTN9jU/3qnjupaMIdydlhSECMdShYvdsMCnL2U9HrvytlY+GXma KWuEm32ChbVTtVTjm3Qkq6prmARNz2dtnixFq/r2GHlbye+I0xze91U3zjlemKAV8JF6 0T4v4LNCp9oPkXnkVLg4qGpR3m7Dh7E7+/VqjgnkBx1C709tyAsJCg55rgBCa9x5k3kO DPAyX1gfIPd9eMvovs7D+asz7l1Nm35kasYGwPFO1m+jr0ezoUPI7P+KWJdGhg8rph+B 6Yuw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1728069412; x=1728674212; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=OL+8Wei0Hl/fpXNg0qcOSx2N31q/ONluFFFu9ekOhMI=; b=V/1cMYKEudWxqDjs1ig+/5tPeKCVPogUTXm1AqlfSsYLlqXdrMMQccuCkKLscFXSEv 8a5BumtkyyBkvFpWWbwfaehP5gDgWYro7OXylZoADfGOfAn3S/VBoil7d9v1dWfu5Iay alh39ESm+Dgl6nQ3RpfyzN7glcivSOYgS/fLOLhowQVOJjLGIP9N/nslNnqy5/kg/VkE jxFImx//GwRmHpt/ZHz2FvDPefQaky3xk/pdTYRg2jUVUx9/jFj3MeinkVRlKT5NkRiO EoqCtkep1VWZBVyVc5dvblAKO1FrsLlqFBHuCkhoVWITKLNIU8cJTjyPQIyPb/p8tAbt QFpQ== X-Gm-Message-State: AOJu0Yzn0b3PVrn4Tzzxd9Bc/JQ+gLgutAQKDS7Ui6kCGwkZhD8LKWGR 4QgrhFXyqyMyAFgFfraRjAk5SnHcdDyj0pb4dUsrFWcOo5bYVcQCWGCvHlJ/oNfHB3EFyrwIio5 5dkdwbz0Hzg== X-Google-Smtp-Source: AGHT+IEdSoCUooVsjdRLkyXOS8ewX7pfdU2/08LEQtlAyHaD4+IC0cbXJeD4y8BBPiXqbSZyN0YnATplzITVRw== X-Received: from edumazet1.c.googlers.com ([fda3:e722:ac3:cc00:f7:ea0b:ac12:11d6]) (user=edumazet job=sendgmr) by 2002:a25:b293:0:b0:e16:67c4:5cd4 with SMTP id 3f1490d57ef6-e28936d0681mr2409276.4.1728069412044; Fri, 04 Oct 2024 12:16:52 -0700 (PDT) Date: Fri, 4 Oct 2024 19:16:42 +0000 In-Reply-To: <20241004191644.1687638-1-edumazet@google.com> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20241004191644.1687638-1-edumazet@google.com> X-Mailer: git-send-email 2.47.0.rc0.187.ge670bccf7e-goog Message-ID: <20241004191644.1687638-4-edumazet@google.com> Subject: [PATCH net-next 3/5] net: add skb_set_owner_edemux() helper From: Eric Dumazet To: "David S . Miller" , Jakub Kicinski , Paolo Abeni , Martin KaFai Lau Cc: netdev@vger.kernel.org, eric.dumazet@gmail.com, Eric Dumazet X-Patchwork-Delegate: kuba@kernel.org This can be used to attach a socket to an skb, taking a reference on sk->sk_refcnt. This helper might be a NOP if sk->sk_refcnt is zero. Use it from tcp_make_synack(). Signed-off-by: Eric Dumazet --- include/net/sock.h | 9 +++++++++ net/core/sock.c | 9 +++------ net/ipv4/tcp_output.c | 2 +- 3 files changed, 13 insertions(+), 7 deletions(-) diff --git a/include/net/sock.h b/include/net/sock.h index c868b8b57e3489cd81efafa3856da09397059080..5facbf33316ab0a424b320850198c7cd6bc1a642 100644 --- a/include/net/sock.h +++ b/include/net/sock.h @@ -1752,6 +1752,15 @@ void sock_efree(struct sk_buff *skb); #ifdef CONFIG_INET void sock_edemux(struct sk_buff *skb); void sock_pfree(struct sk_buff *skb); + +static inline void skb_set_owner_edemux(struct sk_buff *skb, struct sock *sk) +{ + skb_orphan(skb); + if (refcount_inc_not_zero(&sk->sk_refcnt)) { + skb->sk = sk; + skb->destructor = sock_edemux; + } +} #else #define sock_edemux sock_efree #endif diff --git a/net/core/sock.c b/net/core/sock.c index 039be95c40cf6fa429d33e0f42ee606188045992..0582306bb576291c43c9eb0700130b36ba44cc25 100644 --- a/net/core/sock.c +++ b/net/core/sock.c @@ -2594,14 +2594,11 @@ void __sock_wfree(struct sk_buff *skb) void skb_set_owner_w(struct sk_buff *skb, struct sock *sk) { skb_orphan(skb); - skb->sk = sk; #ifdef CONFIG_INET - if (unlikely(!sk_fullsock(sk))) { - skb->destructor = sock_edemux; - sock_hold(sk); - return; - } + if (unlikely(!sk_fullsock(sk))) + return skb_set_owner_edemux(skb, sk); #endif + skb->sk = sk; skb->destructor = sock_wfree; skb_set_hash_from_sk(skb, sk); /* diff --git a/net/ipv4/tcp_output.c b/net/ipv4/tcp_output.c index 4fd746bd4d54f621601b20c3821e71370a4a615a..60c16fa4c9007006ff8ba49b695d227652a2eafb 100644 --- a/net/ipv4/tcp_output.c +++ b/net/ipv4/tcp_output.c @@ -3731,7 +3731,7 @@ struct sk_buff *tcp_make_synack(const struct sock *sk, struct dst_entry *dst, switch (synack_type) { case TCP_SYNACK_NORMAL: - skb_set_owner_w(skb, req_to_sk(req)); + skb_set_owner_edemux(skb, req_to_sk(req)); break; case TCP_SYNACK_COOKIE: /* Under synflood, we do not attach skb to a socket, From patchwork Fri Oct 4 19:16:43 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Dumazet X-Patchwork-Id: 13822884 X-Patchwork-Delegate: kuba@kernel.org Received: from mail-yw1-f202.google.com (mail-yw1-f202.google.com [209.85.128.202]) (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 BC55E1D8A10 for ; Fri, 4 Oct 2024 19:16:54 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.202 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1728069416; cv=none; b=Xgl0euIV8qa39LOMfU8ZhpxFXnWpMKT/ZSkz8TyBAdjYpPCosaJmCpYDOXDJclwA0QJHYpBbowhocr0a/NiGtQhR8sZdNqAwLaDejFLDUshxJwCIeUGvMr9rLElR7TA2WcgDE13wdXa8rtWxgBOxx3s419lab+uEIbG4SxkHvjg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1728069416; c=relaxed/simple; bh=0rzp6qGAOYnBUXj/52siehyJKvpdFknwMUEQ4grP85g=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=Za/0oeFwMQCd1NZ5bq4UJMInJAdY0mm+IQqEhPhfEVqNSPFWIr4N6pLyiDDK2OonNLXTbY6Y7+qgrA5nqLOm2Qe3OJ+dTpzbudNRS0MkhsG+mPkMnT6hQ/wONdWJ3u3JOitDKUJaol4uOQ8VSVCtoOMJROOv/whtLilONdVMdRY= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--edumazet.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=Mx7qh+pJ; arc=none smtp.client-ip=209.85.128.202 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--edumazet.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="Mx7qh+pJ" Received: by mail-yw1-f202.google.com with SMTP id 00721157ae682-6e251ba2243so30602167b3.1 for ; Fri, 04 Oct 2024 12:16:54 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1728069414; x=1728674214; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=IGl4Ykkhxa6wsFpVpS2Ggk5e4pmo9W77Io/UbFbXN5Q=; b=Mx7qh+pJkjLY0AbGpa2ZFdPvHpTkIPC4cF1aj0T71jNj9sGjGQyK2Ug00oMUa4upgx E+mwL1KoDBsB+jK/mMHywzpzdkH3ZGYKbk/EGDrzOpw5QALwF8dtOoWXVyuBoY0W/VTk PxZSJ5GkC4igt/ULyJqkA+qSPXnJ7RSH8kN0kPpHik9mcdQPzW36OJWIFtZ27dilcG23 OGhciZSiObI6OxjPoACDvN19A0qOOVhUmq9NeqHIuz8NewlrmzAnYKFuEzqxur3oiiMB lT3iMNlj/X/eaUcITS2vybDSYq1OSoXi142o70IgwO952wq9FRvfmIedbLagnUaR4aYU 7zzw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1728069414; x=1728674214; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=IGl4Ykkhxa6wsFpVpS2Ggk5e4pmo9W77Io/UbFbXN5Q=; b=dKgbgAb33eAxmX69hk44FoBqag6Z2Cc3YxvwwHNYnJi/SstriIujFjONvS84uiyMvO TF/49D4aIRieDKGVXVrdVzMhwNV/JLdtDMpD74ESwjFeo7kHLbT7wAjdjm0C3LyAOWAP UJogfnMQdiGrzs2sPP9Coq+C8wFi71c/e10UvsIkMhY+8iDaYZDJBh/WWY2B75GdfeCN fsAlbNfVq4VSBOavr0YAMfu9Htr70LV1Y3u1DZDXFCiAcVxjKzvnYU0F2o+wrjCEXnxi vEFOOYES/92xjwJ0l6w3E/3aDusYPtFDVi1EC2TRAtL+x39txsWdA+U3qzdZh+5fgfs0 bU2A== X-Gm-Message-State: AOJu0YzKXObajkr9zBck2KIfq5j5VUmHQPDP/RqJqnQmJMm+azjRHu7z rcJPE6yAmMhGibtC7Z5YlKpuMeeIdJ1pPOCYuIMjHND+KFW5S2UPxVZ+cb/OT3Dg5lHG4iH/WgC I77bACNdScg== X-Google-Smtp-Source: AGHT+IFYzTM6qsBwAhyEqWyqdXHRPaFUxH4rSS2aQUAFSc4GroIJ35gOs1Og3JCR+73Hk6pjlvdC2lkiLlK/9w== X-Received: from edumazet1.c.googlers.com ([fda3:e722:ac3:cc00:f7:ea0b:ac12:11d6]) (user=edumazet job=sendgmr) by 2002:a05:690c:95b:b0:68e:8de6:617c with SMTP id 00721157ae682-6e2c7cd7ee0mr815847b3.5.1728069413766; Fri, 04 Oct 2024 12:16:53 -0700 (PDT) Date: Fri, 4 Oct 2024 19:16:43 +0000 In-Reply-To: <20241004191644.1687638-1-edumazet@google.com> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20241004191644.1687638-1-edumazet@google.com> X-Mailer: git-send-email 2.47.0.rc0.187.ge670bccf7e-goog Message-ID: <20241004191644.1687638-5-edumazet@google.com> Subject: [PATCH net-next 4/5] ipv6: tcp: give socket pointer to control skbs From: Eric Dumazet To: "David S . Miller" , Jakub Kicinski , Paolo Abeni , Martin KaFai Lau Cc: netdev@vger.kernel.org, eric.dumazet@gmail.com, Eric Dumazet X-Patchwork-Delegate: kuba@kernel.org tcp_v6_send_response() send orphaned 'control packets'. These are RST packets and also ACK packets sent from TIME_WAIT. Some eBPF programs would prefer to have a meaningful skb->sk pointer as much as possible. This means that TCP can now attach TIME_WAIT sockets to outgoing skbs. Signed-off-by: Eric Dumazet --- net/ipv6/tcp_ipv6.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/net/ipv6/tcp_ipv6.c b/net/ipv6/tcp_ipv6.c index d71ab4e1efe1c6598cf3d3e4334adf0881064ce9..9a15adb8dbcc1e518d43e4e9b563b5bb29ef9430 100644 --- a/net/ipv6/tcp_ipv6.c +++ b/net/ipv6/tcp_ipv6.c @@ -967,6 +967,9 @@ static void tcp_v6_send_response(const struct sock *sk, struct sk_buff *skb, u32 } if (sk) { + /* unconstify the socket only to attach it to buff with care. */ + skb_set_owner_edemux(buff, (struct sock *)sk); + if (sk->sk_state == TCP_TIME_WAIT) mark = inet_twsk(sk)->tw_mark; else From patchwork Fri Oct 4 19:16:44 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Dumazet X-Patchwork-Id: 13822885 X-Patchwork-Delegate: kuba@kernel.org Received: from mail-yw1-f202.google.com (mail-yw1-f202.google.com [209.85.128.202]) (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 DF07F1ADFEB for ; Fri, 4 Oct 2024 19:16:56 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.202 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1728069418; cv=none; b=gPiX8gNk2fWmyUjQrv/W/uked7nxXb2UCRKZi69wKIYVHYi0XBPX8lLG0SM5vx9UIErwlwdeNbyH7Cd24fzKY1ce7i3oJDM5IBkmRHyoOx/HJeBLYksckgHb/auQaPLO0nNDuK2kjFheEMWOzGtZJikT5Qia2R0so6YwAyaY5ys= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1728069418; c=relaxed/simple; bh=oyBhtjfCS4KUO8+N6jIQpgzbsKWLdqbQvXOYfY2XtsU=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=W/hMHddK/Y3FcUlwL+ZFUcnLebP987ud2RPUJEAI9iCyBBwrlgbGbDm0d9H9e1TtRRPRmbOu65JXtquahAdO4gyW0gSgFLi3IR53RKNyXmFSz4TyI+mISd5BV+RsQN5dMLUPdr/Kk6ZTZoddAcIhyS3GMd/5Im8xUkUD4iFMstk= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--edumazet.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=nZo/I/6W; arc=none smtp.client-ip=209.85.128.202 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--edumazet.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="nZo/I/6W" Received: by mail-yw1-f202.google.com with SMTP id 00721157ae682-6e22f0be237so48482667b3.1 for ; Fri, 04 Oct 2024 12:16:56 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1728069416; x=1728674216; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=WQY54G0TzTKd8OAMtVgvMSskixlx2R2Qlae++KVsEb0=; b=nZo/I/6WVZJc1CAHrWa5OW6mFvYS5/Ggk5RZlrOEHXmyGjOJSJMHGOQ2/4N2A0KRwy HRLY4iI9452gWMxZAU4k5MHxaBmhqRydLXIjEa31GhnfMzxe8d2n/vehoKVY5RoOBbEy nMEvUa4rM5KqZnIsBkjdEZ7ozcjsSfdSFlprDu3V9iOxAlnBCS8tCGfvYaoyVvnSVDbj wPuZMB9y+YoishEqvtziF/1YsQMbjfORQLjIZIrmA64BEtjfrWoWeNiCM1KqHIwnqzWx sTrmJlwZmPZpM2ASJ/iajTN9tAedsakYB2TLfOJCLGFCRDqCW2sbldRLPncbGixRkTPT fq2w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1728069416; x=1728674216; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=WQY54G0TzTKd8OAMtVgvMSskixlx2R2Qlae++KVsEb0=; b=Pap41VMmqWCxHbGG1vsad+Oc5J0TGdwLl8o+kYW+OLJL7gdgPWJhAioiwnmprAm6jJ QEM0nYhbN5mjKLQCEh1Zx0a3Y0IEeHT7spZOS6N/Od+LSNnoXPUjkGgdBhl/KtBpnh9V G1+Y54Pgl7fBJi7CTXVUVnfNDR0IOW1U6Vmjs4ctY5qf+Qr9isiNzMQ8JLS7eBarvpj1 F4TB6zBZylDr20sbpPkpnpGyBEHMDWJbRlJOJqUQ0pk9t4XQocfX98gEixFSBic4NZvQ fLxvAvRA/mHn01XK7cBiVLuu2+f+DQuQU4wY5HpwP4i27hw5tO7iTLVeXtcFK6hzzXoi 6cVg== X-Gm-Message-State: AOJu0YzX5UnOlfAvAjvPRcnmCBd2+69x1oehaMZCc4tLks3zuMXxIK/Q QYLr0me9RxCBH9TCJ4y0oJSfZzoyfzvrnDxnIY0YzzhzUOrQ8a5GWESA+pAG/EYM+rg/74Kx62m AcTEHKrSxrA== X-Google-Smtp-Source: AGHT+IHHkzkSi4zGZMJxVSWNTbopSJRZBtvXHIGN9zQ1umntorxUGy6BxKHw7vmyQE+EZZ+IkfqWqlW/OYd7pw== X-Received: from edumazet1.c.googlers.com ([fda3:e722:ac3:cc00:f7:ea0b:ac12:11d6]) (user=edumazet job=sendgmr) by 2002:a05:6902:b1c:b0:e25:5cb1:77d8 with SMTP id 3f1490d57ef6-e289391fba7mr2475276.6.1728069415606; Fri, 04 Oct 2024 12:16:55 -0700 (PDT) Date: Fri, 4 Oct 2024 19:16:44 +0000 In-Reply-To: <20241004191644.1687638-1-edumazet@google.com> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20241004191644.1687638-1-edumazet@google.com> X-Mailer: git-send-email 2.47.0.rc0.187.ge670bccf7e-goog Message-ID: <20241004191644.1687638-6-edumazet@google.com> Subject: [PATCH net-next 5/5] ipv4: tcp: give socket pointer to control skbs From: Eric Dumazet To: "David S . Miller" , Jakub Kicinski , Paolo Abeni , Martin KaFai Lau Cc: netdev@vger.kernel.org, eric.dumazet@gmail.com, Eric Dumazet X-Patchwork-Delegate: kuba@kernel.org ip_send_unicast_reply() send orphaned 'control packets'. These are RST packets and also ACK packets sent from TIME_WAIT. Some eBPF programs would prefer to have a meaningful skb->sk pointer as much as possible. This means that TCP can now attach TIME_WAIT sockets to outgoing skbs. Signed-off-by: Eric Dumazet --- include/net/ip.h | 3 ++- net/ipv4/ip_output.c | 5 ++++- net/ipv4/tcp_ipv4.c | 4 ++-- 3 files changed, 8 insertions(+), 4 deletions(-) diff --git a/include/net/ip.h b/include/net/ip.h index bab084df15677543b7400bb2832c0e83988884cb..4be0a6a603b2b5d5cfddc045a7d49d0d77be9570 100644 --- a/include/net/ip.h +++ b/include/net/ip.h @@ -288,7 +288,8 @@ static inline __u8 ip_reply_arg_flowi_flags(const struct ip_reply_arg *arg) return (arg->flags & IP_REPLY_ARG_NOSRCCHECK) ? FLOWI_FLAG_ANYSRC : 0; } -void ip_send_unicast_reply(struct sock *sk, struct sk_buff *skb, +void ip_send_unicast_reply(struct sock *sk, const struct sock *orig_sk, + struct sk_buff *skb, const struct ip_options *sopt, __be32 daddr, __be32 saddr, const struct ip_reply_arg *arg, diff --git a/net/ipv4/ip_output.c b/net/ipv4/ip_output.c index 49811c9281d424bc4b43b8e9075da9fe724773cb..7d42be9e614d343cb9e4e25238c50a715a6f8ce2 100644 --- a/net/ipv4/ip_output.c +++ b/net/ipv4/ip_output.c @@ -1587,7 +1587,8 @@ static int ip_reply_glue_bits(void *dptr, char *to, int offset, * Generic function to send a packet as reply to another packet. * Used to send some TCP resets/acks so far. */ -void ip_send_unicast_reply(struct sock *sk, struct sk_buff *skb, +void ip_send_unicast_reply(struct sock *sk, const struct sock *orig_sk, + struct sk_buff *skb, const struct ip_options *sopt, __be32 daddr, __be32 saddr, const struct ip_reply_arg *arg, @@ -1653,6 +1654,8 @@ void ip_send_unicast_reply(struct sock *sk, struct sk_buff *skb, arg->csumoffset) = csum_fold(csum_add(nskb->csum, arg->csum)); nskb->ip_summed = CHECKSUM_NONE; + if (orig_sk) + skb_set_owner_edemux(nskb, (struct sock *)orig_sk); if (transmit_time) nskb->tstamp_type = SKB_CLOCK_MONOTONIC; if (txhash) diff --git a/net/ipv4/tcp_ipv4.c b/net/ipv4/tcp_ipv4.c index 5afe5e57c89b5c28dfada2bf2e01fa7b3afa61f0..8260aa9440f9e1e6fb50b4c01854acaccbbdec17 100644 --- a/net/ipv4/tcp_ipv4.c +++ b/net/ipv4/tcp_ipv4.c @@ -907,7 +907,7 @@ static void tcp_v4_send_reset(const struct sock *sk, struct sk_buff *skb, ctl_sk->sk_mark = 0; ctl_sk->sk_priority = 0; } - ip_send_unicast_reply(ctl_sk, + ip_send_unicast_reply(ctl_sk, sk, skb, &TCP_SKB_CB(skb)->header.h4.opt, ip_hdr(skb)->saddr, ip_hdr(skb)->daddr, &arg, arg.iov[0].iov_len, @@ -1021,7 +1021,7 @@ static void tcp_v4_send_ack(const struct sock *sk, ctl_sk->sk_priority = (sk->sk_state == TCP_TIME_WAIT) ? inet_twsk(sk)->tw_priority : READ_ONCE(sk->sk_priority); transmit_time = tcp_transmit_time(sk); - ip_send_unicast_reply(ctl_sk, + ip_send_unicast_reply(ctl_sk, sk, skb, &TCP_SKB_CB(skb)->header.h4.opt, ip_hdr(skb)->saddr, ip_hdr(skb)->daddr, &arg, arg.iov[0].iov_len,