aboutsummaryrefslogtreecommitdiff
path: root/net
diff options
context:
space:
mode:
authorWilliam Hubbs <williamh@gentoo.org>2012-04-01 22:59:00 -0500
committerWilliam Hubbs <williamh@gentoo.org>2012-04-01 22:59:00 -0500
commit9127684553ea7b0f9285bc3fbe6c554f4519016c (patch)
treedac051ca1085fd02086a150230123ef18f014be2 /net
parent0571a7e05b658fc95da56d9df61e725eeda75a3c (diff)
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
Diffstat (limited to 'net')
-rw-r--r--net/ifconfig.sh.Linux.in26
-rw-r--r--net/iproute2.sh26
2 files changed, 26 insertions, 26 deletions
diff --git a/net/ifconfig.sh.Linux.in b/net/ifconfig.sh.Linux.in
index 411401da..8abc9983 100644
--- a/net/ifconfig.sh.Linux.in
+++ b/net/ifconfig.sh.Linux.in
@@ -24,19 +24,19 @@ _exists()
_ifindex()
{
- local line= i=-2
- while read line; do
- : $(( i += 1 ))
- [ ${i} -lt 1 ] && continue
- case "${line}" in
- "${IFACE}:"*) echo "${i}"; return 0;;
- esac
- done < /proc/net/dev
-
- # Return the next available index
- : $(( i += 1 ))
- echo "${i}"
- return 1
+ local index=-1
+ local f v
+ if [ -e /sys/class/net/"${IFACE}"/ifindex ]; then
+ index=$(cat /sys/class/net/"${IFACE}"/ifindex)
+ else
+ for f in /sys/class/net/*/ifindex ; do
+ v=$(cat $f)
+ [ $v -gt $index ] && index=$v
+ done
+ : $(( index += 1 ))
+ fi
+ echo "${index}"
+ return 0
}
_is_wireless()
diff --git a/net/iproute2.sh b/net/iproute2.sh
index e06152f8..b420e41b 100644
--- a/net/iproute2.sh
+++ b/net/iproute2.sh
@@ -25,19 +25,19 @@ _exists()
_ifindex()
{
- local line= i=-2
- while read line; do
- : $(( i += 1 ))
- [ ${i} -lt 1 ] && continue
- case "${line}" in
- "${IFACE}:"*) echo "${i}"; return 0;;
- esac
- done < /proc/net/dev
-
- # Return the next available index
- : $(( i += 1 ))
- echo "${i}"
- return 1
+ local index=-1
+ local f v
+ if [ -e /sys/class/net/"${IFACE}"/ifindex ]; then
+ index=$(cat /sys/class/net/"${IFACE}"/ifindex)
+ else
+ for f in /sys/class/net/*/ifindex ; do
+ v=$(cat $f)
+ [ $v -gt $index ] && index=$v
+ done
+ : $(( index += 1 ))
+ fi
+ echo "${index}"
+ return 0
}
_is_wireless()