aboutsummaryrefslogtreecommitdiffstats
path: root/net/tipc/port.c
diff options
context:
space:
mode:
Diffstat (limited to 'net/tipc/port.c')
-rw-r--r--net/tipc/port.c111
1 files changed, 42 insertions, 69 deletions
diff --git a/net/tipc/port.c b/net/tipc/port.c
index b3ed2fcab4fb..d43f3182b1d4 100644
--- a/net/tipc/port.c
+++ b/net/tipc/port.c
@@ -90,8 +90,7 @@ int tipc_port_peer_msg(struct tipc_port *p_ptr, struct tipc_msg *msg)
90 * tipc_multicast - send a multicast message to local and remote destinations 90 * tipc_multicast - send a multicast message to local and remote destinations
91 */ 91 */
92int tipc_multicast(u32 ref, struct tipc_name_seq const *seq, 92int tipc_multicast(u32 ref, struct tipc_name_seq const *seq,
93 u32 num_sect, struct iovec const *msg_sect, 93 struct iovec const *msg_sect, unsigned int len)
94 unsigned int total_len)
95{ 94{
96 struct tipc_msg *hdr; 95 struct tipc_msg *hdr;
97 struct sk_buff *buf; 96 struct sk_buff *buf;
@@ -114,8 +113,7 @@ int tipc_multicast(u32 ref, struct tipc_name_seq const *seq,
114 msg_set_namelower(hdr, seq->lower); 113 msg_set_namelower(hdr, seq->lower);
115 msg_set_nameupper(hdr, seq->upper); 114 msg_set_nameupper(hdr, seq->upper);
116 msg_set_hdr_sz(hdr, MCAST_H_SIZE); 115 msg_set_hdr_sz(hdr, MCAST_H_SIZE);
117 res = tipc_msg_build(hdr, msg_sect, num_sect, total_len, MAX_MSG_SIZE, 116 res = tipc_msg_build(hdr, msg_sect, len, MAX_MSG_SIZE, &buf);
118 &buf);
119 if (unlikely(!buf)) 117 if (unlikely(!buf))
120 return res; 118 return res;
121 119
@@ -253,18 +251,15 @@ struct tipc_port *tipc_createport(struct sock *sk,
253 return p_ptr; 251 return p_ptr;
254} 252}
255 253
256int tipc_deleteport(u32 ref) 254int tipc_deleteport(struct tipc_port *p_ptr)
257{ 255{
258 struct tipc_port *p_ptr;
259 struct sk_buff *buf = NULL; 256 struct sk_buff *buf = NULL;
260 257
261 tipc_withdraw(ref, 0, NULL); 258 tipc_withdraw(p_ptr, 0, NULL);
262 p_ptr = tipc_port_lock(ref);
263 if (!p_ptr)
264 return -EINVAL;
265 259
266 tipc_ref_discard(ref); 260 spin_lock_bh(p_ptr->lock);
267 tipc_port_unlock(p_ptr); 261 tipc_ref_discard(p_ptr->ref);
262 spin_unlock_bh(p_ptr->lock);
268 263
269 k_cancel_timer(&p_ptr->timer); 264 k_cancel_timer(&p_ptr->timer);
270 if (p_ptr->connected) { 265 if (p_ptr->connected) {
@@ -436,14 +431,13 @@ exit:
436} 431}
437 432
438int tipc_port_reject_sections(struct tipc_port *p_ptr, struct tipc_msg *hdr, 433int tipc_port_reject_sections(struct tipc_port *p_ptr, struct tipc_msg *hdr,
439 struct iovec const *msg_sect, u32 num_sect, 434 struct iovec const *msg_sect, unsigned int len,
440 unsigned int total_len, int err) 435 int err)
441{ 436{
442 struct sk_buff *buf; 437 struct sk_buff *buf;
443 int res; 438 int res;
444 439
445 res = tipc_msg_build(hdr, msg_sect, num_sect, total_len, MAX_MSG_SIZE, 440 res = tipc_msg_build(hdr, msg_sect, len, MAX_MSG_SIZE, &buf);
446 &buf);
447 if (!buf) 441 if (!buf)
448 return res; 442 return res;
449 443
@@ -707,47 +701,36 @@ int tipc_set_portimportance(u32 ref, unsigned int imp)
707} 701}
708 702
709 703
710int tipc_publish(u32 ref, unsigned int scope, struct tipc_name_seq const *seq) 704int tipc_publish(struct tipc_port *p_ptr, unsigned int scope,
705 struct tipc_name_seq const *seq)
711{ 706{
712 struct tipc_port *p_ptr;
713 struct publication *publ; 707 struct publication *publ;
714 u32 key; 708 u32 key;
715 int res = -EINVAL;
716 709
717 p_ptr = tipc_port_lock(ref); 710 if (p_ptr->connected)
718 if (!p_ptr)
719 return -EINVAL; 711 return -EINVAL;
712 key = p_ptr->ref + p_ptr->pub_count + 1;
713 if (key == p_ptr->ref)
714 return -EADDRINUSE;
720 715
721 if (p_ptr->connected)
722 goto exit;
723 key = ref + p_ptr->pub_count + 1;
724 if (key == ref) {
725 res = -EADDRINUSE;
726 goto exit;
727 }
728 publ = tipc_nametbl_publish(seq->type, seq->lower, seq->upper, 716 publ = tipc_nametbl_publish(seq->type, seq->lower, seq->upper,
729 scope, p_ptr->ref, key); 717 scope, p_ptr->ref, key);
730 if (publ) { 718 if (publ) {
731 list_add(&publ->pport_list, &p_ptr->publications); 719 list_add(&publ->pport_list, &p_ptr->publications);
732 p_ptr->pub_count++; 720 p_ptr->pub_count++;
733 p_ptr->published = 1; 721 p_ptr->published = 1;
734 res = 0; 722 return 0;
735 } 723 }
736exit: 724 return -EINVAL;
737 tipc_port_unlock(p_ptr);
738 return res;
739} 725}
740 726
741int tipc_withdraw(u32 ref, unsigned int scope, struct tipc_name_seq const *seq) 727int tipc_withdraw(struct tipc_port *p_ptr, unsigned int scope,
728 struct tipc_name_seq const *seq)
742{ 729{
743 struct tipc_port *p_ptr;
744 struct publication *publ; 730 struct publication *publ;
745 struct publication *tpubl; 731 struct publication *tpubl;
746 int res = -EINVAL; 732 int res = -EINVAL;
747 733
748 p_ptr = tipc_port_lock(ref);
749 if (!p_ptr)
750 return -EINVAL;
751 if (!seq) { 734 if (!seq) {
752 list_for_each_entry_safe(publ, tpubl, 735 list_for_each_entry_safe(publ, tpubl,
753 &p_ptr->publications, pport_list) { 736 &p_ptr->publications, pport_list) {
@@ -774,7 +757,6 @@ int tipc_withdraw(u32 ref, unsigned int scope, struct tipc_name_seq const *seq)
774 } 757 }
775 if (list_empty(&p_ptr->publications)) 758 if (list_empty(&p_ptr->publications))
776 p_ptr->published = 0; 759 p_ptr->published = 0;
777 tipc_port_unlock(p_ptr);
778 return res; 760 return res;
779} 761}
780 762
@@ -918,15 +900,14 @@ int tipc_port_recv_msg(struct sk_buff *buf)
918 * tipc_port_recv_sections(): Concatenate and deliver sectioned 900 * tipc_port_recv_sections(): Concatenate and deliver sectioned
919 * message for this node. 901 * message for this node.
920 */ 902 */
921static int tipc_port_recv_sections(struct tipc_port *sender, unsigned int num_sect, 903static int tipc_port_recv_sections(struct tipc_port *sender,
922 struct iovec const *msg_sect, 904 struct iovec const *msg_sect,
923 unsigned int total_len) 905 unsigned int len)
924{ 906{
925 struct sk_buff *buf; 907 struct sk_buff *buf;
926 int res; 908 int res;
927 909
928 res = tipc_msg_build(&sender->phdr, msg_sect, num_sect, total_len, 910 res = tipc_msg_build(&sender->phdr, msg_sect, len, MAX_MSG_SIZE, &buf);
929 MAX_MSG_SIZE, &buf);
930 if (likely(buf)) 911 if (likely(buf))
931 tipc_port_recv_msg(buf); 912 tipc_port_recv_msg(buf);
932 return res; 913 return res;
@@ -935,8 +916,7 @@ static int tipc_port_recv_sections(struct tipc_port *sender, unsigned int num_se
935/** 916/**
936 * tipc_send - send message sections on connection 917 * tipc_send - send message sections on connection
937 */ 918 */
938int tipc_send(u32 ref, unsigned int num_sect, struct iovec const *msg_sect, 919int tipc_send(u32 ref, struct iovec const *msg_sect, unsigned int len)
939 unsigned int total_len)
940{ 920{
941 struct tipc_port *p_ptr; 921 struct tipc_port *p_ptr;
942 u32 destnode; 922 u32 destnode;
@@ -950,11 +930,10 @@ int tipc_send(u32 ref, unsigned int num_sect, struct iovec const *msg_sect,
950 if (!tipc_port_congested(p_ptr)) { 930 if (!tipc_port_congested(p_ptr)) {
951 destnode = port_peernode(p_ptr); 931 destnode = port_peernode(p_ptr);
952 if (likely(!in_own_node(destnode))) 932 if (likely(!in_own_node(destnode)))
953 res = tipc_link_send_sections_fast(p_ptr, msg_sect, num_sect, 933 res = tipc_link_send_sections_fast(p_ptr, msg_sect,
954 total_len, destnode); 934 len, destnode);
955 else 935 else
956 res = tipc_port_recv_sections(p_ptr, num_sect, msg_sect, 936 res = tipc_port_recv_sections(p_ptr, msg_sect, len);
957 total_len);
958 937
959 if (likely(res != -ELINKCONG)) { 938 if (likely(res != -ELINKCONG)) {
960 p_ptr->congested = 0; 939 p_ptr->congested = 0;
@@ -965,7 +944,7 @@ int tipc_send(u32 ref, unsigned int num_sect, struct iovec const *msg_sect,
965 } 944 }
966 if (port_unreliable(p_ptr)) { 945 if (port_unreliable(p_ptr)) {
967 p_ptr->congested = 0; 946 p_ptr->congested = 0;
968 return total_len; 947 return len;
969 } 948 }
970 return -ELINKCONG; 949 return -ELINKCONG;
971} 950}
@@ -974,8 +953,7 @@ int tipc_send(u32 ref, unsigned int num_sect, struct iovec const *msg_sect,
974 * tipc_send2name - send message sections to port name 953 * tipc_send2name - send message sections to port name
975 */ 954 */
976int tipc_send2name(u32 ref, struct tipc_name const *name, unsigned int domain, 955int tipc_send2name(u32 ref, struct tipc_name const *name, unsigned int domain,
977 unsigned int num_sect, struct iovec const *msg_sect, 956 struct iovec const *msg_sect, unsigned int len)
978 unsigned int total_len)
979{ 957{
980 struct tipc_port *p_ptr; 958 struct tipc_port *p_ptr;
981 struct tipc_msg *msg; 959 struct tipc_msg *msg;
@@ -999,36 +977,32 @@ int tipc_send2name(u32 ref, struct tipc_name const *name, unsigned int domain,
999 977
1000 if (likely(destport || destnode)) { 978 if (likely(destport || destnode)) {
1001 if (likely(in_own_node(destnode))) 979 if (likely(in_own_node(destnode)))
1002 res = tipc_port_recv_sections(p_ptr, num_sect, 980 res = tipc_port_recv_sections(p_ptr, msg_sect, len);
1003 msg_sect, total_len);
1004 else if (tipc_own_addr) 981 else if (tipc_own_addr)
1005 res = tipc_link_send_sections_fast(p_ptr, msg_sect, 982 res = tipc_link_send_sections_fast(p_ptr, msg_sect,
1006 num_sect, total_len, 983 len, destnode);
1007 destnode);
1008 else 984 else
1009 res = tipc_port_reject_sections(p_ptr, msg, msg_sect, 985 res = tipc_port_reject_sections(p_ptr, msg, msg_sect,
1010 num_sect, total_len, 986 len, TIPC_ERR_NO_NODE);
1011 TIPC_ERR_NO_NODE);
1012 if (likely(res != -ELINKCONG)) { 987 if (likely(res != -ELINKCONG)) {
1013 if (res > 0) 988 if (res > 0)
1014 p_ptr->sent++; 989 p_ptr->sent++;
1015 return res; 990 return res;
1016 } 991 }
1017 if (port_unreliable(p_ptr)) { 992 if (port_unreliable(p_ptr)) {
1018 return total_len; 993 return len;
1019 } 994 }
1020 return -ELINKCONG; 995 return -ELINKCONG;
1021 } 996 }
1022 return tipc_port_reject_sections(p_ptr, msg, msg_sect, num_sect, 997 return tipc_port_reject_sections(p_ptr, msg, msg_sect, len,
1023 total_len, TIPC_ERR_NO_NAME); 998 TIPC_ERR_NO_NAME);
1024} 999}
1025 1000
1026/** 1001/**
1027 * tipc_send2port - send message sections to port identity 1002 * tipc_send2port - send message sections to port identity
1028 */ 1003 */
1029int tipc_send2port(u32 ref, struct tipc_portid const *dest, 1004int tipc_send2port(u32 ref, struct tipc_portid const *dest,
1030 unsigned int num_sect, struct iovec const *msg_sect, 1005 struct iovec const *msg_sect, unsigned int len)
1031 unsigned int total_len)
1032{ 1006{
1033 struct tipc_port *p_ptr; 1007 struct tipc_port *p_ptr;
1034 struct tipc_msg *msg; 1008 struct tipc_msg *msg;
@@ -1046,21 +1020,20 @@ int tipc_send2port(u32 ref, struct tipc_portid const *dest,
1046 msg_set_hdr_sz(msg, BASIC_H_SIZE); 1020 msg_set_hdr_sz(msg, BASIC_H_SIZE);
1047 1021
1048 if (in_own_node(dest->node)) 1022 if (in_own_node(dest->node))
1049 res = tipc_port_recv_sections(p_ptr, num_sect, msg_sect, 1023 res = tipc_port_recv_sections(p_ptr, msg_sect, len);
1050 total_len);
1051 else if (tipc_own_addr) 1024 else if (tipc_own_addr)
1052 res = tipc_link_send_sections_fast(p_ptr, msg_sect, num_sect, 1025 res = tipc_link_send_sections_fast(p_ptr, msg_sect, len,
1053 total_len, dest->node); 1026 dest->node);
1054 else 1027 else
1055 res = tipc_port_reject_sections(p_ptr, msg, msg_sect, num_sect, 1028 res = tipc_port_reject_sections(p_ptr, msg, msg_sect, len,
1056 total_len, TIPC_ERR_NO_NODE); 1029 TIPC_ERR_NO_NODE);
1057 if (likely(res != -ELINKCONG)) { 1030 if (likely(res != -ELINKCONG)) {
1058 if (res > 0) 1031 if (res > 0)
1059 p_ptr->sent++; 1032 p_ptr->sent++;
1060 return res; 1033 return res;
1061 } 1034 }
1062 if (port_unreliable(p_ptr)) { 1035 if (port_unreliable(p_ptr)) {
1063 return total_len; 1036 return len;
1064 } 1037 }
1065 return -ELINKCONG; 1038 return -ELINKCONG;
1066} 1039}