diff options
author | Diego Elio 'Flameeyes' Pettenò <flameeyes@gmail.com> | 2010-09-02 23:47:03 -0400 |
---|---|---|
committer | David S. Miller <davem@davemloft.net> | 2010-09-08 16:08:05 -0400 |
commit | 65040c33ee8d0199ab7686402bffdbf9e1e26cbe (patch) | |
tree | 4c8a35d0b6da2964a0de8f6668c0f5f47efe2825 /net/sctp | |
parent | 2edae08e5b75269855fef3c74fe4292c066e7c33 (diff) |
sctp: implement SIOCINQ ioctl() (take 3)
This simple patch copies the current approach for SIOCINQ ioctl() from DCCP
into SCTP so that the userland code working with SCTP can use a similar
interface across different protocols to know how much space to allocate for
a buffer.
Signed-off-by: Diego Elio Pettenò <flameeyes@gmail.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
Diffstat (limited to 'net/sctp')
-rw-r--r-- | net/sctp/socket.c | 35 |
1 files changed, 34 insertions, 1 deletions
diff --git a/net/sctp/socket.c b/net/sctp/socket.c index cf6dcc908b88..6a691d84aef4 100644 --- a/net/sctp/socket.c +++ b/net/sctp/socket.c | |||
@@ -3592,7 +3592,40 @@ out: | |||
3592 | /* The SCTP ioctl handler. */ | 3592 | /* The SCTP ioctl handler. */ |
3593 | SCTP_STATIC int sctp_ioctl(struct sock *sk, int cmd, unsigned long arg) | 3593 | SCTP_STATIC int sctp_ioctl(struct sock *sk, int cmd, unsigned long arg) |
3594 | { | 3594 | { |
3595 | return -ENOIOCTLCMD; | 3595 | int rc = -ENOTCONN; |
3596 | |||
3597 | sctp_lock_sock(sk); | ||
3598 | |||
3599 | /* | ||
3600 | * SEQPACKET-style sockets in LISTENING state are valid, for | ||
3601 | * SCTP, so only discard TCP-style sockets in LISTENING state. | ||
3602 | */ | ||
3603 | if (sctp_style(sk, TCP) && sctp_sstate(sk, LISTENING)) | ||
3604 | goto out; | ||
3605 | |||
3606 | switch (cmd) { | ||
3607 | case SIOCINQ: { | ||
3608 | struct sk_buff *skb; | ||
3609 | unsigned int amount = 0; | ||
3610 | |||
3611 | skb = skb_peek(&sk->sk_receive_queue); | ||
3612 | if (skb != NULL) { | ||
3613 | /* | ||
3614 | * We will only return the amount of this packet since | ||
3615 | * that is all that will be read. | ||
3616 | */ | ||
3617 | amount = skb->len; | ||
3618 | } | ||
3619 | rc = put_user(amount, (int __user *)arg); | ||
3620 | } | ||
3621 | break; | ||
3622 | default: | ||
3623 | rc = -ENOIOCTLCMD; | ||
3624 | break; | ||
3625 | } | ||
3626 | out: | ||
3627 | sctp_release_sock(sk); | ||
3628 | return rc; | ||
3596 | } | 3629 | } |
3597 | 3630 | ||
3598 | /* This is the function which gets called during socket creation to | 3631 | /* This is the function which gets called during socket creation to |