Blame SOURCES/0041-fix-rich-icmptypes-with-one-family.patch

725d6a
From 5acbdc31a56f4b680323ba7aa92383da9e9f25fa Mon Sep 17 00:00:00 2001
725d6a
From: Eric Garver <eric@garver.life>
725d6a
Date: Wed, 22 Jul 2020 09:18:42 -0400
725d6a
Subject: [PATCH 41/45] fix(rich): icmptypes with one family
725d6a
725d6a
They were mistakenly being added to both families which fails.
725d6a
725d6a
Fixes: rhbz 1855140
725d6a
(cherry picked from commit 0112e36c4e225504b15a1feef3d453a757a00b21)
725d6a
(cherry picked from commit bd61af7db6f92d48a79fb1e84405aef4f522ffbf)
725d6a
---
725d6a
 src/firewall/core/fw_zone.py  | 26 +++++++++++---------------
725d6a
 src/firewall/core/nftables.py |  2 +-
725d6a
 2 files changed, 12 insertions(+), 16 deletions(-)
725d6a
725d6a
diff --git a/src/firewall/core/fw_zone.py b/src/firewall/core/fw_zone.py
725d6a
index 5677effab146..b9fe1f6aae97 100644
725d6a
--- a/src/firewall/core/fw_zone.py
725d6a
+++ b/src/firewall/core/fw_zone.py
725d6a
@@ -1522,14 +1522,17 @@ class FirewallZone(object):
725d6a
                     transaction.add_rules(backend, rules)
725d6a
 
725d6a
     def _rule_prepare(self, enable, zone, rule, transaction):
725d6a
-        if rule.family is not None:
725d6a
+        ipvs = []
725d6a
+        if rule.family:
725d6a
             ipvs = [ rule.family ]
725d6a
-        else:
725d6a
-            ipvs = [ipv for ipv in ["ipv4", "ipv6"] if self._fw.is_ipv_enabled(ipv)]
725d6a
+        elif rule.element and (isinstance(rule.element, Rich_IcmpBlock) or isinstance(rule.element, Rich_IcmpType)):
725d6a
+            ict = self._fw.icmptype.get_icmptype(rule.element.name)
725d6a
+            if ict.destination:
725d6a
+                ipvs = [ipv for ipv in ["ipv4", "ipv6"] if ipv in ict.destination]
725d6a
 
725d6a
         source_ipv = self._rule_source_ipv(rule.source)
725d6a
-        if source_ipv is not None and source_ipv != "":
725d6a
-            if rule.family is not None:
725d6a
+        if source_ipv:
725d6a
+            if rule.family:
725d6a
                 # rule family is defined by user, no way to change it
725d6a
                 if rule.family != source_ipv:
725d6a
                     raise FirewallError(errors.INVALID_RULE,
725d6a
@@ -1538,6 +1541,9 @@ class FirewallZone(object):
725d6a
                 # use the source family as rule family
725d6a
                 ipvs = [ source_ipv ]
725d6a
 
725d6a
+        if not ipvs:
725d6a
+            ipvs = [ipv for ipv in ["ipv4", "ipv6"] if self._fw.is_ipv_enabled(ipv)]
725d6a
+
725d6a
         # add an element to object to allow backends to know what ipvs this applies to
725d6a
         rule.ipvs = ipvs
725d6a
 
725d6a
@@ -1699,16 +1705,6 @@ class FirewallZone(object):
725d6a
                     # icmp block might have reject or drop action, but not accept
725d6a
                     raise FirewallError(errors.INVALID_RULE,
725d6a
                                         "IcmpBlock not usable with accept action")
725d6a
-                if ict.destination:
725d6a
-                    for ipv in ipvs:
725d6a
-                        if ipv in ict.destination \
725d6a
-                           and not backend.is_ipv_supported(ipv):
725d6a
-                            raise FirewallError(
725d6a
-                                errors.INVALID_RULE,
725d6a
-                                "Icmp%s %s not usable with %s" % \
725d6a
-                                ("Block" if type(rule.element) == \
725d6a
-                                 Rich_IcmpBlock else "Type",
725d6a
-                                 rule.element.name, backend.name))
725d6a
 
725d6a
                 table = "filter"
725d6a
                 if enable:
725d6a
diff --git a/src/firewall/core/nftables.py b/src/firewall/core/nftables.py
725d6a
index 85c790b5b51e..0198200b2372 100644
725d6a
--- a/src/firewall/core/nftables.py
725d6a
+++ b/src/firewall/core/nftables.py
725d6a
@@ -1383,7 +1383,7 @@ class nftables(object):
725d6a
             return ICMP_TYPES_FRAGMENTS[ipv][icmp_type]
725d6a
         else:
725d6a
             raise FirewallError(INVALID_ICMPTYPE,
725d6a
-                                "ICMP type '%s' not supported by %s" % (icmp_type, self.name))
725d6a
+                                "ICMP type '%s' not supported by %s for %s" % (icmp_type, self.name, ipv))
725d6a
 
725d6a
     def build_zone_icmp_block_rules(self, enable, zone, ict, rich_rule=None):
725d6a
         table = "filter"
725d6a
-- 
725d6a
2.27.0
725d6a