]>
git.proxmox.com Git - mirror_ubuntu-bionic-kernel.git/blob - net/tipc/port.c
2 * net/tipc/port.c: TIPC port code
4 * Copyright (c) 1992-2007, 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"
42 /* Connection management: */
43 #define PROBING_INTERVAL 3600000 /* [ms] => 1 h */
47 #define MAX_REJECT_SIZE 1024
49 DEFINE_SPINLOCK(tipc_port_list_lock
);
51 static LIST_HEAD(ports
);
52 static void port_handle_node_down(unsigned long ref
);
53 static struct sk_buff
*port_build_self_abort_msg(struct tipc_port
*, u32 err
);
54 static struct sk_buff
*port_build_peer_abort_msg(struct tipc_port
*, u32 err
);
55 static void port_timeout(unsigned long ref
);
58 static u32
port_peernode(struct tipc_port
*p_ptr
)
60 return msg_destnode(&p_ptr
->phdr
);
63 static u32
port_peerport(struct tipc_port
*p_ptr
)
65 return msg_destport(&p_ptr
->phdr
);
69 * tipc_port_peer_msg - verify message was sent by connected port's peer
71 * Handles cases where the node's network address has changed from
72 * the default of <0.0.0> to its configured setting.
74 int tipc_port_peer_msg(struct tipc_port
*p_ptr
, struct tipc_msg
*msg
)
79 if (msg_origport(msg
) != port_peerport(p_ptr
))
82 orignode
= msg_orignode(msg
);
83 peernode
= port_peernode(p_ptr
);
84 return (orignode
== peernode
) ||
85 (!orignode
&& (peernode
== tipc_own_addr
)) ||
86 (!peernode
&& (orignode
== tipc_own_addr
));
90 * tipc_port_mcast_xmit - send a multicast message to local and remote
93 int tipc_port_mcast_xmit(u32 ref
, struct tipc_name_seq
const *seq
,
94 struct iovec
const *msg_sect
, unsigned int len
)
98 struct sk_buff
*ibuf
= NULL
;
99 struct tipc_port_list dports
= {0, NULL
, };
100 struct tipc_port
*oport
= tipc_port_deref(ref
);
104 if (unlikely(!oport
))
107 /* Create multicast message */
109 msg_set_type(hdr
, TIPC_MCAST_MSG
);
110 msg_set_lookup_scope(hdr
, TIPC_CLUSTER_SCOPE
);
111 msg_set_destport(hdr
, 0);
112 msg_set_destnode(hdr
, 0);
113 msg_set_nametype(hdr
, seq
->type
);
114 msg_set_namelower(hdr
, seq
->lower
);
115 msg_set_nameupper(hdr
, seq
->upper
);
116 msg_set_hdr_sz(hdr
, MCAST_H_SIZE
);
117 res
= tipc_msg_build(hdr
, msg_sect
, len
, MAX_MSG_SIZE
, &buf
);
121 /* Figure out where to send multicast message */
122 ext_targets
= tipc_nametbl_mc_translate(seq
->type
, seq
->lower
, seq
->upper
,
123 TIPC_NODE_SCOPE
, &dports
);
125 /* Send message to destinations (duplicate it only if necessary) */
127 if (dports
.count
!= 0) {
128 ibuf
= skb_copy(buf
, GFP_ATOMIC
);
130 tipc_port_list_free(&dports
);
135 res
= tipc_bclink_xmit(buf
);
136 if ((res
< 0) && (dports
.count
!= 0))
144 tipc_port_mcast_rcv(ibuf
, &dports
);
146 tipc_port_list_free(&dports
);
152 * tipc_port_mcast_rcv - deliver multicast message to all destination ports
154 * If there is no port list, perform a lookup to create one
156 void tipc_port_mcast_rcv(struct sk_buff
*buf
, struct tipc_port_list
*dp
)
158 struct tipc_msg
*msg
;
159 struct tipc_port_list dports
= {0, NULL
, };
160 struct tipc_port_list
*item
= dp
;
165 /* Create destination port list, if one wasn't supplied */
167 tipc_nametbl_mc_translate(msg_nametype(msg
),
175 /* Deliver a copy of message to each destination port */
176 if (dp
->count
!= 0) {
177 msg_set_destnode(msg
, tipc_own_addr
);
178 if (dp
->count
== 1) {
179 msg_set_destport(msg
, dp
->ports
[0]);
181 tipc_port_list_free(dp
);
184 for (; cnt
< dp
->count
; cnt
++) {
185 int index
= cnt
% PLSIZE
;
186 struct sk_buff
*b
= skb_clone(buf
, GFP_ATOMIC
);
189 pr_warn("Unable to deliver multicast message(s)\n");
192 if ((index
== 0) && (cnt
!= 0))
194 msg_set_destport(buf_msg(b
), item
->ports
[index
]);
200 tipc_port_list_free(dp
);
204 * tipc_createport - create a generic TIPC port
206 * Returns pointer to (locked) TIPC port, or NULL if unable to create it
208 struct tipc_port
*tipc_createport(struct sock
*sk
,
209 u32 (*dispatcher
)(struct tipc_port
*,
211 void (*wakeup
)(struct tipc_port
*),
212 const u32 importance
)
214 struct tipc_port
*p_ptr
;
215 struct tipc_msg
*msg
;
218 p_ptr
= kzalloc(sizeof(*p_ptr
), GFP_ATOMIC
);
220 pr_warn("Port creation failed, no memory\n");
223 ref
= tipc_ref_acquire(p_ptr
, &p_ptr
->lock
);
225 pr_warn("Port creation failed, ref. table exhausted\n");
231 p_ptr
->max_pkt
= MAX_PKT_DEFAULT
;
233 INIT_LIST_HEAD(&p_ptr
->wait_list
);
234 INIT_LIST_HEAD(&p_ptr
->subscription
.nodesub_list
);
235 p_ptr
->dispatcher
= dispatcher
;
236 p_ptr
->wakeup
= wakeup
;
237 k_init_timer(&p_ptr
->timer
, (Handler
)port_timeout
, ref
);
238 INIT_LIST_HEAD(&p_ptr
->publications
);
239 INIT_LIST_HEAD(&p_ptr
->port_list
);
242 * Must hold port list lock while initializing message header template
243 * to ensure a change to node's own network address doesn't result
244 * in template containing out-dated network address information
246 spin_lock_bh(&tipc_port_list_lock
);
248 tipc_msg_init(msg
, importance
, TIPC_NAMED_MSG
, NAMED_H_SIZE
, 0);
249 msg_set_origport(msg
, ref
);
250 list_add_tail(&p_ptr
->port_list
, &ports
);
251 spin_unlock_bh(&tipc_port_list_lock
);
255 int tipc_deleteport(struct tipc_port
*p_ptr
)
257 struct sk_buff
*buf
= NULL
;
259 tipc_withdraw(p_ptr
, 0, NULL
);
261 spin_lock_bh(p_ptr
->lock
);
262 tipc_ref_discard(p_ptr
->ref
);
263 spin_unlock_bh(p_ptr
->lock
);
265 k_cancel_timer(&p_ptr
->timer
);
266 if (p_ptr
->connected
) {
267 buf
= port_build_peer_abort_msg(p_ptr
, TIPC_ERR_NO_PORT
);
268 tipc_nodesub_unsubscribe(&p_ptr
->subscription
);
271 spin_lock_bh(&tipc_port_list_lock
);
272 list_del(&p_ptr
->port_list
);
273 list_del(&p_ptr
->wait_list
);
274 spin_unlock_bh(&tipc_port_list_lock
);
275 k_term_timer(&p_ptr
->timer
);
277 tipc_net_route_msg(buf
);
281 static int port_unreliable(struct tipc_port
*p_ptr
)
283 return msg_src_droppable(&p_ptr
->phdr
);
286 int tipc_portunreliable(u32 ref
, unsigned int *isunreliable
)
288 struct tipc_port
*p_ptr
;
290 p_ptr
= tipc_port_lock(ref
);
293 *isunreliable
= port_unreliable(p_ptr
);
294 tipc_port_unlock(p_ptr
);
298 int tipc_set_portunreliable(u32 ref
, unsigned int isunreliable
)
300 struct tipc_port
*p_ptr
;
302 p_ptr
= tipc_port_lock(ref
);
305 msg_set_src_droppable(&p_ptr
->phdr
, (isunreliable
!= 0));
306 tipc_port_unlock(p_ptr
);
310 static int port_unreturnable(struct tipc_port
*p_ptr
)
312 return msg_dest_droppable(&p_ptr
->phdr
);
315 int tipc_portunreturnable(u32 ref
, unsigned int *isunrejectable
)
317 struct tipc_port
*p_ptr
;
319 p_ptr
= tipc_port_lock(ref
);
322 *isunrejectable
= port_unreturnable(p_ptr
);
323 tipc_port_unlock(p_ptr
);
327 int tipc_set_portunreturnable(u32 ref
, unsigned int isunrejectable
)
329 struct tipc_port
*p_ptr
;
331 p_ptr
= tipc_port_lock(ref
);
334 msg_set_dest_droppable(&p_ptr
->phdr
, (isunrejectable
!= 0));
335 tipc_port_unlock(p_ptr
);
340 * port_build_proto_msg(): create connection protocol message for port
342 * On entry the port must be locked and connected.
344 static struct sk_buff
*port_build_proto_msg(struct tipc_port
*p_ptr
,
348 struct tipc_msg
*msg
;
350 buf
= tipc_buf_acquire(INT_H_SIZE
);
353 tipc_msg_init(msg
, CONN_MANAGER
, type
, INT_H_SIZE
,
354 port_peernode(p_ptr
));
355 msg_set_destport(msg
, port_peerport(p_ptr
));
356 msg_set_origport(msg
, p_ptr
->ref
);
357 msg_set_msgcnt(msg
, ack
);
362 int tipc_reject_msg(struct sk_buff
*buf
, u32 err
)
364 struct tipc_msg
*msg
= buf_msg(buf
);
365 struct sk_buff
*rbuf
;
366 struct tipc_msg
*rmsg
;
369 u32 data_sz
= msg_data_sz(msg
);
373 /* discard rejected message if it shouldn't be returned to sender */
374 if (WARN(!msg_isdata(msg
),
375 "attempt to reject message with user=%u", msg_user(msg
))) {
379 if (msg_errcode(msg
) || msg_dest_droppable(msg
))
383 * construct returned message by copying rejected message header and
384 * data (or subset), then updating header fields that need adjusting
386 hdr_sz
= msg_hdr_sz(msg
);
387 rmsg_sz
= hdr_sz
+ min_t(u32
, data_sz
, MAX_REJECT_SIZE
);
389 rbuf
= tipc_buf_acquire(rmsg_sz
);
393 rmsg
= buf_msg(rbuf
);
394 skb_copy_to_linear_data(rbuf
, msg
, rmsg_sz
);
396 if (msg_connected(rmsg
)) {
397 imp
= msg_importance(rmsg
);
398 if (imp
< TIPC_CRITICAL_IMPORTANCE
)
399 msg_set_importance(rmsg
, ++imp
);
401 msg_set_non_seq(rmsg
, 0);
402 msg_set_size(rmsg
, rmsg_sz
);
403 msg_set_errcode(rmsg
, err
);
404 msg_set_prevnode(rmsg
, tipc_own_addr
);
405 msg_swap_words(rmsg
, 4, 5);
406 if (!msg_short(rmsg
))
407 msg_swap_words(rmsg
, 6, 7);
409 /* send self-abort message when rejecting on a connected port */
410 if (msg_connected(msg
)) {
411 struct tipc_port
*p_ptr
= tipc_port_lock(msg_destport(msg
));
414 struct sk_buff
*abuf
= NULL
;
416 if (p_ptr
->connected
)
417 abuf
= port_build_self_abort_msg(p_ptr
, err
);
418 tipc_port_unlock(p_ptr
);
419 tipc_net_route_msg(abuf
);
423 /* send returned message & dispose of rejected message */
424 src_node
= msg_prevnode(msg
);
425 if (in_own_node(src_node
))
428 tipc_link_xmit(rbuf
, src_node
, msg_link_selector(rmsg
));
434 int tipc_port_iovec_reject(struct tipc_port
*p_ptr
, struct tipc_msg
*hdr
,
435 struct iovec
const *msg_sect
, unsigned int len
,
441 res
= tipc_msg_build(hdr
, msg_sect
, len
, MAX_MSG_SIZE
, &buf
);
445 return tipc_reject_msg(buf
, err
);
448 static void port_timeout(unsigned long ref
)
450 struct tipc_port
*p_ptr
= tipc_port_lock(ref
);
451 struct sk_buff
*buf
= NULL
;
456 if (!p_ptr
->connected
) {
457 tipc_port_unlock(p_ptr
);
461 /* Last probe answered ? */
462 if (p_ptr
->probing_state
== PROBING
) {
463 buf
= port_build_self_abort_msg(p_ptr
, TIPC_ERR_NO_PORT
);
465 buf
= port_build_proto_msg(p_ptr
, CONN_PROBE
, 0);
466 p_ptr
->probing_state
= PROBING
;
467 k_start_timer(&p_ptr
->timer
, p_ptr
->probing_interval
);
469 tipc_port_unlock(p_ptr
);
470 tipc_net_route_msg(buf
);
474 static void port_handle_node_down(unsigned long ref
)
476 struct tipc_port
*p_ptr
= tipc_port_lock(ref
);
477 struct sk_buff
*buf
= NULL
;
481 buf
= port_build_self_abort_msg(p_ptr
, TIPC_ERR_NO_NODE
);
482 tipc_port_unlock(p_ptr
);
483 tipc_net_route_msg(buf
);
487 static struct sk_buff
*port_build_self_abort_msg(struct tipc_port
*p_ptr
, u32 err
)
489 struct sk_buff
*buf
= port_build_peer_abort_msg(p_ptr
, err
);
492 struct tipc_msg
*msg
= buf_msg(buf
);
493 msg_swap_words(msg
, 4, 5);
494 msg_swap_words(msg
, 6, 7);
500 static struct sk_buff
*port_build_peer_abort_msg(struct tipc_port
*p_ptr
, u32 err
)
503 struct tipc_msg
*msg
;
506 if (!p_ptr
->connected
)
509 buf
= tipc_buf_acquire(BASIC_H_SIZE
);
512 memcpy(msg
, &p_ptr
->phdr
, BASIC_H_SIZE
);
513 msg_set_hdr_sz(msg
, BASIC_H_SIZE
);
514 msg_set_size(msg
, BASIC_H_SIZE
);
515 imp
= msg_importance(msg
);
516 if (imp
< TIPC_CRITICAL_IMPORTANCE
)
517 msg_set_importance(msg
, ++imp
);
518 msg_set_errcode(msg
, err
);
523 void tipc_port_proto_rcv(struct sk_buff
*buf
)
525 struct tipc_msg
*msg
= buf_msg(buf
);
526 struct tipc_port
*p_ptr
;
527 struct sk_buff
*r_buf
= NULL
;
528 u32 destport
= msg_destport(msg
);
531 /* Validate connection */
532 p_ptr
= tipc_port_lock(destport
);
533 if (!p_ptr
|| !p_ptr
->connected
|| !tipc_port_peer_msg(p_ptr
, msg
)) {
534 r_buf
= tipc_buf_acquire(BASIC_H_SIZE
);
536 msg
= buf_msg(r_buf
);
537 tipc_msg_init(msg
, TIPC_HIGH_IMPORTANCE
, TIPC_CONN_MSG
,
538 BASIC_H_SIZE
, msg_orignode(msg
));
539 msg_set_errcode(msg
, TIPC_ERR_NO_PORT
);
540 msg_set_origport(msg
, destport
);
541 msg_set_destport(msg
, msg_origport(msg
));
544 tipc_port_unlock(p_ptr
);
548 /* Process protocol message sent by peer */
549 switch (msg_type(msg
)) {
551 wakeable
= tipc_port_congested(p_ptr
) && p_ptr
->congested
&&
553 p_ptr
->acked
+= msg_msgcnt(msg
);
554 if (!tipc_port_congested(p_ptr
)) {
555 p_ptr
->congested
= 0;
557 p_ptr
->wakeup(p_ptr
);
561 r_buf
= port_build_proto_msg(p_ptr
, CONN_PROBE_REPLY
, 0);
564 /* CONN_PROBE_REPLY or unrecognized - no action required */
567 p_ptr
->probing_state
= CONFIRMED
;
568 tipc_port_unlock(p_ptr
);
570 tipc_net_route_msg(r_buf
);
574 static int port_print(struct tipc_port
*p_ptr
, char *buf
, int len
, int full_id
)
576 struct publication
*publ
;
580 ret
= tipc_snprintf(buf
, len
, "<%u.%u.%u:%u>:",
581 tipc_zone(tipc_own_addr
),
582 tipc_cluster(tipc_own_addr
),
583 tipc_node(tipc_own_addr
), p_ptr
->ref
);
585 ret
= tipc_snprintf(buf
, len
, "%-10u:", p_ptr
->ref
);
587 if (p_ptr
->connected
) {
588 u32 dport
= port_peerport(p_ptr
);
589 u32 destnode
= port_peernode(p_ptr
);
591 ret
+= tipc_snprintf(buf
+ ret
, len
- ret
,
592 " connected to <%u.%u.%u:%u>",
594 tipc_cluster(destnode
),
595 tipc_node(destnode
), dport
);
596 if (p_ptr
->conn_type
!= 0)
597 ret
+= tipc_snprintf(buf
+ ret
, len
- ret
,
598 " via {%u,%u}", p_ptr
->conn_type
,
599 p_ptr
->conn_instance
);
600 } else if (p_ptr
->published
) {
601 ret
+= tipc_snprintf(buf
+ ret
, len
- ret
, " bound to");
602 list_for_each_entry(publ
, &p_ptr
->publications
, pport_list
) {
603 if (publ
->lower
== publ
->upper
)
604 ret
+= tipc_snprintf(buf
+ ret
, len
- ret
,
605 " {%u,%u}", publ
->type
,
608 ret
+= tipc_snprintf(buf
+ ret
, len
- ret
,
609 " {%u,%u,%u}", publ
->type
,
610 publ
->lower
, publ
->upper
);
613 ret
+= tipc_snprintf(buf
+ ret
, len
- ret
, "\n");
617 struct sk_buff
*tipc_port_get_ports(void)
620 struct tlv_desc
*rep_tlv
;
623 struct tipc_port
*p_ptr
;
626 buf
= tipc_cfg_reply_alloc(TLV_SPACE(ULTRA_STRING_MAX_LEN
));
629 rep_tlv
= (struct tlv_desc
*)buf
->data
;
630 pb
= TLV_DATA(rep_tlv
);
631 pb_len
= ULTRA_STRING_MAX_LEN
;
633 spin_lock_bh(&tipc_port_list_lock
);
634 list_for_each_entry(p_ptr
, &ports
, port_list
) {
635 spin_lock_bh(p_ptr
->lock
);
636 str_len
+= port_print(p_ptr
, pb
, pb_len
, 0);
637 spin_unlock_bh(p_ptr
->lock
);
639 spin_unlock_bh(&tipc_port_list_lock
);
640 str_len
+= 1; /* for "\0" */
641 skb_put(buf
, TLV_SPACE(str_len
));
642 TLV_SET(rep_tlv
, TIPC_TLV_ULTRA_STRING
, NULL
, str_len
);
647 void tipc_port_reinit(void)
649 struct tipc_port
*p_ptr
;
650 struct tipc_msg
*msg
;
652 spin_lock_bh(&tipc_port_list_lock
);
653 list_for_each_entry(p_ptr
, &ports
, port_list
) {
655 msg_set_prevnode(msg
, tipc_own_addr
);
656 msg_set_orignode(msg
, tipc_own_addr
);
658 spin_unlock_bh(&tipc_port_list_lock
);
661 void tipc_acknowledge(u32 ref
, u32 ack
)
663 struct tipc_port
*p_ptr
;
664 struct sk_buff
*buf
= NULL
;
666 p_ptr
= tipc_port_lock(ref
);
669 if (p_ptr
->connected
) {
670 p_ptr
->conn_unacked
-= ack
;
671 buf
= port_build_proto_msg(p_ptr
, CONN_ACK
, ack
);
673 tipc_port_unlock(p_ptr
);
674 tipc_net_route_msg(buf
);
677 int tipc_portimportance(u32 ref
, unsigned int *importance
)
679 struct tipc_port
*p_ptr
;
681 p_ptr
= tipc_port_lock(ref
);
684 *importance
= (unsigned int)msg_importance(&p_ptr
->phdr
);
685 tipc_port_unlock(p_ptr
);
689 int tipc_set_portimportance(u32 ref
, unsigned int imp
)
691 struct tipc_port
*p_ptr
;
693 if (imp
> TIPC_CRITICAL_IMPORTANCE
)
696 p_ptr
= tipc_port_lock(ref
);
699 msg_set_importance(&p_ptr
->phdr
, (u32
)imp
);
700 tipc_port_unlock(p_ptr
);
705 int tipc_publish(struct tipc_port
*p_ptr
, unsigned int scope
,
706 struct tipc_name_seq
const *seq
)
708 struct publication
*publ
;
711 if (p_ptr
->connected
)
713 key
= p_ptr
->ref
+ p_ptr
->pub_count
+ 1;
714 if (key
== p_ptr
->ref
)
717 publ
= tipc_nametbl_publish(seq
->type
, seq
->lower
, seq
->upper
,
718 scope
, p_ptr
->ref
, key
);
720 list_add(&publ
->pport_list
, &p_ptr
->publications
);
722 p_ptr
->published
= 1;
728 int tipc_withdraw(struct tipc_port
*p_ptr
, unsigned int scope
,
729 struct tipc_name_seq
const *seq
)
731 struct publication
*publ
;
732 struct publication
*tpubl
;
736 list_for_each_entry_safe(publ
, tpubl
,
737 &p_ptr
->publications
, pport_list
) {
738 tipc_nametbl_withdraw(publ
->type
, publ
->lower
,
739 publ
->ref
, publ
->key
);
743 list_for_each_entry_safe(publ
, tpubl
,
744 &p_ptr
->publications
, pport_list
) {
745 if (publ
->scope
!= scope
)
747 if (publ
->type
!= seq
->type
)
749 if (publ
->lower
!= seq
->lower
)
751 if (publ
->upper
!= seq
->upper
)
753 tipc_nametbl_withdraw(publ
->type
, publ
->lower
,
754 publ
->ref
, publ
->key
);
759 if (list_empty(&p_ptr
->publications
))
760 p_ptr
->published
= 0;
764 int tipc_port_connect(u32 ref
, struct tipc_portid
const *peer
)
766 struct tipc_port
*p_ptr
;
769 p_ptr
= tipc_port_lock(ref
);
772 res
= __tipc_port_connect(ref
, p_ptr
, peer
);
773 tipc_port_unlock(p_ptr
);
778 * __tipc_port_connect - connect to a remote peer
780 * Port must be locked.
782 int __tipc_port_connect(u32 ref
, struct tipc_port
*p_ptr
,
783 struct tipc_portid
const *peer
)
785 struct tipc_msg
*msg
;
788 if (p_ptr
->published
|| p_ptr
->connected
)
794 msg_set_destnode(msg
, peer
->node
);
795 msg_set_destport(msg
, peer
->ref
);
796 msg_set_type(msg
, TIPC_CONN_MSG
);
797 msg_set_lookup_scope(msg
, 0);
798 msg_set_hdr_sz(msg
, SHORT_H_SIZE
);
800 p_ptr
->probing_interval
= PROBING_INTERVAL
;
801 p_ptr
->probing_state
= CONFIRMED
;
802 p_ptr
->connected
= 1;
803 k_start_timer(&p_ptr
->timer
, p_ptr
->probing_interval
);
805 tipc_nodesub_subscribe(&p_ptr
->subscription
, peer
->node
,
806 (void *)(unsigned long)ref
,
807 (net_ev_handler
)port_handle_node_down
);
810 p_ptr
->max_pkt
= tipc_link_get_max_pkt(peer
->node
, ref
);
815 * __tipc_disconnect - disconnect port from peer
817 * Port must be locked.
819 int __tipc_port_disconnect(struct tipc_port
*tp_ptr
)
821 if (tp_ptr
->connected
) {
822 tp_ptr
->connected
= 0;
823 /* let timer expire on it's own to avoid deadlock! */
824 tipc_nodesub_unsubscribe(&tp_ptr
->subscription
);
832 * tipc_port_disconnect(): Disconnect port form peer.
833 * This is a node local operation.
835 int tipc_port_disconnect(u32 ref
)
837 struct tipc_port
*p_ptr
;
840 p_ptr
= tipc_port_lock(ref
);
843 res
= __tipc_port_disconnect(p_ptr
);
844 tipc_port_unlock(p_ptr
);
849 * tipc_port_shutdown(): Send a SHUTDOWN msg to peer and disconnect
851 int tipc_port_shutdown(u32 ref
)
853 struct tipc_port
*p_ptr
;
854 struct sk_buff
*buf
= NULL
;
856 p_ptr
= tipc_port_lock(ref
);
860 buf
= port_build_peer_abort_msg(p_ptr
, TIPC_CONN_SHUTDOWN
);
861 tipc_port_unlock(p_ptr
);
862 tipc_net_route_msg(buf
);
863 return tipc_port_disconnect(ref
);
867 * tipc_port_rcv - receive message from lower layer and deliver to port user
869 int tipc_port_rcv(struct sk_buff
*buf
)
871 struct tipc_port
*p_ptr
;
872 struct tipc_msg
*msg
= buf_msg(buf
);
873 u32 destport
= msg_destport(msg
);
874 u32 dsz
= msg_data_sz(msg
);
877 /* forward unresolved named message */
878 if (unlikely(!destport
)) {
879 tipc_net_route_msg(buf
);
883 /* validate destination & pass to port, otherwise reject message */
884 p_ptr
= tipc_port_lock(destport
);
886 err
= p_ptr
->dispatcher(p_ptr
, buf
);
887 tipc_port_unlock(p_ptr
);
891 err
= TIPC_ERR_NO_PORT
;
894 return tipc_reject_msg(buf
, err
);
898 * tipc_port_iovec_rcv: Concatenate and deliver sectioned
899 * message for this node.
901 static int tipc_port_iovec_rcv(struct tipc_port
*sender
,
902 struct iovec
const *msg_sect
,
908 res
= tipc_msg_build(&sender
->phdr
, msg_sect
, len
, MAX_MSG_SIZE
, &buf
);
915 * tipc_send - send message sections on connection
917 int tipc_send(u32 ref
, struct iovec
const *msg_sect
, unsigned int len
)
919 struct tipc_port
*p_ptr
;
923 p_ptr
= tipc_port_deref(ref
);
924 if (!p_ptr
|| !p_ptr
->connected
)
927 p_ptr
->congested
= 1;
928 if (!tipc_port_congested(p_ptr
)) {
929 destnode
= port_peernode(p_ptr
);
930 if (likely(!in_own_node(destnode
)))
931 res
= tipc_link_iovec_xmit_fast(p_ptr
, msg_sect
, len
,
934 res
= tipc_port_iovec_rcv(p_ptr
, msg_sect
, len
);
936 if (likely(res
!= -ELINKCONG
)) {
937 p_ptr
->congested
= 0;
943 if (port_unreliable(p_ptr
)) {
944 p_ptr
->congested
= 0;
951 * tipc_send2name - send message sections to port name
953 int tipc_send2name(u32 ref
, struct tipc_name
const *name
, unsigned int domain
,
954 struct iovec
const *msg_sect
, unsigned int len
)
956 struct tipc_port
*p_ptr
;
957 struct tipc_msg
*msg
;
958 u32 destnode
= domain
;
962 p_ptr
= tipc_port_deref(ref
);
963 if (!p_ptr
|| p_ptr
->connected
)
967 msg_set_type(msg
, TIPC_NAMED_MSG
);
968 msg_set_hdr_sz(msg
, NAMED_H_SIZE
);
969 msg_set_nametype(msg
, name
->type
);
970 msg_set_nameinst(msg
, name
->instance
);
971 msg_set_lookup_scope(msg
, tipc_addr_scope(domain
));
972 destport
= tipc_nametbl_translate(name
->type
, name
->instance
, &destnode
);
973 msg_set_destnode(msg
, destnode
);
974 msg_set_destport(msg
, destport
);
976 if (likely(destport
|| destnode
)) {
977 if (likely(in_own_node(destnode
)))
978 res
= tipc_port_iovec_rcv(p_ptr
, msg_sect
, len
);
979 else if (tipc_own_addr
)
980 res
= tipc_link_iovec_xmit_fast(p_ptr
, msg_sect
, len
,
983 res
= tipc_port_iovec_reject(p_ptr
, msg
, msg_sect
,
984 len
, TIPC_ERR_NO_NODE
);
985 if (likely(res
!= -ELINKCONG
)) {
990 if (port_unreliable(p_ptr
)) {
995 return tipc_port_iovec_reject(p_ptr
, msg
, msg_sect
, len
,
1000 * tipc_send2port - send message sections to port identity
1002 int tipc_send2port(u32 ref
, struct tipc_portid
const *dest
,
1003 struct iovec
const *msg_sect
, unsigned int len
)
1005 struct tipc_port
*p_ptr
;
1006 struct tipc_msg
*msg
;
1009 p_ptr
= tipc_port_deref(ref
);
1010 if (!p_ptr
|| p_ptr
->connected
)
1014 msg_set_type(msg
, TIPC_DIRECT_MSG
);
1015 msg_set_lookup_scope(msg
, 0);
1016 msg_set_destnode(msg
, dest
->node
);
1017 msg_set_destport(msg
, dest
->ref
);
1018 msg_set_hdr_sz(msg
, BASIC_H_SIZE
);
1020 if (in_own_node(dest
->node
))
1021 res
= tipc_port_iovec_rcv(p_ptr
, msg_sect
, len
);
1022 else if (tipc_own_addr
)
1023 res
= tipc_link_iovec_xmit_fast(p_ptr
, msg_sect
, len
,
1026 res
= tipc_port_iovec_reject(p_ptr
, msg
, msg_sect
, len
,
1028 if (likely(res
!= -ELINKCONG
)) {
1033 if (port_unreliable(p_ptr
)) {