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