bearer.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692
  1. /*
  2. * net/tipc/bearer.c: TIPC bearer code
  3. *
  4. * Copyright (c) 2003-2006, Ericsson AB
  5. * Copyright (c) 2004-2005, 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 = 0;
  46. static u32 media_count = 0;
  47. struct bearer *bearers = 0;
  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 0;
  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(&net_lock);
  98. if (!media_list)
  99. goto exit;
  100. if (!media_name_valid(name)) {
  101. warn("Media registration error: illegal name <%s>\n", name);
  102. goto exit;
  103. }
  104. if (!bcast_addr) {
  105. warn("Media registration error: no broadcast address supplied\n");
  106. goto exit;
  107. }
  108. if (bearer_priority >= TIPC_NUM_LINK_PRI) {
  109. warn("Media registration error: priority %u\n", bearer_priority);
  110. goto exit;
  111. }
  112. if ((link_tolerance < TIPC_MIN_LINK_TOL) ||
  113. (link_tolerance > TIPC_MAX_LINK_TOL)) {
  114. warn("Media registration error: tolerance %u\n", link_tolerance);
  115. goto exit;
  116. }
  117. media_id = media_count++;
  118. if (media_id >= MAX_MEDIA) {
  119. warn("Attempt to register more than %u media\n", MAX_MEDIA);
  120. media_count--;
  121. goto exit;
  122. }
  123. for (i = 0; i < media_id; i++) {
  124. if (media_list[i].type_id == media_type) {
  125. warn("Attempt to register second media with type %u\n",
  126. media_type);
  127. media_count--;
  128. goto exit;
  129. }
  130. if (!strcmp(name, media_list[i].name)) {
  131. warn("Attempt to re-register media name <%s>\n", name);
  132. media_count--;
  133. goto exit;
  134. }
  135. }
  136. m_ptr = &media_list[media_id];
  137. m_ptr->type_id = media_type;
  138. m_ptr->send_msg = send_msg;
  139. m_ptr->enable_bearer = enable;
  140. m_ptr->disable_bearer = disable;
  141. m_ptr->addr2str = addr2str;
  142. memcpy(&m_ptr->bcast_addr, bcast_addr, sizeof(*bcast_addr));
  143. m_ptr->bcast = 1;
  144. strcpy(m_ptr->name, name);
  145. m_ptr->priority = bearer_priority;
  146. m_ptr->tolerance = link_tolerance;
  147. m_ptr->window = send_window_limit;
  148. dbg("Media <%s> registered\n", name);
  149. res = 0;
  150. exit:
  151. write_unlock_bh(&net_lock);
  152. return res;
  153. }
  154. /**
  155. * media_addr_printf - record media address in print buffer
  156. */
  157. void 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. /**
  180. * media_get_names - record names of registered media in buffer
  181. */
  182. struct sk_buff *media_get_names(void)
  183. {
  184. struct sk_buff *buf;
  185. struct media *m_ptr;
  186. int i;
  187. buf = cfg_reply_alloc(MAX_MEDIA * TLV_SPACE(TIPC_MAX_MEDIA_NAME));
  188. if (!buf)
  189. return NULL;
  190. read_lock_bh(&net_lock);
  191. for (i = 0, m_ptr = media_list; i < media_count; i++, m_ptr++) {
  192. cfg_append_tlv(buf, TIPC_TLV_MEDIA_NAME, m_ptr->name,
  193. strlen(m_ptr->name) + 1);
  194. }
  195. read_unlock_bh(&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 ((if_name = strchr(media_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 bearer *bearer_find(const char *name)
  243. {
  244. struct bearer *b_ptr;
  245. u32 i;
  246. for (i = 0, b_ptr = bearers; i < MAX_BEARERS; i++, b_ptr++) {
  247. if (b_ptr->active && (!strcmp(b_ptr->publ.name, name)))
  248. return b_ptr;
  249. }
  250. return 0;
  251. }
  252. /**
  253. * bearer_find - locates bearer object with matching interface name
  254. */
  255. struct bearer *bearer_find_interface(const char *if_name)
  256. {
  257. struct bearer *b_ptr;
  258. char *b_if_name;
  259. u32 i;
  260. for (i = 0, b_ptr = bearers; i < MAX_BEARERS; i++, b_ptr++) {
  261. if (!b_ptr->active)
  262. continue;
  263. b_if_name = strchr(b_ptr->publ.name, ':') + 1;
  264. if (!strcmp(b_if_name, if_name))
  265. return b_ptr;
  266. }
  267. return 0;
  268. }
  269. /**
  270. * bearer_get_names - record names of bearers in buffer
  271. */
  272. struct sk_buff *bearer_get_names(void)
  273. {
  274. struct sk_buff *buf;
  275. struct media *m_ptr;
  276. struct bearer *b_ptr;
  277. int i, j;
  278. buf = cfg_reply_alloc(MAX_BEARERS * TLV_SPACE(TIPC_MAX_BEARER_NAME));
  279. if (!buf)
  280. return NULL;
  281. read_lock_bh(&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 = &bearers[j];
  285. if (b_ptr->active && (b_ptr->media == m_ptr)) {
  286. cfg_append_tlv(buf, TIPC_TLV_BEARER_NAME,
  287. b_ptr->publ.name,
  288. strlen(b_ptr->publ.name) + 1);
  289. }
  290. }
  291. }
  292. read_unlock_bh(&net_lock);
  293. return buf;
  294. }
  295. void bearer_add_dest(struct bearer *b_ptr, u32 dest)
  296. {
  297. nmap_add(&b_ptr->nodes, dest);
  298. disc_update_link_req(b_ptr->link_req);
  299. bcbearer_sort();
  300. }
  301. void bearer_remove_dest(struct bearer *b_ptr, u32 dest)
  302. {
  303. nmap_remove(&b_ptr->nodes, dest);
  304. disc_update_link_req(b_ptr->link_req);
  305. 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. * '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 bearer *b_ptr)
  316. {
  317. u32 res = TIPC_OK;
  318. struct link *ln, *tln;
  319. if (b_ptr->publ.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 = 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 bearer_lock_push(struct bearer *b_ptr)
  333. {
  334. int res;
  335. spin_lock_bh(&b_ptr->publ.lock);
  336. res = bearer_push(b_ptr);
  337. spin_unlock_bh(&b_ptr->publ.lock);
  338. if (res)
  339. 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 *tb_ptr)
  346. {
  347. struct bearer *b_ptr = (struct bearer *)tb_ptr;
  348. spin_lock_bh(&b_ptr->publ.lock);
  349. b_ptr->continue_count++;
  350. if (!list_empty(&b_ptr->cong_links))
  351. k_signal((Handler)bearer_lock_push, (unsigned long)b_ptr);
  352. b_ptr->publ.blocked = 0;
  353. spin_unlock_bh(&b_ptr->publ.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. 'net_lock' is in read_lock here
  360. * bearer.lock is busy
  361. */
  362. static void bearer_schedule_unlocked(struct 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. 'net_lock' is in read_lock here,
  371. * bearer.lock is free
  372. */
  373. void bearer_schedule(struct bearer *b_ptr, struct link *l_ptr)
  374. {
  375. spin_lock_bh(&b_ptr->publ.lock);
  376. bearer_schedule_unlocked(b_ptr, l_ptr);
  377. spin_unlock_bh(&b_ptr->publ.lock);
  378. }
  379. /*
  380. * bearer_resolve_congestion(): Check if there is bearer congestion,
  381. * and if there is, try to resolve it before returning.
  382. * 'net_lock' is read_locked when this function is called
  383. */
  384. int bearer_resolve_congestion(struct 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->publ.lock);
  390. if (!bearer_push(b_ptr)) {
  391. bearer_schedule_unlocked(b_ptr, l_ptr);
  392. res = 0;
  393. }
  394. spin_unlock_bh(&b_ptr->publ.lock);
  395. return res;
  396. }
  397. /**
  398. * tipc_enable_bearer - enable bearer with the given name
  399. */
  400. int tipc_enable_bearer(const char *name, u32 bcast_scope, u32 priority)
  401. {
  402. struct bearer *b_ptr;
  403. struct media *m_ptr;
  404. struct bearer_name b_name;
  405. char addr_string[16];
  406. u32 bearer_id;
  407. u32 with_this_prio;
  408. u32 i;
  409. int res = -EINVAL;
  410. if (tipc_mode != TIPC_NET_MODE)
  411. return -ENOPROTOOPT;
  412. if (!bearer_name_validate(name, &b_name) ||
  413. !addr_domain_valid(bcast_scope) ||
  414. !in_scope(bcast_scope, tipc_own_addr) ||
  415. (priority > TIPC_NUM_LINK_PRI))
  416. return -EINVAL;
  417. write_lock_bh(&net_lock);
  418. if (!bearers)
  419. goto failed;
  420. m_ptr = media_find(b_name.media_name);
  421. if (!m_ptr) {
  422. warn("No media <%s>\n", b_name.media_name);
  423. goto failed;
  424. }
  425. if (priority == TIPC_NUM_LINK_PRI)
  426. priority = m_ptr->priority;
  427. restart:
  428. bearer_id = MAX_BEARERS;
  429. with_this_prio = 1;
  430. for (i = MAX_BEARERS; i-- != 0; ) {
  431. if (!bearers[i].active) {
  432. bearer_id = i;
  433. continue;
  434. }
  435. if (!strcmp(name, bearers[i].publ.name)) {
  436. warn("Bearer <%s> already enabled\n", name);
  437. goto failed;
  438. }
  439. if ((bearers[i].priority == priority) &&
  440. (++with_this_prio > 2)) {
  441. if (priority-- == 0) {
  442. warn("Third bearer <%s> with priority %u, unable to lower to %u\n",
  443. name, priority + 1, priority);
  444. goto failed;
  445. }
  446. warn("Third bearer <%s> with priority %u, lowering to %u\n",
  447. name, priority + 1, priority);
  448. goto restart;
  449. }
  450. }
  451. if (bearer_id >= MAX_BEARERS) {
  452. warn("Attempt to enable more than %d bearers\n", MAX_BEARERS);
  453. goto failed;
  454. }
  455. b_ptr = &bearers[bearer_id];
  456. memset(b_ptr, 0, sizeof(struct bearer));
  457. strcpy(b_ptr->publ.name, name);
  458. res = m_ptr->enable_bearer(&b_ptr->publ);
  459. if (res) {
  460. warn("Failed to enable bearer <%s>\n", name);
  461. goto failed;
  462. }
  463. b_ptr->identity = bearer_id;
  464. b_ptr->media = m_ptr;
  465. b_ptr->net_plane = bearer_id + 'A';
  466. b_ptr->active = 1;
  467. b_ptr->detect_scope = bcast_scope;
  468. b_ptr->priority = priority;
  469. INIT_LIST_HEAD(&b_ptr->cong_links);
  470. INIT_LIST_HEAD(&b_ptr->links);
  471. if (m_ptr->bcast) {
  472. b_ptr->link_req = disc_init_link_req(b_ptr, &m_ptr->bcast_addr,
  473. bcast_scope, 2);
  474. }
  475. b_ptr->publ.lock = SPIN_LOCK_UNLOCKED;
  476. write_unlock_bh(&net_lock);
  477. info("Enabled bearer <%s>, discovery domain %s\n",
  478. name, addr_string_fill(addr_string, bcast_scope));
  479. return 0;
  480. failed:
  481. write_unlock_bh(&net_lock);
  482. return res;
  483. }
  484. /**
  485. * tipc_block_bearer(): Block the bearer with the given name,
  486. * and reset all its links
  487. */
  488. int tipc_block_bearer(const char *name)
  489. {
  490. struct bearer *b_ptr = 0;
  491. struct link *l_ptr;
  492. struct link *temp_l_ptr;
  493. if (tipc_mode != TIPC_NET_MODE)
  494. return -ENOPROTOOPT;
  495. read_lock_bh(&net_lock);
  496. b_ptr = bearer_find(name);
  497. if (!b_ptr) {
  498. warn("Attempt to block unknown bearer <%s>\n", name);
  499. read_unlock_bh(&net_lock);
  500. return -EINVAL;
  501. }
  502. spin_lock_bh(&b_ptr->publ.lock);
  503. b_ptr->publ.blocked = 1;
  504. list_for_each_entry_safe(l_ptr, temp_l_ptr, &b_ptr->links, link_list) {
  505. struct node *n_ptr = l_ptr->owner;
  506. spin_lock_bh(&n_ptr->lock);
  507. link_reset(l_ptr);
  508. spin_unlock_bh(&n_ptr->lock);
  509. }
  510. spin_unlock_bh(&b_ptr->publ.lock);
  511. read_unlock_bh(&net_lock);
  512. info("Blocked bearer <%s>\n", name);
  513. return TIPC_OK;
  514. }
  515. /**
  516. * bearer_disable -
  517. *
  518. * Note: This routine assumes caller holds net_lock.
  519. */
  520. static int bearer_disable(const char *name)
  521. {
  522. struct bearer *b_ptr;
  523. struct link *l_ptr;
  524. struct link *temp_l_ptr;
  525. if (tipc_mode != TIPC_NET_MODE)
  526. return -ENOPROTOOPT;
  527. b_ptr = bearer_find(name);
  528. if (!b_ptr) {
  529. warn("Attempt to disable unknown bearer <%s>\n", name);
  530. return -EINVAL;
  531. }
  532. disc_stop_link_req(b_ptr->link_req);
  533. spin_lock_bh(&b_ptr->publ.lock);
  534. b_ptr->link_req = NULL;
  535. b_ptr->publ.blocked = 1;
  536. if (b_ptr->media->disable_bearer) {
  537. spin_unlock_bh(&b_ptr->publ.lock);
  538. write_unlock_bh(&net_lock);
  539. b_ptr->media->disable_bearer(&b_ptr->publ);
  540. write_lock_bh(&net_lock);
  541. spin_lock_bh(&b_ptr->publ.lock);
  542. }
  543. list_for_each_entry_safe(l_ptr, temp_l_ptr, &b_ptr->links, link_list) {
  544. link_delete(l_ptr);
  545. }
  546. spin_unlock_bh(&b_ptr->publ.lock);
  547. info("Disabled bearer <%s>\n", name);
  548. memset(b_ptr, 0, sizeof(struct bearer));
  549. return TIPC_OK;
  550. }
  551. int tipc_disable_bearer(const char *name)
  552. {
  553. int res;
  554. write_lock_bh(&net_lock);
  555. res = bearer_disable(name);
  556. write_unlock_bh(&net_lock);
  557. return res;
  558. }
  559. int bearer_init(void)
  560. {
  561. int res;
  562. write_lock_bh(&net_lock);
  563. bearers = kmalloc(MAX_BEARERS * sizeof(struct bearer), GFP_ATOMIC);
  564. media_list = kmalloc(MAX_MEDIA * sizeof(struct media), GFP_ATOMIC);
  565. if (bearers && media_list) {
  566. memset(bearers, 0, MAX_BEARERS * sizeof(struct bearer));
  567. memset(media_list, 0, MAX_MEDIA * sizeof(struct media));
  568. res = TIPC_OK;
  569. } else {
  570. kfree(bearers);
  571. kfree(media_list);
  572. bearers = 0;
  573. media_list = 0;
  574. res = -ENOMEM;
  575. }
  576. write_unlock_bh(&net_lock);
  577. return res;
  578. }
  579. void bearer_stop(void)
  580. {
  581. u32 i;
  582. if (!bearers)
  583. return;
  584. for (i = 0; i < MAX_BEARERS; i++) {
  585. if (bearers[i].active)
  586. bearers[i].publ.blocked = 1;
  587. }
  588. for (i = 0; i < MAX_BEARERS; i++) {
  589. if (bearers[i].active)
  590. bearer_disable(bearers[i].publ.name);
  591. }
  592. kfree(bearers);
  593. kfree(media_list);
  594. bearers = 0;
  595. media_list = 0;
  596. media_count = 0;
  597. }