1 |
commit: 9127684553ea7b0f9285bc3fbe6c554f4519016c |
2 |
Author: William Hubbs <williamh <AT> gentoo <DOT> org> |
3 |
AuthorDate: Mon Apr 2 03:59:00 2012 +0000 |
4 |
Commit: William Hubbs <williamh <AT> gentoo <DOT> org> |
5 |
CommitDate: Mon Apr 2 03:59:00 2012 +0000 |
6 |
URL: http://git.overlays.gentoo.org/gitweb/?p=proj/openrc.git;a=commit;h=91276845 |
7 |
|
8 |
Change the method for calculating the interface metric for linux systems |
9 |
|
10 |
On linux systems running >=linux-3.2, the /proc/net/dev file cannot be |
11 |
relied on to show the order network interfaces were added to the system. |
12 |
Also, there is currently a bug in the implementation of the seek call |
13 |
for this file which can cause a system to go into an infinite loop. |
14 |
This commit changes the _ifindex function to retreive the value of |
15 |
/sys/class/net/${IFACE}/ifindex and use that value instead of attempting |
16 |
to calculate one from the interface's position in /proc/net/dev. |
17 |
|
18 |
reported-by: John Keeping <john.keeping <AT> lineone.net> |
19 |
X-Gentoo-Bug: 410127 |
20 |
X-Gentoo-Bug-URL: https://bugs.gentoo.org/show_bug.cgi?id=410127 |
21 |
|
22 |
--- |
23 |
net/ifconfig.sh.Linux.in | 26 +++++++++++++------------- |
24 |
net/iproute2.sh | 26 +++++++++++++------------- |
25 |
2 files changed, 26 insertions(+), 26 deletions(-) |
26 |
|
27 |
diff --git a/net/ifconfig.sh.Linux.in b/net/ifconfig.sh.Linux.in |
28 |
index 411401d..8abc998 100644 |
29 |
--- a/net/ifconfig.sh.Linux.in |
30 |
+++ b/net/ifconfig.sh.Linux.in |
31 |
@@ -24,19 +24,19 @@ _exists() |
32 |
|
33 |
_ifindex() |
34 |
{ |
35 |
- local line= i=-2 |
36 |
- while read line; do |
37 |
- : $(( i += 1 )) |
38 |
- [ ${i} -lt 1 ] && continue |
39 |
- case "${line}" in |
40 |
- "${IFACE}:"*) echo "${i}"; return 0;; |
41 |
- esac |
42 |
- done < /proc/net/dev |
43 |
- |
44 |
- # Return the next available index |
45 |
- : $(( i += 1 )) |
46 |
- echo "${i}" |
47 |
- return 1 |
48 |
+ local index=-1 |
49 |
+ local f v |
50 |
+ if [ -e /sys/class/net/"${IFACE}"/ifindex ]; then |
51 |
+ index=$(cat /sys/class/net/"${IFACE}"/ifindex) |
52 |
+ else |
53 |
+ for f in /sys/class/net/*/ifindex ; do |
54 |
+ v=$(cat $f) |
55 |
+ [ $v -gt $index ] && index=$v |
56 |
+ done |
57 |
+ : $(( index += 1 )) |
58 |
+ fi |
59 |
+ echo "${index}" |
60 |
+ return 0 |
61 |
} |
62 |
|
63 |
_is_wireless() |
64 |
|
65 |
diff --git a/net/iproute2.sh b/net/iproute2.sh |
66 |
index e06152f..b420e41 100644 |
67 |
--- a/net/iproute2.sh |
68 |
+++ b/net/iproute2.sh |
69 |
@@ -25,19 +25,19 @@ _exists() |
70 |
|
71 |
_ifindex() |
72 |
{ |
73 |
- local line= i=-2 |
74 |
- while read line; do |
75 |
- : $(( i += 1 )) |
76 |
- [ ${i} -lt 1 ] && continue |
77 |
- case "${line}" in |
78 |
- "${IFACE}:"*) echo "${i}"; return 0;; |
79 |
- esac |
80 |
- done < /proc/net/dev |
81 |
- |
82 |
- # Return the next available index |
83 |
- : $(( i += 1 )) |
84 |
- echo "${i}" |
85 |
- return 1 |
86 |
+ local index=-1 |
87 |
+ local f v |
88 |
+ if [ -e /sys/class/net/"${IFACE}"/ifindex ]; then |
89 |
+ index=$(cat /sys/class/net/"${IFACE}"/ifindex) |
90 |
+ else |
91 |
+ for f in /sys/class/net/*/ifindex ; do |
92 |
+ v=$(cat $f) |
93 |
+ [ $v -gt $index ] && index=$v |
94 |
+ done |
95 |
+ : $(( index += 1 )) |
96 |
+ fi |
97 |
+ echo "${index}" |
98 |
+ return 0 |
99 |
} |
100 |
|
101 |
_is_wireless() |