]>
Commit | Line | Data |
---|---|---|
b97bf3fd PL |
1 | /* |
2 | * net/tipc/port.c: TIPC port code | |
c4307285 | 3 | * |
05646c91 AS |
4 | * Copyright (c) 1992-2007, Ericsson AB |
5 | * Copyright (c) 2004-2007, Wind River Systems | |
b97bf3fd PL |
6 | * All rights reserved. |
7 | * | |
9ea1fd3c | 8 | * Redistribution and use in source and binary forms, with or without |
b97bf3fd PL |
9 | * modification, are permitted provided that the following conditions are met: |
10 | * | |
9ea1fd3c PL |
11 | * 1. Redistributions of source code must retain the above copyright |
12 | * notice, this list of conditions and the following disclaimer. | |
13 | * 2. Redistributions in binary form must reproduce the above copyright | |
14 | * notice, this list of conditions and the following disclaimer in the | |
15 | * documentation and/or other materials provided with the distribution. | |
16 | * 3. Neither the names of the copyright holders nor the names of its | |
17 | * contributors may be used to endorse or promote products derived from | |
18 | * this software without specific prior written permission. | |
b97bf3fd | 19 | * |
9ea1fd3c PL |
20 | * Alternatively, this software may be distributed under the terms of the |
21 | * GNU General Public License ("GPL") version 2 as published by the Free | |
22 | * Software Foundation. | |
23 | * | |
24 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" | |
25 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | |
26 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | |
27 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE | |
28 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR | |
29 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF | |
30 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS | |
31 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN | |
32 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | |
33 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | |
b97bf3fd PL |
34 | * POSSIBILITY OF SUCH DAMAGE. |
35 | */ | |
36 | ||
37 | #include "core.h" | |
38 | #include "config.h" | |
39 | #include "dbg.h" | |
40 | #include "port.h" | |
41 | #include "addr.h" | |
42 | #include "link.h" | |
43 | #include "node.h" | |
b97bf3fd PL |
44 | #include "name_table.h" |
45 | #include "user_reg.h" | |
46 | #include "msg.h" | |
47 | #include "bcast.h" | |
48 | ||
49 | /* Connection management: */ | |
50 | #define PROBING_INTERVAL 3600000 /* [ms] => 1 h */ | |
51 | #define CONFIRMED 0 | |
52 | #define PROBING 1 | |
53 | ||
54 | #define MAX_REJECT_SIZE 1024 | |
55 | ||
1fc54d8f SR |
56 | static struct sk_buff *msg_queue_head = NULL; |
57 | static struct sk_buff *msg_queue_tail = NULL; | |
b97bf3fd | 58 | |
34af946a IM |
59 | DEFINE_SPINLOCK(tipc_port_list_lock); |
60 | static DEFINE_SPINLOCK(queue_lock); | |
b97bf3fd | 61 | |
4323add6 | 62 | static LIST_HEAD(ports); |
b97bf3fd PL |
63 | static void port_handle_node_down(unsigned long ref); |
64 | static struct sk_buff* port_build_self_abort_msg(struct port *,u32 err); | |
65 | static struct sk_buff* port_build_peer_abort_msg(struct port *,u32 err); | |
66 | static void port_timeout(unsigned long ref); | |
67 | ||
68 | ||
05790c64 | 69 | static u32 port_peernode(struct port *p_ptr) |
b97bf3fd PL |
70 | { |
71 | return msg_destnode(&p_ptr->publ.phdr); | |
72 | } | |
73 | ||
05790c64 | 74 | static u32 port_peerport(struct port *p_ptr) |
b97bf3fd PL |
75 | { |
76 | return msg_destport(&p_ptr->publ.phdr); | |
77 | } | |
78 | ||
05790c64 | 79 | static u32 port_out_seqno(struct port *p_ptr) |
b97bf3fd PL |
80 | { |
81 | return msg_transp_seqno(&p_ptr->publ.phdr); | |
82 | } | |
83 | ||
05790c64 | 84 | static void port_incr_out_seqno(struct port *p_ptr) |
b97bf3fd PL |
85 | { |
86 | struct tipc_msg *m = &p_ptr->publ.phdr; | |
87 | ||
88 | if (likely(!msg_routed(m))) | |
89 | return; | |
90 | msg_set_transp_seqno(m, (msg_transp_seqno(m) + 1)); | |
91 | } | |
92 | ||
93 | /** | |
94 | * tipc_multicast - send a multicast message to local and remote destinations | |
95 | */ | |
96 | ||
97 | int tipc_multicast(u32 ref, struct tipc_name_seq const *seq, u32 domain, | |
98 | u32 num_sect, struct iovec const *msg_sect) | |
99 | { | |
100 | struct tipc_msg *hdr; | |
101 | struct sk_buff *buf; | |
102 | struct sk_buff *ibuf = NULL; | |
103 | struct port_list dports = {0, NULL, }; | |
4323add6 | 104 | struct port *oport = tipc_port_deref(ref); |
b97bf3fd PL |
105 | int ext_targets; |
106 | int res; | |
107 | ||
108 | if (unlikely(!oport)) | |
109 | return -EINVAL; | |
110 | ||
111 | /* Create multicast message */ | |
112 | ||
113 | hdr = &oport->publ.phdr; | |
114 | msg_set_type(hdr, TIPC_MCAST_MSG); | |
115 | msg_set_nametype(hdr, seq->type); | |
116 | msg_set_namelower(hdr, seq->lower); | |
117 | msg_set_nameupper(hdr, seq->upper); | |
118 | msg_set_hdr_sz(hdr, MCAST_H_SIZE); | |
119 | res = msg_build(hdr, msg_sect, num_sect, MAX_MSG_SIZE, | |
120 | !oport->user_port, &buf); | |
121 | if (unlikely(!buf)) | |
122 | return res; | |
123 | ||
124 | /* Figure out where to send multicast message */ | |
125 | ||
4323add6 PL |
126 | ext_targets = tipc_nametbl_mc_translate(seq->type, seq->lower, seq->upper, |
127 | TIPC_NODE_SCOPE, &dports); | |
c4307285 YH |
128 | |
129 | /* Send message to destinations (duplicate it only if necessary) */ | |
b97bf3fd PL |
130 | |
131 | if (ext_targets) { | |
132 | if (dports.count != 0) { | |
133 | ibuf = skb_copy(buf, GFP_ATOMIC); | |
134 | if (ibuf == NULL) { | |
4323add6 | 135 | tipc_port_list_free(&dports); |
b97bf3fd PL |
136 | buf_discard(buf); |
137 | return -ENOMEM; | |
138 | } | |
139 | } | |
4323add6 | 140 | res = tipc_bclink_send_msg(buf); |
b97bf3fd PL |
141 | if ((res < 0) && (dports.count != 0)) { |
142 | buf_discard(ibuf); | |
143 | } | |
144 | } else { | |
145 | ibuf = buf; | |
146 | } | |
147 | ||
148 | if (res >= 0) { | |
149 | if (ibuf) | |
4323add6 | 150 | tipc_port_recv_mcast(ibuf, &dports); |
b97bf3fd | 151 | } else { |
4323add6 | 152 | tipc_port_list_free(&dports); |
b97bf3fd PL |
153 | } |
154 | return res; | |
155 | } | |
156 | ||
157 | /** | |
4323add6 | 158 | * tipc_port_recv_mcast - deliver multicast message to all destination ports |
c4307285 | 159 | * |
b97bf3fd PL |
160 | * If there is no port list, perform a lookup to create one |
161 | */ | |
162 | ||
4323add6 | 163 | void tipc_port_recv_mcast(struct sk_buff *buf, struct port_list *dp) |
b97bf3fd PL |
164 | { |
165 | struct tipc_msg* msg; | |
166 | struct port_list dports = {0, NULL, }; | |
167 | struct port_list *item = dp; | |
168 | int cnt = 0; | |
169 | ||
b97bf3fd PL |
170 | msg = buf_msg(buf); |
171 | ||
172 | /* Create destination port list, if one wasn't supplied */ | |
173 | ||
174 | if (dp == NULL) { | |
4323add6 | 175 | tipc_nametbl_mc_translate(msg_nametype(msg), |
b97bf3fd PL |
176 | msg_namelower(msg), |
177 | msg_nameupper(msg), | |
178 | TIPC_CLUSTER_SCOPE, | |
179 | &dports); | |
180 | item = dp = &dports; | |
181 | } | |
182 | ||
183 | /* Deliver a copy of message to each destination port */ | |
184 | ||
185 | if (dp->count != 0) { | |
186 | if (dp->count == 1) { | |
187 | msg_set_destport(msg, dp->ports[0]); | |
4323add6 PL |
188 | tipc_port_recv_msg(buf); |
189 | tipc_port_list_free(dp); | |
b97bf3fd PL |
190 | return; |
191 | } | |
192 | for (; cnt < dp->count; cnt++) { | |
193 | int index = cnt % PLSIZE; | |
194 | struct sk_buff *b = skb_clone(buf, GFP_ATOMIC); | |
195 | ||
196 | if (b == NULL) { | |
a10bd924 | 197 | warn("Unable to deliver multicast message(s)\n"); |
b97bf3fd PL |
198 | msg_dbg(msg, "LOST:"); |
199 | goto exit; | |
200 | } | |
201 | if ((index == 0) && (cnt != 0)) { | |
202 | item = item->next; | |
203 | } | |
204 | msg_set_destport(buf_msg(b),item->ports[index]); | |
4323add6 | 205 | tipc_port_recv_msg(b); |
b97bf3fd PL |
206 | } |
207 | } | |
208 | exit: | |
209 | buf_discard(buf); | |
4323add6 | 210 | tipc_port_list_free(dp); |
b97bf3fd PL |
211 | } |
212 | ||
213 | /** | |
214 | * tipc_createport_raw - create a native TIPC port | |
c4307285 | 215 | * |
b97bf3fd PL |
216 | * Returns local port reference |
217 | */ | |
218 | ||
219 | u32 tipc_createport_raw(void *usr_handle, | |
220 | u32 (*dispatcher)(struct tipc_port *, struct sk_buff *), | |
221 | void (*wakeup)(struct tipc_port *), | |
222 | const u32 importance) | |
223 | { | |
224 | struct port *p_ptr; | |
225 | struct tipc_msg *msg; | |
226 | u32 ref; | |
227 | ||
0da974f4 | 228 | p_ptr = kzalloc(sizeof(*p_ptr), GFP_ATOMIC); |
a10bd924 AS |
229 | if (!p_ptr) { |
230 | warn("Port creation failed, no memory\n"); | |
b97bf3fd PL |
231 | return 0; |
232 | } | |
4323add6 | 233 | ref = tipc_ref_acquire(p_ptr, &p_ptr->publ.lock); |
b97bf3fd | 234 | if (!ref) { |
a10bd924 | 235 | warn("Port creation failed, reference table exhausted\n"); |
b97bf3fd PL |
236 | kfree(p_ptr); |
237 | return 0; | |
238 | } | |
239 | ||
4323add6 | 240 | tipc_port_lock(ref); |
05646c91 AS |
241 | p_ptr->publ.usr_handle = usr_handle; |
242 | p_ptr->publ.max_pkt = MAX_PKT_DEFAULT; | |
b97bf3fd PL |
243 | p_ptr->publ.ref = ref; |
244 | msg = &p_ptr->publ.phdr; | |
06d82c91 AS |
245 | msg_init(msg, TIPC_LOW_IMPORTANCE, TIPC_NAMED_MSG, TIPC_OK, LONG_H_SIZE, |
246 | 0); | |
b97bf3fd PL |
247 | msg_set_orignode(msg, tipc_own_addr); |
248 | msg_set_prevnode(msg, tipc_own_addr); | |
249 | msg_set_origport(msg, ref); | |
250 | msg_set_importance(msg,importance); | |
251 | p_ptr->last_in_seqno = 41; | |
252 | p_ptr->sent = 1; | |
b97bf3fd PL |
253 | INIT_LIST_HEAD(&p_ptr->wait_list); |
254 | INIT_LIST_HEAD(&p_ptr->subscription.nodesub_list); | |
1fc54d8f | 255 | p_ptr->congested_link = NULL; |
b97bf3fd PL |
256 | p_ptr->dispatcher = dispatcher; |
257 | p_ptr->wakeup = wakeup; | |
1fc54d8f | 258 | p_ptr->user_port = NULL; |
b97bf3fd | 259 | k_init_timer(&p_ptr->timer, (Handler)port_timeout, ref); |
4323add6 | 260 | spin_lock_bh(&tipc_port_list_lock); |
b97bf3fd PL |
261 | INIT_LIST_HEAD(&p_ptr->publications); |
262 | INIT_LIST_HEAD(&p_ptr->port_list); | |
263 | list_add_tail(&p_ptr->port_list, &ports); | |
4323add6 PL |
264 | spin_unlock_bh(&tipc_port_list_lock); |
265 | tipc_port_unlock(p_ptr); | |
b97bf3fd PL |
266 | return ref; |
267 | } | |
268 | ||
269 | int tipc_deleteport(u32 ref) | |
270 | { | |
271 | struct port *p_ptr; | |
1fc54d8f | 272 | struct sk_buff *buf = NULL; |
b97bf3fd | 273 | |
1fc54d8f | 274 | tipc_withdraw(ref, 0, NULL); |
4323add6 | 275 | p_ptr = tipc_port_lock(ref); |
c4307285 | 276 | if (!p_ptr) |
b97bf3fd PL |
277 | return -EINVAL; |
278 | ||
4323add6 PL |
279 | tipc_ref_discard(ref); |
280 | tipc_port_unlock(p_ptr); | |
b97bf3fd PL |
281 | |
282 | k_cancel_timer(&p_ptr->timer); | |
283 | if (p_ptr->publ.connected) { | |
284 | buf = port_build_peer_abort_msg(p_ptr, TIPC_ERR_NO_PORT); | |
4323add6 | 285 | tipc_nodesub_unsubscribe(&p_ptr->subscription); |
b97bf3fd PL |
286 | } |
287 | if (p_ptr->user_port) { | |
4323add6 | 288 | tipc_reg_remove_port(p_ptr->user_port); |
b97bf3fd PL |
289 | kfree(p_ptr->user_port); |
290 | } | |
291 | ||
4323add6 | 292 | spin_lock_bh(&tipc_port_list_lock); |
b97bf3fd PL |
293 | list_del(&p_ptr->port_list); |
294 | list_del(&p_ptr->wait_list); | |
4323add6 | 295 | spin_unlock_bh(&tipc_port_list_lock); |
b97bf3fd PL |
296 | k_term_timer(&p_ptr->timer); |
297 | kfree(p_ptr); | |
298 | dbg("Deleted port %u\n", ref); | |
4323add6 | 299 | tipc_net_route_msg(buf); |
b97bf3fd PL |
300 | return TIPC_OK; |
301 | } | |
302 | ||
303 | /** | |
304 | * tipc_get_port() - return port associated with 'ref' | |
c4307285 | 305 | * |
b97bf3fd PL |
306 | * Note: Port is not locked. |
307 | */ | |
308 | ||
309 | struct tipc_port *tipc_get_port(const u32 ref) | |
310 | { | |
4323add6 | 311 | return (struct tipc_port *)tipc_ref_deref(ref); |
b97bf3fd PL |
312 | } |
313 | ||
314 | /** | |
315 | * tipc_get_handle - return user handle associated to port 'ref' | |
316 | */ | |
317 | ||
318 | void *tipc_get_handle(const u32 ref) | |
319 | { | |
320 | struct port *p_ptr; | |
321 | void * handle; | |
322 | ||
4323add6 | 323 | p_ptr = tipc_port_lock(ref); |
b97bf3fd | 324 | if (!p_ptr) |
1fc54d8f | 325 | return NULL; |
b97bf3fd | 326 | handle = p_ptr->publ.usr_handle; |
4323add6 | 327 | tipc_port_unlock(p_ptr); |
b97bf3fd PL |
328 | return handle; |
329 | } | |
330 | ||
05790c64 | 331 | static int port_unreliable(struct port *p_ptr) |
b97bf3fd PL |
332 | { |
333 | return msg_src_droppable(&p_ptr->publ.phdr); | |
334 | } | |
335 | ||
336 | int tipc_portunreliable(u32 ref, unsigned int *isunreliable) | |
337 | { | |
338 | struct port *p_ptr; | |
c4307285 | 339 | |
4323add6 | 340 | p_ptr = tipc_port_lock(ref); |
b97bf3fd PL |
341 | if (!p_ptr) |
342 | return -EINVAL; | |
343 | *isunreliable = port_unreliable(p_ptr); | |
4cec72c8 | 344 | tipc_port_unlock(p_ptr); |
b97bf3fd PL |
345 | return TIPC_OK; |
346 | } | |
347 | ||
348 | int tipc_set_portunreliable(u32 ref, unsigned int isunreliable) | |
349 | { | |
350 | struct port *p_ptr; | |
c4307285 | 351 | |
4323add6 | 352 | p_ptr = tipc_port_lock(ref); |
b97bf3fd PL |
353 | if (!p_ptr) |
354 | return -EINVAL; | |
355 | msg_set_src_droppable(&p_ptr->publ.phdr, (isunreliable != 0)); | |
4323add6 | 356 | tipc_port_unlock(p_ptr); |
b97bf3fd PL |
357 | return TIPC_OK; |
358 | } | |
359 | ||
05790c64 | 360 | static int port_unreturnable(struct port *p_ptr) |
b97bf3fd PL |
361 | { |
362 | return msg_dest_droppable(&p_ptr->publ.phdr); | |
363 | } | |
364 | ||
365 | int tipc_portunreturnable(u32 ref, unsigned int *isunrejectable) | |
366 | { | |
367 | struct port *p_ptr; | |
c4307285 | 368 | |
4323add6 | 369 | p_ptr = tipc_port_lock(ref); |
b97bf3fd PL |
370 | if (!p_ptr) |
371 | return -EINVAL; | |
372 | *isunrejectable = port_unreturnable(p_ptr); | |
4cec72c8 | 373 | tipc_port_unlock(p_ptr); |
b97bf3fd PL |
374 | return TIPC_OK; |
375 | } | |
376 | ||
377 | int tipc_set_portunreturnable(u32 ref, unsigned int isunrejectable) | |
378 | { | |
379 | struct port *p_ptr; | |
c4307285 | 380 | |
4323add6 | 381 | p_ptr = tipc_port_lock(ref); |
b97bf3fd PL |
382 | if (!p_ptr) |
383 | return -EINVAL; | |
384 | msg_set_dest_droppable(&p_ptr->publ.phdr, (isunrejectable != 0)); | |
4323add6 | 385 | tipc_port_unlock(p_ptr); |
b97bf3fd PL |
386 | return TIPC_OK; |
387 | } | |
388 | ||
c4307285 YH |
389 | /* |
390 | * port_build_proto_msg(): build a port level protocol | |
391 | * or a connection abortion message. Called with | |
b97bf3fd PL |
392 | * tipc_port lock on. |
393 | */ | |
394 | static struct sk_buff *port_build_proto_msg(u32 destport, u32 destnode, | |
395 | u32 origport, u32 orignode, | |
c4307285 | 396 | u32 usr, u32 type, u32 err, |
b97bf3fd PL |
397 | u32 seqno, u32 ack) |
398 | { | |
399 | struct sk_buff *buf; | |
400 | struct tipc_msg *msg; | |
c4307285 | 401 | |
b97bf3fd PL |
402 | buf = buf_acquire(LONG_H_SIZE); |
403 | if (buf) { | |
404 | msg = buf_msg(buf); | |
405 | msg_init(msg, usr, type, err, LONG_H_SIZE, destnode); | |
406 | msg_set_destport(msg, destport); | |
407 | msg_set_origport(msg, origport); | |
408 | msg_set_destnode(msg, destnode); | |
409 | msg_set_orignode(msg, orignode); | |
410 | msg_set_transp_seqno(msg, seqno); | |
411 | msg_set_msgcnt(msg, ack); | |
412 | msg_dbg(msg, "PORT>SEND>:"); | |
413 | } | |
414 | return buf; | |
415 | } | |
416 | ||
b97bf3fd PL |
417 | int tipc_reject_msg(struct sk_buff *buf, u32 err) |
418 | { | |
419 | struct tipc_msg *msg = buf_msg(buf); | |
420 | struct sk_buff *rbuf; | |
421 | struct tipc_msg *rmsg; | |
422 | int hdr_sz; | |
423 | u32 imp = msg_importance(msg); | |
424 | u32 data_sz = msg_data_sz(msg); | |
425 | ||
426 | if (data_sz > MAX_REJECT_SIZE) | |
427 | data_sz = MAX_REJECT_SIZE; | |
428 | if (msg_connected(msg) && (imp < TIPC_CRITICAL_IMPORTANCE)) | |
429 | imp++; | |
430 | msg_dbg(msg, "port->rej: "); | |
431 | ||
432 | /* discard rejected message if it shouldn't be returned to sender */ | |
433 | if (msg_errcode(msg) || msg_dest_droppable(msg)) { | |
434 | buf_discard(buf); | |
435 | return data_sz; | |
436 | } | |
437 | ||
438 | /* construct rejected message */ | |
439 | if (msg_mcast(msg)) | |
440 | hdr_sz = MCAST_H_SIZE; | |
441 | else | |
442 | hdr_sz = LONG_H_SIZE; | |
443 | rbuf = buf_acquire(data_sz + hdr_sz); | |
444 | if (rbuf == NULL) { | |
445 | buf_discard(buf); | |
446 | return data_sz; | |
447 | } | |
448 | rmsg = buf_msg(rbuf); | |
449 | msg_init(rmsg, imp, msg_type(msg), err, hdr_sz, msg_orignode(msg)); | |
450 | msg_set_destport(rmsg, msg_origport(msg)); | |
451 | msg_set_prevnode(rmsg, tipc_own_addr); | |
452 | msg_set_origport(rmsg, msg_destport(msg)); | |
453 | if (msg_short(msg)) | |
454 | msg_set_orignode(rmsg, tipc_own_addr); | |
455 | else | |
456 | msg_set_orignode(rmsg, msg_destnode(msg)); | |
c4307285 | 457 | msg_set_size(rmsg, data_sz + hdr_sz); |
b97bf3fd PL |
458 | msg_set_nametype(rmsg, msg_nametype(msg)); |
459 | msg_set_nameinst(rmsg, msg_nameinst(msg)); | |
27d7ff46 | 460 | skb_copy_to_linear_data_offset(rbuf, hdr_sz, msg_data(msg), data_sz); |
b97bf3fd PL |
461 | |
462 | /* send self-abort message when rejecting on a connected port */ | |
463 | if (msg_connected(msg)) { | |
1fc54d8f | 464 | struct sk_buff *abuf = NULL; |
4323add6 | 465 | struct port *p_ptr = tipc_port_lock(msg_destport(msg)); |
b97bf3fd PL |
466 | |
467 | if (p_ptr) { | |
468 | if (p_ptr->publ.connected) | |
469 | abuf = port_build_self_abort_msg(p_ptr, err); | |
4323add6 | 470 | tipc_port_unlock(p_ptr); |
b97bf3fd | 471 | } |
4323add6 | 472 | tipc_net_route_msg(abuf); |
b97bf3fd PL |
473 | } |
474 | ||
475 | /* send rejected message */ | |
476 | buf_discard(buf); | |
4323add6 | 477 | tipc_net_route_msg(rbuf); |
b97bf3fd PL |
478 | return data_sz; |
479 | } | |
480 | ||
4323add6 PL |
481 | int tipc_port_reject_sections(struct port *p_ptr, struct tipc_msg *hdr, |
482 | struct iovec const *msg_sect, u32 num_sect, | |
483 | int err) | |
b97bf3fd PL |
484 | { |
485 | struct sk_buff *buf; | |
486 | int res; | |
487 | ||
c4307285 | 488 | res = msg_build(hdr, msg_sect, num_sect, MAX_MSG_SIZE, |
b97bf3fd PL |
489 | !p_ptr->user_port, &buf); |
490 | if (!buf) | |
491 | return res; | |
492 | ||
493 | return tipc_reject_msg(buf, err); | |
494 | } | |
495 | ||
496 | static void port_timeout(unsigned long ref) | |
497 | { | |
4323add6 | 498 | struct port *p_ptr = tipc_port_lock(ref); |
1fc54d8f | 499 | struct sk_buff *buf = NULL; |
b97bf3fd | 500 | |
065fd177 AS |
501 | if (!p_ptr) |
502 | return; | |
503 | ||
504 | if (!p_ptr->publ.connected) { | |
505 | tipc_port_unlock(p_ptr); | |
b97bf3fd | 506 | return; |
065fd177 | 507 | } |
b97bf3fd PL |
508 | |
509 | /* Last probe answered ? */ | |
510 | if (p_ptr->probing_state == PROBING) { | |
511 | buf = port_build_self_abort_msg(p_ptr, TIPC_ERR_NO_PORT); | |
512 | } else { | |
513 | buf = port_build_proto_msg(port_peerport(p_ptr), | |
514 | port_peernode(p_ptr), | |
515 | p_ptr->publ.ref, | |
516 | tipc_own_addr, | |
517 | CONN_MANAGER, | |
518 | CONN_PROBE, | |
c4307285 | 519 | TIPC_OK, |
b97bf3fd PL |
520 | port_out_seqno(p_ptr), |
521 | 0); | |
522 | port_incr_out_seqno(p_ptr); | |
523 | p_ptr->probing_state = PROBING; | |
524 | k_start_timer(&p_ptr->timer, p_ptr->probing_interval); | |
525 | } | |
4323add6 PL |
526 | tipc_port_unlock(p_ptr); |
527 | tipc_net_route_msg(buf); | |
b97bf3fd PL |
528 | } |
529 | ||
530 | ||
531 | static void port_handle_node_down(unsigned long ref) | |
532 | { | |
4323add6 | 533 | struct port *p_ptr = tipc_port_lock(ref); |
1fc54d8f | 534 | struct sk_buff* buf = NULL; |
b97bf3fd PL |
535 | |
536 | if (!p_ptr) | |
537 | return; | |
538 | buf = port_build_self_abort_msg(p_ptr, TIPC_ERR_NO_NODE); | |
4323add6 PL |
539 | tipc_port_unlock(p_ptr); |
540 | tipc_net_route_msg(buf); | |
b97bf3fd PL |
541 | } |
542 | ||
543 | ||
544 | static struct sk_buff *port_build_self_abort_msg(struct port *p_ptr, u32 err) | |
545 | { | |
546 | u32 imp = msg_importance(&p_ptr->publ.phdr); | |
547 | ||
548 | if (!p_ptr->publ.connected) | |
1fc54d8f | 549 | return NULL; |
b97bf3fd PL |
550 | if (imp < TIPC_CRITICAL_IMPORTANCE) |
551 | imp++; | |
552 | return port_build_proto_msg(p_ptr->publ.ref, | |
553 | tipc_own_addr, | |
554 | port_peerport(p_ptr), | |
555 | port_peernode(p_ptr), | |
556 | imp, | |
557 | TIPC_CONN_MSG, | |
c4307285 | 558 | err, |
b97bf3fd PL |
559 | p_ptr->last_in_seqno + 1, |
560 | 0); | |
561 | } | |
562 | ||
563 | ||
564 | static struct sk_buff *port_build_peer_abort_msg(struct port *p_ptr, u32 err) | |
565 | { | |
566 | u32 imp = msg_importance(&p_ptr->publ.phdr); | |
567 | ||
568 | if (!p_ptr->publ.connected) | |
1fc54d8f | 569 | return NULL; |
b97bf3fd PL |
570 | if (imp < TIPC_CRITICAL_IMPORTANCE) |
571 | imp++; | |
572 | return port_build_proto_msg(port_peerport(p_ptr), | |
573 | port_peernode(p_ptr), | |
574 | p_ptr->publ.ref, | |
575 | tipc_own_addr, | |
576 | imp, | |
577 | TIPC_CONN_MSG, | |
c4307285 | 578 | err, |
b97bf3fd PL |
579 | port_out_seqno(p_ptr), |
580 | 0); | |
581 | } | |
582 | ||
4323add6 | 583 | void tipc_port_recv_proto_msg(struct sk_buff *buf) |
b97bf3fd PL |
584 | { |
585 | struct tipc_msg *msg = buf_msg(buf); | |
4323add6 | 586 | struct port *p_ptr = tipc_port_lock(msg_destport(msg)); |
b97bf3fd | 587 | u32 err = TIPC_OK; |
1fc54d8f SR |
588 | struct sk_buff *r_buf = NULL; |
589 | struct sk_buff *abort_buf = NULL; | |
b97bf3fd PL |
590 | |
591 | msg_dbg(msg, "PORT<RECV<:"); | |
592 | ||
593 | if (!p_ptr) { | |
594 | err = TIPC_ERR_NO_PORT; | |
595 | } else if (p_ptr->publ.connected) { | |
596 | if (port_peernode(p_ptr) != msg_orignode(msg)) | |
597 | err = TIPC_ERR_NO_PORT; | |
598 | if (port_peerport(p_ptr) != msg_origport(msg)) | |
599 | err = TIPC_ERR_NO_PORT; | |
600 | if (!err && msg_routed(msg)) { | |
601 | u32 seqno = msg_transp_seqno(msg); | |
602 | u32 myno = ++p_ptr->last_in_seqno; | |
603 | if (seqno != myno) { | |
604 | err = TIPC_ERR_NO_PORT; | |
605 | abort_buf = port_build_self_abort_msg(p_ptr, err); | |
606 | } | |
607 | } | |
608 | if (msg_type(msg) == CONN_ACK) { | |
c4307285 | 609 | int wakeup = tipc_port_congested(p_ptr) && |
b97bf3fd PL |
610 | p_ptr->publ.congested && |
611 | p_ptr->wakeup; | |
612 | p_ptr->acked += msg_msgcnt(msg); | |
4323add6 | 613 | if (tipc_port_congested(p_ptr)) |
b97bf3fd PL |
614 | goto exit; |
615 | p_ptr->publ.congested = 0; | |
616 | if (!wakeup) | |
617 | goto exit; | |
618 | p_ptr->wakeup(&p_ptr->publ); | |
619 | goto exit; | |
620 | } | |
621 | } else if (p_ptr->publ.published) { | |
622 | err = TIPC_ERR_NO_PORT; | |
623 | } | |
624 | if (err) { | |
625 | r_buf = port_build_proto_msg(msg_origport(msg), | |
c4307285 YH |
626 | msg_orignode(msg), |
627 | msg_destport(msg), | |
b97bf3fd | 628 | tipc_own_addr, |
06d82c91 | 629 | TIPC_HIGH_IMPORTANCE, |
b97bf3fd PL |
630 | TIPC_CONN_MSG, |
631 | err, | |
632 | 0, | |
633 | 0); | |
634 | goto exit; | |
635 | } | |
636 | ||
637 | /* All is fine */ | |
638 | if (msg_type(msg) == CONN_PROBE) { | |
c4307285 YH |
639 | r_buf = port_build_proto_msg(msg_origport(msg), |
640 | msg_orignode(msg), | |
641 | msg_destport(msg), | |
642 | tipc_own_addr, | |
b97bf3fd PL |
643 | CONN_MANAGER, |
644 | CONN_PROBE_REPLY, | |
645 | TIPC_OK, | |
646 | port_out_seqno(p_ptr), | |
647 | 0); | |
648 | } | |
649 | p_ptr->probing_state = CONFIRMED; | |
650 | port_incr_out_seqno(p_ptr); | |
651 | exit: | |
652 | if (p_ptr) | |
4323add6 PL |
653 | tipc_port_unlock(p_ptr); |
654 | tipc_net_route_msg(r_buf); | |
655 | tipc_net_route_msg(abort_buf); | |
b97bf3fd PL |
656 | buf_discard(buf); |
657 | } | |
658 | ||
659 | static void port_print(struct port *p_ptr, struct print_buf *buf, int full_id) | |
660 | { | |
c4307285 | 661 | struct publication *publ; |
b97bf3fd PL |
662 | |
663 | if (full_id) | |
c4307285 | 664 | tipc_printf(buf, "<%u.%u.%u:%u>:", |
b97bf3fd | 665 | tipc_zone(tipc_own_addr), tipc_cluster(tipc_own_addr), |
c4307285 | 666 | tipc_node(tipc_own_addr), p_ptr->publ.ref); |
b97bf3fd PL |
667 | else |
668 | tipc_printf(buf, "%-10u:", p_ptr->publ.ref); | |
669 | ||
c4307285 YH |
670 | if (p_ptr->publ.connected) { |
671 | u32 dport = port_peerport(p_ptr); | |
672 | u32 destnode = port_peernode(p_ptr); | |
673 | ||
674 | tipc_printf(buf, " connected to <%u.%u.%u:%u>", | |
675 | tipc_zone(destnode), tipc_cluster(destnode), | |
676 | tipc_node(destnode), dport); | |
677 | if (p_ptr->publ.conn_type != 0) | |
678 | tipc_printf(buf, " via {%u,%u}", | |
679 | p_ptr->publ.conn_type, | |
680 | p_ptr->publ.conn_instance); | |
681 | } | |
682 | else if (p_ptr->publ.published) { | |
683 | tipc_printf(buf, " bound to"); | |
684 | list_for_each_entry(publ, &p_ptr->publications, pport_list) { | |
b97bf3fd PL |
685 | if (publ->lower == publ->upper) |
686 | tipc_printf(buf, " {%u,%u}", publ->type, | |
687 | publ->lower); | |
688 | else | |
c4307285 | 689 | tipc_printf(buf, " {%u,%u,%u}", publ->type, |
b97bf3fd | 690 | publ->lower, publ->upper); |
c4307285 YH |
691 | } |
692 | } | |
693 | tipc_printf(buf, "\n"); | |
b97bf3fd PL |
694 | } |
695 | ||
696 | #define MAX_PORT_QUERY 32768 | |
697 | ||
4323add6 | 698 | struct sk_buff *tipc_port_get_ports(void) |
b97bf3fd PL |
699 | { |
700 | struct sk_buff *buf; | |
701 | struct tlv_desc *rep_tlv; | |
702 | struct print_buf pb; | |
703 | struct port *p_ptr; | |
704 | int str_len; | |
705 | ||
4323add6 | 706 | buf = tipc_cfg_reply_alloc(TLV_SPACE(MAX_PORT_QUERY)); |
b97bf3fd PL |
707 | if (!buf) |
708 | return NULL; | |
709 | rep_tlv = (struct tlv_desc *)buf->data; | |
710 | ||
4323add6 PL |
711 | tipc_printbuf_init(&pb, TLV_DATA(rep_tlv), MAX_PORT_QUERY); |
712 | spin_lock_bh(&tipc_port_list_lock); | |
b97bf3fd PL |
713 | list_for_each_entry(p_ptr, &ports, port_list) { |
714 | spin_lock_bh(p_ptr->publ.lock); | |
715 | port_print(p_ptr, &pb, 0); | |
716 | spin_unlock_bh(p_ptr->publ.lock); | |
717 | } | |
4323add6 PL |
718 | spin_unlock_bh(&tipc_port_list_lock); |
719 | str_len = tipc_printbuf_validate(&pb); | |
b97bf3fd PL |
720 | |
721 | skb_put(buf, TLV_SPACE(str_len)); | |
722 | TLV_SET(rep_tlv, TIPC_TLV_ULTRA_STRING, NULL, str_len); | |
723 | ||
724 | return buf; | |
725 | } | |
726 | ||
727 | #if 0 | |
728 | ||
729 | #define MAX_PORT_STATS 2000 | |
730 | ||
731 | struct sk_buff *port_show_stats(const void *req_tlv_area, int req_tlv_space) | |
732 | { | |
733 | u32 ref; | |
734 | struct port *p_ptr; | |
735 | struct sk_buff *buf; | |
736 | struct tlv_desc *rep_tlv; | |
737 | struct print_buf pb; | |
738 | int str_len; | |
739 | ||
740 | if (!TLV_CHECK(req_tlv_area, req_tlv_space, TIPC_TLV_PORT_REF)) | |
741 | return cfg_reply_error_string(TIPC_CFG_TLV_ERROR); | |
742 | ||
743 | ref = *(u32 *)TLV_DATA(req_tlv_area); | |
744 | ref = ntohl(ref); | |
745 | ||
4323add6 | 746 | p_ptr = tipc_port_lock(ref); |
b97bf3fd PL |
747 | if (!p_ptr) |
748 | return cfg_reply_error_string("port not found"); | |
749 | ||
4323add6 | 750 | buf = tipc_cfg_reply_alloc(TLV_SPACE(MAX_PORT_STATS)); |
b97bf3fd | 751 | if (!buf) { |
4323add6 | 752 | tipc_port_unlock(p_ptr); |
b97bf3fd PL |
753 | return NULL; |
754 | } | |
755 | rep_tlv = (struct tlv_desc *)buf->data; | |
756 | ||
4323add6 | 757 | tipc_printbuf_init(&pb, TLV_DATA(rep_tlv), MAX_PORT_STATS); |
b97bf3fd PL |
758 | port_print(p_ptr, &pb, 1); |
759 | /* NEED TO FILL IN ADDITIONAL PORT STATISTICS HERE */ | |
4323add6 PL |
760 | tipc_port_unlock(p_ptr); |
761 | str_len = tipc_printbuf_validate(&pb); | |
b97bf3fd PL |
762 | |
763 | skb_put(buf, TLV_SPACE(str_len)); | |
764 | TLV_SET(rep_tlv, TIPC_TLV_ULTRA_STRING, NULL, str_len); | |
765 | ||
766 | return buf; | |
767 | } | |
768 | ||
769 | #endif | |
770 | ||
4323add6 | 771 | void tipc_port_reinit(void) |
b97bf3fd PL |
772 | { |
773 | struct port *p_ptr; | |
774 | struct tipc_msg *msg; | |
775 | ||
4323add6 | 776 | spin_lock_bh(&tipc_port_list_lock); |
b97bf3fd PL |
777 | list_for_each_entry(p_ptr, &ports, port_list) { |
778 | msg = &p_ptr->publ.phdr; | |
779 | if (msg_orignode(msg) == tipc_own_addr) | |
780 | break; | |
781 | msg_set_orignode(msg, tipc_own_addr); | |
782 | } | |
4323add6 | 783 | spin_unlock_bh(&tipc_port_list_lock); |
b97bf3fd PL |
784 | } |
785 | ||
786 | ||
787 | /* | |
788 | * port_dispatcher_sigh(): Signal handler for messages destinated | |
789 | * to the tipc_port interface. | |
790 | */ | |
791 | ||
792 | static void port_dispatcher_sigh(void *dummy) | |
793 | { | |
794 | struct sk_buff *buf; | |
795 | ||
796 | spin_lock_bh(&queue_lock); | |
797 | buf = msg_queue_head; | |
1fc54d8f | 798 | msg_queue_head = NULL; |
b97bf3fd PL |
799 | spin_unlock_bh(&queue_lock); |
800 | ||
801 | while (buf) { | |
802 | struct port *p_ptr; | |
803 | struct user_port *up_ptr; | |
804 | struct tipc_portid orig; | |
805 | struct tipc_name_seq dseq; | |
806 | void *usr_handle; | |
807 | int connected; | |
808 | int published; | |
9688243b | 809 | u32 message_type; |
b97bf3fd PL |
810 | |
811 | struct sk_buff *next = buf->next; | |
812 | struct tipc_msg *msg = buf_msg(buf); | |
813 | u32 dref = msg_destport(msg); | |
c4307285 | 814 | |
9688243b AS |
815 | message_type = msg_type(msg); |
816 | if (message_type > TIPC_DIRECT_MSG) | |
817 | goto reject; /* Unsupported message type */ | |
818 | ||
4323add6 | 819 | p_ptr = tipc_port_lock(dref); |
9688243b AS |
820 | if (!p_ptr) |
821 | goto reject; /* Port deleted while msg in queue */ | |
822 | ||
b97bf3fd PL |
823 | orig.ref = msg_origport(msg); |
824 | orig.node = msg_orignode(msg); | |
825 | up_ptr = p_ptr->user_port; | |
826 | usr_handle = up_ptr->usr_handle; | |
827 | connected = p_ptr->publ.connected; | |
828 | published = p_ptr->publ.published; | |
829 | ||
830 | if (unlikely(msg_errcode(msg))) | |
831 | goto err; | |
832 | ||
9688243b | 833 | switch (message_type) { |
c4307285 | 834 | |
b97bf3fd PL |
835 | case TIPC_CONN_MSG:{ |
836 | tipc_conn_msg_event cb = up_ptr->conn_msg_cb; | |
837 | u32 peer_port = port_peerport(p_ptr); | |
838 | u32 peer_node = port_peernode(p_ptr); | |
839 | ||
4cec72c8 | 840 | tipc_port_unlock(p_ptr); |
b97bf3fd PL |
841 | if (unlikely(!connected)) { |
842 | if (unlikely(published)) | |
843 | goto reject; | |
844 | tipc_connect2port(dref,&orig); | |
845 | } | |
846 | if (unlikely(msg_origport(msg) != peer_port)) | |
847 | goto reject; | |
848 | if (unlikely(msg_orignode(msg) != peer_node)) | |
849 | goto reject; | |
850 | if (unlikely(!cb)) | |
851 | goto reject; | |
c4307285 | 852 | if (unlikely(++p_ptr->publ.conn_unacked >= |
b97bf3fd | 853 | TIPC_FLOW_CONTROL_WIN)) |
c4307285 | 854 | tipc_acknowledge(dref, |
b97bf3fd PL |
855 | p_ptr->publ.conn_unacked); |
856 | skb_pull(buf, msg_hdr_sz(msg)); | |
857 | cb(usr_handle, dref, &buf, msg_data(msg), | |
858 | msg_data_sz(msg)); | |
859 | break; | |
860 | } | |
861 | case TIPC_DIRECT_MSG:{ | |
862 | tipc_msg_event cb = up_ptr->msg_cb; | |
863 | ||
4cec72c8 | 864 | tipc_port_unlock(p_ptr); |
b97bf3fd PL |
865 | if (unlikely(connected)) |
866 | goto reject; | |
867 | if (unlikely(!cb)) | |
868 | goto reject; | |
869 | skb_pull(buf, msg_hdr_sz(msg)); | |
c4307285 | 870 | cb(usr_handle, dref, &buf, msg_data(msg), |
b97bf3fd PL |
871 | msg_data_sz(msg), msg_importance(msg), |
872 | &orig); | |
873 | break; | |
874 | } | |
9688243b | 875 | case TIPC_MCAST_MSG: |
b97bf3fd PL |
876 | case TIPC_NAMED_MSG:{ |
877 | tipc_named_msg_event cb = up_ptr->named_msg_cb; | |
878 | ||
4cec72c8 | 879 | tipc_port_unlock(p_ptr); |
b97bf3fd PL |
880 | if (unlikely(connected)) |
881 | goto reject; | |
882 | if (unlikely(!cb)) | |
883 | goto reject; | |
884 | if (unlikely(!published)) | |
885 | goto reject; | |
886 | dseq.type = msg_nametype(msg); | |
887 | dseq.lower = msg_nameinst(msg); | |
9688243b AS |
888 | dseq.upper = (message_type == TIPC_NAMED_MSG) |
889 | ? dseq.lower : msg_nameupper(msg); | |
b97bf3fd | 890 | skb_pull(buf, msg_hdr_sz(msg)); |
c4307285 | 891 | cb(usr_handle, dref, &buf, msg_data(msg), |
b97bf3fd PL |
892 | msg_data_sz(msg), msg_importance(msg), |
893 | &orig, &dseq); | |
894 | break; | |
895 | } | |
896 | } | |
897 | if (buf) | |
898 | buf_discard(buf); | |
899 | buf = next; | |
900 | continue; | |
901 | err: | |
9688243b | 902 | switch (message_type) { |
c4307285 | 903 | |
b97bf3fd | 904 | case TIPC_CONN_MSG:{ |
c4307285 | 905 | tipc_conn_shutdown_event cb = |
b97bf3fd PL |
906 | up_ptr->conn_err_cb; |
907 | u32 peer_port = port_peerport(p_ptr); | |
908 | u32 peer_node = port_peernode(p_ptr); | |
909 | ||
4cec72c8 | 910 | tipc_port_unlock(p_ptr); |
b97bf3fd PL |
911 | if (!connected || !cb) |
912 | break; | |
913 | if (msg_origport(msg) != peer_port) | |
914 | break; | |
915 | if (msg_orignode(msg) != peer_node) | |
916 | break; | |
917 | tipc_disconnect(dref); | |
918 | skb_pull(buf, msg_hdr_sz(msg)); | |
919 | cb(usr_handle, dref, &buf, msg_data(msg), | |
920 | msg_data_sz(msg), msg_errcode(msg)); | |
921 | break; | |
922 | } | |
923 | case TIPC_DIRECT_MSG:{ | |
924 | tipc_msg_err_event cb = up_ptr->err_cb; | |
925 | ||
4cec72c8 | 926 | tipc_port_unlock(p_ptr); |
b97bf3fd PL |
927 | if (connected || !cb) |
928 | break; | |
929 | skb_pull(buf, msg_hdr_sz(msg)); | |
930 | cb(usr_handle, dref, &buf, msg_data(msg), | |
931 | msg_data_sz(msg), msg_errcode(msg), &orig); | |
932 | break; | |
933 | } | |
9688243b | 934 | case TIPC_MCAST_MSG: |
b97bf3fd | 935 | case TIPC_NAMED_MSG:{ |
c4307285 | 936 | tipc_named_msg_err_event cb = |
b97bf3fd PL |
937 | up_ptr->named_err_cb; |
938 | ||
4cec72c8 | 939 | tipc_port_unlock(p_ptr); |
b97bf3fd PL |
940 | if (connected || !cb) |
941 | break; | |
942 | dseq.type = msg_nametype(msg); | |
943 | dseq.lower = msg_nameinst(msg); | |
9688243b AS |
944 | dseq.upper = (message_type == TIPC_NAMED_MSG) |
945 | ? dseq.lower : msg_nameupper(msg); | |
b97bf3fd | 946 | skb_pull(buf, msg_hdr_sz(msg)); |
c4307285 | 947 | cb(usr_handle, dref, &buf, msg_data(msg), |
b97bf3fd PL |
948 | msg_data_sz(msg), msg_errcode(msg), &dseq); |
949 | break; | |
950 | } | |
951 | } | |
952 | if (buf) | |
953 | buf_discard(buf); | |
954 | buf = next; | |
955 | continue; | |
956 | reject: | |
957 | tipc_reject_msg(buf, TIPC_ERR_NO_PORT); | |
958 | buf = next; | |
959 | } | |
960 | } | |
961 | ||
962 | /* | |
963 | * port_dispatcher(): Dispatcher for messages destinated | |
964 | * to the tipc_port interface. Called with port locked. | |
965 | */ | |
966 | ||
967 | static u32 port_dispatcher(struct tipc_port *dummy, struct sk_buff *buf) | |
968 | { | |
969 | buf->next = NULL; | |
970 | spin_lock_bh(&queue_lock); | |
971 | if (msg_queue_head) { | |
972 | msg_queue_tail->next = buf; | |
973 | msg_queue_tail = buf; | |
974 | } else { | |
975 | msg_queue_tail = msg_queue_head = buf; | |
4323add6 | 976 | tipc_k_signal((Handler)port_dispatcher_sigh, 0); |
b97bf3fd PL |
977 | } |
978 | spin_unlock_bh(&queue_lock); | |
979 | return TIPC_OK; | |
980 | } | |
981 | ||
c4307285 | 982 | /* |
b97bf3fd | 983 | * Wake up port after congestion: Called with port locked, |
c4307285 | 984 | * |
b97bf3fd PL |
985 | */ |
986 | ||
987 | static void port_wakeup_sh(unsigned long ref) | |
988 | { | |
989 | struct port *p_ptr; | |
990 | struct user_port *up_ptr; | |
1fc54d8f SR |
991 | tipc_continue_event cb = NULL; |
992 | void *uh = NULL; | |
b97bf3fd | 993 | |
4323add6 | 994 | p_ptr = tipc_port_lock(ref); |
b97bf3fd PL |
995 | if (p_ptr) { |
996 | up_ptr = p_ptr->user_port; | |
997 | if (up_ptr) { | |
998 | cb = up_ptr->continue_event_cb; | |
999 | uh = up_ptr->usr_handle; | |
1000 | } | |
4323add6 | 1001 | tipc_port_unlock(p_ptr); |
b97bf3fd PL |
1002 | } |
1003 | if (cb) | |
1004 | cb(uh, ref); | |
1005 | } | |
1006 | ||
1007 | ||
1008 | static void port_wakeup(struct tipc_port *p_ptr) | |
1009 | { | |
4323add6 | 1010 | tipc_k_signal((Handler)port_wakeup_sh, p_ptr->ref); |
b97bf3fd PL |
1011 | } |
1012 | ||
1013 | void tipc_acknowledge(u32 ref, u32 ack) | |
1014 | { | |
1015 | struct port *p_ptr; | |
1fc54d8f | 1016 | struct sk_buff *buf = NULL; |
b97bf3fd | 1017 | |
4323add6 | 1018 | p_ptr = tipc_port_lock(ref); |
b97bf3fd PL |
1019 | if (!p_ptr) |
1020 | return; | |
1021 | if (p_ptr->publ.connected) { | |
1022 | p_ptr->publ.conn_unacked -= ack; | |
1023 | buf = port_build_proto_msg(port_peerport(p_ptr), | |
1024 | port_peernode(p_ptr), | |
1025 | ref, | |
1026 | tipc_own_addr, | |
1027 | CONN_MANAGER, | |
1028 | CONN_ACK, | |
c4307285 | 1029 | TIPC_OK, |
b97bf3fd PL |
1030 | port_out_seqno(p_ptr), |
1031 | ack); | |
1032 | } | |
4323add6 PL |
1033 | tipc_port_unlock(p_ptr); |
1034 | tipc_net_route_msg(buf); | |
b97bf3fd PL |
1035 | } |
1036 | ||
1037 | /* | |
1038 | * tipc_createport(): user level call. Will add port to | |
1039 | * registry if non-zero user_ref. | |
1040 | */ | |
1041 | ||
c4307285 YH |
1042 | int tipc_createport(u32 user_ref, |
1043 | void *usr_handle, | |
1044 | unsigned int importance, | |
1045 | tipc_msg_err_event error_cb, | |
1046 | tipc_named_msg_err_event named_error_cb, | |
1047 | tipc_conn_shutdown_event conn_error_cb, | |
1048 | tipc_msg_event msg_cb, | |
1049 | tipc_named_msg_event named_msg_cb, | |
1050 | tipc_conn_msg_event conn_msg_cb, | |
b97bf3fd PL |
1051 | tipc_continue_event continue_event_cb,/* May be zero */ |
1052 | u32 *portref) | |
1053 | { | |
1054 | struct user_port *up_ptr; | |
c4307285 | 1055 | struct port *p_ptr; |
b97bf3fd PL |
1056 | u32 ref; |
1057 | ||
0da974f4 | 1058 | up_ptr = kmalloc(sizeof(*up_ptr), GFP_ATOMIC); |
a10bd924 | 1059 | if (!up_ptr) { |
a75bf874 | 1060 | warn("Port creation failed, no memory\n"); |
b97bf3fd PL |
1061 | return -ENOMEM; |
1062 | } | |
1fc54d8f | 1063 | ref = tipc_createport_raw(NULL, port_dispatcher, port_wakeup, importance); |
4323add6 | 1064 | p_ptr = tipc_port_lock(ref); |
b97bf3fd PL |
1065 | if (!p_ptr) { |
1066 | kfree(up_ptr); | |
1067 | return -ENOMEM; | |
1068 | } | |
1069 | ||
1070 | p_ptr->user_port = up_ptr; | |
1071 | up_ptr->user_ref = user_ref; | |
1072 | up_ptr->usr_handle = usr_handle; | |
1073 | up_ptr->ref = p_ptr->publ.ref; | |
1074 | up_ptr->err_cb = error_cb; | |
1075 | up_ptr->named_err_cb = named_error_cb; | |
1076 | up_ptr->conn_err_cb = conn_error_cb; | |
1077 | up_ptr->msg_cb = msg_cb; | |
1078 | up_ptr->named_msg_cb = named_msg_cb; | |
1079 | up_ptr->conn_msg_cb = conn_msg_cb; | |
1080 | up_ptr->continue_event_cb = continue_event_cb; | |
1081 | INIT_LIST_HEAD(&up_ptr->uport_list); | |
4323add6 | 1082 | tipc_reg_add_port(up_ptr); |
b97bf3fd | 1083 | *portref = p_ptr->publ.ref; |
c4307285 | 1084 | dbg(" tipc_createport: %x with ref %u\n", p_ptr, p_ptr->publ.ref); |
4323add6 | 1085 | tipc_port_unlock(p_ptr); |
b97bf3fd PL |
1086 | return TIPC_OK; |
1087 | } | |
1088 | ||
1089 | int tipc_ownidentity(u32 ref, struct tipc_portid *id) | |
1090 | { | |
1091 | id->ref = ref; | |
1092 | id->node = tipc_own_addr; | |
1093 | return TIPC_OK; | |
1094 | } | |
1095 | ||
1096 | int tipc_portimportance(u32 ref, unsigned int *importance) | |
1097 | { | |
1098 | struct port *p_ptr; | |
c4307285 | 1099 | |
4323add6 | 1100 | p_ptr = tipc_port_lock(ref); |
b97bf3fd PL |
1101 | if (!p_ptr) |
1102 | return -EINVAL; | |
1103 | *importance = (unsigned int)msg_importance(&p_ptr->publ.phdr); | |
4cec72c8 | 1104 | tipc_port_unlock(p_ptr); |
b97bf3fd PL |
1105 | return TIPC_OK; |
1106 | } | |
1107 | ||
1108 | int tipc_set_portimportance(u32 ref, unsigned int imp) | |
1109 | { | |
1110 | struct port *p_ptr; | |
1111 | ||
1112 | if (imp > TIPC_CRITICAL_IMPORTANCE) | |
1113 | return -EINVAL; | |
1114 | ||
4323add6 | 1115 | p_ptr = tipc_port_lock(ref); |
b97bf3fd PL |
1116 | if (!p_ptr) |
1117 | return -EINVAL; | |
1118 | msg_set_importance(&p_ptr->publ.phdr, (u32)imp); | |
4cec72c8 | 1119 | tipc_port_unlock(p_ptr); |
b97bf3fd PL |
1120 | return TIPC_OK; |
1121 | } | |
1122 | ||
1123 | ||
1124 | int tipc_publish(u32 ref, unsigned int scope, struct tipc_name_seq const *seq) | |
1125 | { | |
1126 | struct port *p_ptr; | |
1127 | struct publication *publ; | |
1128 | u32 key; | |
1129 | int res = -EINVAL; | |
1130 | ||
4323add6 | 1131 | p_ptr = tipc_port_lock(ref); |
d55b4c63 AB |
1132 | if (!p_ptr) |
1133 | return -EINVAL; | |
1134 | ||
b97bf3fd PL |
1135 | dbg("tipc_publ %u, p_ptr = %x, conn = %x, scope = %x, " |
1136 | "lower = %u, upper = %u\n", | |
1137 | ref, p_ptr, p_ptr->publ.connected, scope, seq->lower, seq->upper); | |
b97bf3fd PL |
1138 | if (p_ptr->publ.connected) |
1139 | goto exit; | |
1140 | if (seq->lower > seq->upper) | |
1141 | goto exit; | |
1142 | if ((scope < TIPC_ZONE_SCOPE) || (scope > TIPC_NODE_SCOPE)) | |
1143 | goto exit; | |
1144 | key = ref + p_ptr->pub_count + 1; | |
1145 | if (key == ref) { | |
1146 | res = -EADDRINUSE; | |
1147 | goto exit; | |
1148 | } | |
4323add6 PL |
1149 | publ = tipc_nametbl_publish(seq->type, seq->lower, seq->upper, |
1150 | scope, p_ptr->publ.ref, key); | |
b97bf3fd PL |
1151 | if (publ) { |
1152 | list_add(&publ->pport_list, &p_ptr->publications); | |
1153 | p_ptr->pub_count++; | |
1154 | p_ptr->publ.published = 1; | |
1155 | res = TIPC_OK; | |
1156 | } | |
1157 | exit: | |
4323add6 | 1158 | tipc_port_unlock(p_ptr); |
b97bf3fd PL |
1159 | return res; |
1160 | } | |
1161 | ||
1162 | int tipc_withdraw(u32 ref, unsigned int scope, struct tipc_name_seq const *seq) | |
1163 | { | |
1164 | struct port *p_ptr; | |
1165 | struct publication *publ; | |
1166 | struct publication *tpubl; | |
1167 | int res = -EINVAL; | |
c4307285 | 1168 | |
4323add6 | 1169 | p_ptr = tipc_port_lock(ref); |
b97bf3fd PL |
1170 | if (!p_ptr) |
1171 | return -EINVAL; | |
b97bf3fd | 1172 | if (!seq) { |
c4307285 | 1173 | list_for_each_entry_safe(publ, tpubl, |
b97bf3fd | 1174 | &p_ptr->publications, pport_list) { |
c4307285 | 1175 | tipc_nametbl_withdraw(publ->type, publ->lower, |
4323add6 | 1176 | publ->ref, publ->key); |
b97bf3fd PL |
1177 | } |
1178 | res = TIPC_OK; | |
1179 | } else { | |
c4307285 | 1180 | list_for_each_entry_safe(publ, tpubl, |
b97bf3fd PL |
1181 | &p_ptr->publications, pport_list) { |
1182 | if (publ->scope != scope) | |
1183 | continue; | |
1184 | if (publ->type != seq->type) | |
1185 | continue; | |
1186 | if (publ->lower != seq->lower) | |
1187 | continue; | |
1188 | if (publ->upper != seq->upper) | |
1189 | break; | |
c4307285 | 1190 | tipc_nametbl_withdraw(publ->type, publ->lower, |
4323add6 | 1191 | publ->ref, publ->key); |
b97bf3fd PL |
1192 | res = TIPC_OK; |
1193 | break; | |
1194 | } | |
1195 | } | |
1196 | if (list_empty(&p_ptr->publications)) | |
1197 | p_ptr->publ.published = 0; | |
4323add6 | 1198 | tipc_port_unlock(p_ptr); |
b97bf3fd PL |
1199 | return res; |
1200 | } | |
1201 | ||
1202 | int tipc_connect2port(u32 ref, struct tipc_portid const *peer) | |
1203 | { | |
1204 | struct port *p_ptr; | |
1205 | struct tipc_msg *msg; | |
1206 | int res = -EINVAL; | |
1207 | ||
4323add6 | 1208 | p_ptr = tipc_port_lock(ref); |
b97bf3fd PL |
1209 | if (!p_ptr) |
1210 | return -EINVAL; | |
1211 | if (p_ptr->publ.published || p_ptr->publ.connected) | |
1212 | goto exit; | |
1213 | if (!peer->ref) | |
1214 | goto exit; | |
1215 | ||
1216 | msg = &p_ptr->publ.phdr; | |
1217 | msg_set_destnode(msg, peer->node); | |
1218 | msg_set_destport(msg, peer->ref); | |
1219 | msg_set_orignode(msg, tipc_own_addr); | |
1220 | msg_set_origport(msg, p_ptr->publ.ref); | |
1221 | msg_set_transp_seqno(msg, 42); | |
1222 | msg_set_type(msg, TIPC_CONN_MSG); | |
1223 | if (!may_route(peer->node)) | |
1224 | msg_set_hdr_sz(msg, SHORT_H_SIZE); | |
1225 | else | |
1226 | msg_set_hdr_sz(msg, LONG_H_SIZE); | |
1227 | ||
1228 | p_ptr->probing_interval = PROBING_INTERVAL; | |
1229 | p_ptr->probing_state = CONFIRMED; | |
1230 | p_ptr->publ.connected = 1; | |
1231 | k_start_timer(&p_ptr->timer, p_ptr->probing_interval); | |
1232 | ||
4323add6 | 1233 | tipc_nodesub_subscribe(&p_ptr->subscription,peer->node, |
880b005f | 1234 | (void *)(unsigned long)ref, |
b97bf3fd PL |
1235 | (net_ev_handler)port_handle_node_down); |
1236 | res = TIPC_OK; | |
1237 | exit: | |
4323add6 | 1238 | tipc_port_unlock(p_ptr); |
05646c91 | 1239 | p_ptr->publ.max_pkt = tipc_link_get_max_pkt(peer->node, ref); |
b97bf3fd PL |
1240 | return res; |
1241 | } | |
1242 | ||
1243 | /* | |
1244 | * tipc_disconnect(): Disconnect port form peer. | |
1245 | * This is a node local operation. | |
1246 | */ | |
1247 | ||
1248 | int tipc_disconnect(u32 ref) | |
1249 | { | |
1250 | struct port *p_ptr; | |
1251 | int res = -ENOTCONN; | |
1252 | ||
4323add6 | 1253 | p_ptr = tipc_port_lock(ref); |
b97bf3fd PL |
1254 | if (!p_ptr) |
1255 | return -EINVAL; | |
1256 | if (p_ptr->publ.connected) { | |
1257 | p_ptr->publ.connected = 0; | |
1258 | /* let timer expire on it's own to avoid deadlock! */ | |
4323add6 | 1259 | tipc_nodesub_unsubscribe(&p_ptr->subscription); |
b97bf3fd PL |
1260 | res = TIPC_OK; |
1261 | } | |
4323add6 | 1262 | tipc_port_unlock(p_ptr); |
b97bf3fd PL |
1263 | return res; |
1264 | } | |
1265 | ||
1266 | /* | |
1267 | * tipc_shutdown(): Send a SHUTDOWN msg to peer and disconnect | |
1268 | */ | |
1269 | int tipc_shutdown(u32 ref) | |
1270 | { | |
1271 | struct port *p_ptr; | |
1fc54d8f | 1272 | struct sk_buff *buf = NULL; |
b97bf3fd | 1273 | |
4323add6 | 1274 | p_ptr = tipc_port_lock(ref); |
b97bf3fd PL |
1275 | if (!p_ptr) |
1276 | return -EINVAL; | |
1277 | ||
1278 | if (p_ptr->publ.connected) { | |
1279 | u32 imp = msg_importance(&p_ptr->publ.phdr); | |
1280 | if (imp < TIPC_CRITICAL_IMPORTANCE) | |
1281 | imp++; | |
1282 | buf = port_build_proto_msg(port_peerport(p_ptr), | |
1283 | port_peernode(p_ptr), | |
1284 | ref, | |
1285 | tipc_own_addr, | |
1286 | imp, | |
1287 | TIPC_CONN_MSG, | |
c4307285 | 1288 | TIPC_CONN_SHUTDOWN, |
b97bf3fd PL |
1289 | port_out_seqno(p_ptr), |
1290 | 0); | |
1291 | } | |
4323add6 PL |
1292 | tipc_port_unlock(p_ptr); |
1293 | tipc_net_route_msg(buf); | |
b97bf3fd PL |
1294 | return tipc_disconnect(ref); |
1295 | } | |
1296 | ||
1297 | int tipc_isconnected(u32 ref, int *isconnected) | |
1298 | { | |
1299 | struct port *p_ptr; | |
c4307285 | 1300 | |
4323add6 | 1301 | p_ptr = tipc_port_lock(ref); |
b97bf3fd PL |
1302 | if (!p_ptr) |
1303 | return -EINVAL; | |
1304 | *isconnected = p_ptr->publ.connected; | |
4323add6 | 1305 | tipc_port_unlock(p_ptr); |
b97bf3fd PL |
1306 | return TIPC_OK; |
1307 | } | |
1308 | ||
1309 | int tipc_peer(u32 ref, struct tipc_portid *peer) | |
1310 | { | |
1311 | struct port *p_ptr; | |
1312 | int res; | |
c4307285 | 1313 | |
4323add6 | 1314 | p_ptr = tipc_port_lock(ref); |
b97bf3fd PL |
1315 | if (!p_ptr) |
1316 | return -EINVAL; | |
1317 | if (p_ptr->publ.connected) { | |
1318 | peer->ref = port_peerport(p_ptr); | |
1319 | peer->node = port_peernode(p_ptr); | |
1320 | res = TIPC_OK; | |
1321 | } else | |
1322 | res = -ENOTCONN; | |
4323add6 | 1323 | tipc_port_unlock(p_ptr); |
b97bf3fd PL |
1324 | return res; |
1325 | } | |
1326 | ||
1327 | int tipc_ref_valid(u32 ref) | |
1328 | { | |
1329 | /* Works irrespective of type */ | |
4323add6 | 1330 | return !!tipc_ref_deref(ref); |
b97bf3fd PL |
1331 | } |
1332 | ||
1333 | ||
1334 | /* | |
4323add6 | 1335 | * tipc_port_recv_sections(): Concatenate and deliver sectioned |
b97bf3fd PL |
1336 | * message for this node. |
1337 | */ | |
1338 | ||
4323add6 | 1339 | int tipc_port_recv_sections(struct port *sender, unsigned int num_sect, |
b97bf3fd PL |
1340 | struct iovec const *msg_sect) |
1341 | { | |
1342 | struct sk_buff *buf; | |
1343 | int res; | |
c4307285 | 1344 | |
b97bf3fd PL |
1345 | res = msg_build(&sender->publ.phdr, msg_sect, num_sect, |
1346 | MAX_MSG_SIZE, !sender->user_port, &buf); | |
1347 | if (likely(buf)) | |
4323add6 | 1348 | tipc_port_recv_msg(buf); |
b97bf3fd PL |
1349 | return res; |
1350 | } | |
1351 | ||
1352 | /** | |
1353 | * tipc_send - send message sections on connection | |
1354 | */ | |
1355 | ||
1356 | int tipc_send(u32 ref, unsigned int num_sect, struct iovec const *msg_sect) | |
1357 | { | |
1358 | struct port *p_ptr; | |
1359 | u32 destnode; | |
1360 | int res; | |
1361 | ||
4323add6 | 1362 | p_ptr = tipc_port_deref(ref); |
b97bf3fd PL |
1363 | if (!p_ptr || !p_ptr->publ.connected) |
1364 | return -EINVAL; | |
1365 | ||
1366 | p_ptr->publ.congested = 1; | |
4323add6 | 1367 | if (!tipc_port_congested(p_ptr)) { |
b97bf3fd PL |
1368 | destnode = port_peernode(p_ptr); |
1369 | if (likely(destnode != tipc_own_addr)) | |
4323add6 PL |
1370 | res = tipc_link_send_sections_fast(p_ptr, msg_sect, num_sect, |
1371 | destnode); | |
b97bf3fd | 1372 | else |
4323add6 | 1373 | res = tipc_port_recv_sections(p_ptr, num_sect, msg_sect); |
b97bf3fd PL |
1374 | |
1375 | if (likely(res != -ELINKCONG)) { | |
1376 | port_incr_out_seqno(p_ptr); | |
1377 | p_ptr->publ.congested = 0; | |
1378 | p_ptr->sent++; | |
1379 | return res; | |
1380 | } | |
1381 | } | |
1382 | if (port_unreliable(p_ptr)) { | |
1383 | p_ptr->publ.congested = 0; | |
1384 | /* Just calculate msg length and return */ | |
1385 | return msg_calc_data_size(msg_sect, num_sect); | |
1386 | } | |
1387 | return -ELINKCONG; | |
1388 | } | |
1389 | ||
c4307285 | 1390 | /** |
b97bf3fd PL |
1391 | * tipc_send_buf - send message buffer on connection |
1392 | */ | |
1393 | ||
1394 | int tipc_send_buf(u32 ref, struct sk_buff *buf, unsigned int dsz) | |
1395 | { | |
1396 | struct port *p_ptr; | |
1397 | struct tipc_msg *msg; | |
1398 | u32 destnode; | |
1399 | u32 hsz; | |
1400 | u32 sz; | |
1401 | u32 res; | |
c4307285 | 1402 | |
4323add6 | 1403 | p_ptr = tipc_port_deref(ref); |
b97bf3fd PL |
1404 | if (!p_ptr || !p_ptr->publ.connected) |
1405 | return -EINVAL; | |
1406 | ||
1407 | msg = &p_ptr->publ.phdr; | |
1408 | hsz = msg_hdr_sz(msg); | |
1409 | sz = hsz + dsz; | |
1410 | msg_set_size(msg, sz); | |
1411 | if (skb_cow(buf, hsz)) | |
1412 | return -ENOMEM; | |
1413 | ||
1414 | skb_push(buf, hsz); | |
27d7ff46 | 1415 | skb_copy_to_linear_data(buf, msg, hsz); |
b97bf3fd PL |
1416 | destnode = msg_destnode(msg); |
1417 | p_ptr->publ.congested = 1; | |
4323add6 | 1418 | if (!tipc_port_congested(p_ptr)) { |
b97bf3fd PL |
1419 | if (likely(destnode != tipc_own_addr)) |
1420 | res = tipc_send_buf_fast(buf, destnode); | |
1421 | else { | |
4323add6 | 1422 | tipc_port_recv_msg(buf); |
b97bf3fd PL |
1423 | res = sz; |
1424 | } | |
1425 | if (likely(res != -ELINKCONG)) { | |
1426 | port_incr_out_seqno(p_ptr); | |
1427 | p_ptr->sent++; | |
1428 | p_ptr->publ.congested = 0; | |
1429 | return res; | |
1430 | } | |
1431 | } | |
1432 | if (port_unreliable(p_ptr)) { | |
1433 | p_ptr->publ.congested = 0; | |
1434 | return dsz; | |
1435 | } | |
1436 | return -ELINKCONG; | |
1437 | } | |
1438 | ||
1439 | /** | |
1440 | * tipc_forward2name - forward message sections to port name | |
1441 | */ | |
1442 | ||
c4307285 YH |
1443 | int tipc_forward2name(u32 ref, |
1444 | struct tipc_name const *name, | |
b97bf3fd | 1445 | u32 domain, |
c4307285 | 1446 | u32 num_sect, |
b97bf3fd | 1447 | struct iovec const *msg_sect, |
c4307285 | 1448 | struct tipc_portid const *orig, |
b97bf3fd PL |
1449 | unsigned int importance) |
1450 | { | |
1451 | struct port *p_ptr; | |
1452 | struct tipc_msg *msg; | |
1453 | u32 destnode = domain; | |
1454 | u32 destport = 0; | |
1455 | int res; | |
1456 | ||
4323add6 | 1457 | p_ptr = tipc_port_deref(ref); |
b97bf3fd PL |
1458 | if (!p_ptr || p_ptr->publ.connected) |
1459 | return -EINVAL; | |
1460 | ||
1461 | msg = &p_ptr->publ.phdr; | |
1462 | msg_set_type(msg, TIPC_NAMED_MSG); | |
1463 | msg_set_orignode(msg, orig->node); | |
1464 | msg_set_origport(msg, orig->ref); | |
1465 | msg_set_hdr_sz(msg, LONG_H_SIZE); | |
1466 | msg_set_nametype(msg, name->type); | |
1467 | msg_set_nameinst(msg, name->instance); | |
1468 | msg_set_lookup_scope(msg, addr_scope(domain)); | |
1469 | if (importance <= TIPC_CRITICAL_IMPORTANCE) | |
1470 | msg_set_importance(msg,importance); | |
4323add6 | 1471 | destport = tipc_nametbl_translate(name->type, name->instance, &destnode); |
b97bf3fd PL |
1472 | msg_set_destnode(msg, destnode); |
1473 | msg_set_destport(msg, destport); | |
1474 | ||
1475 | if (likely(destport || destnode)) { | |
1476 | p_ptr->sent++; | |
1477 | if (likely(destnode == tipc_own_addr)) | |
4323add6 | 1478 | return tipc_port_recv_sections(p_ptr, num_sect, msg_sect); |
c4307285 | 1479 | res = tipc_link_send_sections_fast(p_ptr, msg_sect, num_sect, |
4323add6 | 1480 | destnode); |
b97bf3fd PL |
1481 | if (likely(res != -ELINKCONG)) |
1482 | return res; | |
1483 | if (port_unreliable(p_ptr)) { | |
1484 | /* Just calculate msg length and return */ | |
1485 | return msg_calc_data_size(msg_sect, num_sect); | |
1486 | } | |
1487 | return -ELINKCONG; | |
1488 | } | |
c4307285 | 1489 | return tipc_port_reject_sections(p_ptr, msg, msg_sect, num_sect, |
4323add6 | 1490 | TIPC_ERR_NO_NAME); |
b97bf3fd PL |
1491 | } |
1492 | ||
1493 | /** | |
1494 | * tipc_send2name - send message sections to port name | |
1495 | */ | |
1496 | ||
c4307285 | 1497 | int tipc_send2name(u32 ref, |
b97bf3fd | 1498 | struct tipc_name const *name, |
c4307285 YH |
1499 | unsigned int domain, |
1500 | unsigned int num_sect, | |
b97bf3fd PL |
1501 | struct iovec const *msg_sect) |
1502 | { | |
1503 | struct tipc_portid orig; | |
1504 | ||
1505 | orig.ref = ref; | |
1506 | orig.node = tipc_own_addr; | |
1507 | return tipc_forward2name(ref, name, domain, num_sect, msg_sect, &orig, | |
1508 | TIPC_PORT_IMPORTANCE); | |
1509 | } | |
1510 | ||
c4307285 | 1511 | /** |
b97bf3fd PL |
1512 | * tipc_forward_buf2name - forward message buffer to port name |
1513 | */ | |
1514 | ||
1515 | int tipc_forward_buf2name(u32 ref, | |
1516 | struct tipc_name const *name, | |
1517 | u32 domain, | |
1518 | struct sk_buff *buf, | |
1519 | unsigned int dsz, | |
1520 | struct tipc_portid const *orig, | |
1521 | unsigned int importance) | |
1522 | { | |
1523 | struct port *p_ptr; | |
1524 | struct tipc_msg *msg; | |
1525 | u32 destnode = domain; | |
1526 | u32 destport = 0; | |
1527 | int res; | |
1528 | ||
4323add6 | 1529 | p_ptr = (struct port *)tipc_ref_deref(ref); |
b97bf3fd PL |
1530 | if (!p_ptr || p_ptr->publ.connected) |
1531 | return -EINVAL; | |
1532 | ||
1533 | msg = &p_ptr->publ.phdr; | |
1534 | if (importance <= TIPC_CRITICAL_IMPORTANCE) | |
1535 | msg_set_importance(msg, importance); | |
1536 | msg_set_type(msg, TIPC_NAMED_MSG); | |
1537 | msg_set_orignode(msg, orig->node); | |
1538 | msg_set_origport(msg, orig->ref); | |
1539 | msg_set_nametype(msg, name->type); | |
1540 | msg_set_nameinst(msg, name->instance); | |
1541 | msg_set_lookup_scope(msg, addr_scope(domain)); | |
1542 | msg_set_hdr_sz(msg, LONG_H_SIZE); | |
1543 | msg_set_size(msg, LONG_H_SIZE + dsz); | |
4323add6 | 1544 | destport = tipc_nametbl_translate(name->type, name->instance, &destnode); |
b97bf3fd PL |
1545 | msg_set_destnode(msg, destnode); |
1546 | msg_set_destport(msg, destport); | |
1547 | msg_dbg(msg, "forw2name ==> "); | |
1548 | if (skb_cow(buf, LONG_H_SIZE)) | |
1549 | return -ENOMEM; | |
1550 | skb_push(buf, LONG_H_SIZE); | |
27d7ff46 | 1551 | skb_copy_to_linear_data(buf, msg, LONG_H_SIZE); |
b97bf3fd PL |
1552 | msg_dbg(buf_msg(buf),"PREP:"); |
1553 | if (likely(destport || destnode)) { | |
1554 | p_ptr->sent++; | |
1555 | if (destnode == tipc_own_addr) | |
4323add6 | 1556 | return tipc_port_recv_msg(buf); |
b97bf3fd PL |
1557 | res = tipc_send_buf_fast(buf, destnode); |
1558 | if (likely(res != -ELINKCONG)) | |
1559 | return res; | |
1560 | if (port_unreliable(p_ptr)) | |
1561 | return dsz; | |
1562 | return -ELINKCONG; | |
1563 | } | |
1564 | return tipc_reject_msg(buf, TIPC_ERR_NO_NAME); | |
1565 | } | |
1566 | ||
c4307285 | 1567 | /** |
b97bf3fd PL |
1568 | * tipc_send_buf2name - send message buffer to port name |
1569 | */ | |
1570 | ||
c4307285 YH |
1571 | int tipc_send_buf2name(u32 ref, |
1572 | struct tipc_name const *dest, | |
b97bf3fd | 1573 | u32 domain, |
c4307285 | 1574 | struct sk_buff *buf, |
b97bf3fd PL |
1575 | unsigned int dsz) |
1576 | { | |
1577 | struct tipc_portid orig; | |
1578 | ||
1579 | orig.ref = ref; | |
1580 | orig.node = tipc_own_addr; | |
1581 | return tipc_forward_buf2name(ref, dest, domain, buf, dsz, &orig, | |
1582 | TIPC_PORT_IMPORTANCE); | |
1583 | } | |
1584 | ||
c4307285 | 1585 | /** |
b97bf3fd PL |
1586 | * tipc_forward2port - forward message sections to port identity |
1587 | */ | |
1588 | ||
1589 | int tipc_forward2port(u32 ref, | |
1590 | struct tipc_portid const *dest, | |
c4307285 | 1591 | unsigned int num_sect, |
b97bf3fd | 1592 | struct iovec const *msg_sect, |
c4307285 | 1593 | struct tipc_portid const *orig, |
b97bf3fd PL |
1594 | unsigned int importance) |
1595 | { | |
1596 | struct port *p_ptr; | |
1597 | struct tipc_msg *msg; | |
1598 | int res; | |
1599 | ||
4323add6 | 1600 | p_ptr = tipc_port_deref(ref); |
b97bf3fd PL |
1601 | if (!p_ptr || p_ptr->publ.connected) |
1602 | return -EINVAL; | |
1603 | ||
1604 | msg = &p_ptr->publ.phdr; | |
1605 | msg_set_type(msg, TIPC_DIRECT_MSG); | |
1606 | msg_set_orignode(msg, orig->node); | |
1607 | msg_set_origport(msg, orig->ref); | |
1608 | msg_set_destnode(msg, dest->node); | |
1609 | msg_set_destport(msg, dest->ref); | |
1610 | msg_set_hdr_sz(msg, DIR_MSG_H_SIZE); | |
1611 | if (importance <= TIPC_CRITICAL_IMPORTANCE) | |
1612 | msg_set_importance(msg, importance); | |
1613 | p_ptr->sent++; | |
1614 | if (dest->node == tipc_own_addr) | |
4323add6 PL |
1615 | return tipc_port_recv_sections(p_ptr, num_sect, msg_sect); |
1616 | res = tipc_link_send_sections_fast(p_ptr, msg_sect, num_sect, dest->node); | |
b97bf3fd PL |
1617 | if (likely(res != -ELINKCONG)) |
1618 | return res; | |
1619 | if (port_unreliable(p_ptr)) { | |
1620 | /* Just calculate msg length and return */ | |
1621 | return msg_calc_data_size(msg_sect, num_sect); | |
1622 | } | |
1623 | return -ELINKCONG; | |
1624 | } | |
1625 | ||
c4307285 YH |
1626 | /** |
1627 | * tipc_send2port - send message sections to port identity | |
b97bf3fd PL |
1628 | */ |
1629 | ||
c4307285 | 1630 | int tipc_send2port(u32 ref, |
b97bf3fd | 1631 | struct tipc_portid const *dest, |
c4307285 | 1632 | unsigned int num_sect, |
b97bf3fd PL |
1633 | struct iovec const *msg_sect) |
1634 | { | |
1635 | struct tipc_portid orig; | |
1636 | ||
1637 | orig.ref = ref; | |
1638 | orig.node = tipc_own_addr; | |
c4307285 | 1639 | return tipc_forward2port(ref, dest, num_sect, msg_sect, &orig, |
b97bf3fd PL |
1640 | TIPC_PORT_IMPORTANCE); |
1641 | } | |
1642 | ||
c4307285 | 1643 | /** |
b97bf3fd PL |
1644 | * tipc_forward_buf2port - forward message buffer to port identity |
1645 | */ | |
1646 | int tipc_forward_buf2port(u32 ref, | |
1647 | struct tipc_portid const *dest, | |
1648 | struct sk_buff *buf, | |
1649 | unsigned int dsz, | |
1650 | struct tipc_portid const *orig, | |
1651 | unsigned int importance) | |
1652 | { | |
1653 | struct port *p_ptr; | |
1654 | struct tipc_msg *msg; | |
1655 | int res; | |
1656 | ||
4323add6 | 1657 | p_ptr = (struct port *)tipc_ref_deref(ref); |
b97bf3fd PL |
1658 | if (!p_ptr || p_ptr->publ.connected) |
1659 | return -EINVAL; | |
1660 | ||
1661 | msg = &p_ptr->publ.phdr; | |
1662 | msg_set_type(msg, TIPC_DIRECT_MSG); | |
1663 | msg_set_orignode(msg, orig->node); | |
1664 | msg_set_origport(msg, orig->ref); | |
1665 | msg_set_destnode(msg, dest->node); | |
1666 | msg_set_destport(msg, dest->ref); | |
1667 | msg_set_hdr_sz(msg, DIR_MSG_H_SIZE); | |
1668 | if (importance <= TIPC_CRITICAL_IMPORTANCE) | |
1669 | msg_set_importance(msg, importance); | |
1670 | msg_set_size(msg, DIR_MSG_H_SIZE + dsz); | |
1671 | if (skb_cow(buf, DIR_MSG_H_SIZE)) | |
1672 | return -ENOMEM; | |
1673 | ||
1674 | skb_push(buf, DIR_MSG_H_SIZE); | |
27d7ff46 | 1675 | skb_copy_to_linear_data(buf, msg, DIR_MSG_H_SIZE); |
b97bf3fd PL |
1676 | msg_dbg(msg, "buf2port: "); |
1677 | p_ptr->sent++; | |
1678 | if (dest->node == tipc_own_addr) | |
4323add6 | 1679 | return tipc_port_recv_msg(buf); |
b97bf3fd PL |
1680 | res = tipc_send_buf_fast(buf, dest->node); |
1681 | if (likely(res != -ELINKCONG)) | |
1682 | return res; | |
1683 | if (port_unreliable(p_ptr)) | |
1684 | return dsz; | |
1685 | return -ELINKCONG; | |
1686 | } | |
1687 | ||
c4307285 | 1688 | /** |
b97bf3fd PL |
1689 | * tipc_send_buf2port - send message buffer to port identity |
1690 | */ | |
1691 | ||
c4307285 | 1692 | int tipc_send_buf2port(u32 ref, |
b97bf3fd | 1693 | struct tipc_portid const *dest, |
c4307285 | 1694 | struct sk_buff *buf, |
b97bf3fd PL |
1695 | unsigned int dsz) |
1696 | { | |
1697 | struct tipc_portid orig; | |
1698 | ||
1699 | orig.ref = ref; | |
1700 | orig.node = tipc_own_addr; | |
c4307285 | 1701 | return tipc_forward_buf2port(ref, dest, buf, dsz, &orig, |
b97bf3fd PL |
1702 | TIPC_PORT_IMPORTANCE); |
1703 | } | |
1704 |