Skip to contentSkip to conversation

selftests: net: add tests for PPPoL2TP

PATCH Superseded Qingfang Deng 3 participants 5 messages May 8 – May 13

Subsystems (4)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 selftests: net: add tests for PPPoL2TP

Add ping, iperf3, and recursion tests for PPPoL2TP.

Assisted-by Gemini:gemini-3-flash
---
 tools/testing/selftests/net/ppp/Makefile    |  1 +
 tools/testing/selftests/net/ppp/config      |  3 +
 tools/testing/selftests/net/ppp/pppol2tp.sh | 93 +++++++++++++++++++++
 3 files changed, 97 insertions(+)
 create mode 100755 tools/testing/selftests/net/ppp/pppol2tp.sh
tools/testing/selftests/net/ppp/Makefile +1 -0
index b39b0abadde6..6036fa134351 100644
@@ -5,6 +5,7 @@ top_srcdir = ../../../../..
 TEST_PROGS := \
 	ppp_async.sh \
 	pppoe.sh \
+	pppol2tp.sh \
 # end of TEST_PROGS
 
 TEST_FILES := \
tools/testing/selftests/net/ppp/config +3 -0
index b45d25c5b970..8bc3b7c33d5c 100644
@@ -1,4 +1,6 @@
 CONFIG_IPV6=y
+CONFIG_L2TP=m
+CONFIG_NETKIT=y
 CONFIG_PACKET=y
 CONFIG_PPP=m
 CONFIG_PPP_ASYNC=m
@@ -6,4 +8,5 @@ CONFIG_PPP_BSDCOMP=m
 CONFIG_PPP_DEFLATE=m
 CONFIG_PPPOE=m
 CONFIG_PPPOE_HASH_BITS_4=y
+CONFIG_PPPOL2TP=m
 CONFIG_VETH=y
tools/testing/selftests/net/ppp/pppol2tp.sh new file +93 -0

93 lines not on this page · raw message

Signature · 1 line
2.43.0
#1 lore raw
Quoted 67 lines · Qingfang Deng

Add ping, iperf3, and recursion tests for PPPoL2TP.

Assisted-by Gemini:gemini-3-flash
---
 tools/testing/selftests/net/ppp/Makefile    |  1 +
 tools/testing/selftests/net/ppp/config      |  3 +
 tools/testing/selftests/net/ppp/pppol2tp.sh | 93 +++++++++++++++++++++
 3 files changed, 97 insertions(+)
 create mode 100755 tools/testing/selftests/net/ppp/pppol2tp.sh
tools/testing/selftests/net/ppp/Makefile +1 -0
index b39b0abadde6..6036fa134351 100644
@@ -5,6 +5,7 @@ top_srcdir = ../../../../..
 TEST_PROGS := \
 	ppp_async.sh \
 	pppoe.sh \
+	pppol2tp.sh \
 # end of TEST_PROGS
 
 TEST_FILES := \
tools/testing/selftests/net/ppp/config +3 -0
index b45d25c5b970..8bc3b7c33d5c 100644
@@ -1,4 +1,6 @@
 CONFIG_IPV6=y
+CONFIG_L2TP=m
+CONFIG_NETKIT=y
 CONFIG_PACKET=y
 CONFIG_PPP=m
 CONFIG_PPP_ASYNC=m
@@ -6,4 +8,5 @@ CONFIG_PPP_BSDCOMP=m
 CONFIG_PPP_DEFLATE=m
 CONFIG_PPPOE=m
 CONFIG_PPPOE_HASH_BITS_4=y
+CONFIG_PPPOL2TP=m
 CONFIG_VETH=y
tools/testing/selftests/net/ppp/pppol2tp.sh new file +21 -0
new file mode 100755
index 000000000000..5ddcc6c41c33
@@ -0,0 +1,93 @@
+#!/bin/bash
+# SPDX-License-Identifier: GPL-2.0
+
+source ppp_common.sh
+
+NK_SERVER="nk0"
+NK_CLIENT="nk1"
+OUTER_IP_SERVER="172.16.1.1"
+OUTER_IP_CLIENT="172.16.1.2"
+
+PPPOL2TP_DIR=$(mktemp -d /tmp/pppol2tp.XXXXXX)
+
+# shellcheck disable=SC2329
+cleanup() {
+	cleanup_all_ns
+	rm -rf "$PPPOL2TP_DIR"
+}
+
+trap cleanup EXIT
+
+require_command xl2tpd

tools/testing/selftests/net/ppp/pppol2tp.sh line 31

Quoted 10 lines
tools/testing/selftests/net/ppp/pppol2tp.sh new file +10 -0
+ppp_common_init
+modprobe -q l2tp_ppp
+
+# Create the netkit pair
+ip -netns "$NS_CLIENT" link add "$NK_CLIENT" type netkit
+ip -netns "$NS_CLIENT" link set "$NK_SERVER" netns "$NS_SERVER"
+ip -netns "$NS_SERVER" link set "$NK_SERVER" up
+ip -netns "$NS_CLIENT" link set "$NK_CLIENT" up
+ip -netns "$NS_SERVER" address add dev "$NK_SERVER" "$OUTER_IP_SERVER" peer "$OUTER_IP_CLIENT"
+ip -netns "$NS_CLIENT" address add dev "$NK_CLIENT" "$OUTER_IP_CLIENT" peer "$OUTER_IP_SERVER"

Is there a particular reason to create the test setup with a netkit pair instead of the more standard veth pairs?

Thanks,
Felix

#2 lore raw
Quoted 2 lines · Felix Maurer

Is there a particular reason to create the test setup with a netkit pair instead of the more standard veth pairs?

