2006-11-03 15:23:16 +00:00
|
|
|
/*-
|
2008-12-06 13:19:54 +00:00
|
|
|
* Copyright (c) 2001-2008, by Cisco Systems, Inc. All rights reserved.
|
2011-02-05 12:12:51 +00:00
|
|
|
* Copyright (c) 2008-2011, by Randall Stewart. All rights reserved.
|
|
|
|
* Copyright (c) 2008-2011, 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,
|
|
|
|
* 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: sctp_usrreq.c,v 1.48 2005/03/07 23:26:08 itojun Exp $ */
|
|
|
|
|
|
|
|
#include <sys/cdefs.h>
|
|
|
|
__FBSDID("$FreeBSD$");
|
|
|
|
#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-03-19 06:53:02 +00:00
|
|
|
#if defined(INET6)
|
|
|
|
#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>
|
|
|
|
#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-05-29 09:29:03 +00:00
|
|
|
#include <netinet/sctp_bsd_addr.h>
|
2008-12-06 13:19:54 +00:00
|
|
|
#include <netinet/udp.h>
|
2007-05-29 09:29:03 +00:00
|
|
|
|
2006-11-08 00:21:13 +00:00
|
|
|
|
2006-11-03 15:23:16 +00:00
|
|
|
|
2011-01-19 22:10:35 +00:00
|
|
|
extern struct sctp_cc_functions sctp_cc_functions[];
|
2011-01-23 19:36:28 +00:00
|
|
|
extern struct sctp_ss_functions sctp_ss_functions[];
|
2006-11-03 15:23:16 +00:00
|
|
|
|
|
|
|
void
|
|
|
|
sctp_init(void)
|
|
|
|
{
|
|
|
|
u_long sb_max_adj;
|
|
|
|
|
2008-06-14 07:58:05 +00:00
|
|
|
/* Initialize and modify the sysctled variables */
|
|
|
|
sctp_init_sysctls();
|
2006-11-03 15:23:16 +00:00
|
|
|
if ((nmbclusters / 8) > SCTP_ASOC_MAX_CHUNKS_ON_QUEUE)
|
2008-06-14 07:58:05 +00:00
|
|
|
SCTP_BASE_SYSCTL(sctp_max_chunks_on_queue) = (nmbclusters / 8);
|
2006-11-03 15:23:16 +00:00
|
|
|
/*
|
|
|
|
* Allow a user to take no more than 1/2 the number of clusters or
|
|
|
|
* the SB_MAX whichever is smaller for the send window.
|
|
|
|
*/
|
|
|
|
sb_max_adj = (u_long)((u_quad_t) (SB_MAX) * MCLBYTES / (MSIZE + MCLBYTES));
|
2008-06-14 07:58:05 +00:00
|
|
|
SCTP_BASE_SYSCTL(sctp_sendspace) = min(sb_max_adj,
|
2007-05-28 11:17:24 +00:00
|
|
|
(((uint32_t) nmbclusters / 2) * SCTP_DEFAULT_MAXSEGMENT));
|
2006-11-03 15:23:16 +00:00
|
|
|
/*
|
|
|
|
* Now for the recv window, should we take the same amount? or
|
|
|
|
* should I do 1/2 the SB_MAX instead in the SB_MAX min above. For
|
|
|
|
* now I will just copy.
|
|
|
|
*/
|
2008-06-14 07:58:05 +00:00
|
|
|
SCTP_BASE_SYSCTL(sctp_recvspace) = SCTP_BASE_SYSCTL(sctp_sendspace);
|
2006-11-03 15:23:16 +00:00
|
|
|
|
2008-06-14 07:58:05 +00:00
|
|
|
SCTP_BASE_VAR(first_time) = 0;
|
|
|
|
SCTP_BASE_VAR(sctp_pcb_initialized) = 0;
|
|
|
|
sctp_pcb_init();
|
|
|
|
#if defined(SCTP_PACKET_LOGGING)
|
|
|
|
SCTP_BASE_VAR(packet_log_writers) = 0;
|
|
|
|
SCTP_BASE_VAR(packet_log_end) = 0;
|
|
|
|
bzero(&SCTP_BASE_VAR(packet_log_buffer), SCTP_PACKET_LOG_SIZE);
|
|
|
|
#endif
|
2006-11-03 15:23:16 +00:00
|
|
|
|
|
|
|
|
2008-06-14 07:58:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
sctp_finish(void)
|
|
|
|
{
|
|
|
|
sctp_pcb_finish();
|
|
|
|
}
|
2007-01-15 15:12:10 +00:00
|
|
|
|
|
|
|
|
2006-11-03 15:23:16 +00:00
|
|
|
|
2008-05-20 13:47:46 +00:00
|
|
|
void
|
2007-03-19 06:53:02 +00:00
|
|
|
sctp_pathmtu_adjustment(struct sctp_inpcb *inp,
|
2006-11-03 15:23:16 +00:00
|
|
|
struct sctp_tcb *stcb,
|
|
|
|
struct sctp_nets *net,
|
|
|
|
uint16_t nxtsz)
|
|
|
|
{
|
|
|
|
struct sctp_tmit_chunk *chk;
|
2009-09-16 14:23:31 +00:00
|
|
|
uint16_t overhead;
|
2006-11-03 15:23:16 +00:00
|
|
|
|
|
|
|
/* Adjust that too */
|
|
|
|
stcb->asoc.smallest_mtu = nxtsz;
|
|
|
|
/* now off to subtract IP_DF flag if needed */
|
2009-09-16 14:23:31 +00:00
|
|
|
overhead = IP_HDR_SIZE;
|
|
|
|
if (sctp_auth_is_required_chunk(SCTP_DATA, stcb->asoc.peer_auth_chunks)) {
|
|
|
|
overhead += sctp_get_auth_chunk_len(stcb->asoc.peer_hmac_id);
|
|
|
|
}
|
2006-11-03 15:23:16 +00:00
|
|
|
TAILQ_FOREACH(chk, &stcb->asoc.send_queue, sctp_next) {
|
2009-09-16 14:23:31 +00:00
|
|
|
if ((chk->send_size + overhead) > nxtsz) {
|
2006-11-03 15:23:16 +00:00
|
|
|
chk->flags |= CHUNK_FLAGS_FRAGMENT_OK;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
TAILQ_FOREACH(chk, &stcb->asoc.sent_queue, sctp_next) {
|
2009-09-16 14:23:31 +00:00
|
|
|
if ((chk->send_size + overhead) > 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;
|
2009-04-04 11:43:32 +00:00
|
|
|
if (chk->sent < SCTP_DATAGRAM_RESEND) {
|
|
|
|
sctp_flight_size_decrease(chk);
|
|
|
|
sctp_total_flight_decrease(stcb, chk);
|
|
|
|
}
|
2006-11-03 15:23:16 +00:00
|
|
|
if (chk->sent != SCTP_DATAGRAM_RESEND) {
|
|
|
|
sctp_ucount_incr(stcb->asoc.sent_queue_retran_cnt);
|
|
|
|
}
|
|
|
|
chk->sent = SCTP_DATAGRAM_RESEND;
|
|
|
|
chk->rec.data.doing_fast_retransmit = 0;
|
2008-06-14 07:58:05 +00:00
|
|
|
if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_FLIGHT_LOGGING_ENABLE) {
|
2007-06-14 22:59:04 +00:00
|
|
|
sctp_misc_ints(SCTP_FLIGHT_LOG_DOWN_PMTU,
|
|
|
|
chk->whoTo->flight_size,
|
|
|
|
chk->book_size,
|
|
|
|
(uintptr_t) chk->whoTo,
|
|
|
|
chk->rec.data.TSN_seq);
|
|
|
|
}
|
2006-11-03 15:23:16 +00:00
|
|
|
/* Clear any time so NO RTT is being done */
|
|
|
|
chk->do_rtt = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
sctp_notify_mbuf(struct sctp_inpcb *inp,
|
|
|
|
struct sctp_tcb *stcb,
|
|
|
|
struct sctp_nets *net,
|
|
|
|
struct ip *ip,
|
|
|
|
struct sctphdr *sh)
|
|
|
|
{
|
|
|
|
struct icmp *icmph;
|
|
|
|
int totsz, tmr_stopped = 0;
|
|
|
|
uint16_t nxtsz;
|
|
|
|
|
|
|
|
/* protection */
|
|
|
|
if ((inp == NULL) || (stcb == NULL) || (net == NULL) ||
|
|
|
|
(ip == NULL) || (sh == NULL)) {
|
2007-05-09 13:30:06 +00:00
|
|
|
if (stcb != NULL) {
|
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
|
|
|
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;
|
|
|
|
}
|
|
|
|
icmph = (struct icmp *)((caddr_t)ip - (sizeof(struct icmp) -
|
|
|
|
sizeof(struct ip)));
|
|
|
|
if (icmph->icmp_type != ICMP_UNREACH) {
|
|
|
|
/* We only care about unreachable */
|
|
|
|
SCTP_TCB_UNLOCK(stcb);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (icmph->icmp_code != ICMP_UNREACH_NEEDFRAG) {
|
|
|
|
/* not a unreachable message due to frag. */
|
|
|
|
SCTP_TCB_UNLOCK(stcb);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
totsz = ip->ip_len;
|
|
|
|
|
2007-08-24 00:53:53 +00:00
|
|
|
nxtsz = ntohs(icmph->icmp_nextmtu);
|
2006-11-03 15:23:16 +00:00
|
|
|
if (nxtsz == 0) {
|
|
|
|
/*
|
|
|
|
* old type router that does not tell us what the next size
|
|
|
|
* mtu is. Rats we will have to guess (in a educated fashion
|
|
|
|
* of course)
|
|
|
|
*/
|
2010-11-07 18:50:35 +00:00
|
|
|
nxtsz = sctp_get_prev_mtu(totsz);
|
2006-11-03 15:23:16 +00:00
|
|
|
}
|
|
|
|
/* Stop any PMTU timer */
|
2006-12-29 20:21:42 +00:00
|
|
|
if (SCTP_OS_TIMER_PENDING(&net->pmtu_timer.timer)) {
|
2006-11-03 15:23:16 +00:00
|
|
|
tmr_stopped = 1;
|
2006-12-14 17:02:55 +00:00
|
|
|
sctp_timer_stop(SCTP_TIMER_TYPE_PATHMTURAISE, inp, stcb, net,
|
|
|
|
SCTP_FROM_SCTP_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) {
|
2007-03-19 06:53:02 +00:00
|
|
|
sctp_pathmtu_adjustment(inp, stcb, net, nxtsz);
|
2006-11-03 15:23:16 +00:00
|
|
|
}
|
|
|
|
if (tmr_stopped)
|
|
|
|
sctp_timer_start(SCTP_TIMER_TYPE_PATHMTURAISE, inp, stcb, net);
|
|
|
|
|
|
|
|
SCTP_TCB_UNLOCK(stcb);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
sctp_notify(struct sctp_inpcb *inp,
|
2007-09-08 17:48:46 +00:00
|
|
|
struct ip *ip,
|
2006-11-03 15:23:16 +00:00
|
|
|
struct sctphdr *sh,
|
|
|
|
struct sockaddr *to,
|
|
|
|
struct sctp_tcb *stcb,
|
|
|
|
struct sctp_nets *net)
|
|
|
|
{
|
2007-09-08 11:35:11 +00:00
|
|
|
#if defined (__APPLE__) || defined(SCTP_SO_LOCK_TESTING)
|
|
|
|
struct socket *so;
|
|
|
|
|
|
|
|
#endif
|
2006-11-03 15:23:16 +00:00
|
|
|
/* protection */
|
2007-09-08 17:48:46 +00:00
|
|
|
int reason;
|
|
|
|
struct icmp *icmph;
|
|
|
|
|
|
|
|
|
2006-11-03 15:23:16 +00:00
|
|
|
if ((inp == NULL) || (stcb == NULL) || (net == NULL) ||
|
|
|
|
(sh == NULL) || (to == NULL)) {
|
2007-09-08 17:48:46 +00:00
|
|
|
if (stcb)
|
|
|
|
SCTP_TCB_UNLOCK(stcb);
|
2006-11-03 15:23:16 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
/* First job is to verify the vtag matches what I would send */
|
|
|
|
if (ntohl(sh->v_tag) != (stcb->asoc.peer_vtag)) {
|
2007-09-08 17:48:46 +00:00
|
|
|
SCTP_TCB_UNLOCK(stcb);
|
2006-11-03 15:23:16 +00:00
|
|
|
return;
|
|
|
|
}
|
2007-09-08 17:48:46 +00:00
|
|
|
icmph = (struct icmp *)((caddr_t)ip - (sizeof(struct icmp) -
|
|
|
|
sizeof(struct ip)));
|
|
|
|
if (icmph->icmp_type != ICMP_UNREACH) {
|
|
|
|
/* We only care about unreachable */
|
|
|
|
SCTP_TCB_UNLOCK(stcb);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if ((icmph->icmp_code == ICMP_UNREACH_NET) ||
|
|
|
|
(icmph->icmp_code == ICMP_UNREACH_HOST) ||
|
|
|
|
(icmph->icmp_code == ICMP_UNREACH_NET_UNKNOWN) ||
|
|
|
|
(icmph->icmp_code == ICMP_UNREACH_HOST_UNKNOWN) ||
|
|
|
|
(icmph->icmp_code == ICMP_UNREACH_ISOLATED) ||
|
|
|
|
(icmph->icmp_code == ICMP_UNREACH_NET_PROHIB) ||
|
|
|
|
(icmph->icmp_code == ICMP_UNREACH_HOST_PROHIB) ||
|
|
|
|
(icmph->icmp_code == ICMP_UNREACH_FILTER_PROHIB)) {
|
2006-11-03 15:23:16 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* 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.
|
|
|
|
*/
|
2007-09-08 17:48:46 +00:00
|
|
|
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;
|
2006-11-03 15:23:16 +00:00
|
|
|
/*
|
2007-09-08 17:48:46 +00:00
|
|
|
* 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.
|
2006-11-03 15:23:16 +00:00
|
|
|
*/
|
2007-09-08 17:48:46 +00:00
|
|
|
/*
|
|
|
|
* Add debug message here if destination is not in
|
|
|
|
* PF state.
|
|
|
|
*/
|
|
|
|
/* Stop any running T3 timers here? */
|
2010-12-22 17:59:38 +00:00
|
|
|
if ((stcb->asoc.sctp_cmt_on_off > 0) &&
|
2010-08-28 17:59:51 +00:00
|
|
|
(stcb->asoc.sctp_cmt_pf > 0)) {
|
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->icmp_code == ICMP_UNREACH_PROTOCOL) ||
|
|
|
|
(icmph->icmp_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);
|
2007-09-08 11:35:11 +00:00
|
|
|
#if defined (__APPLE__) || defined(SCTP_SO_LOCK_TESTING)
|
2007-09-08 17:48:46 +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 11:35:11 +00:00
|
|
|
#endif
|
2007-09-08 17:48:46 +00:00
|
|
|
(void)sctp_free_assoc(inp, stcb, SCTP_NORMAL_PROC, SCTP_FROM_SCTP_USRREQ + SCTP_LOC_2);
|
2007-09-08 11:35:11 +00:00
|
|
|
#if defined (__APPLE__) || defined(SCTP_SO_LOCK_TESTING)
|
2007-09-08 17:48:46 +00:00
|
|
|
SCTP_SOCKET_UNLOCK(so, 1);
|
|
|
|
/* SCTP_TCB_UNLOCK(stcb); MT: I think this is not needed. */
|
2007-09-08 11:35:11 +00:00
|
|
|
#endif
|
2007-09-08 17:48:46 +00:00
|
|
|
/* no need to unlock here, since the TCB is gone */
|
2006-11-03 15:23:16 +00:00
|
|
|
} else {
|
2007-09-08 17:48:46 +00:00
|
|
|
SCTP_TCB_UNLOCK(stcb);
|
2006-11-03 15:23:16 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
sctp_ctlinput(cmd, sa, vip)
|
|
|
|
int cmd;
|
|
|
|
struct sockaddr *sa;
|
|
|
|
void *vip;
|
|
|
|
{
|
|
|
|
struct ip *ip = vip;
|
|
|
|
struct sctphdr *sh;
|
2007-03-15 11:27:14 +00:00
|
|
|
uint32_t vrf_id;
|
2006-11-03 15:23:16 +00:00
|
|
|
|
2007-04-03 11:15:32 +00:00
|
|
|
/* FIX, for non-bsd is this right? */
|
2007-03-15 11:27:14 +00:00
|
|
|
vrf_id = SCTP_DEFAULT_VRFID;
|
2006-11-03 15:23:16 +00:00
|
|
|
if (sa->sa_family != AF_INET ||
|
|
|
|
((struct sockaddr_in *)sa)->sin_addr.s_addr == INADDR_ANY) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (PRC_IS_REDIRECT(cmd)) {
|
|
|
|
ip = 0;
|
|
|
|
} else if ((unsigned)cmd >= PRC_NCMDS || inetctlerrmap[cmd] == 0) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (ip) {
|
|
|
|
struct sctp_inpcb *inp = NULL;
|
|
|
|
struct sctp_tcb *stcb = NULL;
|
|
|
|
struct sctp_nets *net = NULL;
|
|
|
|
struct sockaddr_in to, from;
|
|
|
|
|
|
|
|
sh = (struct sctphdr *)((caddr_t)ip + (ip->ip_hl << 2));
|
|
|
|
bzero(&to, sizeof(to));
|
|
|
|
bzero(&from, sizeof(from));
|
|
|
|
from.sin_family = to.sin_family = AF_INET;
|
|
|
|
from.sin_len = to.sin_len = sizeof(to);
|
|
|
|
from.sin_port = sh->src_port;
|
|
|
|
from.sin_addr = ip->ip_src;
|
|
|
|
to.sin_port = sh->dest_port;
|
|
|
|
to.sin_addr = ip->ip_dst;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* 'to' holds the dest of the packet that failed to be sent.
|
|
|
|
* 'from' holds our local endpoint address. Thus we reverse
|
|
|
|
* the to and the from in the lookup.
|
|
|
|
*/
|
|
|
|
stcb = sctp_findassociation_addr_sa((struct sockaddr *)&from,
|
|
|
|
(struct sockaddr *)&to,
|
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 && (inp->sctp_socket != NULL)) {
|
|
|
|
if (cmd != PRC_MSGSIZE) {
|
2007-09-08 17:48:46 +00:00
|
|
|
sctp_notify(inp, ip, sh,
|
2006-11-03 15:23:16 +00:00
|
|
|
(struct sockaddr *)&to, stcb,
|
|
|
|
net);
|
|
|
|
} else {
|
|
|
|
/* handle possible ICMP size messages */
|
|
|
|
sctp_notify_mbuf(inp, stcb, net, ip, sh);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if ((stcb == NULL) && (inp != NULL)) {
|
|
|
|
/* reduce ref-count */
|
|
|
|
SCTP_INP_WLOCK(inp);
|
|
|
|
SCTP_INP_DECR_REF(inp);
|
|
|
|
SCTP_INP_WUNLOCK(inp);
|
|
|
|
}
|
2010-06-11 03:54:00 +00:00
|
|
|
if (stcb) {
|
|
|
|
SCTP_TCB_UNLOCK(stcb);
|
|
|
|
}
|
2006-11-03 15:23:16 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
sctp_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_in 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;
|
2006-11-03 15:23:16 +00:00
|
|
|
|
2007-04-03 11:15:32 +00:00
|
|
|
/* FIX, for non-bsd is this right? */
|
2007-03-15 11:27:14 +00:00
|
|
|
vrf_id = SCTP_DEFAULT_VRFID;
|
2007-04-03 11:15:32 +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);
|
2006-11-06 14:54:06 +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(sintosa(&addrs[0]),
|
|
|
|
sintosa(&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) {
|
|
|
|
if ((inp != NULL) && (stcb == NULL)) {
|
|
|
|
/* reduce ref-count */
|
|
|
|
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_SCTP_USRREQ, ENOENT);
|
2006-11-03 15:23:16 +00:00
|
|
|
error = ENOENT;
|
|
|
|
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_inet_sctp, OID_AUTO, getcred, CTLTYPE_OPAQUE | CTLFLAG_RW,
|
|
|
|
0, 0, sctp_getcred, "S,ucred", "Get the ucred of a SCTP connection");
|
|
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
sctp_abort(struct socket *so)
|
|
|
|
{
|
|
|
|
struct sctp_inpcb *inp;
|
|
|
|
uint32_t flags;
|
|
|
|
|
|
|
|
inp = (struct sctp_inpcb *)so->so_pcb;
|
2007-08-24 00:53:53 +00:00
|
|
|
if (inp == 0) {
|
2006-11-03 15:23:16 +00:00
|
|
|
return;
|
2007-08-24 00:53:53 +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
|
|
|
|
sctp_attach(struct socket *so, int proto, struct thread *p)
|
|
|
|
{
|
|
|
|
struct sctp_inpcb *inp;
|
|
|
|
struct inpcb *ip_inp;
|
2007-01-18 09:58:43 +00:00
|
|
|
int error;
|
2007-06-02 11:05:08 +00:00
|
|
|
uint32_t vrf_id = SCTP_DEFAULT_VRFID;
|
2008-12-06 13:19:54 +00:00
|
|
|
|
2007-07-03 12:13:45 +00:00
|
|
|
#ifdef IPSEC
|
2006-11-03 15:23:16 +00:00
|
|
|
uint32_t flags;
|
2008-12-06 13:19:54 +00:00
|
|
|
|
2006-11-03 15:23:16 +00:00
|
|
|
#endif
|
MFp4:
Bring in updated jail support from bz_jail branch.
This enhances the current jail implementation to permit multiple
addresses per jail. In addtion to IPv4, IPv6 is supported as well.
Due to updated checks it is even possible to have jails without
an IP address at all, which basically gives one a chroot with
restricted process view, no networking,..
SCTP support was updated and supports IPv6 in jails as well.
Cpuset support permits jails to be bound to specific processor
sets after creation.
Jails can have an unrestricted (no duplicate protection, etc.) name
in addition to the hostname. The jail name cannot be changed from
within a jail and is considered to be used for management purposes
or as audit-token in the future.
DDB 'show jails' command was added to aid debugging.
Proper compat support permits 32bit jail binaries to be used on 64bit
systems to manage jails. Also backward compatibility was preserved where
possible: for jail v1 syscalls, as well as with user space management
utilities.
Both jail as well as prison version were updated for the new features.
A gap was intentionally left as the intermediate versions had been
used by various patches floating around the last years.
Bump __FreeBSD_version for the afore mentioned and in kernel changes.
Special thanks to:
- Pawel Jakub Dawidek (pjd) for his multi-IPv4 patches
and Olivier Houchard (cognet) for initial single-IPv6 patches.
- Jeff Roberson (jeff) and Randall Stewart (rrs) for their
help, ideas and review on cpuset and SCTP support.
- Robert Watson (rwatson) for lots and lots of help, discussions,
suggestions and review of most of the patch at various stages.
- John Baldwin (jhb) for his help.
- Simon L. Nielsen (simon) as early adopter testing changes
on cluster machines as well as all the testers and people
who provided feedback the last months on freebsd-jail and
other channels.
- My employer, CK Software GmbH, for the support so I could work on this.
Reviewed by: (see above)
MFC after: 3 months (this is just so that I get the mail)
X-MFC Before: 7.2-RELEASE if possible
2008-11-29 14:32:14 +00:00
|
|
|
|
2006-11-03 15:23:16 +00:00
|
|
|
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_SCTP_USRREQ, EINVAL);
|
2006-11-03 15:23:16 +00:00
|
|
|
return EINVAL;
|
|
|
|
}
|
2008-10-18 15:56:12 +00:00
|
|
|
if (so->so_snd.sb_hiwat == 0 || so->so_rcv.sb_hiwat == 0) {
|
|
|
|
error = SCTP_SORESERVE(so, SCTP_BASE_SYSCTL(sctp_sendspace), SCTP_BASE_SYSCTL(sctp_recvspace));
|
|
|
|
if (error) {
|
|
|
|
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) {
|
|
|
|
return error;
|
|
|
|
}
|
|
|
|
inp = (struct sctp_inpcb *)so->so_pcb;
|
|
|
|
SCTP_INP_WLOCK(inp);
|
|
|
|
inp->sctp_flags &= ~SCTP_PCB_FLAGS_BOUND_V6; /* I'm not v6! */
|
|
|
|
ip_inp = &inp->ip_inp.inp;
|
|
|
|
ip_inp->inp_vflag |= INP_IPV4;
|
2009-09-17 15:11:12 +00:00
|
|
|
ip_inp->inp_ip_ttl = MODULE_GLOBAL(ip_defttl);
|
2007-07-03 12:13:45 +00:00
|
|
|
#ifdef IPSEC
|
2007-07-01 11:41:27 +00:00
|
|
|
error = ipsec_init_policy(so, &ip_inp->inp_sp);
|
2006-11-03 15:23:16 +00:00
|
|
|
#ifdef SCTP_LOG_CLOSING
|
|
|
|
sctp_log_closing(inp, NULL, 17);
|
|
|
|
#endif
|
|
|
|
if (error != 0) {
|
2010-01-17 19:47:59 +00:00
|
|
|
try_again:
|
2006-11-03 15:23:16 +00:00
|
|
|
flags = inp->sctp_flags;
|
|
|
|
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, 15);
|
|
|
|
#endif
|
2007-05-08 00:21:05 +00:00
|
|
|
SCTP_INP_WUNLOCK(inp);
|
2007-05-08 15:53:03 +00:00
|
|
|
sctp_inpcb_free(inp, SCTP_FREE_SHOULD_USE_ABORT,
|
|
|
|
SCTP_CALLED_AFTER_CMPSET_OFCLOSE);
|
2007-05-04 15:19:10 +00:00
|
|
|
} else {
|
2010-01-17 19:47:59 +00:00
|
|
|
flags = inp->sctp_flags;
|
|
|
|
if ((flags & SCTP_PCB_FLAGS_SOCKET_GONE) == 0) {
|
|
|
|
goto try_again;
|
|
|
|
} else {
|
|
|
|
SCTP_INP_WUNLOCK(inp);
|
|
|
|
}
|
2006-11-03 15:23:16 +00:00
|
|
|
}
|
|
|
|
return error;
|
|
|
|
}
|
2007-07-03 12:13:45 +00:00
|
|
|
#endif /* IPSEC */
|
2006-11-03 15:23:16 +00:00
|
|
|
SCTP_INP_WUNLOCK(inp);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
sctp_bind(struct socket *so, struct sockaddr *addr, struct thread *p)
|
|
|
|
{
|
2007-08-24 00:53:53 +00:00
|
|
|
struct sctp_inpcb *inp = NULL;
|
2007-01-18 09:58:43 +00:00
|
|
|
int error;
|
2006-11-03 15:23:16 +00:00
|
|
|
|
|
|
|
#ifdef INET6
|
2007-08-24 00:53:53 +00:00
|
|
|
if (addr && addr->sa_family != AF_INET) {
|
2006-11-03 15:23:16 +00:00
|
|
|
/* must be a v4 address! */
|
2007-08-24 00:53:53 +00:00
|
|
|
SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_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
|
|
|
#endif /* INET6 */
|
2007-05-28 11:17:24 +00:00
|
|
|
if (addr && (addr->sa_len != sizeof(struct sockaddr_in))) {
|
2007-08-24 00:53:53 +00:00
|
|
|
SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
|
2007-05-28 11:17:24 +00:00
|
|
|
return EINVAL;
|
|
|
|
}
|
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_SCTP_USRREQ, EINVAL);
|
2006-11-03 15:23:16 +00:00
|
|
|
return EINVAL;
|
2007-08-24 00:53:53 +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;
|
|
|
|
}
|
|
|
|
|
2007-08-27 05:19:48 +00:00
|
|
|
void
|
2006-11-03 15:23:16 +00:00
|
|
|
sctp_close(struct socket *so)
|
|
|
|
{
|
|
|
|
struct sctp_inpcb *inp;
|
|
|
|
uint32_t flags;
|
|
|
|
|
|
|
|
inp = (struct sctp_inpcb *)so->so_pcb;
|
|
|
|
if (inp == 0)
|
|
|
|
return;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Inform all the lower layer assoc that we are done.
|
|
|
|
*/
|
|
|
|
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)))) {
|
|
|
|
if (((so->so_options & SO_LINGER) && (so->so_linger == 0)) ||
|
|
|
|
(so->so_rcv.sb_cc > 0)) {
|
|
|
|
#ifdef SCTP_LOG_CLOSING
|
|
|
|
sctp_log_closing(inp, NULL, 13);
|
|
|
|
#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
|
|
|
} else {
|
|
|
|
#ifdef SCTP_LOG_CLOSING
|
|
|
|
sctp_log_closing(inp, NULL, 14);
|
|
|
|
#endif
|
2007-05-08 15:53:03 +00:00
|
|
|
sctp_inpcb_free(inp, SCTP_FREE_SHOULD_USE_GRACEFUL_CLOSE,
|
|
|
|
SCTP_CALLED_AFTER_CMPSET_OFCLOSE);
|
2006-11-03 15:23:16 +00:00
|
|
|
}
|
|
|
|
/*
|
|
|
|
* The socket is now detached, no matter what the state of
|
|
|
|
* the SCTP association.
|
|
|
|
*/
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int
|
|
|
|
sctp_sendm(struct socket *so, int flags, struct mbuf *m, struct sockaddr *addr,
|
|
|
|
struct mbuf *control, struct thread *p);
|
|
|
|
|
|
|
|
|
|
|
|
int
|
|
|
|
sctp_sendm(struct socket *so, int flags, struct mbuf *m, struct sockaddr *addr,
|
|
|
|
struct mbuf *control, struct thread *p)
|
|
|
|
{
|
|
|
|
struct sctp_inpcb *inp;
|
|
|
|
int error;
|
|
|
|
|
|
|
|
inp = (struct sctp_inpcb *)so->so_pcb;
|
|
|
|
if (inp == 0) {
|
|
|
|
if (control) {
|
|
|
|
sctp_m_freem(control);
|
|
|
|
control = NULL;
|
|
|
|
}
|
2007-08-24 00:53:53 +00:00
|
|
|
SCTP_LTRACE_ERR_RET_PKT(m, inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
|
2006-11-03 15:23:16 +00:00
|
|
|
sctp_m_freem(m);
|
|
|
|
return EINVAL;
|
|
|
|
}
|
|
|
|
/* Got to have an to address if we are NOT a connected socket */
|
|
|
|
if ((addr == NULL) &&
|
|
|
|
((inp->sctp_flags & SCTP_PCB_FLAGS_CONNECTED) ||
|
|
|
|
(inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE))
|
|
|
|
) {
|
|
|
|
goto connected_type;
|
|
|
|
} else if (addr == NULL) {
|
2007-08-24 00:53:53 +00:00
|
|
|
SCTP_LTRACE_ERR_RET_PKT(m, inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EDESTADDRREQ);
|
2006-11-03 15:23:16 +00:00
|
|
|
error = EDESTADDRREQ;
|
|
|
|
sctp_m_freem(m);
|
|
|
|
if (control) {
|
|
|
|
sctp_m_freem(control);
|
|
|
|
control = NULL;
|
|
|
|
}
|
|
|
|
return (error);
|
|
|
|
}
|
|
|
|
#ifdef INET6
|
|
|
|
if (addr->sa_family != AF_INET) {
|
|
|
|
/* must be a v4 address! */
|
2007-08-24 00:53:53 +00:00
|
|
|
SCTP_LTRACE_ERR_RET_PKT(m, inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EDESTADDRREQ);
|
2006-11-03 15:23:16 +00:00
|
|
|
sctp_m_freem(m);
|
|
|
|
if (control) {
|
|
|
|
sctp_m_freem(control);
|
|
|
|
control = NULL;
|
|
|
|
}
|
|
|
|
error = EDESTADDRREQ;
|
2007-08-24 00:53:53 +00:00
|
|
|
return EDESTADDRREQ;
|
2006-11-03 15:23:16 +00:00
|
|
|
}
|
|
|
|
#endif /* INET6 */
|
|
|
|
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");
|
2006-11-03 15:23:16 +00:00
|
|
|
sctp_m_freem(inp->control);
|
|
|
|
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 uses a flag passed */
|
|
|
|
((flags & PRUS_MORETOCOME) == 0)
|
|
|
|
) {
|
|
|
|
/*
|
|
|
|
* note with the current version this code will only be used
|
|
|
|
* by OpenBSD-- NetBSD, FreeBSD, and MacOS have methods for
|
|
|
|
* re-defining sosend to use the sctp_sosend. One can
|
|
|
|
* optionally switch back to this code (by changing back the
|
|
|
|
* definitions) but this is not advisable. This code is used
|
|
|
|
* by FreeBSD when sending a file with sendfile() though.
|
|
|
|
*/
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
ret = sctp_output(inp, inp->pkt, addr, inp->control, p, flags);
|
|
|
|
inp->pkt = NULL;
|
|
|
|
inp->control = NULL;
|
|
|
|
return (ret);
|
|
|
|
} else {
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-08-27 05:19:48 +00:00
|
|
|
int
|
2006-11-03 15:23:16 +00:00
|
|
|
sctp_disconnect(struct socket *so)
|
|
|
|
{
|
|
|
|
struct sctp_inpcb *inp;
|
|
|
|
|
|
|
|
inp = (struct sctp_inpcb *)so->so_pcb;
|
|
|
|
if (inp == NULL) {
|
2007-08-24 00:53:53 +00:00
|
|
|
SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOTCONN);
|
2006-11-03 15:23:16 +00:00
|
|
|
return (ENOTCONN);
|
|
|
|
}
|
|
|
|
SCTP_INP_RLOCK(inp);
|
2007-08-06 15:46:46 +00:00
|
|
|
if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
|
|
|
|
(inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL)) {
|
2009-11-17 20:56:14 +00:00
|
|
|
if (LIST_EMPTY(&inp->sctp_asoc_list)) {
|
2006-11-03 15:23:16 +00:00
|
|
|
/* No connection */
|
|
|
|
SCTP_INP_RUNLOCK(inp);
|
|
|
|
return (0);
|
|
|
|
} else {
|
|
|
|
struct sctp_association *asoc;
|
|
|
|
struct sctp_tcb *stcb;
|
|
|
|
|
|
|
|
stcb = LIST_FIRST(&inp->sctp_asoc_list);
|
|
|
|
if (stcb == NULL) {
|
|
|
|
SCTP_INP_RUNLOCK(inp);
|
2007-08-24 00:53:53 +00:00
|
|
|
SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
|
2006-11-03 15:23:16 +00:00
|
|
|
return (EINVAL);
|
|
|
|
}
|
|
|
|
SCTP_TCB_LOCK(stcb);
|
|
|
|
asoc = &stcb->asoc;
|
|
|
|
if (stcb->asoc.state & SCTP_STATE_ABOUT_TO_BE_FREED) {
|
|
|
|
/* We are about to be freed, out of here */
|
|
|
|
SCTP_TCB_UNLOCK(stcb);
|
|
|
|
SCTP_INP_RUNLOCK(inp);
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
if (((so->so_options & SO_LINGER) &&
|
|
|
|
(so->so_linger == 0)) ||
|
|
|
|
(so->so_rcv.sb_cc > 0)) {
|
|
|
|
if (SCTP_GET_STATE(asoc) !=
|
|
|
|
SCTP_STATE_COOKIE_WAIT) {
|
|
|
|
/* Left with Data unread */
|
|
|
|
struct mbuf *err;
|
|
|
|
|
|
|
|
err = sctp_get_mbuf_for_msg(sizeof(struct sctp_paramhdr), 0, M_DONTWAIT, 1, MT_DATA);
|
|
|
|
if (err) {
|
|
|
|
/*
|
|
|
|
* Fill in the user
|
|
|
|
* initiated abort
|
|
|
|
*/
|
|
|
|
struct sctp_paramhdr *ph;
|
|
|
|
|
|
|
|
ph = mtod(err, struct sctp_paramhdr *);
|
2006-12-29 20:21:42 +00:00
|
|
|
SCTP_BUF_LEN(err) = sizeof(struct sctp_paramhdr);
|
2006-11-03 15:23:16 +00:00
|
|
|
ph->param_type = htons(SCTP_CAUSE_USER_INITIATED_ABT);
|
2006-12-29 20:21:42 +00:00
|
|
|
ph->param_length = htons(SCTP_BUF_LEN(err));
|
2006-11-03 15:23:16 +00:00
|
|
|
}
|
2007-10-01 03:22:29 +00:00
|
|
|
#if defined(SCTP_PANIC_ON_ABORT)
|
|
|
|
panic("disconnect does an abort");
|
|
|
|
#endif
|
2007-09-08 11:35:11 +00:00
|
|
|
sctp_send_abort_tcb(stcb, err, SCTP_SO_LOCKED);
|
2006-11-03 15:23:16 +00:00
|
|
|
SCTP_STAT_INCR_COUNTER32(sctps_aborted);
|
|
|
|
}
|
|
|
|
SCTP_INP_RUNLOCK(inp);
|
|
|
|
if ((SCTP_GET_STATE(&stcb->asoc) == SCTP_STATE_OPEN) ||
|
|
|
|
(SCTP_GET_STATE(&stcb->asoc) == SCTP_STATE_SHUTDOWN_RECEIVED)) {
|
|
|
|
SCTP_STAT_DECR_GAUGE32(sctps_currestab);
|
|
|
|
}
|
2007-08-24 00:53:53 +00:00
|
|
|
(void)sctp_free_assoc(inp, stcb, SCTP_NORMAL_PROC, SCTP_FROM_SCTP_USRREQ + SCTP_LOC_3);
|
2006-11-03 15:23:16 +00:00
|
|
|
/* No unlock tcb assoc is gone */
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
if (TAILQ_EMPTY(&asoc->send_queue) &&
|
|
|
|
TAILQ_EMPTY(&asoc->sent_queue) &&
|
|
|
|
(asoc->stream_queue_cnt == 0)) {
|
|
|
|
/* there is nothing queued to send, so done */
|
|
|
|
if (asoc->locked_on_sending) {
|
|
|
|
goto abort_anyway;
|
|
|
|
}
|
2007-02-12 23:24:31 +00:00
|
|
|
if ((SCTP_GET_STATE(asoc) != SCTP_STATE_SHUTDOWN_SENT) &&
|
|
|
|
(SCTP_GET_STATE(asoc) != SCTP_STATE_SHUTDOWN_ACK_SENT)) {
|
2006-11-03 15:23:16 +00:00
|
|
|
/* only send SHUTDOWN 1st time thru */
|
|
|
|
sctp_stop_timers_for_shutdown(stcb);
|
|
|
|
sctp_send_shutdown(stcb,
|
|
|
|
stcb->asoc.primary_destination);
|
2007-09-08 11:35:11 +00:00
|
|
|
sctp_chunk_output(stcb->sctp_ep, stcb, SCTP_OUTPUT_FROM_T3, SCTP_SO_LOCKED);
|
2007-02-12 23:24:31 +00:00
|
|
|
if ((SCTP_GET_STATE(asoc) == SCTP_STATE_OPEN) ||
|
|
|
|
(SCTP_GET_STATE(asoc) == SCTP_STATE_SHUTDOWN_RECEIVED)) {
|
|
|
|
SCTP_STAT_DECR_GAUGE32(sctps_currestab);
|
|
|
|
}
|
2007-08-24 00:53:53 +00:00
|
|
|
SCTP_SET_STATE(asoc, SCTP_STATE_SHUTDOWN_SENT);
|
2007-10-16 14:05:51 +00:00
|
|
|
SCTP_CLEAR_SUBSTATE(asoc, SCTP_STATE_SHUTDOWN_PENDING);
|
2006-11-03 15:23:16 +00:00
|
|
|
sctp_timer_start(SCTP_TIMER_TYPE_SHUTDOWN,
|
|
|
|
stcb->sctp_ep, stcb,
|
|
|
|
asoc->primary_destination);
|
|
|
|
sctp_timer_start(SCTP_TIMER_TYPE_SHUTDOWNGUARD,
|
|
|
|
stcb->sctp_ep, stcb,
|
|
|
|
asoc->primary_destination);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
/*
|
|
|
|
* we still got (or just got) data to send,
|
|
|
|
* so set SHUTDOWN_PENDING
|
|
|
|
*/
|
|
|
|
/*
|
|
|
|
* XXX sockets draft says that SCTP_EOF
|
|
|
|
* should be sent with no data. currently,
|
|
|
|
* we will allow user data to be sent first
|
|
|
|
* and move to SHUTDOWN-PENDING
|
|
|
|
*/
|
|
|
|
asoc->state |= SCTP_STATE_SHUTDOWN_PENDING;
|
|
|
|
sctp_timer_start(SCTP_TIMER_TYPE_SHUTDOWNGUARD, stcb->sctp_ep, stcb,
|
|
|
|
asoc->primary_destination);
|
|
|
|
if (asoc->locked_on_sending) {
|
|
|
|
/* Locked to send out the data */
|
|
|
|
struct sctp_stream_queue_pending *sp;
|
|
|
|
|
|
|
|
sp = TAILQ_LAST(&asoc->locked_on_sending->outqueue, sctp_streamhead);
|
|
|
|
if (sp == NULL) {
|
2007-05-09 13:30:06 +00:00
|
|
|
SCTP_PRINTF("Error, sp is NULL, locked on sending is non-null strm:%d\n",
|
2006-11-03 15:23:16 +00:00
|
|
|
asoc->locked_on_sending->stream_no);
|
|
|
|
} else {
|
|
|
|
if ((sp->length == 0) && (sp->msg_is_complete == 0))
|
|
|
|
asoc->state |= SCTP_STATE_PARTIAL_MSG_LEFT;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (TAILQ_EMPTY(&asoc->send_queue) &&
|
|
|
|
TAILQ_EMPTY(&asoc->sent_queue) &&
|
|
|
|
(asoc->state & SCTP_STATE_PARTIAL_MSG_LEFT)) {
|
|
|
|
struct mbuf *op_err;
|
|
|
|
|
|
|
|
abort_anyway:
|
|
|
|
op_err = sctp_get_mbuf_for_msg((sizeof(struct sctp_paramhdr) + sizeof(uint32_t)),
|
|
|
|
0, M_DONTWAIT, 1, MT_DATA);
|
|
|
|
if (op_err) {
|
|
|
|
/*
|
|
|
|
* Fill in the user
|
|
|
|
* initiated abort
|
|
|
|
*/
|
|
|
|
struct sctp_paramhdr *ph;
|
|
|
|
uint32_t *ippp;
|
|
|
|
|
2006-12-29 20:21:42 +00:00
|
|
|
SCTP_BUF_LEN(op_err) =
|
2006-11-03 15:23:16 +00:00
|
|
|
(sizeof(struct sctp_paramhdr) + sizeof(uint32_t));
|
|
|
|
ph = mtod(op_err,
|
|
|
|
struct sctp_paramhdr *);
|
|
|
|
ph->param_type = htons(
|
|
|
|
SCTP_CAUSE_USER_INITIATED_ABT);
|
2006-12-29 20:21:42 +00:00
|
|
|
ph->param_length = htons(SCTP_BUF_LEN(op_err));
|
2006-11-03 15:23:16 +00:00
|
|
|
ippp = (uint32_t *) (ph + 1);
|
2006-12-14 17:02:55 +00:00
|
|
|
*ippp = htonl(SCTP_FROM_SCTP_USRREQ + SCTP_LOC_4);
|
2006-11-03 15:23:16 +00:00
|
|
|
}
|
2007-10-01 03:22:29 +00:00
|
|
|
#if defined(SCTP_PANIC_ON_ABORT)
|
|
|
|
panic("disconnect does an abort");
|
|
|
|
#endif
|
|
|
|
|
2006-12-14 17:02:55 +00:00
|
|
|
stcb->sctp_ep->last_abort_code = SCTP_FROM_SCTP_USRREQ + SCTP_LOC_4;
|
2007-09-08 11:35:11 +00:00
|
|
|
sctp_send_abort_tcb(stcb, op_err, SCTP_SO_LOCKED);
|
2006-11-03 15:23:16 +00:00
|
|
|
SCTP_STAT_INCR_COUNTER32(sctps_aborted);
|
|
|
|
if ((SCTP_GET_STATE(&stcb->asoc) == SCTP_STATE_OPEN) ||
|
|
|
|
(SCTP_GET_STATE(&stcb->asoc) == SCTP_STATE_SHUTDOWN_RECEIVED)) {
|
|
|
|
SCTP_STAT_DECR_GAUGE32(sctps_currestab);
|
|
|
|
}
|
|
|
|
SCTP_INP_RUNLOCK(inp);
|
2007-08-24 00:53:53 +00:00
|
|
|
(void)sctp_free_assoc(inp, stcb, SCTP_NORMAL_PROC, SCTP_FROM_SCTP_USRREQ + SCTP_LOC_5);
|
2006-11-03 15:23:16 +00:00
|
|
|
return (0);
|
2007-08-27 05:19:48 +00:00
|
|
|
} else {
|
2007-09-08 11:35:11 +00:00
|
|
|
sctp_chunk_output(inp, stcb, SCTP_OUTPUT_FROM_CLOSING, SCTP_SO_LOCKED);
|
2006-11-03 15:23:16 +00:00
|
|
|
}
|
|
|
|
}
|
2009-02-03 11:04:03 +00:00
|
|
|
soisdisconnecting(so);
|
2006-11-03 15:23:16 +00:00
|
|
|
SCTP_TCB_UNLOCK(stcb);
|
|
|
|
SCTP_INP_RUNLOCK(inp);
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
/* not reached */
|
|
|
|
} else {
|
|
|
|
/* UDP model does not support this */
|
|
|
|
SCTP_INP_RUNLOCK(inp);
|
2007-08-24 00:53:53 +00:00
|
|
|
SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EOPNOTSUPP);
|
2006-11-03 15:23:16 +00:00
|
|
|
return EOPNOTSUPP;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-04-14 18:13:33 +00:00
|
|
|
int
|
|
|
|
sctp_flush(struct socket *so, int how)
|
|
|
|
{
|
|
|
|
/*
|
|
|
|
* We will just clear out the values and let subsequent close clear
|
|
|
|
* out the data, if any. Note if the user did a shutdown(SHUT_RD)
|
|
|
|
* they will not be able to read the data, the socket will block
|
|
|
|
* that from happening.
|
|
|
|
*/
|
2010-06-18 09:01:44 +00:00
|
|
|
struct sctp_inpcb *inp;
|
|
|
|
|
|
|
|
inp = (struct sctp_inpcb *)so->so_pcb;
|
|
|
|
if (inp == NULL) {
|
|
|
|
SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
|
|
|
|
return EINVAL;
|
|
|
|
}
|
|
|
|
SCTP_INP_RLOCK(inp);
|
|
|
|
/* For the 1 to many model this does nothing */
|
|
|
|
if (inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) {
|
|
|
|
SCTP_INP_RUNLOCK(inp);
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
SCTP_INP_RUNLOCK(inp);
|
2008-04-14 18:13:33 +00:00
|
|
|
if ((how == PRU_FLUSH_RD) || (how == PRU_FLUSH_RDWR)) {
|
|
|
|
/*
|
|
|
|
* First make sure the sb will be happy, we don't use these
|
|
|
|
* except maybe the count
|
|
|
|
*/
|
2010-06-18 09:01:44 +00:00
|
|
|
SCTP_INP_WLOCK(inp);
|
|
|
|
SCTP_INP_READ_LOCK(inp);
|
|
|
|
inp->sctp_flags |= SCTP_PCB_FLAGS_SOCKET_CANT_READ;
|
|
|
|
SCTP_INP_READ_UNLOCK(inp);
|
|
|
|
SCTP_INP_WUNLOCK(inp);
|
2008-04-14 18:13:33 +00:00
|
|
|
so->so_rcv.sb_cc = 0;
|
|
|
|
so->so_rcv.sb_mbcnt = 0;
|
|
|
|
so->so_rcv.sb_mb = NULL;
|
|
|
|
}
|
|
|
|
if ((how == PRU_FLUSH_WR) || (how == PRU_FLUSH_RDWR)) {
|
|
|
|
/*
|
|
|
|
* First make sure the sb will be happy, we don't use these
|
|
|
|
* except maybe the count
|
|
|
|
*/
|
|
|
|
so->so_snd.sb_cc = 0;
|
|
|
|
so->so_snd.sb_mbcnt = 0;
|
|
|
|
so->so_snd.sb_mb = NULL;
|
|
|
|
|
|
|
|
}
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
2006-11-03 15:23:16 +00:00
|
|
|
int
|
|
|
|
sctp_shutdown(struct socket *so)
|
|
|
|
{
|
|
|
|
struct sctp_inpcb *inp;
|
|
|
|
|
|
|
|
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_SCTP_USRREQ, EINVAL);
|
2006-11-03 15:23:16 +00:00
|
|
|
return EINVAL;
|
|
|
|
}
|
|
|
|
SCTP_INP_RLOCK(inp);
|
|
|
|
/* For UDP model this is a invalid call */
|
|
|
|
if (inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) {
|
|
|
|
/* Restore the flags that the soshutdown took away. */
|
2010-02-19 18:00:38 +00:00
|
|
|
SOCKBUF_LOCK(&so->so_rcv);
|
2006-11-03 15:23:16 +00:00
|
|
|
so->so_rcv.sb_state &= ~SBS_CANTRCVMORE;
|
2010-02-19 18:00:38 +00:00
|
|
|
SOCKBUF_UNLOCK(&so->so_rcv);
|
2006-11-03 15:23:16 +00:00
|
|
|
/* This proc will wakeup for read and do nothing (I hope) */
|
|
|
|
SCTP_INP_RUNLOCK(inp);
|
2007-08-24 00:53:53 +00:00
|
|
|
SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EOPNOTSUPP);
|
2006-11-03 15:23:16 +00:00
|
|
|
return (EOPNOTSUPP);
|
|
|
|
}
|
|
|
|
/*
|
|
|
|
* Ok if we reach here its the TCP model and it is either a SHUT_WR
|
|
|
|
* or SHUT_RDWR. This means we put the shutdown flag against it.
|
|
|
|
*/
|
|
|
|
{
|
|
|
|
struct sctp_tcb *stcb;
|
|
|
|
struct sctp_association *asoc;
|
|
|
|
|
2009-02-03 11:04:03 +00:00
|
|
|
if ((so->so_state &
|
|
|
|
(SS_ISCONNECTED | SS_ISCONNECTING | SS_ISDISCONNECTING)) == 0) {
|
|
|
|
SCTP_INP_RUNLOCK(inp);
|
|
|
|
return (ENOTCONN);
|
|
|
|
}
|
2006-11-03 15:23:16 +00:00
|
|
|
socantsendmore(so);
|
|
|
|
|
|
|
|
stcb = LIST_FIRST(&inp->sctp_asoc_list);
|
|
|
|
if (stcb == NULL) {
|
|
|
|
/*
|
|
|
|
* Ok we hit the case that the shutdown call was
|
|
|
|
* made after an abort or something. Nothing to do
|
|
|
|
* now.
|
|
|
|
*/
|
2007-04-03 11:15:32 +00:00
|
|
|
SCTP_INP_RUNLOCK(inp);
|
2006-11-03 15:23:16 +00:00
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
SCTP_TCB_LOCK(stcb);
|
|
|
|
asoc = &stcb->asoc;
|
|
|
|
if (TAILQ_EMPTY(&asoc->send_queue) &&
|
|
|
|
TAILQ_EMPTY(&asoc->sent_queue) &&
|
|
|
|
(asoc->stream_queue_cnt == 0)) {
|
|
|
|
if (asoc->locked_on_sending) {
|
|
|
|
goto abort_anyway;
|
|
|
|
}
|
|
|
|
/* there is nothing queued to send, so I'm done... */
|
|
|
|
if (SCTP_GET_STATE(asoc) != SCTP_STATE_SHUTDOWN_SENT) {
|
|
|
|
/* only send SHUTDOWN the first time through */
|
|
|
|
sctp_stop_timers_for_shutdown(stcb);
|
|
|
|
sctp_send_shutdown(stcb,
|
|
|
|
stcb->asoc.primary_destination);
|
2007-09-18 15:16:39 +00:00
|
|
|
sctp_chunk_output(stcb->sctp_ep, stcb, SCTP_OUTPUT_FROM_T3, SCTP_SO_LOCKED);
|
2007-02-12 23:24:31 +00:00
|
|
|
if ((SCTP_GET_STATE(asoc) == SCTP_STATE_OPEN) ||
|
|
|
|
(SCTP_GET_STATE(asoc) == SCTP_STATE_SHUTDOWN_RECEIVED)) {
|
|
|
|
SCTP_STAT_DECR_GAUGE32(sctps_currestab);
|
|
|
|
}
|
2007-08-24 00:53:53 +00:00
|
|
|
SCTP_SET_STATE(asoc, SCTP_STATE_SHUTDOWN_SENT);
|
2007-10-16 14:05:51 +00:00
|
|
|
SCTP_CLEAR_SUBSTATE(asoc, SCTP_STATE_SHUTDOWN_PENDING);
|
2006-11-03 15:23:16 +00:00
|
|
|
sctp_timer_start(SCTP_TIMER_TYPE_SHUTDOWN,
|
|
|
|
stcb->sctp_ep, stcb,
|
|
|
|
asoc->primary_destination);
|
|
|
|
sctp_timer_start(SCTP_TIMER_TYPE_SHUTDOWNGUARD,
|
|
|
|
stcb->sctp_ep, stcb,
|
|
|
|
asoc->primary_destination);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
/*
|
|
|
|
* we still got (or just got) data to send, so set
|
|
|
|
* SHUTDOWN_PENDING
|
|
|
|
*/
|
|
|
|
asoc->state |= SCTP_STATE_SHUTDOWN_PENDING;
|
|
|
|
sctp_timer_start(SCTP_TIMER_TYPE_SHUTDOWNGUARD, stcb->sctp_ep, stcb,
|
|
|
|
asoc->primary_destination);
|
|
|
|
|
|
|
|
if (asoc->locked_on_sending) {
|
|
|
|
/* Locked to send out the data */
|
|
|
|
struct sctp_stream_queue_pending *sp;
|
|
|
|
|
|
|
|
sp = TAILQ_LAST(&asoc->locked_on_sending->outqueue, sctp_streamhead);
|
|
|
|
if (sp == NULL) {
|
2007-05-09 13:30:06 +00:00
|
|
|
SCTP_PRINTF("Error, sp is NULL, locked on sending is non-null strm:%d\n",
|
2006-11-03 15:23:16 +00:00
|
|
|
asoc->locked_on_sending->stream_no);
|
|
|
|
} else {
|
|
|
|
if ((sp->length == 0) && (sp->msg_is_complete == 0)) {
|
|
|
|
asoc->state |= SCTP_STATE_PARTIAL_MSG_LEFT;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (TAILQ_EMPTY(&asoc->send_queue) &&
|
|
|
|
TAILQ_EMPTY(&asoc->sent_queue) &&
|
|
|
|
(asoc->state & SCTP_STATE_PARTIAL_MSG_LEFT)) {
|
|
|
|
struct mbuf *op_err;
|
|
|
|
|
|
|
|
abort_anyway:
|
|
|
|
op_err = sctp_get_mbuf_for_msg((sizeof(struct sctp_paramhdr) + sizeof(uint32_t)),
|
|
|
|
0, M_DONTWAIT, 1, MT_DATA);
|
|
|
|
if (op_err) {
|
|
|
|
/* Fill in the user initiated abort */
|
|
|
|
struct sctp_paramhdr *ph;
|
|
|
|
uint32_t *ippp;
|
|
|
|
|
2006-12-29 20:21:42 +00:00
|
|
|
SCTP_BUF_LEN(op_err) =
|
2006-11-03 15:23:16 +00:00
|
|
|
sizeof(struct sctp_paramhdr) + sizeof(uint32_t);
|
|
|
|
ph = mtod(op_err,
|
|
|
|
struct sctp_paramhdr *);
|
|
|
|
ph->param_type = htons(
|
|
|
|
SCTP_CAUSE_USER_INITIATED_ABT);
|
2006-12-29 20:21:42 +00:00
|
|
|
ph->param_length = htons(SCTP_BUF_LEN(op_err));
|
2006-11-03 15:23:16 +00:00
|
|
|
ippp = (uint32_t *) (ph + 1);
|
2006-12-14 17:02:55 +00:00
|
|
|
*ippp = htonl(SCTP_FROM_SCTP_USRREQ + SCTP_LOC_6);
|
2006-11-03 15:23:16 +00:00
|
|
|
}
|
2007-10-01 03:22:29 +00:00
|
|
|
#if defined(SCTP_PANIC_ON_ABORT)
|
|
|
|
panic("shutdown does an abort");
|
|
|
|
#endif
|
2006-12-14 17:02:55 +00:00
|
|
|
stcb->sctp_ep->last_abort_code = SCTP_FROM_SCTP_USRREQ + SCTP_LOC_6;
|
2006-11-03 15:23:16 +00:00
|
|
|
sctp_abort_an_association(stcb->sctp_ep, stcb,
|
|
|
|
SCTP_RESPONSE_TO_USER_REQ,
|
2007-09-08 11:35:11 +00:00
|
|
|
op_err, SCTP_SO_LOCKED);
|
2006-11-03 15:23:16 +00:00
|
|
|
goto skip_unlock;
|
2007-08-27 05:19:48 +00:00
|
|
|
} else {
|
2007-09-08 11:35:11 +00:00
|
|
|
sctp_chunk_output(inp, stcb, SCTP_OUTPUT_FROM_CLOSING, SCTP_SO_LOCKED);
|
2006-11-03 15:23:16 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
SCTP_TCB_UNLOCK(stcb);
|
|
|
|
}
|
|
|
|
skip_unlock:
|
|
|
|
SCTP_INP_RUNLOCK(inp);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* copies a "user" presentable address and removes embedded scope, etc.
|
|
|
|
* returns 0 on success, 1 on error
|
|
|
|
*/
|
|
|
|
static uint32_t
|
|
|
|
sctp_fill_user_address(struct sockaddr_storage *ss, struct sockaddr *sa)
|
|
|
|
{
|
2008-04-16 17:24:18 +00:00
|
|
|
#ifdef INET6
|
2006-11-03 15:23:16 +00:00
|
|
|
struct sockaddr_in6 lsa6;
|
|
|
|
|
|
|
|
sa = (struct sockaddr *)sctp_recover_scope((struct sockaddr_in6 *)sa,
|
|
|
|
&lsa6);
|
2008-04-16 17:24:18 +00:00
|
|
|
#endif
|
2006-11-03 15:23:16 +00:00
|
|
|
memcpy(ss, sa, sa->sa_len);
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2007-09-08 17:48:46 +00:00
|
|
|
/*
|
|
|
|
* NOTE: assumes addr lock is held
|
|
|
|
*/
|
2007-02-12 23:24:31 +00:00
|
|
|
static size_t
|
2007-03-31 11:47:30 +00:00
|
|
|
sctp_fill_up_addresses_vrf(struct sctp_inpcb *inp,
|
2006-11-03 15:23:16 +00:00
|
|
|
struct sctp_tcb *stcb,
|
2007-02-12 23:24:31 +00:00
|
|
|
size_t limit,
|
2007-03-15 11:27:14 +00:00
|
|
|
struct sockaddr_storage *sas,
|
|
|
|
uint32_t vrf_id)
|
2006-11-03 15:23:16 +00:00
|
|
|
{
|
2007-03-15 11:27:14 +00:00
|
|
|
struct sctp_ifn *sctp_ifn;
|
|
|
|
struct sctp_ifa *sctp_ifa;
|
2007-02-12 23:24:31 +00:00
|
|
|
int loopback_scope, ipv4_local_scope, local_scope, site_scope;
|
|
|
|
size_t actual;
|
2006-11-03 15:23:16 +00:00
|
|
|
int ipv4_addr_legal, ipv6_addr_legal;
|
2007-03-15 11:27:14 +00:00
|
|
|
struct sctp_vrf *vrf;
|
2006-11-03 15:23:16 +00:00
|
|
|
|
|
|
|
actual = 0;
|
|
|
|
if (limit <= 0)
|
|
|
|
return (actual);
|
|
|
|
|
|
|
|
if (stcb) {
|
|
|
|
/* Turn on all the appropriate scope */
|
|
|
|
loopback_scope = stcb->asoc.loopback_scope;
|
|
|
|
ipv4_local_scope = stcb->asoc.ipv4_local_scope;
|
|
|
|
local_scope = stcb->asoc.local_scope;
|
|
|
|
site_scope = stcb->asoc.site_scope;
|
|
|
|
} else {
|
|
|
|
/* Turn on ALL scope, since we look at the EP */
|
|
|
|
loopback_scope = ipv4_local_scope = local_scope =
|
|
|
|
site_scope = 1;
|
|
|
|
}
|
|
|
|
ipv4_addr_legal = ipv6_addr_legal = 0;
|
|
|
|
if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) {
|
|
|
|
ipv6_addr_legal = 1;
|
2007-01-15 15:12:10 +00:00
|
|
|
if (SCTP_IPV6_V6ONLY(inp) == 0) {
|
2006-11-03 15:23:16 +00:00
|
|
|
ipv4_addr_legal = 1;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
ipv4_addr_legal = 1;
|
|
|
|
}
|
2007-03-15 11:27:14 +00:00
|
|
|
vrf = sctp_find_vrf(vrf_id);
|
|
|
|
if (vrf == NULL) {
|
|
|
|
return (0);
|
|
|
|
}
|
2006-11-03 15:23:16 +00:00
|
|
|
if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUNDALL) {
|
2007-03-15 11:27:14 +00:00
|
|
|
LIST_FOREACH(sctp_ifn, &vrf->ifnlist, next_ifn) {
|
2006-11-03 15:23:16 +00:00
|
|
|
if ((loopback_scope == 0) &&
|
2007-03-15 11:27:14 +00:00
|
|
|
SCTP_IFN_IS_IFT_LOOP(sctp_ifn)) {
|
2006-11-03 15:23:16 +00:00
|
|
|
/* Skip loopback if loopback_scope not set */
|
|
|
|
continue;
|
|
|
|
}
|
2007-03-15 11:27:14 +00:00
|
|
|
LIST_FOREACH(sctp_ifa, &sctp_ifn->ifalist, next_ifa) {
|
2006-11-03 15:23:16 +00:00
|
|
|
if (stcb) {
|
|
|
|
/*
|
|
|
|
* For the BOUND-ALL case, the list
|
|
|
|
* associated with a TCB is Always
|
|
|
|
* considered a reverse list.. i.e.
|
|
|
|
* it lists addresses that are NOT
|
|
|
|
* part of the association. If this
|
|
|
|
* is one of those we must skip it.
|
|
|
|
*/
|
|
|
|
if (sctp_is_addr_restricted(stcb,
|
2007-03-15 11:27:14 +00:00
|
|
|
sctp_ifa)) {
|
2006-11-03 15:23:16 +00:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
2008-04-16 17:24:18 +00:00
|
|
|
switch (sctp_ifa->address.sa.sa_family) {
|
|
|
|
case AF_INET:
|
|
|
|
if (ipv4_addr_legal) {
|
|
|
|
struct sockaddr_in *sin;
|
|
|
|
|
|
|
|
sin = (struct sockaddr_in *)&sctp_ifa->address.sa;
|
|
|
|
if (sin->sin_addr.s_addr == 0) {
|
|
|
|
/*
|
|
|
|
* we skip
|
|
|
|
* unspecifed
|
|
|
|
* addresses
|
|
|
|
*/
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if ((ipv4_local_scope == 0) &&
|
|
|
|
(IN4_ISPRIVATE_ADDRESS(&sin->sin_addr))) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
#ifdef INET6
|
|
|
|
if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_NEEDS_MAPPED_V4)) {
|
|
|
|
in6_sin_2_v4mapsin6(sin, (struct sockaddr_in6 *)sas);
|
|
|
|
((struct sockaddr_in6 *)sas)->sin6_port = inp->sctp_lport;
|
|
|
|
sas = (struct sockaddr_storage *)((caddr_t)sas + sizeof(struct sockaddr_in6));
|
|
|
|
actual += sizeof(struct sockaddr_in6);
|
|
|
|
} else {
|
|
|
|
#endif
|
|
|
|
memcpy(sas, sin, sizeof(*sin));
|
|
|
|
((struct sockaddr_in *)sas)->sin_port = inp->sctp_lport;
|
|
|
|
sas = (struct sockaddr_storage *)((caddr_t)sas + sizeof(*sin));
|
|
|
|
actual += sizeof(*sin);
|
|
|
|
#ifdef INET6
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
if (actual >= limit) {
|
|
|
|
return (actual);
|
|
|
|
}
|
2006-11-03 15:23:16 +00:00
|
|
|
} else {
|
|
|
|
continue;
|
|
|
|
}
|
2008-04-16 17:24:18 +00:00
|
|
|
break;
|
|
|
|
#ifdef INET6
|
|
|
|
case AF_INET6:
|
|
|
|
if (ipv6_addr_legal) {
|
|
|
|
struct sockaddr_in6 *sin6;
|
|
|
|
|
|
|
|
sin6 = (struct sockaddr_in6 *)&sctp_ifa->address.sa;
|
|
|
|
if (IN6_IS_ADDR_UNSPECIFIED(&sin6->sin6_addr)) {
|
|
|
|
/*
|
|
|
|
* we skip
|
|
|
|
* unspecifed
|
|
|
|
* addresses
|
|
|
|
*/
|
2006-11-03 15:23:16 +00:00
|
|
|
continue;
|
2008-04-16 17:24:18 +00:00
|
|
|
}
|
|
|
|
if (IN6_IS_ADDR_LINKLOCAL(&sin6->sin6_addr)) {
|
|
|
|
if (local_scope == 0)
|
2006-11-03 15:23:16 +00:00
|
|
|
continue;
|
2008-04-16 17:24:18 +00:00
|
|
|
if (sin6->sin6_scope_id == 0) {
|
|
|
|
if (sa6_recoverscope(sin6) != 0)
|
|
|
|
/*
|
|
|
|
*
|
|
|
|
* bad
|
|
|
|
*
|
|
|
|
* li
|
|
|
|
* nk
|
|
|
|
*
|
|
|
|
* loc
|
|
|
|
* al
|
|
|
|
*
|
|
|
|
* add
|
|
|
|
* re
|
|
|
|
* ss
|
|
|
|
* */
|
|
|
|
continue;
|
|
|
|
}
|
2006-11-03 15:23:16 +00:00
|
|
|
}
|
2008-04-16 17:24:18 +00:00
|
|
|
if ((site_scope == 0) &&
|
|
|
|
(IN6_IS_ADDR_SITELOCAL(&sin6->sin6_addr))) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
memcpy(sas, sin6, sizeof(*sin6));
|
|
|
|
((struct sockaddr_in6 *)sas)->sin6_port = inp->sctp_lport;
|
|
|
|
sas = (struct sockaddr_storage *)((caddr_t)sas + sizeof(*sin6));
|
|
|
|
actual += sizeof(*sin6);
|
|
|
|
if (actual >= limit) {
|
|
|
|
return (actual);
|
|
|
|
}
|
|
|
|
} else {
|
2006-11-03 15:23:16 +00:00
|
|
|
continue;
|
|
|
|
}
|
2008-04-16 17:24:18 +00:00
|
|
|
break;
|
|
|
|
#endif
|
|
|
|
default:
|
|
|
|
/* TSNH */
|
|
|
|
break;
|
2006-11-03 15:23:16 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
struct sctp_laddr *laddr;
|
|
|
|
|
2007-03-15 11:27:14 +00:00
|
|
|
LIST_FOREACH(laddr, &inp->sctp_addr_list, sctp_nxt_addr) {
|
|
|
|
if (stcb) {
|
|
|
|
if (sctp_is_addr_restricted(stcb, laddr->ifa)) {
|
2006-11-03 15:23:16 +00:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
2007-03-15 11:27:14 +00:00
|
|
|
if (sctp_fill_user_address(sas, &laddr->ifa->address.sa))
|
|
|
|
continue;
|
|
|
|
|
|
|
|
((struct sockaddr_in6 *)sas)->sin6_port = inp->sctp_lport;
|
|
|
|
sas = (struct sockaddr_storage *)((caddr_t)sas +
|
|
|
|
laddr->ifa->address.sa.sa_len);
|
|
|
|
actual += laddr->ifa->address.sa.sa_len;
|
|
|
|
if (actual >= limit) {
|
|
|
|
return (actual);
|
2006-11-03 15:23:16 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return (actual);
|
|
|
|
}
|
|
|
|
|
2007-03-31 11:47:30 +00:00
|
|
|
static size_t
|
|
|
|
sctp_fill_up_addresses(struct sctp_inpcb *inp,
|
|
|
|
struct sctp_tcb *stcb,
|
|
|
|
size_t limit,
|
|
|
|
struct sockaddr_storage *sas)
|
|
|
|
{
|
|
|
|
size_t size = 0;
|
|
|
|
|
2007-09-18 15:16:39 +00:00
|
|
|
SCTP_IPI_ADDR_RLOCK();
|
2007-03-31 11:47:30 +00:00
|
|
|
/* fill up addresses for the endpoint's default vrf */
|
|
|
|
size = sctp_fill_up_addresses_vrf(inp, stcb, limit, sas,
|
|
|
|
inp->def_vrf_id);
|
2007-09-18 15:16:39 +00:00
|
|
|
SCTP_IPI_ADDR_RUNLOCK();
|
2007-03-31 11:47:30 +00:00
|
|
|
return (size);
|
|
|
|
}
|
|
|
|
|
2007-09-08 17:48:46 +00:00
|
|
|
/*
|
|
|
|
* NOTE: assumes addr lock is held
|
|
|
|
*/
|
2006-11-03 15:23:16 +00:00
|
|
|
static int
|
2007-03-31 11:47:30 +00:00
|
|
|
sctp_count_max_addresses_vrf(struct sctp_inpcb *inp, uint32_t vrf_id)
|
2006-11-03 15:23:16 +00:00
|
|
|
{
|
|
|
|
int cnt = 0;
|
2007-03-15 11:27:14 +00:00
|
|
|
struct sctp_vrf *vrf = NULL;
|
2006-11-03 15:23:16 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* In both sub-set bound an bound_all cases we return the MAXIMUM
|
|
|
|
* number of addresses that you COULD get. In reality the sub-set
|
|
|
|
* bound may have an exclusion list for a given TCB OR in the
|
|
|
|
* bound-all case a TCB may NOT include the loopback or other
|
|
|
|
* addresses as well.
|
|
|
|
*/
|
2007-03-15 11:27:14 +00:00
|
|
|
vrf = sctp_find_vrf(vrf_id);
|
|
|
|
if (vrf == NULL) {
|
|
|
|
return (0);
|
|
|
|
}
|
2006-11-03 15:23:16 +00:00
|
|
|
if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUNDALL) {
|
2007-03-15 11:27:14 +00:00
|
|
|
struct sctp_ifn *sctp_ifn;
|
|
|
|
struct sctp_ifa *sctp_ifa;
|
2006-11-03 15:23:16 +00:00
|
|
|
|
2007-03-15 11:27:14 +00:00
|
|
|
LIST_FOREACH(sctp_ifn, &vrf->ifnlist, next_ifn) {
|
|
|
|
LIST_FOREACH(sctp_ifa, &sctp_ifn->ifalist, next_ifa) {
|
2006-11-03 15:23:16 +00:00
|
|
|
/* Count them if they are the right type */
|
2007-03-15 11:27:14 +00:00
|
|
|
if (sctp_ifa->address.sa.sa_family == AF_INET) {
|
2008-04-16 17:24:18 +00:00
|
|
|
if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_NEEDS_MAPPED_V4))
|
2006-11-03 15:23:16 +00:00
|
|
|
cnt += sizeof(struct sockaddr_in6);
|
|
|
|
else
|
|
|
|
cnt += sizeof(struct sockaddr_in);
|
|
|
|
|
2007-03-15 11:27:14 +00:00
|
|
|
} else if (sctp_ifa->address.sa.sa_family == AF_INET6)
|
2006-11-03 15:23:16 +00:00
|
|
|
cnt += sizeof(struct sockaddr_in6);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
struct sctp_laddr *laddr;
|
|
|
|
|
|
|
|
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_INET) {
|
2008-04-16 17:24:18 +00:00
|
|
|
if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_NEEDS_MAPPED_V4))
|
2006-11-03 15:23:16 +00:00
|
|
|
cnt += sizeof(struct sockaddr_in6);
|
|
|
|
else
|
|
|
|
cnt += sizeof(struct sockaddr_in);
|
|
|
|
|
2007-03-15 11:27:14 +00:00
|
|
|
} else if (laddr->ifa->address.sa.sa_family == AF_INET6)
|
2006-11-03 15:23:16 +00:00
|
|
|
cnt += sizeof(struct sockaddr_in6);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return (cnt);
|
|
|
|
}
|
|
|
|
|
2007-03-31 11:47:30 +00:00
|
|
|
static int
|
|
|
|
sctp_count_max_addresses(struct sctp_inpcb *inp)
|
|
|
|
{
|
|
|
|
int cnt = 0;
|
|
|
|
|
2007-09-18 15:16:39 +00:00
|
|
|
SCTP_IPI_ADDR_RLOCK();
|
2007-03-31 11:47:30 +00:00
|
|
|
/* count addresses for the endpoint's default VRF */
|
|
|
|
cnt = sctp_count_max_addresses_vrf(inp, inp->def_vrf_id);
|
2007-09-18 15:16:39 +00:00
|
|
|
SCTP_IPI_ADDR_RUNLOCK();
|
2007-03-31 11:47:30 +00:00
|
|
|
return (cnt);
|
|
|
|
}
|
|
|
|
|
2006-11-03 15:23:16 +00:00
|
|
|
static int
|
2007-02-12 23:24:31 +00:00
|
|
|
sctp_do_connect_x(struct socket *so, struct sctp_inpcb *inp, void *optval,
|
|
|
|
size_t optsize, void *p, int delay)
|
2006-11-03 15:23:16 +00:00
|
|
|
{
|
|
|
|
int error = 0;
|
|
|
|
int creat_lock_on = 0;
|
|
|
|
struct sctp_tcb *stcb = NULL;
|
|
|
|
struct sockaddr *sa;
|
2007-05-08 00:21:05 +00:00
|
|
|
int num_v6 = 0, num_v4 = 0, *totaddrp, totaddr;
|
|
|
|
int added = 0;
|
2007-03-15 11:27:14 +00:00
|
|
|
uint32_t vrf_id;
|
2007-05-28 11:17:24 +00:00
|
|
|
int bad_addresses = 0;
|
2007-03-15 11:27:14 +00:00
|
|
|
sctp_assoc_t *a_id;
|
2006-11-03 15:23:16 +00:00
|
|
|
|
2007-05-09 13:30:06 +00:00
|
|
|
SCTPDBG(SCTP_DEBUG_PCB1, "Connectx called\n");
|
2006-11-03 15:23:16 +00:00
|
|
|
|
|
|
|
if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) &&
|
|
|
|
(inp->sctp_flags & SCTP_PCB_FLAGS_CONNECTED)) {
|
|
|
|
/* We are already connected AND the TCP model */
|
2007-08-24 00:53:53 +00:00
|
|
|
SCTP_LTRACE_ERR_RET(inp, stcb, NULL, SCTP_FROM_SCTP_USRREQ, EADDRINUSE);
|
2006-11-03 15:23:16 +00:00
|
|
|
return (EADDRINUSE);
|
|
|
|
}
|
2008-07-31 11:08:30 +00:00
|
|
|
if ((inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) &&
|
|
|
|
(sctp_is_feature_off(inp, SCTP_PCB_FLAGS_PORTREUSE))) {
|
2007-08-24 00:53:53 +00:00
|
|
|
SCTP_LTRACE_ERR_RET(inp, stcb, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
|
2006-11-03 15:23:16 +00:00
|
|
|
return (EINVAL);
|
|
|
|
}
|
|
|
|
if (inp->sctp_flags & SCTP_PCB_FLAGS_CONNECTED) {
|
|
|
|
SCTP_INP_RLOCK(inp);
|
|
|
|
stcb = LIST_FIRST(&inp->sctp_asoc_list);
|
|
|
|
SCTP_INP_RUNLOCK(inp);
|
|
|
|
}
|
|
|
|
if (stcb) {
|
2007-08-24 00:53:53 +00:00
|
|
|
SCTP_LTRACE_ERR_RET(inp, stcb, NULL, SCTP_FROM_SCTP_USRREQ, EALREADY);
|
2006-11-03 15:23:16 +00:00
|
|
|
return (EALREADY);
|
|
|
|
}
|
|
|
|
SCTP_INP_INCR_REF(inp);
|
|
|
|
SCTP_ASOC_CREATE_LOCK(inp);
|
|
|
|
creat_lock_on = 1;
|
|
|
|
if ((inp->sctp_flags & SCTP_PCB_FLAGS_SOCKET_ALLGONE) ||
|
|
|
|
(inp->sctp_flags & SCTP_PCB_FLAGS_SOCKET_GONE)) {
|
2007-08-24 00:53:53 +00:00
|
|
|
SCTP_LTRACE_ERR_RET(inp, stcb, NULL, SCTP_FROM_SCTP_USRREQ, EFAULT);
|
2006-11-03 15:23:16 +00:00
|
|
|
error = EFAULT;
|
|
|
|
goto out_now;
|
|
|
|
}
|
2007-02-12 23:24:31 +00:00
|
|
|
totaddrp = (int *)optval;
|
2006-11-03 15:23:16 +00:00
|
|
|
totaddr = *totaddrp;
|
|
|
|
sa = (struct sockaddr *)(totaddrp + 1);
|
2007-05-28 11:17:24 +00:00
|
|
|
stcb = sctp_connectx_helper_find(inp, sa, &totaddr, &num_v4, &num_v6, &error, (optsize - sizeof(int)), &bad_addresses);
|
|
|
|
if ((stcb != NULL) || bad_addresses) {
|
2007-05-08 00:21:05 +00:00
|
|
|
/* Already have or am bring up an association */
|
|
|
|
SCTP_ASOC_CREATE_UNLOCK(inp);
|
|
|
|
creat_lock_on = 0;
|
2007-06-18 21:59:15 +00:00
|
|
|
if (stcb)
|
|
|
|
SCTP_TCB_UNLOCK(stcb);
|
2007-08-24 00:53:53 +00:00
|
|
|
if (bad_addresses == 0) {
|
|
|
|
SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EALREADY);
|
2007-05-28 11:17:24 +00:00
|
|
|
error = EALREADY;
|
2007-08-24 00:53:53 +00:00
|
|
|
}
|
2007-05-08 00:21:05 +00:00
|
|
|
goto out_now;
|
2006-11-03 15:23:16 +00:00
|
|
|
}
|
|
|
|
#ifdef INET6
|
|
|
|
if (((inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) == 0) &&
|
|
|
|
(num_v6 > 0)) {
|
|
|
|
error = EINVAL;
|
|
|
|
goto out_now;
|
|
|
|
}
|
|
|
|
if ((inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) &&
|
|
|
|
(num_v4 > 0)) {
|
|
|
|
struct in6pcb *inp6;
|
|
|
|
|
|
|
|
inp6 = (struct in6pcb *)inp;
|
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
|
|
|
|
*/
|
2007-08-24 00:53:53 +00:00
|
|
|
SCTP_LTRACE_ERR_RET(inp, stcb, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
|
2006-11-03 15:23:16 +00:00
|
|
|
error = EINVAL;
|
|
|
|
goto out_now;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif /* INET6 */
|
|
|
|
if ((inp->sctp_flags & SCTP_PCB_FLAGS_UNBOUND) ==
|
|
|
|
SCTP_PCB_FLAGS_UNBOUND) {
|
|
|
|
/* Bind a ephemeral port */
|
2007-07-24 20:06:02 +00:00
|
|
|
error = sctp_inpcb_bind(so, NULL, NULL, p);
|
2006-11-03 15:23:16 +00:00
|
|
|
if (error) {
|
|
|
|
goto out_now;
|
|
|
|
}
|
|
|
|
}
|
2007-03-19 06:53:02 +00:00
|
|
|
/* FIX ME: do we want to pass in a vrf on the connect call? */
|
|
|
|
vrf_id = inp->def_vrf_id;
|
|
|
|
|
2008-07-31 11:08:30 +00:00
|
|
|
|
2006-11-03 15:23:16 +00:00
|
|
|
/* We are GOOD to go */
|
2010-04-03 15:40:14 +00:00
|
|
|
stcb = sctp_aloc_assoc(inp, sa, &error, 0, vrf_id,
|
2007-07-21 21:41:32 +00:00
|
|
|
(struct thread *)p
|
|
|
|
);
|
2006-11-03 15:23:16 +00:00
|
|
|
if (stcb == NULL) {
|
|
|
|
/* Gak! no memory */
|
|
|
|
goto out_now;
|
|
|
|
}
|
2007-08-24 00:53:53 +00:00
|
|
|
SCTP_SET_STATE(&stcb->asoc, SCTP_STATE_COOKIE_WAIT);
|
2006-11-03 15:23:16 +00:00
|
|
|
/* move to second address */
|
|
|
|
if (sa->sa_family == AF_INET)
|
|
|
|
sa = (struct sockaddr *)((caddr_t)sa + sizeof(struct sockaddr_in));
|
|
|
|
else
|
|
|
|
sa = (struct sockaddr *)((caddr_t)sa + sizeof(struct sockaddr_in6));
|
|
|
|
|
2007-05-28 11:17:24 +00:00
|
|
|
error = 0;
|
2007-05-08 00:21:05 +00:00
|
|
|
added = sctp_connectx_helper_add(stcb, sa, (totaddr - 1), &error);
|
2007-03-15 11:27:14 +00:00
|
|
|
/* Fill in the return id */
|
2007-05-28 11:17:24 +00:00
|
|
|
if (error) {
|
2010-05-11 17:02:29 +00:00
|
|
|
(void)sctp_free_assoc(inp, stcb, SCTP_PCBFREE_FORCE, SCTP_FROM_SCTP_USRREQ + SCTP_LOC_6);
|
2007-05-28 11:17:24 +00:00
|
|
|
goto out_now;
|
|
|
|
}
|
2007-03-15 11:27:14 +00:00
|
|
|
a_id = (sctp_assoc_t *) optval;
|
|
|
|
*a_id = sctp_get_associd(stcb);
|
2006-11-03 15:23:16 +00:00
|
|
|
|
|
|
|
/* initialize authentication parameters for the assoc */
|
|
|
|
sctp_initialize_auth_params(inp, stcb);
|
|
|
|
|
|
|
|
if (delay) {
|
|
|
|
/* doing delayed connection */
|
|
|
|
stcb->asoc.delayed_connection = 1;
|
|
|
|
sctp_timer_start(SCTP_TIMER_TYPE_INIT, inp, stcb, stcb->asoc.primary_destination);
|
|
|
|
} else {
|
2007-05-08 14:32:53 +00:00
|
|
|
(void)SCTP_GETTIME_TIMEVAL(&stcb->asoc.time_entered);
|
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);
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
out_now:
|
2007-05-17 12:16:24 +00:00
|
|
|
if (creat_lock_on) {
|
2006-11-03 15:23:16 +00:00
|
|
|
SCTP_ASOC_CREATE_UNLOCK(inp);
|
2007-05-17 12:16:24 +00:00
|
|
|
}
|
2006-11-03 15:23:16 +00:00
|
|
|
SCTP_INP_DECR_REF(inp);
|
|
|
|
return error;
|
|
|
|
}
|
|
|
|
|
2007-05-09 13:30:06 +00:00
|
|
|
#define SCTP_FIND_STCB(inp, stcb, assoc_id) { \
|
2007-05-17 12:16:24 +00:00
|
|
|
if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||\
|
|
|
|
(inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL)) { \
|
2007-02-12 23:24:31 +00:00
|
|
|
SCTP_INP_RLOCK(inp); \
|
|
|
|
stcb = LIST_FIRST(&inp->sctp_asoc_list); \
|
2007-05-17 12:16:24 +00:00
|
|
|
if (stcb) { \
|
2007-02-12 23:24:31 +00:00
|
|
|
SCTP_TCB_LOCK(stcb); \
|
2007-05-17 12:16:24 +00:00
|
|
|
} \
|
2007-02-12 23:24:31 +00:00
|
|
|
SCTP_INP_RUNLOCK(inp); \
|
|
|
|
} else if (assoc_id != 0) { \
|
|
|
|
stcb = sctp_findassociation_ep_asocid(inp, assoc_id, 1); \
|
|
|
|
if (stcb == NULL) { \
|
2007-08-24 00:53:53 +00:00
|
|
|
SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOENT); \
|
2007-02-12 23:24:31 +00:00
|
|
|
error = ENOENT; \
|
|
|
|
break; \
|
|
|
|
} \
|
|
|
|
} else { \
|
|
|
|
stcb = NULL; \
|
2007-05-09 13:30:06 +00:00
|
|
|
} \
|
|
|
|
}
|
2007-02-12 23:24:31 +00:00
|
|
|
|
2007-05-09 13:30:06 +00:00
|
|
|
|
|
|
|
#define SCTP_CHECK_AND_CAST(destp, srcp, type, size) {\
|
2007-02-12 23:24:31 +00:00
|
|
|
if (size < sizeof(type)) { \
|
2007-08-24 00:53:53 +00:00
|
|
|
SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL); \
|
2007-02-12 23:24:31 +00:00
|
|
|
error = EINVAL; \
|
|
|
|
break; \
|
|
|
|
} else { \
|
|
|
|
destp = (type *)srcp; \
|
2007-05-09 13:30:06 +00:00
|
|
|
} \
|
|
|
|
}
|
2006-11-03 15:23:16 +00:00
|
|
|
|
|
|
|
static int
|
2007-02-12 23:24:31 +00:00
|
|
|
sctp_getopt(struct socket *so, int optname, void *optval, size_t *optsize,
|
|
|
|
void *p)
|
2006-11-03 15:23:16 +00:00
|
|
|
{
|
2007-08-24 00:53:53 +00:00
|
|
|
struct sctp_inpcb *inp = NULL;
|
2007-02-12 23:24:31 +00:00
|
|
|
int error, val = 0;
|
2006-11-03 15:23:16 +00:00
|
|
|
struct sctp_tcb *stcb = NULL;
|
|
|
|
|
2007-02-12 23:24:31 +00:00
|
|
|
if (optval == NULL) {
|
2007-08-24 00:53:53 +00:00
|
|
|
SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
|
2007-02-12 23:24:31 +00:00
|
|
|
return (EINVAL);
|
|
|
|
}
|
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_SCTP_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 = 0;
|
|
|
|
|
2007-02-12 23:24:31 +00:00
|
|
|
switch (optname) {
|
2006-11-03 15:23:16 +00:00
|
|
|
case SCTP_NODELAY:
|
|
|
|
case SCTP_AUTOCLOSE:
|
|
|
|
case SCTP_EXPLICIT_EOR:
|
|
|
|
case SCTP_AUTO_ASCONF:
|
|
|
|
case SCTP_DISABLE_FRAGMENTS:
|
|
|
|
case SCTP_I_WANT_MAPPED_V4_ADDR:
|
|
|
|
case SCTP_USE_EXT_RCVINFO:
|
|
|
|
SCTP_INP_RLOCK(inp);
|
2007-02-12 23:24:31 +00:00
|
|
|
switch (optname) {
|
2006-11-03 15:23:16 +00:00
|
|
|
case SCTP_DISABLE_FRAGMENTS:
|
2007-02-12 23:24:31 +00:00
|
|
|
val = sctp_is_feature_on(inp, SCTP_PCB_FLAGS_NO_FRAGMENT);
|
2006-11-03 15:23:16 +00:00
|
|
|
break;
|
|
|
|
case SCTP_I_WANT_MAPPED_V4_ADDR:
|
2007-02-12 23:24:31 +00:00
|
|
|
val = sctp_is_feature_on(inp, SCTP_PCB_FLAGS_NEEDS_MAPPED_V4);
|
2006-11-03 15:23:16 +00:00
|
|
|
break;
|
|
|
|
case SCTP_AUTO_ASCONF:
|
2007-08-24 00:53:53 +00:00
|
|
|
if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUNDALL) {
|
|
|
|
/* only valid for bound all sockets */
|
|
|
|
val = sctp_is_feature_on(inp, SCTP_PCB_FLAGS_AUTO_ASCONF);
|
|
|
|
} else {
|
|
|
|
SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
|
|
|
|
error = EINVAL;
|
|
|
|
goto flags_out;
|
|
|
|
}
|
2006-11-03 15:23:16 +00:00
|
|
|
break;
|
|
|
|
case SCTP_EXPLICIT_EOR:
|
2007-02-12 23:24:31 +00:00
|
|
|
val = sctp_is_feature_on(inp, SCTP_PCB_FLAGS_EXPLICIT_EOR);
|
2006-11-03 15:23:16 +00:00
|
|
|
break;
|
|
|
|
case SCTP_NODELAY:
|
2007-02-12 23:24:31 +00:00
|
|
|
val = sctp_is_feature_on(inp, SCTP_PCB_FLAGS_NODELAY);
|
2006-11-03 15:23:16 +00:00
|
|
|
break;
|
|
|
|
case SCTP_USE_EXT_RCVINFO:
|
2007-02-12 23:24:31 +00:00
|
|
|
val = sctp_is_feature_on(inp, SCTP_PCB_FLAGS_EXT_RCVINFO);
|
2006-11-03 15:23:16 +00:00
|
|
|
break;
|
|
|
|
case SCTP_AUTOCLOSE:
|
|
|
|
if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_AUTOCLOSE))
|
2007-02-12 23:24:31 +00:00
|
|
|
val = TICKS_TO_SEC(inp->sctp_ep.auto_close_time);
|
2006-11-03 15:23:16 +00:00
|
|
|
else
|
2007-02-12 23:24:31 +00:00
|
|
|
val = 0;
|
2006-11-03 15:23:16 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
2007-08-24 00:53:53 +00:00
|
|
|
SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOPROTOOPT);
|
2006-11-03 15:23:16 +00:00
|
|
|
error = ENOPROTOOPT;
|
|
|
|
} /* end switch (sopt->sopt_name) */
|
2007-02-12 23:24:31 +00:00
|
|
|
if (optname != SCTP_AUTOCLOSE) {
|
2006-11-03 15:23:16 +00:00
|
|
|
/* make it an "on/off" value */
|
2007-02-12 23:24:31 +00:00
|
|
|
val = (val != 0);
|
2006-11-03 15:23:16 +00:00
|
|
|
}
|
2007-02-12 23:24:31 +00:00
|
|
|
if (*optsize < sizeof(val)) {
|
2007-08-24 00:53:53 +00:00
|
|
|
SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
|
2006-11-03 15:23:16 +00:00
|
|
|
error = EINVAL;
|
|
|
|
}
|
2007-08-24 00:53:53 +00:00
|
|
|
flags_out:
|
2006-11-03 15:23:16 +00:00
|
|
|
SCTP_INP_RUNLOCK(inp);
|
|
|
|
if (error == 0) {
|
|
|
|
/* return the option value */
|
2007-02-12 23:24:31 +00:00
|
|
|
*(int *)optval = val;
|
|
|
|
*optsize = sizeof(val);
|
2006-11-03 15:23:16 +00:00
|
|
|
}
|
|
|
|
break;
|
2007-05-29 09:29:03 +00:00
|
|
|
case SCTP_GET_PACKET_LOG:
|
|
|
|
{
|
|
|
|
#ifdef SCTP_PACKET_LOGGING
|
|
|
|
uint8_t *target;
|
|
|
|
int ret;
|
2007-03-15 11:27:14 +00:00
|
|
|
|
2007-05-29 09:29:03 +00:00
|
|
|
SCTP_CHECK_AND_CAST(target, optval, uint8_t, *optsize);
|
|
|
|
ret = sctp_copy_out_packet_log(target, (int)*optsize);
|
|
|
|
*optsize = ret;
|
|
|
|
#else
|
2007-08-24 00:53:53 +00:00
|
|
|
SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EOPNOTSUPP);
|
2007-05-29 09:29:03 +00:00
|
|
|
error = EOPNOTSUPP;
|
|
|
|
#endif
|
|
|
|
break;
|
|
|
|
}
|
2008-07-31 11:08:30 +00:00
|
|
|
case SCTP_REUSE_PORT:
|
|
|
|
{
|
|
|
|
uint32_t *value;
|
|
|
|
|
|
|
|
if ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE)) {
|
|
|
|
/* Can't do this for a 1-m socket */
|
|
|
|
error = EINVAL;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
SCTP_CHECK_AND_CAST(value, optval, uint32_t, *optsize);
|
|
|
|
*value = sctp_is_feature_on(inp, SCTP_PCB_FLAGS_PORTREUSE);
|
|
|
|
*optsize = sizeof(uint32_t);
|
|
|
|
}
|
|
|
|
break;
|
2006-11-03 15:23:16 +00:00
|
|
|
case SCTP_PARTIAL_DELIVERY_POINT:
|
|
|
|
{
|
2007-02-12 23:24:31 +00:00
|
|
|
uint32_t *value;
|
|
|
|
|
|
|
|
SCTP_CHECK_AND_CAST(value, optval, uint32_t, *optsize);
|
|
|
|
*value = inp->partial_delivery_point;
|
|
|
|
*optsize = sizeof(uint32_t);
|
2006-11-03 15:23:16 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case SCTP_FRAGMENT_INTERLEAVE:
|
|
|
|
{
|
2007-02-12 23:24:31 +00:00
|
|
|
uint32_t *value;
|
|
|
|
|
|
|
|
SCTP_CHECK_AND_CAST(value, optval, uint32_t, *optsize);
|
2007-04-22 11:06:27 +00:00
|
|
|
if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_FRAG_INTERLEAVE)) {
|
|
|
|
if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_INTERLEAVE_STRMS)) {
|
|
|
|
*value = SCTP_FRAG_LEVEL_2;
|
|
|
|
} else {
|
|
|
|
*value = SCTP_FRAG_LEVEL_1;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
*value = SCTP_FRAG_LEVEL_0;
|
|
|
|
}
|
2007-02-12 23:24:31 +00:00
|
|
|
*optsize = sizeof(uint32_t);
|
2006-11-03 15:23:16 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case SCTP_CMT_ON_OFF:
|
|
|
|
{
|
2007-02-12 23:24:31 +00:00
|
|
|
struct sctp_assoc_value *av;
|
|
|
|
|
|
|
|
SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
|
2010-08-28 17:59:51 +00:00
|
|
|
SCTP_FIND_STCB(inp, stcb, av->assoc_id);
|
|
|
|
if (stcb) {
|
|
|
|
av->assoc_value = stcb->asoc.sctp_cmt_on_off;
|
|
|
|
SCTP_TCB_UNLOCK(stcb);
|
2008-12-06 13:19:54 +00:00
|
|
|
} else {
|
2010-08-28 17:59:51 +00:00
|
|
|
SCTP_INP_RLOCK(inp);
|
|
|
|
av->assoc_value = inp->sctp_cmt_on_off;
|
|
|
|
SCTP_INP_RUNLOCK(inp);
|
2008-12-06 13:19:54 +00:00
|
|
|
}
|
|
|
|
*optsize = sizeof(*av);
|
|
|
|
}
|
|
|
|
break;
|
2007-07-14 09:36:28 +00:00
|
|
|
/* JRS - Get socket option for pluggable congestion control */
|
|
|
|
case SCTP_PLUGGABLE_CC:
|
|
|
|
{
|
|
|
|
struct sctp_assoc_value *av;
|
|
|
|
|
|
|
|
SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
|
|
|
|
SCTP_FIND_STCB(inp, stcb, av->assoc_id);
|
|
|
|
if (stcb) {
|
|
|
|
av->assoc_value = stcb->asoc.congestion_control_module;
|
|
|
|
SCTP_TCB_UNLOCK(stcb);
|
|
|
|
} else {
|
|
|
|
av->assoc_value = inp->sctp_ep.sctp_default_cc_module;
|
|
|
|
}
|
|
|
|
*optsize = sizeof(*av);
|
|
|
|
}
|
|
|
|
break;
|
2011-02-26 15:23:46 +00:00
|
|
|
case SCTP_CC_OPTION:
|
|
|
|
{
|
|
|
|
struct sctp_cc_option *cc_opt;
|
|
|
|
|
|
|
|
SCTP_CHECK_AND_CAST(cc_opt, optval, struct sctp_cc_option, *optsize);
|
|
|
|
SCTP_FIND_STCB(inp, stcb, cc_opt->aid_value.assoc_id);
|
|
|
|
if (stcb == NULL) {
|
|
|
|
error = EINVAL;
|
|
|
|
} else {
|
|
|
|
if (stcb->asoc.cc_functions.sctp_cwnd_socket_option == NULL) {
|
|
|
|
error = ENOTSUP;
|
|
|
|
} else {
|
|
|
|
error = (*stcb->asoc.cc_functions.sctp_cwnd_socket_option) (stcb, 0,
|
|
|
|
cc_opt);
|
|
|
|
*optsize = sizeof(*cc_opt);
|
|
|
|
}
|
|
|
|
SCTP_TCB_UNLOCK(stcb);
|
|
|
|
}
|
|
|
|
}
|
2011-03-01 00:37:46 +00:00
|
|
|
break;
|
2011-01-23 19:36:28 +00:00
|
|
|
/* RS - Get socket option for pluggable stream scheduling */
|
|
|
|
case SCTP_PLUGGABLE_SS:
|
|
|
|
{
|
|
|
|
struct sctp_assoc_value *av;
|
|
|
|
|
|
|
|
SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
|
|
|
|
SCTP_FIND_STCB(inp, stcb, av->assoc_id);
|
|
|
|
if (stcb) {
|
|
|
|
av->assoc_value = stcb->asoc.stream_scheduling_module;
|
|
|
|
SCTP_TCB_UNLOCK(stcb);
|
|
|
|
} else {
|
|
|
|
av->assoc_value = inp->sctp_ep.sctp_default_ss_module;
|
|
|
|
}
|
|
|
|
*optsize = sizeof(*av);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case SCTP_SS_VALUE:
|
|
|
|
{
|
|
|
|
struct sctp_stream_value *av;
|
|
|
|
|
|
|
|
SCTP_CHECK_AND_CAST(av, optval, struct sctp_stream_value, *optsize);
|
|
|
|
SCTP_FIND_STCB(inp, stcb, av->assoc_id);
|
|
|
|
if (stcb) {
|
|
|
|
if (stcb->asoc.ss_functions.sctp_ss_get_value(stcb, &stcb->asoc, &stcb->asoc.strmout[av->stream_id],
|
|
|
|
&av->stream_value) < 0) {
|
|
|
|
SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
|
|
|
|
error = EINVAL;
|
|
|
|
} else {
|
|
|
|
*optsize = sizeof(*av);
|
|
|
|
}
|
|
|
|
SCTP_TCB_UNLOCK(stcb);
|
|
|
|
} else {
|
|
|
|
/*
|
|
|
|
* Can't get stream value without
|
|
|
|
* association
|
|
|
|
*/
|
|
|
|
SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
|
|
|
|
error = EINVAL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
2006-11-03 15:23:16 +00:00
|
|
|
case SCTP_GET_ADDR_LEN:
|
|
|
|
{
|
|
|
|
struct sctp_assoc_value *av;
|
|
|
|
|
2007-02-12 23:24:31 +00:00
|
|
|
SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
|
2006-11-03 15:23:16 +00:00
|
|
|
error = EINVAL;
|
2007-03-15 11:27:14 +00:00
|
|
|
#ifdef INET
|
2006-11-03 15:23:16 +00:00
|
|
|
if (av->assoc_value == AF_INET) {
|
|
|
|
av->assoc_value = sizeof(struct sockaddr_in);
|
|
|
|
error = 0;
|
|
|
|
}
|
|
|
|
#endif
|
2007-03-15 11:27:14 +00:00
|
|
|
#ifdef INET6
|
2006-11-03 15:23:16 +00:00
|
|
|
if (av->assoc_value == AF_INET6) {
|
|
|
|
av->assoc_value = sizeof(struct sockaddr_in6);
|
|
|
|
error = 0;
|
|
|
|
}
|
|
|
|
#endif
|
2007-09-08 17:48:46 +00:00
|
|
|
if (error) {
|
2007-08-24 00:53:53 +00:00
|
|
|
SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
|
2007-09-08 17:48:46 +00:00
|
|
|
}
|
2007-02-12 23:24:31 +00:00
|
|
|
*optsize = sizeof(*av);
|
2006-11-03 15:23:16 +00:00
|
|
|
}
|
|
|
|
break;
|
2007-05-17 12:16:24 +00:00
|
|
|
case SCTP_GET_ASSOC_NUMBER:
|
2006-11-03 15:23:16 +00:00
|
|
|
{
|
2007-05-17 12:16:24 +00:00
|
|
|
uint32_t *value, cnt;
|
2006-11-03 15:23:16 +00:00
|
|
|
|
2007-05-17 12:16:24 +00:00
|
|
|
SCTP_CHECK_AND_CAST(value, optval, uint32_t, *optsize);
|
2006-11-03 15:23:16 +00:00
|
|
|
cnt = 0;
|
|
|
|
SCTP_INP_RLOCK(inp);
|
2007-05-17 12:16:24 +00:00
|
|
|
LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
|
|
|
|
cnt++;
|
2006-11-03 15:23:16 +00:00
|
|
|
}
|
2007-05-17 12:16:24 +00:00
|
|
|
SCTP_INP_RUNLOCK(inp);
|
|
|
|
*value = cnt;
|
|
|
|
*optsize = sizeof(uint32_t);
|
|
|
|
}
|
|
|
|
break;
|
2006-11-03 15:23:16 +00:00
|
|
|
|
2007-05-17 12:16:24 +00:00
|
|
|
case SCTP_GET_ASSOC_ID_LIST:
|
|
|
|
{
|
|
|
|
struct sctp_assoc_ids *ids;
|
|
|
|
unsigned int at, limit;
|
|
|
|
|
|
|
|
SCTP_CHECK_AND_CAST(ids, optval, struct sctp_assoc_ids, *optsize);
|
2006-11-03 15:23:16 +00:00
|
|
|
at = 0;
|
2008-12-06 13:19:54 +00:00
|
|
|
limit = (*optsize - sizeof(uint32_t)) / sizeof(sctp_assoc_t);
|
2007-05-17 12:16:24 +00:00
|
|
|
SCTP_INP_RLOCK(inp);
|
|
|
|
LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
|
|
|
|
if (at < limit) {
|
|
|
|
ids->gaids_assoc_id[at++] = sctp_get_associd(stcb);
|
|
|
|
} else {
|
|
|
|
error = EINVAL;
|
2007-08-24 00:53:53 +00:00
|
|
|
SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
|
2006-11-03 15:23:16 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
SCTP_INP_RUNLOCK(inp);
|
2008-12-06 13:19:54 +00:00
|
|
|
ids->gaids_number_of_ids = at;
|
|
|
|
*optsize = ((at * sizeof(sctp_assoc_t)) + sizeof(uint32_t));
|
2006-11-03 15:23:16 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case SCTP_CONTEXT:
|
|
|
|
{
|
|
|
|
struct sctp_assoc_value *av;
|
|
|
|
|
2007-02-12 23:24:31 +00:00
|
|
|
SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
|
|
|
|
SCTP_FIND_STCB(inp, stcb, av->assoc_id);
|
|
|
|
|
|
|
|
if (stcb) {
|
|
|
|
av->assoc_value = stcb->asoc.context;
|
|
|
|
SCTP_TCB_UNLOCK(stcb);
|
2006-11-03 15:23:16 +00:00
|
|
|
} else {
|
2007-02-12 23:24:31 +00:00
|
|
|
SCTP_INP_RLOCK(inp);
|
2006-11-03 15:23:16 +00:00
|
|
|
av->assoc_value = inp->sctp_context;
|
2007-02-12 23:24:31 +00:00
|
|
|
SCTP_INP_RUNLOCK(inp);
|
2006-11-03 15:23:16 +00:00
|
|
|
}
|
2007-02-12 23:24:31 +00:00
|
|
|
*optsize = sizeof(*av);
|
2006-11-03 15:23:16 +00:00
|
|
|
}
|
|
|
|
break;
|
2007-03-15 11:27:14 +00:00
|
|
|
case SCTP_VRF_ID:
|
|
|
|
{
|
2007-05-28 11:17:24 +00:00
|
|
|
uint32_t *default_vrfid;
|
2007-03-15 11:27:14 +00:00
|
|
|
|
2007-05-28 11:17:24 +00:00
|
|
|
SCTP_CHECK_AND_CAST(default_vrfid, optval, uint32_t, *optsize);
|
|
|
|
*default_vrfid = inp->def_vrf_id;
|
2007-03-15 11:27:14 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case SCTP_GET_ASOC_VRF:
|
|
|
|
{
|
|
|
|
struct sctp_assoc_value *id;
|
|
|
|
|
|
|
|
SCTP_CHECK_AND_CAST(id, optval, struct sctp_assoc_value, *optsize);
|
|
|
|
SCTP_FIND_STCB(inp, stcb, id->assoc_id);
|
|
|
|
if (stcb == NULL) {
|
|
|
|
error = EINVAL;
|
2007-08-24 00:53:53 +00:00
|
|
|
SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
|
2007-03-15 11:27:14 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
id->assoc_value = stcb->asoc.vrf_id;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case SCTP_GET_VRF_IDS:
|
|
|
|
{
|
2007-08-24 00:53:53 +00:00
|
|
|
SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EOPNOTSUPP);
|
2007-03-15 11:27:14 +00:00
|
|
|
error = EOPNOTSUPP;
|
|
|
|
break;
|
|
|
|
}
|
2006-11-03 15:23:16 +00:00
|
|
|
case SCTP_GET_NONCE_VALUES:
|
|
|
|
{
|
|
|
|
struct sctp_get_nonce_values *gnv;
|
|
|
|
|
2007-02-12 23:24:31 +00:00
|
|
|
SCTP_CHECK_AND_CAST(gnv, optval, struct sctp_get_nonce_values, *optsize);
|
|
|
|
SCTP_FIND_STCB(inp, stcb, gnv->gn_assoc_id);
|
|
|
|
|
|
|
|
if (stcb) {
|
2006-11-03 15:23:16 +00:00
|
|
|
gnv->gn_peers_tag = stcb->asoc.peer_vtag;
|
|
|
|
gnv->gn_local_tag = stcb->asoc.my_vtag;
|
|
|
|
SCTP_TCB_UNLOCK(stcb);
|
2007-02-12 23:24:31 +00:00
|
|
|
} else {
|
2007-08-24 00:53:53 +00:00
|
|
|
SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOTCONN);
|
2007-02-12 23:24:31 +00:00
|
|
|
error = ENOTCONN;
|
2006-11-03 15:23:16 +00:00
|
|
|
}
|
2007-02-12 23:24:31 +00:00
|
|
|
*optsize = sizeof(*gnv);
|
2006-11-03 15:23:16 +00:00
|
|
|
}
|
|
|
|
break;
|
2007-05-28 11:17:24 +00:00
|
|
|
case SCTP_DELAYED_SACK:
|
2006-11-03 15:23:16 +00:00
|
|
|
{
|
2007-05-28 11:17:24 +00:00
|
|
|
struct sctp_sack_info *sack;
|
2006-11-03 15:23:16 +00:00
|
|
|
|
2007-05-28 11:17:24 +00:00
|
|
|
SCTP_CHECK_AND_CAST(sack, optval, struct sctp_sack_info, *optsize);
|
|
|
|
SCTP_FIND_STCB(inp, stcb, sack->sack_assoc_id);
|
2007-02-12 23:24:31 +00:00
|
|
|
if (stcb) {
|
2007-05-28 11:17:24 +00:00
|
|
|
sack->sack_delay = stcb->asoc.delayed_ack;
|
|
|
|
sack->sack_freq = stcb->asoc.sack_freq;
|
2007-02-12 23:24:31 +00:00
|
|
|
SCTP_TCB_UNLOCK(stcb);
|
|
|
|
} else {
|
2006-11-03 15:23:16 +00:00
|
|
|
SCTP_INP_RLOCK(inp);
|
2007-05-28 11:17:24 +00:00
|
|
|
sack->sack_delay = TICKS_TO_MSEC(inp->sctp_ep.sctp_timeoutticks[SCTP_TIMER_RECV]);
|
|
|
|
sack->sack_freq = inp->sctp_ep.sctp_sack_freq;
|
2006-11-03 15:23:16 +00:00
|
|
|
SCTP_INP_RUNLOCK(inp);
|
|
|
|
}
|
2007-05-28 11:17:24 +00:00
|
|
|
*optsize = sizeof(*sack);
|
2006-11-03 15:23:16 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case SCTP_GET_SNDBUF_USE:
|
2007-02-12 23:24:31 +00:00
|
|
|
{
|
2006-11-03 15:23:16 +00:00
|
|
|
struct sctp_sockstat *ss;
|
|
|
|
|
2007-02-12 23:24:31 +00:00
|
|
|
SCTP_CHECK_AND_CAST(ss, optval, struct sctp_sockstat, *optsize);
|
|
|
|
SCTP_FIND_STCB(inp, stcb, ss->ss_assoc_id);
|
|
|
|
|
|
|
|
if (stcb) {
|
|
|
|
ss->ss_total_sndbuf = stcb->asoc.total_output_queue_size;
|
|
|
|
ss->ss_total_recv_buf = (stcb->asoc.size_on_reasm_queue +
|
|
|
|
stcb->asoc.size_on_all_streams);
|
2006-11-03 15:23:16 +00:00
|
|
|
SCTP_TCB_UNLOCK(stcb);
|
2007-02-12 23:24:31 +00:00
|
|
|
} else {
|
2007-08-24 00:53:53 +00:00
|
|
|
SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOTCONN);
|
2007-02-12 23:24:31 +00:00
|
|
|
error = ENOTCONN;
|
2006-11-03 15:23:16 +00:00
|
|
|
}
|
2007-02-12 23:24:31 +00:00
|
|
|
*optsize = sizeof(struct sctp_sockstat);
|
2006-11-03 15:23:16 +00:00
|
|
|
}
|
|
|
|
break;
|
2007-05-28 11:17:24 +00:00
|
|
|
case SCTP_MAX_BURST:
|
2006-11-03 15:23:16 +00:00
|
|
|
{
|
2011-01-26 19:55:54 +00:00
|
|
|
struct sctp_assoc_value *av;
|
2007-02-12 23:24:31 +00:00
|
|
|
|
2011-01-26 19:55:54 +00:00
|
|
|
SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
|
|
|
|
SCTP_FIND_STCB(inp, stcb, av->assoc_id);
|
2006-11-03 15:23:16 +00:00
|
|
|
|
2011-01-26 19:55:54 +00:00
|
|
|
if (stcb) {
|
|
|
|
av->assoc_value = stcb->asoc.max_burst;
|
|
|
|
SCTP_TCB_UNLOCK(stcb);
|
2011-01-26 19:49:03 +00:00
|
|
|
} else {
|
2011-01-26 19:55:54 +00:00
|
|
|
SCTP_INP_RLOCK(inp);
|
|
|
|
av->assoc_value = inp->sctp_ep.max_burst;
|
|
|
|
SCTP_INP_RUNLOCK(inp);
|
2011-01-26 19:49:03 +00:00
|
|
|
}
|
2011-01-26 19:55:54 +00:00
|
|
|
*optsize = sizeof(struct sctp_assoc_value);
|
|
|
|
|
2006-11-03 15:23:16 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case SCTP_MAXSEG:
|
|
|
|
{
|
2007-03-15 11:27:14 +00:00
|
|
|
struct sctp_assoc_value *av;
|
2006-11-03 15:23:16 +00:00
|
|
|
int ovh;
|
|
|
|
|
2007-03-15 11:27:14 +00:00
|
|
|
SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
|
2007-05-28 11:17:24 +00:00
|
|
|
SCTP_FIND_STCB(inp, stcb, av->assoc_id);
|
2006-11-03 15:23:16 +00:00
|
|
|
|
2007-03-15 11:27:14 +00:00
|
|
|
if (stcb) {
|
|
|
|
av->assoc_value = sctp_get_frag_point(stcb, &stcb->asoc);
|
|
|
|
SCTP_TCB_UNLOCK(stcb);
|
2006-11-03 15:23:16 +00:00
|
|
|
} else {
|
2007-03-15 11:27:14 +00:00
|
|
|
SCTP_INP_RLOCK(inp);
|
|
|
|
if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) {
|
|
|
|
ovh = SCTP_MED_OVERHEAD;
|
|
|
|
} else {
|
|
|
|
ovh = SCTP_MED_V4_OVERHEAD;
|
|
|
|
}
|
2007-05-28 11:17:24 +00:00
|
|
|
if (inp->sctp_frag_point >= SCTP_DEFAULT_MAXSEGMENT)
|
|
|
|
av->assoc_value = 0;
|
|
|
|
else
|
|
|
|
av->assoc_value = inp->sctp_frag_point - ovh;
|
2007-03-15 11:27:14 +00:00
|
|
|
SCTP_INP_RUNLOCK(inp);
|
2006-11-03 15:23:16 +00:00
|
|
|
}
|
2007-03-15 11:27:14 +00:00
|
|
|
*optsize = sizeof(struct sctp_assoc_value);
|
2006-11-03 15:23:16 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case SCTP_GET_STAT_LOG:
|
2007-03-15 11:27:14 +00:00
|
|
|
error = sctp_fill_stat_log(optval, optsize);
|
2006-11-03 15:23:16 +00:00
|
|
|
break;
|
|
|
|
case SCTP_EVENTS:
|
|
|
|
{
|
|
|
|
struct sctp_event_subscribe *events;
|
|
|
|
|
2007-02-12 23:24:31 +00:00
|
|
|
SCTP_CHECK_AND_CAST(events, optval, struct sctp_event_subscribe, *optsize);
|
2006-11-03 15:23:16 +00:00
|
|
|
memset(events, 0, sizeof(*events));
|
|
|
|
SCTP_INP_RLOCK(inp);
|
|
|
|
if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_RECVDATAIOEVNT))
|
|
|
|
events->sctp_data_io_event = 1;
|
|
|
|
|
|
|
|
if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_RECVASSOCEVNT))
|
|
|
|
events->sctp_association_event = 1;
|
|
|
|
|
|
|
|
if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_RECVPADDREVNT))
|
|
|
|
events->sctp_address_event = 1;
|
|
|
|
|
|
|
|
if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_RECVSENDFAILEVNT))
|
|
|
|
events->sctp_send_failure_event = 1;
|
|
|
|
|
|
|
|
if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_RECVPEERERR))
|
|
|
|
events->sctp_peer_error_event = 1;
|
|
|
|
|
|
|
|
if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_RECVSHUTDOWNEVNT))
|
|
|
|
events->sctp_shutdown_event = 1;
|
|
|
|
|
|
|
|
if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_PDAPIEVNT))
|
|
|
|
events->sctp_partial_delivery_event = 1;
|
|
|
|
|
|
|
|
if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_ADAPTATIONEVNT))
|
|
|
|
events->sctp_adaptation_layer_event = 1;
|
|
|
|
|
|
|
|
if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_AUTHEVNT))
|
|
|
|
events->sctp_authentication_event = 1;
|
|
|
|
|
2008-12-06 13:19:54 +00:00
|
|
|
if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_DRYEVNT))
|
|
|
|
events->sctp_sender_dry_event = 1;
|
|
|
|
|
2006-11-03 15:23:16 +00:00
|
|
|
if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_STREAM_RESETEVNT))
|
2010-01-17 19:35:38 +00:00
|
|
|
events->sctp_stream_reset_event = 1;
|
2006-11-03 15:23:16 +00:00
|
|
|
SCTP_INP_RUNLOCK(inp);
|
2007-02-12 23:24:31 +00:00
|
|
|
*optsize = sizeof(struct sctp_event_subscribe);
|
2006-11-03 15:23:16 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case SCTP_ADAPTATION_LAYER:
|
2007-02-12 23:24:31 +00:00
|
|
|
{
|
|
|
|
uint32_t *value;
|
|
|
|
|
|
|
|
SCTP_CHECK_AND_CAST(value, optval, uint32_t, *optsize);
|
|
|
|
|
|
|
|
SCTP_INP_RLOCK(inp);
|
|
|
|
*value = inp->sctp_ep.adaptation_layer_indicator;
|
|
|
|
SCTP_INP_RUNLOCK(inp);
|
|
|
|
*optsize = sizeof(uint32_t);
|
2006-11-03 15:23:16 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case SCTP_SET_INITIAL_DBG_SEQ:
|
2007-02-12 23:24:31 +00:00
|
|
|
{
|
|
|
|
uint32_t *value;
|
|
|
|
|
|
|
|
SCTP_CHECK_AND_CAST(value, optval, uint32_t, *optsize);
|
|
|
|
SCTP_INP_RLOCK(inp);
|
|
|
|
*value = inp->sctp_ep.initial_sequence_debug;
|
|
|
|
SCTP_INP_RUNLOCK(inp);
|
|
|
|
*optsize = sizeof(uint32_t);
|
2006-11-03 15:23:16 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case SCTP_GET_LOCAL_ADDR_SIZE:
|
2007-02-12 23:24:31 +00:00
|
|
|
{
|
|
|
|
uint32_t *value;
|
|
|
|
|
|
|
|
SCTP_CHECK_AND_CAST(value, optval, uint32_t, *optsize);
|
|
|
|
SCTP_INP_RLOCK(inp);
|
2007-03-31 11:47:30 +00:00
|
|
|
*value = sctp_count_max_addresses(inp);
|
2007-02-12 23:24:31 +00:00
|
|
|
SCTP_INP_RUNLOCK(inp);
|
|
|
|
*optsize = sizeof(uint32_t);
|
2006-11-03 15:23:16 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case SCTP_GET_REMOTE_ADDR_SIZE:
|
|
|
|
{
|
2007-02-12 23:24:31 +00:00
|
|
|
uint32_t *value;
|
|
|
|
size_t size;
|
2006-11-03 15:23:16 +00:00
|
|
|
struct sctp_nets *net;
|
|
|
|
|
2007-02-12 23:24:31 +00:00
|
|
|
SCTP_CHECK_AND_CAST(value, optval, uint32_t, *optsize);
|
|
|
|
/* FIXME MT: change to sctp_assoc_value? */
|
|
|
|
SCTP_FIND_STCB(inp, stcb, (sctp_assoc_t) * value);
|
|
|
|
|
|
|
|
if (stcb) {
|
|
|
|
size = 0;
|
|
|
|
/* Count the sizes */
|
|
|
|
TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
|
2008-04-16 17:24:18 +00:00
|
|
|
if ((sctp_is_feature_on(inp, SCTP_PCB_FLAGS_NEEDS_MAPPED_V4)) ||
|
2007-02-12 23:24:31 +00:00
|
|
|
(((struct sockaddr *)&net->ro._l_addr)->sa_family == AF_INET6)) {
|
|
|
|
size += sizeof(struct sockaddr_in6);
|
|
|
|
} else if (((struct sockaddr *)&net->ro._l_addr)->sa_family == AF_INET) {
|
|
|
|
size += sizeof(struct sockaddr_in);
|
|
|
|
} else {
|
|
|
|
/* huh */
|
|
|
|
break;
|
|
|
|
}
|
2006-11-03 15:23:16 +00:00
|
|
|
}
|
2007-02-12 23:24:31 +00:00
|
|
|
SCTP_TCB_UNLOCK(stcb);
|
|
|
|
*value = (uint32_t) size;
|
|
|
|
} else {
|
2007-08-24 00:53:53 +00:00
|
|
|
SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOTCONN);
|
2007-02-12 23:24:31 +00:00
|
|
|
error = ENOTCONN;
|
2006-11-03 15:23:16 +00:00
|
|
|
}
|
2007-02-12 23:24:31 +00:00
|
|
|
*optsize = sizeof(uint32_t);
|
2006-11-03 15:23:16 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case SCTP_GET_PEER_ADDRESSES:
|
|
|
|
/*
|
|
|
|
* Get the address information, an array is passed in to
|
|
|
|
* fill up we pack it.
|
|
|
|
*/
|
|
|
|
{
|
2007-02-12 23:24:31 +00:00
|
|
|
size_t cpsz, left;
|
2006-11-03 15:23:16 +00:00
|
|
|
struct sockaddr_storage *sas;
|
|
|
|
struct sctp_nets *net;
|
|
|
|
struct sctp_getaddresses *saddr;
|
|
|
|
|
2007-02-12 23:24:31 +00:00
|
|
|
SCTP_CHECK_AND_CAST(saddr, optval, struct sctp_getaddresses, *optsize);
|
|
|
|
SCTP_FIND_STCB(inp, stcb, saddr->sget_assoc_id);
|
2006-11-03 15:23:16 +00:00
|
|
|
|
2007-02-12 23:24:31 +00:00
|
|
|
if (stcb) {
|
|
|
|
left = (*optsize) - sizeof(struct sctp_getaddresses);
|
|
|
|
*optsize = sizeof(struct sctp_getaddresses);
|
|
|
|
sas = (struct sockaddr_storage *)&saddr->addr[0];
|
|
|
|
|
|
|
|
TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
|
2008-04-16 17:24:18 +00:00
|
|
|
if ((sctp_is_feature_on(inp, SCTP_PCB_FLAGS_NEEDS_MAPPED_V4)) ||
|
2007-02-12 23:24:31 +00:00
|
|
|
(((struct sockaddr *)&net->ro._l_addr)->sa_family == AF_INET6)) {
|
|
|
|
cpsz = sizeof(struct sockaddr_in6);
|
|
|
|
} else if (((struct sockaddr *)&net->ro._l_addr)->sa_family == AF_INET) {
|
|
|
|
cpsz = sizeof(struct sockaddr_in);
|
|
|
|
} else {
|
|
|
|
/* huh */
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (left < cpsz) {
|
|
|
|
/* not enough room. */
|
|
|
|
break;
|
|
|
|
}
|
2008-04-16 17:24:18 +00:00
|
|
|
#ifdef INET6
|
|
|
|
if ((sctp_is_feature_on(inp, SCTP_PCB_FLAGS_NEEDS_MAPPED_V4)) &&
|
2007-02-12 23:24:31 +00:00
|
|
|
(((struct sockaddr *)&net->ro._l_addr)->sa_family == AF_INET)) {
|
|
|
|
/* Must map the address */
|
|
|
|
in6_sin_2_v4mapsin6((struct sockaddr_in *)&net->ro._l_addr,
|
|
|
|
(struct sockaddr_in6 *)sas);
|
|
|
|
} else {
|
2008-04-16 17:24:18 +00:00
|
|
|
#endif
|
2007-02-12 23:24:31 +00:00
|
|
|
memcpy(sas, &net->ro._l_addr, cpsz);
|
2008-04-16 17:24:18 +00:00
|
|
|
#ifdef INET6
|
2007-02-12 23:24:31 +00:00
|
|
|
}
|
2008-04-16 17:24:18 +00:00
|
|
|
#endif
|
2007-02-12 23:24:31 +00:00
|
|
|
((struct sockaddr_in *)sas)->sin_port = stcb->rport;
|
2006-11-03 15:23:16 +00:00
|
|
|
|
2007-02-12 23:24:31 +00:00
|
|
|
sas = (struct sockaddr_storage *)((caddr_t)sas + cpsz);
|
|
|
|
left -= cpsz;
|
|
|
|
*optsize += cpsz;
|
|
|
|
}
|
|
|
|
SCTP_TCB_UNLOCK(stcb);
|
|
|
|
} else {
|
2007-08-24 00:53:53 +00:00
|
|
|
SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOENT);
|
2007-02-12 23:24:31 +00:00
|
|
|
error = ENOENT;
|
2006-11-03 15:23:16 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case SCTP_GET_LOCAL_ADDRESSES:
|
|
|
|
{
|
2007-02-12 23:24:31 +00:00
|
|
|
size_t limit, actual;
|
2006-11-03 15:23:16 +00:00
|
|
|
struct sockaddr_storage *sas;
|
|
|
|
struct sctp_getaddresses *saddr;
|
|
|
|
|
2007-02-12 23:24:31 +00:00
|
|
|
SCTP_CHECK_AND_CAST(saddr, optval, struct sctp_getaddresses, *optsize);
|
|
|
|
SCTP_FIND_STCB(inp, stcb, saddr->sget_assoc_id);
|
2006-11-03 15:23:16 +00:00
|
|
|
|
|
|
|
sas = (struct sockaddr_storage *)&saddr->addr[0];
|
2007-02-12 23:24:31 +00:00
|
|
|
limit = *optsize - sizeof(sctp_assoc_t);
|
2007-03-31 11:47:30 +00:00
|
|
|
actual = sctp_fill_up_addresses(inp, stcb, limit, sas);
|
2007-05-17 12:16:24 +00:00
|
|
|
if (stcb) {
|
2006-11-03 15:23:16 +00:00
|
|
|
SCTP_TCB_UNLOCK(stcb);
|
2007-05-17 12:16:24 +00:00
|
|
|
}
|
2007-02-12 23:24:31 +00:00
|
|
|
*optsize = sizeof(struct sockaddr_storage) + actual;
|
2006-11-03 15:23:16 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case SCTP_PEER_ADDR_PARAMS:
|
|
|
|
{
|
|
|
|
struct sctp_paddrparams *paddrp;
|
|
|
|
struct sctp_nets *net;
|
|
|
|
|
2007-02-12 23:24:31 +00:00
|
|
|
SCTP_CHECK_AND_CAST(paddrp, optval, struct sctp_paddrparams, *optsize);
|
|
|
|
SCTP_FIND_STCB(inp, stcb, paddrp->spp_assoc_id);
|
2006-11-03 15:23:16 +00:00
|
|
|
|
|
|
|
net = NULL;
|
2007-02-12 23:24:31 +00:00
|
|
|
if (stcb) {
|
|
|
|
net = sctp_findnet(stcb, (struct sockaddr *)&paddrp->spp_address);
|
|
|
|
} else {
|
|
|
|
/*
|
|
|
|
* We increment here since
|
|
|
|
* sctp_findassociation_ep_addr() wil do a
|
|
|
|
* decrement if it finds the stcb as long as
|
|
|
|
* the locked tcb (last argument) is NOT a
|
|
|
|
* TCB.. aka NULL.
|
|
|
|
*/
|
|
|
|
SCTP_INP_INCR_REF(inp);
|
|
|
|
stcb = sctp_findassociation_ep_addr(&inp, (struct sockaddr *)&paddrp->spp_address, &net, NULL, NULL);
|
2006-11-03 15:23:16 +00:00
|
|
|
if (stcb == NULL) {
|
2007-02-12 23:24:31 +00:00
|
|
|
SCTP_INP_DECR_REF(inp);
|
2006-11-03 15:23:16 +00:00
|
|
|
}
|
|
|
|
}
|
2007-08-24 00:53:53 +00:00
|
|
|
if (stcb && (net == NULL)) {
|
|
|
|
struct sockaddr *sa;
|
|
|
|
|
|
|
|
sa = (struct sockaddr *)&paddrp->spp_address;
|
|
|
|
if (sa->sa_family == AF_INET) {
|
|
|
|
struct sockaddr_in *sin;
|
2006-11-03 15:23:16 +00:00
|
|
|
|
2007-08-24 00:53:53 +00:00
|
|
|
sin = (struct sockaddr_in *)sa;
|
|
|
|
if (sin->sin_addr.s_addr) {
|
|
|
|
error = EINVAL;
|
|
|
|
SCTP_TCB_UNLOCK(stcb);
|
|
|
|
SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
} else if (sa->sa_family == AF_INET6) {
|
|
|
|
struct sockaddr_in6 *sin6;
|
|
|
|
|
|
|
|
sin6 = (struct sockaddr_in6 *)sa;
|
|
|
|
if (!IN6_IS_ADDR_UNSPECIFIED(&sin6->sin6_addr)) {
|
|
|
|
error = EINVAL;
|
|
|
|
SCTP_TCB_UNLOCK(stcb);
|
|
|
|
SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
error = EAFNOSUPPORT;
|
|
|
|
SCTP_TCB_UNLOCK(stcb);
|
|
|
|
SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2006-11-03 15:23:16 +00:00
|
|
|
if (stcb) {
|
|
|
|
/* Applys to the specific association */
|
|
|
|
paddrp->spp_flags = 0;
|
|
|
|
if (net) {
|
2007-05-28 11:17:24 +00:00
|
|
|
int ovh;
|
|
|
|
|
|
|
|
if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) {
|
|
|
|
ovh = SCTP_MED_OVERHEAD;
|
|
|
|
} else {
|
|
|
|
ovh = SCTP_MED_V4_OVERHEAD;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-11-03 15:23:16 +00:00
|
|
|
paddrp->spp_pathmaxrxt = net->failure_threshold;
|
2007-05-28 11:17:24 +00:00
|
|
|
paddrp->spp_pathmtu = net->mtu - ovh;
|
2006-11-03 15:23:16 +00:00
|
|
|
/* get flags for HB */
|
|
|
|
if (net->dest_state & SCTP_ADDR_NOHB)
|
|
|
|
paddrp->spp_flags |= SPP_HB_DISABLE;
|
|
|
|
else
|
|
|
|
paddrp->spp_flags |= SPP_HB_ENABLE;
|
|
|
|
/* get flags for PMTU */
|
2006-12-29 20:21:42 +00:00
|
|
|
if (SCTP_OS_TIMER_PENDING(&net->pmtu_timer.timer)) {
|
2006-11-03 15:23:16 +00:00
|
|
|
paddrp->spp_flags |= SPP_PMTUD_ENABLE;
|
|
|
|
} else {
|
|
|
|
paddrp->spp_flags |= SPP_PMTUD_DISABLE;
|
|
|
|
}
|
2007-03-15 11:27:14 +00:00
|
|
|
#ifdef INET
|
2006-11-03 15:23:16 +00:00
|
|
|
if (net->ro._l_addr.sin.sin_family == AF_INET) {
|
|
|
|
paddrp->spp_ipv4_tos = net->tos_flowlabel & 0x000000fc;
|
|
|
|
paddrp->spp_flags |= SPP_IPV4_TOS;
|
|
|
|
}
|
|
|
|
#endif
|
2007-03-15 11:27:14 +00:00
|
|
|
#ifdef INET6
|
2006-11-03 15:23:16 +00:00
|
|
|
if (net->ro._l_addr.sin6.sin6_family == AF_INET6) {
|
|
|
|
paddrp->spp_ipv6_flowlabel = net->tos_flowlabel;
|
|
|
|
paddrp->spp_flags |= SPP_IPV6_FLOWLABEL;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
} else {
|
|
|
|
/*
|
|
|
|
* No destination so return default
|
|
|
|
* value
|
|
|
|
*/
|
2007-05-28 11:17:24 +00:00
|
|
|
int cnt = 0;
|
|
|
|
|
2006-11-03 15:23:16 +00:00
|
|
|
paddrp->spp_pathmaxrxt = stcb->asoc.def_net_failure;
|
|
|
|
paddrp->spp_pathmtu = sctp_get_frag_point(stcb, &stcb->asoc);
|
2007-03-15 11:27:14 +00:00
|
|
|
#ifdef INET
|
2006-11-03 15:23:16 +00:00
|
|
|
paddrp->spp_ipv4_tos = stcb->asoc.default_tos & 0x000000fc;
|
|
|
|
paddrp->spp_flags |= SPP_IPV4_TOS;
|
|
|
|
#endif
|
2007-03-15 11:27:14 +00:00
|
|
|
#ifdef INET6
|
2006-11-03 15:23:16 +00:00
|
|
|
paddrp->spp_ipv6_flowlabel = stcb->asoc.default_flowlabel;
|
|
|
|
paddrp->spp_flags |= SPP_IPV6_FLOWLABEL;
|
|
|
|
#endif
|
|
|
|
/* default settings should be these */
|
2007-05-28 11:17:24 +00:00
|
|
|
if (stcb->asoc.hb_is_disabled == 0) {
|
2006-11-03 15:23:16 +00:00
|
|
|
paddrp->spp_flags |= SPP_HB_ENABLE;
|
2007-05-28 11:17:24 +00:00
|
|
|
} else {
|
|
|
|
paddrp->spp_flags |= SPP_HB_DISABLE;
|
|
|
|
}
|
|
|
|
TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
|
|
|
|
if (SCTP_OS_TIMER_PENDING(&net->pmtu_timer.timer)) {
|
|
|
|
cnt++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (cnt) {
|
|
|
|
paddrp->spp_flags |= SPP_PMTUD_ENABLE;
|
2006-11-03 15:23:16 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
paddrp->spp_hbinterval = stcb->asoc.heart_beat_delay;
|
|
|
|
paddrp->spp_assoc_id = sctp_get_associd(stcb);
|
|
|
|
SCTP_TCB_UNLOCK(stcb);
|
|
|
|
} else {
|
|
|
|
/* Use endpoint defaults */
|
|
|
|
SCTP_INP_RLOCK(inp);
|
|
|
|
paddrp->spp_pathmaxrxt = inp->sctp_ep.def_net_failure;
|
|
|
|
paddrp->spp_hbinterval = TICKS_TO_MSEC(inp->sctp_ep.sctp_timeoutticks[SCTP_TIMER_HEARTBEAT]);
|
|
|
|
paddrp->spp_assoc_id = (sctp_assoc_t) 0;
|
|
|
|
/* get inp's default */
|
2007-03-15 11:27:14 +00:00
|
|
|
#ifdef INET
|
2006-11-03 15:23:16 +00:00
|
|
|
paddrp->spp_ipv4_tos = inp->ip_inp.inp.inp_ip_tos;
|
|
|
|
paddrp->spp_flags |= SPP_IPV4_TOS;
|
|
|
|
#endif
|
2007-03-15 11:27:14 +00:00
|
|
|
#ifdef INET6
|
2006-11-03 15:23:16 +00:00
|
|
|
if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) {
|
|
|
|
paddrp->spp_ipv6_flowlabel = ((struct in6pcb *)inp)->in6p_flowinfo;
|
|
|
|
paddrp->spp_flags |= SPP_IPV6_FLOWLABEL;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
/* can't return this */
|
|
|
|
paddrp->spp_pathmtu = 0;
|
2007-05-28 11:17:24 +00:00
|
|
|
|
2006-11-03 15:23:16 +00:00
|
|
|
/* default behavior, no stcb */
|
2007-05-28 11:17:24 +00:00
|
|
|
paddrp->spp_flags = SPP_PMTUD_ENABLE;
|
2006-11-03 15:23:16 +00:00
|
|
|
|
2007-05-28 11:17:24 +00:00
|
|
|
if (sctp_is_feature_off(inp, SCTP_PCB_FLAGS_DONOT_HEARTBEAT)) {
|
|
|
|
paddrp->spp_flags |= SPP_HB_ENABLE;
|
|
|
|
} else {
|
|
|
|
paddrp->spp_flags |= SPP_HB_DISABLE;
|
|
|
|
}
|
2006-11-03 15:23:16 +00:00
|
|
|
SCTP_INP_RUNLOCK(inp);
|
|
|
|
}
|
2007-02-12 23:24:31 +00:00
|
|
|
*optsize = sizeof(struct sctp_paddrparams);
|
2006-11-03 15:23:16 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case SCTP_GET_PEER_ADDR_INFO:
|
|
|
|
{
|
|
|
|
struct sctp_paddrinfo *paddri;
|
|
|
|
struct sctp_nets *net;
|
|
|
|
|
2007-02-12 23:24:31 +00:00
|
|
|
SCTP_CHECK_AND_CAST(paddri, optval, struct sctp_paddrinfo, *optsize);
|
|
|
|
SCTP_FIND_STCB(inp, stcb, paddri->spinfo_assoc_id);
|
|
|
|
|
2006-11-03 15:23:16 +00:00
|
|
|
net = NULL;
|
2007-02-12 23:24:31 +00:00
|
|
|
if (stcb) {
|
|
|
|
net = sctp_findnet(stcb, (struct sockaddr *)&paddri->spinfo_address);
|
|
|
|
} else {
|
|
|
|
/*
|
|
|
|
* We increment here since
|
|
|
|
* sctp_findassociation_ep_addr() wil do a
|
|
|
|
* decrement if it finds the stcb as long as
|
|
|
|
* the locked tcb (last argument) is NOT a
|
|
|
|
* TCB.. aka NULL.
|
|
|
|
*/
|
|
|
|
SCTP_INP_INCR_REF(inp);
|
|
|
|
stcb = sctp_findassociation_ep_addr(&inp, (struct sockaddr *)&paddri->spinfo_address, &net, NULL, NULL);
|
|
|
|
if (stcb == NULL) {
|
|
|
|
SCTP_INP_DECR_REF(inp);
|
2006-11-03 15:23:16 +00:00
|
|
|
}
|
2007-02-12 23:24:31 +00:00
|
|
|
}
|
2006-11-03 15:23:16 +00:00
|
|
|
|
2007-02-12 23:24:31 +00:00
|
|
|
if ((stcb) && (net)) {
|
2011-01-20 12:40:09 +00:00
|
|
|
if (net->dest_state & SCTP_ADDR_UNCONFIRMED) {
|
2011-01-20 13:53:34 +00:00
|
|
|
/* It's unconfirmed */
|
2011-01-20 12:40:09 +00:00
|
|
|
paddri->spinfo_state = SCTP_UNCONFIRMED;
|
|
|
|
} else if (net->dest_state & SCTP_ADDR_REACHABLE) {
|
2011-01-20 13:53:34 +00:00
|
|
|
/* It's active */
|
2011-01-20 12:40:09 +00:00
|
|
|
paddri->spinfo_state = SCTP_ACTIVE;
|
|
|
|
} else {
|
2011-01-20 13:53:34 +00:00
|
|
|
/* It's inactive */
|
2011-01-20 12:40:09 +00:00
|
|
|
paddri->spinfo_state = SCTP_INACTIVE;
|
|
|
|
}
|
2007-02-12 23:24:31 +00:00
|
|
|
paddri->spinfo_cwnd = net->cwnd;
|
2011-02-24 22:58:15 +00:00
|
|
|
paddri->spinfo_srtt = net->lastsa >> SCTP_RTT_SHIFT;
|
2007-02-12 23:24:31 +00:00
|
|
|
paddri->spinfo_rto = net->RTO;
|
|
|
|
paddri->spinfo_assoc_id = sctp_get_associd(stcb);
|
|
|
|
SCTP_TCB_UNLOCK(stcb);
|
2006-11-03 15:23:16 +00:00
|
|
|
} else {
|
|
|
|
if (stcb) {
|
|
|
|
SCTP_TCB_UNLOCK(stcb);
|
|
|
|
}
|
2007-08-24 00:53:53 +00:00
|
|
|
SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOENT);
|
2006-11-03 15:23:16 +00:00
|
|
|
error = ENOENT;
|
|
|
|
}
|
2007-02-12 23:24:31 +00:00
|
|
|
*optsize = sizeof(struct sctp_paddrinfo);
|
2006-11-03 15:23:16 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case SCTP_PCB_STATUS:
|
|
|
|
{
|
|
|
|
struct sctp_pcbinfo *spcb;
|
|
|
|
|
2007-02-12 23:24:31 +00:00
|
|
|
SCTP_CHECK_AND_CAST(spcb, optval, struct sctp_pcbinfo, *optsize);
|
2006-11-03 15:23:16 +00:00
|
|
|
sctp_fill_pcbinfo(spcb);
|
2007-02-12 23:24:31 +00:00
|
|
|
*optsize = sizeof(struct sctp_pcbinfo);
|
2006-11-03 15:23:16 +00:00
|
|
|
}
|
|
|
|
break;
|
2007-03-15 11:27:14 +00:00
|
|
|
|
2006-11-03 15:23:16 +00:00
|
|
|
case SCTP_STATUS:
|
|
|
|
{
|
|
|
|
struct sctp_nets *net;
|
|
|
|
struct sctp_status *sstat;
|
|
|
|
|
2007-02-12 23:24:31 +00:00
|
|
|
SCTP_CHECK_AND_CAST(sstat, optval, struct sctp_status, *optsize);
|
|
|
|
SCTP_FIND_STCB(inp, stcb, sstat->sstat_assoc_id);
|
2006-11-03 15:23:16 +00:00
|
|
|
|
|
|
|
if (stcb == NULL) {
|
2007-08-24 00:53:53 +00:00
|
|
|
SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
|
2006-11-03 15:23:16 +00:00
|
|
|
error = EINVAL;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
/*
|
|
|
|
* I think passing the state is fine since
|
|
|
|
* sctp_constants.h will be available to the user
|
|
|
|
* land.
|
|
|
|
*/
|
|
|
|
sstat->sstat_state = stcb->asoc.state;
|
2007-10-30 14:09:24 +00:00
|
|
|
sstat->sstat_assoc_id = sctp_get_associd(stcb);
|
2006-11-03 15:23:16 +00:00
|
|
|
sstat->sstat_rwnd = stcb->asoc.peers_rwnd;
|
|
|
|
sstat->sstat_unackdata = stcb->asoc.sent_queue_cnt;
|
|
|
|
/*
|
|
|
|
* We can't include chunks that have been passed to
|
|
|
|
* the socket layer. Only things in queue.
|
|
|
|
*/
|
|
|
|
sstat->sstat_penddata = (stcb->asoc.cnt_on_reasm_queue +
|
|
|
|
stcb->asoc.cnt_on_all_streams);
|
|
|
|
|
|
|
|
|
|
|
|
sstat->sstat_instrms = stcb->asoc.streamincnt;
|
|
|
|
sstat->sstat_outstrms = stcb->asoc.streamoutcnt;
|
|
|
|
sstat->sstat_fragmentation_point = sctp_get_frag_point(stcb, &stcb->asoc);
|
|
|
|
memcpy(&sstat->sstat_primary.spinfo_address,
|
|
|
|
&stcb->asoc.primary_destination->ro._l_addr,
|
|
|
|
((struct sockaddr *)(&stcb->asoc.primary_destination->ro._l_addr))->sa_len);
|
|
|
|
net = stcb->asoc.primary_destination;
|
|
|
|
((struct sockaddr_in *)&sstat->sstat_primary.spinfo_address)->sin_port = stcb->rport;
|
|
|
|
/*
|
|
|
|
* Again the user can get info from sctp_constants.h
|
|
|
|
* for what the state of the network is.
|
|
|
|
*/
|
2011-01-20 12:40:09 +00:00
|
|
|
if (net->dest_state & SCTP_ADDR_UNCONFIRMED) {
|
|
|
|
/* It's unconfirmed */
|
|
|
|
sstat->sstat_primary.spinfo_state = SCTP_UNCONFIRMED;
|
|
|
|
} else if (net->dest_state & SCTP_ADDR_REACHABLE) {
|
2011-01-20 13:53:34 +00:00
|
|
|
/* It's active */
|
2011-01-20 12:40:09 +00:00
|
|
|
sstat->sstat_primary.spinfo_state = SCTP_ACTIVE;
|
|
|
|
} else {
|
2011-01-20 13:53:34 +00:00
|
|
|
/* It's inactive */
|
2011-01-20 12:40:09 +00:00
|
|
|
sstat->sstat_primary.spinfo_state = SCTP_INACTIVE;
|
|
|
|
}
|
2006-11-03 15:23:16 +00:00
|
|
|
sstat->sstat_primary.spinfo_cwnd = net->cwnd;
|
2011-02-24 22:58:15 +00:00
|
|
|
sstat->sstat_primary.spinfo_srtt = net->lastsa >> SCTP_RTT_SHIFT;
|
2006-11-03 15:23:16 +00:00
|
|
|
sstat->sstat_primary.spinfo_rto = net->RTO;
|
|
|
|
sstat->sstat_primary.spinfo_mtu = net->mtu;
|
|
|
|
sstat->sstat_primary.spinfo_assoc_id = sctp_get_associd(stcb);
|
|
|
|
SCTP_TCB_UNLOCK(stcb);
|
2007-02-12 23:24:31 +00:00
|
|
|
*optsize = sizeof(*sstat);
|
2006-11-03 15:23:16 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case SCTP_RTOINFO:
|
|
|
|
{
|
|
|
|
struct sctp_rtoinfo *srto;
|
|
|
|
|
2007-02-12 23:24:31 +00:00
|
|
|
SCTP_CHECK_AND_CAST(srto, optval, struct sctp_rtoinfo, *optsize);
|
|
|
|
SCTP_FIND_STCB(inp, stcb, srto->srto_assoc_id);
|
|
|
|
|
|
|
|
if (stcb) {
|
|
|
|
srto->srto_initial = stcb->asoc.initial_rto;
|
|
|
|
srto->srto_max = stcb->asoc.maxrto;
|
|
|
|
srto->srto_min = stcb->asoc.minrto;
|
|
|
|
SCTP_TCB_UNLOCK(stcb);
|
|
|
|
} else {
|
2006-11-03 15:23:16 +00:00
|
|
|
SCTP_INP_RLOCK(inp);
|
|
|
|
srto->srto_initial = inp->sctp_ep.initial_rto;
|
|
|
|
srto->srto_max = inp->sctp_ep.sctp_maxrto;
|
|
|
|
srto->srto_min = inp->sctp_ep.sctp_minrto;
|
|
|
|
SCTP_INP_RUNLOCK(inp);
|
|
|
|
}
|
2007-02-12 23:24:31 +00:00
|
|
|
*optsize = sizeof(*srto);
|
2006-11-03 15:23:16 +00:00
|
|
|
}
|
|
|
|
break;
|
2010-11-16 22:16:38 +00:00
|
|
|
case SCTP_TIMEOUTS:
|
|
|
|
{
|
|
|
|
struct sctp_timeouts *stimo;
|
|
|
|
|
|
|
|
SCTP_CHECK_AND_CAST(stimo, optval, struct sctp_timeouts, *optsize);
|
|
|
|
SCTP_FIND_STCB(inp, stcb, stimo->stimo_assoc_id);
|
|
|
|
|
|
|
|
if (stcb) {
|
|
|
|
stimo->stimo_init = stcb->asoc.timoinit;
|
|
|
|
stimo->stimo_data = stcb->asoc.timodata;
|
|
|
|
stimo->stimo_sack = stcb->asoc.timosack;
|
|
|
|
stimo->stimo_shutdown = stcb->asoc.timoshutdown;
|
|
|
|
stimo->stimo_heartbeat = stcb->asoc.timoheartbeat;
|
|
|
|
stimo->stimo_cookie = stcb->asoc.timocookie;
|
|
|
|
stimo->stimo_shutdownack = stcb->asoc.timoshutdownack;
|
|
|
|
SCTP_TCB_UNLOCK(stcb);
|
|
|
|
} else {
|
|
|
|
SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
|
|
|
|
error = EINVAL;
|
|
|
|
}
|
|
|
|
*optsize = sizeof(*stimo);
|
|
|
|
}
|
|
|
|
break;
|
2006-11-03 15:23:16 +00:00
|
|
|
case SCTP_ASSOCINFO:
|
|
|
|
{
|
|
|
|
struct sctp_assocparams *sasoc;
|
2007-07-17 20:58:26 +00:00
|
|
|
uint32_t oldval;
|
2006-11-03 15:23:16 +00:00
|
|
|
|
2007-02-12 23:24:31 +00:00
|
|
|
SCTP_CHECK_AND_CAST(sasoc, optval, struct sctp_assocparams, *optsize);
|
|
|
|
SCTP_FIND_STCB(inp, stcb, sasoc->sasoc_assoc_id);
|
2006-11-03 15:23:16 +00:00
|
|
|
|
|
|
|
if (stcb) {
|
2007-07-17 20:58:26 +00:00
|
|
|
oldval = sasoc->sasoc_cookie_life;
|
|
|
|
sasoc->sasoc_cookie_life = TICKS_TO_MSEC(stcb->asoc.cookie_life);
|
2006-11-03 15:23:16 +00:00
|
|
|
sasoc->sasoc_asocmaxrxt = stcb->asoc.max_send_times;
|
|
|
|
sasoc->sasoc_number_peer_destinations = stcb->asoc.numnets;
|
|
|
|
sasoc->sasoc_peer_rwnd = stcb->asoc.peers_rwnd;
|
|
|
|
sasoc->sasoc_local_rwnd = stcb->asoc.my_rwnd;
|
|
|
|
SCTP_TCB_UNLOCK(stcb);
|
|
|
|
} else {
|
|
|
|
SCTP_INP_RLOCK(inp);
|
2007-07-17 20:58:26 +00:00
|
|
|
sasoc->sasoc_cookie_life = TICKS_TO_MSEC(inp->sctp_ep.def_cookie_life);
|
2006-11-03 15:23:16 +00:00
|
|
|
sasoc->sasoc_asocmaxrxt = inp->sctp_ep.max_send_times;
|
|
|
|
sasoc->sasoc_number_peer_destinations = 0;
|
|
|
|
sasoc->sasoc_peer_rwnd = 0;
|
|
|
|
sasoc->sasoc_local_rwnd = sbspace(&inp->sctp_socket->so_rcv);
|
|
|
|
SCTP_INP_RUNLOCK(inp);
|
|
|
|
}
|
2007-02-12 23:24:31 +00:00
|
|
|
*optsize = sizeof(*sasoc);
|
2006-11-03 15:23:16 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case SCTP_DEFAULT_SEND_PARAM:
|
|
|
|
{
|
|
|
|
struct sctp_sndrcvinfo *s_info;
|
|
|
|
|
2007-02-12 23:24:31 +00:00
|
|
|
SCTP_CHECK_AND_CAST(s_info, optval, struct sctp_sndrcvinfo, *optsize);
|
|
|
|
SCTP_FIND_STCB(inp, stcb, s_info->sinfo_assoc_id);
|
|
|
|
|
|
|
|
if (stcb) {
|
2007-05-28 11:17:24 +00:00
|
|
|
memcpy(s_info, &stcb->asoc.def_send, sizeof(stcb->asoc.def_send));
|
2007-02-12 23:24:31 +00:00
|
|
|
SCTP_TCB_UNLOCK(stcb);
|
|
|
|
} else {
|
2006-11-03 15:23:16 +00:00
|
|
|
SCTP_INP_RLOCK(inp);
|
2007-05-28 11:17:24 +00:00
|
|
|
memcpy(s_info, &inp->def_send, sizeof(inp->def_send));
|
2006-11-03 15:23:16 +00:00
|
|
|
SCTP_INP_RUNLOCK(inp);
|
|
|
|
}
|
2007-02-12 23:24:31 +00:00
|
|
|
*optsize = sizeof(*s_info);
|
2006-11-03 15:23:16 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case SCTP_INITMSG:
|
|
|
|
{
|
|
|
|
struct sctp_initmsg *sinit;
|
|
|
|
|
2007-02-12 23:24:31 +00:00
|
|
|
SCTP_CHECK_AND_CAST(sinit, optval, struct sctp_initmsg, *optsize);
|
2006-11-03 15:23:16 +00:00
|
|
|
SCTP_INP_RLOCK(inp);
|
|
|
|
sinit->sinit_num_ostreams = inp->sctp_ep.pre_open_stream_count;
|
|
|
|
sinit->sinit_max_instreams = inp->sctp_ep.max_open_streams_intome;
|
|
|
|
sinit->sinit_max_attempts = inp->sctp_ep.max_init_times;
|
|
|
|
sinit->sinit_max_init_timeo = inp->sctp_ep.initial_init_rto_max;
|
|
|
|
SCTP_INP_RUNLOCK(inp);
|
2007-02-12 23:24:31 +00:00
|
|
|
*optsize = sizeof(*sinit);
|
2006-11-03 15:23:16 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case SCTP_PRIMARY_ADDR:
|
|
|
|
/* we allow a "get" operation on this */
|
|
|
|
{
|
|
|
|
struct sctp_setprim *ssp;
|
|
|
|
|
2007-02-12 23:24:31 +00:00
|
|
|
SCTP_CHECK_AND_CAST(ssp, optval, struct sctp_setprim, *optsize);
|
|
|
|
SCTP_FIND_STCB(inp, stcb, ssp->ssp_assoc_id);
|
|
|
|
|
|
|
|
if (stcb) {
|
|
|
|
/* simply copy out the sockaddr_storage... */
|
2007-05-28 11:17:24 +00:00
|
|
|
int len;
|
|
|
|
|
|
|
|
len = *optsize;
|
|
|
|
if (len > stcb->asoc.primary_destination->ro._l_addr.sa.sa_len)
|
|
|
|
len = stcb->asoc.primary_destination->ro._l_addr.sa.sa_len;
|
|
|
|
|
|
|
|
memcpy(&ssp->ssp_addr,
|
|
|
|
&stcb->asoc.primary_destination->ro._l_addr,
|
|
|
|
len);
|
2007-02-12 23:24:31 +00:00
|
|
|
SCTP_TCB_UNLOCK(stcb);
|
2006-11-03 15:23:16 +00:00
|
|
|
} else {
|
2007-08-24 00:53:53 +00:00
|
|
|
SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
|
2007-02-12 23:24:31 +00:00
|
|
|
error = EINVAL;
|
2006-11-03 15:23:16 +00:00
|
|
|
}
|
2007-02-12 23:24:31 +00:00
|
|
|
*optsize = sizeof(*ssp);
|
2006-11-03 15:23:16 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case SCTP_HMAC_IDENT:
|
|
|
|
{
|
|
|
|
struct sctp_hmacalgo *shmac;
|
|
|
|
sctp_hmaclist_t *hmaclist;
|
|
|
|
uint32_t size;
|
|
|
|
int i;
|
|
|
|
|
2007-02-12 23:24:31 +00:00
|
|
|
SCTP_CHECK_AND_CAST(shmac, optval, struct sctp_hmacalgo, *optsize);
|
|
|
|
|
2006-11-03 15:23:16 +00:00
|
|
|
SCTP_INP_RLOCK(inp);
|
|
|
|
hmaclist = inp->sctp_ep.local_hmacs;
|
|
|
|
if (hmaclist == NULL) {
|
|
|
|
/* no HMACs to return */
|
2007-02-12 23:24:31 +00:00
|
|
|
*optsize = sizeof(*shmac);
|
2007-04-03 11:15:32 +00:00
|
|
|
SCTP_INP_RUNLOCK(inp);
|
2006-11-03 15:23:16 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
/* is there room for all of the hmac ids? */
|
|
|
|
size = sizeof(*shmac) + (hmaclist->num_algo *
|
|
|
|
sizeof(shmac->shmac_idents[0]));
|
2007-02-12 23:24:31 +00:00
|
|
|
if ((size_t)(*optsize) < size) {
|
2007-08-24 00:53:53 +00:00
|
|
|
SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
|
2006-11-03 15:23:16 +00:00
|
|
|
error = EINVAL;
|
|
|
|
SCTP_INP_RUNLOCK(inp);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
/* copy in the list */
|
2008-07-31 11:08:30 +00:00
|
|
|
shmac->shmac_number_of_idents = hmaclist->num_algo;
|
|
|
|
for (i = 0; i < hmaclist->num_algo; i++) {
|
2006-11-03 15:23:16 +00:00
|
|
|
shmac->shmac_idents[i] = hmaclist->hmac[i];
|
2008-07-31 11:08:30 +00:00
|
|
|
}
|
2006-11-03 15:23:16 +00:00
|
|
|
SCTP_INP_RUNLOCK(inp);
|
2007-02-12 23:24:31 +00:00
|
|
|
*optsize = size;
|
2006-11-03 15:23:16 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case SCTP_AUTH_ACTIVE_KEY:
|
|
|
|
{
|
|
|
|
struct sctp_authkeyid *scact;
|
|
|
|
|
2007-02-12 23:24:31 +00:00
|
|
|
SCTP_CHECK_AND_CAST(scact, optval, struct sctp_authkeyid, *optsize);
|
|
|
|
SCTP_FIND_STCB(inp, stcb, scact->scact_assoc_id);
|
|
|
|
|
|
|
|
if (stcb) {
|
2006-11-03 15:23:16 +00:00
|
|
|
/* get the active key on the assoc */
|
2008-12-06 13:19:54 +00:00
|
|
|
scact->scact_keynumber = stcb->asoc.authinfo.active_keyid;
|
2006-11-03 15:23:16 +00:00
|
|
|
SCTP_TCB_UNLOCK(stcb);
|
|
|
|
} else {
|
|
|
|
/* get the endpoint active key */
|
|
|
|
SCTP_INP_RLOCK(inp);
|
|
|
|
scact->scact_keynumber = inp->sctp_ep.default_keyid;
|
|
|
|
SCTP_INP_RUNLOCK(inp);
|
|
|
|
}
|
2007-02-12 23:24:31 +00:00
|
|
|
*optsize = sizeof(*scact);
|
2006-11-03 15:23:16 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case SCTP_LOCAL_AUTH_CHUNKS:
|
|
|
|
{
|
|
|
|
struct sctp_authchunks *sac;
|
|
|
|
sctp_auth_chklist_t *chklist = NULL;
|
2007-02-12 23:24:31 +00:00
|
|
|
size_t size = 0;
|
2006-11-03 15:23:16 +00:00
|
|
|
|
2007-02-12 23:24:31 +00:00
|
|
|
SCTP_CHECK_AND_CAST(sac, optval, struct sctp_authchunks, *optsize);
|
|
|
|
SCTP_FIND_STCB(inp, stcb, sac->gauth_assoc_id);
|
|
|
|
|
|
|
|
if (stcb) {
|
2006-11-03 15:23:16 +00:00
|
|
|
/* get off the assoc */
|
|
|
|
chklist = stcb->asoc.local_auth_chunks;
|
|
|
|
/* is there enough space? */
|
|
|
|
size = sctp_auth_get_chklist_size(chklist);
|
2007-02-12 23:24:31 +00:00
|
|
|
if (*optsize < (sizeof(struct sctp_authchunks) + size)) {
|
2006-11-03 15:23:16 +00:00
|
|
|
error = EINVAL;
|
2007-08-24 00:53:53 +00:00
|
|
|
SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
|
2007-02-12 23:24:31 +00:00
|
|
|
} else {
|
|
|
|
/* copy in the chunks */
|
2007-05-09 13:30:06 +00:00
|
|
|
(void)sctp_serialize_auth_chunks(chklist, sac->gauth_chunks);
|
2006-11-03 15:23:16 +00:00
|
|
|
}
|
|
|
|
SCTP_TCB_UNLOCK(stcb);
|
|
|
|
} else {
|
|
|
|
/* get off the endpoint */
|
|
|
|
SCTP_INP_RLOCK(inp);
|
|
|
|
chklist = inp->sctp_ep.local_auth_chunks;
|
|
|
|
/* is there enough space? */
|
|
|
|
size = sctp_auth_get_chklist_size(chklist);
|
2007-02-12 23:24:31 +00:00
|
|
|
if (*optsize < (sizeof(struct sctp_authchunks) + size)) {
|
2006-11-03 15:23:16 +00:00
|
|
|
error = EINVAL;
|
2007-08-24 00:53:53 +00:00
|
|
|
SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
|
2007-02-12 23:24:31 +00:00
|
|
|
} else {
|
|
|
|
/* copy in the chunks */
|
2007-05-09 13:30:06 +00:00
|
|
|
(void)sctp_serialize_auth_chunks(chklist, sac->gauth_chunks);
|
2006-11-03 15:23:16 +00:00
|
|
|
}
|
|
|
|
SCTP_INP_RUNLOCK(inp);
|
|
|
|
}
|
2007-02-12 23:24:31 +00:00
|
|
|
*optsize = sizeof(struct sctp_authchunks) + size;
|
2006-11-03 15:23:16 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case SCTP_PEER_AUTH_CHUNKS:
|
|
|
|
{
|
|
|
|
struct sctp_authchunks *sac;
|
|
|
|
sctp_auth_chklist_t *chklist = NULL;
|
2007-02-12 23:24:31 +00:00
|
|
|
size_t size = 0;
|
2006-11-03 15:23:16 +00:00
|
|
|
|
2007-02-12 23:24:31 +00:00
|
|
|
SCTP_CHECK_AND_CAST(sac, optval, struct sctp_authchunks, *optsize);
|
|
|
|
SCTP_FIND_STCB(inp, stcb, sac->gauth_assoc_id);
|
|
|
|
|
|
|
|
if (stcb) {
|
|
|
|
/* get off the assoc */
|
|
|
|
chklist = stcb->asoc.peer_auth_chunks;
|
|
|
|
/* is there enough space? */
|
|
|
|
size = sctp_auth_get_chklist_size(chklist);
|
|
|
|
if (*optsize < (sizeof(struct sctp_authchunks) + size)) {
|
|
|
|
error = EINVAL;
|
2007-08-24 00:53:53 +00:00
|
|
|
SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
|
2007-02-12 23:24:31 +00:00
|
|
|
} else {
|
|
|
|
/* copy in the chunks */
|
2007-05-09 13:30:06 +00:00
|
|
|
(void)sctp_serialize_auth_chunks(chklist, sac->gauth_chunks);
|
2007-02-12 23:24:31 +00:00
|
|
|
}
|
2006-11-03 15:23:16 +00:00
|
|
|
SCTP_TCB_UNLOCK(stcb);
|
2007-02-12 23:24:31 +00:00
|
|
|
} else {
|
2007-08-24 00:53:53 +00:00
|
|
|
SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOENT);
|
2007-02-12 23:24:31 +00:00
|
|
|
error = ENOENT;
|
2006-11-03 15:23:16 +00:00
|
|
|
}
|
2007-02-12 23:24:31 +00:00
|
|
|
*optsize = sizeof(struct sctp_authchunks) + size;
|
2006-11-03 15:23:16 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
default:
|
2007-08-24 00:53:53 +00:00
|
|
|
SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOPROTOOPT);
|
2006-11-03 15:23:16 +00:00
|
|
|
error = ENOPROTOOPT;
|
2007-02-12 23:24:31 +00:00
|
|
|
*optsize = 0;
|
2006-11-03 15:23:16 +00:00
|
|
|
break;
|
|
|
|
} /* end switch (sopt->sopt_name) */
|
|
|
|
return (error);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2007-02-12 23:24:31 +00:00
|
|
|
sctp_setopt(struct socket *so, int optname, void *optval, size_t optsize,
|
|
|
|
void *p)
|
2006-11-03 15:23:16 +00:00
|
|
|
{
|
2007-02-12 23:24:31 +00:00
|
|
|
int error, set_opt;
|
|
|
|
uint32_t *mopt;
|
2006-11-03 15:23:16 +00:00
|
|
|
struct sctp_tcb *stcb = NULL;
|
2007-08-24 00:53:53 +00:00
|
|
|
struct sctp_inpcb *inp = NULL;
|
2007-03-15 11:27:14 +00:00
|
|
|
uint32_t vrf_id;
|
2006-11-03 15:23:16 +00:00
|
|
|
|
2007-02-12 23:24:31 +00:00
|
|
|
if (optval == NULL) {
|
2007-05-09 13:30:06 +00:00
|
|
|
SCTP_PRINTF("optval is NULL\n");
|
2007-08-24 00:53:53 +00:00
|
|
|
SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
|
2006-11-03 15:23:16 +00:00
|
|
|
return (EINVAL);
|
|
|
|
}
|
|
|
|
inp = (struct sctp_inpcb *)so->so_pcb;
|
2007-03-15 11:27:14 +00:00
|
|
|
if (inp == 0) {
|
2007-05-09 13:30:06 +00:00
|
|
|
SCTP_PRINTF("inp is NULL?\n");
|
2007-08-24 00:53:53 +00:00
|
|
|
SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
|
2006-11-03 15:23:16 +00:00
|
|
|
return EINVAL;
|
2007-03-15 11:27:14 +00:00
|
|
|
}
|
2007-04-03 11:15:32 +00:00
|
|
|
vrf_id = inp->def_vrf_id;
|
2006-11-03 15:23:16 +00:00
|
|
|
|
|
|
|
error = 0;
|
2007-02-12 23:24:31 +00:00
|
|
|
switch (optname) {
|
2006-11-03 15:23:16 +00:00
|
|
|
case SCTP_NODELAY:
|
|
|
|
case SCTP_AUTOCLOSE:
|
|
|
|
case SCTP_AUTO_ASCONF:
|
|
|
|
case SCTP_EXPLICIT_EOR:
|
|
|
|
case SCTP_DISABLE_FRAGMENTS:
|
|
|
|
case SCTP_USE_EXT_RCVINFO:
|
|
|
|
case SCTP_I_WANT_MAPPED_V4_ADDR:
|
|
|
|
/* copy in the option value */
|
2007-02-12 23:24:31 +00:00
|
|
|
SCTP_CHECK_AND_CAST(mopt, optval, uint32_t, optsize);
|
2006-11-03 15:23:16 +00:00
|
|
|
set_opt = 0;
|
|
|
|
if (error)
|
|
|
|
break;
|
2007-02-12 23:24:31 +00:00
|
|
|
switch (optname) {
|
2006-11-03 15:23:16 +00:00
|
|
|
case SCTP_DISABLE_FRAGMENTS:
|
|
|
|
set_opt = SCTP_PCB_FLAGS_NO_FRAGMENT;
|
|
|
|
break;
|
|
|
|
case SCTP_AUTO_ASCONF:
|
2007-08-24 00:53:53 +00:00
|
|
|
/*
|
|
|
|
* NOTE: we don't really support this flag
|
|
|
|
*/
|
|
|
|
if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUNDALL) {
|
|
|
|
/* only valid for bound all sockets */
|
|
|
|
set_opt = SCTP_PCB_FLAGS_AUTO_ASCONF;
|
|
|
|
} else {
|
|
|
|
SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
|
|
|
|
return (EINVAL);
|
|
|
|
}
|
2006-11-03 15:23:16 +00:00
|
|
|
break;
|
|
|
|
case SCTP_EXPLICIT_EOR:
|
|
|
|
set_opt = SCTP_PCB_FLAGS_EXPLICIT_EOR;
|
|
|
|
break;
|
|
|
|
case SCTP_USE_EXT_RCVINFO:
|
|
|
|
set_opt = SCTP_PCB_FLAGS_EXT_RCVINFO;
|
|
|
|
break;
|
|
|
|
case SCTP_I_WANT_MAPPED_V4_ADDR:
|
|
|
|
if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) {
|
|
|
|
set_opt = SCTP_PCB_FLAGS_NEEDS_MAPPED_V4;
|
|
|
|
} else {
|
2007-08-24 00:53:53 +00:00
|
|
|
SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
|
2006-11-03 15:23:16 +00:00
|
|
|
return (EINVAL);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case SCTP_NODELAY:
|
|
|
|
set_opt = SCTP_PCB_FLAGS_NODELAY;
|
|
|
|
break;
|
|
|
|
case SCTP_AUTOCLOSE:
|
2007-05-28 11:17:24 +00:00
|
|
|
if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
|
|
|
|
(inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL)) {
|
2007-08-24 00:53:53 +00:00
|
|
|
SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
|
2007-05-28 11:17:24 +00:00
|
|
|
return (EINVAL);
|
|
|
|
}
|
2006-11-03 15:23:16 +00:00
|
|
|
set_opt = SCTP_PCB_FLAGS_AUTOCLOSE;
|
|
|
|
/*
|
|
|
|
* The value is in ticks. Note this does not effect
|
|
|
|
* old associations, only new ones.
|
|
|
|
*/
|
|
|
|
inp->sctp_ep.auto_close_time = SEC_TO_TICKS(*mopt);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
SCTP_INP_WLOCK(inp);
|
|
|
|
if (*mopt != 0) {
|
|
|
|
sctp_feature_on(inp, set_opt);
|
|
|
|
} else {
|
|
|
|
sctp_feature_off(inp, set_opt);
|
|
|
|
}
|
|
|
|
SCTP_INP_WUNLOCK(inp);
|
|
|
|
break;
|
2008-07-31 11:08:30 +00:00
|
|
|
case SCTP_REUSE_PORT:
|
|
|
|
{
|
|
|
|
SCTP_CHECK_AND_CAST(mopt, optval, uint32_t, optsize);
|
|
|
|
if ((inp->sctp_flags & SCTP_PCB_FLAGS_UNBOUND) == 0) {
|
|
|
|
/* Can't set it after we are bound */
|
|
|
|
error = EINVAL;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE)) {
|
|
|
|
/* Can't do this for a 1-m socket */
|
|
|
|
error = EINVAL;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (optval)
|
|
|
|
sctp_feature_on(inp, SCTP_PCB_FLAGS_PORTREUSE);
|
|
|
|
else
|
|
|
|
sctp_feature_off(inp, SCTP_PCB_FLAGS_PORTREUSE);
|
|
|
|
}
|
|
|
|
break;
|
2006-11-03 15:23:16 +00:00
|
|
|
case SCTP_PARTIAL_DELIVERY_POINT:
|
|
|
|
{
|
2007-02-12 23:24:31 +00:00
|
|
|
uint32_t *value;
|
|
|
|
|
|
|
|
SCTP_CHECK_AND_CAST(value, optval, uint32_t, optsize);
|
2007-03-20 10:23:11 +00:00
|
|
|
if (*value > SCTP_SB_LIMIT_RCV(so)) {
|
2007-08-24 00:53:53 +00:00
|
|
|
SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
|
2007-03-20 10:23:11 +00:00
|
|
|
error = EINVAL;
|
|
|
|
break;
|
|
|
|
}
|
2007-02-12 23:24:31 +00:00
|
|
|
inp->partial_delivery_point = *value;
|
2006-11-03 15:23:16 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case SCTP_FRAGMENT_INTERLEAVE:
|
|
|
|
/* not yet until we re-write sctp_recvmsg() */
|
|
|
|
{
|
2007-04-22 11:06:27 +00:00
|
|
|
uint32_t *level;
|
2006-11-03 15:23:16 +00:00
|
|
|
|
2007-04-22 11:06:27 +00:00
|
|
|
SCTP_CHECK_AND_CAST(level, optval, uint32_t, optsize);
|
|
|
|
if (*level == SCTP_FRAG_LEVEL_2) {
|
2006-11-03 15:23:16 +00:00
|
|
|
sctp_feature_on(inp, SCTP_PCB_FLAGS_FRAG_INTERLEAVE);
|
2007-04-22 11:06:27 +00:00
|
|
|
sctp_feature_on(inp, SCTP_PCB_FLAGS_INTERLEAVE_STRMS);
|
|
|
|
} else if (*level == SCTP_FRAG_LEVEL_1) {
|
|
|
|
sctp_feature_on(inp, SCTP_PCB_FLAGS_FRAG_INTERLEAVE);
|
|
|
|
sctp_feature_off(inp, SCTP_PCB_FLAGS_INTERLEAVE_STRMS);
|
|
|
|
} else if (*level == SCTP_FRAG_LEVEL_0) {
|
2007-05-28 11:17:24 +00:00
|
|
|
sctp_feature_off(inp, SCTP_PCB_FLAGS_FRAG_INTERLEAVE);
|
2007-04-22 11:06:27 +00:00
|
|
|
sctp_feature_off(inp, SCTP_PCB_FLAGS_INTERLEAVE_STRMS);
|
|
|
|
|
2006-11-03 15:23:16 +00:00
|
|
|
} else {
|
2007-08-24 00:53:53 +00:00
|
|
|
SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
|
2007-04-22 11:06:27 +00:00
|
|
|
error = EINVAL;
|
2006-11-03 15:23:16 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case SCTP_CMT_ON_OFF:
|
2010-08-28 17:59:51 +00:00
|
|
|
if (SCTP_BASE_SYSCTL(sctp_cmt_on_off)) {
|
2006-11-03 15:23:16 +00:00
|
|
|
struct sctp_assoc_value *av;
|
|
|
|
|
2007-02-12 23:24:31 +00:00
|
|
|
SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
|
2010-08-28 17:59:51 +00:00
|
|
|
SCTP_FIND_STCB(inp, stcb, av->assoc_id);
|
|
|
|
if (stcb) {
|
2010-12-22 17:59:38 +00:00
|
|
|
stcb->asoc.sctp_cmt_on_off = av->assoc_value;
|
|
|
|
if (stcb->asoc.sctp_cmt_on_off > 2) {
|
|
|
|
stcb->asoc.sctp_cmt_on_off = 2;
|
|
|
|
}
|
2010-08-28 17:59:51 +00:00
|
|
|
SCTP_TCB_UNLOCK(stcb);
|
2008-12-06 13:19:54 +00:00
|
|
|
} else {
|
2010-08-28 17:59:51 +00:00
|
|
|
SCTP_INP_WLOCK(inp);
|
2010-12-22 17:59:38 +00:00
|
|
|
inp->sctp_cmt_on_off = av->assoc_value;
|
|
|
|
if (inp->sctp_cmt_on_off > 2) {
|
|
|
|
inp->sctp_cmt_on_off = 2;
|
|
|
|
}
|
2010-08-28 17:59:51 +00:00
|
|
|
SCTP_INP_WUNLOCK(inp);
|
2008-12-06 13:19:54 +00:00
|
|
|
}
|
2010-08-28 17:59:51 +00:00
|
|
|
} else {
|
|
|
|
SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOPROTOOPT);
|
|
|
|
error = ENOPROTOOPT;
|
2008-12-06 13:19:54 +00:00
|
|
|
}
|
|
|
|
break;
|
2007-07-14 09:36:28 +00:00
|
|
|
/* JRS - Set socket option for pluggable congestion control */
|
|
|
|
case SCTP_PLUGGABLE_CC:
|
|
|
|
{
|
|
|
|
struct sctp_assoc_value *av;
|
2011-02-26 15:23:46 +00:00
|
|
|
struct sctp_nets *net;
|
2007-07-14 09:36:28 +00:00
|
|
|
|
|
|
|
SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
|
|
|
|
SCTP_FIND_STCB(inp, stcb, av->assoc_id);
|
|
|
|
if (stcb) {
|
|
|
|
switch (av->assoc_value) {
|
|
|
|
case SCTP_CC_RFC2581:
|
|
|
|
case SCTP_CC_HSTCP:
|
|
|
|
case SCTP_CC_HTCP:
|
2011-03-01 00:37:46 +00:00
|
|
|
case SCTP_CC_RTCC:
|
2011-01-19 22:10:35 +00:00
|
|
|
stcb->asoc.cc_functions = sctp_cc_functions[av->assoc_value];
|
|
|
|
stcb->asoc.congestion_control_module = av->assoc_value;
|
2011-02-26 15:23:46 +00:00
|
|
|
if (stcb->asoc.cc_functions.sctp_set_initial_cc_param != NULL) {
|
|
|
|
TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
|
|
|
|
stcb->asoc.cc_functions.sctp_set_initial_cc_param(stcb, net);
|
|
|
|
}
|
|
|
|
}
|
2011-01-19 22:10:35 +00:00
|
|
|
break;
|
2007-07-14 09:36:28 +00:00
|
|
|
default:
|
2011-01-19 22:10:35 +00:00
|
|
|
SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
|
|
|
|
error = EINVAL;
|
|
|
|
break;
|
2007-07-14 09:36:28 +00:00
|
|
|
}
|
2011-01-19 22:10:35 +00:00
|
|
|
SCTP_TCB_UNLOCK(stcb);
|
2007-07-14 09:36:28 +00:00
|
|
|
} else {
|
|
|
|
switch (av->assoc_value) {
|
|
|
|
case SCTP_CC_RFC2581:
|
|
|
|
case SCTP_CC_HSTCP:
|
|
|
|
case SCTP_CC_HTCP:
|
2011-03-01 00:37:46 +00:00
|
|
|
case SCTP_CC_RTCC:
|
2011-01-19 22:10:35 +00:00
|
|
|
SCTP_INP_WLOCK(inp);
|
2007-07-14 09:36:28 +00:00
|
|
|
inp->sctp_ep.sctp_default_cc_module = av->assoc_value;
|
2011-01-19 22:10:35 +00:00
|
|
|
SCTP_INP_WUNLOCK(inp);
|
2007-07-14 09:36:28 +00:00
|
|
|
break;
|
|
|
|
default:
|
2007-08-24 00:53:53 +00:00
|
|
|
SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
|
2007-07-14 09:36:28 +00:00
|
|
|
error = EINVAL;
|
|
|
|
break;
|
2011-01-23 19:36:28 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2011-03-01 00:37:46 +00:00
|
|
|
break;
|
2011-02-26 15:23:46 +00:00
|
|
|
case SCTP_CC_OPTION:
|
|
|
|
{
|
|
|
|
struct sctp_cc_option *cc_opt;
|
|
|
|
|
|
|
|
SCTP_CHECK_AND_CAST(cc_opt, optval, struct sctp_cc_option, optsize);
|
|
|
|
SCTP_FIND_STCB(inp, stcb, cc_opt->aid_value.assoc_id);
|
|
|
|
if (stcb == NULL) {
|
|
|
|
error = EINVAL;
|
|
|
|
} else {
|
|
|
|
if (stcb->asoc.cc_functions.sctp_cwnd_socket_option == NULL) {
|
|
|
|
error = ENOTSUP;
|
|
|
|
} else {
|
|
|
|
error = (*stcb->asoc.cc_functions.sctp_cwnd_socket_option) (stcb, 1,
|
|
|
|
cc_opt);
|
|
|
|
}
|
|
|
|
SCTP_TCB_UNLOCK(stcb);
|
|
|
|
}
|
|
|
|
}
|
2011-01-23 19:36:28 +00:00
|
|
|
break;
|
|
|
|
/* RS - Set socket option for pluggable stream scheduling */
|
|
|
|
case SCTP_PLUGGABLE_SS:
|
|
|
|
{
|
|
|
|
struct sctp_assoc_value *av;
|
|
|
|
|
|
|
|
SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
|
|
|
|
SCTP_FIND_STCB(inp, stcb, av->assoc_id);
|
|
|
|
if (stcb) {
|
|
|
|
switch (av->assoc_value) {
|
|
|
|
case SCTP_SS_DEFAULT:
|
|
|
|
case SCTP_SS_ROUND_ROBIN:
|
|
|
|
case SCTP_SS_ROUND_ROBIN_PACKET:
|
|
|
|
case SCTP_SS_PRIORITY:
|
|
|
|
case SCTP_SS_FAIR_BANDWITH:
|
|
|
|
case SCTP_SS_FIRST_COME:
|
|
|
|
stcb->asoc.ss_functions.sctp_ss_clear(stcb, &stcb->asoc, 1, 1);
|
|
|
|
stcb->asoc.ss_functions = sctp_ss_functions[av->assoc_value];
|
|
|
|
stcb->asoc.stream_scheduling_module = av->assoc_value;
|
|
|
|
stcb->asoc.ss_functions.sctp_ss_init(stcb, &stcb->asoc, 1);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
|
|
|
|
error = EINVAL;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
SCTP_TCB_UNLOCK(stcb);
|
|
|
|
} else {
|
|
|
|
switch (av->assoc_value) {
|
|
|
|
case SCTP_SS_DEFAULT:
|
|
|
|
case SCTP_SS_ROUND_ROBIN:
|
|
|
|
case SCTP_SS_ROUND_ROBIN_PACKET:
|
|
|
|
case SCTP_SS_PRIORITY:
|
|
|
|
case SCTP_SS_FAIR_BANDWITH:
|
|
|
|
case SCTP_SS_FIRST_COME:
|
|
|
|
SCTP_INP_WLOCK(inp);
|
|
|
|
inp->sctp_ep.sctp_default_ss_module = av->assoc_value;
|
|
|
|
SCTP_INP_WUNLOCK(inp);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
|
|
|
|
error = EINVAL;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case SCTP_SS_VALUE:
|
|
|
|
{
|
|
|
|
struct sctp_stream_value *av;
|
|
|
|
|
|
|
|
SCTP_CHECK_AND_CAST(av, optval, struct sctp_stream_value, optsize);
|
|
|
|
SCTP_FIND_STCB(inp, stcb, av->assoc_id);
|
|
|
|
if (stcb) {
|
|
|
|
if (stcb->asoc.ss_functions.sctp_ss_set_value(stcb, &stcb->asoc, &stcb->asoc.strmout[av->stream_id],
|
|
|
|
av->stream_value) < 0) {
|
|
|
|
SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
|
|
|
|
error = EINVAL;
|
|
|
|
}
|
|
|
|
SCTP_TCB_UNLOCK(stcb);
|
|
|
|
} else {
|
|
|
|
/*
|
|
|
|
* Can't set stream value without
|
|
|
|
* association
|
|
|
|
*/
|
|
|
|
SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
|
|
|
|
error = EINVAL;
|
2007-07-14 09:36:28 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
2006-11-03 15:23:16 +00:00
|
|
|
case SCTP_CLR_STAT_LOG:
|
2007-08-24 00:53:53 +00:00
|
|
|
SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EOPNOTSUPP);
|
2006-11-03 15:23:16 +00:00
|
|
|
error = EOPNOTSUPP;
|
|
|
|
break;
|
|
|
|
case SCTP_CONTEXT:
|
|
|
|
{
|
|
|
|
struct sctp_assoc_value *av;
|
|
|
|
|
2007-02-12 23:24:31 +00:00
|
|
|
SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
|
|
|
|
SCTP_FIND_STCB(inp, stcb, av->assoc_id);
|
|
|
|
|
|
|
|
if (stcb) {
|
|
|
|
stcb->asoc.context = av->assoc_value;
|
|
|
|
SCTP_TCB_UNLOCK(stcb);
|
2006-11-03 15:23:16 +00:00
|
|
|
} else {
|
2007-02-12 23:24:31 +00:00
|
|
|
SCTP_INP_WLOCK(inp);
|
2006-11-03 15:23:16 +00:00
|
|
|
inp->sctp_context = av->assoc_value;
|
2007-02-12 23:24:31 +00:00
|
|
|
SCTP_INP_WUNLOCK(inp);
|
2006-11-03 15:23:16 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
2007-03-15 11:27:14 +00:00
|
|
|
case SCTP_VRF_ID:
|
|
|
|
{
|
2007-05-28 11:17:24 +00:00
|
|
|
uint32_t *default_vrfid;
|
2007-03-15 11:27:14 +00:00
|
|
|
|
2007-05-28 11:17:24 +00:00
|
|
|
SCTP_CHECK_AND_CAST(default_vrfid, optval, uint32_t, optsize);
|
|
|
|
if (*default_vrfid > SCTP_MAX_VRF_ID) {
|
2007-08-24 00:53:53 +00:00
|
|
|
SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
|
2007-03-15 11:27:14 +00:00
|
|
|
error = EINVAL;
|
|
|
|
break;
|
|
|
|
}
|
2007-05-28 11:17:24 +00:00
|
|
|
inp->def_vrf_id = *default_vrfid;
|
2007-03-15 11:27:14 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case SCTP_DEL_VRF_ID:
|
|
|
|
{
|
2007-08-24 00:53:53 +00:00
|
|
|
SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EOPNOTSUPP);
|
2007-03-15 11:27:14 +00:00
|
|
|
error = EOPNOTSUPP;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case SCTP_ADD_VRF_ID:
|
|
|
|
{
|
2007-08-24 00:53:53 +00:00
|
|
|
SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EOPNOTSUPP);
|
2007-03-15 11:27:14 +00:00
|
|
|
error = EOPNOTSUPP;
|
|
|
|
break;
|
|
|
|
}
|
2007-05-28 11:17:24 +00:00
|
|
|
case SCTP_DELAYED_SACK:
|
2006-11-03 15:23:16 +00:00
|
|
|
{
|
2007-05-28 11:17:24 +00:00
|
|
|
struct sctp_sack_info *sack;
|
2006-11-03 15:23:16 +00:00
|
|
|
|
2007-05-28 11:17:24 +00:00
|
|
|
SCTP_CHECK_AND_CAST(sack, optval, struct sctp_sack_info, optsize);
|
|
|
|
SCTP_FIND_STCB(inp, stcb, sack->sack_assoc_id);
|
2007-07-17 20:58:26 +00:00
|
|
|
if (sack->sack_delay) {
|
|
|
|
if (sack->sack_delay > SCTP_MAX_SACK_DELAY)
|
|
|
|
sack->sack_delay = SCTP_MAX_SACK_DELAY;
|
|
|
|
}
|
2007-02-12 23:24:31 +00:00
|
|
|
if (stcb) {
|
2007-05-28 11:17:24 +00:00
|
|
|
if (sack->sack_delay) {
|
|
|
|
if (MSEC_TO_TICKS(sack->sack_delay) < 1) {
|
|
|
|
sack->sack_delay = TICKS_TO_MSEC(1);
|
|
|
|
}
|
|
|
|
stcb->asoc.delayed_ack = sack->sack_delay;
|
|
|
|
}
|
|
|
|
if (sack->sack_freq) {
|
|
|
|
stcb->asoc.sack_freq = sack->sack_freq;
|
|
|
|
}
|
2007-02-12 23:24:31 +00:00
|
|
|
SCTP_TCB_UNLOCK(stcb);
|
|
|
|
} else {
|
2006-11-03 15:23:16 +00:00
|
|
|
SCTP_INP_WLOCK(inp);
|
2007-05-28 11:17:24 +00:00
|
|
|
if (sack->sack_delay) {
|
|
|
|
if (MSEC_TO_TICKS(sack->sack_delay) < 1) {
|
|
|
|
sack->sack_delay = TICKS_TO_MSEC(1);
|
|
|
|
}
|
|
|
|
inp->sctp_ep.sctp_timeoutticks[SCTP_TIMER_RECV] = MSEC_TO_TICKS(sack->sack_delay);
|
|
|
|
}
|
|
|
|
if (sack->sack_freq) {
|
|
|
|
inp->sctp_ep.sctp_sack_freq = sack->sack_freq;
|
|
|
|
}
|
2006-11-03 15:23:16 +00:00
|
|
|
SCTP_INP_WUNLOCK(inp);
|
|
|
|
}
|
2007-02-12 23:24:31 +00:00
|
|
|
break;
|
2006-11-03 15:23:16 +00:00
|
|
|
}
|
|
|
|
case SCTP_AUTH_CHUNK:
|
|
|
|
{
|
|
|
|
struct sctp_authchunk *sauth;
|
|
|
|
|
2007-02-12 23:24:31 +00:00
|
|
|
SCTP_CHECK_AND_CAST(sauth, optval, struct sctp_authchunk, optsize);
|
|
|
|
|
|
|
|
SCTP_INP_WLOCK(inp);
|
2007-08-24 00:53:53 +00:00
|
|
|
if (sctp_auth_add_chunk(sauth->sauth_chunk, inp->sctp_ep.local_auth_chunks)) {
|
|
|
|
SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
|
2006-11-03 15:23:16 +00:00
|
|
|
error = EINVAL;
|
2007-08-24 00:53:53 +00:00
|
|
|
}
|
2007-02-12 23:24:31 +00:00
|
|
|
SCTP_INP_WUNLOCK(inp);
|
2006-11-03 15:23:16 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case SCTP_AUTH_KEY:
|
|
|
|
{
|
|
|
|
struct sctp_authkey *sca;
|
|
|
|
struct sctp_keyhead *shared_keys;
|
|
|
|
sctp_sharedkey_t *shared_key;
|
|
|
|
sctp_key_t *key = NULL;
|
2007-02-12 23:24:31 +00:00
|
|
|
size_t size;
|
2006-11-03 15:23:16 +00:00
|
|
|
|
2007-02-12 23:24:31 +00:00
|
|
|
SCTP_CHECK_AND_CAST(sca, optval, struct sctp_authkey, optsize);
|
2007-05-09 13:30:06 +00:00
|
|
|
SCTP_FIND_STCB(inp, stcb, sca->sca_assoc_id);
|
|
|
|
size = optsize - sizeof(*sca);
|
2007-02-12 23:24:31 +00:00
|
|
|
|
|
|
|
if (stcb) {
|
2006-11-03 15:23:16 +00:00
|
|
|
/* set it on the assoc */
|
|
|
|
shared_keys = &stcb->asoc.shared_keys;
|
|
|
|
/* clear the cached keys for this key id */
|
|
|
|
sctp_clear_cachedkeys(stcb, sca->sca_keynumber);
|
|
|
|
/*
|
|
|
|
* create the new shared key and
|
|
|
|
* insert/replace it
|
|
|
|
*/
|
|
|
|
if (size > 0) {
|
|
|
|
key = sctp_set_key(sca->sca_key, (uint32_t) size);
|
|
|
|
if (key == NULL) {
|
2007-08-24 00:53:53 +00:00
|
|
|
SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOMEM);
|
2006-11-03 15:23:16 +00:00
|
|
|
error = ENOMEM;
|
|
|
|
SCTP_TCB_UNLOCK(stcb);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
shared_key = sctp_alloc_sharedkey();
|
|
|
|
if (shared_key == NULL) {
|
|
|
|
sctp_free_key(key);
|
2007-08-24 00:53:53 +00:00
|
|
|
SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOMEM);
|
2006-11-03 15:23:16 +00:00
|
|
|
error = ENOMEM;
|
|
|
|
SCTP_TCB_UNLOCK(stcb);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
shared_key->key = key;
|
|
|
|
shared_key->keyid = sca->sca_keynumber;
|
2008-12-06 13:19:54 +00:00
|
|
|
error = sctp_insert_sharedkey(shared_keys, shared_key);
|
2006-11-03 15:23:16 +00:00
|
|
|
SCTP_TCB_UNLOCK(stcb);
|
|
|
|
} else {
|
2007-02-12 23:24:31 +00:00
|
|
|
/* set it on the endpoint */
|
2006-11-03 15:23:16 +00:00
|
|
|
SCTP_INP_WLOCK(inp);
|
|
|
|
shared_keys = &inp->sctp_ep.shared_keys;
|
|
|
|
/*
|
|
|
|
* clear the cached keys on all assocs for
|
|
|
|
* this key id
|
|
|
|
*/
|
|
|
|
sctp_clear_cachedkeys_ep(inp, sca->sca_keynumber);
|
|
|
|
/*
|
|
|
|
* create the new shared key and
|
|
|
|
* insert/replace it
|
|
|
|
*/
|
|
|
|
if (size > 0) {
|
|
|
|
key = sctp_set_key(sca->sca_key, (uint32_t) size);
|
|
|
|
if (key == NULL) {
|
2007-08-24 00:53:53 +00:00
|
|
|
SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOMEM);
|
2006-11-03 15:23:16 +00:00
|
|
|
error = ENOMEM;
|
|
|
|
SCTP_INP_WUNLOCK(inp);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
shared_key = sctp_alloc_sharedkey();
|
|
|
|
if (shared_key == NULL) {
|
|
|
|
sctp_free_key(key);
|
2007-08-24 00:53:53 +00:00
|
|
|
SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOMEM);
|
2006-11-03 15:23:16 +00:00
|
|
|
error = ENOMEM;
|
|
|
|
SCTP_INP_WUNLOCK(inp);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
shared_key->key = key;
|
|
|
|
shared_key->keyid = sca->sca_keynumber;
|
2008-12-06 13:19:54 +00:00
|
|
|
error = sctp_insert_sharedkey(shared_keys, shared_key);
|
2006-11-03 15:23:16 +00:00
|
|
|
SCTP_INP_WUNLOCK(inp);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case SCTP_HMAC_IDENT:
|
|
|
|
{
|
|
|
|
struct sctp_hmacalgo *shmac;
|
|
|
|
sctp_hmaclist_t *hmaclist;
|
2008-07-31 11:08:30 +00:00
|
|
|
uint16_t hmacid;
|
|
|
|
uint32_t i;
|
|
|
|
|
|
|
|
size_t found;
|
2006-11-03 15:23:16 +00:00
|
|
|
|
2007-02-12 23:24:31 +00:00
|
|
|
SCTP_CHECK_AND_CAST(shmac, optval, struct sctp_hmacalgo, optsize);
|
2008-07-31 11:08:30 +00:00
|
|
|
if (optsize < sizeof(struct sctp_hmacalgo) + shmac->shmac_number_of_idents * sizeof(uint16_t)) {
|
|
|
|
SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
|
|
|
|
error = EINVAL;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
hmaclist = sctp_alloc_hmaclist(shmac->shmac_number_of_idents);
|
2006-11-03 15:23:16 +00:00
|
|
|
if (hmaclist == NULL) {
|
2007-08-24 00:53:53 +00:00
|
|
|
SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOMEM);
|
2006-11-03 15:23:16 +00:00
|
|
|
error = ENOMEM;
|
|
|
|
break;
|
|
|
|
}
|
2008-07-31 11:08:30 +00:00
|
|
|
for (i = 0; i < shmac->shmac_number_of_idents; i++) {
|
2006-11-03 15:23:16 +00:00
|
|
|
hmacid = shmac->shmac_idents[i];
|
2008-07-31 11:08:30 +00:00
|
|
|
if (sctp_auth_add_hmacid(hmaclist, hmacid)) {
|
2006-11-03 15:23:16 +00:00
|
|
|
/* invalid HMACs were found */ ;
|
2007-08-24 00:53:53 +00:00
|
|
|
SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
|
2006-11-03 15:23:16 +00:00
|
|
|
error = EINVAL;
|
2006-11-08 00:21:13 +00:00
|
|
|
sctp_free_hmaclist(hmaclist);
|
2006-11-03 15:23:16 +00:00
|
|
|
goto sctp_set_hmac_done;
|
|
|
|
}
|
|
|
|
}
|
2007-05-28 11:17:24 +00:00
|
|
|
found = 0;
|
|
|
|
for (i = 0; i < hmaclist->num_algo; i++) {
|
|
|
|
if (hmaclist->hmac[i] == SCTP_AUTH_HMAC_ID_SHA1) {
|
|
|
|
/* already in list */
|
|
|
|
found = 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!found) {
|
|
|
|
sctp_free_hmaclist(hmaclist);
|
2007-08-24 00:53:53 +00:00
|
|
|
SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
|
2007-05-28 11:17:24 +00:00
|
|
|
error = EINVAL;
|
|
|
|
break;
|
|
|
|
}
|
2006-11-03 15:23:16 +00:00
|
|
|
/* set it on the endpoint */
|
|
|
|
SCTP_INP_WLOCK(inp);
|
|
|
|
if (inp->sctp_ep.local_hmacs)
|
|
|
|
sctp_free_hmaclist(inp->sctp_ep.local_hmacs);
|
|
|
|
inp->sctp_ep.local_hmacs = hmaclist;
|
|
|
|
SCTP_INP_WUNLOCK(inp);
|
|
|
|
sctp_set_hmac_done:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case SCTP_AUTH_ACTIVE_KEY:
|
|
|
|
{
|
|
|
|
struct sctp_authkeyid *scact;
|
|
|
|
|
2008-12-06 13:19:54 +00:00
|
|
|
SCTP_CHECK_AND_CAST(scact, optval, struct sctp_authkeyid,
|
|
|
|
optsize);
|
2007-02-12 23:24:31 +00:00
|
|
|
SCTP_FIND_STCB(inp, stcb, scact->scact_assoc_id);
|
|
|
|
|
2006-11-03 15:23:16 +00:00
|
|
|
/* set the active key on the right place */
|
2007-02-12 23:24:31 +00:00
|
|
|
if (stcb) {
|
2006-11-03 15:23:16 +00:00
|
|
|
/* set the active key on the assoc */
|
2008-12-06 13:19:54 +00:00
|
|
|
if (sctp_auth_setactivekey(stcb,
|
|
|
|
scact->scact_keynumber)) {
|
|
|
|
SCTP_LTRACE_ERR_RET(inp, NULL, NULL,
|
|
|
|
SCTP_FROM_SCTP_USRREQ,
|
|
|
|
EINVAL);
|
2006-11-03 15:23:16 +00:00
|
|
|
error = EINVAL;
|
2007-08-24 00:53:53 +00:00
|
|
|
}
|
2006-11-03 15:23:16 +00:00
|
|
|
SCTP_TCB_UNLOCK(stcb);
|
|
|
|
} else {
|
|
|
|
/* set the active key on the endpoint */
|
|
|
|
SCTP_INP_WLOCK(inp);
|
2008-12-06 13:19:54 +00:00
|
|
|
if (sctp_auth_setactivekey_ep(inp,
|
|
|
|
scact->scact_keynumber)) {
|
|
|
|
SCTP_LTRACE_ERR_RET(inp, NULL, NULL,
|
|
|
|
SCTP_FROM_SCTP_USRREQ,
|
|
|
|
EINVAL);
|
2006-11-03 15:23:16 +00:00
|
|
|
error = EINVAL;
|
2007-08-24 00:53:53 +00:00
|
|
|
}
|
2006-11-03 15:23:16 +00:00
|
|
|
SCTP_INP_WUNLOCK(inp);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case SCTP_AUTH_DELETE_KEY:
|
|
|
|
{
|
|
|
|
struct sctp_authkeyid *scdel;
|
|
|
|
|
2008-12-06 13:19:54 +00:00
|
|
|
SCTP_CHECK_AND_CAST(scdel, optval, struct sctp_authkeyid,
|
|
|
|
optsize);
|
2007-02-12 23:24:31 +00:00
|
|
|
SCTP_FIND_STCB(inp, stcb, scdel->scact_assoc_id);
|
|
|
|
|
2006-11-03 15:23:16 +00:00
|
|
|
/* delete the key from the right place */
|
2007-02-12 23:24:31 +00:00
|
|
|
if (stcb) {
|
2008-12-06 13:19:54 +00:00
|
|
|
if (sctp_delete_sharedkey(stcb,
|
|
|
|
scdel->scact_keynumber)) {
|
|
|
|
SCTP_LTRACE_ERR_RET(inp, NULL, NULL,
|
|
|
|
SCTP_FROM_SCTP_USRREQ,
|
|
|
|
EINVAL);
|
2006-11-03 15:23:16 +00:00
|
|
|
error = EINVAL;
|
2007-08-24 00:53:53 +00:00
|
|
|
}
|
2006-11-03 15:23:16 +00:00
|
|
|
SCTP_TCB_UNLOCK(stcb);
|
|
|
|
} else {
|
|
|
|
SCTP_INP_WLOCK(inp);
|
2008-12-06 13:19:54 +00:00
|
|
|
if (sctp_delete_sharedkey_ep(inp,
|
|
|
|
scdel->scact_keynumber)) {
|
|
|
|
SCTP_LTRACE_ERR_RET(inp, NULL, NULL,
|
|
|
|
SCTP_FROM_SCTP_USRREQ,
|
|
|
|
EINVAL);
|
|
|
|
error = EINVAL;
|
|
|
|
}
|
|
|
|
SCTP_INP_WUNLOCK(inp);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case SCTP_AUTH_DEACTIVATE_KEY:
|
|
|
|
{
|
|
|
|
struct sctp_authkeyid *keyid;
|
|
|
|
|
|
|
|
SCTP_CHECK_AND_CAST(keyid, optval, struct sctp_authkeyid,
|
|
|
|
optsize);
|
|
|
|
SCTP_FIND_STCB(inp, stcb, keyid->scact_assoc_id);
|
|
|
|
|
|
|
|
/* deactivate the key from the right place */
|
|
|
|
if (stcb) {
|
|
|
|
if (sctp_deact_sharedkey(stcb,
|
|
|
|
keyid->scact_keynumber)) {
|
|
|
|
SCTP_LTRACE_ERR_RET(inp, NULL, NULL,
|
|
|
|
SCTP_FROM_SCTP_USRREQ,
|
|
|
|
EINVAL);
|
|
|
|
error = EINVAL;
|
|
|
|
}
|
|
|
|
SCTP_TCB_UNLOCK(stcb);
|
|
|
|
} else {
|
|
|
|
SCTP_INP_WLOCK(inp);
|
|
|
|
if (sctp_deact_sharedkey_ep(inp,
|
|
|
|
keyid->scact_keynumber)) {
|
|
|
|
SCTP_LTRACE_ERR_RET(inp, NULL, NULL,
|
|
|
|
SCTP_FROM_SCTP_USRREQ,
|
|
|
|
EINVAL);
|
2006-11-03 15:23:16 +00:00
|
|
|
error = EINVAL;
|
2007-08-24 00:53:53 +00:00
|
|
|
}
|
2006-11-03 15:23:16 +00:00
|
|
|
SCTP_INP_WUNLOCK(inp);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case SCTP_RESET_STREAMS:
|
|
|
|
{
|
|
|
|
struct sctp_stream_reset *strrst;
|
2009-02-20 15:03:54 +00:00
|
|
|
uint8_t send_in = 0, send_tsn = 0, send_out = 0,
|
|
|
|
addstream = 0;
|
|
|
|
uint16_t addstrmcnt = 0;
|
2006-11-03 15:23:16 +00:00
|
|
|
int i;
|
|
|
|
|
2007-02-12 23:24:31 +00:00
|
|
|
SCTP_CHECK_AND_CAST(strrst, optval, struct sctp_stream_reset, optsize);
|
|
|
|
SCTP_FIND_STCB(inp, stcb, strrst->strrst_assoc_id);
|
2006-11-03 15:23:16 +00:00
|
|
|
|
|
|
|
if (stcb == NULL) {
|
2007-08-24 00:53:53 +00:00
|
|
|
SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOENT);
|
2006-11-03 15:23:16 +00:00
|
|
|
error = ENOENT;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (stcb->asoc.peer_supports_strreset == 0) {
|
|
|
|
/*
|
|
|
|
* Peer does not support it, we return
|
|
|
|
* protocol not supported since this is true
|
|
|
|
* for this feature and this peer, not the
|
|
|
|
* socket request in general.
|
|
|
|
*/
|
2007-08-24 00:53:53 +00:00
|
|
|
SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EPROTONOSUPPORT);
|
2006-11-03 15:23:16 +00:00
|
|
|
error = EPROTONOSUPPORT;
|
|
|
|
SCTP_TCB_UNLOCK(stcb);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (stcb->asoc.stream_reset_outstanding) {
|
2007-08-24 00:53:53 +00:00
|
|
|
SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EALREADY);
|
2006-11-03 15:23:16 +00:00
|
|
|
error = EALREADY;
|
|
|
|
SCTP_TCB_UNLOCK(stcb);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (strrst->strrst_flags == SCTP_RESET_LOCAL_RECV) {
|
|
|
|
send_in = 1;
|
|
|
|
} else if (strrst->strrst_flags == SCTP_RESET_LOCAL_SEND) {
|
|
|
|
send_out = 1;
|
|
|
|
} else if (strrst->strrst_flags == SCTP_RESET_BOTH) {
|
|
|
|
send_in = 1;
|
|
|
|
send_out = 1;
|
|
|
|
} else if (strrst->strrst_flags == SCTP_RESET_TSN) {
|
|
|
|
send_tsn = 1;
|
2009-02-20 15:03:54 +00:00
|
|
|
} else if (strrst->strrst_flags == SCTP_RESET_ADD_STREAMS) {
|
|
|
|
if (send_tsn ||
|
|
|
|
send_in ||
|
|
|
|
send_out) {
|
|
|
|
/* We can't do that and add streams */
|
|
|
|
error = EINVAL;
|
|
|
|
goto skip_stuff;
|
|
|
|
}
|
|
|
|
if (stcb->asoc.stream_reset_outstanding) {
|
|
|
|
error = EBUSY;
|
|
|
|
goto skip_stuff;
|
|
|
|
}
|
|
|
|
addstream = 1;
|
|
|
|
/* We allocate here */
|
|
|
|
addstrmcnt = strrst->strrst_num_streams;
|
|
|
|
if ((int)(addstrmcnt + stcb->asoc.streamoutcnt) > 0xffff) {
|
|
|
|
/* You can't have more than 64k */
|
|
|
|
error = EINVAL;
|
|
|
|
goto skip_stuff;
|
|
|
|
}
|
|
|
|
if ((stcb->asoc.strm_realoutsize - stcb->asoc.streamoutcnt) < addstrmcnt) {
|
|
|
|
/* Need to allocate more */
|
|
|
|
struct sctp_stream_out *oldstream;
|
2010-12-30 16:56:20 +00:00
|
|
|
struct sctp_stream_queue_pending *sp,
|
|
|
|
*nsp;
|
2009-02-20 15:03:54 +00:00
|
|
|
|
|
|
|
oldstream = stcb->asoc.strmout;
|
|
|
|
/* get some more */
|
|
|
|
SCTP_MALLOC(stcb->asoc.strmout, struct sctp_stream_out *,
|
|
|
|
((stcb->asoc.streamoutcnt + addstrmcnt) * sizeof(struct sctp_stream_out)),
|
|
|
|
SCTP_M_STRMO);
|
|
|
|
if (stcb->asoc.strmout == NULL) {
|
|
|
|
stcb->asoc.strmout = oldstream;
|
|
|
|
error = ENOMEM;
|
|
|
|
goto skip_stuff;
|
|
|
|
}
|
|
|
|
/*
|
|
|
|
* Ok now we proceed with copying
|
|
|
|
* the old out stuff and
|
|
|
|
* initializing the new stuff.
|
|
|
|
*/
|
2009-02-27 20:54:45 +00:00
|
|
|
SCTP_TCB_SEND_LOCK(stcb);
|
2011-01-23 19:36:28 +00:00
|
|
|
stcb->asoc.ss_functions.sctp_ss_clear(stcb, &stcb->asoc, 0, 1);
|
2009-02-27 20:54:45 +00:00
|
|
|
for (i = 0; i < stcb->asoc.streamoutcnt; i++) {
|
|
|
|
TAILQ_INIT(&stcb->asoc.strmout[i].outqueue);
|
|
|
|
stcb->asoc.strmout[i].next_sequence_sent = oldstream[i].next_sequence_sent;
|
|
|
|
stcb->asoc.strmout[i].last_msg_incomplete = oldstream[i].last_msg_incomplete;
|
|
|
|
stcb->asoc.strmout[i].stream_no = i;
|
2011-02-03 20:44:49 +00:00
|
|
|
stcb->asoc.ss_functions.sctp_ss_init_stream(&stcb->asoc.strmout[i], &oldstream[i]);
|
2009-02-27 20:54:45 +00:00
|
|
|
/*
|
|
|
|
* now anything on those
|
|
|
|
* queues?
|
|
|
|
*/
|
2010-12-30 16:56:20 +00:00
|
|
|
TAILQ_FOREACH_SAFE(sp, &oldstream[i].outqueue, next, nsp) {
|
2009-02-27 20:54:45 +00:00
|
|
|
TAILQ_REMOVE(&oldstream[i].outqueue, sp, next);
|
|
|
|
TAILQ_INSERT_TAIL(&stcb->asoc.strmout[i].outqueue, sp, next);
|
|
|
|
}
|
|
|
|
/*
|
|
|
|
* Now move assoc pointers
|
|
|
|
* too
|
|
|
|
*/
|
|
|
|
if (stcb->asoc.last_out_stream == &oldstream[i]) {
|
|
|
|
stcb->asoc.last_out_stream = &stcb->asoc.strmout[i];
|
|
|
|
}
|
|
|
|
if (stcb->asoc.locked_on_sending == &oldstream[i]) {
|
|
|
|
stcb->asoc.locked_on_sending = &stcb->asoc.strmout[i];
|
|
|
|
}
|
|
|
|
}
|
2009-02-20 15:03:54 +00:00
|
|
|
/* now the new streams */
|
2011-01-23 19:36:28 +00:00
|
|
|
stcb->asoc.ss_functions.sctp_ss_init(stcb, &stcb->asoc, 1);
|
2009-02-20 15:03:54 +00:00
|
|
|
for (i = stcb->asoc.streamoutcnt; i < (stcb->asoc.streamoutcnt + addstrmcnt); i++) {
|
|
|
|
stcb->asoc.strmout[i].next_sequence_sent = 0x0;
|
|
|
|
TAILQ_INIT(&stcb->asoc.strmout[i].outqueue);
|
|
|
|
stcb->asoc.strmout[i].stream_no = i;
|
|
|
|
stcb->asoc.strmout[i].last_msg_incomplete = 0;
|
2011-02-03 20:44:49 +00:00
|
|
|
stcb->asoc.ss_functions.sctp_ss_init_stream(&stcb->asoc.strmout[i], NULL);
|
2009-02-20 15:03:54 +00:00
|
|
|
}
|
|
|
|
stcb->asoc.strm_realoutsize = stcb->asoc.streamoutcnt + addstrmcnt;
|
|
|
|
SCTP_FREE(oldstream, SCTP_M_STRMO);
|
|
|
|
}
|
2009-02-27 20:54:45 +00:00
|
|
|
SCTP_TCB_SEND_UNLOCK(stcb);
|
2009-02-20 15:03:54 +00:00
|
|
|
goto skip_stuff;
|
2006-11-03 15:23:16 +00:00
|
|
|
} else {
|
2007-08-24 00:53:53 +00:00
|
|
|
SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
|
2006-11-03 15:23:16 +00:00
|
|
|
error = EINVAL;
|
|
|
|
SCTP_TCB_UNLOCK(stcb);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
for (i = 0; i < strrst->strrst_num_streams; i++) {
|
|
|
|
if ((send_in) &&
|
|
|
|
|
|
|
|
(strrst->strrst_list[i] > stcb->asoc.streamincnt)) {
|
2007-08-24 00:53:53 +00:00
|
|
|
SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
|
2006-11-03 15:23:16 +00:00
|
|
|
error = EINVAL;
|
|
|
|
goto get_out;
|
|
|
|
}
|
|
|
|
if ((send_out) &&
|
|
|
|
(strrst->strrst_list[i] > stcb->asoc.streamoutcnt)) {
|
2007-08-24 00:53:53 +00:00
|
|
|
SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
|
2006-11-03 15:23:16 +00:00
|
|
|
error = EINVAL;
|
|
|
|
goto get_out;
|
|
|
|
}
|
|
|
|
}
|
2009-02-20 15:03:54 +00:00
|
|
|
skip_stuff:
|
2006-11-03 15:23:16 +00:00
|
|
|
if (error) {
|
|
|
|
get_out:
|
|
|
|
SCTP_TCB_UNLOCK(stcb);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
error = sctp_send_str_reset_req(stcb, strrst->strrst_num_streams,
|
|
|
|
strrst->strrst_list,
|
|
|
|
send_out, (stcb->asoc.str_reset_seq_in - 3),
|
2009-02-20 15:03:54 +00:00
|
|
|
send_in, send_tsn, addstream, addstrmcnt);
|
2006-11-03 15:23:16 +00:00
|
|
|
|
2007-09-08 11:35:11 +00:00
|
|
|
sctp_chunk_output(inp, stcb, SCTP_OUTPUT_FROM_STRRST_REQ, SCTP_SO_LOCKED);
|
2006-11-03 15:23:16 +00:00
|
|
|
SCTP_TCB_UNLOCK(stcb);
|
|
|
|
}
|
|
|
|
break;
|
2007-02-12 23:24:31 +00:00
|
|
|
|
2006-11-03 15:23:16 +00:00
|
|
|
case SCTP_CONNECT_X:
|
2007-02-12 23:24:31 +00:00
|
|
|
if (optsize < (sizeof(int) + sizeof(struct sockaddr_in))) {
|
2007-08-24 00:53:53 +00:00
|
|
|
SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
|
2006-11-03 15:23:16 +00:00
|
|
|
error = EINVAL;
|
|
|
|
break;
|
|
|
|
}
|
2007-02-12 23:24:31 +00:00
|
|
|
error = sctp_do_connect_x(so, inp, optval, optsize, p, 0);
|
2006-11-03 15:23:16 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case SCTP_CONNECT_X_DELAYED:
|
2007-02-12 23:24:31 +00:00
|
|
|
if (optsize < (sizeof(int) + sizeof(struct sockaddr_in))) {
|
2007-08-24 00:53:53 +00:00
|
|
|
SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
|
2006-11-03 15:23:16 +00:00
|
|
|
error = EINVAL;
|
|
|
|
break;
|
|
|
|
}
|
2007-02-12 23:24:31 +00:00
|
|
|
error = sctp_do_connect_x(so, inp, optval, optsize, p, 1);
|
2006-11-03 15:23:16 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case SCTP_CONNECT_X_COMPLETE:
|
|
|
|
{
|
|
|
|
struct sockaddr *sa;
|
|
|
|
struct sctp_nets *net;
|
|
|
|
|
2007-02-12 23:24:31 +00:00
|
|
|
/* FIXME MT: check correct? */
|
|
|
|
SCTP_CHECK_AND_CAST(sa, optval, struct sockaddr, optsize);
|
|
|
|
|
2006-11-03 15:23:16 +00:00
|
|
|
/* find tcb */
|
|
|
|
if (inp->sctp_flags & SCTP_PCB_FLAGS_CONNECTED) {
|
|
|
|
SCTP_INP_RLOCK(inp);
|
|
|
|
stcb = LIST_FIRST(&inp->sctp_asoc_list);
|
|
|
|
if (stcb) {
|
|
|
|
SCTP_TCB_LOCK(stcb);
|
|
|
|
net = sctp_findnet(stcb, sa);
|
|
|
|
}
|
|
|
|
SCTP_INP_RUNLOCK(inp);
|
|
|
|
} else {
|
2007-02-12 23:24:31 +00:00
|
|
|
/*
|
|
|
|
* We increment here since
|
|
|
|
* sctp_findassociation_ep_addr() wil do a
|
|
|
|
* decrement if it finds the stcb as long as
|
|
|
|
* the locked tcb (last argument) is NOT a
|
|
|
|
* TCB.. aka NULL.
|
|
|
|
*/
|
2006-11-03 15:23:16 +00:00
|
|
|
SCTP_INP_INCR_REF(inp);
|
|
|
|
stcb = sctp_findassociation_ep_addr(&inp, sa, &net, NULL, NULL);
|
|
|
|
if (stcb == NULL) {
|
|
|
|
SCTP_INP_DECR_REF(inp);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (stcb == NULL) {
|
2007-08-24 00:53:53 +00:00
|
|
|
SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOENT);
|
2006-11-03 15:23:16 +00:00
|
|
|
error = ENOENT;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (stcb->asoc.delayed_connection == 1) {
|
|
|
|
stcb->asoc.delayed_connection = 0;
|
2007-05-08 14:32:53 +00:00
|
|
|
(void)SCTP_GETTIME_TIMEVAL(&stcb->asoc.time_entered);
|
2006-12-14 17:02:55 +00:00
|
|
|
sctp_timer_stop(SCTP_TIMER_TYPE_INIT, inp, stcb,
|
|
|
|
stcb->asoc.primary_destination,
|
|
|
|
SCTP_FROM_SCTP_USRREQ + SCTP_LOC_9);
|
2007-09-08 11:35:11 +00:00
|
|
|
sctp_send_initiate(inp, stcb, SCTP_SO_LOCKED);
|
2006-11-03 15:23:16 +00:00
|
|
|
} else {
|
|
|
|
/*
|
|
|
|
* already expired or did not use delayed
|
|
|
|
* connectx
|
|
|
|
*/
|
2007-08-24 00:53:53 +00:00
|
|
|
SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EALREADY);
|
2006-11-03 15:23:16 +00:00
|
|
|
error = EALREADY;
|
|
|
|
}
|
|
|
|
SCTP_TCB_UNLOCK(stcb);
|
|
|
|
}
|
|
|
|
break;
|
2007-05-28 11:17:24 +00:00
|
|
|
case SCTP_MAX_BURST:
|
2006-11-03 15:23:16 +00:00
|
|
|
{
|
2011-01-26 19:55:54 +00:00
|
|
|
struct sctp_assoc_value *av;
|
2006-11-03 15:23:16 +00:00
|
|
|
|
2011-01-26 19:55:54 +00:00
|
|
|
SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
|
|
|
|
SCTP_FIND_STCB(inp, stcb, av->assoc_id);
|
2007-02-12 23:24:31 +00:00
|
|
|
|
2011-01-26 19:55:54 +00:00
|
|
|
if (stcb) {
|
|
|
|
stcb->asoc.max_burst = av->assoc_value;
|
|
|
|
SCTP_TCB_UNLOCK(stcb);
|
|
|
|
} else {
|
|
|
|
SCTP_INP_WLOCK(inp);
|
|
|
|
inp->sctp_ep.max_burst = av->assoc_value;
|
|
|
|
SCTP_INP_WUNLOCK(inp);
|
|
|
|
}
|
2006-11-03 15:23:16 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case SCTP_MAXSEG:
|
|
|
|
{
|
2007-03-15 11:27:14 +00:00
|
|
|
struct sctp_assoc_value *av;
|
2006-11-03 15:23:16 +00:00
|
|
|
int ovh;
|
|
|
|
|
2007-03-15 11:27:14 +00:00
|
|
|
SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
|
|
|
|
SCTP_FIND_STCB(inp, stcb, av->assoc_id);
|
2007-02-12 23:24:31 +00:00
|
|
|
|
2007-05-28 11:17:24 +00:00
|
|
|
if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) {
|
|
|
|
ovh = SCTP_MED_OVERHEAD;
|
|
|
|
} else {
|
|
|
|
ovh = SCTP_MED_V4_OVERHEAD;
|
|
|
|
}
|
2007-03-15 11:27:14 +00:00
|
|
|
if (stcb) {
|
2007-05-28 11:17:24 +00:00
|
|
|
if (av->assoc_value) {
|
|
|
|
stcb->asoc.sctp_frag_point = (av->assoc_value + ovh);
|
|
|
|
} else {
|
|
|
|
stcb->asoc.sctp_frag_point = SCTP_DEFAULT_MAXSEGMENT;
|
|
|
|
}
|
2007-03-15 11:27:14 +00:00
|
|
|
SCTP_TCB_UNLOCK(stcb);
|
|
|
|
} else {
|
|
|
|
SCTP_INP_WLOCK(inp);
|
|
|
|
/*
|
|
|
|
* FIXME MT: I think this is not in tune
|
|
|
|
* with the API ID
|
|
|
|
*/
|
|
|
|
if (av->assoc_value) {
|
|
|
|
inp->sctp_frag_point = (av->assoc_value + ovh);
|
|
|
|
} else {
|
2007-05-28 11:17:24 +00:00
|
|
|
inp->sctp_frag_point = SCTP_DEFAULT_MAXSEGMENT;
|
2007-03-15 11:27:14 +00:00
|
|
|
}
|
|
|
|
SCTP_INP_WUNLOCK(inp);
|
2006-11-03 15:23:16 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case SCTP_EVENTS:
|
|
|
|
{
|
|
|
|
struct sctp_event_subscribe *events;
|
|
|
|
|
2007-02-12 23:24:31 +00:00
|
|
|
SCTP_CHECK_AND_CAST(events, optval, struct sctp_event_subscribe, optsize);
|
|
|
|
|
2006-11-03 15:23:16 +00:00
|
|
|
SCTP_INP_WLOCK(inp);
|
|
|
|
if (events->sctp_data_io_event) {
|
|
|
|
sctp_feature_on(inp, SCTP_PCB_FLAGS_RECVDATAIOEVNT);
|
|
|
|
} else {
|
|
|
|
sctp_feature_off(inp, SCTP_PCB_FLAGS_RECVDATAIOEVNT);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (events->sctp_association_event) {
|
|
|
|
sctp_feature_on(inp, SCTP_PCB_FLAGS_RECVASSOCEVNT);
|
|
|
|
} else {
|
|
|
|
sctp_feature_off(inp, SCTP_PCB_FLAGS_RECVASSOCEVNT);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (events->sctp_address_event) {
|
|
|
|
sctp_feature_on(inp, SCTP_PCB_FLAGS_RECVPADDREVNT);
|
|
|
|
} else {
|
|
|
|
sctp_feature_off(inp, SCTP_PCB_FLAGS_RECVPADDREVNT);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (events->sctp_send_failure_event) {
|
|
|
|
sctp_feature_on(inp, SCTP_PCB_FLAGS_RECVSENDFAILEVNT);
|
|
|
|
} else {
|
|
|
|
sctp_feature_off(inp, SCTP_PCB_FLAGS_RECVSENDFAILEVNT);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (events->sctp_peer_error_event) {
|
|
|
|
sctp_feature_on(inp, SCTP_PCB_FLAGS_RECVPEERERR);
|
|
|
|
} else {
|
|
|
|
sctp_feature_off(inp, SCTP_PCB_FLAGS_RECVPEERERR);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (events->sctp_shutdown_event) {
|
|
|
|
sctp_feature_on(inp, SCTP_PCB_FLAGS_RECVSHUTDOWNEVNT);
|
|
|
|
} else {
|
|
|
|
sctp_feature_off(inp, SCTP_PCB_FLAGS_RECVSHUTDOWNEVNT);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (events->sctp_partial_delivery_event) {
|
|
|
|
sctp_feature_on(inp, SCTP_PCB_FLAGS_PDAPIEVNT);
|
|
|
|
} else {
|
|
|
|
sctp_feature_off(inp, SCTP_PCB_FLAGS_PDAPIEVNT);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (events->sctp_adaptation_layer_event) {
|
|
|
|
sctp_feature_on(inp, SCTP_PCB_FLAGS_ADAPTATIONEVNT);
|
|
|
|
} else {
|
|
|
|
sctp_feature_off(inp, SCTP_PCB_FLAGS_ADAPTATIONEVNT);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (events->sctp_authentication_event) {
|
|
|
|
sctp_feature_on(inp, SCTP_PCB_FLAGS_AUTHEVNT);
|
|
|
|
} else {
|
|
|
|
sctp_feature_off(inp, SCTP_PCB_FLAGS_AUTHEVNT);
|
|
|
|
}
|
|
|
|
|
2008-12-06 13:19:54 +00:00
|
|
|
if (events->sctp_sender_dry_event) {
|
|
|
|
sctp_feature_on(inp, SCTP_PCB_FLAGS_DRYEVNT);
|
2009-02-03 11:04:03 +00:00
|
|
|
if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
|
|
|
|
(inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL)) {
|
|
|
|
stcb = LIST_FIRST(&inp->sctp_asoc_list);
|
|
|
|
if (stcb) {
|
|
|
|
SCTP_TCB_LOCK(stcb);
|
|
|
|
}
|
|
|
|
if (stcb &&
|
|
|
|
TAILQ_EMPTY(&stcb->asoc.send_queue) &&
|
|
|
|
TAILQ_EMPTY(&stcb->asoc.sent_queue) &&
|
|
|
|
(stcb->asoc.stream_queue_cnt == 0)) {
|
|
|
|
sctp_ulp_notify(SCTP_NOTIFY_SENDER_DRY, stcb, 0, NULL, SCTP_SO_LOCKED);
|
|
|
|
}
|
|
|
|
if (stcb) {
|
|
|
|
SCTP_TCB_UNLOCK(stcb);
|
|
|
|
}
|
|
|
|
}
|
2008-12-06 13:19:54 +00:00
|
|
|
} else {
|
|
|
|
sctp_feature_off(inp, SCTP_PCB_FLAGS_DRYEVNT);
|
|
|
|
}
|
|
|
|
|
2010-01-17 19:35:38 +00:00
|
|
|
if (events->sctp_stream_reset_event) {
|
2006-11-03 15:23:16 +00:00
|
|
|
sctp_feature_on(inp, SCTP_PCB_FLAGS_STREAM_RESETEVNT);
|
|
|
|
} else {
|
|
|
|
sctp_feature_off(inp, SCTP_PCB_FLAGS_STREAM_RESETEVNT);
|
|
|
|
}
|
|
|
|
SCTP_INP_WUNLOCK(inp);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case SCTP_ADAPTATION_LAYER:
|
|
|
|
{
|
|
|
|
struct sctp_setadaptation *adap_bits;
|
|
|
|
|
2007-02-12 23:24:31 +00:00
|
|
|
SCTP_CHECK_AND_CAST(adap_bits, optval, struct sctp_setadaptation, optsize);
|
2006-11-03 15:23:16 +00:00
|
|
|
SCTP_INP_WLOCK(inp);
|
|
|
|
inp->sctp_ep.adaptation_layer_indicator = adap_bits->ssb_adaptation_ind;
|
|
|
|
SCTP_INP_WUNLOCK(inp);
|
|
|
|
}
|
|
|
|
break;
|
2007-02-12 23:24:31 +00:00
|
|
|
#ifdef SCTP_DEBUG
|
2006-11-03 15:23:16 +00:00
|
|
|
case SCTP_SET_INITIAL_DBG_SEQ:
|
|
|
|
{
|
|
|
|
uint32_t *vvv;
|
|
|
|
|
2007-02-12 23:24:31 +00:00
|
|
|
SCTP_CHECK_AND_CAST(vvv, optval, uint32_t, optsize);
|
2006-11-03 15:23:16 +00:00
|
|
|
SCTP_INP_WLOCK(inp);
|
|
|
|
inp->sctp_ep.initial_sequence_debug = *vvv;
|
|
|
|
SCTP_INP_WUNLOCK(inp);
|
|
|
|
}
|
|
|
|
break;
|
2007-02-12 23:24:31 +00:00
|
|
|
#endif
|
2006-11-03 15:23:16 +00:00
|
|
|
case SCTP_DEFAULT_SEND_PARAM:
|
|
|
|
{
|
|
|
|
struct sctp_sndrcvinfo *s_info;
|
|
|
|
|
2007-02-12 23:24:31 +00:00
|
|
|
SCTP_CHECK_AND_CAST(s_info, optval, struct sctp_sndrcvinfo, optsize);
|
|
|
|
SCTP_FIND_STCB(inp, stcb, s_info->sinfo_assoc_id);
|
2006-11-03 15:23:16 +00:00
|
|
|
|
2007-02-12 23:24:31 +00:00
|
|
|
if (stcb) {
|
|
|
|
if (s_info->sinfo_stream <= stcb->asoc.streamoutcnt) {
|
2007-05-28 11:17:24 +00:00
|
|
|
memcpy(&stcb->asoc.def_send, s_info, min(optsize, sizeof(stcb->asoc.def_send)));
|
2006-11-03 15:23:16 +00:00
|
|
|
} else {
|
2007-08-24 00:53:53 +00:00
|
|
|
SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
|
2007-02-12 23:24:31 +00:00
|
|
|
error = EINVAL;
|
2006-11-03 15:23:16 +00:00
|
|
|
}
|
|
|
|
SCTP_TCB_UNLOCK(stcb);
|
2007-02-12 23:24:31 +00:00
|
|
|
} else {
|
|
|
|
SCTP_INP_WLOCK(inp);
|
2007-05-28 11:17:24 +00:00
|
|
|
memcpy(&inp->def_send, s_info, min(optsize, sizeof(inp->def_send)));
|
2007-02-12 23:24:31 +00:00
|
|
|
SCTP_INP_WUNLOCK(inp);
|
2006-11-03 15:23:16 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case SCTP_PEER_ADDR_PARAMS:
|
|
|
|
/* Applys to the specific association */
|
|
|
|
{
|
|
|
|
struct sctp_paddrparams *paddrp;
|
|
|
|
struct sctp_nets *net;
|
|
|
|
|
2007-02-12 23:24:31 +00:00
|
|
|
SCTP_CHECK_AND_CAST(paddrp, optval, struct sctp_paddrparams, optsize);
|
|
|
|
SCTP_FIND_STCB(inp, stcb, paddrp->spp_assoc_id);
|
2006-11-03 15:23:16 +00:00
|
|
|
net = NULL;
|
2007-02-12 23:24:31 +00:00
|
|
|
if (stcb) {
|
|
|
|
net = sctp_findnet(stcb, (struct sockaddr *)&paddrp->spp_address);
|
|
|
|
} else {
|
|
|
|
/*
|
|
|
|
* We increment here since
|
|
|
|
* sctp_findassociation_ep_addr() wil do a
|
|
|
|
* decrement if it finds the stcb as long as
|
|
|
|
* the locked tcb (last argument) is NOT a
|
|
|
|
* TCB.. aka NULL.
|
|
|
|
*/
|
|
|
|
SCTP_INP_INCR_REF(inp);
|
|
|
|
stcb = sctp_findassociation_ep_addr(&inp,
|
|
|
|
(struct sockaddr *)&paddrp->spp_address,
|
|
|
|
&net, NULL, NULL);
|
2006-11-03 15:23:16 +00:00
|
|
|
if (stcb == NULL) {
|
2007-02-12 23:24:31 +00:00
|
|
|
SCTP_INP_DECR_REF(inp);
|
2006-11-03 15:23:16 +00:00
|
|
|
}
|
|
|
|
}
|
2007-08-24 00:53:53 +00:00
|
|
|
if (stcb && (net == NULL)) {
|
|
|
|
struct sockaddr *sa;
|
|
|
|
|
|
|
|
sa = (struct sockaddr *)&paddrp->spp_address;
|
|
|
|
if (sa->sa_family == AF_INET) {
|
|
|
|
struct sockaddr_in *sin;
|
|
|
|
|
|
|
|
sin = (struct sockaddr_in *)sa;
|
|
|
|
if (sin->sin_addr.s_addr) {
|
|
|
|
SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
|
|
|
|
SCTP_TCB_UNLOCK(stcb);
|
|
|
|
error = EINVAL;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
} else if (sa->sa_family == AF_INET6) {
|
|
|
|
struct sockaddr_in6 *sin6;
|
|
|
|
|
|
|
|
sin6 = (struct sockaddr_in6 *)sa;
|
|
|
|
if (!IN6_IS_ADDR_UNSPECIFIED(&sin6->sin6_addr)) {
|
|
|
|
SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
|
|
|
|
SCTP_TCB_UNLOCK(stcb);
|
|
|
|
error = EINVAL;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
error = EAFNOSUPPORT;
|
|
|
|
SCTP_TCB_UNLOCK(stcb);
|
|
|
|
SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2007-05-28 11:17:24 +00:00
|
|
|
/* sanity checks */
|
|
|
|
if ((paddrp->spp_flags & SPP_HB_ENABLE) && (paddrp->spp_flags & SPP_HB_DISABLE)) {
|
|
|
|
if (stcb)
|
|
|
|
SCTP_TCB_UNLOCK(stcb);
|
2007-08-24 00:53:53 +00:00
|
|
|
SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
|
2007-05-28 11:17:24 +00:00
|
|
|
return (EINVAL);
|
|
|
|
}
|
|
|
|
if ((paddrp->spp_flags & SPP_PMTUD_ENABLE) && (paddrp->spp_flags & SPP_PMTUD_DISABLE)) {
|
|
|
|
if (stcb)
|
|
|
|
SCTP_TCB_UNLOCK(stcb);
|
2007-08-24 00:53:53 +00:00
|
|
|
SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
|
2007-05-28 11:17:24 +00:00
|
|
|
return (EINVAL);
|
|
|
|
}
|
2006-11-03 15:23:16 +00:00
|
|
|
if (stcb) {
|
|
|
|
/************************TCB SPECIFIC SET ******************/
|
|
|
|
/*
|
|
|
|
* do we change the timer for HB, we run
|
|
|
|
* only one?
|
|
|
|
*/
|
2007-05-28 11:17:24 +00:00
|
|
|
int ovh = 0;
|
|
|
|
|
|
|
|
if (stcb->sctp_ep->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) {
|
|
|
|
ovh = SCTP_MED_OVERHEAD;
|
|
|
|
} else {
|
|
|
|
ovh = SCTP_MED_V4_OVERHEAD;
|
|
|
|
}
|
|
|
|
|
2006-11-03 15:23:16 +00:00
|
|
|
if (paddrp->spp_hbinterval)
|
|
|
|
stcb->asoc.heart_beat_delay = paddrp->spp_hbinterval;
|
|
|
|
else if (paddrp->spp_flags & SPP_HB_TIME_IS_ZERO)
|
|
|
|
stcb->asoc.heart_beat_delay = 0;
|
|
|
|
|
|
|
|
/* network sets ? */
|
|
|
|
if (net) {
|
|
|
|
/************************NET SPECIFIC SET ******************/
|
|
|
|
if (paddrp->spp_flags & SPP_HB_DEMAND) {
|
|
|
|
/* on demand HB */
|
2007-07-14 09:36:28 +00:00
|
|
|
if (sctp_send_hb(stcb, 1, net) < 0) {
|
|
|
|
/* asoc destroyed */
|
2007-08-24 00:53:53 +00:00
|
|
|
SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
|
2007-07-14 09:36:28 +00:00
|
|
|
error = EINVAL;
|
|
|
|
break;
|
|
|
|
}
|
2006-11-03 15:23:16 +00:00
|
|
|
}
|
|
|
|
if (paddrp->spp_flags & SPP_HB_DISABLE) {
|
|
|
|
net->dest_state |= SCTP_ADDR_NOHB;
|
|
|
|
}
|
|
|
|
if (paddrp->spp_flags & SPP_HB_ENABLE) {
|
|
|
|
net->dest_state &= ~SCTP_ADDR_NOHB;
|
|
|
|
}
|
2007-05-28 11:17:24 +00:00
|
|
|
if ((paddrp->spp_flags & SPP_PMTUD_DISABLE) && (paddrp->spp_pathmtu >= SCTP_SMALLEST_PMTU)) {
|
2006-12-29 20:21:42 +00:00
|
|
|
if (SCTP_OS_TIMER_PENDING(&net->pmtu_timer.timer)) {
|
2006-12-14 17:02:55 +00:00
|
|
|
sctp_timer_stop(SCTP_TIMER_TYPE_PATHMTURAISE, inp, stcb, net,
|
|
|
|
SCTP_FROM_SCTP_USRREQ + SCTP_LOC_10);
|
2006-11-03 15:23:16 +00:00
|
|
|
}
|
|
|
|
if (paddrp->spp_pathmtu > SCTP_DEFAULT_MINSEGMENT) {
|
2007-05-28 11:17:24 +00:00
|
|
|
net->mtu = paddrp->spp_pathmtu + ovh;
|
2007-05-08 00:21:05 +00:00
|
|
|
if (net->mtu < stcb->asoc.smallest_mtu) {
|
2007-03-19 06:53:02 +00:00
|
|
|
sctp_pathmtu_adjustment(inp, stcb, net, net->mtu);
|
2007-05-08 00:21:05 +00:00
|
|
|
}
|
2006-11-03 15:23:16 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
if (paddrp->spp_flags & SPP_PMTUD_ENABLE) {
|
2006-12-29 20:21:42 +00:00
|
|
|
if (SCTP_OS_TIMER_PENDING(&net->pmtu_timer.timer)) {
|
2006-11-03 15:23:16 +00:00
|
|
|
sctp_timer_start(SCTP_TIMER_TYPE_PATHMTURAISE, inp, stcb, net);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (paddrp->spp_pathmaxrxt)
|
|
|
|
net->failure_threshold = paddrp->spp_pathmaxrxt;
|
2007-03-15 11:27:14 +00:00
|
|
|
#ifdef INET
|
2006-11-03 15:23:16 +00:00
|
|
|
if (paddrp->spp_flags & SPP_IPV4_TOS) {
|
|
|
|
if (net->ro._l_addr.sin.sin_family == AF_INET) {
|
|
|
|
net->tos_flowlabel = paddrp->spp_ipv4_tos & 0x000000fc;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
2007-03-15 11:27:14 +00:00
|
|
|
#ifdef INET6
|
2006-11-03 15:23:16 +00:00
|
|
|
if (paddrp->spp_flags & SPP_IPV6_FLOWLABEL) {
|
|
|
|
if (net->ro._l_addr.sin6.sin6_family == AF_INET6) {
|
|
|
|
net->tos_flowlabel = paddrp->spp_ipv6_flowlabel;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
} else {
|
|
|
|
/************************ASSOC ONLY -- NO NET SPECIFIC SET ******************/
|
|
|
|
if (paddrp->spp_pathmaxrxt)
|
|
|
|
stcb->asoc.def_net_failure = paddrp->spp_pathmaxrxt;
|
|
|
|
|
|
|
|
if (paddrp->spp_flags & SPP_HB_ENABLE) {
|
|
|
|
/* Turn back on the timer */
|
|
|
|
stcb->asoc.hb_is_disabled = 0;
|
|
|
|
sctp_timer_start(SCTP_TIMER_TYPE_HEARTBEAT, inp, stcb, net);
|
|
|
|
}
|
2007-05-28 11:17:24 +00:00
|
|
|
if ((paddrp->spp_flags & SPP_PMTUD_DISABLE) && (paddrp->spp_pathmtu >= SCTP_SMALLEST_PMTU)) {
|
|
|
|
TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
|
|
|
|
if (SCTP_OS_TIMER_PENDING(&net->pmtu_timer.timer)) {
|
|
|
|
sctp_timer_stop(SCTP_TIMER_TYPE_PATHMTURAISE, inp, stcb, net,
|
|
|
|
SCTP_FROM_SCTP_USRREQ + SCTP_LOC_10);
|
|
|
|
}
|
|
|
|
if (paddrp->spp_pathmtu > SCTP_DEFAULT_MINSEGMENT) {
|
|
|
|
net->mtu = paddrp->spp_pathmtu + ovh;
|
|
|
|
if (net->mtu < stcb->asoc.smallest_mtu) {
|
|
|
|
sctp_pathmtu_adjustment(inp, stcb, net, net->mtu);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (paddrp->spp_flags & SPP_PMTUD_ENABLE) {
|
|
|
|
TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
|
|
|
|
if (SCTP_OS_TIMER_PENDING(&net->pmtu_timer.timer)) {
|
|
|
|
sctp_timer_start(SCTP_TIMER_TYPE_PATHMTURAISE, inp, stcb, net);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2006-11-03 15:23:16 +00:00
|
|
|
if (paddrp->spp_flags & SPP_HB_DISABLE) {
|
|
|
|
int cnt_of_unconf = 0;
|
|
|
|
struct sctp_nets *lnet;
|
|
|
|
|
|
|
|
stcb->asoc.hb_is_disabled = 1;
|
|
|
|
TAILQ_FOREACH(lnet, &stcb->asoc.nets, sctp_next) {
|
|
|
|
if (lnet->dest_state & SCTP_ADDR_UNCONFIRMED) {
|
|
|
|
cnt_of_unconf++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
/*
|
|
|
|
* stop the timer ONLY if we
|
|
|
|
* have no unconfirmed
|
|
|
|
* addresses
|
|
|
|
*/
|
|
|
|
if (cnt_of_unconf == 0) {
|
2007-05-28 11:17:24 +00:00
|
|
|
TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
|
|
|
|
sctp_timer_stop(SCTP_TIMER_TYPE_HEARTBEAT, inp, stcb, net,
|
|
|
|
SCTP_FROM_SCTP_USRREQ + SCTP_LOC_11);
|
|
|
|
}
|
2006-11-03 15:23:16 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
if (paddrp->spp_flags & SPP_HB_ENABLE) {
|
|
|
|
/* start up the timer. */
|
2007-05-28 11:17:24 +00:00
|
|
|
TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
|
|
|
|
sctp_timer_start(SCTP_TIMER_TYPE_HEARTBEAT, inp, stcb, net);
|
|
|
|
}
|
2006-11-03 15:23:16 +00:00
|
|
|
}
|
2007-03-15 11:27:14 +00:00
|
|
|
#ifdef INET
|
2006-11-03 15:23:16 +00:00
|
|
|
if (paddrp->spp_flags & SPP_IPV4_TOS)
|
|
|
|
stcb->asoc.default_tos = paddrp->spp_ipv4_tos & 0x000000fc;
|
|
|
|
#endif
|
2007-03-15 11:27:14 +00:00
|
|
|
#ifdef INET6
|
2006-11-03 15:23:16 +00:00
|
|
|
if (paddrp->spp_flags & SPP_IPV6_FLOWLABEL)
|
|
|
|
stcb->asoc.default_flowlabel = paddrp->spp_ipv6_flowlabel;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
}
|
|
|
|
SCTP_TCB_UNLOCK(stcb);
|
|
|
|
} else {
|
|
|
|
/************************NO TCB, SET TO default stuff ******************/
|
|
|
|
SCTP_INP_WLOCK(inp);
|
|
|
|
/*
|
|
|
|
* For the TOS/FLOWLABEL stuff you set it
|
|
|
|
* with the options on the socket
|
|
|
|
*/
|
|
|
|
if (paddrp->spp_pathmaxrxt) {
|
|
|
|
inp->sctp_ep.def_net_failure = paddrp->spp_pathmaxrxt;
|
|
|
|
}
|
2007-05-28 11:17:24 +00:00
|
|
|
if (paddrp->spp_flags & SPP_HB_TIME_IS_ZERO)
|
|
|
|
inp->sctp_ep.sctp_timeoutticks[SCTP_TIMER_HEARTBEAT] = 0;
|
2007-07-17 20:58:26 +00:00
|
|
|
else if (paddrp->spp_hbinterval) {
|
|
|
|
if (paddrp->spp_hbinterval > SCTP_MAX_HB_INTERVAL)
|
|
|
|
paddrp->spp_hbinterval = SCTP_MAX_HB_INTERVAL;
|
2006-11-03 15:23:16 +00:00
|
|
|
inp->sctp_ep.sctp_timeoutticks[SCTP_TIMER_HEARTBEAT] = MSEC_TO_TICKS(paddrp->spp_hbinterval);
|
2007-07-17 20:58:26 +00:00
|
|
|
}
|
2007-05-28 11:17:24 +00:00
|
|
|
if (paddrp->spp_flags & SPP_HB_ENABLE) {
|
2006-11-03 15:23:16 +00:00
|
|
|
sctp_feature_off(inp, SCTP_PCB_FLAGS_DONOT_HEARTBEAT);
|
2007-05-28 11:17:24 +00:00
|
|
|
|
2006-11-03 15:23:16 +00:00
|
|
|
} else if (paddrp->spp_flags & SPP_HB_DISABLE) {
|
|
|
|
sctp_feature_on(inp, SCTP_PCB_FLAGS_DONOT_HEARTBEAT);
|
|
|
|
}
|
|
|
|
SCTP_INP_WUNLOCK(inp);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case SCTP_RTOINFO:
|
|
|
|
{
|
|
|
|
struct sctp_rtoinfo *srto;
|
2007-05-17 12:16:24 +00:00
|
|
|
uint32_t new_init, new_min, new_max;
|
2006-11-03 15:23:16 +00:00
|
|
|
|
2007-02-12 23:24:31 +00:00
|
|
|
SCTP_CHECK_AND_CAST(srto, optval, struct sctp_rtoinfo, optsize);
|
|
|
|
SCTP_FIND_STCB(inp, stcb, srto->srto_assoc_id);
|
|
|
|
|
|
|
|
if (stcb) {
|
2007-03-15 11:27:14 +00:00
|
|
|
if (srto->srto_initial)
|
2007-05-17 12:16:24 +00:00
|
|
|
new_init = srto->srto_initial;
|
|
|
|
else
|
|
|
|
new_init = stcb->asoc.initial_rto;
|
2007-03-15 11:27:14 +00:00
|
|
|
if (srto->srto_max)
|
2007-05-17 12:16:24 +00:00
|
|
|
new_max = srto->srto_max;
|
|
|
|
else
|
|
|
|
new_max = stcb->asoc.maxrto;
|
2007-03-15 11:27:14 +00:00
|
|
|
if (srto->srto_min)
|
2007-05-17 12:16:24 +00:00
|
|
|
new_min = srto->srto_min;
|
|
|
|
else
|
|
|
|
new_min = stcb->asoc.minrto;
|
|
|
|
if ((new_min <= new_init) && (new_init <= new_max)) {
|
|
|
|
stcb->asoc.initial_rto = new_init;
|
|
|
|
stcb->asoc.maxrto = new_max;
|
|
|
|
stcb->asoc.minrto = new_min;
|
|
|
|
} else {
|
2008-06-14 07:58:05 +00:00
|
|
|
SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
|
|
|
|
error = EINVAL;
|
2007-05-17 12:16:24 +00:00
|
|
|
}
|
2007-02-12 23:24:31 +00:00
|
|
|
SCTP_TCB_UNLOCK(stcb);
|
|
|
|
} else {
|
2006-11-03 15:23:16 +00:00
|
|
|
SCTP_INP_WLOCK(inp);
|
2007-03-15 11:27:14 +00:00
|
|
|
if (srto->srto_initial)
|
2007-05-17 12:16:24 +00:00
|
|
|
new_init = srto->srto_initial;
|
|
|
|
else
|
|
|
|
new_init = inp->sctp_ep.initial_rto;
|
2007-03-15 11:27:14 +00:00
|
|
|
if (srto->srto_max)
|
2007-05-17 12:16:24 +00:00
|
|
|
new_max = srto->srto_max;
|
|
|
|
else
|
|
|
|
new_max = inp->sctp_ep.sctp_maxrto;
|
2007-03-15 11:27:14 +00:00
|
|
|
if (srto->srto_min)
|
2007-05-17 12:16:24 +00:00
|
|
|
new_min = srto->srto_min;
|
|
|
|
else
|
|
|
|
new_min = inp->sctp_ep.sctp_minrto;
|
|
|
|
if ((new_min <= new_init) && (new_init <= new_max)) {
|
|
|
|
inp->sctp_ep.initial_rto = new_init;
|
|
|
|
inp->sctp_ep.sctp_maxrto = new_max;
|
|
|
|
inp->sctp_ep.sctp_minrto = new_min;
|
|
|
|
} else {
|
2008-06-14 07:58:05 +00:00
|
|
|
SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
|
|
|
|
error = EINVAL;
|
2007-05-17 12:16:24 +00:00
|
|
|
}
|
2006-11-03 15:23:16 +00:00
|
|
|
SCTP_INP_WUNLOCK(inp);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case SCTP_ASSOCINFO:
|
|
|
|
{
|
|
|
|
struct sctp_assocparams *sasoc;
|
|
|
|
|
2007-02-12 23:24:31 +00:00
|
|
|
SCTP_CHECK_AND_CAST(sasoc, optval, struct sctp_assocparams, optsize);
|
|
|
|
SCTP_FIND_STCB(inp, stcb, sasoc->sasoc_assoc_id);
|
2007-07-17 20:58:26 +00:00
|
|
|
if (sasoc->sasoc_cookie_life) {
|
|
|
|
/* boundary check the cookie life */
|
|
|
|
if (sasoc->sasoc_cookie_life < 1000)
|
|
|
|
sasoc->sasoc_cookie_life = 1000;
|
|
|
|
if (sasoc->sasoc_cookie_life > SCTP_MAX_COOKIE_LIFE) {
|
|
|
|
sasoc->sasoc_cookie_life = SCTP_MAX_COOKIE_LIFE;
|
|
|
|
}
|
|
|
|
}
|
2006-11-03 15:23:16 +00:00
|
|
|
if (stcb) {
|
|
|
|
if (sasoc->sasoc_asocmaxrxt)
|
|
|
|
stcb->asoc.max_send_times = sasoc->sasoc_asocmaxrxt;
|
|
|
|
sasoc->sasoc_number_peer_destinations = stcb->asoc.numnets;
|
|
|
|
sasoc->sasoc_peer_rwnd = 0;
|
|
|
|
sasoc->sasoc_local_rwnd = 0;
|
2007-05-28 11:17:24 +00:00
|
|
|
if (sasoc->sasoc_cookie_life) {
|
2007-07-24 20:06:02 +00:00
|
|
|
stcb->asoc.cookie_life = MSEC_TO_TICKS(sasoc->sasoc_cookie_life);
|
2007-03-15 11:27:14 +00:00
|
|
|
}
|
2006-11-03 15:23:16 +00:00
|
|
|
SCTP_TCB_UNLOCK(stcb);
|
|
|
|
} else {
|
|
|
|
SCTP_INP_WLOCK(inp);
|
|
|
|
if (sasoc->sasoc_asocmaxrxt)
|
|
|
|
inp->sctp_ep.max_send_times = sasoc->sasoc_asocmaxrxt;
|
|
|
|
sasoc->sasoc_number_peer_destinations = 0;
|
|
|
|
sasoc->sasoc_peer_rwnd = 0;
|
|
|
|
sasoc->sasoc_local_rwnd = 0;
|
2007-05-28 11:17:24 +00:00
|
|
|
if (sasoc->sasoc_cookie_life) {
|
2007-05-17 12:16:24 +00:00
|
|
|
inp->sctp_ep.def_cookie_life = MSEC_TO_TICKS(sasoc->sasoc_cookie_life);
|
2007-03-15 11:27:14 +00:00
|
|
|
}
|
2006-11-03 15:23:16 +00:00
|
|
|
SCTP_INP_WUNLOCK(inp);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case SCTP_INITMSG:
|
|
|
|
{
|
|
|
|
struct sctp_initmsg *sinit;
|
|
|
|
|
2007-02-12 23:24:31 +00:00
|
|
|
SCTP_CHECK_AND_CAST(sinit, optval, struct sctp_initmsg, optsize);
|
2006-11-03 15:23:16 +00:00
|
|
|
SCTP_INP_WLOCK(inp);
|
|
|
|
if (sinit->sinit_num_ostreams)
|
|
|
|
inp->sctp_ep.pre_open_stream_count = sinit->sinit_num_ostreams;
|
|
|
|
|
|
|
|
if (sinit->sinit_max_instreams)
|
|
|
|
inp->sctp_ep.max_open_streams_intome = sinit->sinit_max_instreams;
|
|
|
|
|
|
|
|
if (sinit->sinit_max_attempts)
|
|
|
|
inp->sctp_ep.max_init_times = sinit->sinit_max_attempts;
|
|
|
|
|
2007-03-15 11:27:14 +00:00
|
|
|
if (sinit->sinit_max_init_timeo)
|
2006-11-03 15:23:16 +00:00
|
|
|
inp->sctp_ep.initial_init_rto_max = sinit->sinit_max_init_timeo;
|
|
|
|
SCTP_INP_WUNLOCK(inp);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case SCTP_PRIMARY_ADDR:
|
|
|
|
{
|
|
|
|
struct sctp_setprim *spa;
|
|
|
|
struct sctp_nets *net, *lnet;
|
|
|
|
|
2007-02-12 23:24:31 +00:00
|
|
|
SCTP_CHECK_AND_CAST(spa, optval, struct sctp_setprim, optsize);
|
|
|
|
SCTP_FIND_STCB(inp, stcb, spa->ssp_assoc_id);
|
2006-11-03 15:23:16 +00:00
|
|
|
|
2007-02-12 23:24:31 +00:00
|
|
|
net = NULL;
|
|
|
|
if (stcb) {
|
|
|
|
net = sctp_findnet(stcb, (struct sockaddr *)&spa->ssp_addr);
|
|
|
|
} else {
|
|
|
|
/*
|
|
|
|
* We increment here since
|
|
|
|
* sctp_findassociation_ep_addr() wil do a
|
|
|
|
* decrement if it finds the stcb as long as
|
|
|
|
* the locked tcb (last argument) is NOT a
|
|
|
|
* TCB.. aka NULL.
|
|
|
|
*/
|
2006-11-03 15:23:16 +00:00
|
|
|
SCTP_INP_INCR_REF(inp);
|
|
|
|
stcb = sctp_findassociation_ep_addr(&inp,
|
|
|
|
(struct sockaddr *)&spa->ssp_addr,
|
|
|
|
&net, NULL, NULL);
|
|
|
|
if (stcb == NULL) {
|
|
|
|
SCTP_INP_DECR_REF(inp);
|
|
|
|
}
|
|
|
|
}
|
2007-02-12 23:24:31 +00:00
|
|
|
|
|
|
|
if ((stcb) && (net)) {
|
|
|
|
if ((net != stcb->asoc.primary_destination) &&
|
|
|
|
(!(net->dest_state & SCTP_ADDR_UNCONFIRMED))) {
|
|
|
|
/* Ok we need to set it */
|
|
|
|
lnet = stcb->asoc.primary_destination;
|
|
|
|
if (sctp_set_primary_addr(stcb, (struct sockaddr *)NULL, net) == 0) {
|
|
|
|
if (net->dest_state & SCTP_ADDR_SWITCH_PRIMARY) {
|
|
|
|
net->dest_state |= SCTP_ADDR_DOUBLE_SWITCH;
|
|
|
|
}
|
|
|
|
net->dest_state |= SCTP_ADDR_SWITCH_PRIMARY;
|
2006-11-03 15:23:16 +00:00
|
|
|
}
|
|
|
|
}
|
2007-02-12 23:24:31 +00:00
|
|
|
} else {
|
2007-08-24 00:53:53 +00:00
|
|
|
SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
|
2007-02-12 23:24:31 +00:00
|
|
|
error = EINVAL;
|
|
|
|
}
|
|
|
|
if (stcb) {
|
|
|
|
SCTP_TCB_UNLOCK(stcb);
|
2006-11-03 15:23:16 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
2007-03-15 11:27:14 +00:00
|
|
|
case SCTP_SET_DYNAMIC_PRIMARY:
|
|
|
|
{
|
|
|
|
union sctp_sockstore *ss;
|
|
|
|
|
2007-06-12 00:12:01 +00:00
|
|
|
error = priv_check(curthread,
|
|
|
|
PRIV_NETINET_RESERVEDPORT);
|
2007-03-15 11:27:14 +00:00
|
|
|
if (error)
|
|
|
|
break;
|
2006-11-03 15:23:16 +00:00
|
|
|
|
2007-03-15 11:27:14 +00:00
|
|
|
SCTP_CHECK_AND_CAST(ss, optval, union sctp_sockstore, optsize);
|
|
|
|
/* SUPER USER CHECK? */
|
|
|
|
error = sctp_dynamic_set_primary(&ss->sa, vrf_id);
|
|
|
|
}
|
|
|
|
break;
|
2006-11-03 15:23:16 +00:00
|
|
|
case SCTP_SET_PEER_PRIMARY_ADDR:
|
|
|
|
{
|
|
|
|
struct sctp_setpeerprim *sspp;
|
|
|
|
|
2007-02-12 23:24:31 +00:00
|
|
|
SCTP_CHECK_AND_CAST(sspp, optval, struct sctp_setpeerprim, optsize);
|
|
|
|
SCTP_FIND_STCB(inp, stcb, sspp->sspp_assoc_id);
|
2007-05-02 12:50:13 +00:00
|
|
|
if (stcb != NULL) {
|
2007-05-28 11:17:24 +00:00
|
|
|
struct sctp_ifa *ifa;
|
|
|
|
|
|
|
|
ifa = sctp_find_ifa_by_addr((struct sockaddr *)&sspp->sspp_addr,
|
2007-09-08 17:48:46 +00:00
|
|
|
stcb->asoc.vrf_id, SCTP_ADDR_NOT_LOCKED);
|
2007-05-28 11:17:24 +00:00
|
|
|
if (ifa == NULL) {
|
2007-08-24 00:53:53 +00:00
|
|
|
SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
|
2007-05-28 11:17:24 +00:00
|
|
|
error = EINVAL;
|
|
|
|
goto out_of_it;
|
|
|
|
}
|
|
|
|
if ((inp->sctp_flags & SCTP_PCB_FLAGS_BOUNDALL) == 0) {
|
|
|
|
/*
|
|
|
|
* Must validate the ifa found is in
|
|
|
|
* our ep
|
|
|
|
*/
|
|
|
|
struct sctp_laddr *laddr;
|
|
|
|
int found = 0;
|
|
|
|
|
|
|
|
LIST_FOREACH(laddr, &inp->sctp_addr_list, sctp_nxt_addr) {
|
|
|
|
if (laddr->ifa == NULL) {
|
|
|
|
SCTPDBG(SCTP_DEBUG_OUTPUT1, "%s: NULL ifa\n",
|
|
|
|
__FUNCTION__);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (laddr->ifa == ifa) {
|
|
|
|
found = 1;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!found) {
|
2007-08-24 00:53:53 +00:00
|
|
|
SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
|
2007-05-28 11:17:24 +00:00
|
|
|
error = EINVAL;
|
|
|
|
goto out_of_it;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (sctp_set_primary_ip_address_sa(stcb,
|
|
|
|
(struct sockaddr *)&sspp->sspp_addr) != 0) {
|
2007-08-24 00:53:53 +00:00
|
|
|
SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
|
2007-02-12 23:24:31 +00:00
|
|
|
error = EINVAL;
|
|
|
|
}
|
2007-05-28 11:17:24 +00:00
|
|
|
out_of_it:
|
2007-05-02 12:50:13 +00:00
|
|
|
SCTP_TCB_UNLOCK(stcb);
|
2007-02-12 23:24:31 +00:00
|
|
|
} else {
|
2007-08-24 00:53:53 +00:00
|
|
|
SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
|
2006-11-03 15:23:16 +00:00
|
|
|
error = EINVAL;
|
|
|
|
}
|
2007-05-02 12:50:13 +00:00
|
|
|
|
2006-11-03 15:23:16 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case SCTP_BINDX_ADD_ADDR:
|
|
|
|
{
|
|
|
|
struct sctp_getaddresses *addrs;
|
2007-07-21 21:41:32 +00:00
|
|
|
size_t sz;
|
2007-07-17 20:58:26 +00:00
|
|
|
struct thread *td;
|
2006-11-03 15:23:16 +00:00
|
|
|
|
2007-07-17 20:58:26 +00:00
|
|
|
td = (struct thread *)p;
|
2007-06-12 11:21:00 +00:00
|
|
|
SCTP_CHECK_AND_CAST(addrs, optval, struct sctp_getaddresses,
|
|
|
|
optsize);
|
2007-07-17 20:58:26 +00:00
|
|
|
if (addrs->addr->sa_family == AF_INET) {
|
|
|
|
sz = sizeof(struct sctp_getaddresses) - sizeof(struct sockaddr) + sizeof(struct sockaddr_in);
|
|
|
|
if (optsize < sz) {
|
2007-08-24 00:53:53 +00:00
|
|
|
SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
|
2007-07-17 20:58:26 +00:00
|
|
|
error = EINVAL;
|
|
|
|
break;
|
|
|
|
}
|
2009-02-13 18:44:30 +00:00
|
|
|
if (td != NULL && (error = prison_local_ip4(td->td_ucred, &(((struct sockaddr_in *)(addrs->addr))->sin_addr)))) {
|
|
|
|
SCTP_LTRACE_ERR_RET(inp, stcb, NULL, SCTP_FROM_SCTP_USRREQ, error);
|
MFp4:
Bring in updated jail support from bz_jail branch.
This enhances the current jail implementation to permit multiple
addresses per jail. In addtion to IPv4, IPv6 is supported as well.
Due to updated checks it is even possible to have jails without
an IP address at all, which basically gives one a chroot with
restricted process view, no networking,..
SCTP support was updated and supports IPv6 in jails as well.
Cpuset support permits jails to be bound to specific processor
sets after creation.
Jails can have an unrestricted (no duplicate protection, etc.) name
in addition to the hostname. The jail name cannot be changed from
within a jail and is considered to be used for management purposes
or as audit-token in the future.
DDB 'show jails' command was added to aid debugging.
Proper compat support permits 32bit jail binaries to be used on 64bit
systems to manage jails. Also backward compatibility was preserved where
possible: for jail v1 syscalls, as well as with user space management
utilities.
Both jail as well as prison version were updated for the new features.
A gap was intentionally left as the intermediate versions had been
used by various patches floating around the last years.
Bump __FreeBSD_version for the afore mentioned and in kernel changes.
Special thanks to:
- Pawel Jakub Dawidek (pjd) for his multi-IPv4 patches
and Olivier Houchard (cognet) for initial single-IPv6 patches.
- Jeff Roberson (jeff) and Randall Stewart (rrs) for their
help, ideas and review on cpuset and SCTP support.
- Robert Watson (rwatson) for lots and lots of help, discussions,
suggestions and review of most of the patch at various stages.
- John Baldwin (jhb) for his help.
- Simon L. Nielsen (simon) as early adopter testing changes
on cluster machines as well as all the testers and people
who provided feedback the last months on freebsd-jail and
other channels.
- My employer, CK Software GmbH, for the support so I could work on this.
Reviewed by: (see above)
MFC after: 3 months (this is just so that I get the mail)
X-MFC Before: 7.2-RELEASE if possible
2008-11-29 14:32:14 +00:00
|
|
|
break;
|
2007-07-17 20:58:26 +00:00
|
|
|
}
|
MFp4:
Bring in updated jail support from bz_jail branch.
This enhances the current jail implementation to permit multiple
addresses per jail. In addtion to IPv4, IPv6 is supported as well.
Due to updated checks it is even possible to have jails without
an IP address at all, which basically gives one a chroot with
restricted process view, no networking,..
SCTP support was updated and supports IPv6 in jails as well.
Cpuset support permits jails to be bound to specific processor
sets after creation.
Jails can have an unrestricted (no duplicate protection, etc.) name
in addition to the hostname. The jail name cannot be changed from
within a jail and is considered to be used for management purposes
or as audit-token in the future.
DDB 'show jails' command was added to aid debugging.
Proper compat support permits 32bit jail binaries to be used on 64bit
systems to manage jails. Also backward compatibility was preserved where
possible: for jail v1 syscalls, as well as with user space management
utilities.
Both jail as well as prison version were updated for the new features.
A gap was intentionally left as the intermediate versions had been
used by various patches floating around the last years.
Bump __FreeBSD_version for the afore mentioned and in kernel changes.
Special thanks to:
- Pawel Jakub Dawidek (pjd) for his multi-IPv4 patches
and Olivier Houchard (cognet) for initial single-IPv6 patches.
- Jeff Roberson (jeff) and Randall Stewart (rrs) for their
help, ideas and review on cpuset and SCTP support.
- Robert Watson (rwatson) for lots and lots of help, discussions,
suggestions and review of most of the patch at various stages.
- John Baldwin (jhb) for his help.
- Simon L. Nielsen (simon) as early adopter testing changes
on cluster machines as well as all the testers and people
who provided feedback the last months on freebsd-jail and
other channels.
- My employer, CK Software GmbH, for the support so I could work on this.
Reviewed by: (see above)
MFC after: 3 months (this is just so that I get the mail)
X-MFC Before: 7.2-RELEASE if possible
2008-11-29 14:32:14 +00:00
|
|
|
#ifdef INET6
|
2007-07-17 20:58:26 +00:00
|
|
|
} else if (addrs->addr->sa_family == AF_INET6) {
|
|
|
|
sz = sizeof(struct sctp_getaddresses) - sizeof(struct sockaddr) + sizeof(struct sockaddr_in6);
|
|
|
|
if (optsize < sz) {
|
2007-08-24 00:53:53 +00:00
|
|
|
SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
|
2007-07-17 20:58:26 +00:00
|
|
|
error = EINVAL;
|
|
|
|
break;
|
|
|
|
}
|
2009-02-13 18:44:30 +00:00
|
|
|
if (td != NULL && (error = prison_local_ip6(td->td_ucred, &(((struct sockaddr_in6 *)(addrs->addr))->sin6_addr),
|
|
|
|
(SCTP_IPV6_V6ONLY(inp) != 0))) != 0) {
|
|
|
|
SCTP_LTRACE_ERR_RET(inp, stcb, NULL, SCTP_FROM_SCTP_USRREQ, error);
|
MFp4:
Bring in updated jail support from bz_jail branch.
This enhances the current jail implementation to permit multiple
addresses per jail. In addtion to IPv4, IPv6 is supported as well.
Due to updated checks it is even possible to have jails without
an IP address at all, which basically gives one a chroot with
restricted process view, no networking,..
SCTP support was updated and supports IPv6 in jails as well.
Cpuset support permits jails to be bound to specific processor
sets after creation.
Jails can have an unrestricted (no duplicate protection, etc.) name
in addition to the hostname. The jail name cannot be changed from
within a jail and is considered to be used for management purposes
or as audit-token in the future.
DDB 'show jails' command was added to aid debugging.
Proper compat support permits 32bit jail binaries to be used on 64bit
systems to manage jails. Also backward compatibility was preserved where
possible: for jail v1 syscalls, as well as with user space management
utilities.
Both jail as well as prison version were updated for the new features.
A gap was intentionally left as the intermediate versions had been
used by various patches floating around the last years.
Bump __FreeBSD_version for the afore mentioned and in kernel changes.
Special thanks to:
- Pawel Jakub Dawidek (pjd) for his multi-IPv4 patches
and Olivier Houchard (cognet) for initial single-IPv6 patches.
- Jeff Roberson (jeff) and Randall Stewart (rrs) for their
help, ideas and review on cpuset and SCTP support.
- Robert Watson (rwatson) for lots and lots of help, discussions,
suggestions and review of most of the patch at various stages.
- John Baldwin (jhb) for his help.
- Simon L. Nielsen (simon) as early adopter testing changes
on cluster machines as well as all the testers and people
who provided feedback the last months on freebsd-jail and
other channels.
- My employer, CK Software GmbH, for the support so I could work on this.
Reviewed by: (see above)
MFC after: 3 months (this is just so that I get the mail)
X-MFC Before: 7.2-RELEASE if possible
2008-11-29 14:32:14 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
} else {
|
|
|
|
error = EAFNOSUPPORT;
|
|
|
|
break;
|
2007-07-17 20:58:26 +00:00
|
|
|
}
|
2007-06-12 11:21:00 +00:00
|
|
|
sctp_bindx_add_address(so, inp, addrs->addr,
|
|
|
|
addrs->sget_assoc_id, vrf_id,
|
|
|
|
&error, p);
|
2006-11-03 15:23:16 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case SCTP_BINDX_REM_ADDR:
|
|
|
|
{
|
|
|
|
struct sctp_getaddresses *addrs;
|
2007-07-21 21:41:32 +00:00
|
|
|
size_t sz;
|
2007-07-17 20:58:26 +00:00
|
|
|
struct thread *td;
|
2006-11-03 15:23:16 +00:00
|
|
|
|
2007-07-17 20:58:26 +00:00
|
|
|
td = (struct thread *)p;
|
MFp4:
Bring in updated jail support from bz_jail branch.
This enhances the current jail implementation to permit multiple
addresses per jail. In addtion to IPv4, IPv6 is supported as well.
Due to updated checks it is even possible to have jails without
an IP address at all, which basically gives one a chroot with
restricted process view, no networking,..
SCTP support was updated and supports IPv6 in jails as well.
Cpuset support permits jails to be bound to specific processor
sets after creation.
Jails can have an unrestricted (no duplicate protection, etc.) name
in addition to the hostname. The jail name cannot be changed from
within a jail and is considered to be used for management purposes
or as audit-token in the future.
DDB 'show jails' command was added to aid debugging.
Proper compat support permits 32bit jail binaries to be used on 64bit
systems to manage jails. Also backward compatibility was preserved where
possible: for jail v1 syscalls, as well as with user space management
utilities.
Both jail as well as prison version were updated for the new features.
A gap was intentionally left as the intermediate versions had been
used by various patches floating around the last years.
Bump __FreeBSD_version for the afore mentioned and in kernel changes.
Special thanks to:
- Pawel Jakub Dawidek (pjd) for his multi-IPv4 patches
and Olivier Houchard (cognet) for initial single-IPv6 patches.
- Jeff Roberson (jeff) and Randall Stewart (rrs) for their
help, ideas and review on cpuset and SCTP support.
- Robert Watson (rwatson) for lots and lots of help, discussions,
suggestions and review of most of the patch at various stages.
- John Baldwin (jhb) for his help.
- Simon L. Nielsen (simon) as early adopter testing changes
on cluster machines as well as all the testers and people
who provided feedback the last months on freebsd-jail and
other channels.
- My employer, CK Software GmbH, for the support so I could work on this.
Reviewed by: (see above)
MFC after: 3 months (this is just so that I get the mail)
X-MFC Before: 7.2-RELEASE if possible
2008-11-29 14:32:14 +00:00
|
|
|
|
2007-02-12 23:24:31 +00:00
|
|
|
SCTP_CHECK_AND_CAST(addrs, optval, struct sctp_getaddresses, optsize);
|
2007-07-17 20:58:26 +00:00
|
|
|
if (addrs->addr->sa_family == AF_INET) {
|
|
|
|
sz = sizeof(struct sctp_getaddresses) - sizeof(struct sockaddr) + sizeof(struct sockaddr_in);
|
|
|
|
if (optsize < sz) {
|
2007-08-24 00:53:53 +00:00
|
|
|
SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
|
2007-07-17 20:58:26 +00:00
|
|
|
error = EINVAL;
|
|
|
|
break;
|
|
|
|
}
|
2009-02-13 18:44:30 +00:00
|
|
|
if (td != NULL && (error = prison_local_ip4(td->td_ucred, &(((struct sockaddr_in *)(addrs->addr))->sin_addr)))) {
|
|
|
|
SCTP_LTRACE_ERR_RET(inp, stcb, NULL, SCTP_FROM_SCTP_USRREQ, error);
|
MFp4:
Bring in updated jail support from bz_jail branch.
This enhances the current jail implementation to permit multiple
addresses per jail. In addtion to IPv4, IPv6 is supported as well.
Due to updated checks it is even possible to have jails without
an IP address at all, which basically gives one a chroot with
restricted process view, no networking,..
SCTP support was updated and supports IPv6 in jails as well.
Cpuset support permits jails to be bound to specific processor
sets after creation.
Jails can have an unrestricted (no duplicate protection, etc.) name
in addition to the hostname. The jail name cannot be changed from
within a jail and is considered to be used for management purposes
or as audit-token in the future.
DDB 'show jails' command was added to aid debugging.
Proper compat support permits 32bit jail binaries to be used on 64bit
systems to manage jails. Also backward compatibility was preserved where
possible: for jail v1 syscalls, as well as with user space management
utilities.
Both jail as well as prison version were updated for the new features.
A gap was intentionally left as the intermediate versions had been
used by various patches floating around the last years.
Bump __FreeBSD_version for the afore mentioned and in kernel changes.
Special thanks to:
- Pawel Jakub Dawidek (pjd) for his multi-IPv4 patches
and Olivier Houchard (cognet) for initial single-IPv6 patches.
- Jeff Roberson (jeff) and Randall Stewart (rrs) for their
help, ideas and review on cpuset and SCTP support.
- Robert Watson (rwatson) for lots and lots of help, discussions,
suggestions and review of most of the patch at various stages.
- John Baldwin (jhb) for his help.
- Simon L. Nielsen (simon) as early adopter testing changes
on cluster machines as well as all the testers and people
who provided feedback the last months on freebsd-jail and
other channels.
- My employer, CK Software GmbH, for the support so I could work on this.
Reviewed by: (see above)
MFC after: 3 months (this is just so that I get the mail)
X-MFC Before: 7.2-RELEASE if possible
2008-11-29 14:32:14 +00:00
|
|
|
break;
|
2007-07-17 20:58:26 +00:00
|
|
|
}
|
MFp4:
Bring in updated jail support from bz_jail branch.
This enhances the current jail implementation to permit multiple
addresses per jail. In addtion to IPv4, IPv6 is supported as well.
Due to updated checks it is even possible to have jails without
an IP address at all, which basically gives one a chroot with
restricted process view, no networking,..
SCTP support was updated and supports IPv6 in jails as well.
Cpuset support permits jails to be bound to specific processor
sets after creation.
Jails can have an unrestricted (no duplicate protection, etc.) name
in addition to the hostname. The jail name cannot be changed from
within a jail and is considered to be used for management purposes
or as audit-token in the future.
DDB 'show jails' command was added to aid debugging.
Proper compat support permits 32bit jail binaries to be used on 64bit
systems to manage jails. Also backward compatibility was preserved where
possible: for jail v1 syscalls, as well as with user space management
utilities.
Both jail as well as prison version were updated for the new features.
A gap was intentionally left as the intermediate versions had been
used by various patches floating around the last years.
Bump __FreeBSD_version for the afore mentioned and in kernel changes.
Special thanks to:
- Pawel Jakub Dawidek (pjd) for his multi-IPv4 patches
and Olivier Houchard (cognet) for initial single-IPv6 patches.
- Jeff Roberson (jeff) and Randall Stewart (rrs) for their
help, ideas and review on cpuset and SCTP support.
- Robert Watson (rwatson) for lots and lots of help, discussions,
suggestions and review of most of the patch at various stages.
- John Baldwin (jhb) for his help.
- Simon L. Nielsen (simon) as early adopter testing changes
on cluster machines as well as all the testers and people
who provided feedback the last months on freebsd-jail and
other channels.
- My employer, CK Software GmbH, for the support so I could work on this.
Reviewed by: (see above)
MFC after: 3 months (this is just so that I get the mail)
X-MFC Before: 7.2-RELEASE if possible
2008-11-29 14:32:14 +00:00
|
|
|
#ifdef INET6
|
2007-07-17 20:58:26 +00:00
|
|
|
} else if (addrs->addr->sa_family == AF_INET6) {
|
|
|
|
sz = sizeof(struct sctp_getaddresses) - sizeof(struct sockaddr) + sizeof(struct sockaddr_in6);
|
|
|
|
if (optsize < sz) {
|
2007-08-24 00:53:53 +00:00
|
|
|
SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
|
2007-07-17 20:58:26 +00:00
|
|
|
error = EINVAL;
|
|
|
|
break;
|
|
|
|
}
|
2009-02-13 18:44:30 +00:00
|
|
|
if (td != NULL && (error = prison_local_ip6(td->td_ucred, &(((struct sockaddr_in6 *)(addrs->addr))->sin6_addr),
|
|
|
|
(SCTP_IPV6_V6ONLY(inp) != 0))) != 0) {
|
|
|
|
SCTP_LTRACE_ERR_RET(inp, stcb, NULL, SCTP_FROM_SCTP_USRREQ, error);
|
MFp4:
Bring in updated jail support from bz_jail branch.
This enhances the current jail implementation to permit multiple
addresses per jail. In addtion to IPv4, IPv6 is supported as well.
Due to updated checks it is even possible to have jails without
an IP address at all, which basically gives one a chroot with
restricted process view, no networking,..
SCTP support was updated and supports IPv6 in jails as well.
Cpuset support permits jails to be bound to specific processor
sets after creation.
Jails can have an unrestricted (no duplicate protection, etc.) name
in addition to the hostname. The jail name cannot be changed from
within a jail and is considered to be used for management purposes
or as audit-token in the future.
DDB 'show jails' command was added to aid debugging.
Proper compat support permits 32bit jail binaries to be used on 64bit
systems to manage jails. Also backward compatibility was preserved where
possible: for jail v1 syscalls, as well as with user space management
utilities.
Both jail as well as prison version were updated for the new features.
A gap was intentionally left as the intermediate versions had been
used by various patches floating around the last years.
Bump __FreeBSD_version for the afore mentioned and in kernel changes.
Special thanks to:
- Pawel Jakub Dawidek (pjd) for his multi-IPv4 patches
and Olivier Houchard (cognet) for initial single-IPv6 patches.
- Jeff Roberson (jeff) and Randall Stewart (rrs) for their
help, ideas and review on cpuset and SCTP support.
- Robert Watson (rwatson) for lots and lots of help, discussions,
suggestions and review of most of the patch at various stages.
- John Baldwin (jhb) for his help.
- Simon L. Nielsen (simon) as early adopter testing changes
on cluster machines as well as all the testers and people
who provided feedback the last months on freebsd-jail and
other channels.
- My employer, CK Software GmbH, for the support so I could work on this.
Reviewed by: (see above)
MFC after: 3 months (this is just so that I get the mail)
X-MFC Before: 7.2-RELEASE if possible
2008-11-29 14:32:14 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
} else {
|
|
|
|
error = EAFNOSUPPORT;
|
|
|
|
break;
|
2007-07-17 20:58:26 +00:00
|
|
|
}
|
2007-06-12 11:21:00 +00:00
|
|
|
sctp_bindx_delete_address(so, inp, addrs->addr,
|
|
|
|
addrs->sget_assoc_id, vrf_id,
|
|
|
|
&error);
|
2006-11-03 15:23:16 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
2007-08-24 00:53:53 +00:00
|
|
|
SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOPROTOOPT);
|
2006-11-03 15:23:16 +00:00
|
|
|
error = ENOPROTOOPT;
|
|
|
|
break;
|
|
|
|
} /* end switch (opt) */
|
|
|
|
return (error);
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
sctp_ctloutput(struct socket *so, struct sockopt *sopt)
|
|
|
|
{
|
2007-02-12 23:24:31 +00:00
|
|
|
void *optval = NULL;
|
|
|
|
size_t optsize = 0;
|
2006-11-03 15:23:16 +00:00
|
|
|
struct sctp_inpcb *inp;
|
2007-02-12 23:24:31 +00:00
|
|
|
void *p;
|
|
|
|
int error = 0;
|
2006-11-03 15:23:16 +00:00
|
|
|
|
|
|
|
inp = (struct sctp_inpcb *)so->so_pcb;
|
|
|
|
if (inp == 0) {
|
|
|
|
/* I made the same as TCP since we are not setup? */
|
2007-08-24 00:53:53 +00:00
|
|
|
SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
|
2006-11-03 15:23:16 +00:00
|
|
|
return (ECONNRESET);
|
|
|
|
}
|
|
|
|
if (sopt->sopt_level != IPPROTO_SCTP) {
|
|
|
|
/* wrong proto level... send back up to IP */
|
|
|
|
#ifdef INET6
|
|
|
|
if (INP_CHECK_SOCKAF(so, AF_INET6))
|
|
|
|
error = ip6_ctloutput(so, sopt);
|
|
|
|
else
|
|
|
|
#endif /* INET6 */
|
|
|
|
error = ip_ctloutput(so, sopt);
|
|
|
|
return (error);
|
|
|
|
}
|
2007-02-12 23:24:31 +00:00
|
|
|
optsize = sopt->sopt_valsize;
|
|
|
|
if (optsize) {
|
2007-05-29 09:29:03 +00:00
|
|
|
SCTP_MALLOC(optval, void *, optsize, SCTP_M_SOCKOPT);
|
2007-02-12 23:24:31 +00:00
|
|
|
if (optval == NULL) {
|
2007-08-24 00:53:53 +00:00
|
|
|
SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOBUFS);
|
2006-11-03 15:23:16 +00:00
|
|
|
return (ENOBUFS);
|
|
|
|
}
|
2007-02-12 23:24:31 +00:00
|
|
|
error = sooptcopyin(sopt, optval, optsize, optsize);
|
2006-11-03 15:23:16 +00:00
|
|
|
if (error) {
|
2007-05-29 09:29:03 +00:00
|
|
|
SCTP_FREE(optval, SCTP_M_SOCKOPT);
|
2006-11-03 15:23:16 +00:00
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
}
|
2007-02-12 23:24:31 +00:00
|
|
|
p = (void *)sopt->sopt_td;
|
2006-11-03 15:23:16 +00:00
|
|
|
if (sopt->sopt_dir == SOPT_SET) {
|
2007-02-12 23:24:31 +00:00
|
|
|
error = sctp_setopt(so, sopt->sopt_name, optval, optsize, p);
|
2006-11-03 15:23:16 +00:00
|
|
|
} else if (sopt->sopt_dir == SOPT_GET) {
|
2007-02-12 23:24:31 +00:00
|
|
|
error = sctp_getopt(so, sopt->sopt_name, optval, &optsize, p);
|
2006-11-03 15:23:16 +00:00
|
|
|
} else {
|
2007-08-24 00:53:53 +00:00
|
|
|
SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
|
2006-11-03 15:23:16 +00:00
|
|
|
error = EINVAL;
|
|
|
|
}
|
2007-02-12 23:24:31 +00:00
|
|
|
if ((error == 0) && (optval != NULL)) {
|
|
|
|
error = sooptcopyout(sopt, optval, optsize);
|
2007-05-29 09:29:03 +00:00
|
|
|
SCTP_FREE(optval, SCTP_M_SOCKOPT);
|
2007-02-12 23:24:31 +00:00
|
|
|
} else if (optval != NULL) {
|
2007-05-29 09:29:03 +00:00
|
|
|
SCTP_FREE(optval, SCTP_M_SOCKOPT);
|
2006-11-03 15:23:16 +00:00
|
|
|
}
|
|
|
|
out:
|
|
|
|
return (error);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static int
|
|
|
|
sctp_connect(struct socket *so, struct sockaddr *addr, struct thread *p)
|
|
|
|
{
|
|
|
|
int error = 0;
|
|
|
|
int create_lock_on = 0;
|
2007-03-15 11:27:14 +00:00
|
|
|
uint32_t vrf_id;
|
2006-11-03 15:23:16 +00:00
|
|
|
struct sctp_inpcb *inp;
|
|
|
|
struct sctp_tcb *stcb = NULL;
|
|
|
|
|
|
|
|
inp = (struct sctp_inpcb *)so->so_pcb;
|
|
|
|
if (inp == 0) {
|
|
|
|
/* I made the same as TCP since we are not setup? */
|
2007-08-24 00:53:53 +00:00
|
|
|
SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
|
2006-11-03 15:23:16 +00:00
|
|
|
return (ECONNRESET);
|
|
|
|
}
|
2007-08-24 00:53:53 +00:00
|
|
|
if (addr == NULL) {
|
|
|
|
SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
|
2007-05-28 11:17:24 +00:00
|
|
|
return EINVAL;
|
2007-08-24 00:53:53 +00:00
|
|
|
}
|
MFp4:
Bring in updated jail support from bz_jail branch.
This enhances the current jail implementation to permit multiple
addresses per jail. In addtion to IPv4, IPv6 is supported as well.
Due to updated checks it is even possible to have jails without
an IP address at all, which basically gives one a chroot with
restricted process view, no networking,..
SCTP support was updated and supports IPv6 in jails as well.
Cpuset support permits jails to be bound to specific processor
sets after creation.
Jails can have an unrestricted (no duplicate protection, etc.) name
in addition to the hostname. The jail name cannot be changed from
within a jail and is considered to be used for management purposes
or as audit-token in the future.
DDB 'show jails' command was added to aid debugging.
Proper compat support permits 32bit jail binaries to be used on 64bit
systems to manage jails. Also backward compatibility was preserved where
possible: for jail v1 syscalls, as well as with user space management
utilities.
Both jail as well as prison version were updated for the new features.
A gap was intentionally left as the intermediate versions had been
used by various patches floating around the last years.
Bump __FreeBSD_version for the afore mentioned and in kernel changes.
Special thanks to:
- Pawel Jakub Dawidek (pjd) for his multi-IPv4 patches
and Olivier Houchard (cognet) for initial single-IPv6 patches.
- Jeff Roberson (jeff) and Randall Stewart (rrs) for their
help, ideas and review on cpuset and SCTP support.
- Robert Watson (rwatson) for lots and lots of help, discussions,
suggestions and review of most of the patch at various stages.
- John Baldwin (jhb) for his help.
- Simon L. Nielsen (simon) as early adopter testing changes
on cluster machines as well as all the testers and people
who provided feedback the last months on freebsd-jail and
other channels.
- My employer, CK Software GmbH, for the support so I could work on this.
Reviewed by: (see above)
MFC after: 3 months (this is just so that I get the mail)
X-MFC Before: 7.2-RELEASE if possible
2008-11-29 14:32:14 +00:00
|
|
|
#ifdef INET6
|
|
|
|
if (addr->sa_family == AF_INET6) {
|
|
|
|
struct sockaddr_in6 *sin6p;
|
2008-12-06 13:19:54 +00:00
|
|
|
|
MFp4:
Bring in updated jail support from bz_jail branch.
This enhances the current jail implementation to permit multiple
addresses per jail. In addtion to IPv4, IPv6 is supported as well.
Due to updated checks it is even possible to have jails without
an IP address at all, which basically gives one a chroot with
restricted process view, no networking,..
SCTP support was updated and supports IPv6 in jails as well.
Cpuset support permits jails to be bound to specific processor
sets after creation.
Jails can have an unrestricted (no duplicate protection, etc.) name
in addition to the hostname. The jail name cannot be changed from
within a jail and is considered to be used for management purposes
or as audit-token in the future.
DDB 'show jails' command was added to aid debugging.
Proper compat support permits 32bit jail binaries to be used on 64bit
systems to manage jails. Also backward compatibility was preserved where
possible: for jail v1 syscalls, as well as with user space management
utilities.
Both jail as well as prison version were updated for the new features.
A gap was intentionally left as the intermediate versions had been
used by various patches floating around the last years.
Bump __FreeBSD_version for the afore mentioned and in kernel changes.
Special thanks to:
- Pawel Jakub Dawidek (pjd) for his multi-IPv4 patches
and Olivier Houchard (cognet) for initial single-IPv6 patches.
- Jeff Roberson (jeff) and Randall Stewart (rrs) for their
help, ideas and review on cpuset and SCTP support.
- Robert Watson (rwatson) for lots and lots of help, discussions,
suggestions and review of most of the patch at various stages.
- John Baldwin (jhb) for his help.
- Simon L. Nielsen (simon) as early adopter testing changes
on cluster machines as well as all the testers and people
who provided feedback the last months on freebsd-jail and
other channels.
- My employer, CK Software GmbH, for the support so I could work on this.
Reviewed by: (see above)
MFC after: 3 months (this is just so that I get the mail)
X-MFC Before: 7.2-RELEASE if possible
2008-11-29 14:32:14 +00:00
|
|
|
if (addr->sa_len != sizeof(struct sockaddr_in6)) {
|
|
|
|
SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
|
|
|
|
return (EINVAL);
|
|
|
|
}
|
|
|
|
sin6p = (struct sockaddr_in6 *)addr;
|
2009-02-13 18:44:30 +00:00
|
|
|
if (p != NULL && (error = prison_remote_ip6(p->td_ucred, &sin6p->sin6_addr)) != 0) {
|
|
|
|
SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
|
|
|
|
return (error);
|
MFp4:
Bring in updated jail support from bz_jail branch.
This enhances the current jail implementation to permit multiple
addresses per jail. In addtion to IPv4, IPv6 is supported as well.
Due to updated checks it is even possible to have jails without
an IP address at all, which basically gives one a chroot with
restricted process view, no networking,..
SCTP support was updated and supports IPv6 in jails as well.
Cpuset support permits jails to be bound to specific processor
sets after creation.
Jails can have an unrestricted (no duplicate protection, etc.) name
in addition to the hostname. The jail name cannot be changed from
within a jail and is considered to be used for management purposes
or as audit-token in the future.
DDB 'show jails' command was added to aid debugging.
Proper compat support permits 32bit jail binaries to be used on 64bit
systems to manage jails. Also backward compatibility was preserved where
possible: for jail v1 syscalls, as well as with user space management
utilities.
Both jail as well as prison version were updated for the new features.
A gap was intentionally left as the intermediate versions had been
used by various patches floating around the last years.
Bump __FreeBSD_version for the afore mentioned and in kernel changes.
Special thanks to:
- Pawel Jakub Dawidek (pjd) for his multi-IPv4 patches
and Olivier Houchard (cognet) for initial single-IPv6 patches.
- Jeff Roberson (jeff) and Randall Stewart (rrs) for their
help, ideas and review on cpuset and SCTP support.
- Robert Watson (rwatson) for lots and lots of help, discussions,
suggestions and review of most of the patch at various stages.
- John Baldwin (jhb) for his help.
- Simon L. Nielsen (simon) as early adopter testing changes
on cluster machines as well as all the testers and people
who provided feedback the last months on freebsd-jail and
other channels.
- My employer, CK Software GmbH, for the support so I could work on this.
Reviewed by: (see above)
MFC after: 3 months (this is just so that I get the mail)
X-MFC Before: 7.2-RELEASE if possible
2008-11-29 14:32:14 +00:00
|
|
|
}
|
|
|
|
} else
|
|
|
|
#endif
|
|
|
|
if (addr->sa_family == AF_INET) {
|
|
|
|
struct sockaddr_in *sinp;
|
2008-12-06 13:19:54 +00:00
|
|
|
|
MFp4:
Bring in updated jail support from bz_jail branch.
This enhances the current jail implementation to permit multiple
addresses per jail. In addtion to IPv4, IPv6 is supported as well.
Due to updated checks it is even possible to have jails without
an IP address at all, which basically gives one a chroot with
restricted process view, no networking,..
SCTP support was updated and supports IPv6 in jails as well.
Cpuset support permits jails to be bound to specific processor
sets after creation.
Jails can have an unrestricted (no duplicate protection, etc.) name
in addition to the hostname. The jail name cannot be changed from
within a jail and is considered to be used for management purposes
or as audit-token in the future.
DDB 'show jails' command was added to aid debugging.
Proper compat support permits 32bit jail binaries to be used on 64bit
systems to manage jails. Also backward compatibility was preserved where
possible: for jail v1 syscalls, as well as with user space management
utilities.
Both jail as well as prison version were updated for the new features.
A gap was intentionally left as the intermediate versions had been
used by various patches floating around the last years.
Bump __FreeBSD_version for the afore mentioned and in kernel changes.
Special thanks to:
- Pawel Jakub Dawidek (pjd) for his multi-IPv4 patches
and Olivier Houchard (cognet) for initial single-IPv6 patches.
- Jeff Roberson (jeff) and Randall Stewart (rrs) for their
help, ideas and review on cpuset and SCTP support.
- Robert Watson (rwatson) for lots and lots of help, discussions,
suggestions and review of most of the patch at various stages.
- John Baldwin (jhb) for his help.
- Simon L. Nielsen (simon) as early adopter testing changes
on cluster machines as well as all the testers and people
who provided feedback the last months on freebsd-jail and
other channels.
- My employer, CK Software GmbH, for the support so I could work on this.
Reviewed by: (see above)
MFC after: 3 months (this is just so that I get the mail)
X-MFC Before: 7.2-RELEASE if possible
2008-11-29 14:32:14 +00:00
|
|
|
if (addr->sa_len != sizeof(struct sockaddr_in)) {
|
|
|
|
SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
|
|
|
|
return (EINVAL);
|
|
|
|
}
|
|
|
|
sinp = (struct sockaddr_in *)addr;
|
2009-02-13 18:44:30 +00:00
|
|
|
if (p != NULL && (error = prison_remote_ip4(p->td_ucred, &sinp->sin_addr)) != 0) {
|
|
|
|
SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
|
|
|
|
return (error);
|
MFp4:
Bring in updated jail support from bz_jail branch.
This enhances the current jail implementation to permit multiple
addresses per jail. In addtion to IPv4, IPv6 is supported as well.
Due to updated checks it is even possible to have jails without
an IP address at all, which basically gives one a chroot with
restricted process view, no networking,..
SCTP support was updated and supports IPv6 in jails as well.
Cpuset support permits jails to be bound to specific processor
sets after creation.
Jails can have an unrestricted (no duplicate protection, etc.) name
in addition to the hostname. The jail name cannot be changed from
within a jail and is considered to be used for management purposes
or as audit-token in the future.
DDB 'show jails' command was added to aid debugging.
Proper compat support permits 32bit jail binaries to be used on 64bit
systems to manage jails. Also backward compatibility was preserved where
possible: for jail v1 syscalls, as well as with user space management
utilities.
Both jail as well as prison version were updated for the new features.
A gap was intentionally left as the intermediate versions had been
used by various patches floating around the last years.
Bump __FreeBSD_version for the afore mentioned and in kernel changes.
Special thanks to:
- Pawel Jakub Dawidek (pjd) for his multi-IPv4 patches
and Olivier Houchard (cognet) for initial single-IPv6 patches.
- Jeff Roberson (jeff) and Randall Stewart (rrs) for their
help, ideas and review on cpuset and SCTP support.
- Robert Watson (rwatson) for lots and lots of help, discussions,
suggestions and review of most of the patch at various stages.
- John Baldwin (jhb) for his help.
- Simon L. Nielsen (simon) as early adopter testing changes
on cluster machines as well as all the testers and people
who provided feedback the last months on freebsd-jail and
other channels.
- My employer, CK Software GmbH, for the support so I could work on this.
Reviewed by: (see above)
MFC after: 3 months (this is just so that I get the mail)
X-MFC Before: 7.2-RELEASE if possible
2008-11-29 14:32:14 +00:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EAFNOSUPPORT);
|
|
|
|
return (EAFNOSUPPORT);
|
2007-05-28 11:17:24 +00:00
|
|
|
}
|
2008-04-14 18:13:33 +00:00
|
|
|
SCTP_INP_INCR_REF(inp);
|
2006-11-03 15:23:16 +00:00
|
|
|
SCTP_ASOC_CREATE_LOCK(inp);
|
|
|
|
create_lock_on = 1;
|
|
|
|
|
2008-04-14 18:13:33 +00:00
|
|
|
|
2006-11-03 15:23:16 +00:00
|
|
|
if ((inp->sctp_flags & SCTP_PCB_FLAGS_SOCKET_ALLGONE) ||
|
|
|
|
(inp->sctp_flags & SCTP_PCB_FLAGS_SOCKET_GONE)) {
|
|
|
|
/* Should I really unlock ? */
|
2007-08-24 00:53:53 +00:00
|
|
|
SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EFAULT);
|
2006-11-03 15:23:16 +00:00
|
|
|
error = EFAULT;
|
|
|
|
goto out_now;
|
|
|
|
}
|
|
|
|
#ifdef INET6
|
|
|
|
if (((inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) == 0) &&
|
|
|
|
(addr->sa_family == AF_INET6)) {
|
2007-08-24 00:53:53 +00:00
|
|
|
SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
|
2006-11-03 15:23:16 +00:00
|
|
|
error = EINVAL;
|
|
|
|
goto out_now;
|
|
|
|
}
|
|
|
|
#endif /* INET6 */
|
|
|
|
if ((inp->sctp_flags & SCTP_PCB_FLAGS_UNBOUND) ==
|
|
|
|
SCTP_PCB_FLAGS_UNBOUND) {
|
|
|
|
/* Bind a ephemeral port */
|
2007-07-24 20:06:02 +00:00
|
|
|
error = sctp_inpcb_bind(so, NULL, NULL, p);
|
2006-11-03 15:23:16 +00:00
|
|
|
if (error) {
|
|
|
|
goto out_now;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
/* Now do we connect? */
|
2008-07-31 11:08:30 +00:00
|
|
|
if ((inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) &&
|
|
|
|
(sctp_is_feature_off(inp, SCTP_PCB_FLAGS_PORTREUSE))) {
|
2007-08-24 00:53:53 +00:00
|
|
|
SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
|
2006-11-03 15:23:16 +00:00
|
|
|
error = EINVAL;
|
|
|
|
goto out_now;
|
|
|
|
}
|
|
|
|
if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) &&
|
|
|
|
(inp->sctp_flags & SCTP_PCB_FLAGS_CONNECTED)) {
|
|
|
|
/* We are already connected AND the TCP model */
|
2007-08-24 00:53:53 +00:00
|
|
|
SCTP_LTRACE_ERR_RET(inp, stcb, NULL, SCTP_FROM_SCTP_USRREQ, EADDRINUSE);
|
2006-11-03 15:23:16 +00:00
|
|
|
error = EADDRINUSE;
|
|
|
|
goto out_now;
|
|
|
|
}
|
|
|
|
if (inp->sctp_flags & SCTP_PCB_FLAGS_CONNECTED) {
|
|
|
|
SCTP_INP_RLOCK(inp);
|
|
|
|
stcb = LIST_FIRST(&inp->sctp_asoc_list);
|
|
|
|
SCTP_INP_RUNLOCK(inp);
|
|
|
|
} else {
|
|
|
|
/*
|
2007-02-12 23:24:31 +00:00
|
|
|
* We increment here since sctp_findassociation_ep_addr()
|
2008-07-31 11:08:30 +00:00
|
|
|
* will do a decrement if it finds the stcb as long as the
|
2007-02-12 23:24:31 +00:00
|
|
|
* locked tcb (last argument) is NOT a TCB.. aka NULL.
|
2006-11-03 15:23:16 +00:00
|
|
|
*/
|
|
|
|
SCTP_INP_INCR_REF(inp);
|
|
|
|
stcb = sctp_findassociation_ep_addr(&inp, addr, NULL, NULL, NULL);
|
|
|
|
if (stcb == NULL) {
|
|
|
|
SCTP_INP_DECR_REF(inp);
|
2007-04-03 11:15:32 +00:00
|
|
|
} else {
|
2008-04-14 18:13:33 +00:00
|
|
|
SCTP_TCB_UNLOCK(stcb);
|
2006-11-03 15:23:16 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
if (stcb != NULL) {
|
|
|
|
/* Already have or am bring up an association */
|
2007-08-24 00:53:53 +00:00
|
|
|
SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EALREADY);
|
2006-11-03 15:23:16 +00:00
|
|
|
error = EALREADY;
|
|
|
|
goto out_now;
|
|
|
|
}
|
2007-04-03 11:15:32 +00:00
|
|
|
vrf_id = inp->def_vrf_id;
|
2006-11-03 15:23:16 +00:00
|
|
|
/* 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
|
|
|
if (stcb == NULL) {
|
|
|
|
/* Gak! no memory */
|
2007-03-15 11:27:14 +00:00
|
|
|
goto out_now;
|
2006-11-03 15:23:16 +00:00
|
|
|
}
|
|
|
|
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 */
|
2010-02-19 18:00:38 +00:00
|
|
|
SOCKBUF_LOCK(&so->so_rcv);
|
|
|
|
so->so_rcv.sb_state &= ~SBS_CANTRCVMORE;
|
|
|
|
SOCKBUF_UNLOCK(&so->so_rcv);
|
|
|
|
SOCKBUF_LOCK(&so->so_snd);
|
|
|
|
so->so_snd.sb_state &= ~SBS_CANTSENDMORE;
|
|
|
|
SOCKBUF_UNLOCK(&so->so_snd);
|
|
|
|
SOCK_LOCK(so);
|
|
|
|
so->so_state &= ~SS_ISDISCONNECTING;
|
|
|
|
SOCK_UNLOCK(so);
|
2006-11-03 15:23:16 +00:00
|
|
|
soisconnecting(so);
|
|
|
|
}
|
2007-08-24 00:53:53 +00:00
|
|
|
SCTP_SET_STATE(&stcb->asoc, SCTP_STATE_COOKIE_WAIT);
|
2007-05-08 14:32:53 +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);
|
2007-04-03 11:15:32 +00:00
|
|
|
SCTP_TCB_UNLOCK(stcb);
|
2006-11-03 15:23:16 +00:00
|
|
|
out_now:
|
2007-05-09 13:30:06 +00:00
|
|
|
if (create_lock_on) {
|
2006-11-03 15:23:16 +00:00
|
|
|
SCTP_ASOC_CREATE_UNLOCK(inp);
|
2007-05-09 13:30:06 +00:00
|
|
|
}
|
2006-11-03 15:23:16 +00:00
|
|
|
SCTP_INP_DECR_REF(inp);
|
|
|
|
return error;
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
sctp_listen(struct socket *so, int backlog, struct thread *p)
|
|
|
|
{
|
|
|
|
/*
|
|
|
|
* Note this module depends on the protocol processing being called
|
|
|
|
* AFTER any socket level flags and backlog are applied to the
|
|
|
|
* socket. The traditional way that the socket flags are applied is
|
|
|
|
* AFTER protocol processing. We have made a change to the
|
|
|
|
* sys/kern/uipc_socket.c module to reverse this but this MUST be in
|
|
|
|
* place if the socket API for SCTP is to work properly.
|
|
|
|
*/
|
|
|
|
|
|
|
|
int error = 0;
|
|
|
|
struct sctp_inpcb *inp;
|
|
|
|
|
|
|
|
inp = (struct sctp_inpcb *)so->so_pcb;
|
|
|
|
if (inp == 0) {
|
|
|
|
/* I made the same as TCP since we are not setup? */
|
2007-08-24 00:53:53 +00:00
|
|
|
SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
|
2006-11-03 15:23:16 +00:00
|
|
|
return (ECONNRESET);
|
|
|
|
}
|
2008-07-31 11:08:30 +00:00
|
|
|
if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_PORTREUSE)) {
|
|
|
|
/* See if we have a listener */
|
|
|
|
struct sctp_inpcb *tinp;
|
|
|
|
union sctp_sockstore store, *sp;
|
|
|
|
|
|
|
|
sp = &store;
|
|
|
|
if ((inp->sctp_flags & SCTP_PCB_FLAGS_BOUNDALL) == 0) {
|
|
|
|
/* not bound all */
|
|
|
|
struct sctp_laddr *laddr;
|
|
|
|
|
|
|
|
LIST_FOREACH(laddr, &inp->sctp_addr_list, sctp_nxt_addr) {
|
|
|
|
memcpy(&store, &laddr->ifa->address, sizeof(store));
|
|
|
|
sp->sin.sin_port = inp->sctp_lport;
|
|
|
|
tinp = sctp_pcb_findep(&sp->sa, 0, 0, inp->def_vrf_id);
|
|
|
|
if (tinp && (tinp != inp) &&
|
|
|
|
((tinp->sctp_flags & SCTP_PCB_FLAGS_SOCKET_ALLGONE) == 0) &&
|
|
|
|
((tinp->sctp_flags & SCTP_PCB_FLAGS_SOCKET_GONE) == 0) &&
|
|
|
|
(tinp->sctp_socket->so_qlimit)) {
|
|
|
|
/*
|
|
|
|
* we have a listener already and
|
|
|
|
* its not this inp.
|
|
|
|
*/
|
|
|
|
SCTP_INP_DECR_REF(tinp);
|
|
|
|
return (EADDRINUSE);
|
|
|
|
} else if (tinp) {
|
|
|
|
SCTP_INP_DECR_REF(tinp);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
/* Setup a local addr bound all */
|
|
|
|
memset(&store, 0, sizeof(store));
|
|
|
|
store.sin.sin_port = inp->sctp_lport;
|
|
|
|
#ifdef INET6
|
|
|
|
if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) {
|
|
|
|
store.sa.sa_family = AF_INET6;
|
|
|
|
store.sa.sa_len = sizeof(struct sockaddr_in6);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
if ((inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) == 0) {
|
|
|
|
store.sa.sa_family = AF_INET;
|
|
|
|
store.sa.sa_len = sizeof(struct sockaddr_in);
|
|
|
|
}
|
|
|
|
tinp = sctp_pcb_findep(&sp->sa, 0, 0, inp->def_vrf_id);
|
|
|
|
if (tinp && (tinp != inp) &&
|
|
|
|
((tinp->sctp_flags & SCTP_PCB_FLAGS_SOCKET_ALLGONE) == 0) &&
|
|
|
|
((tinp->sctp_flags & SCTP_PCB_FLAGS_SOCKET_GONE) == 0) &&
|
|
|
|
(tinp->sctp_socket->so_qlimit)) {
|
|
|
|
/*
|
|
|
|
* we have a listener already and its not
|
|
|
|
* this inp.
|
|
|
|
*/
|
|
|
|
SCTP_INP_DECR_REF(tinp);
|
|
|
|
return (EADDRINUSE);
|
|
|
|
} else if (tinp) {
|
|
|
|
SCTP_INP_DECR_REF(inp);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2006-11-03 15:23:16 +00:00
|
|
|
SCTP_INP_RLOCK(inp);
|
|
|
|
#ifdef SCTP_LOCK_LOGGING
|
2008-06-14 07:58:05 +00:00
|
|
|
if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_LOCK_LOGGING_ENABLE) {
|
2007-06-14 22:59:04 +00:00
|
|
|
sctp_log_lock(inp, (struct sctp_tcb *)NULL, SCTP_LOG_LOCK_SOCK);
|
|
|
|
}
|
2006-11-03 15:23:16 +00:00
|
|
|
#endif
|
|
|
|
SOCK_LOCK(so);
|
|
|
|
error = solisten_proto_check(so);
|
|
|
|
if (error) {
|
|
|
|
SOCK_UNLOCK(so);
|
2007-05-02 12:50:13 +00:00
|
|
|
SCTP_INP_RUNLOCK(inp);
|
2006-11-03 15:23:16 +00:00
|
|
|
return (error);
|
|
|
|
}
|
2008-07-31 11:08:30 +00:00
|
|
|
if ((sctp_is_feature_on(inp, SCTP_PCB_FLAGS_PORTREUSE)) &&
|
|
|
|
(inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL)) {
|
|
|
|
/*
|
|
|
|
* The unlucky case - We are in the tcp pool with this guy.
|
|
|
|
* - Someone else is in the main inp slot. - We must move
|
|
|
|
* this guy (the listener) to the main slot - We must then
|
|
|
|
* move the guy that was listener to the TCP Pool.
|
|
|
|
*/
|
|
|
|
if (sctp_swap_inpcb_for_listen(inp)) {
|
|
|
|
goto in_use;
|
|
|
|
}
|
|
|
|
}
|
2006-11-03 15:23:16 +00:00
|
|
|
if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) &&
|
|
|
|
(inp->sctp_flags & SCTP_PCB_FLAGS_CONNECTED)) {
|
|
|
|
/* We are already connected AND the TCP model */
|
2008-07-31 11:08:30 +00:00
|
|
|
in_use:
|
2006-11-03 15:23:16 +00:00
|
|
|
SCTP_INP_RUNLOCK(inp);
|
|
|
|
SOCK_UNLOCK(so);
|
2007-08-24 00:53:53 +00:00
|
|
|
SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EADDRINUSE);
|
2006-11-03 15:23:16 +00:00
|
|
|
return (EADDRINUSE);
|
|
|
|
}
|
2008-07-31 11:08:30 +00:00
|
|
|
SCTP_INP_RUNLOCK(inp);
|
2006-11-03 15:23:16 +00:00
|
|
|
if (inp->sctp_flags & SCTP_PCB_FLAGS_UNBOUND) {
|
|
|
|
/* We must do a bind. */
|
2007-02-12 23:24:31 +00:00
|
|
|
SOCK_UNLOCK(so);
|
2007-07-24 20:06:02 +00:00
|
|
|
if ((error = sctp_inpcb_bind(so, NULL, NULL, p))) {
|
2006-11-03 15:23:16 +00:00
|
|
|
/* bind error, probably perm */
|
|
|
|
return (error);
|
|
|
|
}
|
2007-02-12 23:24:31 +00:00
|
|
|
SOCK_LOCK(so);
|
2006-11-03 15:23:16 +00:00
|
|
|
}
|
|
|
|
/* It appears for 7.0 and on, we must always call this. */
|
|
|
|
solisten_proto(so, backlog);
|
|
|
|
if (inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) {
|
|
|
|
/* remove the ACCEPTCONN flag for one-to-many sockets */
|
|
|
|
so->so_options &= ~SO_ACCEPTCONN;
|
|
|
|
}
|
|
|
|
if (backlog == 0) {
|
|
|
|
/* turning off listen */
|
|
|
|
so->so_options &= ~SO_ACCEPTCONN;
|
|
|
|
}
|
|
|
|
SOCK_UNLOCK(so);
|
|
|
|
return (error);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int sctp_defered_wakeup_cnt = 0;
|
|
|
|
|
|
|
|
int
|
|
|
|
sctp_accept(struct socket *so, struct sockaddr **addr)
|
|
|
|
{
|
|
|
|
struct sctp_tcb *stcb;
|
|
|
|
struct sctp_inpcb *inp;
|
|
|
|
union sctp_sockstore store;
|
|
|
|
|
2008-04-16 17:24:18 +00:00
|
|
|
#ifdef INET6
|
2006-11-03 15:23:16 +00:00
|
|
|
int error;
|
|
|
|
|
2008-04-16 17:24:18 +00:00
|
|
|
#endif
|
2006-11-03 15:23:16 +00:00
|
|
|
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_SCTP_USRREQ, EINVAL);
|
2006-11-03 15:23:16 +00:00
|
|
|
return (ECONNRESET);
|
|
|
|
}
|
|
|
|
SCTP_INP_RLOCK(inp);
|
|
|
|
if (inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) {
|
2007-04-03 11:15:32 +00:00
|
|
|
SCTP_INP_RUNLOCK(inp);
|
2007-08-24 00:53:53 +00:00
|
|
|
SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EOPNOTSUPP);
|
|
|
|
return (EOPNOTSUPP);
|
2006-11-03 15:23:16 +00:00
|
|
|
}
|
|
|
|
if (so->so_state & SS_ISDISCONNECTED) {
|
|
|
|
SCTP_INP_RUNLOCK(inp);
|
2007-08-24 00:53:53 +00:00
|
|
|
SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ECONNABORTED);
|
2006-11-03 15:23:16 +00:00
|
|
|
return (ECONNABORTED);
|
|
|
|
}
|
|
|
|
stcb = LIST_FIRST(&inp->sctp_asoc_list);
|
|
|
|
if (stcb == NULL) {
|
|
|
|
SCTP_INP_RUNLOCK(inp);
|
2007-08-24 00:53:53 +00:00
|
|
|
SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
|
2006-11-03 15:23:16 +00:00
|
|
|
return (ECONNRESET);
|
|
|
|
}
|
|
|
|
SCTP_TCB_LOCK(stcb);
|
|
|
|
SCTP_INP_RUNLOCK(inp);
|
|
|
|
store = stcb->asoc.primary_destination->ro._l_addr;
|
2010-05-11 17:02:29 +00:00
|
|
|
stcb->asoc.state &= ~SCTP_STATE_IN_ACCEPT_QUEUE;
|
2006-11-03 15:23:16 +00:00
|
|
|
SCTP_TCB_UNLOCK(stcb);
|
2008-04-16 17:24:18 +00:00
|
|
|
switch (store.sa.sa_family) {
|
|
|
|
case AF_INET:
|
|
|
|
{
|
|
|
|
struct sockaddr_in *sin;
|
|
|
|
|
|
|
|
SCTP_MALLOC_SONAME(sin, struct sockaddr_in *, sizeof *sin);
|
2010-06-06 02:32:20 +00:00
|
|
|
if (sin == NULL)
|
|
|
|
return (ENOMEM);
|
2008-04-16 17:24:18 +00:00
|
|
|
sin->sin_family = AF_INET;
|
|
|
|
sin->sin_len = sizeof(*sin);
|
|
|
|
sin->sin_port = ((struct sockaddr_in *)&store)->sin_port;
|
|
|
|
sin->sin_addr = ((struct sockaddr_in *)&store)->sin_addr;
|
|
|
|
*addr = (struct sockaddr *)sin;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
#ifdef INET6
|
|
|
|
case AF_INET6:
|
|
|
|
{
|
|
|
|
struct sockaddr_in6 *sin6;
|
2006-11-03 15:23:16 +00:00
|
|
|
|
2008-04-16 17:24:18 +00:00
|
|
|
SCTP_MALLOC_SONAME(sin6, struct sockaddr_in6 *, sizeof *sin6);
|
2010-06-06 02:32:20 +00:00
|
|
|
if (sin6 == NULL)
|
|
|
|
return (ENOMEM);
|
2008-04-16 17:24:18 +00:00
|
|
|
sin6->sin6_family = AF_INET6;
|
|
|
|
sin6->sin6_len = sizeof(*sin6);
|
|
|
|
sin6->sin6_port = ((struct sockaddr_in6 *)&store)->sin6_port;
|
2006-11-03 15:23:16 +00:00
|
|
|
|
2008-04-16 17:24:18 +00:00
|
|
|
sin6->sin6_addr = ((struct sockaddr_in6 *)&store)->sin6_addr;
|
|
|
|
if ((error = sa6_recoverscope(sin6)) != 0) {
|
|
|
|
SCTP_FREE_SONAME(sin6);
|
|
|
|
return (error);
|
|
|
|
}
|
|
|
|
*addr = (struct sockaddr *)sin6;
|
|
|
|
break;
|
2006-11-08 00:21:13 +00:00
|
|
|
}
|
2008-04-16 17:24:18 +00:00
|
|
|
#endif
|
|
|
|
default:
|
|
|
|
/* TSNH */
|
|
|
|
break;
|
2006-11-03 15:23:16 +00:00
|
|
|
}
|
|
|
|
/* Wake any delayed sleep action */
|
|
|
|
if (inp->sctp_flags & SCTP_PCB_FLAGS_DONT_WAKE) {
|
2007-01-18 09:58:43 +00:00
|
|
|
SCTP_INP_WLOCK(inp);
|
2006-11-03 15:23:16 +00:00
|
|
|
inp->sctp_flags &= ~SCTP_PCB_FLAGS_DONT_WAKE;
|
|
|
|
if (inp->sctp_flags & SCTP_PCB_FLAGS_WAKEOUTPUT) {
|
|
|
|
inp->sctp_flags &= ~SCTP_PCB_FLAGS_WAKEOUTPUT;
|
2007-01-18 09:58:43 +00:00
|
|
|
SCTP_INP_WUNLOCK(inp);
|
2006-11-03 15:23:16 +00:00
|
|
|
SOCKBUF_LOCK(&inp->sctp_socket->so_snd);
|
|
|
|
if (sowriteable(inp->sctp_socket)) {
|
|
|
|
sowwakeup_locked(inp->sctp_socket);
|
|
|
|
} else {
|
|
|
|
SOCKBUF_UNLOCK(&inp->sctp_socket->so_snd);
|
|
|
|
}
|
2007-01-18 09:58:43 +00:00
|
|
|
SCTP_INP_WLOCK(inp);
|
2006-11-03 15:23:16 +00:00
|
|
|
}
|
|
|
|
if (inp->sctp_flags & SCTP_PCB_FLAGS_WAKEINPUT) {
|
|
|
|
inp->sctp_flags &= ~SCTP_PCB_FLAGS_WAKEINPUT;
|
2007-01-18 09:58:43 +00:00
|
|
|
SCTP_INP_WUNLOCK(inp);
|
2006-11-03 15:23:16 +00:00
|
|
|
SOCKBUF_LOCK(&inp->sctp_socket->so_rcv);
|
|
|
|
if (soreadable(inp->sctp_socket)) {
|
|
|
|
sctp_defered_wakeup_cnt++;
|
|
|
|
sorwakeup_locked(inp->sctp_socket);
|
|
|
|
} else {
|
|
|
|
SOCKBUF_UNLOCK(&inp->sctp_socket->so_rcv);
|
|
|
|
}
|
2007-01-18 09:58:43 +00:00
|
|
|
SCTP_INP_WLOCK(inp);
|
2006-11-03 15:23:16 +00:00
|
|
|
}
|
2007-01-18 09:58:43 +00:00
|
|
|
SCTP_INP_WUNLOCK(inp);
|
2006-11-03 15:23:16 +00:00
|
|
|
}
|
2010-05-11 17:02:29 +00:00
|
|
|
if (stcb->asoc.state & SCTP_STATE_ABOUT_TO_BE_FREED) {
|
|
|
|
SCTP_TCB_LOCK(stcb);
|
|
|
|
sctp_free_assoc(inp, stcb, SCTP_NORMAL_PROC, SCTP_FROM_SCTP_USRREQ + SCTP_LOC_7);
|
|
|
|
}
|
2006-11-03 15:23:16 +00:00
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
sctp_ingetaddr(struct socket *so, struct sockaddr **addr)
|
|
|
|
{
|
|
|
|
struct sockaddr_in *sin;
|
2007-03-15 11:27:14 +00:00
|
|
|
uint32_t vrf_id;
|
2006-11-03 15:23:16 +00:00
|
|
|
struct sctp_inpcb *inp;
|
2007-03-19 06:53:02 +00:00
|
|
|
struct sctp_ifa *sctp_ifa;
|
2006-11-03 15:23:16 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Do the malloc first in case it blocks.
|
|
|
|
*/
|
|
|
|
SCTP_MALLOC_SONAME(sin, struct sockaddr_in *, sizeof *sin);
|
2010-06-06 02:32:20 +00:00
|
|
|
if (sin == NULL)
|
|
|
|
return (ENOMEM);
|
2006-11-03 15:23:16 +00:00
|
|
|
sin->sin_family = AF_INET;
|
|
|
|
sin->sin_len = sizeof(*sin);
|
|
|
|
inp = (struct sctp_inpcb *)so->so_pcb;
|
|
|
|
if (!inp) {
|
|
|
|
SCTP_FREE_SONAME(sin);
|
2007-08-24 00:53:53 +00:00
|
|
|
SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
|
2006-11-03 15:23:16 +00:00
|
|
|
return ECONNRESET;
|
|
|
|
}
|
|
|
|
SCTP_INP_RLOCK(inp);
|
|
|
|
sin->sin_port = inp->sctp_lport;
|
|
|
|
if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUNDALL) {
|
|
|
|
if (inp->sctp_flags & SCTP_PCB_FLAGS_CONNECTED) {
|
|
|
|
struct sctp_tcb *stcb;
|
|
|
|
struct sockaddr_in *sin_a;
|
|
|
|
struct sctp_nets *net;
|
|
|
|
int fnd;
|
|
|
|
|
|
|
|
stcb = LIST_FIRST(&inp->sctp_asoc_list);
|
|
|
|
if (stcb == NULL) {
|
|
|
|
goto notConn;
|
|
|
|
}
|
|
|
|
fnd = 0;
|
|
|
|
sin_a = NULL;
|
|
|
|
SCTP_TCB_LOCK(stcb);
|
|
|
|
TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
|
|
|
|
sin_a = (struct sockaddr_in *)&net->ro._l_addr;
|
2006-11-08 00:21:13 +00:00
|
|
|
if (sin_a == NULL)
|
|
|
|
/* this will make coverity happy */
|
|
|
|
continue;
|
|
|
|
|
2006-11-03 15:23:16 +00:00
|
|
|
if (sin_a->sin_family == AF_INET) {
|
|
|
|
fnd = 1;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if ((!fnd) || (sin_a == NULL)) {
|
|
|
|
/* punt */
|
|
|
|
SCTP_TCB_UNLOCK(stcb);
|
|
|
|
goto notConn;
|
|
|
|
}
|
2007-04-03 11:15:32 +00:00
|
|
|
vrf_id = inp->def_vrf_id;
|
2007-03-15 11:27:14 +00:00
|
|
|
sctp_ifa = sctp_source_address_selection(inp,
|
|
|
|
stcb,
|
2007-04-03 11:15:32 +00:00
|
|
|
(sctp_route_t *) & net->ro,
|
2007-03-15 11:27:14 +00:00
|
|
|
net, 0, vrf_id);
|
|
|
|
if (sctp_ifa) {
|
|
|
|
sin->sin_addr = sctp_ifa->address.sin.sin_addr;
|
|
|
|
sctp_free_ifa(sctp_ifa);
|
|
|
|
}
|
2006-11-03 15:23:16 +00:00
|
|
|
SCTP_TCB_UNLOCK(stcb);
|
|
|
|
} else {
|
|
|
|
/* For the bound all case you get back 0 */
|
|
|
|
notConn:
|
|
|
|
sin->sin_addr.s_addr = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
} else {
|
|
|
|
/* Take the first IPv4 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_INET) {
|
2006-11-03 15:23:16 +00:00
|
|
|
struct sockaddr_in *sin_a;
|
|
|
|
|
2007-03-15 11:27:14 +00:00
|
|
|
sin_a = (struct sockaddr_in *)&laddr->ifa->address.sa;
|
2006-11-03 15:23:16 +00:00
|
|
|
sin->sin_addr = sin_a->sin_addr;
|
|
|
|
fnd = 1;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!fnd) {
|
|
|
|
SCTP_FREE_SONAME(sin);
|
|
|
|
SCTP_INP_RUNLOCK(inp);
|
2007-08-24 00:53:53 +00:00
|
|
|
SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOENT);
|
2006-11-03 15:23:16 +00:00
|
|
|
return ENOENT;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
SCTP_INP_RUNLOCK(inp);
|
|
|
|
(*addr) = (struct sockaddr *)sin;
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
sctp_peeraddr(struct socket *so, struct sockaddr **addr)
|
|
|
|
{
|
|
|
|
struct sockaddr_in *sin = (struct sockaddr_in *)*addr;
|
2007-01-18 09:58:43 +00:00
|
|
|
int fnd;
|
2006-11-03 15:23:16 +00:00
|
|
|
struct sockaddr_in *sin_a;
|
|
|
|
struct sctp_inpcb *inp;
|
|
|
|
struct sctp_tcb *stcb;
|
|
|
|
struct sctp_nets *net;
|
|
|
|
|
|
|
|
/* Do the malloc first in case it blocks. */
|
|
|
|
inp = (struct sctp_inpcb *)so->so_pcb;
|
|
|
|
if ((inp == NULL) ||
|
|
|
|
((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_SCTP_USRREQ, ENOTCONN);
|
2006-11-03 15:23:16 +00:00
|
|
|
return (ENOTCONN);
|
|
|
|
}
|
|
|
|
SCTP_MALLOC_SONAME(sin, struct sockaddr_in *, sizeof *sin);
|
2010-06-06 02:32:20 +00:00
|
|
|
if (sin == NULL)
|
|
|
|
return (ENOMEM);
|
2006-11-03 15:23:16 +00:00
|
|
|
sin->sin_family = AF_INET;
|
|
|
|
sin->sin_len = sizeof(*sin);
|
|
|
|
|
|
|
|
/* We must recapture incase we blocked */
|
|
|
|
inp = (struct sctp_inpcb *)so->so_pcb;
|
|
|
|
if (!inp) {
|
|
|
|
SCTP_FREE_SONAME(sin);
|
2007-08-24 00:53:53 +00:00
|
|
|
SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
|
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(sin);
|
2007-08-24 00:53:53 +00:00
|
|
|
SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
|
2006-11-03 15:23:16 +00:00
|
|
|
return ECONNRESET;
|
|
|
|
}
|
|
|
|
fnd = 0;
|
|
|
|
TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
|
|
|
|
sin_a = (struct sockaddr_in *)&net->ro._l_addr;
|
|
|
|
if (sin_a->sin_family == AF_INET) {
|
|
|
|
fnd = 1;
|
|
|
|
sin->sin_port = stcb->rport;
|
|
|
|
sin->sin_addr = sin_a->sin_addr;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
SCTP_TCB_UNLOCK(stcb);
|
|
|
|
if (!fnd) {
|
|
|
|
/* No IPv4 address */
|
|
|
|
SCTP_FREE_SONAME(sin);
|
2007-08-24 00:53:53 +00:00
|
|
|
SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOENT);
|
2006-11-03 15:23:16 +00:00
|
|
|
return ENOENT;
|
|
|
|
}
|
|
|
|
(*addr) = (struct sockaddr *)sin;
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
|
|
|
struct pr_usrreqs sctp_usrreqs = {
|
|
|
|
.pru_abort = sctp_abort,
|
|
|
|
.pru_accept = sctp_accept,
|
|
|
|
.pru_attach = sctp_attach,
|
|
|
|
.pru_bind = sctp_bind,
|
|
|
|
.pru_connect = sctp_connect,
|
|
|
|
.pru_control = in_control,
|
|
|
|
.pru_close = sctp_close,
|
|
|
|
.pru_detach = sctp_close,
|
|
|
|
.pru_sopoll = sopoll_generic,
|
2008-04-14 18:13:33 +00:00
|
|
|
.pru_flush = sctp_flush,
|
2006-11-03 15:23:16 +00:00
|
|
|
.pru_disconnect = sctp_disconnect,
|
|
|
|
.pru_listen = sctp_listen,
|
|
|
|
.pru_peeraddr = sctp_peeraddr,
|
|
|
|
.pru_send = sctp_sendm,
|
|
|
|
.pru_shutdown = sctp_shutdown,
|
|
|
|
.pru_sockaddr = sctp_ingetaddr,
|
|
|
|
.pru_sosend = sctp_sosend,
|
|
|
|
.pru_soreceive = sctp_soreceive
|
|
|
|
};
|