Re: [patch net-next v3 13/13] net: expose devlink port over rtnetlink

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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.

> +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?

> +		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;
> +}



[Index of Archives]     [Linux USB Devel]     [Video for Linux]     [Linux Audio Users]     [Photo]     [Yosemite News]     [Yosemite Photos]     [Linux Kernel]     [Linux SCSI]     [XFree86]

  Powered by Linux