Commit 51458e10 authored by Aaron Conole's avatar Aaron Conole Committed by Jakub Kicinski

selftests: openvswitch: Support implicit ipv6 arguments.

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: default avatarSimon Horman <horms@kernel.org>
Tested-by: default avatarSimon Horman <horms@kernel.org>
Signed-off-by: default avatarAaron Conole <aconole@redhat.com>
Link: https://patch.msgid.link/20240625172245.233874-6-aconole@redhat.comSigned-off-by: default avatarJakub Kicinski <kuba@kernel.org>
parent fefe3b7d
...@@ -200,6 +200,18 @@ def convert_ipv4(data): ...@@ -200,6 +200,18 @@ def convert_ipv4(data):
return int(ipaddress.IPv4Address(ip)), int(ipaddress.IPv4Address(mask)) 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(size):
def convert_int_sized(data): def convert_int_sized(data):
value, _, mask = data.partition('/') value, _, mask = data.partition('/')
...@@ -941,21 +953,21 @@ class ovskey(nla): ...@@ -941,21 +953,21 @@ class ovskey(nla):
"src", "src",
"src", "src",
lambda x: str(ipaddress.IPv6Address(x)), lambda x: str(ipaddress.IPv6Address(x)),
lambda x: int.from_bytes(x, "big"), lambda x: ipaddress.IPv6Address(x).packed if x else 0,
lambda x: ipaddress.IPv6Address(x), convert_ipv6,
), ),
( (
"dst", "dst",
"dst", "dst",
lambda x: str(ipaddress.IPv6Address(x)), lambda x: str(ipaddress.IPv6Address(x)),
lambda x: int.from_bytes(x, "big"), lambda x: ipaddress.IPv6Address(x).packed if x else 0,
lambda x: ipaddress.IPv6Address(x), convert_ipv6,
), ),
("label", "label", "%d", int), ("label", "label", "%d", lambda x: int(x) if x else 0),
("proto", "proto", "%d", int), ("proto", "proto", "%d", lambda x: int(x) if x else 0),
("tclass", "tclass", "%d", int), ("tclass", "tclass", "%d", lambda x: int(x) if x else 0),
("hlimit", "hlimit", "%d", int), ("hlimit", "hlimit", "%d", lambda x: int(x) if x else 0),
("frag", "frag", "%d", int), ("frag", "frag", "%d", lambda x: int(x) if x else 0),
) )
def __init__( def __init__(
...@@ -1153,7 +1165,7 @@ class ovskey(nla): ...@@ -1153,7 +1165,7 @@ class ovskey(nla):
"target", "target",
"target", "target",
lambda x: str(ipaddress.IPv6Address(x)), lambda x: str(ipaddress.IPv6Address(x)),
lambda x: int.from_bytes(x, "big"), convert_ipv6,
), ),
("sll", "sll", macstr, lambda x: int.from_bytes(x, "big")), ("sll", "sll", macstr, lambda x: int.from_bytes(x, "big")),
("tll", "tll", macstr, lambda x: int.from_bytes(x, "big")), ("tll", "tll", macstr, lambda x: int.from_bytes(x, "big")),
...@@ -1238,13 +1250,13 @@ class ovskey(nla): ...@@ -1238,13 +1250,13 @@ class ovskey(nla):
"src", "src",
"src", "src",
lambda x: str(ipaddress.IPv6Address(x)), lambda x: str(ipaddress.IPv6Address(x)),
lambda x: int.from_bytes(x, "big", convertmac), convert_ipv6,
), ),
( (
"dst", "dst",
"dst", "dst",
lambda x: str(ipaddress.IPv6Address(x)), lambda x: str(ipaddress.IPv6Address(x)),
lambda x: int.from_bytes(x, "big"), convert_ipv6,
), ),
("tp_src", "tp_src", "%d", int), ("tp_src", "tp_src", "%d", int),
("tp_dst", "tp_dst", "%d", int), ("tp_dst", "tp_dst", "%d", int),
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment