Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/sh
- MAC1=00:11:32:00:00:00
- MAC2=78:24:AF:00:00:00
- PORTRANGE1=1024:65535 #torrentbox
- PORTRANGE2=22 #ssh
- # TOS rules
- # Torrents from server, lowest priority
- iptables -t mangle -I QOSO 3 -p tcp -m mac --mac-source ${MAC1} -m multiport --sports ${PORTRANGE1} -j RETURN
- iptables -t mangle -I QOSO 3 -p tcp -m mac --mac-source ${MAC1} -m multiport --sports ${PORTRANGE1} -j CONNMARK --set-return 0x5/0x7
- iptables -t mangle -I QOSO 3 -p udp -m mac --mac-source ${MAC1} -m multiport --sports ${PORTRANGE1} -j RETURN
- iptables -t mangle -I QOSO 3 -p udp -m mac --mac-source ${MAC1} -m multiport --sports ${PORTRANGE1} -j CONNMARK --set-return 0x5/0x7
- # ip6tables -t mangle -I QOSO 3 -p tcp -m mac --mac-source ${MAC1} -m multiport --sports ${PORTRANGE1} -j RETURN
- # ip6tables -t mangle -I QOSO 3 -p tcp -m mac --mac-source ${MAC1} -m multiport --sports ${PORTRANGE1} -j CONNMARK --set-return 0x5/0x7
- # ip6tables -t mangle -I QOSO 3 -p udp -m mac --mac-source ${MAC1} -m multiport --sports ${PORTRANGE1} -j RETURN
- # ip6tables -t mangle -I QOSO 3 -p udp -m mac --mac-source ${MAC1} -m multiport --sports ${PORTRANGE1} -j CONNMARK --set-return 0x5/0x7
- # Remote SSH from server
- iptables -t mangle -I QOSO 3 -p tcp -m mac --mac-source ${MAC2} --sport ${PORTRANGE2} -j RETURN
- iptables -t mangle -I QOSO 3 -p tcp -m mac --mac-source ${MAC2} --sport ${PORTRANGE2} -j CONNMARK --set-return 0x1/0x7
- # ip6tables -t mangle -I QOSO 3 -p tcp -m mac --mac-source ${MAC2} --sport ${PORTRANGE2} -j RETURN
- # ip6tables -t mangle -I QOSO 3 -p tcp -m mac --mac-source ${MAC2} --sport ${PORTRANGE2} -j CONNMARK --set-return 0x1/0x7
- # ICMP
- iptables -t mangle -I QOSO 3 -p icmp --icmp-type 8 -j RETURN
- iptables -t mangle -I QOSO 3 -p icmp --icmp-type 8 -j CONNMARK --set-return 0x1/0x7
- iptables -t mangle -I QOSO 3 -p icmp --icmp-type 0 -j RETURN
- iptables -t mangle -I QOSO 3 -p icmp --icmp-type 0 -j CONNMARK --set-return 0x1/0x7
- # ip6tables -t mangle -I QOSO 3 -p icmpv6 --icmpv6-type 128 -j RETURN
- # ip6tables -t mangle -I QOSO 3 -p icmpv6 --icmpv6-type 128 -j CONNMARK --set-return 0x1/0x7
- # ip6tables -t mangle -I QOSO 3 -p icmpv6 --icmpv6-type 129 -j RETURN
- # ip6tables -t mangle -I QOSO 3 -p icmpv6 --icmpv6-type 129 -j CONNMARK --set-return 0x1/0x7
- ######################################################################
- DEV=$(nvram get wan0_ifname)
- CEIL=2048 #maximum upload in kbits/s
- #Rates
- HIGHEST=20
- HIGH=29
- MEDIUM=1
- LOW=40
- LOWEST=10
- #Upper limit
- HIGHEST_LIM=90
- HIGH_LIM=70
- MEDIUM_LIM=1
- LOW_LIM=80
- LOWEST_LIM=50
- tc qdisc del dev ${DEV} root
- tc qdisc del dev ${DEV} ingress
- tc qdisc add dev ${DEV} stab linklayer adsl overhead 40 mtu 1492 mpu 53 root handle 1: hfsc default 40
- # Upload 1:1
- tc class add dev ${DEV} parent 1: classid 1:1 hfsc sc rate ${CEIL}kbit ul rate ${CEIL}kbit
- # download 1:2
- tc class add dev ${DEV} parent 1: classid 1:2 htb rate 1000000kbit ceil 1000000kbit burst 10000 cburst 10000
- # 1:60 ALL Download for BCM
- tc class add dev ${DEV} parent 1:2 classid 1:60 htb rate 1000000kbit ceil 1000000kbit burst 10000 cburst 10000 prio 6
- tc qdisc add dev ${DEV} parent 1:60 handle 60: pfifo
- tc filter add dev ${DEV} parent 1: prio 6 protocol 802.1q handle 6 fw flowid 1:60
- # Upload HIGHEST
- tc class add dev ${DEV} parent 1:1 classid 1:10 hfsc sc umax 1492b dmax 20ms rate $(($HIGHEST*$CEIL/100))kbit ls rate $(($HIGHEST_LIM*$CEIL/100))kbit ul rate ${CEIL}kbit
- tc qdisc add dev ${DEV} parent 1:10 handle 10: sfq limit 127 perturb 10
- tc filter add dev ${DEV} protocol all parent 1: prio 10 handle 1 fw classid 1:10
- tc filter add dev ${DEV} protocol all prio 1 parent 10: handle 10 flow hash keys nfct-src divisor 1024
- echo " TC Class 1:110 defined."
- # Upload HIGH
- tc class add dev ${DEV} parent 1:1 classid 1:20 hfsc sc umax 1492b dmax 33ms rate $(($HIGH*$CEIL/100))kbit ls rate $(($HIGH_LIM*$CEIL/100))kbit ul rate ${CEIL}kbit
- # tc class add dev ${DEV} parent 1:1 classid 1:20 hfsc sc rate $(($HIGH*$CEIL/100))kbit ls rate $(($HIGH_LIM*$CEIL/100))kbit ul rate ${CEIL}kbit
- tc qdisc add dev ${DEV} parent 1:20 handle 20: sfq limit 127 perturb 10
- tc filter add dev ${DEV} protocol all parent 1: prio 20 handle 2 fw classid 1:20
- tc filter add dev ${DEV} protocol all prio 1 parent 20: handle 20 flow hash keys nfct-src divisor 1024
- # Ack packets
- tc filter add dev ${DEV} parent 1:0 protocol ip prio 14 u32\
- match ip protocol 6 0xff\
- match u8 0x05 0x0f at 0\
- match u16 0x0000 0xffc0 at 2\
- match u8 0x10 0xff at 33 flowid 1:10
- # Syn packets
- tc filter add dev ${DEV} parent 1:0 protocol ip prio 15 u32\
- match ip protocol 6 0xff\
- match u8 0x05 0x0f at 0\
- match u16 0x0000 0xffc0 at 2\
- match u8 0x02 0x02 at 33 flowid 1:10
- echo " TC Class 1:120 defined."
- # Upload MEDIUM
- tc class add dev ${DEV} parent 1:1 classid 1:30 hfsc sc rate $(($MEDIUM*$CEIL/100))kbit ls rate $(($MEDIUM_LIM*$CEIL/100))kbit ul rate ${CEIL}kbit
- tc qdisc add dev ${DEV} parent 1:30 handle 30: sfq limit 127 perturb 10
- tc filter add dev ${DEV} protocol all parent 1: prio 30 handle 3 fw classid 1:30
- tc filter add dev ${DEV} protocol all prio 1 parent 30: handle 30 flow hash keys nfct-src divisor 1024
- echo " TC Class 1:130 defined."
- # Upload LOW (default)
- tc class add dev ${DEV} parent 1:1 classid 1:40 hfsc sc umax 1492b dmax 40ms rate $(($LOW*$CEIL/100))kbit ls rate $(($LOW_LIM*$CEIL/100))kbit ul rate ${CEIL}kbit
- # tc class add dev ${DEV} parent 1:1 classid 1:40 hfsc sc rate $(($LOW*$CEIL/100))kbit ls rate $(($LOW_LIM*$CEIL/100))kbit ul rate ${CEIL}kbit
- tc qdisc add dev ${DEV} parent 1:40 handle 40: sfq limit 127 perturb 10
- tc filter add dev ${DEV} protocol all parent 1: prio 40 handle 4 fw classid 1:40
- tc filter add dev ${DEV} protocol all prio 1 parent 40: handle 40 flow hash keys nfct-src divisor 1024
- echo " TC Class 1:140 defined."
- # Upload LOWEST
- tc class add dev ${DEV} parent 1:1 classid 1:50 hfsc sc umax 1492b dmax 100ms rate $(($LOWEST*$CEIL/100))kbit ls rate $((LOWEST_LIM*$CEIL/100))kbit ul rate ${CEIL}kbit
- # tc class add dev ${DEV} parent 1:1 classid 1:50 hfsc sc rate $(($LOWEST*$CEIL/100))kbit ls rate $((LOWEST_LIM*$CEIL/100))kbit ul rate ${CEIL}kbit
- tc qdisc add dev ${DEV} parent 1:50 handle 50: sfq limit 127 perturb 10
- tc filter add dev ${DEV} protocol all parent 1: prio 50 handle 5 fw classid 1:50
- tc filter add dev ${DEV} protocol all prio 1 parent 50: handle 50 flow hash keys nfct-src divisor 1024
- echo " TC Class 1:150 defined."
Advertisement
Add Comment
Please, Sign In to add comment