Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion modules/infra/api/gr_infra.h
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ struct gr_iface {

#define GR_IFACE_NAME_SIZE 64
char name[GR_IFACE_NAME_SIZE]; // Interface name (utf-8 encoded, nul terminated).
uint8_t info[256]; // Type specific interface info.
uint8_t info[512]; // Placeholder for type specific interface info.
};

void register_interface_mode(gr_iface_mode_t mode, const char *next_node);
Expand Down Expand Up @@ -101,6 +101,8 @@ struct gr_iface_info_port {
char devargs[GR_PORT_DEVARGS_SIZE];
#define GR_PORT_DRIVER_NAME_SIZE 32
char driver_name[GR_PORT_DRIVER_NAME_SIZE];
#define GR_PORT_DESCRIPTION_SIZE 255
char description[GR_PORT_DESCRIPTION_SIZE];
};

static_assert(sizeof(struct gr_iface_info_port) <= MEMBER_SIZE(struct gr_iface, info));
Expand Down
16 changes: 14 additions & 2 deletions modules/infra/cli/port.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ static void port_show(const struct gr_api_client *c, const struct gr_iface *ifac

printf("devargs: %s\n", port->devargs);
printf("driver: %s\n", port->driver_name);
printf("desc: %s\n", port->description);
printf("mac: " ETH_F "\n", &port->mac);
if (port->link_speed == UINT32_MAX)
printf("speed: unknown\n");
Expand Down Expand Up @@ -70,6 +71,7 @@ static uint64_t parse_port_args(
) {
uint64_t set_attrs = parse_iface_args(c, p, iface, update);
struct gr_iface_info_port *port;
const char *description;
const char *devargs;

port = (struct gr_iface_info_port *)iface->info;
Expand Down Expand Up @@ -109,6 +111,14 @@ static uint64_t parse_port_args(
iface->mode = GR_IFACE_MODE_L1_XC;
iface->domain_id = peer.id;
}
description = arg_str(p, "DESCRIPTION");
if (description != NULL) {
if (strlen(description) >= sizeof(port->description)) {
errno = ENAMETOOLONG;
goto err;
}
memccpy(port->description, description, 0, sizeof(port->description));
}

if (set_attrs == 0)
errno = EINVAL;
Expand Down Expand Up @@ -149,7 +159,8 @@ static cmd_status_t port_set(const struct gr_api_client *c, const struct ec_pnod
}

#define PORT_ATTRS_CMD \
IFACE_ATTRS_CMD ",(mac MAC),(rxqs N_RXQ),(qsize Q_SIZE),(mode l3|(xconnect PEER))"
IFACE_ATTRS_CMD ",(mac MAC),(rxqs N_RXQ),(qsize Q_SIZE),(mode l3|(xconnect PEER))," \
"(desc DESCRIPTION)"

#define PORT_ATTRS_ARGS \
IFACE_ATTRS_ARGS, with_help("Set the ethernet address.", ec_node_re("MAC", ETH_ADDR_RE)), \
Expand All @@ -160,7 +171,8 @@ static cmd_status_t port_set(const struct gr_api_client *c, const struct ec_pnod
with_help( \
"Peer interface for xconnect", \
ec_node_dyn("PEER", complete_iface_names, INT2PTR(GR_IFACE_TYPE_PORT)) \
)
), \
with_help("desc:", ec_node("any", "DESCRIPTION"))

static int ctx_init(struct ec_node *root) {
int ret;
Expand Down
1 change: 1 addition & 0 deletions modules/infra/control/gr_port.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ struct __rte_aligned(alignof(void *)) iface_info_port {
bool started;
struct rte_mempool *pool;
char *devargs;
char *description;
uint32_t pool_size;
struct mac_filter ucast_filter;
struct mac_filter mcast_filter;
Expand Down
15 changes: 14 additions & 1 deletion modules/infra/control/port.c
Original file line number Diff line number Diff line change
Expand Up @@ -303,6 +303,8 @@ static int iface_port_fini(struct iface *iface) {

free(port->devargs);
port->devargs = NULL;
free(port->description);
port->description = NULL;
if ((ret = rte_eth_dev_info_get(port->port_id, &info)) < 0)
LOG(ERR, "rte_eth_dev_info_get: %s", rte_strerror(-ret));
if ((ret = rte_eth_dev_stop(port->port_id)) < 0)
Expand Down Expand Up @@ -355,11 +357,18 @@ static int iface_port_init(struct iface *iface, const void *api_info) {
return errno_set(EIDRM);

port->port_id = port_id;
port->devargs = NULL;
port->description = NULL;
port->devargs = strndup(api->devargs, GR_PORT_DEVARGS_SIZE);
if (port->devargs == NULL) {
ret = errno_set(ENOMEM);
goto fail;
}
port->description = strndup(api->description, GR_PORT_DESCRIPTION_SIZE);
if (port->description == NULL) {
ret = errno_set(ENOMEM);
goto fail;
}

conf.flags = iface->flags;
conf.mtu = iface->mtu;
Expand All @@ -375,7 +384,10 @@ static int iface_port_init(struct iface *iface, const void *api_info) {

return 0;
fail:
free(port->devargs);
if (port->devargs)
free(port->devargs);
if (port->description)
free(port->description);
return ret;
}

Expand Down Expand Up @@ -561,6 +573,7 @@ static void port_to_api(void *info, const struct iface *iface) {

api->base = port->base;
memccpy(api->devargs, port->devargs, 0, sizeof(api->devargs));
memccpy(api->description, port->description, 0, sizeof(api->description));

if (rte_eth_dev_info_get(port->port_id, &dev_info) == 0) {
memccpy(api->driver_name, dev_info.driver_name, 0, sizeof(api->driver_name));
Expand Down