1 /* $KAME: sctp_usrreq.c,v 1.47 2005/03/06 16:04:18 itojun Exp $ */
2 /* $DragonFly: src/sys/netinet/sctp_usrreq.c,v 1.1 2005/07/15 14:46:17 eirikn Exp $ */
5 * Copyright (c) 2001, 2002, 2003, 2004 Cisco Systems, Inc.
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
11 * 1. Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in the
15 * documentation and/or other materials provided with the distribution.
16 * 3. All advertising materials mentioning features or use of this software
17 * must display the following acknowledgement:
18 * This product includes software developed by Cisco Systems, Inc.
19 * 4. Neither the name of the project nor the names of its contributors
20 * may be used to endorse or promote products derived from this software
21 * without specific prior written permission.
23 * THIS SOFTWARE IS PROVIDED BY CISCO SYSTEMS AND CONTRIBUTORS ``AS IS'' AND
24 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
25 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
26 * ARE DISCLAIMED. IN NO EVENT SHALL CISCO SYSTEMS OR CONTRIBUTORS BE LIABLE
27 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
28 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
29 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
30 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
31 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
32 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
35 #if !(defined(__OpenBSD__) || defined(__APPLE__))
36 #include "opt_ipsec.h"
38 #if defined(__FreeBSD__)
39 #include "opt_inet6.h"
42 #if defined(__NetBSD__)
48 #elif !defined(__OpenBSD__)
52 #include <sys/param.h>
53 #include <sys/systm.h>
54 #include <sys/kernel.h>
55 #include <sys/malloc.h>
57 #include <sys/domain.h>
59 #include <sys/protosw.h>
60 #include <sys/socket.h>
61 #include <sys/socketvar.h>
62 #include <sys/sysctl.h>
63 #include <sys/syslog.h>
65 #include <net/if_types.h>
66 #if defined(__FreeBSD__) || defined(__APPLE__)
67 #include <net/if_var.h>
69 #include <net/route.h>
70 #include <netinet/in.h>
71 #include <netinet/in_systm.h>
72 #include <netinet/ip.h>
73 #include <netinet/ip6.h>
74 #include <netinet/in_pcb.h>
75 #include <netinet/in_var.h>
76 #include <netinet/ip_var.h>
77 #include <netinet6/ip6_var.h>
78 #include <netinet6/in6_var.h>
80 #include <netinet/ip_icmp.h>
81 #include <netinet/icmp_var.h>
82 #include <netinet/sctp_pcb.h>
83 #include <netinet/sctp_header.h>
84 #include <netinet/sctp_var.h>
85 #include <netinet/sctp_output.h>
86 #include <netinet/sctp_uio.h>
87 #include <netinet/sctp_asconf.h>
88 #include <netinet/sctputil.h>
89 #include <netinet/sctp_indata.h>
90 #include <netinet/sctp_asconf.h>
93 #include <netinet6/ipsec.h>
94 #include <netkey/key.h>
100 #include <net/net_osdep.h>
102 #if defined(HAVE_NRL_INPCB) || defined(__FreeBSD__)
107 #define sotoin6pcb sotoinpcb
112 extern u_int32_t sctp_debug_on;
113 #endif /* SCTP_DEBUG */
116 * sysctl tunable variables
118 int sctp_auto_asconf = SCTP_DEFAULT_AUTO_ASCONF;
119 int sctp_max_burst_default = SCTP_DEF_MAX_BURST;
120 int sctp_peer_chunk_oh = sizeof(struct mbuf);
121 int sctp_strict_init = 1;
122 int sctp_no_csum_on_loopback = 1;
123 unsigned int sctp_max_chunks_on_queue = SCTP_ASOC_MAX_CHUNKS_ON_QUEUE;
124 int sctp_sendspace = (128 * 1024);
125 int sctp_recvspace = 128 * (1024 +
127 sizeof(struct sockaddr_in6)
129 sizeof(struct sockaddr_in)
132 int sctp_strict_sacks = 0;
134 int sctp_ecn_nonce = 0;
136 unsigned int sctp_delayed_sack_time_default = SCTP_RECV_MSEC;
137 unsigned int sctp_heartbeat_interval_default = SCTP_HB_DEFAULT_MSEC;
138 unsigned int sctp_pmtu_raise_time_default = SCTP_DEF_PMTU_RAISE_SEC;
139 unsigned int sctp_shutdown_guard_time_default = SCTP_DEF_MAX_SHUTDOWN_SEC;
140 unsigned int sctp_secret_lifetime_default = SCTP_DEFAULT_SECRET_LIFE_SEC;
141 unsigned int sctp_rto_max_default = SCTP_RTO_UPPER_BOUND;
142 unsigned int sctp_rto_min_default = SCTP_RTO_LOWER_BOUND;
143 unsigned int sctp_rto_initial_default = SCTP_RTO_INITIAL;
144 unsigned int sctp_init_rto_max_default = SCTP_RTO_UPPER_BOUND;
145 unsigned int sctp_valid_cookie_life_default = SCTP_DEFAULT_COOKIE_LIFE;
146 unsigned int sctp_init_rtx_max_default = SCTP_DEF_MAX_INIT;
147 unsigned int sctp_assoc_rtx_max_default = SCTP_DEF_MAX_SEND;
148 unsigned int sctp_path_rtx_max_default = SCTP_DEF_MAX_SEND/2;
149 unsigned int sctp_nr_outgoing_streams_default = SCTP_OSTREAM_INITIAL;
155 #define nmbclusters nmbclust
157 /* Init the SCTP pcb in sctp_pcb.c */
163 if (nmbclusters > SCTP_ASOC_MAX_CHUNKS_ON_QUEUE)
164 sctp_max_chunks_on_queue = nmbclusters;
166 /* if (nmbclust > SCTP_ASOC_MAX_CHUNKS_ON_QUEUE)
167 sctp_max_chunks_on_queue = nmbclust; FIX ME */
168 sctp_max_chunks_on_queue = nmbclust * 2;
171 * Allow a user to take no more than 1/2 the number of clusters
172 * or the SB_MAX whichever is smaller for the send window.
174 sb_max_adj = (u_long)((u_quad_t)(SB_MAX) * MCLBYTES / (MSIZE + MCLBYTES));
175 sctp_sendspace = min((min(SB_MAX, sb_max_adj)),
177 ((nmbclusters/2) * SCTP_DEFAULT_MAXSEGMENT));
179 ((nmbclust/2) * SCTP_DEFAULT_MAXSEGMENT));
182 * Now for the recv window, should we take the same amount?
183 * or should I do 1/2 the SB_MAX instead in the SB_MAX min above.
184 * For now I will just copy.
186 sctp_recvspace = sctp_sendspace;
194 ip_2_ip6_hdr(struct ip6_hdr *ip6, struct ip *ip)
196 bzero(ip6, sizeof(*ip6));
198 ip6->ip6_vfc = IPV6_VERSION;
199 ip6->ip6_plen = ip->ip_len;
200 ip6->ip6_nxt = ip->ip_p;
201 ip6->ip6_hlim = ip->ip_ttl;
202 ip6->ip6_src.s6_addr32[2] = ip6->ip6_dst.s6_addr32[2] =
204 ip6->ip6_src.s6_addr32[3] = ip->ip_src.s_addr;
205 ip6->ip6_dst.s6_addr32[3] = ip->ip_dst.s_addr;
210 sctp_split_chunks(struct sctp_association *asoc,
211 struct sctp_stream_out *strm,
212 struct sctp_tmit_chunk *chk)
214 struct sctp_tmit_chunk *new_chk;
216 /* First we need a chunk */
217 new_chk = (struct sctp_tmit_chunk *)SCTP_ZONE_GET(sctppcbinfo.ipi_zone_chunk);
218 if (new_chk == NULL) {
219 chk->flags |= CHUNK_FLAGS_FRAGMENT_OK;
222 sctppcbinfo.ipi_count_chunk++;
223 sctppcbinfo.ipi_gencnt_chunk++;
227 new_chk->data = m_split(chk->data, (chk->send_size>>1), M_DONTWAIT);
228 if (new_chk->data == NULL) {
230 chk->flags |= CHUNK_FLAGS_FRAGMENT_OK;
231 SCTP_ZONE_FREE(sctppcbinfo.ipi_zone_chunk, new_chk);
232 sctppcbinfo.ipi_count_chunk--;
233 if ((int)sctppcbinfo.ipi_count_chunk < 0) {
234 panic("Chunk count is negative");
236 sctppcbinfo.ipi_gencnt_chunk++;
240 /* Data is now split adjust sizes */
241 chk->send_size >>= 1;
242 new_chk->send_size >>= 1;
244 chk->book_size >>= 1;
245 new_chk->book_size >>= 1;
247 /* now adjust the marks */
248 chk->rec.data.rcv_flags |= SCTP_DATA_FIRST_FRAG;
249 chk->rec.data.rcv_flags &= ~SCTP_DATA_LAST_FRAG;
251 new_chk->rec.data.rcv_flags &= ~SCTP_DATA_FIRST_FRAG;
252 new_chk->rec.data.rcv_flags |= SCTP_DATA_LAST_FRAG;
254 /* Increase ref count if dest is set */
256 new_chk->whoTo->ref_count++;
258 /* now drop it on the end of the list*/
259 asoc->stream_queue_cnt++;
260 TAILQ_INSERT_AFTER(&strm->outqueue, chk, new_chk, sctp_next);
264 sctp_notify_mbuf(struct sctp_inpcb *inp,
265 struct sctp_tcb *stcb,
266 struct sctp_nets *net,
276 if ((inp == NULL) || (stcb == NULL) || (net == NULL) ||
277 (ip == NULL) || (sh == NULL)) {
279 SCTP_TCB_UNLOCK(stcb);
282 /* First job is to verify the vtag matches what I would send */
283 if (ntohl(sh->v_tag) != (stcb->asoc.peer_vtag)) {
284 SCTP_TCB_UNLOCK(stcb);
287 icmph = (struct icmp *)((caddr_t)ip - (sizeof(struct icmp) -
289 if (icmph->icmp_type != ICMP_UNREACH) {
290 /* We only care about unreachable */
291 SCTP_TCB_UNLOCK(stcb);
294 if (icmph->icmp_code != ICMP_UNREACH_NEEDFRAG) {
295 /* not a unreachable message due to frag. */
296 SCTP_TCB_UNLOCK(stcb);
300 nxtsz = ntohs(icmph->icmp_seq);
303 * old type router that does not tell us what the next size
304 * mtu is. Rats we will have to guess (in a educated fashion
307 nxtsz = find_next_best_mtu(totsz);
310 /* Stop any PMTU timer */
311 sctp_timer_stop(SCTP_TIMER_TYPE_PATHMTURAISE, inp, stcb, NULL);
313 /* Adjust destination size limit */
314 if (net->mtu > nxtsz) {
317 /* now what about the ep? */
318 if (stcb->asoc.smallest_mtu > nxtsz) {
319 struct sctp_tmit_chunk *chk, *nchk;
320 struct sctp_stream_out *strm;
321 /* Adjust that too */
322 stcb->asoc.smallest_mtu = nxtsz;
323 /* now off to subtract IP_DF flag if needed */
325 TAILQ_FOREACH(chk, &stcb->asoc.send_queue, sctp_next) {
326 if ((chk->send_size+IP_HDR_SIZE) > nxtsz) {
327 chk->flags |= CHUNK_FLAGS_FRAGMENT_OK;
330 TAILQ_FOREACH(chk, &stcb->asoc.sent_queue, sctp_next) {
331 if ((chk->send_size+IP_HDR_SIZE) > nxtsz) {
333 * For this guy we also mark for immediate
334 * resend since we sent to big of chunk
336 chk->flags |= CHUNK_FLAGS_FRAGMENT_OK;
337 if (chk->sent != SCTP_DATAGRAM_RESEND) {
338 stcb->asoc.sent_queue_retran_cnt++;
340 chk->sent = SCTP_DATAGRAM_RESEND;
341 chk->rec.data.doing_fast_retransmit = 0;
343 /* Clear any time so NO RTT is being done */
345 stcb->asoc.total_flight -= chk->book_size;
346 if (stcb->asoc.total_flight < 0) {
347 stcb->asoc.total_flight = 0;
349 stcb->asoc.total_flight_count--;
350 if (stcb->asoc.total_flight_count < 0) {
351 stcb->asoc.total_flight_count = 0;
353 net->flight_size -= chk->book_size;
354 if (net->flight_size < 0) {
355 net->flight_size = 0;
359 TAILQ_FOREACH(strm, &stcb->asoc.out_wheel, next_spoke) {
360 chk = TAILQ_FIRST(&strm->outqueue);
362 nchk = TAILQ_NEXT(chk, sctp_next);
363 if ((chk->send_size+SCTP_MED_OVERHEAD) > nxtsz) {
364 sctp_split_chunks(&stcb->asoc, strm, chk);
370 sctp_timer_start(SCTP_TIMER_TYPE_PATHMTURAISE, inp, stcb, NULL);
371 SCTP_TCB_UNLOCK(stcb);
376 sctp_notify(struct sctp_inpcb *inp,
380 struct sctp_tcb *stcb,
381 struct sctp_nets *net)
384 if ((inp == NULL) || (stcb == NULL) || (net == NULL) ||
385 (sh == NULL) || (to == NULL)) {
387 if (sctp_debug_on & SCTP_DEBUG_USRREQ1) {
388 printf("sctp-notify, bad call\n");
390 #endif /* SCTP_DEBUG */
393 /* First job is to verify the vtag matches what I would send */
394 if (ntohl(sh->v_tag) != (stcb->asoc.peer_vtag)) {
398 /* FIX ME FIX ME PROTOPT i.e. no SCTP should ALWAYS be an ABORT */
400 if ((errno == EHOSTUNREACH) || /* Host is not reachable */
401 (errno == EHOSTDOWN) || /* Host is down */
402 (errno == ECONNREFUSED) || /* Host refused the connection, (not an abort?) */
403 (errno == ENOPROTOOPT) /* SCTP is not present on host */
406 * Hmm reachablity problems we must examine closely.
407 * If its not reachable, we may have lost a network.
408 * Or if there is NO protocol at the other end named SCTP.
409 * well we consider it a OOTB abort.
411 if ((errno == EHOSTUNREACH) || (errno == EHOSTDOWN)) {
412 if (net->dest_state & SCTP_ADDR_REACHABLE) {
413 /* Ok that destination is NOT reachable */
414 net->dest_state &= ~SCTP_ADDR_REACHABLE;
415 net->dest_state |= SCTP_ADDR_NOT_REACHABLE;
416 net->error_count = net->failure_threshold + 1;
417 sctp_ulp_notify(SCTP_NOTIFY_INTERFACE_DOWN,
418 stcb, SCTP_FAILED_THRESHOLD,
422 SCTP_TCB_UNLOCK(stcb);
425 * Here the peer is either playing tricks on us,
426 * including an address that belongs to someone who
427 * does not support SCTP OR was a userland
428 * implementation that shutdown and now is dead. In
429 * either case treat it like a OOTB abort with no TCB
431 sctp_abort_notification(stcb, SCTP_PEER_FAULTY);
432 sctp_free_assoc(inp, stcb);
433 /* no need to unlock here, since the TCB is gone */
436 /* Send all others to the app */
437 if (inp->sctp_socket) {
438 SOCK_LOCK(inp->sctp_socket);
439 inp->sctp_socket->so_error = errno;
440 sctp_sowwakeup(inp, inp->sctp_socket);
441 SOCK_UNLOCK(inp->sctp_socket);
444 SCTP_TCB_UNLOCK(stcb);
448 #if defined(__FreeBSD__) || defined(__APPLE__)
453 sctp_ctlinput(cmd, sa, vip)
463 if (sa->sa_family != AF_INET ||
464 ((struct sockaddr_in *)sa)->sin_addr.s_addr == INADDR_ANY) {
465 #if defined(__FreeBSD__) || defined(__APPLE__)
472 if (PRC_IS_REDIRECT(cmd)) {
474 } else if ((unsigned)cmd >= PRC_NCMDS || inetctlerrmap[cmd] == 0) {
475 #if defined(__FreeBSD__) || defined(__APPLE__)
482 struct sctp_inpcb *inp;
483 struct sctp_tcb *stcb;
484 struct sctp_nets *net;
485 struct sockaddr_in to, from;
487 sh = (struct sctphdr *)((caddr_t)ip + (ip->ip_hl << 2));
488 bzero(&to, sizeof(to));
489 bzero(&from, sizeof(from));
490 from.sin_family = to.sin_family = AF_INET;
491 from.sin_len = to.sin_len = sizeof(to);
492 from.sin_port = sh->src_port;
493 from.sin_addr = ip->ip_src;
494 to.sin_port = sh->dest_port;
495 to.sin_addr = ip->ip_dst;
498 * 'to' holds the dest of the packet that failed to be sent.
499 * 'from' holds our local endpoint address.
500 * Thus we reverse the to and the from in the lookup.
502 #if defined(__NetBSD__) || defined(__OpenBSD__)
507 stcb = sctp_findassociation_addr_sa((struct sockaddr *)&from,
508 (struct sockaddr *)&to,
510 if (stcb != NULL && inp && (inp->sctp_socket != NULL)) {
511 if (cmd != PRC_MSGSIZE) {
513 if (cmd == PRC_HOSTDEAD) {
516 cm = inetctlerrmap[cmd];
518 sctp_notify(inp, cm, sh,
519 (struct sockaddr *)&to, stcb,
522 /* handle possible ICMP size messages */
523 sctp_notify_mbuf(inp, stcb, net, ip, sh);
526 #if defined(__FreeBSD__) && __FreeBSD_version < 500000
527 /* XXX must be fixed for 5.x and higher, leave for 4.x */
528 if (PRC_IS_REDIRECT(cmd) && inp) {
529 in_rtchange((struct inpcb *)inp,
533 if ((stcb == NULL) && (inp != NULL)) {
534 /* reduce ref-count */
536 SCTP_INP_DECR_REF(inp);
537 SCTP_INP_WUNLOCK(inp);
543 #if defined(__FreeBSD__) || defined(__APPLE__)
550 #if defined(__FreeBSD__)
552 sctp_getcred(SYSCTL_HANDLER_ARGS)
554 struct sockaddr_in addrs[2];
555 struct sctp_inpcb *inp;
556 struct sctp_nets *net;
557 struct sctp_tcb *stcb;
560 #if __FreeBSD_version >= 500000
561 error = suser(req->td);
563 error = suser(req->p);
567 error = SYSCTL_IN(req, addrs, sizeof(addrs));
572 stcb = sctp_findassociation_addr_sa(sintosa(&addrs[0]),
575 if (stcb == NULL || inp == NULL || inp->sctp_socket == NULL) {
576 if ((inp != NULL) && (stcb == NULL)) {
577 /* reduce ref-count */
579 SCTP_INP_DECR_REF(inp);
580 SCTP_INP_WUNLOCK(inp);
585 error = SYSCTL_OUT(req, inp->sctp_socket->so_cred, sizeof(struct ucred));
586 SCTP_TCB_UNLOCK(stcb);
592 SYSCTL_PROC(_net_inet_sctp, OID_AUTO, getcred, CTLTYPE_OPAQUE|CTLFLAG_RW,
593 0, 0, sctp_getcred, "S,ucred", "Get the ucred of a SCTP connection");
594 #endif /* #if defined(__FreeBSD__) */
599 #if defined(__FreeBSD__) || defined (__APPLE__)
601 SYSCTL_INT(_net_inet_sctp, OID_AUTO, maxdgram, CTLFLAG_RW,
602 &sctp_sendspace, 0, "Maximum outgoing SCTP buffer size");
604 SYSCTL_INT(_net_inet_sctp, OID_AUTO, recvspace, CTLFLAG_RW,
605 &sctp_recvspace, 0, "Maximum incoming SCTP buffer size");
607 SYSCTL_INT(_net_inet_sctp, OID_AUTO, auto_asconf, CTLFLAG_RW,
608 &sctp_auto_asconf, 0, "Enable SCTP Auto-ASCONF");
610 SYSCTL_INT(_net_inet_sctp, OID_AUTO, ecn_enable, CTLFLAG_RW,
611 &sctp_ecn, 0, "Enable SCTP ECN");
613 SYSCTL_INT(_net_inet_sctp, OID_AUTO, ecn_nonce, CTLFLAG_RW,
614 &sctp_ecn_nonce, 0, "Enable SCTP ECN Nonce");
616 SYSCTL_INT(_net_inet_sctp, OID_AUTO, strict_sacks, CTLFLAG_RW,
617 &sctp_strict_sacks, 0, "Enable SCTP Strict SACK checking");
619 SYSCTL_INT(_net_inet_sctp, OID_AUTO, loopback_nocsum, CTLFLAG_RW,
620 &sctp_no_csum_on_loopback, 0,
621 "Enable NO Csum on packets sent on loopback");
623 SYSCTL_INT(_net_inet_sctp, OID_AUTO, strict_init, CTLFLAG_RW,
624 &sctp_strict_init, 0,
625 "Enable strict INIT/INIT-ACK singleton enforcement");
627 SYSCTL_INT(_net_inet_sctp, OID_AUTO, peer_chkoh, CTLFLAG_RW,
628 &sctp_peer_chunk_oh, 0,
629 "Amount to debit peers rwnd per chunk sent");
631 SYSCTL_INT(_net_inet_sctp, OID_AUTO, maxburst, CTLFLAG_RW,
632 &sctp_max_burst_default, 0,
633 "Default max burst for sctp endpoints");
635 SYSCTL_INT(_net_inet_sctp, OID_AUTO, maxchunks, CTLFLAG_RW,
636 &sctp_max_chunks_on_queue, 0,
637 "Default max chunks on queue per asoc");
639 SYSCTL_UINT(_net_inet_sctp, OID_AUTO, delayed_sack_time, CTLFLAG_RW,
640 &sctp_delayed_sack_time_default, 0,
641 "Default delayed SACK timer in msec");
643 SYSCTL_UINT(_net_inet_sctp, OID_AUTO, heartbeat_interval, CTLFLAG_RW,
644 &sctp_heartbeat_interval_default, 0,
645 "Default heartbeat interval in msec");
647 SYSCTL_UINT(_net_inet_sctp, OID_AUTO, pmtu_raise_time, CTLFLAG_RW,
648 &sctp_pmtu_raise_time_default, 0,
649 "Default PMTU raise timer in sec");
651 SYSCTL_UINT(_net_inet_sctp, OID_AUTO, shutdown_guard_time, CTLFLAG_RW,
652 &sctp_shutdown_guard_time_default, 0,
653 "Default shutdown guard timer in sec");
655 SYSCTL_UINT(_net_inet_sctp, OID_AUTO, secret_lifetime, CTLFLAG_RW,
656 &sctp_secret_lifetime_default, 0,
657 "Default secret lifetime in sec");
659 SYSCTL_UINT(_net_inet_sctp, OID_AUTO, rto_max, CTLFLAG_RW,
660 &sctp_rto_max_default, 0,
661 "Default maximum retransmission timeout in msec");
663 SYSCTL_UINT(_net_inet_sctp, OID_AUTO, rto_min, CTLFLAG_RW,
664 &sctp_rto_min_default, 0,
665 "Default minimum retransmission timeout in msec");
667 SYSCTL_UINT(_net_inet_sctp, OID_AUTO, rto_initial, CTLFLAG_RW,
668 &sctp_rto_initial_default, 0,
669 "Default initial retransmission timeout in msec");
671 SYSCTL_UINT(_net_inet_sctp, OID_AUTO, init_rto_max, CTLFLAG_RW,
672 &sctp_init_rto_max_default, 0,
673 "Default maximum retransmission timeout during association setup in msec");
675 SYSCTL_UINT(_net_inet_sctp, OID_AUTO, valid_cookie_life, CTLFLAG_RW,
676 &sctp_valid_cookie_life_default, 0,
677 "Default cookie lifetime in sec");
679 SYSCTL_UINT(_net_inet_sctp, OID_AUTO, init_rtx_max, CTLFLAG_RW,
680 &sctp_init_rtx_max_default, 0,
681 "Default maximum number of retransmission for INIT chunks");
683 SYSCTL_UINT(_net_inet_sctp, OID_AUTO, assoc_rtx_max, CTLFLAG_RW,
684 &sctp_assoc_rtx_max_default, 0,
685 "Default maximum number of retransmissions per association");
687 SYSCTL_UINT(_net_inet_sctp, OID_AUTO, path_rtx_max, CTLFLAG_RW,
688 &sctp_path_rtx_max_default, 0,
689 "Default maximum of retransmissions per path");
691 SYSCTL_UINT(_net_inet_sctp, OID_AUTO, nr_outgoing_streams, CTLFLAG_RW,
692 &sctp_nr_outgoing_streams_default, 0,
693 "Default number of outgoing streams");
696 SYSCTL_INT(_net_inet_sctp, OID_AUTO, debug, CTLFLAG_RW,
697 &sctp_debug_on, 0, "Configure debug output");
698 #endif /* SCTP_DEBUG */
702 sctp_abort(struct socket *so)
704 struct sctp_inpcb *inp;
707 inp = (struct sctp_inpcb *)so->so_pcb;
709 return EINVAL; /* ??? possible? panic instead? */
711 #if defined(__NetBSD__) || defined(__OpenBSD__)
716 sctp_inpcb_free(inp, 1);
722 #if defined(__FreeBSD__) && __FreeBSD_version >= 500000
723 sctp_attach(struct socket *so, int proto, struct thread *p)
725 sctp_attach(struct socket *so, int proto, struct proc *p)
728 struct sctp_inpcb *inp;
729 struct inpcb *ip_inp;
732 #if defined(__NetBSD__) || defined(__OpenBSD__)
737 inp = (struct sctp_inpcb *)so->so_pcb;
742 error = soreserve(so, sctp_sendspace, sctp_recvspace);
747 error = sctp_inpcb_alloc(so);
752 inp = (struct sctp_inpcb *)so->so_pcb;
755 inp->sctp_flags &= ~SCTP_PCB_FLAGS_BOUND_V6; /* I'm not v6! */
756 ip_inp = &inp->ip_inp.inp;
757 #if defined(__FreeBSD__) || defined(__APPLE__)
758 ip_inp->inp_vflag |= INP_IPV4;
759 ip_inp->inp_ip_ttl = ip_defttl;
761 inp->inp_vflag |= INP_IPV4;
762 inp->inp_ip_ttl = ip_defttl;
766 #if !(defined(__OpenBSD__) || defined(__APPLE__))
767 error = ipsec_init_pcbpolicy(so, &ip_inp->inp_sp);
769 sctp_inpcb_free(inp, 1);
774 SCTP_INP_WUNLOCK(inp);
775 #if defined(__NetBSD__)
776 so->so_send = sctp_sosend;
783 #if defined(__FreeBSD__) && __FreeBSD_version >= 500000
784 sctp_bind(struct socket *so, struct sockaddr *addr, struct thread *p)
786 #elif defined(__FreeBSD__) || defined(__APPLE__)
787 sctp_bind(struct socket *so, struct sockaddr *addr, struct proc *p)
790 sctp_bind(struct socket *so, struct mbuf *nam, struct proc *p)
792 struct sockaddr *addr = nam ? mtod(nam, struct sockaddr *) : NULL;
794 struct sctp_inpcb *inp;
798 if (addr && addr->sa_family != AF_INET)
799 /* must be a v4 address! */
803 inp = (struct sctp_inpcb *)so->so_pcb;
807 #if defined(__NetBSD__) || defined(__OpenBSD__)
812 error = sctp_inpcb_bind(so, addr, p);
819 sctp_detach(struct socket *so)
821 struct sctp_inpcb *inp;
823 inp = (struct sctp_inpcb *)so->so_pcb;
826 #if defined(__NetBSD__) || defined(__OpenBSD__)
831 if (((so->so_options & SO_LINGER) && (so->so_linger == 0)) ||
832 (so->so_rcv.sb_cc > 0)) {
833 sctp_inpcb_free(inp, 1);
835 sctp_inpcb_free(inp, 0);
842 #if defined(__FreeBSD__) && __FreeBSD_version >= 500000
843 sctp_send(struct socket *so, int flags, struct mbuf *m, struct sockaddr *addr,
844 struct mbuf *control, struct thread *p);
846 sctp_send(struct socket *so, int flags, struct mbuf *m, struct sockaddr *addr,
847 struct mbuf *control, struct proc *p);
851 #if defined(__FreeBSD__) && __FreeBSD_version >= 500000
852 sctp_send(struct socket *so, int flags, struct mbuf *m, struct sockaddr *addr,
853 struct mbuf *control, struct thread *p)
856 sctp_send(struct socket *so, int flags, struct mbuf *m, struct sockaddr *addr,
857 struct mbuf *control, struct proc *p)
860 struct sctp_inpcb *inp;
862 inp = (struct sctp_inpcb *)so->so_pcb;
865 sctp_m_freem(control);
871 /* Got to have an to address if we are NOT a connected socket */
872 if ((addr == NULL) &&
873 ((inp->sctp_flags & SCTP_PCB_FLAGS_CONNECTED) ||
874 (inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE))
877 } else if (addr == NULL) {
878 error = EDESTADDRREQ;
881 sctp_m_freem(control);
887 if (addr->sa_family != AF_INET) {
888 /* must be a v4 address! */
891 sctp_m_freem(control);
894 error = EDESTADDRREQ;
899 /* now what about control */
902 printf("huh? control set?\n");
903 sctp_m_freem(inp->control);
906 inp->control = control;
908 /* add it in possibly */
909 if ((inp->pkt) && (inp->pkt->m_flags & M_PKTHDR)) {
915 for (x=m;x;x = x->m_next) {
918 inp->pkt->m_pkthdr.len += c_len;
922 inp->pkt_last->m_next = m;
925 inp->pkt_last = inp->pkt = m;
928 #if defined (__FreeBSD__) || defined(__APPLE__)
929 /* FreeBSD uses a flag passed */
930 ((flags & PRUS_MORETOCOME) == 0)
931 #elif defined( __NetBSD__)
932 /* NetBSD uses the so_state field */
933 ((so->so_state & SS_MORETOCOME) == 0)
935 1 /* Open BSD does not have any "more to come" indication */
939 * note with the current version this code will only be used
940 * by OpenBSD-- NetBSD, FreeBSD, and MacOS have methods for
941 * re-defining sosend to use the sctp_sosend. One can
942 * optionally switch back to this code (by changing back the
943 * definitions) but this is not advisable.
946 ret = sctp_output(inp, inp->pkt, addr, inp->control, p, flags);
956 sctp_disconnect(struct socket *so)
958 struct sctp_inpcb *inp;
961 #if defined(__NetBSD__) || defined(__OpenBSD__)
966 inp = (struct sctp_inpcb *)so->so_pcb;
972 if (inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) {
973 if (LIST_EMPTY(&inp->sctp_asoc_list)) {
976 SCTP_INP_RUNLOCK(inp);
979 int some_on_streamwheel = 0;
980 struct sctp_association *asoc;
981 struct sctp_tcb *stcb;
983 stcb = LIST_FIRST(&inp->sctp_asoc_list);
986 SCTP_INP_RUNLOCK(inp);
991 if (((so->so_options & SO_LINGER) &&
992 (so->so_linger == 0)) ||
993 (so->so_rcv.sb_cc > 0)) {
994 if (SCTP_GET_STATE(asoc) !=
995 SCTP_STATE_COOKIE_WAIT) {
996 /* Left with Data unread */
999 MGET(err, M_DONTWAIT, MT_DATA);
1001 /* Fill in the user initiated abort */
1002 struct sctp_paramhdr *ph;
1003 ph = mtod(err, struct sctp_paramhdr *);
1004 err->m_len = sizeof(struct sctp_paramhdr);
1005 ph->param_type = htons(SCTP_CAUSE_USER_INITIATED_ABT);
1006 ph->param_length = htons(err->m_len);
1008 sctp_send_abort_tcb(stcb, err);
1010 SCTP_INP_RUNLOCK(inp);
1011 sctp_free_assoc(inp, stcb);
1012 /* No unlock tcb assoc is gone */
1016 if (!TAILQ_EMPTY(&asoc->out_wheel)) {
1017 /* Check to see if some data queued */
1018 struct sctp_stream_out *outs;
1019 TAILQ_FOREACH(outs, &asoc->out_wheel,
1021 if (!TAILQ_EMPTY(&outs->outqueue)) {
1022 some_on_streamwheel = 1;
1028 if (TAILQ_EMPTY(&asoc->send_queue) &&
1029 TAILQ_EMPTY(&asoc->sent_queue) &&
1030 (some_on_streamwheel == 0)) {
1031 /* there is nothing queued to send, so done */
1032 if ((SCTP_GET_STATE(asoc) !=
1033 SCTP_STATE_SHUTDOWN_SENT) &&
1034 (SCTP_GET_STATE(asoc) !=
1035 SCTP_STATE_SHUTDOWN_ACK_SENT)) {
1036 /* only send SHUTDOWN 1st time thru */
1038 if (sctp_debug_on & SCTP_DEBUG_OUTPUT4) {
1039 printf("%s:%d sends a shutdown\n",
1045 sctp_send_shutdown(stcb,
1046 stcb->asoc.primary_destination);
1047 sctp_chunk_output(stcb->sctp_ep, stcb, 1);
1048 asoc->state = SCTP_STATE_SHUTDOWN_SENT;
1049 sctp_timer_start(SCTP_TIMER_TYPE_SHUTDOWN,
1050 stcb->sctp_ep, stcb,
1051 asoc->primary_destination);
1052 sctp_timer_start(SCTP_TIMER_TYPE_SHUTDOWNGUARD,
1053 stcb->sctp_ep, stcb,
1054 asoc->primary_destination);
1058 * we still got (or just got) data to send,
1059 * so set SHUTDOWN_PENDING
1062 * XXX sockets draft says that MSG_EOF should
1063 * be sent with no data.
1064 * currently, we will allow user data to be
1065 * sent first and move to SHUTDOWN-PENDING
1067 asoc->state |= SCTP_STATE_SHUTDOWN_PENDING;
1069 SCTP_TCB_UNLOCK(stcb);
1070 SCTP_INP_RUNLOCK(inp);
1076 /* UDP model does not support this */
1077 SCTP_INP_RUNLOCK(inp);
1084 sctp_shutdown(struct socket *so)
1086 struct sctp_inpcb *inp;
1089 #if defined(__NetBSD__) || defined(__OpenBSD__)
1094 inp = (struct sctp_inpcb *)so->so_pcb;
1099 SCTP_INP_RLOCK(inp);
1100 /* For UDP model this is a invalid call */
1101 if (inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) {
1102 /* Restore the flags that the soshutdown took away. */
1103 #if defined(__FreeBSD__) && __FreeBSD_version >= 502115
1104 so->so_rcv.sb_state &= ~SBS_CANTRCVMORE;
1106 so->so_state &= ~SS_CANTRCVMORE;
1108 /* This proc will wakeup for read and do nothing (I hope) */
1110 SCTP_INP_RUNLOCK(inp);
1111 return (EOPNOTSUPP);
1114 * Ok if we reach here its the TCP model and it is either a SHUT_WR
1115 * or SHUT_RDWR. This means we put the shutdown flag against it.
1118 int some_on_streamwheel = 0;
1119 struct sctp_tcb *stcb;
1120 struct sctp_association *asoc;
1123 stcb = LIST_FIRST(&inp->sctp_asoc_list);
1126 * Ok we hit the case that the shutdown call was made
1127 * after an abort or something. Nothing to do now.
1132 SCTP_TCB_LOCK(stcb);
1135 if (!TAILQ_EMPTY(&asoc->out_wheel)) {
1136 /* Check to see if some data queued */
1137 struct sctp_stream_out *outs;
1138 TAILQ_FOREACH(outs, &asoc->out_wheel, next_spoke) {
1139 if (!TAILQ_EMPTY(&outs->outqueue)) {
1140 some_on_streamwheel = 1;
1145 if (TAILQ_EMPTY(&asoc->send_queue) &&
1146 TAILQ_EMPTY(&asoc->sent_queue) &&
1147 (some_on_streamwheel == 0)) {
1148 /* there is nothing queued to send, so I'm done... */
1149 if (SCTP_GET_STATE(asoc) != SCTP_STATE_SHUTDOWN_SENT) {
1150 /* only send SHUTDOWN the first time through */
1152 if (sctp_debug_on & SCTP_DEBUG_OUTPUT4) {
1153 printf("%s:%d sends a shutdown\n",
1159 sctp_send_shutdown(stcb,
1160 stcb->asoc.primary_destination);
1161 sctp_chunk_output(stcb->sctp_ep, stcb, 1);
1162 asoc->state = SCTP_STATE_SHUTDOWN_SENT;
1163 sctp_timer_start(SCTP_TIMER_TYPE_SHUTDOWN,
1164 stcb->sctp_ep, stcb,
1165 asoc->primary_destination);
1166 sctp_timer_start(SCTP_TIMER_TYPE_SHUTDOWNGUARD,
1167 stcb->sctp_ep, stcb,
1168 asoc->primary_destination);
1172 * we still got (or just got) data to send, so
1173 * set SHUTDOWN_PENDING
1175 asoc->state |= SCTP_STATE_SHUTDOWN_PENDING;
1177 SCTP_TCB_UNLOCK(stcb);
1179 SCTP_INP_RUNLOCK(inp);
1185 * copies a "user" presentable address and removes embedded scope, etc.
1186 * returns 0 on success, 1 on error
1189 sctp_fill_user_address(struct sockaddr_storage *ss, struct sockaddr *sa)
1191 struct sockaddr_in6 lsa6;
1192 sa = (struct sockaddr *)sctp_recover_scope((struct sockaddr_in6 *)sa,
1194 memcpy(ss, sa, sa->sa_len);
1199 #if defined(__NetBSD__) || defined(__OpenBSD__)
1201 * On NetBSD and OpenBSD in6_sin_2_v4mapsin6() not used and not exported,
1202 * so we have to export it here.
1204 void in6_sin_2_v4mapsin6 __P((struct sockaddr_in *sin,
1205 struct sockaddr_in6 *sin6));
1209 sctp_fill_up_addresses(struct sctp_inpcb *inp,
1210 struct sctp_tcb *stcb,
1212 struct sockaddr_storage *sas)
1216 int loopback_scope, ipv4_local_scope, local_scope, site_scope, actual;
1217 int ipv4_addr_legal, ipv6_addr_legal;
1223 /* Turn on all the appropriate scope */
1224 loopback_scope = stcb->asoc.loopback_scope;
1225 ipv4_local_scope = stcb->asoc.ipv4_local_scope;
1226 local_scope = stcb->asoc.local_scope;
1227 site_scope = stcb->asoc.site_scope;
1229 /* Turn on ALL scope, since we look at the EP */
1230 loopback_scope = ipv4_local_scope = local_scope =
1233 ipv4_addr_legal = ipv6_addr_legal = 0;
1234 if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) {
1235 ipv6_addr_legal = 1;
1237 #if defined(__OpenBSD__)
1238 (0) /* we always do dual bind */
1239 #elif defined (__NetBSD__)
1240 (((struct in6pcb *)inp)->in6p_flags & IN6P_IPV6_V6ONLY)
1242 (((struct in6pcb *)inp)->inp_flags & IN6P_IPV6_V6ONLY)
1245 ipv4_addr_legal = 1;
1248 ipv4_addr_legal = 1;
1251 if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUNDALL) {
1252 TAILQ_FOREACH(ifn, &ifnet, if_list) {
1253 if ((loopback_scope == 0) &&
1254 (ifn->if_type == IFT_LOOP)) {
1255 /* Skip loopback if loopback_scope not set */
1258 TAILQ_FOREACH(ifa, &ifn->if_addrlist, ifa_list) {
1261 * For the BOUND-ALL case, the list
1262 * associated with a TCB is Always
1263 * considered a reverse list.. i.e.
1264 * it lists addresses that are NOT
1265 * part of the association. If this
1266 * is one of those we must skip it.
1268 if (sctp_is_addr_restricted(stcb,
1273 if ((ifa->ifa_addr->sa_family == AF_INET) &&
1274 (ipv4_addr_legal)) {
1275 struct sockaddr_in *sin;
1276 sin = (struct sockaddr_in *)ifa->ifa_addr;
1277 if (sin->sin_addr.s_addr == 0) {
1278 /* we skip unspecifed addresses */
1281 if ((ipv4_local_scope == 0) &&
1282 (IN4_ISPRIVATE_ADDRESS(&sin->sin_addr))) {
1285 if (inp->sctp_flags & SCTP_PCB_FLAGS_NEEDS_MAPPED_V4) {
1286 in6_sin_2_v4mapsin6(sin, (struct sockaddr_in6 *)sas);
1287 ((struct sockaddr_in6 *)sas)->sin6_port = inp->sctp_lport;
1288 sas = (struct sockaddr_storage *)((caddr_t)sas + sizeof(struct sockaddr_in6));
1289 actual += sizeof(sizeof(struct sockaddr_in6));
1291 memcpy(sas, sin, sizeof(*sin));
1292 ((struct sockaddr_in *)sas)->sin_port = inp->sctp_lport;
1293 sas = (struct sockaddr_storage *)((caddr_t)sas + sizeof(*sin));
1294 actual += sizeof(*sin);
1296 if (actual >= limit) {
1299 } else if ((ifa->ifa_addr->sa_family == AF_INET6) &&
1300 (ipv6_addr_legal)) {
1301 struct sockaddr_in6 *sin6, lsa6;
1302 sin6 = (struct sockaddr_in6 *)ifa->ifa_addr;
1303 if (IN6_IS_ADDR_UNSPECIFIED(&sin6->sin6_addr)) {
1304 /* we skip unspecifed addresses */
1307 if (IN6_IS_ADDR_LINKLOCAL(&sin6->sin6_addr)) {
1308 if (local_scope == 0)
1310 if (sin6->sin6_scope_id == 0) {
1312 if (in6_recoverscope(&lsa6,
1315 /* bad link local address */
1320 if ((site_scope == 0) &&
1321 (IN6_IS_ADDR_SITELOCAL(&sin6->sin6_addr))) {
1324 memcpy(sas, sin6, sizeof(*sin6));
1325 ((struct sockaddr_in6 *)sas)->sin6_port = inp->sctp_lport;
1326 sas = (struct sockaddr_storage *)((caddr_t)sas + sizeof(*sin6));
1327 actual += sizeof(*sin6);
1328 if (actual >= limit) {
1335 struct sctp_laddr *laddr;
1337 * If we have a TCB and we do NOT support ASCONF (it's
1338 * turned off or otherwise) then the list is always the
1339 * true list of addresses (the else case below). Otherwise
1340 * the list on the association is a list of addresses that
1341 * are NOT part of the association.
1343 if (inp->sctp_flags & SCTP_PCB_FLAGS_DO_ASCONF) {
1344 /* The list is a NEGATIVE list */
1345 LIST_FOREACH(laddr, &inp->sctp_addr_list, sctp_nxt_addr) {
1347 if (sctp_is_addr_restricted(stcb, laddr->ifa->ifa_addr)) {
1351 if (sctp_fill_user_address(sas, laddr->ifa->ifa_addr))
1354 ((struct sockaddr_in6 *)sas)->sin6_port = inp->sctp_lport;
1355 sas = (struct sockaddr_storage *)((caddr_t)sas +
1356 laddr->ifa->ifa_addr->sa_len);
1357 actual += laddr->ifa->ifa_addr->sa_len;
1358 if (actual >= limit) {
1363 /* The list is a positive list if present */
1365 /* Must use the specific association list */
1366 LIST_FOREACH(laddr, &stcb->asoc.sctp_local_addr_list,
1368 if (sctp_fill_user_address(sas,
1369 laddr->ifa->ifa_addr))
1371 ((struct sockaddr_in6 *)sas)->sin6_port = inp->sctp_lport;
1372 sas = (struct sockaddr_storage *)((caddr_t)sas +
1373 laddr->ifa->ifa_addr->sa_len);
1374 actual += laddr->ifa->ifa_addr->sa_len;
1375 if (actual >= limit) {
1380 /* No endpoint so use the endpoints individual list */
1381 LIST_FOREACH(laddr, &inp->sctp_addr_list,
1383 if (sctp_fill_user_address(sas,
1384 laddr->ifa->ifa_addr))
1386 ((struct sockaddr_in6 *)sas)->sin6_port = inp->sctp_lport;
1387 sas = (struct sockaddr_storage *)((caddr_t)sas +
1388 laddr->ifa->ifa_addr->sa_len);
1389 actual += laddr->ifa->ifa_addr->sa_len;
1390 if (actual >= limit) {
1401 sctp_count_max_addresses(struct sctp_inpcb *inp)
1405 * In both sub-set bound an bound_all cases we return the MAXIMUM
1406 * number of addresses that you COULD get. In reality the sub-set
1407 * bound may have an exclusion list for a given TCB OR in the
1408 * bound-all case a TCB may NOT include the loopback or other
1409 * addresses as well.
1411 if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUNDALL) {
1415 TAILQ_FOREACH(ifn, &ifnet, if_list) {
1416 TAILQ_FOREACH(ifa, &ifn->if_addrlist, ifa_list) {
1417 /* Count them if they are the right type */
1418 if (ifa->ifa_addr->sa_family == AF_INET) {
1419 if (inp->sctp_flags & SCTP_PCB_FLAGS_NEEDS_MAPPED_V4)
1420 cnt += sizeof(struct sockaddr_in6);
1422 cnt += sizeof(struct sockaddr_in);
1424 } else if (ifa->ifa_addr->sa_family == AF_INET6)
1425 cnt += sizeof(struct sockaddr_in6);
1429 struct sctp_laddr *laddr;
1430 LIST_FOREACH(laddr, &inp->sctp_addr_list, sctp_nxt_addr) {
1431 if (laddr->ifa->ifa_addr->sa_family == AF_INET) {
1432 if (inp->sctp_flags & SCTP_PCB_FLAGS_NEEDS_MAPPED_V4)
1433 cnt += sizeof(struct sockaddr_in6);
1435 cnt += sizeof(struct sockaddr_in);
1437 } else if (laddr->ifa->ifa_addr->sa_family == AF_INET6)
1438 cnt += sizeof(struct sockaddr_in6);
1445 sctp_do_connect_x(struct socket *so,
1446 struct sctp_inpcb *inp,
1448 #if defined(__FreeBSD__) && __FreeBSD_version >= 500000
1456 #if defined(__NetBSD__) || defined(__OpenBSD__)
1457 int s = splsoftnet();
1462 struct sctp_tcb *stcb = NULL;
1463 struct sockaddr *sa;
1464 int num_v6=0, num_v4=0, *totaddrp, totaddr, i, incr, at;
1466 if (sctp_debug_on & SCTP_DEBUG_PCB1) {
1467 printf("Connectx called\n");
1469 #endif /* SCTP_DEBUG */
1471 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) &&
1472 (inp->sctp_flags & SCTP_PCB_FLAGS_CONNECTED)) {
1473 /* We are already connected AND the TCP model */
1475 return (EADDRINUSE);
1477 if (inp->sctp_flags & SCTP_PCB_FLAGS_CONNECTED) {
1478 SCTP_INP_RLOCK(inp);
1479 stcb = LIST_FIRST(&inp->sctp_asoc_list);
1480 SCTP_INP_RUNLOCK(inp);
1487 SCTP_ASOC_CREATE_LOCK(inp);
1488 if ((inp->sctp_flags & SCTP_PCB_FLAGS_SOCKET_GONE) ||
1489 (inp->sctp_flags & SCTP_PCB_FLAGS_SOCKET_GONE)) {
1490 SCTP_ASOC_CREATE_UNLOCK(inp);
1495 totaddrp = mtod(m, int *);
1496 totaddr = *totaddrp;
1497 sa = (struct sockaddr *)(totaddrp + 1);
1499 /* account and validate addresses */
1500 SCTP_INP_WLOCK(inp);
1501 SCTP_INP_INCR_REF(inp);
1502 SCTP_INP_WUNLOCK(inp);
1503 for (i = 0; i < totaddr; i++) {
1504 if (sa->sa_family == AF_INET) {
1506 incr = sizeof(struct sockaddr_in);
1507 } else if (sa->sa_family == AF_INET6) {
1508 struct sockaddr_in6 *sin6;
1509 sin6 = (struct sockaddr_in6 *)sa;
1510 if (IN6_IS_ADDR_V4MAPPED(&sin6->sin6_addr)) {
1511 /* Must be non-mapped for connectx */
1512 SCTP_ASOC_CREATE_UNLOCK(inp);
1517 incr = sizeof(struct sockaddr_in6);
1522 stcb = sctp_findassociation_ep_addr(&inp, sa, NULL, NULL, NULL);
1524 /* Already have or am bring up an association */
1525 SCTP_ASOC_CREATE_UNLOCK(inp);
1526 SCTP_TCB_UNLOCK(stcb);
1530 if ((at + incr) > m->m_len) {
1534 sa = (struct sockaddr *)((caddr_t)sa + incr);
1536 sa = (struct sockaddr *)(totaddrp + 1);
1537 SCTP_INP_WLOCK(inp);
1538 SCTP_INP_DECR_REF(inp);
1539 SCTP_INP_WUNLOCK(inp);
1541 if (((inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) == 0) &&
1544 SCTP_INP_WUNLOCK(inp);
1545 SCTP_ASOC_CREATE_UNLOCK(inp);
1548 if ((inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) &&
1550 struct in6pcb *inp6;
1551 inp6 = (struct in6pcb *)inp;
1553 #if defined(__OpenBSD__)
1554 (0) /* we always do dual bind */
1555 #elif defined (__NetBSD__)
1556 (inp6->in6p_flags & IN6P_IPV6_V6ONLY)
1558 (inp6->inp_flags & IN6P_IPV6_V6ONLY)
1562 * if IPV6_V6ONLY flag, ignore connections
1563 * destined to a v4 addr or v4-mapped addr
1565 SCTP_INP_WUNLOCK(inp);
1566 SCTP_ASOC_CREATE_UNLOCK(inp);
1572 if ((inp->sctp_flags & SCTP_PCB_FLAGS_UNBOUND) ==
1573 SCTP_PCB_FLAGS_UNBOUND) {
1574 /* Bind a ephemeral port */
1575 SCTP_INP_WUNLOCK(inp);
1576 error = sctp_inpcb_bind(so, NULL, p);
1578 SCTP_ASOC_CREATE_UNLOCK(inp);
1583 SCTP_INP_WUNLOCK(inp);
1585 /* We are GOOD to go */
1586 stcb = sctp_aloc_assoc(inp, sa, 1, &error, 0);
1588 /* Gak! no memory */
1589 SCTP_ASOC_CREATE_UNLOCK(inp);
1593 /* move to second address */
1594 if (sa->sa_family == AF_INET)
1595 sa = (struct sockaddr *)((caddr_t)sa + sizeof(struct sockaddr_in));
1597 sa = (struct sockaddr *)((caddr_t)sa + sizeof(struct sockaddr_in6));
1599 for (i = 1; i < totaddr; i++) {
1600 if (sa->sa_family == AF_INET) {
1601 incr = sizeof(struct sockaddr_in);
1602 if (sctp_add_remote_addr(stcb, sa, 0, 8)) {
1603 /* assoc gone no un-lock */
1604 sctp_free_assoc(inp, stcb);
1605 SCTP_ASOC_CREATE_UNLOCK(inp);
1610 } else if (sa->sa_family == AF_INET6) {
1611 incr = sizeof(struct sockaddr_in6);
1612 if (sctp_add_remote_addr(stcb, sa, 0, 8)) {
1613 /* assoc gone no un-lock */
1614 sctp_free_assoc(inp, stcb);
1615 SCTP_ASOC_CREATE_UNLOCK(inp);
1620 sa = (struct sockaddr *)((caddr_t)sa + incr);
1622 stcb->asoc.state = SCTP_STATE_COOKIE_WAIT;
1624 /* doing delayed connection */
1625 stcb->asoc.delayed_connection = 1;
1626 sctp_timer_start(SCTP_TIMER_TYPE_INIT, inp, stcb, stcb->asoc.primary_destination);
1628 SCTP_GETTIME_TIMEVAL(&stcb->asoc.time_entered);
1629 sctp_send_initiate(inp, stcb);
1631 SCTP_TCB_UNLOCK(stcb);
1632 if (stcb->sctp_ep->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) {
1633 stcb->sctp_ep->sctp_flags |= SCTP_PCB_FLAGS_CONNECTED;
1634 /* Set the connected flag so we can queue data */
1637 SCTP_ASOC_CREATE_UNLOCK(inp);
1644 sctp_optsget(struct socket *so,
1647 #if defined(__FreeBSD__) && __FreeBSD_version >= 500000
1654 struct sctp_inpcb *inp;
1656 int error, optval=0;
1657 struct sctp_tcb *stcb = NULL;
1659 inp = (struct sctp_inpcb *)so->so_pcb;
1666 if (sctp_debug_on & SCTP_DEBUG_USRREQ1) {
1667 printf("optsget:MP is NULL EINVAL\n");
1669 #endif /* SCTP_DEBUG */
1674 /* Got to have a mbuf */
1676 if (sctp_debug_on & SCTP_DEBUG_USRREQ1) {
1677 printf("Huh no mbuf\n");
1679 #endif /* SCTP_DEBUG */
1683 if (sctp_debug_on & SCTP_DEBUG_USRREQ2) {
1684 printf("optsget opt:%lxx sz:%u\n", (unsigned long)opt,
1687 #endif /* SCTP_DEBUG */
1691 case SCTP_AUTOCLOSE:
1692 case SCTP_AUTO_ASCONF:
1693 case SCTP_DISABLE_FRAGMENTS:
1694 case SCTP_I_WANT_MAPPED_V4_ADDR:
1696 if (sctp_debug_on & SCTP_DEBUG_USRREQ2) {
1697 printf("other stuff\n");
1699 #endif /* SCTP_DEBUG */
1700 SCTP_INP_RLOCK(inp);
1702 case SCTP_DISABLE_FRAGMENTS:
1703 optval = inp->sctp_flags & SCTP_PCB_FLAGS_NO_FRAGMENT;
1705 case SCTP_I_WANT_MAPPED_V4_ADDR:
1706 optval = inp->sctp_flags & SCTP_PCB_FLAGS_NEEDS_MAPPED_V4;
1708 case SCTP_AUTO_ASCONF:
1709 optval = inp->sctp_flags & SCTP_PCB_FLAGS_AUTO_ASCONF;
1712 optval = inp->sctp_flags & SCTP_PCB_FLAGS_NODELAY;
1714 case SCTP_AUTOCLOSE:
1715 if ((inp->sctp_flags & SCTP_PCB_FLAGS_AUTOCLOSE) ==
1716 SCTP_PCB_FLAGS_AUTOCLOSE)
1717 optval = inp->sctp_ep.auto_close_time;
1723 error = ENOPROTOOPT;
1724 } /* end switch (sopt->sopt_name) */
1725 if (opt != SCTP_AUTOCLOSE) {
1726 /* make it an "on/off" value */
1727 optval = (optval != 0);
1729 if ((size_t)m->m_len < sizeof(int)) {
1732 SCTP_INP_RUNLOCK(inp);
1734 /* return the option value */
1735 *mtod(m, int *) = optval;
1736 m->m_len = sizeof(optval);
1739 case SCTP_GET_ASOC_ID_LIST:
1741 struct sctp_assoc_ids *ids;
1745 if ((size_t)m->m_len < sizeof(struct sctp_assoc_ids)) {
1749 ids = mtod(m, struct sctp_assoc_ids *);
1751 SCTP_INP_RLOCK(inp);
1752 stcb = LIST_FIRST(&inp->sctp_asoc_list);
1755 ids->asls_numb_present = 0;
1756 ids->asls_more_to_get = 0;
1757 SCTP_INP_RUNLOCK(inp);
1760 orig = ids->asls_assoc_start;
1761 stcb = LIST_FIRST(&inp->sctp_asoc_list);
1763 stcb = LIST_NEXT(stcb , sctp_tcblist);
1771 ids->asls_numb_present = 0;
1772 ids->asls_more_to_get = 1;
1773 while(at < MAX_ASOC_IDS_RET) {
1774 ids->asls_assoc_id[at] = sctp_get_associd(stcb);
1776 ids->asls_numb_present++;
1777 stcb = LIST_NEXT(stcb , sctp_tcblist);
1779 ids->asls_more_to_get = 0;
1783 SCTP_INP_RUNLOCK(inp);
1786 case SCTP_GET_NONCE_VALUES:
1788 struct sctp_get_nonce_values *gnv;
1789 if ((size_t)m->m_len < sizeof(struct sctp_get_nonce_values)) {
1793 gnv = mtod(m, struct sctp_get_nonce_values *);
1794 stcb = sctp_findassociation_ep_asocid(inp, gnv->gn_assoc_id);
1798 gnv->gn_peers_tag = stcb->asoc.peer_vtag;
1799 gnv->gn_local_tag = stcb->asoc.my_vtag;
1800 SCTP_TCB_UNLOCK(stcb);
1805 case SCTP_PEER_PUBLIC_KEY:
1806 case SCTP_MY_PUBLIC_KEY:
1807 case SCTP_SET_AUTH_CHUNKS:
1808 case SCTP_SET_AUTH_SECRET:
1809 /* not supported yet and until we refine the draft */
1813 case SCTP_DELAYED_ACK_TIME:
1816 if ((size_t)m->m_len < sizeof(int32_t)) {
1820 tm = mtod(m, int32_t *);
1822 *tm = TICKS_TO_MSEC(inp->sctp_ep.sctp_timeoutticks[SCTP_TIMER_RECV]);
1826 case SCTP_GET_SNDBUF_USE:
1827 if ((size_t)m->m_len < sizeof(struct sctp_sockstat)) {
1830 struct sctp_sockstat *ss;
1831 struct sctp_tcb *stcb;
1832 struct sctp_association *asoc;
1833 ss = mtod(m, struct sctp_sockstat *);
1834 stcb = sctp_findassociation_ep_asocid(inp, ss->ss_assoc_id);
1839 ss->ss_total_sndbuf = (u_int32_t)asoc->total_output_queue_size;
1840 ss->ss_total_mbuf_sndbuf = (u_int32_t)asoc->total_output_mbuf_queue_size;
1841 ss->ss_total_recv_buf = (u_int32_t)(asoc->size_on_delivery_queue +
1842 asoc->size_on_reasm_queue +
1843 asoc->size_on_all_streams);
1844 SCTP_TCB_UNLOCK(stcb);
1846 m->m_len = sizeof(struct sctp_sockstat);
1853 burst = mtod(m, u_int8_t *);
1854 SCTP_INP_RLOCK(inp);
1855 *burst = inp->sctp_ep.max_burst;
1856 SCTP_INP_RUNLOCK(inp);
1857 m->m_len = sizeof(u_int8_t);
1863 sctp_assoc_t *assoc_id;
1866 if ((size_t)m->m_len < sizeof(u_int32_t)) {
1870 if ((size_t)m->m_len < sizeof(sctp_assoc_t)) {
1874 assoc_id = mtod(m, sctp_assoc_t *);
1875 segsize = mtod(m, u_int32_t *);
1876 m->m_len = sizeof(u_int32_t);
1878 if (((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) &&
1879 (inp->sctp_flags & SCTP_PCB_FLAGS_CONNECTED)) ||
1880 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL)) {
1881 struct sctp_tcb *stcb;
1882 SCTP_INP_RLOCK(inp);
1883 stcb = LIST_FIRST(&inp->sctp_asoc_list);
1885 SCTP_TCB_LOCK(stcb);
1886 SCTP_INP_RUNLOCK(inp);
1887 *segsize = sctp_get_frag_point(stcb, &stcb->asoc);
1888 SCTP_TCB_UNLOCK(stcb);
1890 SCTP_INP_RUNLOCK(inp);
1894 stcb = sctp_findassociation_ep_asocid(inp, *assoc_id);
1896 *segsize = sctp_get_frag_point(stcb, &stcb->asoc);
1897 SCTP_TCB_UNLOCK(stcb);
1901 /* default is to get the max, if I
1902 * can't calculate from an existing association.
1904 if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) {
1905 ovh = SCTP_MED_OVERHEAD;
1907 ovh = SCTP_MED_V4_OVERHEAD;
1909 *segsize = inp->sctp_frag_point - ovh;
1914 case SCTP_SET_DEBUG_LEVEL:
1918 if ((size_t)m->m_len < sizeof(u_int32_t)) {
1922 level = mtod(m, u_int32_t *);
1924 *level = sctp_debug_on;
1925 m->m_len = sizeof(u_int32_t);
1926 printf("Returning DEBUG LEVEL %x is set\n",
1927 (u_int)sctp_debug_on);
1929 #else /* SCTP_DEBUG */
1933 case SCTP_GET_STAT_LOG:
1934 #ifdef SCTP_STAT_LOGGING
1935 error = sctp_fill_stat_log(m);
1936 #else /* SCTP_DEBUG */
1943 if ((size_t)m->m_len < sizeof(sctp_pegs)) {
1947 pt = mtod(m, u_int32_t *);
1948 memcpy(pt, sctp_pegs, sizeof(sctp_pegs));
1949 m->m_len = sizeof(sctp_pegs);
1954 struct sctp_event_subscribe *events;
1956 if (sctp_debug_on & SCTP_DEBUG_USRREQ2) {
1957 printf("get events\n");
1959 #endif /* SCTP_DEBUG */
1960 if ((size_t)m->m_len < sizeof(struct sctp_event_subscribe)) {
1962 if (sctp_debug_on & SCTP_DEBUG_USRREQ2) {
1963 printf("M->M_LEN is %d not %d\n",
1965 (int)sizeof(struct sctp_event_subscribe));
1967 #endif /* SCTP_DEBUG */
1971 events = mtod(m, struct sctp_event_subscribe *);
1972 memset(events, 0, sizeof(events));
1973 SCTP_INP_RLOCK(inp);
1974 if (inp->sctp_flags & SCTP_PCB_FLAGS_RECVDATAIOEVNT)
1975 events->sctp_data_io_event = 1;
1977 if (inp->sctp_flags & SCTP_PCB_FLAGS_RECVASSOCEVNT)
1978 events->sctp_association_event = 1;
1980 if (inp->sctp_flags & SCTP_PCB_FLAGS_RECVPADDREVNT)
1981 events->sctp_address_event = 1;
1983 if (inp->sctp_flags & SCTP_PCB_FLAGS_RECVSENDFAILEVNT)
1984 events->sctp_send_failure_event = 1;
1986 if (inp->sctp_flags & SCTP_PCB_FLAGS_RECVPEERERR)
1987 events->sctp_peer_error_event = 1;
1989 if (inp->sctp_flags & SCTP_PCB_FLAGS_RECVSHUTDOWNEVNT)
1990 events->sctp_shutdown_event = 1;
1992 if (inp->sctp_flags & SCTP_PCB_FLAGS_PDAPIEVNT)
1993 events->sctp_partial_delivery_event = 1;
1995 if (inp->sctp_flags & SCTP_PCB_FLAGS_ADAPTIONEVNT)
1996 events->sctp_adaption_layer_event = 1;
1998 if (inp->sctp_flags & SCTP_PCB_FLAGS_STREAM_RESETEVNT)
1999 events->sctp_stream_reset_events = 1;
2000 SCTP_INP_RUNLOCK(inp);
2001 m->m_len = sizeof(struct sctp_event_subscribe);
2006 case SCTP_ADAPTION_LAYER:
2007 if ((size_t)m->m_len < sizeof(int)) {
2012 if (sctp_debug_on & SCTP_DEBUG_USRREQ1) {
2013 printf("getadaption ind\n");
2015 #endif /* SCTP_DEBUG */
2016 SCTP_INP_RLOCK(inp);
2017 *mtod(m, int *) = inp->sctp_ep.adaption_layer_indicator;
2018 SCTP_INP_RUNLOCK(inp);
2019 m->m_len = sizeof(int);
2021 case SCTP_SET_INITIAL_DBG_SEQ:
2022 if ((size_t)m->m_len < sizeof(int)) {
2027 if (sctp_debug_on & SCTP_DEBUG_USRREQ1) {
2028 printf("get initial dbg seq\n");
2030 #endif /* SCTP_DEBUG */
2031 SCTP_INP_RLOCK(inp);
2032 *mtod(m, int *) = inp->sctp_ep.initial_sequence_debug;
2033 SCTP_INP_RUNLOCK(inp);
2034 m->m_len = sizeof(int);
2036 case SCTP_GET_LOCAL_ADDR_SIZE:
2037 if ((size_t)m->m_len < sizeof(int)) {
2042 if (sctp_debug_on & SCTP_DEBUG_USRREQ1) {
2043 printf("get local sizes\n");
2045 #endif /* SCTP_DEBUG */
2046 SCTP_INP_RLOCK(inp);
2047 *mtod(m, int *) = sctp_count_max_addresses(inp);
2048 SCTP_INP_RUNLOCK(inp);
2049 m->m_len = sizeof(int);
2051 case SCTP_GET_REMOTE_ADDR_SIZE:
2053 sctp_assoc_t *assoc_id;
2055 struct sctp_nets *net;
2057 if (sctp_debug_on & SCTP_DEBUG_USRREQ1) {
2058 printf("get remote size\n");
2060 #endif /* SCTP_DEBUG */
2061 if ((size_t)m->m_len < sizeof(sctp_assoc_t)) {
2063 printf("m->m_len:%d not %d\n",
2064 m->m_len, sizeof(sctp_assoc_t));
2065 #endif /* SCTP_DEBUG */
2070 val = mtod(m, u_int32_t *);
2071 if (inp->sctp_flags & SCTP_PCB_FLAGS_CONNECTED) {
2072 SCTP_INP_RLOCK(inp);
2073 stcb = LIST_FIRST(&inp->sctp_asoc_list);
2075 SCTP_TCB_LOCK(stcb);
2076 SCTP_INP_RUNLOCK(inp);
2079 assoc_id = mtod(m, sctp_assoc_t *);
2080 stcb = sctp_findassociation_ep_asocid(inp, *assoc_id);
2089 /* Count the sizes */
2090 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
2091 if ((stcb->sctp_ep->sctp_flags & SCTP_PCB_FLAGS_NEEDS_MAPPED_V4) ||
2092 (((struct sockaddr *)&net->ro._l_addr)->sa_family == AF_INET6)) {
2093 sz += sizeof(struct sockaddr_in6);
2094 } else if (((struct sockaddr *)&net->ro._l_addr)->sa_family == AF_INET) {
2095 sz += sizeof(struct sockaddr_in);
2101 SCTP_TCB_UNLOCK(stcb);
2103 m->m_len = sizeof(u_int32_t);
2106 case SCTP_GET_PEER_ADDRESSES:
2108 * Get the address information, an array
2109 * is passed in to fill up we pack it.
2113 struct sockaddr_storage *sas;
2114 struct sctp_nets *net;
2115 struct sctp_getaddresses *saddr;
2117 if (sctp_debug_on & SCTP_DEBUG_USRREQ1) {
2118 printf("get peer addresses\n");
2120 #endif /* SCTP_DEBUG */
2121 if ((size_t)m->m_len < sizeof(struct sctp_getaddresses)) {
2125 left = m->m_len - sizeof(struct sctp_getaddresses);
2126 saddr = mtod(m, struct sctp_getaddresses *);
2127 if (inp->sctp_flags & SCTP_PCB_FLAGS_CONNECTED) {
2128 SCTP_INP_RLOCK(inp);
2129 stcb = LIST_FIRST(&inp->sctp_asoc_list);
2131 SCTP_TCB_LOCK(stcb);
2132 SCTP_INP_RUNLOCK(inp);
2134 stcb = sctp_findassociation_ep_asocid(inp,
2135 saddr->sget_assoc_id);
2140 m->m_len = sizeof(struct sctp_getaddresses);
2141 sas = (struct sockaddr_storage *)&saddr->addr[0];
2143 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
2144 if ((stcb->sctp_ep->sctp_flags & SCTP_PCB_FLAGS_NEEDS_MAPPED_V4) ||
2145 (((struct sockaddr *)&net->ro._l_addr)->sa_family == AF_INET6)) {
2146 cpsz = sizeof(struct sockaddr_in6);
2147 } else if (((struct sockaddr *)&net->ro._l_addr)->sa_family == AF_INET) {
2148 cpsz = sizeof(struct sockaddr_in);
2154 /* not enough room. */
2156 if (sctp_debug_on & SCTP_DEBUG_USRREQ1) {
2157 printf("Out of room\n");
2159 #endif /* SCTP_DEBUG */
2162 if ((stcb->sctp_ep->sctp_flags & SCTP_PCB_FLAGS_NEEDS_MAPPED_V4) &&
2163 (((struct sockaddr *)&net->ro._l_addr)->sa_family == AF_INET)) {
2164 /* Must map the address */
2165 in6_sin_2_v4mapsin6((struct sockaddr_in *)&net->ro._l_addr,
2166 (struct sockaddr_in6 *)sas);
2168 memcpy(sas, &net->ro._l_addr, cpsz);
2170 ((struct sockaddr_in *)sas)->sin_port = stcb->rport;
2172 sas = (struct sockaddr_storage *)((caddr_t)sas + cpsz);
2176 if (sctp_debug_on & SCTP_DEBUG_USRREQ2) {
2177 printf("left now:%d mlen:%d\n",
2180 #endif /* SCTP_DEBUG */
2182 SCTP_TCB_UNLOCK(stcb);
2185 if (sctp_debug_on & SCTP_DEBUG_USRREQ1) {
2186 printf("All done\n");
2188 #endif /* SCTP_DEBUG */
2190 case SCTP_GET_LOCAL_ADDRESSES:
2193 struct sockaddr_storage *sas;
2194 struct sctp_getaddresses *saddr;
2196 if (sctp_debug_on & SCTP_DEBUG_USRREQ1) {
2197 printf("get local addresses\n");
2199 #endif /* SCTP_DEBUG */
2200 if ((size_t)m->m_len < sizeof(struct sctp_getaddresses)) {
2204 saddr = mtod(m, struct sctp_getaddresses *);
2206 if (saddr->sget_assoc_id) {
2207 if (inp->sctp_flags & SCTP_PCB_FLAGS_CONNECTED) {
2208 SCTP_INP_RLOCK(inp);
2209 stcb = LIST_FIRST(&inp->sctp_asoc_list);
2211 SCTP_TCB_LOCK(stcb);
2212 SCTP_INP_RUNLOCK(inp);
2214 stcb = sctp_findassociation_ep_asocid(inp, saddr->sget_assoc_id);
2220 * assure that the TCP model does not need a assoc id
2223 if ( (inp->sctp_flags & SCTP_PCB_FLAGS_CONNECTED) &&
2225 SCTP_INP_RLOCK(inp);
2226 stcb = LIST_FIRST(&inp->sctp_asoc_list);
2228 SCTP_TCB_LOCK(stcb);
2229 SCTP_INP_RUNLOCK(inp);
2231 sas = (struct sockaddr_storage *)&saddr->addr[0];
2232 limit = m->m_len - sizeof(sctp_assoc_t);
2233 actual = sctp_fill_up_addresses(inp, stcb, limit, sas);
2234 SCTP_TCB_UNLOCK(stcb);
2235 m->m_len = sizeof(struct sockaddr_storage) + actual;
2238 case SCTP_PEER_ADDR_PARAMS:
2240 struct sctp_paddrparams *paddrp;
2241 struct sctp_nets *net;
2244 if (sctp_debug_on & SCTP_DEBUG_USRREQ1) {
2245 printf("Getting peer_addr_params\n");
2247 #endif /* SCTP_DEBUG */
2248 if ((size_t)m->m_len < sizeof(struct sctp_paddrparams)) {
2250 if (sctp_debug_on & SCTP_DEBUG_USRREQ2) {
2251 printf("Hmm m->m_len:%d is to small\n",
2254 #endif /* SCTP_DEBUG */
2258 paddrp = mtod(m, struct sctp_paddrparams *);
2261 if (paddrp->spp_assoc_id) {
2263 if (sctp_debug_on & SCTP_DEBUG_USRREQ1) {
2264 printf("In spp_assoc_id find type\n");
2266 #endif /* SCTP_DEBUG */
2267 if (inp->sctp_flags & SCTP_PCB_FLAGS_CONNECTED) {
2268 SCTP_INP_RLOCK(inp);
2269 stcb = LIST_FIRST(&inp->sctp_asoc_list);
2271 SCTP_TCB_LOCK(stcb);
2272 net = sctp_findnet(stcb, (struct sockaddr *)&paddrp->spp_address);
2274 SCTP_INP_RLOCK(inp);
2276 stcb = sctp_findassociation_ep_asocid(inp, paddrp->spp_assoc_id);
2283 if ( (stcb == NULL) &&
2284 ((((struct sockaddr *)&paddrp->spp_address)->sa_family == AF_INET) ||
2285 (((struct sockaddr *)&paddrp->spp_address)->sa_family == AF_INET6))) {
2286 /* Lookup via address */
2288 if (sctp_debug_on & SCTP_DEBUG_USRREQ1) {
2289 printf("Ok we need to lookup a param\n");
2291 #endif /* SCTP_DEBUG */
2292 if (inp->sctp_flags & SCTP_PCB_FLAGS_CONNECTED) {
2293 SCTP_INP_RLOCK(inp);
2294 stcb = LIST_FIRST(&inp->sctp_asoc_list);
2296 SCTP_TCB_LOCK(stcb);
2297 net = sctp_findnet(stcb, (struct sockaddr *)&paddrp->spp_address);
2299 SCTP_INP_RUNLOCK(inp);
2301 SCTP_INP_WLOCK(inp);
2302 SCTP_INP_INCR_REF(inp);
2303 SCTP_INP_WUNLOCK(inp);
2304 stcb = sctp_findassociation_ep_addr(&inp,
2305 (struct sockaddr *)&paddrp->spp_address,
2308 SCTP_INP_WLOCK(inp);
2309 SCTP_INP_DECR_REF(inp);
2310 SCTP_INP_WUNLOCK(inp);
2319 /* Effects the Endpoint */
2321 if (sctp_debug_on & SCTP_DEBUG_USRREQ1) {
2322 printf("User wants EP level info\n");
2324 #endif /* SCTP_DEBUG */
2328 /* Applys to the specific association */
2330 if (sctp_debug_on & SCTP_DEBUG_USRREQ1) {
2331 printf("In TCB side\n");
2333 #endif /* SCTP_DEBUG */
2335 paddrp->spp_pathmaxrxt = net->failure_threshold;
2337 /* No destination so return default value */
2338 paddrp->spp_pathmaxrxt = stcb->asoc.def_net_failure;
2340 paddrp->spp_hbinterval = stcb->asoc.heart_beat_delay;
2341 paddrp->spp_assoc_id = sctp_get_associd(stcb);
2342 SCTP_TCB_UNLOCK(stcb);
2344 /* Use endpoint defaults */
2345 SCTP_INP_RLOCK(inp);
2347 if (sctp_debug_on & SCTP_DEBUG_USRREQ1) {
2348 printf("In EP levle info\n");
2350 #endif /* SCTP_DEBUG */
2351 paddrp->spp_pathmaxrxt = inp->sctp_ep.def_net_failure;
2352 paddrp->spp_hbinterval = inp->sctp_ep.sctp_timeoutticks[SCTP_TIMER_HEARTBEAT];
2353 paddrp->spp_assoc_id = (sctp_assoc_t)0;
2354 SCTP_INP_RUNLOCK(inp);
2356 m->m_len = sizeof(struct sctp_paddrparams);
2359 case SCTP_GET_PEER_ADDR_INFO:
2361 struct sctp_paddrinfo *paddri;
2362 struct sctp_nets *net;
2364 if (sctp_debug_on & SCTP_DEBUG_USRREQ1) {
2365 printf("GetPEER ADDR_INFO\n");
2367 #endif /* SCTP_DEBUG */
2368 if ((size_t)m->m_len < sizeof(struct sctp_paddrinfo)) {
2372 paddri = mtod(m, struct sctp_paddrinfo *);
2374 if ((((struct sockaddr *)&paddri->spinfo_address)->sa_family == AF_INET) ||
2375 (((struct sockaddr *)&paddri->spinfo_address)->sa_family == AF_INET6)) {
2376 /* Lookup via address */
2377 if (inp->sctp_flags & SCTP_PCB_FLAGS_CONNECTED) {
2378 SCTP_INP_RLOCK(inp);
2379 stcb = LIST_FIRST(&inp->sctp_asoc_list);
2381 SCTP_TCB_LOCK(stcb);
2382 net = sctp_findnet(stcb,
2383 (struct sockaddr *)&paddri->spinfo_address);
2385 SCTP_INP_RUNLOCK(inp);
2387 SCTP_INP_WLOCK(inp);
2388 SCTP_INP_INCR_REF(inp);
2389 SCTP_INP_WUNLOCK(inp);
2390 stcb = sctp_findassociation_ep_addr(&inp,
2391 (struct sockaddr *)&paddri->spinfo_address,
2394 SCTP_INP_WLOCK(inp);
2395 SCTP_INP_DECR_REF(inp);
2396 SCTP_INP_WUNLOCK(inp);
2403 if ((stcb == NULL) || (net == NULL)) {
2407 m->m_len = sizeof(struct sctp_paddrinfo);
2408 paddri->spinfo_state = net->dest_state & (SCTP_REACHABLE_MASK|SCTP_ADDR_NOHB);
2409 paddri->spinfo_cwnd = net->cwnd;
2410 paddri->spinfo_srtt = ((net->lastsa >> 2) + net->lastsv) >> 1;
2411 paddri->spinfo_rto = net->RTO;
2412 paddri->spinfo_assoc_id = sctp_get_associd(stcb);
2413 SCTP_TCB_UNLOCK(stcb);
2416 case SCTP_PCB_STATUS:
2418 struct sctp_pcbinfo *spcb;
2420 if (sctp_debug_on & SCTP_DEBUG_USRREQ1) {
2421 printf("PCB status\n");
2423 #endif /* SCTP_DEBUG */
2424 if ((size_t)m->m_len < sizeof(struct sctp_pcbinfo)) {
2428 spcb = mtod(m, struct sctp_pcbinfo *);
2429 sctp_fill_pcbinfo(spcb);
2430 m->m_len = sizeof(struct sctp_pcbinfo);
2435 struct sctp_nets *net;
2436 struct sctp_status *sstat;
2438 if (sctp_debug_on & SCTP_DEBUG_USRREQ1) {
2439 printf("SCTP status\n");
2441 #endif /* SCTP_DEBUG */
2443 if ((size_t)m->m_len < sizeof(struct sctp_status)) {
2447 sstat = mtod(m, struct sctp_status *);
2449 if (inp->sctp_flags & SCTP_PCB_FLAGS_CONNECTED) {
2450 SCTP_INP_RLOCK(inp);
2451 stcb = LIST_FIRST(&inp->sctp_asoc_list);
2453 SCTP_TCB_LOCK(stcb);
2454 SCTP_INP_RUNLOCK(inp);
2456 stcb = sctp_findassociation_ep_asocid(inp, sstat->sstat_assoc_id);
2463 * I think passing the state is fine since
2464 * sctp_constants.h will be available to the user
2467 sstat->sstat_state = stcb->asoc.state;
2468 sstat->sstat_rwnd = stcb->asoc.peers_rwnd;
2469 sstat->sstat_unackdata = stcb->asoc.sent_queue_cnt;
2471 * We can't include chunks that have been passed
2472 * to the socket layer. Only things in queue.
2474 sstat->sstat_penddata = (stcb->asoc.cnt_on_delivery_queue +
2475 stcb->asoc.cnt_on_reasm_queue +
2476 stcb->asoc.cnt_on_all_streams);
2479 sstat->sstat_instrms = stcb->asoc.streamincnt;
2480 sstat->sstat_outstrms = stcb->asoc.streamoutcnt;
2481 sstat->sstat_fragmentation_point = sctp_get_frag_point(stcb, &stcb->asoc);
2482 memcpy(&sstat->sstat_primary.spinfo_address,
2483 &stcb->asoc.primary_destination->ro._l_addr,
2484 ((struct sockaddr *)(&stcb->asoc.primary_destination->ro._l_addr))->sa_len);
2485 net = stcb->asoc.primary_destination;
2486 ((struct sockaddr_in *)&sstat->sstat_primary.spinfo_address)->sin_port = stcb->rport;
2488 * Again the user can get info from sctp_constants.h
2489 * for what the state of the network is.
2491 sstat->sstat_primary.spinfo_state = net->dest_state & SCTP_REACHABLE_MASK;
2492 sstat->sstat_primary.spinfo_cwnd = net->cwnd;
2493 sstat->sstat_primary.spinfo_srtt = net->lastsa;
2494 sstat->sstat_primary.spinfo_rto = net->RTO;
2495 sstat->sstat_primary.spinfo_mtu = net->mtu;
2496 sstat->sstat_primary.spinfo_assoc_id = sctp_get_associd(stcb);
2497 SCTP_TCB_UNLOCK(stcb);
2498 m->m_len = sizeof(*sstat);
2503 struct sctp_rtoinfo *srto;
2505 if (sctp_debug_on & SCTP_DEBUG_USRREQ1) {
2506 printf("RTO Info\n");
2508 #endif /* SCTP_DEBUG */
2509 if ((size_t)m->m_len < sizeof(struct sctp_rtoinfo)) {
2513 srto = mtod(m, struct sctp_rtoinfo *);
2514 if (srto->srto_assoc_id == 0) {
2515 /* Endpoint only please */
2516 SCTP_INP_RLOCK(inp);
2517 srto->srto_initial = inp->sctp_ep.initial_rto;
2518 srto->srto_max = inp->sctp_ep.sctp_maxrto;
2519 srto->srto_min = inp->sctp_ep.sctp_minrto;
2520 SCTP_INP_RUNLOCK(inp);
2523 if (inp->sctp_flags & SCTP_PCB_FLAGS_CONNECTED) {
2524 SCTP_INP_RLOCK(inp);
2525 stcb = LIST_FIRST(&inp->sctp_asoc_list);
2527 SCTP_TCB_LOCK(stcb);
2528 SCTP_INP_RUNLOCK(inp);
2530 stcb = sctp_findassociation_ep_asocid(inp, srto->srto_assoc_id);
2536 srto->srto_initial = stcb->asoc.initial_rto;
2537 srto->srto_max = stcb->asoc.maxrto;
2538 srto->srto_min = stcb->asoc.minrto;
2539 SCTP_TCB_UNLOCK(stcb);
2540 m->m_len = sizeof(*srto);
2543 case SCTP_ASSOCINFO:
2545 struct sctp_assocparams *sasoc;
2547 if (sctp_debug_on & SCTP_DEBUG_USRREQ1) {
2548 printf("Associnfo\n");
2550 #endif /* SCTP_DEBUG */
2551 if ((size_t)m->m_len < sizeof(struct sctp_assocparams)) {
2555 sasoc = mtod(m, struct sctp_assocparams *);
2558 if (inp->sctp_flags & SCTP_PCB_FLAGS_CONNECTED) {
2559 SCTP_INP_RLOCK(inp);
2560 stcb = LIST_FIRST(&inp->sctp_asoc_list);
2562 SCTP_TCB_LOCK(stcb);
2563 SCTP_INP_RUNLOCK(inp);
2565 if ((sasoc->sasoc_assoc_id) && (stcb == NULL)) {
2566 stcb = sctp_findassociation_ep_asocid(inp,
2567 sasoc->sasoc_assoc_id);
2577 sasoc->sasoc_asocmaxrxt = stcb->asoc.max_send_times;
2578 sasoc->sasoc_number_peer_destinations = stcb->asoc.numnets;
2579 sasoc->sasoc_peer_rwnd = stcb->asoc.peers_rwnd;
2580 sasoc->sasoc_local_rwnd = stcb->asoc.my_rwnd;
2581 sasoc->sasoc_cookie_life = stcb->asoc.cookie_life;
2582 SCTP_TCB_UNLOCK(stcb);
2584 SCTP_INP_RLOCK(inp);
2585 sasoc->sasoc_asocmaxrxt = inp->sctp_ep.max_send_times;
2586 sasoc->sasoc_number_peer_destinations = 0;
2587 sasoc->sasoc_peer_rwnd = 0;
2588 sasoc->sasoc_local_rwnd = sbspace(&inp->sctp_socket->so_rcv);
2589 sasoc->sasoc_cookie_life = inp->sctp_ep.def_cookie_life;
2590 SCTP_INP_RUNLOCK(inp);
2592 m->m_len = sizeof(*sasoc);
2595 case SCTP_DEFAULT_SEND_PARAM:
2597 struct sctp_sndrcvinfo *s_info;
2599 if (m->m_len != sizeof(struct sctp_sndrcvinfo)) {
2603 s_info = mtod(m, struct sctp_sndrcvinfo *);
2604 if (inp->sctp_flags & SCTP_PCB_FLAGS_CONNECTED) {
2605 SCTP_INP_RLOCK(inp);
2606 stcb = LIST_FIRST(&inp->sctp_asoc_list);
2608 SCTP_TCB_LOCK(stcb);
2609 SCTP_INP_RUNLOCK(inp);
2611 stcb = sctp_findassociation_ep_asocid(inp, s_info->sinfo_assoc_id);
2618 *s_info = stcb->asoc.def_send;
2619 SCTP_TCB_UNLOCK(stcb);
2620 m->m_len = sizeof(*s_info);
2624 struct sctp_initmsg *sinit;
2626 if (sctp_debug_on & SCTP_DEBUG_USRREQ1) {
2627 printf("initmsg\n");
2629 #endif /* SCTP_DEBUG */
2630 if ((size_t)m->m_len < sizeof(struct sctp_initmsg)) {
2634 sinit = mtod(m, struct sctp_initmsg *);
2635 SCTP_INP_RLOCK(inp);
2636 sinit->sinit_num_ostreams = inp->sctp_ep.pre_open_stream_count;
2637 sinit->sinit_max_instreams = inp->sctp_ep.max_open_streams_intome;
2638 sinit->sinit_max_attempts = inp->sctp_ep.max_init_times;
2639 sinit->sinit_max_init_timeo = inp->sctp_ep.initial_init_rto_max;
2640 SCTP_INP_RUNLOCK(inp);
2641 m->m_len = sizeof(*sinit);
2644 case SCTP_PRIMARY_ADDR:
2645 /* we allow a "get" operation on this */
2647 struct sctp_setprim *ssp;
2650 if (sctp_debug_on & SCTP_DEBUG_USRREQ1) {
2651 printf("setprimary\n");
2653 #endif /* SCTP_DEBUG */
2654 if ((size_t)m->m_len < sizeof(struct sctp_setprim)) {
2658 ssp = mtod(m, struct sctp_setprim *);
2659 if (inp->sctp_flags & SCTP_PCB_FLAGS_CONNECTED) {
2660 SCTP_INP_RLOCK(inp);
2661 stcb = LIST_FIRST(&inp->sctp_asoc_list);
2663 SCTP_TCB_LOCK(stcb);
2664 SCTP_INP_RUNLOCK(inp);
2666 stcb = sctp_findassociation_ep_asocid(inp, ssp->ssp_assoc_id);
2668 /* one last shot, try it by the address in */
2669 struct sctp_nets *net;
2671 SCTP_INP_WLOCK(inp);
2672 SCTP_INP_INCR_REF(inp);
2673 SCTP_INP_WUNLOCK(inp);
2674 stcb = sctp_findassociation_ep_addr(&inp,
2675 (struct sockaddr *)&ssp->ssp_addr,
2678 SCTP_INP_WLOCK(inp);
2679 SCTP_INP_DECR_REF(inp);
2680 SCTP_INP_WUNLOCK(inp);
2688 /* simply copy out the sockaddr_storage... */
2689 memcpy(&ssp->ssp_addr,
2690 &stcb->asoc.primary_destination->ro._l_addr,
2691 ((struct sockaddr *)&stcb->asoc.primary_destination->ro._l_addr)->sa_len);
2692 SCTP_TCB_UNLOCK(stcb);
2693 m->m_len = sizeof(*ssp);
2697 error = ENOPROTOOPT;
2700 } /* end switch (sopt->sopt_name) */
2705 sctp_optsset(struct socket *so,
2708 #if defined(__FreeBSD__) && __FreeBSD_version >= 500000
2715 int error, *mopt, set_opt, s;
2717 struct sctp_tcb *stcb = NULL;
2718 struct sctp_inpcb *inp;
2722 if (sctp_debug_on & SCTP_DEBUG_USRREQ1) {
2723 printf("optsset:MP is NULL EINVAL\n");
2725 #endif /* SCTP_DEBUG */
2732 inp = (struct sctp_inpcb *)so->so_pcb;
2739 case SCTP_AUTOCLOSE:
2740 case SCTP_AUTO_ASCONF:
2741 case SCTP_DISABLE_FRAGMENTS:
2742 case SCTP_I_WANT_MAPPED_V4_ADDR:
2743 /* copy in the option value */
2744 if ((size_t)m->m_len < sizeof(int)) {
2748 mopt = mtod(m, int *);
2753 case SCTP_DISABLE_FRAGMENTS:
2754 set_opt = SCTP_PCB_FLAGS_NO_FRAGMENT;
2756 case SCTP_AUTO_ASCONF:
2757 set_opt = SCTP_PCB_FLAGS_AUTO_ASCONF;
2760 case SCTP_I_WANT_MAPPED_V4_ADDR:
2761 if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) {
2762 set_opt = SCTP_PCB_FLAGS_NEEDS_MAPPED_V4;
2768 set_opt = SCTP_PCB_FLAGS_NODELAY;
2770 case SCTP_AUTOCLOSE:
2771 set_opt = SCTP_PCB_FLAGS_AUTOCLOSE;
2773 * The value is in ticks.
2774 * Note this does not effect old associations, only
2777 inp->sctp_ep.auto_close_time = (*mopt * hz);
2780 SCTP_INP_WLOCK(inp);
2782 inp->sctp_flags |= set_opt;
2784 inp->sctp_flags &= ~set_opt;
2786 SCTP_INP_WUNLOCK(inp);
2788 case SCTP_MY_PUBLIC_KEY: /* set my public key */
2789 case SCTP_SET_AUTH_CHUNKS: /* set the authenticated chunks required */
2790 case SCTP_SET_AUTH_SECRET: /* set the actual secret for the endpoint */
2791 /* not supported yet and until we refine the draft */
2795 case SCTP_CLR_STAT_LOG:
2796 #ifdef SCTP_STAT_LOGGING
2797 sctp_clr_stat_log();
2802 case SCTP_DELAYED_ACK_TIME:
2805 if ((size_t)m->m_len < sizeof(int32_t)) {
2809 tm = mtod(m, int32_t *);
2811 if ((*tm < 10) || (*tm > 500)) {
2812 /* can't be smaller than 10ms */
2813 /* MUST NOT be larger than 500ms */
2817 inp->sctp_ep.sctp_timeoutticks[SCTP_TIMER_RECV] = MSEC_TO_TICKS(*tm);
2820 case SCTP_RESET_STREAMS:
2822 struct sctp_stream_reset *strrst;
2823 uint8_t two_way, not_peer;
2825 if ((size_t)m->m_len < sizeof(struct sctp_stream_reset)) {
2829 strrst = mtod(m, struct sctp_stream_reset *);
2831 if (inp->sctp_flags & SCTP_PCB_FLAGS_CONNECTED) {
2832 SCTP_INP_RLOCK(inp);
2833 stcb = LIST_FIRST(&inp->sctp_asoc_list);
2835 SCTP_TCB_LOCK(stcb);
2836 SCTP_INP_RUNLOCK(inp);
2838 stcb = sctp_findassociation_ep_asocid(inp, strrst->strrst_assoc_id);
2843 if (stcb->asoc.peer_supports_strreset == 0) {
2844 /* Peer does not support it,
2845 * we return protocol not supported since
2846 * this is true for this feature and this
2847 * peer, not the socket request in general.
2849 error = EPROTONOSUPPORT;
2850 SCTP_TCB_UNLOCK(stcb);
2854 /* Having re-thought this code I added as I write the I-D there
2855 * is NO need for it. The peer, if we are requesting a stream-reset
2856 * will send a request to us but will itself do what we do, take
2857 * and copy off the "reset information" we send and queue TSN's
2858 * larger than the send-next in our response message. Thus they
2861 /* if (stcb->asoc.sending_seq != (stcb->asoc.last_acked_seq + 1)) {*/
2862 /* Must have all sending data ack'd before we
2863 * start this procedure. This is a bit restrictive
2864 * and we SHOULD work on changing this so ONLY the
2865 * streams being RESET get held up. So, a reset-all
2866 * would require this.. but a reset specific just
2867 * needs to be sure that the ones being reset have
2868 * nothing on the send_queue. For now we will
2869 * skip this more detailed method and do a course
2870 * way.. i.e. nothing pending ... for future FIX ME!
2876 if (stcb->asoc.stream_reset_outstanding) {
2878 SCTP_TCB_UNLOCK(stcb);
2881 if (strrst->strrst_flags == SCTP_RESET_LOCAL_RECV) {
2884 } else if (strrst->strrst_flags == SCTP_RESET_LOCAL_SEND) {
2887 } else if (strrst->strrst_flags == SCTP_RESET_BOTH) {
2892 SCTP_TCB_UNLOCK(stcb);
2895 sctp_send_str_reset_req(stcb, strrst->strrst_num_streams,
2896 strrst->strrst_list, two_way, not_peer);
2897 #if defined(__NetBSD__) || defined(__OpenBSD__)
2902 sctp_chunk_output(inp, stcb, 12);
2903 SCTP_TCB_UNLOCK(stcb);
2908 case SCTP_RESET_PEGS:
2909 memset(sctp_pegs, 0, sizeof(sctp_pegs));
2912 case SCTP_CONNECT_X:
2913 if ((size_t)m->m_len < (sizeof(int) + sizeof(struct sockaddr_in))) {
2917 error = sctp_do_connect_x(so, inp, m, p, 0);
2920 case SCTP_CONNECT_X_DELAYED:
2921 if ((size_t)m->m_len < (sizeof(int) + sizeof(struct sockaddr_in))) {
2925 error = sctp_do_connect_x(so, inp, m, p, 1);
2928 case SCTP_CONNECT_X_COMPLETE:
2930 struct sockaddr *sa;
2931 struct sctp_nets *net;
2932 if ((size_t)m->m_len < sizeof(struct sockaddr_in)) {
2936 sa = mtod(m, struct sockaddr *);
2938 if (inp->sctp_flags & SCTP_PCB_FLAGS_CONNECTED) {
2939 SCTP_INP_RLOCK(inp);
2940 stcb = LIST_FIRST(&inp->sctp_asoc_list);
2942 SCTP_TCB_LOCK(stcb);
2943 net = sctp_findnet(stcb, sa);
2945 SCTP_INP_RUNLOCK(inp);
2947 SCTP_INP_WLOCK(inp);
2948 SCTP_INP_INCR_REF(inp);
2949 SCTP_INP_WUNLOCK(inp);
2950 stcb = sctp_findassociation_ep_addr(&inp, sa, &net, NULL, NULL);
2952 SCTP_INP_WLOCK(inp);
2953 SCTP_INP_DECR_REF(inp);
2954 SCTP_INP_WUNLOCK(inp);
2962 if (stcb->asoc.delayed_connection == 1) {
2963 stcb->asoc.delayed_connection = 0;
2964 SCTP_GETTIME_TIMEVAL(&stcb->asoc.time_entered);
2965 sctp_timer_stop(SCTP_TIMER_TYPE_INIT, inp, stcb, stcb->asoc.primary_destination);
2966 sctp_send_initiate(inp, stcb);
2968 /* already expired or did not use delayed connectx */
2971 SCTP_TCB_UNLOCK(stcb);
2977 SCTP_INP_WLOCK(inp);
2978 burst = mtod(m, u_int8_t *);
2980 inp->sctp_ep.max_burst = *burst;
2982 SCTP_INP_WUNLOCK(inp);
2989 if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) {
2990 ovh = SCTP_MED_OVERHEAD;
2992 ovh = SCTP_MED_V4_OVERHEAD;
2994 segsize = mtod(m, u_int32_t *);
2999 SCTP_INP_WLOCK(inp);
3000 inp->sctp_frag_point = (*segsize+ovh);
3001 if (inp->sctp_frag_point < MHLEN) {
3002 inp->sctp_frag_point = MHLEN;
3004 SCTP_INP_WUNLOCK(inp);
3007 case SCTP_SET_DEBUG_LEVEL:
3011 if ((size_t)m->m_len < sizeof(u_int32_t)) {
3015 level = mtod(m, u_int32_t *);
3017 sctp_debug_on = (*level & (SCTP_DEBUG_ALL |
3019 printf("SETTING DEBUG LEVEL to %x\n",
3020 (u_int)sctp_debug_on);
3025 #endif /* SCTP_DEBUG */
3029 struct sctp_event_subscribe *events;
3030 if ((size_t)m->m_len < sizeof(struct sctp_event_subscribe)) {
3034 SCTP_INP_WLOCK(inp);
3035 events = mtod(m, struct sctp_event_subscribe *);
3036 if (events->sctp_data_io_event) {
3037 inp->sctp_flags |= SCTP_PCB_FLAGS_RECVDATAIOEVNT;
3039 inp->sctp_flags &= ~SCTP_PCB_FLAGS_RECVDATAIOEVNT;
3042 if (events->sctp_association_event) {
3043 inp->sctp_flags |= SCTP_PCB_FLAGS_RECVASSOCEVNT;
3045 inp->sctp_flags &= ~SCTP_PCB_FLAGS_RECVASSOCEVNT;
3048 if (events->sctp_address_event) {
3049 inp->sctp_flags |= SCTP_PCB_FLAGS_RECVPADDREVNT;
3051 inp->sctp_flags &= ~SCTP_PCB_FLAGS_RECVPADDREVNT;
3054 if (events->sctp_send_failure_event) {
3055 inp->sctp_flags |= SCTP_PCB_FLAGS_RECVSENDFAILEVNT;
3057 inp->sctp_flags &= ~SCTP_PCB_FLAGS_RECVSENDFAILEVNT;
3060 if (events->sctp_peer_error_event) {
3061 inp->sctp_flags |= SCTP_PCB_FLAGS_RECVPEERERR;
3063 inp->sctp_flags &= ~SCTP_PCB_FLAGS_RECVPEERERR;
3066 if (events->sctp_shutdown_event) {
3067 inp->sctp_flags |= SCTP_PCB_FLAGS_RECVSHUTDOWNEVNT;
3069 inp->sctp_flags &= ~SCTP_PCB_FLAGS_RECVSHUTDOWNEVNT;
3072 if (events->sctp_partial_delivery_event) {
3073 inp->sctp_flags |= SCTP_PCB_FLAGS_PDAPIEVNT;
3075 inp->sctp_flags &= ~SCTP_PCB_FLAGS_PDAPIEVNT;
3078 if (events->sctp_adaption_layer_event) {
3079 inp->sctp_flags |= SCTP_PCB_FLAGS_ADAPTIONEVNT;
3081 inp->sctp_flags &= ~SCTP_PCB_FLAGS_ADAPTIONEVNT;
3084 if (events->sctp_stream_reset_events) {
3085 inp->sctp_flags |= SCTP_PCB_FLAGS_STREAM_RESETEVNT;
3087 inp->sctp_flags &= ~SCTP_PCB_FLAGS_STREAM_RESETEVNT;
3089 SCTP_INP_WUNLOCK(inp);
3093 case SCTP_ADAPTION_LAYER:
3095 struct sctp_setadaption *adap_bits;
3096 if ((size_t)m->m_len < sizeof(struct sctp_setadaption)) {
3100 SCTP_INP_WLOCK(inp);
3101 adap_bits = mtod(m, struct sctp_setadaption *);
3102 inp->sctp_ep.adaption_layer_indicator = adap_bits->ssb_adaption_ind;
3103 SCTP_INP_WUNLOCK(inp);
3106 case SCTP_SET_INITIAL_DBG_SEQ:
3109 if ((size_t)m->m_len < sizeof(u_int32_t)) {
3113 SCTP_INP_WLOCK(inp);
3114 vvv = mtod(m, u_int32_t *);
3115 inp->sctp_ep.initial_sequence_debug = *vvv;
3116 SCTP_INP_WUNLOCK(inp);
3119 case SCTP_DEFAULT_SEND_PARAM:
3121 struct sctp_sndrcvinfo *s_info;
3123 if (m->m_len != sizeof(struct sctp_sndrcvinfo)) {
3127 s_info = mtod(m, struct sctp_sndrcvinfo *);
3129 if (inp->sctp_flags & SCTP_PCB_FLAGS_CONNECTED) {
3130 SCTP_INP_RLOCK(inp);
3131 stcb = LIST_FIRST(&inp->sctp_asoc_list);
3133 SCTP_TCB_LOCK(stcb);
3134 SCTP_INP_RUNLOCK(inp);
3136 stcb = sctp_findassociation_ep_asocid(inp, s_info->sinfo_assoc_id);
3142 /* Validate things */
3143 if (s_info->sinfo_stream > stcb->asoc.streamoutcnt) {
3144 SCTP_TCB_UNLOCK(stcb);
3148 /* Mask off the flags that are allowed */
3149 s_info->sinfo_flags = (s_info->sinfo_flags &
3150 (MSG_UNORDERED | MSG_ADDR_OVER |
3151 MSG_PR_SCTP_TTL | MSG_PR_SCTP_BUF));
3153 stcb->asoc.def_send = *s_info;
3154 SCTP_TCB_UNLOCK(stcb);
3157 case SCTP_PEER_ADDR_PARAMS:
3159 struct sctp_paddrparams *paddrp;
3160 struct sctp_nets *net;
3161 if ((size_t)m->m_len < sizeof(struct sctp_paddrparams)) {
3165 paddrp = mtod(m, struct sctp_paddrparams *);
3167 if (paddrp->spp_assoc_id) {
3168 if (inp->sctp_flags & SCTP_PCB_FLAGS_CONNECTED) {
3169 SCTP_INP_RLOCK(inp);
3170 stcb = LIST_FIRST(&inp->sctp_asoc_list);
3172 SCTP_TCB_LOCK(stcb);
3173 net = sctp_findnet(stcb, (struct sockaddr *)&paddrp->spp_address);
3175 SCTP_INP_RUNLOCK(inp);
3177 stcb = sctp_findassociation_ep_asocid(inp, paddrp->spp_assoc_id);
3184 if ((stcb == NULL) &&
3185 ((((struct sockaddr *)&paddrp->spp_address)->sa_family == AF_INET) ||
3186 (((struct sockaddr *)&paddrp->spp_address)->sa_family == AF_INET6))) {
3187 /* Lookup via address */
3188 if (inp->sctp_flags & SCTP_PCB_FLAGS_CONNECTED) {
3189 SCTP_INP_RLOCK(inp);
3190 stcb = LIST_FIRST(&inp->sctp_asoc_list);
3192 SCTP_TCB_LOCK(stcb);
3193 net = sctp_findnet(stcb,
3194 (struct sockaddr *)&paddrp->spp_address);
3196 SCTP_INP_RUNLOCK(inp);
3198 SCTP_INP_WLOCK(inp);
3199 SCTP_INP_INCR_REF(inp);
3200 SCTP_INP_WUNLOCK(inp);
3201 stcb = sctp_findassociation_ep_addr(&inp,
3202 (struct sockaddr *)&paddrp->spp_address,
3205 SCTP_INP_WLOCK(inp);
3206 SCTP_INP_DECR_REF(inp);
3207 SCTP_INP_WUNLOCK(inp);
3211 /* Effects the Endpoint */
3215 /* Applies to the specific association */
3216 if (paddrp->spp_pathmaxrxt) {
3218 if (paddrp->spp_pathmaxrxt)
3219 net->failure_threshold = paddrp->spp_pathmaxrxt;
3221 if (paddrp->spp_pathmaxrxt)
3222 stcb->asoc.def_net_failure = paddrp->spp_pathmaxrxt;
3225 if ((paddrp->spp_hbinterval != 0) && (paddrp->spp_hbinterval != 0xffffffff)) {
3229 net->dest_state &= ~SCTP_ADDR_NOHB;
3231 old = stcb->asoc.heart_beat_delay;
3232 stcb->asoc.heart_beat_delay = paddrp->spp_hbinterval;
3234 /* Turn back on the timer */
3235 sctp_timer_start(SCTP_TIMER_TYPE_HEARTBEAT, inp, stcb, net);
3238 } else if (paddrp->spp_hbinterval == 0xffffffff) {
3240 sctp_send_hb(stcb, 1, net);
3243 /* off on association */
3244 if (stcb->asoc.heart_beat_delay) {
3245 int cnt_of_unconf = 0;
3246 struct sctp_nets *lnet;
3247 TAILQ_FOREACH(lnet, &stcb->asoc.nets, sctp_next) {
3248 if (lnet->dest_state & SCTP_ADDR_UNCONFIRMED) {
3252 /* stop the timer ONLY if we have no unconfirmed addresses
3254 if (cnt_of_unconf == 0)
3255 sctp_timer_stop(SCTP_TIMER_TYPE_HEARTBEAT, inp, stcb, net);
3257 stcb->asoc.heart_beat_delay = 0;
3259 net->dest_state |= SCTP_ADDR_NOHB;
3262 SCTP_TCB_UNLOCK(stcb);
3264 /* Use endpoint defaults */
3265 SCTP_INP_WLOCK(inp);
3266 if (paddrp->spp_pathmaxrxt)
3267 inp->sctp_ep.def_net_failure = paddrp->spp_pathmaxrxt;
3268 if (paddrp->spp_hbinterval != SCTP_ISSUE_HB)
3269 inp->sctp_ep.sctp_timeoutticks[SCTP_TIMER_HEARTBEAT] = paddrp->spp_hbinterval;
3270 SCTP_INP_WUNLOCK(inp);
3276 struct sctp_rtoinfo *srto;
3277 if ((size_t)m->m_len < sizeof(struct sctp_rtoinfo)) {
3281 srto = mtod(m, struct sctp_rtoinfo *);
3282 if (srto->srto_assoc_id == 0) {
3283 SCTP_INP_WLOCK(inp);
3284 /* If we have a null asoc, its default for the endpoint */
3285 if (srto->srto_initial > 10)
3286 inp->sctp_ep.initial_rto = srto->srto_initial;
3287 if (srto->srto_max > 10)
3288 inp->sctp_ep.sctp_maxrto = srto->srto_max;
3289 if (srto->srto_min > 10)
3290 inp->sctp_ep.sctp_minrto = srto->srto_min;
3291 SCTP_INP_WUNLOCK(inp);
3294 if (inp->sctp_flags & SCTP_PCB_FLAGS_CONNECTED) {
3295 SCTP_INP_RLOCK(inp);
3296 stcb = LIST_FIRST(&inp->sctp_asoc_list);
3298 SCTP_TCB_LOCK(stcb);
3299 SCTP_INP_RUNLOCK(inp);
3301 stcb = sctp_findassociation_ep_asocid(inp, srto->srto_assoc_id);
3306 /* Set in ms we hope :-) */
3307 if (srto->srto_initial > 10)
3308 stcb->asoc.initial_rto = srto->srto_initial;
3309 if (srto->srto_max > 10)
3310 stcb->asoc.maxrto = srto->srto_max;
3311 if (srto->srto_min > 10)
3312 stcb->asoc.minrto = srto->srto_min;
3313 SCTP_TCB_UNLOCK(stcb);
3316 case SCTP_ASSOCINFO:
3318 struct sctp_assocparams *sasoc;
3320 if ((size_t)m->m_len < sizeof(struct sctp_assocparams)) {
3324 sasoc = mtod(m, struct sctp_assocparams *);
3325 if (sasoc->sasoc_assoc_id) {
3326 if (inp->sctp_flags & SCTP_PCB_FLAGS_CONNECTED) {
3327 SCTP_INP_RLOCK(inp);
3328 stcb = LIST_FIRST(&inp->sctp_asoc_list);
3330 SCTP_TCB_LOCK(stcb);
3331 SCTP_INP_RUNLOCK(inp);
3333 stcb = sctp_findassociation_ep_asocid(inp,
3334 sasoc->sasoc_assoc_id);
3344 if (sasoc->sasoc_asocmaxrxt)
3345 stcb->asoc.max_send_times = sasoc->sasoc_asocmaxrxt;
3346 sasoc->sasoc_number_peer_destinations = stcb->asoc.numnets;
3347 sasoc->sasoc_peer_rwnd = 0;
3348 sasoc->sasoc_local_rwnd = 0;
3349 if (stcb->asoc.cookie_life)
3350 stcb->asoc.cookie_life = sasoc->sasoc_cookie_life;
3351 SCTP_TCB_UNLOCK(stcb);
3353 SCTP_INP_WLOCK(inp);
3354 if (sasoc->sasoc_asocmaxrxt)
3355 inp->sctp_ep.max_send_times = sasoc->sasoc_asocmaxrxt;
3356 sasoc->sasoc_number_peer_destinations = 0;
3357 sasoc->sasoc_peer_rwnd = 0;
3358 sasoc->sasoc_local_rwnd = 0;
3359 if (sasoc->sasoc_cookie_life)
3360 inp->sctp_ep.def_cookie_life = sasoc->sasoc_cookie_life;
3361 SCTP_INP_WUNLOCK(inp);
3367 struct sctp_initmsg *sinit;
3369 if ((size_t)m->m_len < sizeof(struct sctp_initmsg)) {
3373 sinit = mtod(m, struct sctp_initmsg *);
3374 SCTP_INP_WLOCK(inp);
3375 if (sinit->sinit_num_ostreams)
3376 inp->sctp_ep.pre_open_stream_count = sinit->sinit_num_ostreams;
3378 if (sinit->sinit_max_instreams)
3379 inp->sctp_ep.max_open_streams_intome = sinit->sinit_max_instreams;
3381 if (sinit->sinit_max_attempts)
3382 inp->sctp_ep.max_init_times = sinit->sinit_max_attempts;
3384 if (sinit->sinit_max_init_timeo > 10)
3385 /* We must be at least a 100ms (we set in ticks) */
3386 inp->sctp_ep.initial_init_rto_max = sinit->sinit_max_init_timeo;
3387 SCTP_INP_WUNLOCK(inp);
3390 case SCTP_PRIMARY_ADDR:
3392 struct sctp_setprim *spa;
3393 struct sctp_nets *net, *lnet;
3394 if ((size_t)m->m_len < sizeof(struct sctp_setprim)) {
3398 spa = mtod(m, struct sctp_setprim *);
3400 if (inp->sctp_flags & SCTP_PCB_FLAGS_CONNECTED) {
3401 SCTP_INP_RLOCK(inp);
3402 stcb = LIST_FIRST(&inp->sctp_asoc_list);
3404 SCTP_TCB_LOCK(stcb);
3409 SCTP_INP_RUNLOCK(inp);
3411 stcb = sctp_findassociation_ep_asocid(inp, spa->ssp_assoc_id);
3414 SCTP_INP_WLOCK(inp);
3415 SCTP_INP_INCR_REF(inp);
3416 SCTP_INP_WUNLOCK(inp);
3417 stcb = sctp_findassociation_ep_addr(&inp,
3418 (struct sockaddr *)&spa->ssp_addr,
3421 SCTP_INP_WLOCK(inp);
3422 SCTP_INP_DECR_REF(inp);
3423 SCTP_INP_WUNLOCK(inp);
3428 /* find the net, associd or connected lookup type */
3429 net = sctp_findnet(stcb, (struct sockaddr *)&spa->ssp_addr);
3431 SCTP_TCB_UNLOCK(stcb);
3436 if ((net != stcb->asoc.primary_destination) &&
3437 (!(net->dest_state & SCTP_ADDR_UNCONFIRMED))) {
3438 /* Ok we need to set it */
3439 lnet = stcb->asoc.primary_destination;
3440 lnet->next_tsn_at_change = net->next_tsn_at_change = stcb->asoc.sending_seq;
3441 if (sctp_set_primary_addr(stcb,
3442 (struct sockaddr *)NULL,
3444 if (net->dest_state & SCTP_ADDR_SWITCH_PRIMARY) {
3445 net->dest_state |= SCTP_ADDR_DOUBLE_SWITCH;
3447 net->dest_state |= SCTP_ADDR_SWITCH_PRIMARY;
3450 SCTP_TCB_UNLOCK(stcb);
3454 case SCTP_SET_PEER_PRIMARY_ADDR:
3456 struct sctp_setpeerprim *sspp;
3457 if ((size_t)m->m_len < sizeof(struct sctp_setpeerprim)) {
3461 sspp = mtod(m, struct sctp_setpeerprim *);
3464 if (inp->sctp_flags & SCTP_PCB_FLAGS_CONNECTED) {
3465 SCTP_INP_RLOCK(inp);
3466 stcb = LIST_FIRST(&inp->sctp_asoc_list);
3468 SCTP_TCB_UNLOCK(stcb);
3469 SCTP_INP_RUNLOCK(inp);
3471 stcb = sctp_findassociation_ep_asocid(inp, sspp->sspp_assoc_id);
3476 if (sctp_set_primary_ip_address_sa(stcb, (struct sockaddr *)&sspp->sspp_addr) != 0) {
3479 SCTP_TCB_UNLOCK(stcb);
3482 case SCTP_BINDX_ADD_ADDR:
3484 struct sctp_getaddresses *addrs;
3485 struct sockaddr *addr_touse;
3486 struct sockaddr_in sin;
3487 /* see if we're bound all already! */
3488 if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUNDALL) {
3492 if ((size_t)m->m_len < sizeof(struct sctp_getaddresses)) {
3496 addrs = mtod(m, struct sctp_getaddresses *);
3497 addr_touse = addrs->addr;
3498 if (addrs->addr->sa_family == AF_INET6) {
3499 struct sockaddr_in6 *sin6;
3500 sin6 = (struct sockaddr_in6 *)addr_touse;
3501 if (IN6_IS_ADDR_V4MAPPED(&sin6->sin6_addr)) {
3502 in6_sin6_2_sin(&sin, sin6);
3503 addr_touse = (struct sockaddr *)&sin;
3506 if (inp->sctp_flags & SCTP_PCB_FLAGS_UNBOUND) {
3508 /* Can't get proc for Net/Open BSD */
3512 error = sctp_inpcb_bind(so, addr_touse, p);
3515 /* No locks required here since bind and mgmt_ep_sa all
3516 * do their own locking. If we do something for the FIX:
3517 * below we may need to lock in that case.
3519 if (addrs->sget_assoc_id == 0) {
3520 /* add the address */
3521 struct sctp_inpcb *lep;
3522 ((struct sockaddr_in *)addr_touse)->sin_port = inp->sctp_lport;
3523 lep = sctp_pcb_findep(addr_touse, 1, 0);
3525 /* We must decrement the refcount
3526 * since we have the ep already and
3527 * are binding. No remove going on
3530 SCTP_INP_WLOCK(inp);
3531 SCTP_INP_DECR_REF(inp);
3532 SCTP_INP_WUNLOCK(inp);
3535 /* already bound to it.. ok */
3537 } else if (lep == NULL) {
3538 ((struct sockaddr_in *)addr_touse)->sin_port = 0;
3539 error = sctp_addr_mgmt_ep_sa(inp, addr_touse,
3540 SCTP_ADD_IP_ADDRESS);
3542 error = EADDRNOTAVAIL;
3548 /* FIX: decide whether we allow assoc based bindx */
3552 case SCTP_BINDX_REM_ADDR:
3554 struct sctp_getaddresses *addrs;
3555 struct sockaddr *addr_touse;
3556 struct sockaddr_in sin;
3557 /* see if we're bound all already! */
3558 if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUNDALL) {
3562 if ((size_t)m->m_len < sizeof(struct sctp_getaddresses)) {
3566 addrs = mtod(m, struct sctp_getaddresses *);
3567 addr_touse = addrs->addr;
3568 if (addrs->addr->sa_family == AF_INET6) {
3569 struct sockaddr_in6 *sin6;
3570 sin6 = (struct sockaddr_in6 *)addr_touse;
3571 if (IN6_IS_ADDR_V4MAPPED(&sin6->sin6_addr)) {
3572 in6_sin6_2_sin(&sin, sin6);
3573 addr_touse = (struct sockaddr *)&sin;
3576 /* No lock required mgmt_ep_sa does its own locking. If
3577 * the FIX: below is ever changed we may need to
3578 * lock before calling association level binding.
3580 if (addrs->sget_assoc_id == 0) {
3581 /* delete the address */
3582 sctp_addr_mgmt_ep_sa(inp, addr_touse,
3583 SCTP_DEL_IP_ADDRESS);
3585 /* FIX: decide whether we allow assoc based bindx */
3590 error = ENOPROTOOPT;
3592 } /* end switch (opt) */
3597 #if defined(__FreeBSD__) || defined(__APPLE__)
3599 sctp_ctloutput(struct socket *so, struct sockopt *sopt)
3601 struct mbuf *m = NULL;
3602 struct sctp_inpcb *inp;
3605 inp = (struct sctp_inpcb *)so->so_pcb;
3606 #if defined(__NetBSD__) || defined(__OpenBSD__)
3613 /* I made the same as TCP since we are not setup? */
3614 return (ECONNRESET);
3616 if (sopt->sopt_level != IPPROTO_SCTP) {
3617 /* wrong proto level... send back up to IP */
3619 if (INP_CHECK_SOCKAF(so, AF_INET6))
3620 error = ip6_ctloutput(so, sopt);
3623 error = ip_ctloutput(so, sopt);
3627 if (sopt->sopt_valsize > MCLBYTES) {
3629 * Restrict us down to a cluster size, that's all we can
3630 * pass either way...
3632 sopt->sopt_valsize = MCLBYTES;
3634 if (sopt->sopt_valsize) {
3636 m = m_get(M_WAIT, MT_DATA);
3637 if (sopt->sopt_valsize > MLEN) {
3638 MCLGET(m, M_DONTWAIT);
3639 if ((m->m_flags & M_EXT) == 0) {
3645 error = sooptcopyin(sopt, mtod(m, caddr_t), sopt->sopt_valsize,
3646 sopt->sopt_valsize);
3651 m->m_len = sopt->sopt_valsize;
3653 if (sopt->sopt_dir == SOPT_SET) {
3654 #if defined(__FreeBSD__) && __FreeBSD_version >= 500000
3655 error = sctp_optsset(so, sopt->sopt_name, &m, sopt->sopt_td);
3657 error = sctp_optsset(so, sopt->sopt_name, &m, sopt->sopt_p);
3659 } else if (sopt->sopt_dir == SOPT_GET) {
3660 #if defined (__FreeBSD__) && __FreeBSD_version >= 500000
3661 error = sctp_optsget(so, sopt->sopt_name, &m, sopt->sopt_td);
3663 error = sctp_optsget(so, sopt->sopt_name, &m, sopt->sopt_p);
3668 if ( (error == 0) && (m != NULL)) {
3669 error = sooptcopyout(sopt, mtod(m, caddr_t), m->m_len);
3671 } else if (m != NULL) {
3680 /* NetBSD and OpenBSD */
3682 sctp_ctloutput(op, so, level, optname, mp)
3691 struct in6pcb *in6p;
3693 int family; /* family of the socket */
3695 family = so->so_proto->pr_domain->dom_family;
3697 #if defined(__NetBSD__) || defined(__OpenBSD__)
3704 inp = sotoinpcb(so);
3712 in6p = sotoin6pcb(so);
3717 return EAFNOSUPPORT;
3722 if (inp == NULL && in6p == NULL)
3726 if (op == PRCO_SETOPT && *mp)
3728 return (ECONNRESET);
3730 if (level != IPPROTO_SCTP) {
3733 error = ip_ctloutput(op, so, level, optname, mp);
3737 error = ip6_ctloutput(op, so, level, optname, mp);
3744 /* Ok if we reach here it is a SCTP option we hope */
3745 if (op == PRCO_SETOPT) {
3746 error = sctp_optsset(so, optname, mp, (struct proc *)NULL);
3749 } else if (op == PRCO_GETOPT) {
3750 error = sctp_optsget(so, optname, mp, (struct proc *)NULL);
3761 #if defined(__FreeBSD__) && __FreeBSD_version >= 500000
3762 sctp_connect(struct socket *so, struct sockaddr *addr, struct thread *p)
3765 #if defined(__FreeBSD__) || defined(__APPLE__)
3766 sctp_connect(struct socket *so, struct sockaddr *addr, struct proc *p)
3769 sctp_connect(struct socket *so, struct mbuf *nam, struct proc *p)
3771 struct sockaddr *addr = mtod(nam, struct sockaddr *);
3774 #if defined(__NetBSD__) || defined(__OpenBSD__)
3775 int s = splsoftnet();
3780 struct sctp_inpcb *inp;
3781 struct sctp_tcb *stcb;
3784 if (sctp_debug_on & SCTP_DEBUG_PCB1) {
3785 printf("Connect called in SCTP to ");
3786 sctp_print_address(addr);
3787 printf("Port %d\n", ntohs(((struct sockaddr_in *)addr)->sin_port));
3789 #endif /* SCTP_DEBUG */
3790 inp = (struct sctp_inpcb *)so->so_pcb;
3793 /* I made the same as TCP since we are not setup? */
3794 return (ECONNRESET);
3796 SCTP_ASOC_CREATE_LOCK(inp);
3797 SCTP_INP_WLOCK(inp);
3798 if ((inp->sctp_flags & SCTP_PCB_FLAGS_SOCKET_GONE) ||
3799 (inp->sctp_flags & SCTP_PCB_FLAGS_SOCKET_GONE)) {
3800 /* Should I really unlock ? */
3801 SCTP_INP_WUNLOCK(inp);
3802 SCTP_ASOC_CREATE_UNLOCK(inp);
3807 if (((inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) == 0) &&
3808 (addr->sa_family == AF_INET6)) {
3809 SCTP_INP_WUNLOCK(inp);
3810 SCTP_ASOC_CREATE_UNLOCK(inp);
3815 if ((inp->sctp_flags & SCTP_PCB_FLAGS_UNBOUND) ==
3816 SCTP_PCB_FLAGS_UNBOUND) {
3817 /* Bind a ephemeral port */
3818 SCTP_INP_WUNLOCK(inp);
3819 error = sctp_inpcb_bind(so, NULL, p);
3821 SCTP_ASOC_CREATE_UNLOCK(inp);
3825 SCTP_INP_WLOCK(inp);
3827 /* Now do we connect? */
3828 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) &&
3829 (inp->sctp_flags & SCTP_PCB_FLAGS_CONNECTED)) {
3830 /* We are already connected AND the TCP model */
3832 SCTP_INP_WUNLOCK(inp);
3833 SCTP_ASOC_CREATE_UNLOCK(inp);
3834 return (EADDRINUSE);
3836 if (inp->sctp_flags & SCTP_PCB_FLAGS_CONNECTED) {
3837 stcb = LIST_FIRST(&inp->sctp_asoc_list);
3839 SCTP_TCB_UNLOCK(stcb);
3840 SCTP_INP_WUNLOCK(inp);
3842 SCTP_INP_INCR_REF(inp);
3843 SCTP_INP_WUNLOCK(inp);
3844 stcb = sctp_findassociation_ep_addr(&inp, addr, NULL, NULL, NULL);
3846 SCTP_INP_WLOCK(inp);
3847 SCTP_INP_DECR_REF(inp);
3848 SCTP_INP_WUNLOCK(inp);
3852 /* Already have or am bring up an association */
3853 SCTP_ASOC_CREATE_UNLOCK(inp);
3854 SCTP_TCB_UNLOCK(stcb);
3858 /* We are GOOD to go */
3859 stcb = sctp_aloc_assoc(inp, addr, 1, &error, 0);
3861 /* Gak! no memory */
3865 if (stcb->sctp_ep->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) {
3866 stcb->sctp_ep->sctp_flags |= SCTP_PCB_FLAGS_CONNECTED;
3867 /* Set the connected flag so we can queue data */
3870 stcb->asoc.state = SCTP_STATE_COOKIE_WAIT;
3871 SCTP_GETTIME_TIMEVAL(&stcb->asoc.time_entered);
3872 sctp_send_initiate(inp, stcb);
3873 SCTP_ASOC_CREATE_UNLOCK(inp);
3874 SCTP_TCB_UNLOCK(stcb);
3880 sctp_usr_recvd(struct socket *so, int flags)
3883 struct sctp_socket_q_list *sq=NULL;
3885 * The user has received some data, we may be able to stuff more
3886 * up the socket. And we need to possibly update the rwnd.
3888 struct sctp_inpcb *inp;
3889 struct sctp_tcb *stcb=NULL;
3891 inp = (struct sctp_inpcb *)so->so_pcb;
3893 if (sctp_debug_on & SCTP_DEBUG_USRREQ2)
3894 printf("Read for so:%x inp:%x Flags:%x\n",
3895 (u_int)so, (u_int)inp, (u_int)flags);
3899 /* I made the same as TCP since we are not setup? */
3901 if (sctp_debug_on & SCTP_DEBUG_USRREQ2)
3902 printf("Nope, connection reset\n");
3904 return (ECONNRESET);
3906 #if defined(__NetBSD__) || defined(__OpenBSD__)
3912 * Grab the first one on the list. It will re-insert itself if
3913 * it runs out of room
3915 SCTP_INP_WLOCK(inp);
3916 if ((flags & MSG_EOR) && ((inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) == 0)
3917 && ((inp->sctp_flags & SCTP_PCB_FLAGS_CONNECTED) == 0)) {
3918 /* Ok the other part of our grubby tracking
3919 * stuff for our horrible layer violation that
3920 * the tsvwg thinks is ok for sctp_peeloff.. gak!
3921 * We must update the next vtag pending on the
3922 * socket buffer (if any).
3924 inp->sctp_vtag_first = sctp_get_first_vtag_from_sb(so);
3925 sq = TAILQ_FIRST(&inp->sctp_queue_list);
3932 stcb = LIST_FIRST(&inp->sctp_asoc_list);
3935 SCTP_TCB_LOCK(stcb);
3938 /* all code in normal stcb path assumes
3939 * that you have a tcb_lock only. Thus
3940 * we must release the inp write lock.
3942 if (flags & MSG_EOR) {
3943 if (((inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) == 0)
3944 && ((inp->sctp_flags & SCTP_PCB_FLAGS_CONNECTED) == 0)) {
3945 stcb = sctp_remove_from_socket_q(inp);
3948 if (sctp_debug_on & SCTP_DEBUG_USRREQ2)
3949 printf("remove from socket queue for inp:%x tcbret:%x\n",
3950 (u_int)inp, (u_int)stcb);
3953 stcb->asoc.my_rwnd_control_len = sctp_sbspace_sub(stcb->asoc.my_rwnd_control_len,
3954 sizeof(struct mbuf));
3955 if (inp->sctp_flags & SCTP_PCB_FLAGS_RECVDATAIOEVNT) {
3956 stcb->asoc.my_rwnd_control_len = sctp_sbspace_sub(stcb->asoc.my_rwnd_control_len,
3957 CMSG_LEN(sizeof(struct sctp_sndrcvinfo)));
3960 if ((TAILQ_EMPTY(&stcb->asoc.delivery_queue) == 0) ||
3961 (TAILQ_EMPTY(&stcb->asoc.reasmqueue) == 0)) {
3962 /* Deliver if there is something to be delivered */
3963 sctp_service_queues(stcb, &stcb->asoc, 1);
3965 sctp_set_rwnd(stcb, &stcb->asoc);
3966 /* if we increase by 1 or more MTU's (smallest MTUs of all
3967 * nets) we send a window update sack
3969 incr = stcb->asoc.my_rwnd - stcb->asoc.my_last_reported_rwnd;
3973 if (((uint32_t)incr >= (stcb->asoc.smallest_mtu * SCTP_SEG_TO_RWND_UPD)) ||
3974 ((((uint32_t)incr)*SCTP_SCALE_OF_RWND_TO_UPD) >= so->so_rcv.sb_hiwat)) {
3975 if (callout_pending(&stcb->asoc.dack_timer.timer)) {
3976 /* If the timer is up, stop it */
3977 sctp_timer_stop(SCTP_TIMER_TYPE_RECV,
3978 stcb->sctp_ep, stcb, NULL);
3980 /* Send the sack, with the new rwnd */
3981 sctp_send_sack(stcb);
3982 /* Now do the output */
3983 sctp_chunk_output(inp, stcb, 10);
3986 if ((( sq ) && (flags & MSG_EOR) && ((inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) == 0))
3987 && ((inp->sctp_flags & SCTP_PCB_FLAGS_CONNECTED) == 0)) {
3988 stcb = sctp_remove_from_socket_q(inp);
3991 SOCKBUF_LOCK(&so->so_rcv);
3992 if (( so->so_rcv.sb_mb == NULL ) &&
3993 (TAILQ_EMPTY(&inp->sctp_queue_list) == 0)) {
3996 if (sctp_debug_on & SCTP_DEBUG_USRREQ2)
3997 printf("Something off, inp:%x so->so_rcv->sb_mb is empty and sockq is not.. cleaning\n",
4000 if (((inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) == 0)
4001 && ((inp->sctp_flags & SCTP_PCB_FLAGS_CONNECTED) == 0)) {
4003 done_yet = TAILQ_EMPTY(&inp->sctp_queue_list);
4006 (void)sctp_remove_from_socket_q(inp);
4007 done_yet = TAILQ_EMPTY(&inp->sctp_queue_list);
4011 if (sctp_debug_on & SCTP_DEBUG_USRREQ2)
4012 printf("Cleaned up %d sockq's\n", sq_cnt);
4015 SOCKBUF_UNLOCK(&so->so_rcv);
4017 SCTP_TCB_UNLOCK(stcb);
4018 SCTP_INP_WUNLOCK(inp);
4024 #if defined(__FreeBSD__) && __FreeBSD_version >= 500000
4025 sctp_listen(struct socket *so, struct thread *p)
4027 sctp_listen(struct socket *so, struct proc *p)
4031 * Note this module depends on the protocol processing being
4032 * called AFTER any socket level flags and backlog are applied
4033 * to the socket. The traditional way that the socket flags are
4034 * applied is AFTER protocol processing. We have made a change
4035 * to the sys/kern/uipc_socket.c module to reverse this but this
4036 * MUST be in place if the socket API for SCTP is to work properly.
4038 #if defined(__NetBSD__) || defined(__OpenBSD__)
4039 int s = splsoftnet();
4044 struct sctp_inpcb *inp;
4046 inp = (struct sctp_inpcb *)so->so_pcb;
4049 /* I made the same as TCP since we are not setup? */
4050 return (ECONNRESET);
4052 SCTP_INP_RLOCK(inp);
4053 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) &&
4054 (inp->sctp_flags & SCTP_PCB_FLAGS_CONNECTED)) {
4055 /* We are already connected AND the TCP model */
4057 SCTP_INP_RUNLOCK(inp);
4058 return (EADDRINUSE);
4060 if (inp->sctp_flags & SCTP_PCB_FLAGS_UNBOUND) {
4061 /* We must do a bind. */
4062 SCTP_INP_RUNLOCK(inp);
4063 if ((error = sctp_inpcb_bind(so, NULL, p))) {
4064 /* bind error, probably perm */
4069 SCTP_INP_RUNLOCK(inp);
4072 SCTP_INP_WLOCK(inp);
4073 if (inp->sctp_socket->so_qlimit) {
4074 if (inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) {
4076 * For the UDP model we must TURN OFF the ACCEPT
4077 * flags since we do NOT allow the accept() call.
4078 * The TCP model (when present) will do accept which
4079 * then prohibits connect().
4081 inp->sctp_socket->so_options &= ~SO_ACCEPTCONN;
4083 inp->sctp_flags |= SCTP_PCB_FLAGS_ACCEPTING;
4085 if (inp->sctp_flags & SCTP_PCB_FLAGS_ACCEPTING) {
4087 * Turning off the listen flags if the backlog is
4088 * set to 0 (i.e. qlimit is 0).
4090 inp->sctp_flags &= ~SCTP_PCB_FLAGS_ACCEPTING;
4092 inp->sctp_socket->so_options &= ~SO_ACCEPTCONN;
4094 SCTP_INP_WUNLOCK(inp);
4101 #if defined(__FreeBSD__) || defined(__APPLE__)
4102 sctp_accept(struct socket *so, struct sockaddr **addr)
4105 sctp_accept(struct socket *so, struct mbuf *nam)
4107 struct sockaddr *addr = mtod(nam, struct sockaddr *);
4109 #if defined(__NetBSD__) || defined(__OpenBSD__)
4110 int s = splsoftnet();
4114 struct sctp_tcb *stcb;
4115 struct sockaddr *prim;
4116 struct sctp_inpcb *inp;
4118 inp = (struct sctp_inpcb *)so->so_pcb;
4122 return (ECONNRESET);
4124 SCTP_INP_RLOCK(inp);
4125 if (so->so_state & SS_ISDISCONNECTED) {
4127 SCTP_INP_RUNLOCK(inp);
4128 return (ECONNABORTED);
4130 stcb = LIST_FIRST(&inp->sctp_asoc_list);
4133 SCTP_INP_RUNLOCK(inp);
4134 return (ECONNRESET);
4136 SCTP_TCB_LOCK(stcb);
4137 SCTP_INP_RUNLOCK(inp);
4138 prim = (struct sockaddr *)&stcb->asoc.primary_destination->ro._l_addr;
4139 if (prim->sa_family == AF_INET) {
4140 struct sockaddr_in *sin;
4141 #if defined(__FreeBSD__) || defined(__APPLE__)
4142 MALLOC(sin, struct sockaddr_in *, sizeof *sin, M_SONAME,
4145 sin = (struct sockaddr_in *)addr;
4146 bzero((caddr_t)sin, sizeof (*sin));
4148 sin->sin_family = AF_INET;
4149 sin->sin_len = sizeof(*sin);
4150 sin->sin_port = ((struct sockaddr_in *)prim)->sin_port;
4151 sin->sin_addr = ((struct sockaddr_in *)prim)->sin_addr;
4152 #if defined(__FreeBSD__) || defined(__APPLE__)
4153 *addr = (struct sockaddr *)sin;
4155 nam->m_len = sizeof(*sin);
4158 struct sockaddr_in6 *sin6;
4159 #if defined(__FreeBSD__) || defined(__APPLE__)
4160 MALLOC(sin6, struct sockaddr_in6 *, sizeof *sin6, M_SONAME,
4163 sin6 = (struct sockaddr_in6 *)addr;
4165 bzero((caddr_t)sin6, sizeof (*sin6));
4166 sin6->sin6_family = AF_INET6;
4167 sin6->sin6_len = sizeof(*sin6);
4168 sin6->sin6_port = ((struct sockaddr_in6 *)prim)->sin6_port;
4170 sin6->sin6_addr = ((struct sockaddr_in6 *)prim)->sin6_addr;
4171 if (IN6_IS_SCOPE_LINKLOCAL(&sin6->sin6_addr))
4172 /* sin6->sin6_scope_id = ntohs(sin6->sin6_addr.s6_addr16[1]);*/
4173 in6_recoverscope(sin6, &sin6->sin6_addr, NULL); /* skip ifp check */
4175 sin6->sin6_scope_id = 0; /*XXX*/
4176 #if defined(__FreeBSD__) || defined (__APPLE__)
4177 *addr= (struct sockaddr *)sin6;
4179 nam->m_len = sizeof(*sin6);
4182 /* Wake any delayed sleep action */
4183 SCTP_TCB_UNLOCK(stcb);
4184 SCTP_INP_WLOCK(inp);
4185 if (inp->sctp_flags & SCTP_PCB_FLAGS_DONT_WAKE) {
4186 inp->sctp_flags &= ~SCTP_PCB_FLAGS_DONT_WAKE;
4187 if (inp->sctp_flags & SCTP_PCB_FLAGS_WAKEOUTPUT) {
4188 inp->sctp_flags &= ~SCTP_PCB_FLAGS_WAKEOUTPUT;
4189 #if defined(__NetBSD__)
4190 if (sowritable(inp->sctp_socket))
4191 sowwakeup(inp->sctp_socket);
4193 if (sowriteable(inp->sctp_socket))
4194 sowwakeup(inp->sctp_socket);
4197 if (inp->sctp_flags & SCTP_PCB_FLAGS_WAKEINPUT) {
4198 inp->sctp_flags &= ~SCTP_PCB_FLAGS_WAKEINPUT;
4199 if (soreadable(inp->sctp_socket))
4200 sorwakeup(inp->sctp_socket);
4204 SCTP_INP_WUNLOCK(inp);
4210 #if defined(__FreeBSD__) || defined(__APPLE__)
4211 sctp_ingetaddr(struct socket *so, struct sockaddr **addr)
4213 sctp_ingetaddr(struct socket *so, struct mbuf *nam)
4216 #if defined(__FreeBSD__) || defined(__APPLE__)
4217 struct sockaddr_in *sin;
4219 struct sockaddr_in *sin = mtod(nam, struct sockaddr_in *);
4222 struct sctp_inpcb *inp;
4224 * Do the malloc first in case it blocks.
4226 #if defined(__FreeBSD__) || defined(__APPLE__)
4227 MALLOC(sin, struct sockaddr_in *, sizeof *sin, M_SONAME, M_WAITOK |
4230 nam->m_len = sizeof(*sin);
4231 memset(sin, 0, sizeof(*sin));
4233 sin->sin_family = AF_INET;
4234 sin->sin_len = sizeof(*sin);
4235 #if defined(__NetBSD__) || defined(__OpenBSD__)
4240 inp = (struct sctp_inpcb *)so->so_pcb;
4243 #if defined(__FreeBSD__) || defined(__APPLE__)
4244 FREE(sin, M_SONAME);
4248 SCTP_INP_RLOCK(inp);
4249 sin->sin_port = inp->sctp_lport;
4250 if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUNDALL) {
4251 if (inp->sctp_flags & SCTP_PCB_FLAGS_CONNECTED) {
4252 struct sctp_tcb *stcb;
4253 struct sockaddr_in *sin_a;
4254 struct sctp_nets *net;
4257 stcb = LIST_FIRST(&inp->sctp_asoc_list);
4263 SCTP_TCB_LOCK(stcb);
4264 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
4265 sin_a = (struct sockaddr_in *)&net->ro._l_addr;
4266 if (sin_a->sin_family == AF_INET) {
4271 if ((!fnd) || (sin_a == NULL)) {
4273 SCTP_TCB_UNLOCK(stcb);
4276 sin->sin_addr = sctp_ipv4_source_address_selection(inp,
4277 stcb, (struct route *)&net->ro, net, 0);
4278 SCTP_TCB_UNLOCK(stcb);
4280 /* For the bound all case you get back 0 */
4282 sin->sin_addr.s_addr = 0;
4286 /* Take the first IPv4 address in the list */
4287 struct sctp_laddr *laddr;
4289 LIST_FOREACH(laddr, &inp->sctp_addr_list, sctp_nxt_addr) {
4290 if (laddr->ifa->ifa_addr->sa_family == AF_INET) {
4291 struct sockaddr_in *sin_a;
4292 sin_a = (struct sockaddr_in *)laddr->ifa->ifa_addr;
4293 sin->sin_addr = sin_a->sin_addr;
4300 #if defined(__FreeBSD__) || defined(__APPLE__)
4301 FREE(sin, M_SONAME);
4303 SCTP_INP_RUNLOCK(inp);
4307 SCTP_INP_RUNLOCK(inp);
4309 #if defined(__FreeBSD__) || defined(__APPLE__)
4310 (*addr) = (struct sockaddr *)sin;
4316 #if defined(__FreeBSD__) || defined(__APPLE__)
4317 sctp_peeraddr(struct socket *so, struct sockaddr **addr)
4319 struct sockaddr_in *sin = (struct sockaddr_in *)*addr;
4321 sctp_peeraddr(struct socket *so, struct mbuf *nam)
4323 struct sockaddr_in *sin = mtod(nam, struct sockaddr_in *);
4326 struct sockaddr_in *sin_a;
4327 struct sctp_inpcb *inp;
4328 struct sctp_tcb *stcb;
4329 struct sctp_nets *net;
4331 /* Do the malloc first in case it blocks. */
4332 inp = (struct sctp_inpcb *)so->so_pcb;
4333 if ((inp == NULL) ||
4334 ((inp->sctp_flags & SCTP_PCB_FLAGS_CONNECTED) == 0)) {
4335 /* UDP type and listeners will drop out here */
4338 #if defined(__NetBSD__) || defined(__OpenBSD__)
4344 #if defined(__FreeBSD__) || defined(__APPLE__)
4345 MALLOC(sin, struct sockaddr_in *, sizeof *sin, M_SONAME, M_WAITOK |
4348 nam->m_len = sizeof(*sin);
4349 memset(sin, 0, sizeof(*sin));
4351 sin->sin_family = AF_INET;
4352 sin->sin_len = sizeof(*sin);
4354 /* We must recapture incase we blocked */
4355 inp = (struct sctp_inpcb *)so->so_pcb;
4358 #if defined(__FreeBSD__) || defined(__APPLE__)
4359 FREE(sin, M_SONAME);
4363 SCTP_INP_RLOCK(inp);
4364 stcb = LIST_FIRST(&inp->sctp_asoc_list);
4366 SCTP_TCB_LOCK(stcb);
4367 SCTP_INP_RUNLOCK(inp);
4370 #if defined(__FreeBSD__) || defined(__APPLE__)
4371 FREE(sin, M_SONAME);
4376 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
4377 sin_a = (struct sockaddr_in *)&net->ro._l_addr;
4378 if (sin_a->sin_family == AF_INET) {
4380 sin->sin_port = stcb->rport;
4381 sin->sin_addr = sin_a->sin_addr;
4385 SCTP_TCB_UNLOCK(stcb);
4387 /* No IPv4 address */
4389 #if defined(__FreeBSD__) || defined(__APPLE__)
4390 FREE(sin, M_SONAME);
4398 #if defined(__FreeBSD__) || defined(__APPLE__)
4399 struct pr_usrreqs sctp_usrreqs = {
4405 pru_connect2_notsupp,
4423 #if defined(__NetBSD__)
4425 sctp_usrreq(so, req, m, nam, control, p)
4428 struct mbuf *m, *nam, *control;
4433 sctp_usrreq(so, req, m, nam, control)
4436 struct mbuf *m, *nam, *control;
4438 struct proc *p = curproc;
4444 family = so->so_proto->pr_domain->dom_family;
4446 #if defined(__NetBSD__) || defined(__OpenBSD__)
4451 if (req == PRU_CONTROL) {
4454 error = in_control(so, (long)m, (caddr_t)nam,
4455 (struct ifnet *)control
4456 #if defined(__NetBSD__)
4463 error = in6_control(so, (long)m, (caddr_t)nam,
4464 (struct ifnet *)control, p);
4468 error = EAFNOSUPPORT;
4474 if (req == PRU_PURGEIF) {
4477 ifn = (struct ifnet *)control;
4478 TAILQ_FOREACH(ifa, &ifn->if_addrlist, ifa_list) {
4479 if (ifa->ifa_addr->sa_family == family) {
4480 sctp_delete_ip_address(ifa);
4494 return (EAFNOSUPPORT);
4502 error = sctp_attach(so, family, p);
4505 error = sctp_detach(so);
4512 error = sctp_bind(so, nam, p);
4515 error = sctp_listen(so, p);
4522 error = sctp_connect(so, nam, p);
4524 case PRU_DISCONNECT:
4525 error = sctp_disconnect(so);
4532 error = sctp_accept(so, nam);
4535 error = sctp_shutdown(so);
4540 * For Open and Net BSD, this is real
4541 * ugly. The mbuf *nam that is passed
4542 * (by soreceive()) is the int flags c
4543 * ast as a (mbuf *) yuck!
4545 error = sctp_usr_recvd(so, (int)((long)nam));
4549 /* Flags are ignored */
4551 if (sctp_debug_on & SCTP_DEBUG_USRREQ1) {
4552 printf("Send called on V4 side\n");
4556 struct sockaddr *addr;
4560 addr = mtod(nam, struct sockaddr *);
4562 error = sctp_send(so, 0, m, addr, control, p);
4566 error = sctp_abort(so);
4573 error = EAFNOSUPPORT;
4576 error = EAFNOSUPPORT;
4579 error = sctp_peeraddr(so, nam);
4582 error = sctp_ingetaddr(so, nam);
4595 /* #if defined(__NetBSD__) || defined(__OpenBSD__) */
4598 * Sysctl for sctp variables.
4601 sctp_sysctl(name, namelen, oldp, oldlenp, newp, newlen)
4610 /* All sysctl names at this level are terminal. */
4616 case SCTPCTL_MAXDGRAM:
4617 return (sysctl_int(oldp, oldlenp, newp, newlen,
4619 case SCTPCTL_RECVSPACE:
4620 return (sysctl_int(oldp, oldlenp, newp, newlen,
4622 case SCTPCTL_AUTOASCONF:
4623 return (sysctl_int(oldp, oldlenp, newp, newlen,
4624 &sctp_auto_asconf));
4625 case SCTPCTL_ECN_ENABLE:
4626 return (sysctl_int(oldp, oldlenp, newp, newlen,
4628 case SCTPCTL_ECN_NONCE:
4629 return (sysctl_int(oldp, oldlenp, newp, newlen,
4631 case SCTPCTL_STRICT_SACK:
4632 return (sysctl_int(oldp, oldlenp, newp, newlen,
4633 &sctp_strict_sacks));
4634 case SCTPCTL_NOCSUM_LO:
4635 return (sysctl_int(oldp, oldlenp, newp, newlen,
4636 &sctp_no_csum_on_loopback));
4637 case SCTPCTL_STRICT_INIT:
4638 return (sysctl_int(oldp, oldlenp, newp, newlen,
4639 &sctp_strict_init));
4640 case SCTPCTL_PEER_CHK_OH:
4641 return (sysctl_int(oldp, oldlenp, newp, newlen,
4642 &sctp_peer_chunk_oh));
4643 case SCTPCTL_MAXBURST:
4644 return (sysctl_int(oldp, oldlenp, newp, newlen,
4645 &sctp_max_burst_default));
4646 case SCTPCTL_MAXCHUNKONQ:
4647 return (sysctl_int(oldp, oldlenp, newp, newlen,
4648 &sctp_max_chunks_on_queue));
4649 case SCTPCTL_DELAYED_SACK:
4650 return (sysctl_int(oldp, oldlenp, newp, newlen,
4651 &sctp_delayed_sack_time_default));
4652 case SCTPCTL_HB_INTERVAL:
4653 return (sysctl_int(oldp, oldlenp, newp, newlen,
4654 &sctp_heartbeat_interval_default));
4655 case SCTPCTL_PMTU_RAISE:
4656 return (sysctl_int(oldp, oldlenp, newp, newlen,
4657 &sctp_pmtu_raise_time_default));
4658 case SCTPCTL_SHUTDOWN_GUARD:
4659 return (sysctl_int(oldp, oldlenp, newp, newlen,
4660 &sctp_shutdown_guard_time_default));
4661 case SCTPCTL_SECRET_LIFETIME:
4662 return (sysctl_int(oldp, oldlenp, newp, newlen,
4663 &sctp_secret_lifetime_default));
4664 case SCTPCTL_RTO_MAX:
4665 return (sysctl_int(oldp, oldlenp, newp, newlen,
4666 &sctp_rto_max_default));
4667 case SCTPCTL_RTO_MIN:
4668 return (sysctl_int(oldp, oldlenp, newp, newlen,
4669 &sctp_rto_min_default));
4670 case SCTPCTL_RTO_INITIAL:
4671 return (sysctl_int(oldp, oldlenp, newp, newlen,
4672 &sctp_rto_initial_default));
4673 case SCTPCTL_INIT_RTO_MAX:
4674 return (sysctl_int(oldp, oldlenp, newp, newlen,
4675 &sctp_init_rto_max_default));
4676 case SCTPCTL_COOKIE_LIFE:
4677 return (sysctl_int(oldp, oldlenp, newp, newlen,
4678 &sctp_valid_cookie_life_default));
4679 case SCTPCTL_INIT_RTX_MAX:
4680 return (sysctl_int(oldp, oldlenp, newp, newlen,
4681 &sctp_init_rtx_max_default));
4682 case SCTPCTL_ASSOC_RTX_MAX:
4683 return (sysctl_int(oldp, oldlenp, newp, newlen,
4684 &sctp_assoc_rtx_max_default));
4685 case SCTPCTL_PATH_RTX_MAX:
4686 return (sysctl_int(oldp, oldlenp, newp, newlen,
4687 &sctp_path_rtx_max_default));
4688 case SCTPCTL_NR_OUTGOING_STREAMS:
4689 return (sysctl_int(oldp, oldlenp, newp, newlen,
4690 &sctp_nr_outgoing_streams_default));
4693 return (sysctl_int(oldp, oldlenp, newp, newlen,
4697 return (ENOPROTOOPT);
4704 * Sysctl for sctp variables.
4706 SYSCTL_SETUP(sysctl_net_inet_sctp_setup, "sysctl net.inet.sctp subtree setup")
4709 sysctl_createv(clog, 0, NULL, NULL,
4711 CTLTYPE_NODE, "net", NULL,
4714 sysctl_createv(clog, 0, NULL, NULL,
4716 CTLTYPE_NODE, "inet", NULL,
4718 CTL_NET, PF_INET, CTL_EOL);
4719 sysctl_createv(clog, 0, NULL, NULL,
4721 CTLTYPE_NODE, "sctp",
4722 SYSCTL_DESCR("sctp related settings"),
4724 CTL_NET, PF_INET, IPPROTO_SCTP, CTL_EOL);
4726 sysctl_createv(clog, 0, NULL, NULL,
4727 CTLFLAG_PERMANENT|CTLFLAG_READWRITE,
4728 CTLTYPE_INT, "maxdgram",
4729 SYSCTL_DESCR("Maximum outgoing SCTP buffer size"),
4730 NULL, 0, &sctp_sendspace, 0,
4731 CTL_NET, PF_INET, IPPROTO_SCTP, SCTPCTL_MAXDGRAM,
4734 sysctl_createv(clog, 0, NULL, NULL,
4735 CTLFLAG_PERMANENT|CTLFLAG_READWRITE,
4736 CTLTYPE_INT, "recvspace",
4737 SYSCTL_DESCR("Maximum incoming SCTP buffer size"),
4738 NULL, 0, &sctp_recvspace, 0,
4739 CTL_NET, PF_INET, IPPROTO_SCTP, SCTPCTL_RECVSPACE,
4742 sysctl_createv(clog, 0, NULL, NULL,
4743 CTLFLAG_PERMANENT|CTLFLAG_READWRITE,
4744 CTLTYPE_INT, "autoasconf",
4745 SYSCTL_DESCR("Enable SCTP Auto-ASCONF"),
4746 NULL, 0, &sctp_auto_asconf, 0,
4747 CTL_NET, PF_INET, IPPROTO_SCTP, SCTPCTL_AUTOASCONF,
4750 sysctl_createv(clog, 0, NULL, NULL,
4751 CTLFLAG_PERMANENT|CTLFLAG_READWRITE,
4752 CTLTYPE_INT, "ecn_enable",
4753 SYSCTL_DESCR("Enable SCTP ECN"),
4754 NULL, 0, &sctp_ecn, 0,
4755 CTL_NET, PF_INET, IPPROTO_SCTP, SCTPCTL_ECN_ENABLE,
4758 sysctl_createv(clog, 0, NULL, NULL,
4759 CTLFLAG_PERMANENT|CTLFLAG_READWRITE,
4760 CTLTYPE_INT, "ecn_nonce",
4761 SYSCTL_DESCR("Enable SCTP ECN Nonce"),
4762 NULL, 0, &sctp_ecn_nonce, 0,
4763 CTL_NET, PF_INET, IPPROTO_SCTP, SCTPCTL_ECN_NONCE,
4766 sysctl_createv(clog, 0, NULL, NULL,
4767 CTLFLAG_PERMANENT|CTLFLAG_READWRITE,
4768 CTLTYPE_INT, "strict_sack",
4769 SYSCTL_DESCR("Enable SCTP Strict SACK checking"),
4770 NULL, 0, &sctp_strict_sacks, 0,
4771 CTL_NET, PF_INET, IPPROTO_SCTP, SCTPCTL_STRICT_SACK,
4774 sysctl_createv(clog, 0, NULL, NULL,
4775 CTLFLAG_PERMANENT|CTLFLAG_READWRITE,
4776 CTLTYPE_INT, "loopback_nocsum",
4777 SYSCTL_DESCR("Enable NO Csum on packets sent on loopback"),
4778 NULL, 0, &sctp_no_csum_on_loopback, 0,
4779 CTL_NET, PF_INET, IPPROTO_SCTP, SCTPCTL_NOCSUM_LO,
4782 sysctl_createv(clog, 0, NULL, NULL,
4783 CTLFLAG_PERMANENT|CTLFLAG_READWRITE,
4784 CTLTYPE_INT, "strict_init",
4785 SYSCTL_DESCR("Enable strict INIT/INIT-ACK singleton enforcement"),
4786 NULL, 0, &sctp_strict_init, 0,
4787 CTL_NET, PF_INET, IPPROTO_SCTP, SCTPCTL_STRICT_INIT,
4790 sysctl_createv(clog, 0, NULL, NULL,
4791 CTLFLAG_PERMANENT|CTLFLAG_READWRITE,
4792 CTLTYPE_INT, "peer_chkoh",
4793 SYSCTL_DESCR("Amount to debit peers rwnd per chunk sent"),
4794 NULL, 0, &sctp_peer_chunk_oh, 0,
4795 CTL_NET, PF_INET, IPPROTO_SCTP, SCTPCTL_PEER_CHK_OH,
4798 sysctl_createv(clog, 0, NULL, NULL,
4799 CTLFLAG_PERMANENT|CTLFLAG_READWRITE,
4800 CTLTYPE_INT, "maxburst",
4801 SYSCTL_DESCR("Default max burst for sctp endpoints"),
4802 NULL, 0, &sctp_max_burst_default, 0,
4803 CTL_NET, PF_INET, IPPROTO_SCTP, SCTPCTL_MAXBURST,
4806 sysctl_createv(clog, 0, NULL, NULL,
4807 CTLFLAG_PERMANENT|CTLFLAG_READWRITE,
4808 CTLTYPE_INT, "maxchunks",
4809 SYSCTL_DESCR("Default max chunks on queue per asoc"),
4810 NULL, 0, &sctp_max_chunks_on_queue, 0,
4811 CTL_NET, PF_INET, IPPROTO_SCTP, SCTPCTL_MAXCHUNKONQ,