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 | |
Bob Copeland | 60854fd | 2016-03-02 10:09:20 -0500 | [diff] [blame] | 21 | static u32 mesh_table_hash(const void *addr, u32 len, u32 seed) |
| 22 | { |
| 23 | /* Use last four bytes of hw addr as hash index */ |
| 24 | return jhash_1word(*(u32 *)(addr+2), seed); |
| 25 | } |
Luis Carlos Cobo | eb2b931 | 2008-02-23 15:17:14 +0100 | [diff] [blame] | 26 | |
Bob Copeland | 60854fd | 2016-03-02 10:09:20 -0500 | [diff] [blame] | 27 | static const struct rhashtable_params mesh_rht_params = { |
| 28 | .nelem_hint = 2, |
| 29 | .automatic_shrinking = true, |
| 30 | .key_len = ETH_ALEN, |
| 31 | .key_offset = offsetof(struct mesh_path, dst), |
| 32 | .head_offset = offsetof(struct mesh_path, rhash), |
| 33 | .hashfn = mesh_table_hash, |
| 34 | }; |
Luis Carlos Cobo | eb2b931 | 2008-02-23 15:17:14 +0100 | [diff] [blame] | 35 | |
Johannes Berg | bf7cd94 | 2013-02-15 14:40:31 +0100 | [diff] [blame] | 36 | static inline bool mpath_expired(struct mesh_path *mpath) |
| 37 | { |
| 38 | return (mpath->flags & MESH_PATH_ACTIVE) && |
| 39 | time_after(jiffies, mpath->exp_time) && |
| 40 | !(mpath->flags & MESH_PATH_FIXED); |
| 41 | } |
Luis Carlos Cobo | eb2b931 | 2008-02-23 15:17:14 +0100 | [diff] [blame] | 42 | |
Bob Copeland | 60854fd | 2016-03-02 10:09:20 -0500 | [diff] [blame] | 43 | static void mesh_path_reclaim(struct rcu_head *rp) |
Henning Rogge | 4cc955d | 2016-02-03 13:58:38 +0100 | [diff] [blame] | 44 | { |
Bob Copeland | 60854fd | 2016-03-02 10:09:20 -0500 | [diff] [blame] | 45 | struct mesh_path *mpath = container_of(rp, struct mesh_path, rcu); |
| 46 | |
| 47 | del_timer_sync(&mpath->timer); |
| 48 | kfree(mpath); |
Henning Rogge | 4cc955d | 2016-02-03 13:58:38 +0100 | [diff] [blame] | 49 | } |
| 50 | |
Bob Copeland | 60854fd | 2016-03-02 10:09:20 -0500 | [diff] [blame] | 51 | static void mesh_path_rht_free(void *ptr, void *unused_arg) |
Johannes Berg | 349eb8c | 2011-05-14 11:56:16 +0200 | [diff] [blame] | 52 | { |
Bob Copeland | 60854fd | 2016-03-02 10:09:20 -0500 | [diff] [blame] | 53 | struct mesh_path *mpath = ptr; |
| 54 | call_rcu(&mpath->rcu, mesh_path_reclaim); |
Johannes Berg | 349eb8c | 2011-05-14 11:56:16 +0200 | [diff] [blame] | 55 | } |
| 56 | |
Bob Copeland | 60854fd | 2016-03-02 10:09:20 -0500 | [diff] [blame] | 57 | static struct mesh_table *mesh_table_alloc(void) |
Johannes Berg | 349eb8c | 2011-05-14 11:56:16 +0200 | [diff] [blame] | 58 | { |
Johannes Berg | 6b86bd6 | 2011-05-12 13:38:50 +0200 | [diff] [blame] | 59 | struct mesh_table *newtbl; |
| 60 | |
Javier Cardona | d676ff4 | 2011-05-17 16:13:34 -0700 | [diff] [blame] | 61 | newtbl = kmalloc(sizeof(struct mesh_table), GFP_ATOMIC); |
Johannes Berg | 6b86bd6 | 2011-05-12 13:38:50 +0200 | [diff] [blame] | 62 | if (!newtbl) |
| 63 | return NULL; |
| 64 | |
Bob Copeland | 60854fd | 2016-03-02 10:09:20 -0500 | [diff] [blame] | 65 | newtbl->known_gates = kzalloc(sizeof(struct hlist_head), GFP_ATOMIC); |
| 66 | if (!newtbl->known_gates) { |
Johannes Berg | 6b86bd6 | 2011-05-12 13:38:50 +0200 | [diff] [blame] | 67 | kfree(newtbl); |
| 68 | return NULL; |
| 69 | } |
Bob Copeland | 60854fd | 2016-03-02 10:09:20 -0500 | [diff] [blame] | 70 | INIT_HLIST_HEAD(newtbl->known_gates); |
Johannes Berg | 6b86bd6 | 2011-05-12 13:38:50 +0200 | [diff] [blame] | 71 | atomic_set(&newtbl->entries, 0); |
Javier Cardona | 5ee68e5 | 2011-08-09 16:45:08 -0700 | [diff] [blame] | 72 | spin_lock_init(&newtbl->gates_lock); |
Johannes Berg | 6b86bd6 | 2011-05-12 13:38:50 +0200 | [diff] [blame] | 73 | |
| 74 | return newtbl; |
| 75 | } |
| 76 | |
Bob Copeland | 60854fd | 2016-03-02 10:09:20 -0500 | [diff] [blame] | 77 | static void mesh_table_free(struct mesh_table *tbl) |
Javier Cardona | 1888923 | 2009-08-10 12:15:52 -0700 | [diff] [blame] | 78 | { |
Bob Copeland | 60854fd | 2016-03-02 10:09:20 -0500 | [diff] [blame] | 79 | rhashtable_free_and_destroy(&tbl->rhead, |
| 80 | mesh_path_rht_free, NULL); |
Javier Cardona | 1888923 | 2009-08-10 12:15:52 -0700 | [diff] [blame] | 81 | kfree(tbl); |
| 82 | } |
| 83 | |
Luis Carlos Cobo | eb2b931 | 2008-02-23 15:17:14 +0100 | [diff] [blame] | 84 | /** |
| 85 | * |
| 86 | * mesh_path_assign_nexthop - update mesh path next hop |
| 87 | * |
| 88 | * @mpath: mesh path to update |
| 89 | * @sta: next hop to assign |
| 90 | * |
| 91 | * Locking: mpath->state_lock must be held when calling this function |
| 92 | */ |
| 93 | void mesh_path_assign_nexthop(struct mesh_path *mpath, struct sta_info *sta) |
| 94 | { |
Javier Cardona | 10c836d | 2009-07-09 14:42:16 -0700 | [diff] [blame] | 95 | struct sk_buff *skb; |
| 96 | struct ieee80211_hdr *hdr; |
Javier Cardona | 10c836d | 2009-07-09 14:42:16 -0700 | [diff] [blame] | 97 | unsigned long flags; |
| 98 | |
Johannes Berg | d0709a6 | 2008-02-25 16:27:46 +0100 | [diff] [blame] | 99 | rcu_assign_pointer(mpath->next_hop, sta); |
Javier Cardona | 10c836d | 2009-07-09 14:42:16 -0700 | [diff] [blame] | 100 | |
Javier Cardona | 10c836d | 2009-07-09 14:42:16 -0700 | [diff] [blame] | 101 | spin_lock_irqsave(&mpath->frame_queue.lock, flags); |
Thomas Pedersen | b22bd52 | 2012-08-09 18:15:39 -0700 | [diff] [blame] | 102 | skb_queue_walk(&mpath->frame_queue, skb) { |
Javier Cardona | 10c836d | 2009-07-09 14:42:16 -0700 | [diff] [blame] | 103 | hdr = (struct ieee80211_hdr *) skb->data; |
| 104 | memcpy(hdr->addr1, sta->sta.addr, ETH_ALEN); |
Thomas Pedersen | 7e3c886 | 2011-11-24 17:15:21 -0800 | [diff] [blame] | 105 | memcpy(hdr->addr2, mpath->sdata->vif.addr, ETH_ALEN); |
Marco Porsch | 3f52b7e | 2013-01-30 18:14:08 +0100 | [diff] [blame] | 106 | ieee80211_mps_set_frame_flags(sta->sdata, sta, hdr); |
Javier Cardona | 10c836d | 2009-07-09 14:42:16 -0700 | [diff] [blame] | 107 | } |
| 108 | |
Javier Cardona | 10c836d | 2009-07-09 14:42:16 -0700 | [diff] [blame] | 109 | spin_unlock_irqrestore(&mpath->frame_queue.lock, flags); |
Luis Carlos Cobo | eb2b931 | 2008-02-23 15:17:14 +0100 | [diff] [blame] | 110 | } |
| 111 | |
Javier Cardona | 5ee68e5 | 2011-08-09 16:45:08 -0700 | [diff] [blame] | 112 | static void prepare_for_gate(struct sk_buff *skb, char *dst_addr, |
| 113 | struct mesh_path *gate_mpath) |
| 114 | { |
| 115 | struct ieee80211_hdr *hdr; |
| 116 | struct ieee80211s_hdr *mshdr; |
| 117 | int mesh_hdrlen, hdrlen; |
| 118 | char *next_hop; |
| 119 | |
| 120 | hdr = (struct ieee80211_hdr *) skb->data; |
| 121 | hdrlen = ieee80211_hdrlen(hdr->frame_control); |
| 122 | mshdr = (struct ieee80211s_hdr *) (skb->data + hdrlen); |
| 123 | |
| 124 | if (!(mshdr->flags & MESH_FLAGS_AE)) { |
| 125 | /* size of the fixed part of the mesh header */ |
| 126 | mesh_hdrlen = 6; |
| 127 | |
| 128 | /* make room for the two extended addresses */ |
| 129 | skb_push(skb, 2 * ETH_ALEN); |
| 130 | memmove(skb->data, hdr, hdrlen + mesh_hdrlen); |
| 131 | |
| 132 | hdr = (struct ieee80211_hdr *) skb->data; |
| 133 | |
| 134 | /* we preserve the previous mesh header and only add |
| 135 | * the new addreses */ |
| 136 | mshdr = (struct ieee80211s_hdr *) (skb->data + hdrlen); |
| 137 | mshdr->flags = MESH_FLAGS_AE_A5_A6; |
| 138 | memcpy(mshdr->eaddr1, hdr->addr3, ETH_ALEN); |
| 139 | memcpy(mshdr->eaddr2, hdr->addr4, ETH_ALEN); |
| 140 | } |
| 141 | |
| 142 | /* update next hop */ |
| 143 | hdr = (struct ieee80211_hdr *) skb->data; |
| 144 | rcu_read_lock(); |
| 145 | next_hop = rcu_dereference(gate_mpath->next_hop)->sta.addr; |
| 146 | memcpy(hdr->addr1, next_hop, ETH_ALEN); |
| 147 | rcu_read_unlock(); |
Thomas Pedersen | 7e3c886 | 2011-11-24 17:15:21 -0800 | [diff] [blame] | 148 | memcpy(hdr->addr2, gate_mpath->sdata->vif.addr, ETH_ALEN); |
Javier Cardona | 5ee68e5 | 2011-08-09 16:45:08 -0700 | [diff] [blame] | 149 | memcpy(hdr->addr3, dst_addr, ETH_ALEN); |
| 150 | } |
| 151 | |
| 152 | /** |
| 153 | * |
| 154 | * mesh_path_move_to_queue - Move or copy frames from one mpath queue to another |
| 155 | * |
| 156 | * This function is used to transfer or copy frames from an unresolved mpath to |
| 157 | * a gate mpath. The function also adds the Address Extension field and |
| 158 | * updates the next hop. |
| 159 | * |
| 160 | * If a frame already has an Address Extension field, only the next hop and |
| 161 | * destination addresses are updated. |
| 162 | * |
| 163 | * The gate mpath must be an active mpath with a valid mpath->next_hop. |
| 164 | * |
| 165 | * @mpath: An active mpath the frames will be sent to (i.e. the gate) |
| 166 | * @from_mpath: The failed mpath |
| 167 | * @copy: When true, copy all the frames to the new mpath queue. When false, |
| 168 | * move them. |
| 169 | */ |
| 170 | static void mesh_path_move_to_queue(struct mesh_path *gate_mpath, |
| 171 | struct mesh_path *from_mpath, |
| 172 | bool copy) |
| 173 | { |
Thomas Pedersen | 4bd4c2d | 2012-08-09 18:15:40 -0700 | [diff] [blame] | 174 | struct sk_buff *skb, *fskb, *tmp; |
| 175 | struct sk_buff_head failq; |
Javier Cardona | 5ee68e5 | 2011-08-09 16:45:08 -0700 | [diff] [blame] | 176 | unsigned long flags; |
Javier Cardona | 5ee68e5 | 2011-08-09 16:45:08 -0700 | [diff] [blame] | 177 | |
Johannes Berg | 8c5bb1f | 2014-04-29 17:55:26 +0200 | [diff] [blame] | 178 | if (WARN_ON(gate_mpath == from_mpath)) |
| 179 | return; |
| 180 | if (WARN_ON(!gate_mpath->next_hop)) |
| 181 | return; |
Javier Cardona | 5ee68e5 | 2011-08-09 16:45:08 -0700 | [diff] [blame] | 182 | |
Javier Cardona | 5ee68e5 | 2011-08-09 16:45:08 -0700 | [diff] [blame] | 183 | __skb_queue_head_init(&failq); |
| 184 | |
| 185 | spin_lock_irqsave(&from_mpath->frame_queue.lock, flags); |
| 186 | skb_queue_splice_init(&from_mpath->frame_queue, &failq); |
| 187 | spin_unlock_irqrestore(&from_mpath->frame_queue.lock, flags); |
| 188 | |
Thomas Pedersen | 4bd4c2d | 2012-08-09 18:15:40 -0700 | [diff] [blame] | 189 | skb_queue_walk_safe(&failq, fskb, tmp) { |
| 190 | if (skb_queue_len(&gate_mpath->frame_queue) >= |
| 191 | MESH_FRAME_QUEUE_LEN) { |
| 192 | mpath_dbg(gate_mpath->sdata, "mpath queue full!\n"); |
| 193 | break; |
John W. Linville | 817a53d | 2011-08-24 15:12:41 -0400 | [diff] [blame] | 194 | } |
Javier Cardona | 5ee68e5 | 2011-08-09 16:45:08 -0700 | [diff] [blame] | 195 | |
Thomas Pedersen | 4bd4c2d | 2012-08-09 18:15:40 -0700 | [diff] [blame] | 196 | skb = skb_copy(fskb, GFP_ATOMIC); |
| 197 | if (WARN_ON(!skb)) |
| 198 | break; |
| 199 | |
Javier Cardona | 5ee68e5 | 2011-08-09 16:45:08 -0700 | [diff] [blame] | 200 | prepare_for_gate(skb, gate_mpath->dst, gate_mpath); |
Thomas Pedersen | 4bd4c2d | 2012-08-09 18:15:40 -0700 | [diff] [blame] | 201 | skb_queue_tail(&gate_mpath->frame_queue, skb); |
| 202 | |
| 203 | if (copy) |
| 204 | continue; |
| 205 | |
| 206 | __skb_unlink(fskb, &failq); |
| 207 | kfree_skb(fskb); |
Javier Cardona | 5ee68e5 | 2011-08-09 16:45:08 -0700 | [diff] [blame] | 208 | } |
| 209 | |
Johannes Berg | bdcbd8e | 2012-06-22 11:29:50 +0200 | [diff] [blame] | 210 | mpath_dbg(gate_mpath->sdata, "Mpath queue for gate %pM has %d frames\n", |
| 211 | gate_mpath->dst, skb_queue_len(&gate_mpath->frame_queue)); |
Javier Cardona | 5ee68e5 | 2011-08-09 16:45:08 -0700 | [diff] [blame] | 212 | |
| 213 | if (!copy) |
| 214 | return; |
| 215 | |
| 216 | spin_lock_irqsave(&from_mpath->frame_queue.lock, flags); |
| 217 | skb_queue_splice(&failq, &from_mpath->frame_queue); |
| 218 | spin_unlock_irqrestore(&from_mpath->frame_queue.lock, flags); |
| 219 | } |
| 220 | |
Luis Carlos Cobo | eb2b931 | 2008-02-23 15:17:14 +0100 | [diff] [blame] | 221 | |
Johannes Berg | 4a3cb70 | 2013-02-12 16:43:19 +0100 | [diff] [blame] | 222 | static struct mesh_path *mpath_lookup(struct mesh_table *tbl, const u8 *dst, |
| 223 | struct ieee80211_sub_if_data *sdata) |
Luis Carlos Cobo | eb2b931 | 2008-02-23 15:17:14 +0100 | [diff] [blame] | 224 | { |
| 225 | struct mesh_path *mpath; |
Luis Carlos Cobo | eb2b931 | 2008-02-23 15:17:14 +0100 | [diff] [blame] | 226 | |
Bob Copeland | 60854fd | 2016-03-02 10:09:20 -0500 | [diff] [blame] | 227 | mpath = rhashtable_lookup_fast(&tbl->rhead, dst, mesh_rht_params); |
| 228 | |
| 229 | if (mpath && mpath_expired(mpath)) { |
| 230 | spin_lock_bh(&mpath->state_lock); |
| 231 | mpath->flags &= ~MESH_PATH_ACTIVE; |
| 232 | spin_unlock_bh(&mpath->state_lock); |
Luis Carlos Cobo | eb2b931 | 2008-02-23 15:17:14 +0100 | [diff] [blame] | 233 | } |
Bob Copeland | 60854fd | 2016-03-02 10:09:20 -0500 | [diff] [blame] | 234 | return mpath; |
Luis Carlos Cobo | eb2b931 | 2008-02-23 15:17:14 +0100 | [diff] [blame] | 235 | } |
| 236 | |
Luis Carlos Cobo | eb2b931 | 2008-02-23 15:17:14 +0100 | [diff] [blame] | 237 | /** |
| 238 | * mesh_path_lookup - look up a path in the mesh path table |
Luis Carlos Cobo | eb2b931 | 2008-02-23 15:17:14 +0100 | [diff] [blame] | 239 | * @sdata: local subif |
Johannes Berg | bf7cd94 | 2013-02-15 14:40:31 +0100 | [diff] [blame] | 240 | * @dst: hardware address (ETH_ALEN length) of destination |
Luis Carlos Cobo | eb2b931 | 2008-02-23 15:17:14 +0100 | [diff] [blame] | 241 | * |
| 242 | * Returns: pointer to the mesh path structure, or NULL if not found |
| 243 | * |
| 244 | * Locking: must be called within a read rcu section. |
| 245 | */ |
Johannes Berg | bf7cd94 | 2013-02-15 14:40:31 +0100 | [diff] [blame] | 246 | struct mesh_path * |
| 247 | mesh_path_lookup(struct ieee80211_sub_if_data *sdata, const u8 *dst) |
Luis Carlos Cobo | eb2b931 | 2008-02-23 15:17:14 +0100 | [diff] [blame] | 248 | { |
Bob Copeland | 60854fd | 2016-03-02 10:09:20 -0500 | [diff] [blame] | 249 | return mpath_lookup(sdata->u.mesh.mesh_paths, dst, sdata); |
Luis Carlos Cobo | eb2b931 | 2008-02-23 15:17:14 +0100 | [diff] [blame] | 250 | } |
| 251 | |
Johannes Berg | bf7cd94 | 2013-02-15 14:40:31 +0100 | [diff] [blame] | 252 | struct mesh_path * |
| 253 | mpp_path_lookup(struct ieee80211_sub_if_data *sdata, const u8 *dst) |
YanBo | 79617de | 2008-09-22 13:30:32 +0800 | [diff] [blame] | 254 | { |
Bob Copeland | 60854fd | 2016-03-02 10:09:20 -0500 | [diff] [blame] | 255 | return mpath_lookup(sdata->u.mesh.mpp_paths, dst, sdata); |
YanBo | 79617de | 2008-09-22 13:30:32 +0800 | [diff] [blame] | 256 | } |
| 257 | |
Bob Copeland | 60854fd | 2016-03-02 10:09:20 -0500 | [diff] [blame] | 258 | static struct mesh_path * |
| 259 | __mesh_path_lookup_by_idx(struct mesh_table *tbl, int idx) |
| 260 | { |
| 261 | int i = 0, ret; |
| 262 | struct mesh_path *mpath = NULL; |
| 263 | struct rhashtable_iter iter; |
| 264 | |
| 265 | ret = rhashtable_walk_init(&tbl->rhead, &iter, GFP_ATOMIC); |
| 266 | if (ret) |
| 267 | return NULL; |
| 268 | |
| 269 | ret = rhashtable_walk_start(&iter); |
| 270 | if (ret && ret != -EAGAIN) |
| 271 | goto err; |
| 272 | |
| 273 | while ((mpath = rhashtable_walk_next(&iter))) { |
| 274 | if (IS_ERR(mpath) && PTR_ERR(mpath) == -EAGAIN) |
| 275 | continue; |
| 276 | if (IS_ERR(mpath)) |
| 277 | break; |
| 278 | if (i++ == idx) |
| 279 | break; |
| 280 | } |
| 281 | err: |
| 282 | rhashtable_walk_stop(&iter); |
| 283 | rhashtable_walk_exit(&iter); |
| 284 | |
| 285 | if (IS_ERR(mpath) || !mpath) |
| 286 | return NULL; |
| 287 | |
| 288 | if (mpath_expired(mpath)) { |
| 289 | spin_lock_bh(&mpath->state_lock); |
| 290 | mpath->flags &= ~MESH_PATH_ACTIVE; |
| 291 | spin_unlock_bh(&mpath->state_lock); |
| 292 | } |
| 293 | return mpath; |
| 294 | } |
YanBo | 79617de | 2008-09-22 13:30:32 +0800 | [diff] [blame] | 295 | |
Luis Carlos Cobo | eb2b931 | 2008-02-23 15:17:14 +0100 | [diff] [blame] | 296 | /** |
| 297 | * mesh_path_lookup_by_idx - look up a path in the mesh path table by its index |
| 298 | * @idx: index |
Jasper Bryant-Greene | f698d85 | 2008-08-03 12:04:37 +1200 | [diff] [blame] | 299 | * @sdata: local subif, or NULL for all entries |
Luis Carlos Cobo | eb2b931 | 2008-02-23 15:17:14 +0100 | [diff] [blame] | 300 | * |
| 301 | * Returns: pointer to the mesh path structure, or NULL if not found. |
| 302 | * |
| 303 | * Locking: must be called within a read rcu section. |
| 304 | */ |
Johannes Berg | bf7cd94 | 2013-02-15 14:40:31 +0100 | [diff] [blame] | 305 | struct mesh_path * |
| 306 | mesh_path_lookup_by_idx(struct ieee80211_sub_if_data *sdata, int idx) |
Luis Carlos Cobo | eb2b931 | 2008-02-23 15:17:14 +0100 | [diff] [blame] | 307 | { |
Bob Copeland | 60854fd | 2016-03-02 10:09:20 -0500 | [diff] [blame] | 308 | return __mesh_path_lookup_by_idx(sdata->u.mesh.mesh_paths, idx); |
Luis Carlos Cobo | eb2b931 | 2008-02-23 15:17:14 +0100 | [diff] [blame] | 309 | } |
| 310 | |
Javier Cardona | 5ee68e5 | 2011-08-09 16:45:08 -0700 | [diff] [blame] | 311 | /** |
Henning Rogge | a2db2ed | 2014-09-12 08:58:50 +0200 | [diff] [blame] | 312 | * mpp_path_lookup_by_idx - look up a path in the proxy path table by its index |
| 313 | * @idx: index |
| 314 | * @sdata: local subif, or NULL for all entries |
| 315 | * |
| 316 | * Returns: pointer to the proxy path structure, or NULL if not found. |
| 317 | * |
| 318 | * Locking: must be called within a read rcu section. |
| 319 | */ |
| 320 | struct mesh_path * |
| 321 | mpp_path_lookup_by_idx(struct ieee80211_sub_if_data *sdata, int idx) |
| 322 | { |
Bob Copeland | 60854fd | 2016-03-02 10:09:20 -0500 | [diff] [blame] | 323 | return __mesh_path_lookup_by_idx(sdata->u.mesh.mpp_paths, idx); |
Henning Rogge | a2db2ed | 2014-09-12 08:58:50 +0200 | [diff] [blame] | 324 | } |
| 325 | |
| 326 | /** |
Johannes Berg | 30be52e | 2011-11-21 11:23:50 +0100 | [diff] [blame] | 327 | * mesh_path_add_gate - add the given mpath to a mesh gate to our path table |
| 328 | * @mpath: gate path to add to table |
Javier Cardona | 5ee68e5 | 2011-08-09 16:45:08 -0700 | [diff] [blame] | 329 | */ |
Johannes Berg | 30be52e | 2011-11-21 11:23:50 +0100 | [diff] [blame] | 330 | int mesh_path_add_gate(struct mesh_path *mpath) |
Javier Cardona | 5ee68e5 | 2011-08-09 16:45:08 -0700 | [diff] [blame] | 331 | { |
Johannes Berg | 30be52e | 2011-11-21 11:23:50 +0100 | [diff] [blame] | 332 | struct mesh_table *tbl; |
Javier Cardona | 5ee68e5 | 2011-08-09 16:45:08 -0700 | [diff] [blame] | 333 | int err; |
| 334 | |
| 335 | rcu_read_lock(); |
Bob Copeland | 60854fd | 2016-03-02 10:09:20 -0500 | [diff] [blame] | 336 | tbl = mpath->sdata->u.mesh.mesh_paths; |
Javier Cardona | 5ee68e5 | 2011-08-09 16:45:08 -0700 | [diff] [blame] | 337 | |
Bob Copeland | 947c2a0 | 2016-02-28 20:03:59 -0500 | [diff] [blame] | 338 | spin_lock_bh(&mpath->state_lock); |
| 339 | if (mpath->is_gate) { |
| 340 | err = -EEXIST; |
| 341 | spin_unlock_bh(&mpath->state_lock); |
Javier Cardona | 5ee68e5 | 2011-08-09 16:45:08 -0700 | [diff] [blame] | 342 | goto err_rcu; |
| 343 | } |
Javier Cardona | 5ee68e5 | 2011-08-09 16:45:08 -0700 | [diff] [blame] | 344 | mpath->is_gate = true; |
| 345 | mpath->sdata->u.mesh.num_gates++; |
Bob Copeland | 947c2a0 | 2016-02-28 20:03:59 -0500 | [diff] [blame] | 346 | |
| 347 | spin_lock(&tbl->gates_lock); |
| 348 | hlist_add_head_rcu(&mpath->gate_list, tbl->known_gates); |
| 349 | spin_unlock(&tbl->gates_lock); |
| 350 | |
| 351 | spin_unlock_bh(&mpath->state_lock); |
| 352 | |
Johannes Berg | bdcbd8e | 2012-06-22 11:29:50 +0200 | [diff] [blame] | 353 | mpath_dbg(mpath->sdata, |
| 354 | "Mesh path: Recorded new gate: %pM. %d known gates\n", |
| 355 | mpath->dst, mpath->sdata->u.mesh.num_gates); |
Johannes Berg | bf7cd94 | 2013-02-15 14:40:31 +0100 | [diff] [blame] | 356 | err = 0; |
Javier Cardona | 5ee68e5 | 2011-08-09 16:45:08 -0700 | [diff] [blame] | 357 | err_rcu: |
| 358 | rcu_read_unlock(); |
| 359 | return err; |
| 360 | } |
| 361 | |
| 362 | /** |
| 363 | * mesh_gate_del - remove a mesh gate from the list of known gates |
| 364 | * @tbl: table which holds our list of known gates |
| 365 | * @mpath: gate mpath |
Javier Cardona | 5ee68e5 | 2011-08-09 16:45:08 -0700 | [diff] [blame] | 366 | */ |
Johannes Berg | bf7cd94 | 2013-02-15 14:40:31 +0100 | [diff] [blame] | 367 | static void mesh_gate_del(struct mesh_table *tbl, struct mesh_path *mpath) |
Javier Cardona | 5ee68e5 | 2011-08-09 16:45:08 -0700 | [diff] [blame] | 368 | { |
Bob Copeland | 947c2a0 | 2016-02-28 20:03:59 -0500 | [diff] [blame] | 369 | lockdep_assert_held(&mpath->state_lock); |
| 370 | if (!mpath->is_gate) |
| 371 | return; |
Javier Cardona | 5ee68e5 | 2011-08-09 16:45:08 -0700 | [diff] [blame] | 372 | |
Bob Copeland | 947c2a0 | 2016-02-28 20:03:59 -0500 | [diff] [blame] | 373 | mpath->is_gate = false; |
| 374 | spin_lock_bh(&tbl->gates_lock); |
| 375 | hlist_del_rcu(&mpath->gate_list); |
| 376 | mpath->sdata->u.mesh.num_gates--; |
| 377 | spin_unlock_bh(&tbl->gates_lock); |
| 378 | |
| 379 | mpath_dbg(mpath->sdata, |
| 380 | "Mesh path: Deleted gate: %pM. %d known gates\n", |
| 381 | mpath->dst, mpath->sdata->u.mesh.num_gates); |
Javier Cardona | 5ee68e5 | 2011-08-09 16:45:08 -0700 | [diff] [blame] | 382 | } |
| 383 | |
| 384 | /** |
Javier Cardona | 5ee68e5 | 2011-08-09 16:45:08 -0700 | [diff] [blame] | 385 | * mesh_gate_num - number of gates known to this interface |
| 386 | * @sdata: subif data |
| 387 | */ |
| 388 | int mesh_gate_num(struct ieee80211_sub_if_data *sdata) |
| 389 | { |
| 390 | return sdata->u.mesh.num_gates; |
| 391 | } |
| 392 | |
Bob Copeland | b15dc38 | 2016-02-28 20:03:58 -0500 | [diff] [blame] | 393 | static |
| 394 | struct mesh_path *mesh_path_new(struct ieee80211_sub_if_data *sdata, |
| 395 | const u8 *dst, gfp_t gfp_flags) |
| 396 | { |
| 397 | struct mesh_path *new_mpath; |
| 398 | |
| 399 | new_mpath = kzalloc(sizeof(struct mesh_path), gfp_flags); |
| 400 | if (!new_mpath) |
| 401 | return NULL; |
| 402 | |
| 403 | memcpy(new_mpath->dst, dst, ETH_ALEN); |
| 404 | eth_broadcast_addr(new_mpath->rann_snd_addr); |
| 405 | new_mpath->is_root = false; |
| 406 | new_mpath->sdata = sdata; |
| 407 | new_mpath->flags = 0; |
| 408 | skb_queue_head_init(&new_mpath->frame_queue); |
| 409 | new_mpath->timer.data = (unsigned long) new_mpath; |
| 410 | new_mpath->timer.function = mesh_path_timer; |
| 411 | new_mpath->exp_time = jiffies; |
| 412 | spin_lock_init(&new_mpath->state_lock); |
| 413 | init_timer(&new_mpath->timer); |
| 414 | |
| 415 | return new_mpath; |
| 416 | } |
| 417 | |
Luis Carlos Cobo | eb2b931 | 2008-02-23 15:17:14 +0100 | [diff] [blame] | 418 | /** |
| 419 | * mesh_path_add - allocate and add a new path to the mesh path table |
Johannes Berg | bf7cd94 | 2013-02-15 14:40:31 +0100 | [diff] [blame] | 420 | * @dst: destination address of the path (ETH_ALEN length) |
Jasper Bryant-Greene | f698d85 | 2008-08-03 12:04:37 +1200 | [diff] [blame] | 421 | * @sdata: local subif |
Luis Carlos Cobo | eb2b931 | 2008-02-23 15:17:14 +0100 | [diff] [blame] | 422 | * |
André Goddard Rosa | af901ca | 2009-11-14 13:09:05 -0200 | [diff] [blame] | 423 | * Returns: 0 on success |
Luis Carlos Cobo | eb2b931 | 2008-02-23 15:17:14 +0100 | [diff] [blame] | 424 | * |
| 425 | * State: the initial state of the new path is set to 0 |
| 426 | */ |
Bob Copeland | ae76eef | 2013-03-29 09:38:39 -0400 | [diff] [blame] | 427 | struct mesh_path *mesh_path_add(struct ieee80211_sub_if_data *sdata, |
| 428 | const u8 *dst) |
Luis Carlos Cobo | eb2b931 | 2008-02-23 15:17:14 +0100 | [diff] [blame] | 429 | { |
Johannes Berg | 349eb8c | 2011-05-14 11:56:16 +0200 | [diff] [blame] | 430 | struct mesh_table *tbl; |
Luis Carlos Cobo | eb2b931 | 2008-02-23 15:17:14 +0100 | [diff] [blame] | 431 | struct mesh_path *mpath, *new_mpath; |
Bob Copeland | 60854fd | 2016-03-02 10:09:20 -0500 | [diff] [blame] | 432 | int ret; |
Luis Carlos Cobo | eb2b931 | 2008-02-23 15:17:14 +0100 | [diff] [blame] | 433 | |
Joe Perches | b203ca3 | 2012-05-08 18:56:52 +0000 | [diff] [blame] | 434 | if (ether_addr_equal(dst, sdata->vif.addr)) |
Luis Carlos Cobo | eb2b931 | 2008-02-23 15:17:14 +0100 | [diff] [blame] | 435 | /* never add ourselves as neighbours */ |
Bob Copeland | ae76eef | 2013-03-29 09:38:39 -0400 | [diff] [blame] | 436 | return ERR_PTR(-ENOTSUPP); |
Luis Carlos Cobo | eb2b931 | 2008-02-23 15:17:14 +0100 | [diff] [blame] | 437 | |
| 438 | if (is_multicast_ether_addr(dst)) |
Bob Copeland | ae76eef | 2013-03-29 09:38:39 -0400 | [diff] [blame] | 439 | return ERR_PTR(-ENOTSUPP); |
Luis Carlos Cobo | eb2b931 | 2008-02-23 15:17:14 +0100 | [diff] [blame] | 440 | |
Johannes Berg | 472dbc4 | 2008-09-11 00:01:49 +0200 | [diff] [blame] | 441 | if (atomic_add_unless(&sdata->u.mesh.mpaths, 1, MESH_MAX_MPATHS) == 0) |
Bob Copeland | ae76eef | 2013-03-29 09:38:39 -0400 | [diff] [blame] | 442 | return ERR_PTR(-ENOSPC); |
| 443 | |
Bob Copeland | b15dc38 | 2016-02-28 20:03:58 -0500 | [diff] [blame] | 444 | new_mpath = mesh_path_new(sdata, dst, GFP_ATOMIC); |
Pavel Emelyanov | 402d775 | 2008-05-06 18:53:43 +0400 | [diff] [blame] | 445 | if (!new_mpath) |
Bob Copeland | 60854fd | 2016-03-02 10:09:20 -0500 | [diff] [blame] | 446 | return ERR_PTR(-ENOMEM); |
Pavel Emelyanov | 402d775 | 2008-05-06 18:53:43 +0400 | [diff] [blame] | 447 | |
Bob Copeland | 60854fd | 2016-03-02 10:09:20 -0500 | [diff] [blame] | 448 | tbl = sdata->u.mesh.mesh_paths; |
| 449 | do { |
| 450 | ret = rhashtable_lookup_insert_fast(&tbl->rhead, |
| 451 | &new_mpath->rhash, |
| 452 | mesh_rht_params); |
Pavel Emelyanov | f84e71a | 2008-05-06 18:46:36 +0400 | [diff] [blame] | 453 | |
Bob Copeland | 60854fd | 2016-03-02 10:09:20 -0500 | [diff] [blame] | 454 | if (ret == -EEXIST) |
| 455 | mpath = rhashtable_lookup_fast(&tbl->rhead, |
| 456 | dst, |
| 457 | mesh_rht_params); |
Luis Carlos Cobo | eb2b931 | 2008-02-23 15:17:14 +0100 | [diff] [blame] | 458 | |
Bob Copeland | 60854fd | 2016-03-02 10:09:20 -0500 | [diff] [blame] | 459 | } while (unlikely(ret == -EEXIST && !mpath)); |
| 460 | |
| 461 | if (ret && ret != -EEXIST) |
| 462 | return ERR_PTR(ret); |
| 463 | |
| 464 | /* At this point either new_mpath was added, or we found a |
| 465 | * matching entry already in the table; in the latter case |
| 466 | * free the unnecessary new entry. |
| 467 | */ |
| 468 | if (ret == -EEXIST) { |
| 469 | kfree(new_mpath); |
| 470 | new_mpath = mpath; |
| 471 | } |
Bob Copeland | 2bdaf38 | 2016-02-28 20:03:56 -0500 | [diff] [blame] | 472 | sdata->u.mesh.mesh_paths_generation++; |
Bob Copeland | 60854fd | 2016-03-02 10:09:20 -0500 | [diff] [blame] | 473 | return new_mpath; |
Javier Cardona | 1888923 | 2009-08-10 12:15:52 -0700 | [diff] [blame] | 474 | } |
Luis Carlos Cobo | eb2b931 | 2008-02-23 15:17:14 +0100 | [diff] [blame] | 475 | |
Johannes Berg | bf7cd94 | 2013-02-15 14:40:31 +0100 | [diff] [blame] | 476 | int mpp_path_add(struct ieee80211_sub_if_data *sdata, |
| 477 | const u8 *dst, const u8 *mpp) |
YanBo | 79617de | 2008-09-22 13:30:32 +0800 | [diff] [blame] | 478 | { |
Johannes Berg | 349eb8c | 2011-05-14 11:56:16 +0200 | [diff] [blame] | 479 | struct mesh_table *tbl; |
Bob Copeland | 60854fd | 2016-03-02 10:09:20 -0500 | [diff] [blame] | 480 | struct mesh_path *new_mpath; |
| 481 | int ret; |
YanBo | 79617de | 2008-09-22 13:30:32 +0800 | [diff] [blame] | 482 | |
Joe Perches | b203ca3 | 2012-05-08 18:56:52 +0000 | [diff] [blame] | 483 | if (ether_addr_equal(dst, sdata->vif.addr)) |
YanBo | 79617de | 2008-09-22 13:30:32 +0800 | [diff] [blame] | 484 | /* never add ourselves as neighbours */ |
| 485 | return -ENOTSUPP; |
| 486 | |
| 487 | if (is_multicast_ether_addr(dst)) |
| 488 | return -ENOTSUPP; |
| 489 | |
Bob Copeland | b15dc38 | 2016-02-28 20:03:58 -0500 | [diff] [blame] | 490 | new_mpath = mesh_path_new(sdata, dst, GFP_ATOMIC); |
YanBo | 79617de | 2008-09-22 13:30:32 +0800 | [diff] [blame] | 491 | |
Bob Copeland | 60854fd | 2016-03-02 10:09:20 -0500 | [diff] [blame] | 492 | if (!new_mpath) |
| 493 | return -ENOMEM; |
YanBo | 79617de | 2008-09-22 13:30:32 +0800 | [diff] [blame] | 494 | |
YanBo | 79617de | 2008-09-22 13:30:32 +0800 | [diff] [blame] | 495 | memcpy(new_mpath->mpp, mpp, ETH_ALEN); |
Bob Copeland | 60854fd | 2016-03-02 10:09:20 -0500 | [diff] [blame] | 496 | tbl = sdata->u.mesh.mpp_paths; |
| 497 | ret = rhashtable_lookup_insert_fast(&tbl->rhead, |
| 498 | &new_mpath->rhash, |
| 499 | mesh_rht_params); |
Henning Rogge | a2db2ed | 2014-09-12 08:58:50 +0200 | [diff] [blame] | 500 | |
Bob Copeland | 2bdaf38 | 2016-02-28 20:03:56 -0500 | [diff] [blame] | 501 | sdata->u.mesh.mpp_paths_generation++; |
Bob Copeland | 60854fd | 2016-03-02 10:09:20 -0500 | [diff] [blame] | 502 | return ret; |
YanBo | 79617de | 2008-09-22 13:30:32 +0800 | [diff] [blame] | 503 | } |
| 504 | |
| 505 | |
Luis Carlos Cobo | eb2b931 | 2008-02-23 15:17:14 +0100 | [diff] [blame] | 506 | /** |
| 507 | * mesh_plink_broken - deactivates paths and sends perr when a link breaks |
| 508 | * |
| 509 | * @sta: broken peer link |
| 510 | * |
| 511 | * This function must be called from the rate control algorithm if enough |
| 512 | * delivery errors suggest that a peer link is no longer usable. |
| 513 | */ |
| 514 | void mesh_plink_broken(struct sta_info *sta) |
| 515 | { |
Bob Copeland | 60854fd | 2016-03-02 10:09:20 -0500 | [diff] [blame] | 516 | struct ieee80211_sub_if_data *sdata = sta->sdata; |
| 517 | struct mesh_table *tbl = sdata->u.mesh.mesh_paths; |
Johannes Berg | 15ff636 | 2009-11-17 13:34:04 +0100 | [diff] [blame] | 518 | 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] | 519 | struct mesh_path *mpath; |
Bob Copeland | 60854fd | 2016-03-02 10:09:20 -0500 | [diff] [blame] | 520 | struct rhashtable_iter iter; |
| 521 | int ret; |
Luis Carlos Cobo | eb2b931 | 2008-02-23 15:17:14 +0100 | [diff] [blame] | 522 | |
Bob Copeland | 60854fd | 2016-03-02 10:09:20 -0500 | [diff] [blame] | 523 | ret = rhashtable_walk_init(&tbl->rhead, &iter, GFP_ATOMIC); |
| 524 | if (ret) |
| 525 | return; |
| 526 | |
| 527 | ret = rhashtable_walk_start(&iter); |
| 528 | if (ret && ret != -EAGAIN) |
| 529 | goto out; |
| 530 | |
| 531 | while ((mpath = rhashtable_walk_next(&iter))) { |
| 532 | if (IS_ERR(mpath) && PTR_ERR(mpath) == -EAGAIN) |
| 533 | continue; |
| 534 | if (IS_ERR(mpath)) |
| 535 | break; |
Andreea-Cristina Bernat | 2688eba | 2014-08-17 16:18:02 +0300 | [diff] [blame] | 536 | if (rcu_access_pointer(mpath->next_hop) == sta && |
Luis Carlos Cobo | eb2b931 | 2008-02-23 15:17:14 +0100 | [diff] [blame] | 537 | mpath->flags & MESH_PATH_ACTIVE && |
| 538 | !(mpath->flags & MESH_PATH_FIXED)) { |
Javier Cardona | f5e50cd | 2011-08-29 13:23:05 -0700 | [diff] [blame] | 539 | spin_lock_bh(&mpath->state_lock); |
Luis Carlos Cobo | eb2b931 | 2008-02-23 15:17:14 +0100 | [diff] [blame] | 540 | mpath->flags &= ~MESH_PATH_ACTIVE; |
Rui Paulo | d19b3bf | 2009-11-09 23:46:55 +0000 | [diff] [blame] | 541 | ++mpath->sn; |
Luis Carlos Cobo | eb2b931 | 2008-02-23 15:17:14 +0100 | [diff] [blame] | 542 | spin_unlock_bh(&mpath->state_lock); |
Johannes Berg | bf7cd94 | 2013-02-15 14:40:31 +0100 | [diff] [blame] | 543 | mesh_path_error_tx(sdata, |
Chun-Yeow Yeoh | f63f842 | 2013-11-13 15:39:12 +0800 | [diff] [blame] | 544 | sdata->u.mesh.mshcfg.element_ttl, |
| 545 | mpath->dst, mpath->sn, |
| 546 | WLAN_REASON_MESH_PATH_DEST_UNREACHABLE, bcast); |
Javier Cardona | f5e50cd | 2011-08-29 13:23:05 -0700 | [diff] [blame] | 547 | } |
Luis Carlos Cobo | eb2b931 | 2008-02-23 15:17:14 +0100 | [diff] [blame] | 548 | } |
Bob Copeland | 60854fd | 2016-03-02 10:09:20 -0500 | [diff] [blame] | 549 | out: |
| 550 | rhashtable_walk_stop(&iter); |
| 551 | rhashtable_walk_exit(&iter); |
Luis Carlos Cobo | eb2b931 | 2008-02-23 15:17:14 +0100 | [diff] [blame] | 552 | } |
Luis Carlos Cobo | eb2b931 | 2008-02-23 15:17:14 +0100 | [diff] [blame] | 553 | |
Bob Copeland | 60854fd | 2016-03-02 10:09:20 -0500 | [diff] [blame] | 554 | static void __mesh_path_del(struct mesh_table *tbl, struct mesh_path *mpath) |
Javier Cardona | 19c50b3 | 2011-08-29 13:23:07 -0700 | [diff] [blame] | 555 | { |
Bob Copeland | 60854fd | 2016-03-02 10:09:20 -0500 | [diff] [blame] | 556 | struct ieee80211_sub_if_data *sdata = mpath->sdata; |
Javier Cardona | 19c50b3 | 2011-08-29 13:23:07 -0700 | [diff] [blame] | 557 | |
Bob Copeland | 60854fd | 2016-03-02 10:09:20 -0500 | [diff] [blame] | 558 | rhashtable_remove_fast(&tbl->rhead, &mpath->rhash, mesh_rht_params); |
Bob Copeland | 947c2a0 | 2016-02-28 20:03:59 -0500 | [diff] [blame] | 559 | spin_lock_bh(&mpath->state_lock); |
Javier Cardona | 19c50b3 | 2011-08-29 13:23:07 -0700 | [diff] [blame] | 560 | mpath->flags |= MESH_PATH_RESOLVING; |
Bob Copeland | 60854fd | 2016-03-02 10:09:20 -0500 | [diff] [blame] | 561 | mesh_gate_del(tbl, mpath); |
| 562 | call_rcu(&mpath->rcu, mesh_path_reclaim); |
Bob Copeland | 947c2a0 | 2016-02-28 20:03:59 -0500 | [diff] [blame] | 563 | spin_unlock_bh(&mpath->state_lock); |
Johannes Berg | c2e703a | 2015-11-17 14:25:21 +0100 | [diff] [blame] | 564 | atomic_dec(&sdata->u.mesh.mpaths); |
Javier Cardona | 19c50b3 | 2011-08-29 13:23:07 -0700 | [diff] [blame] | 565 | atomic_dec(&tbl->entries); |
| 566 | } |
| 567 | |
Luis Carlos Cobo | eb2b931 | 2008-02-23 15:17:14 +0100 | [diff] [blame] | 568 | /** |
| 569 | * mesh_path_flush_by_nexthop - Deletes mesh paths if their next hop matches |
| 570 | * |
Ben Hutchings | 2c53040 | 2012-07-10 10:55:09 +0000 | [diff] [blame] | 571 | * @sta: mesh peer to match |
Luis Carlos Cobo | eb2b931 | 2008-02-23 15:17:14 +0100 | [diff] [blame] | 572 | * |
Luis Carlos Cobo | b4e08ea | 2008-02-29 15:46:08 -0800 | [diff] [blame] | 573 | * RCU notes: this function is called when a mesh plink transitions from |
| 574 | * PLINK_ESTAB to any other state, since PLINK_ESTAB state is the only one that |
| 575 | * 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] | 576 | * sta_info_destroy() calls this) so any reader in a rcu read block will be |
| 577 | * protected against the plink disappearing. |
Luis Carlos Cobo | eb2b931 | 2008-02-23 15:17:14 +0100 | [diff] [blame] | 578 | */ |
| 579 | void mesh_path_flush_by_nexthop(struct sta_info *sta) |
| 580 | { |
Bob Copeland | 2bdaf38 | 2016-02-28 20:03:56 -0500 | [diff] [blame] | 581 | struct ieee80211_sub_if_data *sdata = sta->sdata; |
Bob Copeland | 60854fd | 2016-03-02 10:09:20 -0500 | [diff] [blame] | 582 | struct mesh_table *tbl = sdata->u.mesh.mesh_paths; |
Luis Carlos Cobo | eb2b931 | 2008-02-23 15:17:14 +0100 | [diff] [blame] | 583 | struct mesh_path *mpath; |
Bob Copeland | 60854fd | 2016-03-02 10:09:20 -0500 | [diff] [blame] | 584 | struct rhashtable_iter iter; |
| 585 | int ret; |
Luis Carlos Cobo | eb2b931 | 2008-02-23 15:17:14 +0100 | [diff] [blame] | 586 | |
Bob Copeland | 60854fd | 2016-03-02 10:09:20 -0500 | [diff] [blame] | 587 | ret = rhashtable_walk_init(&tbl->rhead, &iter, GFP_ATOMIC); |
| 588 | if (ret) |
| 589 | return; |
| 590 | |
| 591 | ret = rhashtable_walk_start(&iter); |
| 592 | if (ret && ret != -EAGAIN) |
| 593 | goto out; |
| 594 | |
| 595 | while ((mpath = rhashtable_walk_next(&iter))) { |
| 596 | if (IS_ERR(mpath) && PTR_ERR(mpath) == -EAGAIN) |
| 597 | continue; |
| 598 | if (IS_ERR(mpath)) |
| 599 | break; |
| 600 | |
| 601 | if (rcu_access_pointer(mpath->next_hop) == sta) |
| 602 | __mesh_path_del(tbl, mpath); |
Luis Carlos Cobo | eb2b931 | 2008-02-23 15:17:14 +0100 | [diff] [blame] | 603 | } |
Bob Copeland | 60854fd | 2016-03-02 10:09:20 -0500 | [diff] [blame] | 604 | out: |
| 605 | rhashtable_walk_stop(&iter); |
| 606 | rhashtable_walk_exit(&iter); |
Luis Carlos Cobo | eb2b931 | 2008-02-23 15:17:14 +0100 | [diff] [blame] | 607 | } |
| 608 | |
Henning Rogge | bf5a70e | 2016-02-03 13:58:36 +0100 | [diff] [blame] | 609 | static void mpp_flush_by_proxy(struct ieee80211_sub_if_data *sdata, |
| 610 | const u8 *proxy) |
| 611 | { |
Bob Copeland | 60854fd | 2016-03-02 10:09:20 -0500 | [diff] [blame] | 612 | struct mesh_table *tbl = sdata->u.mesh.mpp_paths; |
| 613 | struct mesh_path *mpath; |
| 614 | struct rhashtable_iter iter; |
| 615 | int ret; |
Henning Rogge | bf5a70e | 2016-02-03 13:58:36 +0100 | [diff] [blame] | 616 | |
Bob Copeland | 60854fd | 2016-03-02 10:09:20 -0500 | [diff] [blame] | 617 | ret = rhashtable_walk_init(&tbl->rhead, &iter, GFP_ATOMIC); |
| 618 | if (ret) |
| 619 | return; |
| 620 | |
| 621 | ret = rhashtable_walk_start(&iter); |
| 622 | if (ret && ret != -EAGAIN) |
| 623 | goto out; |
| 624 | |
| 625 | while ((mpath = rhashtable_walk_next(&iter))) { |
| 626 | if (IS_ERR(mpath) && PTR_ERR(mpath) == -EAGAIN) |
| 627 | continue; |
| 628 | if (IS_ERR(mpath)) |
| 629 | break; |
| 630 | |
| 631 | if (ether_addr_equal(mpath->mpp, proxy)) |
| 632 | __mesh_path_del(tbl, mpath); |
Henning Rogge | bf5a70e | 2016-02-03 13:58:36 +0100 | [diff] [blame] | 633 | } |
Bob Copeland | 60854fd | 2016-03-02 10:09:20 -0500 | [diff] [blame] | 634 | out: |
| 635 | rhashtable_walk_stop(&iter); |
| 636 | rhashtable_walk_exit(&iter); |
Henning Rogge | bf5a70e | 2016-02-03 13:58:36 +0100 | [diff] [blame] | 637 | } |
| 638 | |
Bob Copeland | 60854fd | 2016-03-02 10:09:20 -0500 | [diff] [blame] | 639 | static void table_flush_by_iface(struct mesh_table *tbl) |
Luis Carlos Cobo | eb2b931 | 2008-02-23 15:17:14 +0100 | [diff] [blame] | 640 | { |
| 641 | struct mesh_path *mpath; |
Bob Copeland | 60854fd | 2016-03-02 10:09:20 -0500 | [diff] [blame] | 642 | struct rhashtable_iter iter; |
| 643 | int ret; |
Luis Carlos Cobo | eb2b931 | 2008-02-23 15:17:14 +0100 | [diff] [blame] | 644 | |
Bob Copeland | 60854fd | 2016-03-02 10:09:20 -0500 | [diff] [blame] | 645 | ret = rhashtable_walk_init(&tbl->rhead, &iter, GFP_ATOMIC); |
| 646 | if (ret) |
| 647 | return; |
| 648 | |
| 649 | ret = rhashtable_walk_start(&iter); |
| 650 | if (ret && ret != -EAGAIN) |
| 651 | goto out; |
| 652 | |
| 653 | while ((mpath = rhashtable_walk_next(&iter))) { |
| 654 | if (IS_ERR(mpath) && PTR_ERR(mpath) == -EAGAIN) |
| 655 | continue; |
| 656 | if (IS_ERR(mpath)) |
| 657 | break; |
| 658 | __mesh_path_del(tbl, mpath); |
Luis Carlos Cobo | eb2b931 | 2008-02-23 15:17:14 +0100 | [diff] [blame] | 659 | } |
Bob Copeland | 60854fd | 2016-03-02 10:09:20 -0500 | [diff] [blame] | 660 | out: |
| 661 | rhashtable_walk_stop(&iter); |
| 662 | rhashtable_walk_exit(&iter); |
Luis Carlos Cobo | eb2b931 | 2008-02-23 15:17:14 +0100 | [diff] [blame] | 663 | } |
| 664 | |
Javier Cardona | ece1a2e | 2011-08-29 13:23:04 -0700 | [diff] [blame] | 665 | /** |
| 666 | * mesh_path_flush_by_iface - Deletes all mesh paths associated with a given iface |
| 667 | * |
| 668 | * This function deletes both mesh paths as well as mesh portal paths. |
| 669 | * |
Ben Hutchings | 2c53040 | 2012-07-10 10:55:09 +0000 | [diff] [blame] | 670 | * @sdata: interface data to match |
Javier Cardona | ece1a2e | 2011-08-29 13:23:04 -0700 | [diff] [blame] | 671 | * |
| 672 | */ |
| 673 | 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] | 674 | { |
Bob Copeland | 60854fd | 2016-03-02 10:09:20 -0500 | [diff] [blame] | 675 | table_flush_by_iface(sdata->u.mesh.mesh_paths); |
| 676 | table_flush_by_iface(sdata->u.mesh.mpp_paths); |
Luis Carlos Cobo | eb2b931 | 2008-02-23 15:17:14 +0100 | [diff] [blame] | 677 | } |
| 678 | |
| 679 | /** |
Henning Rogge | 4cc955d | 2016-02-03 13:58:38 +0100 | [diff] [blame] | 680 | * table_path_del - delete a path from the mesh or mpp table |
Luis Carlos Cobo | eb2b931 | 2008-02-23 15:17:14 +0100 | [diff] [blame] | 681 | * |
Henning Rogge | 4cc955d | 2016-02-03 13:58:38 +0100 | [diff] [blame] | 682 | * @tbl: mesh or mpp path table |
Jasper Bryant-Greene | f698d85 | 2008-08-03 12:04:37 +1200 | [diff] [blame] | 683 | * @sdata: local subif |
Henning Rogge | 4cc955d | 2016-02-03 13:58:38 +0100 | [diff] [blame] | 684 | * @addr: dst address (ETH_ALEN length) |
Luis Carlos Cobo | eb2b931 | 2008-02-23 15:17:14 +0100 | [diff] [blame] | 685 | * |
André Goddard Rosa | af901ca | 2009-11-14 13:09:05 -0200 | [diff] [blame] | 686 | * Returns: 0 if successful |
Luis Carlos Cobo | eb2b931 | 2008-02-23 15:17:14 +0100 | [diff] [blame] | 687 | */ |
Bob Copeland | 60854fd | 2016-03-02 10:09:20 -0500 | [diff] [blame] | 688 | static int table_path_del(struct mesh_table *tbl, |
Henning Rogge | 4cc955d | 2016-02-03 13:58:38 +0100 | [diff] [blame] | 689 | struct ieee80211_sub_if_data *sdata, |
| 690 | const u8 *addr) |
Luis Carlos Cobo | eb2b931 | 2008-02-23 15:17:14 +0100 | [diff] [blame] | 691 | { |
| 692 | struct mesh_path *mpath; |
Luis Carlos Cobo | eb2b931 | 2008-02-23 15:17:14 +0100 | [diff] [blame] | 693 | |
Bob Copeland | 60854fd | 2016-03-02 10:09:20 -0500 | [diff] [blame] | 694 | rcu_read_lock(); |
| 695 | mpath = rhashtable_lookup_fast(&tbl->rhead, addr, mesh_rht_params); |
| 696 | if (!mpath) { |
| 697 | rcu_read_unlock(); |
| 698 | return -ENXIO; |
Luis Carlos Cobo | eb2b931 | 2008-02-23 15:17:14 +0100 | [diff] [blame] | 699 | } |
| 700 | |
Bob Copeland | 60854fd | 2016-03-02 10:09:20 -0500 | [diff] [blame] | 701 | __mesh_path_del(tbl, mpath); |
| 702 | rcu_read_unlock(); |
| 703 | return 0; |
Henning Rogge | 4cc955d | 2016-02-03 13:58:38 +0100 | [diff] [blame] | 704 | } |
| 705 | |
Bob Copeland | 60854fd | 2016-03-02 10:09:20 -0500 | [diff] [blame] | 706 | |
Henning Rogge | 4cc955d | 2016-02-03 13:58:38 +0100 | [diff] [blame] | 707 | /** |
| 708 | * mesh_path_del - delete a mesh path from the table |
| 709 | * |
| 710 | * @addr: dst address (ETH_ALEN length) |
| 711 | * @sdata: local subif |
| 712 | * |
| 713 | * Returns: 0 if successful |
| 714 | */ |
| 715 | int mesh_path_del(struct ieee80211_sub_if_data *sdata, const u8 *addr) |
| 716 | { |
Bob Copeland | 60854fd | 2016-03-02 10:09:20 -0500 | [diff] [blame] | 717 | int err; |
Henning Rogge | 4cc955d | 2016-02-03 13:58:38 +0100 | [diff] [blame] | 718 | |
| 719 | /* flush relevant mpp entries first */ |
| 720 | mpp_flush_by_proxy(sdata, addr); |
| 721 | |
Bob Copeland | 2bdaf38 | 2016-02-28 20:03:56 -0500 | [diff] [blame] | 722 | err = table_path_del(sdata->u.mesh.mesh_paths, sdata, addr); |
| 723 | sdata->u.mesh.mesh_paths_generation++; |
Henning Rogge | ab1c790 | 2016-02-03 13:58:37 +0100 | [diff] [blame] | 724 | return err; |
| 725 | } |
| 726 | |
| 727 | /** |
Luis Carlos Cobo | eb2b931 | 2008-02-23 15:17:14 +0100 | [diff] [blame] | 728 | * mesh_path_tx_pending - sends pending frames in a mesh path queue |
| 729 | * |
| 730 | * @mpath: mesh path to activate |
| 731 | * |
| 732 | * Locking: the state_lock of the mpath structure must NOT be held when calling |
| 733 | * this function. |
| 734 | */ |
| 735 | void mesh_path_tx_pending(struct mesh_path *mpath) |
| 736 | { |
Javier Cardona | 249b405 | 2009-07-07 10:55:03 -0700 | [diff] [blame] | 737 | if (mpath->flags & MESH_PATH_ACTIVE) |
| 738 | ieee80211_add_pending_skbs(mpath->sdata->local, |
| 739 | &mpath->frame_queue); |
Luis Carlos Cobo | eb2b931 | 2008-02-23 15:17:14 +0100 | [diff] [blame] | 740 | } |
| 741 | |
| 742 | /** |
Javier Cardona | 5ee68e5 | 2011-08-09 16:45:08 -0700 | [diff] [blame] | 743 | * mesh_path_send_to_gates - sends pending frames to all known mesh gates |
| 744 | * |
| 745 | * @mpath: mesh path whose queue will be emptied |
| 746 | * |
| 747 | * If there is only one gate, the frames are transferred from the failed mpath |
| 748 | * queue to that gate's queue. If there are more than one gates, the frames |
| 749 | * are copied from each gate to the next. After frames are copied, the |
| 750 | * mpath queues are emptied onto the transmission queue. |
| 751 | */ |
| 752 | int mesh_path_send_to_gates(struct mesh_path *mpath) |
| 753 | { |
| 754 | struct ieee80211_sub_if_data *sdata = mpath->sdata; |
Javier Cardona | 5ee68e5 | 2011-08-09 16:45:08 -0700 | [diff] [blame] | 755 | struct mesh_table *tbl; |
| 756 | struct mesh_path *from_mpath = mpath; |
Bob Copeland | 60854fd | 2016-03-02 10:09:20 -0500 | [diff] [blame] | 757 | struct mesh_path *gate; |
Javier Cardona | 5ee68e5 | 2011-08-09 16:45:08 -0700 | [diff] [blame] | 758 | bool copy = false; |
| 759 | struct hlist_head *known_gates; |
| 760 | |
Bob Copeland | 60854fd | 2016-03-02 10:09:20 -0500 | [diff] [blame] | 761 | tbl = sdata->u.mesh.mesh_paths; |
Javier Cardona | 5ee68e5 | 2011-08-09 16:45:08 -0700 | [diff] [blame] | 762 | known_gates = tbl->known_gates; |
Javier Cardona | 5ee68e5 | 2011-08-09 16:45:08 -0700 | [diff] [blame] | 763 | |
| 764 | if (!known_gates) |
| 765 | return -EHOSTUNREACH; |
| 766 | |
Bob Copeland | 60854fd | 2016-03-02 10:09:20 -0500 | [diff] [blame] | 767 | rcu_read_lock(); |
Bob Copeland | 947c2a0 | 2016-02-28 20:03:59 -0500 | [diff] [blame] | 768 | hlist_for_each_entry_rcu(gate, known_gates, gate_list) { |
| 769 | if (gate->flags & MESH_PATH_ACTIVE) { |
| 770 | mpath_dbg(sdata, "Forwarding to %pM\n", gate->dst); |
| 771 | mesh_path_move_to_queue(gate, from_mpath, copy); |
| 772 | from_mpath = gate; |
Javier Cardona | 5ee68e5 | 2011-08-09 16:45:08 -0700 | [diff] [blame] | 773 | copy = true; |
| 774 | } else { |
Johannes Berg | bdcbd8e | 2012-06-22 11:29:50 +0200 | [diff] [blame] | 775 | mpath_dbg(sdata, |
Johannes Berg | d671b2a | 2015-11-06 11:30:46 +0100 | [diff] [blame] | 776 | "Not forwarding to %pM (flags %#x)\n", |
Bob Copeland | 947c2a0 | 2016-02-28 20:03:59 -0500 | [diff] [blame] | 777 | gate->dst, gate->flags); |
Javier Cardona | 5ee68e5 | 2011-08-09 16:45:08 -0700 | [diff] [blame] | 778 | } |
| 779 | } |
| 780 | |
Bob Copeland | 947c2a0 | 2016-02-28 20:03:59 -0500 | [diff] [blame] | 781 | hlist_for_each_entry_rcu(gate, known_gates, gate_list) { |
| 782 | mpath_dbg(sdata, "Sending to %pM\n", gate->dst); |
| 783 | mesh_path_tx_pending(gate); |
Bob Copeland | 2bdaf38 | 2016-02-28 20:03:56 -0500 | [diff] [blame] | 784 | } |
Bob Copeland | 60854fd | 2016-03-02 10:09:20 -0500 | [diff] [blame] | 785 | rcu_read_unlock(); |
Javier Cardona | 5ee68e5 | 2011-08-09 16:45:08 -0700 | [diff] [blame] | 786 | |
| 787 | return (from_mpath == mpath) ? -EHOSTUNREACH : 0; |
| 788 | } |
| 789 | |
| 790 | /** |
Luis Carlos Cobo | eb2b931 | 2008-02-23 15:17:14 +0100 | [diff] [blame] | 791 | * mesh_path_discard_frame - discard a frame whose path could not be resolved |
| 792 | * |
| 793 | * @skb: frame to discard |
Jasper Bryant-Greene | f698d85 | 2008-08-03 12:04:37 +1200 | [diff] [blame] | 794 | * @sdata: network subif the frame was to be sent through |
Luis Carlos Cobo | eb2b931 | 2008-02-23 15:17:14 +0100 | [diff] [blame] | 795 | * |
Luis Carlos Cobo | eb2b931 | 2008-02-23 15:17:14 +0100 | [diff] [blame] | 796 | * Locking: the function must me called within a rcu_read_lock region |
| 797 | */ |
Johannes Berg | bf7cd94 | 2013-02-15 14:40:31 +0100 | [diff] [blame] | 798 | void mesh_path_discard_frame(struct ieee80211_sub_if_data *sdata, |
| 799 | struct sk_buff *skb) |
Luis Carlos Cobo | eb2b931 | 2008-02-23 15:17:14 +0100 | [diff] [blame] | 800 | { |
Luis Carlos Cobo | eb2b931 | 2008-02-23 15:17:14 +0100 | [diff] [blame] | 801 | kfree_skb(skb); |
Johannes Berg | 472dbc4 | 2008-09-11 00:01:49 +0200 | [diff] [blame] | 802 | sdata->u.mesh.mshstats.dropped_frames_no_route++; |
Luis Carlos Cobo | eb2b931 | 2008-02-23 15:17:14 +0100 | [diff] [blame] | 803 | } |
| 804 | |
| 805 | /** |
| 806 | * mesh_path_flush_pending - free the pending queue of a mesh path |
| 807 | * |
| 808 | * @mpath: mesh path whose queue has to be freed |
| 809 | * |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 810 | * 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] | 811 | */ |
| 812 | void mesh_path_flush_pending(struct mesh_path *mpath) |
| 813 | { |
Luis Carlos Cobo | eb2b931 | 2008-02-23 15:17:14 +0100 | [diff] [blame] | 814 | struct sk_buff *skb; |
| 815 | |
Javier Cardona | 00e3f25 | 2011-08-09 16:45:07 -0700 | [diff] [blame] | 816 | while ((skb = skb_dequeue(&mpath->frame_queue)) != NULL) |
Johannes Berg | bf7cd94 | 2013-02-15 14:40:31 +0100 | [diff] [blame] | 817 | mesh_path_discard_frame(mpath->sdata, skb); |
Luis Carlos Cobo | eb2b931 | 2008-02-23 15:17:14 +0100 | [diff] [blame] | 818 | } |
| 819 | |
| 820 | /** |
| 821 | * mesh_path_fix_nexthop - force a specific next hop for a mesh path |
| 822 | * |
| 823 | * @mpath: the mesh path to modify |
| 824 | * @next_hop: the next hop to force |
| 825 | * |
| 826 | * Locking: this function must be called holding mpath->state_lock |
| 827 | */ |
| 828 | void mesh_path_fix_nexthop(struct mesh_path *mpath, struct sta_info *next_hop) |
| 829 | { |
| 830 | spin_lock_bh(&mpath->state_lock); |
| 831 | mesh_path_assign_nexthop(mpath, next_hop); |
Rui Paulo | d19b3bf | 2009-11-09 23:46:55 +0000 | [diff] [blame] | 832 | mpath->sn = 0xffff; |
Luis Carlos Cobo | eb2b931 | 2008-02-23 15:17:14 +0100 | [diff] [blame] | 833 | mpath->metric = 0; |
| 834 | mpath->hop_count = 0; |
| 835 | mpath->exp_time = 0; |
| 836 | mpath->flags |= MESH_PATH_FIXED; |
| 837 | mesh_path_activate(mpath); |
| 838 | spin_unlock_bh(&mpath->state_lock); |
| 839 | mesh_path_tx_pending(mpath); |
| 840 | } |
| 841 | |
Bob Copeland | 2bdaf38 | 2016-02-28 20:03:56 -0500 | [diff] [blame] | 842 | int mesh_pathtbl_init(struct ieee80211_sub_if_data *sdata) |
Luis Carlos Cobo | eb2b931 | 2008-02-23 15:17:14 +0100 | [diff] [blame] | 843 | { |
Johannes Berg | 349eb8c | 2011-05-14 11:56:16 +0200 | [diff] [blame] | 844 | struct mesh_table *tbl_path, *tbl_mpp; |
Dan Carpenter | 4c5ade4 | 2011-08-30 22:16:15 +0300 | [diff] [blame] | 845 | int ret; |
YanBo | 79617de | 2008-09-22 13:30:32 +0800 | [diff] [blame] | 846 | |
Bob Copeland | 60854fd | 2016-03-02 10:09:20 -0500 | [diff] [blame] | 847 | tbl_path = mesh_table_alloc(); |
Johannes Berg | 349eb8c | 2011-05-14 11:56:16 +0200 | [diff] [blame] | 848 | if (!tbl_path) |
| 849 | return -ENOMEM; |
Javier Cardona | 5ee68e5 | 2011-08-09 16:45:08 -0700 | [diff] [blame] | 850 | |
Bob Copeland | 60854fd | 2016-03-02 10:09:20 -0500 | [diff] [blame] | 851 | tbl_mpp = mesh_table_alloc(); |
Johannes Berg | 349eb8c | 2011-05-14 11:56:16 +0200 | [diff] [blame] | 852 | if (!tbl_mpp) { |
Dan Carpenter | 4c5ade4 | 2011-08-30 22:16:15 +0300 | [diff] [blame] | 853 | ret = -ENOMEM; |
| 854 | goto free_path; |
YanBo | 79617de | 2008-09-22 13:30:32 +0800 | [diff] [blame] | 855 | } |
Johannes Berg | 349eb8c | 2011-05-14 11:56:16 +0200 | [diff] [blame] | 856 | |
Bob Copeland | 60854fd | 2016-03-02 10:09:20 -0500 | [diff] [blame] | 857 | rhashtable_init(&tbl_path->rhead, &mesh_rht_params); |
| 858 | rhashtable_init(&tbl_mpp->rhead, &mesh_rht_params); |
Bob Copeland | 2bdaf38 | 2016-02-28 20:03:56 -0500 | [diff] [blame] | 859 | |
Bob Copeland | 60854fd | 2016-03-02 10:09:20 -0500 | [diff] [blame] | 860 | sdata->u.mesh.mesh_paths = tbl_path; |
| 861 | sdata->u.mesh.mpp_paths = tbl_mpp; |
YanBo | 79617de | 2008-09-22 13:30:32 +0800 | [diff] [blame] | 862 | |
Luis Carlos Cobo | eb2b931 | 2008-02-23 15:17:14 +0100 | [diff] [blame] | 863 | return 0; |
Dan Carpenter | 4c5ade4 | 2011-08-30 22:16:15 +0300 | [diff] [blame] | 864 | |
Dan Carpenter | 4c5ade4 | 2011-08-30 22:16:15 +0300 | [diff] [blame] | 865 | free_path: |
Bob Copeland | 60854fd | 2016-03-02 10:09:20 -0500 | [diff] [blame] | 866 | mesh_table_free(tbl_path); |
Dan Carpenter | 4c5ade4 | 2011-08-30 22:16:15 +0300 | [diff] [blame] | 867 | return ret; |
Luis Carlos Cobo | eb2b931 | 2008-02-23 15:17:14 +0100 | [diff] [blame] | 868 | } |
| 869 | |
Bob Copeland | 60854fd | 2016-03-02 10:09:20 -0500 | [diff] [blame] | 870 | static |
| 871 | void mesh_path_tbl_expire(struct ieee80211_sub_if_data *sdata, |
| 872 | struct mesh_table *tbl) |
| 873 | { |
| 874 | struct mesh_path *mpath; |
| 875 | struct rhashtable_iter iter; |
| 876 | int ret; |
| 877 | |
| 878 | ret = rhashtable_walk_init(&tbl->rhead, &iter, GFP_KERNEL); |
| 879 | if (ret) |
| 880 | return; |
| 881 | |
| 882 | ret = rhashtable_walk_start(&iter); |
| 883 | if (ret && ret != -EAGAIN) |
| 884 | goto out; |
| 885 | |
| 886 | while ((mpath = rhashtable_walk_next(&iter))) { |
| 887 | if (IS_ERR(mpath) && PTR_ERR(mpath) == -EAGAIN) |
| 888 | continue; |
| 889 | if (IS_ERR(mpath)) |
| 890 | break; |
| 891 | if ((!(mpath->flags & MESH_PATH_RESOLVING)) && |
| 892 | (!(mpath->flags & MESH_PATH_FIXED)) && |
| 893 | time_after(jiffies, mpath->exp_time + MESH_PATH_EXPIRE)) |
| 894 | __mesh_path_del(tbl, mpath); |
| 895 | } |
| 896 | out: |
| 897 | rhashtable_walk_stop(&iter); |
| 898 | rhashtable_walk_exit(&iter); |
| 899 | } |
| 900 | |
Jasper Bryant-Greene | f698d85 | 2008-08-03 12:04:37 +1200 | [diff] [blame] | 901 | void mesh_path_expire(struct ieee80211_sub_if_data *sdata) |
Luis Carlos Cobo | eb2b931 | 2008-02-23 15:17:14 +0100 | [diff] [blame] | 902 | { |
Bob Copeland | 60854fd | 2016-03-02 10:09:20 -0500 | [diff] [blame] | 903 | mesh_path_tbl_expire(sdata, sdata->u.mesh.mesh_paths); |
| 904 | mesh_path_tbl_expire(sdata, sdata->u.mesh.mpp_paths); |
Luis Carlos Cobo | eb2b931 | 2008-02-23 15:17:14 +0100 | [diff] [blame] | 905 | } |
| 906 | |
Bob Copeland | 2bdaf38 | 2016-02-28 20:03:56 -0500 | [diff] [blame] | 907 | void mesh_pathtbl_unregister(struct ieee80211_sub_if_data *sdata) |
Luis Carlos Cobo | eb2b931 | 2008-02-23 15:17:14 +0100 | [diff] [blame] | 908 | { |
Bob Copeland | 60854fd | 2016-03-02 10:09:20 -0500 | [diff] [blame] | 909 | mesh_table_free(sdata->u.mesh.mesh_paths); |
| 910 | mesh_table_free(sdata->u.mesh.mpp_paths); |
Luis Carlos Cobo | eb2b931 | 2008-02-23 15:17:14 +0100 | [diff] [blame] | 911 | } |