Skip to content

Commit 85b5efb

Browse files
committed
mctpd: remove_peer if get endpoint id fails
method_net_learn_endpoint shall only keep the peer which is alive (responds to the query_get_endpoint_id). Tested: busctl call au.com.codeconstruct.MCTP1 /au/com/codeconstruct/mctp1/networks/1 au.com.codeconstruct.MCTP.Network1 LearnEndpoint y 8 sb "/au/com/codeconstruct/mctp1/networks/1/endpoints/8" false busctl call au.com.codeconstruct.MCTP1 /au/com/codeconstruct/mctp1/networks/1 au.com.codeconstruct.MCTP.Network1 LearnEndpoint y 9 Call failed: MCTP Endpoint did not respond busctl call au.com.codeconstruct.MCTP1 /au/com/codeconstruct/mctp1/networks/1 au.com.codeconstruct.MCTP.Network1 LearnEndpoint y 10 sb "/au/com/codeconstruct/mctp1/networks/1/endpoints/10" true busctl call au.com.codeconstruct.MCTP1 /au/com/codeconstruct/mctp1/networks/1 au.com.codeconstruct.MCTP.Network1 LearnEndpoint y 15 Call failed: Request failed Signed-off-by: Jinliang Wang <jinliangw@google.com>
1 parent 3506e7d commit 85b5efb

File tree

1 file changed

+31
-6
lines changed

1 file changed

+31
-6
lines changed

src/mctpd.c

Lines changed: 31 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2242,7 +2242,7 @@ static void set_berr(struct ctx *ctx, int errcode, sd_bus_error *berr)
22422242

22432243
static int query_get_endpoint_id(struct ctx *ctx, const dest_phys *dest,
22442244
mctp_eid_t *ret_eid, uint8_t *ret_ep_type,
2245-
uint8_t *ret_media_spec)
2245+
uint8_t *ret_media_spec, struct peer *peer)
22462246
{
22472247
struct sockaddr_mctp_ext addr;
22482248
struct mctp_ctrl_cmd_get_eid req = { 0 };
@@ -2257,8 +2257,13 @@ static int query_get_endpoint_id(struct ctx *ctx, const dest_phys *dest,
22572257
mctp_ctrl_msg_hdr_init_req(&req.ctrl_hdr, iid,
22582258
MCTP_CTRL_CMD_GET_ENDPOINT_ID);
22592259

2260-
rc = endpoint_query_phys(ctx, dest, MCTP_CTRL_HDR_MSG_TYPE, &req,
2261-
sizeof(req), &buf, &buf_size, &addr);
2260+
if (peer)
2261+
rc = endpoint_query_peer(peer, MCTP_CTRL_HDR_MSG_TYPE, &req,
2262+
sizeof(req), &buf, &buf_size, &addr);
2263+
else
2264+
rc = endpoint_query_phys(ctx, dest, MCTP_CTRL_HDR_MSG_TYPE,
2265+
&req, sizeof(req), &buf, &buf_size,
2266+
&addr);
22622267
if (rc < 0)
22632268
goto out;
22642269

@@ -2293,7 +2298,8 @@ static int get_endpoint_peer(struct ctx *ctx, sd_bus_error *berr,
22932298
int rc;
22942299

22952300
*ret_peer = NULL;
2296-
rc = query_get_endpoint_id(ctx, dest, &eid, &ep_type, &medium_spec);
2301+
rc = query_get_endpoint_id(ctx, dest, &eid, &ep_type, &medium_spec,
2302+
/*peer=*/NULL);
22972303
if (rc)
22982304
return rc;
22992305

@@ -2559,7 +2565,8 @@ static int method_setup_endpoint(sd_bus_message *call, void *data,
25592565
}
25602566

25612567
/* Get Endpoint ID */
2562-
rc = query_get_endpoint_id(ctx, dest, &eid, &ep_type, &medium_spec);
2568+
rc = query_get_endpoint_id(ctx, dest, &eid, &ep_type, &medium_spec,
2569+
/*peer=*/NULL);
25632570
if (rc)
25642571
goto err;
25652572

@@ -3144,7 +3151,7 @@ static int peer_endpoint_recover(sd_event_source *s, uint64_t usec,
31443151
*/
31453152
rc = query_get_endpoint_id(ctx, &peer->phys, &peer->recovery.eid,
31463153
&peer->recovery.endpoint_type,
3147-
&peer->recovery.medium_spec);
3154+
&peer->recovery.medium_spec, /*peer=*/NULL);
31483155
if (rc < 0) {
31493156
goto reschedule;
31503157
}
@@ -3342,6 +3349,8 @@ static int method_net_learn_endpoint(sd_bus_message *call, void *data,
33423349
mctp_eid_t eid = 0;
33433350
struct peer *peer;
33443351
int rc;
3352+
mctp_eid_t ret_eid;
3353+
uint8_t ret_ep_type, ret_medium_spec;
33453354

33463355
rc = sd_bus_message_read(call, "y", &eid);
33473356
if (rc < 0)
@@ -3359,6 +3368,18 @@ static int method_net_learn_endpoint(sd_bus_message *call, void *data,
33593368
goto err;
33603369
}
33613370

3371+
rc = query_get_endpoint_id(peer->ctx, &dest, &ret_eid, &ret_ep_type,
3372+
&ret_medium_spec, peer);
3373+
if (rc) {
3374+
warnx("Error getting endpoint id for %s. error %d %s",
3375+
peer_tostr(peer), rc, strerror(-rc));
3376+
goto err;
3377+
} else if (ret_eid != eid) {
3378+
warnx("Error getting endpoint eid %u not match expected eid %u.",
3379+
ret_eid, eid);
3380+
goto err;
3381+
}
3382+
33623383
query_peer_properties(peer);
33633384

33643385
publish_peer(peer);
@@ -3368,6 +3389,10 @@ static int method_net_learn_endpoint(sd_bus_message *call, void *data,
33683389
goto err;
33693390
return sd_bus_reply_method_return(call, "sb", peer_path, 1);
33703391
err:
3392+
if (peer) {
3393+
remove_peer(peer);
3394+
}
3395+
33713396
set_berr(ctx, rc, berr);
33723397
return rc;
33733398
}

0 commit comments

Comments
 (0)