]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
qa: only setup nat rules during bridge creation
authorPatrick Donnelly <pdonnell@redhat.com>
Wed, 11 Mar 2026 06:16:35 +0000 (11:46 +0530)
committerPatrick Donnelly <pdonnell@ibm.com>
Tue, 14 Apr 2026 01:27:18 +0000 (21:27 -0400)
Currently the code recreates these NAT rules for every mount. This only
needs to be done once by the first mount.

Signed-off-by: Patrick Donnelly <pdonnell@redhat.com>
qa/tasks/cephfs/mount.py

index f7159c7b4b6e98b837044dc54606408284d7bd5b..1b1c696b3e12b5981adbb46de6acd2d6b13d6883 100644 (file)
@@ -300,38 +300,32 @@ class CephFSMountBase(object):
                 sudo ip addr add {ip}/{mask} brd {brd} dev ceph-brx
             """, timeout=(5*60), omit_sudo=False, cwd='/')
         
-        args = "echo 1 | sudo tee /proc/sys/net/ipv4/ip_forward"
-        self.client_remote.run(args=args, timeout=(5*60), omit_sudo=False)
+            args = "echo 1 | sudo tee /proc/sys/net/ipv4/ip_forward"
+            self.client_remote.run(args=args, timeout=(5*60), omit_sudo=False)
         
-        # Setup the NAT
-        gw = self._default_gateway()
+            # Setup the NAT
+            gw = self._default_gateway()
 
-        self.run_shell_payload(f"""
-            set -e
+            self.run_shell_payload(f"""
+                set -e
 
-            # Try iptables first. If it's missing or lacks MASQUERADE support (Rocky 10), it falls back to nft.
-            if command -v iptables >/dev/null 2>&1 && sudo iptables -t nat -A POSTROUTING -s {self.ceph_brx_net} -o {gw} -j MASQUERADE 2>/dev/null; then
-                sudo iptables -A FORWARD -o {gw} -i ceph-brx -j ACCEPT
-                sudo iptables -A FORWARD -i {gw} -o ceph-brx -j ACCEPT
-            else
-                # Ensure filter table exists. Ignore error if it already does.
-                sudo nft add table ip filter > /dev/null 2>&1 || true
-                sudo nft add chain ip filter forward {{ type filter hook forward priority 0 \; }} > /dev/null 2>&1 || true
+                if command -v iptables >/dev/null 2>&1 && sudo iptables -t nat -A POSTROUTING -s {self.ceph_brx_net} -o {gw} -j MASQUERADE 2>/dev/null; then
+                    sudo iptables -A FORWARD -o {gw} -i ceph-brx -j ACCEPT
+                    sudo iptables -A FORWARD -i {gw} -o ceph-brx -j ACCEPT
+                else
+                    sudo nft add table ip filter > /dev/null 2>&1 || true
+                    sudo nft add chain ip filter forward {{ type filter hook forward priority 0 \; }} > /dev/null 2>&1 || true
 
-                # Ensure nat table exists. Ignore error if it already does.
-                sudo nft add table ip nat > /dev/null 2>&1 || true
+                    sudo nft add table ip nat > /dev/null 2>&1 || true
 
-                # Ensure postrouting chain exists. Ignore error if it already does.
-                sudo nft add chain ip nat postrouting {{ type nat hook postrouting priority 100 \; }} > /dev/null 2>&1 || true
+                    sudo nft add chain ip nat postrouting {{ type nat hook postrouting priority 100 \; }} > /dev/null 2>&1 || true
 
-                # Add the forwarding rules (to filter table, forward chain)
-                sudo nft add rule ip filter forward iifname ceph-brx oifname {gw} accept
-                sudo nft add rule ip filter forward iifname {gw} oifname ceph-brx accept
+                    sudo nft add rule ip filter forward iifname ceph-brx oifname {gw} accept
+                    sudo nft add rule ip filter forward iifname {gw} oifname ceph-brx accept
 
-                # Add the NAT rule (Using the true network CIDR to prevent masking bugs)
-                sudo nft add rule ip nat postrouting ip saddr {self.ceph_brx_net} oifname {gw} masquerade
-            fi
-        """, timeout=(5*60), omit_sudo=False, cwd='/')
+                    sudo nft add rule ip nat postrouting ip saddr {self.ceph_brx_net} oifname {gw} masquerade
+                fi
+            """, timeout=(5*60), omit_sudo=False, cwd='/')
 
     def _setup_netns(self):
         p = self.client_remote.run(args=['ip', 'netns', 'list'],