Skip to content

Commit 13aa877

Browse files
marceloleitnerdavem330
authored andcommitted
sctp: add sockopt to get/set stream scheduler
As defined per RFC Draft ndata Section 4.3.2, named as SCTP_STREAM_SCHEDULER. See-also: https://tools.ietf.org/html/draft-ietf-tsvwg-sctp-ndata-13 Tested-by: Xin Long <[email protected]> Signed-off-by: Marcelo Ricardo Leitner <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent 5bbbbe3 commit 13aa877

File tree

2 files changed

+76
-0
lines changed

2 files changed

+76
-0
lines changed

include/uapi/linux/sctp.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,7 @@ typedef __s32 sctp_assoc_t;
122122
#define SCTP_RESET_ASSOC 120
123123
#define SCTP_ADD_STREAMS 121
124124
#define SCTP_SOCKOPT_PEELOFF_FLAGS 122
125+
#define SCTP_STREAM_SCHEDULER 123
125126

126127
/* PR-SCTP policies */
127128
#define SCTP_PR_SCTP_NONE 0x0000

net/sctp/socket.c

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@
7979
#include <net/sock.h>
8080
#include <net/sctp/sctp.h>
8181
#include <net/sctp/sm.h>
82+
#include <net/sctp/stream_sched.h>
8283

8384
/* Forward declarations for internal helper functions. */
8485
static int sctp_writeable(struct sock *sk);
@@ -3914,6 +3915,36 @@ static int sctp_setsockopt_add_streams(struct sock *sk,
39143915
return retval;
39153916
}
39163917

3918+
static int sctp_setsockopt_scheduler(struct sock *sk,
3919+
char __user *optval,
3920+
unsigned int optlen)
3921+
{
3922+
struct sctp_association *asoc;
3923+
struct sctp_assoc_value params;
3924+
int retval = -EINVAL;
3925+
3926+
if (optlen < sizeof(params))
3927+
goto out;
3928+
3929+
optlen = sizeof(params);
3930+
if (copy_from_user(&params, optval, optlen)) {
3931+
retval = -EFAULT;
3932+
goto out;
3933+
}
3934+
3935+
if (params.assoc_value > SCTP_SS_MAX)
3936+
goto out;
3937+
3938+
asoc = sctp_id2assoc(sk, params.assoc_id);
3939+
if (!asoc)
3940+
goto out;
3941+
3942+
retval = sctp_sched_set_sched(asoc, params.assoc_value);
3943+
3944+
out:
3945+
return retval;
3946+
}
3947+
39173948
/* API 6.2 setsockopt(), getsockopt()
39183949
*
39193950
* Applications use setsockopt() and getsockopt() to set or retrieve
@@ -4095,6 +4126,9 @@ static int sctp_setsockopt(struct sock *sk, int level, int optname,
40954126
case SCTP_ADD_STREAMS:
40964127
retval = sctp_setsockopt_add_streams(sk, optval, optlen);
40974128
break;
4129+
case SCTP_STREAM_SCHEDULER:
4130+
retval = sctp_setsockopt_scheduler(sk, optval, optlen);
4131+
break;
40984132
default:
40994133
retval = -ENOPROTOOPT;
41004134
break;
@@ -6793,6 +6827,43 @@ static int sctp_getsockopt_enable_strreset(struct sock *sk, int len,
67936827
return retval;
67946828
}
67956829

6830+
static int sctp_getsockopt_scheduler(struct sock *sk, int len,
6831+
char __user *optval,
6832+
int __user *optlen)
6833+
{
6834+
struct sctp_assoc_value params;
6835+
struct sctp_association *asoc;
6836+
int retval = -EFAULT;
6837+
6838+
if (len < sizeof(params)) {
6839+
retval = -EINVAL;
6840+
goto out;
6841+
}
6842+
6843+
len = sizeof(params);
6844+
if (copy_from_user(&params, optval, len))
6845+
goto out;
6846+
6847+
asoc = sctp_id2assoc(sk, params.assoc_id);
6848+
if (!asoc) {
6849+
retval = -EINVAL;
6850+
goto out;
6851+
}
6852+
6853+
params.assoc_value = sctp_sched_get_sched(asoc);
6854+
6855+
if (put_user(len, optlen))
6856+
goto out;
6857+
6858+
if (copy_to_user(optval, &params, len))
6859+
goto out;
6860+
6861+
retval = 0;
6862+
6863+
out:
6864+
return retval;
6865+
}
6866+
67966867
static int sctp_getsockopt(struct sock *sk, int level, int optname,
67976868
char __user *optval, int __user *optlen)
67986869
{
@@ -6975,6 +7046,10 @@ static int sctp_getsockopt(struct sock *sk, int level, int optname,
69757046
retval = sctp_getsockopt_enable_strreset(sk, len, optval,
69767047
optlen);
69777048
break;
7049+
case SCTP_STREAM_SCHEDULER:
7050+
retval = sctp_getsockopt_scheduler(sk, len, optval,
7051+
optlen);
7052+
break;
69787053
default:
69797054
retval = -ENOPROTOOPT;
69807055
break;

0 commit comments

Comments
 (0)