-
Notifications
You must be signed in to change notification settings - Fork 69
/
SpeedLimiter
executable file
·64 lines (55 loc) · 1.32 KB
/
SpeedLimiter
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
#!/bin/sh
ACTION=$1
shift
if [[ "$ACTION" == "start" ]]; then
if [[ $# -lt 4 ]]; then
echo "Usage: $0 start [kps] [delay] [plr] [plr-suppress] [comma-separated hosts|\"any\"] [port1] <port2> .. <portn>"
fi
SPEED="$1Kbit/s"
shift
DELAY="$1ms"
shift
PLR="$1"
shift
PLR_SUPPRESS="$1"
shift
if [[ "$PLR_SUPPRESS" == "yes" ]]; then
PLR_SUPPRESS="noerror"
else
PLR_SUPPRESS=""
fi
HOSTS="${1//,/ }"
if [[ "$HOSTS" == "" ]]; then
HOSTS="any"
fi
shift
PIPE=100
while [[ -n "$1" ]]; do
PORT=$1
shift
for HOST in ${HOSTS[@]}; do
HOST=${HOST// /}
/sbin/ipfw add pipe $PIPE ip from $HOST $PORT to me
#/sbin/ipfw add pipe $PIPE ip from any $PORT to $HOST out
/sbin/ipfw pipe $((PIPE ++)) config $PLR_SUPPRESS bw $SPEED queue 64Kbytes delay $DELAY plr $PLR
/sbin/ipfw add pipe $PIPE ip from me $PORT to $HOST
#/sbin/ipfw add pipe $PIPE ip from any $PORT to $HOST in
/sbin/ipfw pipe $((PIPE ++)) config $PLR_SUPPRESS bw $SPEED queue 64Kbytes delay $DELAY plr $PLR
done
done
elif [[ "$ACTION" == "stop" ]]; then
if [[ $# -lt 2 ]]; then
echo "Usage: $0 stop [rule1] [rule2] <rule3> .. <rulen>"
exit 1
fi
while [[ -n "$1" ]]; do
RULE=$1
shift
/sbin/ipfw delete $RULE
done
elif [[ "$ACTION" == "list" ]]; then
/sbin/ipfw list $*
else
echo "Usage: $0 start/stop/list"
exit 1
fi