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 |
| 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 Maloy | b7d4263 | 2017-10-13 11:04:26 +0200 | [diff] [blame] | 49 | #define ADV_ACTIVE (ADV_UNIT * 12) |
Jon Maloy | 75da216 | 2017-10-13 11:04:23 +0200 | [diff] [blame] | 50 | |
| 51 | enum mbr_state { |
| 52 | MBR_QUARANTINED, |
| 53 | MBR_DISCOVERED, |
| 54 | MBR_JOINING, |
| 55 | MBR_PUBLISHED, |
| 56 | MBR_JOINED, |
Jon Maloy | 04d7b57 | 2017-10-13 11:04:34 +0200 | [diff] [blame] | 57 | MBR_PENDING, |
| 58 | MBR_ACTIVE, |
| 59 | MBR_RECLAIMING, |
| 60 | MBR_REMITTED, |
Jon Maloy | 75da216 | 2017-10-13 11:04:23 +0200 | [diff] [blame] | 61 | MBR_LEAVING |
| 62 | }; |
| 63 | |
| 64 | struct tipc_member { |
| 65 | struct rb_node tree_node; |
| 66 | struct list_head list; |
Jon Maloy | b7d4263 | 2017-10-13 11:04:26 +0200 | [diff] [blame] | 67 | struct list_head congested; |
Jon Maloy | ae236fb | 2017-10-13 11:04:25 +0200 | [diff] [blame] | 68 | struct sk_buff *event_msg; |
Jon Maloy | b87a5ea | 2017-10-13 11:04:30 +0200 | [diff] [blame] | 69 | struct sk_buff_head deferredq; |
Jon Maloy | b7d4263 | 2017-10-13 11:04:26 +0200 | [diff] [blame] | 70 | struct tipc_group *group; |
Jon Maloy | 75da216 | 2017-10-13 11:04:23 +0200 | [diff] [blame] | 71 | u32 node; |
| 72 | u32 port; |
Jon Maloy | 31c82a2 | 2017-10-13 11:04:24 +0200 | [diff] [blame] | 73 | u32 instance; |
Jon Maloy | 75da216 | 2017-10-13 11:04:23 +0200 | [diff] [blame] | 74 | enum mbr_state state; |
Jon Maloy | b7d4263 | 2017-10-13 11:04:26 +0200 | [diff] [blame] | 75 | u16 advertised; |
| 76 | u16 window; |
Jon Maloy | 75da216 | 2017-10-13 11:04:23 +0200 | [diff] [blame] | 77 | u16 bc_rcv_nxt; |
Jon Maloy | a3bada7 | 2017-10-13 11:04:33 +0200 | [diff] [blame] | 78 | u16 bc_syncpt; |
Jon Maloy | 2f48771 | 2017-10-13 11:04:31 +0200 | [diff] [blame] | 79 | u16 bc_acked; |
Jon Maloy | b7d4263 | 2017-10-13 11:04:26 +0200 | [diff] [blame] | 80 | bool usr_pending; |
Jon Maloy | 75da216 | 2017-10-13 11:04:23 +0200 | [diff] [blame] | 81 | }; |
| 82 | |
| 83 | struct tipc_group { |
| 84 | struct rb_root members; |
Jon Maloy | b7d4263 | 2017-10-13 11:04:26 +0200 | [diff] [blame] | 85 | struct list_head congested; |
Jon Maloy | 04d7b57 | 2017-10-13 11:04:34 +0200 | [diff] [blame] | 86 | struct list_head pending; |
| 87 | struct list_head active; |
| 88 | struct list_head reclaiming; |
Jon Maloy | 75da216 | 2017-10-13 11:04:23 +0200 | [diff] [blame] | 89 | struct tipc_nlist dests; |
| 90 | struct net *net; |
| 91 | int subid; |
| 92 | u32 type; |
| 93 | u32 instance; |
| 94 | u32 domain; |
| 95 | u32 scope; |
| 96 | u32 portid; |
| 97 | u16 member_cnt; |
Jon Maloy | 04d7b57 | 2017-10-13 11:04:34 +0200 | [diff] [blame] | 98 | u16 active_cnt; |
| 99 | u16 max_active; |
Jon Maloy | 75da216 | 2017-10-13 11:04:23 +0200 | [diff] [blame] | 100 | u16 bc_snd_nxt; |
Jon Maloy | 2f48771 | 2017-10-13 11:04:31 +0200 | [diff] [blame] | 101 | u16 bc_ackers; |
Jon Maloy | 75da216 | 2017-10-13 11:04:23 +0200 | [diff] [blame] | 102 | bool loopback; |
Jon Maloy | ae236fb | 2017-10-13 11:04:25 +0200 | [diff] [blame] | 103 | bool events; |
Jon Maloy | 75da216 | 2017-10-13 11:04:23 +0200 | [diff] [blame] | 104 | }; |
| 105 | |
| 106 | static void tipc_group_proto_xmit(struct tipc_group *grp, struct tipc_member *m, |
| 107 | int mtyp, struct sk_buff_head *xmitq); |
| 108 | |
Jon Maloy | 04d7b57 | 2017-10-13 11:04:34 +0200 | [diff] [blame] | 109 | static void tipc_group_decr_active(struct tipc_group *grp, |
| 110 | struct tipc_member *m) |
| 111 | { |
| 112 | if (m->state == MBR_ACTIVE || m->state == MBR_RECLAIMING) |
| 113 | grp->active_cnt--; |
| 114 | } |
| 115 | |
Jon Maloy | b7d4263 | 2017-10-13 11:04:26 +0200 | [diff] [blame] | 116 | static int tipc_group_rcvbuf_limit(struct tipc_group *grp) |
| 117 | { |
Jon Maloy | 04d7b57 | 2017-10-13 11:04:34 +0200 | [diff] [blame] | 118 | int max_active, active_pool, idle_pool; |
Jon Maloy | b7d4263 | 2017-10-13 11:04:26 +0200 | [diff] [blame] | 119 | int mcnt = grp->member_cnt + 1; |
| 120 | |
Jon Maloy | 04d7b57 | 2017-10-13 11:04:34 +0200 | [diff] [blame] | 121 | /* Limit simultaneous reception from other members */ |
| 122 | max_active = min(mcnt / 8, 64); |
| 123 | max_active = max(max_active, 16); |
| 124 | grp->max_active = max_active; |
| 125 | |
| 126 | /* Reserve blocks for active and idle members */ |
| 127 | active_pool = max_active * ADV_ACTIVE; |
| 128 | idle_pool = (mcnt - max_active) * ADV_IDLE; |
| 129 | |
Jon Maloy | b7d4263 | 2017-10-13 11:04:26 +0200 | [diff] [blame] | 130 | /* Scale to bytes, considering worst-case truesize/msgsize ratio */ |
Jon Maloy | 04d7b57 | 2017-10-13 11:04:34 +0200 | [diff] [blame] | 131 | return (active_pool + idle_pool) * FLOWCTL_BLK_SZ * 4; |
Jon Maloy | b7d4263 | 2017-10-13 11:04:26 +0200 | [diff] [blame] | 132 | } |
| 133 | |
Jon Maloy | 75da216 | 2017-10-13 11:04:23 +0200 | [diff] [blame] | 134 | u16 tipc_group_bc_snd_nxt(struct tipc_group *grp) |
| 135 | { |
| 136 | return grp->bc_snd_nxt; |
| 137 | } |
| 138 | |
Jon Maloy | b7d4263 | 2017-10-13 11:04:26 +0200 | [diff] [blame] | 139 | static bool tipc_group_is_enabled(struct tipc_member *m) |
| 140 | { |
| 141 | return m->state != MBR_QUARANTINED && m->state != MBR_LEAVING; |
| 142 | } |
| 143 | |
Jon Maloy | 75da216 | 2017-10-13 11:04:23 +0200 | [diff] [blame] | 144 | static bool tipc_group_is_receiver(struct tipc_member *m) |
| 145 | { |
| 146 | return m && m->state >= MBR_JOINED; |
| 147 | } |
| 148 | |
Jon Maloy | ee106d7 | 2017-10-13 11:04:28 +0200 | [diff] [blame] | 149 | u32 tipc_group_exclude(struct tipc_group *grp) |
| 150 | { |
| 151 | if (!grp->loopback) |
| 152 | return grp->portid; |
| 153 | return 0; |
| 154 | } |
| 155 | |
Jon Maloy | 75da216 | 2017-10-13 11:04:23 +0200 | [diff] [blame] | 156 | int tipc_group_size(struct tipc_group *grp) |
| 157 | { |
| 158 | return grp->member_cnt; |
| 159 | } |
| 160 | |
| 161 | struct tipc_group *tipc_group_create(struct net *net, u32 portid, |
| 162 | struct tipc_group_req *mreq) |
| 163 | { |
| 164 | struct tipc_group *grp; |
| 165 | u32 type = mreq->type; |
| 166 | |
| 167 | grp = kzalloc(sizeof(*grp), GFP_ATOMIC); |
| 168 | if (!grp) |
| 169 | return NULL; |
| 170 | tipc_nlist_init(&grp->dests, tipc_own_addr(net)); |
Jon Maloy | b7d4263 | 2017-10-13 11:04:26 +0200 | [diff] [blame] | 171 | INIT_LIST_HEAD(&grp->congested); |
Jon Maloy | 04d7b57 | 2017-10-13 11:04:34 +0200 | [diff] [blame] | 172 | INIT_LIST_HEAD(&grp->active); |
| 173 | INIT_LIST_HEAD(&grp->pending); |
| 174 | INIT_LIST_HEAD(&grp->reclaiming); |
Jon Maloy | 75da216 | 2017-10-13 11:04:23 +0200 | [diff] [blame] | 175 | grp->members = RB_ROOT; |
| 176 | grp->net = net; |
| 177 | grp->portid = portid; |
| 178 | grp->domain = addr_domain(net, mreq->scope); |
| 179 | grp->type = type; |
| 180 | grp->instance = mreq->instance; |
| 181 | grp->scope = mreq->scope; |
| 182 | grp->loopback = mreq->flags & TIPC_GROUP_LOOPBACK; |
Jon Maloy | ae236fb | 2017-10-13 11:04:25 +0200 | [diff] [blame] | 183 | grp->events = mreq->flags & TIPC_GROUP_MEMBER_EVTS; |
Jon Maloy | 75da216 | 2017-10-13 11:04:23 +0200 | [diff] [blame] | 184 | if (tipc_topsrv_kern_subscr(net, portid, type, 0, ~0, &grp->subid)) |
| 185 | return grp; |
| 186 | kfree(grp); |
| 187 | return NULL; |
| 188 | } |
| 189 | |
| 190 | void tipc_group_delete(struct net *net, struct tipc_group *grp) |
| 191 | { |
| 192 | struct rb_root *tree = &grp->members; |
| 193 | struct tipc_member *m, *tmp; |
| 194 | struct sk_buff_head xmitq; |
| 195 | |
| 196 | __skb_queue_head_init(&xmitq); |
| 197 | |
| 198 | rbtree_postorder_for_each_entry_safe(m, tmp, tree, tree_node) { |
| 199 | tipc_group_proto_xmit(grp, m, GRP_LEAVE_MSG, &xmitq); |
| 200 | list_del(&m->list); |
| 201 | kfree(m); |
| 202 | } |
| 203 | tipc_node_distr_xmit(net, &xmitq); |
| 204 | tipc_nlist_purge(&grp->dests); |
| 205 | tipc_topsrv_kern_unsubscr(net, grp->subid); |
| 206 | kfree(grp); |
| 207 | } |
| 208 | |
| 209 | struct tipc_member *tipc_group_find_member(struct tipc_group *grp, |
| 210 | u32 node, u32 port) |
| 211 | { |
| 212 | struct rb_node *n = grp->members.rb_node; |
| 213 | u64 nkey, key = (u64)node << 32 | port; |
| 214 | struct tipc_member *m; |
| 215 | |
| 216 | while (n) { |
| 217 | m = container_of(n, struct tipc_member, tree_node); |
| 218 | nkey = (u64)m->node << 32 | m->port; |
| 219 | if (key < nkey) |
| 220 | n = n->rb_left; |
| 221 | else if (key > nkey) |
| 222 | n = n->rb_right; |
| 223 | else |
| 224 | return m; |
| 225 | } |
| 226 | return NULL; |
| 227 | } |
| 228 | |
Jon Maloy | 27bd9ec | 2017-10-13 11:04:27 +0200 | [diff] [blame] | 229 | static struct tipc_member *tipc_group_find_dest(struct tipc_group *grp, |
| 230 | u32 node, u32 port) |
| 231 | { |
| 232 | struct tipc_member *m; |
| 233 | |
| 234 | m = tipc_group_find_member(grp, node, port); |
| 235 | if (m && tipc_group_is_enabled(m)) |
| 236 | return m; |
| 237 | return NULL; |
| 238 | } |
| 239 | |
Jon Maloy | 75da216 | 2017-10-13 11:04:23 +0200 | [diff] [blame] | 240 | static struct tipc_member *tipc_group_find_node(struct tipc_group *grp, |
| 241 | u32 node) |
| 242 | { |
| 243 | struct tipc_member *m; |
| 244 | struct rb_node *n; |
| 245 | |
| 246 | for (n = rb_first(&grp->members); n; n = rb_next(n)) { |
| 247 | m = container_of(n, struct tipc_member, tree_node); |
| 248 | if (m->node == node) |
| 249 | return m; |
| 250 | } |
| 251 | return NULL; |
| 252 | } |
| 253 | |
| 254 | static void tipc_group_add_to_tree(struct tipc_group *grp, |
| 255 | struct tipc_member *m) |
| 256 | { |
| 257 | u64 nkey, key = (u64)m->node << 32 | m->port; |
| 258 | struct rb_node **n, *parent = NULL; |
| 259 | struct tipc_member *tmp; |
| 260 | |
| 261 | n = &grp->members.rb_node; |
| 262 | while (*n) { |
| 263 | tmp = container_of(*n, struct tipc_member, tree_node); |
| 264 | parent = *n; |
| 265 | tmp = container_of(parent, struct tipc_member, tree_node); |
| 266 | nkey = (u64)tmp->node << 32 | tmp->port; |
| 267 | if (key < nkey) |
| 268 | n = &(*n)->rb_left; |
| 269 | else if (key > nkey) |
| 270 | n = &(*n)->rb_right; |
| 271 | else |
| 272 | return; |
| 273 | } |
| 274 | rb_link_node(&m->tree_node, parent, n); |
| 275 | rb_insert_color(&m->tree_node, &grp->members); |
| 276 | } |
| 277 | |
| 278 | static struct tipc_member *tipc_group_create_member(struct tipc_group *grp, |
| 279 | u32 node, u32 port, |
| 280 | int state) |
| 281 | { |
| 282 | struct tipc_member *m; |
| 283 | |
| 284 | m = kzalloc(sizeof(*m), GFP_ATOMIC); |
| 285 | if (!m) |
| 286 | return NULL; |
| 287 | INIT_LIST_HEAD(&m->list); |
Jon Maloy | b7d4263 | 2017-10-13 11:04:26 +0200 | [diff] [blame] | 288 | INIT_LIST_HEAD(&m->congested); |
Jon Maloy | b87a5ea | 2017-10-13 11:04:30 +0200 | [diff] [blame] | 289 | __skb_queue_head_init(&m->deferredq); |
Jon Maloy | b7d4263 | 2017-10-13 11:04:26 +0200 | [diff] [blame] | 290 | m->group = grp; |
Jon Maloy | 75da216 | 2017-10-13 11:04:23 +0200 | [diff] [blame] | 291 | m->node = node; |
| 292 | m->port = port; |
Jon Maloy | 2f48771 | 2017-10-13 11:04:31 +0200 | [diff] [blame] | 293 | m->bc_acked = grp->bc_snd_nxt - 1; |
Jon Maloy | 75da216 | 2017-10-13 11:04:23 +0200 | [diff] [blame] | 294 | grp->member_cnt++; |
| 295 | tipc_group_add_to_tree(grp, m); |
| 296 | tipc_nlist_add(&grp->dests, m->node); |
| 297 | m->state = state; |
| 298 | return m; |
| 299 | } |
| 300 | |
| 301 | void tipc_group_add_member(struct tipc_group *grp, u32 node, u32 port) |
| 302 | { |
| 303 | tipc_group_create_member(grp, node, port, MBR_DISCOVERED); |
| 304 | } |
| 305 | |
| 306 | static void tipc_group_delete_member(struct tipc_group *grp, |
| 307 | struct tipc_member *m) |
| 308 | { |
| 309 | rb_erase(&m->tree_node, &grp->members); |
| 310 | grp->member_cnt--; |
Jon Maloy | 2f48771 | 2017-10-13 11:04:31 +0200 | [diff] [blame] | 311 | |
| 312 | /* Check if we were waiting for replicast ack from this member */ |
| 313 | if (grp->bc_ackers && less(m->bc_acked, grp->bc_snd_nxt - 1)) |
| 314 | grp->bc_ackers--; |
| 315 | |
Jon Maloy | 75da216 | 2017-10-13 11:04:23 +0200 | [diff] [blame] | 316 | list_del_init(&m->list); |
Jon Maloy | b7d4263 | 2017-10-13 11:04:26 +0200 | [diff] [blame] | 317 | list_del_init(&m->congested); |
Jon Maloy | 04d7b57 | 2017-10-13 11:04:34 +0200 | [diff] [blame] | 318 | tipc_group_decr_active(grp, m); |
Jon Maloy | 75da216 | 2017-10-13 11:04:23 +0200 | [diff] [blame] | 319 | |
| 320 | /* If last member on a node, remove node from dest list */ |
| 321 | if (!tipc_group_find_node(grp, m->node)) |
| 322 | tipc_nlist_del(&grp->dests, m->node); |
| 323 | |
| 324 | kfree(m); |
| 325 | } |
| 326 | |
| 327 | struct tipc_nlist *tipc_group_dests(struct tipc_group *grp) |
| 328 | { |
| 329 | return &grp->dests; |
| 330 | } |
| 331 | |
| 332 | void tipc_group_self(struct tipc_group *grp, struct tipc_name_seq *seq, |
| 333 | int *scope) |
| 334 | { |
| 335 | seq->type = grp->type; |
| 336 | seq->lower = grp->instance; |
| 337 | seq->upper = grp->instance; |
| 338 | *scope = grp->scope; |
| 339 | } |
| 340 | |
Jon Maloy | b7d4263 | 2017-10-13 11:04:26 +0200 | [diff] [blame] | 341 | void tipc_group_update_member(struct tipc_member *m, int len) |
Jon Maloy | 75da216 | 2017-10-13 11:04:23 +0200 | [diff] [blame] | 342 | { |
Jon Maloy | b7d4263 | 2017-10-13 11:04:26 +0200 | [diff] [blame] | 343 | struct tipc_group *grp = m->group; |
| 344 | struct tipc_member *_m, *tmp; |
| 345 | |
| 346 | if (!tipc_group_is_enabled(m)) |
| 347 | return; |
| 348 | |
| 349 | m->window -= len; |
| 350 | |
| 351 | if (m->window >= ADV_IDLE) |
| 352 | return; |
| 353 | |
| 354 | if (!list_empty(&m->congested)) |
| 355 | return; |
| 356 | |
| 357 | /* Sort member into congested members' list */ |
| 358 | list_for_each_entry_safe(_m, tmp, &grp->congested, congested) { |
| 359 | if (m->window > _m->window) |
| 360 | continue; |
| 361 | list_add_tail(&m->congested, &_m->congested); |
| 362 | return; |
| 363 | } |
| 364 | list_add_tail(&m->congested, &grp->congested); |
| 365 | } |
| 366 | |
Jon Maloy | 2f48771 | 2017-10-13 11:04:31 +0200 | [diff] [blame] | 367 | 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] | 368 | { |
Jon Maloy | 2f48771 | 2017-10-13 11:04:31 +0200 | [diff] [blame] | 369 | u16 prev = grp->bc_snd_nxt - 1; |
Jon Maloy | b7d4263 | 2017-10-13 11:04:26 +0200 | [diff] [blame] | 370 | struct tipc_member *m; |
| 371 | struct rb_node *n; |
| 372 | |
| 373 | for (n = rb_first(&grp->members); n; n = rb_next(n)) { |
| 374 | m = container_of(n, struct tipc_member, tree_node); |
Jon Maloy | 2f48771 | 2017-10-13 11:04:31 +0200 | [diff] [blame] | 375 | if (tipc_group_is_enabled(m)) { |
Jon Maloy | b7d4263 | 2017-10-13 11:04:26 +0200 | [diff] [blame] | 376 | tipc_group_update_member(m, len); |
Jon Maloy | 2f48771 | 2017-10-13 11:04:31 +0200 | [diff] [blame] | 377 | m->bc_acked = prev; |
| 378 | } |
Jon Maloy | b7d4263 | 2017-10-13 11:04:26 +0200 | [diff] [blame] | 379 | } |
Jon Maloy | 2f48771 | 2017-10-13 11:04:31 +0200 | [diff] [blame] | 380 | |
| 381 | /* Mark number of acknowledges to expect, if any */ |
| 382 | if (ack) |
| 383 | grp->bc_ackers = grp->member_cnt; |
Jon Maloy | 75da216 | 2017-10-13 11:04:23 +0200 | [diff] [blame] | 384 | grp->bc_snd_nxt++; |
| 385 | } |
| 386 | |
Jon Maloy | 27bd9ec | 2017-10-13 11:04:27 +0200 | [diff] [blame] | 387 | bool tipc_group_cong(struct tipc_group *grp, u32 dnode, u32 dport, |
| 388 | int len, struct tipc_member **mbr) |
| 389 | { |
| 390 | struct sk_buff_head xmitq; |
| 391 | struct tipc_member *m; |
| 392 | int adv, state; |
| 393 | |
| 394 | m = tipc_group_find_dest(grp, dnode, dport); |
| 395 | *mbr = m; |
| 396 | if (!m) |
| 397 | return false; |
| 398 | if (m->usr_pending) |
| 399 | return true; |
| 400 | if (m->window >= len) |
| 401 | return false; |
| 402 | m->usr_pending = true; |
| 403 | |
| 404 | /* If not fully advertised, do it now to prevent mutual blocking */ |
| 405 | adv = m->advertised; |
| 406 | state = m->state; |
| 407 | if (state < MBR_JOINED) |
| 408 | return true; |
| 409 | if (state == MBR_JOINED && adv == ADV_IDLE) |
| 410 | return true; |
Jon Maloy | 04d7b57 | 2017-10-13 11:04:34 +0200 | [diff] [blame] | 411 | if (state == MBR_ACTIVE && adv == ADV_ACTIVE) |
| 412 | return true; |
| 413 | if (state == MBR_PENDING && adv == ADV_IDLE) |
| 414 | return true; |
Jon Maloy | 27bd9ec | 2017-10-13 11:04:27 +0200 | [diff] [blame] | 415 | skb_queue_head_init(&xmitq); |
| 416 | tipc_group_proto_xmit(grp, m, GRP_ADV_MSG, &xmitq); |
| 417 | tipc_node_distr_xmit(grp->net, &xmitq); |
| 418 | return true; |
| 419 | } |
| 420 | |
Jon Maloy | b7d4263 | 2017-10-13 11:04:26 +0200 | [diff] [blame] | 421 | bool tipc_group_bc_cong(struct tipc_group *grp, int len) |
| 422 | { |
Jon Maloy | 27bd9ec | 2017-10-13 11:04:27 +0200 | [diff] [blame] | 423 | struct tipc_member *m = NULL; |
Jon Maloy | b7d4263 | 2017-10-13 11:04:26 +0200 | [diff] [blame] | 424 | |
Jon Maloy | 2f48771 | 2017-10-13 11:04:31 +0200 | [diff] [blame] | 425 | /* If prev bcast was replicast, reject until all receivers have acked */ |
| 426 | if (grp->bc_ackers) |
| 427 | return true; |
| 428 | |
Jon Maloy | b7d4263 | 2017-10-13 11:04:26 +0200 | [diff] [blame] | 429 | if (list_empty(&grp->congested)) |
| 430 | return false; |
| 431 | |
| 432 | m = list_first_entry(&grp->congested, struct tipc_member, congested); |
| 433 | if (m->window >= len) |
| 434 | return false; |
| 435 | |
Jon Maloy | 27bd9ec | 2017-10-13 11:04:27 +0200 | [diff] [blame] | 436 | return tipc_group_cong(grp, m->node, m->port, len, &m); |
Jon Maloy | b7d4263 | 2017-10-13 11:04:26 +0200 | [diff] [blame] | 437 | } |
| 438 | |
Jon Maloy | b87a5ea | 2017-10-13 11:04:30 +0200 | [diff] [blame] | 439 | /* tipc_group_sort_msg() - sort msg into queue by bcast sequence number |
| 440 | */ |
| 441 | static void tipc_group_sort_msg(struct sk_buff *skb, struct sk_buff_head *defq) |
| 442 | { |
| 443 | struct tipc_msg *_hdr, *hdr = buf_msg(skb); |
| 444 | u16 bc_seqno = msg_grp_bc_seqno(hdr); |
| 445 | struct sk_buff *_skb, *tmp; |
| 446 | int mtyp = msg_type(hdr); |
| 447 | |
Jon Maloy | a3bada7 | 2017-10-13 11:04:33 +0200 | [diff] [blame] | 448 | /* 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] | 449 | if (mtyp == TIPC_GRP_BCAST_MSG || mtyp == TIPC_GRP_MCAST_MSG) { |
| 450 | skb_queue_walk_safe(defq, _skb, tmp) { |
| 451 | _hdr = buf_msg(_skb); |
| 452 | if (!less(bc_seqno, msg_grp_bc_seqno(_hdr))) |
| 453 | continue; |
| 454 | __skb_queue_before(defq, _skb, skb); |
| 455 | return; |
| 456 | } |
| 457 | /* Bcast was not bypassed, - add to tail */ |
| 458 | } |
| 459 | /* Unicasts are never bypassed, - always add to tail */ |
| 460 | __skb_queue_tail(defq, skb); |
| 461 | } |
| 462 | |
Jon Maloy | 75da216 | 2017-10-13 11:04:23 +0200 | [diff] [blame] | 463 | /* tipc_group_filter_msg() - determine if we should accept arriving message |
| 464 | */ |
| 465 | void tipc_group_filter_msg(struct tipc_group *grp, struct sk_buff_head *inputq, |
| 466 | struct sk_buff_head *xmitq) |
| 467 | { |
| 468 | struct sk_buff *skb = __skb_dequeue(inputq); |
Jon Maloy | a3bada7 | 2017-10-13 11:04:33 +0200 | [diff] [blame] | 469 | bool ack, deliver, update, leave = false; |
Jon Maloy | b87a5ea | 2017-10-13 11:04:30 +0200 | [diff] [blame] | 470 | struct sk_buff_head *defq; |
Jon Maloy | 75da216 | 2017-10-13 11:04:23 +0200 | [diff] [blame] | 471 | struct tipc_member *m; |
| 472 | struct tipc_msg *hdr; |
| 473 | u32 node, port; |
Jon Maloy | b87a5ea | 2017-10-13 11:04:30 +0200 | [diff] [blame] | 474 | int mtyp, blks; |
Jon Maloy | 75da216 | 2017-10-13 11:04:23 +0200 | [diff] [blame] | 475 | |
| 476 | if (!skb) |
| 477 | return; |
| 478 | |
| 479 | hdr = buf_msg(skb); |
Jon Maloy | 75da216 | 2017-10-13 11:04:23 +0200 | [diff] [blame] | 480 | node = msg_orignode(hdr); |
| 481 | port = msg_origport(hdr); |
| 482 | |
| 483 | if (!msg_in_group(hdr)) |
| 484 | goto drop; |
| 485 | |
| 486 | m = tipc_group_find_member(grp, node, port); |
| 487 | if (!tipc_group_is_receiver(m)) |
| 488 | goto drop; |
| 489 | |
Jon Maloy | b87a5ea | 2017-10-13 11:04:30 +0200 | [diff] [blame] | 490 | if (less(msg_grp_bc_seqno(hdr), m->bc_rcv_nxt)) |
| 491 | goto drop; |
Jon Maloy | 5b8dddb | 2017-10-13 11:04:29 +0200 | [diff] [blame] | 492 | |
Jon Maloy | 31c82a2 | 2017-10-13 11:04:24 +0200 | [diff] [blame] | 493 | TIPC_SKB_CB(skb)->orig_member = m->instance; |
Jon Maloy | b87a5ea | 2017-10-13 11:04:30 +0200 | [diff] [blame] | 494 | defq = &m->deferredq; |
| 495 | tipc_group_sort_msg(skb, defq); |
Jon Maloy | 75da216 | 2017-10-13 11:04:23 +0200 | [diff] [blame] | 496 | |
Jon Maloy | b87a5ea | 2017-10-13 11:04:30 +0200 | [diff] [blame] | 497 | while ((skb = skb_peek(defq))) { |
| 498 | hdr = buf_msg(skb); |
| 499 | mtyp = msg_type(hdr); |
| 500 | deliver = true; |
Jon Maloy | 2f48771 | 2017-10-13 11:04:31 +0200 | [diff] [blame] | 501 | ack = false; |
Jon Maloy | b87a5ea | 2017-10-13 11:04:30 +0200 | [diff] [blame] | 502 | update = false; |
| 503 | |
| 504 | if (more(msg_grp_bc_seqno(hdr), m->bc_rcv_nxt)) |
| 505 | break; |
| 506 | |
| 507 | /* Decide what to do with message */ |
| 508 | switch (mtyp) { |
| 509 | case TIPC_GRP_MCAST_MSG: |
| 510 | if (msg_nameinst(hdr) != grp->instance) { |
| 511 | update = true; |
| 512 | deliver = false; |
| 513 | } |
| 514 | /* Fall thru */ |
| 515 | case TIPC_GRP_BCAST_MSG: |
| 516 | m->bc_rcv_nxt++; |
Jon Maloy | 2f48771 | 2017-10-13 11:04:31 +0200 | [diff] [blame] | 517 | ack = msg_grp_bc_ack_req(hdr); |
Jon Maloy | b87a5ea | 2017-10-13 11:04:30 +0200 | [diff] [blame] | 518 | break; |
| 519 | case TIPC_GRP_UCAST_MSG: |
| 520 | break; |
Jon Maloy | a3bada7 | 2017-10-13 11:04:33 +0200 | [diff] [blame] | 521 | case TIPC_GRP_MEMBER_EVT: |
| 522 | if (m->state == MBR_LEAVING) |
| 523 | leave = true; |
| 524 | if (!grp->events) |
| 525 | deliver = false; |
| 526 | break; |
Jon Maloy | b87a5ea | 2017-10-13 11:04:30 +0200 | [diff] [blame] | 527 | default: |
| 528 | break; |
| 529 | } |
| 530 | |
| 531 | /* Execute decisions */ |
| 532 | __skb_dequeue(defq); |
| 533 | if (deliver) |
| 534 | __skb_queue_tail(inputq, skb); |
| 535 | else |
| 536 | kfree_skb(skb); |
| 537 | |
Jon Maloy | 2f48771 | 2017-10-13 11:04:31 +0200 | [diff] [blame] | 538 | if (ack) |
| 539 | tipc_group_proto_xmit(grp, m, GRP_ACK_MSG, xmitq); |
| 540 | |
Jon Maloy | a3bada7 | 2017-10-13 11:04:33 +0200 | [diff] [blame] | 541 | if (leave) { |
Jon Maloy | a3bada7 | 2017-10-13 11:04:33 +0200 | [diff] [blame] | 542 | __skb_queue_purge(defq); |
Jon Maloy | e0e853a | 2017-11-20 21:43:03 +0100 | [diff] [blame^] | 543 | tipc_group_delete_member(grp, m); |
Jon Maloy | a3bada7 | 2017-10-13 11:04:33 +0200 | [diff] [blame] | 544 | break; |
| 545 | } |
Jon Maloy | b87a5ea | 2017-10-13 11:04:30 +0200 | [diff] [blame] | 546 | if (!update) |
| 547 | continue; |
| 548 | |
| 549 | blks = msg_blocks(hdr); |
| 550 | tipc_group_update_rcv_win(grp, blks, node, port, xmitq); |
| 551 | } |
Jon Maloy | 75da216 | 2017-10-13 11:04:23 +0200 | [diff] [blame] | 552 | return; |
| 553 | drop: |
| 554 | kfree_skb(skb); |
| 555 | } |
| 556 | |
Jon Maloy | b7d4263 | 2017-10-13 11:04:26 +0200 | [diff] [blame] | 557 | void tipc_group_update_rcv_win(struct tipc_group *grp, int blks, u32 node, |
| 558 | u32 port, struct sk_buff_head *xmitq) |
| 559 | { |
Jon Maloy | 04d7b57 | 2017-10-13 11:04:34 +0200 | [diff] [blame] | 560 | struct list_head *active = &grp->active; |
| 561 | int max_active = grp->max_active; |
| 562 | int reclaim_limit = max_active * 3 / 4; |
| 563 | int active_cnt = grp->active_cnt; |
| 564 | struct tipc_member *m, *rm; |
Jon Maloy | b7d4263 | 2017-10-13 11:04:26 +0200 | [diff] [blame] | 565 | |
| 566 | m = tipc_group_find_member(grp, node, port); |
| 567 | if (!m) |
| 568 | return; |
| 569 | |
| 570 | m->advertised -= blks; |
| 571 | |
| 572 | switch (m->state) { |
| 573 | case MBR_JOINED: |
Jon Maloy | 04d7b57 | 2017-10-13 11:04:34 +0200 | [diff] [blame] | 574 | /* Reclaim advertised space from least active member */ |
| 575 | if (!list_empty(active) && active_cnt >= reclaim_limit) { |
| 576 | rm = list_first_entry(active, struct tipc_member, list); |
| 577 | rm->state = MBR_RECLAIMING; |
| 578 | list_move_tail(&rm->list, &grp->reclaiming); |
| 579 | tipc_group_proto_xmit(grp, rm, GRP_RECLAIM_MSG, xmitq); |
| 580 | } |
| 581 | /* If max active, become pending and wait for reclaimed space */ |
| 582 | if (active_cnt >= max_active) { |
| 583 | m->state = MBR_PENDING; |
| 584 | list_add_tail(&m->list, &grp->pending); |
| 585 | break; |
| 586 | } |
| 587 | /* Otherwise become active */ |
| 588 | m->state = MBR_ACTIVE; |
| 589 | list_add_tail(&m->list, &grp->active); |
| 590 | grp->active_cnt++; |
| 591 | /* Fall through */ |
| 592 | case MBR_ACTIVE: |
| 593 | if (!list_is_last(&m->list, &grp->active)) |
| 594 | list_move_tail(&m->list, &grp->active); |
| 595 | if (m->advertised > (ADV_ACTIVE * 3 / 4)) |
| 596 | break; |
| 597 | tipc_group_proto_xmit(grp, m, GRP_ADV_MSG, xmitq); |
Jon Maloy | b7d4263 | 2017-10-13 11:04:26 +0200 | [diff] [blame] | 598 | break; |
Jon Maloy | 04d7b57 | 2017-10-13 11:04:34 +0200 | [diff] [blame] | 599 | case MBR_REMITTED: |
| 600 | if (m->advertised > ADV_IDLE) |
| 601 | break; |
| 602 | m->state = MBR_JOINED; |
| 603 | if (m->advertised < ADV_IDLE) { |
| 604 | pr_warn_ratelimited("Rcv unexpected msg after REMIT\n"); |
| 605 | tipc_group_proto_xmit(grp, m, GRP_ADV_MSG, xmitq); |
| 606 | } |
| 607 | break; |
| 608 | case MBR_RECLAIMING: |
Jon Maloy | b7d4263 | 2017-10-13 11:04:26 +0200 | [diff] [blame] | 609 | case MBR_DISCOVERED: |
| 610 | case MBR_JOINING: |
| 611 | case MBR_LEAVING: |
| 612 | default: |
| 613 | break; |
| 614 | } |
| 615 | } |
| 616 | |
Jon Maloy | 75da216 | 2017-10-13 11:04:23 +0200 | [diff] [blame] | 617 | static void tipc_group_proto_xmit(struct tipc_group *grp, struct tipc_member *m, |
| 618 | int mtyp, struct sk_buff_head *xmitq) |
| 619 | { |
| 620 | struct tipc_msg *hdr; |
| 621 | struct sk_buff *skb; |
Jon Maloy | b7d4263 | 2017-10-13 11:04:26 +0200 | [diff] [blame] | 622 | int adv = 0; |
Jon Maloy | 75da216 | 2017-10-13 11:04:23 +0200 | [diff] [blame] | 623 | |
| 624 | skb = tipc_msg_create(GROUP_PROTOCOL, mtyp, INT_H_SIZE, 0, |
| 625 | m->node, tipc_own_addr(grp->net), |
| 626 | m->port, grp->portid, 0); |
| 627 | if (!skb) |
| 628 | return; |
| 629 | |
Jon Maloy | 04d7b57 | 2017-10-13 11:04:34 +0200 | [diff] [blame] | 630 | if (m->state == MBR_ACTIVE) |
Jon Maloy | b7d4263 | 2017-10-13 11:04:26 +0200 | [diff] [blame] | 631 | adv = ADV_ACTIVE - m->advertised; |
Jon Maloy | 04d7b57 | 2017-10-13 11:04:34 +0200 | [diff] [blame] | 632 | else if (m->state == MBR_JOINED || m->state == MBR_PENDING) |
| 633 | adv = ADV_IDLE - m->advertised; |
Jon Maloy | b7d4263 | 2017-10-13 11:04:26 +0200 | [diff] [blame] | 634 | |
Jon Maloy | 75da216 | 2017-10-13 11:04:23 +0200 | [diff] [blame] | 635 | hdr = buf_msg(skb); |
Jon Maloy | b7d4263 | 2017-10-13 11:04:26 +0200 | [diff] [blame] | 636 | |
| 637 | if (mtyp == GRP_JOIN_MSG) { |
Jon Maloy | 75da216 | 2017-10-13 11:04:23 +0200 | [diff] [blame] | 638 | msg_set_grp_bc_syncpt(hdr, grp->bc_snd_nxt); |
Jon Maloy | b7d4263 | 2017-10-13 11:04:26 +0200 | [diff] [blame] | 639 | msg_set_adv_win(hdr, adv); |
| 640 | m->advertised += adv; |
Jon Maloy | a3bada7 | 2017-10-13 11:04:33 +0200 | [diff] [blame] | 641 | } else if (mtyp == GRP_LEAVE_MSG) { |
| 642 | msg_set_grp_bc_syncpt(hdr, grp->bc_snd_nxt); |
Jon Maloy | b7d4263 | 2017-10-13 11:04:26 +0200 | [diff] [blame] | 643 | } else if (mtyp == GRP_ADV_MSG) { |
| 644 | msg_set_adv_win(hdr, adv); |
| 645 | m->advertised += adv; |
Jon Maloy | 2f48771 | 2017-10-13 11:04:31 +0200 | [diff] [blame] | 646 | } else if (mtyp == GRP_ACK_MSG) { |
| 647 | msg_set_grp_bc_acked(hdr, m->bc_rcv_nxt); |
Jon Maloy | 04d7b57 | 2017-10-13 11:04:34 +0200 | [diff] [blame] | 648 | } else if (mtyp == GRP_REMIT_MSG) { |
| 649 | msg_set_grp_remitted(hdr, m->window); |
Jon Maloy | b7d4263 | 2017-10-13 11:04:26 +0200 | [diff] [blame] | 650 | } |
Jon Maloy | 75da216 | 2017-10-13 11:04:23 +0200 | [diff] [blame] | 651 | __skb_queue_tail(xmitq, skb); |
| 652 | } |
| 653 | |
Jon Maloy | b7d4263 | 2017-10-13 11:04:26 +0200 | [diff] [blame] | 654 | void tipc_group_proto_rcv(struct tipc_group *grp, bool *usr_wakeup, |
| 655 | struct tipc_msg *hdr, struct sk_buff_head *inputq, |
Jon Maloy | 75da216 | 2017-10-13 11:04:23 +0200 | [diff] [blame] | 656 | struct sk_buff_head *xmitq) |
| 657 | { |
| 658 | u32 node = msg_orignode(hdr); |
| 659 | u32 port = msg_origport(hdr); |
Jon Maloy | 04d7b57 | 2017-10-13 11:04:34 +0200 | [diff] [blame] | 660 | struct tipc_member *m, *pm; |
Jon Maloy | a3bada7 | 2017-10-13 11:04:33 +0200 | [diff] [blame] | 661 | struct tipc_msg *ehdr; |
Jon Maloy | 04d7b57 | 2017-10-13 11:04:34 +0200 | [diff] [blame] | 662 | u16 remitted, in_flight; |
Jon Maloy | 75da216 | 2017-10-13 11:04:23 +0200 | [diff] [blame] | 663 | |
| 664 | if (!grp) |
| 665 | return; |
| 666 | |
| 667 | m = tipc_group_find_member(grp, node, port); |
| 668 | |
| 669 | switch (msg_type(hdr)) { |
| 670 | case GRP_JOIN_MSG: |
| 671 | if (!m) |
| 672 | m = tipc_group_create_member(grp, node, port, |
| 673 | MBR_QUARANTINED); |
| 674 | if (!m) |
| 675 | return; |
Jon Maloy | a3bada7 | 2017-10-13 11:04:33 +0200 | [diff] [blame] | 676 | m->bc_syncpt = msg_grp_bc_syncpt(hdr); |
| 677 | m->bc_rcv_nxt = m->bc_syncpt; |
Jon Maloy | b7d4263 | 2017-10-13 11:04:26 +0200 | [diff] [blame] | 678 | m->window += msg_adv_win(hdr); |
Jon Maloy | 75da216 | 2017-10-13 11:04:23 +0200 | [diff] [blame] | 679 | |
| 680 | /* Wait until PUBLISH event is received */ |
Jon Maloy | ae236fb | 2017-10-13 11:04:25 +0200 | [diff] [blame] | 681 | if (m->state == MBR_DISCOVERED) { |
Jon Maloy | 75da216 | 2017-10-13 11:04:23 +0200 | [diff] [blame] | 682 | m->state = MBR_JOINING; |
Jon Maloy | ae236fb | 2017-10-13 11:04:25 +0200 | [diff] [blame] | 683 | } else if (m->state == MBR_PUBLISHED) { |
Jon Maloy | 75da216 | 2017-10-13 11:04:23 +0200 | [diff] [blame] | 684 | m->state = MBR_JOINED; |
Jon Maloy | b7d4263 | 2017-10-13 11:04:26 +0200 | [diff] [blame] | 685 | *usr_wakeup = true; |
| 686 | m->usr_pending = false; |
| 687 | tipc_group_proto_xmit(grp, m, GRP_ADV_MSG, xmitq); |
Jon Maloy | a3bada7 | 2017-10-13 11:04:33 +0200 | [diff] [blame] | 688 | ehdr = buf_msg(m->event_msg); |
| 689 | msg_set_grp_bc_seqno(ehdr, m->bc_syncpt); |
Jon Maloy | ae236fb | 2017-10-13 11:04:25 +0200 | [diff] [blame] | 690 | __skb_queue_tail(inputq, m->event_msg); |
| 691 | } |
Jon Maloy | b7d4263 | 2017-10-13 11:04:26 +0200 | [diff] [blame] | 692 | if (m->window < ADV_IDLE) |
| 693 | tipc_group_update_member(m, 0); |
| 694 | else |
| 695 | list_del_init(&m->congested); |
Jon Maloy | 75da216 | 2017-10-13 11:04:23 +0200 | [diff] [blame] | 696 | return; |
| 697 | case GRP_LEAVE_MSG: |
| 698 | if (!m) |
| 699 | return; |
Jon Maloy | a3bada7 | 2017-10-13 11:04:33 +0200 | [diff] [blame] | 700 | m->bc_syncpt = msg_grp_bc_syncpt(hdr); |
Jon Maloy | 75da216 | 2017-10-13 11:04:23 +0200 | [diff] [blame] | 701 | |
| 702 | /* Wait until WITHDRAW event is received */ |
| 703 | if (m->state != MBR_LEAVING) { |
Jon Maloy | 04d7b57 | 2017-10-13 11:04:34 +0200 | [diff] [blame] | 704 | tipc_group_decr_active(grp, m); |
Jon Maloy | 75da216 | 2017-10-13 11:04:23 +0200 | [diff] [blame] | 705 | m->state = MBR_LEAVING; |
| 706 | return; |
| 707 | } |
| 708 | /* Otherwise deliver already received WITHDRAW event */ |
Jon Maloy | a3bada7 | 2017-10-13 11:04:33 +0200 | [diff] [blame] | 709 | ehdr = buf_msg(m->event_msg); |
| 710 | msg_set_grp_bc_seqno(ehdr, m->bc_syncpt); |
Jon Maloy | ae236fb | 2017-10-13 11:04:25 +0200 | [diff] [blame] | 711 | __skb_queue_tail(inputq, m->event_msg); |
Jon Maloy | 2f48771 | 2017-10-13 11:04:31 +0200 | [diff] [blame] | 712 | *usr_wakeup = true; |
Jon Maloy | b7d4263 | 2017-10-13 11:04:26 +0200 | [diff] [blame] | 713 | list_del_init(&m->congested); |
| 714 | return; |
| 715 | case GRP_ADV_MSG: |
| 716 | if (!m) |
| 717 | return; |
| 718 | m->window += msg_adv_win(hdr); |
| 719 | *usr_wakeup = m->usr_pending; |
| 720 | m->usr_pending = false; |
| 721 | list_del_init(&m->congested); |
Jon Maloy | 75da216 | 2017-10-13 11:04:23 +0200 | [diff] [blame] | 722 | return; |
Jon Maloy | 2f48771 | 2017-10-13 11:04:31 +0200 | [diff] [blame] | 723 | case GRP_ACK_MSG: |
| 724 | if (!m) |
| 725 | return; |
| 726 | m->bc_acked = msg_grp_bc_acked(hdr); |
| 727 | if (--grp->bc_ackers) |
| 728 | break; |
| 729 | *usr_wakeup = true; |
| 730 | m->usr_pending = false; |
| 731 | return; |
Jon Maloy | 04d7b57 | 2017-10-13 11:04:34 +0200 | [diff] [blame] | 732 | case GRP_RECLAIM_MSG: |
| 733 | if (!m) |
| 734 | return; |
| 735 | *usr_wakeup = m->usr_pending; |
| 736 | m->usr_pending = false; |
| 737 | tipc_group_proto_xmit(grp, m, GRP_REMIT_MSG, xmitq); |
| 738 | m->window = ADV_IDLE; |
| 739 | return; |
| 740 | case GRP_REMIT_MSG: |
| 741 | if (!m || m->state != MBR_RECLAIMING) |
| 742 | return; |
| 743 | |
| 744 | list_del_init(&m->list); |
| 745 | grp->active_cnt--; |
| 746 | remitted = msg_grp_remitted(hdr); |
| 747 | |
| 748 | /* Messages preceding the REMIT still in receive queue */ |
| 749 | if (m->advertised > remitted) { |
| 750 | m->state = MBR_REMITTED; |
| 751 | in_flight = m->advertised - remitted; |
| 752 | } |
| 753 | /* All messages preceding the REMIT have been read */ |
| 754 | if (m->advertised <= remitted) { |
| 755 | m->state = MBR_JOINED; |
| 756 | in_flight = 0; |
| 757 | } |
| 758 | /* ..and the REMIT overtaken by more messages => re-advertise */ |
| 759 | if (m->advertised < remitted) |
| 760 | tipc_group_proto_xmit(grp, m, GRP_ADV_MSG, xmitq); |
| 761 | |
| 762 | m->advertised = ADV_IDLE + in_flight; |
| 763 | |
| 764 | /* Set oldest pending member to active and advertise */ |
| 765 | if (list_empty(&grp->pending)) |
| 766 | return; |
| 767 | pm = list_first_entry(&grp->pending, struct tipc_member, list); |
| 768 | pm->state = MBR_ACTIVE; |
| 769 | list_move_tail(&pm->list, &grp->active); |
| 770 | grp->active_cnt++; |
| 771 | if (pm->advertised <= (ADV_ACTIVE * 3 / 4)) |
| 772 | tipc_group_proto_xmit(grp, pm, GRP_ADV_MSG, xmitq); |
| 773 | return; |
Jon Maloy | 75da216 | 2017-10-13 11:04:23 +0200 | [diff] [blame] | 774 | default: |
| 775 | pr_warn("Received unknown GROUP_PROTO message\n"); |
| 776 | } |
| 777 | } |
| 778 | |
Jon Maloy | b7d4263 | 2017-10-13 11:04:26 +0200 | [diff] [blame] | 779 | /* tipc_group_member_evt() - receive and handle a member up/down event |
| 780 | */ |
Jon Maloy | 75da216 | 2017-10-13 11:04:23 +0200 | [diff] [blame] | 781 | void tipc_group_member_evt(struct tipc_group *grp, |
Jon Maloy | b7d4263 | 2017-10-13 11:04:26 +0200 | [diff] [blame] | 782 | bool *usr_wakeup, |
| 783 | int *sk_rcvbuf, |
Jon Maloy | 75da216 | 2017-10-13 11:04:23 +0200 | [diff] [blame] | 784 | struct sk_buff *skb, |
Jon Maloy | ae236fb | 2017-10-13 11:04:25 +0200 | [diff] [blame] | 785 | struct sk_buff_head *inputq, |
Jon Maloy | 75da216 | 2017-10-13 11:04:23 +0200 | [diff] [blame] | 786 | struct sk_buff_head *xmitq) |
| 787 | { |
| 788 | struct tipc_msg *hdr = buf_msg(skb); |
| 789 | struct tipc_event *evt = (void *)msg_data(hdr); |
Jon Maloy | ae236fb | 2017-10-13 11:04:25 +0200 | [diff] [blame] | 790 | u32 instance = evt->found_lower; |
Jon Maloy | 75da216 | 2017-10-13 11:04:23 +0200 | [diff] [blame] | 791 | u32 node = evt->port.node; |
| 792 | u32 port = evt->port.ref; |
Jon Maloy | ae236fb | 2017-10-13 11:04:25 +0200 | [diff] [blame] | 793 | int event = evt->event; |
Jon Maloy | 75da216 | 2017-10-13 11:04:23 +0200 | [diff] [blame] | 794 | struct tipc_member *m; |
| 795 | struct net *net; |
Jon Maloy | a3bada7 | 2017-10-13 11:04:33 +0200 | [diff] [blame] | 796 | bool node_up; |
Jon Maloy | 75da216 | 2017-10-13 11:04:23 +0200 | [diff] [blame] | 797 | u32 self; |
| 798 | |
| 799 | if (!grp) |
| 800 | goto drop; |
| 801 | |
| 802 | net = grp->net; |
| 803 | self = tipc_own_addr(net); |
| 804 | if (!grp->loopback && node == self && port == grp->portid) |
| 805 | goto drop; |
| 806 | |
Jon Maloy | ae236fb | 2017-10-13 11:04:25 +0200 | [diff] [blame] | 807 | /* Convert message before delivery to user */ |
| 808 | msg_set_hdr_sz(hdr, GROUP_H_SIZE); |
| 809 | msg_set_user(hdr, TIPC_CRITICAL_IMPORTANCE); |
| 810 | msg_set_type(hdr, TIPC_GRP_MEMBER_EVT); |
| 811 | msg_set_origport(hdr, port); |
| 812 | msg_set_orignode(hdr, node); |
| 813 | msg_set_nametype(hdr, grp->type); |
| 814 | msg_set_grp_evt(hdr, event); |
| 815 | |
Jon Maloy | 75da216 | 2017-10-13 11:04:23 +0200 | [diff] [blame] | 816 | m = tipc_group_find_member(grp, node, port); |
| 817 | |
Jon Maloy | ae236fb | 2017-10-13 11:04:25 +0200 | [diff] [blame] | 818 | if (event == TIPC_PUBLISHED) { |
Jon Maloy | 75da216 | 2017-10-13 11:04:23 +0200 | [diff] [blame] | 819 | if (!m) |
| 820 | m = tipc_group_create_member(grp, node, port, |
| 821 | MBR_DISCOVERED); |
| 822 | if (!m) |
| 823 | goto drop; |
| 824 | |
Jon Maloy | ae236fb | 2017-10-13 11:04:25 +0200 | [diff] [blame] | 825 | /* Hold back event if JOIN message not yet received */ |
| 826 | if (m->state == MBR_DISCOVERED) { |
| 827 | m->event_msg = skb; |
Jon Maloy | 75da216 | 2017-10-13 11:04:23 +0200 | [diff] [blame] | 828 | m->state = MBR_PUBLISHED; |
Jon Maloy | ae236fb | 2017-10-13 11:04:25 +0200 | [diff] [blame] | 829 | } else { |
Jon Maloy | a3bada7 | 2017-10-13 11:04:33 +0200 | [diff] [blame] | 830 | msg_set_grp_bc_seqno(hdr, m->bc_syncpt); |
Jon Maloy | ae236fb | 2017-10-13 11:04:25 +0200 | [diff] [blame] | 831 | __skb_queue_tail(inputq, skb); |
Jon Maloy | 75da216 | 2017-10-13 11:04:23 +0200 | [diff] [blame] | 832 | m->state = MBR_JOINED; |
Jon Maloy | b7d4263 | 2017-10-13 11:04:26 +0200 | [diff] [blame] | 833 | *usr_wakeup = true; |
| 834 | m->usr_pending = false; |
Jon Maloy | ae236fb | 2017-10-13 11:04:25 +0200 | [diff] [blame] | 835 | } |
| 836 | m->instance = instance; |
| 837 | TIPC_SKB_CB(skb)->orig_member = m->instance; |
Jon Maloy | 75da216 | 2017-10-13 11:04:23 +0200 | [diff] [blame] | 838 | tipc_group_proto_xmit(grp, m, GRP_JOIN_MSG, xmitq); |
Jon Maloy | b7d4263 | 2017-10-13 11:04:26 +0200 | [diff] [blame] | 839 | if (m->window < ADV_IDLE) |
| 840 | tipc_group_update_member(m, 0); |
| 841 | else |
| 842 | list_del_init(&m->congested); |
Jon Maloy | ae236fb | 2017-10-13 11:04:25 +0200 | [diff] [blame] | 843 | } else if (event == TIPC_WITHDRAWN) { |
Jon Maloy | 75da216 | 2017-10-13 11:04:23 +0200 | [diff] [blame] | 844 | if (!m) |
| 845 | goto drop; |
| 846 | |
Jon Maloy | ae236fb | 2017-10-13 11:04:25 +0200 | [diff] [blame] | 847 | TIPC_SKB_CB(skb)->orig_member = m->instance; |
| 848 | |
Jon Maloy | 2f48771 | 2017-10-13 11:04:31 +0200 | [diff] [blame] | 849 | *usr_wakeup = true; |
Jon Maloy | b7d4263 | 2017-10-13 11:04:26 +0200 | [diff] [blame] | 850 | m->usr_pending = false; |
Jon Maloy | a3bada7 | 2017-10-13 11:04:33 +0200 | [diff] [blame] | 851 | node_up = tipc_node_is_up(net, node); |
Jon Maloy | b7d4263 | 2017-10-13 11:04:26 +0200 | [diff] [blame] | 852 | |
Jon Maloy | ae236fb | 2017-10-13 11:04:25 +0200 | [diff] [blame] | 853 | /* Hold back event if more messages might be expected */ |
Jon Maloy | a3bada7 | 2017-10-13 11:04:33 +0200 | [diff] [blame] | 854 | if (m->state != MBR_LEAVING && node_up) { |
Jon Maloy | ae236fb | 2017-10-13 11:04:25 +0200 | [diff] [blame] | 855 | m->event_msg = skb; |
Jon Maloy | 04d7b57 | 2017-10-13 11:04:34 +0200 | [diff] [blame] | 856 | tipc_group_decr_active(grp, m); |
Jon Maloy | 75da216 | 2017-10-13 11:04:23 +0200 | [diff] [blame] | 857 | m->state = MBR_LEAVING; |
Jon Maloy | ae236fb | 2017-10-13 11:04:25 +0200 | [diff] [blame] | 858 | } else { |
Jon Maloy | a3bada7 | 2017-10-13 11:04:33 +0200 | [diff] [blame] | 859 | if (node_up) |
| 860 | msg_set_grp_bc_seqno(hdr, m->bc_syncpt); |
| 861 | else |
| 862 | msg_set_grp_bc_seqno(hdr, m->bc_rcv_nxt); |
Jon Maloy | ae236fb | 2017-10-13 11:04:25 +0200 | [diff] [blame] | 863 | __skb_queue_tail(inputq, skb); |
Jon Maloy | ae236fb | 2017-10-13 11:04:25 +0200 | [diff] [blame] | 864 | } |
Jon Maloy | b7d4263 | 2017-10-13 11:04:26 +0200 | [diff] [blame] | 865 | list_del_init(&m->congested); |
Jon Maloy | 75da216 | 2017-10-13 11:04:23 +0200 | [diff] [blame] | 866 | } |
Jon Maloy | b7d4263 | 2017-10-13 11:04:26 +0200 | [diff] [blame] | 867 | *sk_rcvbuf = tipc_group_rcvbuf_limit(grp); |
Jon Maloy | ae236fb | 2017-10-13 11:04:25 +0200 | [diff] [blame] | 868 | return; |
Jon Maloy | 75da216 | 2017-10-13 11:04:23 +0200 | [diff] [blame] | 869 | drop: |
| 870 | kfree_skb(skb); |
| 871 | } |