aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--net/tipc/port.c4
-rw-r--r--net/tipc/socket.c165
-rw-r--r--net/tipc/socket.h13
3 files changed, 98 insertions, 84 deletions
diff --git a/net/tipc/port.c b/net/tipc/port.c
index ec8153f3bf3f..894c0d9fbe0f 100644
--- a/net/tipc/port.c
+++ b/net/tipc/port.c
@@ -193,7 +193,7 @@ exit:
193 193
194void tipc_port_wakeup(struct tipc_port *port) 194void tipc_port_wakeup(struct tipc_port *port)
195{ 195{
196 tipc_sk_wakeup(tipc_port_to_sk(port)); 196 tipc_sock_wakeup(tipc_port_to_sock(port));
197} 197}
198 198
199/* tipc_port_init - intiate TIPC port and lock it 199/* tipc_port_init - intiate TIPC port and lock it
@@ -776,7 +776,7 @@ int tipc_port_rcv(struct sk_buff *buf)
776 /* validate destination & pass to port, otherwise reject message */ 776 /* validate destination & pass to port, otherwise reject message */
777 p_ptr = tipc_port_lock(destport); 777 p_ptr = tipc_port_lock(destport);
778 if (likely(p_ptr)) { 778 if (likely(p_ptr)) {
779 err = tipc_sk_rcv(tipc_port_to_sk(p_ptr), buf); 779 err = tipc_sk_rcv(&tipc_port_to_sock(p_ptr)->sk, buf);
780 tipc_port_unlock(p_ptr); 780 tipc_port_unlock(p_ptr);
781 if (likely(!err)) 781 if (likely(!err))
782 return dsz; 782 return dsz;
diff --git a/net/tipc/socket.c b/net/tipc/socket.c
index 6c7198829805..9cea92ee6c82 100644
--- a/net/tipc/socket.c
+++ b/net/tipc/socket.c
@@ -139,13 +139,15 @@ static void reject_rx_queue(struct sock *sk)
139 * 139 *
140 * Returns 0 on success, errno otherwise 140 * Returns 0 on success, errno otherwise
141 */ 141 */
142static int tipc_sk_create(struct net *net, struct socket *sock, int protocol, 142static int tipc_sk_create(struct net *net, struct socket *sock,
143 int kern) 143 int protocol, int kern)
144{ 144{
145 const struct proto_ops *ops; 145 const struct proto_ops *ops;
146 socket_state state; 146 socket_state state;
147 struct sock *sk; 147 struct sock *sk;
148 struct tipc_port *tp_ptr; 148 struct tipc_sock *tsk;
149 struct tipc_port *port;
150 u32 ref;
149 151
150 /* Validate arguments */ 152 /* Validate arguments */
151 if (unlikely(protocol != 0)) 153 if (unlikely(protocol != 0))
@@ -178,8 +180,12 @@ static int tipc_sk_create(struct net *net, struct socket *sock, int protocol,
178 if (sk == NULL) 180 if (sk == NULL)
179 return -ENOMEM; 181 return -ENOMEM;
180 182
181 tp_ptr = tipc_sk_port(sk); 183 tsk = tipc_sk(sk);
182 if (!tipc_port_init(tp_ptr, TIPC_LOW_IMPORTANCE)) { 184 port = &tsk->port;
185
186 ref = tipc_port_init(port, TIPC_LOW_IMPORTANCE);
187 if (!ref) {
188 pr_warn("Socket registration failed, ref. table exhausted\n");
183 sk_free(sk); 189 sk_free(sk);
184 return -ENOMEM; 190 return -ENOMEM;
185 } 191 }
@@ -194,12 +200,12 @@ static int tipc_sk_create(struct net *net, struct socket *sock, int protocol,
194 sk->sk_data_ready = tipc_data_ready; 200 sk->sk_data_ready = tipc_data_ready;
195 sk->sk_write_space = tipc_write_space; 201 sk->sk_write_space = tipc_write_space;
196 tipc_sk(sk)->conn_timeout = CONN_TIMEOUT_DEFAULT; 202 tipc_sk(sk)->conn_timeout = CONN_TIMEOUT_DEFAULT;
197 spin_unlock_bh(tp_ptr->lock); 203 tipc_port_unlock(port);
198 204
199 if (sock->state == SS_READY) { 205 if (sock->state == SS_READY) {
200 tipc_port_set_unreturnable(tp_ptr, true); 206 tipc_port_set_unreturnable(port, true);
201 if (sock->type == SOCK_DGRAM) 207 if (sock->type == SOCK_DGRAM)
202 tipc_port_set_unreliable(tp_ptr, true); 208 tipc_port_set_unreliable(port, true);
203 } 209 }
204 return 0; 210 return 0;
205} 211}
@@ -292,7 +298,8 @@ int tipc_sock_accept_local(struct socket *sock, struct socket **newsock,
292static int tipc_release(struct socket *sock) 298static int tipc_release(struct socket *sock)
293{ 299{
294 struct sock *sk = sock->sk; 300 struct sock *sk = sock->sk;
295 struct tipc_port *tport; 301 struct tipc_sock *tsk;
302 struct tipc_port *port;
296 struct sk_buff *buf; 303 struct sk_buff *buf;
297 int res; 304 int res;
298 305
@@ -303,7 +310,8 @@ static int tipc_release(struct socket *sock)
303 if (sk == NULL) 310 if (sk == NULL)
304 return 0; 311 return 0;
305 312
306 tport = tipc_sk_port(sk); 313 tsk = tipc_sk(sk);
314 port = &tsk->port;
307 lock_sock(sk); 315 lock_sock(sk);
308 316
309 /* 317 /*
@@ -320,17 +328,16 @@ static int tipc_release(struct socket *sock)
320 if ((sock->state == SS_CONNECTING) || 328 if ((sock->state == SS_CONNECTING) ||
321 (sock->state == SS_CONNECTED)) { 329 (sock->state == SS_CONNECTED)) {
322 sock->state = SS_DISCONNECTING; 330 sock->state = SS_DISCONNECTING;
323 tipc_port_disconnect(tport->ref); 331 tipc_port_disconnect(port->ref);
324 } 332 }
325 tipc_reject_msg(buf, TIPC_ERR_NO_PORT); 333 tipc_reject_msg(buf, TIPC_ERR_NO_PORT);
326 } 334 }
327 } 335 }
328 336
329 /* 337 /* Destroy TIPC port; also disconnects an active connection and
330 * Delete TIPC port; this ensures no more messages are queued 338 * sends a 'FIN-' to peer.
331 * (also disconnects an active connection & sends a 'FIN-' to peer)
332 */ 339 */
333 tipc_port_destroy(tport); 340 tipc_port_destroy(port);
334 341
335 /* Discard any remaining (connection-based) messages in receive queue */ 342 /* Discard any remaining (connection-based) messages in receive queue */
336 __skb_queue_purge(&sk->sk_receive_queue); 343 __skb_queue_purge(&sk->sk_receive_queue);
@@ -365,12 +372,12 @@ static int tipc_bind(struct socket *sock, struct sockaddr *uaddr,
365{ 372{
366 struct sock *sk = sock->sk; 373 struct sock *sk = sock->sk;
367 struct sockaddr_tipc *addr = (struct sockaddr_tipc *)uaddr; 374 struct sockaddr_tipc *addr = (struct sockaddr_tipc *)uaddr;
368 struct tipc_port *tport = tipc_sk_port(sock->sk); 375 struct tipc_sock *tsk = tipc_sk(sk);
369 int res = -EINVAL; 376 int res = -EINVAL;
370 377
371 lock_sock(sk); 378 lock_sock(sk);
372 if (unlikely(!uaddr_len)) { 379 if (unlikely(!uaddr_len)) {
373 res = tipc_withdraw(tport, 0, NULL); 380 res = tipc_withdraw(&tsk->port, 0, NULL);
374 goto exit; 381 goto exit;
375 } 382 }
376 383
@@ -398,8 +405,8 @@ static int tipc_bind(struct socket *sock, struct sockaddr *uaddr,
398 } 405 }
399 406
400 res = (addr->scope > 0) ? 407 res = (addr->scope > 0) ?
401 tipc_publish(tport, addr->scope, &addr->addr.nameseq) : 408 tipc_publish(&tsk->port, addr->scope, &addr->addr.nameseq) :
402 tipc_withdraw(tport, -addr->scope, &addr->addr.nameseq); 409 tipc_withdraw(&tsk->port, -addr->scope, &addr->addr.nameseq);
403exit: 410exit:
404 release_sock(sk); 411 release_sock(sk);
405 return res; 412 return res;
@@ -422,17 +429,17 @@ static int tipc_getname(struct socket *sock, struct sockaddr *uaddr,
422 int *uaddr_len, int peer) 429 int *uaddr_len, int peer)
423{ 430{
424 struct sockaddr_tipc *addr = (struct sockaddr_tipc *)uaddr; 431 struct sockaddr_tipc *addr = (struct sockaddr_tipc *)uaddr;
425 struct tipc_port *port = tipc_sk_port(sock->sk); 432 struct tipc_sock *tsk = tipc_sk(sock->sk);
426 433
427 memset(addr, 0, sizeof(*addr)); 434 memset(addr, 0, sizeof(*addr));
428 if (peer) { 435 if (peer) {
429 if ((sock->state != SS_CONNECTED) && 436 if ((sock->state != SS_CONNECTED) &&
430 ((peer != 2) || (sock->state != SS_DISCONNECTING))) 437 ((peer != 2) || (sock->state != SS_DISCONNECTING)))
431 return -ENOTCONN; 438 return -ENOTCONN;
432 addr->addr.id.ref = tipc_port_peerport(port); 439 addr->addr.id.ref = tipc_port_peerport(&tsk->port);
433 addr->addr.id.node = tipc_port_peernode(port); 440 addr->addr.id.node = tipc_port_peernode(&tsk->port);
434 } else { 441 } else {
435 addr->addr.id.ref = port->ref; 442 addr->addr.id.ref = tsk->port.ref;
436 addr->addr.id.node = tipc_own_addr; 443 addr->addr.id.node = tipc_own_addr;
437 } 444 }
438 445
@@ -489,18 +496,19 @@ static unsigned int tipc_poll(struct file *file, struct socket *sock,
489 poll_table *wait) 496 poll_table *wait)
490{ 497{
491 struct sock *sk = sock->sk; 498 struct sock *sk = sock->sk;
499 struct tipc_sock *tsk = tipc_sk(sk);
492 u32 mask = 0; 500 u32 mask = 0;
493 501
494 sock_poll_wait(file, sk_sleep(sk), wait); 502 sock_poll_wait(file, sk_sleep(sk), wait);
495 503
496 switch ((int)sock->state) { 504 switch ((int)sock->state) {
497 case SS_UNCONNECTED: 505 case SS_UNCONNECTED:
498 if (!tipc_sk_port(sk)->congested) 506 if (!tsk->port.congested)
499 mask |= POLLOUT; 507 mask |= POLLOUT;
500 break; 508 break;
501 case SS_READY: 509 case SS_READY:
502 case SS_CONNECTED: 510 case SS_CONNECTED:
503 if (!tipc_sk_port(sk)->congested) 511 if (!tsk->port.congested)
504 mask |= POLLOUT; 512 mask |= POLLOUT;
505 /* fall thru' */ 513 /* fall thru' */
506 case SS_CONNECTING: 514 case SS_CONNECTING:
@@ -550,7 +558,7 @@ static int dest_name_check(struct sockaddr_tipc *dest, struct msghdr *m)
550static int tipc_wait_for_sndmsg(struct socket *sock, long *timeo_p) 558static int tipc_wait_for_sndmsg(struct socket *sock, long *timeo_p)
551{ 559{
552 struct sock *sk = sock->sk; 560 struct sock *sk = sock->sk;
553 struct tipc_port *tport = tipc_sk_port(sk); 561 struct tipc_sock *tsk = tipc_sk(sk);
554 DEFINE_WAIT(wait); 562 DEFINE_WAIT(wait);
555 int done; 563 int done;
556 564
@@ -566,12 +574,13 @@ static int tipc_wait_for_sndmsg(struct socket *sock, long *timeo_p)
566 return sock_intr_errno(*timeo_p); 574 return sock_intr_errno(*timeo_p);
567 575
568 prepare_to_wait(sk_sleep(sk), &wait, TASK_INTERRUPTIBLE); 576 prepare_to_wait(sk_sleep(sk), &wait, TASK_INTERRUPTIBLE);
569 done = sk_wait_event(sk, timeo_p, !tport->congested); 577 done = sk_wait_event(sk, timeo_p, !tsk->port.congested);
570 finish_wait(sk_sleep(sk), &wait); 578 finish_wait(sk_sleep(sk), &wait);
571 } while (!done); 579 } while (!done);
572 return 0; 580 return 0;
573} 581}
574 582
583
575/** 584/**
576 * tipc_sendmsg - send message in connectionless manner 585 * tipc_sendmsg - send message in connectionless manner
577 * @iocb: if NULL, indicates that socket lock is already held 586 * @iocb: if NULL, indicates that socket lock is already held
@@ -590,10 +599,11 @@ static int tipc_sendmsg(struct kiocb *iocb, struct socket *sock,
590 struct msghdr *m, size_t total_len) 599 struct msghdr *m, size_t total_len)
591{ 600{
592 struct sock *sk = sock->sk; 601 struct sock *sk = sock->sk;
593 struct tipc_port *tport = tipc_sk_port(sk); 602 struct tipc_sock *tsk = tipc_sk(sk);
594 DECLARE_SOCKADDR(struct sockaddr_tipc *, dest, m->msg_name); 603 DECLARE_SOCKADDR(struct sockaddr_tipc *, dest, m->msg_name);
595 int needs_conn; 604 int needs_conn;
596 long timeo; 605 long timeo;
606 u32 ref = tsk->port.ref;
597 int res = -EINVAL; 607 int res = -EINVAL;
598 608
599 if (unlikely(!dest)) 609 if (unlikely(!dest))
@@ -617,13 +627,13 @@ static int tipc_sendmsg(struct kiocb *iocb, struct socket *sock,
617 res = -EISCONN; 627 res = -EISCONN;
618 goto exit; 628 goto exit;
619 } 629 }
620 if (tport->published) { 630 if (tsk->port.published) {
621 res = -EOPNOTSUPP; 631 res = -EOPNOTSUPP;
622 goto exit; 632 goto exit;
623 } 633 }
624 if (dest->addrtype == TIPC_ADDR_NAME) { 634 if (dest->addrtype == TIPC_ADDR_NAME) {
625 tport->conn_type = dest->addr.name.name.type; 635 tsk->port.conn_type = dest->addr.name.name.type;
626 tport->conn_instance = dest->addr.name.name.instance; 636 tsk->port.conn_instance = dest->addr.name.name.instance;
627 } 637 }
628 638
629 /* Abort any pending connection attempts (very unlikely) */ 639 /* Abort any pending connection attempts (very unlikely) */
@@ -636,13 +646,13 @@ static int tipc_sendmsg(struct kiocb *iocb, struct socket *sock,
636 res = dest_name_check(dest, m); 646 res = dest_name_check(dest, m);
637 if (res) 647 if (res)
638 break; 648 break;
639 res = tipc_send2name(tport->ref, 649 res = tipc_send2name(ref,
640 &dest->addr.name.name, 650 &dest->addr.name.name,
641 dest->addr.name.domain, 651 dest->addr.name.domain,
642 m->msg_iov, 652 m->msg_iov,
643 total_len); 653 total_len);
644 } else if (dest->addrtype == TIPC_ADDR_ID) { 654 } else if (dest->addrtype == TIPC_ADDR_ID) {
645 res = tipc_send2port(tport->ref, 655 res = tipc_send2port(ref,
646 &dest->addr.id, 656 &dest->addr.id,
647 m->msg_iov, 657 m->msg_iov,
648 total_len); 658 total_len);
@@ -654,7 +664,7 @@ static int tipc_sendmsg(struct kiocb *iocb, struct socket *sock,
654 res = dest_name_check(dest, m); 664 res = dest_name_check(dest, m);
655 if (res) 665 if (res)
656 break; 666 break;
657 res = tipc_port_mcast_xmit(tport->ref, 667 res = tipc_port_mcast_xmit(ref,
658 &dest->addr.nameseq, 668 &dest->addr.nameseq,
659 m->msg_iov, 669 m->msg_iov,
660 total_len); 670 total_len);
@@ -678,7 +688,8 @@ exit:
678static int tipc_wait_for_sndpkt(struct socket *sock, long *timeo_p) 688static int tipc_wait_for_sndpkt(struct socket *sock, long *timeo_p)
679{ 689{
680 struct sock *sk = sock->sk; 690 struct sock *sk = sock->sk;
681 struct tipc_port *tport = tipc_sk_port(sk); 691 struct tipc_sock *tsk = tipc_sk(sk);
692 struct tipc_port *port = &tsk->port;
682 DEFINE_WAIT(wait); 693 DEFINE_WAIT(wait);
683 int done; 694 int done;
684 695
@@ -697,7 +708,7 @@ static int tipc_wait_for_sndpkt(struct socket *sock, long *timeo_p)
697 708
698 prepare_to_wait(sk_sleep(sk), &wait, TASK_INTERRUPTIBLE); 709 prepare_to_wait(sk_sleep(sk), &wait, TASK_INTERRUPTIBLE);
699 done = sk_wait_event(sk, timeo_p, 710 done = sk_wait_event(sk, timeo_p,
700 (!tport->congested || !tport->connected)); 711 (!port->congested || !port->connected));
701 finish_wait(sk_sleep(sk), &wait); 712 finish_wait(sk_sleep(sk), &wait);
702 } while (!done); 713 } while (!done);
703 return 0; 714 return 0;
@@ -718,7 +729,7 @@ static int tipc_send_packet(struct kiocb *iocb, struct socket *sock,
718 struct msghdr *m, size_t total_len) 729 struct msghdr *m, size_t total_len)
719{ 730{
720 struct sock *sk = sock->sk; 731 struct sock *sk = sock->sk;
721 struct tipc_port *tport = tipc_sk_port(sk); 732 struct tipc_sock *tsk = tipc_sk(sk);
722 DECLARE_SOCKADDR(struct sockaddr_tipc *, dest, m->msg_name); 733 DECLARE_SOCKADDR(struct sockaddr_tipc *, dest, m->msg_name);
723 int res = -EINVAL; 734 int res = -EINVAL;
724 long timeo; 735 long timeo;
@@ -743,7 +754,7 @@ static int tipc_send_packet(struct kiocb *iocb, struct socket *sock,
743 754
744 timeo = sock_sndtimeo(sk, m->msg_flags & MSG_DONTWAIT); 755 timeo = sock_sndtimeo(sk, m->msg_flags & MSG_DONTWAIT);
745 do { 756 do {
746 res = tipc_send(tport->ref, m->msg_iov, total_len); 757 res = tipc_send(tsk->port.ref, m->msg_iov, total_len);
747 if (likely(res != -ELINKCONG)) 758 if (likely(res != -ELINKCONG))
748 break; 759 break;
749 res = tipc_wait_for_sndpkt(sock, &timeo); 760 res = tipc_wait_for_sndpkt(sock, &timeo);
@@ -772,7 +783,7 @@ static int tipc_send_stream(struct kiocb *iocb, struct socket *sock,
772 struct msghdr *m, size_t total_len) 783 struct msghdr *m, size_t total_len)
773{ 784{
774 struct sock *sk = sock->sk; 785 struct sock *sk = sock->sk;
775 struct tipc_port *tport = tipc_sk_port(sk); 786 struct tipc_sock *tsk = tipc_sk(sk);
776 struct msghdr my_msg; 787 struct msghdr my_msg;
777 struct iovec my_iov; 788 struct iovec my_iov;
778 struct iovec *curr_iov; 789 struct iovec *curr_iov;
@@ -820,14 +831,14 @@ static int tipc_send_stream(struct kiocb *iocb, struct socket *sock,
820 my_msg.msg_name = NULL; 831 my_msg.msg_name = NULL;
821 bytes_sent = 0; 832 bytes_sent = 0;
822 833
823 hdr_size = msg_hdr_sz(&tport->phdr); 834 hdr_size = msg_hdr_sz(&tsk->port.phdr);
824 835
825 while (curr_iovlen--) { 836 while (curr_iovlen--) {
826 curr_start = curr_iov->iov_base; 837 curr_start = curr_iov->iov_base;
827 curr_left = curr_iov->iov_len; 838 curr_left = curr_iov->iov_len;
828 839
829 while (curr_left) { 840 while (curr_left) {
830 bytes_to_send = tport->max_pkt - hdr_size; 841 bytes_to_send = tsk->port.max_pkt - hdr_size;
831 if (bytes_to_send > TIPC_MAX_USER_MSG_SIZE) 842 if (bytes_to_send > TIPC_MAX_USER_MSG_SIZE)
832 bytes_to_send = TIPC_MAX_USER_MSG_SIZE; 843 bytes_to_send = TIPC_MAX_USER_MSG_SIZE;
833 if (curr_left < bytes_to_send) 844 if (curr_left < bytes_to_send)
@@ -856,28 +867,29 @@ exit:
856 867
857/** 868/**
858 * auto_connect - complete connection setup to a remote port 869 * auto_connect - complete connection setup to a remote port
859 * @sock: socket structure 870 * @tsk: tipc socket structure
860 * @msg: peer's response message 871 * @msg: peer's response message
861 * 872 *
862 * Returns 0 on success, errno otherwise 873 * Returns 0 on success, errno otherwise
863 */ 874 */
864static int auto_connect(struct socket *sock, struct tipc_msg *msg) 875static int auto_connect(struct tipc_sock *tsk, struct tipc_msg *msg)
865{ 876{
866 struct tipc_port *p_ptr = tipc_sk_port(sock->sk); 877 struct tipc_port *port = &tsk->port;
878 struct socket *sock = tsk->sk.sk_socket;
867 struct tipc_portid peer; 879 struct tipc_portid peer;
868 880
869 peer.ref = msg_origport(msg); 881 peer.ref = msg_origport(msg);
870 peer.node = msg_orignode(msg); 882 peer.node = msg_orignode(msg);
871 883
872 p_ptr = tipc_port_deref(p_ptr->ref); 884 port = tipc_port_deref(port->ref);
873 if (!p_ptr) 885 if (!port)
874 return -EINVAL; 886 return -EINVAL;
875 887
876 __tipc_port_connect(p_ptr->ref, p_ptr, &peer); 888 __tipc_port_connect(port->ref, port, &peer);
877 889
878 if (msg_importance(msg) > TIPC_CRITICAL_IMPORTANCE) 890 if (msg_importance(msg) > TIPC_CRITICAL_IMPORTANCE)
879 return -EINVAL; 891 return -EINVAL;
880 msg_set_importance(&p_ptr->phdr, (u32)msg_importance(msg)); 892 msg_set_importance(&port->phdr, (u32)msg_importance(msg));
881 sock->state = SS_CONNECTED; 893 sock->state = SS_CONNECTED;
882 return 0; 894 return 0;
883} 895}
@@ -1023,7 +1035,8 @@ static int tipc_recvmsg(struct kiocb *iocb, struct socket *sock,
1023 struct msghdr *m, size_t buf_len, int flags) 1035 struct msghdr *m, size_t buf_len, int flags)
1024{ 1036{
1025 struct sock *sk = sock->sk; 1037 struct sock *sk = sock->sk;
1026 struct tipc_port *tport = tipc_sk_port(sk); 1038 struct tipc_sock *tsk = tipc_sk(sk);
1039 struct tipc_port *port = &tsk->port;
1027 struct sk_buff *buf; 1040 struct sk_buff *buf;
1028 struct tipc_msg *msg; 1041 struct tipc_msg *msg;
1029 long timeo; 1042 long timeo;
@@ -1066,7 +1079,7 @@ restart:
1066 set_orig_addr(m, msg); 1079 set_orig_addr(m, msg);
1067 1080
1068 /* Capture ancillary data (optional) */ 1081 /* Capture ancillary data (optional) */
1069 res = anc_data_recv(m, msg, tport); 1082 res = anc_data_recv(m, msg, port);
1070 if (res) 1083 if (res)
1071 goto exit; 1084 goto exit;
1072 1085
@@ -1092,8 +1105,8 @@ restart:
1092 /* Consume received message (optional) */ 1105 /* Consume received message (optional) */
1093 if (likely(!(flags & MSG_PEEK))) { 1106 if (likely(!(flags & MSG_PEEK))) {
1094 if ((sock->state != SS_READY) && 1107 if ((sock->state != SS_READY) &&
1095 (++tport->conn_unacked >= TIPC_FLOW_CONTROL_WIN)) 1108 (++port->conn_unacked >= TIPC_FLOW_CONTROL_WIN))
1096 tipc_acknowledge(tport->ref, tport->conn_unacked); 1109 tipc_acknowledge(port->ref, port->conn_unacked);
1097 advance_rx_queue(sk); 1110 advance_rx_queue(sk);
1098 } 1111 }
1099exit: 1112exit:
@@ -1117,7 +1130,8 @@ static int tipc_recv_stream(struct kiocb *iocb, struct socket *sock,
1117 struct msghdr *m, size_t buf_len, int flags) 1130 struct msghdr *m, size_t buf_len, int flags)
1118{ 1131{
1119 struct sock *sk = sock->sk; 1132 struct sock *sk = sock->sk;
1120 struct tipc_port *tport = tipc_sk_port(sk); 1133 struct tipc_sock *tsk = tipc_sk(sk);
1134 struct tipc_port *port = &tsk->port;
1121 struct sk_buff *buf; 1135 struct sk_buff *buf;
1122 struct tipc_msg *msg; 1136 struct tipc_msg *msg;
1123 long timeo; 1137 long timeo;
@@ -1162,7 +1176,7 @@ restart:
1162 /* Optionally capture sender's address & ancillary data of first msg */ 1176 /* Optionally capture sender's address & ancillary data of first msg */
1163 if (sz_copied == 0) { 1177 if (sz_copied == 0) {
1164 set_orig_addr(m, msg); 1178 set_orig_addr(m, msg);
1165 res = anc_data_recv(m, msg, tport); 1179 res = anc_data_recv(m, msg, port);
1166 if (res) 1180 if (res)
1167 goto exit; 1181 goto exit;
1168 } 1182 }
@@ -1200,8 +1214,8 @@ restart:
1200 1214
1201 /* Consume received message (optional) */ 1215 /* Consume received message (optional) */
1202 if (likely(!(flags & MSG_PEEK))) { 1216 if (likely(!(flags & MSG_PEEK))) {
1203 if (unlikely(++tport->conn_unacked >= TIPC_FLOW_CONTROL_WIN)) 1217 if (unlikely(++port->conn_unacked >= TIPC_FLOW_CONTROL_WIN))
1204 tipc_acknowledge(tport->ref, tport->conn_unacked); 1218 tipc_acknowledge(port->ref, port->conn_unacked);
1205 advance_rx_queue(sk); 1219 advance_rx_queue(sk);
1206 } 1220 }
1207 1221
@@ -1253,15 +1267,16 @@ static void tipc_data_ready(struct sock *sk, int len)
1253 1267
1254/** 1268/**
1255 * filter_connect - Handle all incoming messages for a connection-based socket 1269 * filter_connect - Handle all incoming messages for a connection-based socket
1256 * @port: TIPC port 1270 * @tsk: TIPC socket
1257 * @msg: message 1271 * @msg: message
1258 * 1272 *
1259 * Returns TIPC error status code and socket error status code 1273 * Returns TIPC error status code and socket error status code
1260 * once it encounters some errors 1274 * once it encounters some errors
1261 */ 1275 */
1262static u32 filter_connect(struct tipc_port *port, struct sk_buff **buf) 1276static u32 filter_connect(struct tipc_sock *tsk, struct sk_buff **buf)
1263{ 1277{
1264 struct sock *sk = tipc_port_to_sk(port); 1278 struct sock *sk = &tsk->sk;
1279 struct tipc_port *port = &tsk->port;
1265 struct socket *sock = sk->sk_socket; 1280 struct socket *sock = sk->sk_socket;
1266 struct tipc_msg *msg = buf_msg(*buf); 1281 struct tipc_msg *msg = buf_msg(*buf);
1267 1282
@@ -1294,7 +1309,7 @@ static u32 filter_connect(struct tipc_port *port, struct sk_buff **buf)
1294 if (unlikely(!msg_connected(msg))) 1309 if (unlikely(!msg_connected(msg)))
1295 break; 1310 break;
1296 1311
1297 res = auto_connect(sock, msg); 1312 res = auto_connect(tsk, msg);
1298 if (res) { 1313 if (res) {
1299 sock->state = SS_DISCONNECTING; 1314 sock->state = SS_DISCONNECTING;
1300 sk->sk_err = -res; 1315 sk->sk_err = -res;
@@ -1373,6 +1388,7 @@ static unsigned int rcvbuf_limit(struct sock *sk, struct sk_buff *buf)
1373static u32 filter_rcv(struct sock *sk, struct sk_buff *buf) 1388static u32 filter_rcv(struct sock *sk, struct sk_buff *buf)
1374{ 1389{
1375 struct socket *sock = sk->sk_socket; 1390 struct socket *sock = sk->sk_socket;
1391 struct tipc_sock *tsk = tipc_sk(sk);
1376 struct tipc_msg *msg = buf_msg(buf); 1392 struct tipc_msg *msg = buf_msg(buf);
1377 unsigned int limit = rcvbuf_limit(sk, buf); 1393 unsigned int limit = rcvbuf_limit(sk, buf);
1378 u32 res = TIPC_OK; 1394 u32 res = TIPC_OK;
@@ -1385,7 +1401,7 @@ static u32 filter_rcv(struct sock *sk, struct sk_buff *buf)
1385 if (msg_connected(msg)) 1401 if (msg_connected(msg))
1386 return TIPC_ERR_NO_PORT; 1402 return TIPC_ERR_NO_PORT;
1387 } else { 1403 } else {
1388 res = filter_connect(tipc_sk_port(sk), &buf); 1404 res = filter_connect(tsk, &buf);
1389 if (res != TIPC_OK || buf == NULL) 1405 if (res != TIPC_OK || buf == NULL)
1390 return res; 1406 return res;
1391 } 1407 }
@@ -1656,7 +1672,7 @@ static int tipc_accept(struct socket *sock, struct socket *new_sock, int flags)
1656 goto exit; 1672 goto exit;
1657 1673
1658 new_sk = new_sock->sk; 1674 new_sk = new_sock->sk;
1659 new_port = tipc_sk_port(new_sk); 1675 new_port = &tipc_sk(new_sk)->port;
1660 new_ref = new_port->ref; 1676 new_ref = new_port->ref;
1661 msg = buf_msg(buf); 1677 msg = buf_msg(buf);
1662 1678
@@ -1713,7 +1729,8 @@ exit:
1713static int tipc_shutdown(struct socket *sock, int how) 1729static int tipc_shutdown(struct socket *sock, int how)
1714{ 1730{
1715 struct sock *sk = sock->sk; 1731 struct sock *sk = sock->sk;
1716 struct tipc_port *tport = tipc_sk_port(sk); 1732 struct tipc_sock *tsk = tipc_sk(sk);
1733 struct tipc_port *port = &tsk->port;
1717 struct sk_buff *buf; 1734 struct sk_buff *buf;
1718 int res; 1735 int res;
1719 1736
@@ -1734,10 +1751,10 @@ restart:
1734 kfree_skb(buf); 1751 kfree_skb(buf);
1735 goto restart; 1752 goto restart;
1736 } 1753 }
1737 tipc_port_disconnect(tport->ref); 1754 tipc_port_disconnect(port->ref);
1738 tipc_reject_msg(buf, TIPC_CONN_SHUTDOWN); 1755 tipc_reject_msg(buf, TIPC_CONN_SHUTDOWN);
1739 } else { 1756 } else {
1740 tipc_port_shutdown(tport->ref); 1757 tipc_port_shutdown(port->ref);
1741 } 1758 }
1742 1759
1743 sock->state = SS_DISCONNECTING; 1760 sock->state = SS_DISCONNECTING;
@@ -1779,7 +1796,8 @@ static int tipc_setsockopt(struct socket *sock, int lvl, int opt,
1779 char __user *ov, unsigned int ol) 1796 char __user *ov, unsigned int ol)
1780{ 1797{
1781 struct sock *sk = sock->sk; 1798 struct sock *sk = sock->sk;
1782 struct tipc_port *tport = tipc_sk_port(sk); 1799 struct tipc_sock *tsk = tipc_sk(sk);
1800 struct tipc_port *port = &tsk->port;
1783 u32 value; 1801 u32 value;
1784 int res; 1802 int res;
1785 1803
@@ -1797,16 +1815,16 @@ static int tipc_setsockopt(struct socket *sock, int lvl, int opt,
1797 1815
1798 switch (opt) { 1816 switch (opt) {
1799 case TIPC_IMPORTANCE: 1817 case TIPC_IMPORTANCE:
1800 tipc_port_set_importance(tport, value); 1818 tipc_port_set_importance(port, value);
1801 break; 1819 break;
1802 case TIPC_SRC_DROPPABLE: 1820 case TIPC_SRC_DROPPABLE:
1803 if (sock->type != SOCK_STREAM) 1821 if (sock->type != SOCK_STREAM)
1804 tipc_port_set_unreliable(tport, value); 1822 tipc_port_set_unreliable(port, value);
1805 else 1823 else
1806 res = -ENOPROTOOPT; 1824 res = -ENOPROTOOPT;
1807 break; 1825 break;
1808 case TIPC_DEST_DROPPABLE: 1826 case TIPC_DEST_DROPPABLE:
1809 tipc_port_set_unreturnable(tport, value); 1827 tipc_port_set_unreturnable(port, value);
1810 break; 1828 break;
1811 case TIPC_CONN_TIMEOUT: 1829 case TIPC_CONN_TIMEOUT:
1812 tipc_sk(sk)->conn_timeout = value; 1830 tipc_sk(sk)->conn_timeout = value;
@@ -1838,7 +1856,8 @@ static int tipc_getsockopt(struct socket *sock, int lvl, int opt,
1838 char __user *ov, int __user *ol) 1856 char __user *ov, int __user *ol)
1839{ 1857{
1840 struct sock *sk = sock->sk; 1858 struct sock *sk = sock->sk;
1841 struct tipc_port *tport = tipc_sk_port(sk); 1859 struct tipc_sock *tsk = tipc_sk(sk);
1860 struct tipc_port *port = &tsk->port;
1842 int len; 1861 int len;
1843 u32 value; 1862 u32 value;
1844 int res; 1863 int res;
@@ -1855,13 +1874,13 @@ static int tipc_getsockopt(struct socket *sock, int lvl, int opt,
1855 1874
1856 switch (opt) { 1875 switch (opt) {
1857 case TIPC_IMPORTANCE: 1876 case TIPC_IMPORTANCE:
1858 value = tipc_port_importance(tport); 1877 value = tipc_port_importance(port);
1859 break; 1878 break;
1860 case TIPC_SRC_DROPPABLE: 1879 case TIPC_SRC_DROPPABLE:
1861 value = tipc_port_unreliable(tport); 1880 value = tipc_port_unreliable(port);
1862 break; 1881 break;
1863 case TIPC_DEST_DROPPABLE: 1882 case TIPC_DEST_DROPPABLE:
1864 value = tipc_port_unreturnable(tport); 1883 value = tipc_port_unreturnable(port);
1865 break; 1884 break;
1866 case TIPC_CONN_TIMEOUT: 1885 case TIPC_CONN_TIMEOUT:
1867 value = tipc_sk(sk)->conn_timeout; 1886 value = tipc_sk(sk)->conn_timeout;
diff --git a/net/tipc/socket.h b/net/tipc/socket.h
index a02d0bb0e2ab..74e5c7f195a6 100644
--- a/net/tipc/socket.h
+++ b/net/tipc/socket.h
@@ -57,19 +57,14 @@ static inline struct tipc_sock *tipc_sk(const struct sock *sk)
57 return container_of(sk, struct tipc_sock, sk); 57 return container_of(sk, struct tipc_sock, sk);
58} 58}
59 59
60static inline struct tipc_port *tipc_sk_port(const struct sock *sk) 60static inline struct tipc_sock *tipc_port_to_sock(const struct tipc_port *port)
61{ 61{
62 return &(tipc_sk(sk)->port); 62 return container_of(port, struct tipc_sock, port);
63} 63}
64 64
65static inline struct sock *tipc_port_to_sk(const struct tipc_port *port) 65static inline void tipc_sock_wakeup(struct tipc_sock *tsk)
66{ 66{
67 return &(container_of(port, struct tipc_sock, port))->sk; 67 tsk->sk.sk_write_space(&tsk->sk);
68}
69
70static inline void tipc_sk_wakeup(struct sock *sk)
71{
72 sk->sk_write_space(sk);
73} 68}
74 69
75u32 tipc_sk_rcv(struct sock *sk, struct sk_buff *buf); 70u32 tipc_sk_rcv(struct sock *sk, struct sk_buff *buf);