Adding latency to outbound UDP packets with tc
I would like to impose an arbitrary latency on outbound UDP packets using a fw filter in tc; however, I cannot get the filter to work properly:
tc qdisc add dev eth0 root handle 1: prio
tc qdisc add dev eth0 parent 1:3 handle 30: netem delay 200ms
tc filter add dev eth0 parent 1:0 protocol ip prio 3 handle 1 fw flowid 1:3
iptables -A PREROUTING -i eth0 -t mangle -p udp -j MARK --set-mark 1
If I use the following u32 filter instead I get the desired effect:
tc filter add dev eth0 parent 1:0 protocol ip prio 3 u32 match ip dport 53 0xffff flowid 1:3
I don't wish to use the u32 filters, and what is more troubling I can't get the --ttl-set
or --set-tos
manglers to work in Ubuntu 10.04.
The two may be completely unrelated, but I am concerned that the packets aren't being marked by iptables. I have been unable to find a way to test marking.
Solution 1:
I ended solving my problem with another feature of iptables
instead of --set-mark
:
iptables -t mangle -A POSTROUTING -o eth0 -p udp -j CLASSIFY --set-class 1:3
I hope this helps someone as I toiled over the complexities of tc
for sometime before accomplishing this seemingly simple task.
EDIT:
Andy Smith is correct, I should have been marking the POSTROUTING chain! The following rule should work with --set-mark
:
iptables -A POSTROUTING -t mangle -p udp -j MARK --set-mark 1