From 415b574d866d66c0097f64a2fe79f2a28637ade4 Mon Sep 17 00:00:00 2001 From: Potin Lai Date: Thu, 12 Mar 2026 17:17:48 +0800 Subject: [PATCH] mctpd: allow bridge for assign static endpoint Allow birdge when assigning static enpoint. ``` root@bmc:~# busctl call au.com.codeconstruct.MCTP1 /au/com/codeconstruct/mctp1/interfaces/mcu1u2u1u4u1 au.com.codeconstruct.MCTP.BusOwner1 AssignEndpointStatic ayy 0 30 yisb 30 1 "/au/com/codeconstruct/mctp1/networks/1/endpoints/30" true root@bmc:~# busctl introspect au.com.codeconstruct.MCTP1 /au/com/codeconstruct/mctp1/networks/1/endpoints/30 au.com.codeconstruct.MCTP.Bridge1 NAME TYPE SIGNATURE RESULT/VALUE FLAGS .PoolEnd property y 35 const .PoolStart property y 31 const ``` Signed-off-by: Potin Lai --- src/mctpd.c | 52 +++++++++++++++++++++++++--------------------------- 1 file changed, 25 insertions(+), 27 deletions(-) diff --git a/src/mctpd.c b/src/mctpd.c index cd2b527..3d502da 100644 --- a/src/mctpd.c +++ b/src/mctpd.c @@ -2288,38 +2288,33 @@ static int endpoint_assign_eid(struct ctx *ctx, sd_bus_error *berr, return -EPROTO; } - if (static_eid) { - rc = add_peer(ctx, dest, static_eid, net, &peer, false); - if (rc < 0) - return rc; - - new_eid = static_eid; - } else { - struct eid_allocation alloc; - unsigned int alloc_size = 0; + struct eid_allocation alloc; + unsigned int alloc_size = 0; - if (assign_bridge) - alloc_size = ctx->max_pool_size; + if (assign_bridge) + alloc_size = ctx->max_pool_size; - rc = allocate_eid(ctx, n, alloc_size, &alloc); - if (rc) { - warnx("Cannot allocate any EID (+pool %d) on net %d for %s", - alloc_size, net, dest_phys_tostr(dest)); - sd_bus_error_setf(berr, SD_BUS_ERROR_FAILED, - "Ran out of EIDs"); - return -EADDRNOTAVAIL; - } + rc = allocate_eid(ctx, n, alloc_size, &alloc); + if (rc) { + warnx("Cannot allocate any EID (+pool %d) on net %d for %s", + alloc_size, net, dest_phys_tostr(dest)); + sd_bus_error_setf(berr, SD_BUS_ERROR_FAILED, "Ran out of EIDs"); + return -EADDRNOTAVAIL; + } + if (static_eid) { + new_eid = static_eid; + } else { new_eid = alloc.start; + } - rc = add_peer(ctx, dest, new_eid, net, &peer, false); - if (rc < 0) - return rc; + rc = add_peer(ctx, dest, new_eid, net, &peer, false); + if (rc < 0) + return rc; - peer->pool_size = alloc.extent; - if (peer->pool_size) - peer->pool_start = new_eid + 1; - } + peer->pool_size = alloc.extent; + if (peer->pool_size) + peer->pool_start = new_eid + 1; /* Add a route to the peer prior to assigning it an EID. * The peer may initiate communication immediately, so @@ -3055,7 +3050,7 @@ static int method_assign_endpoint_static(sd_bus_message *call, void *data, } } - rc = endpoint_assign_eid(ctx, berr, dest, &peer, eid, false); + rc = endpoint_assign_eid(ctx, berr, dest, &peer, eid, true); if (rc < 0) { goto err; } @@ -3064,6 +3059,9 @@ static int method_assign_endpoint_static(sd_bus_message *call, void *data, if (!peer_path) goto err; + if (peer->pool_size > 0) + endpoint_allocate_eids(peer); + return sd_bus_reply_method_return(call, "yisb", peer->eid, peer->net, peer_path, 1); err: