diff --git a/net/batman-adv/translation-table.c b/net/batman-adv/translation-table.c index 44a8cf89382c..1c22db348267 100644 --- a/net/batman-adv/translation-table.c +++ b/net/batman-adv/translation-table.c @@ -41,6 +41,7 @@ #include #include #include +#include #include #include #include @@ -693,6 +694,32 @@ static void batadv_tt_local_add_roam(struct batadv_priv *bat_priv, batadv_tt_global_free(bat_priv, tt_global, "Roaming canceled"); } +/** + * batadv_tt_iif_is_wifi() - check whether a client is connected via wifi + * @net: namespace to search the incoming interface in + * @ifindex: index of the interface where the client is connected to + * + * Return: true if @ifindex refers to a wifi interface, false otherwise (which + * includes the case of an unknown or missing incoming interface). + */ +static bool batadv_tt_iif_is_wifi(struct net *net, int ifindex) +{ + struct net_device *in_dev; + u32 wifi_flags; + + if (ifindex == BATADV_NULL_IFINDEX) + return false; + + in_dev = dev_get_by_index(net, ifindex); + if (!in_dev) + return false; + + wifi_flags = batadv_netdev_get_wifi_flags(in_dev); + dev_put(in_dev); + + return batadv_is_wifi(wifi_flags); +} + /** * batadv_tt_local_add() - add a new client to the local table or update an * existing client @@ -712,12 +739,10 @@ bool batadv_tt_local_add(struct net_device *mesh_iface, const u8 *addr, struct batadv_priv *bat_priv = netdev_priv(mesh_iface); struct batadv_tt_global_entry *tt_global = NULL; struct batadv_tt_local_entry *tt_local; - struct net *net = dev_net(mesh_iface); - struct net_device *in_dev = NULL; struct batadv_meshif_vlan *vlan; bool roamed_back = false; - bool iif_is_wifi = false; int packet_size_max; + bool iif_is_wifi; bool ret = false; u8 remote_flags; int hash_added; @@ -725,14 +750,7 @@ bool batadv_tt_local_add(struct net_device *mesh_iface, const u8 *addr, u32 match_mark; bool modified; - if (ifindex != BATADV_NULL_IFINDEX) - in_dev = dev_get_by_index(net, ifindex); - - if (in_dev) { - u32 wifi_flags = batadv_netdev_get_wifi_flags(in_dev); - - iif_is_wifi = batadv_is_wifi(wifi_flags); - } + iif_is_wifi = batadv_tt_iif_is_wifi(dev_net(mesh_iface), ifindex); tt_local = batadv_tt_local_hash_find(bat_priv, addr, vid); @@ -881,7 +899,6 @@ check_roaming: ret = true; out: - dev_put(in_dev); batadv_tt_local_entry_put(tt_local); batadv_tt_global_entry_put(tt_global); return ret;