]> asedeno.scripts.mit.edu Git - linux.git/blobdiff - net/sctp/socket.c
sctp: use SCTP_FUTURE_ASSOC for SCTP_MAXSEG sockopt
[linux.git] / net / sctp / socket.c
index f93c3cf9e5674b5d446e90ccd43611eca5fab508..f38c9127e8588e333e4d42b89873a64f871dc613 100644 (file)
@@ -248,7 +248,7 @@ struct sctp_association *sctp_id2assoc(struct sock *sk, sctp_assoc_t id)
        }
 
        /* Otherwise this is a UDP-style socket. */
-       if (!id || (id == (sctp_assoc_t)-1))
+       if (id <= SCTP_ALL_ASSOC)
                return NULL;
 
        spin_lock_bh(&sctp_assocs_id_lock);
@@ -2750,12 +2750,13 @@ static int sctp_setsockopt_peer_addr_params(struct sock *sk,
                        return -EINVAL;
        }
 
-       /* Get association, if assoc_id != 0 and the socket is a one
-        * to many style socket, and an association was not found, then
-        * the id was invalid.
+       /* Get association, if assoc_id != SCTP_FUTURE_ASSOC and the
+        * socket is a one to many style socket, and an association
+        * was not found, then the id was invalid.
         */
        asoc = sctp_id2assoc(sk, params.spp_assoc_id);
-       if (!asoc && params.spp_assoc_id && sctp_style(sk, UDP))
+       if (!asoc && params.spp_assoc_id != SCTP_FUTURE_ASSOC &&
+           sctp_style(sk, UDP))
                return -EINVAL;
 
        /* Heartbeat demand can only be sent on a transport or
@@ -3144,7 +3145,8 @@ static int sctp_setsockopt_rtoinfo(struct sock *sk, char __user *optval, unsigne
        asoc = sctp_id2assoc(sk, rtoinfo.srto_assoc_id);
 
        /* Set the values to the specific association */
-       if (!asoc && rtoinfo.srto_assoc_id && sctp_style(sk, UDP))
+       if (!asoc && rtoinfo.srto_assoc_id != SCTP_FUTURE_ASSOC &&
+           sctp_style(sk, UDP))
                return -EINVAL;
 
        rto_max = rtoinfo.srto_max;
@@ -3206,7 +3208,8 @@ static int sctp_setsockopt_associnfo(struct sock *sk, char __user *optval, unsig
 
        asoc = sctp_id2assoc(sk, assocparams.sasoc_assoc_id);
 
-       if (!asoc && assocparams.sasoc_assoc_id && sctp_style(sk, UDP))
+       if (!asoc && assocparams.sasoc_assoc_id != SCTP_FUTURE_ASSOC &&
+           sctp_style(sk, UDP))
                return -EINVAL;
 
        /* Set the values to the specific association */
@@ -3319,7 +3322,7 @@ static int sctp_setsockopt_maxseg(struct sock *sk, char __user *optval, unsigned
                                    current->comm, task_pid_nr(current));
                if (copy_from_user(&val, optval, optlen))
                        return -EFAULT;
-               params.assoc_id = 0;
+               params.assoc_id = SCTP_FUTURE_ASSOC;
        } else if (optlen == sizeof(struct sctp_assoc_value)) {
                if (copy_from_user(&params, optval, optlen))
                        return -EFAULT;
@@ -3329,6 +3332,9 @@ static int sctp_setsockopt_maxseg(struct sock *sk, char __user *optval, unsigned
        }
 
        asoc = sctp_id2assoc(sk, params.assoc_id);
+       if (!asoc && params.assoc_id != SCTP_FUTURE_ASSOC &&
+           sctp_style(sk, UDP))
+               return -EINVAL;
 
        if (val) {
                int min_len, max_len;
@@ -3346,8 +3352,6 @@ static int sctp_setsockopt_maxseg(struct sock *sk, char __user *optval, unsigned
                asoc->user_frag = val;
                sctp_assoc_update_frag_point(asoc);
        } else {
-               if (params.assoc_id && sctp_style(sk, UDP))
-                       return -EINVAL;
                sp->user_frag = val;
        }
 
@@ -5676,12 +5680,13 @@ static int sctp_getsockopt_peer_addr_params(struct sock *sk, int len,
                }
        }
 
-       /* Get association, if assoc_id != 0 and the socket is a one
-        * to many style socket, and an association was not found, then
-        * the id was invalid.
+       /* Get association, if assoc_id != SCTP_FUTURE_ASSOC and the
+        * socket is a one to many style socket, and an association
+        * was not found, then the id was invalid.
         */
        asoc = sctp_id2assoc(sk, params.spp_assoc_id);
-       if (!asoc && params.spp_assoc_id && sctp_style(sk, UDP)) {
+       if (!asoc && params.spp_assoc_id != SCTP_FUTURE_ASSOC &&
+           sctp_style(sk, UDP)) {
                pr_debug("%s: failed no association\n", __func__);
                return -EINVAL;
        }
@@ -6296,7 +6301,8 @@ static int sctp_getsockopt_rtoinfo(struct sock *sk, int len,
 
        asoc = sctp_id2assoc(sk, rtoinfo.srto_assoc_id);
 
-       if (!asoc && rtoinfo.srto_assoc_id && sctp_style(sk, UDP))
+       if (!asoc && rtoinfo.srto_assoc_id != SCTP_FUTURE_ASSOC &&
+           sctp_style(sk, UDP))
                return -EINVAL;
 
        /* Values corresponding to the specific association. */
@@ -6353,7 +6359,8 @@ static int sctp_getsockopt_associnfo(struct sock *sk, int len,
 
        asoc = sctp_id2assoc(sk, assocparams.sasoc_assoc_id);
 
-       if (!asoc && assocparams.sasoc_assoc_id && sctp_style(sk, UDP))
+       if (!asoc && assocparams.sasoc_assoc_id != SCTP_FUTURE_ASSOC &&
+           sctp_style(sk, UDP))
                return -EINVAL;
 
        /* Values correspoinding to the specific association */
@@ -6497,7 +6504,7 @@ static int sctp_getsockopt_maxseg(struct sock *sk, int len,
                                    "Use of int in maxseg socket option.\n"
                                    "Use struct sctp_assoc_value instead\n",
                                    current->comm, task_pid_nr(current));
-               params.assoc_id = 0;
+               params.assoc_id = SCTP_FUTURE_ASSOC;
        } else if (len >= sizeof(struct sctp_assoc_value)) {
                len = sizeof(struct sctp_assoc_value);
                if (copy_from_user(&params, optval, len))
@@ -6506,7 +6513,8 @@ static int sctp_getsockopt_maxseg(struct sock *sk, int len,
                return -EINVAL;
 
        asoc = sctp_id2assoc(sk, params.assoc_id);
-       if (!asoc && params.assoc_id && sctp_style(sk, UDP))
+       if (!asoc && params.assoc_id != SCTP_FUTURE_ASSOC &&
+           sctp_style(sk, UDP))
                return -EINVAL;
 
        if (asoc)