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