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
|
#!/bin/bash
# $Header: /var/local/cvs/debian/ifupdown-scripts-zg2/scripts/ifupdown-scripts-zg2.d/eth-interfacename,v 1.1 2004/09/12 18:00:04 mh Exp $
# Environment:
# IFACE = Logical interface name
# MODE = { start | stop }
# METHOD = manual, otherwise exit
# ADDRFAM = inet, otherwise exit
# IF_DEVICE = physical interface name (defaults to logical)
# IF_MAC = MAC address of interface. If not given, use $IF_DEVICE
# IF_MASTER = device name of VLAN master. If not given, search for
# master by MAC address.
. /etc/network/ifupdown-scripts-zg2.d/common-functions
# remove state if interface is being stopped
if [ "$MODE" = "stop" ]; then
exec_down "mac" ""
exec_down "dev" ""
exit 0
fi
# only do something for ethernet interfaces
[ "$IF_TYPE" != "eth" -a -n "$IF_TYPE" ] && exit 0
# only do something if interface is being started
[ "$MODE" = "start" ] || exit 0
# save state
add_down "dev" "$IF_DEVICE"
# get MAC address of VLAN master. If that is not given, later code will
# identify the VLAN master interface by the MAC address given
if [ -n "$IF_MASTER" ]; then
IF_MAC=`get_if_mac "$IF_MASTER"`
fi
# get MAC address of the physical device if not given. Otherwise, later
# code will search for an interface with the given MAC address and appro-
# priately rename the physical interface.
if [ -z "$IF_MAC" ]; then
IF_MAC=`get_if_mac "$IF_DEVICE"`
fi
add_down "mac" "$IF_MAC"
# find current physical interface name that has the MAC we want
INVALID="no:valid:interface"
for iface in `list_ifaces` $INVALID; do
MAC=`get_if_mac "$iface"`
VLAN=`get_vlan_id "$iface"`
if [ "$MAC" = "$IF_MAC" -a "$VLAN" = "$IF_VLAN_ID" ]; then
break
fi
done
# check
for sfile in `grep -l "^mac: $IF_MAC" $STATEDIR/*.state`; do
logicalif="${sfile%.state}"
logicalif="${logicalif##*/}"
VLAN=$[`dev_state_entry "$logicalif" vlan-id`+0]
[ "$VLAN" != "$IF_VLAN_ID" ] && continue
DEV=`dev_state_entry "$logicalif" dev`
if [ "$DEV" != "$IF_DEVICE" ]; then
error "device with MAC address $IF_MAC${IF_VLAN_ID+ (vlan $IF_VLAN_ID)} already up as $DEV for $logicalif."
iface="$INVALID"
break
fi
done
if [ "$iface" = "$INVALID" ]; then
# there is no interface with the desired MAC
# rename interface $IF_DEVICE so that we don't accidentally use it
# we firmly believe that inv$$ ($$ being the pid of the process) will
# be sufficiently random. This _might_ fail if two misconfigured inter-
# faces are in the system and a lot of time passes between initialization
# attempts so that pids have rolled over in the mean time.
msg "renaming $IF_DEVICE, and disabling interface"
cmd "ip link set dev \"$IF_DEVICE\" down"
cmd "ip link set dev \"$IF_DEVICE\" name inv$$"
abort "no interface with MAC address $IF_MAC${IF_VLAN_ID+ (vlan $IF_VLAN_ID)} available for use as $IF_DEVICE"
fi
# set physical interface name to what we want to have
if [ "$iface" != "$IF_DEVICE" ]; then
# we need to rename the iface
cmd "ip link set dev \"$iface\" down"
cmd "ip link set dev \"$iface\" name \"$IF_DEVICE\""
#else
# iface already has the correct name, we're done
fi
cmd "ip link set dev $IF_DEVICE up"
# vi:sw=2
|