• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1#!/bin/bash
2# SPDX-License-Identifier: GPL-2.0
3
4# Kselftest framework requirement - SKIP code is 4.
5ksft_skip=4
6
7ALL_TESTS="loopback_test"
8NUM_NETIFS=2
9source tc_common.sh
10source lib.sh
11
12h1_create()
13{
14	simple_if_init $h1 192.0.2.1/24
15	tc qdisc add dev $h1 clsact
16}
17
18h1_destroy()
19{
20	tc qdisc del dev $h1 clsact
21	simple_if_fini $h1 192.0.2.1/24
22}
23
24h2_create()
25{
26	simple_if_init $h2
27}
28
29h2_destroy()
30{
31	simple_if_fini $h2
32}
33
34loopback_test()
35{
36	RET=0
37
38	tc filter add dev $h1 ingress protocol arp pref 1 handle 101 flower \
39		skip_hw arp_op reply arp_tip 192.0.2.1 action drop
40
41	$MZ $h1 -c 1 -t arp -q
42
43	tc_check_packets "dev $h1 ingress" 101 1
44	check_fail $? "Matched on a filter without loopback setup"
45
46	ethtool -K $h1 loopback on
47	check_err $? "Failed to enable loopback"
48
49	setup_wait_dev $h1
50
51	$MZ $h1 -c 1 -t arp -q
52
53	tc_check_packets "dev $h1 ingress" 101 1
54	check_err $? "Did not match on filter with loopback"
55
56	ethtool -K $h1 loopback off
57	check_err $? "Failed to disable loopback"
58
59	$MZ $h1 -c 1 -t arp -q
60
61	tc_check_packets "dev $h1 ingress" 101 2
62	check_fail $? "Matched on a filter after loopback was removed"
63
64	tc filter del dev $h1 ingress protocol arp pref 1 handle 101 flower
65
66	log_test "loopback"
67}
68
69setup_prepare()
70{
71	h1=${NETIFS[p1]}
72	h2=${NETIFS[p2]}
73
74	vrf_prepare
75
76	h1_create
77	h2_create
78
79	if ethtool -k $h1 | grep loopback | grep -q fixed; then
80		log_test "SKIP: dev $h1 does not support loopback feature"
81		exit $ksft_skip
82	fi
83}
84
85cleanup()
86{
87	pre_cleanup
88
89	h2_destroy
90	h1_destroy
91
92	vrf_cleanup
93}
94
95trap cleanup EXIT
96
97setup_prepare
98setup_wait
99
100tests_run
101
102exit $EXIT_STATUS
103