• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1#!/bin/sh
2# SPDX-License-Identifier: GPL-2.0-or-later
3# Copyright (c) 2018 Oracle and/or its affiliates. All Rights Reserved.
4
5TST_MIN_KVER="4.3"
6TST_NEEDS_TMPDIR=1
7TST_NEEDS_ROOT=1
8TST_NEEDS_DRIVERS="mpls_router mpls_iptunnel mpls_gso"
9TST_NEEDS_CMDS="sysctl modprobe"
10TST_TEST_DATA="icmp tcp udp"
11
12. tst_net.sh
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()
37{
38	local label="$1"
39
40	tst_net_run -s "modprobe -a $TST_NEEDS_DRIVERS"
41
42	ROD sysctl -q net.mpls.conf.$(tst_iface).input=1
43	tst_set_sysctl net.mpls.conf.lo.input 1 safe
44	tst_set_sysctl net.mpls.platform_labels $label safe
45	rpf_loc="$(sysctl -n net.ipv4.conf.all.rp_filter)"
46
47	tst_rhost_run -s -c "sysctl -q net.mpls.conf.$(tst_iface rhost).input=1"
48	rpf_rmt="$(tst_rhost_run -c 'sysctl -n net.ipv4.conf.all.rp_filter')"
49
50	tst_set_sysctl net.ipv4.conf.all.rp_filter 2 safe
51}
52
53mpls_setup_tnl()
54{
55	local ip_loc="$1"
56	local ip_rmt="$2"
57	local label="$3"
58	local mask
59
60	echo "$ip_loc" | grep -q ':' && mask=128 || mask=32
61
62	ROD ip route add $ip_rmt/$mask encap mpls $label dev ltp_v0
63	ROD ip -f mpls route add $((label + 1)) dev lo
64
65	tst_rhost_run -s -c "ip route add $ip_loc/$mask encap mpls $((label + 1)) dev ltp_v0"
66	tst_rhost_run -s -c "ip -f mpls route add $label dev lo"
67}
68mpls_virt_setup()
69{
70	mpls_setup 62
71
72	virt_lib_setup
73
74	tst_res TINFO "test $virt_type with MPLS"
75	virt_setup "local $(tst_ipaddr) remote $(tst_ipaddr rhost) dev $(tst_iface)" \
76		   "local $(tst_ipaddr rhost) remote $(tst_ipaddr) dev $(tst_iface rhost)"
77
78	mpls_setup_tnl $ip_virt_local $ip_virt_remote 60
79	mpls_setup_tnl $ip6_virt_local $ip6_virt_remote 50
80
81	tst_set_sysctl net.mpls.conf.ltp_v0.input 1 safe
82}
83
84mpls_virt_test()
85{
86	local type=$2
87	local max_size=10000
88
89	if [ "$type" = "icmp" ]; then
90		tst_ping $ip_virt_local $ip_virt_remote 10 100 1000 2000 $max_size
91		tst_ping $ip6_virt_local $ip6_virt_remote 10 100 1000 2000 $max_size
92	else
93		tst_netload -S $ip_virt_local -H $ip_virt_remote -T $type -n 10 -N 10
94		tst_netload -S $ip6_virt_local -H $ip6_virt_remote -T $type -n 10 -N 10
95		tst_netload -S $ip_virt_local -H $ip_virt_remote -T $type -A $max_size
96		tst_netload -S $ip6_virt_local -H $ip6_virt_remote -T $type -A $max_size
97	fi
98}
99