L2TP does not need an outer ethernet header so I choose netkit instead of veth.

#3 lore raw
Quoted 6 lines · Qingfang Deng
Quoted 2 lines · Felix Maurer

Is there a particular reason to create the test setup with a netkit pair instead of the more standard veth pairs?

L2TP does not need an outer ethernet header so I choose netkit instead of veth.

I see, thanks. In my opinion, sticking to the same environment setup for as many selftests as possible, i.e., using veth pairs everywhere, has more benefits in terms of maintenance of the test than leaving out the ethernet header has. Also, while I understand that selftests are only supported on systems that run with the respective selftest kernel config, I still think it's good to stick to veth as it is probably available in more kernel builds (think resource constrained envrionments, older kernel versions, etc.).

But in the end, it's up to you and the maintainers. However, if you stick with netkit, please name the interfaces explicitly and don't rely on the current auto-assigned name of the peer interface.

Thanks,
Felix

maintainer
#4 lore raw
In reply to Qingfang Deng
Quoted 7 lines · Qingfang Deng
tools/testing/selftests/net/ppp/pppol2tp.sh new file +1 -0
new file mode 100755
index 000000000000..5ddcc6c41c33
@@ -0,0 +1,93 @@
+#!/bin/bash

tools/testing/selftests/net/ppp/pppol2tp.sh line 11

Quoted 10 lines
tools/testing/selftests/net/ppp/pppol2tp.sh new file +10 -0
+# SPDX-License-Identifier: GPL-2.0
+
+source ppp_common.sh
+
+NK_SERVER="nk0"
+NK_CLIENT="nk1"
+OUTER_IP_SERVER="172.16.1.1"
+OUTER_IP_CLIENT="172.16.1.2"
+
+PPPOL2TP_DIR=$(mktemp -d /tmp/pppol2tp.XXXXXX)

Sashiko (gemini) reports an unhandled error condition here. AFAICS that is irrelevant as it could happen only on a broken system.

Quoted 68 lines
tools/testing/selftests/net/ppp/pppol2tp.sh new file +68 -0
+
+# shellcheck disable=SC2329
+cleanup() {
+	cleanup_all_ns
+	rm -rf "$PPPOL2TP_DIR"
+}
+
+trap cleanup EXIT
+
+require_command xl2tpd
+ppp_common_init
+modprobe -q l2tp_ppp
+
+# Create the netkit pair
+ip -netns "$NS_CLIENT" link add "$NK_CLIENT" type netkit
+ip -netns "$NS_CLIENT" link set "$NK_SERVER" netns "$NS_SERVER"
+ip -netns "$NS_SERVER" link set "$NK_SERVER" up
+ip -netns "$NS_CLIENT" link set "$NK_CLIENT" up
+ip -netns "$NS_SERVER" address add dev "$NK_SERVER" "$OUTER_IP_SERVER" peer "$OUTER_IP_CLIENT"
+ip -netns "$NS_CLIENT" address add dev "$NK_CLIENT" "$OUTER_IP_CLIENT" peer "$OUTER_IP_SERVER"
+
+# Generate configuration files
+cat > "$PPPOL2TP_DIR/l2tp-server.conf" <<EOF
+[global]
+listen-addr = $OUTER_IP_SERVER
+access control = no
+
+[lns default]
+ip range = $IP_CLIENT
+local ip = $IP_SERVER
+require authentication = no
+require chap = no
+require pap = no
+ppp debug = yes
+pppoptfile = $(pwd)/pppoe-server-options
+EOF
+
+cat > "$PPPOL2TP_DIR/l2tp-client.conf" <<EOF
+[global]
+listen-addr = $OUTER_IP_CLIENT
+access control = no
+
+[lac server]
+lns = $OUTER_IP_SERVER
+require authentication = no
+require chap = no
+require pap = no
+ppp debug = yes
+pppoptfile = $(pwd)/pppoe-server-options
+EOF
+
+# Start the L2TP Server
+ip netns exec "$NS_SERVER" xl2tpd -D -c "$PPPOL2TP_DIR/l2tp-server.conf" \
+	-p "$PPPOL2TP_DIR/l2tp-server.pid" -C "$PPPOL2TP_DIR/l2tp-server.control" &
+
+# Start the L2TP Client
+ip netns exec "$NS_CLIENT" xl2tpd -D -c "$PPPOL2TP_DIR/l2tp-client.conf" \
+	-p "$PPPOL2TP_DIR/l2tp-client.pid" -C "$PPPOL2TP_DIR/l2tp-client.control" &
+
+# Wait for xl2tpd to start and open their control pipes
+slowwait 2 [ -p "$PPPOL2TP_DIR/l2tp-server.control" ]
+slowwait 2 [ -p "$PPPOL2TP_DIR/l2tp-client.control" ]
+
+# Connect LAC to LNS
+echo "c server" > "$PPPOL2TP_DIR/l2tp-client.control"
+
+ppp_test_connectivity
+

tools/testing/selftests/net/ppp/pppol2tp.sh line 89

Quoted 10 lines
tools/testing/selftests/net/ppp/pppol2tp.sh new file +10 -0
+log_test "PPPoL2TP"
+
+# Recursion test
+# Delete route to LNS IP
+ip -netns "$NS_CLIENT" route del "$OUTER_IP_SERVER"
+# Add default route through ppp0
+ip -netns "$NS_CLIENT" route add default dev ppp0
+# ping (we expect the ping to fail but not deadlock the system)
+ip netns exec "$NS_CLIENT" ping -c 1 "$IP_SERVER" -w 1
+check_fail $?

Sashiko notes you should clear the RET global variable before any direct or indirect invocation of check_err

/P