Release 4.11 net/batman-adv/translation-table.c
/* Copyright (C) 2007-2017 B.A.T.M.A.N. contributors:
*
* Marek Lindner, Simon Wunderlich, Antonio Quartulli
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of version 2 of the GNU General Public
* License as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, see <http://www.gnu.org/licenses/>.
*/
#include "translation-table.h"
#include "main.h"
#include <linux/atomic.h>
#include <linux/bitops.h>
#include <linux/bug.h>
#include <linux/byteorder/generic.h>
#include <linux/cache.h>
#include <linux/compiler.h>
#include <linux/crc32c.h>
#include <linux/errno.h>
#include <linux/etherdevice.h>
#include <linux/fs.h>
#include <linux/if_ether.h>
#include <linux/init.h>
#include <linux/jhash.h>
#include <linux/jiffies.h>
#include <linux/kernel.h>
#include <linux/kref.h>
#include <linux/list.h>
#include <linux/lockdep.h>
#include <linux/netdevice.h>
#include <linux/netlink.h>
#include <linux/rculist.h>
#include <linux/rcupdate.h>
#include <linux/seq_file.h>
#include <linux/skbuff.h>
#include <linux/slab.h>
#include <linux/spinlock.h>
#include <linux/stddef.h>
#include <linux/string.h>
#include <linux/workqueue.h>
#include <net/genetlink.h>
#include <net/netlink.h>
#include <net/sock.h>
#include <uapi/linux/batman_adv.h>
#include "bridge_loop_avoidance.h"
#include "hard-interface.h"
#include "hash.h"
#include "log.h"
#include "netlink.h"
#include "originator.h"
#include "packet.h"
#include "soft-interface.h"
#include "tvlv.h"
static struct kmem_cache *batadv_tl_cache __read_mostly;
static struct kmem_cache *batadv_tg_cache __read_mostly;
static struct kmem_cache *batadv_tt_orig_cache __read_mostly;
static struct kmem_cache *batadv_tt_change_cache __read_mostly;
static struct kmem_cache *batadv_tt_req_cache __read_mostly;
static struct kmem_cache *batadv_tt_roam_cache __read_mostly;
/* hash class keys */
static struct lock_class_key batadv_tt_local_hash_lock_class_key;
static struct lock_class_key batadv_tt_global_hash_lock_class_key;
static void batadv_send_roam_adv(struct batadv_priv *bat_priv, u8 *client,
unsigned short vid,
struct batadv_orig_node *orig_node);
static void batadv_tt_purge(struct work_struct *work);
static void
batadv_tt_global_del_orig_list(struct batadv_tt_global_entry *tt_global_entry);
static void batadv_tt_global_del(struct batadv_priv *bat_priv,
struct batadv_orig_node *orig_node,
const unsigned char *addr,
unsigned short vid, const char *message,
bool roaming);
/**
* batadv_compare_tt - check if two TT entries are the same
* @node: the list element pointer of the first TT entry
* @data2: pointer to the tt_common_entry of the second TT entry
*
* Compare the MAC address and the VLAN ID of the two TT entries and check if
* they are the same TT client.
* Return: true if the two TT clients are the same, false otherwise
*/
static bool batadv_compare_tt(const struct hlist_node *node, const void *data2)
{
const void *data1 = container_of(node, struct batadv_tt_common_entry,
hash_entry);
const struct batadv_tt_common_entry *tt1 = data1;
const struct batadv_tt_common_entry *tt2 = data2;
return (tt1->vid == tt2->vid) && batadv_compare_eth(data1, data2);
}
Contributors
Person | Tokens | Prop | Commits | CommitProp |
Marek Lindner | 59 | 89.39% | 2 | 28.57% |
Sven Eckelmann | 6 | 9.09% | 4 | 57.14% |
Ding Tianhong | 1 | 1.52% | 1 | 14.29% |
Total | 66 | 100.00% | 7 | 100.00% |
/**
* batadv_choose_tt - return the index of the tt entry in the hash table
* @data: pointer to the tt_common_entry object to map
* @size: the size of the hash table
*
* Return: the hash index where the object represented by 'data' should be
* stored at.
*/
static inline u32 batadv_choose_tt(const void *data, u32 size)
{
struct batadv_tt_common_entry *tt;
u32 hash = 0;
tt = (struct batadv_tt_common_entry *)data;
hash = jhash(&tt->addr, ETH_ALEN, hash);
hash = jhash(&tt->vid, sizeof(tt->vid), hash);
return hash % size;
}
Contributors
Person | Tokens | Prop | Commits | CommitProp |
Antonio Quartulli | 63 | 87.50% | 1 | 33.33% |
Sven Eckelmann | 9 | 12.50% | 2 | 66.67% |
Total | 72 | 100.00% | 3 | 100.00% |
/**
* batadv_tt_hash_find - look for a client in the given hash table
* @hash: the hash table to search
* @addr: the mac address of the client to look for
* @vid: VLAN identifier
*
* Return: a pointer to the tt_common struct belonging to the searched client if
* found, NULL otherwise.
*/
static struct batadv_tt_common_entry *
batadv_tt_hash_find(struct batadv_hashtable *hash, const u8 *addr,
unsigned short vid)
{
struct hlist_head *head;
struct batadv_tt_common_entry to_search, *tt, *tt_tmp = NULL;
u32 index;
if (!hash)
return NULL;
ether_addr_copy(to_search.addr, addr);
to_search.vid = vid;
index = batadv_choose_tt(&to_search, hash->size);
head = &hash->table[index];
rcu_read_lock();
hlist_for_each_entry_rcu(tt, head, hash_entry) {
if (!batadv_compare_eth(tt, addr))
continue;
if (tt->vid != vid)
continue;
if (!kref_get_unless_zero(&tt->refcount))
continue;
tt_tmp = tt;
break;
}
rcu_read_unlock();
return tt_tmp;
}
Contributors
Person | Tokens | Prop | Commits | CommitProp |
Marek Lindner | 79 | 55.24% | 1 | 8.33% |
Antonio Quartulli | 55 | 38.46% | 4 | 33.33% |
Sven Eckelmann | 9 | 6.29% | 7 | 58.33% |
Total | 143 | 100.00% | 12 | 100.00% |
/**
* batadv_tt_local_hash_find - search the local table for a given client
* @bat_priv: the bat priv with all the soft interface information
* @addr: the mac address of the client to look for
* @vid: VLAN identifier
*
* Return: a pointer to the corresponding tt_local_entry struct if the client is
* found, NULL otherwise.
*/
static struct batadv_tt_local_entry *
batadv_tt_local_hash_find(struct batadv_priv *bat_priv, const u8 *addr,
unsigned short vid)
{
struct batadv_tt_common_entry *tt_common_entry;
struct batadv_tt_local_entry *tt_local_entry = NULL;
tt_common_entry = batadv_tt_hash_find(bat_priv->tt.local_hash, addr,
vid);
if (tt_common_entry)
tt_local_entry = container_of(tt_common_entry,
struct batadv_tt_local_entry,
common);
return tt_local_entry;
}
Contributors
Person | Tokens | Prop | Commits | CommitProp |
Antonio Quartulli | 40 | 58.82% | 2 | 25.00% |
Marek Lindner | 16 | 23.53% | 1 | 12.50% |
Sven Eckelmann | 12 | 17.65% | 5 | 62.50% |
Total | 68 | 100.00% | 8 | 100.00% |
/**
* batadv_tt_global_hash_find - search the global table for a given client
* @bat_priv: the bat priv with all the soft interface information
* @addr: the mac address of the client to look for
* @vid: VLAN identifier
*
* Return: a pointer to the corresponding tt_global_entry struct if the client
* is found, NULL otherwise.
*/
static struct batadv_tt_global_entry *
batadv_tt_global_hash_find(struct batadv_priv *bat_priv, const u8 *addr,
unsigned short vid)
{
struct batadv_tt_common_entry *tt_common_entry;
struct batadv_tt_global_entry *tt_global_entry = NULL;
tt_common_entry = batadv_tt_hash_find(bat_priv->tt.global_hash, addr,
vid);
if (tt_common_entry)
tt_global_entry = container_of(tt_common_entry,
struct batadv_tt_global_entry,
common);
return tt_global_entry;
}
Contributors
Person | Tokens | Prop | Commits | CommitProp |
Antonio Quartulli | 35 | 51.47% | 3 | 37.50% |
Marek Lindner | 22 | 32.35% | 1 | 12.50% |
Sven Eckelmann | 11 | 16.18% | 4 | 50.00% |
Total | 68 | 100.00% | 8 | 100.00% |
/**
* batadv_tt_local_entry_free_rcu - free the tt_local_entry
* @rcu: rcu pointer of the tt_local_entry
*/
static void batadv_tt_local_entry_free_rcu(struct rcu_head *rcu)
{
struct batadv_tt_local_entry *tt_local_entry;
tt_local_entry = container_of(rcu, struct batadv_tt_local_entry,
common.rcu);
kmem_cache_free(batadv_tl_cache, tt_local_entry);
}
Contributors
Person | Tokens | Prop | Commits | CommitProp |
Sven Eckelmann | 37 | 100.00% | 1 | 100.00% |
Total | 37 | 100.00% | 1 | 100.00% |
/**
* batadv_tt_local_entry_release - release tt_local_entry from lists and queue
* for free after rcu grace period
* @ref: kref pointer of the nc_node
*/
static void batadv_tt_local_entry_release(struct kref *ref)
{
struct batadv_tt_local_entry *tt_local_entry;
tt_local_entry = container_of(ref, struct batadv_tt_local_entry,
common.refcount);
batadv_softif_vlan_put(tt_local_entry->vlan);
call_rcu(&tt_local_entry->common.rcu, batadv_tt_local_entry_free_rcu);
}
Contributors
Person | Tokens | Prop | Commits | CommitProp |
Sven Eckelmann | 29 | 59.18% | 3 | 60.00% |
Antonio Quartulli | 20 | 40.82% | 2 | 40.00% |
Total | 49 | 100.00% | 5 | 100.00% |
/**
* batadv_tt_local_entry_put - decrement the tt_local_entry refcounter and
* possibly release it
* @tt_local_entry: tt_local_entry to be free'd
*/
static void
batadv_tt_local_entry_put(struct batadv_tt_local_entry *tt_local_entry)
{
kref_put(&tt_local_entry->common.refcount,
batadv_tt_local_entry_release);
}
Contributors
Person | Tokens | Prop | Commits | CommitProp |
Antonio Quartulli | 14 | 60.87% | 2 | 50.00% |
Sven Eckelmann | 9 | 39.13% | 2 | 50.00% |
Total | 23 | 100.00% | 4 | 100.00% |
/**
* batadv_tt_global_entry_free_rcu - free the tt_global_entry
* @rcu: rcu pointer of the tt_global_entry
*/
static void batadv_tt_global_entry_free_rcu(struct rcu_head *rcu)
{
struct batadv_tt_global_entry *tt_global_entry;
tt_global_entry = container_of(rcu, struct batadv_tt_global_entry,
common.rcu);
kmem_cache_free(batadv_tg_cache, tt_global_entry);
}
Contributors
Person | Tokens | Prop | Commits | CommitProp |
Sven Eckelmann | 37 | 100.00% | 1 | 100.00% |
Total | 37 | 100.00% | 1 | 100.00% |
/**
* batadv_tt_global_entry_release - release tt_global_entry from lists and queue
* for free after rcu grace period
* @ref: kref pointer of the nc_node
*/
static void batadv_tt_global_entry_release(struct kref *ref)
{
struct batadv_tt_global_entry *tt_global_entry;
tt_global_entry = container_of(ref, struct batadv_tt_global_entry,
common.refcount);
batadv_tt_global_del_orig_list(tt_global_entry);
call_rcu(&tt_global_entry->common.rcu, batadv_tt_global_entry_free_rcu);
}
Contributors
Person | Tokens | Prop | Commits | CommitProp |
Sven Eckelmann | 34 | 72.34% | 3 | 50.00% |
Antonio Quartulli | 8 | 17.02% | 2 | 33.33% |
Simon Wunderlich | 5 | 10.64% | 1 | 16.67% |
Total | 47 | 100.00% | 6 | 100.00% |
/**
* batadv_tt_global_entry_put - decrement the tt_global_entry refcounter and
* possibly release it
* @tt_global_entry: tt_global_entry to be free'd
*/
static void
batadv_tt_global_entry_put(struct batadv_tt_global_entry *tt_global_entry)
{
kref_put(&tt_global_entry->common.refcount,
batadv_tt_global_entry_release);
}
Contributors
Person | Tokens | Prop | Commits | CommitProp |
Sven Eckelmann | 22 | 95.65% | 2 | 66.67% |
Simon Wunderlich | 1 | 4.35% | 1 | 33.33% |
Total | 23 | 100.00% | 3 | 100.00% |
/**
* batadv_tt_global_hash_count - count the number of orig entries
* @bat_priv: the bat priv with all the soft interface information
* @addr: the mac address of the client to count entries for
* @vid: VLAN identifier
*
* Return: the number of originators advertising the given address/data
* (excluding ourself).
*/
int batadv_tt_global_hash_count(struct batadv_priv *bat_priv,
const u8 *addr, unsigned short vid)
{
struct batadv_tt_global_entry *tt_global_entry;
int count;
tt_global_entry = batadv_tt_global_hash_find(bat_priv, addr, vid);
if (!tt_global_entry)
return 0;
count = atomic_read(&tt_global_entry->orig_list_count);
batadv_tt_global_entry_put(tt_global_entry);
return count;
}
Contributors
Person | Tokens | Prop | Commits | CommitProp |
Linus Lüssing | 62 | 96.88% | 1 | 33.33% |
Sven Eckelmann | 2 | 3.12% | 2 | 66.67% |
Total | 64 | 100.00% | 3 | 100.00% |
/**
* batadv_tt_local_size_mod - change the size by v of the local table identified
* by vid
* @bat_priv: the bat priv with all the soft interface information
* @vid: the VLAN identifier of the sub-table to change
* @v: the amount to sum to the local table size
*/
static void batadv_tt_local_size_mod(struct batadv_priv *bat_priv,
unsigned short vid, int v)
{
struct batadv_softif_vlan *vlan;
vlan = batadv_softif_vlan_get(bat_priv, vid);
if (!vlan)
return;
atomic_add(v, &vlan->tt.num_entries);
batadv_softif_vlan_put(vlan);
}
Contributors
Person | Tokens | Prop | Commits | CommitProp |
Antonio Quartulli | 47 | 85.45% | 2 | 50.00% |
Simon Wunderlich | 7 | 12.73% | 1 | 25.00% |
Sven Eckelmann | 1 | 1.82% | 1 | 25.00% |
Total | 55 | 100.00% | 4 | 100.00% |
/**
* batadv_tt_local_size_inc - increase by one the local table size for the given
* vid
* @bat_priv: the bat priv with all the soft interface information
* @vid: the VLAN identifier
*/
static void batadv_tt_local_size_inc(struct batadv_priv *bat_priv,
unsigned short vid)
{
batadv_tt_local_size_mod(bat_priv, vid, 1);
}
Contributors
Person | Tokens | Prop | Commits | CommitProp |
Antonio Quartulli | 24 | 100.00% | 1 | 100.00% |
Total | 24 | 100.00% | 1 | 100.00% |
/**
* batadv_tt_local_size_dec - decrease by one the local table size for the given
* vid
* @bat_priv: the bat priv with all the soft interface information
* @vid: the VLAN identifier
*/
static void batadv_tt_local_size_dec(struct batadv_priv *bat_priv,
unsigned short vid)
{
batadv_tt_local_size_mod(bat_priv, vid, -1);
}
Contributors
Person | Tokens | Prop | Commits | CommitProp |
Antonio Quartulli | 25 | 100.00% | 1 | 100.00% |
Total | 25 | 100.00% | 1 | 100.00% |
/**
* batadv_tt_global_size_mod - change the size by v of the global table
* for orig_node identified by vid
* @orig_node: the originator for which the table has to be modified
* @vid: the VLAN identifier
* @v: the amount to sum to the global table size
*/
static void batadv_tt_global_size_mod(struct batadv_orig_node *orig_node,
unsigned short vid, int v)
{
struct batadv_orig_node_vlan *vlan;
vlan = batadv_orig_node_vlan_new(orig_node, vid);
if (!vlan)
return;
if (atomic_add_return(v, &vlan->tt.num_entries) == 0) {
spin_lock_bh(&orig_node->vlan_list_lock);
if (!hlist_unhashed(&vlan->list)) {
hlist_del_init_rcu(&vlan->list);
batadv_orig_node_vlan_put(vlan);
}
spin_unlock_bh(&orig_node->vlan_list_lock);
}
batadv_orig_node_vlan_put(vlan);
}
Contributors
Person | Tokens | Prop | Commits | CommitProp |
Antonio Quartulli | 83 | 80.58% | 3 | 60.00% |
Sven Eckelmann | 20 | 19.42% | 2 | 40.00% |
Total | 103 | 100.00% | 5 | 100.00% |
/**
* batadv_tt_global_size_inc - increase by one the global table size for the
* given vid
* @orig_node: the originator which global table size has to be decreased
* @vid: the vlan identifier
*/
static void batadv_tt_global_size_inc(struct batadv_orig_node *orig_node,
unsigned short vid)
{
batadv_tt_global_size_mod(orig_node, vid, 1);
}
Contributors
Person | Tokens | Prop | Commits | CommitProp |
Antonio Quartulli | 24 | 100.00% | 1 | 100.00% |
Total | 24 | 100.00% | 1 | 100.00% |
/**
* batadv_tt_global_size_dec - decrease by one the global table size for the
* given vid
* @orig_node: the originator which global table size has to be decreased
* @vid: the vlan identifier
*/
static void batadv_tt_global_size_dec(struct batadv_orig_node *orig_node,
unsigned short vid)
{
batadv_tt_global_size_mod(orig_node, vid, -1);
}
Contributors
Person | Tokens | Prop | Commits | CommitProp |
Antonio Quartulli | 25 | 100.00% | 2 | 100.00% |
Total | 25 | 100.00% | 2 | 100.00% |
/**
* batadv_tt_orig_list_entry_free_rcu - free the orig_entry
* @rcu: rcu pointer of the orig_entry
*/
static void batadv_tt_orig_list_entry_free_rcu(struct rcu_head *rcu)
{
struct batadv_tt_orig_list_entry *orig_entry;
orig_entry = container_of(rcu, struct batadv_tt_orig_list_entry, rcu);
kmem_cache_free(batadv_tt_orig_cache, orig_entry);
}
Contributors
Person | Tokens | Prop | Commits | CommitProp |
Sven Eckelmann | 35 | 100.00% | 1 | 100.00% |
Total | 35 | 100.00% | 1 | 100.00% |
/**
* batadv_tt_orig_list_entry_release - release tt orig entry from lists and
* queue for free after rcu grace period
* @ref: kref pointer of the tt orig entry
*/
static void batadv_tt_orig_list_entry_release(struct kref *ref)
{
struct batadv_tt_orig_list_entry *orig_entry;
orig_entry = container_of(ref, struct batadv_tt_orig_list_entry,
refcount);
batadv_orig_node_put(orig_entry->orig_node);
call_rcu(&orig_entry->rcu, batadv_tt_orig_list_entry_free_rcu);
}
Contributors
Person | Tokens | Prop | Commits | CommitProp |
Sven Eckelmann | 45 | 100.00% | 4 | 100.00% |
Total | 45 | 100.00% | 4 | 100.00% |
/**
* batadv_tt_orig_list_entry_put - decrement the tt orig entry refcounter and
* possibly release it
* @orig_entry: tt orig entry to be free'd
*/
static void
batadv_tt_orig_list_entry_put(struct batadv_tt_orig_list_entry *orig_entry)
{
kref_put(&orig_entry->refcount, batadv_tt_orig_list_entry_release);
}
Contributors
Person | Tokens | Prop | Commits | CommitProp |
Antonio Quartulli | 14 | 66.67% | 1 | 20.00% |
Sven Eckelmann | 4 | 19.05% | 3 | 60.00% |
Simon Wunderlich | 3 | 14.29% | 1 | 20.00% |
Total | 21 | 100.00% | 5 | 100.00% |
/**
* batadv_tt_local_event - store a local TT event (ADD/DEL)
* @bat_priv: the bat priv with all the soft interface information
* @tt_local_entry: the TT entry involved in the event
* @event_flags: flags to store in the event structure
*/
static void batadv_tt_local_event(struct batadv_priv *bat_priv,
struct batadv_tt_local_entry *tt_local_entry,
u8 event_flags)
{
struct batadv_tt_change_node *tt_change_node, *entry, *safe;
struct batadv_tt_common_entry *common = &tt_local_entry->common;
u8 flags = common->flags | event_flags;
bool event_removed = false;
bool del_op_requested, del_op_entry;
tt_change_node = kmem_cache_alloc(batadv_tt_change_cache, GFP_ATOMIC);
if (!tt_change_node)
return;
tt_change_node->change.flags = flags;
memset(tt_change_node->change.reserved, 0,
sizeof(tt_change_node->change.reserved));
ether_addr_copy(tt_change_node->change.addr, common->addr);
tt_change_node->change.vid = htons(common->vid);
del_op_requested = flags & BATADV_TT_CLIENT_DEL;
/* check for ADD+DEL or DEL+ADD events */
spin_lock_bh(&bat_priv->tt.changes_list_lock);
list_for_each_entry_safe(entry, safe, &bat_priv->tt.changes_list,
list) {
if (!batadv_compare_eth(entry->change.addr, common->addr))
continue;
/* DEL+ADD in the same orig interval have no effect and can be
* removed to avoid silly behaviour on the receiver side. The
* other way around (ADD+DEL) can happen in case of roaming of
* a client still in the NEW state. Roaming of NEW clients is
* now possible due to automatically recognition of "temporary"
* clients
*/
del_op_entry = entry->change.flags & BATADV_TT_CLIENT_DEL;
if (!del_op_requested && del_op_entry)
goto del;
if (del_op_requested && !del_op_entry)
goto del;
/* this is a second add in the same originator interval. It
* means that flags have been changed: update them!
*/
if (!del_op_requested && !del_op_entry)
entry->change.flags = flags;
continue;
del:
list_del(&entry->list);
kmem_cache_free(batadv_tt_change_cache, entry);
kmem_cache_free(batadv_tt_change_cache, tt_change_node);
event_removed = true;
goto unlock;
}
/* track the change in the OGMinterval list */
list_add_tail(&tt_change_node->list, &bat_priv->tt.changes_list);
unlock:
spin_unlock_bh(&bat_priv->tt.changes_list_lock);
if (event_removed)
atomic_dec(&bat_priv->tt.local_changes);
else
atomic_inc(&bat_priv->tt.local_changes);
}
Contributors
Person | Tokens | Prop | Commits | CommitProp |
Antonio Quartulli | 265 | 86.32% | 8 | 50.00% |
Sven Eckelmann | 31 | 10.10% | 6 | 37.50% |
Marek Lindner | 7 | 2.28% | 1 | 6.25% |
Jesper Juhl | 4 | 1.30% | 1 | 6.25% |
Total | 307 | 100.00% | 16 | 100.00% |
/**
* batadv_tt_len - compute length in bytes of given number of tt changes
* @changes_num: number of tt changes
*
* Return: computed length in bytes.
*/
static int batadv_tt_len(int changes_num)
{
return changes_num * sizeof(struct batadv_tvlv_tt_change);
}
Contributors
Person | Tokens | Prop | Commits | CommitProp |
Antonio Quartulli | 15 | 83.33% | 1 | 33.33% |
Marek Lindner | 2 | 11.11% | 1 | 33.33% |
Sven Eckelmann | 1 | 5.56% | 1 | 33.33% |
Total | 18 | 100.00% | 3 | 100.00% |
/**
* batadv_tt_entries - compute the number of entries fitting in tt_len bytes
* @tt_len: available space
*
* Return: the number of entries.
*/
static u16 batadv_tt_entries(u16 tt_len)
{
return tt_len / batadv_tt_len(1);
}
Contributors
Person | Tokens | Prop | Commits | CommitProp |
Antonio Quartulli | 15 | 88.24% | 1 | 50.00% |
Sven Eckelmann | 2 | 11.76% | 1 | 50.00% |
Total | 17 | 100.00% | 2 | 100.00% |
/**
* batadv_tt_local_table_transmit_size - calculates the local translation table
* size when transmitted over the air
* @bat_priv: the bat priv with all the soft interface information
*
* Return: local translation table size in bytes.
*/
static int batadv_tt_local_table_transmit_size(struct batadv_priv *bat_priv)
{
u16 num_vlan = 0;
u16 tt_local_entries = 0;
struct batadv_softif_vlan *vlan;
int hdr_size;
rcu_read_lock();
hlist_for_each_entry_rcu(vlan, &bat_priv->softif_vlan_list, list) {
num_vlan++;
tt_local_entries += atomic_read(&vlan->tt.num_entries);
}
rcu_read_unlock();
/* header size of tvlv encapsulated tt response payload */
hdr_size = sizeof(struct batadv_unicast_tvlv_packet);
hdr_size += sizeof(struct batadv_tvlv_hdr);
hdr_size += sizeof(struct batadv_tvlv_tt_data);
hdr_size += num_vlan * sizeof(struct batadv_tvlv_tt_vlan_data);
return hdr_size + batadv_tt_len(tt_local_entries);
}
Contributors
Person | Tokens | Prop | Commits | CommitProp |
Marek Lindner | 100 | 97.09% | 1 | 33.33% |
Sven Eckelmann | 3 | 2.91% | 2 | 66.67% |
Total | 103 | 100.00% | 3 | 100.00% |
static int batadv_tt_local_init(struct batadv_priv *bat_priv)
{
if (bat_priv->tt.local_hash)
return 0;
bat_priv->tt.local_hash = batadv_hash_new(1024);
if (!bat_priv->tt.local_hash)
return -ENOMEM;
batadv_hash_set_lock_class(bat_priv->tt.local_hash,
&batadv_tt_local_hash_lock_class_key);
return 0;
}
Contributors
Person | Tokens | Prop | Commits | CommitProp |
Sven Eckelmann | 48 | 78.69% | 6 | 75.00% |
Antonio Quartulli | 13 | 21.31% | 2 | 25.00% |
Total | 61 | 100.00% | 8 | 100.00% |
static void batadv_tt_global_free(struct batadv_priv *bat_priv,
struct batadv_tt_global_entry *tt_global,
const char *message)
{
batadv_dbg(BATADV_DBG_TT, bat_priv,
"Deleting global tt entry %pM (vid: %d): %s\n",
tt_global->common.addr,
BATADV_PRINT_VID(tt_global->common.vid), message);
batadv_hash_remove(bat_priv->tt.global_hash, batadv_compare_tt,
batadv_choose_tt, &tt_global->common);
batadv_tt_global_entry_put(tt_global);
}
Contributors
Person | Tokens | Prop | Commits | CommitProp |
Antonio Quartulli | 69 | 98.57% | 3 | 75.00% |
Sven Eckelmann | 1 | 1.43% | 1 | 25.00% |
Total | 70 | 100.00% | 4 | 100.00% |
/**
* batadv_tt_local_add - add a new client to the local table or update an
* existing client
* @soft_iface: netdev struct of the mesh interface
* @addr: the mac address of the client to add
* @vid: VLAN identifier
* @ifindex: index of the interface where the client is connected to (useful to
* identify wireless clients)
* @mark: the value contained in the skb->mark field of the received packet (if
* any)
*
* Return: true if the client was successfully added, false otherwise.
*/
bool batadv_tt_local_add(struct net_device *soft_iface, const u8 *addr,
unsigned short vid, int ifindex, u32 mark)
{
struct batadv_priv *bat_priv = netdev_priv(soft_iface);
struct batadv_tt_local_entry *tt_local;
struct batadv_tt_global_entry *tt_global = NULL;
struct net *net = dev_net(soft_iface);
struct batadv_softif_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;
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);
tt_local = batadv_tt_local_hash_find(bat_priv, addr, vid);
if (!is_multicast_ether_addr(addr))
tt_global = batadv_tt_global_hash_find(bat_priv, addr, vid);
if (tt_local) {
tt_local->last_seen = jiffies;
if (tt_local->common.flags & BATADV_TT_CLIENT_PENDING) {
batadv_dbg(BATADV_DBG_TT, bat_priv,
"Re-adding pending client %pM (vid: %d)\n",
addr, BATADV_PRINT_VID(vid));
/* whatever the reason why the PENDING flag was set,
* this is a client which was enqueued to be removed in
* this orig_interval. Since it popped up again, the
* flag can be reset like it was never enqueued
*/
tt_local->common.flags &= ~BATADV_TT_CLIENT_PENDING;
goto add_event;
}
if (tt_local->common.flags & BATADV_TT_CLIENT_ROAM) {
batadv_dbg(BATADV_DBG_TT, bat_priv,
"Roaming client %pM (vid: %d) came back to its original location\n",
addr, BATADV_PRINT_VID(vid));
/* the ROAM flag is set because this client roamed away
* and the node got a roaming_advertisement message. Now
* that the client popped up again at its original
* location such flag can be unset
*/
tt_local->common.flags &= ~BATADV_TT_CLIENT_ROAM;
roamed_back = true;
}
goto check_roaming;
}
/* Ignore the client if we cannot send it in a full table response. */
table_size = batadv_tt_local_table_transmit_size(bat_priv);
table_size += batadv_tt_len(1);
packet_size_max = atomic_read(&bat_priv->packet_size_max);
if (table_size > packet_size_max) {
net_ratelimited_function(batadv_info, soft_iface,
"Local translation table size (%i) exceeds maximum packet size (%i); Ignoring new local tt entry: %pM\n",
table_size, packet_size_max, addr);
goto out;
}
tt_local = kmem_cache_alloc(batadv_tl_cache, GFP_ATOMIC);
if (!tt_local)
goto out;
/* increase the refcounter of the related vlan */
vlan = batadv_softif_vlan_get(bat_priv, vid);
if (!vlan) {
net_ratelimited_function(batadv_info, soft_iface,
"adding TT local entry %pM to non-existent VLAN %d\n",
addr, BATADV_PRINT_VID(vid));
kmem_cache_free(batadv_tl_cache, tt_local);
tt_local = NULL;
goto out;
}
batadv_dbg(BATADV_DBG_TT, bat_priv,
"Creating new local tt entry: %pM (vid: %d, ttvn: %d)\n",
addr, BATADV_PRINT_VID(vid),
(u8)atomic_read(&bat_priv->tt.vn));
ether_addr_copy(tt_local->common.addr, addr);
/* The local entry has to be marked as NEW to avoid to send it in
* a full table response going out before the next ttvn increment
* (consistency check)
*/
tt_local->common.flags = BATADV_TT_CLIENT_NEW;
tt_local->common.vid = vid;
if (batadv_is_wifi_hardif(in_hardif))
tt_local->common.flags |= BATADV_TT_CLIENT_WIFI;
kref_init(&tt_local->common.refcount);
tt_local->last_seen = jiffies;
tt_local->common.added_at = tt_local->last_seen;
tt_local->vlan = vlan;
/* the batman interface mac and multicast addresses should never be
* purged
*/
if (batadv_compare_eth(addr, soft_iface->dev_addr) ||
is_multicast_ether_addr(addr))
tt_local->common.flags |= BATADV_TT_CLIENT_NOPURGE;
kref_get(&tt_local->common.refcount);
hash_added = batadv_hash_add(bat_priv->tt.local_hash, batadv_compare_tt,
batadv_choose_tt, &tt_local->common,
&tt_local->common.hash_entry);
if (unlikely(hash_added != 0)) {
/* remove the reference for the hash */
batadv_tt_local_entry_put(tt_local);
goto out;
}
add_event:
batadv_tt_local_event(bat_priv, tt_local, BATADV_NO_FLAGS);
check_roaming:
/* Check whether it is a roaming, but don't do anything if the roaming
* process has already been handled
*/
if (tt_global && !(tt_global->common.flags & BATADV_TT_CLIENT_ROAM)) {
/* These node are probably going to update their tt table */
head = &tt_global->orig_list;
rcu_read_lock();
hlist_for_each_entry_rcu(orig_entry, head, list) {
batadv_send_roam_adv(bat_priv, tt_global->common.addr,
tt_global->common.vid,
orig_entry->orig_node);
}
rcu_read_unlock();
if (roamed_back) {
batadv_tt_global_free(bat_priv, tt_global,
"Roaming canceled");
tt_global = NULL;
} else {
/* The global entry has to be marked as ROAMING and
* has to be kept for consistency purpose
*/
tt_global->common.flags |= BATADV_TT_CLIENT_ROAM;
tt_global->roam_at = jiffies;
}
}
/* store the current remote flags before altering them. This helps
* understanding is flags are changing or not
*/
remote_flags = tt_local->common.flags & BATADV_TT_REMOTE_MASK;
if (batadv_is_wifi_hardif(in_hardif))
tt_local->common.flags |= BATADV_TT_CLIENT_WIFI;
else
tt_local->common.flags &= ~BATADV_TT_CLIENT_WIFI;
/* check the mark in the skb: if it's equal to the configured
* isolation_mark, it means the packet is coming from an isolated
* non-mesh client
*/
match_mark = (mark & bat_priv->isolation_mark_mask);
if (bat_priv->isolation_mark_mask &&
match_mark == bat_priv->isolation_mark)
tt_local->common.flags |= BATADV_TT_CLIENT_ISOLA;
else
tt_local->common.flags &= ~BATADV_TT_CLIENT_ISOLA;
/* if any "dynamic" flag has been modified, resend an ADD event for this
* entry so that all the nodes can get the new flags
*/
if (remote_flags ^ (tt_local->common.flags & BATADV_TT_REMOTE_MASK))
batadv_tt_local_event(bat_priv, tt_local, BATADV_NO_FLAGS);
ret = true;
out:
if (in_hardif)
batadv_hardif_put(in_hardif);
if (in_dev)
dev_put(in_dev);
if (tt_local)
batadv_tt_local_entry_put(tt_local);
if (tt_global)
batadv_tt_global_entry_put(tt_global);
return ret;
}
Contributors
Person | Tokens | Prop | Commits | CommitProp |
Antonio Quartulli | 441 | 53.58% | 21 | 42.00% |
Sven Eckelmann | 187 | 22.72% | 20 | 40.00% |
Marek Lindner | 84 | 10.21% | 4 | 8.00% |
Simon Wunderlich | 84 | 10.21% | 3 | 6.00% |
Linus Lüssing | 16 | 1.94% | 1 | 2.00% |
Andrew Lunn | 11 | 1.34% | 1 | 2.00% |
Total | 823 | 100.00% | 50 | 100.00% |
/**
* batadv_tt_prepare_tvlv_global_data - prepare the TVLV TT header to send
* within a TT Response directed to another node
* @orig_node: originator for which the TT data has to be prepared
* @tt_data: uninitialised pointer to the address of the TVLV buffer
* @tt_change: uninitialised pointer to the address of the area where the TT
* changed can be stored
* @tt_len: pointer to the length to reserve to the tt_change. if -1 this
* function reserves the amount of space needed to send the entire global TT
* table. In case of success the value is updated with the real amount of
* reserved bytes
* Allocate the needed amount of memory for the entire TT TVLV and write its
* header made up by one tvlv_tt_data object and a series of tvlv_tt_vlan_data
* objects, one per active VLAN served by the originator node.
*
* Return: the size of the allocated buffer or 0 in case of failure.
*/
static u16
batadv_tt_prepare_tvlv_global_data(struct batadv_orig_node *orig_node,
struct batadv_tvlv_tt_data **tt_data,
struct batadv_tvlv_tt_change **tt_change,
s32 *tt_len)
{
u16 num_vlan = 0;
u16 num_entries = 0;
u16 change_offset;
u16 tvlv_len;
struct batadv_tvlv_tt_vlan_data *tt_vlan;
struct batadv_orig_node_vlan *vlan;
u8 *tt_change_ptr;
rcu_read_lock();
hlist_for_each_entry_rcu(vlan, &orig_node->vlan_list, list) {
num_vlan++;
num_entries += atomic_read(&vlan->tt.num_entries);
}
change_offset = sizeof(**tt_data);
change_offset += num_vlan * sizeof(*tt_vlan);
/* if tt_len is negative, allocate the space needed by the full table */
if (*tt_len < 0)
*tt_len = batadv_tt_len(num_entries);
tvlv_len = *tt_len;
tvlv_len += change_offset;
*tt_data =