Blame SOURCES/0059-fix-icmptype-nftables-runtimeToPermanent-if-ip6table.patch

00cd46
From 244d1bfe190f2cc32c10d0fecaf81536761ecc09 Mon Sep 17 00:00:00 2001
00cd46
From: Eric Garver <eric@garver.life>
00cd46
Date: Tue, 1 Sep 2020 13:16:23 -0400
00cd46
Subject: [PATCH 59/62] fix(icmptype): nftables: runtimeToPermanent if
00cd46
 ip6tables not available
00cd46
00cd46
We were not filling the runtime ipv6 icmptypes list if the active
00cd46
backend was nftables and ip6tables wasn't available. This caused "ipv6"
00cd46
to be dropped from the supported ipvs/destinations for the icmptype.
00cd46
This also caused runtimeToPermanent to fail because the runtime
00cd46
icmptypes definition dropped "ipv6" causing runtimeToPermanent to copy
00cd46
the runtime icmptype to permanent because they were different... this
00cd46
caused sanity checks on the permanent configuration to fail.
00cd46
00cd46
(cherry picked from commit c92d43dcdf5622e82e28454652acd6a981b015f9)
00cd46
(cherry picked from commit 6f23f727be818f356625e39682fb226a81925647)
00cd46
---
00cd46
 src/firewall/core/fw.py          | 24 ++++++++++++++----------
00cd46
 src/firewall/core/fw_icmptype.py |  8 ++++----
00cd46
 src/firewall/core/ipXtables.py   |  2 +-
00cd46
 src/firewall/core/nftables.py    |  6 +++---
00cd46
 src/firewall/server/firewalld.py |  4 ++--
00cd46
 5 files changed, 24 insertions(+), 20 deletions(-)
00cd46
00cd46
diff --git a/src/firewall/core/fw.py b/src/firewall/core/fw.py
00cd46
index c767f416f3d2..1df916efb10f 100644
00cd46
--- a/src/firewall/core/fw.py
00cd46
+++ b/src/firewall/core/fw.py
00cd46
@@ -76,10 +76,10 @@ class Firewall(object):
00cd46
         else:
00cd46
             self.ip4tables_backend = ipXtables.ip4tables(self)
00cd46
             self.ip4tables_enabled = True
00cd46
-            self.ip4tables_supported_icmp_types = [ ]
00cd46
+            self.ipv4_supported_icmp_types = [ ]
00cd46
             self.ip6tables_backend = ipXtables.ip6tables(self)
00cd46
             self.ip6tables_enabled = True
00cd46
-            self.ip6tables_supported_icmp_types = [ ]
00cd46
+            self.ipv6_supported_icmp_types = [ ]
00cd46
             self.ebtables_backend = ebtables.ebtables()
00cd46
             self.ebtables_enabled = True
00cd46
             self.ipset_backend = ipset.ipset()
00cd46
@@ -172,11 +172,13 @@ class Firewall(object):
00cd46
                 log.warning("iptables-restore and iptables are missing, "
00cd46
                             "disabling IPv4 firewall.")
00cd46
                 self.ip4tables_enabled = False
00cd46
-        if self.ip4tables_enabled:
00cd46
-            self.ip4tables_supported_icmp_types = \
00cd46
-                self.ip4tables_backend.supported_icmp_types()
00cd46
+        if self.nftables_enabled:
00cd46
+            self.ipv4_supported_icmp_types = self.nftables_backend.supported_icmp_types("ipv4")
00cd46
         else:
00cd46
-            self.ip4tables_supported_icmp_types = [ ]
00cd46
+            if self.ip4tables_enabled:
00cd46
+                self.ipv4_supported_icmp_types = self.ip4tables_backend.supported_icmp_types()
00cd46
+            else:
00cd46
+                self.ipv4_supported_icmp_types = [ ]
00cd46
         self.ip6tables_backend.fill_exists()
00cd46
         if not self.ip6tables_backend.restore_command_exists:
00cd46
             if self.ip6tables_backend.command_exists:
00cd46
@@ -186,11 +188,13 @@ class Firewall(object):
00cd46
                 log.warning("ip6tables-restore and ip6tables are missing, "
00cd46
                             "disabling IPv6 firewall.")
00cd46
                 self.ip6tables_enabled = False
00cd46
-        if self.ip6tables_enabled:
00cd46
-            self.ip6tables_supported_icmp_types = \
00cd46
-                self.ip6tables_backend.supported_icmp_types()
00cd46
+        if self.nftables_enabled:
00cd46
+            self.ipv6_supported_icmp_types = self.nftables_backend.supported_icmp_types("ipv6")
00cd46
         else:
00cd46
-            self.ip6tables_supported_icmp_types = [ ]
00cd46
+            if self.ip6tables_enabled:
00cd46
+                self.ipv6_supported_icmp_types = self.ip6tables_backend.supported_icmp_types()
00cd46
+            else:
00cd46
+                self.ipv6_supported_icmp_types = [ ]
00cd46
         self.ebtables_backend.fill_exists()
00cd46
         if not self.ebtables_backend.restore_command_exists:
