Merge git://git.kernel.org/pub/scm/linux/kernel/git/davem/net
[linux-block.git] / net / sctp / socket.c
index 17841ab30798ecb2d7269296dcda3c62d434d622..c75acdf71a6f81590185d0b5cf5735f6b500de81 100644 (file)
@@ -79,6 +79,7 @@
 #include <net/sock.h>
 #include <net/sctp/sctp.h>
 #include <net/sctp/sm.h>
+#include <net/sctp/stream_sched.h>
 
 /* Forward declarations for internal helper functions. */
 static int sctp_writeable(struct sock *sk);
@@ -1927,6 +1928,13 @@ static int sctp_sendmsg(struct sock *sk, struct msghdr *msg, size_t msg_len)
                goto out_free;
        }
 
+       /* Allocate sctp_stream_out_ext if not already done */
+       if (unlikely(!asoc->stream.out[sinfo->sinfo_stream].ext)) {
+               err = sctp_stream_init_ext(&asoc->stream, sinfo->sinfo_stream);
+               if (err)
+                       goto out_free;
+       }
+
        if (sctp_wspace(asoc) < msg_len)
                sctp_prsctp_prune(asoc, sinfo, msg_len - sctp_wspace(asoc));
 
@@ -3907,6 +3915,64 @@ out:
        return retval;
 }
 
+static int sctp_setsockopt_scheduler(struct sock *sk,
+                                    char __user *optval,
+                                    unsigned int optlen)
+{
+       struct sctp_association *asoc;
+       struct sctp_assoc_value params;
+       int retval = -EINVAL;
+
+       if (optlen < sizeof(params))
+               goto out;
+
+       optlen = sizeof(params);
+       if (copy_from_user(&params, optval, optlen)) {
+               retval = -EFAULT;
+               goto out;
+       }
+
+       if (params.assoc_value > SCTP_SS_MAX)
+               goto out;
+
+       asoc = sctp_id2assoc(sk, params.assoc_id);
+       if (!asoc)
+               goto out;
+
+       retval = sctp_sched_set_sched(asoc, params.assoc_value);
+
+out:
+       return retval;
+}
+
+static int sctp_setsockopt_scheduler_value(struct sock *sk,
+                                          char __user *optval,
+                                          unsigned int optlen)
+{
+       struct sctp_association *asoc;
+       struct sctp_stream_value params;
+       int retval = -EINVAL;
+
+       if (optlen < sizeof(params))
+               goto out;
+
+       optlen = sizeof(params);
+       if (copy_from_user(&params, optval, optlen)) {
+               retval = -EFAULT;
+               goto out;
+       }
+
+       asoc = sctp_id2assoc(sk, params.assoc_id);
+       if (!asoc)
+               goto out;
+
+       retval = sctp_sched_set_value(asoc, params.stream_id,
+                                     params.stream_value, GFP_KERNEL);
+
+out:
+       return retval;
+}
+
 /* API 6.2 setsockopt(), getsockopt()
  *
  * Applications use setsockopt() and getsockopt() to set or retrieve
@@ -4088,6 +4154,12 @@ static int sctp_setsockopt(struct sock *sk, int level, int optname,
        case SCTP_ADD_STREAMS:
                retval = sctp_setsockopt_add_streams(sk, optval, optlen);
                break;
+       case SCTP_STREAM_SCHEDULER:
+               retval = sctp_setsockopt_scheduler(sk, optval, optlen);
+               break;
+       case SCTP_STREAM_SCHEDULER_VALUE:
+               retval = sctp_setsockopt_scheduler_value(sk, optval, optlen);
+               break;
        default:
                retval = -ENOPROTOOPT;
                break;
@@ -6649,7 +6721,7 @@ static int sctp_getsockopt_pr_streamstatus(struct sock *sk, int len,
                                           char __user *optval,
                                           int __user *optlen)
 {
-       struct sctp_stream_out *streamout;
+       struct sctp_stream_out_ext *streamoute;
        struct sctp_association *asoc;
        struct sctp_prstatus params;
        int retval = -EINVAL;
@@ -6672,21 +6744,29 @@ static int sctp_getsockopt_pr_streamstatus(struct sock *sk, int len,
        if (!asoc || params.sprstat_sid >= asoc->stream.outcnt)
                goto out;
 
-       streamout = &asoc->stream.out[params.sprstat_sid];
+       streamoute = asoc->stream.out[params.sprstat_sid].ext;
+       if (!streamoute) {
+               /* Not allocated yet, means all stats are 0 */
+               params.sprstat_abandoned_unsent = 0;
+               params.sprstat_abandoned_sent = 0;
+               retval = 0;
+               goto out;
+       }
+
        if (policy == SCTP_PR_SCTP_NONE) {
                params.sprstat_abandoned_unsent = 0;
                params.sprstat_abandoned_sent = 0;
                for (policy = 0; policy <= SCTP_PR_INDEX(MAX); policy++) {
                        params.sprstat_abandoned_unsent +=
-                               streamout->abandoned_unsent[policy];
+                               streamoute->abandoned_unsent[policy];
                        params.sprstat_abandoned_sent +=
-                               streamout->abandoned_sent[policy];
+                               streamoute->abandoned_sent[policy];
                }
        } else {
                params.sprstat_abandoned_unsent =
-                       streamout->abandoned_unsent[__SCTP_PR_INDEX(policy)];
+                       streamoute->abandoned_unsent[__SCTP_PR_INDEX(policy)];
                params.sprstat_abandoned_sent =
-                       streamout->abandoned_sent[__SCTP_PR_INDEX(policy)];
+                       streamoute->abandoned_sent[__SCTP_PR_INDEX(policy)];
        }
 
        if (put_user(len, optlen) || copy_to_user(optval, &params, len)) {
@@ -6782,6 +6862,85 @@ out:
        return retval;
 }
 
+static int sctp_getsockopt_scheduler(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) {
+               retval = -EINVAL;
+               goto out;
+       }
+
+       params.assoc_value = sctp_sched_get_sched(asoc);
+
+       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_scheduler_value(struct sock *sk, int len,
+                                          char __user *optval,
+                                          int __user *optlen)
+{
+       struct sctp_stream_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) {
+               retval = -EINVAL;
+               goto out;
+       }
+
+       retval = sctp_sched_get_value(asoc, params.stream_id,
+                                     &params.stream_value);
+       if (retval)
+               goto out;
+
+       if (put_user(len, optlen)) {
+               retval = -EFAULT;
+               goto out;
+       }
+
+       if (copy_to_user(optval, &params, len)) {
+               retval = -EFAULT;
+               goto out;
+       }
+
+out:
+       return retval;
+}
+
 static int sctp_getsockopt(struct sock *sk, int level, int optname,
                           char __user *optval, int __user *optlen)
 {
@@ -6964,6 +7123,14 @@ static int sctp_getsockopt(struct sock *sk, int level, int optname,
                retval = sctp_getsockopt_enable_strreset(sk, len, optval,
                                                         optlen);
                break;
+       case SCTP_STREAM_SCHEDULER:
+               retval = sctp_getsockopt_scheduler(sk, len, optval,
+                                                  optlen);
+               break;
+       case SCTP_STREAM_SCHEDULER_VALUE:
+               retval = sctp_getsockopt_scheduler_value(sk, len, optval,
+                                                        optlen);
+               break;
        default:
                retval = -ENOPROTOOPT;
                break;