From a57bb5741f8edca476a01cecd5b05f96804ae140 Mon Sep 17 00:00:00 2001 From: Willy Tarreau Date: Fri, 3 Oct 2014 11:48:08 +0200 Subject: check-new-if: sort interfaces in /proc/net/dev Recent kernels dump interfaces in a random order. Since the script heavily relies on the ordering from there, this causes a total mess with interfaces being inserted anywhere. Example : root:~# cat /proc/net/dev Inter-| Receive | Transmit face |bytes packets errs drop fifo frame compressed multicast|bytes packets errs drop fifo colls carrier compressed eth6: 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 eth7: 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 eth0: 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 eth8: 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 eth1: 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 eth9: 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 eth2: 22598789 351676 0 30703 0 0 0 30903 464 4 0 0 0 0 0 0 eth3: 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 eth4: 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 lo: 2228 16 0 0 0 0 0 0 2228 16 0 0 0 0 0 0 eth5: 0 0 0 0 0 0 0 0 538 5 0 0 0 0 0 0 Luckily, the system prints interface names padded left with spaces, so in practice a sort always dumps them in proper order, and "lo" is always before "eth*" just like "bond" is always after "eth". So this patch sorts /proc/net/dev before reading it. Note that while acceptable as a temporary solution, a better one should be found with real parsing of interface numbers in the long term. --- check-new-if | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/check-new-if b/check-new-if index 93f883a..c6d2507 100755 --- a/check-new-if +++ b/check-new-if @@ -14,9 +14,8 @@ awk -v f=/etc/config.rc '\ } BEGIN { old=""; changed=0; - while (getline < "/proc/net/dev") - if ($1 ~ ":$") { - sub(":", "", $1); + while ("sort /proc/net/dev" | getline) + if (sub(":$", "", $1)) { prv[$1]=old; nxt[old]=$1; decl[$1]=0; -- 1.7.12.1