]> git.baikalelectronics.ru Git - kernel.git/commitdiff
sctp: use SCTP_FUTURE_ASSOC and add SCTP_CURRENT_ASSOC for SCTP_DEFAULT_SNDINFO sockopt
authorXin Long <lucien.xin@gmail.com>
Mon, 28 Jan 2019 07:08:36 +0000 (15:08 +0800)
committerDavid S. Miller <davem@davemloft.net>
Wed, 30 Jan 2019 08:44:07 +0000 (00:44 -0800)
Check with SCTP_ALL_ASSOC instead in sctp_setsockopt_default_sndinfo and
check with SCTP_FUTURE_ASSOC instead in sctp_getsockopt_default_sndinfo,
it's compatible with 0.

SCTP_CURRENT_ASSOC is supported for SCTP_DEFAULT_SNDINFO in this patch.

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

index 3d3b4f0b1dbbdc95d24a4194d93cd0942ea4633e..6a674cfe4616235754f6d5c990a0c381f3235481 100644 (file)
@@ -3067,20 +3067,37 @@ static int sctp_setsockopt_default_sndinfo(struct sock *sk,
                return -EINVAL;
 
        asoc = sctp_id2assoc(sk, info.snd_assoc_id);
-       if (!asoc && info.snd_assoc_id && sctp_style(sk, UDP))
+       if (!asoc && info.snd_assoc_id > SCTP_ALL_ASSOC &&
+           sctp_style(sk, UDP))
                return -EINVAL;
+
        if (asoc) {
                asoc->default_stream = info.snd_sid;
                asoc->default_flags = info.snd_flags;
                asoc->default_ppid = info.snd_ppid;
                asoc->default_context = info.snd_context;
-       } else {
+
+               return 0;
+       }
+
+       if (info.snd_assoc_id == SCTP_FUTURE_ASSOC ||
+           info.snd_assoc_id == SCTP_ALL_ASSOC) {
                sp->default_stream = info.snd_sid;
                sp->default_flags = info.snd_flags;
                sp->default_ppid = info.snd_ppid;
                sp->default_context = info.snd_context;
        }
 
+       if (info.snd_assoc_id == SCTP_CURRENT_ASSOC ||
+           info.snd_assoc_id == SCTP_ALL_ASSOC) {
+               list_for_each_entry(asoc, &sp->ep->asocs, asocs) {
+                       asoc->default_stream = info.snd_sid;
+                       asoc->default_flags = info.snd_flags;
+                       asoc->default_ppid = info.snd_ppid;
+                       asoc->default_context = info.snd_context;
+               }
+       }
+
        return 0;
 }
 
@@ -6287,8 +6304,10 @@ static int sctp_getsockopt_default_sndinfo(struct sock *sk, int len,
                return -EFAULT;
 
        asoc = sctp_id2assoc(sk, info.snd_assoc_id);
-       if (!asoc && info.snd_assoc_id && sctp_style(sk, UDP))
+       if (!asoc && info.snd_assoc_id != SCTP_FUTURE_ASSOC &&
+           sctp_style(sk, UDP))
                return -EINVAL;
+
        if (asoc) {
                info.snd_sid = asoc->default_stream;
                info.snd_flags = asoc->default_flags;