summaryrefslogtreecommitdiff
path: root/scripts/vyatta-link-detect
blob: ff3886e2c9925239d845bf0839d6b9b26391fa3f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
#! /bin/bash
#
# Usage: vyatta-link-detect devicename on|off
#

usage() {
    echo "Usage: $0 devicename {on|off}"
    exit 1
}

if [ $# -ne 2 ]; then
    usage
fi

# Note can't use sysctl it is broken for vif name because of dots
# link_filter values:
#   0 - always receive
#   1 - ignore receive if admin_down
#   2 - ignore receive if admin_down or link down
set-sysctl () {
    sudo sh -c "echo $2 >/proc/sys/net/ipv4/conf/$1/link_filter"
#   sudo sh -c "echo $2 >/proc/sys/net/ipv6/conf/$1/link_filter"
}

case $2 in
on)	set-sysctl $1 2
        if [ -f /usr/sbin/zebra ]; then
	    exec vtysh -c "configure terminal" -c "interface $1" \
	        -c "link-detect" 
        fi ;;
off)    set-sysctl $1 1
        if [ -f /usr/sbin/zebra ]; then
	    exec vtysh -c "configure terminal" -c "interface $1" \
	        -c "no link-detect"
        fi ;;
*)	usage;;
esac
# not reached