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.6 2005/07/15 17:19:28 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__) || defined(__DragonFly__)
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>
64 #include <sys/thread2.h>
66 #include <net/if_types.h>
67 #if defined(__FreeBSD__) || defined(__APPLE__) || defined(__DragonFly__)
68 #include <net/if_var.h>
70 #include <net/route.h>
71 #include <netinet/in.h>
72 #include <netinet/in_systm.h>
73 #include <netinet/ip.h>
74 #include <netinet/ip6.h>
75 #include <netinet/in_pcb.h>
76 #include <netinet/in_var.h>
77 #include <netinet/ip_var.h>
78 #include <netinet6/ip6_var.h>
79 #include <netinet6/in6_var.h>
81 #include <netinet/ip_icmp.h>
82 #include <netinet/icmp_var.h>
83 #include <netinet/sctp_pcb.h>
84 #include <netinet/sctp_header.h>
85 #include <netinet/sctp_var.h>
86 #include <netinet/sctp_output.h>
87 #include <netinet/sctp_uio.h>
88 #include <netinet/sctp_asconf.h>
89 #include <netinet/sctputil.h>
90 #include <netinet/sctp_indata.h>
91 #include <netinet/sctp_asconf.h>
94 #include <netinet6/ipsec.h>
95 #include <netkey/key.h>
101 #include <net/net_osdep.h>
103 #if defined(HAVE_NRL_INPCB) || defined(__FreeBSD__) || defined(__DragonFly__)
108 #define sotoin6pcb sotoinpcb
113 extern u_int32_t sctp_debug_on;
114 #endif /* SCTP_DEBUG */
117 * sysctl tunable variables
119 int sctp_auto_asconf = SCTP_DEFAULT_AUTO_ASCONF;
120 int sctp_max_burst_default = SCTP_DEF_MAX_BURST;
121 int sctp_peer_chunk_oh = sizeof(struct mbuf);
122 int sctp_strict_init = 1;
123 int sctp_no_csum_on_loopback = 1;
124 unsigned int sctp_max_chunks_on_queue = SCTP_ASOC_MAX_CHUNKS_ON_QUEUE;
125 int sctp_sendspace = (128 * 1024);
126 int sctp_recvspace = 128 * (1024 +
128 sizeof(struct sockaddr_in6)
130 sizeof(struct sockaddr_in)
133 int sctp_strict_sacks = 0;
135 int sctp_ecn_nonce = 0;
137 unsigned int sctp_delayed_sack_time_default = SCTP_RECV_MSEC;
138 unsigned int sctp_heartbeat_interval_default = SCTP_HB_DEFAULT_MSEC;
139 unsigned int sctp_pmtu_raise_time_default = SCTP_DEF_PMTU_RAISE_SEC;
140 unsigned int sctp_shutdown_guard_time_default = SCTP_DEF_MAX_SHUTDOWN_SEC;
141 unsigned int sctp_secret_lifetime_default = SCTP_DEFAULT_SECRET_LIFE_SEC;
142 unsigned int sctp_rto_max_default = SCTP_RTO_UPPER_BOUND;
143 unsigned int sctp_rto_min_default = SCTP_RTO_LOWER_BOUND;
144 unsigned int sctp_rto_initial_default = SCTP_RTO_INITIAL;
145 unsigned int sctp_init_rto_max_default = SCTP_RTO_UPPER_BOUND;
146 unsigned int sctp_valid_cookie_life_default = SCTP_DEFAULT_COOKIE_LIFE;
147 unsigned int sctp_init_rtx_max_default = SCTP_DEF_MAX_INIT;
148 unsigned int sctp_assoc_rtx_max_default = SCTP_DEF_MAX_SEND;
149 unsigned int sctp_path_rtx_max_default = SCTP_DEF_MAX_SEND/2;
150 unsigned int sctp_nr_outgoing_streams_default = SCTP_OSTREAM_INITIAL;
156 #define nmbclusters nmbclust
158 /* Init the SCTP pcb in sctp_pcb.c */
164 if (nmbclusters > SCTP_ASOC_MAX_CHUNKS_ON_QUEUE)
165 sctp_max_chunks_on_queue = nmbclusters;
167 /* if (nmbclust > SCTP_ASOC_MAX_CHUNKS_ON_QUEUE)
168 sctp_max_chunks_on_queue = nmbclust; FIX ME */
169 sctp_max_chunks_on_queue = nmbclust * 2;
172 * Allow a user to take no more than 1/2 the number of clusters
173 * or the SB_MAX whichever is smaller for the send window.
175 sb_max_adj = (u_long)((u_quad_t)(SB_MAX) * MCLBYTES / (MSIZE + MCLBYTES));
176 sctp_sendspace = min((min(SB_MAX, sb_max_adj)),
178 ((nmbclusters/2) * SCTP_DEFAULT_MAXSEGMENT));
180 ((nmbclust/2) * SCTP_DEFAULT_MAXSEGMENT));
183 * Now for the recv window, should we take the same amount?
184 * or should I do 1/2 the SB_MAX instead in the SB_MAX min above.
185 * For now I will just copy.
187 sctp_recvspace = sctp_sendspace;
195 ip_2_ip6_hdr(struct ip6_hdr *ip6, struct ip *ip)
197 bzero(ip6, sizeof(*ip6));
199 ip6->ip6_vfc = IPV6_VERSION;
200 ip6->ip6_plen = ip->ip_len;
201 ip6->ip6_nxt = ip->ip_p;
202 ip6->ip6_hlim = ip->ip_ttl;
203 ip6->ip6_src.s6_addr32[2] = ip6->ip6_dst.s6_addr32[2] =
205 ip6->ip6_src.s6_addr32[3] = ip->ip_src.s_addr;
206 ip6->ip6_dst.s6_addr32[3] = ip->ip_dst.s_addr;
211 sctp_split_chunks(struct sctp_association *asoc,
212 struct sctp_stream_out *strm,
213 struct sctp_tmit_chunk *chk)
215 struct sctp_tmit_chunk *new_chk;
217 /* First we need a chunk */
218 new_chk = (struct sctp_tmit_chunk *)SCTP_ZONE_GET(sctppcbinfo.ipi_zone_chunk);
219 if (new_chk == NULL) {
220 chk->flags |= CHUNK_FLAGS_FRAGMENT_OK;
223 sctppcbinfo.ipi_count_chunk++;
224 sctppcbinfo.ipi_gencnt_chunk++;
228 new_chk->data = m_split(chk->data, (chk->send_size>>1), MB_DONTWAIT);
229 if (new_chk->data == NULL) {
231 chk->flags |= CHUNK_FLAGS_FRAGMENT_OK;
232 SCTP_ZONE_FREE(sctppcbinfo.ipi_zone_chunk, new_chk);
233 sctppcbinfo.ipi_count_chunk--;
234 if ((int)sctppcbinfo.ipi_count_chunk < 0) {
235 panic("Chunk count is negative");
237 sctppcbinfo.ipi_gencnt_chunk++;
241 /* Data is now split adjust sizes */
242 chk->send_size >>= 1;
243 new_chk->send_size >>= 1;
245 chk->book_size >>= 1;
246 new_chk->book_size >>= 1;
248 /* now adjust the marks */
249 chk->rec.data.rcv_flags |= SCTP_DATA_FIRST_FRAG;
250 chk->rec.data.rcv_flags &= ~SCTP_DATA_LAST_FRAG;
252 new_chk->rec.data.rcv_flags &= ~SCTP_DATA_FIRST_FRAG;
253 new_chk->rec.data.rcv_flags |= SCTP_DATA_LAST_FRAG;
255 /* Increase ref count if dest is set */
257 new_chk->whoTo->ref_count++;
259 /* now drop it on the end of the list*/
260 asoc->stream_queue_cnt++;
261 TAILQ_INSERT_AFTER(&strm->outqueue, chk, new_chk, sctp_next);
265 sctp_notify_mbuf(struct sctp_inpcb *inp,
266 struct sctp_tcb *stcb,
267 struct sctp_nets *net,
277 if ((inp == NULL) || (stcb == NULL) || (net == NULL) ||
278 (ip == NULL) || (sh == NULL)) {
280 SCTP_TCB_UNLOCK(stcb);
283 /* First job is to verify the vtag matches what I would send */
284 if (ntohl(sh->v_tag) != (stcb->asoc.peer_vtag)) {
285 SCTP_TCB_UNLOCK(stcb);
288 icmph = (struct icmp *)((caddr_t)ip - (sizeof(struct icmp) -
290 if (icmph->icmp_type != ICMP_UNREACH) {
291 /* We only care about unreachable */
292 SCTP_TCB_UNLOCK(stcb);
295 if (icmph->icmp_code != ICMP_UNREACH_NEEDFRAG) {
296 /* not a unreachable message due to frag. */
297 SCTP_TCB_UNLOCK(stcb);
301 nxtsz = ntohs(icmph->icmp_seq);
304 * old type router that does not tell us what the next size
305 * mtu is. Rats we will have to guess (in a educated fashion
308 nxtsz = find_next_best_mtu(totsz);
311 /* Stop any PMTU timer */
312 sctp_timer_stop(SCTP_TIMER_TYPE_PATHMTURAISE, inp, stcb, NULL);
314 /* Adjust destination size limit */
315 if (net->mtu > nxtsz) {
318 /* now what about the ep? */
319 if (stcb->asoc.smallest_mtu > nxtsz) {
320 struct sctp_tmit_chunk *chk, *nchk;
321 struct sctp_stream_out *strm;
322 /* Adjust that too */
323 stcb->asoc.smallest_mtu = nxtsz;
324 /* now off to subtract IP_DF flag if needed */
326 TAILQ_FOREACH(chk, &stcb->asoc.send_queue, sctp_next) {
327 if ((chk->send_size+IP_HDR_SIZE) > nxtsz) {
328 chk->flags |= CHUNK_FLAGS_FRAGMENT_OK;
331 TAILQ_FOREACH(chk, &stcb->asoc.sent_queue, sctp_next) {
332 if ((chk->send_size+IP_HDR_SIZE) > nxtsz) {
334 * For this guy we also mark for immediate
335 * resend since we sent to big of chunk
337 chk->flags |= CHUNK_FLAGS_FRAGMENT_OK;
338 if (chk->sent != SCTP_DATAGRAM_RESEND) {
339 stcb->asoc.sent_queue_retran_cnt++;
341 chk->sent = SCTP_DATAGRAM_RESEND;
342 chk->rec.data.doing_fast_retransmit = 0;
344 /* Clear any time so NO RTT is being done */
346 stcb->asoc.total_flight -= chk->book_size;
347 if (stcb->asoc.total_flight < 0) {
348 stcb->asoc.total_flight = 0;
350 stcb->asoc.total_flight_count--;
351 if (stcb->asoc.total_flight_count < 0) {
352 stcb->asoc.total_flight_count = 0;
354 net->flight_size -= chk->book_size;
355 if (net->flight_size < 0) {
356 net->flight_size = 0;
360 TAILQ_FOREACH(strm, &stcb->asoc.out_wheel, next_spoke) {
361 chk = TAILQ_FIRST(&strm->outqueue);
363 nchk = TAILQ_NEXT(chk, sctp_next);
364 if ((chk->send_size+SCTP_MED_OVERHEAD) > nxtsz) {
365 sctp_split_chunks(&stcb->asoc, strm, chk);
371 sctp_timer_start(SCTP_TIMER_TYPE_PATHMTURAISE, inp, stcb, NULL);
372 SCTP_TCB_UNLOCK(stcb);
377 sctp_notify(struct sctp_inpcb *inp,
381 struct sctp_tcb *stcb,
382 struct sctp_nets *net)
385 if ((inp == NULL) || (stcb == NULL) || (net == NULL) ||
386 (sh == NULL) || (to == NULL)) {
388 if (sctp_debug_on & SCTP_DEBUG_USRREQ1) {
389 printf("sctp-notify, bad call\n");
391 #endif /* SCTP_DEBUG */
394 /* First job is to verify the vtag matches what I would send */
395 if (ntohl(sh->v_tag) != (stcb->asoc.peer_vtag)) {
399 /* FIX ME FIX ME PROTOPT i.e. no SCTP should ALWAYS be an ABORT */
401 if ((errno == EHOSTUNREACH) || /* Host is not reachable */
402 (errno == EHOSTDOWN) || /* Host is down */
403 (errno == ECONNREFUSED) || /* Host refused the connection, (not an abort?) */
404 (errno == ENOPROTOOPT) /* SCTP is not present on host */
407 * Hmm reachablity problems we must examine closely.
408 * If its not reachable, we may have lost a network.
409 * Or if there is NO protocol at the other end named SCTP.
410 * well we consider it a OOTB abort.
412 if ((errno == EHOSTUNREACH) || (errno == EHOSTDOWN)) {
413 if (net->dest_state & SCTP_ADDR_REACHABLE) {
414 /* Ok that destination is NOT reachable */
415 net->dest_state &= ~SCTP_ADDR_REACHABLE;
416 net->dest_state |= SCTP_ADDR_NOT_REACHABLE;
417 net->error_count = net->failure_threshold + 1;
418 sctp_ulp_notify(SCTP_NOTIFY_INTERFACE_DOWN,
419 stcb, SCTP_FAILED_THRESHOLD,
423 SCTP_TCB_UNLOCK(stcb);
426 * Here the peer is either playing tricks on us,
427 * including an address that belongs to someone who
428 * does not support SCTP OR was a userland
429 * implementation that shutdown and now is dead. In
430 * either case treat it like a OOTB abort with no TCB
432 sctp_abort_notification(stcb, SCTP_PEER_FAULTY);
433 sctp_free_assoc(inp, stcb);
434 /* no need to unlock here, since the TCB is gone */
437 /* Send all others to the app */
438 if (inp->sctp_socket) {
439 SOCK_LOCK(inp->sctp_socket);
440 inp->sctp_socket->so_error = errno;
441 sctp_sowwakeup(inp, inp->sctp_socket);
442 SOCK_UNLOCK(inp->sctp_socket);
445 SCTP_TCB_UNLOCK(stcb);
449 #if defined(__FreeBSD__) || defined(__APPLE__) || defined(__DragonFly__)
454 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__) || defined(__DragonFly__)
472 if (PRC_IS_REDIRECT(cmd)) {
474 } else if ((unsigned)cmd >= PRC_NCMDS || inetctlerrmap[cmd] == 0) {
475 #if defined(__FreeBSD__) || defined(__APPLE__) || defined(__DragonFly__)
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.
503 stcb = sctp_findassociation_addr_sa((struct sockaddr *)&from,
504 (struct sockaddr *)&to,
506 if (stcb != NULL && inp && (inp->sctp_socket != NULL)) {
507 if (cmd != PRC_MSGSIZE) {
509 if (cmd == PRC_HOSTDEAD) {
512 cm = inetctlerrmap[cmd];
514 sctp_notify(inp, cm, sh,
515 (struct sockaddr *)&to, stcb,
518 /* handle possible ICMP size messages */
519 sctp_notify_mbuf(inp, stcb, net, ip, sh);
522 #if (defined(__FreeBSD__) && __FreeBSD_version < 500000) || defined(__DragonFly__)
523 /* XXX must be fixed for 5.x and higher, leave for 4.x */
524 if (PRC_IS_REDIRECT(cmd) && inp) {
525 in_rtchange((struct inpcb *)inp,
529 if ((stcb == NULL) && (inp != NULL)) {
530 /* reduce ref-count */
532 SCTP_INP_DECR_REF(inp);
533 SCTP_INP_WUNLOCK(inp);
539 #if defined(__FreeBSD__) || defined(__APPLE__) || defined(__DragonFly__)
546 #if defined(__FreeBSD__) || defined(__DragonFly__)
548 sctp_getcred(SYSCTL_HANDLER_ARGS)
550 struct sockaddr_in addrs[2];
551 struct sctp_inpcb *inp;
552 struct sctp_nets *net;
553 struct sctp_tcb *stcb;
556 #if __FreeBSD_version >= 500000 || defined(__DragonFly__)
557 error = suser(req->td);
559 error = suser(req->p);
563 error = SYSCTL_IN(req, addrs, sizeof(addrs));
568 stcb = sctp_findassociation_addr_sa(sintosa(&addrs[0]),
571 if (stcb == NULL || inp == NULL || inp->sctp_socket == NULL) {
572 if ((inp != NULL) && (stcb == NULL)) {
573 /* reduce ref-count */
575 SCTP_INP_DECR_REF(inp);
576 SCTP_INP_WUNLOCK(inp);
581 error = SYSCTL_OUT(req, inp->sctp_socket->so_cred, sizeof(struct ucred));
582 SCTP_TCB_UNLOCK(stcb);
588 SYSCTL_PROC(_net_inet_sctp, OID_AUTO, getcred, CTLTYPE_OPAQUE|CTLFLAG_RW,
589 0, 0, sctp_getcred, "S,ucred", "Get the ucred of a SCTP connection");
590 #endif /* #if defined(__FreeBSD__) || defined(__DragonFly__) */
595 #if defined(__FreeBSD__) || defined (__APPLE__) || defined(__DragonFly__)
597 SYSCTL_DECL(_net_inet);
599 SYSCTL_NODE(_net_inet, OID_AUTO, sctp, CTLFLAG_RD, 0,
602 SYSCTL_INT(_net_inet_sctp, OID_AUTO, maxdgram, CTLFLAG_RW,
603 &sctp_sendspace, 0, "Maximum outgoing SCTP buffer size");
605 SYSCTL_INT(_net_inet_sctp, OID_AUTO, recvspace, CTLFLAG_RW,
606 &sctp_recvspace, 0, "Maximum incoming SCTP buffer size");
608 SYSCTL_INT(_net_inet_sctp, OID_AUTO, auto_asconf, CTLFLAG_RW,
609 &sctp_auto_asconf, 0, "Enable SCTP Auto-ASCONF");
611 SYSCTL_INT(_net_inet_sctp, OID_AUTO, ecn_enable, CTLFLAG_RW,
612 &sctp_ecn, 0, "Enable SCTP ECN");
614 SYSCTL_INT(_net_inet_sctp, OID_AUTO, ecn_nonce, CTLFLAG_RW,
615 &sctp_ecn_nonce, 0, "Enable SCTP ECN Nonce");
617 SYSCTL_INT(_net_inet_sctp, OID_AUTO, strict_sacks, CTLFLAG_RW,
618 &sctp_strict_sacks, 0, "Enable SCTP Strict SACK checking");
620 SYSCTL_INT(_net_inet_sctp, OID_AUTO, loopback_nocsum, CTLFLAG_RW,
621 &sctp_no_csum_on_loopback, 0,
622 "Enable NO Csum on packets sent on loopback");
624 SYSCTL_INT(_net_inet_sctp, OID_AUTO, strict_init, CTLFLAG_RW,
625 &sctp_strict_init, 0,
626 "Enable strict INIT/INIT-ACK singleton enforcement");
628 SYSCTL_INT(_net_inet_sctp, OID_AUTO, peer_chkoh, CTLFLAG_RW,
629 &sctp_peer_chunk_oh, 0,
630 "Amount to debit peers rwnd per chunk sent");
632 SYSCTL_INT(_net_inet_sctp, OID_AUTO, maxburst, CTLFLAG_RW,
633 &sctp_max_burst_default, 0,
634 "Default max burst for sctp endpoints");
636 SYSCTL_INT(_net_inet_sctp, OID_AUTO, maxchunks, CTLFLAG_RW,
637 &sctp_max_chunks_on_queue, 0,
638 "Default max chunks on queue per asoc");
640 SYSCTL_UINT(_net_inet_sctp, OID_AUTO, delayed_sack_time, CTLFLAG_RW,
641 &sctp_delayed_sack_time_default, 0,
642 "Default delayed SACK timer in msec");
644 SYSCTL_UINT(_net_inet_sctp, OID_AUTO, heartbeat_interval, CTLFLAG_RW,
645 &sctp_heartbeat_interval_default, 0,
646 "Default heartbeat interval in msec");
648 SYSCTL_UINT(_net_inet_sctp, OID_AUTO, pmtu_raise_time, CTLFLAG_RW,
649 &sctp_pmtu_raise_time_default, 0,
650 "Default PMTU raise timer in sec");
652 SYSCTL_UINT(_net_inet_sctp, OID_AUTO, shutdown_guard_time, CTLFLAG_RW,
653 &sctp_shutdown_guard_time_default, 0,
654 "Default shutdown guard timer in sec");
656 SYSCTL_UINT(_net_inet_sctp, OID_AUTO, secret_lifetime, CTLFLAG_RW,
657 &sctp_secret_lifetime_default, 0,
658 "Default secret lifetime in sec");
660 SYSCTL_UINT(_net_inet_sctp, OID_AUTO, rto_max, CTLFLAG_RW,
661 &sctp_rto_max_default, 0,
662 "Default maximum retransmission timeout in msec");
664 SYSCTL_UINT(_net_inet_sctp, OID_AUTO, rto_min, CTLFLAG_RW,
665 &sctp_rto_min_default, 0,
666 "Default minimum retransmission timeout in msec");
668 SYSCTL_UINT(_net_inet_sctp, OID_AUTO, rto_initial, CTLFLAG_RW,
669 &sctp_rto_initial_default, 0,
670 "Default initial retransmission timeout in msec");
672 SYSCTL_UINT(_net_inet_sctp, OID_AUTO, init_rto_max, CTLFLAG_RW,
673 &sctp_init_rto_max_default, 0,
674 "Default maximum retransmission timeout during association setup in msec");
676 SYSCTL_UINT(_net_inet_sctp, OID_AUTO, valid_cookie_life, CTLFLAG_RW,
677 &sctp_valid_cookie_life_default, 0,
678 "Default cookie lifetime in sec");
680 SYSCTL_UINT(_net_inet_sctp, OID_AUTO, init_rtx_max, CTLFLAG_RW,
681 &sctp_init_rtx_max_default, 0,
682 "Default maximum number of retransmission for INIT chunks");
684 SYSCTL_UINT(_net_inet_sctp, OID_AUTO, assoc_rtx_max, CTLFLAG_RW,
685 &sctp_assoc_rtx_max_default, 0,
686 "Default maximum number of retransmissions per association");
688 SYSCTL_UINT(_net_inet_sctp, OID_AUTO, path_rtx_max, CTLFLAG_RW,
689 &sctp_path_rtx_max_default, 0,
690 "Default maximum of retransmissions per path");
692 SYSCTL_UINT(_net_inet_sctp, OID_AUTO, nr_outgoing_streams, CTLFLAG_RW,
693 &sctp_nr_outgoing_streams_default, 0,
694 "Default number of outgoing streams");
697 SYSCTL_INT(_net_inet_sctp, OID_AUTO, debug, CTLFLAG_RW,
698 &sctp_debug_on, 0, "Configure debug output");
699 #endif /* SCTP_DEBUG */
703 sctp_abort(struct socket *so)
705 struct sctp_inpcb *inp;
707 inp = (struct sctp_inpcb *)so->so_pcb;
709 return EINVAL; /* ??? possible? panic instead? */
712 sctp_inpcb_free(inp, 1);
718 #if defined(__FreeBSD__) && __FreeBSD_version >= 500000
719 sctp_attach(struct socket *so, int proto, struct thread *p)
720 #elif defined(__DragonFly__)
721 sctp_attach(struct socket *so, int proto, struct pru_attach_info *ai)
723 sctp_attach(struct socket *so, int proto, struct proc *p)
726 struct sctp_inpcb *inp;
727 struct inpcb *ip_inp;
731 inp = (struct sctp_inpcb *)so->so_pcb;
736 error = soreserve(so, sctp_sendspace, sctp_recvspace, NULL);
741 error = sctp_inpcb_alloc(so);
746 inp = (struct sctp_inpcb *)so->so_pcb;
749 inp->sctp_flags &= ~SCTP_PCB_FLAGS_BOUND_V6; /* I'm not v6! */
750 ip_inp = &inp->ip_inp.inp;
751 #if defined(__FreeBSD__) || defined(__APPLE__) || defined(__DragonFly__)
752 ip_inp->inp_vflag |= INP_IPV4;
753 ip_inp->inp_ip_ttl = ip_defttl;
755 inp->inp_vflag |= INP_IPV4;
756 inp->inp_ip_ttl = ip_defttl;
760 #if !(defined(__OpenBSD__) || defined(__APPLE__))
761 error = ipsec_init_pcbpolicy(so, &ip_inp->inp_sp);
763 sctp_inpcb_free(inp, 1);
768 SCTP_INP_WUNLOCK(inp);
769 #if defined(__NetBSD__)
770 so->so_send = sctp_sosend;
777 #if (defined(__FreeBSD__) && __FreeBSD_version >= 500000) || defined(__DragonFly__)
778 sctp_bind(struct socket *so, struct sockaddr *addr, struct thread *p)
780 #elif defined(__FreeBSD__) || defined(__APPLE__)
781 sctp_bind(struct socket *so, struct sockaddr *addr, struct proc *p)
784 sctp_bind(struct socket *so, struct mbuf *nam, struct proc *p)
786 struct sockaddr *addr = nam ? mtod(nam, struct sockaddr *) : NULL;
788 struct sctp_inpcb *inp;
792 if (addr && addr->sa_family != AF_INET)
793 /* must be a v4 address! */
797 inp = (struct sctp_inpcb *)so->so_pcb;
802 error = sctp_inpcb_bind(so, addr, p);
809 sctp_detach(struct socket *so)
811 struct sctp_inpcb *inp;
813 inp = (struct sctp_inpcb *)so->so_pcb;
817 if (((so->so_options & SO_LINGER) && (so->so_linger == 0)) ||
818 (so->so_rcv.sb_cc > 0)) {
819 sctp_inpcb_free(inp, 1);
821 sctp_inpcb_free(inp, 0);
828 #if (defined(__FreeBSD__) && __FreeBSD_version >= 500000) || defined(__DragonFly__)
829 sctp_send(struct socket *so, int flags, struct mbuf *m, struct sockaddr *addr,
830 struct mbuf *control, struct thread *p);
832 sctp_send(struct socket *so, int flags, struct mbuf *m, struct sockaddr *addr,
833 struct mbuf *control, struct proc *p);
837 #if (defined(__FreeBSD__) && __FreeBSD_version >= 500000) || defined(__DragonFly__)
838 sctp_send(struct socket *so, int flags, struct mbuf *m, struct sockaddr *addr,
839 struct mbuf *control, struct thread *p)
842 sctp_send(struct socket *so, int flags, struct mbuf *m, struct sockaddr *addr,
843 struct mbuf *control, struct proc *p)
846 struct sctp_inpcb *inp;
848 inp = (struct sctp_inpcb *)so->so_pcb;
851 sctp_m_freem(control);
857 /* Got to have an to address if we are NOT a connected socket */
858 if ((addr == NULL) &&
859 ((inp->sctp_flags & SCTP_PCB_FLAGS_CONNECTED) ||
860 (inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE))
863 } else if (addr == NULL) {
864 error = EDESTADDRREQ;
867 sctp_m_freem(control);
873 if (addr->sa_family != AF_INET) {
874 /* must be a v4 address! */
877 sctp_m_freem(control);
880 error = EDESTADDRREQ;
885 /* now what about control */
888 printf("huh? control set?\n");
889 sctp_m_freem(inp->control);
892 inp->control = control;
894 /* add it in possibly */
895 if ((inp->pkt) && (inp->pkt->m_flags & M_PKTHDR)) {
901 for (x=m;x;x = x->m_next) {
904 inp->pkt->m_pkthdr.len += c_len;
908 inp->pkt_last->m_next = m;
911 inp->pkt_last = inp->pkt = m;
914 #if defined (__FreeBSD__) || defined(__APPLE__) || defined(__DragonFly__)
915 /* FreeBSD uses a flag passed */
916 ((flags & PRUS_MORETOCOME) == 0)
917 #elif defined( __NetBSD__)
918 /* NetBSD uses the so_state field */
919 ((so->so_state & SS_MORETOCOME) == 0)
921 1 /* Open BSD does not have any "more to come" indication */
925 * note with the current version this code will only be used
926 * by OpenBSD-- NetBSD, FreeBSD, and MacOS have methods for
927 * re-defining sosend to use the sctp_sosend. One can
928 * optionally switch back to this code (by changing back the
929 * definitions) but this is not advisable.
932 ret = sctp_output(inp, inp->pkt, addr, inp->control, p, flags);
942 sctp_disconnect(struct socket *so)
944 struct sctp_inpcb *inp;
947 inp = (struct sctp_inpcb *)so->so_pcb;
953 if (inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) {
954 if (LIST_EMPTY(&inp->sctp_asoc_list)) {
957 SCTP_INP_RUNLOCK(inp);
960 int some_on_streamwheel = 0;
961 struct sctp_association *asoc;
962 struct sctp_tcb *stcb;
964 stcb = LIST_FIRST(&inp->sctp_asoc_list);
967 SCTP_INP_RUNLOCK(inp);
972 if (((so->so_options & SO_LINGER) &&
973 (so->so_linger == 0)) ||
974 (so->so_rcv.sb_cc > 0)) {
975 if (SCTP_GET_STATE(asoc) !=
976 SCTP_STATE_COOKIE_WAIT) {
977 /* Left with Data unread */
980 MGET(err, MB_DONTWAIT, MT_DATA);
982 /* Fill in the user initiated abort */
983 struct sctp_paramhdr *ph;
984 ph = mtod(err, struct sctp_paramhdr *);
985 err->m_len = sizeof(struct sctp_paramhdr);
986 ph->param_type = htons(SCTP_CAUSE_USER_INITIATED_ABT);
987 ph->param_length = htons(err->m_len);
989 sctp_send_abort_tcb(stcb, err);
991 SCTP_INP_RUNLOCK(inp);
992 sctp_free_assoc(inp, stcb);
993 /* No unlock tcb assoc is gone */
997 if (!TAILQ_EMPTY(&asoc->out_wheel)) {
998 /* Check to see if some data queued */
999 struct sctp_stream_out *outs;
1000 TAILQ_FOREACH(outs, &asoc->out_wheel,
1002 if (!TAILQ_EMPTY(&outs->outqueue)) {
1003 some_on_streamwheel = 1;
1009 if (TAILQ_EMPTY(&asoc->send_queue) &&
1010 TAILQ_EMPTY(&asoc->sent_queue) &&
1011 (some_on_streamwheel == 0)) {
1012 /* there is nothing queued to send, so done */
1013 if ((SCTP_GET_STATE(asoc) !=
1014 SCTP_STATE_SHUTDOWN_SENT) &&
1015 (SCTP_GET_STATE(asoc) !=
1016 SCTP_STATE_SHUTDOWN_ACK_SENT)) {
1017 /* only send SHUTDOWN 1st time thru */
1019 if (sctp_debug_on & SCTP_DEBUG_OUTPUT4) {
1020 printf("%s:%d sends a shutdown\n",
1026 sctp_send_shutdown(stcb,
1027 stcb->asoc.primary_destination);
1028 sctp_chunk_output(stcb->sctp_ep, stcb, 1);
1029 asoc->state = SCTP_STATE_SHUTDOWN_SENT;
1030 sctp_timer_start(SCTP_TIMER_TYPE_SHUTDOWN,
1031 stcb->sctp_ep, stcb,
1032 asoc->primary_destination);
1033 sctp_timer_start(SCTP_TIMER_TYPE_SHUTDOWNGUARD,
1034 stcb->sctp_ep, stcb,
1035 asoc->primary_destination);
1039 * we still got (or just got) data to send,
1040 * so set SHUTDOWN_PENDING
1043 * XXX sockets draft says that MSG_EOF should
1044 * be sent with no data.
1045 * currently, we will allow user data to be
1046 * sent first and move to SHUTDOWN-PENDING
1048 asoc->state |= SCTP_STATE_SHUTDOWN_PENDING;
1050 SCTP_TCB_UNLOCK(stcb);
1051 SCTP_INP_RUNLOCK(inp);
1057 /* UDP model does not support this */
1058 SCTP_INP_RUNLOCK(inp);
1065 sctp_shutdown(struct socket *so)
1067 struct sctp_inpcb *inp;
1070 inp = (struct sctp_inpcb *)so->so_pcb;
1075 SCTP_INP_RLOCK(inp);
1076 /* For UDP model this is a invalid call */
1077 if (inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) {
1078 /* Restore the flags that the soshutdown took away. */
1079 #if defined(__FreeBSD__) && __FreeBSD_version >= 502115
1080 so->so_rcv.sb_state &= ~SBS_CANTRCVMORE;
1082 so->so_state &= ~SS_CANTRCVMORE;
1084 /* This proc will wakeup for read and do nothing (I hope) */
1086 SCTP_INP_RUNLOCK(inp);
1087 return (EOPNOTSUPP);
1090 * Ok if we reach here its the TCP model and it is either a SHUT_WR
1091 * or SHUT_RDWR. This means we put the shutdown flag against it.
1094 int some_on_streamwheel = 0;
1095 struct sctp_tcb *stcb;
1096 struct sctp_association *asoc;
1099 stcb = LIST_FIRST(&inp->sctp_asoc_list);
1102 * Ok we hit the case that the shutdown call was made
1103 * after an abort or something. Nothing to do now.
1108 SCTP_TCB_LOCK(stcb);
1111 if (!TAILQ_EMPTY(&asoc->out_wheel)) {
1112 /* Check to see if some data queued */
1113 struct sctp_stream_out *outs;
1114 TAILQ_FOREACH(outs, &asoc->out_wheel, next_spoke) {
1115 if (!TAILQ_EMPTY(&outs->outqueue)) {
1116 some_on_streamwheel = 1;
1121 if (TAILQ_EMPTY(&asoc->send_queue) &&
1122 TAILQ_EMPTY(&asoc->sent_queue) &&
1123 (some_on_streamwheel == 0)) {
1124 /* there is nothing queued to send, so I'm done... */
1125 if (SCTP_GET_STATE(asoc) != SCTP_STATE_SHUTDOWN_SENT) {
1126 /* only send SHUTDOWN the first time through */
1128 if (sctp_debug_on & SCTP_DEBUG_OUTPUT4) {
1129 printf("%s:%d sends a shutdown\n",
1135 sctp_send_shutdown(stcb,
1136 stcb->asoc.primary_destination);
1137 sctp_chunk_output(stcb->sctp_ep, stcb, 1);
1138 asoc->state = SCTP_STATE_SHUTDOWN_SENT;
1139 sctp_timer_start(SCTP_TIMER_TYPE_SHUTDOWN,
1140 stcb->sctp_ep, stcb,
1141 asoc->primary_destination);
1142 sctp_timer_start(SCTP_TIMER_TYPE_SHUTDOWNGUARD,
1143 stcb->sctp_ep, stcb,
1144 asoc->primary_destination);
1148 * we still got (or just got) data to send, so
1149 * set SHUTDOWN_PENDING
1151 asoc->state |= SCTP_STATE_SHUTDOWN_PENDING;
1153 SCTP_TCB_UNLOCK(stcb);
1155 SCTP_INP_RUNLOCK(inp);
1161 * copies a "user" presentable address and removes embedded scope, etc.
1162 * returns 0 on success, 1 on error
1165 sctp_fill_user_address(struct sockaddr_storage *ss, struct sockaddr *sa)
1167 struct sockaddr_in6 lsa6;
1168 sa = (struct sockaddr *)sctp_recover_scope((struct sockaddr_in6 *)sa,
1170 memcpy(ss, sa, sa->sa_len);
1175 #if defined(__NetBSD__) || defined(__OpenBSD__)
1177 * On NetBSD and OpenBSD in6_sin_2_v4mapsin6() not used and not exported,
1178 * so we have to export it here.
1180 void in6_sin_2_v4mapsin6 __P((struct sockaddr_in *sin,
1181 struct sockaddr_in6 *sin6));
1185 sctp_fill_up_addresses(struct sctp_inpcb *inp,
1186 struct sctp_tcb *stcb,
1188 struct sockaddr_storage *sas)
1192 int loopback_scope, ipv4_local_scope, local_scope, site_scope, actual;
1193 int ipv4_addr_legal, ipv6_addr_legal;
1199 /* Turn on all the appropriate scope */
1200 loopback_scope = stcb->asoc.loopback_scope;
1201 ipv4_local_scope = stcb->asoc.ipv4_local_scope;
1202 local_scope = stcb->asoc.local_scope;
1203 site_scope = stcb->asoc.site_scope;
1205 /* Turn on ALL scope, since we look at the EP */
1206 loopback_scope = ipv4_local_scope = local_scope =
1209 ipv4_addr_legal = ipv6_addr_legal = 0;
1210 if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) {
1211 ipv6_addr_legal = 1;
1213 #if defined(__OpenBSD__)
1214 (0) /* we always do dual bind */
1215 #elif defined (__NetBSD__)
1216 (((struct in6pcb *)inp)->in6p_flags & IN6P_IPV6_V6ONLY)
1218 (((struct in6pcb *)inp)->inp_flags & IN6P_IPV6_V6ONLY)
1221 ipv4_addr_legal = 1;
1224 ipv4_addr_legal = 1;
1227 if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUNDALL) {
1228 TAILQ_FOREACH(ifn, &ifnet, if_list) {
1229 if ((loopback_scope == 0) &&
1230 (ifn->if_type == IFT_LOOP)) {
1231 /* Skip loopback if loopback_scope not set */
1234 TAILQ_FOREACH(ifa, &ifn->if_addrlist, ifa_list) {
1237 * For the BOUND-ALL case, the list
1238 * associated with a TCB is Always
1239 * considered a reverse list.. i.e.
1240 * it lists addresses that are NOT
1241 * part of the association. If this
1242 * is one of those we must skip it.
1244 if (sctp_is_addr_restricted(stcb,
1249 if ((ifa->ifa_addr->sa_family == AF_INET) &&
1250 (ipv4_addr_legal)) {
1251 struct sockaddr_in *sin;
1252 sin = (struct sockaddr_in *)ifa->ifa_addr;
1253 if (sin->sin_addr.s_addr == 0) {
1254 /* we skip unspecifed addresses */
1257 if ((ipv4_local_scope == 0) &&
1258 (IN4_ISPRIVATE_ADDRESS(&sin->sin_addr))) {
1261 if (inp->sctp_flags & SCTP_PCB_FLAGS_NEEDS_MAPPED_V4) {
1262 in6_sin_2_v4mapsin6(sin, (struct sockaddr_in6 *)sas);
1263 ((struct sockaddr_in6 *)sas)->sin6_port = inp->sctp_lport;
1264 sas = (struct sockaddr_storage *)((caddr_t)sas + sizeof(struct sockaddr_in6));
1265 actual += sizeof(sizeof(struct sockaddr_in6));
1267 memcpy(sas, sin, sizeof(*sin));
1268 ((struct sockaddr_in *)sas)->sin_port = inp->sctp_lport;
1269 sas = (struct sockaddr_storage *)((caddr_t)sas + sizeof(*sin));
1270 actual += sizeof(*sin);
1272 if (actual >= limit) {
1275 } else if ((ifa->ifa_addr->sa_family == AF_INET6) &&
1276 (ipv6_addr_legal)) {
1277 struct sockaddr_in6 *sin6, lsa6;
1278 sin6 = (struct sockaddr_in6 *)ifa->ifa_addr;
1279 if (IN6_IS_ADDR_UNSPECIFIED(&sin6->sin6_addr)) {
1280 /* we skip unspecifed addresses */
1283 if (IN6_IS_ADDR_LINKLOCAL(&sin6->sin6_addr)) {
1284 if (local_scope == 0)
1286 if (sin6->sin6_scope_id == 0) {
1288 if (in6_recoverscope(&lsa6,
1291 /* bad link local address */
1296 if ((site_scope == 0) &&
1297 (IN6_IS_ADDR_SITELOCAL(&sin6->sin6_addr))) {
1300 memcpy(sas, sin6, sizeof(*sin6));
1301 ((struct sockaddr_in6 *)sas)->sin6_port = inp->sctp_lport;
1302 sas = (struct sockaddr_storage *)((caddr_t)sas + sizeof(*sin6));
1303 actual += sizeof(*sin6);
1304 if (actual >= limit) {
1311 struct sctp_laddr *laddr;
1313 * If we have a TCB and we do NOT support ASCONF (it's
1314 * turned off or otherwise) then the list is always the
1315 * true list of addresses (the else case below). Otherwise
1316 * the list on the association is a list of addresses that
1317 * are NOT part of the association.
1319 if (inp->sctp_flags & SCTP_PCB_FLAGS_DO_ASCONF) {
1320 /* The list is a NEGATIVE list */
1321 LIST_FOREACH(laddr, &inp->sctp_addr_list, sctp_nxt_addr) {
1323 if (sctp_is_addr_restricted(stcb, laddr->ifa->ifa_addr)) {
1327 if (sctp_fill_user_address(sas, laddr->ifa->ifa_addr))
1330 ((struct sockaddr_in6 *)sas)->sin6_port = inp->sctp_lport;
1331 sas = (struct sockaddr_storage *)((caddr_t)sas +
1332 laddr->ifa->ifa_addr->sa_len);
1333 actual += laddr->ifa->ifa_addr->sa_len;
1334 if (actual >= limit) {
1339 /* The list is a positive list if present */
1341 /* Must use the specific association list */
1342 LIST_FOREACH(laddr, &stcb->asoc.sctp_local_addr_list,
1344 if (sctp_fill_user_address(sas,
1345 laddr->ifa->ifa_addr))
1347 ((struct sockaddr_in6 *)sas)->sin6_port = inp->sctp_lport;
1348 sas = (struct sockaddr_storage *)((caddr_t)sas +
1349 laddr->ifa->ifa_addr->sa_len);
1350 actual += laddr->ifa->ifa_addr->sa_len;
1351 if (actual >= limit) {
1356 /* No endpoint so use the endpoints individual list */
1357 LIST_FOREACH(laddr, &inp->sctp_addr_list,
1359 if (sctp_fill_user_address(sas,
1360 laddr->ifa->ifa_addr))
1362 ((struct sockaddr_in6 *)sas)->sin6_port = inp->sctp_lport;
1363 sas = (struct sockaddr_storage *)((caddr_t)sas +
1364 laddr->ifa->ifa_addr->sa_len);
1365 actual += laddr->ifa->ifa_addr->sa_len;
1366 if (actual >= limit) {
1377 sctp_count_max_addresses(struct sctp_inpcb *inp)
1381 * In both sub-set bound an bound_all cases we return the MAXIMUM
1382 * number of addresses that you COULD get. In reality the sub-set
1383 * bound may have an exclusion list for a given TCB OR in the
1384 * bound-all case a TCB may NOT include the loopback or other
1385 * addresses as well.
1387 if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUNDALL) {
1391 TAILQ_FOREACH(ifn, &ifnet, if_list) {
1392 TAILQ_FOREACH(ifa, &ifn->if_addrlist, ifa_list) {
1393 /* Count them if they are the right type */
1394 if (ifa->ifa_addr->sa_family == AF_INET) {
1395 if (inp->sctp_flags & SCTP_PCB_FLAGS_NEEDS_MAPPED_V4)
1396 cnt += sizeof(struct sockaddr_in6);
1398 cnt += sizeof(struct sockaddr_in);
1400 } else if (ifa->ifa_addr->sa_family == AF_INET6)
1401 cnt += sizeof(struct sockaddr_in6);
1405 struct sctp_laddr *laddr;
1406 LIST_FOREACH(laddr, &inp->sctp_addr_list, sctp_nxt_addr) {
1407 if (laddr->ifa->ifa_addr->sa_family == AF_INET) {
1408 if (inp->sctp_flags & SCTP_PCB_FLAGS_NEEDS_MAPPED_V4)
1409 cnt += sizeof(struct sockaddr_in6);
1411 cnt += sizeof(struct sockaddr_in);
1413 } else if (laddr->ifa->ifa_addr->sa_family == AF_INET6)
1414 cnt += sizeof(struct sockaddr_in6);
1421 sctp_do_connect_x(struct socket *so,
1422 struct sctp_inpcb *inp,
1424 #if (defined(__FreeBSD__) && __FreeBSD_version >= 500000) || defined(__DragonFly__)
1433 struct sctp_tcb *stcb = NULL;
1434 struct sockaddr *sa;
1435 int num_v6=0, num_v4=0, *totaddrp, totaddr, i, incr, at;
1437 if (sctp_debug_on & SCTP_DEBUG_PCB1) {
1438 printf("Connectx called\n");
1440 #endif /* SCTP_DEBUG */
1443 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) &&
1444 (inp->sctp_flags & SCTP_PCB_FLAGS_CONNECTED)) {
1445 /* We are already connected AND the TCP model */
1447 return (EADDRINUSE);
1449 if (inp->sctp_flags & SCTP_PCB_FLAGS_CONNECTED) {
1450 SCTP_INP_RLOCK(inp);
1451 stcb = LIST_FIRST(&inp->sctp_asoc_list);
1452 SCTP_INP_RUNLOCK(inp);
1459 SCTP_ASOC_CREATE_LOCK(inp);
1460 if ((inp->sctp_flags & SCTP_PCB_FLAGS_SOCKET_GONE) ||
1461 (inp->sctp_flags & SCTP_PCB_FLAGS_SOCKET_GONE)) {
1462 SCTP_ASOC_CREATE_UNLOCK(inp);
1467 totaddrp = mtod(m, int *);
1468 totaddr = *totaddrp;
1469 sa = (struct sockaddr *)(totaddrp + 1);
1471 /* account and validate addresses */
1472 SCTP_INP_WLOCK(inp);
1473 SCTP_INP_INCR_REF(inp);
1474 SCTP_INP_WUNLOCK(inp);
1475 for (i = 0; i < totaddr; i++) {
1476 if (sa->sa_family == AF_INET) {
1478 incr = sizeof(struct sockaddr_in);
1479 } else if (sa->sa_family == AF_INET6) {
1480 struct sockaddr_in6 *sin6;
1481 sin6 = (struct sockaddr_in6 *)sa;
1482 if (IN6_IS_ADDR_V4MAPPED(&sin6->sin6_addr)) {
1483 /* Must be non-mapped for connectx */
1484 SCTP_ASOC_CREATE_UNLOCK(inp);
1489 incr = sizeof(struct sockaddr_in6);
1494 stcb = sctp_findassociation_ep_addr(&inp, sa, NULL, NULL, NULL);
1496 /* Already have or am bring up an association */
1497 SCTP_ASOC_CREATE_UNLOCK(inp);
1498 SCTP_TCB_UNLOCK(stcb);
1502 if ((at + incr) > m->m_len) {
1506 sa = (struct sockaddr *)((caddr_t)sa + incr);
1508 sa = (struct sockaddr *)(totaddrp + 1);
1509 SCTP_INP_WLOCK(inp);
1510 SCTP_INP_DECR_REF(inp);
1511 SCTP_INP_WUNLOCK(inp);
1513 if (((inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) == 0) &&
1516 SCTP_INP_WUNLOCK(inp);
1517 SCTP_ASOC_CREATE_UNLOCK(inp);
1520 if ((inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) &&
1522 struct in6pcb *inp6;
1523 inp6 = (struct in6pcb *)inp;
1525 #if defined(__OpenBSD__)
1526 (0) /* we always do dual bind */
1527 #elif defined (__NetBSD__)
1528 (inp6->in6p_flags & IN6P_IPV6_V6ONLY)
1530 (inp6->inp_flags & IN6P_IPV6_V6ONLY)
1534 * if IPV6_V6ONLY flag, ignore connections
1535 * destined to a v4 addr or v4-mapped addr
1537 SCTP_INP_WUNLOCK(inp);
1538 SCTP_ASOC_CREATE_UNLOCK(inp);
1544 if ((inp->sctp_flags & SCTP_PCB_FLAGS_UNBOUND) ==
1545 SCTP_PCB_FLAGS_UNBOUND) {
1546 /* Bind a ephemeral port */
1547 SCTP_INP_WUNLOCK(inp);
1548 error = sctp_inpcb_bind(so, NULL, p);
1550 SCTP_ASOC_CREATE_UNLOCK(inp);
1555 SCTP_INP_WUNLOCK(inp);
1557 /* We are GOOD to go */
1558 stcb = sctp_aloc_assoc(inp, sa, 1, &error, 0);
1560 /* Gak! no memory */
1561 SCTP_ASOC_CREATE_UNLOCK(inp);
1565 /* move to second address */
1566 if (sa->sa_family == AF_INET)
1567 sa = (struct sockaddr *)((caddr_t)sa + sizeof(struct sockaddr_in));
1569 sa = (struct sockaddr *)((caddr_t)sa + sizeof(struct sockaddr_in6));
1571 for (i = 1; i < totaddr; i++) {
1572 if (sa->sa_family == AF_INET) {
1573 incr = sizeof(struct sockaddr_in);
1574 if (sctp_add_remote_addr(stcb, sa, 0, 8)) {
1575 /* assoc gone no un-lock */
1576 sctp_free_assoc(inp, stcb);
1577 SCTP_ASOC_CREATE_UNLOCK(inp);
1582 } else if (sa->sa_family == AF_INET6) {
1583 incr = sizeof(struct sockaddr_in6);
1584 if (sctp_add_remote_addr(stcb, sa, 0, 8)) {
1585 /* assoc gone no un-lock */
1586 sctp_free_assoc(inp, stcb);
1587 SCTP_ASOC_CREATE_UNLOCK(inp);
1592 sa = (struct sockaddr *)((caddr_t)sa + incr);
1594 stcb->asoc.state = SCTP_STATE_COOKIE_WAIT;
1596 /* doing delayed connection */
1597 stcb->asoc.delayed_connection = 1;
1598 sctp_timer_start(SCTP_TIMER_TYPE_INIT, inp, stcb, stcb->asoc.primary_destination);
1600 SCTP_GETTIME_TIMEVAL(&stcb->asoc.time_entered);
1601 sctp_send_initiate(inp, stcb);
1603 SCTP_TCB_UNLOCK(stcb);
1604 if (stcb->sctp_ep->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) {
1605 stcb->sctp_ep->sctp_flags |= SCTP_PCB_FLAGS_CONNECTED;
1606 /* Set the connected flag so we can queue data */
1609 SCTP_ASOC_CREATE_UNLOCK(inp);
1616 sctp_optsget(struct socket *so,
1619 #if (defined(__FreeBSD__) && __FreeBSD_version >= 500000) || defined(__DragonFly__)
1626 struct sctp_inpcb *inp;
1628 int error, optval=0;
1629 struct sctp_tcb *stcb = NULL;
1631 inp = (struct sctp_inpcb *)so->so_pcb;
1638 if (sctp_debug_on & SCTP_DEBUG_USRREQ1) {
1639 printf("optsget:MP is NULL EINVAL\n");
1641 #endif /* SCTP_DEBUG */
1646 /* Got to have a mbuf */
1648 if (sctp_debug_on & SCTP_DEBUG_USRREQ1) {
1649 printf("Huh no mbuf\n");
1651 #endif /* SCTP_DEBUG */
1655 if (sctp_debug_on & SCTP_DEBUG_USRREQ2) {
1656 printf("optsget opt:%lxx sz:%u\n", (unsigned long)opt,
1659 #endif /* SCTP_DEBUG */
1663 case SCTP_AUTOCLOSE:
1664 case SCTP_AUTO_ASCONF:
1665 case SCTP_DISABLE_FRAGMENTS:
1666 case SCTP_I_WANT_MAPPED_V4_ADDR:
1668 if (sctp_debug_on & SCTP_DEBUG_USRREQ2) {
1669 printf("other stuff\n");
1671 #endif /* SCTP_DEBUG */
1672 SCTP_INP_RLOCK(inp);
1674 case SCTP_DISABLE_FRAGMENTS:
1675 optval = inp->sctp_flags & SCTP_PCB_FLAGS_NO_FRAGMENT;
1677 case SCTP_I_WANT_MAPPED_V4_ADDR:
1678 optval = inp->sctp_flags & SCTP_PCB_FLAGS_NEEDS_MAPPED_V4;
1680 case SCTP_AUTO_ASCONF:
1681 optval = inp->sctp_flags & SCTP_PCB_FLAGS_AUTO_ASCONF;
1684 optval = inp->sctp_flags & SCTP_PCB_FLAGS_NODELAY;
1686 case SCTP_AUTOCLOSE:
1687 if ((inp->sctp_flags & SCTP_PCB_FLAGS_AUTOCLOSE) ==
1688 SCTP_PCB_FLAGS_AUTOCLOSE)
1689 optval = inp->sctp_ep.auto_close_time;
1695 error = ENOPROTOOPT;
1696 } /* end switch (sopt->sopt_name) */
1697 if (opt != SCTP_AUTOCLOSE) {
1698 /* make it an "on/off" value */
1699 optval = (optval != 0);
1701 if ((size_t)m->m_len < sizeof(int)) {
1704 SCTP_INP_RUNLOCK(inp);
1706 /* return the option value */
1707 *mtod(m, int *) = optval;
1708 m->m_len = sizeof(optval);
1711 case SCTP_GET_ASOC_ID_LIST:
1713 struct sctp_assoc_ids *ids;
1717 if ((size_t)m->m_len < sizeof(struct sctp_assoc_ids)) {
1721 ids = mtod(m, struct sctp_assoc_ids *);
1723 SCTP_INP_RLOCK(inp);
1724 stcb = LIST_FIRST(&inp->sctp_asoc_list);
1727 ids->asls_numb_present = 0;
1728 ids->asls_more_to_get = 0;
1729 SCTP_INP_RUNLOCK(inp);
1732 orig = ids->asls_assoc_start;
1733 stcb = LIST_FIRST(&inp->sctp_asoc_list);
1735 stcb = LIST_NEXT(stcb , sctp_tcblist);
1743 ids->asls_numb_present = 0;
1744 ids->asls_more_to_get = 1;
1745 while(at < MAX_ASOC_IDS_RET) {
1746 ids->asls_assoc_id[at] = sctp_get_associd(stcb);
1748 ids->asls_numb_present++;
1749 stcb = LIST_NEXT(stcb , sctp_tcblist);
1751 ids->asls_more_to_get = 0;
1755 SCTP_INP_RUNLOCK(inp);
1758 case SCTP_GET_NONCE_VALUES:
1760 struct sctp_get_nonce_values *gnv;
1761 if ((size_t)m->m_len < sizeof(struct sctp_get_nonce_values)) {
1765 gnv = mtod(m, struct sctp_get_nonce_values *);
1766 stcb = sctp_findassociation_ep_asocid(inp, gnv->gn_assoc_id);
1770 gnv->gn_peers_tag = stcb->asoc.peer_vtag;
1771 gnv->gn_local_tag = stcb->asoc.my_vtag;
1772 SCTP_TCB_UNLOCK(stcb);
1777 case SCTP_PEER_PUBLIC_KEY:
1778 case SCTP_MY_PUBLIC_KEY:
1779 case SCTP_SET_AUTH_CHUNKS:
1780 case SCTP_SET_AUTH_SECRET:
1781 /* not supported yet and until we refine the draft */
1785 case SCTP_DELAYED_ACK_TIME:
1788 if ((size_t)m->m_len < sizeof(int32_t)) {
1792 tm = mtod(m, int32_t *);
1794 *tm = TICKS_TO_MSEC(inp->sctp_ep.sctp_timeoutticks[SCTP_TIMER_RECV]);
1798 case SCTP_GET_SNDBUF_USE:
1799 if ((size_t)m->m_len < sizeof(struct sctp_sockstat)) {
1802 struct sctp_sockstat *ss;
1803 struct sctp_tcb *stcb;
1804 struct sctp_association *asoc;
1805 ss = mtod(m, struct sctp_sockstat *);
1806 stcb = sctp_findassociation_ep_asocid(inp, ss->ss_assoc_id);
1811 ss->ss_total_sndbuf = (u_int32_t)asoc->total_output_queue_size;
1812 ss->ss_total_mbuf_sndbuf = (u_int32_t)asoc->total_output_mbuf_queue_size;
1813 ss->ss_total_recv_buf = (u_int32_t)(asoc->size_on_delivery_queue +
1814 asoc->size_on_reasm_queue +
1815 asoc->size_on_all_streams);
1816 SCTP_TCB_UNLOCK(stcb);
1818 m->m_len = sizeof(struct sctp_sockstat);
1825 burst = mtod(m, u_int8_t *);
1826 SCTP_INP_RLOCK(inp);
1827 *burst = inp->sctp_ep.max_burst;
1828 SCTP_INP_RUNLOCK(inp);
1829 m->m_len = sizeof(u_int8_t);
1835 sctp_assoc_t *assoc_id;
1838 if ((size_t)m->m_len < sizeof(u_int32_t)) {
1842 if ((size_t)m->m_len < sizeof(sctp_assoc_t)) {
1846 assoc_id = mtod(m, sctp_assoc_t *);
1847 segsize = mtod(m, u_int32_t *);
1848 m->m_len = sizeof(u_int32_t);
1850 if (((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) &&
1851 (inp->sctp_flags & SCTP_PCB_FLAGS_CONNECTED)) ||
1852 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL)) {
1853 struct sctp_tcb *stcb;
1854 SCTP_INP_RLOCK(inp);
1855 stcb = LIST_FIRST(&inp->sctp_asoc_list);
1857 SCTP_TCB_LOCK(stcb);
1858 SCTP_INP_RUNLOCK(inp);
1859 *segsize = sctp_get_frag_point(stcb, &stcb->asoc);
1860 SCTP_TCB_UNLOCK(stcb);
1862 SCTP_INP_RUNLOCK(inp);
1866 stcb = sctp_findassociation_ep_asocid(inp, *assoc_id);
1868 *segsize = sctp_get_frag_point(stcb, &stcb->asoc);
1869 SCTP_TCB_UNLOCK(stcb);
1873 /* default is to get the max, if I
1874 * can't calculate from an existing association.
1876 if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) {
1877 ovh = SCTP_MED_OVERHEAD;
1879 ovh = SCTP_MED_V4_OVERHEAD;
1881 *segsize = inp->sctp_frag_point - ovh;
1886 case SCTP_SET_DEBUG_LEVEL:
1890 if ((size_t)m->m_len < sizeof(u_int32_t)) {
1894 level = mtod(m, u_int32_t *);
1896 *level = sctp_debug_on;
1897 m->m_len = sizeof(u_int32_t);
1898 printf("Returning DEBUG LEVEL %x is set\n",
1899 (u_int)sctp_debug_on);
1901 #else /* SCTP_DEBUG */
1905 case SCTP_GET_STAT_LOG:
1906 #ifdef SCTP_STAT_LOGGING
1907 error = sctp_fill_stat_log(m);
1908 #else /* SCTP_DEBUG */
1915 if ((size_t)m->m_len < sizeof(sctp_pegs)) {
1919 pt = mtod(m, u_int32_t *);
1920 memcpy(pt, sctp_pegs, sizeof(sctp_pegs));
1921 m->m_len = sizeof(sctp_pegs);
1926 struct sctp_event_subscribe *events;
1928 if (sctp_debug_on & SCTP_DEBUG_USRREQ2) {
1929 printf("get events\n");
1931 #endif /* SCTP_DEBUG */
1932 if ((size_t)m->m_len < sizeof(struct sctp_event_subscribe)) {
1934 if (sctp_debug_on & SCTP_DEBUG_USRREQ2) {
1935 printf("M->M_LEN is %d not %d\n",
1937 (int)sizeof(struct sctp_event_subscribe));
1939 #endif /* SCTP_DEBUG */
1943 events = mtod(m, struct sctp_event_subscribe *);
1944 memset(events, 0, sizeof(events));
1945 SCTP_INP_RLOCK(inp);
1946 if (inp->sctp_flags & SCTP_PCB_FLAGS_RECVDATAIOEVNT)
1947 events->sctp_data_io_event = 1;
1949 if (inp->sctp_flags & SCTP_PCB_FLAGS_RECVASSOCEVNT)
1950 events->sctp_association_event = 1;
1952 if (inp->sctp_flags & SCTP_PCB_FLAGS_RECVPADDREVNT)
1953 events->sctp_address_event = 1;
1955 if (inp->sctp_flags & SCTP_PCB_FLAGS_RECVSENDFAILEVNT)
1956 events->sctp_send_failure_event = 1;
1958 if (inp->sctp_flags & SCTP_PCB_FLAGS_RECVPEERERR)
1959 events->sctp_peer_error_event = 1;
1961 if (inp->sctp_flags & SCTP_PCB_FLAGS_RECVSHUTDOWNEVNT)
1962 events->sctp_shutdown_event = 1;
1964 if (inp->sctp_flags & SCTP_PCB_FLAGS_PDAPIEVNT)
1965 events->sctp_partial_delivery_event = 1;
1967 if (inp->sctp_flags & SCTP_PCB_FLAGS_ADAPTIONEVNT)
1968 events->sctp_adaption_layer_event = 1;
1970 if (inp->sctp_flags & SCTP_PCB_FLAGS_STREAM_RESETEVNT)
1971 events->sctp_stream_reset_events = 1;
1972 SCTP_INP_RUNLOCK(inp);
1973 m->m_len = sizeof(struct sctp_event_subscribe);
1978 case SCTP_ADAPTION_LAYER:
1979 if ((size_t)m->m_len < sizeof(int)) {
1984 if (sctp_debug_on & SCTP_DEBUG_USRREQ1) {
1985 printf("getadaption ind\n");
1987 #endif /* SCTP_DEBUG */
1988 SCTP_INP_RLOCK(inp);
1989 *mtod(m, int *) = inp->sctp_ep.adaption_layer_indicator;
1990 SCTP_INP_RUNLOCK(inp);
1991 m->m_len = sizeof(int);
1993 case SCTP_SET_INITIAL_DBG_SEQ:
1994 if ((size_t)m->m_len < sizeof(int)) {
1999 if (sctp_debug_on & SCTP_DEBUG_USRREQ1) {
2000 printf("get initial dbg seq\n");
2002 #endif /* SCTP_DEBUG */
2003 SCTP_INP_RLOCK(inp);
2004 *mtod(m, int *) = inp->sctp_ep.initial_sequence_debug;
2005 SCTP_INP_RUNLOCK(inp);
2006 m->m_len = sizeof(int);
2008 case SCTP_GET_LOCAL_ADDR_SIZE:
2009 if ((size_t)m->m_len < sizeof(int)) {
2014 if (sctp_debug_on & SCTP_DEBUG_USRREQ1) {
2015 printf("get local sizes\n");
2017 #endif /* SCTP_DEBUG */
2018 SCTP_INP_RLOCK(inp);
2019 *mtod(m, int *) = sctp_count_max_addresses(inp);
2020 SCTP_INP_RUNLOCK(inp);
2021 m->m_len = sizeof(int);
2023 case SCTP_GET_REMOTE_ADDR_SIZE:
2025 sctp_assoc_t *assoc_id;
2027 struct sctp_nets *net;
2029 if (sctp_debug_on & SCTP_DEBUG_USRREQ1) {
2030 printf("get remote size\n");
2032 #endif /* SCTP_DEBUG */
2033 if ((size_t)m->m_len < sizeof(sctp_assoc_t)) {
2035 printf("m->m_len:%d not %d\n",
2036 m->m_len, sizeof(sctp_assoc_t));
2037 #endif /* SCTP_DEBUG */
2042 val = mtod(m, u_int32_t *);
2043 if (inp->sctp_flags & SCTP_PCB_FLAGS_CONNECTED) {
2044 SCTP_INP_RLOCK(inp);
2045 stcb = LIST_FIRST(&inp->sctp_asoc_list);
2047 SCTP_TCB_LOCK(stcb);
2048 SCTP_INP_RUNLOCK(inp);
2051 assoc_id = mtod(m, sctp_assoc_t *);
2052 stcb = sctp_findassociation_ep_asocid(inp, *assoc_id);
2061 /* Count the sizes */
2062 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
2063 if ((stcb->sctp_ep->sctp_flags & SCTP_PCB_FLAGS_NEEDS_MAPPED_V4) ||
2064 (((struct sockaddr *)&net->ro._l_addr)->sa_family == AF_INET6)) {
2065 sz += sizeof(struct sockaddr_in6);
2066 } else if (((struct sockaddr *)&net->ro._l_addr)->sa_family == AF_INET) {
2067 sz += sizeof(struct sockaddr_in);
2073 SCTP_TCB_UNLOCK(stcb);
2075 m->m_len = sizeof(u_int32_t);
2078 case SCTP_GET_PEER_ADDRESSES:
2080 * Get the address information, an array
2081 * is passed in to fill up we pack it.
2085 struct sockaddr_storage *sas;
2086 struct sctp_nets *net;
2087 struct sctp_getaddresses *saddr;
2089 if (sctp_debug_on & SCTP_DEBUG_USRREQ1) {
2090 printf("get peer addresses\n");
2092 #endif /* SCTP_DEBUG */
2093 if ((size_t)m->m_len < sizeof(struct sctp_getaddresses)) {
2097 left = m->m_len - sizeof(struct sctp_getaddresses);
2098 saddr = mtod(m, struct sctp_getaddresses *);
2099 if (inp->sctp_flags & SCTP_PCB_FLAGS_CONNECTED) {
2100 SCTP_INP_RLOCK(inp);
2101 stcb = LIST_FIRST(&inp->sctp_asoc_list);
2103 SCTP_TCB_LOCK(stcb);
2104 SCTP_INP_RUNLOCK(inp);
2106 stcb = sctp_findassociation_ep_asocid(inp,
2107 saddr->sget_assoc_id);
2112 m->m_len = sizeof(struct sctp_getaddresses);
2113 sas = (struct sockaddr_storage *)&saddr->addr[0];
2115 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
2116 if ((stcb->sctp_ep->sctp_flags & SCTP_PCB_FLAGS_NEEDS_MAPPED_V4) ||
2117 (((struct sockaddr *)&net->ro._l_addr)->sa_family == AF_INET6)) {
2118 cpsz = sizeof(struct sockaddr_in6);
2119 } else if (((struct sockaddr *)&net->ro._l_addr)->sa_family == AF_INET) {
2120 cpsz = sizeof(struct sockaddr_in);
2126 /* not enough room. */
2128 if (sctp_debug_on & SCTP_DEBUG_USRREQ1) {
2129 printf("Out of room\n");
2131 #endif /* SCTP_DEBUG */
2134 if ((stcb->sctp_ep->sctp_flags & SCTP_PCB_FLAGS_NEEDS_MAPPED_V4) &&
2135 (((struct sockaddr *)&net->ro._l_addr)->sa_family == AF_INET)) {
2136 /* Must map the address */
2137 in6_sin_2_v4mapsin6((struct sockaddr_in *)&net->ro._l_addr,
2138 (struct sockaddr_in6 *)sas);
2140 memcpy(sas, &net->ro._l_addr, cpsz);
2142 ((struct sockaddr_in *)sas)->sin_port = stcb->rport;
2144 sas = (struct sockaddr_storage *)((caddr_t)sas + cpsz);
2148 if (sctp_debug_on & SCTP_DEBUG_USRREQ2) {
2149 printf("left now:%d mlen:%d\n",
2152 #endif /* SCTP_DEBUG */
2154 SCTP_TCB_UNLOCK(stcb);
2157 if (sctp_debug_on & SCTP_DEBUG_USRREQ1) {
2158 printf("All done\n");
2160 #endif /* SCTP_DEBUG */
2162 case SCTP_GET_LOCAL_ADDRESSES:
2165 struct sockaddr_storage *sas;
2166 struct sctp_getaddresses *saddr;
2168 if (sctp_debug_on & SCTP_DEBUG_USRREQ1) {
2169 printf("get local addresses\n");
2171 #endif /* SCTP_DEBUG */
2172 if ((size_t)m->m_len < sizeof(struct sctp_getaddresses)) {
2176 saddr = mtod(m, struct sctp_getaddresses *);
2178 if (saddr->sget_assoc_id) {
2179 if (inp->sctp_flags & SCTP_PCB_FLAGS_CONNECTED) {
2180 SCTP_INP_RLOCK(inp);
2181 stcb = LIST_FIRST(&inp->sctp_asoc_list);
2183 SCTP_TCB_LOCK(stcb);
2184 SCTP_INP_RUNLOCK(inp);
2186 stcb = sctp_findassociation_ep_asocid(inp, saddr->sget_assoc_id);
2192 * assure that the TCP model does not need a assoc id
2195 if ( (inp->sctp_flags & SCTP_PCB_FLAGS_CONNECTED) &&
2197 SCTP_INP_RLOCK(inp);
2198 stcb = LIST_FIRST(&inp->sctp_asoc_list);
2200 SCTP_TCB_LOCK(stcb);
2201 SCTP_INP_RUNLOCK(inp);
2203 sas = (struct sockaddr_storage *)&saddr->addr[0];
2204 limit = m->m_len - sizeof(sctp_assoc_t);
2205 actual = sctp_fill_up_addresses(inp, stcb, limit, sas);
2206 SCTP_TCB_UNLOCK(stcb);
2207 m->m_len = sizeof(struct sockaddr_storage) + actual;
2210 case SCTP_PEER_ADDR_PARAMS:
2212 struct sctp_paddrparams *paddrp;
2213 struct sctp_nets *net;
2216 if (sctp_debug_on & SCTP_DEBUG_USRREQ1) {
2217 printf("Getting peer_addr_params\n");
2219 #endif /* SCTP_DEBUG */
2220 if ((size_t)m->m_len < sizeof(struct sctp_paddrparams)) {
2222 if (sctp_debug_on & SCTP_DEBUG_USRREQ2) {
2223 printf("Hmm m->m_len:%d is to small\n",
2226 #endif /* SCTP_DEBUG */
2230 paddrp = mtod(m, struct sctp_paddrparams *);
2233 if (paddrp->spp_assoc_id) {
2235 if (sctp_debug_on & SCTP_DEBUG_USRREQ1) {
2236 printf("In spp_assoc_id find type\n");
2238 #endif /* SCTP_DEBUG */
2239 if (inp->sctp_flags & SCTP_PCB_FLAGS_CONNECTED) {
2240 SCTP_INP_RLOCK(inp);
2241 stcb = LIST_FIRST(&inp->sctp_asoc_list);
2243 SCTP_TCB_LOCK(stcb);
2244 net = sctp_findnet(stcb, (struct sockaddr *)&paddrp->spp_address);
2246 SCTP_INP_RLOCK(inp);
2248 stcb = sctp_findassociation_ep_asocid(inp, paddrp->spp_assoc_id);
2255 if ( (stcb == NULL) &&
2256 ((((struct sockaddr *)&paddrp->spp_address)->sa_family == AF_INET) ||
2257 (((struct sockaddr *)&paddrp->spp_address)->sa_family == AF_INET6))) {
2258 /* Lookup via address */
2260 if (sctp_debug_on & SCTP_DEBUG_USRREQ1) {
2261 printf("Ok we need to lookup a param\n");
2263 #endif /* SCTP_DEBUG */
2264 if (inp->sctp_flags & SCTP_PCB_FLAGS_CONNECTED) {
2265 SCTP_INP_RLOCK(inp);
2266 stcb = LIST_FIRST(&inp->sctp_asoc_list);
2268 SCTP_TCB_LOCK(stcb);
2269 net = sctp_findnet(stcb, (struct sockaddr *)&paddrp->spp_address);
2271 SCTP_INP_RUNLOCK(inp);
2273 SCTP_INP_WLOCK(inp);
2274 SCTP_INP_INCR_REF(inp);
2275 SCTP_INP_WUNLOCK(inp);
2276 stcb = sctp_findassociation_ep_addr(&inp,
2277 (struct sockaddr *)&paddrp->spp_address,
2280 SCTP_INP_WLOCK(inp);
2281 SCTP_INP_DECR_REF(inp);
2282 SCTP_INP_WUNLOCK(inp);
2291 /* Effects the Endpoint */
2293 if (sctp_debug_on & SCTP_DEBUG_USRREQ1) {
2294 printf("User wants EP level info\n");
2296 #endif /* SCTP_DEBUG */
2300 /* Applys to the specific association */
2302 if (sctp_debug_on & SCTP_DEBUG_USRREQ1) {
2303 printf("In TCB side\n");
2305 #endif /* SCTP_DEBUG */
2307 paddrp->spp_pathmaxrxt = net->failure_threshold;
2309 /* No destination so return default value */
2310 paddrp->spp_pathmaxrxt = stcb->asoc.def_net_failure;
2312 paddrp->spp_hbinterval = stcb->asoc.heart_beat_delay;
2313 paddrp->spp_assoc_id = sctp_get_associd(stcb);
2314 SCTP_TCB_UNLOCK(stcb);
2316 /* Use endpoint defaults */
2317 SCTP_INP_RLOCK(inp);
2319 if (sctp_debug_on & SCTP_DEBUG_USRREQ1) {
2320 printf("In EP levle info\n");
2322 #endif /* SCTP_DEBUG */
2323 paddrp->spp_pathmaxrxt = inp->sctp_ep.def_net_failure;
2324 paddrp->spp_hbinterval = inp->sctp_ep.sctp_timeoutticks[SCTP_TIMER_HEARTBEAT];
2325 paddrp->spp_assoc_id = (sctp_assoc_t)0;
2326 SCTP_INP_RUNLOCK(inp);
2328 m->m_len = sizeof(struct sctp_paddrparams);
2331 case SCTP_GET_PEER_ADDR_INFO:
2333 struct sctp_paddrinfo *paddri;
2334 struct sctp_nets *net;
2336 if (sctp_debug_on & SCTP_DEBUG_USRREQ1) {
2337 printf("GetPEER ADDR_INFO\n");
2339 #endif /* SCTP_DEBUG */
2340 if ((size_t)m->m_len < sizeof(struct sctp_paddrinfo)) {
2344 paddri = mtod(m, struct sctp_paddrinfo *);
2346 if ((((struct sockaddr *)&paddri->spinfo_address)->sa_family == AF_INET) ||
2347 (((struct sockaddr *)&paddri->spinfo_address)->sa_family == AF_INET6)) {
2348 /* Lookup via address */
2349 if (inp->sctp_flags & SCTP_PCB_FLAGS_CONNECTED) {
2350 SCTP_INP_RLOCK(inp);
2351 stcb = LIST_FIRST(&inp->sctp_asoc_list);
2353 SCTP_TCB_LOCK(stcb);
2354 net = sctp_findnet(stcb,
2355 (struct sockaddr *)&paddri->spinfo_address);
2357 SCTP_INP_RUNLOCK(inp);
2359 SCTP_INP_WLOCK(inp);
2360 SCTP_INP_INCR_REF(inp);
2361 SCTP_INP_WUNLOCK(inp);
2362 stcb = sctp_findassociation_ep_addr(&inp,
2363 (struct sockaddr *)&paddri->spinfo_address,
2366 SCTP_INP_WLOCK(inp);
2367 SCTP_INP_DECR_REF(inp);
2368 SCTP_INP_WUNLOCK(inp);
2375 if ((stcb == NULL) || (net == NULL)) {
2379 m->m_len = sizeof(struct sctp_paddrinfo);
2380 paddri->spinfo_state = net->dest_state & (SCTP_REACHABLE_MASK|SCTP_ADDR_NOHB);
2381 paddri->spinfo_cwnd = net->cwnd;
2382 paddri->spinfo_srtt = ((net->lastsa >> 2) + net->lastsv) >> 1;
2383 paddri->spinfo_rto = net->RTO;
2384 paddri->spinfo_assoc_id = sctp_get_associd(stcb);
2385 SCTP_TCB_UNLOCK(stcb);
2388 case SCTP_PCB_STATUS:
2390 struct sctp_pcbinfo *spcb;
2392 if (sctp_debug_on & SCTP_DEBUG_USRREQ1) {
2393 printf("PCB status\n");
2395 #endif /* SCTP_DEBUG */
2396 if ((size_t)m->m_len < sizeof(struct sctp_pcbinfo)) {
2400 spcb = mtod(m, struct sctp_pcbinfo *);
2401 sctp_fill_pcbinfo(spcb);
2402 m->m_len = sizeof(struct sctp_pcbinfo);
2407 struct sctp_nets *net;
2408 struct sctp_status *sstat;
2410 if (sctp_debug_on & SCTP_DEBUG_USRREQ1) {
2411 printf("SCTP status\n");
2413 #endif /* SCTP_DEBUG */
2415 if ((size_t)m->m_len < sizeof(struct sctp_status)) {
2419 sstat = mtod(m, struct sctp_status *);
2421 if (inp->sctp_flags & SCTP_PCB_FLAGS_CONNECTED) {
2422 SCTP_INP_RLOCK(inp);
2423 stcb = LIST_FIRST(&inp->sctp_asoc_list);
2425 SCTP_TCB_LOCK(stcb);
2426 SCTP_INP_RUNLOCK(inp);
2428 stcb = sctp_findassociation_ep_asocid(inp, sstat->sstat_assoc_id);
2435 * I think passing the state is fine since
2436 * sctp_constants.h will be available to the user
2439 sstat->sstat_state = stcb->asoc.state;
2440 sstat->sstat_rwnd = stcb->asoc.peers_rwnd;
2441 sstat->sstat_unackdata = stcb->asoc.sent_queue_cnt;
2443 * We can't include chunks that have been passed
2444 * to the socket layer. Only things in queue.
2446 sstat->sstat_penddata = (stcb->asoc.cnt_on_delivery_queue +
2447 stcb->asoc.cnt_on_reasm_queue +
2448 stcb->asoc.cnt_on_all_streams);
2451 sstat->sstat_instrms = stcb->asoc.streamincnt;
2452 sstat->sstat_outstrms = stcb->asoc.streamoutcnt;
2453 sstat->sstat_fragmentation_point = sctp_get_frag_point(stcb, &stcb->asoc);
2454 memcpy(&sstat->sstat_primary.spinfo_address,
2455 &stcb->asoc.primary_destination->ro._l_addr,
2456 ((struct sockaddr *)(&stcb->asoc.primary_destination->ro._l_addr))->sa_len);
2457 net = stcb->asoc.primary_destination;
2458 ((struct sockaddr_in *)&sstat->sstat_primary.spinfo_address)->sin_port = stcb->rport;
2460 * Again the user can get info from sctp_constants.h
2461 * for what the state of the network is.
2463 sstat->sstat_primary.spinfo_state = net->dest_state & SCTP_REACHABLE_MASK;
2464 sstat->sstat_primary.spinfo_cwnd = net->cwnd;
2465 sstat->sstat_primary.spinfo_srtt = net->lastsa;
2466 sstat->sstat_primary.spinfo_rto = net->RTO;
2467 sstat->sstat_primary.spinfo_mtu = net->mtu;
2468 sstat->sstat_primary.spinfo_assoc_id = sctp_get_associd(stcb);
2469 SCTP_TCB_UNLOCK(stcb);
2470 m->m_len = sizeof(*sstat);
2475 struct sctp_rtoinfo *srto;
2477 if (sctp_debug_on & SCTP_DEBUG_USRREQ1) {
2478 printf("RTO Info\n");
2480 #endif /* SCTP_DEBUG */
2481 if ((size_t)m->m_len < sizeof(struct sctp_rtoinfo)) {
2485 srto = mtod(m, struct sctp_rtoinfo *);
2486 if (srto->srto_assoc_id == 0) {
2487 /* Endpoint only please */
2488 SCTP_INP_RLOCK(inp);
2489 srto->srto_initial = inp->sctp_ep.initial_rto;
2490 srto->srto_max = inp->sctp_ep.sctp_maxrto;
2491 srto->srto_min = inp->sctp_ep.sctp_minrto;
2492 SCTP_INP_RUNLOCK(inp);
2495 if (inp->sctp_flags & SCTP_PCB_FLAGS_CONNECTED) {
2496 SCTP_INP_RLOCK(inp);
2497 stcb = LIST_FIRST(&inp->sctp_asoc_list);
2499 SCTP_TCB_LOCK(stcb);
2500 SCTP_INP_RUNLOCK(inp);
2502 stcb = sctp_findassociation_ep_asocid(inp, srto->srto_assoc_id);
2508 srto->srto_initial = stcb->asoc.initial_rto;
2509 srto->srto_max = stcb->asoc.maxrto;
2510 srto->srto_min = stcb->asoc.minrto;
2511 SCTP_TCB_UNLOCK(stcb);
2512 m->m_len = sizeof(*srto);
2515 case SCTP_ASSOCINFO:
2517 struct sctp_assocparams *sasoc;
2519 if (sctp_debug_on & SCTP_DEBUG_USRREQ1) {
2520 printf("Associnfo\n");
2522 #endif /* SCTP_DEBUG */
2523 if ((size_t)m->m_len < sizeof(struct sctp_assocparams)) {
2527 sasoc = mtod(m, struct sctp_assocparams *);
2530 if (inp->sctp_flags & SCTP_PCB_FLAGS_CONNECTED) {
2531 SCTP_INP_RLOCK(inp);
2532 stcb = LIST_FIRST(&inp->sctp_asoc_list);
2534 SCTP_TCB_LOCK(stcb);
2535 SCTP_INP_RUNLOCK(inp);
2537 if ((sasoc->sasoc_assoc_id) && (stcb == NULL)) {
2538 stcb = sctp_findassociation_ep_asocid(inp,
2539 sasoc->sasoc_assoc_id);
2549 sasoc->sasoc_asocmaxrxt = stcb->asoc.max_send_times;
2550 sasoc->sasoc_number_peer_destinations = stcb->asoc.numnets;
2551 sasoc->sasoc_peer_rwnd = stcb->asoc.peers_rwnd;
2552 sasoc->sasoc_local_rwnd = stcb->asoc.my_rwnd;
2553 sasoc->sasoc_cookie_life = stcb->asoc.cookie_life;
2554 SCTP_TCB_UNLOCK(stcb);
2556 SCTP_INP_RLOCK(inp);
2557 sasoc->sasoc_asocmaxrxt = inp->sctp_ep.max_send_times;
2558 sasoc->sasoc_number_peer_destinations = 0;
2559 sasoc->sasoc_peer_rwnd = 0;
2560 sasoc->sasoc_local_rwnd = sbspace(&inp->sctp_socket->so_rcv);
2561 sasoc->sasoc_cookie_life = inp->sctp_ep.def_cookie_life;
2562 SCTP_INP_RUNLOCK(inp);
2564 m->m_len = sizeof(*sasoc);
2567 case SCTP_DEFAULT_SEND_PARAM:
2569 struct sctp_sndrcvinfo *s_info;
2571 if (m->m_len != sizeof(struct sctp_sndrcvinfo)) {
2575 s_info = mtod(m, struct sctp_sndrcvinfo *);
2576 if (inp->sctp_flags & SCTP_PCB_FLAGS_CONNECTED) {
2577 SCTP_INP_RLOCK(inp);
2578 stcb = LIST_FIRST(&inp->sctp_asoc_list);
2580 SCTP_TCB_LOCK(stcb);
2581 SCTP_INP_RUNLOCK(inp);
2583 stcb = sctp_findassociation_ep_asocid(inp, s_info->sinfo_assoc_id);
2590 *s_info = stcb->asoc.def_send;
2591 SCTP_TCB_UNLOCK(stcb);
2592 m->m_len = sizeof(*s_info);
2596 struct sctp_initmsg *sinit;
2598 if (sctp_debug_on & SCTP_DEBUG_USRREQ1) {
2599 printf("initmsg\n");
2601 #endif /* SCTP_DEBUG */
2602 if ((size_t)m->m_len < sizeof(struct sctp_initmsg)) {
2606 sinit = mtod(m, struct sctp_initmsg *);
2607 SCTP_INP_RLOCK(inp);
2608 sinit->sinit_num_ostreams = inp->sctp_ep.pre_open_stream_count;
2609 sinit->sinit_max_instreams = inp->sctp_ep.max_open_streams_intome;
2610 sinit->sinit_max_attempts = inp->sctp_ep.max_init_times;
2611 sinit->sinit_max_init_timeo = inp->sctp_ep.initial_init_rto_max;
2612 SCTP_INP_RUNLOCK(inp);
2613 m->m_len = sizeof(*sinit);
2616 case SCTP_PRIMARY_ADDR:
2617 /* we allow a "get" operation on this */
2619 struct sctp_setprim *ssp;
2622 if (sctp_debug_on & SCTP_DEBUG_USRREQ1) {
2623 printf("setprimary\n");
2625 #endif /* SCTP_DEBUG */
2626 if ((size_t)m->m_len < sizeof(struct sctp_setprim)) {
2630 ssp = mtod(m, struct sctp_setprim *);
2631 if (inp->sctp_flags & SCTP_PCB_FLAGS_CONNECTED) {
2632 SCTP_INP_RLOCK(inp);
2633 stcb = LIST_FIRST(&inp->sctp_asoc_list);
2635 SCTP_TCB_LOCK(stcb);
2636 SCTP_INP_RUNLOCK(inp);
2638 stcb = sctp_findassociation_ep_asocid(inp, ssp->ssp_assoc_id);
2640 /* one last shot, try it by the address in */
2641 struct sctp_nets *net;
2643 SCTP_INP_WLOCK(inp);
2644 SCTP_INP_INCR_REF(inp);
2645 SCTP_INP_WUNLOCK(inp);
2646 stcb = sctp_findassociation_ep_addr(&inp,
2647 (struct sockaddr *)&ssp->ssp_addr,
2650 SCTP_INP_WLOCK(inp);
2651 SCTP_INP_DECR_REF(inp);
2652 SCTP_INP_WUNLOCK(inp);
2660 /* simply copy out the sockaddr_storage... */
2661 memcpy(&ssp->ssp_addr,
2662 &stcb->asoc.primary_destination->ro._l_addr,
2663 ((struct sockaddr *)&stcb->asoc.primary_destination->ro._l_addr)->sa_len);
2664 SCTP_TCB_UNLOCK(stcb);
2665 m->m_len = sizeof(*ssp);
2669 error = ENOPROTOOPT;
2672 } /* end switch (sopt->sopt_name) */
2677 sctp_optsset(struct socket *so,
2680 #if (defined(__FreeBSD__) && __FreeBSD_version >= 500000) || defined(__DragonFly__)
2687 int error, *mopt, set_opt;
2689 struct sctp_tcb *stcb = NULL;
2690 struct sctp_inpcb *inp;
2694 if (sctp_debug_on & SCTP_DEBUG_USRREQ1) {
2695 printf("optsset:MP is NULL EINVAL\n");
2697 #endif /* SCTP_DEBUG */
2704 inp = (struct sctp_inpcb *)so->so_pcb;
2711 case SCTP_AUTOCLOSE:
2712 case SCTP_AUTO_ASCONF:
2713 case SCTP_DISABLE_FRAGMENTS:
2714 case SCTP_I_WANT_MAPPED_V4_ADDR:
2715 /* copy in the option value */
2716 if ((size_t)m->m_len < sizeof(int)) {
2720 mopt = mtod(m, int *);
2725 case SCTP_DISABLE_FRAGMENTS:
2726 set_opt = SCTP_PCB_FLAGS_NO_FRAGMENT;
2728 case SCTP_AUTO_ASCONF:
2729 set_opt = SCTP_PCB_FLAGS_AUTO_ASCONF;
2732 case SCTP_I_WANT_MAPPED_V4_ADDR:
2733 if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) {
2734 set_opt = SCTP_PCB_FLAGS_NEEDS_MAPPED_V4;
2740 set_opt = SCTP_PCB_FLAGS_NODELAY;
2742 case SCTP_AUTOCLOSE:
2743 set_opt = SCTP_PCB_FLAGS_AUTOCLOSE;
2745 * The value is in ticks.
2746 * Note this does not effect old associations, only
2749 inp->sctp_ep.auto_close_time = (*mopt * hz);
2752 SCTP_INP_WLOCK(inp);
2754 inp->sctp_flags |= set_opt;
2756 inp->sctp_flags &= ~set_opt;
2758 SCTP_INP_WUNLOCK(inp);
2760 case SCTP_MY_PUBLIC_KEY: /* set my public key */
2761 case SCTP_SET_AUTH_CHUNKS: /* set the authenticated chunks required */
2762 case SCTP_SET_AUTH_SECRET: /* set the actual secret for the endpoint */
2763 /* not supported yet and until we refine the draft */
2767 case SCTP_CLR_STAT_LOG:
2768 #ifdef SCTP_STAT_LOGGING
2769 sctp_clr_stat_log();
2774 case SCTP_DELAYED_ACK_TIME:
2777 if ((size_t)m->m_len < sizeof(int32_t)) {
2781 tm = mtod(m, int32_t *);
2783 if ((*tm < 10) || (*tm > 500)) {
2784 /* can't be smaller than 10ms */
2785 /* MUST NOT be larger than 500ms */
2789 inp->sctp_ep.sctp_timeoutticks[SCTP_TIMER_RECV] = MSEC_TO_TICKS(*tm);
2792 case SCTP_RESET_STREAMS:
2794 struct sctp_stream_reset *strrst;
2795 uint8_t two_way, not_peer;
2797 if ((size_t)m->m_len < sizeof(struct sctp_stream_reset)) {
2801 strrst = mtod(m, struct sctp_stream_reset *);
2803 if (inp->sctp_flags & SCTP_PCB_FLAGS_CONNECTED) {
2804 SCTP_INP_RLOCK(inp);
2805 stcb = LIST_FIRST(&inp->sctp_asoc_list);
2807 SCTP_TCB_LOCK(stcb);
2808 SCTP_INP_RUNLOCK(inp);
2810 stcb = sctp_findassociation_ep_asocid(inp, strrst->strrst_assoc_id);
2815 if (stcb->asoc.peer_supports_strreset == 0) {
2816 /* Peer does not support it,
2817 * we return protocol not supported since
2818 * this is true for this feature and this
2819 * peer, not the socket request in general.
2821 error = EPROTONOSUPPORT;
2822 SCTP_TCB_UNLOCK(stcb);
2826 /* Having re-thought this code I added as I write the I-D there
2827 * is NO need for it. The peer, if we are requesting a stream-reset
2828 * will send a request to us but will itself do what we do, take
2829 * and copy off the "reset information" we send and queue TSN's
2830 * larger than the send-next in our response message. Thus they
2833 /* if (stcb->asoc.sending_seq != (stcb->asoc.last_acked_seq + 1)) {*/
2834 /* Must have all sending data ack'd before we
2835 * start this procedure. This is a bit restrictive
2836 * and we SHOULD work on changing this so ONLY the
2837 * streams being RESET get held up. So, a reset-all
2838 * would require this.. but a reset specific just
2839 * needs to be sure that the ones being reset have
2840 * nothing on the send_queue. For now we will
2841 * skip this more detailed method and do a course
2842 * way.. i.e. nothing pending ... for future FIX ME!
2848 if (stcb->asoc.stream_reset_outstanding) {
2850 SCTP_TCB_UNLOCK(stcb);
2853 if (strrst->strrst_flags == SCTP_RESET_LOCAL_RECV) {
2856 } else if (strrst->strrst_flags == SCTP_RESET_LOCAL_SEND) {
2859 } else if (strrst->strrst_flags == SCTP_RESET_BOTH) {
2864 SCTP_TCB_UNLOCK(stcb);
2867 sctp_send_str_reset_req(stcb, strrst->strrst_num_streams,
2868 strrst->strrst_list, two_way, not_peer);
2870 sctp_chunk_output(inp, stcb, 12);
2871 SCTP_TCB_UNLOCK(stcb);
2876 case SCTP_RESET_PEGS:
2877 memset(sctp_pegs, 0, sizeof(sctp_pegs));
2880 case SCTP_CONNECT_X:
2881 if ((size_t)m->m_len < (sizeof(int) + sizeof(struct sockaddr_in))) {
2885 error = sctp_do_connect_x(so, inp, m, p, 0);
2888 case SCTP_CONNECT_X_DELAYED:
2889 if ((size_t)m->m_len < (sizeof(int) + sizeof(struct sockaddr_in))) {
2893 error = sctp_do_connect_x(so, inp, m, p, 1);
2896 case SCTP_CONNECT_X_COMPLETE:
2898 struct sockaddr *sa;
2899 struct sctp_nets *net;
2900 if ((size_t)m->m_len < sizeof(struct sockaddr_in)) {
2904 sa = mtod(m, struct sockaddr *);
2906 if (inp->sctp_flags & SCTP_PCB_FLAGS_CONNECTED) {
2907 SCTP_INP_RLOCK(inp);
2908 stcb = LIST_FIRST(&inp->sctp_asoc_list);
2910 SCTP_TCB_LOCK(stcb);
2911 net = sctp_findnet(stcb, sa);
2913 SCTP_INP_RUNLOCK(inp);
2915 SCTP_INP_WLOCK(inp);
2916 SCTP_INP_INCR_REF(inp);
2917 SCTP_INP_WUNLOCK(inp);
2918 stcb = sctp_findassociation_ep_addr(&inp, sa, &net, NULL, NULL);
2920 SCTP_INP_WLOCK(inp);
2921 SCTP_INP_DECR_REF(inp);
2922 SCTP_INP_WUNLOCK(inp);
2930 if (stcb->asoc.delayed_connection == 1) {
2931 stcb->asoc.delayed_connection = 0;
2932 SCTP_GETTIME_TIMEVAL(&stcb->asoc.time_entered);
2933 sctp_timer_stop(SCTP_TIMER_TYPE_INIT, inp, stcb, stcb->asoc.primary_destination);
2934 sctp_send_initiate(inp, stcb);
2936 /* already expired or did not use delayed connectx */
2939 SCTP_TCB_UNLOCK(stcb);
2945 SCTP_INP_WLOCK(inp);
2946 burst = mtod(m, u_int8_t *);
2948 inp->sctp_ep.max_burst = *burst;
2950 SCTP_INP_WUNLOCK(inp);
2957 if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) {
2958 ovh = SCTP_MED_OVERHEAD;
2960 ovh = SCTP_MED_V4_OVERHEAD;
2962 segsize = mtod(m, u_int32_t *);
2967 SCTP_INP_WLOCK(inp);
2968 inp->sctp_frag_point = (*segsize+ovh);
2969 if (inp->sctp_frag_point < MHLEN) {
2970 inp->sctp_frag_point = MHLEN;
2972 SCTP_INP_WUNLOCK(inp);
2975 case SCTP_SET_DEBUG_LEVEL:
2979 if ((size_t)m->m_len < sizeof(u_int32_t)) {
2983 level = mtod(m, u_int32_t *);
2985 sctp_debug_on = (*level & (SCTP_DEBUG_ALL |
2987 printf("SETTING DEBUG LEVEL to %x\n",
2988 (u_int)sctp_debug_on);
2993 #endif /* SCTP_DEBUG */
2997 struct sctp_event_subscribe *events;
2998 if ((size_t)m->m_len < sizeof(struct sctp_event_subscribe)) {
3002 SCTP_INP_WLOCK(inp);
3003 events = mtod(m, struct sctp_event_subscribe *);
3004 if (events->sctp_data_io_event) {
3005 inp->sctp_flags |= SCTP_PCB_FLAGS_RECVDATAIOEVNT;
3007 inp->sctp_flags &= ~SCTP_PCB_FLAGS_RECVDATAIOEVNT;
3010 if (events->sctp_association_event) {
3011 inp->sctp_flags |= SCTP_PCB_FLAGS_RECVASSOCEVNT;
3013 inp->sctp_flags &= ~SCTP_PCB_FLAGS_RECVASSOCEVNT;
3016 if (events->sctp_address_event) {
3017 inp->sctp_flags |= SCTP_PCB_FLAGS_RECVPADDREVNT;
3019 inp->sctp_flags &= ~SCTP_PCB_FLAGS_RECVPADDREVNT;
3022 if (events->sctp_send_failure_event) {
3023 inp->sctp_flags |= SCTP_PCB_FLAGS_RECVSENDFAILEVNT;
3025 inp->sctp_flags &= ~SCTP_PCB_FLAGS_RECVSENDFAILEVNT;
3028 if (events->sctp_peer_error_event) {
3029 inp->sctp_flags |= SCTP_PCB_FLAGS_RECVPEERERR;
3031 inp->sctp_flags &= ~SCTP_PCB_FLAGS_RECVPEERERR;
3034 if (events->sctp_shutdown_event) {
3035 inp->sctp_flags |= SCTP_PCB_FLAGS_RECVSHUTDOWNEVNT;
3037 inp->sctp_flags &= ~SCTP_PCB_FLAGS_RECVSHUTDOWNEVNT;
3040 if (events->sctp_partial_delivery_event) {
3041 inp->sctp_flags |= SCTP_PCB_FLAGS_PDAPIEVNT;
3043 inp->sctp_flags &= ~SCTP_PCB_FLAGS_PDAPIEVNT;
3046 if (events->sctp_adaption_layer_event) {
3047 inp->sctp_flags |= SCTP_PCB_FLAGS_ADAPTIONEVNT;
3049 inp->sctp_flags &= ~SCTP_PCB_FLAGS_ADAPTIONEVNT;
3052 if (events->sctp_stream_reset_events) {
3053 inp->sctp_flags |= SCTP_PCB_FLAGS_STREAM_RESETEVNT;
3055 inp->sctp_flags &= ~SCTP_PCB_FLAGS_STREAM_RESETEVNT;
3057 SCTP_INP_WUNLOCK(inp);
3061 case SCTP_ADAPTION_LAYER:
3063 struct sctp_setadaption *adap_bits;
3064 if ((size_t)m->m_len < sizeof(struct sctp_setadaption)) {
3068 SCTP_INP_WLOCK(inp);
3069 adap_bits = mtod(m, struct sctp_setadaption *);
3070 inp->sctp_ep.adaption_layer_indicator = adap_bits->ssb_adaption_ind;
3071 SCTP_INP_WUNLOCK(inp);
3074 case SCTP_SET_INITIAL_DBG_SEQ:
3077 if ((size_t)m->m_len < sizeof(u_int32_t)) {
3081 SCTP_INP_WLOCK(inp);
3082 vvv = mtod(m, u_int32_t *);
3083 inp->sctp_ep.initial_sequence_debug = *vvv;
3084 SCTP_INP_WUNLOCK(inp);
3087 case SCTP_DEFAULT_SEND_PARAM:
3089 struct sctp_sndrcvinfo *s_info;
3091 if (m->m_len != sizeof(struct sctp_sndrcvinfo)) {
3095 s_info = mtod(m, struct sctp_sndrcvinfo *);
3097 if (inp->sctp_flags & SCTP_PCB_FLAGS_CONNECTED) {
3098 SCTP_INP_RLOCK(inp);
3099 stcb = LIST_FIRST(&inp->sctp_asoc_list);
3101 SCTP_TCB_LOCK(stcb);
3102 SCTP_INP_RUNLOCK(inp);
3104 stcb = sctp_findassociation_ep_asocid(inp, s_info->sinfo_assoc_id);
3110 /* Validate things */
3111 if (s_info->sinfo_stream > stcb->asoc.streamoutcnt) {
3112 SCTP_TCB_UNLOCK(stcb);
3116 /* Mask off the flags that are allowed */
3117 s_info->sinfo_flags = (s_info->sinfo_flags &
3118 (MSG_UNORDERED | MSG_ADDR_OVER |
3119 MSG_PR_SCTP_TTL | MSG_PR_SCTP_BUF));
3121 stcb->asoc.def_send = *s_info;
3122 SCTP_TCB_UNLOCK(stcb);
3125 case SCTP_PEER_ADDR_PARAMS:
3127 struct sctp_paddrparams *paddrp;
3128 struct sctp_nets *net;
3129 if ((size_t)m->m_len < sizeof(struct sctp_paddrparams)) {
3133 paddrp = mtod(m, struct sctp_paddrparams *);
3135 if (paddrp->spp_assoc_id) {
3136 if (inp->sctp_flags & SCTP_PCB_FLAGS_CONNECTED) {
3137 SCTP_INP_RLOCK(inp);
3138 stcb = LIST_FIRST(&inp->sctp_asoc_list);
3140 SCTP_TCB_LOCK(stcb);
3141 net = sctp_findnet(stcb, (struct sockaddr *)&paddrp->spp_address);
3143 SCTP_INP_RUNLOCK(inp);
3145 stcb = sctp_findassociation_ep_asocid(inp, paddrp->spp_assoc_id);
3152 if ((stcb == NULL) &&
3153 ((((struct sockaddr *)&paddrp->spp_address)->sa_family == AF_INET) ||
3154 (((struct sockaddr *)&paddrp->spp_address)->sa_family == AF_INET6))) {
3155 /* Lookup via address */
3156 if (inp->sctp_flags & SCTP_PCB_FLAGS_CONNECTED) {
3157 SCTP_INP_RLOCK(inp);
3158 stcb = LIST_FIRST(&inp->sctp_asoc_list);
3160 SCTP_TCB_LOCK(stcb);
3161 net = sctp_findnet(stcb,
3162 (struct sockaddr *)&paddrp->spp_address);
3164 SCTP_INP_RUNLOCK(inp);
3166 SCTP_INP_WLOCK(inp);
3167 SCTP_INP_INCR_REF(inp);
3168 SCTP_INP_WUNLOCK(inp);
3169 stcb = sctp_findassociation_ep_addr(&inp,
3170 (struct sockaddr *)&paddrp->spp_address,
3173 SCTP_INP_WLOCK(inp);
3174 SCTP_INP_DECR_REF(inp);
3175 SCTP_INP_WUNLOCK(inp);
3179 /* Effects the Endpoint */
3183 /* Applies to the specific association */
3184 if (paddrp->spp_pathmaxrxt) {
3186 if (paddrp->spp_pathmaxrxt)
3187 net->failure_threshold = paddrp->spp_pathmaxrxt;
3189 if (paddrp->spp_pathmaxrxt)
3190 stcb->asoc.def_net_failure = paddrp->spp_pathmaxrxt;
3193 if ((paddrp->spp_hbinterval != 0) && (paddrp->spp_hbinterval != 0xffffffff)) {
3197 net->dest_state &= ~SCTP_ADDR_NOHB;
3199 old = stcb->asoc.heart_beat_delay;
3200 stcb->asoc.heart_beat_delay = paddrp->spp_hbinterval;
3202 /* Turn back on the timer */
3203 sctp_timer_start(SCTP_TIMER_TYPE_HEARTBEAT, inp, stcb, net);
3206 } else if (paddrp->spp_hbinterval == 0xffffffff) {
3208 sctp_send_hb(stcb, 1, net);
3211 /* off on association */
3212 if (stcb->asoc.heart_beat_delay) {
3213 int cnt_of_unconf = 0;
3214 struct sctp_nets *lnet;
3215 TAILQ_FOREACH(lnet, &stcb->asoc.nets, sctp_next) {
3216 if (lnet->dest_state & SCTP_ADDR_UNCONFIRMED) {
3220 /* stop the timer ONLY if we have no unconfirmed addresses
3222 if (cnt_of_unconf == 0)
3223 sctp_timer_stop(SCTP_TIMER_TYPE_HEARTBEAT, inp, stcb, net);
3225 stcb->asoc.heart_beat_delay = 0;
3227 net->dest_state |= SCTP_ADDR_NOHB;
3230 SCTP_TCB_UNLOCK(stcb);
3232 /* Use endpoint defaults */
3233 SCTP_INP_WLOCK(inp);
3234 if (paddrp->spp_pathmaxrxt)
3235 inp->sctp_ep.def_net_failure = paddrp->spp_pathmaxrxt;
3236 if (paddrp->spp_hbinterval != SCTP_ISSUE_HB)
3237 inp->sctp_ep.sctp_timeoutticks[SCTP_TIMER_HEARTBEAT] = paddrp->spp_hbinterval;
3238 SCTP_INP_WUNLOCK(inp);
3244 struct sctp_rtoinfo *srto;
3245 if ((size_t)m->m_len < sizeof(struct sctp_rtoinfo)) {
3249 srto = mtod(m, struct sctp_rtoinfo *);
3250 if (srto->srto_assoc_id == 0) {
3251 SCTP_INP_WLOCK(inp);
3252 /* If we have a null asoc, its default for the endpoint */
3253 if (srto->srto_initial > 10)
3254 inp->sctp_ep.initial_rto = srto->srto_initial;
3255 if (srto->srto_max > 10)
3256 inp->sctp_ep.sctp_maxrto = srto->srto_max;
3257 if (srto->srto_min > 10)
3258 inp->sctp_ep.sctp_minrto = srto->srto_min;
3259 SCTP_INP_WUNLOCK(inp);
3262 if (inp->sctp_flags & SCTP_PCB_FLAGS_CONNECTED) {
3263 SCTP_INP_RLOCK(inp);
3264 stcb = LIST_FIRST(&inp->sctp_asoc_list);
3266 SCTP_TCB_LOCK(stcb);
3267 SCTP_INP_RUNLOCK(inp);
3269 stcb = sctp_findassociation_ep_asocid(inp, srto->srto_assoc_id);
3274 /* Set in ms we hope :-) */
3275 if (srto->srto_initial > 10)
3276 stcb->asoc.initial_rto = srto->srto_initial;
3277 if (srto->srto_max > 10)
3278 stcb->asoc.maxrto = srto->srto_max;
3279 if (srto->srto_min > 10)
3280 stcb->asoc.minrto = srto->srto_min;
3281 SCTP_TCB_UNLOCK(stcb);
3284 case SCTP_ASSOCINFO:
3286 struct sctp_assocparams *sasoc;
3288 if ((size_t)m->m_len < sizeof(struct sctp_assocparams)) {
3292 sasoc = mtod(m, struct sctp_assocparams *);
3293 if (sasoc->sasoc_assoc_id) {
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,
3302 sasoc->sasoc_assoc_id);
3312 if (sasoc->sasoc_asocmaxrxt)
3313 stcb->asoc.max_send_times = sasoc->sasoc_asocmaxrxt;
3314 sasoc->sasoc_number_peer_destinations = stcb->asoc.numnets;
3315 sasoc->sasoc_peer_rwnd = 0;
3316 sasoc->sasoc_local_rwnd = 0;
3317 if (stcb->asoc.cookie_life)
3318 stcb->asoc.cookie_life = sasoc->sasoc_cookie_life;
3319 SCTP_TCB_UNLOCK(stcb);
3321 SCTP_INP_WLOCK(inp);
3322 if (sasoc->sasoc_asocmaxrxt)
3323 inp->sctp_ep.max_send_times = sasoc->sasoc_asocmaxrxt;
3324 sasoc->sasoc_number_peer_destinations = 0;
3325 sasoc->sasoc_peer_rwnd = 0;
3326 sasoc->sasoc_local_rwnd = 0;
3327 if (sasoc->sasoc_cookie_life)
3328 inp->sctp_ep.def_cookie_life = sasoc->sasoc_cookie_life;
3329 SCTP_INP_WUNLOCK(inp);
3335 struct sctp_initmsg *sinit;
3337 if ((size_t)m->m_len < sizeof(struct sctp_initmsg)) {
3341 sinit = mtod(m, struct sctp_initmsg *);
3342 SCTP_INP_WLOCK(inp);
3343 if (sinit->sinit_num_ostreams)
3344 inp->sctp_ep.pre_open_stream_count = sinit->sinit_num_ostreams;
3346 if (sinit->sinit_max_instreams)
3347 inp->sctp_ep.max_open_streams_intome = sinit->sinit_max_instreams;
3349 if (sinit->sinit_max_attempts)
3350 inp->sctp_ep.max_init_times = sinit->sinit_max_attempts;
3352 if (sinit->sinit_max_init_timeo > 10)
3353 /* We must be at least a 100ms (we set in ticks) */
3354 inp->sctp_ep.initial_init_rto_max = sinit->sinit_max_init_timeo;
3355 SCTP_INP_WUNLOCK(inp);
3358 case SCTP_PRIMARY_ADDR:
3360 struct sctp_setprim *spa;
3361 struct sctp_nets *net, *lnet;
3362 if ((size_t)m->m_len < sizeof(struct sctp_setprim)) {
3366 spa = mtod(m, struct sctp_setprim *);
3368 if (inp->sctp_flags & SCTP_PCB_FLAGS_CONNECTED) {
3369 SCTP_INP_RLOCK(inp);
3370 stcb = LIST_FIRST(&inp->sctp_asoc_list);
3372 SCTP_TCB_LOCK(stcb);
3377 SCTP_INP_RUNLOCK(inp);
3379 stcb = sctp_findassociation_ep_asocid(inp, spa->ssp_assoc_id);
3382 SCTP_INP_WLOCK(inp);
3383 SCTP_INP_INCR_REF(inp);
3384 SCTP_INP_WUNLOCK(inp);
3385 stcb = sctp_findassociation_ep_addr(&inp,
3386 (struct sockaddr *)&spa->ssp_addr,
3389 SCTP_INP_WLOCK(inp);
3390 SCTP_INP_DECR_REF(inp);
3391 SCTP_INP_WUNLOCK(inp);
3396 /* find the net, associd or connected lookup type */
3397 net = sctp_findnet(stcb, (struct sockaddr *)&spa->ssp_addr);
3399 SCTP_TCB_UNLOCK(stcb);
3404 if ((net != stcb->asoc.primary_destination) &&
3405 (!(net->dest_state & SCTP_ADDR_UNCONFIRMED))) {
3406 /* Ok we need to set it */
3407 lnet = stcb->asoc.primary_destination;
3408 lnet->next_tsn_at_change = net->next_tsn_at_change = stcb->asoc.sending_seq;
3409 if (sctp_set_primary_addr(stcb,
3410 (struct sockaddr *)NULL,
3412 if (net->dest_state & SCTP_ADDR_SWITCH_PRIMARY) {
3413 net->dest_state |= SCTP_ADDR_DOUBLE_SWITCH;
3415 net->dest_state |= SCTP_ADDR_SWITCH_PRIMARY;
3418 SCTP_TCB_UNLOCK(stcb);
3422 case SCTP_SET_PEER_PRIMARY_ADDR:
3424 struct sctp_setpeerprim *sspp;
3425 if ((size_t)m->m_len < sizeof(struct sctp_setpeerprim)) {
3429 sspp = mtod(m, struct sctp_setpeerprim *);
3432 if (inp->sctp_flags & SCTP_PCB_FLAGS_CONNECTED) {
3433 SCTP_INP_RLOCK(inp);
3434 stcb = LIST_FIRST(&inp->sctp_asoc_list);
3436 SCTP_TCB_UNLOCK(stcb);
3437 SCTP_INP_RUNLOCK(inp);
3439 stcb = sctp_findassociation_ep_asocid(inp, sspp->sspp_assoc_id);
3444 if (sctp_set_primary_ip_address_sa(stcb, (struct sockaddr *)&sspp->sspp_addr) != 0) {
3447 SCTP_TCB_UNLOCK(stcb);
3450 case SCTP_BINDX_ADD_ADDR:
3452 struct sctp_getaddresses *addrs;
3453 struct sockaddr *addr_touse;
3454 struct sockaddr_in sin;
3455 /* see if we're bound all already! */
3456 if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUNDALL) {
3460 if ((size_t)m->m_len < sizeof(struct sctp_getaddresses)) {
3464 addrs = mtod(m, struct sctp_getaddresses *);
3465 addr_touse = addrs->addr;
3466 if (addrs->addr->sa_family == AF_INET6) {
3467 struct sockaddr_in6 *sin6;
3468 sin6 = (struct sockaddr_in6 *)addr_touse;
3469 if (IN6_IS_ADDR_V4MAPPED(&sin6->sin6_addr)) {
3470 in6_sin6_2_sin(&sin, sin6);
3471 addr_touse = (struct sockaddr *)&sin;
3474 if (inp->sctp_flags & SCTP_PCB_FLAGS_UNBOUND) {
3476 /* Can't get proc for Net/Open BSD */
3480 error = sctp_inpcb_bind(so, addr_touse, p);
3483 /* No locks required here since bind and mgmt_ep_sa all
3484 * do their own locking. If we do something for the FIX:
3485 * below we may need to lock in that case.
3487 if (addrs->sget_assoc_id == 0) {
3488 /* add the address */
3489 struct sctp_inpcb *lep;
3490 ((struct sockaddr_in *)addr_touse)->sin_port = inp->sctp_lport;
3491 lep = sctp_pcb_findep(addr_touse, 1, 0);
3493 /* We must decrement the refcount
3494 * since we have the ep already and
3495 * are binding. No remove going on
3498 SCTP_INP_WLOCK(inp);
3499 SCTP_INP_DECR_REF(inp);
3500 SCTP_INP_WUNLOCK(inp);
3503 /* already bound to it.. ok */
3505 } else if (lep == NULL) {
3506 ((struct sockaddr_in *)addr_touse)->sin_port = 0;
3507 error = sctp_addr_mgmt_ep_sa(inp, addr_touse,
3508 SCTP_ADD_IP_ADDRESS);
3510 error = EADDRNOTAVAIL;
3516 /* FIX: decide whether we allow assoc based bindx */
3520 case SCTP_BINDX_REM_ADDR:
3522 struct sctp_getaddresses *addrs;
3523 struct sockaddr *addr_touse;
3524 struct sockaddr_in sin;
3525 /* see if we're bound all already! */
3526 if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUNDALL) {
3530 if ((size_t)m->m_len < sizeof(struct sctp_getaddresses)) {
3534 addrs = mtod(m, struct sctp_getaddresses *);
3535 addr_touse = addrs->addr;
3536 if (addrs->addr->sa_family == AF_INET6) {
3537 struct sockaddr_in6 *sin6;
3538 sin6 = (struct sockaddr_in6 *)addr_touse;
3539 if (IN6_IS_ADDR_V4MAPPED(&sin6->sin6_addr)) {
3540 in6_sin6_2_sin(&sin, sin6);
3541 addr_touse = (struct sockaddr *)&sin;
3544 /* No lock required mgmt_ep_sa does its own locking. If
3545 * the FIX: below is ever changed we may need to
3546 * lock before calling association level binding.
3548 if (addrs->sget_assoc_id == 0) {
3549 /* delete the address */
3550 sctp_addr_mgmt_ep_sa(inp, addr_touse,
3551 SCTP_DEL_IP_ADDRESS);
3553 /* FIX: decide whether we allow assoc based bindx */
3558 error = ENOPROTOOPT;
3560 } /* end switch (opt) */
3565 #if defined(__FreeBSD__) || defined(__APPLE__) || defined(__DragonFly__)
3567 sctp_ctloutput(struct socket *so, struct sockopt *sopt)
3569 struct mbuf *m = NULL;
3570 struct sctp_inpcb *inp;
3573 inp = (struct sctp_inpcb *)so->so_pcb;
3577 /* I made the same as TCP since we are not setup? */
3578 return (ECONNRESET);
3580 if (sopt->sopt_level != IPPROTO_SCTP) {
3581 /* wrong proto level... send back up to IP */
3583 if (INP_CHECK_SOCKAF(so, AF_INET6))
3584 error = ip6_ctloutput(so, sopt);
3587 error = ip_ctloutput(so, sopt);
3591 if (sopt->sopt_valsize > MCLBYTES) {
3593 * Restrict us down to a cluster size, that's all we can
3594 * pass either way...
3596 sopt->sopt_valsize = MCLBYTES;
3598 if (sopt->sopt_valsize) {
3600 m = m_get(MB_WAIT, MT_DATA);
3601 if (sopt->sopt_valsize > MLEN) {
3602 MCLGET(m, MB_DONTWAIT);
3603 if ((m->m_flags & M_EXT) == 0) {
3609 error = sooptcopyin(sopt, mtod(m, caddr_t), sopt->sopt_valsize,
3610 sopt->sopt_valsize);
3615 m->m_len = sopt->sopt_valsize;
3617 if (sopt->sopt_dir == SOPT_SET) {
3618 #if (defined(__FreeBSD__) && __FreeBSD_version >= 500000) || defined(__DragonFly__)
3619 error = sctp_optsset(so, sopt->sopt_name, &m, sopt->sopt_td);
3621 error = sctp_optsset(so, sopt->sopt_name, &m, sopt->sopt_p);
3623 } else if (sopt->sopt_dir == SOPT_GET) {
3624 #if (defined (__FreeBSD__) && __FreeBSD_version >= 500000) || defined(__DragonFly__)
3625 error = sctp_optsget(so, sopt->sopt_name, &m, sopt->sopt_td);
3627 error = sctp_optsget(so, sopt->sopt_name, &m, sopt->sopt_p);
3632 if ( (error == 0) && (m != NULL)) {
3633 error = sooptcopyout(sopt, mtod(m, caddr_t), m->m_len);
3635 } else if (m != NULL) {
3644 /* NetBSD and OpenBSD */
3646 sctp_ctloutput(op, so, level, optname, mp)
3655 struct in6pcb *in6p;
3657 int family; /* family of the socket */
3659 family = so->so_proto->pr_domain->dom_family;
3664 inp = sotoinpcb(so);
3672 in6p = sotoin6pcb(so);
3677 return EAFNOSUPPORT;
3682 if (inp == NULL && in6p == NULL)
3686 if (op == PRCO_SETOPT && *mp)
3688 return (ECONNRESET);
3690 if (level != IPPROTO_SCTP) {
3693 error = ip_ctloutput(op, so, level, optname, mp);
3697 error = ip6_ctloutput(op, so, level, optname, mp);
3704 /* Ok if we reach here it is a SCTP option we hope */
3705 if (op == PRCO_SETOPT) {
3706 error = sctp_optsset(so, optname, mp, (struct proc *)NULL);
3709 } else if (op == PRCO_GETOPT) {
3710 error = sctp_optsget(so, optname, mp, (struct proc *)NULL);
3721 #if (defined(__FreeBSD__) && __FreeBSD_version >= 500000) || defined(__DragonFly__)
3722 sctp_connect(struct socket *so, struct sockaddr *addr, struct thread *p)
3725 #if defined(__FreeBSD__) || defined(__APPLE__)
3726 sctp_connect(struct socket *so, struct sockaddr *addr, struct proc *p)
3729 sctp_connect(struct socket *so, struct mbuf *nam, struct proc *p)
3731 struct sockaddr *addr = mtod(nam, struct sockaddr *);
3735 struct sctp_inpcb *inp;
3736 struct sctp_tcb *stcb;
3739 if (sctp_debug_on & SCTP_DEBUG_PCB1) {
3740 printf("Connect called in SCTP to ");
3741 sctp_print_address(addr);
3742 printf("Port %d\n", ntohs(((struct sockaddr_in *)addr)->sin_port));
3744 #endif /* SCTP_DEBUG */
3746 inp = (struct sctp_inpcb *)so->so_pcb;
3749 /* I made the same as TCP since we are not setup? */
3750 return (ECONNRESET);
3752 SCTP_ASOC_CREATE_LOCK(inp);
3753 SCTP_INP_WLOCK(inp);
3754 if ((inp->sctp_flags & SCTP_PCB_FLAGS_SOCKET_GONE) ||
3755 (inp->sctp_flags & SCTP_PCB_FLAGS_SOCKET_GONE)) {
3756 /* Should I really unlock ? */
3757 SCTP_INP_WUNLOCK(inp);
3758 SCTP_ASOC_CREATE_UNLOCK(inp);
3763 if (((inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) == 0) &&
3764 (addr->sa_family == AF_INET6)) {
3765 SCTP_INP_WUNLOCK(inp);
3766 SCTP_ASOC_CREATE_UNLOCK(inp);
3771 if ((inp->sctp_flags & SCTP_PCB_FLAGS_UNBOUND) ==
3772 SCTP_PCB_FLAGS_UNBOUND) {
3773 /* Bind a ephemeral port */
3774 SCTP_INP_WUNLOCK(inp);
3775 error = sctp_inpcb_bind(so, NULL, p);
3777 SCTP_ASOC_CREATE_UNLOCK(inp);
3781 SCTP_INP_WLOCK(inp);
3783 /* Now do we connect? */
3784 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) &&
3785 (inp->sctp_flags & SCTP_PCB_FLAGS_CONNECTED)) {
3786 /* We are already connected AND the TCP model */
3788 SCTP_INP_WUNLOCK(inp);
3789 SCTP_ASOC_CREATE_UNLOCK(inp);
3790 return (EADDRINUSE);
3792 if (inp->sctp_flags & SCTP_PCB_FLAGS_CONNECTED) {
3793 stcb = LIST_FIRST(&inp->sctp_asoc_list);
3795 SCTP_TCB_UNLOCK(stcb);
3796 SCTP_INP_WUNLOCK(inp);
3798 SCTP_INP_INCR_REF(inp);
3799 SCTP_INP_WUNLOCK(inp);
3800 stcb = sctp_findassociation_ep_addr(&inp, addr, NULL, NULL, NULL);
3802 SCTP_INP_WLOCK(inp);
3803 SCTP_INP_DECR_REF(inp);
3804 SCTP_INP_WUNLOCK(inp);
3808 /* Already have or am bring up an association */
3809 SCTP_ASOC_CREATE_UNLOCK(inp);
3810 SCTP_TCB_UNLOCK(stcb);
3814 /* We are GOOD to go */
3815 stcb = sctp_aloc_assoc(inp, addr, 1, &error, 0);
3817 /* Gak! no memory */
3821 if (stcb->sctp_ep->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) {
3822 stcb->sctp_ep->sctp_flags |= SCTP_PCB_FLAGS_CONNECTED;
3823 /* Set the connected flag so we can queue data */
3826 stcb->asoc.state = SCTP_STATE_COOKIE_WAIT;
3827 SCTP_GETTIME_TIMEVAL(&stcb->asoc.time_entered);
3828 sctp_send_initiate(inp, stcb);
3829 SCTP_ASOC_CREATE_UNLOCK(inp);
3830 SCTP_TCB_UNLOCK(stcb);
3836 sctp_usr_recvd(struct socket *so, int flags)
3838 struct sctp_socket_q_list *sq=NULL;
3840 * The user has received some data, we may be able to stuff more
3841 * up the socket. And we need to possibly update the rwnd.
3843 struct sctp_inpcb *inp;
3844 struct sctp_tcb *stcb=NULL;
3846 inp = (struct sctp_inpcb *)so->so_pcb;
3848 if (sctp_debug_on & SCTP_DEBUG_USRREQ2)
3849 printf("Read for so:%x inp:%x Flags:%x\n",
3850 (u_int)so, (u_int)inp, (u_int)flags);
3854 /* I made the same as TCP since we are not setup? */
3856 if (sctp_debug_on & SCTP_DEBUG_USRREQ2)
3857 printf("Nope, connection reset\n");
3859 return (ECONNRESET);
3863 * Grab the first one on the list. It will re-insert itself if
3864 * it runs out of room
3866 SCTP_INP_WLOCK(inp);
3867 if ((flags & MSG_EOR) && ((inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) == 0)
3868 && ((inp->sctp_flags & SCTP_PCB_FLAGS_CONNECTED) == 0)) {
3869 /* Ok the other part of our grubby tracking
3870 * stuff for our horrible layer violation that
3871 * the tsvwg thinks is ok for sctp_peeloff.. gak!
3872 * We must update the next vtag pending on the
3873 * socket buffer (if any).
3875 inp->sctp_vtag_first = sctp_get_first_vtag_from_sb(so);
3876 sq = TAILQ_FIRST(&inp->sctp_queue_list);
3883 stcb = LIST_FIRST(&inp->sctp_asoc_list);
3886 SCTP_TCB_LOCK(stcb);
3889 /* all code in normal stcb path assumes
3890 * that you have a tcb_lock only. Thus
3891 * we must release the inp write lock.
3893 if (flags & MSG_EOR) {
3894 if (((inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) == 0)
3895 && ((inp->sctp_flags & SCTP_PCB_FLAGS_CONNECTED) == 0)) {
3896 stcb = sctp_remove_from_socket_q(inp);
3899 if (sctp_debug_on & SCTP_DEBUG_USRREQ2)
3900 printf("remove from socket queue for inp:%x tcbret:%x\n",
3901 (u_int)inp, (u_int)stcb);
3904 stcb->asoc.my_rwnd_control_len = sctp_sbspace_sub(stcb->asoc.my_rwnd_control_len,
3905 sizeof(struct mbuf));
3906 if (inp->sctp_flags & SCTP_PCB_FLAGS_RECVDATAIOEVNT) {
3907 stcb->asoc.my_rwnd_control_len = sctp_sbspace_sub(stcb->asoc.my_rwnd_control_len,
3908 CMSG_LEN(sizeof(struct sctp_sndrcvinfo)));
3911 if ((TAILQ_EMPTY(&stcb->asoc.delivery_queue) == 0) ||
3912 (TAILQ_EMPTY(&stcb->asoc.reasmqueue) == 0)) {
3913 /* Deliver if there is something to be delivered */
3914 sctp_service_queues(stcb, &stcb->asoc, 1);
3916 sctp_set_rwnd(stcb, &stcb->asoc);
3917 /* if we increase by 1 or more MTU's (smallest MTUs of all
3918 * nets) we send a window update sack
3920 incr = stcb->asoc.my_rwnd - stcb->asoc.my_last_reported_rwnd;
3924 if (((uint32_t)incr >= (stcb->asoc.smallest_mtu * SCTP_SEG_TO_RWND_UPD)) ||
3925 ((((uint32_t)incr)*SCTP_SCALE_OF_RWND_TO_UPD) >= so->so_rcv.sb_hiwat)) {
3926 if (callout_pending(&stcb->asoc.dack_timer.timer)) {
3927 /* If the timer is up, stop it */
3928 sctp_timer_stop(SCTP_TIMER_TYPE_RECV,
3929 stcb->sctp_ep, stcb, NULL);
3931 /* Send the sack, with the new rwnd */
3932 sctp_send_sack(stcb);
3933 /* Now do the output */
3934 sctp_chunk_output(inp, stcb, 10);
3937 if ((( sq ) && (flags & MSG_EOR) && ((inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) == 0))
3938 && ((inp->sctp_flags & SCTP_PCB_FLAGS_CONNECTED) == 0)) {
3939 stcb = sctp_remove_from_socket_q(inp);
3942 SOCKBUF_LOCK(&so->so_rcv);
3943 if (( so->so_rcv.sb_mb == NULL ) &&
3944 (TAILQ_EMPTY(&inp->sctp_queue_list) == 0)) {
3947 if (sctp_debug_on & SCTP_DEBUG_USRREQ2)
3948 printf("Something off, inp:%x so->so_rcv->sb_mb is empty and sockq is not.. cleaning\n",
3951 if (((inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) == 0)
3952 && ((inp->sctp_flags & SCTP_PCB_FLAGS_CONNECTED) == 0)) {
3954 done_yet = TAILQ_EMPTY(&inp->sctp_queue_list);
3957 (void)sctp_remove_from_socket_q(inp);
3958 done_yet = TAILQ_EMPTY(&inp->sctp_queue_list);
3962 if (sctp_debug_on & SCTP_DEBUG_USRREQ2)
3963 printf("Cleaned up %d sockq's\n", sq_cnt);
3966 SOCKBUF_UNLOCK(&so->so_rcv);
3968 SCTP_TCB_UNLOCK(stcb);
3969 SCTP_INP_WUNLOCK(inp);
3975 #if (defined(__FreeBSD__) && __FreeBSD_version >= 500000) || defined(__DragonFly__)
3976 sctp_listen(struct socket *so, struct thread *p)
3978 sctp_listen(struct socket *so, struct proc *p)
3982 * Note this module depends on the protocol processing being
3983 * called AFTER any socket level flags and backlog are applied
3984 * to the socket. The traditional way that the socket flags are
3985 * applied is AFTER protocol processing. We have made a change
3986 * to the sys/kern/uipc_socket.c module to reverse this but this
3987 * MUST be in place if the socket API for SCTP is to work properly.
3990 struct sctp_inpcb *inp;
3993 inp = (struct sctp_inpcb *)so->so_pcb;
3996 /* I made the same as TCP since we are not setup? */
3997 return (ECONNRESET);
3999 SCTP_INP_RLOCK(inp);
4000 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) &&
4001 (inp->sctp_flags & SCTP_PCB_FLAGS_CONNECTED)) {
4002 /* We are already connected AND the TCP model */
4004 SCTP_INP_RUNLOCK(inp);
4005 return (EADDRINUSE);
4007 if (inp->sctp_flags & SCTP_PCB_FLAGS_UNBOUND) {
4008 /* We must do a bind. */
4009 SCTP_INP_RUNLOCK(inp);
4010 if ((error = sctp_inpcb_bind(so, NULL, p))) {
4011 /* bind error, probably perm */
4016 SCTP_INP_RUNLOCK(inp);
4019 SCTP_INP_WLOCK(inp);
4020 if (inp->sctp_socket->so_qlimit) {
4021 if (inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) {
4023 * For the UDP model we must TURN OFF the ACCEPT
4024 * flags since we do NOT allow the accept() call.
4025 * The TCP model (when present) will do accept which
4026 * then prohibits connect().
4028 inp->sctp_socket->so_options &= ~SO_ACCEPTCONN;
4030 inp->sctp_flags |= SCTP_PCB_FLAGS_ACCEPTING;
4032 if (inp->sctp_flags & SCTP_PCB_FLAGS_ACCEPTING) {
4034 * Turning off the listen flags if the backlog is
4035 * set to 0 (i.e. qlimit is 0).
4037 inp->sctp_flags &= ~SCTP_PCB_FLAGS_ACCEPTING;
4039 inp->sctp_socket->so_options &= ~SO_ACCEPTCONN;
4041 SCTP_INP_WUNLOCK(inp);
4048 #if defined(__FreeBSD__) || defined(__APPLE__) || defined(__DragonFly__)
4049 sctp_accept(struct socket *so, struct sockaddr **addr)
4052 sctp_accept(struct socket *so, struct mbuf *nam)
4054 struct sockaddr *addr = mtod(nam, struct sockaddr *);
4056 struct sctp_tcb *stcb;
4057 struct sockaddr *prim;
4058 struct sctp_inpcb *inp;
4061 inp = (struct sctp_inpcb *)so->so_pcb;
4065 return (ECONNRESET);
4067 SCTP_INP_RLOCK(inp);
4068 if (so->so_state & SS_ISDISCONNECTED) {
4070 SCTP_INP_RUNLOCK(inp);
4071 return (ECONNABORTED);
4073 stcb = LIST_FIRST(&inp->sctp_asoc_list);
4076 SCTP_INP_RUNLOCK(inp);
4077 return (ECONNRESET);
4079 SCTP_TCB_LOCK(stcb);
4080 SCTP_INP_RUNLOCK(inp);
4081 prim = (struct sockaddr *)&stcb->asoc.primary_destination->ro._l_addr;
4082 if (prim->sa_family == AF_INET) {
4083 struct sockaddr_in *sin;
4084 #if defined(__FreeBSD__) || defined(__APPLE__) || defined(__DragonFly__)
4085 MALLOC(sin, struct sockaddr_in *, sizeof *sin, M_SONAME,
4088 sin = (struct sockaddr_in *)addr;
4089 bzero((caddr_t)sin, sizeof (*sin));
4091 sin->sin_family = AF_INET;
4092 sin->sin_len = sizeof(*sin);
4093 sin->sin_port = ((struct sockaddr_in *)prim)->sin_port;
4094 sin->sin_addr = ((struct sockaddr_in *)prim)->sin_addr;
4095 #if defined(__FreeBSD__) || defined(__APPLE__) || defined(__DragonFly__)
4096 *addr = (struct sockaddr *)sin;
4098 nam->m_len = sizeof(*sin);
4101 struct sockaddr_in6 *sin6;
4102 #if defined(__FreeBSD__) || defined(__APPLE__) || defined(__DragonFly__)
4103 MALLOC(sin6, struct sockaddr_in6 *, sizeof *sin6, M_SONAME,
4106 sin6 = (struct sockaddr_in6 *)addr;
4108 bzero((caddr_t)sin6, sizeof (*sin6));
4109 sin6->sin6_family = AF_INET6;
4110 sin6->sin6_len = sizeof(*sin6);
4111 sin6->sin6_port = ((struct sockaddr_in6 *)prim)->sin6_port;
4113 sin6->sin6_addr = ((struct sockaddr_in6 *)prim)->sin6_addr;
4114 if (IN6_IS_SCOPE_LINKLOCAL(&sin6->sin6_addr))
4115 /* sin6->sin6_scope_id = ntohs(sin6->sin6_addr.s6_addr16[1]);*/
4116 in6_recoverscope(sin6, &sin6->sin6_addr, NULL); /* skip ifp check */
4118 sin6->sin6_scope_id = 0; /*XXX*/
4119 #if defined(__FreeBSD__) || defined (__APPLE__) || defined(__DragonFly__)
4120 *addr= (struct sockaddr *)sin6;
4122 nam->m_len = sizeof(*sin6);
4125 /* Wake any delayed sleep action */
4126 SCTP_TCB_UNLOCK(stcb);
4127 SCTP_INP_WLOCK(inp);
4128 if (inp->sctp_flags & SCTP_PCB_FLAGS_DONT_WAKE) {
4129 inp->sctp_flags &= ~SCTP_PCB_FLAGS_DONT_WAKE;
4130 if (inp->sctp_flags & SCTP_PCB_FLAGS_WAKEOUTPUT) {
4131 inp->sctp_flags &= ~SCTP_PCB_FLAGS_WAKEOUTPUT;
4132 #if defined(__NetBSD__)
4133 if (sowritable(inp->sctp_socket))
4134 sowwakeup(inp->sctp_socket);
4136 if (sowriteable(inp->sctp_socket))
4137 sowwakeup(inp->sctp_socket);
4140 if (inp->sctp_flags & SCTP_PCB_FLAGS_WAKEINPUT) {
4141 inp->sctp_flags &= ~SCTP_PCB_FLAGS_WAKEINPUT;
4142 if (soreadable(inp->sctp_socket))
4143 sorwakeup(inp->sctp_socket);
4147 SCTP_INP_WUNLOCK(inp);
4153 #if defined(__FreeBSD__) || defined(__APPLE__) || defined(__DragonFly__)
4154 sctp_ingetaddr(struct socket *so, struct sockaddr **addr)
4156 sctp_ingetaddr(struct socket *so, struct mbuf *nam)
4159 #if defined(__FreeBSD__) || defined(__APPLE__) || defined(__DragonFly__)
4160 struct sockaddr_in *sin;
4162 struct sockaddr_in *sin = mtod(nam, struct sockaddr_in *);
4164 struct sctp_inpcb *inp;
4166 * Do the malloc first in case it blocks.
4168 #if defined(__FreeBSD__) || defined(__APPLE__) || defined(__DragonFly__)
4169 MALLOC(sin, struct sockaddr_in *, sizeof *sin, M_SONAME, M_WAITOK |
4172 nam->m_len = sizeof(*sin);
4173 memset(sin, 0, sizeof(*sin));
4175 sin->sin_family = AF_INET;
4176 sin->sin_len = sizeof(*sin);
4178 inp = (struct sctp_inpcb *)so->so_pcb;
4181 #if defined(__FreeBSD__) || defined(__APPLE__) || defined(__DragonFly__)
4182 FREE(sin, M_SONAME);
4186 SCTP_INP_RLOCK(inp);
4187 sin->sin_port = inp->sctp_lport;
4188 if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUNDALL) {
4189 if (inp->sctp_flags & SCTP_PCB_FLAGS_CONNECTED) {
4190 struct sctp_tcb *stcb;
4191 struct sockaddr_in *sin_a;
4192 struct sctp_nets *net;
4195 stcb = LIST_FIRST(&inp->sctp_asoc_list);
4201 SCTP_TCB_LOCK(stcb);
4202 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
4203 sin_a = (struct sockaddr_in *)&net->ro._l_addr;
4204 if (sin_a->sin_family == AF_INET) {
4209 if ((!fnd) || (sin_a == NULL)) {
4211 SCTP_TCB_UNLOCK(stcb);
4214 sin->sin_addr = sctp_ipv4_source_address_selection(inp,
4215 stcb, (struct route *)&net->ro, net, 0);
4216 SCTP_TCB_UNLOCK(stcb);
4218 /* For the bound all case you get back 0 */
4220 sin->sin_addr.s_addr = 0;
4224 /* Take the first IPv4 address in the list */
4225 struct sctp_laddr *laddr;
4227 LIST_FOREACH(laddr, &inp->sctp_addr_list, sctp_nxt_addr) {
4228 if (laddr->ifa->ifa_addr->sa_family == AF_INET) {
4229 struct sockaddr_in *sin_a;
4230 sin_a = (struct sockaddr_in *)laddr->ifa->ifa_addr;
4231 sin->sin_addr = sin_a->sin_addr;
4238 #if defined(__FreeBSD__) || defined(__APPLE__) || defined(__DragonFly__)
4239 FREE(sin, M_SONAME);
4241 SCTP_INP_RUNLOCK(inp);
4245 SCTP_INP_RUNLOCK(inp);
4247 #if defined(__FreeBSD__) || defined(__APPLE__) || defined(__DragonFly__)
4248 (*addr) = (struct sockaddr *)sin;
4254 #if defined(__FreeBSD__) || defined(__APPLE__) || defined(__DragonFly__)
4255 sctp_peeraddr(struct socket *so, struct sockaddr **addr)
4257 struct sockaddr_in *sin = (struct sockaddr_in *)*addr;
4259 sctp_peeraddr(struct socket *so, struct mbuf *nam)
4261 struct sockaddr_in *sin = mtod(nam, struct sockaddr_in *);
4264 struct sockaddr_in *sin_a;
4265 struct sctp_inpcb *inp;
4266 struct sctp_tcb *stcb;
4267 struct sctp_nets *net;
4269 /* Do the malloc first in case it blocks. */
4270 inp = (struct sctp_inpcb *)so->so_pcb;
4271 if ((inp == NULL) ||
4272 ((inp->sctp_flags & SCTP_PCB_FLAGS_CONNECTED) == 0)) {
4273 /* UDP type and listeners will drop out here */
4278 #if defined(__FreeBSD__) || defined(__APPLE__) || defined(__DragonFly__)
4279 MALLOC(sin, struct sockaddr_in *, sizeof *sin, M_SONAME, M_WAITOK |
4282 nam->m_len = sizeof(*sin);
4283 memset(sin, 0, sizeof(*sin));
4285 sin->sin_family = AF_INET;
4286 sin->sin_len = sizeof(*sin);
4288 /* We must recapture incase we blocked */
4289 inp = (struct sctp_inpcb *)so->so_pcb;
4292 #if defined(__FreeBSD__) || defined(__APPLE__) || defined(__DragonFly__)
4293 FREE(sin, M_SONAME);
4297 SCTP_INP_RLOCK(inp);
4298 stcb = LIST_FIRST(&inp->sctp_asoc_list);
4300 SCTP_TCB_LOCK(stcb);
4301 SCTP_INP_RUNLOCK(inp);
4304 #if defined(__FreeBSD__) || defined(__APPLE__) || defined(__DragonFly__)
4305 FREE(sin, M_SONAME);
4310 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
4311 sin_a = (struct sockaddr_in *)&net->ro._l_addr;
4312 if (sin_a->sin_family == AF_INET) {
4314 sin->sin_port = stcb->rport;
4315 sin->sin_addr = sin_a->sin_addr;
4319 SCTP_TCB_UNLOCK(stcb);
4321 /* No IPv4 address */
4323 #if defined(__FreeBSD__) || defined(__APPLE__) || defined(__DragonFly__)
4324 FREE(sin, M_SONAME);
4332 #if defined(__FreeBSD__) || defined(__APPLE__) || defined(__DragonFly__)
4333 struct pr_usrreqs sctp_usrreqs = {
4339 pru_connect2_notsupp,
4357 #if defined(__NetBSD__)
4359 sctp_usrreq(so, req, m, nam, control, p)
4362 struct mbuf *m, *nam, *control;
4367 sctp_usrreq(so, req, m, nam, control)
4370 struct mbuf *m, *nam, *control;
4372 struct proc *p = curproc;
4377 family = so->so_proto->pr_domain->dom_family;
4380 if (req == PRU_CONTROL) {
4383 error = in_control(so, (long)m, (caddr_t)nam,
4384 (struct ifnet *)control
4385 #if defined(__NetBSD__)
4392 error = in6_control(so, (long)m, (caddr_t)nam,
4393 (struct ifnet *)control, p);
4397 error = EAFNOSUPPORT;
4403 if (req == PRU_PURGEIF) {
4406 ifn = (struct ifnet *)control;
4407 TAILQ_FOREACH(ifa, &ifn->if_addrlist, ifa_list) {
4408 if (ifa->ifa_addr->sa_family == family) {
4409 sctp_delete_ip_address(ifa);
4423 return (EAFNOSUPPORT);
4431 error = sctp_attach(so, family, p);
4434 error = sctp_detach(so);
4441 error = sctp_bind(so, nam, p);
4444 error = sctp_listen(so, p);
4451 error = sctp_connect(so, nam, p);
4453 case PRU_DISCONNECT:
4454 error = sctp_disconnect(so);
4461 error = sctp_accept(so, nam);
4464 error = sctp_shutdown(so);
4469 * For Open and Net BSD, this is real
4470 * ugly. The mbuf *nam that is passed
4471 * (by soreceive()) is the int flags c
4472 * ast as a (mbuf *) yuck!
4474 error = sctp_usr_recvd(so, (int)((long)nam));
4478 /* Flags are ignored */
4480 if (sctp_debug_on & SCTP_DEBUG_USRREQ1) {
4481 printf("Send called on V4 side\n");
4485 struct sockaddr *addr;
4489 addr = mtod(nam, struct sockaddr *);
4491 error = sctp_send(so, 0, m, addr, control, p);
4495 error = sctp_abort(so);
4502 error = EAFNOSUPPORT;
4505 error = EAFNOSUPPORT;
4508 error = sctp_peeraddr(so, nam);
4511 error = sctp_ingetaddr(so, nam);
4524 /* #if defined(__NetBSD__) || defined(__OpenBSD__) */
4527 * Sysctl for sctp variables.
4530 sctp_sysctl(name, namelen, oldp, oldlenp, newp, newlen)
4539 /* All sysctl names at this level are terminal. */
4545 case SCTPCTL_MAXDGRAM:
4546 return (sysctl_int(oldp, oldlenp, newp, newlen,
4548 case SCTPCTL_RECVSPACE:
4549 return (sysctl_int(oldp, oldlenp, newp, newlen,
4551 case SCTPCTL_AUTOASCONF:
4552 return (sysctl_int(oldp, oldlenp, newp, newlen,
4553 &sctp_auto_asconf));
4554 case SCTPCTL_ECN_ENABLE:
4555 return (sysctl_int(oldp, oldlenp, newp, newlen,
4557 case SCTPCTL_ECN_NONCE:
4558 return (sysctl_int(oldp, oldlenp, newp, newlen,
4560 case SCTPCTL_STRICT_SACK:
4561 return (sysctl_int(oldp, oldlenp, newp, newlen,
4562 &sctp_strict_sacks));
4563 case SCTPCTL_NOCSUM_LO:
4564 return (sysctl_int(oldp, oldlenp, newp, newlen,
4565 &sctp_no_csum_on_loopback));
4566 case SCTPCTL_STRICT_INIT:
4567 return (sysctl_int(oldp, oldlenp, newp, newlen,
4568 &sctp_strict_init));
4569 case SCTPCTL_PEER_CHK_OH:
4570 return (sysctl_int(oldp, oldlenp, newp, newlen,
4571 &sctp_peer_chunk_oh));
4572 case SCTPCTL_MAXBURST:
4573 return (sysctl_int(oldp, oldlenp, newp, newlen,
4574 &sctp_max_burst_default));
4575 case SCTPCTL_MAXCHUNKONQ:
4576 return (sysctl_int(oldp, oldlenp, newp, newlen,
4577 &sctp_max_chunks_on_queue));
4578 case SCTPCTL_DELAYED_SACK:
4579 return (sysctl_int(oldp, oldlenp, newp, newlen,
4580 &sctp_delayed_sack_time_default));
4581 case SCTPCTL_HB_INTERVAL:
4582 return (sysctl_int(oldp, oldlenp, newp, newlen,
4583 &sctp_heartbeat_interval_default));
4584 case SCTPCTL_PMTU_RAISE:
4585 return (sysctl_int(oldp, oldlenp, newp, newlen,
4586 &sctp_pmtu_raise_time_default));
4587 case SCTPCTL_SHUTDOWN_GUARD:
4588 return (sysctl_int(oldp, oldlenp, newp, newlen,
4589 &sctp_shutdown_guard_time_default));
4590 case SCTPCTL_SECRET_LIFETIME:
4591 return (sysctl_int(oldp, oldlenp, newp, newlen,
4592 &sctp_secret_lifetime_default));
4593 case SCTPCTL_RTO_MAX:
4594 return (sysctl_int(oldp, oldlenp, newp, newlen,
4595 &sctp_rto_max_default));
4596 case SCTPCTL_RTO_MIN:
4597 return (sysctl_int(oldp, oldlenp, newp, newlen,
4598 &sctp_rto_min_default));
4599 case SCTPCTL_RTO_INITIAL:
4600 return (sysctl_int(oldp, oldlenp, newp, newlen,
4601 &sctp_rto_initial_default));
4602 case SCTPCTL_INIT_RTO_MAX:
4603 return (sysctl_int(oldp, oldlenp, newp, newlen,
4604 &sctp_init_rto_max_default));
4605 case SCTPCTL_COOKIE_LIFE:
4606 return (sysctl_int(oldp, oldlenp, newp, newlen,
4607 &sctp_valid_cookie_life_default));
4608 case SCTPCTL_INIT_RTX_MAX:
4609 return (sysctl_int(oldp, oldlenp, newp, newlen,
4610 &sctp_init_rtx_max_default));
4611 case SCTPCTL_ASSOC_RTX_MAX:
4612 return (sysctl_int(oldp, oldlenp, newp, newlen,
4613 &sctp_assoc_rtx_max_default));
4614 case SCTPCTL_PATH_RTX_MAX:
4615 return (sysctl_int(oldp, oldlenp, newp, newlen,
4616 &sctp_path_rtx_max_default));
4617 case SCTPCTL_NR_OUTGOING_STREAMS:
4618 return (sysctl_int(oldp, oldlenp, newp, newlen,
4619 &sctp_nr_outgoing_streams_default));
4622 return (sysctl_int(oldp, oldlenp, newp, newlen,
4626 return (ENOPROTOOPT);
4633 * Sysctl for sctp variables.
4635 SYSCTL_SETUP(sysctl_net_inet_sctp_setup, "sysctl net.inet.sctp subtree setup")
4638 sysctl_createv(clog, 0, NULL, NULL,
4640 CTLTYPE_NODE, "net", NULL,
4643 sysctl_createv(clog, 0, NULL, NULL,
4645 CTLTYPE_NODE, "inet", NULL,
4647 CTL_NET, PF_INET, CTL_EOL);
4648 sysctl_createv(clog, 0, NULL, NULL,
4650 CTLTYPE_NODE, "sctp",
4651 SYSCTL_DESCR("sctp related settings"),
4653 CTL_NET, PF_INET, IPPROTO_SCTP, CTL_EOL);
4655 sysctl_createv(clog, 0, NULL, NULL,
4656 CTLFLAG_PERMANENT|CTLFLAG_READWRITE,
4657 CTLTYPE_INT, "maxdgram",
4658 SYSCTL_DESCR("Maximum outgoing SCTP buffer size"),
4659 NULL, 0, &sctp_sendspace, 0,
4660 CTL_NET, PF_INET, IPPROTO_SCTP, SCTPCTL_MAXDGRAM,
4663 sysctl_createv(clog, 0, NULL, NULL,
4664 CTLFLAG_PERMANENT|CTLFLAG_READWRITE,
4665 CTLTYPE_INT, "recvspace",
4666 SYSCTL_DESCR("Maximum incoming SCTP buffer size"),
4667 NULL, 0, &sctp_recvspace, 0,
4668 CTL_NET, PF_INET, IPPROTO_SCTP, SCTPCTL_RECVSPACE,
4671 sysctl_createv(clog, 0, NULL, NULL,
4672 CTLFLAG_PERMANENT|CTLFLAG_READWRITE,
4673 CTLTYPE_INT, "autoasconf",
4674 SYSCTL_DESCR("Enable SCTP Auto-ASCONF"),
4675 NULL, 0, &sctp_auto_asconf, 0,
4676 CTL_NET, PF_INET, IPPROTO_SCTP, SCTPCTL_AUTOASCONF,
4679 sysctl_createv(clog, 0, NULL, NULL,
4680 CTLFLAG_PERMANENT|CTLFLAG_READWRITE,
4681 CTLTYPE_INT, "ecn_enable",
4682 SYSCTL_DESCR("Enable SCTP ECN"),
4683 NULL, 0, &sctp_ecn, 0,
4684 CTL_NET, PF_INET, IPPROTO_SCTP, SCTPCTL_ECN_ENABLE,
4687 sysctl_createv(clog, 0, NULL, NULL,
4688 CTLFLAG_PERMANENT|CTLFLAG_READWRITE,
4689 CTLTYPE_INT, "ecn_nonce",
4690 SYSCTL_DESCR("Enable SCTP ECN Nonce"),
4691 NULL, 0, &sctp_ecn_nonce, 0,
4692 CTL_NET, PF_INET, IPPROTO_SCTP, SCTPCTL_ECN_NONCE,
4695 sysctl_createv(clog, 0, NULL, NULL,
4696 CTLFLAG_PERMANENT|CTLFLAG_READWRITE,
4697 CTLTYPE_INT, "strict_sack",
4698 SYSCTL_DESCR("Enable SCTP Strict SACK checking"),
4699 NULL, 0, &sctp_strict_sacks, 0,
4700 CTL_NET, PF_INET, IPPROTO_SCTP, SCTPCTL_STRICT_SACK,
4703 sysctl_createv(clog, 0, NULL, NULL,
4704 CTLFLAG_PERMANENT|CTLFLAG_READWRITE,
4705 CTLTYPE_INT, "loopback_nocsum",
4706 SYSCTL_DESCR("Enable NO Csum on packets sent on loopback"),
4707 NULL, 0, &sctp_no_csum_on_loopback, 0,
4708 CTL_NET, PF_INET, IPPROTO_SCTP, SCTPCTL_NOCSUM_LO,
4711 sysctl_createv(clog, 0, NULL, NULL,
4712 CTLFLAG_PERMANENT|CTLFLAG_READWRITE,
4713 CTLTYPE_INT, "strict_init",
4714 SYSCTL_DESCR("Enable strict INIT/INIT-ACK singleton enforcement"),
4715 NULL, 0, &sctp_strict_init, 0,
4716 CTL_NET, PF_INET, IPPROTO_SCTP, SCTPCTL_STRICT_INIT,
4719 sysctl_createv(clog, 0, NULL, NULL,
4720 CTLFLAG_PERMANENT|CTLFLAG_READWRITE,
4721 CTLTYPE_INT, "peer_chkoh",
4722 SYSCTL_DESCR("Amount to debit peers rwnd per chunk sent"),
4723 NULL, 0, &sctp_peer_chunk_oh, 0,
4724 CTL_NET, PF_INET, IPPROTO_SCTP, SCTPCTL_PEER_CHK_OH,
4727 sysctl_createv(clog, 0, NULL, NULL,
4728 CTLFLAG_PERMANENT|CTLFLAG_READWRITE,
4729 CTLTYPE_INT, "maxburst",
4730 SYSCTL_DESCR("Default max burst for sctp endpoints"),
4731 NULL, 0, &sctp_max_burst_default, 0,
4732 CTL_NET, PF_INET, IPPROTO_SCTP, SCTPCTL_MAXBURST,
4735 sysctl_createv(clog, 0, NULL, NULL,
4736 CTLFLAG_PERMANENT|CTLFLAG_READWRITE,
4737 CTLTYPE_INT, "maxchunks",
4738 SYSCTL_DESCR("Default max chunks on queue per asoc"),
4739 NULL, 0, &sctp_max_chunks_on_queue, 0,
4740 CTL_NET, PF_INET, IPPROTO_SCTP, SCTPCTL_MAXCHUNKONQ,