--- IPaddr2 2011-03-10 17:03:25.000000000 +0100 +++ IPaddr2Interface 2011-03-10 19:56:37.000000000 +0100 @@ -12,6 +12,7 @@ # # Copyright (c) 2003 Tuomo Soini # Copyright (c) 2004-2006 SUSE LINUX AG, Lars Marowsky-Brée +# Copyright (c) 2004-2011 IPCom GmbH, www.ipcom.at, Klaus Darilion # All Rights Reserved. # # This program is free software; you can redistribute it and/or modify @@ -356,16 +357,33 @@ # is an interface name (e.g., "eth0"). # find_interface() { + ipaddr="$1" # # List interfaces but exclude FreeS/WAN ipsecN virtual interfaces # - local iface=`$IP2UTIL -o -f inet addr show | grep "\ $BASEIP/$NETMASK" \ + local iface=`$IP2UTIL -o -f inet addr show | grep "\ $ipaddr/" \ | cut -d ' ' -f2 | grep -v '^ipsec[0-9][0-9]*$'` echo $iface return 0 } # +# Find out if the interface is up, return "up" or "down" +# +interface_status() { + iface="$1" + local status="`$IP2UTIL -o link show "$iface" up`" + + if [ -z "$status" ]; then + echo "down" + return 0 + fi + + echo "up" + return 0 +} + +# # Delete an interface # delete_interface () { @@ -391,6 +409,17 @@ iface="$4" label="$5" + # If the address is already configured, the adding will fail + # (eg. interface is configured, but DOWN). Therefore always + # delete the IP address first. + cur_nic="`find_interface $ipaddr`" + if [ -n "$cur_nic" ]; then + CMD="$IP2UTIL -f inet addr del $ipaddr dev $cur_nic" + + ocf_log info "$CMD" + $CMD + fi + CMD="$IP2UTIL -f inet addr add $ipaddr/$netmask brd $broadcast dev $iface" if [ ! -z "$label" ]; then @@ -557,6 +586,12 @@ ;; esac + int_status="`interface_status $cur_nic`" + if [ "$int_status" = "down" ]; then + echo "no" + return 0 + fi + echo "ok" return 0 fi