Skip to content

Commit 98a53f9

Browse files
ordexNipaLocal
authored andcommitted
testing/selftests: add test tool and scripts for ovpn module
The ovpn-cli tool can be compiled and used as selftest for the ovpn kernel module. [NOTE: it depends on libmedtls for decoding base64-encoded keys] ovpn-cli implements the netlink and RTNL APIs and can thus be integrated in any script for more automated testing. Along with the tool, a bunch of scripts are provided that perform basic functionality tests by means of network namespaces. These scripts take part to the kselftest automation. The output of the scripts, which will appear in the kselftest reports, is a list of steps performed by the scripts plus some output coming from the execution of `ping`, `iperf` and `ovpn-cli` itself. In general it is useful only in case of failure, in order to understand which step has failed and why. Please note: since peer sockets are tied to the userspace process that created them (i.e. exiting the process will result in closing the socket), every run of ovpn-cli that created one will go to background and enter pause(), waiting for the signal which will allow it to terminate. Termination is accomplished at the end of each script by issuing a killall command. Cc: linux-kselftest@vger.kernel.org Cc: Shuah Khan <skhan@linuxfoundation.org> Signed-off-by: Antonio Quartulli <antonio@openvpn.net> Signed-off-by: NipaLocal <nipa@local>
1 parent deded2b commit 98a53f9

File tree

16 files changed

+2722
-0
lines changed

16 files changed

+2722
-0
lines changed

MAINTAINERS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18136,6 +18136,7 @@ T: git https://github.com/OpenVPN/linux-kernel-ovpn.git
1813618136
F: Documentation/netlink/specs/ovpn.yaml
1813718137
F: drivers/net/ovpn/
1813818138
F: include/uapi/linux/ovpn.h
18139+
F: tools/testing/selftests/net/ovpn/
1813918140

1814018141
OPENVSWITCH
1814118142
M: Aaron Conole <aconole@redhat.com>

