Hi
I'm having a hard time figuring out how to do some traffic shaping in openwrt. What I'm trying to do is to limit download/upload rate based on client IP.
I have also tried this sample from wiki and it's not working (not limiting upload rate) http://wiki.openwrt.org/doc/howto/packe … r.example2
I have also tried this sample from jow and it's not working (not limiting upload rate) https://forum.openwrt.org/viewtopic.php?id=23285
My approach is below. The download part is working but the upload part is killing me. What am I missing?
I tried to type everything by hand (not using script) and it didn't give me any errors. Also based on packets number and traffic I'd say that packets do get market, but for some reason they a) don't jump to device or b) filter doesn't see the mark.
This is my INCOMING chain in MANGLE table
This is my OUTGOING chain in MANGLE table
The code I am using
insmod cls_fw >/dev/null 2>&1
insmod cls_u32 >/dev/null 2>&1
insmod sch_htb >/dev/null 2>&1
insmod sch_sfq >/dev/null 2>&1
insmod sch_ingress >/dev/null 2>&1
insmod act_police >/dev/null 2>&1
DOWN_IMQ=0
DOWN_IMQ_NAME="imq0"
DOWN_RATE=1000
DOWN_BURST2=3080
DOWN_BURST=1540 # DOWN_RATE * 1000 / 8 / 100 or at least MTU
DOWN_MTU=1540
UP_IMQ=1
UP_IMQ_NAME="imq1"
UP_RATE=250
UP_BURST2=3080
UP_BURST=1540 # DOWN_RATE * 1000 / 8 / 100 or at least MTU
UP_MTU=1540
INCOMING_CHAIN=INC
OUTGOING_CHAIN=OUT
ip link set $DOWN_IMQ_NAME up
tc qdisc add dev "$DOWN_IMQ_NAME" root handle 1: htb r2q 10
tc class add dev "$DOWN_IMQ_NAME" parent 1: classid 1:1 htb rate 20000kbit
tc class add dev "$DOWN_IMQ_NAME" parent 1:1 classid 1:10 htb rate ${DOWN_RATE}kbit ceil ${DOWN_RATE}kbit burst $DOWN_BURST2 cburst $DOWN_BURST mtu $DOWN_MTU
tc class add dev "$DOWN_IMQ_NAME" parent 1:1 classid 1:20 htb rate 500kbit ceil 500kbit burst $DOWN_BURST2 cburst $DOWN_BURST mtu $DOWN_MTU
tc filter add dev "$DOWN_IMQ_NAME" parent 1: protocol ip handle 80 fw flowid 1:10
tc filter add dev "$DOWN_IMQ_NAME" parent 1: protocol ip handle 81 fw flowid 1:20
ip link set $UP_IMQ_NAME up
tc qdisc add dev "$UP_IMQ_NAME" root handle 1: htb r2q 10
tc class add dev "$UP_IMQ_NAME" parent 1: classid 1:1 htb rate 500kbit
tc class add dev "$UP_IMQ_NAME" parent 1:1 classid 1:10 htb rate ${UP_RATE}kbit ceil ${UP_RATE}kbit burst $UP_BURST2 cburst $UP_BURST mtu $UP_MTU
tc class add dev "$UP_IMQ_NAME" parent 1:1 classid 1:20 htb rate 500kbit ceil 500kbit burst $UP_BURST2 cburst $UP_BURST mtu $UP_MTU
tc filter add dev "$UP_IMQ_NAME" parent 1: protocol ip handle 82 fw flowid 1:10
tc filter add dev "$UP_IMQ_NAME" parent 1: protocol ip handle 83 fw flowid 1:20
iptables -t mangle -I $INCOMING_CHAIN -j IMQ --todev $DOWN_IMQ
iptables -t mangle -I $INCOMING_CHAIN -d 192.168.1.186 -j MARK --set-mark 81
iptables -t mangle -I $OUTGOING_CHAIN -j IMQ --todev $UP_IMQ
iptables -t mangle -I $OUTGOING_CHAIN -s 192.168.1.186 -j MARK --set-mark 82
if I change the "outgoing" to the code below, it works.
ip link set $UP_IMQ_NAME up
tc qdisc add dev "$UP_IMQ_NAME" root handle 1: htb default 1 r2q 10
tc class add dev "$UP_IMQ_NAME" parent 1: classid 1:1 htb rate ${UP_RATE}kbit ceil ${UP_RATE}kbit burst $UP_BURST2 cburst $UP_BURST mtu $UP_MTU prio 1
iptables -t mangle -I $OUTGOING_CHAIN -s 192.168.1.186 -j IMQ --todev $UP_IMQ
(Last edited by mitja.gti on 27 May 2012, 23:10)