diff --git a/src/firewall/core/fw.py b/src/firewall/core/fw.py index c767f41..1df916e 100644 --- a/src/firewall/core/fw.py +++ b/src/firewall/core/fw.py @@ -76,10 +76,10 @@ class Firewall(object): else: self.ip4tables_backend = ipXtables.ip4tables(self) self.ip4tables_enabled = True - self.ip4tables_supported_icmp_types = [ ] + self.ipv4_supported_icmp_types = [ ] self.ip6tables_backend = ipXtables.ip6tables(self) self.ip6tables_enabled = True - self.ip6tables_supported_icmp_types = [ ] + self.ipv6_supported_icmp_types = [ ] self.ebtables_backend = ebtables.ebtables() self.ebtables_enabled = True self.ipset_backend = ipset.ipset() @@ -172,11 +172,13 @@ class Firewall(object): log.warning("iptables-restore and iptables are missing, " "disabling IPv4 firewall.") self.ip4tables_enabled = False - if self.ip4tables_enabled: - self.ip4tables_supported_icmp_types = \ - self.ip4tables_backend.supported_icmp_types() + if self.nftables_enabled: + self.ipv4_supported_icmp_types = self.nftables_backend.supported_icmp_types("ipv4") else: - self.ip4tables_supported_icmp_types = [ ] + if self.ip4tables_enabled: + self.ipv4_supported_icmp_types = self.ip4tables_backend.supported_icmp_types() + else: + self.ipv4_supported_icmp_types = [ ] self.ip6tables_backend.fill_exists() if not self.ip6tables_backend.restore_command_exists: if self.ip6tables_backend.command_exists: @@ -186,11 +188,13 @@ class Firewall(object): log.warning("ip6tables-restore and ip6tables are missing, " "disabling IPv6 firewall.") self.ip6tables_enabled = False - if self.ip6tables_enabled: - self.ip6tables_supported_icmp_types = \ - self.ip6tables_backend.supported_icmp_types() + if self.nftables_enabled: + self.ipv6_supported_icmp_types = self.nftables_backend.supported_icmp_types("ipv6") else: - self.ip6tables_supported_icmp_types = [ ] + if self.ip6tables_enabled: + self.ipv6_supported_icmp_types = self.ip6tables_backend.supported_icmp_types() + else: + self.ipv6_supported_icmp_types = [ ] self.ebtables_backend.fill_exists() if not self.ebtables_backend.restore_command_exists: if self.ebtables_backend.command_exists: diff --git a/src/firewall/core/fw_icmptype.py b/src/firewall/core/fw_icmptype.py index afe9f91..a565bb6 100644 --- a/src/firewall/core/fw_icmptype.py +++ b/src/firewall/core/fw_icmptype.py @@ -57,13 +57,13 @@ class FirewallIcmpType(object): ipvs = orig_ipvs[:] for ipv in orig_ipvs: if ipv == "ipv4": - if not self._fw.ip4tables_enabled: + if not self._fw.ip4tables_enabled and not self._fw.nftables_enabled: continue - supported_icmps = self._fw.ip4tables_supported_icmp_types + supported_icmps = self._fw.ipv4_supported_icmp_types elif ipv == "ipv6": - if not self._fw.ip6tables_enabled: + if not self._fw.ip6tables_enabled and not self._fw.nftables_enabled: continue - supported_icmps = self._fw.ip6tables_supported_icmp_types + supported_icmps = self._fw.ipv6_supported_icmp_types else: supported_icmps = [ ] if obj.name.lower() not in supported_icmps: diff --git a/src/firewall/core/ipXtables.py b/src/firewall/core/ipXtables.py index c4535f2..450e427 100644 --- a/src/firewall/core/ipXtables.py +++ b/src/firewall/core/ipXtables.py @@ -612,7 +612,7 @@ class ip4tables(object): rules.append(["-t", table, "-P", chain, _policy]) return rules - def supported_icmp_types(self): + def supported_icmp_types(self, ipv=None): """Return ICMP types that are supported by the iptables/ip6tables command and kernel""" ret = [ ] output = "" diff --git a/src/firewall/core/nftables.py b/src/firewall/core/nftables.py index daa7ace..0a73c2c 100644 --- a/src/firewall/core/nftables.py +++ b/src/firewall/core/nftables.py @@ -480,13 +480,13 @@ class nftables(object): return rules - def supported_icmp_types(self): + def supported_icmp_types(self, ipv=None): # nftables supports any icmp_type via arbitrary type/code matching. # We just need a translation for it in ICMP_TYPES_FRAGMENTS. supported = set() - for ipv in ICMP_TYPES_FRAGMENTS.keys(): - supported.update(ICMP_TYPES_FRAGMENTS[ipv].keys()) + for _ipv in [ipv] if ipv else ICMP_TYPES_FRAGMENTS.keys(): + supported.update(ICMP_TYPES_FRAGMENTS[_ipv].keys()) return list(supported) diff --git a/src/firewall/server/firewalld.py b/src/firewall/server/firewalld.py index 10b085d..949f577 100644 --- a/src/firewall/server/firewalld.py +++ b/src/firewall/server/firewalld.py @@ -162,7 +162,7 @@ class FirewallD(slip.dbus.service.Object): return dbus.Boolean(self.fw.ip4tables_enabled) elif prop == "IPv4ICMPTypes": - return dbus.Array(self.fw.ip4tables_supported_icmp_types, "s") + return dbus.Array(self.fw.ipv4_supported_icmp_types, "s") elif prop == "IPv6": return dbus.Boolean(self.fw.ip6tables_enabled) @@ -171,7 +171,7 @@ class FirewallD(slip.dbus.service.Object): return dbus.Boolean(self.fw.ipv6_rpfilter_enabled) elif prop == "IPv6ICMPTypes": - return dbus.Array(self.fw.ip6tables_supported_icmp_types, "s") + return dbus.Array(self.fw.ipv6_supported_icmp_types, "s") elif prop == "BRIDGE": return dbus.Boolean(self.fw.ebtables_enabled)