From: Martin Schwenke Date: Thu, 2 Apr 2026 01:45:05 +0000 (+1100) Subject: ctdb-scripts: Add function ip_addr_del() X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=1fafe9a24f8555a5f3f304e221bf1f28ac3dda54;p=thirdparty%2Fsamba.git ctdb-scripts: Add function ip_addr_del() Using a prefix is more natural because it matches "ip addr ..." usage. It should also allow for less parsing. Update all callers of delete_ip_from_iface() to use this function instead. Retain delete_ip_from_iface() for backward compatibility in case custom event scripts are using it. Signed-off-by: Martin Schwenke Reviewed-by: John Mulligan --- diff --git a/ctdb/config/events/legacy/10.interface.script b/ctdb/config/events/legacy/10.interface.script index e46690b4bb9..21cc04e49a7 100755 --- a/ctdb/config/events/legacy/10.interface.script +++ b/ctdb/config/events/legacy/10.interface.script @@ -179,7 +179,7 @@ releaseip) 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 @@ -225,7 +225,7 @@ updateip) # 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 diff --git a/ctdb/config/events/legacy/11.natgw.script b/ctdb/config/events/legacy/11.natgw.script index 99944c64402..7d3f8638a36 100755 --- a/ctdb/config/events/legacy/11.natgw.script +++ b/ctdb/config/events/legacy/11.natgw.script @@ -88,8 +88,8 @@ _natgw_clear() _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 diff --git a/ctdb/config/functions b/ctdb/config/functions index ff6491f347b..cd923957e32 100755 --- a/ctdb/config/functions +++ b/ctdb/config/functions @@ -696,11 +696,10 @@ add_ip_to_iface() 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 @@ -709,12 +708,21 @@ delete_ip_from_iface() # 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() { @@ -741,8 +749,10 @@ drop_ip() 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 }