mirror of
https://mirrors.bfsu.edu.cn/git/linux.git
synced 2024-11-25 13:14:07 +08:00
batman-adv: make the TT CRC logic VLAN specific
This change allows nodes to handle the TT table on a per-VLAN basis. This is needed because nodes may have to store only some of the global entries advertised by another node. In this scenario such nodes would re-create only a partial global table and would not be able to compute a correct CRC anymore. This patch splits the logic and introduces one CRC per VLAN. In this way a node fetching only some entries belonging to some VLANs is still able to compute the needed CRCs and still check the table correctness. With this patch the shape of the TVLV-TT is changed too because now a node needs to advertise all the CRCs of all the VLANs that it is wired to. The debug output of the local Translation Table now shows the CRC along with each entry since there is not a common value for the entire table anymore. Signed-off-by: Antonio Quartulli <antonio@open-mesh.com> Signed-off-by: Marek Lindner <lindner_marek@yahoo.de>
This commit is contained in:
parent
a70a9aa990
commit
7ea7b4a142
@ -44,6 +44,88 @@ static int batadv_compare_orig(const struct hlist_node *node, const void *data2)
|
||||
return (memcmp(data1, data2, ETH_ALEN) == 0 ? 1 : 0);
|
||||
}
|
||||
|
||||
/**
|
||||
* batadv_orig_node_vlan_get - get an orig_node_vlan object
|
||||
* @orig_node: the originator serving the VLAN
|
||||
* @vid: the VLAN identifier
|
||||
*
|
||||
* Returns the vlan object identified by vid and belonging to orig_node or NULL
|
||||
* if it does not exist.
|
||||
*/
|
||||
struct batadv_orig_node_vlan *
|
||||
batadv_orig_node_vlan_get(struct batadv_orig_node *orig_node,
|
||||
unsigned short vid)
|
||||
{
|
||||
struct batadv_orig_node_vlan *vlan = NULL, *tmp;
|
||||
|
||||
rcu_read_lock();
|
||||
list_for_each_entry_rcu(tmp, &orig_node->vlan_list, list) {
|
||||
if (tmp->vid != vid)
|
||||
continue;
|
||||
|
||||
if (!atomic_inc_not_zero(&tmp->refcount))
|
||||
continue;
|
||||
|
||||
vlan = tmp;
|
||||
|
||||
break;
|
||||
}
|
||||
rcu_read_unlock();
|
||||
|
||||
return vlan;
|
||||
}
|
||||
|
||||
/**
|
||||
* batadv_orig_node_vlan_new - search and possibly create an orig_node_vlan
|
||||
* object
|
||||
* @orig_node: the originator serving the VLAN
|
||||
* @vid: the VLAN identifier
|
||||
*
|
||||
* Returns NULL in case of failure or the vlan object identified by vid and
|
||||
* belonging to orig_node otherwise. The object is created and added to the list
|
||||
* if it does not exist.
|
||||
*
|
||||
* The object is returned with refcounter increased by 1.
|
||||
*/
|
||||
struct batadv_orig_node_vlan *
|
||||
batadv_orig_node_vlan_new(struct batadv_orig_node *orig_node,
|
||||
unsigned short vid)
|
||||
{
|
||||
struct batadv_orig_node_vlan *vlan;
|
||||
|
||||
spin_lock_bh(&orig_node->vlan_list_lock);
|
||||
|
||||
/* first look if an object for this vid already exists */
|
||||
vlan = batadv_orig_node_vlan_get(orig_node, vid);
|
||||
if (vlan)
|
||||
goto out;
|
||||
|
||||
vlan = kzalloc(sizeof(*vlan), GFP_ATOMIC);
|
||||
if (!vlan)
|
||||
goto out;
|
||||
|
||||
atomic_set(&vlan->refcount, 2);
|
||||
vlan->vid = vid;
|
||||
|
||||
list_add_rcu(&vlan->list, &orig_node->vlan_list);
|
||||
|
||||
out:
|
||||
spin_unlock_bh(&orig_node->vlan_list_lock);
|
||||
|
||||
return vlan;
|
||||
}
|
||||
|
||||
/**
|
||||
* batadv_orig_node_vlan_free_ref - decrement the refcounter and possibly free
|
||||
* the originator-vlan object
|
||||
* @orig_vlan: the originator-vlan object to release
|
||||
*/
|
||||
void batadv_orig_node_vlan_free_ref(struct batadv_orig_node_vlan *orig_vlan)
|
||||
{
|
||||
if (atomic_dec_and_test(&orig_vlan->refcount))
|
||||
kfree_rcu(orig_vlan, rcu);
|
||||
}
|
||||
|
||||
int batadv_originator_init(struct batadv_priv *bat_priv)
|
||||
{
|
||||
if (bat_priv->orig_hash)
|
||||
@ -218,6 +300,7 @@ struct batadv_orig_node *batadv_get_orig_node(struct batadv_priv *bat_priv,
|
||||
const uint8_t *addr)
|
||||
{
|
||||
struct batadv_orig_node *orig_node;
|
||||
struct batadv_orig_node_vlan *vlan;
|
||||
int size, i;
|
||||
int hash_added;
|
||||
unsigned long reset_time;
|
||||
@ -235,11 +318,13 @@ struct batadv_orig_node *batadv_get_orig_node(struct batadv_priv *bat_priv,
|
||||
|
||||
INIT_HLIST_HEAD(&orig_node->neigh_list);
|
||||
INIT_LIST_HEAD(&orig_node->bond_list);
|
||||
INIT_LIST_HEAD(&orig_node->vlan_list);
|
||||
spin_lock_init(&orig_node->ogm_cnt_lock);
|
||||
spin_lock_init(&orig_node->bcast_seqno_lock);
|
||||
spin_lock_init(&orig_node->neigh_list_lock);
|
||||
spin_lock_init(&orig_node->tt_buff_lock);
|
||||
spin_lock_init(&orig_node->tt_lock);
|
||||
spin_lock_init(&orig_node->vlan_list_lock);
|
||||
|
||||
batadv_nc_init_orig(orig_node);
|
||||
|
||||
@ -251,22 +336,30 @@ struct batadv_orig_node *batadv_get_orig_node(struct batadv_priv *bat_priv,
|
||||
memcpy(orig_node->orig, addr, ETH_ALEN);
|
||||
batadv_dat_init_orig_node_addr(orig_node);
|
||||
orig_node->router = NULL;
|
||||
orig_node->tt_crc = 0;
|
||||
atomic_set(&orig_node->last_ttvn, 0);
|
||||
orig_node->tt_buff = NULL;
|
||||
orig_node->tt_buff_len = 0;
|
||||
atomic_set(&orig_node->tt_size, 0);
|
||||
reset_time = jiffies - 1 - msecs_to_jiffies(BATADV_RESET_PROTECTION_MS);
|
||||
orig_node->bcast_seqno_reset = reset_time;
|
||||
orig_node->batman_seqno_reset = reset_time;
|
||||
|
||||
atomic_set(&orig_node->bond_candidates, 0);
|
||||
|
||||
/* create a vlan object for the "untagged" LAN */
|
||||
vlan = batadv_orig_node_vlan_new(orig_node, BATADV_NO_FLAGS);
|
||||
if (!vlan)
|
||||
goto free_orig_node;
|
||||
/* batadv_orig_node_vlan_new() increases the refcounter.
|
||||
* Immediately release vlan since it is not needed anymore in this
|
||||
* context
|
||||
*/
|
||||
batadv_orig_node_vlan_free_ref(vlan);
|
||||
|
||||
size = bat_priv->num_ifaces * sizeof(unsigned long) * BATADV_NUM_WORDS;
|
||||
|
||||
orig_node->bcast_own = kzalloc(size, GFP_ATOMIC);
|
||||
if (!orig_node->bcast_own)
|
||||
goto free_orig_node;
|
||||
goto free_vlan;
|
||||
|
||||
size = bat_priv->num_ifaces * sizeof(uint8_t);
|
||||
orig_node->bcast_own_sum = kzalloc(size, GFP_ATOMIC);
|
||||
@ -291,6 +384,8 @@ free_bcast_own_sum:
|
||||
kfree(orig_node->bcast_own_sum);
|
||||
free_bcast_own:
|
||||
kfree(orig_node->bcast_own);
|
||||
free_vlan:
|
||||
batadv_orig_node_vlan_free_ref(vlan);
|
||||
free_orig_node:
|
||||
kfree(orig_node);
|
||||
return NULL;
|
||||
|
@ -40,6 +40,13 @@ int batadv_orig_hash_add_if(struct batadv_hard_iface *hard_iface,
|
||||
int max_if_num);
|
||||
int batadv_orig_hash_del_if(struct batadv_hard_iface *hard_iface,
|
||||
int max_if_num);
|
||||
struct batadv_orig_node_vlan *
|
||||
batadv_orig_node_vlan_new(struct batadv_orig_node *orig_node,
|
||||
unsigned short vid);
|
||||
struct batadv_orig_node_vlan *
|
||||
batadv_orig_node_vlan_get(struct batadv_orig_node *orig_node,
|
||||
unsigned short vid);
|
||||
void batadv_orig_node_vlan_free_ref(struct batadv_orig_node_vlan *orig_vlan);
|
||||
|
||||
|
||||
/* hashfunction to choose an entry in a hash table of given size
|
||||
|
@ -391,14 +391,26 @@ struct batadv_tvlv_gateway_data {
|
||||
* struct batadv_tvlv_tt_data - tt data propagated through the tt tvlv container
|
||||
* @flags: translation table flags (see batadv_tt_data_flags)
|
||||
* @ttvn: translation table version number
|
||||
* @reserved: field reserved for future use
|
||||
* @crc: crc32 checksum of the local translation table
|
||||
* @vlan_num: number of announced VLANs. In the TVLV this struct is followed by
|
||||
* one batadv_tvlv_tt_vlan_data object per announced vlan
|
||||
*/
|
||||
struct batadv_tvlv_tt_data {
|
||||
uint8_t flags;
|
||||
uint8_t ttvn;
|
||||
__be16 num_vlan;
|
||||
};
|
||||
|
||||
/**
|
||||
* struct batadv_tvlv_tt_vlan_data - vlan specific tt data propagated through
|
||||
* the tt tvlv container
|
||||
* @crc: crc32 checksum of the entries belonging to this vlan
|
||||
* @vid: vlan identifier
|
||||
* @reserved: unused, useful for alignment purposes
|
||||
*/
|
||||
struct batadv_tvlv_tt_vlan_data {
|
||||
__be32 crc;
|
||||
__be16 vid;
|
||||
uint16_t reserved;
|
||||
__be32 crc;
|
||||
};
|
||||
|
||||
/**
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -106,6 +106,32 @@ struct batadv_frag_list_entry {
|
||||
uint8_t no;
|
||||
};
|
||||
|
||||
/**
|
||||
* struct batadv_vlan_tt - VLAN specific TT attributes
|
||||
* @crc: CRC32 checksum of the entries belonging to this vlan
|
||||
* @num_entries: number of TT entries for this VLAN
|
||||
*/
|
||||
struct batadv_vlan_tt {
|
||||
uint32_t crc;
|
||||
atomic_t num_entries;
|
||||
};
|
||||
|
||||
/**
|
||||
* batadv_orig_node_vlan - VLAN specific data per orig_node
|
||||
* @vid: the VLAN identifier
|
||||
* @tt: VLAN specific TT attributes
|
||||
* @list: list node for orig_node::vlan_list
|
||||
* @refcount: number of context where this object is currently in use
|
||||
* @rcu: struct used for freeing in a RCU-safe manner
|
||||
*/
|
||||
struct batadv_orig_node_vlan {
|
||||
unsigned short vid;
|
||||
struct batadv_vlan_tt tt;
|
||||
struct list_head list;
|
||||
atomic_t refcount;
|
||||
struct rcu_head rcu;
|
||||
};
|
||||
|
||||
/**
|
||||
* struct batadv_orig_node - structure for orig_list maintaining nodes of mesh
|
||||
* @orig: originator ethernet address
|
||||
@ -120,12 +146,10 @@ struct batadv_frag_list_entry {
|
||||
* @batman_seqno_reset: time when the batman seqno window was reset
|
||||
* @capabilities: announced capabilities of this originator
|
||||
* @last_ttvn: last seen translation table version number
|
||||
* @tt_crc: CRC of the translation table
|
||||
* @tt_buff: last tt changeset this node received from the orig node
|
||||
* @tt_buff_len: length of the last tt changeset this node received from the
|
||||
* orig node
|
||||
* @tt_buff_lock: lock that protects tt_buff and tt_buff_len
|
||||
* @tt_size: number of global TT entries announced by the orig node
|
||||
* @tt_initialised: bool keeping track of whether or not this node have received
|
||||
* any translation table information from the orig node yet
|
||||
* @tt_lock: prevents from updating the table while reading it. Table update is
|
||||
@ -154,6 +178,9 @@ struct batadv_frag_list_entry {
|
||||
* @in_coding_list_lock: protects in_coding_list
|
||||
* @out_coding_list_lock: protects out_coding_list
|
||||
* @fragments: array with heads for fragment chains
|
||||
* @vlan_list: a list of orig_node_vlan structs, one per VLAN served by the
|
||||
* originator represented by this object
|
||||
* @vlan_list_lock: lock protecting vlan_list
|
||||
*/
|
||||
struct batadv_orig_node {
|
||||
uint8_t orig[ETH_ALEN];
|
||||
@ -169,11 +196,9 @@ struct batadv_orig_node {
|
||||
unsigned long batman_seqno_reset;
|
||||
uint8_t capabilities;
|
||||
atomic_t last_ttvn;
|
||||
uint32_t tt_crc;
|
||||
unsigned char *tt_buff;
|
||||
int16_t tt_buff_len;
|
||||
spinlock_t tt_buff_lock; /* protects tt_buff & tt_buff_len */
|
||||
atomic_t tt_size;
|
||||
bool tt_initialised;
|
||||
/* prevents from changing the table while reading it */
|
||||
spinlock_t tt_lock;
|
||||
@ -203,6 +228,8 @@ struct batadv_orig_node {
|
||||
spinlock_t out_coding_list_lock; /* Protects out_coding_list */
|
||||
#endif
|
||||
struct batadv_frag_table_entry fragments[BATADV_FRAG_BUFFER_COUNT];
|
||||
struct list_head vlan_list;
|
||||
spinlock_t vlan_list_lock; /* protects vlan_list */
|
||||
};
|
||||
|
||||
/**
|
||||
@ -389,8 +416,6 @@ enum batadv_counters {
|
||||
* @changes_list_lock: lock protecting changes_list
|
||||
* @req_list_lock: lock protecting req_list
|
||||
* @roam_list_lock: lock protecting roam_list
|
||||
* @local_entry_num: number of entries in the local hash table
|
||||
* @local_crc: Checksum of the local table, recomputed before sending a new OGM
|
||||
* @last_changeset: last tt changeset this host has generated
|
||||
* @last_changeset_len: length of last tt changeset this host has generated
|
||||
* @last_changeset_lock: lock protecting last_changeset & last_changeset_len
|
||||
@ -413,8 +438,6 @@ struct batadv_priv_tt {
|
||||
spinlock_t changes_list_lock; /* protects changes */
|
||||
spinlock_t req_list_lock; /* protects req_list */
|
||||
spinlock_t roam_list_lock; /* protects roam_list */
|
||||
atomic_t local_entry_num;
|
||||
uint32_t local_crc;
|
||||
unsigned char *last_changeset;
|
||||
int16_t last_changeset_len;
|
||||
/* protects last_changeset & last_changeset_len */
|
||||
@ -548,6 +571,7 @@ struct batadv_priv_nc {
|
||||
* @vid: VLAN identifier
|
||||
* @kobj: kobject for sysfs vlan subdirectory
|
||||
* @ap_isolation: AP isolation state
|
||||
* @tt: TT private attributes (VLAN specific)
|
||||
* @list: list node for bat_priv::softif_vlan_list
|
||||
* @refcount: number of context where this object is currently in use
|
||||
* @rcu: struct used for freeing in a RCU-safe manner
|
||||
@ -556,6 +580,7 @@ struct batadv_softif_vlan {
|
||||
unsigned short vid;
|
||||
struct kobject *kobj;
|
||||
atomic_t ap_isolation; /* boolean */
|
||||
struct batadv_vlan_tt tt;
|
||||
struct hlist_node list;
|
||||
atomic_t refcount;
|
||||
struct rcu_head rcu;
|
||||
|
Loading…
Reference in New Issue
Block a user