pull request: ovpn 2026-04-13
Subsystems (4)
Antonio Quartulli
maintainercover pull request: ovpn 2026-04-13
Hi Jakub,
I know I am on the edge of the merge window, but I still wanted to send this batch of improvements for the ovpn kselftest because, as you pointed out after my last PR, there were still some pending issues with the latest changes I sent.
This PR is entirely about improving selftests to avoid hangs and ensure they better cope with the kernel CI.
See the tag content for a more detailed summary.
Sorry for being late :/ I hope this can still go in. There is no change outside of the selftest folder.
Please pull or let me know of any issue!
Thanks a lot,
Antonio
The following changes since commit 42f9b4c6ef19e71d2c7d9bfd3c5037d4fe434ad7:
tools: ynl: tests: fix leading space on Makefile target (2026-04-09 20:41:40 -0700)
are available in the Git repository at:
https://github.com/OpenVPN/ovpn-net-next.git tags/ovpn-net-next-20260412
for you to fetch changes up to dc76eb924963f6d48980b6113888c6103f16b8f8:
selftests: ovpn: align command flow with TAP (2026-04-13 00:08:43 +0200)
----------------------------------------------------------------
This batch includes only improvements to the selftest harness:
* switch to TAP test orchestration
* parse slurped notifications as returned by jq -s
* add ovpn_ prefix to helpers and global variables
* fail test in case of netlink notification mismatch
* add missing kernel config dependencies
----------------------------------------------------------------
Ralf Lici (5):
selftests: ovpn: add nftables config dependencies for test-mark
selftests: ovpn: fail notification check on mismatch
selftests: ovpn: flatten slurped notification JSON before filtering
selftests: ovpn: add namespace to helpers and shared variables
selftests: ovpn: align command flow with TAP
tools/testing/selftests/net/ovpn/common.sh | 282 ++++++++++---- tools/testing/selftests/net/ovpn/config | 3 + .../testing/selftests/net/ovpn/test-chachapoly.sh | 2 +- .../selftests/net/ovpn/test-close-socket-tcp.sh | 2 +- .../selftests/net/ovpn/test-close-socket.sh | 83 ++-- tools/testing/selftests/net/ovpn/test-float.sh | 2 +- tools/testing/selftests/net/ovpn/test-mark.sh | 223 +++++++---- .../selftests/net/ovpn/test-symmetric-id-float.sh | 4 +- .../selftests/net/ovpn/test-symmetric-id-tcp.sh | 4 +- .../selftests/net/ovpn/test-symmetric-id.sh | 2 +- tools/testing/selftests/net/ovpn/test-tcp.sh | 2 +- tools/testing/selftests/net/ovpn/test.sh | 423 ++++++++++++++------- 12 files changed, 706 insertions(+), 326 deletions(-)
Antonio Quartulli
maintainerPATCH 1/5 selftests: ovpn: add nftables config dependencies for test-mark
From: Ralf Lici <[email protected]>
test-mark.sh installs nftables rules in an inet/filter output chain and verifies packet drops via nft counters. In vmksft this can fail when the nftables core is not enabled by the ovpn selftest config.
Add the missing kernel options required by this test:
- CONFIG_NETFILTER
- CONFIG_NF_TABLES
- CONFIG_NF_TABLES_INET
--- tools/testing/selftests/net/ovpn/config | 3 +++ 1 file changed, 3 insertions(+)
tools/testing/selftests/net/ovpn/config +3 -0
@@ -5,6 +5,9 @@ CONFIG_CRYPTO_GCM=y CONFIG_DST_CACHE=y CONFIG_INET=y CONFIG_NET=y +CONFIG_NETFILTER=y CONFIG_NET_UDP_TUNNEL=y +CONFIG_NF_TABLES=m +CONFIG_NF_TABLES_INET=y CONFIG_OVPN=m CONFIG_STREAM_PARSER=y
Signature · 1 line
2.52.0
Antonio Quartulli
maintainerPATCH 2/5 selftests: ovpn: fail notification check on mismatch
In reply to Antonio QuartulliFrom: Ralf Lici <[email protected]>
compare_ntfs doesn't fail when expected and received notification streams diverge.
Fix this bug by trackink the diff exit status explicitly and return it to the caller so notification mismatches propagate as test failures.
--- tools/testing/selftests/net/ovpn/common.sh | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-)
tools/testing/selftests/net/ovpn/common.sh +12 -1
@@ -140,23 +140,34 @@ add_peer() { } compare_ntfs() { + local diff_rc=0 + local diff_file + if [ ${#tmp_jsons[@]} -gt 0 ]; then suffix="" [ "${SYMMETRIC_ID}" -eq 1 ] && suffix="${suffix}-symm" [ "$FLOAT" == 1 ] && suffix="${suffix}-float" expected="json/peer${1}${suffix}.json" received="${tmp_jsons[$1]}" + diff_file=$(mktemp) kill -TERM ${listener_pids[$1]} || true wait ${listener_pids[$1]} || true printf "Checking notifications for peer ${1}... " if diff <(jq -s "${JQ_FILTER}" ${expected}) \ - <(jq -s "${JQ_FILTER}" ${received}); then + <(jq -s "${JQ_FILTER}" ${received}) >"${diff_file}" 2>&1; then echo "OK" + else + diff_rc=$? + echo "failed" + cat "${diff_file}" fi + rm -f "${diff_file}" || true rm -f ${received} || true fi + + return "${diff_rc}" } cleanup() {
Signature · 1 line
2.52.0
Jakub Kicinski
maintainerRe: [PATCH net-next 2/5] selftests: ovpn: fail notification check on mismatch
Quoted 5 lines · On Mon, 13 Apr 2026 00:11:18 +0200 Antonio Quartulli wrote:
compare_ntfsdoesn't fail when expected and received notification streams diverge.Fix this bug by trackink the diff exit status explicitly and return it to the caller so notification mismatches propagate as test failures.
Hm, this series nicely cleans up test_mark.sh failures but test_tcp.sh now always fails on debug (slow) kernel builds with:
# TAP version 13
# 1..12
# ok 1 setup network topology
# ok 2 run baseline data traffic
# ok 3 run LAN traffic behind peer1
# ok 4 run iperf throughput
# ok 5 run key rollout
# ok 6 query peers
# ok 7 query missing peer fails
# ok 8 peer lifecycle and key queries
# ok 9 delete peer while traffic
# ok 10 delete stale keys
# ok 11 check timeout behavior
# Checking notifications for peer 3... failed
# 1,9d0
# < {
# < "name": "peer-del-ntf",
# < "msg": {
# < "peer": {
# < "del-reason": "expired",
# < "id": 12
# < }
# < }
# < }
# validate listener output for peer 3: command failed with rc=1: ovpn_compare_ntfs 3
# not ok 12 validate notification output
# # Totals: pass:11 fail:1 xfail:0 xpass:0 skip:0 error:0Similar failure in test_symmetric_id_tcp.sh
Only the debug kernels tho, non-debug kernels seem to pass. So probably some race / slowness.
More runs if you want to compare
https://netdev.bots.linux.dev/contest.html?executor=vmksft-net-extra-dbg&test=test-tcp-sh
This series landed in net-next-2026-04-13--06-00
Antonio Quartulli
maintainerRe: [PATCH net-next 2/5] selftests: ovpn: fail notification check on mismatch
Hi,
Quoted 39 lines · Jakub Kicinski
Quoted 5 lines · On Mon, 13 Apr 2026 00:11:18 +0200 Antonio Quartulli wrote:
compare_ntfsdoesn't fail when expected and received notification streams diverge.Fix this bug by trackink the diff exit status explicitly and return it to the caller so notification mismatches propagate as test failures.
Hm, this series nicely cleans up
test_mark.shfailures buttest_tcp.shnow always fails on debug (slow) kernel builds with:# TAP version 13
# 1..12# ok 1 setup network topology # ok 2 run baseline data traffic # ok 3 run LAN traffic behind peer1 # ok 4 run iperf throughput # ok 5 run key rollout # ok 6 query peers # ok 7 query missing peer fails # ok 8 peer lifecycle and key queries # ok 9 delete peer while traffic # ok 10 delete stale keys # ok 11 check timeout behavior # Checking notifications for peer 3... failed # 1,9d0 # < { # < "name": "peer-del-ntf", # < "msg": { # < "peer": { # < "del-reason": "expired", # < "id": 12 # < } # < } # < } # validate listener output for peer 3: command failed with rc=1: ovpn_compare_ntfs 3 # not ok 12 validate notification output # # Totals: pass:11 fail:1 xfail:0 xpass:0 skip:0 error:0
Quoted 4 lines
Similar failure in
test_symmetric_id_tcp.shOnly the debug kernels tho, non-debug kernels seem to pass. So probably some race / slowness.
We have to extend the internal timeout a bit, because it triggers before the notification is delivered.
Will get this fixed.
Thanks,
Signature · 2 lines
Antonio Quartulli OpenVPN Inc.
Antonio Quartulli
maintainerPATCH 3/5 selftests: ovpn: flatten slurped notification JSON before filtering
In reply to Antonio QuartulliFrom: Ralf Lici <[email protected]>
Notification comparison uses jq -s, which slurps all inputs into an array. Some inputs can be arrays themselves, and applying the .msg.peer filter directly on those entries triggers jq type errors.
Expand any array-valued JSON items returned by jq -s before selecting .msg.peer, so the filter handles both normal notification objects and [] entries without type errors.
--- tools/testing/selftests/net/ovpn/common.sh | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
tools/testing/selftests/net/ovpn/common.sh +2 -1
@@ -15,7 +15,8 @@ SYMMETRIC_ID=${SYMMETRIC_ID:-0} export ID_OFFSET=$(( 9 * (SYMMETRIC_ID == 0) )) -JQ_FILTER='map(select(.msg.peer | has("remote-ipv6") | not)) | +JQ_FILTER='map(if type == "array" then .[] else . end) | + map(select(.msg.peer | has("remote-ipv6") | not)) | map(del(.msg.ifindex)) | sort_by(.msg.peer.id)[]' LAN_IP="11.11.11.11"
Signature · 1 line
2.52.0
Antonio Quartulli
maintainerPATCH 4/5 selftests: ovpn: add namespace to helpers and shared variables
In reply to Antonio QuartulliFrom: Ralf Lici <[email protected]>
Rename common helper entry points and all shared globals in the ovpn selftests to ovpn_ or OVPN_ names so test scripts and wrappers use a single explicit namespace. This is a mechanical refactor only, behavior is unchanged.
--- tools/testing/selftests/net/ovpn/common.sh | 110 +++++++++--------- .../selftests/net/ovpn/test-chachapoly.sh | 2 +- .../net/ovpn/test-close-socket-tcp.sh | 2 +- .../selftests/net/ovpn/test-close-socket.sh | 20 ++-- .../testing/selftests/net/ovpn/test-float.sh | 2 +- tools/testing/selftests/net/ovpn/test-mark.sh | 16 +-- .../net/ovpn/test-symmetric-id-float.sh | 4 +- .../net/ovpn/test-symmetric-id-tcp.sh | 4 +- .../selftests/net/ovpn/test-symmetric-id.sh | 2 +- tools/testing/selftests/net/ovpn/test-tcp.sh | 2 +- tools/testing/selftests/net/ovpn/test.sh | 80 ++++++------- 11 files changed, 122 insertions(+), 122 deletions(-)
tools/testing/selftests/net/ovpn/common.sh +55 -55
@@ -4,35 +4,35 @@ # # Author: Antonio Quartulli <[email protected]> -UDP_PEERS_FILE=${UDP_PEERS_FILE:-udp_peers.txt} -TCP_PEERS_FILE=${TCP_PEERS_FILE:-tcp_peers.txt} +OVPN_UDP_PEERS_FILE=${OVPN_UDP_PEERS_FILE:-udp_peers.txt} +OVPN_TCP_PEERS_FILE=${OVPN_TCP_PEERS_FILE:-tcp_peers.txt} OVPN_CLI=${OVPN_CLI:-./ovpn-cli} -YNL_CLI=${YNL_CLI:-../../../../net/ynl/pyynl/cli.py} -ALG=${ALG:-aes} -PROTO=${PROTO:-UDP} -FLOAT=${FLOAT:-0} -SYMMETRIC_ID=${SYMMETRIC_ID:-0} +OVPN_YNL_CLI=${OVPN_YNL_CLI:-../../../../net/ynl/pyynl/cli.py} +OVPN_ALG=${OVPN_ALG:-aes} +OVPN_PROTO=${OVPN_PROTO:-UDP} +OVPN_FLOAT=${OVPN_FLOAT:-0} +OVPN_SYMMETRIC_ID=${OVPN_SYMMETRIC_ID:-0} -export ID_OFFSET=$(( 9 * (SYMMETRIC_ID == 0) )) +export OVPN_ID_OFFSET=$(( 9 * (OVPN_SYMMETRIC_ID == 0) )) -JQ_FILTER='map(if type == "array" then .[] else . end) | +OVPN_JQ_FILTER='map(if type == "array" then .[] else . end) | map(select(.msg.peer | has("remote-ipv6") | not)) | map(del(.msg.ifindex)) | sort_by(.msg.peer.id)[]' -LAN_IP="11.11.11.11" +OVPN_LAN_IP="11.11.11.11" -declare -A tmp_jsons=() -declare -A listener_pids=() +declare -A OVPN_TMP_JSONS=() +declare -A OVPN_LISTENER_PIDS=() -create_ns() { +ovpn_create_ns() { ip netns add peer${1} } -setup_ns() { +ovpn_setup_ns() { MODE="P2P" if [ ${1} -eq 0 ]; then MODE="MP" - for p in $(seq 1 ${NUM_PEERS}); do + for p in $(seq 1 ${OVPN_NUM_PEERS}); do ip link add veth${p} netns peer0 type veth peer name veth${p} netns peer${p} ip -n peer0 addr add 10.10.${p}.1/24 dev veth${p}
@@ -48,9 +48,9 @@ setup_ns() { ip netns exec peer${1} ${OVPN_CLI} new_iface tun${1} $MODE ip -n peer${1} addr add ${2} dev tun${1} # add a secondary IP to peer 1, to test a LAN behind a client - if [ ${1} -eq 1 -a -n "${LAN_IP}" ]; then - ip -n peer${1} addr add ${LAN_IP} dev tun${1} - ip -n peer0 route add ${LAN_IP} via $(echo ${2} |sed -e s'!/.*!!') dev tun0 + if [ ${1} -eq 1 -a -n "${OVPN_LAN_IP}" ]; then + ip -n peer${1} addr add ${OVPN_LAN_IP} dev tun${1} + ip -n peer0 route add ${OVPN_LAN_IP} via $(echo ${2} |sed -e s'!/.*!!') dev tun0 fi if [ -n "${3}" ]; then ip -n peer${1} link set mtu ${3} dev tun${1}
@@ -58,9 +58,9 @@ setup_ns() { ip -n peer${1} link set tun${1} up } -build_capture_filter() { +ovpn_build_capture_filter() { # match the first four bytes of the openvpn data payload - if [ "${PROTO}" == "UDP" ]; then + if [ "${OVPN_PROTO}" == "UDP" ]; then # For UDP, libpcap transport indexing only works for IPv4, so # use an explicit IPv4 or IPv6 expression based on the peer # address. The IPv6 branch assumes there are no extension
@@ -77,61 +77,61 @@ build_capture_filter() { fi } -setup_listener() { +ovpn_setup_listener() { file=$(mktemp) - PYTHONUNBUFFERED=1 ip netns exec peer${p} ${YNL_CLI} --family ovpn \ + PYTHONUNBUFFERED=1 ip netns exec peer${p} ${OVPN_YNL_CLI} --family ovpn \ --subscribe peers --output-json --duration 40 > ${file} & - listener_pids[$1]=$! - tmp_jsons[$1]="${file}" + OVPN_LISTENER_PIDS[$1]=$! + OVPN_TMP_JSONS[$1]="${file}" } -add_peer() { +ovpn_add_peer() { labels=("ASYMM" "SYMM") - M_ID=${labels[SYMMETRIC_ID]} + M_ID=${labels[OVPN_SYMMETRIC_ID]} - if [ "${PROTO}" == "UDP" ]; then + if [ "${OVPN_PROTO}" == "UDP" ]; then if [ ${1} -eq 0 ]; then ip netns exec peer0 ${OVPN_CLI} new_multi_peer tun0 1 \ - ${M_ID} ${UDP_PEERS_FILE} + ${M_ID} ${OVPN_UDP_PEERS_FILE} - for p in $(seq 1 ${NUM_PEERS}); do - ip netns exec peer0 ${OVPN_CLI} new_key tun0 ${p} 1 0 ${ALG} 0 \ - data64.key + for p in $(seq 1 ${OVPN_NUM_PEERS}); do + ip netns exec peer0 ${OVPN_CLI} new_key tun0 ${p} 1 0 ${OVPN_ALG} \ + 0 data64.key done else - if [ "${SYMMETRIC_ID}" -eq 1 ]; then + if [ "${OVPN_SYMMETRIC_ID}" -eq 1 ]; then PEER_ID=${1} TX_ID="none" else PEER_ID=$(awk "NR == ${1} {print \$2}" \ - ${UDP_PEERS_FILE}) + ${OVPN_UDP_PEERS_FILE}) TX_ID=${1} fi - RADDR=$(awk "NR == ${1} {print \$3}" ${UDP_PEERS_FILE}) - RPORT=$(awk "NR == ${1} {print \$4}" ${UDP_PEERS_FILE}) - LPORT=$(awk "NR == ${1} {print \$6}" ${UDP_PEERS_FILE}) + RADDR=$(awk "NR == ${1} {print \$3}" ${OVPN_UDP_PEERS_FILE}) + RPORT=$(awk "NR == ${1} {print \$4}" ${OVPN_UDP_PEERS_FILE}) + LPORT=$(awk "NR == ${1} {print \$6}" ${OVPN_UDP_PEERS_FILE}) ip netns exec peer${1} ${OVPN_CLI} new_peer tun${1} \ ${PEER_ID} ${TX_ID} ${LPORT} ${RADDR} ${RPORT} ip netns exec peer${1} ${OVPN_CLI} new_key tun${1} \ - ${PEER_ID} 1 0 ${ALG} 1 data64.key + ${PEER_ID} 1 0 ${OVPN_ALG} 1 data64.key fi else if [ ${1} -eq 0 ]; then (ip netns exec peer0 ${OVPN_CLI} listen tun0 1 ${M_ID} \ - ${TCP_PEERS_FILE} && { - for p in $(seq 1 ${NUM_PEERS}); do + ${OVPN_TCP_PEERS_FILE} && { + for p in $(seq 1 ${OVPN_NUM_PEERS}); do ip netns exec peer0 ${OVPN_CLI} new_key tun0 ${p} 1 0 \ - ${ALG} 0 data64.key + ${OVPN_ALG} 0 data64.key done }) & sleep 5 else - if [ "${SYMMETRIC_ID}" -eq 1 ]; then + if [ "${OVPN_SYMMETRIC_ID}" -eq 1 ]; then PEER_ID=${1} TX_ID="none" else PEER_ID=$(awk "NR == ${1} {print \$2}" \ - ${TCP_PEERS_FILE}) + ${OVPN_TCP_PEERS_FILE}) TX_ID=${1} fi ip netns exec peer${1} ${OVPN_CLI} connect tun${1} \
@@ -140,23 +140,23 @@ add_peer() { fi } -compare_ntfs() { +ovpn_compare_ntfs() { local diff_rc=0 local diff_file - if [ ${#tmp_jsons[@]} -gt 0 ]; then + if [ ${#OVPN_TMP_JSONS[@]} -gt 0 ]; then suffix="" - [ "${SYMMETRIC_ID}" -eq 1 ] && suffix="${suffix}-symm" - [ "$FLOAT" == 1 ] && suffix="${suffix}-float" + [ "${OVPN_SYMMETRIC_ID}" -eq 1 ] && suffix="${suffix}-symm" + [ "$OVPN_FLOAT" == 1 ] && suffix="${suffix}-float" expected="json/peer${1}${suffix}.json" - received="${tmp_jsons[$1]}" + received="${OVPN_TMP_JSONS[$1]}" diff_file=$(mktemp) - kill -TERM ${listener_pids[$1]} || true - wait ${listener_pids[$1]} || true + kill -TERM ${OVPN_LISTENER_PIDS[$1]} || true + wait ${OVPN_LISTENER_PIDS[$1]} || true printf "Checking notifications for peer ${1}... " - if diff <(jq -s "${JQ_FILTER}" ${expected}) \ - <(jq -s "${JQ_FILTER}" ${received}) >"${diff_file}" 2>&1; then + if diff <(jq -s "${OVPN_JQ_FILTER}" ${expected}) \ + <(jq -s "${OVPN_JQ_FILTER}" ${received}) >"${diff_file}" 2>&1; then echo "OK" else diff_rc=$?
@@ -171,7 +171,7 @@ compare_ntfs() { return "${diff_rc}" } -cleanup() { +ovpn_cleanup() { # some ovpn-cli processes sleep in background so they need manual poking killall $(basename ${OVPN_CLI}) 2>/dev/null || true
@@ -188,8 +188,8 @@ cleanup() { done } -if [ "${PROTO}" == "UDP" ]; then - NUM_PEERS=${NUM_PEERS:-$(wc -l ${UDP_PEERS_FILE} | awk '{print $1}')} +if [ "${OVPN_PROTO}" == "UDP" ]; then + OVPN_NUM_PEERS=${OVPN_NUM_PEERS:-$(wc -l ${OVPN_UDP_PEERS_FILE} | awk '{print $1}')} else - NUM_PEERS=${NUM_PEERS:-$(wc -l ${TCP_PEERS_FILE} | awk '{print $1}')} + OVPN_NUM_PEERS=${OVPN_NUM_PEERS:-$(wc -l ${OVPN_TCP_PEERS_FILE} | awk '{print $1}')} fi
tools/testing/selftests/net/ovpn/test-chachapoly.sh +1 -1
@@ -4,6 +4,6 @@ # # Author: Antonio Quartulli <[email protected]> -ALG="chachapoly" +OVPN_ALG="chachapoly" source test.sh
tools/testing/selftests/net/ovpn/test-close-socket-tcp.sh +1 -1
@@ -4,6 +4,6 @@ # # Author: Antonio Quartulli <[email protected]> -PROTO="TCP" +OVPN_PROTO="TCP" source test-close-socket.sh
tools/testing/selftests/net/ovpn/test-close-socket.sh +10 -10
@@ -9,30 +9,30 @@ set -e source ./common.sh -cleanup +ovpn_cleanup modprobe -q ovpn || true -for p in $(seq 0 ${NUM_PEERS}); do - create_ns ${p} +for p in $(seq 0 ${OVPN_NUM_PEERS}); do + ovpn_create_ns ${p} done -for p in $(seq 0 ${NUM_PEERS}); do - setup_ns ${p} 5.5.5.$((${p} + 1))/24 +for p in $(seq 0 ${OVPN_NUM_PEERS}); do + ovpn_setup_ns ${p} 5.5.5.$((${p} + 1))/24 done -for p in $(seq 0 ${NUM_PEERS}); do - add_peer ${p} +for p in $(seq 0 ${OVPN_NUM_PEERS}); do + ovpn_add_peer ${p} done -for p in $(seq 1 ${NUM_PEERS}); do +for p in $(seq 1 ${OVPN_NUM_PEERS}); do ip netns exec peer0 ${OVPN_CLI} set_peer tun0 ${p} 60 120 ip netns exec peer${p} ${OVPN_CLI} set_peer tun${p} $((${p}+9)) 60 120 done sleep 1 -for p in $(seq 1 ${NUM_PEERS}); do +for p in $(seq 1 ${OVPN_NUM_PEERS}); do ip netns exec peer0 ping -qfc 500 -w 3 5.5.5.$((${p} + 1)) done
@@ -40,6 +40,6 @@ ip netns exec peer0 iperf3 -1 -s & sleep 1 ip netns exec peer1 iperf3 -Z -t 3 -c 5.5.5.1 -cleanup +ovpn_cleanup modprobe -r ovpn || true
tools/testing/selftests/net/ovpn/test-float.sh +1 -1
@@ -4,6 +4,6 @@ # # Author: Antonio Quartulli <[email protected]> -FLOAT="1" +OVPN_FLOAT="1" source test.sh
tools/testing/selftests/net/ovpn/test-mark.sh +8 -8
@@ -12,29 +12,29 @@ MARK=1056 source ./common.sh -cleanup +ovpn_cleanup modprobe -q ovpn || true -for p in $(seq 0 "${NUM_PEERS}"); do - create_ns "${p}" +for p in $(seq 0 "${OVPN_NUM_PEERS}"); do + ovpn_create_ns "${p}" done for p in $(seq 0 3); do - setup_ns "${p}" 5.5.5.$((p + 1))/24 + ovpn_setup_ns "${p}" 5.5.5.$((p + 1))/24 done # add peer0 with mark ip netns exec peer0 "${OVPN_CLI}" new_multi_peer tun0 1 ASYMM \ - "${UDP_PEERS_FILE}" \ + "${OVPN_UDP_PEERS_FILE}" \ ${MARK} for p in $(seq 1 3); do - ip netns exec peer0 "${OVPN_CLI}" new_key tun0 "${p}" 1 0 "${ALG}" 0 \ + ip netns exec peer0 "${OVPN_CLI}" new_key tun0 "${p}" 1 0 "${OVPN_ALG}" 0 \ data64.key done for p in $(seq 1 3); do - add_peer "${p}" + ovpn_add_peer "${p}" done for p in $(seq 1 3); do
@@ -91,6 +91,6 @@ for p in $(seq 1 3); do ip netns exec peer0 ping -qfc 500 -w 3 5.5.5.$((p + 1)) done -cleanup +ovpn_cleanup modprobe -r ovpn || true
tools/testing/selftests/net/ovpn/test-symmetric-id-float.sh +2 -2
@@ -5,7 +5,7 @@ # Author: Ralf Lici <[email protected]> # Antonio Quartulli <[email protected]> -SYMMETRIC_ID="1" -FLOAT="1" +OVPN_SYMMETRIC_ID="1" +OVPN_FLOAT="1" source test.sh
tools/testing/selftests/net/ovpn/test-symmetric-id-tcp.sh +2 -2
@@ -5,7 +5,7 @@ # Author: Ralf Lici <[email protected]> # Antonio Quartulli <[email protected]> -PROTO="TCP" -SYMMETRIC_ID=1 +OVPN_PROTO="TCP" +OVPN_SYMMETRIC_ID=1 source test.sh
tools/testing/selftests/net/ovpn/test-symmetric-id.sh +1 -1
@@ -5,6 +5,6 @@ # Author: Ralf Lici <[email protected]> # Antonio Quartulli <[email protected]> -SYMMETRIC_ID="1" +OVPN_SYMMETRIC_ID="1" source test.sh
tools/testing/selftests/net/ovpn/test-tcp.sh +1 -1
@@ -4,6 +4,6 @@ # # Author: Antonio Quartulli <[email protected]> -PROTO="TCP" +OVPN_PROTO="TCP" source test.sh
tools/testing/selftests/net/ovpn/test.sh +40 -40
174 lines not on this page · raw message
Signature · 1 line
2.52.0
Antonio Quartulli
maintainerPATCH 5/5 selftests: ovpn: align command flow with TAP
In reply to Antonio QuartulliFrom: Ralf Lici <[email protected]>
Restructure ovpn selftests into using the TAP infrastructure: split each test in stages, execute stage bodies with fail-fast semantics, and emit KTAP pass/fail for each stage.
Centralize behavior control in common.sh and makes the scripts use dedicated wrappers for required-success, expected-failure, and non-fatal commands. Also add the OVPN_VERBOSE mode that exposes captured command output for debugging.
This way tests won't hang anymore in case of failure when executed within the CI machinery.
This change also makes default OVPN_CLI and YNL_CLI resolution independent from the caller CWD by anchoring both to COMMON_DIR, so behavior is stable across direct execution and run_tests-style execution.
--- tools/testing/selftests/net/ovpn/common.sh | 168 ++++++- .../selftests/net/ovpn/test-close-socket.sh | 81 +++- tools/testing/selftests/net/ovpn/test-mark.sh | 219 +++++---- tools/testing/selftests/net/ovpn/test.sh | 415 ++++++++++++------ 4 files changed, 624 insertions(+), 259 deletions(-)
tools/testing/selftests/net/ovpn/common.sh +154 -14
@@ -4,14 +4,18 @@ # # Author: Antonio Quartulli <[email protected]> +OVPN_COMMON_DIR=$(dirname "$(readlink -f "${BASH_SOURCE[0]}")") +source "$OVPN_COMMON_DIR/../../kselftest/ktap_helpers.sh" + OVPN_UDP_PEERS_FILE=${OVPN_UDP_PEERS_FILE:-udp_peers.txt} OVPN_TCP_PEERS_FILE=${OVPN_TCP_PEERS_FILE:-tcp_peers.txt} -OVPN_CLI=${OVPN_CLI:-./ovpn-cli} -OVPN_YNL_CLI=${OVPN_YNL_CLI:-../../../../net/ynl/pyynl/cli.py} +OVPN_CLI=${OVPN_CLI:-${OVPN_COMMON_DIR}/ovpn-cli} +OVPN_YNL_CLI=${OVPN_YNL_CLI:-${OVPN_COMMON_DIR}/../../../../net/ynl/pyynl/cli.py} OVPN_ALG=${OVPN_ALG:-aes} OVPN_PROTO=${OVPN_PROTO:-UDP} OVPN_FLOAT=${OVPN_FLOAT:-0} OVPN_SYMMETRIC_ID=${OVPN_SYMMETRIC_ID:-0} +OVPN_VERBOSE=${OVPN_VERBOSE:-0} export OVPN_ID_OFFSET=$(( 9 * (OVPN_SYMMETRIC_ID == 0) ))
@@ -22,6 +26,110 @@ OVPN_LAN_IP="11.11.11.11" declare -A OVPN_TMP_JSONS=() declare -A OVPN_LISTENER_PIDS=() +OVPN_CURRENT_STAGE="" + +ovpn_is_verbose() { + [[ "${OVPN_VERBOSE}" == "1" ]] +} + +ovpn_log() { + ovpn_is_verbose || return 0 + printf '%s\n' "$*" +} + +ovpn_print_cmd_output() { + local output_file="$1" + local line + + [[ -s "${output_file}" ]] || return 0 + + while IFS= read -r line; do + ovpn_log "${line}" + done < "${output_file}" +} + +ovpn_cmd_run() { + local mode="$1" + local label="$2" + local output_file + local rc + local ret=0 + + shift 2 + + output_file=$(mktemp) + if "$@" >"${output_file}" 2>&1; then + rc=0 + else + rc=$? + fi + + case "${mode}" in + ok) + if [[ "${rc}" -ne 0 ]]; then + cat "${output_file}" + printf '%s\n' "${label}: command failed with rc=${rc}: $*" + ret="${rc}" + fi + ;; + mayfail) + ;; + fail) + [[ "${rc}" -eq 0 ]] && ret=1 + ;; + esac + + if ovpn_is_verbose && [[ "${rc}" -eq 0 || "${mode}" != "ok" ]]; then + ovpn_print_cmd_output "${output_file}" + fi + + rm -f "${output_file}" + return "${ret}" +} + +ovpn_cmd_ok() { + ovpn_cmd_run ok "$@" +} + +ovpn_cmd_mayfail() { + ovpn_cmd_run mayfail "$@" +} + +ovpn_cmd_fail() { + ovpn_cmd_run fail "$@" +} + +ovpn_run_bg() { + local pid_var="$1" + + shift + if ovpn_is_verbose; then + "$@" & + else + "$@" >/dev/null 2>&1 & + fi + + printf -v "${pid_var}" '%s' "$!" +} + +ovpn_run_stage() { + local label="$1" + + shift + OVPN_CURRENT_STAGE="${label}" + "$@" + OVPN_CURRENT_STAGE="" + ktap_test_pass "${label}" +} + +ovpn_stage_err() { + # ERR trap is global under set -eE: only report failures that happen + # while ovpn_run_stage() is actively executing a stage body. + if [[ -n "${OVPN_CURRENT_STAGE}" ]]; then + ktap_test_fail "${OVPN_CURRENT_STAGE}" + OVPN_CURRENT_STAGE="" + fi +} ovpn_create_ns() { ip netns add peer${1}
@@ -78,11 +186,14 @@ ovpn_build_capture_filter() { } ovpn_setup_listener() { + local peer="$1" + local file + file=$(mktemp) - PYTHONUNBUFFERED=1 ip netns exec peer${p} ${OVPN_YNL_CLI} --family ovpn \ - --subscribe peers --output-json --duration 40 > ${file} & - OVPN_LISTENER_PIDS[$1]=$! - OVPN_TMP_JSONS[$1]="${file}" + PYTHONUNBUFFERED=1 ip netns exec "peer${peer}" "${OVPN_YNL_CLI}" --family ovpn \ + --subscribe peers --output-json --duration 40 > "${file}" 2>/dev/null & + OVPN_LISTENER_PIDS["${peer}"]=$! + OVPN_TMP_JSONS["${peer}"]="${file}" } ovpn_add_peer() {
@@ -152,8 +263,8 @@ ovpn_compare_ntfs() { received="${OVPN_TMP_JSONS[$1]}" diff_file=$(mktemp) - kill -TERM ${OVPN_LISTENER_PIDS[$1]} || true - wait ${OVPN_LISTENER_PIDS[$1]} || true + kill -TERM ${OVPN_LISTENER_PIDS[$1]} 2>/dev/null || true + wait ${OVPN_LISTENER_PIDS[$1]} 2>/dev/null || true printf "Checking notifications for peer ${1}... " if diff <(jq -s "${OVPN_JQ_FILTER}" ${expected}) \ <(jq -s "${OVPN_JQ_FILTER}" ${received}) >"${diff_file}" 2>&1; then
@@ -171,20 +282,49 @@ ovpn_compare_ntfs() { return "${diff_rc}" } +ovpn_stop_listener() { + local peer="$1" + local pid="${OVPN_LISTENER_PIDS[$peer]:-}" + local json="${OVPN_TMP_JSONS[$peer]:-}" + + if [[ -n "${pid}" ]]; then + kill -TERM "${pid}" 2>/dev/null || true + wait "${pid}" 2>/dev/null || true + unset "OVPN_LISTENER_PIDS[$peer]" + fi + + if [[ -n "${json}" ]]; then + rm -f "${json}" || true + unset "OVPN_TMP_JSONS[$peer]" + fi +} + +ovpn_cleanup_peer_ns() { + local peer="$1" + + if ! ip netns list | grep -qx "${peer}"; then + return 0 + fi + + ip -n "${peer}" link set tun${peer#peer} down 2>/dev/null || true + ip netns exec "${peer}" ${OVPN_CLI} del_iface tun${peer#peer} \ + 1>/dev/null 2>&1 || true + ip netns del "${peer}" 2>/dev/null || true +} + ovpn_cleanup() { # some ovpn-cli processes sleep in background so they need manual poking - killall $(basename ${OVPN_CLI}) 2>/dev/null || true + killall "$(basename "${OVPN_CLI}")" 2>/dev/null || true - # netns peer0 is deleted without erasing ifaces first - for p in $(seq 1 10); do - ip -n peer${p} link set tun${p} down 2>/dev/null || true - ip netns exec peer${p} ${OVPN_CLI} del_iface tun${p} 2>/dev/null || true + for peer in "${!OVPN_LISTENER_PIDS[@]}"; do + ovpn_stop_listener "${peer}" 2>/dev/null done + for p in $(seq 1 10); do ip -n peer0 link del veth${p} 2>/dev/null || true done for p in $(seq 0 10); do - ip netns del peer${p} 2>/dev/null || true + ovpn_cleanup_peer_ns "peer${p}" 2>/dev/null done }
tools/testing/selftests/net/ovpn/test-close-socket.sh +58 -23
95 lines not on this page · raw message
tools/testing/selftests/net/ovpn/test-mark.sh +140 -79
231 lines not on this page · raw message
tools/testing/selftests/net/ovpn/test.sh +272 -143
433 lines not on this page · raw message
Signature · 1 line
2.52.0
Jakub Kicinski
maintainerRe: [PATCH net-next 5/5] selftests: ovpn: align command flow with TAP
This is an AI-generated review of your patch. The human sending this email says: "The second one looks legit, would you prefer to follow up or respin?"
---
selftests: ovpn: align command flow with TAP
This commit restructures the ovpn selftests to use the TAP infrastructure, splitting each test into stages with KTAP output, adding command wrappers, and centralizing behavior control in common.sh.
Quoted 4 lines
tools/testing/selftests/net/ovpn/common.sh +0
-0
[ ... ]
tools/testing/selftests/net/ovpn/common.sh ovpn_compare_ntfs() { · line 268
Quoted 9 lines
tools/testing/selftests/net/ovpn/common.sh +2
-2@@ -152,8 +263,8 @@ ovpn_compare_ntfs() { received="${OVPN_TMP_JSONS[$1]}" diff_file=$(mktemp) - kill -TERM ${OVPN_LISTENER_PIDS[$1]} || true - wait ${OVPN_LISTENER_PIDS[$1]} || true + kill -TERM ${OVPN_LISTENER_PIDS[$1]} 2>/dev/null || true + wait ${OVPN_LISTENER_PIDS[$1]} 2>/dev/null || true printf "Checking notifications for peer ${1}... "
Does this leave the reaped PID in OVPN_LISTENER_PIDS?
Later, ovpn_cleanup() calls ovpn_stop_listener() which iterates over the array and issues another kill -TERM on the same PID. Since the process was already reaped by the wait here, could the OS recycle the PID, potentially causing the second kill to terminate an unrelated system process?
[ ... ]
tools/testing/selftests/net/ovpn/common.sh ovpn_compare_ntfs() { · line 307
Quoted 6 lines
tools/testing/selftests/net/ovpn/common.sh +6
-0+ovpn_cleanup_peer_ns() { + local peer="$1" + + if ! ip netns list | grep -qx "${peer}"; then + return 0 + fi
Can this fail to match and permanently leak network namespaces?
When virtual interfaces are moved into namespaces during setup, ip netns list often includes an internal ID in its output, such as:
peer0 (id: 0)
Because grep is using the -x flag to enforce an exact whole-line match, it appears this will fail to match peer0 and return early, skipping the subsequent namespace deletion.
[ ... ]
tools/testing/selftests/net/ovpn/test-close-socket.sh set -e · line 10
Quoted 7 lines
tools/testing/selftests/net/ovpn/test-close-socket.sh +0
-0@@ -9,37 +9,72 @@ set -e source ./common.sh
Is test-close-socket.sh missing the set -eE flag and the ovpn_stage_err ERR trap?
The other test scripts were updated to use set -eE and register the trap, which handles emitting the KTAP failure directive. If a command fails here, will set -e cause the script to exit immediately and bypass the KTAP failure reporting entirely?
Antonio Quartulli
maintainerRe: [PATCH net-next 5/5] selftests: ovpn: align command flow with TAP
Hi,
Quoted 3 lines · Jakub Kicinski
This is an AI-generated review of your patch. The human sending this email says: "The second one looks legit, would you prefer to follow up or respin?"
Will respin, since we also have to fix the timeout in 2/5.
Thanks,
Signature · 2 lines
Antonio Quartulli OpenVPN Inc.