Skip to content

Commit 99ea3c6

Browse files
rjarrychristophefontaine
authored andcommitted
smoke: add helper to create ports
Introduce the port_add() helper function to centralize port creation logic. The helper generates a deterministic MAC address from the port name using md5sum and assigns it to the Linux tap interface. By default, net_tap ports have the same MAC address on both the grout side and the Linux side. This causes Linux to wrongfully assume packets sent by grout originated locally, which breaks bridging and MAC learning. Assign a different locally administered MAC address to the Linux side to avoid this issue. Replace all inline port creation calls across smoke tests with calls to this helper. Signed-off-by: Robin Jarry <rjarry@redhat.com> Reviewed-by: Christophe Fontaine <cfontain@redhat.com>
1 parent 72cc512 commit 99ea3c6

22 files changed

Lines changed: 48 additions & 62 deletions

smoke/_init.sh

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,19 @@ trap cleanup EXIT
102102
builddir=${1-}
103103
run_id="$(base32 -w6 < /dev/urandom | tr '[:upper:]' '[:lower:]' | head -n1)-" || :
104104

105+
tap_counter=0
106+
port_add() {
107+
local name="$1"
108+
shift
109+
grcli interface add port "$name" devargs "net_tap$tap_counter,iface=$name" "$@"
110+
# Ensure the Linux net device has a different mac address from grout's.
111+
# This is required to avoid Linux from wrongfully assuming the packets
112+
# sent by grout originated locally.
113+
local mac=$(echo "$name" | md5sum | sed -E 's/(..)(..)(..)(..)(..).*/02:\1:\2:\3:\4:\5/')
114+
ip link set "$name" address "$mac"
115+
tap_counter=$((tap_counter + 1))
116+
}
117+
105118
if [ "$run_grout" = true ]; then
106119
export GROUT_SOCK_PATH=$tmp/grout.sock
107120
fi

smoke/_init_frr.sh

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,26 +5,22 @@ test_frr=true
55

66
. $(dirname $0)/_init.sh
77

8-
tap_index=0
98
create_interface() {
109
local p="$1"
1110
local mac="$2"
1211
local vrf="${3:-0}"
13-
14-
grcli interface add port $p devargs net_tap$tap_index,iface=$p vrf $vrf mac $mac
15-
1612
local max_tries=5
1713
local count=0
14+
15+
port_add $p vrf $vrf mac $mac
16+
1817
while vtysh -c "show interface $p" 2>&1 | grep -q "% Can't find interface"; do
1918
if [ "$count" -ge "$max_tries" ]; then
20-
echo "Interface $p not found after $max_tries attempts."
21-
exit 1
19+
fail "Interface $p not found after $max_tries attempts."
2220
fi
2321
sleep 0.2
2422
count=$((count + 1))
2523
done
26-
27-
tap_index=$((tap_index + 1))
2824
}
2925

