blob: 122162a3181648bad80f110cb94291f4a282e81f [file] [log] [blame]
Jon Maloy75da2162017-10-13 11:04:23 +02001/*
2 * net/tipc/group.c: TIPC group messaging code
3 *
4 * Copyright (c) 2017, Ericsson AB
5 * All rights reserved.
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions are met:
9 *
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.
18 *
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.
22 *
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.
34 */
35
36#include "core.h"
37#include "addr.h"
38#include "group.h"
39#include "bcast.h"
40#include "server.h"
41#include "msg.h"
42#include "socket.h"
43#include "node.h"
44#include "name_table.h"
45#include "subscr.h"
46
47#define ADV_UNIT (((MAX_MSG_SIZE + MAX_H_SIZE) / FLOWCTL_BLK_SZ) + 1)
48#define ADV_IDLE ADV_UNIT
Jon Maloyb7d42632017-10-13 11:04:26 +020049#define ADV_ACTIVE (ADV_UNIT * 12)
Jon Maloy75da2162017-10-13 11:04:23 +020050
51enum mbr_state {
Jon Maloy75da2162017-10-13 11:04:23 +020052 MBR_JOINING,
53 MBR_PUBLISHED,
54 MBR_JOINED,
Jon Maloy04d7b572017-10-13 11:04:34 +020055 MBR_PENDING,
56 MBR_ACTIVE,
57 MBR_RECLAIMING,
58 MBR_REMITTED,
Jon Maloy75da2162017-10-13 11:04:23 +020059 MBR_LEAVING
60};
61
62struct tipc_member {
63 struct rb_node tree_node;
64 struct list_head list;
Jon Maloy38266ca2018-01-04 15:20:44 +010065 struct list_head small_win;
Jon Maloyb87a5ea2017-10-13 11:04:30 +020066 struct sk_buff_head deferredq;
Jon Maloyb7d42632017-10-13 11:04:26 +020067 struct tipc_group *group;
Jon Maloy75da2162017-10-13 11:04:23 +020068 u32 node;
69 u32 port;
Jon Maloy31c82a22017-10-13 11:04:24 +020070 u32 instance;
Jon Maloy75da2162017-10-13 11:04:23 +020071 enum mbr_state state;
Jon Maloyb7d42632017-10-13 11:04:26 +020072 u16 advertised;
73 u16 window;
Jon Maloy75da2162017-10-13 11:04:23 +020074 u16 bc_rcv_nxt;
Jon Maloya3bada72017-10-13 11:04:33 +020075 u16 bc_syncpt;
Jon Maloy2f487712017-10-13 11:04:31 +020076 u16 bc_acked;
Jon Maloy75da2162017-10-13 11:04:23 +020077};
78
79struct tipc_group {
80 struct rb_root members;
Jon Maloy38266ca2018-01-04 15:20:44 +010081 struct list_head small_win;
Jon Maloy04d7b572017-10-13 11:04:34 +020082 struct list_head pending;
83 struct list_head active;
Jon Maloy75da2162017-10-13 11:04:23 +020084 struct tipc_nlist dests;
85 struct net *net;
86 int subid;
87 u32 type;
88 u32 instance;
Jon Maloy75da2162017-10-13 11:04:23 +020089 u32 scope;
90 u32 portid;
91 u16 member_cnt;
Jon Maloy04d7b572017-10-13 11:04:34 +020092 u16 active_cnt;
93 u16 max_active;
Jon Maloy75da2162017-10-13 11:04:23 +020094 u16 bc_snd_nxt;
Jon Maloy2f487712017-10-13 11:04:31 +020095 u16 bc_ackers;
Jon Maloy60c25302018-01-17 16:42:46 +010096 bool *open;
Jon Maloy75da2162017-10-13 11:04:23 +020097 bool loopback;
Jon Maloyae236fb2017-10-13 11:04:25 +020098 bool events;
Jon Maloy75da2162017-10-13 11:04:23 +020099};
100
101static void tipc_group_proto_xmit(struct tipc_group *grp, struct tipc_member *m,
102 int mtyp, struct sk_buff_head *xmitq);
103
Jon Maloyeb929a92018-01-08 21:03:31 +0100104static void tipc_group_open(struct tipc_member *m, bool *wakeup)
105{
106 *wakeup = false;
107 if (list_empty(&m->small_win))
108 return;
109 list_del_init(&m->small_win);
Jon Maloy60c25302018-01-17 16:42:46 +0100110 *m->group->open = true;
Jon Maloyeb929a92018-01-08 21:03:31 +0100111 *wakeup = true;
112}
113
Jon Maloy04d7b572017-10-13 11:04:34 +0200114static void tipc_group_decr_active(struct tipc_group *grp,
115 struct tipc_member *m)
116{
Jon Maloyf9c935d2017-12-29 19:48:02 +0100117 if (m->state == MBR_ACTIVE || m->state == MBR_RECLAIMING ||
118 m->state == MBR_REMITTED)
Jon Maloy04d7b572017-10-13 11:04:34 +0200119 grp->active_cnt--;
120}
121
Jon Maloyb7d42632017-10-13 11:04:26 +0200122static int tipc_group_rcvbuf_limit(struct tipc_group *grp)
123{
Jon Maloy04d7b572017-10-13 11:04:34 +0200124 int max_active, active_pool, idle_pool;
Jon Maloyb7d42632017-10-13 11:04:26 +0200125 int mcnt = grp->member_cnt + 1;
126
Jon Maloy04d7b572017-10-13 11:04:34 +0200127 /* 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;
131
132 /* Reserve blocks for active and idle members */
133 active_pool = max_active * ADV_ACTIVE;
134 idle_pool = (mcnt - max_active) * ADV_IDLE;
135
Jon Maloyb7d42632017-10-13 11:04:26 +0200136 /* Scale to bytes, considering worst-case truesize/msgsize ratio */
Jon Maloy04d7b572017-10-13 11:04:34 +0200137 return (active_pool + idle_pool) * FLOWCTL_BLK_SZ * 4;
Jon Maloyb7d42632017-10-13 11:04:26 +0200138}
139
Jon Maloy75da2162017-10-13 11:04:23 +0200140u16 tipc_group_bc_snd_nxt(struct tipc_group *grp)
141{
142 return grp->bc_snd_nxt;
143}
144
Jon Maloy38266ca2018-01-04 15:20:44 +0100145static bool tipc_group_is_receiver(struct tipc_member *m)
Jon Maloyb7d42632017-10-13 11:04:26 +0200146{
Jon Maloy02334932018-01-08 21:03:25 +0100147 return m && m->state != MBR_JOINING && m->state != MBR_LEAVING;
Jon Maloyb7d42632017-10-13 11:04:26 +0200148}
149
Jon Maloy38266ca2018-01-04 15:20:44 +0100150static bool tipc_group_is_sender(struct tipc_member *m)
Jon Maloy75da2162017-10-13 11:04:23 +0200151{
Jon Maloyd12d2e12018-01-08 21:03:28 +0100152 return m && m->state != MBR_JOINING && m->state != MBR_PUBLISHED;
Jon Maloy75da2162017-10-13 11:04:23 +0200153}
154
Jon Maloyee106d72017-10-13 11:04:28 +0200155u32 tipc_group_exclude(struct tipc_group *grp)
156{
157 if (!grp->loopback)
158 return grp->portid;
159 return 0;
160}
161
Jon Maloy75da2162017-10-13 11:04:23 +0200162int tipc_group_size(struct tipc_group *grp)
163{
164 return grp->member_cnt;
165}
166
167struct tipc_group *tipc_group_create(struct net *net, u32 portid,
Jon Maloy60c25302018-01-17 16:42:46 +0100168 struct tipc_group_req *mreq,
169 bool *group_is_open)
Jon Maloy75da2162017-10-13 11:04:23 +0200170{
Jon Maloy232d07b2018-01-08 21:03:30 +0100171 u32 filter = TIPC_SUB_PORTS | TIPC_SUB_NO_STATUS;
172 bool global = mreq->scope != TIPC_NODE_SCOPE;
Jon Maloy75da2162017-10-13 11:04:23 +0200173 struct tipc_group *grp;
174 u32 type = mreq->type;
175
176 grp = kzalloc(sizeof(*grp), GFP_ATOMIC);
177 if (!grp)
178 return NULL;
179 tipc_nlist_init(&grp->dests, tipc_own_addr(net));
Jon Maloy38266ca2018-01-04 15:20:44 +0100180 INIT_LIST_HEAD(&grp->small_win);
Jon Maloy04d7b572017-10-13 11:04:34 +0200181 INIT_LIST_HEAD(&grp->active);
182 INIT_LIST_HEAD(&grp->pending);
Jon Maloy75da2162017-10-13 11:04:23 +0200183 grp->members = RB_ROOT;
184 grp->net = net;
185 grp->portid = portid;
Jon Maloy75da2162017-10-13 11:04:23 +0200186 grp->type = type;
187 grp->instance = mreq->instance;
188 grp->scope = mreq->scope;
189 grp->loopback = mreq->flags & TIPC_GROUP_LOOPBACK;
Jon Maloyae236fb2017-10-13 11:04:25 +0200190 grp->events = mreq->flags & TIPC_GROUP_MEMBER_EVTS;
Jon Maloy60c25302018-01-17 16:42:46 +0100191 grp->open = group_is_open;
Jon Maloy232d07b2018-01-08 21:03:30 +0100192 filter |= global ? TIPC_SUB_CLUSTER_SCOPE : TIPC_SUB_NODE_SCOPE;
193 if (tipc_topsrv_kern_subscr(net, portid, type, 0, ~0,
194 filter, &grp->subid))
Jon Maloy75da2162017-10-13 11:04:23 +0200195 return grp;
196 kfree(grp);
197 return NULL;
198}
199
Jon Maloyd12d2e12018-01-08 21:03:28 +0100200void tipc_group_join(struct net *net, struct tipc_group *grp, int *sk_rcvbuf)
201{
202 struct rb_root *tree = &grp->members;
203 struct tipc_member *m, *tmp;
204 struct sk_buff_head xmitq;
205
206 skb_queue_head_init(&xmitq);
207 rbtree_postorder_for_each_entry_safe(m, tmp, tree, tree_node) {
208 tipc_group_proto_xmit(grp, m, GRP_JOIN_MSG, &xmitq);
209 tipc_group_update_member(m, 0);
210 }
211 tipc_node_distr_xmit(net, &xmitq);
212 *sk_rcvbuf = tipc_group_rcvbuf_limit(grp);
213}
214
Jon Maloy75da2162017-10-13 11:04:23 +0200215void tipc_group_delete(struct net *net, struct tipc_group *grp)
216{
217 struct rb_root *tree = &grp->members;
218 struct tipc_member *m, *tmp;
219 struct sk_buff_head xmitq;
220
221 __skb_queue_head_init(&xmitq);
222
223 rbtree_postorder_for_each_entry_safe(m, tmp, tree, tree_node) {
224 tipc_group_proto_xmit(grp, m, GRP_LEAVE_MSG, &xmitq);
225 list_del(&m->list);
226 kfree(m);
227 }
228 tipc_node_distr_xmit(net, &xmitq);
229 tipc_nlist_purge(&grp->dests);
230 tipc_topsrv_kern_unsubscr(net, grp->subid);
231 kfree(grp);
232}
233
234struct tipc_member *tipc_group_find_member(struct tipc_group *grp,
235 u32 node, u32 port)
236{
237 struct rb_node *n = grp->members.rb_node;
238 u64 nkey, key = (u64)node << 32 | port;
239 struct tipc_member *m;
240
241 while (n) {
242 m = container_of(n, struct tipc_member, tree_node);
243 nkey = (u64)m->node << 32 | m->port;
244 if (key < nkey)
245 n = n->rb_left;
246 else if (key > nkey)
247 n = n->rb_right;
248 else
249 return m;
250 }
251 return NULL;
252}
253
Jon Maloy27bd9ec2017-10-13 11:04:27 +0200254static struct tipc_member *tipc_group_find_dest(struct tipc_group *grp,
255 u32 node, u32 port)
256{
257 struct tipc_member *m;
258
259 m = tipc_group_find_member(grp, node, port);
Jon Maloy38266ca2018-01-04 15:20:44 +0100260 if (m && tipc_group_is_receiver(m))
Jon Maloy27bd9ec2017-10-13 11:04:27 +0200261 return m;
262 return NULL;
263}
264
Jon Maloy75da2162017-10-13 11:04:23 +0200265static struct tipc_member *tipc_group_find_node(struct tipc_group *grp,
266 u32 node)
267{
268 struct tipc_member *m;
269 struct rb_node *n;
270
271 for (n = rb_first(&grp->members); n; n = rb_next(n)) {
272 m = container_of(n, struct tipc_member, tree_node);
273 if (m->node == node)
274 return m;
275 }
276 return NULL;
277}
278
279static void tipc_group_add_to_tree(struct tipc_group *grp,
280 struct tipc_member *m)
281{
282 u64 nkey, key = (u64)m->node << 32 | m->port;
283 struct rb_node **n, *parent = NULL;
284 struct tipc_member *tmp;
285
286 n = &grp->members.rb_node;
287 while (*n) {
288 tmp = container_of(*n, struct tipc_member, tree_node);
289 parent = *n;
290 tmp = container_of(parent, struct tipc_member, tree_node);
291 nkey = (u64)tmp->node << 32 | tmp->port;
292 if (key < nkey)
293 n = &(*n)->rb_left;
294 else if (key > nkey)
295 n = &(*n)->rb_right;
296 else
297 return;
298 }
299 rb_link_node(&m->tree_node, parent, n);
300 rb_insert_color(&m->tree_node, &grp->members);
301}
302
303static struct tipc_member *tipc_group_create_member(struct tipc_group *grp,
304 u32 node, u32 port,
Jon Maloyd12d2e12018-01-08 21:03:28 +0100305 u32 instance, int state)
Jon Maloy75da2162017-10-13 11:04:23 +0200306{
307 struct tipc_member *m;
308
309 m = kzalloc(sizeof(*m), GFP_ATOMIC);
310 if (!m)
311 return NULL;
312 INIT_LIST_HEAD(&m->list);
Jon Maloy38266ca2018-01-04 15:20:44 +0100313 INIT_LIST_HEAD(&m->small_win);
Jon Maloyb87a5ea2017-10-13 11:04:30 +0200314 __skb_queue_head_init(&m->deferredq);
Jon Maloyb7d42632017-10-13 11:04:26 +0200315 m->group = grp;
Jon Maloy75da2162017-10-13 11:04:23 +0200316 m->node = node;
317 m->port = port;
Jon Maloyd12d2e12018-01-08 21:03:28 +0100318 m->instance = instance;
Jon Maloy2f487712017-10-13 11:04:31 +0200319 m->bc_acked = grp->bc_snd_nxt - 1;
Jon Maloy75da2162017-10-13 11:04:23 +0200320 grp->member_cnt++;
321 tipc_group_add_to_tree(grp, m);
322 tipc_nlist_add(&grp->dests, m->node);
323 m->state = state;
324 return m;
325}
326
Jon Maloyd12d2e12018-01-08 21:03:28 +0100327void tipc_group_add_member(struct tipc_group *grp, u32 node,
328 u32 port, u32 instance)
Jon Maloy75da2162017-10-13 11:04:23 +0200329{
Jon Maloyd12d2e12018-01-08 21:03:28 +0100330 tipc_group_create_member(grp, node, port, instance, MBR_PUBLISHED);
Jon Maloy75da2162017-10-13 11:04:23 +0200331}
332
333static void tipc_group_delete_member(struct tipc_group *grp,
334 struct tipc_member *m)
335{
336 rb_erase(&m->tree_node, &grp->members);
337 grp->member_cnt--;
Jon Maloy2f487712017-10-13 11:04:31 +0200338
339 /* Check if we were waiting for replicast ack from this member */
340 if (grp->bc_ackers && less(m->bc_acked, grp->bc_snd_nxt - 1))
341 grp->bc_ackers--;
342
Jon Maloy75da2162017-10-13 11:04:23 +0200343 list_del_init(&m->list);
Jon Maloy38266ca2018-01-04 15:20:44 +0100344 list_del_init(&m->small_win);
Jon Maloy04d7b572017-10-13 11:04:34 +0200345 tipc_group_decr_active(grp, m);
Jon Maloy75da2162017-10-13 11:04:23 +0200346
347 /* If last member on a node, remove node from dest list */
348 if (!tipc_group_find_node(grp, m->node))
349 tipc_nlist_del(&grp->dests, m->node);
350
351 kfree(m);
352}
353
354struct tipc_nlist *tipc_group_dests(struct tipc_group *grp)
355{
356 return &grp->dests;
357}
358
359void tipc_group_self(struct tipc_group *grp, struct tipc_name_seq *seq,
360 int *scope)
361{
362 seq->type = grp->type;
363 seq->lower = grp->instance;
364 seq->upper = grp->instance;
365 *scope = grp->scope;
366}
367
Jon Maloyb7d42632017-10-13 11:04:26 +0200368void tipc_group_update_member(struct tipc_member *m, int len)
Jon Maloy75da2162017-10-13 11:04:23 +0200369{
Jon Maloyb7d42632017-10-13 11:04:26 +0200370 struct tipc_group *grp = m->group;
371 struct tipc_member *_m, *tmp;
372
Jon Maloy38266ca2018-01-04 15:20:44 +0100373 if (!tipc_group_is_receiver(m))
Jon Maloyb7d42632017-10-13 11:04:26 +0200374 return;
375
376 m->window -= len;
377
378 if (m->window >= ADV_IDLE)
379 return;
380
Jon Maloy38266ca2018-01-04 15:20:44 +0100381 list_del_init(&m->small_win);
Jon Maloyb7d42632017-10-13 11:04:26 +0200382
Jon Maloy38266ca2018-01-04 15:20:44 +0100383 /* Sort member into small_window members' list */
384 list_for_each_entry_safe(_m, tmp, &grp->small_win, small_win) {
Jon Maloyd84d1b32018-01-04 15:20:45 +0100385 if (_m->window > m->window)
386 break;
Jon Maloyb7d42632017-10-13 11:04:26 +0200387 }
Jon Maloyd84d1b32018-01-04 15:20:45 +0100388 list_add_tail(&m->small_win, &_m->small_win);
Jon Maloyb7d42632017-10-13 11:04:26 +0200389}
390
Jon Maloy2f487712017-10-13 11:04:31 +0200391void tipc_group_update_bc_members(struct tipc_group *grp, int len, bool ack)
Jon Maloyb7d42632017-10-13 11:04:26 +0200392{
Jon Maloy2f487712017-10-13 11:04:31 +0200393 u16 prev = grp->bc_snd_nxt - 1;
Jon Maloyb7d42632017-10-13 11:04:26 +0200394 struct tipc_member *m;
395 struct rb_node *n;
Jon Maloy0a3d8052017-12-21 13:07:11 +0100396 u16 ackers = 0;
Jon Maloyb7d42632017-10-13 11:04:26 +0200397
398 for (n = rb_first(&grp->members); n; n = rb_next(n)) {
399 m = container_of(n, struct tipc_member, tree_node);
Jon Maloy38266ca2018-01-04 15:20:44 +0100400 if (tipc_group_is_receiver(m)) {
Jon Maloyb7d42632017-10-13 11:04:26 +0200401 tipc_group_update_member(m, len);
Jon Maloy2f487712017-10-13 11:04:31 +0200402 m->bc_acked = prev;
Jon Maloy0a3d8052017-12-21 13:07:11 +0100403 ackers++;
Jon Maloy2f487712017-10-13 11:04:31 +0200404 }
Jon Maloyb7d42632017-10-13 11:04:26 +0200405 }
Jon Maloy2f487712017-10-13 11:04:31 +0200406
407 /* Mark number of acknowledges to expect, if any */
408 if (ack)
Jon Maloy0a3d8052017-12-21 13:07:11 +0100409 grp->bc_ackers = ackers;
Jon Maloy75da2162017-10-13 11:04:23 +0200410 grp->bc_snd_nxt++;
411}
412
Jon Maloy27bd9ec2017-10-13 11:04:27 +0200413bool tipc_group_cong(struct tipc_group *grp, u32 dnode, u32 dport,
414 int len, struct tipc_member **mbr)
415{
416 struct sk_buff_head xmitq;
417 struct tipc_member *m;
418 int adv, state;
419
420 m = tipc_group_find_dest(grp, dnode, dport);
Jon Maloyeb929a92018-01-08 21:03:31 +0100421 if (!tipc_group_is_receiver(m)) {
422 *mbr = NULL;
Jon Maloy27bd9ec2017-10-13 11:04:27 +0200423 return false;
Jon Maloyeb929a92018-01-08 21:03:31 +0100424 }
425 *mbr = m;
426
Jon Maloy27bd9ec2017-10-13 11:04:27 +0200427 if (m->window >= len)
428 return false;
Jon Maloyeb929a92018-01-08 21:03:31 +0100429
Jon Maloy60c25302018-01-17 16:42:46 +0100430 *grp->open = false;
Jon Maloy27bd9ec2017-10-13 11:04:27 +0200431
432 /* If not fully advertised, do it now to prevent mutual blocking */
433 adv = m->advertised;
434 state = m->state;
Jon Maloy27bd9ec2017-10-13 11:04:27 +0200435 if (state == MBR_JOINED && adv == ADV_IDLE)
436 return true;
Jon Maloy04d7b572017-10-13 11:04:34 +0200437 if (state == MBR_ACTIVE && adv == ADV_ACTIVE)
438 return true;
439 if (state == MBR_PENDING && adv == ADV_IDLE)
440 return true;
Jon Maloy27bd9ec2017-10-13 11:04:27 +0200441 skb_queue_head_init(&xmitq);
442 tipc_group_proto_xmit(grp, m, GRP_ADV_MSG, &xmitq);
443 tipc_node_distr_xmit(grp->net, &xmitq);
444 return true;
445}
446
Jon Maloyb7d42632017-10-13 11:04:26 +0200447bool tipc_group_bc_cong(struct tipc_group *grp, int len)
448{
Jon Maloy27bd9ec2017-10-13 11:04:27 +0200449 struct tipc_member *m = NULL;
Jon Maloyb7d42632017-10-13 11:04:26 +0200450
Jon Maloy2f487712017-10-13 11:04:31 +0200451 /* If prev bcast was replicast, reject until all receivers have acked */
Jon Maloyeb929a92018-01-08 21:03:31 +0100452 if (grp->bc_ackers) {
Jon Maloy60c25302018-01-17 16:42:46 +0100453 *grp->open = false;
Jon Maloy2f487712017-10-13 11:04:31 +0200454 return true;
Jon Maloyeb929a92018-01-08 21:03:31 +0100455 }
Jon Maloy38266ca2018-01-04 15:20:44 +0100456 if (list_empty(&grp->small_win))
Jon Maloyb7d42632017-10-13 11:04:26 +0200457 return false;
458
Jon Maloy38266ca2018-01-04 15:20:44 +0100459 m = list_first_entry(&grp->small_win, struct tipc_member, small_win);
Jon Maloyb7d42632017-10-13 11:04:26 +0200460 if (m->window >= len)
461 return false;
462
Jon Maloy27bd9ec2017-10-13 11:04:27 +0200463 return tipc_group_cong(grp, m->node, m->port, len, &m);
Jon Maloyb7d42632017-10-13 11:04:26 +0200464}
465
Jon Maloyb87a5ea2017-10-13 11:04:30 +0200466/* tipc_group_sort_msg() - sort msg into queue by bcast sequence number
467 */
468static void tipc_group_sort_msg(struct sk_buff *skb, struct sk_buff_head *defq)
469{
470 struct tipc_msg *_hdr, *hdr = buf_msg(skb);
471 u16 bc_seqno = msg_grp_bc_seqno(hdr);
472 struct sk_buff *_skb, *tmp;
473 int mtyp = msg_type(hdr);
474
Jon Maloya3bada72017-10-13 11:04:33 +0200475 /* Bcast/mcast may be bypassed by ucast or other bcast, - sort it in */
Jon Maloyb87a5ea2017-10-13 11:04:30 +0200476 if (mtyp == TIPC_GRP_BCAST_MSG || mtyp == TIPC_GRP_MCAST_MSG) {
477 skb_queue_walk_safe(defq, _skb, tmp) {
478 _hdr = buf_msg(_skb);
479 if (!less(bc_seqno, msg_grp_bc_seqno(_hdr)))
480 continue;
481 __skb_queue_before(defq, _skb, skb);
482 return;
483 }
484 /* Bcast was not bypassed, - add to tail */
485 }
486 /* Unicasts are never bypassed, - always add to tail */
487 __skb_queue_tail(defq, skb);
488}
489
Jon Maloy75da2162017-10-13 11:04:23 +0200490/* tipc_group_filter_msg() - determine if we should accept arriving message
491 */
492void tipc_group_filter_msg(struct tipc_group *grp, struct sk_buff_head *inputq,
493 struct sk_buff_head *xmitq)
494{
495 struct sk_buff *skb = __skb_dequeue(inputq);
Jon Maloya3bada72017-10-13 11:04:33 +0200496 bool ack, deliver, update, leave = false;
Jon Maloyb87a5ea2017-10-13 11:04:30 +0200497 struct sk_buff_head *defq;
Jon Maloy75da2162017-10-13 11:04:23 +0200498 struct tipc_member *m;
499 struct tipc_msg *hdr;
500 u32 node, port;
Jon Maloyb87a5ea2017-10-13 11:04:30 +0200501 int mtyp, blks;
Jon Maloy75da2162017-10-13 11:04:23 +0200502
503 if (!skb)
504 return;
505
506 hdr = buf_msg(skb);
Jon Maloy75da2162017-10-13 11:04:23 +0200507 node = msg_orignode(hdr);
508 port = msg_origport(hdr);
509
510 if (!msg_in_group(hdr))
511 goto drop;
512
513 m = tipc_group_find_member(grp, node, port);
Jon Maloy38266ca2018-01-04 15:20:44 +0100514 if (!tipc_group_is_sender(m))
Jon Maloy75da2162017-10-13 11:04:23 +0200515 goto drop;
516
Jon Maloyb87a5ea2017-10-13 11:04:30 +0200517 if (less(msg_grp_bc_seqno(hdr), m->bc_rcv_nxt))
518 goto drop;
Jon Maloy5b8dddb2017-10-13 11:04:29 +0200519
Jon Maloy31c82a22017-10-13 11:04:24 +0200520 TIPC_SKB_CB(skb)->orig_member = m->instance;
Jon Maloyb87a5ea2017-10-13 11:04:30 +0200521 defq = &m->deferredq;
522 tipc_group_sort_msg(skb, defq);
Jon Maloy75da2162017-10-13 11:04:23 +0200523
Jon Maloyb87a5ea2017-10-13 11:04:30 +0200524 while ((skb = skb_peek(defq))) {
525 hdr = buf_msg(skb);
526 mtyp = msg_type(hdr);
Jon Maloy2e724dc2017-11-27 20:13:39 +0100527 blks = msg_blocks(hdr);
Jon Maloyb87a5ea2017-10-13 11:04:30 +0200528 deliver = true;
Jon Maloy2f487712017-10-13 11:04:31 +0200529 ack = false;
Jon Maloyb87a5ea2017-10-13 11:04:30 +0200530 update = false;
531
532 if (more(msg_grp_bc_seqno(hdr), m->bc_rcv_nxt))
533 break;
534
535 /* Decide what to do with message */
536 switch (mtyp) {
537 case TIPC_GRP_MCAST_MSG:
538 if (msg_nameinst(hdr) != grp->instance) {
539 update = true;
540 deliver = false;
541 }
542 /* Fall thru */
543 case TIPC_GRP_BCAST_MSG:
544 m->bc_rcv_nxt++;
Jon Maloy2f487712017-10-13 11:04:31 +0200545 ack = msg_grp_bc_ack_req(hdr);
Jon Maloyb87a5ea2017-10-13 11:04:30 +0200546 break;
547 case TIPC_GRP_UCAST_MSG:
548 break;
Jon Maloya3bada72017-10-13 11:04:33 +0200549 case TIPC_GRP_MEMBER_EVT:
550 if (m->state == MBR_LEAVING)
551 leave = true;
552 if (!grp->events)
553 deliver = false;
554 break;
Jon Maloyb87a5ea2017-10-13 11:04:30 +0200555 default:
556 break;
557 }
558
559 /* Execute decisions */
560 __skb_dequeue(defq);
561 if (deliver)
562 __skb_queue_tail(inputq, skb);
563 else
564 kfree_skb(skb);
565
Jon Maloy2f487712017-10-13 11:04:31 +0200566 if (ack)
567 tipc_group_proto_xmit(grp, m, GRP_ACK_MSG, xmitq);
568
Jon Maloya3bada72017-10-13 11:04:33 +0200569 if (leave) {
Jon Maloya3bada72017-10-13 11:04:33 +0200570 __skb_queue_purge(defq);
Jon Maloye0e853a2017-11-20 21:43:03 +0100571 tipc_group_delete_member(grp, m);
Jon Maloya3bada72017-10-13 11:04:33 +0200572 break;
573 }
Jon Maloyb87a5ea2017-10-13 11:04:30 +0200574 if (!update)
575 continue;
576
Jon Maloyb87a5ea2017-10-13 11:04:30 +0200577 tipc_group_update_rcv_win(grp, blks, node, port, xmitq);
578 }
Jon Maloy75da2162017-10-13 11:04:23 +0200579 return;
580drop:
581 kfree_skb(skb);
582}
583
Jon Maloyb7d42632017-10-13 11:04:26 +0200584void tipc_group_update_rcv_win(struct tipc_group *grp, int blks, u32 node,
585 u32 port, struct sk_buff_head *xmitq)
586{
Jon Maloy04d7b572017-10-13 11:04:34 +0200587 struct list_head *active = &grp->active;
588 int max_active = grp->max_active;
589 int reclaim_limit = max_active * 3 / 4;
590 int active_cnt = grp->active_cnt;
Jon Maloyf9c935d2017-12-29 19:48:02 +0100591 struct tipc_member *m, *rm, *pm;
Jon Maloyb7d42632017-10-13 11:04:26 +0200592
593 m = tipc_group_find_member(grp, node, port);
594 if (!m)
595 return;
596
597 m->advertised -= blks;
598
599 switch (m->state) {
600 case MBR_JOINED:
Jon Maloy4ea5dab2018-01-08 21:03:24 +0100601 /* First, decide if member can go active */
602 if (active_cnt <= max_active) {
603 m->state = MBR_ACTIVE;
604 list_add_tail(&m->list, active);
605 grp->active_cnt++;
606 tipc_group_proto_xmit(grp, m, GRP_ADV_MSG, xmitq);
607 } else {
608 m->state = MBR_PENDING;
609 list_add_tail(&m->list, &grp->pending);
610 }
611
612 if (active_cnt < reclaim_limit)
613 break;
614
615 /* Reclaim from oldest active member, if possible */
616 if (!list_empty(active)) {
Jon Maloy04d7b572017-10-13 11:04:34 +0200617 rm = list_first_entry(active, struct tipc_member, list);
618 rm->state = MBR_RECLAIMING;
Jon Maloy8d5dee22018-01-08 21:03:23 +0100619 list_del_init(&rm->list);
Jon Maloy04d7b572017-10-13 11:04:34 +0200620 tipc_group_proto_xmit(grp, rm, GRP_RECLAIM_MSG, xmitq);
Jon Maloy04d7b572017-10-13 11:04:34 +0200621 break;
622 }
Jon Maloy4ea5dab2018-01-08 21:03:24 +0100623 /* Nobody to reclaim from; - revert oldest pending to JOINED */
624 pm = list_first_entry(&grp->pending, struct tipc_member, list);
625 list_del_init(&pm->list);
626 pm->state = MBR_JOINED;
627 tipc_group_proto_xmit(grp, pm, GRP_ADV_MSG, xmitq);
628 break;
Jon Maloy04d7b572017-10-13 11:04:34 +0200629 case MBR_ACTIVE:
630 if (!list_is_last(&m->list, &grp->active))
631 list_move_tail(&m->list, &grp->active);
632 if (m->advertised > (ADV_ACTIVE * 3 / 4))
633 break;
634 tipc_group_proto_xmit(grp, m, GRP_ADV_MSG, xmitq);
Jon Maloyb7d42632017-10-13 11:04:26 +0200635 break;
Jon Maloy04d7b572017-10-13 11:04:34 +0200636 case MBR_REMITTED:
637 if (m->advertised > ADV_IDLE)
638 break;
639 m->state = MBR_JOINED;
Jon Maloy8d5dee22018-01-08 21:03:23 +0100640 grp->active_cnt--;
Jon Maloy04d7b572017-10-13 11:04:34 +0200641 if (m->advertised < ADV_IDLE) {
642 pr_warn_ratelimited("Rcv unexpected msg after REMIT\n");
643 tipc_group_proto_xmit(grp, m, GRP_ADV_MSG, xmitq);
644 }
Jon Maloy8d5dee22018-01-08 21:03:23 +0100645
Jon Maloyf9c935d2017-12-29 19:48:02 +0100646 if (list_empty(&grp->pending))
647 return;
648
649 /* Set oldest pending member to active and advertise */
650 pm = list_first_entry(&grp->pending, struct tipc_member, list);
651 pm->state = MBR_ACTIVE;
652 list_move_tail(&pm->list, &grp->active);
653 grp->active_cnt++;
654 tipc_group_proto_xmit(grp, pm, GRP_ADV_MSG, xmitq);
Jon Maloy04d7b572017-10-13 11:04:34 +0200655 break;
656 case MBR_RECLAIMING:
Jon Maloyb7d42632017-10-13 11:04:26 +0200657 case MBR_JOINING:
658 case MBR_LEAVING:
659 default:
660 break;
661 }
662}
663
Jon Maloy7ad32bc2018-01-08 21:03:26 +0100664static void tipc_group_create_event(struct tipc_group *grp,
665 struct tipc_member *m,
666 u32 event, u16 seqno,
667 struct sk_buff_head *inputq)
668{ u32 dnode = tipc_own_addr(grp->net);
669 struct tipc_event evt;
670 struct sk_buff *skb;
671 struct tipc_msg *hdr;
672
673 evt.event = event;
674 evt.found_lower = m->instance;
675 evt.found_upper = m->instance;
676 evt.port.ref = m->port;
677 evt.port.node = m->node;
678 evt.s.seq.type = grp->type;
679 evt.s.seq.lower = m->instance;
680 evt.s.seq.upper = m->instance;
681
682 skb = tipc_msg_create(TIPC_CRITICAL_IMPORTANCE, TIPC_GRP_MEMBER_EVT,
683 GROUP_H_SIZE, sizeof(evt), dnode, m->node,
684 grp->portid, m->port, 0);
685 if (!skb)
686 return;
687
688 hdr = buf_msg(skb);
689 msg_set_nametype(hdr, grp->type);
690 msg_set_grp_evt(hdr, event);
691 msg_set_dest_droppable(hdr, true);
692 msg_set_grp_bc_seqno(hdr, seqno);
693 memcpy(msg_data(hdr), &evt, sizeof(evt));
694 TIPC_SKB_CB(skb)->orig_member = m->instance;
695 __skb_queue_tail(inputq, skb);
696}
697
Jon Maloy75da2162017-10-13 11:04:23 +0200698static void tipc_group_proto_xmit(struct tipc_group *grp, struct tipc_member *m,
699 int mtyp, struct sk_buff_head *xmitq)
700{
701 struct tipc_msg *hdr;
702 struct sk_buff *skb;
Jon Maloyb7d42632017-10-13 11:04:26 +0200703 int adv = 0;
Jon Maloy75da2162017-10-13 11:04:23 +0200704
705 skb = tipc_msg_create(GROUP_PROTOCOL, mtyp, INT_H_SIZE, 0,
706 m->node, tipc_own_addr(grp->net),
707 m->port, grp->portid, 0);
708 if (!skb)
709 return;
710
Jon Maloy04d7b572017-10-13 11:04:34 +0200711 if (m->state == MBR_ACTIVE)
Jon Maloyb7d42632017-10-13 11:04:26 +0200712 adv = ADV_ACTIVE - m->advertised;
Jon Maloy04d7b572017-10-13 11:04:34 +0200713 else if (m->state == MBR_JOINED || m->state == MBR_PENDING)
714 adv = ADV_IDLE - m->advertised;
Jon Maloyb7d42632017-10-13 11:04:26 +0200715
Jon Maloy75da2162017-10-13 11:04:23 +0200716 hdr = buf_msg(skb);
Jon Maloyb7d42632017-10-13 11:04:26 +0200717
718 if (mtyp == GRP_JOIN_MSG) {
Jon Maloy75da2162017-10-13 11:04:23 +0200719 msg_set_grp_bc_syncpt(hdr, grp->bc_snd_nxt);
Jon Maloyb7d42632017-10-13 11:04:26 +0200720 msg_set_adv_win(hdr, adv);
721 m->advertised += adv;
Jon Maloya3bada72017-10-13 11:04:33 +0200722 } else if (mtyp == GRP_LEAVE_MSG) {
723 msg_set_grp_bc_syncpt(hdr, grp->bc_snd_nxt);
Jon Maloyb7d42632017-10-13 11:04:26 +0200724 } else if (mtyp == GRP_ADV_MSG) {
725 msg_set_adv_win(hdr, adv);
726 m->advertised += adv;
Jon Maloy2f487712017-10-13 11:04:31 +0200727 } else if (mtyp == GRP_ACK_MSG) {
728 msg_set_grp_bc_acked(hdr, m->bc_rcv_nxt);
Jon Maloy04d7b572017-10-13 11:04:34 +0200729 } else if (mtyp == GRP_REMIT_MSG) {
730 msg_set_grp_remitted(hdr, m->window);
Jon Maloyb7d42632017-10-13 11:04:26 +0200731 }
Jon Maloy23483392017-12-18 17:34:16 +0100732 msg_set_dest_droppable(hdr, true);
Jon Maloy75da2162017-10-13 11:04:23 +0200733 __skb_queue_tail(xmitq, skb);
734}
735
Jon Maloyb7d42632017-10-13 11:04:26 +0200736void tipc_group_proto_rcv(struct tipc_group *grp, bool *usr_wakeup,
737 struct tipc_msg *hdr, struct sk_buff_head *inputq,
Jon Maloy75da2162017-10-13 11:04:23 +0200738 struct sk_buff_head *xmitq)
739{
740 u32 node = msg_orignode(hdr);
741 u32 port = msg_origport(hdr);
Jon Maloy04d7b572017-10-13 11:04:34 +0200742 struct tipc_member *m, *pm;
Jon Maloy04d7b572017-10-13 11:04:34 +0200743 u16 remitted, in_flight;
Jon Maloy75da2162017-10-13 11:04:23 +0200744
745 if (!grp)
746 return;
747
Jon Maloy232d07b2018-01-08 21:03:30 +0100748 if (grp->scope == TIPC_NODE_SCOPE && node != tipc_own_addr(grp->net))
749 return;
750
Jon Maloy75da2162017-10-13 11:04:23 +0200751 m = tipc_group_find_member(grp, node, port);
752
753 switch (msg_type(hdr)) {
754 case GRP_JOIN_MSG:
755 if (!m)
756 m = tipc_group_create_member(grp, node, port,
Jon Maloyd12d2e12018-01-08 21:03:28 +0100757 0, MBR_JOINING);
Jon Maloy75da2162017-10-13 11:04:23 +0200758 if (!m)
759 return;
Jon Maloya3bada72017-10-13 11:04:33 +0200760 m->bc_syncpt = msg_grp_bc_syncpt(hdr);
761 m->bc_rcv_nxt = m->bc_syncpt;
Jon Maloyb7d42632017-10-13 11:04:26 +0200762 m->window += msg_adv_win(hdr);
Jon Maloy75da2162017-10-13 11:04:23 +0200763
Jon Maloyd12d2e12018-01-08 21:03:28 +0100764 /* Wait until PUBLISH event is received if necessary */
765 if (m->state != MBR_PUBLISHED)
766 return;
767
768 /* Member can be taken into service */
769 m->state = MBR_JOINED;
Jon Maloyeb929a92018-01-08 21:03:31 +0100770 tipc_group_open(m, usr_wakeup);
Jon Maloybb25c382017-12-20 11:03:15 +0100771 tipc_group_update_member(m, 0);
Jon Maloyd12d2e12018-01-08 21:03:28 +0100772 tipc_group_proto_xmit(grp, m, GRP_ADV_MSG, xmitq);
773 tipc_group_create_event(grp, m, TIPC_PUBLISHED,
774 m->bc_syncpt, inputq);
Jon Maloy75da2162017-10-13 11:04:23 +0200775 return;
776 case GRP_LEAVE_MSG:
777 if (!m)
778 return;
Jon Maloya3bada72017-10-13 11:04:33 +0200779 m->bc_syncpt = msg_grp_bc_syncpt(hdr);
Jon Maloy3f42f5f2017-12-18 18:13:34 +0100780 list_del_init(&m->list);
Jon Maloyeb929a92018-01-08 21:03:31 +0100781 tipc_group_open(m, usr_wakeup);
Jon Maloyc2b22bc2018-01-08 21:03:27 +0100782 tipc_group_decr_active(grp, m);
783 m->state = MBR_LEAVING;
Jon Maloy7ad32bc2018-01-08 21:03:26 +0100784 tipc_group_create_event(grp, m, TIPC_WITHDRAWN,
785 m->bc_syncpt, inputq);
Jon Maloyb7d42632017-10-13 11:04:26 +0200786 return;
787 case GRP_ADV_MSG:
788 if (!m)
789 return;
790 m->window += msg_adv_win(hdr);
Jon Maloyeb929a92018-01-08 21:03:31 +0100791 tipc_group_open(m, usr_wakeup);
Jon Maloy75da2162017-10-13 11:04:23 +0200792 return;
Jon Maloy2f487712017-10-13 11:04:31 +0200793 case GRP_ACK_MSG:
794 if (!m)
795 return;
796 m->bc_acked = msg_grp_bc_acked(hdr);
797 if (--grp->bc_ackers)
Jon Maloyeb929a92018-01-08 21:03:31 +0100798 return;
799 list_del_init(&m->small_win);
Jon Maloy60c25302018-01-17 16:42:46 +0100800 *m->group->open = true;
Jon Maloy2f487712017-10-13 11:04:31 +0200801 *usr_wakeup = true;
Jon Maloyeb929a92018-01-08 21:03:31 +0100802 tipc_group_update_member(m, 0);
Jon Maloy2f487712017-10-13 11:04:31 +0200803 return;
Jon Maloy04d7b572017-10-13 11:04:34 +0200804 case GRP_RECLAIM_MSG:
805 if (!m)
806 return;
Jon Maloy04d7b572017-10-13 11:04:34 +0200807 tipc_group_proto_xmit(grp, m, GRP_REMIT_MSG, xmitq);
808 m->window = ADV_IDLE;
Jon Maloyeb929a92018-01-08 21:03:31 +0100809 tipc_group_open(m, usr_wakeup);
Jon Maloy04d7b572017-10-13 11:04:34 +0200810 return;
811 case GRP_REMIT_MSG:
812 if (!m || m->state != MBR_RECLAIMING)
813 return;
814
Jon Maloy04d7b572017-10-13 11:04:34 +0200815 remitted = msg_grp_remitted(hdr);
816
817 /* Messages preceding the REMIT still in receive queue */
818 if (m->advertised > remitted) {
819 m->state = MBR_REMITTED;
820 in_flight = m->advertised - remitted;
Jon Maloyf9c935d2017-12-29 19:48:02 +0100821 m->advertised = ADV_IDLE + in_flight;
822 return;
Jon Maloy04d7b572017-10-13 11:04:34 +0200823 }
Jon Maloy8d5dee22018-01-08 21:03:23 +0100824 /* This should never happen */
Jon Maloy04d7b572017-10-13 11:04:34 +0200825 if (m->advertised < remitted)
Jon Maloy8d5dee22018-01-08 21:03:23 +0100826 pr_warn_ratelimited("Unexpected REMIT msg\n");
Jon Maloy04d7b572017-10-13 11:04:34 +0200827
Jon Maloy8d5dee22018-01-08 21:03:23 +0100828 /* All messages preceding the REMIT have been read */
829 m->state = MBR_JOINED;
Jon Maloyf9c935d2017-12-29 19:48:02 +0100830 grp->active_cnt--;
Jon Maloy8d5dee22018-01-08 21:03:23 +0100831 m->advertised = ADV_IDLE;
Jon Maloy04d7b572017-10-13 11:04:34 +0200832
833 /* Set oldest pending member to active and advertise */
834 if (list_empty(&grp->pending))
835 return;
836 pm = list_first_entry(&grp->pending, struct tipc_member, list);
837 pm->state = MBR_ACTIVE;
838 list_move_tail(&pm->list, &grp->active);
839 grp->active_cnt++;
840 if (pm->advertised <= (ADV_ACTIVE * 3 / 4))
841 tipc_group_proto_xmit(grp, pm, GRP_ADV_MSG, xmitq);
842 return;
Jon Maloy75da2162017-10-13 11:04:23 +0200843 default:
844 pr_warn("Received unknown GROUP_PROTO message\n");
845 }
846}
847
Jon Maloyb7d42632017-10-13 11:04:26 +0200848/* tipc_group_member_evt() - receive and handle a member up/down event
849 */
Jon Maloy75da2162017-10-13 11:04:23 +0200850void tipc_group_member_evt(struct tipc_group *grp,
Jon Maloyb7d42632017-10-13 11:04:26 +0200851 bool *usr_wakeup,
852 int *sk_rcvbuf,
Jon Maloy7ad32bc2018-01-08 21:03:26 +0100853 struct tipc_msg *hdr,
Jon Maloyae236fb2017-10-13 11:04:25 +0200854 struct sk_buff_head *inputq,
Jon Maloy75da2162017-10-13 11:04:23 +0200855 struct sk_buff_head *xmitq)
856{
Jon Maloy75da2162017-10-13 11:04:23 +0200857 struct tipc_event *evt = (void *)msg_data(hdr);
Jon Maloyae236fb2017-10-13 11:04:25 +0200858 u32 instance = evt->found_lower;
Jon Maloy75da2162017-10-13 11:04:23 +0200859 u32 node = evt->port.node;
860 u32 port = evt->port.ref;
Jon Maloyae236fb2017-10-13 11:04:25 +0200861 int event = evt->event;
Jon Maloy75da2162017-10-13 11:04:23 +0200862 struct tipc_member *m;
863 struct net *net;
864 u32 self;
865
866 if (!grp)
Jon Maloy7ad32bc2018-01-08 21:03:26 +0100867 return;
Jon Maloy75da2162017-10-13 11:04:23 +0200868
869 net = grp->net;
870 self = tipc_own_addr(net);
871 if (!grp->loopback && node == self && port == grp->portid)
Jon Maloy7ad32bc2018-01-08 21:03:26 +0100872 return;
Jon Maloyae236fb2017-10-13 11:04:25 +0200873
Jon Maloy75da2162017-10-13 11:04:23 +0200874 m = tipc_group_find_member(grp, node, port);
875
Jon Maloyd12d2e12018-01-08 21:03:28 +0100876 switch (event) {
877 case TIPC_PUBLISHED:
878 /* Send and wait for arrival of JOIN message if necessary */
879 if (!m) {
880 m = tipc_group_create_member(grp, node, port, instance,
881 MBR_PUBLISHED);
882 if (!m)
883 break;
884 tipc_group_update_member(m, 0);
885 tipc_group_proto_xmit(grp, m, GRP_JOIN_MSG, xmitq);
886 break;
Jon Maloyae236fb2017-10-13 11:04:25 +0200887 }
Jon Maloyd12d2e12018-01-08 21:03:28 +0100888
889 if (m->state != MBR_JOINING)
890 break;
891
892 /* Member can be taken into service */
893 m->instance = instance;
894 m->state = MBR_JOINED;
Jon Maloyeb929a92018-01-08 21:03:31 +0100895 tipc_group_open(m, usr_wakeup);
Jon Maloyd84d1b32018-01-04 15:20:45 +0100896 tipc_group_update_member(m, 0);
Jon Maloyd12d2e12018-01-08 21:03:28 +0100897 tipc_group_proto_xmit(grp, m, GRP_JOIN_MSG, xmitq);
898 tipc_group_create_event(grp, m, TIPC_PUBLISHED,
899 m->bc_syncpt, inputq);
900 break;
901 case TIPC_WITHDRAWN:
Jon Maloy75da2162017-10-13 11:04:23 +0200902 if (!m)
Jon Maloyd12d2e12018-01-08 21:03:28 +0100903 break;
Jon Maloyae236fb2017-10-13 11:04:25 +0200904
Jon Maloyc2b22bc2018-01-08 21:03:27 +0100905 tipc_group_decr_active(grp, m);
906 m->state = MBR_LEAVING;
Jon Maloy3f42f5f2017-12-18 18:13:34 +0100907 list_del_init(&m->list);
Jon Maloyeb929a92018-01-08 21:03:31 +0100908 tipc_group_open(m, usr_wakeup);
Jon Maloyc2b22bc2018-01-08 21:03:27 +0100909
910 /* Only send event if no LEAVE message can be expected */
911 if (!tipc_node_is_up(net, node))
912 tipc_group_create_event(grp, m, TIPC_WITHDRAWN,
913 m->bc_rcv_nxt, inputq);
Jon Maloyd12d2e12018-01-08 21:03:28 +0100914 break;
915 default:
916 break;
Jon Maloy75da2162017-10-13 11:04:23 +0200917 }
Jon Maloyb7d42632017-10-13 11:04:26 +0200918 *sk_rcvbuf = tipc_group_rcvbuf_limit(grp);
Jon Maloy75da2162017-10-13 11:04:23 +0200919}