Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 1 | /* |
| 2 | * net/tipc/link.c: TIPC link code |
YOSHIFUJI Hideaki | c430728 | 2007-02-09 23:25:21 +0900 | [diff] [blame] | 3 | * |
Jon Paul Maloy | e74a386 | 2016-03-03 14:23:21 -0500 | [diff] [blame] | 4 | * Copyright (c) 1996-2007, 2012-2016, Ericsson AB |
Ying Xue | 198d73b | 2013-06-17 10:54:42 -0400 | [diff] [blame] | 5 | * Copyright (c) 2004-2007, 2010-2013, Wind River Systems |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 6 | * All rights reserved. |
| 7 | * |
Per Liden | 9ea1fd3 | 2006-01-11 13:30:43 +0100 | [diff] [blame] | 8 | * Redistribution and use in source and binary forms, with or without |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 9 | * modification, are permitted provided that the following conditions are met: |
| 10 | * |
Per Liden | 9ea1fd3 | 2006-01-11 13:30:43 +0100 | [diff] [blame] | 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. |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 19 | * |
Per Liden | 9ea1fd3 | 2006-01-11 13:30:43 +0100 | [diff] [blame] | 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 |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 34 | * POSSIBILITY OF SUCH DAMAGE. |
| 35 | */ |
| 36 | |
| 37 | #include "core.h" |
Jon Paul Maloy | e3eea1e | 2015-03-13 16:08:11 -0400 | [diff] [blame] | 38 | #include "subscr.h" |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 39 | #include "link.h" |
Richard Alpe | 7be57fc | 2014-11-20 10:29:12 +0100 | [diff] [blame] | 40 | #include "bcast.h" |
Jon Paul Maloy | 9816f06 | 2014-05-14 05:39:15 -0400 | [diff] [blame] | 41 | #include "socket.h" |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 42 | #include "name_distr.h" |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 43 | #include "discover.h" |
Richard Alpe | 0655f6a | 2014-11-20 10:29:07 +0100 | [diff] [blame] | 44 | #include "netlink.h" |
Jon Paul Maloy | 35c55c9 | 2016-06-13 20:46:22 -0400 | [diff] [blame] | 45 | #include "monitor.h" |
Tuong Lien | b4b9771 | 2018-12-19 09:17:56 +0700 | [diff] [blame] | 46 | #include "trace.h" |
Tuong Lien | fc1b6d6 | 2019-11-08 12:05:11 +0700 | [diff] [blame] | 47 | #include "crypto.h" |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 48 | |
Ying Xue | 796c75d | 2013-06-17 10:54:48 -0400 | [diff] [blame] | 49 | #include <linux/pkt_sched.h> |
| 50 | |
Jon Paul Maloy | 38206d5 | 2015-11-19 14:30:46 -0500 | [diff] [blame] | 51 | struct tipc_stats { |
Jon Paul Maloy | 9590112 | 2016-11-25 10:35:02 -0500 | [diff] [blame] | 52 | u32 sent_pkts; |
| 53 | u32 recv_pkts; |
Jon Paul Maloy | 38206d5 | 2015-11-19 14:30:46 -0500 | [diff] [blame] | 54 | u32 sent_states; |
| 55 | u32 recv_states; |
| 56 | u32 sent_probes; |
| 57 | u32 recv_probes; |
| 58 | u32 sent_nacks; |
| 59 | u32 recv_nacks; |
| 60 | u32 sent_acks; |
| 61 | u32 sent_bundled; |
| 62 | u32 sent_bundles; |
| 63 | u32 recv_bundled; |
| 64 | u32 recv_bundles; |
| 65 | u32 retransmitted; |
| 66 | u32 sent_fragmented; |
| 67 | u32 sent_fragments; |
| 68 | u32 recv_fragmented; |
| 69 | u32 recv_fragments; |
| 70 | u32 link_congs; /* # port sends blocked by congestion */ |
| 71 | u32 deferred_recv; |
| 72 | u32 duplicates; |
| 73 | u32 max_queue_sz; /* send queue size high water mark */ |
| 74 | u32 accu_queue_sz; /* used for send queue size profiling */ |
| 75 | u32 queue_sz_counts; /* used for send queue size profiling */ |
| 76 | u32 msg_length_counts; /* used for message length profiling */ |
| 77 | u32 msg_lengths_total; /* used for message length profiling */ |
| 78 | u32 msg_length_profile[7]; /* used for msg. length profiling */ |
| 79 | }; |
| 80 | |
| 81 | /** |
| 82 | * struct tipc_link - TIPC link data structure |
| 83 | * @addr: network address of link's peer node |
| 84 | * @name: link name character string |
| 85 | * @media_addr: media address to use when sending messages over link |
| 86 | * @timer: link timer |
| 87 | * @net: pointer to namespace struct |
| 88 | * @refcnt: reference counter for permanent references (owner node & timer) |
| 89 | * @peer_session: link session # being used by peer end of link |
| 90 | * @peer_bearer_id: bearer id used by link's peer endpoint |
| 91 | * @bearer_id: local bearer id used by link |
| 92 | * @tolerance: minimum link continuity loss needed to reset link [in ms] |
Jon Paul Maloy | 38206d5 | 2015-11-19 14:30:46 -0500 | [diff] [blame] | 93 | * @abort_limit: # of unacknowledged continuity probes needed to reset link |
| 94 | * @state: current state of link FSM |
| 95 | * @peer_caps: bitmap describing capabilities of peer node |
| 96 | * @silent_intv_cnt: # of timer intervals without any reception from peer |
| 97 | * @proto_msg: template for control messages generated by link |
| 98 | * @pmsg: convenience pointer to "proto_msg" field |
| 99 | * @priority: current link priority |
| 100 | * @net_plane: current link network plane ('A' through 'H') |
Jon Paul Maloy | 35c55c9 | 2016-06-13 20:46:22 -0400 | [diff] [blame] | 101 | * @mon_state: cookie with information needed by link monitor |
Jon Paul Maloy | 38206d5 | 2015-11-19 14:30:46 -0500 | [diff] [blame] | 102 | * @backlog_limit: backlog queue congestion thresholds (indexed by importance) |
| 103 | * @exp_msg_count: # of tunnelled messages expected during link changeover |
| 104 | * @reset_rcv_checkpt: seq # of last acknowledged message at time of link reset |
| 105 | * @mtu: current maximum packet size for this link |
| 106 | * @advertised_mtu: advertised own mtu when link is being established |
| 107 | * @transmitq: queue for sent, non-acked messages |
| 108 | * @backlogq: queue for messages waiting to be sent |
| 109 | * @snt_nxt: next sequence number to use for outbound messages |
Jon Paul Maloy | 38206d5 | 2015-11-19 14:30:46 -0500 | [diff] [blame] | 110 | * @ackers: # of peers that needs to ack each packet before it can be released |
| 111 | * @acked: # last packet acked by a certain peer. Used for broadcast. |
| 112 | * @rcv_nxt: next sequence number to expect for inbound messages |
| 113 | * @deferred_queue: deferred queue saved OOS b'cast message received from node |
| 114 | * @unacked_window: # of inbound messages rx'd without ack'ing back to peer |
| 115 | * @inputq: buffer queue for messages to be delivered upwards |
| 116 | * @namedq: buffer queue for name table messages to be delivered upwards |
| 117 | * @next_out: ptr to first unsent outbound message in queue |
| 118 | * @wakeupq: linked list of wakeup msgs waiting for link congestion to abate |
| 119 | * @long_msg_seq_no: next identifier to use for outbound fragmented messages |
| 120 | * @reasm_buf: head of partially reassembled inbound message fragments |
| 121 | * @bc_rcvr: marks that this is a broadcast receiver link |
| 122 | * @stats: collects statistics regarding link activity |
| 123 | */ |
| 124 | struct tipc_link { |
| 125 | u32 addr; |
| 126 | char name[TIPC_MAX_LINK_NAME]; |
Jon Paul Maloy | 38206d5 | 2015-11-19 14:30:46 -0500 | [diff] [blame] | 127 | struct net *net; |
| 128 | |
| 129 | /* Management and link supervision data */ |
Jon Maloy | 7ea817f | 2018-07-10 01:07:36 +0200 | [diff] [blame] | 130 | u16 peer_session; |
| 131 | u16 session; |
Jon Maloy | 9012de5 | 2018-07-10 01:07:35 +0200 | [diff] [blame] | 132 | u16 snd_nxt_state; |
| 133 | u16 rcv_nxt_state; |
Jon Paul Maloy | 38206d5 | 2015-11-19 14:30:46 -0500 | [diff] [blame] | 134 | u32 peer_bearer_id; |
| 135 | u32 bearer_id; |
| 136 | u32 tolerance; |
Jon Paul Maloy | 38206d5 | 2015-11-19 14:30:46 -0500 | [diff] [blame] | 137 | u32 abort_limit; |
| 138 | u32 state; |
| 139 | u16 peer_caps; |
Jon Maloy | 7ea817f | 2018-07-10 01:07:36 +0200 | [diff] [blame] | 140 | bool in_session; |
Jon Paul Maloy | 38206d5 | 2015-11-19 14:30:46 -0500 | [diff] [blame] | 141 | bool active; |
| 142 | u32 silent_intv_cnt; |
Jon Paul Maloy | e74a386 | 2016-03-03 14:23:21 -0500 | [diff] [blame] | 143 | char if_name[TIPC_MAX_IF_NAME]; |
Jon Paul Maloy | 38206d5 | 2015-11-19 14:30:46 -0500 | [diff] [blame] | 144 | u32 priority; |
| 145 | char net_plane; |
Jon Paul Maloy | 35c55c9 | 2016-06-13 20:46:22 -0400 | [diff] [blame] | 146 | struct tipc_mon_state mon_state; |
Jon Paul Maloy | 88e8ac7 | 2016-04-15 13:33:04 -0400 | [diff] [blame] | 147 | u16 rst_cnt; |
Jon Paul Maloy | 38206d5 | 2015-11-19 14:30:46 -0500 | [diff] [blame] | 148 | |
| 149 | /* Failover/synch */ |
| 150 | u16 drop_point; |
| 151 | struct sk_buff *failover_reasm_skb; |
Tuong Lien | 58ee86b | 2019-04-04 11:09:53 +0700 | [diff] [blame] | 152 | struct sk_buff_head failover_deferdq; |
Jon Paul Maloy | 38206d5 | 2015-11-19 14:30:46 -0500 | [diff] [blame] | 153 | |
| 154 | /* Max packet negotiation */ |
| 155 | u16 mtu; |
| 156 | u16 advertised_mtu; |
| 157 | |
| 158 | /* Sending */ |
| 159 | struct sk_buff_head transmq; |
| 160 | struct sk_buff_head backlogq; |
| 161 | struct { |
| 162 | u16 len; |
| 163 | u16 limit; |
Tuong Lien | e95584a | 2019-10-02 18:49:43 +0700 | [diff] [blame] | 164 | struct sk_buff *target_bskb; |
Jon Paul Maloy | 38206d5 | 2015-11-19 14:30:46 -0500 | [diff] [blame] | 165 | } backlog[5]; |
| 166 | u16 snd_nxt; |
Jon Paul Maloy | 38206d5 | 2015-11-19 14:30:46 -0500 | [diff] [blame] | 167 | u16 window; |
Jon Paul Maloy | 38206d5 | 2015-11-19 14:30:46 -0500 | [diff] [blame] | 168 | |
| 169 | /* Reception */ |
| 170 | u16 rcv_nxt; |
| 171 | u32 rcv_unacked; |
| 172 | struct sk_buff_head deferdq; |
| 173 | struct sk_buff_head *inputq; |
| 174 | struct sk_buff_head *namedq; |
| 175 | |
| 176 | /* Congestion handling */ |
| 177 | struct sk_buff_head wakeupq; |
| 178 | |
| 179 | /* Fragmentation/reassembly */ |
| 180 | struct sk_buff *reasm_buf; |
Tuong Lien | 2320bcd | 2019-07-24 08:56:12 +0700 | [diff] [blame] | 181 | struct sk_buff *reasm_tnlmsg; |
Jon Paul Maloy | 38206d5 | 2015-11-19 14:30:46 -0500 | [diff] [blame] | 182 | |
| 183 | /* Broadcast */ |
| 184 | u16 ackers; |
| 185 | u16 acked; |
| 186 | struct tipc_link *bc_rcvlink; |
| 187 | struct tipc_link *bc_sndlink; |
Jon Paul Maloy | 7c4a54b | 2016-09-01 13:52:50 -0400 | [diff] [blame] | 188 | u8 nack_state; |
Jon Paul Maloy | 38206d5 | 2015-11-19 14:30:46 -0500 | [diff] [blame] | 189 | bool bc_peer_is_up; |
| 190 | |
| 191 | /* Statistics */ |
| 192 | struct tipc_stats stats; |
| 193 | }; |
| 194 | |
Erik Hugne | 2cf8aa1 | 2012-06-29 00:16:37 -0400 | [diff] [blame] | 195 | /* |
| 196 | * Error message prefixes |
| 197 | */ |
Jon Paul Maloy | 6e49815 | 2015-07-30 18:24:19 -0400 | [diff] [blame] | 198 | static const char *link_co_err = "Link tunneling error, "; |
Erik Hugne | 2cf8aa1 | 2012-06-29 00:16:37 -0400 | [diff] [blame] | 199 | static const char *link_rst_msg = "Resetting link "; |
Richard Alpe | 7be57fc | 2014-11-20 10:29:12 +0100 | [diff] [blame] | 200 | |
Jon Paul Maloy | 5266698 | 2015-10-22 08:51:41 -0400 | [diff] [blame] | 201 | /* Send states for broadcast NACKs |
| 202 | */ |
| 203 | enum { |
| 204 | BC_NACK_SND_CONDITIONAL, |
| 205 | BC_NACK_SND_UNCONDITIONAL, |
| 206 | BC_NACK_SND_SUPPRESS, |
| 207 | }; |
| 208 | |
Jon Maloy | 53962bc | 2019-06-28 17:06:20 +0200 | [diff] [blame] | 209 | #define TIPC_BC_RETR_LIM (jiffies + msecs_to_jiffies(10)) |
Tuong Lien | 382f598 | 2019-04-04 11:09:52 +0700 | [diff] [blame] | 210 | #define TIPC_UC_RETR_TIME (jiffies + msecs_to_jiffies(1)) |
Jon Paul Maloy | 7c4a54b | 2016-09-01 13:52:50 -0400 | [diff] [blame] | 211 | |
YOSHIFUJI Hideaki | c430728 | 2007-02-09 23:25:21 +0900 | [diff] [blame] | 212 | /* |
Jon Paul Maloy | d999297 | 2015-07-16 16:54:31 -0400 | [diff] [blame] | 213 | * Interval between NACKs when packets arrive out of order |
| 214 | */ |
| 215 | #define TIPC_NACK_INTV (TIPC_MIN_LINK_WIN * 2) |
Jon Paul Maloy | e74a386 | 2016-03-03 14:23:21 -0500 | [diff] [blame] | 216 | |
Jon Paul Maloy | 662921c | 2015-07-30 18:24:21 -0400 | [diff] [blame] | 217 | /* Link FSM states: |
Jon Paul Maloy | d3504c3 | 2015-07-16 16:54:25 -0400 | [diff] [blame] | 218 | */ |
| 219 | enum { |
Jon Paul Maloy | 662921c | 2015-07-30 18:24:21 -0400 | [diff] [blame] | 220 | LINK_ESTABLISHED = 0xe, |
| 221 | LINK_ESTABLISHING = 0xe << 4, |
| 222 | LINK_RESET = 0x1 << 8, |
| 223 | LINK_RESETTING = 0x2 << 12, |
| 224 | LINK_PEER_RESET = 0xd << 16, |
| 225 | LINK_FAILINGOVER = 0xf << 20, |
| 226 | LINK_SYNCHING = 0xc << 24 |
Jon Paul Maloy | d3504c3 | 2015-07-16 16:54:25 -0400 | [diff] [blame] | 227 | }; |
| 228 | |
| 229 | /* Link FSM state checking routines |
| 230 | */ |
Jon Paul Maloy | 662921c | 2015-07-30 18:24:21 -0400 | [diff] [blame] | 231 | static int link_is_up(struct tipc_link *l) |
Jon Paul Maloy | d3504c3 | 2015-07-16 16:54:25 -0400 | [diff] [blame] | 232 | { |
Jon Paul Maloy | 662921c | 2015-07-30 18:24:21 -0400 | [diff] [blame] | 233 | return l->state & (LINK_ESTABLISHED | LINK_SYNCHING); |
Jon Paul Maloy | d3504c3 | 2015-07-16 16:54:25 -0400 | [diff] [blame] | 234 | } |
| 235 | |
Jon Paul Maloy | d999297 | 2015-07-16 16:54:31 -0400 | [diff] [blame] | 236 | static int tipc_link_proto_rcv(struct tipc_link *l, struct sk_buff *skb, |
| 237 | struct sk_buff_head *xmitq); |
Jon Paul Maloy | 426cc2b | 2015-07-16 16:54:26 -0400 | [diff] [blame] | 238 | static void tipc_link_build_proto_msg(struct tipc_link *l, int mtyp, bool probe, |
Jon Maloy | 8d6e79d | 2017-11-08 09:59:26 +0100 | [diff] [blame] | 239 | bool probe_reply, u16 rcvgap, |
| 240 | int tolerance, int priority, |
Jon Paul Maloy | 426cc2b | 2015-07-16 16:54:26 -0400 | [diff] [blame] | 241 | struct sk_buff_head *xmitq); |
Jon Paul Maloy | 1a90632 | 2015-11-19 14:30:47 -0500 | [diff] [blame] | 242 | static void link_print(struct tipc_link *l, const char *str); |
Jon Paul Maloy | e0a05eb | 2016-09-01 13:52:51 -0400 | [diff] [blame] | 243 | static int tipc_link_build_nack_msg(struct tipc_link *l, |
| 244 | struct sk_buff_head *xmitq); |
Jon Paul Maloy | 5266698 | 2015-10-22 08:51:41 -0400 | [diff] [blame] | 245 | static void tipc_link_build_bc_init_msg(struct tipc_link *l, |
| 246 | struct sk_buff_head *xmitq); |
| 247 | static bool tipc_link_release_pkts(struct tipc_link *l, u16 to); |
Tuong Lien | 9195948 | 2019-04-04 11:09:51 +0700 | [diff] [blame] | 248 | static u16 tipc_build_gap_ack_blks(struct tipc_link *l, void *data); |
Tuong Lien | 6a6b5c8 | 2019-06-17 12:15:42 +0700 | [diff] [blame] | 249 | static int tipc_link_advance_transmq(struct tipc_link *l, u16 acked, u16 gap, |
| 250 | struct tipc_gap_ack_blks *ga, |
| 251 | struct sk_buff_head *xmitq); |
Jon Paul Maloy | 8b4ed86 | 2015-03-25 12:07:26 -0400 | [diff] [blame] | 252 | |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 253 | /* |
Sam Ravnborg | 05790c6 | 2006-03-20 22:37:04 -0800 | [diff] [blame] | 254 | * Simple non-static link routines (i.e. referenced outside this file) |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 255 | */ |
Jon Paul Maloy | 662921c | 2015-07-30 18:24:21 -0400 | [diff] [blame] | 256 | bool tipc_link_is_up(struct tipc_link *l) |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 257 | { |
Jon Paul Maloy | 662921c | 2015-07-30 18:24:21 -0400 | [diff] [blame] | 258 | return link_is_up(l); |
| 259 | } |
| 260 | |
Jon Paul Maloy | c819930 | 2015-10-15 14:52:46 -0400 | [diff] [blame] | 261 | bool tipc_link_peer_is_down(struct tipc_link *l) |
| 262 | { |
| 263 | return l->state == LINK_PEER_RESET; |
| 264 | } |
| 265 | |
Jon Paul Maloy | 662921c | 2015-07-30 18:24:21 -0400 | [diff] [blame] | 266 | bool tipc_link_is_reset(struct tipc_link *l) |
| 267 | { |
| 268 | return l->state & (LINK_RESET | LINK_FAILINGOVER | LINK_ESTABLISHING); |
| 269 | } |
| 270 | |
Jon Paul Maloy | 73f646c | 2015-10-15 14:52:44 -0400 | [diff] [blame] | 271 | bool tipc_link_is_establishing(struct tipc_link *l) |
| 272 | { |
| 273 | return l->state == LINK_ESTABLISHING; |
| 274 | } |
| 275 | |
Jon Paul Maloy | 662921c | 2015-07-30 18:24:21 -0400 | [diff] [blame] | 276 | bool tipc_link_is_synching(struct tipc_link *l) |
| 277 | { |
| 278 | return l->state == LINK_SYNCHING; |
| 279 | } |
| 280 | |
| 281 | bool tipc_link_is_failingover(struct tipc_link *l) |
| 282 | { |
| 283 | return l->state == LINK_FAILINGOVER; |
| 284 | } |
| 285 | |
| 286 | bool tipc_link_is_blocked(struct tipc_link *l) |
| 287 | { |
| 288 | return l->state & (LINK_RESETTING | LINK_PEER_RESET | LINK_FAILINGOVER); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 289 | } |
| 290 | |
Wu Fengguang | 742e038 | 2015-10-24 22:56:01 +0800 | [diff] [blame] | 291 | static bool link_is_bc_sndlink(struct tipc_link *l) |
Jon Paul Maloy | 5266698 | 2015-10-22 08:51:41 -0400 | [diff] [blame] | 292 | { |
| 293 | return !l->bc_sndlink; |
| 294 | } |
| 295 | |
Wu Fengguang | 742e038 | 2015-10-24 22:56:01 +0800 | [diff] [blame] | 296 | static bool link_is_bc_rcvlink(struct tipc_link *l) |
Jon Paul Maloy | 5266698 | 2015-10-22 08:51:41 -0400 | [diff] [blame] | 297 | { |
| 298 | return ((l->bc_rcvlink == l) && !link_is_bc_sndlink(l)); |
| 299 | } |
| 300 | |
Jon Paul Maloy | c72fa87 | 2015-10-22 08:51:46 -0400 | [diff] [blame] | 301 | void tipc_link_set_active(struct tipc_link *l, bool active) |
| 302 | { |
| 303 | l->active = active; |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 304 | } |
| 305 | |
Jon Paul Maloy | 38206d5 | 2015-11-19 14:30:46 -0500 | [diff] [blame] | 306 | u32 tipc_link_id(struct tipc_link *l) |
| 307 | { |
| 308 | return l->peer_bearer_id << 16 | l->bearer_id; |
| 309 | } |
| 310 | |
| 311 | int tipc_link_window(struct tipc_link *l) |
| 312 | { |
| 313 | return l->window; |
| 314 | } |
| 315 | |
| 316 | int tipc_link_prio(struct tipc_link *l) |
| 317 | { |
| 318 | return l->priority; |
| 319 | } |
| 320 | |
| 321 | unsigned long tipc_link_tolerance(struct tipc_link *l) |
| 322 | { |
| 323 | return l->tolerance; |
| 324 | } |
| 325 | |
| 326 | struct sk_buff_head *tipc_link_inputq(struct tipc_link *l) |
| 327 | { |
| 328 | return l->inputq; |
| 329 | } |
| 330 | |
| 331 | char tipc_link_plane(struct tipc_link *l) |
| 332 | { |
| 333 | return l->net_plane; |
| 334 | } |
| 335 | |
Jon Maloy | 9012de5 | 2018-07-10 01:07:35 +0200 | [diff] [blame] | 336 | void tipc_link_update_caps(struct tipc_link *l, u16 capabilities) |
| 337 | { |
| 338 | l->peer_caps = capabilities; |
| 339 | } |
| 340 | |
Jon Paul Maloy | 5266698 | 2015-10-22 08:51:41 -0400 | [diff] [blame] | 341 | void tipc_link_add_bc_peer(struct tipc_link *snd_l, |
| 342 | struct tipc_link *uc_l, |
| 343 | struct sk_buff_head *xmitq) |
Jon Paul Maloy | 2f56612 | 2015-10-22 08:51:39 -0400 | [diff] [blame] | 344 | { |
Jon Paul Maloy | 5266698 | 2015-10-22 08:51:41 -0400 | [diff] [blame] | 345 | struct tipc_link *rcv_l = uc_l->bc_rcvlink; |
| 346 | |
| 347 | snd_l->ackers++; |
| 348 | rcv_l->acked = snd_l->snd_nxt - 1; |
Jon Paul Maloy | 9a65083 | 2015-11-19 14:12:50 -0500 | [diff] [blame] | 349 | snd_l->state = LINK_ESTABLISHED; |
Jon Paul Maloy | 5266698 | 2015-10-22 08:51:41 -0400 | [diff] [blame] | 350 | tipc_link_build_bc_init_msg(uc_l, xmitq); |
Jon Paul Maloy | 2f56612 | 2015-10-22 08:51:39 -0400 | [diff] [blame] | 351 | } |
| 352 | |
Jon Paul Maloy | 5266698 | 2015-10-22 08:51:41 -0400 | [diff] [blame] | 353 | void tipc_link_remove_bc_peer(struct tipc_link *snd_l, |
| 354 | struct tipc_link *rcv_l, |
| 355 | struct sk_buff_head *xmitq) |
Jon Paul Maloy | 2f56612 | 2015-10-22 08:51:39 -0400 | [diff] [blame] | 356 | { |
Jon Paul Maloy | 5266698 | 2015-10-22 08:51:41 -0400 | [diff] [blame] | 357 | u16 ack = snd_l->snd_nxt - 1; |
| 358 | |
| 359 | snd_l->ackers--; |
Jon Paul Maloy | a71eb72 | 2016-07-11 16:08:36 -0400 | [diff] [blame] | 360 | rcv_l->bc_peer_is_up = true; |
| 361 | rcv_l->state = LINK_ESTABLISHED; |
Jon Paul Maloy | 5266698 | 2015-10-22 08:51:41 -0400 | [diff] [blame] | 362 | tipc_link_bc_ack_rcv(rcv_l, ack, xmitq); |
Tuong Lien | 26574db | 2018-12-19 09:17:57 +0700 | [diff] [blame] | 363 | trace_tipc_link_reset(rcv_l, TIPC_DUMP_ALL, "bclink removed!"); |
Jon Paul Maloy | 5266698 | 2015-10-22 08:51:41 -0400 | [diff] [blame] | 364 | tipc_link_reset(rcv_l); |
| 365 | rcv_l->state = LINK_RESET; |
| 366 | if (!snd_l->ackers) { |
Tuong Lien | 26574db | 2018-12-19 09:17:57 +0700 | [diff] [blame] | 367 | trace_tipc_link_reset(snd_l, TIPC_DUMP_ALL, "zero ackers!"); |
Jon Paul Maloy | 5266698 | 2015-10-22 08:51:41 -0400 | [diff] [blame] | 368 | tipc_link_reset(snd_l); |
Jon Paul Maloy | 9a65083 | 2015-11-19 14:12:50 -0500 | [diff] [blame] | 369 | snd_l->state = LINK_RESET; |
Jon Paul Maloy | 5266698 | 2015-10-22 08:51:41 -0400 | [diff] [blame] | 370 | __skb_queue_purge(xmitq); |
| 371 | } |
Jon Paul Maloy | 2f56612 | 2015-10-22 08:51:39 -0400 | [diff] [blame] | 372 | } |
| 373 | |
| 374 | int tipc_link_bc_peers(struct tipc_link *l) |
| 375 | { |
| 376 | return l->ackers; |
| 377 | } |
| 378 | |
YueHaibing | e064cce | 2018-07-19 17:16:59 +0800 | [diff] [blame] | 379 | static u16 link_bc_rcv_gap(struct tipc_link *l) |
Jon Paul Maloy | 02d11ca | 2016-09-01 13:52:49 -0400 | [diff] [blame] | 380 | { |
| 381 | struct sk_buff *skb = skb_peek(&l->deferdq); |
| 382 | u16 gap = 0; |
| 383 | |
| 384 | if (more(l->snd_nxt, l->rcv_nxt)) |
| 385 | gap = l->snd_nxt - l->rcv_nxt; |
| 386 | if (skb) |
| 387 | gap = buf_seqno(skb) - l->rcv_nxt; |
| 388 | return gap; |
| 389 | } |
| 390 | |
Jon Paul Maloy | 959e178 | 2015-10-22 08:51:43 -0400 | [diff] [blame] | 391 | void tipc_link_set_mtu(struct tipc_link *l, int mtu) |
| 392 | { |
| 393 | l->mtu = mtu; |
| 394 | } |
| 395 | |
| 396 | int tipc_link_mtu(struct tipc_link *l) |
| 397 | { |
| 398 | return l->mtu; |
| 399 | } |
| 400 | |
Tuong Lien | fc1b6d6 | 2019-11-08 12:05:11 +0700 | [diff] [blame] | 401 | int tipc_link_mss(struct tipc_link *l) |
| 402 | { |
| 403 | #ifdef CONFIG_TIPC_CRYPTO |
| 404 | return l->mtu - INT_H_SIZE - EMSG_OVERHEAD; |
| 405 | #else |
| 406 | return l->mtu - INT_H_SIZE; |
| 407 | #endif |
| 408 | } |
| 409 | |
Jon Paul Maloy | 38206d5 | 2015-11-19 14:30:46 -0500 | [diff] [blame] | 410 | u16 tipc_link_rcv_nxt(struct tipc_link *l) |
| 411 | { |
| 412 | return l->rcv_nxt; |
| 413 | } |
| 414 | |
| 415 | u16 tipc_link_acked(struct tipc_link *l) |
| 416 | { |
| 417 | return l->acked; |
| 418 | } |
| 419 | |
| 420 | char *tipc_link_name(struct tipc_link *l) |
| 421 | { |
| 422 | return l->name; |
| 423 | } |
| 424 | |
LUU Duc Canh | c140eb1 | 2018-09-26 21:00:54 +0200 | [diff] [blame] | 425 | u32 tipc_link_state(struct tipc_link *l) |
| 426 | { |
| 427 | return l->state; |
| 428 | } |
| 429 | |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 430 | /** |
Per Liden | 4323add | 2006-01-18 00:38:21 +0100 | [diff] [blame] | 431 | * tipc_link_create - create a new link |
Jon Paul Maloy | 440d896 | 2015-07-30 18:24:26 -0400 | [diff] [blame] | 432 | * @n: pointer to associated node |
Jon Paul Maloy | 0e05498 | 2015-10-22 08:51:36 -0400 | [diff] [blame] | 433 | * @if_name: associated interface name |
| 434 | * @bearer_id: id (index) of associated bearer |
| 435 | * @tolerance: link tolerance to be used by link |
| 436 | * @net_plane: network plane (A,B,c..) this link belongs to |
| 437 | * @mtu: mtu to be advertised by link |
| 438 | * @priority: priority to be used by link |
| 439 | * @window: send window to be used by link |
| 440 | * @session: session to be used by link |
Jon Paul Maloy | 440d896 | 2015-07-30 18:24:26 -0400 | [diff] [blame] | 441 | * @ownnode: identity of own node |
Jon Paul Maloy | 0e05498 | 2015-10-22 08:51:36 -0400 | [diff] [blame] | 442 | * @peer: node id of peer node |
Jon Paul Maloy | fd556f2 | 2015-10-22 08:51:40 -0400 | [diff] [blame] | 443 | * @peer_caps: bitmap describing peer node capabilities |
Jon Paul Maloy | 5266698 | 2015-10-22 08:51:41 -0400 | [diff] [blame] | 444 | * @bc_sndlink: the namespace global link used for broadcast sending |
| 445 | * @bc_rcvlink: the peer specific link used for broadcast reception |
Jon Paul Maloy | 440d896 | 2015-07-30 18:24:26 -0400 | [diff] [blame] | 446 | * @inputq: queue to put messages ready for delivery |
| 447 | * @namedq: queue to put binding table update messages ready for delivery |
| 448 | * @link: return value, pointer to put the created link |
YOSHIFUJI Hideaki | c430728 | 2007-02-09 23:25:21 +0900 | [diff] [blame] | 449 | * |
Jon Paul Maloy | 440d896 | 2015-07-30 18:24:26 -0400 | [diff] [blame] | 450 | * Returns true if link was created, otherwise false |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 451 | */ |
Jon Paul Maloy | c72fa87 | 2015-10-22 08:51:46 -0400 | [diff] [blame] | 452 | bool tipc_link_create(struct net *net, char *if_name, int bearer_id, |
Jon Paul Maloy | 0e05498 | 2015-10-22 08:51:36 -0400 | [diff] [blame] | 453 | int tolerance, char net_plane, u32 mtu, int priority, |
Jon Maloy | 25b0b9c | 2018-03-22 20:42:51 +0100 | [diff] [blame] | 454 | int window, u32 session, u32 self, |
| 455 | u32 peer, u8 *peer_id, u16 peer_caps, |
Jon Paul Maloy | 5266698 | 2015-10-22 08:51:41 -0400 | [diff] [blame] | 456 | struct tipc_link *bc_sndlink, |
| 457 | struct tipc_link *bc_rcvlink, |
| 458 | struct sk_buff_head *inputq, |
| 459 | struct sk_buff_head *namedq, |
Jon Paul Maloy | 440d896 | 2015-07-30 18:24:26 -0400 | [diff] [blame] | 460 | struct tipc_link **link) |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 461 | { |
Jon Maloy | 25b0b9c | 2018-03-22 20:42:51 +0100 | [diff] [blame] | 462 | char peer_str[NODE_ID_STR_LEN] = {0,}; |
| 463 | char self_str[NODE_ID_STR_LEN] = {0,}; |
Jon Paul Maloy | 440d896 | 2015-07-30 18:24:26 -0400 | [diff] [blame] | 464 | struct tipc_link *l; |
Allan Stephens | 37b9c08 | 2011-02-28 11:32:27 -0500 | [diff] [blame] | 465 | |
Jon Paul Maloy | 440d896 | 2015-07-30 18:24:26 -0400 | [diff] [blame] | 466 | l = kzalloc(sizeof(*l), GFP_ATOMIC); |
| 467 | if (!l) |
| 468 | return false; |
| 469 | *link = l; |
Jon Paul Maloy | e74a386 | 2016-03-03 14:23:21 -0500 | [diff] [blame] | 470 | l->session = session; |
Jon Paul Maloy | 0e05498 | 2015-10-22 08:51:36 -0400 | [diff] [blame] | 471 | |
Jon Maloy | 25b0b9c | 2018-03-22 20:42:51 +0100 | [diff] [blame] | 472 | /* Set link name for unicast links only */ |
| 473 | if (peer_id) { |
| 474 | tipc_nodeid2string(self_str, tipc_own_id(net)); |
| 475 | if (strlen(self_str) > 16) |
| 476 | sprintf(self_str, "%x", self); |
| 477 | tipc_nodeid2string(peer_str, peer_id); |
| 478 | if (strlen(peer_str) > 16) |
| 479 | sprintf(peer_str, "%x", peer); |
| 480 | } |
| 481 | /* Peer i/f name will be completed by reset/activate message */ |
Jon Maloy | 7494cfa | 2018-03-29 23:20:45 +0200 | [diff] [blame] | 482 | snprintf(l->name, sizeof(l->name), "%s:%s-%s:unknown", |
| 483 | self_str, if_name, peer_str); |
Jon Maloy | 25b0b9c | 2018-03-22 20:42:51 +0100 | [diff] [blame] | 484 | |
Jon Paul Maloy | e74a386 | 2016-03-03 14:23:21 -0500 | [diff] [blame] | 485 | strcpy(l->if_name, if_name); |
Jon Paul Maloy | 0e05498 | 2015-10-22 08:51:36 -0400 | [diff] [blame] | 486 | l->addr = peer; |
Jon Paul Maloy | fd556f2 | 2015-10-22 08:51:40 -0400 | [diff] [blame] | 487 | l->peer_caps = peer_caps; |
Jon Paul Maloy | c72fa87 | 2015-10-22 08:51:46 -0400 | [diff] [blame] | 488 | l->net = net; |
Jon Maloy | 7ea817f | 2018-07-10 01:07:36 +0200 | [diff] [blame] | 489 | l->in_session = false; |
Jon Paul Maloy | 0e05498 | 2015-10-22 08:51:36 -0400 | [diff] [blame] | 490 | l->bearer_id = bearer_id; |
| 491 | l->tolerance = tolerance; |
Jon Maloy | 047491e | 2018-10-10 17:34:01 +0200 | [diff] [blame] | 492 | if (bc_rcvlink) |
| 493 | bc_rcvlink->tolerance = tolerance; |
Jon Paul Maloy | 0e05498 | 2015-10-22 08:51:36 -0400 | [diff] [blame] | 494 | l->net_plane = net_plane; |
| 495 | l->advertised_mtu = mtu; |
| 496 | l->mtu = mtu; |
| 497 | l->priority = priority; |
| 498 | tipc_link_set_queue_limits(l, window); |
Jon Paul Maloy | c1ab3f1d | 2015-10-22 08:51:38 -0400 | [diff] [blame] | 499 | l->ackers = 1; |
Jon Paul Maloy | 5266698 | 2015-10-22 08:51:41 -0400 | [diff] [blame] | 500 | l->bc_sndlink = bc_sndlink; |
| 501 | l->bc_rcvlink = bc_rcvlink; |
Jon Paul Maloy | 0e05498 | 2015-10-22 08:51:36 -0400 | [diff] [blame] | 502 | l->inputq = inputq; |
| 503 | l->namedq = namedq; |
| 504 | l->state = LINK_RESETTING; |
Jon Paul Maloy | 440d896 | 2015-07-30 18:24:26 -0400 | [diff] [blame] | 505 | __skb_queue_head_init(&l->transmq); |
| 506 | __skb_queue_head_init(&l->backlogq); |
| 507 | __skb_queue_head_init(&l->deferdq); |
Tuong Lien | 58ee86b | 2019-04-04 11:09:53 +0700 | [diff] [blame] | 508 | __skb_queue_head_init(&l->failover_deferdq); |
Jon Paul Maloy | 440d896 | 2015-07-30 18:24:26 -0400 | [diff] [blame] | 509 | skb_queue_head_init(&l->wakeupq); |
| 510 | skb_queue_head_init(l->inputq); |
| 511 | return true; |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 512 | } |
| 513 | |
Jon Paul Maloy | 3230190 | 2015-10-22 08:51:37 -0400 | [diff] [blame] | 514 | /** |
| 515 | * tipc_link_bc_create - create new link to be used for broadcast |
| 516 | * @n: pointer to associated node |
Jon Maloy | 4c94cc2 | 2017-11-30 16:47:25 +0100 | [diff] [blame] | 517 | * @mtu: mtu to be used initially if no peers |
Jon Paul Maloy | 3230190 | 2015-10-22 08:51:37 -0400 | [diff] [blame] | 518 | * @window: send window to be used |
| 519 | * @inputq: queue to put messages ready for delivery |
| 520 | * @namedq: queue to put binding table update messages ready for delivery |
| 521 | * @link: return value, pointer to put the created link |
| 522 | * |
| 523 | * Returns true if link was created, otherwise false |
| 524 | */ |
Jon Paul Maloy | c72fa87 | 2015-10-22 08:51:46 -0400 | [diff] [blame] | 525 | bool tipc_link_bc_create(struct net *net, u32 ownnode, u32 peer, |
Jon Paul Maloy | 5266698 | 2015-10-22 08:51:41 -0400 | [diff] [blame] | 526 | int mtu, int window, u16 peer_caps, |
Jon Paul Maloy | 3230190 | 2015-10-22 08:51:37 -0400 | [diff] [blame] | 527 | struct sk_buff_head *inputq, |
| 528 | struct sk_buff_head *namedq, |
Jon Paul Maloy | 5266698 | 2015-10-22 08:51:41 -0400 | [diff] [blame] | 529 | struct tipc_link *bc_sndlink, |
Jon Paul Maloy | 3230190 | 2015-10-22 08:51:37 -0400 | [diff] [blame] | 530 | struct tipc_link **link) |
| 531 | { |
| 532 | struct tipc_link *l; |
| 533 | |
Jon Paul Maloy | c72fa87 | 2015-10-22 08:51:46 -0400 | [diff] [blame] | 534 | if (!tipc_link_create(net, "", MAX_BEARERS, 0, 'Z', mtu, 0, window, |
Jon Maloy | 25b0b9c | 2018-03-22 20:42:51 +0100 | [diff] [blame] | 535 | 0, ownnode, peer, NULL, peer_caps, bc_sndlink, |
Jon Paul Maloy | 5266698 | 2015-10-22 08:51:41 -0400 | [diff] [blame] | 536 | NULL, inputq, namedq, link)) |
Jon Paul Maloy | 3230190 | 2015-10-22 08:51:37 -0400 | [diff] [blame] | 537 | return false; |
| 538 | |
| 539 | l = *link; |
| 540 | strcpy(l->name, tipc_bclink_name); |
Tuong Lien | 26574db | 2018-12-19 09:17:57 +0700 | [diff] [blame] | 541 | trace_tipc_link_reset(l, TIPC_DUMP_ALL, "bclink created!"); |
Jon Paul Maloy | 3230190 | 2015-10-22 08:51:37 -0400 | [diff] [blame] | 542 | tipc_link_reset(l); |
Jon Paul Maloy | 5266698 | 2015-10-22 08:51:41 -0400 | [diff] [blame] | 543 | l->state = LINK_RESET; |
Jon Paul Maloy | 2f56612 | 2015-10-22 08:51:39 -0400 | [diff] [blame] | 544 | l->ackers = 0; |
Jon Paul Maloy | 5266698 | 2015-10-22 08:51:41 -0400 | [diff] [blame] | 545 | l->bc_rcvlink = l; |
| 546 | |
| 547 | /* Broadcast send link is always up */ |
| 548 | if (link_is_bc_sndlink(l)) |
| 549 | l->state = LINK_ESTABLISHED; |
| 550 | |
Jon Paul Maloy | 01fd12b | 2017-01-18 13:50:53 -0500 | [diff] [blame] | 551 | /* Disable replicast if even a single peer doesn't support it */ |
| 552 | if (link_is_bc_rcvlink(l) && !(peer_caps & TIPC_BCAST_RCAST)) |
Hoang Le | ba5f6a8 | 2019-11-21 10:01:09 +0700 | [diff] [blame] | 553 | tipc_bcast_toggle_rcast(net, false); |
Jon Paul Maloy | 01fd12b | 2017-01-18 13:50:53 -0500 | [diff] [blame] | 554 | |
Jon Paul Maloy | 3230190 | 2015-10-22 08:51:37 -0400 | [diff] [blame] | 555 | return true; |
| 556 | } |
| 557 | |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 558 | /** |
Jon Paul Maloy | 6ab30f9 | 2015-07-16 16:54:27 -0400 | [diff] [blame] | 559 | * tipc_link_fsm_evt - link finite state machine |
| 560 | * @l: pointer to link |
| 561 | * @evt: state machine event to be processed |
Jon Paul Maloy | 6ab30f9 | 2015-07-16 16:54:27 -0400 | [diff] [blame] | 562 | */ |
Jon Paul Maloy | 662921c | 2015-07-30 18:24:21 -0400 | [diff] [blame] | 563 | int tipc_link_fsm_evt(struct tipc_link *l, int evt) |
Jon Paul Maloy | 6ab30f9 | 2015-07-16 16:54:27 -0400 | [diff] [blame] | 564 | { |
Jon Paul Maloy | 5045f7b | 2015-07-30 18:24:20 -0400 | [diff] [blame] | 565 | int rc = 0; |
Tuong Lien | 26574db | 2018-12-19 09:17:57 +0700 | [diff] [blame] | 566 | int old_state = l->state; |
Jon Paul Maloy | 6ab30f9 | 2015-07-16 16:54:27 -0400 | [diff] [blame] | 567 | |
| 568 | switch (l->state) { |
Jon Paul Maloy | 662921c | 2015-07-30 18:24:21 -0400 | [diff] [blame] | 569 | case LINK_RESETTING: |
Jon Paul Maloy | 6ab30f9 | 2015-07-16 16:54:27 -0400 | [diff] [blame] | 570 | switch (evt) { |
Jon Paul Maloy | 662921c | 2015-07-30 18:24:21 -0400 | [diff] [blame] | 571 | case LINK_PEER_RESET_EVT: |
| 572 | l->state = LINK_PEER_RESET; |
Jon Paul Maloy | 6ab30f9 | 2015-07-16 16:54:27 -0400 | [diff] [blame] | 573 | break; |
Jon Paul Maloy | 662921c | 2015-07-30 18:24:21 -0400 | [diff] [blame] | 574 | case LINK_RESET_EVT: |
| 575 | l->state = LINK_RESET; |
Jon Paul Maloy | 6ab30f9 | 2015-07-16 16:54:27 -0400 | [diff] [blame] | 576 | break; |
Jon Paul Maloy | 662921c | 2015-07-30 18:24:21 -0400 | [diff] [blame] | 577 | case LINK_FAILURE_EVT: |
| 578 | case LINK_FAILOVER_BEGIN_EVT: |
| 579 | case LINK_ESTABLISH_EVT: |
| 580 | case LINK_FAILOVER_END_EVT: |
| 581 | case LINK_SYNCH_BEGIN_EVT: |
| 582 | case LINK_SYNCH_END_EVT: |
Jon Paul Maloy | 6ab30f9 | 2015-07-16 16:54:27 -0400 | [diff] [blame] | 583 | default: |
Jon Paul Maloy | 662921c | 2015-07-30 18:24:21 -0400 | [diff] [blame] | 584 | goto illegal_evt; |
Jon Paul Maloy | 6ab30f9 | 2015-07-16 16:54:27 -0400 | [diff] [blame] | 585 | } |
| 586 | break; |
Jon Paul Maloy | 662921c | 2015-07-30 18:24:21 -0400 | [diff] [blame] | 587 | case LINK_RESET: |
Jon Paul Maloy | 6ab30f9 | 2015-07-16 16:54:27 -0400 | [diff] [blame] | 588 | switch (evt) { |
Jon Paul Maloy | 662921c | 2015-07-30 18:24:21 -0400 | [diff] [blame] | 589 | case LINK_PEER_RESET_EVT: |
| 590 | l->state = LINK_ESTABLISHING; |
Jon Paul Maloy | 6ab30f9 | 2015-07-16 16:54:27 -0400 | [diff] [blame] | 591 | break; |
Jon Paul Maloy | 662921c | 2015-07-30 18:24:21 -0400 | [diff] [blame] | 592 | case LINK_FAILOVER_BEGIN_EVT: |
| 593 | l->state = LINK_FAILINGOVER; |
| 594 | case LINK_FAILURE_EVT: |
| 595 | case LINK_RESET_EVT: |
| 596 | case LINK_ESTABLISH_EVT: |
| 597 | case LINK_FAILOVER_END_EVT: |
Jon Paul Maloy | 6ab30f9 | 2015-07-16 16:54:27 -0400 | [diff] [blame] | 598 | break; |
Jon Paul Maloy | 662921c | 2015-07-30 18:24:21 -0400 | [diff] [blame] | 599 | case LINK_SYNCH_BEGIN_EVT: |
| 600 | case LINK_SYNCH_END_EVT: |
Jon Paul Maloy | 6ab30f9 | 2015-07-16 16:54:27 -0400 | [diff] [blame] | 601 | default: |
Jon Paul Maloy | 662921c | 2015-07-30 18:24:21 -0400 | [diff] [blame] | 602 | goto illegal_evt; |
Jon Paul Maloy | 6ab30f9 | 2015-07-16 16:54:27 -0400 | [diff] [blame] | 603 | } |
| 604 | break; |
Jon Paul Maloy | 662921c | 2015-07-30 18:24:21 -0400 | [diff] [blame] | 605 | case LINK_PEER_RESET: |
Jon Paul Maloy | 6ab30f9 | 2015-07-16 16:54:27 -0400 | [diff] [blame] | 606 | switch (evt) { |
Jon Paul Maloy | 662921c | 2015-07-30 18:24:21 -0400 | [diff] [blame] | 607 | case LINK_RESET_EVT: |
| 608 | l->state = LINK_ESTABLISHING; |
Jon Paul Maloy | 6ab30f9 | 2015-07-16 16:54:27 -0400 | [diff] [blame] | 609 | break; |
Jon Paul Maloy | 662921c | 2015-07-30 18:24:21 -0400 | [diff] [blame] | 610 | case LINK_PEER_RESET_EVT: |
| 611 | case LINK_ESTABLISH_EVT: |
| 612 | case LINK_FAILURE_EVT: |
Jon Paul Maloy | 6ab30f9 | 2015-07-16 16:54:27 -0400 | [diff] [blame] | 613 | break; |
Jon Paul Maloy | 662921c | 2015-07-30 18:24:21 -0400 | [diff] [blame] | 614 | case LINK_SYNCH_BEGIN_EVT: |
| 615 | case LINK_SYNCH_END_EVT: |
| 616 | case LINK_FAILOVER_BEGIN_EVT: |
| 617 | case LINK_FAILOVER_END_EVT: |
Jon Paul Maloy | 6ab30f9 | 2015-07-16 16:54:27 -0400 | [diff] [blame] | 618 | default: |
Jon Paul Maloy | 662921c | 2015-07-30 18:24:21 -0400 | [diff] [blame] | 619 | goto illegal_evt; |
Jon Paul Maloy | 6ab30f9 | 2015-07-16 16:54:27 -0400 | [diff] [blame] | 620 | } |
| 621 | break; |
Jon Paul Maloy | 662921c | 2015-07-30 18:24:21 -0400 | [diff] [blame] | 622 | case LINK_FAILINGOVER: |
Jon Paul Maloy | 6ab30f9 | 2015-07-16 16:54:27 -0400 | [diff] [blame] | 623 | switch (evt) { |
Jon Paul Maloy | 662921c | 2015-07-30 18:24:21 -0400 | [diff] [blame] | 624 | case LINK_FAILOVER_END_EVT: |
| 625 | l->state = LINK_RESET; |
Jon Paul Maloy | 6ab30f9 | 2015-07-16 16:54:27 -0400 | [diff] [blame] | 626 | break; |
Jon Paul Maloy | 662921c | 2015-07-30 18:24:21 -0400 | [diff] [blame] | 627 | case LINK_PEER_RESET_EVT: |
| 628 | case LINK_RESET_EVT: |
| 629 | case LINK_ESTABLISH_EVT: |
| 630 | case LINK_FAILURE_EVT: |
Jon Paul Maloy | 6ab30f9 | 2015-07-16 16:54:27 -0400 | [diff] [blame] | 631 | break; |
Jon Paul Maloy | 662921c | 2015-07-30 18:24:21 -0400 | [diff] [blame] | 632 | case LINK_FAILOVER_BEGIN_EVT: |
| 633 | case LINK_SYNCH_BEGIN_EVT: |
| 634 | case LINK_SYNCH_END_EVT: |
Jon Paul Maloy | 6ab30f9 | 2015-07-16 16:54:27 -0400 | [diff] [blame] | 635 | default: |
Jon Paul Maloy | 662921c | 2015-07-30 18:24:21 -0400 | [diff] [blame] | 636 | goto illegal_evt; |
| 637 | } |
| 638 | break; |
| 639 | case LINK_ESTABLISHING: |
| 640 | switch (evt) { |
| 641 | case LINK_ESTABLISH_EVT: |
| 642 | l->state = LINK_ESTABLISHED; |
Jon Paul Maloy | 662921c | 2015-07-30 18:24:21 -0400 | [diff] [blame] | 643 | break; |
| 644 | case LINK_FAILOVER_BEGIN_EVT: |
| 645 | l->state = LINK_FAILINGOVER; |
| 646 | break; |
Jon Paul Maloy | 662921c | 2015-07-30 18:24:21 -0400 | [diff] [blame] | 647 | case LINK_RESET_EVT: |
Jon Paul Maloy | 73f646c | 2015-10-15 14:52:44 -0400 | [diff] [blame] | 648 | l->state = LINK_RESET; |
| 649 | break; |
Jon Paul Maloy | 662921c | 2015-07-30 18:24:21 -0400 | [diff] [blame] | 650 | case LINK_FAILURE_EVT: |
Jon Paul Maloy | 73f646c | 2015-10-15 14:52:44 -0400 | [diff] [blame] | 651 | case LINK_PEER_RESET_EVT: |
Jon Paul Maloy | 662921c | 2015-07-30 18:24:21 -0400 | [diff] [blame] | 652 | case LINK_SYNCH_BEGIN_EVT: |
| 653 | case LINK_FAILOVER_END_EVT: |
| 654 | break; |
| 655 | case LINK_SYNCH_END_EVT: |
| 656 | default: |
| 657 | goto illegal_evt; |
| 658 | } |
| 659 | break; |
| 660 | case LINK_ESTABLISHED: |
| 661 | switch (evt) { |
| 662 | case LINK_PEER_RESET_EVT: |
| 663 | l->state = LINK_PEER_RESET; |
| 664 | rc |= TIPC_LINK_DOWN_EVT; |
| 665 | break; |
| 666 | case LINK_FAILURE_EVT: |
| 667 | l->state = LINK_RESETTING; |
| 668 | rc |= TIPC_LINK_DOWN_EVT; |
| 669 | break; |
| 670 | case LINK_RESET_EVT: |
| 671 | l->state = LINK_RESET; |
| 672 | break; |
| 673 | case LINK_ESTABLISH_EVT: |
Jon Paul Maloy | 5ae2f8e | 2015-08-20 02:12:55 -0400 | [diff] [blame] | 674 | case LINK_SYNCH_END_EVT: |
Jon Paul Maloy | 662921c | 2015-07-30 18:24:21 -0400 | [diff] [blame] | 675 | break; |
| 676 | case LINK_SYNCH_BEGIN_EVT: |
| 677 | l->state = LINK_SYNCHING; |
| 678 | break; |
Jon Paul Maloy | 662921c | 2015-07-30 18:24:21 -0400 | [diff] [blame] | 679 | case LINK_FAILOVER_BEGIN_EVT: |
| 680 | case LINK_FAILOVER_END_EVT: |
| 681 | default: |
| 682 | goto illegal_evt; |
| 683 | } |
| 684 | break; |
| 685 | case LINK_SYNCHING: |
| 686 | switch (evt) { |
| 687 | case LINK_PEER_RESET_EVT: |
| 688 | l->state = LINK_PEER_RESET; |
| 689 | rc |= TIPC_LINK_DOWN_EVT; |
| 690 | break; |
| 691 | case LINK_FAILURE_EVT: |
| 692 | l->state = LINK_RESETTING; |
| 693 | rc |= TIPC_LINK_DOWN_EVT; |
| 694 | break; |
| 695 | case LINK_RESET_EVT: |
| 696 | l->state = LINK_RESET; |
| 697 | break; |
| 698 | case LINK_ESTABLISH_EVT: |
| 699 | case LINK_SYNCH_BEGIN_EVT: |
| 700 | break; |
| 701 | case LINK_SYNCH_END_EVT: |
| 702 | l->state = LINK_ESTABLISHED; |
| 703 | break; |
| 704 | case LINK_FAILOVER_BEGIN_EVT: |
| 705 | case LINK_FAILOVER_END_EVT: |
| 706 | default: |
| 707 | goto illegal_evt; |
Jon Paul Maloy | 6ab30f9 | 2015-07-16 16:54:27 -0400 | [diff] [blame] | 708 | } |
| 709 | break; |
| 710 | default: |
Jon Paul Maloy | 662921c | 2015-07-30 18:24:21 -0400 | [diff] [blame] | 711 | pr_err("Unknown FSM state %x in %s\n", l->state, l->name); |
Jon Paul Maloy | 6ab30f9 | 2015-07-16 16:54:27 -0400 | [diff] [blame] | 712 | } |
Tuong Lien | 26574db | 2018-12-19 09:17:57 +0700 | [diff] [blame] | 713 | trace_tipc_link_fsm(l->name, old_state, l->state, evt); |
Jon Paul Maloy | 662921c | 2015-07-30 18:24:21 -0400 | [diff] [blame] | 714 | return rc; |
| 715 | illegal_evt: |
| 716 | pr_err("Illegal FSM event %x in state %x on link %s\n", |
| 717 | evt, l->state, l->name); |
Tuong Lien | 26574db | 2018-12-19 09:17:57 +0700 | [diff] [blame] | 718 | trace_tipc_link_fsm(l->name, old_state, l->state, evt); |
Jon Paul Maloy | 6ab30f9 | 2015-07-16 16:54:27 -0400 | [diff] [blame] | 719 | return rc; |
| 720 | } |
| 721 | |
Jon Paul Maloy | 333ef69 | 2015-07-16 16:54:28 -0400 | [diff] [blame] | 722 | /* link_profile_stats - update statistical profiling of traffic |
| 723 | */ |
| 724 | static void link_profile_stats(struct tipc_link *l) |
| 725 | { |
| 726 | struct sk_buff *skb; |
| 727 | struct tipc_msg *msg; |
| 728 | int length; |
| 729 | |
| 730 | /* Update counters used in statistical profiling of send traffic */ |
| 731 | l->stats.accu_queue_sz += skb_queue_len(&l->transmq); |
| 732 | l->stats.queue_sz_counts++; |
| 733 | |
| 734 | skb = skb_peek(&l->transmq); |
| 735 | if (!skb) |
| 736 | return; |
| 737 | msg = buf_msg(skb); |
| 738 | length = msg_size(msg); |
| 739 | |
| 740 | if (msg_user(msg) == MSG_FRAGMENTER) { |
| 741 | if (msg_type(msg) != FIRST_FRAGMENT) |
| 742 | return; |
Jon Maloy | a7dc51a | 2019-06-25 19:37:00 +0200 | [diff] [blame] | 743 | length = msg_size(msg_inner_hdr(msg)); |
Jon Paul Maloy | 333ef69 | 2015-07-16 16:54:28 -0400 | [diff] [blame] | 744 | } |
| 745 | l->stats.msg_lengths_total += length; |
| 746 | l->stats.msg_length_counts++; |
| 747 | if (length <= 64) |
| 748 | l->stats.msg_length_profile[0]++; |
| 749 | else if (length <= 256) |
| 750 | l->stats.msg_length_profile[1]++; |
| 751 | else if (length <= 1024) |
| 752 | l->stats.msg_length_profile[2]++; |
| 753 | else if (length <= 4096) |
| 754 | l->stats.msg_length_profile[3]++; |
| 755 | else if (length <= 16384) |
| 756 | l->stats.msg_length_profile[4]++; |
| 757 | else if (length <= 32768) |
| 758 | l->stats.msg_length_profile[5]++; |
| 759 | else |
| 760 | l->stats.msg_length_profile[6]++; |
| 761 | } |
| 762 | |
Tuong Lien | 26574db | 2018-12-19 09:17:57 +0700 | [diff] [blame] | 763 | /** |
| 764 | * tipc_link_too_silent - check if link is "too silent" |
| 765 | * @l: tipc link to be checked |
| 766 | * |
| 767 | * Returns true if the link 'silent_intv_cnt' is about to reach the |
| 768 | * 'abort_limit' value, otherwise false |
| 769 | */ |
| 770 | bool tipc_link_too_silent(struct tipc_link *l) |
| 771 | { |
| 772 | return (l->silent_intv_cnt + 2 > l->abort_limit); |
| 773 | } |
| 774 | |
Jon Paul Maloy | 333ef69 | 2015-07-16 16:54:28 -0400 | [diff] [blame] | 775 | /* tipc_link_timeout - perform periodic task as instructed from node timeout |
| 776 | */ |
| 777 | int tipc_link_timeout(struct tipc_link *l, struct sk_buff_head *xmitq) |
| 778 | { |
Ying Xue | c91522f | 2016-06-15 14:11:31 +0800 | [diff] [blame] | 779 | int mtyp = 0; |
| 780 | int rc = 0; |
Jon Paul Maloy | 42b18f6 | 2016-04-15 13:33:05 -0400 | [diff] [blame] | 781 | bool state = false; |
| 782 | bool probe = false; |
| 783 | bool setup = false; |
Jon Paul Maloy | 5266698 | 2015-10-22 08:51:41 -0400 | [diff] [blame] | 784 | u16 bc_snt = l->bc_sndlink->snd_nxt - 1; |
| 785 | u16 bc_acked = l->bc_rcvlink->acked; |
Jon Paul Maloy | 35c55c9 | 2016-06-13 20:46:22 -0400 | [diff] [blame] | 786 | struct tipc_mon_state *mstate = &l->mon_state; |
Jon Paul Maloy | 5045f7b | 2015-07-30 18:24:20 -0400 | [diff] [blame] | 787 | |
Tuong Lien | 26574db | 2018-12-19 09:17:57 +0700 | [diff] [blame] | 788 | trace_tipc_link_timeout(l, TIPC_DUMP_NONE, " "); |
| 789 | trace_tipc_link_too_silent(l, TIPC_DUMP_ALL, " "); |
Jon Paul Maloy | 662921c | 2015-07-30 18:24:21 -0400 | [diff] [blame] | 790 | switch (l->state) { |
| 791 | case LINK_ESTABLISHED: |
| 792 | case LINK_SYNCHING: |
Jon Paul Maloy | 42b18f6 | 2016-04-15 13:33:05 -0400 | [diff] [blame] | 793 | mtyp = STATE_MSG; |
Jon Paul Maloy | 35c55c9 | 2016-06-13 20:46:22 -0400 | [diff] [blame] | 794 | link_profile_stats(l); |
| 795 | tipc_mon_get_state(l->net, l->addr, mstate, l->bearer_id); |
| 796 | if (mstate->reset || (l->silent_intv_cnt > l->abort_limit)) |
| 797 | return tipc_link_fsm_evt(l, LINK_FAILURE_EVT); |
Jon Paul Maloy | 42b18f6 | 2016-04-15 13:33:05 -0400 | [diff] [blame] | 798 | state = bc_acked != bc_snt; |
Jon Paul Maloy | 35c55c9 | 2016-06-13 20:46:22 -0400 | [diff] [blame] | 799 | state |= l->bc_rcvlink->rcv_unacked; |
| 800 | state |= l->rcv_unacked; |
| 801 | state |= !skb_queue_empty(&l->transmq); |
| 802 | state |= !skb_queue_empty(&l->deferdq); |
| 803 | probe = mstate->probing; |
| 804 | probe |= l->silent_intv_cnt; |
| 805 | if (probe || mstate->monitoring) |
| 806 | l->silent_intv_cnt++; |
Jon Paul Maloy | 662921c | 2015-07-30 18:24:21 -0400 | [diff] [blame] | 807 | break; |
| 808 | case LINK_RESET: |
Jon Paul Maloy | 42b18f6 | 2016-04-15 13:33:05 -0400 | [diff] [blame] | 809 | setup = l->rst_cnt++ <= 4; |
| 810 | setup |= !(l->rst_cnt % 16); |
Jon Paul Maloy | 5045f7b | 2015-07-30 18:24:20 -0400 | [diff] [blame] | 811 | mtyp = RESET_MSG; |
Jon Paul Maloy | 662921c | 2015-07-30 18:24:21 -0400 | [diff] [blame] | 812 | break; |
| 813 | case LINK_ESTABLISHING: |
Jon Paul Maloy | 42b18f6 | 2016-04-15 13:33:05 -0400 | [diff] [blame] | 814 | setup = true; |
Jon Paul Maloy | 5045f7b | 2015-07-30 18:24:20 -0400 | [diff] [blame] | 815 | mtyp = ACTIVATE_MSG; |
Jon Paul Maloy | 662921c | 2015-07-30 18:24:21 -0400 | [diff] [blame] | 816 | break; |
Jon Paul Maloy | 662921c | 2015-07-30 18:24:21 -0400 | [diff] [blame] | 817 | case LINK_PEER_RESET: |
Jon Paul Maloy | 598411d | 2015-07-30 18:24:23 -0400 | [diff] [blame] | 818 | case LINK_RESETTING: |
Jon Paul Maloy | 662921c | 2015-07-30 18:24:21 -0400 | [diff] [blame] | 819 | case LINK_FAILINGOVER: |
| 820 | break; |
| 821 | default: |
| 822 | break; |
Jon Paul Maloy | 5045f7b | 2015-07-30 18:24:20 -0400 | [diff] [blame] | 823 | } |
Jon Paul Maloy | 662921c | 2015-07-30 18:24:21 -0400 | [diff] [blame] | 824 | |
Jon Paul Maloy | 42b18f6 | 2016-04-15 13:33:05 -0400 | [diff] [blame] | 825 | if (state || probe || setup) |
Jon Maloy | 8d6e79d | 2017-11-08 09:59:26 +0100 | [diff] [blame] | 826 | tipc_link_build_proto_msg(l, mtyp, probe, 0, 0, 0, 0, xmitq); |
Jon Paul Maloy | 5045f7b | 2015-07-30 18:24:20 -0400 | [diff] [blame] | 827 | |
Jon Paul Maloy | 333ef69 | 2015-07-16 16:54:28 -0400 | [diff] [blame] | 828 | return rc; |
| 829 | } |
| 830 | |
Jon Paul Maloy | 6ab30f9 | 2015-07-16 16:54:27 -0400 | [diff] [blame] | 831 | /** |
Jon Paul Maloy | 3127a02 | 2015-03-25 12:07:25 -0400 | [diff] [blame] | 832 | * link_schedule_user - schedule a message sender for wakeup after congestion |
Jon Paul Maloy | 365ad35 | 2017-01-03 10:55:11 -0500 | [diff] [blame] | 833 | * @l: congested link |
| 834 | * @hdr: header of message that is being sent |
Jon Paul Maloy | 50100a5 | 2014-08-22 18:09:07 -0400 | [diff] [blame] | 835 | * Create pseudo msg to send back to user when congestion abates |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 836 | */ |
Jon Paul Maloy | 365ad35 | 2017-01-03 10:55:11 -0500 | [diff] [blame] | 837 | static int link_schedule_user(struct tipc_link *l, struct tipc_msg *hdr) |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 838 | { |
Jon Paul Maloy | 365ad35 | 2017-01-03 10:55:11 -0500 | [diff] [blame] | 839 | u32 dnode = tipc_own_addr(l->net); |
| 840 | u32 dport = msg_origport(hdr); |
Jon Paul Maloy | 3127a02 | 2015-03-25 12:07:25 -0400 | [diff] [blame] | 841 | struct sk_buff *skb; |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 842 | |
Jon Paul Maloy | 3127a02 | 2015-03-25 12:07:25 -0400 | [diff] [blame] | 843 | /* Create and schedule wakeup pseudo message */ |
| 844 | skb = tipc_msg_create(SOCK_WAKEUP, 0, INT_H_SIZE, 0, |
Jon Paul Maloy | 365ad35 | 2017-01-03 10:55:11 -0500 | [diff] [blame] | 845 | dnode, l->addr, dport, 0, 0); |
Jon Paul Maloy | 3127a02 | 2015-03-25 12:07:25 -0400 | [diff] [blame] | 846 | if (!skb) |
Jon Paul Maloy | 22d85c7 | 2015-07-16 16:54:23 -0400 | [diff] [blame] | 847 | return -ENOBUFS; |
Jon Paul Maloy | 365ad35 | 2017-01-03 10:55:11 -0500 | [diff] [blame] | 848 | msg_set_dest_droppable(buf_msg(skb), true); |
| 849 | TIPC_SKB_CB(skb)->chain_imp = msg_importance(hdr); |
| 850 | skb_queue_tail(&l->wakeupq, skb); |
| 851 | l->stats.link_congs++; |
Tuong Lien | 26574db | 2018-12-19 09:17:57 +0700 | [diff] [blame] | 852 | trace_tipc_link_conges(l, TIPC_DUMP_ALL, "wakeup scheduled!"); |
Jon Paul Maloy | 3127a02 | 2015-03-25 12:07:25 -0400 | [diff] [blame] | 853 | return -ELINKCONG; |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 854 | } |
| 855 | |
Jon Paul Maloy | 50100a5 | 2014-08-22 18:09:07 -0400 | [diff] [blame] | 856 | /** |
| 857 | * link_prepare_wakeup - prepare users for wakeup after congestion |
Jon Paul Maloy | 365ad35 | 2017-01-03 10:55:11 -0500 | [diff] [blame] | 858 | * @l: congested link |
| 859 | * Wake up a number of waiting users, as permitted by available space |
| 860 | * in the send queue |
Jon Paul Maloy | 50100a5 | 2014-08-22 18:09:07 -0400 | [diff] [blame] | 861 | */ |
YueHaibing | e064cce | 2018-07-19 17:16:59 +0800 | [diff] [blame] | 862 | static void link_prepare_wakeup(struct tipc_link *l) |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 863 | { |
Jon Maloy | 7c5b420 | 2019-07-30 16:23:18 +0200 | [diff] [blame] | 864 | struct sk_buff_head *wakeupq = &l->wakeupq; |
| 865 | struct sk_buff_head *inputq = l->inputq; |
Ying Xue | 58d78b3 | 2014-11-26 11:41:51 +0800 | [diff] [blame] | 866 | struct sk_buff *skb, *tmp; |
Jon Maloy | 7c5b420 | 2019-07-30 16:23:18 +0200 | [diff] [blame] | 867 | struct sk_buff_head tmpq; |
| 868 | int avail[5] = {0,}; |
| 869 | int imp = 0; |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 870 | |
Jon Maloy | 7c5b420 | 2019-07-30 16:23:18 +0200 | [diff] [blame] | 871 | __skb_queue_head_init(&tmpq); |
| 872 | |
| 873 | for (; imp <= TIPC_SYSTEM_IMPORTANCE; imp++) |
| 874 | avail[imp] = l->backlog[imp].limit - l->backlog[imp].len; |
| 875 | |
| 876 | skb_queue_walk_safe(wakeupq, skb, tmp) { |
Jon Paul Maloy | 1f66d16 | 2015-03-25 12:07:24 -0400 | [diff] [blame] | 877 | imp = TIPC_SKB_CB(skb)->chain_imp; |
Jon Maloy | 7c5b420 | 2019-07-30 16:23:18 +0200 | [diff] [blame] | 878 | if (avail[imp] <= 0) |
| 879 | continue; |
| 880 | avail[imp]--; |
| 881 | __skb_unlink(skb, wakeupq); |
| 882 | __skb_queue_tail(&tmpq, skb); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 883 | } |
Jon Maloy | 7c5b420 | 2019-07-30 16:23:18 +0200 | [diff] [blame] | 884 | |
| 885 | spin_lock_bh(&inputq->lock); |
| 886 | skb_queue_splice_tail(&tmpq, inputq); |
| 887 | spin_unlock_bh(&inputq->lock); |
| 888 | |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 889 | } |
| 890 | |
Jon Paul Maloy | 6e49815 | 2015-07-30 18:24:19 -0400 | [diff] [blame] | 891 | void tipc_link_reset(struct tipc_link *l) |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 892 | { |
Ying Xue | a1f8dd3 | 2018-10-11 19:57:56 +0800 | [diff] [blame] | 893 | struct sk_buff_head list; |
Tuong Lien | e95584a | 2019-10-02 18:49:43 +0700 | [diff] [blame] | 894 | u32 imp; |
Ying Xue | a1f8dd3 | 2018-10-11 19:57:56 +0800 | [diff] [blame] | 895 | |
| 896 | __skb_queue_head_init(&list); |
| 897 | |
Jon Maloy | 7ea817f | 2018-07-10 01:07:36 +0200 | [diff] [blame] | 898 | l->in_session = false; |
Tuong Lien | f7a9378 | 2019-04-16 10:48:07 +0700 | [diff] [blame] | 899 | /* Force re-synch of peer session number before establishing */ |
| 900 | l->peer_session--; |
Jon Paul Maloy | e74a386 | 2016-03-03 14:23:21 -0500 | [diff] [blame] | 901 | l->session++; |
Jon Paul Maloy | 6e49815 | 2015-07-30 18:24:19 -0400 | [diff] [blame] | 902 | l->mtu = l->advertised_mtu; |
Ying Xue | a1f8dd3 | 2018-10-11 19:57:56 +0800 | [diff] [blame] | 903 | |
Parthasarathy Bhuvaragan | 3f32d0b | 2018-09-25 22:09:10 +0200 | [diff] [blame] | 904 | spin_lock_bh(&l->wakeupq.lock); |
Ying Xue | a1f8dd3 | 2018-10-11 19:57:56 +0800 | [diff] [blame] | 905 | skb_queue_splice_init(&l->wakeupq, &list); |
Parthasarathy Bhuvaragan | 3f32d0b | 2018-09-25 22:09:10 +0200 | [diff] [blame] | 906 | spin_unlock_bh(&l->wakeupq.lock); |
| 907 | |
Ying Xue | a1f8dd3 | 2018-10-11 19:57:56 +0800 | [diff] [blame] | 908 | spin_lock_bh(&l->inputq->lock); |
| 909 | skb_queue_splice_init(&list, l->inputq); |
| 910 | spin_unlock_bh(&l->inputq->lock); |
| 911 | |
Jon Paul Maloy | 6e49815 | 2015-07-30 18:24:19 -0400 | [diff] [blame] | 912 | __skb_queue_purge(&l->transmq); |
| 913 | __skb_queue_purge(&l->deferdq); |
Jon Paul Maloy | 2af5ae3 | 2015-10-22 08:51:48 -0400 | [diff] [blame] | 914 | __skb_queue_purge(&l->backlogq); |
Tuong Lien | 58ee86b | 2019-04-04 11:09:53 +0700 | [diff] [blame] | 915 | __skb_queue_purge(&l->failover_deferdq); |
Tuong Lien | e95584a | 2019-10-02 18:49:43 +0700 | [diff] [blame] | 916 | for (imp = 0; imp <= TIPC_SYSTEM_IMPORTANCE; imp++) { |
| 917 | l->backlog[imp].len = 0; |
| 918 | l->backlog[imp].target_bskb = NULL; |
| 919 | } |
Jon Paul Maloy | 6e49815 | 2015-07-30 18:24:19 -0400 | [diff] [blame] | 920 | kfree_skb(l->reasm_buf); |
Tuong Lien | 2320bcd | 2019-07-24 08:56:12 +0700 | [diff] [blame] | 921 | kfree_skb(l->reasm_tnlmsg); |
Jon Paul Maloy | 6e49815 | 2015-07-30 18:24:19 -0400 | [diff] [blame] | 922 | kfree_skb(l->failover_reasm_skb); |
| 923 | l->reasm_buf = NULL; |
Tuong Lien | 2320bcd | 2019-07-24 08:56:12 +0700 | [diff] [blame] | 924 | l->reasm_tnlmsg = NULL; |
Jon Paul Maloy | 6e49815 | 2015-07-30 18:24:19 -0400 | [diff] [blame] | 925 | l->failover_reasm_skb = NULL; |
| 926 | l->rcv_unacked = 0; |
| 927 | l->snd_nxt = 1; |
| 928 | l->rcv_nxt = 1; |
Jon Maloy | 9012de5 | 2018-07-10 01:07:35 +0200 | [diff] [blame] | 929 | l->snd_nxt_state = 1; |
| 930 | l->rcv_nxt_state = 1; |
Jon Paul Maloy | c1ab3f1d | 2015-10-22 08:51:38 -0400 | [diff] [blame] | 931 | l->acked = 0; |
Jon Paul Maloy | 6e49815 | 2015-07-30 18:24:19 -0400 | [diff] [blame] | 932 | l->silent_intv_cnt = 0; |
Jon Paul Maloy | 88e8ac7 | 2016-04-15 13:33:04 -0400 | [diff] [blame] | 933 | l->rst_cnt = 0; |
Jon Paul Maloy | 5266698 | 2015-10-22 08:51:41 -0400 | [diff] [blame] | 934 | l->bc_peer_is_up = false; |
Jon Paul Maloy | 35c55c9 | 2016-06-13 20:46:22 -0400 | [diff] [blame] | 935 | memset(&l->mon_state, 0, sizeof(l->mon_state)); |
Jon Paul Maloy | 38206d5 | 2015-11-19 14:30:46 -0500 | [diff] [blame] | 936 | tipc_link_reset_stats(l); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 937 | } |
| 938 | |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 939 | /** |
Jon Paul Maloy | af9b028 | 2015-07-16 16:54:24 -0400 | [diff] [blame] | 940 | * tipc_link_xmit(): enqueue buffer list according to queue situation |
| 941 | * @link: link to use |
| 942 | * @list: chain of buffers containing message |
| 943 | * @xmitq: returned list of packets to be sent by caller |
| 944 | * |
Jon Paul Maloy | 365ad35 | 2017-01-03 10:55:11 -0500 | [diff] [blame] | 945 | * Consumes the buffer chain. |
Jon Paul Maloy | af9b028 | 2015-07-16 16:54:24 -0400 | [diff] [blame] | 946 | * Returns 0 if success, or errno: -ELINKCONG, -EMSGSIZE or -ENOBUFS |
| 947 | * Messages at TIPC_SYSTEM_IMPORTANCE are always accepted |
| 948 | */ |
| 949 | int tipc_link_xmit(struct tipc_link *l, struct sk_buff_head *list, |
| 950 | struct sk_buff_head *xmitq) |
| 951 | { |
| 952 | struct tipc_msg *hdr = buf_msg(skb_peek(list)); |
Tuong Lien | 06e7c70 | 2019-11-01 09:58:57 +0700 | [diff] [blame] | 953 | struct sk_buff_head *backlogq = &l->backlogq; |
| 954 | struct sk_buff_head *transmq = &l->transmq; |
| 955 | struct sk_buff *skb, *_skb; |
| 956 | u16 bc_ack = l->bc_rcvlink->rcv_nxt - 1; |
Jon Paul Maloy | af9b028 | 2015-07-16 16:54:24 -0400 | [diff] [blame] | 957 | u16 ack = l->rcv_nxt - 1; |
| 958 | u16 seqno = l->snd_nxt; |
Jon Paul Maloy | 9590112 | 2016-11-25 10:35:02 -0500 | [diff] [blame] | 959 | int pkt_cnt = skb_queue_len(list); |
Tuong Lien | 06e7c70 | 2019-11-01 09:58:57 +0700 | [diff] [blame] | 960 | int imp = msg_importance(hdr); |
Tuong Lien | fc1b6d6 | 2019-11-08 12:05:11 +0700 | [diff] [blame] | 961 | unsigned int mss = tipc_link_mss(l); |
Tuong Lien | 06e7c70 | 2019-11-01 09:58:57 +0700 | [diff] [blame] | 962 | unsigned int maxwin = l->window; |
| 963 | unsigned int mtu = l->mtu; |
| 964 | bool new_bundle; |
Jon Paul Maloy | 365ad35 | 2017-01-03 10:55:11 -0500 | [diff] [blame] | 965 | int rc = 0; |
Jon Paul Maloy | af9b028 | 2015-07-16 16:54:24 -0400 | [diff] [blame] | 966 | |
Richard Alpe | 4952cd3 | 2016-02-11 10:43:15 +0100 | [diff] [blame] | 967 | if (unlikely(msg_size(hdr) > mtu)) { |
Tuong Lien | 2320bcd | 2019-07-24 08:56:12 +0700 | [diff] [blame] | 968 | pr_warn("Too large msg, purging xmit list %d %d %d %d %d!\n", |
| 969 | skb_queue_len(list), msg_user(hdr), |
| 970 | msg_type(hdr), msg_size(hdr), mtu); |
Jon Maloy | e654f9f | 2019-08-15 16:42:50 +0200 | [diff] [blame] | 971 | __skb_queue_purge(list); |
Jon Paul Maloy | af9b028 | 2015-07-16 16:54:24 -0400 | [diff] [blame] | 972 | return -EMSGSIZE; |
Richard Alpe | 4952cd3 | 2016-02-11 10:43:15 +0100 | [diff] [blame] | 973 | } |
Jon Paul Maloy | af9b028 | 2015-07-16 16:54:24 -0400 | [diff] [blame] | 974 | |
Jon Paul Maloy | 365ad35 | 2017-01-03 10:55:11 -0500 | [diff] [blame] | 975 | /* Allow oversubscription of one data msg per source at congestion */ |
| 976 | if (unlikely(l->backlog[imp].len >= l->backlog[imp].limit)) { |
| 977 | if (imp == TIPC_SYSTEM_IMPORTANCE) { |
| 978 | pr_warn("%s<%s>, link overflow", link_rst_msg, l->name); |
| 979 | return -ENOBUFS; |
| 980 | } |
| 981 | rc = link_schedule_user(l, hdr); |
| 982 | } |
| 983 | |
Jon Paul Maloy | 9590112 | 2016-11-25 10:35:02 -0500 | [diff] [blame] | 984 | if (pkt_cnt > 1) { |
| 985 | l->stats.sent_fragmented++; |
| 986 | l->stats.sent_fragments += pkt_cnt; |
| 987 | } |
| 988 | |
Jon Paul Maloy | af9b028 | 2015-07-16 16:54:24 -0400 | [diff] [blame] | 989 | /* Prepare each packet for sending, and add to relevant queue: */ |
Tuong Lien | 06e7c70 | 2019-11-01 09:58:57 +0700 | [diff] [blame] | 990 | while ((skb = __skb_dequeue(list))) { |
Jon Paul Maloy | af9b028 | 2015-07-16 16:54:24 -0400 | [diff] [blame] | 991 | if (likely(skb_queue_len(transmq) < maxwin)) { |
Tuong Lien | 06e7c70 | 2019-11-01 09:58:57 +0700 | [diff] [blame] | 992 | hdr = buf_msg(skb); |
| 993 | msg_set_seqno(hdr, seqno); |
| 994 | msg_set_ack(hdr, ack); |
| 995 | msg_set_bcast_ack(hdr, bc_ack); |
Jon Paul Maloy | af9b028 | 2015-07-16 16:54:24 -0400 | [diff] [blame] | 996 | _skb = skb_clone(skb, GFP_ATOMIC); |
Richard Alpe | 4952cd3 | 2016-02-11 10:43:15 +0100 | [diff] [blame] | 997 | if (!_skb) { |
Tuong Lien | 06e7c70 | 2019-11-01 09:58:57 +0700 | [diff] [blame] | 998 | kfree_skb(skb); |
Jon Maloy | e654f9f | 2019-08-15 16:42:50 +0200 | [diff] [blame] | 999 | __skb_queue_purge(list); |
Jon Paul Maloy | af9b028 | 2015-07-16 16:54:24 -0400 | [diff] [blame] | 1000 | return -ENOBUFS; |
Richard Alpe | 4952cd3 | 2016-02-11 10:43:15 +0100 | [diff] [blame] | 1001 | } |
Jon Paul Maloy | af9b028 | 2015-07-16 16:54:24 -0400 | [diff] [blame] | 1002 | __skb_queue_tail(transmq, skb); |
Hoang Le | 0557227 | 2018-12-19 11:42:19 +0700 | [diff] [blame] | 1003 | /* next retransmit attempt */ |
| 1004 | if (link_is_bc_sndlink(l)) |
Jon Maloy | 53962bc | 2019-06-28 17:06:20 +0200 | [diff] [blame] | 1005 | TIPC_SKB_CB(skb)->nxt_retr = TIPC_BC_RETR_LIM; |
Jon Paul Maloy | af9b028 | 2015-07-16 16:54:24 -0400 | [diff] [blame] | 1006 | __skb_queue_tail(xmitq, _skb); |
Jon Paul Maloy | c1ab3f1d | 2015-10-22 08:51:38 -0400 | [diff] [blame] | 1007 | TIPC_SKB_CB(skb)->ackers = l->ackers; |
Jon Paul Maloy | af9b028 | 2015-07-16 16:54:24 -0400 | [diff] [blame] | 1008 | l->rcv_unacked = 0; |
Jon Paul Maloy | 9590112 | 2016-11-25 10:35:02 -0500 | [diff] [blame] | 1009 | l->stats.sent_pkts++; |
Jon Paul Maloy | af9b028 | 2015-07-16 16:54:24 -0400 | [diff] [blame] | 1010 | seqno++; |
| 1011 | continue; |
| 1012 | } |
Tuong Lien | 06e7c70 | 2019-11-01 09:58:57 +0700 | [diff] [blame] | 1013 | if (tipc_msg_try_bundle(l->backlog[imp].target_bskb, &skb, |
Tuong Lien | fc1b6d6 | 2019-11-08 12:05:11 +0700 | [diff] [blame] | 1014 | mss, l->addr, &new_bundle)) { |
Tuong Lien | 06e7c70 | 2019-11-01 09:58:57 +0700 | [diff] [blame] | 1015 | if (skb) { |
| 1016 | /* Keep a ref. to the skb for next try */ |
| 1017 | l->backlog[imp].target_bskb = skb; |
| 1018 | l->backlog[imp].len++; |
| 1019 | __skb_queue_tail(backlogq, skb); |
| 1020 | } else { |
| 1021 | if (new_bundle) { |
| 1022 | l->stats.sent_bundles++; |
| 1023 | l->stats.sent_bundled++; |
| 1024 | } |
| 1025 | l->stats.sent_bundled++; |
| 1026 | } |
Jon Paul Maloy | af9b028 | 2015-07-16 16:54:24 -0400 | [diff] [blame] | 1027 | continue; |
| 1028 | } |
Tuong Lien | e95584a | 2019-10-02 18:49:43 +0700 | [diff] [blame] | 1029 | l->backlog[imp].target_bskb = NULL; |
Tuong Lien | 06e7c70 | 2019-11-01 09:58:57 +0700 | [diff] [blame] | 1030 | l->backlog[imp].len += (1 + skb_queue_len(list)); |
| 1031 | __skb_queue_tail(backlogq, skb); |
Jon Paul Maloy | af9b028 | 2015-07-16 16:54:24 -0400 | [diff] [blame] | 1032 | skb_queue_splice_tail_init(list, backlogq); |
| 1033 | } |
| 1034 | l->snd_nxt = seqno; |
Jon Paul Maloy | 365ad35 | 2017-01-03 10:55:11 -0500 | [diff] [blame] | 1035 | return rc; |
Jon Paul Maloy | af9b028 | 2015-07-16 16:54:24 -0400 | [diff] [blame] | 1036 | } |
| 1037 | |
YueHaibing | e064cce | 2018-07-19 17:16:59 +0800 | [diff] [blame] | 1038 | static void tipc_link_advance_backlog(struct tipc_link *l, |
| 1039 | struct sk_buff_head *xmitq) |
Jon Paul Maloy | d999297 | 2015-07-16 16:54:31 -0400 | [diff] [blame] | 1040 | { |
| 1041 | struct sk_buff *skb, *_skb; |
| 1042 | struct tipc_msg *hdr; |
| 1043 | u16 seqno = l->snd_nxt; |
| 1044 | u16 ack = l->rcv_nxt - 1; |
Jon Paul Maloy | 5266698 | 2015-10-22 08:51:41 -0400 | [diff] [blame] | 1045 | u16 bc_ack = l->bc_rcvlink->rcv_nxt - 1; |
Tuong Lien | e95584a | 2019-10-02 18:49:43 +0700 | [diff] [blame] | 1046 | u32 imp; |
Jon Paul Maloy | d999297 | 2015-07-16 16:54:31 -0400 | [diff] [blame] | 1047 | |
| 1048 | while (skb_queue_len(&l->transmq) < l->window) { |
| 1049 | skb = skb_peek(&l->backlogq); |
| 1050 | if (!skb) |
| 1051 | break; |
| 1052 | _skb = skb_clone(skb, GFP_ATOMIC); |
| 1053 | if (!_skb) |
| 1054 | break; |
| 1055 | __skb_dequeue(&l->backlogq); |
| 1056 | hdr = buf_msg(skb); |
Tuong Lien | e95584a | 2019-10-02 18:49:43 +0700 | [diff] [blame] | 1057 | imp = msg_importance(hdr); |
| 1058 | l->backlog[imp].len--; |
| 1059 | if (unlikely(skb == l->backlog[imp].target_bskb)) |
| 1060 | l->backlog[imp].target_bskb = NULL; |
Jon Paul Maloy | d999297 | 2015-07-16 16:54:31 -0400 | [diff] [blame] | 1061 | __skb_queue_tail(&l->transmq, skb); |
Hoang Le | 0557227 | 2018-12-19 11:42:19 +0700 | [diff] [blame] | 1062 | /* next retransmit attempt */ |
| 1063 | if (link_is_bc_sndlink(l)) |
Jon Maloy | 53962bc | 2019-06-28 17:06:20 +0200 | [diff] [blame] | 1064 | TIPC_SKB_CB(skb)->nxt_retr = TIPC_BC_RETR_LIM; |
Hoang Le | 0557227 | 2018-12-19 11:42:19 +0700 | [diff] [blame] | 1065 | |
Jon Paul Maloy | d999297 | 2015-07-16 16:54:31 -0400 | [diff] [blame] | 1066 | __skb_queue_tail(xmitq, _skb); |
Jon Paul Maloy | c1ab3f1d | 2015-10-22 08:51:38 -0400 | [diff] [blame] | 1067 | TIPC_SKB_CB(skb)->ackers = l->ackers; |
Jon Paul Maloy | d999297 | 2015-07-16 16:54:31 -0400 | [diff] [blame] | 1068 | msg_set_seqno(hdr, seqno); |
Jon Paul Maloy | 5266698 | 2015-10-22 08:51:41 -0400 | [diff] [blame] | 1069 | msg_set_ack(hdr, ack); |
| 1070 | msg_set_bcast_ack(hdr, bc_ack); |
Jon Paul Maloy | d999297 | 2015-07-16 16:54:31 -0400 | [diff] [blame] | 1071 | l->rcv_unacked = 0; |
Jon Paul Maloy | 9590112 | 2016-11-25 10:35:02 -0500 | [diff] [blame] | 1072 | l->stats.sent_pkts++; |
Jon Paul Maloy | d999297 | 2015-07-16 16:54:31 -0400 | [diff] [blame] | 1073 | seqno++; |
| 1074 | } |
| 1075 | l->snd_nxt = seqno; |
| 1076 | } |
| 1077 | |
Tuong Lien | 6a6b5c8 | 2019-06-17 12:15:42 +0700 | [diff] [blame] | 1078 | /** |
| 1079 | * link_retransmit_failure() - Detect repeated retransmit failures |
| 1080 | * @l: tipc link sender |
| 1081 | * @r: tipc link receiver (= l in case of unicast) |
Tuong Lien | 6a6b5c8 | 2019-06-17 12:15:42 +0700 | [diff] [blame] | 1082 | * @rc: returned code |
| 1083 | * |
| 1084 | * Return: true if the repeated retransmit failures happens, otherwise |
| 1085 | * false |
| 1086 | */ |
| 1087 | static bool link_retransmit_failure(struct tipc_link *l, struct tipc_link *r, |
Tuong Lien | 7120423 | 2019-08-15 10:24:08 +0700 | [diff] [blame] | 1088 | int *rc) |
Allan Stephens | d356eeb | 2006-06-25 23:40:01 -0700 | [diff] [blame] | 1089 | { |
Tuong Lien | 6a6b5c8 | 2019-06-17 12:15:42 +0700 | [diff] [blame] | 1090 | struct sk_buff *skb = skb_peek(&l->transmq); |
| 1091 | struct tipc_msg *hdr; |
Allan Stephens | d356eeb | 2006-06-25 23:40:01 -0700 | [diff] [blame] | 1092 | |
Tuong Lien | 6a6b5c8 | 2019-06-17 12:15:42 +0700 | [diff] [blame] | 1093 | if (!skb) |
| 1094 | return false; |
Tuong Lien | 7120423 | 2019-08-15 10:24:08 +0700 | [diff] [blame] | 1095 | |
| 1096 | if (!TIPC_SKB_CB(skb)->retr_cnt) |
| 1097 | return false; |
| 1098 | |
| 1099 | if (!time_after(jiffies, TIPC_SKB_CB(skb)->retr_stamp + |
Hoang Le | 426071f | 2019-11-06 13:26:10 +0700 | [diff] [blame] | 1100 | msecs_to_jiffies(r->tolerance * 10))) |
Tuong Lien | 7120423 | 2019-08-15 10:24:08 +0700 | [diff] [blame] | 1101 | return false; |
| 1102 | |
Tuong Lien | 6a6b5c8 | 2019-06-17 12:15:42 +0700 | [diff] [blame] | 1103 | hdr = buf_msg(skb); |
Tuong Lien | 7120423 | 2019-08-15 10:24:08 +0700 | [diff] [blame] | 1104 | if (link_is_bc_sndlink(l) && !less(r->acked, msg_seqno(hdr))) |
| 1105 | return false; |
Tuong Lien | 6a6b5c8 | 2019-06-17 12:15:42 +0700 | [diff] [blame] | 1106 | |
Tuong Lien | 7120423 | 2019-08-15 10:24:08 +0700 | [diff] [blame] | 1107 | pr_warn("Retransmission failure on link <%s>\n", l->name); |
| 1108 | link_print(l, "State of link "); |
| 1109 | pr_info("Failed msg: usr %u, typ %u, len %u, err %u\n", |
| 1110 | msg_user(hdr), msg_type(hdr), msg_size(hdr), msg_errcode(hdr)); |
| 1111 | pr_info("sqno %u, prev: %x, dest: %x\n", |
| 1112 | msg_seqno(hdr), msg_prevnode(hdr), msg_destnode(hdr)); |
| 1113 | pr_info("retr_stamp %d, retr_cnt %d\n", |
| 1114 | jiffies_to_msecs(TIPC_SKB_CB(skb)->retr_stamp), |
| 1115 | TIPC_SKB_CB(skb)->retr_cnt); |
Tuong Lien | 6a6b5c8 | 2019-06-17 12:15:42 +0700 | [diff] [blame] | 1116 | |
Tuong Lien | 7120423 | 2019-08-15 10:24:08 +0700 | [diff] [blame] | 1117 | trace_tipc_list_dump(&l->transmq, true, "retrans failure!"); |
| 1118 | trace_tipc_link_dump(l, TIPC_DUMP_NONE, "retrans failure!"); |
| 1119 | trace_tipc_link_dump(r, TIPC_DUMP_NONE, "retrans failure!"); |
Tuong Lien | 6a6b5c8 | 2019-06-17 12:15:42 +0700 | [diff] [blame] | 1120 | |
Tuong Lien | 7120423 | 2019-08-15 10:24:08 +0700 | [diff] [blame] | 1121 | if (link_is_bc_sndlink(l)) { |
| 1122 | r->state = LINK_RESET; |
| 1123 | *rc = TIPC_LINK_DOWN_EVT; |
| 1124 | } else { |
Tuong Lien | 6a6b5c8 | 2019-06-17 12:15:42 +0700 | [diff] [blame] | 1125 | *rc = tipc_link_fsm_evt(l, LINK_FAILURE_EVT); |
Tuong Lien | 6a6b5c8 | 2019-06-17 12:15:42 +0700 | [diff] [blame] | 1126 | } |
| 1127 | |
Tuong Lien | 7120423 | 2019-08-15 10:24:08 +0700 | [diff] [blame] | 1128 | return true; |
Allan Stephens | d356eeb | 2006-06-25 23:40:01 -0700 | [diff] [blame] | 1129 | } |
| 1130 | |
Tuong Lien | 6a6b5c8 | 2019-06-17 12:15:42 +0700 | [diff] [blame] | 1131 | /* tipc_link_bc_retrans() - retransmit zero or more packets |
Jon Maloy | a4dc70d | 2018-07-06 15:22:36 +0200 | [diff] [blame] | 1132 | * @l: the link to transmit on |
| 1133 | * @r: the receiving link ordering the retransmit. Same as l if unicast |
| 1134 | * @from: retransmit from (inclusive) this sequence number |
| 1135 | * @to: retransmit to (inclusive) this sequence number |
| 1136 | * xmitq: queue for accumulating the retransmitted packets |
| 1137 | */ |
Tuong Lien | 6a6b5c8 | 2019-06-17 12:15:42 +0700 | [diff] [blame] | 1138 | static int tipc_link_bc_retrans(struct tipc_link *l, struct tipc_link *r, |
| 1139 | u16 from, u16 to, struct sk_buff_head *xmitq) |
Jon Paul Maloy | d999297 | 2015-07-16 16:54:31 -0400 | [diff] [blame] | 1140 | { |
| 1141 | struct sk_buff *_skb, *skb = skb_peek(&l->transmq); |
Jon Paul Maloy | 5266698 | 2015-10-22 08:51:41 -0400 | [diff] [blame] | 1142 | u16 bc_ack = l->bc_rcvlink->rcv_nxt - 1; |
Jon Maloy | a4dc70d | 2018-07-06 15:22:36 +0200 | [diff] [blame] | 1143 | u16 ack = l->rcv_nxt - 1; |
| 1144 | struct tipc_msg *hdr; |
Tuong Lien | 6a6b5c8 | 2019-06-17 12:15:42 +0700 | [diff] [blame] | 1145 | int rc = 0; |
Jon Paul Maloy | d999297 | 2015-07-16 16:54:31 -0400 | [diff] [blame] | 1146 | |
| 1147 | if (!skb) |
| 1148 | return 0; |
LUU Duc Canh | 31c4f4c | 2018-11-10 14:23:50 -0500 | [diff] [blame] | 1149 | if (less(to, from)) |
| 1150 | return 0; |
Jon Paul Maloy | d999297 | 2015-07-16 16:54:31 -0400 | [diff] [blame] | 1151 | |
Tuong Lien | 26574db | 2018-12-19 09:17:57 +0700 | [diff] [blame] | 1152 | trace_tipc_link_retrans(r, from, to, &l->transmq); |
Tuong Lien | 6a6b5c8 | 2019-06-17 12:15:42 +0700 | [diff] [blame] | 1153 | |
Tuong Lien | 7120423 | 2019-08-15 10:24:08 +0700 | [diff] [blame] | 1154 | if (link_retransmit_failure(l, r, &rc)) |
Tuong Lien | 6a6b5c8 | 2019-06-17 12:15:42 +0700 | [diff] [blame] | 1155 | return rc; |
Jon Paul Maloy | c1ab3f1d | 2015-10-22 08:51:38 -0400 | [diff] [blame] | 1156 | |
Jon Paul Maloy | d999297 | 2015-07-16 16:54:31 -0400 | [diff] [blame] | 1157 | skb_queue_walk(&l->transmq, skb) { |
Jon Paul Maloy | d999297 | 2015-07-16 16:54:31 -0400 | [diff] [blame] | 1158 | hdr = buf_msg(skb); |
Jon Maloy | a4dc70d | 2018-07-06 15:22:36 +0200 | [diff] [blame] | 1159 | if (less(msg_seqno(hdr), from)) |
| 1160 | continue; |
| 1161 | if (more(msg_seqno(hdr), to)) |
| 1162 | break; |
Tuong Lien | 7120423 | 2019-08-15 10:24:08 +0700 | [diff] [blame] | 1163 | |
| 1164 | if (time_before(jiffies, TIPC_SKB_CB(skb)->nxt_retr)) |
| 1165 | continue; |
| 1166 | TIPC_SKB_CB(skb)->nxt_retr = TIPC_BC_RETR_LIM; |
Tuong Lien | fc1b6d6 | 2019-11-08 12:05:11 +0700 | [diff] [blame] | 1167 | _skb = pskb_copy(skb, GFP_ATOMIC); |
Jon Paul Maloy | d999297 | 2015-07-16 16:54:31 -0400 | [diff] [blame] | 1168 | if (!_skb) |
| 1169 | return 0; |
| 1170 | hdr = buf_msg(_skb); |
Jon Paul Maloy | c1ab3f1d | 2015-10-22 08:51:38 -0400 | [diff] [blame] | 1171 | msg_set_ack(hdr, ack); |
| 1172 | msg_set_bcast_ack(hdr, bc_ack); |
Jon Paul Maloy | d999297 | 2015-07-16 16:54:31 -0400 | [diff] [blame] | 1173 | _skb->priority = TC_PRIO_CONTROL; |
| 1174 | __skb_queue_tail(xmitq, _skb); |
Jon Paul Maloy | d999297 | 2015-07-16 16:54:31 -0400 | [diff] [blame] | 1175 | l->stats.retransmitted++; |
Tuong Lien | 7120423 | 2019-08-15 10:24:08 +0700 | [diff] [blame] | 1176 | |
| 1177 | /* Increase actual retrans counter & mark first time */ |
| 1178 | if (!TIPC_SKB_CB(skb)->retr_cnt++) |
| 1179 | TIPC_SKB_CB(skb)->retr_stamp = jiffies; |
Jon Paul Maloy | d999297 | 2015-07-16 16:54:31 -0400 | [diff] [blame] | 1180 | } |
| 1181 | return 0; |
| 1182 | } |
| 1183 | |
Jon Paul Maloy | c637c10 | 2015-02-05 08:36:41 -0500 | [diff] [blame] | 1184 | /* tipc_data_input - deliver data and name distr msgs to upper layer |
Erik Hugne | 7ae934b | 2014-07-01 10:22:40 +0200 | [diff] [blame] | 1185 | * |
Jon Paul Maloy | c637c10 | 2015-02-05 08:36:41 -0500 | [diff] [blame] | 1186 | * Consumes buffer if message is of right type |
Erik Hugne | 7ae934b | 2014-07-01 10:22:40 +0200 | [diff] [blame] | 1187 | * Node lock must be held |
| 1188 | */ |
Jon Paul Maloy | 5266698 | 2015-10-22 08:51:41 -0400 | [diff] [blame] | 1189 | static bool tipc_data_input(struct tipc_link *l, struct sk_buff *skb, |
Jon Paul Maloy | 9073fb8 | 2015-07-30 18:24:25 -0400 | [diff] [blame] | 1190 | struct sk_buff_head *inputq) |
Erik Hugne | 7ae934b | 2014-07-01 10:22:40 +0200 | [diff] [blame] | 1191 | { |
Jon Maloy | 399574d | 2017-10-13 11:04:32 +0200 | [diff] [blame] | 1192 | struct sk_buff_head *mc_inputq = l->bc_rcvlink->inputq; |
Jon Paul Maloy | a853e4c | 2017-01-18 13:50:52 -0500 | [diff] [blame] | 1193 | struct tipc_msg *hdr = buf_msg(skb); |
| 1194 | |
| 1195 | switch (msg_user(hdr)) { |
Erik Hugne | 7ae934b | 2014-07-01 10:22:40 +0200 | [diff] [blame] | 1196 | case TIPC_LOW_IMPORTANCE: |
| 1197 | case TIPC_MEDIUM_IMPORTANCE: |
| 1198 | case TIPC_HIGH_IMPORTANCE: |
| 1199 | case TIPC_CRITICAL_IMPORTANCE: |
Jon Maloy | 2f48771 | 2017-10-13 11:04:31 +0200 | [diff] [blame] | 1200 | if (unlikely(msg_in_group(hdr) || msg_mcast(hdr))) { |
Jon Maloy | 399574d | 2017-10-13 11:04:32 +0200 | [diff] [blame] | 1201 | skb_queue_tail(mc_inputq, skb); |
Jon Paul Maloy | a853e4c | 2017-01-18 13:50:52 -0500 | [diff] [blame] | 1202 | return true; |
| 1203 | } |
Gustavo A. R. Silva | f79e336 | 2019-01-23 01:09:31 -0600 | [diff] [blame] | 1204 | /* fall through */ |
Jon Maloy | 2f48771 | 2017-10-13 11:04:31 +0200 | [diff] [blame] | 1205 | case CONN_MANAGER: |
Jon Maloy | 36c0a9d | 2017-10-16 16:04:51 +0200 | [diff] [blame] | 1206 | skb_queue_tail(inputq, skb); |
Jon Paul Maloy | c637c10 | 2015-02-05 08:36:41 -0500 | [diff] [blame] | 1207 | return true; |
Jon Maloy | 399574d | 2017-10-13 11:04:32 +0200 | [diff] [blame] | 1208 | case GROUP_PROTOCOL: |
| 1209 | skb_queue_tail(mc_inputq, skb); |
| 1210 | return true; |
Erik Hugne | 7ae934b | 2014-07-01 10:22:40 +0200 | [diff] [blame] | 1211 | case NAME_DISTRIBUTOR: |
Jon Paul Maloy | 5266698 | 2015-10-22 08:51:41 -0400 | [diff] [blame] | 1212 | l->bc_rcvlink->state = LINK_ESTABLISHED; |
| 1213 | skb_queue_tail(l->namedq, skb); |
Jon Paul Maloy | c637c10 | 2015-02-05 08:36:41 -0500 | [diff] [blame] | 1214 | return true; |
Erik Hugne | 7ae934b | 2014-07-01 10:22:40 +0200 | [diff] [blame] | 1215 | case MSG_BUNDLER: |
Jon Paul Maloy | dff29b1 | 2015-04-02 09:33:01 -0400 | [diff] [blame] | 1216 | case TUNNEL_PROTOCOL: |
Jon Paul Maloy | c637c10 | 2015-02-05 08:36:41 -0500 | [diff] [blame] | 1217 | case MSG_FRAGMENTER: |
| 1218 | case BCAST_PROTOCOL: |
| 1219 | return false; |
| 1220 | default: |
| 1221 | pr_warn("Dropping received illegal msg type\n"); |
| 1222 | kfree_skb(skb); |
Hoang Le | 7384b53 | 2019-02-11 09:18:28 +0700 | [diff] [blame] | 1223 | return true; |
Jon Paul Maloy | c637c10 | 2015-02-05 08:36:41 -0500 | [diff] [blame] | 1224 | }; |
| 1225 | } |
| 1226 | |
| 1227 | /* tipc_link_input - process packet that has passed link protocol check |
| 1228 | * |
| 1229 | * Consumes buffer |
Jon Paul Maloy | c637c10 | 2015-02-05 08:36:41 -0500 | [diff] [blame] | 1230 | */ |
Jon Paul Maloy | 9073fb8 | 2015-07-30 18:24:25 -0400 | [diff] [blame] | 1231 | static int tipc_link_input(struct tipc_link *l, struct sk_buff *skb, |
Tuong Lien | 58ee86b | 2019-04-04 11:09:53 +0700 | [diff] [blame] | 1232 | struct sk_buff_head *inputq, |
| 1233 | struct sk_buff **reasm_skb) |
Jon Paul Maloy | c637c10 | 2015-02-05 08:36:41 -0500 | [diff] [blame] | 1234 | { |
Jon Paul Maloy | 6e49815 | 2015-07-30 18:24:19 -0400 | [diff] [blame] | 1235 | struct tipc_msg *hdr = buf_msg(skb); |
Jon Paul Maloy | c637c10 | 2015-02-05 08:36:41 -0500 | [diff] [blame] | 1236 | struct sk_buff *iskb; |
Jon Paul Maloy | 9945e80 | 2015-10-15 14:52:40 -0400 | [diff] [blame] | 1237 | struct sk_buff_head tmpq; |
Jon Paul Maloy | 6e49815 | 2015-07-30 18:24:19 -0400 | [diff] [blame] | 1238 | int usr = msg_user(hdr); |
Jon Paul Maloy | 6e49815 | 2015-07-30 18:24:19 -0400 | [diff] [blame] | 1239 | int pos = 0; |
Jon Paul Maloy | c637c10 | 2015-02-05 08:36:41 -0500 | [diff] [blame] | 1240 | |
Jon Paul Maloy | 6e49815 | 2015-07-30 18:24:19 -0400 | [diff] [blame] | 1241 | if (usr == MSG_BUNDLER) { |
Jon Paul Maloy | 9945e80 | 2015-10-15 14:52:40 -0400 | [diff] [blame] | 1242 | skb_queue_head_init(&tmpq); |
Jon Paul Maloy | 6e49815 | 2015-07-30 18:24:19 -0400 | [diff] [blame] | 1243 | l->stats.recv_bundles++; |
| 1244 | l->stats.recv_bundled += msg_msgcnt(hdr); |
Jon Paul Maloy | c637c10 | 2015-02-05 08:36:41 -0500 | [diff] [blame] | 1245 | while (tipc_msg_extract(skb, &iskb, &pos)) |
Jon Paul Maloy | 9945e80 | 2015-10-15 14:52:40 -0400 | [diff] [blame] | 1246 | tipc_data_input(l, iskb, &tmpq); |
| 1247 | tipc_skb_queue_splice_tail(&tmpq, inputq); |
Jon Paul Maloy | 662921c | 2015-07-30 18:24:21 -0400 | [diff] [blame] | 1248 | return 0; |
Jon Paul Maloy | 6e49815 | 2015-07-30 18:24:19 -0400 | [diff] [blame] | 1249 | } else if (usr == MSG_FRAGMENTER) { |
| 1250 | l->stats.recv_fragments++; |
| 1251 | if (tipc_buf_append(reasm_skb, &skb)) { |
| 1252 | l->stats.recv_fragmented++; |
Jon Paul Maloy | 9073fb8 | 2015-07-30 18:24:25 -0400 | [diff] [blame] | 1253 | tipc_data_input(l, skb, inputq); |
Jon Paul Maloy | 5266698 | 2015-10-22 08:51:41 -0400 | [diff] [blame] | 1254 | } else if (!*reasm_skb && !link_is_bc_rcvlink(l)) { |
| 1255 | pr_warn_ratelimited("Unable to build fragment list\n"); |
Jon Paul Maloy | 662921c | 2015-07-30 18:24:21 -0400 | [diff] [blame] | 1256 | return tipc_link_fsm_evt(l, LINK_FAILURE_EVT); |
Jon Paul Maloy | c637c10 | 2015-02-05 08:36:41 -0500 | [diff] [blame] | 1257 | } |
Jon Paul Maloy | 662921c | 2015-07-30 18:24:21 -0400 | [diff] [blame] | 1258 | return 0; |
Jon Paul Maloy | 6e49815 | 2015-07-30 18:24:19 -0400 | [diff] [blame] | 1259 | } else if (usr == BCAST_PROTOCOL) { |
Jon Paul Maloy | c72fa87 | 2015-10-22 08:51:46 -0400 | [diff] [blame] | 1260 | tipc_bcast_lock(l->net); |
Jon Paul Maloy | 5266698 | 2015-10-22 08:51:41 -0400 | [diff] [blame] | 1261 | tipc_link_bc_init_rcv(l->bc_rcvlink, hdr); |
Jon Paul Maloy | c72fa87 | 2015-10-22 08:51:46 -0400 | [diff] [blame] | 1262 | tipc_bcast_unlock(l->net); |
Jon Paul Maloy | 6e49815 | 2015-07-30 18:24:19 -0400 | [diff] [blame] | 1263 | } |
Tuong Lien | 58ee86b | 2019-04-04 11:09:53 +0700 | [diff] [blame] | 1264 | |
Jon Paul Maloy | 6e49815 | 2015-07-30 18:24:19 -0400 | [diff] [blame] | 1265 | kfree_skb(skb); |
Jon Paul Maloy | 662921c | 2015-07-30 18:24:21 -0400 | [diff] [blame] | 1266 | return 0; |
Erik Hugne | 7ae934b | 2014-07-01 10:22:40 +0200 | [diff] [blame] | 1267 | } |
| 1268 | |
Tuong Lien | 58ee86b | 2019-04-04 11:09:53 +0700 | [diff] [blame] | 1269 | /* tipc_link_tnl_rcv() - receive TUNNEL_PROTOCOL message, drop or process the |
| 1270 | * inner message along with the ones in the old link's |
| 1271 | * deferdq |
| 1272 | * @l: tunnel link |
| 1273 | * @skb: TUNNEL_PROTOCOL message |
| 1274 | * @inputq: queue to put messages ready for delivery |
| 1275 | */ |
| 1276 | static int tipc_link_tnl_rcv(struct tipc_link *l, struct sk_buff *skb, |
| 1277 | struct sk_buff_head *inputq) |
| 1278 | { |
| 1279 | struct sk_buff **reasm_skb = &l->failover_reasm_skb; |
Tuong Lien | 2320bcd | 2019-07-24 08:56:12 +0700 | [diff] [blame] | 1280 | struct sk_buff **reasm_tnlmsg = &l->reasm_tnlmsg; |
Tuong Lien | 58ee86b | 2019-04-04 11:09:53 +0700 | [diff] [blame] | 1281 | struct sk_buff_head *fdefq = &l->failover_deferdq; |
| 1282 | struct tipc_msg *hdr = buf_msg(skb); |
| 1283 | struct sk_buff *iskb; |
| 1284 | int ipos = 0; |
| 1285 | int rc = 0; |
| 1286 | u16 seqno; |
| 1287 | |
Tuong Lien | 2320bcd | 2019-07-24 08:56:12 +0700 | [diff] [blame] | 1288 | if (msg_type(hdr) == SYNCH_MSG) { |
| 1289 | kfree_skb(skb); |
| 1290 | return 0; |
| 1291 | } |
Tuong Lien | 58ee86b | 2019-04-04 11:09:53 +0700 | [diff] [blame] | 1292 | |
Tuong Lien | 2320bcd | 2019-07-24 08:56:12 +0700 | [diff] [blame] | 1293 | /* Not a fragment? */ |
| 1294 | if (likely(!msg_nof_fragms(hdr))) { |
| 1295 | if (unlikely(!tipc_msg_extract(skb, &iskb, &ipos))) { |
| 1296 | pr_warn_ratelimited("Unable to extract msg, defq: %d\n", |
| 1297 | skb_queue_len(fdefq)); |
| 1298 | return 0; |
| 1299 | } |
| 1300 | kfree_skb(skb); |
| 1301 | } else { |
| 1302 | /* Set fragment type for buf_append */ |
| 1303 | if (msg_fragm_no(hdr) == 1) |
| 1304 | msg_set_type(hdr, FIRST_FRAGMENT); |
| 1305 | else if (msg_fragm_no(hdr) < msg_nof_fragms(hdr)) |
| 1306 | msg_set_type(hdr, FRAGMENT); |
| 1307 | else |
| 1308 | msg_set_type(hdr, LAST_FRAGMENT); |
| 1309 | |
| 1310 | if (!tipc_buf_append(reasm_tnlmsg, &skb)) { |
| 1311 | /* Successful but non-complete reassembly? */ |
| 1312 | if (*reasm_tnlmsg || link_is_bc_rcvlink(l)) |
| 1313 | return 0; |
| 1314 | pr_warn_ratelimited("Unable to reassemble tunnel msg\n"); |
| 1315 | return tipc_link_fsm_evt(l, LINK_FAILURE_EVT); |
| 1316 | } |
| 1317 | iskb = skb; |
Tuong Lien | 58ee86b | 2019-04-04 11:09:53 +0700 | [diff] [blame] | 1318 | } |
| 1319 | |
| 1320 | do { |
| 1321 | seqno = buf_seqno(iskb); |
Tuong Lien | 58ee86b | 2019-04-04 11:09:53 +0700 | [diff] [blame] | 1322 | if (unlikely(less(seqno, l->drop_point))) { |
| 1323 | kfree_skb(iskb); |
| 1324 | continue; |
| 1325 | } |
Tuong Lien | 58ee86b | 2019-04-04 11:09:53 +0700 | [diff] [blame] | 1326 | if (unlikely(seqno != l->drop_point)) { |
| 1327 | __tipc_skb_queue_sorted(fdefq, seqno, iskb); |
| 1328 | continue; |
| 1329 | } |
| 1330 | |
| 1331 | l->drop_point++; |
Tuong Lien | 58ee86b | 2019-04-04 11:09:53 +0700 | [diff] [blame] | 1332 | if (!tipc_data_input(l, iskb, inputq)) |
| 1333 | rc |= tipc_link_input(l, iskb, inputq, reasm_skb); |
| 1334 | if (unlikely(rc)) |
| 1335 | break; |
| 1336 | } while ((iskb = __tipc_skb_dequeue(fdefq, l->drop_point))); |
| 1337 | |
Tuong Lien | 58ee86b | 2019-04-04 11:09:53 +0700 | [diff] [blame] | 1338 | return rc; |
| 1339 | } |
| 1340 | |
Jon Paul Maloy | d999297 | 2015-07-16 16:54:31 -0400 | [diff] [blame] | 1341 | static bool tipc_link_release_pkts(struct tipc_link *l, u16 acked) |
| 1342 | { |
| 1343 | bool released = false; |
| 1344 | struct sk_buff *skb, *tmp; |
| 1345 | |
| 1346 | skb_queue_walk_safe(&l->transmq, skb, tmp) { |
| 1347 | if (more(buf_seqno(skb), acked)) |
| 1348 | break; |
| 1349 | __skb_unlink(skb, &l->transmq); |
| 1350 | kfree_skb(skb); |
| 1351 | released = true; |
| 1352 | } |
| 1353 | return released; |
| 1354 | } |
| 1355 | |
Tuong Lien | 9195948 | 2019-04-04 11:09:51 +0700 | [diff] [blame] | 1356 | /* tipc_build_gap_ack_blks - build Gap ACK blocks |
| 1357 | * @l: tipc link that data have come with gaps in sequence if any |
| 1358 | * @data: data buffer to store the Gap ACK blocks after built |
| 1359 | * |
| 1360 | * returns the actual allocated memory size |
| 1361 | */ |
| 1362 | static u16 tipc_build_gap_ack_blks(struct tipc_link *l, void *data) |
| 1363 | { |
| 1364 | struct sk_buff *skb = skb_peek(&l->deferdq); |
| 1365 | struct tipc_gap_ack_blks *ga = data; |
| 1366 | u16 len, expect, seqno = 0; |
| 1367 | u8 n = 0; |
| 1368 | |
| 1369 | if (!skb) |
| 1370 | goto exit; |
| 1371 | |
| 1372 | expect = buf_seqno(skb); |
| 1373 | skb_queue_walk(&l->deferdq, skb) { |
| 1374 | seqno = buf_seqno(skb); |
| 1375 | if (unlikely(more(seqno, expect))) { |
| 1376 | ga->gacks[n].ack = htons(expect - 1); |
| 1377 | ga->gacks[n].gap = htons(seqno - expect); |
| 1378 | if (++n >= MAX_GAP_ACK_BLKS) { |
| 1379 | pr_info_ratelimited("Too few Gap ACK blocks!\n"); |
| 1380 | goto exit; |
| 1381 | } |
| 1382 | } else if (unlikely(less(seqno, expect))) { |
| 1383 | pr_warn("Unexpected skb in deferdq!\n"); |
| 1384 | continue; |
| 1385 | } |
| 1386 | expect = seqno + 1; |
| 1387 | } |
| 1388 | |
| 1389 | /* last block */ |
| 1390 | ga->gacks[n].ack = htons(seqno); |
| 1391 | ga->gacks[n].gap = 0; |
| 1392 | n++; |
| 1393 | |
| 1394 | exit: |
| 1395 | len = tipc_gap_ack_blks_sz(n); |
| 1396 | ga->len = htons(len); |
| 1397 | ga->gack_cnt = n; |
| 1398 | return len; |
| 1399 | } |
| 1400 | |
| 1401 | /* tipc_link_advance_transmq - advance TIPC link transmq queue by releasing |
| 1402 | * acked packets, also doing retransmissions if |
| 1403 | * gaps found |
| 1404 | * @l: tipc link with transmq queue to be advanced |
| 1405 | * @acked: seqno of last packet acked by peer without any gaps before |
| 1406 | * @gap: # of gap packets |
| 1407 | * @ga: buffer pointer to Gap ACK blocks from peer |
| 1408 | * @xmitq: queue for accumulating the retransmitted packets if any |
Tuong Lien | 6a6b5c8 | 2019-06-17 12:15:42 +0700 | [diff] [blame] | 1409 | * |
| 1410 | * In case of a repeated retransmit failures, the call will return shortly |
| 1411 | * with a returned code (e.g. TIPC_LINK_DOWN_EVT) |
Tuong Lien | 9195948 | 2019-04-04 11:09:51 +0700 | [diff] [blame] | 1412 | */ |
Tuong Lien | 6a6b5c8 | 2019-06-17 12:15:42 +0700 | [diff] [blame] | 1413 | static int tipc_link_advance_transmq(struct tipc_link *l, u16 acked, u16 gap, |
| 1414 | struct tipc_gap_ack_blks *ga, |
| 1415 | struct sk_buff_head *xmitq) |
Tuong Lien | 9195948 | 2019-04-04 11:09:51 +0700 | [diff] [blame] | 1416 | { |
| 1417 | struct sk_buff *skb, *_skb, *tmp; |
| 1418 | struct tipc_msg *hdr; |
| 1419 | u16 bc_ack = l->bc_rcvlink->rcv_nxt - 1; |
| 1420 | u16 ack = l->rcv_nxt - 1; |
Tuong Lien | 7120423 | 2019-08-15 10:24:08 +0700 | [diff] [blame] | 1421 | bool passed = false; |
Tuong Lien | 6a6b5c8 | 2019-06-17 12:15:42 +0700 | [diff] [blame] | 1422 | u16 seqno, n = 0; |
| 1423 | int rc = 0; |
| 1424 | |
Tuong Lien | 9195948 | 2019-04-04 11:09:51 +0700 | [diff] [blame] | 1425 | skb_queue_walk_safe(&l->transmq, skb, tmp) { |
| 1426 | seqno = buf_seqno(skb); |
| 1427 | |
| 1428 | next_gap_ack: |
| 1429 | if (less_eq(seqno, acked)) { |
| 1430 | /* release skb */ |
| 1431 | __skb_unlink(skb, &l->transmq); |
| 1432 | kfree_skb(skb); |
| 1433 | } else if (less_eq(seqno, acked + gap)) { |
Tuong Lien | 7120423 | 2019-08-15 10:24:08 +0700 | [diff] [blame] | 1434 | /* First, check if repeated retrans failures occurs? */ |
| 1435 | if (!passed && link_retransmit_failure(l, l, &rc)) |
| 1436 | return rc; |
| 1437 | passed = true; |
| 1438 | |
| 1439 | /* retransmit skb if unrestricted*/ |
Tuong Lien | 382f598 | 2019-04-04 11:09:52 +0700 | [diff] [blame] | 1440 | if (time_before(jiffies, TIPC_SKB_CB(skb)->nxt_retr)) |
| 1441 | continue; |
| 1442 | TIPC_SKB_CB(skb)->nxt_retr = TIPC_UC_RETR_TIME; |
Tuong Lien | fc1b6d6 | 2019-11-08 12:05:11 +0700 | [diff] [blame] | 1443 | _skb = pskb_copy(skb, GFP_ATOMIC); |
Tuong Lien | 9195948 | 2019-04-04 11:09:51 +0700 | [diff] [blame] | 1444 | if (!_skb) |
| 1445 | continue; |
| 1446 | hdr = buf_msg(_skb); |
| 1447 | msg_set_ack(hdr, ack); |
| 1448 | msg_set_bcast_ack(hdr, bc_ack); |
| 1449 | _skb->priority = TC_PRIO_CONTROL; |
| 1450 | __skb_queue_tail(xmitq, _skb); |
| 1451 | l->stats.retransmitted++; |
Tuong Lien | 7120423 | 2019-08-15 10:24:08 +0700 | [diff] [blame] | 1452 | |
| 1453 | /* Increase actual retrans counter & mark first time */ |
| 1454 | if (!TIPC_SKB_CB(skb)->retr_cnt++) |
| 1455 | TIPC_SKB_CB(skb)->retr_stamp = jiffies; |
Tuong Lien | 9195948 | 2019-04-04 11:09:51 +0700 | [diff] [blame] | 1456 | } else { |
| 1457 | /* retry with Gap ACK blocks if any */ |
| 1458 | if (!ga || n >= ga->gack_cnt) |
| 1459 | break; |
| 1460 | acked = ntohs(ga->gacks[n].ack); |
| 1461 | gap = ntohs(ga->gacks[n].gap); |
| 1462 | n++; |
| 1463 | goto next_gap_ack; |
| 1464 | } |
| 1465 | } |
Tuong Lien | 6a6b5c8 | 2019-06-17 12:15:42 +0700 | [diff] [blame] | 1466 | |
| 1467 | return 0; |
Tuong Lien | 9195948 | 2019-04-04 11:09:51 +0700 | [diff] [blame] | 1468 | } |
| 1469 | |
Jon Paul Maloy | 34b9cd6 | 2016-04-15 13:33:07 -0400 | [diff] [blame] | 1470 | /* tipc_link_build_state_msg: prepare link state message for transmission |
Jon Paul Maloy | 5266698 | 2015-10-22 08:51:41 -0400 | [diff] [blame] | 1471 | * |
| 1472 | * Note that sending of broadcast ack is coordinated among nodes, to reduce |
| 1473 | * risk of ack storms towards the sender |
Jon Paul Maloy | f9aa358 | 2015-10-15 14:52:41 -0400 | [diff] [blame] | 1474 | */ |
Jon Paul Maloy | 34b9cd6 | 2016-04-15 13:33:07 -0400 | [diff] [blame] | 1475 | int tipc_link_build_state_msg(struct tipc_link *l, struct sk_buff_head *xmitq) |
Jon Paul Maloy | f9aa358 | 2015-10-15 14:52:41 -0400 | [diff] [blame] | 1476 | { |
Jon Paul Maloy | 5266698 | 2015-10-22 08:51:41 -0400 | [diff] [blame] | 1477 | if (!l) |
| 1478 | return 0; |
| 1479 | |
| 1480 | /* Broadcast ACK must be sent via a unicast link => defer to caller */ |
| 1481 | if (link_is_bc_rcvlink(l)) { |
Jon Paul Maloy | e74a386 | 2016-03-03 14:23:21 -0500 | [diff] [blame] | 1482 | if (((l->rcv_nxt ^ tipc_own_addr(l->net)) & 0xf) != 0xf) |
Jon Paul Maloy | 5266698 | 2015-10-22 08:51:41 -0400 | [diff] [blame] | 1483 | return 0; |
| 1484 | l->rcv_unacked = 0; |
Jon Paul Maloy | 02d11ca | 2016-09-01 13:52:49 -0400 | [diff] [blame] | 1485 | |
| 1486 | /* Use snd_nxt to store peer's snd_nxt in broadcast rcv link */ |
| 1487 | l->snd_nxt = l->rcv_nxt; |
| 1488 | return TIPC_LINK_SND_STATE; |
Jon Paul Maloy | 5266698 | 2015-10-22 08:51:41 -0400 | [diff] [blame] | 1489 | } |
| 1490 | |
| 1491 | /* Unicast ACK */ |
Jon Paul Maloy | f9aa358 | 2015-10-15 14:52:41 -0400 | [diff] [blame] | 1492 | l->rcv_unacked = 0; |
| 1493 | l->stats.sent_acks++; |
Jon Maloy | 8d6e79d | 2017-11-08 09:59:26 +0100 | [diff] [blame] | 1494 | tipc_link_build_proto_msg(l, STATE_MSG, 0, 0, 0, 0, 0, xmitq); |
Jon Paul Maloy | 5266698 | 2015-10-22 08:51:41 -0400 | [diff] [blame] | 1495 | return 0; |
Jon Paul Maloy | f9aa358 | 2015-10-15 14:52:41 -0400 | [diff] [blame] | 1496 | } |
| 1497 | |
Jon Paul Maloy | 282b3a0 | 2015-10-15 14:52:45 -0400 | [diff] [blame] | 1498 | /* tipc_link_build_reset_msg: prepare link RESET or ACTIVATE message |
| 1499 | */ |
| 1500 | void tipc_link_build_reset_msg(struct tipc_link *l, struct sk_buff_head *xmitq) |
| 1501 | { |
| 1502 | int mtyp = RESET_MSG; |
Jon Paul Maloy | 634696b | 2016-04-15 13:33:03 -0400 | [diff] [blame] | 1503 | struct sk_buff *skb; |
Jon Paul Maloy | 282b3a0 | 2015-10-15 14:52:45 -0400 | [diff] [blame] | 1504 | |
| 1505 | if (l->state == LINK_ESTABLISHING) |
| 1506 | mtyp = ACTIVATE_MSG; |
| 1507 | |
Jon Maloy | 8d6e79d | 2017-11-08 09:59:26 +0100 | [diff] [blame] | 1508 | tipc_link_build_proto_msg(l, mtyp, 0, 0, 0, 0, 0, xmitq); |
Jon Paul Maloy | 634696b | 2016-04-15 13:33:03 -0400 | [diff] [blame] | 1509 | |
| 1510 | /* Inform peer that this endpoint is going down if applicable */ |
| 1511 | skb = skb_peek_tail(xmitq); |
| 1512 | if (skb && (l->state == LINK_RESET)) |
| 1513 | msg_set_peer_stopping(buf_msg(skb), 1); |
Jon Paul Maloy | 282b3a0 | 2015-10-15 14:52:45 -0400 | [diff] [blame] | 1514 | } |
| 1515 | |
Jon Paul Maloy | f9aa358 | 2015-10-15 14:52:41 -0400 | [diff] [blame] | 1516 | /* tipc_link_build_nack_msg: prepare link nack message for transmission |
Jon Paul Maloy | e0a05eb | 2016-09-01 13:52:51 -0400 | [diff] [blame] | 1517 | * Note that sending of broadcast NACK is coordinated among nodes, to |
| 1518 | * reduce the risk of NACK storms towards the sender |
Jon Paul Maloy | f9aa358 | 2015-10-15 14:52:41 -0400 | [diff] [blame] | 1519 | */ |
Jon Paul Maloy | e0a05eb | 2016-09-01 13:52:51 -0400 | [diff] [blame] | 1520 | static int tipc_link_build_nack_msg(struct tipc_link *l, |
| 1521 | struct sk_buff_head *xmitq) |
Jon Paul Maloy | f9aa358 | 2015-10-15 14:52:41 -0400 | [diff] [blame] | 1522 | { |
| 1523 | u32 def_cnt = ++l->stats.deferred_recv; |
Tuong Lien | 382f598 | 2019-04-04 11:09:52 +0700 | [diff] [blame] | 1524 | u32 defq_len = skb_queue_len(&l->deferdq); |
Jon Paul Maloy | e0a05eb | 2016-09-01 13:52:51 -0400 | [diff] [blame] | 1525 | int match1, match2; |
Jon Paul Maloy | f9aa358 | 2015-10-15 14:52:41 -0400 | [diff] [blame] | 1526 | |
Jon Paul Maloy | e0a05eb | 2016-09-01 13:52:51 -0400 | [diff] [blame] | 1527 | if (link_is_bc_rcvlink(l)) { |
| 1528 | match1 = def_cnt & 0xf; |
| 1529 | match2 = tipc_own_addr(l->net) & 0xf; |
| 1530 | if (match1 == match2) |
| 1531 | return TIPC_LINK_SND_STATE; |
| 1532 | return 0; |
| 1533 | } |
Jon Paul Maloy | 5266698 | 2015-10-22 08:51:41 -0400 | [diff] [blame] | 1534 | |
Tuong Lien | 382f598 | 2019-04-04 11:09:52 +0700 | [diff] [blame] | 1535 | if (defq_len >= 3 && !((defq_len - 3) % 16)) |
Jon Maloy | 8d6e79d | 2017-11-08 09:59:26 +0100 | [diff] [blame] | 1536 | tipc_link_build_proto_msg(l, STATE_MSG, 0, 0, 0, 0, 0, xmitq); |
Jon Paul Maloy | e0a05eb | 2016-09-01 13:52:51 -0400 | [diff] [blame] | 1537 | return 0; |
Jon Paul Maloy | f9aa358 | 2015-10-15 14:52:41 -0400 | [diff] [blame] | 1538 | } |
| 1539 | |
Jon Paul Maloy | d999297 | 2015-07-16 16:54:31 -0400 | [diff] [blame] | 1540 | /* tipc_link_rcv - process TIPC packets/messages arriving from off-node |
Jon Paul Maloy | f9aa358 | 2015-10-15 14:52:41 -0400 | [diff] [blame] | 1541 | * @l: the link that should handle the message |
Jon Paul Maloy | d999297 | 2015-07-16 16:54:31 -0400 | [diff] [blame] | 1542 | * @skb: TIPC packet |
| 1543 | * @xmitq: queue to place packets to be sent after this call |
| 1544 | */ |
| 1545 | int tipc_link_rcv(struct tipc_link *l, struct sk_buff *skb, |
| 1546 | struct sk_buff_head *xmitq) |
| 1547 | { |
Jon Paul Maloy | f9aa358 | 2015-10-15 14:52:41 -0400 | [diff] [blame] | 1548 | struct sk_buff_head *defq = &l->deferdq; |
Tuong Lien | 382f598 | 2019-04-04 11:09:52 +0700 | [diff] [blame] | 1549 | struct tipc_msg *hdr = buf_msg(skb); |
Jon Paul Maloy | 81204c4 | 2015-10-15 14:52:42 -0400 | [diff] [blame] | 1550 | u16 seqno, rcv_nxt, win_lim; |
Jon Paul Maloy | d999297 | 2015-07-16 16:54:31 -0400 | [diff] [blame] | 1551 | int rc = 0; |
| 1552 | |
Tuong Lien | 382f598 | 2019-04-04 11:09:52 +0700 | [diff] [blame] | 1553 | /* Verify and update link state */ |
| 1554 | if (unlikely(msg_user(hdr) == LINK_PROTOCOL)) |
| 1555 | return tipc_link_proto_rcv(l, skb, xmitq); |
| 1556 | |
| 1557 | /* Don't send probe at next timeout expiration */ |
| 1558 | l->silent_intv_cnt = 0; |
| 1559 | |
Jon Paul Maloy | f9aa358 | 2015-10-15 14:52:41 -0400 | [diff] [blame] | 1560 | do { |
Jon Paul Maloy | d999297 | 2015-07-16 16:54:31 -0400 | [diff] [blame] | 1561 | hdr = buf_msg(skb); |
Jon Paul Maloy | f9aa358 | 2015-10-15 14:52:41 -0400 | [diff] [blame] | 1562 | seqno = msg_seqno(hdr); |
| 1563 | rcv_nxt = l->rcv_nxt; |
Jon Paul Maloy | 81204c4 | 2015-10-15 14:52:42 -0400 | [diff] [blame] | 1564 | win_lim = rcv_nxt + TIPC_MAX_LINK_WIN; |
Jon Paul Maloy | d999297 | 2015-07-16 16:54:31 -0400 | [diff] [blame] | 1565 | |
Jon Paul Maloy | 662921c | 2015-07-30 18:24:21 -0400 | [diff] [blame] | 1566 | if (unlikely(!link_is_up(l))) { |
Jon Paul Maloy | 73f646c | 2015-10-15 14:52:44 -0400 | [diff] [blame] | 1567 | if (l->state == LINK_ESTABLISHING) |
| 1568 | rc = TIPC_LINK_UP_EVT; |
| 1569 | goto drop; |
Jon Paul Maloy | d999297 | 2015-07-16 16:54:31 -0400 | [diff] [blame] | 1570 | } |
| 1571 | |
Jon Paul Maloy | 81204c4 | 2015-10-15 14:52:42 -0400 | [diff] [blame] | 1572 | /* Drop if outside receive window */ |
| 1573 | if (unlikely(less(seqno, rcv_nxt) || more(seqno, win_lim))) { |
| 1574 | l->stats.duplicates++; |
| 1575 | goto drop; |
| 1576 | } |
| 1577 | |
Jon Paul Maloy | d999297 | 2015-07-16 16:54:31 -0400 | [diff] [blame] | 1578 | /* Forward queues and wake up waiting users */ |
| 1579 | if (likely(tipc_link_release_pkts(l, msg_ack(hdr)))) { |
| 1580 | tipc_link_advance_backlog(l, xmitq); |
| 1581 | if (unlikely(!skb_queue_empty(&l->wakeupq))) |
| 1582 | link_prepare_wakeup(l); |
| 1583 | } |
| 1584 | |
Jon Paul Maloy | 81204c4 | 2015-10-15 14:52:42 -0400 | [diff] [blame] | 1585 | /* Defer delivery if sequence gap */ |
| 1586 | if (unlikely(seqno != rcv_nxt)) { |
Jon Paul Maloy | 8306f99 | 2015-10-15 14:52:43 -0400 | [diff] [blame] | 1587 | __tipc_skb_queue_sorted(defq, seqno, skb); |
Jon Paul Maloy | e0a05eb | 2016-09-01 13:52:51 -0400 | [diff] [blame] | 1588 | rc |= tipc_link_build_nack_msg(l, xmitq); |
Jon Paul Maloy | f9aa358 | 2015-10-15 14:52:41 -0400 | [diff] [blame] | 1589 | break; |
Jon Paul Maloy | d999297 | 2015-07-16 16:54:31 -0400 | [diff] [blame] | 1590 | } |
| 1591 | |
Jon Paul Maloy | 81204c4 | 2015-10-15 14:52:42 -0400 | [diff] [blame] | 1592 | /* Deliver packet */ |
Jon Paul Maloy | d999297 | 2015-07-16 16:54:31 -0400 | [diff] [blame] | 1593 | l->rcv_nxt++; |
Jon Paul Maloy | 9590112 | 2016-11-25 10:35:02 -0500 | [diff] [blame] | 1594 | l->stats.recv_pkts++; |
Tuong Lien | 58ee86b | 2019-04-04 11:09:53 +0700 | [diff] [blame] | 1595 | |
| 1596 | if (unlikely(msg_user(hdr) == TUNNEL_PROTOCOL)) |
| 1597 | rc |= tipc_link_tnl_rcv(l, skb, l->inputq); |
| 1598 | else if (!tipc_data_input(l, skb, l->inputq)) |
| 1599 | rc |= tipc_link_input(l, skb, l->inputq, &l->reasm_buf); |
Jon Paul Maloy | f9aa358 | 2015-10-15 14:52:41 -0400 | [diff] [blame] | 1600 | if (unlikely(++l->rcv_unacked >= TIPC_MIN_LINK_WIN)) |
Jon Paul Maloy | 34b9cd6 | 2016-04-15 13:33:07 -0400 | [diff] [blame] | 1601 | rc |= tipc_link_build_state_msg(l, xmitq); |
Jon Paul Maloy | 02d11ca | 2016-09-01 13:52:49 -0400 | [diff] [blame] | 1602 | if (unlikely(rc & ~TIPC_LINK_SND_STATE)) |
Jon Paul Maloy | 5266698 | 2015-10-22 08:51:41 -0400 | [diff] [blame] | 1603 | break; |
Tuong Lien | 382f598 | 2019-04-04 11:09:52 +0700 | [diff] [blame] | 1604 | } while ((skb = __tipc_skb_dequeue(defq, l->rcv_nxt))); |
Jon Paul Maloy | f9aa358 | 2015-10-15 14:52:41 -0400 | [diff] [blame] | 1605 | |
| 1606 | return rc; |
| 1607 | drop: |
| 1608 | kfree_skb(skb); |
Jon Paul Maloy | d999297 | 2015-07-16 16:54:31 -0400 | [diff] [blame] | 1609 | return rc; |
| 1610 | } |
| 1611 | |
Jon Paul Maloy | 426cc2b | 2015-07-16 16:54:26 -0400 | [diff] [blame] | 1612 | static void tipc_link_build_proto_msg(struct tipc_link *l, int mtyp, bool probe, |
Jon Maloy | 8d6e79d | 2017-11-08 09:59:26 +0100 | [diff] [blame] | 1613 | bool probe_reply, u16 rcvgap, |
| 1614 | int tolerance, int priority, |
Jon Paul Maloy | 426cc2b | 2015-07-16 16:54:26 -0400 | [diff] [blame] | 1615 | struct sk_buff_head *xmitq) |
| 1616 | { |
Jon Paul Maloy | 02d11ca | 2016-09-01 13:52:49 -0400 | [diff] [blame] | 1617 | struct tipc_link *bcl = l->bc_rcvlink; |
Jon Paul Maloy | e74a386 | 2016-03-03 14:23:21 -0500 | [diff] [blame] | 1618 | struct sk_buff *skb; |
| 1619 | struct tipc_msg *hdr; |
| 1620 | struct sk_buff_head *dfq = &l->deferdq; |
Jon Paul Maloy | 02d11ca | 2016-09-01 13:52:49 -0400 | [diff] [blame] | 1621 | bool node_up = link_is_up(bcl); |
Jon Paul Maloy | 35c55c9 | 2016-06-13 20:46:22 -0400 | [diff] [blame] | 1622 | struct tipc_mon_state *mstate = &l->mon_state; |
| 1623 | int dlen = 0; |
| 1624 | void *data; |
Tuong Lien | 9195948 | 2019-04-04 11:09:51 +0700 | [diff] [blame] | 1625 | u16 glen = 0; |
Jon Paul Maloy | 426cc2b | 2015-07-16 16:54:26 -0400 | [diff] [blame] | 1626 | |
| 1627 | /* Don't send protocol message during reset or link failover */ |
Jon Paul Maloy | 662921c | 2015-07-30 18:24:21 -0400 | [diff] [blame] | 1628 | if (tipc_link_is_blocked(l)) |
Jon Paul Maloy | 426cc2b | 2015-07-16 16:54:26 -0400 | [diff] [blame] | 1629 | return; |
| 1630 | |
Jon Paul Maloy | e74a386 | 2016-03-03 14:23:21 -0500 | [diff] [blame] | 1631 | if (!tipc_link_is_up(l) && (mtyp == STATE_MSG)) |
| 1632 | return; |
| 1633 | |
| 1634 | if (!skb_queue_empty(dfq)) |
| 1635 | rcvgap = buf_seqno(skb_peek(dfq)) - l->rcv_nxt; |
| 1636 | |
| 1637 | skb = tipc_msg_create(LINK_PROTOCOL, mtyp, INT_H_SIZE, |
Tuong Lien | 9195948 | 2019-04-04 11:09:51 +0700 | [diff] [blame] | 1638 | tipc_max_domain_size + MAX_GAP_ACK_BLKS_SZ, |
| 1639 | l->addr, tipc_own_addr(l->net), 0, 0, 0); |
Jon Paul Maloy | e74a386 | 2016-03-03 14:23:21 -0500 | [diff] [blame] | 1640 | if (!skb) |
| 1641 | return; |
| 1642 | |
| 1643 | hdr = buf_msg(skb); |
Jon Paul Maloy | 35c55c9 | 2016-06-13 20:46:22 -0400 | [diff] [blame] | 1644 | data = msg_data(hdr); |
Jon Paul Maloy | e74a386 | 2016-03-03 14:23:21 -0500 | [diff] [blame] | 1645 | msg_set_session(hdr, l->session); |
| 1646 | msg_set_bearer_id(hdr, l->bearer_id); |
Jon Paul Maloy | 426cc2b | 2015-07-16 16:54:26 -0400 | [diff] [blame] | 1647 | msg_set_net_plane(hdr, l->net_plane); |
Jon Paul Maloy | 5266698 | 2015-10-22 08:51:41 -0400 | [diff] [blame] | 1648 | msg_set_next_sent(hdr, l->snd_nxt); |
| 1649 | msg_set_ack(hdr, l->rcv_nxt - 1); |
Jon Paul Maloy | 02d11ca | 2016-09-01 13:52:49 -0400 | [diff] [blame] | 1650 | msg_set_bcast_ack(hdr, bcl->rcv_nxt - 1); |
Jon Paul Maloy | 06bd2b1 | 2016-10-27 18:51:55 -0400 | [diff] [blame] | 1651 | msg_set_bc_ack_invalid(hdr, !node_up); |
Jon Paul Maloy | 5266698 | 2015-10-22 08:51:41 -0400 | [diff] [blame] | 1652 | msg_set_last_bcast(hdr, l->bc_sndlink->snd_nxt - 1); |
Jon Paul Maloy | 426cc2b | 2015-07-16 16:54:26 -0400 | [diff] [blame] | 1653 | msg_set_link_tolerance(hdr, tolerance); |
| 1654 | msg_set_linkprio(hdr, priority); |
| 1655 | msg_set_redundant_link(hdr, node_up); |
| 1656 | msg_set_seq_gap(hdr, 0); |
Jon Paul Maloy | 5266698 | 2015-10-22 08:51:41 -0400 | [diff] [blame] | 1657 | msg_set_seqno(hdr, l->snd_nxt + U16_MAX / 2); |
Jon Paul Maloy | 426cc2b | 2015-07-16 16:54:26 -0400 | [diff] [blame] | 1658 | |
| 1659 | if (mtyp == STATE_MSG) { |
Jon Maloy | 9012de5 | 2018-07-10 01:07:35 +0200 | [diff] [blame] | 1660 | if (l->peer_caps & TIPC_LINK_PROTO_SEQNO) |
| 1661 | msg_set_seqno(hdr, l->snd_nxt_state++); |
Jon Paul Maloy | e74a386 | 2016-03-03 14:23:21 -0500 | [diff] [blame] | 1662 | msg_set_seq_gap(hdr, rcvgap); |
Jon Paul Maloy | 02d11ca | 2016-09-01 13:52:49 -0400 | [diff] [blame] | 1663 | msg_set_bc_gap(hdr, link_bc_rcv_gap(bcl)); |
Jon Paul Maloy | 426cc2b | 2015-07-16 16:54:26 -0400 | [diff] [blame] | 1664 | msg_set_probe(hdr, probe); |
Jon Maloy | 8d6e79d | 2017-11-08 09:59:26 +0100 | [diff] [blame] | 1665 | msg_set_is_keepalive(hdr, probe || probe_reply); |
Tuong Lien | 9195948 | 2019-04-04 11:09:51 +0700 | [diff] [blame] | 1666 | if (l->peer_caps & TIPC_GAP_ACK_BLOCK) |
| 1667 | glen = tipc_build_gap_ack_blks(l, data); |
| 1668 | tipc_mon_prep(l->net, data + glen, &dlen, mstate, l->bearer_id); |
| 1669 | msg_set_size(hdr, INT_H_SIZE + glen + dlen); |
| 1670 | skb_trim(skb, INT_H_SIZE + glen + dlen); |
Jon Paul Maloy | 426cc2b | 2015-07-16 16:54:26 -0400 | [diff] [blame] | 1671 | l->stats.sent_states++; |
Jon Paul Maloy | 5266698 | 2015-10-22 08:51:41 -0400 | [diff] [blame] | 1672 | l->rcv_unacked = 0; |
Jon Paul Maloy | 426cc2b | 2015-07-16 16:54:26 -0400 | [diff] [blame] | 1673 | } else { |
| 1674 | /* RESET_MSG or ACTIVATE_MSG */ |
Tuong Lien | 91986ee | 2019-02-11 13:29:43 +0700 | [diff] [blame] | 1675 | if (mtyp == ACTIVATE_MSG) { |
| 1676 | msg_set_dest_session_valid(hdr, 1); |
| 1677 | msg_set_dest_session(hdr, l->peer_session); |
| 1678 | } |
Jon Paul Maloy | 426cc2b | 2015-07-16 16:54:26 -0400 | [diff] [blame] | 1679 | msg_set_max_pkt(hdr, l->advertised_mtu); |
Jon Paul Maloy | 35c55c9 | 2016-06-13 20:46:22 -0400 | [diff] [blame] | 1680 | strcpy(data, l->if_name); |
| 1681 | msg_set_size(hdr, INT_H_SIZE + TIPC_MAX_IF_NAME); |
| 1682 | skb_trim(skb, INT_H_SIZE + TIPC_MAX_IF_NAME); |
Jon Paul Maloy | 426cc2b | 2015-07-16 16:54:26 -0400 | [diff] [blame] | 1683 | } |
Jon Paul Maloy | e74a386 | 2016-03-03 14:23:21 -0500 | [diff] [blame] | 1684 | if (probe) |
| 1685 | l->stats.sent_probes++; |
| 1686 | if (rcvgap) |
| 1687 | l->stats.sent_nacks++; |
Jon Paul Maloy | 426cc2b | 2015-07-16 16:54:26 -0400 | [diff] [blame] | 1688 | skb->priority = TC_PRIO_CONTROL; |
Jon Paul Maloy | 6e49815 | 2015-07-30 18:24:19 -0400 | [diff] [blame] | 1689 | __skb_queue_tail(xmitq, skb); |
Tuong Lien | 26574db | 2018-12-19 09:17:57 +0700 | [diff] [blame] | 1690 | trace_tipc_proto_build(skb, false, l->name); |
Jon Paul Maloy | 426cc2b | 2015-07-16 16:54:26 -0400 | [diff] [blame] | 1691 | } |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 1692 | |
LUU Duc Canh | c140eb1 | 2018-09-26 21:00:54 +0200 | [diff] [blame] | 1693 | void tipc_link_create_dummy_tnl_msg(struct tipc_link *l, |
| 1694 | struct sk_buff_head *xmitq) |
| 1695 | { |
| 1696 | u32 onode = tipc_own_addr(l->net); |
| 1697 | struct tipc_msg *hdr, *ihdr; |
| 1698 | struct sk_buff_head tnlq; |
| 1699 | struct sk_buff *skb; |
| 1700 | u32 dnode = l->addr; |
| 1701 | |
Jon Maloy | e654f9f | 2019-08-15 16:42:50 +0200 | [diff] [blame] | 1702 | __skb_queue_head_init(&tnlq); |
LUU Duc Canh | c140eb1 | 2018-09-26 21:00:54 +0200 | [diff] [blame] | 1703 | skb = tipc_msg_create(TUNNEL_PROTOCOL, FAILOVER_MSG, |
| 1704 | INT_H_SIZE, BASIC_H_SIZE, |
| 1705 | dnode, onode, 0, 0, 0); |
| 1706 | if (!skb) { |
| 1707 | pr_warn("%sunable to create tunnel packet\n", link_co_err); |
| 1708 | return; |
| 1709 | } |
| 1710 | |
| 1711 | hdr = buf_msg(skb); |
| 1712 | msg_set_msgcnt(hdr, 1); |
| 1713 | msg_set_bearer_id(hdr, l->peer_bearer_id); |
| 1714 | |
| 1715 | ihdr = (struct tipc_msg *)msg_data(hdr); |
| 1716 | tipc_msg_init(onode, ihdr, TIPC_LOW_IMPORTANCE, TIPC_DIRECT_MSG, |
| 1717 | BASIC_H_SIZE, dnode); |
| 1718 | msg_set_errcode(ihdr, TIPC_ERR_NO_PORT); |
| 1719 | __skb_queue_tail(&tnlq, skb); |
| 1720 | tipc_link_xmit(l, &tnlq, xmitq); |
| 1721 | } |
| 1722 | |
Jon Paul Maloy | 6e49815 | 2015-07-30 18:24:19 -0400 | [diff] [blame] | 1723 | /* tipc_link_tnl_prepare(): prepare and return a list of tunnel packets |
Jon Paul Maloy | f9aa358 | 2015-10-15 14:52:41 -0400 | [diff] [blame] | 1724 | * with contents of the link's transmit and backlog queues. |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 1725 | */ |
Jon Paul Maloy | 6e49815 | 2015-07-30 18:24:19 -0400 | [diff] [blame] | 1726 | void tipc_link_tnl_prepare(struct tipc_link *l, struct tipc_link *tnl, |
| 1727 | int mtyp, struct sk_buff_head *xmitq) |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 1728 | { |
Tuong Lien | 58ee86b | 2019-04-04 11:09:53 +0700 | [diff] [blame] | 1729 | struct sk_buff_head *fdefq = &tnl->failover_deferdq; |
Jon Paul Maloy | 6e49815 | 2015-07-30 18:24:19 -0400 | [diff] [blame] | 1730 | struct sk_buff *skb, *tnlskb; |
| 1731 | struct tipc_msg *hdr, tnlhdr; |
| 1732 | struct sk_buff_head *queue = &l->transmq; |
Tuong Lien | 2320bcd | 2019-07-24 08:56:12 +0700 | [diff] [blame] | 1733 | struct sk_buff_head tmpxq, tnlq, frags; |
Jon Paul Maloy | 6e49815 | 2015-07-30 18:24:19 -0400 | [diff] [blame] | 1734 | u16 pktlen, pktcnt, seqno = l->snd_nxt; |
Tuong Lien | 2320bcd | 2019-07-24 08:56:12 +0700 | [diff] [blame] | 1735 | bool pktcnt_need_update = false; |
Tuong Lien | 4929a93 | 2019-07-24 08:56:11 +0700 | [diff] [blame] | 1736 | u16 syncpt; |
Tuong Lien | 2320bcd | 2019-07-24 08:56:12 +0700 | [diff] [blame] | 1737 | int rc; |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 1738 | |
Jon Paul Maloy | 6e49815 | 2015-07-30 18:24:19 -0400 | [diff] [blame] | 1739 | if (!tnl) |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 1740 | return; |
Jon Paul Maloy | 6e49815 | 2015-07-30 18:24:19 -0400 | [diff] [blame] | 1741 | |
Jon Maloy | e654f9f | 2019-08-15 16:42:50 +0200 | [diff] [blame] | 1742 | __skb_queue_head_init(&tnlq); |
Tuong Lien | 4929a93 | 2019-07-24 08:56:11 +0700 | [diff] [blame] | 1743 | /* Link Synching: |
| 1744 | * From now on, send only one single ("dummy") SYNCH message |
| 1745 | * to peer. The SYNCH message does not contain any data, just |
| 1746 | * a header conveying the synch point to the peer. |
| 1747 | */ |
| 1748 | if (mtyp == SYNCH_MSG && (tnl->peer_caps & TIPC_TUNNEL_ENHANCED)) { |
| 1749 | tnlskb = tipc_msg_create(TUNNEL_PROTOCOL, SYNCH_MSG, |
| 1750 | INT_H_SIZE, 0, l->addr, |
| 1751 | tipc_own_addr(l->net), |
| 1752 | 0, 0, 0); |
| 1753 | if (!tnlskb) { |
| 1754 | pr_warn("%sunable to create dummy SYNCH_MSG\n", |
| 1755 | link_co_err); |
| 1756 | return; |
| 1757 | } |
| 1758 | |
| 1759 | hdr = buf_msg(tnlskb); |
| 1760 | syncpt = l->snd_nxt + skb_queue_len(&l->backlogq) - 1; |
| 1761 | msg_set_syncpt(hdr, syncpt); |
| 1762 | msg_set_bearer_id(hdr, l->peer_bearer_id); |
| 1763 | __skb_queue_tail(&tnlq, tnlskb); |
| 1764 | tipc_link_xmit(tnl, &tnlq, xmitq); |
| 1765 | return; |
| 1766 | } |
| 1767 | |
Tuong Lien | d0d605c | 2019-11-06 18:12:17 +0700 | [diff] [blame] | 1768 | __skb_queue_head_init(&tmpxq); |
| 1769 | __skb_queue_head_init(&frags); |
| 1770 | /* At least one packet required for safe algorithm => add dummy */ |
| 1771 | skb = tipc_msg_create(TIPC_LOW_IMPORTANCE, TIPC_DIRECT_MSG, |
| 1772 | BASIC_H_SIZE, 0, l->addr, tipc_own_addr(l->net), |
| 1773 | 0, 0, TIPC_ERR_NO_PORT); |
| 1774 | if (!skb) { |
| 1775 | pr_warn("%sunable to create tunnel packet\n", link_co_err); |
| 1776 | return; |
| 1777 | } |
| 1778 | __skb_queue_tail(&tnlq, skb); |
| 1779 | tipc_link_xmit(l, &tnlq, &tmpxq); |
| 1780 | __skb_queue_purge(&tmpxq); |
| 1781 | |
Jon Paul Maloy | 6e49815 | 2015-07-30 18:24:19 -0400 | [diff] [blame] | 1782 | /* Initialize reusable tunnel packet header */ |
Jon Paul Maloy | e74a386 | 2016-03-03 14:23:21 -0500 | [diff] [blame] | 1783 | tipc_msg_init(tipc_own_addr(l->net), &tnlhdr, TUNNEL_PROTOCOL, |
Jon Paul Maloy | 6e49815 | 2015-07-30 18:24:19 -0400 | [diff] [blame] | 1784 | mtyp, INT_H_SIZE, l->addr); |
Tuong Lien | 58ee86b | 2019-04-04 11:09:53 +0700 | [diff] [blame] | 1785 | if (mtyp == SYNCH_MSG) |
| 1786 | pktcnt = l->snd_nxt - buf_seqno(skb_peek(&l->transmq)); |
| 1787 | else |
| 1788 | pktcnt = skb_queue_len(&l->transmq); |
| 1789 | pktcnt += skb_queue_len(&l->backlogq); |
Jon Paul Maloy | 6e49815 | 2015-07-30 18:24:19 -0400 | [diff] [blame] | 1790 | msg_set_msgcnt(&tnlhdr, pktcnt); |
| 1791 | msg_set_bearer_id(&tnlhdr, l->peer_bearer_id); |
| 1792 | tnl: |
| 1793 | /* Wrap each packet into a tunnel packet */ |
Jon Paul Maloy | 05dcc5a | 2015-03-13 16:08:10 -0400 | [diff] [blame] | 1794 | skb_queue_walk(queue, skb) { |
Jon Paul Maloy | 6e49815 | 2015-07-30 18:24:19 -0400 | [diff] [blame] | 1795 | hdr = buf_msg(skb); |
| 1796 | if (queue == &l->backlogq) |
| 1797 | msg_set_seqno(hdr, seqno++); |
| 1798 | pktlen = msg_size(hdr); |
Tuong Lien | 2320bcd | 2019-07-24 08:56:12 +0700 | [diff] [blame] | 1799 | |
| 1800 | /* Tunnel link MTU is not large enough? This could be |
| 1801 | * due to: |
| 1802 | * 1) Link MTU has just changed or set differently; |
| 1803 | * 2) Or FAILOVER on the top of a SYNCH message |
| 1804 | * |
| 1805 | * The 2nd case should not happen if peer supports |
| 1806 | * TIPC_TUNNEL_ENHANCED |
| 1807 | */ |
| 1808 | if (pktlen > tnl->mtu - INT_H_SIZE) { |
| 1809 | if (mtyp == FAILOVER_MSG && |
| 1810 | (tnl->peer_caps & TIPC_TUNNEL_ENHANCED)) { |
| 1811 | rc = tipc_msg_fragment(skb, &tnlhdr, tnl->mtu, |
| 1812 | &frags); |
| 1813 | if (rc) { |
| 1814 | pr_warn("%sunable to frag msg: rc %d\n", |
| 1815 | link_co_err, rc); |
| 1816 | return; |
| 1817 | } |
| 1818 | pktcnt += skb_queue_len(&frags) - 1; |
| 1819 | pktcnt_need_update = true; |
| 1820 | skb_queue_splice_tail_init(&frags, &tnlq); |
| 1821 | continue; |
| 1822 | } |
| 1823 | /* Unluckily, peer doesn't have TIPC_TUNNEL_ENHANCED |
| 1824 | * => Just warn it and return! |
| 1825 | */ |
| 1826 | pr_warn_ratelimited("%stoo large msg <%d, %d>: %d!\n", |
| 1827 | link_co_err, msg_user(hdr), |
| 1828 | msg_type(hdr), msg_size(hdr)); |
| 1829 | return; |
| 1830 | } |
| 1831 | |
Jon Paul Maloy | 6e49815 | 2015-07-30 18:24:19 -0400 | [diff] [blame] | 1832 | msg_set_size(&tnlhdr, pktlen + INT_H_SIZE); |
Parthasarathy Bhuvaragan | 57d5f64 | 2017-01-13 15:46:25 +0100 | [diff] [blame] | 1833 | tnlskb = tipc_buf_acquire(pktlen + INT_H_SIZE, GFP_ATOMIC); |
Jon Paul Maloy | 6e49815 | 2015-07-30 18:24:19 -0400 | [diff] [blame] | 1834 | if (!tnlskb) { |
| 1835 | pr_warn("%sunable to send packet\n", link_co_err); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 1836 | return; |
| 1837 | } |
Jon Paul Maloy | 6e49815 | 2015-07-30 18:24:19 -0400 | [diff] [blame] | 1838 | skb_copy_to_linear_data(tnlskb, &tnlhdr, INT_H_SIZE); |
| 1839 | skb_copy_to_linear_data_offset(tnlskb, INT_H_SIZE, hdr, pktlen); |
| 1840 | __skb_queue_tail(&tnlq, tnlskb); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 1841 | } |
Jon Paul Maloy | 6e49815 | 2015-07-30 18:24:19 -0400 | [diff] [blame] | 1842 | if (queue != &l->backlogq) { |
| 1843 | queue = &l->backlogq; |
| 1844 | goto tnl; |
Jon Paul Maloy | dd3f9e7 | 2015-05-14 10:46:18 -0400 | [diff] [blame] | 1845 | } |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 1846 | |
Tuong Lien | 2320bcd | 2019-07-24 08:56:12 +0700 | [diff] [blame] | 1847 | if (pktcnt_need_update) |
| 1848 | skb_queue_walk(&tnlq, skb) { |
| 1849 | hdr = buf_msg(skb); |
| 1850 | msg_set_msgcnt(hdr, pktcnt); |
| 1851 | } |
| 1852 | |
Jon Paul Maloy | 6e49815 | 2015-07-30 18:24:19 -0400 | [diff] [blame] | 1853 | tipc_link_xmit(tnl, &tnlq, xmitq); |
Jon Paul Maloy | f006c9c | 2014-02-13 17:29:11 -0500 | [diff] [blame] | 1854 | |
Jon Paul Maloy | 6e49815 | 2015-07-30 18:24:19 -0400 | [diff] [blame] | 1855 | if (mtyp == FAILOVER_MSG) { |
| 1856 | tnl->drop_point = l->rcv_nxt; |
| 1857 | tnl->failover_reasm_skb = l->reasm_buf; |
| 1858 | l->reasm_buf = NULL; |
Tuong Lien | 58ee86b | 2019-04-04 11:09:53 +0700 | [diff] [blame] | 1859 | |
| 1860 | /* Failover the link's deferdq */ |
| 1861 | if (unlikely(!skb_queue_empty(fdefq))) { |
| 1862 | pr_warn("Link failover deferdq not empty: %d!\n", |
| 1863 | skb_queue_len(fdefq)); |
| 1864 | __skb_queue_purge(fdefq); |
| 1865 | } |
| 1866 | skb_queue_splice_init(&l->deferdq, fdefq); |
Jon Paul Maloy | f006c9c | 2014-02-13 17:29:11 -0500 | [diff] [blame] | 1867 | } |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 1868 | } |
| 1869 | |
Tuong Lien | c0b14a0 | 2019-05-02 17:23:23 +0700 | [diff] [blame] | 1870 | /** |
| 1871 | * tipc_link_failover_prepare() - prepare tnl for link failover |
| 1872 | * |
| 1873 | * This is a special version of the precursor - tipc_link_tnl_prepare(), |
| 1874 | * see the tipc_node_link_failover() for details |
| 1875 | * |
| 1876 | * @l: failover link |
| 1877 | * @tnl: tunnel link |
| 1878 | * @xmitq: queue for messages to be xmited |
| 1879 | */ |
| 1880 | void tipc_link_failover_prepare(struct tipc_link *l, struct tipc_link *tnl, |
| 1881 | struct sk_buff_head *xmitq) |
| 1882 | { |
| 1883 | struct sk_buff_head *fdefq = &tnl->failover_deferdq; |
| 1884 | |
| 1885 | tipc_link_create_dummy_tnl_msg(tnl, xmitq); |
| 1886 | |
Geert Uytterhoeven | 8ebed8a | 2019-10-24 17:30:43 +0200 | [diff] [blame] | 1887 | /* This failover link endpoint was never established before, |
Tuong Lien | c0b14a0 | 2019-05-02 17:23:23 +0700 | [diff] [blame] | 1888 | * so it has not received anything from peer. |
| 1889 | * Otherwise, it must be a normal failover situation or the |
| 1890 | * node has entered SELF_DOWN_PEER_LEAVING and both peer nodes |
| 1891 | * would have to start over from scratch instead. |
| 1892 | */ |
Tuong Lien | c0b14a0 | 2019-05-02 17:23:23 +0700 | [diff] [blame] | 1893 | tnl->drop_point = 1; |
| 1894 | tnl->failover_reasm_skb = NULL; |
| 1895 | |
| 1896 | /* Initiate the link's failover deferdq */ |
| 1897 | if (unlikely(!skb_queue_empty(fdefq))) { |
| 1898 | pr_warn("Link failover deferdq not empty: %d!\n", |
| 1899 | skb_queue_len(fdefq)); |
| 1900 | __skb_queue_purge(fdefq); |
| 1901 | } |
| 1902 | } |
| 1903 | |
Jon Maloy | 7ea817f | 2018-07-10 01:07:36 +0200 | [diff] [blame] | 1904 | /* tipc_link_validate_msg(): validate message against current link state |
| 1905 | * Returns true if message should be accepted, otherwise false |
| 1906 | */ |
| 1907 | bool tipc_link_validate_msg(struct tipc_link *l, struct tipc_msg *hdr) |
| 1908 | { |
| 1909 | u16 curr_session = l->peer_session; |
| 1910 | u16 session = msg_session(hdr); |
| 1911 | int mtyp = msg_type(hdr); |
| 1912 | |
| 1913 | if (msg_user(hdr) != LINK_PROTOCOL) |
| 1914 | return true; |
| 1915 | |
| 1916 | switch (mtyp) { |
| 1917 | case RESET_MSG: |
| 1918 | if (!l->in_session) |
| 1919 | return true; |
| 1920 | /* Accept only RESET with new session number */ |
| 1921 | return more(session, curr_session); |
| 1922 | case ACTIVATE_MSG: |
| 1923 | if (!l->in_session) |
| 1924 | return true; |
| 1925 | /* Accept only ACTIVATE with new or current session number */ |
| 1926 | return !less(session, curr_session); |
| 1927 | case STATE_MSG: |
| 1928 | /* Accept only STATE with current session number */ |
| 1929 | if (!l->in_session) |
| 1930 | return false; |
| 1931 | if (session != curr_session) |
| 1932 | return false; |
LUU Duc Canh | d949cfe | 2018-09-26 22:28:52 +0200 | [diff] [blame] | 1933 | /* Extra sanity check */ |
| 1934 | if (!link_is_up(l) && msg_ack(hdr)) |
| 1935 | return false; |
Jon Maloy | 7ea817f | 2018-07-10 01:07:36 +0200 | [diff] [blame] | 1936 | if (!(l->peer_caps & TIPC_LINK_PROTO_SEQNO)) |
| 1937 | return true; |
| 1938 | /* Accept only STATE with new sequence number */ |
| 1939 | return !less(msg_seqno(hdr), l->rcv_nxt_state); |
| 1940 | default: |
| 1941 | return false; |
| 1942 | } |
| 1943 | } |
| 1944 | |
Jon Paul Maloy | d999297 | 2015-07-16 16:54:31 -0400 | [diff] [blame] | 1945 | /* tipc_link_proto_rcv(): receive link level protocol message : |
| 1946 | * Note that network plane id propagates through the network, and may |
| 1947 | * change at any time. The node with lowest numerical id determines |
| 1948 | * network plane |
| 1949 | */ |
| 1950 | static int tipc_link_proto_rcv(struct tipc_link *l, struct sk_buff *skb, |
| 1951 | struct sk_buff_head *xmitq) |
| 1952 | { |
| 1953 | struct tipc_msg *hdr = buf_msg(skb); |
Tuong Lien | 9195948 | 2019-04-04 11:09:51 +0700 | [diff] [blame] | 1954 | struct tipc_gap_ack_blks *ga = NULL; |
Jon Paul Maloy | d999297 | 2015-07-16 16:54:31 -0400 | [diff] [blame] | 1955 | u16 rcvgap = 0; |
Jon Paul Maloy | c1ab3f1d | 2015-10-22 08:51:38 -0400 | [diff] [blame] | 1956 | u16 ack = msg_ack(hdr); |
| 1957 | u16 gap = msg_seq_gap(hdr); |
Jon Paul Maloy | d999297 | 2015-07-16 16:54:31 -0400 | [diff] [blame] | 1958 | u16 peers_snd_nxt = msg_next_sent(hdr); |
| 1959 | u16 peers_tol = msg_link_tolerance(hdr); |
| 1960 | u16 peers_prio = msg_linkprio(hdr); |
Jon Paul Maloy | 2be80c2 | 2015-08-20 02:12:56 -0400 | [diff] [blame] | 1961 | u16 rcv_nxt = l->rcv_nxt; |
Jon Paul Maloy | 35c55c9 | 2016-06-13 20:46:22 -0400 | [diff] [blame] | 1962 | u16 dlen = msg_data_sz(hdr); |
Jon Paul Maloy | 73f646c | 2015-10-15 14:52:44 -0400 | [diff] [blame] | 1963 | int mtyp = msg_type(hdr); |
Jon Maloy | 8d6e79d | 2017-11-08 09:59:26 +0100 | [diff] [blame] | 1964 | bool reply = msg_probe(hdr); |
Tuong Lien | 9195948 | 2019-04-04 11:09:51 +0700 | [diff] [blame] | 1965 | u16 glen = 0; |
Jon Paul Maloy | 35c55c9 | 2016-06-13 20:46:22 -0400 | [diff] [blame] | 1966 | void *data; |
Jon Paul Maloy | d999297 | 2015-07-16 16:54:31 -0400 | [diff] [blame] | 1967 | char *if_name; |
| 1968 | int rc = 0; |
| 1969 | |
Tuong Lien | 26574db | 2018-12-19 09:17:57 +0700 | [diff] [blame] | 1970 | trace_tipc_proto_rcv(skb, false, l->name); |
Jon Paul Maloy | 5266698 | 2015-10-22 08:51:41 -0400 | [diff] [blame] | 1971 | if (tipc_link_is_blocked(l) || !xmitq) |
Jon Paul Maloy | d999297 | 2015-07-16 16:54:31 -0400 | [diff] [blame] | 1972 | goto exit; |
| 1973 | |
Jon Paul Maloy | e74a386 | 2016-03-03 14:23:21 -0500 | [diff] [blame] | 1974 | if (tipc_own_addr(l->net) > msg_prevnode(hdr)) |
Jon Paul Maloy | d999297 | 2015-07-16 16:54:31 -0400 | [diff] [blame] | 1975 | l->net_plane = msg_net_plane(hdr); |
| 1976 | |
Jon Paul Maloy | 35c55c9 | 2016-06-13 20:46:22 -0400 | [diff] [blame] | 1977 | skb_linearize(skb); |
| 1978 | hdr = buf_msg(skb); |
| 1979 | data = msg_data(hdr); |
| 1980 | |
Tuong Lien | 26574db | 2018-12-19 09:17:57 +0700 | [diff] [blame] | 1981 | if (!tipc_link_validate_msg(l, hdr)) { |
| 1982 | trace_tipc_skb_dump(skb, false, "PROTO invalid (1)!"); |
| 1983 | trace_tipc_link_dump(l, TIPC_DUMP_NONE, "PROTO invalid (1)!"); |
Jon Maloy | 7ea817f | 2018-07-10 01:07:36 +0200 | [diff] [blame] | 1984 | goto exit; |
Tuong Lien | 26574db | 2018-12-19 09:17:57 +0700 | [diff] [blame] | 1985 | } |
Jon Maloy | 7ea817f | 2018-07-10 01:07:36 +0200 | [diff] [blame] | 1986 | |
Jon Paul Maloy | 73f646c | 2015-10-15 14:52:44 -0400 | [diff] [blame] | 1987 | switch (mtyp) { |
Jon Paul Maloy | d999297 | 2015-07-16 16:54:31 -0400 | [diff] [blame] | 1988 | case RESET_MSG: |
Jon Paul Maloy | d999297 | 2015-07-16 16:54:31 -0400 | [diff] [blame] | 1989 | case ACTIVATE_MSG: |
Jon Paul Maloy | d999297 | 2015-07-16 16:54:31 -0400 | [diff] [blame] | 1990 | /* Complete own link name with peer's interface name */ |
| 1991 | if_name = strrchr(l->name, ':') + 1; |
| 1992 | if (sizeof(l->name) - (if_name - l->name) <= TIPC_MAX_IF_NAME) |
| 1993 | break; |
| 1994 | if (msg_data_sz(hdr) < TIPC_MAX_IF_NAME) |
| 1995 | break; |
Jon Paul Maloy | 35c55c9 | 2016-06-13 20:46:22 -0400 | [diff] [blame] | 1996 | strncpy(if_name, data, TIPC_MAX_IF_NAME); |
Jon Paul Maloy | d999297 | 2015-07-16 16:54:31 -0400 | [diff] [blame] | 1997 | |
| 1998 | /* Update own tolerance if peer indicates a non-zero value */ |
Jon Maloy | 047491e | 2018-10-10 17:34:01 +0200 | [diff] [blame] | 1999 | if (in_range(peers_tol, TIPC_MIN_LINK_TOL, TIPC_MAX_LINK_TOL)) { |
Jon Paul Maloy | d999297 | 2015-07-16 16:54:31 -0400 | [diff] [blame] | 2000 | l->tolerance = peers_tol; |
Jon Maloy | 047491e | 2018-10-10 17:34:01 +0200 | [diff] [blame] | 2001 | l->bc_rcvlink->tolerance = peers_tol; |
| 2002 | } |
Jon Paul Maloy | d999297 | 2015-07-16 16:54:31 -0400 | [diff] [blame] | 2003 | /* Update own priority if peer's priority is higher */ |
| 2004 | if (in_range(peers_prio, l->priority + 1, TIPC_MAX_LINK_PRI)) |
| 2005 | l->priority = peers_prio; |
| 2006 | |
Jon Maloy | 7ab412d | 2018-11-10 17:30:24 -0500 | [diff] [blame] | 2007 | /* If peer is going down we want full re-establish cycle */ |
| 2008 | if (msg_peer_stopping(hdr)) { |
Jon Paul Maloy | 634696b | 2016-04-15 13:33:03 -0400 | [diff] [blame] | 2009 | rc = tipc_link_fsm_evt(l, LINK_FAILURE_EVT); |
Jon Maloy | 7ab412d | 2018-11-10 17:30:24 -0500 | [diff] [blame] | 2010 | break; |
| 2011 | } |
Tuong Lien | 91986ee | 2019-02-11 13:29:43 +0700 | [diff] [blame] | 2012 | |
| 2013 | /* If this endpoint was re-created while peer was ESTABLISHING |
| 2014 | * it doesn't know current session number. Force re-synch. |
| 2015 | */ |
| 2016 | if (mtyp == ACTIVATE_MSG && msg_dest_session_valid(hdr) && |
| 2017 | l->session != msg_dest_session(hdr)) { |
| 2018 | if (less(l->session, msg_dest_session(hdr))) |
| 2019 | l->session = msg_dest_session(hdr) + 1; |
| 2020 | break; |
| 2021 | } |
| 2022 | |
Jon Maloy | 7ab412d | 2018-11-10 17:30:24 -0500 | [diff] [blame] | 2023 | /* ACTIVATE_MSG serves as PEER_RESET if link is already down */ |
| 2024 | if (mtyp == RESET_MSG || !link_is_up(l)) |
Jon Paul Maloy | 73f646c | 2015-10-15 14:52:44 -0400 | [diff] [blame] | 2025 | rc = tipc_link_fsm_evt(l, LINK_PEER_RESET_EVT); |
| 2026 | |
| 2027 | /* ACTIVATE_MSG takes up link if it was already locally reset */ |
Jon Maloy | 7ab412d | 2018-11-10 17:30:24 -0500 | [diff] [blame] | 2028 | if (mtyp == ACTIVATE_MSG && l->state == LINK_ESTABLISHING) |
Jon Paul Maloy | 73f646c | 2015-10-15 14:52:44 -0400 | [diff] [blame] | 2029 | rc = TIPC_LINK_UP_EVT; |
| 2030 | |
Jon Paul Maloy | d999297 | 2015-07-16 16:54:31 -0400 | [diff] [blame] | 2031 | l->peer_session = msg_session(hdr); |
Jon Maloy | 7ea817f | 2018-07-10 01:07:36 +0200 | [diff] [blame] | 2032 | l->in_session = true; |
Jon Paul Maloy | d999297 | 2015-07-16 16:54:31 -0400 | [diff] [blame] | 2033 | l->peer_bearer_id = msg_bearer_id(hdr); |
Jon Paul Maloy | d999297 | 2015-07-16 16:54:31 -0400 | [diff] [blame] | 2034 | if (l->mtu > msg_max_pkt(hdr)) |
| 2035 | l->mtu = msg_max_pkt(hdr); |
| 2036 | break; |
Jon Paul Maloy | 662921c | 2015-07-30 18:24:21 -0400 | [diff] [blame] | 2037 | |
Jon Paul Maloy | d999297 | 2015-07-16 16:54:31 -0400 | [diff] [blame] | 2038 | case STATE_MSG: |
Jon Maloy | 9012de5 | 2018-07-10 01:07:35 +0200 | [diff] [blame] | 2039 | l->rcv_nxt_state = msg_seqno(hdr) + 1; |
| 2040 | |
Jon Paul Maloy | d999297 | 2015-07-16 16:54:31 -0400 | [diff] [blame] | 2041 | /* Update own tolerance if peer indicates a non-zero value */ |
Jon Maloy | 047491e | 2018-10-10 17:34:01 +0200 | [diff] [blame] | 2042 | if (in_range(peers_tol, TIPC_MIN_LINK_TOL, TIPC_MAX_LINK_TOL)) { |
Jon Paul Maloy | d999297 | 2015-07-16 16:54:31 -0400 | [diff] [blame] | 2043 | l->tolerance = peers_tol; |
Jon Maloy | 047491e | 2018-10-10 17:34:01 +0200 | [diff] [blame] | 2044 | l->bc_rcvlink->tolerance = peers_tol; |
| 2045 | } |
Jon Paul Maloy | f796755 | 2016-11-23 21:05:26 -0500 | [diff] [blame] | 2046 | /* Update own prio if peer indicates a different value */ |
| 2047 | if ((peers_prio != l->priority) && |
| 2048 | in_range(peers_prio, 1, TIPC_MAX_LINK_PRI)) { |
Richard Alpe | 8172981 | 2016-02-01 08:19:57 +0100 | [diff] [blame] | 2049 | l->priority = peers_prio; |
| 2050 | rc = tipc_link_fsm_evt(l, LINK_FAILURE_EVT); |
| 2051 | } |
| 2052 | |
Jon Paul Maloy | d999297 | 2015-07-16 16:54:31 -0400 | [diff] [blame] | 2053 | l->silent_intv_cnt = 0; |
| 2054 | l->stats.recv_states++; |
| 2055 | if (msg_probe(hdr)) |
| 2056 | l->stats.recv_probes++; |
Jon Paul Maloy | 73f646c | 2015-10-15 14:52:44 -0400 | [diff] [blame] | 2057 | |
| 2058 | if (!link_is_up(l)) { |
| 2059 | if (l->state == LINK_ESTABLISHING) |
| 2060 | rc = TIPC_LINK_UP_EVT; |
Jon Paul Maloy | d999297 | 2015-07-16 16:54:31 -0400 | [diff] [blame] | 2061 | break; |
Jon Paul Maloy | 73f646c | 2015-10-15 14:52:44 -0400 | [diff] [blame] | 2062 | } |
Tuong Lien | 9195948 | 2019-04-04 11:09:51 +0700 | [diff] [blame] | 2063 | |
| 2064 | /* Receive Gap ACK blocks from peer if any */ |
| 2065 | if (l->peer_caps & TIPC_GAP_ACK_BLOCK) { |
| 2066 | ga = (struct tipc_gap_ack_blks *)data; |
| 2067 | glen = ntohs(ga->len); |
| 2068 | /* sanity check: if failed, ignore Gap ACK blocks */ |
| 2069 | if (glen != tipc_gap_ack_blks_sz(ga->gack_cnt)) |
| 2070 | ga = NULL; |
| 2071 | } |
| 2072 | |
| 2073 | tipc_mon_rcv(l->net, data + glen, dlen - glen, l->addr, |
Jon Paul Maloy | 35c55c9 | 2016-06-13 20:46:22 -0400 | [diff] [blame] | 2074 | &l->mon_state, l->bearer_id); |
Jon Paul Maloy | d999297 | 2015-07-16 16:54:31 -0400 | [diff] [blame] | 2075 | |
Jon Paul Maloy | 662921c | 2015-07-30 18:24:21 -0400 | [diff] [blame] | 2076 | /* Send NACK if peer has sent pkts we haven't received yet */ |
Jon Paul Maloy | 2be80c2 | 2015-08-20 02:12:56 -0400 | [diff] [blame] | 2077 | if (more(peers_snd_nxt, rcv_nxt) && !tipc_link_is_synching(l)) |
Jon Paul Maloy | d999297 | 2015-07-16 16:54:31 -0400 | [diff] [blame] | 2078 | rcvgap = peers_snd_nxt - l->rcv_nxt; |
Jon Maloy | 8d6e79d | 2017-11-08 09:59:26 +0100 | [diff] [blame] | 2079 | if (rcvgap || reply) |
| 2080 | tipc_link_build_proto_msg(l, STATE_MSG, 0, reply, |
| 2081 | rcvgap, 0, 0, xmitq); |
Tuong Lien | 9195948 | 2019-04-04 11:09:51 +0700 | [diff] [blame] | 2082 | |
Tuong Lien | 6a6b5c8 | 2019-06-17 12:15:42 +0700 | [diff] [blame] | 2083 | rc |= tipc_link_advance_transmq(l, ack, gap, ga, xmitq); |
Jon Paul Maloy | d999297 | 2015-07-16 16:54:31 -0400 | [diff] [blame] | 2084 | |
| 2085 | /* If NACK, retransmit will now start at right position */ |
Tuong Lien | 9195948 | 2019-04-04 11:09:51 +0700 | [diff] [blame] | 2086 | if (gap) |
Jon Paul Maloy | d999297 | 2015-07-16 16:54:31 -0400 | [diff] [blame] | 2087 | l->stats.recv_nacks++; |
Jon Paul Maloy | 662921c | 2015-07-30 18:24:21 -0400 | [diff] [blame] | 2088 | |
Jon Paul Maloy | d999297 | 2015-07-16 16:54:31 -0400 | [diff] [blame] | 2089 | tipc_link_advance_backlog(l, xmitq); |
| 2090 | if (unlikely(!skb_queue_empty(&l->wakeupq))) |
| 2091 | link_prepare_wakeup(l); |
| 2092 | } |
| 2093 | exit: |
| 2094 | kfree_skb(skb); |
| 2095 | return rc; |
| 2096 | } |
| 2097 | |
Jon Paul Maloy | 5266698 | 2015-10-22 08:51:41 -0400 | [diff] [blame] | 2098 | /* tipc_link_build_bc_proto_msg() - create broadcast protocol message |
| 2099 | */ |
| 2100 | static bool tipc_link_build_bc_proto_msg(struct tipc_link *l, bool bcast, |
| 2101 | u16 peers_snd_nxt, |
| 2102 | struct sk_buff_head *xmitq) |
| 2103 | { |
| 2104 | struct sk_buff *skb; |
| 2105 | struct tipc_msg *hdr; |
| 2106 | struct sk_buff *dfrd_skb = skb_peek(&l->deferdq); |
| 2107 | u16 ack = l->rcv_nxt - 1; |
| 2108 | u16 gap_to = peers_snd_nxt - 1; |
| 2109 | |
| 2110 | skb = tipc_msg_create(BCAST_PROTOCOL, STATE_MSG, INT_H_SIZE, |
Jon Paul Maloy | e74a386 | 2016-03-03 14:23:21 -0500 | [diff] [blame] | 2111 | 0, l->addr, tipc_own_addr(l->net), 0, 0, 0); |
Jon Paul Maloy | 5266698 | 2015-10-22 08:51:41 -0400 | [diff] [blame] | 2112 | if (!skb) |
| 2113 | return false; |
| 2114 | hdr = buf_msg(skb); |
| 2115 | msg_set_last_bcast(hdr, l->bc_sndlink->snd_nxt - 1); |
| 2116 | msg_set_bcast_ack(hdr, ack); |
| 2117 | msg_set_bcgap_after(hdr, ack); |
| 2118 | if (dfrd_skb) |
| 2119 | gap_to = buf_seqno(dfrd_skb) - 1; |
| 2120 | msg_set_bcgap_to(hdr, gap_to); |
| 2121 | msg_set_non_seq(hdr, bcast); |
| 2122 | __skb_queue_tail(xmitq, skb); |
| 2123 | return true; |
| 2124 | } |
| 2125 | |
| 2126 | /* tipc_link_build_bc_init_msg() - synchronize broadcast link endpoints. |
| 2127 | * |
| 2128 | * Give a newly added peer node the sequence number where it should |
| 2129 | * start receiving and acking broadcast packets. |
| 2130 | */ |
Wu Fengguang | 742e038 | 2015-10-24 22:56:01 +0800 | [diff] [blame] | 2131 | static void tipc_link_build_bc_init_msg(struct tipc_link *l, |
| 2132 | struct sk_buff_head *xmitq) |
Jon Paul Maloy | 5266698 | 2015-10-22 08:51:41 -0400 | [diff] [blame] | 2133 | { |
| 2134 | struct sk_buff_head list; |
| 2135 | |
| 2136 | __skb_queue_head_init(&list); |
| 2137 | if (!tipc_link_build_bc_proto_msg(l->bc_rcvlink, false, 0, &list)) |
| 2138 | return; |
Jon Paul Maloy | 06bd2b1 | 2016-10-27 18:51:55 -0400 | [diff] [blame] | 2139 | msg_set_bc_ack_invalid(buf_msg(skb_peek(&list)), true); |
Jon Paul Maloy | 5266698 | 2015-10-22 08:51:41 -0400 | [diff] [blame] | 2140 | tipc_link_xmit(l, &list, xmitq); |
| 2141 | } |
| 2142 | |
| 2143 | /* tipc_link_bc_init_rcv - receive initial broadcast synch data from peer |
| 2144 | */ |
| 2145 | void tipc_link_bc_init_rcv(struct tipc_link *l, struct tipc_msg *hdr) |
| 2146 | { |
| 2147 | int mtyp = msg_type(hdr); |
| 2148 | u16 peers_snd_nxt = msg_bc_snd_nxt(hdr); |
| 2149 | |
| 2150 | if (link_is_up(l)) |
| 2151 | return; |
| 2152 | |
| 2153 | if (msg_user(hdr) == BCAST_PROTOCOL) { |
| 2154 | l->rcv_nxt = peers_snd_nxt; |
| 2155 | l->state = LINK_ESTABLISHED; |
| 2156 | return; |
| 2157 | } |
| 2158 | |
| 2159 | if (l->peer_caps & TIPC_BCAST_SYNCH) |
| 2160 | return; |
| 2161 | |
| 2162 | if (msg_peer_node_is_up(hdr)) |
| 2163 | return; |
| 2164 | |
| 2165 | /* Compatibility: accept older, less safe initial synch data */ |
| 2166 | if ((mtyp == RESET_MSG) || (mtyp == ACTIVATE_MSG)) |
| 2167 | l->rcv_nxt = peers_snd_nxt; |
| 2168 | } |
| 2169 | |
| 2170 | /* tipc_link_bc_sync_rcv - update rcv link according to peer's send state |
| 2171 | */ |
Jon Paul Maloy | 02d11ca | 2016-09-01 13:52:49 -0400 | [diff] [blame] | 2172 | int tipc_link_bc_sync_rcv(struct tipc_link *l, struct tipc_msg *hdr, |
| 2173 | struct sk_buff_head *xmitq) |
Jon Paul Maloy | 5266698 | 2015-10-22 08:51:41 -0400 | [diff] [blame] | 2174 | { |
Jon Paul Maloy | 7c4a54b | 2016-09-01 13:52:50 -0400 | [diff] [blame] | 2175 | struct tipc_link *snd_l = l->bc_sndlink; |
Jon Paul Maloy | 5266698 | 2015-10-22 08:51:41 -0400 | [diff] [blame] | 2176 | u16 peers_snd_nxt = msg_bc_snd_nxt(hdr); |
Jon Paul Maloy | 02d11ca | 2016-09-01 13:52:49 -0400 | [diff] [blame] | 2177 | u16 from = msg_bcast_ack(hdr) + 1; |
| 2178 | u16 to = from + msg_bc_gap(hdr) - 1; |
| 2179 | int rc = 0; |
Jon Paul Maloy | 5266698 | 2015-10-22 08:51:41 -0400 | [diff] [blame] | 2180 | |
| 2181 | if (!link_is_up(l)) |
Jon Paul Maloy | 02d11ca | 2016-09-01 13:52:49 -0400 | [diff] [blame] | 2182 | return rc; |
Jon Paul Maloy | 5266698 | 2015-10-22 08:51:41 -0400 | [diff] [blame] | 2183 | |
| 2184 | if (!msg_peer_node_is_up(hdr)) |
Jon Paul Maloy | 02d11ca | 2016-09-01 13:52:49 -0400 | [diff] [blame] | 2185 | return rc; |
Jon Paul Maloy | 5266698 | 2015-10-22 08:51:41 -0400 | [diff] [blame] | 2186 | |
Jon Paul Maloy | 2d18ac4 | 2016-07-11 16:08:35 -0400 | [diff] [blame] | 2187 | /* Open when peer ackowledges our bcast init msg (pkt #1) */ |
| 2188 | if (msg_ack(hdr)) |
| 2189 | l->bc_peer_is_up = true; |
| 2190 | |
| 2191 | if (!l->bc_peer_is_up) |
Jon Paul Maloy | 02d11ca | 2016-09-01 13:52:49 -0400 | [diff] [blame] | 2192 | return rc; |
Jon Paul Maloy | 5266698 | 2015-10-22 08:51:41 -0400 | [diff] [blame] | 2193 | |
Jon Paul Maloy | 7c4a54b | 2016-09-01 13:52:50 -0400 | [diff] [blame] | 2194 | l->stats.recv_nacks++; |
| 2195 | |
Jon Paul Maloy | 5266698 | 2015-10-22 08:51:41 -0400 | [diff] [blame] | 2196 | /* Ignore if peers_snd_nxt goes beyond receive window */ |
| 2197 | if (more(peers_snd_nxt, l->rcv_nxt + l->window)) |
Jon Paul Maloy | 02d11ca | 2016-09-01 13:52:49 -0400 | [diff] [blame] | 2198 | return rc; |
| 2199 | |
Tuong Lien | 6a6b5c8 | 2019-06-17 12:15:42 +0700 | [diff] [blame] | 2200 | rc = tipc_link_bc_retrans(snd_l, l, from, to, xmitq); |
Jon Paul Maloy | 02d11ca | 2016-09-01 13:52:49 -0400 | [diff] [blame] | 2201 | |
| 2202 | l->snd_nxt = peers_snd_nxt; |
| 2203 | if (link_bc_rcv_gap(l)) |
| 2204 | rc |= TIPC_LINK_SND_STATE; |
| 2205 | |
| 2206 | /* Return now if sender supports nack via STATE messages */ |
| 2207 | if (l->peer_caps & TIPC_BCAST_STATE_NACK) |
| 2208 | return rc; |
| 2209 | |
| 2210 | /* Otherwise, be backwards compatible */ |
Jon Paul Maloy | 5266698 | 2015-10-22 08:51:41 -0400 | [diff] [blame] | 2211 | |
| 2212 | if (!more(peers_snd_nxt, l->rcv_nxt)) { |
| 2213 | l->nack_state = BC_NACK_SND_CONDITIONAL; |
Jon Paul Maloy | 02d11ca | 2016-09-01 13:52:49 -0400 | [diff] [blame] | 2214 | return 0; |
Jon Paul Maloy | 5266698 | 2015-10-22 08:51:41 -0400 | [diff] [blame] | 2215 | } |
| 2216 | |
| 2217 | /* Don't NACK if one was recently sent or peeked */ |
| 2218 | if (l->nack_state == BC_NACK_SND_SUPPRESS) { |
| 2219 | l->nack_state = BC_NACK_SND_UNCONDITIONAL; |
Jon Paul Maloy | 02d11ca | 2016-09-01 13:52:49 -0400 | [diff] [blame] | 2220 | return 0; |
Jon Paul Maloy | 5266698 | 2015-10-22 08:51:41 -0400 | [diff] [blame] | 2221 | } |
| 2222 | |
| 2223 | /* Conditionally delay NACK sending until next synch rcv */ |
| 2224 | if (l->nack_state == BC_NACK_SND_CONDITIONAL) { |
| 2225 | l->nack_state = BC_NACK_SND_UNCONDITIONAL; |
| 2226 | if ((peers_snd_nxt - l->rcv_nxt) < TIPC_MIN_LINK_WIN) |
Jon Paul Maloy | 02d11ca | 2016-09-01 13:52:49 -0400 | [diff] [blame] | 2227 | return 0; |
Jon Paul Maloy | 5266698 | 2015-10-22 08:51:41 -0400 | [diff] [blame] | 2228 | } |
| 2229 | |
| 2230 | /* Send NACK now but suppress next one */ |
| 2231 | tipc_link_build_bc_proto_msg(l, true, peers_snd_nxt, xmitq); |
| 2232 | l->nack_state = BC_NACK_SND_SUPPRESS; |
Jon Paul Maloy | 02d11ca | 2016-09-01 13:52:49 -0400 | [diff] [blame] | 2233 | return 0; |
Jon Paul Maloy | 5266698 | 2015-10-22 08:51:41 -0400 | [diff] [blame] | 2234 | } |
| 2235 | |
| 2236 | void tipc_link_bc_ack_rcv(struct tipc_link *l, u16 acked, |
| 2237 | struct sk_buff_head *xmitq) |
| 2238 | { |
| 2239 | struct sk_buff *skb, *tmp; |
| 2240 | struct tipc_link *snd_l = l->bc_sndlink; |
| 2241 | |
| 2242 | if (!link_is_up(l) || !l->bc_peer_is_up) |
| 2243 | return; |
| 2244 | |
| 2245 | if (!more(acked, l->acked)) |
| 2246 | return; |
| 2247 | |
Tuong Lien | 26574db | 2018-12-19 09:17:57 +0700 | [diff] [blame] | 2248 | trace_tipc_link_bc_ack(l, l->acked, acked, &snd_l->transmq); |
Jon Paul Maloy | 5266698 | 2015-10-22 08:51:41 -0400 | [diff] [blame] | 2249 | /* Skip over packets peer has already acked */ |
| 2250 | skb_queue_walk(&snd_l->transmq, skb) { |
| 2251 | if (more(buf_seqno(skb), l->acked)) |
| 2252 | break; |
| 2253 | } |
| 2254 | |
| 2255 | /* Update/release the packets peer is acking now */ |
| 2256 | skb_queue_walk_from_safe(&snd_l->transmq, skb, tmp) { |
| 2257 | if (more(buf_seqno(skb), acked)) |
| 2258 | break; |
| 2259 | if (!--TIPC_SKB_CB(skb)->ackers) { |
| 2260 | __skb_unlink(skb, &snd_l->transmq); |
| 2261 | kfree_skb(skb); |
| 2262 | } |
| 2263 | } |
| 2264 | l->acked = acked; |
| 2265 | tipc_link_advance_backlog(snd_l, xmitq); |
| 2266 | if (unlikely(!skb_queue_empty(&snd_l->wakeupq))) |
| 2267 | link_prepare_wakeup(snd_l); |
| 2268 | } |
| 2269 | |
| 2270 | /* tipc_link_bc_nack_rcv(): receive broadcast nack message |
Jon Paul Maloy | 02d11ca | 2016-09-01 13:52:49 -0400 | [diff] [blame] | 2271 | * This function is here for backwards compatibility, since |
| 2272 | * no BCAST_PROTOCOL/STATE messages occur from TIPC v2.5. |
Jon Paul Maloy | 5266698 | 2015-10-22 08:51:41 -0400 | [diff] [blame] | 2273 | */ |
| 2274 | int tipc_link_bc_nack_rcv(struct tipc_link *l, struct sk_buff *skb, |
| 2275 | struct sk_buff_head *xmitq) |
| 2276 | { |
| 2277 | struct tipc_msg *hdr = buf_msg(skb); |
| 2278 | u32 dnode = msg_destnode(hdr); |
| 2279 | int mtyp = msg_type(hdr); |
| 2280 | u16 acked = msg_bcast_ack(hdr); |
| 2281 | u16 from = acked + 1; |
| 2282 | u16 to = msg_bcgap_to(hdr); |
| 2283 | u16 peers_snd_nxt = to + 1; |
| 2284 | int rc = 0; |
| 2285 | |
| 2286 | kfree_skb(skb); |
| 2287 | |
| 2288 | if (!tipc_link_is_up(l) || !l->bc_peer_is_up) |
| 2289 | return 0; |
| 2290 | |
| 2291 | if (mtyp != STATE_MSG) |
| 2292 | return 0; |
| 2293 | |
Jon Paul Maloy | e74a386 | 2016-03-03 14:23:21 -0500 | [diff] [blame] | 2294 | if (dnode == tipc_own_addr(l->net)) { |
Jon Paul Maloy | 5266698 | 2015-10-22 08:51:41 -0400 | [diff] [blame] | 2295 | tipc_link_bc_ack_rcv(l, acked, xmitq); |
Tuong Lien | 6a6b5c8 | 2019-06-17 12:15:42 +0700 | [diff] [blame] | 2296 | rc = tipc_link_bc_retrans(l->bc_sndlink, l, from, to, xmitq); |
Jon Paul Maloy | 5266698 | 2015-10-22 08:51:41 -0400 | [diff] [blame] | 2297 | l->stats.recv_nacks++; |
| 2298 | return rc; |
| 2299 | } |
| 2300 | |
| 2301 | /* Msg for other node => suppress own NACK at next sync if applicable */ |
| 2302 | if (more(peers_snd_nxt, l->rcv_nxt) && !less(l->rcv_nxt, from)) |
| 2303 | l->nack_state = BC_NACK_SND_SUPPRESS; |
| 2304 | |
| 2305 | return 0; |
| 2306 | } |
| 2307 | |
Jon Paul Maloy | e3eea1e | 2015-03-13 16:08:11 -0400 | [diff] [blame] | 2308 | void tipc_link_set_queue_limits(struct tipc_link *l, u32 win) |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 2309 | { |
Jon Maloy | 218527f | 2018-03-29 23:20:41 +0200 | [diff] [blame] | 2310 | int max_bulk = TIPC_MAX_PUBL / (l->mtu / ITEM_SIZE); |
Jon Paul Maloy | 05dcc5a | 2015-03-13 16:08:10 -0400 | [diff] [blame] | 2311 | |
Jon Paul Maloy | e3eea1e | 2015-03-13 16:08:11 -0400 | [diff] [blame] | 2312 | l->window = win; |
Jon Paul Maloy | 5a0950c | 2016-08-16 11:53:51 -0400 | [diff] [blame] | 2313 | l->backlog[TIPC_LOW_IMPORTANCE].limit = max_t(u16, 50, win); |
| 2314 | l->backlog[TIPC_MEDIUM_IMPORTANCE].limit = max_t(u16, 100, win * 2); |
| 2315 | l->backlog[TIPC_HIGH_IMPORTANCE].limit = max_t(u16, 150, win * 3); |
| 2316 | l->backlog[TIPC_CRITICAL_IMPORTANCE].limit = max_t(u16, 200, win * 4); |
Jon Paul Maloy | 1f66d16 | 2015-03-25 12:07:24 -0400 | [diff] [blame] | 2317 | l->backlog[TIPC_SYSTEM_IMPORTANCE].limit = max_bulk; |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 2318 | } |
| 2319 | |
Allan Stephens | 5c216e1 | 2011-10-18 11:34:29 -0400 | [diff] [blame] | 2320 | /** |
Jon Paul Maloy | 38206d5 | 2015-11-19 14:30:46 -0500 | [diff] [blame] | 2321 | * link_reset_stats - reset link statistics |
Jon Paul Maloy | 1a90632 | 2015-11-19 14:30:47 -0500 | [diff] [blame] | 2322 | * @l: pointer to link |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 2323 | */ |
Jon Paul Maloy | 38206d5 | 2015-11-19 14:30:46 -0500 | [diff] [blame] | 2324 | void tipc_link_reset_stats(struct tipc_link *l) |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 2325 | { |
Jon Paul Maloy | 38206d5 | 2015-11-19 14:30:46 -0500 | [diff] [blame] | 2326 | memset(&l->stats, 0, sizeof(l->stats)); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 2327 | } |
| 2328 | |
Jon Paul Maloy | 1a20cc2 | 2015-07-16 16:54:30 -0400 | [diff] [blame] | 2329 | static void link_print(struct tipc_link *l, const char *str) |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 2330 | { |
Jon Paul Maloy | 1a20cc2 | 2015-07-16 16:54:30 -0400 | [diff] [blame] | 2331 | struct sk_buff *hskb = skb_peek(&l->transmq); |
Jon Paul Maloy | c1ab3f1d | 2015-10-22 08:51:38 -0400 | [diff] [blame] | 2332 | u16 head = hskb ? msg_seqno(buf_msg(hskb)) : l->snd_nxt - 1; |
Jon Paul Maloy | 1a20cc2 | 2015-07-16 16:54:30 -0400 | [diff] [blame] | 2333 | u16 tail = l->snd_nxt - 1; |
Ying Xue | 7a2f7d1 | 2014-04-21 10:55:46 +0800 | [diff] [blame] | 2334 | |
Jon Paul Maloy | 662921c | 2015-07-30 18:24:21 -0400 | [diff] [blame] | 2335 | pr_info("%s Link <%s> state %x\n", str, l->name, l->state); |
Jon Paul Maloy | 1a20cc2 | 2015-07-16 16:54:30 -0400 | [diff] [blame] | 2336 | pr_info("XMTQ: %u [%u-%u], BKLGQ: %u, SNDNX: %u, RCVNX: %u\n", |
| 2337 | skb_queue_len(&l->transmq), head, tail, |
| 2338 | skb_queue_len(&l->backlogq), l->snd_nxt, l->rcv_nxt); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 2339 | } |
Richard Alpe | 0655f6a | 2014-11-20 10:29:07 +0100 | [diff] [blame] | 2340 | |
| 2341 | /* Parse and validate nested (link) properties valid for media, bearer and link |
| 2342 | */ |
| 2343 | int tipc_nl_parse_link_prop(struct nlattr *prop, struct nlattr *props[]) |
| 2344 | { |
| 2345 | int err; |
| 2346 | |
Johannes Berg | 8cb0817 | 2019-04-26 14:07:28 +0200 | [diff] [blame] | 2347 | err = nla_parse_nested_deprecated(props, TIPC_NLA_PROP_MAX, prop, |
| 2348 | tipc_nl_prop_policy, NULL); |
Richard Alpe | 0655f6a | 2014-11-20 10:29:07 +0100 | [diff] [blame] | 2349 | if (err) |
| 2350 | return err; |
| 2351 | |
| 2352 | if (props[TIPC_NLA_PROP_PRIO]) { |
| 2353 | u32 prio; |
| 2354 | |
| 2355 | prio = nla_get_u32(props[TIPC_NLA_PROP_PRIO]); |
| 2356 | if (prio > TIPC_MAX_LINK_PRI) |
| 2357 | return -EINVAL; |
| 2358 | } |
| 2359 | |
| 2360 | if (props[TIPC_NLA_PROP_TOL]) { |
| 2361 | u32 tol; |
| 2362 | |
| 2363 | tol = nla_get_u32(props[TIPC_NLA_PROP_TOL]); |
| 2364 | if ((tol < TIPC_MIN_LINK_TOL) || (tol > TIPC_MAX_LINK_TOL)) |
| 2365 | return -EINVAL; |
| 2366 | } |
| 2367 | |
| 2368 | if (props[TIPC_NLA_PROP_WIN]) { |
| 2369 | u32 win; |
| 2370 | |
| 2371 | win = nla_get_u32(props[TIPC_NLA_PROP_WIN]); |
| 2372 | if ((win < TIPC_MIN_LINK_WIN) || (win > TIPC_MAX_LINK_WIN)) |
| 2373 | return -EINVAL; |
| 2374 | } |
| 2375 | |
| 2376 | return 0; |
| 2377 | } |
Richard Alpe | 7be57fc | 2014-11-20 10:29:12 +0100 | [diff] [blame] | 2378 | |
Richard Alpe | d818280 | 2014-11-24 11:10:29 +0100 | [diff] [blame] | 2379 | static int __tipc_nl_add_stats(struct sk_buff *skb, struct tipc_stats *s) |
Richard Alpe | 7be57fc | 2014-11-20 10:29:12 +0100 | [diff] [blame] | 2380 | { |
| 2381 | int i; |
| 2382 | struct nlattr *stats; |
| 2383 | |
| 2384 | struct nla_map { |
| 2385 | u32 key; |
| 2386 | u32 val; |
| 2387 | }; |
| 2388 | |
| 2389 | struct nla_map map[] = { |
Jon Paul Maloy | 9590112 | 2016-11-25 10:35:02 -0500 | [diff] [blame] | 2390 | {TIPC_NLA_STATS_RX_INFO, 0}, |
Richard Alpe | 7be57fc | 2014-11-20 10:29:12 +0100 | [diff] [blame] | 2391 | {TIPC_NLA_STATS_RX_FRAGMENTS, s->recv_fragments}, |
| 2392 | {TIPC_NLA_STATS_RX_FRAGMENTED, s->recv_fragmented}, |
| 2393 | {TIPC_NLA_STATS_RX_BUNDLES, s->recv_bundles}, |
| 2394 | {TIPC_NLA_STATS_RX_BUNDLED, s->recv_bundled}, |
Jon Paul Maloy | 9590112 | 2016-11-25 10:35:02 -0500 | [diff] [blame] | 2395 | {TIPC_NLA_STATS_TX_INFO, 0}, |
Richard Alpe | 7be57fc | 2014-11-20 10:29:12 +0100 | [diff] [blame] | 2396 | {TIPC_NLA_STATS_TX_FRAGMENTS, s->sent_fragments}, |
| 2397 | {TIPC_NLA_STATS_TX_FRAGMENTED, s->sent_fragmented}, |
| 2398 | {TIPC_NLA_STATS_TX_BUNDLES, s->sent_bundles}, |
| 2399 | {TIPC_NLA_STATS_TX_BUNDLED, s->sent_bundled}, |
| 2400 | {TIPC_NLA_STATS_MSG_PROF_TOT, (s->msg_length_counts) ? |
| 2401 | s->msg_length_counts : 1}, |
| 2402 | {TIPC_NLA_STATS_MSG_LEN_CNT, s->msg_length_counts}, |
| 2403 | {TIPC_NLA_STATS_MSG_LEN_TOT, s->msg_lengths_total}, |
| 2404 | {TIPC_NLA_STATS_MSG_LEN_P0, s->msg_length_profile[0]}, |
| 2405 | {TIPC_NLA_STATS_MSG_LEN_P1, s->msg_length_profile[1]}, |
| 2406 | {TIPC_NLA_STATS_MSG_LEN_P2, s->msg_length_profile[2]}, |
| 2407 | {TIPC_NLA_STATS_MSG_LEN_P3, s->msg_length_profile[3]}, |
| 2408 | {TIPC_NLA_STATS_MSG_LEN_P4, s->msg_length_profile[4]}, |
| 2409 | {TIPC_NLA_STATS_MSG_LEN_P5, s->msg_length_profile[5]}, |
| 2410 | {TIPC_NLA_STATS_MSG_LEN_P6, s->msg_length_profile[6]}, |
| 2411 | {TIPC_NLA_STATS_RX_STATES, s->recv_states}, |
| 2412 | {TIPC_NLA_STATS_RX_PROBES, s->recv_probes}, |
| 2413 | {TIPC_NLA_STATS_RX_NACKS, s->recv_nacks}, |
| 2414 | {TIPC_NLA_STATS_RX_DEFERRED, s->deferred_recv}, |
| 2415 | {TIPC_NLA_STATS_TX_STATES, s->sent_states}, |
| 2416 | {TIPC_NLA_STATS_TX_PROBES, s->sent_probes}, |
| 2417 | {TIPC_NLA_STATS_TX_NACKS, s->sent_nacks}, |
| 2418 | {TIPC_NLA_STATS_TX_ACKS, s->sent_acks}, |
| 2419 | {TIPC_NLA_STATS_RETRANSMITTED, s->retransmitted}, |
| 2420 | {TIPC_NLA_STATS_DUPLICATES, s->duplicates}, |
| 2421 | {TIPC_NLA_STATS_LINK_CONGS, s->link_congs}, |
| 2422 | {TIPC_NLA_STATS_MAX_QUEUE, s->max_queue_sz}, |
| 2423 | {TIPC_NLA_STATS_AVG_QUEUE, s->queue_sz_counts ? |
| 2424 | (s->accu_queue_sz / s->queue_sz_counts) : 0} |
| 2425 | }; |
| 2426 | |
Michal Kubecek | ae0be8d | 2019-04-26 11:13:06 +0200 | [diff] [blame] | 2427 | stats = nla_nest_start_noflag(skb, TIPC_NLA_LINK_STATS); |
Richard Alpe | 7be57fc | 2014-11-20 10:29:12 +0100 | [diff] [blame] | 2428 | if (!stats) |
| 2429 | return -EMSGSIZE; |
| 2430 | |
| 2431 | for (i = 0; i < ARRAY_SIZE(map); i++) |
| 2432 | if (nla_put_u32(skb, map[i].key, map[i].val)) |
| 2433 | goto msg_full; |
| 2434 | |
| 2435 | nla_nest_end(skb, stats); |
| 2436 | |
| 2437 | return 0; |
| 2438 | msg_full: |
| 2439 | nla_nest_cancel(skb, stats); |
| 2440 | |
| 2441 | return -EMSGSIZE; |
| 2442 | } |
| 2443 | |
| 2444 | /* Caller should hold appropriate locks to protect the link */ |
Jon Paul Maloy | 5be9c08 | 2015-11-19 14:30:45 -0500 | [diff] [blame] | 2445 | int __tipc_nl_add_link(struct net *net, struct tipc_nl_msg *msg, |
| 2446 | struct tipc_link *link, int nlflags) |
Richard Alpe | 7be57fc | 2014-11-20 10:29:12 +0100 | [diff] [blame] | 2447 | { |
Jon Maloy | 23fd3ea | 2018-03-22 20:42:49 +0100 | [diff] [blame] | 2448 | u32 self = tipc_own_addr(net); |
Richard Alpe | 7be57fc | 2014-11-20 10:29:12 +0100 | [diff] [blame] | 2449 | struct nlattr *attrs; |
| 2450 | struct nlattr *prop; |
Jon Maloy | 23fd3ea | 2018-03-22 20:42:49 +0100 | [diff] [blame] | 2451 | void *hdr; |
| 2452 | int err; |
Richard Alpe | 7be57fc | 2014-11-20 10:29:12 +0100 | [diff] [blame] | 2453 | |
Richard Alpe | bfb3e5d | 2015-02-09 09:50:03 +0100 | [diff] [blame] | 2454 | hdr = genlmsg_put(msg->skb, msg->portid, msg->seq, &tipc_genl_family, |
Nicolas Dichtel | f2f6739 | 2015-04-28 18:33:50 +0200 | [diff] [blame] | 2455 | nlflags, TIPC_NL_LINK_GET); |
Richard Alpe | 7be57fc | 2014-11-20 10:29:12 +0100 | [diff] [blame] | 2456 | if (!hdr) |
| 2457 | return -EMSGSIZE; |
| 2458 | |
Michal Kubecek | ae0be8d | 2019-04-26 11:13:06 +0200 | [diff] [blame] | 2459 | attrs = nla_nest_start_noflag(msg->skb, TIPC_NLA_LINK); |
Richard Alpe | 7be57fc | 2014-11-20 10:29:12 +0100 | [diff] [blame] | 2460 | if (!attrs) |
| 2461 | goto msg_full; |
| 2462 | |
| 2463 | if (nla_put_string(msg->skb, TIPC_NLA_LINK_NAME, link->name)) |
| 2464 | goto attr_msg_full; |
Jon Maloy | 23fd3ea | 2018-03-22 20:42:49 +0100 | [diff] [blame] | 2465 | if (nla_put_u32(msg->skb, TIPC_NLA_LINK_DEST, tipc_cluster_mask(self))) |
Richard Alpe | 7be57fc | 2014-11-20 10:29:12 +0100 | [diff] [blame] | 2466 | goto attr_msg_full; |
Jon Paul Maloy | ed193ec | 2015-04-02 09:33:02 -0400 | [diff] [blame] | 2467 | if (nla_put_u32(msg->skb, TIPC_NLA_LINK_MTU, link->mtu)) |
Richard Alpe | 7be57fc | 2014-11-20 10:29:12 +0100 | [diff] [blame] | 2468 | goto attr_msg_full; |
Jon Paul Maloy | 9590112 | 2016-11-25 10:35:02 -0500 | [diff] [blame] | 2469 | if (nla_put_u32(msg->skb, TIPC_NLA_LINK_RX, link->stats.recv_pkts)) |
Richard Alpe | 7be57fc | 2014-11-20 10:29:12 +0100 | [diff] [blame] | 2470 | goto attr_msg_full; |
Jon Paul Maloy | 9590112 | 2016-11-25 10:35:02 -0500 | [diff] [blame] | 2471 | if (nla_put_u32(msg->skb, TIPC_NLA_LINK_TX, link->stats.sent_pkts)) |
Richard Alpe | 7be57fc | 2014-11-20 10:29:12 +0100 | [diff] [blame] | 2472 | goto attr_msg_full; |
| 2473 | |
| 2474 | if (tipc_link_is_up(link)) |
| 2475 | if (nla_put_flag(msg->skb, TIPC_NLA_LINK_UP)) |
| 2476 | goto attr_msg_full; |
Jon Paul Maloy | c72fa87 | 2015-10-22 08:51:46 -0400 | [diff] [blame] | 2477 | if (link->active) |
Richard Alpe | 7be57fc | 2014-11-20 10:29:12 +0100 | [diff] [blame] | 2478 | if (nla_put_flag(msg->skb, TIPC_NLA_LINK_ACTIVE)) |
| 2479 | goto attr_msg_full; |
| 2480 | |
Michal Kubecek | ae0be8d | 2019-04-26 11:13:06 +0200 | [diff] [blame] | 2481 | prop = nla_nest_start_noflag(msg->skb, TIPC_NLA_LINK_PROP); |
Richard Alpe | 7be57fc | 2014-11-20 10:29:12 +0100 | [diff] [blame] | 2482 | if (!prop) |
| 2483 | goto attr_msg_full; |
| 2484 | if (nla_put_u32(msg->skb, TIPC_NLA_PROP_PRIO, link->priority)) |
| 2485 | goto prop_msg_full; |
| 2486 | if (nla_put_u32(msg->skb, TIPC_NLA_PROP_TOL, link->tolerance)) |
| 2487 | goto prop_msg_full; |
| 2488 | if (nla_put_u32(msg->skb, TIPC_NLA_PROP_WIN, |
Jon Paul Maloy | 1f66d16 | 2015-03-25 12:07:24 -0400 | [diff] [blame] | 2489 | link->window)) |
Richard Alpe | 7be57fc | 2014-11-20 10:29:12 +0100 | [diff] [blame] | 2490 | goto prop_msg_full; |
| 2491 | if (nla_put_u32(msg->skb, TIPC_NLA_PROP_PRIO, link->priority)) |
| 2492 | goto prop_msg_full; |
| 2493 | nla_nest_end(msg->skb, prop); |
| 2494 | |
| 2495 | err = __tipc_nl_add_stats(msg->skb, &link->stats); |
| 2496 | if (err) |
| 2497 | goto attr_msg_full; |
| 2498 | |
| 2499 | nla_nest_end(msg->skb, attrs); |
| 2500 | genlmsg_end(msg->skb, hdr); |
| 2501 | |
| 2502 | return 0; |
| 2503 | |
| 2504 | prop_msg_full: |
| 2505 | nla_nest_cancel(msg->skb, prop); |
| 2506 | attr_msg_full: |
| 2507 | nla_nest_cancel(msg->skb, attrs); |
| 2508 | msg_full: |
| 2509 | genlmsg_cancel(msg->skb, hdr); |
| 2510 | |
| 2511 | return -EMSGSIZE; |
| 2512 | } |
Jon Paul Maloy | 38206d5 | 2015-11-19 14:30:46 -0500 | [diff] [blame] | 2513 | |
| 2514 | static int __tipc_nl_add_bc_link_stat(struct sk_buff *skb, |
| 2515 | struct tipc_stats *stats) |
| 2516 | { |
| 2517 | int i; |
| 2518 | struct nlattr *nest; |
| 2519 | |
| 2520 | struct nla_map { |
| 2521 | __u32 key; |
| 2522 | __u32 val; |
| 2523 | }; |
| 2524 | |
| 2525 | struct nla_map map[] = { |
Jon Paul Maloy | 9590112 | 2016-11-25 10:35:02 -0500 | [diff] [blame] | 2526 | {TIPC_NLA_STATS_RX_INFO, stats->recv_pkts}, |
Jon Paul Maloy | 38206d5 | 2015-11-19 14:30:46 -0500 | [diff] [blame] | 2527 | {TIPC_NLA_STATS_RX_FRAGMENTS, stats->recv_fragments}, |
| 2528 | {TIPC_NLA_STATS_RX_FRAGMENTED, stats->recv_fragmented}, |
| 2529 | {TIPC_NLA_STATS_RX_BUNDLES, stats->recv_bundles}, |
| 2530 | {TIPC_NLA_STATS_RX_BUNDLED, stats->recv_bundled}, |
Jon Paul Maloy | 9590112 | 2016-11-25 10:35:02 -0500 | [diff] [blame] | 2531 | {TIPC_NLA_STATS_TX_INFO, stats->sent_pkts}, |
Jon Paul Maloy | 38206d5 | 2015-11-19 14:30:46 -0500 | [diff] [blame] | 2532 | {TIPC_NLA_STATS_TX_FRAGMENTS, stats->sent_fragments}, |
| 2533 | {TIPC_NLA_STATS_TX_FRAGMENTED, stats->sent_fragmented}, |
| 2534 | {TIPC_NLA_STATS_TX_BUNDLES, stats->sent_bundles}, |
| 2535 | {TIPC_NLA_STATS_TX_BUNDLED, stats->sent_bundled}, |
| 2536 | {TIPC_NLA_STATS_RX_NACKS, stats->recv_nacks}, |
| 2537 | {TIPC_NLA_STATS_RX_DEFERRED, stats->deferred_recv}, |
| 2538 | {TIPC_NLA_STATS_TX_NACKS, stats->sent_nacks}, |
| 2539 | {TIPC_NLA_STATS_TX_ACKS, stats->sent_acks}, |
| 2540 | {TIPC_NLA_STATS_RETRANSMITTED, stats->retransmitted}, |
| 2541 | {TIPC_NLA_STATS_DUPLICATES, stats->duplicates}, |
| 2542 | {TIPC_NLA_STATS_LINK_CONGS, stats->link_congs}, |
| 2543 | {TIPC_NLA_STATS_MAX_QUEUE, stats->max_queue_sz}, |
| 2544 | {TIPC_NLA_STATS_AVG_QUEUE, stats->queue_sz_counts ? |
| 2545 | (stats->accu_queue_sz / stats->queue_sz_counts) : 0} |
| 2546 | }; |
| 2547 | |
Michal Kubecek | ae0be8d | 2019-04-26 11:13:06 +0200 | [diff] [blame] | 2548 | nest = nla_nest_start_noflag(skb, TIPC_NLA_LINK_STATS); |
Jon Paul Maloy | 38206d5 | 2015-11-19 14:30:46 -0500 | [diff] [blame] | 2549 | if (!nest) |
| 2550 | return -EMSGSIZE; |
| 2551 | |
| 2552 | for (i = 0; i < ARRAY_SIZE(map); i++) |
| 2553 | if (nla_put_u32(skb, map[i].key, map[i].val)) |
| 2554 | goto msg_full; |
| 2555 | |
| 2556 | nla_nest_end(skb, nest); |
| 2557 | |
| 2558 | return 0; |
| 2559 | msg_full: |
| 2560 | nla_nest_cancel(skb, nest); |
| 2561 | |
| 2562 | return -EMSGSIZE; |
| 2563 | } |
| 2564 | |
| 2565 | int tipc_nl_add_bc_link(struct net *net, struct tipc_nl_msg *msg) |
| 2566 | { |
| 2567 | int err; |
| 2568 | void *hdr; |
| 2569 | struct nlattr *attrs; |
| 2570 | struct nlattr *prop; |
| 2571 | struct tipc_net *tn = net_generic(net, tipc_net_id); |
Hoang Le | 02ec6ca | 2019-03-19 18:49:48 +0700 | [diff] [blame] | 2572 | u32 bc_mode = tipc_bcast_get_broadcast_mode(net); |
| 2573 | u32 bc_ratio = tipc_bcast_get_broadcast_ratio(net); |
Jon Paul Maloy | 38206d5 | 2015-11-19 14:30:46 -0500 | [diff] [blame] | 2574 | struct tipc_link *bcl = tn->bcl; |
| 2575 | |
| 2576 | if (!bcl) |
| 2577 | return 0; |
| 2578 | |
| 2579 | tipc_bcast_lock(net); |
| 2580 | |
| 2581 | hdr = genlmsg_put(msg->skb, msg->portid, msg->seq, &tipc_genl_family, |
| 2582 | NLM_F_MULTI, TIPC_NL_LINK_GET); |
Insu Yun | b53ce3e | 2016-02-17 11:47:35 -0500 | [diff] [blame] | 2583 | if (!hdr) { |
| 2584 | tipc_bcast_unlock(net); |
Jon Paul Maloy | 38206d5 | 2015-11-19 14:30:46 -0500 | [diff] [blame] | 2585 | return -EMSGSIZE; |
Insu Yun | b53ce3e | 2016-02-17 11:47:35 -0500 | [diff] [blame] | 2586 | } |
Jon Paul Maloy | 38206d5 | 2015-11-19 14:30:46 -0500 | [diff] [blame] | 2587 | |
Michal Kubecek | ae0be8d | 2019-04-26 11:13:06 +0200 | [diff] [blame] | 2588 | attrs = nla_nest_start_noflag(msg->skb, TIPC_NLA_LINK); |
Jon Paul Maloy | 38206d5 | 2015-11-19 14:30:46 -0500 | [diff] [blame] | 2589 | if (!attrs) |
| 2590 | goto msg_full; |
| 2591 | |
| 2592 | /* The broadcast link is always up */ |
| 2593 | if (nla_put_flag(msg->skb, TIPC_NLA_LINK_UP)) |
| 2594 | goto attr_msg_full; |
| 2595 | |
| 2596 | if (nla_put_flag(msg->skb, TIPC_NLA_LINK_BROADCAST)) |
| 2597 | goto attr_msg_full; |
| 2598 | if (nla_put_string(msg->skb, TIPC_NLA_LINK_NAME, bcl->name)) |
| 2599 | goto attr_msg_full; |
Jon Paul Maloy | 9590112 | 2016-11-25 10:35:02 -0500 | [diff] [blame] | 2600 | if (nla_put_u32(msg->skb, TIPC_NLA_LINK_RX, 0)) |
Jon Paul Maloy | 38206d5 | 2015-11-19 14:30:46 -0500 | [diff] [blame] | 2601 | goto attr_msg_full; |
Jon Paul Maloy | 9590112 | 2016-11-25 10:35:02 -0500 | [diff] [blame] | 2602 | if (nla_put_u32(msg->skb, TIPC_NLA_LINK_TX, 0)) |
Jon Paul Maloy | 38206d5 | 2015-11-19 14:30:46 -0500 | [diff] [blame] | 2603 | goto attr_msg_full; |
| 2604 | |
Michal Kubecek | ae0be8d | 2019-04-26 11:13:06 +0200 | [diff] [blame] | 2605 | prop = nla_nest_start_noflag(msg->skb, TIPC_NLA_LINK_PROP); |
Jon Paul Maloy | 38206d5 | 2015-11-19 14:30:46 -0500 | [diff] [blame] | 2606 | if (!prop) |
| 2607 | goto attr_msg_full; |
| 2608 | if (nla_put_u32(msg->skb, TIPC_NLA_PROP_WIN, bcl->window)) |
| 2609 | goto prop_msg_full; |
Hoang Le | 02ec6ca | 2019-03-19 18:49:48 +0700 | [diff] [blame] | 2610 | if (nla_put_u32(msg->skb, TIPC_NLA_PROP_BROADCAST, bc_mode)) |
| 2611 | goto prop_msg_full; |
| 2612 | if (bc_mode & BCLINK_MODE_SEL) |
| 2613 | if (nla_put_u32(msg->skb, TIPC_NLA_PROP_BROADCAST_RATIO, |
| 2614 | bc_ratio)) |
| 2615 | goto prop_msg_full; |
Jon Paul Maloy | 38206d5 | 2015-11-19 14:30:46 -0500 | [diff] [blame] | 2616 | nla_nest_end(msg->skb, prop); |
| 2617 | |
| 2618 | err = __tipc_nl_add_bc_link_stat(msg->skb, &bcl->stats); |
| 2619 | if (err) |
| 2620 | goto attr_msg_full; |
| 2621 | |
| 2622 | tipc_bcast_unlock(net); |
| 2623 | nla_nest_end(msg->skb, attrs); |
| 2624 | genlmsg_end(msg->skb, hdr); |
| 2625 | |
| 2626 | return 0; |
| 2627 | |
| 2628 | prop_msg_full: |
| 2629 | nla_nest_cancel(msg->skb, prop); |
| 2630 | attr_msg_full: |
| 2631 | nla_nest_cancel(msg->skb, attrs); |
| 2632 | msg_full: |
| 2633 | tipc_bcast_unlock(net); |
| 2634 | genlmsg_cancel(msg->skb, hdr); |
| 2635 | |
| 2636 | return -EMSGSIZE; |
| 2637 | } |
| 2638 | |
Richard Alpe | d01332f | 2016-02-01 08:19:56 +0100 | [diff] [blame] | 2639 | void tipc_link_set_tolerance(struct tipc_link *l, u32 tol, |
| 2640 | struct sk_buff_head *xmitq) |
Jon Paul Maloy | 38206d5 | 2015-11-19 14:30:46 -0500 | [diff] [blame] | 2641 | { |
| 2642 | l->tolerance = tol; |
Jon Maloy | 047491e | 2018-10-10 17:34:01 +0200 | [diff] [blame] | 2643 | if (l->bc_rcvlink) |
| 2644 | l->bc_rcvlink->tolerance = tol; |
Jon Maloy | 37c64cf | 2018-02-14 13:34:39 +0100 | [diff] [blame] | 2645 | if (link_is_up(l)) |
| 2646 | tipc_link_build_proto_msg(l, STATE_MSG, 0, 0, 0, tol, 0, xmitq); |
Jon Paul Maloy | 38206d5 | 2015-11-19 14:30:46 -0500 | [diff] [blame] | 2647 | } |
| 2648 | |
Richard Alpe | d01332f | 2016-02-01 08:19:56 +0100 | [diff] [blame] | 2649 | void tipc_link_set_prio(struct tipc_link *l, u32 prio, |
| 2650 | struct sk_buff_head *xmitq) |
Jon Paul Maloy | 38206d5 | 2015-11-19 14:30:46 -0500 | [diff] [blame] | 2651 | { |
| 2652 | l->priority = prio; |
Jon Maloy | 8d6e79d | 2017-11-08 09:59:26 +0100 | [diff] [blame] | 2653 | tipc_link_build_proto_msg(l, STATE_MSG, 0, 0, 0, 0, prio, xmitq); |
Jon Paul Maloy | 38206d5 | 2015-11-19 14:30:46 -0500 | [diff] [blame] | 2654 | } |
| 2655 | |
| 2656 | void tipc_link_set_abort_limit(struct tipc_link *l, u32 limit) |
| 2657 | { |
| 2658 | l->abort_limit = limit; |
| 2659 | } |
Tuong Lien | b4b9771 | 2018-12-19 09:17:56 +0700 | [diff] [blame] | 2660 | |
| 2661 | char *tipc_link_name_ext(struct tipc_link *l, char *buf) |
| 2662 | { |
| 2663 | if (!l) |
| 2664 | scnprintf(buf, TIPC_MAX_LINK_NAME, "null"); |
| 2665 | else if (link_is_bc_sndlink(l)) |
| 2666 | scnprintf(buf, TIPC_MAX_LINK_NAME, "broadcast-sender"); |
| 2667 | else if (link_is_bc_rcvlink(l)) |
| 2668 | scnprintf(buf, TIPC_MAX_LINK_NAME, |
| 2669 | "broadcast-receiver, peer %x", l->addr); |
| 2670 | else |
| 2671 | memcpy(buf, l->name, TIPC_MAX_LINK_NAME); |
| 2672 | |
| 2673 | return buf; |
| 2674 | } |
| 2675 | |
| 2676 | /** |
| 2677 | * tipc_link_dump - dump TIPC link data |
| 2678 | * @l: tipc link to be dumped |
| 2679 | * @dqueues: bitmask to decide if any link queue to be dumped? |
| 2680 | * - TIPC_DUMP_NONE: don't dump link queues |
| 2681 | * - TIPC_DUMP_TRANSMQ: dump link transmq queue |
| 2682 | * - TIPC_DUMP_BACKLOGQ: dump link backlog queue |
| 2683 | * - TIPC_DUMP_DEFERDQ: dump link deferd queue |
| 2684 | * - TIPC_DUMP_INPUTQ: dump link input queue |
| 2685 | * - TIPC_DUMP_WAKEUP: dump link wakeup queue |
| 2686 | * - TIPC_DUMP_ALL: dump all the link queues above |
| 2687 | * @buf: returned buffer of dump data in format |
| 2688 | */ |
| 2689 | int tipc_link_dump(struct tipc_link *l, u16 dqueues, char *buf) |
| 2690 | { |
| 2691 | int i = 0; |
| 2692 | size_t sz = (dqueues) ? LINK_LMAX : LINK_LMIN; |
| 2693 | struct sk_buff_head *list; |
| 2694 | struct sk_buff *hskb, *tskb; |
| 2695 | u32 len; |
| 2696 | |
| 2697 | if (!l) { |
| 2698 | i += scnprintf(buf, sz, "link data: (null)\n"); |
| 2699 | return i; |
| 2700 | } |
| 2701 | |
| 2702 | i += scnprintf(buf, sz, "link data: %x", l->addr); |
| 2703 | i += scnprintf(buf + i, sz - i, " %x", l->state); |
| 2704 | i += scnprintf(buf + i, sz - i, " %u", l->in_session); |
| 2705 | i += scnprintf(buf + i, sz - i, " %u", l->session); |
| 2706 | i += scnprintf(buf + i, sz - i, " %u", l->peer_session); |
| 2707 | i += scnprintf(buf + i, sz - i, " %u", l->snd_nxt); |
| 2708 | i += scnprintf(buf + i, sz - i, " %u", l->rcv_nxt); |
| 2709 | i += scnprintf(buf + i, sz - i, " %u", l->snd_nxt_state); |
| 2710 | i += scnprintf(buf + i, sz - i, " %u", l->rcv_nxt_state); |
| 2711 | i += scnprintf(buf + i, sz - i, " %x", l->peer_caps); |
| 2712 | i += scnprintf(buf + i, sz - i, " %u", l->silent_intv_cnt); |
| 2713 | i += scnprintf(buf + i, sz - i, " %u", l->rst_cnt); |
Tuong Lien | 7120423 | 2019-08-15 10:24:08 +0700 | [diff] [blame] | 2714 | i += scnprintf(buf + i, sz - i, " %u", 0); |
Jon Maloy | 77cf8ed | 2019-06-25 17:36:43 +0200 | [diff] [blame] | 2715 | i += scnprintf(buf + i, sz - i, " %u", 0); |
Tuong Lien | b4b9771 | 2018-12-19 09:17:56 +0700 | [diff] [blame] | 2716 | i += scnprintf(buf + i, sz - i, " %u", l->acked); |
| 2717 | |
| 2718 | list = &l->transmq; |
| 2719 | len = skb_queue_len(list); |
| 2720 | hskb = skb_peek(list); |
| 2721 | tskb = skb_peek_tail(list); |
| 2722 | i += scnprintf(buf + i, sz - i, " | %u %u %u", len, |
| 2723 | (hskb) ? msg_seqno(buf_msg(hskb)) : 0, |
| 2724 | (tskb) ? msg_seqno(buf_msg(tskb)) : 0); |
| 2725 | |
| 2726 | list = &l->deferdq; |
| 2727 | len = skb_queue_len(list); |
| 2728 | hskb = skb_peek(list); |
| 2729 | tskb = skb_peek_tail(list); |
| 2730 | i += scnprintf(buf + i, sz - i, " | %u %u %u", len, |
| 2731 | (hskb) ? msg_seqno(buf_msg(hskb)) : 0, |
| 2732 | (tskb) ? msg_seqno(buf_msg(tskb)) : 0); |
| 2733 | |
| 2734 | list = &l->backlogq; |
| 2735 | len = skb_queue_len(list); |
| 2736 | hskb = skb_peek(list); |
| 2737 | tskb = skb_peek_tail(list); |
| 2738 | i += scnprintf(buf + i, sz - i, " | %u %u %u", len, |
| 2739 | (hskb) ? msg_seqno(buf_msg(hskb)) : 0, |
| 2740 | (tskb) ? msg_seqno(buf_msg(tskb)) : 0); |
| 2741 | |
| 2742 | list = l->inputq; |
| 2743 | len = skb_queue_len(list); |
| 2744 | hskb = skb_peek(list); |
| 2745 | tskb = skb_peek_tail(list); |
| 2746 | i += scnprintf(buf + i, sz - i, " | %u %u %u\n", len, |
| 2747 | (hskb) ? msg_seqno(buf_msg(hskb)) : 0, |
| 2748 | (tskb) ? msg_seqno(buf_msg(tskb)) : 0); |
| 2749 | |
| 2750 | if (dqueues & TIPC_DUMP_TRANSMQ) { |
| 2751 | i += scnprintf(buf + i, sz - i, "transmq: "); |
| 2752 | i += tipc_list_dump(&l->transmq, false, buf + i); |
| 2753 | } |
| 2754 | if (dqueues & TIPC_DUMP_BACKLOGQ) { |
| 2755 | i += scnprintf(buf + i, sz - i, |
| 2756 | "backlogq: <%u %u %u %u %u>, ", |
| 2757 | l->backlog[TIPC_LOW_IMPORTANCE].len, |
| 2758 | l->backlog[TIPC_MEDIUM_IMPORTANCE].len, |
| 2759 | l->backlog[TIPC_HIGH_IMPORTANCE].len, |
| 2760 | l->backlog[TIPC_CRITICAL_IMPORTANCE].len, |
| 2761 | l->backlog[TIPC_SYSTEM_IMPORTANCE].len); |
| 2762 | i += tipc_list_dump(&l->backlogq, false, buf + i); |
| 2763 | } |
| 2764 | if (dqueues & TIPC_DUMP_DEFERDQ) { |
| 2765 | i += scnprintf(buf + i, sz - i, "deferdq: "); |
| 2766 | i += tipc_list_dump(&l->deferdq, false, buf + i); |
| 2767 | } |
| 2768 | if (dqueues & TIPC_DUMP_INPUTQ) { |
| 2769 | i += scnprintf(buf + i, sz - i, "inputq: "); |
| 2770 | i += tipc_list_dump(l->inputq, false, buf + i); |
| 2771 | } |
| 2772 | if (dqueues & TIPC_DUMP_WAKEUP) { |
| 2773 | i += scnprintf(buf + i, sz - i, "wakeup: "); |
| 2774 | i += tipc_list_dump(&l->wakeupq, false, buf + i); |
| 2775 | } |
| 2776 | |
| 2777 | return i; |
| 2778 | } |