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.
|
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,
|
|
|
|
* this list of conditions and the following disclaimer.
|
|
|
|
*
|
|
|
|
* b) Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in
|
|
|
|
* the documentation and/or other materials provided with the distribution.
|
|
|
|
*
|
|
|
|
* c) Neither the name of Cisco Systems, Inc. nor the names of its
|
|
|
|
* contributors may be used to endorse or promote products derived
|
|
|
|
* from this software without specific prior written permission.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
|
|
|
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
|
|
|
|
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
|
|
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
|
|
|
|
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
|
|
|
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
|
|
|
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
|
|
|
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
|
|
|
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
|
|
|
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
|
|
|
|
* THE POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
*/
|
|
|
|
/* $KAME: sctp6_usrreq.c,v 1.38 2005/08/24 08:08:56 suz Exp $ */
|
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>
|
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
|
|
|
#if defined(INET6)
|
|
|
|
#include <netinet6/sctp6_var.h>
|
|
|
|
#endif
|
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>
|
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>
|
|
|
|
#if defined(INET6)
|
|
|
|
#include <netipsec/ipsec6.h>
|
2007-07-14 09:36:28 +00:00
|
|
|
#endif /* INET6 */
|
|
|
|
#endif /* IPSEC */
|
2006-11-03 15:23:16 +00:00
|
|
|
|
|
|
|
extern struct protosw inetsw[];
|
|
|
|
|
|
|
|
int
|
2007-07-05 16:23:49 +00:00
|
|
|
sctp6_input(struct mbuf **i_pak, int *offp, int proto)
|
2006-11-03 15:23:16 +00:00
|
|
|
{
|
2006-12-29 20:21:42 +00:00
|
|
|
struct mbuf *m;
|
2006-11-03 15:23:16 +00:00
|
|
|
struct ip6_hdr *ip6;
|
|
|
|
struct sctphdr *sh;
|
|
|
|
struct sctp_inpcb *in6p = NULL;
|
|
|
|
struct sctp_nets *net;
|
|
|
|
int refcount_up = 0;
|
2007-05-08 00:21:05 +00:00
|
|
|
uint32_t check, calc_check;
|
2007-06-01 11:19:54 +00:00
|
|
|
uint32_t vrf_id = 0;
|
2006-11-03 15:23:16 +00:00
|
|
|
struct inpcb *in6p_ip;
|
|
|
|
struct sctp_chunkhdr *ch;
|
2009-02-03 11:04:03 +00:00
|
|
|
int length, offset, iphlen;
|
2007-04-03 11:15:32 +00:00
|
|
|
uint8_t ecn_bits;
|
2006-11-03 15:23:16 +00:00
|
|
|
struct sctp_tcb *stcb = NULL;
|
2007-05-28 11:17:24 +00:00
|
|
|
int pkt_len = 0;
|
2006-11-03 15:23:16 +00:00
|
|
|
int off = *offp;
|
2008-06-14 07:58:05 +00:00
|
|
|
uint16_t port = 0;
|
2006-11-03 15:23:16 +00:00
|
|
|
|
2007-05-08 00:21:05 +00:00
|
|
|
/* get the VRF and table id's */
|
|
|
|
if (SCTP_GET_PKT_VRFID(*i_pak, vrf_id)) {
|
|
|
|
SCTP_RELEASE_PKT(*i_pak);
|
|
|
|
return (-1);
|
|
|
|
}
|
2007-04-14 09:44:09 +00:00
|
|
|
m = SCTP_HEADER_TO_CHAIN(*i_pak);
|
2007-05-28 11:17:24 +00:00
|
|
|
pkt_len = SCTP_HEADER_LEN((*i_pak));
|
2007-04-14 09:44:09 +00:00
|
|
|
|
2007-05-29 09:29:03 +00:00
|
|
|
#ifdef SCTP_PACKET_LOGGING
|
|
|
|
sctp_packet_log(m, pkt_len);
|
|
|
|
#endif
|
2006-11-03 15:23:16 +00:00
|
|
|
ip6 = mtod(m, struct ip6_hdr *);
|
|
|
|
/* Ensure that (sctphdr + sctp_chunkhdr) in a row. */
|
2007-05-28 11:17:24 +00:00
|
|
|
IP6_EXTHDR_GET(sh, struct sctphdr *, m, off,
|
|
|
|
(int)(sizeof(*sh) + sizeof(*ch)));
|
2006-11-03 15:23:16 +00:00
|
|
|
if (sh == NULL) {
|
|
|
|
SCTP_STAT_INCR(sctps_hdrops);
|
|
|
|
return IPPROTO_DONE;
|
|
|
|
}
|
|
|
|
ch = (struct sctp_chunkhdr *)((caddr_t)sh + sizeof(struct sctphdr));
|
|
|
|
iphlen = off;
|
|
|
|
offset = iphlen + sizeof(*sh) + sizeof(*ch);
|
2007-06-17 01:36:02 +00:00
|
|
|
SCTPDBG(SCTP_DEBUG_INPUT1,
|
|
|
|
"sctp6_input() length:%d iphlen:%d\n", pkt_len, iphlen);
|
|
|
|
|
2006-11-03 15:23:16 +00:00
|
|
|
|
|
|
|
#if defined(NFAITH) && NFAITH > 0
|
|
|
|
|
|
|
|
if (faithprefix_p != NULL && (*faithprefix_p) (&ip6->ip6_dst)) {
|
|
|
|
/* XXX send icmp6 host/port unreach? */
|
|
|
|
goto bad;
|
|
|
|
}
|
|
|
|
#endif /* NFAITH defined and > 0 */
|
|
|
|
SCTP_STAT_INCR(sctps_recvpackets);
|
|
|
|
SCTP_STAT_INCR_COUNTER64(sctps_inpackets);
|
2007-05-09 13:30:06 +00:00
|
|
|
SCTPDBG(SCTP_DEBUG_INPUT1, "V6 input gets a packet iphlen:%d pktlen:%d\n",
|
2007-05-28 11:17:24 +00:00
|
|
|
iphlen, pkt_len);
|
2006-11-03 15:23:16 +00:00
|
|
|
if (IN6_IS_ADDR_MULTICAST(&ip6->ip6_dst)) {
|
|
|
|
/* No multi-cast support in SCTP */
|
|
|
|
goto bad;
|
|
|
|
}
|
|
|
|
/* destination port of 0 is illegal, based on RFC2960. */
|
|
|
|
if (sh->dest_port == 0)
|
|
|
|
goto bad;
|
2009-02-03 11:04:03 +00:00
|
|
|
|
|
|
|
SCTPDBG(SCTP_DEBUG_CRCOFFLOAD,
|
|
|
|
"sctp_input(): Packet of length %d received on %s with csum_flags 0x%x.\n",
|
|
|
|
m->m_pkthdr.len,
|
|
|
|
if_name(m->m_pkthdr.rcvif),
|
|
|
|
m->m_pkthdr.csum_flags);
|
|
|
|
if (m->m_pkthdr.csum_flags & CSUM_SCTP_VALID) {
|
|
|
|
SCTP_STAT_INCR(sctps_recvhwcrc);
|
|
|
|
goto sctp_skip_csum;
|
|
|
|
}
|
2007-08-27 05:19:48 +00:00
|
|
|
check = sh->checksum; /* save incoming checksum */
|
2008-06-14 07:58:05 +00:00
|
|
|
if ((check == 0) && (SCTP_BASE_SYSCTL(sctp_no_csum_on_loopback)) &&
|
2007-08-27 05:19:48 +00:00
|
|
|
(IN6_ARE_ADDR_EQUAL(&ip6->ip6_src, &ip6->ip6_dst))) {
|
2009-02-03 11:04:03 +00:00
|
|
|
SCTP_STAT_INCR(sctps_recvnocrc);
|
2007-08-27 05:19:48 +00:00
|
|
|
goto sctp_skip_csum;
|
|
|
|
}
|
|
|
|
sh->checksum = 0; /* prepare for calc */
|
2009-02-03 11:04:03 +00:00
|
|
|
calc_check = sctp_calculate_cksum(m, iphlen);
|
|
|
|
SCTP_STAT_INCR(sctps_recvswcrc);
|
2007-08-27 05:19:48 +00:00
|
|
|
if (calc_check != check) {
|
2009-02-03 11:04:03 +00:00
|
|
|
SCTPDBG(SCTP_DEBUG_INPUT1, "Bad CSUM on SCTP packet calc_check:%x check:%x m:%p phlen:%d\n",
|
|
|
|
calc_check, check, m, iphlen);
|
2007-08-27 05:19:48 +00:00
|
|
|
stcb = sctp_findassociation_addr(m, iphlen, offset - sizeof(*ch),
|
|
|
|
sh, ch, &in6p, &net, vrf_id);
|
2008-06-14 07:58:05 +00:00
|
|
|
if ((net) && (port)) {
|
|
|
|
if (net->port == 0) {
|
|
|
|
sctp_pathmtu_adjustment(in6p, stcb, net, net->mtu - sizeof(struct udphdr));
|
|
|
|
}
|
|
|
|
net->port = port;
|
|
|
|
}
|
2007-08-27 05:19:48 +00:00
|
|
|
/* in6p's ref-count increased && stcb locked */
|
|
|
|
if ((in6p) && (stcb)) {
|
|
|
|
sctp_send_packet_dropped(stcb, net, m, iphlen, 1);
|
2007-09-08 11:35:11 +00:00
|
|
|
sctp_chunk_output((struct sctp_inpcb *)in6p, stcb, SCTP_OUTPUT_FROM_INPUT_ERROR, SCTP_SO_NOT_LOCKED);
|
2007-08-27 05:19:48 +00:00
|
|
|
} else if ((in6p != NULL) && (stcb == NULL)) {
|
|
|
|
refcount_up = 1;
|
2006-11-03 15:23:16 +00:00
|
|
|
}
|
2007-08-27 05:19:48 +00:00
|
|
|
SCTP_STAT_INCR(sctps_badsum);
|
|
|
|
SCTP_STAT_INCR_COUNTER32(sctps_checksumerrors);
|
|
|
|
goto bad;
|
2006-11-03 15:23:16 +00:00
|
|
|
}
|
2007-08-27 05:19:48 +00:00
|
|
|
sh->checksum = calc_check;
|
|
|
|
|
2006-12-29 20:21:42 +00:00
|
|
|
sctp_skip_csum:
|
2006-11-03 15:23:16 +00:00
|
|
|
net = NULL;
|
|
|
|
/*
|
|
|
|
* Locate pcb and tcb for datagram sctp_findassociation_addr() wants
|
|
|
|
* IP/SCTP/first chunk header...
|
|
|
|
*/
|
|
|
|
stcb = sctp_findassociation_addr(m, iphlen, offset - sizeof(*ch),
|
2007-04-03 11:15:32 +00:00
|
|
|
sh, ch, &in6p, &net, vrf_id);
|
2008-06-14 07:58:05 +00:00
|
|
|
if ((net) && (port)) {
|
|
|
|
if (net->port == 0) {
|
|
|
|
sctp_pathmtu_adjustment(in6p, stcb, net, net->mtu - sizeof(struct udphdr));
|
|
|
|
}
|
|
|
|
net->port = port;
|
|
|
|
}
|
2006-11-03 15:23:16 +00:00
|
|
|
/* in6p's ref-count increased */
|
|
|
|
if (in6p == NULL) {
|
|
|
|
struct sctp_init_chunk *init_chk, chunk_buf;
|
|
|
|
|
|
|
|
SCTP_STAT_INCR(sctps_noport);
|
|
|
|
if (ch->chunk_type == SCTP_INITIATION) {
|
|
|
|
/*
|
|
|
|
* we do a trick here to get the INIT tag, dig in
|
|
|
|
* and get the tag from the INIT and put it in the
|
|
|
|
* common header.
|
|
|
|
*/
|
|
|
|
init_chk = (struct sctp_init_chunk *)sctp_m_getptr(m,
|
|
|
|
iphlen + sizeof(*sh), sizeof(*init_chk),
|
2007-04-03 11:15:32 +00:00
|
|
|
(uint8_t *) & chunk_buf);
|
2007-05-09 13:30:06 +00:00
|
|
|
if (init_chk)
|
|
|
|
sh->v_tag = init_chk->init.initiate_tag;
|
|
|
|
else
|
|
|
|
sh->v_tag = 0;
|
2006-11-03 15:23:16 +00:00
|
|
|
}
|
2006-12-14 17:02:55 +00:00
|
|
|
if (ch->chunk_type == SCTP_SHUTDOWN_ACK) {
|
2008-06-14 07:58:05 +00:00
|
|
|
sctp_send_shutdown_complete2(m, iphlen, sh, vrf_id, port);
|
2006-12-14 17:02:55 +00:00
|
|
|
goto bad;
|
|
|
|
}
|
|
|
|
if (ch->chunk_type == SCTP_SHUTDOWN_COMPLETE) {
|
|
|
|
goto bad;
|
|
|
|
}
|
|
|
|
if (ch->chunk_type != SCTP_ABORT_ASSOCIATION)
|
2008-06-14 07:58:05 +00:00
|
|
|
sctp_send_abort(m, iphlen, sh, 0, NULL, vrf_id, port);
|
2006-11-03 15:23:16 +00:00
|
|
|
goto bad;
|
|
|
|
} else if (stcb == NULL) {
|
|
|
|
refcount_up = 1;
|
|
|
|
}
|
|
|
|
in6p_ip = (struct inpcb *)in6p;
|
2007-07-03 12:13:45 +00:00
|
|
|
#ifdef IPSEC
|
2006-11-03 15:23:16 +00:00
|
|
|
/*
|
|
|
|
* Check AH/ESP integrity.
|
|
|
|
*/
|
2006-11-05 13:25:18 +00:00
|
|
|
if (in6p_ip && (ipsec6_in_reject(m, in6p_ip))) {
|
2006-11-03 15:23:16 +00:00
|
|
|
/* XXX */
|
2009-09-17 15:11:12 +00:00
|
|
|
MODULE_GLOBAL(ipsec6stat).in_polvio++;
|
2006-11-03 15:23:16 +00:00
|
|
|
goto bad;
|
2006-11-05 13:25:18 +00:00
|
|
|
}
|
2007-07-14 09:36:28 +00:00
|
|
|
#endif /* IPSEC */
|
2006-11-03 15:23:16 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* CONTROL chunk processing
|
|
|
|
*/
|
|
|
|
offset -= sizeof(*ch);
|
|
|
|
ecn_bits = ((ntohl(ip6->ip6_flow) >> 20) & 0x000000ff);
|
2006-12-29 20:21:42 +00:00
|
|
|
|
|
|
|
/* Length now holds the total packet length payload + iphlen */
|
|
|
|
length = ntohs(ip6->ip6_plen) + iphlen;
|
|
|
|
|
2007-05-17 12:16:24 +00:00
|
|
|
/* sa_ignore NO_NULL_CHK */
|
2007-05-08 14:32:53 +00:00
|
|
|
sctp_common_input_processing(&m, iphlen, offset, length, sh, ch,
|
2008-06-14 07:58:05 +00:00
|
|
|
in6p, stcb, net, ecn_bits, vrf_id, port);
|
2006-11-03 15:23:16 +00:00
|
|
|
/* inp's ref-count reduced && stcb unlocked */
|
|
|
|
/* XXX this stuff below gets moved to appropriate parts later... */
|
|
|
|
if (m)
|
2007-05-08 00:21:05 +00:00
|
|
|
sctp_m_freem(m);
|
2006-11-03 15:23:16 +00:00
|
|
|
if ((in6p) && refcount_up) {
|
|
|
|
/* reduce ref-count */
|
|
|
|
SCTP_INP_WLOCK(in6p);
|
|
|
|
SCTP_INP_DECR_REF(in6p);
|
|
|
|
SCTP_INP_WUNLOCK(in6p);
|
|
|
|
}
|
|
|
|
return IPPROTO_DONE;
|
|
|
|
|
|
|
|
bad:
|
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
|
|
|
if ((in6p) && refcount_up) {
|
|
|
|
/* reduce ref-count */
|
|
|
|
SCTP_INP_WLOCK(in6p);
|
|
|
|
SCTP_INP_DECR_REF(in6p);
|
|
|
|
SCTP_INP_WUNLOCK(in6p);
|
|
|
|
}
|
|
|
|
if (m)
|
2007-05-08 00:21:05 +00:00
|
|
|
sctp_m_freem(m);
|
2006-11-03 15:23:16 +00:00
|
|
|
return IPPROTO_DONE;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void
|
2007-07-05 16:23:49 +00:00
|
|
|
sctp6_notify_mbuf(struct sctp_inpcb *inp, struct icmp6_hdr *icmp6,
|
|
|
|
struct sctphdr *sh, struct sctp_tcb *stcb, struct sctp_nets *net)
|
2006-11-03 15:23:16 +00:00
|
|
|
{
|
2007-04-03 11:15:32 +00:00
|
|
|
uint32_t nxtsz;
|
2006-11-03 15:23:16 +00:00
|
|
|
|
|
|
|
if ((inp == NULL) || (stcb == NULL) || (net == NULL) ||
|
|
|
|
(icmp6 == NULL) || (sh == NULL)) {
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
/* First do we even look at it? */
|
|
|
|
if (ntohl(sh->v_tag) != (stcb->asoc.peer_vtag))
|
|
|
|
goto out;
|
|
|
|
|
|
|
|
if (icmp6->icmp6_type != ICMP6_PACKET_TOO_BIG) {
|
|
|
|
/* not PACKET TO BIG */
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
/*
|
|
|
|
* ok we need to look closely. We could even get smarter and look at
|
|
|
|
* anyone that we sent to in case we get a different ICMP that tells
|
|
|
|
* us there is no way to reach a host, but for this impl, all we
|
|
|
|
* care about is MTU discovery.
|
|
|
|
*/
|
|
|
|
nxtsz = ntohl(icmp6->icmp6_mtu);
|
|
|
|
/* Stop any PMTU timer */
|
2006-12-14 17:02:55 +00:00
|
|
|
sctp_timer_stop(SCTP_TIMER_TYPE_PATHMTURAISE, inp, stcb, NULL, SCTP_FROM_SCTP6_USRREQ + SCTP_LOC_1);
|
2006-11-03 15:23:16 +00:00
|
|
|
|
|
|
|
/* Adjust destination size limit */
|
|
|
|
if (net->mtu > nxtsz) {
|
|
|
|
net->mtu = nxtsz;
|
2008-12-06 13:19:54 +00:00
|
|
|
if (net->port) {
|
|
|
|
net->mtu -= sizeof(struct udphdr);
|
|
|
|
}
|
2006-11-03 15:23:16 +00:00
|
|
|
}
|
|
|
|
/* now what about the ep? */
|
|
|
|
if (stcb->asoc.smallest_mtu > nxtsz) {
|
|
|
|
struct sctp_tmit_chunk *chk;
|
|
|
|
|
|
|
|
/* Adjust that too */
|
|
|
|
stcb->asoc.smallest_mtu = nxtsz;
|
|
|
|
/* now off to subtract IP_DF flag if needed */
|
|
|
|
|
|
|
|
TAILQ_FOREACH(chk, &stcb->asoc.send_queue, sctp_next) {
|
2007-04-03 11:15:32 +00:00
|
|
|
if ((uint32_t) (chk->send_size + IP_HDR_SIZE) > nxtsz) {
|
2006-11-03 15:23:16 +00:00
|
|
|
chk->flags |= CHUNK_FLAGS_FRAGMENT_OK;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
TAILQ_FOREACH(chk, &stcb->asoc.sent_queue, sctp_next) {
|
2007-04-03 11:15:32 +00:00
|
|
|
if ((uint32_t) (chk->send_size + IP_HDR_SIZE) > nxtsz) {
|
2006-11-03 15:23:16 +00:00
|
|
|
/*
|
|
|
|
* For this guy we also mark for immediate
|
|
|
|
* resend since we sent to big of chunk
|
|
|
|
*/
|
|
|
|
chk->flags |= CHUNK_FLAGS_FRAGMENT_OK;
|
|
|
|
if (chk->sent != SCTP_DATAGRAM_RESEND)
|
|
|
|
stcb->asoc.sent_queue_retran_cnt++;
|
|
|
|
chk->sent = SCTP_DATAGRAM_RESEND;
|
|
|
|
chk->rec.data.doing_fast_retransmit = 0;
|
|
|
|
|
|
|
|
chk->sent = SCTP_DATAGRAM_RESEND;
|
|
|
|
/* Clear any time so NO RTT is being done */
|
|
|
|
chk->sent_rcv_time.tv_sec = 0;
|
|
|
|
chk->sent_rcv_time.tv_usec = 0;
|
|
|
|
stcb->asoc.total_flight -= chk->send_size;
|
|
|
|
net->flight_size -= chk->send_size;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
sctp_timer_start(SCTP_TIMER_TYPE_PATHMTURAISE, inp, stcb, NULL);
|
|
|
|
out:
|
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
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-09-13 10:36:43 +00:00
|
|
|
void
|
2007-09-08 17:48:46 +00:00
|
|
|
sctp6_notify(struct sctp_inpcb *inp,
|
|
|
|
struct icmp6_hdr *icmph,
|
|
|
|
struct sctphdr *sh,
|
|
|
|
struct sockaddr *to,
|
|
|
|
struct sctp_tcb *stcb,
|
|
|
|
struct sctp_nets *net)
|
|
|
|
{
|
|
|
|
#if defined (__APPLE__) || defined(SCTP_SO_LOCK_TESTING)
|
|
|
|
struct socket *so;
|
|
|
|
|
|
|
|
#endif
|
|
|
|
/* protection */
|
|
|
|
int reason;
|
|
|
|
|
|
|
|
|
|
|
|
if ((inp == NULL) || (stcb == NULL) || (net == NULL) ||
|
|
|
|
(sh == NULL) || (to == NULL)) {
|
|
|
|
if (stcb)
|
|
|
|
SCTP_TCB_UNLOCK(stcb);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
/* First job is to verify the vtag matches what I would send */
|
|
|
|
if (ntohl(sh->v_tag) != (stcb->asoc.peer_vtag)) {
|
|
|
|
SCTP_TCB_UNLOCK(stcb);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (icmph->icmp6_type != ICMP_UNREACH) {
|
|
|
|
/* We only care about unreachable */
|
|
|
|
SCTP_TCB_UNLOCK(stcb);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if ((icmph->icmp6_code == ICMP_UNREACH_NET) ||
|
|
|
|
(icmph->icmp6_code == ICMP_UNREACH_HOST) ||
|
|
|
|
(icmph->icmp6_code == ICMP_UNREACH_NET_UNKNOWN) ||
|
|
|
|
(icmph->icmp6_code == ICMP_UNREACH_HOST_UNKNOWN) ||
|
|
|
|
(icmph->icmp6_code == ICMP_UNREACH_ISOLATED) ||
|
|
|
|
(icmph->icmp6_code == ICMP_UNREACH_NET_PROHIB) ||
|
|
|
|
(icmph->icmp6_code == ICMP_UNREACH_HOST_PROHIB) ||
|
|
|
|
(icmph->icmp6_code == ICMP_UNREACH_FILTER_PROHIB)) {
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Hmm reachablity problems we must examine closely. If its
|
|
|
|
* not reachable, we may have lost a network. Or if there is
|
|
|
|
* NO protocol at the other end named SCTP. well we consider
|
|
|
|
* it a OOTB abort.
|
|
|
|
*/
|
|
|
|
if (net->dest_state & SCTP_ADDR_REACHABLE) {
|
|
|
|
/* Ok that destination is NOT reachable */
|
|
|
|
SCTP_PRINTF("ICMP (thresh %d/%d) takes interface %p down\n",
|
|
|
|
net->error_count,
|
|
|
|
net->failure_threshold,
|
|
|
|
net);
|
|
|
|
|
|
|
|
net->dest_state &= ~SCTP_ADDR_REACHABLE;
|
|
|
|
net->dest_state |= SCTP_ADDR_NOT_REACHABLE;
|
|
|
|
/*
|
|
|
|
* JRS 5/14/07 - If a destination is unreachable,
|
|
|
|
* the PF bit is turned off. This allows an
|
|
|
|
* unambiguous use of the PF bit for destinations
|
|
|
|
* that are reachable but potentially failed. If the
|
|
|
|
* destination is set to the unreachable state, also
|
|
|
|
* set the destination to the PF state.
|
|
|
|
*/
|
|
|
|
/*
|
|
|
|
* Add debug message here if destination is not in
|
|
|
|
* PF state.
|
|
|
|
*/
|
|
|
|
/* Stop any running T3 timers here? */
|
2008-06-14 07:58:05 +00:00
|
|
|
if (SCTP_BASE_SYSCTL(sctp_cmt_on_off) && SCTP_BASE_SYSCTL(sctp_cmt_pf)) {
|
2007-09-08 17:48:46 +00:00
|
|
|
net->dest_state &= ~SCTP_ADDR_PF;
|
|
|
|
SCTPDBG(SCTP_DEBUG_TIMER4, "Destination %p moved from PF to unreachable.\n",
|
|
|
|
net);
|
|
|
|
}
|
|
|
|
net->error_count = net->failure_threshold + 1;
|
|
|
|
sctp_ulp_notify(SCTP_NOTIFY_INTERFACE_DOWN,
|
|
|
|
stcb, SCTP_FAILED_THRESHOLD,
|
|
|
|
(void *)net, SCTP_SO_NOT_LOCKED);
|
|
|
|
}
|
|
|
|
SCTP_TCB_UNLOCK(stcb);
|
|
|
|
} else if ((icmph->icmp6_code == ICMP_UNREACH_PROTOCOL) ||
|
|
|
|
(icmph->icmp6_code == ICMP_UNREACH_PORT)) {
|
|
|
|
/*
|
|
|
|
* Here the peer is either playing tricks on us, including
|
|
|
|
* an address that belongs to someone who does not support
|
|
|
|
* SCTP OR was a userland implementation that shutdown and
|
|
|
|
* now is dead. In either case treat it like a OOTB abort
|
|
|
|
* with no TCB
|
|
|
|
*/
|
|
|
|
reason = SCTP_PEER_FAULTY;
|
|
|
|
sctp_abort_notification(stcb, reason, SCTP_SO_NOT_LOCKED);
|
|
|
|
#if defined (__APPLE__) || defined(SCTP_SO_LOCK_TESTING)
|
|
|
|
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);
|
|
|
|
#endif
|
|
|
|
(void)sctp_free_assoc(inp, stcb, SCTP_NORMAL_PROC, SCTP_FROM_SCTP_USRREQ + SCTP_LOC_2);
|
|
|
|
#if defined (__APPLE__) || defined(SCTP_SO_LOCK_TESTING)
|
|
|
|
SCTP_SOCKET_UNLOCK(so, 1);
|
|
|
|
/* SCTP_TCB_UNLOCK(stcb); MT: I think this is not needed. */
|
|
|
|
#endif
|
|
|
|
/* no need to unlock here, since the TCB is gone */
|
|
|
|
} else {
|
|
|
|
SCTP_TCB_UNLOCK(stcb);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
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
|
|
|
{
|
|
|
|
struct sctphdr sh;
|
|
|
|
struct ip6ctlparam *ip6cp = NULL;
|
2007-03-15 11:27:14 +00:00
|
|
|
uint32_t vrf_id;
|
2006-11-03 15:23:16 +00:00
|
|
|
|
2007-03-15 11:27:14 +00:00
|
|
|
vrf_id = SCTP_DEFAULT_VRFID;
|
|
|
|
|
2006-11-03 15:23:16 +00:00
|
|
|
if (pktdst->sa_family != AF_INET6 ||
|
|
|
|
pktdst->sa_len != sizeof(struct sockaddr_in6))
|
|
|
|
return;
|
|
|
|
|
|
|
|
if ((unsigned)cmd >= PRC_NCMDS)
|
|
|
|
return;
|
|
|
|
if (PRC_IS_REDIRECT(cmd)) {
|
|
|
|
d = NULL;
|
|
|
|
} else if (inet6ctlerrmap[cmd] == 0) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
/* if the parameter is from icmp6, decode it. */
|
|
|
|
if (d != NULL) {
|
|
|
|
ip6cp = (struct ip6ctlparam *)d;
|
|
|
|
} else {
|
|
|
|
ip6cp = (struct ip6ctlparam *)NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (ip6cp) {
|
|
|
|
/*
|
|
|
|
* XXX: We assume that when IPV6 is non NULL, M and OFF are
|
|
|
|
* valid.
|
|
|
|
*/
|
|
|
|
/* check if we can safely examine src and dst ports */
|
|
|
|
struct sctp_inpcb *inp = NULL;
|
|
|
|
struct sctp_tcb *stcb = NULL;
|
|
|
|
struct sctp_nets *net = NULL;
|
|
|
|
struct sockaddr_in6 final;
|
|
|
|
|
2006-12-29 20:21:42 +00:00
|
|
|
if (ip6cp->ip6c_m == NULL)
|
2006-11-03 15:23:16 +00:00
|
|
|
return;
|
|
|
|
|
|
|
|
bzero(&sh, sizeof(sh));
|
|
|
|
bzero(&final, sizeof(final));
|
|
|
|
inp = NULL;
|
|
|
|
net = NULL;
|
|
|
|
m_copydata(ip6cp->ip6c_m, ip6cp->ip6c_off, sizeof(sh),
|
|
|
|
(caddr_t)&sh);
|
|
|
|
ip6cp->ip6c_src->sin6_port = sh.src_port;
|
|
|
|
final.sin6_len = sizeof(final);
|
|
|
|
final.sin6_family = AF_INET6;
|
|
|
|
final.sin6_addr = ((struct sockaddr_in6 *)pktdst)->sin6_addr;
|
|
|
|
final.sin6_port = sh.dest_port;
|
|
|
|
stcb = sctp_findassociation_addr_sa((struct sockaddr *)ip6cp->ip6c_src,
|
|
|
|
(struct sockaddr *)&final,
|
2007-03-15 11:27:14 +00:00
|
|
|
&inp, &net, 1, vrf_id);
|
2006-11-03 15:23:16 +00:00
|
|
|
/* inp's ref-count increased && stcb locked */
|
|
|
|
if (stcb != NULL && inp && (inp->sctp_socket != NULL)) {
|
|
|
|
if (cmd == PRC_MSGSIZE) {
|
|
|
|
sctp6_notify_mbuf(inp,
|
|
|
|
ip6cp->ip6c_icmp6,
|
|
|
|
&sh,
|
|
|
|
stcb,
|
|
|
|
net);
|
|
|
|
/* inp's ref-count reduced && stcb unlocked */
|
|
|
|
} else {
|
2007-09-08 17:48:46 +00:00
|
|
|
sctp6_notify(inp, ip6cp->ip6c_icmp6, &sh,
|
2006-11-03 15:23:16 +00:00
|
|
|
(struct sockaddr *)&final,
|
|
|
|
stcb, net);
|
|
|
|
/* inp's ref-count reduced && stcb unlocked */
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (PRC_IS_REDIRECT(cmd) && inp) {
|
|
|
|
in6_rtchange((struct in6pcb *)inp,
|
|
|
|
inet6ctlerrmap[cmd]);
|
|
|
|
}
|
|
|
|
if (inp) {
|
|
|
|
/* reduce inp's ref-count */
|
|
|
|
SCTP_INP_WLOCK(inp);
|
|
|
|
SCTP_INP_DECR_REF(inp);
|
|
|
|
SCTP_INP_WUNLOCK(inp);
|
|
|
|
}
|
|
|
|
if (stcb)
|
|
|
|
SCTP_TCB_UNLOCK(stcb);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* 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);
|
|
|
|
|
|
|
|
stcb = sctp_findassociation_addr_sa(sin6tosa(&addrs[0]),
|
|
|
|
sin6tosa(&addrs[1]),
|
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;
|
2007-09-08 17:48:46 +00:00
|
|
|
if (inp == 0) {
|
|
|
|
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
|
|
|
|
sctp6_attach(struct socket *so, int proto, struct thread *p)
|
|
|
|
{
|
|
|
|
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);
|
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
|
|
|
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)
|
|
|
|
return error;
|
|
|
|
}
|
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)
|
|
|
|
return error;
|
|
|
|
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);
|
2006-11-03 15:23:16 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
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;
|
2007-08-24 00:53:53 +00:00
|
|
|
if (inp == 0) {
|
|
|
|
SCTP_LTRACE_ERR_RET(inp, 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
|
|
|
}
|
2007-05-28 11:17:24 +00:00
|
|
|
if (addr) {
|
|
|
|
if ((addr->sa_family == AF_INET6) &&
|
|
|
|
(addr->sa_len != sizeof(struct sockaddr_in6))) {
|
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;
|
|
|
|
}
|
|
|
|
if ((addr->sa_family == AF_INET) &&
|
|
|
|
(addr->sa_len != sizeof(struct sockaddr_in))) {
|
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;
|
|
|
|
}
|
|
|
|
}
|
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)) {
|
2006-11-03 15:23:16 +00:00
|
|
|
if (addr->sa_family == AF_INET) {
|
|
|
|
/* binding v4 addr to v6 socket, so reset flags */
|
|
|
|
inp6->inp_vflag |= INP_IPV4;
|
|
|
|
inp6->inp_vflag &= ~INP_IPV6;
|
|
|
|
} else {
|
|
|
|
struct sockaddr_in6 *sin6_p;
|
|
|
|
|
|
|
|
sin6_p = (struct sockaddr_in6 *)addr;
|
|
|
|
|
|
|
|
if (IN6_IS_ADDR_UNSPECIFIED(&sin6_p->sin6_addr)) {
|
|
|
|
inp6->inp_vflag |= INP_IPV4;
|
|
|
|
} else 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;
|
2007-07-24 20:06:02 +00:00
|
|
|
error = sctp_inpcb_bind(so, (struct sockaddr *)&sin, NULL, p);
|
2006-11-03 15:23:16 +00:00
|
|
|
return error;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else if (addr != NULL) {
|
|
|
|
/* IPV6_V6ONLY socket */
|
|
|
|
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);
|
2006-11-03 15:23:16 +00:00
|
|
|
return EINVAL;
|
|
|
|
} else {
|
|
|
|
struct sockaddr_in6 *sin6_p;
|
|
|
|
|
|
|
|
sin6_p = (struct sockaddr_in6 *)addr;
|
|
|
|
|
2007-09-08 17:48:46 +00:00
|
|
|
if (IN6_IS_ADDR_V4MAPPED(&sin6_p->sin6_addr)) {
|
2006-11-03 15:23:16 +00:00
|
|
|
/* can't bind v4-mapped addrs either! */
|
|
|
|
/* NOTE: we don't support SIIT */
|
2007-08-24 00:53:53 +00:00
|
|
|
SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP6_USRREQ, EINVAL);
|
2007-09-08 17:48:46 +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);
|
2006-11-03 15:23:16 +00:00
|
|
|
return error;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
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 inpcb *in_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);
|
2006-11-03 15:23:16 +00:00
|
|
|
return EINVAL;
|
|
|
|
}
|
|
|
|
in_inp = (struct inpcb *)inp;
|
|
|
|
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);
|
2006-11-03 15:23:16 +00:00
|
|
|
return EINVAL;
|
|
|
|
}
|
|
|
|
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);
|
2006-11-03 15:23:16 +00:00
|
|
|
return EINVAL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (IN6_IS_ADDR_V4MAPPED(&sin6->sin6_addr)) {
|
2009-09-17 15:11:12 +00:00
|
|
|
if (!MODULE_GLOBAL(ip6_v6only)) {
|
2006-11-03 15:23:16 +00:00
|
|
|
struct sockaddr_in sin;
|
|
|
|
|
|
|
|
/* 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);
|
|
|
|
} else {
|
|
|
|
/* mapped addresses aren't enabled */
|
2007-08-24 00:53:53 +00:00
|
|
|
SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP6_USRREQ, EINVAL);
|
2006-11-03 15:23:16 +00:00
|
|
|
return EINVAL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#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 in6pcb *inp6;
|
|
|
|
struct sctp_tcb *stcb;
|
|
|
|
|
|
|
|
#ifdef INET
|
|
|
|
struct sockaddr_in6 *sin6;
|
|
|
|
struct sockaddr_storage ss;
|
|
|
|
|
|
|
|
#endif /* INET */
|
|
|
|
|
|
|
|
inp6 = (struct in6pcb *)so->so_pcb;
|
|
|
|
inp = (struct sctp_inpcb *)so->so_pcb;
|
|
|
|
if (inp == 0) {
|
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);
|
|
|
|
}
|
|
|
|
if ((addr->sa_family == AF_INET6) && (addr->sa_len != sizeof(struct sockaddr_in6))) {
|
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);
|
|
|
|
}
|
|
|
|
if ((addr->sa_family == AF_INET) && (addr->sa_len != sizeof(struct sockaddr_in))) {
|
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);
|
|
|
|
}
|
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);
|
2006-11-03 15:23:16 +00:00
|
|
|
return EINVAL;
|
|
|
|
}
|
|
|
|
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);
|
2006-11-03 15:23:16 +00:00
|
|
|
return EINVAL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (IN6_IS_ADDR_V4MAPPED(&sin6->sin6_addr)) {
|
2009-09-17 15:11:12 +00:00
|
|
|
if (!MODULE_GLOBAL(ip6_v6only)) {
|
2006-11-03 15:23:16 +00:00
|
|
|
/* convert v4-mapped into v4 addr */
|
|
|
|
in6_sin6_2_sin((struct sockaddr_in *)&ss, sin6);
|
|
|
|
addr = (struct sockaddr *)&ss;
|
|
|
|
} else {
|
|
|
|
/* mapped addresses aren't enabled */
|
|
|
|
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);
|
2006-11-03 15:23:16 +00:00
|
|
|
return EINVAL;
|
|
|
|
}
|
|
|
|
} else
|
|
|
|
#endif /* INET */
|
|
|
|
addr = addr; /* for true v6 address case */
|
|
|
|
|
|
|
|
/* 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 */
|
2010-04-03 15:40:14 +00:00
|
|
|
stcb = sctp_aloc_assoc(inp, addr, &error, 0, vrf_id, 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);
|
|
|
|
return error;
|
|
|
|
}
|
|
|
|
|
|
|
|
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.
|
|
|
|
*/
|
|
|
|
SCTP_MALLOC_SONAME(sin6, struct sockaddr_in6 *, sizeof *sin6);
|
|
|
|
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);
|
2006-11-03 15:23:16 +00:00
|
|
|
return ECONNRESET;
|
|
|
|
}
|
|
|
|
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) {
|
|
|
|
goto notConn6;
|
|
|
|
}
|
|
|
|
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 */
|
|
|
|
goto notConn6;
|
|
|
|
}
|
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 */
|
|
|
|
notConn6:
|
|
|
|
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;
|
|
|
|
|
2007-03-15 11:27:14 +00:00
|
|
|
sin_a = (struct sockaddr_in6 *)&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);
|
2006-11-03 15:23:16 +00:00
|
|
|
return ENOENT;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
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)
|
|
|
|
{
|
|
|
|
struct sockaddr_in6 *sin6 = (struct sockaddr_in6 *)*addr;
|
|
|
|
int fnd;
|
|
|
|
struct sockaddr_in6 *sin_a6;
|
|
|
|
struct sctp_inpcb *inp;
|
|
|
|
struct sctp_tcb *stcb;
|
|
|
|
struct sctp_nets *net;
|
|
|
|
|
|
|
|
int error;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Do the malloc first in case it blocks.
|
|
|
|
*/
|
|
|
|
inp = (struct sctp_inpcb *)so->so_pcb;
|
|
|
|
if ((inp->sctp_flags & SCTP_PCB_FLAGS_CONNECTED) == 0) {
|
|
|
|
/* UDP type and listeners will drop out here */
|
2007-08-24 00:53:53 +00:00
|
|
|
SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP6_USRREQ, ENOTCONN);
|
2006-11-03 15:23:16 +00:00
|
|
|
return (ENOTCONN);
|
|
|
|
}
|
|
|
|
SCTP_MALLOC_SONAME(sin6, struct sockaddr_in6 *, sizeof *sin6);
|
|
|
|
sin6->sin6_family = AF_INET6;
|
|
|
|
sin6->sin6_len = sizeof(*sin6);
|
|
|
|
|
|
|
|
/* We must recapture incase we blocked */
|
|
|
|
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);
|
2006-11-03 15:23:16 +00:00
|
|
|
return ECONNRESET;
|
|
|
|
}
|
|
|
|
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);
|
2006-11-03 15:23:16 +00:00
|
|
|
return ECONNRESET;
|
|
|
|
}
|
|
|
|
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);
|
2006-11-03 15:23:16 +00:00
|
|
|
return ENOENT;
|
|
|
|
}
|
|
|
|
if ((error = sa6_recoverscope(sin6)) != 0)
|
|
|
|
return (error);
|
|
|
|
*addr = (struct sockaddr *)sin6;
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
sctp6_in6getaddr(struct socket *so, struct sockaddr **nam)
|
|
|
|
{
|
|
|
|
struct sockaddr *addr;
|
|
|
|
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);
|
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
|
|
|
/* allow v6 addresses precedence */
|
|
|
|
error = sctp6_getaddr(so, nam);
|
|
|
|
if (error) {
|
|
|
|
/* try v4 next if v6 failed */
|
|
|
|
error = sctp_ingetaddr(so, nam);
|
|
|
|
if (error) {
|
|
|
|
return (error);
|
|
|
|
}
|
|
|
|
addr = *nam;
|
|
|
|
/* if I'm V6ONLY, convert it to v4-mapped */
|
2007-01-15 15:12:10 +00:00
|
|
|
if (SCTP_IPV6_V6ONLY(inp6)) {
|
2006-11-03 15:23:16 +00:00
|
|
|
struct sockaddr_in6 sin6;
|
|
|
|
|
|
|
|
in6_sin_2_v4mapsin6((struct sockaddr_in *)addr, &sin6);
|
|
|
|
memcpy(addr, &sin6, sizeof(struct sockaddr_in6));
|
2007-04-14 09:44:09 +00:00
|
|
|
|
2006-11-03 15:23:16 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return (error);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static int
|
|
|
|
sctp6_getpeeraddr(struct socket *so, struct sockaddr **nam)
|
|
|
|
{
|
|
|
|
struct sockaddr *addr = *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);
|
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
|
|
|
/* allow v6 addresses precedence */
|
|
|
|
error = sctp6_peeraddr(so, nam);
|
|
|
|
if (error) {
|
|
|
|
/* try v4 next if v6 failed */
|
|
|
|
error = sctp_peeraddr(so, nam);
|
|
|
|
if (error) {
|
|
|
|
return (error);
|
|
|
|
}
|
|
|
|
/* if I'm V6ONLY, convert it to v4-mapped */
|
2007-01-15 15:12:10 +00:00
|
|
|
if (SCTP_IPV6_V6ONLY(inp6)) {
|
2006-11-03 15:23:16 +00:00
|
|
|
struct sockaddr_in6 sin6;
|
|
|
|
|
|
|
|
in6_sin_2_v4mapsin6((struct sockaddr_in *)addr, &sin6);
|
|
|
|
memcpy(addr, &sin6, sizeof(struct sockaddr_in6));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return error;
|
|
|
|
}
|
|
|
|
|
|
|
|
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
|
|
|
|
};
|