diff options
author | YOSHIFUJI Hideaki <yoshfuji@linux-ipv6.org> | 2007-02-09 09:25:21 -0500 |
---|---|---|
committer | David S. Miller <davem@sunset.davemloft.net> | 2007-02-11 02:20:15 -0500 |
commit | c43072852649d8382b81237ce51195bcec36f24a (patch) | |
tree | 5e55d65bd4d1db35418d2990310bd2c765d60405 /net/tipc/socket.c | |
parent | cca5172a7ec10dfdb0b787cd8e9d5b0b8f179793 (diff) |
[NET] TIPC: Fix whitespace errors.
Signed-off-by: YOSHIFUJI Hideaki <yoshfuji@linux-ipv6.org>
Signed-off-by: David S. Miller <davem@davemloft.net>
Diffstat (limited to 'net/tipc/socket.c')
-rw-r--r-- | net/tipc/socket.c | 426 |
1 files changed, 213 insertions, 213 deletions
diff --git a/net/tipc/socket.c b/net/tipc/socket.c index 2a6a5a6b4c12..b71739fbe2c6 100644 --- a/net/tipc/socket.c +++ b/net/tipc/socket.c | |||
@@ -1,6 +1,6 @@ | |||
1 | /* | 1 | /* |
2 | * net/tipc/socket.c: TIPC socket API | 2 | * net/tipc/socket.c: TIPC socket API |
3 | * | 3 | * |
4 | * Copyright (c) 2001-2006, Ericsson AB | 4 | * Copyright (c) 2001-2006, Ericsson AB |
5 | * Copyright (c) 2004-2006, Wind River Systems | 5 | * Copyright (c) 2004-2006, Wind River Systems |
6 | * All rights reserved. | 6 | * All rights reserved. |
@@ -82,29 +82,29 @@ static int sockets_enabled = 0; | |||
82 | static atomic_t tipc_queue_size = ATOMIC_INIT(0); | 82 | static atomic_t tipc_queue_size = ATOMIC_INIT(0); |
83 | 83 | ||
84 | 84 | ||
85 | /* | 85 | /* |
86 | * sock_lock(): Lock a port/socket pair. lock_sock() can | 86 | * sock_lock(): Lock a port/socket pair. lock_sock() can |
87 | * not be used here, since the same lock must protect ports | 87 | * not be used here, since the same lock must protect ports |
88 | * with non-socket interfaces. | 88 | * with non-socket interfaces. |
89 | * See net.c for description of locking policy. | 89 | * See net.c for description of locking policy. |
90 | */ | 90 | */ |
91 | static void sock_lock(struct tipc_sock* tsock) | 91 | static void sock_lock(struct tipc_sock* tsock) |
92 | { | 92 | { |
93 | spin_lock_bh(tsock->p->lock); | 93 | spin_lock_bh(tsock->p->lock); |
94 | } | 94 | } |
95 | 95 | ||
96 | /* | 96 | /* |
97 | * sock_unlock(): Unlock a port/socket pair | 97 | * sock_unlock(): Unlock a port/socket pair |
98 | */ | 98 | */ |
99 | static void sock_unlock(struct tipc_sock* tsock) | 99 | static void sock_unlock(struct tipc_sock* tsock) |
100 | { | 100 | { |
101 | spin_unlock_bh(tsock->p->lock); | 101 | spin_unlock_bh(tsock->p->lock); |
102 | } | 102 | } |
103 | 103 | ||
104 | /** | 104 | /** |
105 | * pollmask - determine the current set of poll() events for a socket | 105 | * pollmask - determine the current set of poll() events for a socket |
106 | * @sock: socket structure | 106 | * @sock: socket structure |
107 | * | 107 | * |
108 | * TIPC sets the returned events as follows: | 108 | * TIPC sets the returned events as follows: |
109 | * a) POLLRDNORM and POLLIN are set if the socket's receive queue is non-empty | 109 | * a) POLLRDNORM and POLLIN are set if the socket's receive queue is non-empty |
110 | * or if a connection-oriented socket is does not have an active connection | 110 | * or if a connection-oriented socket is does not have an active connection |
@@ -115,7 +115,7 @@ static void sock_unlock(struct tipc_sock* tsock) | |||
115 | * | 115 | * |
116 | * IMPORTANT: The fact that a read or write operation will not block does NOT | 116 | * IMPORTANT: The fact that a read or write operation will not block does NOT |
117 | * imply that the operation will succeed! | 117 | * imply that the operation will succeed! |
118 | * | 118 | * |
119 | * Returns pollmask value | 119 | * Returns pollmask value |
120 | */ | 120 | */ |
121 | 121 | ||
@@ -130,7 +130,7 @@ static u32 pollmask(struct socket *sock) | |||
130 | else | 130 | else |
131 | mask = 0; | 131 | mask = 0; |
132 | 132 | ||
133 | if (sock->state == SS_DISCONNECTING) | 133 | if (sock->state == SS_DISCONNECTING) |
134 | mask |= POLLHUP; | 134 | mask |= POLLHUP; |
135 | else | 135 | else |
136 | mask |= POLLOUT; | 136 | mask |= POLLOUT; |
@@ -146,9 +146,9 @@ static u32 pollmask(struct socket *sock) | |||
146 | 146 | ||
147 | static void advance_queue(struct tipc_sock *tsock) | 147 | static void advance_queue(struct tipc_sock *tsock) |
148 | { | 148 | { |
149 | sock_lock(tsock); | 149 | sock_lock(tsock); |
150 | buf_discard(skb_dequeue(&tsock->sk.sk_receive_queue)); | 150 | buf_discard(skb_dequeue(&tsock->sk.sk_receive_queue)); |
151 | sock_unlock(tsock); | 151 | sock_unlock(tsock); |
152 | atomic_dec(&tipc_queue_size); | 152 | atomic_dec(&tipc_queue_size); |
153 | } | 153 | } |
154 | 154 | ||
@@ -156,7 +156,7 @@ static void advance_queue(struct tipc_sock *tsock) | |||
156 | * tipc_create - create a TIPC socket | 156 | * tipc_create - create a TIPC socket |
157 | * @sock: pre-allocated socket structure | 157 | * @sock: pre-allocated socket structure |
158 | * @protocol: protocol indicator (must be 0) | 158 | * @protocol: protocol indicator (must be 0) |
159 | * | 159 | * |
160 | * This routine creates and attaches a 'struct sock' to the 'struct socket', | 160 | * This routine creates and attaches a 'struct sock' to the 'struct socket', |
161 | * then create and attaches a TIPC port to the 'struct sock' part. | 161 | * then create and attaches a TIPC port to the 'struct sock' part. |
162 | * | 162 | * |
@@ -167,7 +167,7 @@ static int tipc_create(struct socket *sock, int protocol) | |||
167 | struct tipc_sock *tsock; | 167 | struct tipc_sock *tsock; |
168 | struct tipc_port *port; | 168 | struct tipc_port *port; |
169 | struct sock *sk; | 169 | struct sock *sk; |
170 | u32 ref; | 170 | u32 ref; |
171 | 171 | ||
172 | if (unlikely(protocol != 0)) | 172 | if (unlikely(protocol != 0)) |
173 | return -EPROTONOSUPPORT; | 173 | return -EPROTONOSUPPORT; |
@@ -232,7 +232,7 @@ static int tipc_create(struct socket *sock, int protocol) | |||
232 | * For SEQPACKET and STREAM socket types, the first message is rejected | 232 | * For SEQPACKET and STREAM socket types, the first message is rejected |
233 | * and any others are discarded. (If the first message on a STREAM socket | 233 | * and any others are discarded. (If the first message on a STREAM socket |
234 | * is partially-read, it is discarded and the next one is rejected instead.) | 234 | * is partially-read, it is discarded and the next one is rejected instead.) |
235 | * | 235 | * |
236 | * NOTE: Rejected messages are not necessarily returned to the sender! They | 236 | * NOTE: Rejected messages are not necessarily returned to the sender! They |
237 | * are returned or discarded according to the "destination droppable" setting | 237 | * are returned or discarded according to the "destination droppable" setting |
238 | * specified for the message by the sender. | 238 | * specified for the message by the sender. |
@@ -247,7 +247,7 @@ static int release(struct socket *sock) | |||
247 | int res = TIPC_OK; | 247 | int res = TIPC_OK; |
248 | struct sk_buff *buf; | 248 | struct sk_buff *buf; |
249 | 249 | ||
250 | dbg("sock_delete: %x\n",tsock); | 250 | dbg("sock_delete: %x\n",tsock); |
251 | if (!tsock) | 251 | if (!tsock) |
252 | return 0; | 252 | return 0; |
253 | down_interruptible(&tsock->sem); | 253 | down_interruptible(&tsock->sem); |
@@ -255,7 +255,7 @@ static int release(struct socket *sock) | |||
255 | up(&tsock->sem); | 255 | up(&tsock->sem); |
256 | return 0; | 256 | return 0; |
257 | } | 257 | } |
258 | 258 | ||
259 | /* Reject unreceived messages, unless no longer connected */ | 259 | /* Reject unreceived messages, unless no longer connected */ |
260 | 260 | ||
261 | while (sock->state != SS_DISCONNECTING) { | 261 | while (sock->state != SS_DISCONNECTING) { |
@@ -289,7 +289,7 @@ static int release(struct socket *sock) | |||
289 | 289 | ||
290 | sock_put(sk); | 290 | sock_put(sk); |
291 | 291 | ||
292 | atomic_dec(&tipc_user_count); | 292 | atomic_dec(&tipc_user_count); |
293 | return res; | 293 | return res; |
294 | } | 294 | } |
295 | 295 | ||
@@ -298,11 +298,11 @@ static int release(struct socket *sock) | |||
298 | * @sock: socket structure | 298 | * @sock: socket structure |
299 | * @uaddr: socket address describing name(s) and desired operation | 299 | * @uaddr: socket address describing name(s) and desired operation |
300 | * @uaddr_len: size of socket address data structure | 300 | * @uaddr_len: size of socket address data structure |
301 | * | 301 | * |
302 | * Name and name sequence binding is indicated using a positive scope value; | 302 | * Name and name sequence binding is indicated using a positive scope value; |
303 | * a negative scope value unbinds the specified name. Specifying no name | 303 | * a negative scope value unbinds the specified name. Specifying no name |
304 | * (i.e. a socket address length of 0) unbinds all names from the socket. | 304 | * (i.e. a socket address length of 0) unbinds all names from the socket. |
305 | * | 305 | * |
306 | * Returns 0 on success, errno otherwise | 306 | * Returns 0 on success, errno otherwise |
307 | */ | 307 | */ |
308 | 308 | ||
@@ -314,7 +314,7 @@ static int bind(struct socket *sock, struct sockaddr *uaddr, int uaddr_len) | |||
314 | 314 | ||
315 | if (down_interruptible(&tsock->sem)) | 315 | if (down_interruptible(&tsock->sem)) |
316 | return -ERESTARTSYS; | 316 | return -ERESTARTSYS; |
317 | 317 | ||
318 | if (unlikely(!uaddr_len)) { | 318 | if (unlikely(!uaddr_len)) { |
319 | res = tipc_withdraw(tsock->p->ref, 0, NULL); | 319 | res = tipc_withdraw(tsock->p->ref, 0, NULL); |
320 | goto exit; | 320 | goto exit; |
@@ -335,8 +335,8 @@ static int bind(struct socket *sock, struct sockaddr *uaddr, int uaddr_len) | |||
335 | res = -EAFNOSUPPORT; | 335 | res = -EAFNOSUPPORT; |
336 | goto exit; | 336 | goto exit; |
337 | } | 337 | } |
338 | 338 | ||
339 | if (addr->scope > 0) | 339 | if (addr->scope > 0) |
340 | res = tipc_publish(tsock->p->ref, addr->scope, | 340 | res = tipc_publish(tsock->p->ref, addr->scope, |
341 | &addr->addr.nameseq); | 341 | &addr->addr.nameseq); |
342 | else | 342 | else |
@@ -347,17 +347,17 @@ exit: | |||
347 | return res; | 347 | return res; |
348 | } | 348 | } |
349 | 349 | ||
350 | /** | 350 | /** |
351 | * get_name - get port ID of socket or peer socket | 351 | * get_name - get port ID of socket or peer socket |
352 | * @sock: socket structure | 352 | * @sock: socket structure |
353 | * @uaddr: area for returned socket address | 353 | * @uaddr: area for returned socket address |
354 | * @uaddr_len: area for returned length of socket address | 354 | * @uaddr_len: area for returned length of socket address |
355 | * @peer: 0 to obtain socket name, 1 to obtain peer socket name | 355 | * @peer: 0 to obtain socket name, 1 to obtain peer socket name |
356 | * | 356 | * |
357 | * Returns 0 on success, errno otherwise | 357 | * Returns 0 on success, errno otherwise |
358 | */ | 358 | */ |
359 | 359 | ||
360 | static int get_name(struct socket *sock, struct sockaddr *uaddr, | 360 | static int get_name(struct socket *sock, struct sockaddr *uaddr, |
361 | int *uaddr_len, int peer) | 361 | int *uaddr_len, int peer) |
362 | { | 362 | { |
363 | struct tipc_sock *tsock = tipc_sk(sock->sk); | 363 | struct tipc_sock *tsock = tipc_sk(sock->sk); |
@@ -390,7 +390,7 @@ static int get_name(struct socket *sock, struct sockaddr *uaddr, | |||
390 | * Returns the pollmask | 390 | * Returns the pollmask |
391 | */ | 391 | */ |
392 | 392 | ||
393 | static unsigned int poll(struct file *file, struct socket *sock, | 393 | static unsigned int poll(struct file *file, struct socket *sock, |
394 | poll_table *wait) | 394 | poll_table *wait) |
395 | { | 395 | { |
396 | poll_wait(file, sock->sk->sk_sleep, wait); | 396 | poll_wait(file, sock->sk->sk_sleep, wait); |
@@ -398,14 +398,14 @@ static unsigned int poll(struct file *file, struct socket *sock, | |||
398 | return pollmask(sock); | 398 | return pollmask(sock); |
399 | } | 399 | } |
400 | 400 | ||
401 | /** | 401 | /** |
402 | * dest_name_check - verify user is permitted to send to specified port name | 402 | * dest_name_check - verify user is permitted to send to specified port name |
403 | * @dest: destination address | 403 | * @dest: destination address |
404 | * @m: descriptor for message to be sent | 404 | * @m: descriptor for message to be sent |
405 | * | 405 | * |
406 | * Prevents restricted configuration commands from being issued by | 406 | * Prevents restricted configuration commands from being issued by |
407 | * unauthorized users. | 407 | * unauthorized users. |
408 | * | 408 | * |
409 | * Returns 0 if permission is granted, otherwise errno | 409 | * Returns 0 if permission is granted, otherwise errno |
410 | */ | 410 | */ |
411 | 411 | ||
@@ -413,19 +413,19 @@ static int dest_name_check(struct sockaddr_tipc *dest, struct msghdr *m) | |||
413 | { | 413 | { |
414 | struct tipc_cfg_msg_hdr hdr; | 414 | struct tipc_cfg_msg_hdr hdr; |
415 | 415 | ||
416 | if (likely(dest->addr.name.name.type >= TIPC_RESERVED_TYPES)) | 416 | if (likely(dest->addr.name.name.type >= TIPC_RESERVED_TYPES)) |
417 | return 0; | 417 | return 0; |
418 | if (likely(dest->addr.name.name.type == TIPC_TOP_SRV)) | 418 | if (likely(dest->addr.name.name.type == TIPC_TOP_SRV)) |
419 | return 0; | 419 | return 0; |
420 | 420 | ||
421 | if (likely(dest->addr.name.name.type != TIPC_CFG_SRV)) | 421 | if (likely(dest->addr.name.name.type != TIPC_CFG_SRV)) |
422 | return -EACCES; | 422 | return -EACCES; |
423 | 423 | ||
424 | if (copy_from_user(&hdr, m->msg_iov[0].iov_base, sizeof(hdr))) | 424 | if (copy_from_user(&hdr, m->msg_iov[0].iov_base, sizeof(hdr))) |
425 | return -EFAULT; | 425 | return -EFAULT; |
426 | if ((ntohs(hdr.tcm_type) & 0xC000) && (!capable(CAP_NET_ADMIN))) | 426 | if ((ntohs(hdr.tcm_type) & 0xC000) && (!capable(CAP_NET_ADMIN))) |
427 | return -EACCES; | 427 | return -EACCES; |
428 | 428 | ||
429 | return 0; | 429 | return 0; |
430 | } | 430 | } |
431 | 431 | ||
@@ -435,12 +435,12 @@ static int dest_name_check(struct sockaddr_tipc *dest, struct msghdr *m) | |||
435 | * @sock: socket structure | 435 | * @sock: socket structure |
436 | * @m: message to send | 436 | * @m: message to send |
437 | * @total_len: length of message | 437 | * @total_len: length of message |
438 | * | 438 | * |
439 | * Message must have an destination specified explicitly. | 439 | * Message must have an destination specified explicitly. |
440 | * Used for SOCK_RDM and SOCK_DGRAM messages, | 440 | * Used for SOCK_RDM and SOCK_DGRAM messages, |
441 | * and for 'SYN' messages on SOCK_SEQPACKET and SOCK_STREAM connections. | 441 | * and for 'SYN' messages on SOCK_SEQPACKET and SOCK_STREAM connections. |
442 | * (Note: 'SYN+' is prohibited on SOCK_STREAM.) | 442 | * (Note: 'SYN+' is prohibited on SOCK_STREAM.) |
443 | * | 443 | * |
444 | * Returns the number of bytes sent on success, or errno otherwise | 444 | * Returns the number of bytes sent on success, or errno otherwise |
445 | */ | 445 | */ |
446 | 446 | ||
@@ -448,7 +448,7 @@ static int send_msg(struct kiocb *iocb, struct socket *sock, | |||
448 | struct msghdr *m, size_t total_len) | 448 | struct msghdr *m, size_t total_len) |
449 | { | 449 | { |
450 | struct tipc_sock *tsock = tipc_sk(sock->sk); | 450 | struct tipc_sock *tsock = tipc_sk(sock->sk); |
451 | struct sockaddr_tipc *dest = (struct sockaddr_tipc *)m->msg_name; | 451 | struct sockaddr_tipc *dest = (struct sockaddr_tipc *)m->msg_name; |
452 | struct sk_buff *buf; | 452 | struct sk_buff *buf; |
453 | int needs_conn; | 453 | int needs_conn; |
454 | int res = -EINVAL; | 454 | int res = -EINVAL; |
@@ -489,61 +489,61 @@ static int send_msg(struct kiocb *iocb, struct socket *sock, | |||
489 | sock->state = SS_CONNECTING; | 489 | sock->state = SS_CONNECTING; |
490 | } | 490 | } |
491 | 491 | ||
492 | do { | 492 | do { |
493 | if (dest->addrtype == TIPC_ADDR_NAME) { | 493 | if (dest->addrtype == TIPC_ADDR_NAME) { |
494 | if ((res = dest_name_check(dest, m))) | 494 | if ((res = dest_name_check(dest, m))) |
495 | goto exit; | 495 | goto exit; |
496 | res = tipc_send2name(tsock->p->ref, | 496 | res = tipc_send2name(tsock->p->ref, |
497 | &dest->addr.name.name, | 497 | &dest->addr.name.name, |
498 | dest->addr.name.domain, | 498 | dest->addr.name.domain, |
499 | m->msg_iovlen, | 499 | m->msg_iovlen, |
500 | m->msg_iov); | 500 | m->msg_iov); |
501 | } | 501 | } |
502 | else if (dest->addrtype == TIPC_ADDR_ID) { | 502 | else if (dest->addrtype == TIPC_ADDR_ID) { |
503 | res = tipc_send2port(tsock->p->ref, | 503 | res = tipc_send2port(tsock->p->ref, |
504 | &dest->addr.id, | 504 | &dest->addr.id, |
505 | m->msg_iovlen, | 505 | m->msg_iovlen, |
506 | m->msg_iov); | 506 | m->msg_iov); |
507 | } | 507 | } |
508 | else if (dest->addrtype == TIPC_ADDR_MCAST) { | 508 | else if (dest->addrtype == TIPC_ADDR_MCAST) { |
509 | if (needs_conn) { | 509 | if (needs_conn) { |
510 | res = -EOPNOTSUPP; | 510 | res = -EOPNOTSUPP; |
511 | goto exit; | 511 | goto exit; |
512 | } | 512 | } |
513 | if ((res = dest_name_check(dest, m))) | 513 | if ((res = dest_name_check(dest, m))) |
514 | goto exit; | 514 | goto exit; |
515 | res = tipc_multicast(tsock->p->ref, | 515 | res = tipc_multicast(tsock->p->ref, |
516 | &dest->addr.nameseq, | 516 | &dest->addr.nameseq, |
517 | 0, | 517 | 0, |
518 | m->msg_iovlen, | 518 | m->msg_iovlen, |
519 | m->msg_iov); | 519 | m->msg_iov); |
520 | } | 520 | } |
521 | if (likely(res != -ELINKCONG)) { | 521 | if (likely(res != -ELINKCONG)) { |
522 | exit: | 522 | exit: |
523 | up(&tsock->sem); | 523 | up(&tsock->sem); |
524 | return res; | 524 | return res; |
525 | } | 525 | } |
526 | if (m->msg_flags & MSG_DONTWAIT) { | 526 | if (m->msg_flags & MSG_DONTWAIT) { |
527 | res = -EWOULDBLOCK; | 527 | res = -EWOULDBLOCK; |
528 | goto exit; | 528 | goto exit; |
529 | } | 529 | } |
530 | if (wait_event_interruptible(*sock->sk->sk_sleep, | 530 | if (wait_event_interruptible(*sock->sk->sk_sleep, |
531 | !tsock->p->congested)) { | 531 | !tsock->p->congested)) { |
532 | res = -ERESTARTSYS; | 532 | res = -ERESTARTSYS; |
533 | goto exit; | 533 | goto exit; |
534 | } | 534 | } |
535 | } while (1); | 535 | } while (1); |
536 | } | 536 | } |
537 | 537 | ||
538 | /** | 538 | /** |
539 | * send_packet - send a connection-oriented message | 539 | * send_packet - send a connection-oriented message |
540 | * @iocb: (unused) | 540 | * @iocb: (unused) |
541 | * @sock: socket structure | 541 | * @sock: socket structure |
542 | * @m: message to send | 542 | * @m: message to send |
543 | * @total_len: length of message | 543 | * @total_len: length of message |
544 | * | 544 | * |
545 | * Used for SOCK_SEQPACKET messages and SOCK_STREAM data. | 545 | * Used for SOCK_SEQPACKET messages and SOCK_STREAM data. |
546 | * | 546 | * |
547 | * Returns the number of bytes sent on success, or errno otherwise | 547 | * Returns the number of bytes sent on success, or errno otherwise |
548 | */ | 548 | */ |
549 | 549 | ||
@@ -551,7 +551,7 @@ static int send_packet(struct kiocb *iocb, struct socket *sock, | |||
551 | struct msghdr *m, size_t total_len) | 551 | struct msghdr *m, size_t total_len) |
552 | { | 552 | { |
553 | struct tipc_sock *tsock = tipc_sk(sock->sk); | 553 | struct tipc_sock *tsock = tipc_sk(sock->sk); |
554 | struct sockaddr_tipc *dest = (struct sockaddr_tipc *)m->msg_name; | 554 | struct sockaddr_tipc *dest = (struct sockaddr_tipc *)m->msg_name; |
555 | int res; | 555 | int res; |
556 | 556 | ||
557 | /* Handle implied connection establishment */ | 557 | /* Handle implied connection establishment */ |
@@ -561,45 +561,45 @@ static int send_packet(struct kiocb *iocb, struct socket *sock, | |||
561 | 561 | ||
562 | if (down_interruptible(&tsock->sem)) { | 562 | if (down_interruptible(&tsock->sem)) { |
563 | return -ERESTARTSYS; | 563 | return -ERESTARTSYS; |
564 | } | 564 | } |
565 | 565 | ||
566 | do { | 566 | do { |
567 | if (unlikely(sock->state != SS_CONNECTED)) { | 567 | if (unlikely(sock->state != SS_CONNECTED)) { |
568 | if (sock->state == SS_DISCONNECTING) | 568 | if (sock->state == SS_DISCONNECTING) |
569 | res = -EPIPE; | 569 | res = -EPIPE; |
570 | else | 570 | else |
571 | res = -ENOTCONN; | 571 | res = -ENOTCONN; |
572 | goto exit; | 572 | goto exit; |
573 | } | 573 | } |
574 | 574 | ||
575 | res = tipc_send(tsock->p->ref, m->msg_iovlen, m->msg_iov); | 575 | res = tipc_send(tsock->p->ref, m->msg_iovlen, m->msg_iov); |
576 | if (likely(res != -ELINKCONG)) { | 576 | if (likely(res != -ELINKCONG)) { |
577 | exit: | 577 | exit: |
578 | up(&tsock->sem); | 578 | up(&tsock->sem); |
579 | return res; | 579 | return res; |
580 | } | 580 | } |
581 | if (m->msg_flags & MSG_DONTWAIT) { | 581 | if (m->msg_flags & MSG_DONTWAIT) { |
582 | res = -EWOULDBLOCK; | 582 | res = -EWOULDBLOCK; |
583 | goto exit; | 583 | goto exit; |
584 | } | 584 | } |
585 | if (wait_event_interruptible(*sock->sk->sk_sleep, | 585 | if (wait_event_interruptible(*sock->sk->sk_sleep, |
586 | !tsock->p->congested)) { | 586 | !tsock->p->congested)) { |
587 | res = -ERESTARTSYS; | 587 | res = -ERESTARTSYS; |
588 | goto exit; | 588 | goto exit; |
589 | } | 589 | } |
590 | } while (1); | 590 | } while (1); |
591 | } | 591 | } |
592 | 592 | ||
593 | /** | 593 | /** |
594 | * send_stream - send stream-oriented data | 594 | * send_stream - send stream-oriented data |
595 | * @iocb: (unused) | 595 | * @iocb: (unused) |
596 | * @sock: socket structure | 596 | * @sock: socket structure |
597 | * @m: data to send | 597 | * @m: data to send |
598 | * @total_len: total length of data to be sent | 598 | * @total_len: total length of data to be sent |
599 | * | 599 | * |
600 | * Used for SOCK_STREAM data. | 600 | * Used for SOCK_STREAM data. |
601 | * | 601 | * |
602 | * Returns the number of bytes sent on success (or partial success), | 602 | * Returns the number of bytes sent on success (or partial success), |
603 | * or errno if no data sent | 603 | * or errno if no data sent |
604 | */ | 604 | */ |
605 | 605 | ||
@@ -616,26 +616,26 @@ static int send_stream(struct kiocb *iocb, struct socket *sock, | |||
616 | int bytes_to_send; | 616 | int bytes_to_send; |
617 | int bytes_sent; | 617 | int bytes_sent; |
618 | int res; | 618 | int res; |
619 | 619 | ||
620 | if (likely(total_len <= TIPC_MAX_USER_MSG_SIZE)) | 620 | if (likely(total_len <= TIPC_MAX_USER_MSG_SIZE)) |
621 | return send_packet(iocb, sock, m, total_len); | 621 | return send_packet(iocb, sock, m, total_len); |
622 | 622 | ||
623 | /* Can only send large data streams if already connected */ | 623 | /* Can only send large data streams if already connected */ |
624 | 624 | ||
625 | if (unlikely(sock->state != SS_CONNECTED)) { | 625 | if (unlikely(sock->state != SS_CONNECTED)) { |
626 | if (sock->state == SS_DISCONNECTING) | 626 | if (sock->state == SS_DISCONNECTING) |
627 | return -EPIPE; | 627 | return -EPIPE; |
628 | else | 628 | else |
629 | return -ENOTCONN; | 629 | return -ENOTCONN; |
630 | } | 630 | } |
631 | 631 | ||
632 | if (unlikely(m->msg_name)) | 632 | if (unlikely(m->msg_name)) |
633 | return -EISCONN; | 633 | return -EISCONN; |
634 | 634 | ||
635 | /* | 635 | /* |
636 | * Send each iovec entry using one or more messages | 636 | * Send each iovec entry using one or more messages |
637 | * | 637 | * |
638 | * Note: This algorithm is good for the most likely case | 638 | * Note: This algorithm is good for the most likely case |
639 | * (i.e. one large iovec entry), but could be improved to pass sets | 639 | * (i.e. one large iovec entry), but could be improved to pass sets |
640 | * of small iovec entries into send_packet(). | 640 | * of small iovec entries into send_packet(). |
641 | */ | 641 | */ |
@@ -657,7 +657,7 @@ static int send_stream(struct kiocb *iocb, struct socket *sock, | |||
657 | ? curr_left : TIPC_MAX_USER_MSG_SIZE; | 657 | ? curr_left : TIPC_MAX_USER_MSG_SIZE; |
658 | my_iov.iov_base = curr_start; | 658 | my_iov.iov_base = curr_start; |
659 | my_iov.iov_len = bytes_to_send; | 659 | my_iov.iov_len = bytes_to_send; |
660 | if ((res = send_packet(iocb, sock, &my_msg, 0)) < 0) { | 660 | if ((res = send_packet(iocb, sock, &my_msg, 0)) < 0) { |
661 | return bytes_sent ? bytes_sent : res; | 661 | return bytes_sent ? bytes_sent : res; |
662 | } | 662 | } |
663 | curr_left -= bytes_to_send; | 663 | curr_left -= bytes_to_send; |
@@ -676,11 +676,11 @@ static int send_stream(struct kiocb *iocb, struct socket *sock, | |||
676 | * @sock: socket structure | 676 | * @sock: socket structure |
677 | * @tsock: TIPC-specific socket structure | 677 | * @tsock: TIPC-specific socket structure |
678 | * @msg: peer's response message | 678 | * @msg: peer's response message |
679 | * | 679 | * |
680 | * Returns 0 on success, errno otherwise | 680 | * Returns 0 on success, errno otherwise |
681 | */ | 681 | */ |
682 | 682 | ||
683 | static int auto_connect(struct socket *sock, struct tipc_sock *tsock, | 683 | static int auto_connect(struct socket *sock, struct tipc_sock *tsock, |
684 | struct tipc_msg *msg) | 684 | struct tipc_msg *msg) |
685 | { | 685 | { |
686 | struct tipc_portid peer; | 686 | struct tipc_portid peer; |
@@ -702,15 +702,15 @@ static int auto_connect(struct socket *sock, struct tipc_sock *tsock, | |||
702 | * set_orig_addr - capture sender's address for received message | 702 | * set_orig_addr - capture sender's address for received message |
703 | * @m: descriptor for message info | 703 | * @m: descriptor for message info |
704 | * @msg: received message header | 704 | * @msg: received message header |
705 | * | 705 | * |
706 | * Note: Address is not captured if not requested by receiver. | 706 | * Note: Address is not captured if not requested by receiver. |
707 | */ | 707 | */ |
708 | 708 | ||
709 | static void set_orig_addr(struct msghdr *m, struct tipc_msg *msg) | 709 | static void set_orig_addr(struct msghdr *m, struct tipc_msg *msg) |
710 | { | 710 | { |
711 | struct sockaddr_tipc *addr = (struct sockaddr_tipc *)m->msg_name; | 711 | struct sockaddr_tipc *addr = (struct sockaddr_tipc *)m->msg_name; |
712 | 712 | ||
713 | if (addr) { | 713 | if (addr) { |
714 | addr->family = AF_TIPC; | 714 | addr->family = AF_TIPC; |
715 | addr->addrtype = TIPC_ADDR_ID; | 715 | addr->addrtype = TIPC_ADDR_ID; |
716 | addr->addr.id.ref = msg_origport(msg); | 716 | addr->addr.id.ref = msg_origport(msg); |
@@ -722,13 +722,13 @@ static void set_orig_addr(struct msghdr *m, struct tipc_msg *msg) | |||
722 | } | 722 | } |
723 | 723 | ||
724 | /** | 724 | /** |
725 | * anc_data_recv - optionally capture ancillary data for received message | 725 | * anc_data_recv - optionally capture ancillary data for received message |
726 | * @m: descriptor for message info | 726 | * @m: descriptor for message info |
727 | * @msg: received message header | 727 | * @msg: received message header |
728 | * @tport: TIPC port associated with message | 728 | * @tport: TIPC port associated with message |
729 | * | 729 | * |
730 | * Note: Ancillary data is not captured if not requested by receiver. | 730 | * Note: Ancillary data is not captured if not requested by receiver. |
731 | * | 731 | * |
732 | * Returns 0 if successful, otherwise errno | 732 | * Returns 0 if successful, otherwise errno |
733 | */ | 733 | */ |
734 | 734 | ||
@@ -753,7 +753,7 @@ static int anc_data_recv(struct msghdr *m, struct tipc_msg *msg, | |||
753 | if ((res = put_cmsg(m, SOL_TIPC, TIPC_ERRINFO, 8, anc_data))) | 753 | if ((res = put_cmsg(m, SOL_TIPC, TIPC_ERRINFO, 8, anc_data))) |
754 | return res; | 754 | return res; |
755 | if (anc_data[1] && | 755 | if (anc_data[1] && |
756 | (res = put_cmsg(m, SOL_TIPC, TIPC_RETDATA, anc_data[1], | 756 | (res = put_cmsg(m, SOL_TIPC, TIPC_RETDATA, anc_data[1], |
757 | msg_data(msg)))) | 757 | msg_data(msg)))) |
758 | return res; | 758 | return res; |
759 | } | 759 | } |
@@ -790,13 +790,13 @@ static int anc_data_recv(struct msghdr *m, struct tipc_msg *msg, | |||
790 | return 0; | 790 | return 0; |
791 | } | 791 | } |
792 | 792 | ||
793 | /** | 793 | /** |
794 | * recv_msg - receive packet-oriented message | 794 | * recv_msg - receive packet-oriented message |
795 | * @iocb: (unused) | 795 | * @iocb: (unused) |
796 | * @m: descriptor for message info | 796 | * @m: descriptor for message info |
797 | * @buf_len: total size of user buffer area | 797 | * @buf_len: total size of user buffer area |
798 | * @flags: receive flags | 798 | * @flags: receive flags |
799 | * | 799 | * |
800 | * Used for SOCK_DGRAM, SOCK_RDM, and SOCK_SEQPACKET messages. | 800 | * Used for SOCK_DGRAM, SOCK_RDM, and SOCK_SEQPACKET messages. |
801 | * If the complete message doesn't fit in user area, truncate it. | 801 | * If the complete message doesn't fit in user area, truncate it. |
802 | * | 802 | * |
@@ -827,9 +827,9 @@ static int recv_msg(struct kiocb *iocb, struct socket *sock, | |||
827 | if (sock->type == SOCK_SEQPACKET) { | 827 | if (sock->type == SOCK_SEQPACKET) { |
828 | if (unlikely(sock->state == SS_UNCONNECTED)) | 828 | if (unlikely(sock->state == SS_UNCONNECTED)) |
829 | return -ENOTCONN; | 829 | return -ENOTCONN; |
830 | if (unlikely((sock->state == SS_DISCONNECTING) && | 830 | if (unlikely((sock->state == SS_DISCONNECTING) && |
831 | (skb_queue_len(&sock->sk->sk_receive_queue) == 0))) | 831 | (skb_queue_len(&sock->sk->sk_receive_queue) == 0))) |
832 | return -ENOTCONN; | 832 | return -ENOTCONN; |
833 | } | 833 | } |
834 | 834 | ||
835 | /* Look for a message in receive queue; wait if necessary */ | 835 | /* Look for a message in receive queue; wait if necessary */ |
@@ -845,7 +845,7 @@ restart: | |||
845 | } | 845 | } |
846 | 846 | ||
847 | if ((res = wait_event_interruptible( | 847 | if ((res = wait_event_interruptible( |
848 | *sock->sk->sk_sleep, | 848 | *sock->sk->sk_sleep, |
849 | ((q_len = skb_queue_len(&sock->sk->sk_receive_queue)) || | 849 | ((q_len = skb_queue_len(&sock->sk->sk_receive_queue)) || |
850 | (sock->state == SS_DISCONNECTING))) )) { | 850 | (sock->state == SS_DISCONNECTING))) )) { |
851 | goto exit; | 851 | goto exit; |
@@ -890,7 +890,7 @@ restart: | |||
890 | goto exit; | 890 | goto exit; |
891 | 891 | ||
892 | /* Capture message data (if valid) & compute return value (always) */ | 892 | /* Capture message data (if valid) & compute return value (always) */ |
893 | 893 | ||
894 | if (!err) { | 894 | if (!err) { |
895 | if (unlikely(buf_len < sz)) { | 895 | if (unlikely(buf_len < sz)) { |
896 | sz = buf_len; | 896 | sz = buf_len; |
@@ -913,23 +913,23 @@ restart: | |||
913 | /* Consume received message (optional) */ | 913 | /* Consume received message (optional) */ |
914 | 914 | ||
915 | if (likely(!(flags & MSG_PEEK))) { | 915 | if (likely(!(flags & MSG_PEEK))) { |
916 | if (unlikely(++tsock->p->conn_unacked >= TIPC_FLOW_CONTROL_WIN)) | 916 | if (unlikely(++tsock->p->conn_unacked >= TIPC_FLOW_CONTROL_WIN)) |
917 | tipc_acknowledge(tsock->p->ref, tsock->p->conn_unacked); | 917 | tipc_acknowledge(tsock->p->ref, tsock->p->conn_unacked); |
918 | advance_queue(tsock); | 918 | advance_queue(tsock); |
919 | } | 919 | } |
920 | exit: | 920 | exit: |
921 | up(&tsock->sem); | 921 | up(&tsock->sem); |
922 | return res; | 922 | return res; |
923 | } | 923 | } |
924 | 924 | ||
925 | /** | 925 | /** |
926 | * recv_stream - receive stream-oriented data | 926 | * recv_stream - receive stream-oriented data |
927 | * @iocb: (unused) | 927 | * @iocb: (unused) |
928 | * @m: descriptor for message info | 928 | * @m: descriptor for message info |
929 | * @buf_len: total size of user buffer area | 929 | * @buf_len: total size of user buffer area |
930 | * @flags: receive flags | 930 | * @flags: receive flags |
931 | * | 931 | * |
932 | * Used for SOCK_STREAM messages only. If not enough data is available | 932 | * Used for SOCK_STREAM messages only. If not enough data is available |
933 | * will optionally wait for more; never truncates data. | 933 | * will optionally wait for more; never truncates data. |
934 | * | 934 | * |
935 | * Returns size of returned message data, errno otherwise | 935 | * Returns size of returned message data, errno otherwise |
@@ -980,7 +980,7 @@ restart: | |||
980 | } | 980 | } |
981 | 981 | ||
982 | if ((res = wait_event_interruptible( | 982 | if ((res = wait_event_interruptible( |
983 | *sock->sk->sk_sleep, | 983 | *sock->sk->sk_sleep, |
984 | ((q_len = skb_queue_len(&sock->sk->sk_receive_queue)) || | 984 | ((q_len = skb_queue_len(&sock->sk->sk_receive_queue)) || |
985 | (sock->state == SS_DISCONNECTING))) )) { | 985 | (sock->state == SS_DISCONNECTING))) )) { |
986 | goto exit; | 986 | goto exit; |
@@ -1017,7 +1017,7 @@ restart: | |||
1017 | } | 1017 | } |
1018 | 1018 | ||
1019 | /* Capture message data (if valid) & compute return value (always) */ | 1019 | /* Capture message data (if valid) & compute return value (always) */ |
1020 | 1020 | ||
1021 | if (!err) { | 1021 | if (!err) { |
1022 | buf_crs = (unsigned char *)(TIPC_SKB_CB(buf)->handle); | 1022 | buf_crs = (unsigned char *)(TIPC_SKB_CB(buf)->handle); |
1023 | sz = buf->tail - buf_crs; | 1023 | sz = buf->tail - buf_crs; |
@@ -1050,14 +1050,14 @@ restart: | |||
1050 | /* Consume received message (optional) */ | 1050 | /* Consume received message (optional) */ |
1051 | 1051 | ||
1052 | if (likely(!(flags & MSG_PEEK))) { | 1052 | if (likely(!(flags & MSG_PEEK))) { |
1053 | if (unlikely(++tsock->p->conn_unacked >= TIPC_FLOW_CONTROL_WIN)) | 1053 | if (unlikely(++tsock->p->conn_unacked >= TIPC_FLOW_CONTROL_WIN)) |
1054 | tipc_acknowledge(tsock->p->ref, tsock->p->conn_unacked); | 1054 | tipc_acknowledge(tsock->p->ref, tsock->p->conn_unacked); |
1055 | advance_queue(tsock); | 1055 | advance_queue(tsock); |
1056 | } | 1056 | } |
1057 | 1057 | ||
1058 | /* Loop around if more data is required */ | 1058 | /* Loop around if more data is required */ |
1059 | 1059 | ||
1060 | if ((sz_copied < buf_len) /* didn't get all requested data */ | 1060 | if ((sz_copied < buf_len) /* didn't get all requested data */ |
1061 | && (flags & MSG_WAITALL) /* ... and need to wait for more */ | 1061 | && (flags & MSG_WAITALL) /* ... and need to wait for more */ |
1062 | && (!(flags & MSG_PEEK)) /* ... and aren't just peeking at data */ | 1062 | && (!(flags & MSG_PEEK)) /* ... and aren't just peeking at data */ |
1063 | && (!err) /* ... and haven't reached a FIN */ | 1063 | && (!err) /* ... and haven't reached a FIN */ |
@@ -1074,7 +1074,7 @@ exit: | |||
1074 | * @queue_size: current size of queue | 1074 | * @queue_size: current size of queue |
1075 | * @base: nominal maximum size of queue | 1075 | * @base: nominal maximum size of queue |
1076 | * @msg: message to be added to queue | 1076 | * @msg: message to be added to queue |
1077 | * | 1077 | * |
1078 | * Returns 1 if queue is currently overloaded, 0 otherwise | 1078 | * Returns 1 if queue is currently overloaded, 0 otherwise |
1079 | */ | 1079 | */ |
1080 | 1080 | ||
@@ -1098,7 +1098,7 @@ static int queue_overloaded(u32 queue_size, u32 base, struct tipc_msg *msg) | |||
1098 | return (queue_size > threshold); | 1098 | return (queue_size > threshold); |
1099 | } | 1099 | } |
1100 | 1100 | ||
1101 | /** | 1101 | /** |
1102 | * async_disconnect - wrapper function used to disconnect port | 1102 | * async_disconnect - wrapper function used to disconnect port |
1103 | * @portref: TIPC port reference (passed as pointer-sized value) | 1103 | * @portref: TIPC port reference (passed as pointer-sized value) |
1104 | */ | 1104 | */ |
@@ -1108,13 +1108,13 @@ static void async_disconnect(unsigned long portref) | |||
1108 | tipc_disconnect((u32)portref); | 1108 | tipc_disconnect((u32)portref); |
1109 | } | 1109 | } |
1110 | 1110 | ||
1111 | /** | 1111 | /** |
1112 | * dispatch - handle arriving message | 1112 | * dispatch - handle arriving message |
1113 | * @tport: TIPC port that received message | 1113 | * @tport: TIPC port that received message |
1114 | * @buf: message | 1114 | * @buf: message |
1115 | * | 1115 | * |
1116 | * Called with port locked. Must not take socket lock to avoid deadlock risk. | 1116 | * Called with port locked. Must not take socket lock to avoid deadlock risk. |
1117 | * | 1117 | * |
1118 | * Returns TIPC error status code (TIPC_OK if message is not to be rejected) | 1118 | * Returns TIPC error status code (TIPC_OK if message is not to be rejected) |
1119 | */ | 1119 | */ |
1120 | 1120 | ||
@@ -1159,13 +1159,13 @@ static u32 dispatch(struct tipc_port *tport, struct sk_buff *buf) | |||
1159 | msg_dbg(msg, "dispatch filter 4\n"); | 1159 | msg_dbg(msg, "dispatch filter 4\n"); |
1160 | return TIPC_ERR_NO_PORT; | 1160 | return TIPC_ERR_NO_PORT; |
1161 | } | 1161 | } |
1162 | } | 1162 | } |
1163 | else if (sock->state == SS_LISTENING) { | 1163 | else if (sock->state == SS_LISTENING) { |
1164 | if (msg_connected(msg) || msg_errcode(msg)) { | 1164 | if (msg_connected(msg) || msg_errcode(msg)) { |
1165 | msg_dbg(msg, "dispatch filter 5\n"); | 1165 | msg_dbg(msg, "dispatch filter 5\n"); |
1166 | return TIPC_ERR_NO_PORT; | 1166 | return TIPC_ERR_NO_PORT; |
1167 | } | 1167 | } |
1168 | } | 1168 | } |
1169 | else if (sock->state == SS_DISCONNECTING) { | 1169 | else if (sock->state == SS_DISCONNECTING) { |
1170 | msg_dbg(msg, "dispatch filter 6\n"); | 1170 | msg_dbg(msg, "dispatch filter 6\n"); |
1171 | return TIPC_ERR_NO_PORT; | 1171 | return TIPC_ERR_NO_PORT; |
@@ -1180,18 +1180,18 @@ static u32 dispatch(struct tipc_port *tport, struct sk_buff *buf) | |||
1180 | 1180 | ||
1181 | /* Reject message if there isn't room to queue it */ | 1181 | /* Reject message if there isn't room to queue it */ |
1182 | 1182 | ||
1183 | if (unlikely((u32)atomic_read(&tipc_queue_size) > | 1183 | if (unlikely((u32)atomic_read(&tipc_queue_size) > |
1184 | OVERLOAD_LIMIT_BASE)) { | 1184 | OVERLOAD_LIMIT_BASE)) { |
1185 | if (queue_overloaded(atomic_read(&tipc_queue_size), | 1185 | if (queue_overloaded(atomic_read(&tipc_queue_size), |
1186 | OVERLOAD_LIMIT_BASE, msg)) | 1186 | OVERLOAD_LIMIT_BASE, msg)) |
1187 | return TIPC_ERR_OVERLOAD; | 1187 | return TIPC_ERR_OVERLOAD; |
1188 | } | 1188 | } |
1189 | recv_q_len = skb_queue_len(&tsock->sk.sk_receive_queue); | 1189 | recv_q_len = skb_queue_len(&tsock->sk.sk_receive_queue); |
1190 | if (unlikely(recv_q_len > (OVERLOAD_LIMIT_BASE / 2))) { | 1190 | if (unlikely(recv_q_len > (OVERLOAD_LIMIT_BASE / 2))) { |
1191 | if (queue_overloaded(recv_q_len, | 1191 | if (queue_overloaded(recv_q_len, |
1192 | OVERLOAD_LIMIT_BASE / 2, msg)) | 1192 | OVERLOAD_LIMIT_BASE / 2, msg)) |
1193 | return TIPC_ERR_OVERLOAD; | 1193 | return TIPC_ERR_OVERLOAD; |
1194 | } | 1194 | } |
1195 | 1195 | ||
1196 | /* Initiate connection termination for an incoming 'FIN' */ | 1196 | /* Initiate connection termination for an incoming 'FIN' */ |
1197 | 1197 | ||
@@ -1213,10 +1213,10 @@ static u32 dispatch(struct tipc_port *tport, struct sk_buff *buf) | |||
1213 | return TIPC_OK; | 1213 | return TIPC_OK; |
1214 | } | 1214 | } |
1215 | 1215 | ||
1216 | /** | 1216 | /** |
1217 | * wakeupdispatch - wake up port after congestion | 1217 | * wakeupdispatch - wake up port after congestion |
1218 | * @tport: port to wakeup | 1218 | * @tport: port to wakeup |
1219 | * | 1219 | * |
1220 | * Called with port lock on. | 1220 | * Called with port lock on. |
1221 | */ | 1221 | */ |
1222 | 1222 | ||
@@ -1238,7 +1238,7 @@ static void wakeupdispatch(struct tipc_port *tport) | |||
1238 | * Returns 0 on success, errno otherwise | 1238 | * Returns 0 on success, errno otherwise |
1239 | */ | 1239 | */ |
1240 | 1240 | ||
1241 | static int connect(struct socket *sock, struct sockaddr *dest, int destlen, | 1241 | static int connect(struct socket *sock, struct sockaddr *dest, int destlen, |
1242 | int flags) | 1242 | int flags) |
1243 | { | 1243 | { |
1244 | struct tipc_sock *tsock = tipc_sk(sock->sk); | 1244 | struct tipc_sock *tsock = tipc_sk(sock->sk); |
@@ -1260,7 +1260,7 @@ static int connect(struct socket *sock, struct sockaddr *dest, int destlen, | |||
1260 | if (sock->state == SS_CONNECTING) | 1260 | if (sock->state == SS_CONNECTING) |
1261 | return -EALREADY; | 1261 | return -EALREADY; |
1262 | if (sock->state != SS_UNCONNECTED) | 1262 | if (sock->state != SS_UNCONNECTED) |
1263 | return -EISCONN; | 1263 | return -EISCONN; |
1264 | 1264 | ||
1265 | /* | 1265 | /* |
1266 | * Reject connection attempt using multicast address | 1266 | * Reject connection attempt using multicast address |
@@ -1270,7 +1270,7 @@ static int connect(struct socket *sock, struct sockaddr *dest, int destlen, | |||
1270 | */ | 1270 | */ |
1271 | 1271 | ||
1272 | if (dst->addrtype == TIPC_ADDR_MCAST) | 1272 | if (dst->addrtype == TIPC_ADDR_MCAST) |
1273 | return -EINVAL; | 1273 | return -EINVAL; |
1274 | 1274 | ||
1275 | /* Send a 'SYN-' to destination */ | 1275 | /* Send a 'SYN-' to destination */ |
1276 | 1276 | ||
@@ -1281,19 +1281,19 @@ static int connect(struct socket *sock, struct sockaddr *dest, int destlen, | |||
1281 | return res; | 1281 | return res; |
1282 | } | 1282 | } |
1283 | 1283 | ||
1284 | if (down_interruptible(&tsock->sem)) | 1284 | if (down_interruptible(&tsock->sem)) |
1285 | return -ERESTARTSYS; | 1285 | return -ERESTARTSYS; |
1286 | 1286 | ||
1287 | /* Wait for destination's 'ACK' response */ | 1287 | /* Wait for destination's 'ACK' response */ |
1288 | 1288 | ||
1289 | res = wait_event_interruptible_timeout(*sock->sk->sk_sleep, | 1289 | res = wait_event_interruptible_timeout(*sock->sk->sk_sleep, |
1290 | skb_queue_len(&sock->sk->sk_receive_queue), | 1290 | skb_queue_len(&sock->sk->sk_receive_queue), |
1291 | sock->sk->sk_rcvtimeo); | 1291 | sock->sk->sk_rcvtimeo); |
1292 | buf = skb_peek(&sock->sk->sk_receive_queue); | 1292 | buf = skb_peek(&sock->sk->sk_receive_queue); |
1293 | if (res > 0) { | 1293 | if (res > 0) { |
1294 | msg = buf_msg(buf); | 1294 | msg = buf_msg(buf); |
1295 | res = auto_connect(sock, tsock, msg); | 1295 | res = auto_connect(sock, tsock, msg); |
1296 | if (!res) { | 1296 | if (!res) { |
1297 | if (!msg_data_sz(msg)) | 1297 | if (!msg_data_sz(msg)) |
1298 | advance_queue(tsock); | 1298 | advance_queue(tsock); |
1299 | } | 1299 | } |
@@ -1301,7 +1301,7 @@ static int connect(struct socket *sock, struct sockaddr *dest, int destlen, | |||
1301 | if (res == 0) { | 1301 | if (res == 0) { |
1302 | res = -ETIMEDOUT; | 1302 | res = -ETIMEDOUT; |
1303 | } else | 1303 | } else |
1304 | { /* leave "res" unchanged */ } | 1304 | { /* leave "res" unchanged */ } |
1305 | sock->state = SS_DISCONNECTING; | 1305 | sock->state = SS_DISCONNECTING; |
1306 | } | 1306 | } |
1307 | 1307 | ||
@@ -1309,11 +1309,11 @@ static int connect(struct socket *sock, struct sockaddr *dest, int destlen, | |||
1309 | return res; | 1309 | return res; |
1310 | } | 1310 | } |
1311 | 1311 | ||
1312 | /** | 1312 | /** |
1313 | * listen - allow socket to listen for incoming connections | 1313 | * listen - allow socket to listen for incoming connections |
1314 | * @sock: socket structure | 1314 | * @sock: socket structure |
1315 | * @len: (unused) | 1315 | * @len: (unused) |
1316 | * | 1316 | * |
1317 | * Returns 0 on success, errno otherwise | 1317 | * Returns 0 on success, errno otherwise |
1318 | */ | 1318 | */ |
1319 | 1319 | ||
@@ -1326,15 +1326,15 @@ static int listen(struct socket *sock, int len) | |||
1326 | if (sock->state != SS_UNCONNECTED) | 1326 | if (sock->state != SS_UNCONNECTED) |
1327 | return -EINVAL; | 1327 | return -EINVAL; |
1328 | sock->state = SS_LISTENING; | 1328 | sock->state = SS_LISTENING; |
1329 | return 0; | 1329 | return 0; |
1330 | } | 1330 | } |
1331 | 1331 | ||
1332 | /** | 1332 | /** |
1333 | * accept - wait for connection request | 1333 | * accept - wait for connection request |
1334 | * @sock: listening socket | 1334 | * @sock: listening socket |
1335 | * @newsock: new socket that is to be connected | 1335 | * @newsock: new socket that is to be connected |
1336 | * @flags: file-related flags associated with socket | 1336 | * @flags: file-related flags associated with socket |
1337 | * | 1337 | * |
1338 | * Returns 0 on success, errno otherwise | 1338 | * Returns 0 on success, errno otherwise |
1339 | */ | 1339 | */ |
1340 | 1340 | ||
@@ -1348,15 +1348,15 @@ static int accept(struct socket *sock, struct socket *newsock, int flags) | |||
1348 | return -EOPNOTSUPP; | 1348 | return -EOPNOTSUPP; |
1349 | if (sock->state != SS_LISTENING) | 1349 | if (sock->state != SS_LISTENING) |
1350 | return -EINVAL; | 1350 | return -EINVAL; |
1351 | 1351 | ||
1352 | if (unlikely((skb_queue_len(&sock->sk->sk_receive_queue) == 0) && | 1352 | if (unlikely((skb_queue_len(&sock->sk->sk_receive_queue) == 0) && |
1353 | (flags & O_NONBLOCK))) | 1353 | (flags & O_NONBLOCK))) |
1354 | return -EWOULDBLOCK; | 1354 | return -EWOULDBLOCK; |
1355 | 1355 | ||
1356 | if (down_interruptible(&tsock->sem)) | 1356 | if (down_interruptible(&tsock->sem)) |
1357 | return -ERESTARTSYS; | 1357 | return -ERESTARTSYS; |
1358 | 1358 | ||
1359 | if (wait_event_interruptible(*sock->sk->sk_sleep, | 1359 | if (wait_event_interruptible(*sock->sk->sk_sleep, |
1360 | skb_queue_len(&sock->sk->sk_receive_queue))) { | 1360 | skb_queue_len(&sock->sk->sk_receive_queue))) { |
1361 | res = -ERESTARTSYS; | 1361 | res = -ERESTARTSYS; |
1362 | goto exit; | 1362 | goto exit; |
@@ -1381,18 +1381,18 @@ static int accept(struct socket *sock, struct socket *newsock, int flags) | |||
1381 | new_tsock->p->conn_instance = msg_nameinst(msg); | 1381 | new_tsock->p->conn_instance = msg_nameinst(msg); |
1382 | } | 1382 | } |
1383 | 1383 | ||
1384 | /* | 1384 | /* |
1385 | * Respond to 'SYN-' by discarding it & returning 'ACK'-. | 1385 | * Respond to 'SYN-' by discarding it & returning 'ACK'-. |
1386 | * Respond to 'SYN+' by queuing it on new socket. | 1386 | * Respond to 'SYN+' by queuing it on new socket. |
1387 | */ | 1387 | */ |
1388 | 1388 | ||
1389 | msg_dbg(msg,"<ACC<: "); | 1389 | msg_dbg(msg,"<ACC<: "); |
1390 | if (!msg_data_sz(msg)) { | 1390 | if (!msg_data_sz(msg)) { |
1391 | struct msghdr m = {NULL,}; | 1391 | struct msghdr m = {NULL,}; |
1392 | 1392 | ||
1393 | send_packet(NULL, newsock, &m, 0); | 1393 | send_packet(NULL, newsock, &m, 0); |
1394 | advance_queue(tsock); | 1394 | advance_queue(tsock); |
1395 | } else { | 1395 | } else { |
1396 | sock_lock(tsock); | 1396 | sock_lock(tsock); |
1397 | skb_dequeue(&sock->sk->sk_receive_queue); | 1397 | skb_dequeue(&sock->sk->sk_receive_queue); |
1398 | sock_unlock(tsock); | 1398 | sock_unlock(tsock); |
@@ -1410,7 +1410,7 @@ exit: | |||
1410 | * @how: direction to close (unused; always treated as read + write) | 1410 | * @how: direction to close (unused; always treated as read + write) |
1411 | * | 1411 | * |
1412 | * Terminates connection (if necessary), then purges socket's receive queue. | 1412 | * Terminates connection (if necessary), then purges socket's receive queue. |
1413 | * | 1413 | * |
1414 | * Returns 0 on success, errno otherwise | 1414 | * Returns 0 on success, errno otherwise |
1415 | */ | 1415 | */ |
1416 | 1416 | ||
@@ -1483,32 +1483,32 @@ restart: | |||
1483 | * @opt: option identifier | 1483 | * @opt: option identifier |
1484 | * @ov: pointer to new option value | 1484 | * @ov: pointer to new option value |
1485 | * @ol: length of option value | 1485 | * @ol: length of option value |
1486 | * | 1486 | * |
1487 | * For stream sockets only, accepts and ignores all IPPROTO_TCP options | 1487 | * For stream sockets only, accepts and ignores all IPPROTO_TCP options |
1488 | * (to ease compatibility). | 1488 | * (to ease compatibility). |
1489 | * | 1489 | * |
1490 | * Returns 0 on success, errno otherwise | 1490 | * Returns 0 on success, errno otherwise |
1491 | */ | 1491 | */ |
1492 | 1492 | ||
1493 | static int setsockopt(struct socket *sock, | 1493 | static int setsockopt(struct socket *sock, |
1494 | int lvl, int opt, char __user *ov, int ol) | 1494 | int lvl, int opt, char __user *ov, int ol) |
1495 | { | 1495 | { |
1496 | struct tipc_sock *tsock = tipc_sk(sock->sk); | 1496 | struct tipc_sock *tsock = tipc_sk(sock->sk); |
1497 | u32 value; | 1497 | u32 value; |
1498 | int res; | 1498 | int res; |
1499 | 1499 | ||
1500 | if ((lvl == IPPROTO_TCP) && (sock->type == SOCK_STREAM)) | 1500 | if ((lvl == IPPROTO_TCP) && (sock->type == SOCK_STREAM)) |
1501 | return 0; | 1501 | return 0; |
1502 | if (lvl != SOL_TIPC) | 1502 | if (lvl != SOL_TIPC) |
1503 | return -ENOPROTOOPT; | 1503 | return -ENOPROTOOPT; |
1504 | if (ol < sizeof(value)) | 1504 | if (ol < sizeof(value)) |
1505 | return -EINVAL; | 1505 | return -EINVAL; |
1506 | if ((res = get_user(value, (u32 __user *)ov))) | 1506 | if ((res = get_user(value, (u32 __user *)ov))) |
1507 | return res; | 1507 | return res; |
1508 | 1508 | ||
1509 | if (down_interruptible(&tsock->sem)) | 1509 | if (down_interruptible(&tsock->sem)) |
1510 | return -ERESTARTSYS; | 1510 | return -ERESTARTSYS; |
1511 | 1511 | ||
1512 | switch (opt) { | 1512 | switch (opt) { |
1513 | case TIPC_IMPORTANCE: | 1513 | case TIPC_IMPORTANCE: |
1514 | res = tipc_set_portimportance(tsock->p->ref, value); | 1514 | res = tipc_set_portimportance(tsock->p->ref, value); |
@@ -1516,7 +1516,7 @@ static int setsockopt(struct socket *sock, | |||
1516 | case TIPC_SRC_DROPPABLE: | 1516 | case TIPC_SRC_DROPPABLE: |
1517 | if (sock->type != SOCK_STREAM) | 1517 | if (sock->type != SOCK_STREAM) |
1518 | res = tipc_set_portunreliable(tsock->p->ref, value); | 1518 | res = tipc_set_portunreliable(tsock->p->ref, value); |
1519 | else | 1519 | else |
1520 | res = -ENOPROTOOPT; | 1520 | res = -ENOPROTOOPT; |
1521 | break; | 1521 | break; |
1522 | case TIPC_DEST_DROPPABLE: | 1522 | case TIPC_DEST_DROPPABLE: |
@@ -1540,29 +1540,29 @@ static int setsockopt(struct socket *sock, | |||
1540 | * @opt: option identifier | 1540 | * @opt: option identifier |
1541 | * @ov: receptacle for option value | 1541 | * @ov: receptacle for option value |
1542 | * @ol: receptacle for length of option value | 1542 | * @ol: receptacle for length of option value |
1543 | * | 1543 | * |
1544 | * For stream sockets only, returns 0 length result for all IPPROTO_TCP options | 1544 | * For stream sockets only, returns 0 length result for all IPPROTO_TCP options |
1545 | * (to ease compatibility). | 1545 | * (to ease compatibility). |
1546 | * | 1546 | * |
1547 | * Returns 0 on success, errno otherwise | 1547 | * Returns 0 on success, errno otherwise |
1548 | */ | 1548 | */ |
1549 | 1549 | ||
1550 | static int getsockopt(struct socket *sock, | 1550 | static int getsockopt(struct socket *sock, |
1551 | int lvl, int opt, char __user *ov, int __user *ol) | 1551 | int lvl, int opt, char __user *ov, int __user *ol) |
1552 | { | 1552 | { |
1553 | struct tipc_sock *tsock = tipc_sk(sock->sk); | 1553 | struct tipc_sock *tsock = tipc_sk(sock->sk); |
1554 | int len; | 1554 | int len; |
1555 | u32 value; | 1555 | u32 value; |
1556 | int res; | 1556 | int res; |
1557 | 1557 | ||
1558 | if ((lvl == IPPROTO_TCP) && (sock->type == SOCK_STREAM)) | 1558 | if ((lvl == IPPROTO_TCP) && (sock->type == SOCK_STREAM)) |
1559 | return put_user(0, ol); | 1559 | return put_user(0, ol); |
1560 | if (lvl != SOL_TIPC) | 1560 | if (lvl != SOL_TIPC) |
1561 | return -ENOPROTOOPT; | 1561 | return -ENOPROTOOPT; |
1562 | if ((res = get_user(len, ol))) | 1562 | if ((res = get_user(len, ol))) |
1563 | return res; | 1563 | return res; |
1564 | 1564 | ||
1565 | if (down_interruptible(&tsock->sem)) | 1565 | if (down_interruptible(&tsock->sem)) |
1566 | return -ERESTARTSYS; | 1566 | return -ERESTARTSYS; |
1567 | 1567 | ||
1568 | switch (opt) { | 1568 | switch (opt) { |
@@ -1595,30 +1595,30 @@ static int getsockopt(struct socket *sock, | |||
1595 | res = put_user(sizeof(value), ol); | 1595 | res = put_user(sizeof(value), ol); |
1596 | } | 1596 | } |
1597 | 1597 | ||
1598 | up(&tsock->sem); | 1598 | up(&tsock->sem); |
1599 | return res; | 1599 | return res; |
1600 | } | 1600 | } |
1601 | 1601 | ||
1602 | /** | 1602 | /** |
1603 | * Placeholders for non-implemented functionality | 1603 | * Placeholders for non-implemented functionality |
1604 | * | 1604 | * |
1605 | * Returns error code (POSIX-compliant where defined) | 1605 | * Returns error code (POSIX-compliant where defined) |
1606 | */ | 1606 | */ |
1607 | 1607 | ||
1608 | static int ioctl(struct socket *s, u32 cmd, unsigned long arg) | 1608 | static int ioctl(struct socket *s, u32 cmd, unsigned long arg) |
1609 | { | 1609 | { |
1610 | return -EINVAL; | 1610 | return -EINVAL; |
1611 | } | 1611 | } |
1612 | 1612 | ||
1613 | static int no_mmap(struct file *file, struct socket *sock, | 1613 | static int no_mmap(struct file *file, struct socket *sock, |
1614 | struct vm_area_struct *vma) | 1614 | struct vm_area_struct *vma) |
1615 | { | 1615 | { |
1616 | return -EINVAL; | 1616 | return -EINVAL; |
1617 | } | 1617 | } |
1618 | static ssize_t no_sendpage(struct socket *sock, struct page *page, | 1618 | static ssize_t no_sendpage(struct socket *sock, struct page *page, |
1619 | int offset, size_t size, int flags) | 1619 | int offset, size_t size, int flags) |
1620 | { | 1620 | { |
1621 | return -EINVAL; | 1621 | return -EINVAL; |
1622 | } | 1622 | } |
1623 | 1623 | ||
1624 | static int no_skpair(struct socket *s1, struct socket *s2) | 1624 | static int no_skpair(struct socket *s1, struct socket *s2) |
@@ -1647,8 +1647,8 @@ static struct proto_ops msg_ops = { | |||
1647 | .getsockopt = getsockopt, | 1647 | .getsockopt = getsockopt, |
1648 | .sendmsg = send_msg, | 1648 | .sendmsg = send_msg, |
1649 | .recvmsg = recv_msg, | 1649 | .recvmsg = recv_msg, |
1650 | .mmap = no_mmap, | 1650 | .mmap = no_mmap, |
1651 | .sendpage = no_sendpage | 1651 | .sendpage = no_sendpage |
1652 | }; | 1652 | }; |
1653 | 1653 | ||
1654 | static struct proto_ops packet_ops = { | 1654 | static struct proto_ops packet_ops = { |
@@ -1668,8 +1668,8 @@ static struct proto_ops packet_ops = { | |||
1668 | .getsockopt = getsockopt, | 1668 | .getsockopt = getsockopt, |
1669 | .sendmsg = send_packet, | 1669 | .sendmsg = send_packet, |
1670 | .recvmsg = recv_msg, | 1670 | .recvmsg = recv_msg, |
1671 | .mmap = no_mmap, | 1671 | .mmap = no_mmap, |
1672 | .sendpage = no_sendpage | 1672 | .sendpage = no_sendpage |
1673 | }; | 1673 | }; |
1674 | 1674 | ||
1675 | static struct proto_ops stream_ops = { | 1675 | static struct proto_ops stream_ops = { |
@@ -1689,8 +1689,8 @@ static struct proto_ops stream_ops = { | |||
1689 | .getsockopt = getsockopt, | 1689 | .getsockopt = getsockopt, |
1690 | .sendmsg = send_stream, | 1690 | .sendmsg = send_stream, |
1691 | .recvmsg = recv_stream, | 1691 | .recvmsg = recv_stream, |
1692 | .mmap = no_mmap, | 1692 | .mmap = no_mmap, |
1693 | .sendpage = no_sendpage | 1693 | .sendpage = no_sendpage |
1694 | }; | 1694 | }; |
1695 | 1695 | ||
1696 | static struct net_proto_family tipc_family_ops = { | 1696 | static struct net_proto_family tipc_family_ops = { |
@@ -1707,14 +1707,14 @@ static struct proto tipc_proto = { | |||
1707 | 1707 | ||
1708 | /** | 1708 | /** |
1709 | * tipc_socket_init - initialize TIPC socket interface | 1709 | * tipc_socket_init - initialize TIPC socket interface |
1710 | * | 1710 | * |
1711 | * Returns 0 on success, errno otherwise | 1711 | * Returns 0 on success, errno otherwise |
1712 | */ | 1712 | */ |
1713 | int tipc_socket_init(void) | 1713 | int tipc_socket_init(void) |
1714 | { | 1714 | { |
1715 | int res; | 1715 | int res; |
1716 | 1716 | ||
1717 | res = proto_register(&tipc_proto, 1); | 1717 | res = proto_register(&tipc_proto, 1); |
1718 | if (res) { | 1718 | if (res) { |
1719 | err("Failed to register TIPC protocol type\n"); | 1719 | err("Failed to register TIPC protocol type\n"); |
1720 | goto out; | 1720 | goto out; |