xref: /linux/tools/testing/selftests/net/setup_veth.sh (revision fd7d598270724cc787982ea48bbe17ad383a8b7f)
1#!/bin/bash
2# SPDX-License-Identifier: GPL-2.0
3
4setup_veth_ns() {
5	local -r link_dev="$1"
6	local -r ns_name="$2"
7	local -r ns_dev="$3"
8	local -r ns_mac="$4"
9
10	[[ -e /var/run/netns/"${ns_name}" ]] || ip netns add "${ns_name}"
11	echo 100000 > "/sys/class/net/${ns_dev}/gro_flush_timeout"
12	ip link set dev "${ns_dev}" netns "${ns_name}" mtu 65535
13	ip -netns "${ns_name}" link set dev "${ns_dev}" up
14
15	ip netns exec "${ns_name}" ethtool -K "${ns_dev}" gro on tso off
16}
17
18setup_ns() {
19	# Set up server_ns namespace and client_ns namespace
20	ip link add name server type veth peer name client
21
22	setup_veth_ns "${dev}" server_ns server "${SERVER_MAC}"
23	setup_veth_ns "${dev}" client_ns client "${CLIENT_MAC}"
24}
25
26cleanup_ns() {
27	local ns_name
28
29	for ns_name in client_ns server_ns; do
30		[[ -e /var/run/netns/"${ns_name}" ]] && ip netns del "${ns_name}"
31	done
32}
33
34setup() {
35	# no global init setup step needed
36	:
37}
38
39cleanup() {
40	cleanup_ns
41}
42