[PATCH net-next v3 3/3] selftests: net: add a test for the gtp netlink family

From: Anil Kaushik

Date: Fri Oct 09 2026 - 02:08:17 EST


Exercise the gtp generic netlink family through its ynl spec: create a
gtp device, add a PDP context with newpdp, check getpdp lists it and
delpdp removes it. Two more cases check that two contexts are dumped and
that deleting an unknown context fails.

Add a GtpFamily ynl wrapper and register the test.

Signed-off-by: Anil Kaushik <anilkaushikwireless@xxxxxxxxx>
---
MAINTAINERS | 1 +
tools/testing/selftests/net/Makefile | 1 +
tools/testing/selftests/net/config | 1 +
tools/testing/selftests/net/gtp.py | 85 +++++++++++++++++++
.../testing/selftests/net/lib/py/__init__.py | 5 +-
tools/testing/selftests/net/lib/py/ynl.py | 8 +-
6 files changed, 98 insertions(+), 3 deletions(-)
create mode 100755 tools/testing/selftests/net/gtp.py

diff --git a/MAINTAINERS b/MAINTAINERS
index a6e43995ea58..8ac817a78bb0 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -11423,6 +11423,7 @@ S: Maintained
T: git git://git.kernel.org/pub/scm/linux/kernel/git/pablo/gtp.git
F: Documentation/netlink/specs/gtp.yaml
F: drivers/net/gtp.c
+F: tools/testing/selftests/net/gtp.py

GUID PARTITION TABLE (GPT)
M: Davidlohr Bueso <dave@xxxxxxxxxxxx>
diff --git a/tools/testing/selftests/net/Makefile b/tools/testing/selftests/net/Makefile
index d4ca82fec0b4..6b54e04a6430 100644
--- a/tools/testing/selftests/net/Makefile
+++ b/tools/testing/selftests/net/Makefile
@@ -46,6 +46,7 @@ TEST_PROGS := \
fq_band_pktlimit.sh \
gre_gso.sh \
gre_ipv6_lladdr.sh \
+ gtp.py \
icmp.sh \
icmp_redirect.sh \
io_uring_zerocopy_tx.sh \
diff --git a/tools/testing/selftests/net/config b/tools/testing/selftests/net/config
index 737e7e6327b3..c4534e15fb7a 100644
--- a/tools/testing/selftests/net/config
+++ b/tools/testing/selftests/net/config
@@ -15,6 +15,7 @@ CONFIG_DEBUG_INFO_BTF=y
CONFIG_DEBUG_INFO_BTF_MODULES=n
CONFIG_DUMMY=y
CONFIG_GENEVE=m
+CONFIG_GTP=m
CONFIG_IFB=y
CONFIG_INET_DIAG=y
CONFIG_INET_ESP=y
diff --git a/tools/testing/selftests/net/gtp.py b/tools/testing/selftests/net/gtp.py
new file mode 100755
index 000000000000..fcc9bf57a663
--- /dev/null
+++ b/tools/testing/selftests/net/gtp.py
@@ -0,0 +1,85 @@
+#!/usr/bin/env python3
+# SPDX-License-Identifier: GPL-2.0
+
+"""Tests for the gtp netlink family."""
+
+from lib.py import ksft_run, ksft_exit
+from lib.py import ksft_eq, ksft_in, ksft_not_in, ksft_raises
+from lib.py import KsftSkipEx
+from lib.py import NetNS, NetNSEnter
+from lib.py import GtpFamily, NlError
+from lib.py import CmdExitFailure
+from lib.py import ip, defer
+
+
+def _add_gtp_dev(ns):
+ try:
+ ip("link add gtp0 type gtp role ggsn", ns=str(ns))
+ except CmdExitFailure:
+ raise KsftSkipEx("no gtp support (CONFIG_GTP, iproute2)")
+ defer(ip, "link del gtp0", ns=str(ns))
+ ip("link set gtp0 up", ns=str(ns))
+ return ip("-d link show gtp0", ns=str(ns), json=True)[0]["ifindex"]
+
+
+def _iteis(contexts):
+ return [c.get("i-tei") for c in contexts]
+
+
+def add_del_pdp(gtp, ns) -> None:
+ """Add a PDP context, query it, then delete it.
+
+ The query must return the context with the TEIDs and addresses
+ it was created with, and it must be gone after the delete.
+ """
+ link = _add_gtp_dev(ns)
+
+ gtp.newpdp({"link": link, "version": 1,
+ "i-tei": 0x100, "o-tei": 0x200,
+ "ms-address": "10.0.0.1", "peer-address": "192.0.2.1"})
+
+ pdp = [c for c in gtp.getpdp({}, dump=True) if c.get("i-tei") == 0x100]
+ ksft_eq(len(pdp), 1)
+ ksft_eq(pdp[0]["o-tei"], 0x200)
+ ksft_eq(pdp[0]["ms-address"], "10.0.0.1")
+ ksft_eq(pdp[0]["peer-address"], "192.0.2.1")
+
+ gtp.delpdp({"link": link, "version": 1,
+ "i-tei": 0x100, "ms-address": "10.0.0.1"})
+ ksft_not_in(0x100, _iteis(gtp.getpdp({}, dump=True)))
+
+
+def add_two_pdp(gtp, ns) -> None:
+ """Add two PDP contexts and check both are returned."""
+ link = _add_gtp_dev(ns)
+
+ for i_tei, o_tei, ms in ((0x111, 0x211, "10.0.1.1"),
+ (0x112, 0x212, "10.0.1.2")):
+ gtp.newpdp({"link": link, "version": 1,
+ "i-tei": i_tei, "o-tei": o_tei,
+ "ms-address": ms, "peer-address": "192.0.2.5"})
+
+ iteis = _iteis(gtp.getpdp({}, dump=True))
+ ksft_in(0x111, iteis)
+ ksft_in(0x112, iteis)
+
+
+def del_unknown_pdp(gtp, ns) -> None:
+ """Deleting a context that was never added must fail."""
+ link = _add_gtp_dev(ns)
+ with ksft_raises(NlError):
+ gtp.delpdp({"link": link, "version": 1,
+ "i-tei": 0x999, "ms-address": "10.9.9.9"})
+
+
+def main() -> None:
+ """Run the PDP context tests in a temporary netns."""
+ with NetNS() as ns:
+ with NetNSEnter(str(ns)):
+ gtp = GtpFamily()
+ ksft_run([add_del_pdp, add_two_pdp, del_unknown_pdp], args=(gtp, ns))
+ ksft_exit()
+
+
+if __name__ == "__main__":
+ main()
diff --git a/tools/testing/selftests/net/lib/py/__init__.py b/tools/testing/selftests/net/lib/py/__init__.py
index 71df5880b356..e269a260d58e 100644
--- a/tools/testing/selftests/net/lib/py/__init__.py
+++ b/tools/testing/selftests/net/lib/py/__init__.py
@@ -18,7 +18,7 @@ from .utils import CmdExitFailure, fd_read_timeout, cmd, bkg, defer, \
from .bpf import bpf_map_set, bpf_map_dump, bpf_prog_map_ids
from .ynl import NlError, NlctrlFamily, YnlFamily, \
EthtoolFamily, NetdevFamily, RtnlFamily, RtnlAddrFamily, RtnlRouteFamily
-from .ynl import NetshaperFamily, DevlinkFamily, PSPFamily, Netlink
+from .ynl import NetshaperFamily, DevlinkFamily, GtpFamily, PSPFamily, Netlink

