bearer.c 17 KB

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