Blame SOURCES/sos-bz2011538-iptables-save-under-nf_tables-kmod.patch

92cd8f
From 7d5157aa5071e3620246e2d4aa80acb2d3ed30f0 Mon Sep 17 00:00:00 2001
92cd8f
From: Pavel Moravec <pmoravec@redhat.com>
92cd8f
Date: Tue, 28 Sep 2021 22:44:52 +0200
92cd8f
Subject: [PATCH] [networking] prevent iptables-save commands to load nf_tables
92cd8f
 kmod
92cd8f
92cd8f
If iptables has built-in nf_tables kmod, then
92cd8f
'ip netns <foo> iptables-save' command requires the kmod which must
92cd8f
be guarded by predicate.
92cd8f
92cd8f
Analogously for ip6tables.
92cd8f
92cd8f
Resolves: #2703
92cd8f
92cd8f
Signed-off-by: Pavel Moravec <pmoravec@redhat.com>
92cd8f
---
92cd8f
 sos/report/plugins/networking.py | 29 ++++++++++++++++++++++++-----
92cd8f
 1 file changed, 24 insertions(+), 5 deletions(-)
92cd8f
92cd8f
diff --git a/sos/report/plugins/networking.py b/sos/report/plugins/networking.py
92cd8f
index c80ae719..1237f629 100644
92cd8f
--- a/sos/report/plugins/networking.py
92cd8f
+++ b/sos/report/plugins/networking.py
92cd8f
@@ -182,22 +182,41 @@ class Networking(Plugin):
92cd8f
         # per-namespace.
92cd8f
         self.add_cmd_output("ip netns")
92cd8f
         cmd_prefix = "ip netns exec "
92cd8f
-        for namespace in self.get_network_namespaces(
92cd8f
-                            self.get_option("namespace_pattern"),
92cd8f
-                            self.get_option("namespaces")):
92cd8f
+        namespaces = self.get_network_namespaces(
92cd8f
+                self.get_option("namespace_pattern"),
92cd8f
+                self.get_option("namespaces"))
92cd8f
+        if (namespaces):
92cd8f
+            # 'ip netns exec <foo> iptables-save' must be guarded by nf_tables
92cd8f
+            # kmod, if 'iptables -V' output contains 'nf_tables'
92cd8f
+            # analogously for ip6tables
92cd8f
+            co = {'cmd': 'iptables -V', 'output': 'nf_tables'}
92cd8f
+            co6 = {'cmd': 'ip6tables -V', 'output': 'nf_tables'}
92cd8f
+            iptables_with_nft = (SoSPredicate(self, kmods=['nf_tables'])
92cd8f
+                                 if self.test_predicate(self,
92cd8f
+                                 pred=SoSPredicate(self, cmd_outputs=co))
92cd8f
+                                 else None)
92cd8f
+            ip6tables_with_nft = (SoSPredicate(self, kmods=['nf_tables'])
92cd8f
+                                  if self.test_predicate(self,
92cd8f
+                                  pred=SoSPredicate(self, cmd_outputs=co6))
92cd8f
+                                  else None)
92cd8f
+        for namespace in namespaces:
92cd8f
             ns_cmd_prefix = cmd_prefix + namespace + " "
92cd8f
             self.add_cmd_output([
92cd8f
                 ns_cmd_prefix + "ip address show",
92cd8f
                 ns_cmd_prefix + "ip route show table all",
92cd8f
                 ns_cmd_prefix + "ip -s -s neigh show",
92cd8f
                 ns_cmd_prefix + "ip rule list",
92cd8f
-                ns_cmd_prefix + "iptables-save",
92cd8f
-                ns_cmd_prefix + "ip6tables-save",
92cd8f
                 ns_cmd_prefix + "netstat %s -neopa" % self.ns_wide,
92cd8f
                 ns_cmd_prefix + "netstat -s",
92cd8f
                 ns_cmd_prefix + "netstat %s -agn" % self.ns_wide,
92cd8f
                 ns_cmd_prefix + "nstat -zas",
92cd8f
             ], priority=50)
92cd8f
+            self.add_cmd_output([ns_cmd_prefix + "iptables-save"],
92cd8f
+                                pred=iptables_with_nft,
92cd8f
+                                priority=50)
92cd8f
+            self.add_cmd_output([ns_cmd_prefix + "ip6tables-save"],
92cd8f
+                                pred=ip6tables_with_nft,
92cd8f
+                                priority=50)
92cd8f
 
92cd8f
             ss_cmd = ns_cmd_prefix + "ss -peaonmi"
92cd8f
             # --allow-system-changes is handled directly in predicate
92cd8f
-- 
92cd8f
2.31.1
92cd8f