xref: /linux/tools/testing/selftests/net/ppp/pppoe.sh (revision 91a4855d6c03e770e42f17c798a36a3c46e63de2)
1#!/bin/bash
2# SPDX-License-Identifier: GPL-2.0
3
4source ppp_common.sh
5
6VETH_SERVER="veth-server"
7VETH_CLIENT="veth-client"
8PPPOE_LOG=$(mktemp /tmp/pppoe.XXXXXX)
9
10# shellcheck disable=SC2329
11cleanup() {
12	cleanup_all_ns
13	[ -n "$SOCAT_PID" ] && kill_process "$SOCAT_PID"
14	rm -f "$PPPOE_LOG"
15}
16
17trap cleanup EXIT
18
19require_command pppoe-server
20ppp_common_init
21modprobe -q pppoe
22
23# Try to locate pppoe.so plugin
24PPPOE_PLUGIN=$(find /usr/{lib,lib64,lib32}/pppd/ -name pppoe.so -type f -print -quit)
25if [ -z "$PPPOE_PLUGIN" ]; then
26	log_test_skip "PPPoE: pppoe.so plugin not found"
27	exit "$EXIT_STATUS"
28fi
29
30# Create the veth pair
31ip link add "$VETH_SERVER" type veth peer name "$VETH_CLIENT"
32ip link set "$VETH_SERVER" netns "$NS_SERVER"
33ip link set "$VETH_CLIENT" netns "$NS_CLIENT"
34ip -netns "$NS_SERVER" link set "$VETH_SERVER" up
35ip -netns "$NS_CLIENT" link set "$VETH_CLIENT" up
36
37# Start socat as syslog listener
38socat -v -u UNIX-RECV:/dev/log OPEN:/dev/null > "$PPPOE_LOG" 2>&1 &
39SOCAT_PID=$!
40
41# Start the PPP Server. Note that versions before 4.0 ignore -g option and
42# instead use a hardcoded plugin path, so they may fail to find the plugin.
43ip netns exec "$NS_SERVER" pppoe-server -I "$VETH_SERVER" \
44	-L "$IP_SERVER" -R "$IP_CLIENT" -N 1 -q "$(command -v pppd)" \
45	-k -O "$(pwd)/pppoe-server-options" -g "$PPPOE_PLUGIN"
46
47# Start the PPP Client
48ip netns exec "$NS_CLIENT" pppd \
49	local debug updetach noipdefault noauth nodefaultroute \
50	plugin "$PPPOE_PLUGIN" nic-"$VETH_CLIENT"
51
52ppp_test_connectivity
53
54log_test "PPPoE"
55
56# Dump syslog messages if the test failed
57if [ "$RET" -ne 0 ]; then
58	while read -r _sign _date _time len _from _to
59	do      len=${len##*=}
60		read -n "$len" -r LINE
61		echo "$LINE"
62	done < "$PPPOE_LOG"
63fi
64
65exit "$EXIT_STATUS"
66