sctp: use SCTP_FUTURE_ASSOC for SCTP_INTERLEAVING_SUPPORTED sockopt
authorXin Long <lucien.xin@gmail.com>
Mon, 28 Jan 2019 07:08:32 +0000 (15:08 +0800)
committerDavid S. Miller <davem@davemloft.net>
Wed, 30 Jan 2019 08:44:07 +0000 (00:44 -0800)
Check with SCTP_FUTURE_ASSOC instead in
sctp_set/getsockopt_reconfig_supported, it's compatible with 0.

It also adjusts some code to keep a same check form as other functions.

Signed-off-by: Xin Long <lucien.xin@gmail.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
net/sctp/socket.c

index e5487a1140f9ba962187f4c3b89962e25c2770d0..b9263ad6a3a10041a598d9b441327375651b84c7 100644 (file)
@@ -4240,8 +4240,8 @@ static int sctp_setsockopt_interleaving_supported(struct sock *sk,
                                                  unsigned int optlen)
 {
        struct sctp_sock *sp = sctp_sk(sk);
-       struct net *net = sock_net(sk);
        struct sctp_assoc_value params;
+       struct sctp_association *asoc;
        int retval = -EINVAL;
 
        if (optlen < sizeof(params))
@@ -4253,10 +4253,12 @@ static int sctp_setsockopt_interleaving_supported(struct sock *sk,
                goto out;
        }
 
-       if (params.assoc_id)
+       asoc = sctp_id2assoc(sk, params.assoc_id);
+       if (!asoc && params.assoc_id != SCTP_FUTURE_ASSOC &&
+           sctp_style(sk, UDP))
                goto out;
 
-       if (!net->sctp.intl_enable || !sp->frag_interleave) {
+       if (!sock_net(sk)->sctp.intl_enable || !sp->frag_interleave) {
                retval = -EPERM;
                goto out;
        }
@@ -7453,17 +7455,15 @@ static int sctp_getsockopt_interleaving_supported(struct sock *sk, int len,
                goto out;
 
        asoc = sctp_id2assoc(sk, params.assoc_id);
-       if (asoc) {
-               params.assoc_value = asoc->intl_enable;
-       } else if (!params.assoc_id) {
-               struct sctp_sock *sp = sctp_sk(sk);
-
-               params.assoc_value = sp->strm_interleave;
-       } else {
+       if (!asoc && params.assoc_id != SCTP_FUTURE_ASSOC &&
+           sctp_style(sk, UDP)) {
                retval = -EINVAL;
                goto out;
        }
 
+       params.assoc_value = asoc ? asoc->intl_enable
+                                 : sctp_sk(sk)->strm_interleave;
+
        if (put_user(len, optlen))
                goto out;