B.A.T.M.A.N Archive on lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH batadv v2 0/5] batman-adv: drop global hard interface list
@ 2026-06-03  4:28 Sven Eckelmann
  2026-06-03  4:29 ` [PATCH batadv v2 1/5] batman-adv: tt: directly retrieve wifi flags of net_device Sven Eckelmann
                   ` (5 more replies)
  0 siblings, 6 replies; 8+ messages in thread
From: Sven Eckelmann @ 2026-06-03  4:28 UTC (permalink / raw)
  To: b.a.t.m.a.n; +Cc: Sven Eckelmann, Nora Schiffer

The global hard interface list was used in the past to provide and sysfs
(debugfs, procfs) based configuration interface. This requirement is gone
after it was switched to generic netlink and NETLINK_ROUTE. And after the
wifi-flags cache was introduced, it is also no longer used to get
non-batman-adv attached interface information (for ap_isolation and
re-broadcast configuration).

But this odd net_devices list (batadv_hardif_list) stayed and caused some
headaches:

* memory requirement increased (useless) for each network interface of the
  system
* massive increase of various ethernet operations due to the O(n) nature of
  this global list
* the code had to handle switch of a batadv_hard_iface from one mesh_iface
  to either NULL or a different mesh_iface

Just get rid of it now and start to simplify the code around it.

This RFC is on purpose not Signed-off-by because I just want to restart the
discussion but didn't discuss this with the original author (nor documented
the changes in each patch in detail). And it is also not meant to look like
I've reviewed the changes and Ack it - this is unfortunately something
which I have to do again with this rebased version.

I will later post an range-diff which contains all the changes.

Signed-off-by: Sven Eckelmann <sven@narfation.org>
---
Changes in v2:
- rebased
- submit as RFC to get the discussion started again
- drop already merged "batman-adv: store hard_iface as iflink private data"
- switch from kzalloc to kzalloc_obj
- update author's mail and name
- fix reference counting for batman_adv_ptype
- Link to v1: https://patch.msgid.link/0b26554afea5203820faef1dfb498af7533a9b5d.1747687504.git.mschiffer@universe-factory.net

---
Nora Schiffer (4):
      batman-adv: only create hardif while a netdev is part of a mesh
      batman-adv: remove BATADV_IF_NOT_IN_USE hardif state
      batman-adv: remove global hardif list
      batman-adv: move hardif generation counter into batadv_priv

Sven Eckelmann (1):
      batman-adv: tt: directly retrieve wifi flags of net_device

 net/batman-adv/bat_iv_ogm.c        |   3 +-
 net/batman-adv/bat_v_elp.c         |   3 +-
 net/batman-adv/hard-interface.c    | 183 +++++++++++++++----------------------
 net/batman-adv/hard-interface.h    |  11 +--
 net/batman-adv/main.c              |   6 --
 net/batman-adv/main.h              |   3 -
 net/batman-adv/mesh-interface.c    |  13 +--
 net/batman-adv/netlink.c           |   4 +-
 net/batman-adv/originator.c        |   4 -
 net/batman-adv/translation-table.c |  14 +--
 net/batman-adv/types.h             |   6 +-
 11 files changed, 93 insertions(+), 157 deletions(-)
---
base-commit: bba80ddd693e6d82a0b1f456511904cfefd5df24
change-id: 20260531-drop-hardif-list-bcf812da69dd

Best regards,
--  
Sven Eckelmann <sven@narfation.org>


^ permalink raw reply	[flat|nested] 8+ messages in thread

* [PATCH batadv v2 1/5] batman-adv: tt: directly retrieve wifi flags of net_device
  2026-06-03  4:28 [PATCH batadv v2 0/5] batman-adv: drop global hard interface list Sven Eckelmann
@ 2026-06-03  4:29 ` Sven Eckelmann
  2026-06-03  4:44   ` Sven Eckelmann
  2026-06-03  4:29 ` [PATCH batadv v2 2/5] batman-adv: only create hardif while a netdev is part of a mesh Sven Eckelmann
                   ` (4 subsequent siblings)
  5 siblings, 1 reply; 8+ messages in thread
From: Sven Eckelmann @ 2026-06-03  4:29 UTC (permalink / raw)
  To: b.a.t.m.a.n; +Cc: Sven Eckelmann

batadv_tt_local_add() tries to retrieve the wifi flags of an interface to
mark the TT entry as wifi client for the AP isolation feature. In the past,
it was necessary to look up the batadv_hard_iface because the wifi_flags
were stored inside this struct. But with the batadv_wifi_net_devices
rhashtable, it is preferred to directly retrieve the wifi_flags instead of
the indirect route via batadv_hard_iface - which at the end only provides
the net_device (which we used to find the batadv_hard_iface).

This will also be essential when the global batadv_hardif_list is removed
and each lookup via batadv_hardif_get_by_netdev() will require the RTNL
lock.

Signed-off-by: Sven Eckelmann <sven@narfation.org>
---
 net/batman-adv/hard-interface.c    | 35 +++++++++++++++++++++++------------
 net/batman-adv/hard-interface.h    |  1 +
 net/batman-adv/translation-table.c | 14 ++++++++------
 3 files changed, 32 insertions(+), 18 deletions(-)

diff --git a/net/batman-adv/hard-interface.c b/net/batman-adv/hard-interface.c
index bb3c31b5..c592ff58 100644
--- a/net/batman-adv/hard-interface.c
+++ b/net/batman-adv/hard-interface.c
@@ -365,6 +365,28 @@ static u32 batadv_wifi_flags_evaluate(struct net_device *net_device)
 	return wifi_flags;
 }
 
+/**
+ * batadv_netdev_get_wifi_flags() - retrieve wifi flags for net_device
+ * @net_dev: the device to check
+ *
+ * Return: batadv_hard_iface_wifi_flags flags of the device
+ */
+u32 batadv_netdev_get_wifi_flags(struct net_device *net_dev)
+{
+	struct batadv_wifi_net_device_state *device_state;
+	u32 wifi_flags;
+
+	rcu_read_lock();
+	device_state = rhashtable_lookup_fast(&batadv_wifi_net_devices,
+					      &net_dev,
+					      batadv_wifi_net_devices_params);
+	if (device_state)
+		wifi_flags = READ_ONCE(device_state->wifi_flags);
+	rcu_read_unlock();
+
+	return wifi_flags;
+}
+
 /**
  * batadv_hardif_get_wifi_flags() - retrieve wifi flags for hard_iface
  * @hard_iface: the device to check
@@ -373,21 +395,10 @@ static u32 batadv_wifi_flags_evaluate(struct net_device *net_device)
  */
 u32 batadv_hardif_get_wifi_flags(struct batadv_hard_iface *hard_iface)
 {
-	struct batadv_wifi_net_device_state *device_state;
-	u32 wifi_flags = 0;
-
 	if (!hard_iface)
 		return 0;
 
-	rcu_read_lock();
-	device_state = rhashtable_lookup_fast(&batadv_wifi_net_devices,
-					      &hard_iface->net_dev,
-					      batadv_wifi_net_devices_params);
-	if (device_state)
-		wifi_flags = READ_ONCE(device_state->wifi_flags);
-	rcu_read_unlock();
-
-	return wifi_flags;
+	return batadv_netdev_get_wifi_flags(hard_iface->net_dev);
 }
 
 /**
diff --git a/net/batman-adv/hard-interface.h b/net/batman-adv/hard-interface.h
index 089e65c8..822e7e37 100644
--- a/net/batman-adv/hard-interface.h
+++ b/net/batman-adv/hard-interface.h
@@ -70,6 +70,7 @@ extern struct notifier_block batadv_hard_if_notifier;
 
 struct net_device *__batadv_get_real_netdev(struct net_device *net_device);
 struct net_device *batadv_get_real_netdev(struct net_device *net_device);
+u32 batadv_netdev_get_wifi_flags(struct net_device *net_dev);
 u32 batadv_hardif_get_wifi_flags(struct batadv_hard_iface *hard_iface);
 bool batadv_is_wifi_hardif(struct batadv_hard_iface *hard_iface);
 struct batadv_hard_iface*
diff --git a/net/batman-adv/translation-table.c b/net/batman-adv/translation-table.c
index 25acbb34..5e2893f4 100644
--- a/net/batman-adv/translation-table.c
+++ b/net/batman-adv/translation-table.c
@@ -636,20 +636,23 @@ bool batadv_tt_local_add(struct net_device *mesh_iface, const u8 *addr,
 	struct net *net = dev_net(mesh_iface);
 	struct batadv_meshif_vlan *vlan;
 	struct net_device *in_dev = NULL;
-	struct batadv_hard_iface *in_hardif = NULL;
 	struct hlist_head *head;
 	struct batadv_tt_orig_list_entry *orig_entry;
 	int hash_added, table_size, packet_size_max;
 	bool ret = false;
 	bool roamed_back = false;
+	bool iif_is_wifi = false;
 	u8 remote_flags;
 	u32 match_mark;
 
 	if (ifindex != BATADV_NULL_IFINDEX)
 		in_dev = dev_get_by_index(net, ifindex);
 
-	if (in_dev)
-		in_hardif = batadv_hardif_get_by_netdev(in_dev);
+	if (in_dev) {
+		u32 wifi_flags = batadv_netdev_get_wifi_flags(in_dev);
+
+		iif_is_wifi = batadv_is_wifi(wifi_flags);
+	}
 
 	tt_local = batadv_tt_local_hash_find(bat_priv, addr, vid);
 
@@ -724,7 +727,7 @@ bool batadv_tt_local_add(struct net_device *mesh_iface, const u8 *addr,
 	 */
 	tt_local->common.flags = BATADV_TT_CLIENT_NEW;
 	tt_local->common.vid = vid;
