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