Skip to contentSkip to conversation

net: mctp: improvements for NULL-EID addressing

PATCH Applied Jeremy Kerr 3 participants 7 messages Mar 31 – Apr 2

Subsystems (3)
lore
Share & tools
lore

Jeremy Kerr

author maintainer
#0 lore raw

cover net: mctp: improvements for NULL-EID addressing

Currently, our focus for the MCTP routing implementation has been for MCTP bus-owner devices. In this case, we will generally have an EID assigned during local transmit, and have routes established before expecting to receive.

We also want to handle non-bus-owner cases, where:

- we may need to send control protocol messages (like Discovery Notify) before any local addresses have been assigned, particularly as part of acquiring a local address assignment; and

- we will likely want to receive incoming messages before we have routing established.

This series improves handling for these cases, by handling NULL EIDs as source / destination addresses where possible.

---
Jeremy Kerr (3):
net: mctp: perform source address lookups when we populate our dst
net: mctp: allow local TX with no address assigned
net: mctp: don't require a route for null-EID ingress

 include/net/mctp.h         |   1 +
 net/mctp/route.c           |  92 +++++++++++------------
 net/mctp/test/route-test.c | 180 ++++++++++++++++++++++++++++++++++++++++++---
 net/mctp/test/utils.c      |  27 +++++++
 net/mctp/test/utils.h      |   1 +
 5 files changed, 242 insertions(+), 59 deletions(-)

---
base-commit: 7fae6616704a17c64438ad4b73a6effa6c03ffda
change-id: 20260324-dev-mctp-null-eids-0515711235ee

Best regards,

Signature · 1 line
Jeremy Kerr <[email protected]>
author maintainer
#1 lore raw

PATCH 1/3 net: mctp: perform source address lookups when we populate our dst

Rather than querying the output device for its address in mctp_local_output, set up the source address when we're populating the dst structure. If no address is assigned, use MCTP_ADDR_NULL.

This will allow us more flexibility when routing for NULL-source-eid cases. For now though, we still reject a NULL source address in the output path.

We need to update the tests a little, so that addresses are assigned before we do the dst lookups.

---
 include/net/mctp.h         |  1 +
 net/mctp/route.c           | 51 +++++++++++++++++++++++++++++-----------------
 net/mctp/test/route-test.c | 23 +++++++++++----------
 net/mctp/test/utils.c      | 27 ++++++++++++++++++++++++
 net/mctp/test/utils.h      |  1 +
 5 files changed, 73 insertions(+), 30 deletions(-)
