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