The loopback device always reports link up through ethtool, but as it
never calls netif_carrier_{off,on}() its operstate is 'unknown'.  Fix
this by calling netif_carrier_off() before registration and
netif_carrier_on() when opened.

Signed-off-by: Ben Hutchings <[email protected]>
---
You could test with this kernel patch, which should make lo report
operstate=up when the interface is brought up.  (I haven't tested it
myself.)

However, it is generally incorrect to wait for operstate not to be
'unknown', as not all network devices support link detection (that's why
this is the default state).  Please fix whatever code is doing that.

Ben.

--- a/drivers/net/loopback.c
+++ b/drivers/net/loopback.c
@@ -142,6 +142,12 @@ static int loopback_dev_init(struct net_
        return 0;
 }
 
+static int loopback_dev_open(struct net_device *dev)
+{
+       netif_carrier_on(dev);
+       return 0;
+}
+
 static void loopback_dev_free(struct net_device *dev)
 {
        dev_net(dev)->loopback_dev = NULL;
@@ -151,6 +157,7 @@ static void loopback_dev_free(struct net
 
 static const struct net_device_ops loopback_ops = {
        .ndo_init      = loopback_dev_init,
+       .ndo_open      = loopback_dev_open,
        .ndo_start_xmit= loopback_xmit,
        .ndo_get_stats64 = loopback_get_stats64,
        .ndo_set_mac_address = eth_mac_addr,
@@ -199,6 +206,8 @@ static __net_init int loopback_net_init(
        if (!dev)
                goto out;
 
+       netif_carrier_off(dev);
+
        dev_net_set(dev, net);
        err = register_netdev(dev);
        if (err)


-- 
Ben Hutchings
The program is absolutely right; therefore, the computer must be wrong.

Attachment: signature.asc
Description: This is a digitally signed message part

Reply via email to