Initial commit: Linux kernel 4.19 for Unplugged OS

This commit is contained in:
ziv committed 2025-10-06 13:52:42 +00:00
commit d30235b04c
80519 files changed
+35800681

No files matched your search

@@ -0,0 +1,58 @@
Motivation
==========
One of the nice things about network namespaces is that they allow one
to easily create and test complex environments.
Unfortunately, these namespaces can not be used with actual switching
ASICs, as their ports can not be migrated to other network namespaces
(NETIF_F_NETNS_LOCAL) and most of them probably do not support the
L1-separation provided by namespaces.
However, a similar kind of flexibility can be achieved by using VRFs and
by looping the switch ports together. For example:
br0
+
vrf-h1 | vrf-h2
+ +---+----+ +
| | | |
192.0.2.1/24 + + + + 192.0.2.2/24
swp1 swp2 swp3 swp4
+ + + +
| | | |
+--------+ +--------+
The VRFs act as lightweight namespaces representing hosts connected to
the switch.
This approach for testing switch ASICs has several advantages over the
traditional method that requires multiple physical machines, to name a
few:
1. Only the device under test (DUT) is being tested without noise from
other system.
2. Ability to easily provision complex topologies. Testing bridging
between 4-ports LAGs or 8-way ECMP requires many physical links that are
not always available. With the VRF-based approach one merely needs to
loopback more ports.
These tests are written with switch ASICs in mind, but they can be run
on any Linux box using veth pairs to emulate physical loopbacks.
Guidelines for Writing Tests
============================
o Where possible, reuse an existing topology for different tests instead
of recreating the same topology.
o Tests that use anything but the most trivial topologies should include
an ASCII art showing the topology.
o Where possible, IPv6 and IPv4 addresses shall conform to RFC 3849 and
RFC 5737, respectively.
o Where possible, tests shall be written so that they can be reused by
multiple topologies and added to lib.sh.
o Checks shall be added to lib.sh for any external dependencies.
o Code shall be checked using ShellCheck [1] prior to submission.
1. https://www.shellcheck.net/
@@ -0,0 +1,151 @@
#!/bin/bash
# SPDX-License-Identifier: GPL-2.0
ALL_TESTS="ping_ipv4 ping_ipv6 flooding"
NUM_NETIFS=6
CHECK_TC="yes"
source lib.sh
h1_create()
{
simple_if_init $h1 192.0.2.1/24 2001:db8:1::1/64
}
h1_destroy()
{
simple_if_fini $h1 192.0.2.1/24 2001:db8:1::1/64
}
h2_create()
{
simple_if_init $h2 192.0.2.2/24 2001:db8:1::2/64
}
h2_destroy()
{
simple_if_fini $h2 192.0.2.2/24 2001:db8:1::2/64
}
h3_create()
{
simple_if_init $h3 192.0.2.3/24 2001:db8:1::3/64
}
h3_destroy()
{
simple_if_fini $h3 192.0.2.3/24 2001:db8:1::3/64
}
switch_create()
{
ip link add dev br0 type bridge
ip link set dev $swp1 master br0
ip link set dev $swp2 master br0
ip link set dev $swp3 master br0
ip link set dev $swp1 type bridge_slave isolated on
check_err $? "Can't set isolation on port $swp1"
ip link set dev $swp2 type bridge_slave isolated on
check_err $? "Can't set isolation on port $swp2"
ip link set dev $swp3 type bridge_slave isolated off
check_err $? "Can't disable isolation on port $swp3"
ip link set dev br0 up
ip link set dev $swp1 up
ip link set dev $swp2 up
ip link set dev $swp3 up
}
switch_destroy()
{
ip link set dev $swp3 down
ip link set dev $swp2 down
ip link set dev $swp1 down
ip link del dev br0
}
setup_prepare()
{
h1=${NETIFS[p1]}
swp1=${NETIFS[p2]}
swp2=${NETIFS[p3]}
h2=${NETIFS[p4]}
swp3=${NETIFS[p5]}
h3=${NETIFS[p6]}
vrf_prepare
h1_create
h2_create
h3_create
switch_create
}
cleanup()
{
pre_cleanup
switch_destroy
h3_destroy
h2_destroy
h1_destroy
vrf_cleanup
}
ping_ipv4()
{
RET=0
ping_do $h1 192.0.2.2
check_fail $? "Ping worked when it should not have"
RET=0
ping_do $h3 192.0.2.2
check_err $? "Ping didn't work when it should have"
log_test "Isolated port ping"
}
ping_ipv6()
{
RET=0
ping6_do $h1 2001:db8:1::2
check_fail $? "Ping6 worked when it should not have"
RET=0
ping6_do $h3 2001:db8:1::2
check_err $? "Ping6 didn't work when it should have"
log_test "Isolated port ping6"
}
flooding()
{
local mac=de:ad:be:ef:13:37
local ip=192.0.2.100
RET=0
flood_test_do false $mac $ip $h1 $h2
check_err $? "Packet was flooded when it should not have been"
RET=0
flood_test_do true $mac $ip $h3 $h2
check_err $? "Packet was not flooded when it should have been"
log_test "Isolated port flooding"
}
trap cleanup EXIT
setup_prepare
setup_wait
tests_run
exit $EXIT_STATUS
+151
View File
@@ -0,0 +1,151 @@
#!/bin/bash
# SPDX-License-Identifier: GPL-2.0
ALL_TESTS="ping_ipv4 ping_ipv6 learning flooding vlan_deletion extern_learn"
NUM_NETIFS=4
CHECK_TC="yes"
source lib.sh
h1_create()
{
simple_if_init $h1 192.0.2.1/24 2001:db8:1::1/64
}
h1_destroy()
{
simple_if_fini $h1 192.0.2.1/24 2001:db8:1::1/64
}
h2_create()
{
simple_if_init $h2 192.0.2.2/24 2001:db8:1::2/64
}
h2_destroy()
{
simple_if_fini $h2 192.0.2.2/24 2001:db8:1::2/64
}
switch_create()
{
# 10 Seconds ageing time.
ip link add dev br0 type bridge vlan_filtering 1 ageing_time 1000 \
mcast_snooping 0
ip link set dev $swp1 master br0
ip link set dev $swp2 master br0
ip link set dev br0 up
ip link set dev $swp1 up
ip link set dev $swp2 up
}
switch_destroy()
{
ip link set dev $swp2 down
ip link set dev $swp1 down
ip link del dev br0
}
setup_prepare()
{
h1=${NETIFS[p1]}
swp1=${NETIFS[p2]}
swp2=${NETIFS[p3]}
h2=${NETIFS[p4]}
vrf_prepare
h1_create
h2_create
switch_create
}
cleanup()
{
pre_cleanup
switch_destroy
h2_destroy
h1_destroy
vrf_cleanup
}
ping_ipv4()
{
ping_test $h1 192.0.2.2
}
ping_ipv6()
{
ping6_test $h1 2001:db8:1::2
}
learning()
{
learning_test "br0" $swp1 $h1 $h2
}
flooding()
{
flood_test $swp2 $h1 $h2
}
vlan_deletion()
{
# Test that the deletion of a VLAN on a bridge port does not affect
# the PVID VLAN
log_info "Add and delete a VLAN on bridge port $swp1"
bridge vlan add vid 10 dev $swp1
bridge vlan del vid 10 dev $swp1
ping_ipv4
ping_ipv6
}
extern_learn()
{
local mac=de:ad:be:ef:13:37
local ageing_time
# Test that externally learned FDB entries can roam, but not age out
RET=0
bridge fdb add de:ad:be:ef:13:37 dev $swp1 master extern_learn vlan 1
bridge fdb show brport $swp1 | grep -q de:ad:be:ef:13:37
check_err $? "Did not find FDB entry when should"
# Wait for 10 seconds after the ageing time to make sure the FDB entry
# was not aged out
ageing_time=$(bridge_ageing_time_get br0)
sleep $((ageing_time + 10))
bridge fdb show brport $swp1 | grep -q de:ad:be:ef:13:37
check_err $? "FDB entry was aged out when should not"
$MZ $h2 -c 1 -p 64 -a $mac -t ip -q
bridge fdb show brport $swp2 | grep -q de:ad:be:ef:13:37
check_err $? "FDB entry did not roam when should"
log_test "Externally learned FDB entry - ageing & roaming"
bridge fdb del de:ad:be:ef:13:37 dev $swp2 master vlan 1 &> /dev/null
bridge fdb del de:ad:be:ef:13:37 dev $swp1 master vlan 1 &> /dev/null
}
trap cleanup EXIT
setup_prepare
setup_wait
tests_run
exit $EXIT_STATUS
@@ -0,0 +1,104 @@
#!/bin/bash
# SPDX-License-Identifier: GPL-2.0
ALL_TESTS="ping_ipv4 ping_ipv6 learning flooding"
NUM_NETIFS=4
source lib.sh
h1_create()
{
simple_if_init $h1 192.0.2.1/24 2001:db8:1::1/64
}
h1_destroy()
{
simple_if_fini $h1 192.0.2.1/24 2001:db8:1::1/64
}
h2_create()
{
simple_if_init $h2 192.0.2.2/24 2001:db8:1::2/64
}
h2_destroy()
{
simple_if_fini $h2 192.0.2.2/24 2001:db8:1::2/64
}
switch_create()
{
# 10 Seconds ageing time.
ip link add dev br0 type bridge ageing_time 1000 mcast_snooping 0
ip link set dev $swp1 master br0
ip link set dev $swp2 master br0
ip link set dev br0 up
ip link set dev $swp1 up
ip link set dev $swp2 up
}
switch_destroy()
{
ip link set dev $swp2 down
ip link set dev $swp1 down
ip link del dev br0
}
setup_prepare()
{
h1=${NETIFS[p1]}
swp1=${NETIFS[p2]}
swp2=${NETIFS[p3]}
h2=${NETIFS[p4]}
vrf_prepare
h1_create
h2_create
switch_create
}
cleanup()
{
pre_cleanup
switch_destroy
h2_destroy
h1_destroy
vrf_cleanup
}
ping_ipv4()
{
ping_test $h1 192.0.2.2
}
ping_ipv6()
{
ping6_test $h1 2001:db8:1::2
}
learning()
{
learning_test "br0" $swp1 $h1 $h2
}
flooding()
{
flood_test $swp2 $h1 $h2
}
trap cleanup EXIT
setup_prepare
setup_wait
tests_run
exit $EXIT_STATUS
@@ -0,0 +1,12 @@
CONFIG_BRIDGE=m
CONFIG_VLAN_8021Q=m
CONFIG_BRIDGE_VLAN_FILTERING=y
CONFIG_NET_L3_MASTER_DEV=y
CONFIG_IPV6_MULTIPLE_TABLES=y
CONFIG_NET_VRF=m
CONFIG_BPF_SYSCALL=y
CONFIG_CGROUP_BPF=y
CONFIG_NET_CLS_FLOWER=m
CONFIG_NET_SCH_INGRESS=m
CONFIG_NET_ACT_GACT=m
CONFIG_VETH=m
@@ -0,0 +1,108 @@
#!/bin/bash
# SPDX-License-Identifier: GPL-2.0
##############################################################################
# Source library
relative_path="${BASH_SOURCE%/*}"
if [[ "$relative_path" == "${BASH_SOURCE}" ]]; then
relative_path="."
fi
source "$relative_path/lib.sh"
##############################################################################
# Defines
DEVLINK_DEV=$(devlink port show | grep "${NETIFS[p1]}" | \
grep -v "${NETIFS[p1]}[0-9]" | cut -d" " -f1 | \
rev | cut -d"/" -f2- | rev)
if [ -z "$DEVLINK_DEV" ]; then
echo "SKIP: ${NETIFS[p1]} has no devlink device registered for it"
exit 1
fi
if [[ "$(echo $DEVLINK_DEV | grep -c pci)" -eq 0 ]]; then
echo "SKIP: devlink device's bus is not PCI"
exit 1
fi
DEVLINK_VIDDID=$(lspci -s $(echo $DEVLINK_DEV | cut -d"/" -f2) \
-n | cut -d" " -f3)
##############################################################################
# Sanity checks
devlink -j resource show "$DEVLINK_DEV" &> /dev/null
if [ $? -ne 0 ]; then
echo "SKIP: iproute2 too old, missing devlink resource support"
exit 1
fi
##############################################################################
# Devlink helpers
devlink_resource_names_to_path()
{
local resource
local path=""
for resource in "${@}"; do
if [ "$path" == "" ]; then
path="$resource"
else
path="${path}/$resource"
fi
done
echo "$path"
}
devlink_resource_get()
{
local name=$1
local resource_name=.[][\"$DEVLINK_DEV\"]
resource_name="$resource_name | .[] | select (.name == \"$name\")"
shift
for resource in "${@}"; do
resource_name="${resource_name} | .[\"resources\"][] | \
select (.name == \"$resource\")"
done
devlink -j resource show "$DEVLINK_DEV" | jq "$resource_name"
}
devlink_resource_size_get()
{
local size=$(devlink_resource_get "$@" | jq '.["size_new"]')
if [ "$size" == "null" ]; then
devlink_resource_get "$@" | jq '.["size"]'
else
echo "$size"
fi
}
devlink_resource_size_set()
{
local new_size=$1
local path
shift
path=$(devlink_resource_names_to_path "$@")
devlink resource set "$DEVLINK_DEV" path "$path" size "$new_size"
check_err $? "Failed setting path $path to size $size"
}
devlink_reload()
{
local still_pending
devlink dev reload "$DEVLINK_DEV" &> /dev/null
check_err $? "Failed reload"
still_pending=$(devlink resource show "$DEVLINK_DEV" | \
grep -c "size_new")
check_err $still_pending "Failed reload - There are still unset sizes"
}
@@ -0,0 +1,35 @@
#!/bin/bash
# SPDX-License-Identifier: GPL-2.0
##############################################################################
# Topology description. p1 looped back to p2, p3 to p4 and so on.
declare -A NETIFS
NETIFS[p1]=veth0
NETIFS[p2]=veth1
NETIFS[p3]=veth2
NETIFS[p4]=veth3
NETIFS[p5]=veth4
NETIFS[p6]=veth5
NETIFS[p7]=veth6
NETIFS[p8]=veth7
##############################################################################
# Defines
# IPv4 ping utility name
PING=ping
# IPv6 ping utility name. Some distributions use 'ping' for IPv6.
PING6=ping6
# Packet generator. Some distributions use 'mz'.
MZ=mausezahn
# Time to wait after interfaces participating in the test are all UP
WAIT_TIME=5
# Whether to pause on failure or not.
PAUSE_ON_FAIL=no
# Whether to pause on cleanup or not.
PAUSE_ON_CLEANUP=no
# Type of network interface to create
NETIF_TYPE=veth
# Whether to create virtual interfaces (veth) or not
NETIF_CREATE=yes
+257
View File
@@ -0,0 +1,257 @@
#!/bin/bash
# SPDX-License-Identifier: GPL-2.0
# Test traffic distribution when a wECMP route forwards traffic to two GRE
# tunnels.
#
# +-------------------------+
# | H1 |
# | $h1 + |
# | 192.0.2.1/28 | |
# +-------------------|-----+
# |
# +-------------------|------------------------+
# | SW1 | |
# | $ol1 + |
# | 192.0.2.2/28 |
# | |
# | + g1a (gre) + g1b (gre) |
# | loc=192.0.2.65 loc=192.0.2.81 |
# | rem=192.0.2.66 --. rem=192.0.2.82 --. |
# | tos=inherit | tos=inherit | |
# | .------------------' | |
# | | .------------------' |
# | v v |
# | + $ul1.111 (vlan) + $ul1.222 (vlan) |
# | | 192.0.2.129/28 | 192.0.2.145/28 |
# | \ / |
# | \________________/ |
# | | |
# | + $ul1 |
# +------------|-------------------------------+
# |
# +------------|-------------------------------+
# | SW2 + $ul2 |
# | _______|________ |
# | / \ |
# | / \ |
# | + $ul2.111 (vlan) + $ul2.222 (vlan) |
# | ^ 192.0.2.130/28 ^ 192.0.2.146/28 |
# | | | |
# | | '------------------. |
# | '------------------. | |
# | + g2a (gre) | + g2b (gre) | |
# | loc=192.0.2.66 | loc=192.0.2.82 | |
# | rem=192.0.2.65 --' rem=192.0.2.81 --' |
# | tos=inherit tos=inherit |
# | |
# | $ol2 + |
# | 192.0.2.17/28 | |
# +-------------------|------------------------+
# |
# +-------------------|-----+
# | H2 | |
# | $h2 + |
# | 192.0.2.18/28 |
# +-------------------------+
ALL_TESTS="
ping_ipv4
multipath_ipv4
"
NUM_NETIFS=6
source lib.sh
h1_create()
{
simple_if_init $h1 192.0.2.1/28 2001:db8:1::1/64
ip route add vrf v$h1 192.0.2.16/28 via 192.0.2.2
}
h1_destroy()
{
ip route del vrf v$h1 192.0.2.16/28 via 192.0.2.2
simple_if_fini $h1 192.0.2.1/28
}
sw1_create()
{
simple_if_init $ol1 192.0.2.2/28
__simple_if_init $ul1 v$ol1
vlan_create $ul1 111 v$ol1 192.0.2.129/28
vlan_create $ul1 222 v$ol1 192.0.2.145/28
tunnel_create g1a gre 192.0.2.65 192.0.2.66 tos inherit dev v$ol1
__simple_if_init g1a v$ol1 192.0.2.65/32
ip route add vrf v$ol1 192.0.2.66/32 via 192.0.2.130
tunnel_create g1b gre 192.0.2.81 192.0.2.82 tos inherit dev v$ol1
__simple_if_init g1b v$ol1 192.0.2.81/32
ip route add vrf v$ol1 192.0.2.82/32 via 192.0.2.146
ip route add vrf v$ol1 192.0.2.16/28 \
nexthop dev g1a \
nexthop dev g1b
}
sw1_destroy()
{
ip route del vrf v$ol1 192.0.2.16/28
ip route del vrf v$ol1 192.0.2.82/32 via 192.0.2.146
__simple_if_fini g1b 192.0.2.81/32
tunnel_destroy g1b
ip route del vrf v$ol1 192.0.2.66/32 via 192.0.2.130
__simple_if_fini g1a 192.0.2.65/32
tunnel_destroy g1a
vlan_destroy $ul1 222
vlan_destroy $ul1 111
__simple_if_fini $ul1
simple_if_fini $ol1 192.0.2.2/28
}
sw2_create()
{
simple_if_init $ol2 192.0.2.17/28
__simple_if_init $ul2 v$ol2
vlan_create $ul2 111 v$ol2 192.0.2.130/28
vlan_create $ul2 222 v$ol2 192.0.2.146/28
tunnel_create g2a gre 192.0.2.66 192.0.2.65 tos inherit dev v$ol2
__simple_if_init g2a v$ol2 192.0.2.66/32
ip route add vrf v$ol2 192.0.2.65/32 via 192.0.2.129
tunnel_create g2b gre 192.0.2.82 192.0.2.81 tos inherit dev v$ol2
__simple_if_init g2b v$ol2 192.0.2.82/32
ip route add vrf v$ol2 192.0.2.81/32 via 192.0.2.145
ip route add vrf v$ol2 192.0.2.0/28 \
nexthop dev g2a \
nexthop dev g2b
tc qdisc add dev $ul2 clsact
tc filter add dev $ul2 ingress pref 111 prot 802.1Q \
flower vlan_id 111 action pass
tc filter add dev $ul2 ingress pref 222 prot 802.1Q \
flower vlan_id 222 action pass
}
sw2_destroy()
{
tc qdisc del dev $ul2 clsact
ip route del vrf v$ol2 192.0.2.0/28
ip route del vrf v$ol2 192.0.2.81/32 via 192.0.2.145
__simple_if_fini g2b 192.0.2.82/32
tunnel_destroy g2b
ip route del vrf v$ol2 192.0.2.65/32 via 192.0.2.129
__simple_if_fini g2a 192.0.2.66/32
tunnel_destroy g2a
vlan_destroy $ul2 222
vlan_destroy $ul2 111
__simple_if_fini $ul2
simple_if_fini $ol2 192.0.2.17/28
}
h2_create()
{
simple_if_init $h2 192.0.2.18/28
ip route add vrf v$h2 192.0.2.0/28 via 192.0.2.17
}
h2_destroy()
{
ip route del vrf v$h2 192.0.2.0/28 via 192.0.2.17
simple_if_fini $h2 192.0.2.18/28
}
setup_prepare()
{
h1=${NETIFS[p1]}
ol1=${NETIFS[p2]}
ul1=${NETIFS[p3]}
ul2=${NETIFS[p4]}
ol2=${NETIFS[p5]}
h2=${NETIFS[p6]}
vrf_prepare
h1_create
sw1_create
sw2_create
h2_create
forwarding_enable
}
cleanup()
{
pre_cleanup
forwarding_restore
h2_destroy
sw2_destroy
sw1_destroy
h1_destroy
vrf_cleanup
}
multipath4_test()
{
local what=$1; shift
local weight1=$1; shift
local weight2=$1; shift
sysctl_set net.ipv4.fib_multipath_hash_policy 1
ip route replace vrf v$ol1 192.0.2.16/28 \
nexthop dev g1a weight $weight1 \
nexthop dev g1b weight $weight2
local t0_111=$(tc_rule_stats_get $ul2 111 ingress)
local t0_222=$(tc_rule_stats_get $ul2 222 ingress)
ip vrf exec v$h1 \
$MZ $h1 -q -p 64 -A 192.0.2.1 -B 192.0.2.18 \
-d 1msec -t udp "sp=1024,dp=0-32768"
local t1_111=$(tc_rule_stats_get $ul2 111 ingress)
local t1_222=$(tc_rule_stats_get $ul2 222 ingress)
local d111=$((t1_111 - t0_111))
local d222=$((t1_222 - t0_222))
multipath_eval "$what" $weight1 $weight2 $d111 $d222
ip route replace vrf v$ol1 192.0.2.16/28 \
nexthop dev g1a \
nexthop dev g1b
sysctl_restore net.ipv4.fib_multipath_hash_policy
}
ping_ipv4()
{
ping_test $h1 192.0.2.18
}
multipath_ipv4()
{
log_info "Running IPv4 multipath tests"
multipath4_test "ECMP" 1 1
multipath4_test "Weighted MP 2:1" 2 1
multipath4_test "Weighted MP 11:45" 11 45
}
trap cleanup EXIT
setup_prepare
setup_wait
tests_run
exit $EXIT_STATUS
@@ -0,0 +1,964 @@
#!/bin/bash
# SPDX-License-Identifier: GPL-2.0
##############################################################################
# Defines
# Can be overridden by the configuration file.
PING=${PING:=ping}
PING6=${PING6:=ping6}
MZ=${MZ:=mausezahn}
ARPING=${ARPING:=arping}
TEAMD=${TEAMD:=teamd}
WAIT_TIME=${WAIT_TIME:=5}
PAUSE_ON_FAIL=${PAUSE_ON_FAIL:=no}
PAUSE_ON_CLEANUP=${PAUSE_ON_CLEANUP:=no}
NETIF_TYPE=${NETIF_TYPE:=veth}
NETIF_CREATE=${NETIF_CREATE:=yes}
relative_path="${BASH_SOURCE%/*}"
if [[ "$relative_path" == "${BASH_SOURCE}" ]]; then
relative_path="."
fi
if [[ -f $relative_path/forwarding.config ]]; then
source "$relative_path/forwarding.config"
fi
##############################################################################
# Sanity checks
check_tc_version()
{
tc -j &> /dev/null
if [[ $? -ne 0 ]]; then
echo "SKIP: iproute2 too old; tc is missing JSON support"
exit 1
fi
}
check_tc_shblock_support()
{
tc filter help 2>&1 | grep block &> /dev/null
if [[ $? -ne 0 ]]; then
echo "SKIP: iproute2 too old; tc is missing shared block support"
exit 1
fi
}
check_tc_chain_support()
{
tc help 2>&1|grep chain &> /dev/null
if [[ $? -ne 0 ]]; then
echo "SKIP: iproute2 too old; tc is missing chain support"
exit 1
fi
}
if [[ "$(id -u)" -ne 0 ]]; then
echo "SKIP: need root privileges"
exit 0
fi
if [[ "$CHECK_TC" = "yes" ]]; then
check_tc_version
fi
require_command()
{
local cmd=$1; shift
if [[ ! -x "$(command -v "$cmd")" ]]; then
echo "SKIP: $cmd not installed"
exit 1
fi
}
require_command jq
require_command $MZ
if [[ ! -v NUM_NETIFS ]]; then
echo "SKIP: importer does not define \"NUM_NETIFS\""
exit 1
fi
##############################################################################
# Command line options handling
count=0
while [[ $# -gt 0 ]]; do
if [[ "$count" -eq "0" ]]; then
unset NETIFS
declare -A NETIFS
fi
count=$((count + 1))
NETIFS[p$count]="$1"
shift
done
##############################################################################
# Network interfaces configuration
create_netif_veth()
{
local i
for i in $(eval echo {1..$NUM_NETIFS}); do
local j=$((i+1))
ip link show dev ${NETIFS[p$i]} &> /dev/null
if [[ $? -ne 0 ]]; then
ip link add ${NETIFS[p$i]} type veth \
peer name ${NETIFS[p$j]}
if [[ $? -ne 0 ]]; then
echo "Failed to create netif"
exit 1
fi
fi
i=$j
done
}
create_netif()
{
case "$NETIF_TYPE" in
veth) create_netif_veth
;;
*) echo "Can not create interfaces of type \'$NETIF_TYPE\'"
exit 1
;;
esac
}
if [[ "$NETIF_CREATE" = "yes" ]]; then
create_netif
fi
for i in $(eval echo {1..$NUM_NETIFS}); do
ip link show dev ${NETIFS[p$i]} &> /dev/null
if [[ $? -ne 0 ]]; then
echo "SKIP: could not find all required interfaces"
exit 1
fi
done
##############################################################################
# Helpers
# Exit status to return at the end. Set in case one of the tests fails.
EXIT_STATUS=0
# Per-test return value. Clear at the beginning of each test.
RET=0
check_err()
{
local err=$1
local msg=$2
if [[ $RET -eq 0 && $err -ne 0 ]]; then
RET=$err
retmsg=$msg
fi
}
check_fail()
{
local err=$1
local msg=$2
if [[ $RET -eq 0 && $err -eq 0 ]]; then
RET=1
retmsg=$msg
fi
}
check_err_fail()
{
local should_fail=$1; shift
local err=$1; shift
local what=$1; shift
if ((should_fail)); then
check_fail $err "$what succeeded, but should have failed"
else
check_err $err "$what failed"
fi
}
log_test()
{
local test_name=$1
local opt_str=$2
if [[ $# -eq 2 ]]; then
opt_str="($opt_str)"
fi
if [[ $RET -ne 0 ]]; then
EXIT_STATUS=1
printf "TEST: %-60s [FAIL]\n" "$test_name $opt_str"
if [[ ! -z "$retmsg" ]]; then
printf "\t%s\n" "$retmsg"
fi
if [ "${PAUSE_ON_FAIL}" = "yes" ]; then
echo "Hit enter to continue, 'q' to quit"
read a
[ "$a" = "q" ] && exit 1
fi
return 1
fi
printf "TEST: %-60s [PASS]\n" "$test_name $opt_str"
return 0
}
log_info()
{
local msg=$1
echo "INFO: $msg"
}
setup_wait_dev()
{
local dev=$1; shift
while true; do
ip link show dev $dev up \
| grep 'state UP' &> /dev/null
if [[ $? -ne 0 ]]; then
sleep 1
else
break
fi
done
}
setup_wait()
{
local num_netifs=${1:-$NUM_NETIFS}
for ((i = 1; i <= num_netifs; ++i)); do
setup_wait_dev ${NETIFS[p$i]}
done
# Make sure links are ready.
sleep $WAIT_TIME
}
lldpad_app_wait_set()
{
local dev=$1; shift
while lldptool -t -i $dev -V APP -c app | grep -Eq "pending|unknown"; do
echo "$dev: waiting for lldpad to push pending APP updates"
sleep 5
done
}
lldpad_app_wait_del()
{
# Give lldpad a chance to push down the changes. If the device is downed
# too soon, the updates will be left pending. However, they will have
# been struck off the lldpad's DB already, so we won't be able to tell
# they are pending. Then on next test iteration this would cause
# weirdness as newly-added APP rules conflict with the old ones,
# sometimes getting stuck in an "unknown" state.
sleep 5
}
pre_cleanup()
{
if [ "${PAUSE_ON_CLEANUP}" = "yes" ]; then
echo "Pausing before cleanup, hit any key to continue"
read
fi
}
vrf_prepare()
{
ip -4 rule add pref 32765 table local
ip -4 rule del pref 0
ip -6 rule add pref 32765 table local
ip -6 rule del pref 0
}
vrf_cleanup()
{
ip -6 rule add pref 0 table local
ip -6 rule del pref 32765
ip -4 rule add pref 0 table local
ip -4 rule del pref 32765
}
__last_tb_id=0
declare -A __TB_IDS
__vrf_td_id_assign()
{
local vrf_name=$1
__last_tb_id=$((__last_tb_id + 1))
__TB_IDS[$vrf_name]=$__last_tb_id
return $__last_tb_id
}
__vrf_td_id_lookup()
{
local vrf_name=$1
return ${__TB_IDS[$vrf_name]}
}
vrf_create()
{
local vrf_name=$1
local tb_id
__vrf_td_id_assign $vrf_name
tb_id=$?
ip link add dev $vrf_name type vrf table $tb_id
ip -4 route add table $tb_id unreachable default metric 4278198272
ip -6 route add table $tb_id unreachable default metric 4278198272
}
vrf_destroy()
{
local vrf_name=$1
local tb_id
__vrf_td_id_lookup $vrf_name
tb_id=$?
ip -6 route del table $tb_id unreachable default metric 4278198272
ip -4 route del table $tb_id unreachable default metric 4278198272
ip link del dev $vrf_name
}
__addr_add_del()
{
local if_name=$1
local add_del=$2
local array
shift
shift
array=("${@}")
for addrstr in "${array[@]}"; do
ip address $add_del $addrstr dev $if_name
done
}
__simple_if_init()
{
local if_name=$1; shift
local vrf_name=$1; shift
local addrs=("${@}")
ip link set dev $if_name master $vrf_name
ip link set dev $if_name up
__addr_add_del $if_name add "${addrs[@]}"
}
__simple_if_fini()
{
local if_name=$1; shift
local addrs=("${@}")
__addr_add_del $if_name del "${addrs[@]}"
ip link set dev $if_name down
ip link set dev $if_name nomaster
}
simple_if_init()
{
local if_name=$1
local vrf_name
local array
shift
vrf_name=v$if_name
array=("${@}")
vrf_create $vrf_name
ip link set dev $vrf_name up
__simple_if_init $if_name $vrf_name "${array[@]}"
}
simple_if_fini()
{
local if_name=$1
local vrf_name
local array
shift
vrf_name=v$if_name
array=("${@}")
__simple_if_fini $if_name "${array[@]}"
vrf_destroy $vrf_name
}
tunnel_create()
{
local name=$1; shift
local type=$1; shift
local local=$1; shift
local remote=$1; shift
ip link add name $name type $type \
local $local remote $remote "$@"
ip link set dev $name up
}
tunnel_destroy()
{
local name=$1; shift
ip link del dev $name
}
vlan_create()
{
local if_name=$1; shift
local vid=$1; shift
local vrf=$1; shift
local ips=("${@}")
local name=$if_name.$vid
ip link add name $name link $if_name type vlan id $vid
if [ "$vrf" != "" ]; then
ip link set dev $name master $vrf
fi
ip link set dev $name up
__addr_add_del $name add "${ips[@]}"
}
vlan_destroy()
{
local if_name=$1; shift
local vid=$1; shift
local name=$if_name.$vid
ip link del dev $name
}
team_create()
{
local if_name=$1; shift
local mode=$1; shift
require_command $TEAMD
$TEAMD -t $if_name -d -c '{"runner": {"name": "'$mode'"}}'
for slave in "$@"; do
ip link set dev $slave down
ip link set dev $slave master $if_name
ip link set dev $slave up
done
ip link set dev $if_name up
}
team_destroy()
{
local if_name=$1; shift
$TEAMD -t $if_name -k
}
master_name_get()
{
local if_name=$1
ip -j link show dev $if_name | jq -r '.[]["master"]'
}
link_stats_tx_packets_get()
{
local if_name=$1
ip -j -s link show dev $if_name | jq '.[]["stats64"]["tx"]["packets"]'
}
tc_rule_stats_get()
{
local dev=$1; shift
local pref=$1; shift
local dir=$1; shift
tc -j -s filter show dev $dev ${dir:-ingress} pref $pref \
| jq '.[1].options.actions[].stats.packets'
}
mac_get()
{
local if_name=$1
ip -j link show dev $if_name | jq -r '.[]["address"]'
}
bridge_ageing_time_get()
{
local bridge=$1
local ageing_time
# Need to divide by 100 to convert to seconds.
ageing_time=$(ip -j -d link show dev $bridge \
| jq '.[]["linkinfo"]["info_data"]["ageing_time"]')
echo $((ageing_time / 100))
}
declare -A SYSCTL_ORIG
sysctl_set()
{
local key=$1; shift
local value=$1; shift
SYSCTL_ORIG[$key]=$(sysctl -n $key)
sysctl -qw $key=$value
}
sysctl_restore()
{
local key=$1; shift
sysctl -qw $key=${SYSCTL_ORIG["$key"]}
}
forwarding_enable()
{
sysctl_set net.ipv4.conf.all.forwarding 1
sysctl_set net.ipv6.conf.all.forwarding 1
}
forwarding_restore()
{
sysctl_restore net.ipv6.conf.all.forwarding
sysctl_restore net.ipv4.conf.all.forwarding
}
tc_offload_check()
{
local num_netifs=${1:-$NUM_NETIFS}
for ((i = 1; i <= num_netifs; ++i)); do
ethtool -k ${NETIFS[p$i]} \
| grep "hw-tc-offload: on" &> /dev/null
if [[ $? -ne 0 ]]; then
return 1
fi
done
return 0
}
trap_install()
{
local dev=$1; shift
local direction=$1; shift
# Some devices may not support or need in-hardware trapping of traffic
# (e.g. the veth pairs that this library creates for non-existent
# loopbacks). Use continue instead, so that there is a filter in there
# (some tests check counters), and so that other filters are still
# processed.
tc filter add dev $dev $direction pref 1 \
flower skip_sw action trap 2>/dev/null \
|| tc filter add dev $dev $direction pref 1 \
flower action continue
}
trap_uninstall()
{
local dev=$1; shift
local direction=$1; shift
tc filter del dev $dev $direction pref 1 flower
}
slow_path_trap_install()
{
# For slow-path testing, we need to install a trap to get to
# slow path the packets that would otherwise be switched in HW.
if [ "${tcflags/skip_hw}" != "$tcflags" ]; then
trap_install "$@"
fi
}
slow_path_trap_uninstall()
{
if [ "${tcflags/skip_hw}" != "$tcflags" ]; then
trap_uninstall "$@"
fi
}
__icmp_capture_add_del()
{
local add_del=$1; shift
local pref=$1; shift
local vsuf=$1; shift
local tundev=$1; shift
local filter=$1; shift
tc filter $add_del dev "$tundev" ingress \
proto ip$vsuf pref $pref \
flower ip_proto icmp$vsuf $filter \
action pass
}
icmp_capture_install()
{
__icmp_capture_add_del add 100 "" "$@"
}
icmp_capture_uninstall()
{
__icmp_capture_add_del del 100 "" "$@"
}
icmp6_capture_install()
{
__icmp_capture_add_del add 100 v6 "$@"
}
icmp6_capture_uninstall()
{
__icmp_capture_add_del del 100 v6 "$@"
}
__vlan_capture_add_del()
{
local add_del=$1; shift
local pref=$1; shift
local dev=$1; shift
local filter=$1; shift
tc filter $add_del dev "$dev" ingress \
proto 802.1q pref $pref \
flower $filter \
action pass
}
vlan_capture_install()
{
__vlan_capture_add_del add 100 "$@"
}
vlan_capture_uninstall()
{
__vlan_capture_add_del del 100 "$@"
}
__dscp_capture_add_del()
{
local add_del=$1; shift
local dev=$1; shift
local base=$1; shift
local dscp;
for prio in {0..7}; do
dscp=$((base + prio))
__icmp_capture_add_del $add_del $((dscp + 100)) "" $dev \
"skip_hw ip_tos $((dscp << 2))"
done
}
dscp_capture_install()
{
local dev=$1; shift
local base=$1; shift
__dscp_capture_add_del add $dev $base
}
dscp_capture_uninstall()
{
local dev=$1; shift
local base=$1; shift
__dscp_capture_add_del del $dev $base
}
dscp_fetch_stats()
{
local dev=$1; shift
local base=$1; shift
for prio in {0..7}; do
local dscp=$((base + prio))
local t=$(tc_rule_stats_get $dev $((dscp + 100)))
echo "[$dscp]=$t "
done
}
matchall_sink_create()
{
local dev=$1; shift
tc qdisc add dev $dev clsact
tc filter add dev $dev ingress \
pref 10000 \
matchall \
action drop
}
tests_run()
{
local current_test
for current_test in ${TESTS:-$ALL_TESTS}; do
$current_test
done
}
multipath_eval()
{
local desc="$1"
local weight_rp12=$2
local weight_rp13=$3
local packets_rp12=$4
local packets_rp13=$5
local weights_ratio packets_ratio diff
RET=0
if [[ "$weight_rp12" -gt "$weight_rp13" ]]; then
weights_ratio=$(echo "scale=2; $weight_rp12 / $weight_rp13" \
| bc -l)
else
weights_ratio=$(echo "scale=2; $weight_rp13 / $weight_rp12" \
| bc -l)
fi
if [[ "$packets_rp12" -eq "0" || "$packets_rp13" -eq "0" ]]; then
check_err 1 "Packet difference is 0"
log_test "Multipath"
log_info "Expected ratio $weights_ratio"
return
fi
if [[ "$weight_rp12" -gt "$weight_rp13" ]]; then
packets_ratio=$(echo "scale=2; $packets_rp12 / $packets_rp13" \
| bc -l)
else
packets_ratio=$(echo "scale=2; $packets_rp13 / $packets_rp12" \
| bc -l)
fi
diff=$(echo $weights_ratio - $packets_ratio | bc -l)
diff=${diff#-}
test "$(echo "$diff / $weights_ratio > 0.15" | bc -l)" -eq 0
check_err $? "Too large discrepancy between expected and measured ratios"
log_test "$desc"
log_info "Expected ratio $weights_ratio Measured ratio $packets_ratio"
}
##############################################################################
# Tests
ping_do()
{
local if_name=$1
local dip=$2
local vrf_name
vrf_name=$(master_name_get $if_name)
ip vrf exec $vrf_name $PING $dip -c 10 -i 0.1 -w 2 &> /dev/null
}
ping_test()
{
RET=0
ping_do $1 $2
check_err $?
log_test "ping"
}
ping6_do()
{
local if_name=$1
local dip=$2
local vrf_name
vrf_name=$(master_name_get $if_name)
ip vrf exec $vrf_name $PING6 $dip -c 10 -i 0.1 -w 2 &> /dev/null
}
ping6_test()
{
RET=0
ping6_do $1 $2
check_err $?
log_test "ping6"
}
learning_test()
{
local bridge=$1
local br_port1=$2 # Connected to `host1_if`.
local host1_if=$3
local host2_if=$4
local mac=de:ad:be:ef:13:37
local ageing_time
RET=0
bridge -j fdb show br $bridge brport $br_port1 \
| jq -e ".[] | select(.mac == \"$mac\")" &> /dev/null
check_fail $? "Found FDB record when should not"
# Disable unknown unicast flooding on `br_port1` to make sure
# packets are only forwarded through the port after a matching
# FDB entry was installed.
bridge link set dev $br_port1 flood off
tc qdisc add dev $host1_if ingress
tc filter add dev $host1_if ingress protocol ip pref 1 handle 101 \
flower dst_mac $mac action drop
$MZ $host2_if -c 1 -p 64 -b $mac -t ip -q
sleep 1
tc -j -s filter show dev $host1_if ingress \
| jq -e ".[] | select(.options.handle == 101) \
| select(.options.actions[0].stats.packets == 1)" &> /dev/null
check_fail $? "Packet reached second host when should not"
$MZ $host1_if -c 1 -p 64 -a $mac -t ip -q
sleep 1
bridge -j fdb show br $bridge brport $br_port1 \
| jq -e ".[] | select(.mac == \"$mac\")" &> /dev/null
check_err $? "Did not find FDB record when should"
$MZ $host2_if -c 1 -p 64 -b $mac -t ip -q
sleep 1
tc -j -s filter show dev $host1_if ingress \
| jq -e ".[] | select(.options.handle == 101) \
| select(.options.actions[0].stats.packets == 1)" &> /dev/null
check_err $? "Packet did not reach second host when should"
# Wait for 10 seconds after the ageing time to make sure FDB
# record was aged-out.
ageing_time=$(bridge_ageing_time_get $bridge)
sleep $((ageing_time + 10))
bridge -j fdb show br $bridge brport $br_port1 \
| jq -e ".[] | select(.mac == \"$mac\")" &> /dev/null
check_fail $? "Found FDB record when should not"
bridge link set dev $br_port1 learning off
$MZ $host1_if -c 1 -p 64 -a $mac -t ip -q
sleep 1
bridge -j fdb show br $bridge brport $br_port1 \
| jq -e ".[] | select(.mac == \"$mac\")" &> /dev/null
check_fail $? "Found FDB record when should not"
bridge link set dev $br_port1 learning on
tc filter del dev $host1_if ingress protocol ip pref 1 handle 101 flower
tc qdisc del dev $host1_if ingress
bridge link set dev $br_port1 flood on
log_test "FDB learning"
}
flood_test_do()
{
local should_flood=$1
local mac=$2
local ip=$3
local host1_if=$4
local host2_if=$5
local err=0
# Add an ACL on `host2_if` which will tell us whether the packet
# was flooded to it or not.
tc qdisc add dev $host2_if ingress
tc filter add dev $host2_if ingress protocol ip pref 1 handle 101 \
flower dst_mac $mac action drop
$MZ $host1_if -c 1 -p 64 -b $mac -B $ip -t ip -q
sleep 1
tc -j -s filter show dev $host2_if ingress \
| jq -e ".[] | select(.options.handle == 101) \
| select(.options.actions[0].stats.packets == 1)" &> /dev/null
if [[ $? -ne 0 && $should_flood == "true" || \
$? -eq 0 && $should_flood == "false" ]]; then
err=1
fi
tc filter del dev $host2_if ingress protocol ip pref 1 handle 101 flower
tc qdisc del dev $host2_if ingress
return $err
}
flood_unicast_test()
{
local br_port=$1
local host1_if=$2
local host2_if=$3
local mac=de:ad:be:ef:13:37
local ip=192.0.2.100
RET=0
bridge link set dev $br_port flood off
flood_test_do false $mac $ip $host1_if $host2_if
check_err $? "Packet flooded when should not"
bridge link set dev $br_port flood on
flood_test_do true $mac $ip $host1_if $host2_if
check_err $? "Packet was not flooded when should"
log_test "Unknown unicast flood"
}
flood_multicast_test()
{
local br_port=$1
local host1_if=$2
local host2_if=$3
local mac=01:00:5e:00:00:01
local ip=239.0.0.1
RET=0
bridge link set dev $br_port mcast_flood off
flood_test_do false $mac $ip $host1_if $host2_if
check_err $? "Packet flooded when should not"
bridge link set dev $br_port mcast_flood on
flood_test_do true $mac $ip $host1_if $host2_if
check_err $? "Packet was not flooded when should"
log_test "Unregistered multicast flood"
}
flood_test()
{
# `br_port` is connected to `host2_if`
local br_port=$1
local host1_if=$2
local host2_if=$3
flood_unicast_test $br_port $host1_if $host2_if
flood_multicast_test $br_port $host1_if $host2_if
}
+160
View File
@@ -0,0 +1,160 @@
#!/bin/bash
# SPDX-License-Identifier: GPL-2.0
# This test uses standard topology for testing gretap. See
# mirror_gre_topo_lib.sh for more details.
#
# Test for "tc action mirred egress mirror" when the device to mirror to is a
# gretap or ip6gretap netdevice. Expect that the packets come out encapsulated,
# and another gretap / ip6gretap netdevice is then capable of decapsulating the
# traffic. Test that the payload is what is expected (ICMP ping request or
# reply, depending on test).
ALL_TESTS="
test_gretap
test_ip6gretap
test_gretap_mac
test_ip6gretap_mac
test_two_spans
"
NUM_NETIFS=6
source lib.sh
source mirror_lib.sh
source mirror_gre_lib.sh
source mirror_gre_topo_lib.sh
setup_prepare()
{
h1=${NETIFS[p1]}
swp1=${NETIFS[p2]}
swp2=${NETIFS[p3]}
h2=${NETIFS[p4]}
swp3=${NETIFS[p5]}
h3=${NETIFS[p6]}
vrf_prepare
mirror_gre_topo_create
ip address add dev $swp3 192.0.2.129/28
ip address add dev $h3 192.0.2.130/28
ip address add dev $swp3 2001:db8:2::1/64
ip address add dev $h3 2001:db8:2::2/64
}
cleanup()
{
pre_cleanup
ip address del dev $h3 2001:db8:2::2/64
ip address del dev $swp3 2001:db8:2::1/64
ip address del dev $h3 192.0.2.130/28
ip address del dev $swp3 192.0.2.129/28
mirror_gre_topo_destroy
vrf_cleanup
}
test_span_gre_mac()
{
local tundev=$1; shift
local direction=$1; shift
local what=$1; shift
case "$direction" in
ingress) local src_mac=$(mac_get $h1); local dst_mac=$(mac_get $h2)
;;
egress) local src_mac=$(mac_get $h2); local dst_mac=$(mac_get $h1)
;;
esac
RET=0
mirror_install $swp1 $direction $tundev "matchall $tcflags"
icmp_capture_install h3-${tundev} "src_mac $src_mac dst_mac $dst_mac"
mirror_test v$h1 192.0.2.1 192.0.2.2 h3-${tundev} 100 10
icmp_capture_uninstall h3-${tundev}
mirror_uninstall $swp1 $direction
log_test "$direction $what: envelope MAC ($tcflags)"
}
test_two_spans()
{
RET=0
mirror_install $swp1 ingress gt4 "matchall $tcflags"
mirror_install $swp1 egress gt6 "matchall $tcflags"
quick_test_span_gre_dir gt4 ingress
quick_test_span_gre_dir gt6 egress
mirror_uninstall $swp1 ingress
fail_test_span_gre_dir gt4 ingress
quick_test_span_gre_dir gt6 egress
mirror_install $swp1 ingress gt4 "matchall $tcflags"
mirror_uninstall $swp1 egress
quick_test_span_gre_dir gt4 ingress
fail_test_span_gre_dir gt6 egress
mirror_uninstall $swp1 ingress
log_test "two simultaneously configured mirrors ($tcflags)"
}
test_gretap()
{
full_test_span_gre_dir gt4 ingress 8 0 "mirror to gretap"
full_test_span_gre_dir gt4 egress 0 8 "mirror to gretap"
}
test_ip6gretap()
{
full_test_span_gre_dir gt6 ingress 8 0 "mirror to ip6gretap"
full_test_span_gre_dir gt6 egress 0 8 "mirror to ip6gretap"
}
test_gretap_mac()
{
test_span_gre_mac gt4 ingress "mirror to gretap"
test_span_gre_mac gt4 egress "mirror to gretap"
}
test_ip6gretap_mac()
{
test_span_gre_mac gt6 ingress "mirror to ip6gretap"
test_span_gre_mac gt6 egress "mirror to ip6gretap"
}
test_all()
{
slow_path_trap_install $swp1 ingress
slow_path_trap_install $swp1 egress
tests_run
slow_path_trap_uninstall $swp1 egress
slow_path_trap_uninstall $swp1 ingress
}
trap cleanup EXIT
setup_prepare
setup_wait
tcflags="skip_hw"
test_all
if ! tc_offload_check; then
echo "WARN: Could not test offloaded functionality"
else
tcflags="skip_sw"
test_all
fi
exit $EXIT_STATUS
+226
View File
@@ -0,0 +1,226 @@
#!/bin/bash
# SPDX-License-Identifier: GPL-2.0
# +---------------------+ +---------------------+
# | H1 | | H2 |
# | + $h1 | | $h2 + |
# | | 192.0.2.1/28 | | 192.0.2.2/28 | |
# +-----|---------------+ +---------------|-----+
# | |
# +-----|-------------------------------------------------------------|-----+
# | SW o--> mirror | |
# | +---|-------------------------------------------------------------|---+ |
# | | + $swp1 BR $swp2 + | |
# | +---------------------------------------------------------------------+ |
# | |
# | +---------------------------------------------------------------------+ |
# | | OL + gt6 (ip6gretap) + gt4 (gretap) | |
# | | : loc=2001:db8:2::1 : loc=192.0.2.129 | |
# | | : rem=2001:db8:2::2 : rem=192.0.2.130 | |
# | | : ttl=100 : ttl=100 | |
# | | : tos=inherit : tos=inherit | |
# | +-------------------------:--|-------------------:--|-----------------+ |
# | : | : | |
# | +-------------------------:--|-------------------:--|-----------------+ |
# | | UL : |,---------------------' | |
# | | + $swp3 : || : | |
# | | | 192.0.2.129/28 : vv : | |
# | | | 2001:db8:2::1/64 : + ul (dummy) : | |
# | +---|---------------------:----------------------:--------------------+ |
# +-----|---------------------:----------------------:----------------------+
# | : :
# +-----|---------------------:----------------------:----------------------+
# | H3 + $h3 + h3-gt6 (ip6gretap) + h3-gt4 (gretap) |
# | 192.0.2.130/28 loc=2001:db8:2::2 loc=192.0.2.130 |
# | 2001:db8:2::2/64 rem=2001:db8:2::1 rem=192.0.2.129 |
# | ttl=100 ttl=100 |
# | tos=inherit tos=inherit |
# | |
# +-------------------------------------------------------------------------+
#
# This tests mirroring to gretap and ip6gretap configured in an overlay /
# underlay manner, i.e. with a bound dummy device that marks underlay VRF where
# the encapsulated packed should be routed.
ALL_TESTS="
test_gretap
test_ip6gretap
"
NUM_NETIFS=6
source lib.sh
source mirror_lib.sh
source mirror_gre_lib.sh
h1_create()
{
simple_if_init $h1 192.0.2.1/28
}
h1_destroy()
{
simple_if_fini $h1 192.0.2.1/28
}
h2_create()
{
simple_if_init $h2 192.0.2.2/28
}
h2_destroy()
{
simple_if_fini $h2 192.0.2.2/28
}
h3_create()
{
simple_if_init $h3 192.0.2.130/28 2001:db8:2::2/64
tunnel_create h3-gt4 gretap 192.0.2.130 192.0.2.129
ip link set h3-gt4 vrf v$h3
matchall_sink_create h3-gt4
tunnel_create h3-gt6 ip6gretap 2001:db8:2::2 2001:db8:2::1
ip link set h3-gt6 vrf v$h3
matchall_sink_create h3-gt6
}
h3_destroy()
{
tunnel_destroy h3-gt6
tunnel_destroy h3-gt4
simple_if_fini $h3 192.0.2.130/28 2001:db8:2::2/64
}
switch_create()
{
# Bridge between H1 and H2.
ip link add name br1 type bridge vlan_filtering 1
ip link set dev br1 up
ip link set dev $swp1 master br1
ip link set dev $swp1 up
ip link set dev $swp2 master br1
ip link set dev $swp2 up
tc qdisc add dev $swp1 clsact
# Underlay.
simple_if_init $swp3 192.0.2.129/28 2001:db8:2::1/64
ip link add name ul type dummy
ip link set dev ul master v$swp3
ip link set dev ul up
# Overlay.
vrf_create vrf-ol
ip link set dev vrf-ol up
tunnel_create gt4 gretap 192.0.2.129 192.0.2.130 \
ttl 100 tos inherit dev ul
ip link set dev gt4 master vrf-ol
ip link set dev gt4 up
tunnel_create gt6 ip6gretap 2001:db8:2::1 2001:db8:2::2 \
ttl 100 tos inherit dev ul allow-localremote
ip link set dev gt6 master vrf-ol
ip link set dev gt6 up
}
switch_destroy()
{
vrf_destroy vrf-ol
tunnel_destroy gt6
tunnel_destroy gt4
simple_if_fini $swp3 192.0.2.129/28 2001:db8:2::1/64
ip link del dev ul
tc qdisc del dev $swp1 clsact
ip link set dev $swp1 down
ip link set dev $swp2 down
ip link del dev br1
}
setup_prepare()
{
h1=${NETIFS[p1]}
swp1=${NETIFS[p2]}
swp2=${NETIFS[p3]}
h2=${NETIFS[p4]}
swp3=${NETIFS[p5]}
h3=${NETIFS[p6]}
vrf_prepare
h1_create
h2_create
h3_create
switch_create
}
cleanup()
{
pre_cleanup
switch_destroy
h3_destroy
h2_destroy
h1_destroy
vrf_cleanup
}
test_gretap()
{
full_test_span_gre_dir gt4 ingress 8 0 "mirror to gretap w/ UL"
full_test_span_gre_dir gt4 egress 0 8 "mirror to gretap w/ UL"
}
test_ip6gretap()
{
full_test_span_gre_dir gt6 ingress 8 0 "mirror to ip6gretap w/ UL"
full_test_span_gre_dir gt6 egress 0 8 "mirror to ip6gretap w/ UL"
}
test_all()
{
RET=0
slow_path_trap_install $swp1 ingress
slow_path_trap_install $swp1 egress
tests_run
slow_path_trap_uninstall $swp1 egress
slow_path_trap_uninstall $swp1 ingress
}
trap cleanup EXIT
setup_prepare
setup_wait
tcflags="skip_hw"
test_all
if ! tc_offload_check; then
echo "WARN: Could not test offloaded functionality"
else
tcflags="skip_sw"
test_all
fi
exit $EXIT_STATUS
@@ -0,0 +1,132 @@
#!/bin/bash
# SPDX-License-Identifier: GPL-2.0
# Test for "tc action mirred egress mirror" when the underlay route points at a
# bridge device without vlan filtering (802.1d).
#
# This test uses standard topology for testing mirror-to-gretap. See
# mirror_gre_topo_lib.sh for more details. The full topology is as follows:
#
# +---------------------+ +---------------------+
# | H1 | | H2 |
# | + $h1 | | $h2 + |
# | | 192.0.2.1/28 | | 192.0.2.2/28 | |
# +-----|---------------+ +---------------|-----+
# | |
# +-----|-------------------------------------------------------------|-----+
# | SW o---> mirror | |
# | +---|-------------------------------------------------------------|---+ |
# | | + $swp1 + br1 (802.1q bridge) $swp2 + | |
# | +---------------------------------------------------------------------+ |
# | |
# | +---------------------------------------------------------------------+ |
# | | + br2 (802.1d bridge) | |
# | | 192.0.2.129/28 | |
# | | + $swp3 2001:db8:2::1/64 | |
# | +---|-----------------------------------------------------------------+ |
# | | ^ ^ |
# | | + gt6 (ip6gretap) | + gt4 (gretap) | |
# | | : loc=2001:db8:2::1 | : loc=192.0.2.129 | |
# | | : rem=2001:db8:2::2 -+ : rem=192.0.2.130 -+ |
# | | : ttl=100 : ttl=100 |
# | | : tos=inherit : tos=inherit |
# +-----|---------------------:----------------------:----------------------+
# | : :
# +-----|---------------------:----------------------:----------------------+
# | H3 + $h3 + h3-gt6(ip6gretap) + h3-gt4 (gretap) |
# | 192.0.2.130/28 loc=2001:db8:2::2 loc=192.0.2.130 |
# | 2001:db8:2::2/64 rem=2001:db8:2::1 rem=192.0.2.129 |
# | ttl=100 ttl=100 |
# | tos=inherit tos=inherit |
# +-------------------------------------------------------------------------+
ALL_TESTS="
test_gretap
test_ip6gretap
"
NUM_NETIFS=6
source lib.sh
source mirror_lib.sh
source mirror_gre_lib.sh
source mirror_gre_topo_lib.sh
setup_prepare()
{
h1=${NETIFS[p1]}
swp1=${NETIFS[p2]}
swp2=${NETIFS[p3]}
h2=${NETIFS[p4]}
swp3=${NETIFS[p5]}
h3=${NETIFS[p6]}
vrf_prepare
mirror_gre_topo_create
ip link add name br2 type bridge vlan_filtering 0
ip link set dev br2 up
ip link set dev $swp3 master br2
ip route add 192.0.2.130/32 dev br2
ip -6 route add 2001:db8:2::2/128 dev br2
ip address add dev br2 192.0.2.129/28
ip address add dev br2 2001:db8:2::1/64
ip address add dev $h3 192.0.2.130/28
ip address add dev $h3 2001:db8:2::2/64
}
cleanup()
{
pre_cleanup
ip address del dev $h3 2001:db8:2::2/64
ip address del dev $h3 192.0.2.130/28
ip link del dev br2
mirror_gre_topo_destroy
vrf_cleanup
}
test_gretap()
{
full_test_span_gre_dir gt4 ingress 8 0 "mirror to gretap"
full_test_span_gre_dir gt4 egress 0 8 "mirror to gretap"
}
test_ip6gretap()
{
full_test_span_gre_dir gt6 ingress 8 0 "mirror to ip6gretap"
full_test_span_gre_dir gt6 egress 0 8 "mirror to ip6gretap"
}
test_all()
{
slow_path_trap_install $swp1 ingress
slow_path_trap_install $swp1 egress
tests_run
slow_path_trap_uninstall $swp1 egress
slow_path_trap_uninstall $swp1 ingress
}
trap cleanup EXIT
setup_prepare
setup_wait
tcflags="skip_hw"
test_all
if ! tc_offload_check; then
echo "WARN: Could not test offloaded functionality"
else
tcflags="skip_sw"
test_all
fi
exit $EXIT_STATUS
@@ -0,0 +1,132 @@
#!/bin/bash
# SPDX-License-Identifier: GPL-2.0
# This test uses standard topology for testing gretap. See
# mirror_gre_topo_lib.sh for more details.
#
# Test for "tc action mirred egress mirror" when the underlay route points at a
# bridge device without vlan filtering (802.1d). The device attached to that
# bridge is a VLAN.
ALL_TESTS="
test_gretap
test_ip6gretap
test_gretap_stp
test_ip6gretap_stp
"
NUM_NETIFS=6
source lib.sh
source mirror_lib.sh
source mirror_gre_lib.sh
source mirror_gre_topo_lib.sh
setup_prepare()
{
h1=${NETIFS[p1]}
swp1=${NETIFS[p2]}
swp2=${NETIFS[p3]}
h2=${NETIFS[p4]}
swp3=${NETIFS[p5]}
h3=${NETIFS[p6]}
vrf_prepare
mirror_gre_topo_create
ip link add name br2 type bridge vlan_filtering 0
ip link set dev br2 up
vlan_create $swp3 555
ip link set dev $swp3.555 master br2
ip route add 192.0.2.130/32 dev br2
ip -6 route add 2001:db8:2::2/128 dev br2
ip address add dev br2 192.0.2.129/32
ip address add dev br2 2001:db8:2::1/128
vlan_create $h3 555 v$h3 192.0.2.130/28 2001:db8:2::2/64
}
cleanup()
{
pre_cleanup
vlan_destroy $h3 555
ip link del dev br2
vlan_destroy $swp3 555
mirror_gre_topo_destroy
vrf_cleanup
}
test_vlan_match()
{
local tundev=$1; shift
local vlan_match=$1; shift
local what=$1; shift
full_test_span_gre_dir_vlan $tundev ingress "$vlan_match" 8 0 "$what"
full_test_span_gre_dir_vlan $tundev egress "$vlan_match" 0 8 "$what"
}
test_gretap()
{
test_vlan_match gt4 'skip_hw vlan_id 555 vlan_ethtype ip' \
"mirror to gretap"
}
test_ip6gretap()
{
test_vlan_match gt6 'skip_hw vlan_id 555 vlan_ethtype ip' \
"mirror to ip6gretap"
}
test_gretap_stp()
{
# Sometimes after mirror installation, the neighbor's state is not valid.
# The reason is that there is no SW datapath activity related to the
# neighbor for the remote GRE address. Therefore whether the corresponding
# neighbor will be valid is a matter of luck, and the test is thus racy.
# Set the neighbor's state to permanent, so it would be always valid.
ip neigh replace 192.0.2.130 lladdr $(mac_get $h3) \
nud permanent dev br2
full_test_span_gre_stp gt4 $swp3.555 "mirror to gretap"
}
test_ip6gretap_stp()
{
ip neigh replace 2001:db8:2::2 lladdr $(mac_get $h3) \
nud permanent dev br2
full_test_span_gre_stp gt6 $swp3.555 "mirror to ip6gretap"
}
test_all()
{
slow_path_trap_install $swp1 ingress
slow_path_trap_install $swp1 egress
tests_run
slow_path_trap_uninstall $swp1 egress
slow_path_trap_uninstall $swp1 ingress
}
trap cleanup EXIT
setup_prepare
setup_wait
tcflags="skip_hw"
test_all
if ! tc_offload_check; then
echo "WARN: Could not test offloaded functionality"
else
tcflags="skip_sw"
test_all
fi
exit $EXIT_STATUS
@@ -0,0 +1,126 @@
#!/bin/bash
# SPDX-License-Identifier: GPL-2.0
# Test for "tc action mirred egress mirror" when the underlay route points at a
# bridge device with vlan filtering (802.1q).
#
# This test uses standard topology for testing mirror-to-gretap. See
# mirror_gre_topo_lib.sh for more details. The full topology is as follows:
#
# +---------------------+ +---------------------+
# | H1 | | H2 |
# | + $h1 | | $h2 + |
# | | 192.0.2.1/28 | | 192.0.2.2/28 | |
# +-----|---------------+ +---------------|-----+
# | |
# +-----|---------------------------------------------------------------|-----+
# | SW o---> mirror | |
# | +---|---------------------------------------------------------------|---+ |
# | | + $swp1 + br1 (802.1q bridge) $swp2 + | |
# | | 192.0.2.129/28 | |
# | | + $swp3 2001:db8:2::1/64 | |
# | | | vid555 vid555[pvid,untagged] | |
# | +---|-------------------------------------------------------------------+ |
# | | ^ ^ |
# | | + gt6 (ip6gretap) | + gt4 (gretap) | |
# | | : loc=2001:db8:2::1 | : loc=192.0.2.129 | |
# | | : rem=2001:db8:2::2 -+ : rem=192.0.2.130 -+ |
# | | : ttl=100 : ttl=100 |
# | | : tos=inherit : tos=inherit |
# +-----|---------------------:------------------------:----------------------+
# | : :
# +-----|---------------------:------------------------:----------------------+
# | H3 + $h3 + h3-gt6(ip6gretap) + h3-gt4 (gretap) |
# | | loc=2001:db8:2::2 loc=192.0.2.130 |
# | + $h3.555 rem=2001:db8:2::1 rem=192.0.2.129 |
# | 192.0.2.130/28 ttl=100 ttl=100 |
# | 2001:db8:2::2/64 tos=inherit tos=inherit |
# +---------------------------------------------------------------------------+
ALL_TESTS="
test_gretap
test_ip6gretap
"
NUM_NETIFS=6
source lib.sh
source mirror_lib.sh
source mirror_gre_lib.sh
source mirror_gre_topo_lib.sh
setup_prepare()
{
h1=${NETIFS[p1]}
swp1=${NETIFS[p2]}
swp2=${NETIFS[p3]}
h2=${NETIFS[p4]}
swp3=${NETIFS[p5]}
h3=${NETIFS[p6]}
vrf_prepare
mirror_gre_topo_create
ip link set dev $swp3 master br1
bridge vlan add dev br1 vid 555 pvid untagged self
ip address add dev br1 192.0.2.129/28
ip address add dev br1 2001:db8:2::1/64
ip -4 route add 192.0.2.130/32 dev br1
ip -6 route add 2001:db8:2::2/128 dev br1
vlan_create $h3 555 v$h3 192.0.2.130/28 2001:db8:2::2/64
bridge vlan add dev $swp3 vid 555
}
cleanup()
{
pre_cleanup
ip link set dev $swp3 nomaster
vlan_destroy $h3 555
mirror_gre_topo_destroy
vrf_cleanup
}
test_gretap()
{
full_test_span_gre_dir gt4 ingress 8 0 "mirror to gretap"
full_test_span_gre_dir gt4 egress 0 8 "mirror to gretap"
}
test_ip6gretap()
{
full_test_span_gre_dir gt6 ingress 8 0 "mirror to ip6gretap"
full_test_span_gre_dir gt6 egress 0 8 "mirror to ip6gretap"
}
tests()
{
slow_path_trap_install $swp1 ingress
slow_path_trap_install $swp1 egress
tests_run
slow_path_trap_uninstall $swp1 egress
slow_path_trap_uninstall $swp1 ingress
}
trap cleanup EXIT
setup_prepare
setup_wait
tcflags="skip_hw"
tests
if ! tc_offload_check; then
echo "WARN: Could not test offloaded functionality"
else
tcflags="skip_sw"
tests
fi
exit $EXIT_STATUS
@@ -0,0 +1,283 @@
#!/bin/bash
# SPDX-License-Identifier: GPL-2.0
# Test for "tc action mirred egress mirror" when the underlay route points at a
# bridge device with vlan filtering (802.1q), and the egress device is a team
# device.
#
# +----------------------+ +----------------------+
# | H1 | | H2 |
# | + $h1.333 | | $h1.555 + |
# | | 192.0.2.1/28 | | 192.0.2.18/28 | |
# +-----|----------------+ +----------------|-----+
# | $h1 |
# +--------------------------------+------------------------------+
# |
# +--------------------------------------|------------------------------------+
# | SW o---> mirror |
# | | |
# | +--------------------------------+------------------------------+ |
# | | $swp1 | |
# | + $swp1.333 $swp1.555 + |
# | 192.0.2.2/28 192.0.2.17/28 |
# | |
# | +-----------------------------------------------------------------------+ |
# | | BR1 (802.1q) | |
# | | + lag (team) 192.0.2.129/28 | |
# | | / \ 2001:db8:2::1/64 | |
# | +---/---\---------------------------------------------------------------+ |
# | / \ ^ |
# | | \ + gt4 (gretap) | |
# | | \ loc=192.0.2.129 | |
# | | \ rem=192.0.2.130 -+ |
# | | \ ttl=100 |
# | | \ tos=inherit |
# | | \ |
# | | \_________________________________ |
# | | \ |
# | + $swp3 + $swp4 |
# +---|------------------------------------------------|----------------------+
# | |
# +---|----------------------+ +---|----------------------+
# | + $h3 H3 | | + $h4 H4 |
# | 192.0.2.130/28 | | 192.0.2.130/28 |
# | 2001:db8:2::2/64 | | 2001:db8:2::2/64 |
# +--------------------------+ +--------------------------+
ALL_TESTS="
test_mirror_gretap_first
test_mirror_gretap_second
"
NUM_NETIFS=6
source lib.sh
source mirror_lib.sh
source mirror_gre_lib.sh
require_command $ARPING
vlan_host_create()
{
local if_name=$1; shift
local vid=$1; shift
local vrf_name=$1; shift
local ips=("${@}")
vrf_create $vrf_name
ip link set dev $vrf_name up
vlan_create $if_name $vid $vrf_name "${ips[@]}"
}
vlan_host_destroy()
{
local if_name=$1; shift
local vid=$1; shift
local vrf_name=$1; shift
vlan_destroy $if_name $vid
ip link set dev $vrf_name down
vrf_destroy $vrf_name
}
h1_create()
{
vlan_host_create $h1 333 vrf-h1 192.0.2.1/28
ip -4 route add 192.0.2.16/28 vrf vrf-h1 nexthop via 192.0.2.2
}
h1_destroy()
{
ip -4 route del 192.0.2.16/28 vrf vrf-h1
vlan_host_destroy $h1 333 vrf-h1
}
h2_create()
{
vlan_host_create $h1 555 vrf-h2 192.0.2.18/28
ip -4 route add 192.0.2.0/28 vrf vrf-h2 nexthop via 192.0.2.17
}
h2_destroy()
{
ip -4 route del 192.0.2.0/28 vrf vrf-h2
vlan_host_destroy $h1 555 vrf-h2
}
h3_create()
{
simple_if_init $h3 192.0.2.130/28
tc qdisc add dev $h3 clsact
}
h3_destroy()
{
tc qdisc del dev $h3 clsact
simple_if_fini $h3 192.0.2.130/28
}
h4_create()
{
simple_if_init $h4 192.0.2.130/28
tc qdisc add dev $h4 clsact
}
h4_destroy()
{
tc qdisc del dev $h4 clsact
simple_if_fini $h4 192.0.2.130/28
}
switch_create()
{
ip link set dev $swp1 up
tc qdisc add dev $swp1 clsact
vlan_create $swp1 333 "" 192.0.2.2/28
vlan_create $swp1 555 "" 192.0.2.17/28
tunnel_create gt4 gretap 192.0.2.129 192.0.2.130 \
ttl 100 tos inherit
ip link set dev $swp3 up
ip link set dev $swp4 up
ip link add name br1 type bridge vlan_filtering 1
ip link set dev br1 up
__addr_add_del br1 add 192.0.2.129/32
ip -4 route add 192.0.2.130/32 dev br1
team_create lag loadbalance $swp3 $swp4
ip link set dev lag master br1
}
switch_destroy()
{
ip link set dev lag nomaster
team_destroy lag
ip -4 route del 192.0.2.130/32 dev br1
__addr_add_del br1 del 192.0.2.129/32
ip link set dev br1 down
ip link del dev br1
ip link set dev $swp4 down
ip link set dev $swp3 down
tunnel_destroy gt4
vlan_destroy $swp1 555
vlan_destroy $swp1 333
tc qdisc del dev $swp1 clsact
ip link set dev $swp1 down
}
setup_prepare()
{
h1=${NETIFS[p1]}
swp1=${NETIFS[p2]}
swp3=${NETIFS[p3]}
h3=${NETIFS[p4]}
swp4=${NETIFS[p5]}
h4=${NETIFS[p6]}
vrf_prepare
ip link set dev $h1 up
h1_create
h2_create
h3_create
h4_create
switch_create
trap_install $h3 ingress
trap_install $h4 ingress
}
cleanup()
{
pre_cleanup
trap_uninstall $h4 ingress
trap_uninstall $h3 ingress
switch_destroy
h4_destroy
h3_destroy
h2_destroy
h1_destroy
ip link set dev $h1 down
vrf_cleanup
}
test_lag_slave()
{
local host_dev=$1; shift
local up_dev=$1; shift
local down_dev=$1; shift
local what=$1; shift
RET=0
mirror_install $swp1 ingress gt4 \
"proto 802.1q flower vlan_id 333 $tcflags"
# Test connectivity through $up_dev when $down_dev is set down.
ip link set dev $down_dev down
setup_wait_dev $up_dev
setup_wait_dev $host_dev
$ARPING -I br1 192.0.2.130 -qfc 1
sleep 2
mirror_test vrf-h1 192.0.2.1 192.0.2.18 $host_dev 1 10
# Test lack of connectivity when both slaves are down.
ip link set dev $up_dev down
sleep 2
mirror_test vrf-h1 192.0.2.1 192.0.2.18 $h3 1 0
mirror_test vrf-h1 192.0.2.1 192.0.2.18 $h4 1 0
ip link set dev $up_dev up
ip link set dev $down_dev up
mirror_uninstall $swp1 ingress
log_test "$what ($tcflags)"
}
test_mirror_gretap_first()
{
test_lag_slave $h3 $swp3 $swp4 "mirror to gretap: LAG first slave"
}
test_mirror_gretap_second()
{
test_lag_slave $h4 $swp4 $swp3 "mirror to gretap: LAG second slave"
}
test_all()
{
slow_path_trap_install $swp1 ingress
slow_path_trap_install $swp1 egress
tests_run
slow_path_trap_uninstall $swp1 egress
slow_path_trap_uninstall $swp1 ingress
}
trap cleanup EXIT
setup_prepare
setup_wait
tcflags="skip_hw"
test_all
if ! tc_offload_check; then
echo "WARN: Could not test offloaded functionality"
else
tcflags="skip_sw"
test_all
fi
exit $EXIT_STATUS
@@ -0,0 +1,271 @@
#!/bin/bash
# SPDX-License-Identifier: GPL-2.0
# This test uses standard topology for testing gretap. See
# mirror_gre_topo_lib.sh for more details.
#
# Test how mirrors to gretap and ip6gretap react to changes to relevant
# configuration.
ALL_TESTS="
test_ttl
test_tun_up
test_egress_up
test_remote_ip
test_tun_del
test_route_del
"
NUM_NETIFS=6
source lib.sh
source mirror_lib.sh
source mirror_gre_lib.sh
source mirror_gre_topo_lib.sh
setup_prepare()
{
h1=${NETIFS[p1]}
swp1=${NETIFS[p2]}
swp2=${NETIFS[p3]}
h2=${NETIFS[p4]}
swp3=${NETIFS[p5]}
h3=${NETIFS[p6]}
vrf_prepare
mirror_gre_topo_create
# This test downs $swp3, which deletes the configured IPv6 address
# unless this sysctl is set.
sysctl_set net.ipv6.conf.$swp3.keep_addr_on_down 1
ip address add dev $swp3 192.0.2.129/28
ip address add dev $h3 192.0.2.130/28
ip address add dev $swp3 2001:db8:2::1/64
ip address add dev $h3 2001:db8:2::2/64
}
cleanup()
{
pre_cleanup
ip address del dev $h3 2001:db8:2::2/64
ip address del dev $swp3 2001:db8:2::1/64
ip address del dev $h3 192.0.2.130/28
ip address del dev $swp3 192.0.2.129/28
sysctl_restore net.ipv6.conf.$swp3.keep_addr_on_down
mirror_gre_topo_destroy
vrf_cleanup
}
test_span_gre_ttl()
{
local tundev=$1; shift
local type=$1; shift
local prot=$1; shift
local what=$1; shift
RET=0
mirror_install $swp1 ingress $tundev "matchall $tcflags"
tc filter add dev $h3 ingress pref 77 prot $prot \
flower ip_ttl 50 action pass
mirror_test v$h1 192.0.2.1 192.0.2.2 $h3 77 0
ip link set dev $tundev type $type ttl 50
mirror_test v$h1 192.0.2.1 192.0.2.2 $h3 77 10
ip link set dev $tundev type $type ttl 100
tc filter del dev $h3 ingress pref 77
mirror_uninstall $swp1 ingress
log_test "$what: TTL change ($tcflags)"
}
test_span_gre_tun_up()
{
local tundev=$1; shift
local what=$1; shift
RET=0
ip link set dev $tundev down
mirror_install $swp1 ingress $tundev "matchall $tcflags"
fail_test_span_gre_dir $tundev ingress
ip link set dev $tundev up
quick_test_span_gre_dir $tundev ingress
mirror_uninstall $swp1 ingress
log_test "$what: tunnel down/up ($tcflags)"
}
test_span_gre_egress_up()
{
local tundev=$1; shift
local remote_ip=$1; shift
local what=$1; shift
RET=0
ip link set dev $swp3 down
mirror_install $swp1 ingress $tundev "matchall $tcflags"
fail_test_span_gre_dir $tundev ingress
# After setting the device up, wait for neighbor to get resolved so that
# we can expect mirroring to work.
ip link set dev $swp3 up
setup_wait_dev $swp3
ping -c 1 -I $swp3 $remote_ip &>/dev/null
quick_test_span_gre_dir $tundev ingress
mirror_uninstall $swp1 ingress
log_test "$what: egress down/up ($tcflags)"
}
test_span_gre_remote_ip()
{
local tundev=$1; shift
local type=$1; shift
local correct_ip=$1; shift
local wrong_ip=$1; shift
local what=$1; shift
RET=0
ip link set dev $tundev type $type remote $wrong_ip
mirror_install $swp1 ingress $tundev "matchall $tcflags"
fail_test_span_gre_dir $tundev ingress
ip link set dev $tundev type $type remote $correct_ip
quick_test_span_gre_dir $tundev ingress
mirror_uninstall $swp1 ingress
log_test "$what: remote address change ($tcflags)"
}
test_span_gre_tun_del()
{
local tundev=$1; shift
local type=$1; shift
local flags=$1; shift
local local_ip=$1; shift
local remote_ip=$1; shift
local what=$1; shift
RET=0
mirror_install $swp1 ingress $tundev "matchall $tcflags"
quick_test_span_gre_dir $tundev ingress
ip link del dev $tundev
fail_test_span_gre_dir $tundev ingress
tunnel_create $tundev $type $local_ip $remote_ip \
ttl 100 tos inherit $flags
# Recreating the tunnel doesn't reestablish mirroring, so reinstall it
# and verify it works for the follow-up tests.
mirror_uninstall $swp1 ingress
mirror_install $swp1 ingress $tundev "matchall $tcflags"
quick_test_span_gre_dir $tundev ingress
mirror_uninstall $swp1 ingress
log_test "$what: tunnel deleted ($tcflags)"
}
test_span_gre_route_del()
{
local tundev=$1; shift
local edev=$1; shift
local route=$1; shift
local what=$1; shift
RET=0
mirror_install $swp1 ingress $tundev "matchall $tcflags"
quick_test_span_gre_dir $tundev ingress
ip route del $route dev $edev
fail_test_span_gre_dir $tundev ingress
ip route add $route dev $edev
quick_test_span_gre_dir $tundev ingress
mirror_uninstall $swp1 ingress
log_test "$what: underlay route removal ($tcflags)"
}
test_ttl()
{
test_span_gre_ttl gt4 gretap ip "mirror to gretap"
test_span_gre_ttl gt6 ip6gretap ipv6 "mirror to ip6gretap"
}
test_tun_up()
{
test_span_gre_tun_up gt4 "mirror to gretap"
test_span_gre_tun_up gt6 "mirror to ip6gretap"
}
test_egress_up()
{
test_span_gre_egress_up gt4 192.0.2.130 "mirror to gretap"
test_span_gre_egress_up gt6 2001:db8:2::2 "mirror to ip6gretap"
}
test_remote_ip()
{
test_span_gre_remote_ip gt4 gretap 192.0.2.130 192.0.2.132 "mirror to gretap"
test_span_gre_remote_ip gt6 ip6gretap 2001:db8:2::2 2001:db8:2::4 "mirror to ip6gretap"
}
test_tun_del()
{
test_span_gre_tun_del gt4 gretap "" \
192.0.2.129 192.0.2.130 "mirror to gretap"
test_span_gre_tun_del gt6 ip6gretap allow-localremote \
2001:db8:2::1 2001:db8:2::2 "mirror to ip6gretap"
}
test_route_del()
{
test_span_gre_route_del gt4 $swp3 192.0.2.128/28 "mirror to gretap"
test_span_gre_route_del gt6 $swp3 2001:db8:2::/64 "mirror to ip6gretap"
}
test_all()
{
slow_path_trap_install $swp1 ingress
slow_path_trap_install $swp1 egress
tests_run
slow_path_trap_uninstall $swp1 egress
slow_path_trap_uninstall $swp1 ingress
}
trap cleanup EXIT
setup_prepare
setup_wait
tcflags="skip_hw"
test_all
if ! tc_offload_check; then
echo "WARN: Could not test offloaded functionality"
else
tcflags="skip_sw"
test_all
fi
exit $EXIT_STATUS
+137
View File
@@ -0,0 +1,137 @@
#!/bin/bash
# SPDX-License-Identifier: GPL-2.0
# This test uses standard topology for testing gretap. See
# mirror_gre_topo_lib.sh for more details.
#
# This tests flower-triggered mirroring to gretap and ip6gretap netdevices. The
# interfaces on H1 and H2 have two addresses each. Flower match on one of the
# addresses is configured with mirror action. It is expected that when pinging
# this address, mirroring takes place, whereas when pinging the other one,
# there's no mirroring.
ALL_TESTS="
test_gretap
test_ip6gretap
"
NUM_NETIFS=6
source lib.sh
source mirror_lib.sh
source mirror_gre_lib.sh
source mirror_gre_topo_lib.sh
setup_prepare()
{
h1=${NETIFS[p1]}
swp1=${NETIFS[p2]}
swp2=${NETIFS[p3]}
h2=${NETIFS[p4]}
swp3=${NETIFS[p5]}
h3=${NETIFS[p6]}
vrf_prepare
mirror_gre_topo_create
ip address add dev $swp3 192.0.2.129/28
ip address add dev $h3 192.0.2.130/28
ip address add dev $swp3 2001:db8:2::1/64
ip address add dev $h3 2001:db8:2::2/64
ip address add dev $h1 192.0.2.3/28
ip address add dev $h2 192.0.2.4/28
}
cleanup()
{
pre_cleanup
ip address del dev $h2 192.0.2.4/28
ip address del dev $h1 192.0.2.3/28
ip address del dev $h3 2001:db8:2::2/64
ip address del dev $swp3 2001:db8:2::1/64
ip address del dev $h3 192.0.2.130/28
ip address del dev $swp3 192.0.2.129/28
mirror_gre_topo_destroy
vrf_cleanup
}
test_span_gre_dir_acl()
{
test_span_gre_dir_ips "$@" 192.0.2.3 192.0.2.4
}
fail_test_span_gre_dir_acl()
{
fail_test_span_gre_dir_ips "$@" 192.0.2.3 192.0.2.4
}
full_test_span_gre_dir_acl()
{
local tundev=$1; shift
local direction=$1; shift
local forward_type=$1; shift
local backward_type=$1; shift
local match_dip=$1; shift
local what=$1; shift
mirror_install $swp1 $direction $tundev \
"protocol ip flower $tcflags dst_ip $match_dip"
fail_test_span_gre_dir $tundev $direction
test_span_gre_dir_acl "$tundev" "$direction" \
"$forward_type" "$backward_type"
mirror_uninstall $swp1 $direction
# Test lack of mirroring after ACL mirror is uninstalled.
fail_test_span_gre_dir_acl "$tundev" "$direction"
log_test "$direction $what ($tcflags)"
}
test_gretap()
{
full_test_span_gre_dir_acl gt4 ingress 8 0 192.0.2.4 "ACL mirror to gretap"
full_test_span_gre_dir_acl gt4 egress 0 8 192.0.2.3 "ACL mirror to gretap"
}
test_ip6gretap()
{
full_test_span_gre_dir_acl gt6 ingress 8 0 192.0.2.4 "ACL mirror to ip6gretap"
full_test_span_gre_dir_acl gt6 egress 0 8 192.0.2.3 "ACL mirror to ip6gretap"
}
test_all()
{
RET=0
slow_path_trap_install $swp1 ingress
slow_path_trap_install $swp1 egress
tests_run
slow_path_trap_uninstall $swp1 egress
slow_path_trap_uninstall $swp1 ingress
}
trap cleanup EXIT
setup_prepare
setup_wait
tcflags="skip_hw"
test_all
if ! tc_offload_check; then
echo "WARN: Could not test offloaded functionality"
else
tcflags="skip_sw"
test_all
fi
exit $EXIT_STATUS
@@ -0,0 +1,285 @@
#!/bin/bash
# SPDX-License-Identifier: GPL-2.0
# Test for "tc action mirred egress mirror" when the underlay route points at a
# team device.
#
# +----------------------+ +----------------------+
# | H1 | | H2 |
# | + $h1.333 | | $h1.555 + |
# | | 192.0.2.1/28 | | 192.0.2.18/28 | |
# +----|-----------------+ +----------------|-----+
# | $h1 |
# +---------------------------------+------------------------------+
# |
# +--------------------------------------|------------------------------------+
# | SW o---> mirror |
# | | |
# | +----------------------------------+------------------------------+ |
# | | $swp1 | |
# | + $swp1.333 $swp1.555 + |
# | 192.0.2.2/28 192.0.2.17/28 |
# | |
# | |
# | + gt4 (gretap) ,-> + lag1 (team) |
# | loc=192.0.2.129 | | 192.0.2.129/28 |
# | rem=192.0.2.130 --' | |
# | ttl=100 | |
# | tos=inherit | |
# | _____________________|______________________ |
# | / \ |
# | / \ |
# | + $swp3 + $swp4 |
# +---|------------------------------------------------|----------------------+
# | |
# +---|------------------------------------------------|----------------------+
# | + $h3 + $h4 H3 |
# | \ / |
# | \____________________________________________/ |
# | | |
# | + lag2 (team) |
# | 192.0.2.130/28 |
# | |
# +---------------------------------------------------------------------------+
ALL_TESTS="
test_mirror_gretap_first
test_mirror_gretap_second
"
NUM_NETIFS=6
source lib.sh
source mirror_lib.sh
source mirror_gre_lib.sh
require_command $ARPING
vlan_host_create()
{
local if_name=$1; shift
local vid=$1; shift
local vrf_name=$1; shift
local ips=("${@}")
vrf_create $vrf_name
ip link set dev $vrf_name up
vlan_create $if_name $vid $vrf_name "${ips[@]}"
}
vlan_host_destroy()
{
local if_name=$1; shift
local vid=$1; shift
local vrf_name=$1; shift
vlan_destroy $if_name $vid
ip link set dev $vrf_name down
vrf_destroy $vrf_name
}
h1_create()
{
vlan_host_create $h1 333 vrf-h1 192.0.2.1/28
ip -4 route add 192.0.2.16/28 vrf vrf-h1 nexthop via 192.0.2.2
}
h1_destroy()
{
ip -4 route del 192.0.2.16/28 vrf vrf-h1
vlan_host_destroy $h1 333 vrf-h1
}
h2_create()
{
vlan_host_create $h1 555 vrf-h2 192.0.2.18/28
ip -4 route add 192.0.2.0/28 vrf vrf-h2 nexthop via 192.0.2.17
}
h2_destroy()
{
ip -4 route del 192.0.2.0/28 vrf vrf-h2
vlan_host_destroy $h1 555 vrf-h2
}
h3_create_team()
{
team_create lag2 lacp $h3 $h4
__simple_if_init lag2 vrf-h3 192.0.2.130/32
ip -4 route add vrf vrf-h3 192.0.2.129/32 dev lag2
}
h3_destroy_team()
{
ip -4 route del vrf vrf-h3 192.0.2.129/32 dev lag2
__simple_if_fini lag2 192.0.2.130/32
team_destroy lag2
ip link set dev $h3 down
ip link set dev $h4 down
}
h3_create()
{
vrf_create vrf-h3
ip link set dev vrf-h3 up
tc qdisc add dev $h3 clsact
tc qdisc add dev $h4 clsact
h3_create_team
}
h3_destroy()
{
h3_destroy_team
tc qdisc del dev $h4 clsact
tc qdisc del dev $h3 clsact
ip link set dev vrf-h3 down
vrf_destroy vrf-h3
}
switch_create()
{
ip link set dev $swp1 up
tc qdisc add dev $swp1 clsact
vlan_create $swp1 333 "" 192.0.2.2/28
vlan_create $swp1 555 "" 192.0.2.17/28
tunnel_create gt4 gretap 192.0.2.129 192.0.2.130 \
ttl 100 tos inherit
ip link set dev $swp3 up
ip link set dev $swp4 up
team_create lag1 lacp $swp3 $swp4
__addr_add_del lag1 add 192.0.2.129/32
ip -4 route add 192.0.2.130/32 dev lag1
}
switch_destroy()
{
ip -4 route del 192.0.2.130/32 dev lag1
__addr_add_del lag1 del 192.0.2.129/32
team_destroy lag1
ip link set dev $swp4 down
ip link set dev $swp3 down
tunnel_destroy gt4
vlan_destroy $swp1 555
vlan_destroy $swp1 333
tc qdisc del dev $swp1 clsact
ip link set dev $swp1 down
}
setup_prepare()
{
h1=${NETIFS[p1]}
swp1=${NETIFS[p2]}
swp3=${NETIFS[p3]}
h3=${NETIFS[p4]}
swp4=${NETIFS[p5]}
h4=${NETIFS[p6]}
vrf_prepare
ip link set dev $h1 up
h1_create
h2_create
h3_create
switch_create
trap_install $h3 ingress
trap_install $h4 ingress
}
cleanup()
{
pre_cleanup
trap_uninstall $h4 ingress
trap_uninstall $h3 ingress
switch_destroy
h3_destroy
h2_destroy
h1_destroy
ip link set dev $h1 down
vrf_cleanup
}
test_lag_slave()
{
local up_dev=$1; shift
local down_dev=$1; shift
local what=$1; shift
RET=0
mirror_install $swp1 ingress gt4 \
"proto 802.1q flower vlan_id 333 $tcflags"
# Move $down_dev away from the team. That will prompt change in
# txability of the connected device, without changing its upness. The
# driver should notice the txability change and move the traffic to the
# other slave.
ip link set dev $down_dev nomaster
sleep 2
mirror_test vrf-h1 192.0.2.1 192.0.2.18 $up_dev 1 10
# Test lack of connectivity when neither slave is txable.
ip link set dev $up_dev nomaster
sleep 2
mirror_test vrf-h1 192.0.2.1 192.0.2.18 $h3 1 0
mirror_test vrf-h1 192.0.2.1 192.0.2.18 $h4 1 0
mirror_uninstall $swp1 ingress
# Recreate H3's team device, because mlxsw, which this test is
# predominantly mean to test, requires a bottom-up construction and
# doesn't allow enslavement to a device that already has an upper.
h3_destroy_team
h3_create_team
# Wait for ${h,swp}{3,4}.
setup_wait
log_test "$what ($tcflags)"
}
test_mirror_gretap_first()
{
test_lag_slave $h3 $h4 "mirror to gretap: LAG first slave"
}
test_mirror_gretap_second()
{
test_lag_slave $h4 $h3 "mirror to gretap: LAG second slave"
}
test_all()
{
slow_path_trap_install $swp1 ingress
slow_path_trap_install $swp1 egress
tests_run
slow_path_trap_uninstall $swp1 egress
slow_path_trap_uninstall $swp1 ingress
}
trap cleanup EXIT
setup_prepare
setup_wait
tcflags="skip_hw"
test_all
if ! tc_offload_check; then
echo "WARN: Could not test offloaded functionality"
else
tcflags="skip_sw"
test_all
fi
exit $EXIT_STATUS
@@ -0,0 +1,130 @@
# SPDX-License-Identifier: GPL-2.0
source "$relative_path/mirror_lib.sh"
quick_test_span_gre_dir_ips()
{
local tundev=$1; shift
do_test_span_dir_ips 10 h3-$tundev "$@"
}
fail_test_span_gre_dir_ips()
{
local tundev=$1; shift
do_test_span_dir_ips 0 h3-$tundev "$@"
}
test_span_gre_dir_ips()
{
local tundev=$1; shift
test_span_dir_ips h3-$tundev "$@"
}
full_test_span_gre_dir_ips()
{
local tundev=$1; shift
local direction=$1; shift
local forward_type=$1; shift
local backward_type=$1; shift
local what=$1; shift
local ip1=$1; shift
local ip2=$1; shift
RET=0
mirror_install $swp1 $direction $tundev "matchall $tcflags"
test_span_dir_ips "h3-$tundev" "$direction" "$forward_type" \
"$backward_type" "$ip1" "$ip2"
mirror_uninstall $swp1 $direction
log_test "$direction $what ($tcflags)"
}
full_test_span_gre_dir_vlan_ips()
{
local tundev=$1; shift
local direction=$1; shift
local vlan_match=$1; shift
local forward_type=$1; shift
local backward_type=$1; shift
local what=$1; shift
local ip1=$1; shift
local ip2=$1; shift
RET=0
mirror_install $swp1 $direction $tundev "matchall $tcflags"
test_span_dir_ips "h3-$tundev" "$direction" "$forward_type" \
"$backward_type" "$ip1" "$ip2"
tc filter add dev $h3 ingress pref 77 prot 802.1q \
flower $vlan_match \
action pass
mirror_test v$h1 $ip1 $ip2 $h3 77 10
tc filter del dev $h3 ingress pref 77
mirror_uninstall $swp1 $direction
log_test "$direction $what ($tcflags)"
}
quick_test_span_gre_dir()
{
quick_test_span_gre_dir_ips "$@" 192.0.2.1 192.0.2.2
}
fail_test_span_gre_dir()
{
fail_test_span_gre_dir_ips "$@" 192.0.2.1 192.0.2.2
}
test_span_gre_dir()
{
test_span_gre_dir_ips "$@" 192.0.2.1 192.0.2.2
}
full_test_span_gre_dir()
{
full_test_span_gre_dir_ips "$@" 192.0.2.1 192.0.2.2
}
full_test_span_gre_dir_vlan()
{
full_test_span_gre_dir_vlan_ips "$@" 192.0.2.1 192.0.2.2
}
full_test_span_gre_stp_ips()
{
local tundev=$1; shift
local nbpdev=$1; shift
local what=$1; shift
local ip1=$1; shift
local ip2=$1; shift
local h3mac=$(mac_get $h3)
RET=0
mirror_install $swp1 ingress $tundev "matchall $tcflags"
quick_test_span_gre_dir_ips $tundev ingress $ip1 $ip2
bridge link set dev $nbpdev state disabled
sleep 1
fail_test_span_gre_dir_ips $tundev ingress $ip1 $ip2
bridge link set dev $nbpdev state forwarding
sleep 1
quick_test_span_gre_dir_ips $tundev ingress $ip1 $ip2
mirror_uninstall $swp1 ingress
log_test "$what: STP state ($tcflags)"
}
full_test_span_gre_stp()
{
full_test_span_gre_stp_ips "$@" 192.0.2.1 192.0.2.2
}
+115
View File
@@ -0,0 +1,115 @@
#!/bin/bash
# SPDX-License-Identifier: GPL-2.0
# This test uses standard topology for testing gretap. See
# mirror_gre_topo_lib.sh for more details.
#
# Test for mirroring to gretap and ip6gretap, such that the neighbor entry for
# the tunnel remote address has invalid address at the time that the mirroring
# is set up. Later on, the neighbor is deleted and it is expected to be
# reinitialized using the usual ARP process, and the mirroring offload updated.
ALL_TESTS="
test_gretap
test_ip6gretap
"
NUM_NETIFS=6
source lib.sh
source mirror_lib.sh
source mirror_gre_lib.sh
source mirror_gre_topo_lib.sh
setup_prepare()
{
h1=${NETIFS[p1]}
swp1=${NETIFS[p2]}
swp2=${NETIFS[p3]}
h2=${NETIFS[p4]}
swp3=${NETIFS[p5]}
h3=${NETIFS[p6]}
vrf_prepare
mirror_gre_topo_create
ip address add dev $swp3 192.0.2.129/28
ip address add dev $h3 192.0.2.130/28
ip address add dev $swp3 2001:db8:2::1/64
ip address add dev $h3 2001:db8:2::2/64
}
cleanup()
{
pre_cleanup
ip address del dev $h3 2001:db8:2::2/64
ip address del dev $swp3 2001:db8:2::1/64
ip address del dev $h3 192.0.2.130/28
ip address del dev $swp3 192.0.2.129/28
mirror_gre_topo_destroy
vrf_cleanup
}
test_span_gre_neigh()
{
local addr=$1; shift
local tundev=$1; shift
local direction=$1; shift
local what=$1; shift
RET=0
ip neigh replace dev $swp3 $addr lladdr 00:11:22:33:44:55
mirror_install $swp1 $direction $tundev "matchall $tcflags"
fail_test_span_gre_dir $tundev ingress
ip neigh del dev $swp3 $addr
quick_test_span_gre_dir $tundev ingress
mirror_uninstall $swp1 $direction
log_test "$direction $what: neighbor change ($tcflags)"
}
test_gretap()
{
test_span_gre_neigh 192.0.2.130 gt4 ingress "mirror to gretap"
test_span_gre_neigh 192.0.2.130 gt4 egress "mirror to gretap"
}
test_ip6gretap()
{
test_span_gre_neigh 2001:db8:2::2 gt6 ingress "mirror to ip6gretap"
test_span_gre_neigh 2001:db8:2::2 gt6 egress "mirror to ip6gretap"
}
test_all()
{
slow_path_trap_install $swp1 ingress
slow_path_trap_install $swp1 egress
tests_run
slow_path_trap_uninstall $swp1 egress
slow_path_trap_uninstall $swp1 ingress
}
trap cleanup EXIT
setup_prepare
setup_wait
tcflags="skip_hw"
test_all
if ! tc_offload_check; then
echo "WARN: Could not test offloaded functionality"
else
tcflags="skip_sw"
test_all
fi
exit $EXIT_STATUS
+131
View File
@@ -0,0 +1,131 @@
#!/bin/bash
# SPDX-License-Identifier: GPL-2.0
# This test uses standard topology for testing gretap. See
# mirror_gre_topo_lib.sh for more details.
#
# Test that gretap and ip6gretap mirroring works when the other tunnel endpoint
# is reachable through a next-hop route (as opposed to directly-attached route).
ALL_TESTS="
test_gretap
test_ip6gretap
"
NUM_NETIFS=6
source lib.sh
source mirror_lib.sh
source mirror_gre_lib.sh
source mirror_gre_topo_lib.sh
setup_prepare()
{
h1=${NETIFS[p1]}
swp1=${NETIFS[p2]}
swp2=${NETIFS[p3]}
h2=${NETIFS[p4]}
swp3=${NETIFS[p5]}
h3=${NETIFS[p6]}
sysctl_set net.ipv4.conf.all.rp_filter 0
sysctl_set net.ipv4.conf.$h3.rp_filter 0
vrf_prepare
mirror_gre_topo_create
sysctl_set net.ipv4.conf.v$h3.rp_filter 0
ip address add dev $swp3 192.0.2.161/28
ip address add dev $h3 192.0.2.162/28
ip address add dev gt4 192.0.2.129/32
ip address add dev h3-gt4 192.0.2.130/32
# IPv6 route can't be added after address. Such routes are rejected due
# to the gateway address having been configured on the local system. It
# works the other way around though.
ip address add dev $swp3 2001:db8:4::1/64
ip -6 route add 2001:db8:2::2/128 via 2001:db8:4::2
ip address add dev $h3 2001:db8:4::2/64
ip address add dev gt6 2001:db8:2::1
ip address add dev h3-gt6 2001:db8:2::2
}
cleanup()
{
pre_cleanup
ip -6 route del 2001:db8:2::2/128 via 2001:db8:4::2
ip address del dev $h3 2001:db8:4::2/64
ip address del dev $swp3 2001:db8:4::1/64
ip address del dev $h3 192.0.2.162/28
ip address del dev $swp3 192.0.2.161/28
sysctl_restore net.ipv4.conf.v$h3.rp_filter 0
mirror_gre_topo_destroy
vrf_cleanup
sysctl_restore net.ipv4.conf.$h3.rp_filter
sysctl_restore net.ipv4.conf.all.rp_filter
}
test_gretap()
{
RET=0
mirror_install $swp1 ingress gt4 "matchall $tcflags"
# For IPv4, test that there's no mirroring without the route directing
# the traffic to tunnel remote address. Then add it and test that
# mirroring starts. For IPv6 we can't test this due to the limitation
# that routes for locally-specified IPv6 addresses can't be added.
fail_test_span_gre_dir gt4 ingress
ip route add 192.0.2.130/32 via 192.0.2.162
quick_test_span_gre_dir gt4 ingress
ip route del 192.0.2.130/32 via 192.0.2.162
mirror_uninstall $swp1 ingress
log_test "mirror to gre with next-hop remote ($tcflags)"
}
test_ip6gretap()
{
RET=0
mirror_install $swp1 ingress gt6 "matchall $tcflags"
quick_test_span_gre_dir gt6 ingress
mirror_uninstall $swp1 ingress
log_test "mirror to ip6gre with next-hop remote ($tcflags)"
}
test_all()
{
slow_path_trap_install $swp1 ingress
slow_path_trap_install $swp1 egress
tests_run
slow_path_trap_uninstall $swp1 egress
slow_path_trap_uninstall $swp1 ingress
}
trap cleanup EXIT
setup_prepare
setup_wait
tcflags="skip_hw"
test_all
if ! tc_offload_check; then
echo "WARN: Could not test offloaded functionality"
else
tcflags="skip_sw"
test_all
fi
exit $EXIT_STATUS
@@ -0,0 +1,94 @@
# SPDX-License-Identifier: GPL-2.0
# This is the standard topology for testing mirroring to gretap and ip6gretap
# netdevices. The tests that use it tweak it in one way or another--importantly,
# $swp3 and $h3 need to have addresses set up.
#
# +---------------------+ +---------------------+
# | H1 | | H2 |
# | + $h1 | | $h2 + |
# | | 192.0.2.1/28 | | 192.0.2.2/28 | |
# +-----|---------------+ +---------------|-----+
# | |
# +-----|-------------------------------------------------------------|-----+
# | SW o--> mirror | |
# | +---|-------------------------------------------------------------|---+ |
# | | + $swp1 BR $swp2 + | |
# | +---------------------------------------------------------------------+ |
# | |
# | + $swp3 + gt6 (ip6gretap) + gt4 (gretap) |
# | | : loc=2001:db8:2::1 : loc=192.0.2.129 |
# | | : rem=2001:db8:2::2 : rem=192.0.2.130 |
# | | : ttl=100 : ttl=100 |
# | | : tos=inherit : tos=inherit |
# | | : : |
# +-----|---------------------:----------------------:----------------------+
# | : :
# +-----|---------------------:----------------------:----------------------+
# | H3 + $h3 + h3-gt6 (ip6gretap) + h3-gt4 (gretap) |
# | loc=2001:db8:2::2 loc=192.0.2.130 |
# | rem=2001:db8:2::1 rem=192.0.2.129 |
# | ttl=100 ttl=100 |
# | tos=inherit tos=inherit |
# | |
# +-------------------------------------------------------------------------+
source "$relative_path/mirror_topo_lib.sh"
mirror_gre_topo_h3_create()
{
mirror_topo_h3_create
tunnel_create h3-gt4 gretap 192.0.2.130 192.0.2.129
ip link set h3-gt4 vrf v$h3
matchall_sink_create h3-gt4
tunnel_create h3-gt6 ip6gretap 2001:db8:2::2 2001:db8:2::1
ip link set h3-gt6 vrf v$h3
matchall_sink_create h3-gt6
}
mirror_gre_topo_h3_destroy()
{
tunnel_destroy h3-gt6
tunnel_destroy h3-gt4
mirror_topo_h3_destroy
}
mirror_gre_topo_switch_create()
{
mirror_topo_switch_create
tunnel_create gt4 gretap 192.0.2.129 192.0.2.130 \
ttl 100 tos inherit
tunnel_create gt6 ip6gretap 2001:db8:2::1 2001:db8:2::2 \
ttl 100 tos inherit allow-localremote
}
mirror_gre_topo_switch_destroy()
{
tunnel_destroy gt6
tunnel_destroy gt4
mirror_topo_switch_destroy
}
mirror_gre_topo_create()
{
mirror_topo_h1_create
mirror_topo_h2_create
mirror_gre_topo_h3_create
mirror_gre_topo_switch_create
}
mirror_gre_topo_destroy()
{
mirror_gre_topo_switch_destroy
mirror_gre_topo_h3_destroy
mirror_topo_h2_destroy
mirror_topo_h1_destroy
}
+92
View File
@@ -0,0 +1,92 @@
#!/bin/bash
# SPDX-License-Identifier: GPL-2.0
# This test uses standard topology for testing gretap. See
# mirror_gre_topo_lib.sh for more details.
#
# Test for "tc action mirred egress mirror" that mirrors to a gretap netdevice
# whose underlay route points at a vlan device.
ALL_TESTS="
test_gretap
"
NUM_NETIFS=6
source lib.sh
source mirror_lib.sh
source mirror_gre_lib.sh
source mirror_gre_topo_lib.sh
setup_prepare()
{
h1=${NETIFS[p1]}
swp1=${NETIFS[p2]}
swp2=${NETIFS[p3]}
h2=${NETIFS[p4]}
swp3=${NETIFS[p5]}
h3=${NETIFS[p6]}
vrf_prepare
mirror_gre_topo_create
ip link add name $swp3.555 link $swp3 type vlan id 555
ip address add dev $swp3.555 192.0.2.129/32
ip address add dev $swp3.555 2001:db8:2::1/128
ip link set dev $swp3.555 up
ip route add 192.0.2.130/32 dev $swp3.555
ip -6 route add 2001:db8:2::2/128 dev $swp3.555
ip link add name $h3.555 link $h3 type vlan id 555
ip link set dev $h3.555 master v$h3
ip address add dev $h3.555 192.0.2.130/28
ip address add dev $h3.555 2001:db8:2::2/64
ip link set dev $h3.555 up
}
cleanup()
{
pre_cleanup
ip link del dev $h3.555
ip link del dev $swp3.555
mirror_gre_topo_destroy
vrf_cleanup
}
test_gretap()
{
full_test_span_gre_dir gt4 ingress 8 0 "mirror to gretap"
full_test_span_gre_dir gt4 egress 0 8 "mirror to gretap"
}
test_all()
{
slow_path_trap_install $swp1 ingress
slow_path_trap_install $swp1 egress
tests_run
slow_path_trap_uninstall $swp1 egress
slow_path_trap_uninstall $swp1 ingress
}
trap cleanup EXIT
setup_prepare
setup_wait
tcflags="skip_hw"
test_all
if ! tc_offload_check; then
echo "WARN: Could not test offloaded functionality"
else
tcflags="skip_sw"
test_all
fi
exit $EXIT_STATUS
@@ -0,0 +1,283 @@
#!/bin/bash
# SPDX-License-Identifier: GPL-2.0
# This test uses standard topology for testing gretap. See
# mirror_gre_topo_lib.sh for more details.
#
# Test for "tc action mirred egress mirror" when the underlay route points at a
# vlan device on top of a bridge device with vlan filtering (802.1q).
ALL_TESTS="
test_gretap
test_ip6gretap
test_gretap_forbidden_cpu
test_ip6gretap_forbidden_cpu
test_gretap_forbidden_egress
test_ip6gretap_forbidden_egress
test_gretap_untagged_egress
test_ip6gretap_untagged_egress
test_gretap_fdb_roaming
test_ip6gretap_fdb_roaming
test_gretap_stp
test_ip6gretap_stp
"
NUM_NETIFS=6
source lib.sh
source mirror_lib.sh
source mirror_gre_lib.sh
source mirror_gre_topo_lib.sh
require_command $ARPING
setup_prepare()
{
h1=${NETIFS[p1]}
swp1=${NETIFS[p2]}
swp2=${NETIFS[p3]}
h2=${NETIFS[p4]}
swp3=${NETIFS[p5]}
h3=${NETIFS[p6]}
# gt4's remote address is at $h3.555, not $h3. Thus the packets arriving
# directly to $h3 for test_gretap_untagged_egress() are rejected by
# rp_filter and the test spuriously fails.
sysctl_set net.ipv4.conf.all.rp_filter 0
sysctl_set net.ipv4.conf.$h3.rp_filter 0
vrf_prepare
mirror_gre_topo_create
vlan_create br1 555 "" 192.0.2.129/32 2001:db8:2::1/128
bridge vlan add dev br1 vid 555 self
ip route rep 192.0.2.130/32 dev br1.555
ip -6 route rep 2001:db8:2::2/128 dev br1.555
vlan_create $h3 555 v$h3 192.0.2.130/28 2001:db8:2::2/64
ip link set dev $swp3 master br1
bridge vlan add dev $swp3 vid 555
bridge vlan add dev $swp2 vid 555
}
cleanup()
{
pre_cleanup
ip link set dev $swp2 nomaster
ip link set dev $swp3 nomaster
vlan_destroy $h3 555
vlan_destroy br1 555
mirror_gre_topo_destroy
vrf_cleanup
sysctl_restore net.ipv4.conf.$h3.rp_filter
sysctl_restore net.ipv4.conf.all.rp_filter
}
test_vlan_match()
{
local tundev=$1; shift
local vlan_match=$1; shift
local what=$1; shift
full_test_span_gre_dir_vlan $tundev ingress "$vlan_match" 8 0 "$what"
full_test_span_gre_dir_vlan $tundev egress "$vlan_match" 0 8 "$what"
}
test_gretap()
{
test_vlan_match gt4 'skip_hw vlan_id 555 vlan_ethtype ip' \
"mirror to gretap"
}
test_ip6gretap()
{
test_vlan_match gt6 'skip_hw vlan_id 555 vlan_ethtype ip' \
"mirror to ip6gretap"
}
test_span_gre_forbidden_cpu()
{
local tundev=$1; shift
local what=$1; shift
RET=0
# Run the pass-test first, to prime neighbor table.
mirror_install $swp1 ingress $tundev "matchall $tcflags"
quick_test_span_gre_dir $tundev ingress
# Now forbid the VLAN at the bridge and see it fail.
bridge vlan del dev br1 vid 555 self
sleep 1
fail_test_span_gre_dir $tundev ingress
bridge vlan add dev br1 vid 555 self
sleep 1
quick_test_span_gre_dir $tundev ingress
mirror_uninstall $swp1 ingress
log_test "$what: vlan forbidden at a bridge ($tcflags)"
}
test_gretap_forbidden_cpu()
{
test_span_gre_forbidden_cpu gt4 "mirror to gretap"
}
test_ip6gretap_forbidden_cpu()
{
test_span_gre_forbidden_cpu gt6 "mirror to ip6gretap"
}
test_span_gre_forbidden_egress()
{
local tundev=$1; shift
local what=$1; shift
RET=0
mirror_install $swp1 ingress $tundev "matchall $tcflags"
quick_test_span_gre_dir $tundev ingress
bridge vlan del dev $swp3 vid 555
sleep 1
fail_test_span_gre_dir $tundev ingress
bridge vlan add dev $swp3 vid 555
# Re-prime FDB
$ARPING -I br1.555 192.0.2.130 -fqc 1
sleep 1
quick_test_span_gre_dir $tundev ingress
mirror_uninstall $swp1 ingress
log_test "$what: vlan forbidden at a bridge egress ($tcflags)"
}
test_gretap_forbidden_egress()
{
test_span_gre_forbidden_egress gt4 "mirror to gretap"
}
test_ip6gretap_forbidden_egress()
{
test_span_gre_forbidden_egress gt6 "mirror to ip6gretap"
}
test_span_gre_untagged_egress()
{
local tundev=$1; shift
local what=$1; shift
RET=0
mirror_install $swp1 ingress $tundev "matchall $tcflags"
quick_test_span_gre_dir $tundev ingress
quick_test_span_vlan_dir $h3 555 ingress
bridge vlan add dev $swp3 vid 555 pvid untagged
sleep 1
quick_test_span_gre_dir $tundev ingress
fail_test_span_vlan_dir $h3 555 ingress
bridge vlan add dev $swp3 vid 555
sleep 1
quick_test_span_gre_dir $tundev ingress
quick_test_span_vlan_dir $h3 555 ingress
mirror_uninstall $swp1 ingress
log_test "$what: vlan untagged at a bridge egress ($tcflags)"
}
test_gretap_untagged_egress()
{
test_span_gre_untagged_egress gt4 "mirror to gretap"
}
test_ip6gretap_untagged_egress()
{
test_span_gre_untagged_egress gt6 "mirror to ip6gretap"
}
test_span_gre_fdb_roaming()
{
local tundev=$1; shift
local what=$1; shift
local h3mac=$(mac_get $h3)
RET=0
mirror_install $swp1 ingress $tundev "matchall $tcflags"
quick_test_span_gre_dir $tundev ingress
bridge fdb del dev $swp3 $h3mac vlan 555 master
bridge fdb add dev $swp2 $h3mac vlan 555 master
sleep 1
fail_test_span_gre_dir $tundev ingress
bridge fdb del dev $swp2 $h3mac vlan 555 master
# Re-prime FDB
$ARPING -I br1.555 192.0.2.130 -fqc 1
sleep 1
quick_test_span_gre_dir $tundev ingress
mirror_uninstall $swp1 ingress
log_test "$what: MAC roaming ($tcflags)"
}
test_gretap_fdb_roaming()
{
test_span_gre_fdb_roaming gt4 "mirror to gretap"
}
test_ip6gretap_fdb_roaming()
{
test_span_gre_fdb_roaming gt6 "mirror to ip6gretap"
}
test_gretap_stp()
{
full_test_span_gre_stp gt4 $swp3 "mirror to gretap"
}
test_ip6gretap_stp()
{
full_test_span_gre_stp gt6 $swp3 "mirror to ip6gretap"
}
test_all()
{
slow_path_trap_install $swp1 ingress
slow_path_trap_install $swp1 egress
tests_run
slow_path_trap_uninstall $swp1 egress
slow_path_trap_uninstall $swp1 ingress
}
trap cleanup EXIT
setup_prepare
setup_wait
tcflags="skip_hw"
test_all
if ! tc_offload_check; then
echo "WARN: Could not test offloaded functionality"
else
tcflags="skip_sw"
test_all
fi
exit $EXIT_STATUS
@@ -0,0 +1,132 @@
# SPDX-License-Identifier: GPL-2.0
mirror_install()
{
local from_dev=$1; shift
local direction=$1; shift
local to_dev=$1; shift
local filter=$1; shift
tc filter add dev $from_dev $direction \
pref 1000 $filter \
action mirred egress mirror dev $to_dev
}
mirror_uninstall()
{
local from_dev=$1; shift
local direction=$1; shift
tc filter del dev $swp1 $direction pref 1000
}
mirror_test()
{
local vrf_name=$1; shift
local sip=$1; shift
local dip=$1; shift
local dev=$1; shift
local pref=$1; shift
local expect=$1; shift
local t0=$(tc_rule_stats_get $dev $pref)
ip vrf exec $vrf_name \
${PING} ${sip:+-I $sip} $dip -c 10 -i 0.1 -w 2 &> /dev/null
local t1=$(tc_rule_stats_get $dev $pref)
local delta=$((t1 - t0))
# Tolerate a couple stray extra packets.
((expect <= delta && delta <= expect + 2))
check_err $? "Expected to capture $expect packets, got $delta."
}
do_test_span_dir_ips()
{
local expect=$1; shift
local dev=$1; shift
local direction=$1; shift
local ip1=$1; shift
local ip2=$1; shift
icmp_capture_install $dev
mirror_test v$h1 $ip1 $ip2 $dev 100 $expect
mirror_test v$h2 $ip2 $ip1 $dev 100 $expect
icmp_capture_uninstall $dev
}
quick_test_span_dir_ips()
{
do_test_span_dir_ips 10 "$@"
}
fail_test_span_dir_ips()
{
do_test_span_dir_ips 0 "$@"
}
test_span_dir_ips()
{
local dev=$1; shift
local direction=$1; shift
local forward_type=$1; shift
local backward_type=$1; shift
local ip1=$1; shift
local ip2=$1; shift
quick_test_span_dir_ips "$dev" "$direction" "$ip1" "$ip2"
icmp_capture_install $dev "type $forward_type"
mirror_test v$h1 $ip1 $ip2 $dev 100 10
icmp_capture_uninstall $dev
icmp_capture_install $dev "type $backward_type"
mirror_test v$h2 $ip2 $ip1 $dev 100 10
icmp_capture_uninstall $dev
}
fail_test_span_dir()
{
fail_test_span_dir_ips "$@" 192.0.2.1 192.0.2.2
}
test_span_dir()
{
test_span_dir_ips "$@" 192.0.2.1 192.0.2.2
}
do_test_span_vlan_dir_ips()
{
local expect=$1; shift
local dev=$1; shift
local vid=$1; shift
local direction=$1; shift
local ip1=$1; shift
local ip2=$1; shift
# Install the capture as skip_hw to avoid double-counting of packets.
# The traffic is meant for local box anyway, so will be trapped to
# kernel.
vlan_capture_install $dev "skip_hw vlan_id $vid vlan_ethtype ip"
mirror_test v$h1 $ip1 $ip2 $dev 100 $expect
mirror_test v$h2 $ip2 $ip1 $dev 100 $expect
vlan_capture_uninstall $dev
}
quick_test_span_vlan_dir_ips()
{
do_test_span_vlan_dir_ips 10 "$@"
}
fail_test_span_vlan_dir_ips()
{
do_test_span_vlan_dir_ips 0 "$@"
}
quick_test_span_vlan_dir()
{
quick_test_span_vlan_dir_ips "$@" 192.0.2.1 192.0.2.2
}
fail_test_span_vlan_dir()
{
fail_test_span_vlan_dir_ips "$@" 192.0.2.1 192.0.2.2
}
@@ -0,0 +1,101 @@
# SPDX-License-Identifier: GPL-2.0
# This is the standard topology for testing mirroring. The tests that use it
# tweak it in one way or another--typically add more devices to the topology.
#
# +---------------------+ +---------------------+
# | H1 | | H2 |
# | + $h1 | | $h2 + |
# | | 192.0.2.1/28 | | 192.0.2.2/28 | |
# +-----|---------------+ +---------------|-----+
# | |
# +-----|-------------------------------------------------------------|-----+
# | SW o--> mirror | |
# | +---|-------------------------------------------------------------|---+ |
# | | + $swp1 BR $swp2 + | |
# | +---------------------------------------------------------------------+ |
# | |
# | + $swp3 |
# +-----|-------------------------------------------------------------------+
# |
# +-----|-------------------------------------------------------------------+
# | H3 + $h3 |
# | |
# +-------------------------------------------------------------------------+
mirror_topo_h1_create()
{
simple_if_init $h1 192.0.2.1/28
}
mirror_topo_h1_destroy()
{
simple_if_fini $h1 192.0.2.1/28
}
mirror_topo_h2_create()
{
simple_if_init $h2 192.0.2.2/28
}
mirror_topo_h2_destroy()
{
simple_if_fini $h2 192.0.2.2/28
}
mirror_topo_h3_create()
{
simple_if_init $h3
tc qdisc add dev $h3 clsact
}
mirror_topo_h3_destroy()
{
tc qdisc del dev $h3 clsact
simple_if_fini $h3
}
mirror_topo_switch_create()
{
ip link set dev $swp3 up
ip link add name br1 type bridge vlan_filtering 1
ip link set dev br1 up
ip link set dev $swp1 master br1
ip link set dev $swp1 up
ip link set dev $swp2 master br1
ip link set dev $swp2 up
tc qdisc add dev $swp1 clsact
}
mirror_topo_switch_destroy()
{
tc qdisc del dev $swp1 clsact
ip link set dev $swp1 down
ip link set dev $swp2 down
ip link del dev br1
ip link set dev $swp3 down
}
mirror_topo_create()
{
mirror_topo_h1_create
mirror_topo_h2_create
mirror_topo_h3_create
mirror_topo_switch_create
}
mirror_topo_destroy()
{
mirror_topo_switch_destroy
mirror_topo_h3_destroy
mirror_topo_h2_destroy
mirror_topo_h1_destroy
}
+131
View File
@@ -0,0 +1,131 @@
#!/bin/bash
# SPDX-License-Identifier: GPL-2.0
# This test uses standard topology for testing mirroring. See mirror_topo_lib.sh
# for more details.
#
# Test for "tc action mirred egress mirror" that mirrors to a vlan device.
ALL_TESTS="
test_vlan
test_tagged_vlan
"
NUM_NETIFS=6
source lib.sh
source mirror_lib.sh
source mirror_topo_lib.sh
setup_prepare()
{
h1=${NETIFS[p1]}
swp1=${NETIFS[p2]}
swp2=${NETIFS[p3]}
h2=${NETIFS[p4]}
swp3=${NETIFS[p5]}
h3=${NETIFS[p6]}
vrf_prepare
mirror_topo_create
vlan_create $swp3 555
vlan_create $h3 555 v$h3
matchall_sink_create $h3.555
vlan_create $h1 111 v$h1 192.0.2.17/28
bridge vlan add dev $swp1 vid 111
vlan_create $h2 111 v$h2 192.0.2.18/28
bridge vlan add dev $swp2 vid 111
}
cleanup()
{
pre_cleanup
vlan_destroy $h2 111
vlan_destroy $h1 111
vlan_destroy $h3 555
vlan_destroy $swp3 555
mirror_topo_destroy
vrf_cleanup
}
test_vlan_dir()
{
local direction=$1; shift
local forward_type=$1; shift
local backward_type=$1; shift
RET=0
mirror_install $swp1 $direction $swp3.555 "matchall $tcflags"
test_span_dir "$h3.555" "$direction" "$forward_type" "$backward_type"
mirror_uninstall $swp1 $direction
log_test "$direction mirror to vlan ($tcflags)"
}
test_vlan()
{
test_vlan_dir ingress 8 0
test_vlan_dir egress 0 8
}
test_tagged_vlan_dir()
{
local direction=$1; shift
local forward_type=$1; shift
local backward_type=$1; shift
RET=0
mirror_install $swp1 $direction $swp3.555 "matchall $tcflags"
do_test_span_vlan_dir_ips 10 "$h3.555" 111 "$direction" \
192.0.2.17 192.0.2.18
do_test_span_vlan_dir_ips 0 "$h3.555" 555 "$direction" \
192.0.2.17 192.0.2.18
mirror_uninstall $swp1 $direction
log_test "$direction mirror tagged to vlan ($tcflags)"
}
test_tagged_vlan()
{
test_tagged_vlan_dir ingress 8 0
test_tagged_vlan_dir egress 0 8
}
test_all()
{
slow_path_trap_install $swp1 ingress
slow_path_trap_install $swp1 egress
trap_install $h3 ingress
tests_run
trap_uninstall $h3 ingress
slow_path_trap_uninstall $swp1 egress
slow_path_trap_uninstall $swp1 ingress
}
trap cleanup EXIT
setup_prepare
setup_wait
tcflags="skip_hw"
test_all
if ! tc_offload_check; then
echo "WARN: Could not test offloaded functionality"
else
tcflags="skip_sw"
test_all
fi
exit $EXIT_STATUS
+135
View File
@@ -0,0 +1,135 @@
#!/bin/bash
# SPDX-License-Identifier: GPL-2.0
ALL_TESTS="ping_ipv4 ping_ipv6"
NUM_NETIFS=4
source lib.sh
h1_create()
{
vrf_create "vrf-h1"
ip link set dev $h1 master vrf-h1
ip link set dev vrf-h1 up
ip link set dev $h1 up
ip address add 192.0.2.2/24 dev $h1
ip address add 2001:db8:1::2/64 dev $h1
ip route add 198.51.100.0/24 vrf vrf-h1 nexthop via 192.0.2.1
ip route add 2001:db8:2::/64 vrf vrf-h1 nexthop via 2001:db8:1::1
}
h1_destroy()
{
ip route del 2001:db8:2::/64 vrf vrf-h1
ip route del 198.51.100.0/24 vrf vrf-h1
ip address del 2001:db8:1::2/64 dev $h1
ip address del 192.0.2.2/24 dev $h1
ip link set dev $h1 down
vrf_destroy "vrf-h1"
}
h2_create()
{
vrf_create "vrf-h2"
ip link set dev $h2 master vrf-h2
ip link set dev vrf-h2 up
ip link set dev $h2 up
ip address add 198.51.100.2/24 dev $h2
ip address add 2001:db8:2::2/64 dev $h2
ip route add 192.0.2.0/24 vrf vrf-h2 nexthop via 198.51.100.1
ip route add 2001:db8:1::/64 vrf vrf-h2 nexthop via 2001:db8:2::1
}
h2_destroy()
{
ip route del 2001:db8:1::/64 vrf vrf-h2
ip route del 192.0.2.0/24 vrf vrf-h2
ip address del 2001:db8:2::2/64 dev $h2
ip address del 198.51.100.2/24 dev $h2
ip link set dev $h2 down
vrf_destroy "vrf-h2"
}
router_create()
{
ip link set dev $rp1 up
ip link set dev $rp2 up
ip address add 192.0.2.1/24 dev $rp1
ip address add 2001:db8:1::1/64 dev $rp1
ip address add 198.51.100.1/24 dev $rp2
ip address add 2001:db8:2::1/64 dev $rp2
}
router_destroy()
{
ip address del 2001:db8:2::1/64 dev $rp2
ip address del 198.51.100.1/24 dev $rp2
ip address del 2001:db8:1::1/64 dev $rp1
ip address del 192.0.2.1/24 dev $rp1
ip link set dev $rp2 down
ip link set dev $rp1 down
}
setup_prepare()
{
h1=${NETIFS[p1]}
rp1=${NETIFS[p2]}
rp2=${NETIFS[p3]}
h2=${NETIFS[p4]}
vrf_prepare
h1_create
h2_create
router_create
forwarding_enable
}
cleanup()
{
pre_cleanup
forwarding_restore
router_destroy
h2_destroy
h1_destroy
vrf_cleanup
}
ping_ipv4()
{
ping_test $h1 198.51.100.2
}
ping_ipv6()
{
ping6_test $h1 2001:db8:2::2
}
trap cleanup EXIT
setup_prepare
setup_wait
tests_run
exit $EXIT_STATUS
+113
View File
@@ -0,0 +1,113 @@
#!/bin/bash
# SPDX-License-Identifier: GPL-2.0
ALL_TESTS="
ping_ipv4
ping_ipv6
"
NUM_NETIFS=4
source lib.sh
h1_create()
{
simple_if_init $h1 192.0.2.1/28 2001:db8:1::1/64
ip -4 route add 192.0.2.128/28 vrf v$h1 nexthop via 192.0.2.2
ip -6 route add 2001:db8:2::/64 vrf v$h1 nexthop via 2001:db8:1::2
}
h1_destroy()
{
ip -6 route del 2001:db8:2::/64 vrf v$h1
ip -4 route del 192.0.2.128/28 vrf v$h1
simple_if_fini $h1 192.0.2.1/28 2001:db8:1::1/64
}
h2_create()
{
simple_if_init $h2 192.0.2.130/28 2001:db8:2::2/64
ip -4 route add 192.0.2.0/28 vrf v$h2 nexthop via 192.0.2.129
ip -6 route add 2001:db8:1::/64 vrf v$h2 nexthop via 2001:db8:2::1
}
h2_destroy()
{
ip -6 route del 2001:db8:1::/64 vrf v$h2
ip -4 route del 192.0.2.0/28 vrf v$h2
simple_if_fini $h2 192.0.2.130/28 2001:db8:2::2/64
}
router_create()
{
ip link add name br1 type bridge vlan_filtering 1
ip link set dev br1 up
ip link set dev $swp1 master br1
ip link set dev $swp1 up
__addr_add_del br1 add 192.0.2.2/28 2001:db8:1::2/64
ip link set dev $swp2 up
__addr_add_del $swp2 add 192.0.2.129/28 2001:db8:2::1/64
}
router_destroy()
{
__addr_add_del $swp2 del 192.0.2.129/28 2001:db8:2::1/64
ip link set dev $swp2 down
__addr_add_del br1 del 192.0.2.2/28 2001:db8:1::2/64
ip link set dev $swp1 down
ip link set dev $swp1 nomaster
ip link del dev br1
}
setup_prepare()
{
h1=${NETIFS[p1]}
swp1=${NETIFS[p2]}
swp2=${NETIFS[p3]}
h2=${NETIFS[p4]}
vrf_prepare
h1_create
h2_create
router_create
forwarding_enable
}
cleanup()
{
pre_cleanup
forwarding_restore
router_destroy
h2_destroy
h1_destroy
vrf_cleanup
}
ping_ipv4()
{
ping_test $h1 192.0.2.130
}
ping_ipv6()
{
ping6_test $h1 2001:db8:2::2
}
trap cleanup EXIT
setup_prepare
setup_wait
tests_run
exit $EXIT_STATUS
@@ -0,0 +1,132 @@
#!/bin/bash
# SPDX-License-Identifier: GPL-2.0
ALL_TESTS="
ping_ipv4
ping_ipv6
vlan
"
NUM_NETIFS=4
source lib.sh
h1_create()
{
simple_if_init $h1
vlan_create $h1 555 v$h1 192.0.2.1/28 2001:db8:1::1/64
ip -4 route add 192.0.2.128/28 vrf v$h1 nexthop via 192.0.2.2
ip -6 route add 2001:db8:2::/64 vrf v$h1 nexthop via 2001:db8:1::2
}
h1_destroy()
{
ip -6 route del 2001:db8:2::/64 vrf v$h1
ip -4 route del 192.0.2.128/28 vrf v$h1
vlan_destroy $h1 555
simple_if_fini $h1
}
h2_create()
{
simple_if_init $h2 192.0.2.130/28 2001:db8:2::2/64
ip -4 route add 192.0.2.0/28 vrf v$h2 nexthop via 192.0.2.129
ip -6 route add 2001:db8:1::/64 vrf v$h2 nexthop via 2001:db8:2::1
}
h2_destroy()
{
ip -6 route del 2001:db8:1::/64 vrf v$h2
ip -4 route del 192.0.2.0/28 vrf v$h2
simple_if_fini $h2 192.0.2.130/28 2001:db8:2::2/64
}
router_create()
{
ip link add name br1 type bridge vlan_filtering 1
ip link set dev br1 up
ip link set dev $swp1 master br1
ip link set dev $swp1 up
bridge vlan add dev br1 vid 555 self pvid untagged
bridge vlan add dev $swp1 vid 555
__addr_add_del br1 add 192.0.2.2/28 2001:db8:1::2/64
ip link set dev $swp2 up
__addr_add_del $swp2 add 192.0.2.129/28 2001:db8:2::1/64
}
router_destroy()
{
__addr_add_del $swp2 del 192.0.2.129/28 2001:db8:2::1/64
ip link set dev $swp2 down
__addr_add_del br1 del 192.0.2.2/28 2001:db8:1::2/64
ip link set dev $swp1 down
ip link set dev $swp1 nomaster
ip link del dev br1
}
setup_prepare()
{
h1=${NETIFS[p1]}
swp1=${NETIFS[p2]}
swp2=${NETIFS[p3]}
h2=${NETIFS[p4]}
vrf_prepare
h1_create
h2_create
router_create
forwarding_enable
}
cleanup()
{
pre_cleanup
forwarding_restore
router_destroy
h2_destroy
h1_destroy
vrf_cleanup
}
vlan()
{
RET=0
bridge vlan add dev br1 vid 333 self
check_err $? "Can't add a non-PVID VLAN"
bridge vlan del dev br1 vid 333 self
check_err $? "Can't remove a non-PVID VLAN"
log_test "vlan"
}
ping_ipv4()
{
ping_test $h1 192.0.2.130
}
ping_ipv6()
{
ping6_test $h1 2001:db8:2::2
}
trap cleanup EXIT
setup_prepare
setup_wait
tests_run
exit $EXIT_STATUS
+233
View File
@@ -0,0 +1,233 @@
#!/bin/bash
# SPDX-License-Identifier: GPL-2.0
ALL_TESTS="ping_ipv4"
NUM_NETIFS=6
source lib.sh
h1_create()
{
vrf_create "vrf-h1"
ip link set dev $h1 master vrf-h1
ip link set dev vrf-h1 up
ip link set dev $h1 up
ip address add 192.0.2.2/24 dev $h1
ip route add 198.51.100.0/24 vrf vrf-h1 nexthop via 192.0.2.1
ip route add 198.51.200.0/24 vrf vrf-h1 nexthop via 192.0.2.1
}
h1_destroy()
{
ip route del 198.51.200.0/24 vrf vrf-h1
ip route del 198.51.100.0/24 vrf vrf-h1
ip address del 192.0.2.2/24 dev $h1
ip link set dev $h1 down
vrf_destroy "vrf-h1"
}
h2_create()
{
vrf_create "vrf-h2"
ip link set dev $h2 master vrf-h2
ip link set dev vrf-h2 up
ip link set dev $h2 up
ip address add 198.51.100.2/24 dev $h2
ip route add 192.0.2.0/24 vrf vrf-h2 nexthop via 198.51.100.1
ip route add 198.51.200.0/24 vrf vrf-h2 nexthop via 198.51.100.1
}
h2_destroy()
{
ip route del 198.51.200.0/24 vrf vrf-h2
ip route del 192.0.2.0/24 vrf vrf-h2
ip address del 198.51.100.2/24 dev $h2
ip link set dev $h2 down
vrf_destroy "vrf-h2"
}
h3_create()
{
vrf_create "vrf-h3"
ip link set dev $h3 master vrf-h3
ip link set dev vrf-h3 up
ip link set dev $h3 up
ip address add 198.51.200.2/24 dev $h3
ip route add 192.0.2.0/24 vrf vrf-h3 nexthop via 198.51.200.1
ip route add 198.51.100.0/24 vrf vrf-h3 nexthop via 198.51.200.1
}
h3_destroy()
{
ip route del 198.51.100.0/24 vrf vrf-h3
ip route del 192.0.2.0/24 vrf vrf-h3
ip address del 198.51.200.2/24 dev $h3
ip link set dev $h3 down
vrf_destroy "vrf-h3"
}
router_create()
{
ip link set dev $rp1 up
ip link set dev $rp2 up
ip link set dev $rp3 up
ip address add 192.0.2.1/24 dev $rp1
ip address add 198.51.100.1/24 dev $rp2
ip address add 198.51.200.1/24 dev $rp3
}
router_destroy()
{
ip address del 198.51.200.1/24 dev $rp3
ip address del 198.51.100.1/24 dev $rp2
ip address del 192.0.2.1/24 dev $rp1
ip link set dev $rp3 down
ip link set dev $rp2 down
ip link set dev $rp1 down
}
setup_prepare()
{
h1=${NETIFS[p1]}
rp1=${NETIFS[p2]}
rp2=${NETIFS[p3]}
h2=${NETIFS[p4]}
rp3=${NETIFS[p5]}
h3=${NETIFS[p6]}
vrf_prepare
h1_create
h2_create
h3_create
router_create
forwarding_enable
}
cleanup()
{
pre_cleanup
forwarding_restore
router_destroy
h3_destroy
h2_destroy
h1_destroy
vrf_cleanup
}
bc_forwarding_disable()
{
sysctl_set net.ipv4.conf.all.bc_forwarding 0
sysctl_set net.ipv4.conf.$rp1.bc_forwarding 0
}
bc_forwarding_enable()
{
sysctl_set net.ipv4.conf.all.bc_forwarding 1
sysctl_set net.ipv4.conf.$rp1.bc_forwarding 1
}
bc_forwarding_restore()
{
sysctl_restore net.ipv4.conf.$rp1.bc_forwarding
sysctl_restore net.ipv4.conf.all.bc_forwarding
}
ping_test_from()
{
local oif=$1
local dip=$2
local from=$3
local fail=${4:-0}
RET=0
log_info "ping $dip, expected reply from $from"
ip vrf exec $(master_name_get $oif) \
$PING -I $oif $dip -c 10 -i 0.1 -w 2 -b 2>&1 | grep $from &> /dev/null
check_err_fail $fail $?
}
ping_ipv4()
{
sysctl_set net.ipv4.icmp_echo_ignore_broadcasts 0
bc_forwarding_disable
log_info "bc_forwarding disabled on r1 =>"
ping_test_from $h1 198.51.100.255 192.0.2.1
log_test "h1 -> net2: reply from r1 (not forwarding)"
ping_test_from $h1 198.51.200.255 192.0.2.1
log_test "h1 -> net3: reply from r1 (not forwarding)"
ping_test_from $h1 192.0.2.255 192.0.2.1
log_test "h1 -> net1: reply from r1 (not dropping)"
ping_test_from $h1 255.255.255.255 192.0.2.1
log_test "h1 -> 255.255.255.255: reply from r1 (not forwarding)"
ping_test_from $h2 192.0.2.255 198.51.100.1
log_test "h2 -> net1: reply from r1 (not forwarding)"
ping_test_from $h2 198.51.200.255 198.51.100.1
log_test "h2 -> net3: reply from r1 (not forwarding)"
ping_test_from $h2 198.51.100.255 198.51.100.1
log_test "h2 -> net2: reply from r1 (not dropping)"
ping_test_from $h2 255.255.255.255 198.51.100.1
log_test "h2 -> 255.255.255.255: reply from r1 (not forwarding)"
bc_forwarding_restore
bc_forwarding_enable
log_info "bc_forwarding enabled on r1 =>"
ping_test_from $h1 198.51.100.255 198.51.100.2
log_test "h1 -> net2: reply from h2 (forwarding)"
ping_test_from $h1 198.51.200.255 198.51.200.2
log_test "h1 -> net3: reply from h3 (forwarding)"
ping_test_from $h1 192.0.2.255 192.0.2.1 1
log_test "h1 -> net1: no reply (dropping)"
ping_test_from $h1 255.255.255.255 192.0.2.1
log_test "h1 -> 255.255.255.255: reply from r1 (not forwarding)"
ping_test_from $h2 192.0.2.255 192.0.2.2
log_test "h2 -> net1: reply from h1 (forwarding)"
ping_test_from $h2 198.51.200.255 198.51.200.2
log_test "h2 -> net3: reply from h3 (forwarding)"
ping_test_from $h2 198.51.100.255 198.51.100.1 1
log_test "h2 -> net2: no reply (dropping)"
ping_test_from $h2 255.255.255.255 198.51.100.1
log_test "h2 -> 255.255.255.255: reply from r1 (not forwarding)"
bc_forwarding_restore
sysctl_restore net.ipv4.icmp_echo_ignore_broadcasts
}
trap cleanup EXIT
setup_prepare
setup_wait
tests_run
exit $EXIT_STATUS
+342
View File
@@ -0,0 +1,342 @@
#!/bin/bash
# SPDX-License-Identifier: GPL-2.0
ALL_TESTS="ping_ipv4 ping_ipv6 multipath_test"
NUM_NETIFS=8
source lib.sh
h1_create()
{
vrf_create "vrf-h1"
ip link set dev $h1 master vrf-h1
ip link set dev vrf-h1 up
ip link set dev $h1 up
ip address add 192.0.2.2/24 dev $h1
ip address add 2001:db8:1::2/64 dev $h1
ip route add 198.51.100.0/24 vrf vrf-h1 nexthop via 192.0.2.1
ip route add 2001:db8:2::/64 vrf vrf-h1 nexthop via 2001:db8:1::1
}
h1_destroy()
{
ip route del 2001:db8:2::/64 vrf vrf-h1
ip route del 198.51.100.0/24 vrf vrf-h1
ip address del 2001:db8:1::2/64 dev $h1
ip address del 192.0.2.2/24 dev $h1
ip link set dev $h1 down
vrf_destroy "vrf-h1"
}
h2_create()
{
vrf_create "vrf-h2"
ip link set dev $h2 master vrf-h2
ip link set dev vrf-h2 up
ip link set dev $h2 up
ip address add 198.51.100.2/24 dev $h2
ip address add 2001:db8:2::2/64 dev $h2
ip route add 192.0.2.0/24 vrf vrf-h2 nexthop via 198.51.100.1
ip route add 2001:db8:1::/64 vrf vrf-h2 nexthop via 2001:db8:2::1
}
h2_destroy()
{
ip route del 2001:db8:1::/64 vrf vrf-h2
ip route del 192.0.2.0/24 vrf vrf-h2
ip address del 2001:db8:2::2/64 dev $h2
ip address del 198.51.100.2/24 dev $h2
ip link set dev $h2 down
vrf_destroy "vrf-h2"
}
router1_create()
{
vrf_create "vrf-r1"
ip link set dev $rp11 master vrf-r1
ip link set dev $rp12 master vrf-r1
ip link set dev $rp13 master vrf-r1
ip link set dev vrf-r1 up
ip link set dev $rp11 up
ip link set dev $rp12 up
ip link set dev $rp13 up
ip address add 192.0.2.1/24 dev $rp11
ip address add 2001:db8:1::1/64 dev $rp11
ip address add 169.254.2.12/24 dev $rp12
ip address add fe80:2::12/64 dev $rp12
ip address add 169.254.3.13/24 dev $rp13
ip address add fe80:3::13/64 dev $rp13
ip route add 198.51.100.0/24 vrf vrf-r1 \
nexthop via 169.254.2.22 dev $rp12 \
nexthop via 169.254.3.23 dev $rp13
ip route add 2001:db8:2::/64 vrf vrf-r1 \
nexthop via fe80:2::22 dev $rp12 \
nexthop via fe80:3::23 dev $rp13
}
router1_destroy()
{
ip route del 2001:db8:2::/64 vrf vrf-r1
ip route del 198.51.100.0/24 vrf vrf-r1
ip address del fe80:3::13/64 dev $rp13
ip address del 169.254.3.13/24 dev $rp13
ip address del fe80:2::12/64 dev $rp12
ip address del 169.254.2.12/24 dev $rp12
ip address del 2001:db8:1::1/64 dev $rp11
ip address del 192.0.2.1/24 dev $rp11
ip link set dev $rp13 down
ip link set dev $rp12 down
ip link set dev $rp11 down
vrf_destroy "vrf-r1"
}
router2_create()
{
vrf_create "vrf-r2"
ip link set dev $rp21 master vrf-r2
ip link set dev $rp22 master vrf-r2
ip link set dev $rp23 master vrf-r2
ip link set dev vrf-r2 up
ip link set dev $rp21 up
ip link set dev $rp22 up
ip link set dev $rp23 up
ip address add 198.51.100.1/24 dev $rp21
ip address add 2001:db8:2::1/64 dev $rp21
ip address add 169.254.2.22/24 dev $rp22
ip address add fe80:2::22/64 dev $rp22
ip address add 169.254.3.23/24 dev $rp23
ip address add fe80:3::23/64 dev $rp23
ip route add 192.0.2.0/24 vrf vrf-r2 \
nexthop via 169.254.2.12 dev $rp22 \
nexthop via 169.254.3.13 dev $rp23
ip route add 2001:db8:1::/64 vrf vrf-r2 \
nexthop via fe80:2::12 dev $rp22 \
nexthop via fe80:3::13 dev $rp23
}
router2_destroy()
{
ip route del 2001:db8:1::/64 vrf vrf-r2
ip route del 192.0.2.0/24 vrf vrf-r2
ip address del fe80:3::23/64 dev $rp23
ip address del 169.254.3.23/24 dev $rp23
ip address del fe80:2::22/64 dev $rp22
ip address del 169.254.2.22/24 dev $rp22
ip address del 2001:db8:2::1/64 dev $rp21
ip address del 198.51.100.1/24 dev $rp21
ip link set dev $rp23 down
ip link set dev $rp22 down
ip link set dev $rp21 down
vrf_destroy "vrf-r2"
}
multipath4_test()
{
local desc="$1"
local weight_rp12=$2
local weight_rp13=$3
local t0_rp12 t0_rp13 t1_rp12 t1_rp13
local packets_rp12 packets_rp13
# Transmit multiple flows from h1 to h2 and make sure they are
# distributed between both multipath links (rp12 and rp13)
# according to the configured weights.
sysctl_set net.ipv4.fib_multipath_hash_policy 1
ip route replace 198.51.100.0/24 vrf vrf-r1 \
nexthop via 169.254.2.22 dev $rp12 weight $weight_rp12 \
nexthop via 169.254.3.23 dev $rp13 weight $weight_rp13
t0_rp12=$(link_stats_tx_packets_get $rp12)
t0_rp13=$(link_stats_tx_packets_get $rp13)
ip vrf exec vrf-h1 $MZ -q -p 64 -A 192.0.2.2 -B 198.51.100.2 \
-d 1msec -t udp "sp=1024,dp=0-32768"
t1_rp12=$(link_stats_tx_packets_get $rp12)
t1_rp13=$(link_stats_tx_packets_get $rp13)
let "packets_rp12 = $t1_rp12 - $t0_rp12"
let "packets_rp13 = $t1_rp13 - $t0_rp13"
multipath_eval "$desc" $weight_rp12 $weight_rp13 $packets_rp12 $packets_rp13
# Restore settings.
ip route replace 198.51.100.0/24 vrf vrf-r1 \
nexthop via 169.254.2.22 dev $rp12 \
nexthop via 169.254.3.23 dev $rp13
sysctl_restore net.ipv4.fib_multipath_hash_policy
}
multipath6_l4_test()
{
local desc="$1"
local weight_rp12=$2
local weight_rp13=$3
local t0_rp12 t0_rp13 t1_rp12 t1_rp13
local packets_rp12 packets_rp13
# Transmit multiple flows from h1 to h2 and make sure they are
# distributed between both multipath links (rp12 and rp13)
# according to the configured weights.
sysctl_set net.ipv6.fib_multipath_hash_policy 1
ip route replace 2001:db8:2::/64 vrf vrf-r1 \
nexthop via fe80:2::22 dev $rp12 weight $weight_rp12 \
nexthop via fe80:3::23 dev $rp13 weight $weight_rp13
t0_rp12=$(link_stats_tx_packets_get $rp12)
t0_rp13=$(link_stats_tx_packets_get $rp13)
$MZ $h1 -6 -q -p 64 -A 2001:db8:1::2 -B 2001:db8:2::2 \
-d 1msec -t udp "sp=1024,dp=0-32768"
t1_rp12=$(link_stats_tx_packets_get $rp12)
t1_rp13=$(link_stats_tx_packets_get $rp13)
let "packets_rp12 = $t1_rp12 - $t0_rp12"
let "packets_rp13 = $t1_rp13 - $t0_rp13"
multipath_eval "$desc" $weight_rp12 $weight_rp13 $packets_rp12 $packets_rp13
ip route replace 2001:db8:2::/64 vrf vrf-r1 \
nexthop via fe80:2::22 dev $rp12 \
nexthop via fe80:3::23 dev $rp13
sysctl_restore net.ipv6.fib_multipath_hash_policy
}
multipath6_test()
{
local desc="$1"
local weight_rp12=$2
local weight_rp13=$3
local t0_rp12 t0_rp13 t1_rp12 t1_rp13
local packets_rp12 packets_rp13
ip route replace 2001:db8:2::/64 vrf vrf-r1 \
nexthop via fe80:2::22 dev $rp12 weight $weight_rp12 \
nexthop via fe80:3::23 dev $rp13 weight $weight_rp13
t0_rp12=$(link_stats_tx_packets_get $rp12)
t0_rp13=$(link_stats_tx_packets_get $rp13)
# Generate 16384 echo requests, each with a random flow label.
for _ in $(seq 1 16384); do
ip vrf exec vrf-h1 $PING6 2001:db8:2::2 -F 0 -c 1 -q &> /dev/null
done
t1_rp12=$(link_stats_tx_packets_get $rp12)
t1_rp13=$(link_stats_tx_packets_get $rp13)
let "packets_rp12 = $t1_rp12 - $t0_rp12"
let "packets_rp13 = $t1_rp13 - $t0_rp13"
multipath_eval "$desc" $weight_rp12 $weight_rp13 $packets_rp12 $packets_rp13
ip route replace 2001:db8:2::/64 vrf vrf-r1 \
nexthop via fe80:2::22 dev $rp12 \
nexthop via fe80:3::23 dev $rp13
}
multipath_test()
{
log_info "Running IPv4 multipath tests"
multipath4_test "ECMP" 1 1
multipath4_test "Weighted MP 2:1" 2 1
multipath4_test "Weighted MP 11:45" 11 45
log_info "Running IPv6 multipath tests"
multipath6_test "ECMP" 1 1
multipath6_test "Weighted MP 2:1" 2 1
multipath6_test "Weighted MP 11:45" 11 45
log_info "Running IPv6 L4 hash multipath tests"
multipath6_l4_test "ECMP" 1 1
multipath6_l4_test "Weighted MP 2:1" 2 1
multipath6_l4_test "Weighted MP 11:45" 11 45
}
setup_prepare()
{
h1=${NETIFS[p1]}
rp11=${NETIFS[p2]}
rp12=${NETIFS[p3]}
rp22=${NETIFS[p4]}
rp13=${NETIFS[p5]}
rp23=${NETIFS[p6]}
rp21=${NETIFS[p7]}
h2=${NETIFS[p8]}
vrf_prepare
h1_create
h2_create
router1_create
router2_create
forwarding_enable
}
cleanup()
{
pre_cleanup
forwarding_restore
router2_destroy
router1_destroy
h2_destroy
h1_destroy
vrf_cleanup
}
ping_ipv4()
{
ping_test $h1 198.51.100.2
}
ping_ipv6()
{
ping6_test $h1 2001:db8:2::2
}
trap cleanup EXIT
setup_prepare
setup_wait
tests_run
exit $EXIT_STATUS
+213
View File
@@ -0,0 +1,213 @@
#!/bin/bash
# SPDX-License-Identifier: GPL-2.0
ALL_TESTS="gact_drop_and_ok_test mirred_egress_redirect_test \
mirred_egress_mirror_test gact_trap_test"
NUM_NETIFS=4
source tc_common.sh
source lib.sh
tcflags="skip_hw"
h1_create()
{
simple_if_init $h1 192.0.2.1/24
}
h1_destroy()
{
simple_if_fini $h1 192.0.2.1/24
}
h2_create()
{
simple_if_init $h2 192.0.2.2/24
tc qdisc add dev $h2 clsact
}
h2_destroy()
{
tc qdisc del dev $h2 clsact
simple_if_fini $h2 192.0.2.2/24
}
switch_create()
{
simple_if_init $swp1 192.0.2.2/24
tc qdisc add dev $swp1 clsact
simple_if_init $swp2 192.0.2.1/24
}
switch_destroy()
{
simple_if_fini $swp2 192.0.2.1/24
tc qdisc del dev $swp1 clsact
simple_if_fini $swp1 192.0.2.2/24
}
mirred_egress_test()
{
local action=$1
RET=0
tc filter add dev $h2 ingress protocol ip pref 1 handle 101 flower \
$tcflags dst_ip 192.0.2.2 action drop
$MZ $h1 -c 1 -p 64 -a $h1mac -b $h2mac -A 192.0.2.1 -B 192.0.2.2 \
-t ip -q
tc_check_packets "dev $h2 ingress" 101 1
check_fail $? "Matched without redirect rule inserted"
tc filter add dev $swp1 ingress protocol ip pref 1 handle 101 flower \
$tcflags dst_ip 192.0.2.2 action mirred egress $action \
dev $swp2
$MZ $h1 -c 1 -p 64 -a $h1mac -b $h2mac -A 192.0.2.1 -B 192.0.2.2 \
-t ip -q
tc_check_packets "dev $h2 ingress" 101 1
check_err $? "Did not match incoming $action packet"
tc filter del dev $swp1 ingress protocol ip pref 1 handle 101 flower
tc filter del dev $h2 ingress protocol ip pref 1 handle 101 flower
log_test "mirred egress $action ($tcflags)"
}
gact_drop_and_ok_test()
{
RET=0
tc filter add dev $swp1 ingress protocol ip pref 2 handle 102 flower \
$tcflags dst_ip 192.0.2.2 action drop
$MZ $h1 -c 1 -p 64 -a $h1mac -b $h2mac -A 192.0.2.1 -B 192.0.2.2 \
-t ip -q
tc_check_packets "dev $swp1 ingress" 102 1
check_err $? "Packet was not dropped"
tc filter add dev $swp1 ingress protocol ip pref 1 handle 101 flower \
$tcflags dst_ip 192.0.2.2 action ok
$MZ $h1 -c 1 -p 64 -a $h1mac -b $h2mac -A 192.0.2.1 -B 192.0.2.2 \
-t ip -q
tc_check_packets "dev $swp1 ingress" 101 1
check_err $? "Did not see passed packet"
tc_check_packets "dev $swp1 ingress" 102 2
check_fail $? "Packet was dropped and it should not reach here"
tc filter del dev $swp1 ingress protocol ip pref 2 handle 102 flower
tc filter del dev $swp1 ingress protocol ip pref 1 handle 101 flower
log_test "gact drop and ok ($tcflags)"
}
gact_trap_test()
{
RET=0
if [[ "$tcflags" != "skip_sw" ]]; then
return 0;
fi
tc filter add dev $swp1 ingress protocol ip pref 1 handle 101 flower \
skip_hw dst_ip 192.0.2.2 action drop
tc filter add dev $swp1 ingress protocol ip pref 3 handle 103 flower \
$tcflags dst_ip 192.0.2.2 action mirred egress redirect \
dev $swp2
$MZ $h1 -c 1 -p 64 -a $h1mac -b $h2mac -A 192.0.2.1 -B 192.0.2.2 \
-t ip -q
tc_check_packets "dev $swp1 ingress" 101 1
check_fail $? "Saw packet without trap rule inserted"
tc filter add dev $swp1 ingress protocol ip pref 2 handle 102 flower \
$tcflags dst_ip 192.0.2.2 action trap
$MZ $h1 -c 1 -p 64 -a $h1mac -b $h2mac -A 192.0.2.1 -B 192.0.2.2 \
-t ip -q
tc_check_packets "dev $swp1 ingress" 102 1
check_err $? "Packet was not trapped"
tc_check_packets "dev $swp1 ingress" 101 1
check_err $? "Did not see trapped packet"
tc filter del dev $swp1 ingress protocol ip pref 3 handle 103 flower
tc filter del dev $swp1 ingress protocol ip pref 2 handle 102 flower
tc filter del dev $swp1 ingress protocol ip pref 1 handle 101 flower
log_test "trap ($tcflags)"
}
setup_prepare()
{
h1=${NETIFS[p1]}
swp1=${NETIFS[p2]}
swp2=${NETIFS[p3]}
h2=${NETIFS[p4]}
h1mac=$(mac_get $h1)
h2mac=$(mac_get $h2)
swp1origmac=$(mac_get $swp1)
swp2origmac=$(mac_get $swp2)
ip link set $swp1 address $h2mac
ip link set $swp2 address $h1mac
vrf_prepare
h1_create
h2_create
switch_create
}
cleanup()
{
pre_cleanup
switch_destroy
h2_destroy
h1_destroy
vrf_cleanup
ip link set $swp2 address $swp2origmac
ip link set $swp1 address $swp1origmac
}
mirred_egress_redirect_test()
{
mirred_egress_test "redirect"
}
mirred_egress_mirror_test()
{
mirred_egress_test "mirror"
}
trap cleanup EXIT
setup_prepare
setup_wait
tests_run
tc_offload_check
if [[ $? -ne 0 ]]; then
log_info "Could not test offloaded functionality"
else
tcflags="skip_sw"
tests_run
fi
exit $EXIT_STATUS
+205
View File
@@ -0,0 +1,205 @@
#!/bin/bash
# SPDX-License-Identifier: GPL-2.0
ALL_TESTS="unreachable_chain_test gact_goto_chain_test create_destroy_chain \
template_filter_fits"
NUM_NETIFS=2
source tc_common.sh
source lib.sh
tcflags="skip_hw"
h1_create()
{
simple_if_init $h1 192.0.2.1/24
}
h1_destroy()
{
simple_if_fini $h1 192.0.2.1/24
}
h2_create()
{
simple_if_init $h2 192.0.2.2/24
tc qdisc add dev $h2 clsact
}
h2_destroy()
{
tc qdisc del dev $h2 clsact
simple_if_fini $h2 192.0.2.2/24
}
unreachable_chain_test()
{
RET=0
tc filter add dev $h2 ingress chain 1 protocol ip pref 1 handle 1101 \
flower $tcflags dst_mac $h2mac action drop
$MZ $h1 -c 1 -p 64 -a $h1mac -b $h2mac -A 192.0.2.1 -B 192.0.2.2 \
-t ip -q
tc_check_packets "dev $h2 ingress" 1101 1
check_fail $? "matched on filter in unreachable chain"
tc filter del dev $h2 ingress chain 1 protocol ip pref 1 handle 1101 \
flower
log_test "unreachable chain ($tcflags)"
}
gact_goto_chain_test()
{
RET=0
tc filter add dev $h2 ingress chain 1 protocol ip pref 1 handle 1101 \
flower $tcflags dst_mac $h2mac action drop
tc filter add dev $h2 ingress protocol ip pref 2 handle 102 flower \
$tcflags dst_mac $h2mac action drop
tc filter add dev $h2 ingress protocol ip pref 1 handle 101 flower \
$tcflags dst_mac $h2mac action goto chain 1
$MZ $h1 -c 1 -p 64 -a $h1mac -b $h2mac -A 192.0.2.1 -B 192.0.2.2 \
-t ip -q
tc_check_packets "dev $h2 ingress" 102 1
check_fail $? "Matched on a wrong filter"
tc_check_packets "dev $h2 ingress" 101 1
check_err $? "Did not match on correct filter with goto chain action"
tc_check_packets "dev $h2 ingress" 1101 1
check_err $? "Did not match on correct filter in chain 1"
tc filter del dev $h2 ingress protocol ip pref 1 handle 101 flower
tc filter del dev $h2 ingress protocol ip pref 2 handle 102 flower
tc filter del dev $h2 ingress chain 1 protocol ip pref 1 handle 1101 \
flower
log_test "gact goto chain ($tcflags)"
}
create_destroy_chain()
{
RET=0
tc chain add dev $h2 ingress
check_err $? "Failed to create default chain"
output="$(tc -j chain get dev $h2 ingress)"
check_err $? "Failed to get default chain"
echo $output | jq -e ".[] | select(.chain == 0)" &> /dev/null
check_err $? "Unexpected output for default chain"
tc chain add dev $h2 ingress chain 1
check_err $? "Failed to create chain 1"
output="$(tc -j chain get dev $h2 ingress chain 1)"
check_err $? "Failed to get chain 1"
echo $output | jq -e ".[] | select(.chain == 1)" &> /dev/null
check_err $? "Unexpected output for chain 1"
output="$(tc -j chain show dev $h2 ingress)"
check_err $? "Failed to dump chains"
echo $output | jq -e ".[] | select(.chain == 0)" &> /dev/null
check_err $? "Can't find default chain in dump"
echo $output | jq -e ".[] | select(.chain == 1)" &> /dev/null
check_err $? "Can't find chain 1 in dump"
tc chain del dev $h2 ingress
check_err $? "Failed to destroy default chain"
tc chain del dev $h2 ingress chain 1
check_err $? "Failed to destroy chain 1"
log_test "create destroy chain"
}
template_filter_fits()
{
RET=0
tc chain add dev $h2 ingress protocol ip \
flower dst_mac 00:00:00:00:00:00/FF:FF:FF:FF:FF:FF &> /dev/null
tc chain add dev $h2 ingress chain 1 protocol ip \
flower src_mac 00:00:00:00:00:00/FF:FF:FF:FF:FF:FF &> /dev/null
tc filter add dev $h2 ingress protocol ip pref 1 handle 1101 \
flower dst_mac $h2mac action drop
check_err $? "Failed to insert filter which fits template"
tc filter add dev $h2 ingress protocol ip pref 1 handle 1102 \
flower src_mac $h2mac action drop &> /dev/null
check_fail $? "Incorrectly succeded to insert filter which does not template"
tc filter add dev $h2 ingress chain 1 protocol ip pref 1 handle 1101 \
flower src_mac $h2mac action drop
check_err $? "Failed to insert filter which fits template"
tc filter add dev $h2 ingress chain 1 protocol ip pref 1 handle 1102 \
flower dst_mac $h2mac action drop &> /dev/null
check_fail $? "Incorrectly succeded to insert filter which does not template"
tc filter del dev $h2 ingress chain 1 protocol ip pref 1 handle 1102 \
flower &> /dev/null
tc filter del dev $h2 ingress chain 1 protocol ip pref 1 handle 1101 \
flower &> /dev/null
tc filter del dev $h2 ingress protocol ip pref 1 handle 1102 \
flower &> /dev/null
tc filter del dev $h2 ingress protocol ip pref 1 handle 1101 \
flower &> /dev/null
tc chain del dev $h2 ingress chain 1
tc chain del dev $h2 ingress
log_test "template filter fits"
}
setup_prepare()
{
h1=${NETIFS[p1]}
h2=${NETIFS[p2]}
h1mac=$(mac_get $h1)
h2mac=$(mac_get $h2)
vrf_prepare
h1_create
h2_create
}
cleanup()
{
pre_cleanup
h2_destroy
h1_destroy
vrf_cleanup
}
check_tc_chain_support
trap cleanup EXIT
setup_prepare
setup_wait
tests_run
tc_offload_check
if [[ $? -ne 0 ]]; then
log_info "Could not test offloaded functionality"
else
tcflags="skip_sw"
tests_run
fi
exit $EXIT_STATUS
@@ -0,0 +1,25 @@
#!/bin/bash
# SPDX-License-Identifier: GPL-2.0
CHECK_TC="yes"
tc_check_packets()
{
local id=$1
local handle=$2
local count=$3
local ret
output="$(tc -j -s filter show $id)"
# workaround the jq bug which causes jq to return 0 in case input is ""
ret=$?
if [[ $ret -ne 0 ]]; then
return $ret
fi
echo $output | \
jq -e ".[] \
| select(.options.handle == $handle) \
| select(.options.actions[0].stats.packets == $count)" \
&> /dev/null
return $?
}
+260
View File
@@ -0,0 +1,260 @@
#!/bin/bash
# SPDX-License-Identifier: GPL-2.0
ALL_TESTS="match_dst_mac_test match_src_mac_test match_dst_ip_test \
match_src_ip_test match_ip_flags_test"
NUM_NETIFS=2
source tc_common.sh
source lib.sh
tcflags="skip_hw"
h1_create()
{
simple_if_init $h1 192.0.2.1/24 198.51.100.1/24
}
h1_destroy()
{
simple_if_fini $h1 192.0.2.1/24 198.51.100.1/24
}
h2_create()
{
simple_if_init $h2 192.0.2.2/24 198.51.100.2/24
tc qdisc add dev $h2 clsact
}
h2_destroy()
{
tc qdisc del dev $h2 clsact
simple_if_fini $h2 192.0.2.2/24 198.51.100.2/24
}
match_dst_mac_test()
{
local dummy_mac=de:ad:be:ef:aa:aa
RET=0
tc filter add dev $h2 ingress protocol ip pref 1 handle 101 flower \
$tcflags dst_mac $dummy_mac action drop
tc filter add dev $h2 ingress protocol ip pref 2 handle 102 flower \
$tcflags dst_mac $h2mac action drop
$MZ $h1 -c 1 -p 64 -a $h1mac -b $h2mac -A 192.0.2.1 -B 192.0.2.2 \
-t ip -q
tc_check_packets "dev $h2 ingress" 101 1
check_fail $? "Matched on a wrong filter"
tc_check_packets "dev $h2 ingress" 102 1
check_err $? "Did not match on correct filter"
tc filter del dev $h2 ingress protocol ip pref 1 handle 101 flower
tc filter del dev $h2 ingress protocol ip pref 2 handle 102 flower
log_test "dst_mac match ($tcflags)"
}
match_src_mac_test()
{
local dummy_mac=de:ad:be:ef:aa:aa
RET=0
tc filter add dev $h2 ingress protocol ip pref 1 handle 101 flower \
$tcflags src_mac $dummy_mac action drop
tc filter add dev $h2 ingress protocol ip pref 2 handle 102 flower \
$tcflags src_mac $h1mac action drop
$MZ $h1 -c 1 -p 64 -a $h1mac -b $h2mac -A 192.0.2.1 -B 192.0.2.2 \
-t ip -q
tc_check_packets "dev $h2 ingress" 101 1
check_fail $? "Matched on a wrong filter"
tc_check_packets "dev $h2 ingress" 102 1
check_err $? "Did not match on correct filter"
tc filter del dev $h2 ingress protocol ip pref 1 handle 101 flower
tc filter del dev $h2 ingress protocol ip pref 2 handle 102 flower
log_test "src_mac match ($tcflags)"
}
match_dst_ip_test()
{
RET=0
tc filter add dev $h2 ingress protocol ip pref 1 handle 101 flower \
$tcflags dst_ip 198.51.100.2 action drop
tc filter add dev $h2 ingress protocol ip pref 2 handle 102 flower \
$tcflags dst_ip 192.0.2.2 action drop
tc filter add dev $h2 ingress protocol ip pref 3 handle 103 flower \
$tcflags dst_ip 192.0.2.0/24 action drop
$MZ $h1 -c 1 -p 64 -a $h1mac -b $h2mac -A 192.0.2.1 -B 192.0.2.2 \
-t ip -q
tc_check_packets "dev $h2 ingress" 101 1
check_fail $? "Matched on a wrong filter"
tc_check_packets "dev $h2 ingress" 102 1
check_err $? "Did not match on correct filter"
tc filter del dev $h2 ingress protocol ip pref 2 handle 102 flower
$MZ $h1 -c 1 -p 64 -a $h1mac -b $h2mac -A 192.0.2.1 -B 192.0.2.2 \
-t ip -q
tc_check_packets "dev $h2 ingress" 103 1
check_err $? "Did not match on correct filter with mask"
tc filter del dev $h2 ingress protocol ip pref 1 handle 101 flower
tc filter del dev $h2 ingress protocol ip pref 3 handle 103 flower
log_test "dst_ip match ($tcflags)"
}
match_src_ip_test()
{
RET=0
tc filter add dev $h2 ingress protocol ip pref 1 handle 101 flower \
$tcflags src_ip 198.51.100.1 action drop
tc filter add dev $h2 ingress protocol ip pref 2 handle 102 flower \
$tcflags src_ip 192.0.2.1 action drop
tc filter add dev $h2 ingress protocol ip pref 3 handle 103 flower \
$tcflags src_ip 192.0.2.0/24 action drop
$MZ $h1 -c 1 -p 64 -a $h1mac -b $h2mac -A 192.0.2.1 -B 192.0.2.2 \
-t ip -q
tc_check_packets "dev $h2 ingress" 101 1
check_fail $? "Matched on a wrong filter"
tc_check_packets "dev $h2 ingress" 102 1
check_err $? "Did not match on correct filter"
tc filter del dev $h2 ingress protocol ip pref 2 handle 102 flower
$MZ $h1 -c 1 -p 64 -a $h1mac -b $h2mac -A 192.0.2.1 -B 192.0.2.2 \
-t ip -q
tc_check_packets "dev $h2 ingress" 103 1
check_err $? "Did not match on correct filter with mask"
tc filter del dev $h2 ingress protocol ip pref 1 handle 101 flower
tc filter del dev $h2 ingress protocol ip pref 3 handle 103 flower
log_test "src_ip match ($tcflags)"
}
match_ip_flags_test()
{
RET=0
tc filter add dev $h2 ingress protocol ip pref 1 handle 101 flower \
$tcflags ip_flags frag action continue
tc filter add dev $h2 ingress protocol ip pref 2 handle 102 flower \
$tcflags ip_flags firstfrag action continue
tc filter add dev $h2 ingress protocol ip pref 3 handle 103 flower \
$tcflags ip_flags nofirstfrag action continue
tc filter add dev $h2 ingress protocol ip pref 4 handle 104 flower \
$tcflags ip_flags nofrag action drop
$MZ $h1 -c 1 -p 1000 -a $h1mac -b $h2mac -A 192.0.2.1 -B 192.0.2.2 \
-t ip "frag=0" -q
tc_check_packets "dev $h2 ingress" 101 1
check_fail $? "Matched on wrong frag filter (nofrag)"
tc_check_packets "dev $h2 ingress" 102 1
check_fail $? "Matched on wrong firstfrag filter (nofrag)"
tc_check_packets "dev $h2 ingress" 103 1
check_err $? "Did not match on nofirstfrag filter (nofrag) "
tc_check_packets "dev $h2 ingress" 104 1
check_err $? "Did not match on nofrag filter (nofrag)"
$MZ $h1 -c 1 -p 1000 -a $h1mac -b $h2mac -A 192.0.2.1 -B 192.0.2.2 \
-t ip "frag=0,mf" -q
tc_check_packets "dev $h2 ingress" 101 1
check_err $? "Did not match on frag filter (1stfrag)"
tc_check_packets "dev $h2 ingress" 102 1
check_err $? "Did not match fistfrag filter (1stfrag)"
tc_check_packets "dev $h2 ingress" 103 1
check_err $? "Matched on wrong nofirstfrag filter (1stfrag)"
tc_check_packets "dev $h2 ingress" 104 1
check_err $? "Match on wrong nofrag filter (1stfrag)"
$MZ $h1 -c 1 -p 1000 -a $h1mac -b $h2mac -A 192.0.2.1 -B 192.0.2.2 \
-t ip "frag=256,mf" -q
$MZ $h1 -c 1 -p 1000 -a $h1mac -b $h2mac -A 192.0.2.1 -B 192.0.2.2 \
-t ip "frag=256" -q
tc_check_packets "dev $h2 ingress" 101 3
check_err $? "Did not match on frag filter (no1stfrag)"
tc_check_packets "dev $h2 ingress" 102 1
check_err $? "Matched on wrong firstfrag filter (no1stfrag)"
tc_check_packets "dev $h2 ingress" 103 3
check_err $? "Did not match on nofirstfrag filter (no1stfrag)"
tc_check_packets "dev $h2 ingress" 104 1
check_err $? "Matched on nofrag filter (no1stfrag)"
tc filter del dev $h2 ingress protocol ip pref 1 handle 101 flower
tc filter del dev $h2 ingress protocol ip pref 2 handle 102 flower
tc filter del dev $h2 ingress protocol ip pref 3 handle 103 flower
tc filter del dev $h2 ingress protocol ip pref 4 handle 104 flower
log_test "ip_flags match ($tcflags)"
}
setup_prepare()
{
h1=${NETIFS[p1]}
h2=${NETIFS[p2]}
h1mac=$(mac_get $h1)
h2mac=$(mac_get $h2)
vrf_prepare
h1_create
h2_create
}
cleanup()
{
pre_cleanup
h2_destroy
h1_destroy
vrf_cleanup
}
trap cleanup EXIT
setup_prepare
setup_wait
tests_run
tc_offload_check
if [[ $? -ne 0 ]]; then
log_info "Could not test offloaded functionality"
else
tcflags="skip_sw"
tests_run
fi
exit $EXIT_STATUS
+125
View File
@@ -0,0 +1,125 @@
#!/bin/bash
# SPDX-License-Identifier: GPL-2.0
ALL_TESTS="shared_block_test"
NUM_NETIFS=4
source tc_common.sh
source lib.sh
tcflags="skip_hw"
h1_create()
{
simple_if_init $h1 192.0.2.1/24
}
h1_destroy()
{
simple_if_fini $h1 192.0.2.1/24
}
h2_create()
{
simple_if_init $h2 192.0.2.1/24
}
h2_destroy()
{
simple_if_fini $h2 192.0.2.1/24
}
switch_create()
{
simple_if_init $swp1 192.0.2.2/24
tc qdisc add dev $swp1 ingress_block 22 egress_block 23 clsact
simple_if_init $swp2 192.0.2.2/24
tc qdisc add dev $swp2 ingress_block 22 egress_block 23 clsact
}
switch_destroy()
{
tc qdisc del dev $swp2 clsact
simple_if_fini $swp2 192.0.2.2/24
tc qdisc del dev $swp1 clsact
simple_if_fini $swp1 192.0.2.2/24
}
shared_block_test()
{
RET=0
tc filter add block 22 protocol ip pref 1 handle 101 flower \
$tcflags dst_ip 192.0.2.2 action drop
$MZ $h1 -c 1 -p 64 -a $h1mac -b $swmac -A 192.0.2.1 -B 192.0.2.2 \
-t ip -q
tc_check_packets "block 22" 101 1
check_err $? "Did not match first incoming packet on a block"
$MZ $h2 -c 1 -p 64 -a $h2mac -b $swmac -A 192.0.2.1 -B 192.0.2.2 \
-t ip -q
tc_check_packets "block 22" 101 2
check_err $? "Did not match second incoming packet on a block"
tc filter del block 22 protocol ip pref 1 handle 101 flower
log_test "shared block ($tcflags)"
}
setup_prepare()
{
h1=${NETIFS[p1]}
swp1=${NETIFS[p2]}
swp2=${NETIFS[p3]}
h2=${NETIFS[p4]}
h1mac=$(mac_get $h1)
h2mac=$(mac_get $h2)
swmac=$(mac_get $swp1)
swp2origmac=$(mac_get $swp2)
ip link set $swp2 address $swmac
vrf_prepare
h1_create
h2_create
switch_create
}
cleanup()
{
pre_cleanup
switch_destroy
h2_destroy
h1_destroy
vrf_cleanup
ip link set $swp2 address $swp2origmac
}
check_tc_shblock_support
trap cleanup EXIT
setup_prepare
setup_wait
tests_run
tc_offload_check
if [[ $? -ne 0 ]]; then
log_info "Could not test offloaded functionality"
else
tcflags="skip_sw"
tests_run
fi
exit $EXIT_STATUS