1f08c3bdfSopenharmony_ci#!/bin/sh
2f08c3bdfSopenharmony_ci# SPDX-License-Identifier: GPL-2.0-or-later
3f08c3bdfSopenharmony_ci# Copyright (c) 2018 Oracle and/or its affiliates. All Rights Reserved.
4f08c3bdfSopenharmony_ci
5f08c3bdfSopenharmony_ciTST_SETUP="setup"
6f08c3bdfSopenharmony_ciTST_TESTFUNC="test"
7f08c3bdfSopenharmony_ciTST_CLEANUP="cleanup"
8f08c3bdfSopenharmony_ciTST_CNT=3
9f08c3bdfSopenharmony_ciTST_MIN_KVER="4.1"
10f08c3bdfSopenharmony_ciTST_NEEDS_TMPDIR=1
11f08c3bdfSopenharmony_ciTST_NEEDS_ROOT=1
12f08c3bdfSopenharmony_ciTST_NEEDS_DRIVERS="mpls_router"
13f08c3bdfSopenharmony_ciTST_NEEDS_CMDS="sysctl modprobe"
14f08c3bdfSopenharmony_ci
15f08c3bdfSopenharmony_ci
16f08c3bdfSopenharmony_cicleanup()
17f08c3bdfSopenharmony_ci{
18f08c3bdfSopenharmony_ci	ip -f mpls route flush dev lo > /dev/null 2>&1
19f08c3bdfSopenharmony_ci	ip -f mpls route flush dev $(tst_iface) > /dev/null 2>&1
20f08c3bdfSopenharmony_ci}
21f08c3bdfSopenharmony_ci
22f08c3bdfSopenharmony_cisetup()
23f08c3bdfSopenharmony_ci{
24f08c3bdfSopenharmony_ci	ROD modprobe mpls_router
25f08c3bdfSopenharmony_ci}
26f08c3bdfSopenharmony_ci
27f08c3bdfSopenharmony_citest1()
28f08c3bdfSopenharmony_ci{
29f08c3bdfSopenharmony_ci	ROD sysctl -q net.mpls.platform_labels=0xfffff
30f08c3bdfSopenharmony_ci	ROD ip -f mpls route add 0xffffe dev lo
31f08c3bdfSopenharmony_ci	ROD ip -f mpls route show \> /dev/null
32f08c3bdfSopenharmony_ci	ROD ip -f mpls route del 0xffffe dev lo
33f08c3bdfSopenharmony_ci	tst_res TPASS "added label 0xffffe to lo dev"
34f08c3bdfSopenharmony_ci}
35f08c3bdfSopenharmony_ci
36f08c3bdfSopenharmony_citest2()
37f08c3bdfSopenharmony_ci{
38f08c3bdfSopenharmony_ci	ROD sysctl -q net.mpls.platform_labels=0xffffe
39f08c3bdfSopenharmony_ci	ip -f mpls route add 0xffffe dev lo > /dev/null 2>&1
40f08c3bdfSopenharmony_ci	if [ $? -eq 0 ]; then
41f08c3bdfSopenharmony_ci		tst_res TFAIL "can add label that is >= platform_labels"
42f08c3bdfSopenharmony_ci		return
43f08c3bdfSopenharmony_ci	fi
44f08c3bdfSopenharmony_ci
45f08c3bdfSopenharmony_ci	tst_res TPASS "can't add label >= platform_lables"
46f08c3bdfSopenharmony_ci}
47f08c3bdfSopenharmony_ci
48f08c3bdfSopenharmony_citest3()
49f08c3bdfSopenharmony_ci{
50f08c3bdfSopenharmony_ci	local start=16
51f08c3bdfSopenharmony_ci	local end=$((start + NS_TIMES))
52f08c3bdfSopenharmony_ci
53f08c3bdfSopenharmony_ci	ROD sysctl -q net.mpls.platform_labels=$((end + 1))
54f08c3bdfSopenharmony_ci	tst_res TINFO "creating mpls routes with labels from $start..$end"
55f08c3bdfSopenharmony_ci	for l in $(seq $start $end); do
56f08c3bdfSopenharmony_ci		ROD ip -f mpls route add $l dev $(tst_iface)
57f08c3bdfSopenharmony_ci	done
58f08c3bdfSopenharmony_ci
59f08c3bdfSopenharmony_ci	tst_res TINFO "listing created routes"
60f08c3bdfSopenharmony_ci	ROD ip -f mpls route show \> /dev/null
61f08c3bdfSopenharmony_ci
62f08c3bdfSopenharmony_ci	tst_res TINFO "removing the routes"
63f08c3bdfSopenharmony_ci	for l in $(seq $start $end); do
64f08c3bdfSopenharmony_ci		ROD ip -f mpls route del $l dev $(tst_iface)
65f08c3bdfSopenharmony_ci	done
66f08c3bdfSopenharmony_ci	tst_res TPASS "created and removed mpls routes"
67f08c3bdfSopenharmony_ci}
68f08c3bdfSopenharmony_ci
69f08c3bdfSopenharmony_ci. tst_net.sh
70f08c3bdfSopenharmony_citst_run
71