[ARMedslack] A little rc.inet1 tweek

Davide louigi600 at yahoo.it
Wed Aug 21 19:30:06 UTC 2013


I've found that after ethernet module is loaded the link status in not reliable until the interface has been brought up for at least a few seconds.

I often use my laptops both in presence and absence of DHCP servers. I found the default way that the script detects the link status unreliable so I make this change to my rc.inetd (Maybe someone else likes it too ;-) ):
--- rc.inet1    2013-08-17 21:44:25.040707457 +0200
+++ rc.inet1_new        2013-08-17 21:44:06.020603342 +0200
@@ -160,8 +160,25 @@
         #fi
         #### (end commented out)
         # 10 seconds should be a reasonable default DHCP timeout.  30 was too much.
-        echo "/etc/rc.d/rc.inet1:  /sbin/dhcpcd -t ${DHCP_TIMEOUT[$i]:-10} ${DHCP_OPTIONS} ${1}" | $LOGGER
-        /sbin/dhcpcd -t ${DHCP_TIMEOUT[$i]:-10} ${DHCP_OPTIONS} ${1}
+        ifconfig ${1} up
+        STOP=$(expr $(/usr/bin/date +%s) + 5)
+        echo -n "Waiting for link ."
+        while [ $(/usr/bin/date +%s) -le $STOP ]; do
+          echo -n "."
+          [ "$(cat /sys/class/net/${1}/carrier 2> /dev/null)" = "1" ] && break
+          sleep 0.5
+        done
+        CONNSTATUS="$(cat /sys/class/net/${1}/carrier 2> /dev/null)"
+        ifconfig ${1} down
+        if [ "$CONNSTATUS" -eq 1 ]; then
+          echo " ${1} is uplinked"
+          echo "Polling for DHCP server on interface ${1}:"
+          echo "/etc/rc.d/rc.inet1:  /sbin/dhcpcd -t ${DHCP_TIMEOUT[$i]:-10} ${DHCP_OPTIONS} ${1}" | $LOGGER
+          /sbin/dhcpcd -t ${DHCP_TIMEOUT[$i]:-10} ${DHCP_OPTIONS} ${1}
+        else
+          echo " ${1} is not linked"
+          echo "/etc/rc.d/rc.inet1: interface ${1} is not linked" |$LOGGER
+        fi
       else # bring up interface using a static IP address
         if [ ! "${IPADDR[$i]}" = "" ]; then # skip unconfigured interfaces
           # Determine broadcast address from the IP address and netmask:
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.armedslack.org/pipermail/armedslack/attachments/20130821/8caf9994/attachment-0001.html>


More information about the ARMedslack mailing list