]> git.ipfire.org Git - thirdparty/samba.git/commitdiff
ctdb-scripts: Add function ip_addr_del()
authorMartin Schwenke <mschwenke@ddn.com>
Thu, 2 Apr 2026 01:45:05 +0000 (12:45 +1100)
committerMartin Schwenke <martins@samba.org>
Thu, 16 Apr 2026 23:09:33 +0000 (23:09 +0000)
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 <mschwenke@ddn.com>
Reviewed-by: John Mulligan <jmulligan@redhat.com>
ctdb/config/events/legacy/10.interface.script
ctdb/config/events/legacy/11.natgw.script
ctdb/config/functions

index e46690b4bb9df1ba69ef2adb142fc2ed07098c14..21cc04e49a7e10fd368ecadc43763493d1f74943 100755 (executable)
@@ -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
index 99944c64402dba77c9ce3a98b47daf346a2a0045..7d3f8638a363d26ba765fec410f208a32aca5782 100755 (executable)
@@ -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
index ff6491f347bbd2f5f4899650dfb42cfd4f3c5eb5..cd923957e3206e791109bf5cf89b0fa04b0fcf9d 100755 (executable)
@@ -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
 }