]> git.proxmox.com Git - mirror_ubuntu-hirsute-kernel.git/commitdiff
net: Add IF_OPER_TESTING
authorAndrew Lunn <andrew@lunn.ch>
Sun, 19 Apr 2020 22:11:50 +0000 (00:11 +0200)
committerDavid S. Miller <davem@davemloft.net>
Mon, 20 Apr 2020 19:43:24 +0000 (12:43 -0700)
RFC 2863 defines the operational state testing. Add support for this
state, both as a IF_LINK_MODE_ and __LINK_STATE_.

Signed-off-by: Andrew Lunn <andrew@lunn.ch>
Signed-off-by: David S. Miller <davem@davemloft.net>
include/linux/netdevice.h
include/uapi/linux/if.h
net/core/dev.c
net/core/link_watch.c
net/core/rtnetlink.c

index 130a668049ab06dc2be988de296bf6c6edce1e4c..0750b54b37651890eb297e9f97fc956fb5cc48c7 100644 (file)
@@ -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
index be714cd8c826d72a535f7b4caa48b1bf5666fdb2..797ba2c1562af285cb0d21afc93128f46002846d 100644 (file)
@@ -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 */
 };
 
 /*
index 522288177bbd8ce00d2152c218d7eef6fbcd82ab..fb61522b1ce163963f8d0bf54c7c5fa58fce7b9a 100644 (file)
@@ -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
index f153e060183833a292e1362dc0d7073a65ce6da7..75431ca9300fb9c486404da3dda0d344440d4fbc 100644 (file)
@@ -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);
 }
 
index 709ebbf8ab5bf1e2216d220fe9f8e3003dd3d117..d6f4f4a9e8ba35e96d2b32e0b639dae35efa1c9d 100644 (file)
@@ -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)