]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
batman-adv: tt: directly retrieve wifi flags of net_device
authorSven Eckelmann <sven@narfation.org>
Sun, 31 May 2026 13:03:25 +0000 (15:03 +0200)
committerSven Eckelmann <sven@narfation.org>
Wed, 3 Jun 2026 06:27:17 +0000 (08:27 +0200)
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
net/batman-adv/hard-interface.h
net/batman-adv/translation-table.c

index bb3c31b5f259d620c7175800863367a7bc4cf25a..43ebf86e7b3686796e21ae1537a9939ba1b01973 100644 (file)
@@ -366,22 +366,19 @@ out:
 }
 
 /**
- * batadv_hardif_get_wifi_flags() - retrieve wifi flags for hard_iface
- * @hard_iface: the device to check
+ * 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_hardif_get_wifi_flags(struct batadv_hard_iface *hard_iface)
+u32 batadv_netdev_get_wifi_flags(struct net_device *net_dev)
 {
        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,
+                                             &net_dev,
                                              batadv_wifi_net_devices_params);
        if (device_state)
                wifi_flags = READ_ONCE(device_state->wifi_flags);
@@ -390,6 +387,20 @@ u32 batadv_hardif_get_wifi_flags(struct batadv_hard_iface *hard_iface)
        return wifi_flags;
 }
 
+/**
+ * batadv_hardif_get_wifi_flags() - retrieve wifi flags for hard_iface
+ * @hard_iface: the device to check
+ *
+ * Return: batadv_hard_iface_wifi_flags flags of the device
+ */
+u32 batadv_hardif_get_wifi_flags(struct batadv_hard_iface *hard_iface)
+{
+       if (!hard_iface)
+               return 0;
+
+       return batadv_netdev_get_wifi_flags(hard_iface->net_dev);
+}
+
 /**
  * batadv_is_wifi_hardif() - check if the given hardif is a wifi interface
  * @hard_iface: the device to check
index 089e65c8a4817bc1b0dfcecbdd138029560d8665..822e7e378c4d102e7f16a72f49818ebbd9aa1a4a 100644 (file)
@@ -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*
index 44bbaa3bb37d10d6a6864c9536b0a00edeca6206..c346e43d47b9b5887de545c7c1c095a20bdaa4fc 100644 (file)
@@ -596,20 +596,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);
 
@@ -684,7 +687,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;
@@ -743,7 +746,7 @@ check_roaming:
         */
        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;
@@ -767,7 +770,6 @@ check_roaming:
 
        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);