2

I'm a Linux QoS newbie and I'm trying to learn how it works by using the docs at lartc.org as reference.

My first goal is a modest one: I want to assign a higher priority to UDP outgoing traffic, but for some reason it doesn't work.

Here is my current progress:

#!/bin/bash

IPTABLES=/usr/sbin/iptables
TC=/usr/sbin/tc

# All traffic is given an iptables MARK depending on its type:
#   * 10 for low latency traffic (all UDP traffic)
#   * 20 anything else

# all traffic
$IPTABLES -t mangle -A PREROUTING -i eth0 -j MARK --set-mark 20
# udp 
$IPTABLES -t mangle -A PREROUTING -i eth0 -p udp -j MARK --set-mark 10

# root qdisc
$TC qdisc add dev eth0 root handle 1: htb
# overall rate limits (1Mbps outgoing)
$TC class add dev eth0 parent 1: classid 1:1 htb rate 1Mbit
# UDP
$TC class add dev eth0 parent 1:1 classid 1:10 htb rate 512kbit ceil 1Mbit prio 0
# everything else
$TC class add dev eth0 parent 1:1 classid 1:20 htb rate 512kbit ceil 1Mbit prio 1

# do fair shaping in each class
$TC qdisc add dev eth0 parent 1:10 handle 10: sfq perturb 10
$TC qdisc add dev eth0 parent 1:20 handle 20: sfq perturb 10

# divert traffic marked by iptables into each class
$TC filter add dev eth0 parent 1:0 protocol ip handle 10 fw flowid 1:10
$TC filter add dev eth0 parent 1:0 protocol ip handle 20 fw flowid 1:20 

The iptables rules seem to be OK:

$ sudo /usr/sbin/iptables -L -t mangle
Chain PREROUTING (policy ACCEPT)
target     prot opt source               destination         
MARK       all  --  anywhere             anywhere            MARK set 0x14 
MARK       udp  --  anywhere             anywhere            MARK set 0xa 

But as far as I can tell, I'm not getting the expected result. This is how I check:

$ sudo /usr/sbin/tc -s qdisc show     
qdisc htb 1: dev eth0 root refcnt 2 r2q 10 default 0 direct_packets_stat 190646
 Sent 73059945 bytes 190646 pkt (dropped 0, overlimits 0 requeues 0) 
 backlog 0b 0p requeues 0 
qdisc sfq 10: dev eth0 parent 1:10 limit 127p quantum 1514b perturb 10sec 
 Sent 0 bytes 0 pkt (dropped 0, overlimits 0 requeues 0) 
 backlog 0b 0p requeues 0 
qdisc sfq 20: dev eth0 parent 1:20 limit 127p quantum 1514b perturb 10sec 
 Sent 0 bytes 0 pkt (dropped 0, overlimits 0 requeues 0) 
 backlog 0b 0p requeues 0 

See that the counters of sent bytes are 0.

So either my script has some issues, or it works, but I'm using a wrong way to display statistics.

Here are my questions:

  1. What's wrong with my script?
  2. Are there any other ways to debug the htb rules other than using "tc show" for displaying stats?

1 Answers1

1

Which way are your interfaces going? You have your HTB queue applied to to eth0, which makes sense if eth0 is you external interface. However, you're attaching the fwmark with iptables to packets that are arriving in to eth0, not going out -- you probably need to swap the -i for a -o in the iptables line. Otherwise, you're applying a mark to packets going one way, and looking for the mark to filter packets going the other way. Obviously, incoming packets will never hit the outgoing filter, so that's why your counters all say zero.

techieb0y
  • 4,161
  • 16
  • 17
  • After modifying the iptables rules to "-A POSTROUTING -o eth0", `tc -s qisc show` starts showing counted traffic. I guess that was the problem. How can I see that outgoing UDP is indeed being sent first? Are there any tools for that? –  Sep 15 '10 at 03:15