Skip to content

Commit

Permalink
improvement(ipXtables): make parsing of icmp-types testable
Browse files Browse the repository at this point in the history
  • Loading branch information
thom311 authored and erig0 committed Dec 4, 2023
1 parent 506b7b1 commit c3e15e6
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions src/firewall/core/ipXtables.py
Original file line number Diff line number Diff line change
Expand Up @@ -689,7 +689,6 @@ def build_set_policy_rules(self, policy):

def supported_icmp_types(self, ipv=None):
"""Return ICMP types that are supported by the iptables/ip6tables command and kernel"""
ret = []
output = ""
try:
output = self.__run(
Expand All @@ -700,11 +699,14 @@ def supported_icmp_types(self, ipv=None):
log.debug1("iptables error: %s" % ex)
else:
log.debug1("ip6tables error: %s" % ex)
lines = output.splitlines()

return self._parse_supported_icmp_types(self.ipv, output)

@staticmethod
def _parse_supported_icmp_types(ipv, output):
in_types = False
for line in lines:
# print(line)
ret = []
for line in output.splitlines():
if in_types:
line = line.strip().lower()
splits = line.split()
Expand All @@ -716,9 +718,9 @@ def supported_icmp_types(self, ipv=None):
if x not in ret:
ret.append(x)
if (
self.ipv == "ipv4"
ipv == "ipv4"
and line.startswith("Valid ICMP Types:")
or self.ipv == "ipv6"
or ipv == "ipv6"
and line.startswith("Valid ICMPv6 Types:")
):
in_types = True
Expand Down

0 comments on commit c3e15e6

Please sign in to comment.