]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
selftests: net: add tests for PPP
authorQingfang Deng <qingfang.deng@linux.dev>
Fri, 3 Apr 2026 03:48:47 +0000 (11:48 +0800)
committerPaolo Abeni <pabeni@redhat.com>
Tue, 7 Apr 2026 10:08:46 +0000 (12:08 +0200)
Add ping and iperf3 tests for ppp_async.c and pppoe.c.

Signed-off-by: Qingfang Deng <qingfang.deng@linux.dev>
Link: https://patch.msgid.link/20260403034908.30017-1-qingfang.deng@linux.dev
Signed-off-by: Paolo Abeni <pabeni@redhat.com>
MAINTAINERS
tools/testing/selftests/Makefile
tools/testing/selftests/net/ppp/Makefile [new file with mode: 0644]
tools/testing/selftests/net/ppp/config [new file with mode: 0644]
tools/testing/selftests/net/ppp/ppp_async.sh [new file with mode: 0755]
tools/testing/selftests/net/ppp/ppp_common.sh [new file with mode: 0644]
tools/testing/selftests/net/ppp/pppoe-server-options [new file with mode: 0644]
tools/testing/selftests/net/ppp/pppoe.sh [new file with mode: 0755]

index cb48c9ad9ddc7b46cdaf0bfc265bb836508b1972..9d1e6d3acbacdce6494882f701876149e1c11900 100644 (file)
@@ -21083,6 +21083,7 @@ PPP PROTOCOL DRIVERS AND COMPRESSORS
 L:     linux-ppp@vger.kernel.org
 S:     Orphan
 F:     drivers/net/ppp/ppp_*
+F:     tools/testing/selftests/net/ppp/
 
 PPS SUPPORT
 M:     Rodolfo Giometti <giometti@enneenne.com>
index 450f13ba4cca98836bc8a2fe18a2eb43ce14b2d5..65f84e8a0cf00fc39954ea1c406e95b5948ba3a8 100644 (file)
@@ -78,6 +78,7 @@ TARGETS += net/netfilter
 TARGETS += net/openvswitch
 TARGETS += net/ovpn
 TARGETS += net/packetdrill
+TARGETS += net/ppp
 TARGETS += net/rds
 TARGETS += net/tcp_ao
 TARGETS += nolibc
