ovpn: new features + kselftests
Subsystems (5)
Antonio Quartulli
maintainercover ovpn: new features + kselftests
Dear all,
This patchset is just a respin of my latest PR to net-next, including all modifications requested by Jakub and Sabrina.
However, this time I am also adding patches targeting selftest/net/ovpn, as they come in handy for testing the new features (originally I wanted them to be a separate PR, but it doesn't indeed make a lot of sense).
This said, since these kselftest patches are quite invasive, I didn't feel confident with sending them in a PR right away, but I rather wanted some feedback from Sabrina and Shuah first, if possible.
So here we go.
Once I get some approval on this batch, I'll send then send them all to net-next again as PRv2.
Thanks a lot!
Regards,
Antonio Quartulli (1):
selftests: ovpn: allow compiling ovpn-cli.c with mbedtls3
Qingfang Deng (1):
ovpn: pktid: use bitops.h API
Ralf Lici (10):
selftests: ovpn: add notification parsing and matching
ovpn: notify userspace on client float event
ovpn: add support for asymmetric peer IDs
selftests: ovpn: check asymmetric peer-id
selftests: ovpn: add test for the FW mark feature
ovpn: consolidate crypto allocations in one chunk
ovpn: use bound device in UDP when available
selftests: ovpn: add test for bound device
ovpn: use bound address in UDP when available
selftests: ovpn: add test for bound address
Sabrina Dubroca (1):
ovpn: use correct array size to parse nested attributes in
ovpn_nl_key_swap_doit
Documentation/netlink/specs/ovpn.yaml | 23 +- drivers/net/ovpn/crypto_aead.c | 162 +++++++--- drivers/net/ovpn/io.c | 8 +- drivers/net/ovpn/netlink-gen.c | 13 +- drivers/net/ovpn/netlink-gen.h | 6 +- drivers/net/ovpn/netlink.c | 98 +++++- drivers/net/ovpn/netlink.h | 2 + drivers/net/ovpn/peer.c | 6 + drivers/net/ovpn/peer.h | 4 +- drivers/net/ovpn/pktid.c | 11 +- drivers/net/ovpn/pktid.h | 2 +- drivers/net/ovpn/skb.h | 13 +- drivers/net/ovpn/udp.c | 10 +- include/uapi/linux/ovpn.h | 2 + tools/testing/selftests/net/ovpn/Makefile | 17 +- .../selftests/net/ovpn/check_requirements.py | 37 +++ tools/testing/selftests/net/ovpn/common.sh | 60 +++- tools/testing/selftests/net/ovpn/data64.key | 6 +- .../selftests/net/ovpn/json/peer0-float.json | 9 + .../selftests/net/ovpn/json/peer0.json | 6 + .../selftests/net/ovpn/json/peer1-float.json | 1 + .../selftests/net/ovpn/json/peer1.json | 1 + .../selftests/net/ovpn/json/peer2-float.json | 1 + .../selftests/net/ovpn/json/peer2.json | 1 + .../selftests/net/ovpn/json/peer3-float.json | 1 + .../selftests/net/ovpn/json/peer3.json | 1 + .../selftests/net/ovpn/json/peer4-float.json | 1 + .../selftests/net/ovpn/json/peer4.json | 1 + .../selftests/net/ovpn/json/peer5-float.json | 1 + .../selftests/net/ovpn/json/peer5.json | 1 + .../selftests/net/ovpn/json/peer6-float.json | 1 + .../selftests/net/ovpn/json/peer6.json | 1 + tools/testing/selftests/net/ovpn/ovpn-cli.c | 281 +++++++++++------- .../selftests/net/ovpn/requirements.txt | 1 + .../testing/selftests/net/ovpn/tcp_peers.txt | 11 +- .../selftests/net/ovpn/test-bind-addr.sh | 10 + tools/testing/selftests/net/ovpn/test-bind.sh | 117 ++++++++ .../selftests/net/ovpn/test-close-socket.sh | 2 +- tools/testing/selftests/net/ovpn/test-mark.sh | 81 +++++ tools/testing/selftests/net/ovpn/test.sh | 57 +++- .../testing/selftests/net/ovpn/udp_peers.txt | 12 +- 41 files changed, 855 insertions(+), 224 deletions(-) create mode 100755 tools/testing/selftests/net/ovpn/check_requirements.py create mode 100644 tools/testing/selftests/net/ovpn/json/peer0-float.json create mode 100644 tools/testing/selftests/net/ovpn/json/peer0.json create mode 120000 tools/testing/selftests/net/ovpn/json/peer1-float.json create mode 100644 tools/testing/selftests/net/ovpn/json/peer1.json create mode 120000 tools/testing/selftests/net/ovpn/json/peer2-float.json create mode 100644 tools/testing/selftests/net/ovpn/json/peer2.json create mode 120000 tools/testing/selftests/net/ovpn/json/peer3-float.json create mode 100644 tools/testing/selftests/net/ovpn/json/peer3.json create mode 120000 tools/testing/selftests/net/ovpn/json/peer4-float.json create mode 100644 tools/testing/selftests/net/ovpn/json/peer4.json create mode 120000 tools/testing/selftests/net/ovpn/json/peer5-float.json create mode 100644 tools/testing/selftests/net/ovpn/json/peer5.json create mode 120000 tools/testing/selftests/net/ovpn/json/peer6-float.json create mode 100644 tools/testing/selftests/net/ovpn/json/peer6.json create mode 120000 tools/testing/selftests/net/ovpn/requirements.txt create mode 100755 tools/testing/selftests/net/ovpn/test-bind-addr.sh create mode 100755 tools/testing/selftests/net/ovpn/test-bind.sh create mode 100755 tools/testing/selftests/net/ovpn/test-mark.sh
Signature · 1 line
2.51.2
Antonio Quartulli
maintainerRFC 1/13 selftests: ovpn: allow compiling ovpn-cli.c with mbedtls3
mbedtls 3 installs headers and calls the shared object differently than version 2, therefore we must now rely on pkgconfig to fill the right C/LDFLAGS.
Moreover the mbedtls3 library expects any base64 file to have their content on one line.
Since this change does no break older versions, let's change the sample key file format and make mbedtls3 happy.
--- tools/testing/selftests/net/ovpn/Makefile | 14 ++++++++++---- tools/testing/selftests/net/ovpn/data64.key | 6 +----- 2 files changed, 11 insertions(+), 9 deletions(-)
tools/testing/selftests/net/ovpn/Makefile +10 -4
@@ -2,19 +2,25 @@ # Copyright (C) 2020-2025 OpenVPN, Inc. # CFLAGS = -pedantic -Wextra -Wall -Wl,--no-as-needed -g -O0 -ggdb $(KHDR_INCLUDES) +CFLAGS += $(shell pkg-config --cflags mbedcrypto-3 mbedtls-3 2>/dev/null) + VAR_CFLAGS = $(shell pkg-config --cflags libnl-3.0 libnl-genl-3.0 2>/dev/null) ifeq ($(VAR_CFLAGS),) VAR_CFLAGS = -I/usr/include/libnl3 endif CFLAGS += $(VAR_CFLAGS) +MTLS_LDLIBS= $(shell pkg-config --libs mbedcrypto-3 mbedtls-3 2>/dev/null) +ifeq ($(MTLS_LDLIBS),) +MTLS_LDLIBS = -lmbedtls -lmbedcrypto +endif +LDLIBS += $(MTLS_LDLIBS) -LDLIBS = -lmbedtls -lmbedcrypto -VAR_LDLIBS = $(shell pkg-config --libs libnl-3.0 libnl-genl-3.0 2>/dev/null) +NL_LDLIBS = $(shell pkg-config --libs libnl-3.0 libnl-genl-3.0 2>/dev/null) ifeq ($(VAR_LDLIBS),) -VAR_LDLIBS = -lnl-genl-3 -lnl-3 +NL_LDLIBS = -lnl-genl-3 -lnl-3 endif -LDLIBS += $(VAR_LDLIBS) +LDLIBS += $(NL_LDLIBS) TEST_FILES = common.sh
tools/testing/selftests/net/ovpn/data64.key +1 -5
@@ -1,5 +1 @@ -jRqMACN7d7/aFQNT8S7jkrBD8uwrgHbG5OQZP2eu4R1Y7tfpS2bf5RHv06Vi163CGoaIiTX99R3B -ia9ycAH8Wz1+9PWv51dnBLur9jbShlgZ2QHLtUc4a/gfT7zZwULXuuxdLnvR21DDeMBaTbkgbai9 -uvAa7ne1liIgGFzbv+Bas4HDVrygxIxuAnP5Qgc3648IJkZ0QEXPF+O9f0n5+QIvGCxkAUVx+5K6 -KIs+SoeWXnAopELmoGSjUpFtJbagXK82HfdqpuUxT2Tnuef0/14SzVE/vNleBNu2ZbyrSAaah8tE -BofkPJUBFY+YQcfZNM5Dgrw3i+Bpmpq/gpdg5w== +jRqMACN7d7/aFQNT8S7jkrBD8uwrgHbG5OQZP2eu4R1Y7tfpS2bf5RHv06Vi163CGoaIiTX99R3Bia9ycAH8Wz1+9PWv51dnBLur9jbShlgZ2QHLtUc4a/gfT7zZwULXuuxdLnvR21DDeMBaTbkgbai9uvAa7ne1liIgGFzbv+Bas4HDVrygxIxuAnP5Qgc3648IJkZ0QEXPF+O9f0n5+QIvGCxkAUVx+5K6KIs+SoeWXnAopELmoGSjUpFtJbagXK82HfdqpuUxT2Tnuef0/14SzVE/vNleBNu2ZbyrSAaah8tEBofkPJUBFY+YQcfZNM5Dgrw3i+Bpmpq/gpdg5w==
Signature · 1 line
2.51.2
Antonio Quartulli
maintainerRFC 2/13 selftests: ovpn: add notification parsing and matching
In reply to Antonio QuartulliFrom: Ralf Lici <[email protected]>
To verify that netlink notifications are correctly emitted and contain the expected fields, this commit uses the tools/net/ynl/pyynl/cli.py script to create multicast listeners. These listeners record the captured notifications to a JSON file, which is later compared to the expected output.
Since this change introduces additional dependencies (jq, pyyaml, jsonschema), the tests are configured to check for their presence and conditionally skip the notification check if they are missing.
--- .../selftests/net/ovpn/check_requirements.py | 37 +++++++++++++++++++ tools/testing/selftests/net/ovpn/common.sh | 34 +++++++++++++++++ .../selftests/net/ovpn/json/peer0-float.json | 9 +++++ .../selftests/net/ovpn/json/peer0.json | 6 +++ .../selftests/net/ovpn/json/peer1-float.json | 1 + .../selftests/net/ovpn/json/peer1.json | 1 + .../selftests/net/ovpn/json/peer2-float.json | 1 + .../selftests/net/ovpn/json/peer2.json | 1 + .../selftests/net/ovpn/json/peer3-float.json | 1 + .../selftests/net/ovpn/json/peer3.json | 1 + .../selftests/net/ovpn/json/peer4-float.json | 1 + .../selftests/net/ovpn/json/peer4.json | 1 + .../selftests/net/ovpn/json/peer5-float.json | 1 + .../selftests/net/ovpn/json/peer5.json | 1 + .../selftests/net/ovpn/json/peer6-float.json | 1 + .../selftests/net/ovpn/json/peer6.json | 1 + .../selftests/net/ovpn/requirements.txt | 1 + .../testing/selftests/net/ovpn/tcp_peers.txt | 1 + tools/testing/selftests/net/ovpn/test.sh | 10 +++++ 19 files changed, 110 insertions(+) create mode 100755 tools/testing/selftests/net/ovpn/check_requirements.py create mode 100644 tools/testing/selftests/net/ovpn/json/peer0-float.json create mode 100644 tools/testing/selftests/net/ovpn/json/peer0.json create mode 120000 tools/testing/selftests/net/ovpn/json/peer1-float.json create mode 100644 tools/testing/selftests/net/ovpn/json/peer1.json create mode 120000 tools/testing/selftests/net/ovpn/json/peer2-float.json create mode 100644 tools/testing/selftests/net/ovpn/json/peer2.json create mode 120000 tools/testing/selftests/net/ovpn/json/peer3-float.json create mode 100644 tools/testing/selftests/net/ovpn/json/peer3.json create mode 120000 tools/testing/selftests/net/ovpn/json/peer4-float.json create mode 100644 tools/testing/selftests/net/ovpn/json/peer4.json create mode 120000 tools/testing/selftests/net/ovpn/json/peer5-float.json create mode 100644 tools/testing/selftests/net/ovpn/json/peer5.json create mode 120000 tools/testing/selftests/net/ovpn/json/peer6-float.json create mode 100644 tools/testing/selftests/net/ovpn/json/peer6.json create mode 120000 tools/testing/selftests/net/ovpn/requirements.txt
tools/testing/selftests/net/ovpn/check_requirements.py new file +37 -0
@@ -0,0 +1,37 @@ +#!/usr/bin/env python3 + +from importlib.metadata import version, PackageNotFoundError +from packaging.requirements import Requirement +from packaging.version import Version, InvalidVersion +from pathlib import Path +import sys + +def check_requirements(requirements_path="requirements.txt"): + issues = [] + with open(requirements_path) as f: + for line in f: + line = line.strip() + if not line or line.startswith("#"): + continue + try: + req = Requirement(line) + try: + installed_version = Version(version(req.name)) + if req.specifier and installed_version not in req.specifier: + issues.append(f"{req.name}=={installed_version} does not satisfy {req.specifier}") + except PackageNotFoundError: + issues.append(f"{req.name} is not installed") + except InvalidVersion: + issues.append(f"{req.name} has an invalid installed version") + except Exception as e: + issues.append(f"Could not parse requirement line: '{line}' ({e})") + return issues + +problems = check_requirements() +if problems: + print("Dependency issues found:") + for p in problems: + print(" -", p) + sys.exit(1) +else: + sys.exit(0)
tools/testing/selftests/net/ovpn/common.sh +34 -0
@@ -7,12 +7,17 @@ UDP_PEERS_FILE=${UDP_PEERS_FILE:-udp_peers.txt} TCP_PEERS_FILE=${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} +JQ_FILTER='map(select(.msg.peer | has("remote-ipv6") | not)) | map(del(.msg.ifindex)) | sort_by(.msg.peer.id)[]' LAN_IP="11.11.11.11" +declare -A tmp_jsons=() +declare -A listener_pids=() + create_ns() { ip netns add peer${1} }
@@ -48,6 +53,18 @@ setup_ns() { ip -n peer${1} link set tun${1} up } +has_listener_requirements() { + ./check_requirements.py && jq --version >/dev/null 2>&1 +} + +setup_listener() { + file=$(mktemp) + PYTHONUNBUFFERED=1 ip netns exec peer${p} ${YNL_CLI} --family ovpn \ + --subscribe peers --output-json --duration 40 > ${file} & + listener_pids[$1]=$! + tmp_jsons[$1]="${file}" +} + add_peer() { if [ "${PROTO}" == "UDP" ]; then if [ ${1} -eq 0 ]; then
@@ -82,6 +99,23 @@ add_peer() { fi } +compare_ntfs() { + if [ ${#tmp_jsons[@]} -gt 0 ]; then + [ "$FLOAT" == 1 ] && suffix="-float" + expexted="json/peer${1}${suffix}.json" + received="${tmp_jsons[$1]}" + + kill -TERM ${listener_pids[$1]} || true + wait ${listener_pids[$1]} || true + printf "Checking notifications for peer ${1}... " + diff <(jq -s "${JQ_FILTER}" ${expexted}) \ + <(jq -s "${JQ_FILTER}" ${received}) + echo "OK" + + rm -f ${received} || true + fi +} + cleanup() { # some ovpn-cli processes sleep in background so they need manual poking killall $(basename ${OVPN_CLI}) 2>/dev/null || true
tools/testing/selftests/net/ovpn/json/peer0-float.json new file +9 -0
@@ -0,0 +1,9 @@ +{"name": "peer-float-ntf", "msg": {"ifindex": 0, "peer": {"id": 1, "remote-ipv4": "10.10.1.3", "remote-port": 1}}} +{"name": "peer-float-ntf", "msg": {"ifindex": 0, "peer": {"id": 2, "remote-ipv4": "10.10.2.3", "remote-port": 1}}} +{"name": "peer-float-ntf", "msg": {"ifindex": 0, "peer": {"id": 3, "remote-ipv4": "10.10.3.3", "remote-port": 1}}} +{"name": "peer-del-ntf", "msg": {"ifindex": 0, "peer": {"del-reason": "userspace", "id": 1}}} +{"name": "peer-del-ntf", "msg": {"ifindex": 0, "peer": {"del-reason": "userspace", "id": 2}}} +{"name": "peer-del-ntf", "msg": {"ifindex": 0, "peer": {"del-reason": "expired", "id": 3}}} +{"name": "peer-del-ntf", "msg": {"ifindex": 0, "peer": {"del-reason": "expired", "id": 4}}} +{"name": "peer-del-ntf", "msg": {"ifindex": 0, "peer": {"del-reason": "expired", "id": 5}}} +{"name": "peer-del-ntf", "msg": {"ifindex": 0, "peer": {"del-reason": "expired", "id": 6}}}
tools/testing/selftests/net/ovpn/json/peer0.json new file +6 -0
@@ -0,0 +1,6 @@ +{"name": "peer-del-ntf", "msg": {"ifindex": 0, "peer": {"del-reason": "userspace", "id": 1}}} +{"name": "peer-del-ntf", "msg": {"ifindex": 0, "peer": {"del-reason": "userspace", "id": 2}}} +{"name": "peer-del-ntf", "msg": {"ifindex": 0, "peer": {"del-reason": "expired", "id": 3}}} +{"name": "peer-del-ntf", "msg": {"ifindex": 0, "peer": {"del-reason": "expired", "id": 4}}} +{"name": "peer-del-ntf", "msg": {"ifindex": 0, "peer": {"del-reason": "expired", "id": 5}}} +{"name": "peer-del-ntf", "msg": {"ifindex": 0, "peer": {"del-reason": "expired", "id": 6}}}
tools/testing/selftests/net/ovpn/json/peer1-float.json new file +1 -0
@@ -0,0 +1 @@ +peer1.json
tools/testing/selftests/net/ovpn/json/peer1.json new file +1 -0
@@ -0,0 +1 @@ +{"name": "peer-del-ntf", "msg": {"ifindex": 0, "peer": {"del-reason": "userspace", "id": 1}}}
tools/testing/selftests/net/ovpn/json/peer2-float.json new file +1 -0
@@ -0,0 +1 @@ +peer2.json
tools/testing/selftests/net/ovpn/json/peer2.json new file +1 -0
@@ -0,0 +1 @@ +{"name": "peer-del-ntf", "msg": {"ifindex": 0, "peer": {"del-reason": "userspace", "id": 2}}}
tools/testing/selftests/net/ovpn/json/peer3-float.json new file +1 -0
@@ -0,0 +1 @@ +peer3.json
tools/testing/selftests/net/ovpn/json/peer3.json new file +1 -0
@@ -0,0 +1 @@ +{"name": "peer-del-ntf", "msg": {"ifindex": 0, "peer": {"del-reason": "expired", "id": 3}}}
tools/testing/selftests/net/ovpn/json/peer4-float.json new file +1 -0
@@ -0,0 +1 @@ +peer4.json
tools/testing/selftests/net/ovpn/json/peer4.json new file +1 -0
@@ -0,0 +1 @@ +{"name": "peer-del-ntf", "msg": {"ifindex": 0, "peer": {"del-reason": "expired", "id": 4}}}
tools/testing/selftests/net/ovpn/json/peer5-float.json new file +1 -0
@@ -0,0 +1 @@ +peer5.json
tools/testing/selftests/net/ovpn/json/peer5.json new file +1 -0
@@ -0,0 +1 @@ +{"name": "peer-del-ntf", "msg": {"ifindex": 0, "peer": {"del-reason": "expired", "id": 5}}}
tools/testing/selftests/net/ovpn/json/peer6-float.json new file +1 -0
@@ -0,0 +1 @@ +peer6.json
tools/testing/selftests/net/ovpn/json/peer6.json new file +1 -0
@@ -0,0 +1 @@ +{"name": "peer-del-ntf", "msg": {"ifindex": 0, "peer": {"del-reason": "expired", "id": 6}}}
tools/testing/selftests/net/ovpn/requirements.txt new file +1 -0
@@ -0,0 +1 @@ +../../../../net/ynl/requirements.txt
tools/testing/selftests/net/ovpn/tcp_peers.txt +1 -0
@@ -3,3 +3,4 @@ 3 5.5.5.4 4 5.5.5.5 5 5.5.5.6 +6 5.5.5.7
tools/testing/selftests/net/ovpn/test.sh +10 -0
@@ -17,6 +17,12 @@ for p in $(seq 0 ${NUM_PEERS}); do create_ns ${p} done +if has_listener_requirements; then + for p in $(seq 0 ${NUM_PEERS}); do + setup_listener ${p} + done +fi + for p in $(seq 0 ${NUM_PEERS}); do setup_ns ${p} 5.5.5.$((${p} + 1))/24 ${MTU} done
@@ -112,6 +118,10 @@ for p in $(seq 3 ${NUM_PEERS}); do done sleep 5 +for p in $(seq 0 ${NUM_PEERS}); do + compare_ntfs ${p} +done + cleanup modprobe -r ovpn || true
Signature · 1 line
2.51.2
Antonio Quartulli
maintainerRe: [RFC net-next 02/13] selftests: ovpn: add notification parsing and matching
Quoted 8 lines · Antonio Quartulli
From: Ralf Lici <[email protected]>
To verify that netlink notifications are correctly emitted and contain the expected fields, this commit uses the
tools/net/ynl/pyynl/cli.pyscript to create multicast listeners. These listeners record the captured notifications to a JSON file, which is later compared to the expected output.
Quoted 6 lines
Since this change introduces additional dependencies (jq, pyyaml, jsonschema), the tests are configured to check for their presence and conditionally skip the notification check if they are missing.
Signed-off-by Ralf Lici <[email protected]>Signed-off-by Antonio Quartulli <[email protected]>
Note: this patch should come after 05/13 - this is why it fails in pw.
Regards,
Signature · 2 lines
Antonio Quartulli OpenVPN Inc.
Sabrina Dubroca
reviewerRe: [RFC net-next 02/13] selftests: ovpn: add notification parsing and matching
In reply to Antonio QuartulliQuoted 4 lines · Antonio Quartulli
tools/testing/selftests/net/ovpn/common.sh +0
-0
[...]
tools/testing/selftests/net/ovpn/common.sh add_peer() { · line 105
Quoted 8 lines
tools/testing/selftests/net/ovpn/common.sh +4
-0@@ -82,6 +99,23 @@ add_peer() { fi } +compare_ntfs() { + if [ ${#tmp_jsons[@]} -gt 0 ]; then + [ "$FLOAT" == 1 ] && suffix="-float" + expexted="json/peer${1}${suffix}.json"
nit: expected?
tools/testing/selftests/net/ovpn/common.sh add_peer() { · line 113
Quoted 8 lines
tools/testing/selftests/net/ovpn/common.sh +8
-0+ received="${tmp_jsons[$1]}" + + kill -TERM ${listener_pids[$1]} || true + wait ${listener_pids[$1]} || true + printf "Checking notifications for peer ${1}... " + diff <(jq -s "${JQ_FILTER}" ${expexted}) \ + <(jq -s "${JQ_FILTER}" ${received}) + echo "OK"
Should that OK be conditional on what diff returns?
Signature · 1 line
Sabrina
Ralf Lici
reviewerRe: [RFC net-next 02/13] selftests: ovpn: add notification parsing and matching
Quoted 7 lines · Sabrina Dubroca
Quoted 5 lines · Antonio Quartulli
tools/testing/selftests/net/ovpn/common.sh +0
-0[...]
Quoted 10 lines
tools/testing/selftests/net/ovpn/common.sh add_peer() { · line 105
Quoted 8 lines
tools/testing/selftests/net/ovpn/common.sh +0
-0@@ -82,6 +99,23 @@ add_peer() {fi
}tools/testing/selftests/net/ovpn/common.sh +4
-0+compare_ntfs() { + if [ ${#tmp_jsons[@]} -gt 0 ]; then + [ "$FLOAT" == 1 ] && suffix="-float" + expexted="json/peer${1}${suffix}.json"nit: expected?
Will fix, thanks.
Quoted 10 lines
tools/testing/selftests/net/ovpn/common.sh add_peer() { · line 113
Quoted 8 lines
tools/testing/selftests/net/ovpn/common.sh +8
-0+ received="${tmp_jsons[$1]}" + + kill -TERM ${listener_pids[$1]} || true + wait ${listener_pids[$1]} || true + printf "Checking notifications for peer ${1}... " + diff <(jq -s "${JQ_FILTER}" ${expexted}) \ + <(jq -s "${JQ_FILTER}" ${received}) + echo "OK"Should that OK be conditional on what diff returns?
We run selftests with set -e, so if the jsons don’t match, the script will print the diff and exit. That said, I agree the current code isn’t very clear, so I’ll make the "OK" conditional.
Signature · 2 lines
Ralf Lici Mandelbit Srl
Antonio Quartulli
maintainerRFC 3/13 ovpn: use correct array size to parse nested attributes in ovpn_nl_key_swap_doit
In reply to Antonio QuartulliFrom: Sabrina Dubroca <[email protected]>
In ovpn_nl_key_swap_doit, the attributes array used to parse the OVPN_A_KEYCONF uses OVPN_A_PEER_MAX instead of OVPN_A_KEYCONF_MAX. Note that this does not cause any bug, since currently OVPN_A_KEYCONF_MAX < OVPN_A_PEER_MAX.
The wrong constant was introduced by 203e2bf55990 ("ovpn: implement key add/get/del/swap via netlink")
--- drivers/net/ovpn/netlink.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/net/ovpn/netlink.c +1 -1
@@ -1061,8 +1061,8 @@ int ovpn_nl_key_get_doit(struct sk_buff *skb, struct genl_info *info)int ovpn_nl_key_swap_doit (struct sk_buff *skb,struct genl_info *info) { +struct nlattr *attrs[OVPN_A_KEYCONF_MAX +1 ];struct ovpn_priv *ovpn = info->user_ptr[0 ]; -struct nlattr *attrs[OVPN_A_PEER_MAX +1 ];struct ovpn_peer *peer;u32 peer_id;int ret;
Signature · 1 line
2.51.2
Antonio Quartulli
maintainerRFC 4/13 ovpn: pktid: use bitops.h API
In reply to Antonio QuartulliFrom: Qingfang Deng <[email protected]>
Use bitops.h for replay window to simplify code.
--- drivers/net/ovpn/pktid.c | 11 ++++------- drivers/net/ovpn/pktid.h | 2 +- 2 files changed, 5 insertions(+), 8 deletions(-)
drivers/net/ovpn/pktid.c +4 -7
@@ -65,7 +65,7 @@ int ovpn_pktid_recv(struct ovpn_pktid_recv *pr, u32 pkt_id, u32 pkt_time)if (likely (pkt_id == pr->id +1 )) {/* well-formed ID sequence (incremented by 1) */ pr->base =REPLAY_INDEX (pr->base,-1 ); - pr->history[pr->base /8 ] |= (1 << (pr->base %8 )); +__set_bit (pr->base, pr->history);if (pr->extent <REPLAY_WINDOW_SIZE ) ++pr->extent; pr->id = pkt_id;
@@ -77,14 +77,14 @@ int ovpn_pktid_recv(struct ovpn_pktid_recv *pr, u32 pkt_id, u32 pkt_time)unsigned int i; pr->base =REPLAY_INDEX (pr->base, -delta); - pr->history[pr->base /8 ] |= (1 << (pr->base %8 )); +__set_bit (pr->base, pr->history); pr->extent += delta;if (pr->extent >REPLAY_WINDOW_SIZE ) pr->extent =REPLAY_WINDOW_SIZE ;for (i =1 ; i < delta; ++i) {unsigned int newb =REPLAY_INDEX (pr->base, i); - pr->history[newb /8 ] &= ~BIT (newb %8 ); +__clear_bit (newb, pr->history); } }else { pr->base =0 ;
@@ -103,14 +103,11 @@ int ovpn_pktid_recv(struct ovpn_pktid_recv *pr, u32 pkt_id, u32 pkt_time)if (pkt_id > pr->id_floor) {const unsigned int ri =REPLAY_INDEX (pr->base, delta); -u8 *p = &pr->history[ri /8 ]; -const u8 mask = (1 << (ri %8 )); -if (*p & mask) { +if (__test_and_set_bit (ri, pr->history)) { ret = -EINVAL ; goto out; } - *p |= mask; }else { ret = -EINVAL ; goto out;
drivers/net/ovpn/pktid.h +1 -1
@@ -34,7 +34,7 @@ struct ovpn_pktid_xmit {*/ struct ovpn_pktid_recv {/* "sliding window" bitmask of recent packet IDs received */ -u8 history[REPLAY_WINDOW_BYTES ]; + DECLARE_BITMAP(history, REPLAY_WINDOW_SIZE);/* bit position of deque base in history */ unsigned int base;/* extent (in bits) of deque in history */
Signature · 1 line
2.51.2
Antonio Quartulli
maintainerRFC 5/13 ovpn: notify userspace on client float event
In reply to Antonio QuartulliFrom: Ralf Lici <[email protected]>
Send a netlink notification when a client updates its remote UDP endpoint. The notification includes the new IP address, port, and scope ID (for IPv6).
--- Documentation/netlink/specs/ovpn.yaml | 6 ++ drivers/net/ovpn/netlink.c | 82 +++++++++++++++++++++ drivers/net/ovpn/netlink.h | 2 + drivers/net/ovpn/peer.c | 2 + include/uapi/linux/ovpn.h | 1 + tools/testing/selftests/net/ovpn/ovpn-cli.c | 3 + 6 files changed, 96 insertions(+)
Documentation/netlink/specs/ovpn.yaml +6 -0
@@ -502,6 +502,12 @@ operations: - ifindex - keyconf + - + name: peer-float-ntf + doc: Notification about a peer floating (changing its remote UDP endpoint) + notify: peer-get + mcgrp: peers + mcast-groups: list: -
drivers/net/ovpn/netlink.c +82 -0
88 lines not on this page · raw message
drivers/net/ovpn/netlink.h +2 -0
@@ -13,6 +13,8 @@ int ovpn_nl_register(void);void ovpn_nl_unregister (void );int ovpn_nl_peer_del_notify (struct ovpn_peer *peer); +int ovpn_nl_peer_float_notify (struct ovpn_peer *peer, +const struct sockaddr_storage *ss);int ovpn_nl_key_swap_notify (struct ovpn_peer *peer,u8 key_id);#endif /* _NET_OVPN_NETLINK_H_ */
drivers/net/ovpn/peer.c +2 -0
@@ -287,6 +287,8 @@ void ovpn_peer_endpoints_update(struct ovpn_peer *peer, struct sk_buff *skb)spin_unlock_bh (&peer->lock); +ovpn_nl_peer_float_notify (peer, &ss); +/* rehashing is required only in MP mode as P2P has one peer * only and thus there is no hashtable */
include/uapi/linux/ovpn.h +1 -0
@@ -99,6 +99,7 @@ enum {OVPN_CMD_KEY_SWAP ,OVPN_CMD_KEY_SWAP_NTF ,OVPN_CMD_KEY_DEL , +OVPN_CMD_PEER_FLOAT_NTF , __OVPN_CMD_MAX,OVPN_CMD_MAX = (__OVPN_CMD_MAX -1 )
tools/testing/selftests/net/ovpn/ovpn-cli.c +3 -0
@@ -1516,6 +1516,9 @@ static int ovpn_handle_msg(struct nl_msg *msg, void *arg)case OVPN_CMD_PEER_DEL_NTF :fprintf (stdout,"received CMD_PEER_DEL_NTF\n" );break ; +case OVPN_CMD_PEER_FLOAT_NTF : +fprintf (stdout,"received CMD_PEER_FLOAT_NTF\n" ); +break ;case OVPN_CMD_KEY_SWAP_NTF :fprintf (stdout,"received CMD_KEY_SWAP_NTF\n" );break ;
Signature · 1 line
2.51.2
Antonio Quartulli
maintainerRFC 6/13 ovpn: add support for asymmetric peer IDs
In reply to Antonio QuartulliFrom: Ralf Lici <[email protected]>
In order to support the multipeer architecture, upon connection setup each side of a tunnel advertises a unique ID that the other side must include in packets sent to them. Therefore when transmitting a packet, a peer inserts the recipient's advertised ID for that specific tunnel into the peer ID field. When receiving a packet, a peer expects to find its own unique receive ID for that specific tunnel in the peer ID field.
Add support for the TX peer ID and embed it into transmitting packets. If no TX peer ID is specified, fallback to using the same peer ID both for RX and TX in order to be compatible with the non-multipeer compliant peers.
--- Documentation/netlink/specs/ovpn.yaml | 17 ++++++++++++++++- drivers/net/ovpn/crypto_aead.c | 2 +- drivers/net/ovpn/netlink-gen.c | 13 ++++++++++--- drivers/net/ovpn/netlink-gen.h | 6 +++--- drivers/net/ovpn/netlink.c | 14 ++++++++++++-- drivers/net/ovpn/peer.c | 4 ++++ drivers/net/ovpn/peer.h | 4 +++- include/uapi/linux/ovpn.h | 1 + 8 files changed, 50 insertions(+), 11 deletions(-)
Documentation/netlink/specs/ovpn.yaml +16 -1
@@ -43,7 +43,8 @@ attribute-sets: type: u32 doc: >- The unique ID of the peer in the device context. To be used to - identify peers during operations for a specific device + identify peers during operations for a specific device. + Also used to match packets received from this peer. checks: max: 0xFFFFFF -
@@ -160,6 +161,16 @@ attribute-sets: name: link-tx-packets type: uint doc: Number of packets transmitted at the transport level + - + name: tx-id + type: u32 + doc: >- + The ID value used when transmitting packets to this peer. This + way outgoing packets can have a different ID than incoming ones. + Useful in multipeer-to-multipeer connections, where each peer + will advertise the tx-id to be used on the link. + checks: + max: 0xFFFFFF - name: peer-new-input subset-of: peer
@@ -188,6 +199,8 @@ attribute-sets: name: keepalive-interval - name: keepalive-timeout + - + name: tx-id - name: peer-set-input subset-of: peer
@@ -214,6 +227,8 @@ attribute-sets: name: keepalive-interval - name: keepalive-timeout + - + name: tx-id - name: peer-del-input subset-of: peer
drivers/net/ovpn/crypto_aead.c +1 -1
@@ -122,7 +122,7 @@ int ovpn_aead_encrypt(struct ovpn_peer *peer, struct ovpn_crypto_key_slot *ks,memcpy (skb->data, iv,OVPN_NONCE_WIRE_SIZE );/* add packet op as head of additional data */ - op =ovpn_opcode_compose (OVPN_DATA_V2 , ks->key_id, peer->id); + op =ovpn_opcode_compose (OVPN_DATA_V2 , ks->key_id, peer->tx_id);__skb_push (skb,OVPN_OPCODE_SIZE );BUILD_BUG_ON (sizeof (op) !=OVPN_OPCODE_SIZE ); *((__force __be32 *)skb->data) =htonl (op);
drivers/net/ovpn/netlink-gen.c +10 -3
@@ -15,6 +15,10 @@ static const struct netlink_range_validation ovpn_a_peer_id_range = { .max = 16777215ULL, }; +static const struct netlink_range_validation ovpn_a_peer_tx_id_range = { + .max =16777215ULL , +}; +static const struct netlink_range_validation ovpn_a_keyconf_peer_id_range = { .max =16777215ULL , };
@@ -50,7 +54,7 @@ const struct nla_policy ovpn_keydir_nl_policy[OVPN_A_KEYDIR_NONCE_TAIL + 1] = { [OVPN_A_KEYDIR_NONCE_TAIL] = NLA_POLICY_EXACT_LEN(OVPN_NONCE_TAIL_SIZE), }; -const struct nla_policy ovpn_peer_nl_policy[OVPN_A_PEER_LINK_TX_PACKETS +1 ] = { +const struct nla_policy ovpn_peer_nl_policy[OVPN_A_PEER_TX_ID +1 ] = { [OVPN_A_PEER_ID ] =NLA_POLICY_FULL_RANGE (NLA_U32 , &ovpn_a_peer_id_range), [OVPN_A_PEER_REMOTE_IPV4 ] = { .type =NLA_BE32 , }, [OVPN_A_PEER_REMOTE_IPV6 ] =NLA_POLICY_EXACT_LEN (16 ),
@@ -74,13 +78,14 @@ const struct nla_policy ovpn_peer_nl_policy[OVPN_A_PEER_LINK_TX_PACKETS + 1] = { [OVPN_A_PEER_LINK_TX_BYTES] = { .type = NLA_UINT, }, [OVPN_A_PEER_LINK_RX_PACKETS] = { .type = NLA_UINT, }, [OVPN_A_PEER_LINK_TX_PACKETS] = { .type = NLA_UINT, }, + [OVPN_A_PEER_TX_ID] = NLA_POLICY_FULL_RANGE(NLA_U32, &ovpn_a_peer_tx_id_range), };const struct nla_policy ovpn_peer_del_input_nl_policy[OVPN_A_PEER_ID +1 ] = { [OVPN_A_PEER_ID ] =NLA_POLICY_FULL_RANGE (NLA_U32 , &ovpn_a_peer_id_range), }; -const struct nla_policy ovpn_peer_new_input_nl_policy[OVPN_A_PEER_KEEPALIVE_TIMEOUT +1 ] = { +const struct nla_policy ovpn_peer_new_input_nl_policy[OVPN_A_PEER_TX_ID +1 ] = { [OVPN_A_PEER_ID ] =NLA_POLICY_FULL_RANGE (NLA_U32 , &ovpn_a_peer_id_range), [OVPN_A_PEER_REMOTE_IPV4 ] = { .type =NLA_BE32 , }, [OVPN_A_PEER_REMOTE_IPV6 ] =NLA_POLICY_EXACT_LEN (16 ),
@@ -93,9 +98,10 @@ const struct nla_policy ovpn_peer_new_input_nl_policy[OVPN_A_PEER_KEEPALIVE_TIME [OVPN_A_PEER_LOCAL_IPV6] = NLA_POLICY_EXACT_LEN(16), [OVPN_A_PEER_KEEPALIVE_INTERVAL] = { .type = NLA_U32, }, [OVPN_A_PEER_KEEPALIVE_TIMEOUT] = { .type = NLA_U32, }, + [OVPN_A_PEER_TX_ID] = NLA_POLICY_FULL_RANGE(NLA_U32, &ovpn_a_peer_tx_id_range), }; -const struct nla_policy ovpn_peer_set_input_nl_policy[OVPN_A_PEER_KEEPALIVE_TIMEOUT +1 ] = { +const struct nla_policy ovpn_peer_set_input_nl_policy[OVPN_A_PEER_TX_ID +1 ] = { [OVPN_A_PEER_ID ] =NLA_POLICY_FULL_RANGE (NLA_U32 , &ovpn_a_peer_id_range), [OVPN_A_PEER_REMOTE_IPV4 ] = { .type =NLA_BE32 , }, [OVPN_A_PEER_REMOTE_IPV6 ] =NLA_POLICY_EXACT_LEN (16 ),
@@ -107,6 +113,7 @@ const struct nla_policy ovpn_peer_set_input_nl_policy[OVPN_A_PEER_KEEPALIVE_TIME [OVPN_A_PEER_LOCAL_IPV6] = NLA_POLICY_EXACT_LEN(16), [OVPN_A_PEER_KEEPALIVE_INTERVAL] = { .type = NLA_U32, }, [OVPN_A_PEER_KEEPALIVE_TIMEOUT] = { .type = NLA_U32, }, + [OVPN_A_PEER_TX_ID] = NLA_POLICY_FULL_RANGE(NLA_U32, &ovpn_a_peer_tx_id_range), };/* OVPN_CMD_PEER_NEW - do */
drivers/net/ovpn/netlink-gen.h +3 -3
@@ -17,10 +17,10 @@ extern const struct nla_policy ovpn_keyconf_del_input_nl_policy[OVPN_A_KEYCONF_Sextern const struct nla_policy ovpn_keyconf_get_nl_policy[OVPN_A_KEYCONF_CIPHER_ALG +1 ];extern const struct nla_policy ovpn_keyconf_swap_input_nl_policy[OVPN_A_KEYCONF_PEER_ID +1 ];extern const struct nla_policy ovpn_keydir_nl_policy[OVPN_A_KEYDIR_NONCE_TAIL +1 ]; -extern const struct nla_policy ovpn_peer_nl_policy[OVPN_A_PEER_LINK_TX_PACKETS +1 ]; +extern const struct nla_policy ovpn_peer_nl_policy[OVPN_A_PEER_TX_ID +1 ];extern const struct nla_policy ovpn_peer_del_input_nl_policy[OVPN_A_PEER_ID +1 ]; -extern const struct nla_policy ovpn_peer_new_input_nl_policy[OVPN_A_PEER_KEEPALIVE_TIMEOUT +1 ]; -extern const struct nla_policy ovpn_peer_set_input_nl_policy[OVPN_A_PEER_KEEPALIVE_TIMEOUT +1 ]; +extern const struct nla_policy ovpn_peer_new_input_nl_policy[OVPN_A_PEER_TX_ID +1 ]; +extern const struct nla_policy ovpn_peer_set_input_nl_policy[OVPN_A_PEER_TX_ID +1 ];int ovpn_nl_pre_doit (const struct genl_split_ops *ops,struct sk_buff *skb,struct genl_info *info);
drivers/net/ovpn/netlink.c +12 -2
@@ -305,6 +305,12 @@ static int ovpn_nl_peer_modify(struct ovpn_peer *peer, struct genl_info *info,dst_cache_reset (&peer->dst_cache); } +/* In a multipeer-to-multipeer setup we may have asymmetric peer IDs, +* that is peer->id might be different from peer->tx_id. +*/ +if (attrs[OVPN_A_PEER_TX_ID ]) + peer->tx_id =nla_get_u32 (attrs[OVPN_A_PEER_TX_ID ]); +if (attrs[OVPN_A_PEER_VPN_IPV4 ]) { rehash = true; peer->vpn_addrs.ipv4.s_addr =
@@ -326,8 +332,8 @@ static int ovpn_nl_peer_modify(struct ovpn_peer *peer, struct genl_info *info, }netdev_dbg (peer->ovpn->dev, -"modify peer id=%u endpoint=%pIScp VPN-IPv4=%pI4 VPN-IPv6=%pI6c\n" , - peer->id, &ss, +"modify peer id=%u tx_id=%u endpoint=%pIScp VPN-IPv4=%pI4 VPN-IPv6=%pI6c\n" , + peer->id, peer->tx_id, &ss, &peer->vpn_addrs.ipv4.s_addr, &peer->vpn_addrs.ipv6);spin_unlock_bh (&peer->lock);
@@ -373,6 +379,7 @@ int ovpn_nl_peer_new_doit(struct sk_buff *skb, struct genl_info *info) } peer_id =nla_get_u32 (attrs[OVPN_A_PEER_ID ]); + peer =ovpn_peer_new (ovpn, peer_id);if (IS_ERR (peer)) { NL_SET_ERR_MSG_FMT_MOD(info->extack,
@@ -572,6 +579,9 @@ static int ovpn_nl_send_peer(struct sk_buff *skb, const struct genl_info *info,if (nla_put_u32 (skb,OVPN_A_PEER_ID , peer->id)) goto err; +if (nla_put_u32 (skb,OVPN_A_PEER_TX_ID , peer->tx_id)) + goto err; +if (peer->vpn_addrs.ipv4.s_addr !=htonl (INADDR_ANY ))if (nla_put_in_addr (skb,OVPN_A_PEER_VPN_IPV4 , peer->vpn_addrs.ipv4.s_addr))
drivers/net/ovpn/peer.c +4 -0
@@ -99,7 +99,11 @@ struct ovpn_peer *ovpn_peer_new(struct ovpn_priv *ovpn, u32 id)if (!peer)return ERR_PTR (-ENOMEM ); +/* in the default case TX and RX IDs are the same. +* the user may set a different TX ID via netlink +*/ peer->id = id; + peer->tx_id = id; peer->ovpn = ovpn; peer->vpn_addrs.ipv4.s_addr =htonl (INADDR_ANY );
drivers/net/ovpn/peer.h +3 -1
@@ -21,7 +21,8 @@* struct ovpn_peer - the main remote peer object * @ovpn: main openvpn instance this peer belongs to * @dev_tracker: reference tracker for associated dev -* @id: unique identifier +* @id: unique identifier, used to match incoming packets +* @tx_id: identifier to be used in TX packets * @vpn_addrs: IP addresses assigned over the tunnel * @vpn_addrs.ipv4: IPv4 assigned to peer on the tunnel * @vpn_addrs.ipv6: IPv6 assigned to peer on the tunnel
@@ -64,6 +65,7 @@ struct ovpn_peer {struct ovpn_priv *ovpn;netdevice_tracker dev_tracker;u32 id; +u32 tx_id;struct {struct in_addr ipv4;struct in6_addr ipv6;
include/uapi/linux/ovpn.h +1 -0
@@ -54,6 +54,7 @@ enum {OVPN_A_PEER_LINK_TX_BYTES ,OVPN_A_PEER_LINK_RX_PACKETS ,OVPN_A_PEER_LINK_TX_PACKETS , +OVPN_A_PEER_TX_ID , __OVPN_A_PEER_MAX,OVPN_A_PEER_MAX = (__OVPN_A_PEER_MAX -1 )
Signature · 1 line
2.51.2
Antonio Quartulli
maintainerRFC 7/13 selftests: ovpn: check asymmetric peer-id
In reply to Antonio QuartulliFrom: Ralf Lici <[email protected]>
Extend the base test to verify that the correct peer-id is set in data packet headers. This is done by capturing ping packets with ngrep during the initial exchange and matching the first portion of the header against the expected sequence for every connection.
--- tools/testing/selftests/net/ovpn/common.sh | 20 +++---- .../selftests/net/ovpn/json/peer1.json | 2 +- .../selftests/net/ovpn/json/peer2.json | 2 +- .../selftests/net/ovpn/json/peer3.json | 2 +- .../selftests/net/ovpn/json/peer4.json | 2 +- .../selftests/net/ovpn/json/peer5.json | 2 +- .../selftests/net/ovpn/json/peer6.json | 2 +- tools/testing/selftests/net/ovpn/ovpn-cli.c | 53 ++++++++++++------- .../testing/selftests/net/ovpn/tcp_peers.txt | 12 ++--- .../selftests/net/ovpn/test-close-socket.sh | 2 +- tools/testing/selftests/net/ovpn/test.sh | 47 +++++++++++----- .../testing/selftests/net/ovpn/udp_peers.txt | 12 ++--- 12 files changed, 97 insertions(+), 61 deletions(-)
tools/testing/selftests/net/ovpn/common.sh +11 -9
@@ -75,13 +75,14 @@ add_peer() { data64.key done else - RADDR=$(awk "NR == ${1} {print \$2}" ${UDP_PEERS_FILE}) - RPORT=$(awk "NR == ${1} {print \$3}" ${UDP_PEERS_FILE}) - LPORT=$(awk "NR == ${1} {print \$5}" ${UDP_PEERS_FILE}) - ip netns exec peer${1} ${OVPN_CLI} new_peer tun${1} ${1} ${LPORT} \ - ${RADDR} ${RPORT} - ip netns exec peer${1} ${OVPN_CLI} new_key tun${1} ${1} 1 0 ${ALG} 1 \ - data64.key + TX_ID=$(awk "NR == ${1} {print \$2}" ${UDP_PEERS_FILE}) + 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}) + ip netns exec peer${1} ${OVPN_CLI} new_peer tun${1} ${TX_ID} ${1} \ + ${LPORT} ${RADDR} ${RPORT} + ip netns exec peer${1} ${OVPN_CLI} new_key tun${1} ${TX_ID} 1 0 \ + ${ALG} 1 data64.key fi else if [ ${1} -eq 0 ]; then
@@ -93,8 +94,9 @@ add_peer() { }) & sleep 5 else - ip netns exec peer${1} ${OVPN_CLI} connect tun${1} ${1} 10.10.${1}.1 1 \ - data64.key + TX_ID=$(awk "NR == ${1} {print \$2}" ${TCP_PEERS_FILE}) + ip netns exec peer${1} ${OVPN_CLI} connect tun${1} ${TX_ID} ${1} \ + 10.10.${1}.1 1 data64.key fi fi }
tools/testing/selftests/net/ovpn/json/peer1.json +1 -1
@@ -1 +1 @@ -{"name": "peer-del-ntf", "msg": {"ifindex": 0, "peer": {"del-reason": "userspace", "id": 1}}} +{"name": "peer-del-ntf", "msg": {"ifindex": 0, "peer": {"del-reason": "userspace", "id": 10}}}
tools/testing/selftests/net/ovpn/json/peer2.json +1 -1
@@ -1 +1 @@ -{"name": "peer-del-ntf", "msg": {"ifindex": 0, "peer": {"del-reason": "userspace", "id": 2}}} +{"name": "peer-del-ntf", "msg": {"ifindex": 0, "peer": {"del-reason": "userspace", "id": 11}}}
tools/testing/selftests/net/ovpn/json/peer3.json +1 -1
@@ -1 +1 @@ -{"name": "peer-del-ntf", "msg": {"ifindex": 0, "peer": {"del-reason": "expired", "id": 3}}} +{"name": "peer-del-ntf", "msg": {"ifindex": 0, "peer": {"del-reason": "expired", "id": 12}}}
tools/testing/selftests/net/ovpn/json/peer4.json +1 -1
@@ -1 +1 @@ -{"name": "peer-del-ntf", "msg": {"ifindex": 0, "peer": {"del-reason": "expired", "id": 4}}} +{"name": "peer-del-ntf", "msg": {"ifindex": 0, "peer": {"del-reason": "expired", "id": 13}}}
tools/testing/selftests/net/ovpn/json/peer5.json +1 -1
@@ -1 +1 @@ -{"name": "peer-del-ntf", "msg": {"ifindex": 0, "peer": {"del-reason": "expired", "id": 5}}} +{"name": "peer-del-ntf", "msg": {"ifindex": 0, "peer": {"del-reason": "expired", "id": 14}}}
tools/testing/selftests/net/ovpn/json/peer6.json +1 -1
@@ -1 +1 @@ -{"name": "peer-del-ntf", "msg": {"ifindex": 0, "peer": {"del-reason": "expired", "id": 6}}} +{"name": "peer-del-ntf", "msg": {"ifindex": 0, "peer": {"del-reason": "expired", "id": 15}}}
tools/testing/selftests/net/ovpn/ovpn-cli.c +33 -20
158 lines not on this page · raw message
tools/testing/selftests/net/ovpn/tcp_peers.txt +6 -6
@@ -1,6 +1,6 @@ -1 5.5.5.2 -2 5.5.5.3 -3 5.5.5.4 -4 5.5.5.5 -5 5.5.5.6 -6 5.5.5.7 +1 10 5.5.5.2 +2 11 5.5.5.3 +3 12 5.5.5.4 +4 13 5.5.5.5 +5 14 5.5.5.6 +6 15 5.5.5.7
tools/testing/selftests/net/ovpn/test-close-socket.sh +1 -1
@@ -27,7 +27,7 @@ done for p in $(seq 1 ${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} 60 120 + ip netns exec peer${p} ${OVPN_CLI} set_peer tun${p} $((${p}+9)) 60 120 done sleep 1
tools/testing/selftests/net/ovpn/test.sh +34 -13
98 lines not on this page · raw message
tools/testing/selftests/net/ovpn/udp_peers.txt +6 -6
@@ -1,6 +1,6 @@ -1 10.10.1.1 1 10.10.1.2 1 5.5.5.2 -2 10.10.2.1 1 10.10.2.2 1 5.5.5.3 -3 10.10.3.1 1 10.10.3.2 1 5.5.5.4 -4 fd00:0:0:4::1 1 fd00:0:0:4::2 1 5.5.5.5 -5 fd00:0:0:5::1 1 fd00:0:0:5::2 1 5.5.5.6 -6 fd00:0:0:6::1 1 fd00:0:0:6::2 1 5.5.5.7 +1 10 10.10.1.1 1 10.10.1.2 1 5.5.5.2 +2 11 10.10.2.1 1 10.10.2.2 1 5.5.5.3 +3 12 10.10.3.1 1 10.10.3.2 1 5.5.5.4 +4 13 fd00:0:0:4::1 1 fd00:0:0:4::2 1 5.5.5.5 +5 14 fd00:0:0:5::1 1 fd00:0:0:5::2 1 5.5.5.6 +6 15 fd00:0:0:6::1 1 fd00:0:0:6::2 1 5.5.5.7
Signature · 1 line
2.51.2
Sabrina Dubroca
reviewerRe: [RFC net-next 07/13] selftests: ovpn: check asymmetric peer-id
Quoted 13 lines · Antonio Quartulli
tools/testing/selftests/net/ovpn/common.sh +0
-5@@ -75,13 +75,14 @@ add_peer() { data64.key done else - RADDR=$(awk "NR == ${1} {print \$2}" ${UDP_PEERS_FILE}) - RPORT=$(awk "NR == ${1} {print \$3}" ${UDP_PEERS_FILE}) - LPORT=$(awk "NR == ${1} {print \$5}" ${UDP_PEERS_FILE}) - ip netns exec peer${1} ${OVPN_CLI} new_peer tun${1} ${1} ${LPORT} \ - ${RADDR} ${RPORT}
tools/testing/selftests/net/ovpn/common.sh add_peer() { · line 85
Quoted 10 lines
tools/testing/selftests/net/ovpn/common.sh +8
-2- ip netns exec peer${1} ${OVPN_CLI} new_key tun${1} ${1} 1 0 ${ALG} 1 \ - data64.key + TX_ID=$(awk "NR == ${1} {print \$2}" ${UDP_PEERS_FILE}) + 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}) + ip netns exec peer${1} ${OVPN_CLI} new_peer tun${1} ${TX_ID} ${1} \ + ${LPORT} ${RADDR} ${RPORT} + ip netns exec peer${1} ${OVPN_CLI} new_key tun${1} ${TX_ID} 1 0 \ + ${ALG} 1 data64.key
IIUC, we're creating a "client" with peer_id=$TX_ID and tx_id=$ID so that they're flipped from what we installed on the multi-peer side?
Quoted 14 lines
tools/testing/selftests/net/ovpn/ovpn-cli.c +1
-1@@ -103,7 +103,7 @@ struct ovpn_ctx {sa_family_t sa_family; -unsigned long peer_id; +unsigned long peer_id, tx_id;unsigned long lport;union {
tools/testing/selftests/net/ovpn/ovpn-cli.c static int ovpn_new_peer(struct ovpn_ctx *ovpn, bool is_tcp) · line 652
Quoted 4 lines
tools/testing/selftests/net/ovpn/ovpn-cli.c +1
-0@@ -649,6 +649,7 @@ static int ovpn_new_peer(struct ovpn_ctx *ovpn, bool is_tcp) attr =nla_nest_start (ctx->nl_msg,OVPN_A_PEER );NLA_PUT_U32 (ctx->nl_msg,OVPN_A_PEER_ID , ovpn->peer_id); +NLA_PUT_U32 (ctx->nl_msg,OVPN_A_PEER_TX_ID , ovpn->tx_id);
So, with these changes, it's no longer possible to test a userspace not passing the new OVPN_A_PEER_TX_ID attribute? But I guess we could simulate that behavior by passing TX_ID==ID (is there still a test doing that?).
Do we need to preserve some testing of the case where userspace is not passing the new attribute?
Quoted 31 lines
tools/testing/selftests/net/ovpn/ovpn-cli.c +8
-2NLA_PUT_U32 (ctx->nl_msg,OVPN_A_PEER_SOCKET , ovpn->socket);if (!is_tcp) {@@ -767,6 +768,10 @@ static int ovpn_handle_peer(struct nl_msg *msg, void (*arg)__always_unused)fprintf (stderr,"* Peer %u\n" ,nla_get_u32 (pattrs[OVPN_A_PEER_ID ])); +if (pattrs[OVPN_A_PEER_TX_ID ]) +fprintf (stderr,"\tTX peer ID %u\n" , +nla_get_u32 (pattrs[OVPN_A_PEER_TX_ID ])); +if (pattrs[OVPN_A_PEER_SOCKET_NETNSID ])fprintf (stderr,"\tsocket NetNS ID: %d\n" ,nla_get_s32 (pattrs[OVPN_A_PEER_SOCKET_NETNSID ]));@@ -1676,11 +1681,13 @@ static void usage(const char *cmd) "\tkey_file: file containing the symmetric key for encryption\n");fprintf (stderr, -"* new_peer <iface> <peer_id> <lport> <raddr> <rport> [vpnaddr]: add new peer\n" ); +"* new_peer <iface> <peer_id> <tx_id> <lport> <raddr> <rport> [vpnaddr]: add new peer\n" );fprintf (stderr,"\tiface: ovpn interface name\n" );fprintf (stderr,"\tlport: local UDP port to bind to\n" );fprintf (stderr, -"\tpeer_id: peer ID to be used in data packets to/from this peer\n" ); +"\tpeer_id: peer ID found in data packets received from this peer\n" ); +fprintf (stderr, +"\ttx_id: peer ID to be used when sending to this peer\n" );fprintf (stderr,"\traddr: peer IP address\n" );fprintf (stderr,"\trport: peer UDP port\n" );fprintf (stderr,"\tvpnaddr: peer VPN IP\n" );
tools/testing/selftests/net/ovpn/ovpn-cli.c static void usage(const char *cmd) · line 1701
Quoted 5 lines
tools/testing/selftests/net/ovpn/ovpn-cli.c +1
-1@@ -1691,7 +1698,7 @@ static void usage(const char *cmd)fprintf (stderr,"\tlport: local UDP port to bind to\n" );fprintf (stderr,"\tpeers_file: text file containing one peer per line. Line format:\n" ); -fprintf (stderr,"\t\t<peer_id> <raddr> <rport> <vpnaddr>\n" ); +fprintf (stderr,"\t\t<peer_id> <tx_id> <raddr> <rport> <laddr> <lport> <vpnaddr>\n" );
Looks like this is missing similar updates for connect and listen, based on changes to ovpn_run_cmd and ovpn_parse_cmd_args?
Signature · 1 line
Sabrina
Ralf Lici
reviewerRe: [RFC net-next 07/13] selftests: ovpn: check asymmetric peer-id
Quoted 31 lines · Sabrina Dubroca
Quoted 30 lines · Antonio Quartulli
tools/testing/selftests/net/ovpn/common.sh +0
-0@@ -75,13 +75,14 @@ add_peer() {data64.key done
elsetools/testing/selftests/net/ovpn/common.sh +0
-1- RADDR=$(awk "NR == ${1} {print \$2}"${UDP_PEERS_FILE})
tools/testing/selftests/net/ovpn/common.sh +0
-1- RPORT=$(awk "NR == ${1} {print \$3}"${UDP_PEERS_FILE})
tools/testing/selftests/net/ovpn/common.sh +0
-1- LPORT=$(awk "NR == ${1} {print \$5}"${UDP_PEERS_FILE})
tools/testing/selftests/net/ovpn/common.sh +0
-1- ip netns exec peer${1} ${OVPN_CLI} new_peertun${1} ${1} ${LPORT} \
tools/testing/selftests/net/ovpn/common.sh +0
-2- ${RADDR} ${RPORT} - ip netns exec peer${1} ${OVPN_CLI} new_keytun${1} ${1} 1 0 ${ALG} 1 \
tools/testing/selftests/net/ovpn/common.sh +1
-1- data64.key + TX_ID=$(awk "NR == ${1} {print \$2}"${UDP_PEERS_FILE})
tools/testing/selftests/net/ovpn/common.sh +1
-0+ RADDR=$(awk "NR == ${1} {print \$3}"${UDP_PEERS_FILE})
tools/testing/selftests/net/ovpn/common.sh +1
-0+ RPORT=$(awk "NR == ${1} {print \$4}"${UDP_PEERS_FILE})
tools/testing/selftests/net/ovpn/common.sh +1
-0+ LPORT=$(awk "NR == ${1} {print \$6}"${UDP_PEERS_FILE})
tools/testing/selftests/net/ovpn/common.sh +1
-0+ ip netns exec peer${1} ${OVPN_CLI} new_peer
Quoted 8 lines
tools/testing/selftests/net/ovpn/common.sh add_peer() { · line 85
Quoted 5 lines
tun${1} ${TX_ID} ${1} \
tools/testing/selftests/net/ovpn/common.sh +2
-0+ ${LPORT} ${RADDR} ${RPORT} + ip netns exec peer${1} ${OVPN_CLI} new_keytun${1} ${TX_ID} 1 0 \
tools/testing/selftests/net/ovpn/common.sh +1
-0+ ${ALG} 1 data64.keyIIUC, we're creating a "client" with peer_id=$TX_ID and tx_id=$ID so that they're flipped from what we installed on the multi-peer side?
Exactly. I can see that this part is not very clear so I'll properly define PEER_ID and TX_ID for the clients in the next version of the patch.
Quoted 26 lines
Quoted 19 lines
tools/testing/selftests/net/ovpn/ovpn-cli.c +0
-0@@ -103,7 +103,7 @@ struct ovpn_ctx {
sa_family_tsa_family;tools/testing/selftests/net/ovpn/ovpn-cli.c +1
-1-unsigned long peer_id; +unsigned long peer_id, tx_id;unsigned long lport;
union {tools/testing/selftests/net/ovpn/ovpn-cli.c +0
-0@@ -649,6 +649,7 @@ static int ovpn_new_peer(struct ovpn_ctx *ovpn, bool is_tcp)
attr =nla_nest_start(ctx->nl_msg, OVPN_A_PEER);NLA_PUT_U32(ctx->nl_msg, OVPN_A_PEER_ID, ovpn->peer_id);tools/testing/selftests/net/ovpn/ovpn-cli.c static int ovpn_new_peer(struct ovpn_ctx *ovpn, bool is_tcp) · line 652
Quoted 1 line
tools/testing/selftests/net/ovpn/ovpn-cli.c +1
-0+NLA_PUT_U32 (ctx->nl_msg,OVPN_A_PEER_TX_ID , ovpn->tx_id);So, with these changes, it's no longer possible to test a userspace not passing the new
OVPN_A_PEER_TX_IDattribute? But I guess we could simulate that behavior by passing TX_ID==ID (is there still a test doing that?).
Quoted 3 lines
Do we need to preserve some testing of the case where userspace is not passing the new attribute?
That's a valid concern as we're expected to still correctly handle userspace programs that don't pass the attribute. I'll add a boolean flag similar to FLOAT in order to extend the tests to cover this case.
Quoted 43 lines
Quoted 43 lines
NLA_PUT_U32(ctx->nl_msg, OVPN_A_PEER_SOCKET, ovpn->socket);
if (!is_tcp) {tools/testing/selftests/net/ovpn/ovpn-cli.c +0
-0@@ -767,6 +768,10 @@ static int ovpn_handle_peer(struct nl_msg *msg, void (*arg)__always_unused) fprintf(stderr, "* Peer %u\n", nla_get_u32(pattrs[OVPN_A_PEER_ID]));tools/testing/selftests/net/ovpn/ovpn-cli.c +4
-0+if (pattrs[OVPN_A_PEER_TX_ID ]) +fprintf (stderr,"\tTX peer ID %u\n" , +nla_get_u32 (pattrs[OVPN_A_PEER_TX_ID ])); +if (pattrs[OVPN_A_PEER_SOCKET_NETNSID])
fprintf(stderr, "\tsocket NetNS ID: %d\n", nla_get_s32(pattrs[OVPN_A_PEER_SOCKET_NETNS ID]));tools/testing/selftests/net/ovpn/ovpn-cli.c +0
-0@@ -1676,11 +1681,13 @@ static void usage(const char *cmd)"\tkey_file: file containing the symmetric key for encryption\n");
fprintf(stderr,tools/testing/selftests/net/ovpn/ovpn-cli.c +0
-1- "* new_peer <iface> <peer_id> <lport> <raddr><rport> [vpnaddr]: add new peer\n");
tools/testing/selftests/net/ovpn/ovpn-cli.c +1
-0+ "* new_peer <iface> <peer_id> <tx_id> <lport><raddr> <rport> [vpnaddr]: add new peer\n");
fprintf(stderr, "\tiface: ovpn interface name\n");fprintf(stderr, "\tlport: local UDP port to bind to\n"); fprintf(stderr,tools/testing/selftests/net/ovpn/ovpn-cli.c +0
-1- "\tpeer_id: peer ID to be used in data packetsto/from this peer\n");
tools/testing/selftests/net/ovpn/ovpn-cli.c +1
-0+ "\tpeer_id: peer ID found in data packets receivedfrom this peer\n");
tools/testing/selftests/net/ovpn/ovpn-cli.c +2
-0+ fprintf(stderr, + "\ttx_id: peer ID to be used when sending to thispeer\n");
fprintf(stderr, "\traddr: peer IP address\n");fprintf(stderr, "\trport: peer UDP port\n");fprintf(stderr, "\tvpnaddr: peer VPN IP\n");tools/testing/selftests/net/ovpn/ovpn-cli.c +0
-0@@ -1691,7 +1698,7 @@ static void usage(const char *cmd) fprintf(stderr, "\tlport: local UDP port to bind to\n"); fprintf(stderr,"\tpeers_file: text file containing one peer per
Quoted 8 lines
Quoted 5 lines
line. Line format:\n");
tools/testing/selftests/net/ovpn/ovpn-cli.c +0
-1- fprintf(stderr, "\t\t<peer_id> <raddr> <rport><vpnaddr>\n");
tools/testing/selftests/net/ovpn/ovpn-cli.c +1
-0+ fprintf(stderr, "\t\t<peer_id> <tx_id> <raddr> <rport><laddr> <lport> <vpnaddr>\n");
Looks like this is missing similar updates for connect and listen, based on changes to
ovpn_run_cmdandovpn_parse_cmd_args?
Good catch, thanks.
Signature · 2 lines
Ralf Lici Mandelbit Srl
Antonio Quartulli
maintainerRFC 8/13 selftests: ovpn: add test for the FW mark feature
In reply to Antonio QuartulliFrom: Ralf Lici <[email protected]>
Add a selftest to verify that the FW mark socket option is correctly supported and its value propagated by ovpn.
The test adds and removes nftables DROP rules based on the mark value, and checks that the rule counter aligns with the number of lost ping packets.
--- tools/testing/selftests/net/ovpn/Makefile | 1 + tools/testing/selftests/net/ovpn/ovpn-cli.c | 26 +++++- tools/testing/selftests/net/ovpn/test-mark.sh | 81 +++++++++++++++++++ 3 files changed, 106 insertions(+), 2 deletions(-) create mode 100755 tools/testing/selftests/net/ovpn/test-mark.sh
tools/testing/selftests/net/ovpn/Makefile +1 -0
@@ -31,6 +31,7 @@ TEST_PROGS := \ test-close-socket.sh \ test-float.sh \ test-large-mtu.sh \ + test-mark.sh \ test-tcp.sh \ test.sh \ # end of TEST_PROGS
tools/testing/selftests/net/ovpn/ovpn-cli.c +24 -2
@@ -6,6 +6,7 @@* Author: Antonio Quartulli <[email protected]> */ +#include <stdint.h> #include <stdio.h> #include <inttypes.h> #include <stdbool.h>
@@ -133,6 +134,8 @@ struct ovpn_ctx {enum ovpn_key_slot key_slot;int key_id; +uint32_t mark; +const char *peers_file; };
@@ -521,6 +524,15 @@ static int ovpn_socket(struct ovpn_ctx *ctx, sa_family_t family, int proto)return ret; } +if (ctx->mark !=0 ) { + ret =setsockopt (s,SOL_SOCKET ,SO_MARK , (void *)&ctx->mark, +sizeof (ctx->mark)); +if (ret <0 ) { +perror ("setsockopt for SO_MARK" ); +return ret; + } + } +if (family ==AF_INET6 ) { opt =0 ; if (setsockopt(s, IPPROTO_IPV6, IPV6_V6ONLY, &opt,
@@ -1693,12 +1705,13 @@ static void usage(const char *cmd)fprintf (stderr,"\tvpnaddr: peer VPN IP\n" );fprintf (stderr, -"* new_multi_peer <iface> <lport> <peers_file>: add multiple peers as listed in the file\n" ); +"* new_multi_peer <iface> <lport> <peers_file> [mark]: add multiple peers as listed in the file\n" );fprintf (stderr,"\tiface: ovpn interface name\n" );fprintf (stderr,"\tlport: local UDP port to bind to\n" );fprintf (stderr,"\tpeers_file: text file containing one peer per line. Line format:\n" ); -fprintf (stderr,"\t\t<peer_id> <tx_id> <raddr> <rport> <laddr> <lport> <vpnaddr>\n" ); +fprintf (stderr,"\t\t<peer_id> <tx_id> <raddr> <rport> <laddr> <lport> <vpnaddr> [mark]\n" ); +fprintf (stderr,"\tmark: socket FW mark value\n" );fprintf (stderr,"* set_peer <iface> <peer_id> <keepalive_interval> <keepalive_timeout>: set peer attributes\n" );
@@ -2241,6 +2254,15 @@ static int ovpn_parse_cmd_args(struct ovpn_ctx *ovpn, int argc, char *argv[]) } ovpn->peers_file = argv[4 ]; + + ovpn->mark =0 ; +if (argc >5 ) { + ovpn->mark =strtoul (argv[5 ],NULL ,10 ); +if (errno ==ERANGE || ovpn->mark >UINT32_MAX ) { +fprintf (stderr,"mark value out of range\n" ); +return -1 ; + } + }break ;case CMD_SET_PEER :if (argc <6 )
tools/testing/selftests/net/ovpn/test-mark.sh new file +81 -0
81 lines not on this page · raw message
Signature · 1 line
2.51.2
Sabrina Dubroca
reviewerRe: [RFC net-next 08/13] selftests: ovpn: add test for the FW mark feature
Quoted 6 lines · Antonio Quartulli
tools/testing/selftests/net/ovpn/ovpn-cli.c +0
-0@@ -1693,12 +1705,13 @@ static void usage(const char *cmd)fprintf (stderr,"\tvpnaddr: peer VPN IP\n" );
tools/testing/selftests/net/ovpn/ovpn-cli.c static void usage(const char *cmd) · line 1713
Quoted 10 lines
tools/testing/selftests/net/ovpn/ovpn-cli.c +2
-2fprintf (stderr, -"* new_multi_peer <iface> <lport> <peers_file>: add multiple peers as listed in the file\n" ); +"* new_multi_peer <iface> <lport> <peers_file> [mark]: add multiple peers as listed in the file\n" );fprintf (stderr,"\tiface: ovpn interface name\n" );fprintf (stderr,"\tlport: local UDP port to bind to\n" );fprintf (stderr,"\tpeers_file: text file containing one peer per line. Line format:\n" ); -fprintf (stderr,"\t\t<peer_id> <tx_id> <raddr> <rport> <laddr> <lport> <vpnaddr>\n" ); +fprintf (stderr,"\t\t<peer_id> <tx_id> <raddr> <rport> <laddr> <lport> <vpnaddr> [mark]\n" );
This line should be dropped, this patch doesn't have the corresponding change to parse mark while we're looping over the lines of peers_file.
Quoted 5 lines
tools/testing/selftests/net/ovpn/test-mark.sh new file +0
-0
[...]
tools/testing/selftests/net/ovpn/test-mark.sh line 46
Quoted 9 lines
tools/testing/selftests/net/ovpn/test-mark.sh new file +9
-0+for p in $(seq 1 3); 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 3); do + ip netns exec peer0 ping -qfc 500 -s 3000 -w 3 5.5.5.$((${p} + 1))
Any reason this ping (and the final one) uses -s 3000 while the one we expect to fail doesn't?
Quoted 4 lines
tools/testing/selftests/net/ovpn/test-mark.sh new file +4
-0+done + +echo "Adding an nftables drop rule based on mark value ${MARK}" +ip netns exec peer0 nft flush ruleset
tools/testing/selftests/net/ovpn/test-mark.sh line 60
Quoted 10 lines
tools/testing/selftests/net/ovpn/test-mark.sh new file +10
-0+ip netns exec peer0 nft 'add table inet filter' +ip netns exec peer0 nft 'add chain inet filter output { type filter hook output priority 0; policy accept; }' +ip netns exec peer0 nft add rule inet filter output meta mark == ${MARK} counter drop + +DROP_COUNTER=$(ip netns exec peer0 nft list chain inet filter output | sed -n 's/.*packets \([0-9]*\).*/\1/p') +sleep 1 + +# ping should fail +for p in $(seq 1 3); do + PING_OUTPUT=$(ip netns exec peer0 ping -qfc 500 -w 1 5.5.5.$((p+1)) 2>&1) && exit 1
nit: inconsistent syntax for p+1 compared to the other pings ($((p+1)) vs $((${p} + 1)))
tools/testing/selftests/net/ovpn/test-mark.sh line 69
Quoted 9 lines
tools/testing/selftests/net/ovpn/test-mark.sh new file +9
-0+ echo "${PING_OUTPUT}" + LOST_PACKETS=$(echo "$PING_OUTPUT" | grep 'packets transmitted' | awk '{ print $1 }') + # increment the drop counter by the amount of lost packets + DROP_COUNTER=$(($DROP_COUNTER+$LOST_PACKETS)) +done + +# check if the final nft counter matches our counter +TOTAL_COUNT=$(ip netns exec peer0 nft list chain inet filter output | sed -n 's/.*packets \([0-9]*\).*/\1/p') +[ ${DROP_COUNTER} -eq ${TOTAL_COUNT} ] || exit 1
Maybe add something like
echo "Expected ${TOTAL_COUNT} drops, got ${DROP_COUNTER}"if we're failing at this stage?
Quoted 12 lines
tools/testing/selftests/net/ovpn/test-mark.sh new file +12
-0+ +echo "Removing the drop rule" +ip netns exec peer0 nft flush ruleset +sleep 1 + +for p in $(seq 1 3); do + ip netns exec peer0 ping -qfc 500 -s 3000 -w 3 5.5.5.$((${p} + 1)) +done + +cleanup + +modprobe -r ovpn || true
Signature · 1 line
Sabrina
Ralf Lici
reviewerRe: [RFC net-next 08/13] selftests: ovpn: add test for the FW mark feature
Quoted 18 lines · Sabrina Dubroca
Quoted 17 lines · Antonio Quartulli
tools/testing/selftests/net/ovpn/ovpn-cli.c +0
-0@@ -1693,12 +1705,13 @@ static void usage(const char *cmd) fprintf(stderr, "\tvpnaddr: peer VPN IP\n");
fprintf(stderr,tools/testing/selftests/net/ovpn/ovpn-cli.c +0
-1- "* new_multi_peer <iface> <lport> <peers_file>: addmultiple peers as listed in the file\n");
tools/testing/selftests/net/ovpn/ovpn-cli.c +1
-0+ "* new_multi_peer <iface> <lport> <peers_file>[mark]: add multiple peers as listed in the file\n");
fprintf(stderr, "\tiface: ovpn interface name\n");fprintf(stderr, "\tlport: local UDP port to bind to\n"); fprintf(stderr,
"\tpeers_file: text file containing one peer per
Quoted 8 lines
Quoted 5 lines
line. Line format:\n");
tools/testing/selftests/net/ovpn/ovpn-cli.c +0
-1- fprintf(stderr, "\t\t<peer_id> <tx_id> <raddr> <rport><laddr> <lport> <vpnaddr>\n");
tools/testing/selftests/net/ovpn/ovpn-cli.c +1
-0+ fprintf(stderr, "\t\t<peer_id> <tx_id> <raddr> <rport><laddr> <lport> <vpnaddr> [mark]\n");
This line should be dropped, this patch doesn't have the corresponding change to parse mark while we're looping over the lines of
peers_file.
Right, the usage() strings can sometimes be a bit hard to visually parse.
Quoted 8 lines
Quoted 7 lines
tools/testing/selftests/net/ovpn/test-mark.sh new file +0
-0[...]
Quoted 14 lines
Quoted 11 lines
tools/testing/selftests/net/ovpn/test-mark.sh new file +10
-0+for p in $(seq 1 3); 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 3); do + ip netns exec peer0 ping -qfc 500 -s 3000 -w 35.5.5.$((${p} + 1))
Any reason this ping (and the final one) uses -s 3000 while the one we expect to fail doesn't?
No, I think it's a copy-paste leftover. I'll drop this option since it doesn’t add much value to the test.
Quoted 14 lines
Quoted 14 lines
tools/testing/selftests/net/ovpn/test-mark.sh new file +6
-0+done + +echo "Adding an nftables drop rule based on mark value ${MARK}" +ip netns exec peer0 nft flush ruleset +ip netns exec peer0 nft 'add table inet filter' +ip netns exec peer0 nft 'add chain inet filter output { type filterhook output priority 0; policy accept; }'
+ip netns exec peer0 nft add rule inet filter output meta mark == ${MARK} counter droptools/testing/selftests/net/ovpn/test-mark.sh new file +2
-0+ +DROP_COUNTER=$(ip netns exec peer0 nft list chain inet filteroutput | sed -n 's/.*packets \([0-9]*\).*/\1/p')
+sleep 1
Quoted 8 lines
Quoted 5 lines
tools/testing/selftests/net/ovpn/test-mark.sh new file +4
-0+ +# ping should fail +for p in $(seq 1 3); do + PING_OUTPUT=$(ip netns exec peer0 ping -qfc 500 -w 15.5.5.$((p+1)) 2>&1) && exit 1
nit: inconsistent syntax for p+1 compared to the other pings ($((p+1)) vs $((${p} + 1)))
Ok, I'll keep a consistent style for pre-existing files and follow shellcheck's suggestions for new ones. Later we can then cleanup the existing shellcheck warning on the older files.
Quoted 16 lines
Quoted 10 lines
tools/testing/selftests/net/ovpn/test-mark.sh new file +2
-0+ echo "${PING_OUTPUT}" + LOST_PACKETS=$(echo "$PING_OUTPUT" | grep 'packetstransmitted' | awk '{ print $1 }')
tools/testing/selftests/net/ovpn/test-mark.sh new file +6
-0+ # increment the drop counter by the amount of lost packets + DROP_COUNTER=$(($DROP_COUNTER+$LOST_PACKETS)) +done + +# check if the final nft counter matches our counter +TOTAL_COUNT=$(ip netns exec peer0 nft list chain inet filter outputQuoted 2 lines
| sed -n 's/.*packets \([0-9]*\).*/\1/p')
+[ ${DROP_COUNTER} -eq ${TOTAL_COUNT} ] || exit 1Maybe add something like
echo "Expected ${TOTAL_COUNT} drops, got ${DROP_COUNTER}" if we're failing at this stage?
ACK.
Quoted 13 lines
Quoted 13 lines
tools/testing/selftests/net/ovpn/test-mark.sh new file +7
-0+ +echo "Removing the drop rule" +ip netns exec peer0 nft flush ruleset +sleep 1 + +for p in $(seq 1 3); do + ip netns exec peer0 ping -qfc 500 -s 3000 -w 35.5.5.$((${p} + 1))
tools/testing/selftests/net/ovpn/test-mark.sh new file +5
-0+done + +cleanup + +modprobe -r ovpn || true
Signature · 2 lines
Ralf Lici Mandelbit Srl
Antonio Quartulli
maintainerRFC 9/13 ovpn: consolidate crypto allocations in one chunk
In reply to Antonio QuartulliFrom: Ralf Lici <[email protected]>
Currently ovpn uses three separate dynamically allocated structures to set up cryptographic operations for both encryption and decryption. This adds overhead to performance-critical paths and contribute to memory fragmentation.
This commit consolidates those allocations into a single temporary blob, similar to what esp_alloc_tmp() does.
The resulting performance gain is +7.7% and +4.3% for UDP when using AES and ChaChaPoly respectively, and +4.3% for TCP.
--- drivers/net/ovpn/crypto_aead.c | 160 +++++++++++++++++++++++++-------- drivers/net/ovpn/io.c | 8 +- drivers/net/ovpn/skb.h | 13 ++- 3 files changed, 135 insertions(+), 46 deletions(-)
drivers/net/ovpn/crypto_aead.c +123 -37
@@ -36,6 +36,104 @@ static int ovpn_aead_encap_overhead(const struct ovpn_crypto_key_slot *ks)crypto_aead_authsize (ks->encrypt);/* Auth Tag */ } +/** +* ovpn_aead_crypto_tmp_size - compute the size of a temporary object containing +* an AEAD request structure with extra space for SG +* and IV. +* @tfm: the AEAD cipher handle +* @nfrags: the number of fragments in the skb +* +* This function calculates the size of a contiguous memory block that includes +* the initialization vector (IV), the AEAD request, and an array of scatterlist +* entries. For alignment considerations, the IV is placed first, followed by +* the request, and then the scatterlist. +* Additional alignment is applied according to the requirements of the +* underlying structures. +* +* Return: the size of the temporary memory that needs to be allocated +*/ +static unsigned int ovpn_aead_crypto_tmp_size (struct crypto_aead *tfm, +const unsigned int nfrags) +{ +unsigned int len =OVPN_NONCE_SIZE ; + +DEBUG_NET_WARN_ON_ONCE (OVPN_NONCE_SIZE !=crypto_aead_ivsize (tfm)); + +/* min size for a buffer of ivsize, aligned to alignmask */ + len +=crypto_aead_alignmask (tfm) & ~(crypto_tfm_ctx_alignment () -1 ); +/* round up to the next multiple of the crypto ctx alignment */ + len =ALIGN (len,crypto_tfm_ctx_alignment ()); + +/* reserve space for the AEAD request */ + len +=sizeof (struct aead_request ) +crypto_aead_reqsize (tfm); +/* round up to the next multiple of the scatterlist alignment */ + len =ALIGN (len, __alignof__(struct scatterlist )); + +/* add enough space for nfrags + 2 scatterlist entries */ + len +=array_size (sizeof (struct scatterlist ), nfrags +2 ); +return len; +} + +/** +* ovpn_aead_crypto_tmp_iv - retrieve the pointer to the IV within a temporary +* buffer allocated using ovpn_aead_crypto_tmp_size +* @aead: the AEAD cipher handle +* @tmp: a pointer to the beginning of the temporary buffer +* +* This function retrieves a pointer to the initialization vector (IV) in the +* temporary buffer. If the AEAD cipher specifies an IV size, the pointer is +* adjusted using the AEAD's alignment mask to ensure proper alignment. +* +* Returns: a pointer to the IV within the temporary buffer +*/ +static u8 *ovpn_aead_crypto_tmp_iv (struct crypto_aead *aead,void *tmp) +{ +return likely (crypto_aead_ivsize (aead)) ? +PTR_ALIGN ((u8 *)tmp,crypto_aead_alignmask (aead) +1 ) : + tmp; +} + +/** +* ovpn_aead_crypto_tmp_req - retrieve the pointer to the AEAD request structure +* within a temporary buffer allocated using +* ovpn_aead_crypto_tmp_size +* @aead: the AEAD cipher handle +* @iv: a pointer to the initialization vector in the temporary buffer +* +* This function computes the location of the AEAD request structure that +* immediately follows the IV in the temporary buffer and it ensures the request +* is aligned to the crypto transform context alignment. +* +* Returns: a pointer to the AEAD request structure +*/ +static struct aead_request *ovpn_aead_crypto_tmp_req (struct crypto_aead *aead, +const u8 *iv) +{ +return (void *)PTR_ALIGN (iv +crypto_aead_ivsize (aead), +crypto_tfm_ctx_alignment ()); +} + +/** +* ovpn_aead_crypto_req_sg - locate the scatterlist following the AEAD request +* within a temporary buffer allocated using +* ovpn_aead_crypto_tmp_size +* @aead: the AEAD cipher handle +* @req: a pointer to the AEAD request structure in the temporary buffer +* +* This function computes the starting address of the scatterlist that is +* allocated immediately after the AEAD request structure. It aligns the pointer +* based on the alignment requirements of the scatterlist structure. +* +* Returns: a pointer to the scatterlist +*/ +static struct scatterlist *ovpn_aead_crypto_req_sg (struct crypto_aead *aead, +struct aead_request *req) +{ +return (void *)ALIGN ((unsigned long )(req +1 ) + +crypto_aead_reqsize (aead), + __alignof__(struct scatterlist )); +} +int ovpn_aead_encrypt (struct ovpn_peer *peer,struct ovpn_crypto_key_slot *ks,struct sk_buff *skb) {
@@ -45,6 +143,7 @@ int ovpn_aead_encrypt(struct ovpn_peer *peer, struct ovpn_crypto_key_slot *ks,struct scatterlist *sg;int nfrags, ret;u32 pktid, op; +void *tmp;u8 *iv;ovpn_skb_cb (skb)->peer = peer;
@@ -71,13 +170,17 @@ int ovpn_aead_encrypt(struct ovpn_peer *peer, struct ovpn_crypto_key_slot *ks,if (unlikely (nfrags +2 > (MAX_SKB_FRAGS +2 )))return -ENOSPC ; -/* sg may be required by async crypto */ -ovpn_skb_cb (skb)->sg =kmalloc (sizeof (*ovpn_skb_cb (skb)->sg) * - (nfrags +2 ),GFP_ATOMIC ); -if (unlikely (!ovpn_skb_cb (skb)->sg)) +/* allocate temporary memory for iv, sg and req */ + tmp =kmalloc (ovpn_aead_crypto_tmp_size (ks->encrypt, nfrags), +GFP_ATOMIC ); +if (unlikely (!tmp))return -ENOMEM ; - sg =ovpn_skb_cb (skb)->sg; +ovpn_skb_cb (skb)->crypto_tmp = tmp; + + iv =ovpn_aead_crypto_tmp_iv (ks->encrypt, tmp); + req =ovpn_aead_crypto_tmp_req (ks->encrypt, iv); + sg =ovpn_aead_crypto_req_sg (ks->encrypt, req);/* sg table: * 0: op, wire nonce (AD, len=OVPN_OP_SIZE_V2+OVPN_NONCE_WIRE_SIZE),
@@ -105,13 +208,6 @@ int ovpn_aead_encrypt(struct ovpn_peer *peer, struct ovpn_crypto_key_slot *ks,if (unlikely (ret <0 ))return ret; -/* iv may be required by async crypto */ -ovpn_skb_cb (skb)->iv =kmalloc (OVPN_NONCE_SIZE ,GFP_ATOMIC ); -if (unlikely (!ovpn_skb_cb (skb)->iv)) -return -ENOMEM ; - - iv =ovpn_skb_cb (skb)->iv; -/* concat 4 bytes packet id and 8 bytes nonce tail into 12 bytes * nonce */
@@ -130,12 +226,6 @@ int ovpn_aead_encrypt(struct ovpn_peer *peer, struct ovpn_crypto_key_slot *ks,/* AEAD Additional data */ sg_set_buf (sg, skb->data,OVPN_AAD_SIZE ); - req =aead_request_alloc (ks->encrypt,GFP_ATOMIC ); -if (unlikely (!req)) -return -ENOMEM ; - -ovpn_skb_cb (skb)->req = req; -/* setup async crypto operation */ aead_request_set_tfm (req, ks->encrypt);aead_request_set_callback (req,0 , ovpn_encrypt_post, skb);
@@ -156,6 +246,7 @@ int ovpn_aead_decrypt(struct ovpn_peer *peer, struct ovpn_crypto_key_slot *ks,struct aead_request *req;struct sk_buff *trailer;struct scatterlist *sg; +void *tmp;u8 *iv; payload_offset =OVPN_AAD_SIZE + tag_size;
@@ -184,13 +275,17 @@ int ovpn_aead_decrypt(struct ovpn_peer *peer, struct ovpn_crypto_key_slot *ks,if (unlikely (nfrags +2 > (MAX_SKB_FRAGS +2 )))return -ENOSPC ; -/* sg may be required by async crypto */ -ovpn_skb_cb (skb)->sg =kmalloc (sizeof (*ovpn_skb_cb (skb)->sg) * - (nfrags +2 ),GFP_ATOMIC ); -if (unlikely (!ovpn_skb_cb (skb)->sg)) +/* allocate temporary memory for iv, sg and req */ + tmp =kmalloc (ovpn_aead_crypto_tmp_size (ks->decrypt, nfrags), +GFP_ATOMIC ); +if (unlikely (!tmp))return -ENOMEM ; - sg =ovpn_skb_cb (skb)->sg; +ovpn_skb_cb (skb)->crypto_tmp = tmp; + + iv =ovpn_aead_crypto_tmp_iv (ks->decrypt, tmp); + req =ovpn_aead_crypto_tmp_req (ks->decrypt, iv); + sg =ovpn_aead_crypto_req_sg (ks->decrypt, req);/* sg table: * 0: op, wire nonce (AD, len=OVPN_OPCODE_SIZE+OVPN_NONCE_WIRE_SIZE),
@@ -213,24 +308,11 @@ int ovpn_aead_decrypt(struct ovpn_peer *peer, struct ovpn_crypto_key_slot *ks,/* append auth_tag onto scatterlist */ sg_set_buf (sg + ret +1 , skb->data +OVPN_AAD_SIZE , tag_size); -/* iv may be required by async crypto */ -ovpn_skb_cb (skb)->iv =kmalloc (OVPN_NONCE_SIZE ,GFP_ATOMIC ); -if (unlikely (!ovpn_skb_cb (skb)->iv)) -return -ENOMEM ; - - iv =ovpn_skb_cb (skb)->iv; -/* copy nonce into IV buffer */ memcpy (iv, skb->data +OVPN_OPCODE_SIZE ,OVPN_NONCE_WIRE_SIZE );memcpy (iv +OVPN_NONCE_WIRE_SIZE , ks->nonce_tail_recv,OVPN_NONCE_TAIL_SIZE ); - req =aead_request_alloc (ks->decrypt,GFP_ATOMIC ); -if (unlikely (!req)) -return -ENOMEM ; - -ovpn_skb_cb (skb)->req = req; -/* setup async crypto operation */ aead_request_set_tfm (req, ks->decrypt);aead_request_set_callback (req,0 , ovpn_decrypt_post, skb);
@@ -273,7 +355,11 @@ static struct crypto_aead *ovpn_aead_init(const char *title, goto error; } -/* basic AEAD assumption */ +/* basic AEAD assumption +* all current algorithms use OVPN_NONCE_SIZE. +* ovpn_aead_crypto_tmp_size and ovpn_aead_encrypt/decrypt +* expect this. +*/ if (crypto_aead_ivsize (aead) !=OVPN_NONCE_SIZE ) {pr_err ("%s IV size must be %d\n" , title,OVPN_NONCE_SIZE ); ret = -EINVAL ;
drivers/net/ovpn/io.c +2 -6
@@ -119,9 +119,7 @@ void ovpn_decrypt_post(void *data, int ret) peer =ovpn_skb_cb (skb)->peer;/* crypto is done, cleanup skb CB and its members */ -kfree (ovpn_skb_cb (skb)->iv); -kfree (ovpn_skb_cb (skb)->sg); -aead_request_free (ovpn_skb_cb (skb)->req); +kfree (ovpn_skb_cb (skb)->crypto_tmp);if (unlikely (ret <0 )) goto drop;
@@ -248,9 +246,7 @@ void ovpn_encrypt_post(void *data, int ret) peer =ovpn_skb_cb (skb)->peer;/* crypto is done, cleanup skb CB and its members */ -kfree (ovpn_skb_cb (skb)->iv); -kfree (ovpn_skb_cb (skb)->sg); -aead_request_free (ovpn_skb_cb (skb)->req); +kfree (ovpn_skb_cb (skb)->crypto_tmp);if (unlikely (ret == -ERANGE )) {/* we ran out of IVs and we must kill the key as it can't be
drivers/net/ovpn/skb.h +10 -3
@@ -18,12 +18,19 @@#include <linux/socket.h> #include <linux/types.h> +/** +* struct ovpn_cb - ovpn skb control block +* @peer: the peer this skb was received from/sent to +* @ks: the crypto key slot used to encrypt/decrypt this skb +* @crypto_tmp: pointer to temporary memory used for crypto operations +* containing the IV, the scatter gather list and the aead request +* @payload_offset: offset in the skb where the payload starts +* @nosignal: whether this skb should be sent with the MSG_NOSIGNAL flag (TCP) +*/ struct ovpn_cb {struct ovpn_peer *peer;struct ovpn_crypto_key_slot *ks; -struct aead_request *req; -struct scatterlist *sg; -u8 *iv; +void *crypto_tmp;unsigned int payload_offset;bool nosignal; };
Signature · 1 line
2.51.2
Antonio Quartulli
maintainerRFC 10/13 ovpn: use bound device in UDP when available
In reply to Antonio QuartulliFrom: Ralf Lici <[email protected]>
Use the socket’s bound network interface if it’s explicitly specified via the --bind-dev option in openvpn.
--- drivers/net/ovpn/udp.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
drivers/net/ovpn/udp.c +3 -1
@@ -154,6 +154,7 @@ static int ovpn_udp4_output(struct ovpn_peer *peer, struct ovpn_bind *bind, .fl4_dport = bind->remote.in4.sin_port, .flowi4_proto = sk->sk_protocol, .flowi4_mark = sk->sk_mark, + .flowi4_oif = sk->sk_bound_dev_if, };int ret;
@@ -231,7 +232,8 @@ static int ovpn_udp6_output(struct ovpn_peer *peer, struct ovpn_bind *bind, .fl6_dport = bind->remote.in6.sin6_port, .flowi6_proto = sk->sk_protocol, .flowi6_mark = sk->sk_mark, - .flowi6_oif = bind->remote.in6.sin6_scope_id, + .flowi6_oif = sk->sk_bound_dev_if ?: + bind->remote.in6.sin6_scope_id, };local_bh_disable ();
Signature · 1 line
2.51.2
Antonio Quartulli
maintainerRFC 11/13 selftests: ovpn: add test for bound device
In reply to Antonio QuartulliFrom: Ralf Lici <[email protected]>
Add a selftest to verify that when a socket is bound to a device, UDP traffic from ovpn is correctly routed through the specified interface.
The test sets up a P2P session between two peers in separate network namespaces, connected via two veth pairs. It binds to both veth interfaces and uses tcpdump to confirm that traffic flows through the expected paths.
--- tools/testing/selftests/net/ovpn/Makefile | 1 + tools/testing/selftests/net/ovpn/common.sh | 6 +- tools/testing/selftests/net/ovpn/ovpn-cli.c | 39 +++++-- tools/testing/selftests/net/ovpn/test-bind.sh | 103 ++++++++++++++++++ tools/testing/selftests/net/ovpn/test-mark.sh | 2 +- 5 files changed, 137 insertions(+), 14 deletions(-) create mode 100755 tools/testing/selftests/net/ovpn/test-bind.sh
tools/testing/selftests/net/ovpn/Makefile +1 -0
@@ -26,6 +26,7 @@ LDLIBS += $(NL_LDLIBS) TEST_FILES = common.sh TEST_PROGS := \ + test-bind.sh \ test-chachapoly.sh \ test-close-socket-tcp.sh \ test-close-socket.sh \
tools/testing/selftests/net/ovpn/common.sh +4 -2
@@ -66,9 +66,11 @@ setup_listener() { } add_peer() { + dev=${2:-"any"} + if [ "${PROTO}" == "UDP" ]; then if [ ${1} -eq 0 ]; then - ip netns exec peer0 ${OVPN_CLI} new_multi_peer tun0 1 ${UDP_PEERS_FILE} + ip netns exec peer0 ${OVPN_CLI} new_multi_peer tun0 ${dev} 1 ${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 \
@@ -79,7 +81,7 @@ add_peer() { 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}) - ip netns exec peer${1} ${OVPN_CLI} new_peer tun${1} ${TX_ID} ${1} \ + ip netns exec peer${1} ${OVPN_CLI} new_peer tun${1} ${dev} ${TX_ID} ${1} \ ${LPORT} ${RADDR} ${RPORT} ip netns exec peer${1} ${OVPN_CLI} new_key tun${1} ${TX_ID} 1 0 \ ${ALG} 1 data64.key
tools/testing/selftests/net/ovpn/ovpn-cli.c +28 -11
@@ -135,6 +135,7 @@ struct ovpn_ctx {int key_id;uint32_t mark; +const char *bind_dev;const char *peers_file; };
@@ -542,6 +543,14 @@ static int ovpn_socket(struct ovpn_ctx *ctx, sa_family_t family, int proto) } } +if (ctx->bind_dev) { +if (setsockopt (s,SOL_SOCKET ,SO_BINDTODEVICE , ctx->bind_dev, +strlen (ctx->bind_dev) +1 ) !=0 ) { +perror ("setsockopt for SO_BINDTODEVICE" ); +return -1 ; + } + } + ret =bind (s, (struct sockaddr *)&local_sock, sock_len);if (ret <0 ) {perror ("cannot bind socket" );
@@ -1693,8 +1702,10 @@ static void usage(const char *cmd) "\tkey_file: file containing the symmetric key for encryption\n");fprintf (stderr, -"* new_peer <iface> <peer_id> <tx_id> <lport> <raddr> <rport> [vpnaddr]: add new peer\n" ); +"* new_peer <iface> <dev> <peer_id> <tx_id> <lport> <raddr> <rport> [vpnaddr]: add new peer\n" );fprintf (stderr,"\tiface: ovpn interface name\n" ); +fprintf (stderr, +"\tdev: transport interface name to bind to, supports 'any'\n" );fprintf (stderr,"\tlport: local UDP port to bind to\n" );fprintf (stderr,"\tpeer_id: peer ID found in data packets received from this peer\n" );
@@ -1705,8 +1716,10 @@ static void usage(const char *cmd)fprintf (stderr,"\tvpnaddr: peer VPN IP\n" );fprintf (stderr, -"* new_multi_peer <iface> <lport> <peers_file> [mark]: add multiple peers as listed in the file\n" ); +"* new_multi_peer <iface> <dev> <lport> <peers_file> [mark]: add multiple peers as listed in the file\n" );fprintf (stderr,"\tiface: ovpn interface name\n" ); +fprintf (stderr, +"\tdev: transport interface name to bind to, supports 'any'\n" );fprintf (stderr,"\tlport: local UDP port to bind to\n" );fprintf (stderr,"\tpeers_file: text file containing one peer per line. Line format:\n" );
@@ -2227,37 +2240,41 @@ static int ovpn_parse_cmd_args(struct ovpn_ctx *ovpn, int argc, char *argv[]) }break ;case CMD_NEW_PEER : -if (argc <7 ) +if (argc <8 )return -EINVAL ; - ovpn->lport =strtoul (argv[5 ],NULL ,10 ); + ovpn->bind_dev =strcmp (argv[3 ],"any" ) ==0 ?NULL : argv[3 ]; + + ovpn->lport =strtoul (argv[6 ],NULL ,10 );if (errno ==ERANGE || ovpn->lport >65535 ) {fprintf (stderr,"lport value out of range\n" );return -1 ; } -const char *vpnip = (argc >8 ) ? argv[8 ] :NULL ; +const char *vpnip = (argc >9 ) ? argv[9 ] :NULL ; - ret =ovpn_parse_new_peer (ovpn, argv[3 ], argv[4 ], argv[6 ], argv[7 ], + ret =ovpn_parse_new_peer (ovpn, argv[4 ], argv[5 ], argv[7 ], argv[8 ], vpnip);if (ret <0 )return -1 ;break ;case CMD_NEW_MULTI_PEER : -if (argc <5 ) +if (argc <6 )return -EINVAL ; - ovpn->lport =strtoul (argv[3 ],NULL ,10 ); + ovpn->bind_dev =strcmp (argv[3 ],"any" ) ==0 ?NULL : argv[3 ]; + + ovpn->lport =strtoul (argv[4 ],NULL ,10 );if (errno ==ERANGE || ovpn->lport >65535 ) {fprintf (stderr,"lport value out of range\n" );return -1 ; } - ovpn->peers_file = argv[4 ]; + ovpn->peers_file = argv[5 ]; ovpn->mark =0 ; -if (argc >5 ) { - ovpn->mark =strtoul (argv[5 ],NULL ,10 ); +if (argc >6 ) { + ovpn->mark =strtoul (argv[6 ],NULL ,10 );if (errno ==ERANGE || ovpn->mark >UINT32_MAX ) {fprintf (stderr,"mark value out of range\n" );return -1 ;
tools/testing/selftests/net/ovpn/test-bind.sh new file +103 -0
103 lines not on this page · raw message
tools/testing/selftests/net/ovpn/test-mark.sh +1 -1
@@ -26,7 +26,7 @@ for p in $(seq 0 3); do done # add peer0 with mark -ip netns exec peer0 ${OVPN_CLI} new_multi_peer tun0 1 ${UDP_PEERS_FILE} ${MARK} +ip netns exec peer0 ${OVPN_CLI} new_multi_peer tun0 any 1 ${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 data64.key done
Signature · 1 line
2.51.2
Sabrina Dubroca
reviewerRe: [RFC net-next 11/13] selftests: ovpn: add test for bound device
Quoted 9 lines · Antonio Quartulli
From: Ralf Lici <[email protected]>
Add a selftest to verify that when a socket is bound to a device, UDP traffic from ovpn is correctly routed through the specified interface.
The test sets up a P2P session between two peers in separate network namespaces, connected via two veth pairs. It binds to both veth interfaces and uses tcpdump to confirm that traffic flows through the expected paths.
The current setup doesn't really test that, since it would also work without SO_BINDTODEVICE (traffic still flows through the expected veth if I pass "any" instead of veth1/veth2 to the new_peer commands).
[...]
tools/testing/selftests/net/ovpn/common.sh setup_listener() { · line 69
Quoted 9 lines
tools/testing/selftests/net/ovpn/common.sh +1
-0@@ -66,9 +66,11 @@ setup_listener() { } add_peer() { + dev=${2:-"any"}
nit: no user of add_peer is patched to pass this extra argument
Quoted 6 lines
tools/testing/selftests/net/ovpn/test-bind.sh new file +0
-0@@ -0,0 +1,103 @@
[...]
Quoted 14 lines
tools/testing/selftests/net/ovpn/test-bind.sh new file +14
-0+run_bind_test() { + dev1=${1} + dev2=${2} + raddr4_peer1=${3} + raddr4_peer2=${4} + + touch /tmp/ovpn-bind1.log + touch /tmp/ovpn-bind2.log + + ip netns exec peer1 ${OVPN_CLI} del_peer tun1 1 2>/dev/null || true + ip netns exec peer2 ${OVPN_CLI} del_peer tun2 10 2>/dev/null || true + + # close any active socket + killall $(basename ${OVPN_CLI}) 2>/dev/null || true
tools/testing/selftests/net/ovpn/test-bind.sh line 72
Quoted 10 lines
tools/testing/selftests/net/ovpn/test-bind.sh new file +10
-0+ + ip netns exec peer1 ${OVPN_CLI} new_peer tun1 ${dev1} 1 10 1 ${raddr4_peer1} 1 + ip netns exec peer1 ${OVPN_CLI} new_key tun1 1 1 0 ${ALG} 0 data64.key + ip netns exec peer2 ${OVPN_CLI} new_peer tun2 ${dev2} 10 1 1 ${raddr4_peer2} 1 + ip netns exec peer2 ${OVPN_CLI} new_key tun2 10 1 0 ${ALG} 1 data64.key + + ip netns exec peer1 ${OVPN_CLI} set_peer tun1 1 60 120 + ip netns exec peer2 ${OVPN_CLI} set_peer tun2 10 60 120 + + timeout 2 ip netns exec peer1 tcpdump -i veth1 "${PROTO,,}" port 1 -n -q > /tmp/ovpn-bind1.log &
Maybe add
2> /dev/null
to clean up a bit the script output?
Quoted 18 lines
tools/testing/selftests/net/ovpn/test-bind.sh new file +18
-0+ tcpdump1_pid=$! + timeout 2 ip netns exec peer1 tcpdump -i veth2 "${PROTO,,}" port 1 -n -q > /tmp/ovpn-bind2.log & + tcpdump2_pid=$! + sleep 0.5 + + ip netns exec peer1 ping -qfc 50 -w 1 5.5.5.2 + + wait ${tcpdump1_pid} || true + wait ${tcpdump2_pid} || true +} + +run_bind_test veth1 any 10.10.10.2 10.10.10.1 +[ "$(grep -c -i udp /tmp/ovpn-bind1.log)" -ge 100 ] +[ "$(grep -c -i udp /tmp/ovpn-bind2.log)" -eq 0 ] + +run_bind_test veth2 any 20.20.20.2 20.20.20.1 +[ "$(grep -c -i udp /tmp/ovpn-bind2.log)" -ge 100 ] +[ "$(grep -c -i udp /tmp/ovpn-bind1.log)" -eq 0 ]
tools/testing/selftests/net/ovpn/test-bind.sh line 100
Quoted 10 lines
tools/testing/selftests/net/ovpn/test-bind.sh new file +10
-0+ +run_bind_test any veth1 10.10.10.2 10.10.10.1 +[ "$(grep -c -i udp /tmp/ovpn-bind1.log)" -ge 100 ] +[ "$(grep -c -i udp /tmp/ovpn-bind2.log)" -eq 0 ] + +run_bind_test any veth2 20.20.20.2 20.20.20.1 +[ "$(grep -c -i udp /tmp/ovpn-bind2.log)" -ge 100 ] +[ "$(grep -c -i udp /tmp/ovpn-bind1.log)" -eq 0 ] + +cleanup
And also clean up the log files? (maybe via "trap <function> EXIT" so that they get removed as well if the test fails)
Signature · 1 line
Sabrina
Ralf Lici
reviewerRe: [RFC net-next 11/13] selftests: ovpn: add test for bound device
Quoted 14 lines · Sabrina Dubroca
Quoted 7 lines · Antonio Quartulli
From: Ralf Lici <[email protected]>
Add a selftest to verify that when a socket is bound to a device, UDP
traffic from ovpn is correctly routed through the specified interface.Quoted 5 lines
The test sets up a P2P session between two peers in separate network namespaces, connected via two veth pairs. It binds to both veth interfaces and uses tcpdump to confirm that traffic flows through the
expected paths.
Quoted 3 lines
The current setup doesn't really test that, since it would also work without
SO_BINDTODEVICE(traffic still flows through the expected veth if I pass "any" instead of veth1/veth2 to thenew_peercommands).
Thanks for catching this. I see the issue and will try a different approach in the next version of the patch.
Quoted 13 lines
[...]
tools/testing/selftests/net/ovpn/common.sh setup_listener() { · line 69
Quoted 10 lines
tools/testing/selftests/net/ovpn/common.sh +0
-0@@ -66,9 +66,11 @@ setup_listener() { }
add_peer() {tools/testing/selftests/net/ovpn/common.sh +1
-0+ dev=${2:-"any"}nit: no user of
add_peeris patched to pass this extra argument
Yes, I initially considered using this function for test-bind.sh but later abandoned the idea. I'll remove the argument since it's not needed.
Quoted 35 lines
Quoted 7 lines
tools/testing/selftests/net/ovpn/test-bind.sh new file +0
-0@@ -0,0 +1,103 @@[...]
Quoted 27 lines
tools/testing/selftests/net/ovpn/test-bind.sh new file +10
-0+run_bind_test() { + dev1=${1} + dev2=${2} + raddr4_peer1=${3} + raddr4_peer2=${4} + + touch /tmp/ovpn-bind1.log + touch /tmp/ovpn-bind2.log + + ip netns exec peer1 ${OVPN_CLI} del_peer tun1 1 2>/dev/null|| true
tools/testing/selftests/net/ovpn/test-bind.sh new file +1
-0+ ip netns exec peer2 ${OVPN_CLI} del_peer tun2 102>/dev/null || true
tools/testing/selftests/net/ovpn/test-bind.sh new file +5
-0+ + # close any active socket + killall $(basename ${OVPN_CLI}) 2>/dev/null || true + + ip netns exec peer1 ${OVPN_CLI} new_peer tun1 ${dev1} 1 101 ${raddr4_peer1} 1
tools/testing/selftests/net/ovpn/test-bind.sh new file +1
-0+ ip netns exec peer1 ${OVPN_CLI} new_key tun1 1 1 0 ${ALG} 0data64.key
tools/testing/selftests/net/ovpn/test-bind.sh new file +1
-0+ ip netns exec peer2 ${OVPN_CLI} new_peer tun2 ${dev2} 10 11 ${raddr4_peer2} 1
tools/testing/selftests/net/ovpn/test-bind.sh new file +1
-0+ ip netns exec peer2 ${OVPN_CLI} new_key tun2 10 1 0 ${ALG}1 data64.key
tools/testing/selftests/net/ovpn/test-bind.sh new file +2
-0+ + ip netns exec peer1 ${OVPN_CLI} set_peer tun1 1 60 120
Quoted 8 lines
Quoted 4 lines
tools/testing/selftests/net/ovpn/test-bind.sh new file +3
-0+ ip netns exec peer2 ${OVPN_CLI} set_peer tun2 10 60 120 + + timeout 2 ip netns exec peer1 tcpdump -i veth1 "${PROTO,,}"port 1 -n -q >
/tmp/ovpn-bind1.log&Maybe add
2>/dev/null
to clean up a bit the script output?
ACK.
Quoted 24 lines
Quoted 24 lines
tools/testing/selftests/net/ovpn/test-bind.sh new file +2
-0+ tcpdump1_pid=$! + timeout 2 ip netns exec peer1 tcpdump -i veth2 "${PROTO,,}"port 1 -n -q >
/tmp/ovpn-bind2.log&tools/testing/selftests/net/ovpn/test-bind.sh new file +21
-0+ tcpdump2_pid=$! + sleep 0.5 + + ip netns exec peer1 ping -qfc 50 -w 1 5.5.5.2 + + wait ${tcpdump1_pid} || true + wait ${tcpdump2_pid} || true +} + +run_bind_test veth1 any 10.10.10.2 10.10.10.1 +[ "$(grep -c -i udp /tmp/ovpn-bind1.log)" -ge 100 ] +[ "$(grep -c -i udp /tmp/ovpn-bind2.log)" -eq 0 ] + +run_bind_test veth2 any 20.20.20.2 20.20.20.1 +[ "$(grep -c -i udp /tmp/ovpn-bind2.log)" -ge 100 ] +[ "$(grep -c -i udp /tmp/ovpn-bind1.log)" -eq 0 ] + +run_bind_test any veth1 10.10.10.2 10.10.10.1 +[ "$(grep -c -i udp /tmp/ovpn-bind1.log)" -ge 100 ] +[ "$(grep -c -i udp /tmp/ovpn-bind2.log)" -eq 0 ] +
Quoted 8 lines
tools/testing/selftests/net/ovpn/test-bind.sh line 100
Quoted 5 lines
tools/testing/selftests/net/ovpn/test-bind.sh new file +5
-0+run_bind_test any veth2 20.20.20.2 20.20.20.1 +[ "$(grep -c -i udp /tmp/ovpn-bind2.log)" -ge 100 ] +[ "$(grep -c -i udp /tmp/ovpn-bind1.log)" -eq 0 ] + +cleanupAnd also clean up the log files? (maybe via "trap <function> EXIT" so that they get removed as well if the test fails)
ACK.
Signature · 2 lines
Ralf Lici Mandelbit Srl
Antonio Quartulli
maintainerRFC 12/13 ovpn: use bound address in UDP when available
In reply to Antonio QuartulliFrom: Ralf Lici <[email protected]>
Use the socket's locally bound address if it's explicitly specified via the --local option in openvpn.
--- drivers/net/ovpn/udp.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-)
drivers/net/ovpn/udp.c +4 -2
@@ -148,7 +148,7 @@ static int ovpn_udp4_output(struct ovpn_peer *peer, struct ovpn_bind *bind, {struct rtable *rt;struct flowi4 fl = { - .saddr = bind->local.ipv4.s_addr, + .saddr =inet_sk (sk)->inet_rcv_saddr ?: bind->local.ipv4.s_addr, .daddr = bind->remote.in4.sin_addr.s_addr, .fl4_sport =inet_sk (sk)->inet_sport, .fl4_dport = bind->remote.in4.sin_port,
@@ -226,7 +226,9 @@ static int ovpn_udp6_output(struct ovpn_peer *peer, struct ovpn_bind *bind,int ret;struct flowi6 fl = { - .saddr = bind->local.ipv6, + .saddr =ipv6_addr_any (&sk->sk_v6_rcv_saddr) ? + bind->local.ipv6 : + sk->sk_v6_rcv_saddr, .daddr = bind->remote.in6.sin6_addr, .fl6_sport =inet_sk (sk)->inet_sport, .fl6_dport = bind->remote.in6.sin6_port,
Signature · 1 line
2.51.2
Antonio Quartulli
maintainerRFC 13/13 selftests: ovpn: add test for bound address
In reply to Antonio QuartulliFrom: Ralf Lici <[email protected]>
Add a selftest to verify that when a socket is bound to a local address, UDP traffic from ovpn is correctly routed through that address.
This test extends test-bind.sh by binding to the addresses on each veth pair and uses tcpdump to confirm that traffic flows as expected.
--- tools/testing/selftests/net/ovpn/Makefile | 1 + tools/testing/selftests/net/ovpn/common.sh | 6 +- tools/testing/selftests/net/ovpn/ovpn-cli.c | 202 +++++++++--------- .../selftests/net/ovpn/test-bind-addr.sh | 10 + tools/testing/selftests/net/ovpn/test-bind.sh | 52 +++-- tools/testing/selftests/net/ovpn/test-mark.sh | 2 +- 6 files changed, 152 insertions(+), 121 deletions(-) create mode 100755 tools/testing/selftests/net/ovpn/test-bind-addr.sh
tools/testing/selftests/net/ovpn/Makefile +1 -0
@@ -26,6 +26,7 @@ LDLIBS += $(NL_LDLIBS) TEST_FILES = common.sh TEST_PROGS := \ + test-bind-addr.sh \ test-bind.sh \ test-chachapoly.sh \ test-close-socket-tcp.sh \
tools/testing/selftests/net/ovpn/common.sh +4 -2
@@ -67,10 +67,12 @@ setup_listener() { add_peer() { dev=${2:-"any"} + laddr=${3:-"any"} if [ "${PROTO}" == "UDP" ]; then if [ ${1} -eq 0 ]; then - ip netns exec peer0 ${OVPN_CLI} new_multi_peer tun0 ${dev} 1 ${UDP_PEERS_FILE} + ip netns exec peer0 ${OVPN_CLI} new_multi_peer tun0 ${dev} ${laddr} \ + 1 ${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 \
@@ -82,7 +84,7 @@ add_peer() { RPORT=$(awk "NR == ${1} {print \$4}" ${UDP_PEERS_FILE}) LPORT=$(awk "NR == ${1} {print \$6}" ${UDP_PEERS_FILE}) ip netns exec peer${1} ${OVPN_CLI} new_peer tun${1} ${dev} ${TX_ID} ${1} \ - ${LPORT} ${RADDR} ${RPORT} + ${laddr} ${LPORT} ${RADDR} ${RPORT} ip netns exec peer${1} ${OVPN_CLI} new_key tun${1} ${TX_ID} 1 0 \ ${ALG} 1 data64.key fi
tools/testing/selftests/net/ovpn/ovpn-cli.c +103 -99
348 lines not on this page · raw message
tools/testing/selftests/net/ovpn/test-bind-addr.sh new file +10 -0
@@ -0,0 +1,10 @@ +#!/bin/bash +# SPDX-License-Identifier: GPL-2.0 +# Copyright (C) 2020-2025 OpenVPN, Inc. +# +# Author: Ralf Lici <[email protected]> +# Antonio Quartulli <[email protected]> + +BIND_TYPE="ADDR" + +source test-bind.sh
tools/testing/selftests/net/ovpn/test-bind.sh +33 -19
77 lines not on this page · raw message
tools/testing/selftests/net/ovpn/test-mark.sh +1 -1
@@ -26,7 +26,7 @@ for p in $(seq 0 3); do done # add peer0 with mark -ip netns exec peer0 ${OVPN_CLI} new_multi_peer tun0 any 1 ${UDP_PEERS_FILE} ${MARK} +ip netns exec peer0 ${OVPN_CLI} new_multi_peer tun0 any any 1 ${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 data64.key done
Signature · 1 line
2.51.2
Sabrina Dubroca
reviewerRe: [RFC net-next 13/13] selftests: ovpn: add test for bound address
Quoted 7 lines · Antonio Quartulli
From: Ralf Lici <[email protected]>
Add a selftest to verify that when a socket is bound to a local address, UDP traffic from ovpn is correctly routed through that address.
This test extends
test-bind.shby binding to the addresses on each veth pair and uses tcpdump to confirm that traffic flows as expected.
Same as the other bind scenario, the test works even if we don't bind to that address.
A few small comments on the implementation:
tools/testing/selftests/net/ovpn/ovpn-cli.c static int ovpn_socket(struct ovpn_ctx *ctx, sa_family_t family, int proto) · line 521
Quoted 6 lines
tools/testing/selftests/net/ovpn/ovpn-cli.c +1
-1@@ -547,45 +518,83 @@ static int ovpn_socket(struct ovpn_ctx *ctx, sa_family_t family, int proto)if (setsockopt (s,SOL_SOCKET ,SO_BINDTODEVICE , ctx->bind_dev,strlen (ctx->bind_dev) +1 ) !=0 ) {perror ("setsockopt for SO_BINDTODEVICE" ); -return -1 ; + goto close;
ret isn't reset here, ovpn_socket will return a stale value.
Quoted 13 lines
tools/testing/selftests/net/ovpn/ovpn-cli.c +6
-4} } - ret =bind (s, (struct sockaddr *)&local_sock, sock_len); -if (ret <0 ) { -perror ("cannot bind socket" ); - goto err_socket; +return s; +close: +close (s); +return ret; +} +
[...]
tools/testing/selftests/net/ovpn/ovpn-cli.c static int ovpn_parse_cmd_args(struct ovpn_ctx *ovpn, int argc, char *argv[]) · line 2232
Quoted 6 lines
tools/testing/selftests/net/ovpn/ovpn-cli.c +2
-0@@ -2221,6 +2228,9 @@ static int ovpn_parse_cmd_args(struct ovpn_ctx *ovpn, int argc, char *argv[]) ovpn->sa_family =AF_INET ; + ovpn->laddr =NULL ; + ovpn->lport ="1" ;
Why do we want lport=1 on the CONNECT side now?
Quoted 4 lines
tools/testing/selftests/net/ovpn/ovpn-cli.c +1
-0+ ret =ovpn_parse_new_peer (ovpn, argv[3 ], argv[4 ], argv[5 ], argv[6 ],NULL );if (ret <0 ) {
Signature · 1 line
Sabrina
Ralf Lici
reviewerRe: [RFC net-next 13/13] selftests: ovpn: add test for bound address
Quoted 7 lines · Sabrina Dubroca
Quoted 6 lines · Antonio Quartulli
From: Ralf Lici <[email protected]>
Add a selftest to verify that when a socket is bound to a local address,
UDP traffic from ovpn is correctly routed through that address.
Quoted 6 lines
Quoted 3 lines
This test extends
test-bind.shby binding to the addresses on each veth
pair and uses tcpdump to confirm that traffic flows as expected.Same as the other bind scenario, the test works even if we don't bind to that address.
Right, will fix this test as well on the next version.
Quoted 5 lines
A few small comments on the implementation:
Quoted 3 lines
(quoted diff) +0
-0@@ -547,45 +518,83 @@ static int ovpn_socket(struct ovpn_ctx *ctx, sa_family_t family, int proto)if (setsockopt(s,
SOL_SOCKET,SO_BINDTODEVICE, ctx-
Quoted 7 lines
Review
Quoted 5 lines
Quoted 1 line
bind_dev,
strlen(ctx->bind_dev)+ 1) != 0) {perror("setsockopt for SO_BINDTODEVICE");(quoted diff) +1
-1- return -1; + goto close;ret isn't reset here,
ovpn_socketwill return a stale value.
ACK.
Quoted 15 lines
Quoted 14 lines
}
}tools/testing/selftests/net/ovpn/ovpn-cli.c +6
-4- ret =bind (s, (struct sockaddr *)&local_sock, sock_len); -if (ret <0 ) { -perror ("cannot bind socket" ); - goto err_socket; +return s; +close: +close (s); +return ret; +} +[...]
Quoted 9 lines
tools/testing/selftests/net/ovpn/ovpn-cli.c static int ovpn_parse_cmd_args(struct ovpn_ctx *ovpn, int argc, char *argv[]) · line 2232
Quoted 7 lines
(quoted diff) +0
-0@@ -2221,6 +2228,9 @@ static int ovpn_parse_cmd_args(struct ovpn_ctx *ovpn, int argc, char *argv[])
ovpn->sa_family=AF_INET;tools/testing/selftests/net/ovpn/ovpn-cli.c +2
-0+ ovpn->laddr =NULL ; + ovpn->lport ="1" ;Why do we want lport=1 on the CONNECT side now?
That's a mistake. I should have set "0" to let the kernel pick an ephemeral port.
Quoted 5 lines
Quoted 5 lines
+
ret = ovpn_parse_new_peer(ovpn, argv[3], argv[4], argv[5], argv[6],
NULL);
if (ret < 0) {
Thanks a lot!
Signature · 2 lines
Ralf Lici Mandelbit Srl