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.8 2006/06/23 17:20:14 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 <netproto/key/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(int cmd, struct sockaddr *sa, void *vip)
460 if (sa->sa_family != AF_INET ||
461 ((struct sockaddr_in *)sa)->sin_addr.s_addr == INADDR_ANY) {
462 #if defined(__FreeBSD__) || defined(__APPLE__) || defined(__DragonFly__)
469 if (PRC_IS_REDIRECT(cmd)) {
471 } else if ((unsigned)cmd >= PRC_NCMDS || inetctlerrmap[cmd] == 0) {
472 #if defined(__FreeBSD__) || defined(__APPLE__) || defined(__DragonFly__)
479 struct sctp_inpcb *inp;
480 struct sctp_tcb *stcb;
481 struct sctp_nets *net;
482 struct sockaddr_in to, from;
484 sh = (struct sctphdr *)((caddr_t)ip + (ip->ip_hl << 2));
485 bzero(&to, sizeof(to));
486 bzero(&from, sizeof(from));
487 from.sin_family = to.sin_family = AF_INET;
488 from.sin_len = to.sin_len = sizeof(to);
489 from.sin_port = sh->src_port;
490 from.sin_addr = ip->ip_src;
491 to.sin_port = sh->dest_port;
492 to.sin_addr = ip->ip_dst;
495 * 'to' holds the dest of the packet that failed to be sent.
496 * 'from' holds our local endpoint address.
497 * Thus we reverse the to and the from in the lookup.
500 stcb = sctp_findassociation_addr_sa((struct sockaddr *)&from,
501 (struct sockaddr *)&to,
503 if (stcb != NULL && inp && (inp->sctp_socket != NULL)) {
504 if (cmd != PRC_MSGSIZE) {
506 if (cmd == PRC_HOSTDEAD) {
509 cm = inetctlerrmap[cmd];
511 sctp_notify(inp, cm, sh,
512 (struct sockaddr *)&to, stcb,
515 /* handle possible ICMP size messages */
516 sctp_notify_mbuf(inp, stcb, net, ip, sh);
519 #if (defined(__FreeBSD__) && __FreeBSD_version < 500000) || defined(__DragonFly__)
520 /* XXX must be fixed for 5.x and higher, leave for 4.x */
521 if (PRC_IS_REDIRECT(cmd) && inp) {
522 in_rtchange((struct inpcb *)inp,
526 if ((stcb == NULL) && (inp != NULL)) {
527 /* reduce ref-count */
529 SCTP_INP_DECR_REF(inp);
530 SCTP_INP_WUNLOCK(inp);
536 #if defined(__FreeBSD__) || defined(__APPLE__) || defined(__DragonFly__)
543 #if defined(__FreeBSD__) || defined(__DragonFly__)
545 sctp_getcred(SYSCTL_HANDLER_ARGS)
547 struct sockaddr_in addrs[2];
548 struct sctp_inpcb *inp;
549 struct sctp_nets *net;
550 struct sctp_tcb *stcb;
553 #if __FreeBSD_version >= 500000 || defined(__DragonFly__)
554 error = suser(req->td);
556 error = suser(req->p);
560 error = SYSCTL_IN(req, addrs, sizeof(addrs));
565 stcb = sctp_findassociation_addr_sa(sintosa(&addrs[0]),
568 if (stcb == NULL || inp == NULL || inp->sctp_socket == NULL) {
569 if ((inp != NULL) && (stcb == NULL)) {
570 /* reduce ref-count */
572 SCTP_INP_DECR_REF(inp);
573 SCTP_INP_WUNLOCK(inp);
578 error = SYSCTL_OUT(req, inp->sctp_socket->so_cred, sizeof(struct ucred));
579 SCTP_TCB_UNLOCK(stcb);
585 SYSCTL_PROC(_net_inet_sctp, OID_AUTO, getcred, CTLTYPE_OPAQUE|CTLFLAG_RW,
586 0, 0, sctp_getcred, "S,ucred", "Get the ucred of a SCTP connection");
587 #endif /* #if defined(__FreeBSD__) || defined(__DragonFly__) */
592 #if defined(__FreeBSD__) || defined (__APPLE__) || defined(__DragonFly__)
594 SYSCTL_DECL(_net_inet);
596 SYSCTL_NODE(_net_inet, OID_AUTO, sctp, CTLFLAG_RD, 0,
599 SYSCTL_INT(_net_inet_sctp, OID_AUTO, maxdgram, CTLFLAG_RW,
600 &sctp_sendspace, 0, "Maximum outgoing SCTP buffer size");
602 SYSCTL_INT(_net_inet_sctp, OID_AUTO, recvspace, CTLFLAG_RW,
603 &sctp_recvspace, 0, "Maximum incoming SCTP buffer size");
605 SYSCTL_INT(_net_inet_sctp, OID_AUTO, auto_asconf, CTLFLAG_RW,
606 &sctp_auto_asconf, 0, "Enable SCTP Auto-ASCONF");
608 SYSCTL_INT(_net_inet_sctp, OID_AUTO, ecn_enable, CTLFLAG_RW,
609 &sctp_ecn, 0, "Enable SCTP ECN");
611 SYSCTL_INT(_net_inet_sctp, OID_AUTO, ecn_nonce, CTLFLAG_RW,
612 &sctp_ecn_nonce, 0, "Enable SCTP ECN Nonce");
614 SYSCTL_INT(_net_inet_sctp, OID_AUTO, strict_sacks, CTLFLAG_RW,
615 &sctp_strict_sacks, 0, "Enable SCTP Strict SACK checking");
617 SYSCTL_INT(_net_inet_sctp, OID_AUTO, loopback_nocsum, CTLFLAG_RW,
618 &sctp_no_csum_on_loopback, 0,
619 "Enable NO Csum on packets sent on loopback");
621 SYSCTL_INT(_net_inet_sctp, OID_AUTO, strict_init, CTLFLAG_RW,
622 &sctp_strict_init, 0,
623 "Enable strict INIT/INIT-ACK singleton enforcement");
625 SYSCTL_INT(_net_inet_sctp, OID_AUTO, peer_chkoh, CTLFLAG_RW,
626 &sctp_peer_chunk_oh, 0,
627 "Amount to debit peers rwnd per chunk sent");
629 SYSCTL_INT(_net_inet_sctp, OID_AUTO, maxburst, CTLFLAG_RW,
630 &sctp_max_burst_default, 0,
631 "Default max burst for sctp endpoints");
633 SYSCTL_INT(_net_inet_sctp, OID_AUTO, maxchunks, CTLFLAG_RW,
634 &sctp_max_chunks_on_queue, 0,
635 "Default max chunks on queue per asoc");
637 SYSCTL_UINT(_net_inet_sctp, OID_AUTO, delayed_sack_time, CTLFLAG_RW,
638 &sctp_delayed_sack_time_default, 0,
639 "Default delayed SACK timer in msec");
641 SYSCTL_UINT(_net_inet_sctp, OID_AUTO, heartbeat_interval, CTLFLAG_RW,
642 &sctp_heartbeat_interval_default, 0,
643 "Default heartbeat interval in msec");
645 SYSCTL_UINT(_net_inet_sctp, OID_AUTO, pmtu_raise_time, CTLFLAG_RW,
646 &sctp_pmtu_raise_time_default, 0,
647 "Default PMTU raise timer in sec");
649 SYSCTL_UINT(_net_inet_sctp, OID_AUTO, shutdown_guard_time, CTLFLAG_RW,
650 &sctp_shutdown_guard_time_default, 0,
651 "Default shutdown guard timer in sec");
653 SYSCTL_UINT(_net_inet_sctp, OID_AUTO, secret_lifetime, CTLFLAG_RW,
654 &sctp_secret_lifetime_default, 0,
655 "Default secret lifetime in sec");
657 SYSCTL_UINT(_net_inet_sctp, OID_AUTO, rto_max, CTLFLAG_RW,
658 &sctp_rto_max_default, 0,
659 "Default maximum retransmission timeout in msec");
661 SYSCTL_UINT(_net_inet_sctp, OID_AUTO, rto_min, CTLFLAG_RW,
662 &sctp_rto_min_default, 0,
663 "Default minimum retransmission timeout in msec");
665 SYSCTL_UINT(_net_inet_sctp, OID_AUTO, rto_initial, CTLFLAG_RW,
666 &sctp_rto_initial_default, 0,
667 "Default initial retransmission timeout in msec");
669 SYSCTL_UINT(_net_inet_sctp, OID_AUTO, init_rto_max, CTLFLAG_RW,
670 &sctp_init_rto_max_default, 0,
671 "Default maximum retransmission timeout during association setup in msec");
673 SYSCTL_UINT(_net_inet_sctp, OID_AUTO, valid_cookie_life, CTLFLAG_RW,
674 &sctp_valid_cookie_life_default, 0,
675 "Default cookie lifetime in sec");
677 SYSCTL_UINT(_net_inet_sctp, OID_AUTO, init_rtx_max, CTLFLAG_RW,
678 &sctp_init_rtx_max_default, 0,
679 "Default maximum number of retransmission for INIT chunks");
681 SYSCTL_UINT(_net_inet_sctp, OID_AUTO, assoc_rtx_max, CTLFLAG_RW,
682 &sctp_assoc_rtx_max_default, 0,
683 "Default maximum number of retransmissions per association");
685 SYSCTL_UINT(_net_inet_sctp, OID_AUTO, path_rtx_max, CTLFLAG_RW,
686 &sctp_path_rtx_max_default, 0,
687 "Default maximum of retransmissions per path");
689 SYSCTL_UINT(_net_inet_sctp, OID_AUTO, nr_outgoing_streams, CTLFLAG_RW,
690 &sctp_nr_outgoing_streams_default, 0,
691 "Default number of outgoing streams");
694 SYSCTL_INT(_net_inet_sctp, OID_AUTO, debug, CTLFLAG_RW,
695 &sctp_debug_on, 0, "Configure debug output");
696 #endif /* SCTP_DEBUG */
700 sctp_abort(struct socket *so)
702 struct sctp_inpcb *inp;
704 inp = (struct sctp_inpcb *)so->so_pcb;
706 return EINVAL; /* ??? possible? panic instead? */
709 sctp_inpcb_free(inp, 1);
715 #if defined(__FreeBSD__) && __FreeBSD_version >= 500000
716 sctp_attach(struct socket *so, int proto, struct thread *p)
717 #elif defined(__DragonFly__)
718 sctp_attach(struct socket *so, int proto, struct pru_attach_info *ai)
720 sctp_attach(struct socket *so, int proto, struct proc *p)
723 struct sctp_inpcb *inp;
724 struct inpcb *ip_inp;
728 inp = (struct sctp_inpcb *)so->so_pcb;
733 error = soreserve(so, sctp_sendspace, sctp_recvspace, NULL);
738 error = sctp_inpcb_alloc(so);
743 inp = (struct sctp_inpcb *)so->so_pcb;
746 inp->sctp_flags &= ~SCTP_PCB_FLAGS_BOUND_V6; /* I'm not v6! */
747 ip_inp = &inp->ip_inp.inp;
748 #if defined(__FreeBSD__) || defined(__APPLE__) || defined(__DragonFly__)
749 ip_inp->inp_vflag |= INP_IPV4;
750 ip_inp->inp_ip_ttl = ip_defttl;
752 inp->inp_vflag |= INP_IPV4;
753 inp->inp_ip_ttl = ip_defttl;
757 #if !(defined(__OpenBSD__) || defined(__APPLE__))
758 error = ipsec_init_policy(so, &ip_inp->inp_sp);
760 sctp_inpcb_free(inp, 1);
765 SCTP_INP_WUNLOCK(inp);
766 #if defined(__NetBSD__)
767 so->so_send = sctp_sosend;
774 #if (defined(__FreeBSD__) && __FreeBSD_version >= 500000) || defined(__DragonFly__)
775 sctp_bind(struct socket *so, struct sockaddr *addr, struct thread *p)
777 #elif defined(__FreeBSD__) || defined(__APPLE__)
778 sctp_bind(struct socket *so, struct sockaddr *addr, struct proc *p)
781 sctp_bind(struct socket *so, struct mbuf *nam, struct proc *p)
783 struct sockaddr *addr = nam ? mtod(nam, struct sockaddr *) : NULL;
785 struct sctp_inpcb *inp;
789 if (addr && addr->sa_family != AF_INET)
790 /* must be a v4 address! */
794 inp = (struct sctp_inpcb *)so->so_pcb;
799 error = sctp_inpcb_bind(so, addr, p);
806 sctp_detach(struct socket *so)
808 struct sctp_inpcb *inp;
810 inp = (struct sctp_inpcb *)so->so_pcb;
814 if (((so->so_options & SO_LINGER) && (so->so_linger == 0)) ||
815 (so->so_rcv.sb_cc > 0)) {
816 sctp_inpcb_free(inp, 1);
818 sctp_inpcb_free(inp, 0);
825 #if (defined(__FreeBSD__) && __FreeBSD_version >= 500000) || defined(__DragonFly__)
826 sctp_send(struct socket *so, int flags, struct mbuf *m, struct sockaddr *addr,
827 struct mbuf *control, struct thread *p);
829 sctp_send(struct socket *so, int flags, struct mbuf *m, struct sockaddr *addr,
830 struct mbuf *control, struct proc *p);
834 #if (defined(__FreeBSD__) && __FreeBSD_version >= 500000) || defined(__DragonFly__)
835 sctp_send(struct socket *so, int flags, struct mbuf *m, struct sockaddr *addr,
836 struct mbuf *control, struct thread *p)
839 sctp_send(struct socket *so, int flags, struct mbuf *m, struct sockaddr *addr,
840 struct mbuf *control, struct proc *p)
843 struct sctp_inpcb *inp;
845 inp = (struct sctp_inpcb *)so->so_pcb;
848 sctp_m_freem(control);
854 /* Got to have an to address if we are NOT a connected socket */
855 if ((addr == NULL) &&
856 ((inp->sctp_flags & SCTP_PCB_FLAGS_CONNECTED) ||
857 (inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE))
860 } else if (addr == NULL) {
861 error = EDESTADDRREQ;
864 sctp_m_freem(control);
870 if (addr->sa_family != AF_INET) {
871 /* must be a v4 address! */
874 sctp_m_freem(control);
877 error = EDESTADDRREQ;
882 /* now what about control */
885 printf("huh? control set?\n");
886 sctp_m_freem(inp->control);
889 inp->control = control;
891 /* add it in possibly */
892 if ((inp->pkt) && (inp->pkt->m_flags & M_PKTHDR)) {
898 for (x=m;x;x = x->m_next) {
901 inp->pkt->m_pkthdr.len += c_len;
905 inp->pkt_last->m_next = m;
908 inp->pkt_last = inp->pkt = m;
911 #if defined (__FreeBSD__) || defined(__APPLE__) || defined(__DragonFly__)
912 /* FreeBSD uses a flag passed */
913 ((flags & PRUS_MORETOCOME) == 0)
914 #elif defined( __NetBSD__)
915 /* NetBSD uses the so_state field */
916 ((so->so_state & SS_MORETOCOME) == 0)
918 1 /* Open BSD does not have any "more to come" indication */
922 * note with the current version this code will only be used
923 * by OpenBSD-- NetBSD, FreeBSD, and MacOS have methods for
924 * re-defining sosend to use the sctp_sosend. One can
925 * optionally switch back to this code (by changing back the
926 * definitions) but this is not advisable.
929 ret = sctp_output(inp, inp->pkt, addr, inp->control, p, flags);
939 sctp_disconnect(struct socket *so)
941 struct sctp_inpcb *inp;
944 inp = (struct sctp_inpcb *)so->so_pcb;
950 if (inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) {
951 if (LIST_EMPTY(&inp->sctp_asoc_list)) {
954 SCTP_INP_RUNLOCK(inp);
957 int some_on_streamwheel = 0;
958 struct sctp_association *asoc;
959 struct sctp_tcb *stcb;
961 stcb = LIST_FIRST(&inp->sctp_asoc_list);
964 SCTP_INP_RUNLOCK(inp);
969 if (((so->so_options & SO_LINGER) &&
970 (so->so_linger == 0)) ||
971 (so->so_rcv.sb_cc > 0)) {
972 if (SCTP_GET_STATE(asoc) !=
973 SCTP_STATE_COOKIE_WAIT) {
974 /* Left with Data unread */
977 MGET(err, MB_DONTWAIT, MT_DATA);
979 /* Fill in the user initiated abort */
980 struct sctp_paramhdr *ph;
981 ph = mtod(err, struct sctp_paramhdr *);
982 err->m_len = sizeof(struct sctp_paramhdr);
983 ph->param_type = htons(SCTP_CAUSE_USER_INITIATED_ABT);
984 ph->param_length = htons(err->m_len);
986 sctp_send_abort_tcb(stcb, err);
988 SCTP_INP_RUNLOCK(inp);
989 sctp_free_assoc(inp, stcb);
990 /* No unlock tcb assoc is gone */
994 if (!TAILQ_EMPTY(&asoc->out_wheel)) {
995 /* Check to see if some data queued */
996 struct sctp_stream_out *outs;
997 TAILQ_FOREACH(outs, &asoc->out_wheel,
999 if (!TAILQ_EMPTY(&outs->outqueue)) {
1000 some_on_streamwheel = 1;
1006 if (TAILQ_EMPTY(&asoc->send_queue) &&
1007 TAILQ_EMPTY(&asoc->sent_queue) &&
1008 (some_on_streamwheel == 0)) {
1009 /* there is nothing queued to send, so done */
1010 if ((SCTP_GET_STATE(asoc) !=
1011 SCTP_STATE_SHUTDOWN_SENT) &&
1012 (SCTP_GET_STATE(asoc) !=
1013 SCTP_STATE_SHUTDOWN_ACK_SENT)) {
1014 /* only send SHUTDOWN 1st time thru */
1016 if (sctp_debug_on & SCTP_DEBUG_OUTPUT4) {
1017 printf("%s:%d sends a shutdown\n",
1023 sctp_send_shutdown(stcb,
1024 stcb->asoc.primary_destination);
1025 sctp_chunk_output(stcb->sctp_ep, stcb, 1);
1026 asoc->state = SCTP_STATE_SHUTDOWN_SENT;
1027 sctp_timer_start(SCTP_TIMER_TYPE_SHUTDOWN,
1028 stcb->sctp_ep, stcb,
1029 asoc->primary_destination);
1030 sctp_timer_start(SCTP_TIMER_TYPE_SHUTDOWNGUARD,
1031 stcb->sctp_ep, stcb,
1032 asoc->primary_destination);
1036 * we still got (or just got) data to send,
1037 * so set SHUTDOWN_PENDING
1040 * XXX sockets draft says that MSG_EOF should
1041 * be sent with no data.
1042 * currently, we will allow user data to be
1043 * sent first and move to SHUTDOWN-PENDING
1045 asoc->state |= SCTP_STATE_SHUTDOWN_PENDING;
1047 SCTP_TCB_UNLOCK(stcb);
1048 SCTP_INP_RUNLOCK(inp);
1054 /* UDP model does not support this */
1055 SCTP_INP_RUNLOCK(inp);
1062 sctp_shutdown(struct socket *so)
1064 struct sctp_inpcb *inp;
1067 inp = (struct sctp_inpcb *)so->so_pcb;
1072 SCTP_INP_RLOCK(inp);
1073 /* For UDP model this is a invalid call */
1074 if (inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) {
1075 /* Restore the flags that the soshutdown took away. */
1076 #if defined(__FreeBSD__) && __FreeBSD_version >= 502115
1077 so->so_rcv.sb_state &= ~SBS_CANTRCVMORE;
1079 so->so_state &= ~SS_CANTRCVMORE;
1081 /* This proc will wakeup for read and do nothing (I hope) */
1083 SCTP_INP_RUNLOCK(inp);
1084 return (EOPNOTSUPP);
1087 * Ok if we reach here its the TCP model and it is either a SHUT_WR
1088 * or SHUT_RDWR. This means we put the shutdown flag against it.
1091 int some_on_streamwheel = 0;
1092 struct sctp_tcb *stcb;
1093 struct sctp_association *asoc;
1096 stcb = LIST_FIRST(&inp->sctp_asoc_list);
1099 * Ok we hit the case that the shutdown call was made
1100 * after an abort or something. Nothing to do now.
1105 SCTP_TCB_LOCK(stcb);
1108 if (!TAILQ_EMPTY(&asoc->out_wheel)) {
1109 /* Check to see if some data queued */
1110 struct sctp_stream_out *outs;
1111 TAILQ_FOREACH(outs, &asoc->out_wheel, next_spoke) {
1112 if (!TAILQ_EMPTY(&outs->outqueue)) {
1113 some_on_streamwheel = 1;
1118 if (TAILQ_EMPTY(&asoc->send_queue) &&
1119 TAILQ_EMPTY(&asoc->sent_queue) &&
1120 (some_on_streamwheel == 0)) {
1121 /* there is nothing queued to send, so I'm done... */
1122 if (SCTP_GET_STATE(asoc) != SCTP_STATE_SHUTDOWN_SENT) {
1123 /* only send SHUTDOWN the first time through */
1125 if (sctp_debug_on & SCTP_DEBUG_OUTPUT4) {
1126 printf("%s:%d sends a shutdown\n",
1132 sctp_send_shutdown(stcb,
1133 stcb->asoc.primary_destination);
1134 sctp_chunk_output(stcb->sctp_ep, stcb, 1);
1135 asoc->state = SCTP_STATE_SHUTDOWN_SENT;
1136 sctp_timer_start(SCTP_TIMER_TYPE_SHUTDOWN,
1137 stcb->sctp_ep, stcb,
1138 asoc->primary_destination);
1139 sctp_timer_start(SCTP_TIMER_TYPE_SHUTDOWNGUARD,
1140 stcb->sctp_ep, stcb,
1141 asoc->primary_destination);
1145 * we still got (or just got) data to send, so
1146 * set SHUTDOWN_PENDING
1148 asoc->state |= SCTP_STATE_SHUTDOWN_PENDING;
1150 SCTP_TCB_UNLOCK(stcb);
1152 SCTP_INP_RUNLOCK(inp);
1158 * copies a "user" presentable address and removes embedded scope, etc.
1159 * returns 0 on success, 1 on error
1162 sctp_fill_user_address(struct sockaddr_storage *ss, struct sockaddr *sa)
1164 struct sockaddr_in6 lsa6;
1165 sa = (struct sockaddr *)sctp_recover_scope((struct sockaddr_in6 *)sa,
1167 memcpy(ss, sa, sa->sa_len);
1172 #if defined(__NetBSD__) || defined(__OpenBSD__)
1174 * On NetBSD and OpenBSD in6_sin_2_v4mapsin6() not used and not exported,
1175 * so we have to export it here.
1177 void in6_sin_2_v4mapsin6(struct sockaddr_in *sin, struct sockaddr_in6 *sin6);
1181 sctp_fill_up_addresses(struct sctp_inpcb *inp,
1182 struct sctp_tcb *stcb,
1184 struct sockaddr_storage *sas)
1188 int loopback_scope, ipv4_local_scope, local_scope, site_scope, actual;
1189 int ipv4_addr_legal, ipv6_addr_legal;
1195 /* Turn on all the appropriate scope */
1196 loopback_scope = stcb->asoc.loopback_scope;
1197 ipv4_local_scope = stcb->asoc.ipv4_local_scope;
1198 local_scope = stcb->asoc.local_scope;
1199 site_scope = stcb->asoc.site_scope;
1201 /* Turn on ALL scope, since we look at the EP */
1202 loopback_scope = ipv4_local_scope = local_scope =
1205 ipv4_addr_legal = ipv6_addr_legal = 0;
1206 if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) {
1207 ipv6_addr_legal = 1;
1209 #if defined(__OpenBSD__)
1210 (0) /* we always do dual bind */
1211 #elif defined (__NetBSD__)
1212 (((struct in6pcb *)inp)->in6p_flags & IN6P_IPV6_V6ONLY)
1214 (((struct in6pcb *)inp)->inp_flags & IN6P_IPV6_V6ONLY)
1217 ipv4_addr_legal = 1;
1220 ipv4_addr_legal = 1;
1223 if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUNDALL) {
1224 TAILQ_FOREACH(ifn, &ifnet, if_list) {
1225 if ((loopback_scope == 0) &&
1226 (ifn->if_type == IFT_LOOP)) {
1227 /* Skip loopback if loopback_scope not set */
1230 TAILQ_FOREACH(ifa, &ifn->if_addrlist, ifa_list) {
1233 * For the BOUND-ALL case, the list
1234 * associated with a TCB is Always
1235 * considered a reverse list.. i.e.
1236 * it lists addresses that are NOT
1237 * part of the association. If this
1238 * is one of those we must skip it.
1240 if (sctp_is_addr_restricted(stcb,
1245 if ((ifa->ifa_addr->sa_family == AF_INET) &&
1246 (ipv4_addr_legal)) {
1247 struct sockaddr_in *sin;
1248 sin = (struct sockaddr_in *)ifa->ifa_addr;
1249 if (sin->sin_addr.s_addr == 0) {
1250 /* we skip unspecifed addresses */
1253 if ((ipv4_local_scope == 0) &&
1254 (IN4_ISPRIVATE_ADDRESS(&sin->sin_addr))) {
1257 if (inp->sctp_flags & SCTP_PCB_FLAGS_NEEDS_MAPPED_V4) {
1258 in6_sin_2_v4mapsin6(sin, (struct sockaddr_in6 *)sas);
1259 ((struct sockaddr_in6 *)sas)->sin6_port = inp->sctp_lport;
1260 sas = (struct sockaddr_storage *)((caddr_t)sas + sizeof(struct sockaddr_in6));
1261 actual += sizeof(sizeof(struct sockaddr_in6));
1263 memcpy(sas, sin, sizeof(*sin));
1264 ((struct sockaddr_in *)sas)->sin_port = inp->sctp_lport;
1265 sas = (struct sockaddr_storage *)((caddr_t)sas + sizeof(*sin));
1266 actual += sizeof(*sin);
1268 if (actual >= limit) {
1271 } else if ((ifa->ifa_addr->sa_family == AF_INET6) &&
1272 (ipv6_addr_legal)) {
1273 struct sockaddr_in6 *sin6, lsa6;
1274 sin6 = (struct sockaddr_in6 *)ifa->ifa_addr;
1275 if (IN6_IS_ADDR_UNSPECIFIED(&sin6->sin6_addr)) {
1276 /* we skip unspecifed addresses */
1279 if (IN6_IS_ADDR_LINKLOCAL(&sin6->sin6_addr)) {
1280 if (local_scope == 0)
1282 if (sin6->sin6_scope_id == 0) {
1284 if (in6_recoverscope(&lsa6,
1287 /* bad link local address */
1292 if ((site_scope == 0) &&
1293 (IN6_IS_ADDR_SITELOCAL(&sin6->sin6_addr))) {
1296 memcpy(sas, sin6, sizeof(*sin6));
1297 ((struct sockaddr_in6 *)sas)->sin6_port = inp->sctp_lport;
1298 sas = (struct sockaddr_storage *)((caddr_t)sas + sizeof(*sin6));
1299 actual += sizeof(*sin6);
1300 if (actual >= limit) {
1307 struct sctp_laddr *laddr;
1309 * If we have a TCB and we do NOT support ASCONF (it's
1310 * turned off or otherwise) then the list is always the
1311 * true list of addresses (the else case below). Otherwise
1312 * the list on the association is a list of addresses that
1313 * are NOT part of the association.
1315 if (inp->sctp_flags & SCTP_PCB_FLAGS_DO_ASCONF) {
1316 /* The list is a NEGATIVE list */
1317 LIST_FOREACH(laddr, &inp->sctp_addr_list, sctp_nxt_addr) {
1319 if (sctp_is_addr_restricted(stcb, laddr->ifa->ifa_addr)) {
1323 if (sctp_fill_user_address(sas, laddr->ifa->ifa_addr))
1326 ((struct sockaddr_in6 *)sas)->sin6_port = inp->sctp_lport;
1327 sas = (struct sockaddr_storage *)((caddr_t)sas +
1328 laddr->ifa->ifa_addr->sa_len);
1329 actual += laddr->ifa->ifa_addr->sa_len;
1330 if (actual >= limit) {
1335 /* The list is a positive list if present */
1337 /* Must use the specific association list */
1338 LIST_FOREACH(laddr, &stcb->asoc.sctp_local_addr_list,
1340 if (sctp_fill_user_address(sas,
1341 laddr->ifa->ifa_addr))
1343 ((struct sockaddr_in6 *)sas)->sin6_port = inp->sctp_lport;
1344 sas = (struct sockaddr_storage *)((caddr_t)sas +
1345 laddr->ifa->ifa_addr->sa_len);
1346 actual += laddr->ifa->ifa_addr->sa_len;
1347 if (actual >= limit) {
1352 /* No endpoint so use the endpoints individual list */
1353 LIST_FOREACH(laddr, &inp->sctp_addr_list,
1355 if (sctp_fill_user_address(sas,
1356 laddr->ifa->ifa_addr))
1358 ((struct sockaddr_in6 *)sas)->sin6_port = inp->sctp_lport;
1359 sas = (struct sockaddr_storage *)((caddr_t)sas +
1360 laddr->ifa->ifa_addr->sa_len);
1361 actual += laddr->ifa->ifa_addr->sa_len;
1362 if (actual >= limit) {
1373 sctp_count_max_addresses(struct sctp_inpcb *inp)
1377 * In both sub-set bound an bound_all cases we return the MAXIMUM
1378 * number of addresses that you COULD get. In reality the sub-set
1379 * bound may have an exclusion list for a given TCB OR in the
1380 * bound-all case a TCB may NOT include the loopback or other
1381 * addresses as well.
1383 if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUNDALL) {
1387 TAILQ_FOREACH(ifn, &ifnet, if_list) {
1388 TAILQ_FOREACH(ifa, &ifn->if_addrlist, ifa_list) {
1389 /* Count them if they are the right type */
1390 if (ifa->ifa_addr->sa_family == AF_INET) {
1391 if (inp->sctp_flags & SCTP_PCB_FLAGS_NEEDS_MAPPED_V4)
1392 cnt += sizeof(struct sockaddr_in6);
1394 cnt += sizeof(struct sockaddr_in);
1396 } else if (ifa->ifa_addr->sa_family == AF_INET6)
1397 cnt += sizeof(struct sockaddr_in6);
1401 struct sctp_laddr *laddr;
1402 LIST_FOREACH(laddr, &inp->sctp_addr_list, sctp_nxt_addr) {
1403 if (laddr->ifa->ifa_addr->sa_family == AF_INET) {
1404 if (inp->sctp_flags & SCTP_PCB_FLAGS_NEEDS_MAPPED_V4)
1405 cnt += sizeof(struct sockaddr_in6);
1407 cnt += sizeof(struct sockaddr_in);
1409 } else if (laddr->ifa->ifa_addr->sa_family == AF_INET6)
1410 cnt += sizeof(struct sockaddr_in6);
1417 sctp_do_connect_x(struct socket *so,
1418 struct sctp_inpcb *inp,
1420 #if (defined(__FreeBSD__) && __FreeBSD_version >= 500000) || defined(__DragonFly__)
1429 struct sctp_tcb *stcb = NULL;
1430 struct sockaddr *sa;
1431 int num_v6=0, num_v4=0, *totaddrp, totaddr, i, incr, at;
1433 if (sctp_debug_on & SCTP_DEBUG_PCB1) {
1434 printf("Connectx called\n");
1436 #endif /* SCTP_DEBUG */
1439 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) &&
1440 (inp->sctp_flags & SCTP_PCB_FLAGS_CONNECTED)) {
1441 /* We are already connected AND the TCP model */
1443 return (EADDRINUSE);
1445 if (inp->sctp_flags & SCTP_PCB_FLAGS_CONNECTED) {
1446 SCTP_INP_RLOCK(inp);
1447 stcb = LIST_FIRST(&inp->sctp_asoc_list);
1448 SCTP_INP_RUNLOCK(inp);
1455 SCTP_ASOC_CREATE_LOCK(inp);
1456 if ((inp->sctp_flags & SCTP_PCB_FLAGS_SOCKET_GONE) ||
1457 (inp->sctp_flags & SCTP_PCB_FLAGS_SOCKET_GONE)) {
1458 SCTP_ASOC_CREATE_UNLOCK(inp);
1463 totaddrp = mtod(m, int *);
1464 totaddr = *totaddrp;
1465 sa = (struct sockaddr *)(totaddrp + 1);
1467 /* account and validate addresses */
1468 SCTP_INP_WLOCK(inp);
1469 SCTP_INP_INCR_REF(inp);
1470 SCTP_INP_WUNLOCK(inp);
1471 for (i = 0; i < totaddr; i++) {
1472 if (sa->sa_family == AF_INET) {
1474 incr = sizeof(struct sockaddr_in);
1475 } else if (sa->sa_family == AF_INET6) {
1476 struct sockaddr_in6 *sin6;
1477 sin6 = (struct sockaddr_in6 *)sa;
1478 if (IN6_IS_ADDR_V4MAPPED(&sin6->sin6_addr)) {
1479 /* Must be non-mapped for connectx */
1480 SCTP_ASOC_CREATE_UNLOCK(inp);
1485 incr = sizeof(struct sockaddr_in6);
1490 stcb = sctp_findassociation_ep_addr(&inp, sa, NULL, NULL, NULL);
1492 /* Already have or am bring up an association */
1493 SCTP_ASOC_CREATE_UNLOCK(inp);
1494 SCTP_TCB_UNLOCK(stcb);
1498 if ((at + incr) > m->m_len) {
1502 sa = (struct sockaddr *)((caddr_t)sa + incr);
1504 sa = (struct sockaddr *)(totaddrp + 1);
1505 SCTP_INP_WLOCK(inp);
1506 SCTP_INP_DECR_REF(inp);
1507 SCTP_INP_WUNLOCK(inp);
1509 if (((inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) == 0) &&
1512 SCTP_INP_WUNLOCK(inp);
1513 SCTP_ASOC_CREATE_UNLOCK(inp);
1516 if ((inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) &&
1518 struct in6pcb *inp6;
1519 inp6 = (struct in6pcb *)inp;
1521 #if defined(__OpenBSD__)
1522 (0) /* we always do dual bind */
1523 #elif defined (__NetBSD__)
1524 (inp6->in6p_flags & IN6P_IPV6_V6ONLY)
1526 (inp6->inp_flags & IN6P_IPV6_V6ONLY)
1530 * if IPV6_V6ONLY flag, ignore connections
1531 * destined to a v4 addr or v4-mapped addr
1533 SCTP_INP_WUNLOCK(inp);
1534 SCTP_ASOC_CREATE_UNLOCK(inp);
1540 if ((inp->sctp_flags & SCTP_PCB_FLAGS_UNBOUND) ==
1541 SCTP_PCB_FLAGS_UNBOUND) {
1542 /* Bind a ephemeral port */
1543 SCTP_INP_WUNLOCK(inp);
1544 error = sctp_inpcb_bind(so, NULL, p);
1546 SCTP_ASOC_CREATE_UNLOCK(inp);
1551 SCTP_INP_WUNLOCK(inp);
1553 /* We are GOOD to go */
1554 stcb = sctp_aloc_assoc(inp, sa, 1, &error, 0);
1556 /* Gak! no memory */
1557 SCTP_ASOC_CREATE_UNLOCK(inp);
1561 /* move to second address */
1562 if (sa->sa_family == AF_INET)
1563 sa = (struct sockaddr *)((caddr_t)sa + sizeof(struct sockaddr_in));
1565 sa = (struct sockaddr *)((caddr_t)sa + sizeof(struct sockaddr_in6));
1567 for (i = 1; i < totaddr; i++) {
1568 if (sa->sa_family == AF_INET) {
1569 incr = sizeof(struct sockaddr_in);
1570 if (sctp_add_remote_addr(stcb, sa, 0, 8)) {
1571 /* assoc gone no un-lock */
1572 sctp_free_assoc(inp, stcb);
1573 SCTP_ASOC_CREATE_UNLOCK(inp);
1578 } else if (sa->sa_family == AF_INET6) {
1579 incr = sizeof(struct sockaddr_in6);
1580 if (sctp_add_remote_addr(stcb, sa, 0, 8)) {
1581 /* assoc gone no un-lock */
1582 sctp_free_assoc(inp, stcb);
1583 SCTP_ASOC_CREATE_UNLOCK(inp);
1588 sa = (struct sockaddr *)((caddr_t)sa + incr);
1590 stcb->asoc.state = SCTP_STATE_COOKIE_WAIT;
1592 /* doing delayed connection */
1593 stcb->asoc.delayed_connection = 1;
1594 sctp_timer_start(SCTP_TIMER_TYPE_INIT, inp, stcb, stcb->asoc.primary_destination);
1596 SCTP_GETTIME_TIMEVAL(&stcb->asoc.time_entered);
1597 sctp_send_initiate(inp, stcb);
1599 SCTP_TCB_UNLOCK(stcb);
1600 if (stcb->sctp_ep->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) {
1601 stcb->sctp_ep->sctp_flags |= SCTP_PCB_FLAGS_CONNECTED;
1602 /* Set the connected flag so we can queue data */
1605 SCTP_ASOC_CREATE_UNLOCK(inp);
1612 sctp_optsget(struct socket *so,
1615 #if (defined(__FreeBSD__) && __FreeBSD_version >= 500000) || defined(__DragonFly__)
1622 struct sctp_inpcb *inp;
1624 int error, optval=0;
1625 struct sctp_tcb *stcb = NULL;
1627 inp = (struct sctp_inpcb *)so->so_pcb;
1634 if (sctp_debug_on & SCTP_DEBUG_USRREQ1) {
1635 printf("optsget:MP is NULL EINVAL\n");
1637 #endif /* SCTP_DEBUG */
1642 /* Got to have a mbuf */
1644 if (sctp_debug_on & SCTP_DEBUG_USRREQ1) {
1645 printf("Huh no mbuf\n");
1647 #endif /* SCTP_DEBUG */
1651 if (sctp_debug_on & SCTP_DEBUG_USRREQ2) {
1652 printf("optsget opt:%lxx sz:%u\n", (unsigned long)opt,
1655 #endif /* SCTP_DEBUG */
1659 case SCTP_AUTOCLOSE:
1660 case SCTP_AUTO_ASCONF:
1661 case SCTP_DISABLE_FRAGMENTS:
1662 case SCTP_I_WANT_MAPPED_V4_ADDR:
1664 if (sctp_debug_on & SCTP_DEBUG_USRREQ2) {
1665 printf("other stuff\n");
1667 #endif /* SCTP_DEBUG */
1668 SCTP_INP_RLOCK(inp);
1670 case SCTP_DISABLE_FRAGMENTS:
1671 optval = inp->sctp_flags & SCTP_PCB_FLAGS_NO_FRAGMENT;
1673 case SCTP_I_WANT_MAPPED_V4_ADDR:
1674 optval = inp->sctp_flags & SCTP_PCB_FLAGS_NEEDS_MAPPED_V4;
1676 case SCTP_AUTO_ASCONF:
1677 optval = inp->sctp_flags & SCTP_PCB_FLAGS_AUTO_ASCONF;
1680 optval = inp->sctp_flags & SCTP_PCB_FLAGS_NODELAY;
1682 case SCTP_AUTOCLOSE:
1683 if ((inp->sctp_flags & SCTP_PCB_FLAGS_AUTOCLOSE) ==
1684 SCTP_PCB_FLAGS_AUTOCLOSE)
1685 optval = inp->sctp_ep.auto_close_time;
1691 error = ENOPROTOOPT;
1692 } /* end switch (sopt->sopt_name) */
1693 if (opt != SCTP_AUTOCLOSE) {
1694 /* make it an "on/off" value */
1695 optval = (optval != 0);
1697 if ((size_t)m->m_len < sizeof(int)) {
1700 SCTP_INP_RUNLOCK(inp);
1702 /* return the option value */
1703 *mtod(m, int *) = optval;
1704 m->m_len = sizeof(optval);
1707 case SCTP_GET_ASOC_ID_LIST:
1709 struct sctp_assoc_ids *ids;
1713 if ((size_t)m->m_len < sizeof(struct sctp_assoc_ids)) {
1717 ids = mtod(m, struct sctp_assoc_ids *);
1719 SCTP_INP_RLOCK(inp);
1720 stcb = LIST_FIRST(&inp->sctp_asoc_list);
1723 ids->asls_numb_present = 0;
1724 ids->asls_more_to_get = 0;
1725 SCTP_INP_RUNLOCK(inp);
1728 orig = ids->asls_assoc_start;
1729 stcb = LIST_FIRST(&inp->sctp_asoc_list);
1731 stcb = LIST_NEXT(stcb , sctp_tcblist);
1739 ids->asls_numb_present = 0;
1740 ids->asls_more_to_get = 1;
1741 while(at < MAX_ASOC_IDS_RET) {
1742 ids->asls_assoc_id[at] = sctp_get_associd(stcb);
1744 ids->asls_numb_present++;
1745 stcb = LIST_NEXT(stcb , sctp_tcblist);
1747 ids->asls_more_to_get = 0;
1751 SCTP_INP_RUNLOCK(inp);
1754 case SCTP_GET_NONCE_VALUES:
1756 struct sctp_get_nonce_values *gnv;
1757 if ((size_t)m->m_len < sizeof(struct sctp_get_nonce_values)) {
1761 gnv = mtod(m, struct sctp_get_nonce_values *);
1762 stcb = sctp_findassociation_ep_asocid(inp, gnv->gn_assoc_id);
1766 gnv->gn_peers_tag = stcb->asoc.peer_vtag;
1767 gnv->gn_local_tag = stcb->asoc.my_vtag;
1768 SCTP_TCB_UNLOCK(stcb);
1773 case SCTP_PEER_PUBLIC_KEY:
1774 case SCTP_MY_PUBLIC_KEY:
1775 case SCTP_SET_AUTH_CHUNKS:
1776 case SCTP_SET_AUTH_SECRET:
1777 /* not supported yet and until we refine the draft */
1781 case SCTP_DELAYED_ACK_TIME:
1784 if ((size_t)m->m_len < sizeof(int32_t)) {
1788 tm = mtod(m, int32_t *);
1790 *tm = TICKS_TO_MSEC(inp->sctp_ep.sctp_timeoutticks[SCTP_TIMER_RECV]);
1794 case SCTP_GET_SNDBUF_USE:
1795 if ((size_t)m->m_len < sizeof(struct sctp_sockstat)) {
1798 struct sctp_sockstat *ss;
1799 struct sctp_tcb *stcb;
1800 struct sctp_association *asoc;
1801 ss = mtod(m, struct sctp_sockstat *);
1802 stcb = sctp_findassociation_ep_asocid(inp, ss->ss_assoc_id);
1807 ss->ss_total_sndbuf = (u_int32_t)asoc->total_output_queue_size;
1808 ss->ss_total_mbuf_sndbuf = (u_int32_t)asoc->total_output_mbuf_queue_size;
1809 ss->ss_total_recv_buf = (u_int32_t)(asoc->size_on_delivery_queue +
1810 asoc->size_on_reasm_queue +
1811 asoc->size_on_all_streams);
1812 SCTP_TCB_UNLOCK(stcb);
1814 m->m_len = sizeof(struct sctp_sockstat);
1821 burst = mtod(m, u_int8_t *);
1822 SCTP_INP_RLOCK(inp);
1823 *burst = inp->sctp_ep.max_burst;
1824 SCTP_INP_RUNLOCK(inp);
1825 m->m_len = sizeof(u_int8_t);
1831 sctp_assoc_t *assoc_id;
1834 if ((size_t)m->m_len < sizeof(u_int32_t)) {
1838 if ((size_t)m->m_len < sizeof(sctp_assoc_t)) {
1842 assoc_id = mtod(m, sctp_assoc_t *);
1843 segsize = mtod(m, u_int32_t *);
1844 m->m_len = sizeof(u_int32_t);
1846 if (((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) &&
1847 (inp->sctp_flags & SCTP_PCB_FLAGS_CONNECTED)) ||
1848 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL)) {
1849 struct sctp_tcb *stcb;
1850 SCTP_INP_RLOCK(inp);
1851 stcb = LIST_FIRST(&inp->sctp_asoc_list);
1853 SCTP_TCB_LOCK(stcb);
1854 SCTP_INP_RUNLOCK(inp);
1855 *segsize = sctp_get_frag_point(stcb, &stcb->asoc);
1856 SCTP_TCB_UNLOCK(stcb);
1858 SCTP_INP_RUNLOCK(inp);
1862 stcb = sctp_findassociation_ep_asocid(inp, *assoc_id);
1864 *segsize = sctp_get_frag_point(stcb, &stcb->asoc);
1865 SCTP_TCB_UNLOCK(stcb);
1869 /* default is to get the max, if I
1870 * can't calculate from an existing association.
1872 if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) {
1873 ovh = SCTP_MED_OVERHEAD;
1875 ovh = SCTP_MED_V4_OVERHEAD;
1877 *segsize = inp->sctp_frag_point - ovh;
1882 case SCTP_SET_DEBUG_LEVEL:
1886 if ((size_t)m->m_len < sizeof(u_int32_t)) {
1890 level = mtod(m, u_int32_t *);
1892 *level = sctp_debug_on;
1893 m->m_len = sizeof(u_int32_t);
1894 printf("Returning DEBUG LEVEL %x is set\n",
1895 (u_int)sctp_debug_on);
1897 #else /* SCTP_DEBUG */
1901 case SCTP_GET_STAT_LOG:
1902 #ifdef SCTP_STAT_LOGGING
1903 error = sctp_fill_stat_log(m);
1904 #else /* SCTP_DEBUG */
1911 if ((size_t)m->m_len < sizeof(sctp_pegs)) {
1915 pt = mtod(m, u_int32_t *);
1916 memcpy(pt, sctp_pegs, sizeof(sctp_pegs));
1917 m->m_len = sizeof(sctp_pegs);
1922 struct sctp_event_subscribe *events;
1924 if (sctp_debug_on & SCTP_DEBUG_USRREQ2) {
1925 printf("get events\n");
1927 #endif /* SCTP_DEBUG */
1928 if ((size_t)m->m_len < sizeof(struct sctp_event_subscribe)) {
1930 if (sctp_debug_on & SCTP_DEBUG_USRREQ2) {
1931 printf("M->M_LEN is %d not %d\n",
1933 (int)sizeof(struct sctp_event_subscribe));
1935 #endif /* SCTP_DEBUG */
1939 events = mtod(m, struct sctp_event_subscribe *);
1940 memset(events, 0, sizeof(events));
1941 SCTP_INP_RLOCK(inp);
1942 if (inp->sctp_flags & SCTP_PCB_FLAGS_RECVDATAIOEVNT)
1943 events->sctp_data_io_event = 1;
1945 if (inp->sctp_flags & SCTP_PCB_FLAGS_RECVASSOCEVNT)
1946 events->sctp_association_event = 1;
1948 if (inp->sctp_flags & SCTP_PCB_FLAGS_RECVPADDREVNT)
1949 events->sctp_address_event = 1;
1951 if (inp->sctp_flags & SCTP_PCB_FLAGS_RECVSENDFAILEVNT)
1952 events->sctp_send_failure_event = 1;
1954 if (inp->sctp_flags & SCTP_PCB_FLAGS_RECVPEERERR)
1955 events->sctp_peer_error_event = 1;
1957 if (inp->sctp_flags & SCTP_PCB_FLAGS_RECVSHUTDOWNEVNT)
1958 events->sctp_shutdown_event = 1;
1960 if (inp->sctp_flags & SCTP_PCB_FLAGS_PDAPIEVNT)
1961 events->sctp_partial_delivery_event = 1;
1963 if (inp->sctp_flags & SCTP_PCB_FLAGS_ADAPTIONEVNT)
1964 events->sctp_adaption_layer_event = 1;
1966 if (inp->sctp_flags & SCTP_PCB_FLAGS_STREAM_RESETEVNT)
1967 events->sctp_stream_reset_events = 1;
1968 SCTP_INP_RUNLOCK(inp);
1969 m->m_len = sizeof(struct sctp_event_subscribe);
1974 case SCTP_ADAPTION_LAYER:
1975 if ((size_t)m->m_len < sizeof(int)) {
1980 if (sctp_debug_on & SCTP_DEBUG_USRREQ1) {
1981 printf("getadaption ind\n");
1983 #endif /* SCTP_DEBUG */
1984 SCTP_INP_RLOCK(inp);
1985 *mtod(m, int *) = inp->sctp_ep.adaption_layer_indicator;
1986 SCTP_INP_RUNLOCK(inp);
1987 m->m_len = sizeof(int);
1989 case SCTP_SET_INITIAL_DBG_SEQ:
1990 if ((size_t)m->m_len < sizeof(int)) {
1995 if (sctp_debug_on & SCTP_DEBUG_USRREQ1) {
1996 printf("get initial dbg seq\n");
1998 #endif /* SCTP_DEBUG */
1999 SCTP_INP_RLOCK(inp);
2000 *mtod(m, int *) = inp->sctp_ep.initial_sequence_debug;
2001 SCTP_INP_RUNLOCK(inp);
2002 m->m_len = sizeof(int);
2004 case SCTP_GET_LOCAL_ADDR_SIZE:
2005 if ((size_t)m->m_len < sizeof(int)) {
2010 if (sctp_debug_on & SCTP_DEBUG_USRREQ1) {
2011 printf("get local sizes\n");
2013 #endif /* SCTP_DEBUG */
2014 SCTP_INP_RLOCK(inp);
2015 *mtod(m, int *) = sctp_count_max_addresses(inp);
2016 SCTP_INP_RUNLOCK(inp);
2017 m->m_len = sizeof(int);
2019 case SCTP_GET_REMOTE_ADDR_SIZE:
2021 sctp_assoc_t *assoc_id;
2023 struct sctp_nets *net;
2025 if (sctp_debug_on & SCTP_DEBUG_USRREQ1) {
2026 printf("get remote size\n");
2028 #endif /* SCTP_DEBUG */
2029 if ((size_t)m->m_len < sizeof(sctp_assoc_t)) {
2031 printf("m->m_len:%d not %d\n",
2032 m->m_len, sizeof(sctp_assoc_t));
2033 #endif /* SCTP_DEBUG */
2038 val = mtod(m, u_int32_t *);
2039 if (inp->sctp_flags & SCTP_PCB_FLAGS_CONNECTED) {
2040 SCTP_INP_RLOCK(inp);
2041 stcb = LIST_FIRST(&inp->sctp_asoc_list);
2043 SCTP_TCB_LOCK(stcb);
2044 SCTP_INP_RUNLOCK(inp);
2047 assoc_id = mtod(m, sctp_assoc_t *);
2048 stcb = sctp_findassociation_ep_asocid(inp, *assoc_id);
2057 /* Count the sizes */
2058 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
2059 if ((stcb->sctp_ep->sctp_flags & SCTP_PCB_FLAGS_NEEDS_MAPPED_V4) ||
2060 (((struct sockaddr *)&net->ro._l_addr)->sa_family == AF_INET6)) {
2061 sz += sizeof(struct sockaddr_in6);
2062 } else if (((struct sockaddr *)&net->ro._l_addr)->sa_family == AF_INET) {
2063 sz += sizeof(struct sockaddr_in);
2069 SCTP_TCB_UNLOCK(stcb);
2071 m->m_len = sizeof(u_int32_t);
2074 case SCTP_GET_PEER_ADDRESSES:
2076 * Get the address information, an array
2077 * is passed in to fill up we pack it.
2081 struct sockaddr_storage *sas;
2082 struct sctp_nets *net;
2083 struct sctp_getaddresses *saddr;
2085 if (sctp_debug_on & SCTP_DEBUG_USRREQ1) {
2086 printf("get peer addresses\n");
2088 #endif /* SCTP_DEBUG */
2089 if ((size_t)m->m_len < sizeof(struct sctp_getaddresses)) {
2093 left = m->m_len - sizeof(struct sctp_getaddresses);
2094 saddr = mtod(m, struct sctp_getaddresses *);
2095 if (inp->sctp_flags & SCTP_PCB_FLAGS_CONNECTED) {
2096 SCTP_INP_RLOCK(inp);
2097 stcb = LIST_FIRST(&inp->sctp_asoc_list);
2099 SCTP_TCB_LOCK(stcb);
2100 SCTP_INP_RUNLOCK(inp);
2102 stcb = sctp_findassociation_ep_asocid(inp,
2103 saddr->sget_assoc_id);
2108 m->m_len = sizeof(struct sctp_getaddresses);
2109 sas = (struct sockaddr_storage *)&saddr->addr[0];
2111 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
2112 if ((stcb->sctp_ep->sctp_flags & SCTP_PCB_FLAGS_NEEDS_MAPPED_V4) ||
2113 (((struct sockaddr *)&net->ro._l_addr)->sa_family == AF_INET6)) {
2114 cpsz = sizeof(struct sockaddr_in6);
2115 } else if (((struct sockaddr *)&net->ro._l_addr)->sa_family == AF_INET) {
2116 cpsz = sizeof(struct sockaddr_in);
2122 /* not enough room. */
2124 if (sctp_debug_on & SCTP_DEBUG_USRREQ1) {
2125 printf("Out of room\n");
2127 #endif /* SCTP_DEBUG */
2130 if ((stcb->sctp_ep->sctp_flags & SCTP_PCB_FLAGS_NEEDS_MAPPED_V4) &&
2131 (((struct sockaddr *)&net->ro._l_addr)->sa_family == AF_INET)) {
2132 /* Must map the address */
2133 in6_sin_2_v4mapsin6((struct sockaddr_in *)&net->ro._l_addr,
2134 (struct sockaddr_in6 *)sas);
2136 memcpy(sas, &net->ro._l_addr, cpsz);
2138 ((struct sockaddr_in *)sas)->sin_port = stcb->rport;
2140 sas = (struct sockaddr_storage *)((caddr_t)sas + cpsz);
2144 if (sctp_debug_on & SCTP_DEBUG_USRREQ2) {
2145 printf("left now:%d mlen:%d\n",
2148 #endif /* SCTP_DEBUG */
2150 SCTP_TCB_UNLOCK(stcb);
2153 if (sctp_debug_on & SCTP_DEBUG_USRREQ1) {
2154 printf("All done\n");
2156 #endif /* SCTP_DEBUG */
2158 case SCTP_GET_LOCAL_ADDRESSES:
2161 struct sockaddr_storage *sas;
2162 struct sctp_getaddresses *saddr;
2164 if (sctp_debug_on & SCTP_DEBUG_USRREQ1) {
2165 printf("get local addresses\n");
2167 #endif /* SCTP_DEBUG */
2168 if ((size_t)m->m_len < sizeof(struct sctp_getaddresses)) {
2172 saddr = mtod(m, struct sctp_getaddresses *);
2174 if (saddr->sget_assoc_id) {
2175 if (inp->sctp_flags & SCTP_PCB_FLAGS_CONNECTED) {
2176 SCTP_INP_RLOCK(inp);
2177 stcb = LIST_FIRST(&inp->sctp_asoc_list);
2179 SCTP_TCB_LOCK(stcb);
2180 SCTP_INP_RUNLOCK(inp);
2182 stcb = sctp_findassociation_ep_asocid(inp, saddr->sget_assoc_id);
2188 * assure that the TCP model does not need a assoc id
2191 if ( (inp->sctp_flags & SCTP_PCB_FLAGS_CONNECTED) &&
2193 SCTP_INP_RLOCK(inp);
2194 stcb = LIST_FIRST(&inp->sctp_asoc_list);
2196 SCTP_TCB_LOCK(stcb);
2197 SCTP_INP_RUNLOCK(inp);
2199 sas = (struct sockaddr_storage *)&saddr->addr[0];
2200 limit = m->m_len - sizeof(sctp_assoc_t);
2201 actual = sctp_fill_up_addresses(inp, stcb, limit, sas);
2202 SCTP_TCB_UNLOCK(stcb);
2203 m->m_len = sizeof(struct sockaddr_storage) + actual;
2206 case SCTP_PEER_ADDR_PARAMS:
2208 struct sctp_paddrparams *paddrp;
2209 struct sctp_nets *net;
2212 if (sctp_debug_on & SCTP_DEBUG_USRREQ1) {
2213 printf("Getting peer_addr_params\n");
2215 #endif /* SCTP_DEBUG */
2216 if ((size_t)m->m_len < sizeof(struct sctp_paddrparams)) {
2218 if (sctp_debug_on & SCTP_DEBUG_USRREQ2) {
2219 printf("Hmm m->m_len:%d is to small\n",
2222 #endif /* SCTP_DEBUG */
2226 paddrp = mtod(m, struct sctp_paddrparams *);
2229 if (paddrp->spp_assoc_id) {
2231 if (sctp_debug_on & SCTP_DEBUG_USRREQ1) {
2232 printf("In spp_assoc_id find type\n");
2234 #endif /* SCTP_DEBUG */
2235 if (inp->sctp_flags & SCTP_PCB_FLAGS_CONNECTED) {
2236 SCTP_INP_RLOCK(inp);
2237 stcb = LIST_FIRST(&inp->sctp_asoc_list);
2239 SCTP_TCB_LOCK(stcb);
2240 net = sctp_findnet(stcb, (struct sockaddr *)&paddrp->spp_address);
2242 SCTP_INP_RLOCK(inp);
2244 stcb = sctp_findassociation_ep_asocid(inp, paddrp->spp_assoc_id);
2251 if ( (stcb == NULL) &&
2252 ((((struct sockaddr *)&paddrp->spp_address)->sa_family == AF_INET) ||
2253 (((struct sockaddr *)&paddrp->spp_address)->sa_family == AF_INET6))) {
2254 /* Lookup via address */
2256 if (sctp_debug_on & SCTP_DEBUG_USRREQ1) {
2257 printf("Ok we need to lookup a param\n");
2259 #endif /* SCTP_DEBUG */
2260 if (inp->sctp_flags & SCTP_PCB_FLAGS_CONNECTED) {
2261 SCTP_INP_RLOCK(inp);
2262 stcb = LIST_FIRST(&inp->sctp_asoc_list);
2264 SCTP_TCB_LOCK(stcb);
2265 net = sctp_findnet(stcb, (struct sockaddr *)&paddrp->spp_address);
2267 SCTP_INP_RUNLOCK(inp);
2269 SCTP_INP_WLOCK(inp);
2270 SCTP_INP_INCR_REF(inp);
2271 SCTP_INP_WUNLOCK(inp);
2272 stcb = sctp_findassociation_ep_addr(&inp,
2273 (struct sockaddr *)&paddrp->spp_address,
2276 SCTP_INP_WLOCK(inp);
2277 SCTP_INP_DECR_REF(inp);
2278 SCTP_INP_WUNLOCK(inp);
2287 /* Effects the Endpoint */
2289 if (sctp_debug_on & SCTP_DEBUG_USRREQ1) {
2290 printf("User wants EP level info\n");
2292 #endif /* SCTP_DEBUG */
2296 /* Applys to the specific association */
2298 if (sctp_debug_on & SCTP_DEBUG_USRREQ1) {
2299 printf("In TCB side\n");
2301 #endif /* SCTP_DEBUG */
2303 paddrp->spp_pathmaxrxt = net->failure_threshold;
2305 /* No destination so return default value */
2306 paddrp->spp_pathmaxrxt = stcb->asoc.def_net_failure;
2308 paddrp->spp_hbinterval = stcb->asoc.heart_beat_delay;
2309 paddrp->spp_assoc_id = sctp_get_associd(stcb);
2310 SCTP_TCB_UNLOCK(stcb);
2312 /* Use endpoint defaults */
2313 SCTP_INP_RLOCK(inp);
2315 if (sctp_debug_on & SCTP_DEBUG_USRREQ1) {
2316 printf("In EP levle info\n");
2318 #endif /* SCTP_DEBUG */
2319 paddrp->spp_pathmaxrxt = inp->sctp_ep.def_net_failure;
2320 paddrp->spp_hbinterval = inp->sctp_ep.sctp_timeoutticks[SCTP_TIMER_HEARTBEAT];
2321 paddrp->spp_assoc_id = (sctp_assoc_t)0;
2322 SCTP_INP_RUNLOCK(inp);
2324 m->m_len = sizeof(struct sctp_paddrparams);
2327 case SCTP_GET_PEER_ADDR_INFO:
2329 struct sctp_paddrinfo *paddri;
2330 struct sctp_nets *net;
2332 if (sctp_debug_on & SCTP_DEBUG_USRREQ1) {
2333 printf("GetPEER ADDR_INFO\n");
2335 #endif /* SCTP_DEBUG */
2336 if ((size_t)m->m_len < sizeof(struct sctp_paddrinfo)) {
2340 paddri = mtod(m, struct sctp_paddrinfo *);
2342 if ((((struct sockaddr *)&paddri->spinfo_address)->sa_family == AF_INET) ||
2343 (((struct sockaddr *)&paddri->spinfo_address)->sa_family == AF_INET6)) {
2344 /* Lookup via address */
2345 if (inp->sctp_flags & SCTP_PCB_FLAGS_CONNECTED) {
2346 SCTP_INP_RLOCK(inp);
2347 stcb = LIST_FIRST(&inp->sctp_asoc_list);
2349 SCTP_TCB_LOCK(stcb);
2350 net = sctp_findnet(stcb,
2351 (struct sockaddr *)&paddri->spinfo_address);
2353 SCTP_INP_RUNLOCK(inp);
2355 SCTP_INP_WLOCK(inp);
2356 SCTP_INP_INCR_REF(inp);
2357 SCTP_INP_WUNLOCK(inp);
2358 stcb = sctp_findassociation_ep_addr(&inp,
2359 (struct sockaddr *)&paddri->spinfo_address,
2362 SCTP_INP_WLOCK(inp);
2363 SCTP_INP_DECR_REF(inp);
2364 SCTP_INP_WUNLOCK(inp);
2371 if ((stcb == NULL) || (net == NULL)) {
2375 m->m_len = sizeof(struct sctp_paddrinfo);
2376 paddri->spinfo_state = net->dest_state & (SCTP_REACHABLE_MASK|SCTP_ADDR_NOHB);
2377 paddri->spinfo_cwnd = net->cwnd;
2378 paddri->spinfo_srtt = ((net->lastsa >> 2) + net->lastsv) >> 1;
2379 paddri->spinfo_rto = net->RTO;
2380 paddri->spinfo_assoc_id = sctp_get_associd(stcb);
2381 SCTP_TCB_UNLOCK(stcb);
2384 case SCTP_PCB_STATUS:
2386 struct sctp_pcbinfo *spcb;
2388 if (sctp_debug_on & SCTP_DEBUG_USRREQ1) {
2389 printf("PCB status\n");
2391 #endif /* SCTP_DEBUG */
2392 if ((size_t)m->m_len < sizeof(struct sctp_pcbinfo)) {
2396 spcb = mtod(m, struct sctp_pcbinfo *);
2397 sctp_fill_pcbinfo(spcb);
2398 m->m_len = sizeof(struct sctp_pcbinfo);
2403 struct sctp_nets *net;
2404 struct sctp_status *sstat;
2406 if (sctp_debug_on & SCTP_DEBUG_USRREQ1) {
2407 printf("SCTP status\n");
2409 #endif /* SCTP_DEBUG */
2411 if ((size_t)m->m_len < sizeof(struct sctp_status)) {
2415 sstat = mtod(m, struct sctp_status *);
2417 if (inp->sctp_flags & SCTP_PCB_FLAGS_CONNECTED) {
2418 SCTP_INP_RLOCK(inp);
2419 stcb = LIST_FIRST(&inp->sctp_asoc_list);
2421 SCTP_TCB_LOCK(stcb);
2422 SCTP_INP_RUNLOCK(inp);
2424 stcb = sctp_findassociation_ep_asocid(inp, sstat->sstat_assoc_id);
2431 * I think passing the state is fine since
2432 * sctp_constants.h will be available to the user
2435 sstat->sstat_state = stcb->asoc.state;
2436 sstat->sstat_rwnd = stcb->asoc.peers_rwnd;
2437 sstat->sstat_unackdata = stcb->asoc.sent_queue_cnt;
2439 * We can't include chunks that have been passed
2440 * to the socket layer. Only things in queue.
2442 sstat->sstat_penddata = (stcb->asoc.cnt_on_delivery_queue +
2443 stcb->asoc.cnt_on_reasm_queue +
2444 stcb->asoc.cnt_on_all_streams);
2447 sstat->sstat_instrms = stcb->asoc.streamincnt;
2448 sstat->sstat_outstrms = stcb->asoc.streamoutcnt;
2449 sstat->sstat_fragmentation_point = sctp_get_frag_point(stcb, &stcb->asoc);
2450 memcpy(&sstat->sstat_primary.spinfo_address,
2451 &stcb->asoc.primary_destination->ro._l_addr,
2452 ((struct sockaddr *)(&stcb->asoc.primary_destination->ro._l_addr))->sa_len);
2453 net = stcb->asoc.primary_destination;
2454 ((struct sockaddr_in *)&sstat->sstat_primary.spinfo_address)->sin_port = stcb->rport;
2456 * Again the user can get info from sctp_constants.h
2457 * for what the state of the network is.
2459 sstat->sstat_primary.spinfo_state = net->dest_state & SCTP_REACHABLE_MASK;
2460 sstat->sstat_primary.spinfo_cwnd = net->cwnd;
2461 sstat->sstat_primary.spinfo_srtt = net->lastsa;
2462 sstat->sstat_primary.spinfo_rto = net->RTO;
2463 sstat->sstat_primary.spinfo_mtu = net->mtu;
2464 sstat->sstat_primary.spinfo_assoc_id = sctp_get_associd(stcb);
2465 SCTP_TCB_UNLOCK(stcb);
2466 m->m_len = sizeof(*sstat);
2471 struct sctp_rtoinfo *srto;
2473 if (sctp_debug_on & SCTP_DEBUG_USRREQ1) {
2474 printf("RTO Info\n");
2476 #endif /* SCTP_DEBUG */
2477 if ((size_t)m->m_len < sizeof(struct sctp_rtoinfo)) {
2481 srto = mtod(m, struct sctp_rtoinfo *);
2482 if (srto->srto_assoc_id == 0) {
2483 /* Endpoint only please */
2484 SCTP_INP_RLOCK(inp);
2485 srto->srto_initial = inp->sctp_ep.initial_rto;
2486 srto->srto_max = inp->sctp_ep.sctp_maxrto;
2487 srto->srto_min = inp->sctp_ep.sctp_minrto;
2488 SCTP_INP_RUNLOCK(inp);
2491 if (inp->sctp_flags & SCTP_PCB_FLAGS_CONNECTED) {
2492 SCTP_INP_RLOCK(inp);
2493 stcb = LIST_FIRST(&inp->sctp_asoc_list);
2495 SCTP_TCB_LOCK(stcb);
2496 SCTP_INP_RUNLOCK(inp);
2498 stcb = sctp_findassociation_ep_asocid(inp, srto->srto_assoc_id);
2504 srto->srto_initial = stcb->asoc.initial_rto;
2505 srto->srto_max = stcb->asoc.maxrto;
2506 srto->srto_min = stcb->asoc.minrto;
2507 SCTP_TCB_UNLOCK(stcb);
2508 m->m_len = sizeof(*srto);
2511 case SCTP_ASSOCINFO:
2513 struct sctp_assocparams *sasoc;
2515 if (sctp_debug_on & SCTP_DEBUG_USRREQ1) {
2516 printf("Associnfo\n");
2518 #endif /* SCTP_DEBUG */
2519 if ((size_t)m->m_len < sizeof(struct sctp_assocparams)) {
2523 sasoc = mtod(m, struct sctp_assocparams *);
2526 if (inp->sctp_flags & SCTP_PCB_FLAGS_CONNECTED) {
2527 SCTP_INP_RLOCK(inp);
2528 stcb = LIST_FIRST(&inp->sctp_asoc_list);
2530 SCTP_TCB_LOCK(stcb);
2531 SCTP_INP_RUNLOCK(inp);
2533 if ((sasoc->sasoc_assoc_id) && (stcb == NULL)) {
2534 stcb = sctp_findassociation_ep_asocid(inp,
2535 sasoc->sasoc_assoc_id);
2545 sasoc->sasoc_asocmaxrxt = stcb->asoc.max_send_times;
2546 sasoc->sasoc_number_peer_destinations = stcb->asoc.numnets;
2547 sasoc->sasoc_peer_rwnd = stcb->asoc.peers_rwnd;
2548 sasoc->sasoc_local_rwnd = stcb->asoc.my_rwnd;
2549 sasoc->sasoc_cookie_life = stcb->asoc.cookie_life;
2550 SCTP_TCB_UNLOCK(stcb);
2552 SCTP_INP_RLOCK(inp);
2553 sasoc->sasoc_asocmaxrxt = inp->sctp_ep.max_send_times;
2554 sasoc->sasoc_number_peer_destinations = 0;
2555 sasoc->sasoc_peer_rwnd = 0;
2556 sasoc->sasoc_local_rwnd = sbspace(&inp->sctp_socket->so_rcv);
2557 sasoc->sasoc_cookie_life = inp->sctp_ep.def_cookie_life;
2558 SCTP_INP_RUNLOCK(inp);
2560 m->m_len = sizeof(*sasoc);
2563 case SCTP_DEFAULT_SEND_PARAM:
2565 struct sctp_sndrcvinfo *s_info;
2567 if (m->m_len != sizeof(struct sctp_sndrcvinfo)) {
2571 s_info = mtod(m, struct sctp_sndrcvinfo *);
2572 if (inp->sctp_flags & SCTP_PCB_FLAGS_CONNECTED) {
2573 SCTP_INP_RLOCK(inp);
2574 stcb = LIST_FIRST(&inp->sctp_asoc_list);
2576 SCTP_TCB_LOCK(stcb);
2577 SCTP_INP_RUNLOCK(inp);
2579 stcb = sctp_findassociation_ep_asocid(inp, s_info->sinfo_assoc_id);
2586 *s_info = stcb->asoc.def_send;
2587 SCTP_TCB_UNLOCK(stcb);
2588 m->m_len = sizeof(*s_info);
2592 struct sctp_initmsg *sinit;
2594 if (sctp_debug_on & SCTP_DEBUG_USRREQ1) {
2595 printf("initmsg\n");
2597 #endif /* SCTP_DEBUG */
2598 if ((size_t)m->m_len < sizeof(struct sctp_initmsg)) {
2602 sinit = mtod(m, struct sctp_initmsg *);
2603 SCTP_INP_RLOCK(inp);
2604 sinit->sinit_num_ostreams = inp->sctp_ep.pre_open_stream_count;
2605 sinit->sinit_max_instreams = inp->sctp_ep.max_open_streams_intome;
2606 sinit->sinit_max_attempts = inp->sctp_ep.max_init_times;
2607 sinit->sinit_max_init_timeo = inp->sctp_ep.initial_init_rto_max;
2608 SCTP_INP_RUNLOCK(inp);
2609 m->m_len = sizeof(*sinit);
2612 case SCTP_PRIMARY_ADDR:
2613 /* we allow a "get" operation on this */
2615 struct sctp_setprim *ssp;
2618 if (sctp_debug_on & SCTP_DEBUG_USRREQ1) {
2619 printf("setprimary\n");
2621 #endif /* SCTP_DEBUG */
2622 if ((size_t)m->m_len < sizeof(struct sctp_setprim)) {
2626 ssp = mtod(m, struct sctp_setprim *);
2627 if (inp->sctp_flags & SCTP_PCB_FLAGS_CONNECTED) {
2628 SCTP_INP_RLOCK(inp);
2629 stcb = LIST_FIRST(&inp->sctp_asoc_list);
2631 SCTP_TCB_LOCK(stcb);
2632 SCTP_INP_RUNLOCK(inp);
2634 stcb = sctp_findassociation_ep_asocid(inp, ssp->ssp_assoc_id);
2636 /* one last shot, try it by the address in */
2637 struct sctp_nets *net;
2639 SCTP_INP_WLOCK(inp);
2640 SCTP_INP_INCR_REF(inp);
2641 SCTP_INP_WUNLOCK(inp);
2642 stcb = sctp_findassociation_ep_addr(&inp,
2643 (struct sockaddr *)&ssp->ssp_addr,
2646 SCTP_INP_WLOCK(inp);
2647 SCTP_INP_DECR_REF(inp);
2648 SCTP_INP_WUNLOCK(inp);
2656 /* simply copy out the sockaddr_storage... */
2657 memcpy(&ssp->ssp_addr,
2658 &stcb->asoc.primary_destination->ro._l_addr,
2659 ((struct sockaddr *)&stcb->asoc.primary_destination->ro._l_addr)->sa_len);
2660 SCTP_TCB_UNLOCK(stcb);
2661 m->m_len = sizeof(*ssp);
2665 error = ENOPROTOOPT;
2668 } /* end switch (sopt->sopt_name) */
2673 sctp_optsset(struct socket *so,
2676 #if (defined(__FreeBSD__) && __FreeBSD_version >= 500000) || defined(__DragonFly__)
2683 int error, *mopt, set_opt;
2685 struct sctp_tcb *stcb = NULL;
2686 struct sctp_inpcb *inp;
2690 if (sctp_debug_on & SCTP_DEBUG_USRREQ1) {
2691 printf("optsset:MP is NULL EINVAL\n");
2693 #endif /* SCTP_DEBUG */
2700 inp = (struct sctp_inpcb *)so->so_pcb;
2707 case SCTP_AUTOCLOSE:
2708 case SCTP_AUTO_ASCONF:
2709 case SCTP_DISABLE_FRAGMENTS:
2710 case SCTP_I_WANT_MAPPED_V4_ADDR:
2711 /* copy in the option value */
2712 if ((size_t)m->m_len < sizeof(int)) {
2716 mopt = mtod(m, int *);
2721 case SCTP_DISABLE_FRAGMENTS:
2722 set_opt = SCTP_PCB_FLAGS_NO_FRAGMENT;
2724 case SCTP_AUTO_ASCONF:
2725 set_opt = SCTP_PCB_FLAGS_AUTO_ASCONF;
2728 case SCTP_I_WANT_MAPPED_V4_ADDR:
2729 if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) {
2730 set_opt = SCTP_PCB_FLAGS_NEEDS_MAPPED_V4;
2736 set_opt = SCTP_PCB_FLAGS_NODELAY;
2738 case SCTP_AUTOCLOSE:
2739 set_opt = SCTP_PCB_FLAGS_AUTOCLOSE;
2741 * The value is in ticks.
2742 * Note this does not effect old associations, only
2745 inp->sctp_ep.auto_close_time = (*mopt * hz);
2748 SCTP_INP_WLOCK(inp);
2750 inp->sctp_flags |= set_opt;
2752 inp->sctp_flags &= ~set_opt;
2754 SCTP_INP_WUNLOCK(inp);
2756 case SCTP_MY_PUBLIC_KEY: /* set my public key */
2757 case SCTP_SET_AUTH_CHUNKS: /* set the authenticated chunks required */
2758 case SCTP_SET_AUTH_SECRET: /* set the actual secret for the endpoint */
2759 /* not supported yet and until we refine the draft */
2763 case SCTP_CLR_STAT_LOG:
2764 #ifdef SCTP_STAT_LOGGING
2765 sctp_clr_stat_log();
2770 case SCTP_DELAYED_ACK_TIME:
2773 if ((size_t)m->m_len < sizeof(int32_t)) {
2777 tm = mtod(m, int32_t *);
2779 if ((*tm < 10) || (*tm > 500)) {
2780 /* can't be smaller than 10ms */
2781 /* MUST NOT be larger than 500ms */
2785 inp->sctp_ep.sctp_timeoutticks[SCTP_TIMER_RECV] = MSEC_TO_TICKS(*tm);
2788 case SCTP_RESET_STREAMS:
2790 struct sctp_stream_reset *strrst;
2791 uint8_t two_way, not_peer;
2793 if ((size_t)m->m_len < sizeof(struct sctp_stream_reset)) {
2797 strrst = mtod(m, struct sctp_stream_reset *);
2799 if (inp->sctp_flags & SCTP_PCB_FLAGS_CONNECTED) {
2800 SCTP_INP_RLOCK(inp);
2801 stcb = LIST_FIRST(&inp->sctp_asoc_list);
2803 SCTP_TCB_LOCK(stcb);
2804 SCTP_INP_RUNLOCK(inp);
2806 stcb = sctp_findassociation_ep_asocid(inp, strrst->strrst_assoc_id);
2811 if (stcb->asoc.peer_supports_strreset == 0) {
2812 /* Peer does not support it,
2813 * we return protocol not supported since
2814 * this is true for this feature and this
2815 * peer, not the socket request in general.
2817 error = EPROTONOSUPPORT;
2818 SCTP_TCB_UNLOCK(stcb);
2822 /* Having re-thought this code I added as I write the I-D there
2823 * is NO need for it. The peer, if we are requesting a stream-reset
2824 * will send a request to us but will itself do what we do, take
2825 * and copy off the "reset information" we send and queue TSN's
2826 * larger than the send-next in our response message. Thus they
2829 /* if (stcb->asoc.sending_seq != (stcb->asoc.last_acked_seq + 1)) {*/
2830 /* Must have all sending data ack'd before we
2831 * start this procedure. This is a bit restrictive
2832 * and we SHOULD work on changing this so ONLY the
2833 * streams being RESET get held up. So, a reset-all
2834 * would require this.. but a reset specific just
2835 * needs to be sure that the ones being reset have
2836 * nothing on the send_queue. For now we will
2837 * skip this more detailed method and do a course
2838 * way.. i.e. nothing pending ... for future FIX ME!
2844 if (stcb->asoc.stream_reset_outstanding) {
2846 SCTP_TCB_UNLOCK(stcb);
2849 if (strrst->strrst_flags == SCTP_RESET_LOCAL_RECV) {
2852 } else if (strrst->strrst_flags == SCTP_RESET_LOCAL_SEND) {
2855 } else if (strrst->strrst_flags == SCTP_RESET_BOTH) {
2860 SCTP_TCB_UNLOCK(stcb);
2863 sctp_send_str_reset_req(stcb, strrst->strrst_num_streams,
2864 strrst->strrst_list, two_way, not_peer);
2866 sctp_chunk_output(inp, stcb, 12);
2867 SCTP_TCB_UNLOCK(stcb);
2872 case SCTP_RESET_PEGS:
2873 memset(sctp_pegs, 0, sizeof(sctp_pegs));
2876 case SCTP_CONNECT_X:
2877 if ((size_t)m->m_len < (sizeof(int) + sizeof(struct sockaddr_in))) {
2881 error = sctp_do_connect_x(so, inp, m, p, 0);
2884 case SCTP_CONNECT_X_DELAYED:
2885 if ((size_t)m->m_len < (sizeof(int) + sizeof(struct sockaddr_in))) {
2889 error = sctp_do_connect_x(so, inp, m, p, 1);
2892 case SCTP_CONNECT_X_COMPLETE:
2894 struct sockaddr *sa;
2895 struct sctp_nets *net;
2896 if ((size_t)m->m_len < sizeof(struct sockaddr_in)) {
2900 sa = mtod(m, struct sockaddr *);
2902 if (inp->sctp_flags & SCTP_PCB_FLAGS_CONNECTED) {
2903 SCTP_INP_RLOCK(inp);
2904 stcb = LIST_FIRST(&inp->sctp_asoc_list);
2906 SCTP_TCB_LOCK(stcb);
2907 net = sctp_findnet(stcb, sa);
2909 SCTP_INP_RUNLOCK(inp);
2911 SCTP_INP_WLOCK(inp);
2912 SCTP_INP_INCR_REF(inp);
2913 SCTP_INP_WUNLOCK(inp);
2914 stcb = sctp_findassociation_ep_addr(&inp, sa, &net, NULL, NULL);
2916 SCTP_INP_WLOCK(inp);
2917 SCTP_INP_DECR_REF(inp);
2918 SCTP_INP_WUNLOCK(inp);
2926 if (stcb->asoc.delayed_connection == 1) {
2927 stcb->asoc.delayed_connection = 0;
2928 SCTP_GETTIME_TIMEVAL(&stcb->asoc.time_entered);
2929 sctp_timer_stop(SCTP_TIMER_TYPE_INIT, inp, stcb, stcb->asoc.primary_destination);
2930 sctp_send_initiate(inp, stcb);
2932 /* already expired or did not use delayed connectx */
2935 SCTP_TCB_UNLOCK(stcb);
2941 SCTP_INP_WLOCK(inp);
2942 burst = mtod(m, u_int8_t *);
2944 inp->sctp_ep.max_burst = *burst;
2946 SCTP_INP_WUNLOCK(inp);
2953 if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) {
2954 ovh = SCTP_MED_OVERHEAD;
2956 ovh = SCTP_MED_V4_OVERHEAD;
2958 segsize = mtod(m, u_int32_t *);
2963 SCTP_INP_WLOCK(inp);
2964 inp->sctp_frag_point = (*segsize+ovh);
2965 if (inp->sctp_frag_point < MHLEN) {
2966 inp->sctp_frag_point = MHLEN;
2968 SCTP_INP_WUNLOCK(inp);
2971 case SCTP_SET_DEBUG_LEVEL:
2975 if ((size_t)m->m_len < sizeof(u_int32_t)) {
2979 level = mtod(m, u_int32_t *);
2981 sctp_debug_on = (*level & (SCTP_DEBUG_ALL |
2983 printf("SETTING DEBUG LEVEL to %x\n",
2984 (u_int)sctp_debug_on);
2989 #endif /* SCTP_DEBUG */
2993 struct sctp_event_subscribe *events;
2994 if ((size_t)m->m_len < sizeof(struct sctp_event_subscribe)) {
2998 SCTP_INP_WLOCK(inp);
2999 events = mtod(m, struct sctp_event_subscribe *);
3000 if (events->sctp_data_io_event) {
3001 inp->sctp_flags |= SCTP_PCB_FLAGS_RECVDATAIOEVNT;
3003 inp->sctp_flags &= ~SCTP_PCB_FLAGS_RECVDATAIOEVNT;
3006 if (events->sctp_association_event) {
3007 inp->sctp_flags |= SCTP_PCB_FLAGS_RECVASSOCEVNT;
3009 inp->sctp_flags &= ~SCTP_PCB_FLAGS_RECVASSOCEVNT;
3012 if (events->sctp_address_event) {
3013 inp->sctp_flags |= SCTP_PCB_FLAGS_RECVPADDREVNT;
3015 inp->sctp_flags &= ~SCTP_PCB_FLAGS_RECVPADDREVNT;
3018 if (events->sctp_send_failure_event) {
3019 inp->sctp_flags |= SCTP_PCB_FLAGS_RECVSENDFAILEVNT;
3021 inp->sctp_flags &= ~SCTP_PCB_FLAGS_RECVSENDFAILEVNT;
3024 if (events->sctp_peer_error_event) {
3025 inp->sctp_flags |= SCTP_PCB_FLAGS_RECVPEERERR;
3027 inp->sctp_flags &= ~SCTP_PCB_FLAGS_RECVPEERERR;
3030 if (events->sctp_shutdown_event) {
3031 inp->sctp_flags |= SCTP_PCB_FLAGS_RECVSHUTDOWNEVNT;
3033 inp->sctp_flags &= ~SCTP_PCB_FLAGS_RECVSHUTDOWNEVNT;
3036 if (events->sctp_partial_delivery_event) {
3037 inp->sctp_flags |= SCTP_PCB_FLAGS_PDAPIEVNT;
3039 inp->sctp_flags &= ~SCTP_PCB_FLAGS_PDAPIEVNT;
3042 if (events->sctp_adaption_layer_event) {
3043 inp->sctp_flags |= SCTP_PCB_FLAGS_ADAPTIONEVNT;
3045 inp->sctp_flags &= ~SCTP_PCB_FLAGS_ADAPTIONEVNT;
3048 if (events->sctp_stream_reset_events) {
3049 inp->sctp_flags |= SCTP_PCB_FLAGS_STREAM_RESETEVNT;
3051 inp->sctp_flags &= ~SCTP_PCB_FLAGS_STREAM_RESETEVNT;
3053 SCTP_INP_WUNLOCK(inp);
3057 case SCTP_ADAPTION_LAYER:
3059 struct sctp_setadaption *adap_bits;
3060 if ((size_t)m->m_len < sizeof(struct sctp_setadaption)) {
3064 SCTP_INP_WLOCK(inp);
3065 adap_bits = mtod(m, struct sctp_setadaption *);
3066 inp->sctp_ep.adaption_layer_indicator = adap_bits->ssb_adaption_ind;
3067 SCTP_INP_WUNLOCK(inp);
3070 case SCTP_SET_INITIAL_DBG_SEQ:
3073 if ((size_t)m->m_len < sizeof(u_int32_t)) {
3077 SCTP_INP_WLOCK(inp);
3078 vvv = mtod(m, u_int32_t *);
3079 inp->sctp_ep.initial_sequence_debug = *vvv;
3080 SCTP_INP_WUNLOCK(inp);
3083 case SCTP_DEFAULT_SEND_PARAM:
3085 struct sctp_sndrcvinfo *s_info;
3087 if (m->m_len != sizeof(struct sctp_sndrcvinfo)) {
3091 s_info = mtod(m, struct sctp_sndrcvinfo *);
3093 if (inp->sctp_flags & SCTP_PCB_FLAGS_CONNECTED) {
3094 SCTP_INP_RLOCK(inp);
3095 stcb = LIST_FIRST(&inp->sctp_asoc_list);
3097 SCTP_TCB_LOCK(stcb);
3098 SCTP_INP_RUNLOCK(inp);
3100 stcb = sctp_findassociation_ep_asocid(inp, s_info->sinfo_assoc_id);
3106 /* Validate things */
3107 if (s_info->sinfo_stream > stcb->asoc.streamoutcnt) {
3108 SCTP_TCB_UNLOCK(stcb);
3112 /* Mask off the flags that are allowed */
3113 s_info->sinfo_flags = (s_info->sinfo_flags &
3114 (MSG_UNORDERED | MSG_ADDR_OVER |
3115 MSG_PR_SCTP_TTL | MSG_PR_SCTP_BUF));
3117 stcb->asoc.def_send = *s_info;
3118 SCTP_TCB_UNLOCK(stcb);
3121 case SCTP_PEER_ADDR_PARAMS:
3123 struct sctp_paddrparams *paddrp;
3124 struct sctp_nets *net;
3125 if ((size_t)m->m_len < sizeof(struct sctp_paddrparams)) {
3129 paddrp = mtod(m, struct sctp_paddrparams *);
3131 if (paddrp->spp_assoc_id) {
3132 if (inp->sctp_flags & SCTP_PCB_FLAGS_CONNECTED) {
3133 SCTP_INP_RLOCK(inp);
3134 stcb = LIST_FIRST(&inp->sctp_asoc_list);
3136 SCTP_TCB_LOCK(stcb);
3137 net = sctp_findnet(stcb, (struct sockaddr *)&paddrp->spp_address);
3139 SCTP_INP_RUNLOCK(inp);
3141 stcb = sctp_findassociation_ep_asocid(inp, paddrp->spp_assoc_id);
3148 if ((stcb == NULL) &&
3149 ((((struct sockaddr *)&paddrp->spp_address)->sa_family == AF_INET) ||
3150 (((struct sockaddr *)&paddrp->spp_address)->sa_family == AF_INET6))) {
3151 /* Lookup via address */
3152 if (inp->sctp_flags & SCTP_PCB_FLAGS_CONNECTED) {
3153 SCTP_INP_RLOCK(inp);
3154 stcb = LIST_FIRST(&inp->sctp_asoc_list);
3156 SCTP_TCB_LOCK(stcb);
3157 net = sctp_findnet(stcb,
3158 (struct sockaddr *)&paddrp->spp_address);
3160 SCTP_INP_RUNLOCK(inp);
3162 SCTP_INP_WLOCK(inp);
3163 SCTP_INP_INCR_REF(inp);
3164 SCTP_INP_WUNLOCK(inp);
3165 stcb = sctp_findassociation_ep_addr(&inp,
3166 (struct sockaddr *)&paddrp->spp_address,
3169 SCTP_INP_WLOCK(inp);
3170 SCTP_INP_DECR_REF(inp);
3171 SCTP_INP_WUNLOCK(inp);
3175 /* Effects the Endpoint */
3179 /* Applies to the specific association */
3180 if (paddrp->spp_pathmaxrxt) {
3182 if (paddrp->spp_pathmaxrxt)
3183 net->failure_threshold = paddrp->spp_pathmaxrxt;
3185 if (paddrp->spp_pathmaxrxt)
3186 stcb->asoc.def_net_failure = paddrp->spp_pathmaxrxt;
3189 if ((paddrp->spp_hbinterval != 0) && (paddrp->spp_hbinterval != 0xffffffff)) {
3193 net->dest_state &= ~SCTP_ADDR_NOHB;
3195 old = stcb->asoc.heart_beat_delay;
3196 stcb->asoc.heart_beat_delay = paddrp->spp_hbinterval;
3198 /* Turn back on the timer */
3199 sctp_timer_start(SCTP_TIMER_TYPE_HEARTBEAT, inp, stcb, net);
3202 } else if (paddrp->spp_hbinterval == 0xffffffff) {
3204 sctp_send_hb(stcb, 1, net);
3207 /* off on association */
3208 if (stcb->asoc.heart_beat_delay) {
3209 int cnt_of_unconf = 0;
3210 struct sctp_nets *lnet;
3211 TAILQ_FOREACH(lnet, &stcb->asoc.nets, sctp_next) {
3212 if (lnet->dest_state & SCTP_ADDR_UNCONFIRMED) {
3216 /* stop the timer ONLY if we have no unconfirmed addresses
3218 if (cnt_of_unconf == 0)
3219 sctp_timer_stop(SCTP_TIMER_TYPE_HEARTBEAT, inp, stcb, net);
3221 stcb->asoc.heart_beat_delay = 0;
3223 net->dest_state |= SCTP_ADDR_NOHB;
3226 SCTP_TCB_UNLOCK(stcb);
3228 /* Use endpoint defaults */
3229 SCTP_INP_WLOCK(inp);
3230 if (paddrp->spp_pathmaxrxt)
3231 inp->sctp_ep.def_net_failure = paddrp->spp_pathmaxrxt;
3232 if (paddrp->spp_hbinterval != SCTP_ISSUE_HB)
3233 inp->sctp_ep.sctp_timeoutticks[SCTP_TIMER_HEARTBEAT] = paddrp->spp_hbinterval;
3234 SCTP_INP_WUNLOCK(inp);
3240 struct sctp_rtoinfo *srto;
3241 if ((size_t)m->m_len < sizeof(struct sctp_rtoinfo)) {
3245 srto = mtod(m, struct sctp_rtoinfo *);
3246 if (srto->srto_assoc_id == 0) {
3247 SCTP_INP_WLOCK(inp);
3248 /* If we have a null asoc, its default for the endpoint */
3249 if (srto->srto_initial > 10)
3250 inp->sctp_ep.initial_rto = srto->srto_initial;
3251 if (srto->srto_max > 10)
3252 inp->sctp_ep.sctp_maxrto = srto->srto_max;
3253 if (srto->srto_min > 10)
3254 inp->sctp_ep.sctp_minrto = srto->srto_min;
3255 SCTP_INP_WUNLOCK(inp);
3258 if (inp->sctp_flags & SCTP_PCB_FLAGS_CONNECTED) {
3259 SCTP_INP_RLOCK(inp);
3260 stcb = LIST_FIRST(&inp->sctp_asoc_list);
3262 SCTP_TCB_LOCK(stcb);
3263 SCTP_INP_RUNLOCK(inp);
3265 stcb = sctp_findassociation_ep_asocid(inp, srto->srto_assoc_id);
3270 /* Set in ms we hope :-) */
3271 if (srto->srto_initial > 10)
3272 stcb->asoc.initial_rto = srto->srto_initial;
3273 if (srto->srto_max > 10)
3274 stcb->asoc.maxrto = srto->srto_max;
3275 if (srto->srto_min > 10)
3276 stcb->asoc.minrto = srto->srto_min;
3277 SCTP_TCB_UNLOCK(stcb);
3280 case SCTP_ASSOCINFO:
3282 struct sctp_assocparams *sasoc;
3284 if ((size_t)m->m_len < sizeof(struct sctp_assocparams)) {
3288 sasoc = mtod(m, struct sctp_assocparams *);
3289 if (sasoc->sasoc_assoc_id) {
3290 if (inp->sctp_flags & SCTP_PCB_FLAGS_CONNECTED) {
3291 SCTP_INP_RLOCK(inp);
3292 stcb = LIST_FIRST(&inp->sctp_asoc_list);
3294 SCTP_TCB_LOCK(stcb);
3295 SCTP_INP_RUNLOCK(inp);
3297 stcb = sctp_findassociation_ep_asocid(inp,
3298 sasoc->sasoc_assoc_id);
3308 if (sasoc->sasoc_asocmaxrxt)
3309 stcb->asoc.max_send_times = sasoc->sasoc_asocmaxrxt;
3310 sasoc->sasoc_number_peer_destinations = stcb->asoc.numnets;
3311 sasoc->sasoc_peer_rwnd = 0;
3312 sasoc->sasoc_local_rwnd = 0;
3313 if (stcb->asoc.cookie_life)
3314 stcb->asoc.cookie_life = sasoc->sasoc_cookie_life;
3315 SCTP_TCB_UNLOCK(stcb);
3317 SCTP_INP_WLOCK(inp);
3318 if (sasoc->sasoc_asocmaxrxt)
3319 inp->sctp_ep.max_send_times = sasoc->sasoc_asocmaxrxt;
3320 sasoc->sasoc_number_peer_destinations = 0;
3321 sasoc->sasoc_peer_rwnd = 0;
3322 sasoc->sasoc_local_rwnd = 0;
3323 if (sasoc->sasoc_cookie_life)
3324 inp->sctp_ep.def_cookie_life = sasoc->sasoc_cookie_life;
3325 SCTP_INP_WUNLOCK(inp);
3331 struct sctp_initmsg *sinit;
3333 if ((size_t)m->m_len < sizeof(struct sctp_initmsg)) {
3337 sinit = mtod(m, struct sctp_initmsg *);
3338 SCTP_INP_WLOCK(inp);
3339 if (sinit->sinit_num_ostreams)
3340 inp->sctp_ep.pre_open_stream_count = sinit->sinit_num_ostreams;
3342 if (sinit->sinit_max_instreams)
3343 inp->sctp_ep.max_open_streams_intome = sinit->sinit_max_instreams;
3345 if (sinit->sinit_max_attempts)
3346 inp->sctp_ep.max_init_times = sinit->sinit_max_attempts;
3348 if (sinit->sinit_max_init_timeo > 10)
3349 /* We must be at least a 100ms (we set in ticks) */
3350 inp->sctp_ep.initial_init_rto_max = sinit->sinit_max_init_timeo;
3351 SCTP_INP_WUNLOCK(inp);
3354 case SCTP_PRIMARY_ADDR:
3356 struct sctp_setprim *spa;
3357 struct sctp_nets *net, *lnet;
3358 if ((size_t)m->m_len < sizeof(struct sctp_setprim)) {
3362 spa = mtod(m, struct sctp_setprim *);
3364 if (inp->sctp_flags & SCTP_PCB_FLAGS_CONNECTED) {
3365 SCTP_INP_RLOCK(inp);
3366 stcb = LIST_FIRST(&inp->sctp_asoc_list);
3368 SCTP_TCB_LOCK(stcb);
3373 SCTP_INP_RUNLOCK(inp);
3375 stcb = sctp_findassociation_ep_asocid(inp, spa->ssp_assoc_id);
3378 SCTP_INP_WLOCK(inp);
3379 SCTP_INP_INCR_REF(inp);
3380 SCTP_INP_WUNLOCK(inp);
3381 stcb = sctp_findassociation_ep_addr(&inp,
3382 (struct sockaddr *)&spa->ssp_addr,
3385 SCTP_INP_WLOCK(inp);
3386 SCTP_INP_DECR_REF(inp);
3387 SCTP_INP_WUNLOCK(inp);
3392 /* find the net, associd or connected lookup type */
3393 net = sctp_findnet(stcb, (struct sockaddr *)&spa->ssp_addr);
3395 SCTP_TCB_UNLOCK(stcb);
3400 if ((net != stcb->asoc.primary_destination) &&
3401 (!(net->dest_state & SCTP_ADDR_UNCONFIRMED))) {
3402 /* Ok we need to set it */
3403 lnet = stcb->asoc.primary_destination;
3404 lnet->next_tsn_at_change = net->next_tsn_at_change = stcb->asoc.sending_seq;
3405 if (sctp_set_primary_addr(stcb,
3406 (struct sockaddr *)NULL,
3408 if (net->dest_state & SCTP_ADDR_SWITCH_PRIMARY) {
3409 net->dest_state |= SCTP_ADDR_DOUBLE_SWITCH;
3411 net->dest_state |= SCTP_ADDR_SWITCH_PRIMARY;
3414 SCTP_TCB_UNLOCK(stcb);
3418 case SCTP_SET_PEER_PRIMARY_ADDR:
3420 struct sctp_setpeerprim *sspp;
3421 if ((size_t)m->m_len < sizeof(struct sctp_setpeerprim)) {
3425 sspp = mtod(m, struct sctp_setpeerprim *);
3428 if (inp->sctp_flags & SCTP_PCB_FLAGS_CONNECTED) {
3429 SCTP_INP_RLOCK(inp);
3430 stcb = LIST_FIRST(&inp->sctp_asoc_list);
3432 SCTP_TCB_UNLOCK(stcb);
3433 SCTP_INP_RUNLOCK(inp);
3435 stcb = sctp_findassociation_ep_asocid(inp, sspp->sspp_assoc_id);
3440 if (sctp_set_primary_ip_address_sa(stcb, (struct sockaddr *)&sspp->sspp_addr) != 0) {
3443 SCTP_TCB_UNLOCK(stcb);
3446 case SCTP_BINDX_ADD_ADDR:
3448 struct sctp_getaddresses *addrs;
3449 struct sockaddr *addr_touse;
3450 struct sockaddr_in sin;
3451 /* see if we're bound all already! */
3452 if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUNDALL) {
3456 if ((size_t)m->m_len < sizeof(struct sctp_getaddresses)) {
3460 addrs = mtod(m, struct sctp_getaddresses *);
3461 addr_touse = addrs->addr;
3462 if (addrs->addr->sa_family == AF_INET6) {
3463 struct sockaddr_in6 *sin6;
3464 sin6 = (struct sockaddr_in6 *)addr_touse;
3465 if (IN6_IS_ADDR_V4MAPPED(&sin6->sin6_addr)) {
3466 in6_sin6_2_sin(&sin, sin6);
3467 addr_touse = (struct sockaddr *)&sin;
3470 if (inp->sctp_flags & SCTP_PCB_FLAGS_UNBOUND) {
3472 /* Can't get proc for Net/Open BSD */
3476 error = sctp_inpcb_bind(so, addr_touse, p);
3479 /* No locks required here since bind and mgmt_ep_sa all
3480 * do their own locking. If we do something for the FIX:
3481 * below we may need to lock in that case.
3483 if (addrs->sget_assoc_id == 0) {
3484 /* add the address */
3485 struct sctp_inpcb *lep;
3486 ((struct sockaddr_in *)addr_touse)->sin_port = inp->sctp_lport;
3487 lep = sctp_pcb_findep(addr_touse, 1, 0);
3489 /* We must decrement the refcount
3490 * since we have the ep already and
3491 * are binding. No remove going on
3494 SCTP_INP_WLOCK(inp);
3495 SCTP_INP_DECR_REF(inp);
3496 SCTP_INP_WUNLOCK(inp);
3499 /* already bound to it.. ok */
3501 } else if (lep == NULL) {
3502 ((struct sockaddr_in *)addr_touse)->sin_port = 0;
3503 error = sctp_addr_mgmt_ep_sa(inp, addr_touse,
3504 SCTP_ADD_IP_ADDRESS);
3506 error = EADDRNOTAVAIL;
3512 /* FIX: decide whether we allow assoc based bindx */
3516 case SCTP_BINDX_REM_ADDR:
3518 struct sctp_getaddresses *addrs;
3519 struct sockaddr *addr_touse;
3520 struct sockaddr_in sin;
3521 /* see if we're bound all already! */
3522 if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUNDALL) {
3526 if ((size_t)m->m_len < sizeof(struct sctp_getaddresses)) {
3530 addrs = mtod(m, struct sctp_getaddresses *);
3531 addr_touse = addrs->addr;
3532 if (addrs->addr->sa_family == AF_INET6) {
3533 struct sockaddr_in6 *sin6;
3534 sin6 = (struct sockaddr_in6 *)addr_touse;
3535 if (IN6_IS_ADDR_V4MAPPED(&sin6->sin6_addr)) {
3536 in6_sin6_2_sin(&sin, sin6);
3537 addr_touse = (struct sockaddr *)&sin;
3540 /* No lock required mgmt_ep_sa does its own locking. If
3541 * the FIX: below is ever changed we may need to
3542 * lock before calling association level binding.
3544 if (addrs->sget_assoc_id == 0) {
3545 /* delete the address */
3546 sctp_addr_mgmt_ep_sa(inp, addr_touse,
3547 SCTP_DEL_IP_ADDRESS);
3549 /* FIX: decide whether we allow assoc based bindx */
3554 error = ENOPROTOOPT;
3556 } /* end switch (opt) */
3561 #if defined(__FreeBSD__) || defined(__APPLE__) || defined(__DragonFly__)
3563 sctp_ctloutput(struct socket *so, struct sockopt *sopt)
3565 struct mbuf *m = NULL;
3566 struct sctp_inpcb *inp;
3569 inp = (struct sctp_inpcb *)so->so_pcb;
3573 /* I made the same as TCP since we are not setup? */
3574 return (ECONNRESET);
3576 if (sopt->sopt_level != IPPROTO_SCTP) {
3577 /* wrong proto level... send back up to IP */
3579 if (INP_CHECK_SOCKAF(so, AF_INET6))
3580 error = ip6_ctloutput(so, sopt);
3583 error = ip_ctloutput(so, sopt);
3587 if (sopt->sopt_valsize > MCLBYTES) {
3589 * Restrict us down to a cluster size, that's all we can
3590 * pass either way...
3592 sopt->sopt_valsize = MCLBYTES;
3594 if (sopt->sopt_valsize) {
3596 m = m_get(MB_WAIT, MT_DATA);
3597 if (sopt->sopt_valsize > MLEN) {
3598 MCLGET(m, MB_DONTWAIT);
3599 if ((m->m_flags & M_EXT) == 0) {
3605 error = sooptcopyin(sopt, mtod(m, caddr_t), sopt->sopt_valsize,
3606 sopt->sopt_valsize);
3611 m->m_len = sopt->sopt_valsize;
3613 if (sopt->sopt_dir == SOPT_SET) {
3614 #if (defined(__FreeBSD__) && __FreeBSD_version >= 500000) || defined(__DragonFly__)
3615 error = sctp_optsset(so, sopt->sopt_name, &m, sopt->sopt_td);
3617 error = sctp_optsset(so, sopt->sopt_name, &m, sopt->sopt_p);
3619 } else if (sopt->sopt_dir == SOPT_GET) {
3620 #if (defined (__FreeBSD__) && __FreeBSD_version >= 500000) || defined(__DragonFly__)
3621 error = sctp_optsget(so, sopt->sopt_name, &m, sopt->sopt_td);
3623 error = sctp_optsget(so, sopt->sopt_name, &m, sopt->sopt_p);
3628 if ( (error == 0) && (m != NULL)) {
3629 error = sooptcopyout(sopt, mtod(m, caddr_t), m->m_len);
3631 } else if (m != NULL) {
3640 /* NetBSD and OpenBSD */
3642 sctp_ctloutput(int op, struct socket *so, int level, int optname,
3648 struct in6pcb *in6p;
3650 int family; /* family of the socket */
3652 family = so->so_proto->pr_domain->dom_family;
3657 inp = sotoinpcb(so);
3665 in6p = sotoin6pcb(so);
3670 return EAFNOSUPPORT;
3675 if (inp == NULL && in6p == NULL)
3679 if (op == PRCO_SETOPT && *mp)
3681 return (ECONNRESET);
3683 if (level != IPPROTO_SCTP) {
3686 error = ip_ctloutput(op, so, level, optname, mp);
3690 error = ip6_ctloutput(op, so, level, optname, mp);
3697 /* Ok if we reach here it is a SCTP option we hope */
3698 if (op == PRCO_SETOPT) {
3699 error = sctp_optsset(so, optname, mp, (struct proc *)NULL);
3702 } else if (op == PRCO_GETOPT) {
3703 error = sctp_optsget(so, optname, mp, (struct proc *)NULL);
3714 #if (defined(__FreeBSD__) && __FreeBSD_version >= 500000) || defined(__DragonFly__)
3715 sctp_connect(struct socket *so, struct sockaddr *addr, struct thread *p)
3718 #if defined(__FreeBSD__) || defined(__APPLE__)
3719 sctp_connect(struct socket *so, struct sockaddr *addr, struct proc *p)
3722 sctp_connect(struct socket *so, struct mbuf *nam, struct proc *p)
3724 struct sockaddr *addr = mtod(nam, struct sockaddr *);
3728 struct sctp_inpcb *inp;
3729 struct sctp_tcb *stcb;
3732 if (sctp_debug_on & SCTP_DEBUG_PCB1) {
3733 printf("Connect called in SCTP to ");
3734 sctp_print_address(addr);
3735 printf("Port %d\n", ntohs(((struct sockaddr_in *)addr)->sin_port));
3737 #endif /* SCTP_DEBUG */
3739 inp = (struct sctp_inpcb *)so->so_pcb;
3742 /* I made the same as TCP since we are not setup? */
3743 return (ECONNRESET);
3745 SCTP_ASOC_CREATE_LOCK(inp);
3746 SCTP_INP_WLOCK(inp);
3747 if ((inp->sctp_flags & SCTP_PCB_FLAGS_SOCKET_GONE) ||
3748 (inp->sctp_flags & SCTP_PCB_FLAGS_SOCKET_GONE)) {
3749 /* Should I really unlock ? */
3750 SCTP_INP_WUNLOCK(inp);
3751 SCTP_ASOC_CREATE_UNLOCK(inp);
3756 if (((inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) == 0) &&
3757 (addr->sa_family == AF_INET6)) {
3758 SCTP_INP_WUNLOCK(inp);
3759 SCTP_ASOC_CREATE_UNLOCK(inp);
3764 if ((inp->sctp_flags & SCTP_PCB_FLAGS_UNBOUND) ==
3765 SCTP_PCB_FLAGS_UNBOUND) {
3766 /* Bind a ephemeral port */
3767 SCTP_INP_WUNLOCK(inp);
3768 error = sctp_inpcb_bind(so, NULL, p);
3770 SCTP_ASOC_CREATE_UNLOCK(inp);
3774 SCTP_INP_WLOCK(inp);
3776 /* Now do we connect? */
3777 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) &&
3778 (inp->sctp_flags & SCTP_PCB_FLAGS_CONNECTED)) {
3779 /* We are already connected AND the TCP model */
3781 SCTP_INP_WUNLOCK(inp);
3782 SCTP_ASOC_CREATE_UNLOCK(inp);
3783 return (EADDRINUSE);
3785 if (inp->sctp_flags & SCTP_PCB_FLAGS_CONNECTED) {
3786 stcb = LIST_FIRST(&inp->sctp_asoc_list);
3788 SCTP_TCB_UNLOCK(stcb);
3789 SCTP_INP_WUNLOCK(inp);
3791 SCTP_INP_INCR_REF(inp);
3792 SCTP_INP_WUNLOCK(inp);
3793 stcb = sctp_findassociation_ep_addr(&inp, addr, NULL, NULL, NULL);
3795 SCTP_INP_WLOCK(inp);
3796 SCTP_INP_DECR_REF(inp);
3797 SCTP_INP_WUNLOCK(inp);
3801 /* Already have or am bring up an association */
3802 SCTP_ASOC_CREATE_UNLOCK(inp);
3803 SCTP_TCB_UNLOCK(stcb);
3807 /* We are GOOD to go */
3808 stcb = sctp_aloc_assoc(inp, addr, 1, &error, 0);
3810 /* Gak! no memory */
3814 if (stcb->sctp_ep->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) {
3815 stcb->sctp_ep->sctp_flags |= SCTP_PCB_FLAGS_CONNECTED;
3816 /* Set the connected flag so we can queue data */
3819 stcb->asoc.state = SCTP_STATE_COOKIE_WAIT;
3820 SCTP_GETTIME_TIMEVAL(&stcb->asoc.time_entered);
3821 sctp_send_initiate(inp, stcb);
3822 SCTP_ASOC_CREATE_UNLOCK(inp);
3823 SCTP_TCB_UNLOCK(stcb);
3829 sctp_usr_recvd(struct socket *so, int flags)
3831 struct sctp_socket_q_list *sq=NULL;
3833 * The user has received some data, we may be able to stuff more
3834 * up the socket. And we need to possibly update the rwnd.
3836 struct sctp_inpcb *inp;
3837 struct sctp_tcb *stcb=NULL;
3839 inp = (struct sctp_inpcb *)so->so_pcb;
3841 if (sctp_debug_on & SCTP_DEBUG_USRREQ2)
3842 printf("Read for so:%x inp:%x Flags:%x\n",
3843 (u_int)so, (u_int)inp, (u_int)flags);
3847 /* I made the same as TCP since we are not setup? */
3849 if (sctp_debug_on & SCTP_DEBUG_USRREQ2)
3850 printf("Nope, connection reset\n");
3852 return (ECONNRESET);
3856 * Grab the first one on the list. It will re-insert itself if
3857 * it runs out of room
3859 SCTP_INP_WLOCK(inp);
3860 if ((flags & MSG_EOR) && ((inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) == 0)
3861 && ((inp->sctp_flags & SCTP_PCB_FLAGS_CONNECTED) == 0)) {
3862 /* Ok the other part of our grubby tracking
3863 * stuff for our horrible layer violation that
3864 * the tsvwg thinks is ok for sctp_peeloff.. gak!
3865 * We must update the next vtag pending on the
3866 * socket buffer (if any).
3868 inp->sctp_vtag_first = sctp_get_first_vtag_from_sb(so);
3869 sq = TAILQ_FIRST(&inp->sctp_queue_list);
3876 stcb = LIST_FIRST(&inp->sctp_asoc_list);
3879 SCTP_TCB_LOCK(stcb);
3882 /* all code in normal stcb path assumes
3883 * that you have a tcb_lock only. Thus
3884 * we must release the inp write lock.
3886 if (flags & MSG_EOR) {
3887 if (((inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) == 0)
3888 && ((inp->sctp_flags & SCTP_PCB_FLAGS_CONNECTED) == 0)) {
3889 stcb = sctp_remove_from_socket_q(inp);
3892 if (sctp_debug_on & SCTP_DEBUG_USRREQ2)
3893 printf("remove from socket queue for inp:%x tcbret:%x\n",
3894 (u_int)inp, (u_int)stcb);
3897 stcb->asoc.my_rwnd_control_len = sctp_sbspace_sub(stcb->asoc.my_rwnd_control_len,
3898 sizeof(struct mbuf));
3899 if (inp->sctp_flags & SCTP_PCB_FLAGS_RECVDATAIOEVNT) {
3900 stcb->asoc.my_rwnd_control_len = sctp_sbspace_sub(stcb->asoc.my_rwnd_control_len,
3901 CMSG_LEN(sizeof(struct sctp_sndrcvinfo)));
3904 if ((TAILQ_EMPTY(&stcb->asoc.delivery_queue) == 0) ||
3905 (TAILQ_EMPTY(&stcb->asoc.reasmqueue) == 0)) {
3906 /* Deliver if there is something to be delivered */
3907 sctp_service_queues(stcb, &stcb->asoc, 1);
3909 sctp_set_rwnd(stcb, &stcb->asoc);
3910 /* if we increase by 1 or more MTU's (smallest MTUs of all
3911 * nets) we send a window update sack
3913 incr = stcb->asoc.my_rwnd - stcb->asoc.my_last_reported_rwnd;
3917 if (((uint32_t)incr >= (stcb->asoc.smallest_mtu * SCTP_SEG_TO_RWND_UPD)) ||
3918 ((((uint32_t)incr)*SCTP_SCALE_OF_RWND_TO_UPD) >= so->so_rcv.sb_hiwat)) {
3919 if (callout_pending(&stcb->asoc.dack_timer.timer)) {
3920 /* If the timer is up, stop it */
3921 sctp_timer_stop(SCTP_TIMER_TYPE_RECV,
3922 stcb->sctp_ep, stcb, NULL);
3924 /* Send the sack, with the new rwnd */
3925 sctp_send_sack(stcb);
3926 /* Now do the output */
3927 sctp_chunk_output(inp, stcb, 10);
3930 if ((( sq ) && (flags & MSG_EOR) && ((inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) == 0))
3931 && ((inp->sctp_flags & SCTP_PCB_FLAGS_CONNECTED) == 0)) {
3932 stcb = sctp_remove_from_socket_q(inp);
3935 SOCKBUF_LOCK(&so->so_rcv);
3936 if (( so->so_rcv.sb_mb == NULL ) &&
3937 (TAILQ_EMPTY(&inp->sctp_queue_list) == 0)) {
3940 if (sctp_debug_on & SCTP_DEBUG_USRREQ2)
3941 printf("Something off, inp:%x so->so_rcv->sb_mb is empty and sockq is not.. cleaning\n",
3944 if (((inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) == 0)
3945 && ((inp->sctp_flags & SCTP_PCB_FLAGS_CONNECTED) == 0)) {
3947 done_yet = TAILQ_EMPTY(&inp->sctp_queue_list);
3950 sctp_remove_from_socket_q(inp);
3951 done_yet = TAILQ_EMPTY(&inp->sctp_queue_list);
3955 if (sctp_debug_on & SCTP_DEBUG_USRREQ2)
3956 printf("Cleaned up %d sockq's\n", sq_cnt);
3959 SOCKBUF_UNLOCK(&so->so_rcv);
3961 SCTP_TCB_UNLOCK(stcb);
3962 SCTP_INP_WUNLOCK(inp);
3968 #if (defined(__FreeBSD__) && __FreeBSD_version >= 500000) || defined(__DragonFly__)
3969 sctp_listen(struct socket *so, struct thread *p)
3971 sctp_listen(struct socket *so, struct proc *p)
3975 * Note this module depends on the protocol processing being
3976 * called AFTER any socket level flags and backlog are applied
3977 * to the socket. The traditional way that the socket flags are
3978 * applied is AFTER protocol processing. We have made a change
3979 * to the sys/kern/uipc_socket.c module to reverse this but this
3980 * MUST be in place if the socket API for SCTP is to work properly.
3983 struct sctp_inpcb *inp;
3986 inp = (struct sctp_inpcb *)so->so_pcb;
3989 /* I made the same as TCP since we are not setup? */
3990 return (ECONNRESET);
3992 SCTP_INP_RLOCK(inp);
3993 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) &&
3994 (inp->sctp_flags & SCTP_PCB_FLAGS_CONNECTED)) {
3995 /* We are already connected AND the TCP model */
3997 SCTP_INP_RUNLOCK(inp);
3998 return (EADDRINUSE);
4000 if (inp->sctp_flags & SCTP_PCB_FLAGS_UNBOUND) {
4001 /* We must do a bind. */
4002 SCTP_INP_RUNLOCK(inp);
4003 if ((error = sctp_inpcb_bind(so, NULL, p))) {
4004 /* bind error, probably perm */
4009 SCTP_INP_RUNLOCK(inp);
4012 SCTP_INP_WLOCK(inp);
4013 if (inp->sctp_socket->so_qlimit) {
4014 if (inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) {
4016 * For the UDP model we must TURN OFF the ACCEPT
4017 * flags since we do NOT allow the accept() call.
4018 * The TCP model (when present) will do accept which
4019 * then prohibits connect().
4021 inp->sctp_socket->so_options &= ~SO_ACCEPTCONN;
4023 inp->sctp_flags |= SCTP_PCB_FLAGS_ACCEPTING;
4025 if (inp->sctp_flags & SCTP_PCB_FLAGS_ACCEPTING) {
4027 * Turning off the listen flags if the backlog is
4028 * set to 0 (i.e. qlimit is 0).
4030 inp->sctp_flags &= ~SCTP_PCB_FLAGS_ACCEPTING;
4032 inp->sctp_socket->so_options &= ~SO_ACCEPTCONN;
4034 SCTP_INP_WUNLOCK(inp);
4041 #if defined(__FreeBSD__) || defined(__APPLE__) || defined(__DragonFly__)
4042 sctp_accept(struct socket *so, struct sockaddr **addr)
4045 sctp_accept(struct socket *so, struct mbuf *nam)
4047 struct sockaddr *addr = mtod(nam, struct sockaddr *);
4049 struct sctp_tcb *stcb;
4050 struct sockaddr *prim;
4051 struct sctp_inpcb *inp;
4054 inp = (struct sctp_inpcb *)so->so_pcb;
4058 return (ECONNRESET);
4060 SCTP_INP_RLOCK(inp);
4061 if (so->so_state & SS_ISDISCONNECTED) {
4063 SCTP_INP_RUNLOCK(inp);
4064 return (ECONNABORTED);
4066 stcb = LIST_FIRST(&inp->sctp_asoc_list);
4069 SCTP_INP_RUNLOCK(inp);
4070 return (ECONNRESET);
4072 SCTP_TCB_LOCK(stcb);
4073 SCTP_INP_RUNLOCK(inp);
4074 prim = (struct sockaddr *)&stcb->asoc.primary_destination->ro._l_addr;
4075 if (prim->sa_family == AF_INET) {
4076 struct sockaddr_in *sin;
4077 #if defined(__FreeBSD__) || defined(__APPLE__) || defined(__DragonFly__)
4078 MALLOC(sin, struct sockaddr_in *, sizeof *sin, M_SONAME,
4081 sin = (struct sockaddr_in *)addr;
4082 bzero((caddr_t)sin, sizeof (*sin));
4084 sin->sin_family = AF_INET;
4085 sin->sin_len = sizeof(*sin);
4086 sin->sin_port = ((struct sockaddr_in *)prim)->sin_port;
4087 sin->sin_addr = ((struct sockaddr_in *)prim)->sin_addr;
4088 #if defined(__FreeBSD__) || defined(__APPLE__) || defined(__DragonFly__)
4089 *addr = (struct sockaddr *)sin;
4091 nam->m_len = sizeof(*sin);
4094 struct sockaddr_in6 *sin6;
4095 #if defined(__FreeBSD__) || defined(__APPLE__) || defined(__DragonFly__)
4096 MALLOC(sin6, struct sockaddr_in6 *, sizeof *sin6, M_SONAME,
4099 sin6 = (struct sockaddr_in6 *)addr;
4101 bzero((caddr_t)sin6, sizeof (*sin6));
4102 sin6->sin6_family = AF_INET6;
4103 sin6->sin6_len = sizeof(*sin6);
4104 sin6->sin6_port = ((struct sockaddr_in6 *)prim)->sin6_port;
4106 sin6->sin6_addr = ((struct sockaddr_in6 *)prim)->sin6_addr;
4107 if (IN6_IS_SCOPE_LINKLOCAL(&sin6->sin6_addr))
4108 /* sin6->sin6_scope_id = ntohs(sin6->sin6_addr.s6_addr16[1]);*/
4109 in6_recoverscope(sin6, &sin6->sin6_addr, NULL); /* skip ifp check */
4111 sin6->sin6_scope_id = 0; /*XXX*/
4112 #if defined(__FreeBSD__) || defined (__APPLE__) || defined(__DragonFly__)
4113 *addr= (struct sockaddr *)sin6;
4115 nam->m_len = sizeof(*sin6);
4118 /* Wake any delayed sleep action */
4119 SCTP_TCB_UNLOCK(stcb);
4120 SCTP_INP_WLOCK(inp);
4121 if (inp->sctp_flags & SCTP_PCB_FLAGS_DONT_WAKE) {
4122 inp->sctp_flags &= ~SCTP_PCB_FLAGS_DONT_WAKE;
4123 if (inp->sctp_flags & SCTP_PCB_FLAGS_WAKEOUTPUT) {
4124 inp->sctp_flags &= ~SCTP_PCB_FLAGS_WAKEOUTPUT;
4125 #if defined(__NetBSD__)
4126 if (sowritable(inp->sctp_socket))
4127 sowwakeup(inp->sctp_socket);
4129 if (sowriteable(inp->sctp_socket))
4130 sowwakeup(inp->sctp_socket);
4133 if (inp->sctp_flags & SCTP_PCB_FLAGS_WAKEINPUT) {
4134 inp->sctp_flags &= ~SCTP_PCB_FLAGS_WAKEINPUT;
4135 if (soreadable(inp->sctp_socket))
4136 sorwakeup(inp->sctp_socket);
4140 SCTP_INP_WUNLOCK(inp);
4146 #if defined(__FreeBSD__) || defined(__APPLE__) || defined(__DragonFly__)
4147 sctp_ingetaddr(struct socket *so, struct sockaddr **addr)
4149 sctp_ingetaddr(struct socket *so, struct mbuf *nam)
4152 #if defined(__FreeBSD__) || defined(__APPLE__) || defined(__DragonFly__)
4153 struct sockaddr_in *sin;
4155 struct sockaddr_in *sin = mtod(nam, struct sockaddr_in *);
4157 struct sctp_inpcb *inp;
4159 * Do the malloc first in case it blocks.
4161 #if defined(__FreeBSD__) || defined(__APPLE__) || defined(__DragonFly__)
4162 MALLOC(sin, struct sockaddr_in *, sizeof *sin, M_SONAME, M_WAITOK |
4165 nam->m_len = sizeof(*sin);
4166 memset(sin, 0, sizeof(*sin));
4168 sin->sin_family = AF_INET;
4169 sin->sin_len = sizeof(*sin);
4171 inp = (struct sctp_inpcb *)so->so_pcb;
4174 #if defined(__FreeBSD__) || defined(__APPLE__) || defined(__DragonFly__)
4175 FREE(sin, M_SONAME);
4179 SCTP_INP_RLOCK(inp);
4180 sin->sin_port = inp->sctp_lport;
4181 if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUNDALL) {
4182 if (inp->sctp_flags & SCTP_PCB_FLAGS_CONNECTED) {
4183 struct sctp_tcb *stcb;
4184 struct sockaddr_in *sin_a;
4185 struct sctp_nets *net;
4188 stcb = LIST_FIRST(&inp->sctp_asoc_list);
4194 SCTP_TCB_LOCK(stcb);
4195 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
4196 sin_a = (struct sockaddr_in *)&net->ro._l_addr;
4197 if (sin_a->sin_family == AF_INET) {
4202 if ((!fnd) || (sin_a == NULL)) {
4204 SCTP_TCB_UNLOCK(stcb);
4207 sin->sin_addr = sctp_ipv4_source_address_selection(inp,
4208 stcb, (struct route *)&net->ro, net, 0);
4209 SCTP_TCB_UNLOCK(stcb);
4211 /* For the bound all case you get back 0 */
4213 sin->sin_addr.s_addr = 0;
4217 /* Take the first IPv4 address in the list */
4218 struct sctp_laddr *laddr;
4220 LIST_FOREACH(laddr, &inp->sctp_addr_list, sctp_nxt_addr) {
4221 if (laddr->ifa->ifa_addr->sa_family == AF_INET) {
4222 struct sockaddr_in *sin_a;
4223 sin_a = (struct sockaddr_in *)laddr->ifa->ifa_addr;
4224 sin->sin_addr = sin_a->sin_addr;
4231 #if defined(__FreeBSD__) || defined(__APPLE__) || defined(__DragonFly__)
4232 FREE(sin, M_SONAME);
4234 SCTP_INP_RUNLOCK(inp);
4238 SCTP_INP_RUNLOCK(inp);
4240 #if defined(__FreeBSD__) || defined(__APPLE__) || defined(__DragonFly__)
4241 (*addr) = (struct sockaddr *)sin;
4247 #if defined(__FreeBSD__) || defined(__APPLE__) || defined(__DragonFly__)
4248 sctp_peeraddr(struct socket *so, struct sockaddr **addr)
4250 struct sockaddr_in *sin = (struct sockaddr_in *)*addr;
4252 sctp_peeraddr(struct socket *so, struct mbuf *nam)
4254 struct sockaddr_in *sin = mtod(nam, struct sockaddr_in *);
4257 struct sockaddr_in *sin_a;
4258 struct sctp_inpcb *inp;
4259 struct sctp_tcb *stcb;
4260 struct sctp_nets *net;
4262 /* Do the malloc first in case it blocks. */
4263 inp = (struct sctp_inpcb *)so->so_pcb;
4264 if ((inp == NULL) ||
4265 ((inp->sctp_flags & SCTP_PCB_FLAGS_CONNECTED) == 0)) {
4266 /* UDP type and listeners will drop out here */
4271 #if defined(__FreeBSD__) || defined(__APPLE__) || defined(__DragonFly__)
4272 MALLOC(sin, struct sockaddr_in *, sizeof *sin, M_SONAME, M_WAITOK |
4275 nam->m_len = sizeof(*sin);
4276 memset(sin, 0, sizeof(*sin));
4278 sin->sin_family = AF_INET;
4279 sin->sin_len = sizeof(*sin);
4281 /* We must recapture incase we blocked */
4282 inp = (struct sctp_inpcb *)so->so_pcb;
4285 #if defined(__FreeBSD__) || defined(__APPLE__) || defined(__DragonFly__)
4286 FREE(sin, M_SONAME);
4290 SCTP_INP_RLOCK(inp);
4291 stcb = LIST_FIRST(&inp->sctp_asoc_list);
4293 SCTP_TCB_LOCK(stcb);
4294 SCTP_INP_RUNLOCK(inp);
4297 #if defined(__FreeBSD__) || defined(__APPLE__) || defined(__DragonFly__)
4298 FREE(sin, M_SONAME);
4303 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
4304 sin_a = (struct sockaddr_in *)&net->ro._l_addr;
4305 if (sin_a->sin_family == AF_INET) {
4307 sin->sin_port = stcb->rport;
4308 sin->sin_addr = sin_a->sin_addr;
4312 SCTP_TCB_UNLOCK(stcb);
4314 /* No IPv4 address */
4316 #if defined(__FreeBSD__) || defined(__APPLE__) || defined(__DragonFly__)
4317 FREE(sin, M_SONAME);
4325 #if defined(__FreeBSD__) || defined(__APPLE__) || defined(__DragonFly__)
4326 struct pr_usrreqs sctp_usrreqs = {
4332 pru_connect2_notsupp,
4350 #if defined(__NetBSD__)
4352 sctp_usrreq(struct socket *so, int req, struct mbuf *m, struct mbuf *nam,
4353 struct mbuf *control, struct proc *p)
4357 sctp_usrreq(struct socket *so, int req, struct mbuf *m, struct mbuf *nam,
4358 struct mbuf *control)
4360 struct proc *p = curproc;
4365 family = so->so_proto->pr_domain->dom_family;
4368 if (req == PRU_CONTROL) {
4371 error = in_control(so, (long)m, (caddr_t)nam,
4372 (struct ifnet *)control
4373 #if defined(__NetBSD__)
4380 error = in6_control(so, (long)m, (caddr_t)nam,
4381 (struct ifnet *)control, p);
4385 error = EAFNOSUPPORT;
4391 if (req == PRU_PURGEIF) {
4394 ifn = (struct ifnet *)control;
4395 TAILQ_FOREACH(ifa, &ifn->if_addrlist, ifa_list) {
4396 if (ifa->ifa_addr->sa_family == family) {
4397 sctp_delete_ip_address(ifa);
4411 return (EAFNOSUPPORT);
4419 error = sctp_attach(so, family, p);
4422 error = sctp_detach(so);
4429 error = sctp_bind(so, nam, p);
4432 error = sctp_listen(so, p);
4439 error = sctp_connect(so, nam, p);
4441 case PRU_DISCONNECT:
4442 error = sctp_disconnect(so);
4449 error = sctp_accept(so, nam);
4452 error = sctp_shutdown(so);
4457 * For Open and Net BSD, this is real
4458 * ugly. The mbuf *nam that is passed
4459 * (by soreceive()) is the int flags c
4460 * ast as a (mbuf *) yuck!
4462 error = sctp_usr_recvd(so, (int)((long)nam));
4466 /* Flags are ignored */
4468 if (sctp_debug_on & SCTP_DEBUG_USRREQ1) {
4469 printf("Send called on V4 side\n");
4473 struct sockaddr *addr;
4477 addr = mtod(nam, struct sockaddr *);
4479 error = sctp_send(so, 0, m, addr, control, p);
4483 error = sctp_abort(so);
4490 error = EAFNOSUPPORT;
4493 error = EAFNOSUPPORT;
4496 error = sctp_peeraddr(so, nam);
4499 error = sctp_ingetaddr(so, nam);
4512 /* #if defined(__NetBSD__) || defined(__OpenBSD__) */
4515 * Sysctl for sctp variables.
4518 sctp_sysctl(int *name, u_int namelen, void *oldp, size_t *oldlenp, void *newp,
4522 /* All sysctl names at this level are terminal. */
4528 case SCTPCTL_MAXDGRAM:
4529 return (sysctl_int(oldp, oldlenp, newp, newlen,
4531 case SCTPCTL_RECVSPACE:
4532 return (sysctl_int(oldp, oldlenp, newp, newlen,
4534 case SCTPCTL_AUTOASCONF:
4535 return (sysctl_int(oldp, oldlenp, newp, newlen,
4536 &sctp_auto_asconf));
4537 case SCTPCTL_ECN_ENABLE:
4538 return (sysctl_int(oldp, oldlenp, newp, newlen,
4540 case SCTPCTL_ECN_NONCE:
4541 return (sysctl_int(oldp, oldlenp, newp, newlen,
4543 case SCTPCTL_STRICT_SACK:
4544 return (sysctl_int(oldp, oldlenp, newp, newlen,
4545 &sctp_strict_sacks));
4546 case SCTPCTL_NOCSUM_LO:
4547 return (sysctl_int(oldp, oldlenp, newp, newlen,
4548 &sctp_no_csum_on_loopback));
4549 case SCTPCTL_STRICT_INIT:
4550 return (sysctl_int(oldp, oldlenp, newp, newlen,
4551 &sctp_strict_init));
4552 case SCTPCTL_PEER_CHK_OH:
4553 return (sysctl_int(oldp, oldlenp, newp, newlen,
4554 &sctp_peer_chunk_oh));
4555 case SCTPCTL_MAXBURST:
4556 return (sysctl_int(oldp, oldlenp, newp, newlen,
4557 &sctp_max_burst_default));
4558 case SCTPCTL_MAXCHUNKONQ:
4559 return (sysctl_int(oldp, oldlenp, newp, newlen,
4560 &sctp_max_chunks_on_queue));
4561 case SCTPCTL_DELAYED_SACK:
4562 return (sysctl_int(oldp, oldlenp, newp, newlen,
4563 &sctp_delayed_sack_time_default));
4564 case SCTPCTL_HB_INTERVAL:
4565 return (sysctl_int(oldp, oldlenp, newp, newlen,
4566 &sctp_heartbeat_interval_default));
4567 case SCTPCTL_PMTU_RAISE:
4568 return (sysctl_int(oldp, oldlenp, newp, newlen,
4569 &sctp_pmtu_raise_time_default));
4570 case SCTPCTL_SHUTDOWN_GUARD:
4571 return (sysctl_int(oldp, oldlenp, newp, newlen,
4572 &sctp_shutdown_guard_time_default));
4573 case SCTPCTL_SECRET_LIFETIME:
4574 return (sysctl_int(oldp, oldlenp, newp, newlen,
4575 &sctp_secret_lifetime_default));
4576 case SCTPCTL_RTO_MAX:
4577 return (sysctl_int(oldp, oldlenp, newp, newlen,
4578 &sctp_rto_max_default));
4579 case SCTPCTL_RTO_MIN:
4580 return (sysctl_int(oldp, oldlenp, newp, newlen,
4581 &sctp_rto_min_default));
4582 case SCTPCTL_RTO_INITIAL:
4583 return (sysctl_int(oldp, oldlenp, newp, newlen,
4584 &sctp_rto_initial_default));
4585 case SCTPCTL_INIT_RTO_MAX:
4586 return (sysctl_int(oldp, oldlenp, newp, newlen,
4587 &sctp_init_rto_max_default));
4588 case SCTPCTL_COOKIE_LIFE:
4589 return (sysctl_int(oldp, oldlenp, newp, newlen,
4590 &sctp_valid_cookie_life_default));
4591 case SCTPCTL_INIT_RTX_MAX:
4592 return (sysctl_int(oldp, oldlenp, newp, newlen,
4593 &sctp_init_rtx_max_default));
4594 case SCTPCTL_ASSOC_RTX_MAX:
4595 return (sysctl_int(oldp, oldlenp, newp, newlen,
4596 &sctp_assoc_rtx_max_default));
4597 case SCTPCTL_PATH_RTX_MAX:
4598 return (sysctl_int(oldp, oldlenp, newp, newlen,
4599 &sctp_path_rtx_max_default));
4600 case SCTPCTL_NR_OUTGOING_STREAMS:
4601 return (sysctl_int(oldp, oldlenp, newp, newlen,
4602 &sctp_nr_outgoing_streams_default));
4605 return (sysctl_int(oldp, oldlenp, newp, newlen,
4609 return (ENOPROTOOPT);
4616 * Sysctl for sctp variables.
4618 SYSCTL_SETUP(sysctl_net_inet_sctp_setup, "sysctl net.inet.sctp subtree setup")
4621 sysctl_createv(clog, 0, NULL, NULL,
4623 CTLTYPE_NODE, "net", NULL,
4626 sysctl_createv(clog, 0, NULL, NULL,
4628 CTLTYPE_NODE, "inet", NULL,
4630 CTL_NET, PF_INET, CTL_EOL);
4631 sysctl_createv(clog, 0, NULL, NULL,
4633 CTLTYPE_NODE, "sctp",
4634 SYSCTL_DESCR("sctp related settings"),
4636 CTL_NET, PF_INET, IPPROTO_SCTP, CTL_EOL);
4638 sysctl_createv(clog, 0, NULL, NULL,
4639 CTLFLAG_PERMANENT|CTLFLAG_READWRITE,
4640 CTLTYPE_INT, "maxdgram",
4641 SYSCTL_DESCR("Maximum outgoing SCTP buffer size"),
4642 NULL, 0, &sctp_sendspace, 0,
4643 CTL_NET, PF_INET, IPPROTO_SCTP, SCTPCTL_MAXDGRAM,
4646 sysctl_createv(clog, 0, NULL, NULL,
4647 CTLFLAG_PERMANENT|CTLFLAG_READWRITE,
4648 CTLTYPE_INT, "recvspace",
4649 SYSCTL_DESCR("Maximum incoming SCTP buffer size"),
4650 NULL, 0, &sctp_recvspace, 0,
4651 CTL_NET, PF_INET, IPPROTO_SCTP, SCTPCTL_RECVSPACE,
4654 sysctl_createv(clog, 0, NULL, NULL,
4655 CTLFLAG_PERMANENT|CTLFLAG_READWRITE,
4656 CTLTYPE_INT, "autoasconf",
4657 SYSCTL_DESCR("Enable SCTP Auto-ASCONF"),
4658 NULL, 0, &sctp_auto_asconf, 0,
4659 CTL_NET, PF_INET, IPPROTO_SCTP, SCTPCTL_AUTOASCONF,
4662 sysctl_createv(clog, 0, NULL, NULL,
4663 CTLFLAG_PERMANENT|CTLFLAG_READWRITE,
4664 CTLTYPE_INT, "ecn_enable",
4665 SYSCTL_DESCR("Enable SCTP ECN"),
4666 NULL, 0, &sctp_ecn, 0,
4667 CTL_NET, PF_INET, IPPROTO_SCTP, SCTPCTL_ECN_ENABLE,
4670 sysctl_createv(clog, 0, NULL, NULL,
4671 CTLFLAG_PERMANENT|CTLFLAG_READWRITE,
4672 CTLTYPE_INT, "ecn_nonce",
4673 SYSCTL_DESCR("Enable SCTP ECN Nonce"),
4674 NULL, 0, &sctp_ecn_nonce, 0,
4675 CTL_NET, PF_INET, IPPROTO_SCTP, SCTPCTL_ECN_NONCE,
4678 sysctl_createv(clog, 0, NULL, NULL,
4679 CTLFLAG_PERMANENT|CTLFLAG_READWRITE,
4680 CTLTYPE_INT, "strict_sack",
4681 SYSCTL_DESCR("Enable SCTP Strict SACK checking"),
4682 NULL, 0, &sctp_strict_sacks, 0,
4683 CTL_NET, PF_INET, IPPROTO_SCTP, SCTPCTL_STRICT_SACK,
4686 sysctl_createv(clog, 0, NULL, NULL,
4687 CTLFLAG_PERMANENT|CTLFLAG_READWRITE,
4688 CTLTYPE_INT, "loopback_nocsum",
4689 SYSCTL_DESCR("Enable NO Csum on packets sent on loopback"),
4690 NULL, 0, &sctp_no_csum_on_loopback, 0,
4691 CTL_NET, PF_INET, IPPROTO_SCTP, SCTPCTL_NOCSUM_LO,
4694 sysctl_createv(clog, 0, NULL, NULL,
4695 CTLFLAG_PERMANENT|CTLFLAG_READWRITE,
4696 CTLTYPE_INT, "strict_init",
4697 SYSCTL_DESCR("Enable strict INIT/INIT-ACK singleton enforcement"),
4698 NULL, 0, &sctp_strict_init, 0,
4699 CTL_NET, PF_INET, IPPROTO_SCTP, SCTPCTL_STRICT_INIT,
4702 sysctl_createv(clog, 0, NULL, NULL,
4703 CTLFLAG_PERMANENT|CTLFLAG_READWRITE,
4704 CTLTYPE_INT, "peer_chkoh",
4705 SYSCTL_DESCR("Amount to debit peers rwnd per chunk sent"),
4706 NULL, 0, &sctp_peer_chunk_oh, 0,
4707 CTL_NET, PF_INET, IPPROTO_SCTP, SCTPCTL_PEER_CHK_OH,
4710 sysctl_createv(clog, 0, NULL, NULL,
4711 CTLFLAG_PERMANENT|CTLFLAG_READWRITE,
4712 CTLTYPE_INT, "maxburst",
4713 SYSCTL_DESCR("Default max burst for sctp endpoints"),
4714 NULL, 0, &sctp_max_burst_default, 0,
4715 CTL_NET, PF_INET, IPPROTO_SCTP, SCTPCTL_MAXBURST,
4718 sysctl_createv(clog, 0, NULL, NULL,
4719 CTLFLAG_PERMANENT|CTLFLAG_READWRITE,
4720 CTLTYPE_INT, "maxchunks",
4721 SYSCTL_DESCR("Default max chunks on queue per asoc"),
4722 NULL, 0, &sctp_max_chunks_on_queue, 0,
4723 CTL_NET, PF_INET, IPPROTO_SCTP, SCTPCTL_MAXCHUNKONQ,