Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 26 additions & 2 deletions src/mctpd.c
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@ static const char *conf_file_default = MCTPD_CONF_FILE_DEFAULT;

static const mctp_eid_t eid_alloc_min = 0x08;
static const mctp_eid_t eid_alloc_max = 0xfe;
static const uint8_t MCTP_TYPE_VENDOR_PCIE = 0x7e;
static const uint8_t MCTP_TYPE_VENDOR_IANA = 0x7f;

// arbitrary sanity
static size_t MAX_PEER_SIZE = 1000000;
Expand Down Expand Up @@ -981,6 +983,7 @@ static int handle_control_get_message_type_support(
{
struct mctp_ctrl_resp_get_msg_type_support *resp = NULL;
struct mctp_ctrl_cmd_get_msg_type_support *req = NULL;
bool pcie_support = false, iana_support = false;
size_t i, resp_len, type_count;
uint8_t *resp_buf, *msg_types;
int rc;
Expand All @@ -992,6 +995,21 @@ static int handle_control_get_message_type_support(

req = (void *)buf;
type_count = ctx->num_supported_msg_types;
for (i = 0; i < ctx->num_supported_msg_types; i++) {
pcie_support |= (ctx->supported_msg_types[i].msg_type ==
MCTP_TYPE_VENDOR_PCIE);
iana_support |= (ctx->supported_msg_types[i].msg_type ==
MCTP_TYPE_VENDOR_IANA);
}
Comment on lines +998 to +1003
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wouldn't this duplicate the entries for 0x7e/0x7f in the response?


for (i = 0; i < ctx->num_supported_vdm_types; i++) {
pcie_support |= ctx->supported_vdm_types[i].format ==
VID_FORMAT_PCIE;
iana_support |= ctx->supported_vdm_types[i].format ==
VID_FORMAT_IANA;
}
type_count += (pcie_support + iana_support);

// Allocate extra space for the message types
resp_len = sizeof(*resp) + type_count;
resp_buf = malloc(resp_len);
Expand All @@ -1004,13 +1022,19 @@ static int handle_control_get_message_type_support(
mctp_ctrl_msg_hdr_init_resp(&resp->ctrl_hdr, req->ctrl_hdr);
resp->completion_code = MCTP_CTRL_CC_SUCCESS;

resp->msg_type_count = type_count;
// Append message types after msg_type_count
msg_types = (uint8_t *)(resp + 1);
for (i = 0; i < type_count; i++) {
for (i = 0; i < ctx->num_supported_msg_types; i++) {
msg_types[i] = ctx->supported_msg_types[i].msg_type;
}
if (pcie_support) {
msg_types[i++] = MCTP_TYPE_VENDOR_PCIE;
}
if (iana_support) {
msg_types[i++] = MCTP_TYPE_VENDOR_IANA;
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What if someone has already registered 7e/7f ?

Doing the find (setting the booleans) and message construction (setting msg_types) in the same place is a bit unusual.

If you're taking the approach that 7e/7f do not appear in the supported_message_types array, then I would suggest detecting their presence earlier (ie, iterating supported_vdm_types there), which means you can then allocate exactly the correct size message, then do the message construction later, based on the earlier detection.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think 7e or 7f can come in supported_message_types .
Updates the checks


resp->msg_type_count = type_count;
rc = reply_message(ctx, sd, resp, resp_len, addr);
free(resp_buf);

Expand Down
10 changes: 10 additions & 0 deletions tests/test_mctpd.py
Original file line number Diff line number Diff line change
Expand Up @@ -1342,6 +1342,11 @@ async def test_register_vdm_type_support_dbus_disconnect(mctpd, routed_ep):
rsp = await ep.send_control(mctpd.network.mctp_socket, cmd)
assert rsp.hex(' ') == '00 06 00 ff 00 ab cd 00 01'

# Verify GetMsgType includes VDM
cmd = MCTPControlCommand(True, 0, 0x05)
rsp = await ep.send_control(mctpd.network.mctp_socket, cmd)
assert rsp.hex(' ') == '00 05 00 02 00 7e'

# Give mctpd a moment to process the disconnection
await trio.sleep(0.1)

Expand All @@ -1350,6 +1355,11 @@ async def test_register_vdm_type_support_dbus_disconnect(mctpd, routed_ep):
rsp = await ep.send_control(mctpd.network.mctp_socket, cmd)
assert rsp.hex(' ') == '00 06 02' # Should be error again

# Verify GetMsgType has only control command
cmd = MCTPControlCommand(True, 0, 0x05)
rsp = await ep.send_control(mctpd.network.mctp_socket, cmd)
assert rsp.hex(' ') == '00 05 00 01 00'

""" Test RegisterVDMTypeSupport error handling """
async def test_register_vdm_type_support_errors(dbus, mctpd):
mctp = await mctpd_mctp_base_iface_obj(dbus)
Expand Down