diff --git a/tools/testing/selftests/net/ppp/Makefile b/tools/testing/selftests/net/ppp/Makefile
new file mode 100644 (file)
index 0000000..b39b0ab
--- /dev/null
@@ -0,0 +1,15 @@
+# SPDX-License-Identifier: GPL-2.0
+
+top_srcdir = ../../../../..
+
+TEST_PROGS := \
+       ppp_async.sh \
+       pppoe.sh \
+# end of TEST_PROGS
+
+TEST_FILES := \
+       ppp_common.sh \
+       pppoe-server-options \
+# end of TEST_FILES
+
+include ../../lib.mk
diff --git a/tools/testing/selftests/net/ppp/config b/tools/testing/selftests/net/ppp/config
new file mode 100644 (file)
index 0000000..b45d25c
--- /dev/null
@@ -0,0 +1,9 @@
+CONFIG_IPV6=y
+CONFIG_PACKET=y
+CONFIG_PPP=m
+CONFIG_PPP_ASYNC=m
+CONFIG_PPP_BSDCOMP=m
+CONFIG_PPP_DEFLATE=m
+CONFIG_PPPOE=m
+CONFIG_PPPOE_HASH_BITS_4=y
+CONFIG_VETH=y
diff --git a/tools/testing/selftests/net/ppp/ppp_async.sh b/tools/testing/selftests/net/ppp/ppp_async.sh
new file mode 100755 (executable)
index 0000000..10f54c8
--- /dev/null
@@ -0,0 +1,43 @@
+#!/bin/bash
+# SPDX-License-Identifier: GPL-2.0
+
+source ppp_common.sh
+
+# Temporary files for PTY symlinks
+TTY_DIR=$(mktemp -d /tmp/ppp.XXXXXX)
+TTY_SERVER="$TTY_DIR"/server
+TTY_CLIENT="$TTY_DIR"/client
+
+# shellcheck disable=SC2329
+cleanup() {
+       cleanup_all_ns
+       [ -n "$SOCAT_PID" ] && kill_process "$SOCAT_PID"
+       rm -fr "$TTY_DIR"
+}
+
+trap cleanup EXIT
+
+ppp_common_init
+modprobe -q ppp_async
+
+# Create the virtual serial device
+socat -d PTY,link="$TTY_SERVER",rawer PTY,link="$TTY_CLIENT",rawer &
+SOCAT_PID=$!
+
+# Wait for symlinks to be created
+slowwait 5 [ -L "$TTY_SERVER" ]
+
+# Start the PPP Server
+ip netns exec "$NS_SERVER" pppd "$TTY_SERVER" 115200 \
+       "$IP_SERVER":"$IP_CLIENT" \
+       local noauth nodefaultroute debug
+
+# Start the PPP Client
+ip netns exec "$NS_CLIENT" pppd "$TTY_CLIENT" 115200 \
+       local noauth updetach nodefaultroute debug
+
+ppp_test_connectivity
+
+log_test "PPP async"
+
+exit "$EXIT_STATUS"
diff --git a/tools/testing/selftests/net/ppp/ppp_common.sh b/tools/testing/selftests/net/ppp/ppp_common.sh
new file mode 100644 (file)
index 0000000..40bbec3
--- /dev/null
@@ -0,0 +1,45 @@
+#!/bin/bash
+# SPDX-License-Identifier: GPL-2.0
+# shellcheck disable=SC2153
+
+source ../lib.sh
+
+IP_SERVER="192.168.200.1"
+IP_CLIENT="192.168.200.2"
+
+ppp_common_init() {
+       # Package requirements
+       require_command socat
+       require_command pppd
+       require_command iperf3
+
+       # Check for root privileges
+       if [ "$(id -u)" -ne 0 ];then
+               echo "SKIP: Need root privileges"
+               exit "$ksft_skip"
+       fi
+
+       # Namespaces
+       setup_ns NS_SERVER NS_CLIENT
+}
+
+ppp_check_addr() {
+       dev=$1
+       addr=$2
+       ns=$3
+       ip -netns "$ns" -4 addr show dev "$dev" 2>/dev/null | grep -q "$addr"
+       return $?
+}
+
+ppp_test_connectivity() {
+       slowwait 10 ppp_check_addr "ppp0" "$IP_CLIENT" "$NS_CLIENT"
+
+       ip netns exec "$NS_CLIENT" ping -c 3 "$IP_SERVER"
+       check_err $?
+
+       ip netns exec "$NS_SERVER" iperf3 -s -1 -D
+       wait_local_port_listen "$NS_SERVER" 5201 tcp
+
+       ip netns exec "$NS_CLIENT" iperf3 -c "$IP_SERVER" -Z -t 2
+       check_err $?
+}
diff --git a/tools/testing/selftests/net/ppp/pppoe-server-options b/tools/testing/selftests/net/ppp/pppoe-server-options
new file mode 100644 (file)
index 0000000..66c8c9d
--- /dev/null
@@ -0,0 +1,2 @@
+noauth
+noipdefault
diff --git a/tools/testing/selftests/net/ppp/pppoe.sh b/tools/testing/selftests/net/ppp/pppoe.sh
new file mode 100755 (executable)
index 0000000..f67b51d
--- /dev/null
@@ -0,0 +1,65 @@
+#!/bin/bash
+# SPDX-License-Identifier: GPL-2.0
+
+source ppp_common.sh
+
+VETH_SERVER="veth-server"
+VETH_CLIENT="veth-client"
+PPPOE_LOG=$(mktemp /tmp/pppoe.XXXXXX)
+
+# shellcheck disable=SC2329
+cleanup() {
+       cleanup_all_ns
+       [ -n "$SOCAT_PID" ] && kill_process "$SOCAT_PID"
+       rm -f "$PPPOE_LOG"
+}
+
+trap cleanup EXIT
+
+require_command pppoe-server
+ppp_common_init
+modprobe -q pppoe
+
+# Try to locate pppoe.so plugin
+PPPOE_PLUGIN=$(find /usr/{lib,lib64,lib32}/pppd/ -name pppoe.so -type f -print -quit)
+if [ -z "$PPPOE_PLUGIN" ]; then
+       log_test_skip "PPPoE: pppoe.so plugin not found"
+       exit "$EXIT_STATUS"
+fi
+
+# Create the veth pair
+ip link add "$VETH_SERVER" type veth peer name "$VETH_CLIENT"
+ip link set "$VETH_SERVER" netns "$NS_SERVER"
+ip link set "$VETH_CLIENT" netns "$NS_CLIENT"
+ip -netns "$NS_SERVER" link set "$VETH_SERVER" up
+ip -netns "$NS_CLIENT" link set "$VETH_CLIENT" up
+
+# Start socat as syslog listener
+socat -v -u UNIX-RECV:/dev/log OPEN:/dev/null > "$PPPOE_LOG" 2>&1 &
+SOCAT_PID=$!
+
+# Start the PPP Server. Note that versions before 4.0 ignore -g option and
+# instead use a hardcoded plugin path, so they may fail to find the plugin.
+ip netns exec "$NS_SERVER" pppoe-server -I "$VETH_SERVER" \
+       -L "$IP_SERVER" -R "$IP_CLIENT" -N 1 -q "$(command -v pppd)" \
+       -k -O "$(pwd)/pppoe-server-options" -g "$PPPOE_PLUGIN"
+
+# Start the PPP Client
+ip netns exec "$NS_CLIENT" pppd \
+       local debug updetach noipdefault noauth nodefaultroute \
+       plugin "$PPPOE_PLUGIN" nic-"$VETH_CLIENT"
+
+ppp_test_connectivity
+
+log_test "PPPoE"
+
+# Dump syslog messages if the test failed
+if [ "$RET" -ne 0 ]; then
+       while read -r _sign _date _time len _from _to
+       do      len=${len##*=}
+               read -n "$len" -r LINE
+               echo "$LINE"
+       done < "$PPPOE_LOG"
+fi
+
+exit "$EXIT_STATUS"