39 lines
904 B
Bash
Executable file
39 lines
904 B
Bash
Executable file
#!/bin/sh
|
|
|
|
source $(dirname $0)/traffic_common.sh
|
|
|
|
# update traffic counters
|
|
TCur=$((
|
|
$(ip -s link show $IF \
|
|
| awk '{ if (FNR == 4) print $1 " + "; if (FNR == 6) print $1 }' \
|
|
| tr -d "\n")
|
|
))
|
|
# test for invalid cur values (negative number or invalid number format (ret=2))
|
|
if [ "$TCur" -lt 0 ] 2>/dev/null || [ $? -eq 2 ]; then
|
|
# TODO: log error
|
|
exit -1
|
|
fi
|
|
UpdatePer=false
|
|
if [ $TCur -lt $TObs ]; then
|
|
# interface counter has been reset
|
|
TEph=$(($TEph + $TCur))
|
|
# TODO: log warning
|
|
else
|
|
TEph=$(($TEph + $TCur - $TObs))
|
|
fi
|
|
TObs=$TCur
|
|
TPer=$(($TPer + $TEph))
|
|
if [ $TEph -gt $MaxPerTrafficDiff ]; then
|
|
# TODO: log _once_ if TPer exceeds TMax
|
|
TEph=0
|
|
echo $TPer > $TPerFile
|
|
fi
|
|
echo $TEph > $TEphFile
|
|
echo $TObs > $TObsFile
|
|
|
|
# act if traffic max is reached
|
|
if [ $TPer -gt $TMax ]; then
|
|
tc qdisc add dev $IF root tbf rate 80kbit latency 50ms burst 3000
|
|
else
|
|
tc qdisc del dev $IF root
|
|
fi
|