* [PATCH 6.1 00/15] genetlink: Test Netlink subsystem of Linux v6.1
@ 2025-09-12 19:53 Yana Bashlykova
2025-09-12 19:53 ` [PATCH 6.1 10/15] selftests: net: genetlink: add packet capture test infrastructure Yana Bashlykova
2025-09-12 20:17 ` [PATCH 6.1 00/15] genetlink: Test Netlink subsystem of Linux v6.1 Jakub Kicinski
0 siblings, 2 replies; 5+ messages in thread
From: Yana Bashlykova @ 2025-09-12 19:53 UTC (permalink / raw)
To: David S. Miller
Cc: Yana Bashlykova, Eric Dumazet, Jakub Kicinski, Paolo Abeni,
Shuah Khan, Paul Walmsley, Palmer Dabbelt, Albert Ou,
Nathan Chancellor, Nick Desaulniers, Tom Rix, linux-kernel,
netdev, linux-kselftest, linux-riscv, bpf, llvm, lvc-project
This series adds comprehensive testing infrastructure for Netlink
and Generic Netlink
The implementation includes both kernel module and userspace tests to
verify correct Generic Netlink and Netlink behaviors under
various conditions.
Yana Bashlykova (15):
genetlink: add sysfs test module for Generic Netlink
genetlink: add TEST_GENL family for netlink testing
genetlink: add PARALLEL_GENL test family
genetlink: add test case for duplicate genl family registration
genetlink: add test case for family with invalid ops
genetlink: add netlink notifier support
genetlink: add THIRD_GENL family
genetlink: verify unregister fails for non-registered family
genetlink: add LARGE_GENL stress test family
selftests: net: genetlink: add packet capture test infrastructure
selftests: net: genetlink: add /proc/net/netlink test
selftests: net: genetlink: add Generic Netlink controller tests
selftests: net: genetlink: add large family ID resolution test
selftests: net: genetlink: add Netlink and Generic Netlink test suite
selftests: net: genetlink: fix expectation for large family resolution
drivers/net/Kconfig | 2 +
drivers/net/Makefile | 2 +
drivers/net/genetlink/Kconfig | 8 +
drivers/net/genetlink/Makefile | 3 +
.../net-pf-16-proto-16-family-PARALLEL_GENL.c | 1921 ++++++
tools/testing/selftests/net/Makefile | 6 +
tools/testing/selftests/net/genetlink.c | 5152 +++++++++++++++++
7 files changed, 7094 insertions(+)
create mode 100644 drivers/net/genetlink/Kconfig
create mode 100644 drivers/net/genetlink/Makefile
create mode 100644 drivers/net/genetlink/net-pf-16-proto-16-family-PARALLEL_GENL.c
create mode 100644 tools/testing/selftests/net/genetlink.c
--
2.34.1
_______________________________________________
linux-riscv mailing list
linux-riscv@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-riscv
^ permalink raw reply [flat|nested] 5+ messages in thread
* [PATCH 6.1 10/15] selftests: net: genetlink: add packet capture test infrastructure
2025-09-12 19:53 [PATCH 6.1 00/15] genetlink: Test Netlink subsystem of Linux v6.1 Yana Bashlykova
@ 2025-09-12 19:53 ` Yana Bashlykova
2025-09-12 20:17 ` [PATCH 6.1 00/15] genetlink: Test Netlink subsystem of Linux v6.1 Jakub Kicinski
1 sibling, 0 replies; 5+ messages in thread
From: Yana Bashlykova @ 2025-09-12 19:53 UTC (permalink / raw)
To: David S. Miller
Cc: Yana Bashlykova, Eric Dumazet, Jakub Kicinski, Paolo Abeni,
Shuah Khan, Paul Walmsley, Palmer Dabbelt, Albert Ou,
Nathan Chancellor, Nick Desaulniers, Tom Rix, linux-kernel,
netdev, linux-kselftest, linux-riscv, bpf, llvm, lvc-project
Add test cases for monitoring Netlink traffic during test execution
Require CONFIG_NLMON.
Signed-off-by: Yana Bashlykova <yana2bsh@gmail.com>
---
tools/testing/selftests/net/Makefile | 6 +
tools/testing/selftests/net/genetlink.c | 234 ++++++++++++++++++++++++
2 files changed, 240 insertions(+)
create mode 100644 tools/testing/selftests/net/genetlink.c
diff --git a/tools/testing/selftests/net/Makefile b/tools/testing/selftests/net/Makefile
index 69c58362c0ed..0c325ccc5f03 100644
--- a/tools/testing/selftests/net/Makefile
+++ b/tools/testing/selftests/net/Makefile
@@ -71,6 +71,7 @@ TEST_GEN_FILES += bind_bhash
TEST_GEN_PROGS += sk_bind_sendto_listen
TEST_GEN_PROGS += sk_connect_zero_addr
TEST_PROGS += test_ingress_egress_chaining.sh
+TEST_GEN_PROGS += genetlink
TEST_FILES := settings
@@ -82,3 +83,8 @@ $(OUTPUT)/reuseport_bpf_numa: LDLIBS += -lnuma
$(OUTPUT)/tcp_mmap: LDLIBS += -lpthread
$(OUTPUT)/tcp_inq: LDLIBS += -lpthread
$(OUTPUT)/bind_bhash: LDLIBS += -lpthread
+
+$(OUTPUT)/genetlink: LDLIBS += -lnl-3 -lnl-genl-3
+$(OUTPUT)/genetlink: CFLAGS += $(shell pkg-config --cflags libnl-3.0 libnl-genl-3.0)
+
+EXTRA_CLEAN := $(SCRATCH_DIR) $(OUTPUT)/genetlink.pcap
diff --git a/tools/testing/selftests/net/genetlink.c b/tools/testing/selftests/net/genetlink.c
new file mode 100644
index 000000000000..5be9ca68accd
--- /dev/null
+++ b/tools/testing/selftests/net/genetlink.c
@@ -0,0 +1,234 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * Generic Netlink and Netlink test cases
+ *
+ * This test suite validates various aspects of Generic Netlink and Netlink communication
+ *
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <errno.h>
+#include <unistd.h>
+#include <fcntl.h>
+#include <ctype.h>
+#include <sys/wait.h>
+#include <time.h>
+#include <inttypes.h>
+#include <signal.h>
+#include <netlink/netlink.h>
+#include <netlink/genl/genl.h>
+#include <netlink/genl/family.h>
+#include <netlink/genl/ctrl.h>
+#include <netlink/genl/mngt.h>
+#include <linux/genetlink.h>
+
+#include "../kselftest_harness.h"
+
+#define MY_GENL_FAMILY_NAME "TEST_GENL"
+#define MY_GENL_CMD_UNSPEC 0
+#define MY_GENL_CMD_ECHO 1
+#define MY_GENL_CMD_SET_VALUE 2
+#define MY_GENL_CMD_GET_VALUE 3
+#define MY_GENL_CMD_EVENT 4
+#define MY_GENL_CMD_NO_ATTRS 5
+
+#define MY_GENL_SMALL_CMD_GET 0
+
+#define MY_GENL_ATTR_UNSPEC 0
+#define MY_GENL_ATTR_DATA 1
+#define MY_GENL_ATTR_VALUE 2
+#define MY_GENL_ATTR_PATH 3
+#define MY_GENL_ATTR_NESTED 4
+#define MY_GENL_ATTR_MAX 4
+
+#define THIRD_GENL_FAMILY_NAME "THIRD_GENL"
+
+#define THIRD_GENL_CMD_ECHO 1
+
+#define THIRD_GENL_ATTR_UNSPEC 0
+#define THIRD_GENL_ATTR_DATA 1
+#define THIRD_GENL_ATTR_FLAG 2
+#define THIRD_GENL_ATTR_MAX 2
+
+#define PATH_GENL_TEST_NUM "/sys/kernel/genl_test/value"
+#define PATH_GENL_TEST_MES "/sys/kernel/genl_test/message"
+#define PATH_GENL_TEST_DEV "/sys/kernel/genl_test/some_info"
+#define PATH_PARALLEL_GENL_MES "/sys/kernel/parallel_genl/message"
+#define PATH_THIRD_GENL_MES "/sys/kernel/third_genl/message"
+
+#define MY_MCGRP_NAME "MY_MCGRP_GENL"
+
+#define GENL_CTRL "nlctrl"
+#define CTRL_ATTR_POLICY_MAX (__CTRL_ATTR_POLICY_DUMP_MAX - 1)
+
+#define PARALLEL_GENL_FAMILY_NAME "PARALLEL_GENL"
+#define PARALLEL_GENL_ATTR_UNSPEC 0
+#define PARALLEL_GENL_CMD_SEND 1
+#define PARALLEL_GENL_CMD_DUMP_INFO 2
+#define PARALLEL_GENL_CMD_SET_VALUE 3
+#define PARALLEL_GENL_CMD_GET_VALUE 4
+
+#define PARALLEL_GENL_ATTR_DATA 1
+#define PARALLEL_GENL_ATTR_BINARY 2
+#define PARALLEL_GENL_ATTR_NAME 3
+#define PARALLEL_GENL_ATTR_DESC 4
+#define PARALLEL_GENL_ATTR_FLAG_NONBLOCK 9
+#define PARALLEL_GENL_ATTR_FLAG_BLOCK 10
+#define PARALLEL_GENL_ATTR_PATH 12
+#define PARALLEL_GENL_ATTR_MAX 12
+
+#define LARGE_GENL_FAMILY_NAME "LARGE_GENL"
+
+/*
+ * Test cases
+ */
+
+/**
+ * TEST(capture_start) - Starts Netlink traffic capture using nlmon interface
+ *
+ * Creates a virtual nlmon interface, enables it and starts packet capture
+ * with tcpdump. Captured packets are saved to 'genetlink.pcap' file.
+ *
+ * Note:
+ * - Requires root privileges
+ * - Creates temporary interface 'nlmon0'
+ * - Runs tcpdump in background
+ * - Adds small delay to ensure capture starts
+ */
+
+TEST(capture_start)
+{
+ printf("Running Test: starting Netlink traffic capture...\n");
+
+ // Only root can monitor Netlink traffic
+ if (geteuid()) {
+ SKIP(return, "test requires root");
+ return;
+ }
+
+ char command[256];
+ int result;
+
+ snprintf(command, sizeof(command), "ip link add nlmon0 type nlmon");
+ result = system(command);
+ ASSERT_EQ(WEXITSTATUS(result), 0);
+ if (result == -1) {
+ perror("system");
+ return;
+ }
+
+ snprintf(command, sizeof(command), "ip link set nlmon0 up");
+ result = system(command);
+ ASSERT_EQ(WEXITSTATUS(result), 0);
+ if (result == -1) {
+ perror("system");
+ return;
+ }
+
+ snprintf(command, sizeof(command),
+ "tcpdump -i nlmon0 -w genetlink.pcap &");
+ result = system(command);
+ ASSERT_EQ(WEXITSTATUS(result), 0);
+ if (result == -1) {
+ perror("system");
+ return;
+ }
+
+ printf("nlmon is up. Starting netlink process...\n");
+
+ sleep(2);
+
+ printf("Starting Netlink tests...\n");
+}
+
+/**
+ * TEST(capture_end) - Terminates Netlink traffic monitoring session
+ *
+ * Performs controlled shutdown of nlmon capture interface by:
+ * 1. Stopping tcpdump capture process
+ * 2. Bringing down nlmon interface
+ * 3. Deleting nlmon interface
+ *
+ * Test Procedure:
+ * 1. Privilege Check:
+ * - Verifies root privileges (required for nlmon operations)
+ * - Gracefully skips if not root
+ *
+ * 2. Capture Termination:
+ * - Stops tcpdump process (2-second delay for cleanup)
+ * - Brings nlmon0 interface down
+ * - Deletes nlmon0 interface
+ * - Validates each operation succeeds
+ *
+ * 3. Cleanup Verification:
+ * - Checks system command exit statuses
+ * - Provides detailed error reporting
+ *
+ * Key Validations:
+ * - Proper termination of monitoring session
+ * - Correct interface teardown
+ * - Root privilege enforcement
+ * - System command error handling
+ *
+ * Expected Behavior:
+ * - tcpdump process should terminate successfully
+ * - nlmon0 interface should deactivate cleanly
+ * - Interface should be removable
+ * - Non-root execution should skip gracefully
+ *
+ * Security Considerations:
+ * - Requires root for network interface control
+ * - Ensures complete capture session cleanup
+ * - Verifies proper resource release
+ *
+ * Note:
+ * - Should be paired with capture_start test
+ * - Includes 2-second delay for process stabilization
+ * - Provides status feedback through printf
+ */
+
+TEST(capture_end)
+{
+ printf("Running Test: stopping Netlink traffic capture...\n");
+
+ // Only root can monitor Netlink traffic
+ if (geteuid()) {
+ SKIP(return, "test requires root");
+ return;
+ }
+
+ char command[256];
+ int result;
+
+ sleep(2);
+
+ snprintf(command, sizeof(command), "pkill tcpdump");
+ result = system(command);
+ ASSERT_EQ(WEXITSTATUS(result), 0);
+ if (result == -1) {
+ perror("system");
+ return;
+ }
+
+ snprintf(command, sizeof(command), "ip link set nlmon0 down");
+ result = system(command);
+ ASSERT_EQ(WEXITSTATUS(result), 0);
+ if (result == -1) {
+ perror("system");
+ return;
+ }
+
+ snprintf(command, sizeof(command), "ip link delete nlmon0 type nlmon");
+ result = system(command);
+ ASSERT_EQ(WEXITSTATUS(result), 0);
+ if (result == -1) {
+ perror("system");
+ return;
+ }
+
+ printf("The capturing is over\n");
+}
+
+TEST_HARNESS_MAIN
--
2.34.1
_______________________________________________
linux-riscv mailing list
linux-riscv@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-riscv
^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [PATCH 6.1 00/15] genetlink: Test Netlink subsystem of Linux v6.1
2025-09-12 19:53 [PATCH 6.1 00/15] genetlink: Test Netlink subsystem of Linux v6.1 Yana Bashlykova
2025-09-12 19:53 ` [PATCH 6.1 10/15] selftests: net: genetlink: add packet capture test infrastructure Yana Bashlykova
@ 2025-09-12 20:17 ` Jakub Kicinski
2025-10-15 14:49 ` Яна Башлыкова
1 sibling, 1 reply; 5+ messages in thread
From: Jakub Kicinski @ 2025-09-12 20:17 UTC (permalink / raw)
To: Yana Bashlykova
Cc: David S. Miller, Eric Dumazet, Paolo Abeni, Shuah Khan,
Paul Walmsley, Palmer Dabbelt, Albert Ou, Nathan Chancellor,
Nick Desaulniers, Tom Rix, linux-kernel, netdev, linux-kselftest,
linux-riscv, bpf, llvm, lvc-project
On Fri, 12 Sep 2025 22:53:23 +0300 Yana Bashlykova wrote:
> This series adds comprehensive testing infrastructure for Netlink
> and Generic Netlink
>
> The implementation includes both kernel module and userspace tests to
> verify correct Generic Netlink and Netlink behaviors under
> various conditions.
What is the motivation for this work?
_______________________________________________
linux-riscv mailing list
linux-riscv@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-riscv
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH 6.1 00/15] genetlink: Test Netlink subsystem of Linux v6.1
2025-09-12 20:17 ` [PATCH 6.1 00/15] genetlink: Test Netlink subsystem of Linux v6.1 Jakub Kicinski
@ 2025-10-15 14:49 ` Яна Башлыкова
2025-10-15 15:04 ` Jakub Kicinski
0 siblings, 1 reply; 5+ messages in thread
From: Яна Башлыкова @ 2025-10-15 14:49 UTC (permalink / raw)
To: Jakub Kicinski
Cc: David S. Miller, Eric Dumazet, Paolo Abeni, Shuah Khan,
Paul Walmsley, Palmer Dabbelt, Albert Ou, Nathan Chancellor,
Nick Desaulniers, Tom Rix, linux-kernel, netdev, linux-kselftest,
linux-riscv, bpf, llvm, lvc-project
The motivation for this work is to improve the test coverage and
reliability of the Netlink subsystem, specifically for the core
af_netlink.c and genetlink.c components. While the subsystem is
critical for kernel-userspace communication, its coverage by the
existing selftests is quite limited.
To quantify the improvement, these new selftests achieve the following
line coverage (as measured by gcov):
- net/netlink/af_netlink.c: 84.0%
- net/netlink/genetlink.c: 88.8%
Integrating these tests into the upstream suite will provide long-term
stability and make it safer to refactor or add new features to the
Netlink core in the future.
пт, 12 сент. 2025 г. в 23:17, Jakub Kicinski <kuba@kernel.org>:
пт, 12 сент. 2025 г. в 23:17, Jakub Kicinski <kuba@kernel.org>:
>
> On Fri, 12 Sep 2025 22:53:23 +0300 Yana Bashlykova wrote:
> > This series adds comprehensive testing infrastructure for Netlink
> > and Generic Netlink
> >
> > The implementation includes both kernel module and userspace tests to
> > verify correct Generic Netlink and Netlink behaviors under
> > various conditions.
>
> What is the motivation for this work?
_______________________________________________
linux-riscv mailing list
linux-riscv@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-riscv
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH 6.1 00/15] genetlink: Test Netlink subsystem of Linux v6.1
2025-10-15 14:49 ` Яна Башлыкова
@ 2025-10-15 15:04 ` Jakub Kicinski
0 siblings, 0 replies; 5+ messages in thread
From: Jakub Kicinski @ 2025-10-15 15:04 UTC (permalink / raw)
To: Яна Башлыкова
Cc: David S. Miller, Eric Dumazet, Paolo Abeni, Shuah Khan,
Paul Walmsley, Palmer Dabbelt, Albert Ou, Nathan Chancellor,
Nick Desaulniers, Tom Rix, linux-kernel, netdev, linux-kselftest,
linux-riscv, bpf, llvm, lvc-project
On Wed, 15 Oct 2025 17:49:22 +0300 Яна Башлыкова wrote:
> The motivation for this work is to improve the test coverage and
> reliability of the Netlink subsystem, specifically for the core
> af_netlink.c and genetlink.c components. While the subsystem is
> critical for kernel-userspace communication, its coverage by the
> existing selftests is quite limited.
>
> To quantify the improvement, these new selftests achieve the following
> line coverage (as measured by gcov):
> - net/netlink/af_netlink.c: 84.0%
> - net/netlink/genetlink.c: 88.8%
For what it's worth syzbot has:
af_netlink.c 91%
genetlink.c 68%
Without a line of code added to the kernel. Of course it's not
functional testing.
> Integrating these tests into the upstream suite will provide long-term
> stability and make it safer to refactor or add new features to the
> Netlink core in the future.
Happy to hear from others if they disagree but what kernel tests get
merged into the tree is pretty subjective. Do we have a lot of bugs
in genetlink? Are you planning to do major development in this area
and want to catch regressions? If the answers to both of those questions
is "no" IMHO this 7kLoC is not worth carrying in the tree.
_______________________________________________
linux-riscv mailing list
linux-riscv@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-riscv
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2025-10-15 15:05 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-09-12 19:53 [PATCH 6.1 00/15] genetlink: Test Netlink subsystem of Linux v6.1 Yana Bashlykova
2025-09-12 19:53 ` [PATCH 6.1 10/15] selftests: net: genetlink: add packet capture test infrastructure Yana Bashlykova
2025-09-12 20:17 ` [PATCH 6.1 00/15] genetlink: Test Netlink subsystem of Linux v6.1 Jakub Kicinski
2025-10-15 14:49 ` Яна Башлыкова
2025-10-15 15:04 ` Jakub Kicinski
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).