Skip to content

Commit a118274

Browse files
Add Bridge Endpoint Support
* Update peer structure to accomodate for Bridge Type Endpoints. * New Dbus method AssignBridgeStatic to assign static EndpointID to MCTP bridge/pool with start of pool and pool size as arguments for AllocateEndpointID control command Signed-off-by: Faizan Ali <[email protected]>
1 parent f5bb279 commit a118274

File tree

1 file changed

+113
-4
lines changed

1 file changed

+113
-4
lines changed

src/mctpd.c

Lines changed: 113 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,11 @@ struct peer {
189189
uint8_t endpoint_type;
190190
uint8_t medium_spec;
191191
} recovery;
192+
193+
// Pool size
194+
uint8_t pool_size;
195+
uint8_t pool_start;
196+
192197
};
193198

194199
struct ctx {
@@ -1299,7 +1304,7 @@ static int endpoint_query_phys(struct ctx *ctx, const dest_phys *dest,
12991304
}
13001305

13011306
/* returns -ECONNREFUSED if the endpoint returns failure. */
1302-
static int endpoint_send_set_endpoint_id(const struct peer *peer, mctp_eid_t *new_eid)
1307+
static int endpoint_send_set_endpoint_id(struct peer *peer, mctp_eid_t *new_eid)
13031308
{
13041309
struct sockaddr_mctp_ext addr;
13051310
struct mctp_ctrl_cmd_set_eid req = {0};
@@ -1346,9 +1351,11 @@ static int endpoint_send_set_endpoint_id(const struct peer *peer, mctp_eid_t *ne
13461351

13471352
alloc = resp->status & 0x3;
13481353
if (alloc != 0) {
1349-
// TODO for bridges
1350-
warnx("%s requested allocation pool, unimplemented",
1351-
dest_phys_tostr(dest));
1354+
peer->pool_size = resp->eid_pool_size;
1355+
if (peer->ctx->verbose) {
1356+
warnx("%s requested allocation of pool size = %d",
1357+
dest_phys_tostr(dest), peer->pool_size);
1358+
}
13521359
}
13531360

13541361
rc = 0;
@@ -2201,6 +2208,95 @@ static int method_learn_endpoint(sd_bus_message *call, void *data, sd_bus_error
22012208
return rc;
22022209
}
22032210

2211+
static int method_assign_bridge_static(sd_bus_message *call, void *data,
2212+
sd_bus_error *berr)
2213+
{
2214+
char *peer_path = NULL;
2215+
dest_phys desti, *dest = &desti;
2216+
struct link *link = data;
2217+
struct ctx *ctx = link->ctx;
2218+
struct peer *peer = NULL;
2219+
uint8_t eid, pool_start, pool_size;
2220+
int rc;
2221+
2222+
dest->ifindex = link->ifindex;
2223+
if (dest->ifindex <= 0)
2224+
return sd_bus_error_setf(berr, SD_BUS_ERROR_INVALID_ARGS,
2225+
"Unknown MCTP interface");
2226+
2227+
rc = message_read_hwaddr(call, dest);
2228+
if (rc < 0)
2229+
goto err;
2230+
2231+
rc = sd_bus_message_read(call, "y", &eid);
2232+
if (rc < 0)
2233+
goto err;
2234+
2235+
rc = sd_bus_message_read(call, "y", &pool_start);
2236+
if (rc < 0)
2237+
goto err;
2238+
2239+
rc = sd_bus_message_read(call, "y", &pool_size);
2240+
if (rc < 0)
2241+
goto err;
2242+
2243+
rc = validate_dest_phys(ctx, dest);
2244+
if (rc < 0)
2245+
return sd_bus_error_setf(berr, SD_BUS_ERROR_INVALID_ARGS,
2246+
"Bad physaddr");
2247+
2248+
peer = find_peer_by_phys(ctx, dest);
2249+
if (peer) {
2250+
if (peer->eid != eid) {
2251+
return sd_bus_error_setf(berr, SD_BUS_ERROR_INVALID_ARGS,
2252+
"Already assigned a different EID");
2253+
}
2254+
2255+
// Return existing record.
2256+
peer_path = path_from_peer(peer);
2257+
if (!peer_path)
2258+
goto err;
2259+
2260+
return sd_bus_reply_method_return(call, "yisb",
2261+
peer->eid, peer->net, peer_path, 0);
2262+
} else {
2263+
uint32_t netid;
2264+
2265+
// is the requested EID already in use? if so, reject
2266+
netid = mctp_nl_net_byindex(ctx->nl, dest->ifindex);
2267+
peer = find_peer_by_addr(ctx, eid, netid);
2268+
if (peer) {
2269+
return sd_bus_error_setf(berr, SD_BUS_ERROR_INVALID_ARGS,
2270+
"Address in use");
2271+
}
2272+
}
2273+
2274+
rc = endpoint_assign_eid(ctx, berr, dest, &peer, eid);
2275+
if (rc < 0) {
2276+
goto err;
2277+
}
2278+
2279+
peer_path = path_from_peer(peer);
2280+
if (!peer_path) {
2281+
goto err;
2282+
}
2283+
2284+
if(peer->pool_size > 0) {
2285+
peer->pool_start = pool_start;
2286+
if(peer->pool_size && peer->pool_size > pool_size) {
2287+
peer->pool_size = pool_size;
2288+
2289+
//call for Allocate EndpointID
2290+
}
2291+
}
2292+
2293+
return sd_bus_reply_method_return(call, "yisb",
2294+
peer->eid, peer->net, peer_path, 1);
2295+
err:
2296+
set_berr(ctx, rc, berr);
2297+
return rc;
2298+
}
2299+
22042300
// Query various properties of a peer.
22052301
// To be called when a new peer is discovered/assigned, once an EID is known
22062302
// and routable.
@@ -2760,6 +2856,19 @@ static const sd_bus_vtable bus_link_owner_vtable[] = {
27602856
SD_BUS_PARAM(found),
27612857
method_learn_endpoint,
27622858
0),
2859+
SD_BUS_METHOD_WITH_NAMES("AssignBridgeStatic",
2860+
"ayyyy",
2861+
SD_BUS_PARAM(physaddr)
2862+
SD_BUS_PARAM(eid)
2863+
SD_BUS_PARAM(pool_start)
2864+
SD_BUS_PARAM(pool_size),
2865+
"yisb",
2866+
SD_BUS_PARAM(eid)
2867+
SD_BUS_PARAM(net)
2868+
SD_BUS_PARAM(path)
2869+
SD_BUS_PARAM(new),
2870+
method_assign_bridge_static,
2871+
0),
27632872
SD_BUS_VTABLE_END,
27642873

27652874
};

0 commit comments

Comments
 (0)