2 * Copyright (c) 2001-2008, by Cisco Systems, Inc. All rights reserved.
3 * Copyright (c) 2008-2012, by Randall Stewart. All rights reserved.
4 * Copyright (c) 2008-2012, by Michael Tuexen. All rights reserved.
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions are met:
9 * a) Redistributions of source code must retain the above copyright notice,
10 * this list of conditions and the following disclaimer.
12 * b) Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in
14 * the documentation and/or other materials provided with the distribution.
16 * c) Neither the name of Cisco Systems, Inc. nor the names of its
17 * contributors may be used to endorse or promote products derived
18 * from this software without specific prior written permission.
20 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
22 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
24 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
25 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
26 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
27 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
28 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
29 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
30 * THE POSSIBILITY OF SUCH DAMAGE.
33 #include <sys/cdefs.h>
34 __FBSDID("$FreeBSD$");
36 #include <netinet/sctp_os.h>
38 #include <netinet/sctp_pcb.h>
39 #include <netinet/sctp_header.h>
40 #include <netinet/sctp_var.h>
43 #include <netinet/sctp_sysctl.h>
44 #include <netinet/sctp_output.h>
45 #include <netinet/sctp_uio.h>
46 #include <netinet/sctp_asconf.h>
47 #include <netinet/sctputil.h>
48 #include <netinet/sctp_indata.h>
49 #include <netinet/sctp_timer.h>
50 #include <netinet/sctp_auth.h>
51 #include <netinet/sctp_bsd_addr.h>
52 #include <netinet/udp.h>
56 extern struct sctp_cc_functions sctp_cc_functions[];
57 extern struct sctp_ss_functions sctp_ss_functions[];
64 /* Initialize and modify the sysctled variables */
66 if ((nmbclusters / 8) > SCTP_ASOC_MAX_CHUNKS_ON_QUEUE)
67 SCTP_BASE_SYSCTL(sctp_max_chunks_on_queue) = (nmbclusters / 8);
69 * Allow a user to take no more than 1/2 the number of clusters or
70 * the SB_MAX whichever is smaller for the send window.
72 sb_max_adj = (u_long)((u_quad_t) (SB_MAX) * MCLBYTES / (MSIZE + MCLBYTES));
73 SCTP_BASE_SYSCTL(sctp_sendspace) = min(sb_max_adj,
74 (((uint32_t) nmbclusters / 2) * SCTP_DEFAULT_MAXSEGMENT));
76 * Now for the recv window, should we take the same amount? or
77 * should I do 1/2 the SB_MAX instead in the SB_MAX min above. For
78 * now I will just copy.
80 SCTP_BASE_SYSCTL(sctp_recvspace) = SCTP_BASE_SYSCTL(sctp_sendspace);
81 SCTP_BASE_VAR(first_time) = 0;
82 SCTP_BASE_VAR(sctp_pcb_initialized) = 0;
84 #if defined(SCTP_PACKET_LOGGING)
85 SCTP_BASE_VAR(packet_log_writers) = 0;
86 SCTP_BASE_VAR(packet_log_end) = 0;
87 bzero(&SCTP_BASE_VAR(packet_log_buffer), SCTP_PACKET_LOG_SIZE);
100 sctp_pathmtu_adjustment(struct sctp_tcb *stcb, uint16_t nxtsz)
102 struct sctp_tmit_chunk *chk;
105 /* Adjust that too */
106 stcb->asoc.smallest_mtu = nxtsz;
107 /* now off to subtract IP_DF flag if needed */
108 overhead = IP_HDR_SIZE;
109 if (sctp_auth_is_required_chunk(SCTP_DATA, stcb->asoc.peer_auth_chunks)) {
110 overhead += sctp_get_auth_chunk_len(stcb->asoc.peer_hmac_id);
112 TAILQ_FOREACH(chk, &stcb->asoc.send_queue, sctp_next) {
113 if ((chk->send_size + overhead) > nxtsz) {
114 chk->flags |= CHUNK_FLAGS_FRAGMENT_OK;
117 TAILQ_FOREACH(chk, &stcb->asoc.sent_queue, sctp_next) {
118 if ((chk->send_size + overhead) > nxtsz) {
120 * For this guy we also mark for immediate resend
121 * since we sent to big of chunk
123 chk->flags |= CHUNK_FLAGS_FRAGMENT_OK;
124 if (chk->sent < SCTP_DATAGRAM_RESEND) {
125 sctp_flight_size_decrease(chk);
126 sctp_total_flight_decrease(stcb, chk);
128 if (chk->sent != SCTP_DATAGRAM_RESEND) {
129 sctp_ucount_incr(stcb->asoc.sent_queue_retran_cnt);
131 chk->sent = SCTP_DATAGRAM_RESEND;
132 chk->rec.data.doing_fast_retransmit = 0;
133 if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_FLIGHT_LOGGING_ENABLE) {
134 sctp_misc_ints(SCTP_FLIGHT_LOG_DOWN_PMTU,
135 chk->whoTo->flight_size,
137 (uintptr_t) chk->whoTo,
138 chk->rec.data.TSN_seq);
140 /* Clear any time so NO RTT is being done */
148 sctp_notify_mbuf(struct sctp_inpcb *inp,
149 struct sctp_tcb *stcb,
150 struct sctp_nets *net,
155 int totsz, tmr_stopped = 0;
159 if ((inp == NULL) || (stcb == NULL) || (net == NULL) ||
160 (ip == NULL) || (sh == NULL)) {
162 SCTP_TCB_UNLOCK(stcb);
166 /* First job is to verify the vtag matches what I would send */
167 if (ntohl(sh->v_tag) != (stcb->asoc.peer_vtag)) {
168 SCTP_TCB_UNLOCK(stcb);
171 icmph = (struct icmp *)((caddr_t)ip - (sizeof(struct icmp) -
173 if (icmph->icmp_type != ICMP_UNREACH) {
174 /* We only care about unreachable */
175 SCTP_TCB_UNLOCK(stcb);
178 if (icmph->icmp_code != ICMP_UNREACH_NEEDFRAG) {
179 /* not a unreachable message due to frag. */
180 SCTP_TCB_UNLOCK(stcb);
185 nxtsz = ntohs(icmph->icmp_nextmtu);
188 * old type router that does not tell us what the next size
189 * mtu is. Rats we will have to guess (in a educated fashion
192 nxtsz = sctp_get_prev_mtu(totsz);
194 /* Stop any PMTU timer */
195 if (SCTP_OS_TIMER_PENDING(&net->pmtu_timer.timer)) {
197 sctp_timer_stop(SCTP_TIMER_TYPE_PATHMTURAISE, inp, stcb, net,
198 SCTP_FROM_SCTP_USRREQ + SCTP_LOC_1);
200 /* Adjust destination size limit */
201 if (net->mtu > nxtsz) {
204 net->mtu -= sizeof(struct udphdr);
207 /* now what about the ep? */
208 if (stcb->asoc.smallest_mtu > nxtsz) {
209 sctp_pathmtu_adjustment(stcb, nxtsz);
212 sctp_timer_start(SCTP_TIMER_TYPE_PATHMTURAISE, inp, stcb, net);
214 SCTP_TCB_UNLOCK(stcb);
220 sctp_notify(struct sctp_inpcb *inp,
224 struct sctp_tcb *stcb,
225 struct sctp_nets *net)
227 #if defined(__APPLE__) || defined(SCTP_SO_LOCK_TESTING)
234 if ((inp == NULL) || (stcb == NULL) || (net == NULL) ||
235 (sh == NULL) || (to == NULL)) {
237 SCTP_TCB_UNLOCK(stcb);
240 /* First job is to verify the vtag matches what I would send */
241 if (ntohl(sh->v_tag) != (stcb->asoc.peer_vtag)) {
242 SCTP_TCB_UNLOCK(stcb);
245 icmph = (struct icmp *)((caddr_t)ip - (sizeof(struct icmp) -
247 if (icmph->icmp_type != ICMP_UNREACH) {
248 /* We only care about unreachable */
249 SCTP_TCB_UNLOCK(stcb);
252 if ((icmph->icmp_code == ICMP_UNREACH_NET) ||
253 (icmph->icmp_code == ICMP_UNREACH_HOST) ||
254 (icmph->icmp_code == ICMP_UNREACH_NET_UNKNOWN) ||
255 (icmph->icmp_code == ICMP_UNREACH_HOST_UNKNOWN) ||
256 (icmph->icmp_code == ICMP_UNREACH_ISOLATED) ||
257 (icmph->icmp_code == ICMP_UNREACH_NET_PROHIB) ||
258 (icmph->icmp_code == ICMP_UNREACH_HOST_PROHIB) ||
259 (icmph->icmp_code == ICMP_UNREACH_FILTER_PROHIB)) {
262 * Hmm reachablity problems we must examine closely. If its
263 * not reachable, we may have lost a network. Or if there is
264 * NO protocol at the other end named SCTP. well we consider
267 if (net->dest_state & SCTP_ADDR_REACHABLE) {
268 /* Ok that destination is NOT reachable */
269 net->dest_state &= ~SCTP_ADDR_REACHABLE;
270 net->dest_state &= ~SCTP_ADDR_PF;
271 sctp_ulp_notify(SCTP_NOTIFY_INTERFACE_DOWN,
273 (void *)net, SCTP_SO_NOT_LOCKED);
275 SCTP_TCB_UNLOCK(stcb);
276 } else if ((icmph->icmp_code == ICMP_UNREACH_PROTOCOL) ||
277 (icmph->icmp_code == ICMP_UNREACH_PORT)) {
279 * Here the peer is either playing tricks on us, including
280 * an address that belongs to someone who does not support
281 * SCTP OR was a userland implementation that shutdown and
282 * now is dead. In either case treat it like a OOTB abort
285 sctp_abort_notification(stcb, 1, 0, NULL, SCTP_SO_NOT_LOCKED);
286 #if defined(__APPLE__) || defined(SCTP_SO_LOCK_TESTING)
287 so = SCTP_INP_SO(inp);
288 atomic_add_int(&stcb->asoc.refcnt, 1);
289 SCTP_TCB_UNLOCK(stcb);
290 SCTP_SOCKET_LOCK(so, 1);
292 atomic_subtract_int(&stcb->asoc.refcnt, 1);
294 (void)sctp_free_assoc(inp, stcb, SCTP_NORMAL_PROC, SCTP_FROM_SCTP_USRREQ + SCTP_LOC_2);
295 #if defined(__APPLE__) || defined(SCTP_SO_LOCK_TESTING)
296 SCTP_SOCKET_UNLOCK(so, 1);
297 /* SCTP_TCB_UNLOCK(stcb); MT: I think this is not needed. */
299 /* no need to unlock here, since the TCB is gone */
301 SCTP_TCB_UNLOCK(stcb);
307 sctp_ctlinput(cmd, sa, vip)
316 /* FIX, for non-bsd is this right? */
317 vrf_id = SCTP_DEFAULT_VRFID;
318 if (sa->sa_family != AF_INET ||
319 ((struct sockaddr_in *)sa)->sin_addr.s_addr == INADDR_ANY) {
322 if (PRC_IS_REDIRECT(cmd)) {
324 } else if ((unsigned)cmd >= PRC_NCMDS || inetctlerrmap[cmd] == 0) {
328 struct sctp_inpcb *inp = NULL;
329 struct sctp_tcb *stcb = NULL;
330 struct sctp_nets *net = NULL;
331 struct sockaddr_in to, from;
333 sh = (struct sctphdr *)((caddr_t)ip + (ip->ip_hl << 2));
334 bzero(&to, sizeof(to));
335 bzero(&from, sizeof(from));
336 from.sin_family = to.sin_family = AF_INET;
337 from.sin_len = to.sin_len = sizeof(to);
338 from.sin_port = sh->src_port;
339 from.sin_addr = ip->ip_src;
340 to.sin_port = sh->dest_port;
341 to.sin_addr = ip->ip_dst;
344 * 'to' holds the dest of the packet that failed to be sent.
345 * 'from' holds our local endpoint address. Thus we reverse
346 * the to and the from in the lookup.
348 stcb = sctp_findassociation_addr_sa((struct sockaddr *)&to,
349 (struct sockaddr *)&from,
350 &inp, &net, 1, vrf_id);
351 if (stcb != NULL && inp && (inp->sctp_socket != NULL)) {
352 if (cmd != PRC_MSGSIZE) {
353 sctp_notify(inp, ip, sh,
354 (struct sockaddr *)&to, stcb,
357 /* handle possible ICMP size messages */
358 sctp_notify_mbuf(inp, stcb, net, ip, sh);
361 if ((stcb == NULL) && (inp != NULL)) {
362 /* reduce ref-count */
364 SCTP_INP_DECR_REF(inp);
365 SCTP_INP_WUNLOCK(inp);
368 SCTP_TCB_UNLOCK(stcb);
378 sctp_getcred(SYSCTL_HANDLER_ARGS)
381 struct sockaddr_in addrs[2];
382 struct sctp_inpcb *inp;
383 struct sctp_nets *net;
384 struct sctp_tcb *stcb;
388 /* FIX, for non-bsd is this right? */
389 vrf_id = SCTP_DEFAULT_VRFID;
391 error = priv_check(req->td, PRIV_NETINET_GETCRED);
396 error = SYSCTL_IN(req, addrs, sizeof(addrs));
400 stcb = sctp_findassociation_addr_sa(sintosa(&addrs[1]),
402 &inp, &net, 1, vrf_id);
403 if (stcb == NULL || inp == NULL || inp->sctp_socket == NULL) {
404 if ((inp != NULL) && (stcb == NULL)) {
405 /* reduce ref-count */
407 SCTP_INP_DECR_REF(inp);
410 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOENT);
414 SCTP_TCB_UNLOCK(stcb);
416 * We use the write lock here, only since in the error leg we need
417 * it. If we used RLOCK, then we would have to
418 * wlock/decr/unlock/rlock. Which in theory could create a hole.
419 * Better to use higher wlock.
423 error = cr_canseesocket(req->td->td_ucred, inp->sctp_socket);
425 SCTP_INP_WUNLOCK(inp);
428 cru2x(inp->sctp_socket->so_cred, &xuc);
429 SCTP_INP_WUNLOCK(inp);
430 error = SYSCTL_OUT(req, &xuc, sizeof(struct xucred));
435 SYSCTL_PROC(_net_inet_sctp, OID_AUTO, getcred, CTLTYPE_OPAQUE | CTLFLAG_RW,
436 0, 0, sctp_getcred, "S,ucred", "Get the ucred of a SCTP connection");
441 sctp_abort(struct socket *so)
443 struct sctp_inpcb *inp;
446 inp = (struct sctp_inpcb *)so->so_pcb;
451 flags = inp->sctp_flags;
452 #ifdef SCTP_LOG_CLOSING
453 sctp_log_closing(inp, NULL, 17);
455 if (((flags & SCTP_PCB_FLAGS_SOCKET_GONE) == 0) &&
456 (atomic_cmpset_int(&inp->sctp_flags, flags, (flags | SCTP_PCB_FLAGS_SOCKET_GONE | SCTP_PCB_FLAGS_CLOSE_IP)))) {
457 #ifdef SCTP_LOG_CLOSING
458 sctp_log_closing(inp, NULL, 16);
460 sctp_inpcb_free(inp, SCTP_FREE_SHOULD_USE_ABORT,
461 SCTP_CALLED_AFTER_CMPSET_OFCLOSE);
463 SCTP_SB_CLEAR(so->so_snd);
465 * same for the rcv ones, they are only here for the
468 SCTP_SB_CLEAR(so->so_rcv);
470 /* Now null out the reference, we are completely detached. */
474 flags = inp->sctp_flags;
475 if ((flags & SCTP_PCB_FLAGS_SOCKET_GONE) == 0) {
476 goto sctp_must_try_again;
483 sctp_attach(struct socket *so, int proto SCTP_UNUSED, struct thread *p SCTP_UNUSED)
485 struct sctp_inpcb *inp;
486 struct inpcb *ip_inp;
488 uint32_t vrf_id = SCTP_DEFAULT_VRFID;
495 inp = (struct sctp_inpcb *)so->so_pcb;
497 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
500 if (so->so_snd.sb_hiwat == 0 || so->so_rcv.sb_hiwat == 0) {
501 error = SCTP_SORESERVE(so, SCTP_BASE_SYSCTL(sctp_sendspace), SCTP_BASE_SYSCTL(sctp_recvspace));
506 error = sctp_inpcb_alloc(so, vrf_id);
510 inp = (struct sctp_inpcb *)so->so_pcb;
512 inp->sctp_flags &= ~SCTP_PCB_FLAGS_BOUND_V6; /* I'm not v6! */
513 ip_inp = &inp->ip_inp.inp;
514 ip_inp->inp_vflag |= INP_IPV4;
515 ip_inp->inp_ip_ttl = MODULE_GLOBAL(ip_defttl);
517 error = ipsec_init_policy(so, &ip_inp->inp_sp);
518 #ifdef SCTP_LOG_CLOSING
519 sctp_log_closing(inp, NULL, 17);
523 flags = inp->sctp_flags;
524 if (((flags & SCTP_PCB_FLAGS_SOCKET_GONE) == 0) &&
525 (atomic_cmpset_int(&inp->sctp_flags, flags, (flags | SCTP_PCB_FLAGS_SOCKET_GONE | SCTP_PCB_FLAGS_CLOSE_IP)))) {
526 #ifdef SCTP_LOG_CLOSING
527 sctp_log_closing(inp, NULL, 15);
529 SCTP_INP_WUNLOCK(inp);
530 sctp_inpcb_free(inp, SCTP_FREE_SHOULD_USE_ABORT,
531 SCTP_CALLED_AFTER_CMPSET_OFCLOSE);
533 flags = inp->sctp_flags;
534 if ((flags & SCTP_PCB_FLAGS_SOCKET_GONE) == 0) {
537 SCTP_INP_WUNLOCK(inp);
543 SCTP_INP_WUNLOCK(inp);
548 sctp_bind(struct socket *so, struct sockaddr *addr, struct thread *p)
550 struct sctp_inpcb *inp;
552 inp = (struct sctp_inpcb *)so->so_pcb;
554 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
558 if ((addr->sa_family != AF_INET) ||
559 (addr->sa_len != sizeof(struct sockaddr_in))) {
560 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
564 return (sctp_inpcb_bind(so, addr, NULL, p));
569 sctp_close(struct socket *so)
571 struct sctp_inpcb *inp;
574 inp = (struct sctp_inpcb *)so->so_pcb;
579 * Inform all the lower layer assoc that we are done.
582 flags = inp->sctp_flags;
583 #ifdef SCTP_LOG_CLOSING
584 sctp_log_closing(inp, NULL, 17);
586 if (((flags & SCTP_PCB_FLAGS_SOCKET_GONE) == 0) &&
587 (atomic_cmpset_int(&inp->sctp_flags, flags, (flags | SCTP_PCB_FLAGS_SOCKET_GONE | SCTP_PCB_FLAGS_CLOSE_IP)))) {
588 if (((so->so_options & SO_LINGER) && (so->so_linger == 0)) ||
589 (so->so_rcv.sb_cc > 0)) {
590 #ifdef SCTP_LOG_CLOSING
591 sctp_log_closing(inp, NULL, 13);
593 sctp_inpcb_free(inp, SCTP_FREE_SHOULD_USE_ABORT,
594 SCTP_CALLED_AFTER_CMPSET_OFCLOSE);
596 #ifdef SCTP_LOG_CLOSING
597 sctp_log_closing(inp, NULL, 14);
599 sctp_inpcb_free(inp, SCTP_FREE_SHOULD_USE_GRACEFUL_CLOSE,
600 SCTP_CALLED_AFTER_CMPSET_OFCLOSE);
603 * The socket is now detached, no matter what the state of
604 * the SCTP association.
607 SCTP_SB_CLEAR(so->so_snd);
609 * same for the rcv ones, they are only here for the
612 SCTP_SB_CLEAR(so->so_rcv);
614 /* Now null out the reference, we are completely detached. */
618 flags = inp->sctp_flags;
619 if ((flags & SCTP_PCB_FLAGS_SOCKET_GONE) == 0) {
620 goto sctp_must_try_again;
628 sctp_sendm(struct socket *so, int flags, struct mbuf *m, struct sockaddr *addr,
629 struct mbuf *control, struct thread *p);
633 sctp_sendm(struct socket *so, int flags, struct mbuf *m, struct sockaddr *addr,
634 struct mbuf *control, struct thread *p)
636 struct sctp_inpcb *inp;
639 inp = (struct sctp_inpcb *)so->so_pcb;
642 sctp_m_freem(control);
645 SCTP_LTRACE_ERR_RET_PKT(m, inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
649 /* Got to have an to address if we are NOT a connected socket */
650 if ((addr == NULL) &&
651 ((inp->sctp_flags & SCTP_PCB_FLAGS_CONNECTED) ||
652 (inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE))) {
654 } else if (addr == NULL) {
655 SCTP_LTRACE_ERR_RET_PKT(m, inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EDESTADDRREQ);
656 error = EDESTADDRREQ;
659 sctp_m_freem(control);
665 if (addr->sa_family != AF_INET) {
666 /* must be a v4 address! */
667 SCTP_LTRACE_ERR_RET_PKT(m, inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EDESTADDRREQ);
670 sctp_m_freem(control);
673 error = EDESTADDRREQ;
678 /* now what about control */
681 SCTP_PRINTF("huh? control set?\n");
682 sctp_m_freem(inp->control);
685 inp->control = control;
689 SCTP_BUF_NEXT(inp->pkt_last) = m;
692 inp->pkt_last = inp->pkt = m;
695 /* FreeBSD uses a flag passed */
696 ((flags & PRUS_MORETOCOME) == 0)
699 * note with the current version this code will only be used
700 * by OpenBSD-- NetBSD, FreeBSD, and MacOS have methods for
701 * re-defining sosend to use the sctp_sosend. One can
702 * optionally switch back to this code (by changing back the
703 * definitions) but this is not advisable. This code is used
704 * by FreeBSD when sending a file with sendfile() though.
708 ret = sctp_output(inp, inp->pkt, addr, inp->control, p, flags);
718 sctp_disconnect(struct socket *so)
720 struct sctp_inpcb *inp;
722 inp = (struct sctp_inpcb *)so->so_pcb;
724 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOTCONN);
728 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
729 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL)) {
730 if (LIST_EMPTY(&inp->sctp_asoc_list)) {
732 SCTP_INP_RUNLOCK(inp);
735 struct sctp_association *asoc;
736 struct sctp_tcb *stcb;
738 stcb = LIST_FIRST(&inp->sctp_asoc_list);
740 SCTP_INP_RUNLOCK(inp);
741 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
746 if (stcb->asoc.state & SCTP_STATE_ABOUT_TO_BE_FREED) {
747 /* We are about to be freed, out of here */
748 SCTP_TCB_UNLOCK(stcb);
749 SCTP_INP_RUNLOCK(inp);
752 if (((so->so_options & SO_LINGER) &&
753 (so->so_linger == 0)) ||
754 (so->so_rcv.sb_cc > 0)) {
755 if (SCTP_GET_STATE(asoc) !=
756 SCTP_STATE_COOKIE_WAIT) {
757 /* Left with Data unread */
760 err = sctp_get_mbuf_for_msg(sizeof(struct sctp_paramhdr), 0, M_DONTWAIT, 1, MT_DATA);
766 struct sctp_paramhdr *ph;
768 ph = mtod(err, struct sctp_paramhdr *);
769 SCTP_BUF_LEN(err) = sizeof(struct sctp_paramhdr);
770 ph->param_type = htons(SCTP_CAUSE_USER_INITIATED_ABT);
771 ph->param_length = htons(SCTP_BUF_LEN(err));
773 sctp_send_abort_tcb(stcb, err, SCTP_SO_LOCKED);
774 SCTP_STAT_INCR_COUNTER32(sctps_aborted);
776 SCTP_INP_RUNLOCK(inp);
777 if ((SCTP_GET_STATE(&stcb->asoc) == SCTP_STATE_OPEN) ||
778 (SCTP_GET_STATE(&stcb->asoc) == SCTP_STATE_SHUTDOWN_RECEIVED)) {
779 SCTP_STAT_DECR_GAUGE32(sctps_currestab);
781 (void)sctp_free_assoc(inp, stcb, SCTP_NORMAL_PROC, SCTP_FROM_SCTP_USRREQ + SCTP_LOC_3);
782 /* No unlock tcb assoc is gone */
785 if (TAILQ_EMPTY(&asoc->send_queue) &&
786 TAILQ_EMPTY(&asoc->sent_queue) &&
787 (asoc->stream_queue_cnt == 0)) {
788 /* there is nothing queued to send, so done */
789 if (asoc->locked_on_sending) {
792 if ((SCTP_GET_STATE(asoc) != SCTP_STATE_SHUTDOWN_SENT) &&
793 (SCTP_GET_STATE(asoc) != SCTP_STATE_SHUTDOWN_ACK_SENT)) {
794 /* only send SHUTDOWN 1st time thru */
795 struct sctp_nets *netp;
797 if ((SCTP_GET_STATE(asoc) == SCTP_STATE_OPEN) ||
798 (SCTP_GET_STATE(asoc) == SCTP_STATE_SHUTDOWN_RECEIVED)) {
799 SCTP_STAT_DECR_GAUGE32(sctps_currestab);
801 SCTP_SET_STATE(asoc, SCTP_STATE_SHUTDOWN_SENT);
802 SCTP_CLEAR_SUBSTATE(asoc, SCTP_STATE_SHUTDOWN_PENDING);
803 sctp_stop_timers_for_shutdown(stcb);
804 if (stcb->asoc.alternate) {
805 netp = stcb->asoc.alternate;
807 netp = stcb->asoc.primary_destination;
809 sctp_send_shutdown(stcb, netp);
810 sctp_timer_start(SCTP_TIMER_TYPE_SHUTDOWN,
811 stcb->sctp_ep, stcb, netp);
812 sctp_timer_start(SCTP_TIMER_TYPE_SHUTDOWNGUARD,
813 stcb->sctp_ep, stcb, netp);
814 sctp_chunk_output(stcb->sctp_ep, stcb, SCTP_OUTPUT_FROM_T3, SCTP_SO_LOCKED);
818 * we still got (or just got) data to send,
819 * so set SHUTDOWN_PENDING
822 * XXX sockets draft says that SCTP_EOF
823 * should be sent with no data. currently,
824 * we will allow user data to be sent first
825 * and move to SHUTDOWN-PENDING
827 struct sctp_nets *netp;
829 if (stcb->asoc.alternate) {
830 netp = stcb->asoc.alternate;
832 netp = stcb->asoc.primary_destination;
835 asoc->state |= SCTP_STATE_SHUTDOWN_PENDING;
836 sctp_timer_start(SCTP_TIMER_TYPE_SHUTDOWNGUARD, stcb->sctp_ep, stcb,
838 if (asoc->locked_on_sending) {
839 /* Locked to send out the data */
840 struct sctp_stream_queue_pending *sp;
842 sp = TAILQ_LAST(&asoc->locked_on_sending->outqueue, sctp_streamhead);
844 SCTP_PRINTF("Error, sp is NULL, locked on sending is non-null strm:%d\n",
845 asoc->locked_on_sending->stream_no);
847 if ((sp->length == 0) && (sp->msg_is_complete == 0))
848 asoc->state |= SCTP_STATE_PARTIAL_MSG_LEFT;
851 if (TAILQ_EMPTY(&asoc->send_queue) &&
852 TAILQ_EMPTY(&asoc->sent_queue) &&
853 (asoc->state & SCTP_STATE_PARTIAL_MSG_LEFT)) {
857 op_err = sctp_generate_cause(SCTP_CAUSE_USER_INITIATED_ABT, "");
858 stcb->sctp_ep->last_abort_code = SCTP_FROM_SCTP_USRREQ + SCTP_LOC_4;
859 sctp_send_abort_tcb(stcb, op_err, SCTP_SO_LOCKED);
860 SCTP_STAT_INCR_COUNTER32(sctps_aborted);
861 if ((SCTP_GET_STATE(&stcb->asoc) == SCTP_STATE_OPEN) ||
862 (SCTP_GET_STATE(&stcb->asoc) == SCTP_STATE_SHUTDOWN_RECEIVED)) {
863 SCTP_STAT_DECR_GAUGE32(sctps_currestab);
865 SCTP_INP_RUNLOCK(inp);
866 (void)sctp_free_assoc(inp, stcb, SCTP_NORMAL_PROC, SCTP_FROM_SCTP_USRREQ + SCTP_LOC_5);
869 sctp_chunk_output(inp, stcb, SCTP_OUTPUT_FROM_CLOSING, SCTP_SO_LOCKED);
872 soisdisconnecting(so);
873 SCTP_TCB_UNLOCK(stcb);
874 SCTP_INP_RUNLOCK(inp);
879 /* UDP model does not support this */
880 SCTP_INP_RUNLOCK(inp);
881 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EOPNOTSUPP);
887 sctp_flush(struct socket *so, int how)
890 * We will just clear out the values and let subsequent close clear
891 * out the data, if any. Note if the user did a shutdown(SHUT_RD)
892 * they will not be able to read the data, the socket will block
893 * that from happening.
895 struct sctp_inpcb *inp;
897 inp = (struct sctp_inpcb *)so->so_pcb;
899 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
903 /* For the 1 to many model this does nothing */
904 if (inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) {
905 SCTP_INP_RUNLOCK(inp);
908 SCTP_INP_RUNLOCK(inp);
909 if ((how == PRU_FLUSH_RD) || (how == PRU_FLUSH_RDWR)) {
911 * First make sure the sb will be happy, we don't use these
912 * except maybe the count
915 SCTP_INP_READ_LOCK(inp);
916 inp->sctp_flags |= SCTP_PCB_FLAGS_SOCKET_CANT_READ;
917 SCTP_INP_READ_UNLOCK(inp);
918 SCTP_INP_WUNLOCK(inp);
919 so->so_rcv.sb_cc = 0;
920 so->so_rcv.sb_mbcnt = 0;
921 so->so_rcv.sb_mb = NULL;
923 if ((how == PRU_FLUSH_WR) || (how == PRU_FLUSH_RDWR)) {
925 * First make sure the sb will be happy, we don't use these
926 * except maybe the count
928 so->so_snd.sb_cc = 0;
929 so->so_snd.sb_mbcnt = 0;
930 so->so_snd.sb_mb = NULL;
937 sctp_shutdown(struct socket *so)
939 struct sctp_inpcb *inp;
941 inp = (struct sctp_inpcb *)so->so_pcb;
943 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
947 /* For UDP model this is a invalid call */
948 if (!((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
949 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL))) {
950 /* Restore the flags that the soshutdown took away. */
951 SOCKBUF_LOCK(&so->so_rcv);
952 so->so_rcv.sb_state &= ~SBS_CANTRCVMORE;
953 SOCKBUF_UNLOCK(&so->so_rcv);
954 /* This proc will wakeup for read and do nothing (I hope) */
955 SCTP_INP_RUNLOCK(inp);
956 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EOPNOTSUPP);
960 * Ok if we reach here its the TCP model and it is either a SHUT_WR
961 * or SHUT_RDWR. This means we put the shutdown flag against it.
964 struct sctp_tcb *stcb;
965 struct sctp_association *asoc;
968 (SS_ISCONNECTED | SS_ISCONNECTING | SS_ISDISCONNECTING)) == 0) {
969 SCTP_INP_RUNLOCK(inp);
974 stcb = LIST_FIRST(&inp->sctp_asoc_list);
977 * Ok we hit the case that the shutdown call was
978 * made after an abort or something. Nothing to do
981 SCTP_INP_RUNLOCK(inp);
986 if (TAILQ_EMPTY(&asoc->send_queue) &&
987 TAILQ_EMPTY(&asoc->sent_queue) &&
988 (asoc->stream_queue_cnt == 0)) {
989 if (asoc->locked_on_sending) {
992 /* there is nothing queued to send, so I'm done... */
993 if (SCTP_GET_STATE(asoc) != SCTP_STATE_SHUTDOWN_SENT) {
994 /* only send SHUTDOWN the first time through */
995 struct sctp_nets *netp;
997 if ((SCTP_GET_STATE(asoc) == SCTP_STATE_OPEN) ||
998 (SCTP_GET_STATE(asoc) == SCTP_STATE_SHUTDOWN_RECEIVED)) {
999 SCTP_STAT_DECR_GAUGE32(sctps_currestab);
1001 SCTP_SET_STATE(asoc, SCTP_STATE_SHUTDOWN_SENT);
1002 SCTP_CLEAR_SUBSTATE(asoc, SCTP_STATE_SHUTDOWN_PENDING);
1003 sctp_stop_timers_for_shutdown(stcb);
1004 if (stcb->asoc.alternate) {
1005 netp = stcb->asoc.alternate;
1007 netp = stcb->asoc.primary_destination;
1009 sctp_send_shutdown(stcb, netp);
1010 sctp_timer_start(SCTP_TIMER_TYPE_SHUTDOWN,
1011 stcb->sctp_ep, stcb, netp);
1012 sctp_timer_start(SCTP_TIMER_TYPE_SHUTDOWNGUARD,
1013 stcb->sctp_ep, stcb, netp);
1014 sctp_chunk_output(stcb->sctp_ep, stcb, SCTP_OUTPUT_FROM_T3, SCTP_SO_LOCKED);
1018 * we still got (or just got) data to send, so set
1021 struct sctp_nets *netp;
1023 if (stcb->asoc.alternate) {
1024 netp = stcb->asoc.alternate;
1026 netp = stcb->asoc.primary_destination;
1029 asoc->state |= SCTP_STATE_SHUTDOWN_PENDING;
1030 sctp_timer_start(SCTP_TIMER_TYPE_SHUTDOWNGUARD, stcb->sctp_ep, stcb,
1033 if (asoc->locked_on_sending) {
1034 /* Locked to send out the data */
1035 struct sctp_stream_queue_pending *sp;
1037 sp = TAILQ_LAST(&asoc->locked_on_sending->outqueue, sctp_streamhead);
1039 SCTP_PRINTF("Error, sp is NULL, locked on sending is non-null strm:%d\n",
1040 asoc->locked_on_sending->stream_no);
1042 if ((sp->length == 0) && (sp->msg_is_complete == 0)) {
1043 asoc->state |= SCTP_STATE_PARTIAL_MSG_LEFT;
1047 if (TAILQ_EMPTY(&asoc->send_queue) &&
1048 TAILQ_EMPTY(&asoc->sent_queue) &&
1049 (asoc->state & SCTP_STATE_PARTIAL_MSG_LEFT)) {
1050 struct mbuf *op_err;
1053 op_err = sctp_generate_cause(SCTP_CAUSE_USER_INITIATED_ABT, "");
1054 stcb->sctp_ep->last_abort_code = SCTP_FROM_SCTP_USRREQ + SCTP_LOC_6;
1055 sctp_abort_an_association(stcb->sctp_ep, stcb,
1056 op_err, SCTP_SO_LOCKED);
1059 sctp_chunk_output(inp, stcb, SCTP_OUTPUT_FROM_CLOSING, SCTP_SO_LOCKED);
1062 SCTP_TCB_UNLOCK(stcb);
1065 SCTP_INP_RUNLOCK(inp);
1070 * copies a "user" presentable address and removes embedded scope, etc.
1071 * returns 0 on success, 1 on error
1074 sctp_fill_user_address(struct sockaddr_storage *ss, struct sockaddr *sa)
1077 struct sockaddr_in6 lsa6;
1079 sa = (struct sockaddr *)sctp_recover_scope((struct sockaddr_in6 *)sa,
1082 memcpy(ss, sa, sa->sa_len);
1089 * NOTE: assumes addr lock is held
1092 sctp_fill_up_addresses_vrf(struct sctp_inpcb *inp,
1093 struct sctp_tcb *stcb,
1095 struct sockaddr_storage *sas,
1098 struct sctp_ifn *sctp_ifn;
1099 struct sctp_ifa *sctp_ifa;
1104 int ipv4_local_scope, ipv4_addr_legal;
1108 int local_scope, site_scope, ipv6_addr_legal;
1111 struct sctp_vrf *vrf;
1118 /* Turn on all the appropriate scope */
1119 loopback_scope = stcb->asoc.scope.loopback_scope;
1121 ipv4_local_scope = stcb->asoc.scope.ipv4_local_scope;
1122 ipv4_addr_legal = stcb->asoc.scope.ipv4_addr_legal;
1125 local_scope = stcb->asoc.scope.local_scope;
1126 site_scope = stcb->asoc.scope.site_scope;
1127 ipv6_addr_legal = stcb->asoc.scope.ipv6_addr_legal;
1130 /* Use generic values for endpoints. */
1133 ipv4_local_scope = 1;
1139 if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) {
1141 ipv6_addr_legal = 1;
1144 if (SCTP_IPV6_V6ONLY(inp)) {
1145 ipv4_addr_legal = 0;
1147 ipv4_addr_legal = 1;
1152 ipv6_addr_legal = 0;
1155 ipv4_addr_legal = 1;
1159 vrf = sctp_find_vrf(vrf_id);
1163 if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUNDALL) {
1164 LIST_FOREACH(sctp_ifn, &vrf->ifnlist, next_ifn) {
1165 if ((loopback_scope == 0) &&
1166 SCTP_IFN_IS_IFT_LOOP(sctp_ifn)) {
1167 /* Skip loopback if loopback_scope not set */
1170 LIST_FOREACH(sctp_ifa, &sctp_ifn->ifalist, next_ifa) {
1173 * For the BOUND-ALL case, the list
1174 * associated with a TCB is Always
1175 * considered a reverse list.. i.e.
1176 * it lists addresses that are NOT
1177 * part of the association. If this
1178 * is one of those we must skip it.
1180 if (sctp_is_addr_restricted(stcb,
1185 switch (sctp_ifa->address.sa.sa_family) {
1188 if (ipv4_addr_legal) {
1189 struct sockaddr_in *sin;
1191 sin = (struct sockaddr_in *)&sctp_ifa->address.sa;
1192 if (sin->sin_addr.s_addr == 0) {
1200 if ((ipv4_local_scope == 0) &&
1201 (IN4_ISPRIVATE_ADDRESS(&sin->sin_addr))) {
1205 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_NEEDS_MAPPED_V4)) {
1206 in6_sin_2_v4mapsin6(sin, (struct sockaddr_in6 *)sas);
1207 ((struct sockaddr_in6 *)sas)->sin6_port = inp->sctp_lport;
1208 sas = (struct sockaddr_storage *)((caddr_t)sas + sizeof(struct sockaddr_in6));
1209 actual += sizeof(struct sockaddr_in6);
1212 memcpy(sas, sin, sizeof(*sin));
1213 ((struct sockaddr_in *)sas)->sin_port = inp->sctp_lport;
1214 sas = (struct sockaddr_storage *)((caddr_t)sas + sizeof(*sin));
1215 actual += sizeof(*sin);
1219 if (actual >= limit) {
1229 if (ipv6_addr_legal) {
1230 struct sockaddr_in6 *sin6;
1232 sin6 = (struct sockaddr_in6 *)&sctp_ifa->address.sa;
1233 if (IN6_IS_ADDR_UNSPECIFIED(&sin6->sin6_addr)) {
1241 if (IN6_IS_ADDR_LINKLOCAL(&sin6->sin6_addr)) {
1242 if (local_scope == 0)
1244 if (sin6->sin6_scope_id == 0) {
1245 if (sa6_recoverscope(sin6) != 0)
1263 if ((site_scope == 0) &&
1264 (IN6_IS_ADDR_SITELOCAL(&sin6->sin6_addr))) {
1267 memcpy(sas, sin6, sizeof(*sin6));
1268 ((struct sockaddr_in6 *)sas)->sin6_port = inp->sctp_lport;
1269 sas = (struct sockaddr_storage *)((caddr_t)sas + sizeof(*sin6));
1270 actual += sizeof(*sin6);
1271 if (actual >= limit) {
1286 struct sctp_laddr *laddr;
1288 LIST_FOREACH(laddr, &inp->sctp_addr_list, sctp_nxt_addr) {
1290 if (sctp_is_addr_restricted(stcb, laddr->ifa)) {
1294 if (sctp_fill_user_address(sas, &laddr->ifa->address.sa))
1296 switch (laddr->ifa->address.sa.sa_family) {
1299 ((struct sockaddr_in *)sas)->sin_port = inp->sctp_lport;
1304 ((struct sockaddr_in6 *)sas)->sin6_port = inp->sctp_lport;
1311 sas = (struct sockaddr_storage *)((caddr_t)sas +
1312 laddr->ifa->address.sa.sa_len);
1313 actual += laddr->ifa->address.sa.sa_len;
1314 if (actual >= limit) {
1323 sctp_fill_up_addresses(struct sctp_inpcb *inp,
1324 struct sctp_tcb *stcb,
1326 struct sockaddr_storage *sas)
1330 SCTP_IPI_ADDR_RLOCK();
1331 /* fill up addresses for the endpoint's default vrf */
1332 size = sctp_fill_up_addresses_vrf(inp, stcb, limit, sas,
1334 SCTP_IPI_ADDR_RUNLOCK();
1339 * NOTE: assumes addr lock is held
1342 sctp_count_max_addresses_vrf(struct sctp_inpcb *inp, uint32_t vrf_id)
1345 struct sctp_vrf *vrf = NULL;
1348 * In both sub-set bound an bound_all cases we return the MAXIMUM
1349 * number of addresses that you COULD get. In reality the sub-set
1350 * bound may have an exclusion list for a given TCB OR in the
1351 * bound-all case a TCB may NOT include the loopback or other
1352 * addresses as well.
1354 vrf = sctp_find_vrf(vrf_id);
1358 if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUNDALL) {
1359 struct sctp_ifn *sctp_ifn;
1360 struct sctp_ifa *sctp_ifa;
1362 LIST_FOREACH(sctp_ifn, &vrf->ifnlist, next_ifn) {
1363 LIST_FOREACH(sctp_ifa, &sctp_ifn->ifalist, next_ifa) {
1364 /* Count them if they are the right type */
1365 switch (sctp_ifa->address.sa.sa_family) {
1368 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_NEEDS_MAPPED_V4))
1369 cnt += sizeof(struct sockaddr_in6);
1371 cnt += sizeof(struct sockaddr_in);
1376 cnt += sizeof(struct sockaddr_in6);
1385 struct sctp_laddr *laddr;
1387 LIST_FOREACH(laddr, &inp->sctp_addr_list, sctp_nxt_addr) {
1388 switch (laddr->ifa->address.sa.sa_family) {
1391 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_NEEDS_MAPPED_V4))
1392 cnt += sizeof(struct sockaddr_in6);
1394 cnt += sizeof(struct sockaddr_in);
1399 cnt += sizeof(struct sockaddr_in6);
1411 sctp_count_max_addresses(struct sctp_inpcb *inp)
1415 SCTP_IPI_ADDR_RLOCK();
1416 /* count addresses for the endpoint's default VRF */
1417 cnt = sctp_count_max_addresses_vrf(inp, inp->def_vrf_id);
1418 SCTP_IPI_ADDR_RUNLOCK();
1423 sctp_do_connect_x(struct socket *so, struct sctp_inpcb *inp, void *optval,
1424 size_t optsize, void *p, int delay)
1427 int creat_lock_on = 0;
1428 struct sctp_tcb *stcb = NULL;
1429 struct sockaddr *sa;
1430 int num_v6 = 0, num_v4 = 0, *totaddrp, totaddr;
1432 int bad_addresses = 0;
1435 SCTPDBG(SCTP_DEBUG_PCB1, "Connectx called\n");
1437 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) &&
1438 (inp->sctp_flags & SCTP_PCB_FLAGS_CONNECTED)) {
1439 /* We are already connected AND the TCP model */
1440 SCTP_LTRACE_ERR_RET(inp, stcb, NULL, SCTP_FROM_SCTP_USRREQ, EADDRINUSE);
1441 return (EADDRINUSE);
1443 if ((inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) &&
1444 (sctp_is_feature_off(inp, SCTP_PCB_FLAGS_PORTREUSE))) {
1445 SCTP_LTRACE_ERR_RET(inp, stcb, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
1448 if (inp->sctp_flags & SCTP_PCB_FLAGS_CONNECTED) {
1449 SCTP_INP_RLOCK(inp);
1450 stcb = LIST_FIRST(&inp->sctp_asoc_list);
1451 SCTP_INP_RUNLOCK(inp);
1454 SCTP_LTRACE_ERR_RET(inp, stcb, NULL, SCTP_FROM_SCTP_USRREQ, EALREADY);
1457 SCTP_INP_INCR_REF(inp);
1458 SCTP_ASOC_CREATE_LOCK(inp);
1460 if ((inp->sctp_flags & SCTP_PCB_FLAGS_SOCKET_ALLGONE) ||
1461 (inp->sctp_flags & SCTP_PCB_FLAGS_SOCKET_GONE)) {
1462 SCTP_LTRACE_ERR_RET(inp, stcb, NULL, SCTP_FROM_SCTP_USRREQ, EFAULT);
1466 totaddrp = (int *)optval;
1467 totaddr = *totaddrp;
1468 sa = (struct sockaddr *)(totaddrp + 1);
1469 stcb = sctp_connectx_helper_find(inp, sa, &totaddr, &num_v4, &num_v6, &error, (optsize - sizeof(int)), &bad_addresses);
1470 if ((stcb != NULL) || bad_addresses) {
1471 /* Already have or am bring up an association */
1472 SCTP_ASOC_CREATE_UNLOCK(inp);
1475 SCTP_TCB_UNLOCK(stcb);
1476 if (bad_addresses == 0) {
1477 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EALREADY);
1483 if (((inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) == 0) &&
1488 if ((inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) &&
1490 struct in6pcb *inp6;
1492 inp6 = (struct in6pcb *)inp;
1493 if (SCTP_IPV6_V6ONLY(inp6)) {
1495 * if IPV6_V6ONLY flag, ignore connections destined
1496 * to a v4 addr or v4-mapped addr
1498 SCTP_LTRACE_ERR_RET(inp, stcb, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
1504 if ((inp->sctp_flags & SCTP_PCB_FLAGS_UNBOUND) ==
1505 SCTP_PCB_FLAGS_UNBOUND) {
1506 /* Bind a ephemeral port */
1507 error = sctp_inpcb_bind(so, NULL, NULL, p);
1512 /* FIX ME: do we want to pass in a vrf on the connect call? */
1513 vrf_id = inp->def_vrf_id;
1516 /* We are GOOD to go */
1517 stcb = sctp_aloc_assoc(inp, sa, &error, 0, vrf_id,
1521 /* Gak! no memory */
1524 if (stcb->sctp_ep->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) {
1525 stcb->sctp_ep->sctp_flags |= SCTP_PCB_FLAGS_CONNECTED;
1526 /* Set the connected flag so we can queue data */
1529 SCTP_SET_STATE(&stcb->asoc, SCTP_STATE_COOKIE_WAIT);
1530 /* move to second address */
1531 switch (sa->sa_family) {
1534 sa = (struct sockaddr *)((caddr_t)sa + sizeof(struct sockaddr_in));
1539 sa = (struct sockaddr *)((caddr_t)sa + sizeof(struct sockaddr_in6));
1547 sctp_connectx_helper_add(stcb, sa, (totaddr - 1), &error);
1548 /* Fill in the return id */
1550 (void)sctp_free_assoc(inp, stcb, SCTP_PCBFREE_FORCE, SCTP_FROM_SCTP_USRREQ + SCTP_LOC_6);
1553 a_id = (sctp_assoc_t *) optval;
1554 *a_id = sctp_get_associd(stcb);
1556 /* initialize authentication parameters for the assoc */
1557 sctp_initialize_auth_params(inp, stcb);
1560 /* doing delayed connection */
1561 stcb->asoc.delayed_connection = 1;
1562 sctp_timer_start(SCTP_TIMER_TYPE_INIT, inp, stcb, stcb->asoc.primary_destination);
1564 (void)SCTP_GETTIME_TIMEVAL(&stcb->asoc.time_entered);
1565 sctp_send_initiate(inp, stcb, SCTP_SO_LOCKED);
1567 SCTP_TCB_UNLOCK(stcb);
1568 if (stcb->sctp_ep->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) {
1569 stcb->sctp_ep->sctp_flags |= SCTP_PCB_FLAGS_CONNECTED;
1570 /* Set the connected flag so we can queue data */
1574 if (creat_lock_on) {
1575 SCTP_ASOC_CREATE_UNLOCK(inp);
1577 SCTP_INP_DECR_REF(inp);
1581 #define SCTP_FIND_STCB(inp, stcb, assoc_id) { \
1582 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||\
1583 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL)) { \
1584 SCTP_INP_RLOCK(inp); \
1585 stcb = LIST_FIRST(&inp->sctp_asoc_list); \
1587 SCTP_TCB_LOCK(stcb); \
1589 SCTP_INP_RUNLOCK(inp); \
1590 } else if (assoc_id > SCTP_ALL_ASSOC) { \
1591 stcb = sctp_findassociation_ep_asocid(inp, assoc_id, 1); \
1592 if (stcb == NULL) { \
1593 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOENT); \
1603 #define SCTP_CHECK_AND_CAST(destp, srcp, type, size) {\
1604 if (size < sizeof(type)) { \
1605 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL); \
1609 destp = (type *)srcp; \
1614 sctp_getopt(struct socket *so, int optname, void *optval, size_t *optsize,
1617 struct sctp_inpcb *inp = NULL;
1619 struct sctp_tcb *stcb = NULL;
1621 if (optval == NULL) {
1622 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
1625 inp = (struct sctp_inpcb *)so->so_pcb;
1627 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
1634 case SCTP_AUTOCLOSE:
1635 case SCTP_EXPLICIT_EOR:
1636 case SCTP_AUTO_ASCONF:
1637 case SCTP_DISABLE_FRAGMENTS:
1638 case SCTP_I_WANT_MAPPED_V4_ADDR:
1639 case SCTP_USE_EXT_RCVINFO:
1640 SCTP_INP_RLOCK(inp);
1642 case SCTP_DISABLE_FRAGMENTS:
1643 val = sctp_is_feature_on(inp, SCTP_PCB_FLAGS_NO_FRAGMENT);
1645 case SCTP_I_WANT_MAPPED_V4_ADDR:
1646 val = sctp_is_feature_on(inp, SCTP_PCB_FLAGS_NEEDS_MAPPED_V4);
1648 case SCTP_AUTO_ASCONF:
1649 if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUNDALL) {
1650 /* only valid for bound all sockets */
1651 val = sctp_is_feature_on(inp, SCTP_PCB_FLAGS_AUTO_ASCONF);
1653 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
1658 case SCTP_EXPLICIT_EOR:
1659 val = sctp_is_feature_on(inp, SCTP_PCB_FLAGS_EXPLICIT_EOR);
1662 val = sctp_is_feature_on(inp, SCTP_PCB_FLAGS_NODELAY);
1664 case SCTP_USE_EXT_RCVINFO:
1665 val = sctp_is_feature_on(inp, SCTP_PCB_FLAGS_EXT_RCVINFO);
1667 case SCTP_AUTOCLOSE:
1668 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_AUTOCLOSE))
1669 val = TICKS_TO_SEC(inp->sctp_ep.auto_close_time);
1675 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOPROTOOPT);
1676 error = ENOPROTOOPT;
1677 } /* end switch (sopt->sopt_name) */
1678 if (*optsize < sizeof(val)) {
1679 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
1683 SCTP_INP_RUNLOCK(inp);
1685 /* return the option value */
1686 *(int *)optval = val;
1687 *optsize = sizeof(val);
1690 case SCTP_GET_PACKET_LOG:
1692 #ifdef SCTP_PACKET_LOGGING
1696 SCTP_CHECK_AND_CAST(target, optval, uint8_t, *optsize);
1697 ret = sctp_copy_out_packet_log(target, (int)*optsize);
1700 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EOPNOTSUPP);
1705 case SCTP_REUSE_PORT:
1709 if ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE)) {
1710 /* Can't do this for a 1-m socket */
1714 SCTP_CHECK_AND_CAST(value, optval, uint32_t, *optsize);
1715 *value = sctp_is_feature_on(inp, SCTP_PCB_FLAGS_PORTREUSE);
1716 *optsize = sizeof(uint32_t);
1719 case SCTP_PARTIAL_DELIVERY_POINT:
1723 SCTP_CHECK_AND_CAST(value, optval, uint32_t, *optsize);
1724 *value = inp->partial_delivery_point;
1725 *optsize = sizeof(uint32_t);
1728 case SCTP_FRAGMENT_INTERLEAVE:
1732 SCTP_CHECK_AND_CAST(value, optval, uint32_t, *optsize);
1733 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_FRAG_INTERLEAVE)) {
1734 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_INTERLEAVE_STRMS)) {
1735 *value = SCTP_FRAG_LEVEL_2;
1737 *value = SCTP_FRAG_LEVEL_1;
1740 *value = SCTP_FRAG_LEVEL_0;
1742 *optsize = sizeof(uint32_t);
1745 case SCTP_CMT_ON_OFF:
1747 struct sctp_assoc_value *av;
1749 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
1750 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
1752 av->assoc_value = stcb->asoc.sctp_cmt_on_off;
1753 SCTP_TCB_UNLOCK(stcb);
1755 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
1756 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
1757 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
1758 SCTP_INP_RLOCK(inp);
1759 av->assoc_value = inp->sctp_cmt_on_off;
1760 SCTP_INP_RUNLOCK(inp);
1762 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
1767 *optsize = sizeof(struct sctp_assoc_value);
1771 case SCTP_PLUGGABLE_CC:
1773 struct sctp_assoc_value *av;
1775 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
1776 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
1778 av->assoc_value = stcb->asoc.congestion_control_module;
1779 SCTP_TCB_UNLOCK(stcb);
1781 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
1782 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
1783 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
1784 SCTP_INP_RLOCK(inp);
1785 av->assoc_value = inp->sctp_ep.sctp_default_cc_module;
1786 SCTP_INP_RUNLOCK(inp);
1788 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
1793 *optsize = sizeof(struct sctp_assoc_value);
1797 case SCTP_CC_OPTION:
1799 struct sctp_cc_option *cc_opt;
1801 SCTP_CHECK_AND_CAST(cc_opt, optval, struct sctp_cc_option, *optsize);
1802 SCTP_FIND_STCB(inp, stcb, cc_opt->aid_value.assoc_id);
1806 if (stcb->asoc.cc_functions.sctp_cwnd_socket_option == NULL) {
1809 error = (*stcb->asoc.cc_functions.sctp_cwnd_socket_option) (stcb, 0, cc_opt);
1810 *optsize = sizeof(struct sctp_cc_option);
1812 SCTP_TCB_UNLOCK(stcb);
1816 case SCTP_PLUGGABLE_SS:
1818 struct sctp_assoc_value *av;
1820 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
1821 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
1823 av->assoc_value = stcb->asoc.stream_scheduling_module;
1824 SCTP_TCB_UNLOCK(stcb);
1826 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
1827 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
1828 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
1829 SCTP_INP_RLOCK(inp);
1830 av->assoc_value = inp->sctp_ep.sctp_default_ss_module;
1831 SCTP_INP_RUNLOCK(inp);
1833 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
1838 *optsize = sizeof(struct sctp_assoc_value);
1844 struct sctp_stream_value *av;
1846 SCTP_CHECK_AND_CAST(av, optval, struct sctp_stream_value, *optsize);
1847 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
1849 if (stcb->asoc.ss_functions.sctp_ss_get_value(stcb, &stcb->asoc, &stcb->asoc.strmout[av->stream_id],
1850 &av->stream_value) < 0) {
1851 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
1854 *optsize = sizeof(struct sctp_stream_value);
1856 SCTP_TCB_UNLOCK(stcb);
1859 * Can't get stream value without
1862 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
1867 case SCTP_GET_ADDR_LEN:
1869 struct sctp_assoc_value *av;
1871 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
1874 if (av->assoc_value == AF_INET) {
1875 av->assoc_value = sizeof(struct sockaddr_in);
1880 if (av->assoc_value == AF_INET6) {
1881 av->assoc_value = sizeof(struct sockaddr_in6);
1886 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
1888 *optsize = sizeof(struct sctp_assoc_value);
1892 case SCTP_GET_ASSOC_NUMBER:
1894 uint32_t *value, cnt;
1896 SCTP_CHECK_AND_CAST(value, optval, uint32_t, *optsize);
1898 SCTP_INP_RLOCK(inp);
1899 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
1902 SCTP_INP_RUNLOCK(inp);
1904 *optsize = sizeof(uint32_t);
1907 case SCTP_GET_ASSOC_ID_LIST:
1909 struct sctp_assoc_ids *ids;
1910 unsigned int at, limit;
1912 SCTP_CHECK_AND_CAST(ids, optval, struct sctp_assoc_ids, *optsize);
1914 limit = (*optsize - sizeof(uint32_t)) / sizeof(sctp_assoc_t);
1915 SCTP_INP_RLOCK(inp);
1916 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
1918 ids->gaids_assoc_id[at++] = sctp_get_associd(stcb);
1921 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
1925 SCTP_INP_RUNLOCK(inp);
1927 ids->gaids_number_of_ids = at;
1928 *optsize = ((at * sizeof(sctp_assoc_t)) + sizeof(uint32_t));
1934 struct sctp_assoc_value *av;
1936 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
1937 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
1940 av->assoc_value = stcb->asoc.context;
1941 SCTP_TCB_UNLOCK(stcb);
1943 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
1944 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
1945 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
1946 SCTP_INP_RLOCK(inp);
1947 av->assoc_value = inp->sctp_context;
1948 SCTP_INP_RUNLOCK(inp);
1950 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
1955 *optsize = sizeof(struct sctp_assoc_value);
1961 uint32_t *default_vrfid;
1963 SCTP_CHECK_AND_CAST(default_vrfid, optval, uint32_t, *optsize);
1964 *default_vrfid = inp->def_vrf_id;
1965 *optsize = sizeof(uint32_t);
1968 case SCTP_GET_ASOC_VRF:
1970 struct sctp_assoc_value *id;
1972 SCTP_CHECK_AND_CAST(id, optval, struct sctp_assoc_value, *optsize);
1973 SCTP_FIND_STCB(inp, stcb, id->assoc_id);
1976 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
1978 id->assoc_value = stcb->asoc.vrf_id;
1979 *optsize = sizeof(struct sctp_assoc_value);
1983 case SCTP_GET_VRF_IDS:
1985 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EOPNOTSUPP);
1989 case SCTP_GET_NONCE_VALUES:
1991 struct sctp_get_nonce_values *gnv;
1993 SCTP_CHECK_AND_CAST(gnv, optval, struct sctp_get_nonce_values, *optsize);
1994 SCTP_FIND_STCB(inp, stcb, gnv->gn_assoc_id);
1997 gnv->gn_peers_tag = stcb->asoc.peer_vtag;
1998 gnv->gn_local_tag = stcb->asoc.my_vtag;
1999 SCTP_TCB_UNLOCK(stcb);
2000 *optsize = sizeof(struct sctp_get_nonce_values);
2002 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOTCONN);
2007 case SCTP_DELAYED_SACK:
2009 struct sctp_sack_info *sack;
2011 SCTP_CHECK_AND_CAST(sack, optval, struct sctp_sack_info, *optsize);
2012 SCTP_FIND_STCB(inp, stcb, sack->sack_assoc_id);
2014 sack->sack_delay = stcb->asoc.delayed_ack;
2015 sack->sack_freq = stcb->asoc.sack_freq;
2016 SCTP_TCB_UNLOCK(stcb);
2018 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
2019 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
2020 (sack->sack_assoc_id == SCTP_FUTURE_ASSOC)) {
2021 SCTP_INP_RLOCK(inp);
2022 sack->sack_delay = TICKS_TO_MSEC(inp->sctp_ep.sctp_timeoutticks[SCTP_TIMER_RECV]);
2023 sack->sack_freq = inp->sctp_ep.sctp_sack_freq;
2024 SCTP_INP_RUNLOCK(inp);
2026 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2031 *optsize = sizeof(struct sctp_sack_info);
2035 case SCTP_GET_SNDBUF_USE:
2037 struct sctp_sockstat *ss;
2039 SCTP_CHECK_AND_CAST(ss, optval, struct sctp_sockstat, *optsize);
2040 SCTP_FIND_STCB(inp, stcb, ss->ss_assoc_id);
2043 ss->ss_total_sndbuf = stcb->asoc.total_output_queue_size;
2044 ss->ss_total_recv_buf = (stcb->asoc.size_on_reasm_queue +
2045 stcb->asoc.size_on_all_streams);
2046 SCTP_TCB_UNLOCK(stcb);
2047 *optsize = sizeof(struct sctp_sockstat);
2049 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOTCONN);
2054 case SCTP_MAX_BURST:
2056 struct sctp_assoc_value *av;
2058 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
2059 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
2062 av->assoc_value = stcb->asoc.max_burst;
2063 SCTP_TCB_UNLOCK(stcb);
2065 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
2066 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
2067 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
2068 SCTP_INP_RLOCK(inp);
2069 av->assoc_value = inp->sctp_ep.max_burst;
2070 SCTP_INP_RUNLOCK(inp);
2072 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2077 *optsize = sizeof(struct sctp_assoc_value);
2083 struct sctp_assoc_value *av;
2086 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
2087 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
2090 av->assoc_value = sctp_get_frag_point(stcb, &stcb->asoc);
2091 SCTP_TCB_UNLOCK(stcb);
2093 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
2094 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
2095 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
2096 SCTP_INP_RLOCK(inp);
2097 if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) {
2098 ovh = SCTP_MED_OVERHEAD;
2100 ovh = SCTP_MED_V4_OVERHEAD;
2102 if (inp->sctp_frag_point >= SCTP_DEFAULT_MAXSEGMENT)
2103 av->assoc_value = 0;
2105 av->assoc_value = inp->sctp_frag_point - ovh;
2106 SCTP_INP_RUNLOCK(inp);
2108 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2113 *optsize = sizeof(struct sctp_assoc_value);
2117 case SCTP_GET_STAT_LOG:
2118 error = sctp_fill_stat_log(optval, optsize);
2122 struct sctp_event_subscribe *events;
2124 SCTP_CHECK_AND_CAST(events, optval, struct sctp_event_subscribe, *optsize);
2125 memset(events, 0, sizeof(struct sctp_event_subscribe));
2126 SCTP_INP_RLOCK(inp);
2127 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_RECVDATAIOEVNT))
2128 events->sctp_data_io_event = 1;
2130 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_RECVASSOCEVNT))
2131 events->sctp_association_event = 1;
2133 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_RECVPADDREVNT))
2134 events->sctp_address_event = 1;
2136 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_RECVSENDFAILEVNT))
2137 events->sctp_send_failure_event = 1;
2139 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_RECVPEERERR))
2140 events->sctp_peer_error_event = 1;
2142 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_RECVSHUTDOWNEVNT))
2143 events->sctp_shutdown_event = 1;
2145 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_PDAPIEVNT))
2146 events->sctp_partial_delivery_event = 1;
2148 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_ADAPTATIONEVNT))
2149 events->sctp_adaptation_layer_event = 1;
2151 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_AUTHEVNT))
2152 events->sctp_authentication_event = 1;
2154 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_DRYEVNT))
2155 events->sctp_sender_dry_event = 1;
2157 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_STREAM_RESETEVNT))
2158 events->sctp_stream_reset_event = 1;
2159 SCTP_INP_RUNLOCK(inp);
2160 *optsize = sizeof(struct sctp_event_subscribe);
2163 case SCTP_ADAPTATION_LAYER:
2167 SCTP_CHECK_AND_CAST(value, optval, uint32_t, *optsize);
2169 SCTP_INP_RLOCK(inp);
2170 *value = inp->sctp_ep.adaptation_layer_indicator;
2171 SCTP_INP_RUNLOCK(inp);
2172 *optsize = sizeof(uint32_t);
2175 case SCTP_SET_INITIAL_DBG_SEQ:
2179 SCTP_CHECK_AND_CAST(value, optval, uint32_t, *optsize);
2180 SCTP_INP_RLOCK(inp);
2181 *value = inp->sctp_ep.initial_sequence_debug;
2182 SCTP_INP_RUNLOCK(inp);
2183 *optsize = sizeof(uint32_t);
2186 case SCTP_GET_LOCAL_ADDR_SIZE:
2190 SCTP_CHECK_AND_CAST(value, optval, uint32_t, *optsize);
2191 SCTP_INP_RLOCK(inp);
2192 *value = sctp_count_max_addresses(inp);
2193 SCTP_INP_RUNLOCK(inp);
2194 *optsize = sizeof(uint32_t);
2197 case SCTP_GET_REMOTE_ADDR_SIZE:
2201 struct sctp_nets *net;
2203 SCTP_CHECK_AND_CAST(value, optval, uint32_t, *optsize);
2204 /* FIXME MT: change to sctp_assoc_value? */
2205 SCTP_FIND_STCB(inp, stcb, (sctp_assoc_t) * value);
2209 /* Count the sizes */
2210 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
2211 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_NEEDS_MAPPED_V4)) {
2212 size += sizeof(struct sockaddr_in6);
2214 switch (((struct sockaddr *)&net->ro._l_addr)->sa_family) {
2217 size += sizeof(struct sockaddr_in);
2222 size += sizeof(struct sockaddr_in6);
2230 SCTP_TCB_UNLOCK(stcb);
2231 *value = (uint32_t) size;
2232 *optsize = sizeof(uint32_t);
2234 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOTCONN);
2239 case SCTP_GET_PEER_ADDRESSES:
2241 * Get the address information, an array is passed in to
2242 * fill up we pack it.
2246 struct sockaddr_storage *sas;
2247 struct sctp_nets *net;
2248 struct sctp_getaddresses *saddr;
2250 SCTP_CHECK_AND_CAST(saddr, optval, struct sctp_getaddresses, *optsize);
2251 SCTP_FIND_STCB(inp, stcb, saddr->sget_assoc_id);
2254 left = (*optsize) - sizeof(struct sctp_getaddresses);
2255 *optsize = sizeof(struct sctp_getaddresses);
2256 sas = (struct sockaddr_storage *)&saddr->addr[0];
2258 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
2259 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_NEEDS_MAPPED_V4)) {
2260 cpsz = sizeof(struct sockaddr_in6);
2262 switch (((struct sockaddr *)&net->ro._l_addr)->sa_family) {
2265 cpsz = sizeof(struct sockaddr_in);
2270 cpsz = sizeof(struct sockaddr_in6);
2282 /* not enough room. */
2285 #if defined(INET) && defined(INET6)
2286 if ((sctp_is_feature_on(inp, SCTP_PCB_FLAGS_NEEDS_MAPPED_V4)) &&
2287 (((struct sockaddr *)&net->ro._l_addr)->sa_family == AF_INET)) {
2288 /* Must map the address */
2289 in6_sin_2_v4mapsin6((struct sockaddr_in *)&net->ro._l_addr,
2290 (struct sockaddr_in6 *)sas);
2293 memcpy(sas, &net->ro._l_addr, cpsz);
2294 #if defined(INET) && defined(INET6)
2297 ((struct sockaddr_in *)sas)->sin_port = stcb->rport;
2299 sas = (struct sockaddr_storage *)((caddr_t)sas + cpsz);
2303 SCTP_TCB_UNLOCK(stcb);
2305 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOENT);
2310 case SCTP_GET_LOCAL_ADDRESSES:
2312 size_t limit, actual;
2313 struct sockaddr_storage *sas;
2314 struct sctp_getaddresses *saddr;
2316 SCTP_CHECK_AND_CAST(saddr, optval, struct sctp_getaddresses, *optsize);
2317 SCTP_FIND_STCB(inp, stcb, saddr->sget_assoc_id);
2319 sas = (struct sockaddr_storage *)&saddr->addr[0];
2320 limit = *optsize - sizeof(sctp_assoc_t);
2321 actual = sctp_fill_up_addresses(inp, stcb, limit, sas);
2323 SCTP_TCB_UNLOCK(stcb);
2325 *optsize = sizeof(struct sockaddr_storage) + actual;
2328 case SCTP_PEER_ADDR_PARAMS:
2330 struct sctp_paddrparams *paddrp;
2331 struct sctp_nets *net;
2333 SCTP_CHECK_AND_CAST(paddrp, optval, struct sctp_paddrparams, *optsize);
2334 SCTP_FIND_STCB(inp, stcb, paddrp->spp_assoc_id);
2338 net = sctp_findnet(stcb, (struct sockaddr *)&paddrp->spp_address);
2341 * We increment here since
2342 * sctp_findassociation_ep_addr() wil do a
2343 * decrement if it finds the stcb as long as
2344 * the locked tcb (last argument) is NOT a
2347 SCTP_INP_INCR_REF(inp);
2348 stcb = sctp_findassociation_ep_addr(&inp, (struct sockaddr *)&paddrp->spp_address, &net, NULL, NULL);
2350 SCTP_INP_DECR_REF(inp);
2353 if (stcb && (net == NULL)) {
2354 struct sockaddr *sa;
2356 sa = (struct sockaddr *)&paddrp->spp_address;
2358 if (sa->sa_family == AF_INET) {
2359 struct sockaddr_in *sin;
2361 sin = (struct sockaddr_in *)sa;
2362 if (sin->sin_addr.s_addr) {
2364 SCTP_TCB_UNLOCK(stcb);
2365 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
2371 if (sa->sa_family == AF_INET6) {
2372 struct sockaddr_in6 *sin6;
2374 sin6 = (struct sockaddr_in6 *)sa;
2375 if (!IN6_IS_ADDR_UNSPECIFIED(&sin6->sin6_addr)) {
2377 SCTP_TCB_UNLOCK(stcb);
2378 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
2384 error = EAFNOSUPPORT;
2385 SCTP_TCB_UNLOCK(stcb);
2386 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
2391 /* Applies to the specific association */
2392 paddrp->spp_flags = 0;
2396 if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) {
2397 ovh = SCTP_MED_OVERHEAD;
2399 ovh = SCTP_MED_V4_OVERHEAD;
2402 paddrp->spp_hbinterval = net->heart_beat_delay;
2403 paddrp->spp_pathmaxrxt = net->failure_threshold;
2404 paddrp->spp_pathmtu = net->mtu - ovh;
2405 /* get flags for HB */
2406 if (net->dest_state & SCTP_ADDR_NOHB) {
2407 paddrp->spp_flags |= SPP_HB_DISABLE;
2409 paddrp->spp_flags |= SPP_HB_ENABLE;
2411 /* get flags for PMTU */
2412 if (net->dest_state & SCTP_ADDR_NO_PMTUD) {
2413 paddrp->spp_flags |= SPP_PMTUD_ENABLE;
2415 paddrp->spp_flags |= SPP_PMTUD_DISABLE;
2417 if (net->dscp & 0x01) {
2418 paddrp->spp_dscp = net->dscp & 0xfc;
2419 paddrp->spp_flags |= SPP_DSCP;
2422 if ((net->ro._l_addr.sa.sa_family == AF_INET6) &&
2423 (net->flowlabel & 0x80000000)) {
2424 paddrp->spp_ipv6_flowlabel = net->flowlabel & 0x000fffff;
2425 paddrp->spp_flags |= SPP_IPV6_FLOWLABEL;
2430 * No destination so return default
2433 paddrp->spp_pathmaxrxt = stcb->asoc.def_net_failure;
2434 paddrp->spp_pathmtu = sctp_get_frag_point(stcb, &stcb->asoc);
2435 if (stcb->asoc.default_dscp & 0x01) {
2436 paddrp->spp_dscp = stcb->asoc.default_dscp & 0xfc;
2437 paddrp->spp_flags |= SPP_DSCP;
2440 if (stcb->asoc.default_flowlabel & 0x80000000) {
2441 paddrp->spp_ipv6_flowlabel = stcb->asoc.default_flowlabel & 0x000fffff;
2442 paddrp->spp_flags |= SPP_IPV6_FLOWLABEL;
2445 /* default settings should be these */
2446 if (sctp_stcb_is_feature_on(inp, stcb, SCTP_PCB_FLAGS_DONOT_HEARTBEAT)) {
2447 paddrp->spp_flags |= SPP_HB_DISABLE;
2449 paddrp->spp_flags |= SPP_HB_ENABLE;
2451 if (sctp_stcb_is_feature_on(inp, stcb, SCTP_PCB_FLAGS_DO_NOT_PMTUD)) {
2452 paddrp->spp_flags |= SPP_PMTUD_DISABLE;
2454 paddrp->spp_flags |= SPP_PMTUD_ENABLE;
2456 paddrp->spp_hbinterval = stcb->asoc.heart_beat_delay;
2458 paddrp->spp_assoc_id = sctp_get_associd(stcb);
2459 SCTP_TCB_UNLOCK(stcb);
2461 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
2462 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
2463 (paddrp->spp_assoc_id == SCTP_FUTURE_ASSOC)) {
2464 /* Use endpoint defaults */
2465 SCTP_INP_RLOCK(inp);
2466 paddrp->spp_pathmaxrxt = inp->sctp_ep.def_net_failure;
2467 paddrp->spp_hbinterval = TICKS_TO_MSEC(inp->sctp_ep.sctp_timeoutticks[SCTP_TIMER_HEARTBEAT]);
2468 paddrp->spp_assoc_id = SCTP_FUTURE_ASSOC;
2469 /* get inp's default */
2470 if (inp->sctp_ep.default_dscp & 0x01) {
2471 paddrp->spp_dscp = inp->sctp_ep.default_dscp & 0xfc;
2472 paddrp->spp_flags |= SPP_DSCP;
2475 if ((inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) &&
2476 (inp->sctp_ep.default_flowlabel & 0x80000000)) {
2477 paddrp->spp_ipv6_flowlabel = inp->sctp_ep.default_flowlabel & 0x000fffff;
2478 paddrp->spp_flags |= SPP_IPV6_FLOWLABEL;
2481 /* can't return this */
2482 paddrp->spp_pathmtu = 0;
2484 if (sctp_is_feature_off(inp, SCTP_PCB_FLAGS_DONOT_HEARTBEAT)) {
2485 paddrp->spp_flags |= SPP_HB_ENABLE;
2487 paddrp->spp_flags |= SPP_HB_DISABLE;
2489 if (sctp_is_feature_off(inp, SCTP_PCB_FLAGS_DO_NOT_PMTUD)) {
2490 paddrp->spp_flags |= SPP_PMTUD_ENABLE;
2492 paddrp->spp_flags |= SPP_PMTUD_DISABLE;
2494 SCTP_INP_RUNLOCK(inp);
2496 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2501 *optsize = sizeof(struct sctp_paddrparams);
2505 case SCTP_GET_PEER_ADDR_INFO:
2507 struct sctp_paddrinfo *paddri;
2508 struct sctp_nets *net;
2510 SCTP_CHECK_AND_CAST(paddri, optval, struct sctp_paddrinfo, *optsize);
2511 SCTP_FIND_STCB(inp, stcb, paddri->spinfo_assoc_id);
2515 net = sctp_findnet(stcb, (struct sockaddr *)&paddri->spinfo_address);
2518 * We increment here since
2519 * sctp_findassociation_ep_addr() wil do a
2520 * decrement if it finds the stcb as long as
2521 * the locked tcb (last argument) is NOT a
2524 SCTP_INP_INCR_REF(inp);
2525 stcb = sctp_findassociation_ep_addr(&inp, (struct sockaddr *)&paddri->spinfo_address, &net, NULL, NULL);
2527 SCTP_INP_DECR_REF(inp);
2531 if ((stcb) && (net)) {
2532 if (net->dest_state & SCTP_ADDR_UNCONFIRMED) {
2533 /* It's unconfirmed */
2534 paddri->spinfo_state = SCTP_UNCONFIRMED;
2535 } else if (net->dest_state & SCTP_ADDR_REACHABLE) {
2537 paddri->spinfo_state = SCTP_ACTIVE;
2540 paddri->spinfo_state = SCTP_INACTIVE;
2542 paddri->spinfo_cwnd = net->cwnd;
2543 paddri->spinfo_srtt = net->lastsa >> SCTP_RTT_SHIFT;
2544 paddri->spinfo_rto = net->RTO;
2545 paddri->spinfo_assoc_id = sctp_get_associd(stcb);
2546 paddri->spinfo_mtu = net->mtu;
2547 SCTP_TCB_UNLOCK(stcb);
2548 *optsize = sizeof(struct sctp_paddrinfo);
2551 SCTP_TCB_UNLOCK(stcb);
2553 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOENT);
2558 case SCTP_PCB_STATUS:
2560 struct sctp_pcbinfo *spcb;
2562 SCTP_CHECK_AND_CAST(spcb, optval, struct sctp_pcbinfo, *optsize);
2563 sctp_fill_pcbinfo(spcb);
2564 *optsize = sizeof(struct sctp_pcbinfo);
2569 struct sctp_nets *net;
2570 struct sctp_status *sstat;
2572 SCTP_CHECK_AND_CAST(sstat, optval, struct sctp_status, *optsize);
2573 SCTP_FIND_STCB(inp, stcb, sstat->sstat_assoc_id);
2576 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2581 * I think passing the state is fine since
2582 * sctp_constants.h will be available to the user
2585 sstat->sstat_state = stcb->asoc.state;
2586 sstat->sstat_assoc_id = sctp_get_associd(stcb);
2587 sstat->sstat_rwnd = stcb->asoc.peers_rwnd;
2588 sstat->sstat_unackdata = stcb->asoc.sent_queue_cnt;
2590 * We can't include chunks that have been passed to
2591 * the socket layer. Only things in queue.
2593 sstat->sstat_penddata = (stcb->asoc.cnt_on_reasm_queue +
2594 stcb->asoc.cnt_on_all_streams);
2597 sstat->sstat_instrms = stcb->asoc.streamincnt;
2598 sstat->sstat_outstrms = stcb->asoc.streamoutcnt;
2599 sstat->sstat_fragmentation_point = sctp_get_frag_point(stcb, &stcb->asoc);
2600 memcpy(&sstat->sstat_primary.spinfo_address,
2601 &stcb->asoc.primary_destination->ro._l_addr,
2602 ((struct sockaddr *)(&stcb->asoc.primary_destination->ro._l_addr))->sa_len);
2603 net = stcb->asoc.primary_destination;
2604 ((struct sockaddr_in *)&sstat->sstat_primary.spinfo_address)->sin_port = stcb->rport;
2606 * Again the user can get info from sctp_constants.h
2607 * for what the state of the network is.
2609 if (net->dest_state & SCTP_ADDR_UNCONFIRMED) {
2610 /* It's unconfirmed */
2611 sstat->sstat_primary.spinfo_state = SCTP_UNCONFIRMED;
2612 } else if (net->dest_state & SCTP_ADDR_REACHABLE) {
2614 sstat->sstat_primary.spinfo_state = SCTP_ACTIVE;
2617 sstat->sstat_primary.spinfo_state = SCTP_INACTIVE;
2619 sstat->sstat_primary.spinfo_cwnd = net->cwnd;
2620 sstat->sstat_primary.spinfo_srtt = net->lastsa >> SCTP_RTT_SHIFT;
2621 sstat->sstat_primary.spinfo_rto = net->RTO;
2622 sstat->sstat_primary.spinfo_mtu = net->mtu;
2623 sstat->sstat_primary.spinfo_assoc_id = sctp_get_associd(stcb);
2624 SCTP_TCB_UNLOCK(stcb);
2625 *optsize = sizeof(struct sctp_status);
2630 struct sctp_rtoinfo *srto;
2632 SCTP_CHECK_AND_CAST(srto, optval, struct sctp_rtoinfo, *optsize);
2633 SCTP_FIND_STCB(inp, stcb, srto->srto_assoc_id);
2636 srto->srto_initial = stcb->asoc.initial_rto;
2637 srto->srto_max = stcb->asoc.maxrto;
2638 srto->srto_min = stcb->asoc.minrto;
2639 SCTP_TCB_UNLOCK(stcb);
2641 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
2642 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
2643 (srto->srto_assoc_id == SCTP_FUTURE_ASSOC)) {
2644 SCTP_INP_RLOCK(inp);
2645 srto->srto_initial = inp->sctp_ep.initial_rto;
2646 srto->srto_max = inp->sctp_ep.sctp_maxrto;
2647 srto->srto_min = inp->sctp_ep.sctp_minrto;
2648 SCTP_INP_RUNLOCK(inp);
2650 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2655 *optsize = sizeof(struct sctp_rtoinfo);
2661 struct sctp_timeouts *stimo;
2663 SCTP_CHECK_AND_CAST(stimo, optval, struct sctp_timeouts, *optsize);
2664 SCTP_FIND_STCB(inp, stcb, stimo->stimo_assoc_id);
2667 stimo->stimo_init = stcb->asoc.timoinit;
2668 stimo->stimo_data = stcb->asoc.timodata;
2669 stimo->stimo_sack = stcb->asoc.timosack;
2670 stimo->stimo_shutdown = stcb->asoc.timoshutdown;
2671 stimo->stimo_heartbeat = stcb->asoc.timoheartbeat;
2672 stimo->stimo_cookie = stcb->asoc.timocookie;
2673 stimo->stimo_shutdownack = stcb->asoc.timoshutdownack;
2674 SCTP_TCB_UNLOCK(stcb);
2675 *optsize = sizeof(struct sctp_timeouts);
2677 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2682 case SCTP_ASSOCINFO:
2684 struct sctp_assocparams *sasoc;
2686 SCTP_CHECK_AND_CAST(sasoc, optval, struct sctp_assocparams, *optsize);
2687 SCTP_FIND_STCB(inp, stcb, sasoc->sasoc_assoc_id);
2690 sasoc->sasoc_cookie_life = TICKS_TO_MSEC(stcb->asoc.cookie_life);
2691 sasoc->sasoc_asocmaxrxt = stcb->asoc.max_send_times;
2692 sasoc->sasoc_number_peer_destinations = stcb->asoc.numnets;
2693 sasoc->sasoc_peer_rwnd = stcb->asoc.peers_rwnd;
2694 sasoc->sasoc_local_rwnd = stcb->asoc.my_rwnd;
2695 SCTP_TCB_UNLOCK(stcb);
2697 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
2698 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
2699 (sasoc->sasoc_assoc_id == SCTP_FUTURE_ASSOC)) {
2700 SCTP_INP_RLOCK(inp);
2701 sasoc->sasoc_cookie_life = TICKS_TO_MSEC(inp->sctp_ep.def_cookie_life);
2702 sasoc->sasoc_asocmaxrxt = inp->sctp_ep.max_send_times;
2703 sasoc->sasoc_number_peer_destinations = 0;
2704 sasoc->sasoc_peer_rwnd = 0;
2705 sasoc->sasoc_local_rwnd = sbspace(&inp->sctp_socket->so_rcv);
2706 SCTP_INP_RUNLOCK(inp);
2708 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2713 *optsize = sizeof(struct sctp_assocparams);
2717 case SCTP_DEFAULT_SEND_PARAM:
2719 struct sctp_sndrcvinfo *s_info;
2721 SCTP_CHECK_AND_CAST(s_info, optval, struct sctp_sndrcvinfo, *optsize);
2722 SCTP_FIND_STCB(inp, stcb, s_info->sinfo_assoc_id);
2725 memcpy(s_info, &stcb->asoc.def_send, sizeof(stcb->asoc.def_send));
2726 SCTP_TCB_UNLOCK(stcb);
2728 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
2729 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
2730 (s_info->sinfo_assoc_id == SCTP_FUTURE_ASSOC)) {
2731 SCTP_INP_RLOCK(inp);
2732 memcpy(s_info, &inp->def_send, sizeof(inp->def_send));
2733 SCTP_INP_RUNLOCK(inp);
2735 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2740 *optsize = sizeof(struct sctp_sndrcvinfo);
2746 struct sctp_initmsg *sinit;
2748 SCTP_CHECK_AND_CAST(sinit, optval, struct sctp_initmsg, *optsize);
2749 SCTP_INP_RLOCK(inp);
2750 sinit->sinit_num_ostreams = inp->sctp_ep.pre_open_stream_count;
2751 sinit->sinit_max_instreams = inp->sctp_ep.max_open_streams_intome;
2752 sinit->sinit_max_attempts = inp->sctp_ep.max_init_times;
2753 sinit->sinit_max_init_timeo = inp->sctp_ep.initial_init_rto_max;
2754 SCTP_INP_RUNLOCK(inp);
2755 *optsize = sizeof(struct sctp_initmsg);
2758 case SCTP_PRIMARY_ADDR:
2759 /* we allow a "get" operation on this */
2761 struct sctp_setprim *ssp;
2763 SCTP_CHECK_AND_CAST(ssp, optval, struct sctp_setprim, *optsize);
2764 SCTP_FIND_STCB(inp, stcb, ssp->ssp_assoc_id);
2767 /* simply copy out the sockaddr_storage... */
2771 if (len > stcb->asoc.primary_destination->ro._l_addr.sa.sa_len)
2772 len = stcb->asoc.primary_destination->ro._l_addr.sa.sa_len;
2774 memcpy(&ssp->ssp_addr,
2775 &stcb->asoc.primary_destination->ro._l_addr,
2777 SCTP_TCB_UNLOCK(stcb);
2778 *optsize = sizeof(struct sctp_setprim);
2780 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2785 case SCTP_HMAC_IDENT:
2787 struct sctp_hmacalgo *shmac;
2788 sctp_hmaclist_t *hmaclist;
2792 SCTP_CHECK_AND_CAST(shmac, optval, struct sctp_hmacalgo, *optsize);
2794 SCTP_INP_RLOCK(inp);
2795 hmaclist = inp->sctp_ep.local_hmacs;
2796 if (hmaclist == NULL) {
2797 /* no HMACs to return */
2798 *optsize = sizeof(*shmac);
2799 SCTP_INP_RUNLOCK(inp);
2802 /* is there room for all of the hmac ids? */
2803 size = sizeof(*shmac) + (hmaclist->num_algo *
2804 sizeof(shmac->shmac_idents[0]));
2805 if ((size_t)(*optsize) < size) {
2806 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2808 SCTP_INP_RUNLOCK(inp);
2811 /* copy in the list */
2812 shmac->shmac_number_of_idents = hmaclist->num_algo;
2813 for (i = 0; i < hmaclist->num_algo; i++) {
2814 shmac->shmac_idents[i] = hmaclist->hmac[i];
2816 SCTP_INP_RUNLOCK(inp);
2820 case SCTP_AUTH_ACTIVE_KEY:
2822 struct sctp_authkeyid *scact;
2824 SCTP_CHECK_AND_CAST(scact, optval, struct sctp_authkeyid, *optsize);
2825 SCTP_FIND_STCB(inp, stcb, scact->scact_assoc_id);
2828 /* get the active key on the assoc */
2829 scact->scact_keynumber = stcb->asoc.authinfo.active_keyid;
2830 SCTP_TCB_UNLOCK(stcb);
2832 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
2833 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
2834 (scact->scact_assoc_id == SCTP_FUTURE_ASSOC)) {
2835 /* get the endpoint active key */
2836 SCTP_INP_RLOCK(inp);
2837 scact->scact_keynumber = inp->sctp_ep.default_keyid;
2838 SCTP_INP_RUNLOCK(inp);
2840 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2845 *optsize = sizeof(struct sctp_authkeyid);
2849 case SCTP_LOCAL_AUTH_CHUNKS:
2851 struct sctp_authchunks *sac;
2852 sctp_auth_chklist_t *chklist = NULL;
2855 SCTP_CHECK_AND_CAST(sac, optval, struct sctp_authchunks, *optsize);
2856 SCTP_FIND_STCB(inp, stcb, sac->gauth_assoc_id);
2859 /* get off the assoc */
2860 chklist = stcb->asoc.local_auth_chunks;
2861 /* is there enough space? */
2862 size = sctp_auth_get_chklist_size(chklist);
2863 if (*optsize < (sizeof(struct sctp_authchunks) + size)) {
2865 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
2867 /* copy in the chunks */
2868 (void)sctp_serialize_auth_chunks(chklist, sac->gauth_chunks);
2869 sac->gauth_number_of_chunks = (uint32_t) size;
2870 *optsize = sizeof(struct sctp_authchunks) + size;
2872 SCTP_TCB_UNLOCK(stcb);
2874 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
2875 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
2876 (sac->gauth_assoc_id == SCTP_FUTURE_ASSOC)) {
2877 /* get off the endpoint */
2878 SCTP_INP_RLOCK(inp);
2879 chklist = inp->sctp_ep.local_auth_chunks;
2880 /* is there enough space? */
2881 size = sctp_auth_get_chklist_size(chklist);
2882 if (*optsize < (sizeof(struct sctp_authchunks) + size)) {
2884 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
2886 /* copy in the chunks */
2887 (void)sctp_serialize_auth_chunks(chklist, sac->gauth_chunks);
2888 sac->gauth_number_of_chunks = (uint32_t) size;
2889 *optsize = sizeof(struct sctp_authchunks) + size;
2891 SCTP_INP_RUNLOCK(inp);
2893 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2899 case SCTP_PEER_AUTH_CHUNKS:
2901 struct sctp_authchunks *sac;
2902 sctp_auth_chklist_t *chklist = NULL;
2905 SCTP_CHECK_AND_CAST(sac, optval, struct sctp_authchunks, *optsize);
2906 SCTP_FIND_STCB(inp, stcb, sac->gauth_assoc_id);
2909 /* get off the assoc */
2910 chklist = stcb->asoc.peer_auth_chunks;
2911 /* is there enough space? */
2912 size = sctp_auth_get_chklist_size(chklist);
2913 if (*optsize < (sizeof(struct sctp_authchunks) + size)) {
2915 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
2917 /* copy in the chunks */
2918 (void)sctp_serialize_auth_chunks(chklist, sac->gauth_chunks);
2919 sac->gauth_number_of_chunks = (uint32_t) size;
2920 *optsize = sizeof(struct sctp_authchunks) + size;
2922 SCTP_TCB_UNLOCK(stcb);
2924 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOENT);
2931 struct sctp_event *event;
2932 uint32_t event_type;
2934 SCTP_CHECK_AND_CAST(event, optval, struct sctp_event, *optsize);
2935 SCTP_FIND_STCB(inp, stcb, event->se_assoc_id);
2937 switch (event->se_type) {
2938 case SCTP_ASSOC_CHANGE:
2939 event_type = SCTP_PCB_FLAGS_RECVASSOCEVNT;
2941 case SCTP_PEER_ADDR_CHANGE:
2942 event_type = SCTP_PCB_FLAGS_RECVPADDREVNT;
2944 case SCTP_REMOTE_ERROR:
2945 event_type = SCTP_PCB_FLAGS_RECVPEERERR;
2947 case SCTP_SEND_FAILED:
2948 event_type = SCTP_PCB_FLAGS_RECVSENDFAILEVNT;
2950 case SCTP_SHUTDOWN_EVENT:
2951 event_type = SCTP_PCB_FLAGS_RECVSHUTDOWNEVNT;
2953 case SCTP_ADAPTATION_INDICATION:
2954 event_type = SCTP_PCB_FLAGS_ADAPTATIONEVNT;
2956 case SCTP_PARTIAL_DELIVERY_EVENT:
2957 event_type = SCTP_PCB_FLAGS_PDAPIEVNT;
2959 case SCTP_AUTHENTICATION_EVENT:
2960 event_type = SCTP_PCB_FLAGS_AUTHEVNT;
2962 case SCTP_STREAM_RESET_EVENT:
2963 event_type = SCTP_PCB_FLAGS_STREAM_RESETEVNT;
2965 case SCTP_SENDER_DRY_EVENT:
2966 event_type = SCTP_PCB_FLAGS_DRYEVNT;
2968 case SCTP_NOTIFICATIONS_STOPPED_EVENT:
2970 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOTSUP);
2973 case SCTP_ASSOC_RESET_EVENT:
2974 event_type = SCTP_PCB_FLAGS_ASSOC_RESETEVNT;
2976 case SCTP_STREAM_CHANGE_EVENT:
2977 event_type = SCTP_PCB_FLAGS_STREAM_CHANGEEVNT;
2979 case SCTP_SEND_FAILED_EVENT:
2980 event_type = SCTP_PCB_FLAGS_RECVNSENDFAILEVNT;
2984 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2988 if (event_type > 0) {
2990 event->se_on = sctp_stcb_is_feature_on(inp, stcb, event_type);
2991 SCTP_TCB_UNLOCK(stcb);
2993 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
2994 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
2995 (event->se_assoc_id == SCTP_FUTURE_ASSOC)) {
2996 SCTP_INP_RLOCK(inp);
2997 event->se_on = sctp_is_feature_on(inp, event_type);
2998 SCTP_INP_RUNLOCK(inp);
3000 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3006 *optsize = sizeof(struct sctp_event);
3010 case SCTP_RECVRCVINFO:
3014 if (*optsize < sizeof(int)) {
3015 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3018 SCTP_INP_RLOCK(inp);
3019 onoff = sctp_is_feature_on(inp, SCTP_PCB_FLAGS_RECVRCVINFO);
3020 SCTP_INP_RUNLOCK(inp);
3023 /* return the option value */
3024 *(int *)optval = onoff;
3025 *optsize = sizeof(int);
3029 case SCTP_RECVNXTINFO:
3033 if (*optsize < sizeof(int)) {
3034 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3037 SCTP_INP_RLOCK(inp);
3038 onoff = sctp_is_feature_on(inp, SCTP_PCB_FLAGS_RECVNXTINFO);
3039 SCTP_INP_RUNLOCK(inp);
3042 /* return the option value */
3043 *(int *)optval = onoff;
3044 *optsize = sizeof(int);
3048 case SCTP_DEFAULT_SNDINFO:
3050 struct sctp_sndinfo *info;
3052 SCTP_CHECK_AND_CAST(info, optval, struct sctp_sndinfo, *optsize);
3053 SCTP_FIND_STCB(inp, stcb, info->snd_assoc_id);
3056 info->snd_sid = stcb->asoc.def_send.sinfo_stream;
3057 info->snd_flags = stcb->asoc.def_send.sinfo_flags;
3058 info->snd_flags &= 0xfff0;
3059 info->snd_ppid = stcb->asoc.def_send.sinfo_ppid;
3060 info->snd_context = stcb->asoc.def_send.sinfo_context;
3061 SCTP_TCB_UNLOCK(stcb);
3063 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3064 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3065 (info->snd_assoc_id == SCTP_FUTURE_ASSOC)) {
3066 SCTP_INP_RLOCK(inp);
3067 info->snd_sid = inp->def_send.sinfo_stream;
3068 info->snd_flags = inp->def_send.sinfo_flags;
3069 info->snd_flags &= 0xfff0;
3070 info->snd_ppid = inp->def_send.sinfo_ppid;
3071 info->snd_context = inp->def_send.sinfo_context;
3072 SCTP_INP_RUNLOCK(inp);
3074 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3079 *optsize = sizeof(struct sctp_sndinfo);
3083 case SCTP_DEFAULT_PRINFO:
3085 struct sctp_default_prinfo *info;
3087 SCTP_CHECK_AND_CAST(info, optval, struct sctp_default_prinfo, *optsize);
3088 SCTP_FIND_STCB(inp, stcb, info->pr_assoc_id);
3091 info->pr_policy = PR_SCTP_POLICY(stcb->asoc.def_send.sinfo_flags);
3092 info->pr_value = stcb->asoc.def_send.sinfo_timetolive;
3093 SCTP_TCB_UNLOCK(stcb);
3095 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3096 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3097 (info->pr_assoc_id == SCTP_FUTURE_ASSOC)) {
3098 SCTP_INP_RLOCK(inp);
3099 info->pr_policy = PR_SCTP_POLICY(inp->def_send.sinfo_flags);
3100 info->pr_value = inp->def_send.sinfo_timetolive;
3101 SCTP_INP_RUNLOCK(inp);
3103 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3108 *optsize = sizeof(struct sctp_default_prinfo);
3112 case SCTP_PEER_ADDR_THLDS:
3114 struct sctp_paddrthlds *thlds;
3115 struct sctp_nets *net;
3117 SCTP_CHECK_AND_CAST(thlds, optval, struct sctp_paddrthlds, *optsize);
3118 SCTP_FIND_STCB(inp, stcb, thlds->spt_assoc_id);
3122 net = sctp_findnet(stcb, (struct sockaddr *)&thlds->spt_address);
3125 * We increment here since
3126 * sctp_findassociation_ep_addr() wil do a
3127 * decrement if it finds the stcb as long as
3128 * the locked tcb (last argument) is NOT a
3131 SCTP_INP_INCR_REF(inp);
3132 stcb = sctp_findassociation_ep_addr(&inp, (struct sockaddr *)&thlds->spt_address, &net, NULL, NULL);
3134 SCTP_INP_DECR_REF(inp);
3137 if (stcb && (net == NULL)) {
3138 struct sockaddr *sa;
3140 sa = (struct sockaddr *)&thlds->spt_address;
3142 if (sa->sa_family == AF_INET) {
3143 struct sockaddr_in *sin;
3145 sin = (struct sockaddr_in *)sa;
3146 if (sin->sin_addr.s_addr) {
3148 SCTP_TCB_UNLOCK(stcb);
3149 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
3155 if (sa->sa_family == AF_INET6) {
3156 struct sockaddr_in6 *sin6;
3158 sin6 = (struct sockaddr_in6 *)sa;
3159 if (!IN6_IS_ADDR_UNSPECIFIED(&sin6->sin6_addr)) {
3161 SCTP_TCB_UNLOCK(stcb);
3162 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
3168 error = EAFNOSUPPORT;
3169 SCTP_TCB_UNLOCK(stcb);
3170 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
3176 thlds->spt_pathmaxrxt = net->failure_threshold;
3177 thlds->spt_pathpfthld = net->pf_threshold;
3179 thlds->spt_pathmaxrxt = stcb->asoc.def_net_failure;
3180 thlds->spt_pathpfthld = stcb->asoc.def_net_pf_threshold;
3182 thlds->spt_assoc_id = sctp_get_associd(stcb);
3183 SCTP_TCB_UNLOCK(stcb);
3185 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3186 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3187 (thlds->spt_assoc_id == SCTP_FUTURE_ASSOC)) {
3188 /* Use endpoint defaults */
3189 SCTP_INP_RLOCK(inp);
3190 thlds->spt_pathmaxrxt = inp->sctp_ep.def_net_failure;
3191 thlds->spt_pathpfthld = inp->sctp_ep.def_net_pf_threshold;
3192 SCTP_INP_RUNLOCK(inp);
3194 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3199 *optsize = sizeof(struct sctp_paddrthlds);
3203 case SCTP_REMOTE_UDP_ENCAPS_PORT:
3205 struct sctp_udpencaps *encaps;
3206 struct sctp_nets *net;
3208 SCTP_CHECK_AND_CAST(encaps, optval, struct sctp_udpencaps, *optsize);
3209 SCTP_FIND_STCB(inp, stcb, encaps->sue_assoc_id);
3212 net = sctp_findnet(stcb, (struct sockaddr *)&encaps->sue_address);
3215 * We increment here since
3216 * sctp_findassociation_ep_addr() wil do a
3217 * decrement if it finds the stcb as long as
3218 * the locked tcb (last argument) is NOT a
3222 SCTP_INP_INCR_REF(inp);
3223 stcb = sctp_findassociation_ep_addr(&inp, (struct sockaddr *)&encaps->sue_address, &net, NULL, NULL);
3225 SCTP_INP_DECR_REF(inp);
3228 if (stcb && (net == NULL)) {
3229 struct sockaddr *sa;
3231 sa = (struct sockaddr *)&encaps->sue_address;
3233 if (sa->sa_family == AF_INET) {
3234 struct sockaddr_in *sin;
3236 sin = (struct sockaddr_in *)sa;
3237 if (sin->sin_addr.s_addr) {
3239 SCTP_TCB_UNLOCK(stcb);
3240 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
3246 if (sa->sa_family == AF_INET6) {
3247 struct sockaddr_in6 *sin6;
3249 sin6 = (struct sockaddr_in6 *)sa;
3250 if (!IN6_IS_ADDR_UNSPECIFIED(&sin6->sin6_addr)) {
3252 SCTP_TCB_UNLOCK(stcb);
3253 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
3259 error = EAFNOSUPPORT;
3260 SCTP_TCB_UNLOCK(stcb);
3261 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
3267 encaps->sue_port = net->port;
3269 encaps->sue_port = stcb->asoc.port;
3271 SCTP_TCB_UNLOCK(stcb);
3273 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3274 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3275 (encaps->sue_assoc_id == SCTP_FUTURE_ASSOC)) {
3276 SCTP_INP_RLOCK(inp);
3277 encaps->sue_port = inp->sctp_ep.port;
3278 SCTP_INP_RUNLOCK(inp);
3280 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3285 *optsize = sizeof(struct sctp_udpencaps);
3289 case SCTP_ENABLE_STREAM_RESET:
3291 struct sctp_assoc_value *av;
3293 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
3294 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
3297 av->assoc_value = (uint32_t) stcb->asoc.local_strreset_support;
3298 SCTP_TCB_UNLOCK(stcb);
3300 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3301 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3302 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
3303 SCTP_INP_RLOCK(inp);
3304 av->assoc_value = (uint32_t) inp->local_strreset_support;
3305 SCTP_INP_RUNLOCK(inp);
3307 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3312 *optsize = sizeof(struct sctp_assoc_value);
3317 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOPROTOOPT);
3318 error = ENOPROTOOPT;
3320 } /* end switch (sopt->sopt_name) */
3328 sctp_setopt(struct socket *so, int optname, void *optval, size_t optsize,
3333 struct sctp_tcb *stcb = NULL;
3334 struct sctp_inpcb *inp = NULL;
3337 if (optval == NULL) {
3338 SCTP_PRINTF("optval is NULL\n");
3339 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3342 inp = (struct sctp_inpcb *)so->so_pcb;
3344 SCTP_PRINTF("inp is NULL?\n");
3345 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3348 vrf_id = inp->def_vrf_id;
3353 case SCTP_AUTOCLOSE:
3354 case SCTP_AUTO_ASCONF:
3355 case SCTP_EXPLICIT_EOR:
3356 case SCTP_DISABLE_FRAGMENTS:
3357 case SCTP_USE_EXT_RCVINFO:
3358 case SCTP_I_WANT_MAPPED_V4_ADDR:
3359 /* copy in the option value */
3360 SCTP_CHECK_AND_CAST(mopt, optval, uint32_t, optsize);
3365 case SCTP_DISABLE_FRAGMENTS:
3366 set_opt = SCTP_PCB_FLAGS_NO_FRAGMENT;
3368 case SCTP_AUTO_ASCONF:
3370 * NOTE: we don't really support this flag
3372 if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUNDALL) {
3373 /* only valid for bound all sockets */
3374 if ((SCTP_BASE_SYSCTL(sctp_auto_asconf) == 0) &&
3376 /* forbidden by admin */
3377 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EPERM);
3380 set_opt = SCTP_PCB_FLAGS_AUTO_ASCONF;
3382 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3386 case SCTP_EXPLICIT_EOR:
3387 set_opt = SCTP_PCB_FLAGS_EXPLICIT_EOR;
3389 case SCTP_USE_EXT_RCVINFO:
3390 set_opt = SCTP_PCB_FLAGS_EXT_RCVINFO;
3392 case SCTP_I_WANT_MAPPED_V4_ADDR:
3393 if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) {
3394 set_opt = SCTP_PCB_FLAGS_NEEDS_MAPPED_V4;
3396 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3401 set_opt = SCTP_PCB_FLAGS_NODELAY;
3403 case SCTP_AUTOCLOSE:
3404 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3405 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL)) {
3406 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3409 set_opt = SCTP_PCB_FLAGS_AUTOCLOSE;
3411 * The value is in ticks. Note this does not effect
3412 * old associations, only new ones.
3414 inp->sctp_ep.auto_close_time = SEC_TO_TICKS(*mopt);
3417 SCTP_INP_WLOCK(inp);
3419 sctp_feature_on(inp, set_opt);
3421 sctp_feature_off(inp, set_opt);
3423 SCTP_INP_WUNLOCK(inp);
3425 case SCTP_REUSE_PORT:
3427 SCTP_CHECK_AND_CAST(mopt, optval, uint32_t, optsize);
3428 if ((inp->sctp_flags & SCTP_PCB_FLAGS_UNBOUND) == 0) {
3429 /* Can't set it after we are bound */
3433 if ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE)) {
3434 /* Can't do this for a 1-m socket */
3439 sctp_feature_on(inp, SCTP_PCB_FLAGS_PORTREUSE);
3441 sctp_feature_off(inp, SCTP_PCB_FLAGS_PORTREUSE);
3444 case SCTP_PARTIAL_DELIVERY_POINT:
3448 SCTP_CHECK_AND_CAST(value, optval, uint32_t, optsize);
3449 if (*value > SCTP_SB_LIMIT_RCV(so)) {
3450 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3454 inp->partial_delivery_point = *value;
3457 case SCTP_FRAGMENT_INTERLEAVE:
3458 /* not yet until we re-write sctp_recvmsg() */
3462 SCTP_CHECK_AND_CAST(level, optval, uint32_t, optsize);
3463 if (*level == SCTP_FRAG_LEVEL_2) {
3464 sctp_feature_on(inp, SCTP_PCB_FLAGS_FRAG_INTERLEAVE);
3465 sctp_feature_on(inp, SCTP_PCB_FLAGS_INTERLEAVE_STRMS);
3466 } else if (*level == SCTP_FRAG_LEVEL_1) {
3467 sctp_feature_on(inp, SCTP_PCB_FLAGS_FRAG_INTERLEAVE);
3468 sctp_feature_off(inp, SCTP_PCB_FLAGS_INTERLEAVE_STRMS);
3469 } else if (*level == SCTP_FRAG_LEVEL_0) {
3470 sctp_feature_off(inp, SCTP_PCB_FLAGS_FRAG_INTERLEAVE);
3471 sctp_feature_off(inp, SCTP_PCB_FLAGS_INTERLEAVE_STRMS);
3474 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3479 case SCTP_CMT_ON_OFF:
3480 if (SCTP_BASE_SYSCTL(sctp_cmt_on_off)) {
3481 struct sctp_assoc_value *av;
3483 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
3484 if (av->assoc_value > SCTP_CMT_MAX) {
3485 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3489 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
3491 stcb->asoc.sctp_cmt_on_off = av->assoc_value;
3492 SCTP_TCB_UNLOCK(stcb);
3494 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3495 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3496 (av->assoc_id == SCTP_FUTURE_ASSOC) ||
3497 (av->assoc_id == SCTP_ALL_ASSOC)) {
3498 SCTP_INP_WLOCK(inp);
3499 inp->sctp_cmt_on_off = av->assoc_value;
3500 SCTP_INP_WUNLOCK(inp);
3502 if ((av->assoc_id == SCTP_CURRENT_ASSOC) ||
3503 (av->assoc_id == SCTP_ALL_ASSOC)) {
3504 SCTP_INP_RLOCK(inp);
3505 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
3506 SCTP_TCB_LOCK(stcb);
3507 stcb->asoc.sctp_cmt_on_off = av->assoc_value;
3508 SCTP_TCB_UNLOCK(stcb);
3510 SCTP_INP_RUNLOCK(inp);
3514 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOPROTOOPT);
3515 error = ENOPROTOOPT;
3518 case SCTP_PLUGGABLE_CC:
3520 struct sctp_assoc_value *av;
3521 struct sctp_nets *net;
3523 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
3524 if ((av->assoc_value != SCTP_CC_RFC2581) &&
3525 (av->assoc_value != SCTP_CC_HSTCP) &&
3526 (av->assoc_value != SCTP_CC_HTCP) &&
3527 (av->assoc_value != SCTP_CC_RTCC)) {
3528 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3532 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
3534 stcb->asoc.cc_functions = sctp_cc_functions[av->assoc_value];
3535 stcb->asoc.congestion_control_module = av->assoc_value;
3536 if (stcb->asoc.cc_functions.sctp_set_initial_cc_param != NULL) {
3537 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
3538 stcb->asoc.cc_functions.sctp_set_initial_cc_param(stcb, net);
3541 SCTP_TCB_UNLOCK(stcb);
3543 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3544 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3545 (av->assoc_id == SCTP_FUTURE_ASSOC) ||
3546 (av->assoc_id == SCTP_ALL_ASSOC)) {
3547 SCTP_INP_WLOCK(inp);
3548 inp->sctp_ep.sctp_default_cc_module = av->assoc_value;
3549 SCTP_INP_WUNLOCK(inp);
3551 if ((av->assoc_id == SCTP_CURRENT_ASSOC) ||
3552 (av->assoc_id == SCTP_ALL_ASSOC)) {
3553 SCTP_INP_RLOCK(inp);
3554 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
3555 SCTP_TCB_LOCK(stcb);
3556 stcb->asoc.cc_functions = sctp_cc_functions[av->assoc_value];
3557 stcb->asoc.congestion_control_module = av->assoc_value;
3558 if (stcb->asoc.cc_functions.sctp_set_initial_cc_param != NULL) {
3559 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
3560 stcb->asoc.cc_functions.sctp_set_initial_cc_param(stcb, net);
3563 SCTP_TCB_UNLOCK(stcb);
3565 SCTP_INP_RUNLOCK(inp);
3570 case SCTP_CC_OPTION:
3572 struct sctp_cc_option *cc_opt;
3574 SCTP_CHECK_AND_CAST(cc_opt, optval, struct sctp_cc_option, optsize);
3575 SCTP_FIND_STCB(inp, stcb, cc_opt->aid_value.assoc_id);
3577 if (cc_opt->aid_value.assoc_id == SCTP_CURRENT_ASSOC) {
3578 SCTP_INP_RLOCK(inp);
3579 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
3580 SCTP_TCB_LOCK(stcb);
3581 if (stcb->asoc.cc_functions.sctp_cwnd_socket_option) {
3582 (*stcb->asoc.cc_functions.sctp_cwnd_socket_option) (stcb, 1, cc_opt);
3584 SCTP_TCB_UNLOCK(stcb);
3586 SCTP_INP_RUNLOCK(inp);
3591 if (stcb->asoc.cc_functions.sctp_cwnd_socket_option == NULL) {
3594 error = (*stcb->asoc.cc_functions.sctp_cwnd_socket_option) (stcb, 1,
3597 SCTP_TCB_UNLOCK(stcb);
3601 case SCTP_PLUGGABLE_SS:
3603 struct sctp_assoc_value *av;
3605 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
3606 if ((av->assoc_value != SCTP_SS_DEFAULT) &&
3607 (av->assoc_value != SCTP_SS_ROUND_ROBIN) &&
3608 (av->assoc_value != SCTP_SS_ROUND_ROBIN_PACKET) &&
3609 (av->assoc_value != SCTP_SS_PRIORITY) &&
3610 (av->assoc_value != SCTP_SS_FAIR_BANDWITH) &&
3611 (av->assoc_value != SCTP_SS_FIRST_COME)) {
3612 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3616 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
3618 stcb->asoc.ss_functions.sctp_ss_clear(stcb, &stcb->asoc, 1, 1);
3619 stcb->asoc.ss_functions = sctp_ss_functions[av->assoc_value];
3620 stcb->asoc.stream_scheduling_module = av->assoc_value;
3621 stcb->asoc.ss_functions.sctp_ss_init(stcb, &stcb->asoc, 1);
3622 SCTP_TCB_UNLOCK(stcb);
3624 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3625 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3626 (av->assoc_id == SCTP_FUTURE_ASSOC) ||
3627 (av->assoc_id == SCTP_ALL_ASSOC)) {
3628 SCTP_INP_WLOCK(inp);
3629 inp->sctp_ep.sctp_default_ss_module = av->assoc_value;
3630 SCTP_INP_WUNLOCK(inp);
3632 if ((av->assoc_id == SCTP_CURRENT_ASSOC) ||
3633 (av->assoc_id == SCTP_ALL_ASSOC)) {
3634 SCTP_INP_RLOCK(inp);
3635 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
3636 SCTP_TCB_LOCK(stcb);
3637 stcb->asoc.ss_functions.sctp_ss_clear(stcb, &stcb->asoc, 1, 1);
3638 stcb->asoc.ss_functions = sctp_ss_functions[av->assoc_value];
3639 stcb->asoc.stream_scheduling_module = av->assoc_value;
3640 stcb->asoc.ss_functions.sctp_ss_init(stcb, &stcb->asoc, 1);
3641 SCTP_TCB_UNLOCK(stcb);
3643 SCTP_INP_RUNLOCK(inp);
3650 struct sctp_stream_value *av;
3652 SCTP_CHECK_AND_CAST(av, optval, struct sctp_stream_value, optsize);
3653 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
3655 if (stcb->asoc.ss_functions.sctp_ss_set_value(stcb, &stcb->asoc, &stcb->asoc.strmout[av->stream_id],
3656 av->stream_value) < 0) {
3657 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3660 SCTP_TCB_UNLOCK(stcb);
3662 if (av->assoc_id == SCTP_CURRENT_ASSOC) {
3663 SCTP_INP_RLOCK(inp);
3664 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
3665 SCTP_TCB_LOCK(stcb);
3666 stcb->asoc.ss_functions.sctp_ss_set_value(stcb,
3668 &stcb->asoc.strmout[av->stream_id],
3670 SCTP_TCB_UNLOCK(stcb);
3672 SCTP_INP_RUNLOCK(inp);
3676 * Can't set stream value without
3679 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3685 case SCTP_CLR_STAT_LOG:
3686 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EOPNOTSUPP);
3691 struct sctp_assoc_value *av;
3693 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
3694 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
3697 stcb->asoc.context = av->assoc_value;
3698 SCTP_TCB_UNLOCK(stcb);
3700 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3701 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3702 (av->assoc_id == SCTP_FUTURE_ASSOC) ||
3703 (av->assoc_id == SCTP_ALL_ASSOC)) {
3704 SCTP_INP_WLOCK(inp);
3705 inp->sctp_context = av->assoc_value;
3706 SCTP_INP_WUNLOCK(inp);
3708 if ((av->assoc_id == SCTP_CURRENT_ASSOC) ||
3709 (av->assoc_id == SCTP_ALL_ASSOC)) {
3710 SCTP_INP_RLOCK(inp);
3711 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
3712 SCTP_TCB_LOCK(stcb);
3713 stcb->asoc.context = av->assoc_value;
3714 SCTP_TCB_UNLOCK(stcb);
3716 SCTP_INP_RUNLOCK(inp);
3723 uint32_t *default_vrfid;
3725 SCTP_CHECK_AND_CAST(default_vrfid, optval, uint32_t, optsize);
3726 if (*default_vrfid > SCTP_MAX_VRF_ID) {
3727 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3731 inp->def_vrf_id = *default_vrfid;
3734 case SCTP_DEL_VRF_ID:
3736 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EOPNOTSUPP);
3740 case SCTP_ADD_VRF_ID:
3742 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EOPNOTSUPP);
3746 case SCTP_DELAYED_SACK:
3748 struct sctp_sack_info *sack;
3750 SCTP_CHECK_AND_CAST(sack, optval, struct sctp_sack_info, optsize);
3751 SCTP_FIND_STCB(inp, stcb, sack->sack_assoc_id);
3752 if (sack->sack_delay) {
3753 if (sack->sack_delay > SCTP_MAX_SACK_DELAY)
3754 sack->sack_delay = SCTP_MAX_SACK_DELAY;
3755 if (MSEC_TO_TICKS(sack->sack_delay) < 1) {
3756 sack->sack_delay = TICKS_TO_MSEC(1);
3760 if (sack->sack_delay) {
3761 stcb->asoc.delayed_ack = sack->sack_delay;
3763 if (sack->sack_freq) {
3764 stcb->asoc.sack_freq = sack->sack_freq;
3766 SCTP_TCB_UNLOCK(stcb);
3768 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3769 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3770 (sack->sack_assoc_id == SCTP_FUTURE_ASSOC) ||
3771 (sack->sack_assoc_id == SCTP_ALL_ASSOC)) {
3772 SCTP_INP_WLOCK(inp);
3773 if (sack->sack_delay) {
3774 inp->sctp_ep.sctp_timeoutticks[SCTP_TIMER_RECV] = MSEC_TO_TICKS(sack->sack_delay);
3776 if (sack->sack_freq) {
3777 inp->sctp_ep.sctp_sack_freq = sack->sack_freq;
3779 SCTP_INP_WUNLOCK(inp);
3781 if ((sack->sack_assoc_id == SCTP_CURRENT_ASSOC) ||
3782 (sack->sack_assoc_id == SCTP_ALL_ASSOC)) {
3783 SCTP_INP_RLOCK(inp);
3784 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
3785 SCTP_TCB_LOCK(stcb);
3786 if (sack->sack_delay) {
3787 stcb->asoc.delayed_ack = sack->sack_delay;
3789 if (sack->sack_freq) {
3790 stcb->asoc.sack_freq = sack->sack_freq;
3792 SCTP_TCB_UNLOCK(stcb);
3794 SCTP_INP_RUNLOCK(inp);
3799 case SCTP_AUTH_CHUNK:
3801 struct sctp_authchunk *sauth;
3803 SCTP_CHECK_AND_CAST(sauth, optval, struct sctp_authchunk, optsize);
3805 SCTP_INP_WLOCK(inp);
3806 if (sctp_auth_add_chunk(sauth->sauth_chunk, inp->sctp_ep.local_auth_chunks)) {
3807 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3810 SCTP_INP_WUNLOCK(inp);
3815 struct sctp_authkey *sca;
3816 struct sctp_keyhead *shared_keys;
3817 sctp_sharedkey_t *shared_key;
3818 sctp_key_t *key = NULL;
3821 SCTP_CHECK_AND_CAST(sca, optval, struct sctp_authkey, optsize);
3822 if (sca->sca_keylength == 0) {
3823 size = optsize - sizeof(struct sctp_authkey);
3825 if (sca->sca_keylength + sizeof(struct sctp_authkey) <= optsize) {
3826 size = sca->sca_keylength;
3828 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3833 SCTP_FIND_STCB(inp, stcb, sca->sca_assoc_id);
3836 shared_keys = &stcb->asoc.shared_keys;
3837 /* clear the cached keys for this key id */
3838 sctp_clear_cachedkeys(stcb, sca->sca_keynumber);
3840 * create the new shared key and
3844 key = sctp_set_key(sca->sca_key, (uint32_t) size);
3846 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOMEM);
3848 SCTP_TCB_UNLOCK(stcb);
3852 shared_key = sctp_alloc_sharedkey();
3853 if (shared_key == NULL) {
3855 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOMEM);
3857 SCTP_TCB_UNLOCK(stcb);
3860 shared_key->key = key;
3861 shared_key->keyid = sca->sca_keynumber;
3862 error = sctp_insert_sharedkey(shared_keys, shared_key);
3863 SCTP_TCB_UNLOCK(stcb);
3865 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3866 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3867 (sca->sca_assoc_id == SCTP_FUTURE_ASSOC) ||
3868 (sca->sca_assoc_id == SCTP_ALL_ASSOC)) {
3869 SCTP_INP_WLOCK(inp);
3870 shared_keys = &inp->sctp_ep.shared_keys;
3872 * clear the cached keys on all
3873 * assocs for this key id
3875 sctp_clear_cachedkeys_ep(inp, sca->sca_keynumber);
3877 * create the new shared key and
3881 key = sctp_set_key(sca->sca_key, (uint32_t) size);
3883 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOMEM);
3885 SCTP_INP_WUNLOCK(inp);
3889 shared_key = sctp_alloc_sharedkey();
3890 if (shared_key == NULL) {
3892 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOMEM);
3894 SCTP_INP_WUNLOCK(inp);
3897 shared_key->key = key;
3898 shared_key->keyid = sca->sca_keynumber;
3899 error = sctp_insert_sharedkey(shared_keys, shared_key);
3900 SCTP_INP_WUNLOCK(inp);
3902 if ((sca->sca_assoc_id == SCTP_CURRENT_ASSOC) ||
3903 (sca->sca_assoc_id == SCTP_ALL_ASSOC)) {
3904 SCTP_INP_RLOCK(inp);
3905 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
3906 SCTP_TCB_LOCK(stcb);
3907 shared_keys = &stcb->asoc.shared_keys;
3909 * clear the cached keys for
3912 sctp_clear_cachedkeys(stcb, sca->sca_keynumber);
3914 * create the new shared key
3915 * and insert/replace it
3918 key = sctp_set_key(sca->sca_key, (uint32_t) size);
3920 SCTP_TCB_UNLOCK(stcb);
3924 shared_key = sctp_alloc_sharedkey();
3925 if (shared_key == NULL) {
3927 SCTP_TCB_UNLOCK(stcb);
3930 shared_key->key = key;
3931 shared_key->keyid = sca->sca_keynumber;
3932 error = sctp_insert_sharedkey(shared_keys, shared_key);
3933 SCTP_TCB_UNLOCK(stcb);
3935 SCTP_INP_RUNLOCK(inp);
3940 case SCTP_HMAC_IDENT:
3942 struct sctp_hmacalgo *shmac;
3943 sctp_hmaclist_t *hmaclist;
3947 SCTP_CHECK_AND_CAST(shmac, optval, struct sctp_hmacalgo, optsize);
3948 if (optsize < sizeof(struct sctp_hmacalgo) + shmac->shmac_number_of_idents * sizeof(uint16_t)) {
3949 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3953 hmaclist = sctp_alloc_hmaclist(shmac->shmac_number_of_idents);
3954 if (hmaclist == NULL) {
3955 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOMEM);
3959 for (i = 0; i < shmac->shmac_number_of_idents; i++) {
3960 hmacid = shmac->shmac_idents[i];
3961 if (sctp_auth_add_hmacid(hmaclist, hmacid)) {
3962 /* invalid HMACs were found */ ;
3963 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3965 sctp_free_hmaclist(hmaclist);
3966 goto sctp_set_hmac_done;
3969 for (i = 0; i < hmaclist->num_algo; i++) {
3970 if (hmaclist->hmac[i] == SCTP_AUTH_HMAC_ID_SHA1) {
3971 /* already in list */
3975 if (i == hmaclist->num_algo) {
3976 /* not found in list */
3977 sctp_free_hmaclist(hmaclist);
3978 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3982 /* set it on the endpoint */
3983 SCTP_INP_WLOCK(inp);
3984 if (inp->sctp_ep.local_hmacs)
3985 sctp_free_hmaclist(inp->sctp_ep.local_hmacs);
3986 inp->sctp_ep.local_hmacs = hmaclist;
3987 SCTP_INP_WUNLOCK(inp);
3991 case SCTP_AUTH_ACTIVE_KEY:
3993 struct sctp_authkeyid *scact;
3995 SCTP_CHECK_AND_CAST(scact, optval, struct sctp_authkeyid, optsize);
3996 SCTP_FIND_STCB(inp, stcb, scact->scact_assoc_id);
3998 /* set the active key on the right place */
4000 /* set the active key on the assoc */
4001 if (sctp_auth_setactivekey(stcb,
4002 scact->scact_keynumber)) {
4003 SCTP_LTRACE_ERR_RET(inp, NULL, NULL,
4004 SCTP_FROM_SCTP_USRREQ,
4008 SCTP_TCB_UNLOCK(stcb);
4010 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
4011 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
4012 (scact->scact_assoc_id == SCTP_FUTURE_ASSOC) ||
4013 (scact->scact_assoc_id == SCTP_ALL_ASSOC)) {
4014 SCTP_INP_WLOCK(inp);
4015 if (sctp_auth_setactivekey_ep(inp, scact->scact_keynumber)) {
4016 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4019 SCTP_INP_WUNLOCK(inp);
4021 if ((scact->scact_assoc_id == SCTP_CURRENT_ASSOC) ||
4022 (scact->scact_assoc_id == SCTP_ALL_ASSOC)) {
4023 SCTP_INP_RLOCK(inp);
4024 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
4025 SCTP_TCB_LOCK(stcb);
4026 sctp_auth_setactivekey(stcb, scact->scact_keynumber);
4027 SCTP_TCB_UNLOCK(stcb);
4029 SCTP_INP_RUNLOCK(inp);
4034 case SCTP_AUTH_DELETE_KEY:
4036 struct sctp_authkeyid *scdel;
4038 SCTP_CHECK_AND_CAST(scdel, optval, struct sctp_authkeyid, optsize);
4039 SCTP_FIND_STCB(inp, stcb, scdel->scact_assoc_id);
4041 /* delete the key from the right place */
4043 if (sctp_delete_sharedkey(stcb, scdel->scact_keynumber)) {
4044 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4047 SCTP_TCB_UNLOCK(stcb);
4049 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
4050 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
4051 (scdel->scact_assoc_id == SCTP_FUTURE_ASSOC) ||
4052 (scdel->scact_assoc_id == SCTP_ALL_ASSOC)) {
4053 SCTP_INP_WLOCK(inp);
4054 if (sctp_delete_sharedkey_ep(inp, scdel->scact_keynumber)) {
4055 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4058 SCTP_INP_WUNLOCK(inp);
4060 if ((scdel->scact_assoc_id == SCTP_CURRENT_ASSOC) ||
4061 (scdel->scact_assoc_id == SCTP_ALL_ASSOC)) {
4062 SCTP_INP_RLOCK(inp);
4063 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
4064 SCTP_TCB_LOCK(stcb);
4065 sctp_delete_sharedkey(stcb, scdel->scact_keynumber);
4066 SCTP_TCB_UNLOCK(stcb);
4068 SCTP_INP_RUNLOCK(inp);
4073 case SCTP_AUTH_DEACTIVATE_KEY:
4075 struct sctp_authkeyid *keyid;
4077 SCTP_CHECK_AND_CAST(keyid, optval, struct sctp_authkeyid, optsize);
4078 SCTP_FIND_STCB(inp, stcb, keyid->scact_assoc_id);
4080 /* deactivate the key from the right place */
4082 if (sctp_deact_sharedkey(stcb, keyid->scact_keynumber)) {
4083 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4086 SCTP_TCB_UNLOCK(stcb);
4088 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
4089 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
4090 (keyid->scact_assoc_id == SCTP_FUTURE_ASSOC) ||
4091 (keyid->scact_assoc_id == SCTP_ALL_ASSOC)) {
4092 SCTP_INP_WLOCK(inp);
4093 if (sctp_deact_sharedkey_ep(inp, keyid->scact_keynumber)) {
4094 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4097 SCTP_INP_WUNLOCK(inp);
4099 if ((keyid->scact_assoc_id == SCTP_CURRENT_ASSOC) ||
4100 (keyid->scact_assoc_id == SCTP_ALL_ASSOC)) {
4101 SCTP_INP_RLOCK(inp);
4102 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
4103 SCTP_TCB_LOCK(stcb);
4104 sctp_deact_sharedkey(stcb, keyid->scact_keynumber);
4105 SCTP_TCB_UNLOCK(stcb);
4107 SCTP_INP_RUNLOCK(inp);
4112 case SCTP_ENABLE_STREAM_RESET:
4114 struct sctp_assoc_value *av;
4116 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
4117 if (av->assoc_value & (~SCTP_ENABLE_VALUE_MASK)) {
4118 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4122 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
4124 stcb->asoc.local_strreset_support = (uint8_t) av->assoc_value;
4125 SCTP_TCB_UNLOCK(stcb);
4127 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
4128 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
4129 (av->assoc_id == SCTP_FUTURE_ASSOC) ||
4130 (av->assoc_id == SCTP_ALL_ASSOC)) {
4131 SCTP_INP_WLOCK(inp);
4132 inp->local_strreset_support = (uint8_t) av->assoc_value;
4133 SCTP_INP_WUNLOCK(inp);
4135 if ((av->assoc_id == SCTP_CURRENT_ASSOC) ||
4136 (av->assoc_id == SCTP_ALL_ASSOC)) {
4137 SCTP_INP_RLOCK(inp);
4138 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
4139 SCTP_TCB_LOCK(stcb);
4140 stcb->asoc.local_strreset_support = (uint8_t) av->assoc_value;
4141 SCTP_TCB_UNLOCK(stcb);
4143 SCTP_INP_RUNLOCK(inp);
4148 case SCTP_RESET_STREAMS:
4150 struct sctp_reset_streams *strrst;
4151 int i, send_out = 0;
4154 SCTP_CHECK_AND_CAST(strrst, optval, struct sctp_reset_streams, optsize);
4155 SCTP_FIND_STCB(inp, stcb, strrst->srs_assoc_id);
4157 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOENT);
4161 if (stcb->asoc.peer_supports_strreset == 0) {
4163 * Peer does not support the chunk type.
4165 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EOPNOTSUPP);
4167 SCTP_TCB_UNLOCK(stcb);
4170 if (stcb->asoc.stream_reset_outstanding) {
4171 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EALREADY);
4173 SCTP_TCB_UNLOCK(stcb);
4176 if (strrst->srs_flags & SCTP_STREAM_RESET_INCOMING) {
4179 if (strrst->srs_flags & SCTP_STREAM_RESET_OUTGOING) {
4182 if ((send_in == 0) && (send_out == 0)) {
4183 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4185 SCTP_TCB_UNLOCK(stcb);
4188 for (i = 0; i < strrst->srs_number_streams; i++) {
4190 (strrst->srs_stream_list[i] > stcb->asoc.streamincnt)) {
4191 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4196 (strrst->srs_stream_list[i] > stcb->asoc.streamoutcnt)) {
4197 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4203 SCTP_TCB_UNLOCK(stcb);
4206 error = sctp_send_str_reset_req(stcb, strrst->srs_number_streams,
4207 strrst->srs_stream_list,
4208 send_out, send_in, 0, 0, 0, 0, 0);
4210 sctp_chunk_output(inp, stcb, SCTP_OUTPUT_FROM_STRRST_REQ, SCTP_SO_LOCKED);
4211 SCTP_TCB_UNLOCK(stcb);
4214 case SCTP_ADD_STREAMS:
4216 struct sctp_add_streams *stradd;
4217 uint8_t addstream = 0;
4218 uint16_t add_o_strmcnt = 0;
4219 uint16_t add_i_strmcnt = 0;
4221 SCTP_CHECK_AND_CAST(stradd, optval, struct sctp_add_streams, optsize);
4222 SCTP_FIND_STCB(inp, stcb, stradd->sas_assoc_id);
4224 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOENT);
4228 if (stcb->asoc.peer_supports_strreset == 0) {
4230 * Peer does not support the chunk type.
4232 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EOPNOTSUPP);
4234 SCTP_TCB_UNLOCK(stcb);
4237 if (stcb->asoc.stream_reset_outstanding) {
4238 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EALREADY);
4240 SCTP_TCB_UNLOCK(stcb);
4243 if ((stradd->sas_outstrms == 0) &&
4244 (stradd->sas_instrms == 0)) {
4248 if (stradd->sas_outstrms) {
4250 /* We allocate here */
4251 add_o_strmcnt = stradd->sas_outstrms;
4252 if ((((int)add_o_strmcnt) + ((int)stcb->asoc.streamoutcnt)) > 0x0000ffff) {
4253 /* You can't have more than 64k */
4258 if (stradd->sas_instrms) {
4263 * We allocate inside
4264 * sctp_send_str_reset_req()
4266 add_i_strmcnt = stradd->sas_instrms;
4267 cnt = add_i_strmcnt;
4268 cnt += stcb->asoc.streamincnt;
4269 if (cnt > 0x0000ffff) {
4270 /* You can't have more than 64k */
4274 if (cnt > (int)stcb->asoc.max_inbound_streams) {
4275 /* More than you are allowed */
4280 error = sctp_send_str_reset_req(stcb, 0, NULL, 0, 0, 0, addstream, add_o_strmcnt, add_i_strmcnt, 0);
4281 sctp_chunk_output(inp, stcb, SCTP_OUTPUT_FROM_STRRST_REQ, SCTP_SO_LOCKED);
4283 SCTP_TCB_UNLOCK(stcb);
4286 case SCTP_RESET_ASSOC:
4290 SCTP_CHECK_AND_CAST(value, optval, uint32_t, optsize);
4291 SCTP_FIND_STCB(inp, stcb, (sctp_assoc_t) * value);
4293 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOENT);
4297 if (stcb->asoc.peer_supports_strreset == 0) {
4299 * Peer does not support the chunk type.
4301 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EOPNOTSUPP);
4303 SCTP_TCB_UNLOCK(stcb);
4306 if (stcb->asoc.stream_reset_outstanding) {
4307 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EALREADY);
4309 SCTP_TCB_UNLOCK(stcb);
4312 error = sctp_send_str_reset_req(stcb, 0, NULL, 0, 0, 1, 0, 0, 0, 0);
4313 sctp_chunk_output(inp, stcb, SCTP_OUTPUT_FROM_STRRST_REQ, SCTP_SO_LOCKED);
4314 SCTP_TCB_UNLOCK(stcb);
4317 case SCTP_CONNECT_X:
4318 if (optsize < (sizeof(int) + sizeof(struct sockaddr_in))) {
4319 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4323 error = sctp_do_connect_x(so, inp, optval, optsize, p, 0);
4325 case SCTP_CONNECT_X_DELAYED:
4326 if (optsize < (sizeof(int) + sizeof(struct sockaddr_in))) {
4327 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4331 error = sctp_do_connect_x(so, inp, optval, optsize, p, 1);
4333 case SCTP_CONNECT_X_COMPLETE:
4335 struct sockaddr *sa;
4336 struct sctp_nets *net;
4338 /* FIXME MT: check correct? */
4339 SCTP_CHECK_AND_CAST(sa, optval, struct sockaddr, optsize);
4342 if (inp->sctp_flags & SCTP_PCB_FLAGS_CONNECTED) {
4343 SCTP_INP_RLOCK(inp);
4344 stcb = LIST_FIRST(&inp->sctp_asoc_list);
4346 SCTP_TCB_LOCK(stcb);
4347 net = sctp_findnet(stcb, sa);
4349 SCTP_INP_RUNLOCK(inp);
4352 * We increment here since
4353 * sctp_findassociation_ep_addr() wil do a
4354 * decrement if it finds the stcb as long as
4355 * the locked tcb (last argument) is NOT a
4358 SCTP_INP_INCR_REF(inp);
4359 stcb = sctp_findassociation_ep_addr(&inp, sa, &net, NULL, NULL);
4361 SCTP_INP_DECR_REF(inp);
4366 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOENT);
4370 if (stcb->asoc.delayed_connection == 1) {
4371 stcb->asoc.delayed_connection = 0;
4372 (void)SCTP_GETTIME_TIMEVAL(&stcb->asoc.time_entered);
4373 sctp_timer_stop(SCTP_TIMER_TYPE_INIT, inp, stcb,
4374 stcb->asoc.primary_destination,
4375 SCTP_FROM_SCTP_USRREQ + SCTP_LOC_9);
4376 sctp_send_initiate(inp, stcb, SCTP_SO_LOCKED);
4379 * already expired or did not use delayed
4382 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EALREADY);
4385 SCTP_TCB_UNLOCK(stcb);
4388 case SCTP_MAX_BURST:
4390 struct sctp_assoc_value *av;
4392 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
4393 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
4396 stcb->asoc.max_burst = av->assoc_value;
4397 SCTP_TCB_UNLOCK(stcb);
4399 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
4400 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
4401 (av->assoc_id == SCTP_FUTURE_ASSOC) ||
4402 (av->assoc_id == SCTP_ALL_ASSOC)) {
4403 SCTP_INP_WLOCK(inp);
4404 inp->sctp_ep.max_burst = av->assoc_value;
4405 SCTP_INP_WUNLOCK(inp);
4407 if ((av->assoc_id == SCTP_CURRENT_ASSOC) ||
4408 (av->assoc_id == SCTP_ALL_ASSOC)) {
4409 SCTP_INP_RLOCK(inp);
4410 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
4411 SCTP_TCB_LOCK(stcb);
4412 stcb->asoc.max_burst = av->assoc_value;
4413 SCTP_TCB_UNLOCK(stcb);
4415 SCTP_INP_RUNLOCK(inp);
4422 struct sctp_assoc_value *av;
4425 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
4426 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
4428 if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) {
4429 ovh = SCTP_MED_OVERHEAD;
4431 ovh = SCTP_MED_V4_OVERHEAD;
4434 if (av->assoc_value) {
4435 stcb->asoc.sctp_frag_point = (av->assoc_value + ovh);
4437 stcb->asoc.sctp_frag_point = SCTP_DEFAULT_MAXSEGMENT;
4439 SCTP_TCB_UNLOCK(stcb);
4441 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
4442 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
4443 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
4444 SCTP_INP_WLOCK(inp);
4446 * FIXME MT: I think this is not in
4447 * tune with the API ID
4449 if (av->assoc_value) {
4450 inp->sctp_frag_point = (av->assoc_value + ovh);
4452 inp->sctp_frag_point = SCTP_DEFAULT_MAXSEGMENT;
4454 SCTP_INP_WUNLOCK(inp);
4456 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4464 struct sctp_event_subscribe *events;
4466 SCTP_CHECK_AND_CAST(events, optval, struct sctp_event_subscribe, optsize);
4468 SCTP_INP_WLOCK(inp);
4469 if (events->sctp_data_io_event) {
4470 sctp_feature_on(inp, SCTP_PCB_FLAGS_RECVDATAIOEVNT);
4472 sctp_feature_off(inp, SCTP_PCB_FLAGS_RECVDATAIOEVNT);
4475 if (events->sctp_association_event) {
4476 sctp_feature_on(inp, SCTP_PCB_FLAGS_RECVASSOCEVNT);
4478 sctp_feature_off(inp, SCTP_PCB_FLAGS_RECVASSOCEVNT);
4481 if (events->sctp_address_event) {
4482 sctp_feature_on(inp, SCTP_PCB_FLAGS_RECVPADDREVNT);
4484 sctp_feature_off(inp, SCTP_PCB_FLAGS_RECVPADDREVNT);
4487 if (events->sctp_send_failure_event) {
4488 sctp_feature_on(inp, SCTP_PCB_FLAGS_RECVSENDFAILEVNT);
4490 sctp_feature_off(inp, SCTP_PCB_FLAGS_RECVSENDFAILEVNT);
4493 if (events->sctp_peer_error_event) {
4494 sctp_feature_on(inp, SCTP_PCB_FLAGS_RECVPEERERR);
4496 sctp_feature_off(inp, SCTP_PCB_FLAGS_RECVPEERERR);
4499 if (events->sctp_shutdown_event) {
4500 sctp_feature_on(inp, SCTP_PCB_FLAGS_RECVSHUTDOWNEVNT);
4502 sctp_feature_off(inp, SCTP_PCB_FLAGS_RECVSHUTDOWNEVNT);
4505 if (events->sctp_partial_delivery_event) {
4506 sctp_feature_on(inp, SCTP_PCB_FLAGS_PDAPIEVNT);
4508 sctp_feature_off(inp, SCTP_PCB_FLAGS_PDAPIEVNT);
4511 if (events->sctp_adaptation_layer_event) {
4512 sctp_feature_on(inp, SCTP_PCB_FLAGS_ADAPTATIONEVNT);
4514 sctp_feature_off(inp, SCTP_PCB_FLAGS_ADAPTATIONEVNT);
4517 if (events->sctp_authentication_event) {
4518 sctp_feature_on(inp, SCTP_PCB_FLAGS_AUTHEVNT);
4520 sctp_feature_off(inp, SCTP_PCB_FLAGS_AUTHEVNT);
4523 if (events->sctp_sender_dry_event) {
4524 sctp_feature_on(inp, SCTP_PCB_FLAGS_DRYEVNT);
4526 sctp_feature_off(inp, SCTP_PCB_FLAGS_DRYEVNT);
4529 if (events->sctp_stream_reset_event) {
4530 sctp_feature_on(inp, SCTP_PCB_FLAGS_STREAM_RESETEVNT);
4532 sctp_feature_off(inp, SCTP_PCB_FLAGS_STREAM_RESETEVNT);
4534 SCTP_INP_WUNLOCK(inp);
4536 SCTP_INP_RLOCK(inp);
4537 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
4538 SCTP_TCB_LOCK(stcb);
4539 if (events->sctp_association_event) {
4540 sctp_stcb_feature_on(inp, stcb, SCTP_PCB_FLAGS_RECVASSOCEVNT);
4542 sctp_stcb_feature_off(inp, stcb, SCTP_PCB_FLAGS_RECVASSOCEVNT);
4544 if (events->sctp_address_event) {
4545 sctp_stcb_feature_on(inp, stcb, SCTP_PCB_FLAGS_RECVPADDREVNT);
4547 sctp_stcb_feature_off(inp, stcb, SCTP_PCB_FLAGS_RECVPADDREVNT);
4549 if (events->sctp_send_failure_event) {
4550 sctp_stcb_feature_on(inp, stcb, SCTP_PCB_FLAGS_RECVSENDFAILEVNT);
4552 sctp_stcb_feature_off(inp, stcb, SCTP_PCB_FLAGS_RECVSENDFAILEVNT);
4554 if (events->sctp_peer_error_event) {
4555 sctp_stcb_feature_on(inp, stcb, SCTP_PCB_FLAGS_RECVPEERERR);
4557 sctp_stcb_feature_off(inp, stcb, SCTP_PCB_FLAGS_RECVPEERERR);
4559 if (events->sctp_shutdown_event) {
4560 sctp_stcb_feature_on(inp, stcb, SCTP_PCB_FLAGS_RECVSHUTDOWNEVNT);
4562 sctp_stcb_feature_off(inp, stcb, SCTP_PCB_FLAGS_RECVSHUTDOWNEVNT);
4564 if (events->sctp_partial_delivery_event) {
4565 sctp_stcb_feature_on(inp, stcb, SCTP_PCB_FLAGS_PDAPIEVNT);
4567 sctp_stcb_feature_off(inp, stcb, SCTP_PCB_FLAGS_PDAPIEVNT);
4569 if (events->sctp_adaptation_layer_event) {
4570 sctp_stcb_feature_on(inp, stcb, SCTP_PCB_FLAGS_ADAPTATIONEVNT);
4572 sctp_stcb_feature_off(inp, stcb, SCTP_PCB_FLAGS_ADAPTATIONEVNT);
4574 if (events->sctp_authentication_event) {
4575 sctp_stcb_feature_on(inp, stcb, SCTP_PCB_FLAGS_AUTHEVNT);
4577 sctp_stcb_feature_off(inp, stcb, SCTP_PCB_FLAGS_AUTHEVNT);
4579 if (events->sctp_sender_dry_event) {
4580 sctp_stcb_feature_on(inp, stcb, SCTP_PCB_FLAGS_DRYEVNT);
4582 sctp_stcb_feature_off(inp, stcb, SCTP_PCB_FLAGS_DRYEVNT);
4584 if (events->sctp_stream_reset_event) {
4585 sctp_stcb_feature_on(inp, stcb, SCTP_PCB_FLAGS_STREAM_RESETEVNT);
4587 sctp_stcb_feature_off(inp, stcb, SCTP_PCB_FLAGS_STREAM_RESETEVNT);
4589 SCTP_TCB_UNLOCK(stcb);
4592 * Send up the sender dry event only for 1-to-1
4595 if (events->sctp_sender_dry_event) {
4596 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
4597 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL)) {
4598 stcb = LIST_FIRST(&inp->sctp_asoc_list);
4600 SCTP_TCB_LOCK(stcb);
4601 if (TAILQ_EMPTY(&stcb->asoc.send_queue) &&
4602 TAILQ_EMPTY(&stcb->asoc.sent_queue) &&
4603 (stcb->asoc.stream_queue_cnt == 0)) {
4604 sctp_ulp_notify(SCTP_NOTIFY_SENDER_DRY, stcb, 0, NULL, SCTP_SO_LOCKED);
4606 SCTP_TCB_UNLOCK(stcb);
4610 SCTP_INP_RUNLOCK(inp);
4613 case SCTP_ADAPTATION_LAYER:
4615 struct sctp_setadaptation *adap_bits;
4617 SCTP_CHECK_AND_CAST(adap_bits, optval, struct sctp_setadaptation, optsize);
4618 SCTP_INP_WLOCK(inp);
4619 inp->sctp_ep.adaptation_layer_indicator = adap_bits->ssb_adaptation_ind;
4620 inp->sctp_ep.adaptation_layer_indicator_provided = 1;
4621 SCTP_INP_WUNLOCK(inp);
4625 case SCTP_SET_INITIAL_DBG_SEQ:
4629 SCTP_CHECK_AND_CAST(vvv, optval, uint32_t, optsize);
4630 SCTP_INP_WLOCK(inp);
4631 inp->sctp_ep.initial_sequence_debug = *vvv;
4632 SCTP_INP_WUNLOCK(inp);
4636 case SCTP_DEFAULT_SEND_PARAM:
4638 struct sctp_sndrcvinfo *s_info;
4640 SCTP_CHECK_AND_CAST(s_info, optval, struct sctp_sndrcvinfo, optsize);
4641 SCTP_FIND_STCB(inp, stcb, s_info->sinfo_assoc_id);
4644 if (s_info->sinfo_stream < stcb->asoc.streamoutcnt) {
4645 memcpy(&stcb->asoc.def_send, s_info, min(optsize, sizeof(stcb->asoc.def_send)));
4647 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4650 SCTP_TCB_UNLOCK(stcb);
4652 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
4653 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
4654 (s_info->sinfo_assoc_id == SCTP_FUTURE_ASSOC) ||
4655 (s_info->sinfo_assoc_id == SCTP_ALL_ASSOC)) {
4656 SCTP_INP_WLOCK(inp);
4657 memcpy(&inp->def_send, s_info, min(optsize, sizeof(inp->def_send)));
4658 SCTP_INP_WUNLOCK(inp);
4660 if ((s_info->sinfo_assoc_id == SCTP_CURRENT_ASSOC) ||
4661 (s_info->sinfo_assoc_id == SCTP_ALL_ASSOC)) {
4662 SCTP_INP_RLOCK(inp);
4663 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
4664 SCTP_TCB_LOCK(stcb);
4665 if (s_info->sinfo_stream < stcb->asoc.streamoutcnt) {
4666 memcpy(&stcb->asoc.def_send, s_info, min(optsize, sizeof(stcb->asoc.def_send)));
4668 SCTP_TCB_UNLOCK(stcb);
4670 SCTP_INP_RUNLOCK(inp);
4675 case SCTP_PEER_ADDR_PARAMS:
4677 struct sctp_paddrparams *paddrp;
4678 struct sctp_nets *net;
4680 SCTP_CHECK_AND_CAST(paddrp, optval, struct sctp_paddrparams, optsize);
4681 SCTP_FIND_STCB(inp, stcb, paddrp->spp_assoc_id);
4684 net = sctp_findnet(stcb, (struct sockaddr *)&paddrp->spp_address);
4687 * We increment here since
4688 * sctp_findassociation_ep_addr() wil do a
4689 * decrement if it finds the stcb as long as
4690 * the locked tcb (last argument) is NOT a
4693 SCTP_INP_INCR_REF(inp);
4694 stcb = sctp_findassociation_ep_addr(&inp,
4695 (struct sockaddr *)&paddrp->spp_address,
4698 SCTP_INP_DECR_REF(inp);
4701 if (stcb && (net == NULL)) {
4702 struct sockaddr *sa;
4704 sa = (struct sockaddr *)&paddrp->spp_address;
4706 if (sa->sa_family == AF_INET) {
4708 struct sockaddr_in *sin;
4710 sin = (struct sockaddr_in *)sa;
4711 if (sin->sin_addr.s_addr) {
4712 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4713 SCTP_TCB_UNLOCK(stcb);
4720 if (sa->sa_family == AF_INET6) {
4721 struct sockaddr_in6 *sin6;
4723 sin6 = (struct sockaddr_in6 *)sa;
4724 if (!IN6_IS_ADDR_UNSPECIFIED(&sin6->sin6_addr)) {
4725 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4726 SCTP_TCB_UNLOCK(stcb);
4733 error = EAFNOSUPPORT;
4734 SCTP_TCB_UNLOCK(stcb);
4735 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
4740 if ((paddrp->spp_flags & SPP_HB_ENABLE) && (paddrp->spp_flags & SPP_HB_DISABLE)) {
4742 SCTP_TCB_UNLOCK(stcb);
4743 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4746 if ((paddrp->spp_flags & SPP_PMTUD_ENABLE) && (paddrp->spp_flags & SPP_PMTUD_DISABLE)) {
4748 SCTP_TCB_UNLOCK(stcb);
4749 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4753 /************************TCB SPECIFIC SET ******************/
4755 * do we change the timer for HB, we run
4760 if (stcb->sctp_ep->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) {
4761 ovh = SCTP_MED_OVERHEAD;
4763 ovh = SCTP_MED_V4_OVERHEAD;
4766 /* network sets ? */
4768 /************************NET SPECIFIC SET ******************/
4769 if (paddrp->spp_flags & SPP_HB_DISABLE) {
4770 if (!(net->dest_state & SCTP_ADDR_UNCONFIRMED) &&
4771 !(net->dest_state & SCTP_ADDR_NOHB)) {
4772 sctp_timer_stop(SCTP_TIMER_TYPE_HEARTBEAT, inp, stcb, net,
4773 SCTP_FROM_SCTP_USRREQ + SCTP_LOC_10);
4775 net->dest_state |= SCTP_ADDR_NOHB;
4777 if (paddrp->spp_flags & SPP_HB_ENABLE) {
4778 if (paddrp->spp_hbinterval) {
4779 net->heart_beat_delay = paddrp->spp_hbinterval;
4780 } else if (paddrp->spp_flags & SPP_HB_TIME_IS_ZERO) {
4781 net->heart_beat_delay = 0;
4783 sctp_timer_stop(SCTP_TIMER_TYPE_HEARTBEAT, inp, stcb, net,
4784 SCTP_FROM_SCTP_USRREQ + SCTP_LOC_10);
4785 sctp_timer_start(SCTP_TIMER_TYPE_HEARTBEAT, inp, stcb, net);
4786 net->dest_state &= ~SCTP_ADDR_NOHB;
4788 if (paddrp->spp_flags & SPP_HB_DEMAND) {
4790 sctp_send_hb(stcb, net, SCTP_SO_LOCKED);
4791 sctp_chunk_output(inp, stcb, SCTP_OUTPUT_FROM_SOCKOPT, SCTP_SO_LOCKED);
4792 sctp_timer_start(SCTP_TIMER_TYPE_HEARTBEAT, inp, stcb, net);
4794 if ((paddrp->spp_flags & SPP_PMTUD_DISABLE) && (paddrp->spp_pathmtu >= SCTP_SMALLEST_PMTU)) {
4795 if (SCTP_OS_TIMER_PENDING(&net->pmtu_timer.timer)) {
4796 sctp_timer_stop(SCTP_TIMER_TYPE_PATHMTURAISE, inp, stcb, net,
4797 SCTP_FROM_SCTP_USRREQ + SCTP_LOC_10);
4799 net->dest_state |= SCTP_ADDR_NO_PMTUD;
4800 net->mtu = paddrp->spp_pathmtu + ovh;
4801 if (net->mtu < stcb->asoc.smallest_mtu) {
4802 sctp_pathmtu_adjustment(stcb, net->mtu);
4805 if (paddrp->spp_flags & SPP_PMTUD_ENABLE) {
4806 if (!SCTP_OS_TIMER_PENDING(&net->pmtu_timer.timer)) {
4807 sctp_timer_start(SCTP_TIMER_TYPE_PATHMTURAISE, inp, stcb, net);
4809 net->dest_state &= ~SCTP_ADDR_NO_PMTUD;
4811 if (paddrp->spp_pathmaxrxt) {
4812 if (net->dest_state & SCTP_ADDR_PF) {
4813 if (net->error_count > paddrp->spp_pathmaxrxt) {
4814 net->dest_state &= ~SCTP_ADDR_PF;
4817 if ((net->error_count <= paddrp->spp_pathmaxrxt) &&
4818 (net->error_count > net->pf_threshold)) {
4819 net->dest_state |= SCTP_ADDR_PF;
4820 sctp_send_hb(stcb, net, SCTP_SO_LOCKED);
4821 sctp_timer_stop(SCTP_TIMER_TYPE_HEARTBEAT, stcb->sctp_ep, stcb, net, SCTP_FROM_SCTP_TIMER + SCTP_LOC_3);
4822 sctp_timer_start(SCTP_TIMER_TYPE_HEARTBEAT, stcb->sctp_ep, stcb, net);
4825 if (net->dest_state & SCTP_ADDR_REACHABLE) {
4826 if (net->error_count > paddrp->spp_pathmaxrxt) {
4827 net->dest_state &= ~SCTP_ADDR_REACHABLE;
4828 sctp_ulp_notify(SCTP_NOTIFY_INTERFACE_DOWN, stcb, 0, net, SCTP_SO_LOCKED);
4831 if (net->error_count <= paddrp->spp_pathmaxrxt) {
4832 net->dest_state |= SCTP_ADDR_REACHABLE;
4833 sctp_ulp_notify(SCTP_NOTIFY_INTERFACE_UP, stcb, 0, net, SCTP_SO_LOCKED);
4836 net->failure_threshold = paddrp->spp_pathmaxrxt;
4838 if (paddrp->spp_flags & SPP_DSCP) {
4839 net->dscp = paddrp->spp_dscp & 0xfc;
4843 if (paddrp->spp_flags & SPP_IPV6_FLOWLABEL) {
4844 if (net->ro._l_addr.sa.sa_family == AF_INET6) {
4845 net->flowlabel = paddrp->spp_ipv6_flowlabel & 0x000fffff;
4846 net->flowlabel |= 0x80000000;
4851 /************************ASSOC ONLY -- NO NET SPECIFIC SET ******************/
4852 if (paddrp->spp_pathmaxrxt) {
4853 stcb->asoc.def_net_failure = paddrp->spp_pathmaxrxt;
4854 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
4855 if (net->dest_state & SCTP_ADDR_PF) {
4856 if (net->error_count > paddrp->spp_pathmaxrxt) {
4857 net->dest_state &= ~SCTP_ADDR_PF;
4860 if ((net->error_count <= paddrp->spp_pathmaxrxt) &&
4861 (net->error_count > net->pf_threshold)) {
4862 net->dest_state |= SCTP_ADDR_PF;
4863 sctp_send_hb(stcb, net, SCTP_SO_LOCKED);
4864 sctp_timer_stop(SCTP_TIMER_TYPE_HEARTBEAT, stcb->sctp_ep, stcb, net, SCTP_FROM_SCTP_TIMER + SCTP_LOC_3);
4865 sctp_timer_start(SCTP_TIMER_TYPE_HEARTBEAT, stcb->sctp_ep, stcb, net);
4868 if (net->dest_state & SCTP_ADDR_REACHABLE) {
4869 if (net->error_count > paddrp->spp_pathmaxrxt) {
4870 net->dest_state &= ~SCTP_ADDR_REACHABLE;
4871 sctp_ulp_notify(SCTP_NOTIFY_INTERFACE_DOWN, stcb, 0, net, SCTP_SO_LOCKED);
4874 if (net->error_count <= paddrp->spp_pathmaxrxt) {
4875 net->dest_state |= SCTP_ADDR_REACHABLE;
4876 sctp_ulp_notify(SCTP_NOTIFY_INTERFACE_UP, stcb, 0, net, SCTP_SO_LOCKED);
4879 net->failure_threshold = paddrp->spp_pathmaxrxt;
4882 if (paddrp->spp_flags & SPP_HB_ENABLE) {
4883 if (paddrp->spp_hbinterval) {
4884 stcb->asoc.heart_beat_delay = paddrp->spp_hbinterval;
4885 } else if (paddrp->spp_flags & SPP_HB_TIME_IS_ZERO) {
4886 stcb->asoc.heart_beat_delay = 0;
4888 /* Turn back on the timer */
4889 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
4890 if (paddrp->spp_hbinterval) {
4891 net->heart_beat_delay = paddrp->spp_hbinterval;
4892 } else if (paddrp->spp_flags & SPP_HB_TIME_IS_ZERO) {
4893 net->heart_beat_delay = 0;
4895 if (net->dest_state & SCTP_ADDR_NOHB) {
4896 net->dest_state &= ~SCTP_ADDR_NOHB;
4898 sctp_timer_stop(SCTP_TIMER_TYPE_HEARTBEAT, inp, stcb, net,
4899 SCTP_FROM_SCTP_USRREQ + SCTP_LOC_10);
4900 sctp_timer_start(SCTP_TIMER_TYPE_HEARTBEAT, inp, stcb, net);
4902 sctp_stcb_feature_off(inp, stcb, SCTP_PCB_FLAGS_DONOT_HEARTBEAT);
4904 if (paddrp->spp_flags & SPP_HB_DISABLE) {
4905 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
4906 if (!(net->dest_state & SCTP_ADDR_NOHB)) {
4907 net->dest_state |= SCTP_ADDR_NOHB;
4908 if (!(net->dest_state & SCTP_ADDR_UNCONFIRMED)) {
4909 sctp_timer_stop(SCTP_TIMER_TYPE_HEARTBEAT, inp, stcb, net, SCTP_FROM_SCTP_USRREQ + SCTP_LOC_10);
4913 sctp_stcb_feature_on(inp, stcb, SCTP_PCB_FLAGS_DONOT_HEARTBEAT);
4915 if ((paddrp->spp_flags & SPP_PMTUD_DISABLE) && (paddrp->spp_pathmtu >= SCTP_SMALLEST_PMTU)) {
4916 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
4917 if (SCTP_OS_TIMER_PENDING(&net->pmtu_timer.timer)) {
4918 sctp_timer_stop(SCTP_TIMER_TYPE_PATHMTURAISE, inp, stcb, net,
4919 SCTP_FROM_SCTP_USRREQ + SCTP_LOC_10);
4921 net->dest_state |= SCTP_ADDR_NO_PMTUD;
4922 net->mtu = paddrp->spp_pathmtu + ovh;
4923 if (net->mtu < stcb->asoc.smallest_mtu) {
4924 sctp_pathmtu_adjustment(stcb, net->mtu);
4927 sctp_stcb_feature_on(inp, stcb, SCTP_PCB_FLAGS_DO_NOT_PMTUD);
4929 if (paddrp->spp_flags & SPP_PMTUD_ENABLE) {
4930 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
4931 if (!SCTP_OS_TIMER_PENDING(&net->pmtu_timer.timer)) {
4932 sctp_timer_start(SCTP_TIMER_TYPE_PATHMTURAISE, inp, stcb, net);
4934 net->dest_state &= ~SCTP_ADDR_NO_PMTUD;
4936 sctp_stcb_feature_off(inp, stcb, SCTP_PCB_FLAGS_DO_NOT_PMTUD);
4938 if (paddrp->spp_flags & SPP_DSCP) {
4939 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
4940 net->dscp = paddrp->spp_dscp & 0xfc;
4943 stcb->asoc.default_dscp = paddrp->spp_dscp & 0xfc;
4944 stcb->asoc.default_dscp |= 0x01;
4947 if (paddrp->spp_flags & SPP_IPV6_FLOWLABEL) {
4948 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
4949 if (net->ro._l_addr.sa.sa_family == AF_INET6) {
4950 net->flowlabel = paddrp->spp_ipv6_flowlabel & 0x000fffff;
4951 net->flowlabel |= 0x80000000;
4954 stcb->asoc.default_flowlabel = paddrp->spp_ipv6_flowlabel & 0x000fffff;
4955 stcb->asoc.default_flowlabel |= 0x80000000;
4959 SCTP_TCB_UNLOCK(stcb);
4961 /************************NO TCB, SET TO default stuff ******************/
4962 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
4963 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
4964 (paddrp->spp_assoc_id == SCTP_FUTURE_ASSOC)) {
4965 SCTP_INP_WLOCK(inp);
4967 * For the TOS/FLOWLABEL stuff you
4968 * set it with the options on the
4971 if (paddrp->spp_pathmaxrxt) {
4972 inp->sctp_ep.def_net_failure = paddrp->spp_pathmaxrxt;
4974 if (paddrp->spp_flags & SPP_HB_TIME_IS_ZERO)
4975 inp->sctp_ep.sctp_timeoutticks[SCTP_TIMER_HEARTBEAT] = 0;
4976 else if (paddrp->spp_hbinterval) {
4977 if (paddrp->spp_hbinterval > SCTP_MAX_HB_INTERVAL)
4978 paddrp->spp_hbinterval = SCTP_MAX_HB_INTERVAL;
4979 inp->sctp_ep.sctp_timeoutticks[SCTP_TIMER_HEARTBEAT] = MSEC_TO_TICKS(paddrp->spp_hbinterval);
4981 if (paddrp->spp_flags & SPP_HB_ENABLE) {
4982 if (paddrp->spp_flags & SPP_HB_TIME_IS_ZERO) {
4983 inp->sctp_ep.sctp_timeoutticks[SCTP_TIMER_HEARTBEAT] = 0;
4984 } else if (paddrp->spp_hbinterval) {
4985 inp->sctp_ep.sctp_timeoutticks[SCTP_TIMER_HEARTBEAT] = MSEC_TO_TICKS(paddrp->spp_hbinterval);
4987 sctp_feature_off(inp, SCTP_PCB_FLAGS_DONOT_HEARTBEAT);
4988 } else if (paddrp->spp_flags & SPP_HB_DISABLE) {
4989 sctp_feature_on(inp, SCTP_PCB_FLAGS_DONOT_HEARTBEAT);
4991 if (paddrp->spp_flags & SPP_PMTUD_ENABLE) {
4992 sctp_feature_off(inp, SCTP_PCB_FLAGS_DO_NOT_PMTUD);
4993 } else if (paddrp->spp_flags & SPP_PMTUD_DISABLE) {
4994 sctp_feature_on(inp, SCTP_PCB_FLAGS_DO_NOT_PMTUD);
4996 if (paddrp->spp_flags & SPP_DSCP) {
4997 inp->sctp_ep.default_dscp = paddrp->spp_dscp & 0xfc;
4998 inp->sctp_ep.default_dscp |= 0x01;
5001 if (paddrp->spp_flags & SPP_IPV6_FLOWLABEL) {
5002 if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) {
5003 inp->sctp_ep.default_flowlabel = paddrp->spp_ipv6_flowlabel & 0x000fffff;
5004 inp->sctp_ep.default_flowlabel |= 0x80000000;
5008 SCTP_INP_WUNLOCK(inp);
5010 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5018 struct sctp_rtoinfo *srto;
5019 uint32_t new_init, new_min, new_max;
5021 SCTP_CHECK_AND_CAST(srto, optval, struct sctp_rtoinfo, optsize);
5022 SCTP_FIND_STCB(inp, stcb, srto->srto_assoc_id);
5025 if (srto->srto_initial)
5026 new_init = srto->srto_initial;
5028 new_init = stcb->asoc.initial_rto;
5030 new_max = srto->srto_max;
5032 new_max = stcb->asoc.maxrto;
5034 new_min = srto->srto_min;
5036 new_min = stcb->asoc.minrto;
5037 if ((new_min <= new_init) && (new_init <= new_max)) {
5038 stcb->asoc.initial_rto = new_init;
5039 stcb->asoc.maxrto = new_max;
5040 stcb->asoc.minrto = new_min;
5042 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5045 SCTP_TCB_UNLOCK(stcb);
5047 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
5048 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
5049 (srto->srto_assoc_id == SCTP_FUTURE_ASSOC)) {
5050 SCTP_INP_WLOCK(inp);
5051 if (srto->srto_initial)
5052 new_init = srto->srto_initial;
5054 new_init = inp->sctp_ep.initial_rto;
5056 new_max = srto->srto_max;
5058 new_max = inp->sctp_ep.sctp_maxrto;
5060 new_min = srto->srto_min;
5062 new_min = inp->sctp_ep.sctp_minrto;
5063 if ((new_min <= new_init) && (new_init <= new_max)) {
5064 inp->sctp_ep.initial_rto = new_init;
5065 inp->sctp_ep.sctp_maxrto = new_max;
5066 inp->sctp_ep.sctp_minrto = new_min;
5068 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5071 SCTP_INP_WUNLOCK(inp);
5073 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5079 case SCTP_ASSOCINFO:
5081 struct sctp_assocparams *sasoc;
5083 SCTP_CHECK_AND_CAST(sasoc, optval, struct sctp_assocparams, optsize);
5084 SCTP_FIND_STCB(inp, stcb, sasoc->sasoc_assoc_id);
5085 if (sasoc->sasoc_cookie_life) {
5086 /* boundary check the cookie life */
5087 if (sasoc->sasoc_cookie_life < 1000)
5088 sasoc->sasoc_cookie_life = 1000;
5089 if (sasoc->sasoc_cookie_life > SCTP_MAX_COOKIE_LIFE) {
5090 sasoc->sasoc_cookie_life = SCTP_MAX_COOKIE_LIFE;
5094 if (sasoc->sasoc_asocmaxrxt)
5095 stcb->asoc.max_send_times = sasoc->sasoc_asocmaxrxt;
5096 if (sasoc->sasoc_cookie_life) {
5097 stcb->asoc.cookie_life = MSEC_TO_TICKS(sasoc->sasoc_cookie_life);
5099 SCTP_TCB_UNLOCK(stcb);
5101 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
5102 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
5103 (sasoc->sasoc_assoc_id == SCTP_FUTURE_ASSOC)) {
5104 SCTP_INP_WLOCK(inp);
5105 if (sasoc->sasoc_asocmaxrxt)
5106 inp->sctp_ep.max_send_times = sasoc->sasoc_asocmaxrxt;
5107 if (sasoc->sasoc_cookie_life) {
5108 inp->sctp_ep.def_cookie_life = MSEC_TO_TICKS(sasoc->sasoc_cookie_life);
5110 SCTP_INP_WUNLOCK(inp);
5112 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5120 struct sctp_initmsg *sinit;
5122 SCTP_CHECK_AND_CAST(sinit, optval, struct sctp_initmsg, optsize);
5123 SCTP_INP_WLOCK(inp);
5124 if (sinit->sinit_num_ostreams)
5125 inp->sctp_ep.pre_open_stream_count = sinit->sinit_num_ostreams;
5127 if (sinit->sinit_max_instreams)
5128 inp->sctp_ep.max_open_streams_intome = sinit->sinit_max_instreams;
5130 if (sinit->sinit_max_attempts)
5131 inp->sctp_ep.max_init_times = sinit->sinit_max_attempts;
5133 if (sinit->sinit_max_init_timeo)
5134 inp->sctp_ep.initial_init_rto_max = sinit->sinit_max_init_timeo;
5135 SCTP_INP_WUNLOCK(inp);
5138 case SCTP_PRIMARY_ADDR:
5140 struct sctp_setprim *spa;
5141 struct sctp_nets *net;
5143 SCTP_CHECK_AND_CAST(spa, optval, struct sctp_setprim, optsize);
5144 SCTP_FIND_STCB(inp, stcb, spa->ssp_assoc_id);
5148 net = sctp_findnet(stcb, (struct sockaddr *)&spa->ssp_addr);
5151 * We increment here since
5152 * sctp_findassociation_ep_addr() wil do a
5153 * decrement if it finds the stcb as long as
5154 * the locked tcb (last argument) is NOT a
5157 SCTP_INP_INCR_REF(inp);
5158 stcb = sctp_findassociation_ep_addr(&inp,
5159 (struct sockaddr *)&spa->ssp_addr,
5162 SCTP_INP_DECR_REF(inp);
5166 if ((stcb) && (net)) {
5167 if ((net != stcb->asoc.primary_destination) &&
5168 (!(net->dest_state & SCTP_ADDR_UNCONFIRMED))) {
5169 /* Ok we need to set it */
5170 if (sctp_set_primary_addr(stcb, (struct sockaddr *)NULL, net) == 0) {
5171 if ((stcb->asoc.alternate) &&
5172 (!(net->dest_state & SCTP_ADDR_PF)) &&
5173 (net->dest_state & SCTP_ADDR_REACHABLE)) {
5174 sctp_free_remote_addr(stcb->asoc.alternate);
5175 stcb->asoc.alternate = NULL;
5180 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5184 SCTP_TCB_UNLOCK(stcb);
5188 case SCTP_SET_DYNAMIC_PRIMARY:
5190 union sctp_sockstore *ss;
5192 error = priv_check(curthread,
5193 PRIV_NETINET_RESERVEDPORT);
5197 SCTP_CHECK_AND_CAST(ss, optval, union sctp_sockstore, optsize);
5198 /* SUPER USER CHECK? */
5199 error = sctp_dynamic_set_primary(&ss->sa, vrf_id);
5202 case SCTP_SET_PEER_PRIMARY_ADDR:
5204 struct sctp_setpeerprim *sspp;
5206 SCTP_CHECK_AND_CAST(sspp, optval, struct sctp_setpeerprim, optsize);
5207 SCTP_FIND_STCB(inp, stcb, sspp->sspp_assoc_id);
5209 struct sctp_ifa *ifa;
5211 ifa = sctp_find_ifa_by_addr((struct sockaddr *)&sspp->sspp_addr,
5212 stcb->asoc.vrf_id, SCTP_ADDR_NOT_LOCKED);
5214 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5218 if ((inp->sctp_flags & SCTP_PCB_FLAGS_BOUNDALL) == 0) {
5220 * Must validate the ifa found is in
5223 struct sctp_laddr *laddr;
5226 LIST_FOREACH(laddr, &inp->sctp_addr_list, sctp_nxt_addr) {
5227 if (laddr->ifa == NULL) {
5228 SCTPDBG(SCTP_DEBUG_OUTPUT1, "%s: NULL ifa\n",
5232 if (laddr->ifa == ifa) {
5238 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5243 if (sctp_set_primary_ip_address_sa(stcb,
5244 (struct sockaddr *)&sspp->sspp_addr) != 0) {
5245 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5249 SCTP_TCB_UNLOCK(stcb);
5251 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5256 case SCTP_BINDX_ADD_ADDR:
5258 struct sctp_getaddresses *addrs;
5261 td = (struct thread *)p;
5262 SCTP_CHECK_AND_CAST(addrs, optval, struct sctp_getaddresses,
5265 if (addrs->addr->sa_family == AF_INET) {
5266 if (optsize < sizeof(struct sctp_getaddresses) - sizeof(struct sockaddr) + sizeof(struct sockaddr_in)) {
5267 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5271 if (td != NULL && (error = prison_local_ip4(td->td_ucred, &(((struct sockaddr_in *)(addrs->addr))->sin_addr)))) {
5272 SCTP_LTRACE_ERR_RET(inp, stcb, NULL, SCTP_FROM_SCTP_USRREQ, error);
5278 if (addrs->addr->sa_family == AF_INET6) {
5279 if (optsize < sizeof(struct sctp_getaddresses) - sizeof(struct sockaddr) + sizeof(struct sockaddr_in6)) {
5280 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5284 if (td != NULL && (error = prison_local_ip6(td->td_ucred, &(((struct sockaddr_in6 *)(addrs->addr))->sin6_addr),
5285 (SCTP_IPV6_V6ONLY(inp) != 0))) != 0) {
5286 SCTP_LTRACE_ERR_RET(inp, stcb, NULL, SCTP_FROM_SCTP_USRREQ, error);
5292 error = EAFNOSUPPORT;
5295 sctp_bindx_add_address(so, inp, addrs->addr,
5296 addrs->sget_assoc_id, vrf_id,
5300 case SCTP_BINDX_REM_ADDR:
5302 struct sctp_getaddresses *addrs;
5305 td = (struct thread *)p;
5307 SCTP_CHECK_AND_CAST(addrs, optval, struct sctp_getaddresses, optsize);
5309 if (addrs->addr->sa_family == AF_INET) {
5310 if (optsize < sizeof(struct sctp_getaddresses) - sizeof(struct sockaddr) + sizeof(struct sockaddr_in)) {
5311 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5315 if (td != NULL && (error = prison_local_ip4(td->td_ucred, &(((struct sockaddr_in *)(addrs->addr))->sin_addr)))) {
5316 SCTP_LTRACE_ERR_RET(inp, stcb, NULL, SCTP_FROM_SCTP_USRREQ, error);
5322 if (addrs->addr->sa_family == AF_INET6) {
5323 if (optsize < sizeof(struct sctp_getaddresses) - sizeof(struct sockaddr) + sizeof(struct sockaddr_in6)) {
5324 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5329 (error = prison_local_ip6(td->td_ucred,
5330 &(((struct sockaddr_in6 *)(addrs->addr))->sin6_addr),
5331 (SCTP_IPV6_V6ONLY(inp) != 0))) != 0) {
5332 SCTP_LTRACE_ERR_RET(inp, stcb, NULL, SCTP_FROM_SCTP_USRREQ, error);
5338 error = EAFNOSUPPORT;
5341 sctp_bindx_delete_address(inp, addrs->addr,
5342 addrs->sget_assoc_id, vrf_id,
5348 struct sctp_event *event;
5349 uint32_t event_type;
5351 SCTP_CHECK_AND_CAST(event, optval, struct sctp_event, optsize);
5352 SCTP_FIND_STCB(inp, stcb, event->se_assoc_id);
5353 switch (event->se_type) {
5354 case SCTP_ASSOC_CHANGE:
5355 event_type = SCTP_PCB_FLAGS_RECVASSOCEVNT;
5357 case SCTP_PEER_ADDR_CHANGE:
5358 event_type = SCTP_PCB_FLAGS_RECVPADDREVNT;
5360 case SCTP_REMOTE_ERROR:
5361 event_type = SCTP_PCB_FLAGS_RECVPEERERR;
5363 case SCTP_SEND_FAILED:
5364 event_type = SCTP_PCB_FLAGS_RECVSENDFAILEVNT;
5366 case SCTP_SHUTDOWN_EVENT:
5367 event_type = SCTP_PCB_FLAGS_RECVSHUTDOWNEVNT;
5369 case SCTP_ADAPTATION_INDICATION:
5370 event_type = SCTP_PCB_FLAGS_ADAPTATIONEVNT;
5372 case SCTP_PARTIAL_DELIVERY_EVENT:
5373 event_type = SCTP_PCB_FLAGS_PDAPIEVNT;
5375 case SCTP_AUTHENTICATION_EVENT:
5376 event_type = SCTP_PCB_FLAGS_AUTHEVNT;
5378 case SCTP_STREAM_RESET_EVENT:
5379 event_type = SCTP_PCB_FLAGS_STREAM_RESETEVNT;
5381 case SCTP_SENDER_DRY_EVENT:
5382 event_type = SCTP_PCB_FLAGS_DRYEVNT;
5384 case SCTP_NOTIFICATIONS_STOPPED_EVENT:
5386 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOTSUP);
5389 case SCTP_ASSOC_RESET_EVENT:
5390 event_type = SCTP_PCB_FLAGS_ASSOC_RESETEVNT;
5392 case SCTP_STREAM_CHANGE_EVENT:
5393 event_type = SCTP_PCB_FLAGS_STREAM_CHANGEEVNT;
5395 case SCTP_SEND_FAILED_EVENT:
5396 event_type = SCTP_PCB_FLAGS_RECVNSENDFAILEVNT;
5400 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5404 if (event_type > 0) {
5407 sctp_stcb_feature_on(inp, stcb, event_type);
5408 if (event_type == SCTP_PCB_FLAGS_DRYEVNT) {
5409 if (TAILQ_EMPTY(&stcb->asoc.send_queue) &&
5410 TAILQ_EMPTY(&stcb->asoc.sent_queue) &&
5411 (stcb->asoc.stream_queue_cnt == 0)) {
5412 sctp_ulp_notify(SCTP_NOTIFY_SENDER_DRY, stcb, 0, NULL, SCTP_SO_LOCKED);
5416 sctp_stcb_feature_off(inp, stcb, event_type);
5418 SCTP_TCB_UNLOCK(stcb);
5421 * We don't want to send up a storm
5422 * of events, so return an error for
5425 if ((event_type == SCTP_PCB_FLAGS_DRYEVNT) &&
5426 ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) == 0) &&
5427 ((inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) == 0) &&
5428 ((event->se_assoc_id == SCTP_ALL_ASSOC) ||
5429 (event->se_assoc_id == SCTP_CURRENT_ASSOC))) {
5430 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOTSUP);
5434 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
5435 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
5436 (event->se_assoc_id == SCTP_FUTURE_ASSOC) ||
5437 (event->se_assoc_id == SCTP_ALL_ASSOC)) {
5438 SCTP_INP_WLOCK(inp);
5440 sctp_feature_on(inp, event_type);
5442 sctp_feature_off(inp, event_type);
5444 SCTP_INP_WUNLOCK(inp);
5446 if ((event->se_assoc_id == SCTP_CURRENT_ASSOC) ||
5447 (event->se_assoc_id == SCTP_ALL_ASSOC)) {
5448 SCTP_INP_RLOCK(inp);
5449 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
5450 SCTP_TCB_LOCK(stcb);
5452 sctp_stcb_feature_on(inp, stcb, event_type);
5454 sctp_stcb_feature_off(inp, stcb, event_type);
5456 SCTP_TCB_UNLOCK(stcb);
5458 SCTP_INP_RUNLOCK(inp);
5464 case SCTP_RECVRCVINFO:
5468 SCTP_CHECK_AND_CAST(onoff, optval, int, optsize);
5469 SCTP_INP_WLOCK(inp);
5471 sctp_feature_on(inp, SCTP_PCB_FLAGS_RECVRCVINFO);
5473 sctp_feature_off(inp, SCTP_PCB_FLAGS_RECVRCVINFO);
5475 SCTP_INP_WUNLOCK(inp);
5478 case SCTP_RECVNXTINFO:
5482 SCTP_CHECK_AND_CAST(onoff, optval, int, optsize);
5483 SCTP_INP_WLOCK(inp);
5485 sctp_feature_on(inp, SCTP_PCB_FLAGS_RECVNXTINFO);
5487 sctp_feature_off(inp, SCTP_PCB_FLAGS_RECVNXTINFO);
5489 SCTP_INP_WUNLOCK(inp);
5492 case SCTP_DEFAULT_SNDINFO:
5494 struct sctp_sndinfo *info;
5497 SCTP_CHECK_AND_CAST(info, optval, struct sctp_sndinfo, optsize);
5498 SCTP_FIND_STCB(inp, stcb, info->snd_assoc_id);
5501 if (info->snd_sid < stcb->asoc.streamoutcnt) {
5502 stcb->asoc.def_send.sinfo_stream = info->snd_sid;
5503 policy = PR_SCTP_POLICY(stcb->asoc.def_send.sinfo_flags);
5504 stcb->asoc.def_send.sinfo_flags = info->snd_flags;
5505 stcb->asoc.def_send.sinfo_flags |= policy;
5506 stcb->asoc.def_send.sinfo_ppid = info->snd_ppid;
5507 stcb->asoc.def_send.sinfo_context = info->snd_context;
5509 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5512 SCTP_TCB_UNLOCK(stcb);
5514 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
5515 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
5516 (info->snd_assoc_id == SCTP_FUTURE_ASSOC) ||
5517 (info->snd_assoc_id == SCTP_ALL_ASSOC)) {
5518 SCTP_INP_WLOCK(inp);
5519 inp->def_send.sinfo_stream = info->snd_sid;
5520 policy = PR_SCTP_POLICY(inp->def_send.sinfo_flags);
5521 inp->def_send.sinfo_flags = info->snd_flags;
5522 inp->def_send.sinfo_flags |= policy;
5523 inp->def_send.sinfo_ppid = info->snd_ppid;
5524 inp->def_send.sinfo_context = info->snd_context;
5525 SCTP_INP_WUNLOCK(inp);
5527 if ((info->snd_assoc_id == SCTP_CURRENT_ASSOC) ||
5528 (info->snd_assoc_id == SCTP_ALL_ASSOC)) {
5529 SCTP_INP_RLOCK(inp);
5530 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
5531 SCTP_TCB_LOCK(stcb);
5532 if (info->snd_sid < stcb->asoc.streamoutcnt) {
5533 stcb->asoc.def_send.sinfo_stream = info->snd_sid;
5534 policy = PR_SCTP_POLICY(stcb->asoc.def_send.sinfo_flags);
5535 stcb->asoc.def_send.sinfo_flags = info->snd_flags;
5536 stcb->asoc.def_send.sinfo_flags |= policy;
5537 stcb->asoc.def_send.sinfo_ppid = info->snd_ppid;
5538 stcb->asoc.def_send.sinfo_context = info->snd_context;
5540 SCTP_TCB_UNLOCK(stcb);
5542 SCTP_INP_RUNLOCK(inp);
5547 case SCTP_DEFAULT_PRINFO:
5549 struct sctp_default_prinfo *info;
5551 SCTP_CHECK_AND_CAST(info, optval, struct sctp_default_prinfo, optsize);
5552 SCTP_FIND_STCB(inp, stcb, info->pr_assoc_id);
5554 if (PR_SCTP_INVALID_POLICY(info->pr_policy)) {
5555 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5560 stcb->asoc.def_send.sinfo_flags &= 0xfff0;
5561 stcb->asoc.def_send.sinfo_flags |= info->pr_policy;
5562 stcb->asoc.def_send.sinfo_timetolive = info->pr_value;
5563 SCTP_TCB_UNLOCK(stcb);
5565 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
5566 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
5567 (info->pr_assoc_id == SCTP_FUTURE_ASSOC) ||
5568 (info->pr_assoc_id == SCTP_ALL_ASSOC)) {
5569 SCTP_INP_WLOCK(inp);
5570 inp->def_send.sinfo_flags &= 0xfff0;
5571 inp->def_send.sinfo_flags |= info->pr_policy;
5572 inp->def_send.sinfo_timetolive = info->pr_value;
5573 SCTP_INP_WUNLOCK(inp);
5575 if ((info->pr_assoc_id == SCTP_CURRENT_ASSOC) ||
5576 (info->pr_assoc_id == SCTP_ALL_ASSOC)) {
5577 SCTP_INP_RLOCK(inp);
5578 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
5579 SCTP_TCB_LOCK(stcb);
5580 stcb->asoc.def_send.sinfo_flags &= 0xfff0;
5581 stcb->asoc.def_send.sinfo_flags |= info->pr_policy;
5582 stcb->asoc.def_send.sinfo_timetolive = info->pr_value;
5583 SCTP_TCB_UNLOCK(stcb);
5585 SCTP_INP_RUNLOCK(inp);
5590 case SCTP_PEER_ADDR_THLDS:
5591 /* Applies to the specific association */
5593 struct sctp_paddrthlds *thlds;
5594 struct sctp_nets *net;
5596 SCTP_CHECK_AND_CAST(thlds, optval, struct sctp_paddrthlds, optsize);
5597 SCTP_FIND_STCB(inp, stcb, thlds->spt_assoc_id);
5600 net = sctp_findnet(stcb, (struct sockaddr *)&thlds->spt_assoc_id);
5603 * We increment here since
5604 * sctp_findassociation_ep_addr() wil do a
5605 * decrement if it finds the stcb as long as
5606 * the locked tcb (last argument) is NOT a
5609 SCTP_INP_INCR_REF(inp);
5610 stcb = sctp_findassociation_ep_addr(&inp,
5611 (struct sockaddr *)&thlds->spt_assoc_id,
5614 SCTP_INP_DECR_REF(inp);
5617 if (stcb && (net == NULL)) {
5618 struct sockaddr *sa;
5620 sa = (struct sockaddr *)&thlds->spt_assoc_id;
5622 if (sa->sa_family == AF_INET) {
5624 struct sockaddr_in *sin;
5626 sin = (struct sockaddr_in *)sa;
5627 if (sin->sin_addr.s_addr) {
5628 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5629 SCTP_TCB_UNLOCK(stcb);
5636 if (sa->sa_family == AF_INET6) {
5637 struct sockaddr_in6 *sin6;
5639 sin6 = (struct sockaddr_in6 *)sa;
5640 if (!IN6_IS_ADDR_UNSPECIFIED(&sin6->sin6_addr)) {
5641 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5642 SCTP_TCB_UNLOCK(stcb);
5649 error = EAFNOSUPPORT;
5650 SCTP_TCB_UNLOCK(stcb);
5651 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
5657 if (net->dest_state & SCTP_ADDR_PF) {
5658 if ((net->failure_threshold > thlds->spt_pathmaxrxt) ||
5659 (net->failure_threshold <= thlds->spt_pathpfthld)) {
5660 net->dest_state &= ~SCTP_ADDR_PF;
5663 if ((net->failure_threshold > thlds->spt_pathpfthld) &&
5664 (net->failure_threshold <= thlds->spt_pathmaxrxt)) {
5665 net->dest_state |= SCTP_ADDR_PF;
5666 sctp_send_hb(stcb, net, SCTP_SO_LOCKED);
5667 sctp_timer_stop(SCTP_TIMER_TYPE_HEARTBEAT, stcb->sctp_ep, stcb, net, SCTP_FROM_SCTP_TIMER + SCTP_LOC_3);
5668 sctp_timer_start(SCTP_TIMER_TYPE_HEARTBEAT, stcb->sctp_ep, stcb, net);
5671 if (net->dest_state & SCTP_ADDR_REACHABLE) {
5672 if (net->failure_threshold > thlds->spt_pathmaxrxt) {
5673 net->dest_state &= ~SCTP_ADDR_REACHABLE;
5674 sctp_ulp_notify(SCTP_NOTIFY_INTERFACE_DOWN, stcb, 0, net, SCTP_SO_LOCKED);
5677 if (net->failure_threshold <= thlds->spt_pathmaxrxt) {
5678 net->dest_state |= SCTP_ADDR_REACHABLE;
5679 sctp_ulp_notify(SCTP_NOTIFY_INTERFACE_UP, stcb, 0, net, SCTP_SO_LOCKED);
5682 net->failure_threshold = thlds->spt_pathmaxrxt;
5683 net->pf_threshold = thlds->spt_pathpfthld;
5685 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
5686 if (net->dest_state & SCTP_ADDR_PF) {
5687 if ((net->failure_threshold > thlds->spt_pathmaxrxt) ||
5688 (net->failure_threshold <= thlds->spt_pathpfthld)) {
5689 net->dest_state &= ~SCTP_ADDR_PF;
5692 if ((net->failure_threshold > thlds->spt_pathpfthld) &&
5693 (net->failure_threshold <= thlds->spt_pathmaxrxt)) {
5694 net->dest_state |= SCTP_ADDR_PF;
5695 sctp_send_hb(stcb, net, SCTP_SO_LOCKED);
5696 sctp_timer_stop(SCTP_TIMER_TYPE_HEARTBEAT, stcb->sctp_ep, stcb, net, SCTP_FROM_SCTP_TIMER + SCTP_LOC_3);
5697 sctp_timer_start(SCTP_TIMER_TYPE_HEARTBEAT, stcb->sctp_ep, stcb, net);
5700 if (net->dest_state & SCTP_ADDR_REACHABLE) {
5701 if (net->failure_threshold > thlds->spt_pathmaxrxt) {
5702 net->dest_state &= ~SCTP_ADDR_REACHABLE;
5703 sctp_ulp_notify(SCTP_NOTIFY_INTERFACE_DOWN, stcb, 0, net, SCTP_SO_LOCKED);
5706 if (net->failure_threshold <= thlds->spt_pathmaxrxt) {
5707 net->dest_state |= SCTP_ADDR_REACHABLE;
5708 sctp_ulp_notify(SCTP_NOTIFY_INTERFACE_UP, stcb, 0, net, SCTP_SO_LOCKED);
5711 net->failure_threshold = thlds->spt_pathmaxrxt;
5712 net->pf_threshold = thlds->spt_pathpfthld;
5714 stcb->asoc.def_net_failure = thlds->spt_pathmaxrxt;
5715 stcb->asoc.def_net_pf_threshold = thlds->spt_pathpfthld;
5718 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
5719 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
5720 (thlds->spt_assoc_id == SCTP_FUTURE_ASSOC)) {
5721 SCTP_INP_WLOCK(inp);
5722 inp->sctp_ep.def_net_failure = thlds->spt_pathmaxrxt;
5723 inp->sctp_ep.def_net_pf_threshold = thlds->spt_pathpfthld;
5724 SCTP_INP_WUNLOCK(inp);
5726 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5732 case SCTP_REMOTE_UDP_ENCAPS_PORT:
5734 struct sctp_udpencaps *encaps;
5735 struct sctp_nets *net;
5737 SCTP_CHECK_AND_CAST(encaps, optval, struct sctp_udpencaps, optsize);
5738 SCTP_FIND_STCB(inp, stcb, encaps->sue_assoc_id);
5740 net = sctp_findnet(stcb, (struct sockaddr *)&encaps->sue_address);
5743 * We increment here since
5744 * sctp_findassociation_ep_addr() wil do a
5745 * decrement if it finds the stcb as long as
5746 * the locked tcb (last argument) is NOT a
5750 SCTP_INP_INCR_REF(inp);
5751 stcb = sctp_findassociation_ep_addr(&inp, (struct sockaddr *)&encaps->sue_address, &net, NULL, NULL);
5753 SCTP_INP_DECR_REF(inp);
5756 if (stcb && (net == NULL)) {
5757 struct sockaddr *sa;
5759 sa = (struct sockaddr *)&encaps->sue_address;
5761 if (sa->sa_family == AF_INET) {
5763 struct sockaddr_in *sin;
5765 sin = (struct sockaddr_in *)sa;
5766 if (sin->sin_addr.s_addr) {
5767 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5768 SCTP_TCB_UNLOCK(stcb);
5775 if (sa->sa_family == AF_INET6) {
5776 struct sockaddr_in6 *sin6;
5778 sin6 = (struct sockaddr_in6 *)sa;
5779 if (!IN6_IS_ADDR_UNSPECIFIED(&sin6->sin6_addr)) {
5780 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5781 SCTP_TCB_UNLOCK(stcb);
5788 error = EAFNOSUPPORT;
5789 SCTP_TCB_UNLOCK(stcb);
5790 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
5796 net->port = encaps->sue_port;
5798 stcb->asoc.port = encaps->sue_port;
5800 SCTP_TCB_UNLOCK(stcb);
5802 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
5803 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
5804 (encaps->sue_assoc_id == SCTP_FUTURE_ASSOC)) {
5805 SCTP_INP_WLOCK(inp);
5806 inp->sctp_ep.port = encaps->sue_port;
5807 SCTP_INP_WUNLOCK(inp);
5809 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5816 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOPROTOOPT);
5817 error = ENOPROTOOPT;
5819 } /* end switch (opt) */
5824 sctp_ctloutput(struct socket *so, struct sockopt *sopt)
5826 void *optval = NULL;
5831 if (sopt->sopt_level != IPPROTO_SCTP) {
5832 /* wrong proto level... send back up to IP */
5834 if (INP_CHECK_SOCKAF(so, AF_INET6))
5835 error = ip6_ctloutput(so, sopt);
5837 #if defined(INET) && defined(INET6)
5841 error = ip_ctloutput(so, sopt);
5845 optsize = sopt->sopt_valsize;
5847 SCTP_MALLOC(optval, void *, optsize, SCTP_M_SOCKOPT);
5848 if (optval == NULL) {
5849 SCTP_LTRACE_ERR_RET(so->so_pcb, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOBUFS);
5852 error = sooptcopyin(sopt, optval, optsize, optsize);
5854 SCTP_FREE(optval, SCTP_M_SOCKOPT);
5858 p = (void *)sopt->sopt_td;
5859 if (sopt->sopt_dir == SOPT_SET) {
5860 error = sctp_setopt(so, sopt->sopt_name, optval, optsize, p);
5861 } else if (sopt->sopt_dir == SOPT_GET) {
5862 error = sctp_getopt(so, sopt->sopt_name, optval, &optsize, p);
5864 SCTP_LTRACE_ERR_RET(so->so_pcb, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5867 if ((error == 0) && (optval != NULL)) {
5868 error = sooptcopyout(sopt, optval, optsize);
5869 SCTP_FREE(optval, SCTP_M_SOCKOPT);
5870 } else if (optval != NULL) {
5871 SCTP_FREE(optval, SCTP_M_SOCKOPT);
5879 sctp_connect(struct socket *so, struct sockaddr *addr, struct thread *p)
5882 int create_lock_on = 0;
5884 struct sctp_inpcb *inp;
5885 struct sctp_tcb *stcb = NULL;
5887 inp = (struct sctp_inpcb *)so->so_pcb;
5889 /* I made the same as TCP since we are not setup? */
5890 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5891 return (ECONNRESET);
5894 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5897 switch (addr->sa_family) {
5901 struct sockaddr_in6 *sin6p;
5903 if (addr->sa_len != sizeof(struct sockaddr_in6)) {
5904 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5907 sin6p = (struct sockaddr_in6 *)addr;
5908 if (p != NULL && (error = prison_remote_ip6(p->td_ucred, &sin6p->sin6_addr)) != 0) {
5909 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
5918 struct sockaddr_in *sinp;
5920 if (addr->sa_len != sizeof(struct sockaddr_in)) {
5921 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5924 sinp = (struct sockaddr_in *)addr;
5925 if (p != NULL && (error = prison_remote_ip4(p->td_ucred, &sinp->sin_addr)) != 0) {
5926 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
5933 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EAFNOSUPPORT);
5934 return (EAFNOSUPPORT);
5936 SCTP_INP_INCR_REF(inp);
5937 SCTP_ASOC_CREATE_LOCK(inp);
5941 if ((inp->sctp_flags & SCTP_PCB_FLAGS_SOCKET_ALLGONE) ||
5942 (inp->sctp_flags & SCTP_PCB_FLAGS_SOCKET_GONE)) {
5943 /* Should I really unlock ? */
5944 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EFAULT);
5949 if (((inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) == 0) &&
5950 (addr->sa_family == AF_INET6)) {
5951 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5956 if ((inp->sctp_flags & SCTP_PCB_FLAGS_UNBOUND) ==
5957 SCTP_PCB_FLAGS_UNBOUND) {
5958 /* Bind a ephemeral port */
5959 error = sctp_inpcb_bind(so, NULL, NULL, p);
5964 /* Now do we connect? */
5965 if ((inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) &&
5966 (sctp_is_feature_off(inp, SCTP_PCB_FLAGS_PORTREUSE))) {
5967 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5971 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) &&
5972 (inp->sctp_flags & SCTP_PCB_FLAGS_CONNECTED)) {
5973 /* We are already connected AND the TCP model */
5974 SCTP_LTRACE_ERR_RET(inp, stcb, NULL, SCTP_FROM_SCTP_USRREQ, EADDRINUSE);
5978 if (inp->sctp_flags & SCTP_PCB_FLAGS_CONNECTED) {
5979 SCTP_INP_RLOCK(inp);
5980 stcb = LIST_FIRST(&inp->sctp_asoc_list);
5981 SCTP_INP_RUNLOCK(inp);
5984 * We increment here since sctp_findassociation_ep_addr()
5985 * will do a decrement if it finds the stcb as long as the
5986 * locked tcb (last argument) is NOT a TCB.. aka NULL.
5988 SCTP_INP_INCR_REF(inp);
5989 stcb = sctp_findassociation_ep_addr(&inp, addr, NULL, NULL, NULL);
5991 SCTP_INP_DECR_REF(inp);
5993 SCTP_TCB_UNLOCK(stcb);
5997 /* Already have or am bring up an association */
5998 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EALREADY);
6002 vrf_id = inp->def_vrf_id;
6003 /* We are GOOD to go */
6004 stcb = sctp_aloc_assoc(inp, addr, &error, 0, vrf_id, p);
6006 /* Gak! no memory */
6009 if (stcb->sctp_ep->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) {
6010 stcb->sctp_ep->sctp_flags |= SCTP_PCB_FLAGS_CONNECTED;
6011 /* Set the connected flag so we can queue data */
6014 SCTP_SET_STATE(&stcb->asoc, SCTP_STATE_COOKIE_WAIT);
6015 (void)SCTP_GETTIME_TIMEVAL(&stcb->asoc.time_entered);
6017 /* initialize authentication parameters for the assoc */
6018 sctp_initialize_auth_params(inp, stcb);
6020 sctp_send_initiate(inp, stcb, SCTP_SO_LOCKED);
6021 SCTP_TCB_UNLOCK(stcb);
6023 if (create_lock_on) {
6024 SCTP_ASOC_CREATE_UNLOCK(inp);
6026 SCTP_INP_DECR_REF(inp);
6033 sctp_listen(struct socket *so, int backlog, struct thread *p)
6036 * Note this module depends on the protocol processing being called
6037 * AFTER any socket level flags and backlog are applied to the
6038 * socket. The traditional way that the socket flags are applied is
6039 * AFTER protocol processing. We have made a change to the
6040 * sys/kern/uipc_socket.c module to reverse this but this MUST be in
6041 * place if the socket API for SCTP is to work properly.
6045 struct sctp_inpcb *inp;
6047 inp = (struct sctp_inpcb *)so->so_pcb;
6049 /* I made the same as TCP since we are not setup? */
6050 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6051 return (ECONNRESET);
6053 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_PORTREUSE)) {
6054 /* See if we have a listener */
6055 struct sctp_inpcb *tinp;
6056 union sctp_sockstore store, *sp;
6059 if ((inp->sctp_flags & SCTP_PCB_FLAGS_BOUNDALL) == 0) {
6061 struct sctp_laddr *laddr;
6063 LIST_FOREACH(laddr, &inp->sctp_addr_list, sctp_nxt_addr) {
6064 memcpy(&store, &laddr->ifa->address, sizeof(store));
6065 switch (sp->sa.sa_family) {
6068 sp->sin.sin_port = inp->sctp_lport;
6073 sp->sin6.sin6_port = inp->sctp_lport;
6079 tinp = sctp_pcb_findep(&sp->sa, 0, 0, inp->def_vrf_id);
6080 if (tinp && (tinp != inp) &&
6081 ((tinp->sctp_flags & SCTP_PCB_FLAGS_SOCKET_ALLGONE) == 0) &&
6082 ((tinp->sctp_flags & SCTP_PCB_FLAGS_SOCKET_GONE) == 0) &&
6083 (tinp->sctp_socket->so_qlimit)) {
6085 * we have a listener already and
6088 SCTP_INP_DECR_REF(tinp);
6089 return (EADDRINUSE);
6091 SCTP_INP_DECR_REF(tinp);
6095 /* Setup a local addr bound all */
6096 memset(&store, 0, sizeof(store));
6097 switch (sp->sa.sa_family) {
6100 store.sin.sin_port = inp->sctp_lport;
6105 sp->sin6.sin6_port = inp->sctp_lport;
6112 if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) {
6113 store.sa.sa_family = AF_INET6;
6114 store.sa.sa_len = sizeof(struct sockaddr_in6);
6118 if ((inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) == 0) {
6119 store.sa.sa_family = AF_INET;
6120 store.sa.sa_len = sizeof(struct sockaddr_in);
6123 tinp = sctp_pcb_findep(&sp->sa, 0, 0, inp->def_vrf_id);
6124 if (tinp && (tinp != inp) &&
6125 ((tinp->sctp_flags & SCTP_PCB_FLAGS_SOCKET_ALLGONE) == 0) &&
6126 ((tinp->sctp_flags & SCTP_PCB_FLAGS_SOCKET_GONE) == 0) &&
6127 (tinp->sctp_socket->so_qlimit)) {
6129 * we have a listener already and its not
6132 SCTP_INP_DECR_REF(tinp);
6133 return (EADDRINUSE);
6135 SCTP_INP_DECR_REF(inp);
6139 SCTP_INP_RLOCK(inp);
6140 #ifdef SCTP_LOCK_LOGGING
6141 if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_LOCK_LOGGING_ENABLE) {
6142 sctp_log_lock(inp, (struct sctp_tcb *)NULL, SCTP_LOG_LOCK_SOCK);
6146 error = solisten_proto_check(so);
6149 SCTP_INP_RUNLOCK(inp);
6152 if ((sctp_is_feature_on(inp, SCTP_PCB_FLAGS_PORTREUSE)) &&
6153 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL)) {
6155 * The unlucky case - We are in the tcp pool with this guy.
6156 * - Someone else is in the main inp slot. - We must move
6157 * this guy (the listener) to the main slot - We must then
6158 * move the guy that was listener to the TCP Pool.
6160 if (sctp_swap_inpcb_for_listen(inp)) {
6164 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) &&
6165 (inp->sctp_flags & SCTP_PCB_FLAGS_CONNECTED)) {
6166 /* We are already connected AND the TCP model */
6168 SCTP_INP_RUNLOCK(inp);
6170 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EADDRINUSE);
6171 return (EADDRINUSE);
6173 SCTP_INP_RUNLOCK(inp);
6174 if (inp->sctp_flags & SCTP_PCB_FLAGS_UNBOUND) {
6175 /* We must do a bind. */
6177 if ((error = sctp_inpcb_bind(so, NULL, NULL, p))) {
6178 /* bind error, probably perm */
6183 /* It appears for 7.0 and on, we must always call this. */
6184 solisten_proto(so, backlog);
6185 if (inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) {
6186 /* remove the ACCEPTCONN flag for one-to-many sockets */
6187 so->so_options &= ~SO_ACCEPTCONN;
6190 /* turning off listen */
6191 so->so_options &= ~SO_ACCEPTCONN;
6197 static int sctp_defered_wakeup_cnt = 0;
6200 sctp_accept(struct socket *so, struct sockaddr **addr)
6202 struct sctp_tcb *stcb;
6203 struct sctp_inpcb *inp;
6204 union sctp_sockstore store;
6210 inp = (struct sctp_inpcb *)so->so_pcb;
6213 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6214 return (ECONNRESET);
6216 SCTP_INP_RLOCK(inp);
6217 if (inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) {
6218 SCTP_INP_RUNLOCK(inp);
6219 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EOPNOTSUPP);
6220 return (EOPNOTSUPP);
6222 if (so->so_state & SS_ISDISCONNECTED) {
6223 SCTP_INP_RUNLOCK(inp);
6224 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ECONNABORTED);
6225 return (ECONNABORTED);
6227 stcb = LIST_FIRST(&inp->sctp_asoc_list);
6229 SCTP_INP_RUNLOCK(inp);
6230 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6231 return (ECONNRESET);
6233 SCTP_TCB_LOCK(stcb);
6234 SCTP_INP_RUNLOCK(inp);
6235 store = stcb->asoc.primary_destination->ro._l_addr;
6236 stcb->asoc.state &= ~SCTP_STATE_IN_ACCEPT_QUEUE;
6237 SCTP_TCB_UNLOCK(stcb);
6238 switch (store.sa.sa_family) {
6242 struct sockaddr_in *sin;
6244 SCTP_MALLOC_SONAME(sin, struct sockaddr_in *, sizeof *sin);
6247 sin->sin_family = AF_INET;
6248 sin->sin_len = sizeof(*sin);
6249 sin->sin_port = store.sin.sin_port;
6250 sin->sin_addr = store.sin.sin_addr;
6251 *addr = (struct sockaddr *)sin;
6258 struct sockaddr_in6 *sin6;
6260 SCTP_MALLOC_SONAME(sin6, struct sockaddr_in6 *, sizeof *sin6);
6263 sin6->sin6_family = AF_INET6;
6264 sin6->sin6_len = sizeof(*sin6);
6265 sin6->sin6_port = store.sin6.sin6_port;
6266 sin6->sin6_addr = store.sin6.sin6_addr;
6267 if ((error = sa6_recoverscope(sin6)) != 0) {
6268 SCTP_FREE_SONAME(sin6);
6271 *addr = (struct sockaddr *)sin6;
6279 /* Wake any delayed sleep action */
6280 if (inp->sctp_flags & SCTP_PCB_FLAGS_DONT_WAKE) {
6281 SCTP_INP_WLOCK(inp);
6282 inp->sctp_flags &= ~SCTP_PCB_FLAGS_DONT_WAKE;
6283 if (inp->sctp_flags & SCTP_PCB_FLAGS_WAKEOUTPUT) {
6284 inp->sctp_flags &= ~SCTP_PCB_FLAGS_WAKEOUTPUT;
6285 SCTP_INP_WUNLOCK(inp);
6286 SOCKBUF_LOCK(&inp->sctp_socket->so_snd);
6287 if (sowriteable(inp->sctp_socket)) {
6288 sowwakeup_locked(inp->sctp_socket);
6290 SOCKBUF_UNLOCK(&inp->sctp_socket->so_snd);
6292 SCTP_INP_WLOCK(inp);
6294 if (inp->sctp_flags & SCTP_PCB_FLAGS_WAKEINPUT) {
6295 inp->sctp_flags &= ~SCTP_PCB_FLAGS_WAKEINPUT;
6296 SCTP_INP_WUNLOCK(inp);
6297 SOCKBUF_LOCK(&inp->sctp_socket->so_rcv);
6298 if (soreadable(inp->sctp_socket)) {
6299 sctp_defered_wakeup_cnt++;
6300 sorwakeup_locked(inp->sctp_socket);
6302 SOCKBUF_UNLOCK(&inp->sctp_socket->so_rcv);
6304 SCTP_INP_WLOCK(inp);
6306 SCTP_INP_WUNLOCK(inp);
6308 if (stcb->asoc.state & SCTP_STATE_ABOUT_TO_BE_FREED) {
6309 SCTP_TCB_LOCK(stcb);
6310 sctp_free_assoc(inp, stcb, SCTP_NORMAL_PROC, SCTP_FROM_SCTP_USRREQ + SCTP_LOC_7);
6317 sctp_ingetaddr(struct socket *so, struct sockaddr **addr)
6319 struct sockaddr_in *sin;
6321 struct sctp_inpcb *inp;
6322 struct sctp_ifa *sctp_ifa;
6325 * Do the malloc first in case it blocks.
6327 SCTP_MALLOC_SONAME(sin, struct sockaddr_in *, sizeof *sin);
6330 sin->sin_family = AF_INET;
6331 sin->sin_len = sizeof(*sin);
6332 inp = (struct sctp_inpcb *)so->so_pcb;
6334 SCTP_FREE_SONAME(sin);
6335 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6336 return (ECONNRESET);
6338 SCTP_INP_RLOCK(inp);
6339 sin->sin_port = inp->sctp_lport;
6340 if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUNDALL) {
6341 if (inp->sctp_flags & SCTP_PCB_FLAGS_CONNECTED) {
6342 struct sctp_tcb *stcb;
6343 struct sockaddr_in *sin_a;
6344 struct sctp_nets *net;
6347 stcb = LIST_FIRST(&inp->sctp_asoc_list);
6353 SCTP_TCB_LOCK(stcb);
6354 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
6355 sin_a = (struct sockaddr_in *)&net->ro._l_addr;
6357 /* this will make coverity happy */
6360 if (sin_a->sin_family == AF_INET) {
6365 if ((!fnd) || (sin_a == NULL)) {
6367 SCTP_TCB_UNLOCK(stcb);
6370 vrf_id = inp->def_vrf_id;
6371 sctp_ifa = sctp_source_address_selection(inp,
6373 (sctp_route_t *) & net->ro,
6376 sin->sin_addr = sctp_ifa->address.sin.sin_addr;
6377 sctp_free_ifa(sctp_ifa);
6379 SCTP_TCB_UNLOCK(stcb);
6381 /* For the bound all case you get back 0 */
6383 sin->sin_addr.s_addr = 0;
6387 /* Take the first IPv4 address in the list */
6388 struct sctp_laddr *laddr;
6391 LIST_FOREACH(laddr, &inp->sctp_addr_list, sctp_nxt_addr) {
6392 if (laddr->ifa->address.sa.sa_family == AF_INET) {
6393 struct sockaddr_in *sin_a;
6395 sin_a = (struct sockaddr_in *)&laddr->ifa->address.sa;
6396 sin->sin_addr = sin_a->sin_addr;
6402 SCTP_FREE_SONAME(sin);
6403 SCTP_INP_RUNLOCK(inp);
6404 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOENT);
6408 SCTP_INP_RUNLOCK(inp);
6409 (*addr) = (struct sockaddr *)sin;
6414 sctp_peeraddr(struct socket *so, struct sockaddr **addr)
6416 struct sockaddr_in *sin;
6418 struct sockaddr_in *sin_a;
6419 struct sctp_inpcb *inp;
6420 struct sctp_tcb *stcb;
6421 struct sctp_nets *net;
6423 /* Do the malloc first in case it blocks. */
6424 SCTP_MALLOC_SONAME(sin, struct sockaddr_in *, sizeof *sin);
6427 sin->sin_family = AF_INET;
6428 sin->sin_len = sizeof(*sin);
6430 inp = (struct sctp_inpcb *)so->so_pcb;
6431 if ((inp == NULL) ||
6432 ((inp->sctp_flags & SCTP_PCB_FLAGS_CONNECTED) == 0)) {
6433 /* UDP type and listeners will drop out here */
6434 SCTP_FREE_SONAME(sin);
6435 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOTCONN);
6438 SCTP_INP_RLOCK(inp);
6439 stcb = LIST_FIRST(&inp->sctp_asoc_list);
6441 SCTP_TCB_LOCK(stcb);
6443 SCTP_INP_RUNLOCK(inp);
6445 SCTP_FREE_SONAME(sin);
6446 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6447 return (ECONNRESET);
6450 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
6451 sin_a = (struct sockaddr_in *)&net->ro._l_addr;
6452 if (sin_a->sin_family == AF_INET) {
6454 sin->sin_port = stcb->rport;
6455 sin->sin_addr = sin_a->sin_addr;
6459 SCTP_TCB_UNLOCK(stcb);
6461 /* No IPv4 address */
6462 SCTP_FREE_SONAME(sin);
6463 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOENT);
6466 (*addr) = (struct sockaddr *)sin;
6470 struct pr_usrreqs sctp_usrreqs = {
6471 .pru_abort = sctp_abort,
6472 .pru_accept = sctp_accept,
6473 .pru_attach = sctp_attach,
6474 .pru_bind = sctp_bind,
6475 .pru_connect = sctp_connect,
6476 .pru_control = in_control,
6477 .pru_close = sctp_close,
6478 .pru_detach = sctp_close,
6479 .pru_sopoll = sopoll_generic,
6480 .pru_flush = sctp_flush,
6481 .pru_disconnect = sctp_disconnect,
6482 .pru_listen = sctp_listen,
6483 .pru_peeraddr = sctp_peeraddr,
6484 .pru_send = sctp_sendm,
6485 .pru_shutdown = sctp_shutdown,
6486 .pru_sockaddr = sctp_ingetaddr,
6487 .pru_sosend = sctp_sosend,
6488 .pru_soreceive = sctp_soreceive