Linux kernel mirror (for testing)
git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel
os
linux
1#!/bin/bash
2# SPDX-License-Identifier: GPL-2.0
3
4# See virtio_net_common.sh comments for more details about assumed setup
5
6ALL_TESTS="
7 initial_ping_test
8 f_mac_test
9"
10
11source virtio_net_common.sh
12
13lib_dir=$(dirname "$0")
14source "$lib_dir"/../../../net/forwarding/lib.sh
15
16h1=${NETIFS[p1]}
17h2=${NETIFS[p2]}
18
19h1_create()
20{
21 simple_if_init $h1 $H1_IPV4/24 $H1_IPV6/64
22}
23
24h1_destroy()
25{
26 simple_if_fini $h1 $H1_IPV4/24 $H1_IPV6/64
27}
28
29h2_create()
30{
31 simple_if_init $h2 $H2_IPV4/24 $H2_IPV6/64
32}
33
34h2_destroy()
35{
36 simple_if_fini $h2 $H2_IPV4/24 $H2_IPV6/64
37}
38
39initial_ping_test()
40{
41 setup_cleanup
42 setup_prepare
43 ping_test $h1 $H2_IPV4 " simple"
44}
45
46f_mac_test()
47{
48 RET=0
49 local test_name="mac feature filtered"
50
51 virtio_feature_present $h1 $VIRTIO_NET_F_MAC
52 if [ $? -ne 0 ]; then
53 log_test_skip "$test_name" "Device $h1 is missing feature $VIRTIO_NET_F_MAC."
54 return 0
55 fi
56 virtio_feature_present $h1 $VIRTIO_NET_F_MAC
57 if [ $? -ne 0 ]; then
58 log_test_skip "$test_name" "Device $h2 is missing feature $VIRTIO_NET_F_MAC."
59 return 0
60 fi
61
62 setup_cleanup
63 setup_prepare
64
65 grep -q 0 /sys/class/net/$h1/addr_assign_type
66 check_err $? "Permanent address assign type for $h1 is not set"
67 grep -q 0 /sys/class/net/$h2/addr_assign_type
68 check_err $? "Permanent address assign type for $h2 is not set"
69
70 setup_cleanup
71 virtio_filter_feature_add $h1 $VIRTIO_NET_F_MAC
72 virtio_filter_feature_add $h2 $VIRTIO_NET_F_MAC
73 setup_prepare
74
75 grep -q 0 /sys/class/net/$h1/addr_assign_type
76 check_fail $? "Permanent address assign type for $h1 is set when F_MAC feature is filtered"
77 grep -q 0 /sys/class/net/$h2/addr_assign_type
78 check_fail $? "Permanent address assign type for $h2 is set when F_MAC feature is filtered"
79
80 ping_do $h1 $H2_IPV4
81 check_err $? "Ping failed"
82
83 log_test "$test_name"
84}
85
86setup_prepare()
87{
88 virtio_device_rebind $h1
89 virtio_device_rebind $h2
90 wait_for_dev $h1
91 wait_for_dev $h2
92
93 vrf_prepare
94
95 h1_create
96 h2_create
97}
98
99setup_cleanup()
100{
101 h2_destroy
102 h1_destroy
103
104 vrf_cleanup
105
106 virtio_filter_features_clear $h1
107 virtio_filter_features_clear $h2
108 virtio_device_rebind $h1
109 virtio_device_rebind $h2
110 wait_for_dev $h1
111 wait_for_dev $h2
112}
113
114cleanup()
115{
116 pre_cleanup
117 setup_cleanup
118}
119
120check_driver $h1 "virtio_net"
121check_driver $h2 "virtio_net"
122check_virtio_debugfs $h1
123check_virtio_debugfs $h2
124
125trap cleanup EXIT
126
127setup_prepare
128
129tests_run
130
131exit "$EXIT_STATUS"