Commit 807736f6 authored by Sven Eckelmann's avatar Sven Eckelmann Committed by Antonio Quartulli

batman-adv: Split batadv_priv in sub-structures for features

The structure batadv_priv grows everytime a new feature is introduced. It gets
hard to find the parts of the struct that belongs to a specific feature. This
becomes even harder by the fact that not every feature uses a prefix in the
member name.

The variables for bridge loop avoidence, gateway handling, translation table
and visualization server are moved into separate structs that are included in
the bat_priv main struct.
Signed-off-by: default avatarSven Eckelmann <sven@narfation.org>
Signed-off-by: default avatarAntonio Quartulli <ordex@autistici.org>
parent 62446307
...@@ -603,8 +603,8 @@ static void batadv_iv_ogm_schedule(struct batadv_hard_iface *hard_iface) ...@@ -603,8 +603,8 @@ static void batadv_iv_ogm_schedule(struct batadv_hard_iface *hard_iface)
htonl((uint32_t)atomic_read(&hard_iface->seqno)); htonl((uint32_t)atomic_read(&hard_iface->seqno));
atomic_inc(&hard_iface->seqno); atomic_inc(&hard_iface->seqno);
batadv_ogm_packet->ttvn = atomic_read(&bat_priv->ttvn); batadv_ogm_packet->ttvn = atomic_read(&bat_priv->tt.vn);
batadv_ogm_packet->tt_crc = htons(bat_priv->tt_crc); batadv_ogm_packet->tt_crc = htons(bat_priv->tt.local_crc);
if (tt_num_changes >= 0) if (tt_num_changes >= 0)
batadv_ogm_packet->tt_num_changes = tt_num_changes; batadv_ogm_packet->tt_num_changes = tt_num_changes;
......
This diff is collapsed.
...@@ -48,7 +48,7 @@ batadv_gw_get_selected_gw_node(struct batadv_priv *bat_priv) ...@@ -48,7 +48,7 @@ batadv_gw_get_selected_gw_node(struct batadv_priv *bat_priv)
struct batadv_gw_node *gw_node; struct batadv_gw_node *gw_node;
rcu_read_lock(); rcu_read_lock();
gw_node = rcu_dereference(bat_priv->curr_gw); gw_node = rcu_dereference(bat_priv->gw.curr_gw);
if (!gw_node) if (!gw_node)
goto out; goto out;
...@@ -91,23 +91,23 @@ static void batadv_gw_select(struct batadv_priv *bat_priv, ...@@ -91,23 +91,23 @@ static void batadv_gw_select(struct batadv_priv *bat_priv,
{ {
struct batadv_gw_node *curr_gw_node; struct batadv_gw_node *curr_gw_node;
spin_lock_bh(&bat_priv->gw_list_lock); spin_lock_bh(&bat_priv->gw.list_lock);
if (new_gw_node && !atomic_inc_not_zero(&new_gw_node->refcount)) if (new_gw_node && !atomic_inc_not_zero(&new_gw_node->refcount))
new_gw_node = NULL; new_gw_node = NULL;
curr_gw_node = rcu_dereference_protected(bat_priv->curr_gw, 1); curr_gw_node = rcu_dereference_protected(bat_priv->gw.curr_gw, 1);
rcu_assign_pointer(bat_priv->curr_gw, new_gw_node); rcu_assign_pointer(bat_priv->gw.curr_gw, new_gw_node);
if (curr_gw_node) if (curr_gw_node)
batadv_gw_node_free_ref(curr_gw_node); batadv_gw_node_free_ref(curr_gw_node);
spin_unlock_bh(&bat_priv->gw_list_lock); spin_unlock_bh(&bat_priv->gw.list_lock);
} }
void batadv_gw_deselect(struct batadv_priv *bat_priv) void batadv_gw_deselect(struct batadv_priv *bat_priv)
{ {
atomic_set(&bat_priv->gw_reselect, 1); atomic_set(&bat_priv->gw.reselect, 1);
} }
static struct batadv_gw_node * static struct batadv_gw_node *
...@@ -122,7 +122,7 @@ batadv_gw_get_best_gw_node(struct batadv_priv *bat_priv) ...@@ -122,7 +122,7 @@ batadv_gw_get_best_gw_node(struct batadv_priv *bat_priv)
struct batadv_orig_node *orig_node; struct batadv_orig_node *orig_node;
rcu_read_lock(); rcu_read_lock();
hlist_for_each_entry_rcu(gw_node, node, &bat_priv->gw_list, list) { hlist_for_each_entry_rcu(gw_node, node, &bat_priv->gw.list, list) {
if (gw_node->deleted) if (gw_node->deleted)
continue; continue;
...@@ -202,7 +202,7 @@ void batadv_gw_election(struct batadv_priv *bat_priv) ...@@ -202,7 +202,7 @@ void batadv_gw_election(struct batadv_priv *bat_priv)
curr_gw = batadv_gw_get_selected_gw_node(bat_priv); curr_gw = batadv_gw_get_selected_gw_node(bat_priv);
if (!batadv_atomic_dec_not_zero(&bat_priv->gw_reselect) && curr_gw) if (!batadv_atomic_dec_not_zero(&bat_priv->gw.reselect) && curr_gw)
goto out; goto out;
next_gw = batadv_gw_get_best_gw_node(bat_priv); next_gw = batadv_gw_get_best_gw_node(bat_priv);
...@@ -321,9 +321,9 @@ static void batadv_gw_node_add(struct batadv_priv *bat_priv, ...@@ -321,9 +321,9 @@ static void batadv_gw_node_add(struct batadv_priv *bat_priv,
gw_node->orig_node = orig_node; gw_node->orig_node = orig_node;
atomic_set(&gw_node->refcount, 1); atomic_set(&gw_node->refcount, 1);
spin_lock_bh(&bat_priv->gw_list_lock); spin_lock_bh(&bat_priv->gw.list_lock);
hlist_add_head_rcu(&gw_node->list, &bat_priv->gw_list); hlist_add_head_rcu(&gw_node->list, &bat_priv->gw.list);
spin_unlock_bh(&bat_priv->gw_list_lock); spin_unlock_bh(&bat_priv->gw.list_lock);
batadv_gw_bandwidth_to_kbit(new_gwflags, &down, &up); batadv_gw_bandwidth_to_kbit(new_gwflags, &down, &up);
batadv_dbg(BATADV_DBG_BATMAN, bat_priv, batadv_dbg(BATADV_DBG_BATMAN, bat_priv,
...@@ -350,7 +350,7 @@ void batadv_gw_node_update(struct batadv_priv *bat_priv, ...@@ -350,7 +350,7 @@ void batadv_gw_node_update(struct batadv_priv *bat_priv,
curr_gw = batadv_gw_get_selected_gw_node(bat_priv); curr_gw = batadv_gw_get_selected_gw_node(bat_priv);
rcu_read_lock(); rcu_read_lock();
hlist_for_each_entry_rcu(gw_node, node, &bat_priv->gw_list, list) { hlist_for_each_entry_rcu(gw_node, node, &bat_priv->gw.list, list) {
if (gw_node->orig_node != orig_node) if (gw_node->orig_node != orig_node)
continue; continue;
...@@ -404,10 +404,10 @@ void batadv_gw_node_purge(struct batadv_priv *bat_priv) ...@@ -404,10 +404,10 @@ void batadv_gw_node_purge(struct batadv_priv *bat_priv)
curr_gw = batadv_gw_get_selected_gw_node(bat_priv); curr_gw = batadv_gw_get_selected_gw_node(bat_priv);
spin_lock_bh(&bat_priv->gw_list_lock); spin_lock_bh(&bat_priv->gw.list_lock);
hlist_for_each_entry_safe(gw_node, node, node_tmp, hlist_for_each_entry_safe(gw_node, node, node_tmp,
&bat_priv->gw_list, list) { &bat_priv->gw.list, list) {
if (((!gw_node->deleted) || if (((!gw_node->deleted) ||
(time_before(jiffies, gw_node->deleted + timeout))) && (time_before(jiffies, gw_node->deleted + timeout))) &&
atomic_read(&bat_priv->mesh_state) == BATADV_MESH_ACTIVE) atomic_read(&bat_priv->mesh_state) == BATADV_MESH_ACTIVE)
...@@ -420,7 +420,7 @@ void batadv_gw_node_purge(struct batadv_priv *bat_priv) ...@@ -420,7 +420,7 @@ void batadv_gw_node_purge(struct batadv_priv *bat_priv)
batadv_gw_node_free_ref(gw_node); batadv_gw_node_free_ref(gw_node);
} }
spin_unlock_bh(&bat_priv->gw_list_lock); spin_unlock_bh(&bat_priv->gw.list_lock);
/* gw_deselect() needs to acquire the gw_list_lock */ /* gw_deselect() needs to acquire the gw_list_lock */
if (do_deselect) if (do_deselect)
...@@ -496,7 +496,7 @@ int batadv_gw_client_seq_print_text(struct seq_file *seq, void *offset) ...@@ -496,7 +496,7 @@ int batadv_gw_client_seq_print_text(struct seq_file *seq, void *offset)
primary_if->net_dev->dev_addr, net_dev->name); primary_if->net_dev->dev_addr, net_dev->name);
rcu_read_lock(); rcu_read_lock();
hlist_for_each_entry_rcu(gw_node, node, &bat_priv->gw_list, list) { hlist_for_each_entry_rcu(gw_node, node, &bat_priv->gw.list, list) {
if (gw_node->deleted) if (gw_node->deleted)
continue; continue;
......
...@@ -103,13 +103,14 @@ static void batadv_primary_if_update_addr(struct batadv_priv *bat_priv, ...@@ -103,13 +103,14 @@ static void batadv_primary_if_update_addr(struct batadv_priv *bat_priv,
{ {
struct batadv_vis_packet *vis_packet; struct batadv_vis_packet *vis_packet;
struct batadv_hard_iface *primary_if; struct batadv_hard_iface *primary_if;
struct sk_buff *skb;
primary_if = batadv_primary_if_get_selected(bat_priv); primary_if = batadv_primary_if_get_selected(bat_priv);
if (!primary_if) if (!primary_if)
goto out; goto out;
vis_packet = (struct batadv_vis_packet *) skb = bat_priv->vis.my_info->skb_packet;
bat_priv->my_vis_info->skb_packet->data; vis_packet = (struct batadv_vis_packet *)skb->data;
memcpy(vis_packet->vis_orig, primary_if->net_dev->dev_addr, ETH_ALEN); memcpy(vis_packet->vis_orig, primary_if->net_dev->dev_addr, ETH_ALEN);
memcpy(vis_packet->sender_orig, memcpy(vis_packet->sender_orig,
primary_if->net_dev->dev_addr, ETH_ALEN); primary_if->net_dev->dev_addr, ETH_ALEN);
......
...@@ -94,20 +94,20 @@ int batadv_mesh_init(struct net_device *soft_iface) ...@@ -94,20 +94,20 @@ int batadv_mesh_init(struct net_device *soft_iface)
spin_lock_init(&bat_priv->forw_bat_list_lock); spin_lock_init(&bat_priv->forw_bat_list_lock);
spin_lock_init(&bat_priv->forw_bcast_list_lock); spin_lock_init(&bat_priv->forw_bcast_list_lock);
spin_lock_init(&bat_priv->tt_changes_list_lock); spin_lock_init(&bat_priv->tt.changes_list_lock);
spin_lock_init(&bat_priv->tt_req_list_lock); spin_lock_init(&bat_priv->tt.req_list_lock);
spin_lock_init(&bat_priv->tt_roam_list_lock); spin_lock_init(&bat_priv->tt.roam_list_lock);
spin_lock_init(&bat_priv->tt_buff_lock); spin_lock_init(&bat_priv->tt.last_changeset_lock);
spin_lock_init(&bat_priv->gw_list_lock); spin_lock_init(&bat_priv->gw.list_lock);
spin_lock_init(&bat_priv->vis_hash_lock); spin_lock_init(&bat_priv->vis.hash_lock);
spin_lock_init(&bat_priv->vis_list_lock); spin_lock_init(&bat_priv->vis.list_lock);
INIT_HLIST_HEAD(&bat_priv->forw_bat_list); INIT_HLIST_HEAD(&bat_priv->forw_bat_list);
INIT_HLIST_HEAD(&bat_priv->forw_bcast_list); INIT_HLIST_HEAD(&bat_priv->forw_bcast_list);
INIT_HLIST_HEAD(&bat_priv->gw_list); INIT_HLIST_HEAD(&bat_priv->gw.list);
INIT_LIST_HEAD(&bat_priv->tt_changes_list); INIT_LIST_HEAD(&bat_priv->tt.changes_list);
INIT_LIST_HEAD(&bat_priv->tt_req_list); INIT_LIST_HEAD(&bat_priv->tt.req_list);
INIT_LIST_HEAD(&bat_priv->tt_roam_list); INIT_LIST_HEAD(&bat_priv->tt.roam_list);
ret = batadv_originator_init(bat_priv); ret = batadv_originator_init(bat_priv);
if (ret < 0) if (ret < 0)
...@@ -128,7 +128,7 @@ int batadv_mesh_init(struct net_device *soft_iface) ...@@ -128,7 +128,7 @@ int batadv_mesh_init(struct net_device *soft_iface)
if (ret < 0) if (ret < 0)
goto err; goto err;
atomic_set(&bat_priv->gw_reselect, 0); atomic_set(&bat_priv->gw.reselect, 0);
atomic_set(&bat_priv->mesh_state, BATADV_MESH_ACTIVE); atomic_set(&bat_priv->mesh_state, BATADV_MESH_ACTIVE);
return 0; return 0;
......
...@@ -721,7 +721,7 @@ int batadv_recv_roam_adv(struct sk_buff *skb, struct batadv_hard_iface *recv_if) ...@@ -721,7 +721,7 @@ int batadv_recv_roam_adv(struct sk_buff *skb, struct batadv_hard_iface *recv_if)
* been incremented yet. This flag will make me check all the incoming * been incremented yet. This flag will make me check all the incoming
* packets for the correct destination. * packets for the correct destination.
*/ */
bat_priv->tt_poss_change = true; bat_priv->tt.poss_change = true;
batadv_orig_node_free_ref(orig_node); batadv_orig_node_free_ref(orig_node);
out: out:
...@@ -947,8 +947,8 @@ static int batadv_check_unicast_ttvn(struct batadv_priv *bat_priv, ...@@ -947,8 +947,8 @@ static int batadv_check_unicast_ttvn(struct batadv_priv *bat_priv,
unicast_packet = (struct batadv_unicast_packet *)skb->data; unicast_packet = (struct batadv_unicast_packet *)skb->data;
if (batadv_is_my_mac(unicast_packet->dest)) { if (batadv_is_my_mac(unicast_packet->dest)) {
tt_poss_change = bat_priv->tt_poss_change; tt_poss_change = bat_priv->tt.poss_change;
curr_ttvn = (uint8_t)atomic_read(&bat_priv->ttvn); curr_ttvn = (uint8_t)atomic_read(&bat_priv->tt.vn);
} else { } else {
orig_node = batadv_orig_hash_find(bat_priv, orig_node = batadv_orig_hash_find(bat_priv,
unicast_packet->dest); unicast_packet->dest);
......
...@@ -420,14 +420,15 @@ struct net_device *batadv_softif_create(const char *name) ...@@ -420,14 +420,15 @@ struct net_device *batadv_softif_create(const char *name)
atomic_set(&bat_priv->mesh_state, BATADV_MESH_INACTIVE); atomic_set(&bat_priv->mesh_state, BATADV_MESH_INACTIVE);
atomic_set(&bat_priv->bcast_seqno, 1); atomic_set(&bat_priv->bcast_seqno, 1);
atomic_set(&bat_priv->ttvn, 0); atomic_set(&bat_priv->tt.vn, 0);
atomic_set(&bat_priv->tt_local_changes, 0); atomic_set(&bat_priv->tt.local_changes, 0);
atomic_set(&bat_priv->tt_ogm_append_cnt, 0); atomic_set(&bat_priv->tt.ogm_append_cnt, 0);
atomic_set(&bat_priv->bla_num_requests, 0); #ifdef CONFIG_BATMAN_ADV_BLA
atomic_set(&bat_priv->bla.num_requests, 0);
bat_priv->tt_buff = NULL; #endif
bat_priv->tt_buff_len = 0; bat_priv->tt.last_changeset = NULL;
bat_priv->tt_poss_change = false; bat_priv->tt.last_changeset_len = 0;
bat_priv->tt.poss_change = false;
bat_priv->primary_if = NULL; bat_priv->primary_if = NULL;
bat_priv->num_ifaces = 0; bat_priv->num_ifaces = 0;
......
This diff is collapsed.
...@@ -165,6 +165,67 @@ enum batadv_counters { ...@@ -165,6 +165,67 @@ enum batadv_counters {
BATADV_CNT_NUM, BATADV_CNT_NUM,
}; };
/**
* struct batadv_priv_tt - per mesh interface translation table data
* @vn: translation table version number
* @local_changes: changes registered in an originator interval
* @poss_change: Detect an ongoing roaming phase. If true, then this node
* received a roaming_adv and has to inspect every packet directed to it to
* check whether it still is the true destination or not. This flag will be
* reset to false as soon as the this node's ttvn is increased
* @changes_list: tracks tt local changes within an originator interval
* @req_list: list of pending tt_requests
* @local_crc: Checksum of the local table, recomputed before sending a new OGM
*/
struct batadv_priv_tt {
atomic_t vn;
atomic_t ogm_append_cnt;
atomic_t local_changes;
bool poss_change;
struct list_head changes_list;
struct batadv_hashtable *local_hash;
struct batadv_hashtable *global_hash;
struct list_head req_list;
struct list_head roam_list;
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;
uint16_t local_crc;
unsigned char *last_changeset;
int16_t last_changeset_len;
spinlock_t last_changeset_lock; /* protects last_changeset */
struct delayed_work work;
};
#ifdef CONFIG_BATMAN_ADV_BLA
struct batadv_priv_bla {
atomic_t num_requests; /* number of bla requests in flight */
struct batadv_hashtable *claim_hash;
struct batadv_hashtable *backbone_hash;
struct batadv_bcast_duplist_entry bcast_duplist[BATADV_DUPLIST_SIZE];
int bcast_duplist_curr;
struct batadv_bla_claim_dst claim_dest;
struct delayed_work work;
};
#endif
struct batadv_priv_gw {
struct hlist_head list;
spinlock_t list_lock; /* protects gw_list and curr_gw */
struct batadv_gw_node __rcu *curr_gw; /* rcu protected pointer */
atomic_t reselect;
};
struct batadv_priv_vis {
struct list_head send_list;
struct batadv_hashtable *hash;
spinlock_t hash_lock; /* protects hash */
spinlock_t list_lock; /* protects info::recv_list */
struct delayed_work work;
struct batadv_vis_info *my_info;
};
struct batadv_priv { struct batadv_priv {
atomic_t mesh_state; atomic_t mesh_state;
struct net_device_stats stats; struct net_device_stats stats;
...@@ -184,64 +245,24 @@ struct batadv_priv { ...@@ -184,64 +245,24 @@ struct batadv_priv {
atomic_t bcast_seqno; atomic_t bcast_seqno;
atomic_t bcast_queue_left; atomic_t bcast_queue_left;
atomic_t batman_queue_left; atomic_t batman_queue_left;
atomic_t ttvn; /* translation table version number */
atomic_t tt_ogm_append_cnt;
atomic_t tt_local_changes; /* changes registered in a OGM interval */
atomic_t bla_num_requests; /* number of bla requests in flight */
/* The tt_poss_change flag is used to detect an ongoing roaming phase.
* If true, then I received a Roaming_adv and I have to inspect every
* packet directed to me to check whether I am still the true
* destination or not. This flag will be reset to false as soon as I
* increase my TTVN
*/
bool tt_poss_change;
char num_ifaces; char num_ifaces;
struct batadv_debug_log *debug_log; struct batadv_debug_log *debug_log;
struct kobject *mesh_obj; struct kobject *mesh_obj;
struct dentry *debug_dir; struct dentry *debug_dir;
struct hlist_head forw_bat_list; struct hlist_head forw_bat_list;
struct hlist_head forw_bcast_list; struct hlist_head forw_bcast_list;
struct hlist_head gw_list;
struct list_head tt_changes_list; /* tracks changes in a OGM int */
struct list_head vis_send_list;
struct batadv_hashtable *orig_hash; struct batadv_hashtable *orig_hash;
struct batadv_hashtable *tt_local_hash;
struct batadv_hashtable *tt_global_hash;
#ifdef CONFIG_BATMAN_ADV_BLA
struct batadv_hashtable *claim_hash;
struct batadv_hashtable *backbone_hash;
#endif
struct list_head tt_req_list; /* list of pending tt_requests */
struct list_head tt_roam_list;
struct batadv_hashtable *vis_hash;
#ifdef CONFIG_BATMAN_ADV_BLA
struct batadv_bcast_duplist_entry bcast_duplist[BATADV_DUPLIST_SIZE];
int bcast_duplist_curr;
struct batadv_bla_claim_dst claim_dest;
#endif
spinlock_t forw_bat_list_lock; /* protects forw_bat_list */ spinlock_t forw_bat_list_lock; /* protects forw_bat_list */
spinlock_t forw_bcast_list_lock; /* protects */ spinlock_t forw_bcast_list_lock; /* protects */
spinlock_t tt_changes_list_lock; /* protects tt_changes */
spinlock_t tt_req_list_lock; /* protects tt_req_list */
spinlock_t tt_roam_list_lock; /* protects tt_roam_list */
spinlock_t gw_list_lock; /* protects gw_list and curr_gw */
spinlock_t vis_hash_lock; /* protects vis_hash */
spinlock_t vis_list_lock; /* protects vis_info::recv_list */
atomic_t num_local_tt;
/* Checksum of the local table, recomputed before sending a new OGM */
uint16_t tt_crc;
unsigned char *tt_buff;
int16_t tt_buff_len;
spinlock_t tt_buff_lock; /* protects tt_buff */
struct delayed_work tt_work;
struct delayed_work orig_work; struct delayed_work orig_work;
struct delayed_work vis_work;
struct delayed_work bla_work;
struct batadv_gw_node __rcu *curr_gw; /* rcu protected pointer */
atomic_t gw_reselect;
struct batadv_hard_iface __rcu *primary_if; /* rcu protected pointer */ struct batadv_hard_iface __rcu *primary_if; /* rcu protected pointer */
struct batadv_vis_info *my_vis_info;
struct batadv_algo_ops *bat_algo_ops; struct batadv_algo_ops *bat_algo_ops;
#ifdef CONFIG_BATMAN_ADV_BLA
struct batadv_priv_bla bla;
#endif
struct batadv_priv_gw gw;
struct batadv_priv_tt tt;
struct batadv_priv_vis vis;
}; };
struct batadv_socket_client { struct batadv_socket_client {
......
This diff is collapsed.
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment