Skip to content

Commit e93b4f0

Browse files
committed
Merge branch 'sctp-add-SCTP_ECN_SUPPORTED-sockopt'
Xin Long says: ==================== sctp: add SCTP_ECN_SUPPORTED sockopt This patchset is to make ecn flag per netns and endpoint and then add SCTP_ECN_SUPPORTED sockopt, as does for other feature flags. ==================== Acked-by: Neil Horman <[email protected]> Signed-off-by: David S. Miller <[email protected]>
2 parents 7add83d + d5886b9 commit e93b4f0

File tree

8 files changed

+102
-5
lines changed

8 files changed

+102
-5
lines changed

include/net/netns/sctp.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,9 @@ struct netns_sctp {
128128
/* Flag to indicate if stream interleave is enabled */
129129
int intl_enable;
130130

131+
/* Flag to indicate if ecn is enabled */
132+
int ecn_enable;
133+
131134
/*
132135
* Policy to control SCTP IPv4 address scoping
133136
* 0 - Disable IPv4 address scoping

include/net/sctp/structs.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1322,7 +1322,8 @@ struct sctp_endpoint {
13221322
/* SCTP-AUTH: endpoint shared keys */
13231323
struct list_head endpoint_shared_keys;
13241324
__u16 active_key_id;
1325-
__u8 auth_enable:1,
1325+
__u8 ecn_enable:1,
1326+
auth_enable:1,
13261327
intl_enable:1,
13271328
prsctp_enable:1,
13281329
asconf_enable:1,

include/uapi/linux/sctp.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,7 @@ typedef __s32 sctp_assoc_t;
136136
#define SCTP_EVENT 127
137137
#define SCTP_ASCONF_SUPPORTED 128
138138
#define SCTP_AUTH_SUPPORTED 129
139+
#define SCTP_ECN_SUPPORTED 130
139140

140141
/* PR-SCTP policies */
141142
#define SCTP_PR_SCTP_NONE 0x0000

net/sctp/endpointola.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,7 @@ static struct sctp_endpoint *sctp_endpoint_init(struct sctp_endpoint *ep,
106106
*/
107107
ep->prsctp_enable = net->sctp.prsctp_enable;
108108
ep->reconf_enable = net->sctp.reconf_enable;
109+
ep->ecn_enable = net->sctp.ecn_enable;
109110

110111
/* Remember who we are attached to. */
111112
ep->base.sk = sk;

net/sctp/protocol.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1254,6 +1254,9 @@ static int __net_init sctp_defaults_init(struct net *net)
12541254
/* Disable AUTH by default. */
12551255
net->sctp.auth_enable = 0;
12561256

1257+
/* Enable ECN by default. */
1258+
net->sctp.ecn_enable = 1;
1259+
12571260
/* Set SCOPE policy to enabled */
12581261
net->sctp.scope_policy = SCTP_SCOPE_POLICY_ENABLE;
12591262

net/sctp/sm_make_chunk.c

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -244,7 +244,9 @@ struct sctp_chunk *sctp_make_init(const struct sctp_association *asoc,
244244

245245
chunksize = sizeof(init) + addrs_len;
246246
chunksize += SCTP_PAD4(SCTP_SAT_LEN(num_types));
247-
chunksize += sizeof(ecap_param);
247+
248+
if (asoc->ep->ecn_enable)
249+
chunksize += sizeof(ecap_param);
248250

249251
if (asoc->ep->prsctp_enable)
250252
chunksize += sizeof(prsctp_param);
@@ -335,7 +337,8 @@ struct sctp_chunk *sctp_make_init(const struct sctp_association *asoc,
335337
sctp_addto_chunk(retval, sizeof(sat), &sat);
336338
sctp_addto_chunk(retval, num_types * sizeof(__u16), &types);
337339

338-
sctp_addto_chunk(retval, sizeof(ecap_param), &ecap_param);
340+
if (asoc->ep->ecn_enable)
341+
sctp_addto_chunk(retval, sizeof(ecap_param), &ecap_param);
339342

340343
/* Add the supported extensions parameter. Be nice and add this
341344
* fist before addiding the parameters for the extensions themselves
@@ -2597,8 +2600,13 @@ static int sctp_process_param(struct sctp_association *asoc,
25972600
break;
25982601

25992602
case SCTP_PARAM_ECN_CAPABLE:
2600-
asoc->peer.ecn_capable = 1;
2601-
break;
2603+
if (asoc->ep->ecn_enable) {
2604+
asoc->peer.ecn_capable = 1;
2605+
break;
2606+
}
2607+
/* Fall Through */
2608+
goto fall_through;
2609+
26022610

26032611
case SCTP_PARAM_ADAPTATION_LAYER_IND:
26042612
asoc->peer.adaptation_ind = ntohl(param.aind->adaptation_ind);

net/sctp/socket.c

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4560,6 +4560,34 @@ static int sctp_setsockopt_auth_supported(struct sock *sk,
45604560
return retval;
45614561
}
45624562

4563+
static int sctp_setsockopt_ecn_supported(struct sock *sk,
4564+
char __user *optval,
4565+
unsigned int optlen)
4566+
{
4567+
struct sctp_assoc_value params;
4568+
struct sctp_association *asoc;
4569+
int retval = -EINVAL;
4570+
4571+
if (optlen != sizeof(params))
4572+
goto out;
4573+
4574+
if (copy_from_user(&params, optval, optlen)) {
4575+
retval = -EFAULT;
4576+
goto out;
4577+
}
4578+
4579+
asoc = sctp_id2assoc(sk, params.assoc_id);
4580+
if (!asoc && params.assoc_id != SCTP_FUTURE_ASSOC &&
4581+
sctp_style(sk, UDP))
4582+
goto out;
4583+
4584+
sctp_sk(sk)->ep->ecn_enable = !!params.assoc_value;
4585+
retval = 0;
4586+
4587+
out:
4588+
return retval;
4589+
}
4590+
45634591
/* API 6.2 setsockopt(), getsockopt()
45644592
*
45654593
* Applications use setsockopt() and getsockopt() to set or retrieve
@@ -4766,6 +4794,9 @@ static int sctp_setsockopt(struct sock *sk, int level, int optname,
47664794
case SCTP_AUTH_SUPPORTED:
47674795
retval = sctp_setsockopt_auth_supported(sk, optval, optlen);
47684796
break;
4797+
case SCTP_ECN_SUPPORTED:
4798+
retval = sctp_setsockopt_ecn_supported(sk, optval, optlen);
4799+
break;
47694800
default:
47704801
retval = -ENOPROTOOPT;
47714802
break;
@@ -7828,6 +7859,45 @@ static int sctp_getsockopt_auth_supported(struct sock *sk, int len,
78287859
return retval;
78297860
}
78307861

7862+
static int sctp_getsockopt_ecn_supported(struct sock *sk, int len,
7863+
char __user *optval,
7864+
int __user *optlen)
7865+
{
7866+
struct sctp_assoc_value params;
7867+
struct sctp_association *asoc;
7868+
int retval = -EFAULT;
7869+
7870+
if (len < sizeof(params)) {
7871+
retval = -EINVAL;
7872+
goto out;
7873+
}
7874+
7875+
len = sizeof(params);
7876+
if (copy_from_user(&params, optval, len))
7877+
goto out;
7878+
7879+
asoc = sctp_id2assoc(sk, params.assoc_id);
7880+
if (!asoc && params.assoc_id != SCTP_FUTURE_ASSOC &&
7881+
sctp_style(sk, UDP)) {
7882+
retval = -EINVAL;
7883+
goto out;
7884+
}
7885+
7886+
params.assoc_value = asoc ? asoc->peer.ecn_capable
7887+
: sctp_sk(sk)->ep->ecn_enable;
7888+
7889+
if (put_user(len, optlen))
7890+
goto out;
7891+
7892+
if (copy_to_user(optval, &params, len))
7893+
goto out;
7894+
7895+
retval = 0;
7896+
7897+
out:
7898+
return retval;
7899+
}
7900+
78317901
static int sctp_getsockopt(struct sock *sk, int level, int optname,
78327902
char __user *optval, int __user *optlen)
78337903
{
@@ -8037,6 +8107,9 @@ static int sctp_getsockopt(struct sock *sk, int level, int optname,
80378107
retval = sctp_getsockopt_auth_supported(sk, len, optval,
80388108
optlen);
80398109
break;
8110+
case SCTP_ECN_SUPPORTED:
8111+
retval = sctp_getsockopt_ecn_supported(sk, len, optval, optlen);
8112+
break;
80408113
default:
80418114
retval = -ENOPROTOOPT;
80428115
break;

net/sctp/sysctl.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -277,6 +277,13 @@ static struct ctl_table sctp_net_table[] = {
277277
.mode = 0644,
278278
.proc_handler = proc_dointvec,
279279
},
280+
{
281+
.procname = "ecn_enable",
282+
.data = &init_net.sctp.ecn_enable,
283+
.maxlen = sizeof(int),
284+
.mode = 0644,
285+
.proc_handler = proc_dointvec,
286+
},
280287
{
281288
.procname = "addr_scope_policy",
282289
.data = &init_net.sctp.scope_policy,

0 commit comments

Comments
 (0)