[PATCH net-next 1/3] selftests: drv-net: resolve remote interface name

Jakub Kicinski
2025-02-13T00:35:01Z

Find out and record in env the name of the interface which remote host
will use for the IP address provided via config.

Interface name is useful for mausezahn and for setting up tunnels.

Signed-off-by: Jakub Kicinski <kuba@kernel.org>
---
tools/testing/selftests/drivers/net/lib/py/env.py | 13 +++++++++++++
1 file changed, 13 insertions(+)

diff --git a/tools/testing/selftests/drivers/net/lib/py/env.py b/tools/testing/selftests/drivers/net/lib/py/env.py
index 886b4904613c..fc649797230b 100644
--- a/tools/testing/selftests/drivers/net/lib/py/env.py
+++ b/tools/testing/selftests/drivers/net/lib/py/env.py
@@ -154,6 +154,9 @@ from .remote import Remote
self.ifname = self.dev['ifname']
self.ifindex = self.dev['ifindex']

+ # resolve remote interface name
+ self.remote_ifname = self.resolve_remote_ifc()
+
self._required_cmd = {}

def create_local(self):
@@ -200,6 +203,16 @@ from .remote import Remote
raise Exception("Invalid environment, missing configuration:", missing,
"Please see tools/testing/selftests/drivers/net/README.rst")

+ def resolve_remote_ifc(self):
+ v4 = v6 = None
+ if self.remote_v4:
+ v4 = ip("addr show to " + self.remote_v4, json=True, host=self.remote)
+ if self.remote_v6:
+ v6 = ip("addr show to " + self.remote_v6, json=True, host=self.remote)
+ if v4 and v6 and v4[0]["ifname"] != v6[0]["ifname"]:
+ raise Exception("Can't resolve remote interface name, v4 and v6 don't match")
+ return v6[0]["ifname"] if v6 else v4[0]["ifname"]
+
def __enter__(self):
return self

--
2.48.1