Skip to content

Commit

Permalink
mctpd: conf: use a set of role descriptions for parsing the mode conf…
Browse files Browse the repository at this point in the history
…ig values

Rather than hard-coding the mode types in the config parsing, move these
to an array of role descriptions, and parse from that.

This will be used in an upcoming change where we parse roles from dbus
properties too.

Signed-off-by: Jeremy Kerr <[email protected]>
  • Loading branch information
jk-ozlabs committed Jun 29, 2024
1 parent 597f40a commit c9ad1be
Showing 1 changed file with 37 additions and 8 deletions.
45 changes: 37 additions & 8 deletions src/mctpd.c
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,31 @@ struct ctx;
// all local peers have the same phys
static const dest_phys local_phys = { .ifindex = 0 };

enum endpoint_role {
ENDPOINT_ROLE_UNKNOWN,
ENDPOINT_ROLE_BUS_OWNER,
ENDPOINT_ROLE_ENDPOINT,
};

struct role {
enum endpoint_role role;
const char *conf_val;
};

static const struct role roles[] = {
[ENDPOINT_ROLE_UNKNOWN] = {
.role = ENDPOINT_ROLE_UNKNOWN,
},
[ENDPOINT_ROLE_BUS_OWNER] = {
.role = ENDPOINT_ROLE_BUS_OWNER,
.conf_val = "bus-owner",
},
[ENDPOINT_ROLE_ENDPOINT] = {
.role = ENDPOINT_ROLE_ENDPOINT,
.conf_val = "endpoint",
},
};

struct peer {
int net;
mctp_eid_t eid;
Expand Down Expand Up @@ -3592,16 +3617,20 @@ static int parse_args(ctx *ctx, int argc, char **argv)

static int parse_config_mode(ctx *ctx, const char *mode)
{
if (!strcmp(mode, "bus-owner")) {
ctx->bus_owner = true;
} else if (!strcmp(mode, "endpoint")) {
ctx->bus_owner = false;
} else {
warnx("invalid value '%s' for mode configuration", mode);
return -1;
unsigned int i;

for (i = 0; i < ARRAY_SIZE(roles); i++) {
const struct role *role = &roles[i];

if (!role->conf_val || strcmp(role->conf_val, mode))
continue;

ctx->bus_owner = role->role == ENDPOINT_ROLE_BUS_OWNER;
return 0;
}

return 0;
warnx("invalid value '%s' for mode configuration", mode);
return -1;
}

static int fill_uuid(ctx *ctx)
Expand Down

0 comments on commit c9ad1be

Please sign in to comment.