hc
2024-10-22 8ac6c7a54ed1b98d142dce24b11c6de6a1e239a5
kernel/net/mac80211/mesh_pathtbl.c
....@@ -1,10 +1,7 @@
1
+// SPDX-License-Identifier: GPL-2.0-only
12 /*
23 * Copyright (c) 2008, 2009 open80211s Ltd.
34 * 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.
85 */
96
107 #include <linux/etherdevice.h>
....@@ -50,36 +47,27 @@
5047 mesh_path_free_rcu(tbl, mpath);
5148 }
5249
53
-static struct mesh_table *mesh_table_alloc(void)
50
+static void mesh_table_init(struct mesh_table *tbl)
5451 {
55
- struct mesh_table *newtbl;
52
+ INIT_HLIST_HEAD(&tbl->known_gates);
53
+ INIT_HLIST_HEAD(&tbl->walk_head);
54
+ atomic_set(&tbl->entries, 0);
55
+ spin_lock_init(&tbl->gates_lock);
56
+ spin_lock_init(&tbl->walk_lock);
5657
57
- newtbl = kmalloc(sizeof(struct mesh_table), GFP_ATOMIC);
58
- if (!newtbl)
59
- return NULL;
60
-
61
- INIT_HLIST_HEAD(&newtbl->known_gates);
62
- INIT_HLIST_HEAD(&newtbl->walk_head);
63
- atomic_set(&newtbl->entries, 0);
64
- spin_lock_init(&newtbl->gates_lock);
65
- spin_lock_init(&newtbl->walk_lock);
66
- if (rhashtable_init(&newtbl->rhead, &mesh_rht_params)) {
67
- kfree(newtbl);
68
- return NULL;
69
- }
70
-
71
- return newtbl;
58
+ /* rhashtable_init() may fail only in case of wrong
59
+ * mesh_rht_params
60
+ */
61
+ WARN_ON(rhashtable_init(&tbl->rhead, &mesh_rht_params));
7262 }
7363
7464 static void mesh_table_free(struct mesh_table *tbl)
7565 {
7666 rhashtable_free_and_destroy(&tbl->rhead,
7767 mesh_path_rht_free, tbl);
78
- kfree(tbl);
7968 }
8069
8170 /**
82
- *
8371 * mesh_path_assign_nexthop - update mesh path next hop
8472 *
8573 * @mpath: mesh path to update
....@@ -147,7 +135,6 @@
147135 }
148136
149137 /**
150
- *
151138 * mesh_path_move_to_queue - Move or copy frames from one mpath queue to another
152139 *
153140 * This function is used to transfer or copy frames from an unresolved mpath to
....@@ -159,7 +146,7 @@
159146 *
160147 * The gate mpath must be an active mpath with a valid mpath->next_hop.
161148 *
162
- * @mpath: An active mpath the frames will be sent to (i.e. the gate)
149
+ * @gate_mpath: An active mpath the frames will be sent to (i.e. the gate)
163150 * @from_mpath: The failed mpath
164151 * @copy: When true, copy all the frames to the new mpath queue. When false,
165152 * move them.
....@@ -221,7 +208,7 @@
221208 {
222209 struct mesh_path *mpath;
223210
224
- mpath = rhashtable_lookup_fast(&tbl->rhead, dst, mesh_rht_params);
211
+ mpath = rhashtable_lookup(&tbl->rhead, dst, mesh_rht_params);
225212
226213 if (mpath && mpath_expired(mpath)) {
227214 spin_lock_bh(&mpath->state_lock);
....@@ -243,13 +230,13 @@
243230 struct mesh_path *
244231 mesh_path_lookup(struct ieee80211_sub_if_data *sdata, const u8 *dst)
245232 {
246
- return mpath_lookup(sdata->u.mesh.mesh_paths, dst, sdata);
233
+ return mpath_lookup(&sdata->u.mesh.mesh_paths, dst, sdata);
247234 }
248235
249236 struct mesh_path *
250237 mpp_path_lookup(struct ieee80211_sub_if_data *sdata, const u8 *dst)
251238 {
252
- return mpath_lookup(sdata->u.mesh.mpp_paths, dst, sdata);
239
+ return mpath_lookup(&sdata->u.mesh.mpp_paths, dst, sdata);
253240 }
254241
255242 static struct mesh_path *
....@@ -286,7 +273,7 @@
286273 struct mesh_path *
287274 mesh_path_lookup_by_idx(struct ieee80211_sub_if_data *sdata, int idx)
288275 {
289
- return __mesh_path_lookup_by_idx(sdata->u.mesh.mesh_paths, idx);
276
+ return __mesh_path_lookup_by_idx(&sdata->u.mesh.mesh_paths, idx);
290277 }
291278
292279 /**
....@@ -301,7 +288,7 @@
301288 struct mesh_path *
302289 mpp_path_lookup_by_idx(struct ieee80211_sub_if_data *sdata, int idx)
303290 {
304
- return __mesh_path_lookup_by_idx(sdata->u.mesh.mpp_paths, idx);
291
+ return __mesh_path_lookup_by_idx(&sdata->u.mesh.mpp_paths, idx);
305292 }
306293
307294 /**
....@@ -314,7 +301,7 @@
314301 int err;
315302
316303 rcu_read_lock();
317
- tbl = mpath->sdata->u.mesh.mesh_paths;
304
+ tbl = &mpath->sdata->u.mesh.mesh_paths;
318305
319306 spin_lock_bh(&mpath->state_lock);
320307 if (mpath->is_gate) {
....@@ -408,7 +395,6 @@
408395 {
409396 struct mesh_table *tbl;
410397 struct mesh_path *mpath, *new_mpath;
411
- int ret;
412398
413399 if (ether_addr_equal(dst, sdata->vif.addr))
414400 /* never add ourselves as neighbours */
....@@ -424,27 +410,20 @@
424410 if (!new_mpath)
425411 return ERR_PTR(-ENOMEM);
426412
427
- tbl = sdata->u.mesh.mesh_paths;
413
+ tbl = &sdata->u.mesh.mesh_paths;
428414 spin_lock_bh(&tbl->walk_lock);
429
- do {
430
- ret = rhashtable_lookup_insert_fast(&tbl->rhead,
431
- &new_mpath->rhash,
432
- mesh_rht_params);
433
-
434
- if (ret == -EEXIST)
435
- mpath = rhashtable_lookup_fast(&tbl->rhead,
436
- dst,
437
- mesh_rht_params);
438
- else if (!ret)
439
- hlist_add_head(&new_mpath->walk_list, &tbl->walk_head);
440
- } while (unlikely(ret == -EEXIST && !mpath));
415
+ mpath = rhashtable_lookup_get_insert_fast(&tbl->rhead,
416
+ &new_mpath->rhash,
417
+ mesh_rht_params);
418
+ if (!mpath)
419
+ hlist_add_head(&new_mpath->walk_list, &tbl->walk_head);
441420 spin_unlock_bh(&tbl->walk_lock);
442421
443
- if (ret) {
422
+ if (mpath) {
444423 kfree(new_mpath);
445424
446
- if (ret != -EEXIST)
447
- return ERR_PTR(ret);
425
+ if (IS_ERR(mpath))
426
+ return mpath;
448427
449428 new_mpath = mpath;
450429 }
....@@ -473,7 +452,7 @@
473452 return -ENOMEM;
474453
475454 memcpy(new_mpath->mpp, mpp, ETH_ALEN);
476
- tbl = sdata->u.mesh.mpp_paths;
455
+ tbl = &sdata->u.mesh.mpp_paths;
477456
478457 spin_lock_bh(&tbl->walk_lock);
479458 ret = rhashtable_lookup_insert_fast(&tbl->rhead,
....@@ -502,7 +481,7 @@
502481 void mesh_plink_broken(struct sta_info *sta)
503482 {
504483 struct ieee80211_sub_if_data *sdata = sta->sdata;
505
- struct mesh_table *tbl = sdata->u.mesh.mesh_paths;
484
+ struct mesh_table *tbl = &sdata->u.mesh.mesh_paths;
506485 static const u8 bcast[ETH_ALEN] = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff};
507486 struct mesh_path *mpath;
508487
....@@ -561,7 +540,7 @@
561540 void mesh_path_flush_by_nexthop(struct sta_info *sta)
562541 {
563542 struct ieee80211_sub_if_data *sdata = sta->sdata;
564
- struct mesh_table *tbl = sdata->u.mesh.mesh_paths;
543
+ struct mesh_table *tbl = &sdata->u.mesh.mesh_paths;
565544 struct mesh_path *mpath;
566545 struct hlist_node *n;
567546
....@@ -576,7 +555,7 @@
576555 static void mpp_flush_by_proxy(struct ieee80211_sub_if_data *sdata,
577556 const u8 *proxy)
578557 {
579
- struct mesh_table *tbl = sdata->u.mesh.mpp_paths;
558
+ struct mesh_table *tbl = &sdata->u.mesh.mpp_paths;
580559 struct mesh_path *mpath;
581560 struct hlist_node *n;
582561
....@@ -610,8 +589,8 @@
610589 */
611590 void mesh_path_flush_by_iface(struct ieee80211_sub_if_data *sdata)
612591 {
613
- table_flush_by_iface(sdata->u.mesh.mesh_paths);
614
- table_flush_by_iface(sdata->u.mesh.mpp_paths);
592
+ table_flush_by_iface(&sdata->u.mesh.mesh_paths);
593
+ table_flush_by_iface(&sdata->u.mesh.mpp_paths);
615594 }
616595
617596 /**
....@@ -657,7 +636,7 @@
657636 /* flush relevant mpp entries first */
658637 mpp_flush_by_proxy(sdata, addr);
659638
660
- err = table_path_del(sdata->u.mesh.mesh_paths, sdata, addr);
639
+ err = table_path_del(&sdata->u.mesh.mesh_paths, sdata, addr);
661640 sdata->u.mesh.mesh_paths_generation++;
662641 return err;
663642 }
....@@ -695,7 +674,7 @@
695674 struct mesh_path *gate;
696675 bool copy = false;
697676
698
- tbl = sdata->u.mesh.mesh_paths;
677
+ tbl = &sdata->u.mesh.mesh_paths;
699678
700679 rcu_read_lock();
701680 hlist_for_each_entry_rcu(gate, &tbl->known_gates, gate_list) {
....@@ -731,7 +710,7 @@
731710 void mesh_path_discard_frame(struct ieee80211_sub_if_data *sdata,
732711 struct sk_buff *skb)
733712 {
734
- kfree_skb(skb);
713
+ ieee80211_free_txskb(&sdata->local->hw, skb);
735714 sdata->u.mesh.mshstats.dropped_frames_no_route++;
736715 }
737716
....@@ -775,29 +754,10 @@
775754 mesh_path_tx_pending(mpath);
776755 }
777756
778
-int mesh_pathtbl_init(struct ieee80211_sub_if_data *sdata)
757
+void mesh_pathtbl_init(struct ieee80211_sub_if_data *sdata)
779758 {
780
- struct mesh_table *tbl_path, *tbl_mpp;
781
- int ret;
782
-
783
- tbl_path = mesh_table_alloc();
784
- if (!tbl_path)
785
- return -ENOMEM;
786
-
787
- tbl_mpp = mesh_table_alloc();
788
- if (!tbl_mpp) {
789
- ret = -ENOMEM;
790
- goto free_path;
791
- }
792
-
793
- sdata->u.mesh.mesh_paths = tbl_path;
794
- sdata->u.mesh.mpp_paths = tbl_mpp;
795
-
796
- return 0;
797
-
798
-free_path:
799
- mesh_table_free(tbl_path);
800
- return ret;
759
+ mesh_table_init(&sdata->u.mesh.mesh_paths);
760
+ mesh_table_init(&sdata->u.mesh.mpp_paths);
801761 }
802762
803763 static
....@@ -819,12 +779,12 @@
819779
820780 void mesh_path_expire(struct ieee80211_sub_if_data *sdata)
821781 {
822
- mesh_path_tbl_expire(sdata, sdata->u.mesh.mesh_paths);
823
- mesh_path_tbl_expire(sdata, sdata->u.mesh.mpp_paths);
782
+ mesh_path_tbl_expire(sdata, &sdata->u.mesh.mesh_paths);
783
+ mesh_path_tbl_expire(sdata, &sdata->u.mesh.mpp_paths);
824784 }
825785
826786 void mesh_pathtbl_unregister(struct ieee80211_sub_if_data *sdata)
827787 {
828
- mesh_table_free(sdata->u.mesh.mesh_paths);
829
- mesh_table_free(sdata->u.mesh.mpp_paths);
788
+ mesh_table_free(&sdata->u.mesh.mesh_paths);
789
+ mesh_table_free(&sdata->u.mesh.mpp_paths);
830790 }