tools/testing/selftests/Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ TARGETS += net/hsr
7171
TARGETS += net/mptcp
7272
TARGETS += net/netfilter
7373
TARGETS += net/openvswitch
74+
TARGETS += net/ovpn
7475
TARGETS += net/packetdrill
7576
TARGETS += net/rds
7677
TARGETS += net/tcp_ao
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# SPDX-License-Identifier: GPL-2.0+
2+
ovpn-cli
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
# SPDX-License-Identifier: GPL-2.0
2+
# Copyright (C) 2020-2025 OpenVPN, Inc.
3+
#
4+
CFLAGS = -pedantic -Wextra -Wall -Wl,--no-as-needed -g -O0 -ggdb $(KHDR_INCLUDES)
5+
VAR_CFLAGS = $(shell pkg-config --cflags libnl-3.0 libnl-genl-3.0 2>/dev/null)
6+
ifeq ($(VAR_CFLAGS),)
7+
VAR_CFLAGS = -I/usr/include/libnl3
8+
endif
9+
CFLAGS += $(VAR_CFLAGS)
10+
11+
12+
LDLIBS = -lmbedtls -lmbedcrypto
13+
VAR_LDLIBS = $(shell pkg-config --libs libnl-3.0 libnl-genl-3.0 2>/dev/null)
14+
ifeq ($(VAR_LDLIBS),)
15+
VAR_LDLIBS = -lnl-genl-3 -lnl-3
16+
endif
17+
LDLIBS += $(VAR_LDLIBS)
18+
19+
20+
TEST_FILES = common.sh
21+
22+
TEST_PROGS = test.sh \
23+
test-chachapoly.sh \
24+
test-tcp.sh \
25+
test-float.sh \
26+
test-close-socket.sh \
27+
test-close-socket-tcp.sh
28+
29+
TEST_GEN_FILES := ovpn-cli
30+
31+
include ../../lib.mk
Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
#!/bin/bash
2+
# SPDX-License-Identifier: GPL-2.0
3+
# Copyright (C) 2020-2025 OpenVPN, Inc.
4+
#
5+
# Author: Antonio Quartulli <antonio@openvpn.net>
6+
7+
UDP_PEERS_FILE=${UDP_PEERS_FILE:-udp_peers.txt}
8+
TCP_PEERS_FILE=${TCP_PEERS_FILE:-tcp_peers.txt}
9+
OVPN_CLI=${OVPN_CLI:-./ovpn-cli}
10+
ALG=${ALG:-aes}
11+
PROTO=${PROTO:-UDP}
12+
FLOAT=${FLOAT:-0}
13+
14+
create_ns() {
15+
ip netns add peer${1}
16+
}
17+
18+
setup_ns() {
19+
MODE="P2P"
20+
21+
if [ ${1} -eq 0 ]; then
22+
MODE="MP"
23+
for p in $(seq 1 ${NUM_PEERS}); do
24+
ip link add veth${p} netns peer0 type veth peer name veth${p} netns peer${p}
25+
26+
ip -n peer0 addr add 10.10.${p}.1/24 dev veth${p}
27+
ip -n peer0 link set veth${p} up
28+
29+
ip -n peer${p} addr add 10.10.${p}.2/24 dev veth${p}
30+
ip -n peer${p} link set veth${p} up
31+
done
32+
fi
33+
34+
ip netns exec peer${1} ${OVPN_CLI} new_iface tun${1} $MODE
35+
ip -n peer${1} addr add ${2} dev tun${1}
36+
ip -n peer${1} link set tun${1} up
37+
}
38+
39+
add_peer() {
40+
if [ "${PROTO}" == "UDP" ]; then
41+
if [ ${1} -eq 0 ]; then
42+
ip netns exec peer0 ${OVPN_CLI} new_multi_peer tun0 1 ${UDP_PEERS_FILE}
43+
44+
for p in $(seq 1 ${NUM_PEERS}); do
45+
ip netns exec peer0 ${OVPN_CLI} new_key tun0 ${p} 1 0 ${ALG} 0 \
46+
data64.key
47+
done
48+
else
49+
ip netns exec peer${1} ${OVPN_CLI} new_peer tun${1} ${1} 1 10.10.${1}.1 1
50+
ip netns exec peer${1} ${OVPN_CLI} new_key tun${1} ${1} 1 0 ${ALG} 1 \
51+
data64.key
52+
fi
53+
else
54+
if [ ${1} -eq 0 ]; then
55+
(ip netns exec peer0 ${OVPN_CLI} listen tun0 1 ${TCP_PEERS_FILE} && {
56+
for p in $(seq 1 ${NUM_PEERS}); do
57+
ip netns exec peer0 ${OVPN_CLI} new_key tun0 ${p} 1 0 \
58+
${ALG} 0 data64.key
59+
done
60+
}) &
61+
sleep 5
62+
else
63+
ip netns exec peer${1} ${OVPN_CLI} connect tun${1} ${1} 10.10.${1}.1 1 \
64+
data64.key
65+
fi
66+
fi
67+
}
68+
69+
cleanup() {
70+
# some ovpn-cli processes sleep in background so they need manual poking
71+
killall $(basename ${OVPN_CLI}) 2>/dev/null || true
72+
73+
# netns peer0 is deleted without erasing ifaces first
74+
for p in $(seq 1 10); do
75+
ip -n peer${p} link set tun${p} down 2>/dev/null || true
76+
ip netns exec peer${p} ${OVPN_CLI} del_iface tun${p} 2>/dev/null || true
77+
done
78+
for p in $(seq 1 10); do
79+
ip -n peer0 link del veth${p} 2>/dev/null || true
80+
done
81+
for p in $(seq 0 10); do
82+
ip netns del peer${p} 2>/dev/null || true
83+
done
84+
}
85+
86+
if [ "${PROTO}" == "UDP" ]; then
87+
NUM_PEERS=${NUM_PEERS:-$(wc -l ${UDP_PEERS_FILE} | awk '{print $1}')}
88+
else
89+
NUM_PEERS=${NUM_PEERS:-$(wc -l ${TCP_PEERS_FILE} | awk '{print $1}')}
90+
fi
91+
92+
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
CONFIG_NET=y
2+
CONFIG_INET=y
3+
CONFIG_STREAM_PARSER=y
4+
CONFIG_NET_UDP_TUNNEL=y
5+
CONFIG_DST_CACHE=y
6+
CONFIG_CRYPTO=y
7+
CONFIG_CRYPTO_AES=y
8+
CONFIG_CRYPTO_GCM=y
9+
CONFIG_CRYPTO_CHACHA20POLY1305=y
10+
CONFIG_OVPN=m
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
jRqMACN7d7/aFQNT8S7jkrBD8uwrgHbG5OQZP2eu4R1Y7tfpS2bf5RHv06Vi163CGoaIiTX99R3B
2+
ia9ycAH8Wz1+9PWv51dnBLur9jbShlgZ2QHLtUc4a/gfT7zZwULXuuxdLnvR21DDeMBaTbkgbai9
3+
uvAa7ne1liIgGFzbv+Bas4HDVrygxIxuAnP5Qgc3648IJkZ0QEXPF+O9f0n5+QIvGCxkAUVx+5K6
4+
KIs+SoeWXnAopELmoGSjUpFtJbagXK82HfdqpuUxT2Tnuef0/14SzVE/vNleBNu2ZbyrSAaah8tE
5+
BofkPJUBFY+YQcfZNM5Dgrw3i+Bpmpq/gpdg5w==

0 commit comments

Comments
 (0)