136e2c
From b40b19e1de852aee5b1a53a26c8fb0e3e00b6a71 Mon Sep 17 00:00:00 2001
136e2c
From: Eric Garver <eric@garver.life>
136e2c
Date: Fri, 20 Sep 2019 09:48:07 -0400
136e2c
Subject: [PATCH 105/109] fix: service: usage of helpers with '-' in name
136e2c
136e2c
Fixes: 8c65bda2a750 ("fix: allow custom helpers using standard helper modules")
136e2c
(cherry picked from commit 28f3e6a83167ca2798157fd6e2c752b296c72830)
136e2c
(cherry picked from commit 98e77f8fb8fd6e72e71eb1267ea5ccbc0563cb83)
136e2c
---
136e2c
 src/firewall/core/fw_zone.py | 6 +++---
136e2c
 src/firewall/functions.py    | 6 ++++--
136e2c
 2 files changed, 7 insertions(+), 5 deletions(-)
136e2c
136e2c
diff --git a/src/firewall/core/fw_zone.py b/src/firewall/core/fw_zone.py
136e2c
index c096e3efe028..e7be779ebc8c 100644
136e2c
--- a/src/firewall/core/fw_zone.py
136e2c
+++ b/src/firewall/core/fw_zone.py
136e2c
@@ -25,7 +25,7 @@ from firewall.core.base import SHORTCUTS, DEFAULT_ZONE_TARGET, \
136e2c
 from firewall.core.logger import log
136e2c
 from firewall.functions import portStr, checkIPnMask, checkIP6nMask, \
136e2c
     checkProtocol, enable_ip_forwarding, check_single_address, check_mac, \
136e2c
-    portInPortRange
136e2c
+    portInPortRange, get_nf_conntrack_short_name
136e2c
 from firewall.core.rich import Rich_Rule, Rich_Accept, \
136e2c
     Rich_Mark, Rich_Service, Rich_Port, Rich_Protocol, \
136e2c
     Rich_Masquerade, Rich_ForwardPort, Rich_SourcePort, Rich_IcmpBlock, \
136e2c
@@ -1609,7 +1609,7 @@ class FirewallZone(object):
136e2c
                         modules = [ ]
136e2c
                         for helper in helpers:
136e2c
                             module = helper.module
136e2c
-                            _module_short_name = module.replace("-","_").replace("nf_conntrack_", "")
136e2c
+                            _module_short_name = get_nf_conntrack_short_name(module)
136e2c
                             if self._fw.nf_conntrack_helper_setting == 0:
136e2c
                                 if _module_short_name not in \
136e2c
                                    self._fw.nf_conntrack_helpers[module]:
136e2c
@@ -1820,7 +1820,7 @@ class FirewallZone(object):
136e2c
             if self._fw.nf_conntrack_helper_setting == 0:
136e2c
                 for helper in helpers:
136e2c
                     module = helper.module
136e2c
-                    _module_short_name = module.replace("-","_").replace("nf_conntrack_", "")
136e2c
+                    _module_short_name = get_nf_conntrack_short_name(module)
136e2c
                     if _module_short_name not in \
136e2c
                        self._fw.nf_conntrack_helpers[module]:
136e2c
                         raise FirewallError(
136e2c
diff --git a/src/firewall/functions.py b/src/firewall/functions.py
136e2c
index 5f54a59204b8..ad2166905d1d 100644
136e2c
--- a/src/firewall/functions.py
136e2c
+++ b/src/firewall/functions.py
136e2c
@@ -345,6 +345,9 @@ def enable_ip_forwarding(ipv):
136e2c
         return writefile("/proc/sys/net/ipv6/conf/all/forwarding", "1\n")
136e2c
     return False
136e2c
 
136e2c
+def get_nf_conntrack_short_name(module):
136e2c
+    return module.replace("_","-").replace("nf-conntrack-", "")
136e2c
+
136e2c
 def get_nf_conntrack_helpers():
136e2c
     kver = os.uname()[2]
136e2c
     path = "/lib/modules/%s/kernel/net/netfilter/" % kver
136e2c
@@ -361,8 +364,7 @@ def get_nf_conntrack_helpers():
136e2c
             # the we add it to helpers list and goto next module
136e2c
             if filename.startswith("nf_conntrack_proto_"):
136e2c
                 helper = filename.split(".")[0].strip()
136e2c
-                helper = helper.replace("_", "-")
136e2c
-                helper = helper.replace("nf-conntrack-", "")
136e2c
+                helper = get_nf_conntrack_short_name(helper)
136e2c
                 helpers.setdefault(module, [ ]).append(helper)
136e2c
                 continue
136e2c
             # Else we get module alias and if "-helper" in the "alias:" line of modinfo
136e2c
-- 
136e2c
2.20.1
136e2c