Skip to content

Commit 190f887

Browse files
dsaherndavem330
authored andcommitted
selftests: forwarding: Add suppport to create veth interfaces
For tests using veth interfaces, the test infrastructure can create the netdevs if they do not exist. Arguably this is a preferred approach since the tests require p$N and p$(N+1) to be pairs. Signed-off-by: David Ahern <dsahern@gmail.com> Reviewed-by: Ido Schimmel <idosch@mellanox.com> Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent 955dc68 commit 190f887

File tree

2 files changed

+40
-0
lines changed

2 files changed

+40
-0
lines changed

tools/testing/selftests/net/forwarding/forwarding.config.sample

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,11 @@ NETIFS[p6]=veth5
1414
NETIFS[p7]=veth6
1515
NETIFS[p8]=veth7
1616

17+
NETIF_TYPE=veth
18+
19+
# only virtual interfaces (veth) can be created by test infra
20+
#NETIF_CREATE=yes
21+
1722
##############################################################################
1823
# Defines
1924

tools/testing/selftests/net/forwarding/lib.sh

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,41 @@ done
7676
##############################################################################
7777
# Network interfaces configuration
7878

79+
create_netif_veth()
80+
{
81+
local i
82+
83+
for i in $(eval echo {1..$NUM_NETIFS}); do
84+
local j=$((i+1))
85+
86+
ip link show dev ${NETIFS[p$i]} &> /dev/null
87+
if [[ $? -ne 0 ]]; then
88+
ip link add ${NETIFS[p$i]} type veth \
89+
peer name ${NETIFS[p$j]}
90+
if [[ $? -ne 0 ]]; then
91+
echo "Failed to create netif"
92+
exit 1
93+
fi
94+
fi
95+
i=$j
96+
done
97+
}
98+
99+
create_netif()
100+
{
101+
case "$NETIF_TYPE" in
102+
veth) create_netif_veth
103+
;;
104+
*) echo "Can not create interfaces of type \'$NETIF_TYPE\'"
105+
exit 1
106+
;;
107+
esac
108+
}
109+
110+
if [[ "$NETIF_CREATE" = "yes" ]]; then
111+
create_netif
112+
fi
113+
79114
for i in $(eval echo {1..$NUM_NETIFS}); do
80115
ip link show dev ${NETIFS[p$i]} &> /dev/null
81116
if [[ $? -ne 0 ]]; then

0 commit comments

Comments
 (0)