Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!
Bug 25480 - net_eth0 script should detect that there is no cable - fix included
Summary: net_eth0 script should detect that there is no cable - fix included
Status: RESOLVED DUPLICATE of bug 33272
Alias: None
Product: Gentoo Linux
Classification: Unclassified
Component: [OLD] Core system (show other bugs)
Hardware: All Linux
: High enhancement (vote)
Assignee: Martin Schlemmer (RETIRED)
URL:
Whiteboard:
Keywords:
: 26628 (view as bug list)
Depends on:
Blocks:
 
Reported: 2003-07-28 22:14 UTC by Leo
Modified: 2005-07-17 13:06 UTC (History)
4 users (show)

See Also:
Package list:
Runtime testing required: ---


Attachments
new /etc/init.d/net.eth0 with link check (net.eth0,4.87 KB, text/plain)
2003-07-28 22:16 UTC, Leo
Details
More simpel patch against current CVS (net.eth0-checklink.patch,917 bytes, patch)
2003-08-20 11:46 UTC, Henrik Brix Andersen
Details | Diff
Even MORE simple link detection. (net.eth0.diff,1.63 KB, patch)
2003-11-08 11:16 UTC, Jordan Ritter
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Leo 2003-07-28 22:14:32 UTC
In other distributions, there is a detection of the physical link connected to
the network card. If the card is not connected, you don't spend time waiting for
the dhcp timeout...

It's sufficient to add that to the net_eth0 script:

start() {
    local retval=0

    setup_env
    checkconfig || return 1

    ebegin "Bringing ${IFACE} up"

    if check_link_down ${IFACE}; then
        eend 1 "Failed; no link present.  Check cable?"
    else

....
.....
}




# From Mandrake-RedHat, modified by Leo
check_link_down ()
{
    if [ -x /sbin/mii-tool ]; then
        # wait for link to come up
        sleep 2
        /sbin/mii-tool $1 >/dev/null 2>&1 || return 1
        output=`LC_ALL=C /sbin/mii-tool $1 2>&1`
        if echo $output | grep -q "Operation not supported"; then
            return 0
        elif echo $output | grep -q "Invalid argument"; then
            return 0
        elif echo $output | grep -q "No MII transceiver present"; then
            return 0
        elif echo $output | grep -q "no link"; then
            return 0
        elif echo $output | grep -q "link ok"; then
            return 1
        else
            return 0
        fi
    fi
    return 0
}
Comment 1 Leo 2003-07-28 22:16:09 UTC
Created attachment 15170 [details]
new /etc/init.d/net.eth0 with link check
Comment 2 SpanKY gentoo-dev 2003-08-14 16:31:42 UTC
*** Bug 26628 has been marked as a duplicate of this bug. ***
Comment 3 Henrik Brix Andersen 2003-08-20 11:46:15 UTC
Created attachment 16370 [details, diff]
More simpel patch against current CVS

I've added a patch I came up with on my own a few days ago. This patch is
against current CVS and I think it conforms better to the coding style used
throughout the init scripts.

I am not saying this is better than the above patch - I am merely saying it's
an alternative.
Comment 4 Jordan Ritter 2003-11-08 11:05:23 UTC
Here's an even simpler patch -- the link state is reported via ifconfig,
which can be caught in setup_env():

--- net.eth0.orig       2003-11-08 11:04:50.000000000 -0800
+++ net.eth0    2003-11-08 10:55:17.000000000 -0800
@@ -33,6 +33,7 @@
         inet6_IFACE="$(eval echo \$\{inet6_${iface}\})"
         alias_IFACE="$(eval echo \$\{alias_${iface}\})"
         status_IFACE="$(ifconfig | gawk -v IFACE="${iface}" '/Link/ { if
($1 == IFACE) print "up" }')"
+        carrier_IFACE="$(ifconfig | gawk -v IFACE="${iface}" '/RUNNING/
{ if ($1 == IFACE) print "running" }')"
         vlans="$(eval echo \$\{iface_${IFACE}_vlans\})"
 }

