diff --git a/modules/infra/api/gr_infra.h b/modules/infra/api/gr_infra.h index 4bb0b55f9..33874f82a 100644 --- a/modules/infra/api/gr_infra.h +++ b/modules/infra/api/gr_infra.h @@ -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); @@ -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)); diff --git a/modules/infra/cli/port.c b/modules/infra/cli/port.c index b42b70162..23ec68755 100644 --- a/modules/infra/cli/port.c +++ b/modules/infra/cli/port.c @@ -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"); @@ -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; @@ -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; @@ -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)), \ @@ -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; diff --git a/modules/infra/control/gr_port.h b/modules/infra/control/gr_port.h index 8764745eb..f018f51fa 100644 --- a/modules/infra/control/gr_port.h +++ b/modules/infra/control/gr_port.h @@ -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; diff --git a/modules/infra/control/port.c b/modules/infra/control/port.c index f37083453..18f77644e 100644 --- a/modules/infra/control/port.c +++ b/modules/infra/control/port.c @@ -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) @@ -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; @@ -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; } @@ -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));