sctp: use SCTP_FUTURE_ASSOC and add SCTP_CURRENT_ASSOC for SCTP_AUTH_ACTIVE_KEY sockopt
authorXin Long <lucien.xin@gmail.com>
Mon, 28 Jan 2019 07:08:40 +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_auth_key.
SCTP_CURRENT_ASSOC is supported for SCTP_AUTH_ACTIVE_KEY 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 ec969c0a7891f2b0c49f7a86e20c7efebe4bc379..3345eb160ca1fa7179b80ea093c2d69d33bf1ebc 100644 (file)
@@ -3832,8 +3832,9 @@ static int sctp_setsockopt_active_key(struct sock *sk,
                                      unsigned int optlen)
 {
        struct sctp_endpoint *ep = sctp_sk(sk)->ep;
-       struct sctp_authkeyid val;
        struct sctp_association *asoc;
+       struct sctp_authkeyid val;
+       int ret = 0;
 
        if (!ep->auth_enable)
                return -EACCES;
@@ -3844,10 +3845,32 @@ static int sctp_setsockopt_active_key(struct sock *sk,
                return -EFAULT;
 
        asoc = sctp_id2assoc(sk, val.scact_assoc_id);
-       if (!asoc && val.scact_assoc_id && sctp_style(sk, UDP))
+       if (!asoc && val.scact_assoc_id > SCTP_ALL_ASSOC &&
+           sctp_style(sk, UDP))
                return -EINVAL;
 
-       return sctp_auth_set_active_key(ep, asoc, val.scact_keynumber);
+       if (asoc)
+               return sctp_auth_set_active_key(ep, asoc, val.scact_keynumber);
+
+       if (val.scact_assoc_id == SCTP_FUTURE_ASSOC ||
+           val.scact_assoc_id == SCTP_ALL_ASSOC) {
+               ret = sctp_auth_set_active_key(ep, asoc, val.scact_keynumber);
+               if (ret)
+                       return ret;
+       }
+
+       if (val.scact_assoc_id == SCTP_CURRENT_ASSOC ||
+           val.scact_assoc_id == SCTP_ALL_ASSOC) {
+               list_for_each_entry(asoc, &ep->asocs, asocs) {
+                       int res = sctp_auth_set_active_key(ep, asoc,
+                                                          val.scact_keynumber);
+
+                       if (res && !ret)
+                               ret = res;
+               }
+       }
+
+       return ret;
 }
 
 /*