lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <1573229926-30040-5-git-send-email-yuvalav@mellanox.com>
Date:   Fri,  8 Nov 2019 18:18:40 +0200
From:   Yuval Avnery <yuvalav@...lanox.com>
To:     netdev@...r.kernel.org
Cc:     jiri@...lanox.com, saeedm@...lanox.com, leon@...nel.org,
        davem@...emloft.net, jakub.kicinski@...ronome.com,
        shuah@...nel.org, danielj@...lanox.com, parav@...lanox.com,
        andrew.gospodarek@...adcom.com, michael.chan@...adcom.com,
        Yuval Avnery <yuvalav@...lanox.com>
Subject: [PATCH net-next v2 04/10] devlink: Support subdev HW address get

Allow privileged user to get the HW address of a subdev.

Example:

$ devlink subdev show pci/0000:03:00.0/1
pci/0000:03:00.0/1: flavour pcivf pf 0 vf 0 port_index 1 hw_addr 00:23:35:af:35:34

$ devlink subdev show pci/0000:03:00.0/1 -pj
{
    "subdev": {
        "pci/0000:03:00.0/1": {
            "flavour": "pcivf",
            "pf": 0,
            "vf": 0,
            "port_index": 1,
            "hw_addr": "00:23:35:af:35:34"
        }
    }
}

Signed-off-by: Yuval Avnery <yuvalav@...lanox.com>
Acked-by: Jiri Pirko <jiri@...lanox.com>
---
 include/net/devlink.h        |  3 +++
 include/uapi/linux/devlink.h |  1 +
 net/core/devlink.c           | 34 +++++++++++++++++++++++++++-------
 3 files changed, 31 insertions(+), 7 deletions(-)

diff --git a/include/net/devlink.h b/include/net/devlink.h
index 0cedd6d34ef8..5917260e5748 100644
--- a/include/net/devlink.h
+++ b/include/net/devlink.h
@@ -765,6 +765,9 @@ struct devlink_ops {
 };
 
 struct devlink_subdev_ops {
+	int (*hw_addr_get)(struct devlink_subdev *subdev,
+			   u8 *hw_addr, struct netlink_ext_ack *extack);
+	unsigned int hw_addr_len;
 };
 
 static inline void *devlink_priv(struct devlink *devlink)
