bearer.c 17 KB

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