0

I am trying to do bandwidth control for an ipset using these tutorials 1,3,21. And this script. I have modified it to get ipsetnames.

This is my bandwithshaing script.

TC=/sbin/tc
IF=wlan0             # Interface 
DNLD=1mbit          # DOWNLOAD Limit
UPLD=1mbit          # UPLOAD Limit 
IP1="myIPset1"     # Host IP
IP2="myIPset2"
U32="$TC filter add dev $IF protocol ip parent 1:0 prio 1 u32"

start() {

    $TC qdisc add dev $IF root handle 1: htb default 30
    $TC class add dev $IF parent 1: classid 1:1 htb rate $DNLD
    $TC class add dev $IF parent 1: classid 1:2 htb rate $UPLD
    $U32 match iptables dst $IP flowid 1:1
    $U32 match iptables src $IP flowid 1:2

        #second chain
    $TC qdisc add dev $IF root handle 1: htb default 30
    $TC class add dev $IF parent 1: classid 1:1 htb rate $DNLD
    $TC class add dev $IF parent 1: classid 1:2 htb rate $UPLD
    $U32 match iptables dst $IP1 flowid 1:1
    $U32 match iptables src $IP1 flowid 1:2
}

stop() {

    $TC qdisc del dev $IF root

}

restart() {

    stop
    sleep 1
    start
    }

show() {

    $TC -s qdisc ls dev $IF
    }
case "$1" in

  start)
        echo -n "Starting bandwidth shaping: "
    start
    echo "done"
    ;;

  stop)

    echo -n "Stopping bandwidth shaping: "
    stop
    echo "done"
    ;;

  restart)
        echo -n "Restarting bandwidth shaping: "
    restart
    echo "done"
    ;;
  show)
        echo "Bandwidth shaping status for $IF:\n"
    show
    echo ""
    ;;

  *)
        pwd=$(pwd)
    echo "Usage: $(/usr/bin/dirname $pwd)/tc.bash {start|stop|restart|show}"
    ;;

esac
exit 0

When I try to start bandwithshaping script, I am getting following output. Starting bandwidth shaping: Illegal "match"

Illegal "match"
RTNETLINK answers: File exists
RTNETLINK answers: File exists
RTNETLINK answers: File exists
Illegal "match"
Illegal "match"
done

This is not shaping the bandwidth. If I use an IP address, it works fine.

I am new for qdisc and tc, is it possible to do this?

Thanks in advance. What am I missing here?

1 Answers1

0

"RTNETLINK answers: File exists" error comes when there is already a qdisc attached to root. Usually "tc qdisc del dev $IF root" is run before setting up tc rules on a device so that the old rules are deleted.

Tc rules can be applied only on egress traffic. The root handle is for the egress traffic and there will be no packets with dst set to IP1 or IP2. We use a ifb device to convert ingress traffic to egress and apply rules on it - http://linux-ip.net/gl/tc-filters/tc-filters-node3.html

I'm not sure about using ipset names in filters

livinston
  • 105
  • 1
  • 3