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.
41 #include "name_distr.h"
46 #include <linux/pkt_sched.h>
49 * Error message prefixes
51 static const char *link_co_err
= "Link changeover error, ";
52 static const char *link_rst_msg
= "Resetting link ";
53 static const char *link_unk_evt
= "Unknown link event ";
55 static const struct nla_policy tipc_nl_link_policy
[TIPC_NLA_LINK_MAX
+ 1] = {
56 [TIPC_NLA_LINK_UNSPEC
] = { .type
= NLA_UNSPEC
},
57 [TIPC_NLA_LINK_NAME
] = {
59 .len
= TIPC_MAX_LINK_NAME
61 [TIPC_NLA_LINK_MTU
] = { .type
= NLA_U32
},
62 [TIPC_NLA_LINK_BROADCAST
] = { .type
= NLA_FLAG
},
63 [TIPC_NLA_LINK_UP
] = { .type
= NLA_FLAG
},
64 [TIPC_NLA_LINK_ACTIVE
] = { .type
= NLA_FLAG
},
65 [TIPC_NLA_LINK_PROP
] = { .type
= NLA_NESTED
},
66 [TIPC_NLA_LINK_STATS
] = { .type
= NLA_NESTED
},
67 [TIPC_NLA_LINK_RX
] = { .type
= NLA_U32
},
68 [TIPC_NLA_LINK_TX
] = { .type
= NLA_U32
}
71 /* Properties valid for media, bearar and link */
72 static const struct nla_policy tipc_nl_prop_policy
[TIPC_NLA_PROP_MAX
+ 1] = {
73 [TIPC_NLA_PROP_UNSPEC
] = { .type
= NLA_UNSPEC
},
74 [TIPC_NLA_PROP_PRIO
] = { .type
= NLA_U32
},
75 [TIPC_NLA_PROP_TOL
] = { .type
= NLA_U32
},
76 [TIPC_NLA_PROP_WIN
] = { .type
= NLA_U32
}
80 * Out-of-range value for link session numbers
82 #define INVALID_SESSION 0x10000
87 #define STARTING_EVT 856384768 /* link processing trigger */
88 #define TRAFFIC_MSG_EVT 560815u /* rx'd ??? */
89 #define TIMEOUT_EVT 560817u /* link timer expired */
92 * The following two 'message types' is really just implementation
93 * data conveniently stored in the message header.
94 * They must not be considered part of the protocol
100 * State value stored in 'exp_msg_count'
102 #define START_CHANGEOVER 100000u
104 static void link_handle_out_of_seq_msg(struct tipc_link
*l_ptr
,
105 struct sk_buff
*buf
);
106 static void tipc_link_proto_rcv(struct tipc_link
*l_ptr
, struct sk_buff
*buf
);
107 static int tipc_link_tunnel_rcv(struct tipc_node
*n_ptr
,
108 struct sk_buff
**buf
);
109 static void link_set_supervision_props(struct tipc_link
*l_ptr
, u32 tolerance
);
110 static void link_state_event(struct tipc_link
*l_ptr
, u32 event
);
111 static void link_reset_statistics(struct tipc_link
*l_ptr
);
112 static void link_print(struct tipc_link
*l_ptr
, const char *str
);
113 static void tipc_link_sync_xmit(struct tipc_link
*l
);
114 static void tipc_link_sync_rcv(struct tipc_node
*n
, struct sk_buff
*buf
);
115 static int tipc_link_input(struct tipc_link
*l
, struct sk_buff
*buf
);
116 static int tipc_link_prepare_input(struct tipc_link
*l
, struct sk_buff
**buf
);
119 * Simple link routines
121 static unsigned int align(unsigned int i
)
123 return (i
+ 3) & ~3u;
126 static void link_init_max_pkt(struct tipc_link
*l_ptr
)
128 struct tipc_bearer
*b_ptr
;
132 b_ptr
= rcu_dereference_rtnl(bearer_list
[l_ptr
->bearer_id
]);
137 max_pkt
= (b_ptr
->mtu
& ~3);
140 if (max_pkt
> MAX_MSG_SIZE
)
141 max_pkt
= MAX_MSG_SIZE
;
143 l_ptr
->max_pkt_target
= max_pkt
;
144 if (l_ptr
->max_pkt_target
< MAX_PKT_DEFAULT
)
145 l_ptr
->max_pkt
= l_ptr
->max_pkt_target
;
147 l_ptr
->max_pkt
= MAX_PKT_DEFAULT
;
149 l_ptr
->max_pkt_probes
= 0;
152 static u32
link_next_sent(struct tipc_link
*l_ptr
)
155 return buf_seqno(l_ptr
->next_out
);
156 return mod(l_ptr
->next_out_no
);
159 static u32
link_last_sent(struct tipc_link
*l_ptr
)
161 return mod(link_next_sent(l_ptr
) - 1);
165 * Simple non-static link routines (i.e. referenced outside this file)
167 int tipc_link_is_up(struct tipc_link
*l_ptr
)
171 return link_working_working(l_ptr
) || link_working_unknown(l_ptr
);
174 int tipc_link_is_active(struct tipc_link
*l_ptr
)
176 return (l_ptr
->owner
->active_links
[0] == l_ptr
) ||
177 (l_ptr
->owner
->active_links
[1] == l_ptr
);
181 * link_timeout - handle expiration of link timer
182 * @l_ptr: pointer to link
184 static void link_timeout(struct tipc_link
*l_ptr
)
186 tipc_node_lock(l_ptr
->owner
);
188 /* update counters used in statistical profiling of send traffic */
189 l_ptr
->stats
.accu_queue_sz
+= l_ptr
->out_queue_size
;
190 l_ptr
->stats
.queue_sz_counts
++;
192 if (l_ptr
->first_out
) {
193 struct tipc_msg
*msg
= buf_msg(l_ptr
->first_out
);
194 u32 length
= msg_size(msg
);
196 if ((msg_user(msg
) == MSG_FRAGMENTER
) &&
197 (msg_type(msg
) == FIRST_FRAGMENT
)) {
198 length
= msg_size(msg_get_wrapped(msg
));
201 l_ptr
->stats
.msg_lengths_total
+= length
;
202 l_ptr
->stats
.msg_length_counts
++;
204 l_ptr
->stats
.msg_length_profile
[0]++;
205 else if (length
<= 256)
206 l_ptr
->stats
.msg_length_profile
[1]++;
207 else if (length
<= 1024)
208 l_ptr
->stats
.msg_length_profile
[2]++;
209 else if (length
<= 4096)
210 l_ptr
->stats
.msg_length_profile
[3]++;
211 else if (length
<= 16384)
212 l_ptr
->stats
.msg_length_profile
[4]++;
213 else if (length
<= 32768)
214 l_ptr
->stats
.msg_length_profile
[5]++;
216 l_ptr
->stats
.msg_length_profile
[6]++;
220 /* do all other link processing performed on a periodic basis */
222 link_state_event(l_ptr
, TIMEOUT_EVT
);
225 tipc_link_push_queue(l_ptr
);
227 tipc_node_unlock(l_ptr
->owner
);
230 static void link_set_timer(struct tipc_link
*l_ptr
, u32 time
)
232 k_start_timer(&l_ptr
->timer
, time
);
236 * tipc_link_create - create a new link
237 * @n_ptr: pointer to associated node
238 * @b_ptr: pointer to associated bearer
239 * @media_addr: media address to use when sending messages over link
241 * Returns pointer to link.
243 struct tipc_link
*tipc_link_create(struct tipc_node
*n_ptr
,
244 struct tipc_bearer
*b_ptr
,
245 const struct tipc_media_addr
*media_addr
)
247 struct tipc_link
*l_ptr
;
248 struct tipc_msg
*msg
;
250 char addr_string
[16];
251 u32 peer
= n_ptr
->addr
;
253 if (n_ptr
->link_cnt
>= MAX_BEARERS
) {
254 tipc_addr_string_fill(addr_string
, n_ptr
->addr
);
255 pr_err("Attempt to establish %uth link to %s. Max %u allowed.\n",
256 n_ptr
->link_cnt
, addr_string
, MAX_BEARERS
);
260 if (n_ptr
->links
[b_ptr
->identity
]) {
261 tipc_addr_string_fill(addr_string
, n_ptr
->addr
);
262 pr_err("Attempt to establish second link on <%s> to %s\n",
263 b_ptr
->name
, addr_string
);
267 l_ptr
= kzalloc(sizeof(*l_ptr
), GFP_ATOMIC
);
269 pr_warn("Link creation failed, no memory\n");
274 if_name
= strchr(b_ptr
->name
, ':') + 1;
275 sprintf(l_ptr
->name
, "%u.%u.%u:%s-%u.%u.%u:unknown",
276 tipc_zone(tipc_own_addr
), tipc_cluster(tipc_own_addr
),
277 tipc_node(tipc_own_addr
),
279 tipc_zone(peer
), tipc_cluster(peer
), tipc_node(peer
));
280 /* note: peer i/f name is updated by reset/activate message */
281 memcpy(&l_ptr
->media_addr
, media_addr
, sizeof(*media_addr
));
282 l_ptr
->owner
= n_ptr
;
283 l_ptr
->checkpoint
= 1;
284 l_ptr
->peer_session
= INVALID_SESSION
;
285 l_ptr
->bearer_id
= b_ptr
->identity
;
286 link_set_supervision_props(l_ptr
, b_ptr
->tolerance
);
287 l_ptr
->state
= RESET_UNKNOWN
;
289 l_ptr
->pmsg
= (struct tipc_msg
*)&l_ptr
->proto_msg
;
291 tipc_msg_init(msg
, LINK_PROTOCOL
, RESET_MSG
, INT_H_SIZE
, l_ptr
->addr
);
292 msg_set_size(msg
, sizeof(l_ptr
->proto_msg
));
293 msg_set_session(msg
, (tipc_random
& 0xffff));
294 msg_set_bearer_id(msg
, b_ptr
->identity
);
295 strcpy((char *)msg_data(msg
), if_name
);
297 l_ptr
->priority
= b_ptr
->priority
;
298 tipc_link_set_queue_limits(l_ptr
, b_ptr
->window
);
300 l_ptr
->net_plane
= b_ptr
->net_plane
;
301 link_init_max_pkt(l_ptr
);
303 l_ptr
->next_out_no
= 1;
304 __skb_queue_head_init(&l_ptr
->waiting_sks
);
306 link_reset_statistics(l_ptr
);
308 tipc_node_attach_link(n_ptr
, l_ptr
);
310 k_init_timer(&l_ptr
->timer
, (Handler
)link_timeout
,
311 (unsigned long)l_ptr
);
313 link_state_event(l_ptr
, STARTING_EVT
);
318 void tipc_link_delete_list(unsigned int bearer_id
, bool shutting_down
)
320 struct tipc_link
*l_ptr
;
321 struct tipc_node
*n_ptr
;
324 list_for_each_entry_rcu(n_ptr
, &tipc_node_list
, list
) {
325 tipc_node_lock(n_ptr
);
326 l_ptr
= n_ptr
->links
[bearer_id
];
328 tipc_link_reset(l_ptr
);
329 if (shutting_down
|| !tipc_node_is_up(n_ptr
)) {
330 tipc_node_detach_link(l_ptr
->owner
, l_ptr
);
331 tipc_link_reset_fragments(l_ptr
);
332 tipc_node_unlock(n_ptr
);
334 /* Nobody else can access this link now: */
335 del_timer_sync(&l_ptr
->timer
);
338 /* Detach/delete when failover is finished: */
339 l_ptr
->flags
|= LINK_STOPPED
;
340 tipc_node_unlock(n_ptr
);
341 del_timer_sync(&l_ptr
->timer
);
345 tipc_node_unlock(n_ptr
);
351 * link_schedule_user - schedule user for wakeup after congestion
352 * @link: congested link
353 * @oport: sending port
354 * @chain_sz: size of buffer chain that was attempted sent
355 * @imp: importance of message attempted sent
356 * Create pseudo msg to send back to user when congestion abates
358 static bool link_schedule_user(struct tipc_link
*link
, u32 oport
,
359 uint chain_sz
, uint imp
)
363 buf
= tipc_msg_create(SOCK_WAKEUP
, 0, INT_H_SIZE
, 0, tipc_own_addr
,
364 tipc_own_addr
, oport
, 0, 0);
367 TIPC_SKB_CB(buf
)->chain_sz
= chain_sz
;
368 TIPC_SKB_CB(buf
)->chain_imp
= imp
;
369 __skb_queue_tail(&link
->waiting_sks
, buf
);
370 link
->stats
.link_congs
++;
375 * link_prepare_wakeup - prepare users for wakeup after congestion
376 * @link: congested link
377 * Move a number of waiting users, as permitted by available space in
378 * the send queue, from link wait queue to node wait queue for wakeup
380 static void link_prepare_wakeup(struct tipc_link
*link
)
382 struct sk_buff_head
*wq
= &link
->waiting_sks
;
384 uint pend_qsz
= link
->out_queue_size
;
386 for (buf
= skb_peek(wq
); buf
; buf
= skb_peek(wq
)) {
387 if (pend_qsz
>= link
->queue_limit
[TIPC_SKB_CB(buf
)->chain_imp
])
389 pend_qsz
+= TIPC_SKB_CB(buf
)->chain_sz
;
390 __skb_queue_tail(&link
->owner
->waiting_sks
, __skb_dequeue(wq
));
395 * link_release_outqueue - purge link's outbound message queue
396 * @l_ptr: pointer to link
398 static void link_release_outqueue(struct tipc_link
*l_ptr
)
400 kfree_skb_list(l_ptr
->first_out
);
401 l_ptr
->first_out
= NULL
;
402 l_ptr
->out_queue_size
= 0;
406 * tipc_link_reset_fragments - purge link's inbound message fragments queue
407 * @l_ptr: pointer to link
409 void tipc_link_reset_fragments(struct tipc_link
*l_ptr
)
411 kfree_skb(l_ptr
->reasm_buf
);
412 l_ptr
->reasm_buf
= NULL
;
416 * tipc_link_purge_queues - purge all pkt queues associated with link
417 * @l_ptr: pointer to link
419 void tipc_link_purge_queues(struct tipc_link
*l_ptr
)
421 kfree_skb_list(l_ptr
->oldest_deferred_in
);
422 kfree_skb_list(l_ptr
->first_out
);
423 tipc_link_reset_fragments(l_ptr
);
426 void tipc_link_reset(struct tipc_link
*l_ptr
)
428 u32 prev_state
= l_ptr
->state
;
429 u32 checkpoint
= l_ptr
->next_in_no
;
430 int was_active_link
= tipc_link_is_active(l_ptr
);
431 struct tipc_node
*owner
= l_ptr
->owner
;
433 msg_set_session(l_ptr
->pmsg
, ((msg_session(l_ptr
->pmsg
) + 1) & 0xffff));
435 /* Link is down, accept any session */
436 l_ptr
->peer_session
= INVALID_SESSION
;
438 /* Prepare for max packet size negotiation */
439 link_init_max_pkt(l_ptr
);
441 l_ptr
->state
= RESET_UNKNOWN
;
443 if ((prev_state
== RESET_UNKNOWN
) || (prev_state
== RESET_RESET
))
446 tipc_node_link_down(l_ptr
->owner
, l_ptr
);
447 tipc_bearer_remove_dest(l_ptr
->bearer_id
, l_ptr
->addr
);
449 if (was_active_link
&& tipc_node_active_links(l_ptr
->owner
)) {
450 l_ptr
->reset_checkpoint
= checkpoint
;
451 l_ptr
->exp_msg_count
= START_CHANGEOVER
;
454 /* Clean up all queues: */
455 link_release_outqueue(l_ptr
);
456 kfree_skb_list(l_ptr
->oldest_deferred_in
);
457 if (!skb_queue_empty(&l_ptr
->waiting_sks
)) {
458 skb_queue_splice_init(&l_ptr
->waiting_sks
, &owner
->waiting_sks
);
459 owner
->action_flags
|= TIPC_WAKEUP_USERS
;
461 l_ptr
->retransm_queue_head
= 0;
462 l_ptr
->retransm_queue_size
= 0;
463 l_ptr
->last_out
= NULL
;
464 l_ptr
->first_out
= NULL
;
465 l_ptr
->next_out
= NULL
;
466 l_ptr
->unacked_window
= 0;
467 l_ptr
->checkpoint
= 1;
468 l_ptr
->next_out_no
= 1;
469 l_ptr
->deferred_inqueue_sz
= 0;
470 l_ptr
->oldest_deferred_in
= NULL
;
471 l_ptr
->newest_deferred_in
= NULL
;
472 l_ptr
->fsm_msg_cnt
= 0;
473 l_ptr
->stale_count
= 0;
474 link_reset_statistics(l_ptr
);
477 void tipc_link_reset_list(unsigned int bearer_id
)
479 struct tipc_link
*l_ptr
;
480 struct tipc_node
*n_ptr
;
483 list_for_each_entry_rcu(n_ptr
, &tipc_node_list
, list
) {
484 tipc_node_lock(n_ptr
);
485 l_ptr
= n_ptr
->links
[bearer_id
];
487 tipc_link_reset(l_ptr
);
488 tipc_node_unlock(n_ptr
);
493 static void link_activate(struct tipc_link
*l_ptr
)
495 l_ptr
->next_in_no
= l_ptr
->stats
.recv_info
= 1;
496 tipc_node_link_up(l_ptr
->owner
, l_ptr
);
497 tipc_bearer_add_dest(l_ptr
->bearer_id
, l_ptr
->addr
);
501 * link_state_event - link finite state machine
502 * @l_ptr: pointer to link
503 * @event: state machine event to process
505 static void link_state_event(struct tipc_link
*l_ptr
, unsigned int event
)
507 struct tipc_link
*other
;
508 u32 cont_intv
= l_ptr
->continuity_interval
;
510 if (l_ptr
->flags
& LINK_STOPPED
)
513 if (!(l_ptr
->flags
& LINK_STARTED
) && (event
!= STARTING_EVT
))
514 return; /* Not yet. */
516 /* Check whether changeover is going on */
517 if (l_ptr
->exp_msg_count
) {
518 if (event
== TIMEOUT_EVT
)
519 link_set_timer(l_ptr
, cont_intv
);
523 switch (l_ptr
->state
) {
524 case WORKING_WORKING
:
526 case TRAFFIC_MSG_EVT
:
530 if (l_ptr
->next_in_no
!= l_ptr
->checkpoint
) {
531 l_ptr
->checkpoint
= l_ptr
->next_in_no
;
532 if (tipc_bclink_acks_missing(l_ptr
->owner
)) {
533 tipc_link_proto_xmit(l_ptr
, STATE_MSG
,
535 l_ptr
->fsm_msg_cnt
++;
536 } else if (l_ptr
->max_pkt
< l_ptr
->max_pkt_target
) {
537 tipc_link_proto_xmit(l_ptr
, STATE_MSG
,
539 l_ptr
->fsm_msg_cnt
++;
541 link_set_timer(l_ptr
, cont_intv
);
544 l_ptr
->state
= WORKING_UNKNOWN
;
545 l_ptr
->fsm_msg_cnt
= 0;
546 tipc_link_proto_xmit(l_ptr
, STATE_MSG
, 1, 0, 0, 0, 0);
547 l_ptr
->fsm_msg_cnt
++;
548 link_set_timer(l_ptr
, cont_intv
/ 4);
551 pr_info("%s<%s>, requested by peer\n", link_rst_msg
,
553 tipc_link_reset(l_ptr
);
554 l_ptr
->state
= RESET_RESET
;
555 l_ptr
->fsm_msg_cnt
= 0;
556 tipc_link_proto_xmit(l_ptr
, ACTIVATE_MSG
,
558 l_ptr
->fsm_msg_cnt
++;
559 link_set_timer(l_ptr
, cont_intv
);
562 pr_err("%s%u in WW state\n", link_unk_evt
, event
);
565 case WORKING_UNKNOWN
:
567 case TRAFFIC_MSG_EVT
:
569 l_ptr
->state
= WORKING_WORKING
;
570 l_ptr
->fsm_msg_cnt
= 0;
571 link_set_timer(l_ptr
, cont_intv
);
574 pr_info("%s<%s>, requested by peer while probing\n",
575 link_rst_msg
, l_ptr
->name
);
576 tipc_link_reset(l_ptr
);
577 l_ptr
->state
= RESET_RESET
;
578 l_ptr
->fsm_msg_cnt
= 0;
579 tipc_link_proto_xmit(l_ptr
, ACTIVATE_MSG
,
581 l_ptr
->fsm_msg_cnt
++;
582 link_set_timer(l_ptr
, cont_intv
);
585 if (l_ptr
->next_in_no
!= l_ptr
->checkpoint
) {
586 l_ptr
->state
= WORKING_WORKING
;
587 l_ptr
->fsm_msg_cnt
= 0;
588 l_ptr
->checkpoint
= l_ptr
->next_in_no
;
589 if (tipc_bclink_acks_missing(l_ptr
->owner
)) {
590 tipc_link_proto_xmit(l_ptr
, STATE_MSG
,
592 l_ptr
->fsm_msg_cnt
++;
594 link_set_timer(l_ptr
, cont_intv
);
595 } else if (l_ptr
->fsm_msg_cnt
< l_ptr
->abort_limit
) {
596 tipc_link_proto_xmit(l_ptr
, STATE_MSG
,
598 l_ptr
->fsm_msg_cnt
++;
599 link_set_timer(l_ptr
, cont_intv
/ 4);
600 } else { /* Link has failed */
601 pr_warn("%s<%s>, peer not responding\n",
602 link_rst_msg
, l_ptr
->name
);
603 tipc_link_reset(l_ptr
);
604 l_ptr
->state
= RESET_UNKNOWN
;
605 l_ptr
->fsm_msg_cnt
= 0;
606 tipc_link_proto_xmit(l_ptr
, RESET_MSG
,
608 l_ptr
->fsm_msg_cnt
++;
609 link_set_timer(l_ptr
, cont_intv
);
613 pr_err("%s%u in WU state\n", link_unk_evt
, event
);
618 case TRAFFIC_MSG_EVT
:
621 other
= l_ptr
->owner
->active_links
[0];
622 if (other
&& link_working_unknown(other
))
624 l_ptr
->state
= WORKING_WORKING
;
625 l_ptr
->fsm_msg_cnt
= 0;
626 link_activate(l_ptr
);
627 tipc_link_proto_xmit(l_ptr
, STATE_MSG
, 1, 0, 0, 0, 0);
628 l_ptr
->fsm_msg_cnt
++;
629 if (l_ptr
->owner
->working_links
== 1)
630 tipc_link_sync_xmit(l_ptr
);
631 link_set_timer(l_ptr
, cont_intv
);
634 l_ptr
->state
= RESET_RESET
;
635 l_ptr
->fsm_msg_cnt
= 0;
636 tipc_link_proto_xmit(l_ptr
, ACTIVATE_MSG
,
638 l_ptr
->fsm_msg_cnt
++;
639 link_set_timer(l_ptr
, cont_intv
);
642 l_ptr
->flags
|= LINK_STARTED
;
645 tipc_link_proto_xmit(l_ptr
, RESET_MSG
, 0, 0, 0, 0, 0);
646 l_ptr
->fsm_msg_cnt
++;
647 link_set_timer(l_ptr
, cont_intv
);
650 pr_err("%s%u in RU state\n", link_unk_evt
, event
);
655 case TRAFFIC_MSG_EVT
:
657 other
= l_ptr
->owner
->active_links
[0];
658 if (other
&& link_working_unknown(other
))
660 l_ptr
->state
= WORKING_WORKING
;
661 l_ptr
->fsm_msg_cnt
= 0;
662 link_activate(l_ptr
);
663 tipc_link_proto_xmit(l_ptr
, STATE_MSG
, 1, 0, 0, 0, 0);
664 l_ptr
->fsm_msg_cnt
++;
665 if (l_ptr
->owner
->working_links
== 1)
666 tipc_link_sync_xmit(l_ptr
);
667 link_set_timer(l_ptr
, cont_intv
);
672 tipc_link_proto_xmit(l_ptr
, ACTIVATE_MSG
,
674 l_ptr
->fsm_msg_cnt
++;
675 link_set_timer(l_ptr
, cont_intv
);
678 pr_err("%s%u in RR state\n", link_unk_evt
, event
);
682 pr_err("Unknown link state %u/%u\n", l_ptr
->state
, event
);
686 /* tipc_link_cong: determine return value and how to treat the
687 * sent buffer during link congestion.
688 * - For plain, errorless user data messages we keep the buffer and
690 * - For all other messages we discard the buffer and return -EHOSTUNREACH
691 * - For TIPC internal messages we also reset the link
693 static int tipc_link_cong(struct tipc_link
*link
, struct sk_buff
*buf
)
695 struct tipc_msg
*msg
= buf_msg(buf
);
696 uint imp
= tipc_msg_tot_importance(msg
);
697 u32 oport
= msg_tot_origport(msg
);
699 if (unlikely(imp
> TIPC_CRITICAL_IMPORTANCE
)) {
700 pr_warn("%s<%s>, send queue full", link_rst_msg
, link
->name
);
701 tipc_link_reset(link
);
704 if (unlikely(msg_errcode(msg
)))
706 if (unlikely(msg_reroute_cnt(msg
)))
708 if (TIPC_SKB_CB(buf
)->wakeup_pending
)
710 if (link_schedule_user(link
, oport
, TIPC_SKB_CB(buf
)->chain_sz
, imp
))
714 return -EHOSTUNREACH
;
718 * __tipc_link_xmit(): same as tipc_link_xmit, but destlink is known & locked
720 * @buf: chain of buffers containing message
721 * Consumes the buffer chain, except when returning -ELINKCONG
722 * Returns 0 if success, otherwise errno: -ELINKCONG, -EMSGSIZE (plain socket
723 * user data messages) or -EHOSTUNREACH (all other messages/senders)
724 * Only the socket functions tipc_send_stream() and tipc_send_packet() need
725 * to act on the return value, since they may need to do more send attempts.
727 int __tipc_link_xmit(struct tipc_link
*link
, struct sk_buff
*buf
)
729 struct tipc_msg
*msg
= buf_msg(buf
);
730 uint psz
= msg_size(msg
);
731 uint qsz
= link
->out_queue_size
;
732 uint sndlim
= link
->queue_limit
[0];
733 uint imp
= tipc_msg_tot_importance(msg
);
734 uint mtu
= link
->max_pkt
;
735 uint ack
= mod(link
->next_in_no
- 1);
736 uint seqno
= link
->next_out_no
;
737 uint bc_last_in
= link
->owner
->bclink
.last_in
;
738 struct tipc_media_addr
*addr
= &link
->media_addr
;
739 struct sk_buff
*next
= buf
->next
;
741 /* Match queue limits against msg importance: */
742 if (unlikely(qsz
>= link
->queue_limit
[imp
]))
743 return tipc_link_cong(link
, buf
);
745 /* Has valid packet limit been used ? */
746 if (unlikely(psz
> mtu
)) {
751 /* Prepare each packet for sending, and add to outqueue: */
755 msg_set_word(msg
, 2, ((ack
<< 16) | mod(seqno
)));
756 msg_set_bcast_ack(msg
, bc_last_in
);
758 if (!link
->first_out
) {
759 link
->first_out
= buf
;
760 } else if (qsz
< sndlim
) {
761 link
->last_out
->next
= buf
;
762 } else if (tipc_msg_bundle(link
->last_out
, buf
, mtu
)) {
763 link
->stats
.sent_bundled
++;
767 } else if (tipc_msg_make_bundle(&buf
, mtu
, link
->addr
)) {
768 link
->stats
.sent_bundled
++;
769 link
->stats
.sent_bundles
++;
770 link
->last_out
->next
= buf
;
772 link
->next_out
= buf
;
774 link
->last_out
->next
= buf
;
776 link
->next_out
= buf
;
779 /* Send packet if possible: */
780 if (likely(++qsz
<= sndlim
)) {
781 tipc_bearer_send(link
->bearer_id
, buf
, addr
);
782 link
->next_out
= next
;
783 link
->unacked_window
= 0;
786 link
->last_out
= buf
;
789 link
->next_out_no
= seqno
;
790 link
->out_queue_size
= qsz
;
795 * tipc_link_xmit() is the general link level function for message sending
796 * @buf: chain of buffers containing message
797 * @dsz: amount of user data to be sent
798 * @dnode: address of destination node
799 * @selector: a number used for deterministic link selection
800 * Consumes the buffer chain, except when returning -ELINKCONG
801 * Returns 0 if success, otherwise errno: -ELINKCONG,-EHOSTUNREACH,-EMSGSIZE
803 int tipc_link_xmit(struct sk_buff
*buf
, u32 dnode
, u32 selector
)
805 struct tipc_link
*link
= NULL
;
806 struct tipc_node
*node
;
807 int rc
= -EHOSTUNREACH
;
809 node
= tipc_node_find(dnode
);
811 tipc_node_lock(node
);
812 link
= node
->active_links
[selector
& 1];
814 rc
= __tipc_link_xmit(link
, buf
);
815 tipc_node_unlock(node
);
821 if (likely(in_own_node(dnode
)))
822 return tipc_sk_rcv(buf
);
829 * tipc_link_sync_xmit - synchronize broadcast link endpoints.
831 * Give a newly added peer node the sequence number where it should
832 * start receiving and acking broadcast packets.
834 * Called with node locked
836 static void tipc_link_sync_xmit(struct tipc_link
*link
)
839 struct tipc_msg
*msg
;
841 buf
= tipc_buf_acquire(INT_H_SIZE
);
846 tipc_msg_init(msg
, BCAST_PROTOCOL
, STATE_MSG
, INT_H_SIZE
, link
->addr
);
847 msg_set_last_bcast(msg
, link
->owner
->bclink
.acked
);
848 __tipc_link_xmit(link
, buf
);
852 * tipc_link_sync_rcv - synchronize broadcast link endpoints.
853 * Receive the sequence number where we should start receiving and
854 * acking broadcast packets from a newly added peer node, and open
855 * up for reception of such packets.
857 * Called with node locked
859 static void tipc_link_sync_rcv(struct tipc_node
*n
, struct sk_buff
*buf
)
861 struct tipc_msg
*msg
= buf_msg(buf
);
863 n
->bclink
.last_sent
= n
->bclink
.last_in
= msg_last_bcast(msg
);
864 n
->bclink
.recv_permitted
= true;
869 * tipc_link_push_packet: Push one unsent packet to the media
871 static u32
tipc_link_push_packet(struct tipc_link
*l_ptr
)
873 struct sk_buff
*buf
= l_ptr
->first_out
;
874 u32 r_q_size
= l_ptr
->retransm_queue_size
;
875 u32 r_q_head
= l_ptr
->retransm_queue_head
;
877 /* Step to position where retransmission failed, if any, */
878 /* consider that buffers may have been released in meantime */
879 if (r_q_size
&& buf
) {
880 u32 last
= lesser(mod(r_q_head
+ r_q_size
),
881 link_last_sent(l_ptr
));
882 u32 first
= buf_seqno(buf
);
884 while (buf
&& less(first
, r_q_head
)) {
885 first
= mod(first
+ 1);
888 l_ptr
->retransm_queue_head
= r_q_head
= first
;
889 l_ptr
->retransm_queue_size
= r_q_size
= mod(last
- first
);
892 /* Continue retransmission now, if there is anything: */
893 if (r_q_size
&& buf
) {
894 msg_set_ack(buf_msg(buf
), mod(l_ptr
->next_in_no
- 1));
895 msg_set_bcast_ack(buf_msg(buf
), l_ptr
->owner
->bclink
.last_in
);
896 tipc_bearer_send(l_ptr
->bearer_id
, buf
, &l_ptr
->media_addr
);
897 l_ptr
->retransm_queue_head
= mod(++r_q_head
);
898 l_ptr
->retransm_queue_size
= --r_q_size
;
899 l_ptr
->stats
.retransmitted
++;
903 /* Send one deferred data message, if send window not full: */
904 buf
= l_ptr
->next_out
;
906 struct tipc_msg
*msg
= buf_msg(buf
);
907 u32 next
= msg_seqno(msg
);
908 u32 first
= buf_seqno(l_ptr
->first_out
);
910 if (mod(next
- first
) < l_ptr
->queue_limit
[0]) {
911 msg_set_ack(msg
, mod(l_ptr
->next_in_no
- 1));
912 msg_set_bcast_ack(msg
, l_ptr
->owner
->bclink
.last_in
);
913 tipc_bearer_send(l_ptr
->bearer_id
, buf
,
915 if (msg_user(msg
) == MSG_BUNDLER
)
916 msg_set_type(msg
, BUNDLE_CLOSED
);
917 l_ptr
->next_out
= buf
->next
;
925 * push_queue(): push out the unsent messages of a link where
926 * congestion has abated. Node is locked
928 void tipc_link_push_queue(struct tipc_link
*l_ptr
)
933 res
= tipc_link_push_packet(l_ptr
);
937 void tipc_link_reset_all(struct tipc_node
*node
)
939 char addr_string
[16];
942 tipc_node_lock(node
);
944 pr_warn("Resetting all links to %s\n",
945 tipc_addr_string_fill(addr_string
, node
->addr
));
947 for (i
= 0; i
< MAX_BEARERS
; i
++) {
948 if (node
->links
[i
]) {
949 link_print(node
->links
[i
], "Resetting link\n");
950 tipc_link_reset(node
->links
[i
]);
954 tipc_node_unlock(node
);
957 static void link_retransmit_failure(struct tipc_link
*l_ptr
,
960 struct tipc_msg
*msg
= buf_msg(buf
);
962 pr_warn("Retransmission failure on link <%s>\n", l_ptr
->name
);
965 /* Handle failure on standard link */
966 link_print(l_ptr
, "Resetting link\n");
967 tipc_link_reset(l_ptr
);
970 /* Handle failure on broadcast link */
971 struct tipc_node
*n_ptr
;
972 char addr_string
[16];
974 pr_info("Msg seq number: %u, ", msg_seqno(msg
));
975 pr_cont("Outstanding acks: %lu\n",
976 (unsigned long) TIPC_SKB_CB(buf
)->handle
);
978 n_ptr
= tipc_bclink_retransmit_to();
979 tipc_node_lock(n_ptr
);
981 tipc_addr_string_fill(addr_string
, n_ptr
->addr
);
982 pr_info("Broadcast link info for %s\n", addr_string
);
983 pr_info("Reception permitted: %d, Acked: %u\n",
984 n_ptr
->bclink
.recv_permitted
,
985 n_ptr
->bclink
.acked
);
986 pr_info("Last in: %u, Oos state: %u, Last sent: %u\n",
987 n_ptr
->bclink
.last_in
,
988 n_ptr
->bclink
.oos_state
,
989 n_ptr
->bclink
.last_sent
);
991 tipc_node_unlock(n_ptr
);
993 tipc_bclink_set_flags(TIPC_BCLINK_RESET
);
994 l_ptr
->stale_count
= 0;
998 void tipc_link_retransmit(struct tipc_link
*l_ptr
, struct sk_buff
*buf
,
1001 struct tipc_msg
*msg
;
1008 /* Detect repeated retransmit failures */
1009 if (l_ptr
->last_retransmitted
== msg_seqno(msg
)) {
1010 if (++l_ptr
->stale_count
> 100) {
1011 link_retransmit_failure(l_ptr
, buf
);
1015 l_ptr
->last_retransmitted
= msg_seqno(msg
);
1016 l_ptr
->stale_count
= 1;
1019 while (retransmits
&& (buf
!= l_ptr
->next_out
) && buf
) {
1021 msg_set_ack(msg
, mod(l_ptr
->next_in_no
- 1));
1022 msg_set_bcast_ack(msg
, l_ptr
->owner
->bclink
.last_in
);
1023 tipc_bearer_send(l_ptr
->bearer_id
, buf
, &l_ptr
->media_addr
);
1026 l_ptr
->stats
.retransmitted
++;
1029 l_ptr
->retransm_queue_head
= l_ptr
->retransm_queue_size
= 0;
1033 * link_insert_deferred_queue - insert deferred messages back into receive chain
1035 static struct sk_buff
*link_insert_deferred_queue(struct tipc_link
*l_ptr
,
1036 struct sk_buff
*buf
)
1040 if (l_ptr
->oldest_deferred_in
== NULL
)
1043 seq_no
= buf_seqno(l_ptr
->oldest_deferred_in
);
1044 if (seq_no
== mod(l_ptr
->next_in_no
)) {
1045 l_ptr
->newest_deferred_in
->next
= buf
;
1046 buf
= l_ptr
->oldest_deferred_in
;
1047 l_ptr
->oldest_deferred_in
= NULL
;
1048 l_ptr
->deferred_inqueue_sz
= 0;
1054 * link_recv_buf_validate - validate basic format of received message
1056 * This routine ensures a TIPC message has an acceptable header, and at least
1057 * as much data as the header indicates it should. The routine also ensures
1058 * that the entire message header is stored in the main fragment of the message
1059 * buffer, to simplify future access to message header fields.
1061 * Note: Having extra info present in the message header or data areas is OK.
1062 * TIPC will ignore the excess, under the assumption that it is optional info
1063 * introduced by a later release of the protocol.
1065 static int link_recv_buf_validate(struct sk_buff
*buf
)
1067 static u32 min_data_hdr_size
[8] = {
1068 SHORT_H_SIZE
, MCAST_H_SIZE
, NAMED_H_SIZE
, BASIC_H_SIZE
,
1069 MAX_H_SIZE
, MAX_H_SIZE
, MAX_H_SIZE
, MAX_H_SIZE
1072 struct tipc_msg
*msg
;
1078 /* If this packet comes from the defer queue, the skb has already
1081 if (unlikely(TIPC_SKB_CB(buf
)->deferred
))
1084 if (unlikely(buf
->len
< MIN_H_SIZE
))
1087 msg
= skb_header_pointer(buf
, 0, sizeof(tipc_hdr
), tipc_hdr
);
1091 if (unlikely(msg_version(msg
) != TIPC_VERSION
))
1094 size
= msg_size(msg
);
1095 hdr_size
= msg_hdr_sz(msg
);
1096 min_hdr_size
= msg_isdata(msg
) ?
1097 min_data_hdr_size
[msg_type(msg
)] : INT_H_SIZE
;
1099 if (unlikely((hdr_size
< min_hdr_size
) ||
1100 (size
< hdr_size
) ||
1101 (buf
->len
< size
) ||
1102 (size
- hdr_size
> TIPC_MAX_USER_MSG_SIZE
)))
1105 return pskb_may_pull(buf
, hdr_size
);
1109 * tipc_rcv - process TIPC packets/messages arriving from off-node
1110 * @head: pointer to message buffer chain
1111 * @b_ptr: pointer to bearer message arrived on
1113 * Invoked with no locks held. Bearer pointer must point to a valid bearer
1114 * structure (i.e. cannot be NULL), but bearer can be inactive.
1116 void tipc_rcv(struct sk_buff
*head
, struct tipc_bearer
*b_ptr
)
1119 struct tipc_node
*n_ptr
;
1120 struct tipc_link
*l_ptr
;
1121 struct sk_buff
*crs
;
1122 struct sk_buff
*buf
= head
;
1123 struct tipc_msg
*msg
;
1131 /* Ensure message is well-formed */
1132 if (unlikely(!link_recv_buf_validate(buf
)))
1135 /* Ensure message data is a single contiguous unit */
1136 if (unlikely(skb_linearize(buf
)))
1139 /* Handle arrival of a non-unicast link message */
1142 if (unlikely(msg_non_seq(msg
))) {
1143 if (msg_user(msg
) == LINK_CONFIG
)
1144 tipc_disc_rcv(buf
, b_ptr
);
1146 tipc_bclink_rcv(buf
);
1150 /* Discard unicast link messages destined for another node */
1151 if (unlikely(!msg_short(msg
) &&
1152 (msg_destnode(msg
) != tipc_own_addr
)))
1155 /* Locate neighboring node that sent message */
1156 n_ptr
= tipc_node_find(msg_prevnode(msg
));
1157 if (unlikely(!n_ptr
))
1159 tipc_node_lock(n_ptr
);
1161 /* Locate unicast link endpoint that should handle message */
1162 l_ptr
= n_ptr
->links
[b_ptr
->identity
];
1163 if (unlikely(!l_ptr
))
1164 goto unlock_discard
;
1166 /* Verify that communication with node is currently allowed */
1167 if ((n_ptr
->action_flags
& TIPC_WAIT_PEER_LINKS_DOWN
) &&
1168 msg_user(msg
) == LINK_PROTOCOL
&&
1169 (msg_type(msg
) == RESET_MSG
||
1170 msg_type(msg
) == ACTIVATE_MSG
) &&
1171 !msg_redundant_link(msg
))
1172 n_ptr
->action_flags
&= ~TIPC_WAIT_PEER_LINKS_DOWN
;
1174 if (tipc_node_blocked(n_ptr
))
1175 goto unlock_discard
;
1177 /* Validate message sequence number info */
1178 seq_no
= msg_seqno(msg
);
1179 ackd
= msg_ack(msg
);
1181 /* Release acked messages */
1182 if (n_ptr
->bclink
.recv_permitted
)
1183 tipc_bclink_acknowledge(n_ptr
, msg_bcast_ack(msg
));
1185 crs
= l_ptr
->first_out
;
1186 while ((crs
!= l_ptr
->next_out
) &&
1187 less_eq(buf_seqno(crs
), ackd
)) {
1188 struct sk_buff
*next
= crs
->next
;
1194 l_ptr
->first_out
= crs
;
1195 l_ptr
->out_queue_size
-= released
;
1198 /* Try sending any messages link endpoint has pending */
1199 if (unlikely(l_ptr
->next_out
))
1200 tipc_link_push_queue(l_ptr
);
1202 if (released
&& !skb_queue_empty(&l_ptr
->waiting_sks
)) {
1203 link_prepare_wakeup(l_ptr
);
1204 l_ptr
->owner
->action_flags
|= TIPC_WAKEUP_USERS
;
1207 /* Process the incoming packet */
1208 if (unlikely(!link_working_working(l_ptr
))) {
1209 if (msg_user(msg
) == LINK_PROTOCOL
) {
1210 tipc_link_proto_rcv(l_ptr
, buf
);
1211 head
= link_insert_deferred_queue(l_ptr
, head
);
1212 tipc_node_unlock(n_ptr
);
1216 /* Traffic message. Conditionally activate link */
1217 link_state_event(l_ptr
, TRAFFIC_MSG_EVT
);
1219 if (link_working_working(l_ptr
)) {
1220 /* Re-insert buffer in front of queue */
1223 tipc_node_unlock(n_ptr
);
1226 goto unlock_discard
;
1229 /* Link is now in state WORKING_WORKING */
1230 if (unlikely(seq_no
!= mod(l_ptr
->next_in_no
))) {
1231 link_handle_out_of_seq_msg(l_ptr
, buf
);
1232 head
= link_insert_deferred_queue(l_ptr
, head
);
1233 tipc_node_unlock(n_ptr
);
1236 l_ptr
->next_in_no
++;
1237 if (unlikely(l_ptr
->oldest_deferred_in
))
1238 head
= link_insert_deferred_queue(l_ptr
, head
);
1240 if (unlikely(++l_ptr
->unacked_window
>= TIPC_MIN_LINK_WIN
)) {
1241 l_ptr
->stats
.sent_acks
++;
1242 tipc_link_proto_xmit(l_ptr
, STATE_MSG
, 0, 0, 0, 0, 0);
1245 if (tipc_link_prepare_input(l_ptr
, &buf
)) {
1246 tipc_node_unlock(n_ptr
);
1249 tipc_node_unlock(n_ptr
);
1251 if (tipc_link_input(l_ptr
, buf
) != 0)
1255 tipc_node_unlock(n_ptr
);
1262 * tipc_link_prepare_input - process TIPC link messages
1264 * returns nonzero if the message was consumed
1266 * Node lock must be held
1268 static int tipc_link_prepare_input(struct tipc_link
*l
, struct sk_buff
**buf
)
1270 struct tipc_node
*n
;
1271 struct tipc_msg
*msg
;
1275 msg
= buf_msg(*buf
);
1276 switch (msg_user(msg
)) {
1277 case CHANGEOVER_PROTOCOL
:
1278 if (tipc_link_tunnel_rcv(n
, buf
))
1281 case MSG_FRAGMENTER
:
1282 l
->stats
.recv_fragments
++;
1283 if (tipc_buf_append(&l
->reasm_buf
, buf
)) {
1284 l
->stats
.recv_fragmented
++;
1286 } else if (!l
->reasm_buf
) {
1291 l
->stats
.recv_bundles
++;
1292 l
->stats
.recv_bundled
+= msg_msgcnt(msg
);
1295 case NAME_DISTRIBUTOR
:
1296 n
->bclink
.recv_permitted
= true;
1299 case BCAST_PROTOCOL
:
1300 tipc_link_sync_rcv(n
, *buf
);
1308 * tipc_link_input - Deliver message too higher layers
1310 static int tipc_link_input(struct tipc_link
*l
, struct sk_buff
*buf
)
1312 struct tipc_msg
*msg
= buf_msg(buf
);
1315 switch (msg_user(msg
)) {
1316 case TIPC_LOW_IMPORTANCE
:
1317 case TIPC_MEDIUM_IMPORTANCE
:
1318 case TIPC_HIGH_IMPORTANCE
:
1319 case TIPC_CRITICAL_IMPORTANCE
:
1323 case NAME_DISTRIBUTOR
:
1324 tipc_named_rcv(buf
);
1327 tipc_link_bundle_rcv(buf
);
1336 * tipc_link_defer_pkt - Add out-of-sequence message to deferred reception queue
1338 * Returns increase in queue length (i.e. 0 or 1)
1340 u32
tipc_link_defer_pkt(struct sk_buff
**head
, struct sk_buff
**tail
,
1341 struct sk_buff
*buf
)
1343 struct sk_buff
*queue_buf
;
1344 struct sk_buff
**prev
;
1345 u32 seq_no
= buf_seqno(buf
);
1350 if (*head
== NULL
) {
1351 *head
= *tail
= buf
;
1356 if (less(buf_seqno(*tail
), seq_no
)) {
1357 (*tail
)->next
= buf
;
1362 /* Locate insertion point in queue, then insert; discard if duplicate */
1366 u32 curr_seqno
= buf_seqno(queue_buf
);
1368 if (seq_no
== curr_seqno
) {
1373 if (less(seq_no
, curr_seqno
))
1376 prev
= &queue_buf
->next
;
1377 queue_buf
= queue_buf
->next
;
1380 buf
->next
= queue_buf
;
1386 * link_handle_out_of_seq_msg - handle arrival of out-of-sequence packet
1388 static void link_handle_out_of_seq_msg(struct tipc_link
*l_ptr
,
1389 struct sk_buff
*buf
)
1391 u32 seq_no
= buf_seqno(buf
);
1393 if (likely(msg_user(buf_msg(buf
)) == LINK_PROTOCOL
)) {
1394 tipc_link_proto_rcv(l_ptr
, buf
);
1398 /* Record OOS packet arrival (force mismatch on next timeout) */
1399 l_ptr
->checkpoint
--;
1402 * Discard packet if a duplicate; otherwise add it to deferred queue
1403 * and notify peer of gap as per protocol specification
1405 if (less(seq_no
, mod(l_ptr
->next_in_no
))) {
1406 l_ptr
->stats
.duplicates
++;
1411 if (tipc_link_defer_pkt(&l_ptr
->oldest_deferred_in
,
1412 &l_ptr
->newest_deferred_in
, buf
)) {
1413 l_ptr
->deferred_inqueue_sz
++;
1414 l_ptr
->stats
.deferred_recv
++;
1415 TIPC_SKB_CB(buf
)->deferred
= true;
1416 if ((l_ptr
->deferred_inqueue_sz
% 16) == 1)
1417 tipc_link_proto_xmit(l_ptr
, STATE_MSG
, 0, 0, 0, 0, 0);
1419 l_ptr
->stats
.duplicates
++;
1423 * Send protocol message to the other endpoint.
1425 void tipc_link_proto_xmit(struct tipc_link
*l_ptr
, u32 msg_typ
, int probe_msg
,
1426 u32 gap
, u32 tolerance
, u32 priority
, u32 ack_mtu
)
1428 struct sk_buff
*buf
= NULL
;
1429 struct tipc_msg
*msg
= l_ptr
->pmsg
;
1430 u32 msg_size
= sizeof(l_ptr
->proto_msg
);
1433 /* Don't send protocol message during link changeover */
1434 if (l_ptr
->exp_msg_count
)
1437 /* Abort non-RESET send if communication with node is prohibited */
1438 if ((tipc_node_blocked(l_ptr
->owner
)) && (msg_typ
!= RESET_MSG
))
1441 /* Create protocol message with "out-of-sequence" sequence number */
1442 msg_set_type(msg
, msg_typ
);
1443 msg_set_net_plane(msg
, l_ptr
->net_plane
);
1444 msg_set_bcast_ack(msg
, l_ptr
->owner
->bclink
.last_in
);
1445 msg_set_last_bcast(msg
, tipc_bclink_get_last_sent());
1447 if (msg_typ
== STATE_MSG
) {
1448 u32 next_sent
= mod(l_ptr
->next_out_no
);
1450 if (!tipc_link_is_up(l_ptr
))
1452 if (l_ptr
->next_out
)
1453 next_sent
= buf_seqno(l_ptr
->next_out
);
1454 msg_set_next_sent(msg
, next_sent
);
1455 if (l_ptr
->oldest_deferred_in
) {
1456 u32 rec
= buf_seqno(l_ptr
->oldest_deferred_in
);
1457 gap
= mod(rec
- mod(l_ptr
->next_in_no
));
1459 msg_set_seq_gap(msg
, gap
);
1461 l_ptr
->stats
.sent_nacks
++;
1462 msg_set_link_tolerance(msg
, tolerance
);
1463 msg_set_linkprio(msg
, priority
);
1464 msg_set_max_pkt(msg
, ack_mtu
);
1465 msg_set_ack(msg
, mod(l_ptr
->next_in_no
- 1));
1466 msg_set_probe(msg
, probe_msg
!= 0);
1468 u32 mtu
= l_ptr
->max_pkt
;
1470 if ((mtu
< l_ptr
->max_pkt_target
) &&
1471 link_working_working(l_ptr
) &&
1472 l_ptr
->fsm_msg_cnt
) {
1473 msg_size
= (mtu
+ (l_ptr
->max_pkt_target
- mtu
)/2 + 2) & ~3;
1474 if (l_ptr
->max_pkt_probes
== 10) {
1475 l_ptr
->max_pkt_target
= (msg_size
- 4);
1476 l_ptr
->max_pkt_probes
= 0;
1477 msg_size
= (mtu
+ (l_ptr
->max_pkt_target
- mtu
)/2 + 2) & ~3;
1479 l_ptr
->max_pkt_probes
++;
1482 l_ptr
->stats
.sent_probes
++;
1484 l_ptr
->stats
.sent_states
++;
1485 } else { /* RESET_MSG or ACTIVATE_MSG */
1486 msg_set_ack(msg
, mod(l_ptr
->reset_checkpoint
- 1));
1487 msg_set_seq_gap(msg
, 0);
1488 msg_set_next_sent(msg
, 1);
1489 msg_set_probe(msg
, 0);
1490 msg_set_link_tolerance(msg
, l_ptr
->tolerance
);
1491 msg_set_linkprio(msg
, l_ptr
->priority
);
1492 msg_set_max_pkt(msg
, l_ptr
->max_pkt_target
);
1495 r_flag
= (l_ptr
->owner
->working_links
> tipc_link_is_up(l_ptr
));
1496 msg_set_redundant_link(msg
, r_flag
);
1497 msg_set_linkprio(msg
, l_ptr
->priority
);
1498 msg_set_size(msg
, msg_size
);
1500 msg_set_seqno(msg
, mod(l_ptr
->next_out_no
+ (0xffff/2)));
1502 buf
= tipc_buf_acquire(msg_size
);
1506 skb_copy_to_linear_data(buf
, msg
, sizeof(l_ptr
->proto_msg
));
1507 buf
->priority
= TC_PRIO_CONTROL
;
1509 tipc_bearer_send(l_ptr
->bearer_id
, buf
, &l_ptr
->media_addr
);
1510 l_ptr
->unacked_window
= 0;
1515 * Receive protocol message :
1516 * Note that network plane id propagates through the network, and may
1517 * change at any time. The node with lowest address rules
1519 static void tipc_link_proto_rcv(struct tipc_link
*l_ptr
, struct sk_buff
*buf
)
1525 struct tipc_msg
*msg
= buf_msg(buf
);
1527 /* Discard protocol message during link changeover */
1528 if (l_ptr
->exp_msg_count
)
1531 if (l_ptr
->net_plane
!= msg_net_plane(msg
))
1532 if (tipc_own_addr
> msg_prevnode(msg
))
1533 l_ptr
->net_plane
= msg_net_plane(msg
);
1535 switch (msg_type(msg
)) {
1538 if (!link_working_unknown(l_ptr
) &&
1539 (l_ptr
->peer_session
!= INVALID_SESSION
)) {
1540 if (less_eq(msg_session(msg
), l_ptr
->peer_session
))
1541 break; /* duplicate or old reset: ignore */
1544 if (!msg_redundant_link(msg
) && (link_working_working(l_ptr
) ||
1545 link_working_unknown(l_ptr
))) {
1547 * peer has lost contact -- don't allow peer's links
1548 * to reactivate before we recognize loss & clean up
1550 l_ptr
->owner
->action_flags
|= TIPC_WAIT_OWN_LINKS_DOWN
;
1553 link_state_event(l_ptr
, RESET_MSG
);
1557 /* Update link settings according other endpoint's values */
1558 strcpy((strrchr(l_ptr
->name
, ':') + 1), (char *)msg_data(msg
));
1560 msg_tol
= msg_link_tolerance(msg
);
1561 if (msg_tol
> l_ptr
->tolerance
)
1562 link_set_supervision_props(l_ptr
, msg_tol
);
1564 if (msg_linkprio(msg
) > l_ptr
->priority
)
1565 l_ptr
->priority
= msg_linkprio(msg
);
1567 max_pkt_info
= msg_max_pkt(msg
);
1569 if (max_pkt_info
< l_ptr
->max_pkt_target
)
1570 l_ptr
->max_pkt_target
= max_pkt_info
;
1571 if (l_ptr
->max_pkt
> l_ptr
->max_pkt_target
)
1572 l_ptr
->max_pkt
= l_ptr
->max_pkt_target
;
1574 l_ptr
->max_pkt
= l_ptr
->max_pkt_target
;
1577 /* Synchronize broadcast link info, if not done previously */
1578 if (!tipc_node_is_up(l_ptr
->owner
)) {
1579 l_ptr
->owner
->bclink
.last_sent
=
1580 l_ptr
->owner
->bclink
.last_in
=
1581 msg_last_bcast(msg
);
1582 l_ptr
->owner
->bclink
.oos_state
= 0;
1585 l_ptr
->peer_session
= msg_session(msg
);
1586 l_ptr
->peer_bearer_id
= msg_bearer_id(msg
);
1588 if (msg_type(msg
) == ACTIVATE_MSG
)
1589 link_state_event(l_ptr
, ACTIVATE_MSG
);
1593 msg_tol
= msg_link_tolerance(msg
);
1595 link_set_supervision_props(l_ptr
, msg_tol
);
1597 if (msg_linkprio(msg
) &&
1598 (msg_linkprio(msg
) != l_ptr
->priority
)) {
1599 pr_warn("%s<%s>, priority change %u->%u\n",
1600 link_rst_msg
, l_ptr
->name
, l_ptr
->priority
,
1602 l_ptr
->priority
= msg_linkprio(msg
);
1603 tipc_link_reset(l_ptr
); /* Enforce change to take effect */
1607 /* Record reception; force mismatch at next timeout: */
1608 l_ptr
->checkpoint
--;
1610 link_state_event(l_ptr
, TRAFFIC_MSG_EVT
);
1611 l_ptr
->stats
.recv_states
++;
1612 if (link_reset_unknown(l_ptr
))
1615 if (less_eq(mod(l_ptr
->next_in_no
), msg_next_sent(msg
))) {
1616 rec_gap
= mod(msg_next_sent(msg
) -
1617 mod(l_ptr
->next_in_no
));
1620 max_pkt_ack
= msg_max_pkt(msg
);
1621 if (max_pkt_ack
> l_ptr
->max_pkt
) {
1622 l_ptr
->max_pkt
= max_pkt_ack
;
1623 l_ptr
->max_pkt_probes
= 0;
1627 if (msg_probe(msg
)) {
1628 l_ptr
->stats
.recv_probes
++;
1629 if (msg_size(msg
) > sizeof(l_ptr
->proto_msg
))
1630 max_pkt_ack
= msg_size(msg
);
1633 /* Protocol message before retransmits, reduce loss risk */
1634 if (l_ptr
->owner
->bclink
.recv_permitted
)
1635 tipc_bclink_update_link_state(l_ptr
->owner
,
1636 msg_last_bcast(msg
));
1638 if (rec_gap
|| (msg_probe(msg
))) {
1639 tipc_link_proto_xmit(l_ptr
, STATE_MSG
, 0, rec_gap
, 0,
1642 if (msg_seq_gap(msg
)) {
1643 l_ptr
->stats
.recv_nacks
++;
1644 tipc_link_retransmit(l_ptr
, l_ptr
->first_out
,
1654 /* tipc_link_tunnel_xmit(): Tunnel one packet via a link belonging to
1655 * a different bearer. Owner node is locked.
1657 static void tipc_link_tunnel_xmit(struct tipc_link
*l_ptr
,
1658 struct tipc_msg
*tunnel_hdr
,
1659 struct tipc_msg
*msg
,
1662 struct tipc_link
*tunnel
;
1663 struct sk_buff
*buf
;
1664 u32 length
= msg_size(msg
);
1666 tunnel
= l_ptr
->owner
->active_links
[selector
& 1];
1667 if (!tipc_link_is_up(tunnel
)) {
1668 pr_warn("%stunnel link no longer available\n", link_co_err
);
1671 msg_set_size(tunnel_hdr
, length
+ INT_H_SIZE
);
1672 buf
= tipc_buf_acquire(length
+ INT_H_SIZE
);
1674 pr_warn("%sunable to send tunnel msg\n", link_co_err
);
1677 skb_copy_to_linear_data(buf
, tunnel_hdr
, INT_H_SIZE
);
1678 skb_copy_to_linear_data_offset(buf
, INT_H_SIZE
, msg
, length
);
1679 __tipc_link_xmit(tunnel
, buf
);
1683 /* tipc_link_failover_send_queue(): A link has gone down, but a second
1684 * link is still active. We can do failover. Tunnel the failing link's
1685 * whole send queue via the remaining link. This way, we don't lose
1686 * any packets, and sequence order is preserved for subsequent traffic
1687 * sent over the remaining link. Owner node is locked.
1689 void tipc_link_failover_send_queue(struct tipc_link
*l_ptr
)
1691 u32 msgcount
= l_ptr
->out_queue_size
;
1692 struct sk_buff
*crs
= l_ptr
->first_out
;
1693 struct tipc_link
*tunnel
= l_ptr
->owner
->active_links
[0];
1694 struct tipc_msg tunnel_hdr
;
1700 tipc_msg_init(&tunnel_hdr
, CHANGEOVER_PROTOCOL
,
1701 ORIGINAL_MSG
, INT_H_SIZE
, l_ptr
->addr
);
1702 msg_set_bearer_id(&tunnel_hdr
, l_ptr
->peer_bearer_id
);
1703 msg_set_msgcnt(&tunnel_hdr
, msgcount
);
1705 if (!l_ptr
->first_out
) {
1706 struct sk_buff
*buf
;
1708 buf
= tipc_buf_acquire(INT_H_SIZE
);
1710 skb_copy_to_linear_data(buf
, &tunnel_hdr
, INT_H_SIZE
);
1711 msg_set_size(&tunnel_hdr
, INT_H_SIZE
);
1712 __tipc_link_xmit(tunnel
, buf
);
1714 pr_warn("%sunable to send changeover msg\n",
1720 split_bundles
= (l_ptr
->owner
->active_links
[0] !=
1721 l_ptr
->owner
->active_links
[1]);
1724 struct tipc_msg
*msg
= buf_msg(crs
);
1726 if ((msg_user(msg
) == MSG_BUNDLER
) && split_bundles
) {
1727 struct tipc_msg
*m
= msg_get_wrapped(msg
);
1728 unchar
*pos
= (unchar
*)m
;
1730 msgcount
= msg_msgcnt(msg
);
1731 while (msgcount
--) {
1732 msg_set_seqno(m
, msg_seqno(msg
));
1733 tipc_link_tunnel_xmit(l_ptr
, &tunnel_hdr
, m
,
1734 msg_link_selector(m
));
1735 pos
+= align(msg_size(m
));
1736 m
= (struct tipc_msg
*)pos
;
1739 tipc_link_tunnel_xmit(l_ptr
, &tunnel_hdr
, msg
,
1740 msg_link_selector(msg
));
1746 /* tipc_link_dup_queue_xmit(): A second link has become active. Tunnel a
1747 * duplicate of the first link's send queue via the new link. This way, we
1748 * are guaranteed that currently queued packets from a socket are delivered
1749 * before future traffic from the same socket, even if this is using the
1750 * new link. The last arriving copy of each duplicate packet is dropped at
1751 * the receiving end by the regular protocol check, so packet cardinality
1752 * and sequence order is preserved per sender/receiver socket pair.
1753 * Owner node is locked.
1755 void tipc_link_dup_queue_xmit(struct tipc_link
*l_ptr
,
1756 struct tipc_link
*tunnel
)
1758 struct sk_buff
*iter
;
1759 struct tipc_msg tunnel_hdr
;
1761 tipc_msg_init(&tunnel_hdr
, CHANGEOVER_PROTOCOL
,
1762 DUPLICATE_MSG
, INT_H_SIZE
, l_ptr
->addr
);
1763 msg_set_msgcnt(&tunnel_hdr
, l_ptr
->out_queue_size
);
1764 msg_set_bearer_id(&tunnel_hdr
, l_ptr
->peer_bearer_id
);
1765 iter
= l_ptr
->first_out
;
1767 struct sk_buff
*outbuf
;
1768 struct tipc_msg
*msg
= buf_msg(iter
);
1769 u32 length
= msg_size(msg
);
1771 if (msg_user(msg
) == MSG_BUNDLER
)
1772 msg_set_type(msg
, CLOSED_MSG
);
1773 msg_set_ack(msg
, mod(l_ptr
->next_in_no
- 1)); /* Update */
1774 msg_set_bcast_ack(msg
, l_ptr
->owner
->bclink
.last_in
);
1775 msg_set_size(&tunnel_hdr
, length
+ INT_H_SIZE
);
1776 outbuf
= tipc_buf_acquire(length
+ INT_H_SIZE
);
1777 if (outbuf
== NULL
) {
1778 pr_warn("%sunable to send duplicate msg\n",
1782 skb_copy_to_linear_data(outbuf
, &tunnel_hdr
, INT_H_SIZE
);
1783 skb_copy_to_linear_data_offset(outbuf
, INT_H_SIZE
, iter
->data
,
1785 __tipc_link_xmit(tunnel
, outbuf
);
1786 if (!tipc_link_is_up(l_ptr
))
1793 * buf_extract - extracts embedded TIPC message from another message
1794 * @skb: encapsulating message buffer
1795 * @from_pos: offset to extract from
1797 * Returns a new message buffer containing an embedded message. The
1798 * encapsulating message itself is left unchanged.
1800 static struct sk_buff
*buf_extract(struct sk_buff
*skb
, u32 from_pos
)
1802 struct tipc_msg
*msg
= (struct tipc_msg
*)(skb
->data
+ from_pos
);
1803 u32 size
= msg_size(msg
);
1806 eb
= tipc_buf_acquire(size
);
1808 skb_copy_to_linear_data(eb
, msg
, size
);
1814 /* tipc_link_dup_rcv(): Receive a tunnelled DUPLICATE_MSG packet.
1815 * Owner node is locked.
1817 static void tipc_link_dup_rcv(struct tipc_link
*l_ptr
,
1818 struct sk_buff
*t_buf
)
1820 struct sk_buff
*buf
;
1822 if (!tipc_link_is_up(l_ptr
))
1825 buf
= buf_extract(t_buf
, INT_H_SIZE
);
1827 pr_warn("%sfailed to extract inner dup pkt\n", link_co_err
);
1831 /* Add buffer to deferred queue, if applicable: */
1832 link_handle_out_of_seq_msg(l_ptr
, buf
);
1835 /* tipc_link_failover_rcv(): Receive a tunnelled ORIGINAL_MSG packet
1836 * Owner node is locked.
1838 static struct sk_buff
*tipc_link_failover_rcv(struct tipc_link
*l_ptr
,
1839 struct sk_buff
*t_buf
)
1841 struct tipc_msg
*t_msg
= buf_msg(t_buf
);
1842 struct sk_buff
*buf
= NULL
;
1843 struct tipc_msg
*msg
;
1845 if (tipc_link_is_up(l_ptr
))
1846 tipc_link_reset(l_ptr
);
1848 /* First failover packet? */
1849 if (l_ptr
->exp_msg_count
== START_CHANGEOVER
)
1850 l_ptr
->exp_msg_count
= msg_msgcnt(t_msg
);
1852 /* Should there be an inner packet? */
1853 if (l_ptr
->exp_msg_count
) {
1854 l_ptr
->exp_msg_count
--;
1855 buf
= buf_extract(t_buf
, INT_H_SIZE
);
1857 pr_warn("%sno inner failover pkt\n", link_co_err
);
1862 if (less(msg_seqno(msg
), l_ptr
->reset_checkpoint
)) {
1867 if (msg_user(msg
) == MSG_FRAGMENTER
) {
1868 l_ptr
->stats
.recv_fragments
++;
1869 tipc_buf_append(&l_ptr
->reasm_buf
, &buf
);
1873 if ((l_ptr
->exp_msg_count
== 0) && (l_ptr
->flags
& LINK_STOPPED
)) {
1874 tipc_node_detach_link(l_ptr
->owner
, l_ptr
);
1880 /* tipc_link_tunnel_rcv(): Receive a tunnelled packet, sent
1881 * via other link as result of a failover (ORIGINAL_MSG) or
1882 * a new active link (DUPLICATE_MSG). Failover packets are
1883 * returned to the active link for delivery upwards.
1884 * Owner node is locked.
1886 static int tipc_link_tunnel_rcv(struct tipc_node
*n_ptr
,
1887 struct sk_buff
**buf
)
1889 struct sk_buff
*t_buf
= *buf
;
1890 struct tipc_link
*l_ptr
;
1891 struct tipc_msg
*t_msg
= buf_msg(t_buf
);
1892 u32 bearer_id
= msg_bearer_id(t_msg
);
1896 if (bearer_id
>= MAX_BEARERS
)
1899 l_ptr
= n_ptr
->links
[bearer_id
];
1903 if (msg_type(t_msg
) == DUPLICATE_MSG
)
1904 tipc_link_dup_rcv(l_ptr
, t_buf
);
1905 else if (msg_type(t_msg
) == ORIGINAL_MSG
)
1906 *buf
= tipc_link_failover_rcv(l_ptr
, t_buf
);
1908 pr_warn("%sunknown tunnel pkt received\n", link_co_err
);
1911 return *buf
!= NULL
;
1915 * Bundler functionality:
1917 void tipc_link_bundle_rcv(struct sk_buff
*buf
)
1919 u32 msgcount
= msg_msgcnt(buf_msg(buf
));
1920 u32 pos
= INT_H_SIZE
;
1921 struct sk_buff
*obuf
;
1922 struct tipc_msg
*omsg
;
1924 while (msgcount
--) {
1925 obuf
= buf_extract(buf
, pos
);
1927 pr_warn("Link unable to unbundle message(s)\n");
1930 omsg
= buf_msg(obuf
);
1931 pos
+= align(msg_size(omsg
));
1932 if (msg_isdata(omsg
)) {
1933 if (unlikely(msg_type(omsg
) == TIPC_MCAST_MSG
))
1934 tipc_sk_mcast_rcv(obuf
);
1937 } else if (msg_user(omsg
) == CONN_MANAGER
) {
1939 } else if (msg_user(omsg
) == NAME_DISTRIBUTOR
) {
1940 tipc_named_rcv(obuf
);
1942 pr_warn("Illegal bundled msg: %u\n", msg_user(omsg
));
1949 static void link_set_supervision_props(struct tipc_link
*l_ptr
, u32 tolerance
)
1951 if ((tolerance
< TIPC_MIN_LINK_TOL
) || (tolerance
> TIPC_MAX_LINK_TOL
))
1954 l_ptr
->tolerance
= tolerance
;
1955 l_ptr
->continuity_interval
=
1956 ((tolerance
/ 4) > 500) ? 500 : tolerance
/ 4;
1957 l_ptr
->abort_limit
= tolerance
/ (l_ptr
->continuity_interval
/ 4);
1960 void tipc_link_set_queue_limits(struct tipc_link
*l_ptr
, u32 window
)
1962 /* Data messages from this node, inclusive FIRST_FRAGM */
1963 l_ptr
->queue_limit
[TIPC_LOW_IMPORTANCE
] = window
;
1964 l_ptr
->queue_limit
[TIPC_MEDIUM_IMPORTANCE
] = (window
/ 3) * 4;
1965 l_ptr
->queue_limit
[TIPC_HIGH_IMPORTANCE
] = (window
/ 3) * 5;
1966 l_ptr
->queue_limit
[TIPC_CRITICAL_IMPORTANCE
] = (window
/ 3) * 6;
1967 /* Transiting data messages,inclusive FIRST_FRAGM */
1968 l_ptr
->queue_limit
[TIPC_LOW_IMPORTANCE
+ 4] = 300;
1969 l_ptr
->queue_limit
[TIPC_MEDIUM_IMPORTANCE
+ 4] = 600;
1970 l_ptr
->queue_limit
[TIPC_HIGH_IMPORTANCE
+ 4] = 900;
1971 l_ptr
->queue_limit
[TIPC_CRITICAL_IMPORTANCE
+ 4] = 1200;
1972 l_ptr
->queue_limit
[CONN_MANAGER
] = 1200;
1973 l_ptr
->queue_limit
[CHANGEOVER_PROTOCOL
] = 2500;
1974 l_ptr
->queue_limit
[NAME_DISTRIBUTOR
] = 3000;
1975 /* FRAGMENT and LAST_FRAGMENT packets */
1976 l_ptr
->queue_limit
[MSG_FRAGMENTER
] = 4000;
1979 /* tipc_link_find_owner - locate owner node of link by link's name
1980 * @name: pointer to link name string
1981 * @bearer_id: pointer to index in 'node->links' array where the link was found.
1983 * Returns pointer to node owning the link, or 0 if no matching link is found.
1985 static struct tipc_node
*tipc_link_find_owner(const char *link_name
,
1986 unsigned int *bearer_id
)
1988 struct tipc_link
*l_ptr
;
1989 struct tipc_node
*n_ptr
;
1990 struct tipc_node
*found_node
= 0;
1995 list_for_each_entry_rcu(n_ptr
, &tipc_node_list
, list
) {
1996 tipc_node_lock(n_ptr
);
1997 for (i
= 0; i
< MAX_BEARERS
; i
++) {
1998 l_ptr
= n_ptr
->links
[i
];
1999 if (l_ptr
&& !strcmp(l_ptr
->name
, link_name
)) {
2005 tipc_node_unlock(n_ptr
);
2015 * link_value_is_valid -- validate proposed link tolerance/priority/window
2017 * @cmd: value type (TIPC_CMD_SET_LINK_*)
2018 * @new_value: the new value
2020 * Returns 1 if value is within range, 0 if not.
2022 static int link_value_is_valid(u16 cmd
, u32 new_value
)
2025 case TIPC_CMD_SET_LINK_TOL
:
2026 return (new_value
>= TIPC_MIN_LINK_TOL
) &&
2027 (new_value
<= TIPC_MAX_LINK_TOL
);
2028 case TIPC_CMD_SET_LINK_PRI
:
2029 return (new_value
<= TIPC_MAX_LINK_PRI
);
2030 case TIPC_CMD_SET_LINK_WINDOW
:
2031 return (new_value
>= TIPC_MIN_LINK_WIN
) &&
2032 (new_value
<= TIPC_MAX_LINK_WIN
);
2038 * link_cmd_set_value - change priority/tolerance/window for link/bearer/media
2039 * @name: ptr to link, bearer, or media name
2040 * @new_value: new value of link, bearer, or media setting
2041 * @cmd: which link, bearer, or media attribute to set (TIPC_CMD_SET_LINK_*)
2043 * Caller must hold RTNL lock to ensure link/bearer/media is not deleted.
2045 * Returns 0 if value updated and negative value on error.
2047 static int link_cmd_set_value(const char *name
, u32 new_value
, u16 cmd
)
2049 struct tipc_node
*node
;
2050 struct tipc_link
*l_ptr
;
2051 struct tipc_bearer
*b_ptr
;
2052 struct tipc_media
*m_ptr
;
2056 node
= tipc_link_find_owner(name
, &bearer_id
);
2058 tipc_node_lock(node
);
2059 l_ptr
= node
->links
[bearer_id
];
2063 case TIPC_CMD_SET_LINK_TOL
:
2064 link_set_supervision_props(l_ptr
, new_value
);
2065 tipc_link_proto_xmit(l_ptr
, STATE_MSG
, 0, 0,
2068 case TIPC_CMD_SET_LINK_PRI
:
2069 l_ptr
->priority
= new_value
;
2070 tipc_link_proto_xmit(l_ptr
, STATE_MSG
, 0, 0,
2073 case TIPC_CMD_SET_LINK_WINDOW
:
2074 tipc_link_set_queue_limits(l_ptr
, new_value
);
2081 tipc_node_unlock(node
);
2085 b_ptr
= tipc_bearer_find(name
);
2088 case TIPC_CMD_SET_LINK_TOL
:
2089 b_ptr
->tolerance
= new_value
;
2091 case TIPC_CMD_SET_LINK_PRI
:
2092 b_ptr
->priority
= new_value
;
2094 case TIPC_CMD_SET_LINK_WINDOW
:
2095 b_ptr
->window
= new_value
;
2104 m_ptr
= tipc_media_find(name
);
2108 case TIPC_CMD_SET_LINK_TOL
:
2109 m_ptr
->tolerance
= new_value
;
2111 case TIPC_CMD_SET_LINK_PRI
:
2112 m_ptr
->priority
= new_value
;
2114 case TIPC_CMD_SET_LINK_WINDOW
:
2115 m_ptr
->window
= new_value
;
2124 struct sk_buff
*tipc_link_cmd_config(const void *req_tlv_area
, int req_tlv_space
,
2127 struct tipc_link_config
*args
;
2131 if (!TLV_CHECK(req_tlv_area
, req_tlv_space
, TIPC_TLV_LINK_CONFIG
))
2132 return tipc_cfg_reply_error_string(TIPC_CFG_TLV_ERROR
);
2134 args
= (struct tipc_link_config
*)TLV_DATA(req_tlv_area
);
2135 new_value
= ntohl(args
->value
);
2137 if (!link_value_is_valid(cmd
, new_value
))
2138 return tipc_cfg_reply_error_string(
2139 "cannot change, value invalid");
2141 if (!strcmp(args
->name
, tipc_bclink_name
)) {
2142 if ((cmd
== TIPC_CMD_SET_LINK_WINDOW
) &&
2143 (tipc_bclink_set_queue_limits(new_value
) == 0))
2144 return tipc_cfg_reply_none();
2145 return tipc_cfg_reply_error_string(TIPC_CFG_NOT_SUPPORTED
2146 " (cannot change setting on broadcast link)");
2149 res
= link_cmd_set_value(args
->name
, new_value
, cmd
);
2151 return tipc_cfg_reply_error_string("cannot change link setting");
2153 return tipc_cfg_reply_none();
2157 * link_reset_statistics - reset link statistics
2158 * @l_ptr: pointer to link
2160 static void link_reset_statistics(struct tipc_link
*l_ptr
)
2162 memset(&l_ptr
->stats
, 0, sizeof(l_ptr
->stats
));
2163 l_ptr
->stats
.sent_info
= l_ptr
->next_out_no
;
2164 l_ptr
->stats
.recv_info
= l_ptr
->next_in_no
;
2167 struct sk_buff
*tipc_link_cmd_reset_stats(const void *req_tlv_area
, int req_tlv_space
)
2170 struct tipc_link
*l_ptr
;
2171 struct tipc_node
*node
;
2172 unsigned int bearer_id
;
2174 if (!TLV_CHECK(req_tlv_area
, req_tlv_space
, TIPC_TLV_LINK_NAME
))
2175 return tipc_cfg_reply_error_string(TIPC_CFG_TLV_ERROR
);
2177 link_name
= (char *)TLV_DATA(req_tlv_area
);
2178 if (!strcmp(link_name
, tipc_bclink_name
)) {
2179 if (tipc_bclink_reset_stats())
2180 return tipc_cfg_reply_error_string("link not found");
2181 return tipc_cfg_reply_none();
2183 node
= tipc_link_find_owner(link_name
, &bearer_id
);
2185 return tipc_cfg_reply_error_string("link not found");
2187 tipc_node_lock(node
);
2188 l_ptr
= node
->links
[bearer_id
];
2190 tipc_node_unlock(node
);
2191 return tipc_cfg_reply_error_string("link not found");
2193 link_reset_statistics(l_ptr
);
2194 tipc_node_unlock(node
);
2195 return tipc_cfg_reply_none();
2199 * percent - convert count to a percentage of total (rounding up or down)
2201 static u32
percent(u32 count
, u32 total
)
2203 return (count
* 100 + (total
/ 2)) / total
;
2207 * tipc_link_stats - print link statistics
2209 * @buf: print buffer area
2210 * @buf_size: size of print buffer area
2212 * Returns length of print buffer data string (or 0 if error)
2214 static int tipc_link_stats(const char *name
, char *buf
, const u32 buf_size
)
2216 struct tipc_link
*l
;
2217 struct tipc_stats
*s
;
2218 struct tipc_node
*node
;
2220 u32 profile_total
= 0;
2221 unsigned int bearer_id
;
2224 if (!strcmp(name
, tipc_bclink_name
))
2225 return tipc_bclink_stats(buf
, buf_size
);
2227 node
= tipc_link_find_owner(name
, &bearer_id
);
2231 tipc_node_lock(node
);
2233 l
= node
->links
[bearer_id
];
2235 tipc_node_unlock(node
);
2241 if (tipc_link_is_active(l
))
2243 else if (tipc_link_is_up(l
))
2248 ret
= tipc_snprintf(buf
, buf_size
, "Link <%s>\n"
2249 " %s MTU:%u Priority:%u Tolerance:%u ms"
2250 " Window:%u packets\n",
2251 l
->name
, status
, l
->max_pkt
, l
->priority
,
2252 l
->tolerance
, l
->queue_limit
[0]);
2254 ret
+= tipc_snprintf(buf
+ ret
, buf_size
- ret
,
2255 " RX packets:%u fragments:%u/%u bundles:%u/%u\n",
2256 l
->next_in_no
- s
->recv_info
, s
->recv_fragments
,
2257 s
->recv_fragmented
, s
->recv_bundles
,
2260 ret
+= tipc_snprintf(buf
+ ret
, buf_size
- ret
,
2261 " TX packets:%u fragments:%u/%u bundles:%u/%u\n",
2262 l
->next_out_no
- s
->sent_info
, s
->sent_fragments
,
2263 s
->sent_fragmented
, s
->sent_bundles
,
2266 profile_total
= s
->msg_length_counts
;
2270 ret
+= tipc_snprintf(buf
+ ret
, buf_size
- ret
,
2271 " TX profile sample:%u packets average:%u octets\n"
2272 " 0-64:%u%% -256:%u%% -1024:%u%% -4096:%u%% "
2273 "-16384:%u%% -32768:%u%% -66000:%u%%\n",
2274 s
->msg_length_counts
,
2275 s
->msg_lengths_total
/ profile_total
,
2276 percent(s
->msg_length_profile
[0], profile_total
),
2277 percent(s
->msg_length_profile
[1], profile_total
),
2278 percent(s
->msg_length_profile
[2], profile_total
),
2279 percent(s
->msg_length_profile
[3], profile_total
),
2280 percent(s
->msg_length_profile
[4], profile_total
),
2281 percent(s
->msg_length_profile
[5], profile_total
),
2282 percent(s
->msg_length_profile
[6], profile_total
));
2284 ret
+= tipc_snprintf(buf
+ ret
, buf_size
- ret
,
2285 " RX states:%u probes:%u naks:%u defs:%u"
2286 " dups:%u\n", s
->recv_states
, s
->recv_probes
,
2287 s
->recv_nacks
, s
->deferred_recv
, s
->duplicates
);
2289 ret
+= tipc_snprintf(buf
+ ret
, buf_size
- ret
,
2290 " TX states:%u probes:%u naks:%u acks:%u"
2291 " dups:%u\n", s
->sent_states
, s
->sent_probes
,
2292 s
->sent_nacks
, s
->sent_acks
, s
->retransmitted
);
2294 ret
+= tipc_snprintf(buf
+ ret
, buf_size
- ret
,
2295 " Congestion link:%u Send queue"
2296 " max:%u avg:%u\n", s
->link_congs
,
2297 s
->max_queue_sz
, s
->queue_sz_counts
?
2298 (s
->accu_queue_sz
/ s
->queue_sz_counts
) : 0);
2300 tipc_node_unlock(node
);
2304 struct sk_buff
*tipc_link_cmd_show_stats(const void *req_tlv_area
, int req_tlv_space
)
2306 struct sk_buff
*buf
;
2307 struct tlv_desc
*rep_tlv
;
2312 if (!TLV_CHECK(req_tlv_area
, req_tlv_space
, TIPC_TLV_LINK_NAME
))
2313 return tipc_cfg_reply_error_string(TIPC_CFG_TLV_ERROR
);
2315 buf
= tipc_cfg_reply_alloc(TLV_SPACE(ULTRA_STRING_MAX_LEN
));
2319 rep_tlv
= (struct tlv_desc
*)buf
->data
;
2320 pb
= TLV_DATA(rep_tlv
);
2321 pb_len
= ULTRA_STRING_MAX_LEN
;
2322 str_len
= tipc_link_stats((char *)TLV_DATA(req_tlv_area
),
2326 return tipc_cfg_reply_error_string("link not found");
2328 str_len
+= 1; /* for "\0" */
2329 skb_put(buf
, TLV_SPACE(str_len
));
2330 TLV_SET(rep_tlv
, TIPC_TLV_ULTRA_STRING
, NULL
, str_len
);
2336 * tipc_link_get_max_pkt - get maximum packet size to use when sending to destination
2337 * @dest: network address of destination node
2338 * @selector: used to select from set of active links
2340 * If no active link can be found, uses default maximum packet size.
2342 u32
tipc_link_get_max_pkt(u32 dest
, u32 selector
)
2344 struct tipc_node
*n_ptr
;
2345 struct tipc_link
*l_ptr
;
2346 u32 res
= MAX_PKT_DEFAULT
;
2348 if (dest
== tipc_own_addr
)
2349 return MAX_MSG_SIZE
;
2351 n_ptr
= tipc_node_find(dest
);
2353 tipc_node_lock(n_ptr
);
2354 l_ptr
= n_ptr
->active_links
[selector
& 1];
2356 res
= l_ptr
->max_pkt
;
2357 tipc_node_unlock(n_ptr
);
2362 static void link_print(struct tipc_link
*l_ptr
, const char *str
)
2364 struct tipc_bearer
*b_ptr
;
2367 b_ptr
= rcu_dereference_rtnl(bearer_list
[l_ptr
->bearer_id
]);
2369 pr_info("%s Link %x<%s>:", str
, l_ptr
->addr
, b_ptr
->name
);
2372 if (link_working_unknown(l_ptr
))
2374 else if (link_reset_reset(l_ptr
))
2376 else if (link_reset_unknown(l_ptr
))
2378 else if (link_working_working(l_ptr
))
2384 /* Parse and validate nested (link) properties valid for media, bearer and link
2386 int tipc_nl_parse_link_prop(struct nlattr
*prop
, struct nlattr
*props
[])
2390 err
= nla_parse_nested(props
, TIPC_NLA_PROP_MAX
, prop
,
2391 tipc_nl_prop_policy
);
2395 if (props
[TIPC_NLA_PROP_PRIO
]) {
2398 prio
= nla_get_u32(props
[TIPC_NLA_PROP_PRIO
]);
2399 if (prio
> TIPC_MAX_LINK_PRI
)
2403 if (props
[TIPC_NLA_PROP_TOL
]) {
2406 tol
= nla_get_u32(props
[TIPC_NLA_PROP_TOL
]);
2407 if ((tol
< TIPC_MIN_LINK_TOL
) || (tol
> TIPC_MAX_LINK_TOL
))
2411 if (props
[TIPC_NLA_PROP_WIN
]) {
2414 win
= nla_get_u32(props
[TIPC_NLA_PROP_WIN
]);
2415 if ((win
< TIPC_MIN_LINK_WIN
) || (win
> TIPC_MAX_LINK_WIN
))
2422 int tipc_nl_link_set(struct sk_buff
*skb
, struct genl_info
*info
)
2428 struct tipc_link
*link
;
2429 struct tipc_node
*node
;
2430 struct nlattr
*attrs
[TIPC_NLA_LINK_MAX
+ 1];
2432 if (!info
->attrs
[TIPC_NLA_LINK
])
2435 err
= nla_parse_nested(attrs
, TIPC_NLA_LINK_MAX
,
2436 info
->attrs
[TIPC_NLA_LINK
],
2437 tipc_nl_link_policy
);
2441 if (!attrs
[TIPC_NLA_LINK_NAME
])
2444 name
= nla_data(attrs
[TIPC_NLA_LINK_NAME
]);
2446 node
= tipc_link_find_owner(name
, &bearer_id
);
2450 tipc_node_lock(node
);
2452 link
= node
->links
[bearer_id
];
2458 if (attrs
[TIPC_NLA_LINK_PROP
]) {
2459 struct nlattr
*props
[TIPC_NLA_PROP_MAX
+ 1];
2461 err
= tipc_nl_parse_link_prop(attrs
[TIPC_NLA_LINK_PROP
],
2468 if (props
[TIPC_NLA_PROP_TOL
]) {
2471 tol
= nla_get_u32(props
[TIPC_NLA_PROP_TOL
]);
2472 link_set_supervision_props(link
, tol
);
2473 tipc_link_proto_xmit(link
, STATE_MSG
, 0, 0, tol
, 0, 0);
2475 if (props
[TIPC_NLA_PROP_PRIO
]) {
2478 prio
= nla_get_u32(props
[TIPC_NLA_PROP_PRIO
]);
2479 link
->priority
= prio
;
2480 tipc_link_proto_xmit(link
, STATE_MSG
, 0, 0, 0, prio
, 0);
2482 if (props
[TIPC_NLA_PROP_WIN
]) {
2485 win
= nla_get_u32(props
[TIPC_NLA_PROP_WIN
]);
2486 tipc_link_set_queue_limits(link
, win
);
2491 tipc_node_unlock(node
);
2496 static int __tipc_nl_add_stats(struct sk_buff
*skb
, struct tipc_stats
*s
)
2499 struct nlattr
*stats
;
2506 struct nla_map map
[] = {
2507 {TIPC_NLA_STATS_RX_INFO
, s
->recv_info
},
2508 {TIPC_NLA_STATS_RX_FRAGMENTS
, s
->recv_fragments
},
2509 {TIPC_NLA_STATS_RX_FRAGMENTED
, s
->recv_fragmented
},
2510 {TIPC_NLA_STATS_RX_BUNDLES
, s
->recv_bundles
},
2511 {TIPC_NLA_STATS_RX_BUNDLED
, s
->recv_bundled
},
2512 {TIPC_NLA_STATS_TX_INFO
, s
->sent_info
},
2513 {TIPC_NLA_STATS_TX_FRAGMENTS
, s
->sent_fragments
},
2514 {TIPC_NLA_STATS_TX_FRAGMENTED
, s
->sent_fragmented
},
2515 {TIPC_NLA_STATS_TX_BUNDLES
, s
->sent_bundles
},
2516 {TIPC_NLA_STATS_TX_BUNDLED
, s
->sent_bundled
},
2517 {TIPC_NLA_STATS_MSG_PROF_TOT
, (s
->msg_length_counts
) ?
2518 s
->msg_length_counts
: 1},
2519 {TIPC_NLA_STATS_MSG_LEN_CNT
, s
->msg_length_counts
},
2520 {TIPC_NLA_STATS_MSG_LEN_TOT
, s
->msg_lengths_total
},
2521 {TIPC_NLA_STATS_MSG_LEN_P0
, s
->msg_length_profile
[0]},
2522 {TIPC_NLA_STATS_MSG_LEN_P1
, s
->msg_length_profile
[1]},
2523 {TIPC_NLA_STATS_MSG_LEN_P2
, s
->msg_length_profile
[2]},
2524 {TIPC_NLA_STATS_MSG_LEN_P3
, s
->msg_length_profile
[3]},
2525 {TIPC_NLA_STATS_MSG_LEN_P4
, s
->msg_length_profile
[4]},
2526 {TIPC_NLA_STATS_MSG_LEN_P5
, s
->msg_length_profile
[5]},
2527 {TIPC_NLA_STATS_MSG_LEN_P6
, s
->msg_length_profile
[6]},
2528 {TIPC_NLA_STATS_RX_STATES
, s
->recv_states
},
2529 {TIPC_NLA_STATS_RX_PROBES
, s
->recv_probes
},
2530 {TIPC_NLA_STATS_RX_NACKS
, s
->recv_nacks
},
2531 {TIPC_NLA_STATS_RX_DEFERRED
, s
->deferred_recv
},
2532 {TIPC_NLA_STATS_TX_STATES
, s
->sent_states
},
2533 {TIPC_NLA_STATS_TX_PROBES
, s
->sent_probes
},
2534 {TIPC_NLA_STATS_TX_NACKS
, s
->sent_nacks
},
2535 {TIPC_NLA_STATS_TX_ACKS
, s
->sent_acks
},
2536 {TIPC_NLA_STATS_RETRANSMITTED
, s
->retransmitted
},
2537 {TIPC_NLA_STATS_DUPLICATES
, s
->duplicates
},
2538 {TIPC_NLA_STATS_LINK_CONGS
, s
->link_congs
},
2539 {TIPC_NLA_STATS_MAX_QUEUE
, s
->max_queue_sz
},
2540 {TIPC_NLA_STATS_AVG_QUEUE
, s
->queue_sz_counts
?
2541 (s
->accu_queue_sz
/ s
->queue_sz_counts
) : 0}
2544 stats
= nla_nest_start(skb
, TIPC_NLA_LINK_STATS
);
2548 for (i
= 0; i
< ARRAY_SIZE(map
); i
++)
2549 if (nla_put_u32(skb
, map
[i
].key
, map
[i
].val
))
2552 nla_nest_end(skb
, stats
);
2556 nla_nest_cancel(skb
, stats
);
2561 /* Caller should hold appropriate locks to protect the link */
2562 static int __tipc_nl_add_link(struct tipc_nl_msg
*msg
, struct tipc_link
*link
)
2566 struct nlattr
*attrs
;
2567 struct nlattr
*prop
;
2569 hdr
= genlmsg_put(msg
->skb
, msg
->portid
, msg
->seq
, &tipc_genl_v2_family
,
2570 NLM_F_MULTI
, TIPC_NL_LINK_GET
);
2574 attrs
= nla_nest_start(msg
->skb
, TIPC_NLA_LINK
);
2578 if (nla_put_string(msg
->skb
, TIPC_NLA_LINK_NAME
, link
->name
))
2580 if (nla_put_u32(msg
->skb
, TIPC_NLA_LINK_DEST
,
2581 tipc_cluster_mask(tipc_own_addr
)))
2583 if (nla_put_u32(msg
->skb
, TIPC_NLA_LINK_MTU
, link
->max_pkt
))
2585 if (nla_put_u32(msg
->skb
, TIPC_NLA_LINK_RX
, link
->next_in_no
))
2587 if (nla_put_u32(msg
->skb
, TIPC_NLA_LINK_TX
, link
->next_out_no
))
2590 if (tipc_link_is_up(link
))
2591 if (nla_put_flag(msg
->skb
, TIPC_NLA_LINK_UP
))
2593 if (tipc_link_is_active(link
))
2594 if (nla_put_flag(msg
->skb
, TIPC_NLA_LINK_ACTIVE
))
2597 prop
= nla_nest_start(msg
->skb
, TIPC_NLA_LINK_PROP
);
2600 if (nla_put_u32(msg
->skb
, TIPC_NLA_PROP_PRIO
, link
->priority
))
2602 if (nla_put_u32(msg
->skb
, TIPC_NLA_PROP_TOL
, link
->tolerance
))
2604 if (nla_put_u32(msg
->skb
, TIPC_NLA_PROP_WIN
,
2605 link
->queue_limit
[TIPC_LOW_IMPORTANCE
]))
2607 if (nla_put_u32(msg
->skb
, TIPC_NLA_PROP_PRIO
, link
->priority
))
2609 nla_nest_end(msg
->skb
, prop
);
2611 err
= __tipc_nl_add_stats(msg
->skb
, &link
->stats
);
2615 nla_nest_end(msg
->skb
, attrs
);
2616 genlmsg_end(msg
->skb
, hdr
);
2621 nla_nest_cancel(msg
->skb
, prop
);
2623 nla_nest_cancel(msg
->skb
, attrs
);
2625 genlmsg_cancel(msg
->skb
, hdr
);
2630 /* Caller should hold node lock */
2631 static int __tipc_nl_add_node_links(struct tipc_nl_msg
*msg
,
2632 struct tipc_node
*node
,
2638 for (i
= *prev_link
; i
< MAX_BEARERS
; i
++) {
2641 if (!node
->links
[i
])
2644 err
= __tipc_nl_add_link(msg
, node
->links
[i
]);
2653 int tipc_nl_link_dump(struct sk_buff
*skb
, struct netlink_callback
*cb
)
2655 struct tipc_node
*node
;
2656 struct tipc_nl_msg msg
;
2657 u32 prev_node
= cb
->args
[0];
2658 u32 prev_link
= cb
->args
[1];
2659 int done
= cb
->args
[2];
2666 msg
.portid
= NETLINK_CB(cb
->skb
).portid
;
2667 msg
.seq
= cb
->nlh
->nlmsg_seq
;
2672 node
= tipc_node_find(prev_node
);
2674 /* We never set seq or call nl_dump_check_consistent()
2675 * this means that setting prev_seq here will cause the
2676 * consistence check to fail in the netlink callback
2677 * handler. Resulting in the last NLMSG_DONE message
2678 * having the NLM_F_DUMP_INTR flag set.
2684 list_for_each_entry_continue_rcu(node
, &tipc_node_list
, list
) {
2685 tipc_node_lock(node
);
2686 err
= __tipc_nl_add_node_links(&msg
, node
, &prev_link
);
2687 tipc_node_unlock(node
);
2691 prev_node
= node
->addr
;
2694 err
= tipc_nl_add_bc_link(&msg
);
2698 list_for_each_entry_rcu(node
, &tipc_node_list
, list
) {
2699 tipc_node_lock(node
);
2700 err
= __tipc_nl_add_node_links(&msg
, node
, &prev_link
);
2701 tipc_node_unlock(node
);
2705 prev_node
= node
->addr
;
2712 cb
->args
[0] = prev_node
;
2713 cb
->args
[1] = prev_link
;
2719 int tipc_nl_link_get(struct sk_buff
*skb
, struct genl_info
*info
)
2721 struct sk_buff
*ans_skb
;
2722 struct tipc_nl_msg msg
;
2723 struct tipc_link
*link
;
2724 struct tipc_node
*node
;
2729 if (!info
->attrs
[TIPC_NLA_LINK_NAME
])
2732 name
= nla_data(info
->attrs
[TIPC_NLA_LINK_NAME
]);
2733 node
= tipc_link_find_owner(name
, &bearer_id
);
2737 ans_skb
= nlmsg_new(NLMSG_GOODSIZE
, GFP_KERNEL
);
2742 msg
.portid
= info
->snd_portid
;
2743 msg
.seq
= info
->snd_seq
;
2745 tipc_node_lock(node
);
2746 link
= node
->links
[bearer_id
];
2752 err
= __tipc_nl_add_link(&msg
, link
);
2756 tipc_node_unlock(node
);
2758 return genlmsg_reply(ans_skb
, info
);
2761 tipc_node_unlock(node
);
2762 nlmsg_free(ans_skb
);
2767 int tipc_nl_link_reset_stats(struct sk_buff
*skb
, struct genl_info
*info
)
2771 unsigned int bearer_id
;
2772 struct tipc_link
*link
;
2773 struct tipc_node
*node
;
2774 struct nlattr
*attrs
[TIPC_NLA_LINK_MAX
+ 1];
2776 if (!info
->attrs
[TIPC_NLA_LINK
])
2779 err
= nla_parse_nested(attrs
, TIPC_NLA_LINK_MAX
,
2780 info
->attrs
[TIPC_NLA_LINK
],
2781 tipc_nl_link_policy
);
2785 if (!attrs
[TIPC_NLA_LINK_NAME
])
2788 link_name
= nla_data(attrs
[TIPC_NLA_LINK_NAME
]);
2790 if (strcmp(link_name
, tipc_bclink_name
) == 0) {
2791 err
= tipc_bclink_reset_stats();
2797 node
= tipc_link_find_owner(link_name
, &bearer_id
);
2801 tipc_node_lock(node
);
2803 link
= node
->links
[bearer_id
];
2805 tipc_node_unlock(node
);
2809 link_reset_statistics(link
);
2811 tipc_node_unlock(node
);