michael@0: /*- michael@0: * Copyright (c) 2001-2008, by Cisco Systems, Inc. All rights reserved. michael@0: * Copyright (c) 2008-2012, by Randall Stewart. All rights reserved. michael@0: * Copyright (c) 2008-2012, by Michael Tuexen. All rights reserved. michael@0: * michael@0: * Redistribution and use in source and binary forms, with or without michael@0: * modification, are permitted provided that the following conditions are met: michael@0: * michael@0: * a) Redistributions of source code must retain the above copyright notice, michael@0: * this list of conditions and the following disclaimer. michael@0: * michael@0: * b) Redistributions in binary form must reproduce the above copyright michael@0: * notice, this list of conditions and the following disclaimer in michael@0: * the documentation and/or other materials provided with the distribution. michael@0: * michael@0: * c) Neither the name of Cisco Systems, Inc. nor the names of its michael@0: * contributors may be used to endorse or promote products derived michael@0: * from this software without specific prior written permission. michael@0: * michael@0: * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS michael@0: * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, michael@0: * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE michael@0: * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE michael@0: * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR michael@0: * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF michael@0: * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS michael@0: * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN michael@0: * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) michael@0: * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF michael@0: * THE POSSIBILITY OF SUCH DAMAGE. michael@0: */ michael@0: michael@0: #ifdef __FreeBSD__ michael@0: #include michael@0: __FBSDID("$FreeBSD: head/sys/netinet/sctp_usrreq.c 259943 2013-12-27 13:07:00Z tuexen $"); michael@0: #endif michael@0: michael@0: #include michael@0: #ifdef __FreeBSD__ michael@0: #include michael@0: #endif michael@0: #include michael@0: #include michael@0: #include michael@0: #ifdef INET6 michael@0: #if defined(__Userspace_os_FreeBSD) michael@0: #include michael@0: #endif michael@0: #endif michael@0: #include michael@0: #include michael@0: #include michael@0: #include michael@0: #include michael@0: #include michael@0: #include michael@0: #include michael@0: #include michael@0: #if defined(__Userspace__) michael@0: #include michael@0: #endif michael@0: #if !defined(__Userspace_os_Windows) michael@0: #include michael@0: #endif michael@0: michael@0: #if defined(HAVE_SCTP_PEELOFF_SOCKOPT) michael@0: #include michael@0: #endif /* HAVE_SCTP_PEELOFF_SOCKOPT */ michael@0: michael@0: #if defined(__APPLE__) michael@0: #define APPLE_FILE_NO 7 michael@0: #endif michael@0: michael@0: extern struct sctp_cc_functions sctp_cc_functions[]; michael@0: extern struct sctp_ss_functions sctp_ss_functions[]; michael@0: michael@0: void michael@0: #if defined(__Userspace__) michael@0: sctp_init(uint16_t port, michael@0: int (*conn_output)(void *addr, void *buffer, size_t length, uint8_t tos, uint8_t set_df), michael@0: void (*debug_printf)(const char *format, ...)) michael@0: #elif defined(__APPLE__) && (!defined(APPLE_LEOPARD) && !defined(APPLE_SNOWLEOPARD) &&!defined(APPLE_LION) && !defined(APPLE_MOUNTAINLION)) michael@0: sctp_init(struct protosw *pp SCTP_UNUSED, struct domain *dp SCTP_UNUSED) michael@0: #else michael@0: sctp_init(void) michael@0: #endif michael@0: { michael@0: #if !defined(__Panda__) && !defined(__Userspace__) michael@0: u_long sb_max_adj; michael@0: michael@0: #endif michael@0: #if defined(__Userspace__) michael@0: #if defined(__Userspace_os_Windows) michael@0: #if defined(INET) || defined(INET6) michael@0: WSADATA wsaData; michael@0: michael@0: if (WSAStartup(MAKEWORD(2,2), &wsaData) != 0) { michael@0: SCTP_PRINTF("WSAStartup failed\n"); michael@0: exit (-1); michael@0: } michael@0: #endif michael@0: InitializeConditionVariable(&accept_cond); michael@0: InitializeCriticalSection(&accept_mtx); michael@0: #else michael@0: pthread_cond_init(&accept_cond, NULL); michael@0: pthread_mutex_init(&accept_mtx, NULL); michael@0: #endif michael@0: #endif michael@0: /* Initialize and modify the sysctled variables */ michael@0: sctp_init_sysctls(); michael@0: #if defined(__Userspace__) michael@0: #if defined(__Userspace_os_Windows) michael@0: srand((unsigned int)time(NULL)); michael@0: #else michael@0: srandom(getpid()); /* so inp->sctp_ep.random_numbers are truly random... */ michael@0: #endif michael@0: #endif michael@0: #if defined(__Panda__) michael@0: sctp_sendspace = SB_MAX; michael@0: sctp_recvspace = SB_MAX; michael@0: michael@0: #elif defined(__Userspace__) michael@0: SCTP_BASE_SYSCTL(sctp_sendspace) = SB_MAX; michael@0: SCTP_BASE_SYSCTL(sctp_recvspace) = SB_RAW; michael@0: SCTP_BASE_SYSCTL(sctp_udp_tunneling_port) = port; michael@0: #else michael@0: #if !defined(__APPLE__) michael@0: if ((nmbclusters / 8) > SCTP_ASOC_MAX_CHUNKS_ON_QUEUE) michael@0: SCTP_BASE_SYSCTL(sctp_max_chunks_on_queue) = (nmbclusters / 8); michael@0: #endif michael@0: /* michael@0: * Allow a user to take no more than 1/2 the number of clusters or michael@0: * the SB_MAX whichever is smaller for the send window. michael@0: */ michael@0: #if defined(__APPLE__) michael@0: sb_max_adj = (u_long)((u_quad_t) (sb_max) * MCLBYTES / (MSIZE + MCLBYTES)); michael@0: #else michael@0: sb_max_adj = (u_long)((u_quad_t) (SB_MAX) * MCLBYTES / (MSIZE + MCLBYTES)); michael@0: #endif michael@0: #if defined(__APPLE__) michael@0: SCTP_BASE_SYSCTL(sctp_sendspace) = sb_max_adj; michael@0: #else michael@0: SCTP_BASE_SYSCTL(sctp_sendspace) = min(sb_max_adj, michael@0: (((uint32_t)nmbclusters / 2) * SCTP_DEFAULT_MAXSEGMENT)); michael@0: #endif michael@0: /* michael@0: * Now for the recv window, should we take the same amount? or michael@0: * should I do 1/2 the SB_MAX instead in the SB_MAX min above. For michael@0: * now I will just copy. michael@0: */ michael@0: SCTP_BASE_SYSCTL(sctp_recvspace) = SCTP_BASE_SYSCTL(sctp_sendspace); michael@0: #endif michael@0: SCTP_BASE_VAR(first_time) = 0; michael@0: SCTP_BASE_VAR(sctp_pcb_initialized) = 0; michael@0: #if defined(__Userspace__) michael@0: #if !defined(__Userspace_os_Windows) michael@0: #if defined(INET) || defined(INET6) michael@0: SCTP_BASE_VAR(userspace_route) = -1; michael@0: #endif michael@0: #endif michael@0: #ifdef INET michael@0: SCTP_BASE_VAR(userspace_rawsctp) = -1; michael@0: SCTP_BASE_VAR(userspace_udpsctp) = -1; michael@0: #endif michael@0: #ifdef INET6 michael@0: SCTP_BASE_VAR(userspace_rawsctp6) = -1; michael@0: SCTP_BASE_VAR(userspace_udpsctp6) = -1; michael@0: #endif michael@0: SCTP_BASE_VAR(timer_thread_should_exit) = 0; michael@0: SCTP_BASE_VAR(conn_output) = conn_output; michael@0: SCTP_BASE_VAR(debug_printf) = debug_printf; michael@0: #endif michael@0: sctp_pcb_init(); michael@0: #if defined(__Userspace__) michael@0: sctp_start_timer(); michael@0: #endif michael@0: #if defined(SCTP_PACKET_LOGGING) michael@0: SCTP_BASE_VAR(packet_log_writers) = 0; michael@0: SCTP_BASE_VAR(packet_log_end) = 0; michael@0: bzero(&SCTP_BASE_VAR(packet_log_buffer), SCTP_PACKET_LOG_SIZE); michael@0: #endif michael@0: #if defined(__APPLE__) michael@0: SCTP_BASE_VAR(sctp_main_timer_ticks) = 0; michael@0: sctp_start_main_timer(); michael@0: timeout(sctp_delayed_startup, NULL, 1); michael@0: #endif michael@0: } michael@0: michael@0: void michael@0: sctp_finish(void) michael@0: { michael@0: #if defined(__APPLE__) michael@0: untimeout(sctp_delayed_startup, NULL); michael@0: sctp_over_udp_stop(); michael@0: sctp_address_monitor_stop(); michael@0: sctp_stop_main_timer(); michael@0: #endif michael@0: #if defined(__Userspace__) michael@0: #if defined(INET) || defined(INET6) michael@0: recv_thread_destroy(); michael@0: #endif michael@0: #if !defined(__Userspace_os_Windows) michael@0: #if defined(INET) || defined(INET6) michael@0: if (SCTP_BASE_VAR(userspace_route) != -1) { michael@0: pthread_join(SCTP_BASE_VAR(recvthreadroute), NULL); michael@0: } michael@0: #endif michael@0: #endif michael@0: #ifdef INET michael@0: if (SCTP_BASE_VAR(userspace_rawsctp) != -1) { michael@0: #if defined(__Userspace_os_Windows) michael@0: WaitForSingleObject(SCTP_BASE_VAR(recvthreadraw), INFINITE); michael@0: CloseHandle(SCTP_BASE_VAR(recvthreadraw)); michael@0: #else michael@0: pthread_join(SCTP_BASE_VAR(recvthreadraw), NULL); michael@0: #endif michael@0: } michael@0: if (SCTP_BASE_VAR(userspace_udpsctp) != -1) { michael@0: #if defined(__Userspace_os_Windows) michael@0: WaitForSingleObject(SCTP_BASE_VAR(recvthreadudp), INFINITE); michael@0: CloseHandle(SCTP_BASE_VAR(recvthreadudp)); michael@0: #else michael@0: pthread_join(SCTP_BASE_VAR(recvthreadudp), NULL); michael@0: #endif michael@0: } michael@0: #endif michael@0: #ifdef INET6 michael@0: if (SCTP_BASE_VAR(userspace_rawsctp6) != -1) { michael@0: #if defined(__Userspace_os_Windows) michael@0: WaitForSingleObject(SCTP_BASE_VAR(recvthreadraw6), INFINITE); michael@0: CloseHandle(SCTP_BASE_VAR(recvthreadraw6)); michael@0: #else michael@0: pthread_join(SCTP_BASE_VAR(recvthreadraw6), NULL); michael@0: #endif michael@0: } michael@0: if (SCTP_BASE_VAR(userspace_udpsctp6) != -1) { michael@0: #if defined(__Userspace_os_Windows) michael@0: WaitForSingleObject(SCTP_BASE_VAR(recvthreadudp6), INFINITE); michael@0: CloseHandle(SCTP_BASE_VAR(recvthreadudp6)); michael@0: #else michael@0: pthread_join(SCTP_BASE_VAR(recvthreadudp6), NULL); michael@0: #endif michael@0: } michael@0: #endif michael@0: SCTP_BASE_VAR(timer_thread_should_exit) = 1; michael@0: #if defined(__Userspace_os_Windows) michael@0: WaitForSingleObject(SCTP_BASE_VAR(timer_thread), INFINITE); michael@0: CloseHandle(SCTP_BASE_VAR(timer_thread)); michael@0: #else michael@0: pthread_join(SCTP_BASE_VAR(timer_thread), NULL); michael@0: #endif michael@0: #endif michael@0: sctp_pcb_finish(); michael@0: #if defined(__Userspace__) michael@0: #if defined(__Userspace_os_Windows) michael@0: DeleteConditionVariable(&accept_cond); michael@0: DeleteCriticalSection(&accept_mtx); michael@0: #else michael@0: pthread_cond_destroy(&accept_cond); michael@0: pthread_mutex_destroy(&accept_mtx); michael@0: #endif michael@0: #endif michael@0: #if defined(__Windows__) michael@0: sctp_finish_sysctls(); michael@0: #if defined(INET) || defined(INET6) michael@0: WSACleanup(); michael@0: #endif michael@0: #endif michael@0: } michael@0: michael@0: michael@0: michael@0: void michael@0: sctp_pathmtu_adjustment(struct sctp_tcb *stcb, uint16_t nxtsz) michael@0: { michael@0: struct sctp_tmit_chunk *chk; michael@0: uint16_t overhead; michael@0: michael@0: /* Adjust that too */ michael@0: stcb->asoc.smallest_mtu = nxtsz; michael@0: /* now off to subtract IP_DF flag if needed */ michael@0: overhead = IP_HDR_SIZE; michael@0: if (sctp_auth_is_required_chunk(SCTP_DATA, stcb->asoc.peer_auth_chunks)) { michael@0: overhead += sctp_get_auth_chunk_len(stcb->asoc.peer_hmac_id); michael@0: } michael@0: TAILQ_FOREACH(chk, &stcb->asoc.send_queue, sctp_next) { michael@0: if ((chk->send_size + overhead) > nxtsz) { michael@0: chk->flags |= CHUNK_FLAGS_FRAGMENT_OK; michael@0: } michael@0: } michael@0: TAILQ_FOREACH(chk, &stcb->asoc.sent_queue, sctp_next) { michael@0: if ((chk->send_size + overhead) > nxtsz) { michael@0: /* michael@0: * For this guy we also mark for immediate resend michael@0: * since we sent to big of chunk michael@0: */ michael@0: chk->flags |= CHUNK_FLAGS_FRAGMENT_OK; michael@0: if (chk->sent < SCTP_DATAGRAM_RESEND) { michael@0: sctp_flight_size_decrease(chk); michael@0: sctp_total_flight_decrease(stcb, chk); michael@0: } michael@0: if (chk->sent != SCTP_DATAGRAM_RESEND) { michael@0: sctp_ucount_incr(stcb->asoc.sent_queue_retran_cnt); michael@0: } michael@0: chk->sent = SCTP_DATAGRAM_RESEND; michael@0: chk->rec.data.doing_fast_retransmit = 0; michael@0: if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_FLIGHT_LOGGING_ENABLE) { michael@0: sctp_misc_ints(SCTP_FLIGHT_LOG_DOWN_PMTU, michael@0: chk->whoTo->flight_size, michael@0: chk->book_size, michael@0: (uintptr_t)chk->whoTo, michael@0: chk->rec.data.TSN_seq); michael@0: } michael@0: /* Clear any time so NO RTT is being done */ michael@0: chk->do_rtt = 0; michael@0: } michael@0: } michael@0: } michael@0: michael@0: #ifdef INET michael@0: #if !defined(__Userspace__) michael@0: #if defined(__Panda__) || defined(__Windows__) michael@0: void michael@0: #else michael@0: static void michael@0: #endif michael@0: sctp_notify_mbuf(struct sctp_inpcb *inp, michael@0: struct sctp_tcb *stcb, michael@0: struct sctp_nets *net, michael@0: struct ip *ip, michael@0: struct sctphdr *sh) michael@0: { michael@0: struct icmp *icmph; michael@0: int totsz, tmr_stopped = 0; michael@0: uint16_t nxtsz; michael@0: michael@0: /* protection */ michael@0: if ((inp == NULL) || (stcb == NULL) || (net == NULL) || michael@0: (ip == NULL) || (sh == NULL)) { michael@0: if (stcb != NULL) { michael@0: SCTP_TCB_UNLOCK(stcb); michael@0: } michael@0: return; michael@0: } michael@0: /* First job is to verify the vtag matches what I would send */ michael@0: if (ntohl(sh->v_tag) != (stcb->asoc.peer_vtag)) { michael@0: SCTP_TCB_UNLOCK(stcb); michael@0: return; michael@0: } michael@0: icmph = (struct icmp *)((caddr_t)ip - (sizeof(struct icmp) - michael@0: sizeof(struct ip))); michael@0: if (icmph->icmp_type != ICMP_UNREACH) { michael@0: /* We only care about unreachable */ michael@0: SCTP_TCB_UNLOCK(stcb); michael@0: return; michael@0: } michael@0: if (icmph->icmp_code != ICMP_UNREACH_NEEDFRAG) { michael@0: /* not a unreachable message due to frag. */ michael@0: SCTP_TCB_UNLOCK(stcb); michael@0: return; michael@0: } michael@0: #if defined(__FreeBSD__) && __FreeBSD_version >= 1000000 michael@0: totsz = ntohs(ip->ip_len); michael@0: #else michael@0: totsz = ip->ip_len; michael@0: #endif michael@0: michael@0: nxtsz = ntohs(icmph->icmp_nextmtu); michael@0: if (nxtsz == 0) { michael@0: /* michael@0: * old type router that does not tell us what the next size michael@0: * mtu is. Rats we will have to guess (in a educated fashion michael@0: * of course) michael@0: */ michael@0: nxtsz = sctp_get_prev_mtu(totsz); michael@0: } michael@0: /* Stop any PMTU timer */ michael@0: if (SCTP_OS_TIMER_PENDING(&net->pmtu_timer.timer)) { michael@0: tmr_stopped = 1; michael@0: sctp_timer_stop(SCTP_TIMER_TYPE_PATHMTURAISE, inp, stcb, net, michael@0: SCTP_FROM_SCTP_USRREQ+SCTP_LOC_1); michael@0: } michael@0: /* Adjust destination size limit */ michael@0: if (net->mtu > nxtsz) { michael@0: net->mtu = nxtsz; michael@0: if (net->port) { michael@0: net->mtu -= sizeof(struct udphdr); michael@0: } michael@0: } michael@0: /* now what about the ep? */ michael@0: if (stcb->asoc.smallest_mtu > nxtsz) { michael@0: sctp_pathmtu_adjustment(stcb, nxtsz); michael@0: } michael@0: if (tmr_stopped) michael@0: sctp_timer_start(SCTP_TIMER_TYPE_PATHMTURAISE, inp, stcb, net); michael@0: michael@0: SCTP_TCB_UNLOCK(stcb); michael@0: } michael@0: #endif michael@0: #endif michael@0: michael@0: void michael@0: sctp_notify(struct sctp_inpcb *inp, michael@0: struct ip *ip, michael@0: struct sctphdr *sh, michael@0: struct sockaddr *to, michael@0: struct sctp_tcb *stcb, michael@0: struct sctp_nets *net) michael@0: { michael@0: #if defined(__APPLE__) || defined(SCTP_SO_LOCK_TESTING) michael@0: struct socket *so; michael@0: michael@0: #endif michael@0: struct icmp *icmph; michael@0: michael@0: /* protection */ michael@0: if ((inp == NULL) || (stcb == NULL) || (net == NULL) || michael@0: (sh == NULL) || (to == NULL)) { michael@0: if (stcb) michael@0: SCTP_TCB_UNLOCK(stcb); michael@0: return; michael@0: } michael@0: /* First job is to verify the vtag matches what I would send */ michael@0: if (ntohl(sh->v_tag) != (stcb->asoc.peer_vtag)) { michael@0: SCTP_TCB_UNLOCK(stcb); michael@0: return; michael@0: } michael@0: michael@0: icmph = (struct icmp *)((caddr_t)ip - (sizeof(struct icmp) - michael@0: sizeof(struct ip))); michael@0: if (icmph->icmp_type != ICMP_UNREACH) { michael@0: /* We only care about unreachable */ michael@0: SCTP_TCB_UNLOCK(stcb); michael@0: return; michael@0: } michael@0: if ((icmph->icmp_code == ICMP_UNREACH_NET) || michael@0: (icmph->icmp_code == ICMP_UNREACH_HOST) || michael@0: (icmph->icmp_code == ICMP_UNREACH_NET_UNKNOWN) || michael@0: (icmph->icmp_code == ICMP_UNREACH_HOST_UNKNOWN) || michael@0: (icmph->icmp_code == ICMP_UNREACH_ISOLATED) || michael@0: (icmph->icmp_code == ICMP_UNREACH_NET_PROHIB) || michael@0: (icmph->icmp_code == ICMP_UNREACH_HOST_PROHIB) || michael@0: #if defined(__Panda__) michael@0: (icmph->icmp_code == ICMP_UNREACH_ADMIN)) { michael@0: #elif defined(__Userspace_os_NetBSD) michael@0: (icmph->icmp_code == ICMP_UNREACH_ADMIN_PROHIBIT)) { michael@0: #else michael@0: (icmph->icmp_code == ICMP_UNREACH_FILTER_PROHIB)) { michael@0: #endif michael@0: michael@0: /* michael@0: * Hmm reachablity problems we must examine closely. If its michael@0: * not reachable, we may have lost a network. Or if there is michael@0: * NO protocol at the other end named SCTP. well we consider michael@0: * it a OOTB abort. michael@0: */ michael@0: if (net->dest_state & SCTP_ADDR_REACHABLE) { michael@0: /* Ok that destination is NOT reachable */ michael@0: net->dest_state &= ~SCTP_ADDR_REACHABLE; michael@0: net->dest_state &= ~SCTP_ADDR_PF; michael@0: sctp_ulp_notify(SCTP_NOTIFY_INTERFACE_DOWN, michael@0: stcb, 0, michael@0: (void *)net, SCTP_SO_NOT_LOCKED); michael@0: } michael@0: SCTP_TCB_UNLOCK(stcb); michael@0: } else if ((icmph->icmp_code == ICMP_UNREACH_PROTOCOL) || michael@0: (icmph->icmp_code == ICMP_UNREACH_PORT)) { michael@0: /* michael@0: * Here the peer is either playing tricks on us, michael@0: * including an address that belongs to someone who michael@0: * does not support SCTP OR was a userland michael@0: * implementation that shutdown and now is dead. In michael@0: * either case treat it like a OOTB abort with no michael@0: * TCB michael@0: */ michael@0: sctp_abort_notification(stcb, 1, 0, NULL, SCTP_SO_NOT_LOCKED); michael@0: #if defined(__APPLE__) || defined(SCTP_SO_LOCK_TESTING) michael@0: so = SCTP_INP_SO(inp); michael@0: atomic_add_int(&stcb->asoc.refcnt, 1); michael@0: SCTP_TCB_UNLOCK(stcb); michael@0: SCTP_SOCKET_LOCK(so, 1); michael@0: SCTP_TCB_LOCK(stcb); michael@0: atomic_subtract_int(&stcb->asoc.refcnt, 1); michael@0: #endif michael@0: (void)sctp_free_assoc(inp, stcb, SCTP_NORMAL_PROC, SCTP_FROM_SCTP_USRREQ+SCTP_LOC_2); michael@0: #if defined(__APPLE__) || defined(SCTP_SO_LOCK_TESTING) michael@0: SCTP_SOCKET_UNLOCK(so, 1); michael@0: /* SCTP_TCB_UNLOCK(stcb); MT: I think this is not needed.*/ michael@0: #endif michael@0: /* no need to unlock here, since the TCB is gone */ michael@0: } else { michael@0: SCTP_TCB_UNLOCK(stcb); michael@0: } michael@0: } michael@0: michael@0: #ifdef INET michael@0: #if !defined(__Panda__) && !defined(__Userspace__) michael@0: #if defined(__FreeBSD__) || defined(__APPLE__) || defined(__Windows__) michael@0: void michael@0: #else michael@0: void * michael@0: #endif michael@0: sctp_ctlinput(cmd, sa, vip) michael@0: int cmd; michael@0: struct sockaddr *sa; michael@0: void *vip; michael@0: { michael@0: struct ip *ip = vip; michael@0: struct sctphdr *sh; michael@0: uint32_t vrf_id; michael@0: /* FIX, for non-bsd is this right? */ michael@0: vrf_id = SCTP_DEFAULT_VRFID; michael@0: if (sa->sa_family != AF_INET || michael@0: ((struct sockaddr_in *)sa)->sin_addr.s_addr == INADDR_ANY) { michael@0: #if defined(__FreeBSD__) || defined(__APPLE__) || defined(__Windows__) michael@0: return; michael@0: #else michael@0: return (NULL); michael@0: #endif michael@0: } michael@0: if (PRC_IS_REDIRECT(cmd)) { michael@0: ip = 0; michael@0: } else if ((unsigned)cmd >= PRC_NCMDS || inetctlerrmap[cmd] == 0) { michael@0: #if defined(__FreeBSD__) || defined(__APPLE__) || defined(__Windows__) michael@0: return; michael@0: #else michael@0: return (NULL); michael@0: #endif michael@0: } michael@0: if (ip) { michael@0: struct sctp_inpcb *inp = NULL; michael@0: struct sctp_tcb *stcb = NULL; michael@0: struct sctp_nets *net = NULL; michael@0: struct sockaddr_in to, from; michael@0: michael@0: sh = (struct sctphdr *)((caddr_t)ip + (ip->ip_hl << 2)); michael@0: bzero(&to, sizeof(to)); michael@0: bzero(&from, sizeof(from)); michael@0: from.sin_family = to.sin_family = AF_INET; michael@0: #ifdef HAVE_SIN_LEN michael@0: from.sin_len = to.sin_len = sizeof(to); michael@0: #endif michael@0: from.sin_port = sh->src_port; michael@0: from.sin_addr = ip->ip_src; michael@0: to.sin_port = sh->dest_port; michael@0: to.sin_addr = ip->ip_dst; michael@0: michael@0: /* michael@0: * 'to' holds the dest of the packet that failed to be sent. michael@0: * 'from' holds our local endpoint address. Thus we reverse michael@0: * the to and the from in the lookup. michael@0: */ michael@0: stcb = sctp_findassociation_addr_sa((struct sockaddr *)&to, michael@0: (struct sockaddr *)&from, michael@0: &inp, &net, 1, vrf_id); michael@0: if (stcb != NULL && inp && (inp->sctp_socket != NULL)) { michael@0: if (cmd != PRC_MSGSIZE) { michael@0: sctp_notify(inp, ip, sh, michael@0: (struct sockaddr *)&to, stcb, michael@0: net); michael@0: } else { michael@0: /* handle possible ICMP size messages */ michael@0: sctp_notify_mbuf(inp, stcb, net, ip, sh); michael@0: } michael@0: } else { michael@0: #if defined(__FreeBSD__) && __FreeBSD_version < 500000 michael@0: /* michael@0: * XXX must be fixed for 5.x and higher, leave for michael@0: * 4.x michael@0: */ michael@0: if (PRC_IS_REDIRECT(cmd) && inp) { michael@0: in_rtchange((struct inpcb *)inp, michael@0: inetctlerrmap[cmd]); michael@0: } michael@0: #endif michael@0: if ((stcb == NULL) && (inp != NULL)) { michael@0: /* reduce ref-count */ michael@0: SCTP_INP_WLOCK(inp); michael@0: SCTP_INP_DECR_REF(inp); michael@0: SCTP_INP_WUNLOCK(inp); michael@0: } michael@0: if (stcb) { michael@0: SCTP_TCB_UNLOCK(stcb); michael@0: } michael@0: } michael@0: } michael@0: #if defined(__FreeBSD__) || defined(__APPLE__) || defined(__Windows__) michael@0: return; michael@0: #else michael@0: return (NULL); michael@0: #endif michael@0: } michael@0: #endif michael@0: #endif michael@0: michael@0: #if defined(__FreeBSD__) michael@0: static int michael@0: sctp_getcred(SYSCTL_HANDLER_ARGS) michael@0: { michael@0: struct xucred xuc; michael@0: struct sockaddr_in addrs[2]; michael@0: struct sctp_inpcb *inp; michael@0: struct sctp_nets *net; michael@0: struct sctp_tcb *stcb; michael@0: int error; michael@0: uint32_t vrf_id; michael@0: michael@0: /* FIX, for non-bsd is this right? */ michael@0: vrf_id = SCTP_DEFAULT_VRFID; michael@0: michael@0: #if __FreeBSD_version > 602000 michael@0: error = priv_check(req->td, PRIV_NETINET_GETCRED); michael@0: michael@0: #elif __FreeBSD_version >= 500000 michael@0: error = suser(req->td); michael@0: #else michael@0: error = suser(req->p); michael@0: #endif michael@0: if (error) michael@0: return (error); michael@0: michael@0: error = SYSCTL_IN(req, addrs, sizeof(addrs)); michael@0: if (error) michael@0: return (error); michael@0: michael@0: stcb = sctp_findassociation_addr_sa(sintosa(&addrs[1]), michael@0: sintosa(&addrs[0]), michael@0: &inp, &net, 1, vrf_id); michael@0: if (stcb == NULL || inp == NULL || inp->sctp_socket == NULL) { michael@0: if ((inp != NULL) && (stcb == NULL)) { michael@0: /* reduce ref-count */ michael@0: SCTP_INP_WLOCK(inp); michael@0: SCTP_INP_DECR_REF(inp); michael@0: goto cred_can_cont; michael@0: } michael@0: michael@0: SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOENT); michael@0: error = ENOENT; michael@0: goto out; michael@0: } michael@0: SCTP_TCB_UNLOCK(stcb); michael@0: /* We use the write lock here, only michael@0: * since in the error leg we need it. michael@0: * If we used RLOCK, then we would have michael@0: * to wlock/decr/unlock/rlock. Which michael@0: * in theory could create a hole. Better michael@0: * to use higher wlock. michael@0: */ michael@0: SCTP_INP_WLOCK(inp); michael@0: cred_can_cont: michael@0: error = cr_canseesocket(req->td->td_ucred, inp->sctp_socket); michael@0: if (error) { michael@0: SCTP_INP_WUNLOCK(inp); michael@0: goto out; michael@0: } michael@0: cru2x(inp->sctp_socket->so_cred, &xuc); michael@0: SCTP_INP_WUNLOCK(inp); michael@0: error = SYSCTL_OUT(req, &xuc, sizeof(struct xucred)); michael@0: out: michael@0: return (error); michael@0: } michael@0: michael@0: SYSCTL_PROC(_net_inet_sctp, OID_AUTO, getcred, CTLTYPE_OPAQUE | CTLFLAG_RW, michael@0: 0, 0, sctp_getcred, "S,ucred", "Get the ucred of a SCTP connection"); michael@0: #endif /* #if defined(__FreeBSD__) */ michael@0: michael@0: michael@0: #ifdef INET michael@0: #if defined(__Panda__) || defined(__Windows__) || defined(__Userspace__) michael@0: int michael@0: #elif defined(__FreeBSD__) && __FreeBSD_version > 690000 michael@0: static void michael@0: #else michael@0: static int michael@0: #endif michael@0: sctp_abort(struct socket *so) michael@0: { michael@0: struct sctp_inpcb *inp; michael@0: uint32_t flags; michael@0: michael@0: inp = (struct sctp_inpcb *)so->so_pcb; michael@0: if (inp == NULL) { michael@0: #if defined(__FreeBSD__) && __FreeBSD_version > 690000 michael@0: return; michael@0: #else michael@0: SCTP_LTRACE_ERR_RET(NULL, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL); michael@0: return (EINVAL); michael@0: #endif michael@0: } michael@0: michael@0: sctp_must_try_again: michael@0: flags = inp->sctp_flags; michael@0: #ifdef SCTP_LOG_CLOSING michael@0: sctp_log_closing(inp, NULL, 17); michael@0: #endif michael@0: if (((flags & SCTP_PCB_FLAGS_SOCKET_GONE) == 0) && michael@0: (atomic_cmpset_int(&inp->sctp_flags, flags, (flags | SCTP_PCB_FLAGS_SOCKET_GONE | SCTP_PCB_FLAGS_CLOSE_IP)))) { michael@0: #ifdef SCTP_LOG_CLOSING michael@0: sctp_log_closing(inp, NULL, 16); michael@0: #endif michael@0: sctp_inpcb_free(inp, SCTP_FREE_SHOULD_USE_ABORT, michael@0: SCTP_CALLED_AFTER_CMPSET_OFCLOSE); michael@0: SOCK_LOCK(so); michael@0: SCTP_SB_CLEAR(so->so_snd); michael@0: /* same for the rcv ones, they are only michael@0: * here for the accounting/select. michael@0: */ michael@0: SCTP_SB_CLEAR(so->so_rcv); michael@0: michael@0: #if defined(__APPLE__) michael@0: so->so_usecount--; michael@0: #else michael@0: /* Now null out the reference, we are completely detached. */ michael@0: so->so_pcb = NULL; michael@0: #endif michael@0: SOCK_UNLOCK(so); michael@0: } else { michael@0: flags = inp->sctp_flags; michael@0: if ((flags & SCTP_PCB_FLAGS_SOCKET_GONE) == 0) { michael@0: goto sctp_must_try_again; michael@0: } michael@0: } michael@0: #if defined(__FreeBSD__) && __FreeBSD_version > 690000 michael@0: return; michael@0: #else michael@0: return (0); michael@0: #endif michael@0: } michael@0: michael@0: #if defined(__Panda__) || defined(__Userspace__) michael@0: int michael@0: #else michael@0: static int michael@0: #endif michael@0: #if defined(__FreeBSD__) && __FreeBSD_version >= 500000 michael@0: sctp_attach(struct socket *so, int proto SCTP_UNUSED, struct thread *p SCTP_UNUSED) michael@0: #elif defined(__Panda__) || defined(__Userspace__) michael@0: sctp_attach(struct socket *so, int proto SCTP_UNUSED, uint32_t vrf_id) michael@0: #elif defined(__Windows__) michael@0: sctp_attach(struct socket *so, int proto SCTP_UNUSED, PKTHREAD p SCTP_UNUSED) michael@0: #else michael@0: sctp_attach(struct socket *so, int proto SCTP_UNUSED, struct proc *p SCTP_UNUSED) michael@0: #endif michael@0: { michael@0: struct sctp_inpcb *inp; michael@0: struct inpcb *ip_inp; michael@0: int error; michael@0: #if !defined(__Panda__) && !defined(__Userspace__) michael@0: uint32_t vrf_id = SCTP_DEFAULT_VRFID; michael@0: #endif michael@0: #ifdef IPSEC michael@0: uint32_t flags; michael@0: #endif michael@0: michael@0: inp = (struct sctp_inpcb *)so->so_pcb; michael@0: if (inp != 0) { michael@0: SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL); michael@0: return (EINVAL); michael@0: } michael@0: if (so->so_snd.sb_hiwat == 0 || so->so_rcv.sb_hiwat == 0) { michael@0: error = SCTP_SORESERVE(so, SCTP_BASE_SYSCTL(sctp_sendspace), SCTP_BASE_SYSCTL(sctp_recvspace)); michael@0: if (error) { michael@0: return (error); michael@0: } michael@0: } michael@0: error = sctp_inpcb_alloc(so, vrf_id); michael@0: if (error) { michael@0: return (error); michael@0: } michael@0: inp = (struct sctp_inpcb *)so->so_pcb; michael@0: SCTP_INP_WLOCK(inp); michael@0: inp->sctp_flags &= ~SCTP_PCB_FLAGS_BOUND_V6; /* I'm not v6! */ michael@0: ip_inp = &inp->ip_inp.inp; michael@0: ip_inp->inp_vflag |= INP_IPV4; michael@0: ip_inp->inp_ip_ttl = MODULE_GLOBAL(ip_defttl); michael@0: #ifdef IPSEC michael@0: #if !(defined(__APPLE__)) michael@0: error = ipsec_init_policy(so, &ip_inp->inp_sp); michael@0: #ifdef SCTP_LOG_CLOSING michael@0: sctp_log_closing(inp, NULL, 17); michael@0: #endif michael@0: if (error != 0) { michael@0: try_again: michael@0: flags = inp->sctp_flags; michael@0: if (((flags & SCTP_PCB_FLAGS_SOCKET_GONE) == 0) && michael@0: (atomic_cmpset_int(&inp->sctp_flags, flags, (flags | SCTP_PCB_FLAGS_SOCKET_GONE | SCTP_PCB_FLAGS_CLOSE_IP)))) { michael@0: #ifdef SCTP_LOG_CLOSING michael@0: sctp_log_closing(inp, NULL, 15); michael@0: #endif michael@0: SCTP_INP_WUNLOCK(inp); michael@0: sctp_inpcb_free(inp, SCTP_FREE_SHOULD_USE_ABORT, michael@0: SCTP_CALLED_AFTER_CMPSET_OFCLOSE); michael@0: } else { michael@0: flags = inp->sctp_flags; michael@0: if ((flags & SCTP_PCB_FLAGS_SOCKET_GONE) == 0) { michael@0: goto try_again; michael@0: } else { michael@0: SCTP_INP_WUNLOCK(inp); michael@0: } michael@0: } michael@0: return (error); michael@0: } michael@0: #endif michael@0: #endif /* IPSEC */ michael@0: SCTP_INP_WUNLOCK(inp); michael@0: return (0); michael@0: } michael@0: michael@0: #if defined(__FreeBSD__) && __FreeBSD_version >= 500000 michael@0: static int michael@0: sctp_bind(struct socket *so, struct sockaddr *addr, struct thread *p) michael@0: { michael@0: #elif defined(__FreeBSD__) || defined(__APPLE__) michael@0: static int michael@0: sctp_bind(struct socket *so, struct sockaddr *addr, struct proc *p) { michael@0: #elif defined(__Panda__) || defined(__Userspace__) michael@0: int michael@0: sctp_bind(struct socket *so, struct sockaddr *addr) { michael@0: void *p = NULL; michael@0: #elif defined(__Windows__) michael@0: static int michael@0: sctp_bind(struct socket *so, struct sockaddr *addr, PKTHREAD p) { michael@0: #else michael@0: static int michael@0: sctp_bind(struct socket *so, struct mbuf *nam, struct proc *p) michael@0: { michael@0: struct sockaddr *addr = nam ? mtod(nam, struct sockaddr *): NULL; michael@0: michael@0: #endif michael@0: struct sctp_inpcb *inp; michael@0: michael@0: inp = (struct sctp_inpcb *)so->so_pcb; michael@0: if (inp == NULL) { michael@0: SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL); michael@0: return (EINVAL); michael@0: } michael@0: if (addr != NULL) { michael@0: #ifdef HAVE_SA_LEN michael@0: if ((addr->sa_family != AF_INET) || michael@0: (addr->sa_len != sizeof(struct sockaddr_in))) { michael@0: #else michael@0: if (addr->sa_family != AF_INET) { michael@0: #endif michael@0: SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL); michael@0: return (EINVAL); michael@0: } michael@0: } michael@0: return (sctp_inpcb_bind(so, addr, NULL, p)); michael@0: } michael@0: michael@0: #endif michael@0: #if defined(__Userspace__) michael@0: michael@0: int michael@0: sctpconn_attach(struct socket *so, int proto SCTP_UNUSED, uint32_t vrf_id) michael@0: { michael@0: struct sctp_inpcb *inp; michael@0: struct inpcb *ip_inp; michael@0: int error; michael@0: michael@0: inp = (struct sctp_inpcb *)so->so_pcb; michael@0: if (inp != NULL) { michael@0: SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL); michael@0: return (EINVAL); michael@0: } michael@0: if (so->so_snd.sb_hiwat == 0 || so->so_rcv.sb_hiwat == 0) { michael@0: error = SCTP_SORESERVE(so, SCTP_BASE_SYSCTL(sctp_sendspace), SCTP_BASE_SYSCTL(sctp_recvspace)); michael@0: if (error) { michael@0: return (error); michael@0: } michael@0: } michael@0: error = sctp_inpcb_alloc(so, vrf_id); michael@0: if (error) { michael@0: return (error); michael@0: } michael@0: inp = (struct sctp_inpcb *)so->so_pcb; michael@0: SCTP_INP_WLOCK(inp); michael@0: inp->sctp_flags &= ~SCTP_PCB_FLAGS_BOUND_V6; michael@0: inp->sctp_flags |= SCTP_PCB_FLAGS_BOUND_CONN; michael@0: ip_inp = &inp->ip_inp.inp; michael@0: ip_inp->inp_vflag |= INP_CONN; michael@0: ip_inp->inp_ip_ttl = MODULE_GLOBAL(ip_defttl); michael@0: SCTP_INP_WUNLOCK(inp); michael@0: return (0); michael@0: } michael@0: michael@0: int michael@0: sctpconn_bind(struct socket *so, struct sockaddr *addr) michael@0: { michael@0: struct sctp_inpcb *inp; michael@0: michael@0: inp = (struct sctp_inpcb *)so->so_pcb; michael@0: if (inp == NULL) { michael@0: SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL); michael@0: return (EINVAL); michael@0: } michael@0: if (addr != NULL) { michael@0: #ifdef HAVE_SA_LEN michael@0: if ((addr->sa_family != AF_CONN) || michael@0: (addr->sa_len != sizeof(struct sockaddr_conn))) { michael@0: #else michael@0: if (addr->sa_family != AF_CONN) { michael@0: #endif michael@0: SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL); michael@0: return (EINVAL); michael@0: } michael@0: } michael@0: return (sctp_inpcb_bind(so, addr, NULL, NULL)); michael@0: } michael@0: michael@0: #endif michael@0: #if (defined(__FreeBSD__) && __FreeBSD_version > 690000) || defined(__Windows__) || defined(__Userspace__) michael@0: void michael@0: sctp_close(struct socket *so) michael@0: { michael@0: struct sctp_inpcb *inp; michael@0: uint32_t flags; michael@0: michael@0: inp = (struct sctp_inpcb *)so->so_pcb; michael@0: if (inp == NULL) michael@0: return; michael@0: michael@0: /* Inform all the lower layer assoc that we michael@0: * are done. michael@0: */ michael@0: sctp_must_try_again: michael@0: flags = inp->sctp_flags; michael@0: #ifdef SCTP_LOG_CLOSING michael@0: sctp_log_closing(inp, NULL, 17); michael@0: #endif michael@0: if (((flags & SCTP_PCB_FLAGS_SOCKET_GONE) == 0) && michael@0: (atomic_cmpset_int(&inp->sctp_flags, flags, (flags | SCTP_PCB_FLAGS_SOCKET_GONE | SCTP_PCB_FLAGS_CLOSE_IP)))) { michael@0: #if defined(__Userspace__) michael@0: if (((so->so_options & SCTP_SO_LINGER) && (so->so_linger == 0)) || michael@0: (so->so_rcv.sb_cc > 0)) { michael@0: #else michael@0: if (((so->so_options & SO_LINGER) && (so->so_linger == 0)) || michael@0: (so->so_rcv.sb_cc > 0)) { michael@0: #endif michael@0: #ifdef SCTP_LOG_CLOSING michael@0: sctp_log_closing(inp, NULL, 13); michael@0: #endif michael@0: sctp_inpcb_free(inp, SCTP_FREE_SHOULD_USE_ABORT, michael@0: SCTP_CALLED_AFTER_CMPSET_OFCLOSE); michael@0: } else { michael@0: #ifdef SCTP_LOG_CLOSING michael@0: sctp_log_closing(inp, NULL, 14); michael@0: #endif michael@0: sctp_inpcb_free(inp, SCTP_FREE_SHOULD_USE_GRACEFUL_CLOSE, michael@0: SCTP_CALLED_AFTER_CMPSET_OFCLOSE); michael@0: } michael@0: /* The socket is now detached, no matter what michael@0: * the state of the SCTP association. michael@0: */ michael@0: SOCK_LOCK(so); michael@0: SCTP_SB_CLEAR(so->so_snd); michael@0: /* same for the rcv ones, they are only michael@0: * here for the accounting/select. michael@0: */ michael@0: SCTP_SB_CLEAR(so->so_rcv); michael@0: michael@0: #if !defined(__APPLE__) michael@0: /* Now null out the reference, we are completely detached. */ michael@0: so->so_pcb = NULL; michael@0: #endif michael@0: SOCK_UNLOCK(so); michael@0: } else { michael@0: flags = inp->sctp_flags; michael@0: if ((flags & SCTP_PCB_FLAGS_SOCKET_GONE) == 0) { michael@0: goto sctp_must_try_again; michael@0: } michael@0: } michael@0: return; michael@0: } michael@0: michael@0: #else michael@0: michael@0: michael@0: int michael@0: sctp_detach(struct socket *so) michael@0: { michael@0: struct sctp_inpcb *inp; michael@0: uint32_t flags; michael@0: michael@0: inp = (struct sctp_inpcb *)so->so_pcb; michael@0: if (inp == NULL) { michael@0: #if defined(__FreeBSD__) && __FreeBSD_version > 690000 michael@0: return; michael@0: #else michael@0: SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL); michael@0: return (EINVAL); michael@0: #endif michael@0: } michael@0: sctp_must_try_again: michael@0: flags = inp->sctp_flags; michael@0: #ifdef SCTP_LOG_CLOSING michael@0: sctp_log_closing(inp, NULL, 17); michael@0: #endif michael@0: if (((flags & SCTP_PCB_FLAGS_SOCKET_GONE) == 0) && michael@0: (atomic_cmpset_int(&inp->sctp_flags, flags, (flags | SCTP_PCB_FLAGS_SOCKET_GONE | SCTP_PCB_FLAGS_CLOSE_IP)))) { michael@0: #if defined(__Userspace__) michael@0: if (((so->so_options & SCTP_SO_LINGER) && (so->so_linger == 0)) || michael@0: (so->so_rcv.sb_cc > 0)) { michael@0: #else michael@0: if (((so->so_options & SO_LINGER) && (so->so_linger == 0)) || michael@0: (so->so_rcv.sb_cc > 0)) { michael@0: #endif michael@0: #ifdef SCTP_LOG_CLOSING michael@0: sctp_log_closing(inp, NULL, 13); michael@0: #endif michael@0: sctp_inpcb_free(inp, SCTP_FREE_SHOULD_USE_ABORT, michael@0: SCTP_CALLED_AFTER_CMPSET_OFCLOSE); michael@0: } else { michael@0: #ifdef SCTP_LOG_CLOSING michael@0: sctp_log_closing(inp, NULL, 13); michael@0: #endif michael@0: sctp_inpcb_free(inp, SCTP_FREE_SHOULD_USE_GRACEFUL_CLOSE, michael@0: SCTP_CALLED_AFTER_CMPSET_OFCLOSE); michael@0: } michael@0: /* The socket is now detached, no matter what michael@0: * the state of the SCTP association. michael@0: */ michael@0: SCTP_SB_CLEAR(so->so_snd); michael@0: /* same for the rcv ones, they are only michael@0: * here for the accounting/select. michael@0: */ michael@0: SCTP_SB_CLEAR(so->so_rcv); michael@0: #if !defined(__APPLE__) michael@0: /* Now disconnect */ michael@0: so->so_pcb = NULL; michael@0: #endif michael@0: } else { michael@0: flags = inp->sctp_flags; michael@0: if ((flags & SCTP_PCB_FLAGS_SOCKET_GONE) == 0) { michael@0: goto sctp_must_try_again; michael@0: } michael@0: } michael@0: #if defined(__FreeBSD__) && __FreeBSD_version > 690000 michael@0: return; michael@0: #else michael@0: return (0); michael@0: #endif michael@0: } michael@0: #endif michael@0: michael@0: #if defined(__Userspace__) michael@0: /* __Userspace__ is not calling sctp_sendm */ michael@0: #endif michael@0: #if !(defined(__Panda__) || defined(__Windows__)) michael@0: int michael@0: #if defined(__FreeBSD__) && __FreeBSD_version >= 500000 michael@0: sctp_sendm(struct socket *so, int flags, struct mbuf *m, struct sockaddr *addr, michael@0: struct mbuf *control, struct thread *p); michael@0: michael@0: #else michael@0: sctp_sendm(struct socket *so, int flags, struct mbuf *m, struct sockaddr *addr, michael@0: struct mbuf *control, struct proc *p); michael@0: michael@0: #endif michael@0: michael@0: int michael@0: #if defined(__FreeBSD__) && __FreeBSD_version >= 500000 michael@0: sctp_sendm(struct socket *so, int flags, struct mbuf *m, struct sockaddr *addr, michael@0: struct mbuf *control, struct thread *p) michael@0: { michael@0: #else michael@0: sctp_sendm(struct socket *so, int flags, struct mbuf *m, struct sockaddr *addr, michael@0: struct mbuf *control, struct proc *p) michael@0: { michael@0: #endif michael@0: struct sctp_inpcb *inp; michael@0: int error; michael@0: michael@0: inp = (struct sctp_inpcb *)so->so_pcb; michael@0: if (inp == NULL) { michael@0: if (control) { michael@0: sctp_m_freem(control); michael@0: control = NULL; michael@0: } michael@0: SCTP_LTRACE_ERR_RET_PKT(m, inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL); michael@0: sctp_m_freem(m); michael@0: return (EINVAL); michael@0: } michael@0: /* Got to have an to address if we are NOT a connected socket */ michael@0: if ((addr == NULL) && michael@0: ((inp->sctp_flags & SCTP_PCB_FLAGS_CONNECTED) || michael@0: (inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE))) { michael@0: goto connected_type; michael@0: } else if (addr == NULL) { michael@0: SCTP_LTRACE_ERR_RET_PKT(m, inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EDESTADDRREQ); michael@0: error = EDESTADDRREQ; michael@0: sctp_m_freem(m); michael@0: if (control) { michael@0: sctp_m_freem(control); michael@0: control = NULL; michael@0: } michael@0: return (error); michael@0: } michael@0: #ifdef INET6 michael@0: if (addr->sa_family != AF_INET) { michael@0: /* must be a v4 address! */ michael@0: SCTP_LTRACE_ERR_RET_PKT(m, inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EDESTADDRREQ); michael@0: sctp_m_freem(m); michael@0: if (control) { michael@0: sctp_m_freem(control); michael@0: control = NULL; michael@0: } michael@0: error = EDESTADDRREQ; michael@0: return (error); michael@0: } michael@0: #endif /* INET6 */ michael@0: connected_type: michael@0: /* now what about control */ michael@0: if (control) { michael@0: if (inp->control) { michael@0: SCTP_PRINTF("huh? control set?\n"); michael@0: sctp_m_freem(inp->control); michael@0: inp->control = NULL; michael@0: } michael@0: inp->control = control; michael@0: } michael@0: /* Place the data */ michael@0: if (inp->pkt) { michael@0: SCTP_BUF_NEXT(inp->pkt_last) = m; michael@0: inp->pkt_last = m; michael@0: } else { michael@0: inp->pkt_last = inp->pkt = m; michael@0: } michael@0: if ( michael@0: #if defined(__FreeBSD__) || defined(__APPLE__) michael@0: /* FreeBSD uses a flag passed */ michael@0: ((flags & PRUS_MORETOCOME) == 0) michael@0: #else michael@0: 1 /* Open BSD does not have any "more to come" michael@0: * indication */ michael@0: #endif michael@0: ) { michael@0: /* michael@0: * note with the current version this code will only be used michael@0: * by OpenBSD-- NetBSD, FreeBSD, and MacOS have methods for michael@0: * re-defining sosend to use the sctp_sosend. One can michael@0: * optionally switch back to this code (by changing back the michael@0: * definitions) but this is not advisable. This code is used michael@0: * by FreeBSD when sending a file with sendfile() though. michael@0: */ michael@0: int ret; michael@0: michael@0: ret = sctp_output(inp, inp->pkt, addr, inp->control, p, flags); michael@0: inp->pkt = NULL; michael@0: inp->control = NULL; michael@0: return (ret); michael@0: } else { michael@0: return (0); michael@0: } michael@0: } michael@0: #endif michael@0: michael@0: int michael@0: sctp_disconnect(struct socket *so) michael@0: { michael@0: struct sctp_inpcb *inp; michael@0: michael@0: inp = (struct sctp_inpcb *)so->so_pcb; michael@0: if (inp == NULL) { michael@0: SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOTCONN); michael@0: return (ENOTCONN); michael@0: } michael@0: SCTP_INP_RLOCK(inp); michael@0: if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) || michael@0: (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL)) { michael@0: if (LIST_EMPTY(&inp->sctp_asoc_list)) { michael@0: /* No connection */ michael@0: SCTP_INP_RUNLOCK(inp); michael@0: return (0); michael@0: } else { michael@0: struct sctp_association *asoc; michael@0: struct sctp_tcb *stcb; michael@0: michael@0: stcb = LIST_FIRST(&inp->sctp_asoc_list); michael@0: if (stcb == NULL) { michael@0: SCTP_INP_RUNLOCK(inp); michael@0: SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL); michael@0: return (EINVAL); michael@0: } michael@0: SCTP_TCB_LOCK(stcb); michael@0: asoc = &stcb->asoc; michael@0: if (stcb->asoc.state & SCTP_STATE_ABOUT_TO_BE_FREED) { michael@0: /* We are about to be freed, out of here */ michael@0: SCTP_TCB_UNLOCK(stcb); michael@0: SCTP_INP_RUNLOCK(inp); michael@0: return (0); michael@0: } michael@0: #if defined(__Userspace__) michael@0: if (((so->so_options & SCTP_SO_LINGER) && michael@0: (so->so_linger == 0)) || michael@0: (so->so_rcv.sb_cc > 0)) { michael@0: #else michael@0: if (((so->so_options & SO_LINGER) && michael@0: (so->so_linger == 0)) || michael@0: (so->so_rcv.sb_cc > 0)) { michael@0: #endif michael@0: if (SCTP_GET_STATE(asoc) != michael@0: SCTP_STATE_COOKIE_WAIT) { michael@0: /* Left with Data unread */ michael@0: struct mbuf *err; michael@0: michael@0: err = sctp_get_mbuf_for_msg(sizeof(struct sctp_paramhdr), 0, M_NOWAIT, 1, MT_DATA); michael@0: if (err) { michael@0: /* michael@0: * Fill in the user michael@0: * initiated abort michael@0: */ michael@0: struct sctp_paramhdr *ph; michael@0: michael@0: ph = mtod(err, struct sctp_paramhdr *); michael@0: SCTP_BUF_LEN(err) = sizeof(struct sctp_paramhdr); michael@0: ph->param_type = htons(SCTP_CAUSE_USER_INITIATED_ABT); michael@0: ph->param_length = htons(SCTP_BUF_LEN(err)); michael@0: } michael@0: sctp_send_abort_tcb(stcb, err, SCTP_SO_LOCKED); michael@0: SCTP_STAT_INCR_COUNTER32(sctps_aborted); michael@0: } michael@0: SCTP_INP_RUNLOCK(inp); michael@0: if ((SCTP_GET_STATE(&stcb->asoc) == SCTP_STATE_OPEN) || michael@0: (SCTP_GET_STATE(&stcb->asoc) == SCTP_STATE_SHUTDOWN_RECEIVED)) { michael@0: SCTP_STAT_DECR_GAUGE32(sctps_currestab); michael@0: } michael@0: (void)sctp_free_assoc(inp, stcb, SCTP_NORMAL_PROC, SCTP_FROM_SCTP_USRREQ+SCTP_LOC_3); michael@0: /* No unlock tcb assoc is gone */ michael@0: return (0); michael@0: } michael@0: if (TAILQ_EMPTY(&asoc->send_queue) && michael@0: TAILQ_EMPTY(&asoc->sent_queue) && michael@0: (asoc->stream_queue_cnt == 0)) { michael@0: /* there is nothing queued to send, so done */ michael@0: if (asoc->locked_on_sending) { michael@0: goto abort_anyway; michael@0: } michael@0: if ((SCTP_GET_STATE(asoc) != SCTP_STATE_SHUTDOWN_SENT) && michael@0: (SCTP_GET_STATE(asoc) != SCTP_STATE_SHUTDOWN_ACK_SENT)) { michael@0: /* only send SHUTDOWN 1st time thru */ michael@0: struct sctp_nets *netp; michael@0: michael@0: if ((SCTP_GET_STATE(asoc) == SCTP_STATE_OPEN) || michael@0: (SCTP_GET_STATE(asoc) == SCTP_STATE_SHUTDOWN_RECEIVED)) { michael@0: SCTP_STAT_DECR_GAUGE32(sctps_currestab); michael@0: } michael@0: SCTP_SET_STATE(asoc, SCTP_STATE_SHUTDOWN_SENT); michael@0: SCTP_CLEAR_SUBSTATE(asoc, SCTP_STATE_SHUTDOWN_PENDING); michael@0: sctp_stop_timers_for_shutdown(stcb); michael@0: if (stcb->asoc.alternate) { michael@0: netp = stcb->asoc.alternate; michael@0: } else { michael@0: netp = stcb->asoc.primary_destination; michael@0: } michael@0: sctp_send_shutdown(stcb,netp); michael@0: sctp_timer_start(SCTP_TIMER_TYPE_SHUTDOWN, michael@0: stcb->sctp_ep, stcb, netp); michael@0: sctp_timer_start(SCTP_TIMER_TYPE_SHUTDOWNGUARD, michael@0: stcb->sctp_ep, stcb, netp); michael@0: sctp_chunk_output(stcb->sctp_ep, stcb, SCTP_OUTPUT_FROM_T3, SCTP_SO_LOCKED); michael@0: } michael@0: } else { michael@0: /* michael@0: * we still got (or just got) data to send, michael@0: * so set SHUTDOWN_PENDING michael@0: */ michael@0: /* michael@0: * XXX sockets draft says that SCTP_EOF michael@0: * should be sent with no data. currently, michael@0: * we will allow user data to be sent first michael@0: * and move to SHUTDOWN-PENDING michael@0: */ michael@0: struct sctp_nets *netp; michael@0: if (stcb->asoc.alternate) { michael@0: netp = stcb->asoc.alternate; michael@0: } else { michael@0: netp = stcb->asoc.primary_destination; michael@0: } michael@0: michael@0: asoc->state |= SCTP_STATE_SHUTDOWN_PENDING; michael@0: sctp_timer_start(SCTP_TIMER_TYPE_SHUTDOWNGUARD, stcb->sctp_ep, stcb, michael@0: netp); michael@0: if (asoc->locked_on_sending) { michael@0: /* Locked to send out the data */ michael@0: struct sctp_stream_queue_pending *sp; michael@0: sp = TAILQ_LAST(&asoc->locked_on_sending->outqueue, sctp_streamhead); michael@0: if (sp == NULL) { michael@0: SCTP_PRINTF("Error, sp is NULL, locked on sending is non-null strm:%d\n", michael@0: asoc->locked_on_sending->stream_no); michael@0: } else { michael@0: if ((sp->length == 0) && (sp->msg_is_complete == 0)) michael@0: asoc->state |= SCTP_STATE_PARTIAL_MSG_LEFT; michael@0: } michael@0: } michael@0: if (TAILQ_EMPTY(&asoc->send_queue) && michael@0: TAILQ_EMPTY(&asoc->sent_queue) && michael@0: (asoc->state & SCTP_STATE_PARTIAL_MSG_LEFT)) { michael@0: struct mbuf *op_err; michael@0: abort_anyway: michael@0: op_err = sctp_get_mbuf_for_msg(sizeof(struct sctp_paramhdr), michael@0: 0, M_NOWAIT, 1, MT_DATA); michael@0: if (op_err) { michael@0: /* Fill in the user initiated abort */ michael@0: struct sctp_paramhdr *ph; michael@0: michael@0: SCTP_BUF_LEN(op_err) = sizeof(struct sctp_paramhdr); michael@0: ph = mtod(op_err, struct sctp_paramhdr *); michael@0: ph->param_type = htons(SCTP_CAUSE_USER_INITIATED_ABT); michael@0: ph->param_length = htons(SCTP_BUF_LEN(op_err)); michael@0: } michael@0: stcb->sctp_ep->last_abort_code = SCTP_FROM_SCTP_USRREQ+SCTP_LOC_4; michael@0: sctp_send_abort_tcb(stcb, op_err, SCTP_SO_LOCKED); michael@0: SCTP_STAT_INCR_COUNTER32(sctps_aborted); michael@0: if ((SCTP_GET_STATE(&stcb->asoc) == SCTP_STATE_OPEN) || michael@0: (SCTP_GET_STATE(&stcb->asoc) == SCTP_STATE_SHUTDOWN_RECEIVED)) { michael@0: SCTP_STAT_DECR_GAUGE32(sctps_currestab); michael@0: } michael@0: SCTP_INP_RUNLOCK(inp); michael@0: (void)sctp_free_assoc(inp, stcb, SCTP_NORMAL_PROC, SCTP_FROM_SCTP_USRREQ+SCTP_LOC_5); michael@0: return (0); michael@0: } else { michael@0: sctp_chunk_output(inp, stcb, SCTP_OUTPUT_FROM_CLOSING, SCTP_SO_LOCKED); michael@0: } michael@0: } michael@0: soisdisconnecting(so); michael@0: SCTP_TCB_UNLOCK(stcb); michael@0: SCTP_INP_RUNLOCK(inp); michael@0: return (0); michael@0: } michael@0: /* not reached */ michael@0: } else { michael@0: /* UDP model does not support this */ michael@0: SCTP_INP_RUNLOCK(inp); michael@0: SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EOPNOTSUPP); michael@0: return (EOPNOTSUPP); michael@0: } michael@0: } michael@0: michael@0: #if defined(__FreeBSD__) || defined(__Windows__) || defined(__Userspace__) michael@0: int michael@0: sctp_flush(struct socket *so, int how) michael@0: { michael@0: /* michael@0: * We will just clear out the values and let michael@0: * subsequent close clear out the data, if any. michael@0: * Note if the user did a shutdown(SHUT_RD) they michael@0: * will not be able to read the data, the socket michael@0: * will block that from happening. michael@0: */ michael@0: struct sctp_inpcb *inp; michael@0: michael@0: inp = (struct sctp_inpcb *)so->so_pcb; michael@0: if (inp == NULL) { michael@0: SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL); michael@0: return (EINVAL); michael@0: } michael@0: SCTP_INP_RLOCK(inp); michael@0: /* For the 1 to many model this does nothing */ michael@0: if (inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) { michael@0: SCTP_INP_RUNLOCK(inp); michael@0: return (0); michael@0: } michael@0: SCTP_INP_RUNLOCK(inp); michael@0: if ((how == PRU_FLUSH_RD) || (how == PRU_FLUSH_RDWR)) { michael@0: /* First make sure the sb will be happy, we don't michael@0: * use these except maybe the count michael@0: */ michael@0: SCTP_INP_WLOCK(inp); michael@0: SCTP_INP_READ_LOCK(inp); michael@0: inp->sctp_flags |= SCTP_PCB_FLAGS_SOCKET_CANT_READ; michael@0: SCTP_INP_READ_UNLOCK(inp); michael@0: SCTP_INP_WUNLOCK(inp); michael@0: so->so_rcv.sb_cc = 0; michael@0: so->so_rcv.sb_mbcnt = 0; michael@0: so->so_rcv.sb_mb = NULL; michael@0: } michael@0: if ((how == PRU_FLUSH_WR) || (how == PRU_FLUSH_RDWR)) { michael@0: /* First make sure the sb will be happy, we don't michael@0: * use these except maybe the count michael@0: */ michael@0: so->so_snd.sb_cc = 0; michael@0: so->so_snd.sb_mbcnt = 0; michael@0: so->so_snd.sb_mb = NULL; michael@0: michael@0: } michael@0: return (0); michael@0: } michael@0: #endif michael@0: michael@0: int michael@0: sctp_shutdown(struct socket *so) michael@0: { michael@0: struct sctp_inpcb *inp; michael@0: michael@0: inp = (struct sctp_inpcb *)so->so_pcb; michael@0: if (inp == NULL) { michael@0: SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL); michael@0: return (EINVAL); michael@0: } michael@0: SCTP_INP_RLOCK(inp); michael@0: /* For UDP model this is a invalid call */ michael@0: if (!((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) || michael@0: (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL))) { michael@0: /* Restore the flags that the soshutdown took away. */ michael@0: #if (defined(__FreeBSD__) && __FreeBSD_version >= 502115) || defined(__Windows__) michael@0: SOCKBUF_LOCK(&so->so_rcv); michael@0: so->so_rcv.sb_state &= ~SBS_CANTRCVMORE; michael@0: SOCKBUF_UNLOCK(&so->so_rcv); michael@0: #else michael@0: so->so_state &= ~SS_CANTRCVMORE; michael@0: #endif michael@0: /* This proc will wakeup for read and do nothing (I hope) */ michael@0: SCTP_INP_RUNLOCK(inp); michael@0: SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EOPNOTSUPP); michael@0: return (EOPNOTSUPP); michael@0: } michael@0: /* michael@0: * Ok if we reach here its the TCP model and it is either a SHUT_WR michael@0: * or SHUT_RDWR. This means we put the shutdown flag against it. michael@0: */ michael@0: { michael@0: struct sctp_tcb *stcb; michael@0: struct sctp_association *asoc; michael@0: michael@0: if ((so->so_state & michael@0: (SS_ISCONNECTED|SS_ISCONNECTING|SS_ISDISCONNECTING)) == 0) { michael@0: SCTP_INP_RUNLOCK(inp); michael@0: return (ENOTCONN); michael@0: } michael@0: socantsendmore(so); michael@0: michael@0: stcb = LIST_FIRST(&inp->sctp_asoc_list); michael@0: if (stcb == NULL) { michael@0: /* michael@0: * Ok we hit the case that the shutdown call was michael@0: * made after an abort or something. Nothing to do michael@0: * now. michael@0: */ michael@0: SCTP_INP_RUNLOCK(inp); michael@0: return (0); michael@0: } michael@0: SCTP_TCB_LOCK(stcb); michael@0: asoc = &stcb->asoc; michael@0: if (TAILQ_EMPTY(&asoc->send_queue) && michael@0: TAILQ_EMPTY(&asoc->sent_queue) && michael@0: (asoc->stream_queue_cnt == 0)) { michael@0: if (asoc->locked_on_sending) { michael@0: goto abort_anyway; michael@0: } michael@0: /* there is nothing queued to send, so I'm done... */ michael@0: if (SCTP_GET_STATE(asoc) != SCTP_STATE_SHUTDOWN_SENT) { michael@0: /* only send SHUTDOWN the first time through */ michael@0: struct sctp_nets *netp; michael@0: michael@0: if ((SCTP_GET_STATE(asoc) == SCTP_STATE_OPEN) || michael@0: (SCTP_GET_STATE(asoc) == SCTP_STATE_SHUTDOWN_RECEIVED)) { michael@0: SCTP_STAT_DECR_GAUGE32(sctps_currestab); michael@0: } michael@0: SCTP_SET_STATE(asoc, SCTP_STATE_SHUTDOWN_SENT); michael@0: SCTP_CLEAR_SUBSTATE(asoc, SCTP_STATE_SHUTDOWN_PENDING); michael@0: sctp_stop_timers_for_shutdown(stcb); michael@0: if (stcb->asoc.alternate) { michael@0: netp = stcb->asoc.alternate; michael@0: } else { michael@0: netp = stcb->asoc.primary_destination; michael@0: } michael@0: sctp_send_shutdown(stcb, netp); michael@0: sctp_timer_start(SCTP_TIMER_TYPE_SHUTDOWN, michael@0: stcb->sctp_ep, stcb, netp); michael@0: sctp_timer_start(SCTP_TIMER_TYPE_SHUTDOWNGUARD, michael@0: stcb->sctp_ep, stcb, netp); michael@0: sctp_chunk_output(stcb->sctp_ep, stcb, SCTP_OUTPUT_FROM_T3, SCTP_SO_LOCKED); michael@0: } michael@0: } else { michael@0: /* michael@0: * we still got (or just got) data to send, so set michael@0: * SHUTDOWN_PENDING michael@0: */ michael@0: struct sctp_nets *netp; michael@0: if (stcb->asoc.alternate) { michael@0: netp = stcb->asoc.alternate; michael@0: } else { michael@0: netp = stcb->asoc.primary_destination; michael@0: } michael@0: michael@0: asoc->state |= SCTP_STATE_SHUTDOWN_PENDING; michael@0: sctp_timer_start(SCTP_TIMER_TYPE_SHUTDOWNGUARD, stcb->sctp_ep, stcb, michael@0: netp); michael@0: michael@0: if (asoc->locked_on_sending) { michael@0: /* Locked to send out the data */ michael@0: struct sctp_stream_queue_pending *sp; michael@0: sp = TAILQ_LAST(&asoc->locked_on_sending->outqueue, sctp_streamhead); michael@0: if (sp == NULL) { michael@0: SCTP_PRINTF("Error, sp is NULL, locked on sending is non-null strm:%d\n", michael@0: asoc->locked_on_sending->stream_no); michael@0: } else { michael@0: if ((sp->length == 0) && (sp-> msg_is_complete == 0)) { michael@0: asoc->state |= SCTP_STATE_PARTIAL_MSG_LEFT; michael@0: } michael@0: } michael@0: } michael@0: if (TAILQ_EMPTY(&asoc->send_queue) && michael@0: TAILQ_EMPTY(&asoc->sent_queue) && michael@0: (asoc->state & SCTP_STATE_PARTIAL_MSG_LEFT)) { michael@0: struct mbuf *op_err; michael@0: abort_anyway: michael@0: op_err = sctp_get_mbuf_for_msg(sizeof(struct sctp_paramhdr), michael@0: 0, M_NOWAIT, 1, MT_DATA); michael@0: if (op_err) { michael@0: /* Fill in the user initiated abort */ michael@0: struct sctp_paramhdr *ph; michael@0: michael@0: SCTP_BUF_LEN(op_err) = sizeof(struct sctp_paramhdr); michael@0: ph = mtod(op_err, struct sctp_paramhdr *); michael@0: ph->param_type = htons( SCTP_CAUSE_USER_INITIATED_ABT); michael@0: ph->param_length = htons(SCTP_BUF_LEN(op_err)); michael@0: } michael@0: stcb->sctp_ep->last_abort_code = SCTP_FROM_SCTP_USRREQ+SCTP_LOC_6; michael@0: sctp_abort_an_association(stcb->sctp_ep, stcb, michael@0: op_err, SCTP_SO_LOCKED); michael@0: goto skip_unlock; michael@0: } else { michael@0: sctp_chunk_output(inp, stcb, SCTP_OUTPUT_FROM_CLOSING, SCTP_SO_LOCKED); michael@0: } michael@0: } michael@0: SCTP_TCB_UNLOCK(stcb); michael@0: } michael@0: skip_unlock: michael@0: SCTP_INP_RUNLOCK(inp); michael@0: return (0); michael@0: } michael@0: michael@0: /* michael@0: * copies a "user" presentable address and removes embedded scope, etc. michael@0: * returns 0 on success, 1 on error michael@0: */ michael@0: static uint32_t michael@0: sctp_fill_user_address(struct sockaddr_storage *ss, struct sockaddr *sa) michael@0: { michael@0: #ifdef INET6 michael@0: #if defined(SCTP_EMBEDDED_V6_SCOPE) michael@0: struct sockaddr_in6 lsa6; michael@0: michael@0: sa = (struct sockaddr *)sctp_recover_scope((struct sockaddr_in6 *)sa, michael@0: &lsa6); michael@0: #endif michael@0: #endif michael@0: #ifdef HAVE_SA_LEN michael@0: memcpy(ss, sa, sa->sa_len); michael@0: #else michael@0: switch (sa->sa_family) { michael@0: #ifdef INET michael@0: case AF_INET: michael@0: memcpy(ss, sa, sizeof(struct sockaddr_in)); michael@0: break; michael@0: #endif michael@0: #ifdef INET6 michael@0: case AF_INET6: michael@0: memcpy(ss, sa, sizeof(struct sockaddr_in6)); michael@0: break; michael@0: #endif michael@0: #if defined(__Userspace__) michael@0: case AF_CONN: michael@0: memcpy(ss, sa, sizeof(struct sockaddr_conn)); michael@0: break; michael@0: #endif michael@0: default: michael@0: /* TSNH */ michael@0: break; michael@0: } michael@0: #endif michael@0: return (0); michael@0: } michael@0: michael@0: michael@0: michael@0: /* michael@0: * NOTE: assumes addr lock is held michael@0: */ michael@0: static size_t michael@0: sctp_fill_up_addresses_vrf(struct sctp_inpcb *inp, michael@0: struct sctp_tcb *stcb, michael@0: size_t limit, michael@0: struct sockaddr_storage *sas, michael@0: uint32_t vrf_id) michael@0: { michael@0: struct sctp_ifn *sctp_ifn; michael@0: struct sctp_ifa *sctp_ifa; michael@0: size_t actual; michael@0: int loopback_scope; michael@0: #if defined(INET) michael@0: int ipv4_local_scope, ipv4_addr_legal; michael@0: #endif michael@0: #if defined(INET6) michael@0: int local_scope, site_scope, ipv6_addr_legal; michael@0: #endif michael@0: #if defined(__Userspace__) michael@0: int conn_addr_legal; michael@0: #endif michael@0: struct sctp_vrf *vrf; michael@0: michael@0: actual = 0; michael@0: if (limit <= 0) michael@0: return (actual); michael@0: michael@0: if (stcb) { michael@0: /* Turn on all the appropriate scope */ michael@0: loopback_scope = stcb->asoc.scope.loopback_scope; michael@0: #if defined(INET) michael@0: ipv4_local_scope = stcb->asoc.scope.ipv4_local_scope; michael@0: ipv4_addr_legal = stcb->asoc.scope.ipv4_addr_legal; michael@0: #endif michael@0: #if defined(INET6) michael@0: local_scope = stcb->asoc.scope.local_scope; michael@0: site_scope = stcb->asoc.scope.site_scope; michael@0: ipv6_addr_legal = stcb->asoc.scope.ipv6_addr_legal; michael@0: #endif michael@0: #if defined(__Userspace__) michael@0: conn_addr_legal = stcb->asoc.scope.conn_addr_legal; michael@0: #endif michael@0: } else { michael@0: /* Use generic values for endpoints. */ michael@0: loopback_scope = 1; michael@0: #if defined(INET) michael@0: ipv4_local_scope = 1; michael@0: #endif michael@0: #if defined(INET6) michael@0: local_scope = 1; michael@0: site_scope = 1; michael@0: #endif michael@0: if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) { michael@0: #if defined(INET6) michael@0: ipv6_addr_legal = 1; michael@0: #endif michael@0: #if defined(INET) michael@0: if (SCTP_IPV6_V6ONLY(inp)) { michael@0: ipv4_addr_legal = 0; michael@0: } else { michael@0: ipv4_addr_legal = 1; michael@0: } michael@0: #endif michael@0: #if defined(__Userspace__) michael@0: conn_addr_legal = 0; michael@0: #endif michael@0: } else { michael@0: #if defined(INET6) michael@0: ipv6_addr_legal = 0; michael@0: #endif michael@0: #if defined(__Userspace__) michael@0: if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_CONN) { michael@0: conn_addr_legal = 1; michael@0: #if defined(INET) michael@0: ipv4_addr_legal = 0; michael@0: #endif michael@0: } else { michael@0: conn_addr_legal = 0; michael@0: #if defined(INET) michael@0: ipv4_addr_legal = 1; michael@0: #endif michael@0: } michael@0: #else michael@0: #if defined(INET) michael@0: ipv4_addr_legal = 1; michael@0: #endif michael@0: #endif michael@0: } michael@0: } michael@0: vrf = sctp_find_vrf(vrf_id); michael@0: if (vrf == NULL) { michael@0: return (0); michael@0: } michael@0: if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUNDALL) { michael@0: LIST_FOREACH(sctp_ifn, &vrf->ifnlist, next_ifn) { michael@0: if ((loopback_scope == 0) && michael@0: SCTP_IFN_IS_IFT_LOOP(sctp_ifn)) { michael@0: /* Skip loopback if loopback_scope not set */ michael@0: continue; michael@0: } michael@0: LIST_FOREACH(sctp_ifa, &sctp_ifn->ifalist, next_ifa) { michael@0: if (stcb) { michael@0: /* michael@0: * For the BOUND-ALL case, the list michael@0: * associated with a TCB is Always michael@0: * considered a reverse list.. i.e. michael@0: * it lists addresses that are NOT michael@0: * part of the association. If this michael@0: * is one of those we must skip it. michael@0: */ michael@0: if (sctp_is_addr_restricted(stcb, michael@0: sctp_ifa)) { michael@0: continue; michael@0: } michael@0: } michael@0: switch (sctp_ifa->address.sa.sa_family) { michael@0: #ifdef INET michael@0: case AF_INET: michael@0: if (ipv4_addr_legal) { michael@0: struct sockaddr_in *sin; michael@0: michael@0: sin = (struct sockaddr_in *)&sctp_ifa->address.sa; michael@0: if (sin->sin_addr.s_addr == 0) { michael@0: /* michael@0: * we skip unspecifed michael@0: * addresses michael@0: */ michael@0: continue; michael@0: } michael@0: if ((ipv4_local_scope == 0) && michael@0: (IN4_ISPRIVATE_ADDRESS(&sin->sin_addr))) { michael@0: continue; michael@0: } michael@0: #ifdef INET6 michael@0: if (sctp_is_feature_on(inp,SCTP_PCB_FLAGS_NEEDS_MAPPED_V4)) { michael@0: in6_sin_2_v4mapsin6(sin, (struct sockaddr_in6 *)sas); michael@0: ((struct sockaddr_in6 *)sas)->sin6_port = inp->sctp_lport; michael@0: sas = (struct sockaddr_storage *)((caddr_t)sas + sizeof(struct sockaddr_in6)); michael@0: actual += sizeof(struct sockaddr_in6); michael@0: } else { michael@0: #endif michael@0: memcpy(sas, sin, sizeof(*sin)); michael@0: ((struct sockaddr_in *)sas)->sin_port = inp->sctp_lport; michael@0: sas = (struct sockaddr_storage *)((caddr_t)sas + sizeof(*sin)); michael@0: actual += sizeof(*sin); michael@0: #ifdef INET6 michael@0: } michael@0: #endif michael@0: if (actual >= limit) { michael@0: return (actual); michael@0: } michael@0: } else { michael@0: continue; michael@0: } michael@0: break; michael@0: #endif michael@0: #ifdef INET6 michael@0: case AF_INET6: michael@0: if (ipv6_addr_legal) { michael@0: struct sockaddr_in6 *sin6; michael@0: michael@0: #if defined(SCTP_EMBEDDED_V6_SCOPE) && !defined(SCTP_KAME) michael@0: struct sockaddr_in6 lsa6; michael@0: #endif michael@0: sin6 = (struct sockaddr_in6 *)&sctp_ifa->address.sa; michael@0: if (IN6_IS_ADDR_UNSPECIFIED(&sin6->sin6_addr)) { michael@0: /* michael@0: * we skip unspecifed michael@0: * addresses michael@0: */ michael@0: continue; michael@0: } michael@0: if (IN6_IS_ADDR_LINKLOCAL(&sin6->sin6_addr)) { michael@0: if (local_scope == 0) michael@0: continue; michael@0: #if defined(SCTP_EMBEDDED_V6_SCOPE) michael@0: if (sin6->sin6_scope_id == 0) { michael@0: #ifdef SCTP_KAME michael@0: if (sa6_recoverscope(sin6) != 0) michael@0: /* michael@0: * bad link michael@0: * local michael@0: * address michael@0: */ michael@0: continue; michael@0: #else michael@0: lsa6 = *sin6; michael@0: if (in6_recoverscope(&lsa6, michael@0: &lsa6.sin6_addr, michael@0: NULL)) michael@0: /* michael@0: * bad link michael@0: * local michael@0: * address michael@0: */ michael@0: continue; michael@0: sin6 = &lsa6; michael@0: #endif /* SCTP_KAME */ michael@0: } michael@0: #endif /* SCTP_EMBEDDED_V6_SCOPE */ michael@0: } michael@0: if ((site_scope == 0) && michael@0: (IN6_IS_ADDR_SITELOCAL(&sin6->sin6_addr))) { michael@0: continue; michael@0: } michael@0: memcpy(sas, sin6, sizeof(*sin6)); michael@0: ((struct sockaddr_in6 *)sas)->sin6_port = inp->sctp_lport; michael@0: sas = (struct sockaddr_storage *)((caddr_t)sas + sizeof(*sin6)); michael@0: actual += sizeof(*sin6); michael@0: if (actual >= limit) { michael@0: return (actual); michael@0: } michael@0: } else { michael@0: continue; michael@0: } michael@0: break; michael@0: #endif michael@0: #if defined(__Userspace__) michael@0: case AF_CONN: michael@0: if (conn_addr_legal) { michael@0: memcpy(sas, &sctp_ifa->address.sconn, sizeof(struct sockaddr_conn)); michael@0: ((struct sockaddr_conn *)sas)->sconn_port = inp->sctp_lport; michael@0: sas = (struct sockaddr_storage *)((caddr_t)sas + sizeof(struct sockaddr_conn)); michael@0: actual += sizeof(struct sockaddr_conn); michael@0: if (actual >= limit) { michael@0: return (actual); michael@0: } michael@0: } else { michael@0: continue; michael@0: } michael@0: #endif michael@0: default: michael@0: /* TSNH */ michael@0: break; michael@0: } michael@0: } michael@0: } michael@0: } else { michael@0: struct sctp_laddr *laddr; michael@0: #ifndef HAVE_SA_LEN michael@0: uint32_t sa_len = 0; michael@0: #endif michael@0: michael@0: LIST_FOREACH(laddr, &inp->sctp_addr_list, sctp_nxt_addr) { michael@0: if (stcb) { michael@0: if (sctp_is_addr_restricted(stcb, laddr->ifa)) { michael@0: continue; michael@0: } michael@0: } michael@0: if (sctp_fill_user_address(sas, &laddr->ifa->address.sa)) michael@0: continue; michael@0: switch (laddr->ifa->address.sa.sa_family) { michael@0: #ifdef INET michael@0: case AF_INET: michael@0: ((struct sockaddr_in *)sas)->sin_port = inp->sctp_lport; michael@0: break; michael@0: #endif michael@0: #ifdef INET6 michael@0: case AF_INET6: michael@0: ((struct sockaddr_in6 *)sas)->sin6_port = inp->sctp_lport; michael@0: break; michael@0: #endif michael@0: #if defined(__Userspace__) michael@0: case AF_CONN: michael@0: ((struct sockaddr_conn *)sas)->sconn_port = inp->sctp_lport; michael@0: break; michael@0: #endif michael@0: default: michael@0: /* TSNH */ michael@0: break; michael@0: } michael@0: #ifdef HAVE_SA_LEN michael@0: sas = (struct sockaddr_storage *)((caddr_t)sas + michael@0: laddr->ifa->address.sa.sa_len); michael@0: actual += laddr->ifa->address.sa.sa_len; michael@0: #else michael@0: switch (laddr->ifa->address.sa.sa_family) { michael@0: #ifdef INET michael@0: case AF_INET: michael@0: sa_len = sizeof(struct sockaddr_in); michael@0: break; michael@0: #endif michael@0: #ifdef INET6 michael@0: case AF_INET6: michael@0: sa_len = sizeof(struct sockaddr_in6); michael@0: break; michael@0: #endif michael@0: #if defined(__Userspace__) michael@0: case AF_CONN: michael@0: sa_len = sizeof(struct sockaddr_conn); michael@0: break; michael@0: #endif michael@0: default: michael@0: /* TSNH */ michael@0: break; michael@0: } michael@0: sas = (struct sockaddr_storage *)((caddr_t)sas + sa_len); michael@0: actual += sa_len; michael@0: #endif michael@0: if (actual >= limit) { michael@0: return (actual); michael@0: } michael@0: } michael@0: } michael@0: return (actual); michael@0: } michael@0: michael@0: static size_t michael@0: sctp_fill_up_addresses(struct sctp_inpcb *inp, michael@0: struct sctp_tcb *stcb, michael@0: size_t limit, michael@0: struct sockaddr_storage *sas) michael@0: { michael@0: size_t size = 0; michael@0: #ifdef SCTP_MVRF michael@0: uint32_t id; michael@0: #endif michael@0: michael@0: SCTP_IPI_ADDR_RLOCK(); michael@0: #ifdef SCTP_MVRF michael@0: /* michael@0: * FIX ME: ?? this WILL report duplicate addresses if they appear michael@0: * in more than one VRF. michael@0: */ michael@0: /* fill up addresses for all VRFs on the endpoint */ michael@0: for (id = 0; (id < inp->num_vrfs) && (size < limit); id++) { michael@0: size += sctp_fill_up_addresses_vrf(inp, stcb, limit, sas, michael@0: inp->m_vrf_ids[id]); michael@0: sas = (struct sockaddr_storage *)((caddr_t)sas + size); michael@0: } michael@0: #else michael@0: /* fill up addresses for the endpoint's default vrf */ michael@0: size = sctp_fill_up_addresses_vrf(inp, stcb, limit, sas, michael@0: inp->def_vrf_id); michael@0: #endif michael@0: SCTP_IPI_ADDR_RUNLOCK(); michael@0: return (size); michael@0: } michael@0: michael@0: /* michael@0: * NOTE: assumes addr lock is held michael@0: */ michael@0: static int michael@0: sctp_count_max_addresses_vrf(struct sctp_inpcb *inp, uint32_t vrf_id) michael@0: { michael@0: int cnt = 0; michael@0: struct sctp_vrf *vrf = NULL; michael@0: michael@0: /* michael@0: * In both sub-set bound an bound_all cases we return the MAXIMUM michael@0: * number of addresses that you COULD get. In reality the sub-set michael@0: * bound may have an exclusion list for a given TCB OR in the michael@0: * bound-all case a TCB may NOT include the loopback or other michael@0: * addresses as well. michael@0: */ michael@0: vrf = sctp_find_vrf(vrf_id); michael@0: if (vrf == NULL) { michael@0: return (0); michael@0: } michael@0: if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUNDALL) { michael@0: struct sctp_ifn *sctp_ifn; michael@0: struct sctp_ifa *sctp_ifa; michael@0: michael@0: LIST_FOREACH(sctp_ifn, &vrf->ifnlist, next_ifn) { michael@0: LIST_FOREACH(sctp_ifa, &sctp_ifn->ifalist, next_ifa) { michael@0: /* Count them if they are the right type */ michael@0: switch (sctp_ifa->address.sa.sa_family) { michael@0: #ifdef INET michael@0: case AF_INET: michael@0: if (sctp_is_feature_on(inp,SCTP_PCB_FLAGS_NEEDS_MAPPED_V4)) michael@0: cnt += sizeof(struct sockaddr_in6); michael@0: else michael@0: cnt += sizeof(struct sockaddr_in); michael@0: break; michael@0: #endif michael@0: #ifdef INET6 michael@0: case AF_INET6: michael@0: cnt += sizeof(struct sockaddr_in6); michael@0: break; michael@0: #endif michael@0: #if defined(__Userspace__) michael@0: case AF_CONN: michael@0: cnt += sizeof(struct sockaddr_conn); michael@0: break; michael@0: #endif michael@0: default: michael@0: break; michael@0: } michael@0: } michael@0: } michael@0: } else { michael@0: struct sctp_laddr *laddr; michael@0: michael@0: LIST_FOREACH(laddr, &inp->sctp_addr_list, sctp_nxt_addr) { michael@0: switch (laddr->ifa->address.sa.sa_family) { michael@0: #ifdef INET michael@0: case AF_INET: michael@0: if (sctp_is_feature_on(inp,SCTP_PCB_FLAGS_NEEDS_MAPPED_V4)) michael@0: cnt += sizeof(struct sockaddr_in6); michael@0: else michael@0: cnt += sizeof(struct sockaddr_in); michael@0: break; michael@0: #endif michael@0: #ifdef INET6 michael@0: case AF_INET6: michael@0: cnt += sizeof(struct sockaddr_in6); michael@0: break; michael@0: #endif michael@0: #if defined(__Userspace__) michael@0: case AF_CONN: michael@0: cnt += sizeof(struct sockaddr_conn); michael@0: break; michael@0: #endif michael@0: default: michael@0: break; michael@0: } michael@0: } michael@0: } michael@0: return (cnt); michael@0: } michael@0: michael@0: static int michael@0: sctp_count_max_addresses(struct sctp_inpcb *inp) michael@0: { michael@0: int cnt = 0; michael@0: #ifdef SCTP_MVRF michael@0: int id; michael@0: #endif michael@0: michael@0: SCTP_IPI_ADDR_RLOCK(); michael@0: #ifdef SCTP_MVRF michael@0: /* michael@0: * FIX ME: ?? this WILL count duplicate addresses if they appear michael@0: * in more than one VRF. michael@0: */ michael@0: /* count addresses for all VRFs on the endpoint */ michael@0: for (id = 0; id < inp->num_vrfs; id++) { michael@0: cnt += sctp_count_max_addresses_vrf(inp, inp->m_vrf_ids[id]); michael@0: } michael@0: #else michael@0: /* count addresses for the endpoint's default VRF */ michael@0: cnt = sctp_count_max_addresses_vrf(inp, inp->def_vrf_id); michael@0: #endif michael@0: SCTP_IPI_ADDR_RUNLOCK(); michael@0: return (cnt); michael@0: } michael@0: michael@0: static int michael@0: sctp_do_connect_x(struct socket *so, struct sctp_inpcb *inp, void *optval, michael@0: size_t optsize, void *p, int delay) michael@0: { michael@0: int error = 0; michael@0: int creat_lock_on = 0; michael@0: struct sctp_tcb *stcb = NULL; michael@0: struct sockaddr *sa; michael@0: int num_v6 = 0, num_v4 = 0, *totaddrp, totaddr; michael@0: uint32_t vrf_id; michael@0: int bad_addresses = 0; michael@0: sctp_assoc_t *a_id; michael@0: michael@0: SCTPDBG(SCTP_DEBUG_PCB1, "Connectx called\n"); michael@0: michael@0: if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) && michael@0: (inp->sctp_flags & SCTP_PCB_FLAGS_CONNECTED)) { michael@0: /* We are already connected AND the TCP model */ michael@0: SCTP_LTRACE_ERR_RET(inp, stcb, NULL, SCTP_FROM_SCTP_USRREQ, EADDRINUSE); michael@0: return (EADDRINUSE); michael@0: } michael@0: michael@0: if ((inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) && michael@0: (sctp_is_feature_off(inp, SCTP_PCB_FLAGS_PORTREUSE))) { michael@0: SCTP_LTRACE_ERR_RET(inp, stcb, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL); michael@0: return (EINVAL); michael@0: } michael@0: michael@0: if (inp->sctp_flags & SCTP_PCB_FLAGS_CONNECTED) { michael@0: SCTP_INP_RLOCK(inp); michael@0: stcb = LIST_FIRST(&inp->sctp_asoc_list); michael@0: SCTP_INP_RUNLOCK(inp); michael@0: } michael@0: if (stcb) { michael@0: SCTP_LTRACE_ERR_RET(inp, stcb, NULL, SCTP_FROM_SCTP_USRREQ, EALREADY); michael@0: return (EALREADY); michael@0: } michael@0: SCTP_INP_INCR_REF(inp); michael@0: SCTP_ASOC_CREATE_LOCK(inp); michael@0: creat_lock_on = 1; michael@0: if ((inp->sctp_flags & SCTP_PCB_FLAGS_SOCKET_ALLGONE) || michael@0: (inp->sctp_flags & SCTP_PCB_FLAGS_SOCKET_GONE)) { michael@0: SCTP_LTRACE_ERR_RET(inp, stcb, NULL, SCTP_FROM_SCTP_USRREQ, EFAULT); michael@0: error = EFAULT; michael@0: goto out_now; michael@0: } michael@0: totaddrp = (int *)optval; michael@0: totaddr = *totaddrp; michael@0: sa = (struct sockaddr *)(totaddrp + 1); michael@0: stcb = sctp_connectx_helper_find(inp, sa, &totaddr, &num_v4, &num_v6, &error, (optsize - sizeof(int)), &bad_addresses); michael@0: if ((stcb != NULL) || bad_addresses) { michael@0: /* Already have or am bring up an association */ michael@0: SCTP_ASOC_CREATE_UNLOCK(inp); michael@0: creat_lock_on = 0; michael@0: if (stcb) michael@0: SCTP_TCB_UNLOCK(stcb); michael@0: if (bad_addresses == 0) { michael@0: SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EALREADY); michael@0: error = EALREADY; michael@0: } michael@0: goto out_now; michael@0: } michael@0: #ifdef INET6 michael@0: if (((inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) == 0) && michael@0: (num_v6 > 0)) { michael@0: error = EINVAL; michael@0: goto out_now; michael@0: } michael@0: if ((inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) && michael@0: (num_v4 > 0)) { michael@0: struct in6pcb *inp6; michael@0: michael@0: inp6 = (struct in6pcb *)inp; michael@0: if (SCTP_IPV6_V6ONLY(inp6)) { michael@0: /* michael@0: * if IPV6_V6ONLY flag, ignore connections destined michael@0: * to a v4 addr or v4-mapped addr michael@0: */ michael@0: SCTP_LTRACE_ERR_RET(inp, stcb, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL); michael@0: error = EINVAL; michael@0: goto out_now; michael@0: } michael@0: } michael@0: #endif /* INET6 */ michael@0: if ((inp->sctp_flags & SCTP_PCB_FLAGS_UNBOUND) == michael@0: SCTP_PCB_FLAGS_UNBOUND) { michael@0: /* Bind a ephemeral port */ michael@0: error = sctp_inpcb_bind(so, NULL, NULL, p); michael@0: if (error) { michael@0: goto out_now; michael@0: } michael@0: } michael@0: michael@0: /* FIX ME: do we want to pass in a vrf on the connect call? */ michael@0: vrf_id = inp->def_vrf_id; michael@0: michael@0: michael@0: /* We are GOOD to go */ michael@0: stcb = sctp_aloc_assoc(inp, sa, &error, 0, vrf_id, michael@0: #if defined(__FreeBSD__) && __FreeBSD_version >= 500000 michael@0: (struct thread *)p michael@0: #elif defined(__Windows__) michael@0: (PKTHREAD)p michael@0: #else michael@0: (struct proc *)p michael@0: #endif michael@0: ); michael@0: if (stcb == NULL) { michael@0: /* Gak! no memory */ michael@0: goto out_now; michael@0: } michael@0: if (stcb->sctp_ep->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) { michael@0: stcb->sctp_ep->sctp_flags |= SCTP_PCB_FLAGS_CONNECTED; michael@0: /* Set the connected flag so we can queue data */ michael@0: soisconnecting(so); michael@0: } michael@0: SCTP_SET_STATE(&stcb->asoc, SCTP_STATE_COOKIE_WAIT); michael@0: /* move to second address */ michael@0: switch (sa->sa_family) { michael@0: #ifdef INET michael@0: case AF_INET: michael@0: sa = (struct sockaddr *)((caddr_t)sa + sizeof(struct sockaddr_in)); michael@0: break; michael@0: #endif michael@0: #ifdef INET6 michael@0: case AF_INET6: michael@0: sa = (struct sockaddr *)((caddr_t)sa + sizeof(struct sockaddr_in6)); michael@0: break; michael@0: #endif michael@0: default: michael@0: break; michael@0: } michael@0: michael@0: error = 0; michael@0: sctp_connectx_helper_add(stcb, sa, (totaddr-1), &error); michael@0: /* Fill in the return id */ michael@0: if (error) { michael@0: (void)sctp_free_assoc(inp, stcb, SCTP_PCBFREE_FORCE, SCTP_FROM_SCTP_USRREQ+SCTP_LOC_6); michael@0: goto out_now; michael@0: } michael@0: a_id = (sctp_assoc_t *)optval; michael@0: *a_id = sctp_get_associd(stcb); michael@0: michael@0: /* initialize authentication parameters for the assoc */ michael@0: sctp_initialize_auth_params(inp, stcb); michael@0: michael@0: if (delay) { michael@0: /* doing delayed connection */ michael@0: stcb->asoc.delayed_connection = 1; michael@0: sctp_timer_start(SCTP_TIMER_TYPE_INIT, inp, stcb, stcb->asoc.primary_destination); michael@0: } else { michael@0: (void)SCTP_GETTIME_TIMEVAL(&stcb->asoc.time_entered); michael@0: sctp_send_initiate(inp, stcb, SCTP_SO_LOCKED); michael@0: } michael@0: SCTP_TCB_UNLOCK(stcb); michael@0: if (stcb->sctp_ep->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) { michael@0: stcb->sctp_ep->sctp_flags |= SCTP_PCB_FLAGS_CONNECTED; michael@0: /* Set the connected flag so we can queue data */ michael@0: soisconnecting(so); michael@0: } michael@0: out_now: michael@0: if (creat_lock_on) { michael@0: SCTP_ASOC_CREATE_UNLOCK(inp); michael@0: } michael@0: SCTP_INP_DECR_REF(inp); michael@0: return (error); michael@0: } michael@0: michael@0: #define SCTP_FIND_STCB(inp, stcb, assoc_id) { \ michael@0: if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||\ michael@0: (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL)) { \ michael@0: SCTP_INP_RLOCK(inp); \ michael@0: stcb = LIST_FIRST(&inp->sctp_asoc_list); \ michael@0: if (stcb) { \ michael@0: SCTP_TCB_LOCK(stcb); \ michael@0: } \ michael@0: SCTP_INP_RUNLOCK(inp); \ michael@0: } else if (assoc_id > SCTP_ALL_ASSOC) { \ michael@0: stcb = sctp_findassociation_ep_asocid(inp, assoc_id, 1); \ michael@0: if (stcb == NULL) { \ michael@0: SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOENT); \ michael@0: error = ENOENT; \ michael@0: break; \ michael@0: } \ michael@0: } else { \ michael@0: stcb = NULL; \ michael@0: } \ michael@0: } michael@0: michael@0: michael@0: #define SCTP_CHECK_AND_CAST(destp, srcp, type, size) {\ michael@0: if (size < sizeof(type)) { \ michael@0: SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL); \ michael@0: error = EINVAL; \ michael@0: break; \ michael@0: } else { \ michael@0: destp = (type *)srcp; \ michael@0: } \ michael@0: } michael@0: michael@0: #if defined(__Panda__) || defined(__Userspace__) michael@0: int michael@0: #else michael@0: static int michael@0: #endif michael@0: sctp_getopt(struct socket *so, int optname, void *optval, size_t *optsize, michael@0: void *p) { michael@0: struct sctp_inpcb *inp = NULL; michael@0: int error, val = 0; michael@0: struct sctp_tcb *stcb = NULL; michael@0: michael@0: if (optval == NULL) { michael@0: SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL); michael@0: return (EINVAL); michael@0: } michael@0: michael@0: inp = (struct sctp_inpcb *)so->so_pcb; michael@0: if (inp == NULL) { michael@0: SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL); michael@0: return EINVAL; michael@0: } michael@0: error = 0; michael@0: michael@0: switch (optname) { michael@0: case SCTP_NODELAY: michael@0: case SCTP_AUTOCLOSE: michael@0: case SCTP_EXPLICIT_EOR: michael@0: case SCTP_AUTO_ASCONF: michael@0: case SCTP_DISABLE_FRAGMENTS: michael@0: case SCTP_I_WANT_MAPPED_V4_ADDR: michael@0: case SCTP_USE_EXT_RCVINFO: michael@0: SCTP_INP_RLOCK(inp); michael@0: switch (optname) { michael@0: case SCTP_DISABLE_FRAGMENTS: michael@0: val = sctp_is_feature_on(inp, SCTP_PCB_FLAGS_NO_FRAGMENT); michael@0: break; michael@0: case SCTP_I_WANT_MAPPED_V4_ADDR: michael@0: val = sctp_is_feature_on(inp, SCTP_PCB_FLAGS_NEEDS_MAPPED_V4); michael@0: break; michael@0: case SCTP_AUTO_ASCONF: michael@0: if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUNDALL) { michael@0: /* only valid for bound all sockets */ michael@0: val = sctp_is_feature_on(inp, SCTP_PCB_FLAGS_AUTO_ASCONF); michael@0: } else { michael@0: SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL); michael@0: error = EINVAL; michael@0: goto flags_out; michael@0: } michael@0: break; michael@0: case SCTP_EXPLICIT_EOR: michael@0: val = sctp_is_feature_on(inp, SCTP_PCB_FLAGS_EXPLICIT_EOR); michael@0: break; michael@0: case SCTP_NODELAY: michael@0: val = sctp_is_feature_on(inp, SCTP_PCB_FLAGS_NODELAY); michael@0: break; michael@0: case SCTP_USE_EXT_RCVINFO: michael@0: val = sctp_is_feature_on(inp, SCTP_PCB_FLAGS_EXT_RCVINFO); michael@0: break; michael@0: case SCTP_AUTOCLOSE: michael@0: if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_AUTOCLOSE)) michael@0: val = TICKS_TO_SEC(inp->sctp_ep.auto_close_time); michael@0: else michael@0: val = 0; michael@0: break; michael@0: michael@0: default: michael@0: SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOPROTOOPT); michael@0: error = ENOPROTOOPT; michael@0: } /* end switch (sopt->sopt_name) */ michael@0: if (*optsize < sizeof(val)) { michael@0: SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL); michael@0: error = EINVAL; michael@0: } michael@0: flags_out: michael@0: SCTP_INP_RUNLOCK(inp); michael@0: if (error == 0) { michael@0: /* return the option value */ michael@0: *(int *)optval = val; michael@0: *optsize = sizeof(val); michael@0: } michael@0: break; michael@0: case SCTP_GET_PACKET_LOG: michael@0: { michael@0: #ifdef SCTP_PACKET_LOGGING michael@0: uint8_t *target; michael@0: int ret; michael@0: michael@0: SCTP_CHECK_AND_CAST(target, optval, uint8_t, *optsize); michael@0: ret = sctp_copy_out_packet_log(target , (int)*optsize); michael@0: *optsize = ret; michael@0: #else michael@0: SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EOPNOTSUPP); michael@0: error = EOPNOTSUPP; michael@0: #endif michael@0: break; michael@0: } michael@0: case SCTP_REUSE_PORT: michael@0: { michael@0: uint32_t *value; michael@0: michael@0: if ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE)) { michael@0: /* Can't do this for a 1-m socket */ michael@0: error = EINVAL; michael@0: break; michael@0: } michael@0: SCTP_CHECK_AND_CAST(value, optval, uint32_t, *optsize); michael@0: *value = sctp_is_feature_on(inp, SCTP_PCB_FLAGS_PORTREUSE); michael@0: *optsize = sizeof(uint32_t); michael@0: break; michael@0: } michael@0: case SCTP_PARTIAL_DELIVERY_POINT: michael@0: { michael@0: uint32_t *value; michael@0: michael@0: SCTP_CHECK_AND_CAST(value, optval, uint32_t, *optsize); michael@0: *value = inp->partial_delivery_point; michael@0: *optsize = sizeof(uint32_t); michael@0: break; michael@0: } michael@0: case SCTP_FRAGMENT_INTERLEAVE: michael@0: { michael@0: uint32_t *value; michael@0: michael@0: SCTP_CHECK_AND_CAST(value, optval, uint32_t, *optsize); michael@0: if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_FRAG_INTERLEAVE)) { michael@0: if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_INTERLEAVE_STRMS)) { michael@0: *value = SCTP_FRAG_LEVEL_2; michael@0: } else { michael@0: *value = SCTP_FRAG_LEVEL_1; michael@0: } michael@0: } else { michael@0: *value = SCTP_FRAG_LEVEL_0; michael@0: } michael@0: *optsize = sizeof(uint32_t); michael@0: break; michael@0: } michael@0: case SCTP_CMT_ON_OFF: michael@0: { michael@0: struct sctp_assoc_value *av; michael@0: michael@0: SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize); michael@0: SCTP_FIND_STCB(inp, stcb, av->assoc_id); michael@0: if (stcb) { michael@0: av->assoc_value = stcb->asoc.sctp_cmt_on_off; michael@0: SCTP_TCB_UNLOCK(stcb); michael@0: } else { michael@0: if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) || michael@0: (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) || michael@0: (av->assoc_id == SCTP_FUTURE_ASSOC)) { michael@0: SCTP_INP_RLOCK(inp); michael@0: av->assoc_value = inp->sctp_cmt_on_off; michael@0: SCTP_INP_RUNLOCK(inp); michael@0: } else { michael@0: SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL); michael@0: error = EINVAL; michael@0: } michael@0: } michael@0: if (error == 0) { michael@0: *optsize = sizeof(struct sctp_assoc_value); michael@0: } michael@0: break; michael@0: } michael@0: case SCTP_PLUGGABLE_CC: michael@0: { michael@0: struct sctp_assoc_value *av; michael@0: michael@0: SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize); michael@0: SCTP_FIND_STCB(inp, stcb, av->assoc_id); michael@0: if (stcb) { michael@0: av->assoc_value = stcb->asoc.congestion_control_module; michael@0: SCTP_TCB_UNLOCK(stcb); michael@0: } else { michael@0: if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) || michael@0: (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) || michael@0: (av->assoc_id == SCTP_FUTURE_ASSOC)) { michael@0: SCTP_INP_RLOCK(inp); michael@0: av->assoc_value = inp->sctp_ep.sctp_default_cc_module; michael@0: SCTP_INP_RUNLOCK(inp); michael@0: } else { michael@0: SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL); michael@0: error = EINVAL; michael@0: } michael@0: } michael@0: if (error == 0) { michael@0: *optsize = sizeof(struct sctp_assoc_value); michael@0: } michael@0: break; michael@0: } michael@0: case SCTP_CC_OPTION: michael@0: { michael@0: struct sctp_cc_option *cc_opt; michael@0: michael@0: SCTP_CHECK_AND_CAST(cc_opt, optval, struct sctp_cc_option, *optsize); michael@0: SCTP_FIND_STCB(inp, stcb, cc_opt->aid_value.assoc_id); michael@0: if (stcb == NULL) { michael@0: error = EINVAL; michael@0: } else { michael@0: if (stcb->asoc.cc_functions.sctp_cwnd_socket_option == NULL) { michael@0: error = ENOTSUP; michael@0: } else { michael@0: error = (*stcb->asoc.cc_functions.sctp_cwnd_socket_option)(stcb, 0, cc_opt); michael@0: *optsize = sizeof(struct sctp_cc_option); michael@0: } michael@0: SCTP_TCB_UNLOCK(stcb); michael@0: } michael@0: break; michael@0: } michael@0: case SCTP_PLUGGABLE_SS: michael@0: { michael@0: struct sctp_assoc_value *av; michael@0: michael@0: SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize); michael@0: SCTP_FIND_STCB(inp, stcb, av->assoc_id); michael@0: if (stcb) { michael@0: av->assoc_value = stcb->asoc.stream_scheduling_module; michael@0: SCTP_TCB_UNLOCK(stcb); michael@0: } else { michael@0: if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) || michael@0: (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) || michael@0: (av->assoc_id == SCTP_FUTURE_ASSOC)) { michael@0: SCTP_INP_RLOCK(inp); michael@0: av->assoc_value = inp->sctp_ep.sctp_default_ss_module; michael@0: SCTP_INP_RUNLOCK(inp); michael@0: } else { michael@0: SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL); michael@0: error = EINVAL; michael@0: } michael@0: } michael@0: if (error == 0) { michael@0: *optsize = sizeof(struct sctp_assoc_value); michael@0: } michael@0: break; michael@0: } michael@0: case SCTP_SS_VALUE: michael@0: { michael@0: struct sctp_stream_value *av; michael@0: michael@0: SCTP_CHECK_AND_CAST(av, optval, struct sctp_stream_value, *optsize); michael@0: SCTP_FIND_STCB(inp, stcb, av->assoc_id); michael@0: if (stcb) { michael@0: if (stcb->asoc.ss_functions.sctp_ss_get_value(stcb, &stcb->asoc, &stcb->asoc.strmout[av->stream_id], michael@0: &av->stream_value) < 0) { michael@0: SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL); michael@0: error = EINVAL; michael@0: } else { michael@0: *optsize = sizeof(struct sctp_stream_value); michael@0: } michael@0: SCTP_TCB_UNLOCK(stcb); michael@0: } else { michael@0: /* Can't get stream value without association */ michael@0: SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL); michael@0: error = EINVAL; michael@0: } michael@0: break; michael@0: } michael@0: case SCTP_GET_ADDR_LEN: michael@0: { michael@0: struct sctp_assoc_value *av; michael@0: michael@0: SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize); michael@0: error = EINVAL; michael@0: #ifdef INET michael@0: if (av->assoc_value == AF_INET) { michael@0: av->assoc_value = sizeof(struct sockaddr_in); michael@0: error = 0; michael@0: } michael@0: #endif michael@0: #ifdef INET6 michael@0: if (av->assoc_value == AF_INET6) { michael@0: av->assoc_value = sizeof(struct sockaddr_in6); michael@0: error = 0; michael@0: } michael@0: #endif michael@0: #if defined(__Userspace__) michael@0: if (av->assoc_value == AF_CONN) { michael@0: av->assoc_value = sizeof(struct sockaddr_conn); michael@0: error = 0; michael@0: } michael@0: #endif michael@0: if (error) { michael@0: SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error); michael@0: } else { michael@0: *optsize = sizeof(struct sctp_assoc_value); michael@0: } michael@0: break; michael@0: } michael@0: case SCTP_GET_ASSOC_NUMBER: michael@0: { michael@0: uint32_t *value, cnt; michael@0: michael@0: SCTP_CHECK_AND_CAST(value, optval, uint32_t, *optsize); michael@0: cnt = 0; michael@0: SCTP_INP_RLOCK(inp); michael@0: LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) { michael@0: cnt++; michael@0: } michael@0: SCTP_INP_RUNLOCK(inp); michael@0: *value = cnt; michael@0: *optsize = sizeof(uint32_t); michael@0: break; michael@0: } michael@0: case SCTP_GET_ASSOC_ID_LIST: michael@0: { michael@0: struct sctp_assoc_ids *ids; michael@0: unsigned int at, limit; michael@0: michael@0: SCTP_CHECK_AND_CAST(ids, optval, struct sctp_assoc_ids, *optsize); michael@0: at = 0; michael@0: limit = (*optsize-sizeof(uint32_t))/ sizeof(sctp_assoc_t); michael@0: SCTP_INP_RLOCK(inp); michael@0: LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) { michael@0: if (at < limit) { michael@0: ids->gaids_assoc_id[at++] = sctp_get_associd(stcb); michael@0: } else { michael@0: error = EINVAL; michael@0: SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error); michael@0: break; michael@0: } michael@0: } michael@0: SCTP_INP_RUNLOCK(inp); michael@0: if (error == 0) { michael@0: ids->gaids_number_of_ids = at; michael@0: *optsize = ((at * sizeof(sctp_assoc_t)) + sizeof(uint32_t)); michael@0: } michael@0: break; michael@0: } michael@0: case SCTP_CONTEXT: michael@0: { michael@0: struct sctp_assoc_value *av; michael@0: michael@0: SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize); michael@0: SCTP_FIND_STCB(inp, stcb, av->assoc_id); michael@0: michael@0: if (stcb) { michael@0: av->assoc_value = stcb->asoc.context; michael@0: SCTP_TCB_UNLOCK(stcb); michael@0: } else { michael@0: if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) || michael@0: (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) || michael@0: (av->assoc_id == SCTP_FUTURE_ASSOC)) { michael@0: SCTP_INP_RLOCK(inp); michael@0: av->assoc_value = inp->sctp_context; michael@0: SCTP_INP_RUNLOCK(inp); michael@0: } else { michael@0: SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL); michael@0: error = EINVAL; michael@0: } michael@0: } michael@0: if (error == 0) { michael@0: *optsize = sizeof(struct sctp_assoc_value); michael@0: } michael@0: break; michael@0: } michael@0: case SCTP_VRF_ID: michael@0: { michael@0: uint32_t *default_vrfid; michael@0: michael@0: SCTP_CHECK_AND_CAST(default_vrfid, optval, uint32_t, *optsize); michael@0: *default_vrfid = inp->def_vrf_id; michael@0: *optsize = sizeof(uint32_t); michael@0: break; michael@0: } michael@0: case SCTP_GET_ASOC_VRF: michael@0: { michael@0: struct sctp_assoc_value *id; michael@0: michael@0: SCTP_CHECK_AND_CAST(id, optval, struct sctp_assoc_value, *optsize); michael@0: SCTP_FIND_STCB(inp, stcb, id->assoc_id); michael@0: if (stcb == NULL) { michael@0: error = EINVAL; michael@0: SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error); michael@0: } else { michael@0: id->assoc_value = stcb->asoc.vrf_id; michael@0: *optsize = sizeof(struct sctp_assoc_value); michael@0: } michael@0: break; michael@0: } michael@0: case SCTP_GET_VRF_IDS: michael@0: { michael@0: #ifdef SCTP_MVRF michael@0: int siz_needed; michael@0: uint32_t *vrf_ids; michael@0: michael@0: SCTP_CHECK_AND_CAST(vrf_ids, optval, uint32_t, *optsize); michael@0: siz_needed = inp->num_vrfs * sizeof(uint32_t); michael@0: if (*optsize < siz_needed) { michael@0: error = EINVAL; michael@0: SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error); michael@0: } else { michael@0: memcpy(vrf_ids, inp->m_vrf_ids, siz_needed); michael@0: *optsize = siz_needed; michael@0: } michael@0: #else michael@0: SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EOPNOTSUPP); michael@0: error = EOPNOTSUPP; michael@0: #endif michael@0: break; michael@0: } michael@0: case SCTP_GET_NONCE_VALUES: michael@0: { michael@0: struct sctp_get_nonce_values *gnv; michael@0: michael@0: SCTP_CHECK_AND_CAST(gnv, optval, struct sctp_get_nonce_values, *optsize); michael@0: SCTP_FIND_STCB(inp, stcb, gnv->gn_assoc_id); michael@0: michael@0: if (stcb) { michael@0: gnv->gn_peers_tag = stcb->asoc.peer_vtag; michael@0: gnv->gn_local_tag = stcb->asoc.my_vtag; michael@0: SCTP_TCB_UNLOCK(stcb); michael@0: *optsize = sizeof(struct sctp_get_nonce_values); michael@0: } else { michael@0: SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOTCONN); michael@0: error = ENOTCONN; michael@0: } michael@0: break; michael@0: } michael@0: case SCTP_DELAYED_SACK: michael@0: { michael@0: struct sctp_sack_info *sack; michael@0: michael@0: SCTP_CHECK_AND_CAST(sack, optval, struct sctp_sack_info, *optsize); michael@0: SCTP_FIND_STCB(inp, stcb, sack->sack_assoc_id); michael@0: if (stcb) { michael@0: sack->sack_delay = stcb->asoc.delayed_ack; michael@0: sack->sack_freq = stcb->asoc.sack_freq; michael@0: SCTP_TCB_UNLOCK(stcb); michael@0: } else { michael@0: if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) || michael@0: (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) || michael@0: (sack->sack_assoc_id == SCTP_FUTURE_ASSOC)) { michael@0: SCTP_INP_RLOCK(inp); michael@0: sack->sack_delay = TICKS_TO_MSEC(inp->sctp_ep.sctp_timeoutticks[SCTP_TIMER_RECV]); michael@0: sack->sack_freq = inp->sctp_ep.sctp_sack_freq; michael@0: SCTP_INP_RUNLOCK(inp); michael@0: } else { michael@0: SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL); michael@0: error = EINVAL; michael@0: } michael@0: } michael@0: if (error == 0) { michael@0: *optsize = sizeof(struct sctp_sack_info); michael@0: } michael@0: break; michael@0: } michael@0: case SCTP_GET_SNDBUF_USE: michael@0: { michael@0: struct sctp_sockstat *ss; michael@0: michael@0: SCTP_CHECK_AND_CAST(ss, optval, struct sctp_sockstat, *optsize); michael@0: SCTP_FIND_STCB(inp, stcb, ss->ss_assoc_id); michael@0: michael@0: if (stcb) { michael@0: ss->ss_total_sndbuf = stcb->asoc.total_output_queue_size; michael@0: ss->ss_total_recv_buf = (stcb->asoc.size_on_reasm_queue + michael@0: stcb->asoc.size_on_all_streams); michael@0: SCTP_TCB_UNLOCK(stcb); michael@0: *optsize = sizeof(struct sctp_sockstat); michael@0: } else { michael@0: SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOTCONN); michael@0: error = ENOTCONN; michael@0: } michael@0: break; michael@0: } michael@0: case SCTP_MAX_BURST: michael@0: { michael@0: #if defined(__FreeBSD__) && __FreeBSD_version < 900000 michael@0: uint8_t *value; michael@0: michael@0: SCTP_CHECK_AND_CAST(value, optval, uint8_t, *optsize); michael@0: michael@0: SCTP_INP_RLOCK(inp); michael@0: if (inp->sctp_ep.max_burst < 256) { michael@0: *value = inp->sctp_ep.max_burst; michael@0: } else { michael@0: *value = 255; michael@0: } michael@0: SCTP_INP_RUNLOCK(inp); michael@0: *optsize = sizeof(uint8_t); michael@0: #else michael@0: struct sctp_assoc_value *av; michael@0: michael@0: SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize); michael@0: SCTP_FIND_STCB(inp, stcb, av->assoc_id); michael@0: michael@0: if (stcb) { michael@0: av->assoc_value = stcb->asoc.max_burst; michael@0: SCTP_TCB_UNLOCK(stcb); michael@0: } else { michael@0: if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) || michael@0: (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) || michael@0: (av->assoc_id == SCTP_FUTURE_ASSOC)) { michael@0: SCTP_INP_RLOCK(inp); michael@0: av->assoc_value = inp->sctp_ep.max_burst; michael@0: SCTP_INP_RUNLOCK(inp); michael@0: } else { michael@0: SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL); michael@0: error = EINVAL; michael@0: } michael@0: } michael@0: if (error == 0) { michael@0: *optsize = sizeof(struct sctp_assoc_value); michael@0: } michael@0: #endif michael@0: break; michael@0: } michael@0: case SCTP_MAXSEG: michael@0: { michael@0: struct sctp_assoc_value *av; michael@0: int ovh; michael@0: michael@0: SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize); michael@0: SCTP_FIND_STCB(inp, stcb, av->assoc_id); michael@0: michael@0: if (stcb) { michael@0: av->assoc_value = sctp_get_frag_point(stcb, &stcb->asoc); michael@0: SCTP_TCB_UNLOCK(stcb); michael@0: } else { michael@0: if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) || michael@0: (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) || michael@0: (av->assoc_id == SCTP_FUTURE_ASSOC)) { michael@0: SCTP_INP_RLOCK(inp); michael@0: if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) { michael@0: ovh = SCTP_MED_OVERHEAD; michael@0: } else { michael@0: ovh = SCTP_MED_V4_OVERHEAD; michael@0: } michael@0: if (inp->sctp_frag_point >= SCTP_DEFAULT_MAXSEGMENT) michael@0: av->assoc_value = 0; michael@0: else michael@0: av->assoc_value = inp->sctp_frag_point - ovh; michael@0: SCTP_INP_RUNLOCK(inp); michael@0: } else { michael@0: SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL); michael@0: error = EINVAL; michael@0: } michael@0: } michael@0: if (error == 0) { michael@0: *optsize = sizeof(struct sctp_assoc_value); michael@0: } michael@0: break; michael@0: } michael@0: case SCTP_GET_STAT_LOG: michael@0: error = sctp_fill_stat_log(optval, optsize); michael@0: break; michael@0: case SCTP_EVENTS: michael@0: { michael@0: struct sctp_event_subscribe *events; michael@0: michael@0: SCTP_CHECK_AND_CAST(events, optval, struct sctp_event_subscribe, *optsize); michael@0: memset(events, 0, sizeof(struct sctp_event_subscribe)); michael@0: SCTP_INP_RLOCK(inp); michael@0: if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_RECVDATAIOEVNT)) michael@0: events->sctp_data_io_event = 1; michael@0: michael@0: if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_RECVASSOCEVNT)) michael@0: events->sctp_association_event = 1; michael@0: michael@0: if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_RECVPADDREVNT)) michael@0: events->sctp_address_event = 1; michael@0: michael@0: if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_RECVSENDFAILEVNT)) michael@0: events->sctp_send_failure_event = 1; michael@0: michael@0: if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_RECVPEERERR)) michael@0: events->sctp_peer_error_event = 1; michael@0: michael@0: if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_RECVSHUTDOWNEVNT)) michael@0: events->sctp_shutdown_event = 1; michael@0: michael@0: if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_PDAPIEVNT)) michael@0: events->sctp_partial_delivery_event = 1; michael@0: michael@0: if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_ADAPTATIONEVNT)) michael@0: events->sctp_adaptation_layer_event = 1; michael@0: michael@0: if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_AUTHEVNT)) michael@0: events->sctp_authentication_event = 1; michael@0: michael@0: if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_DRYEVNT)) michael@0: events->sctp_sender_dry_event = 1; michael@0: michael@0: if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_STREAM_RESETEVNT)) michael@0: events->sctp_stream_reset_event = 1; michael@0: SCTP_INP_RUNLOCK(inp); michael@0: *optsize = sizeof(struct sctp_event_subscribe); michael@0: break; michael@0: } michael@0: case SCTP_ADAPTATION_LAYER: michael@0: { michael@0: uint32_t *value; michael@0: michael@0: SCTP_CHECK_AND_CAST(value, optval, uint32_t, *optsize); michael@0: michael@0: SCTP_INP_RLOCK(inp); michael@0: *value = inp->sctp_ep.adaptation_layer_indicator; michael@0: SCTP_INP_RUNLOCK(inp); michael@0: *optsize = sizeof(uint32_t); michael@0: break; michael@0: } michael@0: case SCTP_SET_INITIAL_DBG_SEQ: michael@0: { michael@0: uint32_t *value; michael@0: michael@0: SCTP_CHECK_AND_CAST(value, optval, uint32_t, *optsize); michael@0: SCTP_INP_RLOCK(inp); michael@0: *value = inp->sctp_ep.initial_sequence_debug; michael@0: SCTP_INP_RUNLOCK(inp); michael@0: *optsize = sizeof(uint32_t); michael@0: break; michael@0: } michael@0: case SCTP_GET_LOCAL_ADDR_SIZE: michael@0: { michael@0: uint32_t *value; michael@0: michael@0: SCTP_CHECK_AND_CAST(value, optval, uint32_t, *optsize); michael@0: SCTP_INP_RLOCK(inp); michael@0: *value = sctp_count_max_addresses(inp); michael@0: SCTP_INP_RUNLOCK(inp); michael@0: *optsize = sizeof(uint32_t); michael@0: break; michael@0: } michael@0: case SCTP_GET_REMOTE_ADDR_SIZE: michael@0: { michael@0: uint32_t *value; michael@0: size_t size; michael@0: struct sctp_nets *net; michael@0: michael@0: SCTP_CHECK_AND_CAST(value, optval, uint32_t, *optsize); michael@0: /* FIXME MT: change to sctp_assoc_value? */ michael@0: SCTP_FIND_STCB(inp, stcb, (sctp_assoc_t) *value); michael@0: michael@0: if (stcb) { michael@0: size = 0; michael@0: /* Count the sizes */ michael@0: TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) { michael@0: if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_NEEDS_MAPPED_V4)) { michael@0: size += sizeof(struct sockaddr_in6); michael@0: } else { michael@0: switch (((struct sockaddr *)&net->ro._l_addr)->sa_family) { michael@0: #ifdef INET michael@0: case AF_INET: michael@0: size += sizeof(struct sockaddr_in); michael@0: break; michael@0: #endif michael@0: #ifdef INET6 michael@0: case AF_INET6: michael@0: size += sizeof(struct sockaddr_in6); michael@0: break; michael@0: #endif michael@0: #if defined(__Userspace__) michael@0: case AF_CONN: michael@0: size += sizeof(struct sockaddr_conn); michael@0: break; michael@0: #endif michael@0: default: michael@0: break; michael@0: } michael@0: } michael@0: } michael@0: SCTP_TCB_UNLOCK(stcb); michael@0: *value = (uint32_t) size; michael@0: *optsize = sizeof(uint32_t); michael@0: } else { michael@0: SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOTCONN); michael@0: error = ENOTCONN; michael@0: } michael@0: break; michael@0: } michael@0: case SCTP_GET_PEER_ADDRESSES: michael@0: /* michael@0: * Get the address information, an array is passed in to michael@0: * fill up we pack it. michael@0: */ michael@0: { michael@0: size_t cpsz, left; michael@0: struct sockaddr_storage *sas; michael@0: struct sctp_nets *net; michael@0: struct sctp_getaddresses *saddr; michael@0: michael@0: SCTP_CHECK_AND_CAST(saddr, optval, struct sctp_getaddresses, *optsize); michael@0: SCTP_FIND_STCB(inp, stcb, saddr->sget_assoc_id); michael@0: michael@0: if (stcb) { michael@0: left = (*optsize) - sizeof(struct sctp_getaddresses); michael@0: *optsize = sizeof(struct sctp_getaddresses); michael@0: sas = (struct sockaddr_storage *)&saddr->addr[0]; michael@0: michael@0: TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) { michael@0: if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_NEEDS_MAPPED_V4)) { michael@0: cpsz = sizeof(struct sockaddr_in6); michael@0: } else { michael@0: switch (((struct sockaddr *)&net->ro._l_addr)->sa_family) { michael@0: #ifdef INET michael@0: case AF_INET: michael@0: cpsz = sizeof(struct sockaddr_in); michael@0: break; michael@0: #endif michael@0: #ifdef INET6 michael@0: case AF_INET6: michael@0: cpsz = sizeof(struct sockaddr_in6); michael@0: break; michael@0: #endif michael@0: #if defined(__Userspace__) michael@0: case AF_CONN: michael@0: cpsz = sizeof(struct sockaddr_conn); michael@0: break; michael@0: #endif michael@0: default: michael@0: cpsz = 0; michael@0: break; michael@0: } michael@0: } michael@0: if (cpsz == 0) { michael@0: break; michael@0: } michael@0: if (left < cpsz) { michael@0: /* not enough room. */ michael@0: break; michael@0: } michael@0: #if defined(INET) && defined(INET6) michael@0: if ((sctp_is_feature_on(inp, SCTP_PCB_FLAGS_NEEDS_MAPPED_V4)) && michael@0: (((struct sockaddr *)&net->ro._l_addr)->sa_family == AF_INET)) { michael@0: /* Must map the address */ michael@0: in6_sin_2_v4mapsin6((struct sockaddr_in *)&net->ro._l_addr, michael@0: (struct sockaddr_in6 *)sas); michael@0: } else { michael@0: #endif michael@0: memcpy(sas, &net->ro._l_addr, cpsz); michael@0: #if defined(INET) && defined(INET6) michael@0: } michael@0: #endif michael@0: ((struct sockaddr_in *)sas)->sin_port = stcb->rport; michael@0: michael@0: sas = (struct sockaddr_storage *)((caddr_t)sas + cpsz); michael@0: left -= cpsz; michael@0: *optsize += cpsz; michael@0: } michael@0: SCTP_TCB_UNLOCK(stcb); michael@0: } else { michael@0: SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOENT); michael@0: error = ENOENT; michael@0: } michael@0: break; michael@0: } michael@0: case SCTP_GET_LOCAL_ADDRESSES: michael@0: { michael@0: size_t limit, actual; michael@0: struct sockaddr_storage *sas; michael@0: struct sctp_getaddresses *saddr; michael@0: michael@0: SCTP_CHECK_AND_CAST(saddr, optval, struct sctp_getaddresses, *optsize); michael@0: SCTP_FIND_STCB(inp, stcb, saddr->sget_assoc_id); michael@0: michael@0: sas = (struct sockaddr_storage *)&saddr->addr[0]; michael@0: limit = *optsize - sizeof(sctp_assoc_t); michael@0: actual = sctp_fill_up_addresses(inp, stcb, limit, sas); michael@0: if (stcb) { michael@0: SCTP_TCB_UNLOCK(stcb); michael@0: } michael@0: *optsize = sizeof(struct sockaddr_storage) + actual; michael@0: break; michael@0: } michael@0: case SCTP_PEER_ADDR_PARAMS: michael@0: { michael@0: struct sctp_paddrparams *paddrp; michael@0: struct sctp_nets *net; michael@0: michael@0: SCTP_CHECK_AND_CAST(paddrp, optval, struct sctp_paddrparams, *optsize); michael@0: SCTP_FIND_STCB(inp, stcb, paddrp->spp_assoc_id); michael@0: michael@0: net = NULL; michael@0: if (stcb) { michael@0: net = sctp_findnet(stcb, (struct sockaddr *)&paddrp->spp_address); michael@0: } else { michael@0: /* We increment here since sctp_findassociation_ep_addr() wil michael@0: * do a decrement if it finds the stcb as long as the locked michael@0: * tcb (last argument) is NOT a TCB.. aka NULL. michael@0: */ michael@0: SCTP_INP_INCR_REF(inp); michael@0: stcb = sctp_findassociation_ep_addr(&inp, (struct sockaddr *)&paddrp->spp_address, &net, NULL, NULL); michael@0: if (stcb == NULL) { michael@0: SCTP_INP_DECR_REF(inp); michael@0: } michael@0: } michael@0: if (stcb && (net == NULL)) { michael@0: struct sockaddr *sa; michael@0: michael@0: sa = (struct sockaddr *)&paddrp->spp_address; michael@0: #ifdef INET michael@0: if (sa->sa_family == AF_INET) { michael@0: struct sockaddr_in *sin; michael@0: michael@0: sin = (struct sockaddr_in *)sa; michael@0: if (sin->sin_addr.s_addr) { michael@0: error = EINVAL; michael@0: SCTP_TCB_UNLOCK(stcb); michael@0: SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error); michael@0: break; michael@0: } michael@0: } else michael@0: #endif michael@0: #ifdef INET6 michael@0: if (sa->sa_family == AF_INET6) { michael@0: struct sockaddr_in6 *sin6; michael@0: michael@0: sin6 = (struct sockaddr_in6 *)sa; michael@0: if (!IN6_IS_ADDR_UNSPECIFIED(&sin6->sin6_addr)) { michael@0: error = EINVAL; michael@0: SCTP_TCB_UNLOCK(stcb); michael@0: SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error); michael@0: break; michael@0: } michael@0: } else michael@0: #endif michael@0: #if defined(__Userspace__) michael@0: if (sa->sa_family == AF_CONN) { michael@0: struct sockaddr_conn *sconn; michael@0: michael@0: sconn = (struct sockaddr_conn *)sa; michael@0: if (sconn->sconn_addr != NULL) { michael@0: error = EINVAL; michael@0: SCTP_TCB_UNLOCK(stcb); michael@0: SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error); michael@0: break; michael@0: } michael@0: } else michael@0: #endif michael@0: { michael@0: error = EAFNOSUPPORT; michael@0: SCTP_TCB_UNLOCK(stcb); michael@0: SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error); michael@0: break; michael@0: } michael@0: } michael@0: michael@0: if (stcb) { michael@0: /* Applies to the specific association */ michael@0: paddrp->spp_flags = 0; michael@0: if (net) { michael@0: int ovh; michael@0: if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) { michael@0: ovh = SCTP_MED_OVERHEAD; michael@0: } else { michael@0: ovh = SCTP_MED_V4_OVERHEAD; michael@0: } michael@0: michael@0: paddrp->spp_hbinterval = net->heart_beat_delay; michael@0: paddrp->spp_pathmaxrxt = net->failure_threshold; michael@0: paddrp->spp_pathmtu = net->mtu - ovh; michael@0: /* get flags for HB */ michael@0: if (net->dest_state & SCTP_ADDR_NOHB) { michael@0: paddrp->spp_flags |= SPP_HB_DISABLE; michael@0: } else { michael@0: paddrp->spp_flags |= SPP_HB_ENABLE; michael@0: } michael@0: /* get flags for PMTU */ michael@0: if (net->dest_state & SCTP_ADDR_NO_PMTUD) { michael@0: paddrp->spp_flags |= SPP_PMTUD_ENABLE; michael@0: } else { michael@0: paddrp->spp_flags |= SPP_PMTUD_DISABLE; michael@0: } michael@0: if (net->dscp & 0x01) { michael@0: paddrp->spp_dscp = net->dscp & 0xfc; michael@0: paddrp->spp_flags |= SPP_DSCP; michael@0: } michael@0: #ifdef INET6 michael@0: if ((net->ro._l_addr.sa.sa_family == AF_INET6) && michael@0: (net->flowlabel & 0x80000000)) { michael@0: paddrp->spp_ipv6_flowlabel = net->flowlabel & 0x000fffff; michael@0: paddrp->spp_flags |= SPP_IPV6_FLOWLABEL; michael@0: } michael@0: #endif michael@0: } else { michael@0: /* michael@0: * No destination so return default michael@0: * value michael@0: */ michael@0: paddrp->spp_pathmaxrxt = stcb->asoc.def_net_failure; michael@0: paddrp->spp_pathmtu = sctp_get_frag_point(stcb, &stcb->asoc); michael@0: if (stcb->asoc.default_dscp & 0x01) { michael@0: paddrp->spp_dscp = stcb->asoc.default_dscp & 0xfc; michael@0: paddrp->spp_flags |= SPP_DSCP; michael@0: } michael@0: #ifdef INET6 michael@0: if (stcb->asoc.default_flowlabel & 0x80000000) { michael@0: paddrp->spp_ipv6_flowlabel = stcb->asoc.default_flowlabel & 0x000fffff; michael@0: paddrp->spp_flags |= SPP_IPV6_FLOWLABEL; michael@0: } michael@0: #endif michael@0: /* default settings should be these */ michael@0: if (sctp_stcb_is_feature_on(inp, stcb, SCTP_PCB_FLAGS_DONOT_HEARTBEAT)) { michael@0: paddrp->spp_flags |= SPP_HB_DISABLE; michael@0: } else { michael@0: paddrp->spp_flags |= SPP_HB_ENABLE; michael@0: } michael@0: if (sctp_stcb_is_feature_on(inp, stcb, SCTP_PCB_FLAGS_DO_NOT_PMTUD)) { michael@0: paddrp->spp_flags |= SPP_PMTUD_DISABLE; michael@0: } else { michael@0: paddrp->spp_flags |= SPP_PMTUD_ENABLE; michael@0: } michael@0: paddrp->spp_hbinterval = stcb->asoc.heart_beat_delay; michael@0: } michael@0: paddrp->spp_assoc_id = sctp_get_associd(stcb); michael@0: SCTP_TCB_UNLOCK(stcb); michael@0: } else { michael@0: if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) || michael@0: (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) || michael@0: (paddrp->spp_assoc_id == SCTP_FUTURE_ASSOC)) { michael@0: /* Use endpoint defaults */ michael@0: SCTP_INP_RLOCK(inp); michael@0: paddrp->spp_pathmaxrxt = inp->sctp_ep.def_net_failure; michael@0: paddrp->spp_hbinterval = TICKS_TO_MSEC(inp->sctp_ep.sctp_timeoutticks[SCTP_TIMER_HEARTBEAT]); michael@0: paddrp->spp_assoc_id = SCTP_FUTURE_ASSOC; michael@0: /* get inp's default */ michael@0: if (inp->sctp_ep.default_dscp & 0x01) { michael@0: paddrp->spp_dscp = inp->sctp_ep.default_dscp & 0xfc; michael@0: paddrp->spp_flags |= SPP_DSCP; michael@0: } michael@0: #ifdef INET6 michael@0: if ((inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) && michael@0: (inp->sctp_ep.default_flowlabel & 0x80000000)) { michael@0: paddrp->spp_ipv6_flowlabel = inp->sctp_ep.default_flowlabel & 0x000fffff; michael@0: paddrp->spp_flags |= SPP_IPV6_FLOWLABEL; michael@0: } michael@0: #endif michael@0: /* can't return this */ michael@0: paddrp->spp_pathmtu = 0; michael@0: michael@0: if (sctp_is_feature_off(inp, SCTP_PCB_FLAGS_DONOT_HEARTBEAT)) { michael@0: paddrp->spp_flags |= SPP_HB_ENABLE; michael@0: } else { michael@0: paddrp->spp_flags |= SPP_HB_DISABLE; michael@0: } michael@0: if (sctp_is_feature_off(inp, SCTP_PCB_FLAGS_DO_NOT_PMTUD)) { michael@0: paddrp->spp_flags |= SPP_PMTUD_ENABLE; michael@0: } else { michael@0: paddrp->spp_flags |= SPP_PMTUD_DISABLE; michael@0: } michael@0: SCTP_INP_RUNLOCK(inp); michael@0: } else { michael@0: SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL); michael@0: error = EINVAL; michael@0: } michael@0: } michael@0: if (error == 0) { michael@0: *optsize = sizeof(struct sctp_paddrparams); michael@0: } michael@0: break; michael@0: } michael@0: case SCTP_GET_PEER_ADDR_INFO: michael@0: { michael@0: struct sctp_paddrinfo *paddri; michael@0: struct sctp_nets *net; michael@0: michael@0: SCTP_CHECK_AND_CAST(paddri, optval, struct sctp_paddrinfo, *optsize); michael@0: SCTP_FIND_STCB(inp, stcb, paddri->spinfo_assoc_id); michael@0: michael@0: net = NULL; michael@0: if (stcb) { michael@0: net = sctp_findnet(stcb, (struct sockaddr *)&paddri->spinfo_address); michael@0: } else { michael@0: /* We increment here since sctp_findassociation_ep_addr() wil michael@0: * do a decrement if it finds the stcb as long as the locked michael@0: * tcb (last argument) is NOT a TCB.. aka NULL. michael@0: */ michael@0: SCTP_INP_INCR_REF(inp); michael@0: stcb = sctp_findassociation_ep_addr(&inp, (struct sockaddr *)&paddri->spinfo_address, &net, NULL, NULL); michael@0: if (stcb == NULL) { michael@0: SCTP_INP_DECR_REF(inp); michael@0: } michael@0: } michael@0: michael@0: if ((stcb) && (net)) { michael@0: if (net->dest_state & SCTP_ADDR_UNCONFIRMED) { michael@0: /* It's unconfirmed */ michael@0: paddri->spinfo_state = SCTP_UNCONFIRMED; michael@0: } else if (net->dest_state & SCTP_ADDR_REACHABLE) { michael@0: /* It's active */ michael@0: paddri->spinfo_state = SCTP_ACTIVE; michael@0: } else { michael@0: /* It's inactive */ michael@0: paddri->spinfo_state = SCTP_INACTIVE; michael@0: } michael@0: paddri->spinfo_cwnd = net->cwnd; michael@0: paddri->spinfo_srtt = net->lastsa >> SCTP_RTT_SHIFT; michael@0: paddri->spinfo_rto = net->RTO; michael@0: paddri->spinfo_assoc_id = sctp_get_associd(stcb); michael@0: paddri->spinfo_mtu = net->mtu; michael@0: SCTP_TCB_UNLOCK(stcb); michael@0: *optsize = sizeof(struct sctp_paddrinfo); michael@0: } else { michael@0: if (stcb) { michael@0: SCTP_TCB_UNLOCK(stcb); michael@0: } michael@0: SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOENT); michael@0: error = ENOENT; michael@0: } michael@0: break; michael@0: } michael@0: case SCTP_PCB_STATUS: michael@0: { michael@0: struct sctp_pcbinfo *spcb; michael@0: michael@0: SCTP_CHECK_AND_CAST(spcb, optval, struct sctp_pcbinfo, *optsize); michael@0: sctp_fill_pcbinfo(spcb); michael@0: *optsize = sizeof(struct sctp_pcbinfo); michael@0: break; michael@0: } michael@0: case SCTP_STATUS: michael@0: { michael@0: struct sctp_nets *net; michael@0: struct sctp_status *sstat; michael@0: michael@0: SCTP_CHECK_AND_CAST(sstat, optval, struct sctp_status, *optsize); michael@0: SCTP_FIND_STCB(inp, stcb, sstat->sstat_assoc_id); michael@0: michael@0: if (stcb == NULL) { michael@0: SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL); michael@0: error = EINVAL; michael@0: break; michael@0: } michael@0: /* michael@0: * I think passing the state is fine since michael@0: * sctp_constants.h will be available to the user michael@0: * land. michael@0: */ michael@0: sstat->sstat_state = stcb->asoc.state; michael@0: sstat->sstat_assoc_id = sctp_get_associd(stcb); michael@0: sstat->sstat_rwnd = stcb->asoc.peers_rwnd; michael@0: sstat->sstat_unackdata = stcb->asoc.sent_queue_cnt; michael@0: /* michael@0: * We can't include chunks that have been passed to michael@0: * the socket layer. Only things in queue. michael@0: */ michael@0: sstat->sstat_penddata = (stcb->asoc.cnt_on_reasm_queue + michael@0: stcb->asoc.cnt_on_all_streams); michael@0: michael@0: michael@0: sstat->sstat_instrms = stcb->asoc.streamincnt; michael@0: sstat->sstat_outstrms = stcb->asoc.streamoutcnt; michael@0: sstat->sstat_fragmentation_point = sctp_get_frag_point(stcb, &stcb->asoc); michael@0: #ifdef HAVE_SA_LEN michael@0: memcpy(&sstat->sstat_primary.spinfo_address, michael@0: &stcb->asoc.primary_destination->ro._l_addr, michael@0: ((struct sockaddr *)(&stcb->asoc.primary_destination->ro._l_addr))->sa_len); michael@0: #else michael@0: if (stcb->asoc.primary_destination->ro._l_addr.sa.sa_family == AF_INET) { michael@0: memcpy(&sstat->sstat_primary.spinfo_address, michael@0: &stcb->asoc.primary_destination->ro._l_addr, michael@0: sizeof(struct sockaddr_in)); michael@0: } else { michael@0: memcpy(&sstat->sstat_primary.spinfo_address, michael@0: &stcb->asoc.primary_destination->ro._l_addr, michael@0: sizeof(struct sockaddr_in6)); michael@0: } michael@0: #endif michael@0: net = stcb->asoc.primary_destination; michael@0: ((struct sockaddr_in *)&sstat->sstat_primary.spinfo_address)->sin_port = stcb->rport; michael@0: /* michael@0: * Again the user can get info from sctp_constants.h michael@0: * for what the state of the network is. michael@0: */ michael@0: if (net->dest_state & SCTP_ADDR_UNCONFIRMED) { michael@0: /* It's unconfirmed */ michael@0: sstat->sstat_primary.spinfo_state = SCTP_UNCONFIRMED; michael@0: } else if (net->dest_state & SCTP_ADDR_REACHABLE) { michael@0: /* It's active */ michael@0: sstat->sstat_primary.spinfo_state = SCTP_ACTIVE; michael@0: } else { michael@0: /* It's inactive */ michael@0: sstat->sstat_primary.spinfo_state = SCTP_INACTIVE; michael@0: } michael@0: sstat->sstat_primary.spinfo_cwnd = net->cwnd; michael@0: sstat->sstat_primary.spinfo_srtt = net->lastsa >> SCTP_RTT_SHIFT; michael@0: sstat->sstat_primary.spinfo_rto = net->RTO; michael@0: sstat->sstat_primary.spinfo_mtu = net->mtu; michael@0: sstat->sstat_primary.spinfo_assoc_id = sctp_get_associd(stcb); michael@0: SCTP_TCB_UNLOCK(stcb); michael@0: *optsize = sizeof(struct sctp_status); michael@0: break; michael@0: } michael@0: case SCTP_RTOINFO: michael@0: { michael@0: struct sctp_rtoinfo *srto; michael@0: michael@0: SCTP_CHECK_AND_CAST(srto, optval, struct sctp_rtoinfo, *optsize); michael@0: SCTP_FIND_STCB(inp, stcb, srto->srto_assoc_id); michael@0: michael@0: if (stcb) { michael@0: srto->srto_initial = stcb->asoc.initial_rto; michael@0: srto->srto_max = stcb->asoc.maxrto; michael@0: srto->srto_min = stcb->asoc.minrto; michael@0: SCTP_TCB_UNLOCK(stcb); michael@0: } else { michael@0: if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) || michael@0: (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) || michael@0: (srto->srto_assoc_id == SCTP_FUTURE_ASSOC)) { michael@0: SCTP_INP_RLOCK(inp); michael@0: srto->srto_initial = inp->sctp_ep.initial_rto; michael@0: srto->srto_max = inp->sctp_ep.sctp_maxrto; michael@0: srto->srto_min = inp->sctp_ep.sctp_minrto; michael@0: SCTP_INP_RUNLOCK(inp); michael@0: } else { michael@0: SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL); michael@0: error = EINVAL; michael@0: } michael@0: } michael@0: if (error == 0) { michael@0: *optsize = sizeof(struct sctp_rtoinfo); michael@0: } michael@0: break; michael@0: } michael@0: case SCTP_TIMEOUTS: michael@0: { michael@0: struct sctp_timeouts *stimo; michael@0: michael@0: SCTP_CHECK_AND_CAST(stimo, optval, struct sctp_timeouts, *optsize); michael@0: SCTP_FIND_STCB(inp, stcb, stimo->stimo_assoc_id); michael@0: michael@0: if (stcb) { michael@0: stimo->stimo_init= stcb->asoc.timoinit; michael@0: stimo->stimo_data= stcb->asoc.timodata; michael@0: stimo->stimo_sack= stcb->asoc.timosack; michael@0: stimo->stimo_shutdown= stcb->asoc.timoshutdown; michael@0: stimo->stimo_heartbeat= stcb->asoc.timoheartbeat; michael@0: stimo->stimo_cookie= stcb->asoc.timocookie; michael@0: stimo->stimo_shutdownack= stcb->asoc.timoshutdownack; michael@0: SCTP_TCB_UNLOCK(stcb); michael@0: *optsize = sizeof(struct sctp_timeouts); michael@0: } else { michael@0: SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL); michael@0: error = EINVAL; michael@0: } michael@0: break; michael@0: } michael@0: case SCTP_ASSOCINFO: michael@0: { michael@0: struct sctp_assocparams *sasoc; michael@0: michael@0: SCTP_CHECK_AND_CAST(sasoc, optval, struct sctp_assocparams, *optsize); michael@0: SCTP_FIND_STCB(inp, stcb, sasoc->sasoc_assoc_id); michael@0: michael@0: if (stcb) { michael@0: sasoc->sasoc_cookie_life = TICKS_TO_MSEC(stcb->asoc.cookie_life); michael@0: sasoc->sasoc_asocmaxrxt = stcb->asoc.max_send_times; michael@0: sasoc->sasoc_number_peer_destinations = stcb->asoc.numnets; michael@0: sasoc->sasoc_peer_rwnd = stcb->asoc.peers_rwnd; michael@0: sasoc->sasoc_local_rwnd = stcb->asoc.my_rwnd; michael@0: SCTP_TCB_UNLOCK(stcb); michael@0: } else { michael@0: if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) || michael@0: (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) || michael@0: (sasoc->sasoc_assoc_id == SCTP_FUTURE_ASSOC)) { michael@0: SCTP_INP_RLOCK(inp); michael@0: sasoc->sasoc_cookie_life = TICKS_TO_MSEC(inp->sctp_ep.def_cookie_life); michael@0: sasoc->sasoc_asocmaxrxt = inp->sctp_ep.max_send_times; michael@0: sasoc->sasoc_number_peer_destinations = 0; michael@0: sasoc->sasoc_peer_rwnd = 0; michael@0: sasoc->sasoc_local_rwnd = sbspace(&inp->sctp_socket->so_rcv); michael@0: SCTP_INP_RUNLOCK(inp); michael@0: } else { michael@0: SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL); michael@0: error = EINVAL; michael@0: } michael@0: } michael@0: if (error == 0) { michael@0: *optsize = sizeof(struct sctp_assocparams); michael@0: } michael@0: break; michael@0: } michael@0: case SCTP_DEFAULT_SEND_PARAM: michael@0: { michael@0: struct sctp_sndrcvinfo *s_info; michael@0: michael@0: SCTP_CHECK_AND_CAST(s_info, optval, struct sctp_sndrcvinfo, *optsize); michael@0: SCTP_FIND_STCB(inp, stcb, s_info->sinfo_assoc_id); michael@0: michael@0: if (stcb) { michael@0: memcpy(s_info, &stcb->asoc.def_send, sizeof(stcb->asoc.def_send)); michael@0: SCTP_TCB_UNLOCK(stcb); michael@0: } else { michael@0: if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) || michael@0: (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) || michael@0: (s_info->sinfo_assoc_id == SCTP_FUTURE_ASSOC)) { michael@0: SCTP_INP_RLOCK(inp); michael@0: memcpy(s_info, &inp->def_send, sizeof(inp->def_send)); michael@0: SCTP_INP_RUNLOCK(inp); michael@0: } else { michael@0: SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL); michael@0: error = EINVAL; michael@0: } michael@0: } michael@0: if (error == 0) { michael@0: *optsize = sizeof(struct sctp_sndrcvinfo); michael@0: } michael@0: break; michael@0: } michael@0: case SCTP_INITMSG: michael@0: { michael@0: struct sctp_initmsg *sinit; michael@0: michael@0: SCTP_CHECK_AND_CAST(sinit, optval, struct sctp_initmsg, *optsize); michael@0: SCTP_INP_RLOCK(inp); michael@0: sinit->sinit_num_ostreams = inp->sctp_ep.pre_open_stream_count; michael@0: sinit->sinit_max_instreams = inp->sctp_ep.max_open_streams_intome; michael@0: sinit->sinit_max_attempts = inp->sctp_ep.max_init_times; michael@0: sinit->sinit_max_init_timeo = inp->sctp_ep.initial_init_rto_max; michael@0: SCTP_INP_RUNLOCK(inp); michael@0: *optsize = sizeof(struct sctp_initmsg); michael@0: break; michael@0: } michael@0: case SCTP_PRIMARY_ADDR: michael@0: /* we allow a "get" operation on this */ michael@0: { michael@0: struct sctp_setprim *ssp; michael@0: michael@0: SCTP_CHECK_AND_CAST(ssp, optval, struct sctp_setprim, *optsize); michael@0: SCTP_FIND_STCB(inp, stcb, ssp->ssp_assoc_id); michael@0: michael@0: if (stcb) { michael@0: /* simply copy out the sockaddr_storage... */ michael@0: size_t len; michael@0: michael@0: len = *optsize; michael@0: #ifdef HAVE_SA_LEN michael@0: if (len > stcb->asoc.primary_destination->ro._l_addr.sa.sa_len) michael@0: len = stcb->asoc.primary_destination->ro._l_addr.sa.sa_len; michael@0: #else michael@0: if (stcb->asoc.primary_destination->ro._l_addr.sa.sa_family == AF_INET && michael@0: len > sizeof(struct sockaddr_in)) michael@0: len = sizeof(struct sockaddr_in); michael@0: else if ( michael@0: stcb->asoc.primary_destination->ro._l_addr.sa.sa_family == AF_INET6 && michael@0: len > sizeof(struct sockaddr_in6)) michael@0: len = sizeof(struct sockaddr_in6); michael@0: #endif michael@0: michael@0: memcpy(&ssp->ssp_addr, michael@0: &stcb->asoc.primary_destination->ro._l_addr, michael@0: len); michael@0: SCTP_TCB_UNLOCK(stcb); michael@0: *optsize = sizeof(struct sctp_setprim); michael@0: } else { michael@0: SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL); michael@0: error = EINVAL; michael@0: } michael@0: break; michael@0: } michael@0: case SCTP_HMAC_IDENT: michael@0: { michael@0: struct sctp_hmacalgo *shmac; michael@0: sctp_hmaclist_t *hmaclist; michael@0: uint32_t size; michael@0: int i; michael@0: michael@0: SCTP_CHECK_AND_CAST(shmac, optval, struct sctp_hmacalgo, *optsize); michael@0: michael@0: SCTP_INP_RLOCK(inp); michael@0: hmaclist = inp->sctp_ep.local_hmacs; michael@0: if (hmaclist == NULL) { michael@0: /* no HMACs to return */ michael@0: *optsize = sizeof(*shmac); michael@0: SCTP_INP_RUNLOCK(inp); michael@0: break; michael@0: } michael@0: /* is there room for all of the hmac ids? */ michael@0: size = sizeof(*shmac) + (hmaclist->num_algo * michael@0: sizeof(shmac->shmac_idents[0])); michael@0: if ((size_t)(*optsize) < size) { michael@0: SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL); michael@0: error = EINVAL; michael@0: SCTP_INP_RUNLOCK(inp); michael@0: break; michael@0: } michael@0: /* copy in the list */ michael@0: shmac->shmac_number_of_idents = hmaclist->num_algo; michael@0: for (i = 0; i < hmaclist->num_algo; i++) { michael@0: shmac->shmac_idents[i] = hmaclist->hmac[i]; michael@0: } michael@0: SCTP_INP_RUNLOCK(inp); michael@0: *optsize = size; michael@0: break; michael@0: } michael@0: case SCTP_AUTH_ACTIVE_KEY: michael@0: { michael@0: struct sctp_authkeyid *scact; michael@0: michael@0: SCTP_CHECK_AND_CAST(scact, optval, struct sctp_authkeyid, *optsize); michael@0: SCTP_FIND_STCB(inp, stcb, scact->scact_assoc_id); michael@0: michael@0: if (stcb) { michael@0: /* get the active key on the assoc */ michael@0: scact->scact_keynumber = stcb->asoc.authinfo.active_keyid; michael@0: SCTP_TCB_UNLOCK(stcb); michael@0: } else { michael@0: if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) || michael@0: (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) || michael@0: (scact->scact_assoc_id == SCTP_FUTURE_ASSOC)) { michael@0: /* get the endpoint active key */ michael@0: SCTP_INP_RLOCK(inp); michael@0: scact->scact_keynumber = inp->sctp_ep.default_keyid; michael@0: SCTP_INP_RUNLOCK(inp); michael@0: } else { michael@0: SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL); michael@0: error = EINVAL; michael@0: } michael@0: } michael@0: if (error == 0) { michael@0: *optsize = sizeof(struct sctp_authkeyid); michael@0: } michael@0: break; michael@0: } michael@0: case SCTP_LOCAL_AUTH_CHUNKS: michael@0: { michael@0: struct sctp_authchunks *sac; michael@0: sctp_auth_chklist_t *chklist = NULL; michael@0: size_t size = 0; michael@0: michael@0: SCTP_CHECK_AND_CAST(sac, optval, struct sctp_authchunks, *optsize); michael@0: SCTP_FIND_STCB(inp, stcb, sac->gauth_assoc_id); michael@0: michael@0: if (stcb) { michael@0: /* get off the assoc */ michael@0: chklist = stcb->asoc.local_auth_chunks; michael@0: /* is there enough space? */ michael@0: size = sctp_auth_get_chklist_size(chklist); michael@0: if (*optsize < (sizeof(struct sctp_authchunks) + size)) { michael@0: error = EINVAL; michael@0: SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error); michael@0: } else { michael@0: /* copy in the chunks */ michael@0: (void)sctp_serialize_auth_chunks(chklist, sac->gauth_chunks); michael@0: sac->gauth_number_of_chunks = (uint32_t)size; michael@0: *optsize = sizeof(struct sctp_authchunks) + size; michael@0: } michael@0: SCTP_TCB_UNLOCK(stcb); michael@0: } else { michael@0: if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) || michael@0: (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) || michael@0: (sac->gauth_assoc_id == SCTP_FUTURE_ASSOC)) { michael@0: /* get off the endpoint */ michael@0: SCTP_INP_RLOCK(inp); michael@0: chklist = inp->sctp_ep.local_auth_chunks; michael@0: /* is there enough space? */ michael@0: size = sctp_auth_get_chklist_size(chklist); michael@0: if (*optsize < (sizeof(struct sctp_authchunks) + size)) { michael@0: error = EINVAL; michael@0: SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error); michael@0: } else { michael@0: /* copy in the chunks */ michael@0: (void)sctp_serialize_auth_chunks(chklist, sac->gauth_chunks); michael@0: sac->gauth_number_of_chunks = (uint32_t)size; michael@0: *optsize = sizeof(struct sctp_authchunks) + size; michael@0: } michael@0: SCTP_INP_RUNLOCK(inp); michael@0: } else { michael@0: SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL); michael@0: error = EINVAL; michael@0: } michael@0: } michael@0: break; michael@0: } michael@0: case SCTP_PEER_AUTH_CHUNKS: michael@0: { michael@0: struct sctp_authchunks *sac; michael@0: sctp_auth_chklist_t *chklist = NULL; michael@0: size_t size = 0; michael@0: michael@0: SCTP_CHECK_AND_CAST(sac, optval, struct sctp_authchunks, *optsize); michael@0: SCTP_FIND_STCB(inp, stcb, sac->gauth_assoc_id); michael@0: michael@0: if (stcb) { michael@0: /* get off the assoc */ michael@0: chklist = stcb->asoc.peer_auth_chunks; michael@0: /* is there enough space? */ michael@0: size = sctp_auth_get_chklist_size(chklist); michael@0: if (*optsize < (sizeof(struct sctp_authchunks) + size)) { michael@0: error = EINVAL; michael@0: SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error); michael@0: } else { michael@0: /* copy in the chunks */ michael@0: (void)sctp_serialize_auth_chunks(chklist, sac->gauth_chunks); michael@0: sac->gauth_number_of_chunks = (uint32_t)size; michael@0: *optsize = sizeof(struct sctp_authchunks) + size; michael@0: } michael@0: SCTP_TCB_UNLOCK(stcb); michael@0: } else { michael@0: SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOENT); michael@0: error = ENOENT; michael@0: } michael@0: break; michael@0: } michael@0: #if defined(HAVE_SCTP_PEELOFF_SOCKOPT) michael@0: case SCTP_PEELOFF: michael@0: { michael@0: struct sctp_peeloff_opt *peeloff; michael@0: michael@0: SCTP_CHECK_AND_CAST(peeloff, optval, struct sctp_peeloff_opt, *optsize); michael@0: /* do the peeloff */ michael@0: error = sctp_peeloff_option(p, peeloff); michael@0: if (error == 0) { michael@0: *optsize = sizeof(struct sctp_peeloff_opt); michael@0: } michael@0: } michael@0: break; michael@0: #endif /* HAVE_SCTP_PEELOFF_SOCKOPT */ michael@0: case SCTP_EVENT: michael@0: { michael@0: struct sctp_event *event; michael@0: uint32_t event_type; michael@0: michael@0: SCTP_CHECK_AND_CAST(event, optval, struct sctp_event, *optsize); michael@0: SCTP_FIND_STCB(inp, stcb, event->se_assoc_id); michael@0: michael@0: switch (event->se_type) { michael@0: case SCTP_ASSOC_CHANGE: michael@0: event_type = SCTP_PCB_FLAGS_RECVASSOCEVNT; michael@0: break; michael@0: case SCTP_PEER_ADDR_CHANGE: michael@0: event_type = SCTP_PCB_FLAGS_RECVPADDREVNT; michael@0: break; michael@0: case SCTP_REMOTE_ERROR: michael@0: event_type = SCTP_PCB_FLAGS_RECVPEERERR; michael@0: break; michael@0: case SCTP_SEND_FAILED: michael@0: event_type = SCTP_PCB_FLAGS_RECVSENDFAILEVNT; michael@0: break; michael@0: case SCTP_SHUTDOWN_EVENT: michael@0: event_type = SCTP_PCB_FLAGS_RECVSHUTDOWNEVNT; michael@0: break; michael@0: case SCTP_ADAPTATION_INDICATION: michael@0: event_type = SCTP_PCB_FLAGS_ADAPTATIONEVNT; michael@0: break; michael@0: case SCTP_PARTIAL_DELIVERY_EVENT: michael@0: event_type = SCTP_PCB_FLAGS_PDAPIEVNT; michael@0: break; michael@0: case SCTP_AUTHENTICATION_EVENT: michael@0: event_type = SCTP_PCB_FLAGS_AUTHEVNT; michael@0: break; michael@0: case SCTP_STREAM_RESET_EVENT: michael@0: event_type = SCTP_PCB_FLAGS_STREAM_RESETEVNT; michael@0: break; michael@0: case SCTP_SENDER_DRY_EVENT: michael@0: event_type = SCTP_PCB_FLAGS_DRYEVNT; michael@0: break; michael@0: case SCTP_NOTIFICATIONS_STOPPED_EVENT: michael@0: event_type = 0; michael@0: SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOTSUP); michael@0: error = ENOTSUP; michael@0: break; michael@0: case SCTP_ASSOC_RESET_EVENT: michael@0: event_type = SCTP_PCB_FLAGS_ASSOC_RESETEVNT; michael@0: break; michael@0: case SCTP_STREAM_CHANGE_EVENT: michael@0: event_type = SCTP_PCB_FLAGS_STREAM_CHANGEEVNT; michael@0: break; michael@0: case SCTP_SEND_FAILED_EVENT: michael@0: event_type = SCTP_PCB_FLAGS_RECVNSENDFAILEVNT; michael@0: break; michael@0: default: michael@0: event_type = 0; michael@0: SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL); michael@0: error = EINVAL; michael@0: break; michael@0: } michael@0: if (event_type > 0) { michael@0: if (stcb) { michael@0: event->se_on = sctp_stcb_is_feature_on(inp, stcb, event_type); michael@0: SCTP_TCB_UNLOCK(stcb); michael@0: } else { michael@0: if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) || michael@0: (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) || michael@0: (event->se_assoc_id == SCTP_FUTURE_ASSOC)) { michael@0: SCTP_INP_RLOCK(inp); michael@0: event->se_on = sctp_is_feature_on(inp, event_type); michael@0: SCTP_INP_RUNLOCK(inp); michael@0: } else { michael@0: SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL); michael@0: error = EINVAL; michael@0: } michael@0: } michael@0: } michael@0: if (error == 0) { michael@0: *optsize = sizeof(struct sctp_event); michael@0: } michael@0: break; michael@0: } michael@0: case SCTP_RECVRCVINFO: michael@0: { michael@0: int onoff; michael@0: michael@0: if (*optsize < sizeof(int)) { michael@0: SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL); michael@0: error = EINVAL; michael@0: } else { michael@0: SCTP_INP_RLOCK(inp); michael@0: onoff = sctp_is_feature_on(inp, SCTP_PCB_FLAGS_RECVRCVINFO); michael@0: SCTP_INP_RUNLOCK(inp); michael@0: } michael@0: if (error == 0) { michael@0: /* return the option value */ michael@0: *(int *)optval = onoff; michael@0: *optsize = sizeof(int); michael@0: } michael@0: break; michael@0: } michael@0: case SCTP_RECVNXTINFO: michael@0: { michael@0: int onoff; michael@0: michael@0: if (*optsize < sizeof(int)) { michael@0: SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL); michael@0: error = EINVAL; michael@0: } else { michael@0: SCTP_INP_RLOCK(inp); michael@0: onoff = sctp_is_feature_on(inp, SCTP_PCB_FLAGS_RECVNXTINFO); michael@0: SCTP_INP_RUNLOCK(inp); michael@0: } michael@0: if (error == 0) { michael@0: /* return the option value */ michael@0: *(int *)optval = onoff; michael@0: *optsize = sizeof(int); michael@0: } michael@0: break; michael@0: } michael@0: case SCTP_DEFAULT_SNDINFO: michael@0: { michael@0: struct sctp_sndinfo *info; michael@0: michael@0: SCTP_CHECK_AND_CAST(info, optval, struct sctp_sndinfo, *optsize); michael@0: SCTP_FIND_STCB(inp, stcb, info->snd_assoc_id); michael@0: michael@0: if (stcb) { michael@0: info->snd_sid = stcb->asoc.def_send.sinfo_stream; michael@0: info->snd_flags = stcb->asoc.def_send.sinfo_flags; michael@0: info->snd_flags &= 0xfff0; michael@0: info->snd_ppid = stcb->asoc.def_send.sinfo_ppid; michael@0: info->snd_context = stcb->asoc.def_send.sinfo_context; michael@0: SCTP_TCB_UNLOCK(stcb); michael@0: } else { michael@0: if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) || michael@0: (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) || michael@0: (info->snd_assoc_id == SCTP_FUTURE_ASSOC)) { michael@0: SCTP_INP_RLOCK(inp); michael@0: info->snd_sid = inp->def_send.sinfo_stream; michael@0: info->snd_flags = inp->def_send.sinfo_flags; michael@0: info->snd_flags &= 0xfff0; michael@0: info->snd_ppid = inp->def_send.sinfo_ppid; michael@0: info->snd_context = inp->def_send.sinfo_context; michael@0: SCTP_INP_RUNLOCK(inp); michael@0: } else { michael@0: SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL); michael@0: error = EINVAL; michael@0: } michael@0: } michael@0: if (error == 0) { michael@0: *optsize = sizeof(struct sctp_sndinfo); michael@0: } michael@0: break; michael@0: } michael@0: case SCTP_DEFAULT_PRINFO: michael@0: { michael@0: struct sctp_default_prinfo *info; michael@0: michael@0: SCTP_CHECK_AND_CAST(info, optval, struct sctp_default_prinfo, *optsize); michael@0: SCTP_FIND_STCB(inp, stcb, info->pr_assoc_id); michael@0: michael@0: if (stcb) { michael@0: info->pr_policy = PR_SCTP_POLICY(stcb->asoc.def_send.sinfo_flags); michael@0: info->pr_value = stcb->asoc.def_send.sinfo_timetolive; michael@0: SCTP_TCB_UNLOCK(stcb); michael@0: } else { michael@0: if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) || michael@0: (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) || michael@0: (info->pr_assoc_id == SCTP_FUTURE_ASSOC)) { michael@0: SCTP_INP_RLOCK(inp); michael@0: info->pr_policy = PR_SCTP_POLICY(inp->def_send.sinfo_flags); michael@0: info->pr_value = inp->def_send.sinfo_timetolive; michael@0: SCTP_INP_RUNLOCK(inp); michael@0: } else { michael@0: SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL); michael@0: error = EINVAL; michael@0: } michael@0: } michael@0: if (error == 0) { michael@0: *optsize = sizeof(struct sctp_default_prinfo); michael@0: } michael@0: break; michael@0: } michael@0: case SCTP_PEER_ADDR_THLDS: michael@0: { michael@0: struct sctp_paddrthlds *thlds; michael@0: struct sctp_nets *net; michael@0: michael@0: SCTP_CHECK_AND_CAST(thlds, optval, struct sctp_paddrthlds, *optsize); michael@0: SCTP_FIND_STCB(inp, stcb, thlds->spt_assoc_id); michael@0: michael@0: net = NULL; michael@0: if (stcb) { michael@0: net = sctp_findnet(stcb, (struct sockaddr *)&thlds->spt_address); michael@0: } else { michael@0: /* We increment here since sctp_findassociation_ep_addr() wil michael@0: * do a decrement if it finds the stcb as long as the locked michael@0: * tcb (last argument) is NOT a TCB.. aka NULL. michael@0: */ michael@0: SCTP_INP_INCR_REF(inp); michael@0: stcb = sctp_findassociation_ep_addr(&inp, (struct sockaddr *)&thlds->spt_address, &net, NULL, NULL); michael@0: if (stcb == NULL) { michael@0: SCTP_INP_DECR_REF(inp); michael@0: } michael@0: } michael@0: if (stcb && (net == NULL)) { michael@0: struct sockaddr *sa; michael@0: michael@0: sa = (struct sockaddr *)&thlds->spt_address; michael@0: #ifdef INET michael@0: if (sa->sa_family == AF_INET) { michael@0: struct sockaddr_in *sin; michael@0: michael@0: sin = (struct sockaddr_in *)sa; michael@0: if (sin->sin_addr.s_addr) { michael@0: error = EINVAL; michael@0: SCTP_TCB_UNLOCK(stcb); michael@0: SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error); michael@0: break; michael@0: } michael@0: } else michael@0: #endif michael@0: #ifdef INET6 michael@0: if (sa->sa_family == AF_INET6) { michael@0: struct sockaddr_in6 *sin6; michael@0: michael@0: sin6 = (struct sockaddr_in6 *)sa; michael@0: if (!IN6_IS_ADDR_UNSPECIFIED(&sin6->sin6_addr)) { michael@0: error = EINVAL; michael@0: SCTP_TCB_UNLOCK(stcb); michael@0: SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error); michael@0: break; michael@0: } michael@0: } else michael@0: #endif michael@0: #if defined(__Userspace__) michael@0: if (sa->sa_family == AF_CONN) { michael@0: struct sockaddr_conn *sconn; michael@0: michael@0: sconn = (struct sockaddr_conn *)sa; michael@0: if (sconn->sconn_addr != NULL) { michael@0: error = EINVAL; michael@0: SCTP_TCB_UNLOCK(stcb); michael@0: SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error); michael@0: break; michael@0: } michael@0: } else michael@0: #endif michael@0: { michael@0: error = EAFNOSUPPORT; michael@0: SCTP_TCB_UNLOCK(stcb); michael@0: SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error); michael@0: break; michael@0: } michael@0: } michael@0: michael@0: if (stcb) { michael@0: if (net) { michael@0: thlds->spt_pathmaxrxt = net->failure_threshold; michael@0: thlds->spt_pathpfthld = net->pf_threshold; michael@0: } else { michael@0: thlds->spt_pathmaxrxt = stcb->asoc.def_net_failure; michael@0: thlds->spt_pathpfthld = stcb->asoc.def_net_pf_threshold; michael@0: } michael@0: thlds->spt_assoc_id = sctp_get_associd(stcb); michael@0: SCTP_TCB_UNLOCK(stcb); michael@0: } else { michael@0: if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) || michael@0: (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) || michael@0: (thlds->spt_assoc_id == SCTP_FUTURE_ASSOC)) { michael@0: /* Use endpoint defaults */ michael@0: SCTP_INP_RLOCK(inp); michael@0: thlds->spt_pathmaxrxt = inp->sctp_ep.def_net_failure; michael@0: thlds->spt_pathpfthld = inp->sctp_ep.def_net_pf_threshold; michael@0: SCTP_INP_RUNLOCK(inp); michael@0: } else { michael@0: SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL); michael@0: error = EINVAL; michael@0: } michael@0: } michael@0: if (error == 0) { michael@0: *optsize = sizeof(struct sctp_paddrthlds); michael@0: } michael@0: break; michael@0: } michael@0: case SCTP_REMOTE_UDP_ENCAPS_PORT: michael@0: { michael@0: struct sctp_udpencaps *encaps; michael@0: struct sctp_nets *net; michael@0: michael@0: SCTP_CHECK_AND_CAST(encaps, optval, struct sctp_udpencaps, *optsize); michael@0: SCTP_FIND_STCB(inp, stcb, encaps->sue_assoc_id); michael@0: michael@0: if (stcb) { michael@0: net = sctp_findnet(stcb, (struct sockaddr *)&encaps->sue_address); michael@0: } else { michael@0: /* We increment here since sctp_findassociation_ep_addr() wil michael@0: * do a decrement if it finds the stcb as long as the locked michael@0: * tcb (last argument) is NOT a TCB.. aka NULL. michael@0: */ michael@0: net = NULL; michael@0: SCTP_INP_INCR_REF(inp); michael@0: stcb = sctp_findassociation_ep_addr(&inp, (struct sockaddr *)&encaps->sue_address, &net, NULL, NULL); michael@0: if (stcb == NULL) { michael@0: SCTP_INP_DECR_REF(inp); michael@0: } michael@0: } michael@0: if (stcb && (net == NULL)) { michael@0: struct sockaddr *sa; michael@0: michael@0: sa = (struct sockaddr *)&encaps->sue_address; michael@0: #ifdef INET michael@0: if (sa->sa_family == AF_INET) { michael@0: struct sockaddr_in *sin; michael@0: michael@0: sin = (struct sockaddr_in *)sa; michael@0: if (sin->sin_addr.s_addr) { michael@0: error = EINVAL; michael@0: SCTP_TCB_UNLOCK(stcb); michael@0: SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error); michael@0: break; michael@0: } michael@0: } else michael@0: #endif michael@0: #ifdef INET6 michael@0: if (sa->sa_family == AF_INET6) { michael@0: struct sockaddr_in6 *sin6; michael@0: michael@0: sin6 = (struct sockaddr_in6 *)sa; michael@0: if (!IN6_IS_ADDR_UNSPECIFIED(&sin6->sin6_addr)) { michael@0: error = EINVAL; michael@0: SCTP_TCB_UNLOCK(stcb); michael@0: SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error); michael@0: break; michael@0: } michael@0: } else michael@0: #endif michael@0: #if defined(__Userspace__) michael@0: if (sa->sa_family == AF_CONN) { michael@0: struct sockaddr_conn *sconn; michael@0: michael@0: sconn = (struct sockaddr_conn *)sa; michael@0: if (sconn->sconn_addr != NULL) { michael@0: error = EINVAL; michael@0: SCTP_TCB_UNLOCK(stcb); michael@0: SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error); michael@0: break; michael@0: } michael@0: } else michael@0: #endif michael@0: { michael@0: error = EAFNOSUPPORT; michael@0: SCTP_TCB_UNLOCK(stcb); michael@0: SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error); michael@0: break; michael@0: } michael@0: } michael@0: michael@0: if (stcb) { michael@0: if (net) { michael@0: encaps->sue_port = net->port; michael@0: } else { michael@0: encaps->sue_port = stcb->asoc.port; michael@0: } michael@0: SCTP_TCB_UNLOCK(stcb); michael@0: } else { michael@0: if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) || michael@0: (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) || michael@0: (encaps->sue_assoc_id == SCTP_FUTURE_ASSOC)) { michael@0: SCTP_INP_RLOCK(inp); michael@0: encaps->sue_port = inp->sctp_ep.port; michael@0: SCTP_INP_RUNLOCK(inp); michael@0: } else { michael@0: SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL); michael@0: error = EINVAL; michael@0: } michael@0: } michael@0: if (error == 0) { michael@0: *optsize = sizeof(struct sctp_udpencaps); michael@0: } michael@0: break; michael@0: } michael@0: case SCTP_ENABLE_STREAM_RESET: michael@0: { michael@0: struct sctp_assoc_value *av; michael@0: michael@0: SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize); michael@0: SCTP_FIND_STCB(inp, stcb, av->assoc_id); michael@0: michael@0: if (stcb) { michael@0: av->assoc_value = (uint32_t)stcb->asoc.local_strreset_support; michael@0: SCTP_TCB_UNLOCK(stcb); michael@0: } else { michael@0: if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) || michael@0: (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) || michael@0: (av->assoc_id == SCTP_FUTURE_ASSOC)) { michael@0: SCTP_INP_RLOCK(inp); michael@0: av->assoc_value = (uint32_t)inp->local_strreset_support; michael@0: SCTP_INP_RUNLOCK(inp); michael@0: } else { michael@0: SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL); michael@0: error = EINVAL; michael@0: } michael@0: } michael@0: if (error == 0) { michael@0: *optsize = sizeof(struct sctp_assoc_value); michael@0: } michael@0: break; michael@0: } michael@0: default: michael@0: SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOPROTOOPT); michael@0: error = ENOPROTOOPT; michael@0: break; michael@0: } /* end switch (sopt->sopt_name) */ michael@0: if (error) { michael@0: *optsize = 0; michael@0: } michael@0: return (error); michael@0: } michael@0: michael@0: #if defined(__Panda__) || defined(__Userspace__) michael@0: int michael@0: #else michael@0: static int michael@0: #endif michael@0: sctp_setopt(struct socket *so, int optname, void *optval, size_t optsize, michael@0: void *p) michael@0: { michael@0: int error, set_opt; michael@0: uint32_t *mopt; michael@0: struct sctp_tcb *stcb = NULL; michael@0: struct sctp_inpcb *inp = NULL; michael@0: uint32_t vrf_id; michael@0: michael@0: if (optval == NULL) { michael@0: SCTP_PRINTF("optval is NULL\n"); michael@0: SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL); michael@0: return (EINVAL); michael@0: } michael@0: inp = (struct sctp_inpcb *)so->so_pcb; michael@0: if (inp == NULL) { michael@0: SCTP_PRINTF("inp is NULL?\n"); michael@0: SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL); michael@0: return (EINVAL); michael@0: } michael@0: vrf_id = inp->def_vrf_id; michael@0: michael@0: error = 0; michael@0: switch (optname) { michael@0: case SCTP_NODELAY: michael@0: case SCTP_AUTOCLOSE: michael@0: case SCTP_AUTO_ASCONF: michael@0: case SCTP_EXPLICIT_EOR: michael@0: case SCTP_DISABLE_FRAGMENTS: michael@0: case SCTP_USE_EXT_RCVINFO: michael@0: case SCTP_I_WANT_MAPPED_V4_ADDR: michael@0: /* copy in the option value */ michael@0: SCTP_CHECK_AND_CAST(mopt, optval, uint32_t, optsize); michael@0: set_opt = 0; michael@0: if (error) michael@0: break; michael@0: switch (optname) { michael@0: case SCTP_DISABLE_FRAGMENTS: michael@0: set_opt = SCTP_PCB_FLAGS_NO_FRAGMENT; michael@0: break; michael@0: case SCTP_AUTO_ASCONF: michael@0: /* michael@0: * NOTE: we don't really support this flag michael@0: */ michael@0: if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUNDALL) { michael@0: /* only valid for bound all sockets */ michael@0: if ((SCTP_BASE_SYSCTL(sctp_auto_asconf) == 0) && michael@0: (*mopt != 0)) { michael@0: /* forbidden by admin */ michael@0: SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EPERM); michael@0: return (EPERM); michael@0: } michael@0: set_opt = SCTP_PCB_FLAGS_AUTO_ASCONF; michael@0: } else { michael@0: SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL); michael@0: return (EINVAL); michael@0: } michael@0: break; michael@0: case SCTP_EXPLICIT_EOR: michael@0: set_opt = SCTP_PCB_FLAGS_EXPLICIT_EOR; michael@0: break; michael@0: case SCTP_USE_EXT_RCVINFO: michael@0: set_opt = SCTP_PCB_FLAGS_EXT_RCVINFO; michael@0: break; michael@0: case SCTP_I_WANT_MAPPED_V4_ADDR: michael@0: if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) { michael@0: set_opt = SCTP_PCB_FLAGS_NEEDS_MAPPED_V4; michael@0: } else { michael@0: SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL); michael@0: return (EINVAL); michael@0: } michael@0: break; michael@0: case SCTP_NODELAY: michael@0: set_opt = SCTP_PCB_FLAGS_NODELAY; michael@0: break; michael@0: case SCTP_AUTOCLOSE: michael@0: if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) || michael@0: (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL)) { michael@0: SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL); michael@0: return (EINVAL); michael@0: } michael@0: set_opt = SCTP_PCB_FLAGS_AUTOCLOSE; michael@0: /* michael@0: * The value is in ticks. Note this does not effect michael@0: * old associations, only new ones. michael@0: */ michael@0: inp->sctp_ep.auto_close_time = SEC_TO_TICKS(*mopt); michael@0: break; michael@0: } michael@0: SCTP_INP_WLOCK(inp); michael@0: if (*mopt != 0) { michael@0: sctp_feature_on(inp, set_opt); michael@0: } else { michael@0: sctp_feature_off(inp, set_opt); michael@0: } michael@0: SCTP_INP_WUNLOCK(inp); michael@0: break; michael@0: case SCTP_REUSE_PORT: michael@0: { michael@0: SCTP_CHECK_AND_CAST(mopt, optval, uint32_t, optsize); michael@0: if ((inp->sctp_flags & SCTP_PCB_FLAGS_UNBOUND) == 0) { michael@0: /* Can't set it after we are bound */ michael@0: error = EINVAL; michael@0: break; michael@0: } michael@0: if ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE)) { michael@0: /* Can't do this for a 1-m socket */ michael@0: error = EINVAL; michael@0: break; michael@0: } michael@0: if (optval) michael@0: sctp_feature_on(inp, SCTP_PCB_FLAGS_PORTREUSE); michael@0: else michael@0: sctp_feature_off(inp, SCTP_PCB_FLAGS_PORTREUSE); michael@0: break; michael@0: } michael@0: case SCTP_PARTIAL_DELIVERY_POINT: michael@0: { michael@0: uint32_t *value; michael@0: michael@0: SCTP_CHECK_AND_CAST(value, optval, uint32_t, optsize); michael@0: if (*value > SCTP_SB_LIMIT_RCV(so)) { michael@0: SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL); michael@0: error = EINVAL; michael@0: break; michael@0: } michael@0: inp->partial_delivery_point = *value; michael@0: break; michael@0: } michael@0: case SCTP_FRAGMENT_INTERLEAVE: michael@0: /* not yet until we re-write sctp_recvmsg() */ michael@0: { michael@0: uint32_t *level; michael@0: michael@0: SCTP_CHECK_AND_CAST(level, optval, uint32_t, optsize); michael@0: if (*level == SCTP_FRAG_LEVEL_2) { michael@0: sctp_feature_on(inp, SCTP_PCB_FLAGS_FRAG_INTERLEAVE); michael@0: sctp_feature_on(inp, SCTP_PCB_FLAGS_INTERLEAVE_STRMS); michael@0: } else if (*level == SCTP_FRAG_LEVEL_1) { michael@0: sctp_feature_on(inp, SCTP_PCB_FLAGS_FRAG_INTERLEAVE); michael@0: sctp_feature_off(inp, SCTP_PCB_FLAGS_INTERLEAVE_STRMS); michael@0: } else if (*level == SCTP_FRAG_LEVEL_0) { michael@0: sctp_feature_off(inp, SCTP_PCB_FLAGS_FRAG_INTERLEAVE); michael@0: sctp_feature_off(inp, SCTP_PCB_FLAGS_INTERLEAVE_STRMS); michael@0: michael@0: } else { michael@0: SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL); michael@0: error = EINVAL; michael@0: } michael@0: break; michael@0: } michael@0: case SCTP_CMT_ON_OFF: michael@0: if (SCTP_BASE_SYSCTL(sctp_cmt_on_off)) { michael@0: struct sctp_assoc_value *av; michael@0: michael@0: SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize); michael@0: if (av->assoc_value > SCTP_CMT_MAX) { michael@0: SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL); michael@0: error = EINVAL; michael@0: break; michael@0: } michael@0: SCTP_FIND_STCB(inp, stcb, av->assoc_id); michael@0: if (stcb) { michael@0: stcb->asoc.sctp_cmt_on_off = av->assoc_value; michael@0: SCTP_TCB_UNLOCK(stcb); michael@0: } else { michael@0: if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) || michael@0: (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) || michael@0: (av->assoc_id == SCTP_FUTURE_ASSOC) || michael@0: (av->assoc_id == SCTP_ALL_ASSOC)) { michael@0: SCTP_INP_WLOCK(inp); michael@0: inp->sctp_cmt_on_off = av->assoc_value; michael@0: SCTP_INP_WUNLOCK(inp); michael@0: } michael@0: if ((av->assoc_id == SCTP_CURRENT_ASSOC) || michael@0: (av->assoc_id == SCTP_ALL_ASSOC)) { michael@0: SCTP_INP_RLOCK(inp); michael@0: LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) { michael@0: SCTP_TCB_LOCK(stcb); michael@0: stcb->asoc.sctp_cmt_on_off = av->assoc_value; michael@0: SCTP_TCB_UNLOCK(stcb); michael@0: } michael@0: SCTP_INP_RUNLOCK(inp); michael@0: } michael@0: } michael@0: } else { michael@0: SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOPROTOOPT); michael@0: error = ENOPROTOOPT; michael@0: } michael@0: break; michael@0: case SCTP_PLUGGABLE_CC: michael@0: { michael@0: struct sctp_assoc_value *av; michael@0: struct sctp_nets *net; michael@0: michael@0: SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize); michael@0: if ((av->assoc_value != SCTP_CC_RFC2581) && michael@0: (av->assoc_value != SCTP_CC_HSTCP) && michael@0: (av->assoc_value != SCTP_CC_HTCP) && michael@0: (av->assoc_value != SCTP_CC_RTCC)) { michael@0: SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL); michael@0: error = EINVAL; michael@0: break; michael@0: } michael@0: SCTP_FIND_STCB(inp, stcb, av->assoc_id); michael@0: if (stcb) { michael@0: stcb->asoc.cc_functions = sctp_cc_functions[av->assoc_value]; michael@0: stcb->asoc.congestion_control_module = av->assoc_value; michael@0: if (stcb->asoc.cc_functions.sctp_set_initial_cc_param != NULL) { michael@0: TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) { michael@0: stcb->asoc.cc_functions.sctp_set_initial_cc_param(stcb, net); michael@0: } michael@0: } michael@0: SCTP_TCB_UNLOCK(stcb); michael@0: } else { michael@0: if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) || michael@0: (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) || michael@0: (av->assoc_id == SCTP_FUTURE_ASSOC) || michael@0: (av->assoc_id == SCTP_ALL_ASSOC)) { michael@0: SCTP_INP_WLOCK(inp); michael@0: inp->sctp_ep.sctp_default_cc_module = av->assoc_value; michael@0: SCTP_INP_WUNLOCK(inp); michael@0: } michael@0: if ((av->assoc_id == SCTP_CURRENT_ASSOC) || michael@0: (av->assoc_id == SCTP_ALL_ASSOC)) { michael@0: SCTP_INP_RLOCK(inp); michael@0: LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) { michael@0: SCTP_TCB_LOCK(stcb); michael@0: stcb->asoc.cc_functions = sctp_cc_functions[av->assoc_value]; michael@0: stcb->asoc.congestion_control_module = av->assoc_value; michael@0: if (stcb->asoc.cc_functions.sctp_set_initial_cc_param != NULL) { michael@0: TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) { michael@0: stcb->asoc.cc_functions.sctp_set_initial_cc_param(stcb, net); michael@0: } michael@0: } michael@0: SCTP_TCB_UNLOCK(stcb); michael@0: } michael@0: SCTP_INP_RUNLOCK(inp); michael@0: } michael@0: } michael@0: break; michael@0: } michael@0: case SCTP_CC_OPTION: michael@0: { michael@0: struct sctp_cc_option *cc_opt; michael@0: michael@0: SCTP_CHECK_AND_CAST(cc_opt, optval, struct sctp_cc_option, optsize); michael@0: SCTP_FIND_STCB(inp, stcb, cc_opt->aid_value.assoc_id); michael@0: if (stcb == NULL) { michael@0: if (cc_opt->aid_value.assoc_id == SCTP_CURRENT_ASSOC) { michael@0: SCTP_INP_RLOCK(inp); michael@0: LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) { michael@0: SCTP_TCB_LOCK(stcb); michael@0: if (stcb->asoc.cc_functions.sctp_cwnd_socket_option) { michael@0: (*stcb->asoc.cc_functions.sctp_cwnd_socket_option)(stcb, 1, cc_opt); michael@0: } michael@0: SCTP_TCB_UNLOCK(stcb); michael@0: } michael@0: SCTP_INP_RUNLOCK(inp); michael@0: } else { michael@0: error = EINVAL; michael@0: } michael@0: } else { michael@0: if (stcb->asoc.cc_functions.sctp_cwnd_socket_option == NULL) { michael@0: error = ENOTSUP; michael@0: } else { michael@0: error = (*stcb->asoc.cc_functions.sctp_cwnd_socket_option)(stcb, 1, michael@0: cc_opt); michael@0: } michael@0: SCTP_TCB_UNLOCK(stcb); michael@0: } michael@0: break; michael@0: } michael@0: case SCTP_PLUGGABLE_SS: michael@0: { michael@0: struct sctp_assoc_value *av; michael@0: michael@0: SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize); michael@0: if ((av->assoc_value != SCTP_SS_DEFAULT) && michael@0: (av->assoc_value != SCTP_SS_ROUND_ROBIN) && michael@0: (av->assoc_value != SCTP_SS_ROUND_ROBIN_PACKET) && michael@0: (av->assoc_value != SCTP_SS_PRIORITY) && michael@0: (av->assoc_value != SCTP_SS_FAIR_BANDWITH) && michael@0: (av->assoc_value != SCTP_SS_FIRST_COME)) { michael@0: SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL); michael@0: error = EINVAL; michael@0: break; michael@0: } michael@0: SCTP_FIND_STCB(inp, stcb, av->assoc_id); michael@0: if (stcb) { michael@0: stcb->asoc.ss_functions.sctp_ss_clear(stcb, &stcb->asoc, 1, 1); michael@0: stcb->asoc.ss_functions = sctp_ss_functions[av->assoc_value]; michael@0: stcb->asoc.stream_scheduling_module = av->assoc_value; michael@0: stcb->asoc.ss_functions.sctp_ss_init(stcb, &stcb->asoc, 1); michael@0: SCTP_TCB_UNLOCK(stcb); michael@0: } else { michael@0: if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) || michael@0: (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) || michael@0: (av->assoc_id == SCTP_FUTURE_ASSOC) || michael@0: (av->assoc_id == SCTP_ALL_ASSOC)) { michael@0: SCTP_INP_WLOCK(inp); michael@0: inp->sctp_ep.sctp_default_ss_module = av->assoc_value; michael@0: SCTP_INP_WUNLOCK(inp); michael@0: } michael@0: if ((av->assoc_id == SCTP_CURRENT_ASSOC) || michael@0: (av->assoc_id == SCTP_ALL_ASSOC)) { michael@0: SCTP_INP_RLOCK(inp); michael@0: LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) { michael@0: SCTP_TCB_LOCK(stcb); michael@0: stcb->asoc.ss_functions.sctp_ss_clear(stcb, &stcb->asoc, 1, 1); michael@0: stcb->asoc.ss_functions = sctp_ss_functions[av->assoc_value]; michael@0: stcb->asoc.stream_scheduling_module = av->assoc_value; michael@0: stcb->asoc.ss_functions.sctp_ss_init(stcb, &stcb->asoc, 1); michael@0: SCTP_TCB_UNLOCK(stcb); michael@0: } michael@0: SCTP_INP_RUNLOCK(inp); michael@0: } michael@0: } michael@0: break; michael@0: } michael@0: case SCTP_SS_VALUE: michael@0: { michael@0: struct sctp_stream_value *av; michael@0: michael@0: SCTP_CHECK_AND_CAST(av, optval, struct sctp_stream_value, optsize); michael@0: SCTP_FIND_STCB(inp, stcb, av->assoc_id); michael@0: if (stcb) { michael@0: if (stcb->asoc.ss_functions.sctp_ss_set_value(stcb, &stcb->asoc, &stcb->asoc.strmout[av->stream_id], michael@0: av->stream_value) < 0) { michael@0: SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL); michael@0: error = EINVAL; michael@0: } michael@0: SCTP_TCB_UNLOCK(stcb); michael@0: } else { michael@0: if (av->assoc_id == SCTP_CURRENT_ASSOC) { michael@0: SCTP_INP_RLOCK(inp); michael@0: LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) { michael@0: SCTP_TCB_LOCK(stcb); michael@0: stcb->asoc.ss_functions.sctp_ss_set_value(stcb, michael@0: &stcb->asoc, michael@0: &stcb->asoc.strmout[av->stream_id], michael@0: av->stream_value); michael@0: SCTP_TCB_UNLOCK(stcb); michael@0: } michael@0: SCTP_INP_RUNLOCK(inp); michael@0: michael@0: } else { michael@0: /* Can't set stream value without association */ michael@0: SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL); michael@0: error = EINVAL; michael@0: } michael@0: } michael@0: break; michael@0: } michael@0: case SCTP_CLR_STAT_LOG: michael@0: SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EOPNOTSUPP); michael@0: error = EOPNOTSUPP; michael@0: break; michael@0: case SCTP_CONTEXT: michael@0: { michael@0: struct sctp_assoc_value *av; michael@0: michael@0: SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize); michael@0: SCTP_FIND_STCB(inp, stcb, av->assoc_id); michael@0: michael@0: if (stcb) { michael@0: stcb->asoc.context = av->assoc_value; michael@0: SCTP_TCB_UNLOCK(stcb); michael@0: } else { michael@0: if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) || michael@0: (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) || michael@0: (av->assoc_id == SCTP_FUTURE_ASSOC) || michael@0: (av->assoc_id == SCTP_ALL_ASSOC)) { michael@0: SCTP_INP_WLOCK(inp); michael@0: inp->sctp_context = av->assoc_value; michael@0: SCTP_INP_WUNLOCK(inp); michael@0: } michael@0: if ((av->assoc_id == SCTP_CURRENT_ASSOC) || michael@0: (av->assoc_id == SCTP_ALL_ASSOC)) { michael@0: SCTP_INP_RLOCK(inp); michael@0: LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) { michael@0: SCTP_TCB_LOCK(stcb); michael@0: stcb->asoc.context = av->assoc_value; michael@0: SCTP_TCB_UNLOCK(stcb); michael@0: } michael@0: SCTP_INP_RUNLOCK(inp); michael@0: } michael@0: } michael@0: break; michael@0: } michael@0: case SCTP_VRF_ID: michael@0: { michael@0: uint32_t *default_vrfid; michael@0: #ifdef SCTP_MVRF michael@0: int i; michael@0: #endif michael@0: SCTP_CHECK_AND_CAST(default_vrfid, optval, uint32_t, optsize); michael@0: if (*default_vrfid > SCTP_MAX_VRF_ID) { michael@0: SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL); michael@0: error = EINVAL; michael@0: break; michael@0: } michael@0: #ifdef SCTP_MVRF michael@0: for (i = 0; i < inp->num_vrfs; i++) { michael@0: /* The VRF must be in the VRF list */ michael@0: if (*default_vrfid == inp->m_vrf_ids[i]) { michael@0: SCTP_INP_WLOCK(inp); michael@0: inp->def_vrf_id = *default_vrfid; michael@0: SCTP_INP_WUNLOCK(inp); michael@0: goto sctp_done; michael@0: } michael@0: } michael@0: SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL); michael@0: error = EINVAL; michael@0: #else michael@0: inp->def_vrf_id = *default_vrfid; michael@0: #endif michael@0: #ifdef SCTP_MVRF michael@0: sctp_done: michael@0: #endif michael@0: break; michael@0: } michael@0: case SCTP_DEL_VRF_ID: michael@0: { michael@0: #ifdef SCTP_MVRF michael@0: uint32_t *del_vrfid; michael@0: int i, fnd = 0; michael@0: michael@0: SCTP_CHECK_AND_CAST(del_vrfid, optval, uint32_t, optsize); michael@0: if (*del_vrfid > SCTP_MAX_VRF_ID) { michael@0: SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL); michael@0: error = EINVAL; michael@0: break; michael@0: } michael@0: if (inp->num_vrfs == 1) { michael@0: /* Can't delete last one */ michael@0: SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL); michael@0: error = EINVAL; michael@0: break; michael@0: } michael@0: if ((inp->sctp_flags & SCTP_PCB_FLAGS_UNBOUND) == 0) { michael@0: /* Can't add more once you are bound */ michael@0: SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL); michael@0: error = EINVAL; michael@0: break; michael@0: } michael@0: SCTP_INP_WLOCK(inp); michael@0: for (i = 0; i < inp->num_vrfs; i++) { michael@0: if (*del_vrfid == inp->m_vrf_ids[i]) { michael@0: fnd = 1; michael@0: break; michael@0: } michael@0: } michael@0: if (!fnd) { michael@0: SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL); michael@0: error = EINVAL; michael@0: break; michael@0: } michael@0: if (i != (inp->num_vrfs - 1)) { michael@0: /* Take bottom one and move to this slot */ michael@0: inp->m_vrf_ids[i] = inp->m_vrf_ids[(inp->num_vrfs-1)]; michael@0: } michael@0: if (*del_vrfid == inp->def_vrf_id) { michael@0: /* Take the first one as the new default */ michael@0: inp->def_vrf_id = inp->m_vrf_ids[0]; michael@0: } michael@0: /* Drop the number by one killing last one */ michael@0: inp->num_vrfs--; michael@0: #else michael@0: SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EOPNOTSUPP); michael@0: error = EOPNOTSUPP; michael@0: #endif michael@0: break; michael@0: } michael@0: case SCTP_ADD_VRF_ID: michael@0: { michael@0: #ifdef SCTP_MVRF michael@0: uint32_t *add_vrfid; michael@0: int i; michael@0: michael@0: SCTP_CHECK_AND_CAST(add_vrfid, optval, uint32_t, optsize); michael@0: if (*add_vrfid > SCTP_MAX_VRF_ID) { michael@0: SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL); michael@0: error = EINVAL; michael@0: break; michael@0: } michael@0: if ((inp->sctp_flags & SCTP_PCB_FLAGS_UNBOUND) == 0) { michael@0: /* Can't add more once you are bound */ michael@0: SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL); michael@0: error = EINVAL; michael@0: break; michael@0: } michael@0: SCTP_INP_WLOCK(inp); michael@0: /* Verify its not already here */ michael@0: for (i = 0; i < inp->num_vrfs; i++) { michael@0: if (*add_vrfid == inp->m_vrf_ids[i]) { michael@0: SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EALREADY); michael@0: error = EALREADY; michael@0: SCTP_INP_WUNLOCK(inp); michael@0: break; michael@0: } michael@0: } michael@0: if ((inp->num_vrfs + 1) > inp->vrf_size) { michael@0: /* need to grow array */ michael@0: uint32_t *tarray; michael@0: SCTP_MALLOC(tarray, uint32_t *, michael@0: (sizeof(uint32_t) * (inp->vrf_size + SCTP_DEFAULT_VRF_SIZE)), michael@0: SCTP_M_MVRF); michael@0: if (tarray == NULL) { michael@0: SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOMEM); michael@0: error = ENOMEM; michael@0: SCTP_INP_WUNLOCK(inp); michael@0: break; michael@0: } michael@0: memcpy(tarray, inp->m_vrf_ids, (sizeof(uint32_t) * inp->vrf_size)); michael@0: SCTP_FREE(inp->m_vrf_ids, SCTP_M_MVRF); michael@0: inp->m_vrf_ids = tarray; michael@0: inp->vrf_size += SCTP_DEFAULT_VRF_SIZE; michael@0: } michael@0: inp->m_vrf_ids[inp->num_vrfs] = *add_vrfid; michael@0: inp->num_vrfs++; michael@0: SCTP_INP_WUNLOCK(inp); michael@0: #else michael@0: SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EOPNOTSUPP); michael@0: error = EOPNOTSUPP; michael@0: #endif michael@0: break; michael@0: } michael@0: case SCTP_DELAYED_SACK: michael@0: { michael@0: struct sctp_sack_info *sack; michael@0: michael@0: SCTP_CHECK_AND_CAST(sack, optval, struct sctp_sack_info, optsize); michael@0: SCTP_FIND_STCB(inp, stcb, sack->sack_assoc_id); michael@0: if (sack->sack_delay) { michael@0: if (sack->sack_delay > SCTP_MAX_SACK_DELAY) michael@0: sack->sack_delay = SCTP_MAX_SACK_DELAY; michael@0: if (MSEC_TO_TICKS(sack->sack_delay) < 1) { michael@0: sack->sack_delay = TICKS_TO_MSEC(1); michael@0: } michael@0: } michael@0: if (stcb) { michael@0: if (sack->sack_delay) { michael@0: stcb->asoc.delayed_ack = sack->sack_delay; michael@0: } michael@0: if (sack->sack_freq) { michael@0: stcb->asoc.sack_freq = sack->sack_freq; michael@0: } michael@0: SCTP_TCB_UNLOCK(stcb); michael@0: } else { michael@0: if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) || michael@0: (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) || michael@0: (sack->sack_assoc_id == SCTP_FUTURE_ASSOC) || michael@0: (sack->sack_assoc_id == SCTP_ALL_ASSOC)) { michael@0: SCTP_INP_WLOCK(inp); michael@0: if (sack->sack_delay) { michael@0: inp->sctp_ep.sctp_timeoutticks[SCTP_TIMER_RECV] = MSEC_TO_TICKS(sack->sack_delay); michael@0: } michael@0: if (sack->sack_freq) { michael@0: inp->sctp_ep.sctp_sack_freq = sack->sack_freq; michael@0: } michael@0: SCTP_INP_WUNLOCK(inp); michael@0: } michael@0: if ((sack->sack_assoc_id == SCTP_CURRENT_ASSOC) || michael@0: (sack->sack_assoc_id == SCTP_ALL_ASSOC)) { michael@0: SCTP_INP_RLOCK(inp); michael@0: LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) { michael@0: SCTP_TCB_LOCK(stcb); michael@0: if (sack->sack_delay) { michael@0: stcb->asoc.delayed_ack = sack->sack_delay; michael@0: } michael@0: if (sack->sack_freq) { michael@0: stcb->asoc.sack_freq = sack->sack_freq; michael@0: } michael@0: SCTP_TCB_UNLOCK(stcb); michael@0: } michael@0: SCTP_INP_RUNLOCK(inp); michael@0: } michael@0: } michael@0: break; michael@0: } michael@0: case SCTP_AUTH_CHUNK: michael@0: { michael@0: struct sctp_authchunk *sauth; michael@0: michael@0: SCTP_CHECK_AND_CAST(sauth, optval, struct sctp_authchunk, optsize); michael@0: michael@0: SCTP_INP_WLOCK(inp); michael@0: if (sctp_auth_add_chunk(sauth->sauth_chunk, inp->sctp_ep.local_auth_chunks)) { michael@0: SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL); michael@0: error = EINVAL; michael@0: } michael@0: SCTP_INP_WUNLOCK(inp); michael@0: break; michael@0: } michael@0: case SCTP_AUTH_KEY: michael@0: { michael@0: struct sctp_authkey *sca; michael@0: struct sctp_keyhead *shared_keys; michael@0: sctp_sharedkey_t *shared_key; michael@0: sctp_key_t *key = NULL; michael@0: size_t size; michael@0: michael@0: SCTP_CHECK_AND_CAST(sca, optval, struct sctp_authkey, optsize); michael@0: if (sca->sca_keylength == 0) { michael@0: size = optsize - sizeof(struct sctp_authkey); michael@0: } else { michael@0: if (sca->sca_keylength + sizeof(struct sctp_authkey) <= optsize) { michael@0: size = sca->sca_keylength; michael@0: } else { michael@0: SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL); michael@0: error = EINVAL; michael@0: break; michael@0: } michael@0: } michael@0: SCTP_FIND_STCB(inp, stcb, sca->sca_assoc_id); michael@0: michael@0: if (stcb) { michael@0: shared_keys = &stcb->asoc.shared_keys; michael@0: /* clear the cached keys for this key id */ michael@0: sctp_clear_cachedkeys(stcb, sca->sca_keynumber); michael@0: /* michael@0: * create the new shared key and michael@0: * insert/replace it michael@0: */ michael@0: if (size > 0) { michael@0: key = sctp_set_key(sca->sca_key, (uint32_t) size); michael@0: if (key == NULL) { michael@0: SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOMEM); michael@0: error = ENOMEM; michael@0: SCTP_TCB_UNLOCK(stcb); michael@0: break; michael@0: } michael@0: } michael@0: shared_key = sctp_alloc_sharedkey(); michael@0: if (shared_key == NULL) { michael@0: sctp_free_key(key); michael@0: SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOMEM); michael@0: error = ENOMEM; michael@0: SCTP_TCB_UNLOCK(stcb); michael@0: break; michael@0: } michael@0: shared_key->key = key; michael@0: shared_key->keyid = sca->sca_keynumber; michael@0: error = sctp_insert_sharedkey(shared_keys, shared_key); michael@0: SCTP_TCB_UNLOCK(stcb); michael@0: } else { michael@0: if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) || michael@0: (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) || michael@0: (sca->sca_assoc_id == SCTP_FUTURE_ASSOC) || michael@0: (sca->sca_assoc_id == SCTP_ALL_ASSOC)) { michael@0: SCTP_INP_WLOCK(inp); michael@0: shared_keys = &inp->sctp_ep.shared_keys; michael@0: /* michael@0: * clear the cached keys on all assocs for michael@0: * this key id michael@0: */ michael@0: sctp_clear_cachedkeys_ep(inp, sca->sca_keynumber); michael@0: /* michael@0: * create the new shared key and michael@0: * insert/replace it michael@0: */ michael@0: if (size > 0) { michael@0: key = sctp_set_key(sca->sca_key, (uint32_t) size); michael@0: if (key == NULL) { michael@0: SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOMEM); michael@0: error = ENOMEM; michael@0: SCTP_INP_WUNLOCK(inp); michael@0: break; michael@0: } michael@0: } michael@0: shared_key = sctp_alloc_sharedkey(); michael@0: if (shared_key == NULL) { michael@0: sctp_free_key(key); michael@0: SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOMEM); michael@0: error = ENOMEM; michael@0: SCTP_INP_WUNLOCK(inp); michael@0: break; michael@0: } michael@0: shared_key->key = key; michael@0: shared_key->keyid = sca->sca_keynumber; michael@0: error = sctp_insert_sharedkey(shared_keys, shared_key); michael@0: SCTP_INP_WUNLOCK(inp); michael@0: } michael@0: if ((sca->sca_assoc_id == SCTP_CURRENT_ASSOC) || michael@0: (sca->sca_assoc_id == SCTP_ALL_ASSOC)) { michael@0: SCTP_INP_RLOCK(inp); michael@0: LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) { michael@0: SCTP_TCB_LOCK(stcb); michael@0: shared_keys = &stcb->asoc.shared_keys; michael@0: /* clear the cached keys for this key id */ michael@0: sctp_clear_cachedkeys(stcb, sca->sca_keynumber); michael@0: /* michael@0: * create the new shared key and michael@0: * insert/replace it michael@0: */ michael@0: if (size > 0) { michael@0: key = sctp_set_key(sca->sca_key, (uint32_t) size); michael@0: if (key == NULL) { michael@0: SCTP_TCB_UNLOCK(stcb); michael@0: continue; michael@0: } michael@0: } michael@0: shared_key = sctp_alloc_sharedkey(); michael@0: if (shared_key == NULL) { michael@0: sctp_free_key(key); michael@0: SCTP_TCB_UNLOCK(stcb); michael@0: continue; michael@0: } michael@0: shared_key->key = key; michael@0: shared_key->keyid = sca->sca_keynumber; michael@0: error = sctp_insert_sharedkey(shared_keys, shared_key); michael@0: SCTP_TCB_UNLOCK(stcb); michael@0: } michael@0: SCTP_INP_RUNLOCK(inp); michael@0: } michael@0: } michael@0: break; michael@0: } michael@0: case SCTP_HMAC_IDENT: michael@0: { michael@0: struct sctp_hmacalgo *shmac; michael@0: sctp_hmaclist_t *hmaclist; michael@0: uint16_t hmacid; michael@0: uint32_t i; michael@0: michael@0: SCTP_CHECK_AND_CAST(shmac, optval, struct sctp_hmacalgo, optsize); michael@0: if (optsize < sizeof(struct sctp_hmacalgo) + shmac->shmac_number_of_idents * sizeof(uint16_t)) { michael@0: SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL); michael@0: error = EINVAL; michael@0: break; michael@0: } michael@0: michael@0: hmaclist = sctp_alloc_hmaclist(shmac->shmac_number_of_idents); michael@0: if (hmaclist == NULL) { michael@0: SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOMEM); michael@0: error = ENOMEM; michael@0: break; michael@0: } michael@0: for (i = 0; i < shmac->shmac_number_of_idents; i++) { michael@0: hmacid = shmac->shmac_idents[i]; michael@0: if (sctp_auth_add_hmacid(hmaclist, hmacid)) { michael@0: /* invalid HMACs were found */; michael@0: SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL); michael@0: error = EINVAL; michael@0: sctp_free_hmaclist(hmaclist); michael@0: goto sctp_set_hmac_done; michael@0: } michael@0: } michael@0: for (i = 0; i < hmaclist->num_algo; i++) { michael@0: if (hmaclist->hmac[i] == SCTP_AUTH_HMAC_ID_SHA1) { michael@0: /* already in list */ michael@0: break; michael@0: } michael@0: } michael@0: if (i == hmaclist->num_algo) { michael@0: /* not found in list */ michael@0: sctp_free_hmaclist(hmaclist); michael@0: SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL); michael@0: error = EINVAL; michael@0: break; michael@0: } michael@0: /* set it on the endpoint */ michael@0: SCTP_INP_WLOCK(inp); michael@0: if (inp->sctp_ep.local_hmacs) michael@0: sctp_free_hmaclist(inp->sctp_ep.local_hmacs); michael@0: inp->sctp_ep.local_hmacs = hmaclist; michael@0: SCTP_INP_WUNLOCK(inp); michael@0: sctp_set_hmac_done: michael@0: break; michael@0: } michael@0: case SCTP_AUTH_ACTIVE_KEY: michael@0: { michael@0: struct sctp_authkeyid *scact; michael@0: michael@0: SCTP_CHECK_AND_CAST(scact, optval, struct sctp_authkeyid, optsize); michael@0: SCTP_FIND_STCB(inp, stcb, scact->scact_assoc_id); michael@0: michael@0: /* set the active key on the right place */ michael@0: if (stcb) { michael@0: /* set the active key on the assoc */ michael@0: if (sctp_auth_setactivekey(stcb, michael@0: scact->scact_keynumber)) { michael@0: SCTP_LTRACE_ERR_RET(inp, NULL, NULL, michael@0: SCTP_FROM_SCTP_USRREQ, michael@0: EINVAL); michael@0: error = EINVAL; michael@0: } michael@0: SCTP_TCB_UNLOCK(stcb); michael@0: } else { michael@0: if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) || michael@0: (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) || michael@0: (scact->scact_assoc_id == SCTP_FUTURE_ASSOC) || michael@0: (scact->scact_assoc_id == SCTP_ALL_ASSOC)) { michael@0: SCTP_INP_WLOCK(inp); michael@0: if (sctp_auth_setactivekey_ep(inp, scact->scact_keynumber)) { michael@0: SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL); michael@0: error = EINVAL; michael@0: } michael@0: SCTP_INP_WUNLOCK(inp); michael@0: } michael@0: if ((scact->scact_assoc_id == SCTP_CURRENT_ASSOC) || michael@0: (scact->scact_assoc_id == SCTP_ALL_ASSOC)) { michael@0: SCTP_INP_RLOCK(inp); michael@0: LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) { michael@0: SCTP_TCB_LOCK(stcb); michael@0: sctp_auth_setactivekey(stcb, scact->scact_keynumber); michael@0: SCTP_TCB_UNLOCK(stcb); michael@0: } michael@0: SCTP_INP_RUNLOCK(inp); michael@0: } michael@0: } michael@0: break; michael@0: } michael@0: case SCTP_AUTH_DELETE_KEY: michael@0: { michael@0: struct sctp_authkeyid *scdel; michael@0: michael@0: SCTP_CHECK_AND_CAST(scdel, optval, struct sctp_authkeyid, optsize); michael@0: SCTP_FIND_STCB(inp, stcb, scdel->scact_assoc_id); michael@0: michael@0: /* delete the key from the right place */ michael@0: if (stcb) { michael@0: if (sctp_delete_sharedkey(stcb, scdel->scact_keynumber)) { michael@0: SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL); michael@0: error = EINVAL; michael@0: } michael@0: SCTP_TCB_UNLOCK(stcb); michael@0: } else { michael@0: if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) || michael@0: (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) || michael@0: (scdel->scact_assoc_id == SCTP_FUTURE_ASSOC) || michael@0: (scdel->scact_assoc_id == SCTP_ALL_ASSOC)) { michael@0: SCTP_INP_WLOCK(inp); michael@0: if (sctp_delete_sharedkey_ep(inp, scdel->scact_keynumber)) { michael@0: SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL); michael@0: error = EINVAL; michael@0: } michael@0: SCTP_INP_WUNLOCK(inp); michael@0: } michael@0: if ((scdel->scact_assoc_id == SCTP_CURRENT_ASSOC) || michael@0: (scdel->scact_assoc_id == SCTP_ALL_ASSOC)) { michael@0: SCTP_INP_RLOCK(inp); michael@0: LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) { michael@0: SCTP_TCB_LOCK(stcb); michael@0: sctp_delete_sharedkey(stcb, scdel->scact_keynumber); michael@0: SCTP_TCB_UNLOCK(stcb); michael@0: } michael@0: SCTP_INP_RUNLOCK(inp); michael@0: } michael@0: } michael@0: break; michael@0: } michael@0: case SCTP_AUTH_DEACTIVATE_KEY: michael@0: { michael@0: struct sctp_authkeyid *keyid; michael@0: michael@0: SCTP_CHECK_AND_CAST(keyid, optval, struct sctp_authkeyid, optsize); michael@0: SCTP_FIND_STCB(inp, stcb, keyid->scact_assoc_id); michael@0: michael@0: /* deactivate the key from the right place */ michael@0: if (stcb) { michael@0: if (sctp_deact_sharedkey(stcb, keyid->scact_keynumber)) { michael@0: SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL); michael@0: error = EINVAL; michael@0: } michael@0: SCTP_TCB_UNLOCK(stcb); michael@0: } else { michael@0: if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) || michael@0: (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) || michael@0: (keyid->scact_assoc_id == SCTP_FUTURE_ASSOC) || michael@0: (keyid->scact_assoc_id == SCTP_ALL_ASSOC)) { michael@0: SCTP_INP_WLOCK(inp); michael@0: if (sctp_deact_sharedkey_ep(inp, keyid->scact_keynumber)) { michael@0: SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL); michael@0: error = EINVAL; michael@0: } michael@0: SCTP_INP_WUNLOCK(inp); michael@0: } michael@0: if ((keyid->scact_assoc_id == SCTP_CURRENT_ASSOC) || michael@0: (keyid->scact_assoc_id == SCTP_ALL_ASSOC)) { michael@0: SCTP_INP_RLOCK(inp); michael@0: LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) { michael@0: SCTP_TCB_LOCK(stcb); michael@0: sctp_deact_sharedkey(stcb, keyid->scact_keynumber); michael@0: SCTP_TCB_UNLOCK(stcb); michael@0: } michael@0: SCTP_INP_RUNLOCK(inp); michael@0: } michael@0: } michael@0: break; michael@0: } michael@0: case SCTP_ENABLE_STREAM_RESET: michael@0: { michael@0: struct sctp_assoc_value *av; michael@0: michael@0: SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize); michael@0: if (av->assoc_value & (~SCTP_ENABLE_VALUE_MASK)) { michael@0: SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL); michael@0: error = EINVAL; michael@0: break; michael@0: } michael@0: SCTP_FIND_STCB(inp, stcb, av->assoc_id); michael@0: if (stcb) { michael@0: stcb->asoc.local_strreset_support = (uint8_t)av->assoc_value; michael@0: SCTP_TCB_UNLOCK(stcb); michael@0: } else { michael@0: if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) || michael@0: (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) || michael@0: (av->assoc_id == SCTP_FUTURE_ASSOC) || michael@0: (av->assoc_id == SCTP_ALL_ASSOC)) { michael@0: SCTP_INP_WLOCK(inp); michael@0: inp->local_strreset_support = (uint8_t)av->assoc_value; michael@0: SCTP_INP_WUNLOCK(inp); michael@0: } michael@0: if ((av->assoc_id == SCTP_CURRENT_ASSOC) || michael@0: (av->assoc_id == SCTP_ALL_ASSOC)) { michael@0: SCTP_INP_RLOCK(inp); michael@0: LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) { michael@0: SCTP_TCB_LOCK(stcb); michael@0: stcb->asoc.local_strreset_support = (uint8_t)av->assoc_value; michael@0: SCTP_TCB_UNLOCK(stcb); michael@0: } michael@0: SCTP_INP_RUNLOCK(inp); michael@0: } michael@0: michael@0: } michael@0: break; michael@0: } michael@0: case SCTP_RESET_STREAMS: michael@0: { michael@0: struct sctp_reset_streams *strrst; michael@0: int i, send_out = 0; michael@0: int send_in = 0; michael@0: michael@0: SCTP_CHECK_AND_CAST(strrst, optval, struct sctp_reset_streams, optsize); michael@0: SCTP_FIND_STCB(inp, stcb, strrst->srs_assoc_id); michael@0: if (stcb == NULL) { michael@0: SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOENT); michael@0: error = ENOENT; michael@0: break; michael@0: } michael@0: if (stcb->asoc.peer_supports_strreset == 0) { michael@0: /* michael@0: * Peer does not support the chunk type. michael@0: */ michael@0: SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EOPNOTSUPP); michael@0: error = EOPNOTSUPP; michael@0: SCTP_TCB_UNLOCK(stcb); michael@0: break; michael@0: } michael@0: if (stcb->asoc.stream_reset_outstanding) { michael@0: SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EALREADY); michael@0: error = EALREADY; michael@0: SCTP_TCB_UNLOCK(stcb); michael@0: break; michael@0: } michael@0: if (strrst->srs_flags & SCTP_STREAM_RESET_INCOMING) { michael@0: send_in = 1; michael@0: } michael@0: if (strrst->srs_flags & SCTP_STREAM_RESET_OUTGOING) { michael@0: send_out = 1; michael@0: } michael@0: if ((send_in == 0) && (send_out == 0)) { michael@0: SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL); michael@0: error = EINVAL; michael@0: SCTP_TCB_UNLOCK(stcb); michael@0: break; michael@0: } michael@0: for (i = 0; i < strrst->srs_number_streams; i++) { michael@0: if ((send_in) && michael@0: (strrst->srs_stream_list[i] > stcb->asoc.streamincnt)) { michael@0: SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL); michael@0: error = EINVAL; michael@0: break; michael@0: } michael@0: if ((send_out) && michael@0: (strrst->srs_stream_list[i] > stcb->asoc.streamoutcnt)) { michael@0: SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL); michael@0: error = EINVAL; michael@0: break; michael@0: } michael@0: } michael@0: if (error) { michael@0: SCTP_TCB_UNLOCK(stcb); michael@0: break; michael@0: } michael@0: error = sctp_send_str_reset_req(stcb, strrst->srs_number_streams, michael@0: strrst->srs_stream_list, michael@0: send_out, send_in, 0, 0, 0, 0, 0); michael@0: michael@0: sctp_chunk_output(inp, stcb, SCTP_OUTPUT_FROM_STRRST_REQ, SCTP_SO_LOCKED); michael@0: SCTP_TCB_UNLOCK(stcb); michael@0: break; michael@0: } michael@0: case SCTP_ADD_STREAMS: michael@0: { michael@0: struct sctp_add_streams *stradd; michael@0: uint8_t addstream = 0; michael@0: uint16_t add_o_strmcnt = 0; michael@0: uint16_t add_i_strmcnt = 0; michael@0: michael@0: SCTP_CHECK_AND_CAST(stradd, optval, struct sctp_add_streams, optsize); michael@0: SCTP_FIND_STCB(inp, stcb, stradd->sas_assoc_id); michael@0: if (stcb == NULL) { michael@0: SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOENT); michael@0: error = ENOENT; michael@0: break; michael@0: } michael@0: if (stcb->asoc.peer_supports_strreset == 0) { michael@0: /* michael@0: * Peer does not support the chunk type. michael@0: */ michael@0: SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EOPNOTSUPP); michael@0: error = EOPNOTSUPP; michael@0: SCTP_TCB_UNLOCK(stcb); michael@0: break; michael@0: } michael@0: if (stcb->asoc.stream_reset_outstanding) { michael@0: SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EALREADY); michael@0: error = EALREADY; michael@0: SCTP_TCB_UNLOCK(stcb); michael@0: break; michael@0: } michael@0: if ((stradd->sas_outstrms == 0) && michael@0: (stradd->sas_instrms == 0)) { michael@0: error = EINVAL; michael@0: goto skip_stuff; michael@0: } michael@0: if (stradd->sas_outstrms) { michael@0: addstream = 1; michael@0: /* We allocate here */ michael@0: add_o_strmcnt = stradd->sas_outstrms; michael@0: if ((((int)add_o_strmcnt) + ((int)stcb->asoc.streamoutcnt)) > 0x0000ffff) { michael@0: /* You can't have more than 64k */ michael@0: error = EINVAL; michael@0: goto skip_stuff; michael@0: } michael@0: } michael@0: if (stradd->sas_instrms) { michael@0: int cnt; michael@0: michael@0: addstream |= 2; michael@0: /* We allocate inside sctp_send_str_reset_req() */ michael@0: add_i_strmcnt = stradd->sas_instrms; michael@0: cnt = add_i_strmcnt; michael@0: cnt += stcb->asoc.streamincnt; michael@0: if (cnt > 0x0000ffff) { michael@0: /* You can't have more than 64k */ michael@0: error = EINVAL; michael@0: goto skip_stuff; michael@0: } michael@0: if (cnt > (int)stcb->asoc.max_inbound_streams) { michael@0: /* More than you are allowed */ michael@0: error = EINVAL; michael@0: goto skip_stuff; michael@0: } michael@0: } michael@0: error = sctp_send_str_reset_req(stcb, 0, NULL, 0, 0, 0, addstream, add_o_strmcnt, add_i_strmcnt, 0); michael@0: sctp_chunk_output(inp, stcb, SCTP_OUTPUT_FROM_STRRST_REQ, SCTP_SO_LOCKED); michael@0: skip_stuff: michael@0: SCTP_TCB_UNLOCK(stcb); michael@0: break; michael@0: } michael@0: case SCTP_RESET_ASSOC: michael@0: { michael@0: uint32_t *value; michael@0: michael@0: SCTP_CHECK_AND_CAST(value, optval, uint32_t, optsize); michael@0: SCTP_FIND_STCB(inp, stcb, (sctp_assoc_t) *value); michael@0: if (stcb == NULL) { michael@0: SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOENT); michael@0: error = ENOENT; michael@0: break; michael@0: } michael@0: if (stcb->asoc.peer_supports_strreset == 0) { michael@0: /* michael@0: * Peer does not support the chunk type. michael@0: */ michael@0: SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EOPNOTSUPP); michael@0: error = EOPNOTSUPP; michael@0: SCTP_TCB_UNLOCK(stcb); michael@0: break; michael@0: } michael@0: if (stcb->asoc.stream_reset_outstanding) { michael@0: SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EALREADY); michael@0: error = EALREADY; michael@0: SCTP_TCB_UNLOCK(stcb); michael@0: break; michael@0: } michael@0: error = sctp_send_str_reset_req(stcb, 0, NULL, 0, 0, 1, 0, 0, 0, 0); michael@0: sctp_chunk_output(inp, stcb, SCTP_OUTPUT_FROM_STRRST_REQ, SCTP_SO_LOCKED); michael@0: SCTP_TCB_UNLOCK(stcb); michael@0: break; michael@0: } michael@0: case SCTP_CONNECT_X: michael@0: if (optsize < (sizeof(int) + sizeof(struct sockaddr_in))) { michael@0: SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL); michael@0: error = EINVAL; michael@0: break; michael@0: } michael@0: error = sctp_do_connect_x(so, inp, optval, optsize, p, 0); michael@0: break; michael@0: case SCTP_CONNECT_X_DELAYED: michael@0: if (optsize < (sizeof(int) + sizeof(struct sockaddr_in))) { michael@0: SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL); michael@0: error = EINVAL; michael@0: break; michael@0: } michael@0: error = sctp_do_connect_x(so, inp, optval, optsize, p, 1); michael@0: break; michael@0: case SCTP_CONNECT_X_COMPLETE: michael@0: { michael@0: struct sockaddr *sa; michael@0: struct sctp_nets *net; michael@0: michael@0: /* FIXME MT: check correct? */ michael@0: SCTP_CHECK_AND_CAST(sa, optval, struct sockaddr, optsize); michael@0: michael@0: /* find tcb */ michael@0: if (inp->sctp_flags & SCTP_PCB_FLAGS_CONNECTED) { michael@0: SCTP_INP_RLOCK(inp); michael@0: stcb = LIST_FIRST(&inp->sctp_asoc_list); michael@0: if (stcb) { michael@0: SCTP_TCB_LOCK(stcb); michael@0: net = sctp_findnet(stcb, sa); michael@0: } michael@0: SCTP_INP_RUNLOCK(inp); michael@0: } else { michael@0: /* We increment here since sctp_findassociation_ep_addr() wil michael@0: * do a decrement if it finds the stcb as long as the locked michael@0: * tcb (last argument) is NOT a TCB.. aka NULL. michael@0: */ michael@0: SCTP_INP_INCR_REF(inp); michael@0: stcb = sctp_findassociation_ep_addr(&inp, sa, &net, NULL, NULL); michael@0: if (stcb == NULL) { michael@0: SCTP_INP_DECR_REF(inp); michael@0: } michael@0: } michael@0: michael@0: if (stcb == NULL) { michael@0: SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOENT); michael@0: error = ENOENT; michael@0: break; michael@0: } michael@0: if (stcb->asoc.delayed_connection == 1) { michael@0: stcb->asoc.delayed_connection = 0; michael@0: (void)SCTP_GETTIME_TIMEVAL(&stcb->asoc.time_entered); michael@0: sctp_timer_stop(SCTP_TIMER_TYPE_INIT, inp, stcb, michael@0: stcb->asoc.primary_destination, michael@0: SCTP_FROM_SCTP_USRREQ+SCTP_LOC_9); michael@0: sctp_send_initiate(inp, stcb, SCTP_SO_LOCKED); michael@0: } else { michael@0: /* michael@0: * already expired or did not use delayed michael@0: * connectx michael@0: */ michael@0: SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EALREADY); michael@0: error = EALREADY; michael@0: } michael@0: SCTP_TCB_UNLOCK(stcb); michael@0: break; michael@0: } michael@0: case SCTP_MAX_BURST: michael@0: { michael@0: #if defined(__FreeBSD__) && __FreeBSD_version < 900000 michael@0: uint8_t *burst; michael@0: michael@0: SCTP_CHECK_AND_CAST(burst, optval, uint8_t, optsize); michael@0: michael@0: SCTP_INP_WLOCK(inp); michael@0: inp->sctp_ep.max_burst = *burst; michael@0: SCTP_INP_WUNLOCK(inp); michael@0: #else michael@0: struct sctp_assoc_value *av; michael@0: michael@0: SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize); michael@0: SCTP_FIND_STCB(inp, stcb, av->assoc_id); michael@0: michael@0: if (stcb) { michael@0: stcb->asoc.max_burst = av->assoc_value; michael@0: SCTP_TCB_UNLOCK(stcb); michael@0: } else { michael@0: if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) || michael@0: (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) || michael@0: (av->assoc_id == SCTP_FUTURE_ASSOC) || michael@0: (av->assoc_id == SCTP_ALL_ASSOC)) { michael@0: SCTP_INP_WLOCK(inp); michael@0: inp->sctp_ep.max_burst = av->assoc_value; michael@0: SCTP_INP_WUNLOCK(inp); michael@0: } michael@0: if ((av->assoc_id == SCTP_CURRENT_ASSOC) || michael@0: (av->assoc_id == SCTP_ALL_ASSOC)) { michael@0: SCTP_INP_RLOCK(inp); michael@0: LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) { michael@0: SCTP_TCB_LOCK(stcb); michael@0: stcb->asoc.max_burst = av->assoc_value; michael@0: SCTP_TCB_UNLOCK(stcb); michael@0: } michael@0: SCTP_INP_RUNLOCK(inp); michael@0: } michael@0: } michael@0: #endif michael@0: break; michael@0: } michael@0: case SCTP_MAXSEG: michael@0: { michael@0: struct sctp_assoc_value *av; michael@0: int ovh; michael@0: michael@0: SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize); michael@0: SCTP_FIND_STCB(inp, stcb, av->assoc_id); michael@0: michael@0: if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) { michael@0: ovh = SCTP_MED_OVERHEAD; michael@0: } else { michael@0: ovh = SCTP_MED_V4_OVERHEAD; michael@0: } michael@0: if (stcb) { michael@0: if (av->assoc_value) { michael@0: stcb->asoc.sctp_frag_point = (av->assoc_value + ovh); michael@0: } else { michael@0: stcb->asoc.sctp_frag_point = SCTP_DEFAULT_MAXSEGMENT; michael@0: } michael@0: SCTP_TCB_UNLOCK(stcb); michael@0: } else { michael@0: if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) || michael@0: (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) || michael@0: (av->assoc_id == SCTP_FUTURE_ASSOC)) { michael@0: SCTP_INP_WLOCK(inp); michael@0: /* FIXME MT: I think this is not in tune with the API ID */ michael@0: if (av->assoc_value) { michael@0: inp->sctp_frag_point = (av->assoc_value + ovh); michael@0: } else { michael@0: inp->sctp_frag_point = SCTP_DEFAULT_MAXSEGMENT; michael@0: } michael@0: SCTP_INP_WUNLOCK(inp); michael@0: } else { michael@0: SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL); michael@0: error = EINVAL; michael@0: } michael@0: } michael@0: break; michael@0: } michael@0: case SCTP_EVENTS: michael@0: { michael@0: struct sctp_event_subscribe *events; michael@0: michael@0: SCTP_CHECK_AND_CAST(events, optval, struct sctp_event_subscribe, optsize); michael@0: michael@0: SCTP_INP_WLOCK(inp); michael@0: if (events->sctp_data_io_event) { michael@0: sctp_feature_on(inp, SCTP_PCB_FLAGS_RECVDATAIOEVNT); michael@0: } else { michael@0: sctp_feature_off(inp, SCTP_PCB_FLAGS_RECVDATAIOEVNT); michael@0: } michael@0: michael@0: if (events->sctp_association_event) { michael@0: sctp_feature_on(inp, SCTP_PCB_FLAGS_RECVASSOCEVNT); michael@0: } else { michael@0: sctp_feature_off(inp, SCTP_PCB_FLAGS_RECVASSOCEVNT); michael@0: } michael@0: michael@0: if (events->sctp_address_event) { michael@0: sctp_feature_on(inp, SCTP_PCB_FLAGS_RECVPADDREVNT); michael@0: } else { michael@0: sctp_feature_off(inp, SCTP_PCB_FLAGS_RECVPADDREVNT); michael@0: } michael@0: michael@0: if (events->sctp_send_failure_event) { michael@0: sctp_feature_on(inp, SCTP_PCB_FLAGS_RECVSENDFAILEVNT); michael@0: } else { michael@0: sctp_feature_off(inp, SCTP_PCB_FLAGS_RECVSENDFAILEVNT); michael@0: } michael@0: michael@0: if (events->sctp_peer_error_event) { michael@0: sctp_feature_on(inp, SCTP_PCB_FLAGS_RECVPEERERR); michael@0: } else { michael@0: sctp_feature_off(inp, SCTP_PCB_FLAGS_RECVPEERERR); michael@0: } michael@0: michael@0: if (events->sctp_shutdown_event) { michael@0: sctp_feature_on(inp, SCTP_PCB_FLAGS_RECVSHUTDOWNEVNT); michael@0: } else { michael@0: sctp_feature_off(inp, SCTP_PCB_FLAGS_RECVSHUTDOWNEVNT); michael@0: } michael@0: michael@0: if (events->sctp_partial_delivery_event) { michael@0: sctp_feature_on(inp, SCTP_PCB_FLAGS_PDAPIEVNT); michael@0: } else { michael@0: sctp_feature_off(inp, SCTP_PCB_FLAGS_PDAPIEVNT); michael@0: } michael@0: michael@0: if (events->sctp_adaptation_layer_event) { michael@0: sctp_feature_on(inp, SCTP_PCB_FLAGS_ADAPTATIONEVNT); michael@0: } else { michael@0: sctp_feature_off(inp, SCTP_PCB_FLAGS_ADAPTATIONEVNT); michael@0: } michael@0: michael@0: if (events->sctp_authentication_event) { michael@0: sctp_feature_on(inp, SCTP_PCB_FLAGS_AUTHEVNT); michael@0: } else { michael@0: sctp_feature_off(inp, SCTP_PCB_FLAGS_AUTHEVNT); michael@0: } michael@0: michael@0: if (events->sctp_sender_dry_event) { michael@0: sctp_feature_on(inp, SCTP_PCB_FLAGS_DRYEVNT); michael@0: } else { michael@0: sctp_feature_off(inp, SCTP_PCB_FLAGS_DRYEVNT); michael@0: } michael@0: michael@0: if (events->sctp_stream_reset_event) { michael@0: sctp_feature_on(inp, SCTP_PCB_FLAGS_STREAM_RESETEVNT); michael@0: } else { michael@0: sctp_feature_off(inp, SCTP_PCB_FLAGS_STREAM_RESETEVNT); michael@0: } michael@0: SCTP_INP_WUNLOCK(inp); michael@0: michael@0: SCTP_INP_RLOCK(inp); michael@0: LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) { michael@0: SCTP_TCB_LOCK(stcb); michael@0: if (events->sctp_association_event) { michael@0: sctp_stcb_feature_on(inp, stcb, SCTP_PCB_FLAGS_RECVASSOCEVNT); michael@0: } else { michael@0: sctp_stcb_feature_off(inp, stcb, SCTP_PCB_FLAGS_RECVASSOCEVNT); michael@0: } michael@0: if (events->sctp_address_event) { michael@0: sctp_stcb_feature_on(inp, stcb, SCTP_PCB_FLAGS_RECVPADDREVNT); michael@0: } else { michael@0: sctp_stcb_feature_off(inp, stcb, SCTP_PCB_FLAGS_RECVPADDREVNT); michael@0: } michael@0: if (events->sctp_send_failure_event) { michael@0: sctp_stcb_feature_on(inp, stcb, SCTP_PCB_FLAGS_RECVSENDFAILEVNT); michael@0: } else { michael@0: sctp_stcb_feature_off(inp, stcb, SCTP_PCB_FLAGS_RECVSENDFAILEVNT); michael@0: } michael@0: if (events->sctp_peer_error_event) { michael@0: sctp_stcb_feature_on(inp, stcb, SCTP_PCB_FLAGS_RECVPEERERR); michael@0: } else { michael@0: sctp_stcb_feature_off(inp, stcb, SCTP_PCB_FLAGS_RECVPEERERR); michael@0: } michael@0: if (events->sctp_shutdown_event) { michael@0: sctp_stcb_feature_on(inp, stcb, SCTP_PCB_FLAGS_RECVSHUTDOWNEVNT); michael@0: } else { michael@0: sctp_stcb_feature_off(inp, stcb, SCTP_PCB_FLAGS_RECVSHUTDOWNEVNT); michael@0: } michael@0: if (events->sctp_partial_delivery_event) { michael@0: sctp_stcb_feature_on(inp, stcb, SCTP_PCB_FLAGS_PDAPIEVNT); michael@0: } else { michael@0: sctp_stcb_feature_off(inp, stcb, SCTP_PCB_FLAGS_PDAPIEVNT); michael@0: } michael@0: if (events->sctp_adaptation_layer_event) { michael@0: sctp_stcb_feature_on(inp, stcb, SCTP_PCB_FLAGS_ADAPTATIONEVNT); michael@0: } else { michael@0: sctp_stcb_feature_off(inp, stcb, SCTP_PCB_FLAGS_ADAPTATIONEVNT); michael@0: } michael@0: if (events->sctp_authentication_event) { michael@0: sctp_stcb_feature_on(inp, stcb, SCTP_PCB_FLAGS_AUTHEVNT); michael@0: } else { michael@0: sctp_stcb_feature_off(inp, stcb, SCTP_PCB_FLAGS_AUTHEVNT); michael@0: } michael@0: if (events->sctp_sender_dry_event) { michael@0: sctp_stcb_feature_on(inp, stcb, SCTP_PCB_FLAGS_DRYEVNT); michael@0: } else { michael@0: sctp_stcb_feature_off(inp, stcb, SCTP_PCB_FLAGS_DRYEVNT); michael@0: } michael@0: if (events->sctp_stream_reset_event) { michael@0: sctp_stcb_feature_on(inp, stcb, SCTP_PCB_FLAGS_STREAM_RESETEVNT); michael@0: } else { michael@0: sctp_stcb_feature_off(inp, stcb, SCTP_PCB_FLAGS_STREAM_RESETEVNT); michael@0: } michael@0: SCTP_TCB_UNLOCK(stcb); michael@0: } michael@0: /* Send up the sender dry event only for 1-to-1 style sockets. */ michael@0: if (events->sctp_sender_dry_event) { michael@0: if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) || michael@0: (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL)) { michael@0: stcb = LIST_FIRST(&inp->sctp_asoc_list); michael@0: if (stcb) { michael@0: SCTP_TCB_LOCK(stcb); michael@0: if (TAILQ_EMPTY(&stcb->asoc.send_queue) && michael@0: TAILQ_EMPTY(&stcb->asoc.sent_queue) && michael@0: (stcb->asoc.stream_queue_cnt == 0)) { michael@0: sctp_ulp_notify(SCTP_NOTIFY_SENDER_DRY, stcb, 0, NULL, SCTP_SO_LOCKED); michael@0: } michael@0: SCTP_TCB_UNLOCK(stcb); michael@0: } michael@0: } michael@0: } michael@0: SCTP_INP_RUNLOCK(inp); michael@0: break; michael@0: } michael@0: case SCTP_ADAPTATION_LAYER: michael@0: { michael@0: struct sctp_setadaptation *adap_bits; michael@0: michael@0: SCTP_CHECK_AND_CAST(adap_bits, optval, struct sctp_setadaptation, optsize); michael@0: SCTP_INP_WLOCK(inp); michael@0: inp->sctp_ep.adaptation_layer_indicator = adap_bits->ssb_adaptation_ind; michael@0: inp->sctp_ep.adaptation_layer_indicator_provided = 1; michael@0: SCTP_INP_WUNLOCK(inp); michael@0: break; michael@0: } michael@0: #ifdef SCTP_DEBUG michael@0: case SCTP_SET_INITIAL_DBG_SEQ: michael@0: { michael@0: uint32_t *vvv; michael@0: michael@0: SCTP_CHECK_AND_CAST(vvv, optval, uint32_t, optsize); michael@0: SCTP_INP_WLOCK(inp); michael@0: inp->sctp_ep.initial_sequence_debug = *vvv; michael@0: SCTP_INP_WUNLOCK(inp); michael@0: break; michael@0: } michael@0: #endif michael@0: case SCTP_DEFAULT_SEND_PARAM: michael@0: { michael@0: struct sctp_sndrcvinfo *s_info; michael@0: michael@0: SCTP_CHECK_AND_CAST(s_info, optval, struct sctp_sndrcvinfo, optsize); michael@0: SCTP_FIND_STCB(inp, stcb, s_info->sinfo_assoc_id); michael@0: michael@0: if (stcb) { michael@0: if (s_info->sinfo_stream < stcb->asoc.streamoutcnt) { michael@0: memcpy(&stcb->asoc.def_send, s_info, min(optsize, sizeof(stcb->asoc.def_send))); michael@0: } else { michael@0: SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL); michael@0: error = EINVAL; michael@0: } michael@0: SCTP_TCB_UNLOCK(stcb); michael@0: } else { michael@0: if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) || michael@0: (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) || michael@0: (s_info->sinfo_assoc_id == SCTP_FUTURE_ASSOC) || michael@0: (s_info->sinfo_assoc_id == SCTP_ALL_ASSOC)) { michael@0: SCTP_INP_WLOCK(inp); michael@0: memcpy(&inp->def_send, s_info, min(optsize, sizeof(inp->def_send))); michael@0: SCTP_INP_WUNLOCK(inp); michael@0: } michael@0: if ((s_info->sinfo_assoc_id == SCTP_CURRENT_ASSOC) || michael@0: (s_info->sinfo_assoc_id == SCTP_ALL_ASSOC)) { michael@0: SCTP_INP_RLOCK(inp); michael@0: LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) { michael@0: SCTP_TCB_LOCK(stcb); michael@0: if (s_info->sinfo_stream < stcb->asoc.streamoutcnt) { michael@0: memcpy(&stcb->asoc.def_send, s_info, min(optsize, sizeof(stcb->asoc.def_send))); michael@0: } michael@0: SCTP_TCB_UNLOCK(stcb); michael@0: } michael@0: SCTP_INP_RUNLOCK(inp); michael@0: } michael@0: } michael@0: break; michael@0: } michael@0: case SCTP_PEER_ADDR_PARAMS: michael@0: { michael@0: struct sctp_paddrparams *paddrp; michael@0: struct sctp_nets *net; michael@0: michael@0: SCTP_CHECK_AND_CAST(paddrp, optval, struct sctp_paddrparams, optsize); michael@0: SCTP_FIND_STCB(inp, stcb, paddrp->spp_assoc_id); michael@0: net = NULL; michael@0: if (stcb) { michael@0: net = sctp_findnet(stcb, (struct sockaddr *)&paddrp->spp_address); michael@0: } else { michael@0: /* We increment here since sctp_findassociation_ep_addr() wil michael@0: * do a decrement if it finds the stcb as long as the locked michael@0: * tcb (last argument) is NOT a TCB.. aka NULL. michael@0: */ michael@0: SCTP_INP_INCR_REF(inp); michael@0: stcb = sctp_findassociation_ep_addr(&inp, michael@0: (struct sockaddr *)&paddrp->spp_address, michael@0: &net, NULL, NULL); michael@0: if (stcb == NULL) { michael@0: SCTP_INP_DECR_REF(inp); michael@0: } michael@0: } michael@0: if (stcb && (net == NULL)) { michael@0: struct sockaddr *sa; michael@0: michael@0: sa = (struct sockaddr *)&paddrp->spp_address; michael@0: #ifdef INET michael@0: if (sa->sa_family == AF_INET) { michael@0: michael@0: struct sockaddr_in *sin; michael@0: sin = (struct sockaddr_in *)sa; michael@0: if (sin->sin_addr.s_addr) { michael@0: SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL); michael@0: SCTP_TCB_UNLOCK(stcb); michael@0: error = EINVAL; michael@0: break; michael@0: } michael@0: } else michael@0: #endif michael@0: #ifdef INET6 michael@0: if (sa->sa_family == AF_INET6) { michael@0: struct sockaddr_in6 *sin6; michael@0: michael@0: sin6 = (struct sockaddr_in6 *)sa; michael@0: if (!IN6_IS_ADDR_UNSPECIFIED(&sin6->sin6_addr)) { michael@0: SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL); michael@0: SCTP_TCB_UNLOCK(stcb); michael@0: error = EINVAL; michael@0: break; michael@0: } michael@0: } else michael@0: #endif michael@0: #if defined(__Userspace__) michael@0: if (sa->sa_family == AF_CONN) { michael@0: struct sockaddr_conn *sconn; michael@0: michael@0: sconn = (struct sockaddr_conn *)sa; michael@0: if (sconn->sconn_addr != NULL) { michael@0: SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL); michael@0: SCTP_TCB_UNLOCK(stcb); michael@0: error = EINVAL; michael@0: break; michael@0: } michael@0: } else michael@0: #endif michael@0: { michael@0: error = EAFNOSUPPORT; michael@0: SCTP_TCB_UNLOCK(stcb); michael@0: SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error); michael@0: break; michael@0: } michael@0: } michael@0: /* sanity checks */ michael@0: if ((paddrp->spp_flags & SPP_HB_ENABLE) && (paddrp->spp_flags & SPP_HB_DISABLE)) { michael@0: if (stcb) michael@0: SCTP_TCB_UNLOCK(stcb); michael@0: SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL); michael@0: return (EINVAL); michael@0: } michael@0: michael@0: if ((paddrp->spp_flags & SPP_PMTUD_ENABLE) && (paddrp->spp_flags & SPP_PMTUD_DISABLE)) { michael@0: if (stcb) michael@0: SCTP_TCB_UNLOCK(stcb); michael@0: SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL); michael@0: return (EINVAL); michael@0: } michael@0: michael@0: if (stcb) { michael@0: /************************TCB SPECIFIC SET ******************/ michael@0: /* michael@0: * do we change the timer for HB, we run michael@0: * only one? michael@0: */ michael@0: int ovh = 0; michael@0: michael@0: if (stcb->sctp_ep->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) { michael@0: ovh = SCTP_MED_OVERHEAD; michael@0: } else { michael@0: ovh = SCTP_MED_V4_OVERHEAD; michael@0: } michael@0: michael@0: /* network sets ? */ michael@0: if (net) { michael@0: /************************NET SPECIFIC SET ******************/ michael@0: if (paddrp->spp_flags & SPP_HB_DISABLE) { michael@0: if (!(net->dest_state & SCTP_ADDR_UNCONFIRMED) && michael@0: !(net->dest_state & SCTP_ADDR_NOHB)) { michael@0: sctp_timer_stop(SCTP_TIMER_TYPE_HEARTBEAT, inp, stcb, net, michael@0: SCTP_FROM_SCTP_USRREQ+SCTP_LOC_10); michael@0: } michael@0: net->dest_state |= SCTP_ADDR_NOHB; michael@0: } michael@0: if (paddrp->spp_flags & SPP_HB_ENABLE) { michael@0: if (paddrp->spp_hbinterval) { michael@0: net->heart_beat_delay = paddrp->spp_hbinterval; michael@0: } else if (paddrp->spp_flags & SPP_HB_TIME_IS_ZERO) { michael@0: net->heart_beat_delay = 0; michael@0: } michael@0: sctp_timer_stop(SCTP_TIMER_TYPE_HEARTBEAT, inp, stcb, net, michael@0: SCTP_FROM_SCTP_USRREQ+SCTP_LOC_10); michael@0: sctp_timer_start(SCTP_TIMER_TYPE_HEARTBEAT, inp, stcb, net); michael@0: net->dest_state &= ~SCTP_ADDR_NOHB; michael@0: } michael@0: if (paddrp->spp_flags & SPP_HB_DEMAND) { michael@0: /* on demand HB */ michael@0: sctp_send_hb(stcb, net, SCTP_SO_LOCKED); michael@0: sctp_chunk_output(inp, stcb, SCTP_OUTPUT_FROM_SOCKOPT, SCTP_SO_LOCKED); michael@0: sctp_timer_start(SCTP_TIMER_TYPE_HEARTBEAT, inp, stcb, net); michael@0: } michael@0: if ((paddrp->spp_flags & SPP_PMTUD_DISABLE) && (paddrp->spp_pathmtu >= SCTP_SMALLEST_PMTU)) { michael@0: if (SCTP_OS_TIMER_PENDING(&net->pmtu_timer.timer)) { michael@0: sctp_timer_stop(SCTP_TIMER_TYPE_PATHMTURAISE, inp, stcb, net, michael@0: SCTP_FROM_SCTP_USRREQ+SCTP_LOC_10); michael@0: } michael@0: net->dest_state |= SCTP_ADDR_NO_PMTUD; michael@0: net->mtu = paddrp->spp_pathmtu + ovh; michael@0: if (net->mtu < stcb->asoc.smallest_mtu) { michael@0: sctp_pathmtu_adjustment(stcb, net->mtu); michael@0: } michael@0: } michael@0: if (paddrp->spp_flags & SPP_PMTUD_ENABLE) { michael@0: if (!SCTP_OS_TIMER_PENDING(&net->pmtu_timer.timer)) { michael@0: sctp_timer_start(SCTP_TIMER_TYPE_PATHMTURAISE, inp, stcb, net); michael@0: } michael@0: net->dest_state &= ~SCTP_ADDR_NO_PMTUD; michael@0: } michael@0: if (paddrp->spp_pathmaxrxt) { michael@0: if (net->dest_state & SCTP_ADDR_PF) { michael@0: if (net->error_count > paddrp->spp_pathmaxrxt) { michael@0: net->dest_state &= ~SCTP_ADDR_PF; michael@0: } michael@0: } else { michael@0: if ((net->error_count <= paddrp->spp_pathmaxrxt) && michael@0: (net->error_count > net->pf_threshold)) { michael@0: net->dest_state |= SCTP_ADDR_PF; michael@0: sctp_send_hb(stcb, net, SCTP_SO_LOCKED); michael@0: sctp_timer_stop(SCTP_TIMER_TYPE_HEARTBEAT, stcb->sctp_ep, stcb, net, SCTP_FROM_SCTP_TIMER + SCTP_LOC_3); michael@0: sctp_timer_start(SCTP_TIMER_TYPE_HEARTBEAT, stcb->sctp_ep, stcb, net); michael@0: } michael@0: } michael@0: if (net->dest_state & SCTP_ADDR_REACHABLE) { michael@0: if (net->error_count > paddrp->spp_pathmaxrxt) { michael@0: net->dest_state &= ~SCTP_ADDR_REACHABLE; michael@0: sctp_ulp_notify(SCTP_NOTIFY_INTERFACE_DOWN, stcb, 0, net, SCTP_SO_LOCKED); michael@0: } michael@0: } else { michael@0: if (net->error_count <= paddrp->spp_pathmaxrxt) { michael@0: net->dest_state |= SCTP_ADDR_REACHABLE; michael@0: sctp_ulp_notify(SCTP_NOTIFY_INTERFACE_UP, stcb, 0, net, SCTP_SO_LOCKED); michael@0: } michael@0: } michael@0: net->failure_threshold = paddrp->spp_pathmaxrxt; michael@0: } michael@0: if (paddrp->spp_flags & SPP_DSCP) { michael@0: net->dscp = paddrp->spp_dscp & 0xfc; michael@0: net->dscp |= 0x01; michael@0: } michael@0: #ifdef INET6 michael@0: if (paddrp->spp_flags & SPP_IPV6_FLOWLABEL) { michael@0: if (net->ro._l_addr.sa.sa_family == AF_INET6) { michael@0: net->flowlabel = paddrp->spp_ipv6_flowlabel & 0x000fffff; michael@0: net->flowlabel |= 0x80000000; michael@0: } michael@0: } michael@0: #endif michael@0: } else { michael@0: /************************ASSOC ONLY -- NO NET SPECIFIC SET ******************/ michael@0: if (paddrp->spp_pathmaxrxt) { michael@0: stcb->asoc.def_net_failure = paddrp->spp_pathmaxrxt; michael@0: TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) { michael@0: if (net->dest_state & SCTP_ADDR_PF) { michael@0: if (net->error_count > paddrp->spp_pathmaxrxt) { michael@0: net->dest_state &= ~SCTP_ADDR_PF; michael@0: } michael@0: } else { michael@0: if ((net->error_count <= paddrp->spp_pathmaxrxt) && michael@0: (net->error_count > net->pf_threshold)) { michael@0: net->dest_state |= SCTP_ADDR_PF; michael@0: sctp_send_hb(stcb, net, SCTP_SO_LOCKED); michael@0: sctp_timer_stop(SCTP_TIMER_TYPE_HEARTBEAT, stcb->sctp_ep, stcb, net, SCTP_FROM_SCTP_TIMER + SCTP_LOC_3); michael@0: sctp_timer_start(SCTP_TIMER_TYPE_HEARTBEAT, stcb->sctp_ep, stcb, net); michael@0: } michael@0: } michael@0: if (net->dest_state & SCTP_ADDR_REACHABLE) { michael@0: if (net->error_count > paddrp->spp_pathmaxrxt) { michael@0: net->dest_state &= ~SCTP_ADDR_REACHABLE; michael@0: sctp_ulp_notify(SCTP_NOTIFY_INTERFACE_DOWN, stcb, 0, net, SCTP_SO_LOCKED); michael@0: } michael@0: } else { michael@0: if (net->error_count <= paddrp->spp_pathmaxrxt) { michael@0: net->dest_state |= SCTP_ADDR_REACHABLE; michael@0: sctp_ulp_notify(SCTP_NOTIFY_INTERFACE_UP, stcb, 0, net, SCTP_SO_LOCKED); michael@0: } michael@0: } michael@0: net->failure_threshold = paddrp->spp_pathmaxrxt; michael@0: } michael@0: } michael@0: michael@0: if (paddrp->spp_flags & SPP_HB_ENABLE) { michael@0: if (paddrp->spp_hbinterval) { michael@0: stcb->asoc.heart_beat_delay = paddrp->spp_hbinterval; michael@0: } else if (paddrp->spp_flags & SPP_HB_TIME_IS_ZERO) { michael@0: stcb->asoc.heart_beat_delay = 0; michael@0: } michael@0: /* Turn back on the timer */ michael@0: TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) { michael@0: if (paddrp->spp_hbinterval) { michael@0: net->heart_beat_delay = paddrp->spp_hbinterval; michael@0: } else if (paddrp->spp_flags & SPP_HB_TIME_IS_ZERO) { michael@0: net->heart_beat_delay = 0; michael@0: } michael@0: if (net->dest_state & SCTP_ADDR_NOHB) { michael@0: net->dest_state &= ~SCTP_ADDR_NOHB; michael@0: } michael@0: sctp_timer_stop(SCTP_TIMER_TYPE_HEARTBEAT, inp, stcb, net, michael@0: SCTP_FROM_SCTP_USRREQ+SCTP_LOC_10); michael@0: sctp_timer_start(SCTP_TIMER_TYPE_HEARTBEAT, inp, stcb, net); michael@0: } michael@0: sctp_stcb_feature_off(inp, stcb, SCTP_PCB_FLAGS_DONOT_HEARTBEAT); michael@0: } michael@0: if (paddrp->spp_flags & SPP_HB_DISABLE) { michael@0: TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) { michael@0: if (!(net->dest_state & SCTP_ADDR_NOHB)) { michael@0: net->dest_state |= SCTP_ADDR_NOHB; michael@0: if (!(net->dest_state & SCTP_ADDR_UNCONFIRMED)) { michael@0: sctp_timer_stop(SCTP_TIMER_TYPE_HEARTBEAT, inp, stcb, net, SCTP_FROM_SCTP_USRREQ+SCTP_LOC_10); michael@0: } michael@0: } michael@0: } michael@0: sctp_stcb_feature_on(inp, stcb, SCTP_PCB_FLAGS_DONOT_HEARTBEAT); michael@0: } michael@0: if ((paddrp->spp_flags & SPP_PMTUD_DISABLE) && (paddrp->spp_pathmtu >= SCTP_SMALLEST_PMTU)) { michael@0: TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) { michael@0: if (SCTP_OS_TIMER_PENDING(&net->pmtu_timer.timer)) { michael@0: sctp_timer_stop(SCTP_TIMER_TYPE_PATHMTURAISE, inp, stcb, net, michael@0: SCTP_FROM_SCTP_USRREQ+SCTP_LOC_10); michael@0: } michael@0: net->dest_state |= SCTP_ADDR_NO_PMTUD; michael@0: net->mtu = paddrp->spp_pathmtu + ovh; michael@0: if (net->mtu < stcb->asoc.smallest_mtu) { michael@0: sctp_pathmtu_adjustment(stcb, net->mtu); michael@0: } michael@0: } michael@0: sctp_stcb_feature_on(inp, stcb, SCTP_PCB_FLAGS_DO_NOT_PMTUD); michael@0: } michael@0: if (paddrp->spp_flags & SPP_PMTUD_ENABLE) { michael@0: TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) { michael@0: if (!SCTP_OS_TIMER_PENDING(&net->pmtu_timer.timer)) { michael@0: sctp_timer_start(SCTP_TIMER_TYPE_PATHMTURAISE, inp, stcb, net); michael@0: } michael@0: net->dest_state &= ~SCTP_ADDR_NO_PMTUD; michael@0: } michael@0: sctp_stcb_feature_off(inp, stcb, SCTP_PCB_FLAGS_DO_NOT_PMTUD); michael@0: } michael@0: if (paddrp->spp_flags & SPP_DSCP) { michael@0: TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) { michael@0: net->dscp = paddrp->spp_dscp & 0xfc; michael@0: net->dscp |= 0x01; michael@0: } michael@0: stcb->asoc.default_dscp = paddrp->spp_dscp & 0xfc; michael@0: stcb->asoc.default_dscp |= 0x01; michael@0: } michael@0: #ifdef INET6 michael@0: if (paddrp->spp_flags & SPP_IPV6_FLOWLABEL) { michael@0: TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) { michael@0: if (net->ro._l_addr.sa.sa_family == AF_INET6) { michael@0: net->flowlabel = paddrp->spp_ipv6_flowlabel & 0x000fffff; michael@0: net->flowlabel |= 0x80000000; michael@0: } michael@0: } michael@0: stcb->asoc.default_flowlabel = paddrp->spp_ipv6_flowlabel & 0x000fffff; michael@0: stcb->asoc.default_flowlabel |= 0x80000000; michael@0: } michael@0: #endif michael@0: } michael@0: SCTP_TCB_UNLOCK(stcb); michael@0: } else { michael@0: /************************NO TCB, SET TO default stuff ******************/ michael@0: if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) || michael@0: (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) || michael@0: (paddrp->spp_assoc_id == SCTP_FUTURE_ASSOC)) { michael@0: SCTP_INP_WLOCK(inp); michael@0: /* michael@0: * For the TOS/FLOWLABEL stuff you set it michael@0: * with the options on the socket michael@0: */ michael@0: if (paddrp->spp_pathmaxrxt) { michael@0: inp->sctp_ep.def_net_failure = paddrp->spp_pathmaxrxt; michael@0: } michael@0: michael@0: if (paddrp->spp_flags & SPP_HB_TIME_IS_ZERO) michael@0: inp->sctp_ep.sctp_timeoutticks[SCTP_TIMER_HEARTBEAT] = 0; michael@0: else if (paddrp->spp_hbinterval) { michael@0: if (paddrp->spp_hbinterval > SCTP_MAX_HB_INTERVAL) michael@0: paddrp->spp_hbinterval= SCTP_MAX_HB_INTERVAL; michael@0: inp->sctp_ep.sctp_timeoutticks[SCTP_TIMER_HEARTBEAT] = MSEC_TO_TICKS(paddrp->spp_hbinterval); michael@0: } michael@0: michael@0: if (paddrp->spp_flags & SPP_HB_ENABLE) { michael@0: if (paddrp->spp_flags & SPP_HB_TIME_IS_ZERO) { michael@0: inp->sctp_ep.sctp_timeoutticks[SCTP_TIMER_HEARTBEAT] = 0; michael@0: } else if (paddrp->spp_hbinterval) { michael@0: inp->sctp_ep.sctp_timeoutticks[SCTP_TIMER_HEARTBEAT] = MSEC_TO_TICKS(paddrp->spp_hbinterval); michael@0: } michael@0: sctp_feature_off(inp, SCTP_PCB_FLAGS_DONOT_HEARTBEAT); michael@0: } else if (paddrp->spp_flags & SPP_HB_DISABLE) { michael@0: sctp_feature_on(inp, SCTP_PCB_FLAGS_DONOT_HEARTBEAT); michael@0: } michael@0: if (paddrp->spp_flags & SPP_PMTUD_ENABLE) { michael@0: sctp_feature_off(inp, SCTP_PCB_FLAGS_DO_NOT_PMTUD); michael@0: } else if (paddrp->spp_flags & SPP_PMTUD_DISABLE) { michael@0: sctp_feature_on(inp, SCTP_PCB_FLAGS_DO_NOT_PMTUD); michael@0: } michael@0: if (paddrp->spp_flags & SPP_DSCP) { michael@0: inp->sctp_ep.default_dscp = paddrp->spp_dscp & 0xfc; michael@0: inp->sctp_ep.default_dscp |= 0x01; michael@0: } michael@0: #ifdef INET6 michael@0: if (paddrp->spp_flags & SPP_IPV6_FLOWLABEL) { michael@0: if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) { michael@0: inp->sctp_ep.default_flowlabel = paddrp->spp_ipv6_flowlabel & 0x000fffff; michael@0: inp->sctp_ep.default_flowlabel |= 0x80000000; michael@0: } michael@0: } michael@0: #endif michael@0: SCTP_INP_WUNLOCK(inp); michael@0: } else { michael@0: SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL); michael@0: error = EINVAL; michael@0: } michael@0: } michael@0: break; michael@0: } michael@0: case SCTP_RTOINFO: michael@0: { michael@0: struct sctp_rtoinfo *srto; michael@0: uint32_t new_init, new_min, new_max; michael@0: michael@0: SCTP_CHECK_AND_CAST(srto, optval, struct sctp_rtoinfo, optsize); michael@0: SCTP_FIND_STCB(inp, stcb, srto->srto_assoc_id); michael@0: michael@0: if (stcb) { michael@0: if (srto->srto_initial) michael@0: new_init = srto->srto_initial; michael@0: else michael@0: new_init = stcb->asoc.initial_rto; michael@0: if (srto->srto_max) michael@0: new_max = srto->srto_max; michael@0: else michael@0: new_max = stcb->asoc.maxrto; michael@0: if (srto->srto_min) michael@0: new_min = srto->srto_min; michael@0: else michael@0: new_min = stcb->asoc.minrto; michael@0: if ((new_min <= new_init) && (new_init <= new_max)) { michael@0: stcb->asoc.initial_rto = new_init; michael@0: stcb->asoc.maxrto = new_max; michael@0: stcb->asoc.minrto = new_min; michael@0: } else { michael@0: SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL); michael@0: error = EINVAL; michael@0: } michael@0: SCTP_TCB_UNLOCK(stcb); michael@0: } else { michael@0: if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) || michael@0: (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) || michael@0: (srto->srto_assoc_id == SCTP_FUTURE_ASSOC)) { michael@0: SCTP_INP_WLOCK(inp); michael@0: if (srto->srto_initial) michael@0: new_init = srto->srto_initial; michael@0: else michael@0: new_init = inp->sctp_ep.initial_rto; michael@0: if (srto->srto_max) michael@0: new_max = srto->srto_max; michael@0: else michael@0: new_max = inp->sctp_ep.sctp_maxrto; michael@0: if (srto->srto_min) michael@0: new_min = srto->srto_min; michael@0: else michael@0: new_min = inp->sctp_ep.sctp_minrto; michael@0: if ((new_min <= new_init) && (new_init <= new_max)) { michael@0: inp->sctp_ep.initial_rto = new_init; michael@0: inp->sctp_ep.sctp_maxrto = new_max; michael@0: inp->sctp_ep.sctp_minrto = new_min; michael@0: } else { michael@0: SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL); michael@0: error = EINVAL; michael@0: } michael@0: SCTP_INP_WUNLOCK(inp); michael@0: } else { michael@0: SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL); michael@0: error = EINVAL; michael@0: } michael@0: } michael@0: break; michael@0: } michael@0: case SCTP_ASSOCINFO: michael@0: { michael@0: struct sctp_assocparams *sasoc; michael@0: michael@0: SCTP_CHECK_AND_CAST(sasoc, optval, struct sctp_assocparams, optsize); michael@0: SCTP_FIND_STCB(inp, stcb, sasoc->sasoc_assoc_id); michael@0: if (sasoc->sasoc_cookie_life) { michael@0: /* boundary check the cookie life */ michael@0: if (sasoc->sasoc_cookie_life < 1000) michael@0: sasoc->sasoc_cookie_life = 1000; michael@0: if (sasoc->sasoc_cookie_life > SCTP_MAX_COOKIE_LIFE) { michael@0: sasoc->sasoc_cookie_life = SCTP_MAX_COOKIE_LIFE; michael@0: } michael@0: } michael@0: if (stcb) { michael@0: if (sasoc->sasoc_asocmaxrxt) michael@0: stcb->asoc.max_send_times = sasoc->sasoc_asocmaxrxt; michael@0: if (sasoc->sasoc_cookie_life) { michael@0: stcb->asoc.cookie_life = MSEC_TO_TICKS(sasoc->sasoc_cookie_life); michael@0: } michael@0: SCTP_TCB_UNLOCK(stcb); michael@0: } else { michael@0: if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) || michael@0: (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) || michael@0: (sasoc->sasoc_assoc_id == SCTP_FUTURE_ASSOC)) { michael@0: SCTP_INP_WLOCK(inp); michael@0: if (sasoc->sasoc_asocmaxrxt) michael@0: inp->sctp_ep.max_send_times = sasoc->sasoc_asocmaxrxt; michael@0: if (sasoc->sasoc_cookie_life) { michael@0: inp->sctp_ep.def_cookie_life = MSEC_TO_TICKS(sasoc->sasoc_cookie_life); michael@0: } michael@0: SCTP_INP_WUNLOCK(inp); michael@0: } else { michael@0: SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL); michael@0: error = EINVAL; michael@0: } michael@0: } michael@0: break; michael@0: } michael@0: case SCTP_INITMSG: michael@0: { michael@0: struct sctp_initmsg *sinit; michael@0: michael@0: SCTP_CHECK_AND_CAST(sinit, optval, struct sctp_initmsg, optsize); michael@0: SCTP_INP_WLOCK(inp); michael@0: if (sinit->sinit_num_ostreams) michael@0: inp->sctp_ep.pre_open_stream_count = sinit->sinit_num_ostreams; michael@0: michael@0: if (sinit->sinit_max_instreams) michael@0: inp->sctp_ep.max_open_streams_intome = sinit->sinit_max_instreams; michael@0: michael@0: if (sinit->sinit_max_attempts) michael@0: inp->sctp_ep.max_init_times = sinit->sinit_max_attempts; michael@0: michael@0: if (sinit->sinit_max_init_timeo) michael@0: inp->sctp_ep.initial_init_rto_max = sinit->sinit_max_init_timeo; michael@0: SCTP_INP_WUNLOCK(inp); michael@0: break; michael@0: } michael@0: case SCTP_PRIMARY_ADDR: michael@0: { michael@0: struct sctp_setprim *spa; michael@0: struct sctp_nets *net; michael@0: michael@0: SCTP_CHECK_AND_CAST(spa, optval, struct sctp_setprim, optsize); michael@0: SCTP_FIND_STCB(inp, stcb, spa->ssp_assoc_id); michael@0: michael@0: net = NULL; michael@0: if (stcb) { michael@0: net = sctp_findnet(stcb, (struct sockaddr *)&spa->ssp_addr); michael@0: } else { michael@0: /* We increment here since sctp_findassociation_ep_addr() wil michael@0: * do a decrement if it finds the stcb as long as the locked michael@0: * tcb (last argument) is NOT a TCB.. aka NULL. michael@0: */ michael@0: SCTP_INP_INCR_REF(inp); michael@0: stcb = sctp_findassociation_ep_addr(&inp, michael@0: (struct sockaddr *)&spa->ssp_addr, michael@0: &net, NULL, NULL); michael@0: if (stcb == NULL) { michael@0: SCTP_INP_DECR_REF(inp); michael@0: } michael@0: } michael@0: michael@0: if ((stcb) && (net)) { michael@0: if ((net != stcb->asoc.primary_destination) && michael@0: (!(net->dest_state & SCTP_ADDR_UNCONFIRMED))) { michael@0: /* Ok we need to set it */ michael@0: if (sctp_set_primary_addr(stcb, (struct sockaddr *)NULL, net) == 0) { michael@0: if ((stcb->asoc.alternate) && michael@0: (!(net->dest_state & SCTP_ADDR_PF)) && michael@0: (net->dest_state & SCTP_ADDR_REACHABLE)) { michael@0: sctp_free_remote_addr(stcb->asoc.alternate); michael@0: stcb->asoc.alternate = NULL; michael@0: } michael@0: } michael@0: } michael@0: } else { michael@0: SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL); michael@0: error = EINVAL; michael@0: } michael@0: if (stcb) { michael@0: SCTP_TCB_UNLOCK(stcb); michael@0: } michael@0: break; michael@0: } michael@0: case SCTP_SET_DYNAMIC_PRIMARY: michael@0: { michael@0: union sctp_sockstore *ss; michael@0: #ifdef SCTP_MVRF michael@0: int i, fnd = 0; michael@0: #endif michael@0: #if !defined(__Windows__) && !defined(__Userspace__) michael@0: #if defined(__APPLE__) michael@0: struct proc *proc; michael@0: #endif michael@0: #ifdef __FreeBSD__ michael@0: #if __FreeBSD_version > 602000 michael@0: error = priv_check(curthread, michael@0: PRIV_NETINET_RESERVEDPORT); michael@0: #elif __FreeBSD_version >= 500000 michael@0: error = suser((struct thread *)p); michael@0: #else michael@0: error = suser(p); michael@0: #endif michael@0: #elif defined(__APPLE__) michael@0: proc = (struct proc *)p; michael@0: if (p) { michael@0: error = suser(proc->p_ucred, &proc->p_acflag); michael@0: } else { michael@0: break; michael@0: } michael@0: #else michael@0: error = suser(p, 0); michael@0: #endif michael@0: #endif michael@0: if (error) michael@0: break; michael@0: michael@0: SCTP_CHECK_AND_CAST(ss, optval, union sctp_sockstore, optsize); michael@0: /* SUPER USER CHECK? */ michael@0: #ifdef SCTP_MVRF michael@0: for (i = 0; i < inp->num_vrfs; i++) { michael@0: if (vrf_id == inp->m_vrf_ids[i]) { michael@0: fnd = 1; michael@0: break; michael@0: } michael@0: } michael@0: if (!fnd) { michael@0: SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL); michael@0: error = EINVAL; michael@0: break; michael@0: } michael@0: #endif michael@0: error = sctp_dynamic_set_primary(&ss->sa, vrf_id); michael@0: break; michael@0: } michael@0: case SCTP_SET_PEER_PRIMARY_ADDR: michael@0: { michael@0: struct sctp_setpeerprim *sspp; michael@0: michael@0: SCTP_CHECK_AND_CAST(sspp, optval, struct sctp_setpeerprim, optsize); michael@0: SCTP_FIND_STCB(inp, stcb, sspp->sspp_assoc_id); michael@0: if (stcb != NULL) { michael@0: struct sctp_ifa *ifa; michael@0: ifa = sctp_find_ifa_by_addr((struct sockaddr *)&sspp->sspp_addr, michael@0: stcb->asoc.vrf_id, SCTP_ADDR_NOT_LOCKED); michael@0: if (ifa == NULL) { michael@0: SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL); michael@0: error = EINVAL; michael@0: goto out_of_it; michael@0: } michael@0: if ((inp->sctp_flags & SCTP_PCB_FLAGS_BOUNDALL) == 0) { michael@0: /* Must validate the ifa found is in our ep */ michael@0: struct sctp_laddr *laddr; michael@0: int found = 0; michael@0: LIST_FOREACH(laddr, &inp->sctp_addr_list, sctp_nxt_addr) { michael@0: if (laddr->ifa == NULL) { michael@0: SCTPDBG(SCTP_DEBUG_OUTPUT1, "%s: NULL ifa\n", michael@0: __FUNCTION__); michael@0: continue; michael@0: } michael@0: if (laddr->ifa == ifa) { michael@0: found = 1; michael@0: break; michael@0: } michael@0: } michael@0: if (!found) { michael@0: SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL); michael@0: error = EINVAL; michael@0: goto out_of_it; michael@0: } michael@0: } michael@0: if (sctp_set_primary_ip_address_sa(stcb, michael@0: (struct sockaddr *)&sspp->sspp_addr) != 0) { michael@0: SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL); michael@0: error = EINVAL; michael@0: } michael@0: out_of_it: michael@0: SCTP_TCB_UNLOCK(stcb); michael@0: } else { michael@0: SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL); michael@0: error = EINVAL; michael@0: } michael@0: break; michael@0: } michael@0: case SCTP_BINDX_ADD_ADDR: michael@0: { michael@0: struct sctp_getaddresses *addrs; michael@0: #if defined(__FreeBSD__) && __FreeBSD_version >= 500000 michael@0: struct thread *td; michael@0: michael@0: td = (struct thread *)p; michael@0: #endif michael@0: SCTP_CHECK_AND_CAST(addrs, optval, struct sctp_getaddresses, michael@0: optsize); michael@0: #ifdef INET michael@0: if (addrs->addr->sa_family == AF_INET) { michael@0: if (optsize < sizeof(struct sctp_getaddresses) - sizeof(struct sockaddr) + sizeof(struct sockaddr_in)) { michael@0: SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL); michael@0: error = EINVAL; michael@0: break; michael@0: } michael@0: #if defined(__FreeBSD__) && __FreeBSD_version >= 800000 michael@0: if (td != NULL && (error = prison_local_ip4(td->td_ucred, &(((struct sockaddr_in *)(addrs->addr))->sin_addr)))) { michael@0: SCTP_LTRACE_ERR_RET(inp, stcb, NULL, SCTP_FROM_SCTP_USRREQ, error); michael@0: break; michael@0: } michael@0: #endif michael@0: } else michael@0: #endif michael@0: #ifdef INET6 michael@0: if (addrs->addr->sa_family == AF_INET6) { michael@0: if (optsize < sizeof(struct sctp_getaddresses) - sizeof(struct sockaddr) + sizeof(struct sockaddr_in6)) { michael@0: SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL); michael@0: error = EINVAL; michael@0: break; michael@0: } michael@0: #if defined(__FreeBSD__) && __FreeBSD_version >= 800000 michael@0: if (td != NULL && (error = prison_local_ip6(td->td_ucred, &(((struct sockaddr_in6 *)(addrs->addr))->sin6_addr), michael@0: (SCTP_IPV6_V6ONLY(inp) != 0))) != 0) { michael@0: SCTP_LTRACE_ERR_RET(inp, stcb, NULL, SCTP_FROM_SCTP_USRREQ, error); michael@0: break; michael@0: } michael@0: #endif michael@0: } else michael@0: #endif michael@0: { michael@0: error = EAFNOSUPPORT; michael@0: break; michael@0: } michael@0: sctp_bindx_add_address(so, inp, addrs->addr, michael@0: addrs->sget_assoc_id, vrf_id, michael@0: &error, p); michael@0: break; michael@0: } michael@0: case SCTP_BINDX_REM_ADDR: michael@0: { michael@0: struct sctp_getaddresses *addrs; michael@0: #if defined(__FreeBSD__) && __FreeBSD_version >= 500000 michael@0: struct thread *td; michael@0: td = (struct thread *)p; michael@0: michael@0: #endif michael@0: SCTP_CHECK_AND_CAST(addrs, optval, struct sctp_getaddresses, optsize); michael@0: #ifdef INET michael@0: if (addrs->addr->sa_family == AF_INET) { michael@0: if (optsize < sizeof(struct sctp_getaddresses) - sizeof(struct sockaddr) + sizeof(struct sockaddr_in)) { michael@0: SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL); michael@0: error = EINVAL; michael@0: break; michael@0: } michael@0: #if defined(__FreeBSD__) && __FreeBSD_version >= 800000 michael@0: if (td != NULL && (error = prison_local_ip4(td->td_ucred, &(((struct sockaddr_in *)(addrs->addr))->sin_addr)))) { michael@0: SCTP_LTRACE_ERR_RET(inp, stcb, NULL, SCTP_FROM_SCTP_USRREQ, error); michael@0: break; michael@0: } michael@0: #endif michael@0: } else michael@0: #endif michael@0: #ifdef INET6 michael@0: if (addrs->addr->sa_family == AF_INET6) { michael@0: if (optsize < sizeof(struct sctp_getaddresses) - sizeof(struct sockaddr) + sizeof(struct sockaddr_in6)) { michael@0: SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL); michael@0: error = EINVAL; michael@0: break; michael@0: } michael@0: #if defined(__FreeBSD__) && __FreeBSD_version >= 800000 michael@0: if (td != NULL && michael@0: (error = prison_local_ip6(td->td_ucred, michael@0: &(((struct sockaddr_in6 *)(addrs->addr))->sin6_addr), michael@0: (SCTP_IPV6_V6ONLY(inp) != 0))) != 0) { michael@0: SCTP_LTRACE_ERR_RET(inp, stcb, NULL, SCTP_FROM_SCTP_USRREQ, error); michael@0: break; michael@0: } michael@0: #endif michael@0: } else michael@0: #endif michael@0: { michael@0: error = EAFNOSUPPORT; michael@0: break; michael@0: } michael@0: sctp_bindx_delete_address(inp, addrs->addr, michael@0: addrs->sget_assoc_id, vrf_id, michael@0: &error); michael@0: break; michael@0: } michael@0: #ifdef __APPLE__ michael@0: case SCTP_LISTEN_FIX: michael@0: /* only applies to one-to-many sockets */ michael@0: if (inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) { michael@0: /* make sure the ACCEPTCONN flag is OFF */ michael@0: so->so_options &= ~SO_ACCEPTCONN; michael@0: } else { michael@0: /* otherwise, not allowed */ michael@0: SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL); michael@0: error = EINVAL; michael@0: } michael@0: break; michael@0: #endif /* __APPLE__ */ michael@0: case SCTP_EVENT: michael@0: { michael@0: struct sctp_event *event; michael@0: uint32_t event_type; michael@0: michael@0: SCTP_CHECK_AND_CAST(event, optval, struct sctp_event, optsize); michael@0: SCTP_FIND_STCB(inp, stcb, event->se_assoc_id); michael@0: switch (event->se_type) { michael@0: case SCTP_ASSOC_CHANGE: michael@0: event_type = SCTP_PCB_FLAGS_RECVASSOCEVNT; michael@0: break; michael@0: case SCTP_PEER_ADDR_CHANGE: michael@0: event_type = SCTP_PCB_FLAGS_RECVPADDREVNT; michael@0: break; michael@0: case SCTP_REMOTE_ERROR: michael@0: event_type = SCTP_PCB_FLAGS_RECVPEERERR; michael@0: break; michael@0: case SCTP_SEND_FAILED: michael@0: event_type = SCTP_PCB_FLAGS_RECVSENDFAILEVNT; michael@0: break; michael@0: case SCTP_SHUTDOWN_EVENT: michael@0: event_type = SCTP_PCB_FLAGS_RECVSHUTDOWNEVNT; michael@0: break; michael@0: case SCTP_ADAPTATION_INDICATION: michael@0: event_type = SCTP_PCB_FLAGS_ADAPTATIONEVNT; michael@0: break; michael@0: case SCTP_PARTIAL_DELIVERY_EVENT: michael@0: event_type = SCTP_PCB_FLAGS_PDAPIEVNT; michael@0: break; michael@0: case SCTP_AUTHENTICATION_EVENT: michael@0: event_type = SCTP_PCB_FLAGS_AUTHEVNT; michael@0: break; michael@0: case SCTP_STREAM_RESET_EVENT: michael@0: event_type = SCTP_PCB_FLAGS_STREAM_RESETEVNT; michael@0: break; michael@0: case SCTP_SENDER_DRY_EVENT: michael@0: event_type = SCTP_PCB_FLAGS_DRYEVNT; michael@0: break; michael@0: case SCTP_NOTIFICATIONS_STOPPED_EVENT: michael@0: event_type = 0; michael@0: SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOTSUP); michael@0: error = ENOTSUP; michael@0: break; michael@0: case SCTP_ASSOC_RESET_EVENT: michael@0: event_type = SCTP_PCB_FLAGS_ASSOC_RESETEVNT; michael@0: break; michael@0: case SCTP_STREAM_CHANGE_EVENT: michael@0: event_type = SCTP_PCB_FLAGS_STREAM_CHANGEEVNT; michael@0: break; michael@0: case SCTP_SEND_FAILED_EVENT: michael@0: event_type = SCTP_PCB_FLAGS_RECVNSENDFAILEVNT; michael@0: break; michael@0: default: michael@0: event_type = 0; michael@0: SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL); michael@0: error = EINVAL; michael@0: break; michael@0: } michael@0: if (event_type > 0) { michael@0: if (stcb) { michael@0: if (event->se_on) { michael@0: sctp_stcb_feature_on(inp, stcb, event_type); michael@0: if (event_type == SCTP_PCB_FLAGS_DRYEVNT) { michael@0: if (TAILQ_EMPTY(&stcb->asoc.send_queue) && michael@0: TAILQ_EMPTY(&stcb->asoc.sent_queue) && michael@0: (stcb->asoc.stream_queue_cnt == 0)) { michael@0: sctp_ulp_notify(SCTP_NOTIFY_SENDER_DRY, stcb, 0, NULL, SCTP_SO_LOCKED); michael@0: } michael@0: } michael@0: } else { michael@0: sctp_stcb_feature_off(inp, stcb, event_type); michael@0: } michael@0: SCTP_TCB_UNLOCK(stcb); michael@0: } else { michael@0: /* michael@0: * We don't want to send up a storm of events, michael@0: * so return an error for sender dry events michael@0: */ michael@0: if ((event_type == SCTP_PCB_FLAGS_DRYEVNT) && michael@0: ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) == 0) && michael@0: ((inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) == 0) && michael@0: ((event->se_assoc_id == SCTP_ALL_ASSOC) || michael@0: (event->se_assoc_id == SCTP_CURRENT_ASSOC))) { michael@0: SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOTSUP); michael@0: error = ENOTSUP; michael@0: break; michael@0: } michael@0: if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) || michael@0: (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) || michael@0: (event->se_assoc_id == SCTP_FUTURE_ASSOC) || michael@0: (event->se_assoc_id == SCTP_ALL_ASSOC)) { michael@0: SCTP_INP_WLOCK(inp); michael@0: if (event->se_on) { michael@0: sctp_feature_on(inp, event_type); michael@0: } else { michael@0: sctp_feature_off(inp, event_type); michael@0: } michael@0: SCTP_INP_WUNLOCK(inp); michael@0: } michael@0: if ((event->se_assoc_id == SCTP_CURRENT_ASSOC) || michael@0: (event->se_assoc_id == SCTP_ALL_ASSOC)) { michael@0: SCTP_INP_RLOCK(inp); michael@0: LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) { michael@0: SCTP_TCB_LOCK(stcb); michael@0: if (event->se_on) { michael@0: sctp_stcb_feature_on(inp, stcb, event_type); michael@0: } else { michael@0: sctp_stcb_feature_off(inp, stcb, event_type); michael@0: } michael@0: SCTP_TCB_UNLOCK(stcb); michael@0: } michael@0: SCTP_INP_RUNLOCK(inp); michael@0: } michael@0: } michael@0: } michael@0: break; michael@0: } michael@0: case SCTP_RECVRCVINFO: michael@0: { michael@0: int *onoff; michael@0: michael@0: SCTP_CHECK_AND_CAST(onoff, optval, int, optsize); michael@0: SCTP_INP_WLOCK(inp); michael@0: if (*onoff != 0) { michael@0: sctp_feature_on(inp, SCTP_PCB_FLAGS_RECVRCVINFO); michael@0: } else { michael@0: sctp_feature_off(inp, SCTP_PCB_FLAGS_RECVRCVINFO); michael@0: } michael@0: SCTP_INP_WUNLOCK(inp); michael@0: break; michael@0: } michael@0: case SCTP_RECVNXTINFO: michael@0: { michael@0: int *onoff; michael@0: michael@0: SCTP_CHECK_AND_CAST(onoff, optval, int, optsize); michael@0: SCTP_INP_WLOCK(inp); michael@0: if (*onoff != 0) { michael@0: sctp_feature_on(inp, SCTP_PCB_FLAGS_RECVNXTINFO); michael@0: } else { michael@0: sctp_feature_off(inp, SCTP_PCB_FLAGS_RECVNXTINFO); michael@0: } michael@0: SCTP_INP_WUNLOCK(inp); michael@0: break; michael@0: } michael@0: case SCTP_DEFAULT_SNDINFO: michael@0: { michael@0: struct sctp_sndinfo *info; michael@0: uint16_t policy; michael@0: michael@0: SCTP_CHECK_AND_CAST(info, optval, struct sctp_sndinfo, optsize); michael@0: SCTP_FIND_STCB(inp, stcb, info->snd_assoc_id); michael@0: michael@0: if (stcb) { michael@0: if (info->snd_sid < stcb->asoc.streamoutcnt) { michael@0: stcb->asoc.def_send.sinfo_stream = info->snd_sid; michael@0: policy = PR_SCTP_POLICY(stcb->asoc.def_send.sinfo_flags); michael@0: stcb->asoc.def_send.sinfo_flags = info->snd_flags; michael@0: stcb->asoc.def_send.sinfo_flags |= policy; michael@0: stcb->asoc.def_send.sinfo_ppid = info->snd_ppid; michael@0: stcb->asoc.def_send.sinfo_context = info->snd_context; michael@0: } else { michael@0: SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL); michael@0: error = EINVAL; michael@0: } michael@0: SCTP_TCB_UNLOCK(stcb); michael@0: } else { michael@0: if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) || michael@0: (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) || michael@0: (info->snd_assoc_id == SCTP_FUTURE_ASSOC) || michael@0: (info->snd_assoc_id == SCTP_ALL_ASSOC)) { michael@0: SCTP_INP_WLOCK(inp); michael@0: inp->def_send.sinfo_stream = info->snd_sid; michael@0: policy = PR_SCTP_POLICY(inp->def_send.sinfo_flags); michael@0: inp->def_send.sinfo_flags = info->snd_flags; michael@0: inp->def_send.sinfo_flags |= policy; michael@0: inp->def_send.sinfo_ppid = info->snd_ppid; michael@0: inp->def_send.sinfo_context = info->snd_context; michael@0: SCTP_INP_WUNLOCK(inp); michael@0: } michael@0: if ((info->snd_assoc_id == SCTP_CURRENT_ASSOC) || michael@0: (info->snd_assoc_id == SCTP_ALL_ASSOC)) { michael@0: SCTP_INP_RLOCK(inp); michael@0: LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) { michael@0: SCTP_TCB_LOCK(stcb); michael@0: if (info->snd_sid < stcb->asoc.streamoutcnt) { michael@0: stcb->asoc.def_send.sinfo_stream = info->snd_sid; michael@0: policy = PR_SCTP_POLICY(stcb->asoc.def_send.sinfo_flags); michael@0: stcb->asoc.def_send.sinfo_flags = info->snd_flags; michael@0: stcb->asoc.def_send.sinfo_flags |= policy; michael@0: stcb->asoc.def_send.sinfo_ppid = info->snd_ppid; michael@0: stcb->asoc.def_send.sinfo_context = info->snd_context; michael@0: } michael@0: SCTP_TCB_UNLOCK(stcb); michael@0: } michael@0: SCTP_INP_RUNLOCK(inp); michael@0: } michael@0: } michael@0: break; michael@0: } michael@0: case SCTP_DEFAULT_PRINFO: michael@0: { michael@0: struct sctp_default_prinfo *info; michael@0: michael@0: SCTP_CHECK_AND_CAST(info, optval, struct sctp_default_prinfo, optsize); michael@0: SCTP_FIND_STCB(inp, stcb, info->pr_assoc_id); michael@0: michael@0: if (PR_SCTP_INVALID_POLICY(info->pr_policy)) { michael@0: SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL); michael@0: error = EINVAL; michael@0: break; michael@0: } michael@0: if (stcb) { michael@0: stcb->asoc.def_send.sinfo_flags &= 0xfff0; michael@0: stcb->asoc.def_send.sinfo_flags |= info->pr_policy; michael@0: stcb->asoc.def_send.sinfo_timetolive = info->pr_value; michael@0: SCTP_TCB_UNLOCK(stcb); michael@0: } else { michael@0: if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) || michael@0: (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) || michael@0: (info->pr_assoc_id == SCTP_FUTURE_ASSOC) || michael@0: (info->pr_assoc_id == SCTP_ALL_ASSOC)) { michael@0: SCTP_INP_WLOCK(inp); michael@0: inp->def_send.sinfo_flags &= 0xfff0; michael@0: inp->def_send.sinfo_flags |= info->pr_policy; michael@0: inp->def_send.sinfo_timetolive = info->pr_value; michael@0: SCTP_INP_WUNLOCK(inp); michael@0: } michael@0: if ((info->pr_assoc_id == SCTP_CURRENT_ASSOC) || michael@0: (info->pr_assoc_id == SCTP_ALL_ASSOC)) { michael@0: SCTP_INP_RLOCK(inp); michael@0: LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) { michael@0: SCTP_TCB_LOCK(stcb); michael@0: stcb->asoc.def_send.sinfo_flags &= 0xfff0; michael@0: stcb->asoc.def_send.sinfo_flags |= info->pr_policy; michael@0: stcb->asoc.def_send.sinfo_timetolive = info->pr_value; michael@0: SCTP_TCB_UNLOCK(stcb); michael@0: } michael@0: SCTP_INP_RUNLOCK(inp); michael@0: } michael@0: } michael@0: break; michael@0: } michael@0: case SCTP_PEER_ADDR_THLDS: michael@0: /* Applies to the specific association */ michael@0: { michael@0: struct sctp_paddrthlds *thlds; michael@0: struct sctp_nets *net; michael@0: michael@0: SCTP_CHECK_AND_CAST(thlds, optval, struct sctp_paddrthlds, optsize); michael@0: SCTP_FIND_STCB(inp, stcb, thlds->spt_assoc_id); michael@0: net = NULL; michael@0: if (stcb) { michael@0: net = sctp_findnet(stcb, (struct sockaddr *)&thlds->spt_assoc_id); michael@0: } else { michael@0: /* We increment here since sctp_findassociation_ep_addr() wil michael@0: * do a decrement if it finds the stcb as long as the locked michael@0: * tcb (last argument) is NOT a TCB.. aka NULL. michael@0: */ michael@0: SCTP_INP_INCR_REF(inp); michael@0: stcb = sctp_findassociation_ep_addr(&inp, michael@0: (struct sockaddr *)&thlds->spt_assoc_id, michael@0: &net, NULL, NULL); michael@0: if (stcb == NULL) { michael@0: SCTP_INP_DECR_REF(inp); michael@0: } michael@0: } michael@0: if (stcb && (net == NULL)) { michael@0: struct sockaddr *sa; michael@0: michael@0: sa = (struct sockaddr *)&thlds->spt_assoc_id; michael@0: #ifdef INET michael@0: if (sa->sa_family == AF_INET) { michael@0: michael@0: struct sockaddr_in *sin; michael@0: sin = (struct sockaddr_in *)sa; michael@0: if (sin->sin_addr.s_addr) { michael@0: SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL); michael@0: SCTP_TCB_UNLOCK(stcb); michael@0: error = EINVAL; michael@0: break; michael@0: } michael@0: } else michael@0: #endif michael@0: #ifdef INET6 michael@0: if (sa->sa_family == AF_INET6) { michael@0: struct sockaddr_in6 *sin6; michael@0: michael@0: sin6 = (struct sockaddr_in6 *)sa; michael@0: if (!IN6_IS_ADDR_UNSPECIFIED(&sin6->sin6_addr)) { michael@0: SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL); michael@0: SCTP_TCB_UNLOCK(stcb); michael@0: error = EINVAL; michael@0: break; michael@0: } michael@0: } else michael@0: #endif michael@0: #if defined(__Userspace__) michael@0: if (sa->sa_family == AF_CONN) { michael@0: struct sockaddr_conn *sconn; michael@0: michael@0: sconn = (struct sockaddr_conn *)sa; michael@0: if (sconn->sconn_addr != NULL) { michael@0: SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL); michael@0: SCTP_TCB_UNLOCK(stcb); michael@0: error = EINVAL; michael@0: break; michael@0: } michael@0: } else michael@0: #endif michael@0: { michael@0: error = EAFNOSUPPORT; michael@0: SCTP_TCB_UNLOCK(stcb); michael@0: SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error); michael@0: break; michael@0: } michael@0: } michael@0: if (stcb) { michael@0: if (net) { michael@0: if (net->dest_state & SCTP_ADDR_PF) { michael@0: if ((net->failure_threshold > thlds->spt_pathmaxrxt) || michael@0: (net->failure_threshold <= thlds->spt_pathpfthld)) { michael@0: net->dest_state &= ~SCTP_ADDR_PF; michael@0: } michael@0: } else { michael@0: if ((net->failure_threshold > thlds->spt_pathpfthld) && michael@0: (net->failure_threshold <= thlds->spt_pathmaxrxt)) { michael@0: net->dest_state |= SCTP_ADDR_PF; michael@0: sctp_send_hb(stcb, net, SCTP_SO_LOCKED); michael@0: sctp_timer_stop(SCTP_TIMER_TYPE_HEARTBEAT, stcb->sctp_ep, stcb, net, SCTP_FROM_SCTP_TIMER + SCTP_LOC_3); michael@0: sctp_timer_start(SCTP_TIMER_TYPE_HEARTBEAT, stcb->sctp_ep, stcb, net); michael@0: } michael@0: } michael@0: if (net->dest_state & SCTP_ADDR_REACHABLE) { michael@0: if (net->failure_threshold > thlds->spt_pathmaxrxt) { michael@0: net->dest_state &= ~SCTP_ADDR_REACHABLE; michael@0: sctp_ulp_notify(SCTP_NOTIFY_INTERFACE_DOWN, stcb, 0, net, SCTP_SO_LOCKED); michael@0: } michael@0: } else { michael@0: if (net->failure_threshold <= thlds->spt_pathmaxrxt) { michael@0: net->dest_state |= SCTP_ADDR_REACHABLE; michael@0: sctp_ulp_notify(SCTP_NOTIFY_INTERFACE_UP, stcb, 0, net, SCTP_SO_LOCKED); michael@0: } michael@0: } michael@0: net->failure_threshold = thlds->spt_pathmaxrxt; michael@0: net->pf_threshold = thlds->spt_pathpfthld; michael@0: } else { michael@0: TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) { michael@0: if (net->dest_state & SCTP_ADDR_PF) { michael@0: if ((net->failure_threshold > thlds->spt_pathmaxrxt) || michael@0: (net->failure_threshold <= thlds->spt_pathpfthld)) { michael@0: net->dest_state &= ~SCTP_ADDR_PF; michael@0: } michael@0: } else { michael@0: if ((net->failure_threshold > thlds->spt_pathpfthld) && michael@0: (net->failure_threshold <= thlds->spt_pathmaxrxt)) { michael@0: net->dest_state |= SCTP_ADDR_PF; michael@0: sctp_send_hb(stcb, net, SCTP_SO_LOCKED); michael@0: sctp_timer_stop(SCTP_TIMER_TYPE_HEARTBEAT, stcb->sctp_ep, stcb, net, SCTP_FROM_SCTP_TIMER + SCTP_LOC_3); michael@0: sctp_timer_start(SCTP_TIMER_TYPE_HEARTBEAT, stcb->sctp_ep, stcb, net); michael@0: } michael@0: } michael@0: if (net->dest_state & SCTP_ADDR_REACHABLE) { michael@0: if (net->failure_threshold > thlds->spt_pathmaxrxt) { michael@0: net->dest_state &= ~SCTP_ADDR_REACHABLE; michael@0: sctp_ulp_notify(SCTP_NOTIFY_INTERFACE_DOWN, stcb, 0, net, SCTP_SO_LOCKED); michael@0: } michael@0: } else { michael@0: if (net->failure_threshold <= thlds->spt_pathmaxrxt) { michael@0: net->dest_state |= SCTP_ADDR_REACHABLE; michael@0: sctp_ulp_notify(SCTP_NOTIFY_INTERFACE_UP, stcb, 0, net, SCTP_SO_LOCKED); michael@0: } michael@0: } michael@0: net->failure_threshold = thlds->spt_pathmaxrxt; michael@0: net->pf_threshold = thlds->spt_pathpfthld; michael@0: } michael@0: stcb->asoc.def_net_failure = thlds->spt_pathmaxrxt; michael@0: stcb->asoc.def_net_pf_threshold = thlds->spt_pathpfthld; michael@0: } michael@0: } else { michael@0: if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) || michael@0: (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) || michael@0: (thlds->spt_assoc_id == SCTP_FUTURE_ASSOC)) { michael@0: SCTP_INP_WLOCK(inp); michael@0: inp->sctp_ep.def_net_failure = thlds->spt_pathmaxrxt; michael@0: inp->sctp_ep.def_net_pf_threshold = thlds->spt_pathpfthld; michael@0: SCTP_INP_WUNLOCK(inp); michael@0: } else { michael@0: SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL); michael@0: error = EINVAL; michael@0: } michael@0: } michael@0: break; michael@0: } michael@0: case SCTP_REMOTE_UDP_ENCAPS_PORT: michael@0: { michael@0: struct sctp_udpencaps *encaps; michael@0: struct sctp_nets *net; michael@0: michael@0: SCTP_CHECK_AND_CAST(encaps, optval, struct sctp_udpencaps, optsize); michael@0: SCTP_FIND_STCB(inp, stcb, encaps->sue_assoc_id); michael@0: if (stcb) { michael@0: net = sctp_findnet(stcb, (struct sockaddr *)&encaps->sue_address); michael@0: } else { michael@0: /* We increment here since sctp_findassociation_ep_addr() wil michael@0: * do a decrement if it finds the stcb as long as the locked michael@0: * tcb (last argument) is NOT a TCB.. aka NULL. michael@0: */ michael@0: net = NULL; michael@0: SCTP_INP_INCR_REF(inp); michael@0: stcb = sctp_findassociation_ep_addr(&inp, (struct sockaddr *)&encaps->sue_address, &net, NULL, NULL); michael@0: if (stcb == NULL) { michael@0: SCTP_INP_DECR_REF(inp); michael@0: } michael@0: } michael@0: if (stcb && (net == NULL)) { michael@0: struct sockaddr *sa; michael@0: michael@0: sa = (struct sockaddr *)&encaps->sue_address; michael@0: #ifdef INET michael@0: if (sa->sa_family == AF_INET) { michael@0: michael@0: struct sockaddr_in *sin; michael@0: sin = (struct sockaddr_in *)sa; michael@0: if (sin->sin_addr.s_addr) { michael@0: SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL); michael@0: SCTP_TCB_UNLOCK(stcb); michael@0: error = EINVAL; michael@0: break; michael@0: } michael@0: } else michael@0: #endif michael@0: #ifdef INET6 michael@0: if (sa->sa_family == AF_INET6) { michael@0: struct sockaddr_in6 *sin6; michael@0: michael@0: sin6 = (struct sockaddr_in6 *)sa; michael@0: if (!IN6_IS_ADDR_UNSPECIFIED(&sin6->sin6_addr)) { michael@0: SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL); michael@0: SCTP_TCB_UNLOCK(stcb); michael@0: error = EINVAL; michael@0: break; michael@0: } michael@0: } else michael@0: #endif michael@0: #if defined(__Userspace__) michael@0: if (sa->sa_family == AF_CONN) { michael@0: struct sockaddr_conn *sconn; michael@0: michael@0: sconn = (struct sockaddr_conn *)sa; michael@0: if (sconn->sconn_addr != NULL) { michael@0: SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL); michael@0: SCTP_TCB_UNLOCK(stcb); michael@0: error = EINVAL; michael@0: break; michael@0: } michael@0: } else michael@0: #endif michael@0: { michael@0: error = EAFNOSUPPORT; michael@0: SCTP_TCB_UNLOCK(stcb); michael@0: SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error); michael@0: break; michael@0: } michael@0: } michael@0: michael@0: if (stcb) { michael@0: if (net) { michael@0: net->port = encaps->sue_port; michael@0: } else { michael@0: stcb->asoc.port = encaps->sue_port; michael@0: } michael@0: SCTP_TCB_UNLOCK(stcb); michael@0: } else { michael@0: if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) || michael@0: (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) || michael@0: (encaps->sue_assoc_id == SCTP_FUTURE_ASSOC)) { michael@0: SCTP_INP_WLOCK(inp); michael@0: inp->sctp_ep.port = encaps->sue_port; michael@0: SCTP_INP_WUNLOCK(inp); michael@0: } else { michael@0: SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL); michael@0: error = EINVAL; michael@0: } michael@0: } michael@0: break; michael@0: } michael@0: default: michael@0: SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOPROTOOPT); michael@0: error = ENOPROTOOPT; michael@0: break; michael@0: } /* end switch (opt) */ michael@0: return (error); michael@0: } michael@0: michael@0: #if defined(__FreeBSD__) || defined(__APPLE__) || defined(__Windows__) michael@0: int michael@0: sctp_ctloutput(struct socket *so, struct sockopt *sopt) michael@0: { michael@0: void *optval = NULL; michael@0: size_t optsize = 0; michael@0: void *p; michael@0: int error = 0; michael@0: michael@0: if (sopt->sopt_level != IPPROTO_SCTP) { michael@0: /* wrong proto level... send back up to IP */ michael@0: #ifdef INET6 michael@0: if (INP_CHECK_SOCKAF(so, AF_INET6)) michael@0: error = ip6_ctloutput(so, sopt); michael@0: #endif /* INET6 */ michael@0: #if defined(INET) && defined(INET6) michael@0: else michael@0: #endif michael@0: #ifdef INET michael@0: error = ip_ctloutput(so, sopt); michael@0: #endif michael@0: return (error); michael@0: } michael@0: optsize = sopt->sopt_valsize; michael@0: if (optsize) { michael@0: SCTP_MALLOC(optval, void *, optsize, SCTP_M_SOCKOPT); michael@0: if (optval == NULL) { michael@0: SCTP_LTRACE_ERR_RET(so->so_pcb, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOBUFS); michael@0: return (ENOBUFS); michael@0: } michael@0: error = sooptcopyin(sopt, optval, optsize, optsize); michael@0: if (error) { michael@0: SCTP_FREE(optval, SCTP_M_SOCKOPT); michael@0: goto out; michael@0: } michael@0: } michael@0: #if (defined(__FreeBSD__) && __FreeBSD_version >= 500000) || defined(__Windows__) michael@0: p = (void *)sopt->sopt_td; michael@0: #else michael@0: p = (void *)sopt->sopt_p; michael@0: #endif michael@0: if (sopt->sopt_dir == SOPT_SET) { michael@0: error = sctp_setopt(so, sopt->sopt_name, optval, optsize, p); michael@0: } else if (sopt->sopt_dir == SOPT_GET) { michael@0: error = sctp_getopt(so, sopt->sopt_name, optval, &optsize, p); michael@0: } else { michael@0: SCTP_LTRACE_ERR_RET(so->so_pcb, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL); michael@0: error = EINVAL; michael@0: } michael@0: if ((error == 0) && (optval != NULL)) { michael@0: error = sooptcopyout(sopt, optval, optsize); michael@0: SCTP_FREE(optval, SCTP_M_SOCKOPT); michael@0: } else if (optval != NULL) { michael@0: SCTP_FREE(optval, SCTP_M_SOCKOPT); michael@0: } michael@0: out: michael@0: return (error); michael@0: } michael@0: #endif michael@0: michael@0: #ifdef INET michael@0: #if defined(__FreeBSD__) && __FreeBSD_version >= 500000 michael@0: static int michael@0: sctp_connect(struct socket *so, struct sockaddr *addr, struct thread *p) michael@0: { michael@0: #else michael@0: #if defined(__FreeBSD__) || defined(__APPLE__) michael@0: static int michael@0: sctp_connect(struct socket *so, struct sockaddr *addr, struct proc *p) michael@0: { michael@0: #elif defined(__Panda__) || defined(__Userspace__) michael@0: int michael@0: sctp_connect(struct socket *so, struct sockaddr *addr) michael@0: { michael@0: void *p = NULL; michael@0: #elif defined(__Windows__) michael@0: static int michael@0: sctp_connect(struct socket *so, struct sockaddr *addr, PKTHREAD p) michael@0: { michael@0: #else michael@0: static int michael@0: sctp_connect(struct socket *so, struct mbuf *nam, struct proc *p) michael@0: { michael@0: struct sockaddr *addr = mtod(nam, struct sockaddr *); michael@0: michael@0: #endif michael@0: #endif michael@0: #ifdef SCTP_MVRF michael@0: int i, fnd = 0; michael@0: #endif michael@0: int error = 0; michael@0: int create_lock_on = 0; michael@0: uint32_t vrf_id; michael@0: struct sctp_inpcb *inp; michael@0: struct sctp_tcb *stcb = NULL; michael@0: michael@0: inp = (struct sctp_inpcb *)so->so_pcb; michael@0: if (inp == NULL) { michael@0: /* I made the same as TCP since we are not setup? */ michael@0: SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL); michael@0: return (ECONNRESET); michael@0: } michael@0: if (addr == NULL) { michael@0: SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL); michael@0: return EINVAL; michael@0: } michael@0: michael@0: #if defined(__Userspace__) michael@0: /* TODO __Userspace__ falls into this code for IPv6 stuff at the moment... */ michael@0: #endif michael@0: #if !defined(__Windows__) && !defined(__Userspace_os_Linux) && !defined(__Userspace_os_Windows) michael@0: switch (addr->sa_family) { michael@0: #ifdef INET6 michael@0: case AF_INET6: michael@0: { michael@0: #if defined(__FreeBSD__) && __FreeBSD_version >= 800000 michael@0: struct sockaddr_in6 *sin6p; michael@0: michael@0: #endif michael@0: if (addr->sa_len != sizeof(struct sockaddr_in6)) { michael@0: SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL); michael@0: return (EINVAL); michael@0: } michael@0: #if defined(__FreeBSD__) && __FreeBSD_version >= 800000 michael@0: sin6p = (struct sockaddr_in6 *)addr; michael@0: if (p != NULL && (error = prison_remote_ip6(p->td_ucred, &sin6p->sin6_addr)) != 0) { michael@0: SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error); michael@0: return (error); michael@0: } michael@0: #endif michael@0: break; michael@0: } michael@0: #endif michael@0: #ifdef INET michael@0: case AF_INET: michael@0: { michael@0: #if defined(__FreeBSD__) && __FreeBSD_version >= 800000 michael@0: struct sockaddr_in *sinp; michael@0: michael@0: #endif michael@0: #if !defined(__Userspace_os_Windows) michael@0: if (addr->sa_len != sizeof(struct sockaddr_in)) { michael@0: SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL); michael@0: return (EINVAL); michael@0: } michael@0: #endif michael@0: #if defined(__FreeBSD__) && __FreeBSD_version >= 800000 michael@0: sinp = (struct sockaddr_in *)addr; michael@0: if (p != NULL && (error = prison_remote_ip4(p->td_ucred, &sinp->sin_addr)) != 0) { michael@0: SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error); michael@0: return (error); michael@0: } michael@0: #endif michael@0: break; michael@0: } michael@0: #endif michael@0: default: michael@0: SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EAFNOSUPPORT); michael@0: return (EAFNOSUPPORT); michael@0: } michael@0: #endif michael@0: SCTP_INP_INCR_REF(inp); michael@0: SCTP_ASOC_CREATE_LOCK(inp); michael@0: create_lock_on = 1; michael@0: michael@0: michael@0: if ((inp->sctp_flags & SCTP_PCB_FLAGS_SOCKET_ALLGONE) || michael@0: (inp->sctp_flags & SCTP_PCB_FLAGS_SOCKET_GONE)) { michael@0: /* Should I really unlock ? */ michael@0: SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EFAULT); michael@0: error = EFAULT; michael@0: goto out_now; michael@0: } michael@0: #ifdef INET6 michael@0: if (((inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) == 0) && michael@0: (addr->sa_family == AF_INET6)) { michael@0: SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL); michael@0: error = EINVAL; michael@0: goto out_now; michael@0: } michael@0: #endif michael@0: #if defined(__Userspace__) michael@0: if ((inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_CONN) && michael@0: (addr->sa_family != AF_CONN)) { michael@0: SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL); michael@0: error = EINVAL; michael@0: goto out_now; michael@0: } michael@0: #endif michael@0: if ((inp->sctp_flags & SCTP_PCB_FLAGS_UNBOUND) == michael@0: SCTP_PCB_FLAGS_UNBOUND) { michael@0: /* Bind a ephemeral port */ michael@0: error = sctp_inpcb_bind(so, NULL, NULL, p); michael@0: if (error) { michael@0: goto out_now; michael@0: } michael@0: } michael@0: /* Now do we connect? */ michael@0: if ((inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) && michael@0: (sctp_is_feature_off(inp, SCTP_PCB_FLAGS_PORTREUSE))) { michael@0: SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL); michael@0: error = EINVAL; michael@0: goto out_now; michael@0: } michael@0: if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) && michael@0: (inp->sctp_flags & SCTP_PCB_FLAGS_CONNECTED)) { michael@0: /* We are already connected AND the TCP model */ michael@0: SCTP_LTRACE_ERR_RET(inp, stcb, NULL, SCTP_FROM_SCTP_USRREQ, EADDRINUSE); michael@0: error = EADDRINUSE; michael@0: goto out_now; michael@0: } michael@0: if (inp->sctp_flags & SCTP_PCB_FLAGS_CONNECTED) { michael@0: SCTP_INP_RLOCK(inp); michael@0: stcb = LIST_FIRST(&inp->sctp_asoc_list); michael@0: SCTP_INP_RUNLOCK(inp); michael@0: } else { michael@0: /* We increment here since sctp_findassociation_ep_addr() will michael@0: * do a decrement if it finds the stcb as long as the locked michael@0: * tcb (last argument) is NOT a TCB.. aka NULL. michael@0: */ michael@0: SCTP_INP_INCR_REF(inp); michael@0: stcb = sctp_findassociation_ep_addr(&inp, addr, NULL, NULL, NULL); michael@0: if (stcb == NULL) { michael@0: SCTP_INP_DECR_REF(inp); michael@0: } else { michael@0: SCTP_TCB_UNLOCK(stcb); michael@0: } michael@0: } michael@0: if (stcb != NULL) { michael@0: /* Already have or am bring up an association */ michael@0: SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EALREADY); michael@0: error = EALREADY; michael@0: goto out_now; michael@0: } michael@0: michael@0: vrf_id = inp->def_vrf_id; michael@0: #ifdef SCTP_MVRF michael@0: for (i = 0; i < inp->num_vrfs; i++) { michael@0: if (vrf_id == inp->m_vrf_ids[i]) { michael@0: fnd = 1; michael@0: break; michael@0: } michael@0: } michael@0: if (!fnd) { michael@0: SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL); michael@0: error = EINVAL; michael@0: goto out_now; michael@0: } michael@0: #endif michael@0: /* We are GOOD to go */ michael@0: stcb = sctp_aloc_assoc(inp, addr, &error, 0, vrf_id, p); michael@0: if (stcb == NULL) { michael@0: /* Gak! no memory */ michael@0: goto out_now; michael@0: } michael@0: if (stcb->sctp_ep->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) { michael@0: stcb->sctp_ep->sctp_flags |= SCTP_PCB_FLAGS_CONNECTED; michael@0: /* Set the connected flag so we can queue data */ michael@0: soisconnecting(so); michael@0: } michael@0: SCTP_SET_STATE(&stcb->asoc, SCTP_STATE_COOKIE_WAIT); michael@0: (void)SCTP_GETTIME_TIMEVAL(&stcb->asoc.time_entered); michael@0: michael@0: /* initialize authentication parameters for the assoc */ michael@0: sctp_initialize_auth_params(inp, stcb); michael@0: michael@0: sctp_send_initiate(inp, stcb, SCTP_SO_LOCKED); michael@0: SCTP_TCB_UNLOCK(stcb); michael@0: out_now: michael@0: if (create_lock_on) { michael@0: SCTP_ASOC_CREATE_UNLOCK(inp); michael@0: } michael@0: michael@0: SCTP_INP_DECR_REF(inp); michael@0: return (error); michael@0: } michael@0: #endif michael@0: michael@0: #if defined(__Userspace__) michael@0: int michael@0: sctpconn_connect(struct socket *so, struct sockaddr *addr) michael@0: { michael@0: #ifdef SCTP_MVRF michael@0: int i, fnd = 0; michael@0: #endif michael@0: void *p = NULL; michael@0: int error = 0; michael@0: int create_lock_on = 0; michael@0: uint32_t vrf_id; michael@0: struct sctp_inpcb *inp; michael@0: struct sctp_tcb *stcb = NULL; michael@0: michael@0: inp = (struct sctp_inpcb *)so->so_pcb; michael@0: if (inp == NULL) { michael@0: /* I made the same as TCP since we are not setup? */ michael@0: SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL); michael@0: return (ECONNRESET); michael@0: } michael@0: if (addr == NULL) { michael@0: SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL); michael@0: return EINVAL; michael@0: } michael@0: switch (addr->sa_family) { michael@0: #ifdef INET michael@0: case AF_INET: michael@0: #ifdef HAVE_SA_LEN michael@0: if (addr->sa_len != sizeof(struct sockaddr_in)) { michael@0: SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL); michael@0: return (EINVAL); michael@0: } michael@0: #endif michael@0: break; michael@0: #endif michael@0: #ifdef INET6 michael@0: case AF_INET6: michael@0: #ifdef HAVE_SA_LEN michael@0: if (addr->sa_len != sizeof(struct sockaddr_in6)) { michael@0: SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL); michael@0: return (EINVAL); michael@0: } michael@0: #endif michael@0: break; michael@0: #endif michael@0: case AF_CONN: michael@0: #ifdef HAVE_SA_LEN michael@0: if (addr->sa_len != sizeof(struct sockaddr_conn)) { michael@0: SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL); michael@0: return (EINVAL); michael@0: } michael@0: #endif michael@0: break; michael@0: default: michael@0: SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EAFNOSUPPORT); michael@0: return (EAFNOSUPPORT); michael@0: } michael@0: SCTP_INP_INCR_REF(inp); michael@0: SCTP_ASOC_CREATE_LOCK(inp); michael@0: create_lock_on = 1; michael@0: michael@0: michael@0: if ((inp->sctp_flags & SCTP_PCB_FLAGS_SOCKET_ALLGONE) || michael@0: (inp->sctp_flags & SCTP_PCB_FLAGS_SOCKET_GONE)) { michael@0: /* Should I really unlock ? */ michael@0: SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EFAULT); michael@0: error = EFAULT; michael@0: goto out_now; michael@0: } michael@0: #ifdef INET6 michael@0: if (((inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) == 0) && michael@0: (addr->sa_family == AF_INET6)) { michael@0: SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL); michael@0: error = EINVAL; michael@0: goto out_now; michael@0: } michael@0: #endif michael@0: if ((inp->sctp_flags & SCTP_PCB_FLAGS_UNBOUND) == SCTP_PCB_FLAGS_UNBOUND) { michael@0: /* Bind a ephemeral port */ michael@0: error = sctp_inpcb_bind(so, NULL, NULL, p); michael@0: if (error) { michael@0: goto out_now; michael@0: } michael@0: } michael@0: /* Now do we connect? */ michael@0: if ((inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) && michael@0: (sctp_is_feature_off(inp, SCTP_PCB_FLAGS_PORTREUSE))) { michael@0: SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL); michael@0: error = EINVAL; michael@0: goto out_now; michael@0: } michael@0: if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) && michael@0: (inp->sctp_flags & SCTP_PCB_FLAGS_CONNECTED)) { michael@0: /* We are already connected AND the TCP model */ michael@0: SCTP_LTRACE_ERR_RET(inp, stcb, NULL, SCTP_FROM_SCTP_USRREQ, EADDRINUSE); michael@0: error = EADDRINUSE; michael@0: goto out_now; michael@0: } michael@0: if (inp->sctp_flags & SCTP_PCB_FLAGS_CONNECTED) { michael@0: SCTP_INP_RLOCK(inp); michael@0: stcb = LIST_FIRST(&inp->sctp_asoc_list); michael@0: SCTP_INP_RUNLOCK(inp); michael@0: } else { michael@0: /* We increment here since sctp_findassociation_ep_addr() will michael@0: * do a decrement if it finds the stcb as long as the locked michael@0: * tcb (last argument) is NOT a TCB.. aka NULL. michael@0: */ michael@0: SCTP_INP_INCR_REF(inp); michael@0: stcb = sctp_findassociation_ep_addr(&inp, addr, NULL, NULL, NULL); michael@0: if (stcb == NULL) { michael@0: SCTP_INP_DECR_REF(inp); michael@0: } else { michael@0: SCTP_TCB_UNLOCK(stcb); michael@0: } michael@0: } michael@0: if (stcb != NULL) { michael@0: /* Already have or am bring up an association */ michael@0: SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EALREADY); michael@0: error = EALREADY; michael@0: goto out_now; michael@0: } michael@0: michael@0: vrf_id = inp->def_vrf_id; michael@0: #ifdef SCTP_MVRF michael@0: for (i = 0; i < inp->num_vrfs; i++) { michael@0: if (vrf_id == inp->m_vrf_ids[i]) { michael@0: fnd = 1; michael@0: break; michael@0: } michael@0: } michael@0: if (!fnd) { michael@0: SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL); michael@0: error = EINVAL; michael@0: goto out_now; michael@0: } michael@0: #endif michael@0: /* We are GOOD to go */ michael@0: stcb = sctp_aloc_assoc(inp, addr, &error, 0, vrf_id, p); michael@0: if (stcb == NULL) { michael@0: /* Gak! no memory */ michael@0: goto out_now; michael@0: } michael@0: if (stcb->sctp_ep->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) { michael@0: stcb->sctp_ep->sctp_flags |= SCTP_PCB_FLAGS_CONNECTED; michael@0: /* Set the connected flag so we can queue data */ michael@0: soisconnecting(so); michael@0: } michael@0: SCTP_SET_STATE(&stcb->asoc, SCTP_STATE_COOKIE_WAIT); michael@0: (void)SCTP_GETTIME_TIMEVAL(&stcb->asoc.time_entered); michael@0: michael@0: /* initialize authentication parameters for the assoc */ michael@0: sctp_initialize_auth_params(inp, stcb); michael@0: michael@0: sctp_send_initiate(inp, stcb, SCTP_SO_LOCKED); michael@0: SCTP_TCB_UNLOCK(stcb); michael@0: out_now: michael@0: if (create_lock_on) { michael@0: SCTP_ASOC_CREATE_UNLOCK(inp); michael@0: } michael@0: michael@0: SCTP_INP_DECR_REF(inp); michael@0: return (error); michael@0: } michael@0: #endif michael@0: int michael@0: #if defined(__FreeBSD__) && __FreeBSD_version >= 500000 michael@0: #if __FreeBSD_version >= 700000 michael@0: sctp_listen(struct socket *so, int backlog, struct thread *p) michael@0: #else michael@0: sctp_listen(struct socket *so, struct thread *p) michael@0: #endif michael@0: #elif defined(__Windows__) michael@0: sctp_listen(struct socket *so, int backlog, PKTHREAD p) michael@0: #elif defined(__Userspace__) michael@0: sctp_listen(struct socket *so, int backlog, struct proc *p) michael@0: #else michael@0: sctp_listen(struct socket *so, struct proc *p) michael@0: #endif michael@0: { michael@0: /* michael@0: * Note this module depends on the protocol processing being called michael@0: * AFTER any socket level flags and backlog are applied to the michael@0: * socket. The traditional way that the socket flags are applied is michael@0: * AFTER protocol processing. We have made a change to the michael@0: * sys/kern/uipc_socket.c module to reverse this but this MUST be in michael@0: * place if the socket API for SCTP is to work properly. michael@0: */ michael@0: michael@0: int error = 0; michael@0: struct sctp_inpcb *inp; michael@0: michael@0: inp = (struct sctp_inpcb *)so->so_pcb; michael@0: if (inp == NULL) { michael@0: /* I made the same as TCP since we are not setup? */ michael@0: SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL); michael@0: return (ECONNRESET); michael@0: } michael@0: if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_PORTREUSE)) { michael@0: /* See if we have a listener */ michael@0: struct sctp_inpcb *tinp; michael@0: union sctp_sockstore store, *sp; michael@0: michael@0: sp = &store; michael@0: if ((inp->sctp_flags & SCTP_PCB_FLAGS_BOUNDALL) == 0) { michael@0: /* not bound all */ michael@0: struct sctp_laddr *laddr; michael@0: michael@0: LIST_FOREACH(laddr, &inp->sctp_addr_list, sctp_nxt_addr) { michael@0: memcpy(&store, &laddr->ifa->address, sizeof(store)); michael@0: switch (sp->sa.sa_family) { michael@0: #ifdef INET michael@0: case AF_INET: michael@0: sp->sin.sin_port = inp->sctp_lport; michael@0: break; michael@0: #endif michael@0: #ifdef INET6 michael@0: case AF_INET6: michael@0: sp->sin6.sin6_port = inp->sctp_lport; michael@0: break; michael@0: #endif michael@0: #if defined(__Userspace__) michael@0: case AF_CONN: michael@0: sp->sconn.sconn_port = inp->sctp_lport; michael@0: break; michael@0: #endif michael@0: default: michael@0: break; michael@0: } michael@0: tinp = sctp_pcb_findep(&sp->sa, 0, 0, inp->def_vrf_id); michael@0: if (tinp && (tinp != inp) && michael@0: ((tinp->sctp_flags & SCTP_PCB_FLAGS_SOCKET_ALLGONE) == 0) && michael@0: ((tinp->sctp_flags & SCTP_PCB_FLAGS_SOCKET_GONE) == 0) && michael@0: (tinp->sctp_socket->so_qlimit)) { michael@0: /* we have a listener already and its not this inp. */ michael@0: SCTP_INP_DECR_REF(tinp); michael@0: return (EADDRINUSE); michael@0: } else if (tinp) { michael@0: SCTP_INP_DECR_REF(tinp); michael@0: } michael@0: } michael@0: } else { michael@0: /* Setup a local addr bound all */ michael@0: memset(&store, 0, sizeof(store)); michael@0: switch (sp->sa.sa_family) { michael@0: #ifdef INET michael@0: case AF_INET: michael@0: store.sin.sin_port = inp->sctp_lport; michael@0: break; michael@0: #endif michael@0: #ifdef INET6 michael@0: case AF_INET6: michael@0: sp->sin6.sin6_port = inp->sctp_lport; michael@0: break; michael@0: #endif michael@0: #if defined(__Userspace__) michael@0: case AF_CONN: michael@0: sp->sconn.sconn_port = inp->sctp_lport; michael@0: break; michael@0: #endif michael@0: default: michael@0: break; michael@0: } michael@0: #ifdef INET6 michael@0: if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) { michael@0: store.sa.sa_family = AF_INET6; michael@0: #ifdef HAVE_SA_LEN michael@0: store.sa.sa_len = sizeof(struct sockaddr_in6); michael@0: #endif michael@0: } michael@0: #endif michael@0: #ifdef INET michael@0: if ((inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) == 0) { michael@0: store.sa.sa_family = AF_INET; michael@0: #ifdef HAVE_SA_LEN michael@0: store.sa.sa_len = sizeof(struct sockaddr_in); michael@0: #endif michael@0: } michael@0: #endif michael@0: tinp = sctp_pcb_findep(&sp->sa, 0, 0, inp->def_vrf_id); michael@0: if (tinp && (tinp != inp) && michael@0: ((tinp->sctp_flags & SCTP_PCB_FLAGS_SOCKET_ALLGONE) == 0) && michael@0: ((tinp->sctp_flags & SCTP_PCB_FLAGS_SOCKET_GONE) == 0) && michael@0: (tinp->sctp_socket->so_qlimit)) { michael@0: /* we have a listener already and its not this inp. */ michael@0: SCTP_INP_DECR_REF(tinp); michael@0: return (EADDRINUSE); michael@0: } else if (tinp) { michael@0: SCTP_INP_DECR_REF(inp); michael@0: } michael@0: } michael@0: } michael@0: SCTP_INP_RLOCK(inp); michael@0: #ifdef SCTP_LOCK_LOGGING michael@0: if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_LOCK_LOGGING_ENABLE) { michael@0: sctp_log_lock(inp, (struct sctp_tcb *)NULL, SCTP_LOG_LOCK_SOCK); michael@0: } michael@0: #endif michael@0: SOCK_LOCK(so); michael@0: #if (defined(__FreeBSD__) && __FreeBSD_version > 500000) || defined(__Userspace__) michael@0: error = solisten_proto_check(so); michael@0: if (error) { michael@0: SOCK_UNLOCK(so); michael@0: SCTP_INP_RUNLOCK(inp); michael@0: return (error); michael@0: } michael@0: #endif michael@0: if ((sctp_is_feature_on(inp, SCTP_PCB_FLAGS_PORTREUSE)) && michael@0: (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL)) { michael@0: /* The unlucky case michael@0: * - We are in the tcp pool with this guy. michael@0: * - Someone else is in the main inp slot. michael@0: * - We must move this guy (the listener) to the main slot michael@0: * - We must then move the guy that was listener to the TCP Pool. michael@0: */ michael@0: if (sctp_swap_inpcb_for_listen(inp)) { michael@0: goto in_use; michael@0: } michael@0: } michael@0: michael@0: if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) && michael@0: (inp->sctp_flags & SCTP_PCB_FLAGS_CONNECTED)) { michael@0: /* We are already connected AND the TCP model */ michael@0: in_use: michael@0: SCTP_INP_RUNLOCK(inp); michael@0: SOCK_UNLOCK(so); michael@0: SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EADDRINUSE); michael@0: return (EADDRINUSE); michael@0: } michael@0: SCTP_INP_RUNLOCK(inp); michael@0: if (inp->sctp_flags & SCTP_PCB_FLAGS_UNBOUND) { michael@0: /* We must do a bind. */ michael@0: SOCK_UNLOCK(so); michael@0: if ((error = sctp_inpcb_bind(so, NULL, NULL, p))) { michael@0: /* bind error, probably perm */ michael@0: return (error); michael@0: } michael@0: SOCK_LOCK(so); michael@0: } michael@0: #if (defined(__FreeBSD__) && __FreeBSD_version > 500000) || defined(__Windows__) || defined(__Userspace__) michael@0: #if __FreeBSD_version >= 700000 || defined(__Windows__) || defined(__Userspace__) michael@0: /* It appears for 7.0 and on, we must always call this. */ michael@0: solisten_proto(so, backlog); michael@0: #else michael@0: if ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) == 0) { michael@0: solisten_proto(so); michael@0: } michael@0: #endif michael@0: #endif michael@0: if (inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) { michael@0: /* remove the ACCEPTCONN flag for one-to-many sockets */ michael@0: #if defined(__Userspace__) michael@0: so->so_options &= ~SCTP_SO_ACCEPTCONN; michael@0: #else michael@0: so->so_options &= ~SO_ACCEPTCONN; michael@0: #endif michael@0: } michael@0: michael@0: #if __FreeBSD_version >= 700000 || defined(__Windows__) || defined(__Userspace__) michael@0: if (backlog == 0) { michael@0: /* turning off listen */ michael@0: #if defined(__Userspace__) michael@0: so->so_options &= ~SCTP_SO_ACCEPTCONN; michael@0: #else michael@0: so->so_options &= ~SO_ACCEPTCONN; michael@0: #endif michael@0: } michael@0: #endif michael@0: SOCK_UNLOCK(so); michael@0: return (error); michael@0: } michael@0: michael@0: static int sctp_defered_wakeup_cnt = 0; michael@0: michael@0: int michael@0: #if defined(__FreeBSD__) || defined(__APPLE__) || defined(__Windows__) || defined(__Userspace__) michael@0: sctp_accept(struct socket *so, struct sockaddr **addr) michael@0: { michael@0: #elif defined(__Panda__) michael@0: sctp_accept(struct socket *so, struct sockaddr *addr, int *namelen, michael@0: void *accept_info, int *accept_info_len) michael@0: { michael@0: #else michael@0: sctp_accept(struct socket *so, struct mbuf *nam) michael@0: { michael@0: struct sockaddr *addr = mtod(nam, struct sockaddr *); michael@0: #endif michael@0: struct sctp_tcb *stcb; michael@0: struct sctp_inpcb *inp; michael@0: union sctp_sockstore store; michael@0: #ifdef INET6 michael@0: #ifdef SCTP_KAME michael@0: int error; michael@0: #endif /* SCTP_KAME */ michael@0: #endif michael@0: inp = (struct sctp_inpcb *)so->so_pcb; michael@0: michael@0: if (inp == NULL) { michael@0: SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL); michael@0: return (ECONNRESET); michael@0: } michael@0: SCTP_INP_RLOCK(inp); michael@0: if (inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) { michael@0: SCTP_INP_RUNLOCK(inp); michael@0: SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EOPNOTSUPP); michael@0: return (EOPNOTSUPP); michael@0: } michael@0: if (so->so_state & SS_ISDISCONNECTED) { michael@0: SCTP_INP_RUNLOCK(inp); michael@0: SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ECONNABORTED); michael@0: return (ECONNABORTED); michael@0: } michael@0: stcb = LIST_FIRST(&inp->sctp_asoc_list); michael@0: if (stcb == NULL) { michael@0: SCTP_INP_RUNLOCK(inp); michael@0: SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL); michael@0: return (ECONNRESET); michael@0: } michael@0: SCTP_TCB_LOCK(stcb); michael@0: SCTP_INP_RUNLOCK(inp); michael@0: store = stcb->asoc.primary_destination->ro._l_addr; michael@0: stcb->asoc.state &= ~SCTP_STATE_IN_ACCEPT_QUEUE; michael@0: SCTP_TCB_UNLOCK(stcb); michael@0: switch (store.sa.sa_family) { michael@0: #ifdef INET michael@0: case AF_INET: michael@0: { michael@0: struct sockaddr_in *sin; michael@0: michael@0: #if defined(__FreeBSD__) || defined(__APPLE__) || defined(__Windows__) || defined(__Userspace__) michael@0: SCTP_MALLOC_SONAME(sin, struct sockaddr_in *, sizeof *sin); michael@0: if (sin == NULL) michael@0: return (ENOMEM); michael@0: #else michael@0: sin = (struct sockaddr_in *)addr; michael@0: bzero((caddr_t)sin, sizeof(*sin)); michael@0: #endif michael@0: sin->sin_family = AF_INET; michael@0: #ifdef HAVE_SIN_LEN michael@0: sin->sin_len = sizeof(*sin); michael@0: #endif michael@0: sin->sin_port = store.sin.sin_port; michael@0: sin->sin_addr = store.sin.sin_addr; michael@0: #if defined(__FreeBSD__) || defined(__APPLE__) || defined(__Windows__) || defined(__Userspace__) michael@0: *addr = (struct sockaddr *)sin; michael@0: #elif !defined(__Panda__) michael@0: SCTP_BUF_LEN(nam) = sizeof(*sin); michael@0: #endif michael@0: break; michael@0: } michael@0: #endif michael@0: #ifdef INET6 michael@0: case AF_INET6: michael@0: { michael@0: struct sockaddr_in6 *sin6; michael@0: michael@0: #if defined(__FreeBSD__) || defined(__APPLE__) || defined(__Windows__) || defined(__Userspace__) michael@0: SCTP_MALLOC_SONAME(sin6, struct sockaddr_in6 *, sizeof *sin6); michael@0: if (sin6 == NULL) michael@0: return (ENOMEM); michael@0: #else michael@0: sin6 = (struct sockaddr_in6 *)addr; michael@0: bzero((caddr_t)sin6, sizeof(*sin6)); michael@0: #endif michael@0: sin6->sin6_family = AF_INET6; michael@0: #ifdef HAVE_SIN6_LEN michael@0: sin6->sin6_len = sizeof(*sin6); michael@0: #endif michael@0: sin6->sin6_port = store.sin6.sin6_port; michael@0: sin6->sin6_addr = store.sin6.sin6_addr; michael@0: #if defined(SCTP_EMBEDDED_V6_SCOPE) michael@0: #ifdef SCTP_KAME michael@0: if ((error = sa6_recoverscope(sin6)) != 0) { michael@0: SCTP_FREE_SONAME(sin6); michael@0: return (error); michael@0: } michael@0: #else michael@0: if (IN6_IS_SCOPE_LINKLOCAL(&sin6->sin6_addr)) michael@0: /* michael@0: * sin6->sin6_scope_id = michael@0: * ntohs(sin6->sin6_addr.s6_addr16[1]); michael@0: */ michael@0: in6_recoverscope(sin6, &sin6->sin6_addr, NULL); /* skip ifp check */ michael@0: else michael@0: sin6->sin6_scope_id = 0; /* XXX */ michael@0: #endif /* SCTP_KAME */ michael@0: #endif /* SCTP_EMBEDDED_V6_SCOPE */ michael@0: #if defined(__FreeBSD__) || defined(__APPLE__) || defined(__Windows__) || defined(__Userspace__) michael@0: *addr = (struct sockaddr *)sin6; michael@0: #elif !defined(__Panda__) michael@0: SCTP_BUF_LEN(nam) = sizeof(*sin6); michael@0: #endif michael@0: break; michael@0: } michael@0: #endif michael@0: #if defined(__Userspace__) michael@0: case AF_CONN: michael@0: { michael@0: struct sockaddr_conn *sconn; michael@0: michael@0: SCTP_MALLOC_SONAME(sconn, struct sockaddr_conn *, sizeof(struct sockaddr_conn)); michael@0: if (sconn == NULL) { michael@0: return (ENOMEM); michael@0: } michael@0: sconn->sconn_family = AF_CONN; michael@0: #ifdef HAVE_SCONN_LEN michael@0: sconn->sconn_len = sizeof(struct sockaddr_conn); michael@0: #endif michael@0: sconn->sconn_port = store.sconn.sconn_port; michael@0: sconn->sconn_addr = store.sconn.sconn_addr; michael@0: *addr = (struct sockaddr *)sconn; michael@0: break; michael@0: } michael@0: #endif michael@0: default: michael@0: /* TSNH */ michael@0: break; michael@0: } michael@0: /* Wake any delayed sleep action */ michael@0: if (inp->sctp_flags & SCTP_PCB_FLAGS_DONT_WAKE) { michael@0: SCTP_INP_WLOCK(inp); michael@0: inp->sctp_flags &= ~SCTP_PCB_FLAGS_DONT_WAKE; michael@0: if (inp->sctp_flags & SCTP_PCB_FLAGS_WAKEOUTPUT) { michael@0: inp->sctp_flags &= ~SCTP_PCB_FLAGS_WAKEOUTPUT; michael@0: SCTP_INP_WUNLOCK(inp); michael@0: SOCKBUF_LOCK(&inp->sctp_socket->so_snd); michael@0: if (sowriteable(inp->sctp_socket)) { michael@0: #if defined(__Userspace__) michael@0: /*__Userspace__ calling sowwakup_locked because of SOCKBUF_LOCK above. */ michael@0: #endif michael@0: #if defined(__FreeBSD__) || defined(__Windows__) || defined(__Userspace__) michael@0: sowwakeup_locked(inp->sctp_socket); michael@0: #else michael@0: #if defined(__APPLE__) michael@0: /* socket is locked */ michael@0: #endif michael@0: sowwakeup(inp->sctp_socket); michael@0: #endif michael@0: } else { michael@0: SOCKBUF_UNLOCK(&inp->sctp_socket->so_snd); michael@0: } michael@0: SCTP_INP_WLOCK(inp); michael@0: } michael@0: if (inp->sctp_flags & SCTP_PCB_FLAGS_WAKEINPUT) { michael@0: inp->sctp_flags &= ~SCTP_PCB_FLAGS_WAKEINPUT; michael@0: SCTP_INP_WUNLOCK(inp); michael@0: SOCKBUF_LOCK(&inp->sctp_socket->so_rcv); michael@0: if (soreadable(inp->sctp_socket)) { michael@0: sctp_defered_wakeup_cnt++; michael@0: #if defined(__Userspace__) michael@0: /*__Userspace__ calling sorwakup_locked because of SOCKBUF_LOCK above */ michael@0: #endif michael@0: #if defined(__FreeBSD__) || defined(__Windows__) || defined(__Userspace__) michael@0: sorwakeup_locked(inp->sctp_socket); michael@0: #else michael@0: #if defined(__APPLE__) michael@0: /* socket is locked */ michael@0: #endif michael@0: sorwakeup(inp->sctp_socket); michael@0: #endif michael@0: } else { michael@0: SOCKBUF_UNLOCK(&inp->sctp_socket->so_rcv); michael@0: } michael@0: SCTP_INP_WLOCK(inp); michael@0: } michael@0: SCTP_INP_WUNLOCK(inp); michael@0: } michael@0: if (stcb->asoc.state & SCTP_STATE_ABOUT_TO_BE_FREED) { michael@0: SCTP_TCB_LOCK(stcb); michael@0: sctp_free_assoc(inp, stcb, SCTP_NORMAL_PROC, SCTP_FROM_SCTP_USRREQ+SCTP_LOC_7); michael@0: } michael@0: return (0); michael@0: } michael@0: michael@0: #ifdef INET michael@0: int michael@0: #if defined(__FreeBSD__) || defined(__APPLE__) || defined(__Windows__) michael@0: sctp_ingetaddr(struct socket *so, struct sockaddr **addr) michael@0: { michael@0: struct sockaddr_in *sin; michael@0: #elif defined(__Panda__) michael@0: sctp_ingetaddr(struct socket *so, struct sockaddr *addr) michael@0: { michael@0: struct sockaddr_in *sin = (struct sockaddr_in *)addr; michael@0: #else michael@0: sctp_ingetaddr(struct socket *so, struct mbuf *nam) michael@0: { michael@0: struct sockaddr_in *sin = mtod(nam, struct sockaddr_in *); michael@0: #endif michael@0: uint32_t vrf_id; michael@0: struct sctp_inpcb *inp; michael@0: struct sctp_ifa *sctp_ifa; michael@0: michael@0: /* michael@0: * Do the malloc first in case it blocks. michael@0: */ michael@0: #if defined(__FreeBSD__) || defined(__APPLE__) || defined(__Windows__) michael@0: SCTP_MALLOC_SONAME(sin, struct sockaddr_in *, sizeof *sin); michael@0: if (sin == NULL) michael@0: return (ENOMEM); michael@0: #elif defined(__Panda__) michael@0: bzero(sin, sizeof(*sin)); michael@0: #else michael@0: SCTP_BUF_LEN(nam) = sizeof(*sin); michael@0: memset(sin, 0, sizeof(*sin)); michael@0: #endif michael@0: sin->sin_family = AF_INET; michael@0: #ifdef HAVE_SIN_LEN michael@0: sin->sin_len = sizeof(*sin); michael@0: #endif michael@0: inp = (struct sctp_inpcb *)so->so_pcb; michael@0: if (!inp) { michael@0: #if defined(__FreeBSD__) || defined(__APPLE__) || defined(__Windows__) michael@0: SCTP_FREE_SONAME(sin); michael@0: #endif michael@0: SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL); michael@0: return (ECONNRESET); michael@0: } michael@0: SCTP_INP_RLOCK(inp); michael@0: sin->sin_port = inp->sctp_lport; michael@0: if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUNDALL) { michael@0: if (inp->sctp_flags & SCTP_PCB_FLAGS_CONNECTED) { michael@0: struct sctp_tcb *stcb; michael@0: struct sockaddr_in *sin_a; michael@0: struct sctp_nets *net; michael@0: int fnd; michael@0: michael@0: stcb = LIST_FIRST(&inp->sctp_asoc_list); michael@0: if (stcb == NULL) { michael@0: goto notConn; michael@0: } michael@0: fnd = 0; michael@0: sin_a = NULL; michael@0: SCTP_TCB_LOCK(stcb); michael@0: TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) { michael@0: sin_a = (struct sockaddr_in *)&net->ro._l_addr; michael@0: if (sin_a == NULL) michael@0: /* this will make coverity happy */ michael@0: continue; michael@0: michael@0: if (sin_a->sin_family == AF_INET) { michael@0: fnd = 1; michael@0: break; michael@0: } michael@0: } michael@0: if ((!fnd) || (sin_a == NULL)) { michael@0: /* punt */ michael@0: SCTP_TCB_UNLOCK(stcb); michael@0: goto notConn; michael@0: } michael@0: michael@0: vrf_id = inp->def_vrf_id; michael@0: sctp_ifa = sctp_source_address_selection(inp, michael@0: stcb, michael@0: (sctp_route_t *)&net->ro, michael@0: net, 0, vrf_id); michael@0: if (sctp_ifa) { michael@0: sin->sin_addr = sctp_ifa->address.sin.sin_addr; michael@0: sctp_free_ifa(sctp_ifa); michael@0: } michael@0: SCTP_TCB_UNLOCK(stcb); michael@0: } else { michael@0: /* For the bound all case you get back 0 */ michael@0: notConn: michael@0: sin->sin_addr.s_addr = 0; michael@0: } michael@0: michael@0: } else { michael@0: /* Take the first IPv4 address in the list */ michael@0: struct sctp_laddr *laddr; michael@0: int fnd = 0; michael@0: michael@0: LIST_FOREACH(laddr, &inp->sctp_addr_list, sctp_nxt_addr) { michael@0: if (laddr->ifa->address.sa.sa_family == AF_INET) { michael@0: struct sockaddr_in *sin_a; michael@0: michael@0: sin_a = (struct sockaddr_in *)&laddr->ifa->address.sa; michael@0: sin->sin_addr = sin_a->sin_addr; michael@0: fnd = 1; michael@0: break; michael@0: } michael@0: } michael@0: if (!fnd) { michael@0: #if defined(__FreeBSD__) || defined(__APPLE__) || defined(__Windows__) michael@0: SCTP_FREE_SONAME(sin); michael@0: #endif michael@0: SCTP_INP_RUNLOCK(inp); michael@0: SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOENT); michael@0: return (ENOENT); michael@0: } michael@0: } michael@0: SCTP_INP_RUNLOCK(inp); michael@0: #if defined(__FreeBSD__) || defined(__APPLE__) || defined(__Windows__) michael@0: (*addr) = (struct sockaddr *)sin; michael@0: #endif michael@0: return (0); michael@0: } michael@0: michael@0: int michael@0: #if defined(__FreeBSD__) || defined(__APPLE__) || defined(__Windows__) michael@0: sctp_peeraddr(struct socket *so, struct sockaddr **addr) michael@0: { michael@0: struct sockaddr_in *sin; michael@0: #elif defined(__Panda__) michael@0: sctp_peeraddr(struct socket *so, struct sockaddr *addr) michael@0: { michael@0: struct sockaddr_in *sin = (struct sockaddr_in *)addr; michael@0: #else michael@0: sctp_peeraddr(struct socket *so, struct mbuf *nam) michael@0: { michael@0: struct sockaddr_in *sin = mtod(nam, struct sockaddr_in *); michael@0: michael@0: #endif michael@0: int fnd; michael@0: struct sockaddr_in *sin_a; michael@0: struct sctp_inpcb *inp; michael@0: struct sctp_tcb *stcb; michael@0: struct sctp_nets *net; michael@0: michael@0: /* Do the malloc first in case it blocks. */ michael@0: #if defined(__FreeBSD__) || defined(__APPLE__) || defined(__Windows__) michael@0: SCTP_MALLOC_SONAME(sin, struct sockaddr_in *, sizeof *sin); michael@0: if (sin == NULL) michael@0: return (ENOMEM); michael@0: #elif defined(__Panda__) michael@0: memset(sin, 0, sizeof(*sin)); michael@0: #else michael@0: SCTP_BUF_LEN(nam) = sizeof(*sin); michael@0: memset(sin, 0, sizeof(*sin)); michael@0: #endif michael@0: sin->sin_family = AF_INET; michael@0: #ifdef HAVE_SIN_LEN michael@0: sin->sin_len = sizeof(*sin); michael@0: #endif michael@0: michael@0: inp = (struct sctp_inpcb *)so->so_pcb; michael@0: if ((inp == NULL) || michael@0: ((inp->sctp_flags & SCTP_PCB_FLAGS_CONNECTED) == 0)) { michael@0: /* UDP type and listeners will drop out here */ michael@0: #if defined(__FreeBSD__) || defined(__APPLE__) || defined(__Windows__) michael@0: SCTP_FREE_SONAME(sin); michael@0: #endif michael@0: SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOTCONN); michael@0: return (ENOTCONN); michael@0: } michael@0: SCTP_INP_RLOCK(inp); michael@0: stcb = LIST_FIRST(&inp->sctp_asoc_list); michael@0: if (stcb) { michael@0: SCTP_TCB_LOCK(stcb); michael@0: } michael@0: SCTP_INP_RUNLOCK(inp); michael@0: if (stcb == NULL) { michael@0: #if defined(__FreeBSD__) || defined(__APPLE__) || defined(__Windows__) michael@0: SCTP_FREE_SONAME(sin); michael@0: #endif michael@0: SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL); michael@0: return (ECONNRESET); michael@0: } michael@0: fnd = 0; michael@0: TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) { michael@0: sin_a = (struct sockaddr_in *)&net->ro._l_addr; michael@0: if (sin_a->sin_family == AF_INET) { michael@0: fnd = 1; michael@0: sin->sin_port = stcb->rport; michael@0: sin->sin_addr = sin_a->sin_addr; michael@0: break; michael@0: } michael@0: } michael@0: SCTP_TCB_UNLOCK(stcb); michael@0: if (!fnd) { michael@0: /* No IPv4 address */ michael@0: #if defined(__FreeBSD__) || defined(__APPLE__) || defined(__Windows__) michael@0: SCTP_FREE_SONAME(sin); michael@0: #endif michael@0: SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOENT); michael@0: return (ENOENT); michael@0: } michael@0: #if defined(__FreeBSD__) || defined(__APPLE__) || defined(__Windows__) michael@0: (*addr) = (struct sockaddr *)sin; michael@0: #endif michael@0: return (0); michael@0: } michael@0: michael@0: #if defined(__FreeBSD__) || defined(__APPLE__) || defined(__Windows__) michael@0: struct pr_usrreqs sctp_usrreqs = { michael@0: #if defined(__FreeBSD__) michael@0: .pru_abort = sctp_abort, michael@0: .pru_accept = sctp_accept, michael@0: .pru_attach = sctp_attach, michael@0: .pru_bind = sctp_bind, michael@0: .pru_connect = sctp_connect, michael@0: .pru_control = in_control, michael@0: #if __FreeBSD_version >= 690000 michael@0: .pru_close = sctp_close, michael@0: .pru_detach = sctp_close, michael@0: .pru_sopoll = sopoll_generic, michael@0: .pru_flush = sctp_flush, michael@0: #else michael@0: .pru_detach = sctp_detach, michael@0: .pru_sopoll = sopoll, michael@0: #endif michael@0: .pru_disconnect = sctp_disconnect, michael@0: .pru_listen = sctp_listen, michael@0: .pru_peeraddr = sctp_peeraddr, michael@0: .pru_send = sctp_sendm, michael@0: .pru_shutdown = sctp_shutdown, michael@0: .pru_sockaddr = sctp_ingetaddr, michael@0: .pru_sosend = sctp_sosend, michael@0: .pru_soreceive = sctp_soreceive michael@0: #elif defined(__APPLE__) michael@0: .pru_abort = sctp_abort, michael@0: .pru_accept = sctp_accept, michael@0: .pru_attach = sctp_attach, michael@0: .pru_bind = sctp_bind, michael@0: .pru_connect = sctp_connect, michael@0: .pru_connect2 = pru_connect2_notsupp, michael@0: .pru_control = in_control, michael@0: .pru_detach = sctp_detach, michael@0: .pru_disconnect = sctp_disconnect, michael@0: .pru_listen = sctp_listen, michael@0: .pru_peeraddr = sctp_peeraddr, michael@0: .pru_rcvd = NULL, michael@0: .pru_rcvoob = pru_rcvoob_notsupp, michael@0: .pru_send = sctp_sendm, michael@0: .pru_sense = pru_sense_null, michael@0: .pru_shutdown = sctp_shutdown, michael@0: .pru_sockaddr = sctp_ingetaddr, michael@0: .pru_sosend = sctp_sosend, michael@0: .pru_soreceive = sctp_soreceive, michael@0: .pru_sopoll = sopoll michael@0: #elif defined(__Windows__) michael@0: sctp_abort, michael@0: sctp_accept, michael@0: sctp_attach, michael@0: sctp_bind, michael@0: sctp_connect, michael@0: pru_connect2_notsupp, michael@0: NULL, michael@0: NULL, michael@0: sctp_disconnect, michael@0: sctp_listen, michael@0: sctp_peeraddr, michael@0: NULL, michael@0: pru_rcvoob_notsupp, michael@0: NULL, michael@0: pru_sense_null, michael@0: sctp_shutdown, michael@0: sctp_flush, michael@0: sctp_ingetaddr, michael@0: sctp_sosend, michael@0: sctp_soreceive, michael@0: sopoll_generic, michael@0: NULL, michael@0: sctp_close michael@0: #endif michael@0: }; michael@0: #elif !defined(__Panda__) && !defined(__Userspace__) michael@0: int michael@0: sctp_usrreq(so, req, m, nam, control) michael@0: struct socket *so; michael@0: int req; michael@0: struct mbuf *m, *nam, *control; michael@0: { michael@0: struct proc *p = curproc; michael@0: uint32_t vrf_id; michael@0: struct sctp_vrf *vrf; michael@0: int error; michael@0: int family; michael@0: struct sctp_inpcb *inp = (struct sctp_inpcb *)so->so_pcb; michael@0: michael@0: error = 0; michael@0: family = so->so_proto->pr_domain->dom_family; michael@0: if (req == PRU_CONTROL) { michael@0: switch (family) { michael@0: case PF_INET: michael@0: error = in_control(so, (long)m, (caddr_t)nam, michael@0: (struct ifnet *)control); michael@0: break; michael@0: #ifdef INET6 michael@0: case PF_INET6: michael@0: error = in6_control(so, (long)m, (caddr_t)nam, michael@0: (struct ifnet *)control, p); michael@0: break; michael@0: #endif michael@0: default: michael@0: SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EAFNOSUPPORT); michael@0: error = EAFNOSUPPORT; michael@0: } michael@0: return (error); michael@0: } michael@0: switch (req) { michael@0: case PRU_ATTACH: michael@0: error = sctp_attach(so, family, p); michael@0: break; michael@0: case PRU_DETACH: michael@0: error = sctp_detach(so); michael@0: break; michael@0: case PRU_BIND: michael@0: if (nam == NULL) { michael@0: SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL); michael@0: return (EINVAL); michael@0: } michael@0: error = sctp_bind(so, nam, p); michael@0: break; michael@0: case PRU_LISTEN: michael@0: error = sctp_listen(so, p); michael@0: break; michael@0: case PRU_CONNECT: michael@0: if (nam == NULL) { michael@0: SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL); michael@0: return (EINVAL); michael@0: } michael@0: error = sctp_connect(so, nam, p); michael@0: break; michael@0: case PRU_DISCONNECT: michael@0: error = sctp_disconnect(so); michael@0: break; michael@0: case PRU_ACCEPT: michael@0: if (nam == NULL) { michael@0: SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL); michael@0: return (EINVAL); michael@0: } michael@0: error = sctp_accept(so, nam); michael@0: break; michael@0: case PRU_SHUTDOWN: michael@0: error = sctp_shutdown(so); michael@0: break; michael@0: michael@0: case PRU_RCVD: michael@0: /* michael@0: * For Open and Net BSD, this is real ugly. The mbuf *nam michael@0: * that is passed (by soreceive()) is the int flags c ast as michael@0: * a (mbuf *) yuck! michael@0: */ michael@0: break; michael@0: michael@0: case PRU_SEND: michael@0: /* Flags are ignored */ michael@0: { michael@0: struct sockaddr *addr; michael@0: michael@0: if (nam == NULL) michael@0: addr = NULL; michael@0: else michael@0: addr = mtod(nam, struct sockaddr *); michael@0: michael@0: error = sctp_sendm(so, 0, m, addr, control, p); michael@0: } michael@0: break; michael@0: case PRU_ABORT: michael@0: error = sctp_abort(so); michael@0: break; michael@0: michael@0: case PRU_SENSE: michael@0: error = 0; michael@0: break; michael@0: case PRU_RCVOOB: michael@0: SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EAFNOSUPPORT); michael@0: error = EAFNOSUPPORT; michael@0: break; michael@0: case PRU_SENDOOB: michael@0: SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EAFNOSUPPORT); michael@0: error = EAFNOSUPPORT; michael@0: break; michael@0: case PRU_PEERADDR: michael@0: error = sctp_peeraddr(so, nam); michael@0: break; michael@0: case PRU_SOCKADDR: michael@0: error = sctp_ingetaddr(so, nam); michael@0: break; michael@0: case PRU_SLOWTIMO: michael@0: error = 0; michael@0: break; michael@0: default: michael@0: break; michael@0: } michael@0: return (error); michael@0: } michael@0: michael@0: #endif michael@0: #endif michael@0: michael@0: #if defined(__Userspace__) michael@0: int michael@0: register_recv_cb(struct socket *so, michael@0: int (*receive_cb)(struct socket *sock, union sctp_sockstore addr, void *data, michael@0: size_t datalen, struct sctp_rcvinfo, int flags, void *ulp_info)) michael@0: { michael@0: struct sctp_inpcb *inp; michael@0: michael@0: inp = (struct sctp_inpcb *) so->so_pcb; michael@0: if (inp == NULL) { michael@0: return (0); michael@0: } michael@0: SCTP_INP_WLOCK(inp); michael@0: inp->recv_callback = receive_cb; michael@0: SCTP_INP_WUNLOCK(inp); michael@0: return (1); michael@0: } michael@0: michael@0: int michael@0: register_send_cb(struct socket *so, uint32_t sb_threshold, int (*send_cb)(struct socket *sock, uint32_t sb_free)) michael@0: { michael@0: struct sctp_inpcb *inp; michael@0: michael@0: inp = (struct sctp_inpcb *) so->so_pcb; michael@0: if (inp == NULL) { michael@0: return (0); michael@0: } michael@0: SCTP_INP_WLOCK(inp); michael@0: inp->send_callback = send_cb; michael@0: inp->send_sb_threshold = sb_threshold; michael@0: SCTP_INP_WUNLOCK(inp); michael@0: /* FIXME change to current amount free. This will be the full buffer michael@0: * the first time this is registered but it could be only a portion michael@0: * of the send buffer if this is called a second time e.g. if the michael@0: * threshold changes. michael@0: */ michael@0: return (1); michael@0: } michael@0: michael@0: int michael@0: register_ulp_info (struct socket *so, void *ulp_info) michael@0: { michael@0: struct sctp_inpcb *inp; michael@0: michael@0: inp = (struct sctp_inpcb *) so->so_pcb; michael@0: if (inp == NULL) { michael@0: return (0); michael@0: } michael@0: SCTP_INP_WLOCK(inp); michael@0: inp->ulp_info = ulp_info; michael@0: SCTP_INP_WUNLOCK(inp); michael@0: return (1); michael@0: } michael@0: #endif