if_: handle "Unknown" emitted by ethtool

Previously error messages were emitted due to this non-numeric value.

Closes: #3
This commit is contained in:
Lars Kruse 2020-08-22 20:26:27 +02:00
parent 710334b615
commit 8046268893
1 changed files with 6 additions and 4 deletions

View File

@ -16,10 +16,12 @@ config_if() {
echo "up.min 0"
echo "up.negative down"
echo "up.cdef up,8,*"
if [ -n "$(which ethtool)" ] && [ -x "$(which ethtool)" ] && ethtool "$INTERFACE" 2>/dev/null | grep -q Speed; then
MAX=$(($(ethtool "$INTERFACE" | grep Speed | sed -e 's/[[:space:]]\{1,\}/ /g' -e 's/^ //' -e 's/M.*//' | cut -d " " -f 2) * 1000000))
echo "up.max $MAX"
echo "down.max $MAX"
if [ -n "$(which ethtool)" ] && [ -x "$(which ethtool)" ]; then
MAX_MBPS=$(ethtool "$INTERFACE" 2>/dev/null | grep "Speed: [0-9]\+Mb/s$" | sed 's/[^0-9]//g')
if [ -n "$MAX_MBPS" ]; then
echo "up.max $((MAX_MBPS * 1024 * 1024))"
echo "down.max $((MAX_MBPS * 1024 * 1024))"
fi
fi
}
fetch_if() {