|
2 | 2 | # tbv-rdma-addr <ifname> -- assign the deterministic per-link routable /64 to a |
3 | 3 | # usb4_rdma GID-only rail netdev, so both ends of a cabled link share a subnet. |
4 | 4 | # Invoked from udev (RUN+=) after the rail netdev appears, and safe to re-run by |
5 | | -# hand. Pure derivation lives in tbv-rdma-addr-lib.sh; this only does the sysfs |
| 5 | +# hand. Pure derivation lives in tbv-rdma-addr-lib.sh; this does the sysfs |
6 | 6 | # lookups and the `ip` assignment. |
7 | 7 | # |
8 | 8 | # The rail netdev is parented (SET_NETDEV_DEV) to its XDomain *device* (e.g. |
9 | 9 | # "0-1"), whose unique_id is the remote peer's host-router UUID. The local |
10 | 10 | # host-router UUID is "<domain>-0" in the same thunderbolt domain. Both ends |
11 | 11 | # therefore hold the same unordered UUID pair -> the same /64 (see the lib). |
| 12 | +# |
| 13 | +# udev renames the netdev (u4r<N> -> tbr-<peer>) BEFORE running RUN+=, so the |
| 14 | +# passed kernel name is stale by the time we run. We therefore resolve the live |
| 15 | +# interface from the stable XDomain parent device (via DEVPATH), not the name. |
12 | 16 | set -eu |
| 17 | +export PATH=/usr/sbin:/usr/bin:/sbin:/bin:${PATH:-} |
13 | 18 |
|
14 | 19 | LIB="$(dirname "$0")/tbv-rdma-addr-lib.sh" |
15 | 20 | [ -r "$LIB" ] || LIB=/usr/lib/thunderbolt-ibverbs/tbv-rdma-addr-lib.sh |
16 | 21 | . "$LIB" |
17 | 22 |
|
18 | 23 | ifc="${1:-}" |
19 | | -[ -n "$ifc" ] || exit 0 |
20 | | - |
21 | | -# Resolve the netdev's parent device, tolerating a concurrent udev rename: prefer |
22 | | -# the passed name, fall back to udev's DEVPATH for this uevent. |
23 | | -dev="$(readlink -f "/sys/class/net/${ifc}/device" 2>/dev/null || true)" |
24 | | -if [ -z "${dev}" ] && [ -n "${DEVPATH:-}" ]; then |
25 | | - dev="$(readlink -f "/sys${DEVPATH}/device" 2>/dev/null || true)" |
| 24 | +xdev="" |
| 25 | +# Prefer the passed name if it still resolves; else recover the XDomain parent |
| 26 | +# from DEVPATH (stable across the rename) and read the live name back out of it. |
| 27 | +if [ -n "$ifc" ] && [ -e "/sys/class/net/${ifc}/device" ]; then |
| 28 | + xdev="$(readlink -f "/sys/class/net/${ifc}/device" 2>/dev/null || true)" |
| 29 | +elif [ -n "${DEVPATH:-}" ]; then |
| 30 | + xdev="$(readlink -f "/sys${DEVPATH%/net/*}" 2>/dev/null || true)" |
| 31 | + [ -n "$xdev" ] && ifc="$(ls "${xdev}/net" 2>/dev/null | head -n1)" |
26 | 32 | fi |
27 | | -[ -n "${dev}" ] || exit 0 |
| 33 | +[ -n "$xdev" ] && [ -n "$ifc" ] && [ -e "/sys/class/net/${ifc}" ] || exit 0 |
28 | 34 |
|
29 | | -remote="$(cat "${dev}/unique_id" 2>/dev/null || true)" |
30 | | -[ -n "${remote}" ] || exit 0 # not an XDomain-parented rail |
| 35 | +remote="$(cat "${xdev}/unique_id" 2>/dev/null || true)" |
| 36 | +[ -n "$remote" ] || exit 0 # not an XDomain-parented rail |
31 | 37 |
|
32 | | -xname="$(basename "${dev}")" # e.g. 0-1 |
33 | | -domain="${xname%%-*}" # e.g. 0 |
| 38 | +domain="$(basename "$xdev")"; domain="${domain%%-*}" |
34 | 39 | local="$(cat "/sys/bus/thunderbolt/devices/${domain}-0/unique_id" 2>/dev/null || true)" |
35 | | -[ -n "${local}" ] || exit 0 |
| 40 | +[ -n "$local" ] || exit 0 |
36 | 41 |
|
37 | | -addr="$(tbv_link_addr "${local}" "${remote}")" |
| 42 | +addr="$(tbv_link_addr "$local" "$remote")" |
38 | 43 |
|
39 | 44 | # nodad: link-local DAD is pointless on a point-to-point GID-only netdev and only |
40 | 45 | # adds latency before the GID appears. `replace` keeps the helper idempotent. |
41 | | -ip -6 addr replace "${addr}" dev "${ifc}" nodad 2>/dev/null || \ |
42 | | - ip -6 addr replace "${addr}" dev "${ifc}" |
43 | | -ip link set "${ifc}" up |
| 46 | +ip -6 addr replace "$addr" dev "$ifc" nodad 2>/dev/null || \ |
| 47 | + ip -6 addr replace "$addr" dev "$ifc" |
| 48 | +ip link set "$ifc" up |
0 commit comments