#!/bin/bash ########################## # Roberts QoS traffic-shaper. Taken from parts of wondershaper, gentoo-wiki and www.ip-phone-forum.de; thank you # guys :) # You need iptables, iproute2 and l7-filter kernel patches. # Please look at www.robert-peter.de/yats/ for more information ########################## iptables="/sbin/iptables" tc="/sbin/tc" # Constants for better readability MARKPRIO1="1" MARKPRIO2="2" MARKPRIO3="3" MARKPRIO4="4" # set this to your outgoing device DEV=ppp0 # set it a little lower than your actual uplink in kbit # (I have 448kbit uplink) UPLINK=420 ################# begin ############## # flush mangle-table, if you are using other scripts using packet-mangling, you have to take care by yourself $iptables -t mangle -F #### Set priority marks to outgoing packets ### Prio 1 - Highest # icmp $iptables -t mangle -o $DEV -A POSTROUTING -p icmp -j MARK --set-mark $MARKPRIO1 # ssh $iptables -t mangle -o $DEV -A POSTROUTING -m layer7 --l7proto ssh -j MARK --set-mark $MARKPRIO1 # voip $iptables -t mangle -o $DEV -A POSTROUTING -m layer7 --l7proto sip -j MARK --set-mark $MARKPRIO1 # TOS min-delay $iptables -t mangle -o $DEV -A POSTROUTING -p tcp -m tos --tos Minimize-Delay -j MARK --set-mark $MARKPRIO1 ## Prio 2 #TCP ACKs $iptables -t mangle -o $DEV -A POSTROUTING -p tcp -m length --length :64 -j MARK --set-mark $MARKPRIO2 # TOS max-throughput $iptables -t mangle -o $DEV -A POSTROUTING -p tcp -m tos --tos Maximize-Throughput -j MARK --set-mark $MARKPRIO2 ## Prio 3 is the default class ## Prio 4 - Lowest # mldonkey $iptables -t mangle -o $DEV -A POSTROUTING -m layer7 --l7proto edonkey -j MARK --set-mark $MARKPRIO4 # TOS min-cost $iptables -t mangle -o $DEV -A POSTROUTING -p tcp -m tos --tos Minimize-Cost -j MARK --set-mark $MARKPRIO4 ####### set up classes and queues # (describe four classes here) # first wipe out the old ones $tc qdisc del dev $DEV root 2> /dev/null > /dev/null $tc qdisc del dev $DEV ingress 2> /dev/null > /dev/null # Specify queue discipline $tc qdisc add dev $DEV root handle 1: htb default 30 # Set root class $tc class add dev $DEV parent 1: classid 1:1 htb rate ${UPLINK}kbit # Specify sub classes $tc class add dev $DEV parent 1:1 classid 1:10 htb rate $[50*UPLINK/100]kbit ceil ${UPLINK}kbit prio 1 $tc class add dev $DEV parent 1:1 classid 1:20 htb rate $[30*UPLINK/100]kbit ceil ${UPLINK}kbit prio 2 $tc class add dev $DEV parent 1:1 classid 1:30 htb rate $[20*UPLINK/100]kbit ceil ${UPLINK}kbit prio 3 $tc class add dev $DEV parent 1:1 classid 1:40 htb rate $[20*UPLINK/100]kbit ceil ${UPLINK}kbit prio 4 # Filter packets marked by iptables $tc filter add dev $DEV parent 1:0 protocol ip prio 1 handle $MARKPRIO1 fw classid 1:10 $tc filter add dev $DEV parent 1:0 protocol ip prio 2 handle $MARKPRIO2 fw classid 1:20 $tc filter add dev $DEV parent 1:0 protocol ip prio 3 handle $MARKPRIO3 fw classid 1:30 $tc filter add dev $DEV parent 1:0 protocol ip prio 4 handle $MARKPRIO4 fw classid 1:40 # All get stochastic fairness $tc qdisc add dev $DEV parent 1:10 handle 10: sfq perturb 10 $tc qdisc add dev $DEV parent 1:20 handle 20: sfq perturb 10 $tc qdisc add dev $DEV parent 1:30 handle 30: sfq perturb 10 $tc qdisc add dev $DEV parent 1:40 handle 40: sfq perturb 10