mesh_pathtbl.c 16 KB

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