43 #define PROBING_INTERVAL 3600000
47 #define MAX_REJECT_SIZE 1024
49 static struct sk_buff *msg_queue_head;
50 static struct sk_buff *msg_queue_tail;
56 static void port_handle_node_down(
unsigned long ref);
59 static void port_timeout(
unsigned long ref);
64 return msg_destnode(&p_ptr->
phdr);
69 return msg_destport(&p_ptr->
phdr);
83 if (msg_origport(msg) != port_peerport(p_ptr))
86 orignode = msg_orignode(msg);
87 peernode = port_peernode(p_ptr);
88 return (orignode == peernode) ||
89 (!orignode && (peernode == tipc_own_addr)) ||
90 (!peernode && (orignode == tipc_own_addr));
97 u32 num_sect,
struct iovec const *msg_sect,
104 struct tipc_port *oport = tipc_port_deref(ref);
115 msg_set_destport(hdr, 0);
116 msg_set_destnode(hdr, 0);
117 msg_set_nametype(hdr, seq->
type);
118 msg_set_namelower(hdr, seq->
lower);
119 msg_set_nameupper(hdr, seq->
upper);
132 if (dports.
count != 0) {
141 if ((res < 0) && (dports.
count != 0))
181 if (dp->
count != 0) {
182 msg_set_destnode(msg, tipc_own_addr);
183 if (dp->
count == 1) {
184 msg_set_destport(msg, dp->
ports[0]);
189 for (; cnt < dp->
count; cnt++) {
194 pr_warn(
"Unable to deliver multicast message(s)\n");
197 if ((index == 0) && (cnt != 0))
199 msg_set_destport(buf_msg(b), item->
ports[index]);
216 const u32 importance)
224 pr_warn(
"Port creation failed, no memory\n");
229 pr_warn(
"Port creation failed, ref. table exhausted\n");
242 k_init_timer(&p_ptr->
timer, (
Handler)port_timeout, ref);
254 msg_set_origport(msg, ref);
266 p_ptr = tipc_port_lock(ref);
271 tipc_port_unlock(p_ptr);
273 k_cancel_timer(&p_ptr->
timer);
284 k_term_timer(&p_ptr->
timer);
290 static int port_unreliable(
struct tipc_port *p_ptr)
292 return msg_src_droppable(&p_ptr->
phdr);
299 p_ptr = tipc_port_lock(ref);
302 *isunreliable = port_unreliable(p_ptr);
303 tipc_port_unlock(p_ptr);
311 p_ptr = tipc_port_lock(ref);
314 msg_set_src_droppable(&p_ptr->
phdr, (isunreliable != 0));
315 tipc_port_unlock(p_ptr);
319 static int port_unreturnable(
struct tipc_port *p_ptr)
321 return msg_dest_droppable(&p_ptr->
phdr);
328 p_ptr = tipc_port_lock(ref);
331 *isunrejectable = port_unreturnable(p_ptr);
332 tipc_port_unlock(p_ptr);
340 p_ptr = tipc_port_lock(ref);
343 msg_set_dest_droppable(&p_ptr->
phdr, (isunrejectable != 0));
344 tipc_port_unlock(p_ptr);
363 port_peernode(p_ptr));
364 msg_set_destport(msg, port_peerport(p_ptr));
365 msg_set_origport(msg, p_ptr->
ref);
366 msg_set_msgcnt(msg, ack);
373 struct tipc_msg *msg = buf_msg(buf);
383 if (
WARN(!msg_isdata(msg),
384 "attempt to reject message with user=%u", msg_user(msg))) {
388 if (msg_errcode(msg) || msg_dest_droppable(msg))
395 hdr_sz = msg_hdr_sz(msg);
402 rmsg = buf_msg(rbuf);
403 skb_copy_to_linear_data(rbuf, msg, rmsg_sz);
405 if (msg_connected(rmsg)) {
406 imp = msg_importance(rmsg);
408 msg_set_importance(rmsg, ++imp);
410 msg_set_non_seq(rmsg, 0);
411 msg_set_size(rmsg, rmsg_sz);
412 msg_set_errcode(rmsg, err);
413 msg_set_prevnode(rmsg, tipc_own_addr);
414 msg_swap_words(rmsg, 4, 5);
415 if (!msg_short(rmsg))
416 msg_swap_words(rmsg, 6, 7);
419 if (msg_connected(msg)) {
420 struct tipc_port *p_ptr = tipc_port_lock(msg_destport(msg));
426 abuf = port_build_self_abort_msg(p_ptr, err);
427 tipc_port_unlock(p_ptr);
433 src_node = msg_prevnode(msg);
434 if (in_own_node(src_node))
444 struct iovec const *msg_sect,
u32 num_sect,
458 static void port_timeout(
unsigned long ref)
460 struct tipc_port *p_ptr = tipc_port_lock(ref);
467 tipc_port_unlock(p_ptr);
475 buf = port_build_proto_msg(p_ptr,
CONN_PROBE, 0);
479 tipc_port_unlock(p_ptr);
484 static void port_handle_node_down(
unsigned long ref)
486 struct tipc_port *p_ptr = tipc_port_lock(ref);
492 tipc_port_unlock(p_ptr);
499 struct sk_buff *buf = port_build_peer_abort_msg(p_ptr, err);
502 struct tipc_msg *msg = buf_msg(buf);
503 msg_swap_words(msg, 4, 5);
504 msg_swap_words(msg, 6, 7);
525 imp = msg_importance(msg);
527 msg_set_importance(msg, ++imp);
528 msg_set_errcode(msg, err);
535 struct tipc_msg *msg = buf_msg(buf);
538 u32 destport = msg_destport(msg);
542 p_ptr = tipc_port_lock(destport);
546 msg = buf_msg(r_buf);
550 msg_set_origport(msg, destport);
551 msg_set_destport(msg, msg_origport(msg));
554 tipc_port_unlock(p_ptr);
561 wakeable = tipc_port_congested(p_ptr) && p_ptr->
congested &&
563 p_ptr->
acked += msg_msgcnt(msg);
564 if (!tipc_port_congested(p_ptr)) {
578 tipc_port_unlock(p_ptr);
584 static int port_print(
struct tipc_port *p_ptr,
char *buf,
int len,
int full_id)
591 tipc_zone(tipc_own_addr),
592 tipc_cluster(tipc_own_addr),
598 u32 dport = port_peerport(p_ptr);
599 u32 destnode = port_peernode(p_ptr);
602 " connected to <%u.%u.%u:%u>",
604 tipc_cluster(destnode),
615 " {%u,%u}", publ->
type,
619 " {%u,%u,%u}", publ->
type,
645 spin_lock_bh(p_ptr->
lock);
646 str_len += port_print(p_ptr, pb, pb_len, 0);
647 spin_unlock_bh(p_ptr->
lock);
665 msg_set_prevnode(msg, tipc_own_addr);
666 msg_set_orignode(msg, tipc_own_addr);
676 static void port_dispatcher_sigh(
void *
dummy)
680 spin_lock_bh(&queue_lock);
681 buf = msg_queue_head;
682 msg_queue_head =
NULL;
683 spin_unlock_bh(&queue_lock);
697 struct tipc_msg *msg = buf_msg(buf);
698 u32 dref = msg_destport(msg);
704 p_ptr = tipc_port_lock(dref);
708 orig.ref = msg_origport(msg);
709 orig.node = msg_orignode(msg);
719 switch (message_type) {
725 tipc_port_unlock(p_ptr);
731 }
else if (peer_invalid)
733 dsz = msg_data_sz(msg);
740 cb(usr_handle, dref, &buf, msg_data(msg), dsz);
746 tipc_port_unlock(p_ptr);
750 cb(usr_handle, dref, &buf, msg_data(msg),
751 msg_data_sz(msg), msg_importance(msg),
759 tipc_port_unlock(p_ptr);
760 if (
unlikely(!cb || connected || !published))
762 dseq.type = msg_nametype(msg);
763 dseq.lower = msg_nameinst(msg);
765 ? dseq.lower : msg_nameupper(msg);
767 cb(usr_handle, dref, &buf, msg_data(msg),
768 msg_data_sz(msg), msg_importance(msg),
778 switch (message_type) {
784 tipc_port_unlock(p_ptr);
785 if (!cb || !connected || peer_invalid)
789 cb(usr_handle, dref, &buf, msg_data(msg),
790 msg_data_sz(msg), msg_errcode(msg));
796 tipc_port_unlock(p_ptr);
797 if (!cb || connected)
800 cb(usr_handle, dref, &buf, msg_data(msg),
801 msg_data_sz(msg), msg_errcode(msg), &orig);
809 tipc_port_unlock(p_ptr);
810 if (!cb || connected)
812 dseq.type = msg_nametype(msg);
813 dseq.lower = msg_nameinst(msg);
815 ? dseq.lower : msg_nameupper(msg);
817 cb(usr_handle, dref, &buf, msg_data(msg),
818 msg_data_sz(msg), msg_errcode(msg), &dseq);
839 spin_lock_bh(&queue_lock);
840 if (msg_queue_head) {
842 msg_queue_tail =
buf;
844 msg_queue_tail = msg_queue_head =
buf;
847 spin_unlock_bh(&queue_lock);
854 static void port_wakeup_sh(
unsigned long ref)
861 p_ptr = tipc_port_lock(ref);
868 tipc_port_unlock(p_ptr);
875 static void port_wakeup(
struct tipc_port *p_ptr)
885 p_ptr = tipc_port_lock(ref);
890 buf = port_build_proto_msg(p_ptr,
CONN_ACK, ack);
892 tipc_port_unlock(p_ptr);
900 unsigned int importance,
915 pr_warn(
"Port creation failed, no memory\n");
928 up_ptr->
err_cb = error_cb;
935 *portref = p_ptr->
ref;
936 tipc_port_unlock(p_ptr);
944 p_ptr = tipc_port_lock(ref);
947 *importance = (
unsigned int)msg_importance(&p_ptr->
phdr);
948 tipc_port_unlock(p_ptr);
959 p_ptr = tipc_port_lock(ref);
962 msg_set_importance(&p_ptr->
phdr, (
u32)imp);
963 tipc_port_unlock(p_ptr);
975 p_ptr = tipc_port_lock(ref);
987 scope, p_ptr->
ref, key);
995 tipc_port_unlock(p_ptr);
1006 p_ptr = tipc_port_lock(ref);
1019 if (publ->
scope != scope)
1035 tipc_port_unlock(p_ptr);
1045 p_ptr = tipc_port_lock(ref);
1054 msg_set_destnode(msg, peer->
node);
1055 msg_set_destport(msg, peer->
ref);
1057 msg_set_lookup_scope(msg, 0);
1066 (
void *)(
unsigned long)ref,
1070 tipc_port_unlock(p_ptr);
1104 p_ptr = tipc_port_lock(ref);
1108 tipc_port_unlock(p_ptr);
1120 p_ptr = tipc_port_lock(ref);
1125 tipc_port_unlock(p_ptr);
1136 struct tipc_msg *msg = buf_msg(buf);
1137 u32 destport = msg_destport(msg);
1138 u32 dsz = msg_data_sz(msg);
1148 p_ptr = tipc_port_lock(destport);
1151 tipc_port_unlock(p_ptr);
1165 static int tipc_port_recv_sections(
struct tipc_port *sender,
unsigned int num_sect,
1166 struct iovec const *msg_sect,
1183 unsigned int total_len)
1189 p_ptr = tipc_port_deref(ref);
1194 if (!tipc_port_congested(p_ptr)) {
1195 destnode = port_peernode(p_ptr);
1196 if (
likely(!in_own_node(destnode)))
1198 total_len, destnode);
1200 res = tipc_port_recv_sections(p_ptr, num_sect, msg_sect,
1210 if (port_unreliable(p_ptr)) {
1221 unsigned int num_sect,
struct iovec const *msg_sect,
1222 unsigned int total_len)
1226 u32 destnode = domain;
1230 p_ptr = tipc_port_deref(ref);
1237 msg_set_nametype(msg, name->
type);
1238 msg_set_nameinst(msg, name->
instance);
1241 msg_set_destnode(msg, destnode);
1242 msg_set_destport(msg, destport);
1244 if (
likely(destport || destnode)) {
1245 if (
likely(in_own_node(destnode)))
1246 res = tipc_port_recv_sections(p_ptr, num_sect,
1247 msg_sect, total_len);
1248 else if (tipc_own_addr)
1250 num_sect, total_len,
1254 num_sect, total_len,
1261 if (port_unreliable(p_ptr)) {
1274 unsigned int num_sect,
struct iovec const *msg_sect,
1275 unsigned int total_len)
1281 p_ptr = tipc_port_deref(ref);
1287 msg_set_lookup_scope(msg, 0);
1288 msg_set_destnode(msg, dest->
node);
1289 msg_set_destport(msg, dest->
ref);
1292 if (in_own_node(dest->
node))
1293 res = tipc_port_recv_sections(p_ptr, num_sect, msg_sect,
1295 else if (tipc_own_addr)
1297 total_len, dest->
node);
1306 if (port_unreliable(p_ptr)) {
1316 struct sk_buff *buf,
unsigned int dsz)
1328 msg_set_destnode(msg, dest->
node);
1329 msg_set_destport(msg, dest->
ref);
1338 if (in_own_node(dest->
node))
1347 if (port_unreliable(p_ptr))