following applies in case the interface on which you do the QoS is an interface with Masquerading or SNAT active, as is often the case with the wan interface that connects to internet or an adsl modem so that the outside world sees one IP address.
Masquerading and SNAT are done before the packages hit the processing by tc, and hence they have lost their original source address by the time you test them for their source address !
If that's your problem the solution is in not doing the filter command in tc using 'u32' but to use 'fw' and use the MARK target in the MANGLE table of iptables. Below are some code snippets; as they result from quick cut/paste from my scripts check carefully.
The priorities serve to prioritize classes at the same level; the higher class (lower number) will be guaranteed its minimum before looking at any other need of other classes at that level. The mark that is set by mangling and used by fw to assign the packet to a class only exists while being processed in the router; it is not part of the data package when the package leaves the router.
TC="/usr/sbin/tc"
IPT="/usr/sbin/iptables"
WAN_IF="eth0.1"
MTU=1470
MIN_RATE=10
UPRATE=650
MINpuser=1
### module loading
for module in sch_htb cls_fw ; do
/sbin/insmod $module 2>&- >&-
done
# Calculate r2q for htb discipline
RTOQ_U=$(($MIN_RATE*$UPRATE*10/(8*$MTU)))
[ $RTOQ_U -gt 20 ] && RTOQ_U=20
[ $RTOQ_U -eq 0 ] && RTOQ_U=1
### purge filters
( $TC filter show dev $WAN_IF | grep -q 'pref 100' ) && {
for pref in 100; do
$TC filter del dev $WAN_IF pref $pref &> /dev/null
done
}
### purge classes
( $TC class show dev $WAN_IF | grep -q '1:1' ) && {
for cnt in 3 2 1; do
string=${TC}' class del dev '${WAN_IF}' classid 1:'${cnt}' &> /dev/null'
eval $string
done
}
### purge qdisc
( $TC qdisc show dev $WAN_IF | grep -q 'htb' ) && {
$TC qdisc del dev $WAN_IF root &> /dev/null
}
### define root qdisc and its parent class that allows borrowing by lower classes; use other class as default
$TC qdisc add dev $WAN_IF root handle 1: htb default 2 r2q $RTOQ_U
$TC class add dev $WAN_IF parent 1:0 classid 1:1 htb rate ${UPRATE}kbit ceil ${UPRATE}kbit mtu $MTU
### define two leaf classes
## others
$TC class add dev $WAN_IF parent 1:1 classid 1:2 htb rate ${MINpuser}kbit ceil ${UPRATE}kbit prio 1 mtu $MTU
$TC qdisc add dev $WAN_IF parent 1:2 handle 2: pfifo limit 25
## special
$TC class add dev $WAN_IF parent 1:1 classid 1:3 htb rate ${MINpuser}kbit ceil ${UPRATE}kbit prio 2 mtu $MTU
$TC qdisc add dev $WAN_IF parent 1:3 handle 3: pfifo limit 25
### reduce long text strings
FLT="$TC filter add dev $WAN_IF parent 1:0 protocol ip pref"
### all filtering must be done on fwmark because iptables MASQUERADE will change source address !
$FLT 100 handle 0x3 fw classid 1:0x3 ## send special user to class 3
### flush and set mangle table
$IPT -t mangle -F
$IPT -t mangle -X
$IPT -t mangle -A PREROUTING -s 192.168.1.2/32 -j MARK --set-mark 0x3
$IPT -t mangle -A PREROUTING -m mark --mark 0x3 -j ACCEPT
## last line is only needed when more entries follow because '-j MARK' doesn't stop traversing the rest of matches
## and you might end up changing the mark because of yet another perhaps less specific match !
(Last edited by doddel on 11 Jan 2008, 19:03)