2 * net/tipc/link.c: TIPC link code
4 * Copyright (c) 1996-2007, 2012-2014, Ericsson AB
5 * Copyright (c) 2004-2007, 2010-2013, Wind River Systems
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions are met:
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.
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.
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.
40 #include "name_distr.h"
45 #include <linux/pkt_sched.h>
48 * Error message prefixes
50 static const char *link_co_err = "Link changeover error, ";
51 static const char *link_rst_msg = "Resetting link ";
52 static const char *link_unk_evt = "Unknown link event ";
54 /* Properties valid for media, bearar and link */
55 static const struct nla_policy tipc_nl_prop_policy[TIPC_NLA_PROP_MAX + 1] = {
56 [TIPC_NLA_PROP_UNSPEC] = { .type = NLA_UNSPEC },
57 [TIPC_NLA_PROP_PRIO] = { .type = NLA_U32 },
58 [TIPC_NLA_PROP_TOL] = { .type = NLA_U32 },
59 [TIPC_NLA_PROP_WIN] = { .type = NLA_U32 }
63 * Out-of-range value for link session numbers
65 #define INVALID_SESSION 0x10000
70 #define STARTING_EVT 856384768 /* link processing trigger */
71 #define TRAFFIC_MSG_EVT 560815u /* rx'd ??? */
72 #define TIMEOUT_EVT 560817u /* link timer expired */
75 * The following two 'message types' is really just implementation
76 * data conveniently stored in the message header.
77 * They must not be considered part of the protocol
83 * State value stored in 'exp_msg_count'
85 #define START_CHANGEOVER 100000u
87 static void link_handle_out_of_seq_msg(struct tipc_link *l_ptr,
89 static void tipc_link_proto_rcv(struct tipc_link *l_ptr, struct sk_buff *buf);
90 static int tipc_link_tunnel_rcv(struct tipc_node *n_ptr,
91 struct sk_buff **buf);
92 static void link_set_supervision_props(struct tipc_link *l_ptr, u32 tolerance);
93 static void link_state_event(struct tipc_link *l_ptr, u32 event);
94 static void link_reset_statistics(struct tipc_link *l_ptr);
95 static void link_print(struct tipc_link *l_ptr, const char *str);
96 static void tipc_link_sync_xmit(struct tipc_link *l);
97 static void tipc_link_sync_rcv(struct tipc_node *n, struct sk_buff *buf);
98 static int tipc_link_input(struct tipc_link *l, struct sk_buff *buf);
99 static int tipc_link_prepare_input(struct tipc_link *l, struct sk_buff **buf);
102 * Simple link routines
104 static unsigned int align(unsigned int i)
106 return (i + 3) & ~3u;
109 static void link_init_max_pkt(struct tipc_link *l_ptr)
111 struct tipc_bearer *b_ptr;
115 b_ptr = rcu_dereference_rtnl(bearer_list[l_ptr->bearer_id]);
120 max_pkt = (b_ptr->mtu & ~3);
123 if (max_pkt > MAX_MSG_SIZE)
124 max_pkt = MAX_MSG_SIZE;
126 l_ptr->max_pkt_target = max_pkt;
127 if (l_ptr->max_pkt_target < MAX_PKT_DEFAULT)
128 l_ptr->max_pkt = l_ptr->max_pkt_target;
130 l_ptr->max_pkt = MAX_PKT_DEFAULT;
132 l_ptr->max_pkt_probes = 0;
135 static u32 link_next_sent(struct tipc_link *l_ptr)
138 return buf_seqno(l_ptr->next_out);
139 return mod(l_ptr->next_out_no);
142 static u32 link_last_sent(struct tipc_link *l_ptr)
144 return mod(link_next_sent(l_ptr) - 1);
148 * Simple non-static link routines (i.e. referenced outside this file)
150 int tipc_link_is_up(struct tipc_link *l_ptr)
154 return link_working_working(l_ptr) || link_working_unknown(l_ptr);
157 int tipc_link_is_active(struct tipc_link *l_ptr)
159 return (l_ptr->owner->active_links[0] == l_ptr) ||
160 (l_ptr->owner->active_links[1] == l_ptr);
164 * link_timeout - handle expiration of link timer
165 * @l_ptr: pointer to link
167 static void link_timeout(struct tipc_link *l_ptr)
169 tipc_node_lock(l_ptr->owner);
171 /* update counters used in statistical profiling of send traffic */
172 l_ptr->stats.accu_queue_sz += l_ptr->out_queue_size;
173 l_ptr->stats.queue_sz_counts++;
175 if (l_ptr->first_out) {
176 struct tipc_msg *msg = buf_msg(l_ptr->first_out);
177 u32 length = msg_size(msg);
179 if ((msg_user(msg) == MSG_FRAGMENTER) &&
180 (msg_type(msg) == FIRST_FRAGMENT)) {
181 length = msg_size(msg_get_wrapped(msg));
184 l_ptr->stats.msg_lengths_total += length;
185 l_ptr->stats.msg_length_counts++;
187 l_ptr->stats.msg_length_profile[0]++;
188 else if (length <= 256)
189 l_ptr->stats.msg_length_profile[1]++;
190 else if (length <= 1024)
191 l_ptr->stats.msg_length_profile[2]++;
192 else if (length <= 4096)
193 l_ptr->stats.msg_length_profile[3]++;
194 else if (length <= 16384)
195 l_ptr->stats.msg_length_profile[4]++;
196 else if (length <= 32768)
197 l_ptr->stats.msg_length_profile[5]++;
199 l_ptr->stats.msg_length_profile[6]++;
203 /* do all other link processing performed on a periodic basis */
205 link_state_event(l_ptr, TIMEOUT_EVT);
208 tipc_link_push_queue(l_ptr);
210 tipc_node_unlock(l_ptr->owner);
213 static void link_set_timer(struct tipc_link *l_ptr, u32 time)
215 k_start_timer(&l_ptr->timer, time);
219 * tipc_link_create - create a new link
220 * @n_ptr: pointer to associated node
221 * @b_ptr: pointer to associated bearer
222 * @media_addr: media address to use when sending messages over link
224 * Returns pointer to link.
226 struct tipc_link *tipc_link_create(struct tipc_node *n_ptr,
227 struct tipc_bearer *b_ptr,
228 const struct tipc_media_addr *media_addr)
230 struct tipc_link *l_ptr;
231 struct tipc_msg *msg;
233 char addr_string[16];
234 u32 peer = n_ptr->addr;
236 if (n_ptr->link_cnt >= MAX_BEARERS) {
237 tipc_addr_string_fill(addr_string, n_ptr->addr);
238 pr_err("Attempt to establish %uth link to %s. Max %u allowed.\n",
239 n_ptr->link_cnt, addr_string, MAX_BEARERS);
243 if (n_ptr->links[b_ptr->identity]) {
244 tipc_addr_string_fill(addr_string, n_ptr->addr);
245 pr_err("Attempt to establish second link on <%s> to %s\n",
246 b_ptr->name, addr_string);
250 l_ptr = kzalloc(sizeof(*l_ptr), GFP_ATOMIC);
252 pr_warn("Link creation failed, no memory\n");
257 if_name = strchr(b_ptr->name, ':') + 1;
258 sprintf(l_ptr->name, "%u.%u.%u:%s-%u.%u.%u:unknown",
259 tipc_zone(tipc_own_addr), tipc_cluster(tipc_own_addr),
260 tipc_node(tipc_own_addr),
262 tipc_zone(peer), tipc_cluster(peer), tipc_node(peer));
263 /* note: peer i/f name is updated by reset/activate message */
264 memcpy(&l_ptr->media_addr, media_addr, sizeof(*media_addr));
265 l_ptr->owner = n_ptr;
266 l_ptr->checkpoint = 1;
267 l_ptr->peer_session = INVALID_SESSION;
268 l_ptr->bearer_id = b_ptr->identity;
269 link_set_supervision_props(l_ptr, b_ptr->tolerance);
270 l_ptr->state = RESET_UNKNOWN;
272 l_ptr->pmsg = (struct tipc_msg *)&l_ptr->proto_msg;
274 tipc_msg_init(msg, LINK_PROTOCOL, RESET_MSG, INT_H_SIZE, l_ptr->addr);
275 msg_set_size(msg, sizeof(l_ptr->proto_msg));
276 msg_set_session(msg, (tipc_random & 0xffff));
277 msg_set_bearer_id(msg, b_ptr->identity);
278 strcpy((char *)msg_data(msg), if_name);
280 l_ptr->priority = b_ptr->priority;
281 tipc_link_set_queue_limits(l_ptr, b_ptr->window);
283 l_ptr->net_plane = b_ptr->net_plane;
284 link_init_max_pkt(l_ptr);
286 l_ptr->next_out_no = 1;
287 __skb_queue_head_init(&l_ptr->waiting_sks);
289 link_reset_statistics(l_ptr);
291 tipc_node_attach_link(n_ptr, l_ptr);
293 k_init_timer(&l_ptr->timer, (Handler)link_timeout,
294 (unsigned long)l_ptr);
296 link_state_event(l_ptr, STARTING_EVT);
301 void tipc_link_delete_list(unsigned int bearer_id, bool shutting_down)
303 struct tipc_link *l_ptr;
304 struct tipc_node *n_ptr;
307 list_for_each_entry_rcu(n_ptr, &tipc_node_list, list) {
308 tipc_node_lock(n_ptr);
309 l_ptr = n_ptr->links[bearer_id];
311 tipc_link_reset(l_ptr);
312 if (shutting_down || !tipc_node_is_up(n_ptr)) {
313 tipc_node_detach_link(l_ptr->owner, l_ptr);
314 tipc_link_reset_fragments(l_ptr);
315 tipc_node_unlock(n_ptr);
317 /* Nobody else can access this link now: */
318 del_timer_sync(&l_ptr->timer);
321 /* Detach/delete when failover is finished: */
322 l_ptr->flags |= LINK_STOPPED;
323 tipc_node_unlock(n_ptr);
324 del_timer_sync(&l_ptr->timer);
328 tipc_node_unlock(n_ptr);
334 * link_schedule_user - schedule user for wakeup after congestion
335 * @link: congested link
336 * @oport: sending port
337 * @chain_sz: size of buffer chain that was attempted sent
338 * @imp: importance of message attempted sent
339 * Create pseudo msg to send back to user when congestion abates
341 static bool link_schedule_user(struct tipc_link *link, u32 oport,
342 uint chain_sz, uint imp)
346 buf = tipc_msg_create(SOCK_WAKEUP, 0, INT_H_SIZE, 0, tipc_own_addr,
347 tipc_own_addr, oport, 0, 0);
350 TIPC_SKB_CB(buf)->chain_sz = chain_sz;
351 TIPC_SKB_CB(buf)->chain_imp = imp;
352 __skb_queue_tail(&link->waiting_sks, buf);
353 link->stats.link_congs++;
358 * link_prepare_wakeup - prepare users for wakeup after congestion
359 * @link: congested link
360 * Move a number of waiting users, as permitted by available space in
361 * the send queue, from link wait queue to node wait queue for wakeup
363 static void link_prepare_wakeup(struct tipc_link *link)
365 struct sk_buff_head *wq = &link->waiting_sks;
367 uint pend_qsz = link->out_queue_size;
369 for (buf = skb_peek(wq); buf; buf = skb_peek(wq)) {
370 if (pend_qsz >= link->queue_limit[TIPC_SKB_CB(buf)->chain_imp])
372 pend_qsz += TIPC_SKB_CB(buf)->chain_sz;
373 __skb_queue_tail(&link->owner->waiting_sks, __skb_dequeue(wq));
378 * link_release_outqueue - purge link's outbound message queue
379 * @l_ptr: pointer to link
381 static void link_release_outqueue(struct tipc_link *l_ptr)
383 kfree_skb_list(l_ptr->first_out);
384 l_ptr->first_out = NULL;
385 l_ptr->out_queue_size = 0;
389 * tipc_link_reset_fragments - purge link's inbound message fragments queue
390 * @l_ptr: pointer to link
392 void tipc_link_reset_fragments(struct tipc_link *l_ptr)
394 kfree_skb(l_ptr->reasm_buf);
395 l_ptr->reasm_buf = NULL;
399 * tipc_link_purge_queues - purge all pkt queues associated with link
400 * @l_ptr: pointer to link
402 void tipc_link_purge_queues(struct tipc_link *l_ptr)
404 kfree_skb_list(l_ptr->oldest_deferred_in);
405 kfree_skb_list(l_ptr->first_out);
406 tipc_link_reset_fragments(l_ptr);
407 kfree_skb(l_ptr->proto_msg_queue);
408 l_ptr->proto_msg_queue = NULL;
411 void tipc_link_reset(struct tipc_link *l_ptr)
413 u32 prev_state = l_ptr->state;
414 u32 checkpoint = l_ptr->next_in_no;
415 int was_active_link = tipc_link_is_active(l_ptr);
416 struct tipc_node *owner = l_ptr->owner;
418 msg_set_session(l_ptr->pmsg, ((msg_session(l_ptr->pmsg) + 1) & 0xffff));
420 /* Link is down, accept any session */
421 l_ptr->peer_session = INVALID_SESSION;
423 /* Prepare for max packet size negotiation */
424 link_init_max_pkt(l_ptr);
426 l_ptr->state = RESET_UNKNOWN;
428 if ((prev_state == RESET_UNKNOWN) || (prev_state == RESET_RESET))
431 tipc_node_link_down(l_ptr->owner, l_ptr);
432 tipc_bearer_remove_dest(l_ptr->bearer_id, l_ptr->addr);
434 if (was_active_link && tipc_node_active_links(l_ptr->owner)) {
435 l_ptr->reset_checkpoint = checkpoint;
436 l_ptr->exp_msg_count = START_CHANGEOVER;
439 /* Clean up all queues: */
440 link_release_outqueue(l_ptr);
441 kfree_skb(l_ptr->proto_msg_queue);
442 l_ptr->proto_msg_queue = NULL;
443 kfree_skb_list(l_ptr->oldest_deferred_in);
444 if (!skb_queue_empty(&l_ptr->waiting_sks)) {
445 skb_queue_splice_init(&l_ptr->waiting_sks, &owner->waiting_sks);
446 owner->action_flags |= TIPC_WAKEUP_USERS;
448 l_ptr->retransm_queue_head = 0;
449 l_ptr->retransm_queue_size = 0;
450 l_ptr->last_out = NULL;
451 l_ptr->first_out = NULL;
452 l_ptr->next_out = NULL;
453 l_ptr->unacked_window = 0;
454 l_ptr->checkpoint = 1;
455 l_ptr->next_out_no = 1;
456 l_ptr->deferred_inqueue_sz = 0;
457 l_ptr->oldest_deferred_in = NULL;
458 l_ptr->newest_deferred_in = NULL;
459 l_ptr->fsm_msg_cnt = 0;
460 l_ptr->stale_count = 0;
461 link_reset_statistics(l_ptr);
464 void tipc_link_reset_list(unsigned int bearer_id)
466 struct tipc_link *l_ptr;
467 struct tipc_node *n_ptr;
470 list_for_each_entry_rcu(n_ptr, &tipc_node_list, list) {
471 tipc_node_lock(n_ptr);
472 l_ptr = n_ptr->links[bearer_id];
474 tipc_link_reset(l_ptr);
475 tipc_node_unlock(n_ptr);
480 static void link_activate(struct tipc_link *l_ptr)
482 l_ptr->next_in_no = l_ptr->stats.recv_info = 1;
483 tipc_node_link_up(l_ptr->owner, l_ptr);
484 tipc_bearer_add_dest(l_ptr->bearer_id, l_ptr->addr);
488 * link_state_event - link finite state machine
489 * @l_ptr: pointer to link
490 * @event: state machine event to process
492 static void link_state_event(struct tipc_link *l_ptr, unsigned int event)
494 struct tipc_link *other;
495 u32 cont_intv = l_ptr->continuity_interval;
497 if (l_ptr->flags & LINK_STOPPED)
500 if (!(l_ptr->flags & LINK_STARTED) && (event != STARTING_EVT))
501 return; /* Not yet. */
503 /* Check whether changeover is going on */
504 if (l_ptr->exp_msg_count) {
505 if (event == TIMEOUT_EVT)
506 link_set_timer(l_ptr, cont_intv);
510 switch (l_ptr->state) {
511 case WORKING_WORKING:
513 case TRAFFIC_MSG_EVT:
517 if (l_ptr->next_in_no != l_ptr->checkpoint) {
518 l_ptr->checkpoint = l_ptr->next_in_no;
519 if (tipc_bclink_acks_missing(l_ptr->owner)) {
520 tipc_link_proto_xmit(l_ptr, STATE_MSG,
522 l_ptr->fsm_msg_cnt++;
523 } else if (l_ptr->max_pkt < l_ptr->max_pkt_target) {
524 tipc_link_proto_xmit(l_ptr, STATE_MSG,
526 l_ptr->fsm_msg_cnt++;
528 link_set_timer(l_ptr, cont_intv);
531 l_ptr->state = WORKING_UNKNOWN;
532 l_ptr->fsm_msg_cnt = 0;
533 tipc_link_proto_xmit(l_ptr, STATE_MSG, 1, 0, 0, 0, 0);
534 l_ptr->fsm_msg_cnt++;
535 link_set_timer(l_ptr, cont_intv / 4);
538 pr_info("%s<%s>, requested by peer\n", link_rst_msg,
540 tipc_link_reset(l_ptr);
541 l_ptr->state = RESET_RESET;
542 l_ptr->fsm_msg_cnt = 0;
543 tipc_link_proto_xmit(l_ptr, ACTIVATE_MSG,
545 l_ptr->fsm_msg_cnt++;
546 link_set_timer(l_ptr, cont_intv);
549 pr_err("%s%u in WW state\n", link_unk_evt, event);
552 case WORKING_UNKNOWN:
554 case TRAFFIC_MSG_EVT:
556 l_ptr->state = WORKING_WORKING;
557 l_ptr->fsm_msg_cnt = 0;
558 link_set_timer(l_ptr, cont_intv);
561 pr_info("%s<%s>, requested by peer while probing\n",
562 link_rst_msg, l_ptr->name);
563 tipc_link_reset(l_ptr);
564 l_ptr->state = RESET_RESET;
565 l_ptr->fsm_msg_cnt = 0;
566 tipc_link_proto_xmit(l_ptr, ACTIVATE_MSG,
568 l_ptr->fsm_msg_cnt++;
569 link_set_timer(l_ptr, cont_intv);
572 if (l_ptr->next_in_no != l_ptr->checkpoint) {
573 l_ptr->state = WORKING_WORKING;
574 l_ptr->fsm_msg_cnt = 0;
575 l_ptr->checkpoint = l_ptr->next_in_no;
576 if (tipc_bclink_acks_missing(l_ptr->owner)) {
577 tipc_link_proto_xmit(l_ptr, STATE_MSG,
579 l_ptr->fsm_msg_cnt++;
581 link_set_timer(l_ptr, cont_intv);
582 } else if (l_ptr->fsm_msg_cnt < l_ptr->abort_limit) {
583 tipc_link_proto_xmit(l_ptr, STATE_MSG,
585 l_ptr->fsm_msg_cnt++;
586 link_set_timer(l_ptr, cont_intv / 4);
587 } else { /* Link has failed */
588 pr_warn("%s<%s>, peer not responding\n",
589 link_rst_msg, l_ptr->name);
590 tipc_link_reset(l_ptr);
591 l_ptr->state = RESET_UNKNOWN;
592 l_ptr->fsm_msg_cnt = 0;
593 tipc_link_proto_xmit(l_ptr, RESET_MSG,
595 l_ptr->fsm_msg_cnt++;
596 link_set_timer(l_ptr, cont_intv);
600 pr_err("%s%u in WU state\n", link_unk_evt, event);
605 case TRAFFIC_MSG_EVT:
608 other = l_ptr->owner->active_links[0];
609 if (other && link_working_unknown(other))
611 l_ptr->state = WORKING_WORKING;
612 l_ptr->fsm_msg_cnt = 0;
613 link_activate(l_ptr);
614 tipc_link_proto_xmit(l_ptr, STATE_MSG, 1, 0, 0, 0, 0);
615 l_ptr->fsm_msg_cnt++;
616 if (l_ptr->owner->working_links == 1)
617 tipc_link_sync_xmit(l_ptr);
618 link_set_timer(l_ptr, cont_intv);
621 l_ptr->state = RESET_RESET;
622 l_ptr->fsm_msg_cnt = 0;
623 tipc_link_proto_xmit(l_ptr, ACTIVATE_MSG,
625 l_ptr->fsm_msg_cnt++;
626 link_set_timer(l_ptr, cont_intv);
629 l_ptr->flags |= LINK_STARTED;
632 tipc_link_proto_xmit(l_ptr, RESET_MSG, 0, 0, 0, 0, 0);
633 l_ptr->fsm_msg_cnt++;
634 link_set_timer(l_ptr, cont_intv);
637 pr_err("%s%u in RU state\n", link_unk_evt, event);
642 case TRAFFIC_MSG_EVT:
644 other = l_ptr->owner->active_links[0];
645 if (other && link_working_unknown(other))
647 l_ptr->state = WORKING_WORKING;
648 l_ptr->fsm_msg_cnt = 0;
649 link_activate(l_ptr);
650 tipc_link_proto_xmit(l_ptr, STATE_MSG, 1, 0, 0, 0, 0);
651 l_ptr->fsm_msg_cnt++;
652 if (l_ptr->owner->working_links == 1)
653 tipc_link_sync_xmit(l_ptr);
654 link_set_timer(l_ptr, cont_intv);
659 tipc_link_proto_xmit(l_ptr, ACTIVATE_MSG,
661 l_ptr->fsm_msg_cnt++;
662 link_set_timer(l_ptr, cont_intv);
665 pr_err("%s%u in RR state\n", link_unk_evt, event);
669 pr_err("Unknown link state %u/%u\n", l_ptr->state, event);
673 /* tipc_link_cong: determine return value and how to treat the
674 * sent buffer during link congestion.
675 * - For plain, errorless user data messages we keep the buffer and
677 * - For all other messages we discard the buffer and return -EHOSTUNREACH
678 * - For TIPC internal messages we also reset the link
680 static int tipc_link_cong(struct tipc_link *link, struct sk_buff *buf)
682 struct tipc_msg *msg = buf_msg(buf);
683 uint imp = tipc_msg_tot_importance(msg);
684 u32 oport = msg_tot_origport(msg);
686 if (unlikely(imp > TIPC_CRITICAL_IMPORTANCE)) {
687 pr_warn("%s<%s>, send queue full", link_rst_msg, link->name);
688 tipc_link_reset(link);
691 if (unlikely(msg_errcode(msg)))
693 if (unlikely(msg_reroute_cnt(msg)))
695 if (TIPC_SKB_CB(buf)->wakeup_pending)
697 if (link_schedule_user(link, oport, TIPC_SKB_CB(buf)->chain_sz, imp))
701 return -EHOSTUNREACH;
705 * __tipc_link_xmit(): same as tipc_link_xmit, but destlink is known & locked
707 * @buf: chain of buffers containing message
708 * Consumes the buffer chain, except when returning -ELINKCONG
709 * Returns 0 if success, otherwise errno: -ELINKCONG, -EMSGSIZE (plain socket
710 * user data messages) or -EHOSTUNREACH (all other messages/senders)
711 * Only the socket functions tipc_send_stream() and tipc_send_packet() need
712 * to act on the return value, since they may need to do more send attempts.
714 int __tipc_link_xmit(struct tipc_link *link, struct sk_buff *buf)
716 struct tipc_msg *msg = buf_msg(buf);
717 uint psz = msg_size(msg);
718 uint qsz = link->out_queue_size;
719 uint sndlim = link->queue_limit[0];
720 uint imp = tipc_msg_tot_importance(msg);
721 uint mtu = link->max_pkt;
722 uint ack = mod(link->next_in_no - 1);
723 uint seqno = link->next_out_no;
724 uint bc_last_in = link->owner->bclink.last_in;
725 struct tipc_media_addr *addr = &link->media_addr;
726 struct sk_buff *next = buf->next;
728 /* Match queue limits against msg importance: */
729 if (unlikely(qsz >= link->queue_limit[imp]))
730 return tipc_link_cong(link, buf);
732 /* Has valid packet limit been used ? */
733 if (unlikely(psz > mtu)) {
738 /* Prepare each packet for sending, and add to outqueue: */
742 msg_set_word(msg, 2, ((ack << 16) | mod(seqno)));
743 msg_set_bcast_ack(msg, bc_last_in);
745 if (!link->first_out) {
746 link->first_out = buf;
747 } else if (qsz < sndlim) {
748 link->last_out->next = buf;
749 } else if (tipc_msg_bundle(link->last_out, buf, mtu)) {
750 link->stats.sent_bundled++;
754 } else if (tipc_msg_make_bundle(&buf, mtu, link->addr)) {
755 link->stats.sent_bundled++;
756 link->stats.sent_bundles++;
757 link->last_out->next = buf;
759 link->next_out = buf;
761 link->last_out->next = buf;
763 link->next_out = buf;
766 /* Send packet if possible: */
767 if (likely(++qsz <= sndlim)) {
768 tipc_bearer_send(link->bearer_id, buf, addr);
769 link->next_out = next;
770 link->unacked_window = 0;
773 link->last_out = buf;
776 link->next_out_no = seqno;
777 link->out_queue_size = qsz;
782 * tipc_link_xmit() is the general link level function for message sending
783 * @buf: chain of buffers containing message
784 * @dsz: amount of user data to be sent
785 * @dnode: address of destination node
786 * @selector: a number used for deterministic link selection
787 * Consumes the buffer chain, except when returning -ELINKCONG
788 * Returns 0 if success, otherwise errno: -ELINKCONG,-EHOSTUNREACH,-EMSGSIZE
790 int tipc_link_xmit(struct sk_buff *buf, u32 dnode, u32 selector)
792 struct tipc_link *link = NULL;
793 struct tipc_node *node;
794 int rc = -EHOSTUNREACH;
796 node = tipc_node_find(dnode);
798 tipc_node_lock(node);
799 link = node->active_links[selector & 1];
801 rc = __tipc_link_xmit(link, buf);
802 tipc_node_unlock(node);
808 if (likely(in_own_node(dnode)))
809 return tipc_sk_rcv(buf);
816 * tipc_link_sync_xmit - synchronize broadcast link endpoints.
818 * Give a newly added peer node the sequence number where it should
819 * start receiving and acking broadcast packets.
821 * Called with node locked
823 static void tipc_link_sync_xmit(struct tipc_link *link)
826 struct tipc_msg *msg;
828 buf = tipc_buf_acquire(INT_H_SIZE);
833 tipc_msg_init(msg, BCAST_PROTOCOL, STATE_MSG, INT_H_SIZE, link->addr);
834 msg_set_last_bcast(msg, link->owner->bclink.acked);
835 __tipc_link_xmit(link, buf);
839 * tipc_link_sync_rcv - synchronize broadcast link endpoints.
840 * Receive the sequence number where we should start receiving and
841 * acking broadcast packets from a newly added peer node, and open
842 * up for reception of such packets.
844 * Called with node locked
846 static void tipc_link_sync_rcv(struct tipc_node *n, struct sk_buff *buf)
848 struct tipc_msg *msg = buf_msg(buf);
850 n->bclink.last_sent = n->bclink.last_in = msg_last_bcast(msg);
851 n->bclink.recv_permitted = true;
856 * tipc_link_push_packet: Push one unsent packet to the media
858 static u32 tipc_link_push_packet(struct tipc_link *l_ptr)
860 struct sk_buff *buf = l_ptr->first_out;
861 u32 r_q_size = l_ptr->retransm_queue_size;
862 u32 r_q_head = l_ptr->retransm_queue_head;
864 /* Step to position where retransmission failed, if any, */
865 /* consider that buffers may have been released in meantime */
866 if (r_q_size && buf) {
867 u32 last = lesser(mod(r_q_head + r_q_size),
868 link_last_sent(l_ptr));
869 u32 first = buf_seqno(buf);
871 while (buf && less(first, r_q_head)) {
872 first = mod(first + 1);
875 l_ptr->retransm_queue_head = r_q_head = first;
876 l_ptr->retransm_queue_size = r_q_size = mod(last - first);
879 /* Continue retransmission now, if there is anything: */
880 if (r_q_size && buf) {
881 msg_set_ack(buf_msg(buf), mod(l_ptr->next_in_no - 1));
882 msg_set_bcast_ack(buf_msg(buf), l_ptr->owner->bclink.last_in);
883 tipc_bearer_send(l_ptr->bearer_id, buf, &l_ptr->media_addr);
884 l_ptr->retransm_queue_head = mod(++r_q_head);
885 l_ptr->retransm_queue_size = --r_q_size;
886 l_ptr->stats.retransmitted++;
890 /* Send deferred protocol message, if any: */
891 buf = l_ptr->proto_msg_queue;
893 msg_set_ack(buf_msg(buf), mod(l_ptr->next_in_no - 1));
894 msg_set_bcast_ack(buf_msg(buf), l_ptr->owner->bclink.last_in);
895 tipc_bearer_send(l_ptr->bearer_id, buf, &l_ptr->media_addr);
896 l_ptr->unacked_window = 0;
898 l_ptr->proto_msg_queue = NULL;
902 /* Send one deferred data message, if send window not full: */
903 buf = l_ptr->next_out;
905 struct tipc_msg *msg = buf_msg(buf);
906 u32 next = msg_seqno(msg);
907 u32 first = buf_seqno(l_ptr->first_out);
909 if (mod(next - first) < l_ptr->queue_limit[0]) {
910 msg_set_ack(msg, mod(l_ptr->next_in_no - 1));
911 msg_set_bcast_ack(msg, l_ptr->owner->bclink.last_in);
912 tipc_bearer_send(l_ptr->bearer_id, buf,
914 if (msg_user(msg) == MSG_BUNDLER)
915 msg_set_type(msg, BUNDLE_CLOSED);
916 l_ptr->next_out = buf->next;
924 * push_queue(): push out the unsent messages of a link where
925 * congestion has abated. Node is locked
927 void tipc_link_push_queue(struct tipc_link *l_ptr)
932 res = tipc_link_push_packet(l_ptr);
936 void tipc_link_reset_all(struct tipc_node *node)
938 char addr_string[16];
941 tipc_node_lock(node);
943 pr_warn("Resetting all links to %s\n",
944 tipc_addr_string_fill(addr_string, node->addr));
946 for (i = 0; i < MAX_BEARERS; i++) {
947 if (node->links[i]) {
948 link_print(node->links[i], "Resetting link\n");
949 tipc_link_reset(node->links[i]);
953 tipc_node_unlock(node);
956 static void link_retransmit_failure(struct tipc_link *l_ptr,
959 struct tipc_msg *msg = buf_msg(buf);
961 pr_warn("Retransmission failure on link <%s>\n", l_ptr->name);
964 /* Handle failure on standard link */
965 link_print(l_ptr, "Resetting link\n");
966 tipc_link_reset(l_ptr);
969 /* Handle failure on broadcast link */
970 struct tipc_node *n_ptr;
971 char addr_string[16];
973 pr_info("Msg seq number: %u, ", msg_seqno(msg));
974 pr_cont("Outstanding acks: %lu\n",
975 (unsigned long) TIPC_SKB_CB(buf)->handle);
977 n_ptr = tipc_bclink_retransmit_to();
978 tipc_node_lock(n_ptr);
980 tipc_addr_string_fill(addr_string, n_ptr->addr);
981 pr_info("Broadcast link info for %s\n", addr_string);
982 pr_info("Reception permitted: %d, Acked: %u\n",
983 n_ptr->bclink.recv_permitted,
984 n_ptr->bclink.acked);
985 pr_info("Last in: %u, Oos state: %u, Last sent: %u\n",
986 n_ptr->bclink.last_in,
987 n_ptr->bclink.oos_state,
988 n_ptr->bclink.last_sent);
990 tipc_node_unlock(n_ptr);
992 tipc_bclink_set_flags(TIPC_BCLINK_RESET);
993 l_ptr->stale_count = 0;
997 void tipc_link_retransmit(struct tipc_link *l_ptr, struct sk_buff *buf,
1000 struct tipc_msg *msg;
1007 /* Detect repeated retransmit failures */
1008 if (l_ptr->last_retransmitted == msg_seqno(msg)) {
1009 if (++l_ptr->stale_count > 100) {
1010 link_retransmit_failure(l_ptr, buf);
1014 l_ptr->last_retransmitted = msg_seqno(msg);
1015 l_ptr->stale_count = 1;
1018 while (retransmits && (buf != l_ptr->next_out) && buf) {
1020 msg_set_ack(msg, mod(l_ptr->next_in_no - 1));
1021 msg_set_bcast_ack(msg, l_ptr->owner->bclink.last_in);
1022 tipc_bearer_send(l_ptr->bearer_id, buf, &l_ptr->media_addr);
1025 l_ptr->stats.retransmitted++;
1028 l_ptr->retransm_queue_head = l_ptr->retransm_queue_size = 0;
1032 * link_insert_deferred_queue - insert deferred messages back into receive chain
1034 static struct sk_buff *link_insert_deferred_queue(struct tipc_link *l_ptr,
1035 struct sk_buff *buf)
1039 if (l_ptr->oldest_deferred_in == NULL)
1042 seq_no = buf_seqno(l_ptr->oldest_deferred_in);
1043 if (seq_no == mod(l_ptr->next_in_no)) {
1044 l_ptr->newest_deferred_in->next = buf;
1045 buf = l_ptr->oldest_deferred_in;
1046 l_ptr->oldest_deferred_in = NULL;
1047 l_ptr->deferred_inqueue_sz = 0;
1053 * link_recv_buf_validate - validate basic format of received message
1055 * This routine ensures a TIPC message has an acceptable header, and at least
1056 * as much data as the header indicates it should. The routine also ensures
1057 * that the entire message header is stored in the main fragment of the message
1058 * buffer, to simplify future access to message header fields.
1060 * Note: Having extra info present in the message header or data areas is OK.
1061 * TIPC will ignore the excess, under the assumption that it is optional info
1062 * introduced by a later release of the protocol.
1064 static int link_recv_buf_validate(struct sk_buff *buf)
1066 static u32 min_data_hdr_size[8] = {
1067 SHORT_H_SIZE, MCAST_H_SIZE, NAMED_H_SIZE, BASIC_H_SIZE,
1068 MAX_H_SIZE, MAX_H_SIZE, MAX_H_SIZE, MAX_H_SIZE
1071 struct tipc_msg *msg;
1077 /* If this packet comes from the defer queue, the skb has already
1080 if (unlikely(TIPC_SKB_CB(buf)->deferred))
1083 if (unlikely(buf->len < MIN_H_SIZE))
1086 msg = skb_header_pointer(buf, 0, sizeof(tipc_hdr), tipc_hdr);
1090 if (unlikely(msg_version(msg) != TIPC_VERSION))
1093 size = msg_size(msg);
1094 hdr_size = msg_hdr_sz(msg);
1095 min_hdr_size = msg_isdata(msg) ?
1096 min_data_hdr_size[msg_type(msg)] : INT_H_SIZE;
1098 if (unlikely((hdr_size < min_hdr_size) ||
1099 (size < hdr_size) ||
1100 (buf->len < size) ||
1101 (size - hdr_size > TIPC_MAX_USER_MSG_SIZE)))
1104 return pskb_may_pull(buf, hdr_size);
1108 * tipc_rcv - process TIPC packets/messages arriving from off-node
1109 * @head: pointer to message buffer chain
1110 * @b_ptr: pointer to bearer message arrived on
1112 * Invoked with no locks held. Bearer pointer must point to a valid bearer
1113 * structure (i.e. cannot be NULL), but bearer can be inactive.
1115 void tipc_rcv(struct sk_buff *head, struct tipc_bearer *b_ptr)
1118 struct tipc_node *n_ptr;
1119 struct tipc_link *l_ptr;
1120 struct sk_buff *crs;
1121 struct sk_buff *buf = head;
1122 struct tipc_msg *msg;
1130 /* Ensure message is well-formed */
1131 if (unlikely(!link_recv_buf_validate(buf)))
1134 /* Ensure message data is a single contiguous unit */
1135 if (unlikely(skb_linearize(buf)))
1138 /* Handle arrival of a non-unicast link message */
1141 if (unlikely(msg_non_seq(msg))) {
1142 if (msg_user(msg) == LINK_CONFIG)
1143 tipc_disc_rcv(buf, b_ptr);
1145 tipc_bclink_rcv(buf);
1149 /* Discard unicast link messages destined for another node */
1150 if (unlikely(!msg_short(msg) &&
1151 (msg_destnode(msg) != tipc_own_addr)))
1154 /* Locate neighboring node that sent message */
1155 n_ptr = tipc_node_find(msg_prevnode(msg));
1156 if (unlikely(!n_ptr))
1158 tipc_node_lock(n_ptr);
1160 /* Locate unicast link endpoint that should handle message */
1161 l_ptr = n_ptr->links[b_ptr->identity];
1162 if (unlikely(!l_ptr))
1163 goto unlock_discard;
1165 /* Verify that communication with node is currently allowed */
1166 if ((n_ptr->action_flags & TIPC_WAIT_PEER_LINKS_DOWN) &&
1167 msg_user(msg) == LINK_PROTOCOL &&
1168 (msg_type(msg) == RESET_MSG ||
1169 msg_type(msg) == ACTIVATE_MSG) &&
1170 !msg_redundant_link(msg))
1171 n_ptr->action_flags &= ~TIPC_WAIT_PEER_LINKS_DOWN;
1173 if (tipc_node_blocked(n_ptr))
1174 goto unlock_discard;
1176 /* Validate message sequence number info */
1177 seq_no = msg_seqno(msg);
1178 ackd = msg_ack(msg);
1180 /* Release acked messages */
1181 if (n_ptr->bclink.recv_permitted)
1182 tipc_bclink_acknowledge(n_ptr, msg_bcast_ack(msg));
1184 crs = l_ptr->first_out;
1185 while ((crs != l_ptr->next_out) &&
1186 less_eq(buf_seqno(crs), ackd)) {
1187 struct sk_buff *next = crs->next;
1193 l_ptr->first_out = crs;
1194 l_ptr->out_queue_size -= released;
1197 /* Try sending any messages link endpoint has pending */
1198 if (unlikely(l_ptr->next_out))
1199 tipc_link_push_queue(l_ptr);
1201 if (released && !skb_queue_empty(&l_ptr->waiting_sks)) {
1202 link_prepare_wakeup(l_ptr);
1203 l_ptr->owner->action_flags |= TIPC_WAKEUP_USERS;
1206 /* Process the incoming packet */
1207 if (unlikely(!link_working_working(l_ptr))) {
1208 if (msg_user(msg) == LINK_PROTOCOL) {
1209 tipc_link_proto_rcv(l_ptr, buf);
1210 head = link_insert_deferred_queue(l_ptr, head);
1211 tipc_node_unlock(n_ptr);
1215 /* Traffic message. Conditionally activate link */
1216 link_state_event(l_ptr, TRAFFIC_MSG_EVT);
1218 if (link_working_working(l_ptr)) {
1219 /* Re-insert buffer in front of queue */
1222 tipc_node_unlock(n_ptr);
1225 goto unlock_discard;
1228 /* Link is now in state WORKING_WORKING */
1229 if (unlikely(seq_no != mod(l_ptr->next_in_no))) {
1230 link_handle_out_of_seq_msg(l_ptr, buf);
1231 head = link_insert_deferred_queue(l_ptr, head);
1232 tipc_node_unlock(n_ptr);
1235 l_ptr->next_in_no++;
1236 if (unlikely(l_ptr->oldest_deferred_in))
1237 head = link_insert_deferred_queue(l_ptr, head);
1239 if (unlikely(++l_ptr->unacked_window >= TIPC_MIN_LINK_WIN)) {
1240 l_ptr->stats.sent_acks++;
1241 tipc_link_proto_xmit(l_ptr, STATE_MSG, 0, 0, 0, 0, 0);
1244 if (tipc_link_prepare_input(l_ptr, &buf)) {
1245 tipc_node_unlock(n_ptr);
1248 tipc_node_unlock(n_ptr);
1250 if (tipc_link_input(l_ptr, buf) != 0)
1254 tipc_node_unlock(n_ptr);
1261 * tipc_link_prepare_input - process TIPC link messages
1263 * returns nonzero if the message was consumed
1265 * Node lock must be held
1267 static int tipc_link_prepare_input(struct tipc_link *l, struct sk_buff **buf)
1269 struct tipc_node *n;
1270 struct tipc_msg *msg;
1274 msg = buf_msg(*buf);
1275 switch (msg_user(msg)) {
1276 case CHANGEOVER_PROTOCOL:
1277 if (tipc_link_tunnel_rcv(n, buf))
1280 case MSG_FRAGMENTER:
1281 l->stats.recv_fragments++;
1282 if (tipc_buf_append(&l->reasm_buf, buf)) {
1283 l->stats.recv_fragmented++;
1285 } else if (!l->reasm_buf) {
1290 l->stats.recv_bundles++;
1291 l->stats.recv_bundled += msg_msgcnt(msg);
1294 case NAME_DISTRIBUTOR:
1295 n->bclink.recv_permitted = true;
1298 case BCAST_PROTOCOL:
1299 tipc_link_sync_rcv(n, *buf);
1307 * tipc_link_input - Deliver message too higher layers
1309 static int tipc_link_input(struct tipc_link *l, struct sk_buff *buf)
1311 struct tipc_msg *msg = buf_msg(buf);
1314 switch (msg_user(msg)) {
1315 case TIPC_LOW_IMPORTANCE:
1316 case TIPC_MEDIUM_IMPORTANCE:
1317 case TIPC_HIGH_IMPORTANCE:
1318 case TIPC_CRITICAL_IMPORTANCE:
1322 case NAME_DISTRIBUTOR:
1323 tipc_named_rcv(buf);
1326 tipc_link_bundle_rcv(buf);
1335 * tipc_link_defer_pkt - Add out-of-sequence message to deferred reception queue
1337 * Returns increase in queue length (i.e. 0 or 1)
1339 u32 tipc_link_defer_pkt(struct sk_buff **head, struct sk_buff **tail,
1340 struct sk_buff *buf)
1342 struct sk_buff *queue_buf;
1343 struct sk_buff **prev;
1344 u32 seq_no = buf_seqno(buf);
1349 if (*head == NULL) {
1350 *head = *tail = buf;
1355 if (less(buf_seqno(*tail), seq_no)) {
1356 (*tail)->next = buf;
1361 /* Locate insertion point in queue, then insert; discard if duplicate */
1365 u32 curr_seqno = buf_seqno(queue_buf);
1367 if (seq_no == curr_seqno) {
1372 if (less(seq_no, curr_seqno))
1375 prev = &queue_buf->next;
1376 queue_buf = queue_buf->next;
1379 buf->next = queue_buf;
1385 * link_handle_out_of_seq_msg - handle arrival of out-of-sequence packet
1387 static void link_handle_out_of_seq_msg(struct tipc_link *l_ptr,
1388 struct sk_buff *buf)
1390 u32 seq_no = buf_seqno(buf);
1392 if (likely(msg_user(buf_msg(buf)) == LINK_PROTOCOL)) {
1393 tipc_link_proto_rcv(l_ptr, buf);
1397 /* Record OOS packet arrival (force mismatch on next timeout) */
1398 l_ptr->checkpoint--;
1401 * Discard packet if a duplicate; otherwise add it to deferred queue
1402 * and notify peer of gap as per protocol specification
1404 if (less(seq_no, mod(l_ptr->next_in_no))) {
1405 l_ptr->stats.duplicates++;
1410 if (tipc_link_defer_pkt(&l_ptr->oldest_deferred_in,
1411 &l_ptr->newest_deferred_in, buf)) {
1412 l_ptr->deferred_inqueue_sz++;
1413 l_ptr->stats.deferred_recv++;
1414 TIPC_SKB_CB(buf)->deferred = true;
1415 if ((l_ptr->deferred_inqueue_sz % 16) == 1)
1416 tipc_link_proto_xmit(l_ptr, STATE_MSG, 0, 0, 0, 0, 0);
1418 l_ptr->stats.duplicates++;
1422 * Send protocol message to the other endpoint.
1424 void tipc_link_proto_xmit(struct tipc_link *l_ptr, u32 msg_typ, int probe_msg,
1425 u32 gap, u32 tolerance, u32 priority, u32 ack_mtu)
1427 struct sk_buff *buf = NULL;
1428 struct tipc_msg *msg = l_ptr->pmsg;
1429 u32 msg_size = sizeof(l_ptr->proto_msg);
1432 /* Discard any previous message that was deferred due to congestion */
1433 if (l_ptr->proto_msg_queue) {
1434 kfree_skb(l_ptr->proto_msg_queue);
1435 l_ptr->proto_msg_queue = NULL;
1438 /* Don't send protocol message during link changeover */
1439 if (l_ptr->exp_msg_count)
1442 /* Abort non-RESET send if communication with node is prohibited */
1443 if ((tipc_node_blocked(l_ptr->owner)) && (msg_typ != RESET_MSG))
1446 /* Create protocol message with "out-of-sequence" sequence number */
1447 msg_set_type(msg, msg_typ);
1448 msg_set_net_plane(msg, l_ptr->net_plane);
1449 msg_set_bcast_ack(msg, l_ptr->owner->bclink.last_in);
1450 msg_set_last_bcast(msg, tipc_bclink_get_last_sent());
1452 if (msg_typ == STATE_MSG) {
1453 u32 next_sent = mod(l_ptr->next_out_no);
1455 if (!tipc_link_is_up(l_ptr))
1457 if (l_ptr->next_out)
1458 next_sent = buf_seqno(l_ptr->next_out);
1459 msg_set_next_sent(msg, next_sent);
1460 if (l_ptr->oldest_deferred_in) {
1461 u32 rec = buf_seqno(l_ptr->oldest_deferred_in);
1462 gap = mod(rec - mod(l_ptr->next_in_no));
1464 msg_set_seq_gap(msg, gap);
1466 l_ptr->stats.sent_nacks++;
1467 msg_set_link_tolerance(msg, tolerance);
1468 msg_set_linkprio(msg, priority);
1469 msg_set_max_pkt(msg, ack_mtu);
1470 msg_set_ack(msg, mod(l_ptr->next_in_no - 1));
1471 msg_set_probe(msg, probe_msg != 0);
1473 u32 mtu = l_ptr->max_pkt;
1475 if ((mtu < l_ptr->max_pkt_target) &&
1476 link_working_working(l_ptr) &&
1477 l_ptr->fsm_msg_cnt) {
1478 msg_size = (mtu + (l_ptr->max_pkt_target - mtu)/2 + 2) & ~3;
1479 if (l_ptr->max_pkt_probes == 10) {
1480 l_ptr->max_pkt_target = (msg_size - 4);
1481 l_ptr->max_pkt_probes = 0;
1482 msg_size = (mtu + (l_ptr->max_pkt_target - mtu)/2 + 2) & ~3;
1484 l_ptr->max_pkt_probes++;
1487 l_ptr->stats.sent_probes++;
1489 l_ptr->stats.sent_states++;
1490 } else { /* RESET_MSG or ACTIVATE_MSG */
1491 msg_set_ack(msg, mod(l_ptr->reset_checkpoint - 1));
1492 msg_set_seq_gap(msg, 0);
1493 msg_set_next_sent(msg, 1);
1494 msg_set_probe(msg, 0);
1495 msg_set_link_tolerance(msg, l_ptr->tolerance);
1496 msg_set_linkprio(msg, l_ptr->priority);
1497 msg_set_max_pkt(msg, l_ptr->max_pkt_target);
1500 r_flag = (l_ptr->owner->working_links > tipc_link_is_up(l_ptr));
1501 msg_set_redundant_link(msg, r_flag);
1502 msg_set_linkprio(msg, l_ptr->priority);
1503 msg_set_size(msg, msg_size);
1505 msg_set_seqno(msg, mod(l_ptr->next_out_no + (0xffff/2)));
1507 buf = tipc_buf_acquire(msg_size);
1511 skb_copy_to_linear_data(buf, msg, sizeof(l_ptr->proto_msg));
1512 buf->priority = TC_PRIO_CONTROL;
1514 tipc_bearer_send(l_ptr->bearer_id, buf, &l_ptr->media_addr);
1515 l_ptr->unacked_window = 0;
1520 * Receive protocol message :
1521 * Note that network plane id propagates through the network, and may
1522 * change at any time. The node with lowest address rules
1524 static void tipc_link_proto_rcv(struct tipc_link *l_ptr, struct sk_buff *buf)
1530 struct tipc_msg *msg = buf_msg(buf);
1532 /* Discard protocol message during link changeover */
1533 if (l_ptr->exp_msg_count)
1536 if (l_ptr->net_plane != msg_net_plane(msg))
1537 if (tipc_own_addr > msg_prevnode(msg))
1538 l_ptr->net_plane = msg_net_plane(msg);
1540 switch (msg_type(msg)) {
1543 if (!link_working_unknown(l_ptr) &&
1544 (l_ptr->peer_session != INVALID_SESSION)) {
1545 if (less_eq(msg_session(msg), l_ptr->peer_session))
1546 break; /* duplicate or old reset: ignore */
1549 if (!msg_redundant_link(msg) && (link_working_working(l_ptr) ||
1550 link_working_unknown(l_ptr))) {
1552 * peer has lost contact -- don't allow peer's links
1553 * to reactivate before we recognize loss & clean up
1555 l_ptr->owner->action_flags |= TIPC_WAIT_OWN_LINKS_DOWN;
1558 link_state_event(l_ptr, RESET_MSG);
1562 /* Update link settings according other endpoint's values */
1563 strcpy((strrchr(l_ptr->name, ':') + 1), (char *)msg_data(msg));
1565 msg_tol = msg_link_tolerance(msg);
1566 if (msg_tol > l_ptr->tolerance)
1567 link_set_supervision_props(l_ptr, msg_tol);
1569 if (msg_linkprio(msg) > l_ptr->priority)
1570 l_ptr->priority = msg_linkprio(msg);
1572 max_pkt_info = msg_max_pkt(msg);
1574 if (max_pkt_info < l_ptr->max_pkt_target)
1575 l_ptr->max_pkt_target = max_pkt_info;
1576 if (l_ptr->max_pkt > l_ptr->max_pkt_target)
1577 l_ptr->max_pkt = l_ptr->max_pkt_target;
1579 l_ptr->max_pkt = l_ptr->max_pkt_target;
1582 /* Synchronize broadcast link info, if not done previously */
1583 if (!tipc_node_is_up(l_ptr->owner)) {
1584 l_ptr->owner->bclink.last_sent =
1585 l_ptr->owner->bclink.last_in =
1586 msg_last_bcast(msg);
1587 l_ptr->owner->bclink.oos_state = 0;
1590 l_ptr->peer_session = msg_session(msg);
1591 l_ptr->peer_bearer_id = msg_bearer_id(msg);
1593 if (msg_type(msg) == ACTIVATE_MSG)
1594 link_state_event(l_ptr, ACTIVATE_MSG);
1598 msg_tol = msg_link_tolerance(msg);
1600 link_set_supervision_props(l_ptr, msg_tol);
1602 if (msg_linkprio(msg) &&
1603 (msg_linkprio(msg) != l_ptr->priority)) {
1604 pr_warn("%s<%s>, priority change %u->%u\n",
1605 link_rst_msg, l_ptr->name, l_ptr->priority,
1607 l_ptr->priority = msg_linkprio(msg);
1608 tipc_link_reset(l_ptr); /* Enforce change to take effect */
1612 /* Record reception; force mismatch at next timeout: */
1613 l_ptr->checkpoint--;
1615 link_state_event(l_ptr, TRAFFIC_MSG_EVT);
1616 l_ptr->stats.recv_states++;
1617 if (link_reset_unknown(l_ptr))
1620 if (less_eq(mod(l_ptr->next_in_no), msg_next_sent(msg))) {
1621 rec_gap = mod(msg_next_sent(msg) -
1622 mod(l_ptr->next_in_no));
1625 max_pkt_ack = msg_max_pkt(msg);
1626 if (max_pkt_ack > l_ptr->max_pkt) {
1627 l_ptr->max_pkt = max_pkt_ack;
1628 l_ptr->max_pkt_probes = 0;
1632 if (msg_probe(msg)) {
1633 l_ptr->stats.recv_probes++;
1634 if (msg_size(msg) > sizeof(l_ptr->proto_msg))
1635 max_pkt_ack = msg_size(msg);
1638 /* Protocol message before retransmits, reduce loss risk */
1639 if (l_ptr->owner->bclink.recv_permitted)
1640 tipc_bclink_update_link_state(l_ptr->owner,
1641 msg_last_bcast(msg));
1643 if (rec_gap || (msg_probe(msg))) {
1644 tipc_link_proto_xmit(l_ptr, STATE_MSG, 0, rec_gap, 0,
1647 if (msg_seq_gap(msg)) {
1648 l_ptr->stats.recv_nacks++;
1649 tipc_link_retransmit(l_ptr, l_ptr->first_out,
1659 /* tipc_link_tunnel_xmit(): Tunnel one packet via a link belonging to
1660 * a different bearer. Owner node is locked.
1662 static void tipc_link_tunnel_xmit(struct tipc_link *l_ptr,
1663 struct tipc_msg *tunnel_hdr,
1664 struct tipc_msg *msg,
1667 struct tipc_link *tunnel;
1668 struct sk_buff *buf;
1669 u32 length = msg_size(msg);
1671 tunnel = l_ptr->owner->active_links[selector & 1];
1672 if (!tipc_link_is_up(tunnel)) {
1673 pr_warn("%stunnel link no longer available\n", link_co_err);
1676 msg_set_size(tunnel_hdr, length + INT_H_SIZE);
1677 buf = tipc_buf_acquire(length + INT_H_SIZE);
1679 pr_warn("%sunable to send tunnel msg\n", link_co_err);
1682 skb_copy_to_linear_data(buf, tunnel_hdr, INT_H_SIZE);
1683 skb_copy_to_linear_data_offset(buf, INT_H_SIZE, msg, length);
1684 __tipc_link_xmit(tunnel, buf);
1688 /* tipc_link_failover_send_queue(): A link has gone down, but a second
1689 * link is still active. We can do failover. Tunnel the failing link's
1690 * whole send queue via the remaining link. This way, we don't lose
1691 * any packets, and sequence order is preserved for subsequent traffic
1692 * sent over the remaining link. Owner node is locked.
1694 void tipc_link_failover_send_queue(struct tipc_link *l_ptr)
1696 u32 msgcount = l_ptr->out_queue_size;
1697 struct sk_buff *crs = l_ptr->first_out;
1698 struct tipc_link *tunnel = l_ptr->owner->active_links[0];
1699 struct tipc_msg tunnel_hdr;
1705 tipc_msg_init(&tunnel_hdr, CHANGEOVER_PROTOCOL,
1706 ORIGINAL_MSG, INT_H_SIZE, l_ptr->addr);
1707 msg_set_bearer_id(&tunnel_hdr, l_ptr->peer_bearer_id);
1708 msg_set_msgcnt(&tunnel_hdr, msgcount);
1710 if (!l_ptr->first_out) {
1711 struct sk_buff *buf;
1713 buf = tipc_buf_acquire(INT_H_SIZE);
1715 skb_copy_to_linear_data(buf, &tunnel_hdr, INT_H_SIZE);
1716 msg_set_size(&tunnel_hdr, INT_H_SIZE);
1717 __tipc_link_xmit(tunnel, buf);
1719 pr_warn("%sunable to send changeover msg\n",
1725 split_bundles = (l_ptr->owner->active_links[0] !=
1726 l_ptr->owner->active_links[1]);
1729 struct tipc_msg *msg = buf_msg(crs);
1731 if ((msg_user(msg) == MSG_BUNDLER) && split_bundles) {
1732 struct tipc_msg *m = msg_get_wrapped(msg);
1733 unchar *pos = (unchar *)m;
1735 msgcount = msg_msgcnt(msg);
1736 while (msgcount--) {
1737 msg_set_seqno(m, msg_seqno(msg));
1738 tipc_link_tunnel_xmit(l_ptr, &tunnel_hdr, m,
1739 msg_link_selector(m));
1740 pos += align(msg_size(m));
1741 m = (struct tipc_msg *)pos;
1744 tipc_link_tunnel_xmit(l_ptr, &tunnel_hdr, msg,
1745 msg_link_selector(msg));
1751 /* tipc_link_dup_queue_xmit(): A second link has become active. Tunnel a
1752 * duplicate of the first link's send queue via the new link. This way, we
1753 * are guaranteed that currently queued packets from a socket are delivered
1754 * before future traffic from the same socket, even if this is using the
1755 * new link. The last arriving copy of each duplicate packet is dropped at
1756 * the receiving end by the regular protocol check, so packet cardinality
1757 * and sequence order is preserved per sender/receiver socket pair.
1758 * Owner node is locked.
1760 void tipc_link_dup_queue_xmit(struct tipc_link *l_ptr,
1761 struct tipc_link *tunnel)
1763 struct sk_buff *iter;
1764 struct tipc_msg tunnel_hdr;
1766 tipc_msg_init(&tunnel_hdr, CHANGEOVER_PROTOCOL,
1767 DUPLICATE_MSG, INT_H_SIZE, l_ptr->addr);
1768 msg_set_msgcnt(&tunnel_hdr, l_ptr->out_queue_size);
1769 msg_set_bearer_id(&tunnel_hdr, l_ptr->peer_bearer_id);
1770 iter = l_ptr->first_out;
1772 struct sk_buff *outbuf;
1773 struct tipc_msg *msg = buf_msg(iter);
1774 u32 length = msg_size(msg);
1776 if (msg_user(msg) == MSG_BUNDLER)
1777 msg_set_type(msg, CLOSED_MSG);
1778 msg_set_ack(msg, mod(l_ptr->next_in_no - 1)); /* Update */
1779 msg_set_bcast_ack(msg, l_ptr->owner->bclink.last_in);
1780 msg_set_size(&tunnel_hdr, length + INT_H_SIZE);
1781 outbuf = tipc_buf_acquire(length + INT_H_SIZE);
1782 if (outbuf == NULL) {
1783 pr_warn("%sunable to send duplicate msg\n",
1787 skb_copy_to_linear_data(outbuf, &tunnel_hdr, INT_H_SIZE);
1788 skb_copy_to_linear_data_offset(outbuf, INT_H_SIZE, iter->data,
1790 __tipc_link_xmit(tunnel, outbuf);
1791 if (!tipc_link_is_up(l_ptr))
1798 * buf_extract - extracts embedded TIPC message from another message
1799 * @skb: encapsulating message buffer
1800 * @from_pos: offset to extract from
1802 * Returns a new message buffer containing an embedded message. The
1803 * encapsulating message itself is left unchanged.
1805 static struct sk_buff *buf_extract(struct sk_buff *skb, u32 from_pos)
1807 struct tipc_msg *msg = (struct tipc_msg *)(skb->data + from_pos);
1808 u32 size = msg_size(msg);
1811 eb = tipc_buf_acquire(size);
1813 skb_copy_to_linear_data(eb, msg, size);
1819 /* tipc_link_dup_rcv(): Receive a tunnelled DUPLICATE_MSG packet.
1820 * Owner node is locked.
1822 static void tipc_link_dup_rcv(struct tipc_link *l_ptr,
1823 struct sk_buff *t_buf)
1825 struct sk_buff *buf;
1827 if (!tipc_link_is_up(l_ptr))
1830 buf = buf_extract(t_buf, INT_H_SIZE);
1832 pr_warn("%sfailed to extract inner dup pkt\n", link_co_err);
1836 /* Add buffer to deferred queue, if applicable: */
1837 link_handle_out_of_seq_msg(l_ptr, buf);
1840 /* tipc_link_failover_rcv(): Receive a tunnelled ORIGINAL_MSG packet
1841 * Owner node is locked.
1843 static struct sk_buff *tipc_link_failover_rcv(struct tipc_link *l_ptr,
1844 struct sk_buff *t_buf)
1846 struct tipc_msg *t_msg = buf_msg(t_buf);
1847 struct sk_buff *buf = NULL;
1848 struct tipc_msg *msg;
1850 if (tipc_link_is_up(l_ptr))
1851 tipc_link_reset(l_ptr);
1853 /* First failover packet? */
1854 if (l_ptr->exp_msg_count == START_CHANGEOVER)
1855 l_ptr->exp_msg_count = msg_msgcnt(t_msg);
1857 /* Should there be an inner packet? */
1858 if (l_ptr->exp_msg_count) {
1859 l_ptr->exp_msg_count--;
1860 buf = buf_extract(t_buf, INT_H_SIZE);
1862 pr_warn("%sno inner failover pkt\n", link_co_err);
1867 if (less(msg_seqno(msg), l_ptr->reset_checkpoint)) {
1872 if (msg_user(msg) == MSG_FRAGMENTER) {
1873 l_ptr->stats.recv_fragments++;
1874 tipc_buf_append(&l_ptr->reasm_buf, &buf);
1878 if ((l_ptr->exp_msg_count == 0) && (l_ptr->flags & LINK_STOPPED)) {
1879 tipc_node_detach_link(l_ptr->owner, l_ptr);
1885 /* tipc_link_tunnel_rcv(): Receive a tunnelled packet, sent
1886 * via other link as result of a failover (ORIGINAL_MSG) or
1887 * a new active link (DUPLICATE_MSG). Failover packets are
1888 * returned to the active link for delivery upwards.
1889 * Owner node is locked.
1891 static int tipc_link_tunnel_rcv(struct tipc_node *n_ptr,
1892 struct sk_buff **buf)
1894 struct sk_buff *t_buf = *buf;
1895 struct tipc_link *l_ptr;
1896 struct tipc_msg *t_msg = buf_msg(t_buf);
1897 u32 bearer_id = msg_bearer_id(t_msg);
1901 if (bearer_id >= MAX_BEARERS)
1904 l_ptr = n_ptr->links[bearer_id];
1908 if (msg_type(t_msg) == DUPLICATE_MSG)
1909 tipc_link_dup_rcv(l_ptr, t_buf);
1910 else if (msg_type(t_msg) == ORIGINAL_MSG)
1911 *buf = tipc_link_failover_rcv(l_ptr, t_buf);
1913 pr_warn("%sunknown tunnel pkt received\n", link_co_err);
1916 return *buf != NULL;
1920 * Bundler functionality:
1922 void tipc_link_bundle_rcv(struct sk_buff *buf)
1924 u32 msgcount = msg_msgcnt(buf_msg(buf));
1925 u32 pos = INT_H_SIZE;
1926 struct sk_buff *obuf;
1927 struct tipc_msg *omsg;
1929 while (msgcount--) {
1930 obuf = buf_extract(buf, pos);
1932 pr_warn("Link unable to unbundle message(s)\n");
1935 omsg = buf_msg(obuf);
1936 pos += align(msg_size(omsg));
1937 if (msg_isdata(omsg)) {
1938 if (unlikely(msg_type(omsg) == TIPC_MCAST_MSG))
1939 tipc_sk_mcast_rcv(obuf);
1942 } else if (msg_user(omsg) == CONN_MANAGER) {
1944 } else if (msg_user(omsg) == NAME_DISTRIBUTOR) {
1945 tipc_named_rcv(obuf);
1947 pr_warn("Illegal bundled msg: %u\n", msg_user(omsg));
1954 static void link_set_supervision_props(struct tipc_link *l_ptr, u32 tolerance)
1956 if ((tolerance < TIPC_MIN_LINK_TOL) || (tolerance > TIPC_MAX_LINK_TOL))
1959 l_ptr->tolerance = tolerance;
1960 l_ptr->continuity_interval =
1961 ((tolerance / 4) > 500) ? 500 : tolerance / 4;
1962 l_ptr->abort_limit = tolerance / (l_ptr->continuity_interval / 4);
1965 void tipc_link_set_queue_limits(struct tipc_link *l_ptr, u32 window)
1967 /* Data messages from this node, inclusive FIRST_FRAGM */
1968 l_ptr->queue_limit[TIPC_LOW_IMPORTANCE] = window;
1969 l_ptr->queue_limit[TIPC_MEDIUM_IMPORTANCE] = (window / 3) * 4;
1970 l_ptr->queue_limit[TIPC_HIGH_IMPORTANCE] = (window / 3) * 5;
1971 l_ptr->queue_limit[TIPC_CRITICAL_IMPORTANCE] = (window / 3) * 6;
1972 /* Transiting data messages,inclusive FIRST_FRAGM */
1973 l_ptr->queue_limit[TIPC_LOW_IMPORTANCE + 4] = 300;
1974 l_ptr->queue_limit[TIPC_MEDIUM_IMPORTANCE + 4] = 600;
1975 l_ptr->queue_limit[TIPC_HIGH_IMPORTANCE + 4] = 900;
1976 l_ptr->queue_limit[TIPC_CRITICAL_IMPORTANCE + 4] = 1200;
1977 l_ptr->queue_limit[CONN_MANAGER] = 1200;
1978 l_ptr->queue_limit[CHANGEOVER_PROTOCOL] = 2500;
1979 l_ptr->queue_limit[NAME_DISTRIBUTOR] = 3000;
1980 /* FRAGMENT and LAST_FRAGMENT packets */
1981 l_ptr->queue_limit[MSG_FRAGMENTER] = 4000;
1984 /* tipc_link_find_owner - locate owner node of link by link's name
1985 * @name: pointer to link name string
1986 * @bearer_id: pointer to index in 'node->links' array where the link was found.
1988 * Returns pointer to node owning the link, or 0 if no matching link is found.
1990 static struct tipc_node *tipc_link_find_owner(const char *link_name,
1991 unsigned int *bearer_id)
1993 struct tipc_link *l_ptr;
1994 struct tipc_node *n_ptr;
1995 struct tipc_node *found_node = 0;
2000 list_for_each_entry_rcu(n_ptr, &tipc_node_list, list) {
2001 tipc_node_lock(n_ptr);
2002 for (i = 0; i < MAX_BEARERS; i++) {
2003 l_ptr = n_ptr->links[i];
2004 if (l_ptr && !strcmp(l_ptr->name, link_name)) {
2010 tipc_node_unlock(n_ptr);
2020 * link_value_is_valid -- validate proposed link tolerance/priority/window
2022 * @cmd: value type (TIPC_CMD_SET_LINK_*)
2023 * @new_value: the new value
2025 * Returns 1 if value is within range, 0 if not.
2027 static int link_value_is_valid(u16 cmd, u32 new_value)
2030 case TIPC_CMD_SET_LINK_TOL:
2031 return (new_value >= TIPC_MIN_LINK_TOL) &&
2032 (new_value <= TIPC_MAX_LINK_TOL);
2033 case TIPC_CMD_SET_LINK_PRI:
2034 return (new_value <= TIPC_MAX_LINK_PRI);
2035 case TIPC_CMD_SET_LINK_WINDOW:
2036 return (new_value >= TIPC_MIN_LINK_WIN) &&
2037 (new_value <= TIPC_MAX_LINK_WIN);
2043 * link_cmd_set_value - change priority/tolerance/window for link/bearer/media
2044 * @name: ptr to link, bearer, or media name
2045 * @new_value: new value of link, bearer, or media setting
2046 * @cmd: which link, bearer, or media attribute to set (TIPC_CMD_SET_LINK_*)
2048 * Caller must hold RTNL lock to ensure link/bearer/media is not deleted.
2050 * Returns 0 if value updated and negative value on error.
2052 static int link_cmd_set_value(const char *name, u32 new_value, u16 cmd)
2054 struct tipc_node *node;
2055 struct tipc_link *l_ptr;
2056 struct tipc_bearer *b_ptr;
2057 struct tipc_media *m_ptr;
2061 node = tipc_link_find_owner(name, &bearer_id);
2063 tipc_node_lock(node);
2064 l_ptr = node->links[bearer_id];
2068 case TIPC_CMD_SET_LINK_TOL:
2069 link_set_supervision_props(l_ptr, new_value);
2070 tipc_link_proto_xmit(l_ptr, STATE_MSG, 0, 0,
2073 case TIPC_CMD_SET_LINK_PRI:
2074 l_ptr->priority = new_value;
2075 tipc_link_proto_xmit(l_ptr, STATE_MSG, 0, 0,
2078 case TIPC_CMD_SET_LINK_WINDOW:
2079 tipc_link_set_queue_limits(l_ptr, new_value);
2086 tipc_node_unlock(node);
2090 b_ptr = tipc_bearer_find(name);
2093 case TIPC_CMD_SET_LINK_TOL:
2094 b_ptr->tolerance = new_value;
2096 case TIPC_CMD_SET_LINK_PRI:
2097 b_ptr->priority = new_value;
2099 case TIPC_CMD_SET_LINK_WINDOW:
2100 b_ptr->window = new_value;
2109 m_ptr = tipc_media_find(name);
2113 case TIPC_CMD_SET_LINK_TOL:
2114 m_ptr->tolerance = new_value;
2116 case TIPC_CMD_SET_LINK_PRI:
2117 m_ptr->priority = new_value;
2119 case TIPC_CMD_SET_LINK_WINDOW:
2120 m_ptr->window = new_value;
2129 struct sk_buff *tipc_link_cmd_config(const void *req_tlv_area, int req_tlv_space,
2132 struct tipc_link_config *args;
2136 if (!TLV_CHECK(req_tlv_area, req_tlv_space, TIPC_TLV_LINK_CONFIG))
2137 return tipc_cfg_reply_error_string(TIPC_CFG_TLV_ERROR);
2139 args = (struct tipc_link_config *)TLV_DATA(req_tlv_area);
2140 new_value = ntohl(args->value);
2142 if (!link_value_is_valid(cmd, new_value))
2143 return tipc_cfg_reply_error_string(
2144 "cannot change, value invalid");
2146 if (!strcmp(args->name, tipc_bclink_name)) {
2147 if ((cmd == TIPC_CMD_SET_LINK_WINDOW) &&
2148 (tipc_bclink_set_queue_limits(new_value) == 0))
2149 return tipc_cfg_reply_none();
2150 return tipc_cfg_reply_error_string(TIPC_CFG_NOT_SUPPORTED
2151 " (cannot change setting on broadcast link)");
2154 res = link_cmd_set_value(args->name, new_value, cmd);
2156 return tipc_cfg_reply_error_string("cannot change link setting");
2158 return tipc_cfg_reply_none();
2162 * link_reset_statistics - reset link statistics
2163 * @l_ptr: pointer to link
2165 static void link_reset_statistics(struct tipc_link *l_ptr)
2167 memset(&l_ptr->stats, 0, sizeof(l_ptr->stats));
2168 l_ptr->stats.sent_info = l_ptr->next_out_no;
2169 l_ptr->stats.recv_info = l_ptr->next_in_no;
2172 struct sk_buff *tipc_link_cmd_reset_stats(const void *req_tlv_area, int req_tlv_space)
2175 struct tipc_link *l_ptr;
2176 struct tipc_node *node;
2177 unsigned int bearer_id;
2179 if (!TLV_CHECK(req_tlv_area, req_tlv_space, TIPC_TLV_LINK_NAME))
2180 return tipc_cfg_reply_error_string(TIPC_CFG_TLV_ERROR);
2182 link_name = (char *)TLV_DATA(req_tlv_area);
2183 if (!strcmp(link_name, tipc_bclink_name)) {
2184 if (tipc_bclink_reset_stats())
2185 return tipc_cfg_reply_error_string("link not found");
2186 return tipc_cfg_reply_none();
2188 node = tipc_link_find_owner(link_name, &bearer_id);
2190 return tipc_cfg_reply_error_string("link not found");
2192 tipc_node_lock(node);
2193 l_ptr = node->links[bearer_id];
2195 tipc_node_unlock(node);
2196 return tipc_cfg_reply_error_string("link not found");
2198 link_reset_statistics(l_ptr);
2199 tipc_node_unlock(node);
2200 return tipc_cfg_reply_none();
2204 * percent - convert count to a percentage of total (rounding up or down)
2206 static u32 percent(u32 count, u32 total)
2208 return (count * 100 + (total / 2)) / total;
2212 * tipc_link_stats - print link statistics
2214 * @buf: print buffer area
2215 * @buf_size: size of print buffer area
2217 * Returns length of print buffer data string (or 0 if error)
2219 static int tipc_link_stats(const char *name, char *buf, const u32 buf_size)
2221 struct tipc_link *l;
2222 struct tipc_stats *s;
2223 struct tipc_node *node;
2225 u32 profile_total = 0;
2226 unsigned int bearer_id;
2229 if (!strcmp(name, tipc_bclink_name))
2230 return tipc_bclink_stats(buf, buf_size);
2232 node = tipc_link_find_owner(name, &bearer_id);
2236 tipc_node_lock(node);
2238 l = node->links[bearer_id];
2240 tipc_node_unlock(node);
2246 if (tipc_link_is_active(l))
2248 else if (tipc_link_is_up(l))
2253 ret = tipc_snprintf(buf, buf_size, "Link <%s>\n"
2254 " %s MTU:%u Priority:%u Tolerance:%u ms"
2255 " Window:%u packets\n",
2256 l->name, status, l->max_pkt, l->priority,
2257 l->tolerance, l->queue_limit[0]);
2259 ret += tipc_snprintf(buf + ret, buf_size - ret,
2260 " RX packets:%u fragments:%u/%u bundles:%u/%u\n",
2261 l->next_in_no - s->recv_info, s->recv_fragments,
2262 s->recv_fragmented, s->recv_bundles,
2265 ret += tipc_snprintf(buf + ret, buf_size - ret,
2266 " TX packets:%u fragments:%u/%u bundles:%u/%u\n",
2267 l->next_out_no - s->sent_info, s->sent_fragments,
2268 s->sent_fragmented, s->sent_bundles,
2271 profile_total = s->msg_length_counts;
2275 ret += tipc_snprintf(buf + ret, buf_size - ret,
2276 " TX profile sample:%u packets average:%u octets\n"
2277 " 0-64:%u%% -256:%u%% -1024:%u%% -4096:%u%% "
2278 "-16384:%u%% -32768:%u%% -66000:%u%%\n",
2279 s->msg_length_counts,
2280 s->msg_lengths_total / profile_total,
2281 percent(s->msg_length_profile[0], profile_total),
2282 percent(s->msg_length_profile[1], profile_total),
2283 percent(s->msg_length_profile[2], profile_total),
2284 percent(s->msg_length_profile[3], profile_total),
2285 percent(s->msg_length_profile[4], profile_total),
2286 percent(s->msg_length_profile[5], profile_total),
2287 percent(s->msg_length_profile[6], profile_total));
2289 ret += tipc_snprintf(buf + ret, buf_size - ret,
2290 " RX states:%u probes:%u naks:%u defs:%u"
2291 " dups:%u\n", s->recv_states, s->recv_probes,
2292 s->recv_nacks, s->deferred_recv, s->duplicates);
2294 ret += tipc_snprintf(buf + ret, buf_size - ret,
2295 " TX states:%u probes:%u naks:%u acks:%u"
2296 " dups:%u\n", s->sent_states, s->sent_probes,
2297 s->sent_nacks, s->sent_acks, s->retransmitted);
2299 ret += tipc_snprintf(buf + ret, buf_size - ret,
2300 " Congestion link:%u Send queue"
2301 " max:%u avg:%u\n", s->link_congs,
2302 s->max_queue_sz, s->queue_sz_counts ?
2303 (s->accu_queue_sz / s->queue_sz_counts) : 0);
2305 tipc_node_unlock(node);
2309 struct sk_buff *tipc_link_cmd_show_stats(const void *req_tlv_area, int req_tlv_space)
2311 struct sk_buff *buf;
2312 struct tlv_desc *rep_tlv;
2317 if (!TLV_CHECK(req_tlv_area, req_tlv_space, TIPC_TLV_LINK_NAME))
2318 return tipc_cfg_reply_error_string(TIPC_CFG_TLV_ERROR);
2320 buf = tipc_cfg_reply_alloc(TLV_SPACE(ULTRA_STRING_MAX_LEN));
2324 rep_tlv = (struct tlv_desc *)buf->data;
2325 pb = TLV_DATA(rep_tlv);
2326 pb_len = ULTRA_STRING_MAX_LEN;
2327 str_len = tipc_link_stats((char *)TLV_DATA(req_tlv_area),
2331 return tipc_cfg_reply_error_string("link not found");
2333 str_len += 1; /* for "\0" */
2334 skb_put(buf, TLV_SPACE(str_len));
2335 TLV_SET(rep_tlv, TIPC_TLV_ULTRA_STRING, NULL, str_len);
2341 * tipc_link_get_max_pkt - get maximum packet size to use when sending to destination
2342 * @dest: network address of destination node
2343 * @selector: used to select from set of active links
2345 * If no active link can be found, uses default maximum packet size.
2347 u32 tipc_link_get_max_pkt(u32 dest, u32 selector)
2349 struct tipc_node *n_ptr;
2350 struct tipc_link *l_ptr;
2351 u32 res = MAX_PKT_DEFAULT;
2353 if (dest == tipc_own_addr)
2354 return MAX_MSG_SIZE;
2356 n_ptr = tipc_node_find(dest);
2358 tipc_node_lock(n_ptr);
2359 l_ptr = n_ptr->active_links[selector & 1];
2361 res = l_ptr->max_pkt;
2362 tipc_node_unlock(n_ptr);
2367 static void link_print(struct tipc_link *l_ptr, const char *str)
2369 struct tipc_bearer *b_ptr;
2372 b_ptr = rcu_dereference_rtnl(bearer_list[l_ptr->bearer_id]);
2374 pr_info("%s Link %x<%s>:", str, l_ptr->addr, b_ptr->name);
2377 if (link_working_unknown(l_ptr))
2379 else if (link_reset_reset(l_ptr))
2381 else if (link_reset_unknown(l_ptr))
2383 else if (link_working_working(l_ptr))
2389 /* Parse and validate nested (link) properties valid for media, bearer and link
2391 int tipc_nl_parse_link_prop(struct nlattr *prop, struct nlattr *props[])
2395 err = nla_parse_nested(props, TIPC_NLA_PROP_MAX, prop,
2396 tipc_nl_prop_policy);
2400 if (props[TIPC_NLA_PROP_PRIO]) {
2403 prio = nla_get_u32(props[TIPC_NLA_PROP_PRIO]);
2404 if (prio > TIPC_MAX_LINK_PRI)
2408 if (props[TIPC_NLA_PROP_TOL]) {
2411 tol = nla_get_u32(props[TIPC_NLA_PROP_TOL]);
2412 if ((tol < TIPC_MIN_LINK_TOL) || (tol > TIPC_MAX_LINK_TOL))
2416 if (props[TIPC_NLA_PROP_WIN]) {
2419 win = nla_get_u32(props[TIPC_NLA_PROP_WIN]);
2420 if ((win < TIPC_MIN_LINK_WIN) || (win > TIPC_MAX_LINK_WIN))