Here's yet another batch of fixes to make the tests more robust against different environments. With this lot, I'm now able to run the pasta, passt, passt_in_ns and two_guests tests on my Fedora system. I'm still hitting problems with the perf tests. This series (specifically 11/18) updates the demo to use socat instead of openbsd netcat. This is needed, or the change to socat in the mbuto image would break the demo. However, I'm hitting unrelated problems trying to run the demos, so the switch to socat is, alas, untested. David Gibson (18): tests: Remove no longer needed /usr/bin/bash link tests: Let Fedora find dhclient-script in /usr/sbin tests: Add rudimentary debugging to dhclient-script tests: Add some extra dhclient support directories to mbuto.img tests: More robust parsing of resolv.conf for DHCP tests tests: Handle the case of a nameserver on host localhost tests: Correctly handle domain search list in dhclient-script tests: Fix detection of empty 'hout' responses in passt{,_in_ns} tests tests: Fix creation of test file in udp passt tests valgrind needs futex tests: Use socat instead of netcat tests: Remove unnecessary ^D in passt_in_ns teardown tests: Remove unnecessary truncation of temporary files in udp tests tests: Use dhclient --no-pid for namespaces in two_guests tests tests: Clean up better after iperf tests tests: No need to retrieve host ifname in ndp/pasta tests: Correct determination of host interface name in tests demo: Use git protocol downloads Makefile | 2 +- test/README.md | 2 +- test/demo/passt | 10 +-- test/demo/pasta | 14 ++--- test/dhcp/passt | 22 +++---- test/lib/setup | 24 ++++++-- test/lib/test | 2 +- test/ndp/pasta | 5 +- test/passt.mbuto | 18 +++--- test/tcp/passt | 36 +++++------ test/tcp/passt_in_ns | 138 +++++++++++++++++++++--------------------- test/tcp/pasta | 58 +++++++++--------- test/two_guests/basic | 24 ++++---- test/udp/passt | 26 ++++---- test/udp/passt_in_ns | 82 +++++++++++-------------- test/udp/pasta | 34 +++++------ 16 files changed, 247 insertions(+), 250 deletions(-) -- 2.36.1
AFAICT the symlink we created in mbuto from /usr/bin/bash to /bin/sh was for the benefit of a dhclient-script which used /usr/bin/bash as its interpreter (e.g. in Fedora). That was a bit risky if the script really did require bash and we linked it to dash or another shell. We now supply our own custom dhclient-script, so we don't need the link any more. Signed-off-by: David Gibson <david(a)gibson.dropbear.id.au> --- test/passt.mbuto | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/test/passt.mbuto b/test/passt.mbuto index 968c1cd..2990020 100755 --- a/test/passt.mbuto +++ b/test/passt.mbuto @@ -19,8 +19,7 @@ KMODS="${KMODS:- virtio_net virtio_pci}" LINKS="${LINKS:- ash,dash,bash /init - ash,dash,bash /bin/sh - ash,dash,bash /usr/bin/bash}" + ash,dash,bash /bin/sh}" DIRS="${DIRS} /tmp /sbin" -- 2.36.1
Modern Fedora (and RHEL) systems have /sbin as a symlink to /usr/sbin (along with a number of similar links). Along with that it expects to find dhclient-script in /usr/sbin/dhclient-script rather than /sbin/dhclient-script. Link them together in our mbuto image so that the Fedora build of dhclient can find it. Signed-off-by: David Gibson <david(a)gibson.dropbear.id.au> --- test/passt.mbuto | 1 + 1 file changed, 1 insertion(+) diff --git a/test/passt.mbuto b/test/passt.mbuto index 2990020..500c34f 100755 --- a/test/passt.mbuto +++ b/test/passt.mbuto @@ -41,6 +41,7 @@ FIXUP="${FIXUP}"' exit 0 EOF chmod 755 /sbin/dhclient-script + ln -s /sbin /usr/sbin :> /etc/fstab sh +m ' -- 2.36.1
We now supply a minimal dhclient-script of our own in the mbuto boot image. There are some problems with it, so add some basic logging to help debug it. Signed-off-by: David Gibson <david(a)gibson.dropbear.id.au> --- test/passt.mbuto | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/test/passt.mbuto b/test/passt.mbuto index 500c34f..fb59cec 100755 --- a/test/passt.mbuto +++ b/test/passt.mbuto @@ -21,11 +21,15 @@ LINKS="${LINKS:- ash,dash,bash /init ash,dash,bash /bin/sh}" -DIRS="${DIRS} /tmp /sbin" +DIRS="${DIRS} /tmp /sbin /var/log" FIXUP="${FIXUP}"' cat > /sbin/dhclient-script << EOF #!/bin/sh +LOG=/var/log/dhclient-script.log +echo \${reason} \${interface} >> \$LOG +set >> \$LOG + [ -n "\${new_interface_mtu}" ] && ip link set dev \${interface} mtu \${new_interface_mtu} [ -n "\${new_ip_address}" ] && ip addr add \${new_ip_address}/\${new_subnet_mask} dev \${interface} -- 2.36.1
Although it can operate without them, dhclient can issue errors if it doesn't have /var/run to write a pid file and /var/lib to write a leases file. Create those in mbuto.img to stop it complaining. Signed-off-by: David Gibson <david(a)gibson.dropbear.id.au> --- test/passt.mbuto | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/passt.mbuto b/test/passt.mbuto index fb59cec..b33c0a8 100755 --- a/test/passt.mbuto +++ b/test/passt.mbuto @@ -21,7 +21,7 @@ LINKS="${LINKS:- ash,dash,bash /init ash,dash,bash /bin/sh}" -DIRS="${DIRS} /tmp /sbin /var/log" +DIRS="${DIRS} /tmp /sbin /var/log /var/run /var/lib" FIXUP="${FIXUP}"' cat > /sbin/dhclient-script << EOF -- 2.36.1
To check publishing of DNS information via DHCP, we need to extract a list of nameservers and/or search domains from resolv.conf in the test script. The current version (usually) leaves the result with a trailing ','. That's usually ok because it happens on both guest and host sides. However it's kind of confusing, and might stop working if the host had a resolv.conf without a trailing \n on the last line. It also makes some later changes we'll need more difficult. So, normalize the output from resolv.conf a bit further, removing any trailing ','. It turns out we can do this with a slightly less complex sed expression than the one we already have. Signed-off-by: David Gibson <david(a)gibson.dropbear.id.au> --- test/dhcp/passt | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/test/dhcp/passt b/test/dhcp/passt index 00047a9..a5491bc 100644 --- a/test/dhcp/passt +++ b/test/dhcp/passt @@ -35,15 +35,15 @@ gout MTU ip -j link show | jq -rM '.[] | select(.ifname == "__IFNAME__").mtu' check [ __MTU__ = 65520 ] test DHCP: DNS -gout DNS sed -n 's/^nameserver \([0-9]*\.\)\(.*\)/\1\2/p' /etc/resolv.conf | tr '\n' ',' | sed 's/\(.*\)/\1\n/g' -hout HOST_DNS sed -n 's/^nameserver \([0-9]*\.\)\(.*\)/\1\2/p' /etc/resolv.conf | head -n3 | tr '\n' ',' | sed 's/\(.*\)/\1\n/g' +gout DNS sed -n 's/^nameserver \([0-9]*\.\)\(.*\)/\1\2/p' /etc/resolv.conf | tr '\n' ',' | sed 's/,$//;s/$/\n/' +hout HOST_DNS sed -n 's/^nameserver \([0-9]*\.\)\(.*\)/\1\2/p' /etc/resolv.conf | head -n3 | tr '\n' ',' | sed 's/,$//;s/$/\n/' check [ "__DNS__" = "__HOST_DNS__" ] # FQDNs should be terminated by dots, but the guest DHCP client might omit them: # strip them first test DHCP: search list -gout SEARCH sed 's/\. / /g' /etc/resolv.conf | sed 's/\.$//g' | sed -n 's/^search \(.*\)/\1/p' | tr ' \n' ',' | sed 's/\(.*\)/\1\n/g' -hout HOST_SEARCH sed 's/\. / /g' /etc/resolv.conf | sed 's/\.$//g' | sed -n 's/^search \(.*\)/\1/p' | tr ' \n' ',' | sed 's/\(.*\)/\1\n/g' +gout SEARCH sed 's/\. / /g' /etc/resolv.conf | sed 's/\.$//g' | sed -n 's/^search \(.*\)/\1/p' | tr ' \n' ',' | sed 's/,$//;s/$/\n/' +hout HOST_SEARCH sed 's/\. / /g' /etc/resolv.conf | sed 's/\.$//g' | sed -n 's/^search \(.*\)/\1/p' | tr ' \n' ',' | sed 's/,$//;s/$/\n/' check [ "__SEARCH__" = "__HOST_SEARCH__" ] test DHCPv6: address @@ -59,11 +59,11 @@ check [ "__GW6__" = "__HOST_GW6__" ] # Strip interface specifier: interface names might differ between host and guest test DHCPv6: DNS -gout DNS6 sed -n 's/^nameserver \([^:]*:\)\([^%]*\).*/\1\2/p' /etc/resolv.conf | tr '\n' ',' | sed 's/\(.*\)/\1\n/g' -hout HOST_DNS6 sed -n 's/^nameserver \([^:]*:\)\([^%]*\).*/\1\2/p' /etc/resolv.conf | tr '\n' ',' | sed 's/\(.*\)/\1\n/g' +gout DNS6 sed -n 's/^nameserver \([^:]*:\)\([^%]*\).*/\1\2/p' /etc/resolv.conf | tr '\n' ',' | sed 's/,$//;s/$/\n/' +hout HOST_DNS6 sed -n 's/^nameserver \([^:]*:\)\([^%]*\).*/\1\2/p' /etc/resolv.conf | tr '\n' ',' | sed 's/,$//;s/$/\n/' check [ "__DNS6__" = "__HOST_DNS6__" ] test DHCPv6: search list -gout SEARCH6 sed 's/\. / /g' /etc/resolv.conf | sed 's/\.$//g' | sed -n 's/^search \(.*\)/\1/p' | tr ' \n' ',' | sed 's/\(.*\)/\1\n/g' -hout HOST_SEARCH6 sed 's/\. / /g' /etc/resolv.conf | sed 's/\.$//g' | sed -n 's/^search \(.*\)/\1/p' | tr ' \n' ',' | sed 's/\(.*\)/\1\n/g' +gout SEARCH6 sed 's/\. / /g' /etc/resolv.conf | sed 's/\.$//g' | sed -n 's/^search \(.*\)/\1/p' | tr ' \n' ',' | sed 's/,$//;s/$/\n/' +hout HOST_SEARCH6 sed 's/\. / /g' /etc/resolv.conf | sed 's/\.$//g' | sed -n 's/^search \(.*\)/\1/p' | tr ' \n' ',' | sed 's/,$//;s/$/\n/' check [ "__SEARCH6__" = "__HOST_SEARCH6__" ] -- 2.36.1
We previously introduced a change to passt to handle the case where the host machine is its own nameserver - so resolv.conf points to 127.0.0.1. In this case we advertize the gateway as the DNS server for the guest, which in turn will be redirected back to the host by existing passt logic. The dhcp/passt doesn't handle this case correctly, so add some logic to account for it. Signed-off-by: David Gibson <david(a)gibson.dropbear.id.au> --- test/dhcp/passt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/dhcp/passt b/test/dhcp/passt index a5491bc..3d2e939 100644 --- a/test/dhcp/passt +++ b/test/dhcp/passt @@ -37,7 +37,7 @@ check [ __MTU__ = 65520 ] test DHCP: DNS gout DNS sed -n 's/^nameserver \([0-9]*\.\)\(.*\)/\1\2/p' /etc/resolv.conf | tr '\n' ',' | sed 's/,$//;s/$/\n/' hout HOST_DNS sed -n 's/^nameserver \([0-9]*\.\)\(.*\)/\1\2/p' /etc/resolv.conf | head -n3 | tr '\n' ',' | sed 's/,$//;s/$/\n/' -check [ "__DNS__" = "__HOST_DNS__" ] +check [ "__DNS__" = "__HOST_DNS__" ] || [ "__DNS__" = "__HOST_GW__" -a "__HOST_DNS__" = "127.0.0.1" ] # FQDNs should be terminated by dots, but the guest DHCP client might omit them: # strip them first @@ -61,7 +61,7 @@ check [ "__GW6__" = "__HOST_GW6__" ] test DHCPv6: DNS gout DNS6 sed -n 's/^nameserver \([^:]*:\)\([^%]*\).*/\1\2/p' /etc/resolv.conf | tr '\n' ',' | sed 's/,$//;s/$/\n/' hout HOST_DNS6 sed -n 's/^nameserver \([^:]*:\)\([^%]*\).*/\1\2/p' /etc/resolv.conf | tr '\n' ',' | sed 's/,$//;s/$/\n/' -check [ "__DNS6__" = "__HOST_DNS6__" ] +check [ "__DNS6__" = "__HOST_DNS6__" ] || [ "__DNS6__" = "__HOST_GW6__" -a "__HOST_DNS6__" = "::1" ] test DHCPv6: search list gout SEARCH6 sed 's/\. / /g' /etc/resolv.conf | sed 's/\.$//g' | sed -n 's/^search \(.*\)/\1/p' | tr ' \n' ',' | sed 's/,$//;s/$/\n/' -- 2.36.1
Currently our small custom dhclient-script only handles the 'domain-name' option, which can just list a single domain, not the 'domain-search' option, which can handle several. Correct it to handle both. We also weren't emptying the resolv.conf file before we began, which could lead to surprising contents after multiple DHCP transactions. Signed-off-by: David Gibson <david(a)gibson.dropbear.id.au> --- test/passt.mbuto | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/test/passt.mbuto b/test/passt.mbuto index b33c0a8..c515a0c 100755 --- a/test/passt.mbuto +++ b/test/passt.mbuto @@ -34,13 +34,13 @@ set >> \$LOG [ -n "\${new_ip_address}" ] && ip addr add \${new_ip_address}/\${new_subnet_mask} dev \${interface} [ -n "\${new_routers}" ] && for r in \${new_routers}; do ip route add default via \${r} dev \${interface}; done +:> /etc/resolv.conf [ -n "\${new_domain_name_servers}" ] && for d in \${new_domain_name_servers}; do echo "nameserver \${d}" >> /etc/resolv.conf; done -[ -n "\${new_domain_name}" ] && (printf "search"; for d in \${new_domain_name}; do printf " %s" "\${d}"; done; printf "\n") >> /etc/resolv.conf - +[ -n "\${new_domain_name}" ] && echo "search \${new_domain_name}" >> /etc/resolf.conf +[ -n "\${new_domain_search}" ] && (printf "search"; for d in \${new_domain_search}; do printf " %s" "\${d}"; done; printf "\n") >> /etc/resolv.conf [ -n "\${new_ip6_address}" ] && ip addr add \${new_ip6_address}/\${new_ip6_prefixlen} dev \${interface} [ -n "\${new_dhcp6_name_servers}" ] && for d in \${new_dhcp6_name_servers}; do echo "nameserver \${d}%\${interface}" >> /etc/resolv.conf; done [ -n "\${new_dhcp6_domain_search}" ] && (printf "search"; for d in \${new_dhcp6_domain_search}; do printf " %s" "\${d}"; done; printf "\n") >> /etc/resolv.conf - [ -n "\${new_host_name}" ] && hostname "\${new_host_name}" exit 0 EOF -- 2.36.1
The dhcp/passt and dhcp/passt_in_ns tests at least, and maybe others use 'hout' commands that need to be able to detect empty output. However, we don't set PS1, which means the screen-scraping logic which detects this may not be reliable. In addition, if the host is using a recent bash, it will have bracketed paste mode enabled which will also add escape codes which will mess up the empty output detection. Set the prompt and disable bracketed paste mode from the passt and passt_in_ns setups to avoid these problems. Signed-off-by: David Gibson <david(a)gibson.dropbear.id.au> --- test/lib/setup | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/test/lib/setup b/test/lib/setup index 0d0f3cf..adbfa9e 100755 --- a/test/lib/setup +++ b/test/lib/setup @@ -57,6 +57,13 @@ setup_passt() { " -device virtio-net-pci,netdev=hostnet0,x-txburst=16384" \ " -netdev socket,fd=5,id=hostnet0" pane_status GUEST + + # Set things up to reduce problems parsing host command output + pane_run HOST "PS1='$ '" + pane_wait HOST + # Non-bash shells will fail this, but also don't need it, so ignore errors + pane_run HOST "bind 'set enable-bracketed-paste off'" + pane_wait HOST } # setup_pasta() - Create a network and user namespace, connect pasta to it @@ -168,6 +175,13 @@ setup_passt_in_ns() { " -device virtio-net-pci,netdev=hostnet0,x-txburst=524288" \ " -netdev socket,fd=5,id=hostnet0" pane_status GUEST + + # Set things up to reduce problems parsing host command output + pane_run HOST "PS1='$ '" + pane_wait HOST + # Non-bash shells will fail this, but also don't need it, so ignore errors + pane_run HOST "bind 'set enable-bracketed-paste off'" + pane_wait HOST } # setup_two_guests() - Set up two namespace, run qemu and passt in both of them -- 2.36.1
In what looks like a copy-and-paste error from the TCP script, the udp/passt test script creates a test file called '__TEMP_BIG__', while the commands it use the variable __TEMP__. Correct this so that a) we actually transfer the data we created for the purpose and b) we don't leave a stale __TEMP_BIG__ file in the current directory. Signed-off-by: David Gibson <david(a)gibson.dropbear.id.au> --- test/udp/passt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/udp/passt b/test/udp/passt index 8a848bd..9598d0e 100644 --- a/test/udp/passt +++ b/test/udp/passt @@ -18,7 +18,7 @@ test UDP/IPv4: host to guest temp TEMP temp NC_PID guestb (nc -u -q1 -4 -l 10001 & echo $! > __NC_PID__) | tee test.bin | (grep -qm1 "END_OF_TEST" && kill $(cat __NC_PID__)) -host dd if=/dev/urandom bs=1k count=5 > __TEMP_BIG__ && printf "\nEND_OF_TEST\n" >> __TEMP__ +host dd if=/dev/urandom bs=1k count=5 > __TEMP__ && printf "\nEND_OF_TEST\n" >> __TEMP__ host cat __TEMP__ | nc -u -q1 -N 127.0.0.1 10001 guestw hout HOST_MD5 md5sum __TEMP__ | cut -d' ' -f1 -- 2.36.1
Some versions of valgrind (such as the version on my Fedora laptop - valgrind-3.19.0-3.fc36.x86_64) use futexes. But futex is currently not allowed in the seccomp filter, even with the extra calls added for valgrind builds. Add it, to avoid spurious valgrind failures. Signed-off-by: David Gibson <david(a)gibson.dropbear.id.au> --- Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Makefile b/Makefile index 6f7c971..0de872e 100644 --- a/Makefile +++ b/Makefile @@ -115,7 +115,7 @@ qrap: $(QRAP_SRCS) passt.h valgrind: EXTRA_SYSCALLS="rt_sigprocmask rt_sigtimedwait rt_sigaction \ getpid gettid kill clock_gettime mmap munmap open \ - unlink gettimeofday" + unlink gettimeofday futex" valgrind: CFLAGS:=-g -O0 $(filter-out -O%,$(CFLAGS)) valgrind: all -- 2.36.1
Commit 41c02e10 ("tests: Use nmap-ncat instead of openbsd netcat for pasta tests") updated the pasta tests to use the nmap version of ncat instead of the openbsd version, for greater portability. For some upcoming changes, however, we'll be wanting to use socat. "socat" can do everything "ncat" can and more, so let's move all the tests using host tools (either directly on the host or via mbuto generated images) to using socat instead. Signed-off-by: David Gibson <david(a)gibson.dropbear.id.au> --- test/README.md | 2 +- test/demo/passt | 8 +-- test/demo/pasta | 12 ++-- test/passt.mbuto | 2 +- test/tcp/passt | 36 +++++------ test/tcp/passt_in_ns | 138 +++++++++++++++++++++--------------------- test/tcp/pasta | 58 +++++++++--------- test/two_guests/basic | 22 +++---- test/udp/passt | 22 +++---- test/udp/passt_in_ns | 72 +++++++++++----------- test/udp/pasta | 28 ++++----- 11 files changed, 200 insertions(+), 200 deletions(-) diff --git a/test/README.md b/test/README.md index 201332b..581949a 100644 --- a/test/README.md +++ b/test/README.md @@ -29,7 +29,7 @@ on a system, i.e. common utilities such as a shell are not included here. Example for Debian, and possibly most Debian-based distributions: build-essential git jq strace iperf3 qemu-system-x86 tmux sipcalc bc - clang-tidy cppcheck isc-dhcp-common psmisc linux-cpupower ncat + clang-tidy cppcheck isc-dhcp-common psmisc linux-cpupower socat netcat-openbsd fakeroot lz4 lm-sensors qemu-system-arm qemu-system-ppc qemu-system-misc qemu-system-x86 valgrind diff --git a/test/demo/passt b/test/demo/passt index bcad718..dac8ac7 100644 --- a/test/demo/passt +++ b/test/demo/passt @@ -130,9 +130,9 @@ nl nl say Let's try to communicate between host and guest. sleep 2 -guestb nc -6 -l -p 5201 +guestb socat TCP6-LISTEN:5201 STDIO sleep 2 -host echo "Hello from the host" | nc -N ::1 5201 +host echo "Hello from the host" | socat -u STDIN TCP6:[::1]:5201 sleep 5 nl @@ -143,9 +143,9 @@ say the address of the default gateway. sleep 2 gout GW ip -j -4 route show|jq -rM '.[] | select(.dst == "default").gateway' sleep 5 -hostb nc -l -p 31337 +hostb socat TCP4-LISTEN:31337 STDIO sleep 2 -guest echo "Hello from the guest" | nc -N __GW__ 31337 +guest echo "Hello from the guest" | socat -u STDIN TCP4:__GW__:x31337 sleep 3 nl diff --git a/test/demo/pasta b/test/demo/pasta index f4b7da2..d84d856 100644 --- a/test/demo/pasta +++ b/test/demo/pasta @@ -99,9 +99,9 @@ nl say pasta detects bound ports and forwards them. sleep 3 -nsb ncat -6 -l ::1 31337 +nsb socat TCP6-LISTEN:31337,bind=[::1] STDOUT sleep 2 -host echo "Hello from the host" | ncat ::1 31337 +host echo "Hello from the host" | socat -u STDIN TCP6:[::1]:31337 sleep 5 nl @@ -110,9 +110,9 @@ say Now the other way around... nl say we can use a loopback address sleep 2 -hostb ncat -l ::1 31337 +hostb socat TCP6-LISTEN:31337,bind=[::1] STDIO sleep 2 -ns echo "Hello from the namespace" | ncat ::1 31337 +ns echo "Hello from the namespace" | socat -u STDIN TCP6:[::1]:31337 sleep 5 nl @@ -120,9 +120,9 @@ say or the address of the default gateway. sleep 2 nsout GW ip -j -4 route show|jq -rM '.[] | select(.dst == "default").gateway' sleep 5 -hostb ncat -l 0.0.0.0 31337 +hostb socat TCP4-LISTEN:31337 STDIO sleep 2 -ns echo "Hello from the namespace" | ncat __GW__ 31337 +ns echo "Hello from the namespace" | socat -u STDIN TCP4:__GW__:31337 sleep 3 nl diff --git a/test/passt.mbuto b/test/passt.mbuto index c515a0c..8b41674 100755 --- a/test/passt.mbuto +++ b/test/passt.mbuto @@ -12,7 +12,7 @@ PROGS="${PROGS:-ash,dash,bash ip mount ls insmod mkdir ln cat chmod lsmod modprobe find grep mknod mv rm umount jq iperf3 dhclient hostname - sed tr chown sipcalc cut md5sum nc dd strace ping tail killall sleep + sed tr chown sipcalc cut md5sum socat dd strace ping tail killall sleep sysctl nproc tcp_rr tcp_crr udp_rr which tee seq bc}" KMODS="${KMODS:- virtio_net virtio_pci}" diff --git a/test/tcp/passt b/test/tcp/passt index 4baa610..6e65137 100644 --- a/test/tcp/passt +++ b/test/tcp/passt @@ -11,75 +11,75 @@ # Copyright (c) 2021 Red Hat GmbH # Author: Stefano Brivio <sbrivio(a)redhat.com> -gtools nc ip jq cat md5sum cut -htools dd nc ip jq cat md5sum cut +gtools socat ip jq md5sum cut +htools dd socat ip jq md5sum cut test TCP/IPv4: host to guest: big transfer temp TEMP_BIG -guestb nc -4 -l 10001 > test_big.bin +guestb socat -u TCP4-LISTEN:10001,reuseaddr OPEN:test_big.bin,create,trunc host dd if=/dev/urandom bs=1M count=10 > __TEMP_BIG__ -host cat __TEMP_BIG__ | nc -N 127.0.0.1 10001 +host socat -u OPEN:__TEMP_BIG__ TCP4:127.0.0.1:10001 guestw hout HOST_MD5_BIG md5sum __TEMP_BIG__ | cut -d' ' -f1 gout GUEST_MD5_BIG md5sum test_big.bin | cut -d' ' -f1 check [ "__GUEST_MD5_BIG__" = "__HOST_MD5_BIG__" ] test TCP/IPv4: guest to host: big transfer -hostb nc -4 -l 10003 > __TEMP_BIG__ +hostb socat -u TCP4-LISTEN:10003,bind=127.0.0.1,reuseaddr OPEN:__TEMP_BIG__,create,trunc gout GW ip -j -4 route show|jq -rM '.[] | select(.dst == "default").gateway' -guest cat test_big.bin | nc -N __GW__ 10003 +guest socat -u OPEN:test_big.bin TCP4:__GW__:10003 hostw hout HOST_MD5_BIG md5sum __TEMP_BIG__ | cut -d' ' -f1 check [ "__GUEST_MD5_BIG__" = "__HOST_MD5_BIG__" ] test TCP/IPv4: host to guest: small transfer temp TEMP_SMALL -guestb nc -4 -l 10001 > test_small.bin +guestb socat -u TCP4-LISTEN:10001,reuseaddr OPEN:test_small.bin,create,trunc host dd if=/dev/urandom bs=2k count=1 > __TEMP_SMALL__ -host cat __TEMP_SMALL__ | nc -N 127.0.0.1 10001 +host socat -u OPEN:__TEMP_SMALL__ TCP4:127.0.0.1:10001 guestw hout HOST_MD5_SMALL md5sum __TEMP_SMALL__ | cut -d' ' -f1 gout GUEST_MD5_SMALL md5sum test_small.bin | cut -d' ' -f1 check [ "__GUEST_MD5_SMALL__" = "__HOST_MD5_SMALL__" ] test TCP/IPv4: guest to host: small transfer -hostb nc -4 -l 10003 > __TEMP_SMALL__ +hostb socat -u TCP4-LISTEN:10003,bind=127.0.0.1,reuseaddr OPEN:__TEMP_SMALL__,create,trunc sleep 1 -guest cat test_small.bin | nc -N __GW__ 10003 +guest socat -u OPEN:test_small.bin TCP4:__GW__:10003 hostw hout HOST_MD5_SMALL md5sum __TEMP_SMALL__ | cut -d' ' -f1 check [ "__GUEST_MD5_SMALL__" = "__HOST_MD5_SMALL__" ] test TCP/IPv6: host to guest: big transfer -guestb nc -6 -l 10001 > test_big.bin +guestb socat -u TCP6-LISTEN:10001,reuseaddr OPEN:test_big.bin,create,trunc sleep 1 -host cat __TEMP_BIG__ | nc -N ::1 10001 +host socat -u OPEN:__TEMP_BIG__ TCP6:[::1]:10001 guestw gout GUEST_MD5_BIG md5sum test_big.bin | cut -d' ' -f1 check [ "__GUEST_MD5_BIG__" = "__HOST_MD5_BIG__" ] test TCP/IPv6: guest to host: big transfer -hostb nc -6 -l 10003 > __TEMP_BIG__ +hostb socat -u TCP6-LISTEN:10003,bind=[::1],reuseaddr OPEN:__TEMP_BIG__,create,trunc gout GW6 ip -j -6 route show|jq -rM '.[] | select(.dst == "default").gateway' gout IFNAME ip -j link show | jq -rM '.[] | select(.link_type == "ether").ifname' -guest cat test_big.bin | nc -N __GW6__%__IFNAME__ 10003 +guest socat -u OPEN:test_big.bin TCP6:[__GW6__%__IFNAME__]:10003 hostw hout HOST_MD5_BIG md5sum __TEMP_BIG__ | cut -d' ' -f1 check [ "__GUEST_MD5_BIG__" = "__HOST_MD5_BIG__" ] test TCP/IPv6: host to guest: small transfer -guestb nc -6 -l 10001 > test_small.bin +guestb socat -u TCP6-LISTEN:10001,reuseaddr OPEN:test_small.bin,create,trunc sleep 1 -host cat __TEMP_SMALL__ | nc -N ::1 10001 +host socat -u OPEN:__TEMP_SMALL__ TCP6:[::1]:10001 guestw gout GUEST_MD5_SMALL md5sum test_small.bin | cut -d' ' -f1 check [ "__GUEST_MD5_SMALL__" = "__HOST_MD5_SMALL__" ] test TCP/IPv6: guest to host: small transfer -hostb nc -6 -l 10003 > __TEMP_SMALL__ +hostb socat -u TCP6-LISTEN:10003,bind=[::1],reuseaddr OPEN:__TEMP_SMALL__,create,trunc sleep 1 -guest cat test_small.bin | nc -N __GW6__%__IFNAME__ 10003 +guest socat -u OPEN:test_small.bin TCP6:[__GW6__%__IFNAME__]:10003 hostw hout HOST_MD5_SMALL md5sum __TEMP_SMALL__ | cut -d' ' -f1 check [ "__GUEST_MD5_SMALL__" = "__HOST_MD5_SMALL__" ] diff --git a/test/tcp/passt_in_ns b/test/tcp/passt_in_ns index 2a11e0b..ab22485 100644 --- a/test/tcp/passt_in_ns +++ b/test/tcp/passt_in_ns @@ -11,15 +11,15 @@ # Copyright (c) 2021 Red Hat GmbH # Author: Stefano Brivio <sbrivio(a)redhat.com> -gtools nc ip jq cat md5sum cut -htools dd nc ip jq cat md5sum cut -nstools nc ip jq cat md5sum cut +gtools socat ip jq md5sum cut +htools dd socat ip jq md5sum cut +nstools socat ip jq md5sum cut test TCP/IPv4: host to guest: big transfer temp TEMP_BIG -guestb nc -4 -l 10001 > test_big.bin -host dd if=/dev/urandom bs=1M count=10 > __TEMP_BIG__ -host cat __TEMP_BIG__ | nc -N 127.0.0.1 10001 +guestb socat -u TCP4-LISTEN:10001 OPEN:test_big.bin,create,trunc +host dd if=/dev/urandom bs=1M count=10 of=__TEMP_BIG__ +host socat -u OPEN:__TEMP_BIG__ TCP4:127.0.0.1:10001 guestw hout MD5_BIG md5sum __TEMP_BIG__ | cut -d' ' -f1 gout GUEST_MD5_BIG md5sum test_big.bin | cut -d' ' -f1 @@ -27,63 +27,63 @@ check [ "__GUEST_MD5_BIG__" = "__MD5_BIG__" ] test TCP/IPv4: host to ns: big transfer temp TEMP_NS_BIG -nsb nc -4 -l 10002 > __TEMP_NS_BIG__ -host cat __TEMP_BIG__ | nc -N 127.0.0.1 10002 +nsb socat -u TCP4-LISTEN:10002 OPEN:__TEMP_NS_BIG__,create,trunc +host socat -u OPEN:__TEMP_BIG__ TCP4:127.0.0.1:10002 nsw nsout NS_MD5_BIG md5sum __TEMP_NS_BIG__ | cut -d' ' -f1 check [ "__NS_MD5_BIG__" = "__MD5_BIG__" ] test TCP/IPv4: guest to host: big transfer -hostb nc -4 -l 10003 > __TEMP_BIG__ +hostb socat -u TCP4-LISTEN:10003 OPEN:__TEMP_BIG__,create,trunc gout GW ip -j -4 route show|jq -rM '.[] | select(.dst == "default").gateway' -guest cat test_big.bin | nc -N __GW__ 10003 +guest socat -u OPEN:test_big.bin TCP4:__GW__:10003 hostw hout HOST_MD5_BIG md5sum __TEMP_BIG__ | cut -d' ' -f1 check [ "__HOST_MD5_BIG__" = "__MD5_BIG__" ] test TCP/IPv4: guest to ns: big transfer -nsb nc -4 -l 10002 > __TEMP_BIG__ -guest cat test_big.bin | nc -N __GW__ 10002 +nsb socat -u TCP4-LISTEN:10002 OPEN:__TEMP_BIG__,create,trunc +guest socat -u OPEN:test_big.bin TCP4:__GW__:10002 hostw hout HOST_MD5_BIG md5sum __TEMP_BIG__ | cut -d' ' -f1 check [ "__HOST_MD5_BIG__" = "__MD5_BIG__" ] test TCP/IPv4: ns to host (spliced): big transfer sleep 1 -hostb nc -4 -l 10003 > __TEMP_BIG__ -ns cat __TEMP_NS_BIG__ | nc -N 127.0.0.1 10003 +hostb socat -u TCP4-LISTEN:10003 OPEN:__TEMP_BIG__,create,trunc +ns socat -u OPEN:__TEMP_NS_BIG__ TCP4:127.0.0.1:10003 hostw hout HOST_MD5_BIG md5sum __TEMP_BIG__ | cut -d' ' -f1 check [ "__HOST_MD5_BIG__" = "__MD5_BIG__" ] test TCP/IPv4: ns to host (via tap): big transfer -hostb nc -4 -l 10003 > __TEMP_BIG__ -ns cat __TEMP_NS_BIG__ | nc -N __GW__ 10003 +hostb socat -u TCP4-LISTEN:10003 OPEN:__TEMP_BIG__,create,trunc +ns socat -u OPEN:__TEMP_NS_BIG__ TCP4:__GW__:10003 hostw hout HOST_MD5_BIG md5sum __TEMP_BIG__ | cut -d' ' -f1 check [ "__HOST_MD5_BIG__" = "__MD5_BIG__" ] test TCP/IPv4: ns to guest (using loopback address): big transfer -guestb nc -4 -l 10001 > test_big.bin -ns cat __TEMP_NS_BIG__ | nc -N 127.0.0.1 10001 +guestb socat -u TCP4-LISTEN:10001 OPEN:test_big.bin,create,trunc +ns socat -u OPEN:__TEMP_NS_BIG__ TCP4:127.0.0.1:10001 guestw gout GUEST_MD5_BIG md5sum test_big.bin | cut -d' ' -f1 check [ "__GUEST_MD5_BIG__" = "__MD5_BIG__" ] test TCP/IPv4: ns to guest (using namespace address): big transfer -guestb nc -4 -l 10001 > test_big.bin +guestb socat -u TCP4-LISTEN:10001 OPEN:test_big.bin,create,trunc nsout IFNAME ip -j link show | jq -rM '.[] | select(.link_type == "ether").ifname' nsout ADDR ip -j -4 addr show|jq -rM '.[] | select(.ifname == "__IFNAME__").addr_info[0].local' -ns cat __TEMP_NS_BIG__ | nc -N __ADDR__ 10001 +ns socat -u OPEN:__TEMP_NS_BIG__ TCP4:__ADDR__:10001 guestw gout GUEST_MD5_BIG md5sum test_big.bin | cut -d' ' -f1 check [ "__GUEST_MD5_BIG__" = "__MD5_BIG__" ] test TCP/IPv4: host to guest: small transfer temp TEMP_SMALL -guestb nc -4 -l 10001 > test_small.bin -host dd if=/dev/urandom bs=2k count=100 > __TEMP_SMALL__ -host cat __TEMP_SMALL__ | nc -N 127.0.0.1 10001 +guestb socat -u TCP4-LISTEN:10001 OPEN:test_small.bin,create,trunc +host dd if=/dev/urandom bs=2k count=100 of=__TEMP_SMALL__ +host socat -u OPEN:__TEMP_SMALL__ TCP4:127.0.0.1:10001 guestw hout MD5_SMALL md5sum __TEMP_SMALL__ | cut -d' ' -f1 gout GUEST_MD5_SMALL md5sum test_small.bin | cut -d' ' -f1 @@ -91,171 +91,171 @@ check [ "__GUEST_MD5_SMALL__" = "__MD5_SMALL__" ] test TCP/IPv4: host to ns: small transfer temp TEMP_NS_SMALL -nsb nc -4 -l 10002 > __TEMP_NS_SMALL__ -host cat __TEMP_SMALL__ | nc -N 127.0.0.1 10002 +nsb socat -u TCP4-LISTEN:10002 OPEN:__TEMP_NS_SMALL__,create,trunc +host socat -u OPEN:__TEMP_SMALL__ TCP4:127.0.0.1:10002 nsw nsout NS_MD5_SMALL md5sum __TEMP_NS_SMALL__ | cut -d' ' -f1 check [ "__NS_MD5_SMALL__" = "__MD5_SMALL__" ] test TCP/IPv4: guest to host: small transfer -hostb nc -4 -l 10003 > __TEMP_SMALL__ +hostb socat -u TCP4-LISTEN:10003 OPEN:__TEMP_SMALL__,create,trunc gout GW ip -j -4 route show|jq -rM '.[] | select(.dst == "default").gateway' -guest cat test_small.bin | nc -N __GW__ 10003 +guest socat -u OPEN:test_small.bin TCP4:__GW__:10003 hostw hout HOST_MD5_SMALL md5sum __TEMP_SMALL__ | cut -d' ' -f1 check [ "__HOST_MD5_SMALL__" = "__MD5_SMALL__" ] test TCP/IPv4: guest to ns: small transfer -nsb nc -4 -l 10002 > __TEMP_SMALL__ -guest cat test_small.bin | nc -N __GW__ 10002 +nsb socat -u TCP4-LISTEN:10002 OPEN:__TEMP_SMALL__,create,trunc +guest socat -u OPEN:test_small.bin TCP4:__GW__:10002 hostw hout HOST_MD5_SMALL md5sum __TEMP_SMALL__ | cut -d' ' -f1 check [ "__HOST_MD5_SMALL__" = "__MD5_SMALL__" ] test TCP/IPv4: ns to host (spliced): small transfer sleep 1 -hostb nc -4 -l 10003 > __TEMP_SMALL__ -ns cat __TEMP_NS_SMALL__ | nc -N 127.0.0.1 10003 +hostb socat -u TCP4-LISTEN:10003 OPEN:__TEMP_SMALL__,create,trunc +ns socat -u OPEN:__TEMP_NS_SMALL__ TCP4:127.0.0.1:10003 hostw hout HOST_MD5_SMALL md5sum __TEMP_SMALL__ | cut -d' ' -f1 check [ "__HOST_MD5_SMALL__" = "__MD5_SMALL__" ] test TCP/IPv4: ns to host (via tap): small transfer -hostb nc -4 -l 10003 > __TEMP_SMALL__ -ns cat __TEMP_NS_SMALL__ | nc -N __GW__ 10003 +hostb socat -u TCP4-LISTEN:10003 OPEN:__TEMP_SMALL__,create,trunc +ns socat -u OPEN:__TEMP_NS_SMALL__ TCP4:__GW__:10003 hostw hout HOST_MD5_SMALL md5sum __TEMP_SMALL__ | cut -d' ' -f1 check [ "__HOST_MD5_SMALL__" = "__MD5_SMALL__" ] test TCP/IPv4: ns to guest (using loopback address): small transfer -guestb nc -4 -l 10001 > test_small.bin -ns cat __TEMP_NS_SMALL__ | nc -N 127.0.0.1 10001 +guestb socat -u TCP4-LISTEN:10001 OPEN:test_small.bin,create,trunc +ns socat -u OPEN:__TEMP_NS_SMALL__ TCP4:127.0.0.1:10001 guestw gout GUEST_MD5_SMALL md5sum test_small.bin | cut -d' ' -f1 check [ "__GUEST_MD5_SMALL__" = "__MD5_SMALL__" ] test TCP/IPv4: ns to guest (using namespace address): small transfer -guestb nc -4 -l 10001 > test_small.bin -ns cat __TEMP_NS_SMALL__ | nc -N __ADDR__ 10001 +guestb socat -u TCP4-LISTEN:10001 OPEN:test_small.bin,create,trunc +ns socat -u OPEN:__TEMP_NS_SMALL__ TCP4:__ADDR__:10001 guestw gout GUEST_MD5_SMALL md5sum test_small.bin | cut -d' ' -f1 check [ "__GUEST_MD5_SMALL__" = "__MD5_SMALL__" ] test TCP/IPv6: host to guest: big transfer -guestb nc -6 -l 10001 > test_big.bin -host cat __TEMP_BIG__ | nc -N ::1 10001 +guestb socat -u TCP6-LISTEN:10001 OPEN:test_big.bin,create,trunc +host socat -u OPEN:__TEMP_BIG__ TCP6:[::1]:10001 guestw gout GUEST_MD5_BIG md5sum test_big.bin | cut -d' ' -f1 check [ "__GUEST_MD5_BIG__" = "__MD5_BIG__" ] test TCP/IPv6: host to ns: big transfer -nsb nc -6 -l 10002 > __TEMP_NS_BIG__ -host cat __TEMP_BIG__ | nc -N ::1 10002 +nsb socat -u TCP6-LISTEN:10002 OPEN:__TEMP_NS_BIG__,create,trunc +host socat -u OPEN:__TEMP_BIG__ TCP6:[::1]:10002 nsw nsout NS_MD5_BIG md5sum __TEMP_NS_BIG__ | cut -d' ' -f1 check [ "__NS_MD5_BIG__" = "__MD5_BIG__" ] test TCP/IPv6: guest to host: big transfer -hostb nc -6 -l 10003 > __TEMP_BIG__ +hostb socat -u TCP6-LISTEN:10003 OPEN:__TEMP_BIG__,create,trunc gout GW6 ip -j -6 route show|jq -rM '.[] | select(.dst == "default").gateway' gout IFNAME ip -j link show | jq -rM '.[] | select(.link_type == "ether").ifname' -guest cat test_big.bin | nc -N __GW6__%__IFNAME__ 10003 +guest socat -u OPEN:test_big.bin TCP6:[__GW6__%__IFNAME__]:10003 hostw hout HOST_MD5_BIG md5sum __TEMP_BIG__ | cut -d' ' -f1 check [ "__HOST_MD5_BIG__" = "__MD5_BIG__" ] test TCP/IPv6: guest to ns: big transfer -nsb nc -6 -l 10002 > __TEMP_BIG__ -guest cat test_big.bin | nc -N __GW6__%__IFNAME__ 10002 +nsb socat -u TCP6-LISTEN:10002 OPEN:__TEMP_BIG__,create,trunc +guest socat -u OPEN:test_big.bin TCP6:[__GW6__%__IFNAME__]:10002 hostw hout HOST_MD5_BIG md5sum __TEMP_BIG__ | cut -d' ' -f1 check [ "__HOST_MD5_BIG__" = "__MD5_BIG__" ] test TCP/IPv6: ns to host (spliced): big transfer -hostb nc -6 -l 10003 > __TEMP_BIG__ -ns cat __TEMP_NS_BIG__ | nc -N ::1 10003 +hostb socat -u TCP6-LISTEN:10003 OPEN:__TEMP_BIG__,create,trunc +ns socat -u OPEN:__TEMP_NS_BIG__ TCP6:[::1]:10003 hostw hout HOST_MD5_BIG md5sum __TEMP_BIG__ | cut -d' ' -f1 check [ "__HOST_MD5_BIG__" = "__MD5_BIG__" ] test TCP/IPv6: ns to host (via tap): big transfer -hostb nc -6 -l 10003 > __TEMP_BIG__ +hostb socat -u TCP6-LISTEN:10003 OPEN:__TEMP_BIG__,create,trunc nsout IFNAME ip -j link show | jq -rM '.[] | select(.link_type == "ether").ifname' -ns cat __TEMP_NS_BIG__ | nc -N __GW6__%__IFNAME__ 10003 +ns socat -u OPEN:__TEMP_NS_BIG__ TCP6:[__GW6__%__IFNAME__]:10003 hostw hout HOST_MD5_BIG md5sum __TEMP_BIG__ | cut -d' ' -f1 check [ "__HOST_MD5_BIG__" = "__MD5_BIG__" ] test TCP/IPv6: ns to guest (using loopback address): big transfer -guestb nc -6 -l 10001 > test_big.bin -ns cat __TEMP_NS_BIG__ | nc -N ::1 10001 +guestb socat -u TCP6-LISTEN:10001 OPEN:test_big.bin,create,trunc +ns socat -u OPEN:__TEMP_NS_BIG__ TCP6:[::1]:10001 guestw gout GUEST_MD5_BIG md5sum test_big.bin | cut -d' ' -f1 check [ "__GUEST_MD5_BIG__" = "__MD5_BIG__" ] test TCP/IPv6: ns to guest (using namespace address): big transfer -guestb nc -6 -l 10001 > test_big.bin +guestb socat -u TCP6-LISTEN:10001 OPEN:test_big.bin,create,trunc nsout ADDR6 ip -j -6 addr show|jq -rM '.[] | select(.ifname == "__IFNAME__").addr_info[0].local' -ns cat __TEMP_NS_BIG__ | nc -N __ADDR6__ 10001 +ns socat -u OPEN:__TEMP_NS_BIG__ TCP6:[__ADDR6__]:10001 guestw gout GUEST_MD5_BIG md5sum test_big.bin | cut -d' ' -f1 check [ "__GUEST_MD5_BIG__" = "__MD5_BIG__" ] test TCP/IPv6: host to guest: small transfer -guestb nc -6 -l 10001 > test_small.bin -host cat __TEMP_SMALL__ | nc -N ::1 10001 +guestb socat -u TCP6-LISTEN:10001 OPEN:test_small.bin,create,trunc +host socat -u OPEN:__TEMP_SMALL__ TCP6:[::1]:10001 guestw gout GUEST_MD5_SMALL md5sum test_small.bin | cut -d' ' -f1 check [ "__GUEST_MD5_SMALL__" = "__MD5_SMALL__" ] test TCP/IPv6: host to ns: small transfer -nsb nc -6 -l 10002 > __TEMP_NS_SMALL__ -host cat __TEMP_SMALL__ | nc -N ::1 10002 +nsb socat -u TCP6-LISTEN:10002 OPEN:__TEMP_NS_SMALL__,create,trunc +host socat -u OPEN:__TEMP_SMALL__ TCP6:[::1]:10002 nsw nsout NS_MD5_SMALL md5sum __TEMP_NS_SMALL__ | cut -d' ' -f1 check [ "__NS_MD5_SMALL__" = "__MD5_SMALL__" ] test TCP/IPv6: guest to host: small transfer -hostb nc -6 -l 10003 > __TEMP_SMALL__ +hostb socat -u TCP6-LISTEN:10003 OPEN:__TEMP_SMALL__,create,trunc gout GW6 ip -j -6 route show|jq -rM '.[] | select(.dst == "default").gateway' gout IFNAME ip -j link show | jq -rM '.[] | select(.link_type == "ether").ifname' -guest cat test_small.bin | nc -N __GW6__%__IFNAME__ 10003 +guest socat -u OPEN:test_small.bin TCP6:[__GW6__%__IFNAME__]:10003 hostw hout HOST_MD5_SMALL md5sum __TEMP_SMALL__ | cut -d' ' -f1 check [ "__HOST_MD5_SMALL__" = "__MD5_SMALL__" ] test TCP/IPv6: guest to ns: small transfer -nsb nc -6 -l 10002 > __TEMP_SMALL__ -guest cat test_small.bin | nc -N __GW6__%__IFNAME__ 10002 +nsb socat -u TCP6-LISTEN:10002 OPEN:__TEMP_SMALL__ +guest socat -u OPEN:test_small.bin TCP6:[__GW6__%__IFNAME__]:10002 hostw hout HOST_MD5_SMALL md5sum __TEMP_SMALL__ | cut -d' ' -f1 check [ "__HOST_MD5_SMALL__" = "__MD5_SMALL__" ] test TCP/IPv6: ns to host (spliced): small transfer -hostb nc -6 -l 10003 > __TEMP_SMALL__ -ns cat __TEMP_NS_SMALL__ | nc -N ::1 10003 +hostb socat -u TCP6-LISTEN:10003 OPEN:__TEMP_SMALL__,create,trunc +ns socat -u OPEN:__TEMP_NS_SMALL__ TCP6:[::1]:10003 hostw hout HOST_MD5_SMALL md5sum __TEMP_SMALL__ | cut -d' ' -f1 check [ "__HOST_MD5_SMALL__" = "__MD5_SMALL__" ] test TCP/IPv6: ns to host (via tap): small transfer -hostb nc -6 -l 10003 > __TEMP_SMALL__ +hostb socat -u TCP6-LISTEN:10003 OPEN:__TEMP_SMALL__,create,trunc nsout IFNAME ip -j link show | jq -rM '.[] | select(.link_type == "ether").ifname' -ns cat __TEMP_NS_SMALL__ | nc -N __GW6__%__IFNAME__ 10003 +ns socat -u OPEN:__TEMP_NS_SMALL__ TCP6:[__GW6__%__IFNAME__]:10003 hostw hout HOST_MD5_SMALL md5sum __TEMP_SMALL__ | cut -d' ' -f1 check [ "__HOST_MD5_SMALL__" = "__MD5_SMALL__" ] test TCP/IPv6: ns to guest (using loopback address): small transfer -guestb nc -6 -l 10001 > test_small.bin -ns cat __TEMP_NS_SMALL__ | nc -N ::1 10001 +guestb socat -u TCP6-LISTEN:10001 OPEN:test_small.bin,create,trunc +ns socat -u OPEN:__TEMP_NS_SMALL__ TCP6:[::1]:10001 guestw gout GUEST_MD5_SMALL md5sum test_small.bin | cut -d' ' -f1 check [ "__GUEST_MD5_SMALL__" = "__MD5_SMALL__" ] test TCP/IPv6: ns to guest (using namespace address): small transfer -guestb nc -6 -l 10001 > test_small.bin -ns cat __TEMP_NS_SMALL__ | nc -N __ADDR6__ 10001 +guestb socat -u TCP6-LISTEN:10001 OPEN:test_small.bin,create,trunc +ns socat -u OPEN:__TEMP_NS_SMALL__ TCP6:[__ADDR6__]:10001 guestw gout GUEST_MD5_SMALL md5sum test_small.bin | cut -d' ' -f1 check [ "__GUEST_MD5_SMALL__" = "__MD5_SMALL__" ] diff --git a/test/tcp/pasta b/test/tcp/pasta index 068393a..0d6c729 100644 --- a/test/tcp/pasta +++ b/test/tcp/pasta @@ -11,31 +11,31 @@ # Copyright (c) 2021 Red Hat GmbH # Author: Stefano Brivio <sbrivio(a)redhat.com> -htools dd ncat ip jq cat md5sum cut -nstools ncat ip jq cat md5sum cut +htools dd socat ip jq md5sum cut +nstools socat ip jq md5sum cut test TCP/IPv4: host to ns: big transfer temp TEMP_BIG temp TEMP_NS_BIG -nsb ncat -4 -l 127.0.0.1 10002 > __TEMP_NS_BIG__ -host dd if=/dev/urandom bs=1M count=10 > __TEMP_BIG__ -host cat __TEMP_BIG__ | ncat 127.0.0.1 10002 +nsb socat -u TCP4-LISTEN:10002,bind=127.0.0.1 OPEN:__TEMP_NS_BIG__,create,trunc +host dd if=/dev/urandom bs=1M count=10 of=__TEMP_BIG__ +host socat -u OPEN:__TEMP_BIG__ TCP4:127.0.0.1:10002 nsw hout MD5_BIG md5sum __TEMP_BIG__ | cut -d' ' -f1 nsout NS_MD5_BIG md5sum __TEMP_NS_BIG__ | cut -d' ' -f1 check [ "__NS_MD5_BIG__" = "__MD5_BIG__" ] test TCP/IPv4: ns to host (spliced): big transfer -hostb ncat -4 -l 127.0.0.1 10003 > __TEMP_BIG__ -ns cat __TEMP_NS_BIG__ | ncat 127.0.0.1 10003 +hostb socat -u TCP4-LISTEN:10003,bind=127.0.0.1 OPEN:__TEMP_BIG__,create,trunc +ns socat -u OPEN:__TEMP_NS_BIG__ TCP4:127.0.0.1:10003 hostw hout HOST_MD5_BIG md5sum __TEMP_BIG__ | cut -d' ' -f1 check [ "__HOST_MD5_BIG__" = "__MD5_BIG__" ] test TCP/IPv4: ns to host (via tap): big transfer -hostb ncat -4 -l 0.0.0.0 10003 > __TEMP_BIG__ +hostb socat -u TCP4-LISTEN:10003 OPEN:__TEMP_BIG__,create,trunc nsout GW ip -j -4 route show|jq -rM '.[] | select(.dst == "default").gateway' -ns cat __TEMP_NS_BIG__ | ncat __GW__ 10003 +ns socat -u OPEN:__TEMP_NS_BIG__ TCP4:__GW__:10003 hostw hout HOST_MD5_BIG md5sum __TEMP_BIG__ | cut -d' ' -f1 check [ "__HOST_MD5_BIG__" = "__MD5_BIG__" ] @@ -43,50 +43,50 @@ check [ "__HOST_MD5_BIG__" = "__MD5_BIG__" ] test TCP/IPv4: host to ns: small transfer temp TEMP_SMALL temp TEMP_NS_SMALL -nsb ncat -4 -l 127.0.0.1 10002 > __TEMP_NS_SMALL__ -host dd if=/dev/urandom bs=2k count=1 > __TEMP_SMALL__ -host cat __TEMP_SMALL__ | ncat 127.0.0.1 10002 +nsb socat -u TCP4-LISTEN:10002,bind=127.0.0.1 OPEN:__TEMP_NS_SMALL__,create,trunc +host dd if=/dev/urandom bs=2k count=1 of=__TEMP_SMALL__ +host socat OPEN:__TEMP_SMALL__ TCP4:127.0.0.1:10002 nsw hout MD5_SMALL md5sum __TEMP_SMALL__ | cut -d' ' -f1 nsout NS_MD5_SMALL md5sum __TEMP_NS_SMALL__ | cut -d' ' -f1 check [ "__NS_MD5_SMALL__" = "__MD5_SMALL__" ] test TCP/IPv4: ns to host (spliced): small transfer -hostb ncat -4 -l 127.0.0.1 10003 > __TEMP_SMALL__ -ns cat __TEMP_NS_SMALL__ | ncat 127.0.0.1 10003 +hostb socat -u TCP4-LISTEN:10003,bind=127.0.0.1 OPEN:__TEMP_SMALL__,create,trunc +ns socat OPEN:__TEMP_NS_SMALL__ TCP4:127.0.0.1:10003 hostw hout HOST_MD5_SMALL md5sum __TEMP_SMALL__ | cut -d' ' -f1 check [ "__HOST_MD5_SMALL__" = "__MD5_SMALL__" ] test TCP/IPv4: ns to host (via tap): small transfer -hostb ncat -4 -l 0.0.0.0 10003 > __TEMP_SMALL__ +hostb socat -u TCP4-LISTEN:10003 OPEN:__TEMP_SMALL__,create,trunc nsout GW ip -j -4 route show|jq -rM '.[] | select(.dst == "default").gateway' -ns cat __TEMP_NS_SMALL__ | ncat __GW__ 10003 +ns socat -u OPEN:__TEMP_NS_SMALL__ TCP4:__GW__:10003 hostw hout HOST_MD5_SMALL md5sum __TEMP_SMALL__ | cut -d' ' -f1 check [ "__HOST_MD5_SMALL__" = "__MD5_SMALL__" ] test TCP/IPv6: host to ns: big transfer -nsb ncat -6 -l ::1 10002 > __TEMP_NS_BIG__ -host cat __TEMP_BIG__ | ncat ::1 10002 +nsb socat -u TCP6-LISTEN:10002,bind=[::1] OPEN:__TEMP_NS_BIG__,create,trunc +host socat -u OPEN:__TEMP_BIG__ TCP6:[::1]:10002 nsw hout MD5_BIG md5sum __TEMP_BIG__ | cut -d' ' -f1 nsout NS_MD5_BIG md5sum __TEMP_NS_BIG__ | cut -d' ' -f1 check [ "__NS_MD5_BIG__" = "__MD5_BIG__" ] test TCP/IPv6: ns to host (spliced): big transfer -hostb ncat -6 -l ::1 10003 > __TEMP_BIG__ -ns cat __TEMP_NS_BIG__ | ncat ::1 10003 +hostb socat -u TCP6-LISTEN:10003,bind=[::1] OPEN:__TEMP_BIG__,create,trunc +ns socat -u OPEN:__TEMP_NS_BIG__ TCP6:[::1]:10003 hostw hout HOST_MD5_BIG md5sum __TEMP_BIG__ | cut -d' ' -f1 check [ "__HOST_MD5_BIG__" = "__MD5_BIG__" ] nsw test TCP/IPv6: ns to host (via tap): big transfer -hostb ncat -6 -l :: 10003 > __TEMP_BIG__ +hostb socat -u TCP6-LISTEN:10003 OPEN:__TEMP_BIG__,create,trunc nsout GW6 ip -j -6 route show|jq -rM '.[] | select(.dst == "default").gateway' nsout IFNAME ip -j link show | jq -rM '.[] | select(.link_type == "ether").ifname' -ns cat __TEMP_NS_BIG__ | ncat __GW6__%__IFNAME__ 10003 +ns socat -u OPEN:__TEMP_NS_BIG__ TCP6:[__GW6__%__IFNAME__]:10003 hostw hout HOST_MD5_BIG md5sum __TEMP_BIG__ | cut -d' ' -f1 check [ "__HOST_MD5_BIG__" = "__MD5_BIG__" ] @@ -94,24 +94,24 @@ check [ "__HOST_MD5_BIG__" = "__MD5_BIG__" ] test TCP/IPv6: host to ns: small transfer temp TEMP_SMALL temp TEMP_NS_SMALL -nsb ncat -6 -l ::1 10002 > __TEMP_NS_SMALL__ -host dd if=/dev/urandom bs=2k count=1 > __TEMP_SMALL__ -host cat __TEMP_SMALL__ | ncat ::1 10002 +nsb socat -u TCP6-LISTEN:10002,bind=[::1] OPEN:__TEMP_NS_SMALL__,create,trunc +host dd if=/dev/urandom bs=2k count=1 of=__TEMP_SMALL__ +host socat -u OPEN:__TEMP_SMALL__ TCP6:[::1]:10002 nsw hout MD5_SMALL md5sum __TEMP_SMALL__ | cut -d' ' -f1 nsout NS_MD5_SMALL md5sum __TEMP_NS_SMALL__ | cut -d' ' -f1 check [ "__NS_MD5_SMALL__" = "__MD5_SMALL__" ] test TCP/IPv6: ns to host (spliced): small transfer -hostb ncat -6 -l ::1 10003 > __TEMP_SMALL__ -ns cat __TEMP_NS_SMALL__ | ncat ::1 10003 +hostb socat -u TCP6-LISTEN:10003,bind=[::1] OPEN:__TEMP_SMALL__,create,trunc +ns socat -u OPEN:__TEMP_NS_SMALL__ TCP6:[::1]:10003 hostw hout HOST_MD5_SMALL md5sum __TEMP_SMALL__ | cut -d' ' -f1 check [ "__HOST_MD5_SMALL__" = "__MD5_SMALL__" ] test TCP/IPv6: ns to host (via tap): small transfer -hostb ncat -6 -l :: 10003 > __TEMP_SMALL__ -ns cat __TEMP_NS_SMALL__ | ncat __GW6__%__IFNAME__ 10003 +hostb socat -u TCP6-LISTEN:10003 OPEN:__TEMP_SMALL__,create,trunc +ns socat -u OPEN:__TEMP_NS_SMALL__ TCP6:[__GW6__%__IFNAME__]:10003 hostw hout HOST_MD5_SMALL md5sum __TEMP_SMALL__ | cut -d' ' -f1 check [ "__HOST_MD5_SMALL__" = "__MD5_SMALL__" ] diff --git a/test/two_guests/basic b/test/two_guests/basic index 850a27b..cf0b975 100644 --- a/test/two_guests/basic +++ b/test/two_guests/basic @@ -11,9 +11,9 @@ # Copyright (c) 2021 Red Hat GmbH # Author: Stefano Brivio <sbrivio(a)redhat.com> -g1tools ip jq dhclient nc cat -g2tools ip jq dhclient nc cat -htools ip jq cat md5sum cut +g1tools ip jq dhclient socat cat +g2tools ip jq dhclient socat cat +htools ip jq md5sum cut test Interface names g1out IFNAME1 ip -j link show | jq -rM '.[] | select(.link_type == "ether").ifname' @@ -46,8 +46,8 @@ check [ "__ADDR2_6__" = "__HOST_ADDR6__" ] test TCP/IPv4: guest 1 > guest 2 g1out GW1 ip -j -4 route show|jq -rM '.[] | select(.dst == "default").gateway' -guest2b nc -4 -l 10004 > msg -guest1 echo "Hello_from_guest_1" | nc -N __GW1__ 10004 +guest2b socat -u TCP4-LISTEN:10004 OPEN:msg,create,trunc +guest1 echo "Hello_from_guest_1" | socat -u STDIN TCP4:__GW1__:10004 guest2w sleep 1 g2out MSG2 cat msg @@ -55,24 +55,24 @@ check [ "__MSG2__" = "Hello_from_guest_1" ] test TCP/IPv6: guest 2 > guest 1 g2out GW2_6 ip -j -6 route show|jq -rM '.[] | select(.dst == "default").gateway' -guest1b nc -6 -l 10001 > msg -guest2 echo "Hello_from_guest_2" | nc -N __GW2_6__%__IFNAME2__ 10001 +guest1b socat -u TCP6-LISTEN:10001 OPEN:msg,create,trunc +guest2 echo "Hello_from_guest_2" | socat -u STDIN TCP6:[__GW2_6__%__IFNAME2__]:10001 guest1w sleep 1 g1out MSG1 cat msg check [ "__MSG1__" = "Hello_from_guest_2" ] test UDP/IPv4: guest 1 > guest 2 -guest2b nc -u -W1 -4 -l 10004 > msg -guest1 echo "Hello_from_guest_1" | nc -u -q1 __GW1__ 10004 +guest2b socat -u TCP4-LISTEN:10004 OPEN:msg,create,trunc +guest1 echo "Hello_from_guest_1" | socat -u STDIN TCP4:__GW1__:10004 guest2w sleep 1 g2out MSG2 cat msg check [ "__MSG2__" = "Hello_from_guest_1" ] test UDP/IPv6: guest 2 > guest 1 -guest1b nc -u -W1 -6 -l 10001 > msg -guest2 echo "Hello_from_guest_2" | nc -u -q1 -N __GW2_6__%__IFNAME2__ 10001 +guest1b socat -u TCP6-LISTEN:10001 OPEN:msg,create,trunc +guest2 echo "Hello_from_guest_2" | socat -u STDIN TCP6:[__GW2_6__%__IFNAME2__]:10001 guest1w sleep 1 g1out MSG1 cat msg diff --git a/test/udp/passt b/test/udp/passt index 9598d0e..ee575e0 100644 --- a/test/udp/passt +++ b/test/udp/passt @@ -11,15 +11,15 @@ # Copyright (c) 2021 Red Hat GmbH # Author: Stefano Brivio <sbrivio(a)redhat.com> -gtools nc tee grep cat ip jq md5sum cut -htools printf dd nc tee grep cat ip jq md5sum cut +gtools socat tee grep cat ip jq md5sum cut +htools printf dd socat tee grep cat ip jq md5sum cut test UDP/IPv4: host to guest temp TEMP -temp NC_PID -guestb (nc -u -q1 -4 -l 10001 & echo $! > __NC_PID__) | tee test.bin | (grep -qm1 "END_OF_TEST" && kill $(cat __NC_PID__)) +temp SC_PID +guestb (socat -u UDP4-LISTEN:10001 STDOUT & echo $! > __SC_PID__) | tee test.bin | (grep -qm1 "END_OF_TEST" && kill $(cat __SC_PID__)) host dd if=/dev/urandom bs=1k count=5 > __TEMP__ && printf "\nEND_OF_TEST\n" >> __TEMP__ -host cat __TEMP__ | nc -u -q1 -N 127.0.0.1 10001 +host socat -u OPEN:__TEMP__ UDP4:127.0.0.1:10001 guestw hout HOST_MD5 md5sum __TEMP__ | cut -d' ' -f1 gout GUEST_MD5 md5sum test.bin | cut -d' ' -f1 @@ -27,27 +27,27 @@ check [ "__GUEST_MD5__" = "__HOST_MD5__" ] test UDP/IPv4: guest to host host :> __TEMP__ -hostb (nc -u -q1 -4 -l 10003 & echo $! > __NC_PID__) | tee __TEMP__ | (grep -qm1 "END_OF_TEST" && kill $(cat __NC_PID__)) +hostb (socat -u UDP4-LISTEN:10003,bind=127.0.0.1 STDOUT & echo $! > __SC_PID__) | tee __TEMP__ | (grep -qm1 "END_OF_TEST" && kill $(cat __SC_PID__)) gout GW ip -j -4 route show|jq -rM '.[] | select(.dst == "default").gateway' -guest cat test.bin | nc -u -q1 -N __GW__ 10003 +guest socat -u OPEN:test.bin UDP4:__GW__:10003 hostw hout HOST_MD5 md5sum __TEMP__ | cut -d' ' -f1 check [ "__GUEST_MD5__" = "__HOST_MD5__" ] test UDP/IPv6: host to guest -guestb (nc -u -q1 -6 -l 10001 & echo $! > nc.pid) | tee test.bin | (grep -qm1 "END_OF_TEST" && kill $(cat nc.pid)) +guestb (socat -u UDP6-LISTEN:10001 STDOUT & echo $! > sc.pid) | tee test.bin | (grep -qm1 "END_OF_TEST" && kill $(cat sc.pid)) sleep 1 -host cat __TEMP__ | nc -u -q1 -N ::1 10001 +host socat -u OPEN:__TEMP__ UDP6:[::1]:10001 guestw gout GUEST_MD5 md5sum test.bin | cut -d' ' -f1 check [ "__GUEST_MD5__" = "__HOST_MD5__" ] test UDP/IPv6: guest to host host :> __TEMP__ -hostb (nc -u -q1 -6 -l 10003 & echo $! > __NC_PID__) | tee __TEMP__ | (grep -qm1 "END_OF_TEST" && kill $(cat __NC_PID__)) +hostb (socat -u UDP6-LISTEN:10003,bind=[::1] STDOUT & echo $! > __SC_PID__) | tee __TEMP__ | (grep -qm1 "END_OF_TEST" && kill $(cat __SC_PID__)) gout GW6 ip -j -6 route show|jq -rM '.[] | select(.dst == "default").gateway' gout IFNAME ip -j link show | jq -rM '.[] | select(.link_type == "ether").ifname' -guest cat test.bin | nc -u -q1 -N __GW6__%__IFNAME__ 10003 +guest socat -u OPEN:test.bin UDP6:[__GW6__%__IFNAME__]:10003 hostw hout HOST_MD5 md5sum __TEMP__ | cut -d' ' -f1 check [ "__GUEST_MD5__" = "__HOST_MD5__" ] diff --git a/test/udp/passt_in_ns b/test/udp/passt_in_ns index 3607251..3536298 100644 --- a/test/udp/passt_in_ns +++ b/test/udp/passt_in_ns @@ -11,16 +11,16 @@ # Copyright (c) 2021 Red Hat GmbH # Author: Stefano Brivio <sbrivio(a)redhat.com> -gtools nc tee grep cat ip jq md5sum cut -nstools nc tee grep cat ip jq md5sum cut -htools printf dd nc tee grep cat ip jq md5sum cut +gtools socat tee grep cat ip jq md5sum cut +nstools socat tee grep cat ip jq md5sum cut +htools printf dd socat tee grep cat ip jq md5sum cut test UDP/IPv4: host to guest temp TEMP -temp NC_PID -guestb (nc -u -q1 -4 -l 10001 & echo $! > nc.pic) | tee test.bin | (grep -qm1 "END_OF_TEST" && kill $(cat nc.pic)) +temp SC_PID +guestb (socat -u UDP4-LISTEN:10001 STDOUT & echo $! > sc.pid) | tee test.bin | (grep -qm1 "END_OF_TEST" && kill $(cat sc.pid)) host dd if=/dev/urandom bs=1k count=5 > __TEMP__ && printf "\nEND_OF_TEST\n" >> __TEMP__ -host cat __TEMP__ | nc -u -q1 -N 127.0.0.1 10001 +host socat -u OPEN:__TEMP__ UDP4:127.0.0.1:10001 guestw hout MD5 md5sum __TEMP__ | cut -d' ' -f1 gout GUEST_MD5 md5sum test.bin | cut -d' ' -f1 @@ -29,25 +29,25 @@ check [ "__GUEST_MD5__" = "__MD5__" ] test UDP/IPv4: host to ns temp TEMP_NS ns :> __TEMP_NS__ -nsb (nc -u -q1 -4 -l 10002 & echo $! > __NC_PID__) | tee __TEMP_NS__ | (grep -qm1 "END_OF_TEST" && kill $(cat __NC_PID__)) -host cat __TEMP__ | nc -u -q1 -N 127.0.0.1 10002 +nsb (socat -u UDP4-LISTEN:10002 STDOUT & echo $! > __SC_PID__) | tee __TEMP_NS__ | (grep -qm1 "END_OF_TEST" && kill $(cat __SC_PID__)) +host socat -u OPEN:__TEMP__ UDP4:127.0.0.1:10002 nsw nsout NS_MD5 md5sum __TEMP_NS__ | cut -d' ' -f1 check [ "__NS_MD5__" = "__MD5__" ] test UDP/IPv4: guest to host host :> __TEMP__ -hostb (nc -u -q1 -4 -l 10003 & echo $! > __NC_PID__) | tee __TEMP__ | (grep -qm1 "END_OF_TEST" && kill $(cat __NC_PID__)) +hostb (socat -u UDP4-LISTEN:10003 STDOUT & echo $! > __SC_PID__) | tee __TEMP__ | (grep -qm1 "END_OF_TEST" && kill $(cat __SC_PID__)) gout GW ip -j -4 route show|jq -rM '.[] | select(.dst == "default").gateway' -guest cat test.bin | nc -u -q1 -N __GW__ 10003 +guest socat -u OPEN:test.bin UDP4:__GW__:10003 hostw hout HOST_MD5 md5sum __TEMP__ | cut -d' ' -f1 check [ "__HOST_MD5__" = "__MD5__" ] test UDP/IPv4: guest to ns ns :> __TEMP_NS__ -nsb (nc -u -q1 -4 -l 10002 & echo $! > __NC_PID__) | tee __TEMP_NS__ | (grep -qm1 "END_OF_TEST" && kill $(cat __NC_PID__)) -guest cat test.bin | nc -u -q1 -N __GW__ 10002 +nsb (socat -u UDP4-LISTEN:10002 STDOUT & echo $! > __SC_PID__) | tee __TEMP_NS__ | (grep -qm1 "END_OF_TEST" && kill $(cat __SC_PID__)) +guest socat -u OPEN:test.bin UDP4:__GW__:10002 hostw hout HOST_MD5 md5sum __TEMP__ | cut -d' ' -f1 check [ "__HOST_MD5__" = "__MD5__" ] @@ -55,97 +55,97 @@ check [ "__HOST_MD5__" = "__MD5__" ] test UDP/IPv4: ns to host (recvmmsg/sendmmsg) sleep 1 host :> __TEMP__ -hostb (nc -u -q1 -4 -l 10003 & echo $! > __NC_PID__) | tee __TEMP__ | (grep -qm1 "END_OF_TEST" && kill $(cat __NC_PID__)) -ns cat __TEMP_NS__ | nc -u -q1 -N 127.0.0.1 10003 +hostb (socat -u UDP4-LISTEN:10003 STDOUT & echo $! > __SC_PID__) | tee __TEMP__ | (grep -qm1 "END_OF_TEST" && kill $(cat __SC_PID__)) +ns socat -u OPEN:__TEMP_NS__ UDP4:127.0.0.1:10003 hostw hout HOST_MD5 md5sum __TEMP__ | cut -d' ' -f1 check [ "__HOST_MD5__" = "__MD5__" ] test UDP/IPv4: ns to host (via tap) host :> __TEMP__ -hostb (nc -u -q1 -4 -l 10003 & echo $! > __NC_PID__) | tee __TEMP__ | (grep -qm1 "END_OF_TEST" && kill $(cat __NC_PID__)) -ns cat __TEMP_NS__ | nc -u -q1 -N __GW__ 10003 +hostb (socat -u UDP4-LISTEN:10003 STDOUT & echo $! > __SC_PID__) | tee __TEMP__ | (grep -qm1 "END_OF_TEST" && kill $(cat __SC_PID__)) +ns socat -u OPEN:__TEMP_NS__ UDP4:__GW__:10003 hostw hout HOST_MD5 md5sum __TEMP__ | cut -d' ' -f1 check [ "__HOST_MD5__" = "__MD5__" ] test UDP/IPv4: ns to guest (using loopback address) -guestb (nc -u -q1 -4 -l 10001 & echo $! > nc.pid) | tee test.bin | (grep -qm1 "END_OF_TEST" && kill $(cat nc.pid)) -ns cat __TEMP_NS__ | nc -u -q1 -N 127.0.0.1 10001 +guestb (socat -u UDP4-LISTEN:10001 STDOUT & echo $! > sc.pid) | tee test.bin | (grep -qm1 "END_OF_TEST" && kill $(cat sc.pid)) +ns socat -u OPEN:__TEMP_NS__ UDP4:127.0.0.1:10001 guestw gout GUEST_MD5 md5sum test.bin | cut -d' ' -f1 check [ "__GUEST_MD5__" = "__MD5__" ] test UDP/IPv4: ns to guest (using namespace address) -guestb (nc -u -q1 -4 -l 10001 & echo $! > nc.pid) | tee test.bin | (grep -qm1 "END_OF_TEST" && kill $(cat nc.pid)) +guestb (socat -u UDP4-LISTEN:10001 STDOUT & echo $! > sc.pid) | tee test.bin | (grep -qm1 "END_OF_TEST" && kill $(cat sc.pid)) nsout IFNAME ip -j link show | jq -rM '.[] | select(.link_type == "ether").ifname' nsout ADDR ip -j -4 addr show|jq -rM '.[] | select(.ifname == "__IFNAME__").addr_info[0].local' -ns cat __TEMP_NS__ | nc -u -q1 -N __ADDR__ 10001 +ns socat -u OPEN:__TEMP_NS__ UDP4:__ADDR__:10001 guestw gout GUEST_MD5 md5sum test.bin | cut -d' ' -f1 check [ "__GUEST_MD5__" = "__MD5__" ] test UDP/IPv6: host to guest -guestb (nc -u -q1 -6 -l 10001 & echo $! > nc.pid) | tee test.bin | (grep -qm1 "END_OF_TEST" && kill $(cat nc.pid)) -host cat __TEMP__ | nc -u -q1 -N ::1 10001 +guestb (socat -u UDP6-LISTEN:10001 STDOUT & echo $! > sc.pid) | tee test.bin | (grep -qm1 "END_OF_TEST" && kill $(cat sc.pid)) +host socat -u OPEN:__TEMP__ UDP6:[::1]:10001 guestw gout GUEST_MD5 md5sum test.bin | cut -d' ' -f1 check [ "__GUEST_MD5__" = "__MD5__" ] test UDP/IPv6: host to ns ns :> __TEMP_NS__ -nsb (nc -u -q1 -6 -l 10002 & echo $! > __NC_PID__) | tee __TEMP_NS__ | (grep -qm1 "END_OF_TEST" && kill $(cat __NC_PID__)) -host cat __TEMP__ | nc -u -q1 -N ::1 10002 +nsb (socat -u UDP6-LISTEN:10002 STDOUT & echo $! > __SC_PID__) | tee __TEMP_NS__ | (grep -qm1 "END_OF_TEST" && kill $(cat __SC_PID__)) +host socat -u OPEN:__TEMP__ UDP6:[::1]:10002 nsw nsout NS_MD5 md5sum __TEMP_NS__ | cut -d' ' -f1 check [ "__NS_MD5__" = "__MD5__" ] test UDP/IPv6: guest to host host :> __TEMP__ -hostb (nc -u -q1 -6 -l 10003 & echo $! > __NC_PID__) | tee __TEMP__ | (grep -qm1 "END_OF_TEST" && kill $(cat __NC_PID__)) +hostb (socat -u UDP6-LISTEN:10003 STDOUT & echo $! > __SC_PID__) | tee __TEMP__ | (grep -qm1 "END_OF_TEST" && kill $(cat __SC_PID__)) gout GW6 ip -j -6 route show|jq -rM '.[] | select(.dst == "default").gateway' gout IFNAME ip -j link show | jq -rM '.[] | select(.link_type == "ether").ifname' -guest cat test.bin | nc -u -q1 -N __GW6__%__IFNAME__ 10003 +guest socat -u OPEN:test.bin UDP6:[__GW6__%__IFNAME__]:10003 hostw hout HOST_MD5 md5sum __TEMP__ | cut -d' ' -f1 check [ "__HOST_MD5__" = "__MD5__" ] test UDP/IPv6: guest to ns ns :> __TEMP_NS__ -nsb (nc -u -q1 -6 -l 10002 & echo $! > __NC_PID__) | tee __TEMP_NS__ | (grep -qm1 "END_OF_TEST" && kill $(cat __NC_PID__)) -guest cat test.bin | nc -u -q1 -N __GW6__%__IFNAME__ 10002 +nsb (socat -u UDP6-LISTEN:10002 STDOUT & echo $! > __SC_PID__) | tee __TEMP_NS__ | (grep -qm1 "END_OF_TEST" && kill $(cat __SC_PID__)) +guest socat -u OPEN:test.bin UDP6:[__GW6__%__IFNAME__]:10002 hostw hout HOST_MD5 md5sum __TEMP__ | cut -d' ' -f1 check [ "__HOST_MD5__" = "__MD5__" ] test UDP/IPv6: ns to host (recvmmsg/sendmmsg) host :> __TEMP__ -hostb (nc -u -q1 -6 -l 10003 & echo $! > __NC_PID__) | tee __TEMP__ | (grep -qm1 "END_OF_TEST" && kill $(cat __NC_PID__)) -ns cat __TEMP_NS__ | nc -u -q1 -N ::1 10003 +hostb (socat -u UDP6-LISTEN:10003 STDOUT & echo $! > __SC_PID__) | tee __TEMP__ | (grep -qm1 "END_OF_TEST" && kill $(cat __SC_PID__)) +ns socat -u OPEN:__TEMP_NS__ UDP6:[::1]:10003 hostw hout HOST_MD5 md5sum __TEMP__ | cut -d' ' -f1 check [ "__HOST_MD5__" = "__MD5__" ] test UDP/IPv6: ns to host (via tap) host :> __TEMP__ -hostb (nc -u -q1 -6 -l 10003 & echo $! > __NC_PID__) | tee __TEMP__ | (grep -qm1 "END_OF_TEST" && kill $(cat __NC_PID__)) +hostb (socat -u UDP6-LISTEN:10003 STDOUT & echo $! > __SC_PID__) | tee __TEMP__ | (grep -qm1 "END_OF_TEST" && kill $(cat __SC_PID__)) nsout IFNAME ip -j link show | jq -rM '.[] | select(.link_type == "ether").ifname' -ns cat __TEMP_NS__ | nc -u -q1 -N __GW6__%__IFNAME__ 10003 +ns socat -u OPEN:__TEMP_NS__ UDP6:[__GW6__%__IFNAME__]:10003 hostw hout HOST_MD5 md5sum __TEMP__ | cut -d' ' -f1 check [ "__HOST_MD5__" = "__MD5__" ] test UDP/IPv6: ns to guest (using loopback address) -guestb (nc -u -q1 -6 -l 10001 & echo $! > nc.pid) | tee test.bin | (grep -qm1 "END_OF_TEST" && kill $(cat nc.pid)) -ns cat __TEMP_NS__ | nc -u -q1 -N ::1 10001 +guestb (socat -u UDP6-LISTEN:10001 STDOUT & echo $! > sc.pid) | tee test.bin | (grep -qm1 "END_OF_TEST" && kill $(cat sc.pid)) +ns socat -u OPEN:__TEMP_NS__ UDP6:[::1]:10001 guestw gout GUEST_MD5 md5sum test.bin | cut -d' ' -f1 check [ "__GUEST_MD5__" = "__MD5__" ] test UDP/IPv6: ns to guest (using namespace address) -guestb (nc -u -q1 -6 -l 10001 & echo $! > nc.pid) | tee test.bin | (grep -qm1 "END_OF_TEST" && kill $(cat nc.pid)) +guestb (socat -u UDP6-LISTEN:10001 STDOUT & echo $! > sc.pid) | tee test.bin | (grep -qm1 "END_OF_TEST" && kill $(cat sc.pid)) nsout ADDR6 ip -j -6 addr show|jq -rM '.[] | select(.ifname == "__IFNAME__").addr_info[0].local' -ns cat __TEMP_NS__ | nc -u -q1 -N __ADDR6__ 10001 +ns socat -u OPEN:__TEMP_NS__ UDP6:[__ADDR6__]:10001 guestw gout GUEST_MD5 md5sum test.bin | cut -d' ' -f1 check [ "__GUEST_MD5__" = "__MD5__" ] diff --git a/test/udp/pasta b/test/udp/pasta index a7e5015..43e0513 100644 --- a/test/udp/pasta +++ b/test/udp/pasta @@ -11,18 +11,18 @@ # Copyright (c) 2021 Red Hat GmbH # Author: Stefano Brivio <sbrivio(a)redhat.com> -nstools ncat tee grep cat ip jq md5sum cut -htools printf dd ncat tee grep cat ip jq md5sum cut +nstools socat tee grep cat ip jq md5sum cut +htools printf dd socat tee grep cat ip jq md5sum cut test UDP/IPv4: host to ns temp TEMP temp TEMP_NS temp NC_PID ns :> __TEMP_NS__ -nsb (ncat -u -4 -l 127.0.0.1 10002 & echo $! > __NC_PID__) | tee __TEMP_NS__ | (grep -qm1 "END_OF_TEST" && kill $(cat __NC_PID__)) +nsb (socat -u UDP4-LISTEN:10002,bind=127.0.0.1 STDOUT & echo $! > __NC_PID__) | tee __TEMP_NS__ | (grep -qm1 "END_OF_TEST" && kill $(cat __NC_PID__)) host dd if=/dev/urandom bs=1k count=5 > __TEMP__ && printf "\nEND_OF_TEST\n" >> __TEMP__ -host cat __TEMP__ | ncat -u 127.0.0.1 10002 +host socat OPEN:__TEMP__ UDP4:127.0.0.1:10002 nsw hout MD5 md5sum __TEMP__ | cut -d' ' -f1 nsout NS_MD5 md5sum __TEMP_NS__ | cut -d' ' -f1 @@ -30,26 +30,26 @@ check [ "__NS_MD5__" = "__MD5__" ] test UDP/IPv4: ns to host (recvmmsg/sendmmsg) host :> __TEMP__ -hostb (ncat -u -4 -l 127.0.0.1 10003 & echo $! > __NC_PID__) | tee __TEMP__ | (grep -qm1 "END_OF_TEST" && kill $(cat __NC_PID__)) +hostb (socat -u UDP4-LISTEN:10003,bind=127.0.0.1 STDOUT & echo $! > __NC_PID__) | tee __TEMP__ | (grep -qm1 "END_OF_TEST" && kill $(cat __NC_PID__)) sleep 1 -ns cat __TEMP_NS__ | ncat -u 127.0.0.1 10003 +ns socat OPEN:__TEMP_NS__ UDP4:127.0.0.1:10003 hostw hout HOST_MD5 md5sum __TEMP__ | cut -d' ' -f1 check [ "__HOST_MD5__" = "__MD5__" ] test UDP/IPv4: ns to host (via tap) host :> __TEMP__ -hostb (ncat -u -4 -l 0.0.0.0 10003 & echo $! > __NC_PID__) | tee __TEMP__ | (grep -qm1 "END_OF_TEST" && kill $(cat __NC_PID__)) +hostb (socat -u UDP4-LISTEN:10003 STDOUT & echo $! > __NC_PID__) | tee __TEMP__ | (grep -qm1 "END_OF_TEST" && kill $(cat __NC_PID__)) nsout GW ip -j -4 route show|jq -rM '.[] | select(.dst == "default").gateway' -ns cat __TEMP_NS__ | ncat -u __GW__ 10003 +ns socat -u OPEN:__TEMP_NS__ UDP4:__GW__:10003 hostw hout HOST_MD5 md5sum __TEMP__ | cut -d' ' -f1 check [ "__HOST_MD5__" = "__MD5__" ] test UDP/IPv6: host to ns ns :> __TEMP_NS__ -nsb (ncat -u -6 -l ::1 10002 & echo $! > __NC_PID__) | tee __TEMP_NS__ | (grep -qm1 "END_OF_TEST" && kill $(cat __NC_PID__)) -host cat __TEMP__ | ncat -u ::1 10002 +nsb (socat -u UDP6-LISTEN:10002,bind=[::1] STDOUT & echo $! > __NC_PID__) | tee __TEMP_NS__ | (grep -qm1 "END_OF_TEST" && kill $(cat __NC_PID__)) +host socat -u OPEN:__TEMP__ UDP6:[::1]:10002 nsw hout MD5 md5sum __TEMP__ | cut -d' ' -f1 nsout NS_MD5 md5sum __TEMP_NS__ | cut -d' ' -f1 @@ -57,9 +57,9 @@ check [ "__NS_MD5__" = "__MD5__" ] test UDP/IPv6: ns to host (recvmmsg/sendmmsg) host :> __TEMP__ -hostb (ncat -u -6 -l ::1 10003 & echo $! > __NC_PID__) | tee __TEMP__ | (grep -qm1 "END_OF_TEST" && kill $(cat __NC_PID__)) +hostb (socat -u UDP6-LISTEN:10003,bind=[::1] STDOUT & echo $! > __NC_PID__) | tee __TEMP__ | (grep -qm1 "END_OF_TEST" && kill $(cat __NC_PID__)) sleep 1 -ns cat __TEMP_NS__ | ncat -u ::1 10003 +ns socat -u OPEN:__TEMP_NS__ UDP6:[::1]:10003 hostw hout HOST_MD5 md5sum __TEMP__ | cut -d' ' -f1 check [ "__HOST_MD5__" = "__MD5__" ] @@ -67,10 +67,10 @@ nsw test UDP/IPv6: ns to host (via tap) host :> __TEMP__ -hostb (ncat -u -6 -l :: 10003 & echo $! > __NC_PID__) | tee __TEMP__ | (grep -qm1 "END_OF_TEST" && kill $(cat __NC_PID__)) +hostb (socat -u UDP6-LISTEN:10003 STDOUT & echo $! > __NC_PID__) | tee __TEMP__ | (grep -qm1 "END_OF_TEST" && kill $(cat __NC_PID__)) nsout GW6 ip -j -6 route show|jq -rM '.[] | select(.dst == "default").gateway' nsout IFNAME ip -j link show | jq -rM '.[] | select(.link_type == "ether").ifname' -ns cat __TEMP_NS__ | ncat -u __GW6__%__IFNAME__ 10003 +ns socat -u OPEN:__TEMP_NS__ UDP6:[__GW6__%__IFNAME__]:10003 hostw hout HOST_MD5 md5sum __TEMP__ | cut -d' ' -f1 check [ "__HOST_MD5__" = "__MD5__" ] -- 2.36.1
teardown_passt_in_ns() sends a ^D to the NS pane, which appears to be intended to terminate the nsenter running there, leaving the namespace. However, we've also sent a ^D to the PASST pane which will exit the pasta instance which created the namespace. With the namespace destroyed the nsenter in the NS pane will be killed, so it does not need to be exited explicitly. In fact sending the extra ^D can be harmful, since it will exit the shell in which the nsenter was run, causing the whole pane to be closed. That can then mean that the "pane_wait NS" hangs indefinitely. I believe this will sometimes work, because there's a race between the various options here, but it should be more reliable without the extra ^D. Signed-off-by: David Gibson <david(a)gibson.dropbear.id.au> --- test/lib/setup | 2 -- 1 file changed, 2 deletions(-) diff --git a/test/lib/setup b/test/lib/setup index adbfa9e..752469c 100755 --- a/test/lib/setup +++ b/test/lib/setup @@ -306,8 +306,6 @@ teardown_passt_in_ns() { [ ${VALGRIND} -eq 0 ] && pane_status GUEST tmux send-keys -t ${PANE_PASST} "C-d" - tmux send-keys -t ${PANE_NS} "C-d" - pane_wait GUEST pane_wait NS pane_wait PASST -- 2.36.1
All the UDP tests use :> to truncate some temporary data files. This appears to be so that they're empty before writing data to them with tee. However tee, by default, truncates its output file anyway (you need tee -a to append). So drop the unnecessary truncations. Signed-off-by: David Gibson <david(a)gibson.dropbear.id.au> --- test/udp/passt | 2 -- test/udp/passt_in_ns | 10 ---------- test/udp/pasta | 6 ------ 3 files changed, 18 deletions(-) diff --git a/test/udp/passt b/test/udp/passt index ee575e0..7c58648 100644 --- a/test/udp/passt +++ b/test/udp/passt @@ -26,7 +26,6 @@ gout GUEST_MD5 md5sum test.bin | cut -d' ' -f1 check [ "__GUEST_MD5__" = "__HOST_MD5__" ] test UDP/IPv4: guest to host -host :> __TEMP__ hostb (socat -u UDP4-LISTEN:10003,bind=127.0.0.1 STDOUT & echo $! > __SC_PID__) | tee __TEMP__ | (grep -qm1 "END_OF_TEST" && kill $(cat __SC_PID__)) gout GW ip -j -4 route show|jq -rM '.[] | select(.dst == "default").gateway' guest socat -u OPEN:test.bin UDP4:__GW__:10003 @@ -43,7 +42,6 @@ gout GUEST_MD5 md5sum test.bin | cut -d' ' -f1 check [ "__GUEST_MD5__" = "__HOST_MD5__" ] test UDP/IPv6: guest to host -host :> __TEMP__ hostb (socat -u UDP6-LISTEN:10003,bind=[::1] STDOUT & echo $! > __SC_PID__) | tee __TEMP__ | (grep -qm1 "END_OF_TEST" && kill $(cat __SC_PID__)) gout GW6 ip -j -6 route show|jq -rM '.[] | select(.dst == "default").gateway' gout IFNAME ip -j link show | jq -rM '.[] | select(.link_type == "ether").ifname' diff --git a/test/udp/passt_in_ns b/test/udp/passt_in_ns index 3536298..8f8090b 100644 --- a/test/udp/passt_in_ns +++ b/test/udp/passt_in_ns @@ -28,7 +28,6 @@ check [ "__GUEST_MD5__" = "__MD5__" ] test UDP/IPv4: host to ns temp TEMP_NS -ns :> __TEMP_NS__ nsb (socat -u UDP4-LISTEN:10002 STDOUT & echo $! > __SC_PID__) | tee __TEMP_NS__ | (grep -qm1 "END_OF_TEST" && kill $(cat __SC_PID__)) host socat -u OPEN:__TEMP__ UDP4:127.0.0.1:10002 nsw @@ -36,7 +35,6 @@ nsout NS_MD5 md5sum __TEMP_NS__ | cut -d' ' -f1 check [ "__NS_MD5__" = "__MD5__" ] test UDP/IPv4: guest to host -host :> __TEMP__ hostb (socat -u UDP4-LISTEN:10003 STDOUT & echo $! > __SC_PID__) | tee __TEMP__ | (grep -qm1 "END_OF_TEST" && kill $(cat __SC_PID__)) gout GW ip -j -4 route show|jq -rM '.[] | select(.dst == "default").gateway' guest socat -u OPEN:test.bin UDP4:__GW__:10003 @@ -45,7 +43,6 @@ hout HOST_MD5 md5sum __TEMP__ | cut -d' ' -f1 check [ "__HOST_MD5__" = "__MD5__" ] test UDP/IPv4: guest to ns -ns :> __TEMP_NS__ nsb (socat -u UDP4-LISTEN:10002 STDOUT & echo $! > __SC_PID__) | tee __TEMP_NS__ | (grep -qm1 "END_OF_TEST" && kill $(cat __SC_PID__)) guest socat -u OPEN:test.bin UDP4:__GW__:10002 hostw @@ -54,7 +51,6 @@ check [ "__HOST_MD5__" = "__MD5__" ] test UDP/IPv4: ns to host (recvmmsg/sendmmsg) sleep 1 -host :> __TEMP__ hostb (socat -u UDP4-LISTEN:10003 STDOUT & echo $! > __SC_PID__) | tee __TEMP__ | (grep -qm1 "END_OF_TEST" && kill $(cat __SC_PID__)) ns socat -u OPEN:__TEMP_NS__ UDP4:127.0.0.1:10003 hostw @@ -62,7 +58,6 @@ hout HOST_MD5 md5sum __TEMP__ | cut -d' ' -f1 check [ "__HOST_MD5__" = "__MD5__" ] test UDP/IPv4: ns to host (via tap) -host :> __TEMP__ hostb (socat -u UDP4-LISTEN:10003 STDOUT & echo $! > __SC_PID__) | tee __TEMP__ | (grep -qm1 "END_OF_TEST" && kill $(cat __SC_PID__)) ns socat -u OPEN:__TEMP_NS__ UDP4:__GW__:10003 hostw @@ -93,7 +88,6 @@ gout GUEST_MD5 md5sum test.bin | cut -d' ' -f1 check [ "__GUEST_MD5__" = "__MD5__" ] test UDP/IPv6: host to ns -ns :> __TEMP_NS__ nsb (socat -u UDP6-LISTEN:10002 STDOUT & echo $! > __SC_PID__) | tee __TEMP_NS__ | (grep -qm1 "END_OF_TEST" && kill $(cat __SC_PID__)) host socat -u OPEN:__TEMP__ UDP6:[::1]:10002 nsw @@ -101,7 +95,6 @@ nsout NS_MD5 md5sum __TEMP_NS__ | cut -d' ' -f1 check [ "__NS_MD5__" = "__MD5__" ] test UDP/IPv6: guest to host -host :> __TEMP__ hostb (socat -u UDP6-LISTEN:10003 STDOUT & echo $! > __SC_PID__) | tee __TEMP__ | (grep -qm1 "END_OF_TEST" && kill $(cat __SC_PID__)) gout GW6 ip -j -6 route show|jq -rM '.[] | select(.dst == "default").gateway' gout IFNAME ip -j link show | jq -rM '.[] | select(.link_type == "ether").ifname' @@ -111,7 +104,6 @@ hout HOST_MD5 md5sum __TEMP__ | cut -d' ' -f1 check [ "__HOST_MD5__" = "__MD5__" ] test UDP/IPv6: guest to ns -ns :> __TEMP_NS__ nsb (socat -u UDP6-LISTEN:10002 STDOUT & echo $! > __SC_PID__) | tee __TEMP_NS__ | (grep -qm1 "END_OF_TEST" && kill $(cat __SC_PID__)) guest socat -u OPEN:test.bin UDP6:[__GW6__%__IFNAME__]:10002 hostw @@ -119,7 +111,6 @@ hout HOST_MD5 md5sum __TEMP__ | cut -d' ' -f1 check [ "__HOST_MD5__" = "__MD5__" ] test UDP/IPv6: ns to host (recvmmsg/sendmmsg) -host :> __TEMP__ hostb (socat -u UDP6-LISTEN:10003 STDOUT & echo $! > __SC_PID__) | tee __TEMP__ | (grep -qm1 "END_OF_TEST" && kill $(cat __SC_PID__)) ns socat -u OPEN:__TEMP_NS__ UDP6:[::1]:10003 hostw @@ -127,7 +118,6 @@ hout HOST_MD5 md5sum __TEMP__ | cut -d' ' -f1 check [ "__HOST_MD5__" = "__MD5__" ] test UDP/IPv6: ns to host (via tap) -host :> __TEMP__ hostb (socat -u UDP6-LISTEN:10003 STDOUT & echo $! > __SC_PID__) | tee __TEMP__ | (grep -qm1 "END_OF_TEST" && kill $(cat __SC_PID__)) nsout IFNAME ip -j link show | jq -rM '.[] | select(.link_type == "ether").ifname' ns socat -u OPEN:__TEMP_NS__ UDP6:[__GW6__%__IFNAME__]:10003 diff --git a/test/udp/pasta b/test/udp/pasta index 43e0513..25063ea 100644 --- a/test/udp/pasta +++ b/test/udp/pasta @@ -18,7 +18,6 @@ test UDP/IPv4: host to ns temp TEMP temp TEMP_NS temp NC_PID -ns :> __TEMP_NS__ nsb (socat -u UDP4-LISTEN:10002,bind=127.0.0.1 STDOUT & echo $! > __NC_PID__) | tee __TEMP_NS__ | (grep -qm1 "END_OF_TEST" && kill $(cat __NC_PID__)) host dd if=/dev/urandom bs=1k count=5 > __TEMP__ && printf "\nEND_OF_TEST\n" >> __TEMP__ @@ -29,7 +28,6 @@ nsout NS_MD5 md5sum __TEMP_NS__ | cut -d' ' -f1 check [ "__NS_MD5__" = "__MD5__" ] test UDP/IPv4: ns to host (recvmmsg/sendmmsg) -host :> __TEMP__ hostb (socat -u UDP4-LISTEN:10003,bind=127.0.0.1 STDOUT & echo $! > __NC_PID__) | tee __TEMP__ | (grep -qm1 "END_OF_TEST" && kill $(cat __NC_PID__)) sleep 1 ns socat OPEN:__TEMP_NS__ UDP4:127.0.0.1:10003 @@ -38,7 +36,6 @@ hout HOST_MD5 md5sum __TEMP__ | cut -d' ' -f1 check [ "__HOST_MD5__" = "__MD5__" ] test UDP/IPv4: ns to host (via tap) -host :> __TEMP__ hostb (socat -u UDP4-LISTEN:10003 STDOUT & echo $! > __NC_PID__) | tee __TEMP__ | (grep -qm1 "END_OF_TEST" && kill $(cat __NC_PID__)) nsout GW ip -j -4 route show|jq -rM '.[] | select(.dst == "default").gateway' ns socat -u OPEN:__TEMP_NS__ UDP4:__GW__:10003 @@ -47,7 +44,6 @@ hout HOST_MD5 md5sum __TEMP__ | cut -d' ' -f1 check [ "__HOST_MD5__" = "__MD5__" ] test UDP/IPv6: host to ns -ns :> __TEMP_NS__ nsb (socat -u UDP6-LISTEN:10002,bind=[::1] STDOUT & echo $! > __NC_PID__) | tee __TEMP_NS__ | (grep -qm1 "END_OF_TEST" && kill $(cat __NC_PID__)) host socat -u OPEN:__TEMP__ UDP6:[::1]:10002 nsw @@ -56,7 +52,6 @@ nsout NS_MD5 md5sum __TEMP_NS__ | cut -d' ' -f1 check [ "__NS_MD5__" = "__MD5__" ] test UDP/IPv6: ns to host (recvmmsg/sendmmsg) -host :> __TEMP__ hostb (socat -u UDP6-LISTEN:10003,bind=[::1] STDOUT & echo $! > __NC_PID__) | tee __TEMP__ | (grep -qm1 "END_OF_TEST" && kill $(cat __NC_PID__)) sleep 1 ns socat -u OPEN:__TEMP_NS__ UDP6:[::1]:10003 @@ -66,7 +61,6 @@ check [ "__HOST_MD5__" = "__MD5__" ] nsw test UDP/IPv6: ns to host (via tap) -host :> __TEMP__ hostb (socat -u UDP6-LISTEN:10003 STDOUT & echo $! > __NC_PID__) | tee __TEMP__ | (grep -qm1 "END_OF_TEST" && kill $(cat __NC_PID__)) nsout GW6 ip -j -6 route show|jq -rM '.[] | select(.dst == "default").gateway' nsout IFNAME ip -j link show | jq -rM '.[] | select(.link_type == "ether").ifname' -- 2.36.1
Before starting the guests, these tests configure addresses in a pasta namespace using dhclient. However, because it's a user namespace, it's not running as "real" root and can't write to the dhclient pid file. This doesn't stop it working, but causes an ugly error message which we can avoid by using the --no-pid option. Signed-off-by: David Gibson <david(a)gibson.dropbear.id.au> --- test/lib/setup | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/test/lib/setup b/test/lib/setup index 752469c..5c7b08f 100755 --- a/test/lib/setup +++ b/test/lib/setup @@ -233,13 +233,13 @@ setup_two_guests() { pane_wait PASST_1 __ifname="$(pane_parse PASST_1)" - pane_run GUEST_1 "/sbin/dhclient -4 ${__ifname}" - pane_run GUEST_2 "/sbin/dhclient -4 ${__ifname}" + pane_run GUEST_1 "/sbin/dhclient -4 --no-pid ${__ifname}" + pane_run GUEST_2 "/sbin/dhclient -4 --no-pid ${__ifname}" pane_status GUEST_1 pane_status GUEST_2 sleep 2 - pane_run GUEST_1 "/sbin/dhclient -6 ${__ifname}" - pane_run GUEST_2 "/sbin/dhclient -6 ${__ifname}" + pane_run GUEST_1 "/sbin/dhclient -6 --no-pid ${__ifname}" + pane_run GUEST_2 "/sbin/dhclient -6 --no-pid ${__ifname}" pane_status GUEST_1 pane_status GUEST_2 -- 2.36.1
The iperf based test commands create a bunch of .bw and .pid files for each iperf client and server. The server side .bw files are cleaned up afterwards, but the pid files are not, and none of the client side files are cleaned up. The latter doesn't really matter when the client is run on ephemeral guests, but sometimes we run it in a namespace that shares the filesystem with the host. Clean up all of these files after the tests. Signed-off-by: David Gibson <david(a)gibson.dropbear.id.au> --- test/lib/test | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/lib/test b/test/lib/test index cb89e0b..e5a8632 100755 --- a/test/lib/test +++ b/test/lib/test @@ -79,7 +79,7 @@ test_iperf3() { pane_wait "${__pane}" pane_parse "${__pane}" pane_run "${__pane}" 'for i in $(seq 0 '${__procs}'); do' \ - 'rm -f s${i}.bw; done' + 'rm -f [cs]${i}.bw [cs]${i}.pid; done' pane_status "${__pane}" } -- 2.36.1
With pasta, the namespace interface name is generally the same as the host interface name. We already rely on this in the dhcp/pasta tests, but for no clear reason ndp/pasta separately determines the host interface name. Remove this unnecessary step. Signed-off-by: David Gibson <david(a)gibson.dropbear.id.au> --- test/ndp/pasta | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/test/ndp/pasta b/test/ndp/pasta index 2a2dd1a..28fdd72 100644 --- a/test/ndp/pasta +++ b/test/ndp/pasta @@ -16,15 +16,14 @@ htools ip jq sipcalc grep cut test Interface name nsout IFNAME ip -j link show | jq -rM '.[] | select(.link_type == "ether").ifname' +check [ -n "__IFNAME__" ] ns ip link set dev __IFNAME__ up sleep 2 -hout HOST_IFNAME ip -j -4 route show|jq -rM '.[] | select(.dst == "default").dev' -check [ -n "__IFNAME__" ] test SLAAC: prefix nsout ADDR6 ip -j -6 addr show|jq -rM '.[] | select(.ifname == "__IFNAME__").addr_info[] | select(.scope == "global" and .prefixlen == 64).local' nsout PREFIX6 sipcalc __ADDR6__/64 | grep prefix | cut -d' ' -f4 -hout HOST_ADDR6 ip -j -6 addr show|jq -rM '.[] | select(.ifname == "__HOST_IFNAME__").addr_info[] | select(.scope == "global").local' +hout HOST_ADDR6 ip -j -6 addr show|jq -rM '.[] | select(.ifname == "__IFNAME__").addr_info[] | select(.scope == "global").local' hout HOST_PREFIX6 sipcalc __HOST_ADDR6__/64 | grep prefix | cut -d' ' -f4 check [ "__PREFIX6__" = "__HOST_PREFIX6__" ] -- 2.36.1
By default, passt itself attaches to the first host interface with a default route. However, when determining the host interface name the tests implicitly select the *last* host interface: they use a jq expression which will list all interfaces with default routes, but the way output detection works in the scripts, it will only pick up the last line. If there are multiple interfaces with default routes on the host, and they each have a different address, this can cause spurious test failures. Signed-off-by: David Gibson <david(a)gibson.dropbear.id.au> --- test/dhcp/passt | 2 +- test/two_guests/basic | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/test/dhcp/passt b/test/dhcp/passt index 3d2e939..f45227a 100644 --- a/test/dhcp/passt +++ b/test/dhcp/passt @@ -16,7 +16,7 @@ htools ip jq sed tr head test Interface name gout IFNAME ip -j link show | jq -rM '.[] | select(.link_type == "ether").ifname' -hout HOST_IFNAME ip -j -4 route show|jq -rM '.[] | select(.dst == "default").dev' +hout HOST_IFNAME ip -j -4 route show|jq -rM '[.[] | select(.dst == "default").dev] | .[0]' check [ -n "__IFNAME__" ] test DHCP: address diff --git a/test/two_guests/basic b/test/two_guests/basic index cf0b975..f7c016d 100644 --- a/test/two_guests/basic +++ b/test/two_guests/basic @@ -18,7 +18,7 @@ htools ip jq md5sum cut test Interface names g1out IFNAME1 ip -j link show | jq -rM '.[] | select(.link_type == "ether").ifname' g2out IFNAME2 ip -j link show | jq -rM '.[] | select(.link_type == "ether").ifname' -hout HOST_IFNAME ip -j -4 route show|jq -rM '.[] | select(.dst == "default").dev' +hout HOST_IFNAME ip -j -4 route show|jq -rM '[.[] | select(.dst == "default").dev] | .[0]' check [ -n "__IFNAME1__" ] check [ -n "__IFNAME2__" ] -- 2.36.1
On Fri, Jul 15, 2022 at 03:21:40PM +1000, David Gibson wrote:By default, passt itself attaches to the first host interface with a default route. However, when determining the host interface name the tests implicitly select the *last* host interface: they use a jq expression which will list all interfaces with default routes, but the way output detection works in the scripts, it will only pick up the last line. If there are multiple interfaces with default routes on the host, and they each have a different address, this can cause spurious test failures.It seems this change is not enough to always fix the tests when there are multiple default routes. I'm still sometimes getting failures, now because passt itself doesn't seem to be picking the interface with the first default route. I'm wondering if this is because ip(8) is sorting the output, not just presenting it in the same order that the underlying netlink interface does.Signed-off-by: David Gibson <david(a)gibson.dropbear.id.au> --- test/dhcp/passt | 2 +- test/two_guests/basic | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/test/dhcp/passt b/test/dhcp/passt index 3d2e939..f45227a 100644 --- a/test/dhcp/passt +++ b/test/dhcp/passt @@ -16,7 +16,7 @@ htools ip jq sed tr head test Interface name gout IFNAME ip -j link show | jq -rM '.[] | select(.link_type == "ether").ifname' -hout HOST_IFNAME ip -j -4 route show|jq -rM '.[] | select(.dst == "default").dev' +hout HOST_IFNAME ip -j -4 route show|jq -rM '[.[] | select(.dst == "default").dev] | .[0]' check [ -n "__IFNAME__" ] test DHCP: address diff --git a/test/two_guests/basic b/test/two_guests/basic index cf0b975..f7c016d 100644 --- a/test/two_guests/basic +++ b/test/two_guests/basic @@ -18,7 +18,7 @@ htools ip jq md5sum cut test Interface names g1out IFNAME1 ip -j link show | jq -rM '.[] | select(.link_type == "ether").ifname' g2out IFNAME2 ip -j link show | jq -rM '.[] | select(.link_type == "ether").ifname' -hout HOST_IFNAME ip -j -4 route show|jq -rM '.[] | select(.dst == "default").dev' +hout HOST_IFNAME ip -j -4 route show|jq -rM '[.[] | select(.dst == "default").dev] | .[0]' check [ -n "__IFNAME1__" ] check [ -n "__IFNAME2__" ]-- David Gibson | I'll have my music baroque, and my code david AT gibson.dropbear.id.au | minimalist, thank you. NOT _the_ _other_ | _way_ _around_! http://www.ozlabs.org/~dgibson
On Tue, 19 Jul 2022 16:20:45 +1000 David Gibson <david(a)gibson.dropbear.id.au> wrote:On Fri, Jul 15, 2022 at 03:21:40PM +1000, David Gibson wrote:I don't see that happening at least in my environment (and I also can't see any code that would sort it, that pretty much comes from rtnl_dump_filter_l() in lib/libnetlink.c). The netlink "filter", though, is slightly different. For IPv4: $ strace -e sendto ip route show >/dev/null sendto(3, [{{len=36, type=RTM_GETROUTE, flags=NLM_F_REQUEST|NLM_F_DUMP, seq=1658257027, pid=0}, {rtm_family=AF_INET, rtm_dst_len=0, rtm_src_len=0, rtm_tos=0, rtm_table=RT_TABLE_UNSPEC, rtm_protocol=RTPROT_UNSPEC, rtm_scope=RT_SCOPE_UNIVERSE, rtm_type=RTN_UNSPEC, rtm_flags=0}, {{nla_len=8, nla_type=RTA_TABLE}, RT_TABLE_MAIN}}, {len=0, type=0 /* NLMSG_??? */, flags=0, seq=0, pid=0}], 156, 0, NULL, 0) = 156 $ strace -e sendto ./passt -f sendto(5, {{len=28, type=RTM_GETROUTE, flags=NLM_F_REQUEST|NLM_F_DUMP, seq=0, pid=0}, {rtm_family=AF_INET, rtm_dst_len=0, rtm_src_len=0, rtm_tos=0, rtm_table=RT_TABLE_MAIN, rtm_protocol=RTPROT_UNSPEC, rtm_scope=RT_SCOPE_UNIVERSE, rtm_type=RTN_UNICAST, rtm_flags=0}}, 28, 0, NULL, 0) = 28 [...] and, while I don't think the FIB trie is actually descended in a different way, we might still have a slightly different result from the kernel (if I recall correctly, I didn't check right now). But letting that aside for a moment: if you have two default routes, I suppose they have different metrics. If not, what's the intended usage? If yes, we should probably implement a sorting logic in passt, so that the route with the lowest metric is picked, and then adjust the jq expression to also pick that one. -- StefanoBy default, passt itself attaches to the first host interface with a default route. However, when determining the host interface name the tests implicitly select the *last* host interface: they use a jq expression which will list all interfaces with default routes, but the way output detection works in the scripts, it will only pick up the last line. If there are multiple interfaces with default routes on the host, and they each have a different address, this can cause spurious test failures.It seems this change is not enough to always fix the tests when there are multiple default routes. I'm still sometimes getting failures, now because passt itself doesn't seem to be picking the interface with the first default route. I'm wondering if this is because ip(8) is sorting the output, not just presenting it in the same order that the underlying netlink interface does.
On Tue, Jul 19, 2022 at 09:05:52PM +0200, Stefano Brivio wrote:On Tue, 19 Jul 2022 16:20:45 +1000 David Gibson <david(a)gibson.dropbear.id.au> wrote:Yes, there are two different metrics. I was thinking after I sent this that we should sort by metric.On Fri, Jul 15, 2022 at 03:21:40PM +1000, David Gibson wrote:I don't see that happening at least in my environment (and I also can't see any code that would sort it, that pretty much comes from rtnl_dump_filter_l() in lib/libnetlink.c). The netlink "filter", though, is slightly different. For IPv4: $ strace -e sendto ip route show >/dev/null sendto(3, [{{len=36, type=RTM_GETROUTE, flags=NLM_F_REQUEST|NLM_F_DUMP, seq=1658257027, pid=0}, {rtm_family=AF_INET, rtm_dst_len=0, rtm_src_len=0, rtm_tos=0, rtm_table=RT_TABLE_UNSPEC, rtm_protocol=RTPROT_UNSPEC, rtm_scope=RT_SCOPE_UNIVERSE, rtm_type=RTN_UNSPEC, rtm_flags=0}, {{nla_len=8, nla_type=RTA_TABLE}, RT_TABLE_MAIN}}, {len=0, type=0 /* NLMSG_??? */, flags=0, seq=0, pid=0}], 156, 0, NULL, 0) = 156 $ strace -e sendto ./passt -f sendto(5, {{len=28, type=RTM_GETROUTE, flags=NLM_F_REQUEST|NLM_F_DUMP, seq=0, pid=0}, {rtm_family=AF_INET, rtm_dst_len=0, rtm_src_len=0, rtm_tos=0, rtm_table=RT_TABLE_MAIN, rtm_protocol=RTPROT_UNSPEC, rtm_scope=RT_SCOPE_UNIVERSE, rtm_type=RTN_UNICAST, rtm_flags=0}}, 28, 0, NULL, 0) = 28 [...] and, while I don't think the FIB trie is actually descended in a different way, we might still have a slightly different result from the kernel (if I recall correctly, I didn't check right now). But letting that aside for a moment: if you have two default routes, I suppose they have different metrics. If not, what's the intended usage?By default, passt itself attaches to the first host interface with a default route. However, when determining the host interface name the tests implicitly select the *last* host interface: they use a jq expression which will list all interfaces with default routes, but the way output detection works in the scripts, it will only pick up the last line. If there are multiple interfaces with default routes on the host, and they each have a different address, this can cause spurious test failures.It seems this change is not enough to always fix the tests when there are multiple default routes. I'm still sometimes getting failures, now because passt itself doesn't seem to be picking the interface with the first default route. I'm wondering if this is because ip(8) is sorting the output, not just presenting it in the same order that the underlying netlink interface does.If yes, we should probably implement a sorting logic in passt, so that the route with the lowest metric is picked, and then adjust the jq expression to also pick that one.Agreed. I'll see if I can implement this. Up to you whether you drop this patch or I just do another update on top of it. -- David Gibson | I'll have my music baroque, and my code david AT gibson.dropbear.id.au | minimalist, thank you. NOT _the_ _other_ | _way_ _around_! http://www.ozlabs.org/~dgibson
On Wed, Jul 20, 2022 at 12:47:57PM +1000, David Gibson wrote:On Tue, Jul 19, 2022 at 09:05:52PM +0200, Stefano Brivio wrote: > On Tue, 19 Jul 2022 16:20:45 +1000 > David Gibson <david(a)gibson.dropbear.id.au> wrote: > > > On Fri, Jul 15, 2022 at 03:21:40PM +1000, David Gibson wrote: > > > By default, passt itself attaches to the first host interface with a > > > default route. However, when determining the host interface name the tests > > > implicitly select the *last* host interface: they use a jq expression which > > > will list all interfaces with default routes, but the way output detection > > > works in the scripts, it will only pick up the last line. > > > > > > If there are multiple interfaces with default routes on the host, and they > > > each have a different address, this can cause spurious test > > > failures. > > > > It seems this change is not enough to always fix the tests when there > > are multiple default routes. I'm still sometimes getting failures, > > now because passt itself doesn't seem to be picking the interface > > with the first default route. > > > > I'm wondering if this is because ip(8) is sorting the output, not just > > presenting it in the same order that the underlying netlink interface > > does. > > I don't see that happening at least in my environment (and I also can't > see any code that would sort it, that pretty much comes from > rtnl_dump_filter_l() in lib/libnetlink.c). > > The netlink "filter", though, is slightly different. For IPv4: > > $ strace -e sendto ip route show >/dev/null > sendto(3, [{{len=36, type=RTM_GETROUTE, flags=NLM_F_REQUEST|NLM_F_DUMP, seq=1658257027, pid=0}, {rtm_family=AF_INET, rtm_dst_len=0, rtm_src_len=0, rtm_tos=0, rtm_table=RT_TABLE_UNSPEC, rtm_protocol=RTPROT_UNSPEC, rtm_scope=RT_SCOPE_UNIVERSE, rtm_type=RTN_UNSPEC, rtm_flags=0}, {{nla_len=8, nla_type=RTA_TABLE}, RT_TABLE_MAIN}}, {len=0, type=0 /* NLMSG_??? */, flags=0, seq=0, pid=0}], 156, 0, NULL, 0) = 156 > > $ strace -e sendto ./passt -f > sendto(5, {{len=28, type=RTM_GETROUTE, flags=NLM_F_REQUEST|NLM_F_DUMP, seq=0, pid=0}, {rtm_family=AF_INET, rtm_dst_len=0, rtm_src_len=0, rtm_tos=0, rtm_table=RT_TABLE_MAIN, rtm_protocol=RTPROT_UNSPEC, rtm_scope=RT_SCOPE_UNIVERSE, rtm_type=RTN_UNICAST, rtm_flags=0}}, 28, 0, NULL, 0) = 28 > [...] > > and, while I don't think the FIB trie is actually descended in a > different way, we might still have a slightly different result from the > kernel (if I recall correctly, I didn't check right now).So, I've been staring at this for most of the day. I don't think the difference is because of the slightly different filters. Instead it's an easy to miss subtletly in nl_get_ext_if(). In nl_get_ext_if() both first_v4 and first_v6 will be set to the interface which meets the criteria and comes first in the order of routes returned by netlink from the kernel. However, there's this early return: word = (long *)has_v4; for (i = 0; i < ARRAY_SIZE(has_v4) / sizeof(long); i++, word++) { tmp = *word; while ((n = ffsl(tmp))) { int ifi = i * sizeof(long) * 8 + n - 1; if (!first_v4) first_v4 = ifi; tmp &= ~(1UL << (n - 1)); if (bitmap_isset(has_v6, ifi)) { *v4 = *v6 = IP_VERSION_ENABLED; return ifi; <================ HERE } } } Which means that if we find an interface with both a v4 and a v6 default route, we'll return it immediately. That loop is across the has_v4 bitmap, so we'll return the first one in *interface index order*, which might not necessarily be the same as the order the routes are returned from netlink. In the other cases: one of v4 or v6 is disabled, or there's no interface with both v4 and v6 default routes, then we'll end up returning the first interface in netlink route order. Which makes passt's overall priority of selecting interfaces pretty hard to follow. I've been thinking a bunch about what the order should be. The obvious cleanup to the current logic would be: 1. If there are >0 interfaces with both default v4 and v6 routes, pick the one with the lowest metric 2. Otherwise if there are >0 interfaces with a default v4 route, pick the one with the lowest metric 3. Otherwise if there are >0 interfaces with a default v6 route, pick the one with the lowest metric 4. Otherwise fail. ..but, I think that's the wrong choice. For one thing it gets weird in the unlikely but possible case that there are two interfaces with both v4 and v6 routes, but one has a lower v4 metric and the other has a lower v6 metric. But more importantly, I think it fails the "do what you want by default" test in the case of a host that has both v4 and v6 routing, but not on the same interface. That's quite a realistic situation if the v6 connectivity is coming from a tunnel (6in4 or 6rd or 6over4 or whatever). Instead, I think we should separately pick an external interface for v4 and v6 connectivity. Yes, it's weird to have a view of two different host interfaces on the same virtual interface. It also means pasta has to arbitrarily pick one of the host interface names for the namespace, which will make the tests a bit uglier. But it makes picking the right interfaces a lot simpler and clearer, and does what you probably want for the case of a host with tunnelled ipv6 connectivity.-- David Gibson | I'll have my music baroque, and my code david AT gibson.dropbear.id.au | minimalist, thank you. NOT _the_ _other_ | _way_ _around_! http://www.ozlabs.org/~dgibsonBut letting that aside for a moment: if you have two default routes, I suppose they have different metrics. If not, what's the intended usage?Yes, there are two different metrics. I was thinking after I sent this that we should sort by metric.If yes, we should probably implement a sorting logic in passt, so that the route with the lowest metric is picked, and then adjust the jq expression to also pick that one.Agreed. I'll see if I can implement this. Up to you whether you drop this patch or I just do another update on top of it.
On Wed, 20 Jul 2022 17:24:18 +1000 David Gibson <david(a)gibson.dropbear.id.au> wrote:On Wed, Jul 20, 2022 at 12:47:57PM +1000, David Gibson wrote:Whoops :) ...right, sorry, I forgot about that.On Tue, Jul 19, 2022 at 09:05:52PM +0200, Stefano Brivio wrote: > On Tue, 19 Jul 2022 16:20:45 +1000 > David Gibson <david(a)gibson.dropbear.id.au> wrote: > > > On Fri, Jul 15, 2022 at 03:21:40PM +1000, David Gibson wrote: > > > By default, passt itself attaches to the first host interface with a > > > default route. However, when determining the host interface name the tests > > > implicitly select the *last* host interface: they use a jq expression which > > > will list all interfaces with default routes, but the way output detection > > > works in the scripts, it will only pick up the last line. > > > > > > If there are multiple interfaces with default routes on the host, and they > > > each have a different address, this can cause spurious test > > > failures. > > > > It seems this change is not enough to always fix the tests when there > > are multiple default routes. I'm still sometimes getting failures, > > now because passt itself doesn't seem to be picking the interface > > with the first default route. > > > > I'm wondering if this is because ip(8) is sorting the output, not just > > presenting it in the same order that the underlying netlink interface > > does. > > I don't see that happening at least in my environment (and I also can't > see any code that would sort it, that pretty much comes from > rtnl_dump_filter_l() in lib/libnetlink.c). > > The netlink "filter", though, is slightly different. For IPv4: > > $ strace -e sendto ip route show >/dev/null > sendto(3, [{{len=36, type=RTM_GETROUTE, flags=NLM_F_REQUEST|NLM_F_DUMP, seq=1658257027, pid=0}, {rtm_family=AF_INET, rtm_dst_len=0, rtm_src_len=0, rtm_tos=0, rtm_table=RT_TABLE_UNSPEC, rtm_protocol=RTPROT_UNSPEC, rtm_scope=RT_SCOPE_UNIVERSE, rtm_type=RTN_UNSPEC, rtm_flags=0}, {{nla_len=8, nla_type=RTA_TABLE}, RT_TABLE_MAIN}}, {len=0, type=0 /* NLMSG_??? */, flags=0, seq=0, pid=0}], 156, 0, NULL, 0) = 156 > > $ strace -e sendto ./passt -f > sendto(5, {{len=28, type=RTM_GETROUTE, flags=NLM_F_REQUEST|NLM_F_DUMP, seq=0, pid=0}, {rtm_family=AF_INET, rtm_dst_len=0, rtm_src_len=0, rtm_tos=0, rtm_table=RT_TABLE_MAIN, rtm_protocol=RTPROT_UNSPEC, rtm_scope=RT_SCOPE_UNIVERSE, rtm_type=RTN_UNICAST, rtm_flags=0}}, 28, 0, NULL, 0) = 28 > [...] > > and, while I don't think the FIB trie is actually descended in a > different way, we might still have a slightly different result from the > kernel (if I recall correctly, I didn't check right now).So, I've been staring at this for most of the day. I don't think the difference is because of the slightly different filters. Instead it's an easy to miss subtletly in nl_get_ext_if(). In nl_get_ext_if() both first_v4 and first_v6 will be set to the interface which meets the criteria and comes first in the order of routes returned by netlink from the kernel. However, there's this early return: word = (long *)has_v4; for (i = 0; i < ARRAY_SIZE(has_v4) / sizeof(long); i++, word++) { tmp = *word; while ((n = ffsl(tmp))) { int ifi = i * sizeof(long) * 8 + n - 1; if (!first_v4) first_v4 = ifi; tmp &= ~(1UL << (n - 1)); if (bitmap_isset(has_v6, ifi)) { *v4 = *v6 = IP_VERSION_ENABLED; return ifi; <================ HERE } } } Which means that if we find an interface with both a v4 and a v6 default route, we'll return it immediately. That loop is across the has_v4 bitmap, so we'll return the first one in *interface index order*, which might not necessarily be the same as the order the routes are returned from netlink.In the other cases: one of v4 or v6 is disabled, or there's no interface with both v4 and v6 default routes, then we'll end up returning the first interface in netlink route order. Which makes passt's overall priority of selecting interfaces pretty hard to follow. I've been thinking a bunch about what the order should be. The obvious cleanup to the current logic would be: 1. If there are >0 interfaces with both default v4 and v6 routes, pick the one with the lowest metric 2. Otherwise if there are >0 interfaces with a default v4 route, pick the one with the lowest metric 3. Otherwise if there are >0 interfaces with a default v6 route, pick the one with the lowest metric 4. Otherwise fail. ..but, I think that's the wrong choice. For one thing it gets weird in the unlikely but possible case that there are two interfaces with both v4 and v6 routes, but one has a lower v4 metric and the other has a lower v6 metric. But more importantly, I think it fails the "do what you want by default" test in the case of a host that has both v4 and v6 routing, but not on the same interface. That's quite a realistic situation if the v6 connectivity is coming from a tunnel (6in4 or 6rd or 6over4 or whatever).Definitely, I didn't consider the tunneled IPv6 case, but it looks still rather real even nowadays.Instead, I think we should separately pick an external interface for v4 and v6 connectivity. Yes, it's weird to have a view of two different host interfaces on the same virtual interface. It also means pasta has to arbitrarily pick one of the host interface names for the namespace, which will make the tests a bit uglier. But it makes picking the right interfaces a lot simpler and clearer, and does what you probably want for the case of a host with tunnelled ipv6 connectivity.I totally agree. It's still less weird than the alternative. We'll need to store two interface indices (say, "ifi4" and "ifi6"), but their usage right now is almost entirely limited to configuration and netlink functions. One additional usage is to select a given interface for sockets bound to link-local addresses by means of setting .sin6_scope_id in struct sockaddr_in6 -- that happens in tcp_conn_from_tap() and sock_l4(). There, we just need to switch to the new "ifi6" index. Let me know if I should start looking into this or if you can do it instead. -- Stefano
On Wed, Jul 20, 2022 at 10:23:22AM +0200, Stefano Brivio wrote:On Wed, 20 Jul 2022 17:24:18 +1000 David Gibson <david(a)gibson.dropbear.id.au> wrote:Yeah, I gather IPv6 is finally fairly standard in Germany, but here in Australia I'm with basically the only residential ISP which provides v6.On Wed, Jul 20, 2022 at 12:47:57PM +1000, David Gibson wrote:Whoops :) ...right, sorry, I forgot about that.On Tue, Jul 19, 2022 at 09:05:52PM +0200, Stefano Brivio wrote: > On Tue, 19 Jul 2022 16:20:45 +1000 > David Gibson <david(a)gibson.dropbear.id.au> wrote: > > > On Fri, Jul 15, 2022 at 03:21:40PM +1000, David Gibson wrote: > > > By default, passt itself attaches to the first host interface with a > > > default route. However, when determining the host interface name the tests > > > implicitly select the *last* host interface: they use a jq expression which > > > will list all interfaces with default routes, but the way output detection > > > works in the scripts, it will only pick up the last line. > > > > > > If there are multiple interfaces with default routes on the host, and they > > > each have a different address, this can cause spurious test > > > failures. > > > > It seems this change is not enough to always fix the tests when there > > are multiple default routes. I'm still sometimes getting failures, > > now because passt itself doesn't seem to be picking the interface > > with the first default route. > > > > I'm wondering if this is because ip(8) is sorting the output, not just > > presenting it in the same order that the underlying netlink interface > > does. > > I don't see that happening at least in my environment (and I also can't > see any code that would sort it, that pretty much comes from > rtnl_dump_filter_l() in lib/libnetlink.c). > > The netlink "filter", though, is slightly different. For IPv4: > > $ strace -e sendto ip route show >/dev/null > sendto(3, [{{len=36, type=RTM_GETROUTE, flags=NLM_F_REQUEST|NLM_F_DUMP, seq=1658257027, pid=0}, {rtm_family=AF_INET, rtm_dst_len=0, rtm_src_len=0, rtm_tos=0, rtm_table=RT_TABLE_UNSPEC, rtm_protocol=RTPROT_UNSPEC, rtm_scope=RT_SCOPE_UNIVERSE, rtm_type=RTN_UNSPEC, rtm_flags=0}, {{nla_len=8, nla_type=RTA_TABLE}, RT_TABLE_MAIN}}, {len=0, type=0 /* NLMSG_??? */, flags=0, seq=0, pid=0}], 156, 0, NULL, 0) = 156 > > $ strace -e sendto ./passt -f > sendto(5, {{len=28, type=RTM_GETROUTE, flags=NLM_F_REQUEST|NLM_F_DUMP, seq=0, pid=0}, {rtm_family=AF_INET, rtm_dst_len=0, rtm_src_len=0, rtm_tos=0, rtm_table=RT_TABLE_MAIN, rtm_protocol=RTPROT_UNSPEC, rtm_scope=RT_SCOPE_UNIVERSE, rtm_type=RTN_UNICAST, rtm_flags=0}}, 28, 0, NULL, 0) = 28 > [...] > > and, while I don't think the FIB trie is actually descended in a > different way, we might still have a slightly different result from the > kernel (if I recall correctly, I didn't check right now).So, I've been staring at this for most of the day. I don't think the difference is because of the slightly different filters. Instead it's an easy to miss subtletly in nl_get_ext_if(). In nl_get_ext_if() both first_v4 and first_v6 will be set to the interface which meets the criteria and comes first in the order of routes returned by netlink from the kernel. However, there's this early return: word = (long *)has_v4; for (i = 0; i < ARRAY_SIZE(has_v4) / sizeof(long); i++, word++) { tmp = *word; while ((n = ffsl(tmp))) { int ifi = i * sizeof(long) * 8 + n - 1; if (!first_v4) first_v4 = ifi; tmp &= ~(1UL << (n - 1)); if (bitmap_isset(has_v6, ifi)) { *v4 = *v6 = IP_VERSION_ENABLED; return ifi; <================ HERE } } } Which means that if we find an interface with both a v4 and a v6 default route, we'll return it immediately. That loop is across the has_v4 bitmap, so we'll return the first one in *interface index order*, which might not necessarily be the same as the order the routes are returned from netlink.In the other cases: one of v4 or v6 is disabled, or there's no interface with both v4 and v6 default routes, then we'll end up returning the first interface in netlink route order. Which makes passt's overall priority of selecting interfaces pretty hard to follow. I've been thinking a bunch about what the order should be. The obvious cleanup to the current logic would be: 1. If there are >0 interfaces with both default v4 and v6 routes, pick the one with the lowest metric 2. Otherwise if there are >0 interfaces with a default v4 route, pick the one with the lowest metric 3. Otherwise if there are >0 interfaces with a default v6 route, pick the one with the lowest metric 4. Otherwise fail. ..but, I think that's the wrong choice. For one thing it gets weird in the unlikely but possible case that there are two interfaces with both v4 and v6 routes, but one has a lower v4 metric and the other has a lower v6 metric. But more importantly, I think it fails the "do what you want by default" test in the case of a host that has both v4 and v6 routing, but not on the same interface. That's quite a realistic situation if the v6 connectivity is coming from a tunnel (6in4 or 6rd or 6over4 or whatever).Definitely, I didn't consider the tunneled IPv6 case, but it looks still rather real even nowadays.Excellent.Instead, I think we should separately pick an external interface for v4 and v6 connectivity. Yes, it's weird to have a view of two different host interfaces on the same virtual interface. It also means pasta has to arbitrarily pick one of the host interface names for the namespace, which will make the tests a bit uglier. But it makes picking the right interfaces a lot simpler and clearer, and does what you probably want for the case of a host with tunnelled ipv6 connectivity.I totally agree. It's still less weird than the alternative.We'll need to store two interface indices (say, "ifi4" and "ifi6"), but their usage right now is almost entirely limited to configuration and netlink functions.Yes, I looked through all the uses of c->ifi, and it looks fairly straightforward.One additional usage is to select a given interface for sockets bound to link-local addresses by means of setting .sin6_scope_id in struct sockaddr_in6 -- that happens in tcp_conn_from_tap() and sock_l4(). There, we just need to switch to the new "ifi6" index. Let me know if I should start looking into this or if you can do it instead.I'll work on it. Hoping I can get that done before heading on holiday next week. -- David Gibson | I'll have my music baroque, and my code david AT gibson.dropbear.id.au | minimalist, thank you. NOT _the_ _other_ | _way_ _around_! http://www.ozlabs.org/~dgibson
For some reason using https to clone from the passt git repo is very slow, at least from network-distant places. Use git protocol in the demo instead to avoid a tedious wait to get the source. Signed-off-by: David Gibson <david(a)gibson.dropbear.id.au> --- test/demo/passt | 2 +- test/demo/pasta | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/test/demo/passt b/test/demo/passt index dac8ac7..72744b1 100644 --- a/test/demo/passt +++ b/test/demo/passt @@ -22,7 +22,7 @@ say Let's fetch the source sleep 1 tempdir TEMPDIR host cd __TEMPDIR__ -host git clone https://passt.top/passt +host git clone git://passt.top/passt sleep 1 say and build it. diff --git a/test/demo/pasta b/test/demo/pasta index d84d856..9a5c381 100644 --- a/test/demo/pasta +++ b/test/demo/pasta @@ -22,7 +22,7 @@ say Let's fetch the source sleep 1 tempdir TEMPDIR host cd __TEMPDIR__ -host git clone https://passt.top/passt +host git clone git://passt.top/passt sleep 1 say and build it. -- 2.36.1
On Fri, 15 Jul 2022 15:21:23 +1000 David Gibson <david(a)gibson.dropbear.id.au> wrote:Here's yet another batch of fixes to make the tests more robust against different environments. With this lot, I'm now able to run the pasta, passt, passt_in_ns and two_guests tests on my Fedora system. I'm still hitting problems with the perf tests. This series (specifically 11/18) updates the demo to use socat instead of openbsd netcat. This is needed, or the change to socat in the mbuto image would break the demo. However, I'm hitting unrelated problems trying to run the demos, so the switch to socat is, alas, untested.I'm testing this now (excluding 17/18) together with the demo fix-up series I just sent, hopefully some of the issues you found there are also gone. -- Stefano