--- network.subr 2007-11-18 21:58:49.000000000 +0000 +++ network.subr 2007-11-18 22:52:43.000000000 +0000 @@ -585,18 +585,54 @@ return $_ret } +get_if_mac() +{ + ifconfig $1 2>/dev/null | while read proto addr rest; do + case ${proto} in + ether) + echo $addr + esac + done +} + # ifnet_rename # Rename all requested interfaces. # ifnet_rename() { - _ifn_list="`ifconfig -l`" [ -z "$_ifn_list" ] && return 0 for _if in ${_ifn_list} ; do _ifname=`get_if_var $_if ifconfig_IF_name` if [ ! -z "$_ifname" ]; then ifconfig $_if name $_ifname + # ifconfig returns EX_OK even if it fails + _if=$_ifname + fi + + if [ ! -z "$ifconfig_mac_names" ]; then + mac=`get_if_mac $_if | sed -e 's/[^a-f0-9]//g'` + if [ ! -z "$mac" ]; then + eval _ifmac_${mac}_name=$_if + fi + fi + done + + [ -z "$ifconfig_mac_names" ] && return 0 + for _ifname in ${ifconfig_mac_names} ; do + _ifmac=`get_if_var $_ifname ifconfig_mac_IF` + if [ ! -z "$_ifmac" ] ; then + _mac="`echo $_ifmac |tr '[:upper:]' '[:lower:]' |sed -e 's/[^a-f0-9]//g'`" + _if=`eval echo \\${_ifmac_${_mac}_name}` + if [ ! -z $_if ] ; then + if [ ! $_if = $_ifname ]; then + ifconfig $_if name $_ifname + fi + else + warn "Unable to locate interface with MAC $_ifmac for $_ifname" + fi + else + warn "MAC not configured for $_ifname, please set ifconfig_mac_${_ifname}" fi done return 0