__all__ = ["KSRC",
"KsftFailEx", "KsftSkipEx", "KsftXfailEx", "ksft_pr", "ksft_eq",
@@ -32,6 +32,7 @@ __all__ = ["KSRC",
"wait_port_listen", "ctl_file_write", "wait_file", "tool", "tc",
"bpf_map_set", "bpf_map_dump", "bpf_prog_map_ids",
"NetdevSim", "NetdevSimDev",
- "NetshaperFamily", "DevlinkFamily", "PSPFamily", "NlError",
+ "NetshaperFamily", "DevlinkFamily", "GtpFamily", "PSPFamily",
+ "NlError",
"YnlFamily", "EthtoolFamily", "NetdevFamily", "RtnlFamily",
"NlctrlFamily", "RtnlAddrFamily", "RtnlRouteFamily", "Netlink"]
diff --git a/tools/testing/selftests/net/lib/py/ynl.py b/tools/testing/selftests/net/lib/py/ynl.py
index 08deff756f29..7edb74971023 100644
--- a/tools/testing/selftests/net/lib/py/ynl.py
+++ b/tools/testing/selftests/net/lib/py/ynl.py
@@ -31,7 +31,7 @@ __all__ = [
"NlError", "NlPolicy", "Netlink", "YnlFamily", "SPEC_PATH",
"EthtoolFamily", "RtnlFamily", "RtnlAddrFamily", "RtnlRouteFamily",
"NetdevFamily", "NetshaperFamily", "NlctrlFamily", "DevlinkFamily",
- "PSPFamily",
+ "GtpFamily", "PSPFamily",
]

#
@@ -85,3 +85,9 @@ class PSPFamily(YnlFamily):
def __init__(self, recv_size=0):
super().__init__((SPEC_PATH / Path('psp.yaml')).as_posix(),
schema='', recv_size=recv_size)
+
+
+class GtpFamily(YnlFamily):
+ def __init__(self, recv_size=0):
+ super().__init__((SPEC_PATH / Path('gtp.yaml')).as_posix(),
+ schema='', recv_size=recv_size)
--
2.25.1