]> git.ipfire.org Git - thirdparty/samba.git/commitdiff
ctdb-scripts: Add function ip_addr_add()
authorMartin Schwenke <mschwenke@ddn.com>
Wed, 8 Apr 2026 01:28:41 +0000 (11:28 +1000)
committerMartin Schwenke <martins@samba.org>
Thu, 16 Apr 2026 23:09:33 +0000 (23:09 +0000)
For consistency with new ip_addr_del().

Update all callers of add_ip_to_iface() to use this function
instead.

Retain add_ip_to_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/functions

index 21cc04e49a7e10fd368ecadc43763493d1f74943..a23bac4bb0792c28f854c5d93c7297d8bf1fafdd 100755 (executable)
@@ -143,7 +143,7 @@ takeip)
 
        update_my_public_ip_addresses "takeip" "$ip"
 
-       if ! add_ip_to_iface "$iface" "$ip" "$maskbits"; then
+       if ! ip_addr_add "${ip}/${maskbits}" "$iface"; then
                exit 1
        fi
 
@@ -228,7 +228,7 @@ updateip)
                ip_addr_del "${ip}/${maskbits}" "$oiface" >/dev/null 2>&1
        fi
 
-       if ! add_ip_to_iface "$niface" "$ip" "$_maskbits"; then
+       if ! ip_addr_add "${ip}/${_maskbits}" "$niface"; then
                ip_unblock "$ip" "$oiface"
                exit 1
        fi
index cd923957e3206e791109bf5cf89b0fa04b0fcf9d..581e5a29e68a6228eb997441cd52376c9d29041f 100755 (executable)
@@ -649,11 +649,10 @@ get_tcp_connections_for_ip()
 
 ########################################################
 
-add_ip_to_iface()
+ip_addr_add()
 {
-       _iface=$1
-       _ip=$2
-       _maskbits=$3
+       _prefix="$1"
+       _iface="$2"
 
        # Ensure interface is up
        ip link set "$_iface" up ||
@@ -667,13 +666,14 @@ add_ip_to_iface()
 
        # Intentionally unquoted multi-word value here
        # shellcheck disable=SC2086
-       if ! ip addr add "$_ip/$_maskbits" $_bcast dev "$_iface"; then
-               echo "Failed to add $_ip/$_maskbits on dev $_iface"
+       if ! ip addr add "$_prefix" $_bcast dev "$_iface"; then
+               echo "Failed to add ${_prefix} on dev ${_iface}"
                return 1
        fi
 
        # Wait 5 seconds for IPv6 addresses to stop being tentative...
        if [ -z "$_bcast" ]; then
+               _ip="${_prefix%/*}"
                for _x in $(seq 1 10); do
                        ip addr show to "${_ip}/128" | grep -q "tentative" || break
                        sleep 0.5
@@ -684,18 +684,27 @@ add_ip_to_iface()
                _t=$(ip addr show to "${_ip}/128")
                case "$_t" in
                "")
-                       echo "Failed to add $_ip/$_maskbits on dev $_iface"
+                       echo "Failed to add ${_prefix} on dev ${_iface}"
                        return 1
                        ;;
                *tentative* | *dadfailed*)
-                       echo "Failed to add $_ip/$_maskbits on dev $_iface"
-                       ip addr del "$_ip/$_maskbits" dev "$_iface"
+                       echo "Failed to add ${_prefix} on dev ${_iface}"
+                       ip addr del "$_prefix" dev "$_iface"
                        return 1
                        ;;
                esac
        fi
 }
 
+add_ip_to_iface()
+{
+       _iface=$1
+       _ip=$2
+       _maskbits=$3
+
+       ip_addr_add "${_ip}/${_maskbits}" "$_iface"
+}
+
 ip_addr_del()
 {
        _prefix="$1"