update_my_public_ip_addresses "releaseip" "$ip"
if [ -n "$iface" ]; then
- if ! delete_ip_from_iface "$iface" "$ip" "$maskbits"; then
+ if ! ip_addr_del "${ip}/${maskbits}" "$iface"; then
ip_unblock "$ip" "$iface"
exit 1
fi
# they will silently fail.
if [ -n "$oiface" ]; then
ip_block "$ip" "$oiface"
- delete_ip_from_iface "$oiface" "$ip" "$maskbits" >/dev/null 2>&1
+ ip_addr_del "${ip}/${maskbits}" "$oiface" >/dev/null 2>&1
fi
if ! add_ip_to_iface "$niface" "$ip" "$_maskbits"; then
_ip="${CTDB_NATGW_PUBLIC_IP%/*}"
_maskbits="${CTDB_NATGW_PUBLIC_IP#*/}"
- delete_ip_from_iface \
- "$CTDB_NATGW_PUBLIC_IFACE" "$_ip" "$_maskbits" >/dev/null 2>&1
+ ip_addr_del \
+ "${_ip}/${_maskbits}" "$CTDB_NATGW_PUBLIC_IFACE" >/dev/null 2>&1
for _net_gw in $CTDB_NATGW_STATIC_ROUTES; do
_net="${_net_gw%@*}"
ip route del "$_net" metric 10 >/dev/null 2>/dev/null
fi
}
-delete_ip_from_iface()
+ip_addr_del()
{
- _iface=$1
- _ip=$2
- _maskbits=$3
+ _prefix="$1"
+ _iface="$2"
# This could be set globally for all interfaces but it is probably
# better to avoid surprises, so limit it the interfaces where CTDB
# remembering and re-adding secondaries.
set_proc "sys/net/ipv4/conf/${_iface}/promote_secondaries" 1
- if ! ip addr del "$_ip/$_maskbits" dev "$_iface"; then
- echo "Failed to del $_ip on dev $_iface"
+ if ! ip addr del "$_prefix" dev "$_iface"; then
+ echo "Failed to del ${_prefix} on dev ${_iface}"
return 1
fi
}
+delete_ip_from_iface()
+{
+ _iface=$1
+ _ip=$2
+ _maskbits=$3
+
+ ip_addr_del "${_ip}/${_maskbits}" "$_iface"
+}
+
# If the given IP is hosted then print 2 items: maskbits and iface
ip_maskbits_iface()
{
if [ -n "$1" ]; then
_maskbits="$1"
_iface="$2"
- echo "Removing public address $_addr/$_maskbits from device $_iface"
- delete_ip_from_iface "$_iface" "$_addr" "$_maskbits" >/dev/null 2>&1
+
+ _prefix="${_addr}/${_maskbits}"
+ echo "Removing public address ${_prefix} from device ${_iface}"
+ ip_addr_del "$_prefix" "$_iface" >/dev/null 2>&1
fi
}