Re: init scripts to use and save iproute and tc rules

Linux Advanced Routing and Traffic Control

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

 



|Where can I find any init scripts to use and save iproute and tc rules?
]- here is one for tcng for mandrake, u can easly change it for tc (just edit start() ) to suit your needs


#!/bin/sh
#
# tcng:       Starts the tcng Server
#
# Version:      @(#) /etc/rc.d/init.d/tcng 0.1
#
# chkconfig: 2345 90 10
# description: Starts and stops the tcng at boot time and shutdown.
#
# processname: tcng
#
# created : from Raptor
#

#path to the tc command
tc=/sbin/tc
#path to the tcc command
tcc=/arh/bin/com.pl
#where is the tcng config file
tcngConf=/path/tcng/blah.tcng

offMsg=OFF
onMsg=ON
debug=1

# Source function library.
. /etc/rc.d/init.d/functions

isUp () {
    res=`$tc qdisc show dev $1`
    if [ -z "$res" ]; then return 1; fi
    return 0
}

start () {
    gprintf "Starting tcng services: "; echo
    OLDIFS="$IFS"
    IFS="
"
    cmds=`$tcc $tcngConf | grep -v "^#" | sed -e "s/^tc//"`
    for cmd in $cmds; do
        [ $debug -eq 1 ] && gprintf "Execute : $cmd:" && echo; 
        eval "$tc $cmd"
    done
    touch /var/lock/subsys/tcng
    IFS="$OLDIFS"
}


stop () {
    gprintf "Stopping some/all tcng services: "
    echo
    #if explictly specified shut only these devices
    [ "$1" ] && devs=$*;
#	echo $devs
    for d in $devs; do
        if isUp $d ; then 
    	    gprintf "Flushing : $d"; echo
    	    $tc qdisc del dev $d root
	else gprintf "No traffic control running on : $d"; echo
        fi
#    	    rm -f /var/lock/subsys/tcng-$d	    
    done	
    rm -f /var/lock/subsys/tcng;#this is not the correct behavior 	
}


status () {
     [ "$1" ] && devs=$*;	
#    echo $devs
    for d in $devs; do
        if isUp $d ; 
    	    then gprintf "traffic control on $d : [$onMsg]"; echo;
	    else gprintf "traffic control on $d: [$offMsg]"; echo;
	fi
    done		
}

show () {
    if [ -z "$1" ]; then what=all; else what=$1; fi
    shift
    if [ "$1" ]; then devs=$*; fi	
    for d in $devs; do
	if isUp $d; then
    	    [ "$what" = "all" ] || [ "$what" = "qdisc" ] && gprintf "`$tc qdisc show dev $d`"; echo    
    	    [ "$what" = "all" ] || [ "$what" = "class" ] && gprintf "`$tc class show dev $d`"; echo    	
    	    [ "$what" = "all" ] || [ "$what" = "filter" ] && gprintf "`$tc filter show dev $d`"; echo    	
	fi
    done
}


parse () {
    echo "$1" | perl -ne '
	$_ =~ s/(\d+?:\d+?)/$1/gs;
	print $_
    ' 
}

stat () {
    [ -z "$1" ] || [ -z "$2" ] && gprintf "qdisc|class or device has to be specified !!!" && echo && exit;
    parse "`$tc -s $1 show dev $2`"
}

devs=`ifconfig -a | grep '^\w' | grep -v lo | cut -f 1 -d ' '`
command=$1
shift;

case "$command" in
  start) start ;;
  stop)	stop $@ ;;
  status) status $@ ;;
  show) show $@ ;;	
  stat) stat $@ ;;
  restart)
	gprintf "Restarting tcng. "; echo
	stop $@
	start $@
	;;
  *)
	gprintf "*** Usage: 
	    tcng {start|stop|status|restart} [devices]
	    tcng show [all|qdisc|class|filter] [devices]
	    tcng stat [qdisc|class] [devices]
	"; echo
	exit 1
esac

exit 0

_______________________________________________
LARTC mailing list / LARTC@mailman.ds9a.nl
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