From: lwk <lwk111111@126.com>
To: davem@davemloft.net
Cc: edumazet@google.com, dsahern@kernel.org,
linux-kernel@vger.kernel.org, lwk <lwk111111@126.com>
Subject: [PATCH] net: add synsend and synrecv statistics
Date: Wed, 16 Apr 2025 15:46:26 +0800 [thread overview]
Message-ID: <1744789586-4488-1-git-send-email-lwk111111@126.com> (raw)
In some scenarios, it is necessary to know the count of syn
packages sent and syn packages received in order to assist in
troubleshooting issues.
Signed-off-by: lwk <lwk111111@126.com>
modified: include/uapi/linux/snmp.h
modified: net/ipv4/proc.c
modified: net/ipv4/tcp_input.c
modified: net/ipv4/tcp_output.c
---
include/uapi/linux/snmp.h | 2 ++
net/ipv4/proc.c | 2 ++
net/ipv4/tcp_input.c | 1 +
net/ipv4/tcp_output.c | 1 +
4 files changed, 6 insertions(+)
diff --git a/include/uapi/linux/snmp.h b/include/uapi/linux/snmp.h
index 848c778..3ebf80d 100644
--- a/include/uapi/linux/snmp.h
+++ b/include/uapi/linux/snmp.h
@@ -303,6 +303,8 @@ enum
LINUX_MIB_TCPAOKEYNOTFOUND, /* TCPAOKeyNotFound */
LINUX_MIB_TCPAOGOOD, /* TCPAOGood */
LINUX_MIB_TCPAODROPPEDICMPS, /* TCPAODroppedIcmps */
+ LINUX_MIB_TCPSYNSEND, /* TCPSynSend */
+ LINUX_MIB_TCPSYNRECV, /* TCPSynRecv */
__LINUX_MIB_MAX
};
diff --git a/net/ipv4/proc.c b/net/ipv4/proc.c
index affd21a..1fb7755 100644
--- a/net/ipv4/proc.c
+++ b/net/ipv4/proc.c
@@ -306,6 +306,8 @@ static int sockstat_seq_show(struct seq_file *seq, void *v)
SNMP_MIB_ITEM("TCPAOKeyNotFound", LINUX_MIB_TCPAOKEYNOTFOUND),
SNMP_MIB_ITEM("TCPAOGood", LINUX_MIB_TCPAOGOOD),
SNMP_MIB_ITEM("TCPAODroppedIcmps", LINUX_MIB_TCPAODROPPEDICMPS),
+ SNMP_MIB_ITEM("TCPSynSend", LINUX_MIB_TCPSYNSEND),
+ SNMP_MIB_ITEM("TCPSynRecv", LINUX_MIB_TCPSYNRECV),
SNMP_MIB_SENTINEL
};
diff --git a/net/ipv4/tcp_input.c b/net/ipv4/tcp_input.c
index 0cbf81b..a77bf35 100644
--- a/net/ipv4/tcp_input.c
+++ b/net/ipv4/tcp_input.c
@@ -6781,6 +6781,7 @@ enum skb_drop_reason
icsk->icsk_af_ops->conn_request(sk, skb);
local_bh_enable();
rcu_read_unlock();
+ NET_INC_STATS(sock_net(sk), LINUX_MIB_TCPSYNRECV);
consume_skb(skb);
return 0;
diff --git a/net/ipv4/tcp_output.c b/net/ipv4/tcp_output.c
index bc95d2a..821aa63 100644
--- a/net/ipv4/tcp_output.c
+++ b/net/ipv4/tcp_output.c
@@ -4143,6 +4143,7 @@ int tcp_connect(struct sock *sk)
tcp_connect_queue_skb(sk, buff);
tcp_ecn_send_syn(sk, buff);
tcp_rbtree_insert(&sk->tcp_rtx_queue, buff);
+ NET_INC_STATS(sock_net(sk), LINUX_MIB_TCPSYNSEND);
/* Send off SYN; include data in Fast Open. */
err = tp->fastopen_req ? tcp_send_syn_data(sk, buff) :
--
1.8.3.1
reply other threads:[~2025-04-16 8:02 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
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=1744789586-4488-1-git-send-email-lwk111111@126.com \
--to=lwk111111@126.com \
--cc=davem@davemloft.net \
--cc=dsahern@kernel.org \
--cc=edumazet@google.com \
--cc=linux-kernel@vger.kernel.org \
/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
all inboxes | Powered by JetHome®