Skip to content

Commit

Permalink
mctpd: enumerate /networks and /endpoints object paths
Browse files Browse the repository at this point in the history
Enumerate the parent D-Bus object path `.../mctp1/networks` for the
network paths `.../mctp1/networks/<NetID>` and
`.../mctp1/networks/<NetID>/endpoints` for the endpoints path
`.../mctp1/networks/<NetID>/endpoints/<EID>`.

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 <[email protected]>
Signed-off-by: Jeremy Kerr <[email protected]>
  • Loading branch information
ThuBaNguyen authored and jk-ozlabs committed Jun 10, 2024
1 parent 9ed35ed commit 768b4d5
Showing 1 changed file with 64 additions and 13 deletions.
77 changes: 64 additions & 13 deletions src/mctpd.c
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -2998,29 +3013,75 @@ 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/<NetID>
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/<NetID>/endpoints object
num_nodes++;
break;
}
}
}

// .../mctp1/networks/<NetID>/endpoints/<EID> 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;
goto out;
}

j = 0;
// .../mctp1
nodes[j] = strdup(MCTP_DBUS_PATH);
if (!nodes[j]) {
rc = -ENOMEM;
goto out;
}
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/<NetId>
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/<NetID>/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];
Expand All @@ -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++;
Expand Down

0 comments on commit 768b4d5

Please sign in to comment.