From patchwork Thu May 9 04:43:22 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yuan Fang X-Patchwork-Id: 13659420 X-Patchwork-Delegate: kuba@kernel.org Received: from mail-pl1-f169.google.com (mail-pl1-f169.google.com [209.85.214.169]) (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 239CE10E5; Thu, 9 May 2024 04:43:30 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.169 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715229813; cv=none; b=NQhCgSAWxjrPoQ1kckrfusIB5llQWjDDsQ+6AdyqHLmBypiwwZlhjT7pkO17w9WIdMuZukuOAJt5Nefj8lm6M8nkEwI4do9JhXE6tDsJwJoGNcbqdUcix4SADLmhi3o9nYEDzXsPHSixjjvs6Of7Fg2rzpS4ZHnz/9XcYJ8MZeg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715229813; c=relaxed/simple; bh=0APn/GyB9C3LGDrLfnj/FpbTqKbd0+K519YfKo41k2I=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=A1CpODbr2bzgCi+ZB4Lght4Av8BijBRXO/UCWgaZDqrC0rJW+Ii4EwzGlDvNQ0NNnlbqqyhbGPHitmNrD7mfpA35mUaWwKxxL1LMqL8lYXMP3Ro0GKhArEYm2QUz3iFY2iXMV+aAo+uLIitr/tGlSc+yss3sigsxHQNYjJA5ze0= 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=kiLoH4iD; arc=none smtp.client-ip=209.85.214.169 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="kiLoH4iD" Received: by mail-pl1-f169.google.com with SMTP id d9443c01a7336-1ed96772f92so3633815ad.0; Wed, 08 May 2024 21:43:30 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1715229810; x=1715834610; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=pVSe9gUHjI1t4fahoHDRMA+6pIokvYwYsfwP/32CnUk=; b=kiLoH4iDV7Pga/RjT/ze4teJiXf5gIpPqa2RJBqqf5mdJRDoQFp91kyojmOa/7ByY7 iLF1yI8MC8zKiMCbn8hH8agtBuO8QggRL1i1gA79dEuI2zDMfXw2jgal7CchUqXnh8N6 tWM1FIX0I+yV6bX3Yhvuw945dGVx4THCNgvJziGGaEr9Ve+AkmX5yUenwxfgAmLqmiBc i6UUcgSBy3sRluuQjAzEm2muamXPErQHdGFC1A+xYgbXUK/sY47Es41tEONkHU3hp2z8 BcC9LKOdK1X7Vs9CqL3n17esdUOZRJ9miL8P6j/xl/5vStDa3Y64H9B052TWmtNLafEo DOrw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1715229810; x=1715834610; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=pVSe9gUHjI1t4fahoHDRMA+6pIokvYwYsfwP/32CnUk=; b=XOZmBOdZW4/TlKXYJBbjirh89iTkjiGjgtJmh16NQkXRy8m21GIShW5nVOt9/ID/U+ vPSuQS/tqJLJCRGLzmcRU0F81FIndAC5vqIlK9+zuf5TBXh+cRCUadsxJpivTGrXKPpu AtTegTMlDLc2F5bCRu37r3k9qFuJITjTr3jUa3N2W9a5JoTYtpCOn3gLsrbF3ge2/75Z HokabYsEph/nnDzVkawLMN9fRtgtURrkm+m5CwV42lVdFjZTxk8uDUjWKuCjAyUB7iYN Vfu0Kf0AXs4cf8B3Tli2E/xuSdLA559bewFZOvnvHirITLg/aGAnPWZzdaSv5fyUzmxz Ij0w== X-Forwarded-Encrypted: i=1; AJvYcCWMoFCrOn5vYA5zJhaYDNhHfHVpWYN1ETrKUl/ERXgoQYn3Jy+Ry+07RlDrBc3nRATQZ42kxwgtlpZox2jNKKwRs/EKXyJ/E/NNRheP209P7v3gb3Qe3YZnuWClnswZCDkPmQZh X-Gm-Message-State: AOJu0YwJpRxeAeq8UyYp37nDoHGWdn4Qcp3x9G2bfI7yYRvlmkyggU/a jpVUj8MxUAIu1345RQC04Q/TGLJui97LMol2aYa7f24yXheNdVUxqOwSSfs+C2Y= X-Google-Smtp-Source: AGHT+IHNdDrS9k9IuPXnckeeqensFTS1LNXyuNEjN/yggcXbLkUhtE/ySxtJjrqcoC9bCQ/OSUPquw== X-Received: by 2002:a17:902:f64d:b0:1e2:a162:6f7a with SMTP id d9443c01a7336-1eeb05a17acmr54663635ad.43.1715229810355; Wed, 08 May 2024 21:43:30 -0700 (PDT) Received: from localhost ([117.32.216.71]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-1ef0b9d4613sm4264665ad.44.2024.05.08.21.43.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 08 May 2024 21:43:30 -0700 (PDT) From: Yuan Fang To: edumazet@google.com Cc: davem@davemloft.net, netdev@vger.kernel.org, linux-kernel@vger.kernel.org, Yuan Fang Subject: [PATCH 1/2] tcp: fix get_tcp4_sock() output error info Date: Thu, 9 May 2024 12:43:22 +0800 Message-ID: <20240509044323.247606-1-yf768672249@gmail.com> X-Mailer: git-send-email 2.45.0 Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Patchwork-Delegate: kuba@kernel.org When in the TCP_LISTEN state, using netstat,the Send-Q is always 0. Modify tx_queue to the value of sk->sk_max_ack_backlog. Signed-off-by: Yuan Fang Tested-by: Mohith Kumar Thummaluru Signed-off-by: Yuan Fang --- net/ipv4/tcp_ipv4.c | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/net/ipv4/tcp_ipv4.c b/net/ipv4/tcp_ipv4.c index a22ee5838751..70416ba902b9 100644 --- a/net/ipv4/tcp_ipv4.c +++ b/net/ipv4/tcp_ipv4.c @@ -2867,7 +2867,7 @@ static void get_tcp4_sock(struct sock *sk, struct seq_file *f, int i) __be32 src = inet->inet_rcv_saddr; __u16 destp = ntohs(inet->inet_dport); __u16 srcp = ntohs(inet->inet_sport); - int rx_queue; + int rx_queue, tx_queue; int state; if (icsk->icsk_pending == ICSK_TIME_RETRANS || @@ -2887,19 +2887,22 @@ static void get_tcp4_sock(struct sock *sk, struct seq_file *f, int i) } state = inet_sk_state_load(sk); - if (state == TCP_LISTEN) + if (state == TCP_LISTEN) { rx_queue = READ_ONCE(sk->sk_ack_backlog); - else + tx_queue = READ_ONCE(sk->sk_max_ack_backlog); + } else { /* Because we don't lock the socket, * we might find a transient negative value. */ rx_queue = max_t(int, READ_ONCE(tp->rcv_nxt) - READ_ONCE(tp->copied_seq), 0); + tx_queue = READ_ONCE(tp->write_seq) - tp->snd_una; + } seq_printf(f, "%4d: %08X:%04X %08X:%04X %02X %08X:%08X %02X:%08lX " "%08X %5u %8d %lu %d %pK %lu %lu %u %u %d", i, src, srcp, dest, destp, state, - READ_ONCE(tp->write_seq) - tp->snd_una, + tx_queue, rx_queue, timer_active, jiffies_delta_to_clock_t(timer_expires - jiffies), From patchwork Thu May 9 04:43:23 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yuan Fang X-Patchwork-Id: 13659421 X-Patchwork-Delegate: kuba@kernel.org Received: from mail-pl1-f181.google.com (mail-pl1-f181.google.com [209.85.214.181]) (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 A9D1C10E5; Thu, 9 May 2024 04:43:37 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.181 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715229819; cv=none; b=mr8+sczOCrdXBCqdpWieRUwEB95foMZLTkRxpHQc+Ar0ZzItkSf37AeGmjsGs2WfmdxC1Ek1U9W6xbDpz9A1+Uj1nbajCsGfXT9gFe5Cvmpm4DCgeRRQib0ZjgsB0s/HzCKFBJehs+mIiRGVhAU/5PFXkyPFI9n+UFK+eVdrfIw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715229819; c=relaxed/simple; bh=wC8ROQGMCBiyRkgcqeR1VWvYtgaUZqSR/VXIfZ3SVZI=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=cVyASkgKg3CuCCQLdjzS81lErW2Ui49JPMerZ0f2FLHZIVxOqzZ+eoh9SERVWj7x/uNVOVz+sxTmOsAmx4TEmYK5ckGJ8Vrv7dRkvUuF5zZkRaAHvuK7lxDtluJ6vefwxQ2e1CCD4+rq2KZa/pPmwgvsup+8b35pLF2m3YRC2AM= 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=U/oM8gK5; arc=none smtp.client-ip=209.85.214.181 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="U/oM8gK5" Received: by mail-pl1-f181.google.com with SMTP id d9443c01a7336-1edf506b216so3070335ad.2; Wed, 08 May 2024 21:43:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1715229817; x=1715834617; 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=RAVsowuKL8PpxwI/qtET9GJ7xFpj2lJ5HF1nhUYlHaY=; b=U/oM8gK5HkUr96YdtUNs6WL4FTDYAFE8HDYcnCDLQzfviPNKKoRra5OdW6uyCxXWQM pFstItpRfyI7mg4ERkHEXEZioVPDq4oj/HmvazZOYnZd+M9gzpnf9ReDhvvqYgG1b79P M9C0sa//IoZtID69f27ixbq7aCQ+pKlQXJwqineSaeP20rB0ypXW6wB0jCJVnJmxrsaC TBJ63lgtBvi0gtL+qtsXC51q7KtOI/VTRfQelAtZ3SWHzG5N2yImILb+UxJfsVKf7cE7 K4yluMWxLkhb0i7XYcfgPXcmy7mVHkHLi0Bh/BJeRGm3UmJTLhn04ETAyTiNxr/1Ht0G 0+mA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1715229817; x=1715834617; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=RAVsowuKL8PpxwI/qtET9GJ7xFpj2lJ5HF1nhUYlHaY=; b=KtHs+qHgcclHntvGAhbckfsRfGNfeK7maL9CgjP06pmS9XBaH/0Qoj7ZVmvEaUdQyC 6bO7GfR6l9t6qph4Hf8uI3lzs8M8nS2nQ9a+BsQSBtyeYBNoRfuaTQh6frxcsfLXHYhY 1VuMZLLYKjgYRfB2mUxXHb+XdbJcw09FfNLFi978DZMlR4HwzZzF0sD7q06jGZAn3Uug oGNKhZVH3bgfB/abqCYoEYoaaiKSe+4weHzIy8XD1bNMT6WcBU230iwxfdPVhVMlu/Ix aqmUB0DU2eaiDnrvYooSFUAmbutvWHzmCkzieRFpTDz75R913GNteHIWCgWwCyEsY7+W jgRA== X-Forwarded-Encrypted: i=1; AJvYcCWEW/T5T6eSBk3jHdA0cBiaa25xVUAT/iP958atK4vT9yHq9xy3qo7kA1eZZFGl4/zUDa/wPoZyIj8pIR63jKfTt7Sjt9arAQ5MnLYiAaz299i0EByYDoOXH55Nj88TyxmI9Hpg X-Gm-Message-State: AOJu0Ywi+/zyNezi8/XdOE5OpnkAY8PG17colc5ov27eRC0lWcMWnmGC 8UnkHCiMKpEIFOREzunJcF83OxAdu3s8chPockDuYeKUflq2gHpP X-Google-Smtp-Source: AGHT+IHjG84ykjAvUA3ORCTHT7UNqgZtDs11HRYoPIcMLVKsLvcqOsgyCDbW78ExK3X0UkfTlpXPcQ== X-Received: by 2002:a17:902:edc5:b0:1e4:60d4:916b with SMTP id d9443c01a7336-1eeb0aa49acmr38936125ad.64.1715229816966; Wed, 08 May 2024 21:43:36 -0700 (PDT) Received: from localhost ([117.32.216.71]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-1ef0c13699dsm4066405ad.239.2024.05.08.21.43.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 08 May 2024 21:43:36 -0700 (PDT) From: Yuan Fang To: edumazet@google.com Cc: davem@davemloft.net, netdev@vger.kernel.org, linux-kernel@vger.kernel.org, Yuan Fang Subject: [PATCH 2/2] tcp/ipv6: fix get_tcp6_sock() output error info Date: Thu, 9 May 2024 12:43:23 +0800 Message-ID: <20240509044323.247606-2-yf768672249@gmail.com> X-Mailer: git-send-email 2.45.0 In-Reply-To: <20240509044323.247606-1-yf768672249@gmail.com> References: <20240509044323.247606-1-yf768672249@gmail.com> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Patchwork-Delegate: kuba@kernel.org Using the netstat command, the Send-Q is always 0 in TCP_LISTEN. Modify tx_queue to the value of sk->sk_max_ack_backlog. Signed-off-by: Yuan Fang Signed-off-by: Yuan Fang --- net/ipv6/tcp_ipv6.c | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/net/ipv6/tcp_ipv6.c b/net/ipv6/tcp_ipv6.c index 3f4cba49e9ee..07ea1be13151 100644 --- a/net/ipv6/tcp_ipv6.c +++ b/net/ipv6/tcp_ipv6.c @@ -2177,7 +2177,7 @@ static void get_tcp6_sock(struct seq_file *seq, struct sock *sp, int i) const struct tcp_sock *tp = tcp_sk(sp); const struct inet_connection_sock *icsk = inet_csk(sp); const struct fastopen_queue *fastopenq = &icsk->icsk_accept_queue.fastopenq; - int rx_queue; + int rx_queue, tx_queue; int state; dest = &sp->sk_v6_daddr; @@ -2202,14 +2202,17 @@ static void get_tcp6_sock(struct seq_file *seq, struct sock *sp, int i) } state = inet_sk_state_load(sp); - if (state == TCP_LISTEN) + if (state == TCP_LISTEN) { rx_queue = READ_ONCE(sp->sk_ack_backlog); - else + tx_queue = READ_ONCE(sp->sk_max_ack_backlog); + } else { /* Because we don't lock the socket, * we might find a transient negative value. */ rx_queue = max_t(int, READ_ONCE(tp->rcv_nxt) - READ_ONCE(tp->copied_seq), 0); + tx_queue = READ_ONCE(tp->write_seq) - tp->snd_una; + } seq_printf(seq, "%4d: %08X%08X%08X%08X:%04X %08X%08X%08X%08X:%04X " @@ -2220,7 +2223,7 @@ static void get_tcp6_sock(struct seq_file *seq, struct sock *sp, int i) dest->s6_addr32[0], dest->s6_addr32[1], dest->s6_addr32[2], dest->s6_addr32[3], destp, state, - READ_ONCE(tp->write_seq) - tp->snd_una, + tx_queue, rx_queue, timer_active, jiffies_delta_to_clock_t(timer_expires - jiffies),