2011-05-05 19:49:27 +00:00
|
|
|
/*-
|
2017-11-20 19:49:47 +00:00
|
|
|
* SPDX-License-Identifier: BSD-3-Clause
|
|
|
|
*
|
2011-05-05 19:49:27 +00:00
|
|
|
* Copyright (c) 2001-2007, by Cisco Systems, Inc. All rights reserved.
|
2012-05-23 10:35:40 +00:00
|
|
|
* Copyright (c) 2008-2012, by Randall Stewart. All rights reserved.
|
|
|
|
* Copyright (c) 2008-2012, by Michael Tuexen. All rights reserved.
|
2006-12-15 12:01:50 +00:00
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
2011-05-05 19:49:27 +00:00
|
|
|
* 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.
|
2006-12-15 12:01:50 +00:00
|
|
|
*
|
2011-05-05 19:49:27 +00:00
|
|
|
* 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.
|
2006-12-15 12:01:50 +00:00
|
|
|
*/
|
2011-05-05 19:49:27 +00:00
|
|
|
|
2006-12-15 12:01:50 +00:00
|
|
|
#include <sys/cdefs.h>
|
|
|
|
__FBSDID("$FreeBSD$");
|
2012-05-23 10:35:40 +00:00
|
|
|
|
2020-06-20 21:06:02 +00:00
|
|
|
#include <stdbool.h>
|
2020-06-21 23:47:27 +00:00
|
|
|
#include <stddef.h>
|
2006-12-15 12:01:50 +00:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <errno.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
#include <sys/types.h>
|
|
|
|
#include <sys/socket.h>
|
|
|
|
#include <sys/errno.h>
|
|
|
|
#include <sys/syscall.h>
|
|
|
|
#include <sys/uio.h>
|
|
|
|
#include <netinet/in.h>
|
|
|
|
#include <arpa/inet.h>
|
|
|
|
#include <netinet/sctp_uio.h>
|
|
|
|
#include <netinet/sctp.h>
|
|
|
|
|
|
|
|
#ifndef IN6_IS_ADDR_V4MAPPED
|
|
|
|
#define IN6_IS_ADDR_V4MAPPED(a) \
|
2010-07-04 08:09:33 +00:00
|
|
|
((*(const uint32_t *)(const void *)(&(a)->s6_addr[0]) == 0) && \
|
|
|
|
(*(const uint32_t *)(const void *)(&(a)->s6_addr[4]) == 0) && \
|
|
|
|
(*(const uint32_t *)(const void *)(&(a)->s6_addr[8]) == ntohl(0x0000ffff)))
|
2006-12-15 12:01:50 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#define SCTP_CONTROL_VEC_SIZE_RCV 16384
|
2007-02-22 12:42:43 +00:00
|
|
|
|
2006-12-15 12:01:50 +00:00
|
|
|
|
|
|
|
static void
|
|
|
|
in6_sin6_2_sin(struct sockaddr_in *sin, struct sockaddr_in6 *sin6)
|
|
|
|
{
|
|
|
|
bzero(sin, sizeof(*sin));
|
|
|
|
sin->sin_len = sizeof(struct sockaddr_in);
|
|
|
|
sin->sin_family = AF_INET;
|
|
|
|
sin->sin_port = sin6->sin6_port;
|
|
|
|
sin->sin_addr.s_addr = sin6->sin6_addr.__u6_addr.__u6_addr32[3];
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
sctp_getaddrlen(sa_family_t family)
|
|
|
|
{
|
2011-06-15 23:50:27 +00:00
|
|
|
int ret, sd;
|
2006-12-15 12:01:50 +00:00
|
|
|
socklen_t siz;
|
|
|
|
struct sctp_assoc_value av;
|
|
|
|
|
|
|
|
av.assoc_value = family;
|
|
|
|
siz = sizeof(av);
|
|
|
|
#if defined(AF_INET)
|
|
|
|
sd = socket(AF_INET, SOCK_SEQPACKET, IPPROTO_SCTP);
|
|
|
|
#elif defined(AF_INET6)
|
|
|
|
sd = socket(AF_INET6, SOCK_SEQPACKET, IPPROTO_SCTP);
|
2011-06-15 23:50:27 +00:00
|
|
|
#else
|
|
|
|
sd = -1;
|
2006-12-15 12:01:50 +00:00
|
|
|
#endif
|
|
|
|
if (sd == -1) {
|
2007-06-22 13:59:54 +00:00
|
|
|
return (-1);
|
2006-12-15 12:01:50 +00:00
|
|
|
}
|
2011-06-15 23:50:27 +00:00
|
|
|
ret = getsockopt(sd, IPPROTO_SCTP, SCTP_GET_ADDR_LEN, &av, &siz);
|
2006-12-15 12:01:50 +00:00
|
|
|
close(sd);
|
2011-06-15 23:50:27 +00:00
|
|
|
if (ret == 0) {
|
2006-12-15 12:01:50 +00:00
|
|
|
return ((int)av.assoc_value);
|
|
|
|
} else {
|
2007-06-22 13:59:54 +00:00
|
|
|
return (-1);
|
2006-12-15 12:01:50 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2007-06-11 21:05:29 +00:00
|
|
|
sctp_connectx(int sd, const struct sockaddr *addrs, int addrcnt,
|
2020-06-18 16:22:09 +00:00
|
|
|
sctp_assoc_t *id)
|
2006-12-15 12:01:50 +00:00
|
|
|
{
|
2013-04-10 11:26:30 +00:00
|
|
|
char *buf;
|
2013-09-19 06:19:24 +00:00
|
|
|
int i, ret, *aa;
|
2006-12-15 12:01:50 +00:00
|
|
|
char *cpto;
|
|
|
|
const struct sockaddr *at;
|
2013-09-19 06:19:24 +00:00
|
|
|
size_t len;
|
2006-12-15 12:01:50 +00:00
|
|
|
|
2007-06-11 21:05:29 +00:00
|
|
|
/* validate the address count and list */
|
|
|
|
if ((addrs == NULL) || (addrcnt <= 0)) {
|
|
|
|
errno = EINVAL;
|
|
|
|
return (-1);
|
|
|
|
}
|
2013-04-10 11:26:30 +00:00
|
|
|
if ((buf = malloc(sizeof(int) + (size_t)addrcnt * sizeof(struct sockaddr_in6))) == NULL) {
|
|
|
|
errno = E2BIG;
|
|
|
|
return (-1);
|
|
|
|
}
|
2013-09-19 06:19:24 +00:00
|
|
|
len = sizeof(int);
|
2006-12-15 12:01:50 +00:00
|
|
|
at = addrs;
|
2013-04-10 11:26:30 +00:00
|
|
|
cpto = buf + sizeof(int);
|
2006-12-15 12:01:50 +00:00
|
|
|
/* validate all the addresses and get the size */
|
|
|
|
for (i = 0; i < addrcnt; i++) {
|
2012-11-19 19:26:19 +00:00
|
|
|
switch (at->sa_family) {
|
|
|
|
case AF_INET:
|
2007-06-25 18:58:27 +00:00
|
|
|
if (at->sa_len != sizeof(struct sockaddr_in)) {
|
2013-04-10 11:26:30 +00:00
|
|
|
free(buf);
|
2007-06-25 18:58:27 +00:00
|
|
|
errno = EINVAL;
|
|
|
|
return (-1);
|
|
|
|
}
|
2012-11-19 19:26:19 +00:00
|
|
|
memcpy(cpto, at, sizeof(struct sockaddr_in));
|
|
|
|
cpto = ((caddr_t)cpto + sizeof(struct sockaddr_in));
|
|
|
|
len += sizeof(struct sockaddr_in);
|
|
|
|
break;
|
|
|
|
case AF_INET6:
|
2007-06-25 18:58:27 +00:00
|
|
|
if (at->sa_len != sizeof(struct sockaddr_in6)) {
|
2013-04-10 11:26:30 +00:00
|
|
|
free(buf);
|
2007-06-25 18:58:27 +00:00
|
|
|
errno = EINVAL;
|
|
|
|
return (-1);
|
|
|
|
}
|
2006-12-15 12:01:50 +00:00
|
|
|
if (IN6_IS_ADDR_V4MAPPED(&((struct sockaddr_in6 *)at)->sin6_addr)) {
|
|
|
|
in6_sin6_2_sin((struct sockaddr_in *)cpto, (struct sockaddr_in6 *)at);
|
|
|
|
cpto = ((caddr_t)cpto + sizeof(struct sockaddr_in));
|
|
|
|
len += sizeof(struct sockaddr_in);
|
|
|
|
} else {
|
2012-11-19 19:26:19 +00:00
|
|
|
memcpy(cpto, at, sizeof(struct sockaddr_in6));
|
|
|
|
cpto = ((caddr_t)cpto + sizeof(struct sockaddr_in6));
|
|
|
|
len += sizeof(struct sockaddr_in6);
|
2006-12-15 12:01:50 +00:00
|
|
|
}
|
2012-11-19 19:26:19 +00:00
|
|
|
break;
|
|
|
|
default:
|
2013-04-10 11:26:30 +00:00
|
|
|
free(buf);
|
2006-12-15 12:01:50 +00:00
|
|
|
errno = EINVAL;
|
|
|
|
return (-1);
|
|
|
|
}
|
2013-04-10 11:26:30 +00:00
|
|
|
at = (struct sockaddr *)((caddr_t)at + at->sa_len);
|
2006-12-15 12:01:50 +00:00
|
|
|
}
|
|
|
|
aa = (int *)buf;
|
2013-04-10 11:26:30 +00:00
|
|
|
*aa = addrcnt;
|
2006-12-15 12:01:50 +00:00
|
|
|
ret = setsockopt(sd, IPPROTO_SCTP, SCTP_CONNECT_X, (void *)buf,
|
2020-06-18 16:22:09 +00:00
|
|
|
(socklen_t)len);
|
2013-04-10 11:26:30 +00:00
|
|
|
if ((ret == 0) && (id != NULL)) {
|
2020-06-18 16:22:09 +00:00
|
|
|
*id = *(sctp_assoc_t *)buf;
|
2007-03-15 11:27:14 +00:00
|
|
|
}
|
2013-09-19 06:19:24 +00:00
|
|
|
free(buf);
|
2006-12-15 12:01:50 +00:00
|
|
|
return (ret);
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
sctp_bindx(int sd, struct sockaddr *addrs, int addrcnt, int flags)
|
|
|
|
{
|
|
|
|
struct sockaddr *sa;
|
2007-07-24 20:06:02 +00:00
|
|
|
struct sockaddr_in *sin;
|
|
|
|
struct sockaddr_in6 *sin6;
|
2011-12-17 14:55:19 +00:00
|
|
|
int i;
|
2020-06-20 21:06:02 +00:00
|
|
|
uint16_t sport;
|
|
|
|
bool fix_port;
|
2006-12-15 12:01:50 +00:00
|
|
|
|
2007-06-11 21:05:29 +00:00
|
|
|
/* validate the flags */
|
2006-12-15 12:01:50 +00:00
|
|
|
if ((flags != SCTP_BINDX_ADD_ADDR) &&
|
|
|
|
(flags != SCTP_BINDX_REM_ADDR)) {
|
|
|
|
errno = EFAULT;
|
|
|
|
return (-1);
|
|
|
|
}
|
2007-06-11 21:05:29 +00:00
|
|
|
/* validate the address count and list */
|
|
|
|
if ((addrcnt <= 0) || (addrs == NULL)) {
|
|
|
|
errno = EINVAL;
|
|
|
|
return (-1);
|
|
|
|
}
|
2020-06-20 21:06:02 +00:00
|
|
|
sport = 0;
|
|
|
|
fix_port = false;
|
2007-07-24 20:06:02 +00:00
|
|
|
/* First pre-screen the addresses */
|
2006-12-15 12:01:50 +00:00
|
|
|
sa = addrs;
|
2007-07-24 20:06:02 +00:00
|
|
|
for (i = 0; i < addrcnt; i++) {
|
2012-11-19 19:26:19 +00:00
|
|
|
switch (sa->sa_family) {
|
|
|
|
case AF_INET:
|
|
|
|
if (sa->sa_len != sizeof(struct sockaddr_in)) {
|
|
|
|
errno = EINVAL;
|
|
|
|
return (-1);
|
|
|
|
}
|
2007-07-24 20:06:02 +00:00
|
|
|
sin = (struct sockaddr_in *)sa;
|
|
|
|
if (sin->sin_port) {
|
|
|
|
/* non-zero port, check or save */
|
|
|
|
if (sport) {
|
|
|
|
/* Check against our port */
|
|
|
|
if (sport != sin->sin_port) {
|
2012-11-19 19:26:19 +00:00
|
|
|
errno = EINVAL;
|
|
|
|
return (-1);
|
2007-07-24 20:06:02 +00:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
/* save off the port */
|
|
|
|
sport = sin->sin_port;
|
2020-06-20 21:06:02 +00:00
|
|
|
fix_port = (i > 0);
|
2007-07-24 20:06:02 +00:00
|
|
|
}
|
|
|
|
}
|
2012-11-19 19:26:19 +00:00
|
|
|
break;
|
|
|
|
case AF_INET6:
|
|
|
|
if (sa->sa_len != sizeof(struct sockaddr_in6)) {
|
|
|
|
errno = EINVAL;
|
|
|
|
return (-1);
|
|
|
|
}
|
2007-07-24 20:06:02 +00:00
|
|
|
sin6 = (struct sockaddr_in6 *)sa;
|
|
|
|
if (sin6->sin6_port) {
|
|
|
|
/* non-zero port, check or save */
|
|
|
|
if (sport) {
|
|
|
|
/* Check against our port */
|
|
|
|
if (sport != sin6->sin6_port) {
|
2012-11-19 19:26:19 +00:00
|
|
|
errno = EINVAL;
|
|
|
|
return (-1);
|
2007-07-24 20:06:02 +00:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
/* save off the port */
|
|
|
|
sport = sin6->sin6_port;
|
2020-06-20 21:06:02 +00:00
|
|
|
fix_port = (i > 0);
|
2007-07-24 20:06:02 +00:00
|
|
|
}
|
|
|
|
}
|
2012-11-19 19:26:19 +00:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
/* Invalid address family specified. */
|
2014-01-04 11:39:59 +00:00
|
|
|
errno = EAFNOSUPPORT;
|
2012-11-19 19:26:19 +00:00
|
|
|
return (-1);
|
2007-07-24 20:06:02 +00:00
|
|
|
}
|
2011-12-17 14:55:19 +00:00
|
|
|
sa = (struct sockaddr *)((caddr_t)sa + sa->sa_len);
|
2007-07-24 20:06:02 +00:00
|
|
|
}
|
2012-11-19 19:26:19 +00:00
|
|
|
sa = addrs;
|
2006-12-15 12:01:50 +00:00
|
|
|
for (i = 0; i < addrcnt; i++) {
|
2014-01-04 11:39:59 +00:00
|
|
|
/*
|
|
|
|
* Now, if there was a port mentioned, assure that the first
|
|
|
|
* address has that port to make sure it fails or succeeds
|
|
|
|
* correctly.
|
|
|
|
*/
|
2020-06-20 21:06:02 +00:00
|
|
|
if (fix_port) {
|
|
|
|
switch (sa->sa_family) {
|
2014-01-04 11:39:59 +00:00
|
|
|
case AF_INET:
|
2020-06-20 21:06:02 +00:00
|
|
|
((struct sockaddr_in *)sa)->sin_port = sport;
|
2014-01-04 11:39:59 +00:00
|
|
|
break;
|
|
|
|
case AF_INET6:
|
2020-06-20 21:06:02 +00:00
|
|
|
((struct sockaddr_in6 *)sa)->sin6_port = sport;
|
2014-01-04 11:39:59 +00:00
|
|
|
break;
|
|
|
|
}
|
2020-06-20 21:06:02 +00:00
|
|
|
fix_port = false;
|
2014-01-04 11:39:59 +00:00
|
|
|
}
|
2020-06-20 21:06:02 +00:00
|
|
|
if (setsockopt(sd, IPPROTO_SCTP, flags, sa, sa->sa_len) != 0) {
|
2006-12-15 12:01:50 +00:00
|
|
|
return (-1);
|
|
|
|
}
|
2011-12-17 14:55:19 +00:00
|
|
|
sa = (struct sockaddr *)((caddr_t)sa + sa->sa_len);
|
2006-12-15 12:01:50 +00:00
|
|
|
}
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2020-06-18 16:22:09 +00:00
|
|
|
sctp_opt_info(int sd, sctp_assoc_t id, int opt, void *arg, socklen_t *size)
|
2006-12-15 12:01:50 +00:00
|
|
|
{
|
|
|
|
if (arg == NULL) {
|
2007-07-02 10:52:34 +00:00
|
|
|
errno = EINVAL;
|
|
|
|
return (-1);
|
2006-12-15 12:01:50 +00:00
|
|
|
}
|
2013-07-09 19:12:47 +00:00
|
|
|
if ((id == SCTP_CURRENT_ASSOC) ||
|
|
|
|
(id == SCTP_ALL_ASSOC)) {
|
|
|
|
errno = EINVAL;
|
|
|
|
return (-1);
|
|
|
|
}
|
2007-07-24 20:06:02 +00:00
|
|
|
switch (opt) {
|
|
|
|
case SCTP_RTOINFO:
|
|
|
|
((struct sctp_rtoinfo *)arg)->srto_assoc_id = id;
|
|
|
|
break;
|
|
|
|
case SCTP_ASSOCINFO:
|
|
|
|
((struct sctp_assocparams *)arg)->sasoc_assoc_id = id;
|
|
|
|
break;
|
|
|
|
case SCTP_DEFAULT_SEND_PARAM:
|
|
|
|
((struct sctp_assocparams *)arg)->sasoc_assoc_id = id;
|
|
|
|
break;
|
|
|
|
case SCTP_PRIMARY_ADDR:
|
|
|
|
((struct sctp_setprim *)arg)->ssp_assoc_id = id;
|
|
|
|
break;
|
|
|
|
case SCTP_PEER_ADDR_PARAMS:
|
|
|
|
((struct sctp_paddrparams *)arg)->spp_assoc_id = id;
|
|
|
|
break;
|
|
|
|
case SCTP_MAXSEG:
|
|
|
|
((struct sctp_assoc_value *)arg)->assoc_id = id;
|
|
|
|
break;
|
|
|
|
case SCTP_AUTH_KEY:
|
|
|
|
((struct sctp_authkey *)arg)->sca_assoc_id = id;
|
|
|
|
break;
|
|
|
|
case SCTP_AUTH_ACTIVE_KEY:
|
|
|
|
((struct sctp_authkeyid *)arg)->scact_assoc_id = id;
|
|
|
|
break;
|
|
|
|
case SCTP_DELAYED_SACK:
|
|
|
|
((struct sctp_sack_info *)arg)->sack_assoc_id = id;
|
|
|
|
break;
|
|
|
|
case SCTP_CONTEXT:
|
|
|
|
((struct sctp_assoc_value *)arg)->assoc_id = id;
|
|
|
|
break;
|
|
|
|
case SCTP_STATUS:
|
|
|
|
((struct sctp_status *)arg)->sstat_assoc_id = id;
|
|
|
|
break;
|
|
|
|
case SCTP_GET_PEER_ADDR_INFO:
|
|
|
|
((struct sctp_paddrinfo *)arg)->spinfo_assoc_id = id;
|
|
|
|
break;
|
|
|
|
case SCTP_PEER_AUTH_CHUNKS:
|
|
|
|
((struct sctp_authchunks *)arg)->gauth_assoc_id = id;
|
|
|
|
break;
|
|
|
|
case SCTP_LOCAL_AUTH_CHUNKS:
|
|
|
|
((struct sctp_authchunks *)arg)->gauth_assoc_id = id;
|
|
|
|
break;
|
2011-05-05 19:49:27 +00:00
|
|
|
case SCTP_TIMEOUTS:
|
|
|
|
((struct sctp_timeouts *)arg)->stimo_assoc_id = id;
|
|
|
|
break;
|
2011-06-15 23:50:27 +00:00
|
|
|
case SCTP_EVENT:
|
|
|
|
((struct sctp_event *)arg)->se_assoc_id = id;
|
|
|
|
break;
|
2011-06-17 07:03:42 +00:00
|
|
|
case SCTP_DEFAULT_SNDINFO:
|
|
|
|
((struct sctp_sndinfo *)arg)->snd_assoc_id = id;
|
|
|
|
break;
|
|
|
|
case SCTP_DEFAULT_PRINFO:
|
|
|
|
((struct sctp_default_prinfo *)arg)->pr_assoc_id = id;
|
|
|
|
break;
|
2011-08-03 20:21:00 +00:00
|
|
|
case SCTP_PEER_ADDR_THLDS:
|
|
|
|
((struct sctp_paddrthlds *)arg)->spt_assoc_id = id;
|
|
|
|
break;
|
2011-11-20 15:00:45 +00:00
|
|
|
case SCTP_REMOTE_UDP_ENCAPS_PORT:
|
|
|
|
((struct sctp_udpencaps *)arg)->sue_assoc_id = id;
|
|
|
|
break;
|
2014-08-02 17:35:13 +00:00
|
|
|
case SCTP_ECN_SUPPORTED:
|
|
|
|
((struct sctp_assoc_value *)arg)->assoc_id = id;
|
2014-08-02 21:36:40 +00:00
|
|
|
break;
|
|
|
|
case SCTP_PR_SUPPORTED:
|
|
|
|
((struct sctp_assoc_value *)arg)->assoc_id = id;
|
2014-08-03 14:10:10 +00:00
|
|
|
break;
|
2014-08-12 11:30:16 +00:00
|
|
|
case SCTP_AUTH_SUPPORTED:
|
|
|
|
((struct sctp_assoc_value *)arg)->assoc_id = id;
|
|
|
|
break;
|
|
|
|
case SCTP_ASCONF_SUPPORTED:
|
|
|
|
((struct sctp_assoc_value *)arg)->assoc_id = id;
|
|
|
|
break;
|
2014-08-04 20:07:35 +00:00
|
|
|
case SCTP_RECONFIG_SUPPORTED:
|
|
|
|
((struct sctp_assoc_value *)arg)->assoc_id = id;
|
|
|
|
break;
|
2014-08-03 14:10:10 +00:00
|
|
|
case SCTP_NRSACK_SUPPORTED:
|
|
|
|
((struct sctp_assoc_value *)arg)->assoc_id = id;
|
2014-08-03 18:12:55 +00:00
|
|
|
break;
|
|
|
|
case SCTP_PKTDROP_SUPPORTED:
|
|
|
|
((struct sctp_assoc_value *)arg)->assoc_id = id;
|
2014-08-02 17:35:13 +00:00
|
|
|
break;
|
2011-06-17 07:06:42 +00:00
|
|
|
case SCTP_MAX_BURST:
|
|
|
|
((struct sctp_assoc_value *)arg)->assoc_id = id;
|
|
|
|
break;
|
2013-07-09 19:04:19 +00:00
|
|
|
case SCTP_ENABLE_STREAM_RESET:
|
|
|
|
((struct sctp_assoc_value *)arg)->assoc_id = id;
|
|
|
|
break;
|
2014-08-13 15:50:16 +00:00
|
|
|
case SCTP_PR_STREAM_STATUS:
|
|
|
|
((struct sctp_prstatus *)arg)->sprstat_assoc_id = id;
|
|
|
|
break;
|
|
|
|
case SCTP_PR_ASSOC_STATUS:
|
|
|
|
((struct sctp_prstatus *)arg)->sprstat_assoc_id = id;
|
|
|
|
break;
|
2015-03-10 19:49:25 +00:00
|
|
|
case SCTP_MAX_CWND:
|
|
|
|
((struct sctp_assoc_value *)arg)->assoc_id = id;
|
|
|
|
break;
|
2007-07-24 20:06:02 +00:00
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
2007-05-16 20:23:39 +00:00
|
|
|
return (getsockopt(sd, IPPROTO_SCTP, opt, arg, size));
|
2006-12-15 12:01:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
sctp_getpaddrs(int sd, sctp_assoc_t id, struct sockaddr **raddrs)
|
|
|
|
{
|
|
|
|
struct sctp_getaddresses *addrs;
|
|
|
|
struct sockaddr *sa;
|
|
|
|
sctp_assoc_t asoc;
|
|
|
|
caddr_t lim;
|
2011-12-17 14:55:19 +00:00
|
|
|
socklen_t opt_len;
|
2006-12-15 12:01:50 +00:00
|
|
|
int cnt;
|
|
|
|
|
|
|
|
if (raddrs == NULL) {
|
|
|
|
errno = EFAULT;
|
|
|
|
return (-1);
|
|
|
|
}
|
|
|
|
asoc = id;
|
2020-06-18 16:22:09 +00:00
|
|
|
opt_len = (socklen_t)sizeof(sctp_assoc_t);
|
2006-12-15 12:01:50 +00:00
|
|
|
if (getsockopt(sd, IPPROTO_SCTP, SCTP_GET_REMOTE_ADDR_SIZE,
|
2011-12-17 14:55:19 +00:00
|
|
|
&asoc, &opt_len) != 0) {
|
2006-12-15 12:01:50 +00:00
|
|
|
return (-1);
|
|
|
|
}
|
|
|
|
/* size required is returned in 'asoc' */
|
2020-06-21 23:12:56 +00:00
|
|
|
opt_len = (socklen_t)((size_t)asoc + sizeof(struct sctp_getaddresses));
|
2011-12-17 14:55:19 +00:00
|
|
|
addrs = calloc(1, (size_t)opt_len);
|
2006-12-15 12:01:50 +00:00
|
|
|
if (addrs == NULL) {
|
2012-11-03 13:22:25 +00:00
|
|
|
errno = ENOMEM;
|
2006-12-15 12:01:50 +00:00
|
|
|
return (-1);
|
|
|
|
}
|
|
|
|
addrs->sget_assoc_id = id;
|
|
|
|
/* Now lets get the array of addresses */
|
|
|
|
if (getsockopt(sd, IPPROTO_SCTP, SCTP_GET_PEER_ADDRESSES,
|
2011-12-17 14:55:19 +00:00
|
|
|
addrs, &opt_len) != 0) {
|
2006-12-15 12:01:50 +00:00
|
|
|
free(addrs);
|
|
|
|
return (-1);
|
|
|
|
}
|
2020-06-21 23:12:56 +00:00
|
|
|
*raddrs = &addrs->addr[0].sa;
|
2006-12-15 12:01:50 +00:00
|
|
|
cnt = 0;
|
2020-06-21 23:12:56 +00:00
|
|
|
sa = &addrs->addr[0].sa;
|
2011-12-17 14:55:19 +00:00
|
|
|
lim = (caddr_t)addrs + opt_len;
|
2006-12-15 12:01:50 +00:00
|
|
|
while (((caddr_t)sa < lim) && (sa->sa_len > 0)) {
|
|
|
|
sa = (struct sockaddr *)((caddr_t)sa + sa->sa_len);
|
|
|
|
cnt++;
|
|
|
|
}
|
|
|
|
return (cnt);
|
|
|
|
}
|
|
|
|
|
2007-03-15 11:27:14 +00:00
|
|
|
void
|
2006-12-15 12:01:50 +00:00
|
|
|
sctp_freepaddrs(struct sockaddr *addrs)
|
|
|
|
{
|
|
|
|
void *fr_addr;
|
|
|
|
|
2013-04-10 11:26:30 +00:00
|
|
|
/* Take away the hidden association id */
|
2020-06-21 23:12:56 +00:00
|
|
|
fr_addr = (void *)((caddr_t)addrs - offsetof(struct sctp_getaddresses, addr));
|
2006-12-15 12:01:50 +00:00
|
|
|
/* Now free it */
|
|
|
|
free(fr_addr);
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
sctp_getladdrs(int sd, sctp_assoc_t id, struct sockaddr **raddrs)
|
|
|
|
{
|
|
|
|
struct sctp_getaddresses *addrs;
|
|
|
|
caddr_t lim;
|
|
|
|
struct sockaddr *sa;
|
2011-12-17 14:55:19 +00:00
|
|
|
size_t size_of_addresses;
|
|
|
|
socklen_t opt_len;
|
2006-12-15 12:01:50 +00:00
|
|
|
int cnt;
|
|
|
|
|
|
|
|
if (raddrs == NULL) {
|
|
|
|
errno = EFAULT;
|
|
|
|
return (-1);
|
|
|
|
}
|
|
|
|
size_of_addresses = 0;
|
2020-06-18 16:22:09 +00:00
|
|
|
opt_len = (socklen_t)sizeof(int);
|
2006-12-15 12:01:50 +00:00
|
|
|
if (getsockopt(sd, IPPROTO_SCTP, SCTP_GET_LOCAL_ADDR_SIZE,
|
2011-12-17 14:55:19 +00:00
|
|
|
&size_of_addresses, &opt_len) != 0) {
|
2006-12-15 12:01:50 +00:00
|
|
|
errno = ENOMEM;
|
|
|
|
return (-1);
|
|
|
|
}
|
|
|
|
if (size_of_addresses == 0) {
|
|
|
|
errno = ENOTCONN;
|
|
|
|
return (-1);
|
|
|
|
}
|
2020-06-21 23:12:56 +00:00
|
|
|
opt_len = (socklen_t)(size_of_addresses + sizeof(struct sctp_getaddresses));
|
2011-12-17 14:55:19 +00:00
|
|
|
addrs = calloc(1, (size_t)opt_len);
|
2006-12-15 12:01:50 +00:00
|
|
|
if (addrs == NULL) {
|
|
|
|
errno = ENOMEM;
|
|
|
|
return (-1);
|
|
|
|
}
|
|
|
|
addrs->sget_assoc_id = id;
|
|
|
|
/* Now lets get the array of addresses */
|
|
|
|
if (getsockopt(sd, IPPROTO_SCTP, SCTP_GET_LOCAL_ADDRESSES, addrs,
|
2011-12-17 14:55:19 +00:00
|
|
|
&opt_len) != 0) {
|
2006-12-15 12:01:50 +00:00
|
|
|
free(addrs);
|
|
|
|
errno = ENOMEM;
|
|
|
|
return (-1);
|
|
|
|
}
|
2020-06-21 23:12:56 +00:00
|
|
|
*raddrs = &addrs->addr[0].sa;
|
2006-12-15 12:01:50 +00:00
|
|
|
cnt = 0;
|
2020-06-21 23:12:56 +00:00
|
|
|
sa = &addrs->addr[0].sa;
|
2011-12-17 14:55:19 +00:00
|
|
|
lim = (caddr_t)addrs + opt_len;
|
2006-12-15 12:01:50 +00:00
|
|
|
while (((caddr_t)sa < lim) && (sa->sa_len > 0)) {
|
|
|
|
sa = (struct sockaddr *)((caddr_t)sa + sa->sa_len);
|
|
|
|
cnt++;
|
|
|
|
}
|
|
|
|
return (cnt);
|
|
|
|
}
|
|
|
|
|
2007-03-15 11:27:14 +00:00
|
|
|
void
|
2006-12-15 12:01:50 +00:00
|
|
|
sctp_freeladdrs(struct sockaddr *addrs)
|
|
|
|
{
|
|
|
|
void *fr_addr;
|
|
|
|
|
2013-04-10 11:26:30 +00:00
|
|
|
/* Take away the hidden association id */
|
2020-06-21 23:12:56 +00:00
|
|
|
fr_addr = (void *)((caddr_t)addrs - offsetof(struct sctp_getaddresses, addr));
|
2006-12-15 12:01:50 +00:00
|
|
|
/* Now free it */
|
|
|
|
free(fr_addr);
|
|
|
|
}
|
|
|
|
|
|
|
|
ssize_t
|
|
|
|
sctp_sendmsg(int s,
|
|
|
|
const void *data,
|
|
|
|
size_t len,
|
|
|
|
const struct sockaddr *to,
|
2007-05-16 20:23:39 +00:00
|
|
|
socklen_t tolen,
|
2010-07-04 08:09:33 +00:00
|
|
|
uint32_t ppid,
|
|
|
|
uint32_t flags,
|
|
|
|
uint16_t stream_no,
|
|
|
|
uint32_t timetolive,
|
|
|
|
uint32_t context)
|
2006-12-15 12:01:50 +00:00
|
|
|
{
|
|
|
|
#ifdef SYS_sctp_generic_sendmsg
|
|
|
|
struct sctp_sndrcvinfo sinfo;
|
|
|
|
|
2011-12-15 12:35:03 +00:00
|
|
|
memset(&sinfo, 0, sizeof(struct sctp_sndrcvinfo));
|
2006-12-15 12:01:50 +00:00
|
|
|
sinfo.sinfo_ppid = ppid;
|
|
|
|
sinfo.sinfo_flags = flags;
|
|
|
|
sinfo.sinfo_stream = stream_no;
|
|
|
|
sinfo.sinfo_timetolive = timetolive;
|
|
|
|
sinfo.sinfo_context = context;
|
|
|
|
sinfo.sinfo_assoc_id = 0;
|
|
|
|
return (syscall(SYS_sctp_generic_sendmsg, s,
|
|
|
|
data, len, to, tolen, &sinfo, 0));
|
|
|
|
#else
|
|
|
|
struct msghdr msg;
|
2013-04-10 11:26:30 +00:00
|
|
|
struct sctp_sndrcvinfo *sinfo;
|
2011-05-05 19:49:27 +00:00
|
|
|
struct iovec iov;
|
2013-04-10 11:26:30 +00:00
|
|
|
char cmsgbuf[CMSG_SPACE(sizeof(struct sctp_sndrcvinfo))];
|
2006-12-15 12:01:50 +00:00
|
|
|
struct cmsghdr *cmsg;
|
|
|
|
struct sockaddr *who = NULL;
|
|
|
|
union {
|
|
|
|
struct sockaddr_in in;
|
|
|
|
struct sockaddr_in6 in6;
|
|
|
|
} addr;
|
|
|
|
|
2011-05-05 19:49:27 +00:00
|
|
|
if ((tolen > 0) &&
|
|
|
|
((to == NULL) || (tolen < sizeof(struct sockaddr)))) {
|
2007-05-16 20:23:39 +00:00
|
|
|
errno = EINVAL;
|
2013-02-10 19:21:17 +00:00
|
|
|
return (-1);
|
2007-05-16 20:23:39 +00:00
|
|
|
}
|
2013-04-10 11:26:30 +00:00
|
|
|
if ((to != NULL) && (tolen > 0)) {
|
|
|
|
switch (to->sa_family) {
|
|
|
|
case AF_INET:
|
2007-05-16 20:23:39 +00:00
|
|
|
if (tolen != sizeof(struct sockaddr_in)) {
|
|
|
|
errno = EINVAL;
|
2013-02-10 19:21:17 +00:00
|
|
|
return (-1);
|
2007-05-16 20:23:39 +00:00
|
|
|
}
|
2011-05-05 19:49:27 +00:00
|
|
|
if ((to->sa_len > 0) &&
|
|
|
|
(to->sa_len != sizeof(struct sockaddr_in))) {
|
2007-05-16 20:23:39 +00:00
|
|
|
errno = EINVAL;
|
2013-02-10 19:21:17 +00:00
|
|
|
return (-1);
|
2007-05-16 20:23:39 +00:00
|
|
|
}
|
|
|
|
memcpy(&addr, to, sizeof(struct sockaddr_in));
|
|
|
|
addr.in.sin_len = sizeof(struct sockaddr_in);
|
2013-04-10 11:26:30 +00:00
|
|
|
break;
|
|
|
|
case AF_INET6:
|
2007-05-16 20:23:39 +00:00
|
|
|
if (tolen != sizeof(struct sockaddr_in6)) {
|
|
|
|
errno = EINVAL;
|
2013-02-10 19:21:17 +00:00
|
|
|
return (-1);
|
2007-05-16 20:23:39 +00:00
|
|
|
}
|
2011-05-05 19:49:27 +00:00
|
|
|
if ((to->sa_len > 0) &&
|
|
|
|
(to->sa_len != sizeof(struct sockaddr_in6))) {
|
2007-05-16 20:23:39 +00:00
|
|
|
errno = EINVAL;
|
2013-02-10 19:21:17 +00:00
|
|
|
return (-1);
|
2006-12-15 12:01:50 +00:00
|
|
|
}
|
2007-05-16 20:23:39 +00:00
|
|
|
memcpy(&addr, to, sizeof(struct sockaddr_in6));
|
|
|
|
addr.in6.sin6_len = sizeof(struct sockaddr_in6);
|
2013-04-10 11:26:30 +00:00
|
|
|
break;
|
|
|
|
default:
|
2007-05-16 20:23:39 +00:00
|
|
|
errno = EAFNOSUPPORT;
|
2013-02-10 19:21:17 +00:00
|
|
|
return (-1);
|
2006-12-15 12:01:50 +00:00
|
|
|
}
|
|
|
|
who = (struct sockaddr *)&addr;
|
|
|
|
}
|
2020-06-18 16:22:09 +00:00
|
|
|
|
2011-05-05 19:49:27 +00:00
|
|
|
iov.iov_base = (char *)data;
|
|
|
|
iov.iov_len = len;
|
2006-12-15 12:01:50 +00:00
|
|
|
|
2007-05-16 20:23:39 +00:00
|
|
|
if (who) {
|
2006-12-15 12:01:50 +00:00
|
|
|
msg.msg_name = (caddr_t)who;
|
|
|
|
msg.msg_namelen = who->sa_len;
|
|
|
|
} else {
|
|
|
|
msg.msg_name = (caddr_t)NULL;
|
|
|
|
msg.msg_namelen = 0;
|
|
|
|
}
|
2011-05-05 19:49:27 +00:00
|
|
|
msg.msg_iov = &iov;
|
2006-12-15 12:01:50 +00:00
|
|
|
msg.msg_iovlen = 1;
|
2013-04-10 11:26:30 +00:00
|
|
|
msg.msg_control = cmsgbuf;
|
|
|
|
msg.msg_controllen = CMSG_SPACE(sizeof(struct sctp_sndrcvinfo));
|
2014-12-17 07:47:25 +00:00
|
|
|
msg.msg_flags = 0;
|
2013-04-10 11:26:30 +00:00
|
|
|
cmsg = (struct cmsghdr *)cmsgbuf;
|
2006-12-15 12:01:50 +00:00
|
|
|
cmsg->cmsg_level = IPPROTO_SCTP;
|
|
|
|
cmsg->cmsg_type = SCTP_SNDRCV;
|
|
|
|
cmsg->cmsg_len = CMSG_LEN(sizeof(struct sctp_sndrcvinfo));
|
2013-04-10 11:26:30 +00:00
|
|
|
sinfo = (struct sctp_sndrcvinfo *)CMSG_DATA(cmsg);
|
2014-08-12 11:30:16 +00:00
|
|
|
memset(sinfo, 0, sizeof(struct sctp_sndrcvinfo));
|
2013-04-10 11:26:30 +00:00
|
|
|
sinfo->sinfo_stream = stream_no;
|
|
|
|
sinfo->sinfo_ssn = 0;
|
|
|
|
sinfo->sinfo_flags = flags;
|
|
|
|
sinfo->sinfo_ppid = ppid;
|
|
|
|
sinfo->sinfo_context = context;
|
|
|
|
sinfo->sinfo_assoc_id = 0;
|
|
|
|
sinfo->sinfo_timetolive = timetolive;
|
|
|
|
return (sendmsg(s, &msg, 0));
|
2006-12-15 12:01:50 +00:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
sctp_assoc_t
|
|
|
|
sctp_getassocid(int sd, struct sockaddr *sa)
|
|
|
|
{
|
2007-07-14 09:36:28 +00:00
|
|
|
struct sctp_paddrinfo sp;
|
2006-12-16 06:03:43 +00:00
|
|
|
socklen_t siz;
|
2006-12-15 12:01:50 +00:00
|
|
|
|
|
|
|
/* First get the assoc id */
|
2007-07-14 09:36:28 +00:00
|
|
|
siz = sizeof(sp);
|
2006-12-15 12:01:50 +00:00
|
|
|
memset(&sp, 0, sizeof(sp));
|
2007-07-14 09:36:28 +00:00
|
|
|
memcpy((caddr_t)&sp.spinfo_address, sa, sa->sa_len);
|
2006-12-15 12:01:50 +00:00
|
|
|
if (getsockopt(sd, IPPROTO_SCTP,
|
2007-07-14 09:36:28 +00:00
|
|
|
SCTP_GET_PEER_ADDR_INFO, &sp, &siz) != 0) {
|
2013-04-10 11:26:30 +00:00
|
|
|
/* We depend on the fact that 0 can never be returned */
|
2020-06-18 16:22:09 +00:00
|
|
|
return ((sctp_assoc_t)0);
|
2006-12-15 12:01:50 +00:00
|
|
|
}
|
2007-07-14 09:36:28 +00:00
|
|
|
return (sp.spinfo_assoc_id);
|
2006-12-15 12:01:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
ssize_t
|
|
|
|
sctp_send(int sd, const void *data, size_t len,
|
|
|
|
const struct sctp_sndrcvinfo *sinfo,
|
|
|
|
int flags)
|
|
|
|
{
|
|
|
|
|
|
|
|
#ifdef SYS_sctp_generic_sendmsg
|
|
|
|
struct sockaddr *to = NULL;
|
|
|
|
|
|
|
|
return (syscall(SYS_sctp_generic_sendmsg, sd,
|
|
|
|
data, len, to, 0, sinfo, flags));
|
|
|
|
#else
|
|
|
|
struct msghdr msg;
|
2011-05-05 19:49:27 +00:00
|
|
|
struct iovec iov;
|
2013-04-10 11:26:30 +00:00
|
|
|
char cmsgbuf[CMSG_SPACE(sizeof(struct sctp_sndrcvinfo))];
|
2006-12-15 12:01:50 +00:00
|
|
|
struct cmsghdr *cmsg;
|
|
|
|
|
|
|
|
if (sinfo == NULL) {
|
2007-07-14 09:36:28 +00:00
|
|
|
errno = EINVAL;
|
|
|
|
return (-1);
|
2006-12-15 12:01:50 +00:00
|
|
|
}
|
2011-05-05 19:49:27 +00:00
|
|
|
iov.iov_base = (char *)data;
|
|
|
|
iov.iov_len = len;
|
2006-12-15 12:01:50 +00:00
|
|
|
|
2013-04-10 11:26:30 +00:00
|
|
|
msg.msg_name = NULL;
|
2006-12-15 12:01:50 +00:00
|
|
|
msg.msg_namelen = 0;
|
2011-05-05 19:49:27 +00:00
|
|
|
msg.msg_iov = &iov;
|
2006-12-15 12:01:50 +00:00
|
|
|
msg.msg_iovlen = 1;
|
2013-04-10 11:26:30 +00:00
|
|
|
msg.msg_control = cmsgbuf;
|
|
|
|
msg.msg_controllen = CMSG_SPACE(sizeof(struct sctp_sndrcvinfo));
|
2014-12-17 07:47:25 +00:00
|
|
|
msg.msg_flags = 0;
|
2013-04-10 11:26:30 +00:00
|
|
|
cmsg = (struct cmsghdr *)cmsgbuf;
|
2006-12-15 12:01:50 +00:00
|
|
|
cmsg->cmsg_level = IPPROTO_SCTP;
|
|
|
|
cmsg->cmsg_type = SCTP_SNDRCV;
|
|
|
|
cmsg->cmsg_len = CMSG_LEN(sizeof(struct sctp_sndrcvinfo));
|
2013-04-10 11:26:30 +00:00
|
|
|
memcpy(CMSG_DATA(cmsg), sinfo, sizeof(struct sctp_sndrcvinfo));
|
|
|
|
return (sendmsg(sd, &msg, flags));
|
2006-12-15 12:01:50 +00:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ssize_t
|
|
|
|
sctp_sendx(int sd, const void *msg, size_t msg_len,
|
|
|
|
struct sockaddr *addrs, int addrcnt,
|
|
|
|
struct sctp_sndrcvinfo *sinfo,
|
|
|
|
int flags)
|
|
|
|
{
|
2010-07-07 11:19:06 +00:00
|
|
|
struct sctp_sndrcvinfo __sinfo;
|
2006-12-15 12:01:50 +00:00
|
|
|
ssize_t ret;
|
|
|
|
int i, cnt, *aa, saved_errno;
|
|
|
|
char *buf;
|
2011-12-17 14:55:19 +00:00
|
|
|
int no_end_cx = 0;
|
|
|
|
size_t len, add_len;
|
2006-12-15 12:01:50 +00:00
|
|
|
struct sockaddr *at;
|
|
|
|
|
2007-07-24 20:06:02 +00:00
|
|
|
if (addrs == NULL) {
|
|
|
|
errno = EINVAL;
|
|
|
|
return (-1);
|
|
|
|
}
|
2007-02-22 12:42:43 +00:00
|
|
|
#ifdef SYS_sctp_generic_sendmsg
|
2011-05-05 19:49:27 +00:00
|
|
|
if (addrcnt == 1) {
|
2007-02-22 12:42:43 +00:00
|
|
|
socklen_t l;
|
2016-01-24 22:31:34 +00:00
|
|
|
ssize_t ret;
|
2007-02-22 12:42:43 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Quick way, we don't need to do a connectx so lets use the
|
|
|
|
* syscall directly.
|
|
|
|
*/
|
|
|
|
l = addrs->sa_len;
|
2016-01-24 22:31:34 +00:00
|
|
|
ret = syscall(SYS_sctp_generic_sendmsg, sd,
|
|
|
|
msg, msg_len, addrs, l, sinfo, flags);
|
|
|
|
if ((ret >= 0) && (sinfo != NULL)) {
|
|
|
|
sinfo->sinfo_assoc_id = sctp_getassocid(sd, addrs);
|
|
|
|
}
|
|
|
|
return (ret);
|
2007-02-22 12:42:43 +00:00
|
|
|
}
|
|
|
|
#endif
|
2007-07-14 09:36:28 +00:00
|
|
|
|
2006-12-15 12:01:50 +00:00
|
|
|
len = sizeof(int);
|
|
|
|
at = addrs;
|
|
|
|
cnt = 0;
|
|
|
|
/* validate all the addresses and get the size */
|
|
|
|
for (i = 0; i < addrcnt; i++) {
|
|
|
|
if (at->sa_family == AF_INET) {
|
|
|
|
add_len = sizeof(struct sockaddr_in);
|
|
|
|
} else if (at->sa_family == AF_INET6) {
|
|
|
|
add_len = sizeof(struct sockaddr_in6);
|
|
|
|
} else {
|
|
|
|
errno = EINVAL;
|
|
|
|
return (-1);
|
|
|
|
}
|
|
|
|
len += add_len;
|
|
|
|
at = (struct sockaddr *)((caddr_t)at + add_len);
|
|
|
|
cnt++;
|
|
|
|
}
|
|
|
|
/* do we have any? */
|
|
|
|
if (cnt == 0) {
|
|
|
|
errno = EINVAL;
|
|
|
|
return (-1);
|
|
|
|
}
|
|
|
|
buf = malloc(len);
|
|
|
|
if (buf == NULL) {
|
2012-11-03 13:22:25 +00:00
|
|
|
errno = ENOMEM;
|
2007-07-14 09:36:28 +00:00
|
|
|
return (-1);
|
2006-12-15 12:01:50 +00:00
|
|
|
}
|
|
|
|
aa = (int *)buf;
|
|
|
|
*aa = cnt;
|
|
|
|
aa++;
|
2011-12-17 14:55:19 +00:00
|
|
|
memcpy((caddr_t)aa, addrs, (size_t)(len - sizeof(int)));
|
2006-12-15 12:01:50 +00:00
|
|
|
ret = setsockopt(sd, IPPROTO_SCTP, SCTP_CONNECT_X_DELAYED, (void *)buf,
|
2020-06-18 16:22:09 +00:00
|
|
|
(socklen_t)len);
|
2006-12-15 12:01:50 +00:00
|
|
|
|
|
|
|
free(buf);
|
|
|
|
if (ret != 0) {
|
|
|
|
if (errno == EALREADY) {
|
2010-01-31 21:47:39 +00:00
|
|
|
no_end_cx = 1;
|
2006-12-15 12:01:50 +00:00
|
|
|
goto continue_send;
|
|
|
|
}
|
|
|
|
return (ret);
|
|
|
|
}
|
|
|
|
continue_send:
|
2010-07-07 11:19:06 +00:00
|
|
|
if (sinfo == NULL) {
|
|
|
|
sinfo = &__sinfo;
|
|
|
|
memset(&__sinfo, 0, sizeof(__sinfo));
|
|
|
|
}
|
2006-12-15 12:01:50 +00:00
|
|
|
sinfo->sinfo_assoc_id = sctp_getassocid(sd, addrs);
|
|
|
|
if (sinfo->sinfo_assoc_id == 0) {
|
|
|
|
(void)setsockopt(sd, IPPROTO_SCTP, SCTP_CONNECT_X_COMPLETE, (void *)addrs,
|
2020-06-18 16:22:09 +00:00
|
|
|
(socklen_t)addrs->sa_len);
|
2006-12-15 12:01:50 +00:00
|
|
|
errno = ENOENT;
|
|
|
|
return (-1);
|
|
|
|
}
|
|
|
|
ret = sctp_send(sd, msg, msg_len, sinfo, flags);
|
|
|
|
saved_errno = errno;
|
|
|
|
if (no_end_cx == 0)
|
|
|
|
(void)setsockopt(sd, IPPROTO_SCTP, SCTP_CONNECT_X_COMPLETE, (void *)addrs,
|
2020-06-18 16:22:09 +00:00
|
|
|
(socklen_t)addrs->sa_len);
|
2006-12-15 12:01:50 +00:00
|
|
|
|
|
|
|
errno = saved_errno;
|
|
|
|
return (ret);
|
|
|
|
}
|
|
|
|
|
|
|
|
ssize_t
|
|
|
|
sctp_sendmsgx(int sd,
|
|
|
|
const void *msg,
|
|
|
|
size_t len,
|
|
|
|
struct sockaddr *addrs,
|
|
|
|
int addrcnt,
|
2010-07-04 08:09:33 +00:00
|
|
|
uint32_t ppid,
|
|
|
|
uint32_t flags,
|
|
|
|
uint16_t stream_no,
|
|
|
|
uint32_t timetolive,
|
|
|
|
uint32_t context)
|
2006-12-15 12:01:50 +00:00
|
|
|
{
|
|
|
|
struct sctp_sndrcvinfo sinfo;
|
|
|
|
|
|
|
|
memset((void *)&sinfo, 0, sizeof(struct sctp_sndrcvinfo));
|
|
|
|
sinfo.sinfo_ppid = ppid;
|
|
|
|
sinfo.sinfo_flags = flags;
|
2016-12-07 21:24:49 +00:00
|
|
|
sinfo.sinfo_stream = stream_no;
|
2006-12-15 12:01:50 +00:00
|
|
|
sinfo.sinfo_timetolive = timetolive;
|
|
|
|
sinfo.sinfo_context = context;
|
2013-02-10 19:21:17 +00:00
|
|
|
return (sctp_sendx(sd, msg, len, addrs, addrcnt, &sinfo, 0));
|
2006-12-15 12:01:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
ssize_t
|
|
|
|
sctp_recvmsg(int s,
|
|
|
|
void *dbuf,
|
|
|
|
size_t len,
|
|
|
|
struct sockaddr *from,
|
2020-06-18 16:22:09 +00:00
|
|
|
socklen_t *fromlen,
|
2006-12-15 12:01:50 +00:00
|
|
|
struct sctp_sndrcvinfo *sinfo,
|
|
|
|
int *msg_flags)
|
|
|
|
{
|
|
|
|
#ifdef SYS_sctp_generic_recvmsg
|
2011-05-05 19:49:27 +00:00
|
|
|
struct iovec iov;
|
2006-12-15 12:01:50 +00:00
|
|
|
|
2011-05-05 19:49:27 +00:00
|
|
|
iov.iov_base = dbuf;
|
|
|
|
iov.iov_len = len;
|
2006-12-15 12:01:50 +00:00
|
|
|
return (syscall(SYS_sctp_generic_recvmsg, s,
|
2011-05-05 19:49:27 +00:00
|
|
|
&iov, 1, from, fromlen, sinfo, msg_flags));
|
2006-12-15 12:01:50 +00:00
|
|
|
#else
|
|
|
|
ssize_t sz;
|
|
|
|
struct msghdr msg;
|
2011-05-05 19:49:27 +00:00
|
|
|
struct iovec iov;
|
2013-04-10 11:26:30 +00:00
|
|
|
char cmsgbuf[SCTP_CONTROL_VEC_SIZE_RCV];
|
2006-12-15 12:01:50 +00:00
|
|
|
struct cmsghdr *cmsg;
|
|
|
|
|
|
|
|
if (msg_flags == NULL) {
|
|
|
|
errno = EINVAL;
|
|
|
|
return (-1);
|
|
|
|
}
|
2011-05-05 19:49:27 +00:00
|
|
|
iov.iov_base = dbuf;
|
|
|
|
iov.iov_len = len;
|
2006-12-15 12:01:50 +00:00
|
|
|
msg.msg_name = (caddr_t)from;
|
|
|
|
if (fromlen == NULL)
|
|
|
|
msg.msg_namelen = 0;
|
|
|
|
else
|
|
|
|
msg.msg_namelen = *fromlen;
|
2011-05-05 19:49:27 +00:00
|
|
|
msg.msg_iov = &iov;
|
2006-12-15 12:01:50 +00:00
|
|
|
msg.msg_iovlen = 1;
|
2013-04-10 11:26:30 +00:00
|
|
|
msg.msg_control = cmsgbuf;
|
|
|
|
msg.msg_controllen = sizeof(cmsgbuf);
|
2014-12-17 07:47:25 +00:00
|
|
|
msg.msg_flags = 0;
|
2007-06-11 21:05:29 +00:00
|
|
|
sz = recvmsg(s, &msg, *msg_flags);
|
2011-05-05 19:49:27 +00:00
|
|
|
*msg_flags = msg.msg_flags;
|
|
|
|
if (sz <= 0) {
|
2006-12-15 12:01:50 +00:00
|
|
|
return (sz);
|
2011-05-05 19:49:27 +00:00
|
|
|
}
|
|
|
|
if (sinfo) {
|
2006-12-15 12:01:50 +00:00
|
|
|
sinfo->sinfo_assoc_id = 0;
|
2011-05-05 19:49:27 +00:00
|
|
|
}
|
2013-04-10 11:26:30 +00:00
|
|
|
if ((msg.msg_controllen > 0) && (sinfo != NULL)) {
|
2006-12-15 12:01:50 +00:00
|
|
|
/*
|
|
|
|
* parse through and see if we find the sctp_sndrcvinfo (if
|
|
|
|
* the user wants it).
|
|
|
|
*/
|
2013-04-10 11:26:30 +00:00
|
|
|
for (cmsg = CMSG_FIRSTHDR(&msg); cmsg; cmsg = CMSG_NXTHDR(&msg, cmsg)) {
|
|
|
|
if (cmsg->cmsg_level != IPPROTO_SCTP) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (cmsg->cmsg_type == SCTP_SNDRCV) {
|
|
|
|
memcpy(sinfo, CMSG_DATA(cmsg), sizeof(struct sctp_sndrcvinfo));
|
2006-12-15 12:01:50 +00:00
|
|
|
break;
|
|
|
|
}
|
2013-04-10 11:26:30 +00:00
|
|
|
if (cmsg->cmsg_type == SCTP_EXTRCV) {
|
|
|
|
/*
|
|
|
|
* Let's hope that the user provided enough
|
|
|
|
* enough memory. At least he asked for more
|
|
|
|
* information.
|
|
|
|
*/
|
|
|
|
memcpy(sinfo, CMSG_DATA(cmsg), sizeof(struct sctp_extrcvinfo));
|
|
|
|
break;
|
2006-12-15 12:01:50 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return (sz);
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2020-06-18 16:22:09 +00:00
|
|
|
ssize_t
|
2011-06-15 23:50:27 +00:00
|
|
|
sctp_recvv(int sd,
|
|
|
|
const struct iovec *iov,
|
|
|
|
int iovlen,
|
|
|
|
struct sockaddr *from,
|
2020-06-18 16:22:09 +00:00
|
|
|
socklen_t *fromlen,
|
2011-06-15 23:50:27 +00:00
|
|
|
void *info,
|
2020-06-18 16:22:09 +00:00
|
|
|
socklen_t *infolen,
|
2011-06-15 23:50:27 +00:00
|
|
|
unsigned int *infotype,
|
|
|
|
int *flags)
|
|
|
|
{
|
2013-04-10 11:26:30 +00:00
|
|
|
char cmsgbuf[SCTP_CONTROL_VEC_SIZE_RCV];
|
2011-06-15 23:50:27 +00:00
|
|
|
struct msghdr msg;
|
|
|
|
struct cmsghdr *cmsg;
|
2013-04-10 11:26:30 +00:00
|
|
|
ssize_t ret;
|
2011-06-15 23:50:27 +00:00
|
|
|
struct sctp_rcvinfo *rcvinfo;
|
|
|
|
struct sctp_nxtinfo *nxtinfo;
|
2006-12-15 12:01:50 +00:00
|
|
|
|
2014-12-10 14:50:57 +00:00
|
|
|
if (((info != NULL) && (infolen == NULL)) ||
|
2011-06-16 15:36:09 +00:00
|
|
|
((info == NULL) && (infolen != NULL) && (*infolen != 0)) ||
|
|
|
|
((info != NULL) && (infotype == NULL))) {
|
|
|
|
errno = EINVAL;
|
|
|
|
return (-1);
|
|
|
|
}
|
2011-06-15 23:50:27 +00:00
|
|
|
if (infotype) {
|
|
|
|
*infotype = SCTP_RECVV_NOINFO;
|
|
|
|
}
|
|
|
|
msg.msg_name = from;
|
|
|
|
if (fromlen == NULL) {
|
|
|
|
msg.msg_namelen = 0;
|
|
|
|
} else {
|
|
|
|
msg.msg_namelen = *fromlen;
|
|
|
|
}
|
|
|
|
msg.msg_iov = (struct iovec *)iov;
|
|
|
|
msg.msg_iovlen = iovlen;
|
2013-04-10 11:26:30 +00:00
|
|
|
msg.msg_control = cmsgbuf;
|
|
|
|
msg.msg_controllen = sizeof(cmsgbuf);
|
2014-12-17 07:47:25 +00:00
|
|
|
msg.msg_flags = 0;
|
2013-04-10 11:26:30 +00:00
|
|
|
ret = recvmsg(sd, &msg, *flags);
|
2011-06-15 23:50:27 +00:00
|
|
|
*flags = msg.msg_flags;
|
2013-04-10 11:26:30 +00:00
|
|
|
if ((ret > 0) &&
|
2011-06-15 23:50:27 +00:00
|
|
|
(msg.msg_controllen > 0) &&
|
|
|
|
(infotype != NULL) &&
|
|
|
|
(infolen != NULL) &&
|
|
|
|
(*infolen > 0)) {
|
|
|
|
rcvinfo = NULL;
|
|
|
|
nxtinfo = NULL;
|
|
|
|
for (cmsg = CMSG_FIRSTHDR(&msg); cmsg; cmsg = CMSG_NXTHDR(&msg, cmsg)) {
|
|
|
|
if (cmsg->cmsg_level != IPPROTO_SCTP) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (cmsg->cmsg_type == SCTP_RCVINFO) {
|
|
|
|
rcvinfo = (struct sctp_rcvinfo *)CMSG_DATA(cmsg);
|
2013-04-10 11:26:30 +00:00
|
|
|
if (nxtinfo != NULL) {
|
|
|
|
break;
|
|
|
|
} else {
|
|
|
|
continue;
|
|
|
|
}
|
2011-06-15 23:50:27 +00:00
|
|
|
}
|
|
|
|
if (cmsg->cmsg_type == SCTP_NXTINFO) {
|
|
|
|
nxtinfo = (struct sctp_nxtinfo *)CMSG_DATA(cmsg);
|
2013-04-10 11:26:30 +00:00
|
|
|
if (rcvinfo != NULL) {
|
|
|
|
break;
|
|
|
|
} else {
|
|
|
|
continue;
|
|
|
|
}
|
2011-06-15 23:50:27 +00:00
|
|
|
}
|
|
|
|
}
|
2013-04-10 11:26:30 +00:00
|
|
|
if (rcvinfo != NULL) {
|
|
|
|
if ((nxtinfo != NULL) && (*infolen >= sizeof(struct sctp_recvv_rn))) {
|
|
|
|
struct sctp_recvv_rn *rn_info;
|
|
|
|
|
|
|
|
rn_info = (struct sctp_recvv_rn *)info;
|
|
|
|
rn_info->recvv_rcvinfo = *rcvinfo;
|
|
|
|
rn_info->recvv_nxtinfo = *nxtinfo;
|
2020-06-18 16:22:09 +00:00
|
|
|
*infolen = (socklen_t)sizeof(struct sctp_recvv_rn);
|
2013-04-10 11:26:30 +00:00
|
|
|
*infotype = SCTP_RECVV_RN;
|
|
|
|
} else if (*infolen >= sizeof(struct sctp_rcvinfo)) {
|
|
|
|
memcpy(info, rcvinfo, sizeof(struct sctp_rcvinfo));
|
2020-06-18 16:22:09 +00:00
|
|
|
*infolen = (socklen_t)sizeof(struct sctp_rcvinfo);
|
2013-04-10 11:26:30 +00:00
|
|
|
*infotype = SCTP_RECVV_RCVINFO;
|
2011-06-15 23:50:27 +00:00
|
|
|
}
|
2013-04-10 11:26:30 +00:00
|
|
|
} else if (nxtinfo != NULL) {
|
|
|
|
if (*infolen >= sizeof(struct sctp_nxtinfo)) {
|
2011-06-15 23:50:27 +00:00
|
|
|
memcpy(info, nxtinfo, sizeof(struct sctp_nxtinfo));
|
2020-06-18 16:22:09 +00:00
|
|
|
*infolen = (socklen_t)sizeof(struct sctp_nxtinfo);
|
2011-06-15 23:50:27 +00:00
|
|
|
*infotype = SCTP_RECVV_NXTINFO;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2013-04-10 11:26:30 +00:00
|
|
|
return (ret);
|
2011-06-15 23:50:27 +00:00
|
|
|
}
|
2006-12-15 12:01:50 +00:00
|
|
|
|
2011-06-15 23:50:27 +00:00
|
|
|
ssize_t
|
|
|
|
sctp_sendv(int sd,
|
|
|
|
const struct iovec *iov, int iovcnt,
|
|
|
|
struct sockaddr *addrs, int addrcnt,
|
|
|
|
void *info, socklen_t infolen, unsigned int infotype,
|
|
|
|
int flags)
|
2006-12-15 12:01:50 +00:00
|
|
|
{
|
2011-06-15 23:50:27 +00:00
|
|
|
ssize_t ret;
|
|
|
|
int i;
|
2011-06-16 15:36:09 +00:00
|
|
|
socklen_t addr_len;
|
2011-06-15 23:50:27 +00:00
|
|
|
struct msghdr msg;
|
2011-06-16 15:36:09 +00:00
|
|
|
in_port_t port;
|
|
|
|
struct sctp_sendv_spa *spa_info;
|
2011-06-15 23:50:27 +00:00
|
|
|
struct cmsghdr *cmsg;
|
|
|
|
char *cmsgbuf;
|
|
|
|
struct sockaddr *addr;
|
|
|
|
struct sockaddr_in *addr_in;
|
|
|
|
struct sockaddr_in6 *addr_in6;
|
2016-01-24 22:08:15 +00:00
|
|
|
sctp_assoc_t *assoc_id;
|
2011-06-15 23:50:27 +00:00
|
|
|
|
2011-06-16 15:36:09 +00:00
|
|
|
if ((addrcnt < 0) ||
|
|
|
|
(iovcnt < 0) ||
|
2011-06-16 17:30:50 +00:00
|
|
|
((addrs == NULL) && (addrcnt > 0)) ||
|
|
|
|
((addrs != NULL) && (addrcnt == 0)) ||
|
2011-06-16 15:36:09 +00:00
|
|
|
((iov == NULL) && (iovcnt > 0)) ||
|
|
|
|
((iov != NULL) && (iovcnt == 0))) {
|
2011-06-15 23:50:27 +00:00
|
|
|
errno = EINVAL;
|
|
|
|
return (-1);
|
|
|
|
}
|
|
|
|
cmsgbuf = malloc(CMSG_SPACE(sizeof(struct sctp_sndinfo)) +
|
|
|
|
CMSG_SPACE(sizeof(struct sctp_prinfo)) +
|
|
|
|
CMSG_SPACE(sizeof(struct sctp_authinfo)) +
|
2011-12-17 14:55:19 +00:00
|
|
|
(size_t)addrcnt * CMSG_SPACE(sizeof(struct in6_addr)));
|
2011-06-15 23:50:27 +00:00
|
|
|
if (cmsgbuf == NULL) {
|
2012-11-03 13:22:25 +00:00
|
|
|
errno = ENOMEM;
|
2006-12-15 12:01:50 +00:00
|
|
|
return (-1);
|
2011-06-15 23:50:27 +00:00
|
|
|
}
|
2016-01-24 22:08:15 +00:00
|
|
|
assoc_id = NULL;
|
2011-06-15 23:50:27 +00:00
|
|
|
msg.msg_control = cmsgbuf;
|
|
|
|
msg.msg_controllen = 0;
|
|
|
|
cmsg = (struct cmsghdr *)cmsgbuf;
|
|
|
|
switch (infotype) {
|
2011-06-16 15:36:09 +00:00
|
|
|
case SCTP_SENDV_NOINFO:
|
|
|
|
if ((infolen != 0) || (info != NULL)) {
|
|
|
|
free(cmsgbuf);
|
|
|
|
errno = EINVAL;
|
|
|
|
return (-1);
|
|
|
|
}
|
|
|
|
break;
|
2011-06-15 23:50:27 +00:00
|
|
|
case SCTP_SENDV_SNDINFO:
|
2011-06-16 15:36:09 +00:00
|
|
|
if ((info == NULL) || (infolen < sizeof(struct sctp_sndinfo))) {
|
2011-06-15 23:50:27 +00:00
|
|
|
free(cmsgbuf);
|
|
|
|
errno = EINVAL;
|
|
|
|
return (-1);
|
|
|
|
}
|
|
|
|
cmsg->cmsg_level = IPPROTO_SCTP;
|
|
|
|
cmsg->cmsg_type = SCTP_SNDINFO;
|
|
|
|
cmsg->cmsg_len = CMSG_LEN(sizeof(struct sctp_sndinfo));
|
|
|
|
memcpy(CMSG_DATA(cmsg), info, sizeof(struct sctp_sndinfo));
|
|
|
|
msg.msg_controllen += CMSG_SPACE(sizeof(struct sctp_sndinfo));
|
|
|
|
cmsg = (struct cmsghdr *)((caddr_t)cmsg + CMSG_SPACE(sizeof(struct sctp_sndinfo)));
|
2016-01-24 22:08:15 +00:00
|
|
|
assoc_id = &(((struct sctp_sndinfo *)info)->snd_assoc_id);
|
2011-06-15 23:50:27 +00:00
|
|
|
break;
|
|
|
|
case SCTP_SENDV_PRINFO:
|
2011-06-16 15:36:09 +00:00
|
|
|
if ((info == NULL) || (infolen < sizeof(struct sctp_prinfo))) {
|
2011-06-15 23:50:27 +00:00
|
|
|
free(cmsgbuf);
|
|
|
|
errno = EINVAL;
|
|
|
|
return (-1);
|
|
|
|
}
|
|
|
|
cmsg->cmsg_level = IPPROTO_SCTP;
|
|
|
|
cmsg->cmsg_type = SCTP_PRINFO;
|
|
|
|
cmsg->cmsg_len = CMSG_LEN(sizeof(struct sctp_prinfo));
|
|
|
|
memcpy(CMSG_DATA(cmsg), info, sizeof(struct sctp_prinfo));
|
|
|
|
msg.msg_controllen += CMSG_SPACE(sizeof(struct sctp_prinfo));
|
|
|
|
cmsg = (struct cmsghdr *)((caddr_t)cmsg + CMSG_SPACE(sizeof(struct sctp_prinfo)));
|
|
|
|
break;
|
|
|
|
case SCTP_SENDV_AUTHINFO:
|
2011-06-16 15:36:09 +00:00
|
|
|
if ((info == NULL) || (infolen < sizeof(struct sctp_authinfo))) {
|
2011-06-15 23:50:27 +00:00
|
|
|
free(cmsgbuf);
|
|
|
|
errno = EINVAL;
|
|
|
|
return (-1);
|
|
|
|
}
|
|
|
|
cmsg->cmsg_level = IPPROTO_SCTP;
|
|
|
|
cmsg->cmsg_type = SCTP_AUTHINFO;
|
|
|
|
cmsg->cmsg_len = CMSG_LEN(sizeof(struct sctp_authinfo));
|
|
|
|
memcpy(CMSG_DATA(cmsg), info, sizeof(struct sctp_authinfo));
|
|
|
|
msg.msg_controllen += CMSG_SPACE(sizeof(struct sctp_authinfo));
|
|
|
|
cmsg = (struct cmsghdr *)((caddr_t)cmsg + CMSG_SPACE(sizeof(struct sctp_authinfo)));
|
|
|
|
break;
|
|
|
|
case SCTP_SENDV_SPA:
|
2011-06-16 15:36:09 +00:00
|
|
|
if ((info == NULL) || (infolen < sizeof(struct sctp_sendv_spa))) {
|
2011-06-15 23:50:27 +00:00
|
|
|
free(cmsgbuf);
|
|
|
|
errno = EINVAL;
|
|
|
|
return (-1);
|
|
|
|
}
|
|
|
|
spa_info = (struct sctp_sendv_spa *)info;
|
|
|
|
if (spa_info->sendv_flags & SCTP_SEND_SNDINFO_VALID) {
|
|
|
|
cmsg->cmsg_level = IPPROTO_SCTP;
|
|
|
|
cmsg->cmsg_type = SCTP_SNDINFO;
|
|
|
|
cmsg->cmsg_len = CMSG_LEN(sizeof(struct sctp_sndinfo));
|
|
|
|
memcpy(CMSG_DATA(cmsg), &spa_info->sendv_sndinfo, sizeof(struct sctp_sndinfo));
|
|
|
|
msg.msg_controllen += CMSG_SPACE(sizeof(struct sctp_sndinfo));
|
|
|
|
cmsg = (struct cmsghdr *)((caddr_t)cmsg + CMSG_SPACE(sizeof(struct sctp_sndinfo)));
|
2016-01-24 22:08:15 +00:00
|
|
|
assoc_id = &(spa_info->sendv_sndinfo.snd_assoc_id);
|
2011-06-15 23:50:27 +00:00
|
|
|
}
|
|
|
|
if (spa_info->sendv_flags & SCTP_SEND_PRINFO_VALID) {
|
|
|
|
cmsg->cmsg_level = IPPROTO_SCTP;
|
|
|
|
cmsg->cmsg_type = SCTP_PRINFO;
|
|
|
|
cmsg->cmsg_len = CMSG_LEN(sizeof(struct sctp_prinfo));
|
|
|
|
memcpy(CMSG_DATA(cmsg), &spa_info->sendv_prinfo, sizeof(struct sctp_prinfo));
|
|
|
|
msg.msg_controllen += CMSG_SPACE(sizeof(struct sctp_prinfo));
|
|
|
|
cmsg = (struct cmsghdr *)((caddr_t)cmsg + CMSG_SPACE(sizeof(struct sctp_prinfo)));
|
|
|
|
}
|
|
|
|
if (spa_info->sendv_flags & SCTP_SEND_AUTHINFO_VALID) {
|
|
|
|
cmsg->cmsg_level = IPPROTO_SCTP;
|
|
|
|
cmsg->cmsg_type = SCTP_AUTHINFO;
|
|
|
|
cmsg->cmsg_len = CMSG_LEN(sizeof(struct sctp_authinfo));
|
|
|
|
memcpy(CMSG_DATA(cmsg), &spa_info->sendv_authinfo, sizeof(struct sctp_authinfo));
|
|
|
|
msg.msg_controllen += CMSG_SPACE(sizeof(struct sctp_authinfo));
|
|
|
|
cmsg = (struct cmsghdr *)((caddr_t)cmsg + CMSG_SPACE(sizeof(struct sctp_authinfo)));
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
free(cmsgbuf);
|
|
|
|
errno = EINVAL;
|
|
|
|
return (-1);
|
|
|
|
}
|
|
|
|
addr = addrs;
|
2011-06-16 15:36:09 +00:00
|
|
|
msg.msg_name = NULL;
|
|
|
|
msg.msg_namelen = 0;
|
|
|
|
|
|
|
|
for (i = 0; i < addrcnt; i++) {
|
2011-06-15 23:50:27 +00:00
|
|
|
switch (addr->sa_family) {
|
|
|
|
case AF_INET:
|
2020-06-18 16:22:09 +00:00
|
|
|
addr_len = (socklen_t)sizeof(struct sockaddr_in);
|
2011-06-16 15:36:09 +00:00
|
|
|
addr_in = (struct sockaddr_in *)addr;
|
|
|
|
if (addr_in->sin_len != addr_len) {
|
|
|
|
free(cmsgbuf);
|
|
|
|
errno = EINVAL;
|
|
|
|
return (-1);
|
|
|
|
}
|
|
|
|
if (i == 0) {
|
|
|
|
port = addr_in->sin_port;
|
|
|
|
} else {
|
|
|
|
if (port == addr_in->sin_port) {
|
|
|
|
cmsg->cmsg_level = IPPROTO_SCTP;
|
|
|
|
cmsg->cmsg_type = SCTP_DSTADDRV4;
|
|
|
|
cmsg->cmsg_len = CMSG_LEN(sizeof(struct in_addr));
|
|
|
|
memcpy(CMSG_DATA(cmsg), &addr_in->sin_addr, sizeof(struct in_addr));
|
|
|
|
msg.msg_controllen += CMSG_SPACE(sizeof(struct in_addr));
|
|
|
|
cmsg = (struct cmsghdr *)((caddr_t)cmsg + CMSG_SPACE(sizeof(struct in_addr)));
|
|
|
|
} else {
|
|
|
|
free(cmsgbuf);
|
|
|
|
errno = EINVAL;
|
|
|
|
return (-1);
|
|
|
|
}
|
|
|
|
}
|
2011-06-15 23:50:27 +00:00
|
|
|
break;
|
|
|
|
case AF_INET6:
|
2020-06-18 16:22:09 +00:00
|
|
|
addr_len = (socklen_t)sizeof(struct sockaddr_in6);
|
2011-06-16 15:36:09 +00:00
|
|
|
addr_in6 = (struct sockaddr_in6 *)addr;
|
|
|
|
if (addr_in6->sin6_len != addr_len) {
|
|
|
|
free(cmsgbuf);
|
|
|
|
errno = EINVAL;
|
|
|
|
return (-1);
|
|
|
|
}
|
|
|
|
if (i == 0) {
|
|
|
|
port = addr_in6->sin6_port;
|
|
|
|
} else {
|
|
|
|
if (port == addr_in6->sin6_port) {
|
|
|
|
cmsg->cmsg_level = IPPROTO_SCTP;
|
|
|
|
cmsg->cmsg_type = SCTP_DSTADDRV6;
|
|
|
|
cmsg->cmsg_len = CMSG_LEN(sizeof(struct in6_addr));
|
|
|
|
memcpy(CMSG_DATA(cmsg), &addr_in6->sin6_addr, sizeof(struct in6_addr));
|
|
|
|
msg.msg_controllen += CMSG_SPACE(sizeof(struct in6_addr));
|
|
|
|
cmsg = (struct cmsghdr *)((caddr_t)cmsg + CMSG_SPACE(sizeof(struct in6_addr)));
|
|
|
|
} else {
|
|
|
|
free(cmsgbuf);
|
|
|
|
errno = EINVAL;
|
|
|
|
return (-1);
|
|
|
|
}
|
|
|
|
}
|
2011-06-15 23:50:27 +00:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
free(cmsgbuf);
|
|
|
|
errno = EINVAL;
|
|
|
|
return (-1);
|
|
|
|
}
|
2011-06-16 15:36:09 +00:00
|
|
|
if (i == 0) {
|
|
|
|
msg.msg_name = addr;
|
|
|
|
msg.msg_namelen = addr_len;
|
2011-06-15 23:50:27 +00:00
|
|
|
}
|
2011-06-16 15:36:09 +00:00
|
|
|
addr = (struct sockaddr *)((caddr_t)addr + addr_len);
|
|
|
|
}
|
|
|
|
if (msg.msg_controllen == 0) {
|
|
|
|
msg.msg_control = NULL;
|
2006-12-15 12:01:50 +00:00
|
|
|
}
|
2011-06-15 23:50:27 +00:00
|
|
|
msg.msg_iov = (struct iovec *)iov;
|
|
|
|
msg.msg_iovlen = iovcnt;
|
|
|
|
msg.msg_flags = 0;
|
|
|
|
ret = sendmsg(sd, &msg, flags);
|
|
|
|
free(cmsgbuf);
|
2016-01-24 22:08:15 +00:00
|
|
|
if ((ret >= 0) && (addrs != NULL) && (assoc_id != NULL)) {
|
|
|
|
*assoc_id = sctp_getassocid(sd, addrs);
|
|
|
|
}
|
2011-06-15 23:50:27 +00:00
|
|
|
return (ret);
|
2006-12-15 12:01:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#if !defined(SYS_sctp_peeloff) && !defined(HAVE_SCTP_PEELOFF_SOCKOPT)
|
|
|
|
|
|
|
|
int
|
|
|
|
sctp_peeloff(int sd, sctp_assoc_t assoc_id)
|
|
|
|
{
|
|
|
|
/* NOT supported, return invalid sd */
|
|
|
|
errno = ENOTSUP;
|
|
|
|
return (-1);
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|
|
|
|
#if defined(SYS_sctp_peeloff) && !defined(HAVE_SCTP_PEELOFF_SOCKOPT)
|
|
|
|
int
|
|
|
|
sctp_peeloff(int sd, sctp_assoc_t assoc_id)
|
|
|
|
{
|
|
|
|
return (syscall(SYS_sctp_peeloff, sd, assoc_id));
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|
2007-02-22 12:42:43 +00:00
|
|
|
|
2007-02-22 13:39:57 +00:00
|
|
|
#undef SCTP_CONTROL_VEC_SIZE_RCV
|