public
Description: A rigorous set of firewall scripts for BSD ipfw, and Linux iptables
Homepage:
Clone URL: git://github.com/jwiegley/jw.firewall.git
jw.firewall / setrate
100755 56 lines (45 sloc) 1.669 kb
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
#!/bin/bash
 
# The usage of this script is:
# setrate <interface index> <inbound KByte/s rate> <outbound rate>
#
# To find the interface index, use "ipfw pipe show"; the pipes are are
# number 100-109, sequentially based on the unique occurrance of the
# interfaces passed to rc.firewall.
#
# For example, if you passed "en1 en1 en2 en0 en0" (passing different
# networks for each), then their interface indices would be 0 1 2 3 4.
# However, since pipes are not duplicated for the same interface, the
# interface indices available for calling setrate would be 0 2 3.
 
base=$1
 
if [[ -n "$2" && -n "$3" ]]; then
    /sbin/ipfw -q pipe $((100 + base)) config bw ${2}Kbit/s
    /sbin/ipfw -q pipe $((110 + base)) config bw ${3}Kbit/s
 
    echo Set rate: inbound ${2}Kbit/s outbound ${3}Kbit/s
 
    exit 0
fi
 
rate=$(/sbin/ipfw pipe show $((100 + base)) | head -1 | awk '{print $2}')
 
case $(cat /var/run/firewall-type) in
    Home)
hour=$(($(expr $(date +%H))))
if (( $hour >= 0 && $hour <= 8 )); then
if [[ $rate != "1.450" ]]; then
/sbin/ipfw -q pipe $((100 + base)) config bw 1450Kbit/s
/sbin/ipfw -q pipe $((110 + base)) config bw 950Kbit/s
 
echo Set rate: inbound 1450Kbit/s outbound 950Kbit/s
fi
else
if [[ $rate != "750.000" ]]; then
/sbin/ipfw -q pipe $((100 + base)) config bw 750Kbit/s
/sbin/ipfw -q pipe $((110 + base)) config bw 500Kbit/s
 
echo Set rate: inbound 750Kbit/s outbound 500Kbit/s
fi
fi
;;
    *)
if [[ $rate != "unlimited" ]]; then
/sbin/ipfw -q pipe $((100 + base)) config bw 0
/sbin/ipfw -q pipe $((110 + base)) config bw 0
 
echo Set rate: inbound unlimited outbound unlimited
fi
;;
esac