]> git.ipfire.org Git - thirdparty/samba.git/commitdiff
ctdb-tests: Implement altname property for ip link/addr
authorMartin Schwenke <mschwenke@ddn.com>
Mon, 13 Apr 2026 04:18:28 +0000 (14:18 +1000)
committerMartin Schwenke <martins@samba.org>
Thu, 16 Apr 2026 23:09:33 +0000 (23:09 +0000)
Only implemented for these commands.  I don't even want to think about
doing this for ip route right now.

Signed-off-by: Martin Schwenke <mschwenke@ddn.com>
Reviewed-by: John Mulligan <jmulligan@redhat.com>
ctdb/tests/UNIT/eventscripts/stubs/ip

index 71feb3a7fd0d0d0f5eada1286b7a32d41ceb79c4..3b74e6e25f44e6d70a523ab708bdf8dcf9e9de8d 100755 (executable)
@@ -37,10 +37,28 @@ ip_link()
                shift
                ip_link_delete "$@"
                ;;
+       prop*)
+               shift
+               ip_link_property "$@"
+               ;;
        *) not_implemented "$*" ;;
        esac
 }
 
+# updates $dev
+convert_altname_dev()
+{
+       for _t in "${FAKE_IP_STATE}/altname/"*"/${dev}"; do
+               if [ -e "$_t" ]; then
+                       _t="${_t%/*}"   # dirname
+                       dev="${_t##*/}" # basename
+                       return 0
+               fi
+       done
+
+       return 1
+}
+
 ip_link_add()
 {
        _link=""
@@ -87,6 +105,8 @@ ip_link_delete()
        mkdir -p "${FAKE_IP_STATE}/interfaces-deleted"
        touch "${FAKE_IP_STATE}/interfaces-deleted/$1"
        rm -f "${FAKE_IP_STATE}/interfaces-vlan/$1"
+       rm -rf "${FAKE_IP_STATE}/altname/$1"
+
 }
 
 ip_link_set_up()
@@ -114,6 +134,8 @@ ip_link_show()
                exit 255
        fi
 
+       convert_altname_dev
+
        if [ -r "${FAKE_IP_STATE}/interfaces-vlan/${dev}" ]; then
                read -r _link <"${FAKE_IP_STATE}/interfaces-vlan/${dev}"
                dev="${dev}@${_link}"
@@ -149,7 +171,36 @@ ip_link_show()
        else
                echo "${n:-42}: ${dev}: ${_status} ${_opts}"
                echo "    link/${_type} ${_mac} brd ${_brd}"
+               for _altname in "${FAKE_IP_STATE}/altname/${dev}/"*; do
+                       if [ -e "$_altname" ]; then
+                               echo "    altname ${_altname##*/}" # basename
+                       fi
+               done
+       fi
+}
+
+ip_link_property()
+{
+       _t="ip link property"
+       if [ $# -ne 5 ]; then
+               not_implemented "${_t} without \"add\""
+       fi
+       if [ "$1" != "add" ] || [ "$2" != "dev" ] || [ "$4" != "altname" ]; then
+               not_implemented \
+                       "${_t} without \"add dev <dev> altname <altname>\""
        fi
+
+       dev="$3"
+       _altname="$5"
+
+       if convert_altname_dev; then
+               echo "RTNETLINK answers: File exists" >&2
+               exit 2
+       fi
+
+       # Each device can multiple altname properties, each specified
+       # by a subdirectory
+       mkdir -p "${FAKE_IP_STATE}/altname/${dev}/${_altname}"
 }
 
 # This is incomplete because it doesn't actually look up table ids in
@@ -247,6 +298,7 @@ ip_addr_show()
                        ;;
                esac
        done
+       convert_altname_dev
        devices="$dev"
        if [ -z "$devices" ]; then
                # No device specified?  Get all the primaries...
@@ -403,6 +455,7 @@ ip_addr_add()
        if [ -z "$dev" ]; then
                not_implemented "addr add (without dev)"
        fi
+       convert_altname_dev
        mkdir -p "${FAKE_IP_STATE}/addresses"
        net_str=$(ipv4_host_addr_to_net "$local")
        net_str=$(echo "$net_str" | sed -e 's@/@_@')
@@ -449,6 +502,7 @@ ip_addr_del()
        if [ -z "$dev" ]; then
                not_implemented "addr del (without dev)"
        fi
+       convert_altname_dev
        mkdir -p "${FAKE_IP_STATE}/addresses"
        net_str=$(ipv4_host_addr_to_net "$local")
        net_str=$(echo "$net_str" | sed -e 's@/@_@')