A way to do QoS working for Upload and Download

Post new topic   Reply to topic    DD-WRT Forum Forum Index -> General Questions
Author Message
platbr
DD-WRT Novice


Joined: 02 Dec 2009
Posts: 16

PostPosted: Mon Mar 28, 2011 5:08    Post subject: A way to do QoS working for Upload and Download Reply with quote
If QoS option in GUI is OFF the imq module will always be unload by the dd-wrt, and if is ON it will delete your QoS settings in the firewall script.

So i did this


----------------------------------------------
# Startup Script
# write /tmp/loop.sh and /tmp/qos.sh

cat <<EOF > /tmp/loop.sh
# Verifing if imq1 is up each 15 secs, if not run qos.sh to setup QoS
while [ 1 ]; do
ifconfig imq1 > /dev/null
if [ \$? -eq "1" ]
then
sh /tmp/qos.sh
fi
sleep 15
done
EOF

#QoS Script using imq1 to Upload and Download
cat <<EOF > /tmp/qos.sh
iptables -t mangle -F
iptables -t mangle -Z
iptables -t mangle -X
insmod imq
insmod ipt_IMQ
ip link set imq1 up
tc qdisc del dev imq1 root
tc qdisc add dev imq1 root handle 1: htb

# Download
tc class add dev imq1 parent 1: classid 1:1 htb rate 14500kbit ceil 14500kbit prio 1

# Estacao 192.168.10.2
tc class add dev imq1 parent 1:1 classid 1:10 htb rate 7000kbit ceil 14500kbit prio 1
tc filter add dev imq1 parent 1: protocol ip prio 1 u32 match ip dst 192.168.10.2/32 flowid 1:10

# Estacao 192.168.10.3
tc class add dev imq1 parent 1:1 classid 1:11 htb rate 5000kbit ceil 14500kbit prio 1
tc filter add dev imq1 parent 1: protocol ip prio 1 u32 match ip dst 192.168.10.3/32 flowid 1:21

# Outras estacoes
tc class add dev imq1 parent 1:1 classid 1:19 htb rate 2500kbit ceil 14500kbit prio 1

tc qdisc add dev imq1 parent 1:10 handle 10: sfq perturb 10
tc qdisc add dev imq1 parent 1:10 handle 11: sfq perturb 10
tc qdisc add dev imq1 parent 1:19 handle 19: sfq perturb 10


# Upload
tc class add dev imq1 parent 1: classid 1:2 htb rate 900kbit ceil 900kbit prio 1

# Estacao 192.168.10.2
tc class add dev imq1 parent 1:2 classid 1:20 htb rate 400kbit ceil 900kbit prio 1
tc filter add dev imq1 parent 1: protocol ip prio 1 u32 match ip src 192.168.10.2/32 flowid 1:20

# Estacao 192.168.10.3
tc class add dev imq1 parent 1:2 classid 1:21 htb rate 400kbit ceil 900kbit prio 1
tc filter add dev imq1 parent 1: protocol ip prio 1 u32 match ip src 192.168.10.3/32 flowid 1:21

# Outras estacoes
tc class add dev imq1 parent 1:2 classid 1:29 htb rate 100kbit ceil 900kbit prio 1

tc qdisc add dev imq1 parent 1:20 handle 20: sfq perturb 10
tc qdisc add dev imq1 parent 1:20 handle 21: sfq perturb 10
tc qdisc add dev imq1 parent 1:29 handle 29: sfq perturb 10

# Iptables
iptables -t mangle -I PREROUTING 1 -j IMQ --todev 1
iptables -t mangle -I PREROUTING 2 -j RETURN
iptables -t mangle -I FORWARD 1 -j IMQ --todev 1
iptables -t mangle -I FORWARD 2 -j RETURN
EOF


sh /tmp/loop.sh &

----------------------------------------------


Last edited by platbr on Mon Mar 28, 2011 17:41; edited 1 time in total
Sponsor
phuzi0n
DD-WRT Guru


Joined: 10 Oct 2006
Posts: 10143

