Skip to content

Commit 65dcb8f

Browse files
committed
mctpd: Add Network1.LearnEndpoint
Our current support for bridged endpoints requires static EIDs to be allocated in advance. To handle that case, add a new dbus call: LearnEndpoint, on the net object (au.com.codeconstruct.MCTP.Network1). This takes an EID, performs a discovery query, and publishes a new endpoint object if that query was sucessful. This allows dbus clients to enumerate briged EPs. Signed-off-by: Jeremy Kerr <jk@codeconstruct.com.au>
1 parent 5a474e0 commit 65dcb8f

File tree

4 files changed

+83
-2
lines changed

4 files changed

+83
-2
lines changed

CHANGELOG.md

+5-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,11 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
1111
1. New debug tool, `mctp-bench`, for sending and receiving a stream of MCTP
1212
messages between two processes.
1313

14-
2. mctpd: Add `au.com.codeconstruct.MCTP.Network1` interface
14+
2. mctpd: Add `au.com.codeconstruct.MCTP.Network1` interface, including
15+
- a `LocalEIDs` property, representing the local EIDs assigned on this
16+
network
17+
- a `LearnEndpoint` method, for enumerating endpoints that already have an
18+
address assigned, and are routable
1519

1620
3. tests: the fake mctp environment can now be run standalone, allowing
1721
experimentation with different system and network configurations

docs/mctpd.md

+12-1
Original file line numberDiff line numberDiff line change
@@ -156,11 +156,22 @@ All MCTP networks objects host the `au.com.codeconstruct.MCTP.Network1` dbus
156156
interface:
157157

158158
```
159-
NAME TYPE SIGNATURE RESULT/VALUE FLAGS
159+
NAME TYPE SIGNATURE RESULT/VALUE FLAGS
160160
au.com.codeconstruct.MCTP.Network1 interface - - -
161+
.LearnEndpoint method y sb -
161162
.LocalEIDs property ay 1 8 const
162163
```
163164

165+
### `.LearnEndpoint`: `y`
166+
167+
The `LearnEndpoint` method allows a caller to perform enumeration of a
168+
static endpoint that we can already route to. This may be useful to discover
169+
bridged endpoints, where the EID assigment has already been handled by the
170+
bridge.
171+
172+
`LearnEndpoint` takes an EID as its only argument, and returns the endpoint's
173+
path, and a boolean indicating whether the endpoint was newly discovered.
174+
164175
The D-Bus interface includes the `LocalEIDs` property which reports BMC local EIDs
165176
in the network.
166177

src/mctpd.c

+48
Original file line numberDiff line numberDiff line change
@@ -2731,6 +2731,46 @@ static int method_endpoint_set_mtu(sd_bus_message *call, void *data,
27312731
return rc;
27322732
}
27332733

2734+
static int method_net_learn_endpoint(sd_bus_message *call, void *data,
2735+
sd_bus_error *berr)
2736+
{
2737+
const char *peer_path = NULL;
2738+
struct net *net = data;
2739+
struct ctx *ctx = net->ctx;
2740+
dest_phys dest = { 0 };
2741+
mctp_eid_t eid = 0;
2742+
struct peer *peer;
2743+
int rc;
2744+
2745+
rc = sd_bus_message_read(call, "y", &eid);
2746+
if (rc < 0)
2747+
goto err;
2748+
2749+
peer = find_peer_by_addr(ctx, eid, net->net);
2750+
/* already known? */
2751+
if (peer)
2752+
return sd_bus_reply_method_return(call, "sb",
2753+
path_from_peer(peer), false);
2754+
2755+
rc = add_peer(ctx, &dest, eid, net->net, &peer);
2756+
if (rc) {
2757+
warnx("can't add peer: %s", strerror(-rc));
2758+
goto err;
2759+
}
2760+
2761+
query_peer_properties(peer);
2762+
2763+
publish_peer(peer, false);
2764+
2765+
peer_path = path_from_peer(peer);
2766+
if (!peer_path)
2767+
goto err;
2768+
return sd_bus_reply_method_return(call, "sb", peer_path, 1);
2769+
err:
2770+
set_berr(ctx, rc, berr);
2771+
return rc;
2772+
}
2773+
27342774
// Testing code
27352775
static int cb_test_timer(sd_event_source *s, uint64_t t, void* data)
27362776
{
@@ -3110,6 +3150,14 @@ static const sd_bus_vtable bus_link_vtable[] = {
31103150

31113151
static const sd_bus_vtable bus_network_vtable[] = {
31123152
SD_BUS_VTABLE_START(0),
3153+
SD_BUS_METHOD_WITH_NAMES("LearnEndpoint",
3154+
"y",
3155+
SD_BUS_PARAM(physaddr),
3156+
"sb",
3157+
SD_BUS_PARAM(path)
3158+
SD_BUS_PARAM(found),
3159+
method_net_learn_endpoint,
3160+
0),
31133161
SD_BUS_PROPERTY("LocalEIDs",
31143162
"ay",
31153163
bus_network_get_prop,

tests/test_mctpd.py

+18
Original file line numberDiff line numberDiff line change
@@ -483,3 +483,21 @@ async def test_network_local_eids_none(dbus, mctpd):
483483
eids = list(await net.get_local_eids())
484484

485485
assert eids == []
486+
487+
""" Bridged EP can be discovered via Network1.LearnEndpoint """
488+
async def test_bridged_learn_endpoint(dbus, mctpd):
489+
iface = mctpd.system.interfaces[0]
490+
ep = mctpd.network.endpoints[0]
491+
br_ep = Endpoint(iface, bytes(), eid = 10, types = [0, 2])
492+
ep.add_bridged_ep(br_ep)
493+
mctpd.network.add_endpoint(br_ep)
494+
495+
await mctpd.system.add_route(mctpd.system.Route(iface, br_ep.eid, 1))
496+
# static neighbour; no gateway route support at present
497+
await mctpd.system.add_neighbour(mctpd.system.Neighbour(iface, ep.lladdr, br_ep.eid))
498+
499+
net = await mctpd_mctp_network_obj(dbus, iface.net)
500+
(path, new) = await net.call_learn_endpoint(br_ep.eid)
501+
502+
assert path == f'/au/com/codeconstruct/mctp1/networks/1/endpoints/{br_ep.eid}'
503+
assert new

0 commit comments

Comments
 (0)