#include <linux/if_arp.h>
-#define MIN(x, y) ((x) < (y) ? (x) : (y))
-
/* protect update critical side of if_list - but not the content */
static DEFINE_SPINLOCK(if_list_lock);
+static void hardif_free_rcu(struct rcu_head *rcu)
+{
+ struct batman_if *batman_if;
+
+ batman_if = container_of(rcu, struct batman_if, rcu);
+ dev_put(batman_if->net_dev);
+ kref_put(&batman_if->refcount, hardif_free_ref);
+}
+
struct batman_if *get_batman_if_by_netdev(struct net_device *net_dev)
{
struct batman_if *batman_if;
out:
if (batman_if)
- hardif_hold(batman_if);
+ kref_get(&batman_if->refcount);
rcu_read_unlock();
return batman_if;
out:
if (batman_if)
- hardif_hold(batman_if);
+ kref_get(&batman_if->refcount);
rcu_read_unlock();
return batman_if;
struct batman_if *old_if;
if (batman_if)
- hardif_hold(batman_if);
+ kref_get(&batman_if->refcount);
old_if = bat_priv->primary_if;
bat_priv->primary_if = batman_if;
if (old_if)
- hardif_put(old_if);
+ kref_put(&old_if->refcount, hardif_free_ref);
if (!bat_priv->primary_if)
return;
* (have MTU > 1500 + BAT_HEADER_LEN) */
int min_mtu = ETH_DATA_LEN;
- if (atomic_read(&bat_priv->frag_enabled))
+ if (atomic_read(&bat_priv->fragmentation))
goto out;
rcu_read_lock();
if (batman_if->soft_iface != soft_iface)
continue;
- min_mtu = MIN(batman_if->net_dev->mtu - BAT_HEADER_LEN,
- min_mtu);
+ min_mtu = min_t(int, batman_if->net_dev->mtu - BAT_HEADER_LEN,
+ min_mtu);
}
rcu_read_unlock();
out:
batman_if->batman_adv_ptype.type = __constant_htons(ETH_P_BATMAN);
batman_if->batman_adv_ptype.func = batman_skb_recv;
batman_if->batman_adv_ptype.dev = batman_if->net_dev;
- hardif_hold(batman_if);
+ kref_get(&batman_if->refcount);
dev_add_pack(&batman_if->batman_adv_ptype);
atomic_set(&batman_if->seqno, 1);
bat_info(batman_if->soft_iface, "Adding interface: %s\n",
batman_if->net_dev->name);
- if (atomic_read(&bat_priv->frag_enabled) && batman_if->net_dev->mtu <
+ if (atomic_read(&bat_priv->fragmentation) && batman_if->net_dev->mtu <
ETH_DATA_LEN + BAT_HEADER_LEN)
bat_info(batman_if->soft_iface,
"The MTU of interface %s is too small (%i) to handle "
batman_if->net_dev->name, batman_if->net_dev->mtu,
ETH_DATA_LEN + BAT_HEADER_LEN);
- if (!atomic_read(&bat_priv->frag_enabled) && batman_if->net_dev->mtu <
+ if (!atomic_read(&bat_priv->fragmentation) && batman_if->net_dev->mtu <
ETH_DATA_LEN + BAT_HEADER_LEN)
bat_info(batman_if->soft_iface,
"The MTU of interface %s is too small (%i) to handle "
bat_info(batman_if->soft_iface, "Removing interface: %s\n",
batman_if->net_dev->name);
dev_remove_pack(&batman_if->batman_adv_ptype);
- hardif_put(batman_if);
+ kref_put(&batman_if->refcount, hardif_free_ref);
bat_priv->num_ifaces--;
orig_hash_del_if(batman_if, bat_priv->num_ifaces);
set_primary_if(bat_priv, new_if);
if (new_if)
- hardif_put(new_if);
+ kref_put(&new_if->refcount, hardif_free_ref);
}
kfree(batman_if->packet_buff);
batman_if->soft_iface = NULL;
batman_if->if_status = IF_NOT_IN_USE;
INIT_LIST_HEAD(&batman_if->list);
- atomic_set(&batman_if->refcnt, 0);
- hardif_hold(batman_if);
+ kref_init(&batman_if->refcount);
check_known_mac_addr(batman_if->net_dev);
spin_unlock(&if_list_lock);
/* extra reference for return */
- hardif_hold(batman_if);
+ kref_get(&batman_if->refcount);
return batman_if;
free_if:
return;
batman_if->if_status = IF_TO_BE_REMOVED;
- synchronize_rcu();
sysfs_del_hardif(&batman_if->hardif_obj);
- hardif_put(batman_if);
+ call_rcu(&batman_if->rcu, hardif_free_rcu);
}
void hardif_remove_interfaces(void)
update_min_mtu(batman_if->soft_iface);
break;
case NETDEV_CHANGEADDR:
- if (batman_if->if_status == IF_NOT_IN_USE) {
- hardif_put(batman_if);
- goto out;
- }
+ if (batman_if->if_status == IF_NOT_IN_USE)
+ goto hardif_put;
check_known_mac_addr(batman_if->net_dev);
update_mac_addresses(batman_if);
default:
break;
};
- hardif_put(batman_if);
+hardif_put:
+ kref_put(&batman_if->refcount, hardif_free_ref);
out:
return NOTIFY_DONE;
}