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.c182
1 files changed, 49 insertions, 133 deletions
diff --git a/net/tipc/socket.c b/net/tipc/socket.c
index adb2eff4a102..09dc5b97e079 100644
--- a/net/tipc/socket.c
+++ b/net/tipc/socket.c
@@ -34,11 +34,12 @@
34 * POSSIBILITY OF SUCH DAMAGE. 34 * POSSIBILITY OF SUCH DAMAGE.
35 */ 35 */
36 36
37#include <net/sock.h>
38
39#include "core.h" 37#include "core.h"
40#include "port.h" 38#include "port.h"
41 39
40#include <linux/export.h>
41#include <net/sock.h>
42
42#define SS_LISTENING -1 /* socket is listening */ 43#define SS_LISTENING -1 /* socket is listening */
43#define SS_READY -2 /* socket is connectionless */ 44#define SS_READY -2 /* socket is connectionless */
44 45
@@ -49,11 +50,11 @@ struct tipc_sock {
49 struct sock sk; 50 struct sock sk;
50 struct tipc_port *p; 51 struct tipc_port *p;
51 struct tipc_portid peer_name; 52 struct tipc_portid peer_name;
52 long conn_timeout; 53 unsigned int conn_timeout;
53}; 54};
54 55
55#define tipc_sk(sk) ((struct tipc_sock *)(sk)) 56#define tipc_sk(sk) ((struct tipc_sock *)(sk))
56#define tipc_sk_port(sk) ((struct tipc_port *)(tipc_sk(sk)->p)) 57#define tipc_sk_port(sk) (tipc_sk(sk)->p)
57 58
58#define tipc_rx_ready(sock) (!skb_queue_empty(&sock->sk->sk_receive_queue) || \ 59#define tipc_rx_ready(sock) (!skb_queue_empty(&sock->sk->sk_receive_queue) || \
59 (sock->state == SS_DISCONNECTING)) 60 (sock->state == SS_DISCONNECTING))
@@ -122,10 +123,9 @@ static atomic_t tipc_queue_size = ATOMIC_INIT(0);
122 * 123 *
123 * Caller must hold socket lock 124 * Caller must hold socket lock
124 */ 125 */
125
126static void advance_rx_queue(struct sock *sk) 126static void advance_rx_queue(struct sock *sk)
127{ 127{
128 buf_discard(__skb_dequeue(&sk->sk_receive_queue)); 128 kfree_skb(__skb_dequeue(&sk->sk_receive_queue));
129 atomic_dec(&tipc_queue_size); 129 atomic_dec(&tipc_queue_size);
130} 130}
131 131
@@ -134,14 +134,13 @@ static void advance_rx_queue(struct sock *sk)
134 * 134 *
135 * Caller must hold socket lock 135 * Caller must hold socket lock
136 */ 136 */
137
138static void discard_rx_queue(struct sock *sk) 137static void discard_rx_queue(struct sock *sk)
139{ 138{
140 struct sk_buff *buf; 139 struct sk_buff *buf;
141 140
142 while ((buf = __skb_dequeue(&sk->sk_receive_queue))) { 141 while ((buf = __skb_dequeue(&sk->sk_receive_queue))) {
143 atomic_dec(&tipc_queue_size); 142 atomic_dec(&tipc_queue_size);
144 buf_discard(buf); 143 kfree_skb(buf);
145 } 144 }
146} 145}
147 146
@@ -150,7 +149,6 @@ static void discard_rx_queue(struct sock *sk)
150 * 149 *
151 * Caller must hold socket lock 150 * Caller must hold socket lock
152 */ 151 */
153
154static void reject_rx_queue(struct sock *sk) 152static void reject_rx_queue(struct sock *sk)
155{ 153{
156 struct sk_buff *buf; 154 struct sk_buff *buf;
@@ -173,7 +171,6 @@ static void reject_rx_queue(struct sock *sk)
173 * 171 *
174 * Returns 0 on success, errno otherwise 172 * Returns 0 on success, errno otherwise
175 */ 173 */
176
177static int tipc_create(struct net *net, struct socket *sock, int protocol, 174static int tipc_create(struct net *net, struct socket *sock, int protocol,
178 int kern) 175 int kern)
179{ 176{
@@ -183,10 +180,6 @@ static int tipc_create(struct net *net, struct socket *sock, int protocol,
183 struct tipc_port *tp_ptr; 180 struct tipc_port *tp_ptr;
184 181
185 /* Validate arguments */ 182 /* Validate arguments */
186
187 if (!net_eq(net, &init_net))
188 return -EAFNOSUPPORT;
189
190 if (unlikely(protocol != 0)) 183 if (unlikely(protocol != 0))
191 return -EPROTONOSUPPORT; 184 return -EPROTONOSUPPORT;
192 185
@@ -209,13 +202,11 @@ static int tipc_create(struct net *net, struct socket *sock, int protocol,
209 } 202 }
210 203
211 /* Allocate socket's protocol area */ 204 /* Allocate socket's protocol area */
212
213 sk = sk_alloc(net, AF_TIPC, GFP_KERNEL, &tipc_proto); 205 sk = sk_alloc(net, AF_TIPC, GFP_KERNEL, &tipc_proto);
214 if (sk == NULL) 206 if (sk == NULL)
215 return -ENOMEM; 207 return -ENOMEM;
216 208
217 /* Allocate TIPC port for socket to use */ 209 /* Allocate TIPC port for socket to use */
218
219 tp_ptr = tipc_createport_raw(sk, &dispatch, &wakeupdispatch, 210 tp_ptr = tipc_createport_raw(sk, &dispatch, &wakeupdispatch,
220 TIPC_LOW_IMPORTANCE); 211 TIPC_LOW_IMPORTANCE);
221 if (unlikely(!tp_ptr)) { 212 if (unlikely(!tp_ptr)) {
@@ -224,14 +215,13 @@ static int tipc_create(struct net *net, struct socket *sock, int protocol,
224 } 215 }
225 216
226 /* Finish initializing socket data structures */ 217 /* Finish initializing socket data structures */
227
228 sock->ops = ops; 218 sock->ops = ops;
229 sock->state = state; 219 sock->state = state;
230 220
231 sock_init_data(sock, sk); 221 sock_init_data(sock, sk);
232 sk->sk_backlog_rcv = backlog_rcv; 222 sk->sk_backlog_rcv = backlog_rcv;
233 tipc_sk(sk)->p = tp_ptr; 223 tipc_sk(sk)->p = tp_ptr;
234 tipc_sk(sk)->conn_timeout = msecs_to_jiffies(CONN_TIMEOUT_DEFAULT); 224 tipc_sk(sk)->conn_timeout = CONN_TIMEOUT_DEFAULT;
235 225
236 spin_unlock_bh(tp_ptr->lock); 226 spin_unlock_bh(tp_ptr->lock);
237 227
@@ -260,7 +250,6 @@ static int tipc_create(struct net *net, struct socket *sock, int protocol,
260 * 250 *
261 * Returns 0 on success, errno otherwise 251 * Returns 0 on success, errno otherwise
262 */ 252 */
263
264static int release(struct socket *sock) 253static int release(struct socket *sock)
265{ 254{
266 struct sock *sk = sock->sk; 255 struct sock *sk = sock->sk;
@@ -272,7 +261,6 @@ static int release(struct socket *sock)
272 * Exit if socket isn't fully initialized (occurs when a failed accept() 261 * Exit if socket isn't fully initialized (occurs when a failed accept()
273 * releases a pre-allocated child socket that was never used) 262 * releases a pre-allocated child socket that was never used)
274 */ 263 */
275
276 if (sk == NULL) 264 if (sk == NULL)
277 return 0; 265 return 0;
278 266
@@ -283,14 +271,13 @@ static int release(struct socket *sock)
283 * Reject all unreceived messages, except on an active connection 271 * Reject all unreceived messages, except on an active connection
284 * (which disconnects locally & sends a 'FIN+' to peer) 272 * (which disconnects locally & sends a 'FIN+' to peer)
285 */ 273 */
286
287 while (sock->state != SS_DISCONNECTING) { 274 while (sock->state != SS_DISCONNECTING) {
288 buf = __skb_dequeue(&sk->sk_receive_queue); 275 buf = __skb_dequeue(&sk->sk_receive_queue);
289 if (buf == NULL) 276 if (buf == NULL)
290 break; 277 break;
291 atomic_dec(&tipc_queue_size); 278 atomic_dec(&tipc_queue_size);
292 if (TIPC_SKB_CB(buf)->handle != 0) 279 if (TIPC_SKB_CB(buf)->handle != 0)
293 buf_discard(buf); 280 kfree_skb(buf);
294 else { 281 else {
295 if ((sock->state == SS_CONNECTING) || 282 if ((sock->state == SS_CONNECTING) ||
296 (sock->state == SS_CONNECTED)) { 283 (sock->state == SS_CONNECTED)) {
@@ -305,15 +292,12 @@ static int release(struct socket *sock)
305 * Delete TIPC port; this ensures no more messages are queued 292 * Delete TIPC port; this ensures no more messages are queued
306 * (also disconnects an active connection & sends a 'FIN-' to peer) 293 * (also disconnects an active connection & sends a 'FIN-' to peer)
307 */ 294 */
308
309 res = tipc_deleteport(tport->ref); 295 res = tipc_deleteport(tport->ref);
310 296
311 /* Discard any remaining (connection-based) messages in receive queue */ 297 /* Discard any remaining (connection-based) messages in receive queue */
312
313 discard_rx_queue(sk); 298 discard_rx_queue(sk);
314 299
315 /* Reject any messages that accumulated in backlog queue */ 300 /* Reject any messages that accumulated in backlog queue */
316
317 sock->state = SS_DISCONNECTING; 301 sock->state = SS_DISCONNECTING;
318 release_sock(sk); 302 release_sock(sk);
319 303
@@ -338,7 +322,6 @@ static int release(struct socket *sock)
338 * NOTE: This routine doesn't need to take the socket lock since it doesn't 322 * NOTE: This routine doesn't need to take the socket lock since it doesn't
339 * access any non-constant socket information. 323 * access any non-constant socket information.
340 */ 324 */
341
342static int bind(struct socket *sock, struct sockaddr *uaddr, int uaddr_len) 325static int bind(struct socket *sock, struct sockaddr *uaddr, int uaddr_len)
343{ 326{
344 struct sockaddr_tipc *addr = (struct sockaddr_tipc *)uaddr; 327 struct sockaddr_tipc *addr = (struct sockaddr_tipc *)uaddr;
@@ -357,6 +340,9 @@ static int bind(struct socket *sock, struct sockaddr *uaddr, int uaddr_len)
357 else if (addr->addrtype != TIPC_ADDR_NAMESEQ) 340 else if (addr->addrtype != TIPC_ADDR_NAMESEQ)
358 return -EAFNOSUPPORT; 341 return -EAFNOSUPPORT;
359 342
343 if (addr->addr.nameseq.type < TIPC_RESERVED_TYPES)
344 return -EACCES;
345
360 return (addr->scope > 0) ? 346 return (addr->scope > 0) ?
361 tipc_publish(portref, addr->scope, &addr->addr.nameseq) : 347 tipc_publish(portref, addr->scope, &addr->addr.nameseq) :
362 tipc_withdraw(portref, -addr->scope, &addr->addr.nameseq); 348 tipc_withdraw(portref, -addr->scope, &addr->addr.nameseq);
@@ -375,7 +361,6 @@ static int bind(struct socket *sock, struct sockaddr *uaddr, int uaddr_len)
375 * accesses socket information that is unchanging (or which changes in 361 * accesses socket information that is unchanging (or which changes in
376 * a completely predictable manner). 362 * a completely predictable manner).
377 */ 363 */
378
379static int get_name(struct socket *sock, struct sockaddr *uaddr, 364static int get_name(struct socket *sock, struct sockaddr *uaddr,
380 int *uaddr_len, int peer) 365 int *uaddr_len, int peer)
381{ 366{
@@ -443,7 +428,6 @@ static int get_name(struct socket *sock, struct sockaddr *uaddr,
443 * imply that the operation will succeed, merely that it should be performed 428 * imply that the operation will succeed, merely that it should be performed
444 * and will not block. 429 * and will not block.
445 */ 430 */
446
447static unsigned int poll(struct file *file, struct socket *sock, 431static unsigned int poll(struct file *file, struct socket *sock,
448 poll_table *wait) 432 poll_table *wait)
449{ 433{
@@ -481,7 +465,6 @@ static unsigned int poll(struct file *file, struct socket *sock,
481 * 465 *
482 * Returns 0 if permission is granted, otherwise errno 466 * Returns 0 if permission is granted, otherwise errno
483 */ 467 */
484
485static int dest_name_check(struct sockaddr_tipc *dest, struct msghdr *m) 468static int dest_name_check(struct sockaddr_tipc *dest, struct msghdr *m)
486{ 469{
487 struct tipc_cfg_msg_hdr hdr; 470 struct tipc_cfg_msg_hdr hdr;
@@ -517,7 +500,6 @@ static int dest_name_check(struct sockaddr_tipc *dest, struct msghdr *m)
517 * 500 *
518 * Returns the number of bytes sent on success, or errno otherwise 501 * Returns the number of bytes sent on success, or errno otherwise
519 */ 502 */
520
521static int send_msg(struct kiocb *iocb, struct socket *sock, 503static int send_msg(struct kiocb *iocb, struct socket *sock,
522 struct msghdr *m, size_t total_len) 504 struct msghdr *m, size_t total_len)
523{ 505{
@@ -525,6 +507,7 @@ static int send_msg(struct kiocb *iocb, struct socket *sock,
525 struct tipc_port *tport = tipc_sk_port(sk); 507 struct tipc_port *tport = tipc_sk_port(sk);
526 struct sockaddr_tipc *dest = (struct sockaddr_tipc *)m->msg_name; 508 struct sockaddr_tipc *dest = (struct sockaddr_tipc *)m->msg_name;
527 int needs_conn; 509 int needs_conn;
510 long timeout_val;
528 int res = -EINVAL; 511 int res = -EINVAL;
529 512
530 if (unlikely(!dest)) 513 if (unlikely(!dest))
@@ -533,7 +516,7 @@ static int send_msg(struct kiocb *iocb, struct socket *sock,
533 (dest->family != AF_TIPC))) 516 (dest->family != AF_TIPC)))
534 return -EINVAL; 517 return -EINVAL;
535 if ((total_len > TIPC_MAX_USER_MSG_SIZE) || 518 if ((total_len > TIPC_MAX_USER_MSG_SIZE) ||
536 (m->msg_iovlen > (unsigned)INT_MAX)) 519 (m->msg_iovlen > (unsigned int)INT_MAX))
537 return -EMSGSIZE; 520 return -EMSGSIZE;
538 521
539 if (iocb) 522 if (iocb)
@@ -560,10 +543,11 @@ static int send_msg(struct kiocb *iocb, struct socket *sock,
560 } 543 }
561 544
562 /* Abort any pending connection attempts (very unlikely) */ 545 /* Abort any pending connection attempts (very unlikely) */
563
564 reject_rx_queue(sk); 546 reject_rx_queue(sk);
565 } 547 }
566 548
549 timeout_val = sock_sndtimeo(sk, m->msg_flags & MSG_DONTWAIT);
550
567 do { 551 do {
568 if (dest->addrtype == TIPC_ADDR_NAME) { 552 if (dest->addrtype == TIPC_ADDR_NAME) {
569 res = dest_name_check(dest, m); 553 res = dest_name_check(dest, m);
@@ -600,16 +584,14 @@ static int send_msg(struct kiocb *iocb, struct socket *sock,
600 sock->state = SS_CONNECTING; 584 sock->state = SS_CONNECTING;
601 break; 585 break;
602 } 586 }
603 if (m->msg_flags & MSG_DONTWAIT) { 587 if (timeout_val <= 0L) {
604 res = -EWOULDBLOCK; 588 res = timeout_val ? timeout_val : -EWOULDBLOCK;
605 break; 589 break;
606 } 590 }
607 release_sock(sk); 591 release_sock(sk);
608 res = wait_event_interruptible(*sk_sleep(sk), 592 timeout_val = wait_event_interruptible_timeout(*sk_sleep(sk),
609 !tport->congested); 593 !tport->congested, timeout_val);
610 lock_sock(sk); 594 lock_sock(sk);
611 if (res)
612 break;
613 } while (1); 595 } while (1);
614 596
615exit: 597exit:
@@ -629,27 +611,28 @@ exit:
629 * 611 *
630 * Returns the number of bytes sent on success, or errno otherwise 612 * Returns the number of bytes sent on success, or errno otherwise
631 */ 613 */
632
633static int send_packet(struct kiocb *iocb, struct socket *sock, 614static int send_packet(struct kiocb *iocb, struct socket *sock,
634 struct msghdr *m, size_t total_len) 615 struct msghdr *m, size_t total_len)
635{ 616{
636 struct sock *sk = sock->sk; 617 struct sock *sk = sock->sk;
637 struct tipc_port *tport = tipc_sk_port(sk); 618 struct tipc_port *tport = tipc_sk_port(sk);
638 struct sockaddr_tipc *dest = (struct sockaddr_tipc *)m->msg_name; 619 struct sockaddr_tipc *dest = (struct sockaddr_tipc *)m->msg_name;
620 long timeout_val;
639 int res; 621 int res;
640 622
641 /* Handle implied connection establishment */ 623 /* Handle implied connection establishment */
642
643 if (unlikely(dest)) 624 if (unlikely(dest))
644 return send_msg(iocb, sock, m, total_len); 625 return send_msg(iocb, sock, m, total_len);
645 626
646 if ((total_len > TIPC_MAX_USER_MSG_SIZE) || 627 if ((total_len > TIPC_MAX_USER_MSG_SIZE) ||
647 (m->msg_iovlen > (unsigned)INT_MAX)) 628 (m->msg_iovlen > (unsigned int)INT_MAX))
648 return -EMSGSIZE; 629 return -EMSGSIZE;
649 630
650 if (iocb) 631 if (iocb)
651 lock_sock(sk); 632 lock_sock(sk);
652 633
634 timeout_val = sock_sndtimeo(sk, m->msg_flags & MSG_DONTWAIT);
635
653 do { 636 do {
654 if (unlikely(sock->state != SS_CONNECTED)) { 637 if (unlikely(sock->state != SS_CONNECTED)) {
655 if (sock->state == SS_DISCONNECTING) 638 if (sock->state == SS_DISCONNECTING)
@@ -663,16 +646,14 @@ static int send_packet(struct kiocb *iocb, struct socket *sock,
663 total_len); 646 total_len);
664 if (likely(res != -ELINKCONG)) 647 if (likely(res != -ELINKCONG))
665 break; 648 break;
666 if (m->msg_flags & MSG_DONTWAIT) { 649 if (timeout_val <= 0L) {
667 res = -EWOULDBLOCK; 650 res = timeout_val ? timeout_val : -EWOULDBLOCK;
668 break; 651 break;
669 } 652 }
670 release_sock(sk); 653 release_sock(sk);
671 res = wait_event_interruptible(*sk_sleep(sk), 654 timeout_val = wait_event_interruptible_timeout(*sk_sleep(sk),
672 (!tport->congested || !tport->connected)); 655 (!tport->congested || !tport->connected), timeout_val);
673 lock_sock(sk); 656 lock_sock(sk);
674 if (res)
675 break;
676 } while (1); 657 } while (1);
677 658
678 if (iocb) 659 if (iocb)
@@ -692,7 +673,6 @@ static int send_packet(struct kiocb *iocb, struct socket *sock,
692 * Returns the number of bytes sent on success (or partial success), 673 * Returns the number of bytes sent on success (or partial success),
693 * or errno if no data sent 674 * or errno if no data sent
694 */ 675 */
695
696static int send_stream(struct kiocb *iocb, struct socket *sock, 676static int send_stream(struct kiocb *iocb, struct socket *sock,
697 struct msghdr *m, size_t total_len) 677 struct msghdr *m, size_t total_len)
698{ 678{
@@ -712,7 +692,6 @@ static int send_stream(struct kiocb *iocb, struct socket *sock,
712 lock_sock(sk); 692 lock_sock(sk);
713 693
714 /* Handle special cases where there is no connection */ 694 /* Handle special cases where there is no connection */
715
716 if (unlikely(sock->state != SS_CONNECTED)) { 695 if (unlikely(sock->state != SS_CONNECTED)) {
717 if (sock->state == SS_UNCONNECTED) { 696 if (sock->state == SS_UNCONNECTED) {
718 res = send_packet(NULL, sock, m, total_len); 697 res = send_packet(NULL, sock, m, total_len);
@@ -731,8 +710,8 @@ static int send_stream(struct kiocb *iocb, struct socket *sock,
731 goto exit; 710 goto exit;
732 } 711 }
733 712
734 if ((total_len > (unsigned)INT_MAX) || 713 if ((total_len > (unsigned int)INT_MAX) ||
735 (m->msg_iovlen > (unsigned)INT_MAX)) { 714 (m->msg_iovlen > (unsigned int)INT_MAX)) {
736 res = -EMSGSIZE; 715 res = -EMSGSIZE;
737 goto exit; 716 goto exit;
738 } 717 }
@@ -744,7 +723,6 @@ static int send_stream(struct kiocb *iocb, struct socket *sock,
744 * (i.e. one large iovec entry), but could be improved to pass sets 723 * (i.e. one large iovec entry), but could be improved to pass sets
745 * of small iovec entries into send_packet(). 724 * of small iovec entries into send_packet().
746 */ 725 */
747
748 curr_iov = m->msg_iov; 726 curr_iov = m->msg_iov;
749 curr_iovlen = m->msg_iovlen; 727 curr_iovlen = m->msg_iovlen;
750 my_msg.msg_iov = &my_iov; 728 my_msg.msg_iov = &my_iov;
@@ -793,7 +771,6 @@ exit:
793 * 771 *
794 * Returns 0 on success, errno otherwise 772 * Returns 0 on success, errno otherwise
795 */ 773 */
796
797static int auto_connect(struct socket *sock, struct tipc_msg *msg) 774static int auto_connect(struct socket *sock, struct tipc_msg *msg)
798{ 775{
799 struct tipc_sock *tsock = tipc_sk(sock->sk); 776 struct tipc_sock *tsock = tipc_sk(sock->sk);
@@ -818,7 +795,6 @@ static int auto_connect(struct socket *sock, struct tipc_msg *msg)
818 * 795 *
819 * Note: Address is not captured if not requested by receiver. 796 * Note: Address is not captured if not requested by receiver.
820 */ 797 */
821
822static void set_orig_addr(struct msghdr *m, struct tipc_msg *msg) 798static void set_orig_addr(struct msghdr *m, struct tipc_msg *msg)
823{ 799{
824 struct sockaddr_tipc *addr = (struct sockaddr_tipc *)m->msg_name; 800 struct sockaddr_tipc *addr = (struct sockaddr_tipc *)m->msg_name;
@@ -844,7 +820,6 @@ static void set_orig_addr(struct msghdr *m, struct tipc_msg *msg)
844 * 820 *
845 * Returns 0 if successful, otherwise errno 821 * Returns 0 if successful, otherwise errno
846 */ 822 */
847
848static int anc_data_recv(struct msghdr *m, struct tipc_msg *msg, 823static int anc_data_recv(struct msghdr *m, struct tipc_msg *msg,
849 struct tipc_port *tport) 824 struct tipc_port *tport)
850{ 825{
@@ -858,7 +833,6 @@ static int anc_data_recv(struct msghdr *m, struct tipc_msg *msg,
858 return 0; 833 return 0;
859 834
860 /* Optionally capture errored message object(s) */ 835 /* Optionally capture errored message object(s) */
861
862 err = msg ? msg_errcode(msg) : 0; 836 err = msg ? msg_errcode(msg) : 0;
863 if (unlikely(err)) { 837 if (unlikely(err)) {
864 anc_data[0] = err; 838 anc_data[0] = err;
@@ -875,7 +849,6 @@ static int anc_data_recv(struct msghdr *m, struct tipc_msg *msg,
875 } 849 }
876 850
877 /* Optionally capture message destination object */ 851 /* Optionally capture message destination object */
878
879 dest_type = msg ? msg_type(msg) : TIPC_DIRECT_MSG; 852 dest_type = msg ? msg_type(msg) : TIPC_DIRECT_MSG;
880 switch (dest_type) { 853 switch (dest_type) {
881 case TIPC_NAMED_MSG: 854 case TIPC_NAMED_MSG:
@@ -920,7 +893,6 @@ static int anc_data_recv(struct msghdr *m, struct tipc_msg *msg,
920 * 893 *
921 * Returns size of returned message data, errno otherwise 894 * Returns size of returned message data, errno otherwise
922 */ 895 */
923
924static int recv_msg(struct kiocb *iocb, struct socket *sock, 896static int recv_msg(struct kiocb *iocb, struct socket *sock,
925 struct msghdr *m, size_t buf_len, int flags) 897 struct msghdr *m, size_t buf_len, int flags)
926{ 898{
@@ -934,7 +906,6 @@ static int recv_msg(struct kiocb *iocb, struct socket *sock,
934 int res; 906 int res;
935 907
936 /* Catch invalid receive requests */ 908 /* Catch invalid receive requests */
937
938 if (unlikely(!buf_len)) 909 if (unlikely(!buf_len))
939 return -EINVAL; 910 return -EINVAL;
940 911
@@ -949,7 +920,6 @@ static int recv_msg(struct kiocb *iocb, struct socket *sock,
949restart: 920restart:
950 921
951 /* Look for a message in receive queue; wait if necessary */ 922 /* Look for a message in receive queue; wait if necessary */
952
953 while (skb_queue_empty(&sk->sk_receive_queue)) { 923 while (skb_queue_empty(&sk->sk_receive_queue)) {
954 if (sock->state == SS_DISCONNECTING) { 924 if (sock->state == SS_DISCONNECTING) {
955 res = -ENOTCONN; 925 res = -ENOTCONN;
@@ -967,14 +937,12 @@ restart:
967 } 937 }
968 938
969 /* Look at first message in receive queue */ 939 /* Look at first message in receive queue */
970
971 buf = skb_peek(&sk->sk_receive_queue); 940 buf = skb_peek(&sk->sk_receive_queue);
972 msg = buf_msg(buf); 941 msg = buf_msg(buf);
973 sz = msg_data_sz(msg); 942 sz = msg_data_sz(msg);
974 err = msg_errcode(msg); 943 err = msg_errcode(msg);
975 944
976 /* Complete connection setup for an implied connect */ 945 /* Complete connection setup for an implied connect */
977
978 if (unlikely(sock->state == SS_CONNECTING)) { 946 if (unlikely(sock->state == SS_CONNECTING)) {
979 res = auto_connect(sock, msg); 947 res = auto_connect(sock, msg);
980 if (res) 948 if (res)
@@ -982,24 +950,20 @@ restart:
982 } 950 }
983 951
984 /* Discard an empty non-errored message & try again */ 952 /* Discard an empty non-errored message & try again */
985
986 if ((!sz) && (!err)) { 953 if ((!sz) && (!err)) {
987 advance_rx_queue(sk); 954 advance_rx_queue(sk);
988 goto restart; 955 goto restart;
989 } 956 }
990 957
991 /* Capture sender's address (optional) */ 958 /* Capture sender's address (optional) */
992
993 set_orig_addr(m, msg); 959 set_orig_addr(m, msg);
994 960
995 /* Capture ancillary data (optional) */ 961 /* Capture ancillary data (optional) */
996
997 res = anc_data_recv(m, msg, tport); 962 res = anc_data_recv(m, msg, tport);
998 if (res) 963 if (res)
999 goto exit; 964 goto exit;
1000 965
1001 /* Capture message data (if valid) & compute return value (always) */ 966 /* Capture message data (if valid) & compute return value (always) */
1002
1003 if (!err) { 967 if (!err) {
1004 if (unlikely(buf_len < sz)) { 968 if (unlikely(buf_len < sz)) {
1005 sz = buf_len; 969 sz = buf_len;
@@ -1019,7 +983,6 @@ restart:
1019 } 983 }
1020 984
1021 /* Consume received message (optional) */ 985 /* Consume received message (optional) */
1022
1023 if (likely(!(flags & MSG_PEEK))) { 986 if (likely(!(flags & MSG_PEEK))) {
1024 if ((sock->state != SS_READY) && 987 if ((sock->state != SS_READY) &&
1025 (++tport->conn_unacked >= TIPC_FLOW_CONTROL_WIN)) 988 (++tport->conn_unacked >= TIPC_FLOW_CONTROL_WIN))
@@ -1043,7 +1006,6 @@ exit:
1043 * 1006 *
1044 * Returns size of returned message data, errno otherwise 1007 * Returns size of returned message data, errno otherwise
1045 */ 1008 */
1046
1047static int recv_stream(struct kiocb *iocb, struct socket *sock, 1009static int recv_stream(struct kiocb *iocb, struct socket *sock,
1048 struct msghdr *m, size_t buf_len, int flags) 1010 struct msghdr *m, size_t buf_len, int flags)
1049{ 1011{
@@ -1059,7 +1021,6 @@ static int recv_stream(struct kiocb *iocb, struct socket *sock,
1059 int res = 0; 1021 int res = 0;
1060 1022
1061 /* Catch invalid receive attempts */ 1023 /* Catch invalid receive attempts */
1062
1063 if (unlikely(!buf_len)) 1024 if (unlikely(!buf_len))
1064 return -EINVAL; 1025 return -EINVAL;
1065 1026
@@ -1073,10 +1034,9 @@ static int recv_stream(struct kiocb *iocb, struct socket *sock,
1073 1034
1074 target = sock_rcvlowat(sk, flags & MSG_WAITALL, buf_len); 1035 target = sock_rcvlowat(sk, flags & MSG_WAITALL, buf_len);
1075 timeout = sock_rcvtimeo(sk, flags & MSG_DONTWAIT); 1036 timeout = sock_rcvtimeo(sk, flags & MSG_DONTWAIT);
1076restart:
1077 1037
1038restart:
1078 /* Look for a message in receive queue; wait if necessary */ 1039 /* Look for a message in receive queue; wait if necessary */
1079
1080 while (skb_queue_empty(&sk->sk_receive_queue)) { 1040 while (skb_queue_empty(&sk->sk_receive_queue)) {
1081 if (sock->state == SS_DISCONNECTING) { 1041 if (sock->state == SS_DISCONNECTING) {
1082 res = -ENOTCONN; 1042 res = -ENOTCONN;
@@ -1094,21 +1054,18 @@ restart:
1094 } 1054 }
1095 1055
1096 /* Look at first message in receive queue */ 1056 /* Look at first message in receive queue */
1097
1098 buf = skb_peek(&sk->sk_receive_queue); 1057 buf = skb_peek(&sk->sk_receive_queue);
1099 msg = buf_msg(buf); 1058 msg = buf_msg(buf);
1100 sz = msg_data_sz(msg); 1059 sz = msg_data_sz(msg);
1101 err = msg_errcode(msg); 1060 err = msg_errcode(msg);
1102 1061
1103 /* Discard an empty non-errored message & try again */ 1062 /* Discard an empty non-errored message & try again */
1104
1105 if ((!sz) && (!err)) { 1063 if ((!sz) && (!err)) {
1106 advance_rx_queue(sk); 1064 advance_rx_queue(sk);
1107 goto restart; 1065 goto restart;
1108 } 1066 }
1109 1067
1110 /* Optionally capture sender's address & ancillary data of first msg */ 1068 /* Optionally capture sender's address & ancillary data of first msg */
1111
1112 if (sz_copied == 0) { 1069 if (sz_copied == 0) {
1113 set_orig_addr(m, msg); 1070 set_orig_addr(m, msg);
1114 res = anc_data_recv(m, msg, tport); 1071 res = anc_data_recv(m, msg, tport);
@@ -1117,7 +1074,6 @@ restart:
1117 } 1074 }
1118 1075
1119 /* Capture message data (if valid) & compute return value (always) */ 1076 /* Capture message data (if valid) & compute return value (always) */
1120
1121 if (!err) { 1077 if (!err) {
1122 u32 offset = (u32)(unsigned long)(TIPC_SKB_CB(buf)->handle); 1078 u32 offset = (u32)(unsigned long)(TIPC_SKB_CB(buf)->handle);
1123 1079
@@ -1149,7 +1105,6 @@ restart:
1149 } 1105 }
1150 1106
1151 /* Consume received message (optional) */ 1107 /* Consume received message (optional) */
1152
1153 if (likely(!(flags & MSG_PEEK))) { 1108 if (likely(!(flags & MSG_PEEK))) {
1154 if (unlikely(++tport->conn_unacked >= TIPC_FLOW_CONTROL_WIN)) 1109 if (unlikely(++tport->conn_unacked >= TIPC_FLOW_CONTROL_WIN))
1155 tipc_acknowledge(tport->ref, tport->conn_unacked); 1110 tipc_acknowledge(tport->ref, tport->conn_unacked);
@@ -1157,7 +1112,6 @@ restart:
1157 } 1112 }
1158 1113
1159 /* Loop around if more data is required */ 1114 /* Loop around if more data is required */
1160
1161 if ((sz_copied < buf_len) && /* didn't get all requested data */ 1115 if ((sz_copied < buf_len) && /* didn't get all requested data */
1162 (!skb_queue_empty(&sk->sk_receive_queue) || 1116 (!skb_queue_empty(&sk->sk_receive_queue) ||
1163 (sz_copied < target)) && /* and more is ready or required */ 1117 (sz_copied < target)) && /* and more is ready or required */
@@ -1178,7 +1132,6 @@ exit:
1178 * 1132 *
1179 * Returns 1 if queue is unable to accept message, 0 otherwise 1133 * Returns 1 if queue is unable to accept message, 0 otherwise
1180 */ 1134 */
1181
1182static int rx_queue_full(struct tipc_msg *msg, u32 queue_size, u32 base) 1135static int rx_queue_full(struct tipc_msg *msg, u32 queue_size, u32 base)
1183{ 1136{
1184 u32 threshold; 1137 u32 threshold;
@@ -1211,7 +1164,6 @@ static int rx_queue_full(struct tipc_msg *msg, u32 queue_size, u32 base)
1211 * 1164 *
1212 * Returns TIPC error status code (TIPC_OK if message is not to be rejected) 1165 * Returns TIPC error status code (TIPC_OK if message is not to be rejected)
1213 */ 1166 */
1214
1215static u32 filter_rcv(struct sock *sk, struct sk_buff *buf) 1167static u32 filter_rcv(struct sock *sk, struct sk_buff *buf)
1216{ 1168{
1217 struct socket *sock = sk->sk_socket; 1169 struct socket *sock = sk->sk_socket;
@@ -1219,12 +1171,8 @@ static u32 filter_rcv(struct sock *sk, struct sk_buff *buf)
1219 u32 recv_q_len; 1171 u32 recv_q_len;
1220 1172
1221 /* Reject message if it is wrong sort of message for socket */ 1173 /* Reject message if it is wrong sort of message for socket */
1222 1174 if (msg_type(msg) > TIPC_DIRECT_MSG)
1223 /* 1175 return TIPC_ERR_NO_PORT;
1224 * WOULD IT BE BETTER TO JUST DISCARD THESE MESSAGES INSTEAD?
1225 * "NO PORT" ISN'T REALLY THE RIGHT ERROR CODE, AND THERE MAY
1226 * BE SECURITY IMPLICATIONS INHERENT IN REJECTING INVALID TRAFFIC
1227 */
1228 1176
1229 if (sock->state == SS_READY) { 1177 if (sock->state == SS_READY) {
1230 if (msg_connected(msg)) 1178 if (msg_connected(msg))
@@ -1233,7 +1181,8 @@ static u32 filter_rcv(struct sock *sk, struct sk_buff *buf)
1233 if (msg_mcast(msg)) 1181 if (msg_mcast(msg))
1234 return TIPC_ERR_NO_PORT; 1182 return TIPC_ERR_NO_PORT;
1235 if (sock->state == SS_CONNECTED) { 1183 if (sock->state == SS_CONNECTED) {
1236 if (!msg_connected(msg)) 1184 if (!msg_connected(msg) ||
1185 !tipc_port_peer_msg(tipc_sk_port(sk), msg))
1237 return TIPC_ERR_NO_PORT; 1186 return TIPC_ERR_NO_PORT;
1238 } else if (sock->state == SS_CONNECTING) { 1187 } else if (sock->state == SS_CONNECTING) {
1239 if (!msg_connected(msg) && (msg_errcode(msg) == 0)) 1188 if (!msg_connected(msg) && (msg_errcode(msg) == 0))
@@ -1250,7 +1199,6 @@ static u32 filter_rcv(struct sock *sk, struct sk_buff *buf)
1250 } 1199 }
1251 1200
1252 /* Reject message if there isn't room to queue it */ 1201 /* Reject message if there isn't room to queue it */
1253
1254 recv_q_len = (u32)atomic_read(&tipc_queue_size); 1202 recv_q_len = (u32)atomic_read(&tipc_queue_size);
1255 if (unlikely(recv_q_len >= OVERLOAD_LIMIT_BASE)) { 1203 if (unlikely(recv_q_len >= OVERLOAD_LIMIT_BASE)) {
1256 if (rx_queue_full(msg, recv_q_len, OVERLOAD_LIMIT_BASE)) 1204 if (rx_queue_full(msg, recv_q_len, OVERLOAD_LIMIT_BASE))
@@ -1263,13 +1211,11 @@ static u32 filter_rcv(struct sock *sk, struct sk_buff *buf)
1263 } 1211 }
1264 1212
1265 /* Enqueue message (finally!) */ 1213 /* Enqueue message (finally!) */
1266
1267 TIPC_SKB_CB(buf)->handle = 0; 1214 TIPC_SKB_CB(buf)->handle = 0;
1268 atomic_inc(&tipc_queue_size); 1215 atomic_inc(&tipc_queue_size);
1269 __skb_queue_tail(&sk->sk_receive_queue, buf); 1216 __skb_queue_tail(&sk->sk_receive_queue, buf);
1270 1217
1271 /* Initiate connection termination for an incoming 'FIN' */ 1218 /* Initiate connection termination for an incoming 'FIN' */
1272
1273 if (unlikely(msg_errcode(msg) && (sock->state == SS_CONNECTED))) { 1219 if (unlikely(msg_errcode(msg) && (sock->state == SS_CONNECTED))) {
1274 sock->state = SS_DISCONNECTING; 1220 sock->state = SS_DISCONNECTING;
1275 tipc_disconnect_port(tipc_sk_port(sk)); 1221 tipc_disconnect_port(tipc_sk_port(sk));
@@ -1289,7 +1235,6 @@ static u32 filter_rcv(struct sock *sk, struct sk_buff *buf)
1289 * 1235 *
1290 * Returns 0 1236 * Returns 0
1291 */ 1237 */
1292
1293static int backlog_rcv(struct sock *sk, struct sk_buff *buf) 1238static int backlog_rcv(struct sock *sk, struct sk_buff *buf)
1294{ 1239{
1295 u32 res; 1240 u32 res;
@@ -1309,7 +1254,6 @@ static int backlog_rcv(struct sock *sk, struct sk_buff *buf)
1309 * 1254 *
1310 * Returns TIPC error status code (TIPC_OK if message is not to be rejected) 1255 * Returns TIPC error status code (TIPC_OK if message is not to be rejected)
1311 */ 1256 */
1312
1313static u32 dispatch(struct tipc_port *tport, struct sk_buff *buf) 1257static u32 dispatch(struct tipc_port *tport, struct sk_buff *buf)
1314{ 1258{
1315 struct sock *sk = (struct sock *)tport->usr_handle; 1259 struct sock *sk = (struct sock *)tport->usr_handle;
@@ -1321,12 +1265,11 @@ static u32 dispatch(struct tipc_port *tport, struct sk_buff *buf)
1321 * This code is based on sk_receive_skb(), but must be distinct from it 1265 * This code is based on sk_receive_skb(), but must be distinct from it
1322 * since a TIPC-specific filter/reject mechanism is utilized 1266 * since a TIPC-specific filter/reject mechanism is utilized
1323 */ 1267 */
1324
1325 bh_lock_sock(sk); 1268 bh_lock_sock(sk);
1326 if (!sock_owned_by_user(sk)) { 1269 if (!sock_owned_by_user(sk)) {
1327 res = filter_rcv(sk, buf); 1270 res = filter_rcv(sk, buf);
1328 } else { 1271 } else {
1329 if (sk_add_backlog(sk, buf)) 1272 if (sk_add_backlog(sk, buf, sk->sk_rcvbuf))
1330 res = TIPC_ERR_OVERLOAD; 1273 res = TIPC_ERR_OVERLOAD;
1331 else 1274 else
1332 res = TIPC_OK; 1275 res = TIPC_OK;
@@ -1342,7 +1285,6 @@ static u32 dispatch(struct tipc_port *tport, struct sk_buff *buf)
1342 * 1285 *
1343 * Called with port lock already taken. 1286 * Called with port lock already taken.
1344 */ 1287 */
1345
1346static void wakeupdispatch(struct tipc_port *tport) 1288static void wakeupdispatch(struct tipc_port *tport)
1347{ 1289{
1348 struct sock *sk = (struct sock *)tport->usr_handle; 1290 struct sock *sk = (struct sock *)tport->usr_handle;
@@ -1360,7 +1302,6 @@ static void wakeupdispatch(struct tipc_port *tport)
1360 * 1302 *
1361 * Returns 0 on success, errno otherwise 1303 * Returns 0 on success, errno otherwise
1362 */ 1304 */
1363
1364static int connect(struct socket *sock, struct sockaddr *dest, int destlen, 1305static int connect(struct socket *sock, struct sockaddr *dest, int destlen,
1365 int flags) 1306 int flags)
1366{ 1307{
@@ -1369,27 +1310,24 @@ static int connect(struct socket *sock, struct sockaddr *dest, int destlen,
1369 struct msghdr m = {NULL,}; 1310 struct msghdr m = {NULL,};
1370 struct sk_buff *buf; 1311 struct sk_buff *buf;
1371 struct tipc_msg *msg; 1312 struct tipc_msg *msg;
1372 long timeout; 1313 unsigned int timeout;
1373 int res; 1314 int res;
1374 1315
1375 lock_sock(sk); 1316 lock_sock(sk);
1376 1317
1377 /* For now, TIPC does not allow use of connect() with DGRAM/RDM types */ 1318 /* For now, TIPC does not allow use of connect() with DGRAM/RDM types */
1378
1379 if (sock->state == SS_READY) { 1319 if (sock->state == SS_READY) {
1380 res = -EOPNOTSUPP; 1320 res = -EOPNOTSUPP;
1381 goto exit; 1321 goto exit;
1382 } 1322 }
1383 1323
1384 /* For now, TIPC does not support the non-blocking form of connect() */ 1324 /* For now, TIPC does not support the non-blocking form of connect() */
1385
1386 if (flags & O_NONBLOCK) { 1325 if (flags & O_NONBLOCK) {
1387 res = -EOPNOTSUPP; 1326 res = -EOPNOTSUPP;
1388 goto exit; 1327 goto exit;
1389 } 1328 }
1390 1329
1391 /* Issue Posix-compliant error code if socket is in the wrong state */ 1330 /* Issue Posix-compliant error code if socket is in the wrong state */
1392
1393 if (sock->state == SS_LISTENING) { 1331 if (sock->state == SS_LISTENING) {
1394 res = -EOPNOTSUPP; 1332 res = -EOPNOTSUPP;
1395 goto exit; 1333 goto exit;
@@ -1409,18 +1347,15 @@ static int connect(struct socket *sock, struct sockaddr *dest, int destlen,
1409 * Note: send_msg() validates the rest of the address fields, 1347 * Note: send_msg() validates the rest of the address fields,
1410 * so there's no need to do it here 1348 * so there's no need to do it here
1411 */ 1349 */
1412
1413 if (dst->addrtype == TIPC_ADDR_MCAST) { 1350 if (dst->addrtype == TIPC_ADDR_MCAST) {
1414 res = -EINVAL; 1351 res = -EINVAL;
1415 goto exit; 1352 goto exit;
1416 } 1353 }
1417 1354
1418 /* Reject any messages already in receive queue (very unlikely) */ 1355 /* Reject any messages already in receive queue (very unlikely) */
1419
1420 reject_rx_queue(sk); 1356 reject_rx_queue(sk);
1421 1357
1422 /* Send a 'SYN-' to destination */ 1358 /* Send a 'SYN-' to destination */
1423
1424 m.msg_name = dest; 1359 m.msg_name = dest;
1425 m.msg_namelen = destlen; 1360 m.msg_namelen = destlen;
1426 res = send_msg(NULL, sock, &m, 0); 1361 res = send_msg(NULL, sock, &m, 0);
@@ -1428,13 +1363,13 @@ static int connect(struct socket *sock, struct sockaddr *dest, int destlen,
1428 goto exit; 1363 goto exit;
1429 1364
1430 /* Wait until an 'ACK' or 'RST' arrives, or a timeout occurs */ 1365 /* Wait until an 'ACK' or 'RST' arrives, or a timeout occurs */
1431
1432 timeout = tipc_sk(sk)->conn_timeout; 1366 timeout = tipc_sk(sk)->conn_timeout;
1433 release_sock(sk); 1367 release_sock(sk);
1434 res = wait_event_interruptible_timeout(*sk_sleep(sk), 1368 res = wait_event_interruptible_timeout(*sk_sleep(sk),
1435 (!skb_queue_empty(&sk->sk_receive_queue) || 1369 (!skb_queue_empty(&sk->sk_receive_queue) ||
1436 (sock->state != SS_CONNECTING)), 1370 (sock->state != SS_CONNECTING)),
1437 timeout ? timeout : MAX_SCHEDULE_TIMEOUT); 1371 timeout ? (long)msecs_to_jiffies(timeout)
1372 : MAX_SCHEDULE_TIMEOUT);
1438 lock_sock(sk); 1373 lock_sock(sk);
1439 1374
1440 if (res > 0) { 1375 if (res > 0) {
@@ -1472,7 +1407,6 @@ exit:
1472 * 1407 *
1473 * Returns 0 on success, errno otherwise 1408 * Returns 0 on success, errno otherwise
1474 */ 1409 */
1475
1476static int listen(struct socket *sock, int len) 1410static int listen(struct socket *sock, int len)
1477{ 1411{
1478 struct sock *sk = sock->sk; 1412 struct sock *sk = sock->sk;
@@ -1480,9 +1414,7 @@ static int listen(struct socket *sock, int len)
1480 1414
1481 lock_sock(sk); 1415 lock_sock(sk);
1482 1416
1483 if (sock->state == SS_READY) 1417 if (sock->state != SS_UNCONNECTED)
1484 res = -EOPNOTSUPP;
1485 else if (sock->state != SS_UNCONNECTED)
1486 res = -EINVAL; 1418 res = -EINVAL;
1487 else { 1419 else {
1488 sock->state = SS_LISTENING; 1420 sock->state = SS_LISTENING;
@@ -1501,7 +1433,6 @@ static int listen(struct socket *sock, int len)
1501 * 1433 *
1502 * Returns 0 on success, errno otherwise 1434 * Returns 0 on success, errno otherwise
1503 */ 1435 */
1504
1505static int accept(struct socket *sock, struct socket *new_sock, int flags) 1436static int accept(struct socket *sock, struct socket *new_sock, int flags)
1506{ 1437{
1507 struct sock *sk = sock->sk; 1438 struct sock *sk = sock->sk;
@@ -1510,10 +1441,6 @@ static int accept(struct socket *sock, struct socket *new_sock, int flags)
1510 1441
1511 lock_sock(sk); 1442 lock_sock(sk);
1512 1443
1513 if (sock->state == SS_READY) {
1514 res = -EOPNOTSUPP;
1515 goto exit;
1516 }
1517 if (sock->state != SS_LISTENING) { 1444 if (sock->state != SS_LISTENING) {
1518 res = -EINVAL; 1445 res = -EINVAL;
1519 goto exit; 1446 goto exit;
@@ -1548,11 +1475,9 @@ static int accept(struct socket *sock, struct socket *new_sock, int flags)
1548 * Reject any stray messages received by new socket 1475 * Reject any stray messages received by new socket
1549 * before the socket lock was taken (very, very unlikely) 1476 * before the socket lock was taken (very, very unlikely)
1550 */ 1477 */
1551
1552 reject_rx_queue(new_sk); 1478 reject_rx_queue(new_sk);
1553 1479
1554 /* Connect new socket to it's peer */ 1480 /* Connect new socket to it's peer */
1555
1556 new_tsock->peer_name.ref = msg_origport(msg); 1481 new_tsock->peer_name.ref = msg_origport(msg);
1557 new_tsock->peer_name.node = msg_orignode(msg); 1482 new_tsock->peer_name.node = msg_orignode(msg);
1558 tipc_connect2port(new_ref, &new_tsock->peer_name); 1483 tipc_connect2port(new_ref, &new_tsock->peer_name);
@@ -1568,7 +1493,6 @@ static int accept(struct socket *sock, struct socket *new_sock, int flags)
1568 * Respond to 'SYN-' by discarding it & returning 'ACK'-. 1493 * Respond to 'SYN-' by discarding it & returning 'ACK'-.
1569 * Respond to 'SYN+' by queuing it on new socket. 1494 * Respond to 'SYN+' by queuing it on new socket.
1570 */ 1495 */
1571
1572 if (!msg_data_sz(msg)) { 1496 if (!msg_data_sz(msg)) {
1573 struct msghdr m = {NULL,}; 1497 struct msghdr m = {NULL,};
1574 1498
@@ -1594,7 +1518,6 @@ exit:
1594 * 1518 *
1595 * Returns 0 on success, errno otherwise 1519 * Returns 0 on success, errno otherwise
1596 */ 1520 */
1597
1598static int shutdown(struct socket *sock, int how) 1521static int shutdown(struct socket *sock, int how)
1599{ 1522{
1600 struct sock *sk = sock->sk; 1523 struct sock *sk = sock->sk;
@@ -1611,13 +1534,13 @@ static int shutdown(struct socket *sock, int how)
1611 case SS_CONNECTING: 1534 case SS_CONNECTING:
1612 case SS_CONNECTED: 1535 case SS_CONNECTED:
1613 1536
1614 /* Disconnect and send a 'FIN+' or 'FIN-' message to peer */
1615restart: 1537restart:
1538 /* Disconnect and send a 'FIN+' or 'FIN-' message to peer */
1616 buf = __skb_dequeue(&sk->sk_receive_queue); 1539 buf = __skb_dequeue(&sk->sk_receive_queue);
1617 if (buf) { 1540 if (buf) {
1618 atomic_dec(&tipc_queue_size); 1541 atomic_dec(&tipc_queue_size);
1619 if (TIPC_SKB_CB(buf)->handle != 0) { 1542 if (TIPC_SKB_CB(buf)->handle != 0) {
1620 buf_discard(buf); 1543 kfree_skb(buf);
1621 goto restart; 1544 goto restart;
1622 } 1545 }
1623 tipc_disconnect(tport->ref); 1546 tipc_disconnect(tport->ref);
@@ -1633,7 +1556,6 @@ restart:
1633 case SS_DISCONNECTING: 1556 case SS_DISCONNECTING:
1634 1557
1635 /* Discard any unreceived messages; wake up sleeping tasks */ 1558 /* Discard any unreceived messages; wake up sleeping tasks */
1636
1637 discard_rx_queue(sk); 1559 discard_rx_queue(sk);
1638 if (waitqueue_active(sk_sleep(sk))) 1560 if (waitqueue_active(sk_sleep(sk)))
1639 wake_up_interruptible(sk_sleep(sk)); 1561 wake_up_interruptible(sk_sleep(sk));
@@ -1661,7 +1583,6 @@ restart:
1661 * 1583 *
1662 * Returns 0 on success, errno otherwise 1584 * Returns 0 on success, errno otherwise
1663 */ 1585 */
1664
1665static int setsockopt(struct socket *sock, 1586static int setsockopt(struct socket *sock,
1666 int lvl, int opt, char __user *ov, unsigned int ol) 1587 int lvl, int opt, char __user *ov, unsigned int ol)
1667{ 1588{
@@ -1696,7 +1617,7 @@ static int setsockopt(struct socket *sock,
1696 res = tipc_set_portunreturnable(tport->ref, value); 1617 res = tipc_set_portunreturnable(tport->ref, value);
1697 break; 1618 break;
1698 case TIPC_CONN_TIMEOUT: 1619 case TIPC_CONN_TIMEOUT:
1699 tipc_sk(sk)->conn_timeout = msecs_to_jiffies(value); 1620 tipc_sk(sk)->conn_timeout = value;
1700 /* no need to set "res", since already 0 at this point */ 1621 /* no need to set "res", since already 0 at this point */
1701 break; 1622 break;
1702 default: 1623 default:
@@ -1721,7 +1642,6 @@ static int setsockopt(struct socket *sock,
1721 * 1642 *
1722 * Returns 0 on success, errno otherwise 1643 * Returns 0 on success, errno otherwise
1723 */ 1644 */
1724
1725static int getsockopt(struct socket *sock, 1645static int getsockopt(struct socket *sock,
1726 int lvl, int opt, char __user *ov, int __user *ol) 1646 int lvl, int opt, char __user *ov, int __user *ol)
1727{ 1647{
@@ -1752,7 +1672,7 @@ static int getsockopt(struct socket *sock,
1752 res = tipc_portunreturnable(tport->ref, &value); 1672 res = tipc_portunreturnable(tport->ref, &value);
1753 break; 1673 break;
1754 case TIPC_CONN_TIMEOUT: 1674 case TIPC_CONN_TIMEOUT:
1755 value = jiffies_to_msecs(tipc_sk(sk)->conn_timeout); 1675 value = tipc_sk(sk)->conn_timeout;
1756 /* no need to set "res", since already 0 at this point */ 1676 /* no need to set "res", since already 0 at this point */
1757 break; 1677 break;
1758 case TIPC_NODE_RECVQ_DEPTH: 1678 case TIPC_NODE_RECVQ_DEPTH:
@@ -1779,9 +1699,7 @@ static int getsockopt(struct socket *sock,
1779 return put_user(sizeof(value), ol); 1699 return put_user(sizeof(value), ol);
1780} 1700}
1781 1701
1782/** 1702/* Protocol switches for the various types of TIPC sockets */
1783 * Protocol switches for the various types of TIPC sockets
1784 */
1785 1703
1786static const struct proto_ops msg_ops = { 1704static const struct proto_ops msg_ops = {
1787 .owner = THIS_MODULE, 1705 .owner = THIS_MODULE,
@@ -1790,11 +1708,11 @@ static const struct proto_ops msg_ops = {
1790 .bind = bind, 1708 .bind = bind,
1791 .connect = connect, 1709 .connect = connect,
1792 .socketpair = sock_no_socketpair, 1710 .socketpair = sock_no_socketpair,
1793 .accept = accept, 1711 .accept = sock_no_accept,
1794 .getname = get_name, 1712 .getname = get_name,
1795 .poll = poll, 1713 .poll = poll,
1796 .ioctl = sock_no_ioctl, 1714 .ioctl = sock_no_ioctl,
1797 .listen = listen, 1715 .listen = sock_no_listen,
1798 .shutdown = shutdown, 1716 .shutdown = shutdown,
1799 .setsockopt = setsockopt, 1717 .setsockopt = setsockopt,
1800 .getsockopt = getsockopt, 1718 .getsockopt = getsockopt,
@@ -1869,13 +1787,13 @@ int tipc_socket_init(void)
1869 1787
1870 res = proto_register(&tipc_proto, 1); 1788 res = proto_register(&tipc_proto, 1);
1871 if (res) { 1789 if (res) {
1872 err("Failed to register TIPC protocol type\n"); 1790 pr_err("Failed to register TIPC protocol type\n");
1873 goto out; 1791 goto out;
1874 } 1792 }
1875 1793
1876 res = sock_register(&tipc_family_ops); 1794 res = sock_register(&tipc_family_ops);
1877 if (res) { 1795 if (res) {
1878 err("Failed to register TIPC socket type\n"); 1796 pr_err("Failed to register TIPC socket type\n");
1879 proto_unregister(&tipc_proto); 1797 proto_unregister(&tipc_proto);
1880 goto out; 1798 goto out;
1881 } 1799 }
@@ -1888,7 +1806,6 @@ int tipc_socket_init(void)
1888/** 1806/**
1889 * tipc_socket_stop - stop TIPC socket interface 1807 * tipc_socket_stop - stop TIPC socket interface
1890 */ 1808 */
1891
1892void tipc_socket_stop(void) 1809void tipc_socket_stop(void)
1893{ 1810{
1894 if (!sockets_enabled) 1811 if (!sockets_enabled)
@@ -1898,4 +1815,3 @@ void tipc_socket_stop(void)
1898 sock_unregister(tipc_family_ops.family); 1815 sock_unregister(tipc_family_ops.family);
1899 proto_unregister(&tipc_proto); 1816 proto_unregister(&tipc_proto);
1900} 1817}
1901