bcast.c 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803
  1. /*
  2. * net/tipc/bcast.c: TIPC broadcast code
  3. *
  4. * Copyright (c) 2003-2005, Ericsson Research Canada
  5. * Copyright (c) 2004, Intel Corporation.
  6. * Copyright (c) 2005, Wind River Systems
  7. * Copyright (c) 2005-2006, Ericsson AB
  8. * All rights reserved.
  9. *
  10. * Redistribution and use in source and binary forms, with or without
  11. * modification, are permitted provided that the following conditions are met:
  12. *
  13. * Redistributions of source code must retain the above copyright notice, this
  14. * list of conditions and the following disclaimer.
  15. * Redistributions in binary form must reproduce the above copyright notice,
  16. * this list of conditions and the following disclaimer in the documentation
  17. * and/or other materials provided with the distribution.
  18. * Neither the names of the copyright holders nor the names of its
  19. * contributors may be used to endorse or promote products derived from this
  20. * software without specific prior written permission.
  21. *
  22. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  23. * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  24. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  25. * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
  26. * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
  27. * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
  28. * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
  29. * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
  30. * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  31. * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  32. * POSSIBILITY OF SUCH DAMAGE.
  33. */
  34. #include "core.h"
  35. #include "msg.h"
  36. #include "dbg.h"
  37. #include "link.h"
  38. #include "net.h"
  39. #include "node.h"
  40. #include "port.h"
  41. #include "addr.h"
  42. #include "node_subscr.h"
  43. #include "name_distr.h"
  44. #include "bearer.h"
  45. #include "name_table.h"
  46. #include "bcast.h"
  47. #define MAX_PKT_DEFAULT_MCAST 1500 /* bcast link max packet size (fixed) */
  48. #define BCLINK_WIN_DEFAULT 20 /* bcast link window size (default) */
  49. #define BCLINK_LOG_BUF_SIZE 0
  50. /**
  51. * struct bcbearer_pair - a pair of bearers used by broadcast link
  52. * @primary: pointer to primary bearer
  53. * @secondary: pointer to secondary bearer
  54. *
  55. * Bearers must have same priority and same set of reachable destinations
  56. * to be paired.
  57. */
  58. struct bcbearer_pair {
  59. struct bearer *primary;
  60. struct bearer *secondary;
  61. };
  62. /**
  63. * struct bcbearer - bearer used by broadcast link
  64. * @bearer: (non-standard) broadcast bearer structure
  65. * @media: (non-standard) broadcast media structure
  66. * @bpairs: array of bearer pairs
  67. * @bpairs_temp: array of bearer pairs used during creation of "bpairs"
  68. */
  69. struct bcbearer {
  70. struct bearer bearer;
  71. struct media media;
  72. struct bcbearer_pair bpairs[MAX_BEARERS];
  73. struct bcbearer_pair bpairs_temp[TIPC_NUM_LINK_PRI];
  74. };
  75. /**
  76. * struct bclink - link used for broadcast messages
  77. * @link: (non-standard) broadcast link structure
  78. * @node: (non-standard) node structure representing b'cast link's peer node
  79. *
  80. * Handles sequence numbering, fragmentation, bundling, etc.
  81. */
  82. struct bclink {
  83. struct link link;
  84. struct node node;
  85. };
  86. static struct bcbearer *bcbearer = NULL;
  87. static struct bclink *bclink = NULL;
  88. static struct link *bcl = NULL;
  89. static spinlock_t bc_lock = SPIN_LOCK_UNLOCKED;
  90. char bc_link_name[] = "multicast-link";
  91. static inline u32 buf_seqno(struct sk_buff *buf)
  92. {
  93. return msg_seqno(buf_msg(buf));
  94. }
  95. static inline u32 bcbuf_acks(struct sk_buff *buf)
  96. {
  97. return (u32)TIPC_SKB_CB(buf)->handle;
  98. }
  99. static inline void bcbuf_set_acks(struct sk_buff *buf, u32 acks)
  100. {
  101. TIPC_SKB_CB(buf)->handle = (void *)acks;
  102. }
  103. static inline void bcbuf_decr_acks(struct sk_buff *buf)
  104. {
  105. bcbuf_set_acks(buf, bcbuf_acks(buf) - 1);
  106. }
  107. /**
  108. * bclink_set_gap - set gap according to contents of current deferred pkt queue
  109. *
  110. * Called with 'node' locked, bc_lock unlocked
  111. */
  112. static inline void bclink_set_gap(struct node *n_ptr)
  113. {
  114. struct sk_buff *buf = n_ptr->bclink.deferred_head;
  115. n_ptr->bclink.gap_after = n_ptr->bclink.gap_to =
  116. mod(n_ptr->bclink.last_in);
  117. if (unlikely(buf != NULL))
  118. n_ptr->bclink.gap_to = mod(buf_seqno(buf) - 1);
  119. }
  120. /**
  121. * bclink_ack_allowed - test if ACK or NACK message can be sent at this moment
  122. *
  123. * This mechanism endeavours to prevent all nodes in network from trying
  124. * to ACK or NACK at the same time.
  125. *
  126. * Note: TIPC uses a different trigger to distribute ACKs than it does to
  127. * distribute NACKs, but tries to use the same spacing (divide by 16).
  128. */
  129. static inline int bclink_ack_allowed(u32 n)
  130. {
  131. return((n % TIPC_MIN_LINK_WIN) == tipc_own_tag);
  132. }
  133. /**
  134. * bclink_retransmit_pkt - retransmit broadcast packets
  135. * @after: sequence number of last packet to *not* retransmit
  136. * @to: sequence number of last packet to retransmit
  137. *
  138. * Called with 'node' locked, bc_lock unlocked
  139. */
  140. static void bclink_retransmit_pkt(u32 after, u32 to)
  141. {
  142. struct sk_buff *buf;
  143. spin_lock_bh(&bc_lock);
  144. buf = bcl->first_out;
  145. while (buf && less_eq(buf_seqno(buf), after)) {
  146. buf = buf->next;
  147. }
  148. if (buf != NULL)
  149. link_retransmit(bcl, buf, mod(to - after));
  150. spin_unlock_bh(&bc_lock);
  151. }
  152. /**
  153. * bclink_acknowledge - handle acknowledgement of broadcast packets
  154. * @n_ptr: node that sent acknowledgement info
  155. * @acked: broadcast sequence # that has been acknowledged
  156. *
  157. * Node is locked, bc_lock unlocked.
  158. */
  159. void bclink_acknowledge(struct node *n_ptr, u32 acked)
  160. {
  161. struct sk_buff *crs;
  162. struct sk_buff *next;
  163. unsigned int released = 0;
  164. if (less_eq(acked, n_ptr->bclink.acked))
  165. return;
  166. spin_lock_bh(&bc_lock);
  167. /* Skip over packets that node has previously acknowledged */
  168. crs = bcl->first_out;
  169. while (crs && less_eq(buf_seqno(crs), n_ptr->bclink.acked)) {
  170. crs = crs->next;
  171. }
  172. /* Update packets that node is now acknowledging */
  173. while (crs && less_eq(buf_seqno(crs), acked)) {
  174. next = crs->next;
  175. bcbuf_decr_acks(crs);
  176. if (bcbuf_acks(crs) == 0) {
  177. bcl->first_out = next;
  178. bcl->out_queue_size--;
  179. buf_discard(crs);
  180. released = 1;
  181. }
  182. crs = next;
  183. }
  184. n_ptr->bclink.acked = acked;
  185. /* Try resolving broadcast link congestion, if necessary */
  186. if (unlikely(bcl->next_out))
  187. link_push_queue(bcl);
  188. if (unlikely(released && !list_empty(&bcl->waiting_ports)))
  189. link_wakeup_ports(bcl, 0);
  190. spin_unlock_bh(&bc_lock);
  191. }
  192. /**
  193. * bclink_send_ack - unicast an ACK msg
  194. *
  195. * net_lock and node lock set
  196. */
  197. static void bclink_send_ack(struct node *n_ptr)
  198. {
  199. struct link *l_ptr = n_ptr->active_links[n_ptr->addr & 1];
  200. if (l_ptr != NULL)
  201. link_send_proto_msg(l_ptr, STATE_MSG, 0, 0, 0, 0, 0);
  202. }
  203. /**
  204. * bclink_send_nack- broadcast a NACK msg
  205. *
  206. * net_lock and node lock set
  207. */
  208. static void bclink_send_nack(struct node *n_ptr)
  209. {
  210. struct sk_buff *buf;
  211. struct tipc_msg *msg;
  212. if (!less(n_ptr->bclink.gap_after, n_ptr->bclink.gap_to))
  213. return;
  214. buf = buf_acquire(INT_H_SIZE);
  215. if (buf) {
  216. msg = buf_msg(buf);
  217. msg_init(msg, BCAST_PROTOCOL, STATE_MSG,
  218. TIPC_OK, INT_H_SIZE, n_ptr->addr);
  219. msg_set_mc_netid(msg, tipc_net_id);
  220. msg_set_bcast_ack(msg, mod(n_ptr->bclink.last_in));
  221. msg_set_bcgap_after(msg, n_ptr->bclink.gap_after);
  222. msg_set_bcgap_to(msg, n_ptr->bclink.gap_to);
  223. msg_set_bcast_tag(msg, tipc_own_tag);
  224. if (bearer_send(&bcbearer->bearer, buf, 0)) {
  225. bcl->stats.sent_nacks++;
  226. buf_discard(buf);
  227. } else {
  228. bearer_schedule(bcl->b_ptr, bcl);
  229. bcl->proto_msg_queue = buf;
  230. bcl->stats.bearer_congs++;
  231. }
  232. /*
  233. * Ensure we doesn't send another NACK msg to the node
  234. * until 16 more deferred messages arrive from it
  235. * (i.e. helps prevent all nodes from NACK'ing at same time)
  236. */
  237. n_ptr->bclink.nack_sync = tipc_own_tag;
  238. }
  239. }
  240. /**
  241. * bclink_check_gap - send a NACK if a sequence gap exists
  242. *
  243. * net_lock and node lock set
  244. */
  245. void bclink_check_gap(struct node *n_ptr, u32 last_sent)
  246. {
  247. if (!n_ptr->bclink.supported ||
  248. less_eq(last_sent, mod(n_ptr->bclink.last_in)))
  249. return;
  250. bclink_set_gap(n_ptr);
  251. if (n_ptr->bclink.gap_after == n_ptr->bclink.gap_to)
  252. n_ptr->bclink.gap_to = last_sent;
  253. bclink_send_nack(n_ptr);
  254. }
  255. /**
  256. * bclink_peek_nack - process a NACK msg meant for another node
  257. *
  258. * Only net_lock set.
  259. */
  260. void bclink_peek_nack(u32 dest, u32 sender_tag, u32 gap_after, u32 gap_to)
  261. {
  262. struct node *n_ptr = node_find(dest);
  263. u32 my_after, my_to;
  264. if (unlikely(!n_ptr || !node_is_up(n_ptr)))
  265. return;
  266. node_lock(n_ptr);
  267. /*
  268. * Modify gap to suppress unnecessary NACKs from this node
  269. */
  270. my_after = n_ptr->bclink.gap_after;
  271. my_to = n_ptr->bclink.gap_to;
  272. if (less_eq(gap_after, my_after)) {
  273. if (less(my_after, gap_to) && less(gap_to, my_to))
  274. n_ptr->bclink.gap_after = gap_to;
  275. else if (less_eq(my_to, gap_to))
  276. n_ptr->bclink.gap_to = n_ptr->bclink.gap_after;
  277. } else if (less_eq(gap_after, my_to)) {
  278. if (less_eq(my_to, gap_to))
  279. n_ptr->bclink.gap_to = gap_after;
  280. } else {
  281. /*
  282. * Expand gap if missing bufs not in deferred queue:
  283. */
  284. struct sk_buff *buf = n_ptr->bclink.deferred_head;
  285. u32 prev = n_ptr->bclink.gap_to;
  286. for (; buf; buf = buf->next) {
  287. u32 seqno = buf_seqno(buf);
  288. if (mod(seqno - prev) != 1)
  289. buf = NULL;
  290. if (seqno == gap_after)
  291. break;
  292. prev = seqno;
  293. }
  294. if (buf == NULL)
  295. n_ptr->bclink.gap_to = gap_after;
  296. }
  297. /*
  298. * Some nodes may send a complementary NACK now:
  299. */
  300. if (bclink_ack_allowed(sender_tag + 1)) {
  301. if (n_ptr->bclink.gap_to != n_ptr->bclink.gap_after) {
  302. bclink_send_nack(n_ptr);
  303. bclink_set_gap(n_ptr);
  304. }
  305. }
  306. node_unlock(n_ptr);
  307. }
  308. /**
  309. * bclink_send_msg - broadcast a packet to all nodes in cluster
  310. */
  311. int bclink_send_msg(struct sk_buff *buf)
  312. {
  313. int res;
  314. spin_lock_bh(&bc_lock);
  315. res = link_send_buf(bcl, buf);
  316. if (unlikely(res == -ELINKCONG))
  317. buf_discard(buf);
  318. else
  319. bcl->stats.sent_info++;
  320. if (bcl->out_queue_size > bcl->stats.max_queue_sz)
  321. bcl->stats.max_queue_sz = bcl->out_queue_size;
  322. bcl->stats.queue_sz_counts++;
  323. bcl->stats.accu_queue_sz += bcl->out_queue_size;
  324. spin_unlock_bh(&bc_lock);
  325. return res;
  326. }
  327. /**
  328. * bclink_recv_pkt - receive a broadcast packet, and deliver upwards
  329. *
  330. * net_lock is read_locked, no other locks set
  331. */
  332. void bclink_recv_pkt(struct sk_buff *buf)
  333. {
  334. struct tipc_msg *msg = buf_msg(buf);
  335. struct node* node = node_find(msg_prevnode(msg));
  336. u32 next_in;
  337. u32 seqno;
  338. struct sk_buff *deferred;
  339. msg_dbg(msg, "<BC<<<");
  340. if (unlikely(!node || !node_is_up(node) || !node->bclink.supported ||
  341. (msg_mc_netid(msg) != tipc_net_id))) {
  342. buf_discard(buf);
  343. return;
  344. }
  345. if (unlikely(msg_user(msg) == BCAST_PROTOCOL)) {
  346. msg_dbg(msg, "<BCNACK<<<");
  347. if (msg_destnode(msg) == tipc_own_addr) {
  348. node_lock(node);
  349. bclink_acknowledge(node, msg_bcast_ack(msg));
  350. node_unlock(node);
  351. bcl->stats.recv_nacks++;
  352. bclink_retransmit_pkt(msg_bcgap_after(msg),
  353. msg_bcgap_to(msg));
  354. } else {
  355. bclink_peek_nack(msg_destnode(msg),
  356. msg_bcast_tag(msg),
  357. msg_bcgap_after(msg),
  358. msg_bcgap_to(msg));
  359. }
  360. buf_discard(buf);
  361. return;
  362. }
  363. node_lock(node);
  364. receive:
  365. deferred = node->bclink.deferred_head;
  366. next_in = mod(node->bclink.last_in + 1);
  367. seqno = msg_seqno(msg);
  368. if (likely(seqno == next_in)) {
  369. bcl->stats.recv_info++;
  370. node->bclink.last_in++;
  371. bclink_set_gap(node);
  372. if (unlikely(bclink_ack_allowed(seqno))) {
  373. bclink_send_ack(node);
  374. bcl->stats.sent_acks++;
  375. }
  376. if (likely(msg_isdata(msg))) {
  377. node_unlock(node);
  378. port_recv_mcast(buf, NULL);
  379. } else if (msg_user(msg) == MSG_BUNDLER) {
  380. bcl->stats.recv_bundles++;
  381. bcl->stats.recv_bundled += msg_msgcnt(msg);
  382. node_unlock(node);
  383. link_recv_bundle(buf);
  384. } else if (msg_user(msg) == MSG_FRAGMENTER) {
  385. bcl->stats.recv_fragments++;
  386. if (link_recv_fragment(&node->bclink.defragm,
  387. &buf, &msg))
  388. bcl->stats.recv_fragmented++;
  389. node_unlock(node);
  390. net_route_msg(buf);
  391. } else {
  392. node_unlock(node);
  393. net_route_msg(buf);
  394. }
  395. if (deferred && (buf_seqno(deferred) == mod(next_in + 1))) {
  396. node_lock(node);
  397. buf = deferred;
  398. msg = buf_msg(buf);
  399. node->bclink.deferred_head = deferred->next;
  400. goto receive;
  401. }
  402. return;
  403. } else if (less(next_in, seqno)) {
  404. u32 gap_after = node->bclink.gap_after;
  405. u32 gap_to = node->bclink.gap_to;
  406. if (link_defer_pkt(&node->bclink.deferred_head,
  407. &node->bclink.deferred_tail,
  408. buf)) {
  409. node->bclink.nack_sync++;
  410. bcl->stats.deferred_recv++;
  411. if (seqno == mod(gap_after + 1))
  412. node->bclink.gap_after = seqno;
  413. else if (less(gap_after, seqno) && less(seqno, gap_to))
  414. node->bclink.gap_to = seqno;
  415. }
  416. if (bclink_ack_allowed(node->bclink.nack_sync)) {
  417. if (gap_to != gap_after)
  418. bclink_send_nack(node);
  419. bclink_set_gap(node);
  420. }
  421. } else {
  422. bcl->stats.duplicates++;
  423. buf_discard(buf);
  424. }
  425. node_unlock(node);
  426. }
  427. u32 bclink_get_last_sent(void)
  428. {
  429. u32 last_sent = mod(bcl->next_out_no - 1);
  430. if (bcl->next_out)
  431. last_sent = mod(buf_seqno(bcl->next_out) - 1);
  432. return last_sent;
  433. }
  434. u32 bclink_acks_missing(struct node *n_ptr)
  435. {
  436. return (n_ptr->bclink.supported &&
  437. (bclink_get_last_sent() != n_ptr->bclink.acked));
  438. }
  439. /**
  440. * bcbearer_send - send a packet through the broadcast pseudo-bearer
  441. *
  442. * Send through as many bearers as necessary to reach all nodes
  443. * that support TIPC multicasting.
  444. *
  445. * Returns 0 if packet sent successfully, non-zero if not
  446. */
  447. int bcbearer_send(struct sk_buff *buf,
  448. struct tipc_bearer *unused1,
  449. struct tipc_media_addr *unused2)
  450. {
  451. static int send_count = 0;
  452. struct node_map remains;
  453. struct node_map remains_new;
  454. int bp_index;
  455. int swap_time;
  456. /* Prepare buffer for broadcasting (if first time trying to send it) */
  457. if (likely(!msg_non_seq(buf_msg(buf)))) {
  458. struct tipc_msg *msg;
  459. assert(cluster_bcast_nodes.count != 0);
  460. bcbuf_set_acks(buf, cluster_bcast_nodes.count);
  461. msg = buf_msg(buf);
  462. msg_set_non_seq(msg);
  463. msg_set_mc_netid(msg, tipc_net_id);
  464. }
  465. /* Determine if bearer pairs should be swapped following this attempt */
  466. if ((swap_time = (++send_count >= 10)))
  467. send_count = 0;
  468. /* Send buffer over bearers until all targets reached */
  469. remains = cluster_bcast_nodes;
  470. for (bp_index = 0; bp_index < MAX_BEARERS; bp_index++) {
  471. struct bearer *p = bcbearer->bpairs[bp_index].primary;
  472. struct bearer *s = bcbearer->bpairs[bp_index].secondary;
  473. if (!p)
  474. break; /* no more bearers to try */
  475. nmap_diff(&remains, &p->nodes, &remains_new);
  476. if (remains_new.count == remains.count)
  477. continue; /* bearer pair doesn't add anything */
  478. if (!p->publ.blocked &&
  479. !p->media->send_msg(buf, &p->publ, &p->media->bcast_addr)) {
  480. if (swap_time && s && !s->publ.blocked)
  481. goto swap;
  482. else
  483. goto update;
  484. }
  485. if (!s || s->publ.blocked ||
  486. s->media->send_msg(buf, &s->publ, &s->media->bcast_addr))
  487. continue; /* unable to send using bearer pair */
  488. swap:
  489. bcbearer->bpairs[bp_index].primary = s;
  490. bcbearer->bpairs[bp_index].secondary = p;
  491. update:
  492. if (remains_new.count == 0)
  493. return TIPC_OK;
  494. remains = remains_new;
  495. }
  496. /* Unable to reach all targets */
  497. bcbearer->bearer.publ.blocked = 1;
  498. bcl->stats.bearer_congs++;
  499. return ~TIPC_OK;
  500. }
  501. /**
  502. * bcbearer_sort - create sets of bearer pairs used by broadcast bearer
  503. */
  504. void bcbearer_sort(void)
  505. {
  506. struct bcbearer_pair *bp_temp = bcbearer->bpairs_temp;
  507. struct bcbearer_pair *bp_curr;
  508. int b_index;
  509. int pri;
  510. spin_lock_bh(&bc_lock);
  511. /* Group bearers by priority (can assume max of two per priority) */
  512. memset(bp_temp, 0, sizeof(bcbearer->bpairs_temp));
  513. for (b_index = 0; b_index < MAX_BEARERS; b_index++) {
  514. struct bearer *b = &bearers[b_index];
  515. if (!b->active || !b->nodes.count)
  516. continue;
  517. if (!bp_temp[b->priority].primary)
  518. bp_temp[b->priority].primary = b;
  519. else
  520. bp_temp[b->priority].secondary = b;
  521. }
  522. /* Create array of bearer pairs for broadcasting */
  523. bp_curr = bcbearer->bpairs;
  524. memset(bcbearer->bpairs, 0, sizeof(bcbearer->bpairs));
  525. for (pri = (TIPC_NUM_LINK_PRI - 1); pri >= 0; pri--) {
  526. if (!bp_temp[pri].primary)
  527. continue;
  528. bp_curr->primary = bp_temp[pri].primary;
  529. if (bp_temp[pri].secondary) {
  530. if (nmap_equal(&bp_temp[pri].primary->nodes,
  531. &bp_temp[pri].secondary->nodes)) {
  532. bp_curr->secondary = bp_temp[pri].secondary;
  533. } else {
  534. bp_curr++;
  535. bp_curr->primary = bp_temp[pri].secondary;
  536. }
  537. }
  538. bp_curr++;
  539. }
  540. spin_unlock_bh(&bc_lock);
  541. }
  542. /**
  543. * bcbearer_push - resolve bearer congestion
  544. *
  545. * Forces bclink to push out any unsent packets, until all packets are gone
  546. * or congestion reoccurs.
  547. * No locks set when function called
  548. */
  549. void bcbearer_push(void)
  550. {
  551. struct bearer *b_ptr;
  552. spin_lock_bh(&bc_lock);
  553. b_ptr = &bcbearer->bearer;
  554. if (b_ptr->publ.blocked) {
  555. b_ptr->publ.blocked = 0;
  556. bearer_lock_push(b_ptr);
  557. }
  558. spin_unlock_bh(&bc_lock);
  559. }
  560. int bclink_stats(char *buf, const u32 buf_size)
  561. {
  562. struct print_buf pb;
  563. if (!bcl)
  564. return 0;
  565. printbuf_init(&pb, buf, buf_size);
  566. spin_lock_bh(&bc_lock);
  567. tipc_printf(&pb, "Link <%s>\n"
  568. " Window:%u packets\n",
  569. bcl->name, bcl->queue_limit[0]);
  570. tipc_printf(&pb, " RX packets:%u fragments:%u/%u bundles:%u/%u\n",
  571. bcl->stats.recv_info,
  572. bcl->stats.recv_fragments,
  573. bcl->stats.recv_fragmented,
  574. bcl->stats.recv_bundles,
  575. bcl->stats.recv_bundled);
  576. tipc_printf(&pb, " TX packets:%u fragments:%u/%u bundles:%u/%u\n",
  577. bcl->stats.sent_info,
  578. bcl->stats.sent_fragments,
  579. bcl->stats.sent_fragmented,
  580. bcl->stats.sent_bundles,
  581. bcl->stats.sent_bundled);
  582. tipc_printf(&pb, " RX naks:%u defs:%u dups:%u\n",
  583. bcl->stats.recv_nacks,
  584. bcl->stats.deferred_recv,
  585. bcl->stats.duplicates);
  586. tipc_printf(&pb, " TX naks:%u acks:%u dups:%u\n",
  587. bcl->stats.sent_nacks,
  588. bcl->stats.sent_acks,
  589. bcl->stats.retransmitted);
  590. tipc_printf(&pb, " Congestion bearer:%u link:%u Send queue max:%u avg:%u\n",
  591. bcl->stats.bearer_congs,
  592. bcl->stats.link_congs,
  593. bcl->stats.max_queue_sz,
  594. bcl->stats.queue_sz_counts
  595. ? (bcl->stats.accu_queue_sz / bcl->stats.queue_sz_counts)
  596. : 0);
  597. spin_unlock_bh(&bc_lock);
  598. return printbuf_validate(&pb);
  599. }
  600. int bclink_reset_stats(void)
  601. {
  602. if (!bcl)
  603. return -ENOPROTOOPT;
  604. spin_lock_bh(&bc_lock);
  605. memset(&bcl->stats, 0, sizeof(bcl->stats));
  606. spin_unlock_bh(&bc_lock);
  607. return TIPC_OK;
  608. }
  609. int bclink_set_queue_limits(u32 limit)
  610. {
  611. if (!bcl)
  612. return -ENOPROTOOPT;
  613. if ((limit < TIPC_MIN_LINK_WIN) || (limit > TIPC_MAX_LINK_WIN))
  614. return -EINVAL;
  615. spin_lock_bh(&bc_lock);
  616. link_set_queue_limits(bcl, limit);
  617. spin_unlock_bh(&bc_lock);
  618. return TIPC_OK;
  619. }
  620. int bclink_init(void)
  621. {
  622. bcbearer = kmalloc(sizeof(*bcbearer), GFP_ATOMIC);
  623. bclink = kmalloc(sizeof(*bclink), GFP_ATOMIC);
  624. if (!bcbearer || !bclink) {
  625. nomem:
  626. warn("Memory squeeze; Failed to create multicast link\n");
  627. kfree(bcbearer);
  628. bcbearer = NULL;
  629. kfree(bclink);
  630. bclink = NULL;
  631. return -ENOMEM;
  632. }
  633. memset(bcbearer, 0, sizeof(struct bcbearer));
  634. INIT_LIST_HEAD(&bcbearer->bearer.cong_links);
  635. bcbearer->bearer.media = &bcbearer->media;
  636. bcbearer->media.send_msg = bcbearer_send;
  637. sprintf(bcbearer->media.name, "tipc-multicast");
  638. bcl = &bclink->link;
  639. memset(bclink, 0, sizeof(struct bclink));
  640. INIT_LIST_HEAD(&bcl->waiting_ports);
  641. bcl->next_out_no = 1;
  642. bclink->node.lock = SPIN_LOCK_UNLOCKED;
  643. bcl->owner = &bclink->node;
  644. bcl->max_pkt = MAX_PKT_DEFAULT_MCAST;
  645. link_set_queue_limits(bcl, BCLINK_WIN_DEFAULT);
  646. bcl->b_ptr = &bcbearer->bearer;
  647. bcl->state = WORKING_WORKING;
  648. sprintf(bcl->name, bc_link_name);
  649. if (BCLINK_LOG_BUF_SIZE) {
  650. char *pb = kmalloc(BCLINK_LOG_BUF_SIZE, GFP_ATOMIC);
  651. if (!pb)
  652. goto nomem;
  653. printbuf_init(&bcl->print_buf, pb, BCLINK_LOG_BUF_SIZE);
  654. }
  655. return TIPC_OK;
  656. }
  657. void bclink_stop(void)
  658. {
  659. spin_lock_bh(&bc_lock);
  660. if (bcbearer) {
  661. link_stop(bcl);
  662. if (BCLINK_LOG_BUF_SIZE)
  663. kfree(bcl->print_buf.buf);
  664. bcl = NULL;
  665. kfree(bclink);
  666. bclink = NULL;
  667. kfree(bcbearer);
  668. bcbearer = NULL;
  669. }
  670. spin_unlock_bh(&bc_lock);
  671. }