Blame SOURCES/firewalld-0.4.4.5-firewall.functions-New-function-get_nf_nat_helpers-rhbz#1452681.patch

64e4ee
From 5a864808c03b703fd9073133fd185347703177c7 Mon Sep 17 00:00:00 2001
64e4ee
From: Thomas Woerner <twoerner@redhat.com>
64e4ee
Date: Mon, 22 May 2017 17:50:40 +0200
64e4ee
Subject: [PATCH 1/6] firewall.functions: New function get_nf_nat_helpers
64e4ee
64e4ee
This function returns a dict { module: [helper, ..], .. } similar to
64e4ee
get_nf_conntrack_helpers but for NAT helpers only. NAT helpers are not part
64e4ee
of the dict that is returned by get_nf_conntrack_helpers as it only lists
64e4ee
connection tracking helpers.
64e4ee
64e4ee
This is needed for RHBZ#1452681
64e4ee
64e4ee
(cherry picked from commit 577668e9b788e9982e90f331d934aaa8d79cae56)
64e4ee
---
64e4ee
 src/firewall/functions.py | 22 +++++++++++++++++++++-
64e4ee
 1 file changed, 21 insertions(+), 1 deletion(-)
64e4ee
64e4ee
diff --git a/src/firewall/functions.py b/src/firewall/functions.py
64e4ee
index 71d39a540754..07e65ab7c7f8 100644
64e4ee
--- a/src/firewall/functions.py
64e4ee
+++ b/src/firewall/functions.py
64e4ee
@@ -25,7 +25,7 @@ __all__ = [ "PY2", "getPortID", "getPortRange", "portStr", "getServiceName",
64e4ee
             "firewalld_is_active", "tempFile", "readfile", "writefile",
64e4ee
             "enable_ip_forwarding", "get_nf_conntrack_helper_setting",
64e4ee
             "set_nf_conntrack_helper_setting", "get_nf_conntrack_helpers",
64e4ee
-            "check_port", "check_address",
64e4ee
+            "get_nf_nat_helpers", "check_port", "check_address",
64e4ee
             "check_single_address", "check_mac", "uniqify", "ppid_of_pid",
64e4ee
             "max_zone_name_len", "checkUser", "checkUid", "checkCommand",
64e4ee
             "checkContext", "joinArgs", "splitArgs",
64e4ee
@@ -351,6 +351,26 @@ def get_nf_conntrack_helpers():
64e4ee
                     helpers.setdefault(module, [ ]).append(helper)
64e4ee
     return helpers
64e4ee
 
64e4ee
+def get_nf_nat_helpers():
64e4ee
+    kver = os.uname()[2]
64e4ee
+    path = "/lib/modules/%s/kernel/net/netfilter/" % kver
64e4ee
+    helpers = { }
64e4ee
+    if os.path.isdir(path):
64e4ee
+        for filename in sorted(os.listdir(path)):
64e4ee
+            if not filename.startswith("nf_nat_"):
64e4ee
+                continue
64e4ee
+            module = filename.split(".")[0]
64e4ee
+            (status, ret) = runProg(COMMANDS["modinfo"], [ module, ])
64e4ee
+            if status != 0:
64e4ee
+                continue
64e4ee
+            alias = None
64e4ee
+            for line in ret.split("\n"):
64e4ee
+                if line.startswith("description:") and "NAT helper" in line:
64e4ee
+                    helper = module.replace("nf_nat_", "")
64e4ee
+                    helper = helper.replace("_", "-")
64e4ee
+                    helpers.setdefault(module, [ ]).append(helper)
64e4ee
+    return helpers
64e4ee
+
64e4ee
 def get_nf_conntrack_helper_setting():
64e4ee
     try:
64e4ee
         return int(readfile("/proc/sys/net/netfilter/nf_conntrack_helper")[0])
64e4ee
-- 
64e4ee
2.12.0
64e4ee