bearer.c 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636
  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 tipc_bearers[MAX_BEARERS];
  49. static void bearer_disable(struct tipc_bearer *b_ptr);
  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, b_ptr = tipc_bearers; i < MAX_BEARERS; i++, b_ptr++) {
  158. if (b_ptr->active && (!strcmp(b_ptr->name, name)))
  159. return b_ptr;
  160. }
  161. return NULL;
  162. }
  163. /**
  164. * tipc_bearer_get_names - record names of bearers in buffer
  165. */
  166. struct sk_buff *tipc_bearer_get_names(void)
  167. {
  168. struct sk_buff *buf;
  169. struct tipc_bearer *b;
  170. int i, j;
  171. buf = tipc_cfg_reply_alloc(MAX_BEARERS * TLV_SPACE(TIPC_MAX_BEARER_NAME));
  172. if (!buf)
  173. return NULL;
  174. read_lock_bh(&tipc_net_lock);
  175. for (i = 0; media_info_array[i] != NULL; i++) {
  176. for (j = 0; j < MAX_BEARERS; j++) {
  177. b = &tipc_bearers[j];
  178. if (b->active && (b->media == media_info_array[i])) {
  179. tipc_cfg_append_tlv(buf, TIPC_TLV_BEARER_NAME,
  180. b->name,
  181. strlen(b->name) + 1);
  182. }
  183. }
  184. }
  185. read_unlock_bh(&tipc_net_lock);
  186. return buf;
  187. }
  188. void tipc_bearer_add_dest(struct tipc_bearer *b_ptr, u32 dest)
  189. {
  190. tipc_nmap_add(&b_ptr->nodes, dest);
  191. tipc_bcbearer_sort();
  192. tipc_disc_add_dest(b_ptr->link_req);
  193. }
  194. void tipc_bearer_remove_dest(struct tipc_bearer *b_ptr, u32 dest)
  195. {
  196. tipc_nmap_remove(&b_ptr->nodes, dest);
  197. tipc_bcbearer_sort();
  198. tipc_disc_remove_dest(b_ptr->link_req);
  199. }
  200. /**
  201. * tipc_enable_bearer - enable bearer with the given name
  202. */
  203. int tipc_enable_bearer(const char *name, u32 disc_domain, u32 priority)
  204. {
  205. struct tipc_bearer *b_ptr;
  206. struct tipc_media *m_ptr;
  207. struct tipc_bearer_names b_names;
  208. char addr_string[16];
  209. u32 bearer_id;
  210. u32 with_this_prio;
  211. u32 i;
  212. int res = -EINVAL;
  213. if (!tipc_own_addr) {
  214. pr_warn("Bearer <%s> rejected, not supported in standalone mode\n",
  215. name);
  216. return -ENOPROTOOPT;
  217. }
  218. if (!bearer_name_validate(name, &b_names)) {
  219. pr_warn("Bearer <%s> rejected, illegal name\n", name);
  220. return -EINVAL;
  221. }
  222. if (tipc_addr_domain_valid(disc_domain) &&
  223. (disc_domain != tipc_own_addr)) {
  224. if (tipc_in_scope(disc_domain, tipc_own_addr)) {
  225. disc_domain = tipc_own_addr & TIPC_CLUSTER_MASK;
  226. res = 0; /* accept any node in own cluster */
  227. } else if (in_own_cluster_exact(disc_domain))
  228. res = 0; /* accept specified node in own cluster */
  229. }
  230. if (res) {
  231. pr_warn("Bearer <%s> rejected, illegal discovery domain\n",
  232. name);
  233. return -EINVAL;
  234. }
  235. if ((priority > TIPC_MAX_LINK_PRI) &&
  236. (priority != TIPC_MEDIA_LINK_PRI)) {
  237. pr_warn("Bearer <%s> rejected, illegal priority\n", name);
  238. return -EINVAL;
  239. }
  240. write_lock_bh(&tipc_net_lock);
  241. m_ptr = tipc_media_find(b_names.media_name);
  242. if (!m_ptr) {
  243. pr_warn("Bearer <%s> rejected, media <%s> not registered\n",
  244. name, b_names.media_name);
  245. goto exit;
  246. }
  247. if (priority == TIPC_MEDIA_LINK_PRI)
  248. priority = m_ptr->priority;
  249. restart:
  250. bearer_id = MAX_BEARERS;
  251. with_this_prio = 1;
  252. for (i = MAX_BEARERS; i-- != 0; ) {
  253. if (!tipc_bearers[i].active) {
  254. bearer_id = i;
  255. continue;
  256. }
  257. if (!strcmp(name, tipc_bearers[i].name)) {
  258. pr_warn("Bearer <%s> rejected, already enabled\n",
  259. name);
  260. goto exit;
  261. }
  262. if ((tipc_bearers[i].priority == priority) &&
  263. (++with_this_prio > 2)) {
  264. if (priority-- == 0) {
  265. pr_warn("Bearer <%s> rejected, duplicate priority\n",
  266. name);
  267. goto exit;
  268. }
  269. pr_warn("Bearer <%s> priority adjustment required %u->%u\n",
  270. name, priority + 1, priority);
  271. goto restart;
  272. }
  273. }
  274. if (bearer_id >= MAX_BEARERS) {
  275. pr_warn("Bearer <%s> rejected, bearer limit reached (%u)\n",
  276. name, MAX_BEARERS);
  277. goto exit;
  278. }
  279. b_ptr = &tipc_bearers[bearer_id];
  280. strcpy(b_ptr->name, name);
  281. b_ptr->media = m_ptr;
  282. res = m_ptr->enable_media(b_ptr);
  283. if (res) {
  284. pr_warn("Bearer <%s> rejected, enable failure (%d)\n",
  285. name, -res);
  286. goto exit;
  287. }
  288. b_ptr->identity = bearer_id;
  289. b_ptr->tolerance = m_ptr->tolerance;
  290. b_ptr->window = m_ptr->window;
  291. b_ptr->net_plane = bearer_id + 'A';
  292. b_ptr->active = 1;
  293. b_ptr->priority = priority;
  294. INIT_LIST_HEAD(&b_ptr->links);
  295. spin_lock_init(&b_ptr->lock);
  296. res = tipc_disc_create(b_ptr, &b_ptr->bcast_addr, disc_domain);
  297. if (res) {
  298. bearer_disable(b_ptr);
  299. pr_warn("Bearer <%s> rejected, discovery object creation failed\n",
  300. name);
  301. goto exit;
  302. }
  303. pr_info("Enabled bearer <%s>, discovery domain %s, priority %u\n",
  304. name,
  305. tipc_addr_string_fill(addr_string, disc_domain), priority);
  306. exit:
  307. write_unlock_bh(&tipc_net_lock);
  308. return res;
  309. }
  310. /**
  311. * tipc_reset_bearer - Reset all links established over this bearer
  312. */
  313. static int tipc_reset_bearer(struct tipc_bearer *b_ptr)
  314. {
  315. struct tipc_link *l_ptr;
  316. struct tipc_link *temp_l_ptr;
  317. read_lock_bh(&tipc_net_lock);
  318. pr_info("Resetting bearer <%s>\n", b_ptr->name);
  319. spin_lock_bh(&b_ptr->lock);
  320. list_for_each_entry_safe(l_ptr, temp_l_ptr, &b_ptr->links, link_list) {
  321. struct tipc_node *n_ptr = l_ptr->owner;
  322. spin_lock_bh(&n_ptr->lock);
  323. tipc_link_reset(l_ptr);
  324. spin_unlock_bh(&n_ptr->lock);
  325. }
  326. spin_unlock_bh(&b_ptr->lock);
  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)
  336. {
  337. struct tipc_link *l_ptr;
  338. struct tipc_link *temp_l_ptr;
  339. struct tipc_link_req *temp_req;
  340. pr_info("Disabling bearer <%s>\n", b_ptr->name);
  341. spin_lock_bh(&b_ptr->lock);
  342. b_ptr->media->disable_media(b_ptr);
  343. list_for_each_entry_safe(l_ptr, temp_l_ptr, &b_ptr->links, link_list) {
  344. tipc_link_delete(l_ptr);
  345. }
  346. temp_req = b_ptr->link_req;
  347. b_ptr->link_req = NULL;
  348. spin_unlock_bh(&b_ptr->lock);
  349. if (temp_req)
  350. tipc_disc_delete(temp_req);
  351. memset(b_ptr, 0, sizeof(struct tipc_bearer));
  352. }
  353. int tipc_disable_bearer(const char *name)
  354. {
  355. struct tipc_bearer *b_ptr;
  356. int res;
  357. write_lock_bh(&tipc_net_lock);
  358. b_ptr = tipc_bearer_find(name);
  359. if (b_ptr == NULL) {
  360. pr_warn("Attempt to disable unknown bearer <%s>\n", name);
  361. res = -EINVAL;
  362. } else {
  363. bearer_disable(b_ptr);
  364. res = 0;
  365. }
  366. write_unlock_bh(&tipc_net_lock);
  367. return res;
  368. }
  369. /* tipc_l2_media_addr_set - initialize Ethernet media address structure
  370. *
  371. * Media-dependent "value" field stores MAC address in first 6 bytes
  372. * and zeroes out the remaining bytes.
  373. */
  374. void tipc_l2_media_addr_set(const struct tipc_bearer *b,
  375. struct tipc_media_addr *a, char *mac)
  376. {
  377. int len = b->media->hwaddr_len;
  378. if (unlikely(sizeof(a->value) < len)) {
  379. WARN_ONCE(1, "Media length invalid\n");
  380. return;
  381. }
  382. memcpy(a->value, mac, len);
  383. memset(a->value + len, 0, sizeof(a->value) - len);
  384. a->media_id = b->media->type_id;
  385. a->broadcast = !memcmp(mac, b->bcast_addr.value, len);
  386. }
  387. int tipc_enable_l2_media(struct tipc_bearer *b)
  388. {
  389. struct net_device *dev;
  390. char *driver_name = strchr((const char *)b->name, ':') + 1;
  391. /* Find device with specified name */
  392. dev = dev_get_by_name(&init_net, driver_name);
  393. if (!dev)
  394. return -ENODEV;
  395. /* Associate TIPC bearer with Ethernet bearer */
  396. b->media_ptr = dev;
  397. memset(b->bcast_addr.value, 0, sizeof(b->bcast_addr.value));
  398. memcpy(b->bcast_addr.value, dev->broadcast, b->media->hwaddr_len);
  399. b->bcast_addr.media_id = b->media->type_id;
  400. b->bcast_addr.broadcast = 1;
  401. b->mtu = dev->mtu;
  402. tipc_l2_media_addr_set(b, &b->addr, (char *)dev->dev_addr);
  403. rcu_assign_pointer(dev->tipc_ptr, b);
  404. return 0;
  405. }
  406. /* tipc_disable_l2_media - detach TIPC bearer from an Ethernet interface
  407. *
  408. * Mark Ethernet bearer as inactive so that incoming buffers are thrown away,
  409. * then get worker thread to complete bearer cleanup. (Can't do cleanup
  410. * here because cleanup code needs to sleep and caller holds spinlocks.)
  411. */
  412. void tipc_disable_l2_media(struct tipc_bearer *b)
  413. {
  414. struct net_device *dev = (struct net_device *)b->media_ptr;
  415. RCU_INIT_POINTER(dev->tipc_ptr, NULL);
  416. dev_put(dev);
  417. }
  418. /**
  419. * tipc_l2_send_msg - send a TIPC packet out over an Ethernet interface
  420. * @buf: the packet to be sent
  421. * @b_ptr: the bearer through which the packet is to be sent
  422. * @dest: peer destination address
  423. */
  424. int tipc_l2_send_msg(struct sk_buff *buf, struct tipc_bearer *b,
  425. struct tipc_media_addr *dest)
  426. {
  427. struct sk_buff *clone;
  428. int delta;
  429. struct net_device *dev = (struct net_device *)b->media_ptr;
  430. clone = skb_clone(buf, GFP_ATOMIC);
  431. if (!clone)
  432. return 0;
  433. delta = dev->hard_header_len - skb_headroom(buf);
  434. if ((delta > 0) &&
  435. pskb_expand_head(clone, SKB_DATA_ALIGN(delta), 0, GFP_ATOMIC)) {
  436. kfree_skb(clone);
  437. return 0;
  438. }
  439. skb_reset_network_header(clone);
  440. clone->dev = dev;
  441. clone->protocol = htons(ETH_P_TIPC);
  442. dev_hard_header(clone, dev, ETH_P_TIPC, dest->value,
  443. dev->dev_addr, clone->len);
  444. dev_queue_xmit(clone);
  445. return 0;
  446. }
  447. /* tipc_bearer_send- sends buffer to destination over bearer
  448. *
  449. * IMPORTANT:
  450. * The media send routine must not alter the buffer being passed in
  451. * as it may be needed for later retransmission!
  452. */
  453. void tipc_bearer_send(struct tipc_bearer *b, struct sk_buff *buf,
  454. struct tipc_media_addr *dest)
  455. {
  456. b->media->send_msg(buf, b, dest);
  457. }
  458. /**
  459. * tipc_l2_rcv_msg - handle incoming TIPC message from an interface
  460. * @buf: the received packet
  461. * @dev: the net device that the packet was received on
  462. * @pt: the packet_type structure which was used to register this handler
  463. * @orig_dev: the original receive net device in case the device is a bond
  464. *
  465. * Accept only packets explicitly sent to this node, or broadcast packets;
  466. * ignores packets sent using interface multicast, and traffic sent to other
  467. * nodes (which can happen if interface is running in promiscuous mode).
  468. */
  469. static int tipc_l2_rcv_msg(struct sk_buff *buf, struct net_device *dev,
  470. struct packet_type *pt, struct net_device *orig_dev)
  471. {
  472. struct tipc_bearer *b_ptr;
  473. if (!net_eq(dev_net(dev), &init_net)) {
  474. kfree_skb(buf);
  475. return NET_RX_DROP;
  476. }
  477. rcu_read_lock();
  478. b_ptr = rcu_dereference(dev->tipc_ptr);
  479. if (likely(b_ptr)) {
  480. if (likely(buf->pkt_type <= PACKET_BROADCAST)) {
  481. buf->next = NULL;
  482. tipc_rcv(buf, b_ptr);
  483. rcu_read_unlock();
  484. return NET_RX_SUCCESS;
  485. }
  486. }
  487. rcu_read_unlock();
  488. kfree_skb(buf);
  489. return NET_RX_DROP;
  490. }
  491. /**
  492. * tipc_l2_device_event - handle device events from network device
  493. * @nb: the context of the notification
  494. * @evt: the type of event
  495. * @ptr: the net device that the event was on
  496. *
  497. * This function is called by the Ethernet driver in case of link
  498. * change event.
  499. */
  500. static int tipc_l2_device_event(struct notifier_block *nb, unsigned long evt,
  501. void *ptr)
  502. {
  503. struct tipc_bearer *b_ptr;
  504. struct net_device *dev = netdev_notifier_info_to_dev(ptr);
  505. if (!net_eq(dev_net(dev), &init_net))
  506. return NOTIFY_DONE;
  507. rcu_read_lock();
  508. b_ptr = rcu_dereference(dev->tipc_ptr);
  509. if (!b_ptr) {
  510. rcu_read_unlock();
  511. return NOTIFY_DONE;
  512. }
  513. b_ptr->mtu = dev->mtu;
  514. switch (evt) {
  515. case NETDEV_CHANGE:
  516. if (netif_carrier_ok(dev))
  517. break;
  518. case NETDEV_DOWN:
  519. case NETDEV_CHANGEMTU:
  520. case NETDEV_CHANGEADDR:
  521. tipc_reset_bearer(b_ptr);
  522. break;
  523. case NETDEV_UNREGISTER:
  524. case NETDEV_CHANGENAME:
  525. tipc_disable_bearer(b_ptr->name);
  526. break;
  527. }
  528. rcu_read_unlock();
  529. return NOTIFY_OK;
  530. }
  531. static struct packet_type tipc_packet_type __read_mostly = {
  532. .type = __constant_htons(ETH_P_TIPC),
  533. .func = tipc_l2_rcv_msg,
  534. };
  535. static struct notifier_block notifier = {
  536. .notifier_call = tipc_l2_device_event,
  537. .priority = 0,
  538. };
  539. int tipc_bearer_setup(void)
  540. {
  541. int err;
  542. err = register_netdevice_notifier(&notifier);
  543. if (err)
  544. return err;
  545. dev_add_pack(&tipc_packet_type);
  546. return 0;
  547. }
  548. void tipc_bearer_cleanup(void)
  549. {
  550. unregister_netdevice_notifier(&notifier);
  551. dev_remove_pack(&tipc_packet_type);
  552. }
  553. void tipc_bearer_stop(void)
  554. {
  555. u32 i;
  556. for (i = 0; i < MAX_BEARERS; i++) {
  557. if (tipc_bearers[i].active)
  558. bearer_disable(&tipc_bearers[i]);
  559. }
  560. }