Jon Maloy | 75da216 | 2017-10-13 11:04:23 +0200 | [diff] [blame] | 1 | /* |
| 2 | * net/tipc/group.c: TIPC group messaging code |
| 3 | * |
| 4 | * Copyright (c) 2017, Ericsson AB |
Jon Maloy | b6f88d9 | 2020-11-25 13:29:15 -0500 | [diff] [blame] | 5 | * Copyright (c) 2020, Red Hat Inc |
Jon Maloy | 75da216 | 2017-10-13 11:04:23 +0200 | [diff] [blame] | 6 | * All rights reserved. |
| 7 | * |
| 8 | * Redistribution and use in source and binary forms, with or without |
| 9 | * modification, are permitted provided that the following conditions are met: |
| 10 | * |
| 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. |
| 19 | * |
| 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. |
| 23 | * |
| 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. |
| 35 | */ |
| 36 | |
| 37 | #include "core.h" |
| 38 | #include "addr.h" |
| 39 | #include "group.h" |
| 40 | #include "bcast.h" |
Jon Maloy | 026321c | 2018-02-15 10:40:51 +0100 | [diff] [blame] | 41 | #include "topsrv.h" |
Jon Maloy | 75da216 | 2017-10-13 11:04:23 +0200 | [diff] [blame] | 42 | #include "msg.h" |
| 43 | #include "socket.h" |
| 44 | #include "node.h" |
| 45 | #include "name_table.h" |
| 46 | #include "subscr.h" |
| 47 | |
| 48 | #define ADV_UNIT (((MAX_MSG_SIZE + MAX_H_SIZE) / FLOWCTL_BLK_SZ) + 1) |
| 49 | #define ADV_IDLE ADV_UNIT |
Jon Maloy | b7d4263 | 2017-10-13 11:04:26 +0200 | [diff] [blame] | 50 | #define ADV_ACTIVE (ADV_UNIT * 12) |
Jon Maloy | 75da216 | 2017-10-13 11:04:23 +0200 | [diff] [blame] | 51 | |
| 52 | enum mbr_state { |
Jon Maloy | 75da216 | 2017-10-13 11:04:23 +0200 | [diff] [blame] | 53 | MBR_JOINING, |
| 54 | MBR_PUBLISHED, |
| 55 | MBR_JOINED, |
Jon Maloy | 04d7b57 | 2017-10-13 11:04:34 +0200 | [diff] [blame] | 56 | MBR_PENDING, |
| 57 | MBR_ACTIVE, |
| 58 | MBR_RECLAIMING, |
| 59 | MBR_REMITTED, |
Jon Maloy | 75da216 | 2017-10-13 11:04:23 +0200 | [diff] [blame] | 60 | MBR_LEAVING |
| 61 | }; |
| 62 | |
| 63 | struct tipc_member { |
| 64 | struct rb_node tree_node; |
| 65 | struct list_head list; |
Jon Maloy | 38266ca | 2018-01-04 15:20:44 +0100 | [diff] [blame] | 66 | struct list_head small_win; |
Jon Maloy | b87a5ea | 2017-10-13 11:04:30 +0200 | [diff] [blame] | 67 | struct sk_buff_head deferredq; |
Jon Maloy | b7d4263 | 2017-10-13 11:04:26 +0200 | [diff] [blame] | 68 | struct tipc_group *group; |
Jon Maloy | 75da216 | 2017-10-13 11:04:23 +0200 | [diff] [blame] | 69 | u32 node; |
| 70 | u32 port; |
Jon Maloy | 31c82a2 | 2017-10-13 11:04:24 +0200 | [diff] [blame] | 71 | u32 instance; |
Jon Maloy | 75da216 | 2017-10-13 11:04:23 +0200 | [diff] [blame] | 72 | enum mbr_state state; |
Jon Maloy | b7d4263 | 2017-10-13 11:04:26 +0200 | [diff] [blame] | 73 | u16 advertised; |
| 74 | u16 window; |
Jon Maloy | 75da216 | 2017-10-13 11:04:23 +0200 | [diff] [blame] | 75 | u16 bc_rcv_nxt; |
Jon Maloy | a3bada7 | 2017-10-13 11:04:33 +0200 | [diff] [blame] | 76 | u16 bc_syncpt; |
Jon Maloy | 2f48771 | 2017-10-13 11:04:31 +0200 | [diff] [blame] | 77 | u16 bc_acked; |
Jon Maloy | 75da216 | 2017-10-13 11:04:23 +0200 | [diff] [blame] | 78 | }; |
| 79 | |
| 80 | struct tipc_group { |
| 81 | struct rb_root members; |
Jon Maloy | 38266ca | 2018-01-04 15:20:44 +0100 | [diff] [blame] | 82 | struct list_head small_win; |
Jon Maloy | 04d7b57 | 2017-10-13 11:04:34 +0200 | [diff] [blame] | 83 | struct list_head pending; |
| 84 | struct list_head active; |
Jon Maloy | 75da216 | 2017-10-13 11:04:23 +0200 | [diff] [blame] | 85 | struct tipc_nlist dests; |
| 86 | struct net *net; |
| 87 | int subid; |
| 88 | u32 type; |
| 89 | u32 instance; |
Jon Maloy | 75da216 | 2017-10-13 11:04:23 +0200 | [diff] [blame] | 90 | u32 scope; |
| 91 | u32 portid; |
| 92 | u16 member_cnt; |
Jon Maloy | 04d7b57 | 2017-10-13 11:04:34 +0200 | [diff] [blame] | 93 | u16 active_cnt; |
| 94 | u16 max_active; |
Jon Maloy | 75da216 | 2017-10-13 11:04:23 +0200 | [diff] [blame] | 95 | u16 bc_snd_nxt; |
Jon Maloy | 2f48771 | 2017-10-13 11:04:31 +0200 | [diff] [blame] | 96 | u16 bc_ackers; |
Jon Maloy | 60c2530 | 2018-01-17 16:42:46 +0100 | [diff] [blame] | 97 | bool *open; |
Jon Maloy | 75da216 | 2017-10-13 11:04:23 +0200 | [diff] [blame] | 98 | bool loopback; |
Jon Maloy | ae236fb | 2017-10-13 11:04:25 +0200 | [diff] [blame] | 99 | bool events; |
Jon Maloy | 75da216 | 2017-10-13 11:04:23 +0200 | [diff] [blame] | 100 | }; |
| 101 | |
| 102 | static void tipc_group_proto_xmit(struct tipc_group *grp, struct tipc_member *m, |
| 103 | int mtyp, struct sk_buff_head *xmitq); |
| 104 | |
Jon Maloy | eb929a9 | 2018-01-08 21:03:31 +0100 | [diff] [blame] | 105 | static void tipc_group_open(struct tipc_member *m, bool *wakeup) |
| 106 | { |
| 107 | *wakeup = false; |
| 108 | if (list_empty(&m->small_win)) |
| 109 | return; |
| 110 | list_del_init(&m->small_win); |
Jon Maloy | 60c2530 | 2018-01-17 16:42:46 +0100 | [diff] [blame] | 111 | *m->group->open = true; |
Jon Maloy | eb929a9 | 2018-01-08 21:03:31 +0100 | [diff] [blame] | 112 | *wakeup = true; |
| 113 | } |
| 114 | |
Jon Maloy | 04d7b57 | 2017-10-13 11:04:34 +0200 | [diff] [blame] | 115 | static void tipc_group_decr_active(struct tipc_group *grp, |
| 116 | struct tipc_member *m) |
| 117 | { |
Jon Maloy | f9c935d | 2017-12-29 19:48:02 +0100 | [diff] [blame] | 118 | if (m->state == MBR_ACTIVE || m->state == MBR_RECLAIMING || |
| 119 | m->state == MBR_REMITTED) |
Jon Maloy | 04d7b57 | 2017-10-13 11:04:34 +0200 | [diff] [blame] | 120 | grp->active_cnt--; |
| 121 | } |
| 122 | |
Jon Maloy | b7d4263 | 2017-10-13 11:04:26 +0200 | [diff] [blame] | 123 | static int tipc_group_rcvbuf_limit(struct tipc_group *grp) |
| 124 | { |
Jon Maloy | 04d7b57 | 2017-10-13 11:04:34 +0200 | [diff] [blame] | 125 | int max_active, active_pool, idle_pool; |
Jon Maloy | b7d4263 | 2017-10-13 11:04:26 +0200 | [diff] [blame] | 126 | int mcnt = grp->member_cnt + 1; |
| 127 | |
Jon Maloy | 04d7b57 | 2017-10-13 11:04:34 +0200 | [diff] [blame] | 128 | /* Limit simultaneous reception from other members */ |
| 129 | max_active = min(mcnt / 8, 64); |
| 130 | max_active = max(max_active, 16); |
| 131 | grp->max_active = max_active; |
| 132 | |
| 133 | /* Reserve blocks for active and idle members */ |
| 134 | active_pool = max_active * ADV_ACTIVE; |
| 135 | idle_pool = (mcnt - max_active) * ADV_IDLE; |
| 136 | |
Jon Maloy | b7d4263 | 2017-10-13 11:04:26 +0200 | [diff] [blame] | 137 | /* Scale to bytes, considering worst-case truesize/msgsize ratio */ |
Jon Maloy | 04d7b57 | 2017-10-13 11:04:34 +0200 | [diff] [blame] | 138 | return (active_pool + idle_pool) * FLOWCTL_BLK_SZ * 4; |
Jon Maloy | b7d4263 | 2017-10-13 11:04:26 +0200 | [diff] [blame] | 139 | } |
| 140 | |
Jon Maloy | 75da216 | 2017-10-13 11:04:23 +0200 | [diff] [blame] | 141 | u16 tipc_group_bc_snd_nxt(struct tipc_group *grp) |
| 142 | { |
| 143 | return grp->bc_snd_nxt; |
| 144 | } |
| 145 | |
Jon Maloy | 38266ca | 2018-01-04 15:20:44 +0100 | [diff] [blame] | 146 | static bool tipc_group_is_receiver(struct tipc_member *m) |
Jon Maloy | b7d4263 | 2017-10-13 11:04:26 +0200 | [diff] [blame] | 147 | { |
Jon Maloy | 0233493 | 2018-01-08 21:03:25 +0100 | [diff] [blame] | 148 | return m && m->state != MBR_JOINING && m->state != MBR_LEAVING; |
Jon Maloy | b7d4263 | 2017-10-13 11:04:26 +0200 | [diff] [blame] | 149 | } |
| 150 | |
Jon Maloy | 38266ca | 2018-01-04 15:20:44 +0100 | [diff] [blame] | 151 | static bool tipc_group_is_sender(struct tipc_member *m) |
Jon Maloy | 75da216 | 2017-10-13 11:04:23 +0200 | [diff] [blame] | 152 | { |
Jon Maloy | d12d2e1 | 2018-01-08 21:03:28 +0100 | [diff] [blame] | 153 | return m && m->state != MBR_JOINING && m->state != MBR_PUBLISHED; |
Jon Maloy | 75da216 | 2017-10-13 11:04:23 +0200 | [diff] [blame] | 154 | } |
| 155 | |
Jon Maloy | ee106d7 | 2017-10-13 11:04:28 +0200 | [diff] [blame] | 156 | u32 tipc_group_exclude(struct tipc_group *grp) |
| 157 | { |
| 158 | if (!grp->loopback) |
| 159 | return grp->portid; |
| 160 | return 0; |
| 161 | } |
| 162 | |
Jon Maloy | 75da216 | 2017-10-13 11:04:23 +0200 | [diff] [blame] | 163 | struct tipc_group *tipc_group_create(struct net *net, u32 portid, |
Jon Maloy | 60c2530 | 2018-01-17 16:42:46 +0100 | [diff] [blame] | 164 | struct tipc_group_req *mreq, |
| 165 | bool *group_is_open) |
Jon Maloy | 75da216 | 2017-10-13 11:04:23 +0200 | [diff] [blame] | 166 | { |
Jon Maloy | 232d07b | 2018-01-08 21:03:30 +0100 | [diff] [blame] | 167 | u32 filter = TIPC_SUB_PORTS | TIPC_SUB_NO_STATUS; |
| 168 | bool global = mreq->scope != TIPC_NODE_SCOPE; |
Jon Maloy | 75da216 | 2017-10-13 11:04:23 +0200 | [diff] [blame] | 169 | struct tipc_group *grp; |
| 170 | u32 type = mreq->type; |
| 171 | |
| 172 | grp = kzalloc(sizeof(*grp), GFP_ATOMIC); |
| 173 | if (!grp) |
| 174 | return NULL; |
| 175 | tipc_nlist_init(&grp->dests, tipc_own_addr(net)); |
Jon Maloy | 38266ca | 2018-01-04 15:20:44 +0100 | [diff] [blame] | 176 | INIT_LIST_HEAD(&grp->small_win); |
Jon Maloy | 04d7b57 | 2017-10-13 11:04:34 +0200 | [diff] [blame] | 177 | INIT_LIST_HEAD(&grp->active); |
| 178 | INIT_LIST_HEAD(&grp->pending); |
Jon Maloy | 75da216 | 2017-10-13 11:04:23 +0200 | [diff] [blame] | 179 | grp->members = RB_ROOT; |
| 180 | grp->net = net; |
| 181 | grp->portid = portid; |
Jon Maloy | 75da216 | 2017-10-13 11:04:23 +0200 | [diff] [blame] | 182 | grp->type = type; |
| 183 | grp->instance = mreq->instance; |
| 184 | grp->scope = mreq->scope; |
| 185 | grp->loopback = mreq->flags & TIPC_GROUP_LOOPBACK; |
Jon Maloy | ae236fb | 2017-10-13 11:04:25 +0200 | [diff] [blame] | 186 | grp->events = mreq->flags & TIPC_GROUP_MEMBER_EVTS; |
Jon Maloy | 60c2530 | 2018-01-17 16:42:46 +0100 | [diff] [blame] | 187 | grp->open = group_is_open; |
Jon Maloy | 1b22bca | 2018-02-26 20:14:04 +0100 | [diff] [blame] | 188 | *grp->open = false; |
Jon Maloy | 232d07b | 2018-01-08 21:03:30 +0100 | [diff] [blame] | 189 | filter |= global ? TIPC_SUB_CLUSTER_SCOPE : TIPC_SUB_NODE_SCOPE; |
| 190 | if (tipc_topsrv_kern_subscr(net, portid, type, 0, ~0, |
| 191 | filter, &grp->subid)) |
Jon Maloy | 75da216 | 2017-10-13 11:04:23 +0200 | [diff] [blame] | 192 | return grp; |
| 193 | kfree(grp); |
| 194 | return NULL; |
| 195 | } |
| 196 | |
Jon Maloy | d12d2e1 | 2018-01-08 21:03:28 +0100 | [diff] [blame] | 197 | void tipc_group_join(struct net *net, struct tipc_group *grp, int *sk_rcvbuf) |
| 198 | { |
| 199 | struct rb_root *tree = &grp->members; |
| 200 | struct tipc_member *m, *tmp; |
| 201 | struct sk_buff_head xmitq; |
| 202 | |
Jon Maloy | e654f9f | 2019-08-15 16:42:50 +0200 | [diff] [blame] | 203 | __skb_queue_head_init(&xmitq); |
Jon Maloy | d12d2e1 | 2018-01-08 21:03:28 +0100 | [diff] [blame] | 204 | rbtree_postorder_for_each_entry_safe(m, tmp, tree, tree_node) { |
| 205 | tipc_group_proto_xmit(grp, m, GRP_JOIN_MSG, &xmitq); |
| 206 | tipc_group_update_member(m, 0); |
| 207 | } |
| 208 | tipc_node_distr_xmit(net, &xmitq); |
| 209 | *sk_rcvbuf = tipc_group_rcvbuf_limit(grp); |
| 210 | } |
| 211 | |
Jon Maloy | 75da216 | 2017-10-13 11:04:23 +0200 | [diff] [blame] | 212 | void tipc_group_delete(struct net *net, struct tipc_group *grp) |
| 213 | { |
| 214 | struct rb_root *tree = &grp->members; |
| 215 | struct tipc_member *m, *tmp; |
| 216 | struct sk_buff_head xmitq; |
| 217 | |
| 218 | __skb_queue_head_init(&xmitq); |
| 219 | |
| 220 | rbtree_postorder_for_each_entry_safe(m, tmp, tree, tree_node) { |
| 221 | tipc_group_proto_xmit(grp, m, GRP_LEAVE_MSG, &xmitq); |
Xin Long | 5cf0261 | 2019-06-16 17:24:07 +0800 | [diff] [blame] | 222 | __skb_queue_purge(&m->deferredq); |
Jon Maloy | 75da216 | 2017-10-13 11:04:23 +0200 | [diff] [blame] | 223 | list_del(&m->list); |
| 224 | kfree(m); |
| 225 | } |
| 226 | tipc_node_distr_xmit(net, &xmitq); |
| 227 | tipc_nlist_purge(&grp->dests); |
| 228 | tipc_topsrv_kern_unsubscr(net, grp->subid); |
| 229 | kfree(grp); |
| 230 | } |
| 231 | |
YueHaibing | e064cce | 2018-07-19 17:16:59 +0800 | [diff] [blame] | 232 | static struct tipc_member *tipc_group_find_member(struct tipc_group *grp, |
| 233 | u32 node, u32 port) |
Jon Maloy | 75da216 | 2017-10-13 11:04:23 +0200 | [diff] [blame] | 234 | { |
| 235 | struct rb_node *n = grp->members.rb_node; |
| 236 | u64 nkey, key = (u64)node << 32 | port; |
| 237 | struct tipc_member *m; |
| 238 | |
| 239 | while (n) { |
| 240 | m = container_of(n, struct tipc_member, tree_node); |
| 241 | nkey = (u64)m->node << 32 | m->port; |
| 242 | if (key < nkey) |
| 243 | n = n->rb_left; |
| 244 | else if (key > nkey) |
| 245 | n = n->rb_right; |
| 246 | else |
| 247 | return m; |
| 248 | } |
| 249 | return NULL; |
| 250 | } |
| 251 | |
Jon Maloy | 27bd9ec | 2017-10-13 11:04:27 +0200 | [diff] [blame] | 252 | static struct tipc_member *tipc_group_find_dest(struct tipc_group *grp, |
| 253 | u32 node, u32 port) |
| 254 | { |
| 255 | struct tipc_member *m; |
| 256 | |
| 257 | m = tipc_group_find_member(grp, node, port); |
Jon Maloy | 38266ca | 2018-01-04 15:20:44 +0100 | [diff] [blame] | 258 | if (m && tipc_group_is_receiver(m)) |
Jon Maloy | 27bd9ec | 2017-10-13 11:04:27 +0200 | [diff] [blame] | 259 | return m; |
| 260 | return NULL; |
| 261 | } |
| 262 | |
Jon Maloy | 75da216 | 2017-10-13 11:04:23 +0200 | [diff] [blame] | 263 | static struct tipc_member *tipc_group_find_node(struct tipc_group *grp, |
| 264 | u32 node) |
| 265 | { |
| 266 | struct tipc_member *m; |
| 267 | struct rb_node *n; |
| 268 | |
| 269 | for (n = rb_first(&grp->members); n; n = rb_next(n)) { |
| 270 | m = container_of(n, struct tipc_member, tree_node); |
| 271 | if (m->node == node) |
| 272 | return m; |
| 273 | } |
| 274 | return NULL; |
| 275 | } |
| 276 | |
Peilin Ye | bb3a420 | 2020-09-13 04:06:05 -0400 | [diff] [blame] | 277 | static int tipc_group_add_to_tree(struct tipc_group *grp, |
| 278 | struct tipc_member *m) |
Jon Maloy | 75da216 | 2017-10-13 11:04:23 +0200 | [diff] [blame] | 279 | { |
| 280 | u64 nkey, key = (u64)m->node << 32 | m->port; |
| 281 | struct rb_node **n, *parent = NULL; |
| 282 | struct tipc_member *tmp; |
| 283 | |
| 284 | n = &grp->members.rb_node; |
| 285 | while (*n) { |
| 286 | tmp = container_of(*n, struct tipc_member, tree_node); |
| 287 | parent = *n; |
| 288 | tmp = container_of(parent, struct tipc_member, tree_node); |
| 289 | nkey = (u64)tmp->node << 32 | tmp->port; |
| 290 | if (key < nkey) |
| 291 | n = &(*n)->rb_left; |
| 292 | else if (key > nkey) |
| 293 | n = &(*n)->rb_right; |
| 294 | else |
Peilin Ye | bb3a420 | 2020-09-13 04:06:05 -0400 | [diff] [blame] | 295 | return -EEXIST; |
Jon Maloy | 75da216 | 2017-10-13 11:04:23 +0200 | [diff] [blame] | 296 | } |
| 297 | rb_link_node(&m->tree_node, parent, n); |
| 298 | rb_insert_color(&m->tree_node, &grp->members); |
Peilin Ye | bb3a420 | 2020-09-13 04:06:05 -0400 | [diff] [blame] | 299 | return 0; |
Jon Maloy | 75da216 | 2017-10-13 11:04:23 +0200 | [diff] [blame] | 300 | } |
| 301 | |
| 302 | static struct tipc_member *tipc_group_create_member(struct tipc_group *grp, |
| 303 | u32 node, u32 port, |
Jon Maloy | d12d2e1 | 2018-01-08 21:03:28 +0100 | [diff] [blame] | 304 | u32 instance, int state) |
Jon Maloy | 75da216 | 2017-10-13 11:04:23 +0200 | [diff] [blame] | 305 | { |
| 306 | struct tipc_member *m; |
Peilin Ye | bb3a420 | 2020-09-13 04:06:05 -0400 | [diff] [blame] | 307 | int ret; |
Jon Maloy | 75da216 | 2017-10-13 11:04:23 +0200 | [diff] [blame] | 308 | |
| 309 | m = kzalloc(sizeof(*m), GFP_ATOMIC); |
| 310 | if (!m) |
| 311 | return NULL; |
| 312 | INIT_LIST_HEAD(&m->list); |
Jon Maloy | 38266ca | 2018-01-04 15:20:44 +0100 | [diff] [blame] | 313 | INIT_LIST_HEAD(&m->small_win); |
Jon Maloy | b87a5ea | 2017-10-13 11:04:30 +0200 | [diff] [blame] | 314 | __skb_queue_head_init(&m->deferredq); |
Jon Maloy | b7d4263 | 2017-10-13 11:04:26 +0200 | [diff] [blame] | 315 | m->group = grp; |
Jon Maloy | 75da216 | 2017-10-13 11:04:23 +0200 | [diff] [blame] | 316 | m->node = node; |
| 317 | m->port = port; |
Jon Maloy | d12d2e1 | 2018-01-08 21:03:28 +0100 | [diff] [blame] | 318 | m->instance = instance; |
Jon Maloy | 2f48771 | 2017-10-13 11:04:31 +0200 | [diff] [blame] | 319 | m->bc_acked = grp->bc_snd_nxt - 1; |
Peilin Ye | bb3a420 | 2020-09-13 04:06:05 -0400 | [diff] [blame] | 320 | ret = tipc_group_add_to_tree(grp, m); |
| 321 | if (ret < 0) { |
| 322 | kfree(m); |
| 323 | return NULL; |
| 324 | } |
Jon Maloy | 75da216 | 2017-10-13 11:04:23 +0200 | [diff] [blame] | 325 | grp->member_cnt++; |
Jon Maloy | 75da216 | 2017-10-13 11:04:23 +0200 | [diff] [blame] | 326 | tipc_nlist_add(&grp->dests, m->node); |
| 327 | m->state = state; |
| 328 | return m; |
| 329 | } |
| 330 | |
Jon Maloy | d12d2e1 | 2018-01-08 21:03:28 +0100 | [diff] [blame] | 331 | void tipc_group_add_member(struct tipc_group *grp, u32 node, |
| 332 | u32 port, u32 instance) |
Jon Maloy | 75da216 | 2017-10-13 11:04:23 +0200 | [diff] [blame] | 333 | { |
Jon Maloy | d12d2e1 | 2018-01-08 21:03:28 +0100 | [diff] [blame] | 334 | tipc_group_create_member(grp, node, port, instance, MBR_PUBLISHED); |
Jon Maloy | 75da216 | 2017-10-13 11:04:23 +0200 | [diff] [blame] | 335 | } |
| 336 | |
| 337 | static void tipc_group_delete_member(struct tipc_group *grp, |
| 338 | struct tipc_member *m) |
| 339 | { |
| 340 | rb_erase(&m->tree_node, &grp->members); |
| 341 | grp->member_cnt--; |
Jon Maloy | 2f48771 | 2017-10-13 11:04:31 +0200 | [diff] [blame] | 342 | |
| 343 | /* Check if we were waiting for replicast ack from this member */ |
| 344 | if (grp->bc_ackers && less(m->bc_acked, grp->bc_snd_nxt - 1)) |
| 345 | grp->bc_ackers--; |
| 346 | |
Jon Maloy | 75da216 | 2017-10-13 11:04:23 +0200 | [diff] [blame] | 347 | list_del_init(&m->list); |
Jon Maloy | 38266ca | 2018-01-04 15:20:44 +0100 | [diff] [blame] | 348 | list_del_init(&m->small_win); |
Jon Maloy | 04d7b57 | 2017-10-13 11:04:34 +0200 | [diff] [blame] | 349 | tipc_group_decr_active(grp, m); |
Jon Maloy | 75da216 | 2017-10-13 11:04:23 +0200 | [diff] [blame] | 350 | |
| 351 | /* If last member on a node, remove node from dest list */ |
| 352 | if (!tipc_group_find_node(grp, m->node)) |
| 353 | tipc_nlist_del(&grp->dests, m->node); |
| 354 | |
| 355 | kfree(m); |
| 356 | } |
| 357 | |
| 358 | struct tipc_nlist *tipc_group_dests(struct tipc_group *grp) |
| 359 | { |
| 360 | return &grp->dests; |
| 361 | } |
| 362 | |
Jon Maloy | b6f88d9 | 2020-11-25 13:29:15 -0500 | [diff] [blame] | 363 | void tipc_group_self(struct tipc_group *grp, struct tipc_service_range *seq, |
Jon Maloy | 75da216 | 2017-10-13 11:04:23 +0200 | [diff] [blame] | 364 | int *scope) |
| 365 | { |
| 366 | seq->type = grp->type; |
| 367 | seq->lower = grp->instance; |
| 368 | seq->upper = grp->instance; |
| 369 | *scope = grp->scope; |
| 370 | } |
| 371 | |
Jon Maloy | b7d4263 | 2017-10-13 11:04:26 +0200 | [diff] [blame] | 372 | void tipc_group_update_member(struct tipc_member *m, int len) |
Jon Maloy | 75da216 | 2017-10-13 11:04:23 +0200 | [diff] [blame] | 373 | { |
Jon Maloy | b7d4263 | 2017-10-13 11:04:26 +0200 | [diff] [blame] | 374 | struct tipc_group *grp = m->group; |
| 375 | struct tipc_member *_m, *tmp; |
| 376 | |
Jon Maloy | 38266ca | 2018-01-04 15:20:44 +0100 | [diff] [blame] | 377 | if (!tipc_group_is_receiver(m)) |
Jon Maloy | b7d4263 | 2017-10-13 11:04:26 +0200 | [diff] [blame] | 378 | return; |
| 379 | |
| 380 | m->window -= len; |
| 381 | |
| 382 | if (m->window >= ADV_IDLE) |
| 383 | return; |
| 384 | |
Jon Maloy | 38266ca | 2018-01-04 15:20:44 +0100 | [diff] [blame] | 385 | list_del_init(&m->small_win); |
Jon Maloy | b7d4263 | 2017-10-13 11:04:26 +0200 | [diff] [blame] | 386 | |
Jon Maloy | 38266ca | 2018-01-04 15:20:44 +0100 | [diff] [blame] | 387 | /* Sort member into small_window members' list */ |
| 388 | list_for_each_entry_safe(_m, tmp, &grp->small_win, small_win) { |
Jon Maloy | d84d1b3 | 2018-01-04 15:20:45 +0100 | [diff] [blame] | 389 | if (_m->window > m->window) |
| 390 | break; |
Jon Maloy | b7d4263 | 2017-10-13 11:04:26 +0200 | [diff] [blame] | 391 | } |
Jon Maloy | d84d1b3 | 2018-01-04 15:20:45 +0100 | [diff] [blame] | 392 | list_add_tail(&m->small_win, &_m->small_win); |
Jon Maloy | b7d4263 | 2017-10-13 11:04:26 +0200 | [diff] [blame] | 393 | } |
| 394 | |
Jon Maloy | 2f48771 | 2017-10-13 11:04:31 +0200 | [diff] [blame] | 395 | void tipc_group_update_bc_members(struct tipc_group *grp, int len, bool ack) |
Jon Maloy | b7d4263 | 2017-10-13 11:04:26 +0200 | [diff] [blame] | 396 | { |
Jon Maloy | 2f48771 | 2017-10-13 11:04:31 +0200 | [diff] [blame] | 397 | u16 prev = grp->bc_snd_nxt - 1; |
Jon Maloy | b7d4263 | 2017-10-13 11:04:26 +0200 | [diff] [blame] | 398 | struct tipc_member *m; |
| 399 | struct rb_node *n; |
Jon Maloy | 0a3d805 | 2017-12-21 13:07:11 +0100 | [diff] [blame] | 400 | u16 ackers = 0; |
Jon Maloy | b7d4263 | 2017-10-13 11:04:26 +0200 | [diff] [blame] | 401 | |
| 402 | for (n = rb_first(&grp->members); n; n = rb_next(n)) { |
| 403 | m = container_of(n, struct tipc_member, tree_node); |
Jon Maloy | 38266ca | 2018-01-04 15:20:44 +0100 | [diff] [blame] | 404 | if (tipc_group_is_receiver(m)) { |
Jon Maloy | b7d4263 | 2017-10-13 11:04:26 +0200 | [diff] [blame] | 405 | tipc_group_update_member(m, len); |
Jon Maloy | 2f48771 | 2017-10-13 11:04:31 +0200 | [diff] [blame] | 406 | m->bc_acked = prev; |
Jon Maloy | 0a3d805 | 2017-12-21 13:07:11 +0100 | [diff] [blame] | 407 | ackers++; |
Jon Maloy | 2f48771 | 2017-10-13 11:04:31 +0200 | [diff] [blame] | 408 | } |
Jon Maloy | b7d4263 | 2017-10-13 11:04:26 +0200 | [diff] [blame] | 409 | } |
Jon Maloy | 2f48771 | 2017-10-13 11:04:31 +0200 | [diff] [blame] | 410 | |
| 411 | /* Mark number of acknowledges to expect, if any */ |
| 412 | if (ack) |
Jon Maloy | 0a3d805 | 2017-12-21 13:07:11 +0100 | [diff] [blame] | 413 | grp->bc_ackers = ackers; |
Jon Maloy | 75da216 | 2017-10-13 11:04:23 +0200 | [diff] [blame] | 414 | grp->bc_snd_nxt++; |
| 415 | } |
| 416 | |
Jon Maloy | 27bd9ec | 2017-10-13 11:04:27 +0200 | [diff] [blame] | 417 | bool tipc_group_cong(struct tipc_group *grp, u32 dnode, u32 dport, |
| 418 | int len, struct tipc_member **mbr) |
| 419 | { |
| 420 | struct sk_buff_head xmitq; |
| 421 | struct tipc_member *m; |
| 422 | int adv, state; |
| 423 | |
| 424 | m = tipc_group_find_dest(grp, dnode, dport); |
Jon Maloy | eb929a9 | 2018-01-08 21:03:31 +0100 | [diff] [blame] | 425 | if (!tipc_group_is_receiver(m)) { |
| 426 | *mbr = NULL; |
Jon Maloy | 27bd9ec | 2017-10-13 11:04:27 +0200 | [diff] [blame] | 427 | return false; |
Jon Maloy | eb929a9 | 2018-01-08 21:03:31 +0100 | [diff] [blame] | 428 | } |
| 429 | *mbr = m; |
| 430 | |
Jon Maloy | 27bd9ec | 2017-10-13 11:04:27 +0200 | [diff] [blame] | 431 | if (m->window >= len) |
| 432 | return false; |
Jon Maloy | eb929a9 | 2018-01-08 21:03:31 +0100 | [diff] [blame] | 433 | |
Jon Maloy | 60c2530 | 2018-01-17 16:42:46 +0100 | [diff] [blame] | 434 | *grp->open = false; |
Jon Maloy | 27bd9ec | 2017-10-13 11:04:27 +0200 | [diff] [blame] | 435 | |
| 436 | /* If not fully advertised, do it now to prevent mutual blocking */ |
| 437 | adv = m->advertised; |
| 438 | state = m->state; |
Jon Maloy | 27bd9ec | 2017-10-13 11:04:27 +0200 | [diff] [blame] | 439 | if (state == MBR_JOINED && adv == ADV_IDLE) |
| 440 | return true; |
Jon Maloy | 04d7b57 | 2017-10-13 11:04:34 +0200 | [diff] [blame] | 441 | if (state == MBR_ACTIVE && adv == ADV_ACTIVE) |
| 442 | return true; |
| 443 | if (state == MBR_PENDING && adv == ADV_IDLE) |
| 444 | return true; |
Jon Maloy | e654f9f | 2019-08-15 16:42:50 +0200 | [diff] [blame] | 445 | __skb_queue_head_init(&xmitq); |
Jon Maloy | 27bd9ec | 2017-10-13 11:04:27 +0200 | [diff] [blame] | 446 | tipc_group_proto_xmit(grp, m, GRP_ADV_MSG, &xmitq); |
| 447 | tipc_node_distr_xmit(grp->net, &xmitq); |
| 448 | return true; |
| 449 | } |
| 450 | |
Jon Maloy | b7d4263 | 2017-10-13 11:04:26 +0200 | [diff] [blame] | 451 | bool tipc_group_bc_cong(struct tipc_group *grp, int len) |
| 452 | { |
Jon Maloy | 27bd9ec | 2017-10-13 11:04:27 +0200 | [diff] [blame] | 453 | struct tipc_member *m = NULL; |
Jon Maloy | b7d4263 | 2017-10-13 11:04:26 +0200 | [diff] [blame] | 454 | |
Jon Maloy | 2f48771 | 2017-10-13 11:04:31 +0200 | [diff] [blame] | 455 | /* If prev bcast was replicast, reject until all receivers have acked */ |
Jon Maloy | eb929a9 | 2018-01-08 21:03:31 +0100 | [diff] [blame] | 456 | if (grp->bc_ackers) { |
Jon Maloy | 60c2530 | 2018-01-17 16:42:46 +0100 | [diff] [blame] | 457 | *grp->open = false; |
Jon Maloy | 2f48771 | 2017-10-13 11:04:31 +0200 | [diff] [blame] | 458 | return true; |
Jon Maloy | eb929a9 | 2018-01-08 21:03:31 +0100 | [diff] [blame] | 459 | } |
Jon Maloy | 38266ca | 2018-01-04 15:20:44 +0100 | [diff] [blame] | 460 | if (list_empty(&grp->small_win)) |
Jon Maloy | b7d4263 | 2017-10-13 11:04:26 +0200 | [diff] [blame] | 461 | return false; |
| 462 | |
Jon Maloy | 38266ca | 2018-01-04 15:20:44 +0100 | [diff] [blame] | 463 | m = list_first_entry(&grp->small_win, struct tipc_member, small_win); |
Jon Maloy | b7d4263 | 2017-10-13 11:04:26 +0200 | [diff] [blame] | 464 | if (m->window >= len) |
| 465 | return false; |
| 466 | |
Jon Maloy | 27bd9ec | 2017-10-13 11:04:27 +0200 | [diff] [blame] | 467 | return tipc_group_cong(grp, m->node, m->port, len, &m); |
Jon Maloy | b7d4263 | 2017-10-13 11:04:26 +0200 | [diff] [blame] | 468 | } |
| 469 | |
Jon Maloy | b87a5ea | 2017-10-13 11:04:30 +0200 | [diff] [blame] | 470 | /* tipc_group_sort_msg() - sort msg into queue by bcast sequence number |
| 471 | */ |
| 472 | static void tipc_group_sort_msg(struct sk_buff *skb, struct sk_buff_head *defq) |
| 473 | { |
| 474 | struct tipc_msg *_hdr, *hdr = buf_msg(skb); |
| 475 | u16 bc_seqno = msg_grp_bc_seqno(hdr); |
| 476 | struct sk_buff *_skb, *tmp; |
| 477 | int mtyp = msg_type(hdr); |
| 478 | |
Jon Maloy | a3bada7 | 2017-10-13 11:04:33 +0200 | [diff] [blame] | 479 | /* Bcast/mcast may be bypassed by ucast or other bcast, - sort it in */ |
Jon Maloy | b87a5ea | 2017-10-13 11:04:30 +0200 | [diff] [blame] | 480 | if (mtyp == TIPC_GRP_BCAST_MSG || mtyp == TIPC_GRP_MCAST_MSG) { |
| 481 | skb_queue_walk_safe(defq, _skb, tmp) { |
| 482 | _hdr = buf_msg(_skb); |
| 483 | if (!less(bc_seqno, msg_grp_bc_seqno(_hdr))) |
| 484 | continue; |
| 485 | __skb_queue_before(defq, _skb, skb); |
| 486 | return; |
| 487 | } |
| 488 | /* Bcast was not bypassed, - add to tail */ |
| 489 | } |
| 490 | /* Unicasts are never bypassed, - always add to tail */ |
| 491 | __skb_queue_tail(defq, skb); |
| 492 | } |
| 493 | |
Jon Maloy | 75da216 | 2017-10-13 11:04:23 +0200 | [diff] [blame] | 494 | /* tipc_group_filter_msg() - determine if we should accept arriving message |
| 495 | */ |
| 496 | void tipc_group_filter_msg(struct tipc_group *grp, struct sk_buff_head *inputq, |
| 497 | struct sk_buff_head *xmitq) |
| 498 | { |
| 499 | struct sk_buff *skb = __skb_dequeue(inputq); |
Jon Maloy | a3bada7 | 2017-10-13 11:04:33 +0200 | [diff] [blame] | 500 | bool ack, deliver, update, leave = false; |
Jon Maloy | b87a5ea | 2017-10-13 11:04:30 +0200 | [diff] [blame] | 501 | struct sk_buff_head *defq; |
Jon Maloy | 75da216 | 2017-10-13 11:04:23 +0200 | [diff] [blame] | 502 | struct tipc_member *m; |
| 503 | struct tipc_msg *hdr; |
| 504 | u32 node, port; |
Jon Maloy | b87a5ea | 2017-10-13 11:04:30 +0200 | [diff] [blame] | 505 | int mtyp, blks; |
Jon Maloy | 75da216 | 2017-10-13 11:04:23 +0200 | [diff] [blame] | 506 | |
| 507 | if (!skb) |
| 508 | return; |
| 509 | |
| 510 | hdr = buf_msg(skb); |
Jon Maloy | 75da216 | 2017-10-13 11:04:23 +0200 | [diff] [blame] | 511 | node = msg_orignode(hdr); |
| 512 | port = msg_origport(hdr); |
| 513 | |
| 514 | if (!msg_in_group(hdr)) |
| 515 | goto drop; |
| 516 | |
| 517 | m = tipc_group_find_member(grp, node, port); |
Jon Maloy | 38266ca | 2018-01-04 15:20:44 +0100 | [diff] [blame] | 518 | if (!tipc_group_is_sender(m)) |
Jon Maloy | 75da216 | 2017-10-13 11:04:23 +0200 | [diff] [blame] | 519 | goto drop; |
| 520 | |
Jon Maloy | b87a5ea | 2017-10-13 11:04:30 +0200 | [diff] [blame] | 521 | if (less(msg_grp_bc_seqno(hdr), m->bc_rcv_nxt)) |
| 522 | goto drop; |
Jon Maloy | 5b8dddb | 2017-10-13 11:04:29 +0200 | [diff] [blame] | 523 | |
Jon Maloy | 31c82a2 | 2017-10-13 11:04:24 +0200 | [diff] [blame] | 524 | TIPC_SKB_CB(skb)->orig_member = m->instance; |
Jon Maloy | b87a5ea | 2017-10-13 11:04:30 +0200 | [diff] [blame] | 525 | defq = &m->deferredq; |
| 526 | tipc_group_sort_msg(skb, defq); |
Jon Maloy | 75da216 | 2017-10-13 11:04:23 +0200 | [diff] [blame] | 527 | |
Jon Maloy | b87a5ea | 2017-10-13 11:04:30 +0200 | [diff] [blame] | 528 | while ((skb = skb_peek(defq))) { |
| 529 | hdr = buf_msg(skb); |
| 530 | mtyp = msg_type(hdr); |
Jon Maloy | 2e724dc | 2017-11-27 20:13:39 +0100 | [diff] [blame] | 531 | blks = msg_blocks(hdr); |
Jon Maloy | b87a5ea | 2017-10-13 11:04:30 +0200 | [diff] [blame] | 532 | deliver = true; |
Jon Maloy | 2f48771 | 2017-10-13 11:04:31 +0200 | [diff] [blame] | 533 | ack = false; |
Jon Maloy | b87a5ea | 2017-10-13 11:04:30 +0200 | [diff] [blame] | 534 | update = false; |
| 535 | |
| 536 | if (more(msg_grp_bc_seqno(hdr), m->bc_rcv_nxt)) |
| 537 | break; |
| 538 | |
| 539 | /* Decide what to do with message */ |
| 540 | switch (mtyp) { |
| 541 | case TIPC_GRP_MCAST_MSG: |
| 542 | if (msg_nameinst(hdr) != grp->instance) { |
| 543 | update = true; |
| 544 | deliver = false; |
| 545 | } |
Gustavo A. R. Silva | df561f66 | 2020-08-23 17:36:59 -0500 | [diff] [blame] | 546 | fallthrough; |
Jon Maloy | b87a5ea | 2017-10-13 11:04:30 +0200 | [diff] [blame] | 547 | case TIPC_GRP_BCAST_MSG: |
| 548 | m->bc_rcv_nxt++; |
Jon Maloy | 2f48771 | 2017-10-13 11:04:31 +0200 | [diff] [blame] | 549 | ack = msg_grp_bc_ack_req(hdr); |
Jon Maloy | b87a5ea | 2017-10-13 11:04:30 +0200 | [diff] [blame] | 550 | break; |
| 551 | case TIPC_GRP_UCAST_MSG: |
| 552 | break; |
Jon Maloy | a3bada7 | 2017-10-13 11:04:33 +0200 | [diff] [blame] | 553 | case TIPC_GRP_MEMBER_EVT: |
| 554 | if (m->state == MBR_LEAVING) |
| 555 | leave = true; |
| 556 | if (!grp->events) |
| 557 | deliver = false; |
| 558 | break; |
Jon Maloy | b87a5ea | 2017-10-13 11:04:30 +0200 | [diff] [blame] | 559 | default: |
| 560 | break; |
| 561 | } |
| 562 | |
| 563 | /* Execute decisions */ |
| 564 | __skb_dequeue(defq); |
| 565 | if (deliver) |
| 566 | __skb_queue_tail(inputq, skb); |
| 567 | else |
| 568 | kfree_skb(skb); |
| 569 | |
Jon Maloy | 2f48771 | 2017-10-13 11:04:31 +0200 | [diff] [blame] | 570 | if (ack) |
| 571 | tipc_group_proto_xmit(grp, m, GRP_ACK_MSG, xmitq); |
| 572 | |
Jon Maloy | a3bada7 | 2017-10-13 11:04:33 +0200 | [diff] [blame] | 573 | if (leave) { |
Jon Maloy | a3bada7 | 2017-10-13 11:04:33 +0200 | [diff] [blame] | 574 | __skb_queue_purge(defq); |
Jon Maloy | e0e853a | 2017-11-20 21:43:03 +0100 | [diff] [blame] | 575 | tipc_group_delete_member(grp, m); |
Jon Maloy | a3bada7 | 2017-10-13 11:04:33 +0200 | [diff] [blame] | 576 | break; |
| 577 | } |
Jon Maloy | b87a5ea | 2017-10-13 11:04:30 +0200 | [diff] [blame] | 578 | if (!update) |
| 579 | continue; |
| 580 | |
Jon Maloy | b87a5ea | 2017-10-13 11:04:30 +0200 | [diff] [blame] | 581 | tipc_group_update_rcv_win(grp, blks, node, port, xmitq); |
| 582 | } |
Jon Maloy | 75da216 | 2017-10-13 11:04:23 +0200 | [diff] [blame] | 583 | return; |
| 584 | drop: |
| 585 | kfree_skb(skb); |
| 586 | } |
| 587 | |
Jon Maloy | b7d4263 | 2017-10-13 11:04:26 +0200 | [diff] [blame] | 588 | void tipc_group_update_rcv_win(struct tipc_group *grp, int blks, u32 node, |
| 589 | u32 port, struct sk_buff_head *xmitq) |
| 590 | { |
Jon Maloy | 04d7b57 | 2017-10-13 11:04:34 +0200 | [diff] [blame] | 591 | struct list_head *active = &grp->active; |
| 592 | int max_active = grp->max_active; |
| 593 | int reclaim_limit = max_active * 3 / 4; |
| 594 | int active_cnt = grp->active_cnt; |
Jon Maloy | f9c935d | 2017-12-29 19:48:02 +0100 | [diff] [blame] | 595 | struct tipc_member *m, *rm, *pm; |
Jon Maloy | b7d4263 | 2017-10-13 11:04:26 +0200 | [diff] [blame] | 596 | |
| 597 | m = tipc_group_find_member(grp, node, port); |
| 598 | if (!m) |
| 599 | return; |
| 600 | |
| 601 | m->advertised -= blks; |
| 602 | |
| 603 | switch (m->state) { |
| 604 | case MBR_JOINED: |
Jon Maloy | 4ea5dab | 2018-01-08 21:03:24 +0100 | [diff] [blame] | 605 | /* First, decide if member can go active */ |
| 606 | if (active_cnt <= max_active) { |
| 607 | m->state = MBR_ACTIVE; |
| 608 | list_add_tail(&m->list, active); |
| 609 | grp->active_cnt++; |
| 610 | tipc_group_proto_xmit(grp, m, GRP_ADV_MSG, xmitq); |
| 611 | } else { |
| 612 | m->state = MBR_PENDING; |
| 613 | list_add_tail(&m->list, &grp->pending); |
| 614 | } |
| 615 | |
| 616 | if (active_cnt < reclaim_limit) |
| 617 | break; |
| 618 | |
| 619 | /* Reclaim from oldest active member, if possible */ |
| 620 | if (!list_empty(active)) { |
Jon Maloy | 04d7b57 | 2017-10-13 11:04:34 +0200 | [diff] [blame] | 621 | rm = list_first_entry(active, struct tipc_member, list); |
| 622 | rm->state = MBR_RECLAIMING; |
Jon Maloy | 8d5dee2 | 2018-01-08 21:03:23 +0100 | [diff] [blame] | 623 | list_del_init(&rm->list); |
Jon Maloy | 04d7b57 | 2017-10-13 11:04:34 +0200 | [diff] [blame] | 624 | tipc_group_proto_xmit(grp, rm, GRP_RECLAIM_MSG, xmitq); |
Jon Maloy | 04d7b57 | 2017-10-13 11:04:34 +0200 | [diff] [blame] | 625 | break; |
| 626 | } |
Jon Maloy | 4ea5dab | 2018-01-08 21:03:24 +0100 | [diff] [blame] | 627 | /* Nobody to reclaim from; - revert oldest pending to JOINED */ |
| 628 | pm = list_first_entry(&grp->pending, struct tipc_member, list); |
| 629 | list_del_init(&pm->list); |
| 630 | pm->state = MBR_JOINED; |
| 631 | tipc_group_proto_xmit(grp, pm, GRP_ADV_MSG, xmitq); |
| 632 | break; |
Jon Maloy | 04d7b57 | 2017-10-13 11:04:34 +0200 | [diff] [blame] | 633 | case MBR_ACTIVE: |
| 634 | if (!list_is_last(&m->list, &grp->active)) |
| 635 | list_move_tail(&m->list, &grp->active); |
| 636 | if (m->advertised > (ADV_ACTIVE * 3 / 4)) |
| 637 | break; |
| 638 | tipc_group_proto_xmit(grp, m, GRP_ADV_MSG, xmitq); |
Jon Maloy | b7d4263 | 2017-10-13 11:04:26 +0200 | [diff] [blame] | 639 | break; |
Jon Maloy | 04d7b57 | 2017-10-13 11:04:34 +0200 | [diff] [blame] | 640 | case MBR_REMITTED: |
| 641 | if (m->advertised > ADV_IDLE) |
| 642 | break; |
| 643 | m->state = MBR_JOINED; |
Jon Maloy | 8d5dee2 | 2018-01-08 21:03:23 +0100 | [diff] [blame] | 644 | grp->active_cnt--; |
Jon Maloy | 04d7b57 | 2017-10-13 11:04:34 +0200 | [diff] [blame] | 645 | if (m->advertised < ADV_IDLE) { |
| 646 | pr_warn_ratelimited("Rcv unexpected msg after REMIT\n"); |
| 647 | tipc_group_proto_xmit(grp, m, GRP_ADV_MSG, xmitq); |
| 648 | } |
Jon Maloy | 8d5dee2 | 2018-01-08 21:03:23 +0100 | [diff] [blame] | 649 | |
Jon Maloy | f9c935d | 2017-12-29 19:48:02 +0100 | [diff] [blame] | 650 | if (list_empty(&grp->pending)) |
| 651 | return; |
| 652 | |
| 653 | /* Set oldest pending member to active and advertise */ |
| 654 | pm = list_first_entry(&grp->pending, struct tipc_member, list); |
| 655 | pm->state = MBR_ACTIVE; |
| 656 | list_move_tail(&pm->list, &grp->active); |
| 657 | grp->active_cnt++; |
| 658 | tipc_group_proto_xmit(grp, pm, GRP_ADV_MSG, xmitq); |
Jon Maloy | 04d7b57 | 2017-10-13 11:04:34 +0200 | [diff] [blame] | 659 | break; |
| 660 | case MBR_RECLAIMING: |
Jon Maloy | b7d4263 | 2017-10-13 11:04:26 +0200 | [diff] [blame] | 661 | case MBR_JOINING: |
| 662 | case MBR_LEAVING: |
| 663 | default: |
| 664 | break; |
| 665 | } |
| 666 | } |
| 667 | |
Jon Maloy | 7ad32bc | 2018-01-08 21:03:26 +0100 | [diff] [blame] | 668 | static void tipc_group_create_event(struct tipc_group *grp, |
| 669 | struct tipc_member *m, |
| 670 | u32 event, u16 seqno, |
| 671 | struct sk_buff_head *inputq) |
| 672 | { u32 dnode = tipc_own_addr(grp->net); |
| 673 | struct tipc_event evt; |
| 674 | struct sk_buff *skb; |
| 675 | struct tipc_msg *hdr; |
| 676 | |
Jon Maloy | b06f9d9 | 2018-10-18 17:38:29 +0200 | [diff] [blame] | 677 | memset(&evt, 0, sizeof(evt)); |
Jon Maloy | 7ad32bc | 2018-01-08 21:03:26 +0100 | [diff] [blame] | 678 | evt.event = event; |
| 679 | evt.found_lower = m->instance; |
| 680 | evt.found_upper = m->instance; |
| 681 | evt.port.ref = m->port; |
| 682 | evt.port.node = m->node; |
| 683 | evt.s.seq.type = grp->type; |
| 684 | evt.s.seq.lower = m->instance; |
| 685 | evt.s.seq.upper = m->instance; |
| 686 | |
| 687 | skb = tipc_msg_create(TIPC_CRITICAL_IMPORTANCE, TIPC_GRP_MEMBER_EVT, |
| 688 | GROUP_H_SIZE, sizeof(evt), dnode, m->node, |
| 689 | grp->portid, m->port, 0); |
| 690 | if (!skb) |
| 691 | return; |
| 692 | |
| 693 | hdr = buf_msg(skb); |
| 694 | msg_set_nametype(hdr, grp->type); |
| 695 | msg_set_grp_evt(hdr, event); |
| 696 | msg_set_dest_droppable(hdr, true); |
| 697 | msg_set_grp_bc_seqno(hdr, seqno); |
| 698 | memcpy(msg_data(hdr), &evt, sizeof(evt)); |
| 699 | TIPC_SKB_CB(skb)->orig_member = m->instance; |
| 700 | __skb_queue_tail(inputq, skb); |
| 701 | } |
| 702 | |
Jon Maloy | 75da216 | 2017-10-13 11:04:23 +0200 | [diff] [blame] | 703 | static void tipc_group_proto_xmit(struct tipc_group *grp, struct tipc_member *m, |
| 704 | int mtyp, struct sk_buff_head *xmitq) |
| 705 | { |
| 706 | struct tipc_msg *hdr; |
| 707 | struct sk_buff *skb; |
Jon Maloy | b7d4263 | 2017-10-13 11:04:26 +0200 | [diff] [blame] | 708 | int adv = 0; |
Jon Maloy | 75da216 | 2017-10-13 11:04:23 +0200 | [diff] [blame] | 709 | |
| 710 | skb = tipc_msg_create(GROUP_PROTOCOL, mtyp, INT_H_SIZE, 0, |
| 711 | m->node, tipc_own_addr(grp->net), |
| 712 | m->port, grp->portid, 0); |
| 713 | if (!skb) |
| 714 | return; |
| 715 | |
Jon Maloy | 04d7b57 | 2017-10-13 11:04:34 +0200 | [diff] [blame] | 716 | if (m->state == MBR_ACTIVE) |
Jon Maloy | b7d4263 | 2017-10-13 11:04:26 +0200 | [diff] [blame] | 717 | adv = ADV_ACTIVE - m->advertised; |
Jon Maloy | 04d7b57 | 2017-10-13 11:04:34 +0200 | [diff] [blame] | 718 | else if (m->state == MBR_JOINED || m->state == MBR_PENDING) |
| 719 | adv = ADV_IDLE - m->advertised; |
Jon Maloy | b7d4263 | 2017-10-13 11:04:26 +0200 | [diff] [blame] | 720 | |
Jon Maloy | 75da216 | 2017-10-13 11:04:23 +0200 | [diff] [blame] | 721 | hdr = buf_msg(skb); |
Jon Maloy | b7d4263 | 2017-10-13 11:04:26 +0200 | [diff] [blame] | 722 | |
| 723 | if (mtyp == GRP_JOIN_MSG) { |
Jon Maloy | 75da216 | 2017-10-13 11:04:23 +0200 | [diff] [blame] | 724 | msg_set_grp_bc_syncpt(hdr, grp->bc_snd_nxt); |
Jon Maloy | b7d4263 | 2017-10-13 11:04:26 +0200 | [diff] [blame] | 725 | msg_set_adv_win(hdr, adv); |
| 726 | m->advertised += adv; |
Jon Maloy | a3bada7 | 2017-10-13 11:04:33 +0200 | [diff] [blame] | 727 | } else if (mtyp == GRP_LEAVE_MSG) { |
| 728 | msg_set_grp_bc_syncpt(hdr, grp->bc_snd_nxt); |
Jon Maloy | b7d4263 | 2017-10-13 11:04:26 +0200 | [diff] [blame] | 729 | } else if (mtyp == GRP_ADV_MSG) { |
| 730 | msg_set_adv_win(hdr, adv); |
| 731 | m->advertised += adv; |
Jon Maloy | 2f48771 | 2017-10-13 11:04:31 +0200 | [diff] [blame] | 732 | } else if (mtyp == GRP_ACK_MSG) { |
| 733 | msg_set_grp_bc_acked(hdr, m->bc_rcv_nxt); |
Jon Maloy | 04d7b57 | 2017-10-13 11:04:34 +0200 | [diff] [blame] | 734 | } else if (mtyp == GRP_REMIT_MSG) { |
| 735 | msg_set_grp_remitted(hdr, m->window); |
Jon Maloy | b7d4263 | 2017-10-13 11:04:26 +0200 | [diff] [blame] | 736 | } |
Jon Maloy | 2348339 | 2017-12-18 17:34:16 +0100 | [diff] [blame] | 737 | msg_set_dest_droppable(hdr, true); |
Jon Maloy | 75da216 | 2017-10-13 11:04:23 +0200 | [diff] [blame] | 738 | __skb_queue_tail(xmitq, skb); |
| 739 | } |
| 740 | |
Jon Maloy | b7d4263 | 2017-10-13 11:04:26 +0200 | [diff] [blame] | 741 | void tipc_group_proto_rcv(struct tipc_group *grp, bool *usr_wakeup, |
| 742 | struct tipc_msg *hdr, struct sk_buff_head *inputq, |
Jon Maloy | 75da216 | 2017-10-13 11:04:23 +0200 | [diff] [blame] | 743 | struct sk_buff_head *xmitq) |
| 744 | { |
| 745 | u32 node = msg_orignode(hdr); |
| 746 | u32 port = msg_origport(hdr); |
Jon Maloy | 04d7b57 | 2017-10-13 11:04:34 +0200 | [diff] [blame] | 747 | struct tipc_member *m, *pm; |
Jon Maloy | 04d7b57 | 2017-10-13 11:04:34 +0200 | [diff] [blame] | 748 | u16 remitted, in_flight; |
Jon Maloy | 75da216 | 2017-10-13 11:04:23 +0200 | [diff] [blame] | 749 | |
| 750 | if (!grp) |
| 751 | return; |
| 752 | |
Jon Maloy | 232d07b | 2018-01-08 21:03:30 +0100 | [diff] [blame] | 753 | if (grp->scope == TIPC_NODE_SCOPE && node != tipc_own_addr(grp->net)) |
| 754 | return; |
| 755 | |
Jon Maloy | 75da216 | 2017-10-13 11:04:23 +0200 | [diff] [blame] | 756 | m = tipc_group_find_member(grp, node, port); |
| 757 | |
| 758 | switch (msg_type(hdr)) { |
| 759 | case GRP_JOIN_MSG: |
| 760 | if (!m) |
| 761 | m = tipc_group_create_member(grp, node, port, |
Jon Maloy | d12d2e1 | 2018-01-08 21:03:28 +0100 | [diff] [blame] | 762 | 0, MBR_JOINING); |
Jon Maloy | 75da216 | 2017-10-13 11:04:23 +0200 | [diff] [blame] | 763 | if (!m) |
| 764 | return; |
Jon Maloy | a3bada7 | 2017-10-13 11:04:33 +0200 | [diff] [blame] | 765 | m->bc_syncpt = msg_grp_bc_syncpt(hdr); |
| 766 | m->bc_rcv_nxt = m->bc_syncpt; |
Jon Maloy | b7d4263 | 2017-10-13 11:04:26 +0200 | [diff] [blame] | 767 | m->window += msg_adv_win(hdr); |
Jon Maloy | 75da216 | 2017-10-13 11:04:23 +0200 | [diff] [blame] | 768 | |
Jon Maloy | d12d2e1 | 2018-01-08 21:03:28 +0100 | [diff] [blame] | 769 | /* Wait until PUBLISH event is received if necessary */ |
| 770 | if (m->state != MBR_PUBLISHED) |
| 771 | return; |
| 772 | |
| 773 | /* Member can be taken into service */ |
| 774 | m->state = MBR_JOINED; |
Jon Maloy | eb929a9 | 2018-01-08 21:03:31 +0100 | [diff] [blame] | 775 | tipc_group_open(m, usr_wakeup); |
Jon Maloy | bb25c38 | 2017-12-20 11:03:15 +0100 | [diff] [blame] | 776 | tipc_group_update_member(m, 0); |
Jon Maloy | d12d2e1 | 2018-01-08 21:03:28 +0100 | [diff] [blame] | 777 | tipc_group_proto_xmit(grp, m, GRP_ADV_MSG, xmitq); |
| 778 | tipc_group_create_event(grp, m, TIPC_PUBLISHED, |
| 779 | m->bc_syncpt, inputq); |
Jon Maloy | 75da216 | 2017-10-13 11:04:23 +0200 | [diff] [blame] | 780 | return; |
| 781 | case GRP_LEAVE_MSG: |
| 782 | if (!m) |
| 783 | return; |
Jon Maloy | a3bada7 | 2017-10-13 11:04:33 +0200 | [diff] [blame] | 784 | m->bc_syncpt = msg_grp_bc_syncpt(hdr); |
Jon Maloy | 3f42f5f | 2017-12-18 18:13:34 +0100 | [diff] [blame] | 785 | list_del_init(&m->list); |
Jon Maloy | eb929a9 | 2018-01-08 21:03:31 +0100 | [diff] [blame] | 786 | tipc_group_open(m, usr_wakeup); |
Jon Maloy | c2b22bc | 2018-01-08 21:03:27 +0100 | [diff] [blame] | 787 | tipc_group_decr_active(grp, m); |
| 788 | m->state = MBR_LEAVING; |
Jon Maloy | 7ad32bc | 2018-01-08 21:03:26 +0100 | [diff] [blame] | 789 | tipc_group_create_event(grp, m, TIPC_WITHDRAWN, |
| 790 | m->bc_syncpt, inputq); |
Jon Maloy | b7d4263 | 2017-10-13 11:04:26 +0200 | [diff] [blame] | 791 | return; |
| 792 | case GRP_ADV_MSG: |
| 793 | if (!m) |
| 794 | return; |
| 795 | m->window += msg_adv_win(hdr); |
Jon Maloy | eb929a9 | 2018-01-08 21:03:31 +0100 | [diff] [blame] | 796 | tipc_group_open(m, usr_wakeup); |
Jon Maloy | 75da216 | 2017-10-13 11:04:23 +0200 | [diff] [blame] | 797 | return; |
Jon Maloy | 2f48771 | 2017-10-13 11:04:31 +0200 | [diff] [blame] | 798 | case GRP_ACK_MSG: |
| 799 | if (!m) |
| 800 | return; |
| 801 | m->bc_acked = msg_grp_bc_acked(hdr); |
| 802 | if (--grp->bc_ackers) |
Jon Maloy | eb929a9 | 2018-01-08 21:03:31 +0100 | [diff] [blame] | 803 | return; |
| 804 | list_del_init(&m->small_win); |
Jon Maloy | 60c2530 | 2018-01-17 16:42:46 +0100 | [diff] [blame] | 805 | *m->group->open = true; |
Jon Maloy | 2f48771 | 2017-10-13 11:04:31 +0200 | [diff] [blame] | 806 | *usr_wakeup = true; |
Jon Maloy | eb929a9 | 2018-01-08 21:03:31 +0100 | [diff] [blame] | 807 | tipc_group_update_member(m, 0); |
Jon Maloy | 2f48771 | 2017-10-13 11:04:31 +0200 | [diff] [blame] | 808 | return; |
Jon Maloy | 04d7b57 | 2017-10-13 11:04:34 +0200 | [diff] [blame] | 809 | case GRP_RECLAIM_MSG: |
| 810 | if (!m) |
| 811 | return; |
Jon Maloy | 04d7b57 | 2017-10-13 11:04:34 +0200 | [diff] [blame] | 812 | tipc_group_proto_xmit(grp, m, GRP_REMIT_MSG, xmitq); |
| 813 | m->window = ADV_IDLE; |
Jon Maloy | eb929a9 | 2018-01-08 21:03:31 +0100 | [diff] [blame] | 814 | tipc_group_open(m, usr_wakeup); |
Jon Maloy | 04d7b57 | 2017-10-13 11:04:34 +0200 | [diff] [blame] | 815 | return; |
| 816 | case GRP_REMIT_MSG: |
| 817 | if (!m || m->state != MBR_RECLAIMING) |
| 818 | return; |
| 819 | |
Jon Maloy | 04d7b57 | 2017-10-13 11:04:34 +0200 | [diff] [blame] | 820 | remitted = msg_grp_remitted(hdr); |
| 821 | |
| 822 | /* Messages preceding the REMIT still in receive queue */ |
| 823 | if (m->advertised > remitted) { |
| 824 | m->state = MBR_REMITTED; |
| 825 | in_flight = m->advertised - remitted; |
Jon Maloy | f9c935d | 2017-12-29 19:48:02 +0100 | [diff] [blame] | 826 | m->advertised = ADV_IDLE + in_flight; |
| 827 | return; |
Jon Maloy | 04d7b57 | 2017-10-13 11:04:34 +0200 | [diff] [blame] | 828 | } |
Jon Maloy | 8d5dee2 | 2018-01-08 21:03:23 +0100 | [diff] [blame] | 829 | /* This should never happen */ |
Jon Maloy | 04d7b57 | 2017-10-13 11:04:34 +0200 | [diff] [blame] | 830 | if (m->advertised < remitted) |
Jon Maloy | 8d5dee2 | 2018-01-08 21:03:23 +0100 | [diff] [blame] | 831 | pr_warn_ratelimited("Unexpected REMIT msg\n"); |
Jon Maloy | 04d7b57 | 2017-10-13 11:04:34 +0200 | [diff] [blame] | 832 | |
Jon Maloy | 8d5dee2 | 2018-01-08 21:03:23 +0100 | [diff] [blame] | 833 | /* All messages preceding the REMIT have been read */ |
| 834 | m->state = MBR_JOINED; |
Jon Maloy | f9c935d | 2017-12-29 19:48:02 +0100 | [diff] [blame] | 835 | grp->active_cnt--; |
Jon Maloy | 8d5dee2 | 2018-01-08 21:03:23 +0100 | [diff] [blame] | 836 | m->advertised = ADV_IDLE; |
Jon Maloy | 04d7b57 | 2017-10-13 11:04:34 +0200 | [diff] [blame] | 837 | |
| 838 | /* Set oldest pending member to active and advertise */ |
| 839 | if (list_empty(&grp->pending)) |
| 840 | return; |
| 841 | pm = list_first_entry(&grp->pending, struct tipc_member, list); |
| 842 | pm->state = MBR_ACTIVE; |
| 843 | list_move_tail(&pm->list, &grp->active); |
| 844 | grp->active_cnt++; |
| 845 | if (pm->advertised <= (ADV_ACTIVE * 3 / 4)) |
| 846 | tipc_group_proto_xmit(grp, pm, GRP_ADV_MSG, xmitq); |
| 847 | return; |
Jon Maloy | 75da216 | 2017-10-13 11:04:23 +0200 | [diff] [blame] | 848 | default: |
| 849 | pr_warn("Received unknown GROUP_PROTO message\n"); |
| 850 | } |
| 851 | } |
| 852 | |
Jon Maloy | b7d4263 | 2017-10-13 11:04:26 +0200 | [diff] [blame] | 853 | /* tipc_group_member_evt() - receive and handle a member up/down event |
| 854 | */ |
Jon Maloy | 75da216 | 2017-10-13 11:04:23 +0200 | [diff] [blame] | 855 | void tipc_group_member_evt(struct tipc_group *grp, |
Jon Maloy | b7d4263 | 2017-10-13 11:04:26 +0200 | [diff] [blame] | 856 | bool *usr_wakeup, |
| 857 | int *sk_rcvbuf, |
Jon Maloy | 7ad32bc | 2018-01-08 21:03:26 +0100 | [diff] [blame] | 858 | struct tipc_msg *hdr, |
Jon Maloy | ae236fb | 2017-10-13 11:04:25 +0200 | [diff] [blame] | 859 | struct sk_buff_head *inputq, |
Jon Maloy | 75da216 | 2017-10-13 11:04:23 +0200 | [diff] [blame] | 860 | struct sk_buff_head *xmitq) |
| 861 | { |
Jon Maloy | 75da216 | 2017-10-13 11:04:23 +0200 | [diff] [blame] | 862 | struct tipc_event *evt = (void *)msg_data(hdr); |
Jon Maloy | ae236fb | 2017-10-13 11:04:25 +0200 | [diff] [blame] | 863 | u32 instance = evt->found_lower; |
Jon Maloy | 75da216 | 2017-10-13 11:04:23 +0200 | [diff] [blame] | 864 | u32 node = evt->port.node; |
| 865 | u32 port = evt->port.ref; |
Jon Maloy | ae236fb | 2017-10-13 11:04:25 +0200 | [diff] [blame] | 866 | int event = evt->event; |
Jon Maloy | 75da216 | 2017-10-13 11:04:23 +0200 | [diff] [blame] | 867 | struct tipc_member *m; |
| 868 | struct net *net; |
| 869 | u32 self; |
| 870 | |
| 871 | if (!grp) |
Jon Maloy | 7ad32bc | 2018-01-08 21:03:26 +0100 | [diff] [blame] | 872 | return; |
Jon Maloy | 75da216 | 2017-10-13 11:04:23 +0200 | [diff] [blame] | 873 | |
| 874 | net = grp->net; |
| 875 | self = tipc_own_addr(net); |
| 876 | if (!grp->loopback && node == self && port == grp->portid) |
Jon Maloy | 7ad32bc | 2018-01-08 21:03:26 +0100 | [diff] [blame] | 877 | return; |
Jon Maloy | ae236fb | 2017-10-13 11:04:25 +0200 | [diff] [blame] | 878 | |
Jon Maloy | 75da216 | 2017-10-13 11:04:23 +0200 | [diff] [blame] | 879 | m = tipc_group_find_member(grp, node, port); |
| 880 | |
Jon Maloy | d12d2e1 | 2018-01-08 21:03:28 +0100 | [diff] [blame] | 881 | switch (event) { |
| 882 | case TIPC_PUBLISHED: |
| 883 | /* Send and wait for arrival of JOIN message if necessary */ |
| 884 | if (!m) { |
| 885 | m = tipc_group_create_member(grp, node, port, instance, |
| 886 | MBR_PUBLISHED); |
| 887 | if (!m) |
| 888 | break; |
| 889 | tipc_group_update_member(m, 0); |
| 890 | tipc_group_proto_xmit(grp, m, GRP_JOIN_MSG, xmitq); |
| 891 | break; |
Jon Maloy | ae236fb | 2017-10-13 11:04:25 +0200 | [diff] [blame] | 892 | } |
Jon Maloy | d12d2e1 | 2018-01-08 21:03:28 +0100 | [diff] [blame] | 893 | |
| 894 | if (m->state != MBR_JOINING) |
| 895 | break; |
| 896 | |
| 897 | /* Member can be taken into service */ |
| 898 | m->instance = instance; |
| 899 | m->state = MBR_JOINED; |
Jon Maloy | eb929a9 | 2018-01-08 21:03:31 +0100 | [diff] [blame] | 900 | tipc_group_open(m, usr_wakeup); |
Jon Maloy | d84d1b3 | 2018-01-04 15:20:45 +0100 | [diff] [blame] | 901 | tipc_group_update_member(m, 0); |
Jon Maloy | d12d2e1 | 2018-01-08 21:03:28 +0100 | [diff] [blame] | 902 | tipc_group_proto_xmit(grp, m, GRP_JOIN_MSG, xmitq); |
| 903 | tipc_group_create_event(grp, m, TIPC_PUBLISHED, |
| 904 | m->bc_syncpt, inputq); |
| 905 | break; |
| 906 | case TIPC_WITHDRAWN: |
Jon Maloy | 75da216 | 2017-10-13 11:04:23 +0200 | [diff] [blame] | 907 | if (!m) |
Jon Maloy | d12d2e1 | 2018-01-08 21:03:28 +0100 | [diff] [blame] | 908 | break; |
Jon Maloy | ae236fb | 2017-10-13 11:04:25 +0200 | [diff] [blame] | 909 | |
Jon Maloy | c2b22bc | 2018-01-08 21:03:27 +0100 | [diff] [blame] | 910 | tipc_group_decr_active(grp, m); |
| 911 | m->state = MBR_LEAVING; |
Jon Maloy | 3f42f5f | 2017-12-18 18:13:34 +0100 | [diff] [blame] | 912 | list_del_init(&m->list); |
Jon Maloy | eb929a9 | 2018-01-08 21:03:31 +0100 | [diff] [blame] | 913 | tipc_group_open(m, usr_wakeup); |
Jon Maloy | c2b22bc | 2018-01-08 21:03:27 +0100 | [diff] [blame] | 914 | |
| 915 | /* Only send event if no LEAVE message can be expected */ |
| 916 | if (!tipc_node_is_up(net, node)) |
| 917 | tipc_group_create_event(grp, m, TIPC_WITHDRAWN, |
| 918 | m->bc_rcv_nxt, inputq); |
Jon Maloy | d12d2e1 | 2018-01-08 21:03:28 +0100 | [diff] [blame] | 919 | break; |
| 920 | default: |
| 921 | break; |
Jon Maloy | 75da216 | 2017-10-13 11:04:23 +0200 | [diff] [blame] | 922 | } |
Jon Maloy | b7d4263 | 2017-10-13 11:04:26 +0200 | [diff] [blame] | 923 | *sk_rcvbuf = tipc_group_rcvbuf_limit(grp); |
Jon Maloy | 75da216 | 2017-10-13 11:04:23 +0200 | [diff] [blame] | 924 | } |
GhantaKrishnamurthy MohanKrishna | a1be5a2 | 2018-06-29 13:26:18 +0200 | [diff] [blame] | 925 | |
| 926 | int tipc_group_fill_sock_diag(struct tipc_group *grp, struct sk_buff *skb) |
| 927 | { |
Michal Kubecek | ae0be8d | 2019-04-26 11:13:06 +0200 | [diff] [blame] | 928 | struct nlattr *group = nla_nest_start_noflag(skb, TIPC_NLA_SOCK_GROUP); |
GhantaKrishnamurthy MohanKrishna | a1be5a2 | 2018-06-29 13:26:18 +0200 | [diff] [blame] | 929 | |
Kangjie Lu | 4589e28 | 2019-03-15 12:11:59 -0500 | [diff] [blame] | 930 | if (!group) |
| 931 | return -EMSGSIZE; |
| 932 | |
GhantaKrishnamurthy MohanKrishna | a1be5a2 | 2018-06-29 13:26:18 +0200 | [diff] [blame] | 933 | if (nla_put_u32(skb, TIPC_NLA_SOCK_GROUP_ID, |
| 934 | grp->type) || |
| 935 | nla_put_u32(skb, TIPC_NLA_SOCK_GROUP_INSTANCE, |
| 936 | grp->instance) || |
| 937 | nla_put_u32(skb, TIPC_NLA_SOCK_GROUP_BC_SEND_NEXT, |
| 938 | grp->bc_snd_nxt)) |
| 939 | goto group_msg_cancel; |
| 940 | |
| 941 | if (grp->scope == TIPC_NODE_SCOPE) |
| 942 | if (nla_put_flag(skb, TIPC_NLA_SOCK_GROUP_NODE_SCOPE)) |
| 943 | goto group_msg_cancel; |
| 944 | |
| 945 | if (grp->scope == TIPC_CLUSTER_SCOPE) |
| 946 | if (nla_put_flag(skb, TIPC_NLA_SOCK_GROUP_CLUSTER_SCOPE)) |
| 947 | goto group_msg_cancel; |
| 948 | |
| 949 | if (*grp->open) |
| 950 | if (nla_put_flag(skb, TIPC_NLA_SOCK_GROUP_OPEN)) |
| 951 | goto group_msg_cancel; |
| 952 | |
| 953 | nla_nest_end(skb, group); |
| 954 | return 0; |
| 955 | |
| 956 | group_msg_cancel: |
| 957 | nla_nest_cancel(skb, group); |
| 958 | return -1; |
| 959 | } |