3026
set_ip_address() {

smoke/cross_vrf_forward_frr_test.sh

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ for n in 0 1; do
1414
p=$run_id$n
1515
netns_add n-$p
1616
ip link set $p netns n-$p
17-
ip -n n-$p link set $p address ba:d0:ca:ca:00:0$n
1817
ip -n n-$p link set $p up
1918
ip -n n-$p link set lo up
2019
ip -n n-$p addr add 172.16.$n.2/24 dev $p

smoke/cross_vrf_forward_test.sh

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@
77
p0=${run_id}0
88
p1=${run_id}1
99

10-
grcli interface add port $p0 devargs net_tap0,iface=$p0 vrf 1 mac f0:0d:ac:dc:01:00
11-
grcli interface add port $p1 devargs net_tap1,iface=$p1 vrf 2 mac f0:0d:ac:dc:01:01
10+
port_add $p0 vrf 1 mac f0:0d:ac:dc:01:00
11+
port_add $p1 vrf 2 mac f0:0d:ac:dc:01:01
1212
grcli address add 172.16.0.1/24 iface $p0
1313
grcli address add 172.16.1.1/24 iface $p1
1414

@@ -26,7 +26,6 @@ for n in 0 1; do
2626
p=$run_id$n
2727
netns_add $p
2828
ip link set $p netns $p
29-
ip -n $p link set $p address ba:d0:ca:ca:01:0$n
3029
ip -n $p link set $p up
3130
ip -n $p addr add 172.16.$n.2/24 dev $p
3231
ip -n $p addr add 16.$n.0.1/16 dev lo

smoke/dnat44_test.sh

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@
77
p0=${run_id}0
88
p1=${run_id}1
99

10-
grcli interface add port $p0 devargs net_tap0,iface=$p0 mac f0:0d:ac:dc:00:00
11-
grcli interface add port $p1 devargs net_tap1,iface=$p1 mac f0:0d:ac:dc:00:01
10+
port_add $p0 mac f0:0d:ac:dc:00:00
11+
port_add $p1 mac f0:0d:ac:dc:00:01
1212
grcli address add 172.16.0.1/24 iface $p0
1313
grcli address add 10.99.0.1/24 iface $p1
1414
grcli dnat44 add interface $p0 destination 172.16.0.99 replace 10.99.0.99
@@ -19,7 +19,6 @@ for n in 0 1; do
1919
p=$run_id$n
2020
netns_add $p
2121
ip link set $p netns $p
22-
ip -n $p link set $p address ba:d0:ca:ca:00:0$n
2322
ip -n $p link set $p up
2423
ip -n $p link set lo up
2524
done

smoke/ip6_builtin_icmp_test.sh

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,16 +7,15 @@
77
p0=${run_id}0
88
p1=${run_id}1
99

10-
grcli interface add port $p0 devargs net_tap0,iface=$p0 mac f0:0d:ac:dc:13:00
11-
grcli interface add port $p1 devargs net_tap1,iface=$p1 mac f0:0d:ac:dc:13:01
10+
port_add $p0 mac f0:0d:ac:dc:13:00
11+
port_add $p1 mac f0:0d:ac:dc:13:01
1212
grcli address add fd00:ba4:0::1/64 iface $p0
1313
grcli address add fd00:ba4:1::1/64 iface $p1
1414

1515
for n in 0 1; do
1616
p=$run_id$n
1717
netns_add $p
1818
ip link set $p netns $p
19-
ip -n $p link set $p address ba:d0:ca:cd:00:0$n
2019
ip -n $p link set $p up
2120
ip -n $p addr add fd00:ba4:$n::2/64 dev $p
2221
ip -n $p route add fd00:ba4::/62 via fd00:ba4:$n::1 dev $p

smoke/ip6_forward_frr_test.sh

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ for n in 1 2; do
1414
p=$run_id$n
1515
netns_add n-$p
1616
ip link set $p netns n-$p
17-
ip -n n-$p link set $p address d2:ad:ca:ca:a4:1$n
1817
ip -n n-$p link set $p up
1918
ip -n n-$p link set lo up
2019
ip -n n-$p addr add fd00:ba4:$n::2/64 dev $p

smoke/ip6_forward_test.sh

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@
77
p1=${run_id}1
88
p2=${run_id}2
99

10-
grcli interface add port $p1 devargs net_tap0,iface=$p1 mac d2:f0:0c:ba:a4:11
11-
grcli interface add port $p2 devargs net_tap1,iface=$p2 mac d2:f0:0c:ba:a4:12
10+
port_add $p1 mac d2:f0:0c:ba:a4:11
11+
port_add $p2 mac d2:f0:0c:ba:a4:12
1212
grcli address add fd00:ba4:1::1/64 iface $p1
1313
grcli address add fd00:ba4:2::1/64 iface $p2
1414
grcli route add fd00:f00:1::/64 via fd00:ba4:1::2
@@ -19,7 +19,6 @@ for n in 1 2; do
1919
p=$run_id$n
2020
netns_add $p
2121
ip link set $p netns $p
22-
ip -n $p link set $p address d2:ad:ca:ca:a4:1$n
2322
ip -n $p link set $p up
2423
ip -n $p link set lo up
2524
ip -n $p addr add fd00:ba4:$n::2/64 dev $p

smoke/ip6_rs_ra_test.sh

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,13 @@ command -v rdisc6 || fail "rdisc6 (from ndisc6 package) is not installed"
88

99
p1=${run_id}1
1010

11-
grcli interface add port $p1 devargs net_tap0,iface=$p1 mac d2:f0:0c:ba:a4:11
11+
port_add $p1 mac d2:f0:0c:ba:a4:11
1212
grcli address add fd00:ba4:1::1/64 iface $p1
1313

1414
for n in 1; do
1515
p=$run_id$n
1616
netns_add $p
1717
ip link set $p netns $p
18-
ip -n $p link set $p address d2:ad:ca:ca:a4:1$n
1918
ip -n $p link set $p up
2019
ip -n $p addr add fd00:ba4:$n::2/64 dev $p
2120
ip -n $p addr show

smoke/ip6_same_peer_test.sh

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@
77
p1=${run_id}1
88
p2=${run_id}2
99

10-
grcli interface add port $p1 devargs net_tap0,iface=$p1 mac d2:f0:0c:ba:a4:11
11-
grcli interface add port $p2 devargs net_tap1,iface=$p2 mac d2:f0:0c:ba:a4:12
10+
port_add $p1 mac d2:f0:0c:ba:a4:11
11+
port_add $p2 mac d2:f0:0c:ba:a4:12
1212

1313
grcli address add fd00:ba4:1::1/64 iface $p1
1414
grcli address add fd00:ba4:2::1/64 iface $p2
@@ -17,7 +17,6 @@ for n in 1 2; do
1717
p=$run_id$n
1818
netns_add $p
1919
ip link set $p netns $p
20-
ip -n $p link set $p address d2:ad:ca:ca:a4:1
2120
ip -n $p link set $p up
2221
ip -n $p addr add fd00:ba4:$n::2/64 dev $p
2322
# ip -n $p addr add fe80::beef:2/64 dev $p

0 commit comments

Comments
 (0)