batman-adv: Don't increase MTU when set by user
authorSven Eckelmann <sven@narfation.org>
Wed, 19 Jul 2023 08:01:15 +0000 (10:01 +0200)
committerSimon Wunderlich <sw@simonwunderlich.de>
Thu, 20 Jul 2023 06:56:33 +0000 (08:56 +0200)
If the user set an MTU value, it usually means that there are special
requirements for the MTU. But if an interface gots activated, the MTU was
always recalculated and then the user set value was overwritten.

The only reason why this user set value has to be overwritten, is when the
MTU has to be decreased because batman-adv is not able to transfer packets
with the user specified size.

Fixes: c6c8fea29769 ("net: Add batman-adv meshing protocol")
Cc: stable@vger.kernel.org
Signed-off-by: Sven Eckelmann <sven@narfation.org>
Signed-off-by: Simon Wunderlich <sw@simonwunderlich.de>
net/batman-adv/hard-interface.c
net/batman-adv/soft-interface.c
net/batman-adv/types.h

index ae5762af0146763215b500b3ecbb4590a3901f88..24c9c0c3f3166f66d5696175fe8dd55f1fdce8c7 100644 (file)
@@ -630,7 +630,19 @@ out:
  */
 void batadv_update_min_mtu(struct net_device *soft_iface)
 {
-       dev_set_mtu(soft_iface, batadv_hardif_min_mtu(soft_iface));
+       struct batadv_priv *bat_priv = netdev_priv(soft_iface);
+       int limit_mtu;
+       int mtu;
+
+       mtu = batadv_hardif_min_mtu(soft_iface);
+
+       if (bat_priv->mtu_set_by_user)
+               limit_mtu = bat_priv->mtu_set_by_user;
+       else
+               limit_mtu = ETH_DATA_LEN;
+
+       mtu = min(mtu, limit_mtu);
+       dev_set_mtu(soft_iface, mtu);
 
        /* Check if the local translate table should be cleaned up to match a
         * new (and smaller) MTU.
index d3fdf82282afea518b99ce8be44d47781fdf0d3a..85d00dc9ce32c69fdeaff5ebb0d7098d846f830f 100644 (file)
@@ -153,11 +153,14 @@ static int batadv_interface_set_mac_addr(struct net_device *dev, void *p)
 
 static int batadv_interface_change_mtu(struct net_device *dev, int new_mtu)
 {
+       struct batadv_priv *bat_priv = netdev_priv(dev);
+
        /* check ranges */
        if (new_mtu < 68 || new_mtu > batadv_hardif_min_mtu(dev))
                return -EINVAL;
 
        dev->mtu = new_mtu;
+       bat_priv->mtu_set_by_user = new_mtu;
 
        return 0;
 }
index ca9449ec9836a17bad1455221af0016091e87bde..cf1a0eafe3abc9cce9a442a0cd6028e465bf389e 100644 (file)
@@ -1546,6 +1546,12 @@ struct batadv_priv {
        /** @soft_iface: net device which holds this struct as private data */
        struct net_device *soft_iface;
 
+       /**
+        * @mtu_set_by_user: MTU was set once by user
+        * protected by rtnl_lock
+        */
+       int mtu_set_by_user;
+
        /**
         * @bat_counters: mesh internal traffic statistic counters (see
         *  batadv_counters)