RFC 2863 Testing Oper status
Subsystems (3)
Andrew Lunn
maintainerv2 cover RFC 2863 Testing Oper status
This patchset add support for RFC 2863 Oper status testing. An interface is placed into this state when a self test is performed using ethtool.
v2:
Fix date/kernel version in Documentation
Add reviewed-by tags
Andrew Lunn (3):
net: Add IF_OPER_TESTING
net: Add testing sysfs attribute
net: ethtool: self_test: Mark interface in testing operative status
Documentation/ABI/testing/sysfs-class-net | 13 +++++++ include/linux/netdevice.h | 41 +++++++++++++++++++++++ include/uapi/linux/if.h | 1 + net/core/dev.c | 5 +++ net/core/link_watch.c | 12 +++++-- net/core/net-sysfs.c | 15 ++++++++- net/core/rtnetlink.c | 9 ++++- net/ethtool/ioctl.c | 2 ++ 8 files changed, 94 insertions(+), 4 deletions(-)
Signature · 1 line
2.26.1
Andrew Lunn
maintainerPATCH v2 1/3 net: Add IF_OPER_TESTING
RFC 2863 defines the operational state testing. Add support for this state, both as a IF_LINK_MODE_ and __LINK_STATE_.
--- include/linux/netdevice.h | 41 +++++++++++++++++++++++++++++++++++++++ include/uapi/linux/if.h | 1 + net/core/dev.c | 5 +++++ net/core/link_watch.c | 12 ++++++++++-- net/core/rtnetlink.c | 9 ++++++++- 5 files changed, 65 insertions(+), 3 deletions(-)
include/linux/netdevice.h +41 -0
@@ -288,6 +288,7 @@ enum netdev_state_t { __LINK_STATE_NOCARRIER, __LINK_STATE_LINKWATCH_PENDING, __LINK_STATE_DORMANT, + __LINK_STATE_TESTING, };
@@ -3907,6 +3908,46 @@ static inline bool netif_dormant(const struct net_device *dev) } +/** +* netif_testing_on - mark device as under test. +* @dev: network device +* +* Mark device as under test (as per RFC2863). +* +* The testing state indicates that some test(s) must be performed on +* the interface. After completion, of the test, the interface state +* will change to up, dormant, or down, as appropriate. +*/ +static inline void netif_testing_on (struct net_device *dev) +{ +if (!test_and_set_bit (__LINK_STATE_TESTING, &dev->state)) +linkwatch_fire_event (dev); +} + +/** +* netif_testing_off - set device as not under test. +* @dev: network device +* +* Device is not in testing state. +*/ +static inline void netif_testing_off (struct net_device *dev) +{ +if (test_and_clear_bit (__LINK_STATE_TESTING, &dev->state)) +linkwatch_fire_event (dev); +} + +/** +* netif_testing - test if device is under test +* @dev: network device +* +* Check if device is under test +*/ +static inline bool netif_testing (const struct net_device *dev) +{ +return test_bit (__LINK_STATE_TESTING, &dev->state); +} + +/** * netif_oper_up - test if device is operational * @dev: network device
include/uapi/linux/if.h +1 -0
@@ -178,6 +178,7 @@ enum {enum {IF_LINK_MODE_DEFAULT ,IF_LINK_MODE_DORMANT ,/* limit upward transition to dormant */ +IF_LINK_MODE_TESTING ,/* limit upward transition to testing */ };/*
net/core/dev.c +5 -0
@@ -9136,6 +9136,11 @@ void netif_stacked_transfer_operstate(const struct net_device *rootdev,else netif_dormant_off (dev); +if (rootdev->operstate ==IF_OPER_TESTING ) +netif_testing_on (dev); +else +netif_testing_off (dev); +if (netif_carrier_ok (rootdev))netif_carrier_on (dev);else
net/core/link_watch.c +10 -2
@@ -34,6 +34,9 @@ static DEFINE_SPINLOCK(lweventlist_lock);static unsigned char default_operstate (const struct net_device *dev) { +if (netif_testing (dev)) +return IF_OPER_TESTING ; +if (!netif_carrier_ok (dev))return (dev->ifindex !=dev_get_iflink (dev) ?IF_OPER_LOWERLAYERDOWN :IF_OPER_DOWN );
@@ -55,11 +58,15 @@ static void rfc2863_policy(struct net_device *dev)write_lock_bh (&dev_base_lock);switch (dev->link_mode) { +case IF_LINK_MODE_TESTING : +if (operstate ==IF_OPER_UP ) + operstate =IF_OPER_TESTING ; +break ; +case IF_LINK_MODE_DORMANT :if (operstate ==IF_OPER_UP ) operstate =IF_OPER_DORMANT ;break ; -case IF_LINK_MODE_DEFAULT :default :break ;
@@ -74,7 +81,8 @@ static void rfc2863_policy(struct net_device *dev)void linkwatch_init_dev (struct net_device *dev) {/* Handle pre-registration link state changes */ -if (!netif_carrier_ok (dev) ||netif_dormant (dev)) +if (!netif_carrier_ok (dev) ||netif_dormant (dev) || +netif_testing (dev))rfc2863_policy (dev); }
net/core/rtnetlink.c +8 -1
@@ -829,11 +829,18 @@ static void set_operstate(struct net_device *dev, unsigned char transition)switch (transition) {case IF_OPER_UP :if ((operstate ==IF_OPER_DORMANT || + operstate ==IF_OPER_TESTING || operstate ==IF_OPER_UNKNOWN ) && - !netif_dormant (dev)) + !netif_dormant (dev) && !netif_testing (dev)) operstate =IF_OPER_UP ;break ; +case IF_OPER_TESTING : +if (operstate ==IF_OPER_UP || + operstate ==IF_OPER_UNKNOWN ) + operstate =IF_OPER_TESTING ; +break ; +case IF_OPER_DORMANT :if (operstate ==IF_OPER_UP || operstate ==IF_OPER_UNKNOWN )
Signature · 1 line
2.26.1
Andrew Lunn
maintainerPATCH v2 2/3 net: Add testing sysfs attribute
In reply to Andrew LunnSimilar to speed, duplex and dorment, report the testing status in sysfs.
---
v2: Correct date/kernel version
--- Documentation/ABI/testing/sysfs-class-net | 13 +++++++++++++ net/core/net-sysfs.c | 15 ++++++++++++++- 2 files changed, 27 insertions(+), 1 deletion(-)
Documentation/ABI/testing/sysfs-class-net +13 -0
@@ -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: April 2002 +KernelVersion: 5.8 +Contact: [email protected] +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
net/core/net-sysfs.c +14 -1
@@ -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,
Signature · 1 line
2.26.1
Andrew Lunn
maintainerPATCH v2 3/3 net: ethtool: self_test: Mark interface in testing operative status
In reply to Andrew LunnWhen an interface is executing a self test, put the interface into operative status testing.
--- net/ethtool/ioctl.c | 2 ++ 1 file changed, 2 insertions(+)
net/ethtool/ioctl.c +2 -0
@@ -1746,7 +1746,9 @@ static int ethtool_self_test(struct net_device *dev, char __user *useraddr)if (!data)return -ENOMEM ; +netif_testing_on (dev); ops->self_test (dev, &test, data); +netif_testing_off (dev); ret = -EFAULT ;if (copy_to_user (useraddr, &test,sizeof (test)))
Signature · 1 line
2.26.1
David Miller
maintainerFrom: Andrew Lunn <[email protected]>
Date: Mon, 20 Apr 2020 00:11:49 +0200
Quoted 7 lines
This patchset add support for RFC 2863 Oper status testing. An interface is placed into this state when a self test is performed using ethtool.
v2:
Fix date/kernel version in Documentation
Add reviewed-by tags
Series applied, thanks Andrew.