summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMatt Johnston <matt@codeconstruct.com.au>2025-07-10 16:56:00 +0800
committerPaolo Abeni <pabeni@redhat.com>2025-07-15 12:08:39 +0200
commitb7e28129b667dede890bc7bd340a77e325df156a (patch)
treeb57a2102e15990b3eb13522dbb3378e627ec9e72
parent3549eb08e5505823857838b5cf5f08567702d054 (diff)
net: mctp: Test conflicts of connect() with bind()
The addition of connect() adds new conflict cases to test. Signed-off-by: Matt Johnston <matt@codeconstruct.com.au> Link: https://patch.msgid.link/20250710-mctp-bind-v4-7-8ec2f6460c56@codeconstruct.com.au Signed-off-by: Paolo Abeni <pabeni@redhat.com>
-rw-r--r--net/mctp/test/sock-test.c45
-rw-r--r--net/mctp/test/utils.c14
-rw-r--r--net/mctp/test/utils.h4
3 files changed, 59 insertions, 4 deletions
diff --git a/net/mctp/test/sock-test.c b/net/mctp/test/sock-test.c
index 0cfc337be687..b0942deb5019 100644
--- a/net/mctp/test/sock-test.c
+++ b/net/mctp/test/sock-test.c
@@ -245,6 +245,11 @@ static const struct mctp_test_bind_setup bind_addrany_net2_type2 = {
.bind_addr = MCTP_ADDR_ANY, .bind_net = 2, .bind_type = 2,
};
+static const struct mctp_test_bind_setup bind_addrany_net2_type1_peer9 = {
+ .bind_addr = MCTP_ADDR_ANY, .bind_net = 2, .bind_type = 1,
+ .have_peer = true, .peer_addr = 9, .peer_net = 2,
+};
+
struct mctp_bind_pair_test {
const struct mctp_test_bind_setup *bind1;
const struct mctp_test_bind_setup *bind2;
@@ -278,19 +283,50 @@ static const struct mctp_bind_pair_test mctp_bind_pair_tests[] = {
* vs ADDR_ANY, explicit default net 1, OK
*/
{ &bind_addrany_netdefault_type1, &bind_addrany_net1_type1, 0 },
+
+ /* specific remote peer doesn't conflict with any-peer bind */
+ { &bind_addrany_net2_type1_peer9, &bind_addrany_net2_type1, 0 },
+
+ /* bind() NET_ANY is allowed with a connect() net */
+ { &bind_addrany_net2_type1_peer9, &bind_addrany_netdefault_type1, 0 },
};
static void mctp_bind_pair_desc(const struct mctp_bind_pair_test *t, char *desc)
{
+ char peer1[25] = {0}, peer2[25] = {0};
+
+ if (t->bind1->have_peer)
+ snprintf(peer1, sizeof(peer1), ", peer %d net %d",
+ t->bind1->peer_addr, t->bind1->peer_net);
+ if (t->bind2->have_peer)
+ snprintf(peer2, sizeof(peer2), ", peer %d net %d",
+ t->bind2->peer_addr, t->bind2->peer_net);
+
snprintf(desc, KUNIT_PARAM_DESC_SIZE,
- "{bind(addr %d, type %d, net %d)} {bind(addr %d, type %d, net %d)} -> error %d",
- t->bind1->bind_addr, t->bind1->bind_type, t->bind1->bind_net,
- t->bind2->bind_addr, t->bind2->bind_type, t->bind2->bind_net,
- t->error);
+ "{bind(addr %d, type %d, net %d%s)} {bind(addr %d, type %d, net %d%s)} -> error %d",
+ t->bind1->bind_addr, t->bind1->bind_type,
+ t->bind1->bind_net, peer1,
+ t->bind2->bind_addr, t->bind2->bind_type,
+ t->bind2->bind_net, peer2, t->error);
}
KUNIT_ARRAY_PARAM(mctp_bind_pair, mctp_bind_pair_tests, mctp_bind_pair_desc);
+static void mctp_test_bind_invalid(struct kunit *test)
+{
+ struct socket *sock;
+ int rc;
+
+ /* bind() fails if the bind() vs connect() networks mismatch. */
+ const struct mctp_test_bind_setup bind_connect_net_mismatch = {
+ .bind_addr = MCTP_ADDR_ANY, .bind_net = 1, .bind_type = 1,
+ .have_peer = true, .peer_addr = 9, .peer_net = 2,
+ };
+ mctp_test_bind_run(test, &bind_connect_net_mismatch, &rc, &sock);
+ KUNIT_EXPECT_EQ(test, -rc, EINVAL);
+ sock_release(sock);
+}
+
static int
mctp_test_bind_conflicts_inner(struct kunit *test,
const struct mctp_test_bind_setup *bind1,
@@ -348,6 +384,7 @@ static struct kunit_case mctp_test_cases[] = {
KUNIT_CASE(mctp_test_sock_sendmsg_extaddr),
KUNIT_CASE(mctp_test_sock_recvmsg_extaddr),
KUNIT_CASE_PARAM(mctp_test_bind_conflicts, mctp_bind_pair_gen_params),
+ KUNIT_CASE(mctp_test_bind_invalid),
{}
};
diff --git a/net/mctp/test/utils.c b/net/mctp/test/utils.c
index c971e2c326f3..953d41902771 100644
--- a/net/mctp/test/utils.c
+++ b/net/mctp/test/utils.c
@@ -271,6 +271,20 @@ void mctp_test_bind_run(struct kunit *test,
rc = sock_create_kern(&init_net, AF_MCTP, SOCK_DGRAM, 0, sock);
KUNIT_ASSERT_EQ(test, rc, 0);
+ /* connect() if requested */
+ if (setup->have_peer) {
+ memset(&addr, 0x0, sizeof(addr));
+ addr.smctp_family = AF_MCTP;
+ addr.smctp_network = setup->peer_net;
+ addr.smctp_addr.s_addr = setup->peer_addr;
+ /* connect() type must match bind() type */
+ addr.smctp_type = setup->bind_type;
+ rc = kernel_connect(*sock, (struct sockaddr *)&addr,
+ sizeof(addr), 0);
+ KUNIT_EXPECT_EQ(test, rc, 0);
+ }
+
+ /* bind() */
memset(&addr, 0x0, sizeof(addr));
addr.smctp_family = AF_MCTP;
addr.smctp_network = setup->bind_net;
diff --git a/net/mctp/test/utils.h b/net/mctp/test/utils.h
index 7dd1a92ab770..c2aaba5188ab 100644
--- a/net/mctp/test/utils.h
+++ b/net/mctp/test/utils.h
@@ -35,6 +35,10 @@ struct mctp_test_bind_setup {
mctp_eid_t bind_addr;
int bind_net;
u8 bind_type;
+
+ bool have_peer;
+ mctp_eid_t peer_addr;
+ int peer_net;
};
struct mctp_test_dev *mctp_test_create_dev(void);