Change the method for calculating the interface metric for linux systems

On linux systems running  >=linux-3.2, the /proc/net/dev file cannot be
relied on to show the order network interfaces were added to the system.
Also, there is currently a bug in the implementation of the seek call
for this file which can cause a system to go into an infinite loop.
This commit changes the _ifindex function to retreive the value of
/sys/class/net/${IFACE}/ifindex and use that value instead of attempting
to calculate one from the interface's position in /proc/net/dev.

reported-by: John Keeping <john.keeping@lineone.net>
X-Gentoo-Bug: 410127
X-Gentoo-Bug-URL: https://bugs.gentoo.org/show_bug.cgi?id=410127
This commit is contained in:
William Hubbs 2012-04-01 22:59:00 -05:00
parent 0571a7e05b
commit 9127684553
2 changed files with 26 additions and 26 deletions

View File

@ -24,19 +24,19 @@ _exists()
_ifindex() _ifindex()
{ {
local line= i=-2 local index=-1
while read line; do local f v
: $(( i += 1 )) if [ -e /sys/class/net/"${IFACE}"/ifindex ]; then
[ ${i} -lt 1 ] && continue index=$(cat /sys/class/net/"${IFACE}"/ifindex)
case "${line}" in else
"${IFACE}:"*) echo "${i}"; return 0;; for f in /sys/class/net/*/ifindex ; do
esac v=$(cat $f)
done < /proc/net/dev [ $v -gt $index ] && index=$v
done
# Return the next available index : $(( index += 1 ))
: $(( i += 1 )) fi
echo "${i}" echo "${index}"
return 1 return 0
} }
_is_wireless() _is_wireless()

View File

@ -25,19 +25,19 @@ _exists()
_ifindex() _ifindex()
{ {
local line= i=-2 local index=-1
while read line; do local f v
: $(( i += 1 )) if [ -e /sys/class/net/"${IFACE}"/ifindex ]; then
[ ${i} -lt 1 ] && continue index=$(cat /sys/class/net/"${IFACE}"/ifindex)
case "${line}" in else
"${IFACE}:"*) echo "${i}"; return 0;; for f in /sys/class/net/*/ifindex ; do
esac v=$(cat $f)
done < /proc/net/dev [ $v -gt $index ] && index=$v
done
# Return the next available index : $(( index += 1 ))
: $(( i += 1 )) fi
echo "${i}" echo "${index}"
return 1 return 0
} }
_is_wireless() _is_wireless()