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 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 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 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110
|
#!/bin/bash
# $Header: /var/local/cvs/debian/ifupdown-scripts-zg2/scripts/ifupdown-scripts-zg2.d/address,v 1.1 2004/09/12 18:00:04 mh Exp $
# IFACE = Logical interface name
# MODE = start | stop
# METHOD = manual, otherwise exit!
# IF_ADDRESS = address/prefix
# IF_DEVICE = physical interface name
# IF_SCOPE = scope of address
# IF_BRD = broadcast address (all1 default, all0/none allowed)
# IF_FLAGS = "secondary"
. /etc/network/ifupdown-scripts-zg2.d/common-functions
# check that an address has been configured for this interface
# TODO: Maybe check if it actually looks like an IP address?
[ -z "$IF_ADDRESS" ] && exit 0
case "$MODE" in
start)
# build address parameters, parse flags
ADDRPARM="dev $IF_DEVICE"
if [ "$IF_DEVICE" != "$IFACE" -a "$IF_TYPE" != "atm" ]; then
# if logical device name differs from physical, label interface
# atm doesn't allow labels on Interfaces (atm-tools 2.4.1)
ADDRPARM="$ADDRPARM label $IF_DEVICE:$IFACE"
fi
IF_BRD=${IF_BRD:="all1"}
case "$IF_BRD" in
none) : ;;
all1) ADDRPARM="$ADDRPARM broadcast +";;
all0) ADDRPARM="$ADDRPARM broadcast -";;
*) ADDRPARM="$ADDRPARM broadcast $IF_BRD";;
esac
ADDRPARM="$ADDRPARM $IF_ADDRESS"
ADDRPARM="$ADDRPARM ${IF_SCOPE:+scope } $IF_SCOPE"
SECONDARY=""
echo $IF_FLAGS | grep -s -q -i "secondary" && SECONDARY="1"
# initialize interface
cmd "ip addr add $ADDRPARM"
# check if primary or secondary IP
# primary / secondary IP addresses need to be addresed differently since
# taking down a primary IP also removes the secondaries. This can have
# unwanted effects to network connectivity and wrecks our interface state.
if /sbin/ip addr show dev $IF_DEVICE secondary | \
grep -s -q $IF_ADDRESS; then
# $IF_ADDRESS has become secondary IP
if [ -z "$SECONDARY" ]; then
# $IF_ADDRESS is not marked as secondary
# take away IP again
ip addr del $ADDRPARM
abort "secondary IP not marked as such in /etc/network/interface"
fi
elif /sbin/ip addr show dev $IF_DEVICE primary | \
grep -s -q $IF_ADDRESS; then
# $IF_ADDRESS has become primary IP
if [ -n "$SECONDARY" ]; then
# $IF_ADDRESS is marked as secondary
# take away IP again
ip addr del $ADDRPARM
abort "secondary IP came up as primary. Bring up primary before bringing up secondaries."
fi
fi
add_down "address" "addr del $ADDRPARM"
add_down "ip-address" "$IF_ADDRESS"
add_down "ip-dev" "$IF_DEVICE"
cmd "ip link set dev $IF_DEVICE up"
;;
stop)
ADDR=`state_entry ip-address`
DEV=`state_entry ip-dev`
exec_down "ip-address" ""
exec_down "ip-dev" ""
if /sbin/ip addr show dev $DEV primary | \
grep -s -q $ADDR; then
# we are trying to take down a primary IP address
if /sbin/ip addr show dev $DEV secondary | \
grep -s -q inet; then
# there are still secondary IPs present
abort "take down secondary IPs before taking down primary IPs."
fi
fi
exec_down "address" "ip"
DEV=`state_entry dev`
if ! /sbin/ip addr show dev $DEV | grep -s -q inet; then
# device doesn't have any more IP addresses
if ! is_active_vlan_master $DEV; then
# if we take down an interface that is an active vlan master,
# we take down all VLANs. Not a good idea.
cmd "ip link set dev $DEV down"
fi
fi
;;
*)
;;
esac
# end of file
|