From: Jiayuan Chen <jiayuan.chen@linux.dev>
To: bpf@vger.kernel.org
Cc: Jiayuan Chen <jiayuan.chen@linux.dev>,
Kuniyuki Iwashima <kuniyu@google.com>,
Eric Dumazet <edumazet@google.com>,
Neal Cardwell <ncardwell@google.com>,
"David S. Miller" <davem@davemloft.net>,
Jakub Kicinski <kuba@kernel.org>, Paolo Abeni <pabeni@redhat.com>,
Simon Horman <horms@kernel.org>,
Alexei Starovoitov <ast@kernel.org>,
Daniel Borkmann <daniel@iogearbox.net>,
Andrii Nakryiko <andrii@kernel.org>,
Martin KaFai Lau <martin.lau@linux.dev>,
Eduard Zingerman <eddyz87@gmail.com>,
Kumar Kartikeya Dwivedi <memxor@gmail.com>,
Song Liu <song@kernel.org>,
Yonghong Song <yonghong.song@linux.dev>,
Jiri Olsa <jolsa@kernel.org>, Shuah Khan <shuah@kernel.org>,
netdev@vger.kernel.org, linux-kernel@vger.kernel.org,
linux-kselftest@vger.kernel.org
Subject: [PATCH bpf-next v4 2/2] selftests/bpf: verify syncookie statistics in tcp_custom_syncookie
Date: Thu, 14 May 2026 13:09:58 +0800 [thread overview]
Message-ID: <20260514051015.177926-3-jiayuan.chen@linux.dev> (raw)
In-Reply-To: <20260514051015.177926-1-jiayuan.chen@linux.dev>
Add read_tcpext_snmp() helper to network_helpers which reads a
TcpExt SNMP counter via nstat, and use it in the tcp_custom_syncookie
test to verify that LINUX_MIB_SYNCOOKIESRECV is incremented and
LINUX_MIB_SYNCOOKIESFAILED stays unchanged across a successful
BPF custom syncookie validation.
The delta is captured between start_server() and accept(), which
covers the full SYN/ACK/cookie-check path for one connection.
Signed-off-by: Jiayuan Chen <jiayuan.chen@linux.dev>
Reviewed-by: Kuniyuki Iwashima <kuniyu@google.com>
---
tools/testing/selftests/bpf/network_helpers.c | 22 +++++++++++++++++++
tools/testing/selftests/bpf/network_helpers.h | 1 +
.../bpf/prog_tests/tcp_custom_syncookie.c | 20 +++++++++++++++++
3 files changed, 43 insertions(+)
diff --git a/tools/testing/selftests/bpf/network_helpers.c b/tools/testing/selftests/bpf/network_helpers.c
index b82f572641b7d..4e3848f60261e 100644
--- a/tools/testing/selftests/bpf/network_helpers.c
+++ b/tools/testing/selftests/bpf/network_helpers.c
@@ -621,6 +621,28 @@ int get_socket_local_port(int sock_fd)
return -1;
}
+int read_tcpext_snmp(const char *name, unsigned long *val)
+{
+ char cmd[128], buf[128];
+ int ret = 0;
+ FILE *f;
+
+ snprintf(cmd, sizeof(cmd),
+ "nstat -azs TcpExt%s | awk '/TcpExt/ {print $2}'", name);
+ f = popen(cmd, "r");
+ if (!f)
+ return -errno;
+
+ if (!fgets(buf, sizeof(buf), f)) {
+ ret = ferror(f) ? -errno : -ENODATA;
+ goto out;
+ }
+ *val = strtoul(buf, NULL, 10);
+out:
+ pclose(f);
+ return ret;
+}
+
int get_hw_ring_size(char *ifname, struct ethtool_ringparam *ring_param)
{
struct ifreq ifr = {0};
diff --git a/tools/testing/selftests/bpf/network_helpers.h b/tools/testing/selftests/bpf/network_helpers.h
index 79a010c88e11c..c53cd781df6e6 100644
--- a/tools/testing/selftests/bpf/network_helpers.h
+++ b/tools/testing/selftests/bpf/network_helpers.h
@@ -84,6 +84,7 @@ int make_sockaddr(int family, const char *addr_str, __u16 port,
struct sockaddr_storage *addr, socklen_t *len);
char *ping_command(int family);
int get_socket_local_port(int sock_fd);
+int read_tcpext_snmp(const char *name, unsigned long *val);
int get_hw_ring_size(char *ifname, struct ethtool_ringparam *ring_param);
int set_hw_ring_size(char *ifname, struct ethtool_ringparam *ring_param);
diff --git a/tools/testing/selftests/bpf/prog_tests/tcp_custom_syncookie.c b/tools/testing/selftests/bpf/prog_tests/tcp_custom_syncookie.c
index eaf441dc7e79b..00d5c32674fc9 100644
--- a/tools/testing/selftests/bpf/prog_tests/tcp_custom_syncookie.c
+++ b/tools/testing/selftests/bpf/prog_tests/tcp_custom_syncookie.c
@@ -91,12 +91,21 @@ static void transfer_message(int sender, int receiver)
static void create_connection(struct test_tcp_custom_syncookie_case *test_case)
{
+ unsigned long failed_before, failed_after;
+ unsigned long recv_before, recv_after;
int server, client, child;
server = start_server(test_case->family, test_case->type, test_case->addr, 0, 0);
if (!ASSERT_NEQ(server, -1, "start_server"))
return;
+ if (!ASSERT_OK(read_tcpext_snmp("SyncookiesRecv", &recv_before),
+ "read SyncookiesRecv before"))
+ goto close_server;
+ if (!ASSERT_OK(read_tcpext_snmp("SyncookiesFailed", &failed_before),
+ "read SyncookiesFailed before"))
+ goto close_server;
+
client = connect_to_fd(server, 0);
if (!ASSERT_NEQ(client, -1, "connect_to_fd"))
goto close_server;
@@ -105,9 +114,20 @@ static void create_connection(struct test_tcp_custom_syncookie_case *test_case)
if (!ASSERT_NEQ(child, -1, "accept"))
goto close_client;
+ if (!ASSERT_OK(read_tcpext_snmp("SyncookiesRecv", &recv_after),
+ "read SyncookiesRecv after"))
+ goto close_child;
+ if (!ASSERT_OK(read_tcpext_snmp("SyncookiesFailed", &failed_after),
+ "read SyncookiesFailed after"))
+ goto close_child;
+
+ ASSERT_EQ(recv_after - recv_before, 1, "SyncookiesRecv delta");
+ ASSERT_EQ(failed_after - failed_before, 0, "SyncookiesFailed delta");
+
transfer_message(client, child);
transfer_message(child, client);
+close_child:
close(child);
close_client:
close(client);
--
2.43.0
prev parent reply other threads:[~2026-05-14 5:10 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-05-14 5:09 [PATCH bpf-next v4 0/2] bpf,net: add missing custom syncookie statistics and add selftest Jiayuan Chen
2026-05-14 5:09 ` [PATCH bpf-next v4 1/2] net: add missing syncookie statistics for BPF custom syncookies Jiayuan Chen
2026-05-14 5:09 ` Jiayuan Chen [this message]
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=20260514051015.177926-3-jiayuan.chen@linux.dev \
--to=jiayuan.chen@linux.dev \
--cc=andrii@kernel.org \
--cc=ast@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=daniel@iogearbox.net \
--cc=davem@davemloft.net \
--cc=eddyz87@gmail.com \
--cc=edumazet@google.com \
--cc=horms@kernel.org \
--cc=jolsa@kernel.org \
--cc=kuba@kernel.org \
--cc=kuniyu@google.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-kselftest@vger.kernel.org \
--cc=martin.lau@linux.dev \
--cc=memxor@gmail.com \
--cc=ncardwell@google.com \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.com \
--cc=shuah@kernel.org \
--cc=song@kernel.org \
--cc=yonghong.song@linux.dev \
/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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.