#!/bin/sh
DEV=eth0
TC=/sbin/tc
U32="filter add dev $DEV protocol ip parent 1:0 prio 1 u32"
echo Delete previous root qdisc
$TC qdisc del dev $DEV root >/dev/null 2>&1
echo Add root qdisc
$TC qdisc add dev $DEV root handle 1: htb default 20
echo Add root class
$TC class add dev $DEV parent 1: classid 1:1 htb rate 10000kbit ceil 10000kbit burst 4k
#echo Add default class
#$TC class add dev $DEV parent 1:1 classid 1:0x10 htb rate 12 ceil 850kbit burst 4k
#$TC qdisc add dev $DEV parent 1:0x10 handle 0x10: pfifo limit 5
echo Add class PRIMARY
$TC class add dev $DEV parent 1:1 classid 1:0x20 htb rate 12kbit ceil 700kbit burst 4k prio 1
echo Add client HTTP_ACCESS
$TC class add dev $DEV parent 1:0x20 classid 1:0x21 htb rate 20kbit ceil 300kbit burst 4k prio 1
$TC ${U32} match ip dst 192.168.0.0/24 match ip dport 80 0xffff flowid 1:0x21
$TC ${U32} match ip dst 192.168.0.0/24 match ip sport 80 0xffff flowid 1:0x21
$TC ${U32} match ip dst 192.168.0.0/24 match ip dport 1863 0xffff flowid 1:0x21
$TC ${U32} match ip dst 192.168.0.0/24 match ip sport 1863 0xffff flowid 1:0x21
$TC ${U32} match ip dst 192.168.0.0/24 match ip dport 22 0xffff flowid 1:0x21
$TC ${U32} match ip dst 192.168.0.0/24 match ip sport 22 0xffff flowid 1:0x21
$TC ${U32} match ip dst 192.168.0.0/24 match ip dport 21 0xffff flowid 1:0x21
$TC ${U32} match ip dst 192.168.0.0/24 match ip sport 21 0xffff flowid 1:0x21
$TC ${U32} match ip dst 192.168.0.0/24 match ip dport 443 0xffff flowid 1:0x21 #https
$TC ${U32} match ip dst 192.168.0.0/24 match ip sport 443 0xffff flowid 1:0x21 #https
$TC qdisc add dev $DEV parent 1:0x21 handle 0x21: pfifo limit 5
echo add games
$TC class add dev $DEV parent 1:0x20 classid 1:0x22 htb rate 22kbit ceil 100kbit burst 2k prio 2
$TC ${U32} match ip dst 192.168.0.0/24 match ip dport 8888 0xffff flowid 1:0x22 # horyu
$TC ${U32} match ip dst 192.168.0.0/24 match ip sport 8888 0xffff flowid 1:0x22 # horyu
$TC ${U32} match ip dst 192.168.0.0/24 match ip dport 7171 0xffff flowid 1:0x22 # tibia
$TC ${U32} match ip dst 192.168.0.0/24 match ip sport 7171 0xffff flowid 1:0x22 # tibia
$TC ${U32} match ip dst 192.168.0.0/24 match ip sport 7777 0xffff flowid 1:0x22 # line
$TC ${U32} match ip dst 192.168.0.0/24 match ip dport 7777 0xffff flowid 1:0x22 # line
$TC ${U32} match ip dst 192.168.0.0/24 match ip sport 2106 0xffff flowid 1:0x22 # hagnarok
$TC ${U32} match ip dst 192.168.0.0/24 match ip dport 8085 0xffff flowid 1:0x22 # jogo
$TC ${U32} match ip dst 192.168.0.0/24 match ip sport 8085 0xffff flowid 1:0x22 # jogo
#$TC ${U32} match ip dst 192.168.0.0/24 match ip dport 2412 0xffff flowid 1:0x22
#$TC ${U32} match ip dst 192.168.0.0/24 match ip sport 2412 0xffff flowid 1:0x22
#$TC ${U32} match ip dst 192.168.0.0/24 match ip dport 3118 0xffff flowid 1:0x22
#$TC ${U32} match ip dst 192.168.0.0/24 match ip sport 3118 0xffff flowid 1:0x22
$TC ${U32} match ip dst 192.168.0.0/24 match ip dport 6000 0xffff flowid 1:0x22
$TC ${U32} match ip dst 192.168.0.0/24 match ip sport 6000 0xffff flowid 1:0x22
$TC ${U32} match ip dst 192.168.0.0/24 match ip dport 6900 0xffff flowid 1:0x22
$TC ${U32} match ip dst 192.168.0.0/24 match ip sport 6900 0xffff flowid 1:0x22
$TC ${U32} match ip dst 192.168.0.0/24 match ip dport 5000 0xffff flowid 1:0x22
$TC ${U32} match ip dst 192.168.0.0/24 match ip sport 5000 0xffff flowid 1:0x22
$TC ${U32} match ip dst 192.168.0.0/24 match ip dport 4661 0xffff flowid 1:0x22
$TC ${U32} match ip dst 192.168.0.0/24 match ip sport 4661 0xffff flowid 1:0x22
$TC ${U32} match ip dst 192.168.0.0/24 match ip dport 3724 0xffff flowid 1:0x22 #battlefield
$TC ${U32} match ip dst 192.168.0.0/24 match ip sport 3724 0xffff flowid 1:0x22 #battlefiel
$TC ${U32} match ip dst 192.168.0.0/24 match ip dport 2594 0xffff flowid 1:0x22 #gambound
$TC ${U32} match ip dst 192.168.0.0/24 match ip sport 2594 0xffff flowid 1:0x22 #gambound
$TC ${U32} match ip dst 192.168.0.0/24 match ip dport 9014 0xffff flowid 1:0x22 #gambound
$TC ${U32} match ip dst 192.168.0.0/24 match ip sport 9014 0xffff flowid 1:0x22 #gambound
$TC ${U32} match ip dst 192.168.0.0/24 match ip dport 2106 0xffff flowid 1:0x22 #gambound
$TC ${U32} match ip dst 192.168.0.0/24 match ip sport 2106 0xffff flowid 1:0x22 #gambound
$TC qdisc add dev $DEV parent 1:0x22 handle 0x22: pfifo limit 5
echo Add client DOWN #torrent, kazza e outros
$TC class add dev $DEV parent 1:0x20 classid 1:0x23 htb rate 10kbit ceil 200kbit burst 4k prio 3
$TC ${U32} match ip dst 192.168.0.0/24 flowid 1:0x23
$TC qdisc add dev $DEV parent 1:0x23 handle 0x23: pfifo limit 5
echo add games uploads
$TC class add dev $DEV parent 1:0x20 classid 1:0x24 htb rate 22kbit ceil 200kbit burst 2k prio 2
$TC ${U32} match ip src 192.168.0.0/24 match ip dport 6000 0xffff flowid 1:0x24
$TC ${U32} match ip src 192.168.0.0/24 match ip sport 6000 0xffff flowid 1:0x24
$TC ${U32} match ip src 192.168.0.0/24 match ip dport 6900 0xffff flowid 1:0x24
$TC ${U32} match ip src 192.168.0.0/24 match ip sport 6900 0xffff flowid 1:0x24
$TC ${U32} match ip src 192.168.0.0/24 match ip dport 5000 0xffff flowid 1:0x24
$TC ${U32} match ip src 192.168.0.0/24 match ip sport 5000 0xffff flowid 1:0x24
$TC ${U32} match ip src 192.168.0.0/24 match ip sport 8085 0xffff flowid 1:0x24
$TC ${U32} match ip src 192.168.0.0/24 match ip dport 8085 0xffff flowid 1:0x24
$TC ${U32} match ip src 192.168.0.0/24 match ip sport 7777 0xffff flowid 1:0x24
$TC ${U32} match ip src 192.168.0.0/24 match ip dport 7777 0xffff flowid 1:0x24
$TC ${U32} match ip src 192.168.0.0/24 match ip sport 3724 0xffff flowid 1:0x24
$TC ${U32} match ip src 192.168.0.0/24 match ip dport 3724 0xffff flowid 1:0x24
$TC ${U32} match ip src 192.168.0.0/24 match ip sport 2594 0xffff flowid 1:0x24
$TC ${U32} match ip src 192.168.0.0/24 match ip dport 2594 0xffff flowid 1:0x24
$TC ${U32} match ip src 192.168.0.0/24 match ip dport 1863 0xffff flowid 1:0x24
$TC ${U32} match ip src 192.168.0.0/24 match ip sport 1863 0xffff flowid 1:0x24
$TC qdisc add dev $DEV parent 1:0x24 handle 0x24: pfifo limit 5
echo Add client UP
$TC class add dev $DEV parent 1:0x20 classid 1:0x25 htb rate 10kbit ceil 400kbit burst 4k prio 3
$TC ${U32} match ip src 192.168.0.0/24 flowid 1:0x25
$TC qdisc add dev $DEV parent 1:0x25 handle 0x25: pfifo limit 5