diff mbox series

[net-next,2/3] net: Add testing sysfs attribute

Message ID 20200417230350.802675-3-andrew@lunn.ch
State Changes Requested
Delegated to: David Miller
Headers show
Series RFC 2863 Testing Oper status | expand

Commit Message

Andrew Lunn April 17, 2020, 11:03 p.m. UTC
Similar to speed, duplex and dorment, report the testing status
in sysfs.

Signed-off-by: Andrew Lunn <andrew@lunn.ch>
---
 Documentation/ABI/testing/sysfs-class-net | 13 +++++++++++++
 net/core/net-sysfs.c                      | 15 ++++++++++++++-
 2 files changed, 27 insertions(+), 1 deletion(-)

Comments

Florian Fainelli April 17, 2020, 11:49 p.m. UTC | #1
On 4/17/2020 4:03 PM, Andrew Lunn wrote:
> Similar to speed, duplex and dorment, report the testing status
> in sysfs.
> 
> Signed-off-by: Andrew Lunn <andrew@lunn.ch>
> ---
>   Documentation/ABI/testing/sysfs-class-net | 13 +++++++++++++
>   net/core/net-sysfs.c                      | 15 ++++++++++++++-
>   2 files changed, 27 insertions(+), 1 deletion(-)
> 
> diff --git a/Documentation/ABI/testing/sysfs-class-net b/Documentation/ABI/testing/sysfs-class-net
> index 664a8f6a634f..5e8b09743e04 100644
> --- a/Documentation/ABI/testing/sysfs-class-net
> +++ b/Documentation/ABI/testing/sysfs-class-net
> @@ -124,6 +124,19 @@ Description:
>   		authentication is performed (e.g: 802.1x). 'link_mode' attribute
>   		will also reflect the dormant state.
>   
> +What:		/sys/class/net/<iface>/testing
> +Date:		Jun 2019
> +KernelVersion:	5.2

This should probably be 5.8 now, other than that:

Reviewed-by: Florian Fainelli <f.fainelli@gmail.com>
Andrew Lunn April 17, 2020, 11:54 p.m. UTC | #2
On Fri, Apr 17, 2020 at 04:49:23PM -0700, Florian Fainelli wrote:
> 
> 
> On 4/17/2020 4:03 PM, Andrew Lunn wrote:
> > Similar to speed, duplex and dorment, report the testing status
> > in sysfs.
> > 
> > Signed-off-by: Andrew Lunn <andrew@lunn.ch>
> > ---
> >   Documentation/ABI/testing/sysfs-class-net | 13 +++++++++++++
> >   net/core/net-sysfs.c                      | 15 ++++++++++++++-
> >   2 files changed, 27 insertions(+), 1 deletion(-)
> > 
> > diff --git a/Documentation/ABI/testing/sysfs-class-net b/Documentation/ABI/testing/sysfs-class-net
> > index 664a8f6a634f..5e8b09743e04 100644
> > --- a/Documentation/ABI/testing/sysfs-class-net
> > +++ b/Documentation/ABI/testing/sysfs-class-net
> > @@ -124,6 +124,19 @@ Description:
> >   		authentication is performed (e.g: 802.1x). 'link_mode' attribute
> >   		will also reflect the dormant state.
> > +What:		/sys/class/net/<iface>/testing
> > +Date:		Jun 2019
> > +KernelVersion:	5.2
> 
> This should probably be 5.8 now, other than that:

Ah, yes. Shows how long this has been sat in my tree.

> Reviewed-by: Florian Fainelli <f.fainelli@gmail.com>

Thanks
	Andrew
diff mbox series

Patch

diff --git a/Documentation/ABI/testing/sysfs-class-net b/Documentation/ABI/testing/sysfs-class-net
index 664a8f6a634f..5e8b09743e04 100644
--- a/Documentation/ABI/testing/sysfs-class-net
+++ b/Documentation/ABI/testing/sysfs-class-net
@@ -124,6 +124,19 @@  Description:
 		authentication is performed (e.g: 802.1x). 'link_mode' attribute
 		will also reflect the dormant state.
 
+What:		/sys/class/net/<iface>/testing
+Date:		Jun 2019
+KernelVersion:	5.2
+Contact:	netdev@vger.kernel.org
+Description:
+		Indicates whether the interface is under test. Possible
+		values are:
+		0: interface is not being tested
+		1: interface is being tested
+
+		When an interface is under test, it cannot be expected
+		to pass packets as normal.
+
 What:		/sys/clas/net/<iface>/duplex
 Date:		October 2009
 KernelVersion:	2.6.33
diff --git a/net/core/net-sysfs.c b/net/core/net-sysfs.c
index 4773ad6ec111..0d9e46de205e 100644
--- a/net/core/net-sysfs.c
+++ b/net/core/net-sysfs.c
@@ -243,6 +243,18 @@  static ssize_t duplex_show(struct device *dev,
 }
 static DEVICE_ATTR_RO(duplex);
 
+static ssize_t testing_show(struct device *dev,
+			    struct device_attribute *attr, char *buf)
+{
+	struct net_device *netdev = to_net_dev(dev);
+
+	if (netif_running(netdev))
+		return sprintf(buf, fmt_dec, !!netif_testing(netdev));
+
+	return -EINVAL;
+}
+static DEVICE_ATTR_RO(testing);
+
 static ssize_t dormant_show(struct device *dev,
 			    struct device_attribute *attr, char *buf)
 {
@@ -260,7 +272,7 @@  static const char *const operstates[] = {
 	"notpresent", /* currently unused */
 	"down",
 	"lowerlayerdown",
-	"testing", /* currently unused */
+	"testing",
 	"dormant",
 	"up"
 };
@@ -524,6 +536,7 @@  static struct attribute *net_class_attrs[] __ro_after_init = {
 	&dev_attr_speed.attr,
 	&dev_attr_duplex.attr,
 	&dev_attr_dormant.attr,
+	&dev_attr_testing.attr,
 	&dev_attr_operstate.attr,
 	&dev_attr_carrier_changes.attr,
 	&dev_attr_ifalias.attr,