/network/if-down.d/ifupdown-scripts-zg2-60address
http://github.com/brinkman83/bashrc · #! · 102 lines · 86 code · 16 blank · 0 comment · 0 complexity · 382523840e110c53c6cb646873428c33 MD5 · raw file
- #!/bin/bash
- # $Header$
- # 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" ]; then
- # if logical device name differs from physical, label interface
- 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=""
- if echo $IF_FLAGS | grep -s -q -i "secondary"; then
- SECONDARY="1"
- fi
- # 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 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 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"
- ;;
- stop)
- ADDR=$(state_entry ip-address)
- DEV=$(state_entry ip-dev)
- exec_down "ip-address" ""
- exec_down "ip-dev" ""
- if [ -n "$DEV" ]; then
- if ip addr show dev "$DEV" primary | \
- grep -s -q "$ADDR"; then
- # we are trying to take down a primary IP address
- if ip addr show dev "$DEV" secondary | \
- grep -s -q inet[^6]; then
- # there are still secondary IPs present
- abort "take down secondary IPs before taking down primary IPs."
- fi
- fi
- fi
- exec_down "address" "ip"
- ;;
- *)
- ;;
- esac
- # end of file