diff options
Diffstat (limited to 'net/tipc/socket.c')
-rw-r--r-- | net/tipc/socket.c | 83 |
1 files changed, 2 insertions, 81 deletions
diff --git a/net/tipc/socket.c b/net/tipc/socket.c index 3c00b40f815..5577a447f53 100644 --- a/net/tipc/socket.c +++ b/net/tipc/socket.c | |||
@@ -123,7 +123,6 @@ static atomic_t tipc_queue_size = ATOMIC_INIT(0); | |||
123 | * | 123 | * |
124 | * Caller must hold socket lock | 124 | * Caller must hold socket lock |
125 | */ | 125 | */ |
126 | |||
127 | static void advance_rx_queue(struct sock *sk) | 126 | static void advance_rx_queue(struct sock *sk) |
128 | { | 127 | { |
129 | kfree_skb(__skb_dequeue(&sk->sk_receive_queue)); | 128 | kfree_skb(__skb_dequeue(&sk->sk_receive_queue)); |
@@ -135,7 +134,6 @@ static void advance_rx_queue(struct sock *sk) | |||
135 | * | 134 | * |
136 | * Caller must hold socket lock | 135 | * Caller must hold socket lock |
137 | */ | 136 | */ |
138 | |||
139 | static void discard_rx_queue(struct sock *sk) | 137 | static void discard_rx_queue(struct sock *sk) |
140 | { | 138 | { |
141 | struct sk_buff *buf; | 139 | struct sk_buff *buf; |
@@ -151,7 +149,6 @@ static void discard_rx_queue(struct sock *sk) | |||
151 | * | 149 | * |
152 | * Caller must hold socket lock | 150 | * Caller must hold socket lock |
153 | */ | 151 | */ |
154 | |||
155 | static void reject_rx_queue(struct sock *sk) | 152 | static void reject_rx_queue(struct sock *sk) |
156 | { | 153 | { |
157 | struct sk_buff *buf; | 154 | struct sk_buff *buf; |
@@ -174,7 +171,6 @@ static void reject_rx_queue(struct sock *sk) | |||
174 | * | 171 | * |
175 | * Returns 0 on success, errno otherwise | 172 | * Returns 0 on success, errno otherwise |
176 | */ | 173 | */ |
177 | |||
178 | static int tipc_create(struct net *net, struct socket *sock, int protocol, | 174 | static int tipc_create(struct net *net, struct socket *sock, int protocol, |
179 | int kern) | 175 | int kern) |
180 | { | 176 | { |
@@ -184,7 +180,6 @@ static int tipc_create(struct net *net, struct socket *sock, int protocol, | |||
184 | struct tipc_port *tp_ptr; | 180 | struct tipc_port *tp_ptr; |
185 | 181 | ||
186 | /* Validate arguments */ | 182 | /* Validate arguments */ |
187 | |||
188 | if (unlikely(protocol != 0)) | 183 | if (unlikely(protocol != 0)) |
189 | return -EPROTONOSUPPORT; | 184 | return -EPROTONOSUPPORT; |
190 | 185 | ||
@@ -207,13 +202,11 @@ static int tipc_create(struct net *net, struct socket *sock, int protocol, | |||
207 | } | 202 | } |
208 | 203 | ||
209 | /* Allocate socket's protocol area */ | 204 | /* Allocate socket's protocol area */ |
210 | |||
211 | sk = sk_alloc(net, AF_TIPC, GFP_KERNEL, &tipc_proto); | 205 | sk = sk_alloc(net, AF_TIPC, GFP_KERNEL, &tipc_proto); |
212 | if (sk == NULL) | 206 | if (sk == NULL) |
213 | return -ENOMEM; | 207 | return -ENOMEM; |
214 | 208 | ||
215 | /* Allocate TIPC port for socket to use */ | 209 | /* Allocate TIPC port for socket to use */ |
216 | |||
217 | tp_ptr = tipc_createport_raw(sk, &dispatch, &wakeupdispatch, | 210 | tp_ptr = tipc_createport_raw(sk, &dispatch, &wakeupdispatch, |
218 | TIPC_LOW_IMPORTANCE); | 211 | TIPC_LOW_IMPORTANCE); |
219 | if (unlikely(!tp_ptr)) { | 212 | if (unlikely(!tp_ptr)) { |
@@ -222,7 +215,6 @@ static int tipc_create(struct net *net, struct socket *sock, int protocol, | |||
222 | } | 215 | } |
223 | 216 | ||
224 | /* Finish initializing socket data structures */ | 217 | /* Finish initializing socket data structures */ |
225 | |||
226 | sock->ops = ops; | 218 | sock->ops = ops; |
227 | sock->state = state; | 219 | sock->state = state; |
228 | 220 | ||
@@ -258,7 +250,6 @@ static int tipc_create(struct net *net, struct socket *sock, int protocol, | |||
258 | * | 250 | * |
259 | * Returns 0 on success, errno otherwise | 251 | * Returns 0 on success, errno otherwise |
260 | */ | 252 | */ |
261 | |||
262 | static int release(struct socket *sock) | 253 | static int release(struct socket *sock) |
263 | { | 254 | { |
264 | struct sock *sk = sock->sk; | 255 | struct sock *sk = sock->sk; |
@@ -270,7 +261,6 @@ static int release(struct socket *sock) | |||
270 | * 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() |
271 | * releases a pre-allocated child socket that was never used) | 262 | * releases a pre-allocated child socket that was never used) |
272 | */ | 263 | */ |
273 | |||
274 | if (sk == NULL) | 264 | if (sk == NULL) |
275 | return 0; | 265 | return 0; |
276 | 266 | ||
@@ -281,7 +271,6 @@ static int release(struct socket *sock) | |||
281 | * Reject all unreceived messages, except on an active connection | 271 | * Reject all unreceived messages, except on an active connection |
282 | * (which disconnects locally & sends a 'FIN+' to peer) | 272 | * (which disconnects locally & sends a 'FIN+' to peer) |
283 | */ | 273 | */ |
284 | |||
285 | while (sock->state != SS_DISCONNECTING) { | 274 | while (sock->state != SS_DISCONNECTING) { |
286 | buf = __skb_dequeue(&sk->sk_receive_queue); | 275 | buf = __skb_dequeue(&sk->sk_receive_queue); |
287 | if (buf == NULL) | 276 | if (buf == NULL) |
@@ -303,15 +292,12 @@ static int release(struct socket *sock) | |||
303 | * Delete TIPC port; this ensures no more messages are queued | 292 | * Delete TIPC port; this ensures no more messages are queued |
304 | * (also disconnects an active connection & sends a 'FIN-' to peer) | 293 | * (also disconnects an active connection & sends a 'FIN-' to peer) |
305 | */ | 294 | */ |
306 | |||
307 | res = tipc_deleteport(tport->ref); | 295 | res = tipc_deleteport(tport->ref); |
308 | 296 | ||
309 | /* Discard any remaining (connection-based) messages in receive queue */ | 297 | /* Discard any remaining (connection-based) messages in receive queue */ |
310 | |||
311 | discard_rx_queue(sk); | 298 | discard_rx_queue(sk); |
312 | 299 | ||
313 | /* Reject any messages that accumulated in backlog queue */ | 300 | /* Reject any messages that accumulated in backlog queue */ |
314 | |||
315 | sock->state = SS_DISCONNECTING; | 301 | sock->state = SS_DISCONNECTING; |
316 | release_sock(sk); | 302 | release_sock(sk); |
317 | 303 | ||
@@ -336,7 +322,6 @@ static int release(struct socket *sock) | |||
336 | * 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 |
337 | * access any non-constant socket information. | 323 | * access any non-constant socket information. |
338 | */ | 324 | */ |
339 | |||
340 | static int bind(struct socket *sock, struct sockaddr *uaddr, int uaddr_len) | 325 | static int bind(struct socket *sock, struct sockaddr *uaddr, int uaddr_len) |
341 | { | 326 | { |
342 | struct sockaddr_tipc *addr = (struct sockaddr_tipc *)uaddr; | 327 | struct sockaddr_tipc *addr = (struct sockaddr_tipc *)uaddr; |
@@ -376,7 +361,6 @@ static int bind(struct socket *sock, struct sockaddr *uaddr, int uaddr_len) | |||
376 | * accesses socket information that is unchanging (or which changes in | 361 | * accesses socket information that is unchanging (or which changes in |
377 | * a completely predictable manner). | 362 | * a completely predictable manner). |
378 | */ | 363 | */ |
379 | |||
380 | static int get_name(struct socket *sock, struct sockaddr *uaddr, | 364 | static int get_name(struct socket *sock, struct sockaddr *uaddr, |
381 | int *uaddr_len, int peer) | 365 | int *uaddr_len, int peer) |
382 | { | 366 | { |
@@ -444,7 +428,6 @@ static int get_name(struct socket *sock, struct sockaddr *uaddr, | |||
444 | * 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 |
445 | * and will not block. | 429 | * and will not block. |
446 | */ | 430 | */ |
447 | |||
448 | static unsigned int poll(struct file *file, struct socket *sock, | 431 | static unsigned int poll(struct file *file, struct socket *sock, |
449 | poll_table *wait) | 432 | poll_table *wait) |
450 | { | 433 | { |
@@ -482,7 +465,6 @@ static unsigned int poll(struct file *file, struct socket *sock, | |||
482 | * | 465 | * |
483 | * Returns 0 if permission is granted, otherwise errno | 466 | * Returns 0 if permission is granted, otherwise errno |
484 | */ | 467 | */ |
485 | |||
486 | static int dest_name_check(struct sockaddr_tipc *dest, struct msghdr *m) | 468 | static int dest_name_check(struct sockaddr_tipc *dest, struct msghdr *m) |
487 | { | 469 | { |
488 | struct tipc_cfg_msg_hdr hdr; | 470 | struct tipc_cfg_msg_hdr hdr; |
@@ -518,7 +500,6 @@ static int dest_name_check(struct sockaddr_tipc *dest, struct msghdr *m) | |||
518 | * | 500 | * |
519 | * Returns the number of bytes sent on success, or errno otherwise | 501 | * Returns the number of bytes sent on success, or errno otherwise |
520 | */ | 502 | */ |
521 | |||
522 | static int send_msg(struct kiocb *iocb, struct socket *sock, | 503 | static int send_msg(struct kiocb *iocb, struct socket *sock, |
523 | struct msghdr *m, size_t total_len) | 504 | struct msghdr *m, size_t total_len) |
524 | { | 505 | { |
@@ -562,7 +543,6 @@ static int send_msg(struct kiocb *iocb, struct socket *sock, | |||
562 | } | 543 | } |
563 | 544 | ||
564 | /* Abort any pending connection attempts (very unlikely) */ | 545 | /* Abort any pending connection attempts (very unlikely) */ |
565 | |||
566 | reject_rx_queue(sk); | 546 | reject_rx_queue(sk); |
567 | } | 547 | } |
568 | 548 | ||
@@ -631,7 +611,6 @@ exit: | |||
631 | * | 611 | * |
632 | * Returns the number of bytes sent on success, or errno otherwise | 612 | * Returns the number of bytes sent on success, or errno otherwise |
633 | */ | 613 | */ |
634 | |||
635 | static int send_packet(struct kiocb *iocb, struct socket *sock, | 614 | static int send_packet(struct kiocb *iocb, struct socket *sock, |
636 | struct msghdr *m, size_t total_len) | 615 | struct msghdr *m, size_t total_len) |
637 | { | 616 | { |
@@ -642,7 +621,6 @@ static int send_packet(struct kiocb *iocb, struct socket *sock, | |||
642 | int res; | 621 | int res; |
643 | 622 | ||
644 | /* Handle implied connection establishment */ | 623 | /* Handle implied connection establishment */ |
645 | |||
646 | if (unlikely(dest)) | 624 | if (unlikely(dest)) |
647 | return send_msg(iocb, sock, m, total_len); | 625 | return send_msg(iocb, sock, m, total_len); |
648 | 626 | ||
@@ -695,7 +673,6 @@ static int send_packet(struct kiocb *iocb, struct socket *sock, | |||
695 | * Returns the number of bytes sent on success (or partial success), | 673 | * Returns the number of bytes sent on success (or partial success), |
696 | * or errno if no data sent | 674 | * or errno if no data sent |
697 | */ | 675 | */ |
698 | |||
699 | static int send_stream(struct kiocb *iocb, struct socket *sock, | 676 | static int send_stream(struct kiocb *iocb, struct socket *sock, |
700 | struct msghdr *m, size_t total_len) | 677 | struct msghdr *m, size_t total_len) |
701 | { | 678 | { |
@@ -715,7 +692,6 @@ static int send_stream(struct kiocb *iocb, struct socket *sock, | |||
715 | lock_sock(sk); | 692 | lock_sock(sk); |
716 | 693 | ||
717 | /* Handle special cases where there is no connection */ | 694 | /* Handle special cases where there is no connection */ |
718 | |||
719 | if (unlikely(sock->state != SS_CONNECTED)) { | 695 | if (unlikely(sock->state != SS_CONNECTED)) { |
720 | if (sock->state == SS_UNCONNECTED) { | 696 | if (sock->state == SS_UNCONNECTED) { |
721 | res = send_packet(NULL, sock, m, total_len); | 697 | res = send_packet(NULL, sock, m, total_len); |
@@ -747,7 +723,6 @@ static int send_stream(struct kiocb *iocb, struct socket *sock, | |||
747 | * (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 |
748 | * of small iovec entries into send_packet(). | 724 | * of small iovec entries into send_packet(). |
749 | */ | 725 | */ |
750 | |||
751 | curr_iov = m->msg_iov; | 726 | curr_iov = m->msg_iov; |
752 | curr_iovlen = m->msg_iovlen; | 727 | curr_iovlen = m->msg_iovlen; |
753 | my_msg.msg_iov = &my_iov; | 728 | my_msg.msg_iov = &my_iov; |
@@ -796,7 +771,6 @@ exit: | |||
796 | * | 771 | * |
797 | * Returns 0 on success, errno otherwise | 772 | * Returns 0 on success, errno otherwise |
798 | */ | 773 | */ |
799 | |||
800 | static int auto_connect(struct socket *sock, struct tipc_msg *msg) | 774 | static int auto_connect(struct socket *sock, struct tipc_msg *msg) |
801 | { | 775 | { |
802 | struct tipc_sock *tsock = tipc_sk(sock->sk); | 776 | struct tipc_sock *tsock = tipc_sk(sock->sk); |
@@ -821,7 +795,6 @@ static int auto_connect(struct socket *sock, struct tipc_msg *msg) | |||
821 | * | 795 | * |
822 | * Note: Address is not captured if not requested by receiver. | 796 | * Note: Address is not captured if not requested by receiver. |
823 | */ | 797 | */ |
824 | |||
825 | static void set_orig_addr(struct msghdr *m, struct tipc_msg *msg) | 798 | static void set_orig_addr(struct msghdr *m, struct tipc_msg *msg) |
826 | { | 799 | { |
827 | struct sockaddr_tipc *addr = (struct sockaddr_tipc *)m->msg_name; | 800 | struct sockaddr_tipc *addr = (struct sockaddr_tipc *)m->msg_name; |
@@ -847,7 +820,6 @@ static void set_orig_addr(struct msghdr *m, struct tipc_msg *msg) | |||
847 | * | 820 | * |
848 | * Returns 0 if successful, otherwise errno | 821 | * Returns 0 if successful, otherwise errno |
849 | */ | 822 | */ |
850 | |||
851 | static int anc_data_recv(struct msghdr *m, struct tipc_msg *msg, | 823 | static int anc_data_recv(struct msghdr *m, struct tipc_msg *msg, |
852 | struct tipc_port *tport) | 824 | struct tipc_port *tport) |
853 | { | 825 | { |
@@ -861,7 +833,6 @@ static int anc_data_recv(struct msghdr *m, struct tipc_msg *msg, | |||
861 | return 0; | 833 | return 0; |
862 | 834 | ||
863 | /* Optionally capture errored message object(s) */ | 835 | /* Optionally capture errored message object(s) */ |
864 | |||
865 | err = msg ? msg_errcode(msg) : 0; | 836 | err = msg ? msg_errcode(msg) : 0; |
866 | if (unlikely(err)) { | 837 | if (unlikely(err)) { |
867 | anc_data[0] = err; | 838 | anc_data[0] = err; |
@@ -878,7 +849,6 @@ static int anc_data_recv(struct msghdr *m, struct tipc_msg *msg, | |||
878 | } | 849 | } |
879 | 850 | ||
880 | /* Optionally capture message destination object */ | 851 | /* Optionally capture message destination object */ |
881 | |||
882 | dest_type = msg ? msg_type(msg) : TIPC_DIRECT_MSG; | 852 | dest_type = msg ? msg_type(msg) : TIPC_DIRECT_MSG; |
883 | switch (dest_type) { | 853 | switch (dest_type) { |
884 | case TIPC_NAMED_MSG: | 854 | case TIPC_NAMED_MSG: |
@@ -923,7 +893,6 @@ static int anc_data_recv(struct msghdr *m, struct tipc_msg *msg, | |||
923 | * | 893 | * |
924 | * Returns size of returned message data, errno otherwise | 894 | * Returns size of returned message data, errno otherwise |
925 | */ | 895 | */ |
926 | |||
927 | static int recv_msg(struct kiocb *iocb, struct socket *sock, | 896 | static int recv_msg(struct kiocb *iocb, struct socket *sock, |
928 | struct msghdr *m, size_t buf_len, int flags) | 897 | struct msghdr *m, size_t buf_len, int flags) |
929 | { | 898 | { |
@@ -937,7 +906,6 @@ static int recv_msg(struct kiocb *iocb, struct socket *sock, | |||
937 | int res; | 906 | int res; |
938 | 907 | ||
939 | /* Catch invalid receive requests */ | 908 | /* Catch invalid receive requests */ |
940 | |||
941 | if (unlikely(!buf_len)) | 909 | if (unlikely(!buf_len)) |
942 | return -EINVAL; | 910 | return -EINVAL; |
943 | 911 | ||
@@ -952,7 +920,6 @@ static int recv_msg(struct kiocb *iocb, struct socket *sock, | |||
952 | restart: | 920 | restart: |
953 | 921 | ||
954 | /* Look for a message in receive queue; wait if necessary */ | 922 | /* Look for a message in receive queue; wait if necessary */ |
955 | |||
956 | while (skb_queue_empty(&sk->sk_receive_queue)) { | 923 | while (skb_queue_empty(&sk->sk_receive_queue)) { |
957 | if (sock->state == SS_DISCONNECTING) { | 924 | if (sock->state == SS_DISCONNECTING) { |
958 | res = -ENOTCONN; | 925 | res = -ENOTCONN; |
@@ -970,14 +937,12 @@ restart: | |||
970 | } | 937 | } |
971 | 938 | ||
972 | /* Look at first message in receive queue */ | 939 | /* Look at first message in receive queue */ |
973 | |||
974 | buf = skb_peek(&sk->sk_receive_queue); | 940 | buf = skb_peek(&sk->sk_receive_queue); |
975 | msg = buf_msg(buf); | 941 | msg = buf_msg(buf); |
976 | sz = msg_data_sz(msg); | 942 | sz = msg_data_sz(msg); |
977 | err = msg_errcode(msg); | 943 | err = msg_errcode(msg); |
978 | 944 | ||
979 | /* Complete connection setup for an implied connect */ | 945 | /* Complete connection setup for an implied connect */ |
980 | |||
981 | if (unlikely(sock->state == SS_CONNECTING)) { | 946 | if (unlikely(sock->state == SS_CONNECTING)) { |
982 | res = auto_connect(sock, msg); | 947 | res = auto_connect(sock, msg); |
983 | if (res) | 948 | if (res) |
@@ -985,24 +950,20 @@ restart: | |||
985 | } | 950 | } |
986 | 951 | ||
987 | /* Discard an empty non-errored message & try again */ | 952 | /* Discard an empty non-errored message & try again */ |
988 | |||
989 | if ((!sz) && (!err)) { | 953 | if ((!sz) && (!err)) { |
990 | advance_rx_queue(sk); | 954 | advance_rx_queue(sk); |
991 | goto restart; | 955 | goto restart; |
992 | } | 956 | } |
993 | 957 | ||
994 | /* Capture sender's address (optional) */ | 958 | /* Capture sender's address (optional) */ |
995 | |||
996 | set_orig_addr(m, msg); | 959 | set_orig_addr(m, msg); |
997 | 960 | ||
998 | /* Capture ancillary data (optional) */ | 961 | /* Capture ancillary data (optional) */ |
999 | |||
1000 | res = anc_data_recv(m, msg, tport); | 962 | res = anc_data_recv(m, msg, tport); |
1001 | if (res) | 963 | if (res) |
1002 | goto exit; | 964 | goto exit; |
1003 | 965 | ||
1004 | /* Capture message data (if valid) & compute return value (always) */ | 966 | /* Capture message data (if valid) & compute return value (always) */ |
1005 | |||
1006 | if (!err) { | 967 | if (!err) { |
1007 | if (unlikely(buf_len < sz)) { | 968 | if (unlikely(buf_len < sz)) { |
1008 | sz = buf_len; | 969 | sz = buf_len; |
@@ -1022,7 +983,6 @@ restart: | |||
1022 | } | 983 | } |
1023 | 984 | ||
1024 | /* Consume received message (optional) */ | 985 | /* Consume received message (optional) */ |
1025 | |||
1026 | if (likely(!(flags & MSG_PEEK))) { | 986 | if (likely(!(flags & MSG_PEEK))) { |
1027 | if ((sock->state != SS_READY) && | 987 | if ((sock->state != SS_READY) && |
1028 | (++tport->conn_unacked >= TIPC_FLOW_CONTROL_WIN)) | 988 | (++tport->conn_unacked >= TIPC_FLOW_CONTROL_WIN)) |
@@ -1046,7 +1006,6 @@ exit: | |||
1046 | * | 1006 | * |
1047 | * Returns size of returned message data, errno otherwise | 1007 | * Returns size of returned message data, errno otherwise |
1048 | */ | 1008 | */ |
1049 | |||
1050 | static int recv_stream(struct kiocb *iocb, struct socket *sock, | 1009 | static int recv_stream(struct kiocb *iocb, struct socket *sock, |
1051 | struct msghdr *m, size_t buf_len, int flags) | 1010 | struct msghdr *m, size_t buf_len, int flags) |
1052 | { | 1011 | { |
@@ -1062,7 +1021,6 @@ static int recv_stream(struct kiocb *iocb, struct socket *sock, | |||
1062 | int res = 0; | 1021 | int res = 0; |
1063 | 1022 | ||
1064 | /* Catch invalid receive attempts */ | 1023 | /* Catch invalid receive attempts */ |
1065 | |||
1066 | if (unlikely(!buf_len)) | 1024 | if (unlikely(!buf_len)) |
1067 | return -EINVAL; | 1025 | return -EINVAL; |
1068 | 1026 | ||
@@ -1076,10 +1034,9 @@ static int recv_stream(struct kiocb *iocb, struct socket *sock, | |||
1076 | 1034 | ||
1077 | target = sock_rcvlowat(sk, flags & MSG_WAITALL, buf_len); | 1035 | target = sock_rcvlowat(sk, flags & MSG_WAITALL, buf_len); |
1078 | timeout = sock_rcvtimeo(sk, flags & MSG_DONTWAIT); | 1036 | timeout = sock_rcvtimeo(sk, flags & MSG_DONTWAIT); |
1079 | restart: | ||
1080 | 1037 | ||
1038 | restart: | ||
1081 | /* Look for a message in receive queue; wait if necessary */ | 1039 | /* Look for a message in receive queue; wait if necessary */ |
1082 | |||
1083 | while (skb_queue_empty(&sk->sk_receive_queue)) { | 1040 | while (skb_queue_empty(&sk->sk_receive_queue)) { |
1084 | if (sock->state == SS_DISCONNECTING) { | 1041 | if (sock->state == SS_DISCONNECTING) { |
1085 | res = -ENOTCONN; | 1042 | res = -ENOTCONN; |
@@ -1097,21 +1054,18 @@ restart: | |||
1097 | } | 1054 | } |
1098 | 1055 | ||
1099 | /* Look at first message in receive queue */ | 1056 | /* Look at first message in receive queue */ |
1100 | |||
1101 | buf = skb_peek(&sk->sk_receive_queue); | 1057 | buf = skb_peek(&sk->sk_receive_queue); |
1102 | msg = buf_msg(buf); | 1058 | msg = buf_msg(buf); |
1103 | sz = msg_data_sz(msg); | 1059 | sz = msg_data_sz(msg); |
1104 | err = msg_errcode(msg); | 1060 | err = msg_errcode(msg); |
1105 | 1061 | ||
1106 | /* Discard an empty non-errored message & try again */ | 1062 | /* Discard an empty non-errored message & try again */ |
1107 | |||
1108 | if ((!sz) && (!err)) { | 1063 | if ((!sz) && (!err)) { |
1109 | advance_rx_queue(sk); | 1064 | advance_rx_queue(sk); |
1110 | goto restart; | 1065 | goto restart; |
1111 | } | 1066 | } |
1112 | 1067 | ||
1113 | /* Optionally capture sender's address & ancillary data of first msg */ | 1068 | /* Optionally capture sender's address & ancillary data of first msg */ |
1114 | |||
1115 | if (sz_copied == 0) { | 1069 | if (sz_copied == 0) { |
1116 | set_orig_addr(m, msg); | 1070 | set_orig_addr(m, msg); |
1117 | res = anc_data_recv(m, msg, tport); | 1071 | res = anc_data_recv(m, msg, tport); |
@@ -1120,7 +1074,6 @@ restart: | |||
1120 | } | 1074 | } |
1121 | 1075 | ||
1122 | /* Capture message data (if valid) & compute return value (always) */ | 1076 | /* Capture message data (if valid) & compute return value (always) */ |
1123 | |||
1124 | if (!err) { | 1077 | if (!err) { |
1125 | u32 offset = (u32)(unsigned long)(TIPC_SKB_CB(buf)->handle); | 1078 | u32 offset = (u32)(unsigned long)(TIPC_SKB_CB(buf)->handle); |
1126 | 1079 | ||
@@ -1152,7 +1105,6 @@ restart: | |||
1152 | } | 1105 | } |
1153 | 1106 | ||
1154 | /* Consume received message (optional) */ | 1107 | /* Consume received message (optional) */ |
1155 | |||
1156 | if (likely(!(flags & MSG_PEEK))) { | 1108 | if (likely(!(flags & MSG_PEEK))) { |
1157 | if (unlikely(++tport->conn_unacked >= TIPC_FLOW_CONTROL_WIN)) | 1109 | if (unlikely(++tport->conn_unacked >= TIPC_FLOW_CONTROL_WIN)) |
1158 | tipc_acknowledge(tport->ref, tport->conn_unacked); | 1110 | tipc_acknowledge(tport->ref, tport->conn_unacked); |
@@ -1160,7 +1112,6 @@ restart: | |||
1160 | } | 1112 | } |
1161 | 1113 | ||
1162 | /* Loop around if more data is required */ | 1114 | /* Loop around if more data is required */ |
1163 | |||
1164 | if ((sz_copied < buf_len) && /* didn't get all requested data */ | 1115 | if ((sz_copied < buf_len) && /* didn't get all requested data */ |
1165 | (!skb_queue_empty(&sk->sk_receive_queue) || | 1116 | (!skb_queue_empty(&sk->sk_receive_queue) || |
1166 | (sz_copied < target)) && /* and more is ready or required */ | 1117 | (sz_copied < target)) && /* and more is ready or required */ |
@@ -1181,7 +1132,6 @@ exit: | |||
1181 | * | 1132 | * |
1182 | * Returns 1 if queue is unable to accept message, 0 otherwise | 1133 | * Returns 1 if queue is unable to accept message, 0 otherwise |
1183 | */ | 1134 | */ |
1184 | |||
1185 | static int rx_queue_full(struct tipc_msg *msg, u32 queue_size, u32 base) | 1135 | static int rx_queue_full(struct tipc_msg *msg, u32 queue_size, u32 base) |
1186 | { | 1136 | { |
1187 | u32 threshold; | 1137 | u32 threshold; |
@@ -1214,7 +1164,6 @@ static int rx_queue_full(struct tipc_msg *msg, u32 queue_size, u32 base) | |||
1214 | * | 1164 | * |
1215 | * 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) |
1216 | */ | 1166 | */ |
1217 | |||
1218 | static u32 filter_rcv(struct sock *sk, struct sk_buff *buf) | 1167 | static u32 filter_rcv(struct sock *sk, struct sk_buff *buf) |
1219 | { | 1168 | { |
1220 | struct socket *sock = sk->sk_socket; | 1169 | struct socket *sock = sk->sk_socket; |
@@ -1222,7 +1171,6 @@ static u32 filter_rcv(struct sock *sk, struct sk_buff *buf) | |||
1222 | u32 recv_q_len; | 1171 | u32 recv_q_len; |
1223 | 1172 | ||
1224 | /* Reject message if it is wrong sort of message for socket */ | 1173 | /* Reject message if it is wrong sort of message for socket */ |
1225 | |||
1226 | if (msg_type(msg) > TIPC_DIRECT_MSG) | 1174 | if (msg_type(msg) > TIPC_DIRECT_MSG) |
1227 | return TIPC_ERR_NO_PORT; | 1175 | return TIPC_ERR_NO_PORT; |
1228 | 1176 | ||
@@ -1251,7 +1199,6 @@ static u32 filter_rcv(struct sock *sk, struct sk_buff *buf) | |||
1251 | } | 1199 | } |
1252 | 1200 | ||
1253 | /* Reject message if there isn't room to queue it */ | 1201 | /* Reject message if there isn't room to queue it */ |
1254 | |||
1255 | recv_q_len = (u32)atomic_read(&tipc_queue_size); | 1202 | recv_q_len = (u32)atomic_read(&tipc_queue_size); |
1256 | if (unlikely(recv_q_len >= OVERLOAD_LIMIT_BASE)) { | 1203 | if (unlikely(recv_q_len >= OVERLOAD_LIMIT_BASE)) { |
1257 | if (rx_queue_full(msg, recv_q_len, OVERLOAD_LIMIT_BASE)) | 1204 | if (rx_queue_full(msg, recv_q_len, OVERLOAD_LIMIT_BASE)) |
@@ -1264,13 +1211,11 @@ static u32 filter_rcv(struct sock *sk, struct sk_buff *buf) | |||
1264 | } | 1211 | } |
1265 | 1212 | ||
1266 | /* Enqueue message (finally!) */ | 1213 | /* Enqueue message (finally!) */ |
1267 | |||
1268 | TIPC_SKB_CB(buf)->handle = 0; | 1214 | TIPC_SKB_CB(buf)->handle = 0; |
1269 | atomic_inc(&tipc_queue_size); | 1215 | atomic_inc(&tipc_queue_size); |
1270 | __skb_queue_tail(&sk->sk_receive_queue, buf); | 1216 | __skb_queue_tail(&sk->sk_receive_queue, buf); |
1271 | 1217 | ||
1272 | /* Initiate connection termination for an incoming 'FIN' */ | 1218 | /* Initiate connection termination for an incoming 'FIN' */ |
1273 | |||
1274 | if (unlikely(msg_errcode(msg) && (sock->state == SS_CONNECTED))) { | 1219 | if (unlikely(msg_errcode(msg) && (sock->state == SS_CONNECTED))) { |
1275 | sock->state = SS_DISCONNECTING; | 1220 | sock->state = SS_DISCONNECTING; |
1276 | tipc_disconnect_port(tipc_sk_port(sk)); | 1221 | tipc_disconnect_port(tipc_sk_port(sk)); |
@@ -1290,7 +1235,6 @@ static u32 filter_rcv(struct sock *sk, struct sk_buff *buf) | |||
1290 | * | 1235 | * |
1291 | * Returns 0 | 1236 | * Returns 0 |
1292 | */ | 1237 | */ |
1293 | |||
1294 | static int backlog_rcv(struct sock *sk, struct sk_buff *buf) | 1238 | static int backlog_rcv(struct sock *sk, struct sk_buff *buf) |
1295 | { | 1239 | { |
1296 | u32 res; | 1240 | u32 res; |
@@ -1310,7 +1254,6 @@ static int backlog_rcv(struct sock *sk, struct sk_buff *buf) | |||
1310 | * | 1254 | * |
1311 | * 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) |
1312 | */ | 1256 | */ |
1313 | |||
1314 | static u32 dispatch(struct tipc_port *tport, struct sk_buff *buf) | 1257 | static u32 dispatch(struct tipc_port *tport, struct sk_buff *buf) |
1315 | { | 1258 | { |
1316 | struct sock *sk = (struct sock *)tport->usr_handle; | 1259 | struct sock *sk = (struct sock *)tport->usr_handle; |
@@ -1322,7 +1265,6 @@ static u32 dispatch(struct tipc_port *tport, struct sk_buff *buf) | |||
1322 | * 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 |
1323 | * since a TIPC-specific filter/reject mechanism is utilized | 1266 | * since a TIPC-specific filter/reject mechanism is utilized |
1324 | */ | 1267 | */ |
1325 | |||
1326 | bh_lock_sock(sk); | 1268 | bh_lock_sock(sk); |
1327 | if (!sock_owned_by_user(sk)) { | 1269 | if (!sock_owned_by_user(sk)) { |
1328 | res = filter_rcv(sk, buf); | 1270 | res = filter_rcv(sk, buf); |
@@ -1343,7 +1285,6 @@ static u32 dispatch(struct tipc_port *tport, struct sk_buff *buf) | |||
1343 | * | 1285 | * |
1344 | * Called with port lock already taken. | 1286 | * Called with port lock already taken. |
1345 | */ | 1287 | */ |
1346 | |||
1347 | static void wakeupdispatch(struct tipc_port *tport) | 1288 | static void wakeupdispatch(struct tipc_port *tport) |
1348 | { | 1289 | { |
1349 | struct sock *sk = (struct sock *)tport->usr_handle; | 1290 | struct sock *sk = (struct sock *)tport->usr_handle; |
@@ -1361,7 +1302,6 @@ static void wakeupdispatch(struct tipc_port *tport) | |||
1361 | * | 1302 | * |
1362 | * Returns 0 on success, errno otherwise | 1303 | * Returns 0 on success, errno otherwise |
1363 | */ | 1304 | */ |
1364 | |||
1365 | static int connect(struct socket *sock, struct sockaddr *dest, int destlen, | 1305 | static int connect(struct socket *sock, struct sockaddr *dest, int destlen, |
1366 | int flags) | 1306 | int flags) |
1367 | { | 1307 | { |
@@ -1376,21 +1316,18 @@ static int connect(struct socket *sock, struct sockaddr *dest, int destlen, | |||
1376 | lock_sock(sk); | 1316 | lock_sock(sk); |
1377 | 1317 | ||
1378 | /* 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 */ |
1379 | |||
1380 | if (sock->state == SS_READY) { | 1319 | if (sock->state == SS_READY) { |
1381 | res = -EOPNOTSUPP; | 1320 | res = -EOPNOTSUPP; |
1382 | goto exit; | 1321 | goto exit; |
1383 | } | 1322 | } |
1384 | 1323 | ||
1385 | /* 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() */ |
1386 | |||
1387 | if (flags & O_NONBLOCK) { | 1325 | if (flags & O_NONBLOCK) { |
1388 | res = -EOPNOTSUPP; | 1326 | res = -EOPNOTSUPP; |
1389 | goto exit; | 1327 | goto exit; |
1390 | } | 1328 | } |
1391 | 1329 | ||
1392 | /* 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 */ |
1393 | |||
1394 | if (sock->state == SS_LISTENING) { | 1331 | if (sock->state == SS_LISTENING) { |
1395 | res = -EOPNOTSUPP; | 1332 | res = -EOPNOTSUPP; |
1396 | goto exit; | 1333 | goto exit; |
@@ -1410,18 +1347,15 @@ static int connect(struct socket *sock, struct sockaddr *dest, int destlen, | |||
1410 | * Note: send_msg() validates the rest of the address fields, | 1347 | * Note: send_msg() validates the rest of the address fields, |
1411 | * so there's no need to do it here | 1348 | * so there's no need to do it here |
1412 | */ | 1349 | */ |
1413 | |||
1414 | if (dst->addrtype == TIPC_ADDR_MCAST) { | 1350 | if (dst->addrtype == TIPC_ADDR_MCAST) { |
1415 | res = -EINVAL; | 1351 | res = -EINVAL; |
1416 | goto exit; | 1352 | goto exit; |
1417 | } | 1353 | } |
1418 | 1354 | ||
1419 | /* Reject any messages already in receive queue (very unlikely) */ | 1355 | /* Reject any messages already in receive queue (very unlikely) */ |
1420 | |||
1421 | reject_rx_queue(sk); | 1356 | reject_rx_queue(sk); |
1422 | 1357 | ||
1423 | /* Send a 'SYN-' to destination */ | 1358 | /* Send a 'SYN-' to destination */ |
1424 | |||
1425 | m.msg_name = dest; | 1359 | m.msg_name = dest; |
1426 | m.msg_namelen = destlen; | 1360 | m.msg_namelen = destlen; |
1427 | res = send_msg(NULL, sock, &m, 0); | 1361 | res = send_msg(NULL, sock, &m, 0); |
@@ -1429,7 +1363,6 @@ static int connect(struct socket *sock, struct sockaddr *dest, int destlen, | |||
1429 | goto exit; | 1363 | goto exit; |
1430 | 1364 | ||
1431 | /* Wait until an 'ACK' or 'RST' arrives, or a timeout occurs */ | 1365 | /* Wait until an 'ACK' or 'RST' arrives, or a timeout occurs */ |
1432 | |||
1433 | timeout = tipc_sk(sk)->conn_timeout; | 1366 | timeout = tipc_sk(sk)->conn_timeout; |
1434 | release_sock(sk); | 1367 | release_sock(sk); |
1435 | res = wait_event_interruptible_timeout(*sk_sleep(sk), | 1368 | res = wait_event_interruptible_timeout(*sk_sleep(sk), |
@@ -1474,7 +1407,6 @@ exit: | |||
1474 | * | 1407 | * |
1475 | * Returns 0 on success, errno otherwise | 1408 | * Returns 0 on success, errno otherwise |
1476 | */ | 1409 | */ |
1477 | |||
1478 | static int listen(struct socket *sock, int len) | 1410 | static int listen(struct socket *sock, int len) |
1479 | { | 1411 | { |
1480 | struct sock *sk = sock->sk; | 1412 | struct sock *sk = sock->sk; |
@@ -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 | |||
1505 | static int accept(struct socket *sock, struct socket *new_sock, int flags) | 1436 | static 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; |
@@ -1544,11 +1475,9 @@ static int accept(struct socket *sock, struct socket *new_sock, int flags) | |||
1544 | * Reject any stray messages received by new socket | 1475 | * Reject any stray messages received by new socket |
1545 | * before the socket lock was taken (very, very unlikely) | 1476 | * before the socket lock was taken (very, very unlikely) |
1546 | */ | 1477 | */ |
1547 | |||
1548 | reject_rx_queue(new_sk); | 1478 | reject_rx_queue(new_sk); |
1549 | 1479 | ||
1550 | /* Connect new socket to it's peer */ | 1480 | /* Connect new socket to it's peer */ |
1551 | |||
1552 | new_tsock->peer_name.ref = msg_origport(msg); | 1481 | new_tsock->peer_name.ref = msg_origport(msg); |
1553 | new_tsock->peer_name.node = msg_orignode(msg); | 1482 | new_tsock->peer_name.node = msg_orignode(msg); |
1554 | tipc_connect2port(new_ref, &new_tsock->peer_name); | 1483 | tipc_connect2port(new_ref, &new_tsock->peer_name); |
@@ -1564,7 +1493,6 @@ static int accept(struct socket *sock, struct socket *new_sock, int flags) | |||
1564 | * Respond to 'SYN-' by discarding it & returning 'ACK'-. | 1493 | * Respond to 'SYN-' by discarding it & returning 'ACK'-. |
1565 | * Respond to 'SYN+' by queuing it on new socket. | 1494 | * Respond to 'SYN+' by queuing it on new socket. |
1566 | */ | 1495 | */ |
1567 | |||
1568 | if (!msg_data_sz(msg)) { | 1496 | if (!msg_data_sz(msg)) { |
1569 | struct msghdr m = {NULL,}; | 1497 | struct msghdr m = {NULL,}; |
1570 | 1498 | ||
@@ -1590,7 +1518,6 @@ exit: | |||
1590 | * | 1518 | * |
1591 | * Returns 0 on success, errno otherwise | 1519 | * Returns 0 on success, errno otherwise |
1592 | */ | 1520 | */ |
1593 | |||
1594 | static int shutdown(struct socket *sock, int how) | 1521 | static int shutdown(struct socket *sock, int how) |
1595 | { | 1522 | { |
1596 | struct sock *sk = sock->sk; | 1523 | struct sock *sk = sock->sk; |
@@ -1607,8 +1534,8 @@ static int shutdown(struct socket *sock, int how) | |||
1607 | case SS_CONNECTING: | 1534 | case SS_CONNECTING: |
1608 | case SS_CONNECTED: | 1535 | case SS_CONNECTED: |
1609 | 1536 | ||
1610 | /* Disconnect and send a 'FIN+' or 'FIN-' message to peer */ | ||
1611 | restart: | 1537 | restart: |
1538 | /* Disconnect and send a 'FIN+' or 'FIN-' message to peer */ | ||
1612 | buf = __skb_dequeue(&sk->sk_receive_queue); | 1539 | buf = __skb_dequeue(&sk->sk_receive_queue); |
1613 | if (buf) { | 1540 | if (buf) { |
1614 | atomic_dec(&tipc_queue_size); | 1541 | atomic_dec(&tipc_queue_size); |
@@ -1629,7 +1556,6 @@ restart: | |||
1629 | case SS_DISCONNECTING: | 1556 | case SS_DISCONNECTING: |
1630 | 1557 | ||
1631 | /* Discard any unreceived messages; wake up sleeping tasks */ | 1558 | /* Discard any unreceived messages; wake up sleeping tasks */ |
1632 | |||
1633 | discard_rx_queue(sk); | 1559 | discard_rx_queue(sk); |
1634 | if (waitqueue_active(sk_sleep(sk))) | 1560 | if (waitqueue_active(sk_sleep(sk))) |
1635 | wake_up_interruptible(sk_sleep(sk)); | 1561 | wake_up_interruptible(sk_sleep(sk)); |
@@ -1657,7 +1583,6 @@ restart: | |||
1657 | * | 1583 | * |
1658 | * Returns 0 on success, errno otherwise | 1584 | * Returns 0 on success, errno otherwise |
1659 | */ | 1585 | */ |
1660 | |||
1661 | static int setsockopt(struct socket *sock, | 1586 | static int setsockopt(struct socket *sock, |
1662 | int lvl, int opt, char __user *ov, unsigned int ol) | 1587 | int lvl, int opt, char __user *ov, unsigned int ol) |
1663 | { | 1588 | { |
@@ -1717,7 +1642,6 @@ static int setsockopt(struct socket *sock, | |||
1717 | * | 1642 | * |
1718 | * Returns 0 on success, errno otherwise | 1643 | * Returns 0 on success, errno otherwise |
1719 | */ | 1644 | */ |
1720 | |||
1721 | static int getsockopt(struct socket *sock, | 1645 | static int getsockopt(struct socket *sock, |
1722 | int lvl, int opt, char __user *ov, int __user *ol) | 1646 | int lvl, int opt, char __user *ov, int __user *ol) |
1723 | { | 1647 | { |
@@ -1778,7 +1702,6 @@ static int getsockopt(struct socket *sock, | |||
1778 | /** | 1702 | /** |
1779 | * Protocol switches for the various types of TIPC sockets | 1703 | * Protocol switches for the various types of TIPC sockets |
1780 | */ | 1704 | */ |
1781 | |||
1782 | static const struct proto_ops msg_ops = { | 1705 | static const struct proto_ops msg_ops = { |
1783 | .owner = THIS_MODULE, | 1706 | .owner = THIS_MODULE, |
1784 | .family = AF_TIPC, | 1707 | .family = AF_TIPC, |
@@ -1884,7 +1807,6 @@ int tipc_socket_init(void) | |||
1884 | /** | 1807 | /** |
1885 | * tipc_socket_stop - stop TIPC socket interface | 1808 | * tipc_socket_stop - stop TIPC socket interface |
1886 | */ | 1809 | */ |
1887 | |||
1888 | void tipc_socket_stop(void) | 1810 | void tipc_socket_stop(void) |
1889 | { | 1811 | { |
1890 | if (!sockets_enabled) | 1812 | if (!sockets_enabled) |
@@ -1894,4 +1816,3 @@ void tipc_socket_stop(void) | |||
1894 | sock_unregister(tipc_family_ops.family); | 1816 | sock_unregister(tipc_family_ops.family); |
1895 | proto_unregister(&tipc_proto); | 1817 | proto_unregister(&tipc_proto); |
1896 | } | 1818 | } |
1897 | |||