* 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.
This commit is contained in:
parent
88381ca3e3
commit
48f65f00fa
Notes:
svn2git
2020-12-20 02:59:44 +00:00
svn path=/head/; revision=221512
@ -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:
|
||||
*
|
||||
* 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.
|
||||
* 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 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 <sys/cdefs.h>
|
||||
__FBSDID("$FreeBSD$");
|
||||
#include <stdio.h>
|
||||
@ -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, int opt, void *arg, socklen_t * size)
|
||||
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_t len,
|
||||
#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_t len,
|
||||
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_t msg_len,
|
||||
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_id)
|
||||
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_id)
|
||||
#undef SCTP_CONTROL_VEC_SIZE_SND
|
||||
#undef SCTP_CONTROL_VEC_SIZE_RCV
|
||||
#undef SCTP_STACK_BUF_SIZE
|
||||
#undef SCTP_SMALL_IOVEC_SIZE
|
||||
|
Loading…
Reference in New Issue
Block a user