Skip to content

Commit ffb8264

Browse files
committed
testenv: rework veth creating and config
Instead of creating the veth in the root namespace and then moving and renaming it, just create it directly in the target namespace with the right name from the beginning. This requires a bit of rework of the settings afterwards, but should hopefully fix any inconsistency issues such as the MAC address issue reported in #159. Signed-off-by: Toke Høiland-Jørgensen <toke@redhat.com>
1 parent 7e4abef commit ffb8264

1 file changed

Lines changed: 18 additions & 12 deletions

File tree

testenv/testenv.sh

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,15 @@ cleanup()
160160
iface_macaddr()
161161
{
162162
local iface="$1"
163-
ip -br link show dev "$iface" | awk '{print $3}'
163+
local ns="${2:-}"
164+
local output
165+
166+
if [ -n "$ns" ]; then
167+
output=$(ip -br -n "$ns" link show dev "$iface")
168+
else
169+
output=$(ip -br link show dev "$iface")
170+
fi
171+
echo "$output" | awk '{print $3}'
164172
}
165173

166174
set_sysctls()
@@ -215,27 +223,25 @@ setup()
215223
fi
216224

217225
ip netns add "$NS"
218-
ip link add dev "$NS" type veth peer name "$PEERNAME"
226+
ip link add dev "$NS" type veth peer name veth0 netns "$NS"
227+
219228
OUTSIDE_MAC=$(iface_macaddr "$NS")
220-
INSIDE_MAC=$(iface_macaddr "$PEERNAME")
221-
set_sysctls $NS
229+
INSIDE_MAC=$(iface_macaddr veth0 "$NS")
222230

223-
ethtool -K "$NS" rxvlan off txvlan off
224-
ethtool -K "$PEERNAME" rxvlan off txvlan off
225-
ip link set dev "$PEERNAME" netns "$NS"
231+
set_sysctls $NS
226232
ip link set dev "$NS" up
227233
ip addr add dev "$NS" "${OUTSIDE_IP6}/${IP6_PREFIX_SIZE}"
234+
ethtool -K "$NS" rxvlan off txvlan off
235+
# Prevent neighbour queries on the link
236+
ip neigh add "$INSIDE_IP6" lladdr "$INSIDE_MAC" dev "$NS" nud permanent
228237

229-
ip -n "$NS" link set dev "$PEERNAME" name veth0
238+
set_sysctls veth0 "$NS"
230239
ip -n "$NS" link set dev lo up
231240
ip -n "$NS" link set dev veth0 up
232-
set_sysctls veth0 "$NS"
233241
ip -n "$NS" addr add dev veth0 "${INSIDE_IP6}/${IP6_PREFIX_SIZE}"
234-
242+
ip netns exec "$NS" ethtool -K veth0 rxvlan off txvlan off
235243
# Prevent neighbour queries on the link
236-
ip neigh add "$INSIDE_IP6" lladdr "$INSIDE_MAC" dev "$NS" nud permanent
237244
ip -n "$NS" neigh add "$OUTSIDE_IP6" lladdr "$OUTSIDE_MAC" dev veth0 nud permanent
238-
239245
# Add route for whole test subnet, to make it easier to communicate between
240246
# namespaces
241247
ip -n "$NS" route add "${IP6_SUBNET}::/$IP6_FULL_PREFIX_SIZE" via "$OUTSIDE_IP6" dev veth0

0 commit comments

Comments
 (0)