-	if (batadv_is_wifi_hardif(in_hardif))
+	if (iif_is_wifi)
 		tt_local->common.flags |= BATADV_TT_CLIENT_WIFI;
 	kref_init(&tt_local->common.refcount);
 	tt_local->last_seen = jiffies;
@@ -783,7 +786,7 @@ bool batadv_tt_local_add(struct net_device *mesh_iface, const u8 *addr,
 	 */
 	remote_flags = tt_local->common.flags & BATADV_TT_REMOTE_MASK;
 
-	if (batadv_is_wifi_hardif(in_hardif))
+	if (iif_is_wifi)
 		tt_local->common.flags |= BATADV_TT_CLIENT_WIFI;
 	else
 		tt_local->common.flags &= ~BATADV_TT_CLIENT_WIFI;
@@ -807,7 +810,6 @@ bool batadv_tt_local_add(struct net_device *mesh_iface, const u8 *addr,
 
 	ret = true;
 out:
-	batadv_hardif_put(in_hardif);
 	dev_put(in_dev);
 	batadv_tt_local_entry_put(tt_local);
 	batadv_tt_global_entry_put(tt_global);

-- 
2.47.3


^ permalink raw reply related	[flat|nested] 8+ messages in thread

* [PATCH batadv v2 2/5] batman-adv: only create hardif while a netdev is part of a mesh
  2026-06-03  4:28 [PATCH batadv v2 0/5] batman-adv: drop global hard interface list Sven Eckelmann
  2026-06-03  4:29 ` [PATCH batadv v2 1/5] batman-adv: tt: directly retrieve wifi flags of net_device Sven Eckelmann
@ 2026-06-03  4:29 ` Sven Eckelmann
  2026-06-03  4:29 ` [PATCH batadv v2 3/5] batman-adv: remove BATADV_IF_NOT_IN_USE hardif state Sven Eckelmann
                   ` (3 subsequent siblings)
  5 siblings, 0 replies; 8+ messages in thread
From: Sven Eckelmann @ 2026-06-03  4:29 UTC (permalink / raw)
  To: b.a.t.m.a.n; +Cc: Sven Eckelmann, Nora Schiffer

From: Nora Schiffer <neocturne@universe-factory.net>

batman-adv has used netdevice notifiers to create a hardif struct for
every Ethernet-like netdev in the system, instead of just for netdevs
that are actually used for meshing.

This is inefficient in many ways: It requires maintaining a global list
of hardifs (as there is no other place to store the hardif associated
with a netdev), lookups in this list are O(n) in the total number of
interfaces, and the maintenance of this list results in just loading the
batman-adv module to cause a slowdown of certain netdev operations (for
example, deleting n Ethernet netdevs may take O(n^2) because for each
removal, the corresponding hardif needs to be looked up in the global
list).

As the next step towards removing the global list, only create a hardif
struct when an interface is added to a mesh, and destroy it on removal.
Parts of batadv_hardif_add_interface() are merged into
batadv_hardif_enable_interface(), and batadv_hardif_remove_interface()
can be dropped altogether.
---
 net/batman-adv/hard-interface.c | 122 +++++++++++++++-------------------------
 net/batman-adv/hard-interface.h |   2 +-
 net/batman-adv/mesh-interface.c |  13 +----
 3 files changed, 48 insertions(+), 89 deletions(-)

diff --git a/net/batman-adv/hard-interface.c b/net/batman-adv/hard-interface.c
index c592ff58..0020cf6a 100644
--- a/net/batman-adv/hard-interface.c
+++ b/net/batman-adv/hard-interface.c
@@ -723,33 +723,64 @@ batadv_hardif_deactivate_interface(struct batadv_hard_iface *hard_iface)
 }
 
 /**
- * batadv_hardif_enable_interface() - Enslave hard interface to mesh interface
- * @hard_iface: hard interface to add to mesh interface
+ * batadv_hardif_enable_interface() - Enslave interface to mesh interface
+ * @net_dev: netdev struct of the interface to add to mesh interface
  * @mesh_iface: netdev struct of the mesh interface
  *
- * Return: 0 on success or negative error number in case of failure
+ * Return: new hardif on success, NULL for unsupported device types or negative
+ *         error number in case of failure
  */
-int batadv_hardif_enable_interface(struct batadv_hard_iface *hard_iface,
+int batadv_hardif_enable_interface(struct net_device *net_dev,
 				   struct net_device *mesh_iface)
 {
 	struct batadv_priv *bat_priv;
 	__be16 ethertype = htons(ETH_P_BATMAN);
 	int max_header_len = batadv_max_header_len();
+	struct batadv_hard_iface *hard_iface;
 	unsigned int required_mtu;
 	unsigned int hardif_mtu;
 	bool fragmentation;
 	int ret;
 
-	hardif_mtu = READ_ONCE(hard_iface->net_dev->mtu);
+	ASSERT_RTNL();
+
+	if (!batadv_is_valid_iface(net_dev))
+		return -EINVAL;
+
+	hardif_mtu = READ_ONCE(net_dev->mtu);
 	required_mtu = READ_ONCE(mesh_iface->mtu) + max_header_len;
 
 	if (hardif_mtu < ETH_MIN_MTU + max_header_len)
 		return -EINVAL;
 
-	if (hard_iface->if_status != BATADV_IF_NOT_IN_USE)
-		goto out;
+	hard_iface = kzalloc_obj(*hard_iface, GFP_ATOMIC);
+	if (!hard_iface)
+		return -ENOMEM;
+
+	netdev_hold(net_dev, &hard_iface->dev_tracker, GFP_ATOMIC);
+	hard_iface->net_dev = net_dev;
+
+	hard_iface->mesh_iface = NULL;
+	hard_iface->if_status = BATADV_IF_INACTIVE;
+
+	INIT_LIST_HEAD(&hard_iface->list);
+	INIT_HLIST_HEAD(&hard_iface->neigh_list);
+
+	mutex_init(&hard_iface->bat_iv.ogm_buff_mutex);
+	spin_lock_init(&hard_iface->neigh_list_lock);
+	kref_init(&hard_iface->refcount);
+
+	hard_iface->num_bcasts = BATADV_NUM_BCASTS_DEFAULT;
+	if (batadv_is_wifi_hardif(hard_iface))
+		hard_iface->num_bcasts = BATADV_NUM_BCASTS_WIRELESS;
+
+	WRITE_ONCE(hard_iface->hop_penalty, 0);
+
+	batadv_v_hardif_init(hard_iface);
 
 	kref_get(&hard_iface->refcount);
+	list_add_tail_rcu(&hard_iface->list, &batadv_hardif_list);
+	batadv_hardif_generation++;
 
 	netdev_hold(mesh_iface, &hard_iface->meshif_dev_tracker, GFP_ATOMIC);
 	hard_iface->mesh_iface = mesh_iface;
@@ -764,8 +795,6 @@ int batadv_hardif_enable_interface(struct batadv_hard_iface *hard_iface,
 	if (ret < 0)
 		goto err_upper;
 
-	hard_iface->if_status = BATADV_IF_INACTIVE;
-
 	kref_get(&hard_iface->refcount);
 	hard_iface->batman_adv_ptype.type = ethertype;
 	hard_iface->batman_adv_ptype.func = batadv_batman_skb_recv;
@@ -802,7 +831,6 @@ int batadv_hardif_enable_interface(struct batadv_hard_iface *hard_iface,
 	if (bat_priv->algo_ops->iface.enabled)
 		bat_priv->algo_ops->iface.enabled(hard_iface);
 
-out:
 	return 0;
 
 err_upper:
@@ -847,11 +875,17 @@ void batadv_hardif_disable_interface(struct batadv_hard_iface *hard_iface)
 	struct batadv_priv *bat_priv = netdev_priv(hard_iface->mesh_iface);
 	struct batadv_hard_iface *primary_if = NULL;
 
+	ASSERT_RTNL();
+
 	batadv_hardif_deactivate_interface(hard_iface);
 
 	if (hard_iface->if_status != BATADV_IF_INACTIVE)
 		goto out;
 
+	list_del_rcu(&hard_iface->list);
+	batadv_hardif_put(hard_iface);
+	batadv_hardif_generation++;
+
 	batadv_info(hard_iface->mesh_iface, "Removing interface: %s\n",
 		    hard_iface->net_dev->name);
 	dev_remove_pack(&hard_iface->batman_adv_ptype);
@@ -868,7 +902,7 @@ void batadv_hardif_disable_interface(struct batadv_hard_iface *hard_iface)
 	}
 
 	bat_priv->algo_ops->iface.disable(hard_iface);
-	hard_iface->if_status = BATADV_IF_NOT_IN_USE;
+	hard_iface->if_status = BATADV_IF_TO_BE_REMOVED;
 
 	/* delete all references to this hard_iface */
 	batadv_purge_orig_ref(bat_priv);
@@ -889,63 +923,6 @@ void batadv_hardif_disable_interface(struct batadv_hard_iface *hard_iface)
 	batadv_hardif_put(primary_if);
 }
 
-static struct batadv_hard_iface *
-batadv_hardif_add_interface(struct net_device *net_dev)
-{
-	struct batadv_hard_iface *hard_iface;
-
-	ASSERT_RTNL();
-
-	if (!batadv_is_valid_iface(net_dev))
-		return NULL;
-
-	hard_iface = kzalloc_obj(*hard_iface, GFP_ATOMIC);
-	if (!hard_iface)
-		return NULL;
-
-	netdev_hold(net_dev, &hard_iface->dev_tracker, GFP_ATOMIC);
-	hard_iface->net_dev = net_dev;
-
-	hard_iface->mesh_iface = NULL;
-	hard_iface->if_status = BATADV_IF_NOT_IN_USE;
-
-	INIT_LIST_HEAD(&hard_iface->list);
-	INIT_HLIST_HEAD(&hard_iface->neigh_list);
-
-	mutex_init(&hard_iface->bat_iv.ogm_buff_mutex);
-	spin_lock_init(&hard_iface->neigh_list_lock);
-	kref_init(&hard_iface->refcount);
-
-	hard_iface->num_bcasts = BATADV_NUM_BCASTS_DEFAULT;
-	if (batadv_is_wifi_hardif(hard_iface))
-		hard_iface->num_bcasts = BATADV_NUM_BCASTS_WIRELESS;
-
-	WRITE_ONCE(hard_iface->hop_penalty, 0);
-
-	batadv_v_hardif_init(hard_iface);
-
-	kref_get(&hard_iface->refcount);
-	list_add_tail_rcu(&hard_iface->list, &batadv_hardif_list);
-	batadv_hardif_generation++;
-
-	return hard_iface;
-}
-
-static void batadv_hardif_remove_interface(struct batadv_hard_iface *hard_iface)
-{
-	ASSERT_RTNL();
-
-	/* first deactivate interface */
-	if (hard_iface->if_status != BATADV_IF_NOT_IN_USE)
-		batadv_hardif_disable_interface(hard_iface);
-
-	if (hard_iface->if_status != BATADV_IF_NOT_IN_USE)
-		return;
-
-	hard_iface->if_status = BATADV_IF_TO_BE_REMOVED;
-	batadv_hardif_put(hard_iface);
-}
-
 /**
  * batadv_hard_if_event_meshif() - Handle events for mesh interfaces
  * @event: NETDEV_* event to handle
@@ -1107,10 +1084,6 @@ static int batadv_hard_if_event(struct notifier_block *this,
 	batadv_wifi_net_device_event(event, net_dev);
 
 	hard_iface = batadv_hardif_get_by_netdev(net_dev);
-	if (!hard_iface && (event == NETDEV_REGISTER ||
-			    event == NETDEV_POST_TYPE_CHANGE))
-		hard_iface = batadv_hardif_add_interface(net_dev);
-
 	if (!hard_iface)
 		goto out;
 
@@ -1124,10 +1097,7 @@ static int batadv_hard_if_event(struct notifier_block *this,
 		break;
 	case NETDEV_UNREGISTER:
 	case NETDEV_PRE_TYPE_CHANGE:
-		list_del_rcu(&hard_iface->list);
-		batadv_hardif_generation++;
-
-		batadv_hardif_remove_interface(hard_iface);
+		batadv_hardif_disable_interface(hard_iface);
 		break;
 	case NETDEV_CHANGEMTU:
 		if (hard_iface->mesh_iface)
diff --git a/net/batman-adv/hard-interface.h b/net/batman-adv/hard-interface.h
index 822e7e37..845ff5d2 100644
--- a/net/batman-adv/hard-interface.h
+++ b/net/batman-adv/hard-interface.h
@@ -75,7 +75,7 @@ u32 batadv_hardif_get_wifi_flags(struct batadv_hard_iface *hard_iface);
 bool batadv_is_wifi_hardif(struct batadv_hard_iface *hard_iface);
 struct batadv_hard_iface*
 batadv_hardif_get_by_netdev(const struct net_device *net_dev);
-int batadv_hardif_enable_interface(struct batadv_hard_iface *hard_iface,
+int batadv_hardif_enable_interface(struct net_device *net_dev,
 				   struct net_device *mesh_iface);
 void batadv_hardif_disable_interface(struct batadv_hard_iface *hard_iface);
 int batadv_hardif_min_mtu(struct net_device *mesh_iface);
diff --git a/net/batman-adv/mesh-interface.c b/net/batman-adv/mesh-interface.c
index 7367c1bd..ef324ece 100644
--- a/net/batman-adv/mesh-interface.c
+++ b/net/batman-adv/mesh-interface.c
@@ -836,18 +836,7 @@ static int batadv_meshif_slave_add(struct net_device *dev,
 				   struct net_device *slave_dev,
 				   struct netlink_ext_ack *extack)
 {
-	struct batadv_hard_iface *hard_iface;
-	int ret = -EINVAL;
-
-	hard_iface = batadv_hardif_get_by_netdev(slave_dev);
-	if (!hard_iface || hard_iface->mesh_iface)
-		goto out;
-
-	ret = batadv_hardif_enable_interface(hard_iface, dev);
-
-out:
-	batadv_hardif_put(hard_iface);
-	return ret;
+	return batadv_hardif_enable_interface(slave_dev, dev);
 }
 
 /**

-- 
2.47.3


^ permalink raw reply related	[flat|nested] 8+ messages in thread

* [PATCH batadv v2 3/5] batman-adv: remove BATADV_IF_NOT_IN_USE hardif state
  2026-06-03  4:28 [PATCH batadv v2 0/5] batman-adv: drop global hard interface list Sven Eckelmann
  2026-06-03  4:29 ` [PATCH batadv v2 1/5] batman-adv: tt: directly retrieve wifi flags of net_device Sven Eckelmann
  2026-06-03  4:29 ` [PATCH batadv v2 2/5] batman-adv: only create hardif while a netdev is part of a mesh Sven Eckelmann
@ 2026-06-03  4:29 ` Sven Eckelmann
  2026-06-03  4:29 ` [PATCH batadv v2 4/5] batman-adv: remove global hardif list Sven Eckelmann
                   ` (2 subsequent siblings)
  5 siblings, 0 replies; 8+ messages in thread
From: Sven Eckelmann @ 2026-06-03  4:29 UTC (permalink / raw)
  To: b.a.t.m.a.n; +Cc: Sven Eckelmann, Nora Schiffer

From: Nora Schiffer <neocturne@universe-factory.net>

With hardifs only existing while an interface is part of a mesh, the
BATADV_IF_NOT_IN_USE state has become redundant.
---
 net/batman-adv/bat_iv_ogm.c     | 3 +--
 net/batman-adv/bat_v_elp.c      | 3 +--
 net/batman-adv/hard-interface.c | 9 ---------
 net/batman-adv/hard-interface.h | 6 ------
 net/batman-adv/originator.c     | 4 ----
 5 files changed, 2 insertions(+), 23 deletions(-)

diff --git a/net/batman-adv/bat_iv_ogm.c b/net/batman-adv/bat_iv_ogm.c
index 6f5a468c..7242ae6f 100644
--- a/net/batman-adv/bat_iv_ogm.c
+++ b/net/batman-adv/bat_iv_ogm.c
@@ -901,8 +901,7 @@ static void batadv_iv_ogm_schedule_buff(struct batadv_hard_iface *hard_iface)
 
 static void batadv_iv_ogm_schedule(struct batadv_hard_iface *hard_iface)
 {
-	if (hard_iface->if_status == BATADV_IF_NOT_IN_USE ||
-	    hard_iface->if_status == BATADV_IF_TO_BE_REMOVED)
+	if (hard_iface->if_status == BATADV_IF_TO_BE_REMOVED)
 		return;
 
 	mutex_lock(&hard_iface->bat_iv.ogm_buff_mutex);
diff --git a/net/batman-adv/bat_v_elp.c b/net/batman-adv/bat_v_elp.c
index d53485d1..d5ae58cb 100644
--- a/net/batman-adv/bat_v_elp.c
+++ b/net/batman-adv/bat_v_elp.c
@@ -311,8 +311,7 @@ static void batadv_v_elp_periodic_work(struct work_struct *work)
 		goto out;
 
 	/* we are in the process of shutting this interface down */
-	if (hard_iface->if_status == BATADV_IF_NOT_IN_USE ||
-	    hard_iface->if_status == BATADV_IF_TO_BE_REMOVED)
+	if (hard_iface->if_status == BATADV_IF_TO_BE_REMOVED)
 		goto out;
 
 	/* the interface was enabled but may not be ready yet */
diff --git a/net/batman-adv/hard-interface.c b/net/batman-adv/hard-interface.c
index 0020cf6a..909e9b01 100644
--- a/net/batman-adv/hard-interface.c
+++ b/net/batman-adv/hard-interface.c
@@ -546,9 +546,6 @@ static void batadv_check_known_mac_addr(const struct batadv_hard_iface *hard_ifa
 		if (tmp_hard_iface == hard_iface)
 			continue;
 
-		if (tmp_hard_iface->if_status == BATADV_IF_NOT_IN_USE)
-			continue;
-
 		if (!batadv_compare_eth(tmp_hard_iface->net_dev->dev_addr,
 					hard_iface->net_dev->dev_addr))
 			continue;
@@ -574,9 +571,6 @@ static void batadv_hardif_recalc_extra_skbroom(struct net_device *mesh_iface)
 
 	rcu_read_lock();
 	netdev_for_each_lower_private_rcu(mesh_iface, hard_iface, iter) {
-		if (hard_iface->if_status == BATADV_IF_NOT_IN_USE)
-			continue;
-
 		lower_header_len = max_t(unsigned short, lower_header_len,
 					 hard_iface->net_dev->hard_header_len);
 
@@ -1104,9 +1098,6 @@ static int batadv_hard_if_event(struct notifier_block *this,
 			batadv_update_min_mtu(hard_iface->mesh_iface);
 		break;
 	case NETDEV_CHANGEADDR:
-		if (hard_iface->if_status == BATADV_IF_NOT_IN_USE)
-			goto hardif_put;
-
 		batadv_check_known_mac_addr(hard_iface);
 
 		bat_priv = netdev_priv(hard_iface->mesh_iface);
diff --git a/net/batman-adv/hard-interface.h b/net/batman-adv/hard-interface.h
index 845ff5d2..1194f24f 100644
--- a/net/batman-adv/hard-interface.h
+++ b/net/batman-adv/hard-interface.h
@@ -21,12 +21,6 @@
  * enum batadv_hard_if_state - State of a hard interface
  */
 enum batadv_hard_if_state {
-	/**
-	 * @BATADV_IF_NOT_IN_USE: interface is not used as slave interface of a
-	 * batman-adv mesh interface
-	 */
-	BATADV_IF_NOT_IN_USE,
-
 	/**
 	 * @BATADV_IF_TO_BE_REMOVED: interface will be removed from mesh
 	 * interface
diff --git a/net/batman-adv/originator.c b/net/batman-adv/originator.c
index 15d660ca..bbd4f9d4 100644
--- a/net/batman-adv/originator.c
+++ b/net/batman-adv/originator.c
@@ -1033,7 +1033,6 @@ batadv_purge_neigh_ifinfo(struct batadv_priv *bat_priv,
 
 		/* don't purge if the interface is not (going) down */
 		if (if_outgoing->if_status != BATADV_IF_INACTIVE &&
-		    if_outgoing->if_status != BATADV_IF_NOT_IN_USE &&
 		    if_outgoing->if_status != BATADV_IF_TO_BE_REMOVED)
 			continue;
 
@@ -1077,7 +1076,6 @@ batadv_purge_orig_ifinfo(struct batadv_priv *bat_priv,
 
 		/* don't purge if the interface is not (going) down */
 		if (if_outgoing->if_status != BATADV_IF_INACTIVE &&
-		    if_outgoing->if_status != BATADV_IF_NOT_IN_USE &&
 		    if_outgoing->if_status != BATADV_IF_TO_BE_REMOVED)
 			continue;
 
@@ -1127,10 +1125,8 @@ batadv_purge_orig_neighbors(struct batadv_priv *bat_priv,
 
 		if (batadv_has_timed_out(last_seen, BATADV_PURGE_TIMEOUT) ||
 		    if_incoming->if_status == BATADV_IF_INACTIVE ||
-		    if_incoming->if_status == BATADV_IF_NOT_IN_USE ||
 		    if_incoming->if_status == BATADV_IF_TO_BE_REMOVED) {
 			if (if_incoming->if_status == BATADV_IF_INACTIVE ||
-			    if_incoming->if_status == BATADV_IF_NOT_IN_USE ||
 			    if_incoming->if_status == BATADV_IF_TO_BE_REMOVED)
 				batadv_dbg(BATADV_DBG_BATMAN, bat_priv,
 					   "neighbor purge: originator %pM, neighbor: %pM, iface: %s\n",

-- 
2.47.3


^ permalink raw reply related	[flat|nested] 8+ messages in thread

* [PATCH batadv v2 4/5] batman-adv: remove global hardif list
  2026-06-03  4:28 [PATCH batadv v2 0/5] batman-adv: drop global hard interface list Sven Eckelmann
                   ` (2 preceding siblings ...)
  2026-06-03  4:29 ` [PATCH batadv v2 3/5] batman-adv: remove BATADV_IF_NOT_IN_USE hardif state Sven Eckelmann
@ 2026-06-03  4:29 ` Sven Eckelmann
  2026-06-03  4:29 ` [PATCH batadv v2 5/5] batman-adv: move hardif generation counter into batadv_priv Sven Eckelmann
  2026-06-03  4:43 ` [PATCH batadv v2 0/5] batman-adv: drop global hard interface list Sven Eckelmann
  5 siblings, 0 replies; 8+ messages in thread
From: Sven Eckelmann @ 2026-06-03  4:29 UTC (permalink / raw)
  To: b.a.t.m.a.n; +Cc: Sven Eckelmann, Nora Schiffer

From: Nora Schiffer <neocturne@universe-factory.net>

With interfaces being kept track of as iflink private data, there is no
need for the global list anymore. batadv_hardif_get_by_netdev() can now
use netdev_master_upper_dev_get()+netdev_lower_dev_get_private() to find
the hardif corresponding to a netdev.
---
 net/batman-adv/hard-interface.c | 35 +++++++++++++----------------------
 net/batman-adv/hard-interface.h |  2 +-
 net/batman-adv/main.c           |  5 -----
 net/batman-adv/main.h           |  1 -
 net/batman-adv/netlink.c        |  2 ++
 net/batman-adv/types.h          |  3 ---
 6 files changed, 16 insertions(+), 32 deletions(-)

diff --git a/net/batman-adv/hard-interface.c b/net/batman-adv/hard-interface.c
index 909e9b01..3990d826 100644
--- a/net/batman-adv/hard-interface.c
+++ b/net/batman-adv/hard-interface.c
@@ -63,6 +63,7 @@ void batadv_hardif_release(struct kref *ref)
 	struct batadv_hard_iface *hard_iface;
 
 	hard_iface = container_of(ref, struct batadv_hard_iface, refcount);
+	netdev_put(hard_iface->mesh_iface, &hard_iface->meshif_dev_tracker);
 	netdev_put(hard_iface->net_dev, &hard_iface->dev_tracker);
 
 	kfree_rcu(hard_iface, rcu);
@@ -75,21 +76,21 @@ void batadv_hardif_release(struct kref *ref)
  * Return: batadv_hard_iface of net_dev (with increased refcnt), NULL on errors
  */
 struct batadv_hard_iface *
-batadv_hardif_get_by_netdev(const struct net_device *net_dev)
+batadv_hardif_get_by_netdev(struct net_device *net_dev)
 {
 	struct batadv_hard_iface *hard_iface;
+	struct net_device *mesh_iface;
 
-	rcu_read_lock();
-	list_for_each_entry_rcu(hard_iface, &batadv_hardif_list, list) {
-		if (hard_iface->net_dev == net_dev &&
-		    kref_get_unless_zero(&hard_iface->refcount))
-			goto out;
-	}
+	ASSERT_RTNL();
 
-	hard_iface = NULL;
+	mesh_iface = netdev_master_upper_dev_get(net_dev);
+	if (!mesh_iface || !batadv_meshif_is_valid(mesh_iface))
+		return NULL;
+
+	hard_iface = netdev_lower_dev_get_private(mesh_iface, net_dev);
+	if (!kref_get_unless_zero(&hard_iface->refcount))
+		return NULL;
 
-out:
-	rcu_read_unlock();
 	return hard_iface;
 }
 
@@ -754,10 +755,8 @@ int batadv_hardif_enable_interface(struct net_device *net_dev,
 	netdev_hold(net_dev, &hard_iface->dev_tracker, GFP_ATOMIC);
 	hard_iface->net_dev = net_dev;
 
-	hard_iface->mesh_iface = NULL;
 	hard_iface->if_status = BATADV_IF_INACTIVE;
 
-	INIT_LIST_HEAD(&hard_iface->list);
 	INIT_HLIST_HEAD(&hard_iface->neigh_list);
 
 	mutex_init(&hard_iface->bat_iv.ogm_buff_mutex);
@@ -772,14 +771,11 @@ int batadv_hardif_enable_interface(struct net_device *net_dev,
 
 	batadv_v_hardif_init(hard_iface);
 
-	kref_get(&hard_iface->refcount);
-	list_add_tail_rcu(&hard_iface->list, &batadv_hardif_list);
-	batadv_hardif_generation++;
-
 	netdev_hold(mesh_iface, &hard_iface->meshif_dev_tracker, GFP_ATOMIC);
 	hard_iface->mesh_iface = mesh_iface;
 	bat_priv = netdev_priv(hard_iface->mesh_iface);
 
+	batadv_hardif_generation++;
 	ret = netdev_master_upper_dev_link(hard_iface->net_dev,
 					   mesh_iface, hard_iface, NULL, NULL);
 	if (ret)
@@ -876,10 +872,6 @@ void batadv_hardif_disable_interface(struct batadv_hard_iface *hard_iface)
 	if (hard_iface->if_status != BATADV_IF_INACTIVE)
 		goto out;
 
-	list_del_rcu(&hard_iface->list);
-	batadv_hardif_put(hard_iface);
-	batadv_hardif_generation++;
-
 	batadv_info(hard_iface->mesh_iface, "Removing interface: %s\n",
 		    hard_iface->net_dev->name);
 	dev_remove_pack(&hard_iface->batman_adv_ptype);
@@ -901,8 +893,8 @@ void batadv_hardif_disable_interface(struct batadv_hard_iface *hard_iface)
 	/* delete all references to this hard_iface */
 	batadv_purge_orig_ref(bat_priv);
 	batadv_purge_outstanding_packets(bat_priv, hard_iface);
-	netdev_put(hard_iface->mesh_iface, &hard_iface->meshif_dev_tracker);
 
+	batadv_hardif_generation++;
 	netdev_upper_dev_unlink(hard_iface->net_dev, hard_iface->mesh_iface);
 	batadv_hardif_recalc_extra_skbroom(hard_iface->mesh_iface);
 
@@ -910,7 +902,6 @@ void batadv_hardif_disable_interface(struct batadv_hard_iface *hard_iface)
 	if (batadv_hardif_cnt(hard_iface->mesh_iface) <= 1)
 		batadv_gw_check_client_stop(bat_priv);
 
-	hard_iface->mesh_iface = NULL;
 	batadv_hardif_put(hard_iface);
 
 out:
diff --git a/net/batman-adv/hard-interface.h b/net/batman-adv/hard-interface.h
index 1194f24f..a5fd8c52 100644
--- a/net/batman-adv/hard-interface.h
+++ b/net/batman-adv/hard-interface.h
@@ -68,7 +68,7 @@ u32 batadv_netdev_get_wifi_flags(struct net_device *net_dev);
 u32 batadv_hardif_get_wifi_flags(struct batadv_hard_iface *hard_iface);
 bool batadv_is_wifi_hardif(struct batadv_hard_iface *hard_iface);
 struct batadv_hard_iface*
-batadv_hardif_get_by_netdev(const struct net_device *net_dev);
+batadv_hardif_get_by_netdev(struct net_device *net_dev);
 int batadv_hardif_enable_interface(struct net_device *net_dev,
 				   struct net_device *mesh_iface);
 void batadv_hardif_disable_interface(struct batadv_hard_iface *hard_iface);
diff --git a/net/batman-adv/main.c b/net/batman-adv/main.c
index 60d4f600..ad26b6ce 100644
--- a/net/batman-adv/main.c
+++ b/net/batman-adv/main.c
@@ -59,10 +59,6 @@
 #include "tp_meter.h"
 #include "translation-table.h"
 
-/* List manipulations on hardif_list have to be rtnl_lock()'ed,
- * list traversals just rcu-locked
- */
-struct list_head batadv_hardif_list;
 unsigned int batadv_hardif_generation;
 static int (*batadv_rx_handler[256])(struct sk_buff *skb,
 				     struct batadv_hard_iface *recv_if);
@@ -95,7 +91,6 @@ static int __init batadv_init(void)
 	if (ret < 0)
 		return ret;
 
-	INIT_LIST_HEAD(&batadv_hardif_list);
 	batadv_algo_init();
 
 	batadv_recv_handler_init();
diff --git a/net/batman-adv/main.h b/net/batman-adv/main.h
index f68fc8b7..e3414504 100644
--- a/net/batman-adv/main.h
+++ b/net/batman-adv/main.h
@@ -226,7 +226,6 @@ static inline int batadv_print_vid(unsigned short vid)
 		return -1;
 }
 
-extern struct list_head batadv_hardif_list;
 extern unsigned int batadv_hardif_generation;
 
 extern struct workqueue_struct *batadv_event_workqueue;
diff --git a/net/batman-adv/netlink.c b/net/batman-adv/netlink.c
index 4a0fe9ec..1449f364 100644
--- a/net/batman-adv/netlink.c
+++ b/net/batman-adv/netlink.c
@@ -1205,7 +1205,9 @@ batadv_netlink_get_hardif_from_ifindex(struct batadv_priv *bat_priv,
 	if (!hard_dev)
 		return ERR_PTR(-ENODEV);
 
+	rtnl_lock();
 	hard_iface = batadv_hardif_get_by_netdev(hard_dev);
+	rtnl_unlock();
 	if (!hard_iface)
 		goto err_put_harddev;
 
diff --git a/net/batman-adv/types.h b/net/batman-adv/types.h
index 19c73168..deb0b738 100644
--- a/net/batman-adv/types.h
+++ b/net/batman-adv/types.h
@@ -208,9 +208,6 @@ struct batadv_wifi_net_device_state {
  * struct batadv_hard_iface - network device known to batman-adv
  */
 struct batadv_hard_iface {
-	/** @list: list node for batadv_hardif_list */
-	struct list_head list;
-
 	/** @if_status: status of the interface for batman-adv */
 	char if_status;
 

-- 
2.47.3


^ permalink raw reply related	[flat|nested] 8+ messages in thread

* [PATCH batadv v2 5/5] batman-adv: move hardif generation counter into batadv_priv
  2026-06-03  4:28 [PATCH batadv v2 0/5] batman-adv: drop global hard interface list Sven Eckelmann
                   ` (3 preceding siblings ...)
  2026-06-03  4:29 ` [PATCH batadv v2 4/5] batman-adv: remove global hardif list Sven Eckelmann
@ 2026-06-03  4:29 ` Sven Eckelmann
  2026-06-03  4:43 ` [PATCH batadv v2 0/5] batman-adv: drop global hard interface list Sven Eckelmann
  5 siblings, 0 replies; 8+ messages in thread
From: Sven Eckelmann @ 2026-06-03  4:29 UTC (permalink / raw)
  To: b.a.t.m.a.n; +Cc: Sven Eckelmann, Nora Schiffer

From: Nora Schiffer <neocturne@universe-factory.net>

The counter doesn't need to be global.
---
 net/batman-adv/hard-interface.c | 4 ++--
 net/batman-adv/main.c           | 1 -
 net/batman-adv/main.h           | 2 --
 net/batman-adv/netlink.c        | 2 +-
 net/batman-adv/types.h          | 3 +++
 5 files changed, 6 insertions(+), 6 deletions(-)

diff --git a/net/batman-adv/hard-interface.c b/net/batman-adv/hard-interface.c
index 3990d826..8e16b20a 100644
--- a/net/batman-adv/hard-interface.c
+++ b/net/batman-adv/hard-interface.c
@@ -775,7 +775,7 @@ int batadv_hardif_enable_interface(struct net_device *net_dev,
 	hard_iface->mesh_iface = mesh_iface;
 	bat_priv = netdev_priv(hard_iface->mesh_iface);
 
-	batadv_hardif_generation++;
+	bat_priv->hardif_generation++;
 	ret = netdev_master_upper_dev_link(hard_iface->net_dev,
 					   mesh_iface, hard_iface, NULL, NULL);
 	if (ret)
@@ -894,7 +894,7 @@ void batadv_hardif_disable_interface(struct batadv_hard_iface *hard_iface)
 	batadv_purge_orig_ref(bat_priv);
 	batadv_purge_outstanding_packets(bat_priv, hard_iface);
 
-	batadv_hardif_generation++;
+	bat_priv->hardif_generation++;
 	netdev_upper_dev_unlink(hard_iface->net_dev, hard_iface->mesh_iface);
 	batadv_hardif_recalc_extra_skbroom(hard_iface->mesh_iface);
 
diff --git a/net/batman-adv/main.c b/net/batman-adv/main.c
index ad26b6ce..f3c2e42c 100644
--- a/net/batman-adv/main.c
+++ b/net/batman-adv/main.c
@@ -59,7 +59,6 @@
 #include "tp_meter.h"
 #include "translation-table.h"
 
-unsigned int batadv_hardif_generation;
 static int (*batadv_rx_handler[256])(struct sk_buff *skb,
 				     struct batadv_hard_iface *recv_if);
 
diff --git a/net/batman-adv/main.h b/net/batman-adv/main.h
index e3414504..e738758e 100644
--- a/net/batman-adv/main.h
+++ b/net/batman-adv/main.h
@@ -226,8 +226,6 @@ static inline int batadv_print_vid(unsigned short vid)
 		return -1;
 }
 
-extern unsigned int batadv_hardif_generation;
-
 extern struct workqueue_struct *batadv_event_workqueue;
 
 int batadv_mesh_init(struct net_device *mesh_iface);
diff --git a/net/batman-adv/netlink.c b/net/batman-adv/netlink.c
index 1449f364..557a5539 100644
--- a/net/batman-adv/netlink.c
+++ b/net/batman-adv/netlink.c
@@ -962,7 +962,7 @@ batadv_netlink_dump_hardif(struct sk_buff *msg, struct netlink_callback *cb)
 	bat_priv = netdev_priv(mesh_iface);
 
 	rtnl_lock();
-	cb->seq = batadv_hardif_generation << 1 | 1;
+	cb->seq = bat_priv->hardif_generation << 1 | 1;
 
 	netdev_for_each_lower_private(mesh_iface, hard_iface, iter) {
 		if (i++ < skip)
diff --git a/net/batman-adv/types.h b/net/batman-adv/types.h
index deb0b738..5ea04c32 100644
--- a/net/batman-adv/types.h
+++ b/net/batman-adv/types.h
@@ -1658,6 +1658,9 @@ struct batadv_priv {
 	/** @tp_num: number of currently active tp sessions */
 	atomic_t tp_num;
 
+	/** @hardif_generation: generation counter added to netlink hardif dumps */
+	unsigned int hardif_generation;
+
 	/** @orig_work: work queue callback item for orig node purging */
 	struct delayed_work orig_work;
 

-- 
2.47.3


^ permalink raw reply related	[flat|nested] 8+ messages in thread

* Re: [PATCH batadv v2 0/5] batman-adv: drop global hard interface list
  2026-06-03  4:28 [PATCH batadv v2 0/5] batman-adv: drop global hard interface list Sven Eckelmann
                   ` (4 preceding siblings ...)
  2026-06-03  4:29 ` [PATCH batadv v2 5/5] batman-adv: move hardif generation counter into batadv_priv Sven Eckelmann
@ 2026-06-03  4:43 ` Sven Eckelmann
  5 siblings, 0 replies; 8+ messages in thread
From: Sven Eckelmann @ 2026-06-03  4:43 UTC (permalink / raw)
  To: b.a.t.m.a.n; +Cc: Nora Schiffer


[-- Attachment #1.1: Type: text/plain, Size: 830 bytes --]

On Wednesday, 3 June 2026 06:28:59 CEST Sven Eckelmann wrote:
> This RFC is on purpose not Signed-off-by

Looks like I forgot to mark it as an RFC. Anyway, just consider it an RFC to 
get the discussion started again and make sure that both sides are ok with the 
adjustments.

Please make sure that this is not yet an endorsement of this specific version 
of the patchset. I still have to sit down again and make sure that it makes 
sense (tm). But I am at least convinced at the moment that the idea behind the 
patchset is good.

> I will later post an range-diff which contains all the changes.

git range-diff v2025.3..ecsv/schiffer-netdev-orig 3f5b367f76482a714b4263bf2b1bddb0d49831ca..6b1570a75d32eceb827d5dd826681126205f87de

See v1-v2.rdiff. Please double check that I actually addressed my old 
comments.

Regards,
	Sven

[-- Attachment #1.2: v1-v2.rdiff --]
[-- Type: text/plain, Size: 14587 bytes --]

1:  cfcf1328 < -:  -------- batman-adv: store hard_iface as iflink private data
-:  -------- > 1:  0c1926bf batman-adv: tt: directly retrieve wifi flags of net_device
2:  d97e5558 ! 2:  add14bf4 batman-adv: only create hardif while a netdev is part of a mesh
    @@
      ## Metadata ##
    -Author: Matthias Schiffer <mschiffer@universe-factory.net>
    +Author: Nora Schiffer <neocturne@universe-factory.net>
     
      ## Commit message ##
         batman-adv: only create hardif while a netdev is part of a mesh
    @@ Commit message
         batadv_hardif_enable_interface(), and batadv_hardif_remove_interface()
         can be dropped altogether.
     
    -    Signed-off-by: Matthias Schiffer <mschiffer@universe-factory.net>
    -
      ## net/batman-adv/hard-interface.c ##
     @@ net/batman-adv/hard-interface.c: batadv_hardif_deactivate_interface(struct batadv_hard_iface *hard_iface)
      }
    @@ net/batman-adv/hard-interface.c: batadv_hardif_deactivate_interface(struct batad
     +	struct batadv_hard_iface *hard_iface;
      	unsigned int required_mtu;
      	unsigned int hardif_mtu;
    + 	bool fragmentation;
      	int ret;
      
    +-	hardif_mtu = READ_ONCE(hard_iface->net_dev->mtu);
     +	ASSERT_RTNL();
     +
     +	if (!batadv_is_valid_iface(net_dev))
     +		return -EINVAL;
     +
    -+	hard_iface = kzalloc(sizeof(*hard_iface), GFP_ATOMIC);
    ++	hardif_mtu = READ_ONCE(net_dev->mtu);
    + 	required_mtu = READ_ONCE(mesh_iface->mtu) + max_header_len;
    + 
    + 	if (hardif_mtu < ETH_MIN_MTU + max_header_len)
    + 		return -EINVAL;
    + 
    +-	if (hard_iface->if_status != BATADV_IF_NOT_IN_USE)
    +-		goto out;
    ++	hard_iface = kzalloc_obj(*hard_iface, GFP_ATOMIC);
     +	if (!hard_iface)
     +		return -ENOMEM;
     +
    @@ net/batman-adv/hard-interface.c: batadv_hardif_deactivate_interface(struct batad
     +	kref_init(&hard_iface->refcount);
     +
     +	hard_iface->num_bcasts = BATADV_NUM_BCASTS_DEFAULT;
    -+	hard_iface->wifi_flags = batadv_wifi_flags_evaluate(net_dev);
     +	if (batadv_is_wifi_hardif(hard_iface))
     +		hard_iface->num_bcasts = BATADV_NUM_BCASTS_WIRELESS;
     +
    -+	atomic_set(&hard_iface->hop_penalty, 0);
    ++	WRITE_ONCE(hard_iface->hop_penalty, 0);
     +
     +	batadv_v_hardif_init(hard_iface);
    -+
    -+	kref_get(&hard_iface->refcount);
    + 
    + 	kref_get(&hard_iface->refcount);
     +	list_add_tail_rcu(&hard_iface->list, &batadv_hardif_list);
     +	batadv_hardif_generation++;
    -+
    - 	hardif_mtu = READ_ONCE(hard_iface->net_dev->mtu);
    - 	required_mtu = READ_ONCE(mesh_iface->mtu) + max_header_len;
    - 
    --	if (hardif_mtu < ETH_MIN_MTU + max_header_len)
    --		return -EINVAL;
    --
    --	if (hard_iface->if_status != BATADV_IF_NOT_IN_USE)
    --		goto out;
    --
    --	kref_get(&hard_iface->refcount);
    -+	if (hardif_mtu < ETH_MIN_MTU + max_header_len) {
    -+		ret = -EINVAL;
    -+		goto err_put;
    -+	}
      
      	netdev_hold(mesh_iface, &hard_iface->meshif_dev_tracker, GFP_ATOMIC);
      	hard_iface->mesh_iface = mesh_iface;
    @@ net/batman-adv/hard-interface.c: int batadv_hardif_enable_interface(struct batad
      
     -	hard_iface->if_status = BATADV_IF_INACTIVE;
     -
    --	kref_get(&hard_iface->refcount);
    + 	kref_get(&hard_iface->refcount);
      	hard_iface->batman_adv_ptype.type = ethertype;
      	hard_iface->batman_adv_ptype.func = batadv_batman_skb_recv;
    - 	hard_iface->batman_adv_ptype.dev = hard_iface->net_dev;
     @@ net/batman-adv/hard-interface.c: int batadv_hardif_enable_interface(struct batadv_hard_iface *hard_iface,
      	if (bat_priv->algo_ops->iface.enabled)
      		bat_priv->algo_ops->iface.enabled(hard_iface);
    @@ net/batman-adv/hard-interface.c: int batadv_hardif_enable_interface(struct batad
      	return 0;
      
      err_upper:
    -@@ net/batman-adv/hard-interface.c: int batadv_hardif_enable_interface(struct batadv_hard_iface *hard_iface,
    - err_dev:
    - 	hard_iface->mesh_iface = NULL;
    - 	netdev_put(mesh_iface, &hard_iface->meshif_dev_tracker);
    -+err_put:
    - 	batadv_hardif_put(hard_iface);
    - 	return ret;
    - }
     @@ net/batman-adv/hard-interface.c: void batadv_hardif_disable_interface(struct batadv_hard_iface *hard_iface)
      	struct batadv_priv *bat_priv = netdev_priv(hard_iface->mesh_iface);
      	struct batadv_hard_iface *primary_if = NULL;
    @@ net/batman-adv/hard-interface.c: void batadv_hardif_disable_interface(struct bat
      		goto out;
      
     +	list_del_rcu(&hard_iface->list);
    ++	batadv_hardif_put(hard_iface);
     +	batadv_hardif_generation++;
     +
      	batadv_info(hard_iface->mesh_iface, "Removing interface: %s\n",
    @@ net/batman-adv/hard-interface.c: void batadv_hardif_disable_interface(struct bat
     -	if (!batadv_is_valid_iface(net_dev))
     -		return NULL;
     -
    --	hard_iface = kzalloc(sizeof(*hard_iface), GFP_ATOMIC);
    +-	hard_iface = kzalloc_obj(*hard_iface, GFP_ATOMIC);
     -	if (!hard_iface)
     -		return NULL;
     -
    @@ net/batman-adv/hard-interface.c: void batadv_hardif_disable_interface(struct bat
     -	kref_init(&hard_iface->refcount);
     -
     -	hard_iface->num_bcasts = BATADV_NUM_BCASTS_DEFAULT;
    --	hard_iface->wifi_flags = batadv_wifi_flags_evaluate(net_dev);
     -	if (batadv_is_wifi_hardif(hard_iface))
     -		hard_iface->num_bcasts = BATADV_NUM_BCASTS_WIRELESS;
     -
    --	atomic_set(&hard_iface->hop_penalty, 0);
    +-	WRITE_ONCE(hard_iface->hop_penalty, 0);
     -
     -	batadv_v_hardif_init(hard_iface);
     -
    @@ net/batman-adv/hard-interface.c: void batadv_hardif_disable_interface(struct bat
       * batadv_hard_if_event_meshif() - Handle events for mesh interfaces
       * @event: NETDEV_* event to handle
     @@ net/batman-adv/hard-interface.c: static int batadv_hard_if_event(struct notifier_block *this,
    - 		return batadv_hard_if_event_meshif(event, net_dev);
    + 	batadv_wifi_net_device_event(event, net_dev);
      
      	hard_iface = batadv_hardif_get_by_netdev(net_dev);
     -	if (!hard_iface && (event == NETDEV_REGISTER ||
    @@ net/batman-adv/hard-interface.c: static int batadv_hard_if_event(struct notifier
      		if (hard_iface->mesh_iface)
     
      ## net/batman-adv/hard-interface.h ##
    -@@ net/batman-adv/hard-interface.h: bool batadv_is_cfg80211_hardif(struct batadv_hard_iface *hard_iface);
    +@@ net/batman-adv/hard-interface.h: u32 batadv_hardif_get_wifi_flags(struct batadv_hard_iface *hard_iface);
      bool batadv_is_wifi_hardif(struct batadv_hard_iface *hard_iface);
      struct batadv_hard_iface*
      batadv_hardif_get_by_netdev(const struct net_device *net_dev);
3:  61023efc ! 3:  9f62d7ce batman-adv: remove BATADV_IF_NOT_IN_USE hardif state
    @@
      ## Metadata ##
    -Author: Matthias Schiffer <mschiffer@universe-factory.net>
    +Author: Nora Schiffer <neocturne@universe-factory.net>
     
      ## Commit message ##
         batman-adv: remove BATADV_IF_NOT_IN_USE hardif state
    @@ Commit message
         With hardifs only existing while an interface is part of a mesh, the
         BATADV_IF_NOT_IN_USE state has become redundant.
     
    -    Signed-off-by: Matthias Schiffer <mschiffer@universe-factory.net>
    -    Acked-by: Sven Eckelmann <sven@narfation.org>
    -
      ## net/batman-adv/bat_iv_ogm.c ##
     @@ net/batman-adv/bat_iv_ogm.c: static void batadv_iv_ogm_schedule_buff(struct batadv_hard_iface *hard_iface)
      
4:  aaa80559 ! 4:  f35d12ce batman-adv: remove global hardif list
    @@
      ## Metadata ##
    -Author: Matthias Schiffer <mschiffer@universe-factory.net>
    +Author: Nora Schiffer <neocturne@universe-factory.net>
     
      ## Commit message ##
         batman-adv: remove global hardif list
    @@ Commit message
         use netdev_master_upper_dev_get()+netdev_lower_dev_get_private() to find
         the hardif corresponding to a netdev.
     
    -    Signed-off-by: Matthias Schiffer <mschiffer@universe-factory.net>
    -
      ## net/batman-adv/hard-interface.c ##
    +@@ net/batman-adv/hard-interface.c: void batadv_hardif_release(struct kref *ref)
    + 	struct batadv_hard_iface *hard_iface;
    + 
    + 	hard_iface = container_of(ref, struct batadv_hard_iface, refcount);
    ++	netdev_put(hard_iface->mesh_iface, &hard_iface->meshif_dev_tracker);
    + 	netdev_put(hard_iface->net_dev, &hard_iface->dev_tracker);
    + 
    + 	kfree_rcu(hard_iface, rcu);
     @@ net/batman-adv/hard-interface.c: void batadv_hardif_release(struct kref *ref)
       * Return: batadv_hard_iface of net_dev (with increased refcnt), NULL on errors
       */
    @@ net/batman-adv/hard-interface.c: void batadv_hardif_release(struct kref *ref)
     -		    kref_get_unless_zero(&hard_iface->refcount))
     -			goto out;
     -	}
    ++	ASSERT_RTNL();
    + 
    +-	hard_iface = NULL;
     +	mesh_iface = netdev_master_upper_dev_get(net_dev);
     +	if (!mesh_iface || !batadv_meshif_is_valid(mesh_iface))
     +		return NULL;
    - 
    --	hard_iface = NULL;
    ++
     +	hard_iface = netdev_lower_dev_get_private(mesh_iface, net_dev);
     +	if (!kref_get_unless_zero(&hard_iface->refcount))
     +		return NULL;
    @@ net/batman-adv/hard-interface.c: void batadv_hardif_release(struct kref *ref)
      }
      
     @@ net/batman-adv/hard-interface.c: int batadv_hardif_enable_interface(struct net_device *net_dev,
    - 	hard_iface->mesh_iface = NULL;
    + 	netdev_hold(net_dev, &hard_iface->dev_tracker, GFP_ATOMIC);
    + 	hard_iface->net_dev = net_dev;
    + 
    +-	hard_iface->mesh_iface = NULL;
      	hard_iface->if_status = BATADV_IF_INACTIVE;
      
     -	INIT_LIST_HEAD(&hard_iface->list);
    @@ net/batman-adv/hard-interface.c: int batadv_hardif_enable_interface(struct net_d
      
      	mutex_init(&hard_iface->bat_iv.ogm_buff_mutex);
     @@ net/batman-adv/hard-interface.c: int batadv_hardif_enable_interface(struct net_device *net_dev,
    + 
      	batadv_v_hardif_init(hard_iface);
      
    - 	kref_get(&hard_iface->refcount);
    +-	kref_get(&hard_iface->refcount);
     -	list_add_tail_rcu(&hard_iface->list, &batadv_hardif_list);
     -	batadv_hardif_generation++;
    - 
    - 	hardif_mtu = READ_ONCE(hard_iface->net_dev->mtu);
    - 	required_mtu = READ_ONCE(mesh_iface->mtu) + max_header_len;
    -@@ net/batman-adv/hard-interface.c: int batadv_hardif_enable_interface(struct net_device *net_dev,
    +-
    + 	netdev_hold(mesh_iface, &hard_iface->meshif_dev_tracker, GFP_ATOMIC);
      	hard_iface->mesh_iface = mesh_iface;
      	bat_priv = netdev_priv(hard_iface->mesh_iface);
      
    @@ net/batman-adv/hard-interface.c: void batadv_hardif_disable_interface(struct bat
      		goto out;
      
     -	list_del_rcu(&hard_iface->list);
    +-	batadv_hardif_put(hard_iface);
     -	batadv_hardif_generation++;
     -
      	batadv_info(hard_iface->mesh_iface, "Removing interface: %s\n",
      		    hard_iface->net_dev->name);
      	dev_remove_pack(&hard_iface->batman_adv_ptype);
     @@ net/batman-adv/hard-interface.c: void batadv_hardif_disable_interface(struct batadv_hard_iface *hard_iface)
    + 	/* delete all references to this hard_iface */
    + 	batadv_purge_orig_ref(bat_priv);
      	batadv_purge_outstanding_packets(bat_priv, hard_iface);
    - 	netdev_put(hard_iface->mesh_iface, &hard_iface->meshif_dev_tracker);
    +-	netdev_put(hard_iface->mesh_iface, &hard_iface->meshif_dev_tracker);
      
     +	batadv_hardif_generation++;
      	netdev_upper_dev_unlink(hard_iface->net_dev, hard_iface->mesh_iface);
      	batadv_hardif_recalc_extra_skbroom(hard_iface->mesh_iface);
      
    +@@ net/batman-adv/hard-interface.c: void batadv_hardif_disable_interface(struct batadv_hard_iface *hard_iface)
    + 	if (batadv_hardif_cnt(hard_iface->mesh_iface) <= 1)
    + 		batadv_gw_check_client_stop(bat_priv);
    + 
    +-	hard_iface->mesh_iface = NULL;
    + 	batadv_hardif_put(hard_iface);
    + 
    + out:
     
      ## net/batman-adv/hard-interface.h ##
    -@@ net/batman-adv/hard-interface.h: struct net_device *batadv_get_real_netdev(struct net_device *net_device);
    - bool batadv_is_cfg80211_hardif(struct batadv_hard_iface *hard_iface);
    +@@ net/batman-adv/hard-interface.h: u32 batadv_netdev_get_wifi_flags(struct net_device *net_dev);
    + u32 batadv_hardif_get_wifi_flags(struct batadv_hard_iface *hard_iface);
      bool batadv_is_wifi_hardif(struct batadv_hard_iface *hard_iface);
      struct batadv_hard_iface*
     -batadv_hardif_get_by_netdev(const struct net_device *net_dev);
    @@ net/batman-adv/main.h: static inline int batadv_print_vid(unsigned short vid)
      
      extern struct workqueue_struct *batadv_event_workqueue;
     
    + ## net/batman-adv/netlink.c ##
    +@@ net/batman-adv/netlink.c: batadv_netlink_get_hardif_from_ifindex(struct batadv_priv *bat_priv,
    + 	if (!hard_dev)
    + 		return ERR_PTR(-ENODEV);
    + 
    ++	rtnl_lock();
    + 	hard_iface = batadv_hardif_get_by_netdev(hard_dev);
    ++	rtnl_unlock();
    + 	if (!hard_iface)
    + 		goto err_put_harddev;
    + 
    +
      ## net/batman-adv/types.h ##
    -@@ net/batman-adv/types.h: enum batadv_hard_iface_wifi_flags {
    +@@ net/batman-adv/types.h: struct batadv_wifi_net_device_state {
       * struct batadv_hard_iface - network device known to batman-adv
       */
      struct batadv_hard_iface {
5:  0d0b32d8 ! 5:  6b1570a7 batman-adv: move hardif generation counter into batadv_priv
    @@
      ## Metadata ##
    -Author: Matthias Schiffer <mschiffer@universe-factory.net>
    +Author: Nora Schiffer <neocturne@universe-factory.net>
     
      ## Commit message ##
         batman-adv: move hardif generation counter into batadv_priv
     
         The counter doesn't need to be global.
     
    -    Signed-off-by: Matthias Schiffer <mschiffer@universe-factory.net>
    -    Acked-by: Sven Eckelmann <sven@narfation.org>
    -
      ## net/batman-adv/hard-interface.c ##
     @@ net/batman-adv/hard-interface.c: int batadv_hardif_enable_interface(struct net_device *net_dev,
      	hard_iface->mesh_iface = mesh_iface;
    @@ net/batman-adv/hard-interface.c: int batadv_hardif_enable_interface(struct net_d
      					   mesh_iface, hard_iface, NULL, NULL);
      	if (ret)
     @@ net/batman-adv/hard-interface.c: void batadv_hardif_disable_interface(struct batadv_hard_iface *hard_iface)
    + 	batadv_purge_orig_ref(bat_priv);
      	batadv_purge_outstanding_packets(bat_priv, hard_iface);
    - 	netdev_put(hard_iface->mesh_iface, &hard_iface->meshif_dev_tracker);
      
     -	batadv_hardif_generation++;
     +	bat_priv->hardif_generation++;

[-- Attachment #2: This is a digitally signed message part. --]
[-- Type: application/pgp-signature, Size: 228 bytes --]

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH batadv v2 1/5] batman-adv: tt: directly retrieve wifi flags of net_device
  2026-06-03  4:29 ` [PATCH batadv v2 1/5] batman-adv: tt: directly retrieve wifi flags of net_device Sven Eckelmann
@ 2026-06-03  4:44   ` Sven Eckelmann
  0 siblings, 0 replies; 8+ messages in thread
From: Sven Eckelmann @ 2026-06-03  4:44 UTC (permalink / raw)
  To: b.a.t.m.a.n

[-- Attachment #1: Type: text/plain, Size: 108 bytes --]

On Wednesday, 3 June 2026 06:29:00 CEST Sven Eckelmann wrote:
> +       u32 wifi_flags;

u32 wifi_flags = 0;

[-- Attachment #2: This is a digitally signed message part. --]
[-- Type: application/pgp-signature, Size: 228 bytes --]

^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2026-06-03  4:44 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-06-03  4:28 [PATCH batadv v2 0/5] batman-adv: drop global hard interface list Sven Eckelmann
2026-06-03  4:29 ` [PATCH batadv v2 1/5] batman-adv: tt: directly retrieve wifi flags of net_device Sven Eckelmann
2026-06-03  4:44   ` Sven Eckelmann
2026-06-03  4:29 ` [PATCH batadv v2 2/5] batman-adv: only create hardif while a netdev is part of a mesh Sven Eckelmann
2026-06-03  4:29 ` [PATCH batadv v2 3/5] batman-adv: remove BATADV_IF_NOT_IN_USE hardif state Sven Eckelmann
2026-06-03  4:29 ` [PATCH batadv v2 4/5] batman-adv: remove global hardif list Sven Eckelmann
2026-06-03  4:29 ` [PATCH batadv v2 5/5] batman-adv: move hardif generation counter into batadv_priv Sven Eckelmann
2026-06-03  4:43 ` [PATCH batadv v2 0/5] batman-adv: drop global hard interface list Sven Eckelmann

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox