From 5c3b15de6cf84f02ef2b759c8762969fe21965b6 Mon Sep 17 00:00:00 2001 From: Jeremy Kerr Date: Thu, 7 Nov 2024 09:30:51 +0800 Subject: [PATCH] mctpd: Fix Message Type Support query In e7d64b0 ("mctpd: check IIDs and opcodes in control protocol responses"), we dropped the store to peer->num_message_types, so endpoints would report support for no types over dbus. Fix the missing store, and add a simple testcase for Get Message Type Support. Reported-by: John Chung Fixes: e7d64b0 ("mctpd: check IIDs and opcodes in control protocol responses") Signed-off-by: Jeremy Kerr --- CHANGELOG.md | 3 +++ src/mctpd.c | 1 + tests/test_mctpd.py | 22 ++++++++++++++++++++++ 3 files changed, 26 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 4c4553a..c926fa3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -13,6 +13,9 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/). 2. Fixed some header includes where we were previously assuming a glibc layout +3. Fixed incorrect setup of peer message type data, where peer endpoints would + report no types supported over dbus. + ### Changed 1. We now enforce IID checks on MCTP control protocol responses; this diff --git a/src/mctpd.c b/src/mctpd.c index 412d720..9a6edb3 100644 --- a/src/mctpd.c +++ b/src/mctpd.c @@ -1809,6 +1809,7 @@ static int query_get_peer_msgtypes(peer *peer) { rc = -ENOMEM; goto out; } + peer->num_message_types = resp->msg_type_count; memcpy(peer->message_types, (void*)(resp+1), resp->msg_type_count); rc = 0; out: diff --git a/tests/test_mctpd.py b/tests/test_mctpd.py index 262917b..53a9768 100644 --- a/tests/test_mctpd.py +++ b/tests/test_mctpd.py @@ -5,6 +5,7 @@ from mctp_test_utils import ( mctpd_mctp_iface_obj, + mctpd_mctp_endpoint_common_obj, mctpd_mctp_endpoint_control_obj ) from conftest import Endpoint, MCTPSockAddr @@ -433,3 +434,24 @@ async def handle_mctp_control(self, sock, src_addr, msg): await mctp.call_learn_endpoint(ep.lladdr) assert str(ex.value) == "Request failed" + +""" Ensure we're parsing Get Message Type Support responses""" +async def test_query_message_types(dbus, mctpd): + iface = mctpd.system.interfaces[0] + ep = mctpd.network.endpoints[0] + ep_types = [0, 1, 5] + ep.types = ep_types + + mctp = await mctpd_mctp_iface_obj(dbus, iface) + + (eid, net, path, new) = await mctp.call_setup_endpoint(ep.lladdr) + + assert eid == ep.eid + + ep = await mctpd_mctp_endpoint_common_obj(dbus, path) + + query_types = list(await ep.get_supported_message_types()) + ep_types.sort() + query_types.sort() + + assert ep_types == query_types