2 * net/tipc/group.c: TIPC group messaging code
4 * Copyright (c) 2017, Ericsson AB
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions are met:
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
15 * 3. Neither the names of the copyright holders nor the names of its
16 * contributors may be used to endorse or promote products derived from
17 * this software without specific prior written permission.
19 * Alternatively, this software may be distributed under the terms of the
20 * GNU General Public License ("GPL") version 2 as published by the Free
21 * Software Foundation.
23 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
24 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
25 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
26 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
27 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
28 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
29 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
30 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
31 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
32 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
33 * POSSIBILITY OF SUCH DAMAGE.
44 #include "name_table.h"
47 #define ADV_UNIT (((MAX_MSG_SIZE + MAX_H_SIZE) / FLOWCTL_BLK_SZ) + 1)
48 #define ADV_IDLE ADV_UNIT
49 #define ADV_ACTIVE (ADV_UNIT * 12)
63 struct rb_node tree_node
;
64 struct list_head list
;
65 struct list_head small_win
;
66 struct sk_buff_head deferredq
;
67 struct tipc_group
*group
;
80 struct rb_root members
;
81 struct list_head small_win
;
82 struct list_head pending
;
83 struct list_head active
;
84 struct tipc_nlist dests
;
101 static void tipc_group_proto_xmit(struct tipc_group
*grp
, struct tipc_member
*m
,
102 int mtyp
, struct sk_buff_head
*xmitq
);
104 static void tipc_group_open(struct tipc_member
*m
, bool *wakeup
)
107 if (list_empty(&m
->small_win
))
109 list_del_init(&m
->small_win
);
110 *m
->group
->open
= true;
114 static void tipc_group_decr_active(struct tipc_group
*grp
,
115 struct tipc_member
*m
)
117 if (m
->state
== MBR_ACTIVE
|| m
->state
== MBR_RECLAIMING
||
118 m
->state
== MBR_REMITTED
)
122 static int tipc_group_rcvbuf_limit(struct tipc_group
*grp
)
124 int max_active
, active_pool
, idle_pool
;
125 int mcnt
= grp
->member_cnt
+ 1;
127 /* Limit simultaneous reception from other members */
128 max_active
= min(mcnt
/ 8, 64);
129 max_active
= max(max_active
, 16);
130 grp
->max_active
= max_active
;
132 /* Reserve blocks for active and idle members */
133 active_pool
= max_active
* ADV_ACTIVE
;
134 idle_pool
= (mcnt
- max_active
) * ADV_IDLE
;
136 /* Scale to bytes, considering worst-case truesize/msgsize ratio */
137 return (active_pool
+ idle_pool
) * FLOWCTL_BLK_SZ
* 4;
140 u16
tipc_group_bc_snd_nxt(struct tipc_group
*grp
)
142 return grp
->bc_snd_nxt
;
145 static bool tipc_group_is_receiver(struct tipc_member
*m
)
147 return m
&& m
->state
!= MBR_JOINING
&& m
->state
!= MBR_LEAVING
;
150 static bool tipc_group_is_sender(struct tipc_member
*m
)
152 return m
&& m
->state
!= MBR_JOINING
&& m
->state
!= MBR_PUBLISHED
;
155 u32
tipc_group_exclude(struct tipc_group
*grp
)
162 int tipc_group_size(struct tipc_group
*grp
)
164 return grp
->member_cnt
;
167 struct tipc_group
*tipc_group_create(struct net
*net
, u32 portid
,
168 struct tipc_group_req
*mreq
,
171 u32 filter
= TIPC_SUB_PORTS
| TIPC_SUB_NO_STATUS
;
172 bool global
= mreq
->scope
!= TIPC_NODE_SCOPE
;
173 struct tipc_group
*grp
;
174 u32 type
= mreq
->type
;
176 grp
= kzalloc(sizeof(*grp
), GFP_ATOMIC
);
179 tipc_nlist_init(&grp
->dests
, tipc_own_addr(net
));
180 INIT_LIST_HEAD(&grp
->small_win
);
181 INIT_LIST_HEAD(&grp
->active
);
182 INIT_LIST_HEAD(&grp
->pending
);
183 grp
->members
= RB_ROOT
;
185 grp
->portid
= portid
;
187 grp
->instance
= mreq
->instance
;
188 grp
->scope
= mreq
->scope
;
189 grp
->loopback
= mreq
->flags
& TIPC_GROUP_LOOPBACK
;
190 grp
->events
= mreq
->flags
& TIPC_GROUP_MEMBER_EVTS
;
191 grp
->open
= group_is_open
;
193 filter
|= global
? TIPC_SUB_CLUSTER_SCOPE
: TIPC_SUB_NODE_SCOPE
;
194 if (tipc_topsrv_kern_subscr(net
, portid
, type
, 0, ~0,
195 filter
, &grp
->subid
))
201 void tipc_group_join(struct net
*net
, struct tipc_group
*grp
, int *sk_rcvbuf
)
203 struct rb_root
*tree
= &grp
->members
;
204 struct tipc_member
*m
, *tmp
;
205 struct sk_buff_head xmitq
;
207 skb_queue_head_init(&xmitq
);
208 rbtree_postorder_for_each_entry_safe(m
, tmp
, tree
, tree_node
) {
209 tipc_group_proto_xmit(grp
, m
, GRP_JOIN_MSG
, &xmitq
);
210 tipc_group_update_member(m
, 0);
212 tipc_node_distr_xmit(net
, &xmitq
);
213 *sk_rcvbuf
= tipc_group_rcvbuf_limit(grp
);
216 void tipc_group_delete(struct net
*net
, struct tipc_group
*grp
)
218 struct rb_root
*tree
= &grp
->members
;
219 struct tipc_member
*m
, *tmp
;
220 struct sk_buff_head xmitq
;
222 __skb_queue_head_init(&xmitq
);
224 rbtree_postorder_for_each_entry_safe(m
, tmp
, tree
, tree_node
) {
225 tipc_group_proto_xmit(grp
, m
, GRP_LEAVE_MSG
, &xmitq
);
229 tipc_node_distr_xmit(net
, &xmitq
);
230 tipc_nlist_purge(&grp
->dests
);
231 tipc_topsrv_kern_unsubscr(net
, grp
->subid
);
235 struct tipc_member
*tipc_group_find_member(struct tipc_group
*grp
,
238 struct rb_node
*n
= grp
->members
.rb_node
;
239 u64 nkey
, key
= (u64
)node
<< 32 | port
;
240 struct tipc_member
*m
;
243 m
= container_of(n
, struct tipc_member
, tree_node
);
244 nkey
= (u64
)m
->node
<< 32 | m
->port
;
255 static struct tipc_member
*tipc_group_find_dest(struct tipc_group
*grp
,
258 struct tipc_member
*m
;
260 m
= tipc_group_find_member(grp
, node
, port
);
261 if (m
&& tipc_group_is_receiver(m
))
266 static struct tipc_member
*tipc_group_find_node(struct tipc_group
*grp
,
269 struct tipc_member
*m
;
272 for (n
= rb_first(&grp
->members
); n
; n
= rb_next(n
)) {
273 m
= container_of(n
, struct tipc_member
, tree_node
);
280 static void tipc_group_add_to_tree(struct tipc_group
*grp
,
281 struct tipc_member
*m
)
283 u64 nkey
, key
= (u64
)m
->node
<< 32 | m
->port
;
284 struct rb_node
**n
, *parent
= NULL
;
285 struct tipc_member
*tmp
;
287 n
= &grp
->members
.rb_node
;
289 tmp
= container_of(*n
, struct tipc_member
, tree_node
);
291 tmp
= container_of(parent
, struct tipc_member
, tree_node
);
292 nkey
= (u64
)tmp
->node
<< 32 | tmp
->port
;
300 rb_link_node(&m
->tree_node
, parent
, n
);
301 rb_insert_color(&m
->tree_node
, &grp
->members
);
304 static struct tipc_member
*tipc_group_create_member(struct tipc_group
*grp
,
306 u32 instance
, int state
)
308 struct tipc_member
*m
;
310 m
= kzalloc(sizeof(*m
), GFP_ATOMIC
);
313 INIT_LIST_HEAD(&m
->list
);
314 INIT_LIST_HEAD(&m
->small_win
);
315 __skb_queue_head_init(&m
->deferredq
);
319 m
->instance
= instance
;
320 m
->bc_acked
= grp
->bc_snd_nxt
- 1;
322 tipc_group_add_to_tree(grp
, m
);
323 tipc_nlist_add(&grp
->dests
, m
->node
);
328 void tipc_group_add_member(struct tipc_group
*grp
, u32 node
,
329 u32 port
, u32 instance
)
331 tipc_group_create_member(grp
, node
, port
, instance
, MBR_PUBLISHED
);
334 static void tipc_group_delete_member(struct tipc_group
*grp
,
335 struct tipc_member
*m
)
337 rb_erase(&m
->tree_node
, &grp
->members
);
340 /* Check if we were waiting for replicast ack from this member */
341 if (grp
->bc_ackers
&& less(m
->bc_acked
, grp
->bc_snd_nxt
- 1))
344 list_del_init(&m
->list
);
345 list_del_init(&m
->small_win
);
346 tipc_group_decr_active(grp
, m
);
348 /* If last member on a node, remove node from dest list */
349 if (!tipc_group_find_node(grp
, m
->node
))
350 tipc_nlist_del(&grp
->dests
, m
->node
);
355 struct tipc_nlist
*tipc_group_dests(struct tipc_group
*grp
)
360 void tipc_group_self(struct tipc_group
*grp
, struct tipc_name_seq
*seq
,
363 seq
->type
= grp
->type
;
364 seq
->lower
= grp
->instance
;
365 seq
->upper
= grp
->instance
;
369 void tipc_group_update_member(struct tipc_member
*m
, int len
)
371 struct tipc_group
*grp
= m
->group
;
372 struct tipc_member
*_m
, *tmp
;
374 if (!tipc_group_is_receiver(m
))
379 if (m
->window
>= ADV_IDLE
)
382 list_del_init(&m
->small_win
);
384 /* Sort member into small_window members' list */
385 list_for_each_entry_safe(_m
, tmp
, &grp
->small_win
, small_win
) {
386 if (_m
->window
> m
->window
)
389 list_add_tail(&m
->small_win
, &_m
->small_win
);
392 void tipc_group_update_bc_members(struct tipc_group
*grp
, int len
, bool ack
)
394 u16 prev
= grp
->bc_snd_nxt
- 1;
395 struct tipc_member
*m
;
399 for (n
= rb_first(&grp
->members
); n
; n
= rb_next(n
)) {
400 m
= container_of(n
, struct tipc_member
, tree_node
);
401 if (tipc_group_is_receiver(m
)) {
402 tipc_group_update_member(m
, len
);
408 /* Mark number of acknowledges to expect, if any */
410 grp
->bc_ackers
= ackers
;
414 bool tipc_group_cong(struct tipc_group
*grp
, u32 dnode
, u32 dport
,
415 int len
, struct tipc_member
**mbr
)
417 struct sk_buff_head xmitq
;
418 struct tipc_member
*m
;
421 m
= tipc_group_find_dest(grp
, dnode
, dport
);
422 if (!tipc_group_is_receiver(m
)) {
428 if (m
->window
>= len
)
433 /* If not fully advertised, do it now to prevent mutual blocking */
436 if (state
== MBR_JOINED
&& adv
== ADV_IDLE
)
438 if (state
== MBR_ACTIVE
&& adv
== ADV_ACTIVE
)
440 if (state
== MBR_PENDING
&& adv
== ADV_IDLE
)
442 skb_queue_head_init(&xmitq
);
443 tipc_group_proto_xmit(grp
, m
, GRP_ADV_MSG
, &xmitq
);
444 tipc_node_distr_xmit(grp
->net
, &xmitq
);
448 bool tipc_group_bc_cong(struct tipc_group
*grp
, int len
)
450 struct tipc_member
*m
= NULL
;
452 /* If prev bcast was replicast, reject until all receivers have acked */
453 if (grp
->bc_ackers
) {
457 if (list_empty(&grp
->small_win
))
460 m
= list_first_entry(&grp
->small_win
, struct tipc_member
, small_win
);
461 if (m
->window
>= len
)
464 return tipc_group_cong(grp
, m
->node
, m
->port
, len
, &m
);
467 /* tipc_group_sort_msg() - sort msg into queue by bcast sequence number
469 static void tipc_group_sort_msg(struct sk_buff
*skb
, struct sk_buff_head
*defq
)
471 struct tipc_msg
*_hdr
, *hdr
= buf_msg(skb
);
472 u16 bc_seqno
= msg_grp_bc_seqno(hdr
);
473 struct sk_buff
*_skb
, *tmp
;
474 int mtyp
= msg_type(hdr
);
476 /* Bcast/mcast may be bypassed by ucast or other bcast, - sort it in */
477 if (mtyp
== TIPC_GRP_BCAST_MSG
|| mtyp
== TIPC_GRP_MCAST_MSG
) {
478 skb_queue_walk_safe(defq
, _skb
, tmp
) {
479 _hdr
= buf_msg(_skb
);
480 if (!less(bc_seqno
, msg_grp_bc_seqno(_hdr
)))
482 __skb_queue_before(defq
, _skb
, skb
);
485 /* Bcast was not bypassed, - add to tail */
487 /* Unicasts are never bypassed, - always add to tail */
488 __skb_queue_tail(defq
, skb
);
491 /* tipc_group_filter_msg() - determine if we should accept arriving message
493 void tipc_group_filter_msg(struct tipc_group
*grp
, struct sk_buff_head
*inputq
,
494 struct sk_buff_head
*xmitq
)
496 struct sk_buff
*skb
= __skb_dequeue(inputq
);
497 bool ack
, deliver
, update
, leave
= false;
498 struct sk_buff_head
*defq
;
499 struct tipc_member
*m
;
500 struct tipc_msg
*hdr
;
508 node
= msg_orignode(hdr
);
509 port
= msg_origport(hdr
);
511 if (!msg_in_group(hdr
))
514 m
= tipc_group_find_member(grp
, node
, port
);
515 if (!tipc_group_is_sender(m
))
518 if (less(msg_grp_bc_seqno(hdr
), m
->bc_rcv_nxt
))
521 TIPC_SKB_CB(skb
)->orig_member
= m
->instance
;
522 defq
= &m
->deferredq
;
523 tipc_group_sort_msg(skb
, defq
);
525 while ((skb
= skb_peek(defq
))) {
527 mtyp
= msg_type(hdr
);
528 blks
= msg_blocks(hdr
);
533 if (more(msg_grp_bc_seqno(hdr
), m
->bc_rcv_nxt
))
536 /* Decide what to do with message */
538 case TIPC_GRP_MCAST_MSG
:
539 if (msg_nameinst(hdr
) != grp
->instance
) {
544 case TIPC_GRP_BCAST_MSG
:
546 ack
= msg_grp_bc_ack_req(hdr
);
548 case TIPC_GRP_UCAST_MSG
:
550 case TIPC_GRP_MEMBER_EVT
:
551 if (m
->state
== MBR_LEAVING
)
560 /* Execute decisions */
563 __skb_queue_tail(inputq
, skb
);
568 tipc_group_proto_xmit(grp
, m
, GRP_ACK_MSG
, xmitq
);
571 __skb_queue_purge(defq
);
572 tipc_group_delete_member(grp
, m
);
578 tipc_group_update_rcv_win(grp
, blks
, node
, port
, xmitq
);
585 void tipc_group_update_rcv_win(struct tipc_group
*grp
, int blks
, u32 node
,
586 u32 port
, struct sk_buff_head
*xmitq
)
588 struct list_head
*active
= &grp
->active
;
589 int max_active
= grp
->max_active
;
590 int reclaim_limit
= max_active
* 3 / 4;
591 int active_cnt
= grp
->active_cnt
;
592 struct tipc_member
*m
, *rm
, *pm
;
594 m
= tipc_group_find_member(grp
, node
, port
);
598 m
->advertised
-= blks
;
602 /* First, decide if member can go active */
603 if (active_cnt
<= max_active
) {
604 m
->state
= MBR_ACTIVE
;
605 list_add_tail(&m
->list
, active
);
607 tipc_group_proto_xmit(grp
, m
, GRP_ADV_MSG
, xmitq
);
609 m
->state
= MBR_PENDING
;
610 list_add_tail(&m
->list
, &grp
->pending
);
613 if (active_cnt
< reclaim_limit
)
616 /* Reclaim from oldest active member, if possible */
617 if (!list_empty(active
)) {
618 rm
= list_first_entry(active
, struct tipc_member
, list
);
619 rm
->state
= MBR_RECLAIMING
;
620 list_del_init(&rm
->list
);
621 tipc_group_proto_xmit(grp
, rm
, GRP_RECLAIM_MSG
, xmitq
);
624 /* Nobody to reclaim from; - revert oldest pending to JOINED */
625 pm
= list_first_entry(&grp
->pending
, struct tipc_member
, list
);
626 list_del_init(&pm
->list
);
627 pm
->state
= MBR_JOINED
;
628 tipc_group_proto_xmit(grp
, pm
, GRP_ADV_MSG
, xmitq
);
631 if (!list_is_last(&m
->list
, &grp
->active
))
632 list_move_tail(&m
->list
, &grp
->active
);
633 if (m
->advertised
> (ADV_ACTIVE
* 3 / 4))
635 tipc_group_proto_xmit(grp
, m
, GRP_ADV_MSG
, xmitq
);
638 if (m
->advertised
> ADV_IDLE
)
640 m
->state
= MBR_JOINED
;
642 if (m
->advertised
< ADV_IDLE
) {
643 pr_warn_ratelimited("Rcv unexpected msg after REMIT\n");
644 tipc_group_proto_xmit(grp
, m
, GRP_ADV_MSG
, xmitq
);
647 if (list_empty(&grp
->pending
))
650 /* Set oldest pending member to active and advertise */
651 pm
= list_first_entry(&grp
->pending
, struct tipc_member
, list
);
652 pm
->state
= MBR_ACTIVE
;
653 list_move_tail(&pm
->list
, &grp
->active
);
655 tipc_group_proto_xmit(grp
, pm
, GRP_ADV_MSG
, xmitq
);
665 static void tipc_group_create_event(struct tipc_group
*grp
,
666 struct tipc_member
*m
,
667 u32 event
, u16 seqno
,
668 struct sk_buff_head
*inputq
)
669 { u32 dnode
= tipc_own_addr(grp
->net
);
670 struct tipc_event evt
;
672 struct tipc_msg
*hdr
;
675 evt
.found_lower
= m
->instance
;
676 evt
.found_upper
= m
->instance
;
677 evt
.port
.ref
= m
->port
;
678 evt
.port
.node
= m
->node
;
679 evt
.s
.seq
.type
= grp
->type
;
680 evt
.s
.seq
.lower
= m
->instance
;
681 evt
.s
.seq
.upper
= m
->instance
;
683 skb
= tipc_msg_create(TIPC_CRITICAL_IMPORTANCE
, TIPC_GRP_MEMBER_EVT
,
684 GROUP_H_SIZE
, sizeof(evt
), dnode
, m
->node
,
685 grp
->portid
, m
->port
, 0);
690 msg_set_nametype(hdr
, grp
->type
);
691 msg_set_grp_evt(hdr
, event
);
692 msg_set_dest_droppable(hdr
, true);
693 msg_set_grp_bc_seqno(hdr
, seqno
);
694 memcpy(msg_data(hdr
), &evt
, sizeof(evt
));
695 TIPC_SKB_CB(skb
)->orig_member
= m
->instance
;
696 __skb_queue_tail(inputq
, skb
);
699 static void tipc_group_proto_xmit(struct tipc_group
*grp
, struct tipc_member
*m
,
700 int mtyp
, struct sk_buff_head
*xmitq
)
702 struct tipc_msg
*hdr
;
706 skb
= tipc_msg_create(GROUP_PROTOCOL
, mtyp
, INT_H_SIZE
, 0,
707 m
->node
, tipc_own_addr(grp
->net
),
708 m
->port
, grp
->portid
, 0);
712 if (m
->state
== MBR_ACTIVE
)
713 adv
= ADV_ACTIVE
- m
->advertised
;
714 else if (m
->state
== MBR_JOINED
|| m
->state
== MBR_PENDING
)
715 adv
= ADV_IDLE
- m
->advertised
;
719 if (mtyp
== GRP_JOIN_MSG
) {
720 msg_set_grp_bc_syncpt(hdr
, grp
->bc_snd_nxt
);
721 msg_set_adv_win(hdr
, adv
);
722 m
->advertised
+= adv
;
723 } else if (mtyp
== GRP_LEAVE_MSG
) {
724 msg_set_grp_bc_syncpt(hdr
, grp
->bc_snd_nxt
);
725 } else if (mtyp
== GRP_ADV_MSG
) {
726 msg_set_adv_win(hdr
, adv
);
727 m
->advertised
+= adv
;
728 } else if (mtyp
== GRP_ACK_MSG
) {
729 msg_set_grp_bc_acked(hdr
, m
->bc_rcv_nxt
);
730 } else if (mtyp
== GRP_REMIT_MSG
) {
731 msg_set_grp_remitted(hdr
, m
->window
);
733 msg_set_dest_droppable(hdr
, true);
734 __skb_queue_tail(xmitq
, skb
);
737 void tipc_group_proto_rcv(struct tipc_group
*grp
, bool *usr_wakeup
,
738 struct tipc_msg
*hdr
, struct sk_buff_head
*inputq
,
739 struct sk_buff_head
*xmitq
)
741 u32 node
= msg_orignode(hdr
);
742 u32 port
= msg_origport(hdr
);
743 struct tipc_member
*m
, *pm
;
744 u16 remitted
, in_flight
;
749 if (grp
->scope
== TIPC_NODE_SCOPE
&& node
!= tipc_own_addr(grp
->net
))
752 m
= tipc_group_find_member(grp
, node
, port
);
754 switch (msg_type(hdr
)) {
757 m
= tipc_group_create_member(grp
, node
, port
,
761 m
->bc_syncpt
= msg_grp_bc_syncpt(hdr
);
762 m
->bc_rcv_nxt
= m
->bc_syncpt
;
763 m
->window
+= msg_adv_win(hdr
);
765 /* Wait until PUBLISH event is received if necessary */
766 if (m
->state
!= MBR_PUBLISHED
)
769 /* Member can be taken into service */
770 m
->state
= MBR_JOINED
;
771 tipc_group_open(m
, usr_wakeup
);
772 tipc_group_update_member(m
, 0);
773 tipc_group_proto_xmit(grp
, m
, GRP_ADV_MSG
, xmitq
);
774 tipc_group_create_event(grp
, m
, TIPC_PUBLISHED
,
775 m
->bc_syncpt
, inputq
);
780 m
->bc_syncpt
= msg_grp_bc_syncpt(hdr
);
781 list_del_init(&m
->list
);
782 tipc_group_open(m
, usr_wakeup
);
783 tipc_group_decr_active(grp
, m
);
784 m
->state
= MBR_LEAVING
;
785 tipc_group_create_event(grp
, m
, TIPC_WITHDRAWN
,
786 m
->bc_syncpt
, inputq
);
791 m
->window
+= msg_adv_win(hdr
);
792 tipc_group_open(m
, usr_wakeup
);
797 m
->bc_acked
= msg_grp_bc_acked(hdr
);
798 if (--grp
->bc_ackers
)
800 list_del_init(&m
->small_win
);
801 *m
->group
->open
= true;
803 tipc_group_update_member(m
, 0);
805 case GRP_RECLAIM_MSG
:
808 tipc_group_proto_xmit(grp
, m
, GRP_REMIT_MSG
, xmitq
);
809 m
->window
= ADV_IDLE
;
810 tipc_group_open(m
, usr_wakeup
);
813 if (!m
|| m
->state
!= MBR_RECLAIMING
)
816 remitted
= msg_grp_remitted(hdr
);
818 /* Messages preceding the REMIT still in receive queue */
819 if (m
->advertised
> remitted
) {
820 m
->state
= MBR_REMITTED
;
821 in_flight
= m
->advertised
- remitted
;
822 m
->advertised
= ADV_IDLE
+ in_flight
;
825 /* This should never happen */
826 if (m
->advertised
< remitted
)
827 pr_warn_ratelimited("Unexpected REMIT msg\n");
829 /* All messages preceding the REMIT have been read */
830 m
->state
= MBR_JOINED
;
832 m
->advertised
= ADV_IDLE
;
834 /* Set oldest pending member to active and advertise */
835 if (list_empty(&grp
->pending
))
837 pm
= list_first_entry(&grp
->pending
, struct tipc_member
, list
);
838 pm
->state
= MBR_ACTIVE
;
839 list_move_tail(&pm
->list
, &grp
->active
);
841 if (pm
->advertised
<= (ADV_ACTIVE
* 3 / 4))
842 tipc_group_proto_xmit(grp
, pm
, GRP_ADV_MSG
, xmitq
);
845 pr_warn("Received unknown GROUP_PROTO message\n");
849 /* tipc_group_member_evt() - receive and handle a member up/down event
851 void tipc_group_member_evt(struct tipc_group
*grp
,
854 struct tipc_msg
*hdr
,
855 struct sk_buff_head
*inputq
,
856 struct sk_buff_head
*xmitq
)
858 struct tipc_event
*evt
= (void *)msg_data(hdr
);
859 u32 instance
= evt
->found_lower
;
860 u32 node
= evt
->port
.node
;
861 u32 port
= evt
->port
.ref
;
862 int event
= evt
->event
;
863 struct tipc_member
*m
;
871 self
= tipc_own_addr(net
);
872 if (!grp
->loopback
&& node
== self
&& port
== grp
->portid
)
875 m
= tipc_group_find_member(grp
, node
, port
);
879 /* Send and wait for arrival of JOIN message if necessary */
881 m
= tipc_group_create_member(grp
, node
, port
, instance
,
885 tipc_group_update_member(m
, 0);
886 tipc_group_proto_xmit(grp
, m
, GRP_JOIN_MSG
, xmitq
);
890 if (m
->state
!= MBR_JOINING
)
893 /* Member can be taken into service */
894 m
->instance
= instance
;
895 m
->state
= MBR_JOINED
;
896 tipc_group_open(m
, usr_wakeup
);
897 tipc_group_update_member(m
, 0);
898 tipc_group_proto_xmit(grp
, m
, GRP_JOIN_MSG
, xmitq
);
899 tipc_group_create_event(grp
, m
, TIPC_PUBLISHED
,
900 m
->bc_syncpt
, inputq
);
906 tipc_group_decr_active(grp
, m
);
907 m
->state
= MBR_LEAVING
;
908 list_del_init(&m
->list
);
909 tipc_group_open(m
, usr_wakeup
);
911 /* Only send event if no LEAVE message can be expected */
912 if (!tipc_node_is_up(net
, node
))
913 tipc_group_create_event(grp
, m
, TIPC_WITHDRAWN
,
914 m
->bc_rcv_nxt
, inputq
);
919 *sk_rcvbuf
= tipc_group_rcvbuf_limit(grp
);