From a47b5d0d87dcd789baa6449eb62ead41645e96c6 Mon Sep 17 00:00:00 2001 From: Bill Nottingham Date: Tue, 28 Feb 2006 23:43:04 +0000 Subject: array variables are bad. use $IFS with '/', as that is illegal in net device names. coalesce some things into a function. --- sysconfig/network-scripts/ifup-eth | 2 +- sysconfig/network-scripts/network-functions | 28 ++++++++++++++++++---------- 2 files changed, 19 insertions(+), 11 deletions(-) (limited to 'sysconfig/network-scripts') diff --git a/sysconfig/network-scripts/ifup-eth b/sysconfig/network-scripts/ifup-eth index 45efb881..d66ba5af 100755 --- a/sysconfig/network-scripts/ifup-eth +++ b/sysconfig/network-scripts/ifup-eth @@ -40,7 +40,7 @@ is_available ${REALDEVICE} if [ -n "${HWADDR}" ]; then FOUNDMACADDR=`get_hwaddr ${REALDEVICE}` if [ "${FOUNDMACADDR}" != "${HWADDR}" ]; then - curdev=`ip -o link | grep -v link/ieee802.11 | awk -F ': ' -vIGNORECASE=1 "/$HWADDR/ { print \\$2 }"` + curdev=`get_device_by_hwaddr ${HWADDR}` if [ -n "$curdev" ]; then rename_device "${REALDEVICE}" "${HWADDR}" "${curdev}" || { echo $"Device ${DEVICE} has different MAC address than expected, ignoring." diff --git a/sysconfig/network-scripts/network-functions b/sysconfig/network-scripts/network-functions index accff4bd..3e3e4518 100644 --- a/sysconfig/network-scripts/network-functions +++ b/sysconfig/network-scripts/network-functions @@ -25,6 +25,11 @@ get_config_by_hwaddr () LANG=C grep -il "^[[:space:]]*HWADDR=${1}\([[:space:]]\+\|#\+\|$\)" /etc/sysconfig/network-scripts/ifcfg-* } +get_device_by_hwaddr () +{ + LANG=C ip -o link | grep -v link/ieee802.11 | awk -F ': ' -vIGNORECASE=1 "/$1/ { print \$2 }" +} + need_config () { CONFIG="ifcfg-${1}" @@ -157,30 +162,33 @@ do_netreport () # rename_device() - Rename a network device to something else # $1 - desired name -# $2 - hardware address to name -# $3 - Array variable - list of devices that are already in use +# $2 - hardware address to name (no longer used) +# $3 - '/' separated list of devices that are already in use # (for general calls, use the current device you're trying to # change to $1) rename_device() { - local devs=$3 - - /sbin/ip link set "${devs[0]}" name "$1" 2>/dev/null || { + local target=${3##*/} + + /sbin/ip link set "$target" name "$1" || { local hw2=`get_hwaddr ${1}` local nconfig=`get_config_by_hwaddr ${hw2}` + local curdev=`get_device_by_hwaddr ${hw2}` local dev= if [ -n "$nconfig" ]; then dev=$(. $nconfig ; echo $DEVICE) - for device in "${devs[@]}" ; do + oldifs=$IFS + IFS=/ + for device in $3 ; do [ "$dev" = "$device" ] && unset dev done + IFS=$oldifs fi [ -z "$dev" ] && dev=dev$RANDOM - devs[${#devs[@]}]=$1 - rename_device $dev $hw2 $devs - /sbin/ip link set "${devs[0]}" name $1 2>/dev/null + rename_device $dev $hw2 "$3/$curdev" + /sbin/ip link set "$target" name $1 } } @@ -200,7 +208,7 @@ is_available () # trying to rename it: configure_ccwgroup_device if [ -n "$HWADDR" ]; then - local curdev=`ip -o link | grep -v link/ieee802.11 | awk -F ': ' -vIGNORECASE=1 "/$HWADDR/ { print \\$2 }"` + local curdev=`get_device_by_hwaddr "$HWADDR"` if [ -z "$curdev" ]; then return 1 fi -- cgit v1.2.1