2006-11-03 15:23:16 +00:00
|
|
|
/*-
|
2007-05-08 17:01:12 +00:00
|
|
|
* Copyright (c) 2001-2007, by Cisco Systems, Inc. All rights reserved.
|
2012-05-23 11:26:28 +00:00
|
|
|
* Copyright (c) 2008-2012, by Randall Stewart. All rights reserved.
|
|
|
|
* Copyright (c) 2008-2012, by Michael Tuexen. All rights reserved.
|
2006-11-03 15:23:16 +00:00
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions are met:
|
|
|
|
*
|
|
|
|
* a) Redistributions of source code must retain the above copyright notice,
|
2011-12-17 19:21:40 +00:00
|
|
|
* this list of conditions and the following disclaimer.
|
2006-11-03 15:23:16 +00:00
|
|
|
*
|
|
|
|
* b) Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in
|
2011-12-17 19:21:40 +00:00
|
|
|
* the documentation and/or other materials provided with the distribution.
|
2006-11-03 15:23:16 +00:00
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*/
|
2007-12-10 16:03:40 +00:00
|
|
|
|
2006-11-03 17:21:53 +00:00
|
|
|
#include <sys/cdefs.h>
|
2006-11-03 15:23:16 +00:00
|
|
|
__FBSDID("$FreeBSD$");
|
2007-01-18 09:58:43 +00:00
|
|
|
|
2006-11-03 15:23:16 +00:00
|
|
|
#include <netinet/sctp_os.h>
|
2012-07-15 20:16:17 +00:00
|
|
|
#ifdef INET6
|
2007-01-18 09:58:43 +00:00
|
|
|
#include <sys/proc.h>
|
2006-11-03 15:23:16 +00:00
|
|
|
#include <netinet/sctp_pcb.h>
|
|
|
|
#include <netinet/sctp_header.h>
|
|
|
|
#include <netinet/sctp_var.h>
|
2007-04-14 09:44:09 +00:00
|
|
|
#include <netinet6/sctp6_var.h>
|
2007-03-15 11:27:14 +00:00
|
|
|
#include <netinet/sctp_sysctl.h>
|
2006-11-03 15:23:16 +00:00
|
|
|
#include <netinet/sctp_output.h>
|
2007-01-18 09:58:43 +00:00
|
|
|
#include <netinet/sctp_uio.h>
|
|
|
|
#include <netinet/sctp_asconf.h>
|
|
|
|
#include <netinet/sctputil.h>
|
|
|
|
#include <netinet/sctp_indata.h>
|
|
|
|
#include <netinet/sctp_timer.h>
|
|
|
|
#include <netinet/sctp_auth.h>
|
2007-04-14 09:44:09 +00:00
|
|
|
#include <netinet/sctp_input.h>
|
|
|
|
#include <netinet/sctp_output.h>
|
2007-05-29 09:29:03 +00:00
|
|
|
#include <netinet/sctp_bsd_addr.h>
|
2009-02-03 11:04:03 +00:00
|
|
|
#include <netinet/sctp_crc32.h>
|
2015-07-25 18:26:09 +00:00
|
|
|
#include <netinet/icmp6.h>
|
2008-06-14 07:58:05 +00:00
|
|
|
#include <netinet/udp.h>
|
2006-11-03 15:23:16 +00:00
|
|
|
|
2007-07-03 12:13:45 +00:00
|
|
|
#ifdef IPSEC
|
2007-07-01 11:41:27 +00:00
|
|
|
#include <netipsec/ipsec.h>
|
|
|
|
#include <netipsec/ipsec6.h>
|
2007-07-14 09:36:28 +00:00
|
|
|
#endif /* IPSEC */
|
2006-11-03 15:23:16 +00:00
|
|
|
|
|
|
|
extern struct protosw inetsw[];
|
|
|
|
|
|
|
|
int
|
2012-11-17 20:04:04 +00:00
|
|
|
sctp6_input_with_port(struct mbuf **i_pak, int *offp, uint16_t port)
|
2006-11-03 15:23:16 +00:00
|
|
|
{
|
2006-12-29 20:21:42 +00:00
|
|
|
struct mbuf *m;
|
2012-06-25 19:13:43 +00:00
|
|
|
int iphlen;
|
2012-07-02 16:44:09 +00:00
|
|
|
uint32_t vrf_id;
|
2012-06-25 19:13:43 +00:00
|
|
|
uint8_t ecn_bits;
|
2012-06-28 16:01:08 +00:00
|
|
|
struct sockaddr_in6 src, dst;
|
2006-11-03 15:23:16 +00:00
|
|
|
struct ip6_hdr *ip6;
|
|
|
|
struct sctphdr *sh;
|
|
|
|
struct sctp_chunkhdr *ch;
|
2012-06-25 19:13:43 +00:00
|
|
|
int length, offset;
|
2010-08-29 18:50:30 +00:00
|
|
|
|
|
|
|
#if !defined(SCTP_WITH_NO_CSUM)
|
2012-07-02 16:44:09 +00:00
|
|
|
uint8_t compute_crc;
|
2010-08-29 18:50:30 +00:00
|
|
|
|
|
|
|
#endif
|
2012-07-02 16:44:09 +00:00
|
|
|
uint32_t mflowid;
|
2014-12-04 21:17:50 +00:00
|
|
|
uint8_t mflowtype;
|
2015-06-17 15:20:14 +00:00
|
|
|
uint16_t fibnum;
|
2006-11-03 15:23:16 +00:00
|
|
|
|
2012-06-25 19:13:43 +00:00
|
|
|
iphlen = *offp;
|
2007-05-08 00:21:05 +00:00
|
|
|
if (SCTP_GET_PKT_VRFID(*i_pak, vrf_id)) {
|
|
|
|
SCTP_RELEASE_PKT(*i_pak);
|
2012-06-25 19:13:43 +00:00
|
|
|
return (IPPROTO_DONE);
|
2007-05-08 00:21:05 +00:00
|
|
|
}
|
2007-04-14 09:44:09 +00:00
|
|
|
m = SCTP_HEADER_TO_CHAIN(*i_pak);
|
2012-06-25 19:13:43 +00:00
|
|
|
#ifdef SCTP_MBUF_LOGGING
|
|
|
|
/* Log in any input mbufs */
|
|
|
|
if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_MBUF_LOGGING_ENABLE) {
|
2015-01-10 20:49:57 +00:00
|
|
|
sctp_log_mbc(m, SCTP_MBUF_INPUT);
|
2012-06-25 19:13:43 +00:00
|
|
|
}
|
|
|
|
#endif
|
2012-06-24 21:25:54 +00:00
|
|
|
#ifdef SCTP_PACKET_LOGGING
|
|
|
|
if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_LAST_PACKET_TRACING) {
|
|
|
|
sctp_packet_log(m);
|
|
|
|
}
|
2007-05-29 09:29:03 +00:00
|
|
|
#endif
|
2012-07-02 16:44:09 +00:00
|
|
|
SCTPDBG(SCTP_DEBUG_CRCOFFLOAD,
|
2013-08-25 12:44:03 +00:00
|
|
|
"sctp6_input(): Packet of length %d received on %s with csum_flags 0x%b.\n",
|
2012-07-02 16:44:09 +00:00
|
|
|
m->m_pkthdr.len,
|
|
|
|
if_name(m->m_pkthdr.rcvif),
|
2013-08-25 12:44:03 +00:00
|
|
|
(int)m->m_pkthdr.csum_flags, CSUM_BITS);
|
2014-12-04 21:17:50 +00:00
|
|
|
mflowid = m->m_pkthdr.flowid;
|
|
|
|
mflowtype = M_HASHTYPE_GET(m);
|
2015-06-17 15:20:14 +00:00
|
|
|
fibnum = M_GETFIB(m);
|
2012-06-25 19:13:43 +00:00
|
|
|
SCTP_STAT_INCR(sctps_recvpackets);
|
|
|
|
SCTP_STAT_INCR_COUNTER64(sctps_inpackets);
|
|
|
|
/* Get IP, SCTP, and first chunk header together in the first mbuf. */
|
|
|
|
offset = iphlen + sizeof(struct sctphdr) + sizeof(struct sctp_chunkhdr);
|
2012-07-02 16:44:09 +00:00
|
|
|
ip6 = mtod(m, struct ip6_hdr *);
|
2012-06-25 19:13:43 +00:00
|
|
|
IP6_EXTHDR_GET(sh, struct sctphdr *, m, iphlen,
|
|
|
|
(int)(sizeof(struct sctphdr) + sizeof(struct sctp_chunkhdr)));
|
2006-11-03 15:23:16 +00:00
|
|
|
if (sh == NULL) {
|
|
|
|
SCTP_STAT_INCR(sctps_hdrops);
|
2011-12-27 10:16:24 +00:00
|
|
|
return (IPPROTO_DONE);
|
2006-11-03 15:23:16 +00:00
|
|
|
}
|
|
|
|
ch = (struct sctp_chunkhdr *)((caddr_t)sh + sizeof(struct sctphdr));
|
2012-06-25 19:13:43 +00:00
|
|
|
offset -= sizeof(struct sctp_chunkhdr);
|
2012-06-28 16:01:08 +00:00
|
|
|
memset(&src, 0, sizeof(struct sockaddr_in6));
|
|
|
|
src.sin6_family = AF_INET6;
|
|
|
|
src.sin6_len = sizeof(struct sockaddr_in6);
|
|
|
|
src.sin6_port = sh->src_port;
|
|
|
|
src.sin6_addr = ip6->ip6_src;
|
|
|
|
if (in6_setscope(&src.sin6_addr, m->m_pkthdr.rcvif, NULL) != 0) {
|
2012-07-02 16:44:09 +00:00
|
|
|
goto out;
|
2012-06-28 16:01:08 +00:00
|
|
|
}
|
|
|
|
memset(&dst, 0, sizeof(struct sockaddr_in6));
|
|
|
|
dst.sin6_family = AF_INET6;
|
|
|
|
dst.sin6_len = sizeof(struct sockaddr_in6);
|
|
|
|
dst.sin6_port = sh->dest_port;
|
|
|
|
dst.sin6_addr = ip6->ip6_dst;
|
|
|
|
if (in6_setscope(&dst.sin6_addr, m->m_pkthdr.rcvif, NULL) != 0) {
|
2012-07-02 16:44:09 +00:00
|
|
|
goto out;
|
2012-06-28 16:01:08 +00:00
|
|
|
}
|
2012-06-25 19:13:43 +00:00
|
|
|
length = ntohs(ip6->ip6_plen) + iphlen;
|
|
|
|
/* Validate mbuf chain length with IP payload length. */
|
2012-07-02 16:44:09 +00:00
|
|
|
if (SCTP_HEADER_LEN(m) != length) {
|
2012-06-25 19:13:43 +00:00
|
|
|
SCTPDBG(SCTP_DEBUG_INPUT1,
|
2012-07-02 16:44:09 +00:00
|
|
|
"sctp6_input() length:%d reported length:%d\n", length, SCTP_HEADER_LEN(m));
|
2012-06-25 19:13:43 +00:00
|
|
|
SCTP_STAT_INCR(sctps_hdrops);
|
2012-07-02 16:44:09 +00:00
|
|
|
goto out;
|
2006-11-03 15:23:16 +00:00
|
|
|
}
|
2012-06-25 19:13:43 +00:00
|
|
|
if (IN6_IS_ADDR_MULTICAST(&ip6->ip6_dst)) {
|
2012-07-02 16:44:09 +00:00
|
|
|
goto out;
|
2012-06-25 19:13:43 +00:00
|
|
|
}
|
2012-07-02 16:44:09 +00:00
|
|
|
ecn_bits = ((ntohl(ip6->ip6_flow) >> 20) & 0x000000ff);
|
2010-08-29 18:50:30 +00:00
|
|
|
#if defined(SCTP_WITH_NO_CSUM)
|
|
|
|
SCTP_STAT_INCR(sctps_recvnocrc);
|
|
|
|
#else
|
2009-02-03 11:04:03 +00:00
|
|
|
if (m->m_pkthdr.csum_flags & CSUM_SCTP_VALID) {
|
|
|
|
SCTP_STAT_INCR(sctps_recvhwcrc);
|
2012-07-02 16:44:09 +00:00
|
|
|
compute_crc = 0;
|
|
|
|
} else {
|
|
|
|
SCTP_STAT_INCR(sctps_recvswcrc);
|
|
|
|
compute_crc = 1;
|
2006-11-05 13:25:18 +00:00
|
|
|
}
|
2012-06-25 19:13:43 +00:00
|
|
|
#endif
|
2012-06-28 16:01:08 +00:00
|
|
|
sctp_common_input_processing(&m, iphlen, offset, length,
|
|
|
|
(struct sockaddr *)&src,
|
|
|
|
(struct sockaddr *)&dst,
|
2012-07-02 16:44:09 +00:00
|
|
|
sh, ch,
|
|
|
|
#if !defined(SCTP_WITH_NO_CSUM)
|
|
|
|
compute_crc,
|
|
|
|
#endif
|
|
|
|
ecn_bits,
|
2015-06-17 15:20:14 +00:00
|
|
|
mflowtype, mflowid, fibnum,
|
2012-06-14 06:54:48 +00:00
|
|
|
vrf_id, port);
|
2012-07-02 16:44:09 +00:00
|
|
|
out:
|
2012-06-25 19:13:43 +00:00
|
|
|
if (m) {
|
2007-05-08 00:21:05 +00:00
|
|
|
sctp_m_freem(m);
|
2012-06-25 19:13:43 +00:00
|
|
|
}
|
2011-12-27 10:16:24 +00:00
|
|
|
return (IPPROTO_DONE);
|
2006-11-03 15:23:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-11-17 20:04:04 +00:00
|
|
|
int
|
|
|
|
sctp6_input(struct mbuf **i_pak, int *offp, int proto SCTP_UNUSED)
|
|
|
|
{
|
|
|
|
return (sctp6_input_with_port(i_pak, offp, 0));
|
|
|
|
}
|
|
|
|
|
2007-09-13 10:36:43 +00:00
|
|
|
void
|
2007-09-08 17:48:46 +00:00
|
|
|
sctp6_notify(struct sctp_inpcb *inp,
|
|
|
|
struct sctp_tcb *stcb,
|
2016-04-16 21:34:49 +00:00
|
|
|
struct sctp_nets *net,
|
|
|
|
uint8_t icmp6_type,
|
|
|
|
uint8_t icmp6_code,
|
|
|
|
uint16_t next_mtu)
|
2007-09-08 17:48:46 +00:00
|
|
|
{
|
2012-06-25 17:15:09 +00:00
|
|
|
#if defined(__APPLE__) || defined(SCTP_SO_LOCK_TESTING)
|
2007-09-08 17:48:46 +00:00
|
|
|
struct socket *so;
|
|
|
|
|
|
|
|
#endif
|
2016-04-16 21:34:49 +00:00
|
|
|
int timer_stopped;
|
|
|
|
|
|
|
|
switch (icmp6_type) {
|
|
|
|
case ICMP6_DST_UNREACH:
|
|
|
|
if ((icmp6_code == ICMP6_DST_UNREACH_NOROUTE) ||
|
|
|
|
(icmp6_code == ICMP6_DST_UNREACH_ADMIN) ||
|
|
|
|
(icmp6_code == ICMP6_DST_UNREACH_BEYONDSCOPE) ||
|
|
|
|
(icmp6_code == ICMP6_DST_UNREACH_ADDR)) {
|
|
|
|
/* Mark the net unreachable. */
|
|
|
|
if (net->dest_state & SCTP_ADDR_REACHABLE) {
|
|
|
|
/* Ok that destination is not reachable */
|
|
|
|
net->dest_state &= ~SCTP_ADDR_REACHABLE;
|
|
|
|
net->dest_state &= ~SCTP_ADDR_PF;
|
|
|
|
sctp_ulp_notify(SCTP_NOTIFY_INTERFACE_DOWN,
|
|
|
|
stcb, 0, (void *)net, SCTP_SO_NOT_LOCKED);
|
|
|
|
}
|
2007-09-08 17:48:46 +00:00
|
|
|
}
|
|
|
|
SCTP_TCB_UNLOCK(stcb);
|
2016-04-16 21:34:49 +00:00
|
|
|
break;
|
|
|
|
case ICMP6_PARAM_PROB:
|
|
|
|
/* Treat it like an ABORT. */
|
|
|
|
if (icmp6_code == ICMP6_PARAMPROB_NEXTHEADER) {
|
|
|
|
sctp_abort_notification(stcb, 1, 0, NULL, SCTP_SO_NOT_LOCKED);
|
2012-06-25 17:15:09 +00:00
|
|
|
#if defined(__APPLE__) || defined(SCTP_SO_LOCK_TESTING)
|
2016-04-16 21:34:49 +00:00
|
|
|
so = SCTP_INP_SO(inp);
|
|
|
|
atomic_add_int(&stcb->asoc.refcnt, 1);
|
|
|
|
SCTP_TCB_UNLOCK(stcb);
|
|
|
|
SCTP_SOCKET_LOCK(so, 1);
|
|
|
|
SCTP_TCB_LOCK(stcb);
|
|
|
|
atomic_subtract_int(&stcb->asoc.refcnt, 1);
|
2007-09-08 17:48:46 +00:00
|
|
|
#endif
|
2016-04-16 21:34:49 +00:00
|
|
|
(void)sctp_free_assoc(inp, stcb, SCTP_NORMAL_PROC,
|
|
|
|
SCTP_FROM_SCTP_USRREQ + SCTP_LOC_2);
|
2012-06-25 17:15:09 +00:00
|
|
|
#if defined(__APPLE__) || defined(SCTP_SO_LOCK_TESTING)
|
2016-04-16 21:34:49 +00:00
|
|
|
SCTP_SOCKET_UNLOCK(so, 1);
|
2007-09-08 17:48:46 +00:00
|
|
|
#endif
|
2016-04-16 21:34:49 +00:00
|
|
|
} else {
|
|
|
|
SCTP_TCB_UNLOCK(stcb);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case ICMP6_PACKET_TOO_BIG:
|
|
|
|
if (SCTP_OS_TIMER_PENDING(&net->pmtu_timer.timer)) {
|
|
|
|
timer_stopped = 1;
|
|
|
|
sctp_timer_stop(SCTP_TIMER_TYPE_PATHMTURAISE, inp, stcb, net,
|
|
|
|
SCTP_FROM_SCTP_USRREQ + SCTP_LOC_1);
|
|
|
|
} else {
|
|
|
|
timer_stopped = 0;
|
|
|
|
}
|
|
|
|
/* Update the path MTU. */
|
|
|
|
if (net->mtu > next_mtu) {
|
|
|
|
net->mtu = next_mtu;
|
|
|
|
if (net->port) {
|
|
|
|
net->mtu -= sizeof(struct udphdr);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
/* Update the association MTU */
|
|
|
|
if (stcb->asoc.smallest_mtu > next_mtu) {
|
|
|
|
sctp_pathmtu_adjustment(stcb, next_mtu);
|
|
|
|
}
|
|
|
|
/* Finally, start the PMTU timer if it was running before. */
|
|
|
|
if (timer_stopped) {
|
|
|
|
sctp_timer_start(SCTP_TIMER_TYPE_PATHMTURAISE, inp, stcb, net);
|
|
|
|
}
|
|
|
|
SCTP_TCB_UNLOCK(stcb);
|
|
|
|
break;
|
|
|
|
default:
|
2007-09-08 17:48:46 +00:00
|
|
|
SCTP_TCB_UNLOCK(stcb);
|
2016-04-16 21:34:49 +00:00
|
|
|
break;
|
2007-09-08 17:48:46 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-11-03 15:23:16 +00:00
|
|
|
void
|
2007-07-05 16:23:49 +00:00
|
|
|
sctp6_ctlinput(int cmd, struct sockaddr *pktdst, void *d)
|
2006-11-03 15:23:16 +00:00
|
|
|
{
|
2016-04-16 21:34:49 +00:00
|
|
|
struct ip6ctlparam *ip6cp;
|
|
|
|
struct sctp_inpcb *inp;
|
|
|
|
struct sctp_tcb *stcb;
|
|
|
|
struct sctp_nets *net;
|
2006-11-03 15:23:16 +00:00
|
|
|
struct sctphdr sh;
|
2016-04-16 21:34:49 +00:00
|
|
|
struct sockaddr_in6 src, dst;
|
2007-03-15 11:27:14 +00:00
|
|
|
|
2006-11-03 15:23:16 +00:00
|
|
|
if (pktdst->sa_family != AF_INET6 ||
|
2016-04-16 21:34:49 +00:00
|
|
|
pktdst->sa_len != sizeof(struct sockaddr_in6)) {
|
2006-11-03 15:23:16 +00:00
|
|
|
return;
|
2016-04-16 21:34:49 +00:00
|
|
|
}
|
|
|
|
if ((unsigned)cmd >= PRC_NCMDS) {
|
2006-11-03 15:23:16 +00:00
|
|
|
return;
|
2016-04-16 21:34:49 +00:00
|
|
|
}
|
2006-11-03 15:23:16 +00:00
|
|
|
if (PRC_IS_REDIRECT(cmd)) {
|
|
|
|
d = NULL;
|
|
|
|
} else if (inet6ctlerrmap[cmd] == 0) {
|
|
|
|
return;
|
|
|
|
}
|
2016-04-16 21:34:49 +00:00
|
|
|
/* If the parameter is from icmp6, decode it. */
|
2006-11-03 15:23:16 +00:00
|
|
|
if (d != NULL) {
|
|
|
|
ip6cp = (struct ip6ctlparam *)d;
|
|
|
|
} else {
|
|
|
|
ip6cp = (struct ip6ctlparam *)NULL;
|
|
|
|
}
|
|
|
|
|
2016-04-16 21:34:49 +00:00
|
|
|
if (ip6cp != NULL) {
|
2006-11-03 15:23:16 +00:00
|
|
|
/*
|
|
|
|
* XXX: We assume that when IPV6 is non NULL, M and OFF are
|
|
|
|
* valid.
|
|
|
|
*/
|
2016-04-16 21:34:49 +00:00
|
|
|
if (ip6cp->ip6c_m == NULL) {
|
2006-11-03 15:23:16 +00:00
|
|
|
return;
|
2016-04-16 21:34:49 +00:00
|
|
|
}
|
|
|
|
/*
|
|
|
|
* Check if we can safely examine the ports and the
|
|
|
|
* verification tag of the SCTP common header.
|
|
|
|
*/
|
|
|
|
if (ip6cp->ip6c_m->m_pkthdr.len <
|
2016-04-18 20:16:41 +00:00
|
|
|
(int32_t) (ip6cp->ip6c_off + offsetof(struct sctphdr, checksum))) {
|
2016-01-14 10:11:10 +00:00
|
|
|
return;
|
2016-04-16 21:34:49 +00:00
|
|
|
}
|
|
|
|
/* Copy out the port numbers and the verification tag. */
|
2006-11-03 15:23:16 +00:00
|
|
|
bzero(&sh, sizeof(sh));
|
2016-04-16 21:34:49 +00:00
|
|
|
m_copydata(ip6cp->ip6c_m,
|
|
|
|
ip6cp->ip6c_off,
|
|
|
|
sizeof(uint16_t) + sizeof(uint16_t) + sizeof(uint32_t),
|
|
|
|
(caddr_t)&sh);
|
|
|
|
memset(&src, 0, sizeof(struct sockaddr_in6));
|
|
|
|
src.sin6_family = AF_INET6;
|
|
|
|
src.sin6_len = sizeof(struct sockaddr_in6);
|
|
|
|
src.sin6_port = sh.src_port;
|
|
|
|
src.sin6_addr = ip6cp->ip6c_ip6->ip6_src;
|
|
|
|
if (in6_setscope(&src.sin6_addr, ip6cp->ip6c_m->m_pkthdr.rcvif, NULL) != 0) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
memset(&dst, 0, sizeof(struct sockaddr_in6));
|
|
|
|
dst.sin6_family = AF_INET6;
|
|
|
|
dst.sin6_len = sizeof(struct sockaddr_in6);
|
|
|
|
dst.sin6_port = sh.dest_port;
|
|
|
|
dst.sin6_addr = ip6cp->ip6c_ip6->ip6_dst;
|
|
|
|
if (in6_setscope(&dst.sin6_addr, ip6cp->ip6c_m->m_pkthdr.rcvif, NULL) != 0) {
|
|
|
|
return;
|
|
|
|
}
|
2006-11-03 15:23:16 +00:00
|
|
|
inp = NULL;
|
|
|
|
net = NULL;
|
2016-04-16 21:34:49 +00:00
|
|
|
stcb = sctp_findassociation_addr_sa((struct sockaddr *)&dst,
|
|
|
|
(struct sockaddr *)&src,
|
|
|
|
&inp, &net, 1, SCTP_DEFAULT_VRFID);
|
|
|
|
if ((stcb != NULL) &&
|
|
|
|
(net != NULL) &&
|
|
|
|
(inp != NULL) &&
|
|
|
|
(inp->sctp_socket != NULL)) {
|
|
|
|
/* Check the verification tag */
|
|
|
|
if (ntohl(sh.v_tag) != 0) {
|
|
|
|
/*
|
|
|
|
* This must be the verification tag used
|
|
|
|
* for sending out packets. We don't
|
|
|
|
* consider packets reflecting the
|
|
|
|
* verification tag.
|
|
|
|
*/
|
|
|
|
if (ntohl(sh.v_tag) != stcb->asoc.peer_vtag) {
|
|
|
|
SCTP_TCB_UNLOCK(stcb);
|
|
|
|
return;
|
|
|
|
}
|
2006-11-03 15:23:16 +00:00
|
|
|
} else {
|
2016-04-16 21:34:49 +00:00
|
|
|
if (ip6cp->ip6c_m->m_pkthdr.len >=
|
|
|
|
ip6cp->ip6c_off + sizeof(struct sctphdr) +
|
|
|
|
sizeof(struct sctp_chunkhdr) +
|
|
|
|
offsetof(struct sctp_init, a_rwnd)) {
|
|
|
|
/*
|
|
|
|
* In this case we can check if we
|
|
|
|
* got an INIT chunk and if the
|
|
|
|
* initiate tag matches.
|
|
|
|
*/
|
|
|
|
uint32_t initiate_tag;
|
|
|
|
uint8_t chunk_type;
|
|
|
|
|
|
|
|
m_copydata(ip6cp->ip6c_m,
|
|
|
|
ip6cp->ip6c_off +
|
|
|
|
sizeof(struct sctphdr),
|
|
|
|
sizeof(uint8_t),
|
|
|
|
(caddr_t)&chunk_type);
|
|
|
|
m_copydata(ip6cp->ip6c_m,
|
|
|
|
ip6cp->ip6c_off +
|
|
|
|
sizeof(struct sctphdr) +
|
|
|
|
sizeof(struct sctp_chunkhdr),
|
|
|
|
sizeof(uint32_t),
|
|
|
|
(caddr_t)&initiate_tag);
|
|
|
|
if ((chunk_type != SCTP_INITIATION) ||
|
|
|
|
(ntohl(initiate_tag) != stcb->asoc.my_vtag)) {
|
|
|
|
SCTP_TCB_UNLOCK(stcb);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
SCTP_TCB_UNLOCK(stcb);
|
|
|
|
return;
|
|
|
|
}
|
2006-11-03 15:23:16 +00:00
|
|
|
}
|
2016-04-16 21:34:49 +00:00
|
|
|
sctp6_notify(inp, stcb, net,
|
|
|
|
ip6cp->ip6c_icmp6->icmp6_type,
|
|
|
|
ip6cp->ip6c_icmp6->icmp6_code,
|
|
|
|
(uint16_t) ntohl(ip6cp->ip6c_icmp6->icmp6_mtu));
|
2006-11-03 15:23:16 +00:00
|
|
|
} else {
|
2016-04-16 21:34:49 +00:00
|
|
|
if ((stcb == NULL) && (inp != NULL)) {
|
2006-11-03 15:23:16 +00:00
|
|
|
/* reduce inp's ref-count */
|
|
|
|
SCTP_INP_WLOCK(inp);
|
|
|
|
SCTP_INP_DECR_REF(inp);
|
|
|
|
SCTP_INP_WUNLOCK(inp);
|
|
|
|
}
|
2016-04-16 21:34:49 +00:00
|
|
|
if (stcb) {
|
2006-11-03 15:23:16 +00:00
|
|
|
SCTP_TCB_UNLOCK(stcb);
|
2016-04-16 21:34:49 +00:00
|
|
|
}
|
2006-11-03 15:23:16 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* this routine can probably be collasped into the one in sctp_userreq.c
|
|
|
|
* since they do the same thing and now we lookup with a sockaddr
|
|
|
|
*/
|
|
|
|
static int
|
|
|
|
sctp6_getcred(SYSCTL_HANDLER_ARGS)
|
|
|
|
{
|
2006-11-08 00:21:13 +00:00
|
|
|
struct xucred xuc;
|
2006-11-03 15:23:16 +00:00
|
|
|
struct sockaddr_in6 addrs[2];
|
|
|
|
struct sctp_inpcb *inp;
|
|
|
|
struct sctp_nets *net;
|
|
|
|
struct sctp_tcb *stcb;
|
2006-11-08 00:21:13 +00:00
|
|
|
int error;
|
2007-03-15 11:27:14 +00:00
|
|
|
uint32_t vrf_id;
|
|
|
|
|
|
|
|
vrf_id = SCTP_DEFAULT_VRFID;
|
2006-11-03 15:23:16 +00:00
|
|
|
|
2007-06-12 00:12:01 +00:00
|
|
|
error = priv_check(req->td, PRIV_NETINET_GETCRED);
|
2006-11-03 15:23:16 +00:00
|
|
|
if (error)
|
|
|
|
return (error);
|
|
|
|
|
2007-08-24 00:53:53 +00:00
|
|
|
if (req->newlen != sizeof(addrs)) {
|
|
|
|
SCTP_LTRACE_ERR_RET(NULL, NULL, NULL, SCTP_FROM_SCTP6_USRREQ, EINVAL);
|
2006-11-03 15:23:16 +00:00
|
|
|
return (EINVAL);
|
2007-08-24 00:53:53 +00:00
|
|
|
}
|
|
|
|
if (req->oldlen != sizeof(struct ucred)) {
|
|
|
|
SCTP_LTRACE_ERR_RET(NULL, NULL, NULL, SCTP_FROM_SCTP6_USRREQ, EINVAL);
|
2006-11-03 15:23:16 +00:00
|
|
|
return (EINVAL);
|
2007-08-24 00:53:53 +00:00
|
|
|
}
|
2006-11-03 15:23:16 +00:00
|
|
|
error = SYSCTL_IN(req, addrs, sizeof(addrs));
|
|
|
|
if (error)
|
|
|
|
return (error);
|
|
|
|
|
2012-06-28 16:01:08 +00:00
|
|
|
stcb = sctp_findassociation_addr_sa(sin6tosa(&addrs[1]),
|
|
|
|
sin6tosa(&addrs[0]),
|
2007-03-15 11:27:14 +00:00
|
|
|
&inp, &net, 1, vrf_id);
|
2006-11-03 15:23:16 +00:00
|
|
|
if (stcb == NULL || inp == NULL || inp->sctp_socket == NULL) {
|
2006-11-08 00:21:13 +00:00
|
|
|
if ((inp != NULL) && (stcb == NULL)) {
|
|
|
|
/* reduce ref-count */
|
2006-11-03 15:23:16 +00:00
|
|
|
SCTP_INP_WLOCK(inp);
|
|
|
|
SCTP_INP_DECR_REF(inp);
|
2006-11-08 00:21:13 +00:00
|
|
|
goto cred_can_cont;
|
2006-11-03 15:23:16 +00:00
|
|
|
}
|
2007-08-24 00:53:53 +00:00
|
|
|
SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP6_USRREQ, ENOENT);
|
2006-11-08 00:21:13 +00:00
|
|
|
error = ENOENT;
|
2006-11-03 15:23:16 +00:00
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
SCTP_TCB_UNLOCK(stcb);
|
2006-11-08 00:21:13 +00:00
|
|
|
/*
|
|
|
|
* We use the write lock here, only since in the error leg we need
|
|
|
|
* it. If we used RLOCK, then we would have to
|
|
|
|
* wlock/decr/unlock/rlock. Which in theory could create a hole.
|
|
|
|
* Better to use higher wlock.
|
|
|
|
*/
|
|
|
|
SCTP_INP_WLOCK(inp);
|
|
|
|
cred_can_cont:
|
|
|
|
error = cr_canseesocket(req->td->td_ucred, inp->sctp_socket);
|
|
|
|
if (error) {
|
|
|
|
SCTP_INP_WUNLOCK(inp);
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
cru2x(inp->sctp_socket->so_cred, &xuc);
|
|
|
|
SCTP_INP_WUNLOCK(inp);
|
|
|
|
error = SYSCTL_OUT(req, &xuc, sizeof(struct xucred));
|
2006-11-03 15:23:16 +00:00
|
|
|
out:
|
|
|
|
return (error);
|
|
|
|
}
|
|
|
|
|
|
|
|
SYSCTL_PROC(_net_inet6_sctp6, OID_AUTO, getcred, CTLTYPE_OPAQUE | CTLFLAG_RW,
|
|
|
|
0, 0,
|
|
|
|
sctp6_getcred, "S,ucred", "Get the ucred of a SCTP6 connection");
|
|
|
|
|
|
|
|
|
|
|
|
/* This is the same as the sctp_abort() could be made common */
|
|
|
|
static void
|
|
|
|
sctp6_abort(struct socket *so)
|
|
|
|
{
|
|
|
|
struct sctp_inpcb *inp;
|
|
|
|
uint32_t flags;
|
|
|
|
|
|
|
|
inp = (struct sctp_inpcb *)so->so_pcb;
|
2012-03-15 14:22:05 +00:00
|
|
|
if (inp == NULL) {
|
2007-09-08 17:48:46 +00:00
|
|
|
SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP6_USRREQ, EINVAL);
|
2006-11-03 15:23:16 +00:00
|
|
|
return;
|
2007-09-08 17:48:46 +00:00
|
|
|
}
|
2006-11-03 15:23:16 +00:00
|
|
|
sctp_must_try_again:
|
|
|
|
flags = inp->sctp_flags;
|
|
|
|
#ifdef SCTP_LOG_CLOSING
|
|
|
|
sctp_log_closing(inp, NULL, 17);
|
|
|
|
#endif
|
|
|
|
if (((flags & SCTP_PCB_FLAGS_SOCKET_GONE) == 0) &&
|
|
|
|
(atomic_cmpset_int(&inp->sctp_flags, flags, (flags | SCTP_PCB_FLAGS_SOCKET_GONE | SCTP_PCB_FLAGS_CLOSE_IP)))) {
|
|
|
|
#ifdef SCTP_LOG_CLOSING
|
|
|
|
sctp_log_closing(inp, NULL, 16);
|
|
|
|
#endif
|
2007-05-08 15:53:03 +00:00
|
|
|
sctp_inpcb_free(inp, SCTP_FREE_SHOULD_USE_ABORT,
|
|
|
|
SCTP_CALLED_AFTER_CMPSET_OFCLOSE);
|
2006-11-03 15:23:16 +00:00
|
|
|
SOCK_LOCK(so);
|
2007-03-19 06:53:02 +00:00
|
|
|
SCTP_SB_CLEAR(so->so_snd);
|
2006-11-03 15:23:16 +00:00
|
|
|
/*
|
|
|
|
* same for the rcv ones, they are only here for the
|
|
|
|
* accounting/select.
|
|
|
|
*/
|
2007-03-19 06:53:02 +00:00
|
|
|
SCTP_SB_CLEAR(so->so_rcv);
|
|
|
|
/* Now null out the reference, we are completely detached. */
|
2006-11-03 15:23:16 +00:00
|
|
|
so->so_pcb = NULL;
|
|
|
|
SOCK_UNLOCK(so);
|
|
|
|
} else {
|
|
|
|
flags = inp->sctp_flags;
|
|
|
|
if ((flags & SCTP_PCB_FLAGS_SOCKET_GONE) == 0) {
|
|
|
|
goto sctp_must_try_again;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2011-12-17 19:21:40 +00:00
|
|
|
sctp6_attach(struct socket *so, int proto SCTP_UNUSED, struct thread *p SCTP_UNUSED)
|
2006-11-03 15:23:16 +00:00
|
|
|
{
|
|
|
|
struct in6pcb *inp6;
|
2007-01-18 09:58:43 +00:00
|
|
|
int error;
|
2006-11-03 15:23:16 +00:00
|
|
|
struct sctp_inpcb *inp;
|
2007-06-02 11:05:08 +00:00
|
|
|
uint32_t vrf_id = SCTP_DEFAULT_VRFID;
|
2006-11-03 15:23:16 +00:00
|
|
|
|
|
|
|
inp = (struct sctp_inpcb *)so->so_pcb;
|
2007-08-24 00:53:53 +00:00
|
|
|
if (inp != NULL) {
|
|
|
|
SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP6_USRREQ, EINVAL);
|
2011-12-27 10:16:24 +00:00
|
|
|
return (EINVAL);
|
2007-08-24 00:53:53 +00:00
|
|
|
}
|
2006-11-03 15:23:16 +00:00
|
|
|
if (so->so_snd.sb_hiwat == 0 || so->so_rcv.sb_hiwat == 0) {
|
2008-06-14 07:58:05 +00:00
|
|
|
error = SCTP_SORESERVE(so, SCTP_BASE_SYSCTL(sctp_sendspace), SCTP_BASE_SYSCTL(sctp_recvspace));
|
2006-11-03 15:23:16 +00:00
|
|
|
if (error)
|
2011-12-27 10:16:24 +00:00
|
|
|
return (error);
|
2006-11-03 15:23:16 +00:00
|
|
|
}
|
2007-06-02 11:05:08 +00:00
|
|
|
error = sctp_inpcb_alloc(so, vrf_id);
|
2006-11-03 15:23:16 +00:00
|
|
|
if (error)
|
2011-12-27 10:16:24 +00:00
|
|
|
return (error);
|
2006-11-03 15:23:16 +00:00
|
|
|
inp = (struct sctp_inpcb *)so->so_pcb;
|
2007-06-02 11:05:08 +00:00
|
|
|
SCTP_INP_WLOCK(inp);
|
2006-11-03 15:23:16 +00:00
|
|
|
inp->sctp_flags |= SCTP_PCB_FLAGS_BOUND_V6; /* I'm v6! */
|
|
|
|
inp6 = (struct in6pcb *)inp;
|
|
|
|
|
|
|
|
inp6->inp_vflag |= INP_IPV6;
|
|
|
|
inp6->in6p_hops = -1; /* use kernel default */
|
|
|
|
inp6->in6p_cksum = -1; /* just to be sure */
|
|
|
|
#ifdef INET
|
|
|
|
/*
|
|
|
|
* XXX: ugly!! IPv4 TTL initialization is necessary for an IPv6
|
|
|
|
* socket as well, because the socket may be bound to an IPv6
|
|
|
|
* wildcard address, which may match an IPv4-mapped IPv6 address.
|
|
|
|
*/
|
2009-09-17 15:11:12 +00:00
|
|
|
inp6->inp_ip_ttl = MODULE_GLOBAL(ip_defttl);
|
2006-11-03 15:23:16 +00:00
|
|
|
#endif
|
|
|
|
/*
|
|
|
|
* Hmm what about the IPSEC stuff that is missing here but in
|
|
|
|
* sctp_attach()?
|
|
|
|
*/
|
2007-06-02 11:05:08 +00:00
|
|
|
SCTP_INP_WUNLOCK(inp);
|
2011-12-27 10:16:24 +00:00
|
|
|
return (0);
|
2006-11-03 15:23:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
sctp6_bind(struct socket *so, struct sockaddr *addr, struct thread *p)
|
|
|
|
{
|
|
|
|
struct sctp_inpcb *inp;
|
|
|
|
struct in6pcb *inp6;
|
2007-01-18 09:58:43 +00:00
|
|
|
int error;
|
2006-11-03 15:23:16 +00:00
|
|
|
|
|
|
|
inp = (struct sctp_inpcb *)so->so_pcb;
|
2012-03-15 14:22:05 +00:00
|
|
|
if (inp == NULL) {
|
2007-08-24 00:53:53 +00:00
|
|
|
SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP6_USRREQ, EINVAL);
|
2011-12-27 10:16:24 +00:00
|
|
|
return (EINVAL);
|
2007-08-24 00:53:53 +00:00
|
|
|
}
|
2007-05-28 11:17:24 +00:00
|
|
|
if (addr) {
|
2011-04-30 11:18:16 +00:00
|
|
|
switch (addr->sa_family) {
|
|
|
|
#ifdef INET
|
|
|
|
case AF_INET:
|
|
|
|
if (addr->sa_len != sizeof(struct sockaddr_in)) {
|
|
|
|
SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP6_USRREQ, EINVAL);
|
2011-12-27 10:16:24 +00:00
|
|
|
return (EINVAL);
|
2011-04-30 11:18:16 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
#endif
|
|
|
|
#ifdef INET6
|
|
|
|
case AF_INET6:
|
|
|
|
if (addr->sa_len != sizeof(struct sockaddr_in6)) {
|
|
|
|
SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP6_USRREQ, EINVAL);
|
2011-12-27 10:16:24 +00:00
|
|
|
return (EINVAL);
|
2011-04-30 11:18:16 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
#endif
|
|
|
|
default:
|
2007-08-24 00:53:53 +00:00
|
|
|
SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP6_USRREQ, EINVAL);
|
2011-12-27 10:16:24 +00:00
|
|
|
return (EINVAL);
|
2007-05-28 11:17:24 +00:00
|
|
|
}
|
|
|
|
}
|
2006-11-03 15:23:16 +00:00
|
|
|
inp6 = (struct in6pcb *)inp;
|
|
|
|
inp6->inp_vflag &= ~INP_IPV4;
|
|
|
|
inp6->inp_vflag |= INP_IPV6;
|
2007-01-15 15:12:10 +00:00
|
|
|
if ((addr != NULL) && (SCTP_IPV6_V6ONLY(inp6) == 0)) {
|
2011-04-30 11:18:16 +00:00
|
|
|
switch (addr->sa_family) {
|
|
|
|
#ifdef INET
|
|
|
|
case AF_INET:
|
2006-11-03 15:23:16 +00:00
|
|
|
/* binding v4 addr to v6 socket, so reset flags */
|
|
|
|
inp6->inp_vflag |= INP_IPV4;
|
|
|
|
inp6->inp_vflag &= ~INP_IPV6;
|
2011-04-30 11:18:16 +00:00
|
|
|
break;
|
|
|
|
#endif
|
|
|
|
#ifdef INET6
|
|
|
|
case AF_INET6:
|
|
|
|
{
|
|
|
|
struct sockaddr_in6 *sin6_p;
|
2006-11-03 15:23:16 +00:00
|
|
|
|
2011-04-30 11:18:16 +00:00
|
|
|
sin6_p = (struct sockaddr_in6 *)addr;
|
2006-11-03 15:23:16 +00:00
|
|
|
|
2011-04-30 11:18:16 +00:00
|
|
|
if (IN6_IS_ADDR_UNSPECIFIED(&sin6_p->sin6_addr)) {
|
|
|
|
inp6->inp_vflag |= INP_IPV4;
|
|
|
|
}
|
|
|
|
#ifdef INET
|
|
|
|
if (IN6_IS_ADDR_V4MAPPED(&sin6_p->sin6_addr)) {
|
|
|
|
struct sockaddr_in sin;
|
|
|
|
|
|
|
|
in6_sin6_2_sin(&sin, sin6_p);
|
|
|
|
inp6->inp_vflag |= INP_IPV4;
|
|
|
|
inp6->inp_vflag &= ~INP_IPV6;
|
|
|
|
error = sctp_inpcb_bind(so, (struct sockaddr *)&sin, NULL, p);
|
2011-12-27 10:16:24 +00:00
|
|
|
return (error);
|
2011-04-30 11:18:16 +00:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
break;
|
2006-11-03 15:23:16 +00:00
|
|
|
}
|
2011-04-30 11:18:16 +00:00
|
|
|
#endif
|
|
|
|
default:
|
|
|
|
break;
|
2006-11-03 15:23:16 +00:00
|
|
|
}
|
|
|
|
} else if (addr != NULL) {
|
2011-04-30 11:18:16 +00:00
|
|
|
struct sockaddr_in6 *sin6_p;
|
|
|
|
|
2006-11-03 15:23:16 +00:00
|
|
|
/* IPV6_V6ONLY socket */
|
2011-04-30 11:18:16 +00:00
|
|
|
#ifdef INET
|
2006-11-03 15:23:16 +00:00
|
|
|
if (addr->sa_family == AF_INET) {
|
|
|
|
/* can't bind v4 addr to v6 only socket! */
|
2007-08-24 00:53:53 +00:00
|
|
|
SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP6_USRREQ, EINVAL);
|
2011-12-27 10:16:24 +00:00
|
|
|
return (EINVAL);
|
2011-04-30 11:18:16 +00:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
sin6_p = (struct sockaddr_in6 *)addr;
|
2006-11-03 15:23:16 +00:00
|
|
|
|
2011-04-30 11:18:16 +00:00
|
|
|
if (IN6_IS_ADDR_V4MAPPED(&sin6_p->sin6_addr)) {
|
|
|
|
/* can't bind v4-mapped addrs either! */
|
|
|
|
/* NOTE: we don't support SIIT */
|
|
|
|
SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP6_USRREQ, EINVAL);
|
2011-12-27 10:16:24 +00:00
|
|
|
return (EINVAL);
|
2006-11-03 15:23:16 +00:00
|
|
|
}
|
|
|
|
}
|
2007-07-24 20:06:02 +00:00
|
|
|
error = sctp_inpcb_bind(so, addr, NULL, p);
|
2011-12-27 10:16:24 +00:00
|
|
|
return (error);
|
2006-11-03 15:23:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
sctp6_close(struct socket *so)
|
|
|
|
{
|
2007-08-27 05:19:48 +00:00
|
|
|
sctp_close(so);
|
2006-11-03 15:23:16 +00:00
|
|
|
}
|
|
|
|
|
2007-03-15 11:27:14 +00:00
|
|
|
/* This could be made common with sctp_detach() since they are identical */
|
2006-11-03 15:23:16 +00:00
|
|
|
|
2007-04-14 09:44:09 +00:00
|
|
|
static
|
|
|
|
int
|
2006-11-03 15:23:16 +00:00
|
|
|
sctp6_disconnect(struct socket *so)
|
|
|
|
{
|
2007-08-27 05:19:48 +00:00
|
|
|
return (sctp_disconnect(so));
|
2006-11-03 15:23:16 +00:00
|
|
|
}
|
|
|
|
|
2007-04-14 09:44:09 +00:00
|
|
|
|
2006-11-03 15:23:16 +00:00
|
|
|
int
|
|
|
|
sctp_sendm(struct socket *so, int flags, struct mbuf *m, struct sockaddr *addr,
|
|
|
|
struct mbuf *control, struct thread *p);
|
|
|
|
|
|
|
|
|
|
|
|
static int
|
|
|
|
sctp6_send(struct socket *so, int flags, struct mbuf *m, struct sockaddr *addr,
|
|
|
|
struct mbuf *control, struct thread *p)
|
|
|
|
{
|
|
|
|
struct sctp_inpcb *inp;
|
|
|
|
struct in6pcb *inp6;
|
|
|
|
|
|
|
|
#ifdef INET
|
|
|
|
struct sockaddr_in6 *sin6;
|
|
|
|
|
|
|
|
#endif /* INET */
|
|
|
|
/* No SPL needed since sctp_output does this */
|
|
|
|
|
|
|
|
inp = (struct sctp_inpcb *)so->so_pcb;
|
|
|
|
if (inp == NULL) {
|
|
|
|
if (control) {
|
2007-05-08 00:21:05 +00:00
|
|
|
SCTP_RELEASE_PKT(control);
|
2006-11-03 15:23:16 +00:00
|
|
|
control = NULL;
|
|
|
|
}
|
2007-05-08 00:21:05 +00:00
|
|
|
SCTP_RELEASE_PKT(m);
|
2007-08-24 00:53:53 +00:00
|
|
|
SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP6_USRREQ, EINVAL);
|
2011-12-27 10:16:24 +00:00
|
|
|
return (EINVAL);
|
2006-11-03 15:23:16 +00:00
|
|
|
}
|
|
|
|
inp6 = (struct in6pcb *)inp;
|
|
|
|
/*
|
|
|
|
* For the TCP model we may get a NULL addr, if we are a connected
|
|
|
|
* socket thats ok.
|
|
|
|
*/
|
|
|
|
if ((inp->sctp_flags & SCTP_PCB_FLAGS_CONNECTED) &&
|
|
|
|
(addr == NULL)) {
|
|
|
|
goto connected_type;
|
|
|
|
}
|
|
|
|
if (addr == NULL) {
|
2007-05-08 00:21:05 +00:00
|
|
|
SCTP_RELEASE_PKT(m);
|
2006-11-03 15:23:16 +00:00
|
|
|
if (control) {
|
2007-05-08 00:21:05 +00:00
|
|
|
SCTP_RELEASE_PKT(control);
|
2006-11-03 15:23:16 +00:00
|
|
|
control = NULL;
|
|
|
|
}
|
2007-08-24 00:53:53 +00:00
|
|
|
SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP6_USRREQ, EDESTADDRREQ);
|
2006-11-03 15:23:16 +00:00
|
|
|
return (EDESTADDRREQ);
|
|
|
|
}
|
|
|
|
#ifdef INET
|
|
|
|
sin6 = (struct sockaddr_in6 *)addr;
|
2007-01-15 15:12:10 +00:00
|
|
|
if (SCTP_IPV6_V6ONLY(inp6)) {
|
2006-11-03 15:23:16 +00:00
|
|
|
/*
|
|
|
|
* if IPV6_V6ONLY flag, we discard datagrams destined to a
|
|
|
|
* v4 addr or v4-mapped addr
|
|
|
|
*/
|
|
|
|
if (addr->sa_family == AF_INET) {
|
2007-08-24 00:53:53 +00:00
|
|
|
SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP6_USRREQ, EINVAL);
|
2011-12-27 10:16:24 +00:00
|
|
|
return (EINVAL);
|
2006-11-03 15:23:16 +00:00
|
|
|
}
|
|
|
|
if (IN6_IS_ADDR_V4MAPPED(&sin6->sin6_addr)) {
|
2007-08-24 00:53:53 +00:00
|
|
|
SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP6_USRREQ, EINVAL);
|
2011-12-27 10:16:24 +00:00
|
|
|
return (EINVAL);
|
2006-11-03 15:23:16 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
if (IN6_IS_ADDR_V4MAPPED(&sin6->sin6_addr)) {
|
2013-05-10 18:09:38 +00:00
|
|
|
struct sockaddr_in sin;
|
2006-11-03 15:23:16 +00:00
|
|
|
|
2013-05-10 18:09:38 +00:00
|
|
|
/* convert v4-mapped into v4 addr and send */
|
|
|
|
in6_sin6_2_sin(&sin, sin6);
|
|
|
|
return (sctp_sendm(so, flags, m, (struct sockaddr *)&sin, control, p));
|
2006-11-03 15:23:16 +00:00
|
|
|
}
|
|
|
|
#endif /* INET */
|
|
|
|
connected_type:
|
|
|
|
/* now what about control */
|
|
|
|
if (control) {
|
|
|
|
if (inp->control) {
|
2007-05-09 13:30:06 +00:00
|
|
|
SCTP_PRINTF("huh? control set?\n");
|
2007-05-08 00:21:05 +00:00
|
|
|
SCTP_RELEASE_PKT(inp->control);
|
2006-11-03 15:23:16 +00:00
|
|
|
inp->control = NULL;
|
|
|
|
}
|
|
|
|
inp->control = control;
|
|
|
|
}
|
|
|
|
/* Place the data */
|
|
|
|
if (inp->pkt) {
|
2006-12-29 20:21:42 +00:00
|
|
|
SCTP_BUF_NEXT(inp->pkt_last) = m;
|
2006-11-03 15:23:16 +00:00
|
|
|
inp->pkt_last = m;
|
|
|
|
} else {
|
|
|
|
inp->pkt_last = inp->pkt = m;
|
|
|
|
}
|
|
|
|
if (
|
|
|
|
/* FreeBSD and MacOSX uses a flag passed */
|
|
|
|
((flags & PRUS_MORETOCOME) == 0)
|
|
|
|
) {
|
|
|
|
/*
|
|
|
|
* note with the current version this code will only be used
|
|
|
|
* by OpenBSD, NetBSD and FreeBSD have methods for
|
|
|
|
* re-defining sosend() to use sctp_sosend(). One can
|
|
|
|
* optionaly switch back to this code (by changing back the
|
|
|
|
* defininitions but this is not advisable.
|
|
|
|
*/
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
ret = sctp_output(inp, inp->pkt, addr, inp->control, p, flags);
|
|
|
|
inp->pkt = NULL;
|
|
|
|
inp->control = NULL;
|
|
|
|
return (ret);
|
|
|
|
} else {
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
sctp6_connect(struct socket *so, struct sockaddr *addr, struct thread *p)
|
|
|
|
{
|
2007-03-15 11:27:14 +00:00
|
|
|
uint32_t vrf_id;
|
2006-11-03 15:23:16 +00:00
|
|
|
int error = 0;
|
|
|
|
struct sctp_inpcb *inp;
|
|
|
|
struct sctp_tcb *stcb;
|
|
|
|
|
|
|
|
#ifdef INET
|
2013-11-02 20:12:19 +00:00
|
|
|
struct in6pcb *inp6;
|
2006-11-03 15:23:16 +00:00
|
|
|
struct sockaddr_in6 *sin6;
|
2014-09-07 09:06:26 +00:00
|
|
|
union sctp_sockstore store;
|
2006-11-03 15:23:16 +00:00
|
|
|
|
2011-04-30 11:18:16 +00:00
|
|
|
#endif
|
2006-11-03 15:23:16 +00:00
|
|
|
|
2013-11-02 20:12:19 +00:00
|
|
|
#ifdef INET
|
2006-11-03 15:23:16 +00:00
|
|
|
inp6 = (struct in6pcb *)so->so_pcb;
|
2013-11-02 20:12:19 +00:00
|
|
|
#endif
|
2006-11-03 15:23:16 +00:00
|
|
|
inp = (struct sctp_inpcb *)so->so_pcb;
|
2012-03-15 14:22:05 +00:00
|
|
|
if (inp == NULL) {
|
2007-08-24 00:53:53 +00:00
|
|
|
SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP6_USRREQ, ECONNRESET);
|
2006-11-03 15:23:16 +00:00
|
|
|
return (ECONNRESET); /* I made the same as TCP since we are
|
|
|
|
* not setup? */
|
|
|
|
}
|
2007-05-28 11:17:24 +00:00
|
|
|
if (addr == NULL) {
|
2007-08-24 00:53:53 +00:00
|
|
|
SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP6_USRREQ, EINVAL);
|
2007-05-28 11:17:24 +00:00
|
|
|
return (EINVAL);
|
|
|
|
}
|
2011-04-30 11:18:16 +00:00
|
|
|
switch (addr->sa_family) {
|
|
|
|
#ifdef INET
|
|
|
|
case AF_INET:
|
|
|
|
if (addr->sa_len != sizeof(struct sockaddr_in)) {
|
|
|
|
SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP6_USRREQ, EINVAL);
|
|
|
|
return (EINVAL);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
#endif
|
|
|
|
#ifdef INET6
|
|
|
|
case AF_INET6:
|
|
|
|
if (addr->sa_len != sizeof(struct sockaddr_in6)) {
|
|
|
|
SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP6_USRREQ, EINVAL);
|
|
|
|
return (EINVAL);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
#endif
|
|
|
|
default:
|
2007-08-24 00:53:53 +00:00
|
|
|
SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP6_USRREQ, EINVAL);
|
2007-05-28 11:17:24 +00:00
|
|
|
return (EINVAL);
|
|
|
|
}
|
2011-04-30 11:18:16 +00:00
|
|
|
|
2007-04-03 11:15:32 +00:00
|
|
|
vrf_id = inp->def_vrf_id;
|
2006-11-03 15:23:16 +00:00
|
|
|
SCTP_ASOC_CREATE_LOCK(inp);
|
|
|
|
SCTP_INP_RLOCK(inp);
|
|
|
|
if ((inp->sctp_flags & SCTP_PCB_FLAGS_UNBOUND) ==
|
|
|
|
SCTP_PCB_FLAGS_UNBOUND) {
|
|
|
|
/* Bind a ephemeral port */
|
|
|
|
SCTP_INP_RUNLOCK(inp);
|
|
|
|
error = sctp6_bind(so, NULL, p);
|
|
|
|
if (error) {
|
|
|
|
SCTP_ASOC_CREATE_UNLOCK(inp);
|
|
|
|
|
|
|
|
return (error);
|
|
|
|
}
|
|
|
|
SCTP_INP_RLOCK(inp);
|
|
|
|
}
|
|
|
|
if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) &&
|
|
|
|
(inp->sctp_flags & SCTP_PCB_FLAGS_CONNECTED)) {
|
|
|
|
/* We are already connected AND the TCP model */
|
|
|
|
SCTP_INP_RUNLOCK(inp);
|
|
|
|
SCTP_ASOC_CREATE_UNLOCK(inp);
|
2007-08-24 00:53:53 +00:00
|
|
|
SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP6_USRREQ, EADDRINUSE);
|
2006-11-03 15:23:16 +00:00
|
|
|
return (EADDRINUSE);
|
|
|
|
}
|
|
|
|
#ifdef INET
|
|
|
|
sin6 = (struct sockaddr_in6 *)addr;
|
2007-01-15 15:12:10 +00:00
|
|
|
if (SCTP_IPV6_V6ONLY(inp6)) {
|
2006-11-03 15:23:16 +00:00
|
|
|
/*
|
|
|
|
* if IPV6_V6ONLY flag, ignore connections destined to a v4
|
|
|
|
* addr or v4-mapped addr
|
|
|
|
*/
|
|
|
|
if (addr->sa_family == AF_INET) {
|
|
|
|
SCTP_INP_RUNLOCK(inp);
|
|
|
|
SCTP_ASOC_CREATE_UNLOCK(inp);
|
2007-08-24 00:53:53 +00:00
|
|
|
SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP6_USRREQ, EINVAL);
|
2011-12-27 10:16:24 +00:00
|
|
|
return (EINVAL);
|
2006-11-03 15:23:16 +00:00
|
|
|
}
|
|
|
|
if (IN6_IS_ADDR_V4MAPPED(&sin6->sin6_addr)) {
|
|
|
|
SCTP_INP_RUNLOCK(inp);
|
|
|
|
SCTP_ASOC_CREATE_UNLOCK(inp);
|
2007-08-24 00:53:53 +00:00
|
|
|
SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP6_USRREQ, EINVAL);
|
2011-12-27 10:16:24 +00:00
|
|
|
return (EINVAL);
|
2006-11-03 15:23:16 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
if (IN6_IS_ADDR_V4MAPPED(&sin6->sin6_addr)) {
|
2013-05-10 18:09:38 +00:00
|
|
|
/* convert v4-mapped into v4 addr */
|
2014-09-07 09:06:26 +00:00
|
|
|
in6_sin6_2_sin(&store.sin, sin6);
|
|
|
|
addr = &store.sa;
|
2011-05-03 20:34:02 +00:00
|
|
|
}
|
2006-11-03 15:23:16 +00:00
|
|
|
#endif /* INET */
|
|
|
|
/* Now do we connect? */
|
|
|
|
if (inp->sctp_flags & SCTP_PCB_FLAGS_CONNECTED) {
|
|
|
|
stcb = LIST_FIRST(&inp->sctp_asoc_list);
|
2007-05-09 13:30:06 +00:00
|
|
|
if (stcb) {
|
2006-11-03 15:23:16 +00:00
|
|
|
SCTP_TCB_UNLOCK(stcb);
|
2007-05-09 13:30:06 +00:00
|
|
|
}
|
2006-11-03 15:23:16 +00:00
|
|
|
SCTP_INP_RUNLOCK(inp);
|
|
|
|
} else {
|
|
|
|
SCTP_INP_RUNLOCK(inp);
|
|
|
|
SCTP_INP_WLOCK(inp);
|
|
|
|
SCTP_INP_INCR_REF(inp);
|
|
|
|
SCTP_INP_WUNLOCK(inp);
|
|
|
|
stcb = sctp_findassociation_ep_addr(&inp, addr, NULL, NULL, NULL);
|
|
|
|
if (stcb == NULL) {
|
|
|
|
SCTP_INP_WLOCK(inp);
|
|
|
|
SCTP_INP_DECR_REF(inp);
|
|
|
|
SCTP_INP_WUNLOCK(inp);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (stcb != NULL) {
|
|
|
|
/* Already have or am bring up an association */
|
|
|
|
SCTP_ASOC_CREATE_UNLOCK(inp);
|
|
|
|
SCTP_TCB_UNLOCK(stcb);
|
2007-08-24 00:53:53 +00:00
|
|
|
SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP6_USRREQ, EALREADY);
|
2006-11-03 15:23:16 +00:00
|
|
|
return (EALREADY);
|
|
|
|
}
|
|
|
|
/* We are GOOD to go */
|
2015-12-06 16:17:57 +00:00
|
|
|
stcb = sctp_aloc_assoc(inp, addr, &error, 0, vrf_id, inp->sctp_ep.pre_open_stream_count, p);
|
2006-11-03 15:23:16 +00:00
|
|
|
SCTP_ASOC_CREATE_UNLOCK(inp);
|
|
|
|
if (stcb == NULL) {
|
|
|
|
/* Gak! no memory */
|
|
|
|
return (error);
|
|
|
|
}
|
|
|
|
if (stcb->sctp_ep->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) {
|
|
|
|
stcb->sctp_ep->sctp_flags |= SCTP_PCB_FLAGS_CONNECTED;
|
|
|
|
/* Set the connected flag so we can queue data */
|
|
|
|
soisconnecting(so);
|
|
|
|
}
|
|
|
|
stcb->asoc.state = SCTP_STATE_COOKIE_WAIT;
|
2007-05-09 13:30:06 +00:00
|
|
|
(void)SCTP_GETTIME_TIMEVAL(&stcb->asoc.time_entered);
|
2006-11-03 15:23:16 +00:00
|
|
|
|
|
|
|
/* initialize authentication parameters for the assoc */
|
|
|
|
sctp_initialize_auth_params(inp, stcb);
|
|
|
|
|
2007-09-08 11:35:11 +00:00
|
|
|
sctp_send_initiate(inp, stcb, SCTP_SO_LOCKED);
|
2006-11-03 15:23:16 +00:00
|
|
|
SCTP_TCB_UNLOCK(stcb);
|
2011-12-27 10:16:24 +00:00
|
|
|
return (error);
|
2006-11-03 15:23:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
sctp6_getaddr(struct socket *so, struct sockaddr **addr)
|
|
|
|
{
|
|
|
|
struct sockaddr_in6 *sin6;
|
|
|
|
struct sctp_inpcb *inp;
|
2007-03-15 11:27:14 +00:00
|
|
|
uint32_t vrf_id;
|
|
|
|
struct sctp_ifa *sctp_ifa;
|
2006-11-03 15:23:16 +00:00
|
|
|
|
|
|
|
int error;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Do the malloc first in case it blocks.
|
|
|
|
*/
|
2011-04-30 11:18:16 +00:00
|
|
|
SCTP_MALLOC_SONAME(sin6, struct sockaddr_in6 *, sizeof(*sin6));
|
2010-08-28 17:59:51 +00:00
|
|
|
if (sin6 == NULL)
|
2011-12-27 10:16:24 +00:00
|
|
|
return (ENOMEM);
|
2006-11-03 15:23:16 +00:00
|
|
|
sin6->sin6_family = AF_INET6;
|
|
|
|
sin6->sin6_len = sizeof(*sin6);
|
|
|
|
|
|
|
|
inp = (struct sctp_inpcb *)so->so_pcb;
|
|
|
|
if (inp == NULL) {
|
|
|
|
SCTP_FREE_SONAME(sin6);
|
2007-08-24 00:53:53 +00:00
|
|
|
SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP6_USRREQ, ECONNRESET);
|
2011-12-27 10:16:24 +00:00
|
|
|
return (ECONNRESET);
|
2006-11-03 15:23:16 +00:00
|
|
|
}
|
|
|
|
SCTP_INP_RLOCK(inp);
|
|
|
|
sin6->sin6_port = inp->sctp_lport;
|
|
|
|
if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUNDALL) {
|
|
|
|
/* For the bound all case you get back 0 */
|
|
|
|
if (inp->sctp_flags & SCTP_PCB_FLAGS_CONNECTED) {
|
|
|
|
struct sctp_tcb *stcb;
|
|
|
|
struct sockaddr_in6 *sin_a6;
|
|
|
|
struct sctp_nets *net;
|
|
|
|
int fnd;
|
|
|
|
|
|
|
|
stcb = LIST_FIRST(&inp->sctp_asoc_list);
|
|
|
|
if (stcb == NULL) {
|
2016-02-18 21:05:04 +00:00
|
|
|
SCTP_INP_RUNLOCK(inp);
|
2016-02-23 18:50:34 +00:00
|
|
|
SCTP_FREE_SONAME(sin6);
|
2016-02-18 21:05:04 +00:00
|
|
|
SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP6_USRREQ, ENOENT);
|
|
|
|
return (ENOENT);
|
2006-11-03 15:23:16 +00:00
|
|
|
}
|
|
|
|
fnd = 0;
|
|
|
|
sin_a6 = NULL;
|
|
|
|
TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
|
|
|
|
sin_a6 = (struct sockaddr_in6 *)&net->ro._l_addr;
|
2006-11-08 00:21:13 +00:00
|
|
|
if (sin_a6 == NULL)
|
|
|
|
/* this will make coverity happy */
|
|
|
|
continue;
|
|
|
|
|
2006-11-03 15:23:16 +00:00
|
|
|
if (sin_a6->sin6_family == AF_INET6) {
|
|
|
|
fnd = 1;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if ((!fnd) || (sin_a6 == NULL)) {
|
|
|
|
/* punt */
|
2016-02-18 21:05:04 +00:00
|
|
|
SCTP_INP_RUNLOCK(inp);
|
2016-02-23 18:50:34 +00:00
|
|
|
SCTP_FREE_SONAME(sin6);
|
2016-02-18 21:05:04 +00:00
|
|
|
SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP6_USRREQ, ENOENT);
|
|
|
|
return (ENOENT);
|
2006-11-03 15:23:16 +00:00
|
|
|
}
|
2007-04-03 11:15:32 +00:00
|
|
|
vrf_id = inp->def_vrf_id;
|
|
|
|
sctp_ifa = sctp_source_address_selection(inp, stcb, (sctp_route_t *) & net->ro, net, 0, vrf_id);
|
2007-03-15 11:27:14 +00:00
|
|
|
if (sctp_ifa) {
|
|
|
|
sin6->sin6_addr = sctp_ifa->address.sin6.sin6_addr;
|
|
|
|
}
|
2006-11-03 15:23:16 +00:00
|
|
|
} else {
|
|
|
|
/* For the bound all case you get back 0 */
|
|
|
|
memset(&sin6->sin6_addr, 0, sizeof(sin6->sin6_addr));
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
/* Take the first IPv6 address in the list */
|
|
|
|
struct sctp_laddr *laddr;
|
|
|
|
int fnd = 0;
|
|
|
|
|
|
|
|
LIST_FOREACH(laddr, &inp->sctp_addr_list, sctp_nxt_addr) {
|
2007-03-15 11:27:14 +00:00
|
|
|
if (laddr->ifa->address.sa.sa_family == AF_INET6) {
|
2006-11-03 15:23:16 +00:00
|
|
|
struct sockaddr_in6 *sin_a;
|
|
|
|
|
2014-09-07 09:06:26 +00:00
|
|
|
sin_a = &laddr->ifa->address.sin6;
|
2006-11-03 15:23:16 +00:00
|
|
|
sin6->sin6_addr = sin_a->sin6_addr;
|
|
|
|
fnd = 1;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!fnd) {
|
|
|
|
SCTP_FREE_SONAME(sin6);
|
|
|
|
SCTP_INP_RUNLOCK(inp);
|
2007-08-24 00:53:53 +00:00
|
|
|
SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP6_USRREQ, ENOENT);
|
2011-12-27 10:16:24 +00:00
|
|
|
return (ENOENT);
|
2006-11-03 15:23:16 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
SCTP_INP_RUNLOCK(inp);
|
|
|
|
/* Scoping things for v6 */
|
2006-11-08 00:21:13 +00:00
|
|
|
if ((error = sa6_recoverscope(sin6)) != 0) {
|
|
|
|
SCTP_FREE_SONAME(sin6);
|
2006-11-03 15:23:16 +00:00
|
|
|
return (error);
|
2006-11-08 00:21:13 +00:00
|
|
|
}
|
2006-11-03 15:23:16 +00:00
|
|
|
(*addr) = (struct sockaddr *)sin6;
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
sctp6_peeraddr(struct socket *so, struct sockaddr **addr)
|
|
|
|
{
|
2012-02-18 16:06:15 +00:00
|
|
|
struct sockaddr_in6 *sin6;
|
2006-11-03 15:23:16 +00:00
|
|
|
int fnd;
|
|
|
|
struct sockaddr_in6 *sin_a6;
|
|
|
|
struct sctp_inpcb *inp;
|
|
|
|
struct sctp_tcb *stcb;
|
|
|
|
struct sctp_nets *net;
|
|
|
|
int error;
|
|
|
|
|
2011-12-27 10:16:24 +00:00
|
|
|
/* Do the malloc first in case it blocks. */
|
2006-11-03 15:23:16 +00:00
|
|
|
SCTP_MALLOC_SONAME(sin6, struct sockaddr_in6 *, sizeof *sin6);
|
2010-08-28 17:59:51 +00:00
|
|
|
if (sin6 == NULL)
|
|
|
|
return (ENOMEM);
|
2006-11-03 15:23:16 +00:00
|
|
|
sin6->sin6_family = AF_INET6;
|
|
|
|
sin6->sin6_len = sizeof(*sin6);
|
|
|
|
|
|
|
|
inp = (struct sctp_inpcb *)so->so_pcb;
|
2011-12-27 10:16:24 +00:00
|
|
|
if ((inp == NULL) ||
|
|
|
|
((inp->sctp_flags & SCTP_PCB_FLAGS_CONNECTED) == 0)) {
|
|
|
|
/* UDP type and listeners will drop out here */
|
2006-11-03 15:23:16 +00:00
|
|
|
SCTP_FREE_SONAME(sin6);
|
2011-12-27 10:16:24 +00:00
|
|
|
SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP6_USRREQ, ENOTCONN);
|
|
|
|
return (ENOTCONN);
|
2006-11-03 15:23:16 +00:00
|
|
|
}
|
|
|
|
SCTP_INP_RLOCK(inp);
|
|
|
|
stcb = LIST_FIRST(&inp->sctp_asoc_list);
|
2007-05-09 13:30:06 +00:00
|
|
|
if (stcb) {
|
2006-11-03 15:23:16 +00:00
|
|
|
SCTP_TCB_LOCK(stcb);
|
2007-05-09 13:30:06 +00:00
|
|
|
}
|
2006-11-03 15:23:16 +00:00
|
|
|
SCTP_INP_RUNLOCK(inp);
|
|
|
|
if (stcb == NULL) {
|
|
|
|
SCTP_FREE_SONAME(sin6);
|
2007-08-24 00:53:53 +00:00
|
|
|
SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP6_USRREQ, ECONNRESET);
|
2011-12-27 10:16:24 +00:00
|
|
|
return (ECONNRESET);
|
2006-11-03 15:23:16 +00:00
|
|
|
}
|
|
|
|
fnd = 0;
|
|
|
|
TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
|
|
|
|
sin_a6 = (struct sockaddr_in6 *)&net->ro._l_addr;
|
|
|
|
if (sin_a6->sin6_family == AF_INET6) {
|
|
|
|
fnd = 1;
|
|
|
|
sin6->sin6_port = stcb->rport;
|
|
|
|
sin6->sin6_addr = sin_a6->sin6_addr;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
SCTP_TCB_UNLOCK(stcb);
|
|
|
|
if (!fnd) {
|
|
|
|
/* No IPv4 address */
|
|
|
|
SCTP_FREE_SONAME(sin6);
|
2007-08-24 00:53:53 +00:00
|
|
|
SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP6_USRREQ, ENOENT);
|
2011-12-27 10:16:24 +00:00
|
|
|
return (ENOENT);
|
2006-11-03 15:23:16 +00:00
|
|
|
}
|
2014-12-17 20:19:57 +00:00
|
|
|
if ((error = sa6_recoverscope(sin6)) != 0) {
|
|
|
|
SCTP_FREE_SONAME(sin6);
|
|
|
|
SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP6_USRREQ, error);
|
2006-11-03 15:23:16 +00:00
|
|
|
return (error);
|
2014-12-17 20:19:57 +00:00
|
|
|
}
|
2006-11-03 15:23:16 +00:00
|
|
|
*addr = (struct sockaddr *)sin6;
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
sctp6_in6getaddr(struct socket *so, struct sockaddr **nam)
|
|
|
|
{
|
|
|
|
struct in6pcb *inp6 = sotoin6pcb(so);
|
2007-01-18 09:58:43 +00:00
|
|
|
int error;
|
2006-11-03 15:23:16 +00:00
|
|
|
|
2007-08-24 00:53:53 +00:00
|
|
|
if (inp6 == NULL) {
|
|
|
|
SCTP_LTRACE_ERR_RET(NULL, NULL, NULL, SCTP_FROM_SCTP6_USRREQ, EINVAL);
|
2011-12-27 10:16:24 +00:00
|
|
|
return (EINVAL);
|
2007-08-24 00:53:53 +00:00
|
|
|
}
|
2006-11-03 15:23:16 +00:00
|
|
|
/* allow v6 addresses precedence */
|
|
|
|
error = sctp6_getaddr(so, nam);
|
2011-04-30 11:18:16 +00:00
|
|
|
#ifdef INET
|
2006-11-03 15:23:16 +00:00
|
|
|
if (error) {
|
2016-02-18 21:05:04 +00:00
|
|
|
struct sockaddr_in6 *sin6;
|
|
|
|
|
2006-11-03 15:23:16 +00:00
|
|
|
/* try v4 next if v6 failed */
|
|
|
|
error = sctp_ingetaddr(so, nam);
|
|
|
|
if (error) {
|
|
|
|
return (error);
|
|
|
|
}
|
2016-02-18 21:05:04 +00:00
|
|
|
SCTP_MALLOC_SONAME(sin6, struct sockaddr_in6 *, sizeof *sin6);
|
|
|
|
if (sin6 == NULL) {
|
|
|
|
SCTP_FREE_SONAME(*nam);
|
|
|
|
return (ENOMEM);
|
2006-11-03 15:23:16 +00:00
|
|
|
}
|
2016-02-18 21:05:04 +00:00
|
|
|
in6_sin_2_v4mapsin6((struct sockaddr_in *)*nam, sin6);
|
|
|
|
SCTP_FREE_SONAME(*nam);
|
|
|
|
*nam = (struct sockaddr *)sin6;
|
2006-11-03 15:23:16 +00:00
|
|
|
}
|
2011-04-30 11:18:16 +00:00
|
|
|
#endif
|
2006-11-03 15:23:16 +00:00
|
|
|
return (error);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static int
|
|
|
|
sctp6_getpeeraddr(struct socket *so, struct sockaddr **nam)
|
|
|
|
{
|
|
|
|
struct in6pcb *inp6 = sotoin6pcb(so);
|
2007-01-18 09:58:43 +00:00
|
|
|
int error;
|
2006-11-03 15:23:16 +00:00
|
|
|
|
2007-08-24 00:53:53 +00:00
|
|
|
if (inp6 == NULL) {
|
|
|
|
SCTP_LTRACE_ERR_RET(NULL, NULL, NULL, SCTP_FROM_SCTP6_USRREQ, EINVAL);
|
2011-12-27 10:16:24 +00:00
|
|
|
return (EINVAL);
|
2007-08-24 00:53:53 +00:00
|
|
|
}
|
2006-11-03 15:23:16 +00:00
|
|
|
/* allow v6 addresses precedence */
|
|
|
|
error = sctp6_peeraddr(so, nam);
|
2011-04-30 11:18:16 +00:00
|
|
|
#ifdef INET
|
2006-11-03 15:23:16 +00:00
|
|
|
if (error) {
|
2016-02-18 21:05:04 +00:00
|
|
|
struct sockaddr_in6 *sin6;
|
|
|
|
|
2006-11-03 15:23:16 +00:00
|
|
|
/* try v4 next if v6 failed */
|
|
|
|
error = sctp_peeraddr(so, nam);
|
|
|
|
if (error) {
|
|
|
|
return (error);
|
|
|
|
}
|
2016-02-18 21:05:04 +00:00
|
|
|
SCTP_MALLOC_SONAME(sin6, struct sockaddr_in6 *, sizeof *sin6);
|
|
|
|
if (sin6 == NULL) {
|
|
|
|
SCTP_FREE_SONAME(*nam);
|
|
|
|
return (ENOMEM);
|
2006-11-03 15:23:16 +00:00
|
|
|
}
|
2016-02-18 21:05:04 +00:00
|
|
|
in6_sin_2_v4mapsin6((struct sockaddr_in *)*nam, sin6);
|
|
|
|
SCTP_FREE_SONAME(*nam);
|
|
|
|
*nam = (struct sockaddr *)sin6;
|
2006-11-03 15:23:16 +00:00
|
|
|
}
|
2011-04-30 11:18:16 +00:00
|
|
|
#endif
|
2011-12-27 10:16:24 +00:00
|
|
|
return (error);
|
2006-11-03 15:23:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
struct pr_usrreqs sctp6_usrreqs = {
|
|
|
|
.pru_abort = sctp6_abort,
|
|
|
|
.pru_accept = sctp_accept,
|
|
|
|
.pru_attach = sctp6_attach,
|
|
|
|
.pru_bind = sctp6_bind,
|
|
|
|
.pru_connect = sctp6_connect,
|
|
|
|
.pru_control = in6_control,
|
|
|
|
.pru_close = sctp6_close,
|
|
|
|
.pru_detach = sctp6_close,
|
|
|
|
.pru_sopoll = sopoll_generic,
|
2008-04-14 18:12:37 +00:00
|
|
|
.pru_flush = sctp_flush,
|
2006-11-03 15:23:16 +00:00
|
|
|
.pru_disconnect = sctp6_disconnect,
|
|
|
|
.pru_listen = sctp_listen,
|
|
|
|
.pru_peeraddr = sctp6_getpeeraddr,
|
|
|
|
.pru_send = sctp6_send,
|
|
|
|
.pru_shutdown = sctp_shutdown,
|
|
|
|
.pru_sockaddr = sctp6_in6getaddr,
|
|
|
|
.pru_sosend = sctp_sosend,
|
|
|
|
.pru_soreceive = sctp_soreceive
|
|
|
|
};
|
2012-07-15 20:16:17 +00:00
|
|
|
|
|
|
|
#endif
|