@@ -63,11 +64,18 @@
                 # Check that eth0 was not brough up by the kernel ...
                 if [ "${status_IFACE}" != "up" ]
                 then
-                        /sbin/dhcpcd ${dhcpcd_IFACE} ${IFACE} >/dev/null
|| {
-                                retval=$?
-                                eend ${retval} "Failed to bring ${IFACE}
up"
-                                return ${retval}
-                        }
+                        # Check that the interface has a carrier
+                        if [ "${carrier_IFACE}" == "running" ]
+                        then
+                                /sbin/dhcpcd ${dhcpcd_IFACE} ${IFACE} >/dev/null
|| {
+                                        retval=$?
+                                        eend ${retval} "Failed to bring
${IFACE} up"
+                                        return ${retval}
+                                }
+                        else
+                                eend 1 "${IFACE} is not plugged in or has
no carrier signal"
+                                return 1
+                        fi
                 fi
         fi
Comment 5 Jordan Ritter 2003-11-08 11:16:31 UTC
Created attachment 20446 [details, diff]
Even MORE simple link detection.

Instead of using mii-tool to get link state, we can re-use the link state
"RUNNING" from ifconfig (which comes from the ioctl SIOCGIFFLAGS, which equates
to the netif_carrier_ok (netdevice.h) from the kernel's net_device struct).
 

This patch simply augments setup_env() with one more variable.
Comment 6 Nathan Kerr 2003-11-14 07:20:08 UTC
The checking of the link is a good idea, however it does not allow my interface to come up.  I am running net-tools 1.60-r7 with the development-sources-2.6.0_test8.  Before eth0 is started ifconfig does not report eth0 to be RUNNING and therefore the test fails.  By commenting out the check I was able to start my connection.  Here is my unstarted eth0 output from ifconfig:

eth0      Link encap:Ethernet  HWaddr 00:02:3F:8B:B8:79
          BROADCAST MULTICAST  MTU:1500  Metric:1
          RX packets:3588 errors:0 dropped:0 overruns:0 frame:0
          TX packets:3894 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000
          RX bytes:2642385 (2.5 Mb)  TX bytes:574093 (560.6 Kb)
          Interrupt:10 Base address:0x4000

Here is the output after eth0 is started:

eth0      Link encap:Ethernet  HWaddr 00:02:3F:8B:B8:79
          inet addr:192.168.0.166  Bcast:192.168.0.255  Mask:255.255.255.0
          inet6 addr: fe80::202:3fff:fe8b:b879/64 Scope:Link
          UP BROADCAST NOTRAILERS RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:3624 errors:0 dropped:0 overruns:0 frame:0
          TX packets:3904 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000
          RX bytes:2646421 (2.5 Mb)  TX bytes:575301 (561.8 Kb)
          Interrupt:10 Base address:0x4000

At this point RUNNING is in the output, but before it was not.  Here is the code I commented out from /etc/init.d/net.eth0 version 1.32:

# Check that the interface has a carrier
#if [ "${carrier_IFACE}" = "running" ]
#then
     /sbin/dhcpcd ${dhcpcd_IFACE} ${IFACE} >/dev/null || {
          retval=$?
          eend ${retval} "Failed to bring ${IFACE} up"
          return ${retval}
     }
#else
     #eend 1 "${IFACE} is not plugged in or has no carrier signal"
     #return 1
#fi

Hope this helps
Comment 7 Adrian Almenar 2003-11-19 06:59:08 UTC
AFAIK latest ~arch baselayout haas this, and its causing me problems with dhcp.

I hve the cable plugged and it always says "eth0 is not plugged in or has no carrier signal".

btw if i runn by hand dhcpcd eth0 my network card works perfectly.

Im using development-sources-2.6.0_beta9.
Comment 8 Aron Griffis (RETIRED) gentoo-dev 2004-05-07 15:39:24 UTC

*** This bug has been marked as a duplicate of 33272 ***