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