2 * net/tipc/link.c: TIPC link code
4 * Copyright (c) 1996-2007, 2012-2015, 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.
42 #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 * State value stored in 'failover_pkts'
94 #define FIRST_FAILOVER 0xffffu
96 static void link_handle_out_of_seq_msg(struct tipc_link *link,
98 static void tipc_link_proto_rcv(struct tipc_link *link,
100 static void link_set_supervision_props(struct tipc_link *l_ptr, u32 tol);
101 static void link_state_event(struct tipc_link *l_ptr, u32 event);
102 static void link_reset_statistics(struct tipc_link *l_ptr);
103 static void link_print(struct tipc_link *l_ptr, const char *str);
104 static void tipc_link_sync_xmit(struct tipc_link *l);
105 static void tipc_link_sync_rcv(struct tipc_node *n, struct sk_buff *buf);
106 static void tipc_link_input(struct tipc_link *l, struct sk_buff *skb);
107 static bool tipc_data_input(struct tipc_link *l, struct sk_buff *skb);
108 static bool tipc_link_failover_rcv(struct tipc_link *l, struct sk_buff **skb);
110 * Simple link routines
112 static unsigned int align(unsigned int i)
114 return (i + 3) & ~3u;
117 static void tipc_link_release(struct kref *kref)
119 kfree(container_of(kref, struct tipc_link, ref));
122 static void tipc_link_get(struct tipc_link *l_ptr)
124 kref_get(&l_ptr->ref);
127 static void tipc_link_put(struct tipc_link *l_ptr)
129 kref_put(&l_ptr->ref, tipc_link_release);
132 static struct tipc_link *tipc_parallel_link(struct tipc_link *l)
134 if (l->owner->active_links[0] != l)
135 return l->owner->active_links[0];
136 return l->owner->active_links[1];
139 static void link_init_max_pkt(struct tipc_link *l_ptr)
141 struct tipc_node *node = l_ptr->owner;
142 struct tipc_net *tn = net_generic(node->net, tipc_net_id);
143 struct tipc_bearer *b_ptr;
147 b_ptr = rcu_dereference_rtnl(tn->bearer_list[l_ptr->bearer_id]);
152 max_pkt = (b_ptr->mtu & ~3);
155 if (max_pkt > MAX_MSG_SIZE)
156 max_pkt = MAX_MSG_SIZE;
158 l_ptr->max_pkt_target = max_pkt;
159 if (l_ptr->max_pkt_target < MAX_PKT_DEFAULT)
160 l_ptr->max_pkt = l_ptr->max_pkt_target;
162 l_ptr->max_pkt = MAX_PKT_DEFAULT;
164 l_ptr->max_pkt_probes = 0;
168 * Simple non-static link routines (i.e. referenced outside this file)
170 int tipc_link_is_up(struct tipc_link *l_ptr)
174 return link_working_working(l_ptr) || link_working_unknown(l_ptr);
177 int tipc_link_is_active(struct tipc_link *l_ptr)
179 return (l_ptr->owner->active_links[0] == l_ptr) ||
180 (l_ptr->owner->active_links[1] == l_ptr);
184 * link_timeout - handle expiration of link timer
185 * @l_ptr: pointer to link
187 static void link_timeout(unsigned long data)
189 struct tipc_link *l_ptr = (struct tipc_link *)data;
192 tipc_node_lock(l_ptr->owner);
194 /* update counters used in statistical profiling of send traffic */
195 l_ptr->stats.accu_queue_sz += skb_queue_len(&l_ptr->transmq);
196 l_ptr->stats.queue_sz_counts++;
198 skb = skb_peek(&l_ptr->transmq);
200 struct tipc_msg *msg = buf_msg(skb);
201 u32 length = msg_size(msg);
203 if ((msg_user(msg) == MSG_FRAGMENTER) &&
204 (msg_type(msg) == FIRST_FRAGMENT)) {
205 length = msg_size(msg_get_wrapped(msg));
208 l_ptr->stats.msg_lengths_total += length;
209 l_ptr->stats.msg_length_counts++;
211 l_ptr->stats.msg_length_profile[0]++;
212 else if (length <= 256)
213 l_ptr->stats.msg_length_profile[1]++;
214 else if (length <= 1024)
215 l_ptr->stats.msg_length_profile[2]++;
216 else if (length <= 4096)
217 l_ptr->stats.msg_length_profile[3]++;
218 else if (length <= 16384)
219 l_ptr->stats.msg_length_profile[4]++;
220 else if (length <= 32768)
221 l_ptr->stats.msg_length_profile[5]++;
223 l_ptr->stats.msg_length_profile[6]++;
227 /* do all other link processing performed on a periodic basis */
228 link_state_event(l_ptr, TIMEOUT_EVT);
230 if (skb_queue_len(&l_ptr->backlogq))
231 tipc_link_push_packets(l_ptr);
233 tipc_node_unlock(l_ptr->owner);
234 tipc_link_put(l_ptr);
237 static void link_set_timer(struct tipc_link *link, unsigned long time)
239 if (!mod_timer(&link->timer, jiffies + time))
244 * tipc_link_create - create a new link
245 * @n_ptr: pointer to associated node
246 * @b_ptr: pointer to associated bearer
247 * @media_addr: media address to use when sending messages over link
249 * Returns pointer to link.
251 struct tipc_link *tipc_link_create(struct tipc_node *n_ptr,
252 struct tipc_bearer *b_ptr,
253 const struct tipc_media_addr *media_addr)
255 struct tipc_net *tn = net_generic(n_ptr->net, tipc_net_id);
256 struct tipc_link *l_ptr;
257 struct tipc_msg *msg;
259 char addr_string[16];
260 u32 peer = n_ptr->addr;
262 if (n_ptr->link_cnt >= MAX_BEARERS) {
263 tipc_addr_string_fill(addr_string, n_ptr->addr);
264 pr_err("Attempt to establish %uth link to %s. Max %u allowed.\n",
265 n_ptr->link_cnt, addr_string, MAX_BEARERS);
269 if (n_ptr->links[b_ptr->identity]) {
270 tipc_addr_string_fill(addr_string, n_ptr->addr);
271 pr_err("Attempt to establish second link on <%s> to %s\n",
272 b_ptr->name, addr_string);
276 l_ptr = kzalloc(sizeof(*l_ptr), GFP_ATOMIC);
278 pr_warn("Link creation failed, no memory\n");
281 kref_init(&l_ptr->ref);
283 if_name = strchr(b_ptr->name, ':') + 1;
284 sprintf(l_ptr->name, "%u.%u.%u:%s-%u.%u.%u:unknown",
285 tipc_zone(tn->own_addr), tipc_cluster(tn->own_addr),
286 tipc_node(tn->own_addr),
288 tipc_zone(peer), tipc_cluster(peer), tipc_node(peer));
289 /* note: peer i/f name is updated by reset/activate message */
290 memcpy(&l_ptr->media_addr, media_addr, sizeof(*media_addr));
291 l_ptr->owner = n_ptr;
292 l_ptr->checkpoint = 1;
293 l_ptr->peer_session = INVALID_SESSION;
294 l_ptr->bearer_id = b_ptr->identity;
295 link_set_supervision_props(l_ptr, b_ptr->tolerance);
296 l_ptr->state = RESET_UNKNOWN;
298 l_ptr->pmsg = (struct tipc_msg *)&l_ptr->proto_msg;
300 tipc_msg_init(tn->own_addr, msg, LINK_PROTOCOL, RESET_MSG, INT_H_SIZE,
302 msg_set_size(msg, sizeof(l_ptr->proto_msg));
303 msg_set_session(msg, (tn->random & 0xffff));
304 msg_set_bearer_id(msg, b_ptr->identity);
305 strcpy((char *)msg_data(msg), if_name);
306 l_ptr->net_plane = b_ptr->net_plane;
307 link_init_max_pkt(l_ptr);
308 l_ptr->priority = b_ptr->priority;
309 tipc_link_set_queue_limits(l_ptr, b_ptr->window);
310 l_ptr->next_out_no = 1;
311 __skb_queue_head_init(&l_ptr->transmq);
312 __skb_queue_head_init(&l_ptr->backlogq);
313 __skb_queue_head_init(&l_ptr->deferdq);
314 skb_queue_head_init(&l_ptr->wakeupq);
315 skb_queue_head_init(&l_ptr->inputq);
316 skb_queue_head_init(&l_ptr->namedq);
317 link_reset_statistics(l_ptr);
318 tipc_node_attach_link(n_ptr, l_ptr);
319 setup_timer(&l_ptr->timer, link_timeout, (unsigned long)l_ptr);
320 link_state_event(l_ptr, STARTING_EVT);
326 * tipc_link_delete - Delete a link
327 * @l: link to be deleted
329 void tipc_link_delete(struct tipc_link *l)
332 if (del_timer(&l->timer))
334 l->flags |= LINK_STOPPED;
335 /* Delete link now, or when timer is finished: */
336 tipc_link_reset_fragments(l);
337 tipc_node_detach_link(l->owner, l);
341 void tipc_link_delete_list(struct net *net, unsigned int bearer_id,
344 struct tipc_net *tn = net_generic(net, tipc_net_id);
345 struct tipc_link *link;
346 struct tipc_node *node;
349 list_for_each_entry_rcu(node, &tn->node_list, list) {
350 tipc_node_lock(node);
351 link = node->links[bearer_id];
353 tipc_link_delete(link);
354 tipc_node_unlock(node);
360 * link_schedule_user - schedule a message sender for wakeup after congestion
361 * @link: congested link
362 * @list: message that was attempted sent
363 * Create pseudo msg to send back to user when congestion abates
364 * Only consumes message if there is an error
366 static int link_schedule_user(struct tipc_link *link, struct sk_buff_head *list)
368 struct tipc_msg *msg = buf_msg(skb_peek(list));
369 int imp = msg_importance(msg);
370 u32 oport = msg_origport(msg);
371 u32 addr = link_own_addr(link);
374 /* This really cannot happen... */
375 if (unlikely(imp > TIPC_CRITICAL_IMPORTANCE)) {
376 pr_warn("%s<%s>, send queue full", link_rst_msg, link->name);
377 tipc_link_reset(link);
380 /* Non-blocking sender: */
381 if (TIPC_SKB_CB(skb_peek(list))->wakeup_pending)
384 /* Create and schedule wakeup pseudo message */
385 skb = tipc_msg_create(SOCK_WAKEUP, 0, INT_H_SIZE, 0,
386 addr, addr, oport, 0, 0);
389 TIPC_SKB_CB(skb)->chain_sz = skb_queue_len(list);
390 TIPC_SKB_CB(skb)->chain_imp = imp;
391 skb_queue_tail(&link->wakeupq, skb);
392 link->stats.link_congs++;
395 __skb_queue_purge(list);
400 * link_prepare_wakeup - prepare users for wakeup after congestion
401 * @link: congested link
402 * Move a number of waiting users, as permitted by available space in
403 * the send queue, from link wait queue to node wait queue for wakeup
405 void link_prepare_wakeup(struct tipc_link *l)
407 int pnd[TIPC_SYSTEM_IMPORTANCE + 1] = {0,};
409 struct sk_buff *skb, *tmp;
411 skb_queue_walk_safe(&l->wakeupq, skb, tmp) {
412 imp = TIPC_SKB_CB(skb)->chain_imp;
413 lim = l->window + l->backlog[imp].limit;
414 pnd[imp] += TIPC_SKB_CB(skb)->chain_sz;
415 if ((pnd[imp] + l->backlog[imp].len) >= lim)
417 skb_unlink(skb, &l->wakeupq);
418 skb_queue_tail(&l->inputq, skb);
419 l->owner->inputq = &l->inputq;
420 l->owner->action_flags |= TIPC_MSG_EVT;
425 * tipc_link_reset_fragments - purge link's inbound message fragments queue
426 * @l_ptr: pointer to link
428 void tipc_link_reset_fragments(struct tipc_link *l_ptr)
430 kfree_skb(l_ptr->reasm_buf);
431 l_ptr->reasm_buf = NULL;
434 static void tipc_link_purge_backlog(struct tipc_link *l)
436 __skb_queue_purge(&l->backlogq);
437 l->backlog[TIPC_LOW_IMPORTANCE].len = 0;
438 l->backlog[TIPC_MEDIUM_IMPORTANCE].len = 0;
439 l->backlog[TIPC_HIGH_IMPORTANCE].len = 0;
440 l->backlog[TIPC_CRITICAL_IMPORTANCE].len = 0;
441 l->backlog[TIPC_SYSTEM_IMPORTANCE].len = 0;
445 * tipc_link_purge_queues - purge all pkt queues associated with link
446 * @l_ptr: pointer to link
448 void tipc_link_purge_queues(struct tipc_link *l_ptr)
450 __skb_queue_purge(&l_ptr->deferdq);
451 __skb_queue_purge(&l_ptr->transmq);
452 tipc_link_purge_backlog(l_ptr);
453 tipc_link_reset_fragments(l_ptr);
456 void tipc_link_reset(struct tipc_link *l_ptr)
458 u32 prev_state = l_ptr->state;
459 int was_active_link = tipc_link_is_active(l_ptr);
460 struct tipc_node *owner = l_ptr->owner;
461 struct tipc_link *pl = tipc_parallel_link(l_ptr);
463 msg_set_session(l_ptr->pmsg, ((msg_session(l_ptr->pmsg) + 1) & 0xffff));
465 /* Link is down, accept any session */
466 l_ptr->peer_session = INVALID_SESSION;
468 /* Prepare for max packet size negotiation */
469 link_init_max_pkt(l_ptr);
471 l_ptr->state = RESET_UNKNOWN;
473 if ((prev_state == RESET_UNKNOWN) || (prev_state == RESET_RESET))
476 tipc_node_link_down(l_ptr->owner, l_ptr);
477 tipc_bearer_remove_dest(owner->net, l_ptr->bearer_id, l_ptr->addr);
479 if (was_active_link && tipc_node_is_up(l_ptr->owner) && (pl != l_ptr)) {
480 l_ptr->flags |= LINK_FAILINGOVER;
481 l_ptr->failover_checkpt = l_ptr->next_in_no;
482 pl->failover_pkts = FIRST_FAILOVER;
483 pl->failover_checkpt = l_ptr->next_in_no;
484 pl->failover_skb = l_ptr->reasm_buf;
486 kfree_skb(l_ptr->reasm_buf);
488 /* Clean up all queues, except inputq: */
489 __skb_queue_purge(&l_ptr->transmq);
490 __skb_queue_purge(&l_ptr->deferdq);
492 owner->inputq = &l_ptr->inputq;
493 skb_queue_splice_init(&l_ptr->wakeupq, owner->inputq);
494 if (!skb_queue_empty(owner->inputq))
495 owner->action_flags |= TIPC_MSG_EVT;
496 tipc_link_purge_backlog(l_ptr);
497 l_ptr->reasm_buf = NULL;
498 l_ptr->rcv_unacked = 0;
499 l_ptr->checkpoint = 1;
500 l_ptr->next_out_no = 1;
501 l_ptr->fsm_msg_cnt = 0;
502 l_ptr->stale_count = 0;
503 link_reset_statistics(l_ptr);
506 void tipc_link_reset_list(struct net *net, unsigned int bearer_id)
508 struct tipc_net *tn = net_generic(net, tipc_net_id);
509 struct tipc_link *l_ptr;
510 struct tipc_node *n_ptr;
513 list_for_each_entry_rcu(n_ptr, &tn->node_list, list) {
514 tipc_node_lock(n_ptr);
515 l_ptr = n_ptr->links[bearer_id];
517 tipc_link_reset(l_ptr);
518 tipc_node_unlock(n_ptr);
523 static void link_activate(struct tipc_link *link)
525 struct tipc_node *node = link->owner;
527 link->next_in_no = 1;
528 link->stats.recv_info = 1;
529 tipc_node_link_up(node, link);
530 tipc_bearer_add_dest(node->net, link->bearer_id, link->addr);
534 * link_state_event - link finite state machine
535 * @l_ptr: pointer to link
536 * @event: state machine event to process
538 static void link_state_event(struct tipc_link *l_ptr, unsigned int event)
540 struct tipc_link *other;
541 unsigned long cont_intv = l_ptr->cont_intv;
543 if (l_ptr->flags & LINK_STOPPED)
546 if (!(l_ptr->flags & LINK_STARTED) && (event != STARTING_EVT))
547 return; /* Not yet. */
549 if (l_ptr->flags & LINK_FAILINGOVER) {
550 if (event == TIMEOUT_EVT)
551 link_set_timer(l_ptr, cont_intv);
555 switch (l_ptr->state) {
556 case WORKING_WORKING:
558 case TRAFFIC_MSG_EVT:
562 if (l_ptr->next_in_no != l_ptr->checkpoint) {
563 l_ptr->checkpoint = l_ptr->next_in_no;
564 if (tipc_bclink_acks_missing(l_ptr->owner)) {
565 tipc_link_proto_xmit(l_ptr, STATE_MSG,
567 l_ptr->fsm_msg_cnt++;
568 } else if (l_ptr->max_pkt < l_ptr->max_pkt_target) {
569 tipc_link_proto_xmit(l_ptr, STATE_MSG,
571 l_ptr->fsm_msg_cnt++;
573 link_set_timer(l_ptr, cont_intv);
576 l_ptr->state = WORKING_UNKNOWN;
577 l_ptr->fsm_msg_cnt = 0;
578 tipc_link_proto_xmit(l_ptr, STATE_MSG, 1, 0, 0, 0, 0);
579 l_ptr->fsm_msg_cnt++;
580 link_set_timer(l_ptr, cont_intv / 4);
583 pr_debug("%s<%s>, requested by peer\n",
584 link_rst_msg, l_ptr->name);
585 tipc_link_reset(l_ptr);
586 l_ptr->state = RESET_RESET;
587 l_ptr->fsm_msg_cnt = 0;
588 tipc_link_proto_xmit(l_ptr, ACTIVATE_MSG,
590 l_ptr->fsm_msg_cnt++;
591 link_set_timer(l_ptr, cont_intv);
594 pr_debug("%s%u in WW state\n", link_unk_evt, event);
597 case WORKING_UNKNOWN:
599 case TRAFFIC_MSG_EVT:
601 l_ptr->state = WORKING_WORKING;
602 l_ptr->fsm_msg_cnt = 0;
603 link_set_timer(l_ptr, cont_intv);
606 pr_debug("%s<%s>, requested by peer while probing\n",
607 link_rst_msg, l_ptr->name);
608 tipc_link_reset(l_ptr);
609 l_ptr->state = RESET_RESET;
610 l_ptr->fsm_msg_cnt = 0;
611 tipc_link_proto_xmit(l_ptr, ACTIVATE_MSG,
613 l_ptr->fsm_msg_cnt++;
614 link_set_timer(l_ptr, cont_intv);
617 if (l_ptr->next_in_no != l_ptr->checkpoint) {
618 l_ptr->state = WORKING_WORKING;
619 l_ptr->fsm_msg_cnt = 0;
620 l_ptr->checkpoint = l_ptr->next_in_no;
621 if (tipc_bclink_acks_missing(l_ptr->owner)) {
622 tipc_link_proto_xmit(l_ptr, STATE_MSG,
624 l_ptr->fsm_msg_cnt++;
626 link_set_timer(l_ptr, cont_intv);
627 } else if (l_ptr->fsm_msg_cnt < l_ptr->abort_limit) {
628 tipc_link_proto_xmit(l_ptr, STATE_MSG,
630 l_ptr->fsm_msg_cnt++;
631 link_set_timer(l_ptr, cont_intv / 4);
632 } else { /* Link has failed */
633 pr_debug("%s<%s>, peer not responding\n",
634 link_rst_msg, l_ptr->name);
635 tipc_link_reset(l_ptr);
636 l_ptr->state = RESET_UNKNOWN;
637 l_ptr->fsm_msg_cnt = 0;
638 tipc_link_proto_xmit(l_ptr, RESET_MSG,
640 l_ptr->fsm_msg_cnt++;
641 link_set_timer(l_ptr, cont_intv);
645 pr_err("%s%u in WU state\n", link_unk_evt, event);
650 case TRAFFIC_MSG_EVT:
653 other = l_ptr->owner->active_links[0];
654 if (other && link_working_unknown(other))
656 l_ptr->state = WORKING_WORKING;
657 l_ptr->fsm_msg_cnt = 0;
658 link_activate(l_ptr);
659 tipc_link_proto_xmit(l_ptr, STATE_MSG, 1, 0, 0, 0, 0);
660 l_ptr->fsm_msg_cnt++;
661 if (l_ptr->owner->working_links == 1)
662 tipc_link_sync_xmit(l_ptr);
663 link_set_timer(l_ptr, cont_intv);
666 l_ptr->state = RESET_RESET;
667 l_ptr->fsm_msg_cnt = 0;
668 tipc_link_proto_xmit(l_ptr, ACTIVATE_MSG,
670 l_ptr->fsm_msg_cnt++;
671 link_set_timer(l_ptr, cont_intv);
674 l_ptr->flags |= LINK_STARTED;
675 l_ptr->fsm_msg_cnt++;
676 link_set_timer(l_ptr, cont_intv);
679 tipc_link_proto_xmit(l_ptr, RESET_MSG, 0, 0, 0, 0, 0);
680 l_ptr->fsm_msg_cnt++;
681 link_set_timer(l_ptr, cont_intv);
684 pr_err("%s%u in RU state\n", link_unk_evt, event);
689 case TRAFFIC_MSG_EVT:
691 other = l_ptr->owner->active_links[0];
692 if (other && link_working_unknown(other))
694 l_ptr->state = WORKING_WORKING;
695 l_ptr->fsm_msg_cnt = 0;
696 link_activate(l_ptr);
697 tipc_link_proto_xmit(l_ptr, STATE_MSG, 1, 0, 0, 0, 0);
698 l_ptr->fsm_msg_cnt++;
699 if (l_ptr->owner->working_links == 1)
700 tipc_link_sync_xmit(l_ptr);
701 link_set_timer(l_ptr, cont_intv);
706 tipc_link_proto_xmit(l_ptr, ACTIVATE_MSG,
708 l_ptr->fsm_msg_cnt++;
709 link_set_timer(l_ptr, cont_intv);
712 pr_err("%s%u in RR state\n", link_unk_evt, event);
716 pr_err("Unknown link state %u/%u\n", l_ptr->state, event);
721 * __tipc_link_xmit(): same as tipc_link_xmit, but destlink is known & locked
723 * @list: chain of buffers containing message
725 * Consumes the buffer chain, except when returning -ELINKCONG,
726 * since the caller then may want to make more send attempts.
727 * Returns 0 if success, or errno: -ELINKCONG, -EMSGSIZE or -ENOBUFS
728 * Messages at TIPC_SYSTEM_IMPORTANCE are always accepted
730 int __tipc_link_xmit(struct net *net, struct tipc_link *link,
731 struct sk_buff_head *list)
733 struct tipc_msg *msg = buf_msg(skb_peek(list));
734 unsigned int maxwin = link->window;
735 unsigned int imp = msg_importance(msg);
736 uint mtu = link->max_pkt;
737 uint ack = mod(link->next_in_no - 1);
738 uint seqno = link->next_out_no;
739 uint bc_last_in = link->owner->bclink.last_in;
740 struct tipc_media_addr *addr = &link->media_addr;
741 struct sk_buff_head *transmq = &link->transmq;
742 struct sk_buff_head *backlogq = &link->backlogq;
743 struct sk_buff *skb, *tmp;
745 /* Match backlog limit against msg importance: */
746 if (unlikely(link->backlog[imp].len >= link->backlog[imp].limit))
747 return link_schedule_user(link, list);
749 if (unlikely(msg_size(msg) > mtu)) {
750 __skb_queue_purge(list);
753 /* Prepare each packet for sending, and add to relevant queue: */
754 skb_queue_walk_safe(list, skb, tmp) {
755 __skb_unlink(skb, list);
757 msg_set_seqno(msg, seqno);
758 msg_set_ack(msg, ack);
759 msg_set_bcast_ack(msg, bc_last_in);
761 if (likely(skb_queue_len(transmq) < maxwin)) {
762 __skb_queue_tail(transmq, skb);
763 tipc_bearer_send(net, link->bearer_id, skb, addr);
764 link->rcv_unacked = 0;
768 if (tipc_msg_bundle(skb_peek_tail(backlogq), skb, mtu)) {
769 link->stats.sent_bundled++;
772 if (tipc_msg_make_bundle(&skb, mtu, link->addr)) {
773 link->stats.sent_bundled++;
774 link->stats.sent_bundles++;
775 imp = msg_importance(buf_msg(skb));
777 __skb_queue_tail(backlogq, skb);
778 link->backlog[imp].len++;
781 link->next_out_no = seqno;
785 static void skb2list(struct sk_buff *skb, struct sk_buff_head *list)
787 skb_queue_head_init(list);
788 __skb_queue_tail(list, skb);
791 static int __tipc_link_xmit_skb(struct tipc_link *link, struct sk_buff *skb)
793 struct sk_buff_head head;
795 skb2list(skb, &head);
796 return __tipc_link_xmit(link->owner->net, link, &head);
799 /* tipc_link_xmit_skb(): send single buffer to destination
800 * Buffers sent via this functon are generally TIPC_SYSTEM_IMPORTANCE
801 * messages, which will not be rejected
802 * The only exception is datagram messages rerouted after secondary
803 * lookup, which are rare and safe to dispose of anyway.
804 * TODO: Return real return value, and let callers use
805 * tipc_wait_for_sendpkt() where applicable
807 int tipc_link_xmit_skb(struct net *net, struct sk_buff *skb, u32 dnode,
810 struct sk_buff_head head;
813 skb2list(skb, &head);
814 rc = tipc_link_xmit(net, &head, dnode, selector);
815 if (rc == -ELINKCONG)
821 * tipc_link_xmit() is the general link level function for message sending
822 * @net: the applicable net namespace
823 * @list: chain of buffers containing message
824 * @dsz: amount of user data to be sent
825 * @dnode: address of destination node
826 * @selector: a number used for deterministic link selection
827 * Consumes the buffer chain, except when returning -ELINKCONG
828 * Returns 0 if success, otherwise errno: -ELINKCONG,-EHOSTUNREACH,-EMSGSIZE
830 int tipc_link_xmit(struct net *net, struct sk_buff_head *list, u32 dnode,
833 struct tipc_link *link = NULL;
834 struct tipc_node *node;
835 int rc = -EHOSTUNREACH;
837 node = tipc_node_find(net, dnode);
839 tipc_node_lock(node);
840 link = node->active_links[selector & 1];
842 rc = __tipc_link_xmit(net, link, list);
843 tipc_node_unlock(node);
849 if (likely(in_own_node(net, dnode))) {
850 tipc_sk_rcv(net, list);
854 __skb_queue_purge(list);
859 * tipc_link_sync_xmit - synchronize broadcast link endpoints.
861 * Give a newly added peer node the sequence number where it should
862 * start receiving and acking broadcast packets.
864 * Called with node locked
866 static void tipc_link_sync_xmit(struct tipc_link *link)
869 struct tipc_msg *msg;
871 skb = tipc_buf_acquire(INT_H_SIZE);
876 tipc_msg_init(link_own_addr(link), msg, BCAST_PROTOCOL, STATE_MSG,
877 INT_H_SIZE, link->addr);
878 msg_set_last_bcast(msg, link->owner->bclink.acked);
879 __tipc_link_xmit_skb(link, skb);
883 * tipc_link_sync_rcv - synchronize broadcast link endpoints.
884 * Receive the sequence number where we should start receiving and
885 * acking broadcast packets from a newly added peer node, and open
886 * up for reception of such packets.
888 * Called with node locked
890 static void tipc_link_sync_rcv(struct tipc_node *n, struct sk_buff *buf)
892 struct tipc_msg *msg = buf_msg(buf);
894 n->bclink.last_sent = n->bclink.last_in = msg_last_bcast(msg);
895 n->bclink.recv_permitted = true;
900 * tipc_link_push_packets - push unsent packets to bearer
902 * Push out the unsent messages of a link where congestion
903 * has abated. Node is locked.
905 * Called with node locked
907 void tipc_link_push_packets(struct tipc_link *link)
910 struct tipc_msg *msg;
911 unsigned int ack = mod(link->next_in_no - 1);
913 while (skb_queue_len(&link->transmq) < link->window) {
914 skb = __skb_dequeue(&link->backlogq);
918 link->backlog[msg_importance(msg)].len--;
919 msg_set_ack(msg, ack);
920 msg_set_bcast_ack(msg, link->owner->bclink.last_in);
921 link->rcv_unacked = 0;
922 __skb_queue_tail(&link->transmq, skb);
923 tipc_bearer_send(link->owner->net, link->bearer_id,
924 skb, &link->media_addr);
928 void tipc_link_reset_all(struct tipc_node *node)
930 char addr_string[16];
933 tipc_node_lock(node);
935 pr_warn("Resetting all links to %s\n",
936 tipc_addr_string_fill(addr_string, node->addr));
938 for (i = 0; i < MAX_BEARERS; i++) {
939 if (node->links[i]) {
940 link_print(node->links[i], "Resetting link\n");
941 tipc_link_reset(node->links[i]);
945 tipc_node_unlock(node);
948 static void link_retransmit_failure(struct tipc_link *l_ptr,
951 struct tipc_msg *msg = buf_msg(buf);
952 struct net *net = l_ptr->owner->net;
954 pr_warn("Retransmission failure on link <%s>\n", l_ptr->name);
957 /* Handle failure on standard link */
958 link_print(l_ptr, "Resetting link\n");
959 tipc_link_reset(l_ptr);
962 /* Handle failure on broadcast link */
963 struct tipc_node *n_ptr;
964 char addr_string[16];
966 pr_info("Msg seq number: %u, ", msg_seqno(msg));
967 pr_cont("Outstanding acks: %lu\n",
968 (unsigned long) TIPC_SKB_CB(buf)->handle);
970 n_ptr = tipc_bclink_retransmit_to(net);
972 tipc_addr_string_fill(addr_string, n_ptr->addr);
973 pr_info("Broadcast link info for %s\n", addr_string);
974 pr_info("Reception permitted: %d, Acked: %u\n",
975 n_ptr->bclink.recv_permitted,
976 n_ptr->bclink.acked);
977 pr_info("Last in: %u, Oos state: %u, Last sent: %u\n",
978 n_ptr->bclink.last_in,
979 n_ptr->bclink.oos_state,
980 n_ptr->bclink.last_sent);
982 n_ptr->action_flags |= TIPC_BCAST_RESET;
983 l_ptr->stale_count = 0;
987 void tipc_link_retransmit(struct tipc_link *l_ptr, struct sk_buff *skb,
990 struct tipc_msg *msg;
997 /* Detect repeated retransmit failures */
998 if (l_ptr->last_retransmitted == msg_seqno(msg)) {
999 if (++l_ptr->stale_count > 100) {
1000 link_retransmit_failure(l_ptr, skb);
1004 l_ptr->last_retransmitted = msg_seqno(msg);
1005 l_ptr->stale_count = 1;
1008 skb_queue_walk_from(&l_ptr->transmq, skb) {
1012 msg_set_ack(msg, mod(l_ptr->next_in_no - 1));
1013 msg_set_bcast_ack(msg, l_ptr->owner->bclink.last_in);
1014 tipc_bearer_send(l_ptr->owner->net, l_ptr->bearer_id, skb,
1015 &l_ptr->media_addr);
1017 l_ptr->stats.retransmitted++;
1021 /* link_synch(): check if all packets arrived before the synch
1022 * point have been consumed
1023 * Returns true if the parallel links are synched, otherwise false
1025 static bool link_synch(struct tipc_link *l)
1027 unsigned int post_synch;
1028 struct tipc_link *pl;
1030 pl = tipc_parallel_link(l);
1034 /* Was last pre-synch packet added to input queue ? */
1035 if (less_eq(pl->next_in_no, l->synch_point))
1038 /* Is it still in the input queue ? */
1039 post_synch = mod(pl->next_in_no - l->synch_point) - 1;
1040 if (skb_queue_len(&pl->inputq) > post_synch)
1043 l->flags &= ~LINK_SYNCHING;
1047 static void link_retrieve_defq(struct tipc_link *link,
1048 struct sk_buff_head *list)
1052 if (skb_queue_empty(&link->deferdq))
1055 seq_no = buf_seqno(skb_peek(&link->deferdq));
1056 if (seq_no == mod(link->next_in_no))
1057 skb_queue_splice_tail_init(&link->deferdq, list);
1061 * tipc_rcv - process TIPC packets/messages arriving from off-node
1062 * @net: the applicable net namespace
1064 * @b_ptr: pointer to bearer message arrived on
1066 * Invoked with no locks held. Bearer pointer must point to a valid bearer
1067 * structure (i.e. cannot be NULL), but bearer can be inactive.
1069 void tipc_rcv(struct net *net, struct sk_buff *skb, struct tipc_bearer *b_ptr)
1071 struct tipc_net *tn = net_generic(net, tipc_net_id);
1072 struct sk_buff_head head;
1073 struct tipc_node *n_ptr;
1074 struct tipc_link *l_ptr;
1075 struct sk_buff *skb1, *tmp;
1076 struct tipc_msg *msg;
1081 skb2list(skb, &head);
1083 while ((skb = __skb_dequeue(&head))) {
1084 /* Ensure message is well-formed */
1085 if (unlikely(!tipc_msg_validate(skb)))
1088 /* Handle arrival of a non-unicast link message */
1090 if (unlikely(msg_non_seq(msg))) {
1091 if (msg_user(msg) == LINK_CONFIG)
1092 tipc_disc_rcv(net, skb, b_ptr);
1094 tipc_bclink_rcv(net, skb);
1098 /* Discard unicast link messages destined for another node */
1099 if (unlikely(!msg_short(msg) &&
1100 (msg_destnode(msg) != tn->own_addr)))
1103 /* Locate neighboring node that sent message */
1104 n_ptr = tipc_node_find(net, msg_prevnode(msg));
1105 if (unlikely(!n_ptr))
1108 tipc_node_lock(n_ptr);
1109 /* Locate unicast link endpoint that should handle message */
1110 l_ptr = n_ptr->links[b_ptr->identity];
1111 if (unlikely(!l_ptr))
1114 /* Verify that communication with node is currently allowed */
1115 if ((n_ptr->action_flags & TIPC_WAIT_PEER_LINKS_DOWN) &&
1116 msg_user(msg) == LINK_PROTOCOL &&
1117 (msg_type(msg) == RESET_MSG ||
1118 msg_type(msg) == ACTIVATE_MSG) &&
1119 !msg_redundant_link(msg))
1120 n_ptr->action_flags &= ~TIPC_WAIT_PEER_LINKS_DOWN;
1122 if (tipc_node_blocked(n_ptr))
1125 /* Validate message sequence number info */
1126 seq_no = msg_seqno(msg);
1127 ackd = msg_ack(msg);
1129 /* Release acked messages */
1130 if (unlikely(n_ptr->bclink.acked != msg_bcast_ack(msg)))
1131 tipc_bclink_acknowledge(n_ptr, msg_bcast_ack(msg));
1134 skb_queue_walk_safe(&l_ptr->transmq, skb1, tmp) {
1135 if (more(buf_seqno(skb1), ackd))
1137 __skb_unlink(skb1, &l_ptr->transmq);
1142 /* Try sending any messages link endpoint has pending */
1143 if (unlikely(skb_queue_len(&l_ptr->backlogq)))
1144 tipc_link_push_packets(l_ptr);
1146 if (released && !skb_queue_empty(&l_ptr->wakeupq))
1147 link_prepare_wakeup(l_ptr);
1149 /* Process the incoming packet */
1150 if (unlikely(!link_working_working(l_ptr))) {
1151 if (msg_user(msg) == LINK_PROTOCOL) {
1152 tipc_link_proto_rcv(l_ptr, skb);
1153 link_retrieve_defq(l_ptr, &head);
1158 /* Traffic message. Conditionally activate link */
1159 link_state_event(l_ptr, TRAFFIC_MSG_EVT);
1161 if (link_working_working(l_ptr)) {
1162 /* Re-insert buffer in front of queue */
1163 __skb_queue_head(&head, skb);
1170 /* Link is now in state WORKING_WORKING */
1171 if (unlikely(seq_no != mod(l_ptr->next_in_no))) {
1172 link_handle_out_of_seq_msg(l_ptr, skb);
1173 link_retrieve_defq(l_ptr, &head);
1177 /* Synchronize with parallel link if applicable */
1178 if (unlikely((l_ptr->flags & LINK_SYNCHING) && !msg_dup(msg))) {
1179 link_handle_out_of_seq_msg(l_ptr, skb);
1180 if (link_synch(l_ptr))
1181 link_retrieve_defq(l_ptr, &head);
1185 l_ptr->next_in_no++;
1186 if (unlikely(!skb_queue_empty(&l_ptr->deferdq)))
1187 link_retrieve_defq(l_ptr, &head);
1188 if (unlikely(++l_ptr->rcv_unacked >= TIPC_MIN_LINK_WIN)) {
1189 l_ptr->stats.sent_acks++;
1190 tipc_link_proto_xmit(l_ptr, STATE_MSG, 0, 0, 0, 0, 0);
1192 tipc_link_input(l_ptr, skb);
1195 tipc_node_unlock(n_ptr);
1196 tipc_node_put(n_ptr);
1203 /* tipc_data_input - deliver data and name distr msgs to upper layer
1205 * Consumes buffer if message is of right type
1206 * Node lock must be held
1208 static bool tipc_data_input(struct tipc_link *link, struct sk_buff *skb)
1210 struct tipc_node *node = link->owner;
1211 struct tipc_msg *msg = buf_msg(skb);
1212 u32 dport = msg_destport(msg);
1214 switch (msg_user(msg)) {
1215 case TIPC_LOW_IMPORTANCE:
1216 case TIPC_MEDIUM_IMPORTANCE:
1217 case TIPC_HIGH_IMPORTANCE:
1218 case TIPC_CRITICAL_IMPORTANCE:
1220 if (tipc_skb_queue_tail(&link->inputq, skb, dport)) {
1221 node->inputq = &link->inputq;
1222 node->action_flags |= TIPC_MSG_EVT;
1225 case NAME_DISTRIBUTOR:
1226 node->bclink.recv_permitted = true;
1227 node->namedq = &link->namedq;
1228 skb_queue_tail(&link->namedq, skb);
1229 if (skb_queue_len(&link->namedq) == 1)
1230 node->action_flags |= TIPC_NAMED_MSG_EVT;
1233 case TUNNEL_PROTOCOL:
1234 case MSG_FRAGMENTER:
1235 case BCAST_PROTOCOL:
1238 pr_warn("Dropping received illegal msg type\n");
1244 /* tipc_link_input - process packet that has passed link protocol check
1247 * Node lock must be held
1249 static void tipc_link_input(struct tipc_link *link, struct sk_buff *skb)
1251 struct tipc_node *node = link->owner;
1252 struct tipc_msg *msg = buf_msg(skb);
1253 struct sk_buff *iskb;
1256 if (likely(tipc_data_input(link, skb)))
1259 switch (msg_user(msg)) {
1260 case TUNNEL_PROTOCOL:
1262 link->flags |= LINK_SYNCHING;
1263 link->synch_point = msg_seqno(msg_get_wrapped(msg));
1267 if (!tipc_link_failover_rcv(link, &skb))
1269 if (msg_user(buf_msg(skb)) != MSG_BUNDLER) {
1270 tipc_data_input(link, skb);
1274 link->stats.recv_bundles++;
1275 link->stats.recv_bundled += msg_msgcnt(msg);
1277 while (tipc_msg_extract(skb, &iskb, &pos))
1278 tipc_data_input(link, iskb);
1280 case MSG_FRAGMENTER:
1281 link->stats.recv_fragments++;
1282 if (tipc_buf_append(&link->reasm_buf, &skb)) {
1283 link->stats.recv_fragmented++;
1284 tipc_data_input(link, skb);
1285 } else if (!link->reasm_buf) {
1286 tipc_link_reset(link);
1289 case BCAST_PROTOCOL:
1290 tipc_link_sync_rcv(node, skb);
1298 * tipc_link_defer_pkt - Add out-of-sequence message to deferred reception queue
1300 * Returns increase in queue length (i.e. 0 or 1)
1302 u32 tipc_link_defer_pkt(struct sk_buff_head *list, struct sk_buff *skb)
1304 struct sk_buff *skb1;
1305 u32 seq_no = buf_seqno(skb);
1308 if (skb_queue_empty(list)) {
1309 __skb_queue_tail(list, skb);
1314 if (less(buf_seqno(skb_peek_tail(list)), seq_no)) {
1315 __skb_queue_tail(list, skb);
1319 /* Locate insertion point in queue, then insert; discard if duplicate */
1320 skb_queue_walk(list, skb1) {
1321 u32 curr_seqno = buf_seqno(skb1);
1323 if (seq_no == curr_seqno) {
1328 if (less(seq_no, curr_seqno))
1332 __skb_queue_before(list, skb1, skb);
1337 * link_handle_out_of_seq_msg - handle arrival of out-of-sequence packet
1339 static void link_handle_out_of_seq_msg(struct tipc_link *l_ptr,
1340 struct sk_buff *buf)
1342 u32 seq_no = buf_seqno(buf);
1344 if (likely(msg_user(buf_msg(buf)) == LINK_PROTOCOL)) {
1345 tipc_link_proto_rcv(l_ptr, buf);
1349 /* Record OOS packet arrival (force mismatch on next timeout) */
1350 l_ptr->checkpoint--;
1353 * Discard packet if a duplicate; otherwise add it to deferred queue
1354 * and notify peer of gap as per protocol specification
1356 if (less(seq_no, mod(l_ptr->next_in_no))) {
1357 l_ptr->stats.duplicates++;
1362 if (tipc_link_defer_pkt(&l_ptr->deferdq, buf)) {
1363 l_ptr->stats.deferred_recv++;
1364 if ((skb_queue_len(&l_ptr->deferdq) % TIPC_MIN_LINK_WIN) == 1)
1365 tipc_link_proto_xmit(l_ptr, STATE_MSG, 0, 0, 0, 0, 0);
1367 l_ptr->stats.duplicates++;
1372 * Send protocol message to the other endpoint.
1374 void tipc_link_proto_xmit(struct tipc_link *l_ptr, u32 msg_typ, int probe_msg,
1375 u32 gap, u32 tolerance, u32 priority, u32 ack_mtu)
1377 struct sk_buff *buf = NULL;
1378 struct tipc_msg *msg = l_ptr->pmsg;
1379 u32 msg_size = sizeof(l_ptr->proto_msg);
1382 /* Don't send protocol message during link failover */
1383 if (l_ptr->flags & LINK_FAILINGOVER)
1386 /* Abort non-RESET send if communication with node is prohibited */
1387 if ((tipc_node_blocked(l_ptr->owner)) && (msg_typ != RESET_MSG))
1390 /* Create protocol message with "out-of-sequence" sequence number */
1391 msg_set_type(msg, msg_typ);
1392 msg_set_net_plane(msg, l_ptr->net_plane);
1393 msg_set_bcast_ack(msg, l_ptr->owner->bclink.last_in);
1394 msg_set_last_bcast(msg, tipc_bclink_get_last_sent(l_ptr->owner->net));
1396 if (msg_typ == STATE_MSG) {
1397 u32 next_sent = mod(l_ptr->next_out_no);
1399 if (!tipc_link_is_up(l_ptr))
1401 if (skb_queue_len(&l_ptr->backlogq))
1402 next_sent = buf_seqno(skb_peek(&l_ptr->backlogq));
1403 msg_set_next_sent(msg, next_sent);
1404 if (!skb_queue_empty(&l_ptr->deferdq)) {
1405 u32 rec = buf_seqno(skb_peek(&l_ptr->deferdq));
1406 gap = mod(rec - mod(l_ptr->next_in_no));
1408 msg_set_seq_gap(msg, gap);
1410 l_ptr->stats.sent_nacks++;
1411 msg_set_link_tolerance(msg, tolerance);
1412 msg_set_linkprio(msg, priority);
1413 msg_set_max_pkt(msg, ack_mtu);
1414 msg_set_ack(msg, mod(l_ptr->next_in_no - 1));
1415 msg_set_probe(msg, probe_msg != 0);
1417 u32 mtu = l_ptr->max_pkt;
1419 if ((mtu < l_ptr->max_pkt_target) &&
1420 link_working_working(l_ptr) &&
1421 l_ptr->fsm_msg_cnt) {
1422 msg_size = (mtu + (l_ptr->max_pkt_target - mtu)/2 + 2) & ~3;
1423 if (l_ptr->max_pkt_probes == 10) {
1424 l_ptr->max_pkt_target = (msg_size - 4);
1425 l_ptr->max_pkt_probes = 0;
1426 msg_size = (mtu + (l_ptr->max_pkt_target - mtu)/2 + 2) & ~3;
1428 l_ptr->max_pkt_probes++;
1431 l_ptr->stats.sent_probes++;
1433 l_ptr->stats.sent_states++;
1434 } else { /* RESET_MSG or ACTIVATE_MSG */
1435 msg_set_ack(msg, mod(l_ptr->failover_checkpt - 1));
1436 msg_set_seq_gap(msg, 0);
1437 msg_set_next_sent(msg, 1);
1438 msg_set_probe(msg, 0);
1439 msg_set_link_tolerance(msg, l_ptr->tolerance);
1440 msg_set_linkprio(msg, l_ptr->priority);
1441 msg_set_max_pkt(msg, l_ptr->max_pkt_target);
1444 r_flag = (l_ptr->owner->working_links > tipc_link_is_up(l_ptr));
1445 msg_set_redundant_link(msg, r_flag);
1446 msg_set_linkprio(msg, l_ptr->priority);
1447 msg_set_size(msg, msg_size);
1449 msg_set_seqno(msg, mod(l_ptr->next_out_no + (0xffff/2)));
1451 buf = tipc_buf_acquire(msg_size);
1455 skb_copy_to_linear_data(buf, msg, sizeof(l_ptr->proto_msg));
1456 buf->priority = TC_PRIO_CONTROL;
1457 tipc_bearer_send(l_ptr->owner->net, l_ptr->bearer_id, buf,
1458 &l_ptr->media_addr);
1459 l_ptr->rcv_unacked = 0;
1464 * Receive protocol message :
1465 * Note that network plane id propagates through the network, and may
1466 * change at any time. The node with lowest address rules
1468 static void tipc_link_proto_rcv(struct tipc_link *l_ptr,
1469 struct sk_buff *buf)
1475 struct tipc_msg *msg = buf_msg(buf);
1477 if (l_ptr->flags & LINK_FAILINGOVER)
1480 if (l_ptr->net_plane != msg_net_plane(msg))
1481 if (link_own_addr(l_ptr) > msg_prevnode(msg))
1482 l_ptr->net_plane = msg_net_plane(msg);
1484 switch (msg_type(msg)) {
1487 if (!link_working_unknown(l_ptr) &&
1488 (l_ptr->peer_session != INVALID_SESSION)) {
1489 if (less_eq(msg_session(msg), l_ptr->peer_session))
1490 break; /* duplicate or old reset: ignore */
1493 if (!msg_redundant_link(msg) && (link_working_working(l_ptr) ||
1494 link_working_unknown(l_ptr))) {
1496 * peer has lost contact -- don't allow peer's links
1497 * to reactivate before we recognize loss & clean up
1499 l_ptr->owner->action_flags |= TIPC_WAIT_OWN_LINKS_DOWN;
1502 link_state_event(l_ptr, RESET_MSG);
1506 /* Update link settings according other endpoint's values */
1507 strcpy((strrchr(l_ptr->name, ':') + 1), (char *)msg_data(msg));
1509 msg_tol = msg_link_tolerance(msg);
1510 if (msg_tol > l_ptr->tolerance)
1511 link_set_supervision_props(l_ptr, msg_tol);
1513 if (msg_linkprio(msg) > l_ptr->priority)
1514 l_ptr->priority = msg_linkprio(msg);
1516 max_pkt_info = msg_max_pkt(msg);
1518 if (max_pkt_info < l_ptr->max_pkt_target)
1519 l_ptr->max_pkt_target = max_pkt_info;
1520 if (l_ptr->max_pkt > l_ptr->max_pkt_target)
1521 l_ptr->max_pkt = l_ptr->max_pkt_target;
1523 l_ptr->max_pkt = l_ptr->max_pkt_target;
1526 /* Synchronize broadcast link info, if not done previously */
1527 if (!tipc_node_is_up(l_ptr->owner)) {
1528 l_ptr->owner->bclink.last_sent =
1529 l_ptr->owner->bclink.last_in =
1530 msg_last_bcast(msg);
1531 l_ptr->owner->bclink.oos_state = 0;
1534 l_ptr->peer_session = msg_session(msg);
1535 l_ptr->peer_bearer_id = msg_bearer_id(msg);
1537 if (msg_type(msg) == ACTIVATE_MSG)
1538 link_state_event(l_ptr, ACTIVATE_MSG);
1542 msg_tol = msg_link_tolerance(msg);
1544 link_set_supervision_props(l_ptr, msg_tol);
1546 if (msg_linkprio(msg) &&
1547 (msg_linkprio(msg) != l_ptr->priority)) {
1548 pr_debug("%s<%s>, priority change %u->%u\n",
1549 link_rst_msg, l_ptr->name,
1550 l_ptr->priority, msg_linkprio(msg));
1551 l_ptr->priority = msg_linkprio(msg);
1552 tipc_link_reset(l_ptr); /* Enforce change to take effect */
1556 /* Record reception; force mismatch at next timeout: */
1557 l_ptr->checkpoint--;
1559 link_state_event(l_ptr, TRAFFIC_MSG_EVT);
1560 l_ptr->stats.recv_states++;
1561 if (link_reset_unknown(l_ptr))
1564 if (less_eq(mod(l_ptr->next_in_no), msg_next_sent(msg))) {
1565 rec_gap = mod(msg_next_sent(msg) -
1566 mod(l_ptr->next_in_no));
1569 max_pkt_ack = msg_max_pkt(msg);
1570 if (max_pkt_ack > l_ptr->max_pkt) {
1571 l_ptr->max_pkt = max_pkt_ack;
1572 l_ptr->max_pkt_probes = 0;
1576 if (msg_probe(msg)) {
1577 l_ptr->stats.recv_probes++;
1578 if (msg_size(msg) > sizeof(l_ptr->proto_msg))
1579 max_pkt_ack = msg_size(msg);
1582 /* Protocol message before retransmits, reduce loss risk */
1583 if (l_ptr->owner->bclink.recv_permitted)
1584 tipc_bclink_update_link_state(l_ptr->owner,
1585 msg_last_bcast(msg));
1587 if (rec_gap || (msg_probe(msg))) {
1588 tipc_link_proto_xmit(l_ptr, STATE_MSG, 0, rec_gap, 0,
1591 if (msg_seq_gap(msg)) {
1592 l_ptr->stats.recv_nacks++;
1593 tipc_link_retransmit(l_ptr, skb_peek(&l_ptr->transmq),
1603 /* tipc_link_tunnel_xmit(): Tunnel one packet via a link belonging to
1604 * a different bearer. Owner node is locked.
1606 static void tipc_link_tunnel_xmit(struct tipc_link *l_ptr,
1607 struct tipc_msg *tunnel_hdr,
1608 struct tipc_msg *msg,
1611 struct tipc_link *tunnel;
1612 struct sk_buff *skb;
1613 u32 length = msg_size(msg);
1615 tunnel = l_ptr->owner->active_links[selector & 1];
1616 if (!tipc_link_is_up(tunnel)) {
1617 pr_warn("%stunnel link no longer available\n", link_co_err);
1620 msg_set_size(tunnel_hdr, length + INT_H_SIZE);
1621 skb = tipc_buf_acquire(length + INT_H_SIZE);
1623 pr_warn("%sunable to send tunnel msg\n", link_co_err);
1626 skb_copy_to_linear_data(skb, tunnel_hdr, INT_H_SIZE);
1627 skb_copy_to_linear_data_offset(skb, INT_H_SIZE, msg, length);
1628 __tipc_link_xmit_skb(tunnel, skb);
1632 /* tipc_link_failover_send_queue(): A link has gone down, but a second
1633 * link is still active. We can do failover. Tunnel the failing link's
1634 * whole send queue via the remaining link. This way, we don't lose
1635 * any packets, and sequence order is preserved for subsequent traffic
1636 * sent over the remaining link. Owner node is locked.
1638 void tipc_link_failover_send_queue(struct tipc_link *l_ptr)
1641 struct tipc_link *tunnel = l_ptr->owner->active_links[0];
1642 struct tipc_msg tunnel_hdr;
1643 struct sk_buff *skb;
1649 tipc_msg_init(link_own_addr(l_ptr), &tunnel_hdr, TUNNEL_PROTOCOL,
1650 FAILOVER_MSG, INT_H_SIZE, l_ptr->addr);
1651 skb_queue_splice_tail_init(&l_ptr->backlogq, &l_ptr->transmq);
1652 tipc_link_purge_backlog(l_ptr);
1653 msgcount = skb_queue_len(&l_ptr->transmq);
1654 msg_set_bearer_id(&tunnel_hdr, l_ptr->peer_bearer_id);
1655 msg_set_msgcnt(&tunnel_hdr, msgcount);
1657 if (skb_queue_empty(&l_ptr->transmq)) {
1658 skb = tipc_buf_acquire(INT_H_SIZE);
1660 skb_copy_to_linear_data(skb, &tunnel_hdr, INT_H_SIZE);
1661 msg_set_size(&tunnel_hdr, INT_H_SIZE);
1662 __tipc_link_xmit_skb(tunnel, skb);
1664 pr_warn("%sunable to send changeover msg\n",
1670 split_bundles = (l_ptr->owner->active_links[0] !=
1671 l_ptr->owner->active_links[1]);
1673 skb_queue_walk(&l_ptr->transmq, skb) {
1674 struct tipc_msg *msg = buf_msg(skb);
1676 if ((msg_user(msg) == MSG_BUNDLER) && split_bundles) {
1677 struct tipc_msg *m = msg_get_wrapped(msg);
1678 unchar *pos = (unchar *)m;
1680 msgcount = msg_msgcnt(msg);
1681 while (msgcount--) {
1682 msg_set_seqno(m, msg_seqno(msg));
1683 tipc_link_tunnel_xmit(l_ptr, &tunnel_hdr, m,
1684 msg_link_selector(m));
1685 pos += align(msg_size(m));
1686 m = (struct tipc_msg *)pos;
1689 tipc_link_tunnel_xmit(l_ptr, &tunnel_hdr, msg,
1690 msg_link_selector(msg));
1695 /* tipc_link_dup_queue_xmit(): A second link has become active. Tunnel a
1696 * duplicate of the first link's send queue via the new link. This way, we
1697 * are guaranteed that currently queued packets from a socket are delivered
1698 * before future traffic from the same socket, even if this is using the
1699 * new link. The last arriving copy of each duplicate packet is dropped at
1700 * the receiving end by the regular protocol check, so packet cardinality
1701 * and sequence order is preserved per sender/receiver socket pair.
1702 * Owner node is locked.
1704 void tipc_link_dup_queue_xmit(struct tipc_link *link,
1705 struct tipc_link *tnl)
1707 struct sk_buff *skb;
1708 struct tipc_msg tnl_hdr;
1709 struct sk_buff_head *queue = &link->transmq;
1712 tipc_msg_init(link_own_addr(link), &tnl_hdr, TUNNEL_PROTOCOL,
1713 SYNCH_MSG, INT_H_SIZE, link->addr);
1714 mcnt = skb_queue_len(&link->transmq) + skb_queue_len(&link->backlogq);
1715 msg_set_msgcnt(&tnl_hdr, mcnt);
1716 msg_set_bearer_id(&tnl_hdr, link->peer_bearer_id);
1719 skb_queue_walk(queue, skb) {
1720 struct sk_buff *outskb;
1721 struct tipc_msg *msg = buf_msg(skb);
1722 u32 len = msg_size(msg);
1724 msg_set_ack(msg, mod(link->next_in_no - 1));
1725 msg_set_bcast_ack(msg, link->owner->bclink.last_in);
1726 msg_set_size(&tnl_hdr, len + INT_H_SIZE);
1727 outskb = tipc_buf_acquire(len + INT_H_SIZE);
1728 if (outskb == NULL) {
1729 pr_warn("%sunable to send duplicate msg\n",
1733 skb_copy_to_linear_data(outskb, &tnl_hdr, INT_H_SIZE);
1734 skb_copy_to_linear_data_offset(outskb, INT_H_SIZE,
1736 __tipc_link_xmit_skb(tnl, outskb);
1737 if (!tipc_link_is_up(link))
1740 if (queue == &link->backlogq)
1742 queue = &link->backlogq;
1746 /* tipc_link_failover_rcv(): Receive a tunnelled FAILOVER_MSG packet
1747 * Owner node is locked.
1749 static bool tipc_link_failover_rcv(struct tipc_link *link,
1750 struct sk_buff **skb)
1752 struct tipc_msg *msg = buf_msg(*skb);
1753 struct sk_buff *iskb = NULL;
1754 struct tipc_link *pl = NULL;
1755 int bearer_id = msg_bearer_id(msg);
1758 if (msg_type(msg) != FAILOVER_MSG) {
1759 pr_warn("%sunknown tunnel pkt received\n", link_co_err);
1762 if (bearer_id >= MAX_BEARERS)
1765 if (bearer_id == link->bearer_id)
1768 pl = link->owner->links[bearer_id];
1769 if (pl && tipc_link_is_up(pl))
1770 tipc_link_reset(pl);
1772 if (link->failover_pkts == FIRST_FAILOVER)
1773 link->failover_pkts = msg_msgcnt(msg);
1775 /* Should we expect an inner packet? */
1776 if (!link->failover_pkts)
1779 if (!tipc_msg_extract(*skb, &iskb, &pos)) {
1780 pr_warn("%sno inner failover pkt\n", link_co_err);
1784 link->failover_pkts--;
1787 /* Was this packet already delivered? */
1788 if (less(buf_seqno(iskb), link->failover_checkpt)) {
1793 if (msg_user(buf_msg(iskb)) == MSG_FRAGMENTER) {
1794 link->stats.recv_fragments++;
1795 tipc_buf_append(&link->failover_skb, &iskb);
1798 if (!link->failover_pkts && pl)
1799 pl->flags &= ~LINK_FAILINGOVER;
1805 static void link_set_supervision_props(struct tipc_link *l_ptr, u32 tol)
1807 unsigned long intv = ((tol / 4) > 500) ? 500 : tol / 4;
1809 if ((tol < TIPC_MIN_LINK_TOL) || (tol > TIPC_MAX_LINK_TOL))
1812 l_ptr->tolerance = tol;
1813 l_ptr->cont_intv = msecs_to_jiffies(intv);
1814 l_ptr->abort_limit = tol / (jiffies_to_msecs(l_ptr->cont_intv) / 4);
1817 void tipc_link_set_queue_limits(struct tipc_link *l, u32 win)
1819 int max_bulk = TIPC_MAX_PUBLICATIONS / (l->max_pkt / ITEM_SIZE);
1822 l->backlog[TIPC_LOW_IMPORTANCE].limit = win / 2;
1823 l->backlog[TIPC_MEDIUM_IMPORTANCE].limit = win;
1824 l->backlog[TIPC_HIGH_IMPORTANCE].limit = win / 2 * 3;
1825 l->backlog[TIPC_CRITICAL_IMPORTANCE].limit = win * 2;
1826 l->backlog[TIPC_SYSTEM_IMPORTANCE].limit = max_bulk;
1829 /* tipc_link_find_owner - locate owner node of link by link's name
1830 * @net: the applicable net namespace
1831 * @name: pointer to link name string
1832 * @bearer_id: pointer to index in 'node->links' array where the link was found.
1834 * Returns pointer to node owning the link, or 0 if no matching link is found.
1836 static struct tipc_node *tipc_link_find_owner(struct net *net,
1837 const char *link_name,
1838 unsigned int *bearer_id)
1840 struct tipc_net *tn = net_generic(net, tipc_net_id);
1841 struct tipc_link *l_ptr;
1842 struct tipc_node *n_ptr;
1843 struct tipc_node *found_node = NULL;
1848 list_for_each_entry_rcu(n_ptr, &tn->node_list, list) {
1849 tipc_node_lock(n_ptr);
1850 for (i = 0; i < MAX_BEARERS; i++) {
1851 l_ptr = n_ptr->links[i];
1852 if (l_ptr && !strcmp(l_ptr->name, link_name)) {
1858 tipc_node_unlock(n_ptr);
1868 * link_reset_statistics - reset link statistics
1869 * @l_ptr: pointer to link
1871 static void link_reset_statistics(struct tipc_link *l_ptr)
1873 memset(&l_ptr->stats, 0, sizeof(l_ptr->stats));
1874 l_ptr->stats.sent_info = l_ptr->next_out_no;
1875 l_ptr->stats.recv_info = l_ptr->next_in_no;
1878 static void link_print(struct tipc_link *l_ptr, const char *str)
1880 struct tipc_net *tn = net_generic(l_ptr->owner->net, tipc_net_id);
1881 struct tipc_bearer *b_ptr;
1884 b_ptr = rcu_dereference_rtnl(tn->bearer_list[l_ptr->bearer_id]);
1886 pr_info("%s Link %x<%s>:", str, l_ptr->addr, b_ptr->name);
1889 if (link_working_unknown(l_ptr))
1891 else if (link_reset_reset(l_ptr))
1893 else if (link_reset_unknown(l_ptr))
1895 else if (link_working_working(l_ptr))
1901 /* Parse and validate nested (link) properties valid for media, bearer and link
1903 int tipc_nl_parse_link_prop(struct nlattr *prop, struct nlattr *props[])
1907 err = nla_parse_nested(props, TIPC_NLA_PROP_MAX, prop,
1908 tipc_nl_prop_policy);
1912 if (props[TIPC_NLA_PROP_PRIO]) {
1915 prio = nla_get_u32(props[TIPC_NLA_PROP_PRIO]);
1916 if (prio > TIPC_MAX_LINK_PRI)
1920 if (props[TIPC_NLA_PROP_TOL]) {
1923 tol = nla_get_u32(props[TIPC_NLA_PROP_TOL]);
1924 if ((tol < TIPC_MIN_LINK_TOL) || (tol > TIPC_MAX_LINK_TOL))
1928 if (props[TIPC_NLA_PROP_WIN]) {
1931 win = nla_get_u32(props[TIPC_NLA_PROP_WIN]);
1932 if ((win < TIPC_MIN_LINK_WIN) || (win > TIPC_MAX_LINK_WIN))
1939 int tipc_nl_link_set(struct sk_buff *skb, struct genl_info *info)
1945 struct tipc_link *link;
1946 struct tipc_node *node;
1947 struct nlattr *attrs[TIPC_NLA_LINK_MAX + 1];
1948 struct net *net = sock_net(skb->sk);
1950 if (!info->attrs[TIPC_NLA_LINK])
1953 err = nla_parse_nested(attrs, TIPC_NLA_LINK_MAX,
1954 info->attrs[TIPC_NLA_LINK],
1955 tipc_nl_link_policy);
1959 if (!attrs[TIPC_NLA_LINK_NAME])
1962 name = nla_data(attrs[TIPC_NLA_LINK_NAME]);
1964 node = tipc_link_find_owner(net, name, &bearer_id);
1968 tipc_node_lock(node);
1970 link = node->links[bearer_id];
1976 if (attrs[TIPC_NLA_LINK_PROP]) {
1977 struct nlattr *props[TIPC_NLA_PROP_MAX + 1];
1979 err = tipc_nl_parse_link_prop(attrs[TIPC_NLA_LINK_PROP],
1986 if (props[TIPC_NLA_PROP_TOL]) {
1989 tol = nla_get_u32(props[TIPC_NLA_PROP_TOL]);
1990 link_set_supervision_props(link, tol);
1991 tipc_link_proto_xmit(link, STATE_MSG, 0, 0, tol, 0, 0);
1993 if (props[TIPC_NLA_PROP_PRIO]) {
1996 prio = nla_get_u32(props[TIPC_NLA_PROP_PRIO]);
1997 link->priority = prio;
1998 tipc_link_proto_xmit(link, STATE_MSG, 0, 0, 0, prio, 0);
2000 if (props[TIPC_NLA_PROP_WIN]) {
2003 win = nla_get_u32(props[TIPC_NLA_PROP_WIN]);
2004 tipc_link_set_queue_limits(link, win);
2009 tipc_node_unlock(node);
2014 static int __tipc_nl_add_stats(struct sk_buff *skb, struct tipc_stats *s)
2017 struct nlattr *stats;
2024 struct nla_map map[] = {
2025 {TIPC_NLA_STATS_RX_INFO, s->recv_info},
2026 {TIPC_NLA_STATS_RX_FRAGMENTS, s->recv_fragments},
2027 {TIPC_NLA_STATS_RX_FRAGMENTED, s->recv_fragmented},
2028 {TIPC_NLA_STATS_RX_BUNDLES, s->recv_bundles},
2029 {TIPC_NLA_STATS_RX_BUNDLED, s->recv_bundled},
2030 {TIPC_NLA_STATS_TX_INFO, s->sent_info},
2031 {TIPC_NLA_STATS_TX_FRAGMENTS, s->sent_fragments},
2032 {TIPC_NLA_STATS_TX_FRAGMENTED, s->sent_fragmented},
2033 {TIPC_NLA_STATS_TX_BUNDLES, s->sent_bundles},
2034 {TIPC_NLA_STATS_TX_BUNDLED, s->sent_bundled},
2035 {TIPC_NLA_STATS_MSG_PROF_TOT, (s->msg_length_counts) ?
2036 s->msg_length_counts : 1},
2037 {TIPC_NLA_STATS_MSG_LEN_CNT, s->msg_length_counts},
2038 {TIPC_NLA_STATS_MSG_LEN_TOT, s->msg_lengths_total},
2039 {TIPC_NLA_STATS_MSG_LEN_P0, s->msg_length_profile[0]},
2040 {TIPC_NLA_STATS_MSG_LEN_P1, s->msg_length_profile[1]},
2041 {TIPC_NLA_STATS_MSG_LEN_P2, s->msg_length_profile[2]},
2042 {TIPC_NLA_STATS_MSG_LEN_P3, s->msg_length_profile[3]},
2043 {TIPC_NLA_STATS_MSG_LEN_P4, s->msg_length_profile[4]},
2044 {TIPC_NLA_STATS_MSG_LEN_P5, s->msg_length_profile[5]},
2045 {TIPC_NLA_STATS_MSG_LEN_P6, s->msg_length_profile[6]},
2046 {TIPC_NLA_STATS_RX_STATES, s->recv_states},
2047 {TIPC_NLA_STATS_RX_PROBES, s->recv_probes},
2048 {TIPC_NLA_STATS_RX_NACKS, s->recv_nacks},
2049 {TIPC_NLA_STATS_RX_DEFERRED, s->deferred_recv},
2050 {TIPC_NLA_STATS_TX_STATES, s->sent_states},
2051 {TIPC_NLA_STATS_TX_PROBES, s->sent_probes},
2052 {TIPC_NLA_STATS_TX_NACKS, s->sent_nacks},
2053 {TIPC_NLA_STATS_TX_ACKS, s->sent_acks},
2054 {TIPC_NLA_STATS_RETRANSMITTED, s->retransmitted},
2055 {TIPC_NLA_STATS_DUPLICATES, s->duplicates},
2056 {TIPC_NLA_STATS_LINK_CONGS, s->link_congs},
2057 {TIPC_NLA_STATS_MAX_QUEUE, s->max_queue_sz},
2058 {TIPC_NLA_STATS_AVG_QUEUE, s->queue_sz_counts ?
2059 (s->accu_queue_sz / s->queue_sz_counts) : 0}
2062 stats = nla_nest_start(skb, TIPC_NLA_LINK_STATS);
2066 for (i = 0; i < ARRAY_SIZE(map); i++)
2067 if (nla_put_u32(skb, map[i].key, map[i].val))
2070 nla_nest_end(skb, stats);
2074 nla_nest_cancel(skb, stats);
2079 /* Caller should hold appropriate locks to protect the link */
2080 static int __tipc_nl_add_link(struct net *net, struct tipc_nl_msg *msg,
2081 struct tipc_link *link)
2085 struct nlattr *attrs;
2086 struct nlattr *prop;
2087 struct tipc_net *tn = net_generic(net, tipc_net_id);
2089 hdr = genlmsg_put(msg->skb, msg->portid, msg->seq, &tipc_genl_family,
2090 NLM_F_MULTI, TIPC_NL_LINK_GET);
2094 attrs = nla_nest_start(msg->skb, TIPC_NLA_LINK);
2098 if (nla_put_string(msg->skb, TIPC_NLA_LINK_NAME, link->name))
2100 if (nla_put_u32(msg->skb, TIPC_NLA_LINK_DEST,
2101 tipc_cluster_mask(tn->own_addr)))
2103 if (nla_put_u32(msg->skb, TIPC_NLA_LINK_MTU, link->max_pkt))
2105 if (nla_put_u32(msg->skb, TIPC_NLA_LINK_RX, link->next_in_no))
2107 if (nla_put_u32(msg->skb, TIPC_NLA_LINK_TX, link->next_out_no))
2110 if (tipc_link_is_up(link))
2111 if (nla_put_flag(msg->skb, TIPC_NLA_LINK_UP))
2113 if (tipc_link_is_active(link))
2114 if (nla_put_flag(msg->skb, TIPC_NLA_LINK_ACTIVE))
2117 prop = nla_nest_start(msg->skb, TIPC_NLA_LINK_PROP);
2120 if (nla_put_u32(msg->skb, TIPC_NLA_PROP_PRIO, link->priority))
2122 if (nla_put_u32(msg->skb, TIPC_NLA_PROP_TOL, link->tolerance))
2124 if (nla_put_u32(msg->skb, TIPC_NLA_PROP_WIN,
2127 if (nla_put_u32(msg->skb, TIPC_NLA_PROP_PRIO, link->priority))
2129 nla_nest_end(msg->skb, prop);
2131 err = __tipc_nl_add_stats(msg->skb, &link->stats);
2135 nla_nest_end(msg->skb, attrs);
2136 genlmsg_end(msg->skb, hdr);
2141 nla_nest_cancel(msg->skb, prop);
2143 nla_nest_cancel(msg->skb, attrs);
2145 genlmsg_cancel(msg->skb, hdr);
2150 /* Caller should hold node lock */
2151 static int __tipc_nl_add_node_links(struct net *net, struct tipc_nl_msg *msg,
2152 struct tipc_node *node, u32 *prev_link)
2157 for (i = *prev_link; i < MAX_BEARERS; i++) {
2160 if (!node->links[i])
2163 err = __tipc_nl_add_link(net, msg, node->links[i]);
2172 int tipc_nl_link_dump(struct sk_buff *skb, struct netlink_callback *cb)
2174 struct net *net = sock_net(skb->sk);
2175 struct tipc_net *tn = net_generic(net, tipc_net_id);
2176 struct tipc_node *node;
2177 struct tipc_nl_msg msg;
2178 u32 prev_node = cb->args[0];
2179 u32 prev_link = cb->args[1];
2180 int done = cb->args[2];
2187 msg.portid = NETLINK_CB(cb->skb).portid;
2188 msg.seq = cb->nlh->nlmsg_seq;
2192 node = tipc_node_find(net, prev_node);
2194 /* We never set seq or call nl_dump_check_consistent()
2195 * this means that setting prev_seq here will cause the
2196 * consistence check to fail in the netlink callback
2197 * handler. Resulting in the last NLMSG_DONE message
2198 * having the NLM_F_DUMP_INTR flag set.
2203 tipc_node_put(node);
2205 list_for_each_entry_continue_rcu(node, &tn->node_list,
2207 tipc_node_lock(node);
2208 err = __tipc_nl_add_node_links(net, &msg, node,
2210 tipc_node_unlock(node);
2211 tipc_node_put(node);
2215 prev_node = node->addr;
2218 err = tipc_nl_add_bc_link(net, &msg);
2222 list_for_each_entry_rcu(node, &tn->node_list, list) {
2223 tipc_node_lock(node);
2224 err = __tipc_nl_add_node_links(net, &msg, node,
2226 tipc_node_unlock(node);
2230 prev_node = node->addr;
2237 cb->args[0] = prev_node;
2238 cb->args[1] = prev_link;
2244 int tipc_nl_link_get(struct sk_buff *skb, struct genl_info *info)
2246 struct net *net = genl_info_net(info);
2247 struct sk_buff *ans_skb;
2248 struct tipc_nl_msg msg;
2249 struct tipc_link *link;
2250 struct tipc_node *node;
2255 if (!info->attrs[TIPC_NLA_LINK_NAME])
2258 name = nla_data(info->attrs[TIPC_NLA_LINK_NAME]);
2259 node = tipc_link_find_owner(net, name, &bearer_id);
2263 ans_skb = nlmsg_new(NLMSG_GOODSIZE, GFP_KERNEL);
2268 msg.portid = info->snd_portid;
2269 msg.seq = info->snd_seq;
2271 tipc_node_lock(node);
2272 link = node->links[bearer_id];
2278 err = __tipc_nl_add_link(net, &msg, link);
2282 tipc_node_unlock(node);
2284 return genlmsg_reply(ans_skb, info);
2287 tipc_node_unlock(node);
2288 nlmsg_free(ans_skb);
2293 int tipc_nl_link_reset_stats(struct sk_buff *skb, struct genl_info *info)
2297 unsigned int bearer_id;
2298 struct tipc_link *link;
2299 struct tipc_node *node;
2300 struct nlattr *attrs[TIPC_NLA_LINK_MAX + 1];
2301 struct net *net = sock_net(skb->sk);
2303 if (!info->attrs[TIPC_NLA_LINK])
2306 err = nla_parse_nested(attrs, TIPC_NLA_LINK_MAX,
2307 info->attrs[TIPC_NLA_LINK],
2308 tipc_nl_link_policy);
2312 if (!attrs[TIPC_NLA_LINK_NAME])
2315 link_name = nla_data(attrs[TIPC_NLA_LINK_NAME]);
2317 if (strcmp(link_name, tipc_bclink_name) == 0) {
2318 err = tipc_bclink_reset_stats(net);
2324 node = tipc_link_find_owner(net, link_name, &bearer_id);
2328 tipc_node_lock(node);
2330 link = node->links[bearer_id];
2332 tipc_node_unlock(node);
2336 link_reset_statistics(link);
2338 tipc_node_unlock(node);