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 }
Created attachment 15170 [details] new /etc/init.d/net.eth0 with link check
*** Bug 26628 has been marked as a duplicate of this bug. ***
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.
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
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.
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
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.
*** This bug has been marked as a duplicate of 33272 ***