netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Eric Dumazet <edumazet@google.com>
To: "David S . Miller" <davem@davemloft.net>,
	Jakub Kicinski <kuba@kernel.org>,
	 Paolo Abeni <pabeni@redhat.com>
Cc: Martin KaFai Lau <martin.lau@kernel.org>,
	Kuniyuki Iwashima <kuniyu@amazon.com>,
	 Neal Cardwell <ncardwell@google.com>,
	Brian Vazquez <brianvv@google.com>,
	netdev@vger.kernel.org,  eric.dumazet@gmail.com,
	Eric Dumazet <edumazet@google.com>
Subject: [PATCH v3 net-next 2/5] net_sched: sch_fq: prepare for TIME_WAIT sockets
Date: Thu, 10 Oct 2024 17:48:14 +0000	[thread overview]
Message-ID: <20241010174817.1543642-3-edumazet@google.com> (raw)
In-Reply-To: <20241010174817.1543642-1-edumazet@google.com>

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 <edumazet@google.com>
---
 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 b32f1424ecc52e4a299a207c029192475c1b6a65..703ec6aef927337f7ca6798ff3c3970529af53f9 100644
--- a/include/net/sock.h
+++ b/include/net/sock.h
@@ -2800,6 +2800,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 aeabf45c9200c4aea75fb6c63986e37eddfea5f9..a97638bef6da5be8a84cc572bf2372551f4b7f96 100644
--- a/net/sched/sch_fq.c
+++ b/net/sched/sch_fq.c
@@ -362,8 +362,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
-- 
2.47.0.rc1.288.g06298d1525-goog


  parent reply	other threads:[~2024-10-10 17:48 UTC|newest]

Thread overview: 24+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-10-10 17:48 [PATCH v3 net-next 0/5] tcp: add skb->sk to more control packets Eric Dumazet
2024-10-10 17:48 ` [PATCH v3 net-next 1/5] net: add TIME_WAIT logic to sk_to_full_sk() Eric Dumazet
2024-10-11 23:20   ` Kuniyuki Iwashima
2024-10-12  3:32   ` Martin KaFai Lau
2024-10-14 14:01   ` Brian Vazquez
2024-10-14 14:27     ` Eric Dumazet
2024-10-14 15:08       ` Brian Vazquez
     [not found]       ` <CAMzD94TytK5RfDvLKXfxR7nys=voptywE3_3zSFymXNCky0AsQ@mail.gmail.com>
2024-10-14 15:23         ` Eric Dumazet
2024-10-14 15:39           ` Brian Vazquez
2024-10-10 17:48 ` Eric Dumazet [this message]
2024-10-11 23:25   ` [PATCH v3 net-next 2/5] net_sched: sch_fq: prepare for TIME_WAIT sockets Kuniyuki Iwashima
2024-10-14 14:05   ` Brian Vazquez
2024-10-10 17:48 ` [PATCH v3 net-next 3/5] net: add skb_set_owner_edemux() helper Eric Dumazet
2024-10-11 23:29   ` Kuniyuki Iwashima
2024-10-14 14:20   ` Brian Vazquez
2024-10-14 14:23     ` Eric Dumazet
2024-10-14 14:34       ` Brian Vazquez
2024-10-10 17:48 ` [PATCH v3 net-next 4/5] ipv6: tcp: give socket pointer to control skbs Eric Dumazet
2024-10-11 23:32   ` Kuniyuki Iwashima
2024-10-14 14:22   ` Brian Vazquez
2024-10-10 17:48 ` [PATCH v3 net-next 5/5] ipv4: " Eric Dumazet
2024-10-11 23:41   ` Kuniyuki Iwashima
2024-10-14 14:23   ` Brian Vazquez
2024-10-15  1:00 ` [PATCH v3 net-next 0/5] tcp: add skb->sk to more control packets patchwork-bot+netdevbpf

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20241010174817.1543642-3-edumazet@google.com \
    --to=edumazet@google.com \
    --cc=brianvv@google.com \
    --cc=davem@davemloft.net \
    --cc=eric.dumazet@gmail.com \
    --cc=kuba@kernel.org \
    --cc=kuniyu@amazon.com \
    --cc=martin.lau@kernel.org \
    --cc=ncardwell@google.com \
    --cc=netdev@vger.kernel.org \
    --cc=pabeni@redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).