vlan.sh 1.45 KB
Newer Older
1 2
#!/bin/sh

3
tmpdir=/tmp
4
vlans_set_status_file="$tmpdir"/vlans_set_status
5 6 7 8 9

dotconfig=/wr/etc/dot-config

set -o pipefail

10 11 12
start() {
    echo -n "Setting up VLANs: "

13 14 15 16 17 18 19
    if [ -f $dotconfig ]; then
	. $dotconfig
    else
	echo "$0 unable to start wrs_throttling, unable to source " \
	      "dot-config ($dotconfig)!"
	exit 1
    fi
20

21 22 23 24 25 26 27 28 29 30 31 32
    WRS_LOG=$CONFIG_WRS_LOG_OTHER

    # if empty turn it to /dev/null
    if [ -z $WRS_LOG ]; then
	WRS_LOG="/dev/null";
    fi

    # if a pathname, use it
    if echo "$WRS_LOG" | grep / > /dev/null; then
	eval LOGPIPE=\" \> $WRS_LOG 2\>\&1 \";
    else
	# not a pathname: use verbatim
33
	eval LOGPIPE=\" 2\>\&1 \| logger -t vlan -p $WRS_LOG\"
34 35
    fi

36 37 38 39 40 41
    # set msg level
    if [ ! -z $CONFIG_WRS_LOG_LEVEL_OTHER ]; then
	WRS_MSG_LEVEL=$CONFIG_WRS_LOG_LEVEL_OTHER
	export WRS_MSG_LEVEL
    fi

42 43 44 45
    # set-up VLANs
    eval /wr/bin/wrs_vlans -f /wr/etc/dot-config $LOGPIPE
    ret=$?
    if [ $ret -eq 0 ]; then
46
	echo "OK"
47
	echo "ok" > $vlans_set_status_file
48 49
    elif [ $ret -eq 2 ]; then
	echo "Disabled"
50
	echo "disabled" > $vlans_set_status_file
51 52
    else
	echo "Failed"
53
	echo "failed" > $vlans_set_status_file
54 55 56 57 58 59
    fi
}

stop() {
    echo -n "Clean VLANs' configuration: "

60
    /wr/bin/wrs_vlans --port 1-18 --pmode 3
61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85
    /wr/bin/wrs_vlans --clear

    echo "OK"
}

restart() {
    stop
    start
}

case "$1" in
    start)
	start
	;;
    stop)
	stop
	;;
    restart|reload)
	restart
	;;
    *)
	echo $"Usage: $0 {start|stop|restart}"
	exit 1
	;;
esac