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