diff mbox

[v1] net-sysfs: expose permanent hardware address in sysfs

Message ID cd90d330753ff145d209240a72caafac32f5e750.1399347193.git.decot@googlers.com
State Rejected, archived
Delegated to: David Miller
Headers show

Commit Message

David Decotigny May 6, 2014, 3:34 a.m. UTC
Tested:
  grep . /sys/class/net/*/*addr*

Signed-off-by: David Decotigny <decot@googlers.com>
---
 net/core/net-sysfs.c | 15 +++++++++++++++
 1 file changed, 15 insertions(+)

Comments

Florian Fainelli May 7, 2014, 5:24 a.m. UTC | #1
Le 05/05/2014 20:34, David Decotigny a écrit :
> Tested:
>    grep . /sys/class/net/*/*addr*

Please also include the relevant sysfs documentation changes in 
Documentation/ABI/testing/sysfs-class-net.

Thanks!

>
> Signed-off-by: David Decotigny <decot@googlers.com>
> ---
>   net/core/net-sysfs.c | 15 +++++++++++++++
>   1 file changed, 15 insertions(+)
>
> diff --git a/net/core/net-sysfs.c b/net/core/net-sysfs.c
> index 1cac29e..bf57024 100644
> --- a/net/core/net-sysfs.c
> +++ b/net/core/net-sysfs.c
> @@ -127,6 +127,20 @@ static ssize_t address_show(struct device *dev, struct device_attribute *attr,
>   }
>   static DEVICE_ATTR_RO(address);
>
> +static ssize_t perm_addr_show(struct device *dev, struct device_attribute *attr,
> +			      char *buf)
> +{
> +	struct net_device *net = to_net_dev(dev);
> +	ssize_t ret = -EINVAL;
> +
> +	read_lock(&dev_base_lock);
> +	if (dev_isalive(net))
> +		ret = sysfs_format_mac(buf, net->perm_addr, net->addr_len);
> +	read_unlock(&dev_base_lock);
> +	return ret;
> +}
> +static DEVICE_ATTR_RO(perm_addr);
> +
>   static ssize_t broadcast_show(struct device *dev,
>   			      struct device_attribute *attr, char *buf)
>   {
> @@ -391,6 +405,7 @@ static struct attribute *net_class_attrs[] = {
>   	&dev_attr_addr_len.attr,
>   	&dev_attr_link_mode.attr,
>   	&dev_attr_address.attr,
> +	&dev_attr_perm_addr.attr,
>   	&dev_attr_broadcast.attr,
>   	&dev_attr_speed.attr,
>   	&dev_attr_duplex.attr,
>
--
To unsubscribe from this list: send the line "unsubscribe netdev" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
David Miller May 7, 2014, 8:16 p.m. UTC | #2
From: David Decotigny <decot@googlers.com>
Date: Mon,  5 May 2014 20:34:00 -0700

> Tested:
>   grep . /sys/class/net/*/*addr*
> 
> Signed-off-by: David Decotigny <decot@googlers.com>

ETHTOOL_GPERMADDR exists already, please use that instead, thanks.
--
To unsubscribe from this list: send the line "unsubscribe netdev" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
diff mbox

Patch

diff --git a/net/core/net-sysfs.c b/net/core/net-sysfs.c
index 1cac29e..bf57024 100644
--- a/net/core/net-sysfs.c
+++ b/net/core/net-sysfs.c
@@ -127,6 +127,20 @@  static ssize_t address_show(struct device *dev, struct device_attribute *attr,
 }
 static DEVICE_ATTR_RO(address);
 
+static ssize_t perm_addr_show(struct device *dev, struct device_attribute *attr,
+			      char *buf)
+{
+	struct net_device *net = to_net_dev(dev);
+	ssize_t ret = -EINVAL;
+
+	read_lock(&dev_base_lock);
+	if (dev_isalive(net))
+		ret = sysfs_format_mac(buf, net->perm_addr, net->addr_len);
+	read_unlock(&dev_base_lock);
+	return ret;
+}
+static DEVICE_ATTR_RO(perm_addr);
+
 static ssize_t broadcast_show(struct device *dev,
 			      struct device_attribute *attr, char *buf)
 {
@@ -391,6 +405,7 @@  static struct attribute *net_class_attrs[] = {
 	&dev_attr_addr_len.attr,
 	&dev_attr_link_mode.attr,
 	&dev_attr_address.attr,
+	&dev_attr_perm_addr.attr,
 	&dev_attr_broadcast.attr,
 	&dev_attr_speed.attr,
 	&dev_attr_duplex.attr,