Skip to content

Commit a4c135c

Browse files
Simon WunderlichMarek Lindner
authored andcommitted
batman-adv: protect bonding with rcu locks
bonding / alternating candidates need to be secured by rcu locks as well. This patch therefore converts the bonding list from a plain pointer list to a rcu securable lists and references the bonding candidates. Signed-off-by: Simon Wunderlich <siwu@hrz.tu-chemnitz.de> Signed-off-by: Marek Lindner <lindner_marek@yahoo.de>
1 parent 2ae2daf commit a4c135c

7 files changed

Lines changed: 195 additions & 163 deletions

File tree

‎net/batman-adv/hard-interface.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -271,7 +271,7 @@ static void hardif_activate_interface(struct batman_if *batman_if)
271271
static void hardif_deactivate_interface(struct batman_if *batman_if)
272272
{
273273
if ((batman_if->if_status != IF_ACTIVE) &&
274-
(batman_if->if_status != IF_TO_BE_ACTIVATED))
274+
(batman_if->if_status != IF_TO_BE_ACTIVATED))
275275
return;
276276

277277
batman_if->if_status = IF_INACTIVE;

‎net/batman-adv/originator.c‎

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,14 @@ static void neigh_node_free_rcu(struct rcu_head *rcu)
7575
kref_put(&neigh_node->refcount, neigh_node_free_ref);
7676
}
7777

78+
void neigh_node_free_rcu_bond(struct rcu_head *rcu)
79+
{
80+
struct neigh_node *neigh_node;
81+
82+
neigh_node = container_of(rcu, struct neigh_node, rcu_bond);
83+
kref_put(&neigh_node->refcount, neigh_node_free_ref);
84+
}
85+
7886
struct neigh_node *create_neighbor(struct orig_node *orig_node,
7987
struct orig_node *orig_neigh_node,
8088
uint8_t *neigh,
@@ -91,6 +99,7 @@ struct neigh_node *create_neighbor(struct orig_node *orig_node,
9199
return NULL;
92100

93101
INIT_HLIST_NODE(&neigh_node->list);
102+
INIT_LIST_HEAD(&neigh_node->bonding_list);
94103

95104
memcpy(neigh_node->addr, neigh, ETH_ALEN);
96105
neigh_node->orig_node = orig_neigh_node;
@@ -106,13 +115,20 @@ struct neigh_node *create_neighbor(struct orig_node *orig_node,
106115
void orig_node_free_ref(struct kref *refcount)
107116
{
108117
struct hlist_node *node, *node_tmp;
109-
struct neigh_node *neigh_node;
118+
struct neigh_node *neigh_node, *tmp_neigh_node;
110119
struct orig_node *orig_node;
111120

112121
orig_node = container_of(refcount, struct orig_node, refcount);
113122

114123
spin_lock_bh(&orig_node->neigh_list_lock);
115124

125+
/* for all bonding members ... */
126+
list_for_each_entry_safe(neigh_node, tmp_neigh_node,
127+
&orig_node->bond_list, bonding_list) {
128+
list_del_rcu(&neigh_node->bonding_list);
129+
call_rcu(&neigh_node->rcu_bond, neigh_node_free_rcu_bond);
130+
}
131+
116132
/* for all neighbors towards this originator ... */
117133
hlist_for_each_entry_safe(neigh_node, node, node_tmp,
118134
&orig_node->neigh_list, list) {
@@ -207,6 +223,7 @@ struct orig_node *get_orig_node(struct bat_priv *bat_priv, uint8_t *addr)
207223
return NULL;
208224

209225
INIT_HLIST_HEAD(&orig_node->neigh_list);
226+
INIT_LIST_HEAD(&orig_node->bond_list);
210227
spin_lock_init(&orig_node->ogm_cnt_lock);
211228
spin_lock_init(&orig_node->neigh_list_lock);
212229
kref_init(&orig_node->refcount);
@@ -220,6 +237,8 @@ struct orig_node *get_orig_node(struct bat_priv *bat_priv, uint8_t *addr)
220237
orig_node->batman_seqno_reset = jiffies - 1
221238
- msecs_to_jiffies(RESET_PROTECTION_MS);
222239

240+
atomic_set(&orig_node->bond_candidates, 0);
241+
223242
size = bat_priv->num_ifaces * sizeof(unsigned long) * NUM_WORDS;
224243

225244
orig_node->bcast_own = kzalloc(size, GFP_ATOMIC);
@@ -295,6 +314,7 @@ static bool purge_orig_neighbors(struct bat_priv *bat_priv,
295314
neigh_purged = true;
296315

297316
hlist_del_rcu(&neigh_node->list);
317+
bonding_candidate_del(orig_node, neigh_node);
298318
call_rcu(&neigh_node->rcu, neigh_node_free_rcu);
299319
} else {
300320
if ((!*best_neigh_node) ||
@@ -326,9 +346,6 @@ static bool purge_orig_node(struct bat_priv *bat_priv,
326346
best_neigh_node,
327347
orig_node->hna_buff,
328348
orig_node->hna_buff_len);
329-
/* update bonding candidates, we could have lost
330-
* some candidates. */
331-
update_bonding_candidates(orig_node);
332349
}
333350
}
334351

‎net/batman-adv/originator.h‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ int originator_init(struct bat_priv *bat_priv);
2626
void originator_free(struct bat_priv *bat_priv);
2727
void purge_orig_ref(struct bat_priv *bat_priv);
2828
void orig_node_free_ref(struct kref *refcount);
29+
void neigh_node_free_rcu_bond(struct rcu_head *rcu);
2930
struct orig_node *get_orig_node(struct bat_priv *bat_priv, uint8_t *addr);
3031
struct neigh_node *create_neighbor(struct orig_node *orig_node,
3132
struct orig_node *orig_neigh_node,

0 commit comments

Comments
 (0)