Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions homa_plumbing.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand Down
8 changes: 8 additions & 0 deletions test/mock.c
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*/
Expand Down Expand Up @@ -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;
}

Expand Down Expand Up @@ -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;
Expand Down
3 changes: 3 additions & 0 deletions test/mock.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
34 changes: 34 additions & 0 deletions test/unit_homa_plumbing.c
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#include "ccutils.h"
#include "mock.h"
#include "utils.h"
#include <linux/version.h>

FIXTURE(homa_plumbing) {
struct in6_addr client_ip[1];
Expand Down Expand Up @@ -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