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