2 * net/tipc/link.c: TIPC link code
4 * Copyright (c) 1996-2007, Ericsson AB
5 * Copyright (c) 2004-2007, 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"
46 * Out-of-range value for link session numbers
49 #define INVALID_SESSION 0x10000
52 * Limit for deferred reception queue:
55 #define DEF_QUEUE_LIMIT 256u
61 #define STARTING_EVT 856384768 /* link processing trigger */
62 #define TRAFFIC_MSG_EVT 560815u /* rx'd ??? */
63 #define TIMEOUT_EVT 560817u /* link timer expired */
66 * The following two 'message types' is really just implementation
67 * data conveniently stored in the message header.
68 * They must not be considered part of the protocol
74 * State value stored in 'exp_msg_count'
77 #define START_CHANGEOVER 100000u
80 * struct link_name - deconstructed link name
81 * @addr_local: network address of node at this end
82 * @if_local: name of interface at this end
83 * @addr_peer: network address of node at far end
84 * @if_peer: name of interface at far end
89 char if_local
[TIPC_MAX_IF_NAME
];
91 char if_peer
[TIPC_MAX_IF_NAME
];
94 static void link_handle_out_of_seq_msg(struct link
*l_ptr
,
96 static void link_recv_proto_msg(struct link
*l_ptr
, struct sk_buff
*buf
);
97 static int link_recv_changeover_msg(struct link
**l_ptr
, struct sk_buff
**buf
);
98 static void link_set_supervision_props(struct link
*l_ptr
, u32 tolerance
);
99 static int link_send_sections_long(struct port
*sender
,
100 struct iovec
const *msg_sect
,
101 u32 num_sect
, u32 destnode
);
102 static void link_check_defragm_bufs(struct link
*l_ptr
);
103 static void link_state_event(struct link
*l_ptr
, u32 event
);
104 static void link_reset_statistics(struct link
*l_ptr
);
105 static void link_print(struct link
*l_ptr
, struct print_buf
*buf
,
107 static void link_start(struct link
*l_ptr
);
108 static int link_send_long_buf(struct link
*l_ptr
, struct sk_buff
*buf
);
112 * Debugging code used by link routines only
114 * When debugging link problems on a system that has multiple links,
115 * the standard TIPC debugging routines may not be useful since they
116 * allow the output from multiple links to be intermixed. For this reason
117 * routines of the form "dbg_link_XXX()" have been created that will capture
118 * debug info into a link's personal print buffer, which can then be dumped
119 * into the TIPC system log (TIPC_LOG) upon request.
121 * To enable per-link debugging, use LINK_LOG_BUF_SIZE to specify the size
122 * of the print buffer used by each link. If LINK_LOG_BUF_SIZE is set to 0,
123 * the dbg_link_XXX() routines simply send their output to the standard
124 * debug print buffer (DBG_OUTPUT), if it has been defined; this can be useful
125 * when there is only a single link in the system being debugged.
128 * - When enabled, LINK_LOG_BUF_SIZE should be set to at least TIPC_PB_MIN_SIZE
129 * - "l_ptr" must be valid when using dbg_link_XXX() macros
132 #define LINK_LOG_BUF_SIZE 0
134 #define dbg_link(fmt, arg...) \
136 if (LINK_LOG_BUF_SIZE) \
137 tipc_printf(&l_ptr->print_buf, fmt, ## arg); \
139 #define dbg_link_msg(msg, txt) \
141 if (LINK_LOG_BUF_SIZE) \
142 tipc_msg_dbg(&l_ptr->print_buf, msg, txt); \
144 #define dbg_link_state(txt) \
146 if (LINK_LOG_BUF_SIZE) \
147 link_print(l_ptr, &l_ptr->print_buf, txt); \
149 #define dbg_link_dump() do { \
150 if (LINK_LOG_BUF_SIZE) { \
151 tipc_printf(LOG, "\n\nDumping link <%s>:\n", l_ptr->name); \
152 tipc_printbuf_move(LOG, &l_ptr->print_buf); \
156 static void dbg_print_link(struct link
*l_ptr
, const char *str
)
158 if (DBG_OUTPUT
!= TIPC_NULL
)
159 link_print(l_ptr
, DBG_OUTPUT
, str
);
162 static void dbg_print_buf_chain(struct sk_buff
*root_buf
)
164 if (DBG_OUTPUT
!= TIPC_NULL
) {
165 struct sk_buff
*buf
= root_buf
;
168 msg_dbg(buf_msg(buf
), "In chain: ");
175 * Simple link routines
178 static unsigned int align(unsigned int i
)
180 return (i
+ 3) & ~3u;
183 static void link_init_max_pkt(struct link
*l_ptr
)
187 max_pkt
= (l_ptr
->b_ptr
->publ
.mtu
& ~3);
188 if (max_pkt
> MAX_MSG_SIZE
)
189 max_pkt
= MAX_MSG_SIZE
;
191 l_ptr
->max_pkt_target
= max_pkt
;
192 if (l_ptr
->max_pkt_target
< MAX_PKT_DEFAULT
)
193 l_ptr
->max_pkt
= l_ptr
->max_pkt_target
;
195 l_ptr
->max_pkt
= MAX_PKT_DEFAULT
;
197 l_ptr
->max_pkt_probes
= 0;
200 static u32
link_next_sent(struct link
*l_ptr
)
203 return msg_seqno(buf_msg(l_ptr
->next_out
));
204 return mod(l_ptr
->next_out_no
);
207 static u32
link_last_sent(struct link
*l_ptr
)
209 return mod(link_next_sent(l_ptr
) - 1);
213 * Simple non-static link routines (i.e. referenced outside this file)
216 int tipc_link_is_up(struct link
*l_ptr
)
220 return link_working_working(l_ptr
) || link_working_unknown(l_ptr
);
223 int tipc_link_is_active(struct link
*l_ptr
)
225 return (l_ptr
->owner
->active_links
[0] == l_ptr
) ||
226 (l_ptr
->owner
->active_links
[1] == l_ptr
);
230 * link_name_validate - validate & (optionally) deconstruct link name
231 * @name - ptr to link name string
232 * @name_parts - ptr to area for link name components (or NULL if not needed)
234 * Returns 1 if link name is valid, otherwise 0.
237 static int link_name_validate(const char *name
, struct link_name
*name_parts
)
239 char name_copy
[TIPC_MAX_LINK_NAME
];
245 u32 z_local
, c_local
, n_local
;
246 u32 z_peer
, c_peer
, n_peer
;
250 /* copy link name & ensure length is OK */
252 name_copy
[TIPC_MAX_LINK_NAME
- 1] = 0;
253 /* need above in case non-Posix strncpy() doesn't pad with nulls */
254 strncpy(name_copy
, name
, TIPC_MAX_LINK_NAME
);
255 if (name_copy
[TIPC_MAX_LINK_NAME
- 1] != 0)
258 /* ensure all component parts of link name are present */
260 addr_local
= name_copy
;
261 if ((if_local
= strchr(addr_local
, ':')) == NULL
)
264 if ((addr_peer
= strchr(if_local
, '-')) == NULL
)
267 if_local_len
= addr_peer
- if_local
;
268 if ((if_peer
= strchr(addr_peer
, ':')) == NULL
)
271 if_peer_len
= strlen(if_peer
) + 1;
273 /* validate component parts of link name */
275 if ((sscanf(addr_local
, "%u.%u.%u%c",
276 &z_local
, &c_local
, &n_local
, &dummy
) != 3) ||
277 (sscanf(addr_peer
, "%u.%u.%u%c",
278 &z_peer
, &c_peer
, &n_peer
, &dummy
) != 3) ||
279 (z_local
> 255) || (c_local
> 4095) || (n_local
> 4095) ||
280 (z_peer
> 255) || (c_peer
> 4095) || (n_peer
> 4095) ||
281 (if_local_len
<= 1) || (if_local_len
> TIPC_MAX_IF_NAME
) ||
282 (if_peer_len
<= 1) || (if_peer_len
> TIPC_MAX_IF_NAME
) ||
283 (strspn(if_local
, tipc_alphabet
) != (if_local_len
- 1)) ||
284 (strspn(if_peer
, tipc_alphabet
) != (if_peer_len
- 1)))
287 /* return link name components, if necessary */
290 name_parts
->addr_local
= tipc_addr(z_local
, c_local
, n_local
);
291 strcpy(name_parts
->if_local
, if_local
);
292 name_parts
->addr_peer
= tipc_addr(z_peer
, c_peer
, n_peer
);
293 strcpy(name_parts
->if_peer
, if_peer
);
299 * link_timeout - handle expiration of link timer
300 * @l_ptr: pointer to link
302 * This routine must not grab "tipc_net_lock" to avoid a potential deadlock conflict
303 * with tipc_link_delete(). (There is no risk that the node will be deleted by
304 * another thread because tipc_link_delete() always cancels the link timer before
305 * tipc_node_delete() is called.)
308 static void link_timeout(struct link
*l_ptr
)
310 tipc_node_lock(l_ptr
->owner
);
312 /* update counters used in statistical profiling of send traffic */
314 l_ptr
->stats
.accu_queue_sz
+= l_ptr
->out_queue_size
;
315 l_ptr
->stats
.queue_sz_counts
++;
317 if (l_ptr
->out_queue_size
> l_ptr
->stats
.max_queue_sz
)
318 l_ptr
->stats
.max_queue_sz
= l_ptr
->out_queue_size
;
320 if (l_ptr
->first_out
) {
321 struct tipc_msg
*msg
= buf_msg(l_ptr
->first_out
);
322 u32 length
= msg_size(msg
);
324 if ((msg_user(msg
) == MSG_FRAGMENTER
) &&
325 (msg_type(msg
) == FIRST_FRAGMENT
)) {
326 length
= msg_size(msg_get_wrapped(msg
));
329 l_ptr
->stats
.msg_lengths_total
+= length
;
330 l_ptr
->stats
.msg_length_counts
++;
332 l_ptr
->stats
.msg_length_profile
[0]++;
333 else if (length
<= 256)
334 l_ptr
->stats
.msg_length_profile
[1]++;
335 else if (length
<= 1024)
336 l_ptr
->stats
.msg_length_profile
[2]++;
337 else if (length
<= 4096)
338 l_ptr
->stats
.msg_length_profile
[3]++;
339 else if (length
<= 16384)
340 l_ptr
->stats
.msg_length_profile
[4]++;
341 else if (length
<= 32768)
342 l_ptr
->stats
.msg_length_profile
[5]++;
344 l_ptr
->stats
.msg_length_profile
[6]++;
348 /* do all other link processing performed on a periodic basis */
350 link_check_defragm_bufs(l_ptr
);
352 link_state_event(l_ptr
, TIMEOUT_EVT
);
355 tipc_link_push_queue(l_ptr
);
357 tipc_node_unlock(l_ptr
->owner
);
360 static void link_set_timer(struct link
*l_ptr
, u32 time
)
362 k_start_timer(&l_ptr
->timer
, time
);
366 * tipc_link_create - create a new link
367 * @b_ptr: pointer to associated bearer
368 * @peer: network address of node at other end of link
369 * @media_addr: media address to use when sending messages over link
371 * Returns pointer to link.
374 struct link
*tipc_link_create(struct bearer
*b_ptr
, const u32 peer
,
375 const struct tipc_media_addr
*media_addr
)
378 struct tipc_msg
*msg
;
381 l_ptr
= kzalloc(sizeof(*l_ptr
), GFP_ATOMIC
);
383 warn("Link creation failed, no memory\n");
387 if (LINK_LOG_BUF_SIZE
) {
388 char *pb
= kmalloc(LINK_LOG_BUF_SIZE
, GFP_ATOMIC
);
392 warn("Link creation failed, no memory for print buffer\n");
395 tipc_printbuf_init(&l_ptr
->print_buf
, pb
, LINK_LOG_BUF_SIZE
);
399 if_name
= strchr(b_ptr
->publ
.name
, ':') + 1;
400 sprintf(l_ptr
->name
, "%u.%u.%u:%s-%u.%u.%u:",
401 tipc_zone(tipc_own_addr
), tipc_cluster(tipc_own_addr
),
402 tipc_node(tipc_own_addr
),
404 tipc_zone(peer
), tipc_cluster(peer
), tipc_node(peer
));
405 /* note: peer i/f is appended to link name by reset/activate */
406 memcpy(&l_ptr
->media_addr
, media_addr
, sizeof(*media_addr
));
407 l_ptr
->checkpoint
= 1;
408 l_ptr
->b_ptr
= b_ptr
;
409 link_set_supervision_props(l_ptr
, b_ptr
->media
->tolerance
);
410 l_ptr
->state
= RESET_UNKNOWN
;
412 l_ptr
->pmsg
= (struct tipc_msg
*)&l_ptr
->proto_msg
;
414 tipc_msg_init(msg
, LINK_PROTOCOL
, RESET_MSG
, INT_H_SIZE
, l_ptr
->addr
);
415 msg_set_size(msg
, sizeof(l_ptr
->proto_msg
));
416 msg_set_session(msg
, (tipc_random
& 0xffff));
417 msg_set_bearer_id(msg
, b_ptr
->identity
);
418 strcpy((char *)msg_data(msg
), if_name
);
420 l_ptr
->priority
= b_ptr
->priority
;
421 tipc_link_set_queue_limits(l_ptr
, b_ptr
->media
->window
);
423 link_init_max_pkt(l_ptr
);
425 l_ptr
->next_out_no
= 1;
426 INIT_LIST_HEAD(&l_ptr
->waiting_ports
);
428 link_reset_statistics(l_ptr
);
430 l_ptr
->owner
= tipc_node_attach_link(l_ptr
);
432 if (LINK_LOG_BUF_SIZE
)
433 kfree(l_ptr
->print_buf
.buf
);
438 k_init_timer(&l_ptr
->timer
, (Handler
)link_timeout
, (unsigned long)l_ptr
);
439 list_add_tail(&l_ptr
->link_list
, &b_ptr
->links
);
440 tipc_k_signal((Handler
)link_start
, (unsigned long)l_ptr
);
442 dbg("tipc_link_create(): tolerance = %u,cont intv = %u, abort_limit = %u\n",
443 l_ptr
->tolerance
, l_ptr
->continuity_interval
, l_ptr
->abort_limit
);
449 * tipc_link_delete - delete a link
450 * @l_ptr: pointer to link
452 * Note: 'tipc_net_lock' is write_locked, bearer is locked.
453 * This routine must not grab the node lock until after link timer cancellation
454 * to avoid a potential deadlock situation.
457 void tipc_link_delete(struct link
*l_ptr
)
460 err("Attempt to delete non-existent link\n");
464 dbg("tipc_link_delete()\n");
466 k_cancel_timer(&l_ptr
->timer
);
468 tipc_node_lock(l_ptr
->owner
);
469 tipc_link_reset(l_ptr
);
470 tipc_node_detach_link(l_ptr
->owner
, l_ptr
);
471 tipc_link_stop(l_ptr
);
472 list_del_init(&l_ptr
->link_list
);
473 if (LINK_LOG_BUF_SIZE
)
474 kfree(l_ptr
->print_buf
.buf
);
475 tipc_node_unlock(l_ptr
->owner
);
476 k_term_timer(&l_ptr
->timer
);
480 static void link_start(struct link
*l_ptr
)
482 dbg("link_start %x\n", l_ptr
);
483 link_state_event(l_ptr
, STARTING_EVT
);
487 * link_schedule_port - schedule port for deferred sending
488 * @l_ptr: pointer to link
489 * @origport: reference to sending port
490 * @sz: amount of data to be sent
492 * Schedules port for renewed sending of messages after link congestion
496 static int link_schedule_port(struct link
*l_ptr
, u32 origport
, u32 sz
)
500 spin_lock_bh(&tipc_port_list_lock
);
501 p_ptr
= tipc_port_lock(origport
);
505 if (!list_empty(&p_ptr
->wait_list
))
507 p_ptr
->publ
.congested
= 1;
508 p_ptr
->waiting_pkts
= 1 + ((sz
- 1) / l_ptr
->max_pkt
);
509 list_add_tail(&p_ptr
->wait_list
, &l_ptr
->waiting_ports
);
510 l_ptr
->stats
.link_congs
++;
512 tipc_port_unlock(p_ptr
);
514 spin_unlock_bh(&tipc_port_list_lock
);
518 void tipc_link_wakeup_ports(struct link
*l_ptr
, int all
)
521 struct port
*temp_p_ptr
;
522 int win
= l_ptr
->queue_limit
[0] - l_ptr
->out_queue_size
;
528 if (!spin_trylock_bh(&tipc_port_list_lock
))
530 if (link_congested(l_ptr
))
532 list_for_each_entry_safe(p_ptr
, temp_p_ptr
, &l_ptr
->waiting_ports
,
536 list_del_init(&p_ptr
->wait_list
);
537 spin_lock_bh(p_ptr
->publ
.lock
);
538 p_ptr
->publ
.congested
= 0;
539 p_ptr
->wakeup(&p_ptr
->publ
);
540 win
-= p_ptr
->waiting_pkts
;
541 spin_unlock_bh(p_ptr
->publ
.lock
);
545 spin_unlock_bh(&tipc_port_list_lock
);
549 * link_release_outqueue - purge link's outbound message queue
550 * @l_ptr: pointer to link
553 static void link_release_outqueue(struct link
*l_ptr
)
555 struct sk_buff
*buf
= l_ptr
->first_out
;
556 struct sk_buff
*next
;
563 l_ptr
->first_out
= NULL
;
564 l_ptr
->out_queue_size
= 0;
568 * tipc_link_reset_fragments - purge link's inbound message fragments queue
569 * @l_ptr: pointer to link
572 void tipc_link_reset_fragments(struct link
*l_ptr
)
574 struct sk_buff
*buf
= l_ptr
->defragm_buf
;
575 struct sk_buff
*next
;
582 l_ptr
->defragm_buf
= NULL
;
586 * tipc_link_stop - purge all inbound and outbound messages associated with link
587 * @l_ptr: pointer to link
590 void tipc_link_stop(struct link
*l_ptr
)
593 struct sk_buff
*next
;
595 buf
= l_ptr
->oldest_deferred_in
;
602 buf
= l_ptr
->first_out
;
609 tipc_link_reset_fragments(l_ptr
);
611 buf_discard(l_ptr
->proto_msg_queue
);
612 l_ptr
->proto_msg_queue
= NULL
;
615 /* LINK EVENT CODE IS NOT SUPPORTED AT PRESENT */
616 #define link_send_event(fcn, l_ptr, up) do { } while (0)
618 void tipc_link_reset(struct link
*l_ptr
)
621 u32 prev_state
= l_ptr
->state
;
622 u32 checkpoint
= l_ptr
->next_in_no
;
623 int was_active_link
= tipc_link_is_active(l_ptr
);
625 msg_set_session(l_ptr
->pmsg
, ((msg_session(l_ptr
->pmsg
) + 1) & 0xffff));
627 /* Link is down, accept any session */
628 l_ptr
->peer_session
= INVALID_SESSION
;
630 /* Prepare for max packet size negotiation */
631 link_init_max_pkt(l_ptr
);
633 l_ptr
->state
= RESET_UNKNOWN
;
634 dbg_link_state("Resetting Link\n");
636 if ((prev_state
== RESET_UNKNOWN
) || (prev_state
== RESET_RESET
))
639 tipc_node_link_down(l_ptr
->owner
, l_ptr
);
640 tipc_bearer_remove_dest(l_ptr
->b_ptr
, l_ptr
->addr
);
642 if (was_active_link
&& tipc_node_has_active_links(l_ptr
->owner
) &&
643 l_ptr
->owner
->permit_changeover
) {
644 l_ptr
->reset_checkpoint
= checkpoint
;
645 l_ptr
->exp_msg_count
= START_CHANGEOVER
;
648 /* Clean up all queues: */
650 link_release_outqueue(l_ptr
);
651 buf_discard(l_ptr
->proto_msg_queue
);
652 l_ptr
->proto_msg_queue
= NULL
;
653 buf
= l_ptr
->oldest_deferred_in
;
655 struct sk_buff
*next
= buf
->next
;
659 if (!list_empty(&l_ptr
->waiting_ports
))
660 tipc_link_wakeup_ports(l_ptr
, 1);
662 l_ptr
->retransm_queue_head
= 0;
663 l_ptr
->retransm_queue_size
= 0;
664 l_ptr
->last_out
= NULL
;
665 l_ptr
->first_out
= NULL
;
666 l_ptr
->next_out
= NULL
;
667 l_ptr
->unacked_window
= 0;
668 l_ptr
->checkpoint
= 1;
669 l_ptr
->next_out_no
= 1;
670 l_ptr
->deferred_inqueue_sz
= 0;
671 l_ptr
->oldest_deferred_in
= NULL
;
672 l_ptr
->newest_deferred_in
= NULL
;
673 l_ptr
->fsm_msg_cnt
= 0;
674 l_ptr
->stale_count
= 0;
675 link_reset_statistics(l_ptr
);
677 link_send_event(tipc_cfg_link_event
, l_ptr
, 0);
678 if (!in_own_cluster(l_ptr
->addr
))
679 link_send_event(tipc_disc_link_event
, l_ptr
, 0);
683 static void link_activate(struct link
*l_ptr
)
685 l_ptr
->next_in_no
= l_ptr
->stats
.recv_info
= 1;
686 tipc_node_link_up(l_ptr
->owner
, l_ptr
);
687 tipc_bearer_add_dest(l_ptr
->b_ptr
, l_ptr
->addr
);
688 link_send_event(tipc_cfg_link_event
, l_ptr
, 1);
689 if (!in_own_cluster(l_ptr
->addr
))
690 link_send_event(tipc_disc_link_event
, l_ptr
, 1);
694 * link_state_event - link finite state machine
695 * @l_ptr: pointer to link
696 * @event: state machine event to process
699 static void link_state_event(struct link
*l_ptr
, unsigned event
)
702 u32 cont_intv
= l_ptr
->continuity_interval
;
704 if (!l_ptr
->started
&& (event
!= STARTING_EVT
))
705 return; /* Not yet. */
707 if (link_blocked(l_ptr
)) {
708 if (event
== TIMEOUT_EVT
) {
709 link_set_timer(l_ptr
, cont_intv
);
711 return; /* Changeover going on */
713 dbg_link("STATE_EV: <%s> ", l_ptr
->name
);
715 switch (l_ptr
->state
) {
716 case WORKING_WORKING
:
719 case TRAFFIC_MSG_EVT
:
727 if (l_ptr
->next_in_no
!= l_ptr
->checkpoint
) {
728 l_ptr
->checkpoint
= l_ptr
->next_in_no
;
729 if (tipc_bclink_acks_missing(l_ptr
->owner
)) {
730 tipc_link_send_proto_msg(l_ptr
, STATE_MSG
,
732 l_ptr
->fsm_msg_cnt
++;
733 } else if (l_ptr
->max_pkt
< l_ptr
->max_pkt_target
) {
734 tipc_link_send_proto_msg(l_ptr
, STATE_MSG
,
736 l_ptr
->fsm_msg_cnt
++;
738 link_set_timer(l_ptr
, cont_intv
);
741 dbg_link(" -> WU\n");
742 l_ptr
->state
= WORKING_UNKNOWN
;
743 l_ptr
->fsm_msg_cnt
= 0;
744 tipc_link_send_proto_msg(l_ptr
, STATE_MSG
, 1, 0, 0, 0, 0);
745 l_ptr
->fsm_msg_cnt
++;
746 link_set_timer(l_ptr
, cont_intv
/ 4);
749 dbg_link("RES -> RR\n");
750 info("Resetting link <%s>, requested by peer\n",
752 tipc_link_reset(l_ptr
);
753 l_ptr
->state
= RESET_RESET
;
754 l_ptr
->fsm_msg_cnt
= 0;
755 tipc_link_send_proto_msg(l_ptr
, ACTIVATE_MSG
, 0, 0, 0, 0, 0);
756 l_ptr
->fsm_msg_cnt
++;
757 link_set_timer(l_ptr
, cont_intv
);
760 err("Unknown link event %u in WW state\n", event
);
763 case WORKING_UNKNOWN
:
766 case TRAFFIC_MSG_EVT
:
769 dbg_link("ACT -> WW\n");
770 l_ptr
->state
= WORKING_WORKING
;
771 l_ptr
->fsm_msg_cnt
= 0;
772 link_set_timer(l_ptr
, cont_intv
);
775 dbg_link("RES -> RR\n");
776 info("Resetting link <%s>, requested by peer "
777 "while probing\n", l_ptr
->name
);
778 tipc_link_reset(l_ptr
);
779 l_ptr
->state
= RESET_RESET
;
780 l_ptr
->fsm_msg_cnt
= 0;
781 tipc_link_send_proto_msg(l_ptr
, ACTIVATE_MSG
, 0, 0, 0, 0, 0);
782 l_ptr
->fsm_msg_cnt
++;
783 link_set_timer(l_ptr
, cont_intv
);
787 if (l_ptr
->next_in_no
!= l_ptr
->checkpoint
) {
789 l_ptr
->state
= WORKING_WORKING
;
790 l_ptr
->fsm_msg_cnt
= 0;
791 l_ptr
->checkpoint
= l_ptr
->next_in_no
;
792 if (tipc_bclink_acks_missing(l_ptr
->owner
)) {
793 tipc_link_send_proto_msg(l_ptr
, STATE_MSG
,
795 l_ptr
->fsm_msg_cnt
++;
797 link_set_timer(l_ptr
, cont_intv
);
798 } else if (l_ptr
->fsm_msg_cnt
< l_ptr
->abort_limit
) {
799 dbg_link("Probing %u/%u,timer = %u ms)\n",
800 l_ptr
->fsm_msg_cnt
, l_ptr
->abort_limit
,
802 tipc_link_send_proto_msg(l_ptr
, STATE_MSG
,
804 l_ptr
->fsm_msg_cnt
++;
805 link_set_timer(l_ptr
, cont_intv
/ 4);
806 } else { /* Link has failed */
807 dbg_link("-> RU (%u probes unanswered)\n",
809 warn("Resetting link <%s>, peer not responding\n",
811 tipc_link_reset(l_ptr
);
812 l_ptr
->state
= RESET_UNKNOWN
;
813 l_ptr
->fsm_msg_cnt
= 0;
814 tipc_link_send_proto_msg(l_ptr
, RESET_MSG
,
816 l_ptr
->fsm_msg_cnt
++;
817 link_set_timer(l_ptr
, cont_intv
);
821 err("Unknown link event %u in WU state\n", event
);
827 case TRAFFIC_MSG_EVT
:
831 other
= l_ptr
->owner
->active_links
[0];
832 if (other
&& link_working_unknown(other
)) {
836 dbg_link("ACT -> WW\n");
837 l_ptr
->state
= WORKING_WORKING
;
838 l_ptr
->fsm_msg_cnt
= 0;
839 link_activate(l_ptr
);
840 tipc_link_send_proto_msg(l_ptr
, STATE_MSG
, 1, 0, 0, 0, 0);
841 l_ptr
->fsm_msg_cnt
++;
842 link_set_timer(l_ptr
, cont_intv
);
846 dbg_link(" -> RR\n");
847 l_ptr
->state
= RESET_RESET
;
848 l_ptr
->fsm_msg_cnt
= 0;
849 tipc_link_send_proto_msg(l_ptr
, ACTIVATE_MSG
, 1, 0, 0, 0, 0);
850 l_ptr
->fsm_msg_cnt
++;
851 link_set_timer(l_ptr
, cont_intv
);
859 tipc_link_send_proto_msg(l_ptr
, RESET_MSG
, 0, 0, 0, 0, 0);
860 l_ptr
->fsm_msg_cnt
++;
861 link_set_timer(l_ptr
, cont_intv
);
864 err("Unknown link event %u in RU state\n", event
);
870 case TRAFFIC_MSG_EVT
:
874 other
= l_ptr
->owner
->active_links
[0];
875 if (other
&& link_working_unknown(other
)) {
879 dbg_link("ACT -> WW\n");
880 l_ptr
->state
= WORKING_WORKING
;
881 l_ptr
->fsm_msg_cnt
= 0;
882 link_activate(l_ptr
);
883 tipc_link_send_proto_msg(l_ptr
, STATE_MSG
, 1, 0, 0, 0, 0);
884 l_ptr
->fsm_msg_cnt
++;
885 link_set_timer(l_ptr
, cont_intv
);
892 tipc_link_send_proto_msg(l_ptr
, ACTIVATE_MSG
, 0, 0, 0, 0, 0);
893 l_ptr
->fsm_msg_cnt
++;
894 link_set_timer(l_ptr
, cont_intv
);
895 dbg_link("fsm_msg_cnt %u\n", l_ptr
->fsm_msg_cnt
);
898 err("Unknown link event %u in RR state\n", event
);
902 err("Unknown link state %u/%u\n", l_ptr
->state
, event
);
907 * link_bundle_buf(): Append contents of a buffer to
908 * the tail of an existing one.
911 static int link_bundle_buf(struct link
*l_ptr
,
912 struct sk_buff
*bundler
,
915 struct tipc_msg
*bundler_msg
= buf_msg(bundler
);
916 struct tipc_msg
*msg
= buf_msg(buf
);
917 u32 size
= msg_size(msg
);
918 u32 bundle_size
= msg_size(bundler_msg
);
919 u32 to_pos
= align(bundle_size
);
920 u32 pad
= to_pos
- bundle_size
;
922 if (msg_user(bundler_msg
) != MSG_BUNDLER
)
924 if (msg_type(bundler_msg
) != OPEN_MSG
)
926 if (skb_tailroom(bundler
) < (pad
+ size
))
928 if (l_ptr
->max_pkt
< (to_pos
+ size
))
931 skb_put(bundler
, pad
+ size
);
932 skb_copy_to_linear_data_offset(bundler
, to_pos
, buf
->data
, size
);
933 msg_set_size(bundler_msg
, to_pos
+ size
);
934 msg_set_msgcnt(bundler_msg
, msg_msgcnt(bundler_msg
) + 1);
935 dbg("Packed msg # %u(%u octets) into pos %u in buf(#%u)\n",
936 msg_msgcnt(bundler_msg
), size
, to_pos
, msg_seqno(bundler_msg
));
937 msg_dbg(msg
, "PACKD:");
939 l_ptr
->stats
.sent_bundled
++;
943 static void link_add_to_outqueue(struct link
*l_ptr
,
945 struct tipc_msg
*msg
)
947 u32 ack
= mod(l_ptr
->next_in_no
- 1);
948 u32 seqno
= mod(l_ptr
->next_out_no
++);
950 msg_set_word(msg
, 2, ((ack
<< 16) | seqno
));
951 msg_set_bcast_ack(msg
, l_ptr
->owner
->bclink
.last_in
);
953 if (l_ptr
->first_out
) {
954 l_ptr
->last_out
->next
= buf
;
955 l_ptr
->last_out
= buf
;
957 l_ptr
->first_out
= l_ptr
->last_out
= buf
;
958 l_ptr
->out_queue_size
++;
962 * tipc_link_send_buf() is the 'full path' for messages, called from
963 * inside TIPC when the 'fast path' in tipc_send_buf
964 * has failed, and from link_send()
967 int tipc_link_send_buf(struct link
*l_ptr
, struct sk_buff
*buf
)
969 struct tipc_msg
*msg
= buf_msg(buf
);
970 u32 size
= msg_size(msg
);
971 u32 dsz
= msg_data_sz(msg
);
972 u32 queue_size
= l_ptr
->out_queue_size
;
973 u32 imp
= tipc_msg_tot_importance(msg
);
974 u32 queue_limit
= l_ptr
->queue_limit
[imp
];
975 u32 max_packet
= l_ptr
->max_pkt
;
977 msg_set_prevnode(msg
, tipc_own_addr
); /* If routed message */
979 /* Match msg importance against queue limits: */
981 if (unlikely(queue_size
>= queue_limit
)) {
982 if (imp
<= TIPC_CRITICAL_IMPORTANCE
) {
983 return link_schedule_port(l_ptr
, msg_origport(msg
),
986 msg_dbg(msg
, "TIPC: Congestion, throwing away\n");
988 if (imp
> CONN_MANAGER
) {
989 warn("Resetting link <%s>, send queue full", l_ptr
->name
);
990 tipc_link_reset(l_ptr
);
995 /* Fragmentation needed ? */
997 if (size
> max_packet
)
998 return link_send_long_buf(l_ptr
, buf
);
1000 /* Packet can be queued or sent: */
1002 if (queue_size
> l_ptr
->stats
.max_queue_sz
)
1003 l_ptr
->stats
.max_queue_sz
= queue_size
;
1005 if (likely(!tipc_bearer_congested(l_ptr
->b_ptr
, l_ptr
) &&
1006 !link_congested(l_ptr
))) {
1007 link_add_to_outqueue(l_ptr
, buf
, msg
);
1009 if (likely(tipc_bearer_send(l_ptr
->b_ptr
, buf
, &l_ptr
->media_addr
))) {
1010 l_ptr
->unacked_window
= 0;
1012 tipc_bearer_schedule(l_ptr
->b_ptr
, l_ptr
);
1013 l_ptr
->stats
.bearer_congs
++;
1014 l_ptr
->next_out
= buf
;
1018 /* Congestion: can message be bundled ?: */
1020 if ((msg_user(msg
) != CHANGEOVER_PROTOCOL
) &&
1021 (msg_user(msg
) != MSG_FRAGMENTER
)) {
1023 /* Try adding message to an existing bundle */
1025 if (l_ptr
->next_out
&&
1026 link_bundle_buf(l_ptr
, l_ptr
->last_out
, buf
)) {
1027 tipc_bearer_resolve_congestion(l_ptr
->b_ptr
, l_ptr
);
1031 /* Try creating a new bundle */
1033 if (size
<= max_packet
* 2 / 3) {
1034 struct sk_buff
*bundler
= tipc_buf_acquire(max_packet
);
1035 struct tipc_msg bundler_hdr
;
1038 tipc_msg_init(&bundler_hdr
, MSG_BUNDLER
, OPEN_MSG
,
1039 INT_H_SIZE
, l_ptr
->addr
);
1040 skb_copy_to_linear_data(bundler
, &bundler_hdr
,
1042 skb_trim(bundler
, INT_H_SIZE
);
1043 link_bundle_buf(l_ptr
, bundler
, buf
);
1046 l_ptr
->stats
.sent_bundles
++;
1050 if (!l_ptr
->next_out
)
1051 l_ptr
->next_out
= buf
;
1052 link_add_to_outqueue(l_ptr
, buf
, msg
);
1053 tipc_bearer_resolve_congestion(l_ptr
->b_ptr
, l_ptr
);
1058 * tipc_link_send(): same as tipc_link_send_buf(), but the link to use has
1059 * not been selected yet, and the the owner node is not locked
1060 * Called by TIPC internal users, e.g. the name distributor
1063 int tipc_link_send(struct sk_buff
*buf
, u32 dest
, u32 selector
)
1066 struct tipc_node
*n_ptr
;
1067 int res
= -ELINKCONG
;
1069 read_lock_bh(&tipc_net_lock
);
1070 n_ptr
= tipc_node_select(dest
, selector
);
1072 tipc_node_lock(n_ptr
);
1073 l_ptr
= n_ptr
->active_links
[selector
& 1];
1075 dbg("tipc_link_send: found link %x for dest %x\n", l_ptr
, dest
);
1076 res
= tipc_link_send_buf(l_ptr
, buf
);
1078 dbg("Attempt to send msg to unreachable node:\n");
1079 msg_dbg(buf_msg(buf
),">>>");
1082 tipc_node_unlock(n_ptr
);
1084 dbg("Attempt to send msg to unknown node:\n");
1085 msg_dbg(buf_msg(buf
),">>>");
1088 read_unlock_bh(&tipc_net_lock
);
1093 * link_send_buf_fast: Entry for data messages where the
1094 * destination link is known and the header is complete,
1095 * inclusive total message length. Very time critical.
1096 * Link is locked. Returns user data length.
1099 static int link_send_buf_fast(struct link
*l_ptr
, struct sk_buff
*buf
,
1102 struct tipc_msg
*msg
= buf_msg(buf
);
1103 int res
= msg_data_sz(msg
);
1105 if (likely(!link_congested(l_ptr
))) {
1106 if (likely(msg_size(msg
) <= l_ptr
->max_pkt
)) {
1107 if (likely(list_empty(&l_ptr
->b_ptr
->cong_links
))) {
1108 link_add_to_outqueue(l_ptr
, buf
, msg
);
1109 if (likely(tipc_bearer_send(l_ptr
->b_ptr
, buf
,
1110 &l_ptr
->media_addr
))) {
1111 l_ptr
->unacked_window
= 0;
1112 msg_dbg(msg
,"SENT_FAST:");
1115 dbg("failed sent fast...\n");
1116 tipc_bearer_schedule(l_ptr
->b_ptr
, l_ptr
);
1117 l_ptr
->stats
.bearer_congs
++;
1118 l_ptr
->next_out
= buf
;
1123 *used_max_pkt
= l_ptr
->max_pkt
;
1125 return tipc_link_send_buf(l_ptr
, buf
); /* All other cases */
1129 * tipc_send_buf_fast: Entry for data messages where the
1130 * destination node is known and the header is complete,
1131 * inclusive total message length.
1132 * Returns user data length.
1134 int tipc_send_buf_fast(struct sk_buff
*buf
, u32 destnode
)
1137 struct tipc_node
*n_ptr
;
1139 u32 selector
= msg_origport(buf_msg(buf
)) & 1;
1142 if (destnode
== tipc_own_addr
)
1143 return tipc_port_recv_msg(buf
);
1145 read_lock_bh(&tipc_net_lock
);
1146 n_ptr
= tipc_node_select(destnode
, selector
);
1147 if (likely(n_ptr
)) {
1148 tipc_node_lock(n_ptr
);
1149 l_ptr
= n_ptr
->active_links
[selector
];
1150 dbg("send_fast: buf %x selected %x, destnode = %x\n",
1151 buf
, l_ptr
, destnode
);
1152 if (likely(l_ptr
)) {
1153 res
= link_send_buf_fast(l_ptr
, buf
, &dummy
);
1154 tipc_node_unlock(n_ptr
);
1155 read_unlock_bh(&tipc_net_lock
);
1158 tipc_node_unlock(n_ptr
);
1160 read_unlock_bh(&tipc_net_lock
);
1161 res
= msg_data_sz(buf_msg(buf
));
1162 tipc_reject_msg(buf
, TIPC_ERR_NO_NODE
);
1168 * tipc_link_send_sections_fast: Entry for messages where the
1169 * destination processor is known and the header is complete,
1170 * except for total message length.
1171 * Returns user data length or errno.
1173 int tipc_link_send_sections_fast(struct port
*sender
,
1174 struct iovec
const *msg_sect
,
1178 struct tipc_msg
*hdr
= &sender
->publ
.phdr
;
1180 struct sk_buff
*buf
;
1181 struct tipc_node
*node
;
1183 u32 selector
= msg_origport(hdr
) & 1;
1187 * Try building message using port's max_pkt hint.
1188 * (Must not hold any locks while building message.)
1191 res
= tipc_msg_build(hdr
, msg_sect
, num_sect
, sender
->publ
.max_pkt
,
1192 !sender
->user_port
, &buf
);
1194 read_lock_bh(&tipc_net_lock
);
1195 node
= tipc_node_select(destaddr
, selector
);
1197 tipc_node_lock(node
);
1198 l_ptr
= node
->active_links
[selector
];
1199 if (likely(l_ptr
)) {
1201 res
= link_send_buf_fast(l_ptr
, buf
,
1202 &sender
->publ
.max_pkt
);
1203 if (unlikely(res
< 0))
1206 tipc_node_unlock(node
);
1207 read_unlock_bh(&tipc_net_lock
);
1211 /* Exit if build request was invalid */
1213 if (unlikely(res
< 0))
1216 /* Exit if link (or bearer) is congested */
1218 if (link_congested(l_ptr
) ||
1219 !list_empty(&l_ptr
->b_ptr
->cong_links
)) {
1220 res
= link_schedule_port(l_ptr
,
1221 sender
->publ
.ref
, res
);
1226 * Message size exceeds max_pkt hint; update hint,
1227 * then re-try fast path or fragment the message
1230 sender
->publ
.max_pkt
= l_ptr
->max_pkt
;
1231 tipc_node_unlock(node
);
1232 read_unlock_bh(&tipc_net_lock
);
1235 if ((msg_hdr_sz(hdr
) + res
) <= sender
->publ
.max_pkt
)
1238 return link_send_sections_long(sender
, msg_sect
,
1239 num_sect
, destaddr
);
1241 tipc_node_unlock(node
);
1243 read_unlock_bh(&tipc_net_lock
);
1245 /* Couldn't find a link to the destination node */
1248 return tipc_reject_msg(buf
, TIPC_ERR_NO_NODE
);
1250 return tipc_port_reject_sections(sender
, hdr
, msg_sect
, num_sect
,
1256 * link_send_sections_long(): Entry for long messages where the
1257 * destination node is known and the header is complete,
1258 * inclusive total message length.
1259 * Link and bearer congestion status have been checked to be ok,
1260 * and are ignored if they change.
1262 * Note that fragments do not use the full link MTU so that they won't have
1263 * to undergo refragmentation if link changeover causes them to be sent
1264 * over another link with an additional tunnel header added as prefix.
1265 * (Refragmentation will still occur if the other link has a smaller MTU.)
1267 * Returns user data length or errno.
1269 static int link_send_sections_long(struct port
*sender
,
1270 struct iovec
const *msg_sect
,
1275 struct tipc_node
*node
;
1276 struct tipc_msg
*hdr
= &sender
->publ
.phdr
;
1277 u32 dsz
= msg_data_sz(hdr
);
1278 u32 max_pkt
,fragm_sz
,rest
;
1279 struct tipc_msg fragm_hdr
;
1280 struct sk_buff
*buf
,*buf_chain
,*prev
;
1281 u32 fragm_crs
,fragm_rest
,hsz
,sect_rest
;
1282 const unchar
*sect_crs
;
1288 max_pkt
= sender
->publ
.max_pkt
- INT_H_SIZE
;
1289 /* leave room for tunnel header in case of link changeover */
1290 fragm_sz
= max_pkt
- INT_H_SIZE
;
1291 /* leave room for fragmentation header in each fragment */
1299 /* Prepare reusable fragment header: */
1301 msg_dbg(hdr
, ">FRAGMENTING>");
1302 tipc_msg_init(&fragm_hdr
, MSG_FRAGMENTER
, FIRST_FRAGMENT
,
1303 INT_H_SIZE
, msg_destnode(hdr
));
1304 msg_set_link_selector(&fragm_hdr
, sender
->publ
.ref
);
1305 msg_set_size(&fragm_hdr
, max_pkt
);
1306 msg_set_fragm_no(&fragm_hdr
, 1);
1308 /* Prepare header of first fragment: */
1310 buf_chain
= buf
= tipc_buf_acquire(max_pkt
);
1314 skb_copy_to_linear_data(buf
, &fragm_hdr
, INT_H_SIZE
);
1315 hsz
= msg_hdr_sz(hdr
);
1316 skb_copy_to_linear_data_offset(buf
, INT_H_SIZE
, hdr
, hsz
);
1317 msg_dbg(buf_msg(buf
), ">BUILD>");
1319 /* Chop up message: */
1321 fragm_crs
= INT_H_SIZE
+ hsz
;
1322 fragm_rest
= fragm_sz
- hsz
;
1324 do { /* For all sections */
1328 sect_rest
= msg_sect
[++curr_sect
].iov_len
;
1329 sect_crs
= (const unchar
*)msg_sect
[curr_sect
].iov_base
;
1332 if (sect_rest
< fragm_rest
)
1337 if (likely(!sender
->user_port
)) {
1338 if (copy_from_user(buf
->data
+ fragm_crs
, sect_crs
, sz
)) {
1340 for (; buf_chain
; buf_chain
= buf
) {
1341 buf
= buf_chain
->next
;
1342 buf_discard(buf_chain
);
1347 skb_copy_to_linear_data_offset(buf
, fragm_crs
,
1355 if (!fragm_rest
&& rest
) {
1357 /* Initiate new fragment: */
1358 if (rest
<= fragm_sz
) {
1360 msg_set_type(&fragm_hdr
,LAST_FRAGMENT
);
1362 msg_set_type(&fragm_hdr
, FRAGMENT
);
1364 msg_set_size(&fragm_hdr
, fragm_sz
+ INT_H_SIZE
);
1365 msg_set_fragm_no(&fragm_hdr
, ++fragm_no
);
1367 buf
= tipc_buf_acquire(fragm_sz
+ INT_H_SIZE
);
1373 skb_copy_to_linear_data(buf
, &fragm_hdr
, INT_H_SIZE
);
1374 fragm_crs
= INT_H_SIZE
;
1375 fragm_rest
= fragm_sz
;
1376 msg_dbg(buf_msg(buf
)," >BUILD>");
1382 * Now we have a buffer chain. Select a link and check
1383 * that packet size is still OK
1385 node
= tipc_node_select(destaddr
, sender
->publ
.ref
& 1);
1387 tipc_node_lock(node
);
1388 l_ptr
= node
->active_links
[sender
->publ
.ref
& 1];
1390 tipc_node_unlock(node
);
1393 if (l_ptr
->max_pkt
< max_pkt
) {
1394 sender
->publ
.max_pkt
= l_ptr
->max_pkt
;
1395 tipc_node_unlock(node
);
1396 for (; buf_chain
; buf_chain
= buf
) {
1397 buf
= buf_chain
->next
;
1398 buf_discard(buf_chain
);
1404 for (; buf_chain
; buf_chain
= buf
) {
1405 buf
= buf_chain
->next
;
1406 buf_discard(buf_chain
);
1408 return tipc_port_reject_sections(sender
, hdr
, msg_sect
, num_sect
,
1412 /* Append whole chain to send queue: */
1415 l_ptr
->long_msg_seq_no
= mod(l_ptr
->long_msg_seq_no
+ 1);
1416 if (!l_ptr
->next_out
)
1417 l_ptr
->next_out
= buf_chain
;
1418 l_ptr
->stats
.sent_fragmented
++;
1420 struct sk_buff
*next
= buf
->next
;
1421 struct tipc_msg
*msg
= buf_msg(buf
);
1423 l_ptr
->stats
.sent_fragments
++;
1424 msg_set_long_msgno(msg
, l_ptr
->long_msg_seq_no
);
1425 link_add_to_outqueue(l_ptr
, buf
, msg
);
1426 msg_dbg(msg
, ">ADD>");
1430 /* Send it, if possible: */
1432 tipc_link_push_queue(l_ptr
);
1433 tipc_node_unlock(node
);
1438 * tipc_link_push_packet: Push one unsent packet to the media
1440 u32
tipc_link_push_packet(struct link
*l_ptr
)
1442 struct sk_buff
*buf
= l_ptr
->first_out
;
1443 u32 r_q_size
= l_ptr
->retransm_queue_size
;
1444 u32 r_q_head
= l_ptr
->retransm_queue_head
;
1446 /* Step to position where retransmission failed, if any, */
1447 /* consider that buffers may have been released in meantime */
1449 if (r_q_size
&& buf
) {
1450 u32 last
= lesser(mod(r_q_head
+ r_q_size
),
1451 link_last_sent(l_ptr
));
1452 u32 first
= msg_seqno(buf_msg(buf
));
1454 while (buf
&& less(first
, r_q_head
)) {
1455 first
= mod(first
+ 1);
1458 l_ptr
->retransm_queue_head
= r_q_head
= first
;
1459 l_ptr
->retransm_queue_size
= r_q_size
= mod(last
- first
);
1462 /* Continue retransmission now, if there is anything: */
1464 if (r_q_size
&& buf
) {
1465 msg_set_ack(buf_msg(buf
), mod(l_ptr
->next_in_no
- 1));
1466 msg_set_bcast_ack(buf_msg(buf
), l_ptr
->owner
->bclink
.last_in
);
1467 if (tipc_bearer_send(l_ptr
->b_ptr
, buf
, &l_ptr
->media_addr
)) {
1468 msg_dbg(buf_msg(buf
), ">DEF-RETR>");
1469 l_ptr
->retransm_queue_head
= mod(++r_q_head
);
1470 l_ptr
->retransm_queue_size
= --r_q_size
;
1471 l_ptr
->stats
.retransmitted
++;
1474 l_ptr
->stats
.bearer_congs
++;
1475 msg_dbg(buf_msg(buf
), "|>DEF-RETR>");
1480 /* Send deferred protocol message, if any: */
1482 buf
= l_ptr
->proto_msg_queue
;
1484 msg_set_ack(buf_msg(buf
), mod(l_ptr
->next_in_no
- 1));
1485 msg_set_bcast_ack(buf_msg(buf
),l_ptr
->owner
->bclink
.last_in
);
1486 if (tipc_bearer_send(l_ptr
->b_ptr
, buf
, &l_ptr
->media_addr
)) {
1487 msg_dbg(buf_msg(buf
), ">DEF-PROT>");
1488 l_ptr
->unacked_window
= 0;
1490 l_ptr
->proto_msg_queue
= NULL
;
1493 msg_dbg(buf_msg(buf
), "|>DEF-PROT>");
1494 l_ptr
->stats
.bearer_congs
++;
1499 /* Send one deferred data message, if send window not full: */
1501 buf
= l_ptr
->next_out
;
1503 struct tipc_msg
*msg
= buf_msg(buf
);
1504 u32 next
= msg_seqno(msg
);
1505 u32 first
= msg_seqno(buf_msg(l_ptr
->first_out
));
1507 if (mod(next
- first
) < l_ptr
->queue_limit
[0]) {
1508 msg_set_ack(msg
, mod(l_ptr
->next_in_no
- 1));
1509 msg_set_bcast_ack(msg
, l_ptr
->owner
->bclink
.last_in
);
1510 if (tipc_bearer_send(l_ptr
->b_ptr
, buf
, &l_ptr
->media_addr
)) {
1511 if (msg_user(msg
) == MSG_BUNDLER
)
1512 msg_set_type(msg
, CLOSED_MSG
);
1513 msg_dbg(msg
, ">PUSH-DATA>");
1514 l_ptr
->next_out
= buf
->next
;
1517 msg_dbg(msg
, "|PUSH-DATA|");
1518 l_ptr
->stats
.bearer_congs
++;
1523 return PUSH_FINISHED
;
1527 * push_queue(): push out the unsent messages of a link where
1528 * congestion has abated. Node is locked
1530 void tipc_link_push_queue(struct link
*l_ptr
)
1534 if (tipc_bearer_congested(l_ptr
->b_ptr
, l_ptr
))
1538 res
= tipc_link_push_packet(l_ptr
);
1541 if (res
== PUSH_FAILED
)
1542 tipc_bearer_schedule(l_ptr
->b_ptr
, l_ptr
);
1545 static void link_reset_all(unsigned long addr
)
1547 struct tipc_node
*n_ptr
;
1548 char addr_string
[16];
1551 read_lock_bh(&tipc_net_lock
);
1552 n_ptr
= tipc_node_find((u32
)addr
);
1554 read_unlock_bh(&tipc_net_lock
);
1555 return; /* node no longer exists */
1558 tipc_node_lock(n_ptr
);
1560 warn("Resetting all links to %s\n",
1561 tipc_addr_string_fill(addr_string
, n_ptr
->addr
));
1563 for (i
= 0; i
< MAX_BEARERS
; i
++) {
1564 if (n_ptr
->links
[i
]) {
1565 link_print(n_ptr
->links
[i
], TIPC_OUTPUT
,
1566 "Resetting link\n");
1567 tipc_link_reset(n_ptr
->links
[i
]);
1571 tipc_node_unlock(n_ptr
);
1572 read_unlock_bh(&tipc_net_lock
);
1575 static void link_retransmit_failure(struct link
*l_ptr
, struct sk_buff
*buf
)
1577 struct tipc_msg
*msg
= buf_msg(buf
);
1579 warn("Retransmission failure on link <%s>\n", l_ptr
->name
);
1580 tipc_msg_dbg(TIPC_OUTPUT
, msg
, ">RETR-FAIL>");
1584 /* Handle failure on standard link */
1586 link_print(l_ptr
, TIPC_OUTPUT
, "Resetting link\n");
1587 tipc_link_reset(l_ptr
);
1591 /* Handle failure on broadcast link */
1593 struct tipc_node
*n_ptr
;
1594 char addr_string
[16];
1596 tipc_printf(TIPC_OUTPUT
, "Msg seq number: %u, ", msg_seqno(msg
));
1597 tipc_printf(TIPC_OUTPUT
, "Outstanding acks: %lu\n",
1598 (unsigned long) TIPC_SKB_CB(buf
)->handle
);
1600 n_ptr
= l_ptr
->owner
->next
;
1601 tipc_node_lock(n_ptr
);
1603 tipc_addr_string_fill(addr_string
, n_ptr
->addr
);
1604 tipc_printf(TIPC_OUTPUT
, "Multicast link info for %s\n", addr_string
);
1605 tipc_printf(TIPC_OUTPUT
, "Supported: %d, ", n_ptr
->bclink
.supported
);
1606 tipc_printf(TIPC_OUTPUT
, "Acked: %u\n", n_ptr
->bclink
.acked
);
1607 tipc_printf(TIPC_OUTPUT
, "Last in: %u, ", n_ptr
->bclink
.last_in
);
1608 tipc_printf(TIPC_OUTPUT
, "Gap after: %u, ", n_ptr
->bclink
.gap_after
);
1609 tipc_printf(TIPC_OUTPUT
, "Gap to: %u\n", n_ptr
->bclink
.gap_to
);
1610 tipc_printf(TIPC_OUTPUT
, "Nack sync: %u\n\n", n_ptr
->bclink
.nack_sync
);
1612 tipc_k_signal((Handler
)link_reset_all
, (unsigned long)n_ptr
->addr
);
1614 tipc_node_unlock(n_ptr
);
1616 l_ptr
->stale_count
= 0;
1620 void tipc_link_retransmit(struct link
*l_ptr
, struct sk_buff
*buf
,
1623 struct tipc_msg
*msg
;
1630 dbg("Retransmitting %u in link %x\n", retransmits
, l_ptr
);
1632 if (tipc_bearer_congested(l_ptr
->b_ptr
, l_ptr
)) {
1633 if (l_ptr
->retransm_queue_size
== 0) {
1634 msg_dbg(msg
, ">NO_RETR->BCONG>");
1635 dbg_print_link(l_ptr
, " ");
1636 l_ptr
->retransm_queue_head
= msg_seqno(msg
);
1637 l_ptr
->retransm_queue_size
= retransmits
;
1639 err("Unexpected retransmit on link %s (qsize=%d)\n",
1640 l_ptr
->name
, l_ptr
->retransm_queue_size
);
1644 /* Detect repeated retransmit failures on uncongested bearer */
1646 if (l_ptr
->last_retransmitted
== msg_seqno(msg
)) {
1647 if (++l_ptr
->stale_count
> 100) {
1648 link_retransmit_failure(l_ptr
, buf
);
1652 l_ptr
->last_retransmitted
= msg_seqno(msg
);
1653 l_ptr
->stale_count
= 1;
1657 while (retransmits
&& (buf
!= l_ptr
->next_out
) && buf
) {
1659 msg_set_ack(msg
, mod(l_ptr
->next_in_no
- 1));
1660 msg_set_bcast_ack(msg
, l_ptr
->owner
->bclink
.last_in
);
1661 if (tipc_bearer_send(l_ptr
->b_ptr
, buf
, &l_ptr
->media_addr
)) {
1662 msg_dbg(buf_msg(buf
), ">RETR>");
1665 l_ptr
->stats
.retransmitted
++;
1667 tipc_bearer_schedule(l_ptr
->b_ptr
, l_ptr
);
1668 l_ptr
->stats
.bearer_congs
++;
1669 l_ptr
->retransm_queue_head
= msg_seqno(buf_msg(buf
));
1670 l_ptr
->retransm_queue_size
= retransmits
;
1675 l_ptr
->retransm_queue_head
= l_ptr
->retransm_queue_size
= 0;
1679 * link_insert_deferred_queue - insert deferred messages back into receive chain
1682 static struct sk_buff
*link_insert_deferred_queue(struct link
*l_ptr
,
1683 struct sk_buff
*buf
)
1687 if (l_ptr
->oldest_deferred_in
== NULL
)
1690 seq_no
= msg_seqno(buf_msg(l_ptr
->oldest_deferred_in
));
1691 if (seq_no
== mod(l_ptr
->next_in_no
)) {
1692 l_ptr
->newest_deferred_in
->next
= buf
;
1693 buf
= l_ptr
->oldest_deferred_in
;
1694 l_ptr
->oldest_deferred_in
= NULL
;
1695 l_ptr
->deferred_inqueue_sz
= 0;
1701 * link_recv_buf_validate - validate basic format of received message
1703 * This routine ensures a TIPC message has an acceptable header, and at least
1704 * as much data as the header indicates it should. The routine also ensures
1705 * that the entire message header is stored in the main fragment of the message
1706 * buffer, to simplify future access to message header fields.
1708 * Note: Having extra info present in the message header or data areas is OK.
1709 * TIPC will ignore the excess, under the assumption that it is optional info
1710 * introduced by a later release of the protocol.
1713 static int link_recv_buf_validate(struct sk_buff
*buf
)
1715 static u32 min_data_hdr_size
[8] = {
1716 SHORT_H_SIZE
, MCAST_H_SIZE
, LONG_H_SIZE
, DIR_MSG_H_SIZE
,
1717 MAX_H_SIZE
, MAX_H_SIZE
, MAX_H_SIZE
, MAX_H_SIZE
1720 struct tipc_msg
*msg
;
1726 if (unlikely(buf
->len
< MIN_H_SIZE
))
1729 msg
= skb_header_pointer(buf
, 0, sizeof(tipc_hdr
), tipc_hdr
);
1733 if (unlikely(msg_version(msg
) != TIPC_VERSION
))
1736 size
= msg_size(msg
);
1737 hdr_size
= msg_hdr_sz(msg
);
1738 min_hdr_size
= msg_isdata(msg
) ?
1739 min_data_hdr_size
[msg_type(msg
)] : INT_H_SIZE
;
1741 if (unlikely((hdr_size
< min_hdr_size
) ||
1742 (size
< hdr_size
) ||
1743 (buf
->len
< size
) ||
1744 (size
- hdr_size
> TIPC_MAX_USER_MSG_SIZE
)))
1747 return pskb_may_pull(buf
, hdr_size
);
1751 * tipc_recv_msg - process TIPC messages arriving from off-node
1752 * @head: pointer to message buffer chain
1753 * @tb_ptr: pointer to bearer message arrived on
1755 * Invoked with no locks held. Bearer pointer must point to a valid bearer
1756 * structure (i.e. cannot be NULL), but bearer can be inactive.
1759 void tipc_recv_msg(struct sk_buff
*head
, struct tipc_bearer
*tb_ptr
)
1761 read_lock_bh(&tipc_net_lock
);
1763 struct bearer
*b_ptr
= (struct bearer
*)tb_ptr
;
1764 struct tipc_node
*n_ptr
;
1766 struct sk_buff
*crs
;
1767 struct sk_buff
*buf
= head
;
1768 struct tipc_msg
*msg
;
1776 /* Ensure bearer is still enabled */
1778 if (unlikely(!b_ptr
->active
))
1781 /* Ensure message is well-formed */
1783 if (unlikely(!link_recv_buf_validate(buf
)))
1786 /* Ensure message data is a single contiguous unit */
1788 if (unlikely(buf_linearize(buf
))) {
1792 /* Handle arrival of a non-unicast link message */
1796 if (unlikely(msg_non_seq(msg
))) {
1797 if (msg_user(msg
) == LINK_CONFIG
)
1798 tipc_disc_recv_msg(buf
, b_ptr
);
1800 tipc_bclink_recv_pkt(buf
);
1804 if (unlikely(!msg_short(msg
) &&
1805 (msg_destnode(msg
) != tipc_own_addr
)))
1808 /* Discard non-routeable messages destined for another node */
1810 if (unlikely(!msg_isdata(msg
) &&
1811 (msg_destnode(msg
) != tipc_own_addr
))) {
1812 if ((msg_user(msg
) != CONN_MANAGER
) &&
1813 (msg_user(msg
) != MSG_FRAGMENTER
))
1817 /* Locate neighboring node that sent message */
1819 n_ptr
= tipc_node_find(msg_prevnode(msg
));
1820 if (unlikely(!n_ptr
))
1822 tipc_node_lock(n_ptr
);
1824 /* Don't talk to neighbor during cleanup after last session */
1826 if (n_ptr
->cleanup_required
) {
1827 tipc_node_unlock(n_ptr
);
1831 /* Locate unicast link endpoint that should handle message */
1833 l_ptr
= n_ptr
->links
[b_ptr
->identity
];
1834 if (unlikely(!l_ptr
)) {
1835 tipc_node_unlock(n_ptr
);
1839 /* Validate message sequence number info */
1841 seq_no
= msg_seqno(msg
);
1842 ackd
= msg_ack(msg
);
1844 /* Release acked messages */
1846 if (less(n_ptr
->bclink
.acked
, msg_bcast_ack(msg
))) {
1847 if (tipc_node_is_up(n_ptr
) && n_ptr
->bclink
.supported
)
1848 tipc_bclink_acknowledge(n_ptr
, msg_bcast_ack(msg
));
1851 crs
= l_ptr
->first_out
;
1852 while ((crs
!= l_ptr
->next_out
) &&
1853 less_eq(msg_seqno(buf_msg(crs
)), ackd
)) {
1854 struct sk_buff
*next
= crs
->next
;
1861 l_ptr
->first_out
= crs
;
1862 l_ptr
->out_queue_size
-= released
;
1865 /* Try sending any messages link endpoint has pending */
1867 if (unlikely(l_ptr
->next_out
))
1868 tipc_link_push_queue(l_ptr
);
1869 if (unlikely(!list_empty(&l_ptr
->waiting_ports
)))
1870 tipc_link_wakeup_ports(l_ptr
, 0);
1871 if (unlikely(++l_ptr
->unacked_window
>= TIPC_MIN_LINK_WIN
)) {
1872 l_ptr
->stats
.sent_acks
++;
1873 tipc_link_send_proto_msg(l_ptr
, STATE_MSG
, 0, 0, 0, 0, 0);
1876 /* Now (finally!) process the incoming message */
1879 if (likely(link_working_working(l_ptr
))) {
1880 if (likely(seq_no
== mod(l_ptr
->next_in_no
))) {
1881 l_ptr
->next_in_no
++;
1882 if (unlikely(l_ptr
->oldest_deferred_in
))
1883 head
= link_insert_deferred_queue(l_ptr
,
1885 if (likely(msg_is_dest(msg
, tipc_own_addr
))) {
1887 if (likely(msg_isdata(msg
))) {
1888 tipc_node_unlock(n_ptr
);
1889 tipc_port_recv_msg(buf
);
1892 switch (msg_user(msg
)) {
1894 l_ptr
->stats
.recv_bundles
++;
1895 l_ptr
->stats
.recv_bundled
+=
1897 tipc_node_unlock(n_ptr
);
1898 tipc_link_recv_bundle(buf
);
1900 case ROUTE_DISTRIBUTOR
:
1901 tipc_node_unlock(n_ptr
);
1902 tipc_cltr_recv_routing_table(buf
);
1904 case NAME_DISTRIBUTOR
:
1905 tipc_node_unlock(n_ptr
);
1906 tipc_named_recv(buf
);
1909 tipc_node_unlock(n_ptr
);
1910 tipc_port_recv_proto_msg(buf
);
1912 case MSG_FRAGMENTER
:
1913 l_ptr
->stats
.recv_fragments
++;
1914 if (tipc_link_recv_fragment(&l_ptr
->defragm_buf
,
1916 l_ptr
->stats
.recv_fragmented
++;
1920 case CHANGEOVER_PROTOCOL
:
1921 type
= msg_type(msg
);
1922 if (link_recv_changeover_msg(&l_ptr
, &buf
)) {
1924 seq_no
= msg_seqno(msg
);
1925 if (type
== ORIGINAL_MSG
)
1927 goto protocol_check
;
1932 tipc_node_unlock(n_ptr
);
1933 tipc_net_route_msg(buf
);
1936 link_handle_out_of_seq_msg(l_ptr
, buf
);
1937 head
= link_insert_deferred_queue(l_ptr
, head
);
1938 tipc_node_unlock(n_ptr
);
1942 if (msg_user(msg
) == LINK_PROTOCOL
) {
1943 link_recv_proto_msg(l_ptr
, buf
);
1944 head
= link_insert_deferred_queue(l_ptr
, head
);
1945 tipc_node_unlock(n_ptr
);
1948 msg_dbg(msg
,"NSEQ<REC<");
1949 link_state_event(l_ptr
, TRAFFIC_MSG_EVT
);
1951 if (link_working_working(l_ptr
)) {
1952 /* Re-insert in front of queue */
1953 msg_dbg(msg
,"RECV-REINS:");
1956 tipc_node_unlock(n_ptr
);
1959 tipc_node_unlock(n_ptr
);
1963 read_unlock_bh(&tipc_net_lock
);
1967 * link_defer_buf(): Sort a received out-of-sequence packet
1968 * into the deferred reception queue.
1969 * Returns the increase of the queue length,i.e. 0 or 1
1972 u32
tipc_link_defer_pkt(struct sk_buff
**head
,
1973 struct sk_buff
**tail
,
1974 struct sk_buff
*buf
)
1976 struct sk_buff
*prev
= NULL
;
1977 struct sk_buff
*crs
= *head
;
1978 u32 seq_no
= msg_seqno(buf_msg(buf
));
1983 if (*head
== NULL
) {
1984 *head
= *tail
= buf
;
1989 if (less(msg_seqno(buf_msg(*tail
)), seq_no
)) {
1990 (*tail
)->next
= buf
;
1995 /* Scan through queue and sort it in */
1997 struct tipc_msg
*msg
= buf_msg(crs
);
1999 if (less(seq_no
, msg_seqno(msg
))) {
2007 if (seq_no
== msg_seqno(msg
)) {
2015 /* Message is a duplicate of an existing message */
2022 * link_handle_out_of_seq_msg - handle arrival of out-of-sequence packet
2025 static void link_handle_out_of_seq_msg(struct link
*l_ptr
,
2026 struct sk_buff
*buf
)
2028 u32 seq_no
= msg_seqno(buf_msg(buf
));
2030 if (likely(msg_user(buf_msg(buf
)) == LINK_PROTOCOL
)) {
2031 link_recv_proto_msg(l_ptr
, buf
);
2035 dbg("rx OOS msg: seq_no %u, expecting %u (%u)\n",
2036 seq_no
, mod(l_ptr
->next_in_no
), l_ptr
->next_in_no
);
2038 /* Record OOS packet arrival (force mismatch on next timeout) */
2040 l_ptr
->checkpoint
--;
2043 * Discard packet if a duplicate; otherwise add it to deferred queue
2044 * and notify peer of gap as per protocol specification
2047 if (less(seq_no
, mod(l_ptr
->next_in_no
))) {
2048 l_ptr
->stats
.duplicates
++;
2053 if (tipc_link_defer_pkt(&l_ptr
->oldest_deferred_in
,
2054 &l_ptr
->newest_deferred_in
, buf
)) {
2055 l_ptr
->deferred_inqueue_sz
++;
2056 l_ptr
->stats
.deferred_recv
++;
2057 if ((l_ptr
->deferred_inqueue_sz
% 16) == 1)
2058 tipc_link_send_proto_msg(l_ptr
, STATE_MSG
, 0, 0, 0, 0, 0);
2060 l_ptr
->stats
.duplicates
++;
2064 * Send protocol message to the other endpoint.
2066 void tipc_link_send_proto_msg(struct link
*l_ptr
, u32 msg_typ
, int probe_msg
,
2067 u32 gap
, u32 tolerance
, u32 priority
, u32 ack_mtu
)
2069 struct sk_buff
*buf
= NULL
;
2070 struct tipc_msg
*msg
= l_ptr
->pmsg
;
2071 u32 msg_size
= sizeof(l_ptr
->proto_msg
);
2073 if (link_blocked(l_ptr
))
2075 msg_set_type(msg
, msg_typ
);
2076 msg_set_net_plane(msg
, l_ptr
->b_ptr
->net_plane
);
2077 msg_set_bcast_ack(msg
, mod(l_ptr
->owner
->bclink
.last_in
));
2078 msg_set_last_bcast(msg
, tipc_bclink_get_last_sent());
2080 if (msg_typ
== STATE_MSG
) {
2081 u32 next_sent
= mod(l_ptr
->next_out_no
);
2083 if (!tipc_link_is_up(l_ptr
))
2085 if (l_ptr
->next_out
)
2086 next_sent
= msg_seqno(buf_msg(l_ptr
->next_out
));
2087 msg_set_next_sent(msg
, next_sent
);
2088 if (l_ptr
->oldest_deferred_in
) {
2089 u32 rec
= msg_seqno(buf_msg(l_ptr
->oldest_deferred_in
));
2090 gap
= mod(rec
- mod(l_ptr
->next_in_no
));
2092 msg_set_seq_gap(msg
, gap
);
2094 l_ptr
->stats
.sent_nacks
++;
2095 msg_set_link_tolerance(msg
, tolerance
);
2096 msg_set_linkprio(msg
, priority
);
2097 msg_set_max_pkt(msg
, ack_mtu
);
2098 msg_set_ack(msg
, mod(l_ptr
->next_in_no
- 1));
2099 msg_set_probe(msg
, probe_msg
!= 0);
2101 u32 mtu
= l_ptr
->max_pkt
;
2103 if ((mtu
< l_ptr
->max_pkt_target
) &&
2104 link_working_working(l_ptr
) &&
2105 l_ptr
->fsm_msg_cnt
) {
2106 msg_size
= (mtu
+ (l_ptr
->max_pkt_target
- mtu
)/2 + 2) & ~3;
2107 if (l_ptr
->max_pkt_probes
== 10) {
2108 l_ptr
->max_pkt_target
= (msg_size
- 4);
2109 l_ptr
->max_pkt_probes
= 0;
2110 msg_size
= (mtu
+ (l_ptr
->max_pkt_target
- mtu
)/2 + 2) & ~3;
2112 l_ptr
->max_pkt_probes
++;
2115 l_ptr
->stats
.sent_probes
++;
2117 l_ptr
->stats
.sent_states
++;
2118 } else { /* RESET_MSG or ACTIVATE_MSG */
2119 msg_set_ack(msg
, mod(l_ptr
->reset_checkpoint
- 1));
2120 msg_set_seq_gap(msg
, 0);
2121 msg_set_next_sent(msg
, 1);
2122 msg_set_link_tolerance(msg
, l_ptr
->tolerance
);
2123 msg_set_linkprio(msg
, l_ptr
->priority
);
2124 msg_set_max_pkt(msg
, l_ptr
->max_pkt_target
);
2127 if (tipc_node_has_redundant_links(l_ptr
->owner
)) {
2128 msg_set_redundant_link(msg
);
2130 msg_clear_redundant_link(msg
);
2132 msg_set_linkprio(msg
, l_ptr
->priority
);
2134 /* Ensure sequence number will not fit : */
2136 msg_set_seqno(msg
, mod(l_ptr
->next_out_no
+ (0xffff/2)));
2140 if (tipc_bearer_congested(l_ptr
->b_ptr
, l_ptr
)) {
2141 if (!l_ptr
->proto_msg_queue
) {
2142 l_ptr
->proto_msg_queue
=
2143 tipc_buf_acquire(sizeof(l_ptr
->proto_msg
));
2145 buf
= l_ptr
->proto_msg_queue
;
2148 skb_copy_to_linear_data(buf
, msg
, sizeof(l_ptr
->proto_msg
));
2151 msg_set_timestamp(msg
, jiffies_to_msecs(jiffies
));
2153 /* Message can be sent */
2157 buf
= tipc_buf_acquire(msg_size
);
2161 skb_copy_to_linear_data(buf
, msg
, sizeof(l_ptr
->proto_msg
));
2162 msg_set_size(buf_msg(buf
), msg_size
);
2164 if (tipc_bearer_send(l_ptr
->b_ptr
, buf
, &l_ptr
->media_addr
)) {
2165 l_ptr
->unacked_window
= 0;
2170 /* New congestion */
2171 tipc_bearer_schedule(l_ptr
->b_ptr
, l_ptr
);
2172 l_ptr
->proto_msg_queue
= buf
;
2173 l_ptr
->stats
.bearer_congs
++;
2177 * Receive protocol message :
2178 * Note that network plane id propagates through the network, and may
2179 * change at any time. The node with lowest address rules
2182 static void link_recv_proto_msg(struct link
*l_ptr
, struct sk_buff
*buf
)
2188 struct tipc_msg
*msg
= buf_msg(buf
);
2190 dbg("AT(%u):", jiffies_to_msecs(jiffies
));
2192 if (link_blocked(l_ptr
))
2195 /* record unnumbered packet arrival (force mismatch on next timeout) */
2197 l_ptr
->checkpoint
--;
2199 if (l_ptr
->b_ptr
->net_plane
!= msg_net_plane(msg
))
2200 if (tipc_own_addr
> msg_prevnode(msg
))
2201 l_ptr
->b_ptr
->net_plane
= msg_net_plane(msg
);
2203 l_ptr
->owner
->permit_changeover
= msg_redundant_link(msg
);
2205 switch (msg_type(msg
)) {
2208 if (!link_working_unknown(l_ptr
) &&
2209 (l_ptr
->peer_session
!= INVALID_SESSION
)) {
2210 if (msg_session(msg
) == l_ptr
->peer_session
) {
2211 dbg("Duplicate RESET: %u<->%u\n",
2212 msg_session(msg
), l_ptr
->peer_session
);
2213 break; /* duplicate: ignore */
2218 /* Update link settings according other endpoint's values */
2220 strcpy((strrchr(l_ptr
->name
, ':') + 1), (char *)msg_data(msg
));
2222 if ((msg_tol
= msg_link_tolerance(msg
)) &&
2223 (msg_tol
> l_ptr
->tolerance
))
2224 link_set_supervision_props(l_ptr
, msg_tol
);
2226 if (msg_linkprio(msg
) > l_ptr
->priority
)
2227 l_ptr
->priority
= msg_linkprio(msg
);
2229 max_pkt_info
= msg_max_pkt(msg
);
2231 if (max_pkt_info
< l_ptr
->max_pkt_target
)
2232 l_ptr
->max_pkt_target
= max_pkt_info
;
2233 if (l_ptr
->max_pkt
> l_ptr
->max_pkt_target
)
2234 l_ptr
->max_pkt
= l_ptr
->max_pkt_target
;
2236 l_ptr
->max_pkt
= l_ptr
->max_pkt_target
;
2238 l_ptr
->owner
->bclink
.supported
= (max_pkt_info
!= 0);
2240 link_state_event(l_ptr
, msg_type(msg
));
2242 l_ptr
->peer_session
= msg_session(msg
);
2243 l_ptr
->peer_bearer_id
= msg_bearer_id(msg
);
2245 /* Synchronize broadcast sequence numbers */
2246 if (!tipc_node_has_redundant_links(l_ptr
->owner
)) {
2247 l_ptr
->owner
->bclink
.last_in
= mod(msg_last_bcast(msg
));
2252 if ((msg_tol
= msg_link_tolerance(msg
)))
2253 link_set_supervision_props(l_ptr
, msg_tol
);
2255 if (msg_linkprio(msg
) &&
2256 (msg_linkprio(msg
) != l_ptr
->priority
)) {
2257 warn("Resetting link <%s>, priority change %u->%u\n",
2258 l_ptr
->name
, l_ptr
->priority
, msg_linkprio(msg
));
2259 l_ptr
->priority
= msg_linkprio(msg
);
2260 tipc_link_reset(l_ptr
); /* Enforce change to take effect */
2263 link_state_event(l_ptr
, TRAFFIC_MSG_EVT
);
2264 l_ptr
->stats
.recv_states
++;
2265 if (link_reset_unknown(l_ptr
))
2268 if (less_eq(mod(l_ptr
->next_in_no
), msg_next_sent(msg
))) {
2269 rec_gap
= mod(msg_next_sent(msg
) -
2270 mod(l_ptr
->next_in_no
));
2273 max_pkt_ack
= msg_max_pkt(msg
);
2274 if (max_pkt_ack
> l_ptr
->max_pkt
) {
2275 dbg("Link <%s> updated MTU %u -> %u\n",
2276 l_ptr
->name
, l_ptr
->max_pkt
, max_pkt_ack
);
2277 l_ptr
->max_pkt
= max_pkt_ack
;
2278 l_ptr
->max_pkt_probes
= 0;
2282 if (msg_probe(msg
)) {
2283 l_ptr
->stats
.recv_probes
++;
2284 if (msg_size(msg
) > sizeof(l_ptr
->proto_msg
)) {
2285 max_pkt_ack
= msg_size(msg
);
2289 /* Protocol message before retransmits, reduce loss risk */
2291 tipc_bclink_check_gap(l_ptr
->owner
, msg_last_bcast(msg
));
2293 if (rec_gap
|| (msg_probe(msg
))) {
2294 tipc_link_send_proto_msg(l_ptr
, STATE_MSG
,
2295 0, rec_gap
, 0, 0, max_pkt_ack
);
2297 if (msg_seq_gap(msg
)) {
2298 msg_dbg(msg
, "With Gap:");
2299 l_ptr
->stats
.recv_nacks
++;
2300 tipc_link_retransmit(l_ptr
, l_ptr
->first_out
,
2305 msg_dbg(buf_msg(buf
), "<DISCARDING UNKNOWN<");
2313 * tipc_link_tunnel(): Send one message via a link belonging to
2314 * another bearer. Owner node is locked.
2316 static void tipc_link_tunnel(struct link
*l_ptr
,
2317 struct tipc_msg
*tunnel_hdr
,
2318 struct tipc_msg
*msg
,
2321 struct link
*tunnel
;
2322 struct sk_buff
*buf
;
2323 u32 length
= msg_size(msg
);
2325 tunnel
= l_ptr
->owner
->active_links
[selector
& 1];
2326 if (!tipc_link_is_up(tunnel
)) {
2327 warn("Link changeover error, "
2328 "tunnel link no longer available\n");
2331 msg_set_size(tunnel_hdr
, length
+ INT_H_SIZE
);
2332 buf
= tipc_buf_acquire(length
+ INT_H_SIZE
);
2334 warn("Link changeover error, "
2335 "unable to send tunnel msg\n");
2338 skb_copy_to_linear_data(buf
, tunnel_hdr
, INT_H_SIZE
);
2339 skb_copy_to_linear_data_offset(buf
, INT_H_SIZE
, msg
, length
);
2340 dbg("%c->%c:", l_ptr
->b_ptr
->net_plane
, tunnel
->b_ptr
->net_plane
);
2341 msg_dbg(buf_msg(buf
), ">SEND>");
2342 tipc_link_send_buf(tunnel
, buf
);
2348 * changeover(): Send whole message queue via the remaining link
2349 * Owner node is locked.
2352 void tipc_link_changeover(struct link
*l_ptr
)
2354 u32 msgcount
= l_ptr
->out_queue_size
;
2355 struct sk_buff
*crs
= l_ptr
->first_out
;
2356 struct link
*tunnel
= l_ptr
->owner
->active_links
[0];
2357 struct tipc_msg tunnel_hdr
;
2363 if (!l_ptr
->owner
->permit_changeover
) {
2364 warn("Link changeover error, "
2365 "peer did not permit changeover\n");
2369 tipc_msg_init(&tunnel_hdr
, CHANGEOVER_PROTOCOL
,
2370 ORIGINAL_MSG
, INT_H_SIZE
, l_ptr
->addr
);
2371 msg_set_bearer_id(&tunnel_hdr
, l_ptr
->peer_bearer_id
);
2372 msg_set_msgcnt(&tunnel_hdr
, msgcount
);
2373 dbg("Link changeover requires %u tunnel messages\n", msgcount
);
2375 if (!l_ptr
->first_out
) {
2376 struct sk_buff
*buf
;
2378 buf
= tipc_buf_acquire(INT_H_SIZE
);
2380 skb_copy_to_linear_data(buf
, &tunnel_hdr
, INT_H_SIZE
);
2381 msg_set_size(&tunnel_hdr
, INT_H_SIZE
);
2382 dbg("%c->%c:", l_ptr
->b_ptr
->net_plane
,
2383 tunnel
->b_ptr
->net_plane
);
2384 msg_dbg(&tunnel_hdr
, "EMPTY>SEND>");
2385 tipc_link_send_buf(tunnel
, buf
);
2387 warn("Link changeover error, "
2388 "unable to send changeover msg\n");
2393 split_bundles
= (l_ptr
->owner
->active_links
[0] !=
2394 l_ptr
->owner
->active_links
[1]);
2397 struct tipc_msg
*msg
= buf_msg(crs
);
2399 if ((msg_user(msg
) == MSG_BUNDLER
) && split_bundles
) {
2400 struct tipc_msg
*m
= msg_get_wrapped(msg
);
2401 unchar
* pos
= (unchar
*)m
;
2403 msgcount
= msg_msgcnt(msg
);
2404 while (msgcount
--) {
2405 msg_set_seqno(m
,msg_seqno(msg
));
2406 tipc_link_tunnel(l_ptr
, &tunnel_hdr
, m
,
2407 msg_link_selector(m
));
2408 pos
+= align(msg_size(m
));
2409 m
= (struct tipc_msg
*)pos
;
2412 tipc_link_tunnel(l_ptr
, &tunnel_hdr
, msg
,
2413 msg_link_selector(msg
));
2419 void tipc_link_send_duplicate(struct link
*l_ptr
, struct link
*tunnel
)
2421 struct sk_buff
*iter
;
2422 struct tipc_msg tunnel_hdr
;
2424 tipc_msg_init(&tunnel_hdr
, CHANGEOVER_PROTOCOL
,
2425 DUPLICATE_MSG
, INT_H_SIZE
, l_ptr
->addr
);
2426 msg_set_msgcnt(&tunnel_hdr
, l_ptr
->out_queue_size
);
2427 msg_set_bearer_id(&tunnel_hdr
, l_ptr
->peer_bearer_id
);
2428 iter
= l_ptr
->first_out
;
2430 struct sk_buff
*outbuf
;
2431 struct tipc_msg
*msg
= buf_msg(iter
);
2432 u32 length
= msg_size(msg
);
2434 if (msg_user(msg
) == MSG_BUNDLER
)
2435 msg_set_type(msg
, CLOSED_MSG
);
2436 msg_set_ack(msg
, mod(l_ptr
->next_in_no
- 1)); /* Update */
2437 msg_set_bcast_ack(msg
, l_ptr
->owner
->bclink
.last_in
);
2438 msg_set_size(&tunnel_hdr
, length
+ INT_H_SIZE
);
2439 outbuf
= tipc_buf_acquire(length
+ INT_H_SIZE
);
2440 if (outbuf
== NULL
) {
2441 warn("Link changeover error, "
2442 "unable to send duplicate msg\n");
2445 skb_copy_to_linear_data(outbuf
, &tunnel_hdr
, INT_H_SIZE
);
2446 skb_copy_to_linear_data_offset(outbuf
, INT_H_SIZE
, iter
->data
,
2448 dbg("%c->%c:", l_ptr
->b_ptr
->net_plane
,
2449 tunnel
->b_ptr
->net_plane
);
2450 msg_dbg(buf_msg(outbuf
), ">SEND>");
2451 tipc_link_send_buf(tunnel
, outbuf
);
2452 if (!tipc_link_is_up(l_ptr
))
2461 * buf_extract - extracts embedded TIPC message from another message
2462 * @skb: encapsulating message buffer
2463 * @from_pos: offset to extract from
2465 * Returns a new message buffer containing an embedded message. The
2466 * encapsulating message itself is left unchanged.
2469 static struct sk_buff
*buf_extract(struct sk_buff
*skb
, u32 from_pos
)
2471 struct tipc_msg
*msg
= (struct tipc_msg
*)(skb
->data
+ from_pos
);
2472 u32 size
= msg_size(msg
);
2475 eb
= tipc_buf_acquire(size
);
2477 skb_copy_to_linear_data(eb
, msg
, size
);
2482 * link_recv_changeover_msg(): Receive tunneled packet sent
2483 * via other link. Node is locked. Return extracted buffer.
2486 static int link_recv_changeover_msg(struct link
**l_ptr
,
2487 struct sk_buff
**buf
)
2489 struct sk_buff
*tunnel_buf
= *buf
;
2490 struct link
*dest_link
;
2491 struct tipc_msg
*msg
;
2492 struct tipc_msg
*tunnel_msg
= buf_msg(tunnel_buf
);
2493 u32 msg_typ
= msg_type(tunnel_msg
);
2494 u32 msg_count
= msg_msgcnt(tunnel_msg
);
2496 dest_link
= (*l_ptr
)->owner
->links
[msg_bearer_id(tunnel_msg
)];
2498 msg_dbg(tunnel_msg
, "NOLINK/<REC<");
2501 if (dest_link
== *l_ptr
) {
2502 err("Unexpected changeover message on link <%s>\n",
2506 dbg("%c<-%c:", dest_link
->b_ptr
->net_plane
,
2507 (*l_ptr
)->b_ptr
->net_plane
);
2509 msg
= msg_get_wrapped(tunnel_msg
);
2511 if (msg_typ
== DUPLICATE_MSG
) {
2512 if (less(msg_seqno(msg
), mod(dest_link
->next_in_no
))) {
2513 msg_dbg(tunnel_msg
, "DROP/<REC<");
2516 *buf
= buf_extract(tunnel_buf
,INT_H_SIZE
);
2518 warn("Link changeover error, duplicate msg dropped\n");
2521 msg_dbg(tunnel_msg
, "TNL<REC<");
2522 buf_discard(tunnel_buf
);
2526 /* First original message ?: */
2528 if (tipc_link_is_up(dest_link
)) {
2529 msg_dbg(tunnel_msg
, "UP/FIRST/<REC<");
2530 info("Resetting link <%s>, changeover initiated by peer\n",
2532 tipc_link_reset(dest_link
);
2533 dest_link
->exp_msg_count
= msg_count
;
2534 dbg("Expecting %u tunnelled messages\n", msg_count
);
2537 } else if (dest_link
->exp_msg_count
== START_CHANGEOVER
) {
2538 msg_dbg(tunnel_msg
, "BLK/FIRST/<REC<");
2539 dest_link
->exp_msg_count
= msg_count
;
2540 dbg("Expecting %u tunnelled messages\n", msg_count
);
2545 /* Receive original message */
2547 if (dest_link
->exp_msg_count
== 0) {
2548 warn("Link switchover error, "
2549 "got too many tunnelled messages\n");
2550 msg_dbg(tunnel_msg
, "OVERDUE/DROP/<REC<");
2551 dbg_print_link(dest_link
, "LINK:");
2554 dest_link
->exp_msg_count
--;
2555 if (less(msg_seqno(msg
), dest_link
->reset_checkpoint
)) {
2556 msg_dbg(tunnel_msg
, "DROP/DUPL/<REC<");
2559 *buf
= buf_extract(tunnel_buf
, INT_H_SIZE
);
2561 msg_dbg(tunnel_msg
, "TNL<REC<");
2562 buf_discard(tunnel_buf
);
2565 warn("Link changeover error, original msg dropped\n");
2570 buf_discard(tunnel_buf
);
2575 * Bundler functionality:
2577 void tipc_link_recv_bundle(struct sk_buff
*buf
)
2579 u32 msgcount
= msg_msgcnt(buf_msg(buf
));
2580 u32 pos
= INT_H_SIZE
;
2581 struct sk_buff
*obuf
;
2583 msg_dbg(buf_msg(buf
), "<BNDL<: ");
2584 while (msgcount
--) {
2585 obuf
= buf_extract(buf
, pos
);
2587 warn("Link unable to unbundle message(s)\n");
2590 pos
+= align(msg_size(buf_msg(obuf
)));
2591 msg_dbg(buf_msg(obuf
), " /");
2592 tipc_net_route_msg(obuf
);
2598 * Fragmentation/defragmentation:
2603 * link_send_long_buf: Entry for buffers needing fragmentation.
2604 * The buffer is complete, inclusive total message length.
2605 * Returns user data length.
2607 static int link_send_long_buf(struct link
*l_ptr
, struct sk_buff
*buf
)
2609 struct tipc_msg
*inmsg
= buf_msg(buf
);
2610 struct tipc_msg fragm_hdr
;
2611 u32 insize
= msg_size(inmsg
);
2612 u32 dsz
= msg_data_sz(inmsg
);
2613 unchar
*crs
= buf
->data
;
2615 u32 pack_sz
= l_ptr
->max_pkt
;
2616 u32 fragm_sz
= pack_sz
- INT_H_SIZE
;
2620 if (msg_short(inmsg
))
2621 destaddr
= l_ptr
->addr
;
2623 destaddr
= msg_destnode(inmsg
);
2625 if (msg_routed(inmsg
))
2626 msg_set_prevnode(inmsg
, tipc_own_addr
);
2628 /* Prepare reusable fragment header: */
2630 tipc_msg_init(&fragm_hdr
, MSG_FRAGMENTER
, FIRST_FRAGMENT
,
2631 INT_H_SIZE
, destaddr
);
2632 msg_set_link_selector(&fragm_hdr
, msg_link_selector(inmsg
));
2633 msg_set_long_msgno(&fragm_hdr
, mod(l_ptr
->long_msg_seq_no
++));
2634 msg_set_fragm_no(&fragm_hdr
, fragm_no
);
2635 l_ptr
->stats
.sent_fragmented
++;
2637 /* Chop up message: */
2640 struct sk_buff
*fragm
;
2642 if (rest
<= fragm_sz
) {
2644 msg_set_type(&fragm_hdr
, LAST_FRAGMENT
);
2646 fragm
= tipc_buf_acquire(fragm_sz
+ INT_H_SIZE
);
2647 if (fragm
== NULL
) {
2648 warn("Link unable to fragment message\n");
2652 msg_set_size(&fragm_hdr
, fragm_sz
+ INT_H_SIZE
);
2653 skb_copy_to_linear_data(fragm
, &fragm_hdr
, INT_H_SIZE
);
2654 skb_copy_to_linear_data_offset(fragm
, INT_H_SIZE
, crs
,
2656 /* Send queued messages first, if any: */
2658 l_ptr
->stats
.sent_fragments
++;
2659 tipc_link_send_buf(l_ptr
, fragm
);
2660 if (!tipc_link_is_up(l_ptr
))
2662 msg_set_fragm_no(&fragm_hdr
, ++fragm_no
);
2665 msg_set_type(&fragm_hdr
, FRAGMENT
);
2673 * A pending message being re-assembled must store certain values
2674 * to handle subsequent fragments correctly. The following functions
2675 * help storing these values in unused, available fields in the
2676 * pending message. This makes dynamic memory allocation unecessary.
2679 static void set_long_msg_seqno(struct sk_buff
*buf
, u32 seqno
)
2681 msg_set_seqno(buf_msg(buf
), seqno
);
2684 static u32
get_fragm_size(struct sk_buff
*buf
)
2686 return msg_ack(buf_msg(buf
));
2689 static void set_fragm_size(struct sk_buff
*buf
, u32 sz
)
2691 msg_set_ack(buf_msg(buf
), sz
);
2694 static u32
get_expected_frags(struct sk_buff
*buf
)
2696 return msg_bcast_ack(buf_msg(buf
));
2699 static void set_expected_frags(struct sk_buff
*buf
, u32 exp
)
2701 msg_set_bcast_ack(buf_msg(buf
), exp
);
2704 static u32
get_timer_cnt(struct sk_buff
*buf
)
2706 return msg_reroute_cnt(buf_msg(buf
));
2709 static void incr_timer_cnt(struct sk_buff
*buf
)
2711 msg_incr_reroute_cnt(buf_msg(buf
));
2715 * tipc_link_recv_fragment(): Called with node lock on. Returns
2716 * the reassembled buffer if message is complete.
2718 int tipc_link_recv_fragment(struct sk_buff
**pending
, struct sk_buff
**fb
,
2719 struct tipc_msg
**m
)
2721 struct sk_buff
*prev
= NULL
;
2722 struct sk_buff
*fbuf
= *fb
;
2723 struct tipc_msg
*fragm
= buf_msg(fbuf
);
2724 struct sk_buff
*pbuf
= *pending
;
2725 u32 long_msg_seq_no
= msg_long_msgno(fragm
);
2728 msg_dbg(fragm
,"FRG<REC<");
2730 /* Is there an incomplete message waiting for this fragment? */
2732 while (pbuf
&& ((msg_seqno(buf_msg(pbuf
)) != long_msg_seq_no
) ||
2733 (msg_orignode(fragm
) != msg_orignode(buf_msg(pbuf
))))) {
2738 if (!pbuf
&& (msg_type(fragm
) == FIRST_FRAGMENT
)) {
2739 struct tipc_msg
*imsg
= (struct tipc_msg
*)msg_data(fragm
);
2740 u32 msg_sz
= msg_size(imsg
);
2741 u32 fragm_sz
= msg_data_sz(fragm
);
2742 u32 exp_fragm_cnt
= msg_sz
/fragm_sz
+ !!(msg_sz
% fragm_sz
);
2743 u32 max
= TIPC_MAX_USER_MSG_SIZE
+ LONG_H_SIZE
;
2744 if (msg_type(imsg
) == TIPC_MCAST_MSG
)
2745 max
= TIPC_MAX_USER_MSG_SIZE
+ MCAST_H_SIZE
;
2746 if (msg_size(imsg
) > max
) {
2747 msg_dbg(fragm
,"<REC<Oversized: ");
2751 pbuf
= tipc_buf_acquire(msg_size(imsg
));
2753 pbuf
->next
= *pending
;
2755 skb_copy_to_linear_data(pbuf
, imsg
,
2756 msg_data_sz(fragm
));
2757 /* Prepare buffer for subsequent fragments. */
2759 set_long_msg_seqno(pbuf
, long_msg_seq_no
);
2760 set_fragm_size(pbuf
,fragm_sz
);
2761 set_expected_frags(pbuf
,exp_fragm_cnt
- 1);
2763 warn("Link unable to reassemble fragmented message\n");
2767 } else if (pbuf
&& (msg_type(fragm
) != FIRST_FRAGMENT
)) {
2768 u32 dsz
= msg_data_sz(fragm
);
2769 u32 fsz
= get_fragm_size(pbuf
);
2770 u32 crs
= ((msg_fragm_no(fragm
) - 1) * fsz
);
2771 u32 exp_frags
= get_expected_frags(pbuf
) - 1;
2772 skb_copy_to_linear_data_offset(pbuf
, crs
,
2773 msg_data(fragm
), dsz
);
2776 /* Is message complete? */
2778 if (exp_frags
== 0) {
2780 prev
->next
= pbuf
->next
;
2782 *pending
= pbuf
->next
;
2783 msg_reset_reroute_cnt(buf_msg(pbuf
));
2788 set_expected_frags(pbuf
,exp_frags
);
2791 dbg(" Discarding orphan fragment %x\n",fbuf
);
2792 msg_dbg(fragm
,"ORPHAN:");
2793 dbg("Pending long buffers:\n");
2794 dbg_print_buf_chain(*pending
);
2800 * link_check_defragm_bufs - flush stale incoming message fragments
2801 * @l_ptr: pointer to link
2804 static void link_check_defragm_bufs(struct link
*l_ptr
)
2806 struct sk_buff
*prev
= NULL
;
2807 struct sk_buff
*next
= NULL
;
2808 struct sk_buff
*buf
= l_ptr
->defragm_buf
;
2812 if (!link_working_working(l_ptr
))
2815 u32 cnt
= get_timer_cnt(buf
);
2819 incr_timer_cnt(buf
);
2822 dbg(" Discarding incomplete long buffer\n");
2823 msg_dbg(buf_msg(buf
), "LONG:");
2824 dbg_print_link(l_ptr
, "curr:");
2825 dbg("Pending long buffers:\n");
2826 dbg_print_buf_chain(l_ptr
->defragm_buf
);
2828 prev
->next
= buf
->next
;
2830 l_ptr
->defragm_buf
= buf
->next
;
2839 static void link_set_supervision_props(struct link
*l_ptr
, u32 tolerance
)
2841 l_ptr
->tolerance
= tolerance
;
2842 l_ptr
->continuity_interval
=
2843 ((tolerance
/ 4) > 500) ? 500 : tolerance
/ 4;
2844 l_ptr
->abort_limit
= tolerance
/ (l_ptr
->continuity_interval
/ 4);
2848 void tipc_link_set_queue_limits(struct link
*l_ptr
, u32 window
)
2850 /* Data messages from this node, inclusive FIRST_FRAGM */
2851 l_ptr
->queue_limit
[TIPC_LOW_IMPORTANCE
] = window
;
2852 l_ptr
->queue_limit
[TIPC_MEDIUM_IMPORTANCE
] = (window
/ 3) * 4;
2853 l_ptr
->queue_limit
[TIPC_HIGH_IMPORTANCE
] = (window
/ 3) * 5;
2854 l_ptr
->queue_limit
[TIPC_CRITICAL_IMPORTANCE
] = (window
/ 3) * 6;
2855 /* Transiting data messages,inclusive FIRST_FRAGM */
2856 l_ptr
->queue_limit
[TIPC_LOW_IMPORTANCE
+ 4] = 300;
2857 l_ptr
->queue_limit
[TIPC_MEDIUM_IMPORTANCE
+ 4] = 600;
2858 l_ptr
->queue_limit
[TIPC_HIGH_IMPORTANCE
+ 4] = 900;
2859 l_ptr
->queue_limit
[TIPC_CRITICAL_IMPORTANCE
+ 4] = 1200;
2860 l_ptr
->queue_limit
[CONN_MANAGER
] = 1200;
2861 l_ptr
->queue_limit
[ROUTE_DISTRIBUTOR
] = 1200;
2862 l_ptr
->queue_limit
[CHANGEOVER_PROTOCOL
] = 2500;
2863 l_ptr
->queue_limit
[NAME_DISTRIBUTOR
] = 3000;
2864 /* FRAGMENT and LAST_FRAGMENT packets */
2865 l_ptr
->queue_limit
[MSG_FRAGMENTER
] = 4000;
2869 * link_find_link - locate link by name
2870 * @name - ptr to link name string
2871 * @node - ptr to area to be filled with ptr to associated node
2873 * Caller must hold 'tipc_net_lock' to ensure node and bearer are not deleted;
2874 * this also prevents link deletion.
2876 * Returns pointer to link (or 0 if invalid link name).
2879 static struct link
*link_find_link(const char *name
, struct tipc_node
**node
)
2881 struct link_name link_name_parts
;
2882 struct bearer
*b_ptr
;
2885 if (!link_name_validate(name
, &link_name_parts
))
2888 b_ptr
= tipc_bearer_find_interface(link_name_parts
.if_local
);
2892 *node
= tipc_node_find(link_name_parts
.addr_peer
);
2896 l_ptr
= (*node
)->links
[b_ptr
->identity
];
2897 if (!l_ptr
|| strcmp(l_ptr
->name
, name
))
2903 struct sk_buff
*tipc_link_cmd_config(const void *req_tlv_area
, int req_tlv_space
,
2906 struct tipc_link_config
*args
;
2909 struct tipc_node
*node
;
2912 if (!TLV_CHECK(req_tlv_area
, req_tlv_space
, TIPC_TLV_LINK_CONFIG
))
2913 return tipc_cfg_reply_error_string(TIPC_CFG_TLV_ERROR
);
2915 args
= (struct tipc_link_config
*)TLV_DATA(req_tlv_area
);
2916 new_value
= ntohl(args
->value
);
2918 if (!strcmp(args
->name
, tipc_bclink_name
)) {
2919 if ((cmd
== TIPC_CMD_SET_LINK_WINDOW
) &&
2920 (tipc_bclink_set_queue_limits(new_value
) == 0))
2921 return tipc_cfg_reply_none();
2922 return tipc_cfg_reply_error_string(TIPC_CFG_NOT_SUPPORTED
2923 " (cannot change setting on broadcast link)");
2926 read_lock_bh(&tipc_net_lock
);
2927 l_ptr
= link_find_link(args
->name
, &node
);
2929 read_unlock_bh(&tipc_net_lock
);
2930 return tipc_cfg_reply_error_string("link not found");
2933 tipc_node_lock(node
);
2936 case TIPC_CMD_SET_LINK_TOL
:
2937 if ((new_value
>= TIPC_MIN_LINK_TOL
) &&
2938 (new_value
<= TIPC_MAX_LINK_TOL
)) {
2939 link_set_supervision_props(l_ptr
, new_value
);
2940 tipc_link_send_proto_msg(l_ptr
, STATE_MSG
,
2941 0, 0, new_value
, 0, 0);
2945 case TIPC_CMD_SET_LINK_PRI
:
2946 if ((new_value
>= TIPC_MIN_LINK_PRI
) &&
2947 (new_value
<= TIPC_MAX_LINK_PRI
)) {
2948 l_ptr
->priority
= new_value
;
2949 tipc_link_send_proto_msg(l_ptr
, STATE_MSG
,
2950 0, 0, 0, new_value
, 0);
2954 case TIPC_CMD_SET_LINK_WINDOW
:
2955 if ((new_value
>= TIPC_MIN_LINK_WIN
) &&
2956 (new_value
<= TIPC_MAX_LINK_WIN
)) {
2957 tipc_link_set_queue_limits(l_ptr
, new_value
);
2962 tipc_node_unlock(node
);
2964 read_unlock_bh(&tipc_net_lock
);
2966 return tipc_cfg_reply_error_string("cannot change link setting");
2968 return tipc_cfg_reply_none();
2972 * link_reset_statistics - reset link statistics
2973 * @l_ptr: pointer to link
2976 static void link_reset_statistics(struct link
*l_ptr
)
2978 memset(&l_ptr
->stats
, 0, sizeof(l_ptr
->stats
));
2979 l_ptr
->stats
.sent_info
= l_ptr
->next_out_no
;
2980 l_ptr
->stats
.recv_info
= l_ptr
->next_in_no
;
2983 struct sk_buff
*tipc_link_cmd_reset_stats(const void *req_tlv_area
, int req_tlv_space
)
2987 struct tipc_node
*node
;
2989 if (!TLV_CHECK(req_tlv_area
, req_tlv_space
, TIPC_TLV_LINK_NAME
))
2990 return tipc_cfg_reply_error_string(TIPC_CFG_TLV_ERROR
);
2992 link_name
= (char *)TLV_DATA(req_tlv_area
);
2993 if (!strcmp(link_name
, tipc_bclink_name
)) {
2994 if (tipc_bclink_reset_stats())
2995 return tipc_cfg_reply_error_string("link not found");
2996 return tipc_cfg_reply_none();
2999 read_lock_bh(&tipc_net_lock
);
3000 l_ptr
= link_find_link(link_name
, &node
);
3002 read_unlock_bh(&tipc_net_lock
);
3003 return tipc_cfg_reply_error_string("link not found");
3006 tipc_node_lock(node
);
3007 link_reset_statistics(l_ptr
);
3008 tipc_node_unlock(node
);
3009 read_unlock_bh(&tipc_net_lock
);
3010 return tipc_cfg_reply_none();
3014 * percent - convert count to a percentage of total (rounding up or down)
3017 static u32
percent(u32 count
, u32 total
)
3019 return (count
* 100 + (total
/ 2)) / total
;
3023 * tipc_link_stats - print link statistics
3025 * @buf: print buffer area
3026 * @buf_size: size of print buffer area
3028 * Returns length of print buffer data string (or 0 if error)
3031 static int tipc_link_stats(const char *name
, char *buf
, const u32 buf_size
)
3033 struct print_buf pb
;
3035 struct tipc_node
*node
;
3037 u32 profile_total
= 0;
3039 if (!strcmp(name
, tipc_bclink_name
))
3040 return tipc_bclink_stats(buf
, buf_size
);
3042 tipc_printbuf_init(&pb
, buf
, buf_size
);
3044 read_lock_bh(&tipc_net_lock
);
3045 l_ptr
= link_find_link(name
, &node
);
3047 read_unlock_bh(&tipc_net_lock
);
3050 tipc_node_lock(node
);
3052 if (tipc_link_is_active(l_ptr
))
3054 else if (tipc_link_is_up(l_ptr
))
3058 tipc_printf(&pb
, "Link <%s>\n"
3059 " %s MTU:%u Priority:%u Tolerance:%u ms"
3060 " Window:%u packets\n",
3061 l_ptr
->name
, status
, l_ptr
->max_pkt
,
3062 l_ptr
->priority
, l_ptr
->tolerance
, l_ptr
->queue_limit
[0]);
3063 tipc_printf(&pb
, " RX packets:%u fragments:%u/%u bundles:%u/%u\n",
3064 l_ptr
->next_in_no
- l_ptr
->stats
.recv_info
,
3065 l_ptr
->stats
.recv_fragments
,
3066 l_ptr
->stats
.recv_fragmented
,
3067 l_ptr
->stats
.recv_bundles
,
3068 l_ptr
->stats
.recv_bundled
);
3069 tipc_printf(&pb
, " TX packets:%u fragments:%u/%u bundles:%u/%u\n",
3070 l_ptr
->next_out_no
- l_ptr
->stats
.sent_info
,
3071 l_ptr
->stats
.sent_fragments
,
3072 l_ptr
->stats
.sent_fragmented
,
3073 l_ptr
->stats
.sent_bundles
,
3074 l_ptr
->stats
.sent_bundled
);
3075 profile_total
= l_ptr
->stats
.msg_length_counts
;
3078 tipc_printf(&pb
, " TX profile sample:%u packets average:%u octets\n"
3079 " 0-64:%u%% -256:%u%% -1024:%u%% -4096:%u%% "
3080 "-16354:%u%% -32768:%u%% -66000:%u%%\n",
3081 l_ptr
->stats
.msg_length_counts
,
3082 l_ptr
->stats
.msg_lengths_total
/ profile_total
,
3083 percent(l_ptr
->stats
.msg_length_profile
[0], profile_total
),
3084 percent(l_ptr
->stats
.msg_length_profile
[1], profile_total
),
3085 percent(l_ptr
->stats
.msg_length_profile
[2], profile_total
),
3086 percent(l_ptr
->stats
.msg_length_profile
[3], profile_total
),
3087 percent(l_ptr
->stats
.msg_length_profile
[4], profile_total
),
3088 percent(l_ptr
->stats
.msg_length_profile
[5], profile_total
),
3089 percent(l_ptr
->stats
.msg_length_profile
[6], profile_total
));
3090 tipc_printf(&pb
, " RX states:%u probes:%u naks:%u defs:%u dups:%u\n",
3091 l_ptr
->stats
.recv_states
,
3092 l_ptr
->stats
.recv_probes
,
3093 l_ptr
->stats
.recv_nacks
,
3094 l_ptr
->stats
.deferred_recv
,
3095 l_ptr
->stats
.duplicates
);
3096 tipc_printf(&pb
, " TX states:%u probes:%u naks:%u acks:%u dups:%u\n",
3097 l_ptr
->stats
.sent_states
,
3098 l_ptr
->stats
.sent_probes
,
3099 l_ptr
->stats
.sent_nacks
,
3100 l_ptr
->stats
.sent_acks
,
3101 l_ptr
->stats
.retransmitted
);
3102 tipc_printf(&pb
, " Congestion bearer:%u link:%u Send queue max:%u avg:%u\n",
3103 l_ptr
->stats
.bearer_congs
,
3104 l_ptr
->stats
.link_congs
,
3105 l_ptr
->stats
.max_queue_sz
,
3106 l_ptr
->stats
.queue_sz_counts
3107 ? (l_ptr
->stats
.accu_queue_sz
/ l_ptr
->stats
.queue_sz_counts
)
3110 tipc_node_unlock(node
);
3111 read_unlock_bh(&tipc_net_lock
);
3112 return tipc_printbuf_validate(&pb
);
3115 #define MAX_LINK_STATS_INFO 2000
3117 struct sk_buff
*tipc_link_cmd_show_stats(const void *req_tlv_area
, int req_tlv_space
)
3119 struct sk_buff
*buf
;
3120 struct tlv_desc
*rep_tlv
;
3123 if (!TLV_CHECK(req_tlv_area
, req_tlv_space
, TIPC_TLV_LINK_NAME
))
3124 return tipc_cfg_reply_error_string(TIPC_CFG_TLV_ERROR
);
3126 buf
= tipc_cfg_reply_alloc(TLV_SPACE(MAX_LINK_STATS_INFO
));
3130 rep_tlv
= (struct tlv_desc
*)buf
->data
;
3132 str_len
= tipc_link_stats((char *)TLV_DATA(req_tlv_area
),
3133 (char *)TLV_DATA(rep_tlv
), MAX_LINK_STATS_INFO
);
3136 return tipc_cfg_reply_error_string("link not found");
3139 skb_put(buf
, TLV_SPACE(str_len
));
3140 TLV_SET(rep_tlv
, TIPC_TLV_ULTRA_STRING
, NULL
, str_len
);
3146 * tipc_link_get_max_pkt - get maximum packet size to use when sending to destination
3147 * @dest: network address of destination node
3148 * @selector: used to select from set of active links
3150 * If no active link can be found, uses default maximum packet size.
3153 u32
tipc_link_get_max_pkt(u32 dest
, u32 selector
)
3155 struct tipc_node
*n_ptr
;
3157 u32 res
= MAX_PKT_DEFAULT
;
3159 if (dest
== tipc_own_addr
)
3160 return MAX_MSG_SIZE
;
3162 read_lock_bh(&tipc_net_lock
);
3163 n_ptr
= tipc_node_select(dest
, selector
);
3165 tipc_node_lock(n_ptr
);
3166 l_ptr
= n_ptr
->active_links
[selector
& 1];
3168 res
= l_ptr
->max_pkt
;
3169 tipc_node_unlock(n_ptr
);
3171 read_unlock_bh(&tipc_net_lock
);
3175 static void link_dump_send_queue(struct link
*l_ptr
)
3177 if (l_ptr
->next_out
) {
3178 info("\nContents of unsent queue:\n");
3179 dbg_print_buf_chain(l_ptr
->next_out
);
3181 info("\nContents of send queue:\n");
3182 if (l_ptr
->first_out
) {
3183 dbg_print_buf_chain(l_ptr
->first_out
);
3185 info("Empty send queue\n");
3188 static void link_print(struct link
*l_ptr
, struct print_buf
*buf
,
3191 tipc_printf(buf
, str
);
3192 if (link_reset_reset(l_ptr
) || link_reset_unknown(l_ptr
))
3194 tipc_printf(buf
, "Link %x<%s>:",
3195 l_ptr
->addr
, l_ptr
->b_ptr
->publ
.name
);
3196 tipc_printf(buf
, ": NXO(%u):", mod(l_ptr
->next_out_no
));
3197 tipc_printf(buf
, "NXI(%u):", mod(l_ptr
->next_in_no
));
3198 tipc_printf(buf
, "SQUE");
3199 if (l_ptr
->first_out
) {
3200 tipc_printf(buf
, "[%u..", msg_seqno(buf_msg(l_ptr
->first_out
)));
3201 if (l_ptr
->next_out
)
3202 tipc_printf(buf
, "%u..",
3203 msg_seqno(buf_msg(l_ptr
->next_out
)));
3204 tipc_printf(buf
, "%u]", msg_seqno(buf_msg(l_ptr
->last_out
)));
3205 if ((mod(msg_seqno(buf_msg(l_ptr
->last_out
)) -
3206 msg_seqno(buf_msg(l_ptr
->first_out
)))
3207 != (l_ptr
->out_queue_size
- 1)) ||
3208 (l_ptr
->last_out
->next
!= NULL
)) {
3209 tipc_printf(buf
, "\nSend queue inconsistency\n");
3210 tipc_printf(buf
, "first_out= %x ", l_ptr
->first_out
);
3211 tipc_printf(buf
, "next_out= %x ", l_ptr
->next_out
);
3212 tipc_printf(buf
, "last_out= %x ", l_ptr
->last_out
);
3213 link_dump_send_queue(l_ptr
);
3216 tipc_printf(buf
, "[]");
3217 tipc_printf(buf
, "SQSIZ(%u)", l_ptr
->out_queue_size
);
3218 if (l_ptr
->oldest_deferred_in
) {
3219 u32 o
= msg_seqno(buf_msg(l_ptr
->oldest_deferred_in
));
3220 u32 n
= msg_seqno(buf_msg(l_ptr
->newest_deferred_in
));
3221 tipc_printf(buf
, ":RQUE[%u..%u]", o
, n
);
3222 if (l_ptr
->deferred_inqueue_sz
!= mod((n
+ 1) - o
)) {
3223 tipc_printf(buf
, ":RQSIZ(%u)",
3224 l_ptr
->deferred_inqueue_sz
);
3227 if (link_working_unknown(l_ptr
))
3228 tipc_printf(buf
, ":WU");
3229 if (link_reset_reset(l_ptr
))
3230 tipc_printf(buf
, ":RR");
3231 if (link_reset_unknown(l_ptr
))
3232 tipc_printf(buf
, ":RU");
3233 if (link_working_working(l_ptr
))
3234 tipc_printf(buf
, ":WW");
3235 tipc_printf(buf
, "\n");