netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH]  net-sysfs: make flags symmetrical
@ 2013-04-01 18:53 Stephen Hemminger
  2013-04-01 20:16 ` Ben Greear
  0 siblings, 1 reply; 6+ messages in thread
From: Stephen Hemminger @ 2013-04-01 18:53 UTC (permalink / raw)
  To: David Miller; +Cc: netdev

The flags reported by sysfs are the raw kernel flags, not the version
exported to user space. This leads to the unsymmetrical behaviour that
read != write. An example of this is when a device is part of a
bridge.  The PROMISC flag returned from sysfs will not be the same as
other API's.

The reason this patch deserves wider discussion is someone might be
depending on sysfs to read raw kernel flags.

Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>


--- a/net/core/net-sysfs.c	2013-03-21 14:17:08.740354291 -0700
+++ b/net/core/net-sysfs.c	2013-04-01 11:47:46.949728288 -0700
@@ -252,7 +252,19 @@ static ssize_t store_mtu(struct device *
 	return netdev_store(dev, attr, buf, len, change_mtu);
 }
 
-NETDEVICE_SHOW(flags, fmt_hex);
+static ssize_t show_flags(struct device *dev,
+			  struct device_attribute *attr, char *buf)
+{
+	struct net_device *ndev = to_net_dev(dev);
+	ssize_t ret = -EINVAL;
+
+	read_lock(&dev_base_lock);
+	if (dev_isalive(ndev))
+		ret = sprintf(buf, fmt_hex, dev_get_flags(ndev));
+	read_unlock(&dev_base_lock);
+
+	return ret;
+}
 
 static int change_flags(struct net_device *net, unsigned long new_flags)
 {

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2013-04-01 22:26 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-04-01 18:53 [PATCH] net-sysfs: make flags symmetrical Stephen Hemminger
2013-04-01 20:16 ` Ben Greear
2013-04-01 21:18   ` David Miller
2013-04-01 21:32     ` Ben Greear
2013-04-01 22:04   ` Stephen Hemminger
2013-04-01 22:26     ` Ben Greear

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).