]> git.karo-electronics.de Git - karo-tx-linux.git/commitdiff
sctp: add sockopt SCTP_ENABLE_STREAM_RESET
authorXin Long <lucien.xin@gmail.com>
Tue, 17 Jan 2017 16:44:46 +0000 (00:44 +0800)
committerDavid S. Miller <davem@davemloft.net>
Wed, 18 Jan 2017 19:55:10 +0000 (14:55 -0500)
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>
include/net/sctp/structs.h
include/uapi/linux/sctp.h
net/sctp/associola.c
net/sctp/socket.c

index ee037ef15d651d462efdf0d31b9000666f4f7fea..d99b76e33b2e09856b5a48aab14c25d3baa61512 100644 (file)
@@ -1257,6 +1257,8 @@ struct sctp_endpoint {
        __u8  auth_enable:1,
              prsctp_enable:1,
              reconf_enable:1;
+
+       __u8  strreset_enable;
 };
 
 /* Recover the outter endpoint structure. */
@@ -1872,6 +1874,8 @@ struct sctp_association {
             prsctp_enable:1,
             reconf_enable:1;
 
+       __u8 strreset_enable;
+
        __u32 strreset_outseq; /* Update after receiving response */
        __u32 strreset_inseq; /* Update after receiving request */
 
index a406adcc0793e0f3a09706cb693867b49d0ef914..867be0f32fd73614b777d693a2555baf7375bc81 100644 (file)
@@ -115,6 +115,7 @@ typedef __s32 sctp_assoc_t;
 #define SCTP_PR_SUPPORTED      113
 #define SCTP_DEFAULT_PRINFO    114
 #define SCTP_PR_ASSOC_STATUS   115
+#define SCTP_ENABLE_STREAM_RESET       118
 
 /* PR-SCTP policies */
 #define SCTP_PR_SCTP_NONE      0x0000
@@ -138,6 +139,12 @@ typedef __s32 sctp_assoc_t;
 #define SCTP_PR_RTX_ENABLED(x) (SCTP_PR_POLICY(x) == SCTP_PR_SCTP_RTX)
 #define SCTP_PR_PRIO_ENABLED(x)        (SCTP_PR_POLICY(x) == SCTP_PR_SCTP_PRIO)
 
+/* For enable stream reset */
+#define SCTP_ENABLE_RESET_STREAM_REQ   0x01
+#define SCTP_ENABLE_RESET_ASSOC_REQ    0x02
+#define SCTP_ENABLE_CHANGE_ASSOC_REQ   0x04
+#define SCTP_ENABLE_STRRESET_MASK      0x07
+
 /* These are bit fields for msghdr->msg_flags.  See section 5.1.  */
 /* On user space Linux, these live in <bits/socket.h> as an enum.  */
 enum sctp_msg_flags {
index 68b99adc21a31d37f1188aafc61192b132f031db..e50dc6d7543fd6acfa7442f3a9ee575203c7718d 100644 (file)
@@ -271,6 +271,7 @@ static struct sctp_association *sctp_association_init(struct sctp_association *a
        asoc->active_key_id = ep->active_key_id;
        asoc->prsctp_enable = ep->prsctp_enable;
        asoc->reconf_enable = ep->reconf_enable;
+       asoc->strreset_enable = ep->strreset_enable;
 
        /* Save the hmacs and chunks list into this association */
        if (ep->auth_hmacs_list)
index 635e0341269330187c78ba93a35689f5c5d6be02..0a9bc984b6c84fb9e16c28752dc11ffe813d8bfe 100644 (file)
@@ -3750,6 +3750,42 @@ out:
        return retval;
 }
 
+static int sctp_setsockopt_enable_strreset(struct sock *sk,
+                                          char __user *optval,
+                                          unsigned int optlen)
+{
+       struct sctp_assoc_value params;
+       struct sctp_association *asoc;
+       int retval = -EINVAL;
+
+       if (optlen != sizeof(params))
+               goto out;
+
+       if (copy_from_user(&params, optval, optlen)) {
+               retval = -EFAULT;
+               goto out;
+       }
+
+       if (params.assoc_value & (~SCTP_ENABLE_STRRESET_MASK))
+               goto out;
+
+       asoc = sctp_id2assoc(sk, params.assoc_id);
+       if (asoc) {
+               asoc->strreset_enable = params.assoc_value;
+       } else if (!params.assoc_id) {
+               struct sctp_sock *sp = sctp_sk(sk);
+
+               sp->ep->strreset_enable = params.assoc_value;
+       } else {
+               goto out;
+       }
+
+       retval = 0;
+
+out:
+       return retval;
+}
+
 /* API 6.2 setsockopt(), getsockopt()
  *
  * Applications use setsockopt() and getsockopt() to set or retrieve
@@ -3916,6 +3952,9 @@ static int sctp_setsockopt(struct sock *sk, int level, int optname,
        case SCTP_DEFAULT_PRINFO:
                retval = sctp_setsockopt_default_prinfo(sk, optval, optlen);
                break;
+       case SCTP_ENABLE_STREAM_RESET:
+               retval = sctp_setsockopt_enable_strreset(sk, optval, optlen);
+               break;
        default:
                retval = -ENOPROTOOPT;
                break;
@@ -6400,6 +6439,47 @@ out:
        return retval;
 }
 
+static int sctp_getsockopt_enable_strreset(struct sock *sk, int len,
+                                          char __user *optval,
+                                          int __user *optlen)
+{
+       struct sctp_assoc_value params;
+       struct sctp_association *asoc;
+       int retval = -EFAULT;
+
+       if (len < sizeof(params)) {
+               retval = -EINVAL;
+               goto out;
+       }
+
+       len = sizeof(params);
+       if (copy_from_user(&params, optval, len))
+               goto out;
+
+       asoc = sctp_id2assoc(sk, params.assoc_id);
+       if (asoc) {
+               params.assoc_value = asoc->strreset_enable;
+       } else if (!params.assoc_id) {
+               struct sctp_sock *sp = sctp_sk(sk);
+
+               params.assoc_value = sp->ep->strreset_enable;
+       } else {
+               retval = -EINVAL;
+               goto out;
+       }
+
+       if (put_user(len, optlen))
+               goto out;
+
+       if (copy_to_user(optval, &params, len))
+               goto out;
+
+       retval = 0;
+
+out:
+       return retval;
+}
+
 static int sctp_getsockopt(struct sock *sk, int level, int optname,
                           char __user *optval, int __user *optlen)
 {
@@ -6567,6 +6647,10 @@ static int sctp_getsockopt(struct sock *sk, int level, int optname,
                retval = sctp_getsockopt_pr_assocstatus(sk, len, optval,
                                                        optlen);
                break;
+       case SCTP_ENABLE_STREAM_RESET:
+               retval = sctp_getsockopt_enable_strreset(sk, len, optval,
+                                                        optlen);
+               break;
        default:
                retval = -ENOPROTOOPT;
                break;