mac80211: Improve mpath state locking
[deliverable/linux.git] / net / mac80211 / mesh_pathtbl.c
CommitLineData
eb2b9311 1/*
264d9b7d 2 * Copyright (c) 2008, 2009 open80211s Ltd.
eb2b9311
LCC
3 * Author: Luis Carlos Cobo <luisca@cozybit.com>
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License version 2 as
7 * published by the Free Software Foundation.
8 */
9
10#include <linux/etherdevice.h>
11#include <linux/list.h>
eb2b9311 12#include <linux/random.h>
5a0e3ad6 13#include <linux/slab.h>
eb2b9311
LCC
14#include <linux/spinlock.h>
15#include <linux/string.h>
16#include <net/mac80211.h>
17#include "ieee80211_i.h"
18#include "mesh.h"
19
7646887a
JC
20#ifdef CONFIG_MAC80211_VERBOSE_MPATH_DEBUG
21#define mpath_dbg(fmt, args...) printk(KERN_DEBUG fmt, ##args)
22#else
23#define mpath_dbg(fmt, args...) do { (void)(0); } while (0)
24#endif
25
eb2b9311
LCC
26/* There will be initially 2^INIT_PATHS_SIZE_ORDER buckets */
27#define INIT_PATHS_SIZE_ORDER 2
28
29/* Keep the mean chain length below this constant */
30#define MEAN_CHAIN_LEN 2
31
32#define MPATH_EXPIRED(mpath) ((mpath->flags & MESH_PATH_ACTIVE) && \
33 time_after(jiffies, mpath->exp_time) && \
34 !(mpath->flags & MESH_PATH_FIXED))
35
36struct mpath_node {
37 struct hlist_node list;
38 struct rcu_head rcu;
39 /* This indirection allows two different tables to point to the same
40 * mesh_path structure, useful when resizing
41 */
42 struct mesh_path *mpath;
43};
44
349eb8cf
JB
45static struct mesh_table __rcu *mesh_paths;
46static struct mesh_table __rcu *mpp_paths; /* Store paths for MPP&MAP */
eb2b9311 47
f5ea9120 48int mesh_paths_generation;
6b86bd62
JB
49
50/* This lock will have the grow table function as writer and add / delete nodes
51 * as readers. When reading the table (i.e. doing lookups) we are well protected
52 * by RCU
53 */
54static DEFINE_RWLOCK(pathtbl_resize_lock);
55
56
349eb8cf
JB
57static inline struct mesh_table *resize_dereference_mesh_paths(void)
58{
59 return rcu_dereference_protected(mesh_paths,
60 lockdep_is_held(&pathtbl_resize_lock));
61}
62
63static inline struct mesh_table *resize_dereference_mpp_paths(void)
64{
65 return rcu_dereference_protected(mpp_paths,
66 lockdep_is_held(&pathtbl_resize_lock));
67}
68
5ee68e5b
JC
69static int mesh_gate_add(struct mesh_table *tbl, struct mesh_path *mpath);
70
349eb8cf
JB
71/*
72 * CAREFUL -- "tbl" must not be an expression,
73 * in particular not an rcu_dereference(), since
74 * it's used twice. So it is illegal to do
75 * for_each_mesh_entry(rcu_dereference(...), ...)
76 */
77#define for_each_mesh_entry(tbl, p, node, i) \
78 for (i = 0; i <= tbl->hash_mask; i++) \
79 hlist_for_each_entry_rcu(node, p, &tbl->hash_buckets[i], list)
80
81
6b86bd62
JB
82static struct mesh_table *mesh_table_alloc(int size_order)
83{
84 int i;
85 struct mesh_table *newtbl;
86
d676ff49 87 newtbl = kmalloc(sizeof(struct mesh_table), GFP_ATOMIC);
6b86bd62
JB
88 if (!newtbl)
89 return NULL;
90
91 newtbl->hash_buckets = kzalloc(sizeof(struct hlist_head) *
d676ff49 92 (1 << size_order), GFP_ATOMIC);
6b86bd62
JB
93
94 if (!newtbl->hash_buckets) {
95 kfree(newtbl);
96 return NULL;
97 }
98
99 newtbl->hashwlock = kmalloc(sizeof(spinlock_t) *
d676ff49 100 (1 << size_order), GFP_ATOMIC);
6b86bd62
JB
101 if (!newtbl->hashwlock) {
102 kfree(newtbl->hash_buckets);
103 kfree(newtbl);
104 return NULL;
105 }
106
107 newtbl->size_order = size_order;
108 newtbl->hash_mask = (1 << size_order) - 1;
109 atomic_set(&newtbl->entries, 0);
110 get_random_bytes(&newtbl->hash_rnd,
111 sizeof(newtbl->hash_rnd));
112 for (i = 0; i <= newtbl->hash_mask; i++)
113 spin_lock_init(&newtbl->hashwlock[i]);
5ee68e5b 114 spin_lock_init(&newtbl->gates_lock);
6b86bd62
JB
115
116 return newtbl;
117}
118
18889231
JC
119static void __mesh_table_free(struct mesh_table *tbl)
120{
121 kfree(tbl->hash_buckets);
122 kfree(tbl->hashwlock);
123 kfree(tbl);
124}
125
6b86bd62 126static void mesh_table_free(struct mesh_table *tbl, bool free_leafs)
18889231
JC
127{
128 struct hlist_head *mesh_hash;
129 struct hlist_node *p, *q;
5ee68e5b 130 struct mpath_node *gate;
18889231
JC
131 int i;
132
133 mesh_hash = tbl->hash_buckets;
134 for (i = 0; i <= tbl->hash_mask; i++) {
9b84b808 135 spin_lock_bh(&tbl->hashwlock[i]);
18889231
JC
136 hlist_for_each_safe(p, q, &mesh_hash[i]) {
137 tbl->free_node(p, free_leafs);
138 atomic_dec(&tbl->entries);
139 }
9b84b808 140 spin_unlock_bh(&tbl->hashwlock[i]);
18889231 141 }
5ee68e5b
JC
142 if (free_leafs) {
143 spin_lock_bh(&tbl->gates_lock);
144 hlist_for_each_entry_safe(gate, p, q,
145 tbl->known_gates, list) {
146 hlist_del(&gate->list);
147 kfree(gate);
148 }
149 kfree(tbl->known_gates);
150 spin_unlock_bh(&tbl->gates_lock);
151 }
152
18889231
JC
153 __mesh_table_free(tbl);
154}
155
a3e6b12c 156static int mesh_table_grow(struct mesh_table *oldtbl,
6b86bd62 157 struct mesh_table *newtbl)
18889231 158{
18889231
JC
159 struct hlist_head *oldhash;
160 struct hlist_node *p, *q;
161 int i;
162
a3e6b12c
I
163 if (atomic_read(&oldtbl->entries)
164 < oldtbl->mean_chain_len * (oldtbl->hash_mask + 1))
165 return -EAGAIN;
18889231 166
a3e6b12c
I
167 newtbl->free_node = oldtbl->free_node;
168 newtbl->mean_chain_len = oldtbl->mean_chain_len;
169 newtbl->copy_node = oldtbl->copy_node;
5ee68e5b 170 newtbl->known_gates = oldtbl->known_gates;
a3e6b12c 171 atomic_set(&newtbl->entries, atomic_read(&oldtbl->entries));
18889231 172
a3e6b12c
I
173 oldhash = oldtbl->hash_buckets;
174 for (i = 0; i <= oldtbl->hash_mask; i++)
18889231 175 hlist_for_each(p, &oldhash[i])
a3e6b12c 176 if (oldtbl->copy_node(p, newtbl) < 0)
18889231
JC
177 goto errcopy;
178
a3e6b12c 179 return 0;
18889231
JC
180
181errcopy:
182 for (i = 0; i <= newtbl->hash_mask; i++) {
183 hlist_for_each_safe(p, q, &newtbl->hash_buckets[i])
a3e6b12c 184 oldtbl->free_node(p, 0);
18889231 185 }
a3e6b12c 186 return -ENOMEM;
18889231
JC
187}
188
6b86bd62
JB
189static u32 mesh_table_hash(u8 *addr, struct ieee80211_sub_if_data *sdata,
190 struct mesh_table *tbl)
191{
192 /* Use last four bytes of hw addr and interface index as hash index */
193 return jhash_2words(*(u32 *)(addr+2), sdata->dev->ifindex, tbl->hash_rnd)
194 & tbl->hash_mask;
195}
f5ea9120 196
eb2b9311
LCC
197
198/**
199 *
200 * mesh_path_assign_nexthop - update mesh path next hop
201 *
202 * @mpath: mesh path to update
203 * @sta: next hop to assign
204 *
205 * Locking: mpath->state_lock must be held when calling this function
206 */
207void mesh_path_assign_nexthop(struct mesh_path *mpath, struct sta_info *sta)
208{
10c836d7
JC
209 struct sk_buff *skb;
210 struct ieee80211_hdr *hdr;
211 struct sk_buff_head tmpq;
212 unsigned long flags;
213
d0709a65 214 rcu_assign_pointer(mpath->next_hop, sta);
10c836d7
JC
215
216 __skb_queue_head_init(&tmpq);
217
218 spin_lock_irqsave(&mpath->frame_queue.lock, flags);
219
220 while ((skb = __skb_dequeue(&mpath->frame_queue)) != NULL) {
221 hdr = (struct ieee80211_hdr *) skb->data;
222 memcpy(hdr->addr1, sta->sta.addr, ETH_ALEN);
223 __skb_queue_tail(&tmpq, skb);
224 }
225
226 skb_queue_splice(&tmpq, &mpath->frame_queue);
227 spin_unlock_irqrestore(&mpath->frame_queue.lock, flags);
eb2b9311
LCC
228}
229
5ee68e5b
JC
230static void prepare_for_gate(struct sk_buff *skb, char *dst_addr,
231 struct mesh_path *gate_mpath)
232{
233 struct ieee80211_hdr *hdr;
234 struct ieee80211s_hdr *mshdr;
235 int mesh_hdrlen, hdrlen;
236 char *next_hop;
237
238 hdr = (struct ieee80211_hdr *) skb->data;
239 hdrlen = ieee80211_hdrlen(hdr->frame_control);
240 mshdr = (struct ieee80211s_hdr *) (skb->data + hdrlen);
241
242 if (!(mshdr->flags & MESH_FLAGS_AE)) {
243 /* size of the fixed part of the mesh header */
244 mesh_hdrlen = 6;
245
246 /* make room for the two extended addresses */
247 skb_push(skb, 2 * ETH_ALEN);
248 memmove(skb->data, hdr, hdrlen + mesh_hdrlen);
249
250 hdr = (struct ieee80211_hdr *) skb->data;
251
252 /* we preserve the previous mesh header and only add
253 * the new addreses */
254 mshdr = (struct ieee80211s_hdr *) (skb->data + hdrlen);
255 mshdr->flags = MESH_FLAGS_AE_A5_A6;
256 memcpy(mshdr->eaddr1, hdr->addr3, ETH_ALEN);
257 memcpy(mshdr->eaddr2, hdr->addr4, ETH_ALEN);
258 }
259
260 /* update next hop */
261 hdr = (struct ieee80211_hdr *) skb->data;
262 rcu_read_lock();
263 next_hop = rcu_dereference(gate_mpath->next_hop)->sta.addr;
264 memcpy(hdr->addr1, next_hop, ETH_ALEN);
265 rcu_read_unlock();
266 memcpy(hdr->addr3, dst_addr, ETH_ALEN);
267}
268
269/**
270 *
271 * mesh_path_move_to_queue - Move or copy frames from one mpath queue to another
272 *
273 * This function is used to transfer or copy frames from an unresolved mpath to
274 * a gate mpath. The function also adds the Address Extension field and
275 * updates the next hop.
276 *
277 * If a frame already has an Address Extension field, only the next hop and
278 * destination addresses are updated.
279 *
280 * The gate mpath must be an active mpath with a valid mpath->next_hop.
281 *
282 * @mpath: An active mpath the frames will be sent to (i.e. the gate)
283 * @from_mpath: The failed mpath
284 * @copy: When true, copy all the frames to the new mpath queue. When false,
285 * move them.
286 */
287static void mesh_path_move_to_queue(struct mesh_path *gate_mpath,
288 struct mesh_path *from_mpath,
289 bool copy)
290{
c6133661 291 struct sk_buff *skb, *cp_skb = NULL;
5ee68e5b
JC
292 struct sk_buff_head gateq, failq;
293 unsigned long flags;
294 int num_skbs;
295
296 BUG_ON(gate_mpath == from_mpath);
297 BUG_ON(!gate_mpath->next_hop);
298
299 __skb_queue_head_init(&gateq);
300 __skb_queue_head_init(&failq);
301
302 spin_lock_irqsave(&from_mpath->frame_queue.lock, flags);
303 skb_queue_splice_init(&from_mpath->frame_queue, &failq);
304 spin_unlock_irqrestore(&from_mpath->frame_queue.lock, flags);
305
306 num_skbs = skb_queue_len(&failq);
307
308 while (num_skbs--) {
309 skb = __skb_dequeue(&failq);
817a53d9 310 if (copy) {
5ee68e5b 311 cp_skb = skb_copy(skb, GFP_ATOMIC);
817a53d9
JL
312 if (cp_skb)
313 __skb_queue_tail(&failq, cp_skb);
314 }
5ee68e5b
JC
315
316 prepare_for_gate(skb, gate_mpath->dst, gate_mpath);
317 __skb_queue_tail(&gateq, skb);
5ee68e5b
JC
318 }
319
320 spin_lock_irqsave(&gate_mpath->frame_queue.lock, flags);
321 skb_queue_splice(&gateq, &gate_mpath->frame_queue);
322 mpath_dbg("Mpath queue for gate %pM has %d frames\n",
323 gate_mpath->dst,
324 skb_queue_len(&gate_mpath->frame_queue));
325 spin_unlock_irqrestore(&gate_mpath->frame_queue.lock, flags);
326
327 if (!copy)
328 return;
329
330 spin_lock_irqsave(&from_mpath->frame_queue.lock, flags);
331 skb_queue_splice(&failq, &from_mpath->frame_queue);
332 spin_unlock_irqrestore(&from_mpath->frame_queue.lock, flags);
333}
334
eb2b9311
LCC
335
336/**
337 * mesh_path_lookup - look up a path in the mesh path table
338 * @dst: hardware address (ETH_ALEN length) of destination
f698d856 339 * @sdata: local subif
eb2b9311
LCC
340 *
341 * Returns: pointer to the mesh path structure, or NULL if not found
342 *
343 * Locking: must be called within a read rcu section.
344 */
f698d856 345struct mesh_path *mesh_path_lookup(u8 *dst, struct ieee80211_sub_if_data *sdata)
eb2b9311
LCC
346{
347 struct mesh_path *mpath;
348 struct hlist_node *n;
349 struct hlist_head *bucket;
350 struct mesh_table *tbl;
351 struct mpath_node *node;
352
353 tbl = rcu_dereference(mesh_paths);
354
f698d856 355 bucket = &tbl->hash_buckets[mesh_table_hash(dst, sdata, tbl)];
eb2b9311
LCC
356 hlist_for_each_entry_rcu(node, n, bucket, list) {
357 mpath = node->mpath;
f698d856 358 if (mpath->sdata == sdata &&
eb2b9311
LCC
359 memcmp(dst, mpath->dst, ETH_ALEN) == 0) {
360 if (MPATH_EXPIRED(mpath)) {
361 spin_lock_bh(&mpath->state_lock);
362 if (MPATH_EXPIRED(mpath))
363 mpath->flags &= ~MESH_PATH_ACTIVE;
364 spin_unlock_bh(&mpath->state_lock);
365 }
366 return mpath;
367 }
368 }
369 return NULL;
370}
371
79617dee
Y
372struct mesh_path *mpp_path_lookup(u8 *dst, struct ieee80211_sub_if_data *sdata)
373{
374 struct mesh_path *mpath;
375 struct hlist_node *n;
376 struct hlist_head *bucket;
377 struct mesh_table *tbl;
378 struct mpath_node *node;
379
380 tbl = rcu_dereference(mpp_paths);
381
382 bucket = &tbl->hash_buckets[mesh_table_hash(dst, sdata, tbl)];
383 hlist_for_each_entry_rcu(node, n, bucket, list) {
384 mpath = node->mpath;
385 if (mpath->sdata == sdata &&
386 memcmp(dst, mpath->dst, ETH_ALEN) == 0) {
387 if (MPATH_EXPIRED(mpath)) {
388 spin_lock_bh(&mpath->state_lock);
389 if (MPATH_EXPIRED(mpath))
390 mpath->flags &= ~MESH_PATH_ACTIVE;
391 spin_unlock_bh(&mpath->state_lock);
392 }
393 return mpath;
394 }
395 }
396 return NULL;
397}
398
399
eb2b9311
LCC
400/**
401 * mesh_path_lookup_by_idx - look up a path in the mesh path table by its index
402 * @idx: index
f698d856 403 * @sdata: local subif, or NULL for all entries
eb2b9311
LCC
404 *
405 * Returns: pointer to the mesh path structure, or NULL if not found.
406 *
407 * Locking: must be called within a read rcu section.
408 */
f698d856 409struct mesh_path *mesh_path_lookup_by_idx(int idx, struct ieee80211_sub_if_data *sdata)
eb2b9311 410{
349eb8cf 411 struct mesh_table *tbl = rcu_dereference(mesh_paths);
eb2b9311
LCC
412 struct mpath_node *node;
413 struct hlist_node *p;
414 int i;
415 int j = 0;
416
349eb8cf 417 for_each_mesh_entry(tbl, p, node, i) {
f698d856 418 if (sdata && node->mpath->sdata != sdata)
2a8ca29a 419 continue;
eb2b9311
LCC
420 if (j++ == idx) {
421 if (MPATH_EXPIRED(node->mpath)) {
422 spin_lock_bh(&node->mpath->state_lock);
423 if (MPATH_EXPIRED(node->mpath))
424 node->mpath->flags &= ~MESH_PATH_ACTIVE;
425 spin_unlock_bh(&node->mpath->state_lock);
426 }
427 return node->mpath;
428 }
2a8ca29a 429 }
eb2b9311
LCC
430
431 return NULL;
432}
433
5ee68e5b
JC
434static void mesh_gate_node_reclaim(struct rcu_head *rp)
435{
436 struct mpath_node *node = container_of(rp, struct mpath_node, rcu);
437 kfree(node);
438}
439
440/**
441 * mesh_gate_add - mark mpath as path to a mesh gate and add to known_gates
442 * @mesh_tbl: table which contains known_gates list
443 * @mpath: mpath to known mesh gate
444 *
445 * Returns: 0 on success
446 *
447 */
448static int mesh_gate_add(struct mesh_table *tbl, struct mesh_path *mpath)
449{
450 struct mpath_node *gate, *new_gate;
451 struct hlist_node *n;
452 int err;
453
454 rcu_read_lock();
455 tbl = rcu_dereference(tbl);
456
457 hlist_for_each_entry_rcu(gate, n, tbl->known_gates, list)
458 if (gate->mpath == mpath) {
459 err = -EEXIST;
460 goto err_rcu;
461 }
462
463 new_gate = kzalloc(sizeof(struct mpath_node), GFP_ATOMIC);
464 if (!new_gate) {
465 err = -ENOMEM;
466 goto err_rcu;
467 }
468
469 mpath->is_gate = true;
470 mpath->sdata->u.mesh.num_gates++;
471 new_gate->mpath = mpath;
472 spin_lock_bh(&tbl->gates_lock);
473 hlist_add_head_rcu(&new_gate->list, tbl->known_gates);
474 spin_unlock_bh(&tbl->gates_lock);
475 rcu_read_unlock();
476 mpath_dbg("Mesh path (%s): Recorded new gate: %pM. %d known gates\n",
477 mpath->sdata->name, mpath->dst,
478 mpath->sdata->u.mesh.num_gates);
479 return 0;
480err_rcu:
481 rcu_read_unlock();
482 return err;
483}
484
485/**
486 * mesh_gate_del - remove a mesh gate from the list of known gates
487 * @tbl: table which holds our list of known gates
488 * @mpath: gate mpath
489 *
490 * Returns: 0 on success
491 *
492 * Locking: must be called inside rcu_read_lock() section
493 */
494static int mesh_gate_del(struct mesh_table *tbl, struct mesh_path *mpath)
495{
496 struct mpath_node *gate;
497 struct hlist_node *p, *q;
498
499 tbl = rcu_dereference(tbl);
500
501 hlist_for_each_entry_safe(gate, p, q, tbl->known_gates, list)
502 if (gate->mpath == mpath) {
503 spin_lock_bh(&tbl->gates_lock);
504 hlist_del_rcu(&gate->list);
505 call_rcu(&gate->rcu, mesh_gate_node_reclaim);
506 spin_unlock_bh(&tbl->gates_lock);
507 mpath->sdata->u.mesh.num_gates--;
508 mpath->is_gate = false;
509 mpath_dbg("Mesh path (%s): Deleted gate: %pM. "
510 "%d known gates\n", mpath->sdata->name,
511 mpath->dst, mpath->sdata->u.mesh.num_gates);
512 break;
513 }
514
515 return 0;
516}
517
518/**
519 *
520 * mesh_path_add_gate - add the given mpath to a mesh gate to our path table
521 * @mpath: gate path to add to table
522 */
523int mesh_path_add_gate(struct mesh_path *mpath)
524{
525 return mesh_gate_add(mesh_paths, mpath);
526}
527
528/**
529 * mesh_gate_num - number of gates known to this interface
530 * @sdata: subif data
531 */
532int mesh_gate_num(struct ieee80211_sub_if_data *sdata)
533{
534 return sdata->u.mesh.num_gates;
535}
536
eb2b9311
LCC
537/**
538 * mesh_path_add - allocate and add a new path to the mesh path table
539 * @addr: destination address of the path (ETH_ALEN length)
f698d856 540 * @sdata: local subif
eb2b9311 541 *
af901ca1 542 * Returns: 0 on success
eb2b9311
LCC
543 *
544 * State: the initial state of the new path is set to 0
545 */
f698d856 546int mesh_path_add(u8 *dst, struct ieee80211_sub_if_data *sdata)
eb2b9311 547{
18889231
JC
548 struct ieee80211_if_mesh *ifmsh = &sdata->u.mesh;
549 struct ieee80211_local *local = sdata->local;
349eb8cf 550 struct mesh_table *tbl;
eb2b9311
LCC
551 struct mesh_path *mpath, *new_mpath;
552 struct mpath_node *node, *new_node;
553 struct hlist_head *bucket;
554 struct hlist_node *n;
555 int grow = 0;
556 int err = 0;
557 u32 hash_idx;
558
47846c9b 559 if (memcmp(dst, sdata->vif.addr, ETH_ALEN) == 0)
eb2b9311
LCC
560 /* never add ourselves as neighbours */
561 return -ENOTSUPP;
562
563 if (is_multicast_ether_addr(dst))
564 return -ENOTSUPP;
565
472dbc45 566 if (atomic_add_unless(&sdata->u.mesh.mpaths, 1, MESH_MAX_MPATHS) == 0)
eb2b9311
LCC
567 return -ENOSPC;
568
402d7752 569 err = -ENOMEM;
18889231 570 new_mpath = kzalloc(sizeof(struct mesh_path), GFP_ATOMIC);
402d7752
PE
571 if (!new_mpath)
572 goto err_path_alloc;
573
18889231 574 new_node = kmalloc(sizeof(struct mpath_node), GFP_ATOMIC);
402d7752
PE
575 if (!new_node)
576 goto err_node_alloc;
f84e71a9 577
9b84b808 578 read_lock_bh(&pathtbl_resize_lock);
eb2b9311 579 memcpy(new_mpath->dst, dst, ETH_ALEN);
f698d856 580 new_mpath->sdata = sdata;
eb2b9311
LCC
581 new_mpath->flags = 0;
582 skb_queue_head_init(&new_mpath->frame_queue);
eb2b9311
LCC
583 new_node->mpath = new_mpath;
584 new_mpath->timer.data = (unsigned long) new_mpath;
585 new_mpath->timer.function = mesh_path_timer;
586 new_mpath->exp_time = jiffies;
587 spin_lock_init(&new_mpath->state_lock);
588 init_timer(&new_mpath->timer);
589
349eb8cf 590 tbl = resize_dereference_mesh_paths();
eb2b9311 591
349eb8cf
JB
592 hash_idx = mesh_table_hash(dst, sdata, tbl);
593 bucket = &tbl->hash_buckets[hash_idx];
eb2b9311 594
349eb8cf 595 spin_lock_bh(&tbl->hashwlock[hash_idx]);
eb2b9311 596
402d7752 597 err = -EEXIST;
eb2b9311
LCC
598 hlist_for_each_entry(node, n, bucket, list) {
599 mpath = node->mpath;
f698d856 600 if (mpath->sdata == sdata && memcmp(dst, mpath->dst, ETH_ALEN) == 0)
402d7752 601 goto err_exists;
eb2b9311
LCC
602 }
603
604 hlist_add_head_rcu(&new_node->list, bucket);
349eb8cf
JB
605 if (atomic_inc_return(&tbl->entries) >=
606 tbl->mean_chain_len * (tbl->hash_mask + 1))
eb2b9311
LCC
607 grow = 1;
608
f5ea9120
JB
609 mesh_paths_generation++;
610
349eb8cf 611 spin_unlock_bh(&tbl->hashwlock[hash_idx]);
9b84b808 612 read_unlock_bh(&pathtbl_resize_lock);
402d7752 613 if (grow) {
18889231 614 set_bit(MESH_WORK_GROW_MPATH_TABLE, &ifmsh->wrkq_flags);
64592c8f 615 ieee80211_queue_work(&local->hw, &sdata->work);
eb2b9311 616 }
402d7752
PE
617 return 0;
618
619err_exists:
349eb8cf 620 spin_unlock_bh(&tbl->hashwlock[hash_idx]);
9b84b808 621 read_unlock_bh(&pathtbl_resize_lock);
402d7752
PE
622 kfree(new_node);
623err_node_alloc:
624 kfree(new_mpath);
625err_path_alloc:
472dbc45 626 atomic_dec(&sdata->u.mesh.mpaths);
eb2b9311
LCC
627 return err;
628}
629
1928ecab
JB
630static void mesh_table_free_rcu(struct rcu_head *rcu)
631{
632 struct mesh_table *tbl = container_of(rcu, struct mesh_table, rcu_head);
633
634 mesh_table_free(tbl, false);
635}
636
18889231
JC
637void mesh_mpath_table_grow(void)
638{
639 struct mesh_table *oldtbl, *newtbl;
640
9b84b808 641 write_lock_bh(&pathtbl_resize_lock);
349eb8cf
JB
642 oldtbl = resize_dereference_mesh_paths();
643 newtbl = mesh_table_alloc(oldtbl->size_order + 1);
1928ecab
JB
644 if (!newtbl)
645 goto out;
349eb8cf 646 if (mesh_table_grow(oldtbl, newtbl) < 0) {
a3e6b12c 647 __mesh_table_free(newtbl);
1928ecab 648 goto out;
18889231
JC
649 }
650 rcu_assign_pointer(mesh_paths, newtbl);
18889231 651
1928ecab
JB
652 call_rcu(&oldtbl->rcu_head, mesh_table_free_rcu);
653
654 out:
655 write_unlock_bh(&pathtbl_resize_lock);
18889231
JC
656}
657
658void mesh_mpp_table_grow(void)
659{
660 struct mesh_table *oldtbl, *newtbl;
661
9b84b808 662 write_lock_bh(&pathtbl_resize_lock);
349eb8cf
JB
663 oldtbl = resize_dereference_mpp_paths();
664 newtbl = mesh_table_alloc(oldtbl->size_order + 1);
1928ecab
JB
665 if (!newtbl)
666 goto out;
349eb8cf 667 if (mesh_table_grow(oldtbl, newtbl) < 0) {
a3e6b12c 668 __mesh_table_free(newtbl);
1928ecab 669 goto out;
18889231
JC
670 }
671 rcu_assign_pointer(mpp_paths, newtbl);
1928ecab 672 call_rcu(&oldtbl->rcu_head, mesh_table_free_rcu);
18889231 673
1928ecab
JB
674 out:
675 write_unlock_bh(&pathtbl_resize_lock);
18889231 676}
eb2b9311 677
79617dee
Y
678int mpp_path_add(u8 *dst, u8 *mpp, struct ieee80211_sub_if_data *sdata)
679{
18889231
JC
680 struct ieee80211_if_mesh *ifmsh = &sdata->u.mesh;
681 struct ieee80211_local *local = sdata->local;
349eb8cf 682 struct mesh_table *tbl;
79617dee
Y
683 struct mesh_path *mpath, *new_mpath;
684 struct mpath_node *node, *new_node;
685 struct hlist_head *bucket;
686 struct hlist_node *n;
687 int grow = 0;
688 int err = 0;
689 u32 hash_idx;
690
47846c9b 691 if (memcmp(dst, sdata->vif.addr, ETH_ALEN) == 0)
79617dee
Y
692 /* never add ourselves as neighbours */
693 return -ENOTSUPP;
694
695 if (is_multicast_ether_addr(dst))
696 return -ENOTSUPP;
697
698 err = -ENOMEM;
18889231 699 new_mpath = kzalloc(sizeof(struct mesh_path), GFP_ATOMIC);
79617dee
Y
700 if (!new_mpath)
701 goto err_path_alloc;
702
18889231 703 new_node = kmalloc(sizeof(struct mpath_node), GFP_ATOMIC);
79617dee
Y
704 if (!new_node)
705 goto err_node_alloc;
706
9b84b808 707 read_lock_bh(&pathtbl_resize_lock);
79617dee
Y
708 memcpy(new_mpath->dst, dst, ETH_ALEN);
709 memcpy(new_mpath->mpp, mpp, ETH_ALEN);
710 new_mpath->sdata = sdata;
711 new_mpath->flags = 0;
712 skb_queue_head_init(&new_mpath->frame_queue);
713 new_node->mpath = new_mpath;
c6133661 714 init_timer(&new_mpath->timer);
79617dee
Y
715 new_mpath->exp_time = jiffies;
716 spin_lock_init(&new_mpath->state_lock);
717
349eb8cf 718 tbl = resize_dereference_mpp_paths();
79617dee 719
349eb8cf
JB
720 hash_idx = mesh_table_hash(dst, sdata, tbl);
721 bucket = &tbl->hash_buckets[hash_idx];
722
723 spin_lock_bh(&tbl->hashwlock[hash_idx]);
79617dee
Y
724
725 err = -EEXIST;
726 hlist_for_each_entry(node, n, bucket, list) {
727 mpath = node->mpath;
728 if (mpath->sdata == sdata && memcmp(dst, mpath->dst, ETH_ALEN) == 0)
729 goto err_exists;
730 }
731
732 hlist_add_head_rcu(&new_node->list, bucket);
349eb8cf
JB
733 if (atomic_inc_return(&tbl->entries) >=
734 tbl->mean_chain_len * (tbl->hash_mask + 1))
79617dee
Y
735 grow = 1;
736
349eb8cf 737 spin_unlock_bh(&tbl->hashwlock[hash_idx]);
9b84b808 738 read_unlock_bh(&pathtbl_resize_lock);
79617dee 739 if (grow) {
18889231 740 set_bit(MESH_WORK_GROW_MPP_TABLE, &ifmsh->wrkq_flags);
64592c8f 741 ieee80211_queue_work(&local->hw, &sdata->work);
79617dee
Y
742 }
743 return 0;
744
745err_exists:
349eb8cf 746 spin_unlock_bh(&tbl->hashwlock[hash_idx]);
9b84b808 747 read_unlock_bh(&pathtbl_resize_lock);
79617dee
Y
748 kfree(new_node);
749err_node_alloc:
750 kfree(new_mpath);
751err_path_alloc:
752 return err;
753}
754
755
eb2b9311
LCC
756/**
757 * mesh_plink_broken - deactivates paths and sends perr when a link breaks
758 *
759 * @sta: broken peer link
760 *
761 * This function must be called from the rate control algorithm if enough
762 * delivery errors suggest that a peer link is no longer usable.
763 */
764void mesh_plink_broken(struct sta_info *sta)
765{
349eb8cf 766 struct mesh_table *tbl;
15ff6365 767 static const u8 bcast[ETH_ALEN] = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff};
eb2b9311
LCC
768 struct mesh_path *mpath;
769 struct mpath_node *node;
770 struct hlist_node *p;
f698d856 771 struct ieee80211_sub_if_data *sdata = sta->sdata;
eb2b9311 772 int i;
25d49e4d 773 __le16 reason = cpu_to_le16(WLAN_REASON_MESH_PATH_DEST_UNREACHABLE);
eb2b9311
LCC
774
775 rcu_read_lock();
349eb8cf
JB
776 tbl = rcu_dereference(mesh_paths);
777 for_each_mesh_entry(tbl, p, node, i) {
eb2b9311 778 mpath = node->mpath;
349eb8cf 779 if (rcu_dereference(mpath->next_hop) == sta &&
eb2b9311
LCC
780 mpath->flags & MESH_PATH_ACTIVE &&
781 !(mpath->flags & MESH_PATH_FIXED)) {
f5e50cd0 782 spin_lock_bh(&mpath->state_lock);
eb2b9311 783 mpath->flags &= ~MESH_PATH_ACTIVE;
d19b3bf6 784 ++mpath->sn;
eb2b9311 785 spin_unlock_bh(&mpath->state_lock);
45904f21
JC
786 mesh_path_error_tx(sdata->u.mesh.mshcfg.element_ttl,
787 mpath->dst, cpu_to_le32(mpath->sn),
25d49e4d 788 reason, bcast, sdata);
f5e50cd0 789 }
eb2b9311
LCC
790 }
791 rcu_read_unlock();
792}
793
794/**
795 * mesh_path_flush_by_nexthop - Deletes mesh paths if their next hop matches
796 *
797 * @sta - mesh peer to match
798 *
b4e08ea1
LCC
799 * RCU notes: this function is called when a mesh plink transitions from
800 * PLINK_ESTAB to any other state, since PLINK_ESTAB state is the only one that
801 * allows path creation. This will happen before the sta can be freed (because
d0709a65
JB
802 * sta_info_destroy() calls this) so any reader in a rcu read block will be
803 * protected against the plink disappearing.
eb2b9311
LCC
804 */
805void mesh_path_flush_by_nexthop(struct sta_info *sta)
806{
349eb8cf 807 struct mesh_table *tbl;
eb2b9311
LCC
808 struct mesh_path *mpath;
809 struct mpath_node *node;
810 struct hlist_node *p;
811 int i;
812
349eb8cf
JB
813 rcu_read_lock();
814 tbl = rcu_dereference(mesh_paths);
815 for_each_mesh_entry(tbl, p, node, i) {
eb2b9311 816 mpath = node->mpath;
349eb8cf 817 if (rcu_dereference(mpath->next_hop) == sta)
f698d856 818 mesh_path_del(mpath->dst, mpath->sdata);
eb2b9311 819 }
349eb8cf 820 rcu_read_unlock();
eb2b9311
LCC
821}
822
ece1a2e7 823static void mesh_path_flush(struct ieee80211_sub_if_data *sdata)
eb2b9311 824{
349eb8cf 825 struct mesh_table *tbl;
eb2b9311
LCC
826 struct mesh_path *mpath;
827 struct mpath_node *node;
828 struct hlist_node *p;
829 int i;
830
349eb8cf
JB
831 rcu_read_lock();
832 tbl = rcu_dereference(mesh_paths);
833 for_each_mesh_entry(tbl, p, node, i) {
eb2b9311 834 mpath = node->mpath;
f698d856
JBG
835 if (mpath->sdata == sdata)
836 mesh_path_del(mpath->dst, mpath->sdata);
eb2b9311 837 }
349eb8cf 838 rcu_read_unlock();
eb2b9311
LCC
839}
840
841static void mesh_path_node_reclaim(struct rcu_head *rp)
842{
843 struct mpath_node *node = container_of(rp, struct mpath_node, rcu);
f698d856 844 struct ieee80211_sub_if_data *sdata = node->mpath->sdata;
d0709a65 845
c6133661 846 del_timer_sync(&node->mpath->timer);
472dbc45 847 atomic_dec(&sdata->u.mesh.mpaths);
eb2b9311
LCC
848 kfree(node->mpath);
849 kfree(node);
850}
851
ece1a2e7
JC
852static void mpp_path_flush(struct ieee80211_sub_if_data *sdata)
853{
854 struct mesh_table *tbl;
855 struct mesh_path *mpath;
856 struct mpath_node *node;
857 struct hlist_node *p;
858 int i;
859
860 read_lock_bh(&pathtbl_resize_lock);
861 tbl = rcu_dereference_protected(mpp_paths,
862 lockdep_is_held(pathtbl_resize_lock));
863 for_each_mesh_entry(tbl, p, node, i) {
864 mpath = node->mpath;
865 if (mpath->sdata != sdata)
866 continue;
867 spin_lock_bh(&tbl->hashwlock[i]);
f5e50cd0 868 hlist_del_rcu(&node->list);
ece1a2e7
JC
869 call_rcu(&node->rcu, mesh_path_node_reclaim);
870 atomic_dec(&tbl->entries);
871 spin_unlock_bh(&tbl->hashwlock[i]);
872 }
873 read_unlock_bh(&pathtbl_resize_lock);
874}
875
876/**
877 * mesh_path_flush_by_iface - Deletes all mesh paths associated with a given iface
878 *
879 * This function deletes both mesh paths as well as mesh portal paths.
880 *
881 * @sdata - interface data to match
882 *
883 */
884void mesh_path_flush_by_iface(struct ieee80211_sub_if_data *sdata)
885{
886 mesh_path_flush(sdata);
887 mpp_path_flush(sdata);
888}
889
eb2b9311
LCC
890/**
891 * mesh_path_del - delete a mesh path from the table
892 *
893 * @addr: dst address (ETH_ALEN length)
f698d856 894 * @sdata: local subif
eb2b9311 895 *
af901ca1 896 * Returns: 0 if successful
eb2b9311 897 */
f698d856 898int mesh_path_del(u8 *addr, struct ieee80211_sub_if_data *sdata)
eb2b9311 899{
349eb8cf 900 struct mesh_table *tbl;
eb2b9311
LCC
901 struct mesh_path *mpath;
902 struct mpath_node *node;
903 struct hlist_head *bucket;
904 struct hlist_node *n;
905 int hash_idx;
906 int err = 0;
907
9b84b808 908 read_lock_bh(&pathtbl_resize_lock);
349eb8cf
JB
909 tbl = resize_dereference_mesh_paths();
910 hash_idx = mesh_table_hash(addr, sdata, tbl);
911 bucket = &tbl->hash_buckets[hash_idx];
eb2b9311 912
349eb8cf 913 spin_lock_bh(&tbl->hashwlock[hash_idx]);
eb2b9311
LCC
914 hlist_for_each_entry(node, n, bucket, list) {
915 mpath = node->mpath;
f698d856 916 if (mpath->sdata == sdata &&
349eb8cf 917 memcmp(addr, mpath->dst, ETH_ALEN) == 0) {
a6965c44 918 spin_lock_bh(&mpath->state_lock);
5ee68e5b
JC
919 if (mpath->is_gate)
920 mesh_gate_del(tbl, mpath);
cfa22c71
LCC
921 mpath->flags |= MESH_PATH_RESOLVING;
922 hlist_del_rcu(&node->list);
923 call_rcu(&node->rcu, mesh_path_node_reclaim);
349eb8cf 924 atomic_dec(&tbl->entries);
a6965c44 925 spin_unlock_bh(&mpath->state_lock);
eb2b9311
LCC
926 goto enddel;
927 }
928 }
929
930 err = -ENXIO;
931enddel:
f5ea9120 932 mesh_paths_generation++;
349eb8cf 933 spin_unlock_bh(&tbl->hashwlock[hash_idx]);
9b84b808 934 read_unlock_bh(&pathtbl_resize_lock);
eb2b9311
LCC
935 return err;
936}
937
938/**
939 * mesh_path_tx_pending - sends pending frames in a mesh path queue
940 *
941 * @mpath: mesh path to activate
942 *
943 * Locking: the state_lock of the mpath structure must NOT be held when calling
944 * this function.
945 */
946void mesh_path_tx_pending(struct mesh_path *mpath)
947{
249b405c
JC
948 if (mpath->flags & MESH_PATH_ACTIVE)
949 ieee80211_add_pending_skbs(mpath->sdata->local,
950 &mpath->frame_queue);
eb2b9311
LCC
951}
952
5ee68e5b
JC
953/**
954 * mesh_path_send_to_gates - sends pending frames to all known mesh gates
955 *
956 * @mpath: mesh path whose queue will be emptied
957 *
958 * If there is only one gate, the frames are transferred from the failed mpath
959 * queue to that gate's queue. If there are more than one gates, the frames
960 * are copied from each gate to the next. After frames are copied, the
961 * mpath queues are emptied onto the transmission queue.
962 */
963int mesh_path_send_to_gates(struct mesh_path *mpath)
964{
965 struct ieee80211_sub_if_data *sdata = mpath->sdata;
966 struct hlist_node *n;
967 struct mesh_table *tbl;
968 struct mesh_path *from_mpath = mpath;
969 struct mpath_node *gate = NULL;
970 bool copy = false;
971 struct hlist_head *known_gates;
972
973 rcu_read_lock();
974 tbl = rcu_dereference(mesh_paths);
975 known_gates = tbl->known_gates;
976 rcu_read_unlock();
977
978 if (!known_gates)
979 return -EHOSTUNREACH;
980
981 hlist_for_each_entry_rcu(gate, n, known_gates, list) {
982 if (gate->mpath->sdata != sdata)
983 continue;
984
985 if (gate->mpath->flags & MESH_PATH_ACTIVE) {
986 mpath_dbg("Forwarding to %pM\n", gate->mpath->dst);
987 mesh_path_move_to_queue(gate->mpath, from_mpath, copy);
988 from_mpath = gate->mpath;
989 copy = true;
990 } else {
991 mpath_dbg("Not forwarding %p\n", gate->mpath);
992 mpath_dbg("flags %x\n", gate->mpath->flags);
993 }
994 }
995
996 hlist_for_each_entry_rcu(gate, n, known_gates, list)
997 if (gate->mpath->sdata == sdata) {
998 mpath_dbg("Sending to %pM\n", gate->mpath->dst);
999 mesh_path_tx_pending(gate->mpath);
1000 }
1001
1002 return (from_mpath == mpath) ? -EHOSTUNREACH : 0;
1003}
1004
eb2b9311
LCC
1005/**
1006 * mesh_path_discard_frame - discard a frame whose path could not be resolved
1007 *
1008 * @skb: frame to discard
f698d856 1009 * @sdata: network subif the frame was to be sent through
eb2b9311 1010 *
35946a57
JC
1011 * If the frame was being forwarded from another MP, a PERR frame will be sent
1012 * to the precursor. The precursor's address (i.e. the previous hop) was saved
1013 * in addr1 of the frame-to-be-forwarded, and would only be overwritten once
1014 * the destination is successfully resolved.
eb2b9311
LCC
1015 *
1016 * Locking: the function must me called within a rcu_read_lock region
1017 */
f698d856
JBG
1018void mesh_path_discard_frame(struct sk_buff *skb,
1019 struct ieee80211_sub_if_data *sdata)
eb2b9311 1020{
e32f85f7 1021 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) skb->data;
eb2b9311 1022 struct mesh_path *mpath;
d19b3bf6 1023 u32 sn = 0;
25d49e4d 1024 __le16 reason = cpu_to_le16(WLAN_REASON_MESH_PATH_NOFORWARD);
eb2b9311 1025
47846c9b 1026 if (memcmp(hdr->addr4, sdata->vif.addr, ETH_ALEN) != 0) {
eb2b9311
LCC
1027 u8 *ra, *da;
1028
e32f85f7 1029 da = hdr->addr3;
35946a57 1030 ra = hdr->addr1;
af089c15 1031 rcu_read_lock();
f698d856 1032 mpath = mesh_path_lookup(da, sdata);
af089c15
JC
1033 if (mpath) {
1034 spin_lock_bh(&mpath->state_lock);
d19b3bf6 1035 sn = ++mpath->sn;
af089c15
JC
1036 spin_unlock_bh(&mpath->state_lock);
1037 }
1038 rcu_read_unlock();
45904f21 1039 mesh_path_error_tx(sdata->u.mesh.mshcfg.element_ttl, skb->data,
25d49e4d 1040 cpu_to_le32(sn), reason, ra, sdata);
eb2b9311
LCC
1041 }
1042
1043 kfree_skb(skb);
472dbc45 1044 sdata->u.mesh.mshstats.dropped_frames_no_route++;
eb2b9311
LCC
1045}
1046
1047/**
1048 * mesh_path_flush_pending - free the pending queue of a mesh path
1049 *
1050 * @mpath: mesh path whose queue has to be freed
1051 *
25985edc 1052 * Locking: the function must me called within a rcu_read_lock region
eb2b9311
LCC
1053 */
1054void mesh_path_flush_pending(struct mesh_path *mpath)
1055{
eb2b9311
LCC
1056 struct sk_buff *skb;
1057
00e3f25c 1058 while ((skb = skb_dequeue(&mpath->frame_queue)) != NULL)
f698d856 1059 mesh_path_discard_frame(skb, mpath->sdata);
eb2b9311
LCC
1060}
1061
1062/**
1063 * mesh_path_fix_nexthop - force a specific next hop for a mesh path
1064 *
1065 * @mpath: the mesh path to modify
1066 * @next_hop: the next hop to force
1067 *
1068 * Locking: this function must be called holding mpath->state_lock
1069 */
1070void mesh_path_fix_nexthop(struct mesh_path *mpath, struct sta_info *next_hop)
1071{
1072 spin_lock_bh(&mpath->state_lock);
1073 mesh_path_assign_nexthop(mpath, next_hop);
d19b3bf6 1074 mpath->sn = 0xffff;
eb2b9311
LCC
1075 mpath->metric = 0;
1076 mpath->hop_count = 0;
1077 mpath->exp_time = 0;
1078 mpath->flags |= MESH_PATH_FIXED;
1079 mesh_path_activate(mpath);
1080 spin_unlock_bh(&mpath->state_lock);
1081 mesh_path_tx_pending(mpath);
1082}
1083
1084static void mesh_path_node_free(struct hlist_node *p, bool free_leafs)
1085{
1086 struct mesh_path *mpath;
1087 struct mpath_node *node = hlist_entry(p, struct mpath_node, list);
1088 mpath = node->mpath;
1089 hlist_del_rcu(p);
d0df9eec 1090 if (free_leafs) {
c6133661 1091 del_timer_sync(&mpath->timer);
eb2b9311 1092 kfree(mpath);
d0df9eec 1093 }
eb2b9311
LCC
1094 kfree(node);
1095}
1096
4caf86c6 1097static int mesh_path_node_copy(struct hlist_node *p, struct mesh_table *newtbl)
eb2b9311
LCC
1098{
1099 struct mesh_path *mpath;
1100 struct mpath_node *node, *new_node;
1101 u32 hash_idx;
1102
8566dc3f 1103 new_node = kmalloc(sizeof(struct mpath_node), GFP_ATOMIC);
00242c40
PE
1104 if (new_node == NULL)
1105 return -ENOMEM;
1106
eb2b9311
LCC
1107 node = hlist_entry(p, struct mpath_node, list);
1108 mpath = node->mpath;
eb2b9311 1109 new_node->mpath = mpath;
f698d856 1110 hash_idx = mesh_table_hash(mpath->dst, mpath->sdata, newtbl);
eb2b9311
LCC
1111 hlist_add_head(&new_node->list,
1112 &newtbl->hash_buckets[hash_idx]);
4caf86c6 1113 return 0;
eb2b9311
LCC
1114}
1115
1116int mesh_pathtbl_init(void)
1117{
349eb8cf
JB
1118 struct mesh_table *tbl_path, *tbl_mpp;
1119
1120 tbl_path = mesh_table_alloc(INIT_PATHS_SIZE_ORDER);
1121 if (!tbl_path)
79617dee 1122 return -ENOMEM;
349eb8cf
JB
1123 tbl_path->free_node = &mesh_path_node_free;
1124 tbl_path->copy_node = &mesh_path_node_copy;
1125 tbl_path->mean_chain_len = MEAN_CHAIN_LEN;
5ee68e5b
JC
1126 tbl_path->known_gates = kzalloc(sizeof(struct hlist_head), GFP_ATOMIC);
1127 INIT_HLIST_HEAD(tbl_path->known_gates);
1128
79617dee 1129
349eb8cf
JB
1130 tbl_mpp = mesh_table_alloc(INIT_PATHS_SIZE_ORDER);
1131 if (!tbl_mpp) {
1132 mesh_table_free(tbl_path, true);
eb2b9311 1133 return -ENOMEM;
79617dee 1134 }
349eb8cf
JB
1135 tbl_mpp->free_node = &mesh_path_node_free;
1136 tbl_mpp->copy_node = &mesh_path_node_copy;
1137 tbl_mpp->mean_chain_len = MEAN_CHAIN_LEN;
5ee68e5b
JC
1138 tbl_mpp->known_gates = kzalloc(sizeof(struct hlist_head), GFP_ATOMIC);
1139 INIT_HLIST_HEAD(tbl_mpp->known_gates);
349eb8cf
JB
1140
1141 /* Need no locking since this is during init */
1142 RCU_INIT_POINTER(mesh_paths, tbl_path);
1143 RCU_INIT_POINTER(mpp_paths, tbl_mpp);
79617dee 1144
eb2b9311
LCC
1145 return 0;
1146}
1147
f698d856 1148void mesh_path_expire(struct ieee80211_sub_if_data *sdata)
eb2b9311 1149{
349eb8cf 1150 struct mesh_table *tbl;
eb2b9311
LCC
1151 struct mesh_path *mpath;
1152 struct mpath_node *node;
1153 struct hlist_node *p;
1154 int i;
1155
349eb8cf
JB
1156 rcu_read_lock();
1157 tbl = rcu_dereference(mesh_paths);
1158 for_each_mesh_entry(tbl, p, node, i) {
f698d856 1159 if (node->mpath->sdata != sdata)
eb2b9311
LCC
1160 continue;
1161 mpath = node->mpath;
eb2b9311
LCC
1162 if ((!(mpath->flags & MESH_PATH_RESOLVING)) &&
1163 (!(mpath->flags & MESH_PATH_FIXED)) &&
f5e50cd0 1164 time_after(jiffies, mpath->exp_time + MESH_PATH_EXPIRE))
f698d856 1165 mesh_path_del(mpath->dst, mpath->sdata);
349eb8cf 1166 rcu_read_unlock();
eb2b9311
LCC
1167}
1168
1169void mesh_pathtbl_unregister(void)
1170{
349eb8cf
JB
1171 /* no need for locking during exit path */
1172 mesh_table_free(rcu_dereference_raw(mesh_paths), true);
1173 mesh_table_free(rcu_dereference_raw(mpp_paths), true);
eb2b9311 1174}
This page took 0.35356 seconds and 5 git commands to generate.