Commit 490a68e1 authored by Sven Eckelmann's avatar Sven Eckelmann Committed by sanglipeng
Browse files

batman-adv: Don't increase MTU when set by user

stable inclusion
from stable-v5.10.193
commit 7c09590883665bb6645deb3e33cab2c2eb2e1aa7
category: bugfix
bugzilla: https://gitee.com/openeuler/kernel/issues/I9399M

Reference: https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/commit/?id=7c09590883665bb6645deb3e33cab2c2eb2e1aa7



--------------------------------

commit d8e42a2b upstream.

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: c6c8fea2 ("net: Add batman-adv meshing protocol")
Cc: stable@vger.kernel.org
Signed-off-by: default avatarSven Eckelmann <sven@narfation.org>
Signed-off-by: default avatarSimon Wunderlich <sw@simonwunderlich.de>
Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Signed-off-by: default avatarsanglipeng <sanglipeng1@jd.com>
parent a09cc4b8
Loading
Loading
Loading
Loading
+13 −1
Original line number Diff line number Diff line
@@ -632,7 +632,19 @@ int batadv_hardif_min_mtu(struct net_device *soft_iface)
 */
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.
+3 −0
Original line number Diff line number Diff line
@@ -156,11 +156,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;
}
+6 −0
Original line number Diff line number Diff line
@@ -1566,6 +1566,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)