aboutsummaryrefslogtreecommitdiffstats
path: root/net/tipc/socket.c
diff options
context:
space:
mode:
Diffstat (limited to 'net/tipc/socket.c')
-rw-r--r--net/tipc/socket.c418
1 files changed, 202 insertions, 216 deletions
diff --git a/net/tipc/socket.c b/net/tipc/socket.c
index a4cf274455aa..29b7f26a12cf 100644
--- a/net/tipc/socket.c
+++ b/net/tipc/socket.c
@@ -1,7 +1,7 @@
1/* 1/*
2 * net/tipc/socket.c: TIPC socket API 2 * net/tipc/socket.c: TIPC socket API
3 * 3 *
4 * Copyright (c) 2001-2007, 2012 Ericsson AB 4 * Copyright (c) 2001-2007, 2012-2014, Ericsson AB
5 * Copyright (c) 2004-2008, 2010-2013, Wind River Systems 5 * Copyright (c) 2004-2008, 2010-2013, Wind River Systems
6 * All rights reserved. 6 * All rights reserved.
7 * 7 *
@@ -38,30 +38,17 @@
38#include "port.h" 38#include "port.h"
39 39
40#include <linux/export.h> 40#include <linux/export.h>
41#include <net/sock.h>
42 41
43#define SS_LISTENING -1 /* socket is listening */ 42#define SS_LISTENING -1 /* socket is listening */
44#define SS_READY -2 /* socket is connectionless */ 43#define SS_READY -2 /* socket is connectionless */
45 44
46#define CONN_TIMEOUT_DEFAULT 8000 /* default connect timeout = 8s */ 45#define CONN_TIMEOUT_DEFAULT 8000 /* default connect timeout = 8s */
47 46
48struct tipc_sock {
49 struct sock sk;
50 struct tipc_port *p;
51 struct tipc_portid peer_name;
52 unsigned int conn_timeout;
53};
54
55#define tipc_sk(sk) ((struct tipc_sock *)(sk))
56#define tipc_sk_port(sk) (tipc_sk(sk)->p)
57
58static int backlog_rcv(struct sock *sk, struct sk_buff *skb); 47static int backlog_rcv(struct sock *sk, struct sk_buff *skb);
59static u32 dispatch(struct tipc_port *tport, struct sk_buff *buf);
60static void wakeupdispatch(struct tipc_port *tport);
61static void tipc_data_ready(struct sock *sk, int len); 48static void tipc_data_ready(struct sock *sk, int len);
62static void tipc_write_space(struct sock *sk); 49static void tipc_write_space(struct sock *sk);
63static int release(struct socket *sock); 50static int tipc_release(struct socket *sock);
64static int accept(struct socket *sock, struct socket *new_sock, int flags); 51static int tipc_accept(struct socket *sock, struct socket *new_sock, int flags);
65 52
66static const struct proto_ops packet_ops; 53static const struct proto_ops packet_ops;
67static const struct proto_ops stream_ops; 54static const struct proto_ops stream_ops;
@@ -115,6 +102,8 @@ static struct proto tipc_proto_kern;
115 * - port reference 102 * - port reference
116 */ 103 */
117 104
105#include "socket.h"
106
118/** 107/**
119 * advance_rx_queue - discard first buffer in socket receive queue 108 * advance_rx_queue - discard first buffer in socket receive queue
120 * 109 *
@@ -150,13 +139,15 @@ static void reject_rx_queue(struct sock *sk)
150 * 139 *
151 * Returns 0 on success, errno otherwise 140 * Returns 0 on success, errno otherwise
152 */ 141 */
153static int tipc_sk_create(struct net *net, struct socket *sock, int protocol, 142static int tipc_sk_create(struct net *net, struct socket *sock,
154 int kern) 143 int protocol, int kern)
155{ 144{
156 const struct proto_ops *ops; 145 const struct proto_ops *ops;
157 socket_state state; 146 socket_state state;
158 struct sock *sk; 147 struct sock *sk;
159 struct tipc_port *tp_ptr; 148 struct tipc_sock *tsk;
149 struct tipc_port *port;
150 u32 ref;
160 151
161 /* Validate arguments */ 152 /* Validate arguments */
162 if (unlikely(protocol != 0)) 153 if (unlikely(protocol != 0))
@@ -189,10 +180,12 @@ static int tipc_sk_create(struct net *net, struct socket *sock, int protocol,
189 if (sk == NULL) 180 if (sk == NULL)
190 return -ENOMEM; 181 return -ENOMEM;
191 182
192 /* Allocate TIPC port for socket to use */ 183 tsk = tipc_sk(sk);
193 tp_ptr = tipc_createport(sk, &dispatch, &wakeupdispatch, 184 port = &tsk->port;
194 TIPC_LOW_IMPORTANCE); 185
195 if (unlikely(!tp_ptr)) { 186 ref = tipc_port_init(port, TIPC_LOW_IMPORTANCE);
187 if (!ref) {
188 pr_warn("Socket registration failed, ref. table exhausted\n");
196 sk_free(sk); 189 sk_free(sk);
197 return -ENOMEM; 190 return -ENOMEM;
198 } 191 }
@@ -206,17 +199,14 @@ static int tipc_sk_create(struct net *net, struct socket *sock, int protocol,
206 sk->sk_rcvbuf = sysctl_tipc_rmem[1]; 199 sk->sk_rcvbuf = sysctl_tipc_rmem[1];
207 sk->sk_data_ready = tipc_data_ready; 200 sk->sk_data_ready = tipc_data_ready;
208 sk->sk_write_space = tipc_write_space; 201 sk->sk_write_space = tipc_write_space;
209 tipc_sk(sk)->p = tp_ptr;
210 tipc_sk(sk)->conn_timeout = CONN_TIMEOUT_DEFAULT; 202 tipc_sk(sk)->conn_timeout = CONN_TIMEOUT_DEFAULT;
211 203 tipc_port_unlock(port);
212 spin_unlock_bh(tp_ptr->lock);
213 204
214 if (sock->state == SS_READY) { 205 if (sock->state == SS_READY) {
215 tipc_set_portunreturnable(tp_ptr->ref, 1); 206 tipc_port_set_unreturnable(port, true);
216 if (sock->type == SOCK_DGRAM) 207 if (sock->type == SOCK_DGRAM)
217 tipc_set_portunreliable(tp_ptr->ref, 1); 208 tipc_port_set_unreliable(port, true);
218 } 209 }
219
220 return 0; 210 return 0;
221} 211}
222 212
@@ -254,7 +244,7 @@ int tipc_sock_create_local(int type, struct socket **res)
254 */ 244 */
255void tipc_sock_release_local(struct socket *sock) 245void tipc_sock_release_local(struct socket *sock)
256{ 246{
257 release(sock); 247 tipc_release(sock);
258 sock->ops = NULL; 248 sock->ops = NULL;
259 sock_release(sock); 249 sock_release(sock);
260} 250}
@@ -280,7 +270,7 @@ int tipc_sock_accept_local(struct socket *sock, struct socket **newsock,
280 if (ret < 0) 270 if (ret < 0)
281 return ret; 271 return ret;
282 272
283 ret = accept(sock, *newsock, flags); 273 ret = tipc_accept(sock, *newsock, flags);
284 if (ret < 0) { 274 if (ret < 0) {
285 sock_release(*newsock); 275 sock_release(*newsock);
286 return ret; 276 return ret;
@@ -290,7 +280,7 @@ int tipc_sock_accept_local(struct socket *sock, struct socket **newsock,
290} 280}
291 281
292/** 282/**
293 * release - destroy a TIPC socket 283 * tipc_release - destroy a TIPC socket
294 * @sock: socket to destroy 284 * @sock: socket to destroy
295 * 285 *
296 * This routine cleans up any messages that are still queued on the socket. 286 * This routine cleans up any messages that are still queued on the socket.
@@ -305,10 +295,11 @@ int tipc_sock_accept_local(struct socket *sock, struct socket **newsock,
305 * 295 *
306 * Returns 0 on success, errno otherwise 296 * Returns 0 on success, errno otherwise
307 */ 297 */
308static int release(struct socket *sock) 298static int tipc_release(struct socket *sock)
309{ 299{
310 struct sock *sk = sock->sk; 300 struct sock *sk = sock->sk;
311 struct tipc_port *tport; 301 struct tipc_sock *tsk;
302 struct tipc_port *port;
312 struct sk_buff *buf; 303 struct sk_buff *buf;
313 int res; 304 int res;
314 305
@@ -319,7 +310,8 @@ static int release(struct socket *sock)
319 if (sk == NULL) 310 if (sk == NULL)
320 return 0; 311 return 0;
321 312
322 tport = tipc_sk_port(sk); 313 tsk = tipc_sk(sk);
314 port = &tsk->port;
323 lock_sock(sk); 315 lock_sock(sk);
324 316
325 /* 317 /*
@@ -336,17 +328,16 @@ static int release(struct socket *sock)
336 if ((sock->state == SS_CONNECTING) || 328 if ((sock->state == SS_CONNECTING) ||
337 (sock->state == SS_CONNECTED)) { 329 (sock->state == SS_CONNECTED)) {
338 sock->state = SS_DISCONNECTING; 330 sock->state = SS_DISCONNECTING;
339 tipc_disconnect(tport->ref); 331 tipc_port_disconnect(port->ref);
340 } 332 }
341 tipc_reject_msg(buf, TIPC_ERR_NO_PORT); 333 tipc_reject_msg(buf, TIPC_ERR_NO_PORT);
342 } 334 }
343 } 335 }
344 336
345 /* 337 /* Destroy TIPC port; also disconnects an active connection and
346 * Delete TIPC port; this ensures no more messages are queued 338 * sends a 'FIN-' to peer.
347 * (also disconnects an active connection & sends a 'FIN-' to peer)
348 */ 339 */
349 res = tipc_deleteport(tport); 340 tipc_port_destroy(port);
350 341
351 /* Discard any remaining (connection-based) messages in receive queue */ 342 /* Discard any remaining (connection-based) messages in receive queue */
352 __skb_queue_purge(&sk->sk_receive_queue); 343 __skb_queue_purge(&sk->sk_receive_queue);
@@ -362,7 +353,7 @@ static int release(struct socket *sock)
362} 353}
363 354
364/** 355/**
365 * bind - associate or disassocate TIPC name(s) with a socket 356 * tipc_bind - associate or disassocate TIPC name(s) with a socket
366 * @sock: socket structure 357 * @sock: socket structure
367 * @uaddr: socket address describing name(s) and desired operation 358 * @uaddr: socket address describing name(s) and desired operation
368 * @uaddr_len: size of socket address data structure 359 * @uaddr_len: size of socket address data structure
@@ -376,16 +367,17 @@ static int release(struct socket *sock)
376 * NOTE: This routine doesn't need to take the socket lock since it doesn't 367 * NOTE: This routine doesn't need to take the socket lock since it doesn't
377 * access any non-constant socket information. 368 * access any non-constant socket information.
378 */ 369 */
379static int bind(struct socket *sock, struct sockaddr *uaddr, int uaddr_len) 370static int tipc_bind(struct socket *sock, struct sockaddr *uaddr,
371 int uaddr_len)
380{ 372{
381 struct sock *sk = sock->sk; 373 struct sock *sk = sock->sk;
382 struct sockaddr_tipc *addr = (struct sockaddr_tipc *)uaddr; 374 struct sockaddr_tipc *addr = (struct sockaddr_tipc *)uaddr;
383 struct tipc_port *tport = tipc_sk_port(sock->sk); 375 struct tipc_sock *tsk = tipc_sk(sk);
384 int res = -EINVAL; 376 int res = -EINVAL;
385 377
386 lock_sock(sk); 378 lock_sock(sk);
387 if (unlikely(!uaddr_len)) { 379 if (unlikely(!uaddr_len)) {
388 res = tipc_withdraw(tport, 0, NULL); 380 res = tipc_withdraw(&tsk->port, 0, NULL);
389 goto exit; 381 goto exit;
390 } 382 }
391 383
@@ -413,15 +405,15 @@ static int bind(struct socket *sock, struct sockaddr *uaddr, int uaddr_len)
413 } 405 }
414 406
415 res = (addr->scope > 0) ? 407 res = (addr->scope > 0) ?
416 tipc_publish(tport, addr->scope, &addr->addr.nameseq) : 408 tipc_publish(&tsk->port, addr->scope, &addr->addr.nameseq) :
417 tipc_withdraw(tport, -addr->scope, &addr->addr.nameseq); 409 tipc_withdraw(&tsk->port, -addr->scope, &addr->addr.nameseq);
418exit: 410exit:
419 release_sock(sk); 411 release_sock(sk);
420 return res; 412 return res;
421} 413}
422 414
423/** 415/**
424 * get_name - get port ID of socket or peer socket 416 * tipc_getname - get port ID of socket or peer socket
425 * @sock: socket structure 417 * @sock: socket structure
426 * @uaddr: area for returned socket address 418 * @uaddr: area for returned socket address
427 * @uaddr_len: area for returned length of socket address 419 * @uaddr_len: area for returned length of socket address
@@ -433,21 +425,21 @@ exit:
433 * accesses socket information that is unchanging (or which changes in 425 * accesses socket information that is unchanging (or which changes in
434 * a completely predictable manner). 426 * a completely predictable manner).
435 */ 427 */
436static int get_name(struct socket *sock, struct sockaddr *uaddr, 428static int tipc_getname(struct socket *sock, struct sockaddr *uaddr,
437 int *uaddr_len, int peer) 429 int *uaddr_len, int peer)
438{ 430{
439 struct sockaddr_tipc *addr = (struct sockaddr_tipc *)uaddr; 431 struct sockaddr_tipc *addr = (struct sockaddr_tipc *)uaddr;
440 struct tipc_sock *tsock = tipc_sk(sock->sk); 432 struct tipc_sock *tsk = tipc_sk(sock->sk);
441 433
442 memset(addr, 0, sizeof(*addr)); 434 memset(addr, 0, sizeof(*addr));
443 if (peer) { 435 if (peer) {
444 if ((sock->state != SS_CONNECTED) && 436 if ((sock->state != SS_CONNECTED) &&
445 ((peer != 2) || (sock->state != SS_DISCONNECTING))) 437 ((peer != 2) || (sock->state != SS_DISCONNECTING)))
446 return -ENOTCONN; 438 return -ENOTCONN;
447 addr->addr.id.ref = tsock->peer_name.ref; 439 addr->addr.id.ref = tipc_port_peerport(&tsk->port);
448 addr->addr.id.node = tsock->peer_name.node; 440 addr->addr.id.node = tipc_port_peernode(&tsk->port);
449 } else { 441 } else {
450 addr->addr.id.ref = tsock->p->ref; 442 addr->addr.id.ref = tsk->port.ref;
451 addr->addr.id.node = tipc_own_addr; 443 addr->addr.id.node = tipc_own_addr;
452 } 444 }
453 445
@@ -461,7 +453,7 @@ static int get_name(struct socket *sock, struct sockaddr *uaddr,
461} 453}
462 454
463/** 455/**
464 * poll - read and possibly block on pollmask 456 * tipc_poll - read and possibly block on pollmask
465 * @file: file structure associated with the socket 457 * @file: file structure associated with the socket
466 * @sock: socket for which to calculate the poll bits 458 * @sock: socket for which to calculate the poll bits
467 * @wait: ??? 459 * @wait: ???
@@ -500,22 +492,23 @@ static int get_name(struct socket *sock, struct sockaddr *uaddr,
500 * imply that the operation will succeed, merely that it should be performed 492 * imply that the operation will succeed, merely that it should be performed
501 * and will not block. 493 * and will not block.
502 */ 494 */
503static unsigned int poll(struct file *file, struct socket *sock, 495static unsigned int tipc_poll(struct file *file, struct socket *sock,
504 poll_table *wait) 496 poll_table *wait)
505{ 497{
506 struct sock *sk = sock->sk; 498 struct sock *sk = sock->sk;
499 struct tipc_sock *tsk = tipc_sk(sk);
507 u32 mask = 0; 500 u32 mask = 0;
508 501
509 sock_poll_wait(file, sk_sleep(sk), wait); 502 sock_poll_wait(file, sk_sleep(sk), wait);
510 503
511 switch ((int)sock->state) { 504 switch ((int)sock->state) {
512 case SS_UNCONNECTED: 505 case SS_UNCONNECTED:
513 if (!tipc_sk_port(sk)->congested) 506 if (!tsk->port.congested)
514 mask |= POLLOUT; 507 mask |= POLLOUT;
515 break; 508 break;
516 case SS_READY: 509 case SS_READY:
517 case SS_CONNECTED: 510 case SS_CONNECTED:
518 if (!tipc_sk_port(sk)->congested) 511 if (!tsk->port.congested)
519 mask |= POLLOUT; 512 mask |= POLLOUT;
520 /* fall thru' */ 513 /* fall thru' */
521 case SS_CONNECTING: 514 case SS_CONNECTING:
@@ -565,7 +558,7 @@ static int dest_name_check(struct sockaddr_tipc *dest, struct msghdr *m)
565static int tipc_wait_for_sndmsg(struct socket *sock, long *timeo_p) 558static int tipc_wait_for_sndmsg(struct socket *sock, long *timeo_p)
566{ 559{
567 struct sock *sk = sock->sk; 560 struct sock *sk = sock->sk;
568 struct tipc_port *tport = tipc_sk_port(sk); 561 struct tipc_sock *tsk = tipc_sk(sk);
569 DEFINE_WAIT(wait); 562 DEFINE_WAIT(wait);
570 int done; 563 int done;
571 564
@@ -581,14 +574,15 @@ static int tipc_wait_for_sndmsg(struct socket *sock, long *timeo_p)
581 return sock_intr_errno(*timeo_p); 574 return sock_intr_errno(*timeo_p);
582 575
583 prepare_to_wait(sk_sleep(sk), &wait, TASK_INTERRUPTIBLE); 576 prepare_to_wait(sk_sleep(sk), &wait, TASK_INTERRUPTIBLE);
584 done = sk_wait_event(sk, timeo_p, !tport->congested); 577 done = sk_wait_event(sk, timeo_p, !tsk->port.congested);
585 finish_wait(sk_sleep(sk), &wait); 578 finish_wait(sk_sleep(sk), &wait);
586 } while (!done); 579 } while (!done);
587 return 0; 580 return 0;
588} 581}
589 582
583
590/** 584/**
591 * send_msg - send message in connectionless manner 585 * tipc_sendmsg - send message in connectionless manner
592 * @iocb: if NULL, indicates that socket lock is already held 586 * @iocb: if NULL, indicates that socket lock is already held
593 * @sock: socket structure 587 * @sock: socket structure
594 * @m: message to send 588 * @m: message to send
@@ -601,11 +595,12 @@ static int tipc_wait_for_sndmsg(struct socket *sock, long *timeo_p)
601 * 595 *
602 * Returns the number of bytes sent on success, or errno otherwise 596 * Returns the number of bytes sent on success, or errno otherwise
603 */ 597 */
604static int send_msg(struct kiocb *iocb, struct socket *sock, 598static int tipc_sendmsg(struct kiocb *iocb, struct socket *sock,
605 struct msghdr *m, size_t total_len) 599 struct msghdr *m, size_t total_len)
606{ 600{
607 struct sock *sk = sock->sk; 601 struct sock *sk = sock->sk;
608 struct tipc_port *tport = tipc_sk_port(sk); 602 struct tipc_sock *tsk = tipc_sk(sk);
603 struct tipc_port *port = &tsk->port;
609 DECLARE_SOCKADDR(struct sockaddr_tipc *, dest, m->msg_name); 604 DECLARE_SOCKADDR(struct sockaddr_tipc *, dest, m->msg_name);
610 int needs_conn; 605 int needs_conn;
611 long timeo; 606 long timeo;
@@ -632,13 +627,13 @@ static int send_msg(struct kiocb *iocb, struct socket *sock,
632 res = -EISCONN; 627 res = -EISCONN;
633 goto exit; 628 goto exit;
634 } 629 }
635 if (tport->published) { 630 if (tsk->port.published) {
636 res = -EOPNOTSUPP; 631 res = -EOPNOTSUPP;
637 goto exit; 632 goto exit;
638 } 633 }
639 if (dest->addrtype == TIPC_ADDR_NAME) { 634 if (dest->addrtype == TIPC_ADDR_NAME) {
640 tport->conn_type = dest->addr.name.name.type; 635 tsk->port.conn_type = dest->addr.name.name.type;
641 tport->conn_instance = dest->addr.name.name.instance; 636 tsk->port.conn_instance = dest->addr.name.name.instance;
642 } 637 }
643 638
644 /* Abort any pending connection attempts (very unlikely) */ 639 /* Abort any pending connection attempts (very unlikely) */
@@ -651,13 +646,13 @@ static int send_msg(struct kiocb *iocb, struct socket *sock,
651 res = dest_name_check(dest, m); 646 res = dest_name_check(dest, m);
652 if (res) 647 if (res)
653 break; 648 break;
654 res = tipc_send2name(tport->ref, 649 res = tipc_send2name(port,
655 &dest->addr.name.name, 650 &dest->addr.name.name,
656 dest->addr.name.domain, 651 dest->addr.name.domain,
657 m->msg_iov, 652 m->msg_iov,
658 total_len); 653 total_len);
659 } else if (dest->addrtype == TIPC_ADDR_ID) { 654 } else if (dest->addrtype == TIPC_ADDR_ID) {
660 res = tipc_send2port(tport->ref, 655 res = tipc_send2port(port,
661 &dest->addr.id, 656 &dest->addr.id,
662 m->msg_iov, 657 m->msg_iov,
663 total_len); 658 total_len);
@@ -669,10 +664,10 @@ static int send_msg(struct kiocb *iocb, struct socket *sock,
669 res = dest_name_check(dest, m); 664 res = dest_name_check(dest, m);
670 if (res) 665 if (res)
671 break; 666 break;
672 res = tipc_multicast(tport->ref, 667 res = tipc_port_mcast_xmit(port,
673 &dest->addr.nameseq, 668 &dest->addr.nameseq,
674 m->msg_iov, 669 m->msg_iov,
675 total_len); 670 total_len);
676 } 671 }
677 if (likely(res != -ELINKCONG)) { 672 if (likely(res != -ELINKCONG)) {
678 if (needs_conn && (res >= 0)) 673 if (needs_conn && (res >= 0))
@@ -693,7 +688,8 @@ exit:
693static int tipc_wait_for_sndpkt(struct socket *sock, long *timeo_p) 688static int tipc_wait_for_sndpkt(struct socket *sock, long *timeo_p)
694{ 689{
695 struct sock *sk = sock->sk; 690 struct sock *sk = sock->sk;
696 struct tipc_port *tport = tipc_sk_port(sk); 691 struct tipc_sock *tsk = tipc_sk(sk);
692 struct tipc_port *port = &tsk->port;
697 DEFINE_WAIT(wait); 693 DEFINE_WAIT(wait);
698 int done; 694 int done;
699 695
@@ -712,14 +708,14 @@ static int tipc_wait_for_sndpkt(struct socket *sock, long *timeo_p)
712 708
713 prepare_to_wait(sk_sleep(sk), &wait, TASK_INTERRUPTIBLE); 709 prepare_to_wait(sk_sleep(sk), &wait, TASK_INTERRUPTIBLE);
714 done = sk_wait_event(sk, timeo_p, 710 done = sk_wait_event(sk, timeo_p,
715 (!tport->congested || !tport->connected)); 711 (!port->congested || !port->connected));
716 finish_wait(sk_sleep(sk), &wait); 712 finish_wait(sk_sleep(sk), &wait);
717 } while (!done); 713 } while (!done);
718 return 0; 714 return 0;
719} 715}
720 716
721/** 717/**
722 * send_packet - send a connection-oriented message 718 * tipc_send_packet - send a connection-oriented message
723 * @iocb: if NULL, indicates that socket lock is already held 719 * @iocb: if NULL, indicates that socket lock is already held
724 * @sock: socket structure 720 * @sock: socket structure
725 * @m: message to send 721 * @m: message to send
@@ -729,18 +725,18 @@ static int tipc_wait_for_sndpkt(struct socket *sock, long *timeo_p)
729 * 725 *
730 * Returns the number of bytes sent on success, or errno otherwise 726 * Returns the number of bytes sent on success, or errno otherwise
731 */ 727 */
732static int send_packet(struct kiocb *iocb, struct socket *sock, 728static int tipc_send_packet(struct kiocb *iocb, struct socket *sock,
733 struct msghdr *m, size_t total_len) 729 struct msghdr *m, size_t total_len)
734{ 730{
735 struct sock *sk = sock->sk; 731 struct sock *sk = sock->sk;
736 struct tipc_port *tport = tipc_sk_port(sk); 732 struct tipc_sock *tsk = tipc_sk(sk);
737 DECLARE_SOCKADDR(struct sockaddr_tipc *, dest, m->msg_name); 733 DECLARE_SOCKADDR(struct sockaddr_tipc *, dest, m->msg_name);
738 int res = -EINVAL; 734 int res = -EINVAL;
739 long timeo; 735 long timeo;
740 736
741 /* Handle implied connection establishment */ 737 /* Handle implied connection establishment */
742 if (unlikely(dest)) 738 if (unlikely(dest))
743 return send_msg(iocb, sock, m, total_len); 739 return tipc_sendmsg(iocb, sock, m, total_len);
744 740
745 if (total_len > TIPC_MAX_USER_MSG_SIZE) 741 if (total_len > TIPC_MAX_USER_MSG_SIZE)
746 return -EMSGSIZE; 742 return -EMSGSIZE;
@@ -758,7 +754,7 @@ static int send_packet(struct kiocb *iocb, struct socket *sock,
758 754
759 timeo = sock_sndtimeo(sk, m->msg_flags & MSG_DONTWAIT); 755 timeo = sock_sndtimeo(sk, m->msg_flags & MSG_DONTWAIT);
760 do { 756 do {
761 res = tipc_send(tport->ref, m->msg_iov, total_len); 757 res = tipc_send(&tsk->port, m->msg_iov, total_len);
762 if (likely(res != -ELINKCONG)) 758 if (likely(res != -ELINKCONG))
763 break; 759 break;
764 res = tipc_wait_for_sndpkt(sock, &timeo); 760 res = tipc_wait_for_sndpkt(sock, &timeo);
@@ -772,7 +768,7 @@ exit:
772} 768}
773 769
774/** 770/**
775 * send_stream - send stream-oriented data 771 * tipc_send_stream - send stream-oriented data
776 * @iocb: (unused) 772 * @iocb: (unused)
777 * @sock: socket structure 773 * @sock: socket structure
778 * @m: data to send 774 * @m: data to send
@@ -783,11 +779,11 @@ exit:
783 * Returns the number of bytes sent on success (or partial success), 779 * Returns the number of bytes sent on success (or partial success),
784 * or errno if no data sent 780 * or errno if no data sent
785 */ 781 */
786static int send_stream(struct kiocb *iocb, struct socket *sock, 782static int tipc_send_stream(struct kiocb *iocb, struct socket *sock,
787 struct msghdr *m, size_t total_len) 783 struct msghdr *m, size_t total_len)
788{ 784{
789 struct sock *sk = sock->sk; 785 struct sock *sk = sock->sk;
790 struct tipc_port *tport = tipc_sk_port(sk); 786 struct tipc_sock *tsk = tipc_sk(sk);
791 struct msghdr my_msg; 787 struct msghdr my_msg;
792 struct iovec my_iov; 788 struct iovec my_iov;
793 struct iovec *curr_iov; 789 struct iovec *curr_iov;
@@ -804,7 +800,7 @@ static int send_stream(struct kiocb *iocb, struct socket *sock,
804 /* Handle special cases where there is no connection */ 800 /* Handle special cases where there is no connection */
805 if (unlikely(sock->state != SS_CONNECTED)) { 801 if (unlikely(sock->state != SS_CONNECTED)) {
806 if (sock->state == SS_UNCONNECTED) 802 if (sock->state == SS_UNCONNECTED)
807 res = send_packet(NULL, sock, m, total_len); 803 res = tipc_send_packet(NULL, sock, m, total_len);
808 else 804 else
809 res = sock->state == SS_DISCONNECTING ? -EPIPE : -ENOTCONN; 805 res = sock->state == SS_DISCONNECTING ? -EPIPE : -ENOTCONN;
810 goto exit; 806 goto exit;
@@ -835,21 +831,22 @@ static int send_stream(struct kiocb *iocb, struct socket *sock,
835 my_msg.msg_name = NULL; 831 my_msg.msg_name = NULL;
836 bytes_sent = 0; 832 bytes_sent = 0;
837 833
838 hdr_size = msg_hdr_sz(&tport->phdr); 834 hdr_size = msg_hdr_sz(&tsk->port.phdr);
839 835
840 while (curr_iovlen--) { 836 while (curr_iovlen--) {
841 curr_start = curr_iov->iov_base; 837 curr_start = curr_iov->iov_base;
842 curr_left = curr_iov->iov_len; 838 curr_left = curr_iov->iov_len;
843 839
844 while (curr_left) { 840 while (curr_left) {
845 bytes_to_send = tport->max_pkt - hdr_size; 841 bytes_to_send = tsk->port.max_pkt - hdr_size;
846 if (bytes_to_send > TIPC_MAX_USER_MSG_SIZE) 842 if (bytes_to_send > TIPC_MAX_USER_MSG_SIZE)
847 bytes_to_send = TIPC_MAX_USER_MSG_SIZE; 843 bytes_to_send = TIPC_MAX_USER_MSG_SIZE;
848 if (curr_left < bytes_to_send) 844 if (curr_left < bytes_to_send)
849 bytes_to_send = curr_left; 845 bytes_to_send = curr_left;
850 my_iov.iov_base = curr_start; 846 my_iov.iov_base = curr_start;
851 my_iov.iov_len = bytes_to_send; 847 my_iov.iov_len = bytes_to_send;
852 res = send_packet(NULL, sock, &my_msg, bytes_to_send); 848 res = tipc_send_packet(NULL, sock, &my_msg,
849 bytes_to_send);
853 if (res < 0) { 850 if (res < 0) {
854 if (bytes_sent) 851 if (bytes_sent)
855 res = bytes_sent; 852 res = bytes_sent;
@@ -870,27 +867,25 @@ exit:
870 867
871/** 868/**
872 * auto_connect - complete connection setup to a remote port 869 * auto_connect - complete connection setup to a remote port
873 * @sock: socket structure 870 * @tsk: tipc socket structure
874 * @msg: peer's response message 871 * @msg: peer's response message
875 * 872 *
876 * Returns 0 on success, errno otherwise 873 * Returns 0 on success, errno otherwise
877 */ 874 */
878static int auto_connect(struct socket *sock, struct tipc_msg *msg) 875static int auto_connect(struct tipc_sock *tsk, struct tipc_msg *msg)
879{ 876{
880 struct tipc_sock *tsock = tipc_sk(sock->sk); 877 struct tipc_port *port = &tsk->port;
881 struct tipc_port *p_ptr; 878 struct socket *sock = tsk->sk.sk_socket;
879 struct tipc_portid peer;
882 880
883 tsock->peer_name.ref = msg_origport(msg); 881 peer.ref = msg_origport(msg);
884 tsock->peer_name.node = msg_orignode(msg); 882 peer.node = msg_orignode(msg);
885 p_ptr = tipc_port_deref(tsock->p->ref);
886 if (!p_ptr)
887 return -EINVAL;
888 883
889 __tipc_connect(tsock->p->ref, p_ptr, &tsock->peer_name); 884 __tipc_port_connect(port->ref, port, &peer);
890 885
891 if (msg_importance(msg) > TIPC_CRITICAL_IMPORTANCE) 886 if (msg_importance(msg) > TIPC_CRITICAL_IMPORTANCE)
892 return -EINVAL; 887 return -EINVAL;
893 msg_set_importance(&p_ptr->phdr, (u32)msg_importance(msg)); 888 msg_set_importance(&port->phdr, (u32)msg_importance(msg));
894 sock->state = SS_CONNECTED; 889 sock->state = SS_CONNECTED;
895 return 0; 890 return 0;
896} 891}
@@ -997,7 +992,7 @@ static int tipc_wait_for_rcvmsg(struct socket *sock, long timeo)
997 992
998 for (;;) { 993 for (;;) {
999 prepare_to_wait(sk_sleep(sk), &wait, TASK_INTERRUPTIBLE); 994 prepare_to_wait(sk_sleep(sk), &wait, TASK_INTERRUPTIBLE);
1000 if (skb_queue_empty(&sk->sk_receive_queue)) { 995 if (timeo && skb_queue_empty(&sk->sk_receive_queue)) {
1001 if (sock->state == SS_DISCONNECTING) { 996 if (sock->state == SS_DISCONNECTING) {
1002 err = -ENOTCONN; 997 err = -ENOTCONN;
1003 break; 998 break;
@@ -1021,7 +1016,7 @@ static int tipc_wait_for_rcvmsg(struct socket *sock, long timeo)
1021} 1016}
1022 1017
1023/** 1018/**
1024 * recv_msg - receive packet-oriented message 1019 * tipc_recvmsg - receive packet-oriented message
1025 * @iocb: (unused) 1020 * @iocb: (unused)
1026 * @m: descriptor for message info 1021 * @m: descriptor for message info
1027 * @buf_len: total size of user buffer area 1022 * @buf_len: total size of user buffer area
@@ -1032,11 +1027,12 @@ static int tipc_wait_for_rcvmsg(struct socket *sock, long timeo)
1032 * 1027 *
1033 * Returns size of returned message data, errno otherwise 1028 * Returns size of returned message data, errno otherwise
1034 */ 1029 */
1035static int recv_msg(struct kiocb *iocb, struct socket *sock, 1030static int tipc_recvmsg(struct kiocb *iocb, struct socket *sock,
1036 struct msghdr *m, size_t buf_len, int flags) 1031 struct msghdr *m, size_t buf_len, int flags)
1037{ 1032{
1038 struct sock *sk = sock->sk; 1033 struct sock *sk = sock->sk;
1039 struct tipc_port *tport = tipc_sk_port(sk); 1034 struct tipc_sock *tsk = tipc_sk(sk);
1035 struct tipc_port *port = &tsk->port;
1040 struct sk_buff *buf; 1036 struct sk_buff *buf;
1041 struct tipc_msg *msg; 1037 struct tipc_msg *msg;
1042 long timeo; 1038 long timeo;
@@ -1079,7 +1075,7 @@ restart:
1079 set_orig_addr(m, msg); 1075 set_orig_addr(m, msg);
1080 1076
1081 /* Capture ancillary data (optional) */ 1077 /* Capture ancillary data (optional) */
1082 res = anc_data_recv(m, msg, tport); 1078 res = anc_data_recv(m, msg, port);
1083 if (res) 1079 if (res)
1084 goto exit; 1080 goto exit;
1085 1081
@@ -1105,8 +1101,8 @@ restart:
1105 /* Consume received message (optional) */ 1101 /* Consume received message (optional) */
1106 if (likely(!(flags & MSG_PEEK))) { 1102 if (likely(!(flags & MSG_PEEK))) {
1107 if ((sock->state != SS_READY) && 1103 if ((sock->state != SS_READY) &&
1108 (++tport->conn_unacked >= TIPC_FLOW_CONTROL_WIN)) 1104 (++port->conn_unacked >= TIPC_FLOW_CONTROL_WIN))
1109 tipc_acknowledge(tport->ref, tport->conn_unacked); 1105 tipc_acknowledge(port->ref, port->conn_unacked);
1110 advance_rx_queue(sk); 1106 advance_rx_queue(sk);
1111 } 1107 }
1112exit: 1108exit:
@@ -1115,7 +1111,7 @@ exit:
1115} 1111}
1116 1112
1117/** 1113/**
1118 * recv_stream - receive stream-oriented data 1114 * tipc_recv_stream - receive stream-oriented data
1119 * @iocb: (unused) 1115 * @iocb: (unused)
1120 * @m: descriptor for message info 1116 * @m: descriptor for message info
1121 * @buf_len: total size of user buffer area 1117 * @buf_len: total size of user buffer area
@@ -1126,11 +1122,12 @@ exit:
1126 * 1122 *
1127 * Returns size of returned message data, errno otherwise 1123 * Returns size of returned message data, errno otherwise
1128 */ 1124 */
1129static int recv_stream(struct kiocb *iocb, struct socket *sock, 1125static int tipc_recv_stream(struct kiocb *iocb, struct socket *sock,
1130 struct msghdr *m, size_t buf_len, int flags) 1126 struct msghdr *m, size_t buf_len, int flags)
1131{ 1127{
1132 struct sock *sk = sock->sk; 1128 struct sock *sk = sock->sk;
1133 struct tipc_port *tport = tipc_sk_port(sk); 1129 struct tipc_sock *tsk = tipc_sk(sk);
1130 struct tipc_port *port = &tsk->port;
1134 struct sk_buff *buf; 1131 struct sk_buff *buf;
1135 struct tipc_msg *msg; 1132 struct tipc_msg *msg;
1136 long timeo; 1133 long timeo;
@@ -1175,7 +1172,7 @@ restart:
1175 /* Optionally capture sender's address & ancillary data of first msg */ 1172 /* Optionally capture sender's address & ancillary data of first msg */
1176 if (sz_copied == 0) { 1173 if (sz_copied == 0) {
1177 set_orig_addr(m, msg); 1174 set_orig_addr(m, msg);
1178 res = anc_data_recv(m, msg, tport); 1175 res = anc_data_recv(m, msg, port);
1179 if (res) 1176 if (res)
1180 goto exit; 1177 goto exit;
1181 } 1178 }
@@ -1213,8 +1210,8 @@ restart:
1213 1210
1214 /* Consume received message (optional) */ 1211 /* Consume received message (optional) */
1215 if (likely(!(flags & MSG_PEEK))) { 1212 if (likely(!(flags & MSG_PEEK))) {
1216 if (unlikely(++tport->conn_unacked >= TIPC_FLOW_CONTROL_WIN)) 1213 if (unlikely(++port->conn_unacked >= TIPC_FLOW_CONTROL_WIN))
1217 tipc_acknowledge(tport->ref, tport->conn_unacked); 1214 tipc_acknowledge(port->ref, port->conn_unacked);
1218 advance_rx_queue(sk); 1215 advance_rx_queue(sk);
1219 } 1216 }
1220 1217
@@ -1266,17 +1263,19 @@ static void tipc_data_ready(struct sock *sk, int len)
1266 1263
1267/** 1264/**
1268 * filter_connect - Handle all incoming messages for a connection-based socket 1265 * filter_connect - Handle all incoming messages for a connection-based socket
1269 * @tsock: TIPC socket 1266 * @tsk: TIPC socket
1270 * @msg: message 1267 * @msg: message
1271 * 1268 *
1272 * Returns TIPC error status code and socket error status code 1269 * Returns TIPC error status code and socket error status code
1273 * once it encounters some errors 1270 * once it encounters some errors
1274 */ 1271 */
1275static u32 filter_connect(struct tipc_sock *tsock, struct sk_buff **buf) 1272static u32 filter_connect(struct tipc_sock *tsk, struct sk_buff **buf)
1276{ 1273{
1277 struct socket *sock = tsock->sk.sk_socket; 1274 struct sock *sk = &tsk->sk;
1275 struct tipc_port *port = &tsk->port;
1276 struct socket *sock = sk->sk_socket;
1278 struct tipc_msg *msg = buf_msg(*buf); 1277 struct tipc_msg *msg = buf_msg(*buf);
1279 struct sock *sk = &tsock->sk; 1278
1280 u32 retval = TIPC_ERR_NO_PORT; 1279 u32 retval = TIPC_ERR_NO_PORT;
1281 int res; 1280 int res;
1282 1281
@@ -1286,10 +1285,10 @@ static u32 filter_connect(struct tipc_sock *tsock, struct sk_buff **buf)
1286 switch ((int)sock->state) { 1285 switch ((int)sock->state) {
1287 case SS_CONNECTED: 1286 case SS_CONNECTED:
1288 /* Accept only connection-based messages sent by peer */ 1287 /* Accept only connection-based messages sent by peer */
1289 if (msg_connected(msg) && tipc_port_peer_msg(tsock->p, msg)) { 1288 if (msg_connected(msg) && tipc_port_peer_msg(port, msg)) {
1290 if (unlikely(msg_errcode(msg))) { 1289 if (unlikely(msg_errcode(msg))) {
1291 sock->state = SS_DISCONNECTING; 1290 sock->state = SS_DISCONNECTING;
1292 __tipc_disconnect(tsock->p); 1291 __tipc_port_disconnect(port);
1293 } 1292 }
1294 retval = TIPC_OK; 1293 retval = TIPC_OK;
1295 } 1294 }
@@ -1306,7 +1305,7 @@ static u32 filter_connect(struct tipc_sock *tsock, struct sk_buff **buf)
1306 if (unlikely(!msg_connected(msg))) 1305 if (unlikely(!msg_connected(msg)))
1307 break; 1306 break;
1308 1307
1309 res = auto_connect(sock, msg); 1308 res = auto_connect(tsk, msg);
1310 if (res) { 1309 if (res) {
1311 sock->state = SS_DISCONNECTING; 1310 sock->state = SS_DISCONNECTING;
1312 sk->sk_err = -res; 1311 sk->sk_err = -res;
@@ -1385,6 +1384,7 @@ static unsigned int rcvbuf_limit(struct sock *sk, struct sk_buff *buf)
1385static u32 filter_rcv(struct sock *sk, struct sk_buff *buf) 1384static u32 filter_rcv(struct sock *sk, struct sk_buff *buf)
1386{ 1385{
1387 struct socket *sock = sk->sk_socket; 1386 struct socket *sock = sk->sk_socket;
1387 struct tipc_sock *tsk = tipc_sk(sk);
1388 struct tipc_msg *msg = buf_msg(buf); 1388 struct tipc_msg *msg = buf_msg(buf);
1389 unsigned int limit = rcvbuf_limit(sk, buf); 1389 unsigned int limit = rcvbuf_limit(sk, buf);
1390 u32 res = TIPC_OK; 1390 u32 res = TIPC_OK;
@@ -1397,7 +1397,7 @@ static u32 filter_rcv(struct sock *sk, struct sk_buff *buf)
1397 if (msg_connected(msg)) 1397 if (msg_connected(msg))
1398 return TIPC_ERR_NO_PORT; 1398 return TIPC_ERR_NO_PORT;
1399 } else { 1399 } else {
1400 res = filter_connect(tipc_sk(sk), &buf); 1400 res = filter_connect(tsk, &buf);
1401 if (res != TIPC_OK || buf == NULL) 1401 if (res != TIPC_OK || buf == NULL)
1402 return res; 1402 return res;
1403 } 1403 }
@@ -1435,17 +1435,16 @@ static int backlog_rcv(struct sock *sk, struct sk_buff *buf)
1435} 1435}
1436 1436
1437/** 1437/**
1438 * dispatch - handle incoming message 1438 * tipc_sk_rcv - handle incoming message
1439 * @tport: TIPC port that received message 1439 * @sk: socket receiving message
1440 * @buf: message 1440 * @buf: message
1441 * 1441 *
1442 * Called with port lock already taken. 1442 * Called with port lock already taken.
1443 * 1443 *
1444 * Returns TIPC error status code (TIPC_OK if message is not to be rejected) 1444 * Returns TIPC error status code (TIPC_OK if message is not to be rejected)
1445 */ 1445 */
1446static u32 dispatch(struct tipc_port *tport, struct sk_buff *buf) 1446u32 tipc_sk_rcv(struct sock *sk, struct sk_buff *buf)
1447{ 1447{
1448 struct sock *sk = tport->sk;
1449 u32 res; 1448 u32 res;
1450 1449
1451 /* 1450 /*
@@ -1468,19 +1467,6 @@ static u32 dispatch(struct tipc_port *tport, struct sk_buff *buf)
1468 return res; 1467 return res;
1469} 1468}
1470 1469
1471/**
1472 * wakeupdispatch - wake up port after congestion
1473 * @tport: port to wakeup
1474 *
1475 * Called with port lock already taken.
1476 */
1477static void wakeupdispatch(struct tipc_port *tport)
1478{
1479 struct sock *sk = tport->sk;
1480
1481 sk->sk_write_space(sk);
1482}
1483
1484static int tipc_wait_for_connect(struct socket *sock, long *timeo_p) 1470static int tipc_wait_for_connect(struct socket *sock, long *timeo_p)
1485{ 1471{
1486 struct sock *sk = sock->sk; 1472 struct sock *sk = sock->sk;
@@ -1504,7 +1490,7 @@ static int tipc_wait_for_connect(struct socket *sock, long *timeo_p)
1504} 1490}
1505 1491
1506/** 1492/**
1507 * connect - establish a connection to another TIPC port 1493 * tipc_connect - establish a connection to another TIPC port
1508 * @sock: socket structure 1494 * @sock: socket structure
1509 * @dest: socket address for destination port 1495 * @dest: socket address for destination port
1510 * @destlen: size of socket address data structure 1496 * @destlen: size of socket address data structure
@@ -1512,8 +1498,8 @@ static int tipc_wait_for_connect(struct socket *sock, long *timeo_p)
1512 * 1498 *
1513 * Returns 0 on success, errno otherwise 1499 * Returns 0 on success, errno otherwise
1514 */ 1500 */
1515static int connect(struct socket *sock, struct sockaddr *dest, int destlen, 1501static int tipc_connect(struct socket *sock, struct sockaddr *dest,
1516 int flags) 1502 int destlen, int flags)
1517{ 1503{
1518 struct sock *sk = sock->sk; 1504 struct sock *sk = sock->sk;
1519 struct sockaddr_tipc *dst = (struct sockaddr_tipc *)dest; 1505 struct sockaddr_tipc *dst = (struct sockaddr_tipc *)dest;
@@ -1554,7 +1540,7 @@ static int connect(struct socket *sock, struct sockaddr *dest, int destlen,
1554 if (!timeout) 1540 if (!timeout)
1555 m.msg_flags = MSG_DONTWAIT; 1541 m.msg_flags = MSG_DONTWAIT;
1556 1542
1557 res = send_msg(NULL, sock, &m, 0); 1543 res = tipc_sendmsg(NULL, sock, &m, 0);
1558 if ((res < 0) && (res != -EWOULDBLOCK)) 1544 if ((res < 0) && (res != -EWOULDBLOCK))
1559 goto exit; 1545 goto exit;
1560 1546
@@ -1585,13 +1571,13 @@ exit:
1585} 1571}
1586 1572
1587/** 1573/**
1588 * listen - allow socket to listen for incoming connections 1574 * tipc_listen - allow socket to listen for incoming connections
1589 * @sock: socket structure 1575 * @sock: socket structure
1590 * @len: (unused) 1576 * @len: (unused)
1591 * 1577 *
1592 * Returns 0 on success, errno otherwise 1578 * Returns 0 on success, errno otherwise
1593 */ 1579 */
1594static int listen(struct socket *sock, int len) 1580static int tipc_listen(struct socket *sock, int len)
1595{ 1581{
1596 struct sock *sk = sock->sk; 1582 struct sock *sk = sock->sk;
1597 int res; 1583 int res;
@@ -1623,7 +1609,7 @@ static int tipc_wait_for_accept(struct socket *sock, long timeo)
1623 for (;;) { 1609 for (;;) {
1624 prepare_to_wait_exclusive(sk_sleep(sk), &wait, 1610 prepare_to_wait_exclusive(sk_sleep(sk), &wait,
1625 TASK_INTERRUPTIBLE); 1611 TASK_INTERRUPTIBLE);
1626 if (skb_queue_empty(&sk->sk_receive_queue)) { 1612 if (timeo && skb_queue_empty(&sk->sk_receive_queue)) {
1627 release_sock(sk); 1613 release_sock(sk);
1628 timeo = schedule_timeout(timeo); 1614 timeo = schedule_timeout(timeo);
1629 lock_sock(sk); 1615 lock_sock(sk);
@@ -1646,20 +1632,20 @@ static int tipc_wait_for_accept(struct socket *sock, long timeo)
1646} 1632}
1647 1633
1648/** 1634/**
1649 * accept - wait for connection request 1635 * tipc_accept - wait for connection request
1650 * @sock: listening socket 1636 * @sock: listening socket
1651 * @newsock: new socket that is to be connected 1637 * @newsock: new socket that is to be connected
1652 * @flags: file-related flags associated with socket 1638 * @flags: file-related flags associated with socket
1653 * 1639 *
1654 * Returns 0 on success, errno otherwise 1640 * Returns 0 on success, errno otherwise
1655 */ 1641 */
1656static int accept(struct socket *sock, struct socket *new_sock, int flags) 1642static int tipc_accept(struct socket *sock, struct socket *new_sock, int flags)
1657{ 1643{
1658 struct sock *new_sk, *sk = sock->sk; 1644 struct sock *new_sk, *sk = sock->sk;
1659 struct sk_buff *buf; 1645 struct sk_buff *buf;
1660 struct tipc_sock *new_tsock; 1646 struct tipc_port *new_port;
1661 struct tipc_port *new_tport;
1662 struct tipc_msg *msg; 1647 struct tipc_msg *msg;
1648 struct tipc_portid peer;
1663 u32 new_ref; 1649 u32 new_ref;
1664 long timeo; 1650 long timeo;
1665 int res; 1651 int res;
@@ -1670,7 +1656,6 @@ static int accept(struct socket *sock, struct socket *new_sock, int flags)
1670 res = -EINVAL; 1656 res = -EINVAL;
1671 goto exit; 1657 goto exit;
1672 } 1658 }
1673
1674 timeo = sock_rcvtimeo(sk, flags & O_NONBLOCK); 1659 timeo = sock_rcvtimeo(sk, flags & O_NONBLOCK);
1675 res = tipc_wait_for_accept(sock, timeo); 1660 res = tipc_wait_for_accept(sock, timeo);
1676 if (res) 1661 if (res)
@@ -1683,9 +1668,8 @@ static int accept(struct socket *sock, struct socket *new_sock, int flags)
1683 goto exit; 1668 goto exit;
1684 1669
1685 new_sk = new_sock->sk; 1670 new_sk = new_sock->sk;
1686 new_tsock = tipc_sk(new_sk); 1671 new_port = &tipc_sk(new_sk)->port;
1687 new_tport = new_tsock->p; 1672 new_ref = new_port->ref;
1688 new_ref = new_tport->ref;
1689 msg = buf_msg(buf); 1673 msg = buf_msg(buf);
1690 1674
1691 /* we lock on new_sk; but lockdep sees the lock on sk */ 1675 /* we lock on new_sk; but lockdep sees the lock on sk */
@@ -1698,15 +1682,15 @@ static int accept(struct socket *sock, struct socket *new_sock, int flags)
1698 reject_rx_queue(new_sk); 1682 reject_rx_queue(new_sk);
1699 1683
1700 /* Connect new socket to it's peer */ 1684 /* Connect new socket to it's peer */
1701 new_tsock->peer_name.ref = msg_origport(msg); 1685 peer.ref = msg_origport(msg);
1702 new_tsock->peer_name.node = msg_orignode(msg); 1686 peer.node = msg_orignode(msg);
1703 tipc_connect(new_ref, &new_tsock->peer_name); 1687 tipc_port_connect(new_ref, &peer);
1704 new_sock->state = SS_CONNECTED; 1688 new_sock->state = SS_CONNECTED;
1705 1689
1706 tipc_set_portimportance(new_ref, msg_importance(msg)); 1690 tipc_port_set_importance(new_port, msg_importance(msg));
1707 if (msg_named(msg)) { 1691 if (msg_named(msg)) {
1708 new_tport->conn_type = msg_nametype(msg); 1692 new_port->conn_type = msg_nametype(msg);
1709 new_tport->conn_instance = msg_nameinst(msg); 1693 new_port->conn_instance = msg_nameinst(msg);
1710 } 1694 }
1711 1695
1712 /* 1696 /*
@@ -1717,21 +1701,20 @@ static int accept(struct socket *sock, struct socket *new_sock, int flags)
1717 struct msghdr m = {NULL,}; 1701 struct msghdr m = {NULL,};
1718 1702
1719 advance_rx_queue(sk); 1703 advance_rx_queue(sk);
1720 send_packet(NULL, new_sock, &m, 0); 1704 tipc_send_packet(NULL, new_sock, &m, 0);
1721 } else { 1705 } else {
1722 __skb_dequeue(&sk->sk_receive_queue); 1706 __skb_dequeue(&sk->sk_receive_queue);
1723 __skb_queue_head(&new_sk->sk_receive_queue, buf); 1707 __skb_queue_head(&new_sk->sk_receive_queue, buf);
1724 skb_set_owner_r(buf, new_sk); 1708 skb_set_owner_r(buf, new_sk);
1725 } 1709 }
1726 release_sock(new_sk); 1710 release_sock(new_sk);
1727
1728exit: 1711exit:
1729 release_sock(sk); 1712 release_sock(sk);
1730 return res; 1713 return res;
1731} 1714}
1732 1715
1733/** 1716/**
1734 * shutdown - shutdown socket connection 1717 * tipc_shutdown - shutdown socket connection
1735 * @sock: socket structure 1718 * @sock: socket structure
1736 * @how: direction to close (must be SHUT_RDWR) 1719 * @how: direction to close (must be SHUT_RDWR)
1737 * 1720 *
@@ -1739,10 +1722,11 @@ exit:
1739 * 1722 *
1740 * Returns 0 on success, errno otherwise 1723 * Returns 0 on success, errno otherwise
1741 */ 1724 */
1742static int shutdown(struct socket *sock, int how) 1725static int tipc_shutdown(struct socket *sock, int how)
1743{ 1726{
1744 struct sock *sk = sock->sk; 1727 struct sock *sk = sock->sk;
1745 struct tipc_port *tport = tipc_sk_port(sk); 1728 struct tipc_sock *tsk = tipc_sk(sk);
1729 struct tipc_port *port = &tsk->port;
1746 struct sk_buff *buf; 1730 struct sk_buff *buf;
1747 int res; 1731 int res;
1748 1732
@@ -1763,10 +1747,10 @@ restart:
1763 kfree_skb(buf); 1747 kfree_skb(buf);
1764 goto restart; 1748 goto restart;
1765 } 1749 }
1766 tipc_disconnect(tport->ref); 1750 tipc_port_disconnect(port->ref);
1767 tipc_reject_msg(buf, TIPC_CONN_SHUTDOWN); 1751 tipc_reject_msg(buf, TIPC_CONN_SHUTDOWN);
1768 } else { 1752 } else {
1769 tipc_shutdown(tport->ref); 1753 tipc_port_shutdown(port->ref);
1770 } 1754 }
1771 1755
1772 sock->state = SS_DISCONNECTING; 1756 sock->state = SS_DISCONNECTING;
@@ -1792,7 +1776,7 @@ restart:
1792} 1776}
1793 1777
1794/** 1778/**
1795 * setsockopt - set socket option 1779 * tipc_setsockopt - set socket option
1796 * @sock: socket structure 1780 * @sock: socket structure
1797 * @lvl: option level 1781 * @lvl: option level
1798 * @opt: option identifier 1782 * @opt: option identifier
@@ -1804,11 +1788,12 @@ restart:
1804 * 1788 *
1805 * Returns 0 on success, errno otherwise 1789 * Returns 0 on success, errno otherwise
1806 */ 1790 */
1807static int setsockopt(struct socket *sock, int lvl, int opt, char __user *ov, 1791static int tipc_setsockopt(struct socket *sock, int lvl, int opt,
1808 unsigned int ol) 1792 char __user *ov, unsigned int ol)
1809{ 1793{
1810 struct sock *sk = sock->sk; 1794 struct sock *sk = sock->sk;
1811 struct tipc_port *tport = tipc_sk_port(sk); 1795 struct tipc_sock *tsk = tipc_sk(sk);
1796 struct tipc_port *port = &tsk->port;
1812 u32 value; 1797 u32 value;
1813 int res; 1798 int res;
1814 1799
@@ -1826,16 +1811,16 @@ static int setsockopt(struct socket *sock, int lvl, int opt, char __user *ov,
1826 1811
1827 switch (opt) { 1812 switch (opt) {
1828 case TIPC_IMPORTANCE: 1813 case TIPC_IMPORTANCE:
1829 res = tipc_set_portimportance(tport->ref, value); 1814 tipc_port_set_importance(port, value);
1830 break; 1815 break;
1831 case TIPC_SRC_DROPPABLE: 1816 case TIPC_SRC_DROPPABLE:
1832 if (sock->type != SOCK_STREAM) 1817 if (sock->type != SOCK_STREAM)
1833 res = tipc_set_portunreliable(tport->ref, value); 1818 tipc_port_set_unreliable(port, value);
1834 else 1819 else
1835 res = -ENOPROTOOPT; 1820 res = -ENOPROTOOPT;
1836 break; 1821 break;
1837 case TIPC_DEST_DROPPABLE: 1822 case TIPC_DEST_DROPPABLE:
1838 res = tipc_set_portunreturnable(tport->ref, value); 1823 tipc_port_set_unreturnable(port, value);
1839 break; 1824 break;
1840 case TIPC_CONN_TIMEOUT: 1825 case TIPC_CONN_TIMEOUT:
1841 tipc_sk(sk)->conn_timeout = value; 1826 tipc_sk(sk)->conn_timeout = value;
@@ -1851,7 +1836,7 @@ static int setsockopt(struct socket *sock, int lvl, int opt, char __user *ov,
1851} 1836}
1852 1837
1853/** 1838/**
1854 * getsockopt - get socket option 1839 * tipc_getsockopt - get socket option
1855 * @sock: socket structure 1840 * @sock: socket structure
1856 * @lvl: option level 1841 * @lvl: option level
1857 * @opt: option identifier 1842 * @opt: option identifier
@@ -1863,11 +1848,12 @@ static int setsockopt(struct socket *sock, int lvl, int opt, char __user *ov,
1863 * 1848 *
1864 * Returns 0 on success, errno otherwise 1849 * Returns 0 on success, errno otherwise
1865 */ 1850 */
1866static int getsockopt(struct socket *sock, int lvl, int opt, char __user *ov, 1851static int tipc_getsockopt(struct socket *sock, int lvl, int opt,
1867 int __user *ol) 1852 char __user *ov, int __user *ol)
1868{ 1853{
1869 struct sock *sk = sock->sk; 1854 struct sock *sk = sock->sk;
1870 struct tipc_port *tport = tipc_sk_port(sk); 1855 struct tipc_sock *tsk = tipc_sk(sk);
1856 struct tipc_port *port = &tsk->port;
1871 int len; 1857 int len;
1872 u32 value; 1858 u32 value;
1873 int res; 1859 int res;
@@ -1884,13 +1870,13 @@ static int getsockopt(struct socket *sock, int lvl, int opt, char __user *ov,
1884 1870
1885 switch (opt) { 1871 switch (opt) {
1886 case TIPC_IMPORTANCE: 1872 case TIPC_IMPORTANCE:
1887 res = tipc_portimportance(tport->ref, &value); 1873 value = tipc_port_importance(port);
1888 break; 1874 break;
1889 case TIPC_SRC_DROPPABLE: 1875 case TIPC_SRC_DROPPABLE:
1890 res = tipc_portunreliable(tport->ref, &value); 1876 value = tipc_port_unreliable(port);
1891 break; 1877 break;
1892 case TIPC_DEST_DROPPABLE: 1878 case TIPC_DEST_DROPPABLE:
1893 res = tipc_portunreturnable(tport->ref, &value); 1879 value = tipc_port_unreturnable(port);
1894 break; 1880 break;
1895 case TIPC_CONN_TIMEOUT: 1881 case TIPC_CONN_TIMEOUT:
1896 value = tipc_sk(sk)->conn_timeout; 1882 value = tipc_sk(sk)->conn_timeout;
@@ -1925,20 +1911,20 @@ static int getsockopt(struct socket *sock, int lvl, int opt, char __user *ov,
1925static const struct proto_ops msg_ops = { 1911static const struct proto_ops msg_ops = {
1926 .owner = THIS_MODULE, 1912 .owner = THIS_MODULE,
1927 .family = AF_TIPC, 1913 .family = AF_TIPC,
1928 .release = release, 1914 .release = tipc_release,
1929 .bind = bind, 1915 .bind = tipc_bind,
1930 .connect = connect, 1916 .connect = tipc_connect,
1931 .socketpair = sock_no_socketpair, 1917 .socketpair = sock_no_socketpair,
1932 .accept = sock_no_accept, 1918 .accept = sock_no_accept,
1933 .getname = get_name, 1919 .getname = tipc_getname,
1934 .poll = poll, 1920 .poll = tipc_poll,
1935 .ioctl = sock_no_ioctl, 1921 .ioctl = sock_no_ioctl,
1936 .listen = sock_no_listen, 1922 .listen = sock_no_listen,
1937 .shutdown = shutdown, 1923 .shutdown = tipc_shutdown,
1938 .setsockopt = setsockopt, 1924 .setsockopt = tipc_setsockopt,
1939 .getsockopt = getsockopt, 1925 .getsockopt = tipc_getsockopt,
1940 .sendmsg = send_msg, 1926 .sendmsg = tipc_sendmsg,
1941 .recvmsg = recv_msg, 1927 .recvmsg = tipc_recvmsg,
1942 .mmap = sock_no_mmap, 1928 .mmap = sock_no_mmap,
1943 .sendpage = sock_no_sendpage 1929 .sendpage = sock_no_sendpage
1944}; 1930};
@@ -1946,20 +1932,20 @@ static const struct proto_ops msg_ops = {
1946static const struct proto_ops packet_ops = { 1932static const struct proto_ops packet_ops = {
1947 .owner = THIS_MODULE, 1933 .owner = THIS_MODULE,
1948 .family = AF_TIPC, 1934 .family = AF_TIPC,
1949 .release = release, 1935 .release = tipc_release,
1950 .bind = bind, 1936 .bind = tipc_bind,
1951 .connect = connect, 1937 .connect = tipc_connect,
1952 .socketpair = sock_no_socketpair, 1938 .socketpair = sock_no_socketpair,
1953 .accept = accept, 1939 .accept = tipc_accept,
1954 .getname = get_name, 1940 .getname = tipc_getname,
1955 .poll = poll, 1941 .poll = tipc_poll,
1956 .ioctl = sock_no_ioctl, 1942 .ioctl = sock_no_ioctl,
1957 .listen = listen, 1943 .listen = tipc_listen,
1958 .shutdown = shutdown, 1944 .shutdown = tipc_shutdown,
1959 .setsockopt = setsockopt, 1945 .setsockopt = tipc_setsockopt,
1960 .getsockopt = getsockopt, 1946 .getsockopt = tipc_getsockopt,
1961 .sendmsg = send_packet, 1947 .sendmsg = tipc_send_packet,
1962 .recvmsg = recv_msg, 1948 .recvmsg = tipc_recvmsg,
1963 .mmap = sock_no_mmap, 1949 .mmap = sock_no_mmap,
1964 .sendpage = sock_no_sendpage 1950 .sendpage = sock_no_sendpage
1965}; 1951};
@@ -1967,20 +1953,20 @@ static const struct proto_ops packet_ops = {
1967static const struct proto_ops stream_ops = { 1953static const struct proto_ops stream_ops = {
1968 .owner = THIS_MODULE, 1954 .owner = THIS_MODULE,
1969 .family = AF_TIPC, 1955 .family = AF_TIPC,
1970 .release = release, 1956 .release = tipc_release,
1971 .bind = bind, 1957 .bind = tipc_bind,
1972 .connect = connect, 1958 .connect = tipc_connect,
1973 .socketpair = sock_no_socketpair, 1959 .socketpair = sock_no_socketpair,
1974 .accept = accept, 1960 .accept = tipc_accept,
1975 .getname = get_name, 1961 .getname = tipc_getname,
1976 .poll = poll, 1962 .poll = tipc_poll,
1977 .ioctl = sock_no_ioctl, 1963 .ioctl = sock_no_ioctl,
1978 .listen = listen, 1964 .listen = tipc_listen,
1979 .shutdown = shutdown, 1965 .shutdown = tipc_shutdown,
1980 .setsockopt = setsockopt, 1966 .setsockopt = tipc_setsockopt,
1981 .getsockopt = getsockopt, 1967 .getsockopt = tipc_getsockopt,
1982 .sendmsg = send_stream, 1968 .sendmsg = tipc_send_stream,
1983 .recvmsg = recv_stream, 1969 .recvmsg = tipc_recv_stream,
1984 .mmap = sock_no_mmap, 1970 .mmap = sock_no_mmap,
1985 .sendpage = sock_no_sendpage 1971 .sendpage = sock_no_sendpage
1986}; 1972};