PostPosted: Mon Mar 28, 2011 10:40    Post subject: Reply with quote
I've used my own custom QoS scripts for ~2 years and never had any problem with the IMQ modules staying loaded.
_________________
Read the forum announcements thoroughly! Be cautious if you're inexperienced.
Available for paid consulting. (Don't PM about complicated setups otherwise)
Looking for bricks and spare routers to expand my collection. (not interested in G spec models)
platbr
DD-WRT Novice


Joined: 02 Dec 2009
Posts: 16

PostPosted: Mon Mar 28, 2011 17:21    Post subject: Reply with quote
phuzi0n wrote:
I've used my own custom QoS scripts for ~2 years and never had any problem with the IMQ modules staying loaded.

My router is a Ralink RT3052F (Aceex NR22/Y) and ther eis a lot of users reporting QoS for upload is not working, i my issue is if "QoS > Start QoS" option is not checked the imq module is auto unloading after Firewall Script.

One user solved his problem enabling dd-wrt QoS option, it prevents imq to unload, and other said that imq was unloading.

Related in http://www.dd-wrt.com/phpBB2/viewtopic.php?t=76364

I can control download only traffic without this tip, but for download + upload limiting i need to use this loop.

I m using the last one 16454 and i had this issue in other builds.


Last edited by platbr on Mon Mar 28, 2011 18:30; edited 2 times in total
ruriruri
DD-WRT Novice


Joined: 16 Sep 2010
Posts: 3

PostPosted: Sun May 01, 2011 2:15    Post subject: Reply with quote
tc qdisc add dev imq1 parent 1:20 handle 21: sfq perturb 10

is the 1:20 suppose to be 1:21? if not, why is it 1:20?


# Estacao 192.168.10.2
tc class add dev imq1 parent 1:2 classid 1:20 htb rate 400kbit ceil 900kbit prio 1
tc filter add dev imq1 parent 1: protocol ip prio 1 u32 match ip src 192.168.10.2/32 flowid 1:20

how do I change this to match MAC instead of IP?


Thanks
platbr
DD-WRT Novice


Joined: 02 Dec 2009
Posts: 16

PostPosted: Mon May 02, 2011 12:43    Post subject: Reply with quote
yes i was a mistake...


Try this to matching MAC...

The u32 can be used to match any bit in the ip header. Before the ip header, there is a frame header. In that frame header you can find the src and dst mac address. You can trick the u32 filter in using the frame header if you use negative offsets.

Decimal Offset Description
-14: DST MAC, 6 bytes
-8: SRC MAC, 6 bytes
-2: Eth PROTO, 2 bytes, eg. ETH_P_IP
0: Protocol header (IP Header)

From an email on the LARTC list :

Egress (match Dst MAC):
... match u16 0xPPPP 0xFFFF at -2 match u32 0xM2M3M4M5 0xFFFFFFFF at -12 match u16 0xM0M1 0xFFFF at -14

Ingress (match Src MAC):
... match u16 0xPPPP 0xFFFF at -2 match u16 0xM4M5 0xFFFF at -4 match u32 0xM0M1M2M3 0xFFFFFFFF at -8

Where PPPP is the Eth Proto Code (from linux/include/linux/if_ether.h):

0800 ETH_P_IP

and M0..M5 are the 6 bytes of the MAC address

Example for matching ETH_P_IP for MAC 00:11:22:33:44:55

Egress:
... match u16 0x0800 0xFFFF at -2 match u32 0x22334455 0xFFFFFFFF at -12 match u16 0x0011 0xFFFF at -14

Ingress:
... match u16 0x0800 0xFFFF at -2 match u16 0x4455 0xFFFF at -4 match u32 0x00112233 0xFFFFFFFF at -8



ruriruri wrote:
tc qdisc add dev imq1 parent 1:20
handle 21: sfq perturb 10
3w
is the 1:20 suppose to be 1:21? if not, why is it 1:20?


# Estacao 192.168.10.2
tc class add dev imq1 parent 1:2 classid 1:20 htb rate 400kbit ceil 900kbit prio 1
tc filter add dev imq1 parent 1: protocol ip prio 1 u32 match ip src 192.168.10.2/32 flowid 1:20

how do I change this to match MAC instead of IP?


Thanks
quaziyen
DD-WRT Novice


Joined: 11 Oct 2014
Posts: 3

PostPosted: Sat Oct 11, 2014 18:03    Post subject: Reply with quote
DD-WRT v24-sp2 (03/25/13) big (SVN revision 21061)
on ASUS RT-N10U

Wow. It's 2014 and GUI-disabled QoS is still messing with my custom firewall script...
I have been trying to make upload traffic shaping work for several days now, so glad I bumped into this thread.
quaziyen
DD-WRT Novice


Joined: 11 Oct 2014
Posts: 3

PostPosted: Sun Oct 12, 2014 14:26    Post subject: Reply with quote
"insmod imq" string in a startup or firewall script results in this behaviour:

Code:
# dmesg | tail -4
IMQ driver loaded successfully.
      Hooking IMQ before NAT on PREROUTING.
      Hooking IMQ after NAT on POSTROUTING.
IMQ driver unloaded successfully.


Though if I telnet into router and manually insert the imq module, it would work.
Is this a bug? Should I open a ticket on this?
Display posts from previous:    Page 1 of 1
Post new topic   Reply to topic    DD-WRT Forum Forum Index -> General Questions All times are GMT

Navigation

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You can attach files in this forum
You can download files in this forum