From 3ff74eae0e5e98c238b5413f56e6340cfec1352d Mon Sep 17 00:00:00 2001 From: Fletcher Dunn Date: Mon, 18 May 2026 07:34:44 -0700 Subject: [PATCH] Setup loopback aliases for p2p tests properly --- .github/workflows/build.yml | 6 ++++++ .github/workflows/macos.yml | 14 ++++---------- tests/test_p2p.py | 21 ++++++++++++++++++--- 3 files changed, 28 insertions(+), 13 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 1c91f9d..7731b2c 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -74,6 +74,8 @@ jobs: run: | sudo -E bash .github/install.sh sudo -E bash .github/install-post.sh + - name: Setup mock IPs + run: sudo python3 tests/test_p2p.py --setup-mock-ips - name: Build and test (RelWithDebInfo) run: | set -euo pipefail @@ -186,6 +188,10 @@ jobs: steps: - uses: actions/checkout@main + - name: Setup mock IPs + run: py -3 tests/test_p2p.py --setup-mock-ips + shell: cmd + # Mark all directories as safe so checkouts performed in CMakeLists.txt don't cause "unsafe repository" errors. # See https://github.com/actions/checkout/issues/766 - name: Configure Git diff --git a/.github/workflows/macos.yml b/.github/workflows/macos.yml index b24b557..d83b604 100644 --- a/.github/workflows/macos.yml +++ b/.github/workflows/macos.yml @@ -14,6 +14,10 @@ jobs: steps: - uses: actions/checkout@v4 + - name: Setup mock IPs + run: sudo python3 tests/test_p2p.py --setup-mock-ips + shell: bash + - name: Ensure vcpkg cache directories exist run: | mkdir -p "${VCPKG_DOWNLOADS}" @@ -61,21 +65,11 @@ jobs: run: ./test_connection suite-quick shell: bash - - name: Setup mock IPs - working-directory: ${{github.workspace}}/build/bin - run: sudo python3 test_p2p.py --setup-mock-ips - shell: bash - - name: Test p2p working-directory: ${{github.workspace}}/build/bin run: python3 test_p2p.py --spewlevel=debug --loglevel-p2prendezvous=debug shell: bash - - name: Cleanup mock IPs - working-directory: ${{github.workspace}}/build/bin - run: sudo python3 test_p2p.py --cleanup-mock-ips - shell: bash - - name: Configure CMake (Release) run: cmake -B ${{github.workspace}}/build-release -DCMAKE_BUILD_TYPE=Release diff --git a/tests/test_p2p.py b/tests/test_p2p.py index c9043f2..2fb00c2 100755 --- a/tests/test_p2p.py +++ b/tests/test_p2p.py @@ -208,6 +208,8 @@ def _IsAddressBindable( addr ): except OSError: return False +_WINDOWS_LOOPBACK_IFACE = 'Loopback Pseudo-Interface 1' + def _AddLoopbackAddr( addr ): is_ipv6 = ':' in addr sys_name = platform.system() @@ -223,7 +225,12 @@ def _AddLoopbackAddr( addr ): print( "Running 'ip -6 addr add %s/112 dev lo'" % addr ) subprocess.run( [ 'ip', '-6', 'addr', 'add', addr + '/112', 'dev', 'lo' ], check=True ) # IPv4 on Linux: the entire 127/8 block is routable on lo, nothing to do. - # Windows: TBD when needed + elif sys_name == 'Windows': + if is_ipv6: + print( "Running 'netsh interface ipv6 add address \"%s\" %s'" % ( _WINDOWS_LOOPBACK_IFACE, addr ) ) + subprocess.run( [ 'netsh', 'interface', 'ipv6', 'add', 'address', + _WINDOWS_LOOPBACK_IFACE, addr ], check=True ) + # IPv4 on Windows: the entire 127/8 block is routable on the loopback adapter, nothing to do. def _RemoveLoopbackAddr( addr ): is_ipv6 = ':' in addr @@ -240,7 +247,12 @@ def _RemoveLoopbackAddr( addr ): print( "Running 'ip -6 addr del %s/112 dev lo'" % addr ) subprocess.run( [ 'ip', '-6', 'addr', 'del', addr + '/112', 'dev', 'lo' ], check=False ) # IPv4 on Linux: nothing was added, nothing to remove. - # Windows: TBD when needed + elif sys_name == 'Windows': + if is_ipv6: + print( "Running 'netsh interface ipv6 delete address \"%s\" %s'" % ( _WINDOWS_LOOPBACK_IFACE, addr ) ) + subprocess.run( [ 'netsh', 'interface', 'ipv6', 'delete', 'address', + _WINDOWS_LOOPBACK_IFACE, addr ], check=False ) + # IPv4 on Windows: nothing was added, nothing to remove. def SetupMockIPs(): """Add loopback aliases for every mock address that is not already bindable.""" @@ -264,7 +276,10 @@ def CheckMockIPsBindable(): print( "ERROR: the following addresses required by the mock network are not bindable:" ) for addr in missing: print( " " + addr ) - print( "Run 'sudo %s --setup-mock-ips' to add the required loopback aliases." % sys.argv[0] ) + if platform.system() == 'Windows': + print( "Run '%s --setup-mock-ips' from an elevated (Administrator) prompt." % sys.argv[0] ) + else: + print( "Run 'sudo %s --setup-mock-ips' to add the required loopback aliases." % sys.argv[0] ) sys.exit(1) def _nat( internal, gateway, nat_type ):