Skip to content

Commit 65040c3

Browse files
Flameeyesdavem330
authored andcommitted
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>
1 parent 2edae08 commit 65040c3

1 file changed

Lines changed: 34 additions & 1 deletion

File tree

‎net/sctp/socket.c‎

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3592,7 +3592,40 @@ SCTP_STATIC struct sock *sctp_accept(struct sock *sk, int flags, int *err)
35923592
/* The SCTP ioctl handler. */
35933593
SCTP_STATIC int sctp_ioctl(struct sock *sk, int cmd, unsigned long arg)
35943594
{
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;
35963629
}
35973630

35983631
/* This is the function which gets called during socket creation to

0 commit comments

Comments
 (0)