From owner-svn-src-all@FreeBSD.ORG Fri Feb 10 20:45:17 2012 Return-Path: Delivered-To: svn-src-all@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id E0F3C1065670; Fri, 10 Feb 2012 20:45:17 +0000 (UTC) (envelope-from tuexen@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:4f8:fff6::2c]) by mx1.freebsd.org (Postfix) with ESMTP id CA1C28FC12; Fri, 10 Feb 2012 20:45:17 +0000 (UTC) Received: from svn.freebsd.org (localhost [127.0.0.1]) by svn.freebsd.org (8.14.4/8.14.4) with ESMTP id q1AKjHLS093553; Fri, 10 Feb 2012 20:45:17 GMT (envelope-from tuexen@svn.freebsd.org) Received: (from tuexen@localhost) by svn.freebsd.org (8.14.4/8.14.4/Submit) id q1AKjHKv093550; Fri, 10 Feb 2012 20:45:17 GMT (envelope-from tuexen@svn.freebsd.org) Message-Id: <201202102045.q1AKjHKv093550@svn.freebsd.org> From: Michael Tuexen Date: Fri, 10 Feb 2012 20:45:17 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-8@freebsd.org X-SVN-Group: stable-8 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Cc: Subject: svn commit: r231432 - in stable/8/lib: libc/net libusb X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "SVN commit messages for the entire src tree \(except for " user" and " projects" \)" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 10 Feb 2012 20:45:18 -0000 Author: tuexen Date: Fri Feb 10 20:45:17 2012 New Revision: 231432 URL: http://svn.freebsd.org/changeset/base/231432 Log: MFC r221512: * Update copyright notice. * Cleanup usage of iov's. * Add support for SCTP_TIMEOUTS socketoption. * Fix a bug in sctp_recvmsg(): return the msg_flags in case of an error. * Fix a bug in the error handling of sctp_peeloff(): return the -1. Modified: stable/8/lib/libc/net/sctp_sys_calls.c Directory Properties: stable/8/lib/ (props changed) stable/8/lib/bind/ (props changed) stable/8/lib/csu/ (props changed) stable/8/lib/libarchive/ (props changed) stable/8/lib/libbluetooth/ (props changed) stable/8/lib/libc/ (props changed) stable/8/lib/libc/stdtime/ (props changed) stable/8/lib/libc/sys/ (props changed) stable/8/lib/libc_r/ (props changed) stable/8/lib/libcam/ (props changed) stable/8/lib/libcompat/ (props changed) stable/8/lib/libdevinfo/ (props changed) stable/8/lib/libdevstat/ (props changed) stable/8/lib/libdisk/ (props changed) stable/8/lib/libedit/ (props changed) stable/8/lib/libelf/ (props changed) stable/8/lib/libexpat/ (props changed) stable/8/lib/libgeom/ (props changed) stable/8/lib/libgpib/ (props changed) stable/8/lib/libgssapi/ (props changed) stable/8/lib/libipsec/ (props changed) stable/8/lib/libjail/ (props changed) stable/8/lib/libkse/ (props changed) stable/8/lib/libkvm/ (props changed) stable/8/lib/liblzma/ (props changed) stable/8/lib/libmagic/ (props changed) stable/8/lib/libmemstat/ (props changed) stable/8/lib/libpam/ (props changed) stable/8/lib/libpmc/ (props changed) stable/8/lib/libproc/ (props changed) stable/8/lib/libradius/ (props changed) stable/8/lib/librpcsec_gss/ (props changed) stable/8/lib/librtld_db/ (props changed) stable/8/lib/libsm/ (props changed) stable/8/lib/libstand/ (props changed) stable/8/lib/libtacplus/ (props changed) stable/8/lib/libthr/ (props changed) stable/8/lib/libthread_db/ (props changed) stable/8/lib/libufs/ (props changed) stable/8/lib/libugidfw/ (props changed) stable/8/lib/libusb/ (props changed) stable/8/lib/libusb/usb.h (props changed) stable/8/lib/libusbhid/ (props changed) stable/8/lib/libutil/ (props changed) stable/8/lib/libz/ (props changed) stable/8/lib/libz/contrib/ (props changed) stable/8/lib/msun/ (props changed) Modified: stable/8/lib/libc/net/sctp_sys_calls.c ============================================================================== --- stable/8/lib/libc/net/sctp_sys_calls.c Fri Feb 10 20:38:44 2012 (r231431) +++ stable/8/lib/libc/net/sctp_sys_calls.c Fri Feb 10 20:45:17 2012 (r231432) @@ -1,33 +1,35 @@ -/* $KAME: sctp_sys_calls.c,v 1.9 2004/08/17 06:08:53 itojun Exp $ */ - -/* - * Copyright (C) 2002-2007 Cisco Systems Inc, - * All rights reserved. +/*- + * Copyright (c) 2001-2007, by Cisco Systems, Inc. All rights reserved. + * Copyright (c) 2008-2011, by Randall Stewart. All rights reserved. + * Copyright (c) 2008-2011, by Michael Tuexen. All rights reserved. * * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. Neither the name of the project nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. + * modification, are permitted provided that the following conditions are met: + * + * a) Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * + * b) Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the distribution. + * + * c) Neither the name of Cisco Systems, Inc. nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. * - * THIS SOFTWARE IS PROVIDED BY THE PROJECT AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE PROJECT OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF + * THE POSSIBILITY OF SUCH DAMAGE. */ + #include __FBSDID("$FreeBSD$"); #include @@ -58,7 +60,6 @@ __FBSDID("$FreeBSD$"); #define SCTP_CONTROL_VEC_SIZE_SND 8192 #define SCTP_CONTROL_VEC_SIZE_RCV 16384 #define SCTP_STACK_BUF_SIZE 2048 -#define SCTP_SMALL_IOVEC_SIZE 2 #ifdef SCTP_DEBUG_PRINT_ADDRESS @@ -398,6 +399,9 @@ sctp_opt_info(int sd, sctp_assoc_t id, i case SCTP_LOCAL_AUTH_CHUNKS: ((struct sctp_authchunks *)arg)->gauth_assoc_id = id; break; + case SCTP_TIMEOUTS: + ((struct sctp_timeouts *)arg)->stimo_assoc_id = id; + break; default: break; } @@ -551,11 +555,10 @@ sctp_sendmsg(int s, return (syscall(SYS_sctp_generic_sendmsg, s, data, len, to, tolen, &sinfo, 0)); #else - ssize_t sz; struct msghdr msg; struct sctp_sndrcvinfo *s_info; - struct iovec iov[SCTP_SMALL_IOVEC_SIZE]; + struct iovec iov; char controlVector[SCTP_CONTROL_VEC_SIZE_RCV]; struct cmsghdr *cmsg; struct sockaddr *who = NULL; @@ -564,20 +567,8 @@ sctp_sendmsg(int s, struct sockaddr_in6 in6; } addr; -/* - fprintf(io, "sctp_sendmsg(sd:%d, data:%x, len:%d, to:%x, tolen:%d, ppid:%x, flags:%x str:%d ttl:%d ctx:%x\n", - s, - (u_int)data, - (int)len, - (u_int)to, - (int)tolen, - ppid, flags, - (int)stream_no, - (int)timetolive, - (u_int)context); - fflush(io); -*/ - if ((tolen > 0) && ((to == NULL) || (tolen < sizeof(struct sockaddr)))) { + if ((tolen > 0) && + ((to == NULL) || (tolen < sizeof(struct sockaddr)))) { errno = EINVAL; return -1; } @@ -587,7 +578,8 @@ sctp_sendmsg(int s, errno = EINVAL; return -1; } - if ((to->sa_len > 0) && (to->sa_len != sizeof(struct sockaddr_in))) { + if ((to->sa_len > 0) && + (to->sa_len != sizeof(struct sockaddr_in))) { errno = EINVAL; return -1; } @@ -598,7 +590,8 @@ sctp_sendmsg(int s, errno = EINVAL; return -1; } - if ((to->sa_len > 0) && (to->sa_len != sizeof(struct sockaddr_in6))) { + if ((to->sa_len > 0) && + (to->sa_len != sizeof(struct sockaddr_in6))) { errno = EINVAL; return -1; } @@ -610,10 +603,8 @@ sctp_sendmsg(int s, } who = (struct sockaddr *)&addr; } - iov[0].iov_base = (char *)data; - iov[0].iov_len = len; - iov[1].iov_base = NULL; - iov[1].iov_len = 0; + iov.iov_base = (char *)data; + iov.iov_len = len; if (who) { msg.msg_name = (caddr_t)who; @@ -622,7 +613,7 @@ sctp_sendmsg(int s, msg.msg_name = (caddr_t)NULL; msg.msg_namelen = 0; } - msg.msg_iov = iov; + msg.msg_iov = &iov; msg.msg_iovlen = 1; msg.msg_control = (caddr_t)controlVector; @@ -681,7 +672,7 @@ sctp_send(int sd, const void *data, size #else ssize_t sz; struct msghdr msg; - struct iovec iov[SCTP_SMALL_IOVEC_SIZE]; + struct iovec iov; struct sctp_sndrcvinfo *s_info; char controlVector[SCTP_CONTROL_VEC_SIZE_SND]; struct cmsghdr *cmsg; @@ -690,14 +681,12 @@ sctp_send(int sd, const void *data, size errno = EINVAL; return (-1); } - iov[0].iov_base = (char *)data; - iov[0].iov_len = len; - iov[1].iov_base = NULL; - iov[1].iov_len = 0; + iov.iov_base = (char *)data; + iov.iov_len = len; msg.msg_name = 0; msg.msg_namelen = 0; - msg.msg_iov = iov; + msg.msg_iov = &iov; msg.msg_iovlen = 1; msg.msg_control = (caddr_t)controlVector; @@ -736,7 +725,7 @@ sctp_sendx(int sd, const void *msg, size return (-1); } #ifdef SYS_sctp_generic_sendmsg - if (addrcnt < SCTP_SMALL_IOVEC_SIZE) { + if (addrcnt == 1) { socklen_t l; /* @@ -846,18 +835,18 @@ sctp_recvmsg(int s, int *msg_flags) { #ifdef SYS_sctp_generic_recvmsg - struct iovec iov[SCTP_SMALL_IOVEC_SIZE]; + struct iovec iov; - iov[0].iov_base = dbuf; - iov[0].iov_len = len; + iov.iov_base = dbuf; + iov.iov_len = len; return (syscall(SYS_sctp_generic_recvmsg, s, - iov, 1, from, fromlen, sinfo, msg_flags)); + &iov, 1, from, fromlen, sinfo, msg_flags)); #else struct sctp_sndrcvinfo *s_info; ssize_t sz; int sinfo_found = 0; struct msghdr msg; - struct iovec iov[SCTP_SMALL_IOVEC_SIZE]; + struct iovec iov; char controlVector[SCTP_CONTROL_VEC_SIZE_RCV]; struct cmsghdr *cmsg; @@ -866,30 +855,28 @@ sctp_recvmsg(int s, return (-1); } msg.msg_flags = 0; - iov[0].iov_base = dbuf; - iov[0].iov_len = len; - iov[1].iov_base = NULL; - iov[1].iov_len = 0; + iov.iov_base = dbuf; + iov.iov_len = len; msg.msg_name = (caddr_t)from; if (fromlen == NULL) msg.msg_namelen = 0; else msg.msg_namelen = *fromlen; - msg.msg_iov = iov; + msg.msg_iov = &iov; msg.msg_iovlen = 1; msg.msg_control = (caddr_t)controlVector; msg.msg_controllen = sizeof(controlVector); errno = 0; sz = recvmsg(s, &msg, *msg_flags); - if (sz <= 0) + *msg_flags = msg.msg_flags; + if (sz <= 0) { return (sz); - + } s_info = NULL; len = sz; - *msg_flags = msg.msg_flags; - if (sinfo) + if (sinfo) { sinfo->sinfo_assoc_id = 0; - + } if ((msg.msg_controllen) && sinfo) { /* * parse through and see if we find the sctp_sndrcvinfo (if @@ -940,7 +927,7 @@ int sctp_peeloff(int sd, sctp_assoc_t assoc_id) { struct sctp_peeloff_opt peeloff; - int error; + int result; socklen_t optlen; /* set in the socket option params */ @@ -948,10 +935,9 @@ sctp_peeloff(int sd, sctp_assoc_t assoc_ peeloff.s = sd; peeloff.assoc_id = assoc_id; optlen = sizeof(peeloff); - error = getsockopt(sd, IPPROTO_SCTP, SCTP_PEELOFF, (void *)&peeloff, - &optlen); - if (error) { - errno = error; + result = getsockopt(sd, IPPROTO_SCTP, SCTP_PEELOFF, (void *)&peeloff, &optlen); + + if (result < 0) { return (-1); } else { return (peeloff.new_sd); @@ -984,4 +970,3 @@ sctp_peeloff(int sd, sctp_assoc_t assoc_ #undef SCTP_CONTROL_VEC_SIZE_SND #undef SCTP_CONTROL_VEC_SIZE_RCV #undef SCTP_STACK_BUF_SIZE -#undef SCTP_SMALL_IOVEC_SIZE