Tue, Nov 01, 2022 at 05:18:34PM CET, kuba@xxxxxxxxxx wrote: >On Mon, 31 Oct 2022 13:42:48 +0100 Jiri Pirko wrote: >> From: Jiri Pirko <jiri@xxxxxxxxxx> >> >> Expose devlink port handle related to netdev over rtnetlink. Introduce a >> new nested IFLA attribute to carry the info. Call into devlink code to >> fill-up the nest with existing devlink attributes that are used over >> devlink netlink. > >> +int devlink_nl_port_handle_fill(struct sk_buff *msg, struct devlink_port *devlink_port) >> +{ >> + if (devlink_nl_put_handle(msg, devlink_port->devlink)) >> + return -EMSGSIZE; >> + if (nla_put_u32(msg, DEVLINK_ATTR_PORT_INDEX, devlink_port->index)) >> + return -EMSGSIZE; >> + return 0; >> +} >> +EXPORT_SYMBOL_GPL(devlink_nl_port_handle_fill); >> + >> +size_t devlink_nl_port_handle_size(struct devlink_port *devlink_port) >> +{ >> + struct devlink *devlink = devlink_port->devlink; >> + >> + return nla_total_size(strlen(devlink->dev->bus->name) + 1) /* DEVLINK_ATTR_BUS_NAME */ >> + + nla_total_size(strlen(dev_name(devlink->dev)) + 1) /* DEVLINK_ATTR_DEV_NAME */ >> + + nla_total_size(4); /* DEVLINK_ATTR_PORT_INDEX */ >> +} >> +EXPORT_SYMBOL_GPL(devlink_nl_port_handle_size); > >Why the exports? devlink is a boolean now IIRC. Right, removed. > >> +static int rtnl_fill_devlink_port(struct sk_buff *skb, >> + const struct net_device *dev) >> +{ >> + struct nlattr *devlink_port_nest; >> + int ret; >> + >> + devlink_port_nest = nla_nest_start(skb, IFLA_DEVLINK_PORT); >> + if (!devlink_port_nest) >> + return -EMSGSIZE; >> + >> + if (dev->devlink_port) { > >Why produce the empty nest if port is not set? Empty nest indicates that kernel supports this but there is no devlink port associated. I see no other way to indicate this :/ > >> + ret = devlink_nl_port_handle_fill(skb, dev->devlink_port); >> + if (ret < 0) >> + goto nest_cancel; >> + } >> + >> + nla_nest_end(skb, devlink_port_nest); >> + return 0; >> + >> +nest_cancel: >> + nla_nest_cancel(skb, devlink_port_nest); >> + return ret; >> +}