xref: /linux/tools/testing/selftests/rdma/rxe_ipv6.sh (revision 513480da5e9c8f55b4f8f5e89f386e26188fbb3f)
1#!/bin/bash
2
3# Configuration
4NS_NAME="net6"
5VETH_HOST="veth0"
6VETH_NS="veth1"
7RXE_NAME="rxe6"
8PORT=4791
9IP6_ADDR="2001:db8::1/64"
10
11source "$(dirname "$0")/../kselftest/ktap_helpers.sh"
12
13exec > /dev/null
14
15# Cleanup function to run on exit (even on failure)
16cleanup() {
17    ip netns del "$NS_NAME" 2>/dev/null
18    modprobe -r rdma_rxe 2>/dev/null
19    echo "Done."
20}
21trap cleanup EXIT
22
23# 1. Prerequisites check
24for mod in tun veth rdma_rxe; do
25    if ! modinfo "$mod" >/dev/null 2>&1; then
26        echo "SKIP: Kernel module '$mod' not found." >&2
27        exit $KSFT_SKIP
28    fi
29done
30
31modprobe rdma_rxe
32
33# 2. Setup Namespace and Networking
34echo "Setting up IPv6 network namespace..."
35ip netns add "$NS_NAME"
36ip link add "$VETH_HOST" type veth peer name "$VETH_NS"
37ip link set "$VETH_NS" netns "$NS_NAME"
38ip netns exec "$NS_NAME" ip addr add "$IP6_ADDR" dev "$VETH_NS"
39ip netns exec "$NS_NAME" ip link set "$VETH_NS" up
40ip link set "$VETH_HOST" up
41
42# 3. Add RDMA Link
43echo "Adding RDMA RXE link..."
44if ! ip netns exec "$NS_NAME" rdma link add "$RXE_NAME" type rxe netdev "$VETH_NS"; then
45    echo "Error: Failed to create RXE link."
46    exit 1
47fi
48
49# 4. Verification: Port should be listening
50# Using -H to skip headers and -q for quiet exit codes
51if ! ip netns exec "$NS_NAME" ss -Hul6n sport = :$PORT | grep -q ":$PORT"; then
52    echo "Error: UDP port $PORT is NOT listening after link creation."
53    exit 1
54fi
55echo "Verified: Port $PORT is active."
56
57# 5. Removal and Verification
58echo "Deleting RDMA link..."
59ip netns exec "$NS_NAME" rdma link del "$RXE_NAME"
60
61if ip netns exec "$NS_NAME" ss -Hul6n sport = :$PORT | grep -q ":$PORT"; then
62    echo "Error: UDP port $PORT still active after link deletion."
63    exit 1
64fi
65echo "Verified: Port $PORT closed successfully."
66