From patchwork Mon Feb 19 09:51:56 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jeremy Kerr X-Patchwork-Id: 13562481 X-Patchwork-Delegate: kuba@kernel.org Received: from codeconstruct.com.au (pi.codeconstruct.com.au [203.29.241.158]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id E7030286A7 for ; Mon, 19 Feb 2024 09:53:59 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=203.29.241.158 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708336441; cv=none; b=n83bJvZedP9Yl1oiytHxPIoVNBKE1Dedrt/7dB0W85jPO5Nno2FNMxcPFUMkoCr6IWTQgIxiQwdOr0eQqMXTOVU5wFaHxNmUp0MZE0xQobpYnYMjZ4aYoHzLQLDGSlNQdZ3SCUOFMxASUHClG8H8Adx4YFHabxqgfVfMBkd+T24= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708336441; c=relaxed/simple; bh=6HrrZf+RvWjkkutH0zKQQN03igGlKMaD/nLcAfMQeVM=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=F6Ex/P3tQAWsVnY4GSYKDgONzNSyIVZf9teutSt6qcWmWsQNE9OIsjunwZHQ4PUiR7oCo+YG4+TvRZ6TwBvxQQUL540Ve7nHuP6DMqCH/sg5R5dP5MTC9pGPJPJk9aK5stlk2hNuAmmnDIRAlzpcmwrTK5amln3v+mLPxL7TsHk= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=codeconstruct.com.au; spf=pass smtp.mailfrom=codeconstruct.com.au; dkim=pass (2048-bit key) header.d=codeconstruct.com.au header.i=@codeconstruct.com.au header.b=brnvUfG1; arc=none smtp.client-ip=203.29.241.158 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=codeconstruct.com.au Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=codeconstruct.com.au Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=codeconstruct.com.au header.i=@codeconstruct.com.au header.b="brnvUfG1" Received: by codeconstruct.com.au (Postfix, from userid 10000) id 1B9282048F; Mon, 19 Feb 2024 17:53:57 +0800 (AWST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=codeconstruct.com.au; s=2022a; t=1708336437; bh=jZB8Ilcjys0OU6iBAMmbmCBGxR4AlQJ3KQQosxnH9zE=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=brnvUfG19i7DmitRZqO1yR5sSYGI4SMKxhNJNolbwaCVIVCkEDDSJVL8CEgBx3TWu 60I9pGUpGoOzwMIT+2T70Ii1Q5PQZTx8R62nRFtD8UreUcinvvAR+S/g8JQsoUTgZB uNpQn+vlCZS6W2Ijtm5ShtJRCUI3Xn72tlhfZ7mxajmRG2rHidZQKZ4H7UqbokPoZU 4nURdwX5Wiz5ecz04Orgfyog6HNvvbeKuk3jiHuisRFzwpHkEYJrxJ9s6Z1igx8nAS sJGYOmbgAiYBwFwOsGemM3SwDpPgHjOMTtWiGrv4TZXJrtYAGfGJMIZiEUgnY6uOmV QowhTfbT7ybeg== From: Jeremy Kerr To: netdev@vger.kernel.org Cc: Matt Johnston , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Simon Horman , David Howells , Alexander Lobakin , Liang Chen , Johannes Berg , Dan Carpenter Subject: [PATCH net-next v2 11/11] net: mctp: tests: Add a test for proper tag creation on local output Date: Mon, 19 Feb 2024 17:51:56 +0800 Message-Id: <1b66cd5a989f487cb8435c0eebc1457802f1bf84.1708335994.git.jk@codeconstruct.com.au> X-Mailer: git-send-email 2.39.2 In-Reply-To: References: Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Patchwork-Delegate: kuba@kernel.org Ensure we have the correct key parameters on sending a message. Signed-off-by: Jeremy Kerr --- net/mctp/test/route-test.c | 75 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 75 insertions(+) diff --git a/net/mctp/test/route-test.c b/net/mctp/test/route-test.c index eb7e9ac95612..77e5dd422258 100644 --- a/net/mctp/test/route-test.c +++ b/net/mctp/test/route-test.c @@ -971,6 +971,80 @@ static void mctp_test_fragment_flow(struct kunit *test) } #endif +/* Test that outgoing skbs cause a suitable tag to be created */ +static void mctp_test_route_output_key_create(struct kunit *test) +{ + const unsigned int netid = 50; + const u8 dst = 26, src = 15; + struct mctp_test_route *rt; + struct mctp_test_dev *dev; + struct mctp_sk_key *key; + struct netns_mctp *mns; + unsigned long flags; + struct socket *sock; + struct sk_buff *skb; + bool empty, single; + const int len = 2; + int rc; + + dev = mctp_test_create_dev(); + KUNIT_ASSERT_NOT_ERR_OR_NULL(test, dev); + WRITE_ONCE(dev->mdev->net, netid); + + rt = mctp_test_create_route(&init_net, dev->mdev, dst, 68); + KUNIT_ASSERT_NOT_ERR_OR_NULL(test, rt); + + rc = sock_create_kern(&init_net, AF_MCTP, SOCK_DGRAM, 0, &sock); + KUNIT_ASSERT_EQ(test, rc, 0); + + dev->mdev->addrs = kmalloc(sizeof(u8), GFP_KERNEL); + dev->mdev->num_addrs = 1; + dev->mdev->addrs[0] = src; + + skb = alloc_skb(sizeof(struct mctp_hdr) + 1 + len, GFP_KERNEL); + KUNIT_ASSERT_TRUE(test, skb); + __mctp_cb(skb); + skb_reserve(skb, sizeof(struct mctp_hdr) + 1 + len); + memset(skb_put(skb, len), 0, len); + + refcount_inc(&rt->rt.refs); + + mns = &sock_net(sock->sk)->mctp; + + /* We assume we're starting from an empty keys list, which requires + * preceding tests to clean up correctly! + */ + spin_lock_irqsave(&mns->keys_lock, flags); + empty = hlist_empty(&mns->keys); + spin_unlock_irqrestore(&mns->keys_lock, flags); + KUNIT_ASSERT_TRUE(test, empty); + + rc = mctp_local_output(sock->sk, &rt->rt, skb, dst, MCTP_TAG_OWNER); + KUNIT_ASSERT_EQ(test, rc, 0); + + key = NULL; + single = false; + spin_lock_irqsave(&mns->keys_lock, flags); + if (!hlist_empty(&mns->keys)) { + key = hlist_entry(mns->keys.first, struct mctp_sk_key, hlist); + single = hlist_is_singular_node(&key->hlist, &mns->keys); + } + spin_unlock_irqrestore(&mns->keys_lock, flags); + + KUNIT_ASSERT_NOT_NULL(test, key); + KUNIT_ASSERT_TRUE(test, single); + + KUNIT_EXPECT_EQ(test, key->net, netid); + KUNIT_EXPECT_EQ(test, key->local_addr, src); + KUNIT_EXPECT_EQ(test, key->peer_addr, dst); + /* key has incoming tag, so inverse of what we sent */ + KUNIT_EXPECT_FALSE(test, key->tag & MCTP_TAG_OWNER); + + sock_release(sock); + mctp_test_route_destroy(test, rt); + mctp_test_destroy_dev(dev); +} + static struct kunit_case mctp_test_cases[] = { KUNIT_CASE_PARAM(mctp_test_fragment, mctp_frag_gen_params), KUNIT_CASE_PARAM(mctp_test_rx_input, mctp_rx_input_gen_params), @@ -983,6 +1057,7 @@ static struct kunit_case mctp_test_cases[] = { KUNIT_CASE(mctp_test_route_input_multiple_nets_key), KUNIT_CASE(mctp_test_packet_flow), KUNIT_CASE(mctp_test_fragment_flow), + KUNIT_CASE(mctp_test_route_output_key_create), {} };