Skip to content

Commit 7efba10

Browse files
lxindavem330
authored andcommitted
sctp: add SCTP_FUTURE_ASOC and SCTP_CURRENT_ASSOC for SCTP_STREAM_SCHEDULER sockopt
Check with SCTP_ALL_ASSOC instead in sctp_setsockopt_scheduler and check with SCTP_FUTURE_ASSOC instead in sctp_getsockopt_scheduler, it's compatible with 0. SCTP_CURRENT_ASSOC is supported for SCTP_STREAM_SCHEDULER in this patch. It also adds default_ss in sctp_sock to support SCTP_FUTURE_ASSOC. Signed-off-by: Xin Long <lucien.xin@gmail.com> Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent d251f05 commit 7efba10

3 files changed

Lines changed: 34 additions & 14 deletions

File tree

‎include/net/sctp/structs.h‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -211,6 +211,8 @@ struct sctp_sock {
211211
/* Flags controlling Heartbeat, SACK delay, and Path MTU Discovery. */
212212
__u32 param_flags;
213213

214+
__u32 default_ss;
215+
214216
struct sctp_rtoinfo rtoinfo;
215217
struct sctp_paddrparams paddrparam;
216218
struct sctp_assocparams assocparams;

‎net/sctp/outqueue.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,7 @@ void sctp_outq_init(struct sctp_association *asoc, struct sctp_outq *q)
212212
INIT_LIST_HEAD(&q->retransmit);
213213
INIT_LIST_HEAD(&q->sacked);
214214
INIT_LIST_HEAD(&q->abandoned);
215-
sctp_sched_set_sched(asoc, SCTP_SS_DEFAULT);
215+
sctp_sched_set_sched(asoc, sctp_sk(asoc->base.sk)->default_ss);
216216
}
217217

218218
/* Free the outqueue structure and any related pending chunks.

‎net/sctp/socket.c‎

Lines changed: 31 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -4352,29 +4352,44 @@ static int sctp_setsockopt_scheduler(struct sock *sk,
43524352
char __user *optval,
43534353
unsigned int optlen)
43544354
{
4355+
struct sctp_sock *sp = sctp_sk(sk);
43554356
struct sctp_association *asoc;
43564357
struct sctp_assoc_value params;
4357-
int retval = -EINVAL;
4358+
int retval = 0;
43584359

43594360
if (optlen < sizeof(params))
4360-
goto out;
4361+
return -EINVAL;
43614362

43624363
optlen = sizeof(params);
4363-
if (copy_from_user(&params, optval, optlen)) {
4364-
retval = -EFAULT;
4365-
goto out;
4366-
}
4364+
if (copy_from_user(&params, optval, optlen))
4365+
return -EFAULT;
43674366

43684367
if (params.assoc_value > SCTP_SS_MAX)
4369-
goto out;
4368+
return -EINVAL;
43704369

43714370
asoc = sctp_id2assoc(sk, params.assoc_id);
4372-
if (!asoc)
4373-
goto out;
4371+
if (!asoc && params.assoc_id > SCTP_ALL_ASSOC &&
4372+
sctp_style(sk, UDP))
4373+
return -EINVAL;
43744374

4375-
retval = sctp_sched_set_sched(asoc, params.assoc_value);
4375+
if (asoc)
4376+
return sctp_sched_set_sched(asoc, params.assoc_value);
4377+
4378+
if (params.assoc_id == SCTP_FUTURE_ASSOC ||
4379+
params.assoc_id == SCTP_ALL_ASSOC)
4380+
sp->default_ss = params.assoc_value;
4381+
4382+
if (params.assoc_id == SCTP_CURRENT_ASSOC ||
4383+
params.assoc_id == SCTP_ALL_ASSOC) {
4384+
list_for_each_entry(asoc, &sp->ep->asocs, asocs) {
4385+
int ret = sctp_sched_set_sched(asoc,
4386+
params.assoc_value);
4387+
4388+
if (ret && !retval)
4389+
retval = ret;
4390+
}
4391+
}
43764392

4377-
out:
43784393
return retval;
43794394
}
43804395

@@ -5005,6 +5020,7 @@ static int sctp_init_sock(struct sock *sk)
50055020
sp->param_flags = SPP_HB_ENABLE |
50065021
SPP_PMTUD_ENABLE |
50075022
SPP_SACKDELAY_ENABLE;
5023+
sp->default_ss = SCTP_SS_DEFAULT;
50085024

50095025
/* If enabled no SCTP message fragmentation will be performed.
50105026
* Configure through SCTP_DISABLE_FRAGMENTS socket option.
@@ -7572,12 +7588,14 @@ static int sctp_getsockopt_scheduler(struct sock *sk, int len,
75727588
goto out;
75737589

75747590
asoc = sctp_id2assoc(sk, params.assoc_id);
7575-
if (!asoc) {
7591+
if (!asoc && params.assoc_id != SCTP_FUTURE_ASSOC &&
7592+
sctp_style(sk, UDP)) {
75767593
retval = -EINVAL;
75777594
goto out;
75787595
}
75797596

7580-
params.assoc_value = sctp_sched_get_sched(asoc);
7597+
params.assoc_value = asoc ? sctp_sched_get_sched(asoc)
7598+
: sctp_sk(sk)->default_ss;
75817599

75827600
if (put_user(len, optlen))
75837601
goto out;

0 commit comments

Comments
 (0)