bearer.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678
  1. /*
  2. * net/tipc/bearer.c: TIPC bearer code
  3. *
  4. * Copyright (c) 1996-2006, Ericsson AB
  5. * Copyright (c) 2004-2006, 2010-2011, Wind River Systems
  6. * All rights reserved.
  7. *
  8. * Redistribution and use in source and binary forms, with or without
  9. * modification, are permitted provided that the following conditions are met:
  10. *
  11. * 1. Redistributions of source code must retain the above copyright
  12. * notice, this list of conditions and the following disclaimer.
  13. * 2. Redistributions in binary form must reproduce the above copyright
  14. * notice, this list of conditions and the following disclaimer in the
  15. * documentation and/or other materials provided with the distribution.
  16. * 3. Neither the names of the copyright holders nor the names of its
  17. * contributors may be used to endorse or promote products derived from
  18. * this software without specific prior written permission.
  19. *
  20. * Alternatively, this software may be distributed under the terms of the
  21. * GNU General Public License ("GPL") version 2 as published by the Free
  22. * Software Foundation.
  23. *
  24. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  25. * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  26. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  27. * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
  28. * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
  29. * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
  30. * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
  31. * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
  32. * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  33. * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  34. * POSSIBILITY OF SUCH DAMAGE.
  35. */
  36. #include "core.h"
  37. #include "config.h"
  38. #include "bearer.h"
  39. #include "discover.h"
  40. #define MAX_ADDR_STR 32
  41. static struct media media_list[MAX_MEDIA];
  42. static u32 media_count;
  43. struct tipc_bearer tipc_bearers[MAX_BEARERS];
  44. static void bearer_disable(struct tipc_bearer *b_ptr);
  45. /**
  46. * media_name_valid - validate media name
  47. *
  48. * Returns 1 if media name is valid, otherwise 0.
  49. */
  50. static int media_name_valid(const char *name)
  51. {
  52. u32 len;
  53. len = strlen(name);
  54. if ((len + 1) > TIPC_MAX_MEDIA_NAME)
  55. return 0;
  56. return strspn(name, tipc_alphabet) == len;
  57. }
  58. /**
  59. * media_find - locates specified media object by name
  60. */
  61. static struct media *media_find(const char *name)
  62. {
  63. struct media *m_ptr;
  64. u32 i;
  65. for (i = 0, m_ptr = media_list; i < media_count; i++, m_ptr++) {
  66. if (!strcmp(m_ptr->name, name))
  67. return m_ptr;
  68. }
  69. return NULL;
  70. }
  71. /**
  72. * tipc_register_media - register a media type
  73. *
  74. * Bearers for this media type must be activated separately at a later stage.
  75. */
  76. int tipc_register_media(u32 media_type,
  77. char *name,
  78. int (*enable)(struct tipc_bearer *),
  79. void (*disable)(struct tipc_bearer *),
  80. int (*send_msg)(struct sk_buff *,
  81. struct tipc_bearer *,
  82. struct tipc_media_addr *),
  83. char *(*addr2str)(struct tipc_media_addr *a,
  84. char *str_buf, int str_size),
  85. struct tipc_media_addr *bcast_addr,
  86. const u32 bearer_priority,
  87. const u32 link_tolerance, /* [ms] */
  88. const u32 send_window_limit)
  89. {
  90. struct media *m_ptr;
  91. u32 media_id;
  92. u32 i;
  93. int res = -EINVAL;
  94. write_lock_bh(&tipc_net_lock);
  95. if (tipc_mode != TIPC_NET_MODE) {
  96. warn("Media <%s> rejected, not in networked mode yet\n", name);
  97. goto exit;
  98. }
  99. if (!media_name_valid(name)) {
  100. warn("Media <%s> rejected, illegal name\n", name);
  101. goto exit;
  102. }
  103. if (!bcast_addr) {
  104. warn("Media <%s> rejected, no broadcast address\n", name);
  105. goto exit;
  106. }
  107. if ((bearer_priority < TIPC_MIN_LINK_PRI) ||
  108. (bearer_priority > TIPC_MAX_LINK_PRI)) {
  109. warn("Media <%s> rejected, illegal priority (%u)\n", name,
  110. bearer_priority);
  111. goto exit;
  112. }
  113. if ((link_tolerance < TIPC_MIN_LINK_TOL) ||
  114. (link_tolerance > TIPC_MAX_LINK_TOL)) {
  115. warn("Media <%s> rejected, illegal tolerance (%u)\n", name,
  116. link_tolerance);
  117. goto exit;
  118. }
  119. media_id = media_count++;
  120. if (media_id >= MAX_MEDIA) {
  121. warn("Media <%s> rejected, media limit reached (%u)\n", name,
  122. MAX_MEDIA);
  123. media_count--;
  124. goto exit;
  125. }
  126. for (i = 0; i < media_id; i++) {
  127. if (media_list[i].type_id == media_type) {
  128. warn("Media <%s> rejected, duplicate type (%u)\n", name,
  129. media_type);
  130. media_count--;
  131. goto exit;
  132. }
  133. if (!strcmp(name, media_list[i].name)) {
  134. warn("Media <%s> rejected, duplicate name\n", name);
  135. media_count--;
  136. goto exit;
  137. }
  138. }
  139. m_ptr = &media_list[media_id];
  140. m_ptr->type_id = media_type;
  141. m_ptr->send_msg = send_msg;
  142. m_ptr->enable_bearer = enable;
  143. m_ptr->disable_bearer = disable;
  144. m_ptr->addr2str = addr2str;
  145. memcpy(&m_ptr->bcast_addr, bcast_addr, sizeof(*bcast_addr));
  146. strcpy(m_ptr->name, name);
  147. m_ptr->priority = bearer_priority;
  148. m_ptr->tolerance = link_tolerance;
  149. m_ptr->window = send_window_limit;
  150. res = 0;
  151. exit:
  152. write_unlock_bh(&tipc_net_lock);
  153. return res;
  154. }
  155. /**
  156. * tipc_media_addr_printf - record media address in print buffer
  157. */
  158. void tipc_media_addr_printf(struct print_buf *pb, struct tipc_media_addr *a)
  159. {
  160. struct media *m_ptr;
  161. u32 media_type;
  162. u32 i;
  163. media_type = ntohl(a->type);
  164. for (i = 0, m_ptr = media_list; i < media_count; i++, m_ptr++) {
  165. if (m_ptr->type_id == media_type)
  166. break;
  167. }
  168. if ((i < media_count) && (m_ptr->addr2str != NULL)) {
  169. char addr_str[MAX_ADDR_STR];
  170. tipc_printf(pb, "%s(%s)", m_ptr->name,
  171. m_ptr->addr2str(a, addr_str, sizeof(addr_str)));
  172. } else {
  173. unchar *addr = (unchar *)&a->dev_addr;
  174. tipc_printf(pb, "UNKNOWN(%u)", media_type);
  175. for (i = 0; i < (sizeof(*a) - sizeof(a->type)); i++)
  176. tipc_printf(pb, "-%02x", addr[i]);
  177. }
  178. }
  179. /**
  180. * tipc_media_get_names - record names of registered media in buffer
  181. */
  182. struct sk_buff *tipc_media_get_names(void)
  183. {
  184. struct sk_buff *buf;
  185. struct media *m_ptr;
  186. int i;
  187. buf = tipc_cfg_reply_alloc(MAX_MEDIA * TLV_SPACE(TIPC_MAX_MEDIA_NAME));
  188. if (!buf)
  189. return NULL;
  190. read_lock_bh(&tipc_net_lock);
  191. for (i = 0, m_ptr = media_list; i < media_count; i++, m_ptr++) {
  192. tipc_cfg_append_tlv(buf, TIPC_TLV_MEDIA_NAME, m_ptr->name,
  193. strlen(m_ptr->name) + 1);
  194. }
  195. read_unlock_bh(&tipc_net_lock);
  196. return buf;
  197. }
  198. /**
  199. * bearer_name_validate - validate & (optionally) deconstruct bearer name
  200. * @name - ptr to bearer name string
  201. * @name_parts - ptr to area for bearer name components (or NULL if not needed)
  202. *
  203. * Returns 1 if bearer name is valid, otherwise 0.
  204. */
  205. static int bearer_name_validate(const char *name,
  206. struct bearer_name *name_parts)
  207. {
  208. char name_copy[TIPC_MAX_BEARER_NAME];
  209. char *media_name;
  210. char *if_name;
  211. u32 media_len;
  212. u32 if_len;
  213. /* copy bearer name & ensure length is OK */
  214. name_copy[TIPC_MAX_BEARER_NAME - 1] = 0;
  215. /* need above in case non-Posix strncpy() doesn't pad with nulls */
  216. strncpy(name_copy, name, TIPC_MAX_BEARER_NAME);
  217. if (name_copy[TIPC_MAX_BEARER_NAME - 1] != 0)
  218. return 0;
  219. /* ensure all component parts of bearer name are present */
  220. media_name = name_copy;
  221. if_name = strchr(media_name, ':');
  222. if (if_name == NULL)
  223. return 0;
  224. *(if_name++) = 0;
  225. media_len = if_name - media_name;
  226. if_len = strlen(if_name) + 1;
  227. /* validate component parts of bearer name */
  228. if ((media_len <= 1) || (media_len > TIPC_MAX_MEDIA_NAME) ||
  229. (if_len <= 1) || (if_len > TIPC_MAX_IF_NAME) ||
  230. (strspn(media_name, tipc_alphabet) != (media_len - 1)) ||
  231. (strspn(if_name, tipc_alphabet) != (if_len - 1)))
  232. return 0;
  233. /* return bearer name components, if necessary */
  234. if (name_parts) {
  235. strcpy(name_parts->media_name, media_name);
  236. strcpy(name_parts->if_name, if_name);
  237. }
  238. return 1;
  239. }
  240. /**
  241. * bearer_find - locates bearer object with matching bearer name
  242. */
  243. static struct tipc_bearer *bearer_find(const char *name)
  244. {
  245. struct tipc_bearer *b_ptr;
  246. u32 i;
  247. for (i = 0, b_ptr = tipc_bearers; i < MAX_BEARERS; i++, b_ptr++) {
  248. if (b_ptr->active && (!strcmp(b_ptr->name, name)))
  249. return b_ptr;
  250. }
  251. return NULL;
  252. }
  253. /**
  254. * tipc_bearer_find_interface - locates bearer object with matching interface name
  255. */
  256. struct tipc_bearer *tipc_bearer_find_interface(const char *if_name)
  257. {
  258. struct tipc_bearer *b_ptr;
  259. char *b_if_name;
  260. u32 i;
  261. for (i = 0, b_ptr = tipc_bearers; i < MAX_BEARERS; i++, b_ptr++) {
  262. if (!b_ptr->active)
  263. continue;
  264. b_if_name = strchr(b_ptr->name, ':') + 1;
  265. if (!strcmp(b_if_name, if_name))
  266. return b_ptr;
  267. }
  268. return NULL;
  269. }
  270. /**
  271. * tipc_bearer_get_names - record names of bearers in buffer
  272. */
  273. struct sk_buff *tipc_bearer_get_names(void)
  274. {
  275. struct sk_buff *buf;
  276. struct media *m_ptr;
  277. struct tipc_bearer *b_ptr;
  278. int i, j;
  279. buf = tipc_cfg_reply_alloc(MAX_BEARERS * TLV_SPACE(TIPC_MAX_BEARER_NAME));
  280. if (!buf)
  281. return NULL;
  282. read_lock_bh(&tipc_net_lock);
  283. for (i = 0, m_ptr = media_list; i < media_count; i++, m_ptr++) {
  284. for (j = 0; j < MAX_BEARERS; j++) {
  285. b_ptr = &tipc_bearers[j];
  286. if (b_ptr->active && (b_ptr->media == m_ptr)) {
  287. tipc_cfg_append_tlv(buf, TIPC_TLV_BEARER_NAME,
  288. b_ptr->name,
  289. strlen(b_ptr->name) + 1);
  290. }
  291. }
  292. }
  293. read_unlock_bh(&tipc_net_lock);
  294. return buf;
  295. }
  296. void tipc_bearer_add_dest(struct tipc_bearer *b_ptr, u32 dest)
  297. {
  298. tipc_nmap_add(&b_ptr->nodes, dest);
  299. tipc_bcbearer_sort();
  300. tipc_disc_add_dest(b_ptr->link_req);
  301. }
  302. void tipc_bearer_remove_dest(struct tipc_bearer *b_ptr, u32 dest)
  303. {
  304. tipc_nmap_remove(&b_ptr->nodes, dest);
  305. tipc_bcbearer_sort();
  306. tipc_disc_remove_dest(b_ptr->link_req);
  307. }
  308. /*
  309. * bearer_push(): Resolve bearer congestion. Force the waiting
  310. * links to push out their unsent packets, one packet per link
  311. * per iteration, until all packets are gone or congestion reoccurs.
  312. * 'tipc_net_lock' is read_locked when this function is called
  313. * bearer.lock must be taken before calling
  314. * Returns binary true(1) ore false(0)
  315. */
  316. static int bearer_push(struct tipc_bearer *b_ptr)
  317. {
  318. u32 res = 0;
  319. struct link *ln, *tln;
  320. if (b_ptr->blocked)
  321. return 0;
  322. while (!list_empty(&b_ptr->cong_links) && (res != PUSH_FAILED)) {
  323. list_for_each_entry_safe(ln, tln, &b_ptr->cong_links, link_list) {
  324. res = tipc_link_push_packet(ln);
  325. if (res == PUSH_FAILED)
  326. break;
  327. if (res == PUSH_FINISHED)
  328. list_move_tail(&ln->link_list, &b_ptr->links);
  329. }
  330. }
  331. return list_empty(&b_ptr->cong_links);
  332. }
  333. void tipc_bearer_lock_push(struct tipc_bearer *b_ptr)
  334. {
  335. int res;
  336. spin_lock_bh(&b_ptr->lock);
  337. res = bearer_push(b_ptr);
  338. spin_unlock_bh(&b_ptr->lock);
  339. if (res)
  340. tipc_bcbearer_push();
  341. }
  342. /*
  343. * Interrupt enabling new requests after bearer congestion or blocking:
  344. * See bearer_send().
  345. */
  346. void tipc_continue(struct tipc_bearer *b_ptr)
  347. {
  348. spin_lock_bh(&b_ptr->lock);
  349. b_ptr->continue_count++;
  350. if (!list_empty(&b_ptr->cong_links))
  351. tipc_k_signal((Handler)tipc_bearer_lock_push, (unsigned long)b_ptr);
  352. b_ptr->blocked = 0;
  353. spin_unlock_bh(&b_ptr->lock);
  354. }
  355. /*
  356. * Schedule link for sending of messages after the bearer
  357. * has been deblocked by 'continue()'. This method is called
  358. * when somebody tries to send a message via this link while
  359. * the bearer is congested. 'tipc_net_lock' is in read_lock here
  360. * bearer.lock is busy
  361. */
  362. static void tipc_bearer_schedule_unlocked(struct tipc_bearer *b_ptr, struct link *l_ptr)
  363. {
  364. list_move_tail(&l_ptr->link_list, &b_ptr->cong_links);
  365. }
  366. /*
  367. * Schedule link for sending of messages after the bearer
  368. * has been deblocked by 'continue()'. This method is called
  369. * when somebody tries to send a message via this link while
  370. * the bearer is congested. 'tipc_net_lock' is in read_lock here,
  371. * bearer.lock is free
  372. */
  373. void tipc_bearer_schedule(struct tipc_bearer *b_ptr, struct link *l_ptr)
  374. {
  375. spin_lock_bh(&b_ptr->lock);
  376. tipc_bearer_schedule_unlocked(b_ptr, l_ptr);
  377. spin_unlock_bh(&b_ptr->lock);
  378. }
  379. /*
  380. * tipc_bearer_resolve_congestion(): Check if there is bearer congestion,
  381. * and if there is, try to resolve it before returning.
  382. * 'tipc_net_lock' is read_locked when this function is called
  383. */
  384. int tipc_bearer_resolve_congestion(struct tipc_bearer *b_ptr, struct link *l_ptr)
  385. {
  386. int res = 1;
  387. if (list_empty(&b_ptr->cong_links))
  388. return 1;
  389. spin_lock_bh(&b_ptr->lock);
  390. if (!bearer_push(b_ptr)) {
  391. tipc_bearer_schedule_unlocked(b_ptr, l_ptr);
  392. res = 0;
  393. }
  394. spin_unlock_bh(&b_ptr->lock);
  395. return res;
  396. }
  397. /**
  398. * tipc_bearer_congested - determines if bearer is currently congested
  399. */
  400. int tipc_bearer_congested(struct tipc_bearer *b_ptr, struct link *l_ptr)
  401. {
  402. if (unlikely(b_ptr->blocked))
  403. return 1;
  404. if (likely(list_empty(&b_ptr->cong_links)))
  405. return 0;
  406. return !tipc_bearer_resolve_congestion(b_ptr, l_ptr);
  407. }
  408. /**
  409. * tipc_enable_bearer - enable bearer with the given name
  410. */
  411. int tipc_enable_bearer(const char *name, u32 disc_domain, u32 priority)
  412. {
  413. struct tipc_bearer *b_ptr;
  414. struct media *m_ptr;
  415. struct bearer_name b_name;
  416. char addr_string[16];
  417. u32 bearer_id;
  418. u32 with_this_prio;
  419. u32 i;
  420. int res = -EINVAL;
  421. if (tipc_mode != TIPC_NET_MODE) {
  422. warn("Bearer <%s> rejected, not supported in standalone mode\n",
  423. name);
  424. return -ENOPROTOOPT;
  425. }
  426. if (!bearer_name_validate(name, &b_name)) {
  427. warn("Bearer <%s> rejected, illegal name\n", name);
  428. return -EINVAL;
  429. }
  430. if (tipc_addr_domain_valid(disc_domain) &&
  431. (disc_domain != tipc_own_addr)) {
  432. if (tipc_in_scope(disc_domain, tipc_own_addr)) {
  433. disc_domain = tipc_own_addr & TIPC_CLUSTER_MASK;
  434. res = 0; /* accept any node in own cluster */
  435. } else if (in_own_cluster(disc_domain))
  436. res = 0; /* accept specified node in own cluster */
  437. }
  438. if (res) {
  439. warn("Bearer <%s> rejected, illegal discovery domain\n", name);
  440. return -EINVAL;
  441. }
  442. if ((priority < TIPC_MIN_LINK_PRI ||
  443. priority > TIPC_MAX_LINK_PRI) &&
  444. (priority != TIPC_MEDIA_LINK_PRI)) {
  445. warn("Bearer <%s> rejected, illegal priority\n", name);
  446. return -EINVAL;
  447. }
  448. write_lock_bh(&tipc_net_lock);
  449. m_ptr = media_find(b_name.media_name);
  450. if (!m_ptr) {
  451. warn("Bearer <%s> rejected, media <%s> not registered\n", name,
  452. b_name.media_name);
  453. goto exit;
  454. }
  455. if (priority == TIPC_MEDIA_LINK_PRI)
  456. priority = m_ptr->priority;
  457. restart:
  458. bearer_id = MAX_BEARERS;
  459. with_this_prio = 1;
  460. for (i = MAX_BEARERS; i-- != 0; ) {
  461. if (!tipc_bearers[i].active) {
  462. bearer_id = i;
  463. continue;
  464. }
  465. if (!strcmp(name, tipc_bearers[i].name)) {
  466. warn("Bearer <%s> rejected, already enabled\n", name);
  467. goto exit;
  468. }
  469. if ((tipc_bearers[i].priority == priority) &&
  470. (++with_this_prio > 2)) {
  471. if (priority-- == 0) {
  472. warn("Bearer <%s> rejected, duplicate priority\n",
  473. name);
  474. goto exit;
  475. }
  476. warn("Bearer <%s> priority adjustment required %u->%u\n",
  477. name, priority + 1, priority);
  478. goto restart;
  479. }
  480. }
  481. if (bearer_id >= MAX_BEARERS) {
  482. warn("Bearer <%s> rejected, bearer limit reached (%u)\n",
  483. name, MAX_BEARERS);
  484. goto exit;
  485. }
  486. b_ptr = &tipc_bearers[bearer_id];
  487. strcpy(b_ptr->name, name);
  488. res = m_ptr->enable_bearer(b_ptr);
  489. if (res) {
  490. warn("Bearer <%s> rejected, enable failure (%d)\n", name, -res);
  491. goto exit;
  492. }
  493. b_ptr->identity = bearer_id;
  494. b_ptr->media = m_ptr;
  495. b_ptr->net_plane = bearer_id + 'A';
  496. b_ptr->active = 1;
  497. b_ptr->priority = priority;
  498. INIT_LIST_HEAD(&b_ptr->cong_links);
  499. INIT_LIST_HEAD(&b_ptr->links);
  500. spin_lock_init(&b_ptr->lock);
  501. res = tipc_disc_create(b_ptr, &m_ptr->bcast_addr, disc_domain);
  502. if (res) {
  503. bearer_disable(b_ptr);
  504. warn("Bearer <%s> rejected, discovery object creation failed\n",
  505. name);
  506. goto exit;
  507. }
  508. info("Enabled bearer <%s>, discovery domain %s, priority %u\n",
  509. name, tipc_addr_string_fill(addr_string, disc_domain), priority);
  510. exit:
  511. write_unlock_bh(&tipc_net_lock);
  512. return res;
  513. }
  514. /**
  515. * tipc_block_bearer(): Block the bearer with the given name,
  516. * and reset all its links
  517. */
  518. int tipc_block_bearer(const char *name)
  519. {
  520. struct tipc_bearer *b_ptr = NULL;
  521. struct link *l_ptr;
  522. struct link *temp_l_ptr;
  523. read_lock_bh(&tipc_net_lock);
  524. b_ptr = bearer_find(name);
  525. if (!b_ptr) {
  526. warn("Attempt to block unknown bearer <%s>\n", name);
  527. read_unlock_bh(&tipc_net_lock);
  528. return -EINVAL;
  529. }
  530. info("Blocking bearer <%s>\n", name);
  531. spin_lock_bh(&b_ptr->lock);
  532. b_ptr->blocked = 1;
  533. list_for_each_entry_safe(l_ptr, temp_l_ptr, &b_ptr->links, link_list) {
  534. struct tipc_node *n_ptr = l_ptr->owner;
  535. spin_lock_bh(&n_ptr->lock);
  536. tipc_link_reset(l_ptr);
  537. spin_unlock_bh(&n_ptr->lock);
  538. }
  539. spin_unlock_bh(&b_ptr->lock);
  540. read_unlock_bh(&tipc_net_lock);
  541. return 0;
  542. }
  543. /**
  544. * bearer_disable -
  545. *
  546. * Note: This routine assumes caller holds tipc_net_lock.
  547. */
  548. static void bearer_disable(struct tipc_bearer *b_ptr)
  549. {
  550. struct link *l_ptr;
  551. struct link *temp_l_ptr;
  552. info("Disabling bearer <%s>\n", b_ptr->name);
  553. spin_lock_bh(&b_ptr->lock);
  554. b_ptr->blocked = 1;
  555. b_ptr->media->disable_bearer(b_ptr);
  556. list_for_each_entry_safe(l_ptr, temp_l_ptr, &b_ptr->links, link_list) {
  557. tipc_link_delete(l_ptr);
  558. }
  559. if (b_ptr->link_req)
  560. tipc_disc_delete(b_ptr->link_req);
  561. spin_unlock_bh(&b_ptr->lock);
  562. memset(b_ptr, 0, sizeof(struct tipc_bearer));
  563. }
  564. int tipc_disable_bearer(const char *name)
  565. {
  566. struct tipc_bearer *b_ptr;
  567. int res;
  568. write_lock_bh(&tipc_net_lock);
  569. b_ptr = bearer_find(name);
  570. if (b_ptr == NULL) {
  571. warn("Attempt to disable unknown bearer <%s>\n", name);
  572. res = -EINVAL;
  573. } else {
  574. bearer_disable(b_ptr);
  575. res = 0;
  576. }
  577. write_unlock_bh(&tipc_net_lock);
  578. return res;
  579. }
  580. void tipc_bearer_stop(void)
  581. {
  582. u32 i;
  583. for (i = 0; i < MAX_BEARERS; i++) {
  584. if (tipc_bearers[i].active)
  585. bearer_disable(&tipc_bearers[i]);
  586. }
  587. media_count = 0;
  588. }