Skip to content

Commit e3021b6

Browse files
mctpd: respond to Get EID using physical addressing
Currently, mctpd running as an endpoint with no EID set cannot reply to Get EID message, due to having no routing knowledge and we currently use EID-based routing for the response. This uses physical addressing for Get Endpoint message. Signed-off-by: Khang D Nguyen <[email protected]>
1 parent 9c2adf0 commit e3021b6

File tree

2 files changed

+48
-3
lines changed

2 files changed

+48
-3
lines changed

src/mctpd.c

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -570,6 +570,29 @@ static int read_message(struct ctx *ctx, int sd, uint8_t **ret_buf, size_t *ret_
570570
return rc;
571571
}
572572

573+
/* Replies to a physical address */
574+
static int reply_message_phys(struct ctx *ctx, int sd, const void *resp, size_t resp_len,
575+
const struct sockaddr_mctp_ext *addr)
576+
{
577+
ssize_t len;
578+
struct sockaddr_mctp_ext reply_addr = *addr;
579+
580+
reply_addr.smctp_base.smctp_tag &= ~MCTP_TAG_OWNER;
581+
582+
len = mctp_ops.mctp.sendto(sd, resp, resp_len, 0,
583+
(struct sockaddr *)&reply_addr,
584+
sizeof(reply_addr));
585+
if (len < 0) {
586+
return -errno;
587+
}
588+
589+
if ((size_t)len != resp_len) {
590+
bug_warn("short sendto %zd, expected %zu", len, resp_len);
591+
return -EPROTO;
592+
}
593+
return 0;
594+
}
595+
573596
/* Replies to a real EID, not physical addressing */
574597
static int reply_message(struct ctx *ctx, int sd, const void *resp, size_t resp_len,
575598
const struct sockaddr_mctp_ext *addr)
@@ -694,7 +717,8 @@ static int handle_control_get_endpoint_id(struct ctx *ctx,
694717
SET_ENDPOINT_ID_TYPE(resp->eid_type, 2);
695718
// TODO: medium specific information
696719

697-
return reply_message(ctx, sd, resp, sizeof(*resp), addr);
720+
// Get Endpoint ID is typically send and reply using physical addressing.
721+
return reply_message_phys(ctx, sd, resp, sizeof(*resp), addr);
698722
}
699723

700724
static int handle_control_get_endpoint_uuid(struct ctx *ctx,

tests/test_mctpd_endpoint.py

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,35 @@
22
from mctp_test_utils import *
33
from mctpd import *
44

5-
@pytest.fixture(name="config")
6-
def endpoint_config():
5+
@pytest.fixture
6+
def config():
77
return """
88
mode = "endpoint"
99
"""
1010

11+
@pytest.fixture
12+
async def sysnet():
13+
system = System()
14+
iface = System.Interface("mctp0", 1, 1, bytes([0x1D]), 68, 254, True)
15+
await system.add_interface(iface)
16+
network = Network()
17+
network.add_endpoint(Endpoint(iface, bytes([0x10]), eid=8))
18+
return Sysnet(system, network)
19+
20+
1121
""" Test if mctpd is running as an endpoint """
1222
async def test_endpoint_role(dbus, mctpd):
1323
obj = await mctpd_mctp_iface_control_obj(dbus, mctpd.system.interfaces[0])
1424
role = await obj.get_role()
1525
assert str(role) == "Endpoint"
26+
27+
28+
""" mctpd returns null EID on no EID """
29+
async def test_respond_get_eid_with_no_eid(dbus, mctpd):
30+
bo = mctpd.network.endpoints[0]
31+
32+
assert len(mctpd.system.addresses) == 0
33+
34+
# no EID yet
35+
rsp = await bo.send_control(mctpd.network.mctp_socket, 0x02)
36+
assert rsp.hex(' ') == '00 02 00 00 02 00'

0 commit comments

Comments
 (0)