net-sysfs: make flags symmetrical
Subsystems (2)
PATCH 1/1 net-sysfs: make flags symmetrical
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.
net/core/net-sysfs.c +13 -1
@@ -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) {
Quoted 8 lines · Stephen Hemminger
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.
I am depending on this feature. There is no other way I know of to determine if an interface is actually currently acting PROMISC or not.
Please don't 'fix' this.
Thanks,
Ben
Signature · 2 lines
Ben Greear <[email protected]> Candela Technologies Inc http://www.candelatech.com
David Miller
maintainerFrom: Ben Greear <[email protected]>
Date: Mon, 01 Apr 2013 13:16:43 -0700
Quoted 3 lines
I am depending on this feature. There is no other way I know of to determine if an interface is actually currently acting PROMISC or not.
Netlink interface dump, SIOGIFCONF, etc. should provide this information in one form or another.
Quoted 9 lines · David Miller
From: Ben Greear <[email protected]>
Date: Mon, 01 Apr 2013 13:16:43 -0700Quoted 3 lines
I am depending on this feature. There is no other way I know of to determine if an interface is actually currently acting PROMISC or not.
Netlink interface dump, SIOGIFCONF, etc. should provide this information in one form or another.
From looking elsewhere in my code, I think you are right, at least about netlink.
The IFLA_PROMISCUITY field seems to give good results, but if you try to parse the ifinfomsg->ifi_flags method, it may lie to you and tell you the netdev is not PROMISSC when it really is PROMISC.
I haven't tried SIOGIFCONF...
Either way, I'd prefer the sysfs flags stay as is...while I have the netlink interface coded up in my app, it is not exactly light programming and other tools may find it much easier to use the sysfs flags. And, since I've been using the sysfs flags to double-check netlink in some cases, I'll have to add yet more hacks if this compatibility is broken in newer kernels...
Thanks,
Ben
Signature · 2 lines
Ben Greear <[email protected]> Candela Technologies Inc http://www.candelatech.com
Quoted 10 lines · On Mon, 01 Apr 2013 13:16:43 -0700 Ben Greear <[email protected]> wrote:
Quoted 8 lines · Stephen Hemminger
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.
Quoted 9 lines
I am depending on this feature. There is no other way I know of to determine if an interface is actually currently acting PROMISC or not.
Please don't 'fix' this.
Thanks,
Ben
The real problem is there isn't a netlink attribute that encodes the real flags (there should be), and when device changes state a notification should be sent.
Quoted 19 lines · Stephen Hemminger
Quoted 16 lines · On Mon, 01 Apr 2013 13:16:43 -0700 Ben Greear <[email protected]> wrote:
Quoted 8 lines · Stephen Hemminger
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.
I am depending on this feature. There is no other way I know of to determine if an interface is actually currently acting PROMISC or not.
Please don't 'fix' this.
Quoted 7 lines
Quoted 3 lines
Thanks,
BenThe real problem is there isn't a netlink attribute that encodes the real flags (there should be), and when device changes state a notification should be sent.
Ok, that sounds great to me...but plz don't remove the work-around in sysfs in the meantime :)
Thanks,
Ben
Signature · 2 lines
Ben Greear <[email protected]> Candela Technologies Inc http://www.candelatech.com