I guess you mean 8-bit TOS
field in IPv4 packet header. Have you alread read LARTC HOWTO? This is the guide you definitely need to read. Briefly, you need to
1) Define QDISCs
and CLASSes
in which traffic is classified, prioritized and shaped (egress traffic can be shaped only !!!). In general, any packet which needs to be sent is enqueued to QDISC
of network interface.
CEIL=10
tc qdisc add dev eth0 root handle 1: htb default 15
tc class add dev eth0 parent 1: classid 1:1 htb rate ${CEIL}mbit ceil ${CEIL}mbit
tc class add dev eth0 parent 1:1 classid 1:10 htb rate 4mbit ceil ${CEIL}mbit prio 0
tc class add dev eth0 parent 1:1 classid 1:11 htb rate 1mbit ceil ${CEIL}mbit prio 1
tc class add dev eth0 parent 1:1 classid 1:12 htb rate 6mbit ceil ${CEIL}mbit prio 2
tc qdisc add dev eth0 parent 1:11 handle 110: sfq perturb 10
tc qdisc add dev eth0 parent 1:12 handle 120: sfq perturb 10
Classes with lower prio
field are tried first. So the class 1:10 may be dedicated for packets requiring e.g. minimum delay. The classes 1:11 and 1:12 have attached SFQ
queuing discipline to ensure more fair bandwidth sharing.
2) Define FILTERs to enqueue a packet to the right CLASS
.
tc filter add dev eth0 parent 1:0 protocol ip prio 1 handle 10 fw classid 1:10
tc filter add dev eth0 parent 1:0 protocol ip prio 2 handle 11 fw classid 1:11
tc filter add dev eth0 parent 1:0 protocol ip prio 3 handle 12 fw classid 1:12
This simply tells that a packet with mark 10 goes to class 10 and so on.
3) Define iptables rules to mark a packet to enqueue it to the right CLASS
iptables -t mangle -A PREROUTING -m tos --tos Minimize-Delay -j MARK --set-mark 0x10
iptables -t mangle -A PREROUTING -m tos --tos Minimize-Cost -j MARK --set-mark 0x11
iptables -t mangle -A PREROUTING -m tos --tos Maximize-Throughput -j MARK --set-mark 0x12
I use iptables tos
module on purpose to show you how you can match specific values of TOS
field and mark it accordingly. For more about this module run
iptables -m tos --help