diff mbox series

[net-next,5/7] selftests: openvswitch: Support implicit ipv6 arguments.

Message ID 20240617180218.1154326-6-aconole@redhat.com (mailing list archive)
State Superseded
Delegated to: Netdev Maintainers
Headers show
Series selftests: net: Switch pmtu.sh to use the internal ovs script. | 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: 8 this patch: 8
netdev/build_tools success Errors and warnings before: 0 this patch: 0
netdev/cc_maintainers success CCed 8 of 8 maintainers
netdev/build_clang success Errors and warnings before: 8 this patch: 8
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: 8 this patch: 8
netdev/checkpatch success total: 0 errors, 0 warnings, 0 checks, 76 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 success net-next-2024-06-18--12-00 (tests: 654)

Commit Message

Aaron Conole June 17, 2024, 6:02 p.m. UTC
The current iteration of IPv6 support requires explicit fields to be set
in addition to not properly support the actual IPv6 addresses properly.
With this change, make it so that the ipv6() bare option is usable to
create wildcarded flows to match broad swaths of ipv6 traffic.

Reviewed-by: Simon Horman <horms@kernel.org>
Tested-by: Simon Horman <horms@kernel.org>
Signed-off-by: Aaron Conole <aconole@redhat.com>
---
 .../selftests/net/openvswitch/ovs-dpctl.py    | 42 ++++++++++++-------
 1 file changed, 27 insertions(+), 15 deletions(-)

Comments

Aaron Conole June 18, 2024, 4:04 p.m. UTC | #1
Aaron Conole <aconole@redhat.com> writes:

> The current iteration of IPv6 support requires explicit fields to be set
> in addition to not properly support the actual IPv6 addresses properly.
> With this change, make it so that the ipv6() bare option is usable to
> create wildcarded flows to match broad swaths of ipv6 traffic.
>
> Reviewed-by: Simon Horman <horms@kernel.org>
> Tested-by: Simon Horman <horms@kernel.org>
> Signed-off-by: Aaron Conole <aconole@redhat.com>
> ---
>  .../selftests/net/openvswitch/ovs-dpctl.py    | 42 ++++++++++++-------
>  1 file changed, 27 insertions(+), 15 deletions(-)
>
> diff --git a/tools/testing/selftests/net/openvswitch/ovs-dpctl.py b/tools/testing/selftests/net/openvswitch/ovs-dpctl.py
> index 2f16df2fb16b..2062e7e6e99e 100644
> --- a/tools/testing/selftests/net/openvswitch/ovs-dpctl.py
> +++ b/tools/testing/selftests/net/openvswitch/ovs-dpctl.py
> @@ -200,6 +200,18 @@ def convert_ipv4(data):
>  
>      return int(ipaddress.IPv4Address(ip)), int(ipaddress.IPv4Address(mask))
>  
> +def convert_ipv6(data):
> +    ip, _, mask = data.partition('/')
> +
> +    if not ip:
> +        ip = mask = 0
> +    elif not mask:
> +        mask = 'ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff'
> +    elif mask.isdigit():
> +        mask = ipaddress.IPv6Network("::/" + mask).hostmask
> +
> +    return ipaddress.IPv6Address(ip).packed, ipaddress.IPv6Address(mask).packed
> +
>  def convert_int(size):
>      def convert_int_sized(data):
>          value, _, mask = data.partition('/')
> @@ -941,21 +953,21 @@ class ovskey(nla):
>                  "src",
>                  "src",
>                  lambda x: str(ipaddress.IPv6Address(x)),
> -                lambda x: int.from_bytes(x, "big"),
> -                lambda x: ipaddress.IPv6Address(x),
> +                lambda x: ipaddress.IPv6Address(x).packed if x else 0,
> +                convert_ipv6,
>              ),
>              (
>                  "dst",
>                  "dst",
>                  lambda x: str(ipaddress.IPv6Address(x)),
> -                lambda x: int.from_bytes(x, "big"),
> -                lambda x: ipaddress.IPv6Address(x),
> +                lambda x: ipaddress.IPv6Address(x).packed if x else 0,
> +                convert_ipv6,
>              ),
> -            ("label", "label", "%d", int),
> -            ("proto", "proto", "%d", int),
> -            ("tclass", "tclass", "%d", int),
> -            ("hlimit", "hlimit", "%d", int),
> -            ("frag", "frag", "%d", int),
> +            ("label", "label", "%d", lambda x: int(x) if x else 0),
> +            ("proto", "proto", "%d", lambda x: int(x) if x else 0),
> +            ("tclass", "tclass", "%d", lambda x: int(x) if x else 0),
> +            ("hlimit", "hlimit", "%d", lambda x: int(x) if x else 0),
> +            ("frag", "frag", "%d", lambda x: int(x) if x else 0),
>          )
>  
>          def __init__(
> @@ -1152,8 +1164,8 @@ class ovskey(nla):
>              (
>                  "target",
>                  "target",
> -                lambda x: str(ipaddress.IPv6Address(x)),
> -                lambda x: int.from_bytes(x, "big"),
> +                lambda x: ipaddress.IPv6Address(x).packed,

This (and the following str() calls) shouldn't have been changed.  I'll
send a v2.  Sorry about the noise.  It isn't visible in this test, but
when doing some additional ipv6 test development for a future series, I
caught it.

> +                convert_ipv6,
>              ),
>              ("sll", "sll", macstr, lambda x: int.from_bytes(x, "big")),
>              ("tll", "tll", macstr, lambda x: int.from_bytes(x, "big")),
> @@ -1237,14 +1249,14 @@ class ovskey(nla):
>              (
>                  "src",
>                  "src",
> -                lambda x: str(ipaddress.IPv6Address(x)),
> -                lambda x: int.from_bytes(x, "big", convertmac),
> +                lambda x: ipaddress.IPv6Address(x).packed,
> +                convert_ipv6,
>              ),
>              (
>                  "dst",
>                  "dst",
> -                lambda x: str(ipaddress.IPv6Address(x)),
> -                lambda x: int.from_bytes(x, "big"),
> +                lambda x: ipaddress.IPv6Address(x).packed,
> +                convert_ipv6,
>              ),
>              ("tp_src", "tp_src", "%d", int),
>              ("tp_dst", "tp_dst", "%d", int),
diff mbox series

Patch

diff --git a/tools/testing/selftests/net/openvswitch/ovs-dpctl.py b/tools/testing/selftests/net/openvswitch/ovs-dpctl.py
index 2f16df2fb16b..2062e7e6e99e 100644
--- a/tools/testing/selftests/net/openvswitch/ovs-dpctl.py
+++ b/tools/testing/selftests/net/openvswitch/ovs-dpctl.py
@@ -200,6 +200,18 @@  def convert_ipv4(data):
 
     return int(ipaddress.IPv4Address(ip)), int(ipaddress.IPv4Address(mask))
 
+def convert_ipv6(data):
+    ip, _, mask = data.partition('/')
+
+    if not ip:
+        ip = mask = 0
+    elif not mask:
+        mask = 'ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff'
+    elif mask.isdigit():
+        mask = ipaddress.IPv6Network("::/" + mask).hostmask
+
+    return ipaddress.IPv6Address(ip).packed, ipaddress.IPv6Address(mask).packed
+
 def convert_int(size):
     def convert_int_sized(data):
         value, _, mask = data.partition('/')
@@ -941,21 +953,21 @@  class ovskey(nla):
                 "src",
                 "src",
                 lambda x: str(ipaddress.IPv6Address(x)),
-                lambda x: int.from_bytes(x, "big"),
-                lambda x: ipaddress.IPv6Address(x),
+                lambda x: ipaddress.IPv6Address(x).packed if x else 0,
+                convert_ipv6,
             ),
             (
                 "dst",
                 "dst",
                 lambda x: str(ipaddress.IPv6Address(x)),
-                lambda x: int.from_bytes(x, "big"),
-                lambda x: ipaddress.IPv6Address(x),
+                lambda x: ipaddress.IPv6Address(x).packed if x else 0,
+                convert_ipv6,
             ),
