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