cachepc-linux

Fork of AMDESE/linux with modifications for CachePC side-channel attack
git clone https://git.sinitax.com/sinitax/cachepc-linux
Log | Files | Refs | README | LICENSE | sfeed.txt

tc_flower_router.sh (3096B)


      1#!/bin/bash
      2# SPDX-License-Identifier: GPL-2.0
      3
      4ALL_TESTS="match_indev_egress_test"
      5NUM_NETIFS=6
      6source tc_common.sh
      7source lib.sh
      8
      9h1_create()
     10{
     11	simple_if_init $h1 192.0.1.1/24
     12
     13	ip route add 192.0.2.0/24 vrf v$h1 nexthop via 192.0.1.2
     14	ip route add 192.0.3.0/24 vrf v$h1 nexthop via 192.0.1.2
     15}
     16
     17h1_destroy()
     18{
     19	ip route del 192.0.3.0/24 vrf v$h1
     20	ip route del 192.0.2.0/24 vrf v$h1
     21
     22	simple_if_fini $h1 192.0.1.1/24
     23}
     24
     25h2_create()
     26{
     27	simple_if_init $h2 192.0.2.1/24
     28
     29	ip route add 192.0.1.0/24 vrf v$h2 nexthop via 192.0.2.2
     30	ip route add 192.0.3.0/24 vrf v$h2 nexthop via 192.0.2.2
     31}
     32
     33h2_destroy()
     34{
     35	ip route del 192.0.3.0/24 vrf v$h2
     36	ip route del 192.0.1.0/24 vrf v$h2
     37
     38	simple_if_fini $h2 192.0.2.1/24
     39}
     40
     41h3_create()
     42{
     43	simple_if_init $h3 192.0.3.1/24
     44
     45	ip route add 192.0.1.0/24 vrf v$h3 nexthop via 192.0.3.2
     46	ip route add 192.0.2.0/24 vrf v$h3 nexthop via 192.0.3.2
     47}
     48
     49h3_destroy()
     50{
     51	ip route del 192.0.2.0/24 vrf v$h3
     52	ip route del 192.0.1.0/24 vrf v$h3
     53
     54	simple_if_fini $h3 192.0.3.1/24
     55}
     56
     57
     58router_create()
     59{
     60	ip link set dev $rp1 up
     61	ip link set dev $rp2 up
     62	ip link set dev $rp3 up
     63
     64	tc qdisc add dev $rp3 clsact
     65
     66	ip address add 192.0.1.2/24 dev $rp1
     67	ip address add 192.0.2.2/24 dev $rp2
     68	ip address add 192.0.3.2/24 dev $rp3
     69}
     70
     71router_destroy()
     72{
     73	ip address del 192.0.3.2/24 dev $rp3
     74	ip address del 192.0.2.2/24 dev $rp2
     75	ip address del 192.0.1.2/24 dev $rp1
     76
     77	tc qdisc del dev $rp3 clsact
     78
     79	ip link set dev $rp3 down
     80	ip link set dev $rp2 down
     81	ip link set dev $rp1 down
     82}
     83
     84match_indev_egress_test()
     85{
     86	RET=0
     87
     88	tc filter add dev $rp3 egress protocol ip pref 1 handle 101 flower \
     89		$tcflags indev $rp1 dst_ip 192.0.3.1 action drop
     90	tc filter add dev $rp3 egress protocol ip pref 2 handle 102 flower \
     91		$tcflags indev $rp2 dst_ip 192.0.3.1 action drop
     92
     93	$MZ $h1 -c 1 -p 64 -a $h1mac -b $rp1mac -A 192.0.1.1 -B 192.0.3.1 \
     94		-t ip -q
     95
     96	tc_check_packets "dev $rp3 egress" 102 1
     97	check_fail $? "Matched on a wrong filter"
     98
     99	tc_check_packets "dev $rp3 egress" 101 1
    100	check_err $? "Did not match on correct filter"
    101
    102	$MZ $h2 -c 1 -p 64 -a $h2mac -b $rp2mac -A 192.0.2.1 -B 192.0.3.1 \
    103		-t ip -q
    104
    105	tc_check_packets "dev $rp3 egress" 101 2
    106	check_fail $? "Matched on a wrong filter"
    107
    108	tc_check_packets "dev $rp3 egress" 102 1
    109	check_err $? "Did not match on correct filter"
    110
    111	tc filter del dev $rp3 egress protocol ip pref 2 handle 102 flower
    112	tc filter del dev $rp3 egress protocol ip pref 1 handle 101 flower
    113
    114	log_test "indev egress match ($tcflags)"
    115}
    116
    117setup_prepare()
    118{
    119	h1=${NETIFS[p1]}
    120	rp1=${NETIFS[p2]}
    121
    122	h2=${NETIFS[p3]}
    123	rp2=${NETIFS[p4]}
    124
    125	h3=${NETIFS[p5]}
    126	rp3=${NETIFS[p6]}
    127
    128	h1mac=$(mac_get $h1)
    129	rp1mac=$(mac_get $rp1)
    130	h2mac=$(mac_get $h2)
    131	rp2mac=$(mac_get $rp2)
    132
    133	vrf_prepare
    134
    135	h1_create
    136	h2_create
    137	h3_create
    138
    139	router_create
    140
    141	forwarding_enable
    142}
    143
    144cleanup()
    145{
    146	pre_cleanup
    147
    148	forwarding_restore
    149
    150	router_destroy
    151
    152	h3_destroy
    153	h2_destroy
    154	h1_destroy
    155
    156	vrf_cleanup
    157}
    158
    159trap cleanup EXIT
    160
    161setup_prepare
    162setup_wait
    163
    164tc_offload_check
    165if [[ $? -ne 0 ]]; then
    166	log_info "Could not test offloaded functionality"
    167else
    168	tcflags="skip_sw"
    169	tests_run
    170fi
    171
    172exit $EXIT_STATUS