Linux kernel mirror (for testing)
git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel
os
linux
1#!/bin/bash
2# SPDX-License-Identifier: GPL-2.0
3source lib.sh
4
5NSIM_SV_ID=$((256 + RANDOM % 256))
6NSIM_SV_SYS=/sys/bus/netdevsim/devices/netdevsim$NSIM_SV_ID
7NSIM_CL_ID=$((512 + RANDOM % 256))
8NSIM_CL_SYS=/sys/bus/netdevsim/devices/netdevsim$NSIM_CL_ID
9
10NSIM_DEV_SYS_NEW=/sys/bus/netdevsim/new_device
11NSIM_DEV_SYS_DEL=/sys/bus/netdevsim/del_device
12NSIM_DEV_SYS_LINK=/sys/bus/netdevsim/link_device
13NSIM_DEV_SYS_UNLINK=/sys/bus/netdevsim/unlink_device
14
15SERVER_IP=192.168.1.1
16CLIENT_IP=192.168.1.2
17SERVER_PORT=48675
18
19setup_ns()
20{
21 set -e
22 ip netns add nssv
23 ip netns add nscl
24
25 NSIM_SV_NAME=$(find $NSIM_SV_SYS/net -maxdepth 1 -type d ! \
26 -path $NSIM_SV_SYS/net -exec basename {} \;)
27 NSIM_CL_NAME=$(find $NSIM_CL_SYS/net -maxdepth 1 -type d ! \
28 -path $NSIM_CL_SYS/net -exec basename {} \;)
29
30 ip link set $NSIM_SV_NAME netns nssv
31 ip link set $NSIM_CL_NAME netns nscl
32
33 ip netns exec nssv ip addr add "${SERVER_IP}/24" dev $NSIM_SV_NAME
34 ip netns exec nscl ip addr add "${CLIENT_IP}/24" dev $NSIM_CL_NAME
35
36 ip netns exec nssv ip link set dev $NSIM_SV_NAME up
37 ip netns exec nscl ip link set dev $NSIM_CL_NAME up
38
39 # Enable passive TFO
40 ip netns exec nssv sysctl -w net.ipv4.tcp_fastopen=519 > /dev/null
41
42 set +e
43}
44
45cleanup_ns()
46{
47 ip netns del nscl
48 ip netns del nssv
49}
50
51###
52### Code start
53###
54
55modprobe netdevsim
56
57# linking
58
59echo $NSIM_SV_ID > $NSIM_DEV_SYS_NEW
60echo $NSIM_CL_ID > $NSIM_DEV_SYS_NEW
61udevadm settle
62
63setup_ns
64
65NSIM_SV_FD=$((256 + RANDOM % 256))
66exec {NSIM_SV_FD}</var/run/netns/nssv
67NSIM_SV_IFIDX=$(ip netns exec nssv cat /sys/class/net/$NSIM_SV_NAME/ifindex)
68
69NSIM_CL_FD=$((256 + RANDOM % 256))
70exec {NSIM_CL_FD}</var/run/netns/nscl
71NSIM_CL_IFIDX=$(ip netns exec nscl cat /sys/class/net/$NSIM_CL_NAME/ifindex)
72
73echo "$NSIM_SV_FD:$NSIM_SV_IFIDX $NSIM_CL_FD:$NSIM_CL_IFIDX" > \
74 $NSIM_DEV_SYS_LINK
75
76if [ $? -ne 0 ]; then
77 echo "linking netdevsim1 with netdevsim2 should succeed"
78 cleanup_ns
79 exit 1
80fi
81
82out_file=$(mktemp)
83
84timeout -k 1s 30s ip netns exec nssv ./tfo \
85 -s \
86 -p ${SERVER_PORT} \
87 -o ${out_file}&
88
89wait_local_port_listen nssv ${SERVER_PORT} tcp
90
91ip netns exec nscl ./tfo -c -h ${SERVER_IP} -p ${SERVER_PORT}
92
93wait
94
95res=$(cat $out_file)
96rm $out_file
97
98if [ "$res" = "0" ]; then
99 echo "got invalid NAPI ID from passive TFO socket"
100 cleanup_ns
101 exit 1
102fi
103
104echo "$NSIM_SV_FD:$NSIM_SV_IFIDX" > $NSIM_DEV_SYS_UNLINK
105
106echo $NSIM_CL_ID > $NSIM_DEV_SYS_DEL
107
108cleanup_ns
109
110modprobe -r netdevsim
111
112exit 0