[LARTC] Looking for a good htb traffic shaping script to prioritize incoming traffic

Linux Advanced Routing and Traffic Control

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Here the scrip of wonder shaper ... i modified it to
prioritize Counter Strike, ACK, DNS and HTTP.
The same with telnet.
This is used for ppp0 uptreams and the other the htb script for eth0 to
priritize
download. This is working for now, is anybody have to modified something
please tell me.

Best Regards.

Sebastian A. Aresca

The other ... the message are in spanish =(.


     ------------------------------------------ 
Outcoming ------------------------------------------ 

#!/bin/bash
# Wonder Shaper ADSL

##########################################################################
# RATES

DOWNLINK=440
UPLINK=110
UPLINK90=100
UPLINK80=90
DEV=ppp0

##########################################################################
# BORRAS COLAS

tc qdisc del dev $DEV root    2> /dev/null > /dev/null
tc qdisc del dev $DEV ingress 2> /dev/null > /dev/null

iptables -t mangle -F PREROUTING

if [ "$1" = "stop" ]
then
        exit
fi

##########################################################################
# CLASE PRINCIPAL

tc qdisc add dev $DEV root handle 1: htb default 30
tc class add dev $DEV parent 1: classid 1:1 htb rate ${UPLINK}kbit burst 6k

##########################################################################
# SUB CLASES

# Maxima Prioridad
tc class add dev $DEV parent 1:1 classid 1:10 htb rate ${UPLINK}kbit \
   burst 2k prio 1

# Counter

tc class add dev $DEV parent 1:1 classid 1:15 htb rate ${UPLINK90}kbit \
   burst 2k prio 3

# Clase puertos
tc class add dev $DEV parent 1:1 classid 1:20 htb rate ${UPLINK80}kbit \
   burst 2k prio 5

# Clase terminales
tc class add dev $DEV parent 1:1 classid 1:30 htb rate ${UPLINK80}kbit \
   burst 2k prio 7

##########################################################################
# COLAS SFQ

tc qdisc add dev $DEV parent 1:10 handle 10: sfq perturb 10
tc qdisc add dev $DEV parent 1:15 handle 15: sfq perturb 10
tc qdisc add dev $DEV parent 1:20 handle 20: sfq perturb 10
tc qdisc add dev $DEV parent 1:30 handle 30: sfq perturb 10

##########################################################################
# FILTROS

##########################################################################
  # Por puerto
        # ICMP (ping)
        tc filter add dev $DEV parent 1:0 protocol ip prio 10 u32 \
        match ip protocol 1 0xff flowid 1:10

        # ACK
        tc filter add dev $DEV parent 1: protocol ip prio 10 u32 \
        match ip protocol 6 0xff \
        match u8 0x05 0x0f at 0 \
        match u16 0x0000 0xffc0 at 2 \
        match u8 0x10 0xff at 33 \
        match u8 0x10 0xff at 33 \
        flowid 1:10

        # Puerto Telnet 23
        tc filter add dev $DEV parent 1: protocol ip prio 12 u32 \
        match ip dport 23 0xffff flowid 1:10

        # DNS
        #tc filter add dev $DEV parent 1: protocol ip prio 11 u32 \
        #match ip sport 53 0xffff \
        #match ip protocol 17 0xff \
        #flowid 1:10

        # Puerto 80
        tc filter add dev $DEV parent 1: protocol ip prio 20 u32 \
        match ip dport 80 0xffff flowid 1:20

        # Puerto Counter 2701x

        tc filter add dev ppp0 parent 1: protocol ip prio 15 handle 9 fw
flowid 1:15

        iptables -t mangle -A PREROUTING -i eth0 -p udp --dport 27010 \
                 -j MARK --set-mark 9
        iptables -t mangle -A PREROUTING -i eth0 -p udp --dport 27011 \
                 -j MARK --set-mark 9
        iptables -t mangle -A PREROUTING -i eth0 -p udp --dport 27012 \
                 -j MARK --set-mark 9
        iptables -t mangle -A PREROUTING -i eth0 -p udp --dport 27013 \
                 -j MARK --set-mark 9
        iptables -t mangle -A PREROUTING -i eth0 -p udp --dport 27014 \
                 -j MARK --set-mark 9
        iptables -t mangle -A PREROUTING -i eth0 -p udp --dport 27015 \
                 -j MARK --set-mark 9
        iptables -t mangle -A PREROUTING -i eth0 -p udp --dport 27016 \
                 -j MARK --set-mark 9
        iptables -t mangle -A PREROUTING -i eth0 -p udp --dport 27017 \
                 -j MARK --set-mark 9
        iptables -t mangle -A PREROUTING -i eth0 -p udp --dport 27018 \
                 -j MARK --set-mark 9
        iptables -t mangle -A PREROUTING -i eth0 -p udp --dport 27019 \
                 -j MARK --set-mark 9

##########################################################################
  # By machine

        # wksWindowsXP
       tc filter add dev $DEV parent 1: protocol ip prio 20 \
       handle 4 fw flowid 1:30
       iptables -t mangle -A PREROUTING -s 192.168.0.4 \
       -j MARK --set-mark 4

##########################################################################
# General        tc filter add dev $DEV parent 1: protocol ip prio 20 u32 \
        match ip dst 0.0.0.0/0 flowid 1:30

##########################################################################
# DOWNLOAD

tc qdisc add dev $DEV handle ffff: ingress

# filter *everything* to it (0.0.0.0/0), drop everything that's
# coming in too fast:

tc filter add dev $DEV parent ffff: protocol ip prio 50 u32 match ip src \
   0.0.0.0/0 police rate ${DOWNLINK}kbit burst 10k drop flowid :1

     ------------------------------------------ 
Incoming ------------------------------------------ 
#! /bin/sh
#

############################################################################
#
# Parametros
#
############################################################################
#

# r2q = rate_mas_bajo / 1500
#R2Q=15

# Ancho de banda Total
BW=56Kbps

# Definicion de clase padre

tc qdisc del dev eth0 root
iptables -t mangle -F POSTROUTING

if [ "$1" = "stop" ]
then
        echo 'Stop'
        exit
fi

tc qdisc add dev eth0 root handle 1: htb default 19

############################################################################
#
# Clases
#
############################################################################
#

tc class add dev eth0 parent 1: classid 1:1 htb rate $BW ceil $BW
tc class add dev eth0 parent 1:1 classid 1:17 htb rate 36kbps burst 2k ceil
$BW    prio 1
tc class add dev eth0 parent 1:1 classid 1:18 htb rate 10kbps burst 2k ceil
$BW    prio 2
tc class add dev eth0 parent 1:1 classid 1:19 htb rate 10kbps burst 2k ceil
$BW    prio 7

tc qdisc add dev eth0 parent 1:17 handle 17: sfq perturb 10
tc qdisc add dev eth0 parent 1:18 handle 18: sfq perturb 10
tc qdisc add dev eth0 parent 1:19 handle 19: sfq perturb 10

############################################################################
#
# Filtros
#
############################################################################
#

# Con IPTABLES

tc filter add dev eth0 parent 1: protocol ip prio 1 handle 1 fw flowid 1:17
tc filter add dev eth0 parent 1: protocol ip prio 10 handle 9 fw flowid 1:17
tc filter add dev eth0 parent 1: protocol ip prio 30 handle 8 fw flowid 1:18
tc filter add dev eth0 parent 1: protocol ip prio 20 handle 9 fw flowid 1:19

# Por puesto

#iptables -t mangle -A POSTROUTING -o eth0 -d 192.168.0.1 \
#        -j MARK --set-mark 1

# POR PUERTO

# Ping

iptables -t mangle -A POSTROUTING -o eth0 -p icmp \
        -j MARK --set-mark 1

# Puerto 80

iptables -t mangle -A POSTROUTING -o eth0 -p tcp --sport 80 \
        -j MARK --set-mark 8

# Puertos del Counter

iptables -t mangle -A POSTROUTING -o eth0 -p tcp --sport 27010 \
        -j MARK --set-mark 9
iptables -t mangle -A POSTROUTING -o eth0 -p tcp --sport 27011 \
        -j MARK --set-mark 9
iptables -t mangle -A POSTROUTING -o eth0 -p tcp --sport 27012 \
        -j MARK --set-mark 9
iptables -t mangle -A POSTROUTING -o eth0 -p tcp --sport 27013 \
        -j MARK --set-mark 9
iptables -t mangle -A POSTROUTING -o eth0 -p tcp --sport 27014 \
        -j MARK --set-mark 9
iptables -t mangle -A POSTROUTING -o eth0 -p tcp --sport 27015 \
        -j MARK --set-mark 9
iptables -t mangle -A POSTROUTING -o eth0 -p udp --sport 27016 \
        -j MARK --set-mark 9
iptables -t mangle -A POSTROUTING -o eth0 -p tcp --sport 27017 \
        -j MARK --set-mark 9
iptables -t mangle -A POSTROUTING -o eth0 -p tcp --sport 27018 \
        -j MARK --set-mark 9
iptables -t mangle -A POSTROUTING -o eth0 -p tcp --sport 27019 \
        -j MARK --set-mark 9

############################################################################
#
# Respuesta
#
############################################################################
#

#echo 'Cola:'
#tc qdisc show dev eth0
#echo ''
#echo ''
#echo 'Clases:'
#tc class show dev eth0
#echo ''
#echo ''
echo 'Filtros:'
tc filter show dev eth0







> I am looking for a good htb traffic shaping script to prioritize incoming
> traffic over outgoing traffic for my machine.  I have a 100mbit line, ftp
> up, backup data comming in, but whenever mirrors starts grabbing it they
use
> all the traffic and the backup data comming in (the important data) drops
to
> like 300kb/sec.  I was thinking some script doing
>
> sleep 60
> [if downstream > 1mb/sec, limit upstream -1mb/sec] or something.
>
> Also, the machine isnt the best box, so once it gets up to about 10MB/s
> transfer the CPU is running at 100% and cant go much faster, so getting
cpu
> usage low and maybe have it a little less accurate is preferable.
>
> _________________________________________________________________
> Help STOP SPAM with the new MSN 8 and get 2 months FREE*
> http://join.msn.com/?page=features/junkmail
>
> _______________________________________________
> LARTC mailing list / LARTC@xxxxxxxxxxxxxxx
> http://mailman.ds9a.nl/mailman/listinfo/lartc HOWTO: http://lartc.org/
>




[Index of Archives]     [LARTC Home Page]     [Netfilter]     [Netfilter Development]     [Network Development]     [Bugtraq]     [GCC Help]     [Yosemite News]     [Linux Kernel]     [Fedora Users]
  Powered by Linux