Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue #1701: Use a fallback to get interface state using the 'carrier' status #1719

Merged
merged 1 commit into from
Feb 8, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 26 additions & 2 deletions usr/share/rear/rescue/GNU/Linux/310_network_devices.sh
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,23 @@ function get_interface_state () {
local network_interface=$1
local sysfspath=/sys/class/net/$network_interface

cat $sysfspath/operstate
local operstate="$( cat $sysfspath/operstate )"
case "$operstate" in
down|up)
echo "$operstate"
;;
*)
# Some network drivers do not set "operstate" to "down" or "up", in
# such case, rely on "carrier", for which `cat` fails when link is
# administratively down, returns 0 when link is down and 1
# otherwise.
if [ $( cat $sysfspath/carrier 2>/dev/null || echo 0 ) -eq 0 ]; then
echo "down"
else
echo "up"
fi
;;
esac
}

function is_interface_up () {
Expand All @@ -303,7 +319,15 @@ function is_interface_up () {
elif [ "$state" = "up" ] ; then
return 0
else
BugError "Unexpected operational state '$state' for '$network_interface'."
# Some network drivers do not set "operstate" to "down" or "up", in
# such case, rely on "carrier", for which `cat` fails when link is
# administratively down, returns 0 when link is down and 1 otherwise.
state=$( cat $sysfspath/carrier 2>/dev/null || echo 0 )
if [ $state -eq 0 ]; then
return 1
else
return 0
fi
fi
}

Expand Down