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