diff --git a/include/uapi/linux/devlink.h b/include/uapi/linux/devlink.h
index da79ffad9c5a..c7a7ad4c4a20 100644
--- a/include/uapi/linux/devlink.h
+++ b/include/uapi/linux/devlink.h
@@ -439,6 +439,7 @@ enum devlink_attr {
 	DEVLINK_ATTR_SUBDEV_FLAVOUR,		/* u16 */
 	DEVLINK_ATTR_SUBDEV_PF_INDEX,		/* u32 */
 	DEVLINK_ATTR_SUBDEV_VF_INDEX,		/* u32 */
+	DEVLINK_ATTR_SUBDEV_HW_ADDR,		/* binary */
 
 	/* add new attributes above here, update the policy in devlink.c */
 
diff --git a/net/core/devlink.c b/net/core/devlink.c
index 0c97c51dea0d..7d6e3da8a64c 100644
--- a/net/core/devlink.c
+++ b/net/core/devlink.c
@@ -711,10 +711,13 @@ static void devlink_port_notify(struct devlink_port *devlink_port,
 static int devlink_nl_subdev_fill(struct sk_buff *msg, struct devlink *devlink,
 				  struct devlink_subdev *devlink_subdev,
 				  enum devlink_command cmd, u32 subdevid,
-				  u32 seq, int flags)
+				  u32 seq, int flags,
+				  struct netlink_ext_ack *extack)
 {
 	struct devlink_subdev_attrs *attrs = &devlink_subdev->attrs;
+	const struct devlink_subdev_ops *ops = devlink_subdev->ops;
 	void *hdr;
+	int err;
 
 	hdr = genlmsg_put(msg, subdevid, seq, &devlink_nl_family, flags, cmd);
 	if (!hdr)
@@ -748,6 +751,19 @@ static int devlink_nl_subdev_fill(struct sk_buff *msg, struct devlink *devlink,
 				devlink_subdev->devlink_port->index))
 			goto nla_put_failure;
 
+	if (ops && ops->hw_addr_get) {
+		u8 hw_addr[MAX_ADDR_LEN];
+
+		err = ops->hw_addr_get(devlink_subdev, hw_addr, extack);
+		if (err) {
+			genlmsg_cancel(msg, hdr);
+			return err;
+		}
+		if (nla_put(msg, DEVLINK_ATTR_SUBDEV_HW_ADDR,
+			    ops->hw_addr_len, hw_addr))
+			goto nla_put_failure;
+	}
+
 	genlmsg_end(msg, hdr);
 	return 0;
 
@@ -769,8 +785,8 @@ static void devlink_subdev_notify(struct devlink_subdev *devlink_subdev,
 	if (!msg)
 		return;
 
-	err = devlink_nl_subdev_fill(msg, devlink,
-				     devlink_subdev, cmd, 0, 0, 0);
+	err = devlink_nl_subdev_fill(msg, devlink, devlink_subdev, cmd,
+				     0, 0, 0, NULL);
 	if (err) {
 		nlmsg_free(msg);
 		return;
@@ -993,8 +1009,8 @@ static int devlink_nl_cmd_subdev_get_doit(struct sk_buff *skb,
 		return -ENOMEM;
 
 	err = devlink_nl_subdev_fill(msg, devlink, devlink_subdev,
-				     DEVLINK_CMD_SUBDEV_NEW,
-				     info->snd_portid, info->snd_seq, 0);
+				     DEVLINK_CMD_SUBDEV_NEW, info->snd_portid,
+				     info->snd_seq, 0, info->extack);
 	if (err) {
 		nlmsg_free(msg);
 		return err;
@@ -1011,7 +1027,7 @@ static int devlink_nl_cmd_subdev_get_dumpit(struct sk_buff *msg,
 	struct devlink *devlink;
 	int start = cb->args[0];
 	int idx = 0;
-	int err;
+	int err = 0;
 
 	mutex_lock(&devlink_mutex);
 	list_for_each_entry(devlink, &devlink_list, list) {
@@ -1030,7 +1046,7 @@ static int devlink_nl_cmd_subdev_get_dumpit(struct sk_buff *msg,
 						     DEVLINK_CMD_NEW,
 						     NETLINK_CB(cb->skb).portid,
 						     cb->nlh->nlmsg_seq,
-						     NLM_F_MULTI);
+						     NLM_F_MULTI, NULL);
 			if (err) {
 				mutex_unlock(&devlink->lock);
 				goto out;
@@ -1041,6 +1057,8 @@ static int devlink_nl_cmd_subdev_get_dumpit(struct sk_buff *msg,
 	}
 out:
 	mutex_unlock(&devlink_mutex);
+	if (err != -EMSGSIZE)
+		return err;
 
 	cb->args[0] = idx;
 	return msg->len;
@@ -6114,6 +6132,8 @@ static const struct nla_policy devlink_nl_policy[DEVLINK_ATTR_MAX + 1] = {
 	[DEVLINK_ATTR_SUBDEV_FLAVOUR] = { .type = NLA_U16 },
 	[DEVLINK_ATTR_SUBDEV_PF_INDEX] = { .type = NLA_U32 },
 	[DEVLINK_ATTR_SUBDEV_VF_INDEX] = { .type = NLA_U32 },
+	[DEVLINK_ATTR_SUBDEV_HW_ADDR] = { .type = NLA_BINARY,
+					.len = MAX_ADDR_LEN },
 };
 
 static const struct genl_ops devlink_nl_ops[] = {
-- 
2.17.1

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