#!/bin/sh PATH=/sbin:/usr/sbin:/usr/local/sbin:$PATH DEV=eth0 tcf () { if ! tc "$@" ; then echo Failed on: tc "$@" exit 1 fi } tc qdisc del dev $DEV root 2> /dev/null > /dev/null tc qdisc del dev $DEV ingress 2> /dev/null > /dev/null if [ $# != 3 ]; then exit 1; fi #tcf qdisc add dev $DEV root handle 100: prio bands 5 priomap 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 tcf qdisc add dev $DEV root handle 100: prio bands 4 priomap 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 #tcf qdisc add dev $DEV root handle 100: prio bands 3 priomap 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 tcf qdisc add dev eth0 parent 100:1 handle 110: bfifo limit 1000 tcf qdisc add dev eth0 parent 100:2 handle 120: bfifo limit 1000 tcf qdisc add dev eth0 parent 100:3 handle 130: pfifo tcf qdisc add dev eth0 parent 100:4 handle 140: tbf rate $1kbit latency $3ms burst 1540 peakrate $2kbit mtu 1540 # filters # 110 is for ut # 120 for other udp traffic # 130 for tcp acks & icmp # 140 is for rest icmp_match="match ip protocol 1 0xff" tcp_match="match ip protocol 6 0xff" udp_match="match ip protocol 17 0xff" # ff == first fragment == fragment offset=0 ipff_match="match u16 0 0x1fff at 6" icmpff_match="$icmp_match $ipff_match" tcpff_match="$tcp_match $ipff_match" udpff_match="$udp_match $ipff_match" #ssh_smatch=" $tcpff_match match ip sport 22 0xffff" #ssh_dmatch=" $tcpff_match match ip dport 22 0xffff" #telnet_dmatch="$tcpff_match match ip sport 23 0xffff" #www_smatch=" $tcpff_match match ip sport 80 0xffff" ut_smatch=" $udpff_match match ip sport 7777 0xff00" ut_dmatch=" $udpff_match match ip dport 7777 0xfc00" ihl20_match=" match u8 0x05 0x0f at 0" lt64_match=" match u16 0x0000 0xffc0 at 2" tcpackbit_match="match u8 0x10 0xff at 33" tcpack_match=" $tcpff_match $ihl20_match $lt64_match $tcpackbit_match" any_match=" match u8 0 0 at 0" tcf filter add dev $DEV parent 100: protocol ip prio 110 u32 $ut_dmatch flowid 100:1 tcf filter add dev $DEV parent 100: protocol ip prio 110 u32 $ut_smatch flowid 100:1 tcf filter add dev $DEV parent 100: protocol ip prio 120 u32 $udp_match flowid 100:2 tcf filter add dev $DEV parent 100: protocol ip prio 130 u32 $icmp_match flowid 100:3 tcf filter add dev $DEV parent 100: protocol ip prio 130 u32 $tcpack_match flowid 100:3 #tcf filter add dev $DEV parent 100: protocol ip prio 120 u32 $ssh_smatch flowid 100:3 #tcf filter add dev $DEV parent 100: protocol ip prio 120 u32 $ssh_dmatch flowid 100:3 #tcf filter add dev $DEV parent 100: protocol ip prio 120 u32 $telnet_dmatch flowid 100:3 #tcf filter add dev $DEV parent 100: protocol ip prio 130 u32 $www_smatch flowid 100:4 tcf filter add dev $DEV parent 100: protocol ip prio 140 u32 $any_match flowid 100:4