2 * net/tipc/port.c: TIPC port code
4 * Copyright (c) 1992-2007, 2014, Ericsson AB
5 * Copyright (c) 2004-2008, 2010-2013, Wind River Systems
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions are met:
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.
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.
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
34 * POSSIBILITY OF SUCH DAMAGE.
40 #include "name_table.h"
43 /* Connection management: */
44 #define PROBING_INTERVAL 3600000 /* [ms] => 1 h */
48 #define MAX_REJECT_SIZE 1024
50 DEFINE_SPINLOCK(tipc_port_list_lock
);
52 static LIST_HEAD(ports
);
53 static void port_handle_node_down(unsigned long ref
);
54 static struct sk_buff
*port_build_self_abort_msg(struct tipc_port
*, u32 err
);
55 static struct sk_buff
*port_build_peer_abort_msg(struct tipc_port
*, u32 err
);
56 static void port_timeout(unsigned long ref
);
59 * tipc_port_peer_msg - verify message was sent by connected port's peer
61 * Handles cases where the node's network address has changed from
62 * the default of <0.0.0> to its configured setting.
64 int tipc_port_peer_msg(struct tipc_port
*p_ptr
, struct tipc_msg
*msg
)
69 if (msg_origport(msg
) != tipc_port_peerport(p_ptr
))
72 orignode
= msg_orignode(msg
);
73 peernode
= tipc_port_peernode(p_ptr
);
74 return (orignode
== peernode
) ||
75 (!orignode
&& (peernode
== tipc_own_addr
)) ||
76 (!peernode
&& (orignode
== tipc_own_addr
));
80 * tipc_port_mcast_xmit - send a multicast message to local and remote
83 int tipc_port_mcast_xmit(struct tipc_port
*oport
,
84 struct tipc_name_seq
const *seq
,
85 struct iovec
const *msg_sect
,
90 struct sk_buff
*ibuf
= NULL
;
91 struct tipc_port_list dports
= {0, NULL
, };
95 /* Create multicast message */
97 msg_set_type(hdr
, TIPC_MCAST_MSG
);
98 msg_set_lookup_scope(hdr
, TIPC_CLUSTER_SCOPE
);
99 msg_set_destport(hdr
, 0);
100 msg_set_destnode(hdr
, 0);
101 msg_set_nametype(hdr
, seq
->type
);
102 msg_set_namelower(hdr
, seq
->lower
);
103 msg_set_nameupper(hdr
, seq
->upper
);
104 msg_set_hdr_sz(hdr
, MCAST_H_SIZE
);
105 res
= tipc_msg_build(hdr
, msg_sect
, len
, MAX_MSG_SIZE
, &buf
);
109 /* Figure out where to send multicast message */
110 ext_targets
= tipc_nametbl_mc_translate(seq
->type
, seq
->lower
, seq
->upper
,
111 TIPC_NODE_SCOPE
, &dports
);
113 /* Send message to destinations (duplicate it only if necessary) */
115 if (dports
.count
!= 0) {
116 ibuf
= skb_copy(buf
, GFP_ATOMIC
);
118 tipc_port_list_free(&dports
);
123 res
= tipc_bclink_xmit(buf
);
124 if ((res
< 0) && (dports
.count
!= 0))
132 tipc_port_mcast_rcv(ibuf
, &dports
);
134 tipc_port_list_free(&dports
);
140 * tipc_port_mcast_rcv - deliver multicast message to all destination ports
142 * If there is no port list, perform a lookup to create one
144 void tipc_port_mcast_rcv(struct sk_buff
*buf
, struct tipc_port_list
*dp
)
146 struct tipc_msg
*msg
;
147 struct tipc_port_list dports
= {0, NULL
, };
148 struct tipc_port_list
*item
= dp
;
153 /* Create destination port list, if one wasn't supplied */
155 tipc_nametbl_mc_translate(msg_nametype(msg
),
163 /* Deliver a copy of message to each destination port */
164 if (dp
->count
!= 0) {
165 msg_set_destnode(msg
, tipc_own_addr
);
166 if (dp
->count
== 1) {
167 msg_set_destport(msg
, dp
->ports
[0]);
169 tipc_port_list_free(dp
);
172 for (; cnt
< dp
->count
; cnt
++) {
173 int index
= cnt
% PLSIZE
;
174 struct sk_buff
*b
= skb_clone(buf
, GFP_ATOMIC
);
177 pr_warn("Unable to deliver multicast message(s)\n");
180 if ((index
== 0) && (cnt
!= 0))
182 msg_set_destport(buf_msg(b
), item
->ports
[index
]);
188 tipc_port_list_free(dp
);
192 void tipc_port_wakeup(struct tipc_port
*port
)
194 tipc_sock_wakeup(tipc_port_to_sock(port
));
197 /* tipc_port_init - intiate TIPC port and lock it
199 * Returns obtained reference if initialization is successful, zero otherwise
201 u32
tipc_port_init(struct tipc_port
*p_ptr
,
202 const unsigned int importance
)
204 struct tipc_msg
*msg
;
207 ref
= tipc_ref_acquire(p_ptr
, &p_ptr
->lock
);
209 pr_warn("Port registration failed, ref. table exhausted\n");
213 p_ptr
->max_pkt
= MAX_PKT_DEFAULT
;
215 INIT_LIST_HEAD(&p_ptr
->wait_list
);
216 INIT_LIST_HEAD(&p_ptr
->subscription
.nodesub_list
);
217 k_init_timer(&p_ptr
->timer
, (Handler
)port_timeout
, ref
);
218 INIT_LIST_HEAD(&p_ptr
->publications
);
219 INIT_LIST_HEAD(&p_ptr
->port_list
);
222 * Must hold port list lock while initializing message header template
223 * to ensure a change to node's own network address doesn't result
224 * in template containing out-dated network address information
226 spin_lock_bh(&tipc_port_list_lock
);
228 tipc_msg_init(msg
, importance
, TIPC_NAMED_MSG
, NAMED_H_SIZE
, 0);
229 msg_set_origport(msg
, ref
);
230 list_add_tail(&p_ptr
->port_list
, &ports
);
231 spin_unlock_bh(&tipc_port_list_lock
);
235 void tipc_port_destroy(struct tipc_port
*p_ptr
)
237 struct sk_buff
*buf
= NULL
;
239 tipc_withdraw(p_ptr
, 0, NULL
);
241 spin_lock_bh(p_ptr
->lock
);
242 tipc_ref_discard(p_ptr
->ref
);
243 spin_unlock_bh(p_ptr
->lock
);
245 k_cancel_timer(&p_ptr
->timer
);
246 if (p_ptr
->connected
) {
247 buf
= port_build_peer_abort_msg(p_ptr
, TIPC_ERR_NO_PORT
);
248 tipc_nodesub_unsubscribe(&p_ptr
->subscription
);
251 spin_lock_bh(&tipc_port_list_lock
);
252 list_del(&p_ptr
->port_list
);
253 list_del(&p_ptr
->wait_list
);
254 spin_unlock_bh(&tipc_port_list_lock
);
255 k_term_timer(&p_ptr
->timer
);
256 tipc_net_route_msg(buf
);
260 * port_build_proto_msg(): create connection protocol message for port
262 * On entry the port must be locked and connected.
264 static struct sk_buff
*port_build_proto_msg(struct tipc_port
*p_ptr
,
268 struct tipc_msg
*msg
;
270 buf
= tipc_buf_acquire(INT_H_SIZE
);
273 tipc_msg_init(msg
, CONN_MANAGER
, type
, INT_H_SIZE
,
274 tipc_port_peernode(p_ptr
));
275 msg_set_destport(msg
, tipc_port_peerport(p_ptr
));
276 msg_set_origport(msg
, p_ptr
->ref
);
277 msg_set_msgcnt(msg
, ack
);
282 int tipc_reject_msg(struct sk_buff
*buf
, u32 err
)
284 struct tipc_msg
*msg
= buf_msg(buf
);
285 struct sk_buff
*rbuf
;
286 struct tipc_msg
*rmsg
;
289 u32 data_sz
= msg_data_sz(msg
);
293 /* discard rejected message if it shouldn't be returned to sender */
294 if (WARN(!msg_isdata(msg
),
295 "attempt to reject message with user=%u", msg_user(msg
))) {
299 if (msg_errcode(msg
) || msg_dest_droppable(msg
))
303 * construct returned message by copying rejected message header and
304 * data (or subset), then updating header fields that need adjusting
306 hdr_sz
= msg_hdr_sz(msg
);
307 rmsg_sz
= hdr_sz
+ min_t(u32
, data_sz
, MAX_REJECT_SIZE
);
309 rbuf
= tipc_buf_acquire(rmsg_sz
);
313 rmsg
= buf_msg(rbuf
);
314 skb_copy_to_linear_data(rbuf
, msg
, rmsg_sz
);
316 if (msg_connected(rmsg
)) {
317 imp
= msg_importance(rmsg
);
318 if (imp
< TIPC_CRITICAL_IMPORTANCE
)
319 msg_set_importance(rmsg
, ++imp
);
321 msg_set_non_seq(rmsg
, 0);
322 msg_set_size(rmsg
, rmsg_sz
);
323 msg_set_errcode(rmsg
, err
);
324 msg_set_prevnode(rmsg
, tipc_own_addr
);
325 msg_swap_words(rmsg
, 4, 5);
326 if (!msg_short(rmsg
))
327 msg_swap_words(rmsg
, 6, 7);
329 /* send self-abort message when rejecting on a connected port */
330 if (msg_connected(msg
)) {
331 struct tipc_port
*p_ptr
= tipc_port_lock(msg_destport(msg
));
334 struct sk_buff
*abuf
= NULL
;
336 if (p_ptr
->connected
)
337 abuf
= port_build_self_abort_msg(p_ptr
, err
);
338 tipc_port_unlock(p_ptr
);
339 tipc_net_route_msg(abuf
);
343 /* send returned message & dispose of rejected message */
344 src_node
= msg_prevnode(msg
);
345 if (in_own_node(src_node
))
348 tipc_link_xmit(rbuf
, src_node
, msg_link_selector(rmsg
));
354 int tipc_port_iovec_reject(struct tipc_port
*p_ptr
, struct tipc_msg
*hdr
,
355 struct iovec
const *msg_sect
, unsigned int len
,
361 res
= tipc_msg_build(hdr
, msg_sect
, len
, MAX_MSG_SIZE
, &buf
);
365 return tipc_reject_msg(buf
, err
);
368 static void port_timeout(unsigned long ref
)
370 struct tipc_port
*p_ptr
= tipc_port_lock(ref
);
371 struct sk_buff
*buf
= NULL
;
376 if (!p_ptr
->connected
) {
377 tipc_port_unlock(p_ptr
);
381 /* Last probe answered ? */
382 if (p_ptr
->probing_state
== PROBING
) {
383 buf
= port_build_self_abort_msg(p_ptr
, TIPC_ERR_NO_PORT
);
385 buf
= port_build_proto_msg(p_ptr
, CONN_PROBE
, 0);
386 p_ptr
->probing_state
= PROBING
;
387 k_start_timer(&p_ptr
->timer
, p_ptr
->probing_interval
);
389 tipc_port_unlock(p_ptr
);
390 tipc_net_route_msg(buf
);
394 static void port_handle_node_down(unsigned long ref
)
396 struct tipc_port
*p_ptr
= tipc_port_lock(ref
);
397 struct sk_buff
*buf
= NULL
;
401 buf
= port_build_self_abort_msg(p_ptr
, TIPC_ERR_NO_NODE
);
402 tipc_port_unlock(p_ptr
);
403 tipc_net_route_msg(buf
);
407 static struct sk_buff
*port_build_self_abort_msg(struct tipc_port
*p_ptr
, u32 err
)
409 struct sk_buff
*buf
= port_build_peer_abort_msg(p_ptr
, err
);
412 struct tipc_msg
*msg
= buf_msg(buf
);
413 msg_swap_words(msg
, 4, 5);
414 msg_swap_words(msg
, 6, 7);
420 static struct sk_buff
*port_build_peer_abort_msg(struct tipc_port
*p_ptr
, u32 err
)
423 struct tipc_msg
*msg
;
426 if (!p_ptr
->connected
)
429 buf
= tipc_buf_acquire(BASIC_H_SIZE
);
432 memcpy(msg
, &p_ptr
->phdr
, BASIC_H_SIZE
);
433 msg_set_hdr_sz(msg
, BASIC_H_SIZE
);
434 msg_set_size(msg
, BASIC_H_SIZE
);
435 imp
= msg_importance(msg
);
436 if (imp
< TIPC_CRITICAL_IMPORTANCE
)
437 msg_set_importance(msg
, ++imp
);
438 msg_set_errcode(msg
, err
);
443 void tipc_port_proto_rcv(struct sk_buff
*buf
)
445 struct tipc_msg
*msg
= buf_msg(buf
);
446 struct tipc_port
*p_ptr
;
447 struct sk_buff
*r_buf
= NULL
;
448 u32 destport
= msg_destport(msg
);
451 /* Validate connection */
452 p_ptr
= tipc_port_lock(destport
);
453 if (!p_ptr
|| !p_ptr
->connected
|| !tipc_port_peer_msg(p_ptr
, msg
)) {
454 r_buf
= tipc_buf_acquire(BASIC_H_SIZE
);
456 msg
= buf_msg(r_buf
);
457 tipc_msg_init(msg
, TIPC_HIGH_IMPORTANCE
, TIPC_CONN_MSG
,
458 BASIC_H_SIZE
, msg_orignode(msg
));
459 msg_set_errcode(msg
, TIPC_ERR_NO_PORT
);
460 msg_set_origport(msg
, destport
);
461 msg_set_destport(msg
, msg_origport(msg
));
464 tipc_port_unlock(p_ptr
);
468 /* Process protocol message sent by peer */
469 switch (msg_type(msg
)) {
471 wakeable
= tipc_port_congested(p_ptr
) && p_ptr
->congested
;
472 p_ptr
->acked
+= msg_msgcnt(msg
);
473 if (!tipc_port_congested(p_ptr
)) {
474 p_ptr
->congested
= 0;
476 tipc_port_wakeup(p_ptr
);
480 r_buf
= port_build_proto_msg(p_ptr
, CONN_PROBE_REPLY
, 0);
483 /* CONN_PROBE_REPLY or unrecognized - no action required */
486 p_ptr
->probing_state
= CONFIRMED
;
487 tipc_port_unlock(p_ptr
);
489 tipc_net_route_msg(r_buf
);
493 static int port_print(struct tipc_port
*p_ptr
, char *buf
, int len
, int full_id
)
495 struct publication
*publ
;
499 ret
= tipc_snprintf(buf
, len
, "<%u.%u.%u:%u>:",
500 tipc_zone(tipc_own_addr
),
501 tipc_cluster(tipc_own_addr
),
502 tipc_node(tipc_own_addr
), p_ptr
->ref
);
504 ret
= tipc_snprintf(buf
, len
, "%-10u:", p_ptr
->ref
);
506 if (p_ptr
->connected
) {
507 u32 dport
= tipc_port_peerport(p_ptr
);
508 u32 destnode
= tipc_port_peernode(p_ptr
);
510 ret
+= tipc_snprintf(buf
+ ret
, len
- ret
,
511 " connected to <%u.%u.%u:%u>",
513 tipc_cluster(destnode
),
514 tipc_node(destnode
), dport
);
515 if (p_ptr
->conn_type
!= 0)
516 ret
+= tipc_snprintf(buf
+ ret
, len
- ret
,
517 " via {%u,%u}", p_ptr
->conn_type
,
518 p_ptr
->conn_instance
);
519 } else if (p_ptr
->published
) {
520 ret
+= tipc_snprintf(buf
+ ret
, len
- ret
, " bound to");
521 list_for_each_entry(publ
, &p_ptr
->publications
, pport_list
) {
522 if (publ
->lower
== publ
->upper
)
523 ret
+= tipc_snprintf(buf
+ ret
, len
- ret
,
524 " {%u,%u}", publ
->type
,
527 ret
+= tipc_snprintf(buf
+ ret
, len
- ret
,
528 " {%u,%u,%u}", publ
->type
,
529 publ
->lower
, publ
->upper
);
532 ret
+= tipc_snprintf(buf
+ ret
, len
- ret
, "\n");
536 struct sk_buff
*tipc_port_get_ports(void)
539 struct tlv_desc
*rep_tlv
;
542 struct tipc_port
*p_ptr
;
545 buf
= tipc_cfg_reply_alloc(TLV_SPACE(ULTRA_STRING_MAX_LEN
));
548 rep_tlv
= (struct tlv_desc
*)buf
->data
;
549 pb
= TLV_DATA(rep_tlv
);
550 pb_len
= ULTRA_STRING_MAX_LEN
;
552 spin_lock_bh(&tipc_port_list_lock
);
553 list_for_each_entry(p_ptr
, &ports
, port_list
) {
554 spin_lock_bh(p_ptr
->lock
);
555 str_len
+= port_print(p_ptr
, pb
, pb_len
, 0);
556 spin_unlock_bh(p_ptr
->lock
);
558 spin_unlock_bh(&tipc_port_list_lock
);
559 str_len
+= 1; /* for "\0" */
560 skb_put(buf
, TLV_SPACE(str_len
));
561 TLV_SET(rep_tlv
, TIPC_TLV_ULTRA_STRING
, NULL
, str_len
);
566 void tipc_port_reinit(void)
568 struct tipc_port
*p_ptr
;
569 struct tipc_msg
*msg
;
571 spin_lock_bh(&tipc_port_list_lock
);
572 list_for_each_entry(p_ptr
, &ports
, port_list
) {
574 msg_set_prevnode(msg
, tipc_own_addr
);
575 msg_set_orignode(msg
, tipc_own_addr
);
577 spin_unlock_bh(&tipc_port_list_lock
);
580 void tipc_acknowledge(u32 ref
, u32 ack
)
582 struct tipc_port
*p_ptr
;
583 struct sk_buff
*buf
= NULL
;
585 p_ptr
= tipc_port_lock(ref
);
588 if (p_ptr
->connected
) {
589 p_ptr
->conn_unacked
-= ack
;
590 buf
= port_build_proto_msg(p_ptr
, CONN_ACK
, ack
);
592 tipc_port_unlock(p_ptr
);
593 tipc_net_route_msg(buf
);
596 int tipc_publish(struct tipc_port
*p_ptr
, unsigned int scope
,
597 struct tipc_name_seq
const *seq
)
599 struct publication
*publ
;
602 if (p_ptr
->connected
)
604 key
= p_ptr
->ref
+ p_ptr
->pub_count
+ 1;
605 if (key
== p_ptr
->ref
)
608 publ
= tipc_nametbl_publish(seq
->type
, seq
->lower
, seq
->upper
,
609 scope
, p_ptr
->ref
, key
);
611 list_add(&publ
->pport_list
, &p_ptr
->publications
);
613 p_ptr
->published
= 1;
619 int tipc_withdraw(struct tipc_port
*p_ptr
, unsigned int scope
,
620 struct tipc_name_seq
const *seq
)
622 struct publication
*publ
;
623 struct publication
*tpubl
;
627 list_for_each_entry_safe(publ
, tpubl
,
628 &p_ptr
->publications
, pport_list
) {
629 tipc_nametbl_withdraw(publ
->type
, publ
->lower
,
630 publ
->ref
, publ
->key
);
634 list_for_each_entry_safe(publ
, tpubl
,
635 &p_ptr
->publications
, pport_list
) {
636 if (publ
->scope
!= scope
)
638 if (publ
->type
!= seq
->type
)
640 if (publ
->lower
!= seq
->lower
)
642 if (publ
->upper
!= seq
->upper
)
644 tipc_nametbl_withdraw(publ
->type
, publ
->lower
,
645 publ
->ref
, publ
->key
);
650 if (list_empty(&p_ptr
->publications
))
651 p_ptr
->published
= 0;
655 int tipc_port_connect(u32 ref
, struct tipc_portid
const *peer
)
657 struct tipc_port
*p_ptr
;
660 p_ptr
= tipc_port_lock(ref
);
663 res
= __tipc_port_connect(ref
, p_ptr
, peer
);
664 tipc_port_unlock(p_ptr
);
669 * __tipc_port_connect - connect to a remote peer
671 * Port must be locked.
673 int __tipc_port_connect(u32 ref
, struct tipc_port
*p_ptr
,
674 struct tipc_portid
const *peer
)
676 struct tipc_msg
*msg
;
679 if (p_ptr
->published
|| p_ptr
->connected
)
685 msg_set_destnode(msg
, peer
->node
);
686 msg_set_destport(msg
, peer
->ref
);
687 msg_set_type(msg
, TIPC_CONN_MSG
);
688 msg_set_lookup_scope(msg
, 0);
689 msg_set_hdr_sz(msg
, SHORT_H_SIZE
);
691 p_ptr
->probing_interval
= PROBING_INTERVAL
;
692 p_ptr
->probing_state
= CONFIRMED
;
693 p_ptr
->connected
= 1;
694 k_start_timer(&p_ptr
->timer
, p_ptr
->probing_interval
);
696 tipc_nodesub_subscribe(&p_ptr
->subscription
, peer
->node
,
697 (void *)(unsigned long)ref
,
698 (net_ev_handler
)port_handle_node_down
);
701 p_ptr
->max_pkt
= tipc_link_get_max_pkt(peer
->node
, ref
);
706 * __tipc_disconnect - disconnect port from peer
708 * Port must be locked.
710 int __tipc_port_disconnect(struct tipc_port
*tp_ptr
)
712 if (tp_ptr
->connected
) {
713 tp_ptr
->connected
= 0;
714 /* let timer expire on it's own to avoid deadlock! */
715 tipc_nodesub_unsubscribe(&tp_ptr
->subscription
);
723 * tipc_port_disconnect(): Disconnect port form peer.
724 * This is a node local operation.
726 int tipc_port_disconnect(u32 ref
)
728 struct tipc_port
*p_ptr
;
731 p_ptr
= tipc_port_lock(ref
);
734 res
= __tipc_port_disconnect(p_ptr
);
735 tipc_port_unlock(p_ptr
);
740 * tipc_port_shutdown(): Send a SHUTDOWN msg to peer and disconnect
742 int tipc_port_shutdown(u32 ref
)
744 struct tipc_port
*p_ptr
;
745 struct sk_buff
*buf
= NULL
;
747 p_ptr
= tipc_port_lock(ref
);
751 buf
= port_build_peer_abort_msg(p_ptr
, TIPC_CONN_SHUTDOWN
);
752 tipc_port_unlock(p_ptr
);
753 tipc_net_route_msg(buf
);
754 return tipc_port_disconnect(ref
);
758 * tipc_port_iovec_rcv: Concatenate and deliver sectioned
759 * message for this node.
761 static int tipc_port_iovec_rcv(struct tipc_port
*sender
,
762 struct iovec
const *msg_sect
,
768 res
= tipc_msg_build(&sender
->phdr
, msg_sect
, len
, MAX_MSG_SIZE
, &buf
);
775 * tipc_send - send message sections on connection
777 int tipc_send(struct tipc_port
*p_ptr
,
778 struct iovec
const *msg_sect
,
784 if (!p_ptr
->connected
)
787 p_ptr
->congested
= 1;
788 if (!tipc_port_congested(p_ptr
)) {
789 destnode
= tipc_port_peernode(p_ptr
);
790 if (likely(!in_own_node(destnode
)))
791 res
= tipc_link_iovec_xmit_fast(p_ptr
, msg_sect
, len
,
794 res
= tipc_port_iovec_rcv(p_ptr
, msg_sect
, len
);
796 if (likely(res
!= -ELINKCONG
)) {
797 p_ptr
->congested
= 0;
803 if (tipc_port_unreliable(p_ptr
)) {
804 p_ptr
->congested
= 0;
811 * tipc_send2name - send message sections to port name
813 int tipc_send2name(struct tipc_port
*p_ptr
,
814 struct tipc_name
const *name
,
816 struct iovec
const *msg_sect
,
819 struct tipc_msg
*msg
;
820 u32 destnode
= domain
;
824 if (p_ptr
->connected
)
828 msg_set_type(msg
, TIPC_NAMED_MSG
);
829 msg_set_hdr_sz(msg
, NAMED_H_SIZE
);
830 msg_set_nametype(msg
, name
->type
);
831 msg_set_nameinst(msg
, name
->instance
);
832 msg_set_lookup_scope(msg
, tipc_addr_scope(domain
));
833 destport
= tipc_nametbl_translate(name
->type
, name
->instance
, &destnode
);
834 msg_set_destnode(msg
, destnode
);
835 msg_set_destport(msg
, destport
);
837 if (likely(destport
|| destnode
)) {
838 if (likely(in_own_node(destnode
)))
839 res
= tipc_port_iovec_rcv(p_ptr
, msg_sect
, len
);
840 else if (tipc_own_addr
)
841 res
= tipc_link_iovec_xmit_fast(p_ptr
, msg_sect
, len
,
844 res
= tipc_port_iovec_reject(p_ptr
, msg
, msg_sect
,
845 len
, TIPC_ERR_NO_NODE
);
846 if (likely(res
!= -ELINKCONG
)) {
851 if (tipc_port_unreliable(p_ptr
))
856 return tipc_port_iovec_reject(p_ptr
, msg
, msg_sect
, len
,
861 * tipc_send2port - send message sections to port identity
863 int tipc_send2port(struct tipc_port
*p_ptr
,
864 struct tipc_portid
const *dest
,
865 struct iovec
const *msg_sect
,
868 struct tipc_msg
*msg
;
871 if (p_ptr
->connected
)
875 msg_set_type(msg
, TIPC_DIRECT_MSG
);
876 msg_set_lookup_scope(msg
, 0);
877 msg_set_destnode(msg
, dest
->node
);
878 msg_set_destport(msg
, dest
->ref
);
879 msg_set_hdr_sz(msg
, BASIC_H_SIZE
);
881 if (in_own_node(dest
->node
))
882 res
= tipc_port_iovec_rcv(p_ptr
, msg_sect
, len
);
883 else if (tipc_own_addr
)
884 res
= tipc_link_iovec_xmit_fast(p_ptr
, msg_sect
, len
,
887 res
= tipc_port_iovec_reject(p_ptr
, msg
, msg_sect
, len
,
889 if (likely(res
!= -ELINKCONG
)) {
894 if (tipc_port_unreliable(p_ptr
))