aboutsummaryrefslogtreecommitdiffstats
path: root/net/mac80211/mesh_pathtbl.c
diff options
context:
space:
mode:
Diffstat (limited to 'net/mac80211/mesh_pathtbl.c')
-rw-r--r--net/mac80211/mesh_pathtbl.c305
1 files changed, 297 insertions, 8 deletions
diff --git a/net/mac80211/mesh_pathtbl.c b/net/mac80211/mesh_pathtbl.c
index dc7ae8d31aaf..7fde32159fdc 100644
--- a/net/mac80211/mesh_pathtbl.c
+++ b/net/mac80211/mesh_pathtbl.c
@@ -17,6 +17,12 @@
17#include "ieee80211_i.h" 17#include "ieee80211_i.h"
18#include "mesh.h" 18#include "mesh.h"
19 19
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
20/* There will be initially 2^INIT_PATHS_SIZE_ORDER buckets */ 26/* There will be initially 2^INIT_PATHS_SIZE_ORDER buckets */
21#define INIT_PATHS_SIZE_ORDER 2 27#define INIT_PATHS_SIZE_ORDER 2
22 28
@@ -60,6 +66,8 @@ static inline struct mesh_table *resize_dereference_mpp_paths(void)
60 lockdep_is_held(&pathtbl_resize_lock)); 66 lockdep_is_held(&pathtbl_resize_lock));
61} 67}
62 68
69static int mesh_gate_add(struct mesh_table *tbl, struct mesh_path *mpath);
70
63/* 71/*
64 * CAREFUL -- "tbl" must not be an expression, 72 * CAREFUL -- "tbl" must not be an expression,
65 * in particular not an rcu_dereference(), since 73 * in particular not an rcu_dereference(), since
@@ -103,6 +111,7 @@ static struct mesh_table *mesh_table_alloc(int size_order)
103 sizeof(newtbl->hash_rnd)); 111 sizeof(newtbl->hash_rnd));
104 for (i = 0; i <= newtbl->hash_mask; i++) 112 for (i = 0; i <= newtbl->hash_mask; i++)
105 spin_lock_init(&newtbl->hashwlock[i]); 113 spin_lock_init(&newtbl->hashwlock[i]);
114 spin_lock_init(&newtbl->gates_lock);
106 115
107 return newtbl; 116 return newtbl;
108} 117}
@@ -118,6 +127,7 @@ static void mesh_table_free(struct mesh_table *tbl, bool free_leafs)
118{ 127{
119 struct hlist_head *mesh_hash; 128 struct hlist_head *mesh_hash;
120 struct hlist_node *p, *q; 129 struct hlist_node *p, *q;
130 struct mpath_node *gate;
121 int i; 131 int i;
122 132
123 mesh_hash = tbl->hash_buckets; 133 mesh_hash = tbl->hash_buckets;
@@ -129,6 +139,17 @@ static void mesh_table_free(struct mesh_table *tbl, bool free_leafs)
129 } 139 }
130 spin_unlock_bh(&tbl->hashwlock[i]); 140 spin_unlock_bh(&tbl->hashwlock[i]);
131 } 141 }
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
132 __mesh_table_free(tbl); 153 __mesh_table_free(tbl);
133} 154}
134 155
@@ -146,6 +167,7 @@ static int mesh_table_grow(struct mesh_table *oldtbl,
146 newtbl->free_node = oldtbl->free_node; 167 newtbl->free_node = oldtbl->free_node;
147 newtbl->mean_chain_len = oldtbl->mean_chain_len; 168 newtbl->mean_chain_len = oldtbl->mean_chain_len;
148 newtbl->copy_node = oldtbl->copy_node; 169 newtbl->copy_node = oldtbl->copy_node;
170 newtbl->known_gates = oldtbl->known_gates;
149 atomic_set(&newtbl->entries, atomic_read(&oldtbl->entries)); 171 atomic_set(&newtbl->entries, atomic_read(&oldtbl->entries));
150 172
151 oldhash = oldtbl->hash_buckets; 173 oldhash = oldtbl->hash_buckets;
@@ -205,6 +227,111 @@ void mesh_path_assign_nexthop(struct mesh_path *mpath, struct sta_info *sta)
205 spin_unlock_irqrestore(&mpath->frame_queue.lock, flags); 227 spin_unlock_irqrestore(&mpath->frame_queue.lock, flags);
206} 228}
207 229
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{
291 struct sk_buff *skb, *cp_skb = NULL;
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);
310 if (copy)
311 cp_skb = skb_copy(skb, GFP_ATOMIC);
312
313 prepare_for_gate(skb, gate_mpath->dst, gate_mpath);
314 __skb_queue_tail(&gateq, skb);
315
316 if (copy && cp_skb)
317 __skb_queue_tail(&failq, cp_skb);
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
208 335
209/** 336/**
210 * mesh_path_lookup - look up a path in the mesh path table 337 * mesh_path_lookup - look up a path in the mesh path table
@@ -304,6 +431,109 @@ struct mesh_path *mesh_path_lookup_by_idx(int idx, struct ieee80211_sub_if_data
304 return NULL; 431 return NULL;
305} 432}
306 433
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
307/** 537/**
308 * mesh_path_add - allocate and add a new path to the mesh path table 538 * mesh_path_add - allocate and add a new path to the mesh path table
309 * @addr: destination address of the path (ETH_ALEN length) 539 * @addr: destination address of the path (ETH_ALEN length)
@@ -481,6 +711,7 @@ int mpp_path_add(u8 *dst, u8 *mpp, struct ieee80211_sub_if_data *sdata)
481 new_mpath->flags = 0; 711 new_mpath->flags = 0;
482 skb_queue_head_init(&new_mpath->frame_queue); 712 skb_queue_head_init(&new_mpath->frame_queue);
483 new_node->mpath = new_mpath; 713 new_node->mpath = new_mpath;
714 init_timer(&new_mpath->timer);
484 new_mpath->exp_time = jiffies; 715 new_mpath->exp_time = jiffies;
485 spin_lock_init(&new_mpath->state_lock); 716 spin_lock_init(&new_mpath->state_lock);
486 717
@@ -539,6 +770,7 @@ void mesh_plink_broken(struct sta_info *sta)
539 struct hlist_node *p; 770 struct hlist_node *p;
540 struct ieee80211_sub_if_data *sdata = sta->sdata; 771 struct ieee80211_sub_if_data *sdata = sta->sdata;
541 int i; 772 int i;
773 __le16 reason = cpu_to_le16(WLAN_REASON_MESH_PATH_DEST_UNREACHABLE);
542 774
543 rcu_read_lock(); 775 rcu_read_lock();
544 tbl = rcu_dereference(mesh_paths); 776 tbl = rcu_dereference(mesh_paths);
@@ -553,8 +785,7 @@ void mesh_plink_broken(struct sta_info *sta)
553 spin_unlock_bh(&mpath->state_lock); 785 spin_unlock_bh(&mpath->state_lock);
554 mesh_path_error_tx(sdata->u.mesh.mshcfg.element_ttl, 786 mesh_path_error_tx(sdata->u.mesh.mshcfg.element_ttl,
555 mpath->dst, cpu_to_le32(mpath->sn), 787 mpath->dst, cpu_to_le32(mpath->sn),
556 cpu_to_le16(PERR_RCODE_DEST_UNREACH), 788 reason, bcast, sdata);
557 bcast, sdata);
558 } else 789 } else
559 spin_unlock_bh(&mpath->state_lock); 790 spin_unlock_bh(&mpath->state_lock);
560 } 791 }
@@ -647,12 +878,14 @@ int mesh_path_del(u8 *addr, struct ieee80211_sub_if_data *sdata)
647 mpath = node->mpath; 878 mpath = node->mpath;
648 if (mpath->sdata == sdata && 879 if (mpath->sdata == sdata &&
649 memcmp(addr, mpath->dst, ETH_ALEN) == 0) { 880 memcmp(addr, mpath->dst, ETH_ALEN) == 0) {
650 spin_lock(&mpath->state_lock); 881 spin_lock_bh(&mpath->state_lock);
882 if (mpath->is_gate)
883 mesh_gate_del(tbl, mpath);
651 mpath->flags |= MESH_PATH_RESOLVING; 884 mpath->flags |= MESH_PATH_RESOLVING;
652 hlist_del_rcu(&node->list); 885 hlist_del_rcu(&node->list);
653 call_rcu(&node->rcu, mesh_path_node_reclaim); 886 call_rcu(&node->rcu, mesh_path_node_reclaim);
654 atomic_dec(&tbl->entries); 887 atomic_dec(&tbl->entries);
655 spin_unlock(&mpath->state_lock); 888 spin_unlock_bh(&mpath->state_lock);
656 goto enddel; 889 goto enddel;
657 } 890 }
658 } 891 }
@@ -681,6 +914,58 @@ void mesh_path_tx_pending(struct mesh_path *mpath)
681} 914}
682 915
683/** 916/**
917 * mesh_path_send_to_gates - sends pending frames to all known mesh gates
918 *
919 * @mpath: mesh path whose queue will be emptied
920 *
921 * If there is only one gate, the frames are transferred from the failed mpath
922 * queue to that gate's queue. If there are more than one gates, the frames
923 * are copied from each gate to the next. After frames are copied, the
924 * mpath queues are emptied onto the transmission queue.
925 */
926int mesh_path_send_to_gates(struct mesh_path *mpath)
927{
928 struct ieee80211_sub_if_data *sdata = mpath->sdata;
929 struct hlist_node *n;
930 struct mesh_table *tbl;
931 struct mesh_path *from_mpath = mpath;
932 struct mpath_node *gate = NULL;
933 bool copy = false;
934 struct hlist_head *known_gates;
935
936 rcu_read_lock();
937 tbl = rcu_dereference(mesh_paths);
938 known_gates = tbl->known_gates;
939 rcu_read_unlock();
940
941 if (!known_gates)
942 return -EHOSTUNREACH;
943
944 hlist_for_each_entry_rcu(gate, n, known_gates, list) {
945 if (gate->mpath->sdata != sdata)
946 continue;
947
948 if (gate->mpath->flags & MESH_PATH_ACTIVE) {
949 mpath_dbg("Forwarding to %pM\n", gate->mpath->dst);
950 mesh_path_move_to_queue(gate->mpath, from_mpath, copy);
951 from_mpath = gate->mpath;
952 copy = true;
953 } else {
954 mpath_dbg("Not forwarding %p\n", gate->mpath);
955 mpath_dbg("flags %x\n", gate->mpath->flags);
956 }
957 }
958
959 hlist_for_each_entry_rcu(gate, n, known_gates, list)
960 if (gate->mpath->sdata == sdata) {
961 mpath_dbg("Sending to %pM\n", gate->mpath->dst);
962 mesh_path_tx_pending(gate->mpath);
963 }
964
965 return (from_mpath == mpath) ? -EHOSTUNREACH : 0;
966}
967
968/**
684 * mesh_path_discard_frame - discard a frame whose path could not be resolved 969 * mesh_path_discard_frame - discard a frame whose path could not be resolved
685 * 970 *
686 * @skb: frame to discard 971 * @skb: frame to discard
@@ -699,6 +984,7 @@ void mesh_path_discard_frame(struct sk_buff *skb,
699 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) skb->data; 984 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) skb->data;
700 struct mesh_path *mpath; 985 struct mesh_path *mpath;
701 u32 sn = 0; 986 u32 sn = 0;
987 __le16 reason = cpu_to_le16(WLAN_REASON_MESH_PATH_NOFORWARD);
702 988
703 if (memcmp(hdr->addr4, sdata->vif.addr, ETH_ALEN) != 0) { 989 if (memcmp(hdr->addr4, sdata->vif.addr, ETH_ALEN) != 0) {
704 u8 *ra, *da; 990 u8 *ra, *da;
@@ -709,8 +995,7 @@ void mesh_path_discard_frame(struct sk_buff *skb,
709 if (mpath) 995 if (mpath)
710 sn = ++mpath->sn; 996 sn = ++mpath->sn;
711 mesh_path_error_tx(sdata->u.mesh.mshcfg.element_ttl, skb->data, 997 mesh_path_error_tx(sdata->u.mesh.mshcfg.element_ttl, skb->data,
712 cpu_to_le32(sn), 998 cpu_to_le32(sn), reason, ra, sdata);
713 cpu_to_le16(PERR_RCODE_NO_ROUTE), ra, sdata);
714 } 999 }
715 1000
716 kfree_skb(skb); 1001 kfree_skb(skb);
@@ -728,8 +1013,7 @@ void mesh_path_flush_pending(struct mesh_path *mpath)
728{ 1013{
729 struct sk_buff *skb; 1014 struct sk_buff *skb;
730 1015
731 while ((skb = skb_dequeue(&mpath->frame_queue)) && 1016 while ((skb = skb_dequeue(&mpath->frame_queue)) != NULL)
732 (mpath->flags & MESH_PATH_ACTIVE))
733 mesh_path_discard_frame(skb, mpath->sdata); 1017 mesh_path_discard_frame(skb, mpath->sdata);
734} 1018}
735 1019
@@ -797,6 +1081,9 @@ int mesh_pathtbl_init(void)
797 tbl_path->free_node = &mesh_path_node_free; 1081 tbl_path->free_node = &mesh_path_node_free;
798 tbl_path->copy_node = &mesh_path_node_copy; 1082 tbl_path->copy_node = &mesh_path_node_copy;
799 tbl_path->mean_chain_len = MEAN_CHAIN_LEN; 1083 tbl_path->mean_chain_len = MEAN_CHAIN_LEN;
1084 tbl_path->known_gates = kzalloc(sizeof(struct hlist_head), GFP_ATOMIC);
1085 INIT_HLIST_HEAD(tbl_path->known_gates);
1086
800 1087
801 tbl_mpp = mesh_table_alloc(INIT_PATHS_SIZE_ORDER); 1088 tbl_mpp = mesh_table_alloc(INIT_PATHS_SIZE_ORDER);
802 if (!tbl_mpp) { 1089 if (!tbl_mpp) {
@@ -806,6 +1093,8 @@ int mesh_pathtbl_init(void)
806 tbl_mpp->free_node = &mesh_path_node_free; 1093 tbl_mpp->free_node = &mesh_path_node_free;
807 tbl_mpp->copy_node = &mesh_path_node_copy; 1094 tbl_mpp->copy_node = &mesh_path_node_copy;
808 tbl_mpp->mean_chain_len = MEAN_CHAIN_LEN; 1095 tbl_mpp->mean_chain_len = MEAN_CHAIN_LEN;
1096 tbl_mpp->known_gates = kzalloc(sizeof(struct hlist_head), GFP_ATOMIC);
1097 INIT_HLIST_HEAD(tbl_mpp->known_gates);
809 1098
810 /* Need no locking since this is during init */ 1099 /* Need no locking since this is during init */
811 RCU_INIT_POINTER(mesh_paths, tbl_path); 1100 RCU_INIT_POINTER(mesh_paths, tbl_path);