#!/bin/bashlan_if="lan"
lan_ip="192.168.2.1"
lan_ips="192.168.2.0/24"
gw1_rate="12000"
gw2_rate="3000"
#Удаление имеющихся дисциплин
tc qdisc del dev $lan_if root > /dev/null 2>&1
tc qdisc del dev $lan_if ingress > /dev/null 2>&1
#В дефолтный класс в 99% случаев пойдет трафик только через crp-интерфейс
tc qdisc add dev $lan_if root handle 1: htb default 90:
tc class add dev $lan_if parent 1: classid 1:1 htb rate 500mbit
tc class add dev $lan_if parent 1:1 classid 10: htb rate 480mbit ceil 500mbit
tc class add dev $lan_if parent 1:1 classid 20: htb rate ${gw1_rate}kbit
tc class add dev $lan_if parent 1:1 classid 30: htb rate ${gw2_rate}kbit
tc class add dev $lan_if parent 1:1 classid 90: htb rate 5mbit
tc class add dev $lan_if parent 20: classid 20:1 htb rate $[6*$gw1_rate/10]kbit ceil ${gw1_rate}kbit
tc class add dev $lan_if parent 20: classid 20:2 htb rate $[4*$gw1_rate/10]kbit ceil ${gw1_rate}kbit
tc class add dev $lan_if parent 30: classid 30:1 htb rate $[7*$gw2_rate/10]kbit ceil ${gw2_rate}kbit
tc class add dev $lan_if parent 30: classid 30:2 htb rate $[3*$gw2_rate/10]kbit ceil ${gw2_rate}kbit
#На концы классов помещаем sfq-листы
tc qdisc add dev $lan_if parent 20:1 handle 201: sfq perturb 10
tc qdisc add dev $lan_if parent 20:2 handle 202: sfq perturb 10
tc qdisc add dev $lan_if parent 30:1 handle 301: sfq perturb 10
tc qdisc add dev $lan_if parent 30:2 handle 302: sfq perturb 10
#Описание классификаторов
tc filter add dev $lan_if parent 1:1 protocol ip prio 1 u32 match ip src $lan_ip match ip dst $lan_ips flowid 1:10
tc filter add dev $lan_if parent 20: protocol ip prio 2 handle 51 fw flowid 20:1
tc filter add dev $lan_if parent 20: protocol ip prio 4 handle 52 fw flowid 20:2
tc filter add dev $lan_if parent 30: protocol ip prio 3 handle 61 fw flowid 30:1
tc filter add dev $lan_if parent 30: protocol ip prio 5 handle 62 fw flowid 30:2