Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 930cd6e4 authored by Antonio Quartulli's avatar Antonio Quartulli
Browse files

batman-adv: fix soft-interface MTU computation



The current MTU computation always returns a value
smaller than 1500bytes even if the real interfaces
have an MTU large enough to compensate the batman-adv
overhead.

Fix the computation by properly returning the highest
admitted value.

Introduced by a19d3d85
("batman-adv: limit local translation table max size")

Reported-by: default avatarRussell Senior <russell@personaltelco.net>
Signed-off-by: default avatarAntonio Quartulli <antonio@meshcoding.com>
Signed-off-by: default avatarMarek Lindner <mareklindner@neomailbox.ch>
parent 0fd5d57b
Loading
Loading
Loading
Loading
+14 −8
Original line number Original line Diff line number Diff line
@@ -241,7 +241,7 @@ int batadv_hardif_min_mtu(struct net_device *soft_iface)
{
{
	struct batadv_priv *bat_priv = netdev_priv(soft_iface);
	struct batadv_priv *bat_priv = netdev_priv(soft_iface);
	const struct batadv_hard_iface *hard_iface;
	const struct batadv_hard_iface *hard_iface;
	int min_mtu = ETH_DATA_LEN;
	int min_mtu = INT_MAX;


	rcu_read_lock();
	rcu_read_lock();
	list_for_each_entry_rcu(hard_iface, &batadv_hardif_list, list) {
	list_for_each_entry_rcu(hard_iface, &batadv_hardif_list, list) {
@@ -256,8 +256,6 @@ int batadv_hardif_min_mtu(struct net_device *soft_iface)
	}
	}
	rcu_read_unlock();
	rcu_read_unlock();


	atomic_set(&bat_priv->packet_size_max, min_mtu);

	if (atomic_read(&bat_priv->fragmentation) == 0)
	if (atomic_read(&bat_priv->fragmentation) == 0)
		goto out;
		goto out;


@@ -268,13 +266,21 @@ int batadv_hardif_min_mtu(struct net_device *soft_iface)
	min_mtu = min_t(int, min_mtu, BATADV_FRAG_MAX_FRAG_SIZE);
	min_mtu = min_t(int, min_mtu, BATADV_FRAG_MAX_FRAG_SIZE);
	min_mtu -= sizeof(struct batadv_frag_packet);
	min_mtu -= sizeof(struct batadv_frag_packet);
	min_mtu *= BATADV_FRAG_MAX_FRAGMENTS;
	min_mtu *= BATADV_FRAG_MAX_FRAGMENTS;
	atomic_set(&bat_priv->packet_size_max, min_mtu);

	/* with fragmentation enabled we can fragment external packets easily */
	min_mtu = min_t(int, min_mtu, ETH_DATA_LEN);


out:
out:
	return min_mtu - batadv_max_header_len();
	/* report to the other components the maximum amount of bytes that
	 * batman-adv can send over the wire (without considering the payload
	 * overhead). For example, this value is used by TT to compute the
	 * maximum local table table size
	 */
	atomic_set(&bat_priv->packet_size_max, min_mtu);

	/* the real soft-interface MTU is computed by removing the payload
	 * overhead from the maximum amount of bytes that was just computed.
	 *
	 * However batman-adv does not support MTUs bigger than ETH_DATA_LEN
	 */
	return min_t(int, min_mtu - batadv_max_header_len(), ETH_DATA_LEN);
}
}


/* adjusts the MTU if a new interface with a smaller MTU appeared. */
/* adjusts the MTU if a new interface with a smaller MTU appeared. */