bearer.c 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642
  1. /*
  2. * net/tipc/bearer.c: TIPC bearer code
  3. *
  4. * Copyright (c) 1996-2006, 2013, Ericsson AB
  5. * Copyright (c) 2004-2006, 2010-2013, 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 60
  41. static struct tipc_media * const media_info_array[] = {
  42. &eth_media_info,
  43. #ifdef CONFIG_TIPC_MEDIA_IB
  44. &ib_media_info,
  45. #endif
  46. NULL
  47. };
  48. struct tipc_bearer *bearer_list[MAX_BEARERS + 1];
  49. static void bearer_disable(struct tipc_bearer *b_ptr, bool shutting_down);
  50. /**
  51. * tipc_media_find - locates specified media object by name
  52. */
  53. struct tipc_media *tipc_media_find(const char *name)
  54. {
  55. u32 i;
  56. for (i = 0; media_info_array[i] != NULL; i++) {
  57. if (!strcmp(media_info_array[i]->name, name))
  58. break;
  59. }
  60. return media_info_array[i];
  61. }
  62. /**
  63. * media_find_id - locates specified media object by type identifier
  64. */
  65. static struct tipc_media *media_find_id(u8 type)
  66. {
  67. u32 i;
  68. for (i = 0; media_info_array[i] != NULL; i++) {
  69. if (media_info_array[i]->type_id == type)
  70. break;
  71. }
  72. return media_info_array[i];
  73. }
  74. /**
  75. * tipc_media_addr_printf - record media address in print buffer
  76. */
  77. void tipc_media_addr_printf(char *buf, int len, struct tipc_media_addr *a)
  78. {
  79. char addr_str[MAX_ADDR_STR];
  80. struct tipc_media *m_ptr;
  81. int ret;
  82. m_ptr = media_find_id(a->media_id);
  83. if (m_ptr && !m_ptr->addr2str(a, addr_str, sizeof(addr_str)))
  84. ret = tipc_snprintf(buf, len, "%s(%s)", m_ptr->name, addr_str);
  85. else {
  86. u32 i;
  87. ret = tipc_snprintf(buf, len, "UNKNOWN(%u)", a->media_id);
  88. for (i = 0; i < sizeof(a->value); i++)
  89. ret += tipc_snprintf(buf - ret, len + ret,
  90. "-%02x", a->value[i]);
  91. }
  92. }
  93. /**
  94. * tipc_media_get_names - record names of registered media in buffer
  95. */
  96. struct sk_buff *tipc_media_get_names(void)
  97. {
  98. struct sk_buff *buf;
  99. int i;
  100. buf = tipc_cfg_reply_alloc(MAX_MEDIA * TLV_SPACE(TIPC_MAX_MEDIA_NAME));
  101. if (!buf)
  102. return NULL;
  103. for (i = 0; media_info_array[i] != NULL; i++) {
  104. tipc_cfg_append_tlv(buf, TIPC_TLV_MEDIA_NAME,
  105. media_info_array[i]->name,
  106. strlen(media_info_array[i]->name) + 1);
  107. }
  108. return buf;
  109. }
  110. /**
  111. * bearer_name_validate - validate & (optionally) deconstruct bearer name
  112. * @name: ptr to bearer name string
  113. * @name_parts: ptr to area for bearer name components (or NULL if not needed)
  114. *
  115. * Returns 1 if bearer name is valid, otherwise 0.
  116. */
  117. static int bearer_name_validate(const char *name,
  118. struct tipc_bearer_names *name_parts)
  119. {
  120. char name_copy[TIPC_MAX_BEARER_NAME];
  121. char *media_name;
  122. char *if_name;
  123. u32 media_len;
  124. u32 if_len;
  125. /* copy bearer name & ensure length is OK */
  126. name_copy[TIPC_MAX_BEARER_NAME - 1] = 0;
  127. /* need above in case non-Posix strncpy() doesn't pad with nulls */
  128. strncpy(name_copy, name, TIPC_MAX_BEARER_NAME);
  129. if (name_copy[TIPC_MAX_BEARER_NAME - 1] != 0)
  130. return 0;
  131. /* ensure all component parts of bearer name are present */
  132. media_name = name_copy;
  133. if_name = strchr(media_name, ':');
  134. if (if_name == NULL)
  135. return 0;
  136. *(if_name++) = 0;
  137. media_len = if_name - media_name;
  138. if_len = strlen(if_name) + 1;
  139. /* validate component parts of bearer name */
  140. if ((media_len <= 1) || (media_len > TIPC_MAX_MEDIA_NAME) ||
  141. (if_len <= 1) || (if_len > TIPC_MAX_IF_NAME))
  142. return 0;
  143. /* return bearer name components, if necessary */
  144. if (name_parts) {
  145. strcpy(name_parts->media_name, media_name);
  146. strcpy(name_parts->if_name, if_name);
  147. }
  148. return 1;
  149. }
  150. /**
  151. * tipc_bearer_find - locates bearer object with matching bearer name
  152. */
  153. struct tipc_bearer *tipc_bearer_find(const char *name)
  154. {
  155. struct tipc_bearer *b_ptr;
  156. u32 i;
  157. for (i = 0; i < MAX_BEARERS; i++) {
  158. b_ptr = bearer_list[i];
  159. if (b_ptr && (!strcmp(b_ptr->name, name)))
  160. return b_ptr;
  161. }
  162. return NULL;
  163. }
  164. /**
  165. * tipc_bearer_get_names - record names of bearers in buffer
  166. */
  167. struct sk_buff *tipc_bearer_get_names(void)
  168. {
  169. struct sk_buff *buf;
  170. struct tipc_bearer *b;
  171. int i, j;
  172. buf = tipc_cfg_reply_alloc(MAX_BEARERS * TLV_SPACE(TIPC_MAX_BEARER_NAME));
  173. if (!buf)
  174. return NULL;
  175. read_lock_bh(&tipc_net_lock);
  176. for (i = 0; media_info_array[i] != NULL; i++) {
  177. for (j = 0; j < MAX_BEARERS; j++) {
  178. b = bearer_list[j];
  179. if (!b)
  180. continue;
  181. if (b->media == media_info_array[i]) {
  182. tipc_cfg_append_tlv(buf, TIPC_TLV_BEARER_NAME,
  183. b->name,
  184. strlen(b->name) + 1);
  185. }
  186. }
  187. }
  188. read_unlock_bh(&tipc_net_lock);
  189. return buf;
  190. }
  191. void tipc_bearer_add_dest(struct tipc_bearer *b_ptr, u32 dest)
  192. {
  193. tipc_nmap_add(&b_ptr->nodes, dest);
  194. tipc_bcbearer_sort();
  195. tipc_disc_add_dest(b_ptr->link_req);
  196. }
  197. void tipc_bearer_remove_dest(struct tipc_bearer *b_ptr, u32 dest)
  198. {
  199. tipc_nmap_remove(&b_ptr->nodes, dest);
  200. tipc_bcbearer_sort();
  201. tipc_disc_remove_dest(b_ptr->link_req);
  202. }
  203. /**
  204. * tipc_enable_bearer - enable bearer with the given name
  205. */
  206. int tipc_enable_bearer(const char *name, u32 disc_domain, u32 priority)
  207. {
  208. struct tipc_bearer *b_ptr;
  209. struct tipc_media *m_ptr;
  210. struct tipc_bearer_names b_names;
  211. char addr_string[16];
  212. u32 bearer_id;
  213. u32 with_this_prio;
  214. u32 i;
  215. int res = -EINVAL;
  216. if (!tipc_own_addr) {
  217. pr_warn("Bearer <%s> rejected, not supported in standalone mode\n",
  218. name);
  219. return -ENOPROTOOPT;
  220. }
  221. if (!bearer_name_validate(name, &b_names)) {
  222. pr_warn("Bearer <%s> rejected, illegal name\n", name);
  223. return -EINVAL;
  224. }
  225. if (tipc_addr_domain_valid(disc_domain) &&
  226. (disc_domain != tipc_own_addr)) {
  227. if (tipc_in_scope(disc_domain, tipc_own_addr)) {
  228. disc_domain = tipc_own_addr & TIPC_CLUSTER_MASK;
  229. res = 0; /* accept any node in own cluster */
  230. } else if (in_own_cluster_exact(disc_domain))
  231. res = 0; /* accept specified node in own cluster */
  232. }
  233. if (res) {
  234. pr_warn("Bearer <%s> rejected, illegal discovery domain\n",
  235. name);
  236. return -EINVAL;
  237. }
  238. if ((priority > TIPC_MAX_LINK_PRI) &&
  239. (priority != TIPC_MEDIA_LINK_PRI)) {
  240. pr_warn("Bearer <%s> rejected, illegal priority\n", name);
  241. return -EINVAL;
  242. }
  243. write_lock_bh(&tipc_net_lock);
  244. m_ptr = tipc_media_find(b_names.media_name);
  245. if (!m_ptr) {
  246. pr_warn("Bearer <%s> rejected, media <%s> not registered\n",
  247. name, b_names.media_name);
  248. goto exit;
  249. }
  250. if (priority == TIPC_MEDIA_LINK_PRI)
  251. priority = m_ptr->priority;
  252. restart:
  253. bearer_id = MAX_BEARERS;
  254. with_this_prio = 1;
  255. for (i = MAX_BEARERS; i-- != 0; ) {
  256. b_ptr = bearer_list[i];
  257. if (!b_ptr) {
  258. bearer_id = i;
  259. continue;
  260. }
  261. if (!strcmp(name, b_ptr->name)) {
  262. pr_warn("Bearer <%s> rejected, already enabled\n",
  263. name);
  264. goto exit;
  265. }
  266. if ((b_ptr->priority == priority) &&
  267. (++with_this_prio > 2)) {
  268. if (priority-- == 0) {
  269. pr_warn("Bearer <%s> rejected, duplicate priority\n",
  270. name);
  271. goto exit;
  272. }
  273. pr_warn("Bearer <%s> priority adjustment required %u->%u\n",
  274. name, priority + 1, priority);
  275. goto restart;
  276. }
  277. }
  278. if (bearer_id >= MAX_BEARERS) {
  279. pr_warn("Bearer <%s> rejected, bearer limit reached (%u)\n",
  280. name, MAX_BEARERS);
  281. goto exit;
  282. }
  283. b_ptr = kzalloc(sizeof(*b_ptr), GFP_ATOMIC);
  284. if (!b_ptr) {
  285. res = -ENOMEM;
  286. goto exit;
  287. }
  288. strcpy(b_ptr->name, name);
  289. b_ptr->media = m_ptr;
  290. res = m_ptr->enable_media(b_ptr);
  291. if (res) {
  292. pr_warn("Bearer <%s> rejected, enable failure (%d)\n",
  293. name, -res);
  294. goto exit;
  295. }
  296. b_ptr->identity = bearer_id;
  297. b_ptr->tolerance = m_ptr->tolerance;
  298. b_ptr->window = m_ptr->window;
  299. b_ptr->domain = disc_domain;
  300. b_ptr->net_plane = bearer_id + 'A';
  301. b_ptr->priority = priority;
  302. res = tipc_disc_create(b_ptr, &b_ptr->bcast_addr);
  303. if (res) {
  304. bearer_disable(b_ptr, false);
  305. pr_warn("Bearer <%s> rejected, discovery object creation failed\n",
  306. name);
  307. goto exit;
  308. }
  309. bearer_list[bearer_id] = b_ptr;
  310. pr_info("Enabled bearer <%s>, discovery domain %s, priority %u\n",
  311. name,
  312. tipc_addr_string_fill(addr_string, disc_domain), priority);
  313. exit:
  314. write_unlock_bh(&tipc_net_lock);
  315. return res;
  316. }
  317. /**
  318. * tipc_reset_bearer - Reset all links established over this bearer
  319. */
  320. static int tipc_reset_bearer(struct tipc_bearer *b_ptr)
  321. {
  322. read_lock_bh(&tipc_net_lock);
  323. pr_info("Resetting bearer <%s>\n", b_ptr->name);
  324. tipc_disc_delete(b_ptr->link_req);
  325. tipc_link_reset_list(b_ptr->identity);
  326. tipc_disc_create(b_ptr, &b_ptr->bcast_addr);
  327. read_unlock_bh(&tipc_net_lock);
  328. return 0;
  329. }
  330. /**
  331. * bearer_disable
  332. *
  333. * Note: This routine assumes caller holds tipc_net_lock.
  334. */
  335. static void bearer_disable(struct tipc_bearer *b_ptr, bool shutting_down)
  336. {
  337. u32 i;
  338. pr_info("Disabling bearer <%s>\n", b_ptr->name);
  339. b_ptr->media->disable_media(b_ptr);
  340. tipc_link_delete_list(b_ptr->identity, shutting_down);
  341. if (b_ptr->link_req)
  342. tipc_disc_delete(b_ptr->link_req);
  343. for (i = 0; i < MAX_BEARERS; i++) {
  344. if (b_ptr == bearer_list[i]) {
  345. bearer_list[i] = NULL;
  346. break;
  347. }
  348. }
  349. kfree(b_ptr);
  350. }
  351. int tipc_disable_bearer(const char *name)
  352. {
  353. struct tipc_bearer *b_ptr;
  354. int res;
  355. write_lock_bh(&tipc_net_lock);
  356. b_ptr = tipc_bearer_find(name);
  357. if (b_ptr == NULL) {
  358. pr_warn("Attempt to disable unknown bearer <%s>\n", name);
  359. res = -EINVAL;
  360. } else {
  361. bearer_disable(b_ptr, false);
  362. res = 0;
  363. }
  364. write_unlock_bh(&tipc_net_lock);
  365. return res;
  366. }
  367. /* tipc_l2_media_addr_set - initialize Ethernet media address structure
  368. *
  369. * Media-dependent "value" field stores MAC address in first 6 bytes
  370. * and zeroes out the remaining bytes.
  371. */
  372. void tipc_l2_media_addr_set(const struct tipc_bearer *b,
  373. struct tipc_media_addr *a, char *mac)
  374. {
  375. int len = b->media->hwaddr_len;
  376. if (unlikely(sizeof(a->value) < len)) {
  377. WARN_ONCE(1, "Media length invalid\n");
  378. return;
  379. }
  380. memcpy(a->value, mac, len);
  381. memset(a->value + len, 0, sizeof(a->value) - len);
  382. a->media_id = b->media->type_id;
  383. a->broadcast = !memcmp(mac, b->bcast_addr.value, len);
  384. }
  385. int tipc_enable_l2_media(struct tipc_bearer *b)
  386. {
  387. struct net_device *dev;
  388. char *driver_name = strchr((const char *)b->name, ':') + 1;
  389. /* Find device with specified name */
  390. dev = dev_get_by_name(&init_net, driver_name);
  391. if (!dev)
  392. return -ENODEV;
  393. /* Associate TIPC bearer with Ethernet bearer */
  394. b->media_ptr = dev;
  395. memset(b->bcast_addr.value, 0, sizeof(b->bcast_addr.value));
  396. memcpy(b->bcast_addr.value, dev->broadcast, b->media->hwaddr_len);
  397. b->bcast_addr.media_id = b->media->type_id;
  398. b->bcast_addr.broadcast = 1;
  399. b->mtu = dev->mtu;
  400. tipc_l2_media_addr_set(b, &b->addr, (char *)dev->dev_addr);
  401. rcu_assign_pointer(dev->tipc_ptr, b);
  402. return 0;
  403. }
  404. /* tipc_disable_l2_media - detach TIPC bearer from an Ethernet interface
  405. *
  406. * Mark Ethernet bearer as inactive so that incoming buffers are thrown away,
  407. * then get worker thread to complete bearer cleanup. (Can't do cleanup
  408. * here because cleanup code needs to sleep and caller holds spinlocks.)
  409. */
  410. void tipc_disable_l2_media(struct tipc_bearer *b)
  411. {
  412. struct net_device *dev = (struct net_device *)b->media_ptr;
  413. RCU_INIT_POINTER(dev->tipc_ptr, NULL);
  414. dev_put(dev);
  415. }
  416. /**
  417. * tipc_l2_send_msg - send a TIPC packet out over an Ethernet interface
  418. * @buf: the packet to be sent
  419. * @b_ptr: the bearer through which the packet is to be sent
  420. * @dest: peer destination address
  421. */
  422. int tipc_l2_send_msg(struct sk_buff *buf, struct tipc_bearer *b,
  423. struct tipc_media_addr *dest)
  424. {
  425. struct sk_buff *clone;
  426. int delta;
  427. struct net_device *dev = (struct net_device *)b->media_ptr;
  428. clone = skb_clone(buf, GFP_ATOMIC);
  429. if (!clone)
  430. return 0;
  431. delta = dev->hard_header_len - skb_headroom(buf);
  432. if ((delta > 0) &&
  433. pskb_expand_head(clone, SKB_DATA_ALIGN(delta), 0, GFP_ATOMIC)) {
  434. kfree_skb(clone);
  435. return 0;
  436. }
  437. skb_reset_network_header(clone);
  438. clone->dev = dev;
  439. clone->protocol = htons(ETH_P_TIPC);
  440. dev_hard_header(clone, dev, ETH_P_TIPC, dest->value,
  441. dev->dev_addr, clone->len);
  442. dev_queue_xmit(clone);
  443. return 0;
  444. }
  445. /* tipc_bearer_send- sends buffer to destination over bearer
  446. *
  447. * IMPORTANT:
  448. * The media send routine must not alter the buffer being passed in
  449. * as it may be needed for later retransmission!
  450. */
  451. void tipc_bearer_send(struct tipc_bearer *b, struct sk_buff *buf,
  452. struct tipc_media_addr *dest)
  453. {
  454. b->media->send_msg(buf, b, dest);
  455. }
  456. /**
  457. * tipc_l2_rcv_msg - handle incoming TIPC message from an interface
  458. * @buf: the received packet
  459. * @dev: the net device that the packet was received on
  460. * @pt: the packet_type structure which was used to register this handler
  461. * @orig_dev: the original receive net device in case the device is a bond
  462. *
  463. * Accept only packets explicitly sent to this node, or broadcast packets;
  464. * ignores packets sent using interface multicast, and traffic sent to other
  465. * nodes (which can happen if interface is running in promiscuous mode).
  466. */
  467. static int tipc_l2_rcv_msg(struct sk_buff *buf, struct net_device *dev,
  468. struct packet_type *pt, struct net_device *orig_dev)
  469. {
  470. struct tipc_bearer *b_ptr;
  471. if (!net_eq(dev_net(dev), &init_net)) {
  472. kfree_skb(buf);
  473. return NET_RX_DROP;
  474. }
  475. rcu_read_lock();
  476. b_ptr = rcu_dereference(dev->tipc_ptr);
  477. if (likely(b_ptr)) {
  478. if (likely(buf->pkt_type <= PACKET_BROADCAST)) {
  479. buf->next = NULL;
  480. tipc_rcv(buf, b_ptr);
  481. rcu_read_unlock();
  482. return NET_RX_SUCCESS;
  483. }
  484. }
  485. rcu_read_unlock();
  486. kfree_skb(buf);
  487. return NET_RX_DROP;
  488. }
  489. /**
  490. * tipc_l2_device_event - handle device events from network device
  491. * @nb: the context of the notification
  492. * @evt: the type of event
  493. * @ptr: the net device that the event was on
  494. *
  495. * This function is called by the Ethernet driver in case of link
  496. * change event.
  497. */
  498. static int tipc_l2_device_event(struct notifier_block *nb, unsigned long evt,
  499. void *ptr)
  500. {
  501. struct tipc_bearer *b_ptr;
  502. struct net_device *dev = netdev_notifier_info_to_dev(ptr);
  503. if (!net_eq(dev_net(dev), &init_net))
  504. return NOTIFY_DONE;
  505. rcu_read_lock();
  506. b_ptr = rcu_dereference(dev->tipc_ptr);
  507. if (!b_ptr) {
  508. rcu_read_unlock();
  509. return NOTIFY_DONE;
  510. }
  511. b_ptr->mtu = dev->mtu;
  512. switch (evt) {
  513. case NETDEV_CHANGE:
  514. if (netif_carrier_ok(dev))
  515. break;
  516. case NETDEV_DOWN:
  517. case NETDEV_CHANGEMTU:
  518. tipc_reset_bearer(b_ptr);
  519. break;
  520. case NETDEV_CHANGEADDR:
  521. tipc_l2_media_addr_set(b_ptr, &b_ptr->addr,
  522. (char *)dev->dev_addr);
  523. tipc_reset_bearer(b_ptr);
  524. break;
  525. case NETDEV_UNREGISTER:
  526. case NETDEV_CHANGENAME:
  527. tipc_disable_bearer(b_ptr->name);
  528. break;
  529. }
  530. rcu_read_unlock();
  531. return NOTIFY_OK;
  532. }
  533. static struct packet_type tipc_packet_type __read_mostly = {
  534. .type = htons(ETH_P_TIPC),
  535. .func = tipc_l2_rcv_msg,
  536. };
  537. static struct notifier_block notifier = {
  538. .notifier_call = tipc_l2_device_event,
  539. .priority = 0,
  540. };
  541. int tipc_bearer_setup(void)
  542. {
  543. int err;
  544. err = register_netdevice_notifier(&notifier);
  545. if (err)
  546. return err;
  547. dev_add_pack(&tipc_packet_type);
  548. return 0;
  549. }
  550. void tipc_bearer_cleanup(void)
  551. {
  552. unregister_netdevice_notifier(&notifier);
  553. dev_remove_pack(&tipc_packet_type);
  554. }
  555. void tipc_bearer_stop(void)
  556. {
  557. struct tipc_bearer *b_ptr;
  558. u32 i;
  559. for (i = 0; i < MAX_BEARERS; i++) {
  560. b_ptr = bearer_list[i];
  561. if (b_ptr) {
  562. bearer_disable(b_ptr, true);
  563. bearer_list[i] = NULL;
  564. }
  565. }
  566. }