Commit 5392d646886d8f1ae01be69c10600b8df5284c41

Authored by Allan Stephens
Committed by David S. Miller
1 parent a10bd924a4

[TIPC]: Fixed link switchover bugs

Incorporates several related fixes:
- switchover now occurs when switching from an active link to a standby link
- failure of a standby link no longer initiates switchover
- links now display correct # of received packtes following reactivation

Signed-off-by: Allan Stephens <allan.stephens@windriver.com>
Signed-off-by: Per Liden <per.liden@ericsson.com>
Signed-off-by: David S. Miller <davem@davemloft.net>

Showing 3 changed files with 31 additions and 8 deletions Inline Diff

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