From: Martin Schwenke Date: Wed, 8 Apr 2026 01:28:41 +0000 (+1000) Subject: ctdb-scripts: Add function ip_addr_add() X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=44f5207bd7c562c1507984fddefc5e8f663f95cc;p=thirdparty%2Fsamba.git ctdb-scripts: Add function ip_addr_add() 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 Reviewed-by: John Mulligan --- diff --git a/ctdb/config/events/legacy/10.interface.script b/ctdb/config/events/legacy/10.interface.script index 21cc04e49a7..a23bac4bb07 100755 --- a/ctdb/config/events/legacy/10.interface.script +++ b/ctdb/config/events/legacy/10.interface.script @@ -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 diff --git a/ctdb/config/functions b/ctdb/config/functions index cd923957e32..581e5a29e68 100755 --- a/ctdb/config/functions +++ b/ctdb/config/functions @@ -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"