[Shorewall-newbies] Re: Wonder Shaper for Shorewall

Gerhard Olsson gerhard.olsson at tjohoo.se
Thu Jan 15 00:54:33 PST 2004


On Thu, 15 Jan 2004 00:52:18 +0100, Gerhard Olsson  
<gerhard.olsson at tjohoo.se> wrote:

> Modified tcstart file is posted separately

Wonder Shaper is released under GPL by Bert Hubert  
http://lartc.org/wondershaper/
For README etc see the link above

#!/bin/bash
# Wonder Shaper
# please read the README before filling out these values
#
# 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.

#Modification for use in "Shorewall"
#Instead of setting low priority packets in the script, the packets marked
#in tcrules with "1" will be down priotized here
#The main reason is that this allows the rules to handle NAT correctly,
#but the marking rules are more flexible too.
#
#Another change is that the rate for "down priotized" packets are set to  
10%
#instead of 80% of max uprate, but the ceil is set to 90%. If the low prio  
packets
#have many sessions, it may otherwise use a higher share of the traffic.

#Read parameters from shorewall configuration file, if you want to run the  
file
#outside of Shorewall (like "tcstart status")
#.   /etc/shorewall/shorewall.conf

if [ -z "$TC_DEV" -o -z "$TC_UPLINK" -o -z "$TC_DOWNLINK" ]
then
         echo "tcstart (Wonder Shaper) not configured."
         echo "Set TC_DOWNLINK, TC_UPLINK and TC_DEV in shorewall.conf"
         exit
fi

if [ "$1" = "status" ]
then
         tc -s qdisc ls dev $TC_DEV
         tc -s class ls dev $TC_DEV
         exit
fi


# clean existing down- and uplink qdiscs, hide errors
tc qdisc del dev $TC_DEV root    2> /dev/null > /dev/null
tc qdisc del dev $TC_DEV ingress 2> /dev/null > /dev/null

if [ "$1" = "stop" ]
then
         exit
fi


###### uplink

# install root HTB, point default traffic to 1:20:

tc qdisc add dev $TC_DEV root handle 1: htb default 20

# shape everything at $TC_UPLINK speed - this prevents huge queues in your
# DSL modem which destroy latency:

tc class add dev $TC_DEV parent 1: classid 1:1 htb rate ${TC_UPLINK}kbit  
burst 6k

# high prio class 1:10:

tc class add dev $TC_DEV parent 1:1 classid 1:10 htb rate ${TC_UPLINK}kbit  
\
    burst 6k prio 1

# bulk & default class 1:20 - gets slightly less traffic,
# and a lower priority:

tc class add dev $TC_DEV parent 1:1 classid 1:20 htb rate  
$[9*$TC_UPLINK/10]kbit \
    ceil ${TC_UPLINK}kbit burst 6k prio 2

tc class add dev $TC_DEV parent 1:1 classid 1:30 htb rate  
$[$TC_UPLINK/10]kbit \
    ceil $[9*$TC_UPLINK/10]kbit burst 6k prio 2

# all get Stochastic Fairness:
tc qdisc add dev $TC_DEV parent 1:10 handle 10: sfq perturb 10
tc qdisc add dev $TC_DEV parent 1:20 handle 20: sfq perturb 10
tc qdisc add dev $TC_DEV parent 1:30 handle 30: sfq perturb 10

# TOS Minimum Delay (ssh, NOT scp) in 1:10:

tc filter add dev $TC_DEV parent 1:0 protocol ip prio 10 u32 \
       match ip tos 0x10 0xff  flowid 1:10

# ICMP (ip protocol 1) in the interactive class 1:10 so we
# can do measurements & impress our friends:
tc filter add dev $TC_DEV parent 1:0 protocol ip prio 10 u32 \
         match ip protocol 1 0xff flowid 1:10

# To speed up downloads while an upload is going on, put ACK packets in
# the interactive class:
tc filter add dev $TC_DEV parent 1: protocol ip prio 10 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

# rest is 'non-interactive' ie 'bulk' and ends up in 1:20
# some traffic however suffers a worse fate
tc filter add dev $TC_DEV parent 1: protocol ip prio 11 \
    handle 1 fw classid 1:30

# rest is 'non-interactive' ie 'bulk' and ends up in 1:20
tc filter add dev $TC_DEV parent 1: protocol ip prio 18 u32 \
    match ip dst 0.0.0.0/0 flowid 1:20


########## 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 $TC_DEV handle ffff: ingress

# filter *everything* to it (0.0.0.0/0), drop everything that's
# coming in too fast:

tc filter add dev $TC_DEV parent ffff: protocol ip prio 50 u32 match ip  
src \
    0.0.0.0/0 police rate ${TC_DOWNLINK}kbit burst 10k drop flowid :1



More information about the Shorewall-newbies mailing list