132 lines · bash
1#!/bin/bash2# SPDX-License-Identifier: GPL-2.03 4# See virtio_net_common.sh comments for more details about assumed setup5 6ALL_TESTS="7 initial_ping_test8 f_mac_test9"10 11source virtio_net_common.sh12 13lib_dir=$(dirname "$0")14source "$lib_dir"/../../../net/forwarding/lib.sh15 16h1=${NETIFS[p1]}17h2=${NETIFS[p2]}18 19h1_create()20{21 simple_if_init $h1 $H1_IPV4/24 $H1_IPV6/6422}23 24h1_destroy()25{26 simple_if_fini $h1 $H1_IPV4/24 $H1_IPV6/6427}28 29h2_create()30{31 simple_if_init $h2 $H2_IPV4/24 $H2_IPV6/6432}33 34h2_destroy()35{36 simple_if_fini $h2 $H2_IPV4/24 $H2_IPV6/6437}38 39initial_ping_test()40{41 setup_cleanup42 setup_prepare43 ping_test $h1 $H2_IPV4 " simple"44}45 46f_mac_test()47{48 RET=049 local test_name="mac feature filtered"50 51 virtio_feature_present $h1 $VIRTIO_NET_F_MAC52 if [ $? -ne 0 ]; then53 log_test_skip "$test_name" "Device $h1 is missing feature $VIRTIO_NET_F_MAC."54 return 055 fi56 virtio_feature_present $h1 $VIRTIO_NET_F_MAC57 if [ $? -ne 0 ]; then58 log_test_skip "$test_name" "Device $h2 is missing feature $VIRTIO_NET_F_MAC."59 return 060 fi61 62 setup_cleanup63 setup_prepare64 65 grep -q 0 /sys/class/net/$h1/addr_assign_type66 check_err $? "Permanent address assign type for $h1 is not set"67 grep -q 0 /sys/class/net/$h2/addr_assign_type68 check_err $? "Permanent address assign type for $h2 is not set"69 70 setup_cleanup71 virtio_filter_feature_add $h1 $VIRTIO_NET_F_MAC72 virtio_filter_feature_add $h2 $VIRTIO_NET_F_MAC73 setup_prepare74 75 grep -q 0 /sys/class/net/$h1/addr_assign_type76 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_type78 check_fail $? "Permanent address assign type for $h2 is set when F_MAC feature is filtered"79 80 ping_do $h1 $H2_IPV481 check_err $? "Ping failed"82 83 log_test "$test_name"84}85 86setup_prepare()87{88 virtio_device_rebind $h189 virtio_device_rebind $h290 wait_for_dev $h191 wait_for_dev $h292 93 vrf_prepare94 95 h1_create96 h2_create97}98 99setup_cleanup()100{101 h2_destroy102 h1_destroy103 104 vrf_cleanup105 106 virtio_filter_features_clear $h1107 virtio_filter_features_clear $h2108 virtio_device_rebind $h1109 virtio_device_rebind $h2110 wait_for_dev $h1111 wait_for_dev $h2112}113 114cleanup()115{116 pre_cleanup117 setup_cleanup118}119 120check_driver $h1 "virtio_net"121check_driver $h2 "virtio_net"122check_virtio_debugfs $h1123check_virtio_debugfs $h2124 125trap cleanup EXIT126 127setup_prepare128 129tests_run130 131exit "$EXIT_STATUS"132