From a31df960e4d9c1f2c9201500115cc1dda7fe6a4f Mon Sep 17 00:00:00 2001
From: Beniamino Galvani <bgalvani@redhat.com>
Date: Fri, 17 Jul 2026 14:04:44 +0200
Subject: [PATCH] device: fix IPv4 forwarding not enabled on modem data
 interfaces

Modem devices implement ready_for_ip_config() to skip the standard IP
methods (DHCP, shared, link-local) since they handle IP configuration
via ModemManager bearers.

This also skipped _dev_ipforwarding4_start(), which is responsible for:

 - Enabling forwarding when needed, e.g. when ipv4.method=shared is
   active elsewhere.

 - Connecting to the SHARING_IPV4_CHANGED signal so forwarding can be
   retroactively enabled when a shared connection appears later.

As a result, when using a modem as the upstream connection and a Wi-Fi
hotspot (ipv4.method=shared), forwarding was not enabled on the
modem's data interface (e.g. qmapmux0.0), breaking IPv4 connection
sharing.

Fix this by moving _dev_ipforwarding4_start() to the out_devip label
so it runs for all device types that have an IP ifindex, including
those that skip standard IP methods.

Guard with an ifindex check so devices that don't yet have a kernel
link (like OVS internal interfaces) are not affected.

Fixes: 32cbf4c629a3 ('ip: shared: stop using the global forwarding')

https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/work_items/1935
https://gitlab.postmarketos.org/postmarketOS/pmaports/-/work_items/4118
---
 src/core/devices/nm-device.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/src/core/devices/nm-device.c b/src/core/devices/nm-device.c
index 59c467d16a..4a723c977e 100644
--- a/src/core/devices/nm-device.c
+++ b/src/core/devices/nm-device.c
@@ -13433,8 +13433,6 @@ activate_stage3_ip_config_for_addr_family(NMDevice *self, int addr_family)
         if (priv->ipll_data_4.v4.mode == NM_SETTING_IP4_LL_ENABLED)
             _dev_ipll4_start(self);
 
-        _dev_ipforwarding4_start(self, addr_family);
-
         if (nm_streq(priv->ipv4_method, NM_SETTING_IP4_CONFIG_METHOD_AUTO))
             _dev_ipdhcpx_start(self, AF_INET);
         else if (nm_streq(priv->ipv4_method, NM_SETTING_IP4_CONFIG_METHOD_LINK_LOCAL)) {
@@ -13503,6 +13501,9 @@ activate_stage3_ip_config_for_addr_family(NMDevice *self, int addr_family)
     }
 
 out_devip:
+    if (IS_IPv4 && nm_device_get_ip_ifindex(self) > 0)
+        _dev_ipforwarding4_start(self, addr_family);
+
     if (klass->act_stage3_ip_config)
         klass->act_stage3_ip_config(self, addr_family);
 
-- 
GitLab

