Created
June 16, 2013 13:56
-
-
Save lefant/5792139 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
. /etc/rc.conf | |
# leshaper, based on the fabulous wondershaper: | |
# Set the following values to somewhat less than your actual download | |
# and uplink speed. In kilobits. Also set the device that is to be shaped. | |
DOWNLINK=4000 | |
UPLINK=500 | |
DEV=ppp0 | |
case $1 in | |
autostart) | |
test x"${leshaper:-NO}" = x"NO" && exit 0 | |
exec $0 start | |
;; | |
start) | |
########## uplink ############### | |
# shape the root at UPLINK speed to keep the queue local no matter what | |
tc qdisc add dev $DEV root handle 1: tbf rate ${UPLINK}kbit burst 5k latency 50ms mpu 64b | |
# prio band on top of that (automagically prioritises interactive traffic according to TOS bits) | |
tc qdisc add dev $DEV parent 1: handle 11 prio | |
tc qdisc add dev $DEV parent 11:1 handle 111: sfq perturb 10 | |
tc qdisc add dev $DEV parent 11:2 handle 112: sfq perturb 10 | |
tc qdisc add dev $DEV parent 11:3 handle 113: sfq perturb 10 | |
# prioritize small packets (<64 bytes) into first class | |
tc filter add dev $DEV parent 11:0 protocol ip prio 1 u32 \ | |
match ip protocol 6 0xff \ | |
match u8 0x05 0x0f at 0 \ | |
match u16 0x0000 0xffc0 at 2 \ | |
flowid 11:1 | |
# higher prio for voip | |
tc filter add dev $DEV parent 11:0 protocol ip prio 2 u32 match ip src 172.23.1.29/32 flowid 11:1 | |
tc filter add dev $DEV parent 11:0 protocol ip prio 2 u32 match ip dport 4569 0xffff flowid 11:1 | |
tc filter add dev $DEV parent 11:0 protocol ip prio 2 u32 match ip sport 4569 0xffff flowid 11:1 | |
tc filter add dev $DEV parent 11:0 protocol ip prio 2 u32 match ip sport 5004 0xffff flowid 11:1 | |
########## downlink ############# | |
# slow downloads down to somewhat less than the real speed to prevent | |
# queuing at our ISP. Tune to see how high you can set it. | |
# ISPs tend to have *huge* queues to make sure big downloads are fast | |
# | |
# attach ingress policer: | |
tc qdisc add dev $DEV handle ffff: ingress | |
# filter *everything* (0.0.0.0/0), drop everything that's | |
# coming in too fast: | |
tc filter add dev $DEV parent ffff: protocol ip prio 50 u32 match ip src \ | |
0.0.0.0/0 police rate ${DOWNLINK}kbit burst 10k drop flowid :1 | |
;; | |
stop) | |
# clean existing down- and uplink qdiscs, hide errors | |
#tc qdisc del dev $DEV root 2> /dev/null > /dev/null | |
#tc qdisc del dev $DEV ingress 2> /dev/null > /dev/null | |
tc qdisc del dev $DEV root | |
tc qdisc del dev $DEV ingress | |
;; | |
restart) | |
$0 stop | |
$0 start | |
;; | |
status) | |
tc -s qdisc ls dev $DEV | |
tc -s class ls dev $DEV | |
;; | |
*) | |
echo "Usage: $0 {start | stop | restart}" | |
;; | |
esac | |
exit $? |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment