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