Skip to content

Commit 9fb657a

Browse files
lxindavem330
authored andcommitted
sctp: add sockopt SCTP_ENABLE_STREAM_RESET
This patch is to add sockopt SCTP_ENABLE_STREAM_RESET to get/set strreset_enable to indicate which reconf request type it supports, which is described in rfc6525 section 6.3.1. Signed-off-by: Xin Long <lucien.xin@gmail.com> Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent c28445c commit 9fb657a

File tree

4 files changed

+96
-0
lines changed

4 files changed

+96
-0
lines changed

include/net/sctp/structs.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1257,6 +1257,8 @@ struct sctp_endpoint {
12571257
__u8 auth_enable:1,
12581258
prsctp_enable:1,
12591259
reconf_enable:1;
1260+
1261+
__u8 strreset_enable;
12601262
};
12611263

12621264
/* Recover the outter endpoint structure. */
@@ -1872,6 +1874,8 @@ struct sctp_association {
18721874
prsctp_enable:1,
18731875
reconf_enable:1;
18741876

1877+
__u8 strreset_enable;
1878+
18751879
__u32 strreset_outseq; /* Update after receiving response */
18761880
__u32 strreset_inseq; /* Update after receiving request */
18771881

include/uapi/linux/sctp.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,7 @@ typedef __s32 sctp_assoc_t;
115115
#define SCTP_PR_SUPPORTED 113
116116
#define SCTP_DEFAULT_PRINFO 114
117117
#define SCTP_PR_ASSOC_STATUS 115
118+
#define SCTP_ENABLE_STREAM_RESET 118
118119

119120
/* PR-SCTP policies */
120121
#define SCTP_PR_SCTP_NONE 0x0000
@@ -138,6 +139,12 @@ typedef __s32 sctp_assoc_t;
138139
#define SCTP_PR_RTX_ENABLED(x) (SCTP_PR_POLICY(x) == SCTP_PR_SCTP_RTX)
139140
#define SCTP_PR_PRIO_ENABLED(x) (SCTP_PR_POLICY(x) == SCTP_PR_SCTP_PRIO)
140141

142+
/* For enable stream reset */
143+
#define SCTP_ENABLE_RESET_STREAM_REQ 0x01
144+
#define SCTP_ENABLE_RESET_ASSOC_REQ 0x02
145+
#define SCTP_ENABLE_CHANGE_ASSOC_REQ 0x04
146+
#define SCTP_ENABLE_STRRESET_MASK 0x07
147+
141148
/* These are bit fields for msghdr->msg_flags. See section 5.1. */
142149
/* On user space Linux, these live in <bits/socket.h> as an enum. */
143150
enum sctp_msg_flags {

net/sctp/associola.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -271,6 +271,7 @@ static struct sctp_association *sctp_association_init(struct sctp_association *a
271271
asoc->active_key_id = ep->active_key_id;
272272
asoc->prsctp_enable = ep->prsctp_enable;
273273
asoc->reconf_enable = ep->reconf_enable;
274+
asoc->strreset_enable = ep->strreset_enable;
274275

275276
/* Save the hmacs and chunks list into this association */
276277
if (ep->auth_hmacs_list)

net/sctp/socket.c

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3750,6 +3750,42 @@ static int sctp_setsockopt_default_prinfo(struct sock *sk,
37503750
return retval;
37513751
}
37523752

3753+
static int sctp_setsockopt_enable_strreset(struct sock *sk,
3754+
char __user *optval,
3755+
unsigned int optlen)
3756+
{
3757+
struct sctp_assoc_value params;
3758+
struct sctp_association *asoc;
3759+
int retval = -EINVAL;
3760+
3761+
if (optlen != sizeof(params))
3762+
goto out;
3763+
3764+
if (copy_from_user(&params, optval, optlen)) {
3765+
retval = -EFAULT;
3766+
goto out;
3767+
}
3768+
3769+
if (params.assoc_value & (~SCTP_ENABLE_STRRESET_MASK))
3770+
goto out;
3771+
3772+
asoc = sctp_id2assoc(sk, params.assoc_id);
3773+
if (asoc) {
3774+
asoc->strreset_enable = params.assoc_value;
3775+
} else if (!params.assoc_id) {
3776+
struct sctp_sock *sp = sctp_sk(sk);
3777+
3778+
sp->ep->strreset_enable = params.assoc_value;
3779+
} else {
3780+
goto out;
3781+
}
3782+
3783+
retval = 0;
3784+
3785+
out:
3786+
return retval;
3787+
}
3788+
37533789
/* API 6.2 setsockopt(), getsockopt()
37543790
*
37553791
* Applications use setsockopt() and getsockopt() to set or retrieve
@@ -3916,6 +3952,9 @@ static int sctp_setsockopt(struct sock *sk, int level, int optname,
39163952
case SCTP_DEFAULT_PRINFO:
39173953
retval = sctp_setsockopt_default_prinfo(sk, optval, optlen);
39183954
break;
3955+
case SCTP_ENABLE_STREAM_RESET:
3956+
retval = sctp_setsockopt_enable_strreset(sk, optval, optlen);
3957+
break;
39193958
default:
39203959
retval = -ENOPROTOOPT;
39213960
break;
@@ -6400,6 +6439,47 @@ static int sctp_getsockopt_pr_assocstatus(struct sock *sk, int len,
64006439
return retval;
64016440
}
64026441

6442+
static int sctp_getsockopt_enable_strreset(struct sock *sk, int len,
6443+
char __user *optval,
6444+
int __user *optlen)
6445+
{
6446+
struct sctp_assoc_value params;
6447+
struct sctp_association *asoc;
6448+
int retval = -EFAULT;
6449+
6450+
if (len < sizeof(params)) {
6451+
retval = -EINVAL;
6452+
goto out;
6453+
}
6454+
6455+
len = sizeof(params);
6456+
if (copy_from_user(&params, optval, len))
6457+
goto out;
6458+
6459+
asoc = sctp_id2assoc(sk, params.assoc_id);
6460+
if (asoc) {
6461+
params.assoc_value = asoc->strreset_enable;
6462+
} else if (!params.assoc_id) {
6463+
struct sctp_sock *sp = sctp_sk(sk);
6464+
6465+
params.assoc_value = sp->ep->strreset_enable;
6466+
} else {
6467+
retval = -EINVAL;
6468+
goto out;
6469+
}
6470+
6471+
if (put_user(len, optlen))
6472+
goto out;
6473+
6474+
if (copy_to_user(optval, &params, len))
6475+
goto out;
6476+
6477+
retval = 0;
6478+
6479+
out:
6480+
return retval;
6481+
}
6482+
64036483
static int sctp_getsockopt(struct sock *sk, int level, int optname,
64046484
char __user *optval, int __user *optlen)
64056485
{
@@ -6567,6 +6647,10 @@ static int sctp_getsockopt(struct sock *sk, int level, int optname,
65676647
retval = sctp_getsockopt_pr_assocstatus(sk, len, optval,
65686648
optlen);
65696649
break;
6650+
case SCTP_ENABLE_STREAM_RESET:
6651+
retval = sctp_getsockopt_enable_strreset(sk, len, optval,
6652+
optlen);
6653+
break;
65706654
default:
65716655
retval = -ENOPROTOOPT;
65726656
break;

0 commit comments

Comments
 (0)