Commit | Line | Data |
---|---|---|
b97bf3fd PL |
1 | /* |
2 | * net/tipc/link.c: TIPC link code | |
c4307285 | 3 | * |
c64f7a6a | 4 | * Copyright (c) 1996-2007, 2012, Ericsson AB |
198d73b8 | 5 | * Copyright (c) 2004-2007, 2010-2013, Wind River Systems |
b97bf3fd PL |
6 | * All rights reserved. |
7 | * | |
9ea1fd3c | 8 | * Redistribution and use in source and binary forms, with or without |
b97bf3fd PL |
9 | * modification, are permitted provided that the following conditions are met: |
10 | * | |
9ea1fd3c PL |
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. | |
b97bf3fd | 19 | * |
9ea1fd3c PL |
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 | |
b97bf3fd PL |
34 | * POSSIBILITY OF SUCH DAMAGE. |
35 | */ | |
36 | ||
37 | #include "core.h" | |
b97bf3fd | 38 | #include "link.h" |
b97bf3fd | 39 | #include "port.h" |
b97bf3fd | 40 | #include "name_distr.h" |
b97bf3fd PL |
41 | #include "discover.h" |
42 | #include "config.h" | |
b97bf3fd | 43 | |
796c75d0 YX |
44 | #include <linux/pkt_sched.h> |
45 | ||
2cf8aa19 EH |
46 | /* |
47 | * Error message prefixes | |
48 | */ | |
49 | static const char *link_co_err = "Link changeover error, "; | |
50 | static const char *link_rst_msg = "Resetting link "; | |
51 | static const char *link_unk_evt = "Unknown link event "; | |
b97bf3fd | 52 | |
a686e685 AS |
53 | /* |
54 | * Out-of-range value for link session numbers | |
55 | */ | |
a686e685 AS |
56 | #define INVALID_SESSION 0x10000 |
57 | ||
c4307285 YH |
58 | /* |
59 | * Link state events: | |
b97bf3fd | 60 | */ |
b97bf3fd PL |
61 | #define STARTING_EVT 856384768 /* link processing trigger */ |
62 | #define TRAFFIC_MSG_EVT 560815u /* rx'd ??? */ | |
63 | #define TIMEOUT_EVT 560817u /* link timer expired */ | |
64 | ||
c4307285 YH |
65 | /* |
66 | * The following two 'message types' is really just implementation | |
67 | * data conveniently stored in the message header. | |
b97bf3fd PL |
68 | * They must not be considered part of the protocol |
69 | */ | |
70 | #define OPEN_MSG 0 | |
71 | #define CLOSED_MSG 1 | |
72 | ||
c4307285 | 73 | /* |
b97bf3fd PL |
74 | * State value stored in 'exp_msg_count' |
75 | */ | |
b97bf3fd PL |
76 | #define START_CHANGEOVER 100000u |
77 | ||
a18c4bc3 | 78 | static void link_handle_out_of_seq_msg(struct tipc_link *l_ptr, |
b97bf3fd | 79 | struct sk_buff *buf); |
a18c4bc3 PG |
80 | static void link_recv_proto_msg(struct tipc_link *l_ptr, struct sk_buff *buf); |
81 | static int link_recv_changeover_msg(struct tipc_link **l_ptr, | |
82 | struct sk_buff **buf); | |
83 | static void link_set_supervision_props(struct tipc_link *l_ptr, u32 tolerance); | |
23dd4cce | 84 | static int link_send_sections_long(struct tipc_port *sender, |
b97bf3fd | 85 | struct iovec const *msg_sect, |
9446b87a | 86 | unsigned int len, u32 destnode); |
a18c4bc3 PG |
87 | static void link_state_event(struct tipc_link *l_ptr, u32 event); |
88 | static void link_reset_statistics(struct tipc_link *l_ptr); | |
89 | static void link_print(struct tipc_link *l_ptr, const char *str); | |
90 | static void link_start(struct tipc_link *l_ptr); | |
91 | static int link_send_long_buf(struct tipc_link *l_ptr, struct sk_buff *buf); | |
c64f7a6a JM |
92 | static void tipc_link_send_sync(struct tipc_link *l); |
93 | static void tipc_link_recv_sync(struct tipc_node *n, struct sk_buff *buf); | |
31e3c3f6 | 94 | |
b97bf3fd | 95 | /* |
05790c64 | 96 | * Simple link routines |
b97bf3fd | 97 | */ |
05790c64 | 98 | static unsigned int align(unsigned int i) |
b97bf3fd PL |
99 | { |
100 | return (i + 3) & ~3u; | |
101 | } | |
102 | ||
a18c4bc3 | 103 | static void link_init_max_pkt(struct tipc_link *l_ptr) |
b97bf3fd PL |
104 | { |
105 | u32 max_pkt; | |
c4307285 | 106 | |
2d627b92 | 107 | max_pkt = (l_ptr->b_ptr->mtu & ~3); |
b97bf3fd PL |
108 | if (max_pkt > MAX_MSG_SIZE) |
109 | max_pkt = MAX_MSG_SIZE; | |
110 | ||
c4307285 | 111 | l_ptr->max_pkt_target = max_pkt; |
b97bf3fd PL |
112 | if (l_ptr->max_pkt_target < MAX_PKT_DEFAULT) |
113 | l_ptr->max_pkt = l_ptr->max_pkt_target; | |
c4307285 | 114 | else |
b97bf3fd PL |
115 | l_ptr->max_pkt = MAX_PKT_DEFAULT; |
116 | ||
c4307285 | 117 | l_ptr->max_pkt_probes = 0; |
b97bf3fd PL |
118 | } |
119 | ||
a18c4bc3 | 120 | static u32 link_next_sent(struct tipc_link *l_ptr) |
b97bf3fd PL |
121 | { |
122 | if (l_ptr->next_out) | |
f905730c | 123 | return buf_seqno(l_ptr->next_out); |
b97bf3fd PL |
124 | return mod(l_ptr->next_out_no); |
125 | } | |
126 | ||
a18c4bc3 | 127 | static u32 link_last_sent(struct tipc_link *l_ptr) |
b97bf3fd PL |
128 | { |
129 | return mod(link_next_sent(l_ptr) - 1); | |
130 | } | |
131 | ||
132 | /* | |
05790c64 | 133 | * Simple non-static link routines (i.e. referenced outside this file) |
b97bf3fd | 134 | */ |
a18c4bc3 | 135 | int tipc_link_is_up(struct tipc_link *l_ptr) |
b97bf3fd PL |
136 | { |
137 | if (!l_ptr) | |
138 | return 0; | |
a02cec21 | 139 | return link_working_working(l_ptr) || link_working_unknown(l_ptr); |
b97bf3fd PL |
140 | } |
141 | ||
a18c4bc3 | 142 | int tipc_link_is_active(struct tipc_link *l_ptr) |
b97bf3fd | 143 | { |
a02cec21 ED |
144 | return (l_ptr->owner->active_links[0] == l_ptr) || |
145 | (l_ptr->owner->active_links[1] == l_ptr); | |
b97bf3fd PL |
146 | } |
147 | ||
b97bf3fd PL |
148 | /** |
149 | * link_timeout - handle expiration of link timer | |
150 | * @l_ptr: pointer to link | |
c4307285 | 151 | * |
4323add6 PL |
152 | * This routine must not grab "tipc_net_lock" to avoid a potential deadlock conflict |
153 | * with tipc_link_delete(). (There is no risk that the node will be deleted by | |
154 | * another thread because tipc_link_delete() always cancels the link timer before | |
155 | * tipc_node_delete() is called.) | |
b97bf3fd | 156 | */ |
a18c4bc3 | 157 | static void link_timeout(struct tipc_link *l_ptr) |
b97bf3fd | 158 | { |
4323add6 | 159 | tipc_node_lock(l_ptr->owner); |
b97bf3fd PL |
160 | |
161 | /* update counters used in statistical profiling of send traffic */ | |
b97bf3fd PL |
162 | l_ptr->stats.accu_queue_sz += l_ptr->out_queue_size; |
163 | l_ptr->stats.queue_sz_counts++; | |
164 | ||
b97bf3fd PL |
165 | if (l_ptr->first_out) { |
166 | struct tipc_msg *msg = buf_msg(l_ptr->first_out); | |
167 | u32 length = msg_size(msg); | |
168 | ||
f64f9e71 JP |
169 | if ((msg_user(msg) == MSG_FRAGMENTER) && |
170 | (msg_type(msg) == FIRST_FRAGMENT)) { | |
b97bf3fd PL |
171 | length = msg_size(msg_get_wrapped(msg)); |
172 | } | |
173 | if (length) { | |
174 | l_ptr->stats.msg_lengths_total += length; | |
175 | l_ptr->stats.msg_length_counts++; | |
176 | if (length <= 64) | |
177 | l_ptr->stats.msg_length_profile[0]++; | |
178 | else if (length <= 256) | |
179 | l_ptr->stats.msg_length_profile[1]++; | |
180 | else if (length <= 1024) | |
181 | l_ptr->stats.msg_length_profile[2]++; | |
182 | else if (length <= 4096) | |
183 | l_ptr->stats.msg_length_profile[3]++; | |
184 | else if (length <= 16384) | |
185 | l_ptr->stats.msg_length_profile[4]++; | |
186 | else if (length <= 32768) | |
187 | l_ptr->stats.msg_length_profile[5]++; | |
188 | else | |
189 | l_ptr->stats.msg_length_profile[6]++; | |
190 | } | |
191 | } | |
192 | ||
193 | /* do all other link processing performed on a periodic basis */ | |
b97bf3fd PL |
194 | |
195 | link_state_event(l_ptr, TIMEOUT_EVT); | |
196 | ||
197 | if (l_ptr->next_out) | |
4323add6 | 198 | tipc_link_push_queue(l_ptr); |
b97bf3fd | 199 | |
4323add6 | 200 | tipc_node_unlock(l_ptr->owner); |
b97bf3fd PL |
201 | } |
202 | ||
a18c4bc3 | 203 | static void link_set_timer(struct tipc_link *l_ptr, u32 time) |
b97bf3fd PL |
204 | { |
205 | k_start_timer(&l_ptr->timer, time); | |
206 | } | |
207 | ||
208 | /** | |
4323add6 | 209 | * tipc_link_create - create a new link |
37b9c08a | 210 | * @n_ptr: pointer to associated node |
b97bf3fd | 211 | * @b_ptr: pointer to associated bearer |
b97bf3fd | 212 | * @media_addr: media address to use when sending messages over link |
c4307285 | 213 | * |
b97bf3fd PL |
214 | * Returns pointer to link. |
215 | */ | |
a18c4bc3 | 216 | struct tipc_link *tipc_link_create(struct tipc_node *n_ptr, |
37b9c08a | 217 | struct tipc_bearer *b_ptr, |
4323add6 | 218 | const struct tipc_media_addr *media_addr) |
b97bf3fd | 219 | { |
a18c4bc3 | 220 | struct tipc_link *l_ptr; |
b97bf3fd PL |
221 | struct tipc_msg *msg; |
222 | char *if_name; | |
37b9c08a AS |
223 | char addr_string[16]; |
224 | u32 peer = n_ptr->addr; | |
225 | ||
226 | if (n_ptr->link_cnt >= 2) { | |
227 | tipc_addr_string_fill(addr_string, n_ptr->addr); | |
2cf8aa19 | 228 | pr_err("Attempt to establish third link to %s\n", addr_string); |
37b9c08a AS |
229 | return NULL; |
230 | } | |
231 | ||
232 | if (n_ptr->links[b_ptr->identity]) { | |
233 | tipc_addr_string_fill(addr_string, n_ptr->addr); | |
2cf8aa19 EH |
234 | pr_err("Attempt to establish second link on <%s> to %s\n", |
235 | b_ptr->name, addr_string); | |
37b9c08a AS |
236 | return NULL; |
237 | } | |
b97bf3fd | 238 | |
0da974f4 | 239 | l_ptr = kzalloc(sizeof(*l_ptr), GFP_ATOMIC); |
b97bf3fd | 240 | if (!l_ptr) { |
2cf8aa19 | 241 | pr_warn("Link creation failed, no memory\n"); |
b97bf3fd PL |
242 | return NULL; |
243 | } | |
b97bf3fd PL |
244 | |
245 | l_ptr->addr = peer; | |
2d627b92 | 246 | if_name = strchr(b_ptr->name, ':') + 1; |
062b4c99 | 247 | sprintf(l_ptr->name, "%u.%u.%u:%s-%u.%u.%u:unknown", |
b97bf3fd | 248 | tipc_zone(tipc_own_addr), tipc_cluster(tipc_own_addr), |
c4307285 | 249 | tipc_node(tipc_own_addr), |
b97bf3fd PL |
250 | if_name, |
251 | tipc_zone(peer), tipc_cluster(peer), tipc_node(peer)); | |
062b4c99 | 252 | /* note: peer i/f name is updated by reset/activate message */ |
b97bf3fd | 253 | memcpy(&l_ptr->media_addr, media_addr, sizeof(*media_addr)); |
37b9c08a | 254 | l_ptr->owner = n_ptr; |
b97bf3fd | 255 | l_ptr->checkpoint = 1; |
f882cb76 | 256 | l_ptr->peer_session = INVALID_SESSION; |
b97bf3fd | 257 | l_ptr->b_ptr = b_ptr; |
5c216e1d | 258 | link_set_supervision_props(l_ptr, b_ptr->tolerance); |
b97bf3fd PL |
259 | l_ptr->state = RESET_UNKNOWN; |
260 | ||
261 | l_ptr->pmsg = (struct tipc_msg *)&l_ptr->proto_msg; | |
262 | msg = l_ptr->pmsg; | |
c68ca7b7 | 263 | tipc_msg_init(msg, LINK_PROTOCOL, RESET_MSG, INT_H_SIZE, l_ptr->addr); |
b97bf3fd | 264 | msg_set_size(msg, sizeof(l_ptr->proto_msg)); |
a686e685 | 265 | msg_set_session(msg, (tipc_random & 0xffff)); |
b97bf3fd PL |
266 | msg_set_bearer_id(msg, b_ptr->identity); |
267 | strcpy((char *)msg_data(msg), if_name); | |
268 | ||
269 | l_ptr->priority = b_ptr->priority; | |
5c216e1d | 270 | tipc_link_set_queue_limits(l_ptr, b_ptr->window); |
b97bf3fd PL |
271 | |
272 | link_init_max_pkt(l_ptr); | |
273 | ||
274 | l_ptr->next_out_no = 1; | |
275 | INIT_LIST_HEAD(&l_ptr->waiting_ports); | |
276 | ||
277 | link_reset_statistics(l_ptr); | |
278 | ||
37b9c08a | 279 | tipc_node_attach_link(n_ptr, l_ptr); |
b97bf3fd | 280 | |
94571065 FW |
281 | k_init_timer(&l_ptr->timer, (Handler)link_timeout, (unsigned long)l_ptr); |
282 | list_add_tail(&l_ptr->link_list, &b_ptr->links); | |
31e3c3f6 | 283 | tipc_k_signal((Handler)link_start, (unsigned long)l_ptr); |
b97bf3fd | 284 | |
b97bf3fd PL |
285 | return l_ptr; |
286 | } | |
287 | ||
c4307285 | 288 | /** |
4323add6 | 289 | * tipc_link_delete - delete a link |
b97bf3fd | 290 | * @l_ptr: pointer to link |
c4307285 | 291 | * |
4323add6 | 292 | * Note: 'tipc_net_lock' is write_locked, bearer is locked. |
b97bf3fd | 293 | * This routine must not grab the node lock until after link timer cancellation |
c4307285 | 294 | * to avoid a potential deadlock situation. |
b97bf3fd | 295 | */ |
a18c4bc3 | 296 | void tipc_link_delete(struct tipc_link *l_ptr) |
b97bf3fd PL |
297 | { |
298 | if (!l_ptr) { | |
2cf8aa19 | 299 | pr_err("Attempt to delete non-existent link\n"); |
b97bf3fd PL |
300 | return; |
301 | } | |
302 | ||
b97bf3fd | 303 | k_cancel_timer(&l_ptr->timer); |
c4307285 | 304 | |
4323add6 PL |
305 | tipc_node_lock(l_ptr->owner); |
306 | tipc_link_reset(l_ptr); | |
307 | tipc_node_detach_link(l_ptr->owner, l_ptr); | |
308 | tipc_link_stop(l_ptr); | |
b97bf3fd | 309 | list_del_init(&l_ptr->link_list); |
4323add6 | 310 | tipc_node_unlock(l_ptr->owner); |
b97bf3fd PL |
311 | k_term_timer(&l_ptr->timer); |
312 | kfree(l_ptr); | |
313 | } | |
314 | ||
a18c4bc3 | 315 | static void link_start(struct tipc_link *l_ptr) |
b97bf3fd | 316 | { |
214dda4a | 317 | tipc_node_lock(l_ptr->owner); |
b97bf3fd | 318 | link_state_event(l_ptr, STARTING_EVT); |
214dda4a | 319 | tipc_node_unlock(l_ptr->owner); |
b97bf3fd PL |
320 | } |
321 | ||
322 | /** | |
c4307285 | 323 | * link_schedule_port - schedule port for deferred sending |
b97bf3fd PL |
324 | * @l_ptr: pointer to link |
325 | * @origport: reference to sending port | |
326 | * @sz: amount of data to be sent | |
c4307285 YH |
327 | * |
328 | * Schedules port for renewed sending of messages after link congestion | |
b97bf3fd PL |
329 | * has abated. |
330 | */ | |
a18c4bc3 | 331 | static int link_schedule_port(struct tipc_link *l_ptr, u32 origport, u32 sz) |
b97bf3fd | 332 | { |
23dd4cce | 333 | struct tipc_port *p_ptr; |
b97bf3fd | 334 | |
4323add6 PL |
335 | spin_lock_bh(&tipc_port_list_lock); |
336 | p_ptr = tipc_port_lock(origport); | |
b97bf3fd PL |
337 | if (p_ptr) { |
338 | if (!p_ptr->wakeup) | |
339 | goto exit; | |
340 | if (!list_empty(&p_ptr->wait_list)) | |
341 | goto exit; | |
23dd4cce | 342 | p_ptr->congested = 1; |
15e979da | 343 | p_ptr->waiting_pkts = 1 + ((sz - 1) / l_ptr->max_pkt); |
b97bf3fd PL |
344 | list_add_tail(&p_ptr->wait_list, &l_ptr->waiting_ports); |
345 | l_ptr->stats.link_congs++; | |
346 | exit: | |
4323add6 | 347 | tipc_port_unlock(p_ptr); |
b97bf3fd | 348 | } |
4323add6 | 349 | spin_unlock_bh(&tipc_port_list_lock); |
b97bf3fd PL |
350 | return -ELINKCONG; |
351 | } | |
352 | ||
a18c4bc3 | 353 | void tipc_link_wakeup_ports(struct tipc_link *l_ptr, int all) |
b97bf3fd | 354 | { |
23dd4cce AS |
355 | struct tipc_port *p_ptr; |
356 | struct tipc_port *temp_p_ptr; | |
b97bf3fd PL |
357 | int win = l_ptr->queue_limit[0] - l_ptr->out_queue_size; |
358 | ||
359 | if (all) | |
360 | win = 100000; | |
361 | if (win <= 0) | |
362 | return; | |
4323add6 | 363 | if (!spin_trylock_bh(&tipc_port_list_lock)) |
b97bf3fd PL |
364 | return; |
365 | if (link_congested(l_ptr)) | |
366 | goto exit; | |
c4307285 | 367 | list_for_each_entry_safe(p_ptr, temp_p_ptr, &l_ptr->waiting_ports, |
b97bf3fd PL |
368 | wait_list) { |
369 | if (win <= 0) | |
370 | break; | |
371 | list_del_init(&p_ptr->wait_list); | |
23dd4cce AS |
372 | spin_lock_bh(p_ptr->lock); |
373 | p_ptr->congested = 0; | |
374 | p_ptr->wakeup(p_ptr); | |
b97bf3fd | 375 | win -= p_ptr->waiting_pkts; |
23dd4cce | 376 | spin_unlock_bh(p_ptr->lock); |
b97bf3fd PL |
377 | } |
378 | ||
379 | exit: | |
4323add6 | 380 | spin_unlock_bh(&tipc_port_list_lock); |
b97bf3fd PL |
381 | } |
382 | ||
c4307285 | 383 | /** |
b97bf3fd PL |
384 | * link_release_outqueue - purge link's outbound message queue |
385 | * @l_ptr: pointer to link | |
386 | */ | |
a18c4bc3 | 387 | static void link_release_outqueue(struct tipc_link *l_ptr) |
b97bf3fd PL |
388 | { |
389 | struct sk_buff *buf = l_ptr->first_out; | |
390 | struct sk_buff *next; | |
391 | ||
392 | while (buf) { | |
393 | next = buf->next; | |
5f6d9123 | 394 | kfree_skb(buf); |
b97bf3fd PL |
395 | buf = next; |
396 | } | |
397 | l_ptr->first_out = NULL; | |
398 | l_ptr->out_queue_size = 0; | |
399 | } | |
400 | ||
401 | /** | |
4323add6 | 402 | * tipc_link_reset_fragments - purge link's inbound message fragments queue |
b97bf3fd PL |
403 | * @l_ptr: pointer to link |
404 | */ | |
a18c4bc3 | 405 | void tipc_link_reset_fragments(struct tipc_link *l_ptr) |
b97bf3fd | 406 | { |
40ba3cdf EH |
407 | kfree_skb(l_ptr->reasm_head); |
408 | l_ptr->reasm_head = NULL; | |
409 | l_ptr->reasm_tail = NULL; | |
b97bf3fd PL |
410 | } |
411 | ||
c4307285 | 412 | /** |
4323add6 | 413 | * tipc_link_stop - purge all inbound and outbound messages associated with link |
b97bf3fd PL |
414 | * @l_ptr: pointer to link |
415 | */ | |
a18c4bc3 | 416 | void tipc_link_stop(struct tipc_link *l_ptr) |
b97bf3fd PL |
417 | { |
418 | struct sk_buff *buf; | |
419 | struct sk_buff *next; | |
420 | ||
421 | buf = l_ptr->oldest_deferred_in; | |
422 | while (buf) { | |
423 | next = buf->next; | |
5f6d9123 | 424 | kfree_skb(buf); |
b97bf3fd PL |
425 | buf = next; |
426 | } | |
427 | ||
428 | buf = l_ptr->first_out; | |
429 | while (buf) { | |
430 | next = buf->next; | |
5f6d9123 | 431 | kfree_skb(buf); |
b97bf3fd PL |
432 | buf = next; |
433 | } | |
434 | ||
4323add6 | 435 | tipc_link_reset_fragments(l_ptr); |
b97bf3fd | 436 | |
5f6d9123 | 437 | kfree_skb(l_ptr->proto_msg_queue); |
b97bf3fd PL |
438 | l_ptr->proto_msg_queue = NULL; |
439 | } | |
440 | ||
a18c4bc3 | 441 | void tipc_link_reset(struct tipc_link *l_ptr) |
b97bf3fd PL |
442 | { |
443 | struct sk_buff *buf; | |
444 | u32 prev_state = l_ptr->state; | |
445 | u32 checkpoint = l_ptr->next_in_no; | |
5392d646 | 446 | int was_active_link = tipc_link_is_active(l_ptr); |
c4307285 | 447 | |
a686e685 | 448 | msg_set_session(l_ptr->pmsg, ((msg_session(l_ptr->pmsg) + 1) & 0xffff)); |
b97bf3fd | 449 | |
a686e685 AS |
450 | /* Link is down, accept any session */ |
451 | l_ptr->peer_session = INVALID_SESSION; | |
b97bf3fd | 452 | |
c4307285 | 453 | /* Prepare for max packet size negotiation */ |
b97bf3fd | 454 | link_init_max_pkt(l_ptr); |
c4307285 | 455 | |
b97bf3fd | 456 | l_ptr->state = RESET_UNKNOWN; |
b97bf3fd PL |
457 | |
458 | if ((prev_state == RESET_UNKNOWN) || (prev_state == RESET_RESET)) | |
459 | return; | |
460 | ||
4323add6 PL |
461 | tipc_node_link_down(l_ptr->owner, l_ptr); |
462 | tipc_bearer_remove_dest(l_ptr->b_ptr, l_ptr->addr); | |
7368ddf1 | 463 | |
8f19afb2 | 464 | if (was_active_link && tipc_node_active_links(l_ptr->owner) && |
b97bf3fd PL |
465 | l_ptr->owner->permit_changeover) { |
466 | l_ptr->reset_checkpoint = checkpoint; | |
467 | l_ptr->exp_msg_count = START_CHANGEOVER; | |
468 | } | |
469 | ||
470 | /* Clean up all queues: */ | |
b97bf3fd | 471 | link_release_outqueue(l_ptr); |
5f6d9123 | 472 | kfree_skb(l_ptr->proto_msg_queue); |
b97bf3fd PL |
473 | l_ptr->proto_msg_queue = NULL; |
474 | buf = l_ptr->oldest_deferred_in; | |
475 | while (buf) { | |
476 | struct sk_buff *next = buf->next; | |
5f6d9123 | 477 | kfree_skb(buf); |
b97bf3fd PL |
478 | buf = next; |
479 | } | |
480 | if (!list_empty(&l_ptr->waiting_ports)) | |
4323add6 | 481 | tipc_link_wakeup_ports(l_ptr, 1); |
b97bf3fd PL |
482 | |
483 | l_ptr->retransm_queue_head = 0; | |
484 | l_ptr->retransm_queue_size = 0; | |
485 | l_ptr->last_out = NULL; | |
486 | l_ptr->first_out = NULL; | |
487 | l_ptr->next_out = NULL; | |
488 | l_ptr->unacked_window = 0; | |
489 | l_ptr->checkpoint = 1; | |
490 | l_ptr->next_out_no = 1; | |
491 | l_ptr->deferred_inqueue_sz = 0; | |
492 | l_ptr->oldest_deferred_in = NULL; | |
493 | l_ptr->newest_deferred_in = NULL; | |
494 | l_ptr->fsm_msg_cnt = 0; | |
495 | l_ptr->stale_count = 0; | |
496 | link_reset_statistics(l_ptr); | |
b97bf3fd PL |
497 | } |
498 | ||
499 | ||
a18c4bc3 | 500 | static void link_activate(struct tipc_link *l_ptr) |
b97bf3fd | 501 | { |
5392d646 | 502 | l_ptr->next_in_no = l_ptr->stats.recv_info = 1; |
4323add6 PL |
503 | tipc_node_link_up(l_ptr->owner, l_ptr); |
504 | tipc_bearer_add_dest(l_ptr->b_ptr, l_ptr->addr); | |
b97bf3fd PL |
505 | } |
506 | ||
507 | /** | |
508 | * link_state_event - link finite state machine | |
509 | * @l_ptr: pointer to link | |
510 | * @event: state machine event to process | |
511 | */ | |
95c96174 | 512 | static void link_state_event(struct tipc_link *l_ptr, unsigned int event) |
b97bf3fd | 513 | { |
a18c4bc3 | 514 | struct tipc_link *other; |
b97bf3fd PL |
515 | u32 cont_intv = l_ptr->continuity_interval; |
516 | ||
517 | if (!l_ptr->started && (event != STARTING_EVT)) | |
518 | return; /* Not yet. */ | |
519 | ||
520 | if (link_blocked(l_ptr)) { | |
a016892c | 521 | if (event == TIMEOUT_EVT) |
b97bf3fd | 522 | link_set_timer(l_ptr, cont_intv); |
b97bf3fd PL |
523 | return; /* Changeover going on */ |
524 | } | |
b97bf3fd PL |
525 | |
526 | switch (l_ptr->state) { | |
527 | case WORKING_WORKING: | |
b97bf3fd PL |
528 | switch (event) { |
529 | case TRAFFIC_MSG_EVT: | |
b97bf3fd | 530 | case ACTIVATE_MSG: |
b97bf3fd PL |
531 | break; |
532 | case TIMEOUT_EVT: | |
b97bf3fd PL |
533 | if (l_ptr->next_in_no != l_ptr->checkpoint) { |
534 | l_ptr->checkpoint = l_ptr->next_in_no; | |
4323add6 | 535 | if (tipc_bclink_acks_missing(l_ptr->owner)) { |
c4307285 | 536 | tipc_link_send_proto_msg(l_ptr, STATE_MSG, |
4323add6 | 537 | 0, 0, 0, 0, 0); |
b97bf3fd PL |
538 | l_ptr->fsm_msg_cnt++; |
539 | } else if (l_ptr->max_pkt < l_ptr->max_pkt_target) { | |
c4307285 | 540 | tipc_link_send_proto_msg(l_ptr, STATE_MSG, |
4323add6 | 541 | 1, 0, 0, 0, 0); |
b97bf3fd PL |
542 | l_ptr->fsm_msg_cnt++; |
543 | } | |
544 | link_set_timer(l_ptr, cont_intv); | |
545 | break; | |
546 | } | |
b97bf3fd PL |
547 | l_ptr->state = WORKING_UNKNOWN; |
548 | l_ptr->fsm_msg_cnt = 0; | |
4323add6 | 549 | tipc_link_send_proto_msg(l_ptr, STATE_MSG, 1, 0, 0, 0, 0); |
b97bf3fd PL |
550 | l_ptr->fsm_msg_cnt++; |
551 | link_set_timer(l_ptr, cont_intv / 4); | |
552 | break; | |
553 | case RESET_MSG: | |
2cf8aa19 EH |
554 | pr_info("%s<%s>, requested by peer\n", link_rst_msg, |
555 | l_ptr->name); | |
4323add6 | 556 | tipc_link_reset(l_ptr); |
b97bf3fd PL |
557 | l_ptr->state = RESET_RESET; |
558 | l_ptr->fsm_msg_cnt = 0; | |
4323add6 | 559 | tipc_link_send_proto_msg(l_ptr, ACTIVATE_MSG, 0, 0, 0, 0, 0); |
b97bf3fd PL |
560 | l_ptr->fsm_msg_cnt++; |
561 | link_set_timer(l_ptr, cont_intv); | |
562 | break; | |
563 | default: | |
2cf8aa19 | 564 | pr_err("%s%u in WW state\n", link_unk_evt, event); |
b97bf3fd PL |
565 | } |
566 | break; | |
567 | case WORKING_UNKNOWN: | |
b97bf3fd PL |
568 | switch (event) { |
569 | case TRAFFIC_MSG_EVT: | |
b97bf3fd | 570 | case ACTIVATE_MSG: |
b97bf3fd PL |
571 | l_ptr->state = WORKING_WORKING; |
572 | l_ptr->fsm_msg_cnt = 0; | |
573 | link_set_timer(l_ptr, cont_intv); | |
574 | break; | |
575 | case RESET_MSG: | |
2cf8aa19 EH |
576 | pr_info("%s<%s>, requested by peer while probing\n", |
577 | link_rst_msg, l_ptr->name); | |
4323add6 | 578 | tipc_link_reset(l_ptr); |
b97bf3fd PL |
579 | l_ptr->state = RESET_RESET; |
580 | l_ptr->fsm_msg_cnt = 0; | |
4323add6 | 581 | tipc_link_send_proto_msg(l_ptr, ACTIVATE_MSG, 0, 0, 0, 0, 0); |
b97bf3fd PL |
582 | l_ptr->fsm_msg_cnt++; |
583 | link_set_timer(l_ptr, cont_intv); | |
584 | break; | |
585 | case TIMEOUT_EVT: | |
b97bf3fd | 586 | if (l_ptr->next_in_no != l_ptr->checkpoint) { |
b97bf3fd PL |
587 | l_ptr->state = WORKING_WORKING; |
588 | l_ptr->fsm_msg_cnt = 0; | |
589 | l_ptr->checkpoint = l_ptr->next_in_no; | |
4323add6 PL |
590 | if (tipc_bclink_acks_missing(l_ptr->owner)) { |
591 | tipc_link_send_proto_msg(l_ptr, STATE_MSG, | |
592 | 0, 0, 0, 0, 0); | |
b97bf3fd PL |
593 | l_ptr->fsm_msg_cnt++; |
594 | } | |
595 | link_set_timer(l_ptr, cont_intv); | |
596 | } else if (l_ptr->fsm_msg_cnt < l_ptr->abort_limit) { | |
c4307285 | 597 | tipc_link_send_proto_msg(l_ptr, STATE_MSG, |
4323add6 | 598 | 1, 0, 0, 0, 0); |
b97bf3fd PL |
599 | l_ptr->fsm_msg_cnt++; |
600 | link_set_timer(l_ptr, cont_intv / 4); | |
601 | } else { /* Link has failed */ | |
2cf8aa19 EH |
602 | pr_warn("%s<%s>, peer not responding\n", |
603 | link_rst_msg, l_ptr->name); | |
4323add6 | 604 | tipc_link_reset(l_ptr); |
b97bf3fd PL |
605 | l_ptr->state = RESET_UNKNOWN; |
606 | l_ptr->fsm_msg_cnt = 0; | |
4323add6 PL |
607 | tipc_link_send_proto_msg(l_ptr, RESET_MSG, |
608 | 0, 0, 0, 0, 0); | |
b97bf3fd PL |
609 | l_ptr->fsm_msg_cnt++; |
610 | link_set_timer(l_ptr, cont_intv); | |
611 | } | |
612 | break; | |
613 | default: | |
2cf8aa19 | 614 | pr_err("%s%u in WU state\n", link_unk_evt, event); |
b97bf3fd PL |
615 | } |
616 | break; | |
617 | case RESET_UNKNOWN: | |
b97bf3fd PL |
618 | switch (event) { |
619 | case TRAFFIC_MSG_EVT: | |
b97bf3fd PL |
620 | break; |
621 | case ACTIVATE_MSG: | |
622 | other = l_ptr->owner->active_links[0]; | |
8d64a5ba | 623 | if (other && link_working_unknown(other)) |
b97bf3fd | 624 | break; |
b97bf3fd PL |
625 | l_ptr->state = WORKING_WORKING; |
626 | l_ptr->fsm_msg_cnt = 0; | |
627 | link_activate(l_ptr); | |
4323add6 | 628 | tipc_link_send_proto_msg(l_ptr, STATE_MSG, 1, 0, 0, 0, 0); |
b97bf3fd | 629 | l_ptr->fsm_msg_cnt++; |
c64f7a6a JM |
630 | if (l_ptr->owner->working_links == 1) |
631 | tipc_link_send_sync(l_ptr); | |
b97bf3fd PL |
632 | link_set_timer(l_ptr, cont_intv); |
633 | break; | |
634 | case RESET_MSG: | |
b97bf3fd PL |
635 | l_ptr->state = RESET_RESET; |
636 | l_ptr->fsm_msg_cnt = 0; | |
4323add6 | 637 | tipc_link_send_proto_msg(l_ptr, ACTIVATE_MSG, 1, 0, 0, 0, 0); |
b97bf3fd PL |
638 | l_ptr->fsm_msg_cnt++; |
639 | link_set_timer(l_ptr, cont_intv); | |
640 | break; | |
641 | case STARTING_EVT: | |
b97bf3fd PL |
642 | l_ptr->started = 1; |
643 | /* fall through */ | |
644 | case TIMEOUT_EVT: | |
4323add6 | 645 | tipc_link_send_proto_msg(l_ptr, RESET_MSG, 0, 0, 0, 0, 0); |
b97bf3fd PL |
646 | l_ptr->fsm_msg_cnt++; |
647 | link_set_timer(l_ptr, cont_intv); | |
648 | break; | |
649 | default: | |
2cf8aa19 | 650 | pr_err("%s%u in RU state\n", link_unk_evt, event); |
b97bf3fd PL |
651 | } |
652 | break; | |
653 | case RESET_RESET: | |
b97bf3fd PL |
654 | switch (event) { |
655 | case TRAFFIC_MSG_EVT: | |
b97bf3fd PL |
656 | case ACTIVATE_MSG: |
657 | other = l_ptr->owner->active_links[0]; | |
8d64a5ba | 658 | if (other && link_working_unknown(other)) |
b97bf3fd | 659 | break; |
b97bf3fd PL |
660 | l_ptr->state = WORKING_WORKING; |
661 | l_ptr->fsm_msg_cnt = 0; | |
662 | link_activate(l_ptr); | |
4323add6 | 663 | tipc_link_send_proto_msg(l_ptr, STATE_MSG, 1, 0, 0, 0, 0); |
b97bf3fd | 664 | l_ptr->fsm_msg_cnt++; |
c64f7a6a JM |
665 | if (l_ptr->owner->working_links == 1) |
666 | tipc_link_send_sync(l_ptr); | |
b97bf3fd PL |
667 | link_set_timer(l_ptr, cont_intv); |
668 | break; | |
669 | case RESET_MSG: | |
b97bf3fd PL |
670 | break; |
671 | case TIMEOUT_EVT: | |
4323add6 | 672 | tipc_link_send_proto_msg(l_ptr, ACTIVATE_MSG, 0, 0, 0, 0, 0); |
b97bf3fd PL |
673 | l_ptr->fsm_msg_cnt++; |
674 | link_set_timer(l_ptr, cont_intv); | |
b97bf3fd PL |
675 | break; |
676 | default: | |
2cf8aa19 | 677 | pr_err("%s%u in RR state\n", link_unk_evt, event); |
b97bf3fd PL |
678 | } |
679 | break; | |
680 | default: | |
2cf8aa19 | 681 | pr_err("Unknown link state %u/%u\n", l_ptr->state, event); |
b97bf3fd PL |
682 | } |
683 | } | |
684 | ||
685 | /* | |
686 | * link_bundle_buf(): Append contents of a buffer to | |
c4307285 | 687 | * the tail of an existing one. |
b97bf3fd | 688 | */ |
ae8509c4 | 689 | static int link_bundle_buf(struct tipc_link *l_ptr, struct sk_buff *bundler, |
b97bf3fd PL |
690 | struct sk_buff *buf) |
691 | { | |
692 | struct tipc_msg *bundler_msg = buf_msg(bundler); | |
693 | struct tipc_msg *msg = buf_msg(buf); | |
694 | u32 size = msg_size(msg); | |
e49060c7 AS |
695 | u32 bundle_size = msg_size(bundler_msg); |
696 | u32 to_pos = align(bundle_size); | |
697 | u32 pad = to_pos - bundle_size; | |
b97bf3fd PL |
698 | |
699 | if (msg_user(bundler_msg) != MSG_BUNDLER) | |
700 | return 0; | |
701 | if (msg_type(bundler_msg) != OPEN_MSG) | |
702 | return 0; | |
e49060c7 | 703 | if (skb_tailroom(bundler) < (pad + size)) |
b97bf3fd | 704 | return 0; |
15e979da | 705 | if (l_ptr->max_pkt < (to_pos + size)) |
863fae66 | 706 | return 0; |
b97bf3fd | 707 | |
e49060c7 | 708 | skb_put(bundler, pad + size); |
27d7ff46 | 709 | skb_copy_to_linear_data_offset(bundler, to_pos, buf->data, size); |
b97bf3fd PL |
710 | msg_set_size(bundler_msg, to_pos + size); |
711 | msg_set_msgcnt(bundler_msg, msg_msgcnt(bundler_msg) + 1); | |
5f6d9123 | 712 | kfree_skb(buf); |
b97bf3fd PL |
713 | l_ptr->stats.sent_bundled++; |
714 | return 1; | |
715 | } | |
716 | ||
a18c4bc3 | 717 | static void link_add_to_outqueue(struct tipc_link *l_ptr, |
05790c64 SR |
718 | struct sk_buff *buf, |
719 | struct tipc_msg *msg) | |
b97bf3fd PL |
720 | { |
721 | u32 ack = mod(l_ptr->next_in_no - 1); | |
722 | u32 seqno = mod(l_ptr->next_out_no++); | |
723 | ||
724 | msg_set_word(msg, 2, ((ack << 16) | seqno)); | |
725 | msg_set_bcast_ack(msg, l_ptr->owner->bclink.last_in); | |
726 | buf->next = NULL; | |
727 | if (l_ptr->first_out) { | |
728 | l_ptr->last_out->next = buf; | |
729 | l_ptr->last_out = buf; | |
730 | } else | |
731 | l_ptr->first_out = l_ptr->last_out = buf; | |
9bd80b60 | 732 | |
b97bf3fd | 733 | l_ptr->out_queue_size++; |
9bd80b60 AS |
734 | if (l_ptr->out_queue_size > l_ptr->stats.max_queue_sz) |
735 | l_ptr->stats.max_queue_sz = l_ptr->out_queue_size; | |
b97bf3fd PL |
736 | } |
737 | ||
a18c4bc3 | 738 | static void link_add_chain_to_outqueue(struct tipc_link *l_ptr, |
dc63d91e AS |
739 | struct sk_buff *buf_chain, |
740 | u32 long_msgno) | |
741 | { | |
742 | struct sk_buff *buf; | |
743 | struct tipc_msg *msg; | |
744 | ||
745 | if (!l_ptr->next_out) | |
746 | l_ptr->next_out = buf_chain; | |
747 | while (buf_chain) { | |
748 | buf = buf_chain; | |
749 | buf_chain = buf_chain->next; | |
750 | ||
751 | msg = buf_msg(buf); | |
752 | msg_set_long_msgno(msg, long_msgno); | |
753 | link_add_to_outqueue(l_ptr, buf, msg); | |
754 | } | |
755 | } | |
756 | ||
c4307285 YH |
757 | /* |
758 | * tipc_link_send_buf() is the 'full path' for messages, called from | |
b97bf3fd PL |
759 | * inside TIPC when the 'fast path' in tipc_send_buf |
760 | * has failed, and from link_send() | |
761 | */ | |
a18c4bc3 | 762 | int tipc_link_send_buf(struct tipc_link *l_ptr, struct sk_buff *buf) |
b97bf3fd PL |
763 | { |
764 | struct tipc_msg *msg = buf_msg(buf); | |
765 | u32 size = msg_size(msg); | |
766 | u32 dsz = msg_data_sz(msg); | |
767 | u32 queue_size = l_ptr->out_queue_size; | |
c68ca7b7 | 768 | u32 imp = tipc_msg_tot_importance(msg); |
b97bf3fd | 769 | u32 queue_limit = l_ptr->queue_limit[imp]; |
15e979da | 770 | u32 max_packet = l_ptr->max_pkt; |
b97bf3fd | 771 | |
b97bf3fd | 772 | /* Match msg importance against queue limits: */ |
b97bf3fd PL |
773 | if (unlikely(queue_size >= queue_limit)) { |
774 | if (imp <= TIPC_CRITICAL_IMPORTANCE) { | |
bebc55ae | 775 | link_schedule_port(l_ptr, msg_origport(msg), size); |
5f6d9123 | 776 | kfree_skb(buf); |
bebc55ae | 777 | return -ELINKCONG; |
b97bf3fd | 778 | } |
5f6d9123 | 779 | kfree_skb(buf); |
b97bf3fd | 780 | if (imp > CONN_MANAGER) { |
2cf8aa19 EH |
781 | pr_warn("%s<%s>, send queue full", link_rst_msg, |
782 | l_ptr->name); | |
4323add6 | 783 | tipc_link_reset(l_ptr); |
b97bf3fd PL |
784 | } |
785 | return dsz; | |
786 | } | |
787 | ||
788 | /* Fragmentation needed ? */ | |
b97bf3fd | 789 | if (size > max_packet) |
31e3c3f6 | 790 | return link_send_long_buf(l_ptr, buf); |
b97bf3fd | 791 | |
617d3c7a | 792 | /* Packet can be queued or sent. */ |
3c294cb3 | 793 | if (likely(!tipc_bearer_blocked(l_ptr->b_ptr) && |
b97bf3fd PL |
794 | !link_congested(l_ptr))) { |
795 | link_add_to_outqueue(l_ptr, buf, msg); | |
796 | ||
3c294cb3 YX |
797 | tipc_bearer_send(l_ptr->b_ptr, buf, &l_ptr->media_addr); |
798 | l_ptr->unacked_window = 0; | |
b97bf3fd PL |
799 | return dsz; |
800 | } | |
617d3c7a | 801 | /* Congestion: can message be bundled ? */ |
b97bf3fd PL |
802 | if ((msg_user(msg) != CHANGEOVER_PROTOCOL) && |
803 | (msg_user(msg) != MSG_FRAGMENTER)) { | |
804 | ||
805 | /* Try adding message to an existing bundle */ | |
c4307285 | 806 | if (l_ptr->next_out && |
3c294cb3 | 807 | link_bundle_buf(l_ptr, l_ptr->last_out, buf)) |
b97bf3fd | 808 | return dsz; |
b97bf3fd PL |
809 | |
810 | /* Try creating a new bundle */ | |
b97bf3fd | 811 | if (size <= max_packet * 2 / 3) { |
31e3c3f6 | 812 | struct sk_buff *bundler = tipc_buf_acquire(max_packet); |
b97bf3fd PL |
813 | struct tipc_msg bundler_hdr; |
814 | ||
815 | if (bundler) { | |
c68ca7b7 | 816 | tipc_msg_init(&bundler_hdr, MSG_BUNDLER, OPEN_MSG, |
75715217 | 817 | INT_H_SIZE, l_ptr->addr); |
27d7ff46 ACM |
818 | skb_copy_to_linear_data(bundler, &bundler_hdr, |
819 | INT_H_SIZE); | |
b97bf3fd PL |
820 | skb_trim(bundler, INT_H_SIZE); |
821 | link_bundle_buf(l_ptr, bundler, buf); | |
822 | buf = bundler; | |
823 | msg = buf_msg(buf); | |
824 | l_ptr->stats.sent_bundles++; | |
825 | } | |
826 | } | |
827 | } | |
828 | if (!l_ptr->next_out) | |
829 | l_ptr->next_out = buf; | |
830 | link_add_to_outqueue(l_ptr, buf, msg); | |
b97bf3fd PL |
831 | return dsz; |
832 | } | |
833 | ||
c4307285 YH |
834 | /* |
835 | * tipc_link_send(): same as tipc_link_send_buf(), but the link to use has | |
b97bf3fd PL |
836 | * not been selected yet, and the the owner node is not locked |
837 | * Called by TIPC internal users, e.g. the name distributor | |
838 | */ | |
4323add6 | 839 | int tipc_link_send(struct sk_buff *buf, u32 dest, u32 selector) |
b97bf3fd | 840 | { |
a18c4bc3 | 841 | struct tipc_link *l_ptr; |
6c00055a | 842 | struct tipc_node *n_ptr; |
b97bf3fd PL |
843 | int res = -ELINKCONG; |
844 | ||
4323add6 | 845 | read_lock_bh(&tipc_net_lock); |
51a8e4de | 846 | n_ptr = tipc_node_find(dest); |
b97bf3fd | 847 | if (n_ptr) { |
4323add6 | 848 | tipc_node_lock(n_ptr); |
b97bf3fd | 849 | l_ptr = n_ptr->active_links[selector & 1]; |
a016892c | 850 | if (l_ptr) |
4323add6 | 851 | res = tipc_link_send_buf(l_ptr, buf); |
a016892c | 852 | else |
5f6d9123 | 853 | kfree_skb(buf); |
4323add6 | 854 | tipc_node_unlock(n_ptr); |
b97bf3fd | 855 | } else { |
5f6d9123 | 856 | kfree_skb(buf); |
b97bf3fd | 857 | } |
4323add6 | 858 | read_unlock_bh(&tipc_net_lock); |
b97bf3fd PL |
859 | return res; |
860 | } | |
861 | ||
c64f7a6a JM |
862 | /* |
863 | * tipc_link_send_sync - synchronize broadcast link endpoints. | |
864 | * | |
865 | * Give a newly added peer node the sequence number where it should | |
866 | * start receiving and acking broadcast packets. | |
867 | * | |
868 | * Called with node locked | |
869 | */ | |
870 | static void tipc_link_send_sync(struct tipc_link *l) | |
871 | { | |
872 | struct sk_buff *buf; | |
873 | struct tipc_msg *msg; | |
874 | ||
875 | buf = tipc_buf_acquire(INT_H_SIZE); | |
876 | if (!buf) | |
877 | return; | |
878 | ||
879 | msg = buf_msg(buf); | |
880 | tipc_msg_init(msg, BCAST_PROTOCOL, STATE_MSG, INT_H_SIZE, l->addr); | |
881 | msg_set_last_bcast(msg, l->owner->bclink.acked); | |
882 | link_add_chain_to_outqueue(l, buf, 0); | |
883 | tipc_link_push_queue(l); | |
884 | } | |
885 | ||
886 | /* | |
887 | * tipc_link_recv_sync - synchronize broadcast link endpoints. | |
888 | * Receive the sequence number where we should start receiving and | |
889 | * acking broadcast packets from a newly added peer node, and open | |
890 | * up for reception of such packets. | |
891 | * | |
892 | * Called with node locked | |
893 | */ | |
894 | static void tipc_link_recv_sync(struct tipc_node *n, struct sk_buff *buf) | |
895 | { | |
896 | struct tipc_msg *msg = buf_msg(buf); | |
897 | ||
898 | n->bclink.last_sent = n->bclink.last_in = msg_last_bcast(msg); | |
899 | n->bclink.recv_permitted = true; | |
900 | kfree_skb(buf); | |
901 | } | |
902 | ||
903 | /* | |
9aa88c2a AS |
904 | * tipc_link_send_names - send name table entries to new neighbor |
905 | * | |
906 | * Send routine for bulk delivery of name table messages when contact | |
907 | * with a new neighbor occurs. No link congestion checking is performed | |
908 | * because name table messages *must* be delivered. The messages must be | |
909 | * small enough not to require fragmentation. | |
910 | * Called without any locks held. | |
911 | */ | |
9aa88c2a AS |
912 | void tipc_link_send_names(struct list_head *message_list, u32 dest) |
913 | { | |
914 | struct tipc_node *n_ptr; | |
a18c4bc3 | 915 | struct tipc_link *l_ptr; |
9aa88c2a AS |
916 | struct sk_buff *buf; |
917 | struct sk_buff *temp_buf; | |
918 | ||
919 | if (list_empty(message_list)) | |
920 | return; | |
921 | ||
922 | read_lock_bh(&tipc_net_lock); | |
923 | n_ptr = tipc_node_find(dest); | |
924 | if (n_ptr) { | |
925 | tipc_node_lock(n_ptr); | |
926 | l_ptr = n_ptr->active_links[0]; | |
927 | if (l_ptr) { | |
928 | /* convert circular list to linear list */ | |
929 | ((struct sk_buff *)message_list->prev)->next = NULL; | |
930 | link_add_chain_to_outqueue(l_ptr, | |
931 | (struct sk_buff *)message_list->next, 0); | |
932 | tipc_link_push_queue(l_ptr); | |
933 | INIT_LIST_HEAD(message_list); | |
934 | } | |
935 | tipc_node_unlock(n_ptr); | |
936 | } | |
937 | read_unlock_bh(&tipc_net_lock); | |
938 | ||
939 | /* discard the messages if they couldn't be sent */ | |
9aa88c2a AS |
940 | list_for_each_safe(buf, temp_buf, ((struct sk_buff *)message_list)) { |
941 | list_del((struct list_head *)buf); | |
5f6d9123 | 942 | kfree_skb(buf); |
9aa88c2a AS |
943 | } |
944 | } | |
945 | ||
c4307285 YH |
946 | /* |
947 | * link_send_buf_fast: Entry for data messages where the | |
b97bf3fd PL |
948 | * destination link is known and the header is complete, |
949 | * inclusive total message length. Very time critical. | |
950 | * Link is locked. Returns user data length. | |
951 | */ | |
a18c4bc3 | 952 | static int link_send_buf_fast(struct tipc_link *l_ptr, struct sk_buff *buf, |
05790c64 | 953 | u32 *used_max_pkt) |
b97bf3fd PL |
954 | { |
955 | struct tipc_msg *msg = buf_msg(buf); | |
956 | int res = msg_data_sz(msg); | |
957 | ||
958 | if (likely(!link_congested(l_ptr))) { | |
15e979da | 959 | if (likely(msg_size(msg) <= l_ptr->max_pkt)) { |
3c294cb3 | 960 | if (likely(!tipc_bearer_blocked(l_ptr->b_ptr))) { |
b97bf3fd | 961 | link_add_to_outqueue(l_ptr, buf, msg); |
3c294cb3 YX |
962 | tipc_bearer_send(l_ptr->b_ptr, buf, |
963 | &l_ptr->media_addr); | |
964 | l_ptr->unacked_window = 0; | |
b97bf3fd PL |
965 | return res; |
966 | } | |
0e65967e | 967 | } else |
15e979da | 968 | *used_max_pkt = l_ptr->max_pkt; |
b97bf3fd | 969 | } |
4323add6 | 970 | return tipc_link_send_buf(l_ptr, buf); /* All other cases */ |
b97bf3fd PL |
971 | } |
972 | ||
c4307285 YH |
973 | /* |
974 | * tipc_link_send_sections_fast: Entry for messages where the | |
b97bf3fd | 975 | * destination processor is known and the header is complete, |
c4307285 | 976 | * except for total message length. |
b97bf3fd PL |
977 | * Returns user data length or errno. |
978 | */ | |
23dd4cce | 979 | int tipc_link_send_sections_fast(struct tipc_port *sender, |
4323add6 | 980 | struct iovec const *msg_sect, |
9446b87a | 981 | unsigned int len, u32 destaddr) |
b97bf3fd | 982 | { |
23dd4cce | 983 | struct tipc_msg *hdr = &sender->phdr; |
a18c4bc3 | 984 | struct tipc_link *l_ptr; |
b97bf3fd | 985 | struct sk_buff *buf; |
6c00055a | 986 | struct tipc_node *node; |
b97bf3fd PL |
987 | int res; |
988 | u32 selector = msg_origport(hdr) & 1; | |
989 | ||
b97bf3fd PL |
990 | again: |
991 | /* | |
992 | * Try building message using port's max_pkt hint. | |
993 | * (Must not hold any locks while building message.) | |
994 | */ | |
9446b87a | 995 | res = tipc_msg_build(hdr, msg_sect, len, sender->max_pkt, &buf); |
7410f967 YX |
996 | /* Exit if build request was invalid */ |
997 | if (unlikely(res < 0)) | |
998 | return res; | |
b97bf3fd | 999 | |
4323add6 | 1000 | read_lock_bh(&tipc_net_lock); |
51a8e4de | 1001 | node = tipc_node_find(destaddr); |
b97bf3fd | 1002 | if (likely(node)) { |
4323add6 | 1003 | tipc_node_lock(node); |
b97bf3fd PL |
1004 | l_ptr = node->active_links[selector]; |
1005 | if (likely(l_ptr)) { | |
1006 | if (likely(buf)) { | |
1007 | res = link_send_buf_fast(l_ptr, buf, | |
23dd4cce | 1008 | &sender->max_pkt); |
b97bf3fd | 1009 | exit: |
4323add6 PL |
1010 | tipc_node_unlock(node); |
1011 | read_unlock_bh(&tipc_net_lock); | |
b97bf3fd PL |
1012 | return res; |
1013 | } | |
1014 | ||
b97bf3fd | 1015 | /* Exit if link (or bearer) is congested */ |
c4307285 | 1016 | if (link_congested(l_ptr) || |
3c294cb3 | 1017 | tipc_bearer_blocked(l_ptr->b_ptr)) { |
b97bf3fd | 1018 | res = link_schedule_port(l_ptr, |
23dd4cce | 1019 | sender->ref, res); |
b97bf3fd PL |
1020 | goto exit; |
1021 | } | |
1022 | ||
c4307285 | 1023 | /* |
b97bf3fd PL |
1024 | * Message size exceeds max_pkt hint; update hint, |
1025 | * then re-try fast path or fragment the message | |
1026 | */ | |
23dd4cce | 1027 | sender->max_pkt = l_ptr->max_pkt; |
4323add6 PL |
1028 | tipc_node_unlock(node); |
1029 | read_unlock_bh(&tipc_net_lock); | |
b97bf3fd PL |
1030 | |
1031 | ||
23dd4cce | 1032 | if ((msg_hdr_sz(hdr) + res) <= sender->max_pkt) |
b97bf3fd PL |
1033 | goto again; |
1034 | ||
9446b87a | 1035 | return link_send_sections_long(sender, msg_sect, len, |
26896904 | 1036 | destaddr); |
b97bf3fd | 1037 | } |
4323add6 | 1038 | tipc_node_unlock(node); |
b97bf3fd | 1039 | } |
4323add6 | 1040 | read_unlock_bh(&tipc_net_lock); |
b97bf3fd PL |
1041 | |
1042 | /* Couldn't find a link to the destination node */ | |
b97bf3fd PL |
1043 | if (buf) |
1044 | return tipc_reject_msg(buf, TIPC_ERR_NO_NODE); | |
1045 | if (res >= 0) | |
9446b87a YX |
1046 | return tipc_port_reject_sections(sender, hdr, msg_sect, |
1047 | len, TIPC_ERR_NO_NODE); | |
b97bf3fd PL |
1048 | return res; |
1049 | } | |
1050 | ||
c4307285 YH |
1051 | /* |
1052 | * link_send_sections_long(): Entry for long messages where the | |
b97bf3fd | 1053 | * destination node is known and the header is complete, |
c4307285 | 1054 | * inclusive total message length. |
b97bf3fd PL |
1055 | * Link and bearer congestion status have been checked to be ok, |
1056 | * and are ignored if they change. | |
1057 | * | |
1058 | * Note that fragments do not use the full link MTU so that they won't have | |
1059 | * to undergo refragmentation if link changeover causes them to be sent | |
1060 | * over another link with an additional tunnel header added as prefix. | |
1061 | * (Refragmentation will still occur if the other link has a smaller MTU.) | |
1062 | * | |
1063 | * Returns user data length or errno. | |
1064 | */ | |
23dd4cce | 1065 | static int link_send_sections_long(struct tipc_port *sender, |
b97bf3fd | 1066 | struct iovec const *msg_sect, |
9446b87a | 1067 | unsigned int len, u32 destaddr) |
b97bf3fd | 1068 | { |
a18c4bc3 | 1069 | struct tipc_link *l_ptr; |
6c00055a | 1070 | struct tipc_node *node; |
23dd4cce | 1071 | struct tipc_msg *hdr = &sender->phdr; |
9446b87a | 1072 | u32 dsz = len; |
0e65967e | 1073 | u32 max_pkt, fragm_sz, rest; |
b97bf3fd | 1074 | struct tipc_msg fragm_hdr; |
0e65967e AS |
1075 | struct sk_buff *buf, *buf_chain, *prev; |
1076 | u32 fragm_crs, fragm_rest, hsz, sect_rest; | |
40682432 | 1077 | const unchar __user *sect_crs; |
b97bf3fd PL |
1078 | int curr_sect; |
1079 | u32 fragm_no; | |
126c0524 | 1080 | int res = 0; |
b97bf3fd PL |
1081 | |
1082 | again: | |
1083 | fragm_no = 1; | |
23dd4cce | 1084 | max_pkt = sender->max_pkt - INT_H_SIZE; |
b97bf3fd | 1085 | /* leave room for tunnel header in case of link changeover */ |
c4307285 | 1086 | fragm_sz = max_pkt - INT_H_SIZE; |
b97bf3fd PL |
1087 | /* leave room for fragmentation header in each fragment */ |
1088 | rest = dsz; | |
1089 | fragm_crs = 0; | |
1090 | fragm_rest = 0; | |
1091 | sect_rest = 0; | |
1fc54d8f | 1092 | sect_crs = NULL; |
b97bf3fd PL |
1093 | curr_sect = -1; |
1094 | ||
617d3c7a | 1095 | /* Prepare reusable fragment header */ |
c68ca7b7 | 1096 | tipc_msg_init(&fragm_hdr, MSG_FRAGMENTER, FIRST_FRAGMENT, |
75715217 | 1097 | INT_H_SIZE, msg_destnode(hdr)); |
b97bf3fd PL |
1098 | msg_set_size(&fragm_hdr, max_pkt); |
1099 | msg_set_fragm_no(&fragm_hdr, 1); | |
1100 | ||
617d3c7a | 1101 | /* Prepare header of first fragment */ |
31e3c3f6 | 1102 | buf_chain = buf = tipc_buf_acquire(max_pkt); |
b97bf3fd PL |
1103 | if (!buf) |
1104 | return -ENOMEM; | |
1105 | buf->next = NULL; | |
27d7ff46 | 1106 | skb_copy_to_linear_data(buf, &fragm_hdr, INT_H_SIZE); |
b97bf3fd | 1107 | hsz = msg_hdr_sz(hdr); |
27d7ff46 | 1108 | skb_copy_to_linear_data_offset(buf, INT_H_SIZE, hdr, hsz); |
b97bf3fd | 1109 | |
617d3c7a | 1110 | /* Chop up message */ |
b97bf3fd PL |
1111 | fragm_crs = INT_H_SIZE + hsz; |
1112 | fragm_rest = fragm_sz - hsz; | |
1113 | ||
1114 | do { /* For all sections */ | |
1115 | u32 sz; | |
1116 | ||
1117 | if (!sect_rest) { | |
1118 | sect_rest = msg_sect[++curr_sect].iov_len; | |
40682432 | 1119 | sect_crs = msg_sect[curr_sect].iov_base; |
b97bf3fd PL |
1120 | } |
1121 | ||
1122 | if (sect_rest < fragm_rest) | |
1123 | sz = sect_rest; | |
1124 | else | |
1125 | sz = fragm_rest; | |
1126 | ||
f1733d75 | 1127 | if (copy_from_user(buf->data + fragm_crs, sect_crs, sz)) { |
126c0524 | 1128 | res = -EFAULT; |
b97bf3fd | 1129 | error: |
f1733d75 YX |
1130 | for (; buf_chain; buf_chain = buf) { |
1131 | buf = buf_chain->next; | |
1132 | kfree_skb(buf_chain); | |
b97bf3fd | 1133 | } |
126c0524 | 1134 | return res; |
f1733d75 | 1135 | } |
b97bf3fd PL |
1136 | sect_crs += sz; |
1137 | sect_rest -= sz; | |
1138 | fragm_crs += sz; | |
1139 | fragm_rest -= sz; | |
1140 | rest -= sz; | |
1141 | ||
1142 | if (!fragm_rest && rest) { | |
1143 | ||
1144 | /* Initiate new fragment: */ | |
1145 | if (rest <= fragm_sz) { | |
1146 | fragm_sz = rest; | |
0e65967e | 1147 | msg_set_type(&fragm_hdr, LAST_FRAGMENT); |
b97bf3fd PL |
1148 | } else { |
1149 | msg_set_type(&fragm_hdr, FRAGMENT); | |
1150 | } | |
1151 | msg_set_size(&fragm_hdr, fragm_sz + INT_H_SIZE); | |
1152 | msg_set_fragm_no(&fragm_hdr, ++fragm_no); | |
1153 | prev = buf; | |
31e3c3f6 | 1154 | buf = tipc_buf_acquire(fragm_sz + INT_H_SIZE); |
126c0524 YX |
1155 | if (!buf) { |
1156 | res = -ENOMEM; | |
b97bf3fd | 1157 | goto error; |
126c0524 | 1158 | } |
b97bf3fd | 1159 | |
c4307285 | 1160 | buf->next = NULL; |
b97bf3fd | 1161 | prev->next = buf; |
27d7ff46 | 1162 | skb_copy_to_linear_data(buf, &fragm_hdr, INT_H_SIZE); |
b97bf3fd PL |
1163 | fragm_crs = INT_H_SIZE; |
1164 | fragm_rest = fragm_sz; | |
b97bf3fd | 1165 | } |
0e65967e | 1166 | } while (rest > 0); |
b97bf3fd | 1167 | |
c4307285 | 1168 | /* |
b97bf3fd PL |
1169 | * Now we have a buffer chain. Select a link and check |
1170 | * that packet size is still OK | |
1171 | */ | |
51a8e4de | 1172 | node = tipc_node_find(destaddr); |
b97bf3fd | 1173 | if (likely(node)) { |
4323add6 | 1174 | tipc_node_lock(node); |
23dd4cce | 1175 | l_ptr = node->active_links[sender->ref & 1]; |
b97bf3fd | 1176 | if (!l_ptr) { |
4323add6 | 1177 | tipc_node_unlock(node); |
b97bf3fd PL |
1178 | goto reject; |
1179 | } | |
15e979da | 1180 | if (l_ptr->max_pkt < max_pkt) { |
23dd4cce | 1181 | sender->max_pkt = l_ptr->max_pkt; |
4323add6 | 1182 | tipc_node_unlock(node); |
b97bf3fd PL |
1183 | for (; buf_chain; buf_chain = buf) { |
1184 | buf = buf_chain->next; | |
5f6d9123 | 1185 | kfree_skb(buf_chain); |
b97bf3fd PL |
1186 | } |
1187 | goto again; | |
1188 | } | |
1189 | } else { | |
1190 | reject: | |
1191 | for (; buf_chain; buf_chain = buf) { | |
1192 | buf = buf_chain->next; | |
5f6d9123 | 1193 | kfree_skb(buf_chain); |
b97bf3fd | 1194 | } |
9446b87a YX |
1195 | return tipc_port_reject_sections(sender, hdr, msg_sect, |
1196 | len, TIPC_ERR_NO_NODE); | |
b97bf3fd PL |
1197 | } |
1198 | ||
dc63d91e | 1199 | /* Append chain of fragments to send queue & send them */ |
e0f08596 | 1200 | l_ptr->long_msg_seq_no++; |
dc63d91e AS |
1201 | link_add_chain_to_outqueue(l_ptr, buf_chain, l_ptr->long_msg_seq_no); |
1202 | l_ptr->stats.sent_fragments += fragm_no; | |
b97bf3fd | 1203 | l_ptr->stats.sent_fragmented++; |
4323add6 PL |
1204 | tipc_link_push_queue(l_ptr); |
1205 | tipc_node_unlock(node); | |
b97bf3fd PL |
1206 | return dsz; |
1207 | } | |
1208 | ||
c4307285 | 1209 | /* |
4323add6 | 1210 | * tipc_link_push_packet: Push one unsent packet to the media |
b97bf3fd | 1211 | */ |
a18c4bc3 | 1212 | u32 tipc_link_push_packet(struct tipc_link *l_ptr) |
b97bf3fd PL |
1213 | { |
1214 | struct sk_buff *buf = l_ptr->first_out; | |
1215 | u32 r_q_size = l_ptr->retransm_queue_size; | |
1216 | u32 r_q_head = l_ptr->retransm_queue_head; | |
1217 | ||
1218 | /* Step to position where retransmission failed, if any, */ | |
1219 | /* consider that buffers may have been released in meantime */ | |
b97bf3fd | 1220 | if (r_q_size && buf) { |
c4307285 | 1221 | u32 last = lesser(mod(r_q_head + r_q_size), |
b97bf3fd | 1222 | link_last_sent(l_ptr)); |
f905730c | 1223 | u32 first = buf_seqno(buf); |
b97bf3fd PL |
1224 | |
1225 | while (buf && less(first, r_q_head)) { | |
1226 | first = mod(first + 1); | |
1227 | buf = buf->next; | |
1228 | } | |
1229 | l_ptr->retransm_queue_head = r_q_head = first; | |
1230 | l_ptr->retransm_queue_size = r_q_size = mod(last - first); | |
1231 | } | |
1232 | ||
1233 | /* Continue retransmission now, if there is anything: */ | |
ca509101 | 1234 | if (r_q_size && buf) { |
b97bf3fd | 1235 | msg_set_ack(buf_msg(buf), mod(l_ptr->next_in_no - 1)); |
c4307285 | 1236 | msg_set_bcast_ack(buf_msg(buf), l_ptr->owner->bclink.last_in); |
3c294cb3 YX |
1237 | tipc_bearer_send(l_ptr->b_ptr, buf, &l_ptr->media_addr); |
1238 | l_ptr->retransm_queue_head = mod(++r_q_head); | |
1239 | l_ptr->retransm_queue_size = --r_q_size; | |
1240 | l_ptr->stats.retransmitted++; | |
1241 | return 0; | |
b97bf3fd PL |
1242 | } |
1243 | ||
1244 | /* Send deferred protocol message, if any: */ | |
b97bf3fd PL |
1245 | buf = l_ptr->proto_msg_queue; |
1246 | if (buf) { | |
1247 | msg_set_ack(buf_msg(buf), mod(l_ptr->next_in_no - 1)); | |
0e65967e | 1248 | msg_set_bcast_ack(buf_msg(buf), l_ptr->owner->bclink.last_in); |
3c294cb3 YX |
1249 | tipc_bearer_send(l_ptr->b_ptr, buf, &l_ptr->media_addr); |
1250 | l_ptr->unacked_window = 0; | |
1251 | kfree_skb(buf); | |
1252 | l_ptr->proto_msg_queue = NULL; | |
1253 | return 0; | |
b97bf3fd PL |
1254 | } |
1255 | ||
1256 | /* Send one deferred data message, if send window not full: */ | |
b97bf3fd PL |
1257 | buf = l_ptr->next_out; |
1258 | if (buf) { | |
1259 | struct tipc_msg *msg = buf_msg(buf); | |
1260 | u32 next = msg_seqno(msg); | |
f905730c | 1261 | u32 first = buf_seqno(l_ptr->first_out); |
b97bf3fd PL |
1262 | |
1263 | if (mod(next - first) < l_ptr->queue_limit[0]) { | |
1264 | msg_set_ack(msg, mod(l_ptr->next_in_no - 1)); | |
c4307285 | 1265 | msg_set_bcast_ack(msg, l_ptr->owner->bclink.last_in); |
3c294cb3 YX |
1266 | tipc_bearer_send(l_ptr->b_ptr, buf, &l_ptr->media_addr); |
1267 | if (msg_user(msg) == MSG_BUNDLER) | |
1268 | msg_set_type(msg, CLOSED_MSG); | |
1269 | l_ptr->next_out = buf->next; | |
1270 | return 0; | |
b97bf3fd PL |
1271 | } |
1272 | } | |
3c294cb3 | 1273 | return 1; |
b97bf3fd PL |
1274 | } |
1275 | ||
1276 | /* | |
1277 | * push_queue(): push out the unsent messages of a link where | |
1278 | * congestion has abated. Node is locked | |
1279 | */ | |
a18c4bc3 | 1280 | void tipc_link_push_queue(struct tipc_link *l_ptr) |
b97bf3fd PL |
1281 | { |
1282 | u32 res; | |
1283 | ||
3c294cb3 | 1284 | if (tipc_bearer_blocked(l_ptr->b_ptr)) |
b97bf3fd PL |
1285 | return; |
1286 | ||
1287 | do { | |
4323add6 | 1288 | res = tipc_link_push_packet(l_ptr); |
0e35fd5e | 1289 | } while (!res); |
b97bf3fd PL |
1290 | } |
1291 | ||
d356eeba AS |
1292 | static void link_reset_all(unsigned long addr) |
1293 | { | |
6c00055a | 1294 | struct tipc_node *n_ptr; |
d356eeba AS |
1295 | char addr_string[16]; |
1296 | u32 i; | |
1297 | ||
1298 | read_lock_bh(&tipc_net_lock); | |
1299 | n_ptr = tipc_node_find((u32)addr); | |
1300 | if (!n_ptr) { | |
1301 | read_unlock_bh(&tipc_net_lock); | |
1302 | return; /* node no longer exists */ | |
1303 | } | |
1304 | ||
1305 | tipc_node_lock(n_ptr); | |
1306 | ||
2cf8aa19 EH |
1307 | pr_warn("Resetting all links to %s\n", |
1308 | tipc_addr_string_fill(addr_string, n_ptr->addr)); | |
d356eeba AS |
1309 | |
1310 | for (i = 0; i < MAX_BEARERS; i++) { | |
1311 | if (n_ptr->links[i]) { | |
8d64a5ba | 1312 | link_print(n_ptr->links[i], "Resetting link\n"); |
d356eeba AS |
1313 | tipc_link_reset(n_ptr->links[i]); |
1314 | } | |
1315 | } | |
1316 | ||
1317 | tipc_node_unlock(n_ptr); | |
1318 | read_unlock_bh(&tipc_net_lock); | |
1319 | } | |
1320 | ||
a18c4bc3 | 1321 | static void link_retransmit_failure(struct tipc_link *l_ptr, |
ae8509c4 | 1322 | struct sk_buff *buf) |
d356eeba AS |
1323 | { |
1324 | struct tipc_msg *msg = buf_msg(buf); | |
1325 | ||
2cf8aa19 | 1326 | pr_warn("Retransmission failure on link <%s>\n", l_ptr->name); |
d356eeba AS |
1327 | |
1328 | if (l_ptr->addr) { | |
d356eeba | 1329 | /* Handle failure on standard link */ |
8d64a5ba | 1330 | link_print(l_ptr, "Resetting link\n"); |
d356eeba AS |
1331 | tipc_link_reset(l_ptr); |
1332 | ||
1333 | } else { | |
d356eeba | 1334 | /* Handle failure on broadcast link */ |
6c00055a | 1335 | struct tipc_node *n_ptr; |
d356eeba AS |
1336 | char addr_string[16]; |
1337 | ||
2cf8aa19 EH |
1338 | pr_info("Msg seq number: %u, ", msg_seqno(msg)); |
1339 | pr_cont("Outstanding acks: %lu\n", | |
1340 | (unsigned long) TIPC_SKB_CB(buf)->handle); | |
617dbeaa | 1341 | |
01d83edd | 1342 | n_ptr = tipc_bclink_retransmit_to(); |
d356eeba AS |
1343 | tipc_node_lock(n_ptr); |
1344 | ||
c68ca7b7 | 1345 | tipc_addr_string_fill(addr_string, n_ptr->addr); |
2cf8aa19 | 1346 | pr_info("Broadcast link info for %s\n", addr_string); |
389dd9bc YX |
1347 | pr_info("Reception permitted: %d, Acked: %u\n", |
1348 | n_ptr->bclink.recv_permitted, | |
2cf8aa19 EH |
1349 | n_ptr->bclink.acked); |
1350 | pr_info("Last in: %u, Oos state: %u, Last sent: %u\n", | |
1351 | n_ptr->bclink.last_in, | |
1352 | n_ptr->bclink.oos_state, | |
1353 | n_ptr->bclink.last_sent); | |
d356eeba AS |
1354 | |
1355 | tipc_k_signal((Handler)link_reset_all, (unsigned long)n_ptr->addr); | |
1356 | ||
1357 | tipc_node_unlock(n_ptr); | |
1358 | ||
1359 | l_ptr->stale_count = 0; | |
1360 | } | |
1361 | } | |
1362 | ||
a18c4bc3 | 1363 | void tipc_link_retransmit(struct tipc_link *l_ptr, struct sk_buff *buf, |
4323add6 | 1364 | u32 retransmits) |
b97bf3fd PL |
1365 | { |
1366 | struct tipc_msg *msg; | |
1367 | ||
d356eeba AS |
1368 | if (!buf) |
1369 | return; | |
1370 | ||
1371 | msg = buf_msg(buf); | |
c4307285 | 1372 | |
3c294cb3 | 1373 | if (tipc_bearer_blocked(l_ptr->b_ptr)) { |
ca509101 | 1374 | if (l_ptr->retransm_queue_size == 0) { |
d356eeba AS |
1375 | l_ptr->retransm_queue_head = msg_seqno(msg); |
1376 | l_ptr->retransm_queue_size = retransmits; | |
d356eeba | 1377 | } else { |
2cf8aa19 EH |
1378 | pr_err("Unexpected retransmit on link %s (qsize=%d)\n", |
1379 | l_ptr->name, l_ptr->retransm_queue_size); | |
d356eeba | 1380 | } |
ca509101 | 1381 | return; |
d356eeba | 1382 | } else { |
3c294cb3 | 1383 | /* Detect repeated retransmit failures on unblocked bearer */ |
d356eeba AS |
1384 | if (l_ptr->last_retransmitted == msg_seqno(msg)) { |
1385 | if (++l_ptr->stale_count > 100) { | |
1386 | link_retransmit_failure(l_ptr, buf); | |
1387 | return; | |
1388 | } | |
1389 | } else { | |
1390 | l_ptr->last_retransmitted = msg_seqno(msg); | |
1391 | l_ptr->stale_count = 1; | |
1392 | } | |
b97bf3fd | 1393 | } |
d356eeba | 1394 | |
ca509101 | 1395 | while (retransmits && (buf != l_ptr->next_out) && buf) { |
b97bf3fd PL |
1396 | msg = buf_msg(buf); |
1397 | msg_set_ack(msg, mod(l_ptr->next_in_no - 1)); | |
c4307285 | 1398 | msg_set_bcast_ack(msg, l_ptr->owner->bclink.last_in); |
3c294cb3 YX |
1399 | tipc_bearer_send(l_ptr->b_ptr, buf, &l_ptr->media_addr); |
1400 | buf = buf->next; | |
1401 | retransmits--; | |
1402 | l_ptr->stats.retransmitted++; | |
b97bf3fd | 1403 | } |
d356eeba | 1404 | |
b97bf3fd PL |
1405 | l_ptr->retransm_queue_head = l_ptr->retransm_queue_size = 0; |
1406 | } | |
1407 | ||
c4307285 | 1408 | /** |
b97bf3fd PL |
1409 | * link_insert_deferred_queue - insert deferred messages back into receive chain |
1410 | */ | |
a18c4bc3 | 1411 | static struct sk_buff *link_insert_deferred_queue(struct tipc_link *l_ptr, |
b97bf3fd PL |
1412 | struct sk_buff *buf) |
1413 | { | |
1414 | u32 seq_no; | |
1415 | ||
1416 | if (l_ptr->oldest_deferred_in == NULL) | |
1417 | return buf; | |
1418 | ||
f905730c | 1419 | seq_no = buf_seqno(l_ptr->oldest_deferred_in); |
b97bf3fd PL |
1420 | if (seq_no == mod(l_ptr->next_in_no)) { |
1421 | l_ptr->newest_deferred_in->next = buf; | |
1422 | buf = l_ptr->oldest_deferred_in; | |
1423 | l_ptr->oldest_deferred_in = NULL; | |
1424 | l_ptr->deferred_inqueue_sz = 0; | |
1425 | } | |
1426 | return buf; | |
1427 | } | |
1428 | ||
85035568 AS |
1429 | /** |
1430 | * link_recv_buf_validate - validate basic format of received message | |
1431 | * | |
1432 | * This routine ensures a TIPC message has an acceptable header, and at least | |
1433 | * as much data as the header indicates it should. The routine also ensures | |
1434 | * that the entire message header is stored in the main fragment of the message | |
1435 | * buffer, to simplify future access to message header fields. | |
1436 | * | |
1437 | * Note: Having extra info present in the message header or data areas is OK. | |
1438 | * TIPC will ignore the excess, under the assumption that it is optional info | |
1439 | * introduced by a later release of the protocol. | |
1440 | */ | |
85035568 AS |
1441 | static int link_recv_buf_validate(struct sk_buff *buf) |
1442 | { | |
1443 | static u32 min_data_hdr_size[8] = { | |
741d9eb7 | 1444 | SHORT_H_SIZE, MCAST_H_SIZE, NAMED_H_SIZE, BASIC_H_SIZE, |
85035568 AS |
1445 | MAX_H_SIZE, MAX_H_SIZE, MAX_H_SIZE, MAX_H_SIZE |
1446 | }; | |
1447 | ||
1448 | struct tipc_msg *msg; | |
1449 | u32 tipc_hdr[2]; | |
1450 | u32 size; | |
1451 | u32 hdr_size; | |
1452 | u32 min_hdr_size; | |
1453 | ||
1454 | if (unlikely(buf->len < MIN_H_SIZE)) | |
1455 | return 0; | |
1456 | ||
1457 | msg = skb_header_pointer(buf, 0, sizeof(tipc_hdr), tipc_hdr); | |
1458 | if (msg == NULL) | |
1459 | return 0; | |
1460 | ||
1461 | if (unlikely(msg_version(msg) != TIPC_VERSION)) | |
1462 | return 0; | |
1463 | ||
1464 | size = msg_size(msg); | |
1465 | hdr_size = msg_hdr_sz(msg); | |
1466 | min_hdr_size = msg_isdata(msg) ? | |
1467 | min_data_hdr_size[msg_type(msg)] : INT_H_SIZE; | |
1468 | ||
1469 | if (unlikely((hdr_size < min_hdr_size) || | |
1470 | (size < hdr_size) || | |
1471 | (buf->len < size) || | |
1472 | (size - hdr_size > TIPC_MAX_USER_MSG_SIZE))) | |
1473 | return 0; | |
1474 | ||
1475 | return pskb_may_pull(buf, hdr_size); | |
1476 | } | |
1477 | ||
b02b69c8 AS |
1478 | /** |
1479 | * tipc_recv_msg - process TIPC messages arriving from off-node | |
1480 | * @head: pointer to message buffer chain | |
1481 | * @tb_ptr: pointer to bearer message arrived on | |
1482 | * | |
1483 | * Invoked with no locks held. Bearer pointer must point to a valid bearer | |
1484 | * structure (i.e. cannot be NULL), but bearer can be inactive. | |
1485 | */ | |
2d627b92 | 1486 | void tipc_recv_msg(struct sk_buff *head, struct tipc_bearer *b_ptr) |
b97bf3fd | 1487 | { |
4323add6 | 1488 | read_lock_bh(&tipc_net_lock); |
b97bf3fd | 1489 | while (head) { |
6c00055a | 1490 | struct tipc_node *n_ptr; |
a18c4bc3 | 1491 | struct tipc_link *l_ptr; |
b97bf3fd PL |
1492 | struct sk_buff *crs; |
1493 | struct sk_buff *buf = head; | |
85035568 AS |
1494 | struct tipc_msg *msg; |
1495 | u32 seq_no; | |
1496 | u32 ackd; | |
b97bf3fd PL |
1497 | u32 released = 0; |
1498 | int type; | |
1499 | ||
b97bf3fd | 1500 | head = head->next; |
85035568 | 1501 | |
b02b69c8 | 1502 | /* Ensure bearer is still enabled */ |
b02b69c8 | 1503 | if (unlikely(!b_ptr->active)) |
3af390e2 | 1504 | goto discard; |
b02b69c8 | 1505 | |
85035568 | 1506 | /* Ensure message is well-formed */ |
85035568 | 1507 | if (unlikely(!link_recv_buf_validate(buf))) |
3af390e2 | 1508 | goto discard; |
b97bf3fd | 1509 | |
fe13dda2 | 1510 | /* Ensure message data is a single contiguous unit */ |
5f6d9123 | 1511 | if (unlikely(skb_linearize(buf))) |
3af390e2 | 1512 | goto discard; |
fe13dda2 | 1513 | |
85035568 | 1514 | /* Handle arrival of a non-unicast link message */ |
85035568 AS |
1515 | msg = buf_msg(buf); |
1516 | ||
b97bf3fd | 1517 | if (unlikely(msg_non_seq(msg))) { |
1265a021 AS |
1518 | if (msg_user(msg) == LINK_CONFIG) |
1519 | tipc_disc_recv_msg(buf, b_ptr); | |
1520 | else | |
1521 | tipc_bclink_recv_pkt(buf); | |
b97bf3fd PL |
1522 | continue; |
1523 | } | |
c4307285 | 1524 | |
ed33a9c4 | 1525 | /* Discard unicast link messages destined for another node */ |
26008247 AS |
1526 | if (unlikely(!msg_short(msg) && |
1527 | (msg_destnode(msg) != tipc_own_addr))) | |
3af390e2 | 1528 | goto discard; |
c4307285 | 1529 | |
5a68d5ee | 1530 | /* Locate neighboring node that sent message */ |
4323add6 | 1531 | n_ptr = tipc_node_find(msg_prevnode(msg)); |
b97bf3fd | 1532 | if (unlikely(!n_ptr)) |
3af390e2 | 1533 | goto discard; |
4323add6 | 1534 | tipc_node_lock(n_ptr); |
85035568 | 1535 | |
b4b56102 | 1536 | /* Locate unicast link endpoint that should handle message */ |
b4b56102 | 1537 | l_ptr = n_ptr->links[b_ptr->identity]; |
3af390e2 YX |
1538 | if (unlikely(!l_ptr)) |
1539 | goto unlock_discard; | |
5a68d5ee | 1540 | |
b4b56102 | 1541 | /* Verify that communication with node is currently allowed */ |
b4b56102 AS |
1542 | if ((n_ptr->block_setup & WAIT_PEER_DOWN) && |
1543 | msg_user(msg) == LINK_PROTOCOL && | |
1544 | (msg_type(msg) == RESET_MSG || | |
1545 | msg_type(msg) == ACTIVATE_MSG) && | |
1546 | !msg_redundant_link(msg)) | |
1547 | n_ptr->block_setup &= ~WAIT_PEER_DOWN; | |
1548 | ||
3af390e2 YX |
1549 | if (n_ptr->block_setup) |
1550 | goto unlock_discard; | |
85035568 AS |
1551 | |
1552 | /* Validate message sequence number info */ | |
85035568 AS |
1553 | seq_no = msg_seqno(msg); |
1554 | ackd = msg_ack(msg); | |
1555 | ||
1556 | /* Release acked messages */ | |
389dd9bc | 1557 | if (n_ptr->bclink.recv_permitted) |
36559591 | 1558 | tipc_bclink_acknowledge(n_ptr, msg_bcast_ack(msg)); |
b97bf3fd PL |
1559 | |
1560 | crs = l_ptr->first_out; | |
c4307285 | 1561 | while ((crs != l_ptr->next_out) && |
f905730c | 1562 | less_eq(buf_seqno(crs), ackd)) { |
b97bf3fd PL |
1563 | struct sk_buff *next = crs->next; |
1564 | ||
5f6d9123 | 1565 | kfree_skb(crs); |
b97bf3fd PL |
1566 | crs = next; |
1567 | released++; | |
1568 | } | |
1569 | if (released) { | |
1570 | l_ptr->first_out = crs; | |
1571 | l_ptr->out_queue_size -= released; | |
1572 | } | |
85035568 AS |
1573 | |
1574 | /* Try sending any messages link endpoint has pending */ | |
b97bf3fd | 1575 | if (unlikely(l_ptr->next_out)) |
4323add6 | 1576 | tipc_link_push_queue(l_ptr); |
b97bf3fd | 1577 | if (unlikely(!list_empty(&l_ptr->waiting_ports))) |
4323add6 | 1578 | tipc_link_wakeup_ports(l_ptr, 0); |
b97bf3fd PL |
1579 | if (unlikely(++l_ptr->unacked_window >= TIPC_MIN_LINK_WIN)) { |
1580 | l_ptr->stats.sent_acks++; | |
4323add6 | 1581 | tipc_link_send_proto_msg(l_ptr, STATE_MSG, 0, 0, 0, 0, 0); |
b97bf3fd PL |
1582 | } |
1583 | ||
85035568 | 1584 | /* Now (finally!) process the incoming message */ |
b97bf3fd | 1585 | protocol_check: |
3af390e2 YX |
1586 | if (unlikely(!link_working_working(l_ptr))) { |
1587 | if (msg_user(msg) == LINK_PROTOCOL) { | |
1588 | link_recv_proto_msg(l_ptr, buf); | |
1589 | head = link_insert_deferred_queue(l_ptr, head); | |
4323add6 | 1590 | tipc_node_unlock(n_ptr); |
b97bf3fd PL |
1591 | continue; |
1592 | } | |
3af390e2 YX |
1593 | |
1594 | /* Traffic message. Conditionally activate link */ | |
1595 | link_state_event(l_ptr, TRAFFIC_MSG_EVT); | |
1596 | ||
1597 | if (link_working_working(l_ptr)) { | |
1598 | /* Re-insert buffer in front of queue */ | |
1599 | buf->next = head; | |
1600 | head = buf; | |
1601 | tipc_node_unlock(n_ptr); | |
1602 | continue; | |
1603 | } | |
1604 | goto unlock_discard; | |
1605 | } | |
1606 | ||
1607 | /* Link is now in state WORKING_WORKING */ | |
1608 | if (unlikely(seq_no != mod(l_ptr->next_in_no))) { | |
b97bf3fd PL |
1609 | link_handle_out_of_seq_msg(l_ptr, buf); |
1610 | head = link_insert_deferred_queue(l_ptr, head); | |
4323add6 | 1611 | tipc_node_unlock(n_ptr); |
b97bf3fd PL |
1612 | continue; |
1613 | } | |
3af390e2 YX |
1614 | l_ptr->next_in_no++; |
1615 | if (unlikely(l_ptr->oldest_deferred_in)) | |
b97bf3fd | 1616 | head = link_insert_deferred_queue(l_ptr, head); |
3af390e2 YX |
1617 | deliver: |
1618 | if (likely(msg_isdata(msg))) { | |
4323add6 | 1619 | tipc_node_unlock(n_ptr); |
3af390e2 | 1620 | tipc_port_recv_msg(buf); |
b97bf3fd PL |
1621 | continue; |
1622 | } | |
3af390e2 YX |
1623 | switch (msg_user(msg)) { |
1624 | int ret; | |
1625 | case MSG_BUNDLER: | |
1626 | l_ptr->stats.recv_bundles++; | |
1627 | l_ptr->stats.recv_bundled += msg_msgcnt(msg); | |
1628 | tipc_node_unlock(n_ptr); | |
1629 | tipc_link_recv_bundle(buf); | |
1630 | continue; | |
1631 | case NAME_DISTRIBUTOR: | |
1632 | n_ptr->bclink.recv_permitted = true; | |
1633 | tipc_node_unlock(n_ptr); | |
1634 | tipc_named_recv(buf); | |
1635 | continue; | |
1636 | case BCAST_PROTOCOL: | |
1637 | tipc_link_recv_sync(n_ptr, buf); | |
4323add6 | 1638 | tipc_node_unlock(n_ptr); |
b97bf3fd | 1639 | continue; |
3af390e2 YX |
1640 | case CONN_MANAGER: |
1641 | tipc_node_unlock(n_ptr); | |
1642 | tipc_port_recv_proto_msg(buf); | |
1643 | continue; | |
1644 | case MSG_FRAGMENTER: | |
1645 | l_ptr->stats.recv_fragments++; | |
40ba3cdf EH |
1646 | ret = tipc_link_recv_fragment(&l_ptr->reasm_head, |
1647 | &l_ptr->reasm_tail, | |
1648 | &buf); | |
1649 | if (ret == LINK_REASM_COMPLETE) { | |
3af390e2 | 1650 | l_ptr->stats.recv_fragmented++; |
40ba3cdf | 1651 | msg = buf_msg(buf); |
3af390e2 YX |
1652 | goto deliver; |
1653 | } | |
40ba3cdf | 1654 | if (ret == LINK_REASM_ERROR) |
a715b49e | 1655 | tipc_link_reset(l_ptr); |
528f6f4b EH |
1656 | tipc_node_unlock(n_ptr); |
1657 | continue; | |
3af390e2 YX |
1658 | case CHANGEOVER_PROTOCOL: |
1659 | type = msg_type(msg); | |
1660 | if (link_recv_changeover_msg(&l_ptr, &buf)) { | |
1661 | msg = buf_msg(buf); | |
1662 | seq_no = msg_seqno(msg); | |
1663 | if (type == ORIGINAL_MSG) | |
1664 | goto deliver; | |
1665 | goto protocol_check; | |
1666 | } | |
1667 | break; | |
1668 | default: | |
1669 | kfree_skb(buf); | |
1670 | buf = NULL; | |
1671 | break; | |
b97bf3fd | 1672 | } |
4323add6 | 1673 | tipc_node_unlock(n_ptr); |
3af390e2 YX |
1674 | tipc_net_route_msg(buf); |
1675 | continue; | |
1676 | unlock_discard: | |
1677 | ||
1678 | tipc_node_unlock(n_ptr); | |
1679 | discard: | |
5f6d9123 | 1680 | kfree_skb(buf); |
b97bf3fd | 1681 | } |
4323add6 | 1682 | read_unlock_bh(&tipc_net_lock); |
b97bf3fd PL |
1683 | } |
1684 | ||
2c53040f | 1685 | /** |
8809b255 AS |
1686 | * tipc_link_defer_pkt - Add out-of-sequence message to deferred reception queue |
1687 | * | |
1688 | * Returns increase in queue length (i.e. 0 or 1) | |
b97bf3fd | 1689 | */ |
8809b255 | 1690 | u32 tipc_link_defer_pkt(struct sk_buff **head, struct sk_buff **tail, |
4323add6 | 1691 | struct sk_buff *buf) |
b97bf3fd | 1692 | { |
8809b255 AS |
1693 | struct sk_buff *queue_buf; |
1694 | struct sk_buff **prev; | |
f905730c | 1695 | u32 seq_no = buf_seqno(buf); |
b97bf3fd PL |
1696 | |
1697 | buf->next = NULL; | |
1698 | ||
1699 | /* Empty queue ? */ | |
1700 | if (*head == NULL) { | |
1701 | *head = *tail = buf; | |
1702 | return 1; | |
1703 | } | |
1704 | ||
1705 | /* Last ? */ | |
f905730c | 1706 | if (less(buf_seqno(*tail), seq_no)) { |
b97bf3fd PL |
1707 | (*tail)->next = buf; |
1708 | *tail = buf; | |
1709 | return 1; | |
1710 | } | |
1711 | ||
8809b255 AS |
1712 | /* Locate insertion point in queue, then insert; discard if duplicate */ |
1713 | prev = head; | |
1714 | queue_buf = *head; | |
1715 | for (;;) { | |
1716 | u32 curr_seqno = buf_seqno(queue_buf); | |
b97bf3fd | 1717 | |
8809b255 | 1718 | if (seq_no == curr_seqno) { |
5f6d9123 | 1719 | kfree_skb(buf); |
8809b255 | 1720 | return 0; |
b97bf3fd | 1721 | } |
8809b255 AS |
1722 | |
1723 | if (less(seq_no, curr_seqno)) | |
b97bf3fd | 1724 | break; |
b97bf3fd | 1725 | |
8809b255 AS |
1726 | prev = &queue_buf->next; |
1727 | queue_buf = queue_buf->next; | |
1728 | } | |
b97bf3fd | 1729 | |
8809b255 AS |
1730 | buf->next = queue_buf; |
1731 | *prev = buf; | |
1732 | return 1; | |
b97bf3fd PL |
1733 | } |
1734 | ||
8809b255 | 1735 | /* |
b97bf3fd PL |
1736 | * link_handle_out_of_seq_msg - handle arrival of out-of-sequence packet |
1737 | */ | |
a18c4bc3 | 1738 | static void link_handle_out_of_seq_msg(struct tipc_link *l_ptr, |
b97bf3fd PL |
1739 | struct sk_buff *buf) |
1740 | { | |
f905730c | 1741 | u32 seq_no = buf_seqno(buf); |
b97bf3fd PL |
1742 | |
1743 | if (likely(msg_user(buf_msg(buf)) == LINK_PROTOCOL)) { | |
1744 | link_recv_proto_msg(l_ptr, buf); | |
1745 | return; | |
1746 | } | |
1747 | ||
b97bf3fd | 1748 | /* Record OOS packet arrival (force mismatch on next timeout) */ |
b97bf3fd PL |
1749 | l_ptr->checkpoint--; |
1750 | ||
c4307285 | 1751 | /* |
b97bf3fd PL |
1752 | * Discard packet if a duplicate; otherwise add it to deferred queue |
1753 | * and notify peer of gap as per protocol specification | |
1754 | */ | |
b97bf3fd PL |
1755 | if (less(seq_no, mod(l_ptr->next_in_no))) { |
1756 | l_ptr->stats.duplicates++; | |
5f6d9123 | 1757 | kfree_skb(buf); |
b97bf3fd PL |
1758 | return; |
1759 | } | |
1760 | ||
4323add6 PL |
1761 | if (tipc_link_defer_pkt(&l_ptr->oldest_deferred_in, |
1762 | &l_ptr->newest_deferred_in, buf)) { | |
b97bf3fd PL |
1763 | l_ptr->deferred_inqueue_sz++; |
1764 | l_ptr->stats.deferred_recv++; | |
1765 | if ((l_ptr->deferred_inqueue_sz % 16) == 1) | |
4323add6 | 1766 | tipc_link_send_proto_msg(l_ptr, STATE_MSG, 0, 0, 0, 0, 0); |
b97bf3fd PL |
1767 | } else |
1768 | l_ptr->stats.duplicates++; | |
1769 | } | |
1770 | ||
1771 | /* | |
1772 | * Send protocol message to the other endpoint. | |
1773 | */ | |
a18c4bc3 | 1774 | void tipc_link_send_proto_msg(struct tipc_link *l_ptr, u32 msg_typ, |
ae8509c4 PG |
1775 | int probe_msg, u32 gap, u32 tolerance, |
1776 | u32 priority, u32 ack_mtu) | |
b97bf3fd | 1777 | { |
1fc54d8f | 1778 | struct sk_buff *buf = NULL; |
b97bf3fd | 1779 | struct tipc_msg *msg = l_ptr->pmsg; |
c4307285 | 1780 | u32 msg_size = sizeof(l_ptr->proto_msg); |
75f0aa49 | 1781 | int r_flag; |
b97bf3fd | 1782 | |
92d2c905 | 1783 | /* Discard any previous message that was deferred due to congestion */ |
92d2c905 | 1784 | if (l_ptr->proto_msg_queue) { |
5f6d9123 | 1785 | kfree_skb(l_ptr->proto_msg_queue); |
92d2c905 AS |
1786 | l_ptr->proto_msg_queue = NULL; |
1787 | } | |
1788 | ||
b97bf3fd PL |
1789 | if (link_blocked(l_ptr)) |
1790 | return; | |
b4b56102 AS |
1791 | |
1792 | /* Abort non-RESET send if communication with node is prohibited */ | |
b4b56102 AS |
1793 | if ((l_ptr->owner->block_setup) && (msg_typ != RESET_MSG)) |
1794 | return; | |
1795 | ||
92d2c905 | 1796 | /* Create protocol message with "out-of-sequence" sequence number */ |
b97bf3fd PL |
1797 | msg_set_type(msg, msg_typ); |
1798 | msg_set_net_plane(msg, l_ptr->b_ptr->net_plane); | |
7a54d4a9 | 1799 | msg_set_bcast_ack(msg, l_ptr->owner->bclink.last_in); |
4323add6 | 1800 | msg_set_last_bcast(msg, tipc_bclink_get_last_sent()); |
b97bf3fd PL |
1801 | |
1802 | if (msg_typ == STATE_MSG) { | |
1803 | u32 next_sent = mod(l_ptr->next_out_no); | |
1804 | ||
4323add6 | 1805 | if (!tipc_link_is_up(l_ptr)) |
b97bf3fd PL |
1806 | return; |
1807 | if (l_ptr->next_out) | |
f905730c | 1808 | next_sent = buf_seqno(l_ptr->next_out); |
b97bf3fd PL |
1809 | msg_set_next_sent(msg, next_sent); |
1810 | if (l_ptr->oldest_deferred_in) { | |
f905730c | 1811 | u32 rec = buf_seqno(l_ptr->oldest_deferred_in); |
b97bf3fd PL |
1812 | gap = mod(rec - mod(l_ptr->next_in_no)); |
1813 | } | |
1814 | msg_set_seq_gap(msg, gap); | |
1815 | if (gap) | |
1816 | l_ptr->stats.sent_nacks++; | |
1817 | msg_set_link_tolerance(msg, tolerance); | |
1818 | msg_set_linkprio(msg, priority); | |
1819 | msg_set_max_pkt(msg, ack_mtu); | |
1820 | msg_set_ack(msg, mod(l_ptr->next_in_no - 1)); | |
1821 | msg_set_probe(msg, probe_msg != 0); | |
c4307285 | 1822 | if (probe_msg) { |
b97bf3fd PL |
1823 | u32 mtu = l_ptr->max_pkt; |
1824 | ||
c4307285 | 1825 | if ((mtu < l_ptr->max_pkt_target) && |
b97bf3fd PL |
1826 | link_working_working(l_ptr) && |
1827 | l_ptr->fsm_msg_cnt) { | |
1828 | msg_size = (mtu + (l_ptr->max_pkt_target - mtu)/2 + 2) & ~3; | |
c4307285 YH |
1829 | if (l_ptr->max_pkt_probes == 10) { |
1830 | l_ptr->max_pkt_target = (msg_size - 4); | |
1831 | l_ptr->max_pkt_probes = 0; | |
b97bf3fd | 1832 | msg_size = (mtu + (l_ptr->max_pkt_target - mtu)/2 + 2) & ~3; |
c4307285 | 1833 | } |
b97bf3fd | 1834 | l_ptr->max_pkt_probes++; |
c4307285 | 1835 | } |
b97bf3fd PL |
1836 | |
1837 | l_ptr->stats.sent_probes++; | |
c4307285 | 1838 | } |
b97bf3fd PL |
1839 | l_ptr->stats.sent_states++; |
1840 | } else { /* RESET_MSG or ACTIVATE_MSG */ | |
1841 | msg_set_ack(msg, mod(l_ptr->reset_checkpoint - 1)); | |
1842 | msg_set_seq_gap(msg, 0); | |
1843 | msg_set_next_sent(msg, 1); | |
f23d9bf2 | 1844 | msg_set_probe(msg, 0); |
b97bf3fd PL |
1845 | msg_set_link_tolerance(msg, l_ptr->tolerance); |
1846 | msg_set_linkprio(msg, l_ptr->priority); | |
1847 | msg_set_max_pkt(msg, l_ptr->max_pkt_target); | |
1848 | } | |
1849 | ||
75f0aa49 AS |
1850 | r_flag = (l_ptr->owner->working_links > tipc_link_is_up(l_ptr)); |
1851 | msg_set_redundant_link(msg, r_flag); | |
b97bf3fd | 1852 | msg_set_linkprio(msg, l_ptr->priority); |
92d2c905 | 1853 | msg_set_size(msg, msg_size); |
b97bf3fd PL |
1854 | |
1855 | msg_set_seqno(msg, mod(l_ptr->next_out_no + (0xffff/2))); | |
1856 | ||
31e3c3f6 | 1857 | buf = tipc_buf_acquire(msg_size); |
b97bf3fd PL |
1858 | if (!buf) |
1859 | return; | |
1860 | ||
27d7ff46 | 1861 | skb_copy_to_linear_data(buf, msg, sizeof(l_ptr->proto_msg)); |
796c75d0 | 1862 | buf->priority = TC_PRIO_CONTROL; |
b97bf3fd | 1863 | |
3c294cb3 YX |
1864 | /* Defer message if bearer is already blocked */ |
1865 | if (tipc_bearer_blocked(l_ptr->b_ptr)) { | |
92d2c905 | 1866 | l_ptr->proto_msg_queue = buf; |
b97bf3fd PL |
1867 | return; |
1868 | } | |
1869 | ||
3c294cb3 | 1870 | tipc_bearer_send(l_ptr->b_ptr, buf, &l_ptr->media_addr); |
92d2c905 | 1871 | l_ptr->unacked_window = 0; |
5f6d9123 | 1872 | kfree_skb(buf); |
b97bf3fd PL |
1873 | } |
1874 | ||
1875 | /* | |
1876 | * Receive protocol message : | |
c4307285 YH |
1877 | * Note that network plane id propagates through the network, and may |
1878 | * change at any time. The node with lowest address rules | |
b97bf3fd | 1879 | */ |
a18c4bc3 | 1880 | static void link_recv_proto_msg(struct tipc_link *l_ptr, struct sk_buff *buf) |
b97bf3fd PL |
1881 | { |
1882 | u32 rec_gap = 0; | |
1883 | u32 max_pkt_info; | |
c4307285 | 1884 | u32 max_pkt_ack; |
b97bf3fd PL |
1885 | u32 msg_tol; |
1886 | struct tipc_msg *msg = buf_msg(buf); | |
1887 | ||
b97bf3fd PL |
1888 | if (link_blocked(l_ptr)) |
1889 | goto exit; | |
1890 | ||
1891 | /* record unnumbered packet arrival (force mismatch on next timeout) */ | |
b97bf3fd PL |
1892 | l_ptr->checkpoint--; |
1893 | ||
1894 | if (l_ptr->b_ptr->net_plane != msg_net_plane(msg)) | |
1895 | if (tipc_own_addr > msg_prevnode(msg)) | |
1896 | l_ptr->b_ptr->net_plane = msg_net_plane(msg); | |
1897 | ||
1898 | l_ptr->owner->permit_changeover = msg_redundant_link(msg); | |
1899 | ||
1900 | switch (msg_type(msg)) { | |
c4307285 | 1901 | |
b97bf3fd | 1902 | case RESET_MSG: |
a686e685 AS |
1903 | if (!link_working_unknown(l_ptr) && |
1904 | (l_ptr->peer_session != INVALID_SESSION)) { | |
641c218d AS |
1905 | if (less_eq(msg_session(msg), l_ptr->peer_session)) |
1906 | break; /* duplicate or old reset: ignore */ | |
b97bf3fd | 1907 | } |
b4b56102 AS |
1908 | |
1909 | if (!msg_redundant_link(msg) && (link_working_working(l_ptr) || | |
1910 | link_working_unknown(l_ptr))) { | |
1911 | /* | |
1912 | * peer has lost contact -- don't allow peer's links | |
1913 | * to reactivate before we recognize loss & clean up | |
1914 | */ | |
1915 | l_ptr->owner->block_setup = WAIT_NODE_DOWN; | |
1916 | } | |
1917 | ||
47361c87 AS |
1918 | link_state_event(l_ptr, RESET_MSG); |
1919 | ||
b97bf3fd PL |
1920 | /* fall thru' */ |
1921 | case ACTIVATE_MSG: | |
1922 | /* Update link settings according other endpoint's values */ | |
b97bf3fd PL |
1923 | strcpy((strrchr(l_ptr->name, ':') + 1), (char *)msg_data(msg)); |
1924 | ||
2db9983a AS |
1925 | msg_tol = msg_link_tolerance(msg); |
1926 | if (msg_tol > l_ptr->tolerance) | |
b97bf3fd PL |
1927 | link_set_supervision_props(l_ptr, msg_tol); |
1928 | ||
1929 | if (msg_linkprio(msg) > l_ptr->priority) | |
1930 | l_ptr->priority = msg_linkprio(msg); | |
1931 | ||
1932 | max_pkt_info = msg_max_pkt(msg); | |
c4307285 | 1933 | if (max_pkt_info) { |
b97bf3fd PL |
1934 | if (max_pkt_info < l_ptr->max_pkt_target) |
1935 | l_ptr->max_pkt_target = max_pkt_info; | |
1936 | if (l_ptr->max_pkt > l_ptr->max_pkt_target) | |
1937 | l_ptr->max_pkt = l_ptr->max_pkt_target; | |
1938 | } else { | |
c4307285 | 1939 | l_ptr->max_pkt = l_ptr->max_pkt_target; |
b97bf3fd | 1940 | } |
b97bf3fd | 1941 | |
4d75313c | 1942 | /* Synchronize broadcast link info, if not done previously */ |
7a54d4a9 AS |
1943 | if (!tipc_node_is_up(l_ptr->owner)) { |
1944 | l_ptr->owner->bclink.last_sent = | |
1945 | l_ptr->owner->bclink.last_in = | |
1946 | msg_last_bcast(msg); | |
1947 | l_ptr->owner->bclink.oos_state = 0; | |
1948 | } | |
4d75313c | 1949 | |
b97bf3fd PL |
1950 | l_ptr->peer_session = msg_session(msg); |
1951 | l_ptr->peer_bearer_id = msg_bearer_id(msg); | |
47361c87 AS |
1952 | |
1953 | if (msg_type(msg) == ACTIVATE_MSG) | |
1954 | link_state_event(l_ptr, ACTIVATE_MSG); | |
b97bf3fd PL |
1955 | break; |
1956 | case STATE_MSG: | |
1957 | ||
2db9983a AS |
1958 | msg_tol = msg_link_tolerance(msg); |
1959 | if (msg_tol) | |
b97bf3fd | 1960 | link_set_supervision_props(l_ptr, msg_tol); |
c4307285 YH |
1961 | |
1962 | if (msg_linkprio(msg) && | |
b97bf3fd | 1963 | (msg_linkprio(msg) != l_ptr->priority)) { |
2cf8aa19 EH |
1964 | pr_warn("%s<%s>, priority change %u->%u\n", |
1965 | link_rst_msg, l_ptr->name, l_ptr->priority, | |
1966 | msg_linkprio(msg)); | |
b97bf3fd | 1967 | l_ptr->priority = msg_linkprio(msg); |
4323add6 | 1968 | tipc_link_reset(l_ptr); /* Enforce change to take effect */ |
b97bf3fd PL |
1969 | break; |
1970 | } | |
1971 | link_state_event(l_ptr, TRAFFIC_MSG_EVT); | |
1972 | l_ptr->stats.recv_states++; | |
1973 | if (link_reset_unknown(l_ptr)) | |
1974 | break; | |
1975 | ||
1976 | if (less_eq(mod(l_ptr->next_in_no), msg_next_sent(msg))) { | |
c4307285 | 1977 | rec_gap = mod(msg_next_sent(msg) - |
b97bf3fd PL |
1978 | mod(l_ptr->next_in_no)); |
1979 | } | |
1980 | ||
1981 | max_pkt_ack = msg_max_pkt(msg); | |
c4307285 | 1982 | if (max_pkt_ack > l_ptr->max_pkt) { |
c4307285 YH |
1983 | l_ptr->max_pkt = max_pkt_ack; |
1984 | l_ptr->max_pkt_probes = 0; | |
1985 | } | |
b97bf3fd PL |
1986 | |
1987 | max_pkt_ack = 0; | |
c4307285 | 1988 | if (msg_probe(msg)) { |
b97bf3fd | 1989 | l_ptr->stats.recv_probes++; |
a016892c | 1990 | if (msg_size(msg) > sizeof(l_ptr->proto_msg)) |
c4307285 | 1991 | max_pkt_ack = msg_size(msg); |
c4307285 | 1992 | } |
b97bf3fd PL |
1993 | |
1994 | /* Protocol message before retransmits, reduce loss risk */ | |
389dd9bc | 1995 | if (l_ptr->owner->bclink.recv_permitted) |
7a54d4a9 AS |
1996 | tipc_bclink_update_link_state(l_ptr->owner, |
1997 | msg_last_bcast(msg)); | |
b97bf3fd PL |
1998 | |
1999 | if (rec_gap || (msg_probe(msg))) { | |
4323add6 PL |
2000 | tipc_link_send_proto_msg(l_ptr, STATE_MSG, |
2001 | 0, rec_gap, 0, 0, max_pkt_ack); | |
b97bf3fd PL |
2002 | } |
2003 | if (msg_seq_gap(msg)) { | |
b97bf3fd | 2004 | l_ptr->stats.recv_nacks++; |
4323add6 PL |
2005 | tipc_link_retransmit(l_ptr, l_ptr->first_out, |
2006 | msg_seq_gap(msg)); | |
b97bf3fd PL |
2007 | } |
2008 | break; | |
b97bf3fd PL |
2009 | } |
2010 | exit: | |
5f6d9123 | 2011 | kfree_skb(buf); |
b97bf3fd PL |
2012 | } |
2013 | ||
2014 | ||
2015 | /* | |
c4307285 | 2016 | * tipc_link_tunnel(): Send one message via a link belonging to |
b97bf3fd PL |
2017 | * another bearer. Owner node is locked. |
2018 | */ | |
a18c4bc3 | 2019 | static void tipc_link_tunnel(struct tipc_link *l_ptr, |
ae8509c4 | 2020 | struct tipc_msg *tunnel_hdr, struct tipc_msg *msg, |
31e3c3f6 | 2021 | u32 selector) |
b97bf3fd | 2022 | { |
a18c4bc3 | 2023 | struct tipc_link *tunnel; |
b97bf3fd PL |
2024 | struct sk_buff *buf; |
2025 | u32 length = msg_size(msg); | |
2026 | ||
2027 | tunnel = l_ptr->owner->active_links[selector & 1]; | |
5392d646 | 2028 | if (!tipc_link_is_up(tunnel)) { |
2cf8aa19 | 2029 | pr_warn("%stunnel link no longer available\n", link_co_err); |
b97bf3fd | 2030 | return; |
5392d646 | 2031 | } |
b97bf3fd | 2032 | msg_set_size(tunnel_hdr, length + INT_H_SIZE); |
31e3c3f6 | 2033 | buf = tipc_buf_acquire(length + INT_H_SIZE); |
5392d646 | 2034 | if (!buf) { |
2cf8aa19 | 2035 | pr_warn("%sunable to send tunnel msg\n", link_co_err); |
b97bf3fd | 2036 | return; |
5392d646 | 2037 | } |
27d7ff46 ACM |
2038 | skb_copy_to_linear_data(buf, tunnel_hdr, INT_H_SIZE); |
2039 | skb_copy_to_linear_data_offset(buf, INT_H_SIZE, msg, length); | |
4323add6 | 2040 | tipc_link_send_buf(tunnel, buf); |
b97bf3fd PL |
2041 | } |
2042 | ||
2043 | ||
2044 | ||
2045 | /* | |
2046 | * changeover(): Send whole message queue via the remaining link | |
2047 | * Owner node is locked. | |
2048 | */ | |
a18c4bc3 | 2049 | void tipc_link_changeover(struct tipc_link *l_ptr) |
b97bf3fd PL |
2050 | { |
2051 | u32 msgcount = l_ptr->out_queue_size; | |
2052 | struct sk_buff *crs = l_ptr->first_out; | |
a18c4bc3 | 2053 | struct tipc_link *tunnel = l_ptr->owner->active_links[0]; |
b97bf3fd | 2054 | struct tipc_msg tunnel_hdr; |
5392d646 | 2055 | int split_bundles; |
b97bf3fd PL |
2056 | |
2057 | if (!tunnel) | |
2058 | return; | |
2059 | ||
5392d646 | 2060 | if (!l_ptr->owner->permit_changeover) { |
2cf8aa19 | 2061 | pr_warn("%speer did not permit changeover\n", link_co_err); |
b97bf3fd | 2062 | return; |
5392d646 | 2063 | } |
b97bf3fd | 2064 | |
c68ca7b7 | 2065 | tipc_msg_init(&tunnel_hdr, CHANGEOVER_PROTOCOL, |
75715217 | 2066 | ORIGINAL_MSG, INT_H_SIZE, l_ptr->addr); |
b97bf3fd PL |
2067 | msg_set_bearer_id(&tunnel_hdr, l_ptr->peer_bearer_id); |
2068 | msg_set_msgcnt(&tunnel_hdr, msgcount); | |
f131072c | 2069 | |
b97bf3fd PL |
2070 | if (!l_ptr->first_out) { |
2071 | struct sk_buff *buf; | |
2072 | ||
31e3c3f6 | 2073 | buf = tipc_buf_acquire(INT_H_SIZE); |
b97bf3fd | 2074 | if (buf) { |
27d7ff46 | 2075 | skb_copy_to_linear_data(buf, &tunnel_hdr, INT_H_SIZE); |
b97bf3fd | 2076 | msg_set_size(&tunnel_hdr, INT_H_SIZE); |
4323add6 | 2077 | tipc_link_send_buf(tunnel, buf); |
b97bf3fd | 2078 | } else { |
2cf8aa19 EH |
2079 | pr_warn("%sunable to send changeover msg\n", |
2080 | link_co_err); | |
b97bf3fd PL |
2081 | } |
2082 | return; | |
2083 | } | |
f131072c | 2084 | |
c4307285 | 2085 | split_bundles = (l_ptr->owner->active_links[0] != |
5392d646 AS |
2086 | l_ptr->owner->active_links[1]); |
2087 | ||
b97bf3fd PL |
2088 | while (crs) { |
2089 | struct tipc_msg *msg = buf_msg(crs); | |
2090 | ||
2091 | if ((msg_user(msg) == MSG_BUNDLER) && split_bundles) { | |
b97bf3fd | 2092 | struct tipc_msg *m = msg_get_wrapped(msg); |
0e65967e | 2093 | unchar *pos = (unchar *)m; |
b97bf3fd | 2094 | |
d788d805 | 2095 | msgcount = msg_msgcnt(msg); |
b97bf3fd | 2096 | while (msgcount--) { |
0e65967e | 2097 | msg_set_seqno(m, msg_seqno(msg)); |
4323add6 PL |
2098 | tipc_link_tunnel(l_ptr, &tunnel_hdr, m, |
2099 | msg_link_selector(m)); | |
b97bf3fd PL |
2100 | pos += align(msg_size(m)); |
2101 | m = (struct tipc_msg *)pos; | |
2102 | } | |
2103 | } else { | |
4323add6 PL |
2104 | tipc_link_tunnel(l_ptr, &tunnel_hdr, msg, |
2105 | msg_link_selector(msg)); | |
b97bf3fd PL |
2106 | } |
2107 | crs = crs->next; | |
2108 | } | |
2109 | } | |
2110 | ||
a18c4bc3 | 2111 | void tipc_link_send_duplicate(struct tipc_link *l_ptr, struct tipc_link *tunnel) |
b97bf3fd PL |
2112 | { |
2113 | struct sk_buff *iter; | |
2114 | struct tipc_msg tunnel_hdr; | |
2115 | ||
c68ca7b7 | 2116 | tipc_msg_init(&tunnel_hdr, CHANGEOVER_PROTOCOL, |
75715217 | 2117 | DUPLICATE_MSG, INT_H_SIZE, l_ptr->addr); |
b97bf3fd PL |
2118 | msg_set_msgcnt(&tunnel_hdr, l_ptr->out_queue_size); |
2119 | msg_set_bearer_id(&tunnel_hdr, l_ptr->peer_bearer_id); | |
2120 | iter = l_ptr->first_out; | |
2121 | while (iter) { | |
2122 | struct sk_buff *outbuf; | |
2123 | struct tipc_msg *msg = buf_msg(iter); | |
2124 | u32 length = msg_size(msg); | |
2125 | ||
2126 | if (msg_user(msg) == MSG_BUNDLER) | |
2127 | msg_set_type(msg, CLOSED_MSG); | |
2128 | msg_set_ack(msg, mod(l_ptr->next_in_no - 1)); /* Update */ | |
c4307285 | 2129 | msg_set_bcast_ack(msg, l_ptr->owner->bclink.last_in); |
b97bf3fd | 2130 | msg_set_size(&tunnel_hdr, length + INT_H_SIZE); |
31e3c3f6 | 2131 | outbuf = tipc_buf_acquire(length + INT_H_SIZE); |
b97bf3fd | 2132 | if (outbuf == NULL) { |
2cf8aa19 EH |
2133 | pr_warn("%sunable to send duplicate msg\n", |
2134 | link_co_err); | |
b97bf3fd PL |
2135 | return; |
2136 | } | |
27d7ff46 ACM |
2137 | skb_copy_to_linear_data(outbuf, &tunnel_hdr, INT_H_SIZE); |
2138 | skb_copy_to_linear_data_offset(outbuf, INT_H_SIZE, iter->data, | |
2139 | length); | |
4323add6 PL |
2140 | tipc_link_send_buf(tunnel, outbuf); |
2141 | if (!tipc_link_is_up(l_ptr)) | |
b97bf3fd PL |
2142 | return; |
2143 | iter = iter->next; | |
2144 | } | |
2145 | } | |
2146 | ||
b97bf3fd PL |
2147 | /** |
2148 | * buf_extract - extracts embedded TIPC message from another message | |
2149 | * @skb: encapsulating message buffer | |
2150 | * @from_pos: offset to extract from | |
2151 | * | |
c4307285 | 2152 | * Returns a new message buffer containing an embedded message. The |
b97bf3fd PL |
2153 | * encapsulating message itself is left unchanged. |
2154 | */ | |
b97bf3fd PL |
2155 | static struct sk_buff *buf_extract(struct sk_buff *skb, u32 from_pos) |
2156 | { | |
2157 | struct tipc_msg *msg = (struct tipc_msg *)(skb->data + from_pos); | |
2158 | u32 size = msg_size(msg); | |
2159 | struct sk_buff *eb; | |
2160 | ||
31e3c3f6 | 2161 | eb = tipc_buf_acquire(size); |
b97bf3fd | 2162 | if (eb) |
27d7ff46 | 2163 | skb_copy_to_linear_data(eb, msg, size); |
b97bf3fd PL |
2164 | return eb; |
2165 | } | |
2166 | ||
c4307285 | 2167 | /* |
b97bf3fd PL |
2168 | * link_recv_changeover_msg(): Receive tunneled packet sent |
2169 | * via other link. Node is locked. Return extracted buffer. | |
2170 | */ | |
a18c4bc3 | 2171 | static int link_recv_changeover_msg(struct tipc_link **l_ptr, |
b97bf3fd PL |
2172 | struct sk_buff **buf) |
2173 | { | |
2174 | struct sk_buff *tunnel_buf = *buf; | |
a18c4bc3 | 2175 | struct tipc_link *dest_link; |
b97bf3fd PL |
2176 | struct tipc_msg *msg; |
2177 | struct tipc_msg *tunnel_msg = buf_msg(tunnel_buf); | |
2178 | u32 msg_typ = msg_type(tunnel_msg); | |
2179 | u32 msg_count = msg_msgcnt(tunnel_msg); | |
cb4b102f | 2180 | u32 bearer_id = msg_bearer_id(tunnel_msg); |
b97bf3fd | 2181 | |
cb4b102f DC |
2182 | if (bearer_id >= MAX_BEARERS) |
2183 | goto exit; | |
2184 | dest_link = (*l_ptr)->owner->links[bearer_id]; | |
b29f1428 | 2185 | if (!dest_link) |
b97bf3fd | 2186 | goto exit; |
f131072c | 2187 | if (dest_link == *l_ptr) { |
2cf8aa19 EH |
2188 | pr_err("Unexpected changeover message on link <%s>\n", |
2189 | (*l_ptr)->name); | |
f131072c AS |
2190 | goto exit; |
2191 | } | |
b97bf3fd PL |
2192 | *l_ptr = dest_link; |
2193 | msg = msg_get_wrapped(tunnel_msg); | |
2194 | ||
2195 | if (msg_typ == DUPLICATE_MSG) { | |
b29f1428 | 2196 | if (less(msg_seqno(msg), mod(dest_link->next_in_no))) |
b97bf3fd | 2197 | goto exit; |
0e65967e | 2198 | *buf = buf_extract(tunnel_buf, INT_H_SIZE); |
b97bf3fd | 2199 | if (*buf == NULL) { |
2cf8aa19 | 2200 | pr_warn("%sduplicate msg dropped\n", link_co_err); |
b97bf3fd PL |
2201 | goto exit; |
2202 | } | |
5f6d9123 | 2203 | kfree_skb(tunnel_buf); |
b97bf3fd PL |
2204 | return 1; |
2205 | } | |
2206 | ||
2207 | /* First original message ?: */ | |
4323add6 | 2208 | if (tipc_link_is_up(dest_link)) { |
2cf8aa19 EH |
2209 | pr_info("%s<%s>, changeover initiated by peer\n", link_rst_msg, |
2210 | dest_link->name); | |
4323add6 | 2211 | tipc_link_reset(dest_link); |
b97bf3fd PL |
2212 | dest_link->exp_msg_count = msg_count; |
2213 | if (!msg_count) | |
2214 | goto exit; | |
2215 | } else if (dest_link->exp_msg_count == START_CHANGEOVER) { | |
b97bf3fd PL |
2216 | dest_link->exp_msg_count = msg_count; |
2217 | if (!msg_count) | |
2218 | goto exit; | |
2219 | } | |
2220 | ||
2221 | /* Receive original message */ | |
b97bf3fd | 2222 | if (dest_link->exp_msg_count == 0) { |
2cf8aa19 | 2223 | pr_warn("%sgot too many tunnelled messages\n", link_co_err); |
b97bf3fd PL |
2224 | goto exit; |
2225 | } | |
2226 | dest_link->exp_msg_count--; | |
2227 | if (less(msg_seqno(msg), dest_link->reset_checkpoint)) { | |
b97bf3fd PL |
2228 | goto exit; |
2229 | } else { | |
2230 | *buf = buf_extract(tunnel_buf, INT_H_SIZE); | |
2231 | if (*buf != NULL) { | |
5f6d9123 | 2232 | kfree_skb(tunnel_buf); |
b97bf3fd PL |
2233 | return 1; |
2234 | } else { | |
2cf8aa19 | 2235 | pr_warn("%soriginal msg dropped\n", link_co_err); |
b97bf3fd PL |
2236 | } |
2237 | } | |
2238 | exit: | |
1fc54d8f | 2239 | *buf = NULL; |
5f6d9123 | 2240 | kfree_skb(tunnel_buf); |
b97bf3fd PL |
2241 | return 0; |
2242 | } | |
2243 | ||
2244 | /* | |
2245 | * Bundler functionality: | |
2246 | */ | |
4323add6 | 2247 | void tipc_link_recv_bundle(struct sk_buff *buf) |
b97bf3fd PL |
2248 | { |
2249 | u32 msgcount = msg_msgcnt(buf_msg(buf)); | |
2250 | u32 pos = INT_H_SIZE; | |
2251 | struct sk_buff *obuf; | |
2252 | ||
b97bf3fd PL |
2253 | while (msgcount--) { |
2254 | obuf = buf_extract(buf, pos); | |
2255 | if (obuf == NULL) { | |
2cf8aa19 | 2256 | pr_warn("Link unable to unbundle message(s)\n"); |
a10bd924 | 2257 | break; |
3ff50b79 | 2258 | } |
b97bf3fd | 2259 | pos += align(msg_size(buf_msg(obuf))); |
4323add6 | 2260 | tipc_net_route_msg(obuf); |
b97bf3fd | 2261 | } |
5f6d9123 | 2262 | kfree_skb(buf); |
b97bf3fd PL |
2263 | } |
2264 | ||
2265 | /* | |
2266 | * Fragmentation/defragmentation: | |
2267 | */ | |
2268 | ||
c4307285 | 2269 | /* |
31e3c3f6 | 2270 | * link_send_long_buf: Entry for buffers needing fragmentation. |
c4307285 | 2271 | * The buffer is complete, inclusive total message length. |
b97bf3fd PL |
2272 | * Returns user data length. |
2273 | */ | |
a18c4bc3 | 2274 | static int link_send_long_buf(struct tipc_link *l_ptr, struct sk_buff *buf) |
b97bf3fd | 2275 | { |
77561557 AS |
2276 | struct sk_buff *buf_chain = NULL; |
2277 | struct sk_buff *buf_chain_tail = (struct sk_buff *)&buf_chain; | |
b97bf3fd PL |
2278 | struct tipc_msg *inmsg = buf_msg(buf); |
2279 | struct tipc_msg fragm_hdr; | |
2280 | u32 insize = msg_size(inmsg); | |
2281 | u32 dsz = msg_data_sz(inmsg); | |
2282 | unchar *crs = buf->data; | |
2283 | u32 rest = insize; | |
15e979da | 2284 | u32 pack_sz = l_ptr->max_pkt; |
b97bf3fd | 2285 | u32 fragm_sz = pack_sz - INT_H_SIZE; |
77561557 | 2286 | u32 fragm_no = 0; |
9c396a7b | 2287 | u32 destaddr; |
b97bf3fd PL |
2288 | |
2289 | if (msg_short(inmsg)) | |
2290 | destaddr = l_ptr->addr; | |
9c396a7b AS |
2291 | else |
2292 | destaddr = msg_destnode(inmsg); | |
b97bf3fd | 2293 | |
b97bf3fd | 2294 | /* Prepare reusable fragment header: */ |
c68ca7b7 | 2295 | tipc_msg_init(&fragm_hdr, MSG_FRAGMENTER, FIRST_FRAGMENT, |
75715217 | 2296 | INT_H_SIZE, destaddr); |
b97bf3fd PL |
2297 | |
2298 | /* Chop up message: */ | |
b97bf3fd PL |
2299 | while (rest > 0) { |
2300 | struct sk_buff *fragm; | |
2301 | ||
2302 | if (rest <= fragm_sz) { | |
2303 | fragm_sz = rest; | |
2304 | msg_set_type(&fragm_hdr, LAST_FRAGMENT); | |
2305 | } | |
31e3c3f6 | 2306 | fragm = tipc_buf_acquire(fragm_sz + INT_H_SIZE); |
b97bf3fd | 2307 | if (fragm == NULL) { |
5f6d9123 | 2308 | kfree_skb(buf); |
77561557 AS |
2309 | while (buf_chain) { |
2310 | buf = buf_chain; | |
2311 | buf_chain = buf_chain->next; | |
5f6d9123 | 2312 | kfree_skb(buf); |
77561557 AS |
2313 | } |
2314 | return -ENOMEM; | |
b97bf3fd PL |
2315 | } |
2316 | msg_set_size(&fragm_hdr, fragm_sz + INT_H_SIZE); | |
77561557 AS |
2317 | fragm_no++; |
2318 | msg_set_fragm_no(&fragm_hdr, fragm_no); | |
27d7ff46 ACM |
2319 | skb_copy_to_linear_data(fragm, &fragm_hdr, INT_H_SIZE); |
2320 | skb_copy_to_linear_data_offset(fragm, INT_H_SIZE, crs, | |
2321 | fragm_sz); | |
77561557 AS |
2322 | buf_chain_tail->next = fragm; |
2323 | buf_chain_tail = fragm; | |
b97bf3fd | 2324 | |
b97bf3fd PL |
2325 | rest -= fragm_sz; |
2326 | crs += fragm_sz; | |
2327 | msg_set_type(&fragm_hdr, FRAGMENT); | |
2328 | } | |
5f6d9123 | 2329 | kfree_skb(buf); |
77561557 AS |
2330 | |
2331 | /* Append chain of fragments to send queue & send them */ | |
77561557 AS |
2332 | l_ptr->long_msg_seq_no++; |
2333 | link_add_chain_to_outqueue(l_ptr, buf_chain, l_ptr->long_msg_seq_no); | |
2334 | l_ptr->stats.sent_fragments += fragm_no; | |
2335 | l_ptr->stats.sent_fragmented++; | |
2336 | tipc_link_push_queue(l_ptr); | |
2337 | ||
b97bf3fd PL |
2338 | return dsz; |
2339 | } | |
2340 | ||
c4307285 YH |
2341 | /* |
2342 | * tipc_link_recv_fragment(): Called with node lock on. Returns | |
b97bf3fd PL |
2343 | * the reassembled buffer if message is complete. |
2344 | */ | |
40ba3cdf EH |
2345 | int tipc_link_recv_fragment(struct sk_buff **head, struct sk_buff **tail, |
2346 | struct sk_buff **fbuf) | |
b97bf3fd | 2347 | { |
40ba3cdf EH |
2348 | struct sk_buff *frag = *fbuf; |
2349 | struct tipc_msg *msg = buf_msg(frag); | |
2350 | u32 fragid = msg_type(msg); | |
2351 | bool headstolen; | |
2352 | int delta; | |
2353 | ||
2354 | skb_pull(frag, msg_hdr_sz(msg)); | |
2355 | if (fragid == FIRST_FRAGMENT) { | |
2356 | if (*head || skb_unclone(frag, GFP_ATOMIC)) | |
2357 | goto out_free; | |
2358 | *head = frag; | |
2359 | skb_frag_list_init(*head); | |
b97bf3fd | 2360 | return 0; |
3db0a197 EH |
2361 | } else if (*head && |
2362 | skb_try_coalesce(*head, frag, &headstolen, &delta)) { | |
40ba3cdf EH |
2363 | kfree_skb_partial(frag, headstolen); |
2364 | } else { | |
2365 | if (!*head) | |
2366 | goto out_free; | |
2367 | if (!skb_has_frag_list(*head)) | |
2368 | skb_shinfo(*head)->frag_list = frag; | |
2369 | else | |
2370 | (*tail)->next = frag; | |
2371 | *tail = frag; | |
2372 | (*head)->truesize += frag->truesize; | |
2373 | } | |
2374 | if (fragid == LAST_FRAGMENT) { | |
2375 | *fbuf = *head; | |
2376 | *tail = *head = NULL; | |
2377 | return LINK_REASM_COMPLETE; | |
b97bf3fd | 2378 | } |
b97bf3fd | 2379 | return 0; |
40ba3cdf EH |
2380 | out_free: |
2381 | pr_warn_ratelimited("Link unable to reassemble fragmented message\n"); | |
2382 | kfree_skb(*fbuf); | |
2383 | return LINK_REASM_ERROR; | |
b97bf3fd PL |
2384 | } |
2385 | ||
a18c4bc3 | 2386 | static void link_set_supervision_props(struct tipc_link *l_ptr, u32 tolerance) |
b97bf3fd | 2387 | { |
5413b4c6 AS |
2388 | if ((tolerance < TIPC_MIN_LINK_TOL) || (tolerance > TIPC_MAX_LINK_TOL)) |
2389 | return; | |
2390 | ||
b97bf3fd PL |
2391 | l_ptr->tolerance = tolerance; |
2392 | l_ptr->continuity_interval = | |
2393 | ((tolerance / 4) > 500) ? 500 : tolerance / 4; | |
2394 | l_ptr->abort_limit = tolerance / (l_ptr->continuity_interval / 4); | |
2395 | } | |
2396 | ||
a18c4bc3 | 2397 | void tipc_link_set_queue_limits(struct tipc_link *l_ptr, u32 window) |
b97bf3fd PL |
2398 | { |
2399 | /* Data messages from this node, inclusive FIRST_FRAGM */ | |
06d82c91 AS |
2400 | l_ptr->queue_limit[TIPC_LOW_IMPORTANCE] = window; |
2401 | l_ptr->queue_limit[TIPC_MEDIUM_IMPORTANCE] = (window / 3) * 4; | |
2402 | l_ptr->queue_limit[TIPC_HIGH_IMPORTANCE] = (window / 3) * 5; | |
2403 | l_ptr->queue_limit[TIPC_CRITICAL_IMPORTANCE] = (window / 3) * 6; | |
b97bf3fd | 2404 | /* Transiting data messages,inclusive FIRST_FRAGM */ |
06d82c91 AS |
2405 | l_ptr->queue_limit[TIPC_LOW_IMPORTANCE + 4] = 300; |
2406 | l_ptr->queue_limit[TIPC_MEDIUM_IMPORTANCE + 4] = 600; | |
2407 | l_ptr->queue_limit[TIPC_HIGH_IMPORTANCE + 4] = 900; | |
2408 | l_ptr->queue_limit[TIPC_CRITICAL_IMPORTANCE + 4] = 1200; | |
b97bf3fd | 2409 | l_ptr->queue_limit[CONN_MANAGER] = 1200; |
b97bf3fd PL |
2410 | l_ptr->queue_limit[CHANGEOVER_PROTOCOL] = 2500; |
2411 | l_ptr->queue_limit[NAME_DISTRIBUTOR] = 3000; | |
2412 | /* FRAGMENT and LAST_FRAGMENT packets */ | |
2413 | l_ptr->queue_limit[MSG_FRAGMENTER] = 4000; | |
2414 | } | |
2415 | ||
2416 | /** | |
2417 | * link_find_link - locate link by name | |
2c53040f BH |
2418 | * @name: ptr to link name string |
2419 | * @node: ptr to area to be filled with ptr to associated node | |
c4307285 | 2420 | * |
4323add6 | 2421 | * Caller must hold 'tipc_net_lock' to ensure node and bearer are not deleted; |
b97bf3fd | 2422 | * this also prevents link deletion. |
c4307285 | 2423 | * |
b97bf3fd PL |
2424 | * Returns pointer to link (or 0 if invalid link name). |
2425 | */ | |
a18c4bc3 PG |
2426 | static struct tipc_link *link_find_link(const char *name, |
2427 | struct tipc_node **node) | |
b97bf3fd | 2428 | { |
a18c4bc3 | 2429 | struct tipc_link *l_ptr; |
bbfbe47c EH |
2430 | struct tipc_node *n_ptr; |
2431 | int i; | |
b97bf3fd | 2432 | |
bbfbe47c EH |
2433 | list_for_each_entry(n_ptr, &tipc_node_list, list) { |
2434 | for (i = 0; i < MAX_BEARERS; i++) { | |
2435 | l_ptr = n_ptr->links[i]; | |
2436 | if (l_ptr && !strcmp(l_ptr->name, name)) | |
2437 | goto found; | |
2438 | } | |
2439 | } | |
2440 | l_ptr = NULL; | |
2441 | n_ptr = NULL; | |
2442 | found: | |
2443 | *node = n_ptr; | |
b97bf3fd PL |
2444 | return l_ptr; |
2445 | } | |
2446 | ||
5c216e1d AS |
2447 | /** |
2448 | * link_value_is_valid -- validate proposed link tolerance/priority/window | |
2449 | * | |
2c53040f BH |
2450 | * @cmd: value type (TIPC_CMD_SET_LINK_*) |
2451 | * @new_value: the new value | |
5c216e1d AS |
2452 | * |
2453 | * Returns 1 if value is within range, 0 if not. | |
2454 | */ | |
5c216e1d AS |
2455 | static int link_value_is_valid(u16 cmd, u32 new_value) |
2456 | { | |
2457 | switch (cmd) { | |
2458 | case TIPC_CMD_SET_LINK_TOL: | |
2459 | return (new_value >= TIPC_MIN_LINK_TOL) && | |
2460 | (new_value <= TIPC_MAX_LINK_TOL); | |
2461 | case TIPC_CMD_SET_LINK_PRI: | |
2462 | return (new_value <= TIPC_MAX_LINK_PRI); | |
2463 | case TIPC_CMD_SET_LINK_WINDOW: | |
2464 | return (new_value >= TIPC_MIN_LINK_WIN) && | |
2465 | (new_value <= TIPC_MAX_LINK_WIN); | |
2466 | } | |
2467 | return 0; | |
2468 | } | |
2469 | ||
5c216e1d AS |
2470 | /** |
2471 | * link_cmd_set_value - change priority/tolerance/window for link/bearer/media | |
2c53040f BH |
2472 | * @name: ptr to link, bearer, or media name |
2473 | * @new_value: new value of link, bearer, or media setting | |
2474 | * @cmd: which link, bearer, or media attribute to set (TIPC_CMD_SET_LINK_*) | |
5c216e1d AS |
2475 | * |
2476 | * Caller must hold 'tipc_net_lock' to ensure link/bearer/media is not deleted. | |
2477 | * | |
2478 | * Returns 0 if value updated and negative value on error. | |
2479 | */ | |
5c216e1d AS |
2480 | static int link_cmd_set_value(const char *name, u32 new_value, u16 cmd) |
2481 | { | |
2482 | struct tipc_node *node; | |
a18c4bc3 | 2483 | struct tipc_link *l_ptr; |
5c216e1d | 2484 | struct tipc_bearer *b_ptr; |
358a0d1c | 2485 | struct tipc_media *m_ptr; |
636c0371 | 2486 | int res = 0; |
5c216e1d AS |
2487 | |
2488 | l_ptr = link_find_link(name, &node); | |
2489 | if (l_ptr) { | |
2490 | /* | |
2491 | * acquire node lock for tipc_link_send_proto_msg(). | |
2492 | * see "TIPC locking policy" in net.c. | |
2493 | */ | |
2494 | tipc_node_lock(node); | |
2495 | switch (cmd) { | |
2496 | case TIPC_CMD_SET_LINK_TOL: | |
2497 | link_set_supervision_props(l_ptr, new_value); | |
2498 | tipc_link_send_proto_msg(l_ptr, | |
2499 | STATE_MSG, 0, 0, new_value, 0, 0); | |
2500 | break; | |
2501 | case TIPC_CMD_SET_LINK_PRI: | |
2502 | l_ptr->priority = new_value; | |
2503 | tipc_link_send_proto_msg(l_ptr, | |
2504 | STATE_MSG, 0, 0, 0, new_value, 0); | |
2505 | break; | |
2506 | case TIPC_CMD_SET_LINK_WINDOW: | |
2507 | tipc_link_set_queue_limits(l_ptr, new_value); | |
2508 | break; | |
636c0371 YX |
2509 | default: |
2510 | res = -EINVAL; | |
2511 | break; | |
5c216e1d AS |
2512 | } |
2513 | tipc_node_unlock(node); | |
636c0371 | 2514 | return res; |
5c216e1d AS |
2515 | } |
2516 | ||
2517 | b_ptr = tipc_bearer_find(name); | |
2518 | if (b_ptr) { | |
2519 | switch (cmd) { | |
2520 | case TIPC_CMD_SET_LINK_TOL: | |
2521 | b_ptr->tolerance = new_value; | |
636c0371 | 2522 | break; |
5c216e1d AS |
2523 | case TIPC_CMD_SET_LINK_PRI: |
2524 | b_ptr->priority = new_value; | |
636c0371 | 2525 | break; |
5c216e1d AS |
2526 | case TIPC_CMD_SET_LINK_WINDOW: |
2527 | b_ptr->window = new_value; | |
636c0371 YX |
2528 | break; |
2529 | default: | |
2530 | res = -EINVAL; | |
2531 | break; | |
5c216e1d | 2532 | } |
636c0371 | 2533 | return res; |
5c216e1d AS |
2534 | } |
2535 | ||
2536 | m_ptr = tipc_media_find(name); | |
2537 | if (!m_ptr) | |
2538 | return -ENODEV; | |
2539 | switch (cmd) { | |
2540 | case TIPC_CMD_SET_LINK_TOL: | |
2541 | m_ptr->tolerance = new_value; | |
636c0371 | 2542 | break; |
5c216e1d AS |
2543 | case TIPC_CMD_SET_LINK_PRI: |
2544 | m_ptr->priority = new_value; | |
636c0371 | 2545 | break; |
5c216e1d AS |
2546 | case TIPC_CMD_SET_LINK_WINDOW: |
2547 | m_ptr->window = new_value; | |
636c0371 YX |
2548 | break; |
2549 | default: | |
2550 | res = -EINVAL; | |
2551 | break; | |
5c216e1d | 2552 | } |
636c0371 | 2553 | return res; |
5c216e1d AS |
2554 | } |
2555 | ||
c4307285 | 2556 | struct sk_buff *tipc_link_cmd_config(const void *req_tlv_area, int req_tlv_space, |
4323add6 | 2557 | u16 cmd) |
b97bf3fd PL |
2558 | { |
2559 | struct tipc_link_config *args; | |
c4307285 | 2560 | u32 new_value; |
c4307285 | 2561 | int res; |
b97bf3fd PL |
2562 | |
2563 | if (!TLV_CHECK(req_tlv_area, req_tlv_space, TIPC_TLV_LINK_CONFIG)) | |
4323add6 | 2564 | return tipc_cfg_reply_error_string(TIPC_CFG_TLV_ERROR); |
b97bf3fd PL |
2565 | |
2566 | args = (struct tipc_link_config *)TLV_DATA(req_tlv_area); | |
2567 | new_value = ntohl(args->value); | |
2568 | ||
5c216e1d AS |
2569 | if (!link_value_is_valid(cmd, new_value)) |
2570 | return tipc_cfg_reply_error_string( | |
2571 | "cannot change, value invalid"); | |
2572 | ||
4323add6 | 2573 | if (!strcmp(args->name, tipc_bclink_name)) { |
b97bf3fd | 2574 | if ((cmd == TIPC_CMD_SET_LINK_WINDOW) && |
4323add6 PL |
2575 | (tipc_bclink_set_queue_limits(new_value) == 0)) |
2576 | return tipc_cfg_reply_none(); | |
c4307285 | 2577 | return tipc_cfg_reply_error_string(TIPC_CFG_NOT_SUPPORTED |
4323add6 | 2578 | " (cannot change setting on broadcast link)"); |
b97bf3fd PL |
2579 | } |
2580 | ||
4323add6 | 2581 | read_lock_bh(&tipc_net_lock); |
5c216e1d | 2582 | res = link_cmd_set_value(args->name, new_value, cmd); |
4323add6 | 2583 | read_unlock_bh(&tipc_net_lock); |
b97bf3fd | 2584 | if (res) |
c4307285 | 2585 | return tipc_cfg_reply_error_string("cannot change link setting"); |
b97bf3fd | 2586 | |
4323add6 | 2587 | return tipc_cfg_reply_none(); |
b97bf3fd PL |
2588 | } |
2589 | ||
2590 | /** | |
2591 | * link_reset_statistics - reset link statistics | |
2592 | * @l_ptr: pointer to link | |
2593 | */ | |
a18c4bc3 | 2594 | static void link_reset_statistics(struct tipc_link *l_ptr) |
b97bf3fd PL |
2595 | { |
2596 | memset(&l_ptr->stats, 0, sizeof(l_ptr->stats)); | |
2597 | l_ptr->stats.sent_info = l_ptr->next_out_no; | |
2598 | l_ptr->stats.recv_info = l_ptr->next_in_no; | |
2599 | } | |
2600 | ||
4323add6 | 2601 | struct sk_buff *tipc_link_cmd_reset_stats(const void *req_tlv_area, int req_tlv_space) |
b97bf3fd PL |
2602 | { |
2603 | char *link_name; | |
a18c4bc3 | 2604 | struct tipc_link *l_ptr; |
6c00055a | 2605 | struct tipc_node *node; |
b97bf3fd PL |
2606 | |
2607 | if (!TLV_CHECK(req_tlv_area, req_tlv_space, TIPC_TLV_LINK_NAME)) | |
4323add6 | 2608 | return tipc_cfg_reply_error_string(TIPC_CFG_TLV_ERROR); |
b97bf3fd PL |
2609 | |
2610 | link_name = (char *)TLV_DATA(req_tlv_area); | |
4323add6 PL |
2611 | if (!strcmp(link_name, tipc_bclink_name)) { |
2612 | if (tipc_bclink_reset_stats()) | |
2613 | return tipc_cfg_reply_error_string("link not found"); | |
2614 | return tipc_cfg_reply_none(); | |
b97bf3fd PL |
2615 | } |
2616 | ||
4323add6 | 2617 | read_lock_bh(&tipc_net_lock); |
c4307285 | 2618 | l_ptr = link_find_link(link_name, &node); |
b97bf3fd | 2619 | if (!l_ptr) { |
4323add6 PL |
2620 | read_unlock_bh(&tipc_net_lock); |
2621 | return tipc_cfg_reply_error_string("link not found"); | |
b97bf3fd PL |
2622 | } |
2623 | ||
4323add6 | 2624 | tipc_node_lock(node); |
b97bf3fd | 2625 | link_reset_statistics(l_ptr); |
4323add6 PL |
2626 | tipc_node_unlock(node); |
2627 | read_unlock_bh(&tipc_net_lock); | |
2628 | return tipc_cfg_reply_none(); | |
b97bf3fd PL |
2629 | } |
2630 | ||
2631 | /** | |
2632 | * percent - convert count to a percentage of total (rounding up or down) | |
2633 | */ | |
b97bf3fd PL |
2634 | static u32 percent(u32 count, u32 total) |
2635 | { | |
2636 | return (count * 100 + (total / 2)) / total; | |
2637 | } | |
2638 | ||
2639 | /** | |
4323add6 | 2640 | * tipc_link_stats - print link statistics |
b97bf3fd PL |
2641 | * @name: link name |
2642 | * @buf: print buffer area | |
2643 | * @buf_size: size of print buffer area | |
c4307285 | 2644 | * |
b97bf3fd PL |
2645 | * Returns length of print buffer data string (or 0 if error) |
2646 | */ | |
4323add6 | 2647 | static int tipc_link_stats(const char *name, char *buf, const u32 buf_size) |
b97bf3fd | 2648 | { |
dc1aed37 EH |
2649 | struct tipc_link *l; |
2650 | struct tipc_stats *s; | |
6c00055a | 2651 | struct tipc_node *node; |
b97bf3fd PL |
2652 | char *status; |
2653 | u32 profile_total = 0; | |
dc1aed37 | 2654 | int ret; |
b97bf3fd | 2655 | |
4323add6 PL |
2656 | if (!strcmp(name, tipc_bclink_name)) |
2657 | return tipc_bclink_stats(buf, buf_size); | |
b97bf3fd | 2658 | |
4323add6 | 2659 | read_lock_bh(&tipc_net_lock); |
dc1aed37 EH |
2660 | l = link_find_link(name, &node); |
2661 | if (!l) { | |
4323add6 | 2662 | read_unlock_bh(&tipc_net_lock); |
b97bf3fd PL |
2663 | return 0; |
2664 | } | |
4323add6 | 2665 | tipc_node_lock(node); |
dc1aed37 | 2666 | s = &l->stats; |
b97bf3fd | 2667 | |
dc1aed37 | 2668 | if (tipc_link_is_active(l)) |
b97bf3fd | 2669 | status = "ACTIVE"; |
dc1aed37 | 2670 | else if (tipc_link_is_up(l)) |
b97bf3fd PL |
2671 | status = "STANDBY"; |
2672 | else | |
2673 | status = "DEFUNCT"; | |
dc1aed37 EH |
2674 | |
2675 | ret = tipc_snprintf(buf, buf_size, "Link <%s>\n" | |
2676 | " %s MTU:%u Priority:%u Tolerance:%u ms" | |
2677 | " Window:%u packets\n", | |
2678 | l->name, status, l->max_pkt, l->priority, | |
2679 | l->tolerance, l->queue_limit[0]); | |
2680 | ||
2681 | ret += tipc_snprintf(buf + ret, buf_size - ret, | |
2682 | " RX packets:%u fragments:%u/%u bundles:%u/%u\n", | |
2683 | l->next_in_no - s->recv_info, s->recv_fragments, | |
2684 | s->recv_fragmented, s->recv_bundles, | |
2685 | s->recv_bundled); | |
2686 | ||
2687 | ret += tipc_snprintf(buf + ret, buf_size - ret, | |
2688 | " TX packets:%u fragments:%u/%u bundles:%u/%u\n", | |
2689 | l->next_out_no - s->sent_info, s->sent_fragments, | |
2690 | s->sent_fragmented, s->sent_bundles, | |
2691 | s->sent_bundled); | |
2692 | ||
2693 | profile_total = s->msg_length_counts; | |
b97bf3fd PL |
2694 | if (!profile_total) |
2695 | profile_total = 1; | |
dc1aed37 EH |
2696 | |
2697 | ret += tipc_snprintf(buf + ret, buf_size - ret, | |
2698 | " TX profile sample:%u packets average:%u octets\n" | |
2699 | " 0-64:%u%% -256:%u%% -1024:%u%% -4096:%u%% " | |
2700 | "-16384:%u%% -32768:%u%% -66000:%u%%\n", | |
2701 | s->msg_length_counts, | |
2702 | s->msg_lengths_total / profile_total, | |
2703 | percent(s->msg_length_profile[0], profile_total), | |
2704 | percent(s->msg_length_profile[1], profile_total), | |
2705 | percent(s->msg_length_profile[2], profile_total), | |
2706 | percent(s->msg_length_profile[3], profile_total), | |
2707 | percent(s->msg_length_profile[4], profile_total), | |
2708 | percent(s->msg_length_profile[5], profile_total), | |
2709 | percent(s->msg_length_profile[6], profile_total)); | |
2710 | ||
2711 | ret += tipc_snprintf(buf + ret, buf_size - ret, | |
2712 | " RX states:%u probes:%u naks:%u defs:%u" | |
2713 | " dups:%u\n", s->recv_states, s->recv_probes, | |
2714 | s->recv_nacks, s->deferred_recv, s->duplicates); | |
2715 | ||
2716 | ret += tipc_snprintf(buf + ret, buf_size - ret, | |
2717 | " TX states:%u probes:%u naks:%u acks:%u" | |
2718 | " dups:%u\n", s->sent_states, s->sent_probes, | |
2719 | s->sent_nacks, s->sent_acks, s->retransmitted); | |
2720 | ||
2721 | ret += tipc_snprintf(buf + ret, buf_size - ret, | |
3c294cb3 YX |
2722 | " Congestion link:%u Send queue" |
2723 | " max:%u avg:%u\n", s->link_congs, | |
dc1aed37 EH |
2724 | s->max_queue_sz, s->queue_sz_counts ? |
2725 | (s->accu_queue_sz / s->queue_sz_counts) : 0); | |
b97bf3fd | 2726 | |
4323add6 PL |
2727 | tipc_node_unlock(node); |
2728 | read_unlock_bh(&tipc_net_lock); | |
dc1aed37 | 2729 | return ret; |
b97bf3fd PL |
2730 | } |
2731 | ||
4323add6 | 2732 | struct sk_buff *tipc_link_cmd_show_stats(const void *req_tlv_area, int req_tlv_space) |
b97bf3fd PL |
2733 | { |
2734 | struct sk_buff *buf; | |
2735 | struct tlv_desc *rep_tlv; | |
2736 | int str_len; | |
dc1aed37 EH |
2737 | int pb_len; |
2738 | char *pb; | |
b97bf3fd PL |
2739 | |
2740 | if (!TLV_CHECK(req_tlv_area, req_tlv_space, TIPC_TLV_LINK_NAME)) | |
4323add6 | 2741 | return tipc_cfg_reply_error_string(TIPC_CFG_TLV_ERROR); |
b97bf3fd | 2742 | |
dc1aed37 | 2743 | buf = tipc_cfg_reply_alloc(TLV_SPACE(ULTRA_STRING_MAX_LEN)); |
b97bf3fd PL |
2744 | if (!buf) |
2745 | return NULL; | |
2746 | ||
2747 | rep_tlv = (struct tlv_desc *)buf->data; | |
dc1aed37 EH |
2748 | pb = TLV_DATA(rep_tlv); |
2749 | pb_len = ULTRA_STRING_MAX_LEN; | |
4323add6 | 2750 | str_len = tipc_link_stats((char *)TLV_DATA(req_tlv_area), |
dc1aed37 | 2751 | pb, pb_len); |
b97bf3fd | 2752 | if (!str_len) { |
5f6d9123 | 2753 | kfree_skb(buf); |
c4307285 | 2754 | return tipc_cfg_reply_error_string("link not found"); |
b97bf3fd | 2755 | } |
dc1aed37 | 2756 | str_len += 1; /* for "\0" */ |
b97bf3fd PL |
2757 | skb_put(buf, TLV_SPACE(str_len)); |
2758 | TLV_SET(rep_tlv, TIPC_TLV_ULTRA_STRING, NULL, str_len); | |
2759 | ||
2760 | return buf; | |
2761 | } | |
2762 | ||
b97bf3fd | 2763 | /** |
4323add6 | 2764 | * tipc_link_get_max_pkt - get maximum packet size to use when sending to destination |
b97bf3fd PL |
2765 | * @dest: network address of destination node |
2766 | * @selector: used to select from set of active links | |
c4307285 | 2767 | * |
b97bf3fd PL |
2768 | * If no active link can be found, uses default maximum packet size. |
2769 | */ | |
4323add6 | 2770 | u32 tipc_link_get_max_pkt(u32 dest, u32 selector) |
b97bf3fd | 2771 | { |
6c00055a | 2772 | struct tipc_node *n_ptr; |
a18c4bc3 | 2773 | struct tipc_link *l_ptr; |
b97bf3fd | 2774 | u32 res = MAX_PKT_DEFAULT; |
c4307285 | 2775 | |
b97bf3fd PL |
2776 | if (dest == tipc_own_addr) |
2777 | return MAX_MSG_SIZE; | |
2778 | ||
c4307285 | 2779 | read_lock_bh(&tipc_net_lock); |
51a8e4de | 2780 | n_ptr = tipc_node_find(dest); |
b97bf3fd | 2781 | if (n_ptr) { |
4323add6 | 2782 | tipc_node_lock(n_ptr); |
b97bf3fd PL |
2783 | l_ptr = n_ptr->active_links[selector & 1]; |
2784 | if (l_ptr) | |
15e979da | 2785 | res = l_ptr->max_pkt; |
4323add6 | 2786 | tipc_node_unlock(n_ptr); |
b97bf3fd | 2787 | } |
c4307285 | 2788 | read_unlock_bh(&tipc_net_lock); |
b97bf3fd PL |
2789 | return res; |
2790 | } | |
2791 | ||
a18c4bc3 | 2792 | static void link_print(struct tipc_link *l_ptr, const char *str) |
b97bf3fd | 2793 | { |
5deedde9 | 2794 | pr_info("%s Link %x<%s>:", str, l_ptr->addr, l_ptr->b_ptr->name); |
8d64a5ba | 2795 | |
b97bf3fd | 2796 | if (link_working_unknown(l_ptr)) |
5deedde9 | 2797 | pr_cont(":WU\n"); |
8d64a5ba | 2798 | else if (link_reset_reset(l_ptr)) |
5deedde9 | 2799 | pr_cont(":RR\n"); |
8d64a5ba | 2800 | else if (link_reset_unknown(l_ptr)) |
5deedde9 | 2801 | pr_cont(":RU\n"); |
8d64a5ba | 2802 | else if (link_working_working(l_ptr)) |
5deedde9 PG |
2803 | pr_cont(":WW\n"); |
2804 | else | |
2805 | pr_cont("\n"); | |
b97bf3fd | 2806 | } |