-            ("label", "label", "%d", int),
-            ("proto", "proto", "%d", int),
-            ("tclass", "tclass", "%d", int),
-            ("hlimit", "hlimit", "%d", int),
-            ("frag", "frag", "%d", int),
+            ("label", "label", "%d", lambda x: int(x) if x else 0),
+            ("proto", "proto", "%d", lambda x: int(x) if x else 0),
+            ("tclass", "tclass", "%d", lambda x: int(x) if x else 0),
+            ("hlimit", "hlimit", "%d", lambda x: int(x) if x else 0),
+            ("frag", "frag", "%d", lambda x: int(x) if x else 0),
         )
 
         def __init__(
@@ -1152,8 +1164,8 @@  class ovskey(nla):
             (
                 "target",
                 "target",
-                lambda x: str(ipaddress.IPv6Address(x)),
-                lambda x: int.from_bytes(x, "big"),
+                lambda x: ipaddress.IPv6Address(x).packed,
+                convert_ipv6,
             ),
             ("sll", "sll", macstr, lambda x: int.from_bytes(x, "big")),
             ("tll", "tll", macstr, lambda x: int.from_bytes(x, "big")),
@@ -1237,14 +1249,14 @@  class ovskey(nla):
             (
                 "src",
                 "src",
-                lambda x: str(ipaddress.IPv6Address(x)),
-                lambda x: int.from_bytes(x, "big", convertmac),
+                lambda x: ipaddress.IPv6Address(x).packed,
+                convert_ipv6,
             ),
             (
                 "dst",
                 "dst",
-                lambda x: str(ipaddress.IPv6Address(x)),
-                lambda x: int.from_bytes(x, "big"),
+                lambda x: ipaddress.IPv6Address(x).packed,
+                convert_ipv6,
             ),
             ("tp_src", "tp_src", "%d", int),
             ("tp_dst", "tp_dst", "%d", int),