xref: /linux/tools/testing/selftests/net/ovpn/test-close-socket.sh (revision 0fc8f6200d2313278fbf4539bbab74677c685531)
1959bc330SAntonio Quartulli#!/bin/bash
2959bc330SAntonio Quartulli# SPDX-License-Identifier: GPL-2.0
3959bc330SAntonio Quartulli# Copyright (C) 2020-2025 OpenVPN, Inc.
4959bc330SAntonio Quartulli#
5959bc330SAntonio Quartulli#  Author:	Antonio Quartulli <antonio@openvpn.net>
6959bc330SAntonio Quartulli
7959bc330SAntonio Quartulli#set -x
8*1be93bb9SRalf Liciset -eE
9959bc330SAntonio Quartulli
10959bc330SAntonio Quartullisource ./common.sh
11*1be93bb9SRalf Lici
12*1be93bb9SRalf Liciovpn_test_finished=0
13*1be93bb9SRalf Lici
14*1be93bb9SRalf Liciovpn_test_exit() {
15*1be93bb9SRalf Lici	ovpn_cleanup
16*1be93bb9SRalf Lici	modprobe -r ovpn || true
17*1be93bb9SRalf Lici
18*1be93bb9SRalf Lici	if [ "${ovpn_test_finished}" -eq 0 ]; then
19*1be93bb9SRalf Lici		ktap_print_totals
20*1be93bb9SRalf Lici	fi
21*1be93bb9SRalf Lici}
22*1be93bb9SRalf Lici
23*1be93bb9SRalf Liciovpn_prepare_network() {
24*1be93bb9SRalf Lici	local p
25*1be93bb9SRalf Lici	local peer_ns
26*1be93bb9SRalf Lici
27*1be93bb9SRalf Lici	for p in $(seq 0 ${OVPN_NUM_PEERS}); do
28*1be93bb9SRalf Lici		ovpn_cmd_ok "create namespace peer${p}" ovpn_create_ns "${p}"
29*1be93bb9SRalf Lici	done
30*1be93bb9SRalf Lici
31*1be93bb9SRalf Lici	for p in $(seq 0 ${OVPN_NUM_PEERS}); do
32*1be93bb9SRalf Lici		ovpn_cmd_ok "configure peer${p} namespace" ovpn_setup_ns \
33*1be93bb9SRalf Lici			"${p}" 5.5.5.$((p + 1))/24
34*1be93bb9SRalf Lici	done
35*1be93bb9SRalf Lici
36*1be93bb9SRalf Lici	for p in $(seq 0 ${OVPN_NUM_PEERS}); do
37*1be93bb9SRalf Lici		ovpn_cmd_ok "register peer${p} in overlay" ovpn_add_peer "${p}"
38*1be93bb9SRalf Lici	done
39*1be93bb9SRalf Lici
40*1be93bb9SRalf Lici	for p in $(seq 1 ${OVPN_NUM_PEERS}); do
41*1be93bb9SRalf Lici		peer_ns="ovpn_peer${p}"
42*1be93bb9SRalf Lici		ovpn_cmd_ok "set peer0 timeout for peer ${p}" \
43*1be93bb9SRalf Lici			ip netns exec ovpn_peer0 ${OVPN_CLI} set_peer tun0 \
44*1be93bb9SRalf Lici				${p} 60 120
45*1be93bb9SRalf Lici		ovpn_cmd_ok "set peer${p} timeout for peer ${p}" \
46*1be93bb9SRalf Lici			ip netns exec "${peer_ns}" ${OVPN_CLI} set_peer \
47*1be93bb9SRalf Lici				tun${p} $((p + OVPN_ID_OFFSET)) 60 120
48*1be93bb9SRalf Lici	done
49*1be93bb9SRalf Lici}
50*1be93bb9SRalf Lici
51*1be93bb9SRalf Liciovpn_run_ping_traffic() {
52*1be93bb9SRalf Lici	local p
53*1be93bb9SRalf Lici
54*1be93bb9SRalf Lici	for p in $(seq 1 ${OVPN_NUM_PEERS}); do
55*1be93bb9SRalf Lici		ovpn_cmd_ok "send ping traffic to peer ${p}" \
56*1be93bb9SRalf Lici			ip netns exec ovpn_peer0 ping -qfc 500 -w 3 \
57*1be93bb9SRalf Lici				5.5.5.$((p + 1))
58*1be93bb9SRalf Lici	done
59*1be93bb9SRalf Lici}
60*1be93bb9SRalf Lici
61*1be93bb9SRalf Liciovpn_run_iperf() {
62*1be93bb9SRalf Lici	local iperf_pid
63*1be93bb9SRalf Lici
64*1be93bb9SRalf Lici	ovpn_run_bg iperf_pid ip netns exec ovpn_peer0 iperf3 -1 -s
65*1be93bb9SRalf Lici	sleep 1
66*1be93bb9SRalf Lici	ovpn_cmd_ok "run iperf throughput flow" \
67*1be93bb9SRalf Lici		ip netns exec ovpn_peer1 iperf3 -Z -t 3 -c 5.5.5.1
68*1be93bb9SRalf Lici	wait "${iperf_pid}" || return 1
69*1be93bb9SRalf Lici}
70*1be93bb9SRalf Lici
71*1be93bb9SRalf Licitrap ovpn_test_exit EXIT
72*1be93bb9SRalf Licitrap ovpn_stage_err ERR
73*1be93bb9SRalf Lici
74*1be93bb9SRalf Liciktap_print_header
75*1be93bb9SRalf Liciktap_set_plan 3
76959bc330SAntonio Quartulli
777c29665aSRalf Liciovpn_cleanup
78959bc330SAntonio Quartullimodprobe -q ovpn || true
79959bc330SAntonio Quartulli
80*1be93bb9SRalf Liciovpn_run_stage "setup network topology" ovpn_prepare_network
81*1be93bb9SRalf Liciovpn_run_stage "run ping traffic" ovpn_run_ping_traffic
82*1be93bb9SRalf Liciovpn_run_stage "run iperf throughput" ovpn_run_iperf
83959bc330SAntonio Quartulli
84*1be93bb9SRalf Liciovpn_test_finished=1
85*1be93bb9SRalf Liciktap_finished
86