mesh_pathtbl.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662
  1. /*
  2. * Copyright (c) 2008 open80211s Ltd.
  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. #include <linux/etherdevice.h>
  10. #include <linux/list.h>
  11. #include <linux/random.h>
  12. #include <linux/spinlock.h>
  13. #include <linux/string.h>
  14. #include <net/mac80211.h>
  15. #include "ieee80211_i.h"
  16. #include "mesh.h"
  17. /* There will be initially 2^INIT_PATHS_SIZE_ORDER buckets */
  18. #define INIT_PATHS_SIZE_ORDER 2
  19. /* Keep the mean chain length below this constant */
  20. #define MEAN_CHAIN_LEN 2
  21. #define MPATH_EXPIRED(mpath) ((mpath->flags & MESH_PATH_ACTIVE) && \
  22. time_after(jiffies, mpath->exp_time) && \
  23. !(mpath->flags & MESH_PATH_FIXED))
  24. struct mpath_node {
  25. struct hlist_node list;
  26. struct rcu_head rcu;
  27. /* This indirection allows two different tables to point to the same
  28. * mesh_path structure, useful when resizing
  29. */
  30. struct mesh_path *mpath;
  31. };
  32. static struct mesh_table *mesh_paths;
  33. static struct mesh_table *mpp_paths; /* Store paths for MPP&MAP */
  34. /* This lock will have the grow table function as writer and add / delete nodes
  35. * as readers. When reading the table (i.e. doing lookups) we are well protected
  36. * by RCU
  37. */
  38. static DEFINE_RWLOCK(pathtbl_resize_lock);
  39. /**
  40. *
  41. * mesh_path_assign_nexthop - update mesh path next hop
  42. *
  43. * @mpath: mesh path to update
  44. * @sta: next hop to assign
  45. *
  46. * Locking: mpath->state_lock must be held when calling this function
  47. */
  48. void mesh_path_assign_nexthop(struct mesh_path *mpath, struct sta_info *sta)
  49. {
  50. struct sk_buff *skb;
  51. struct ieee80211_hdr *hdr;
  52. struct sk_buff_head tmpq;
  53. unsigned long flags;
  54. rcu_assign_pointer(mpath->next_hop, sta);
  55. __skb_queue_head_init(&tmpq);
  56. spin_lock_irqsave(&mpath->frame_queue.lock, flags);
  57. while ((skb = __skb_dequeue(&mpath->frame_queue)) != NULL) {
  58. hdr = (struct ieee80211_hdr *) skb->data;
  59. memcpy(hdr->addr1, sta->sta.addr, ETH_ALEN);
  60. __skb_queue_tail(&tmpq, skb);
  61. }
  62. skb_queue_splice(&tmpq, &mpath->frame_queue);
  63. spin_unlock_irqrestore(&mpath->frame_queue.lock, flags);
  64. }
  65. /**
  66. * mesh_path_lookup - look up a path in the mesh path table
  67. * @dst: hardware address (ETH_ALEN length) of destination
  68. * @sdata: local subif
  69. *
  70. * Returns: pointer to the mesh path structure, or NULL if not found
  71. *
  72. * Locking: must be called within a read rcu section.
  73. */
  74. struct mesh_path *mesh_path_lookup(u8 *dst, struct ieee80211_sub_if_data *sdata)
  75. {
  76. struct mesh_path *mpath;
  77. struct hlist_node *n;
  78. struct hlist_head *bucket;
  79. struct mesh_table *tbl;
  80. struct mpath_node *node;
  81. tbl = rcu_dereference(mesh_paths);
  82. bucket = &tbl->hash_buckets[mesh_table_hash(dst, sdata, tbl)];
  83. hlist_for_each_entry_rcu(node, n, bucket, list) {
  84. mpath = node->mpath;
  85. if (mpath->sdata == sdata &&
  86. memcmp(dst, mpath->dst, ETH_ALEN) == 0) {
  87. if (MPATH_EXPIRED(mpath)) {
  88. spin_lock_bh(&mpath->state_lock);
  89. if (MPATH_EXPIRED(mpath))
  90. mpath->flags &= ~MESH_PATH_ACTIVE;
  91. spin_unlock_bh(&mpath->state_lock);
  92. }
  93. return mpath;
  94. }
  95. }
  96. return NULL;
  97. }
  98. struct mesh_path *mpp_path_lookup(u8 *dst, struct ieee80211_sub_if_data *sdata)
  99. {
  100. struct mesh_path *mpath;
  101. struct hlist_node *n;
  102. struct hlist_head *bucket;
  103. struct mesh_table *tbl;
  104. struct mpath_node *node;
  105. tbl = rcu_dereference(mpp_paths);
  106. bucket = &tbl->hash_buckets[mesh_table_hash(dst, sdata, tbl)];
  107. hlist_for_each_entry_rcu(node, n, bucket, list) {
  108. mpath = node->mpath;
  109. if (mpath->sdata == sdata &&
  110. memcmp(dst, mpath->dst, ETH_ALEN) == 0) {
  111. if (MPATH_EXPIRED(mpath)) {
  112. spin_lock_bh(&mpath->state_lock);
  113. if (MPATH_EXPIRED(mpath))
  114. mpath->flags &= ~MESH_PATH_ACTIVE;
  115. spin_unlock_bh(&mpath->state_lock);
  116. }
  117. return mpath;
  118. }
  119. }
  120. return NULL;
  121. }
  122. /**
  123. * mesh_path_lookup_by_idx - look up a path in the mesh path table by its index
  124. * @idx: index
  125. * @sdata: local subif, or NULL for all entries
  126. *
  127. * Returns: pointer to the mesh path structure, or NULL if not found.
  128. *
  129. * Locking: must be called within a read rcu section.
  130. */
  131. struct mesh_path *mesh_path_lookup_by_idx(int idx, struct ieee80211_sub_if_data *sdata)
  132. {
  133. struct mpath_node *node;
  134. struct hlist_node *p;
  135. int i;
  136. int j = 0;
  137. for_each_mesh_entry(mesh_paths, p, node, i) {
  138. if (sdata && node->mpath->sdata != sdata)
  139. continue;
  140. if (j++ == idx) {
  141. if (MPATH_EXPIRED(node->mpath)) {
  142. spin_lock_bh(&node->mpath->state_lock);
  143. if (MPATH_EXPIRED(node->mpath))
  144. node->mpath->flags &= ~MESH_PATH_ACTIVE;
  145. spin_unlock_bh(&node->mpath->state_lock);
  146. }
  147. return node->mpath;
  148. }
  149. }
  150. return NULL;
  151. }
  152. /**
  153. * mesh_path_add - allocate and add a new path to the mesh path table
  154. * @addr: destination address of the path (ETH_ALEN length)
  155. * @sdata: local subif
  156. *
  157. * Returns: 0 on sucess
  158. *
  159. * State: the initial state of the new path is set to 0
  160. */
  161. int mesh_path_add(u8 *dst, struct ieee80211_sub_if_data *sdata)
  162. {
  163. struct mesh_path *mpath, *new_mpath;
  164. struct mpath_node *node, *new_node;
  165. struct hlist_head *bucket;
  166. struct hlist_node *n;
  167. int grow = 0;
  168. int err = 0;
  169. u32 hash_idx;
  170. might_sleep();
  171. if (memcmp(dst, sdata->dev->dev_addr, ETH_ALEN) == 0)
  172. /* never add ourselves as neighbours */
  173. return -ENOTSUPP;
  174. if (is_multicast_ether_addr(dst))
  175. return -ENOTSUPP;
  176. if (atomic_add_unless(&sdata->u.mesh.mpaths, 1, MESH_MAX_MPATHS) == 0)
  177. return -ENOSPC;
  178. err = -ENOMEM;
  179. new_mpath = kzalloc(sizeof(struct mesh_path), GFP_KERNEL);
  180. if (!new_mpath)
  181. goto err_path_alloc;
  182. new_node = kmalloc(sizeof(struct mpath_node), GFP_KERNEL);
  183. if (!new_node)
  184. goto err_node_alloc;
  185. read_lock(&pathtbl_resize_lock);
  186. memcpy(new_mpath->dst, dst, ETH_ALEN);
  187. new_mpath->sdata = sdata;
  188. new_mpath->flags = 0;
  189. skb_queue_head_init(&new_mpath->frame_queue);
  190. new_node->mpath = new_mpath;
  191. new_mpath->timer.data = (unsigned long) new_mpath;
  192. new_mpath->timer.function = mesh_path_timer;
  193. new_mpath->exp_time = jiffies;
  194. spin_lock_init(&new_mpath->state_lock);
  195. init_timer(&new_mpath->timer);
  196. hash_idx = mesh_table_hash(dst, sdata, mesh_paths);
  197. bucket = &mesh_paths->hash_buckets[hash_idx];
  198. spin_lock(&mesh_paths->hashwlock[hash_idx]);
  199. err = -EEXIST;
  200. hlist_for_each_entry(node, n, bucket, list) {
  201. mpath = node->mpath;
  202. if (mpath->sdata == sdata && memcmp(dst, mpath->dst, ETH_ALEN) == 0)
  203. goto err_exists;
  204. }
  205. hlist_add_head_rcu(&new_node->list, bucket);
  206. if (atomic_inc_return(&mesh_paths->entries) >=
  207. mesh_paths->mean_chain_len * (mesh_paths->hash_mask + 1))
  208. grow = 1;
  209. spin_unlock(&mesh_paths->hashwlock[hash_idx]);
  210. read_unlock(&pathtbl_resize_lock);
  211. if (grow) {
  212. struct mesh_table *oldtbl, *newtbl;
  213. write_lock(&pathtbl_resize_lock);
  214. oldtbl = mesh_paths;
  215. newtbl = mesh_table_grow(mesh_paths);
  216. if (!newtbl) {
  217. write_unlock(&pathtbl_resize_lock);
  218. return 0;
  219. }
  220. rcu_assign_pointer(mesh_paths, newtbl);
  221. write_unlock(&pathtbl_resize_lock);
  222. synchronize_rcu();
  223. mesh_table_free(oldtbl, false);
  224. }
  225. return 0;
  226. err_exists:
  227. spin_unlock(&mesh_paths->hashwlock[hash_idx]);
  228. read_unlock(&pathtbl_resize_lock);
  229. kfree(new_node);
  230. err_node_alloc:
  231. kfree(new_mpath);
  232. err_path_alloc:
  233. atomic_dec(&sdata->u.mesh.mpaths);
  234. return err;
  235. }
  236. int mpp_path_add(u8 *dst, u8 *mpp, struct ieee80211_sub_if_data *sdata)
  237. {
  238. struct mesh_path *mpath, *new_mpath;
  239. struct mpath_node *node, *new_node;
  240. struct hlist_head *bucket;
  241. struct hlist_node *n;
  242. int grow = 0;
  243. int err = 0;
  244. u32 hash_idx;
  245. might_sleep();
  246. if (memcmp(dst, sdata->dev->dev_addr, ETH_ALEN) == 0)
  247. /* never add ourselves as neighbours */
  248. return -ENOTSUPP;
  249. if (is_multicast_ether_addr(dst))
  250. return -ENOTSUPP;
  251. err = -ENOMEM;
  252. new_mpath = kzalloc(sizeof(struct mesh_path), GFP_KERNEL);
  253. if (!new_mpath)
  254. goto err_path_alloc;
  255. new_node = kmalloc(sizeof(struct mpath_node), GFP_KERNEL);
  256. if (!new_node)
  257. goto err_node_alloc;
  258. read_lock(&pathtbl_resize_lock);
  259. memcpy(new_mpath->dst, dst, ETH_ALEN);
  260. memcpy(new_mpath->mpp, mpp, ETH_ALEN);
  261. new_mpath->sdata = sdata;
  262. new_mpath->flags = 0;
  263. skb_queue_head_init(&new_mpath->frame_queue);
  264. new_node->mpath = new_mpath;
  265. new_mpath->exp_time = jiffies;
  266. spin_lock_init(&new_mpath->state_lock);
  267. hash_idx = mesh_table_hash(dst, sdata, mpp_paths);
  268. bucket = &mpp_paths->hash_buckets[hash_idx];
  269. spin_lock(&mpp_paths->hashwlock[hash_idx]);
  270. err = -EEXIST;
  271. hlist_for_each_entry(node, n, bucket, list) {
  272. mpath = node->mpath;
  273. if (mpath->sdata == sdata && memcmp(dst, mpath->dst, ETH_ALEN) == 0)
  274. goto err_exists;
  275. }
  276. hlist_add_head_rcu(&new_node->list, bucket);
  277. if (atomic_inc_return(&mpp_paths->entries) >=
  278. mpp_paths->mean_chain_len * (mpp_paths->hash_mask + 1))
  279. grow = 1;
  280. spin_unlock(&mpp_paths->hashwlock[hash_idx]);
  281. read_unlock(&pathtbl_resize_lock);
  282. if (grow) {
  283. struct mesh_table *oldtbl, *newtbl;
  284. write_lock(&pathtbl_resize_lock);
  285. oldtbl = mpp_paths;
  286. newtbl = mesh_table_grow(mpp_paths);
  287. if (!newtbl) {
  288. write_unlock(&pathtbl_resize_lock);
  289. return 0;
  290. }
  291. rcu_assign_pointer(mpp_paths, newtbl);
  292. write_unlock(&pathtbl_resize_lock);
  293. synchronize_rcu();
  294. mesh_table_free(oldtbl, false);
  295. }
  296. return 0;
  297. err_exists:
  298. spin_unlock(&mpp_paths->hashwlock[hash_idx]);
  299. read_unlock(&pathtbl_resize_lock);
  300. kfree(new_node);
  301. err_node_alloc:
  302. kfree(new_mpath);
  303. err_path_alloc:
  304. return err;
  305. }
  306. /**
  307. * mesh_plink_broken - deactivates paths and sends perr when a link breaks
  308. *
  309. * @sta: broken peer link
  310. *
  311. * This function must be called from the rate control algorithm if enough
  312. * delivery errors suggest that a peer link is no longer usable.
  313. */
  314. void mesh_plink_broken(struct sta_info *sta)
  315. {
  316. struct mesh_path *mpath;
  317. struct mpath_node *node;
  318. struct hlist_node *p;
  319. struct ieee80211_sub_if_data *sdata = sta->sdata;
  320. int i;
  321. rcu_read_lock();
  322. for_each_mesh_entry(mesh_paths, p, node, i) {
  323. mpath = node->mpath;
  324. spin_lock_bh(&mpath->state_lock);
  325. if (mpath->next_hop == sta &&
  326. mpath->flags & MESH_PATH_ACTIVE &&
  327. !(mpath->flags & MESH_PATH_FIXED)) {
  328. mpath->flags &= ~MESH_PATH_ACTIVE;
  329. ++mpath->dsn;
  330. spin_unlock_bh(&mpath->state_lock);
  331. mesh_path_error_tx(mpath->dst,
  332. cpu_to_le32(mpath->dsn),
  333. sdata->dev->broadcast, sdata);
  334. } else
  335. spin_unlock_bh(&mpath->state_lock);
  336. }
  337. rcu_read_unlock();
  338. }
  339. /**
  340. * mesh_path_flush_by_nexthop - Deletes mesh paths if their next hop matches
  341. *
  342. * @sta - mesh peer to match
  343. *
  344. * RCU notes: this function is called when a mesh plink transitions from
  345. * PLINK_ESTAB to any other state, since PLINK_ESTAB state is the only one that
  346. * allows path creation. This will happen before the sta can be freed (because
  347. * sta_info_destroy() calls this) so any reader in a rcu read block will be
  348. * protected against the plink disappearing.
  349. */
  350. void mesh_path_flush_by_nexthop(struct sta_info *sta)
  351. {
  352. struct mesh_path *mpath;
  353. struct mpath_node *node;
  354. struct hlist_node *p;
  355. int i;
  356. for_each_mesh_entry(mesh_paths, p, node, i) {
  357. mpath = node->mpath;
  358. if (mpath->next_hop == sta)
  359. mesh_path_del(mpath->dst, mpath->sdata);
  360. }
  361. }
  362. void mesh_path_flush(struct ieee80211_sub_if_data *sdata)
  363. {
  364. struct mesh_path *mpath;
  365. struct mpath_node *node;
  366. struct hlist_node *p;
  367. int i;
  368. for_each_mesh_entry(mesh_paths, p, node, i) {
  369. mpath = node->mpath;
  370. if (mpath->sdata == sdata)
  371. mesh_path_del(mpath->dst, mpath->sdata);
  372. }
  373. }
  374. static void mesh_path_node_reclaim(struct rcu_head *rp)
  375. {
  376. struct mpath_node *node = container_of(rp, struct mpath_node, rcu);
  377. struct ieee80211_sub_if_data *sdata = node->mpath->sdata;
  378. del_timer_sync(&node->mpath->timer);
  379. atomic_dec(&sdata->u.mesh.mpaths);
  380. kfree(node->mpath);
  381. kfree(node);
  382. }
  383. /**
  384. * mesh_path_del - delete a mesh path from the table
  385. *
  386. * @addr: dst address (ETH_ALEN length)
  387. * @sdata: local subif
  388. *
  389. * Returns: 0 if succesful
  390. */
  391. int mesh_path_del(u8 *addr, struct ieee80211_sub_if_data *sdata)
  392. {
  393. struct mesh_path *mpath;
  394. struct mpath_node *node;
  395. struct hlist_head *bucket;
  396. struct hlist_node *n;
  397. int hash_idx;
  398. int err = 0;
  399. read_lock(&pathtbl_resize_lock);
  400. hash_idx = mesh_table_hash(addr, sdata, mesh_paths);
  401. bucket = &mesh_paths->hash_buckets[hash_idx];
  402. spin_lock(&mesh_paths->hashwlock[hash_idx]);
  403. hlist_for_each_entry(node, n, bucket, list) {
  404. mpath = node->mpath;
  405. if (mpath->sdata == sdata &&
  406. memcmp(addr, mpath->dst, ETH_ALEN) == 0) {
  407. spin_lock_bh(&mpath->state_lock);
  408. mpath->flags |= MESH_PATH_RESOLVING;
  409. hlist_del_rcu(&node->list);
  410. call_rcu(&node->rcu, mesh_path_node_reclaim);
  411. atomic_dec(&mesh_paths->entries);
  412. spin_unlock_bh(&mpath->state_lock);
  413. goto enddel;
  414. }
  415. }
  416. err = -ENXIO;
  417. enddel:
  418. spin_unlock(&mesh_paths->hashwlock[hash_idx]);
  419. read_unlock(&pathtbl_resize_lock);
  420. return err;
  421. }
  422. /**
  423. * mesh_path_tx_pending - sends pending frames in a mesh path queue
  424. *
  425. * @mpath: mesh path to activate
  426. *
  427. * Locking: the state_lock of the mpath structure must NOT be held when calling
  428. * this function.
  429. */
  430. void mesh_path_tx_pending(struct mesh_path *mpath)
  431. {
  432. struct sk_buff *skb;
  433. while ((skb = skb_dequeue(&mpath->frame_queue)) &&
  434. (mpath->flags & MESH_PATH_ACTIVE))
  435. dev_queue_xmit(skb);
  436. }
  437. /**
  438. * mesh_path_discard_frame - discard a frame whose path could not be resolved
  439. *
  440. * @skb: frame to discard
  441. * @sdata: network subif the frame was to be sent through
  442. *
  443. * If the frame was being forwarded from another MP, a PERR frame will be sent
  444. * to the precursor. The precursor's address (i.e. the previous hop) was saved
  445. * in addr1 of the frame-to-be-forwarded, and would only be overwritten once
  446. * the destination is successfully resolved.
  447. *
  448. * Locking: the function must me called within a rcu_read_lock region
  449. */
  450. void mesh_path_discard_frame(struct sk_buff *skb,
  451. struct ieee80211_sub_if_data *sdata)
  452. {
  453. struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) skb->data;
  454. struct mesh_path *mpath;
  455. u32 dsn = 0;
  456. if (memcmp(hdr->addr4, sdata->dev->dev_addr, ETH_ALEN) != 0) {
  457. u8 *ra, *da;
  458. da = hdr->addr3;
  459. ra = hdr->addr1;
  460. mpath = mesh_path_lookup(da, sdata);
  461. if (mpath)
  462. dsn = ++mpath->dsn;
  463. mesh_path_error_tx(skb->data, cpu_to_le32(dsn), ra, sdata);
  464. }
  465. kfree_skb(skb);
  466. sdata->u.mesh.mshstats.dropped_frames_no_route++;
  467. }
  468. /**
  469. * mesh_path_flush_pending - free the pending queue of a mesh path
  470. *
  471. * @mpath: mesh path whose queue has to be freed
  472. *
  473. * Locking: the function must me called withing a rcu_read_lock region
  474. */
  475. void mesh_path_flush_pending(struct mesh_path *mpath)
  476. {
  477. struct sk_buff *skb;
  478. while ((skb = skb_dequeue(&mpath->frame_queue)) &&
  479. (mpath->flags & MESH_PATH_ACTIVE))
  480. mesh_path_discard_frame(skb, mpath->sdata);
  481. }
  482. /**
  483. * mesh_path_fix_nexthop - force a specific next hop for a mesh path
  484. *
  485. * @mpath: the mesh path to modify
  486. * @next_hop: the next hop to force
  487. *
  488. * Locking: this function must be called holding mpath->state_lock
  489. */
  490. void mesh_path_fix_nexthop(struct mesh_path *mpath, struct sta_info *next_hop)
  491. {
  492. spin_lock_bh(&mpath->state_lock);
  493. mesh_path_assign_nexthop(mpath, next_hop);
  494. mpath->dsn = 0xffff;
  495. mpath->metric = 0;
  496. mpath->hop_count = 0;
  497. mpath->exp_time = 0;
  498. mpath->flags |= MESH_PATH_FIXED;
  499. mesh_path_activate(mpath);
  500. spin_unlock_bh(&mpath->state_lock);
  501. mesh_path_tx_pending(mpath);
  502. }
  503. static void mesh_path_node_free(struct hlist_node *p, bool free_leafs)
  504. {
  505. struct mesh_path *mpath;
  506. struct mpath_node *node = hlist_entry(p, struct mpath_node, list);
  507. mpath = node->mpath;
  508. hlist_del_rcu(p);
  509. if (free_leafs)
  510. kfree(mpath);
  511. kfree(node);
  512. }
  513. static int mesh_path_node_copy(struct hlist_node *p, struct mesh_table *newtbl)
  514. {
  515. struct mesh_path *mpath;
  516. struct mpath_node *node, *new_node;
  517. u32 hash_idx;
  518. new_node = kmalloc(sizeof(struct mpath_node), GFP_ATOMIC);
  519. if (new_node == NULL)
  520. return -ENOMEM;
  521. node = hlist_entry(p, struct mpath_node, list);
  522. mpath = node->mpath;
  523. new_node->mpath = mpath;
  524. hash_idx = mesh_table_hash(mpath->dst, mpath->sdata, newtbl);
  525. hlist_add_head(&new_node->list,
  526. &newtbl->hash_buckets[hash_idx]);
  527. return 0;
  528. }
  529. int mesh_pathtbl_init(void)
  530. {
  531. mesh_paths = mesh_table_alloc(INIT_PATHS_SIZE_ORDER);
  532. if (!mesh_paths)
  533. return -ENOMEM;
  534. mesh_paths->free_node = &mesh_path_node_free;
  535. mesh_paths->copy_node = &mesh_path_node_copy;
  536. mesh_paths->mean_chain_len = MEAN_CHAIN_LEN;
  537. mpp_paths = mesh_table_alloc(INIT_PATHS_SIZE_ORDER);
  538. if (!mpp_paths) {
  539. mesh_table_free(mesh_paths, true);
  540. return -ENOMEM;
  541. }
  542. mpp_paths->free_node = &mesh_path_node_free;
  543. mpp_paths->copy_node = &mesh_path_node_copy;
  544. mpp_paths->mean_chain_len = MEAN_CHAIN_LEN;
  545. return 0;
  546. }
  547. void mesh_path_expire(struct ieee80211_sub_if_data *sdata)
  548. {
  549. struct mesh_path *mpath;
  550. struct mpath_node *node;
  551. struct hlist_node *p;
  552. int i;
  553. read_lock(&pathtbl_resize_lock);
  554. for_each_mesh_entry(mesh_paths, p, node, i) {
  555. if (node->mpath->sdata != sdata)
  556. continue;
  557. mpath = node->mpath;
  558. spin_lock_bh(&mpath->state_lock);
  559. if ((!(mpath->flags & MESH_PATH_RESOLVING)) &&
  560. (!(mpath->flags & MESH_PATH_FIXED)) &&
  561. time_after(jiffies,
  562. mpath->exp_time + MESH_PATH_EXPIRE)) {
  563. spin_unlock_bh(&mpath->state_lock);
  564. mesh_path_del(mpath->dst, mpath->sdata);
  565. } else
  566. spin_unlock_bh(&mpath->state_lock);
  567. }
  568. read_unlock(&pathtbl_resize_lock);
  569. }
  570. void mesh_pathtbl_unregister(void)
  571. {
  572. mesh_table_free(mesh_paths, true);
  573. mesh_table_free(mpp_paths, true);
  574. }