From 29936ec4089980ac7cf6c6fd3df4964c36633056 Mon Sep 17 00:00:00 2001 From: Thu Nguyen Date: Thu, 6 Jun 2024 23:43:09 +0000 Subject: [PATCH] mctpd: enumerate /networks and /endpoints object paths Enumerate the parent D-Bus object path `.../mctp1/networks` for the network paths `.../mctp1/networks/` and `.../mctp1/networks//endpoints` for the endpoints path `.../mctp1/networks//endpoints/`. Tested: Check the MCTP D-Bus interface: ``` busctl tree au.com.codeconstruct.MCTP1 `- /au `- /au/com `- /au/com/codeconstruct `- /au/com/codeconstruct/mctp1 `- /au/com/codeconstruct/mctp1/networks `- /au/com/codeconstruct/mctp1/networks/1 `- /au/com/codeconstruct/mctp1/networks/1/endpoints `- /au/com/codeconstruct/mctp1/networks/1/endpoints/8 ``` Signed-off-by: Thu Nguyen --- src/mctpd.c | 77 ++++++++++++++++++++++++++++++++++++++++++++--------- 1 file changed, 64 insertions(+), 13 deletions(-) diff --git a/src/mctpd.c b/src/mctpd.c index 867fdb7..2be12d3 100644 --- a/src/mctpd.c +++ b/src/mctpd.c @@ -41,6 +41,7 @@ #define min(a, b) ((a) < (b) ? (a) : (b)) #define MCTP_DBUS_PATH "/au/com/codeconstruct/mctp1" +#define MCTP_DBUS_PATH_NETWORKS "/au/com/codeconstruct/mctp1/networks" #define CC_MCTP_DBUS_IFACE_BUSOWNER "au.com.codeconstruct.MCTP.BusOwner1.DRAFT" #define CC_MCTP_DBUS_IFACE_ENDPOINT "au.com.codeconstruct.MCTP.Endpoint1" #define CC_MCTP_DBUS_IFACE_TESTING "au.com.codeconstruct.MCTPTesting" @@ -2901,6 +2902,20 @@ static int bus_endpoint_find_uuid(sd_bus *bus, const char *path, return 0; } +static char* root_endpoints_path(int net) +{ + size_t l; + char *buf = NULL; + + l = strlen(MCTP_DBUS_PATH) + 30; + buf = malloc(l); + if (!buf) { + return NULL; + } + snprintf(buf, l, "%s/networks/%d/endpoints", MCTP_DBUS_PATH, net); + return buf; +} + static char* net_path(int net) { size_t l; @@ -2998,15 +3013,28 @@ static int mctpd_dbus_enumerate(sd_bus *bus, const char* path, // NULL terminator num_nodes = 1; - // .../mctp object + // .../mctp1 object + num_nodes++; + // .../mctp1/networks object num_nodes++; + // .../mctp1/networks/ + for (i = 0; i < ctx->num_nets; i++) { + num_nodes++; + for (size_t t = 0; t < 256; t++) { + if (ctx->nets[i].peeridx[t] != -1) { + // .../mctp1/networks//endpoints object + num_nodes++; + break; + } + } + } + + // .../mctp1/networks//endpoints/ object for (i = 0; i < ctx->size_peers; i++) if (ctx->peers[i].published) num_nodes++; - num_nodes += ctx->num_nets; - nodes = malloc(sizeof(*nodes) * num_nodes); if (!nodes) { rc = -ENOMEM; @@ -3014,6 +3042,7 @@ static int mctpd_dbus_enumerate(sd_bus *bus, const char* path, } j = 0; + // .../mctp1 nodes[j] = strdup(MCTP_DBUS_PATH); if (!nodes[j]) { rc = -ENOMEM; @@ -3021,6 +3050,38 @@ static int mctpd_dbus_enumerate(sd_bus *bus, const char* path, } j++; + // .../mctp1/networks + nodes[j] = strdup(MCTP_DBUS_PATH_NETWORKS); + if (!nodes[j]) { + rc = -ENOMEM; + goto out; + } + j++; + + for (i = 0; i < ctx->num_nets; i++) { + // .../mctp1/networks/ + nodes[j] = net_path(ctx->nets[i].net); + if (nodes[j] == NULL) { + rc = -ENOMEM; + goto out; + } + j++; + + for (size_t t = 0; t < 256; t++) { + if (ctx->nets[i].peeridx[t] == -1) { + continue; + } + // .../mctp1/networks//endpoints object + nodes[j] = root_endpoints_path(ctx->nets[i].net); + if (nodes[j] == NULL) { + rc = -ENOMEM; + goto out; + } + j++; + break; + } + } + // Peers for (i = 0; i < ctx->size_peers; i++) { peer *peer = &ctx->peers[i]; @@ -3034,16 +3095,6 @@ static int mctpd_dbus_enumerate(sd_bus *bus, const char* path, j++; } - // Nets - for (i = 0; i < ctx->num_nets; i++) { - nodes[j] = net_path(ctx->nets[i].net); - if (nodes[j] == NULL) { - rc = -ENOMEM; - goto out; - } - j++; - } - // NULL terminator nodes[j] = NULL; j++;