• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1#!/bin/sh
2# SPDX-License-Identifier: GPL-2.0-or-later
3# Copyright (c) Linux Test Project, 2018-2022
4# Copyright (c) 2018 Oracle and/or its affiliates. All Rights Reserved.
5
6TST_MIN_KVER="4.3"
7TST_NEEDS_TMPDIR=1
8TST_NEEDS_ROOT=1
9TST_NEEDS_DRIVERS="mpls_router mpls_iptunnel mpls_gso"
10TST_NEEDS_CMDS="sysctl modprobe"
11TST_TEST_DATA="icmp tcp udp"
12TST_NETLOAD_BINDTODEVICE=
13
14mpls_cleanup()
15{
16	local flush_dev="ip -f mpls route flush dev"
17
18	$flush_dev lo > /dev/null 2>&1
19	tst_rhost_run -c "$flush_dev lo" > /dev/null
20
21	[ -n "$rpf_loc" ] && sysctl -q net.ipv4.conf.all.rp_filter=$rpf_loc
22	[ -n "$rpf_rmt" ] && tst_rhost_run -s -c "sysctl -q net.ipv4.conf.all.rp_filter=$rpf_rmt"
23}
24
25mpls_virt_cleanup()
26{
27	ip route del $ip_virt_remote/32 dev ltp_v0 > /dev/null 2>&1
28	ip route del $ip6_virt_remote/128 dev ltp_v0 > /dev/null 2>&1
29	tst_rhost_run -c "ip route del $ip_virt_local/32 dev ltp_v0" > /dev/null
30	tst_rhost_run -c "ip route del $ip6_virt_local/128 dev ltp_v0" > /dev/null
31
32	virt_cleanup
33	mpls_cleanup
34}
35
36mpls_setup_driver()
37{
38	local args
39
40	grep -q -w ID_LIKE.*suse /etc/os-release && args='--allow-unsupported'
41	if [ "$TST_NEEDS_DRIVERS" ]; then
42		tst_net_run -s "modprobe $args -a $TST_NEEDS_DRIVERS"
43	fi
44}
45
46mpls_setup()
47{
48	local label="$1"
49
50	mpls_setup_driver
51
52	ROD sysctl -q net.mpls.conf.$(tst_iface).input=1
53	tst_set_sysctl net.mpls.conf.lo.input 1 safe
54	tst_set_sysctl net.mpls.platform_labels $label safe
55	rpf_loc="$(sysctl -n net.ipv4.conf.all.rp_filter)"
56
57	tst_rhost_run -s -c "sysctl -q net.mpls.conf.$(tst_iface rhost).input=1"
58	rpf_rmt="$(tst_rhost_run -c 'sysctl -n net.ipv4.conf.all.rp_filter')"
59
60	tst_set_sysctl net.ipv4.conf.all.rp_filter 2 safe
61}
62
63mpls_setup_tnl()
64{
65	local ip_loc="$1"
66	local ip_rmt="$2"
67	local label="$3"
68	local mask
69
70	echo "$ip_loc" | grep -q ':' && mask=128 || mask=32
71
72	ROD ip route add $ip_rmt/$mask encap mpls $label dev ltp_v0
73	ROD ip -f mpls route add $((label + 1)) dev lo
74
75	tst_rhost_run -s -c "ip route add $ip_loc/$mask encap mpls $((label + 1)) dev ltp_v0"
76	tst_rhost_run -s -c "ip -f mpls route add $label dev lo"
77}
78mpls_virt_setup()
79{
80	mpls_setup 62
81
82	virt_lib_setup
83
84	tst_res TINFO "test $virt_type with MPLS"
85	virt_setup "local $(tst_ipaddr) remote $(tst_ipaddr rhost) dev $(tst_iface)" \
86		   "local $(tst_ipaddr rhost) remote $(tst_ipaddr) dev $(tst_iface rhost)"
87
88	mpls_setup_tnl $ip_virt_local $ip_virt_remote 60
89	mpls_setup_tnl $ip6_virt_local $ip6_virt_remote 50
90
91	tst_set_sysctl net.mpls.conf.ltp_v0.input 1 safe
92}
93
94mpls_virt_test()
95{
96	local type=$2
97	local max_size=$TST_NET_MAX_PKT
98
99	if [ "$type" = "icmp" ]; then
100		tst_ping -I $ip_virt_local -H $ip_virt_remote -s "10 100 1000 2000 $max_size"
101		tst_ping -I $ip6_virt_local -H $ip6_virt_remote -s "10 100 1000 2000 $max_size"
102	else
103		tst_netload -S $ip_virt_local -H $ip_virt_remote -T $type -n 10 -N 10
104		tst_netload -S $ip6_virt_local -H $ip6_virt_remote -T $type -n 10 -N 10
105		tst_netload -S $ip_virt_local -H $ip_virt_remote -T $type -A $max_size
106		tst_netload -S $ip6_virt_local -H $ip6_virt_remote -T $type -A $max_size
107	fi
108}
109
110. tst_net.sh
111