UPWAN1=90000
DOWNWAN1=90000
OTHERUPOne=60
OTHERDOWNOne=60
OTHERUPTwo=30
OTHERDOWNTwo=30
OTHERUPThree=10
OTHERDOWNThree=10
OTHERUPMax=90
OTHERDOWNMax=90
insmod imq
insmod ipt_IMQ
ifconfig imq0 up
ifconfig imq1 up
insmod xt_web.ko
insmod xt_length.ko
insmod xt_hashlimit.ko
wan1=$(nvram get wan_iface)
iptables -t mangle -N QOSDOWN
iptables -t mangle -N QOSUP
iptables -t mangle -F QOSDOWN
iptables -t mangle -F QOSUP
iptables -t mangle -F FORWARD
iptables -t mangle -I FORWARD -j IPTRAFFIC_I
iptables -t mangle -I FORWARD -i br0 -j QOSDOWN
iptables -t mangle -I FORWARD -o br0 -j QOSUP
iptables -t mangle -A FORWARD -i br0 -j IMQ --todev 1
iptables -t mangle -A FORWARD -o br0 -j IMQ --todev 0
DOWNOTHEROne=$(($DOWNWAN1*$OTHERDOWNOne/100))
UPOTHEROne=$(($UPWAN1*$OTHERUPOne/100))
DOWNOTHERTwo=$(($DOWNWAN1*$OTHERDOWNTwo/100))
UPOTHERTwo=$(($UPWAN1*$OTHERUPTwo/100))
DOWNOTHERThree=$(($DOWNWAN1*$OTHERDOWNThree/100))
UPOTHERThree=$(($UPWAN1*$OTHERUPThree/100))
DOWNOTHERMax=$(($DOWNWAN1*$OTHERDOWNMax/100))
UPOTHERMax=$(($UPWAN1*$OTHERUPMax/100))
DOWN=$(($DOWNOTHEROne))
UP=$(($UPOTHEROne))
DOWNWEB=$(($DOWNOTHERTwo))
UPWEB=$(($UPOTHERTwo))
DOWNP2P=$(($DOWNOTHERThree))
UPP2P=$(($UPOTHERThree))
DOWNLITTLE=$(($DOWN*20/100))
DOWNSYN=$(($DOWN*20/100))
DOWNGUA=$(($DOWN*60/100))
DOWNWWW=$(($DOWNWEB*60/100))
DOWNMEDIA=$(($DOWNWEB*40/100))
DOWNDOWN=$(($DOWNP2P*60/100))
DOWNDOWNP2P=$(($DOWNP2P*40/100))
UPLITTLE=$(($UP*20/100))
UPSYN=$(($UP*20/100))
UPGUA=$(($UP*60/100))
UPWWW=$(($UPWEB*60/100))
UPMEDIA=$(($UPWEB*40/100))
UPUP=$(($UPP2P*60/100))
UPUPP2P=$(($UPP2P*40/100))
tc qdisc del dev imq1 root
tc qdisc add dev imq1 root handle 1: htb default 50 r2q 2
tc class add dev imq1 parent 1: classid 1:11 htb rate ${DOWN}kbps ceil ${DOWN}kbps prio 0
tc class add dev imq1 parent 1: classid 1:12 htb rate ${DOWNWEB}kbps ceil ${DOWNOTHERMax}kbps prio 1
tc class add dev imq1 parent 1: classid 1:13 htb rate ${DOWNP2P}kbps ceil ${DOWNOTHERMax}kbps prio 1
tc class add dev imq1 parent 1:11 classid 1:10 htb rate ${DOWNLITTLE}kbps ceil ${DOWN}kbps prio 0
tc class add dev imq1 parent 1:11 classid 1:20 htb rate ${DOWNSYN}kbps ceil ${DOWN}kbps prio 1
tc class add dev imq1 parent 1:11 classid 1:40 htb rate ${DOWNGUA}kbps ceil ${DOWN}kbps prio 2
tc class add dev imq1 parent 1:12 classid 1:50 htb rate ${DOWNWWW}kbps ceil ${DOWNOTHERMax}kbps prio 0
tc class add dev imq1 parent 1:12 classid 1:30 htb rate ${DOWNMEDIA}kbps ceil ${DOWNOTHERMax}kbps prio 1
tc class add dev imq1 parent 1:13 classid 1:80 htb rate ${DOWNDOWN}kbps ceil ${DOWNOTHERMax}kbps prio 0
tc class add dev imq1 parent 1:13 classid 1:90 htb rate ${DOWNDOWNP2P}kbps ceil ${DOWNOTHERMax}kbps prio 1
tc qdisc add dev imq1 parent 1:10 handle 10: sfq perturb 10
tc qdisc add dev imq1 parent 1:20 handle 20: sfq perturb 10
tc qdisc add dev imq1 parent 1:30 handle 30: sfq perturb 10
tc qdisc add dev imq1 parent 1:40 handle 40: sfq perturb 10
tc qdisc add dev imq1 parent 1:50 handle 50: sfq perturb 10
tc qdisc add dev imq1 parent 1:80 handle 80: sfq perturb 10
tc qdisc add dev imq1 parent 1:90 handle 90: sfq perturb 10
tc filter add dev imq1 parent 1: protocol ip handle 1 fw flowid 1:10
tc filter add dev imq1 parent 1: protocol ip handle 2 fw flowid 1:20
tc filter add dev imq1 parent 1: protocol ip handle 3 fw flowid 1:30
tc filter add dev imq1 parent 1: protocol ip handle 4 fw flowid 1:40
tc filter add dev imq1 parent 1: protocol ip handle 5 fw flowid 1:50
tc filter add dev imq1 parent 1: protocol ip handle 8 fw flowid 1:80
tc filter add dev imq1 parent 1: protocol ip handle 9 fw flowid 1:90
tc qdisc del dev imq0 root
tc qdisc add dev imq0 root handle 1: htb default 50
tc class add dev imq0 parent 1: classid 1:11 htb rate ${UP}kbps ceil ${UP}kbps prio 0
tc class add dev imq0 parent 1: classid 1:12 htb rate ${UPWEB}kbps ceil ${UPOTHERMax}kbps prio 1
tc class add dev imq0 parent 1: classid 1:13 htb rate ${UPP2P}kbps ceil ${UPOTHERMax}kbps prio 1
tc class add dev imq0 parent 1:11 classid 1:10 htb rate ${UPLITTLE}kbps ceil ${UP}kbps prio 0
tc class add dev imq0 parent 1:11 classid 1:20 htb rate ${UPSYN}kbps ceil ${UP}kbps prio 1
tc class add dev imq0 parent 1:11 classid 1:40 htb rate ${UPGUA}kbps ceil ${UP}kbps prio 2
tc class add dev imq0 parent 1:12 classid 1:50 htb rate ${UPWWW}kbps ceil ${UPOTHERMax}kbps prio 0
tc class add dev imq0 parent 1:12 classid 1:30 htb rate ${UPMEDIA}kbps ceil ${UPOTHERMax}kbps prio 1
tc class add dev imq0 parent 1:13 classid 1:80 htb rate ${UPUP}kbps ceil ${UPOTHERMax}kbps prio 0
tc class add dev imq0 parent 1:13 classid 1:90 htb rate ${UPUPP2P}kbps ceil ${UPOTHERMax}kbps prio 1
tc qdisc add dev imq0 parent 1:10 handle 10: sfq perturb 10
tc qdisc add dev imq0 parent 1:20 handle 20: sfq perturb 10
tc qdisc add dev imq0 parent 1:30 handle 30: sfq perturb 10
tc qdisc add dev imq0 parent 1:40 handle 40: sfq perturb 10
tc qdisc add dev imq0 parent 1:50 handle 50: sfq perturb 10
tc qdisc add dev imq0 parent 1:80 handle 80: sfq perturb 10
tc qdisc add dev imq0 parent 1:90 handle 90: sfq perturb 10
tc filter add dev imq0 parent 1: protocol ip handle 1 fw flowid 1:10
tc filter add dev imq0 parent 1: protocol ip handle 2 fw flowid 1:20
tc filter add dev imq0 parent 1: protocol ip handle 3 fw flowid 1:30
tc filter add dev imq0 parent 1: protocol ip handle 4 fw flowid 1:40
tc filter add dev imq0 parent 1: protocol ip handle 5 fw flowid 1:50
tc filter add dev imq0 parent 1: protocol ip handle 8 fw flowid 1:80
tc filter add dev imq0 parent 1: protocol ip handle 9 fw flowid 1:90
iptables -t mangle -A QOSDOWN -j CONNMARK --restore-mark
iptables -t mangle -A QOSDOWN -m mark --mark 3 -j RETURN
iptables -t mangle -A QOSDOWN -p ! tcp -m length --length :256 -j MARK --set-mark-return 1
iptables -t mangle -A QOSDOWN -p ! tcp -m hashlimit --hashlimit 20/sec --hashlimit-burst 100 --hashlimit-mode dstip --hashlimit-name fastconn_down -j MARK --set-mark-return 4
iptables -t mangle -A QOSDOWN -p ! tcp -j MARK --set-mark-return 9
iptables -t mangle -A QOSDOWN -p tcp --syn -j MARK --set-mark-return 2
iptables -t mangle -A QOSDOWN -p tcp --sport 443 -j MARK --set-mark-return 5
iptables -t mangle -A QOSDOWN -p tcp --sport ! 80 -m state --state ESTABLISHED -m length --length :256 -j MARK --set-mark-return 1
iptables -t mangle -A QOSDOWN -p tcp --sport ! 80 -m hashlimit --hashlimit 20/sec --hashlimit-burst 100 --hashlimit-mode dstip --hashlimit-name fastconn_down -j MARK --set-mark-return 4
iptables -t mangle -A QOSDOWN -p tcp --sport ! 80 -j MARK --set-mark-return 9
iptables -t mangle -A QOSDOWN -p tcp --sport 80 -j BCOUNT
iptables -t mangle -A QOSDOWN -p tcp --sport 80 -m bcount --range :500000 -j CONNMARK --set-return 0x5/0xff
iptables -t mangle -A QOSDOWN -p tcp --sport 80 -m bcount --range 500001: -j CONNMARK --set-return 0x8/0xff
iptables -t mangle -A QOSUP -j CONNMARK --restore-mark
iptables -t mangle -A QOSUP -m mark --mark 3 -j RETURN
iptables -t mangle -A QOSUP -p ! tcp -m length --length :256 -j MARK --set-mark-return 1
iptables -t mangle -A QOSUP -p ! tcp -m hashlimit --hashlimit 15/sec --hashlimit-burst 100 --hashlimit-mode srcip --hashlimit-name fastconn_up -j MARK --set-mark-return 4
iptables -t mangle -A QOSUP -p ! tcp -j MARK --set-mark-return 9
iptables -t mangle -A QOSUP -p tcp -m web --path ".flv .mp4 .f4v .swf" -j CONNMARK --set-return 0x3/0xff
iptables -t mangle -A QOSUP -j CONNMARK --restore-mark
iptables -t mangle -A QOSUP -m mark --mark 3 -j RETURN
iptables -t mangle -A QOSUP -p tcp --syn -j MARK --set-mark-return 2
iptables -t mangle -A QOSUP -p tcp --dport 443 -j MARK --set-mark-return 5
iptables -t mangle -A QOSUP -p tcp --dport ! 80 -m length --length :256 -j MARK --set-mark-return 1
iptables -t mangle -A QOSUP -p tcp --dport ! 80 -m hashlimit --hashlimit 15/sec --hashlimit-burst 100 --hashlimit-mode srcip --hashlimit-name fastconn_up -j MARK --set-mark-return 4
iptables -t mangle -A QOSUP -p tcp --dport ! 80 -j MARK --set-mark-return 9
iptables -t mangle -A QOSUP -p tcp --dport 80 -j BCOUNT
iptables -t mangle -A QOSUP -p tcp --dport 80 -m bcount --range :40000 -j MARK --set-mark-return 5
iptables -t mangle -A QOSUP -p tcp --dport 80 -m bcount --range 40001: -j MARK --set-mark-return 8
阅读(741) | 评论(0) | 转发(0) |