00cd46
             if self.ebtables_backend.command_exists:
00cd46
diff --git a/src/firewall/core/fw_icmptype.py b/src/firewall/core/fw_icmptype.py
00cd46
index afe9f91d6bf6..a565bb6d8733 100644
00cd46
--- a/src/firewall/core/fw_icmptype.py
00cd46
+++ b/src/firewall/core/fw_icmptype.py
00cd46
@@ -57,13 +57,13 @@ class FirewallIcmpType(object):
00cd46
         ipvs = orig_ipvs[:]
00cd46
         for ipv in orig_ipvs:
00cd46
             if ipv == "ipv4":
00cd46
-                if not self._fw.ip4tables_enabled:
00cd46
+                if not self._fw.ip4tables_enabled and not self._fw.nftables_enabled:
00cd46
                     continue
00cd46
-                supported_icmps = self._fw.ip4tables_supported_icmp_types
00cd46
+                supported_icmps = self._fw.ipv4_supported_icmp_types
00cd46
             elif ipv == "ipv6":
00cd46
-                if not self._fw.ip6tables_enabled:
00cd46
+                if not self._fw.ip6tables_enabled and not self._fw.nftables_enabled:
00cd46
                     continue
00cd46
-                supported_icmps = self._fw.ip6tables_supported_icmp_types
00cd46
+                supported_icmps = self._fw.ipv6_supported_icmp_types
00cd46
             else:
00cd46
                 supported_icmps = [ ]
00cd46
             if obj.name.lower() not in supported_icmps:
00cd46
diff --git a/src/firewall/core/ipXtables.py b/src/firewall/core/ipXtables.py
00cd46
index c4535f2e5818..450e427c08b5 100644
00cd46
--- a/src/firewall/core/ipXtables.py
00cd46
+++ b/src/firewall/core/ipXtables.py
00cd46
@@ -612,7 +612,7 @@ class ip4tables(object):
00cd46
                 rules.append(["-t", table, "-P", chain, _policy])
00cd46
         return rules
00cd46
 
00cd46
-    def supported_icmp_types(self):
00cd46
+    def supported_icmp_types(self, ipv=None):
00cd46
         """Return ICMP types that are supported by the iptables/ip6tables command and kernel"""
00cd46
         ret = [ ]
00cd46
         output = ""
00cd46
diff --git a/src/firewall/core/nftables.py b/src/firewall/core/nftables.py
00cd46
index daa7ace085a2..0a73c2c2669d 100644
00cd46
--- a/src/firewall/core/nftables.py
00cd46
+++ b/src/firewall/core/nftables.py
00cd46
@@ -480,13 +480,13 @@ class nftables(object):
00cd46
 
00cd46
         return rules
00cd46
 
00cd46
-    def supported_icmp_types(self):
00cd46
+    def supported_icmp_types(self, ipv=None):
00cd46
         # nftables supports any icmp_type via arbitrary type/code matching.
00cd46
         # We just need a translation for it in ICMP_TYPES_FRAGMENTS.
00cd46
         supported = set()
00cd46
 
00cd46
-        for ipv in ICMP_TYPES_FRAGMENTS.keys():
00cd46
-            supported.update(ICMP_TYPES_FRAGMENTS[ipv].keys())
00cd46
+        for _ipv in [ipv] if ipv else ICMP_TYPES_FRAGMENTS.keys():
00cd46
+            supported.update(ICMP_TYPES_FRAGMENTS[_ipv].keys())
00cd46
 
00cd46
         return list(supported)
00cd46
 
00cd46
diff --git a/src/firewall/server/firewalld.py b/src/firewall/server/firewalld.py
00cd46
index 10b085d48660..949f577053cc 100644
00cd46
--- a/src/firewall/server/firewalld.py
00cd46
+++ b/src/firewall/server/firewalld.py
00cd46
@@ -162,7 +162,7 @@ class FirewallD(slip.dbus.service.Object):
00cd46
             return dbus.Boolean(self.fw.ip4tables_enabled)
00cd46
 
00cd46
         elif prop == "IPv4ICMPTypes":
00cd46
-            return dbus.Array(self.fw.ip4tables_supported_icmp_types, "s")
00cd46
+            return dbus.Array(self.fw.ipv4_supported_icmp_types, "s")
00cd46
 
00cd46
         elif prop == "IPv6":
00cd46
             return dbus.Boolean(self.fw.ip6tables_enabled)
00cd46
@@ -171,7 +171,7 @@ class FirewallD(slip.dbus.service.Object):
00cd46
             return dbus.Boolean(self.fw.ipv6_rpfilter_enabled)
00cd46
 
00cd46
         elif prop == "IPv6ICMPTypes":
00cd46
-            return dbus.Array(self.fw.ip6tables_supported_icmp_types, "s")
00cd46
+            return dbus.Array(self.fw.ipv6_supported_icmp_types, "s")
00cd46
 
00cd46
         elif prop == "BRIDGE":
00cd46
             return dbus.Boolean(self.fw.ebtables_enabled)
00cd46
-- 
00cd46
2.28.0
00cd46