include/net/mctp.h +1 -0
index c3207ce98f07fcbb436e968d503bc45666794fdc..e1e0a69afdcef7f0924523757010e75ea53e8e7c 100644
@@ -270,6 +270,7 @@ struct mctp_dst {
 	struct mctp_dev *dev;
 	unsigned int mtu;
 	mctp_eid_t nexthop;
+	mctp_eid_t saddr;
 
 	/* set for direct addressing */
 	unsigned char halen;
net/mctp/route.c +32 -19

106 lines not on this page · raw message

net/mctp/test/route-test.c +12 -11
index 61c989c43ec09c9e105de4e51b295d07bb93d6da..639b7c41c2a233fa78f789d0ef25b87a15fb702b 100644
@@ -174,7 +174,9 @@ static void mctp_rx_input_test_to_desc(const struct mctp_rx_input_test *t,
 KUNIT_ARRAY_PARAM(mctp_rx_input, mctp_rx_input_tests,
 		  mctp_rx_input_test_to_desc);
 
-/* set up a local dev, route on EID 8, and a socket listening on type 0 */
+/* set up a local dev (with addr 8), route on EID 8, and a socket listening on
+ * type 0
+ */
 static void __mctp_route_test_init(struct kunit *test,
 				   struct mctp_test_dev **devp,
 				   struct mctp_dst *dst,
@@ -191,6 +193,10 @@ static void __mctp_route_test_init(struct kunit *test,
 	if (netid != MCTP_NET_ANY)
 		WRITE_ONCE(dev->mdev->net, netid);
 
+	dev->mdev->addrs = kmalloc_objs(u8, 1, GFP_KERNEL);
+	dev->mdev->num_addrs = 1;
+	dev->mdev->addrs[0] = 8;
+
 	mctp_test_dst_setup(test, dst, dev, 68);
 
 	rc = sock_create_kern(&init_net, AF_MCTP, SOCK_DGRAM, 0, &sock);
@@ -928,11 +934,6 @@ static void mctp_test_flow_init(struct kunit *test,
 	 */
 	__mctp_route_test_init(test, &dev, dst, sock, MCTP_NET_ANY);
 
-	/* Assign a single EID. ->addrs is freed on mctp netdev release */
-	dev->mdev->addrs = kmalloc(sizeof(u8), GFP_KERNEL);
-	dev->mdev->num_addrs = 1;
-	dev->mdev->addrs[0] = 8;
-
 	skb = alloc_skb(len + sizeof(struct mctp_hdr) + 1, GFP_KERNEL);
 	KUNIT_ASSERT_TRUE(test, skb);
 	__mctp_cb(skb);
@@ -1058,8 +1059,6 @@ static void mctp_test_route_output_key_create(struct kunit *test)
 	KUNIT_ASSERT_NOT_ERR_OR_NULL(test, dev);
 	WRITE_ONCE(dev->mdev->net, netid);
 
-	mctp_test_dst_setup(test, &dst, dev, 68);
-
 	rc = sock_create_kern(&init_net, AF_MCTP, SOCK_DGRAM, 0, &sock);
 	KUNIT_ASSERT_EQ(test, rc, 0);
 
@@ -1067,6 +1066,8 @@ static void mctp_test_route_output_key_create(struct kunit *test)
 	dev->mdev->num_addrs = 1;
 	dev->mdev->addrs[0] = src_eid;
 
+	mctp_test_dst_setup(test, &dst, dev, 68);
+
 	skb = alloc_skb(sizeof(struct mctp_hdr) + 1 + len, GFP_KERNEL);
 	KUNIT_ASSERT_TRUE(test, skb);
 	__mctp_cb(skb);
@@ -1165,7 +1166,7 @@ static void mctp_test_route_gw_lookup(struct kunit *test)
 	struct mctp_test_dev *dev;
 	int rc;
 
-	dev = mctp_test_create_dev();
+	dev = mctp_test_create_dev_with_addr(8);
 	KUNIT_ASSERT_NOT_ERR_OR_NULL(test, dev);
 
 	/* 8 (local) -> 10 (gateway) via 9 (direct) */
@@ -1195,7 +1196,7 @@ static void mctp_test_route_gw_loop(struct kunit *test)
 	struct mctp_test_dev *dev;
 	int rc;
 
-	dev = mctp_test_create_dev();
+	dev = mctp_test_create_dev_with_addr(8);
 	KUNIT_ASSERT_NOT_ERR_OR_NULL(test, dev);
 
 	/* two routes using each other as the gw */
@@ -1254,7 +1255,7 @@ static void mctp_test_route_gw_mtu(struct kunit *test)
 	unsigned int netid;
 	int rc;
 
-	dev = mctp_test_create_dev();
+	dev = mctp_test_create_dev_with_addr(8);
 	KUNIT_ASSERT_NOT_ERR_OR_NULL(test, dev);
 	dev->ndev->mtu = mtus->dev;
 	mdev = dev->mdev;
net/mctp/test/utils.c +27 -0
index 97afe8cd2b05c9f047c4a6e8c9fb1b4496183cfe..2f79f8c1a2b44beb4917a9b92ffd72955a3a03c6 100644
@@ -80,6 +80,26 @@ struct mctp_test_dev *mctp_test_create_dev(void)
 	return __mctp_test_create_dev(0, NULL);
 }
 
+struct mctp_test_dev *mctp_test_create_dev_with_addr(mctp_eid_t addr)
+{
+	struct mctp_test_dev *dev;
+
+	dev = __mctp_test_create_dev(0, NULL);
+	if (!dev)
+		return NULL;
+
+	dev->mdev->addrs = kmalloc_objs(u8, 1, GFP_KERNEL);
+	if (!dev->mdev->addrs) {
+		mctp_test_destroy_dev(dev);
+		return NULL;
+	}
+
+	dev->mdev->num_addrs = 1;
+	dev->mdev->addrs[0] = 8;
+
+	return dev;
+}
+
 struct mctp_test_dev *mctp_test_create_dev_lladdr(unsigned short lladdr_len,
 						  const unsigned char *lladdr)
 {
@@ -171,6 +191,8 @@ struct mctp_test_route *mctp_test_create_route_gw(struct net *net,
 void mctp_test_dst_setup(struct kunit *test, struct mctp_dst *dst,
 			 struct mctp_test_dev *dev, unsigned int mtu)
 {
+	unsigned long flags;
+
 	KUNIT_EXPECT_NOT_ERR_OR_NULL(test, dev);
 
 	memset(dst, 0, sizeof(*dst));
@@ -179,6 +201,11 @@ void mctp_test_dst_setup(struct kunit *test, struct mctp_dst *dst,
 	__mctp_dev_get(dst->dev->dev);
 	dst->mtu = mtu;
 	dst->output = mctp_test_dst_output;
+	dst->saddr = MCTP_ADDR_NULL;
+	spin_lock_irqsave(&dev->mdev->addrs_lock, flags);
+	if (dev->mdev->num_addrs)
+		dst->saddr = dev->mdev->addrs[0];
+	spin_unlock_irqrestore(&dev->mdev->addrs_lock, flags);
 }
 
 void mctp_test_route_destroy(struct kunit *test, struct mctp_test_route *rt)
net/mctp/test/utils.h +1 -0
index 4cc90c9da4d1bfe9c63b2cac5253f9e09be3b147..47603732e6a570f7bb7e138246071fdbc092f790 100644
@@ -42,6 +42,7 @@ struct mctp_test_bind_setup {
 };
 
 struct mctp_test_dev *mctp_test_create_dev(void);
+struct mctp_test_dev *mctp_test_create_dev_with_addr(mctp_eid_t eid);
 struct mctp_test_dev *mctp_test_create_dev_lladdr(unsigned short lladdr_len,
 						  const unsigned char *lladdr);
 void mctp_test_destroy_dev(struct mctp_test_dev *dev);
Signature · 1 line
2.39.5
author maintainer
#4 lore raw

PATCH 2/3 net: mctp: allow local TX with no address assigned

In reply to Jeremy Kerr

If we're operating as a non-bus-owner endpoint, we may want to perform MCTP communication to get an address assigned. In this case, we'll have no local addresses, but can TX just fine either with extended routing, or where a direct route exists.

---
 net/mctp/route.c           |  18 ++-----
 net/mctp/test/route-test.c | 114 +++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 118 insertions(+), 14 deletions(-)
net/mctp/route.c +4 -14
index f6a88e668e68a8431e58ccc46e7ebb7bf2303f71..8c484776e9e42e246d5e214f5c997281f820a43a 100644
@@ -997,8 +997,8 @@ int mctp_route_lookup(struct net *net, unsigned int dnet,
 
 		if (rt->dst_type == MCTP_ROUTE_DIRECT) {
 			mctp_dst_from_route(&dst_tmp, daddr, mtu, rt);
-			/* we need a source address */
-			if (dst_tmp.saddr == MCTP_ADDR_NULL) {
+			/* cannot do gateway-ed routes without a src  */
+			if (dst_tmp.saddr == MCTP_ADDR_NULL && depth != 0) {
 				mctp_dst_release(&dst_tmp);
 			} else {
 				if (dst)
@@ -1141,19 +1141,13 @@ int mctp_local_output(struct sock *sk, struct mctp_dst *dst,
 	struct mctp_sk_key *key;
 	struct mctp_hdr *hdr;
 	unsigned int netid;
-	int rc = 0;
 	u8 tag;
 
 	KUNIT_STATIC_STUB_REDIRECT(mctp_local_output, sk, dst, skb, daddr,
 				   req_tag);
 
-	if (dst->saddr == MCTP_ADDR_NULL)
-		rc = -EHOSTUNREACH;
 	netid = READ_ONCE(dst->dev->net);
 
-	if (rc)
-		goto err_free;
-
 	if (req_tag & MCTP_TAG_OWNER) {
 		if (req_tag & MCTP_TAG_PREALLOC)
 			key = mctp_lookup_prealloc_tag(msk, netid, daddr,
@@ -1163,8 +1157,8 @@ int mctp_local_output(struct sock *sk, struct mctp_dst *dst,
 						   daddr, false, &tag);
 
 		if (IS_ERR(key)) {
-			rc = PTR_ERR(key);
-			goto err_free;
+			kfree_skb(skb);
+			return PTR_ERR(key);
 		}
 		mctp_skb_set_flow(skb, key);
 		/* done with the key in this scope */
@@ -1191,10 +1185,6 @@ int mctp_local_output(struct sock *sk, struct mctp_dst *dst,
 
 	/* route output functions consume the skb, even on error */
 	return mctp_do_fragment_route(dst, skb, dst->mtu, tag);
-
-err_free:
-	kfree_skb(skb);
-	return rc;
 }
 
 /* route management */
net/mctp/test/route-test.c +114 -0

126 lines not on this page · raw message

Signature · 1 line
2.39.5
author maintainer
#5 lore raw

PATCH 3/3 net: mctp: don't require a route for null-EID ingress

In reply to Jeremy Kerr

Currently, if we receive a physically-addressed packet for the local stack, we perform a route_lookup_null to find a matching device-based route. If a route is present, it will always have the ->output fn set to mctp_dst_input, which provides our delivery mechanism.

However, if we don't yet have any local addresses assigned, we won't have any local routes to lookup, so this will fail. One of the use-cases for physical addressing is initial address assignment on endpoint nodes, where we would have no addresses, and therefore no local routes.

Instead of iterating routes (looking for one matching the dev), just create a suitable mctp_dst for the device directly.

Add a testcase for the no-route case too.

---
 net/mctp/route.c           | 31 ++++++++++++-------------------
 net/mctp/test/route-test.c | 43 +++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 55 insertions(+), 19 deletions(-)
net/mctp/route.c +12 -19
index 8c484776e9e42e246d5e214f5c997281f820a43a..78263e7ae423d5bd92b10920b5c42c5f51a15a75 100644
@@ -1017,29 +1017,22 @@ int mctp_route_lookup(struct net *net, unsigned int dnet,
 	return rc;
 }
 
-static int mctp_route_lookup_null(struct net *net, struct net_device *dev,
-				  struct mctp_dst *dst)
+static int mctp_dst_input_null(struct net *net, struct net_device *dev,
+			       struct mctp_dst *dst)
 {
-	int rc = -EHOSTUNREACH;
-	struct mctp_route *rt;
-
 	rcu_read_lock();
+	dst->dev = __mctp_dev_get(dev);
+	rcu_read_unlock();
 
-	list_for_each_entry_rcu(rt, &net->mctp.routes, list) {
-		if (rt->dst_type != MCTP_ROUTE_DIRECT || rt->type != RTN_LOCAL)
-			continue;
-
-		if (rt->dev->dev != dev)
-			continue;
-
-		mctp_dst_from_route(dst, 0, 0, rt);
-		rc = 0;
-		break;
-	}
+	if (!dst->dev)
+		return -EHOSTUNREACH;
 
-	rcu_read_unlock();
+	dst->mtu = READ_ONCE(dev->mtu);
+	dst->halen = 0;
+	dst->output = mctp_dst_input;
+	dst->nexthop = 0;
 
-	return rc;
+	return 0;
 }
 
 static int mctp_do_fragment_route(struct mctp_dst *dst, struct sk_buff *skb,
@@ -1369,7 +1362,7 @@ static int mctp_pkttype_receive(struct sk_buff *skb, struct net_device *dev,
 
 	/* NULL EID, but addressed to our physical address */
 	if (rc && mh->dest == MCTP_ADDR_NULL && skb->pkt_type == PACKET_HOST)
-		rc = mctp_route_lookup_null(net, dev, &dst);
+		rc = mctp_dst_input_null(net, dev, &dst);
 
 	if (rc)
 		goto err_drop;
net/mctp/test/route-test.c +43 -0

55 lines not on this page · raw message

Signature · 1 line
2.39.5
maintainer
#2 lore raw

Re: [PATCH net-next 1/3] net: mctp: perform source address lookups when we populate our dst

In reply to Jeremy Kerr
Quoted 4 lines · Jeremy Kerr

Rather than querying the output device for its address in mctp_local_output, set up the source address when we're populating the dst structure. If no address is assigned, use MCTP_ADDR_NULL.

Quoted 8 lines

This will allow us more flexibility when routing for NULL-source-eid cases. For now though, we still reject a NULL source address in the output path.

We need to update the tests a little, so that addresses are assigned before we do the dst lookups.

Sashiko pointed to a possible pre-existent issue:

https://sashiko.dev/#/patchset/20260331-dev-mctp-null-eids-v1-0-b4d047372eaf%40codeconstruct.com.au

please have a look and follow-up if needed.

Thanks,

Paolo

#6 lore raw
In reply to Jeremy Kerr
This series was applied to netdev/net-next.git (main) by Paolo Abeni <[email protected]>:

Hello:

This series was applied to netdev/net-next.git (main) by Paolo Abeni <[email protected]>:

Quoted 8 lines · On Tue, 31 Mar 2026 15:41:05 +0800 you wrote:

Currently, our focus for the MCTP routing implementation has been for MCTP bus-owner devices. In this case, we will generally have an EID assigned during local transmit, and have routes established before expecting to receive.

We also want to handle non-bus-owner cases, where:

[...]

Here is the summary with links:
- [net-next,1/3] net: mctp: perform source address lookups when we populate our dst

    https://git.kernel.org/netdev/net-next/c/22cb45afd221
  - [net-next,2/3] net: mctp: allow local TX with no address assigned
    https://git.kernel.org/netdev/net-next/c/8af20defc4ed
  - [net-next,3/3] net: mctp: don't require a route for null-EID ingress
    https://git.kernel.org/netdev/net-next/c/0d8647bc74cb

You are awesome, thank you!

Signature · 2 lines
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html
author maintainer
#3 lore raw

Re: [PATCH net-next 1/3] net: mctp: perform source address lookups when we populate our dst

In reply to Paolo Abeni

Hi Pablo,

Quoted 11 lines
Quoted 11 lines

Rather than querying the output device for its address in mctp_local_output, set up the source address when we're populating the dst structure. If no address is assigned, use MCTP_ADDR_NULL.

This will allow us more flexibility when routing for NULL-source-eid cases. For now though, we still reject a NULL source address in the output path.

We need to update the tests a little, so that addresses are assigned before we do the dst lookups.

Quoted 7 lines
Quoted 1 line

Sashiko pointed to a possible pre-existent issue:

https://sashiko.dev/#/patchset/20260331-dev-mctp-null-eids-v1-0-b4d047372eaf%40codeconstruct.com.au

please have a look and follow-up if needed.

Yes, I've just been checking that out this afternoon. While there's nothing pressing there (the findings are somewhat valid, but don't affect any typical behaviour), I think it's worth a fix.

Given the merge to net-next, I assume a patch on top of the series is in order, but let me know if you'd like something else.

Cheers,

Jeremy