[RFC net-next 4/6] selftests: net: add tx_extra_headroom test

From: David Keogh

Date: Thu Oct 15 2026 - 19:58:12 EST


Exercise the IFLA_TX_EXTRA_HEADROOM attribute through YNL: the default
of zero, setting values up to the maximum and back to zero, rejection
of a value above the maximum, supplying the attribute at link creation,
the change notification, persistence across link down/up and across a
network namespace move, and that a VLAN created on top of a configured
device does not inherit the setting.

Signed-off-by: David Keogh <dkeogh@xxxxxxxxxx>
---
tools/testing/selftests/net/Makefile | 1 +
.../selftests/net/tx_extra_headroom.py | 137 ++++++++++++++++++
2 files changed, 138 insertions(+)
create mode 100755 tools/testing/selftests/net/tx_extra_headroom.py

diff --git a/tools/testing/selftests/net/Makefile b/tools/testing/selftests/net/Makefile
index 54beea2e3..0eb9a69e9 100644
--- a/tools/testing/selftests/net/Makefile
+++ b/tools/testing/selftests/net/Makefile
@@ -120,6 +120,7 @@ TEST_PROGS := \
test_vxlan_vnifiltering.sh \
tfo_passive.sh \
traceroute.sh \
+ tx_extra_headroom.py \
txtimestamp.sh \
udpgro.sh \
udpgro_bench.sh \
diff --git a/tools/testing/selftests/net/tx_extra_headroom.py b/tools/testing/selftests/net/tx_extra_headroom.py
new file mode 100755
index 000000000..f6f087e98
--- /dev/null
+++ b/tools/testing/selftests/net/tx_extra_headroom.py
@@ -0,0 +1,137 @@
+#!/usr/bin/env python3
+# SPDX-License-Identifier: GPL-2.0
+
+"""Tests for the IFLA_TX_EXTRA_HEADROOM link attribute."""
+
+from lib.py import ksft_run, ksft_exit, ksft_eq, ksft_raises, ksft_true
+from lib.py import ip
+from lib.py import NetNS, NetNSEnter
+from lib.py import Netlink, NlError, RtnlFamily
+
+ATTR = "tx-extra-headroom"
+MAX = 512
+
+
+def ifindex(name):
+ return ip(f"link show dev {name}", json=True)[0]["ifindex"]
+
+
+def get(rtnl, idx):
+ return rtnl.getlink({"ifi-index": idx})[ATTR]
+
+
+def set_(rtnl, idx, val):
+ rtnl.setlink({"ifi-index": idx, ATTR: val})
+
+
+def test_default_and_set() -> None:
+ """Default is 0, values up to the maximum are accepted, 0 resets."""
+ with NetNS() as ns, NetNSEnter(str(ns)):
+ ip("link add d0 type dummy")
+ rtnl = RtnlFamily()
+ idx = ifindex("d0")
+
+ ksft_eq(get(rtnl, idx), 0)
+ for val in (1, 256, MAX):
+ set_(rtnl, idx, val)
+ ksft_eq(get(rtnl, idx), val)
+ set_(rtnl, idx, 0)
+ ksft_eq(get(rtnl, idx), 0)
+
+
+def test_reject_above_max() -> None:
+ """Values above the maximum are rejected by the policy."""
+ with NetNS() as ns, NetNSEnter(str(ns)):
+ ip("link add d0 type dummy")
+ rtnl = RtnlFamily()
+ idx = ifindex("d0")
+
+ set_(rtnl, idx, 128)
+ with ksft_raises(NlError):
+ set_(rtnl, idx, MAX + 1)
+ ksft_eq(get(rtnl, idx), 128)
+
+
+def test_newlink() -> None:
+ """The attribute can be supplied when the link is created."""
+ with NetNS() as ns, NetNSEnter(str(ns)):
+ rtnl = RtnlFamily()
+ rtnl.newlink({"ifname": "d0", "linkinfo": {"kind": "dummy"},
+ ATTR: 64},
+ flags=[Netlink.NLM_F_CREATE, Netlink.NLM_F_EXCL])
+ ksft_eq(get(rtnl, ifindex("d0")), 64)
+
+
+def test_notification() -> None:
+ """A change produces a link notification carrying the new value."""
+ with NetNS() as ns, NetNSEnter(str(ns)):
+ ip("link add d0 type dummy")
+ ip("link set dev d0 up")
+ rtnl = RtnlFamily()
+ idx = ifindex("d0")
+
+ rtnl.ntf_subscribe("rtnlgrp-link")
+ set_(rtnl, idx, 192)
+
+ seen = None
+ for msg in rtnl.poll_ntf(duration=1):
+ if msg["name"] == "getlink" and msg["msg"]["ifi-index"] == idx:
+ seen = msg["msg"][ATTR]
+ break
+ ksft_eq(seen, 192)
+
+
+def test_survives_down_up() -> None:
+ """Toggling the link does not reset the value."""
+ with NetNS() as ns, NetNSEnter(str(ns)):
+ ip("link add d0 type dummy")
+ rtnl = RtnlFamily()
+ idx = ifindex("d0")
+
+ set_(rtnl, idx, 96)
+ ip("link set dev d0 up")
+ ksft_eq(get(rtnl, idx), 96)
+ ip("link set dev d0 down")
+ ksft_eq(get(rtnl, idx), 96)
+
+
+def test_survives_netns_move() -> None:
+ """Moving the link to another namespace keeps the value."""
+ with NetNS() as ns1, NetNS() as ns2:
+ with NetNSEnter(str(ns1)):
+ ip("link add d0 type dummy")
+ rtnl = RtnlFamily()
+ set_(rtnl, ifindex("d0"), 160)
+ ip(f"link set dev d0 netns {ns2}")
+
+ with NetNSEnter(str(ns2)):
+ rtnl = RtnlFamily()
+ ksft_eq(get(rtnl, ifindex("d0")), 160)
+
+
+def test_not_inherited() -> None:
+ """Stacked devices do not inherit the value of the device below."""
+ with NetNS() as ns, NetNSEnter(str(ns)):
+ ip("link add d0 type dummy")
+ rtnl = RtnlFamily()
+ set_(rtnl, ifindex("d0"), 224)
+
+ ip("link add link d0 name d0.10 type vlan id 10")
+ ksft_eq(get(rtnl, ifindex("d0.10")), 0)
+ ksft_true(rtnl.getlink({"ifi-index": ifindex("d0.10")})["headroom"]
+ >= 4, "vlan needed_headroom")
+
+
+def main() -> None:
+ ksft_run([test_default_and_set,
+ test_reject_above_max,
+ test_newlink,
+ test_notification,
+ test_survives_down_up,
+ test_survives_netns_move,
+ test_not_inherited])
+ ksft_exit()
+
+
+if __name__ == "__main__":
+ main()
--
2.50.1