From a3a9304bfe2da1cc7fca224822c29ade50c482d1 Mon Sep 17 00:00:00 2001 From: Jeremy Kerr Date: Wed, 10 Jun 2026 15:02:18 +0800 Subject: [PATCH 1/3] mctpd: remove add_peer_route() from setup_added_peer() setup_added_peer() does a few things: - adds the local route - queries the peer for UUID and message types - publishes the peer to dbus We will need the local route established earlier in some cases, so move this out of setup_added_peer. We have five current callers: - peer_endpoint_poll(), which already relies on a bridge pool route to be present - the endpoint Set Endpoint ID handler, where we add a new add_peer_route() - endpoint_assign_eid(), which already has an add_peer_route() - get_endpoint_peer(), which only needs a route added in some cases, where the endpoint was not previously known (the change_peer_eid() will also set up the new route) - method_setup_endpoint, where we add a new add_peer_route() This involves correcting the route counts in a couple of test cases: these are was expecting two routes to be present (assumed to be the local route and the new peer route), but they are duplicates, as a result of the existing add_peer_route(), setup_added_peer() in the existing Set Endpoint ID handler. Conveniently, the setup_added_peer()'s comment will now match the implementation. Signed-off-by: Jeremy Kerr --- src/mctpd.c | 9 ++++----- tests/test_mctpd.py | 4 ++-- 2 files changed, 6 insertions(+), 7 deletions(-) diff --git a/src/mctpd.c b/src/mctpd.c index 9cd16f3..dd95426 100644 --- a/src/mctpd.c +++ b/src/mctpd.c @@ -899,6 +899,7 @@ static int handle_control_set_endpoint_id(struct ctx *ctx, int sd, rc = add_peer_from_addr(ctx, addr, &peer); if (rc == 0) { + add_peer_route(peer); rc = setup_added_peer(peer); } if (rc < 0) { @@ -2591,6 +2592,8 @@ static int get_endpoint_peer(struct ctx *ctx, sd_bus_error *berr, rc = add_peer(ctx, dest, eid, net, &peer, false); if (rc < 0) return rc; + + add_peer_route(peer); } peer->endpoint_type = ep_type; @@ -2970,6 +2973,7 @@ static int method_setup_endpoint(sd_bus_message *call, void *data, } else if (rc < 0) { goto err; } else { + add_peer_route(peer); peer->endpoint_type = ep_type; peer->medium_spec = medium_spec; rc = setup_added_peer(peer); @@ -3296,11 +3300,6 @@ static int setup_added_peer(struct peer *peer) // this with .SetMTU as needed peer->mtu = mctp_nl_min_mtu_byindex(peer->ctx->nl, peer->phys.ifindex); - // add route before querying for non-bridged endpoints. - // bridged endpoints will use the bridge's pool range route. - if (!is_eid_in_bridge_pool(n, peer->ctx, peer->eid)) - add_peer_route(peer); - rc = query_peer_properties(peer); if (rc < 0) goto out; diff --git a/tests/test_mctpd.py b/tests/test_mctpd.py index 178d4c3..38656f7 100644 --- a/tests/test_mctpd.py +++ b/tests/test_mctpd.py @@ -127,7 +127,7 @@ async def test_setup_endpoint(dbus, mctpd): assert neigh.eid == ep.eid # we should have a route for the new endpoint too - assert len(mctpd.system.routes) == 2 + assert len(mctpd.system.routes) == 1 async def test_setup_endpoint_conflict(dbus, mctpd): @@ -356,7 +356,7 @@ async def test_assign_endpoint_static(dbus, mctpd): neigh = mctpd.system.neighbours[0] assert neigh.lladdr == dev.lladdr assert neigh.eid == static_eid - assert len(mctpd.system.routes) == 2 + assert len(mctpd.system.routes) == 1 async def test_assign_endpoint_static_allocated(dbus, mctpd): From 59b3ec09fb0ba56f92fd469f76da3884952d4f2a Mon Sep 17 00:00:00 2001 From: Jeremy Kerr Date: Wed, 10 Jun 2026 11:15:51 +0800 Subject: [PATCH 2/3] mctpd: respond to endpoint Set EID requests before enumerating peer The peer setup will issue queries to the (bus owner) peer, and we will block waiting on responses to those. Respond to the Set Endpoint ID command first, then perform the queries. Reported-by: Nidhin MS Signed-off-by: Jeremy Kerr --- src/mctpd.c | 36 ++++++++++++++++++++++++++---------- 1 file changed, 26 insertions(+), 10 deletions(-) diff --git a/src/mctpd.c b/src/mctpd.c index dd95426..33cca57 100644 --- a/src/mctpd.c +++ b/src/mctpd.c @@ -894,28 +894,44 @@ static int handle_control_set_endpoint_id(struct ctx *ctx, int sd, if (rc < 0) { warnx("ERR: cannot add local eid %d to ifindex %d", req->eid, addr->smctp_ifindex); + resp_len = sizeof(struct mctp_ctrl_resp); resp->completion_code = MCTP_CTRL_CC_ERROR_NOT_READY; + reply_message(ctx, sd, resp, resp_len, addr); + return rc; } rc = add_peer_from_addr(ctx, addr, &peer); - if (rc == 0) { - add_peer_route(peer); - rc = setup_added_peer(peer); - } - if (rc < 0) { - warnx("ERR: cannot add bus owner to object lists"); + if (rc) { + errno = -rc; + warn("failed setting up bus owner, rejecting Set EID"); + resp->completion_code = MCTP_CTRL_CC_ERROR; + resp_len = sizeof(struct mctp_ctrl_resp); + reply_message(ctx, sd, resp, resp_len, addr); + return rc; } - if (link_data->discovered != DISCOVERY_UNSUPPORTED) { + add_peer_route(peer); + + if (link_data->discovered != DISCOVERY_UNSUPPORTED) link_data->discovered = DISCOVERY_DISCOVERED; - } + resp->status = SET_MCTP_EID_ASSIGNMENT_STATUS(MCTP_SET_EID_ACCEPTED) | SET_MCTP_EID_ALLOCATION_STATUS(MCTP_SET_EID_POOL_NONE); resp->eid_set = req->eid; resp->eid_pool_size = 0; - fprintf(stderr, "Accepted set eid %d\n", req->eid); - return reply_message(ctx, sd, resp, resp_len, addr); + rc = reply_message(ctx, sd, resp, resp_len, addr); + if (rc) { + errno = -rc; + warn("failed responding to set eid request"); + return rc; + } + + rc = setup_added_peer(peer); + if (rc < 0) + warnx("ERR: cannot add bus owner to object lists"); + + return 0; case MCTP_SET_EID_DISCOVERED: if (link_data->discovered == DISCOVERY_UNSUPPORTED) { From 4e1426ce14d38dbd3bfbfdb771c1ede874bd7be8 Mon Sep 17 00:00:00 2001 From: Jeremy Kerr Date: Thu, 11 Jun 2026 18:12:50 +0800 Subject: [PATCH 3/3] CHANGELOG: add entry for Set Endpoint ID sequencing item Signed-off-by: Jeremy Kerr --- CHANGELOG.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index e22e5f5..07c2db2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -38,6 +38,10 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/). re-use outgoing control protocol instance IDs (IIDs) when we re-send commands. More instances of commands now have retry logic too. +3. When running in endpoint mode, `mctpd` will now issue responses to incoming + Set Endpoint ID commands before performing enumeration on the (bus-owner) + peer. + ## [2.5] - 2026-02-17 ### Added