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

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