]> git.karo-electronics.de Git - karo-tx-linux.git/blobdiff - net/sctp/socket.c
Merge master.kernel.org:/home/rmk/linux-2.6-arm
[karo-tx-linux.git] / net / sctp / socket.c
index 0738843876a10ab4bf7fe675f5477da0aa44996f..ff0a8f88de04bd275f3b16b921ed88d846407ca4 100644 (file)
@@ -2404,9 +2404,9 @@ static int sctp_setsockopt_delayed_ack(struct sock *sk,
                if (params.sack_delay == 0 && params.sack_freq == 0)
                        return 0;
        } else if (optlen == sizeof(struct sctp_assoc_value)) {
-               printk(KERN_WARNING "SCTP: Use of struct sctp_sack_info "
+               printk(KERN_WARNING "SCTP: Use of struct sctp_assoc_value "
                       "in delayed_ack socket option deprecated\n");
-               printk(KERN_WARNING "SCTP: struct sctp_sack_info instead\n");
+               printk(KERN_WARNING "SCTP: Use struct sctp_sack_info instead\n");
                if (copy_from_user(&params, optval, optlen))
                        return -EFAULT;
 
@@ -2717,7 +2717,7 @@ static int sctp_setsockopt_associnfo(struct sock *sk, char __user *optval, int o
                                paths++;
                        }
 
-                       /* Only validate asocmaxrxt if we have more then
+                       /* Only validate asocmaxrxt if we have more than
                         * one path/transport.  We do this because path
                         * retransmissions are only counted when we have more
                         * then one path.
@@ -3010,14 +3010,21 @@ static int sctp_setsockopt_fragment_interleave(struct sock *sk,
 }
 
 /*
- * 7.1.25.  Set or Get the sctp partial delivery point
+ * 8.1.21.  Set or Get the SCTP Partial Delivery Point
  *       (SCTP_PARTIAL_DELIVERY_POINT)
+ *
  * This option will set or get the SCTP partial delivery point.  This
  * point is the size of a message where the partial delivery API will be
  * invoked to help free up rwnd space for the peer.  Setting this to a
- * lower value will cause partial delivery's to happen more often.  The
+ * lower value will cause partial deliveries to happen more often.  The
  * calls argument is an integer that sets or gets the partial delivery
- * point.
+ * point.  Note also that the call will fail if the user attempts to set
+ * this value larger than the socket receive buffer size.
+ *
+ * Note that any single message having a length smaller than or equal to
+ * the SCTP partial delivery point will be delivered in one single read
+ * call as long as the user provided buffer is large enough to hold the
+ * message.
  */
 static int sctp_setsockopt_partial_delivery_point(struct sock *sk,
                                                  char __user *optval,
@@ -3030,6 +3037,12 @@ static int sctp_setsockopt_partial_delivery_point(struct sock *sk,
        if (get_user(val, (int __user *)optval))
                return -EFAULT;
 
+       /* Note: We double the receive buffer from what the user sets
+        * it to be, also initial rwnd is based on rcvbuf/2.
+        */
+       if (val > (sk->sk_rcvbuf >> 1))
+               return -EINVAL;
+
        sctp_sk(sk)->pd_point = val;
 
        return 0; /* is this the right error code? */
@@ -4221,9 +4234,9 @@ static int sctp_getsockopt_delayed_ack(struct sock *sk, int len,
                if (copy_from_user(&params, optval, len))
                        return -EFAULT;
        } else if (len == sizeof(struct sctp_assoc_value)) {
-               printk(KERN_WARNING "SCTP: Use of struct sctp_sack_info "
+               printk(KERN_WARNING "SCTP: Use of struct sctp_assoc_value "
                       "in delayed_ack socket option deprecated\n");
-               printk(KERN_WARNING "SCTP: struct sctp_sack_info instead\n");
+               printk(KERN_WARNING "SCTP: Use struct sctp_sack_info instead\n");
                if (copy_from_user(&params, optval, len))
                        return -EFAULT;
        } else
@@ -5460,6 +5473,38 @@ num:
        return 0;
 }
 
+/*
+ * 8.2.5.  Get the Current Number of Associations (SCTP_GET_ASSOC_NUMBER)
+ * This option gets the current number of associations that are attached
+ * to a one-to-many style socket.  The option value is an uint32_t.
+ */
+static int sctp_getsockopt_assoc_number(struct sock *sk, int len,
+                                   char __user *optval, int __user *optlen)
+{
+       struct sctp_sock *sp = sctp_sk(sk);
+       struct sctp_association *asoc;
+       u32 val = 0;
+
+       if (sctp_style(sk, TCP))
+               return -EOPNOTSUPP;
+
+       if (len < sizeof(u32))
+               return -EINVAL;
+
+       len = sizeof(u32);
+
+       list_for_each_entry(asoc, &(sp->ep->asocs), asocs) {
+               val++;
+       }
+
+       if (put_user(len, optlen))
+               return -EFAULT;
+       if (copy_to_user(optval, &val, len))
+               return -EFAULT;
+
+       return 0;
+}
+
 SCTP_STATIC int sctp_getsockopt(struct sock *sk, int level, int optname,
                                char __user *optval, int __user *optlen)
 {
@@ -5602,6 +5647,9 @@ SCTP_STATIC int sctp_getsockopt(struct sock *sk, int level, int optname,
                retval = sctp_getsockopt_local_auth_chunks(sk, len, optval,
                                                        optlen);
                break;
+       case SCTP_GET_ASSOC_NUMBER:
+               retval = sctp_getsockopt_assoc_number(sk, len, optval, optlen);
+               break;
        default:
                retval = -ENOPROTOOPT;
                break;