From 0769a49eae43e726f6822e4a26204fc92d962f29 Mon Sep 17 00:00:00 2001 From: Brad House Date: Thu, 8 Oct 2026 02:03:40 +0000 Subject: [PATCH 1/4] Use meta l4proto for IPv6 protocol-number ACL rules Match IPv6 ACL rules given by protocol number with "meta l4proto", the expression nft itself uses for tcp, udp and icmpv6 rules, so that every IPv6 ACL rule identifies the protocol the same way. Signed-off-by: Brad House --- systemvm/debian/opt/cloud/bin/configure.py | 2 +- systemvm/test/TestCsAclIpv6.py | 63 ++++++++++++++++++++++ 2 files changed, 64 insertions(+), 1 deletion(-) create mode 100644 systemvm/test/TestCsAclIpv6.py diff --git a/systemvm/debian/opt/cloud/bin/configure.py b/systemvm/debian/opt/cloud/bin/configure.py index bf48be66694c..21568818f9f4 100755 --- a/systemvm/debian/opt/cloud/bin/configure.py +++ b/systemvm/debian/opt/cloud/bin/configure.py @@ -527,7 +527,7 @@ def __process_ip6(self, direction, rule_list): if protocol != "all": icmp_type = "" if protocol == "protocol": - protocol = "ip6 nexthdr %d" % rule['protocol'] + protocol = "meta l4proto %d" % rule['protocol'] proto = protocol if proto == "icmp": proto = proto_str = "icmpv6" diff --git a/systemvm/test/TestCsAclIpv6.py b/systemvm/test/TestCsAclIpv6.py new file mode 100644 index 000000000000..9d5ef100fbb2 --- /dev/null +++ b/systemvm/test/TestCsAclIpv6.py @@ -0,0 +1,63 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +import unittest +from configure import CsAcl + + +class FakeConfig: + + def __init__(self): + self.fw = [] + self.ipv6_acl = [] + self.nft_ipv4_acl = [] + + def get_fw(self): + return self.fw + + def get_ipv6_acl(self): + return self.ipv6_acl + + def get_nft_ipv4_acl(self): + return self.nft_ipv4_acl + + def is_vpc(self): + return True + + def is_routed(self): + return True + + +class TestCsAclIpv6(unittest.TestCase): + + def test_protocol_number_rule_uses_meta_l4proto(self): + config = FakeConfig() + obj = {"device": "eth3", "nic_ip": "10.1.1.1", "nic_netmask": "24", "nic_ip6_cidr": "fd00:1::/64", + "ingress_rules": [{"type": "protocol", "protocol": 47, "cidr": "2001:db8::/64", "allowed": False}], + "egress_rules": [{"type": "protocol", "protocol": 50, "cidr": "2001:db8:1::/64", "allowed": True}]} + acl = CsAcl.AclDevice(obj, config) + acl.create() + + # matched the way nft matches tcp, udp and icmpv6 rules + ingress = [r['rule'] for r in config.ipv6_acl if r.get('chain') == "eth3_ingress_policy" and 'rule' in r] + self.assertIn("ip6 saddr 2001:db8::/64 meta l4proto 47 drop", ingress) + egress = [r['rule'] for r in config.ipv6_acl if r.get('chain') == "eth3_egress_policy" and 'rule' in r] + self.assertIn("ip6 daddr 2001:db8:1::/64 meta l4proto 50 accept", egress) + + +if __name__ == '__main__': + unittest.main() From 6ff859e12f9abdd53fefea5dec48ef8906592438 Mon Sep 17 00:00:00 2001 From: Brad House Date: Thu, 8 Oct 2026 10:59:06 +0000 Subject: [PATCH 2/4] Match IPv6 extension header protocol numbers as extension headers An ACL rule given by the protocol number of an IPv6 extension header (0, 43, 44, 60, 135) is rendered as nft's "exthdr exists" for that header, rather than as an upper-layer protocol. Signed-off-by: Brad House --- systemvm/debian/opt/cloud/bin/configure.py | 13 ++++++++++++- systemvm/test/TestCsAclIpv6.py | 12 ++++++++++++ 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/systemvm/debian/opt/cloud/bin/configure.py b/systemvm/debian/opt/cloud/bin/configure.py index 21568818f9f4..8fe4e9db621f 100755 --- a/systemvm/debian/opt/cloud/bin/configure.py +++ b/systemvm/debian/opt/cloud/bin/configure.py @@ -81,6 +81,17 @@ def appendStringIfNotEmpty(s1, s2): return s1 +# nft names of the IPv6 extension headers, which can also be given as an ACL protocol number +IP6_EXTHDR_NAMES = {0: "hbh", 43: "rt", 44: "frag", 60: "dst", 135: "mh"} + + +def ip6ProtocolMatch(number): + """ An extension header number is matched as that extension header, any other as the protocol """ + if number in IP6_EXTHDR_NAMES: + return "exthdr %s exists" % IP6_EXTHDR_NAMES[number] + return "meta l4proto %d" % number + + class CsPassword(CsDataBag): TOKEN_FILE = "/tmp/passwdsrvrtoken" @@ -527,7 +538,7 @@ def __process_ip6(self, direction, rule_list): if protocol != "all": icmp_type = "" if protocol == "protocol": - protocol = "meta l4proto %d" % rule['protocol'] + protocol = ip6ProtocolMatch(rule['protocol']) proto = protocol if proto == "icmp": proto = proto_str = "icmpv6" diff --git a/systemvm/test/TestCsAclIpv6.py b/systemvm/test/TestCsAclIpv6.py index 9d5ef100fbb2..c51204a5c4a0 100644 --- a/systemvm/test/TestCsAclIpv6.py +++ b/systemvm/test/TestCsAclIpv6.py @@ -58,6 +58,18 @@ def test_protocol_number_rule_uses_meta_l4proto(self): egress = [r['rule'] for r in config.ipv6_acl if r.get('chain') == "eth3_egress_policy" and 'rule' in r] self.assertIn("ip6 daddr 2001:db8:1::/64 meta l4proto 50 accept", egress) + def test_extension_header_number_rule(self): + config = FakeConfig() + rules = [{"type": "protocol", "protocol": p, "cidr": "2001:db8::/64", "allowed": False} for p in (0, 43, 44, 60, 135)] + obj = {"device": "eth3", "nic_ip": "10.1.1.1", "nic_netmask": "24", "nic_ip6_cidr": "fd00:1::/64", + "ingress_rules": rules, "egress_rules": []} + acl = CsAcl.AclDevice(obj, config) + acl.create() + + ingress = [r['rule'] for r in config.ipv6_acl if r.get('chain') == "eth3_ingress_policy" and 'rule' in r] + for name in ("hbh", "rt", "frag", "dst", "mh"): + self.assertIn("ip6 saddr 2001:db8::/64 exthdr %s exists drop" % name, ingress) + if __name__ == '__main__': unittest.main() From fe2724ef97eacac2c9811f6c35bbf1bd87c05eaa Mon Sep 17 00:00:00 2001 From: Brad House Date: Thu, 8 Oct 2026 12:21:25 +0000 Subject: [PATCH 3/4] Test that upper-layer protocol numbers are matched with meta l4proto Signed-off-by: Brad House --- systemvm/test/TestCsAclIpv6.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/systemvm/test/TestCsAclIpv6.py b/systemvm/test/TestCsAclIpv6.py index c51204a5c4a0..d6f6b5dc3fe5 100644 --- a/systemvm/test/TestCsAclIpv6.py +++ b/systemvm/test/TestCsAclIpv6.py @@ -58,6 +58,18 @@ def test_protocol_number_rule_uses_meta_l4proto(self): egress = [r['rule'] for r in config.ipv6_acl if r.get('chain') == "eth3_egress_policy" and 'rule' in r] self.assertIn("ip6 daddr 2001:db8:1::/64 meta l4proto 50 accept", egress) + def test_upper_layer_protocol_numbers_use_meta_l4proto(self): + config = FakeConfig() + rules = [{"type": "protocol", "protocol": p, "cidr": "2001:db8::/64", "allowed": True} for p in (6, 17, 58, 132)] + obj = {"device": "eth3", "nic_ip": "10.1.1.1", "nic_netmask": "24", "nic_ip6_cidr": "fd00:1::/64", + "ingress_rules": rules, "egress_rules": []} + acl = CsAcl.AclDevice(obj, config) + acl.create() + + ingress = [r['rule'] for r in config.ipv6_acl if r.get('chain') == "eth3_ingress_policy" and 'rule' in r] + for p in (6, 17, 58, 132): + self.assertIn("ip6 saddr 2001:db8::/64 meta l4proto %d accept" % p, ingress) + def test_extension_header_number_rule(self): config = FakeConfig() rules = [{"type": "protocol", "protocol": p, "cidr": "2001:db8::/64", "allowed": False} for p in (0, 43, 44, 60, 135)] From b1e0fd652629b2db590b59234aa1c4203cf56ddc Mon Sep 17 00:00:00 2001 From: Brad House Date: Thu, 8 Oct 2026 12:44:22 +0000 Subject: [PATCH 4/4] Test that protocol 51 is matched with meta l4proto Signed-off-by: Brad House --- systemvm/test/TestCsAclIpv6.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/systemvm/test/TestCsAclIpv6.py b/systemvm/test/TestCsAclIpv6.py index d6f6b5dc3fe5..21b17a044eab 100644 --- a/systemvm/test/TestCsAclIpv6.py +++ b/systemvm/test/TestCsAclIpv6.py @@ -60,14 +60,14 @@ def test_protocol_number_rule_uses_meta_l4proto(self): def test_upper_layer_protocol_numbers_use_meta_l4proto(self): config = FakeConfig() - rules = [{"type": "protocol", "protocol": p, "cidr": "2001:db8::/64", "allowed": True} for p in (6, 17, 58, 132)] + rules = [{"type": "protocol", "protocol": p, "cidr": "2001:db8::/64", "allowed": True} for p in (6, 17, 51, 58, 132)] obj = {"device": "eth3", "nic_ip": "10.1.1.1", "nic_netmask": "24", "nic_ip6_cidr": "fd00:1::/64", "ingress_rules": rules, "egress_rules": []} acl = CsAcl.AclDevice(obj, config) acl.create() ingress = [r['rule'] for r in config.ipv6_acl if r.get('chain') == "eth3_ingress_policy" and 'rule' in r] - for p in (6, 17, 58, 132): + for p in (6, 17, 51, 58, 132): self.assertIn("ip6 saddr 2001:db8::/64 meta l4proto %d accept" % p, ingress) def test_extension_header_number_rule(self):