diff mbox series

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

Message ID 20250213003454.1333711-2-kuba@kernel.org (mailing list archive)
State Superseded
Delegated to: Netdev Maintainers
Headers show
Series selftests: drv-net: add a simple TSO test | expand

Checks

Context Check Description
netdev/series_format success Posting correctly formatted
netdev/tree_selection success Clearly marked for net-next
netdev/ynl success Generated files up to date; no warnings/errors; no diff in generated;
netdev/fixes_present success Fixes tag not required for -next series
netdev/header_inline success No static functions without inline keyword in header files
netdev/build_32bit success Errors and warnings before: 0 this patch: 0
netdev/build_tools success Errors and warnings before: 26 (+1) this patch: 26 (+1)
netdev/cc_maintainers warning 1 maintainers not CCed: linux-kselftest@vger.kernel.org
netdev/build_clang success Errors and warnings before: 0 this patch: 0
netdev/verify_signedoff success Signed-off-by tag matches author and committer
netdev/deprecated_api success None detected
netdev/check_selftest success No net selftest shell script
netdev/verify_fixes success No Fixes tag
netdev/build_allmodconfig_warn success Errors and warnings before: 0 this patch: 0
netdev/checkpatch success total: 0 errors, 0 warnings, 0 checks, 25 lines checked
netdev/build_clang_rust success No Rust files in patch. Skipping build
netdev/kdoc success Errors and warnings before: 0 this patch: 0
netdev/source_inline success Was 0 now: 0
netdev/contest fail net-next-2025-02-13--03-00 (tests: 889)

Commit Message

Jakub Kicinski Feb. 13, 2025, 12:34 a.m. UTC
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(+)

Comments

Petr Machata Feb. 13, 2025, 2:31 p.m. UTC | #1
Jakub Kicinski <kuba@kernel.org> writes:

> 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"]

Is existence of more than one interface with the same IP address a
concern? I guess such configuration is broken and wouldn't come up in a
selftest, but consider throwing in an "len(v4) == len(v6) == 1" for
robustness sake. I guess it could in fact replace the "v4 and v6" bit.

> +
>      def __enter__(self):
>          return self
Jakub Kicinski Feb. 13, 2025, 3:55 p.m. UTC | #2
On Thu, 13 Feb 2025 15:31:57 +0100 Petr Machata wrote:
> > +    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"]  
> 
> Is existence of more than one interface with the same IP address a
> concern? I guess such configuration is broken and wouldn't come up in a
> selftest, but consider throwing in an "len(v4) == len(v6) == 1" for
> robustness sake. 

Will do!

> I guess it could in fact replace the "v4 and v6" bit.

Hm, I think that bit has to stay, we only record one interface.
So if v4 and v6 given to the test are on different interfaces
there could be some confusion. Not that we currently validate
the same thing for the local machine..
Petr Machata Feb. 13, 2025, 4:23 p.m. UTC | #3
Jakub Kicinski <kuba@kernel.org> writes:

> On Thu, 13 Feb 2025 15:31:57 +0100 Petr Machata wrote:
>> > +    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"]  
>> 
>> Is existence of more than one interface with the same IP address a
>> concern? I guess such configuration is broken and wouldn't come up in a
>> selftest, but consider throwing in an "len(v4) == len(v6) == 1" for
>> robustness sake. 
>
> Will do!
>
>> I guess it could in fact replace the "v4 and v6" bit.
>
> Hm, I think that bit has to stay, we only record one interface.
> So if v4 and v6 given to the test are on different interfaces
> there could be some confusion. Not that we currently validate
> the same thing for the local machine..

Yeah, I misread the code actually. The goal is, if we have results for
both IPv4 and IPv6, do some extra validation. So the "v4 and v6" part
has to stay. (Plus I forgot that both start out as None, so you can't
just len() them willy nilly anyway.)

I think it should be this or thereabouts?

        if v4 and v6 and (not(len(v4) == len(v6) == 1) or
                          v4[0]["ifname"] != v6[0]["ifname"]):
            raise Exception("Can't resolve remote interface name, v4 and v6 don't match")
diff mbox series

Patch

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