#!/bin/sh # All traffic control is done using linux routing and traffic control. # You nee NETLINK and the QoS/fair queueing support compiled in. # Put the brake on the KaZaA network congestion. # Downstream interface (towards the client) IF_INTERN=eth1 # Upstream interface (towards the internet)) IF_EXTERN=eth0 # Kazaa ports, may be multiple spaced (gnutella?) THROTTLE_DPORT="1214" THROTTLE_SPORT="1214" # Bandwidth for defined ports is done in throttle_ports. THROTTLE_DOWNSTREAM="256kbit" THROTTLE_UPSTREAM="128kbit" throttle_ports() { echo Setting up throttle for ports for port in $THROTTLE_SPORT;do #bandbreedte downstream beperken adsl lijn tc filter add dev $IF_INTERN parent 10:0 protocol ip prio 100 u32 match ip sport $port 0xffff flowid 10:200 done for port in $THROTTLE_DPORT;do #bandbreedte upstream beperken adsl lijn tc filter add dev $IF_EXTERN parent 20:0 protocol ip prio 100 u32 match ip dport $port 0xffff flowid 20:200 done } setup_conn_throttle() { # Limit bandwidth # Throw away old rules. # Downstream tc qdisc del root dev $IF_INTERN # Upstream tc qdisc del root dev $IF_EXTERN # Maximum bandwidth downstream of interface (interface $IF_INTERN) tc qdisc add dev $IF_INTERN root handle 10: cbq bandwidth 100mbit avpkt 1000 # Maximale bandwidth upstream of interface (interface $IF_EXTERN) tc qdisc add dev $IF_ADSL root handle 20: cbq bandwidth 256kbit avpkt 1000 # Main class downstream. tc class add dev $IF_INTERN parent 10:0 classid 10:1 cbq bandwidth 100mbit rate \ 100mbit allot 1514 weight 10mbit prio 8 maxburst 20 avpkt 1000 # Main class upstream. tc class add dev $IF_EXTERN parent 20:0 classid 20:1 cbq bandwidth 256kbit rate \ 256kbit allot 1514 weight 32kbit prio 8 maxburst 20 avpkt 1000 # Class for downstream. tc class add dev $IF_INTERN parent 10:1 classid 10:200 cbq bandwidth 100mbit rate \ $THROTTLE_DOWNSTREAM allot 1514 weight 32kbit prio 5 maxburst 20 avpkt 1000 bounded # Class for upstream. tc class add dev $IF_EXTERN parent 20:1 classid 20:200 cbq bandwidth 256kbit rate \ $THROTTLE_UPSTREAM allot 1514 weight 16kbit prio 5 maxburst 20 avpkt 1000 bounded # Decide which downstream queue we use. (sfq) tc qdisc add dev $IF_INTERN parent 10:200 sfq quantum 1514b perturb 15 # Decide which upstream queue we use. (sfq) tc qdisc add dev $IF_EXTERN parent 20:200 sfq quantum 1514b perturb 15 } setup_conn_throttle throttle_ports