Package: ifupdown-extra
Version: 0.15
Severity: important
Tags: patch

Motivation:
* wrong application paths for arping (from arping package) and ethtool
* ARP_TIMEOUT: anything less than 1500 microseconds is unreliable
* inaccurate arping options
* (not sure) but seems the logic around "ERROR: Duplicate address..." is
  broken
* to always return exit status 0 seems also broken

Bonus:
* useless quoting cleaned up
* reduced number of forks (sed is sufficient; grep and awk not needed in
  ip address extraction)
* executes ethtool only once


-- System Information:
Debian Release: wheezy/sid
  APT prefers unstable
  APT policy: (500, 'unstable'), (500, 'testing')
Architecture: i386 (i686)

Kernel: Linux 2.6.32-5-686 (SMP w/2 CPU cores)
Locale: LANG=C, LC_CTYPE=C (charmap=ANSI_X3.4-1968)
Shell: /bin/sh linked to /bin/bash


Cheers,

-- 
Cristian
--- if-up-scripts/check-duplicate-ip.orig	2009-08-01 01:28:10.000000000 +0200
+++ if-up-scripts/check-duplicate-ip	2011-02-19 12:10:13.000000000 +0100
@@ -36,21 +36,24 @@
 [ -r /etc/default/network-test ] && . /etc/default/network-test
 
 # Defaults
-ARPING=/usr/bin/arping
-ETHTOOL=/usr/sbin/ethtool
+ARPING=/usr/sbin/arping
+ETHTOOL=/sbin/ethtool
 ARP_COUNT=${ARP_COUNT:-2}
-ARP_TIMEOUT=${ARP_TIMEOUT:-3}
+# Time to wait between pings, in microseconds (man arping);
+# experiments show anything less than 1500 is unreliable.
+ARP_TIMEOUT=${ARP_TIMEOUT:-1500}
 DO_SYSLOG=${DO_SYSLOG:-yes}
 VERBOSITY=${VERBOSITY:-0}
 
 # Do not continue if ETHTOOL is not available
-[ ! -x "$ARPING" ] && exit 0
+[ ! -x $ARPING ] && exit 0
 # or if the user has told us to not do arpings
-[ "$DO_ARPING" = "no" ]  && exit 0
+[ "$DO_ARPING" = no ]  && exit 0
 
 # Try to obtain our IP address (DHCP case)
 if [ -z "$IF_ADDRESS" ] ; then
-        IF_ADDRESS=`ip addr show $IFACE | grep "inet " | awk '{print $2}' | sed -e 's/\/.*//'`
+	IF_ADDRESS=$(ip addr show $IFACE |
+		sed -rne 's|^[[:blank:]]*inet[[:blank:]]+([^/]+)/.*|\1|p')
 fi
 # Still no IP? Bail out
 [ -z "$IF_ADDRESS" ] && exit 0
@@ -60,10 +63,10 @@ fi
 LC_ALL=C
 export LC_ALL
 
-if [ "$DO_SYSLOG" = "yes" ] ; then
+if [ "$DO_SYSLOG" = yes ] ; then
 	OUTPUT="logger -i -p daemon.err -s"
 else
-	OUTPUT="echo"
+	OUTPUT=echo
 fi
 
 do_arping() {
@@ -75,24 +78,22 @@ do_arping() {
 # Do not do the check if ethtool (if installed) tells us the interface
 # does not have link, notice that ARPING will try to send the ARP requests
 # even if there is no link so we use this to speed things up
-	if [ -x "$ETHTOOL" ] ; then
-	        LINK=`$ETHTOOL $IFACE 2>&1| grep "Link detected"`
-	        if ! $ETHTOOL $IFACE | grep -q "Link detected: yes" ; then
-			return
-		fi
+	if [ -x $ETHTOOL ] ; then
+		LINK=$($ETHTOOL $IFACE 2>&1 | grep "Link[[:blank:]]\+detected:")
+		echo $LINK | grep -q "yes$" || return
 	fi
 
 	for ADDR in $IF_ADDRESS; do
 		[ "$VERBOSITY" -eq 1 ] && $OUTPUT "DEBUG: Sending arp pings through $IFACE to detect other systems using $ADDR"
-		if ! $ARPING -q -c $ARP_COUNT -w $ARP_TIMEOUT -D -I $IFACE $ADDR ; then
+		if $ARPING -q -c $ARP_COUNT -w $ARP_TIMEOUT -D -i $IFACE $ADDR >/dev/null ; then
 			$OUTPUT "ERROR: Duplicate address $ADDR assigned in the network where $IFACE is connected to"
+			return 1
 		fi
 	done
 }
 
 # Check our IFACE name, if it does not start with eth, bail out
-case "$IFACE" in 
+case $IFACE in
 	eth*) do_arping ;;
 	*) ;;
 esac
-exit 0

Reply via email to