xref: /linux/tools/testing/selftests/rdma/rxe_test_NETDEV_UNREGISTER.sh (revision ab868c10971c5d2cd27b3709d11225941eabe78e)
1#!/bin/bash
2
3# Configuration
4DEV_NAME="tun0"
5RXE_NAME="rxe0"
6RDMA_PORT=4791
7
8source "$(dirname "$0")/../kselftest/ktap_helpers.sh"
9
10exec > /dev/null
11
12# --- Cleanup Routine ---
13# Ensures environment is clean even if the script hits an error
14cleanup() {
15    echo "Performing cleanup..."
16    rdma link del $RXE_NAME 2>/dev/null
17    ip link del $DEV_NAME 2>/dev/null
18    modprobe -r rdma_rxe 2>/dev/null
19}
20trap cleanup EXIT
21
22# 1. Dependency Check
23if ! modinfo rdma_rxe >/dev/null 2>&1; then
24    echo "SKIP: rdma_rxe module not found." >&2
25    exit $KSFT_SKIP
26fi
27
28modprobe rdma_rxe
29
30# 2. Setup TUN Device
31echo "Creating $DEV_NAME..."
32ip tuntap add mode tun "$DEV_NAME"
33ip addr add 1.1.1.1/24 dev "$DEV_NAME"
34ip link set "$DEV_NAME" up
35
36# 3. Attach RXE Link
37echo "Attaching RXE link $RXE_NAME to $DEV_NAME..."
38rdma link add "$RXE_NAME" type rxe netdev "$DEV_NAME"
39
40# 4. Verification: Port Check
41# Use -H (no header) and -q (quiet) for cleaner scripting logic
42if ! ss -Huln sport == :$RDMA_PORT | grep -q ":$RDMA_PORT"; then
43    echo "Error: UDP port $RDMA_PORT is not listening."
44    exit 1
45fi
46echo "Verified: RXE is listening on UDP $RDMA_PORT."
47
48# 5. Trigger NETDEV_UNREGISTER
49# We delete the underlying device without deleting the RDMA link first.
50echo "Triggering NETDEV_UNREGISTER by deleting $DEV_NAME..."
51ip link del "$DEV_NAME"
52
53# 6. Final Verification
54# The RXE link and the UDP port should be automatically cleaned up by the kernel.
55if rdma link show "$RXE_NAME" 2>/dev/null; then
56    echo "Error: $RXE_NAME still exists after netdev removal."
57    exit 1
58fi
59
60if ss -Huln sport == :$RDMA_PORT | grep -q ":$RDMA_PORT"; then
61    echo "Error: UDP port $RDMA_PORT still listening after netdev removal."
62    exit 1
63fi
64
65echo "Success: NETDEV_UNREGISTER handled correctly."
66