From 37decdb0ccbbe21c811faa659d41733d7c766761 Mon Sep 17 00:00:00 2001 From: Alex Becker Date: Thu, 17 Sep 2026 07:33:52 -0500 Subject: [PATCH] fix: add .netns_ok flag + regression test for Linux < 5.14 --- homa_plumbing.c | 1 + test/mock.c | 8 ++++++++ test/mock.h | 3 +++ test/unit_homa_plumbing.c | 34 ++++++++++++++++++++++++++++++++++ 4 files changed, 46 insertions(+) diff --git a/homa_plumbing.c b/homa_plumbing.c index cd5ef1eb..5c60cc89 100644 --- a/homa_plumbing.c +++ b/homa_plumbing.c @@ -144,6 +144,7 @@ static struct net_protocol homa_protocol = { .handler = homa_softirq, .err_handler = homa_err_handler_v4, .no_policy = 1, + .netns_ok = 1, }; static struct inet6_protocol homav6_protocol = { diff --git a/test/mock.c b/test/mock.c index cc9e00a3..c17ba30f 100644 --- a/test/mock.c +++ b/test/mock.c @@ -147,6 +147,10 @@ static int registered_qdiscs; /* Registered by most recent call to register_qdisc. */ static struct Qdisc_ops *qdisc_ops; +/* Arguments from the most recent inet_add_protocol call. Reset for each test. */ +const struct net_protocol *mock_inet_protocol; +unsigned char mock_inet_protocol_num; + /* Keeps track of all the results returned by ip_route_output_flow that * have not yet been freed. Reset for each test. */ @@ -703,6 +707,8 @@ int inet_add_offload(const struct net_offload *prot, unsigned char protocol) int inet_add_protocol(const struct net_protocol *prot, unsigned char num) { + mock_inet_protocol = prot; + mock_inet_protocol_num = num; return 0; } @@ -2599,6 +2605,8 @@ void mock_teardown(void) mock_dst_check_errors = 0; mock_import_ubuf_errors = 0; mock_import_iovec_errors = 0; + mock_inet_protocol = NULL; + mock_inet_protocol_num = 0; mock_ip6_xmit_errors = 0; mock_ip_queue_xmit_errors = 0; mock_kmalloc_errors = 0; diff --git a/test/mock.h b/test/mock.h index c7506817..2952bf76 100644 --- a/test/mock.h +++ b/test/mock.h @@ -182,6 +182,9 @@ extern int mock_ethtool_ksettings_errors; extern bool mock_exit_thread; extern int mock_import_iovec_errors; extern int mock_import_ubuf_errors; +extern const struct net_protocol + *mock_inet_protocol; +extern unsigned char mock_inet_protocol_num; extern int mock_ip6_xmit_errors; extern int mock_ip_queue_xmit_errors; extern bool mock_ipv6; diff --git a/test/unit_homa_plumbing.c b/test/unit_homa_plumbing.c index fda82062..6dbc5fc7 100644 --- a/test/unit_homa_plumbing.c +++ b/test/unit_homa_plumbing.c @@ -8,6 +8,7 @@ #include "ccutils.h" #include "mock.h" #include "utils.h" +#include FIXTURE(homa_plumbing) { struct in6_addr client_ip[1]; @@ -1692,3 +1693,36 @@ TEST_F(homa_plumbing, homa_poll__socket_readable) EXPECT_EQ(POLLIN | POLLRDNORM | POLLOUT | POLLWRNORM, homa_poll(NULL, &sock, NULL)); } + +/* Older kernels require netns_ok to be registered on kernel modules + * Regression check that .netns_ok does not get accidentally removed + * from homa_plumbing.c + * Linux 5.14 removed this field entirely + */ +#if LINUX_VERSION_CODE < KERNEL_VERSION(5, 14, 0) +TEST_F(homa_plumbing, homa_load__ipv4_netns_enabled) +{ + int result; + + /* Release the fixture's Homa instance before loading the global one. */ + homa_destroy(&self->homa); + + /* Require this load to supply the captured registration. */ + mock_inet_protocol = NULL; + mock_inet_protocol_num = 0; + + result = homa_load(); + ASSERT_EQ(0, result); + + /* Inspect the protocol handed to inet_add_protocol. Use nonfatal + * expectations and a null check -> run homa_unload on failure. + */ + EXPECT_NE(NULL, mock_inet_protocol); + EXPECT_EQ(IPPROTO_HOMA, mock_inet_protocol_num); + /* Cast the bit-field for the assertion macro's type inference. */ + if (mock_inet_protocol) + EXPECT_EQ(1, (int)mock_inet_protocol->netns_ok); + + homa_unload(); +} +#endif