2 * Copyright (c) 2001-2006, Cisco Systems, Inc. All rights reserved.
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are met:
7 * a) Redistributions of source code must retain the above copyright notice,
8 * this list of conditions and the following disclaimer.
10 * b) Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in
12 * the documentation and/or other materials provided with the distribution.
14 * c) Neither the name of Cisco Systems, Inc. nor the names of its
15 * contributors may be used to endorse or promote products derived
16 * from this software without specific prior written permission.
18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
20 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
22 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
23 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
24 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
25 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
26 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
27 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
28 * THE POSSIBILITY OF SUCH DAMAGE.
31 /* $KAME: sctp_usrreq.c,v 1.48 2005/03/07 23:26:08 itojun Exp $ */
33 #include <sys/cdefs.h>
34 __FBSDID("$FreeBSD$");
37 #include "opt_ipsec.h"
38 #include "opt_inet6.h"
43 #include <sys/param.h>
44 #include <sys/systm.h>
45 #include <sys/kernel.h>
46 #include <sys/malloc.h>
48 #include <sys/domain.h>
50 #include <sys/protosw.h>
51 #include <sys/socket.h>
52 #include <sys/socketvar.h>
53 #include <sys/sysctl.h>
54 #include <sys/syslog.h>
56 #include <net/if_types.h>
57 #include <net/if_var.h>
58 #include <net/route.h>
59 #include <netinet/in.h>
60 #include <netinet/in_systm.h>
61 #include <netinet/ip.h>
62 #include <netinet/ip6.h>
63 #include <netinet/in_pcb.h>
64 #include <netinet/in_var.h>
65 #include <netinet/ip_var.h>
66 #include <netinet6/ip6_var.h>
67 #include <netinet6/in6_var.h>
68 #include <netinet6/scope6_var.h>
69 #include <netinet/ip_icmp.h>
70 #include <netinet/icmp_var.h>
71 #include <netinet/sctp_os.h>
72 #include <netinet/sctp_pcb.h>
73 #include <netinet/sctp_header.h>
74 #include <netinet/sctp_var.h>
75 #include <netinet/sctp_output.h>
76 #include <netinet/sctp_bsd_addr.h>
77 #include <netinet/sctp_uio.h>
78 #include <netinet/sctp_asconf.h>
79 #include <netinet/sctputil.h>
80 #include <netinet/sctp_indata.h>
81 #include <netinet/sctp_asconf.h>
82 #include <netinet/sctp_timer.h>
83 #include <netinet/sctp_auth.h>
85 #include <netinet6/ipsec.h>
86 #include <netkey/key.h>
96 #define sotoin6pcb sotoinpcb
102 * sysctl tunable variables
104 int sctp_sendspace = (128 * 1024);
105 int sctp_recvspace = 128 * (1024 +
107 sizeof(struct sockaddr_in6)
109 sizeof(struct sockaddr_in)
112 int sctp_mbuf_threshold_count = SCTP_DEFAULT_MBUFS_IN_CHAIN;
113 int sctp_auto_asconf = SCTP_DEFAULT_AUTO_ASCONF;
114 int sctp_ecn_enable = 1;
115 int sctp_ecn_nonce = 0;
116 int sctp_strict_sacks = 0;
117 int sctp_no_csum_on_loopback = 1;
118 int sctp_strict_init = 1;
119 int sctp_abort_if_one_2_one_hits_limit = 0;
120 int sctp_strict_data_order = 0;
122 int sctp_peer_chunk_oh = sizeof(struct mbuf);
123 int sctp_max_burst_default = SCTP_DEF_MAX_BURST;
124 int sctp_use_cwnd_based_maxburst = 1;
125 int sctp_do_drain = 1;
126 int sctp_warm_the_crc32_table = 0;
128 unsigned int sctp_max_chunks_on_queue = SCTP_ASOC_MAX_CHUNKS_ON_QUEUE;
129 unsigned int sctp_delayed_sack_time_default = SCTP_RECV_MSEC;
130 unsigned int sctp_heartbeat_interval_default = SCTP_HB_DEFAULT_MSEC;
131 unsigned int sctp_pmtu_raise_time_default = SCTP_DEF_PMTU_RAISE_SEC;
132 unsigned int sctp_shutdown_guard_time_default = SCTP_DEF_MAX_SHUTDOWN_SEC;
133 unsigned int sctp_secret_lifetime_default = SCTP_DEFAULT_SECRET_LIFE_SEC;
134 unsigned int sctp_rto_max_default = SCTP_RTO_UPPER_BOUND;
135 unsigned int sctp_rto_min_default = SCTP_RTO_LOWER_BOUND;
136 unsigned int sctp_rto_initial_default = SCTP_RTO_INITIAL;
137 unsigned int sctp_init_rto_max_default = SCTP_RTO_UPPER_BOUND;
138 unsigned int sctp_valid_cookie_life_default = SCTP_DEFAULT_COOKIE_LIFE;
139 unsigned int sctp_init_rtx_max_default = SCTP_DEF_MAX_INIT;
140 unsigned int sctp_assoc_rtx_max_default = SCTP_DEF_MAX_SEND;
141 unsigned int sctp_path_rtx_max_default = SCTP_DEF_MAX_PATH_RTX;
142 unsigned int sctp_nr_outgoing_streams_default = SCTP_OSTREAM_INITIAL;
143 unsigned int sctp_add_more_threshold = SCTP_DEFAULT_ADD_MORE;
145 uint32_t sctp_asoc_free_resc_limit = SCTP_DEF_ASOC_RESC_LIMIT;
146 uint32_t sctp_system_free_resc_limit = SCTP_DEF_SYSTEM_RESC_LIMIT;
148 int sctp_min_split_point = SCTP_DEFAULT_SPLIT_POINT_MIN;
149 int sctp_pcbtblsize = SCTP_PCBHASHSIZE;
150 int sctp_hashtblsize = SCTP_TCBHASHSIZE;
151 int sctp_chunkscale = SCTP_CHUNKQUEUE_SCALE;
153 unsigned int sctp_cmt_on_off = 0;
154 unsigned int sctp_cmt_sockopt_on_off = 0;
155 unsigned int sctp_cmt_use_dac = 0;
156 unsigned int sctp_cmt_sockopt_use_dac = 0;
158 int sctp_L2_abc_variable = 1;
159 unsigned int sctp_early_fr = 0;
160 unsigned int sctp_early_fr_msec = SCTP_MINFR_MSEC_TIMER;
161 unsigned int sctp_use_rttvar_cc = 0;
162 int sctp_says_check_for_deadlock = 0;
163 unsigned int sctp_asconf_auth_nochk = 0;
164 unsigned int sctp_auth_disable = 0;
165 unsigned int sctp_auth_random_len = SCTP_AUTH_RANDOM_SIZE_DEFAULT;
166 unsigned int sctp_auth_hmac_id_default = SCTP_AUTH_HMAC_ID_SHA1;
167 struct sctpstat sctpstat;
170 extern uint32_t sctp_debug_on;
172 #endif /* SCTP_DEBUG */
178 /* Init the SCTP pcb in sctp_pcb.c */
183 if ((nmbclusters / 8) > SCTP_ASOC_MAX_CHUNKS_ON_QUEUE)
184 sctp_max_chunks_on_queue = (nmbclusters / 8);
186 * Allow a user to take no more than 1/2 the number of clusters or
187 * the SB_MAX whichever is smaller for the send window.
189 sb_max_adj = (u_long)((u_quad_t) (SB_MAX) * MCLBYTES / (MSIZE + MCLBYTES));
190 sctp_sendspace = min((min(SB_MAX, sb_max_adj)),
191 ((nmbclusters / 2) * SCTP_DEFAULT_MAXSEGMENT));
193 * Now for the recv window, should we take the same amount? or
194 * should I do 1/2 the SB_MAX instead in the SB_MAX min above. For
195 * now I will just copy.
197 sctp_recvspace = sctp_sendspace;
205 ip_2_ip6_hdr(struct ip6_hdr *ip6, struct ip *ip)
207 bzero(ip6, sizeof(*ip6));
209 ip6->ip6_vfc = IPV6_VERSION;
210 ip6->ip6_plen = ip->ip_len;
211 ip6->ip6_nxt = ip->ip_p;
212 ip6->ip6_hlim = ip->ip_ttl;
213 ip6->ip6_src.s6_addr32[2] = ip6->ip6_dst.s6_addr32[2] =
215 ip6->ip6_src.s6_addr32[3] = ip->ip_src.s_addr;
216 ip6->ip6_dst.s6_addr32[3] = ip->ip_dst.s_addr;
223 sctp_pathmtu_adustment(struct sctp_inpcb *inp,
224 struct sctp_tcb *stcb,
225 struct sctp_nets *net,
228 struct sctp_tmit_chunk *chk;
230 /* Adjust that too */
231 stcb->asoc.smallest_mtu = nxtsz;
232 /* now off to subtract IP_DF flag if needed */
234 TAILQ_FOREACH(chk, &stcb->asoc.send_queue, sctp_next) {
235 if ((chk->send_size + IP_HDR_SIZE) > nxtsz) {
236 chk->flags |= CHUNK_FLAGS_FRAGMENT_OK;
239 TAILQ_FOREACH(chk, &stcb->asoc.sent_queue, sctp_next) {
240 if ((chk->send_size + IP_HDR_SIZE) > nxtsz) {
242 * For this guy we also mark for immediate resend
243 * since we sent to big of chunk
245 chk->flags |= CHUNK_FLAGS_FRAGMENT_OK;
246 if (chk->sent != SCTP_DATAGRAM_RESEND) {
247 sctp_ucount_incr(stcb->asoc.sent_queue_retran_cnt);
249 chk->sent = SCTP_DATAGRAM_RESEND;
250 chk->rec.data.doing_fast_retransmit = 0;
252 /* Clear any time so NO RTT is being done */
254 if (stcb->asoc.total_flight >= chk->book_size)
255 stcb->asoc.total_flight -= chk->book_size;
257 stcb->asoc.total_flight = 0;
258 if (stcb->asoc.total_flight_count > 0)
259 stcb->asoc.total_flight_count--;
260 if (net->flight_size >= chk->book_size)
261 net->flight_size -= chk->book_size;
263 net->flight_size = 0;
269 sctp_notify_mbuf(struct sctp_inpcb *inp,
270 struct sctp_tcb *stcb,
271 struct sctp_nets *net,
276 int totsz, tmr_stopped = 0;
280 if ((inp == NULL) || (stcb == NULL) || (net == NULL) ||
281 (ip == NULL) || (sh == NULL)) {
283 SCTP_TCB_UNLOCK(stcb);
286 /* First job is to verify the vtag matches what I would send */
287 if (ntohl(sh->v_tag) != (stcb->asoc.peer_vtag)) {
288 SCTP_TCB_UNLOCK(stcb);
291 icmph = (struct icmp *)((caddr_t)ip - (sizeof(struct icmp) -
293 if (icmph->icmp_type != ICMP_UNREACH) {
294 /* We only care about unreachable */
295 SCTP_TCB_UNLOCK(stcb);
298 if (icmph->icmp_code != ICMP_UNREACH_NEEDFRAG) {
299 /* not a unreachable message due to frag. */
300 SCTP_TCB_UNLOCK(stcb);
305 nxtsz = ntohs(icmph->icmp_seq);
308 * old type router that does not tell us what the next size
309 * mtu is. Rats we will have to guess (in a educated fashion
312 nxtsz = find_next_best_mtu(totsz);
314 /* Stop any PMTU timer */
315 if (callout_pending(&net->pmtu_timer.timer)) {
317 sctp_timer_stop(SCTP_TIMER_TYPE_PATHMTURAISE, inp, stcb, net);
319 /* Adjust destination size limit */
320 if (net->mtu > nxtsz) {
323 /* now what about the ep? */
324 if (stcb->asoc.smallest_mtu > nxtsz) {
325 sctp_pathmtu_adustment(inp, stcb, net, nxtsz);
328 sctp_timer_start(SCTP_TIMER_TYPE_PATHMTURAISE, inp, stcb, net);
330 SCTP_TCB_UNLOCK(stcb);
335 sctp_notify(struct sctp_inpcb *inp,
339 struct sctp_tcb *stcb,
340 struct sctp_nets *net)
343 if ((inp == NULL) || (stcb == NULL) || (net == NULL) ||
344 (sh == NULL) || (to == NULL)) {
347 /* First job is to verify the vtag matches what I would send */
348 if (ntohl(sh->v_tag) != (stcb->asoc.peer_vtag)) {
351 /* FIX ME FIX ME PROTOPT i.e. no SCTP should ALWAYS be an ABORT */
353 if ((errno == EHOSTUNREACH) || /* Host is not reachable */
354 (errno == EHOSTDOWN) || /* Host is down */
355 (errno == ECONNREFUSED) || /* Host refused the connection, (not
357 (errno == ENOPROTOOPT) /* SCTP is not present on host */
360 * Hmm reachablity problems we must examine closely. If its
361 * not reachable, we may have lost a network. Or if there is
362 * NO protocol at the other end named SCTP. well we consider
365 if ((errno == EHOSTUNREACH) || (errno == EHOSTDOWN)) {
366 if (net->dest_state & SCTP_ADDR_REACHABLE) {
367 /* Ok that destination is NOT reachable */
368 net->dest_state &= ~SCTP_ADDR_REACHABLE;
369 net->dest_state |= SCTP_ADDR_NOT_REACHABLE;
370 net->error_count = net->failure_threshold + 1;
371 sctp_ulp_notify(SCTP_NOTIFY_INTERFACE_DOWN,
372 stcb, SCTP_FAILED_THRESHOLD,
376 SCTP_TCB_UNLOCK(stcb);
379 * Here the peer is either playing tricks on us,
380 * including an address that belongs to someone who
381 * does not support SCTP OR was a userland
382 * implementation that shutdown and now is dead. In
383 * either case treat it like a OOTB abort with no
386 sctp_abort_notification(stcb, SCTP_PEER_FAULTY);
387 sctp_free_assoc(inp, stcb, 0);
388 /* no need to unlock here, since the TCB is gone */
391 /* Send all others to the app */
393 SCTP_TCB_UNLOCK(stcb);
396 if (inp->sctp_socket) {
397 #ifdef SCTP_LOCK_LOGGING
398 sctp_log_lock(inp, stcb, SCTP_LOG_LOCK_SOCK);
400 SOCK_LOCK(inp->sctp_socket);
401 inp->sctp_socket->so_error = errno;
402 sctp_sowwakeup(inp, inp->sctp_socket);
403 SOCK_UNLOCK(inp->sctp_socket);
409 sctp_ctlinput(cmd, sa, vip)
419 if (sa->sa_family != AF_INET ||
420 ((struct sockaddr_in *)sa)->sin_addr.s_addr == INADDR_ANY) {
423 if (PRC_IS_REDIRECT(cmd)) {
425 } else if ((unsigned)cmd >= PRC_NCMDS || inetctlerrmap[cmd] == 0) {
429 struct sctp_inpcb *inp = NULL;
430 struct sctp_tcb *stcb = NULL;
431 struct sctp_nets *net = NULL;
432 struct sockaddr_in to, from;
434 sh = (struct sctphdr *)((caddr_t)ip + (ip->ip_hl << 2));
435 bzero(&to, sizeof(to));
436 bzero(&from, sizeof(from));
437 from.sin_family = to.sin_family = AF_INET;
438 from.sin_len = to.sin_len = sizeof(to);
439 from.sin_port = sh->src_port;
440 from.sin_addr = ip->ip_src;
441 to.sin_port = sh->dest_port;
442 to.sin_addr = ip->ip_dst;
445 * 'to' holds the dest of the packet that failed to be sent.
446 * 'from' holds our local endpoint address. Thus we reverse
447 * the to and the from in the lookup.
450 stcb = sctp_findassociation_addr_sa((struct sockaddr *)&from,
451 (struct sockaddr *)&to,
453 if (stcb != NULL && inp && (inp->sctp_socket != NULL)) {
454 if (cmd != PRC_MSGSIZE) {
457 if (cmd == PRC_HOSTDEAD) {
460 cm = inetctlerrmap[cmd];
462 sctp_notify(inp, cm, sh,
463 (struct sockaddr *)&to, stcb,
466 /* handle possible ICMP size messages */
467 sctp_notify_mbuf(inp, stcb, net, ip, sh);
470 if ((stcb == NULL) && (inp != NULL)) {
471 /* reduce ref-count */
473 SCTP_INP_DECR_REF(inp);
474 SCTP_INP_WUNLOCK(inp);
483 sctp_getcred(SYSCTL_HANDLER_ARGS)
485 struct sockaddr_in addrs[2];
486 struct sctp_inpcb *inp;
487 struct sctp_nets *net;
488 struct sctp_tcb *stcb;
491 error = suser(req->td);
494 error = SYSCTL_IN(req, addrs, sizeof(addrs));
499 stcb = sctp_findassociation_addr_sa(sintosa(&addrs[0]),
502 if (stcb == NULL || inp == NULL || inp->sctp_socket == NULL) {
503 if ((inp != NULL) && (stcb == NULL)) {
504 /* reduce ref-count */
506 SCTP_INP_DECR_REF(inp);
507 SCTP_INP_WUNLOCK(inp);
512 error = SYSCTL_OUT(req, inp->sctp_socket->so_cred, sizeof(struct ucred));
513 SCTP_TCB_UNLOCK(stcb);
519 SYSCTL_PROC(_net_inet_sctp, OID_AUTO, getcred, CTLTYPE_OPAQUE | CTLFLAG_RW,
520 0, 0, sctp_getcred, "S,ucred", "Get the ucred of a SCTP connection");
527 SYSCTL_INT(_net_inet_sctp, OID_AUTO, sendspace, CTLFLAG_RW,
528 &sctp_sendspace, 0, "Maximum outgoing SCTP buffer size");
530 SYSCTL_INT(_net_inet_sctp, OID_AUTO, recvspace, CTLFLAG_RW,
531 &sctp_recvspace, 0, "Maximum incoming SCTP buffer size");
533 SYSCTL_INT(_net_inet_sctp, OID_AUTO, auto_asconf, CTLFLAG_RW,
534 &sctp_auto_asconf, 0, "Enable SCTP Auto-ASCONF");
536 SYSCTL_INT(_net_inet_sctp, OID_AUTO, ecn_enable, CTLFLAG_RW,
537 &sctp_ecn_enable, 0, "Enable SCTP ECN");
539 SYSCTL_INT(_net_inet_sctp, OID_AUTO, ecn_nonce, CTLFLAG_RW,
540 &sctp_ecn_nonce, 0, "Enable SCTP ECN Nonce");
542 SYSCTL_INT(_net_inet_sctp, OID_AUTO, strict_sacks, CTLFLAG_RW,
543 &sctp_strict_sacks, 0, "Enable SCTP Strict SACK checking");
545 SYSCTL_INT(_net_inet_sctp, OID_AUTO, loopback_nocsum, CTLFLAG_RW,
546 &sctp_no_csum_on_loopback, 0,
547 "Enable NO Csum on packets sent on loopback");
549 SYSCTL_INT(_net_inet_sctp, OID_AUTO, strict_init, CTLFLAG_RW,
550 &sctp_strict_init, 0,
551 "Enable strict INIT/INIT-ACK singleton enforcement");
553 SYSCTL_INT(_net_inet_sctp, OID_AUTO, peer_chkoh, CTLFLAG_RW,
554 &sctp_peer_chunk_oh, 0,
555 "Amount to debit peers rwnd per chunk sent");
557 SYSCTL_INT(_net_inet_sctp, OID_AUTO, maxburst, CTLFLAG_RW,
558 &sctp_max_burst_default, 0,
559 "Default max burst for sctp endpoints");
561 SYSCTL_INT(_net_inet_sctp, OID_AUTO, maxchunks, CTLFLAG_RW,
562 &sctp_max_chunks_on_queue, 0,
563 "Default max chunks on queue per asoc");
565 SYSCTL_INT(_net_inet_sctp, OID_AUTO, tcbhashsize, CTLFLAG_RW,
566 &sctp_hashtblsize, 0,
567 "Tuneable for Hash table sizes");
569 SYSCTL_INT(_net_inet_sctp, OID_AUTO, min_split_point, CTLFLAG_RW,
570 &sctp_min_split_point, 0,
571 "Minimum size when splitting a chunk");
573 SYSCTL_INT(_net_inet_sctp, OID_AUTO, pcbhashsize, CTLFLAG_RW,
575 "Tuneable for PCB Hash table sizes");
577 SYSCTL_INT(_net_inet_sctp, OID_AUTO, sys_resource, CTLFLAG_RW,
578 &sctp_system_free_resc_limit, 0,
579 "Max number of cached resources in the system");
581 SYSCTL_INT(_net_inet_sctp, OID_AUTO, asoc_resource, CTLFLAG_RW,
582 &sctp_asoc_free_resc_limit, 0,
583 "Max number of cached resources in an asoc");
586 SYSCTL_INT(_net_inet_sctp, OID_AUTO, chunkscale, CTLFLAG_RW,
588 "Tuneable for Scaling of number of chunks and messages");
591 SYSCTL_UINT(_net_inet_sctp, OID_AUTO, delayed_sack_time, CTLFLAG_RW,
592 &sctp_delayed_sack_time_default, 0,
593 "Default delayed SACK timer in msec");
595 SYSCTL_UINT(_net_inet_sctp, OID_AUTO, heartbeat_interval, CTLFLAG_RW,
596 &sctp_heartbeat_interval_default, 0,
597 "Default heartbeat interval in msec");
599 SYSCTL_UINT(_net_inet_sctp, OID_AUTO, pmtu_raise_time, CTLFLAG_RW,
600 &sctp_pmtu_raise_time_default, 0,
601 "Default PMTU raise timer in sec");
603 SYSCTL_UINT(_net_inet_sctp, OID_AUTO, shutdown_guard_time, CTLFLAG_RW,
604 &sctp_shutdown_guard_time_default, 0,
605 "Default shutdown guard timer in sec");
607 SYSCTL_UINT(_net_inet_sctp, OID_AUTO, secret_lifetime, CTLFLAG_RW,
608 &sctp_secret_lifetime_default, 0,
609 "Default secret lifetime in sec");
611 SYSCTL_UINT(_net_inet_sctp, OID_AUTO, rto_max, CTLFLAG_RW,
612 &sctp_rto_max_default, 0,
613 "Default maximum retransmission timeout in msec");
615 SYSCTL_UINT(_net_inet_sctp, OID_AUTO, rto_min, CTLFLAG_RW,
616 &sctp_rto_min_default, 0,
617 "Default minimum retransmission timeout in msec");
619 SYSCTL_UINT(_net_inet_sctp, OID_AUTO, rto_initial, CTLFLAG_RW,
620 &sctp_rto_initial_default, 0,
621 "Default initial retransmission timeout in msec");
623 SYSCTL_UINT(_net_inet_sctp, OID_AUTO, init_rto_max, CTLFLAG_RW,
624 &sctp_init_rto_max_default, 0,
625 "Default maximum retransmission timeout during association setup in msec");
627 SYSCTL_UINT(_net_inet_sctp, OID_AUTO, valid_cookie_life, CTLFLAG_RW,
628 &sctp_valid_cookie_life_default, 0,
629 "Default cookie lifetime in sec");
631 SYSCTL_UINT(_net_inet_sctp, OID_AUTO, init_rtx_max, CTLFLAG_RW,
632 &sctp_init_rtx_max_default, 0,
633 "Default maximum number of retransmission for INIT chunks");
635 SYSCTL_UINT(_net_inet_sctp, OID_AUTO, assoc_rtx_max, CTLFLAG_RW,
636 &sctp_assoc_rtx_max_default, 0,
637 "Default maximum number of retransmissions per association");
639 SYSCTL_UINT(_net_inet_sctp, OID_AUTO, path_rtx_max, CTLFLAG_RW,
640 &sctp_path_rtx_max_default, 0,
641 "Default maximum of retransmissions per path");
643 SYSCTL_UINT(_net_inet_sctp, OID_AUTO, add_more_on_output, CTLFLAG_RW,
644 &sctp_add_more_threshold, 0,
645 "When space wise is it worthwhile to try to add more to a socket send buffer");
648 SYSCTL_UINT(_net_inet_sctp, OID_AUTO, nr_outgoing_streams, CTLFLAG_RW,
649 &sctp_nr_outgoing_streams_default, 0,
650 "Default number of outgoing streams");
652 SYSCTL_UINT(_net_inet_sctp, OID_AUTO, cmt_on_off, CTLFLAG_RW,
656 SYSCTL_UINT(_net_inet_sctp, OID_AUTO, cwnd_maxburst, CTLFLAG_RW,
657 &sctp_use_cwnd_based_maxburst, 0,
658 "Use a CWND adjusting maxburst");
660 SYSCTL_UINT(_net_inet_sctp, OID_AUTO, early_fast_retran, CTLFLAG_RW,
662 "Early Fast Retransmit with Timer");
664 SYSCTL_UINT(_net_inet_sctp, OID_AUTO, use_rttvar_congctrl, CTLFLAG_RW,
665 &sctp_use_rttvar_cc, 0,
666 "Use congestion control via rtt variation");
668 SYSCTL_UINT(_net_inet_sctp, OID_AUTO, deadlock_detect, CTLFLAG_RW,
669 &sctp_says_check_for_deadlock, 0,
670 "SMP Deadlock detection on/off");
672 SYSCTL_UINT(_net_inet_sctp, OID_AUTO, early_fast_retran_msec, CTLFLAG_RW,
673 &sctp_early_fr_msec, 0,
674 "Early Fast Retransmit minimum timer value");
676 SYSCTL_UINT(_net_inet_sctp, OID_AUTO, asconf_auth_nochk, CTLFLAG_RW,
677 &sctp_asconf_auth_nochk, 0,
678 "Disable SCTP ASCONF AUTH requirement");
680 SYSCTL_UINT(_net_inet_sctp, OID_AUTO, auth_disable, CTLFLAG_RW,
681 &sctp_auth_disable, 0,
682 "Disable SCTP AUTH chunk requirement/function");
684 SYSCTL_UINT(_net_inet_sctp, OID_AUTO, auth_random_len, CTLFLAG_RW,
685 &sctp_auth_random_len, 0,
686 "Length of AUTH RANDOMs");
688 SYSCTL_UINT(_net_inet_sctp, OID_AUTO, auth_hmac_id, CTLFLAG_RW,
689 &sctp_auth_hmac_id_default, 0,
690 "Default HMAC Id for SCTP AUTHenthication");
692 SYSCTL_INT(_net_inet_sctp, OID_AUTO, abc_l_var, CTLFLAG_RW,
693 &sctp_L2_abc_variable, 0,
694 "SCTP ABC max increase per SACK (L)");
696 SYSCTL_INT(_net_inet_sctp, OID_AUTO, max_chained_mbufs, CTLFLAG_RW,
697 &sctp_mbuf_threshold_count, 0,
698 "Default max number of small mbufs on a chain");
700 SYSCTL_UINT(_net_inet_sctp, OID_AUTO, cmt_use_dac, CTLFLAG_RW,
701 &sctp_cmt_use_dac, 0,
702 "CMT DAC ON/OFF flag");
704 SYSCTL_INT(_net_inet_sctp, OID_AUTO, do_sctp_drain, CTLFLAG_RW,
706 "Should SCTP respond to the drain calls");
708 SYSCTL_INT(_net_inet_sctp, OID_AUTO, warm_crc_table, CTLFLAG_RW,
709 &sctp_warm_the_crc32_table, 0,
710 "Should the CRC32c tables be warmed before checksum?");
712 SYSCTL_INT(_net_inet_sctp, OID_AUTO, abort_at_limit, CTLFLAG_RW,
713 &sctp_abort_if_one_2_one_hits_limit, 0,
714 "When one-2-one hits qlimit abort");
716 SYSCTL_INT(_net_inet_sctp, OID_AUTO, strict_data_order, CTLFLAG_RW,
717 &sctp_strict_data_order, 0,
718 "Enforce strict data ordering, abort if control inside data");
720 SYSCTL_STRUCT(_net_inet_sctp, OID_AUTO, stats, CTLFLAG_RW,
722 "SCTP statistics (struct sctps_stat, netinet/sctp.h");
724 SYSCTL_INT(_net_inet_sctp, OID_AUTO, debug, CTLFLAG_RW,
725 &sctp_debug_on, 0, "Configure debug output");
726 #endif /* SCTP_DEBUG */
729 sctp_abort(struct socket *so)
731 struct sctp_inpcb *inp;
735 inp = (struct sctp_inpcb *)so->so_pcb;
741 flags = inp->sctp_flags;
742 #ifdef SCTP_LOG_CLOSING
743 sctp_log_closing(inp, NULL, 17);
745 if (((flags & SCTP_PCB_FLAGS_SOCKET_GONE) == 0) &&
746 (atomic_cmpset_int(&inp->sctp_flags, flags, (flags | SCTP_PCB_FLAGS_SOCKET_GONE | SCTP_PCB_FLAGS_CLOSE_IP)))) {
747 #ifdef SCTP_LOG_CLOSING
748 sctp_log_closing(inp, NULL, 16);
750 sctp_inpcb_free(inp, 1, 0);
752 so->so_snd.sb_cc = 0;
753 so->so_snd.sb_mb = NULL;
754 so->so_snd.sb_mbcnt = 0;
757 * same for the rcv ones, they are only here for the
760 so->so_rcv.sb_cc = 0;
761 so->so_rcv.sb_mb = NULL;
762 so->so_rcv.sb_mbcnt = 0;
764 * Now null out the reference, we are completely detached.
770 flags = inp->sctp_flags;
771 if ((flags & SCTP_PCB_FLAGS_SOCKET_GONE) == 0) {
772 goto sctp_must_try_again;
780 sctp_attach(struct socket *so, int proto, struct thread *p)
782 struct sctp_inpcb *inp;
783 struct inpcb *ip_inp;
791 inp = (struct sctp_inpcb *)so->so_pcb;
796 error = soreserve(so, sctp_sendspace, sctp_recvspace);
801 error = sctp_inpcb_alloc(so);
806 inp = (struct sctp_inpcb *)so->so_pcb;
809 inp->sctp_flags &= ~SCTP_PCB_FLAGS_BOUND_V6; /* I'm not v6! */
810 ip_inp = &inp->ip_inp.inp;
811 ip_inp->inp_vflag |= INP_IPV4;
812 ip_inp->inp_ip_ttl = ip_defttl;
815 error = ipsec_init_pcbpolicy(so, &ip_inp->inp_sp);
816 #ifdef SCTP_LOG_CLOSING
817 sctp_log_closing(inp, NULL, 17);
820 flags = inp->sctp_flags;
821 if (((flags & SCTP_PCB_FLAGS_SOCKET_GONE) == 0) &&
822 (atomic_cmpset_int(&inp->sctp_flags, flags, (flags | SCTP_PCB_FLAGS_SOCKET_GONE | SCTP_PCB_FLAGS_CLOSE_IP)))) {
823 #ifdef SCTP_LOG_CLOSING
824 sctp_log_closing(inp, NULL, 15);
826 sctp_inpcb_free(inp, 1, 0);
831 SCTP_INP_WUNLOCK(inp);
837 sctp_bind(struct socket *so, struct sockaddr *addr, struct thread *p)
839 struct sctp_inpcb *inp;
843 if (addr && addr->sa_family != AF_INET)
844 /* must be a v4 address! */
848 inp = (struct sctp_inpcb *)so->so_pcb;
853 error = sctp_inpcb_bind(so, addr, p);
859 sctp_close(struct socket *so)
861 struct sctp_inpcb *inp;
864 inp = (struct sctp_inpcb *)so->so_pcb;
869 * Inform all the lower layer assoc that we are done.
872 flags = inp->sctp_flags;
873 #ifdef SCTP_LOG_CLOSING
874 sctp_log_closing(inp, NULL, 17);
876 if (((flags & SCTP_PCB_FLAGS_SOCKET_GONE) == 0) &&
877 (atomic_cmpset_int(&inp->sctp_flags, flags, (flags | SCTP_PCB_FLAGS_SOCKET_GONE | SCTP_PCB_FLAGS_CLOSE_IP)))) {
878 if (((so->so_options & SO_LINGER) && (so->so_linger == 0)) ||
879 (so->so_rcv.sb_cc > 0)) {
880 #ifdef SCTP_LOG_CLOSING
881 sctp_log_closing(inp, NULL, 13);
883 sctp_inpcb_free(inp, 1, 1);
885 #ifdef SCTP_LOG_CLOSING
886 sctp_log_closing(inp, NULL, 14);
888 sctp_inpcb_free(inp, 0, 1);
891 * The socket is now detached, no matter what the state of
892 * the SCTP association.
895 so->so_snd.sb_cc = 0;
896 so->so_snd.sb_mb = NULL;
897 so->so_snd.sb_mbcnt = 0;
900 * same for the rcv ones, they are only here for the
903 so->so_rcv.sb_cc = 0;
904 so->so_rcv.sb_mb = NULL;
905 so->so_rcv.sb_mbcnt = 0;
907 * Now null out the reference, we are completely detached.
912 flags = inp->sctp_flags;
913 if ((flags & SCTP_PCB_FLAGS_SOCKET_GONE) == 0) {
914 goto sctp_must_try_again;
922 sctp_sendm(struct socket *so, int flags, struct mbuf *m, struct sockaddr *addr,
923 struct mbuf *control, struct thread *p);
927 sctp_sendm(struct socket *so, int flags, struct mbuf *m, struct sockaddr *addr,
928 struct mbuf *control, struct thread *p)
930 struct sctp_inpcb *inp;
933 inp = (struct sctp_inpcb *)so->so_pcb;
936 sctp_m_freem(control);
942 /* Got to have an to address if we are NOT a connected socket */
943 if ((addr == NULL) &&
944 ((inp->sctp_flags & SCTP_PCB_FLAGS_CONNECTED) ||
945 (inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE))
948 } else if (addr == NULL) {
949 error = EDESTADDRREQ;
952 sctp_m_freem(control);
958 if (addr->sa_family != AF_INET) {
959 /* must be a v4 address! */
962 sctp_m_freem(control);
965 error = EDESTADDRREQ;
970 /* now what about control */
973 printf("huh? control set?\n");
974 sctp_m_freem(inp->control);
977 inp->control = control;
979 /* add it in possibly */
980 if ((inp->pkt) && (inp->pkt->m_flags & M_PKTHDR)) {
986 for (x = m; x; x = x->m_next) {
989 inp->pkt->m_pkthdr.len += c_len;
993 inp->pkt_last->m_next = m;
996 inp->pkt_last = inp->pkt = m;
999 /* FreeBSD uses a flag passed */
1000 ((flags & PRUS_MORETOCOME) == 0)
1003 * note with the current version this code will only be used
1004 * by OpenBSD-- NetBSD, FreeBSD, and MacOS have methods for
1005 * re-defining sosend to use the sctp_sosend. One can
1006 * optionally switch back to this code (by changing back the
1007 * definitions) but this is not advisable. This code is used
1008 * by FreeBSD when sending a file with sendfile() though.
1012 ret = sctp_output(inp, inp->pkt, addr, inp->control, p, flags);
1014 inp->control = NULL;
1022 sctp_disconnect(struct socket *so)
1024 struct sctp_inpcb *inp;
1028 inp = (struct sctp_inpcb *)so->so_pcb;
1033 SCTP_INP_RLOCK(inp);
1034 if (inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) {
1035 if (LIST_EMPTY(&inp->sctp_asoc_list)) {
1038 SCTP_INP_RUNLOCK(inp);
1041 struct sctp_association *asoc;
1042 struct sctp_tcb *stcb;
1044 stcb = LIST_FIRST(&inp->sctp_asoc_list);
1047 SCTP_INP_RUNLOCK(inp);
1050 SCTP_TCB_LOCK(stcb);
1052 if (stcb->asoc.state & SCTP_STATE_ABOUT_TO_BE_FREED) {
1053 /* We are about to be freed, out of here */
1054 SCTP_TCB_UNLOCK(stcb);
1055 SCTP_INP_RUNLOCK(inp);
1058 if (((so->so_options & SO_LINGER) &&
1059 (so->so_linger == 0)) ||
1060 (so->so_rcv.sb_cc > 0)) {
1061 if (SCTP_GET_STATE(asoc) !=
1062 SCTP_STATE_COOKIE_WAIT) {
1063 /* Left with Data unread */
1066 err = sctp_get_mbuf_for_msg(sizeof(struct sctp_paramhdr), 0, M_DONTWAIT, 1, MT_DATA);
1072 struct sctp_paramhdr *ph;
1074 ph = mtod(err, struct sctp_paramhdr *);
1075 err->m_len = sizeof(struct sctp_paramhdr);
1076 ph->param_type = htons(SCTP_CAUSE_USER_INITIATED_ABT);
1077 ph->param_length = htons(err->m_len);
1079 sctp_send_abort_tcb(stcb, err);
1080 SCTP_STAT_INCR_COUNTER32(sctps_aborted);
1082 SCTP_INP_RUNLOCK(inp);
1083 if ((SCTP_GET_STATE(&stcb->asoc) == SCTP_STATE_OPEN) ||
1084 (SCTP_GET_STATE(&stcb->asoc) == SCTP_STATE_SHUTDOWN_RECEIVED)) {
1085 SCTP_STAT_DECR_GAUGE32(sctps_currestab);
1087 sctp_free_assoc(inp, stcb, 0);
1088 /* No unlock tcb assoc is gone */
1092 if (TAILQ_EMPTY(&asoc->send_queue) &&
1093 TAILQ_EMPTY(&asoc->sent_queue) &&
1094 (asoc->stream_queue_cnt == 0)) {
1095 /* there is nothing queued to send, so done */
1096 if (asoc->locked_on_sending) {
1099 if ((SCTP_GET_STATE(asoc) !=
1100 SCTP_STATE_SHUTDOWN_SENT) &&
1101 (SCTP_GET_STATE(asoc) !=
1102 SCTP_STATE_SHUTDOWN_ACK_SENT)) {
1103 /* only send SHUTDOWN 1st time thru */
1104 sctp_stop_timers_for_shutdown(stcb);
1105 sctp_send_shutdown(stcb,
1106 stcb->asoc.primary_destination);
1107 sctp_chunk_output(stcb->sctp_ep, stcb, SCTP_OUTPUT_FROM_T3);
1108 asoc->state = SCTP_STATE_SHUTDOWN_SENT;
1109 SCTP_STAT_DECR_GAUGE32(sctps_currestab);
1110 sctp_timer_start(SCTP_TIMER_TYPE_SHUTDOWN,
1111 stcb->sctp_ep, stcb,
1112 asoc->primary_destination);
1113 sctp_timer_start(SCTP_TIMER_TYPE_SHUTDOWNGUARD,
1114 stcb->sctp_ep, stcb,
1115 asoc->primary_destination);
1119 * we still got (or just got) data to send,
1120 * so set SHUTDOWN_PENDING
1123 * XXX sockets draft says that SCTP_EOF
1124 * should be sent with no data. currently,
1125 * we will allow user data to be sent first
1126 * and move to SHUTDOWN-PENDING
1128 asoc->state |= SCTP_STATE_SHUTDOWN_PENDING;
1129 sctp_timer_start(SCTP_TIMER_TYPE_SHUTDOWNGUARD, stcb->sctp_ep, stcb,
1130 asoc->primary_destination);
1131 if (asoc->locked_on_sending) {
1132 /* Locked to send out the data */
1133 struct sctp_stream_queue_pending *sp;
1135 sp = TAILQ_LAST(&asoc->locked_on_sending->outqueue, sctp_streamhead);
1137 printf("Error, sp is NULL, locked on sending is non-null strm:%d\n",
1138 asoc->locked_on_sending->stream_no);
1140 if ((sp->length == 0) && (sp->msg_is_complete == 0))
1141 asoc->state |= SCTP_STATE_PARTIAL_MSG_LEFT;
1144 if (TAILQ_EMPTY(&asoc->send_queue) &&
1145 TAILQ_EMPTY(&asoc->sent_queue) &&
1146 (asoc->state & SCTP_STATE_PARTIAL_MSG_LEFT)) {
1147 struct mbuf *op_err;
1150 op_err = sctp_get_mbuf_for_msg((sizeof(struct sctp_paramhdr) + sizeof(uint32_t)),
1151 0, M_DONTWAIT, 1, MT_DATA);
1157 struct sctp_paramhdr *ph;
1161 (sizeof(struct sctp_paramhdr) + sizeof(uint32_t));
1163 struct sctp_paramhdr *);
1164 ph->param_type = htons(
1165 SCTP_CAUSE_USER_INITIATED_ABT);
1166 ph->param_length = htons(op_err->m_len);
1167 ippp = (uint32_t *) (ph + 1);
1168 *ippp = htonl(0x30000007);
1170 sctp_send_abort_tcb(stcb, op_err);
1171 SCTP_STAT_INCR_COUNTER32(sctps_aborted);
1172 if ((SCTP_GET_STATE(&stcb->asoc) == SCTP_STATE_OPEN) ||
1173 (SCTP_GET_STATE(&stcb->asoc) == SCTP_STATE_SHUTDOWN_RECEIVED)) {
1174 SCTP_STAT_DECR_GAUGE32(sctps_currestab);
1176 SCTP_INP_RUNLOCK(inp);
1177 sctp_free_assoc(inp, stcb, 0);
1182 SCTP_TCB_UNLOCK(stcb);
1183 SCTP_INP_RUNLOCK(inp);
1189 /* UDP model does not support this */
1190 SCTP_INP_RUNLOCK(inp);
1197 sctp_shutdown(struct socket *so)
1199 struct sctp_inpcb *inp;
1203 inp = (struct sctp_inpcb *)so->so_pcb;
1208 SCTP_INP_RLOCK(inp);
1209 /* For UDP model this is a invalid call */
1210 if (inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) {
1211 /* Restore the flags that the soshutdown took away. */
1212 so->so_rcv.sb_state &= ~SBS_CANTRCVMORE;
1213 /* This proc will wakeup for read and do nothing (I hope) */
1215 SCTP_INP_RUNLOCK(inp);
1216 return (EOPNOTSUPP);
1219 * Ok if we reach here its the TCP model and it is either a SHUT_WR
1220 * or SHUT_RDWR. This means we put the shutdown flag against it.
1223 struct sctp_tcb *stcb;
1224 struct sctp_association *asoc;
1228 stcb = LIST_FIRST(&inp->sctp_asoc_list);
1231 * Ok we hit the case that the shutdown call was
1232 * made after an abort or something. Nothing to do
1238 SCTP_TCB_LOCK(stcb);
1240 if (TAILQ_EMPTY(&asoc->send_queue) &&
1241 TAILQ_EMPTY(&asoc->sent_queue) &&
1242 (asoc->stream_queue_cnt == 0)) {
1243 if (asoc->locked_on_sending) {
1246 /* there is nothing queued to send, so I'm done... */
1247 if (SCTP_GET_STATE(asoc) != SCTP_STATE_SHUTDOWN_SENT) {
1248 /* only send SHUTDOWN the first time through */
1249 sctp_stop_timers_for_shutdown(stcb);
1250 sctp_send_shutdown(stcb,
1251 stcb->asoc.primary_destination);
1252 sctp_chunk_output(stcb->sctp_ep, stcb, SCTP_OUTPUT_FROM_T3);
1253 asoc->state = SCTP_STATE_SHUTDOWN_SENT;
1254 SCTP_STAT_DECR_GAUGE32(sctps_currestab);
1255 sctp_timer_start(SCTP_TIMER_TYPE_SHUTDOWN,
1256 stcb->sctp_ep, stcb,
1257 asoc->primary_destination);
1258 sctp_timer_start(SCTP_TIMER_TYPE_SHUTDOWNGUARD,
1259 stcb->sctp_ep, stcb,
1260 asoc->primary_destination);
1264 * we still got (or just got) data to send, so set
1267 asoc->state |= SCTP_STATE_SHUTDOWN_PENDING;
1268 sctp_timer_start(SCTP_TIMER_TYPE_SHUTDOWNGUARD, stcb->sctp_ep, stcb,
1269 asoc->primary_destination);
1271 if (asoc->locked_on_sending) {
1272 /* Locked to send out the data */
1273 struct sctp_stream_queue_pending *sp;
1275 sp = TAILQ_LAST(&asoc->locked_on_sending->outqueue, sctp_streamhead);
1277 printf("Error, sp is NULL, locked on sending is non-null strm:%d\n",
1278 asoc->locked_on_sending->stream_no);
1280 if ((sp->length == 0) && (sp->msg_is_complete == 0)) {
1281 asoc->state |= SCTP_STATE_PARTIAL_MSG_LEFT;
1285 if (TAILQ_EMPTY(&asoc->send_queue) &&
1286 TAILQ_EMPTY(&asoc->sent_queue) &&
1287 (asoc->state & SCTP_STATE_PARTIAL_MSG_LEFT)) {
1288 struct mbuf *op_err;
1291 op_err = sctp_get_mbuf_for_msg((sizeof(struct sctp_paramhdr) + sizeof(uint32_t)),
1292 0, M_DONTWAIT, 1, MT_DATA);
1294 /* Fill in the user initiated abort */
1295 struct sctp_paramhdr *ph;
1299 sizeof(struct sctp_paramhdr) + sizeof(uint32_t);
1301 struct sctp_paramhdr *);
1302 ph->param_type = htons(
1303 SCTP_CAUSE_USER_INITIATED_ABT);
1304 ph->param_length = htons(op_err->m_len);
1305 ippp = (uint32_t *) (ph + 1);
1306 *ippp = htonl(0x30000008);
1308 sctp_abort_an_association(stcb->sctp_ep, stcb,
1309 SCTP_RESPONSE_TO_USER_REQ,
1314 SCTP_TCB_UNLOCK(stcb);
1317 SCTP_INP_RUNLOCK(inp);
1323 * copies a "user" presentable address and removes embedded scope, etc.
1324 * returns 0 on success, 1 on error
1327 sctp_fill_user_address(struct sockaddr_storage *ss, struct sockaddr *sa)
1329 struct sockaddr_in6 lsa6;
1331 sa = (struct sockaddr *)sctp_recover_scope((struct sockaddr_in6 *)sa,
1333 memcpy(ss, sa, sa->sa_len);
1340 sctp_fill_up_addresses(struct sctp_inpcb *inp,
1341 struct sctp_tcb *stcb,
1343 struct sockaddr_storage *sas)
1347 int loopback_scope, ipv4_local_scope, local_scope, site_scope, actual;
1348 int ipv4_addr_legal, ipv6_addr_legal;
1355 /* Turn on all the appropriate scope */
1356 loopback_scope = stcb->asoc.loopback_scope;
1357 ipv4_local_scope = stcb->asoc.ipv4_local_scope;
1358 local_scope = stcb->asoc.local_scope;
1359 site_scope = stcb->asoc.site_scope;
1361 /* Turn on ALL scope, since we look at the EP */
1362 loopback_scope = ipv4_local_scope = local_scope =
1365 ipv4_addr_legal = ipv6_addr_legal = 0;
1366 if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) {
1367 ipv6_addr_legal = 1;
1369 (((struct in6pcb *)inp)->inp_flags & IN6P_IPV6_V6ONLY)
1371 ipv4_addr_legal = 1;
1374 ipv4_addr_legal = 1;
1377 if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUNDALL) {
1378 TAILQ_FOREACH(ifn, &ifnet, if_list) {
1379 if ((loopback_scope == 0) &&
1380 (ifn->if_type == IFT_LOOP)) {
1381 /* Skip loopback if loopback_scope not set */
1384 TAILQ_FOREACH(ifa, &ifn->if_addrlist, ifa_list) {
1387 * For the BOUND-ALL case, the list
1388 * associated with a TCB is Always
1389 * considered a reverse list.. i.e.
1390 * it lists addresses that are NOT
1391 * part of the association. If this
1392 * is one of those we must skip it.
1394 if (sctp_is_addr_restricted(stcb,
1399 if ((ifa->ifa_addr->sa_family == AF_INET) &&
1400 (ipv4_addr_legal)) {
1401 struct sockaddr_in *sin;
1403 sin = (struct sockaddr_in *)ifa->ifa_addr;
1404 if (sin->sin_addr.s_addr == 0) {
1406 * we skip unspecifed
1411 if ((ipv4_local_scope == 0) &&
1412 (IN4_ISPRIVATE_ADDRESS(&sin->sin_addr))) {
1415 if (inp->sctp_flags & SCTP_PCB_FLAGS_NEEDS_MAPPED_V4) {
1416 in6_sin_2_v4mapsin6(sin, (struct sockaddr_in6 *)sas);
1417 ((struct sockaddr_in6 *)sas)->sin6_port = inp->sctp_lport;
1418 sas = (struct sockaddr_storage *)((caddr_t)sas + sizeof(struct sockaddr_in6));
1419 actual += sizeof(sizeof(struct sockaddr_in6));
1421 memcpy(sas, sin, sizeof(*sin));
1422 ((struct sockaddr_in *)sas)->sin_port = inp->sctp_lport;
1423 sas = (struct sockaddr_storage *)((caddr_t)sas + sizeof(*sin));
1424 actual += sizeof(*sin);
1426 if (actual >= limit) {
1429 } else if ((ifa->ifa_addr->sa_family == AF_INET6) &&
1430 (ipv6_addr_legal)) {
1431 struct sockaddr_in6 *sin6;
1433 sin6 = (struct sockaddr_in6 *)ifa->ifa_addr;
1434 if (IN6_IS_ADDR_UNSPECIFIED(&sin6->sin6_addr)) {
1436 * we skip unspecifed
1441 if (IN6_IS_ADDR_LINKLOCAL(&sin6->sin6_addr)) {
1442 if (local_scope == 0)
1444 if (sin6->sin6_scope_id == 0) {
1445 if (sa6_recoverscope(sin6) != 0)
1454 if ((site_scope == 0) &&
1455 (IN6_IS_ADDR_SITELOCAL(&sin6->sin6_addr))) {
1458 memcpy(sas, sin6, sizeof(*sin6));
1459 ((struct sockaddr_in6 *)sas)->sin6_port = inp->sctp_lport;
1460 sas = (struct sockaddr_storage *)((caddr_t)sas + sizeof(*sin6));
1461 actual += sizeof(*sin6);
1462 if (actual >= limit) {
1469 struct sctp_laddr *laddr;
1472 * If we have a TCB and we do NOT support ASCONF (it's
1473 * turned off or otherwise) then the list is always the true
1474 * list of addresses (the else case below). Otherwise the
1475 * list on the association is a list of addresses that are
1476 * NOT part of the association.
1478 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_DO_ASCONF)) {
1479 /* The list is a NEGATIVE list */
1480 LIST_FOREACH(laddr, &inp->sctp_addr_list, sctp_nxt_addr) {
1482 if (sctp_is_addr_restricted(stcb, laddr->ifa->ifa_addr)) {
1486 if (sctp_fill_user_address(sas, laddr->ifa->ifa_addr))
1489 ((struct sockaddr_in6 *)sas)->sin6_port = inp->sctp_lport;
1490 sas = (struct sockaddr_storage *)((caddr_t)sas +
1491 laddr->ifa->ifa_addr->sa_len);
1492 actual += laddr->ifa->ifa_addr->sa_len;
1493 if (actual >= limit) {
1498 /* The list is a positive list if present */
1500 /* Must use the specific association list */
1501 LIST_FOREACH(laddr, &stcb->asoc.sctp_local_addr_list,
1503 if (sctp_fill_user_address(sas,
1504 laddr->ifa->ifa_addr))
1506 ((struct sockaddr_in6 *)sas)->sin6_port = inp->sctp_lport;
1507 sas = (struct sockaddr_storage *)((caddr_t)sas +
1508 laddr->ifa->ifa_addr->sa_len);
1509 actual += laddr->ifa->ifa_addr->sa_len;
1510 if (actual >= limit) {
1516 * No endpoint so use the endpoints
1519 LIST_FOREACH(laddr, &inp->sctp_addr_list,
1521 if (sctp_fill_user_address(sas,
1522 laddr->ifa->ifa_addr))
1524 ((struct sockaddr_in6 *)sas)->sin6_port = inp->sctp_lport;
1525 sas = (struct sockaddr_storage *)((caddr_t)sas +
1526 laddr->ifa->ifa_addr->sa_len);
1527 actual += laddr->ifa->ifa_addr->sa_len;
1528 if (actual >= limit) {
1539 sctp_count_max_addresses(struct sctp_inpcb *inp)
1544 * In both sub-set bound an bound_all cases we return the MAXIMUM
1545 * number of addresses that you COULD get. In reality the sub-set
1546 * bound may have an exclusion list for a given TCB OR in the
1547 * bound-all case a TCB may NOT include the loopback or other
1548 * addresses as well.
1550 if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUNDALL) {
1554 TAILQ_FOREACH(ifn, &ifnet, if_list) {
1555 TAILQ_FOREACH(ifa, &ifn->if_addrlist, ifa_list) {
1556 /* Count them if they are the right type */
1557 if (ifa->ifa_addr->sa_family == AF_INET) {
1558 if (inp->sctp_flags & SCTP_PCB_FLAGS_NEEDS_MAPPED_V4)
1559 cnt += sizeof(struct sockaddr_in6);
1561 cnt += sizeof(struct sockaddr_in);
1563 } else if (ifa->ifa_addr->sa_family == AF_INET6)
1564 cnt += sizeof(struct sockaddr_in6);
1568 struct sctp_laddr *laddr;
1570 LIST_FOREACH(laddr, &inp->sctp_addr_list, sctp_nxt_addr) {
1571 if (laddr->ifa->ifa_addr->sa_family == AF_INET) {
1572 if (inp->sctp_flags & SCTP_PCB_FLAGS_NEEDS_MAPPED_V4)
1573 cnt += sizeof(struct sockaddr_in6);
1575 cnt += sizeof(struct sockaddr_in);
1577 } else if (laddr->ifa->ifa_addr->sa_family == AF_INET6)
1578 cnt += sizeof(struct sockaddr_in6);
1585 sctp_do_connect_x(struct socket *so,
1586 struct sctp_inpcb *inp,
1595 int creat_lock_on = 0;
1596 struct sctp_tcb *stcb = NULL;
1597 struct sockaddr *sa;
1598 int num_v6 = 0, num_v4 = 0, *totaddrp, totaddr, i, incr, at;
1601 if (sctp_debug_on & SCTP_DEBUG_PCB1) {
1602 printf("Connectx called\n");
1604 #endif /* SCTP_DEBUG */
1606 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) &&
1607 (inp->sctp_flags & SCTP_PCB_FLAGS_CONNECTED)) {
1608 /* We are already connected AND the TCP model */
1610 return (EADDRINUSE);
1612 if (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) {
1616 if (inp->sctp_flags & SCTP_PCB_FLAGS_CONNECTED) {
1617 SCTP_INP_RLOCK(inp);
1618 stcb = LIST_FIRST(&inp->sctp_asoc_list);
1619 SCTP_INP_RUNLOCK(inp);
1626 SCTP_INP_INCR_REF(inp);
1627 SCTP_ASOC_CREATE_LOCK(inp);
1629 if ((inp->sctp_flags & SCTP_PCB_FLAGS_SOCKET_ALLGONE) ||
1630 (inp->sctp_flags & SCTP_PCB_FLAGS_SOCKET_GONE)) {
1634 totaddrp = mtod(m, int *);
1635 totaddr = *totaddrp;
1636 sa = (struct sockaddr *)(totaddrp + 1);
1638 /* account and validate addresses */
1639 for (i = 0; i < totaddr; i++) {
1640 if (sa->sa_family == AF_INET) {
1642 incr = sizeof(struct sockaddr_in);
1643 } else if (sa->sa_family == AF_INET6) {
1644 struct sockaddr_in6 *sin6;
1646 sin6 = (struct sockaddr_in6 *)sa;
1647 if (IN6_IS_ADDR_V4MAPPED(&sin6->sin6_addr)) {
1648 /* Must be non-mapped for connectx */
1653 incr = sizeof(struct sockaddr_in6);
1658 stcb = sctp_findassociation_ep_addr(&inp, sa, NULL, NULL, NULL);
1660 /* Already have or am bring up an association */
1661 SCTP_ASOC_CREATE_UNLOCK(inp);
1663 SCTP_TCB_UNLOCK(stcb);
1667 if ((at + incr) > m->m_len) {
1671 sa = (struct sockaddr *)((caddr_t)sa + incr);
1673 sa = (struct sockaddr *)(totaddrp + 1);
1675 if (((inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) == 0) &&
1681 if ((inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) &&
1683 struct in6pcb *inp6;
1685 inp6 = (struct in6pcb *)inp;
1687 (inp6->inp_flags & IN6P_IPV6_V6ONLY)
1690 * if IPV6_V6ONLY flag, ignore connections destined
1691 * to a v4 addr or v4-mapped addr
1698 if ((inp->sctp_flags & SCTP_PCB_FLAGS_UNBOUND) ==
1699 SCTP_PCB_FLAGS_UNBOUND) {
1700 /* Bind a ephemeral port */
1701 SCTP_INP_WUNLOCK(inp);
1702 error = sctp_inpcb_bind(so, NULL, p);
1707 SCTP_INP_WUNLOCK(inp);
1710 /* We are GOOD to go */
1711 stcb = sctp_aloc_assoc(inp, sa, 1, &error, 0);
1713 /* Gak! no memory */
1717 /* move to second address */
1718 if (sa->sa_family == AF_INET)
1719 sa = (struct sockaddr *)((caddr_t)sa + sizeof(struct sockaddr_in));
1721 sa = (struct sockaddr *)((caddr_t)sa + sizeof(struct sockaddr_in6));
1723 for (i = 1; i < totaddr; i++) {
1724 if (sa->sa_family == AF_INET) {
1725 incr = sizeof(struct sockaddr_in);
1726 if (sctp_add_remote_addr(stcb, sa, 0, 8)) {
1727 /* assoc gone no un-lock */
1728 sctp_free_assoc(inp, stcb, 0);
1732 } else if (sa->sa_family == AF_INET6) {
1733 incr = sizeof(struct sockaddr_in6);
1734 if (sctp_add_remote_addr(stcb, sa, 0, 8)) {
1735 /* assoc gone no un-lock */
1736 sctp_free_assoc(inp, stcb, 0);
1741 sa = (struct sockaddr *)((caddr_t)sa + incr);
1743 stcb->asoc.state = SCTP_STATE_COOKIE_WAIT;
1745 /* initialize authentication parameters for the assoc */
1746 sctp_initialize_auth_params(inp, stcb);
1749 /* doing delayed connection */
1750 stcb->asoc.delayed_connection = 1;
1751 sctp_timer_start(SCTP_TIMER_TYPE_INIT, inp, stcb, stcb->asoc.primary_destination);
1753 SCTP_GETTIME_TIMEVAL(&stcb->asoc.time_entered);
1754 sctp_send_initiate(inp, stcb);
1756 SCTP_TCB_UNLOCK(stcb);
1757 if (stcb->sctp_ep->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) {
1758 stcb->sctp_ep->sctp_flags |= SCTP_PCB_FLAGS_CONNECTED;
1759 /* Set the connected flag so we can queue data */
1764 SCTP_ASOC_CREATE_UNLOCK(inp);
1765 SCTP_INP_DECR_REF(inp);
1773 sctp_optsget(struct socket *so,
1779 struct sctp_inpcb *inp;
1781 int error, optval = 0;
1782 struct sctp_tcb *stcb = NULL;
1784 inp = (struct sctp_inpcb *)so->so_pcb;
1794 /* Got to have a mbuf */
1799 case SCTP_AUTOCLOSE:
1800 case SCTP_EXPLICIT_EOR:
1801 case SCTP_AUTO_ASCONF:
1802 case SCTP_DISABLE_FRAGMENTS:
1803 case SCTP_I_WANT_MAPPED_V4_ADDR:
1804 case SCTP_USE_EXT_RCVINFO:
1805 SCTP_INP_RLOCK(inp);
1807 case SCTP_DISABLE_FRAGMENTS:
1808 optval = sctp_is_feature_on(inp, SCTP_PCB_FLAGS_NO_FRAGMENT);
1810 case SCTP_I_WANT_MAPPED_V4_ADDR:
1811 optval = sctp_is_feature_on(inp, SCTP_PCB_FLAGS_NEEDS_MAPPED_V4);
1813 case SCTP_AUTO_ASCONF:
1814 optval = sctp_is_feature_on(inp, SCTP_PCB_FLAGS_AUTO_ASCONF);
1816 case SCTP_EXPLICIT_EOR:
1817 optval = sctp_is_feature_on(inp, SCTP_PCB_FLAGS_EXPLICIT_EOR);
1820 optval = sctp_is_feature_on(inp, SCTP_PCB_FLAGS_NODELAY);
1822 case SCTP_USE_EXT_RCVINFO:
1823 optval = sctp_is_feature_on(inp, SCTP_PCB_FLAGS_EXT_RCVINFO);
1825 case SCTP_AUTOCLOSE:
1826 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_AUTOCLOSE))
1827 optval = TICKS_TO_SEC(inp->sctp_ep.auto_close_time);
1833 error = ENOPROTOOPT;
1834 } /* end switch (sopt->sopt_name) */
1835 if (opt != SCTP_AUTOCLOSE) {
1836 /* make it an "on/off" value */
1837 optval = (optval != 0);
1839 if ((size_t)m->m_len < sizeof(int)) {
1842 SCTP_INP_RUNLOCK(inp);
1844 /* return the option value */
1845 *mtod(m, int *)= optval;
1846 m->m_len = sizeof(optval);
1849 case SCTP_PARTIAL_DELIVERY_POINT:
1851 if ((size_t)m->m_len < sizeof(unsigned int)) {
1855 *mtod(m, unsigned int *)= inp->partial_delivery_point;
1856 m->m_len = sizeof(unsigned int);
1859 case SCTP_FRAGMENT_INTERLEAVE:
1861 if ((size_t)m->m_len < sizeof(unsigned int)) {
1865 *mtod(m, unsigned int *)= sctp_is_feature_on(inp, SCTP_PCB_FLAGS_FRAG_INTERLEAVE);
1866 m->m_len = sizeof(unsigned int);
1869 case SCTP_CMT_ON_OFF:
1871 if ((size_t)m->m_len < sizeof(unsigned int)) {
1875 *mtod(m, unsigned int *)= sctp_cmt_sockopt_on_off;
1876 m->m_len = sizeof(unsigned int);
1879 case SCTP_CMT_USE_DAC:
1881 *mtod(m, unsigned int *)= sctp_cmt_sockopt_use_dac;
1882 m->m_len = sizeof(unsigned int);
1885 case SCTP_GET_ADDR_LEN:
1887 struct sctp_assoc_value *av;
1889 if ((size_t)m->m_len < sizeof(struct sctp_assoc_value)) {
1893 av = mtod(m, struct sctp_assoc_value *);
1896 if (av->assoc_value == AF_INET) {
1897 av->assoc_value = sizeof(struct sockaddr_in);
1902 if (av->assoc_value == AF_INET6) {
1903 av->assoc_value = sizeof(struct sockaddr_in6);
1909 case SCTP_GET_ASOC_ID_LIST:
1911 struct sctp_assoc_ids *ids;
1915 if ((size_t)m->m_len < sizeof(struct sctp_assoc_ids)) {
1919 ids = mtod(m, struct sctp_assoc_ids *);
1921 SCTP_INP_RLOCK(inp);
1922 stcb = LIST_FIRST(&inp->sctp_asoc_list);
1925 ids->asls_numb_present = 0;
1926 ids->asls_more_to_get = 0;
1927 SCTP_INP_RUNLOCK(inp);
1930 orig = ids->asls_assoc_start;
1931 stcb = LIST_FIRST(&inp->sctp_asoc_list);
1933 stcb = LIST_NEXT(stcb, sctp_tcblist);
1943 ids->asls_numb_present = 0;
1944 ids->asls_more_to_get = 1;
1945 while (at < MAX_ASOC_IDS_RET) {
1946 ids->asls_assoc_id[at] = sctp_get_associd(stcb);
1948 ids->asls_numb_present++;
1949 stcb = LIST_NEXT(stcb, sctp_tcblist);
1951 ids->asls_more_to_get = 0;
1955 SCTP_INP_RUNLOCK(inp);
1961 struct sctp_assoc_value *av;
1963 if ((size_t)m->m_len < sizeof(struct sctp_assoc_value)) {
1967 av = mtod(m, struct sctp_assoc_value *);
1969 stcb = sctp_findassociation_ep_asocid(inp, av->assoc_id, 1);
1973 av->assoc_value = stcb->asoc.context;
1974 SCTP_TCB_UNLOCK(stcb);
1977 av->assoc_value = inp->sctp_context;
1981 case SCTP_GET_NONCE_VALUES:
1983 struct sctp_get_nonce_values *gnv;
1985 if ((size_t)m->m_len < sizeof(struct sctp_get_nonce_values)) {
1989 gnv = mtod(m, struct sctp_get_nonce_values *);
1990 stcb = sctp_findassociation_ep_asocid(inp, gnv->gn_assoc_id, 1);
1994 gnv->gn_peers_tag = stcb->asoc.peer_vtag;
1995 gnv->gn_local_tag = stcb->asoc.my_vtag;
1996 SCTP_TCB_UNLOCK(stcb);
2001 case SCTP_DELAYED_ACK_TIME:
2003 struct sctp_assoc_value *tm;
2005 if ((size_t)m->m_len < sizeof(struct sctp_assoc_value)) {
2009 tm = mtod(m, struct sctp_assoc_value *);
2011 if (inp->sctp_flags & SCTP_PCB_FLAGS_CONNECTED) {
2012 SCTP_INP_RLOCK(inp);
2013 stcb = LIST_FIRST(&inp->sctp_asoc_list);
2015 SCTP_TCB_LOCK(stcb);
2016 tm->assoc_value = stcb->asoc.delayed_ack;
2017 SCTP_TCB_UNLOCK(stcb);
2019 tm->assoc_value = TICKS_TO_MSEC(inp->sctp_ep.sctp_timeoutticks[SCTP_TIMER_RECV]);
2021 SCTP_INP_RUNLOCK(inp);
2023 stcb = sctp_findassociation_ep_asocid(inp, tm->assoc_id, 1);
2026 tm->assoc_value = 0;
2028 stcb->asoc.delayed_ack = tm->assoc_value;
2029 SCTP_TCB_UNLOCK(stcb);
2035 case SCTP_GET_SNDBUF_USE:
2036 if ((size_t)m->m_len < sizeof(struct sctp_sockstat)) {
2039 struct sctp_sockstat *ss;
2040 struct sctp_tcb *stcb;
2041 struct sctp_association *asoc;
2043 ss = mtod(m, struct sctp_sockstat *);
2044 stcb = sctp_findassociation_ep_asocid(inp, ss->ss_assoc_id, 1);
2049 ss->ss_total_sndbuf = (uint32_t) asoc->total_output_queue_size;
2050 ss->ss_total_recv_buf = (uint32_t) (asoc->size_on_reasm_queue +
2051 asoc->size_on_all_streams);
2052 SCTP_TCB_UNLOCK(stcb);
2054 m->m_len = sizeof(struct sctp_sockstat);
2062 burst = mtod(m, uint8_t *);
2063 SCTP_INP_RLOCK(inp);
2064 *burst = inp->sctp_ep.max_burst;
2065 SCTP_INP_RUNLOCK(inp);
2066 m->m_len = sizeof(uint8_t);
2073 sctp_assoc_t *assoc_id;
2076 if ((size_t)m->m_len < sizeof(uint32_t)) {
2080 if ((size_t)m->m_len < sizeof(sctp_assoc_t)) {
2084 assoc_id = mtod(m, sctp_assoc_t *);
2085 segsize = mtod(m, uint32_t *);
2086 m->m_len = sizeof(uint32_t);
2088 if (((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) &&
2089 (inp->sctp_flags & SCTP_PCB_FLAGS_CONNECTED)) ||
2090 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL)) {
2091 struct sctp_tcb *stcb;
2093 SCTP_INP_RLOCK(inp);
2094 stcb = LIST_FIRST(&inp->sctp_asoc_list);
2096 SCTP_TCB_LOCK(stcb);
2097 SCTP_INP_RUNLOCK(inp);
2098 *segsize = sctp_get_frag_point(stcb, &stcb->asoc);
2099 SCTP_TCB_UNLOCK(stcb);
2101 SCTP_INP_RUNLOCK(inp);
2105 stcb = sctp_findassociation_ep_asocid(inp, *assoc_id, 1);
2107 *segsize = sctp_get_frag_point(stcb, &stcb->asoc);
2108 SCTP_TCB_UNLOCK(stcb);
2113 * default is to get the max, if I can't
2114 * calculate from an existing association.
2116 if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) {
2117 ovh = SCTP_MED_OVERHEAD;
2119 ovh = SCTP_MED_V4_OVERHEAD;
2121 *segsize = inp->sctp_frag_point - ovh;
2126 case SCTP_SET_DEBUG_LEVEL:
2131 if ((size_t)m->m_len < sizeof(uint32_t)) {
2135 level = mtod(m, uint32_t *);
2137 *level = sctp_debug_on;
2138 m->m_len = sizeof(uint32_t);
2139 printf("Returning DEBUG LEVEL %x is set\n",
2140 (uint32_t) sctp_debug_on);
2142 #else /* SCTP_DEBUG */
2146 case SCTP_GET_STAT_LOG:
2147 #ifdef SCTP_STAT_LOGGING
2148 error = sctp_fill_stat_log(m);
2149 #else /* SCTP_DEBUG */
2155 struct sctp_event_subscribe *events;
2157 if ((size_t)m->m_len < sizeof(struct sctp_event_subscribe)) {
2161 events = mtod(m, struct sctp_event_subscribe *);
2162 memset(events, 0, sizeof(*events));
2163 SCTP_INP_RLOCK(inp);
2164 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_RECVDATAIOEVNT))
2165 events->sctp_data_io_event = 1;
2167 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_RECVASSOCEVNT))
2168 events->sctp_association_event = 1;
2170 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_RECVPADDREVNT))
2171 events->sctp_address_event = 1;
2173 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_RECVSENDFAILEVNT))
2174 events->sctp_send_failure_event = 1;
2176 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_RECVPEERERR))
2177 events->sctp_peer_error_event = 1;
2179 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_RECVSHUTDOWNEVNT))
2180 events->sctp_shutdown_event = 1;
2182 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_PDAPIEVNT))
2183 events->sctp_partial_delivery_event = 1;
2185 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_ADAPTATIONEVNT))
2186 events->sctp_adaptation_layer_event = 1;
2188 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_AUTHEVNT))
2189 events->sctp_authentication_event = 1;
2191 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_STREAM_RESETEVNT))
2192 events->sctp_stream_reset_events = 1;
2193 SCTP_INP_RUNLOCK(inp);
2194 m->m_len = sizeof(struct sctp_event_subscribe);
2199 case SCTP_ADAPTATION_LAYER:
2200 if ((size_t)m->m_len < sizeof(int)) {
2204 SCTP_INP_RLOCK(inp);
2205 *mtod(m, int *)= inp->sctp_ep.adaptation_layer_indicator;
2206 SCTP_INP_RUNLOCK(inp);
2207 m->m_len = sizeof(int);
2209 case SCTP_SET_INITIAL_DBG_SEQ:
2210 if ((size_t)m->m_len < sizeof(int)) {
2214 SCTP_INP_RLOCK(inp);
2215 *mtod(m, int *)= inp->sctp_ep.initial_sequence_debug;
2216 SCTP_INP_RUNLOCK(inp);
2217 m->m_len = sizeof(int);
2219 case SCTP_GET_LOCAL_ADDR_SIZE:
2220 if ((size_t)m->m_len < sizeof(int)) {
2224 SCTP_INP_RLOCK(inp);
2225 *mtod(m, int *)= sctp_count_max_addresses(inp);
2226 SCTP_INP_RUNLOCK(inp);
2227 m->m_len = sizeof(int);
2229 case SCTP_GET_REMOTE_ADDR_SIZE:
2231 sctp_assoc_t *assoc_id;
2233 struct sctp_nets *net;
2235 if ((size_t)m->m_len < sizeof(sctp_assoc_t)) {
2240 val = mtod(m, uint32_t *);
2241 if (inp->sctp_flags & SCTP_PCB_FLAGS_CONNECTED) {
2242 SCTP_INP_RLOCK(inp);
2243 stcb = LIST_FIRST(&inp->sctp_asoc_list);
2245 SCTP_TCB_LOCK(stcb);
2246 SCTP_INP_RUNLOCK(inp);
2249 assoc_id = mtod(m, sctp_assoc_t *);
2250 stcb = sctp_findassociation_ep_asocid(inp, *assoc_id, 1);
2258 /* Count the sizes */
2259 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
2260 if ((stcb->sctp_ep->sctp_flags & SCTP_PCB_FLAGS_NEEDS_MAPPED_V4) ||
2261 (((struct sockaddr *)&net->ro._l_addr)->sa_family == AF_INET6)) {
2262 sz += sizeof(struct sockaddr_in6);
2263 } else if (((struct sockaddr *)&net->ro._l_addr)->sa_family == AF_INET) {
2264 sz += sizeof(struct sockaddr_in);
2270 SCTP_TCB_UNLOCK(stcb);
2272 m->m_len = sizeof(uint32_t);
2275 case SCTP_GET_PEER_ADDRESSES:
2277 * Get the address information, an array is passed in to
2278 * fill up we pack it.
2282 struct sockaddr_storage *sas;
2283 struct sctp_nets *net;
2284 struct sctp_getaddresses *saddr;
2286 if ((size_t)m->m_len < sizeof(struct sctp_getaddresses)) {
2290 left = m->m_len - sizeof(struct sctp_getaddresses);
2291 saddr = mtod(m, struct sctp_getaddresses *);
2292 if (inp->sctp_flags & SCTP_PCB_FLAGS_CONNECTED) {
2293 SCTP_INP_RLOCK(inp);
2294 stcb = LIST_FIRST(&inp->sctp_asoc_list);
2296 SCTP_TCB_LOCK(stcb);
2297 SCTP_INP_RUNLOCK(inp);
2299 stcb = sctp_findassociation_ep_asocid(inp,
2300 saddr->sget_assoc_id, 1);
2305 m->m_len = sizeof(struct sctp_getaddresses);
2306 sas = (struct sockaddr_storage *)&saddr->addr[0];
2308 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
2309 if ((stcb->sctp_ep->sctp_flags & SCTP_PCB_FLAGS_NEEDS_MAPPED_V4) ||
2310 (((struct sockaddr *)&net->ro._l_addr)->sa_family == AF_INET6)) {
2311 cpsz = sizeof(struct sockaddr_in6);
2312 } else if (((struct sockaddr *)&net->ro._l_addr)->sa_family == AF_INET) {
2313 cpsz = sizeof(struct sockaddr_in);
2319 /* not enough room. */
2322 if ((stcb->sctp_ep->sctp_flags & SCTP_PCB_FLAGS_NEEDS_MAPPED_V4) &&
2323 (((struct sockaddr *)&net->ro._l_addr)->sa_family == AF_INET)) {
2324 /* Must map the address */
2325 in6_sin_2_v4mapsin6((struct sockaddr_in *)&net->ro._l_addr,
2326 (struct sockaddr_in6 *)sas);
2328 memcpy(sas, &net->ro._l_addr, cpsz);
2330 ((struct sockaddr_in *)sas)->sin_port = stcb->rport;
2332 sas = (struct sockaddr_storage *)((caddr_t)sas + cpsz);
2336 SCTP_TCB_UNLOCK(stcb);
2339 case SCTP_GET_LOCAL_ADDRESSES:
2342 struct sockaddr_storage *sas;
2343 struct sctp_getaddresses *saddr;
2345 if ((size_t)m->m_len < sizeof(struct sctp_getaddresses)) {
2349 saddr = mtod(m, struct sctp_getaddresses *);
2351 if (saddr->sget_assoc_id) {
2352 if (inp->sctp_flags & SCTP_PCB_FLAGS_CONNECTED) {
2353 SCTP_INP_RLOCK(inp);
2354 stcb = LIST_FIRST(&inp->sctp_asoc_list);
2356 SCTP_TCB_LOCK(stcb);
2357 SCTP_INP_RUNLOCK(inp);
2359 stcb = sctp_findassociation_ep_asocid(inp, saddr->sget_assoc_id, 1);
2365 * assure that the TCP model does not need a assoc
2366 * id once connected.
2368 if ((inp->sctp_flags & SCTP_PCB_FLAGS_CONNECTED) &&
2370 SCTP_INP_RLOCK(inp);
2371 stcb = LIST_FIRST(&inp->sctp_asoc_list);
2373 SCTP_TCB_LOCK(stcb);
2374 SCTP_INP_RUNLOCK(inp);
2376 sas = (struct sockaddr_storage *)&saddr->addr[0];
2377 limit = m->m_len - sizeof(sctp_assoc_t);
2378 actual = sctp_fill_up_addresses(inp, stcb, limit, sas);
2380 SCTP_TCB_UNLOCK(stcb);
2381 m->m_len = sizeof(struct sockaddr_storage) + actual;
2384 case SCTP_PEER_ADDR_PARAMS:
2386 struct sctp_paddrparams *paddrp;
2387 struct sctp_nets *net;
2389 if ((size_t)m->m_len < sizeof(struct sctp_paddrparams)) {
2393 paddrp = mtod(m, struct sctp_paddrparams *);
2396 if (paddrp->spp_assoc_id) {
2397 if (inp->sctp_flags & SCTP_PCB_FLAGS_CONNECTED) {
2398 SCTP_INP_RLOCK(inp);
2399 stcb = LIST_FIRST(&inp->sctp_asoc_list);
2401 SCTP_TCB_LOCK(stcb);
2402 net = sctp_findnet(stcb, (struct sockaddr *)&paddrp->spp_address);
2404 SCTP_INP_RLOCK(inp);
2406 stcb = sctp_findassociation_ep_asocid(inp, paddrp->spp_assoc_id, 1);
2413 if ((stcb == NULL) &&
2414 ((((struct sockaddr *)&paddrp->spp_address)->sa_family == AF_INET) ||
2415 (((struct sockaddr *)&paddrp->spp_address)->sa_family == AF_INET6))) {
2416 /* Lookup via address */
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 net = sctp_findnet(stcb, (struct sockaddr *)&paddrp->spp_address);
2424 SCTP_INP_RUNLOCK(inp);
2426 SCTP_INP_INCR_REF(inp);
2427 stcb = sctp_findassociation_ep_addr(&inp,
2428 (struct sockaddr *)&paddrp->spp_address,
2431 SCTP_INP_DECR_REF(inp);
2441 /* Applys to the specific association */
2442 paddrp->spp_flags = 0;
2444 paddrp->spp_pathmaxrxt = net->failure_threshold;
2445 paddrp->spp_pathmtu = net->mtu;
2446 /* get flags for HB */
2447 if (net->dest_state & SCTP_ADDR_NOHB)
2448 paddrp->spp_flags |= SPP_HB_DISABLE;
2450 paddrp->spp_flags |= SPP_HB_ENABLE;
2451 /* get flags for PMTU */
2452 if (callout_pending(&net->pmtu_timer.timer)) {
2453 paddrp->spp_flags |= SPP_PMTUD_ENABLE;
2455 paddrp->spp_flags |= SPP_PMTUD_DISABLE;
2458 if (net->ro._l_addr.sin.sin_family == AF_INET) {
2459 paddrp->spp_ipv4_tos = net->tos_flowlabel & 0x000000fc;
2460 paddrp->spp_flags |= SPP_IPV4_TOS;
2464 if (net->ro._l_addr.sin6.sin6_family == AF_INET6) {
2465 paddrp->spp_ipv6_flowlabel = net->tos_flowlabel;
2466 paddrp->spp_flags |= SPP_IPV6_FLOWLABEL;
2471 * No destination so return default
2474 paddrp->spp_pathmaxrxt = stcb->asoc.def_net_failure;
2475 paddrp->spp_pathmtu = sctp_get_frag_point(stcb, &stcb->asoc);
2477 paddrp->spp_ipv4_tos = stcb->asoc.default_tos & 0x000000fc;
2478 paddrp->spp_flags |= SPP_IPV4_TOS;
2481 paddrp->spp_ipv6_flowlabel = stcb->asoc.default_flowlabel;
2482 paddrp->spp_flags |= SPP_IPV6_FLOWLABEL;
2484 /* default settings should be these */
2485 if (sctp_is_hb_timer_running(stcb)) {
2486 paddrp->spp_flags |= SPP_HB_ENABLE;
2489 paddrp->spp_hbinterval = stcb->asoc.heart_beat_delay;
2490 paddrp->spp_sackdelay = stcb->asoc.delayed_ack;
2492 * Currently we don't support no sack delay
2493 * aka SPP_SACKDELAY_DISABLE.
2495 paddrp->spp_flags |= SPP_SACKDELAY_ENABLE;
2496 paddrp->spp_assoc_id = sctp_get_associd(stcb);
2497 SCTP_TCB_UNLOCK(stcb);
2499 /* Use endpoint defaults */
2500 SCTP_INP_RLOCK(inp);
2501 paddrp->spp_pathmaxrxt = inp->sctp_ep.def_net_failure;
2502 paddrp->spp_hbinterval = TICKS_TO_MSEC(inp->sctp_ep.sctp_timeoutticks[SCTP_TIMER_HEARTBEAT]);
2503 paddrp->spp_sackdelay = TICKS_TO_MSEC(inp->sctp_ep.sctp_timeoutticks[SCTP_TIMER_RECV]);
2504 paddrp->spp_assoc_id = (sctp_assoc_t) 0;
2505 /* get inp's default */
2507 paddrp->spp_ipv4_tos = inp->ip_inp.inp.inp_ip_tos;
2508 paddrp->spp_flags |= SPP_IPV4_TOS;
2511 if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) {
2512 paddrp->spp_ipv6_flowlabel = ((struct in6pcb *)inp)->in6p_flowinfo;
2513 paddrp->spp_flags |= SPP_IPV6_FLOWLABEL;
2516 /* can't return this */
2517 paddrp->spp_pathmaxrxt = 0;
2518 paddrp->spp_pathmtu = 0;
2519 /* default behavior, no stcb */
2520 paddrp->spp_flags = SPP_HB_ENABLE | SPP_SACKDELAY_ENABLE | SPP_PMTUD_ENABLE;
2522 SCTP_INP_RUNLOCK(inp);
2524 m->m_len = sizeof(struct sctp_paddrparams);
2527 case SCTP_GET_PEER_ADDR_INFO:
2529 struct sctp_paddrinfo *paddri;
2530 struct sctp_nets *net;
2532 if ((size_t)m->m_len < sizeof(struct sctp_paddrinfo)) {
2536 paddri = mtod(m, struct sctp_paddrinfo *);
2538 if ((((struct sockaddr *)&paddri->spinfo_address)->sa_family == AF_INET) ||
2539 (((struct sockaddr *)&paddri->spinfo_address)->sa_family == AF_INET6)) {
2540 /* Lookup via address */
2541 if (inp->sctp_flags & SCTP_PCB_FLAGS_CONNECTED) {
2542 SCTP_INP_RLOCK(inp);
2543 stcb = LIST_FIRST(&inp->sctp_asoc_list);
2545 SCTP_TCB_LOCK(stcb);
2546 net = sctp_findnet(stcb,
2547 (struct sockaddr *)&paddri->spinfo_address);
2549 SCTP_INP_RUNLOCK(inp);
2551 SCTP_INP_INCR_REF(inp);
2552 stcb = sctp_findassociation_ep_addr(&inp,
2553 (struct sockaddr *)&paddri->spinfo_address,
2556 SCTP_INP_DECR_REF(inp);
2563 if ((stcb == NULL) || (net == NULL)) {
2565 SCTP_TCB_UNLOCK(stcb);
2570 m->m_len = sizeof(struct sctp_paddrinfo);
2571 paddri->spinfo_state = net->dest_state & (SCTP_REACHABLE_MASK | SCTP_ADDR_NOHB);
2572 paddri->spinfo_cwnd = net->cwnd;
2573 paddri->spinfo_srtt = ((net->lastsa >> 2) + net->lastsv) >> 1;
2574 paddri->spinfo_rto = net->RTO;
2575 paddri->spinfo_assoc_id = sctp_get_associd(stcb);
2576 SCTP_TCB_UNLOCK(stcb);
2579 case SCTP_PCB_STATUS:
2581 struct sctp_pcbinfo *spcb;
2583 if ((size_t)m->m_len < sizeof(struct sctp_pcbinfo)) {
2587 spcb = mtod(m, struct sctp_pcbinfo *);
2588 sctp_fill_pcbinfo(spcb);
2589 m->m_len = sizeof(struct sctp_pcbinfo);
2594 struct sctp_nets *net;
2595 struct sctp_status *sstat;
2597 if ((size_t)m->m_len < sizeof(struct sctp_status)) {
2601 sstat = mtod(m, struct sctp_status *);
2603 if (inp->sctp_flags & SCTP_PCB_FLAGS_CONNECTED) {
2604 SCTP_INP_RLOCK(inp);
2605 stcb = LIST_FIRST(&inp->sctp_asoc_list);
2607 SCTP_TCB_LOCK(stcb);
2608 SCTP_INP_RUNLOCK(inp);
2610 stcb = sctp_findassociation_ep_asocid(inp, sstat->sstat_assoc_id, 1);
2617 * I think passing the state is fine since
2618 * sctp_constants.h will be available to the user
2621 sstat->sstat_state = stcb->asoc.state;
2622 sstat->sstat_rwnd = stcb->asoc.peers_rwnd;
2623 sstat->sstat_unackdata = stcb->asoc.sent_queue_cnt;
2625 * We can't include chunks that have been passed to
2626 * the socket layer. Only things in queue.
2628 sstat->sstat_penddata = (stcb->asoc.cnt_on_reasm_queue +
2629 stcb->asoc.cnt_on_all_streams);
2632 sstat->sstat_instrms = stcb->asoc.streamincnt;
2633 sstat->sstat_outstrms = stcb->asoc.streamoutcnt;
2634 sstat->sstat_fragmentation_point = sctp_get_frag_point(stcb, &stcb->asoc);
2635 memcpy(&sstat->sstat_primary.spinfo_address,
2636 &stcb->asoc.primary_destination->ro._l_addr,
2637 ((struct sockaddr *)(&stcb->asoc.primary_destination->ro._l_addr))->sa_len);
2638 net = stcb->asoc.primary_destination;
2639 ((struct sockaddr_in *)&sstat->sstat_primary.spinfo_address)->sin_port = stcb->rport;
2641 * Again the user can get info from sctp_constants.h
2642 * for what the state of the network is.
2644 sstat->sstat_primary.spinfo_state = net->dest_state & SCTP_REACHABLE_MASK;
2645 sstat->sstat_primary.spinfo_cwnd = net->cwnd;
2646 sstat->sstat_primary.spinfo_srtt = net->lastsa;
2647 sstat->sstat_primary.spinfo_rto = net->RTO;
2648 sstat->sstat_primary.spinfo_mtu = net->mtu;
2649 sstat->sstat_primary.spinfo_assoc_id = sctp_get_associd(stcb);
2650 SCTP_TCB_UNLOCK(stcb);
2651 m->m_len = sizeof(*sstat);
2656 struct sctp_rtoinfo *srto;
2658 if ((size_t)m->m_len < sizeof(struct sctp_rtoinfo)) {
2662 srto = mtod(m, struct sctp_rtoinfo *);
2663 if (srto->srto_assoc_id == 0) {
2664 /* Endpoint only please */
2665 SCTP_INP_RLOCK(inp);
2666 srto->srto_initial = inp->sctp_ep.initial_rto;
2667 srto->srto_max = inp->sctp_ep.sctp_maxrto;
2668 srto->srto_min = inp->sctp_ep.sctp_minrto;
2669 SCTP_INP_RUNLOCK(inp);
2672 if (inp->sctp_flags & SCTP_PCB_FLAGS_CONNECTED) {
2673 SCTP_INP_RLOCK(inp);
2674 stcb = LIST_FIRST(&inp->sctp_asoc_list);
2676 SCTP_TCB_LOCK(stcb);
2677 SCTP_INP_RUNLOCK(inp);
2679 stcb = sctp_findassociation_ep_asocid(inp, srto->srto_assoc_id, 1);
2685 srto->srto_initial = stcb->asoc.initial_rto;
2686 srto->srto_max = stcb->asoc.maxrto;
2687 srto->srto_min = stcb->asoc.minrto;
2688 SCTP_TCB_UNLOCK(stcb);
2689 m->m_len = sizeof(*srto);
2692 case SCTP_ASSOCINFO:
2694 struct sctp_assocparams *sasoc;
2696 if ((size_t)m->m_len < sizeof(struct sctp_assocparams)) {
2700 sasoc = mtod(m, struct sctp_assocparams *);
2703 if (inp->sctp_flags & SCTP_PCB_FLAGS_CONNECTED) {
2704 SCTP_INP_RLOCK(inp);
2705 stcb = LIST_FIRST(&inp->sctp_asoc_list);
2708 SCTP_TCB_LOCK(stcb);
2710 SCTP_INP_RUNLOCK(inp);
2711 } else if (sasoc->sasoc_assoc_id) {
2712 stcb = sctp_findassociation_ep_asocid(inp,
2713 sasoc->sasoc_assoc_id, 1);
2722 sasoc->sasoc_asocmaxrxt = stcb->asoc.max_send_times;
2723 sasoc->sasoc_number_peer_destinations = stcb->asoc.numnets;
2724 sasoc->sasoc_peer_rwnd = stcb->asoc.peers_rwnd;
2725 sasoc->sasoc_local_rwnd = stcb->asoc.my_rwnd;
2726 sasoc->sasoc_cookie_life = stcb->asoc.cookie_life;
2727 SCTP_TCB_UNLOCK(stcb);
2729 SCTP_INP_RLOCK(inp);
2730 sasoc->sasoc_asocmaxrxt = inp->sctp_ep.max_send_times;
2731 sasoc->sasoc_number_peer_destinations = 0;
2732 sasoc->sasoc_peer_rwnd = 0;
2733 sasoc->sasoc_local_rwnd = sbspace(&inp->sctp_socket->so_rcv);
2734 sasoc->sasoc_cookie_life = inp->sctp_ep.def_cookie_life;
2735 SCTP_INP_RUNLOCK(inp);
2737 m->m_len = sizeof(*sasoc);
2740 case SCTP_DEFAULT_SEND_PARAM:
2742 struct sctp_sndrcvinfo *s_info;
2744 if (m->m_len != sizeof(struct sctp_sndrcvinfo)) {
2748 s_info = mtod(m, struct sctp_sndrcvinfo *);
2749 if (inp->sctp_flags & SCTP_PCB_FLAGS_CONNECTED) {
2750 SCTP_INP_RLOCK(inp);
2751 stcb = LIST_FIRST(&inp->sctp_asoc_list);
2753 SCTP_TCB_LOCK(stcb);
2754 SCTP_INP_RUNLOCK(inp);
2756 stcb = sctp_findassociation_ep_asocid(inp, s_info->sinfo_assoc_id, 1);
2763 *s_info = stcb->asoc.def_send;
2764 SCTP_TCB_UNLOCK(stcb);
2765 m->m_len = sizeof(*s_info);
2770 struct sctp_initmsg *sinit;
2772 if ((size_t)m->m_len < sizeof(struct sctp_initmsg)) {
2776 sinit = mtod(m, struct sctp_initmsg *);
2777 SCTP_INP_RLOCK(inp);
2778 sinit->sinit_num_ostreams = inp->sctp_ep.pre_open_stream_count;
2779 sinit->sinit_max_instreams = inp->sctp_ep.max_open_streams_intome;
2780 sinit->sinit_max_attempts = inp->sctp_ep.max_init_times;
2781 sinit->sinit_max_init_timeo = inp->sctp_ep.initial_init_rto_max;
2782 SCTP_INP_RUNLOCK(inp);
2783 m->m_len = sizeof(*sinit);
2786 case SCTP_PRIMARY_ADDR:
2787 /* we allow a "get" operation on this */
2789 struct sctp_setprim *ssp;
2791 if ((size_t)m->m_len < sizeof(struct sctp_setprim)) {
2795 ssp = mtod(m, struct sctp_setprim *);
2796 if (inp->sctp_flags & SCTP_PCB_FLAGS_CONNECTED) {
2797 SCTP_INP_RLOCK(inp);
2798 stcb = LIST_FIRST(&inp->sctp_asoc_list);
2800 SCTP_TCB_LOCK(stcb);
2801 SCTP_INP_RUNLOCK(inp);
2803 stcb = sctp_findassociation_ep_asocid(inp, ssp->ssp_assoc_id, 1);
2806 * one last shot, try it by the
2809 struct sctp_nets *net;
2811 SCTP_INP_INCR_REF(inp);
2812 stcb = sctp_findassociation_ep_addr(&inp,
2813 (struct sockaddr *)&ssp->ssp_addr,
2816 SCTP_INP_DECR_REF(inp);
2824 /* simply copy out the sockaddr_storage... */
2825 memcpy(&ssp->ssp_addr,
2826 &stcb->asoc.primary_destination->ro._l_addr,
2827 ((struct sockaddr *)&stcb->asoc.primary_destination->ro._l_addr)->sa_len);
2828 SCTP_TCB_UNLOCK(stcb);
2829 m->m_len = sizeof(*ssp);
2833 case SCTP_HMAC_IDENT:
2835 struct sctp_hmacalgo *shmac;
2836 sctp_hmaclist_t *hmaclist;
2840 if ((size_t)(m->m_len) < sizeof(*shmac)) {
2844 shmac = mtod(m, struct sctp_hmacalgo *);
2845 SCTP_INP_RLOCK(inp);
2846 hmaclist = inp->sctp_ep.local_hmacs;
2847 if (hmaclist == NULL) {
2848 /* no HMACs to return */
2849 m->m_len = sizeof(*shmac);
2852 /* is there room for all of the hmac ids? */
2853 size = sizeof(*shmac) + (hmaclist->num_algo *
2854 sizeof(shmac->shmac_idents[0]));
2855 if ((size_t)(m->m_len) < size) {
2857 SCTP_INP_RUNLOCK(inp);
2860 /* copy in the list */
2861 for (i = 0; i < hmaclist->num_algo; i++)
2862 shmac->shmac_idents[i] = hmaclist->hmac[i];
2863 SCTP_INP_RUNLOCK(inp);
2867 case SCTP_AUTH_ACTIVE_KEY:
2869 struct sctp_authkeyid *scact;
2871 if ((size_t)(m->m_len) < sizeof(*scact)) {
2875 scact = mtod(m, struct sctp_authkeyid *);
2876 if (inp->sctp_flags & SCTP_PCB_FLAGS_CONNECTED) {
2878 * if one-to-one, get from the connected
2879 * assoc; else endpoint
2881 SCTP_INP_RLOCK(inp);
2882 stcb = LIST_FIRST(&inp->sctp_asoc_list);
2884 SCTP_TCB_LOCK(stcb);
2885 SCTP_INP_RUNLOCK(inp);
2886 } else if (scact->scact_assoc_id) {
2887 stcb = sctp_findassociation_ep_asocid(inp, scact->scact_assoc_id, 1);
2894 /* get the active key on the assoc */
2895 scact->scact_keynumber = stcb->asoc.authinfo.assoc_keyid;
2896 SCTP_TCB_UNLOCK(stcb);
2898 /* get the endpoint active key */
2899 SCTP_INP_RLOCK(inp);
2900 scact->scact_keynumber = inp->sctp_ep.default_keyid;
2901 SCTP_INP_RUNLOCK(inp);
2903 m->m_len = sizeof(*scact);
2906 case SCTP_LOCAL_AUTH_CHUNKS:
2908 struct sctp_authchunks *sac;
2909 sctp_auth_chklist_t *chklist = NULL;
2912 if ((size_t)(m->m_len) < sizeof(*sac)) {
2916 sac = mtod(m, struct sctp_authchunks *);
2917 if (inp->sctp_flags & SCTP_PCB_FLAGS_CONNECTED) {
2919 * if one-to-one, get from the connected
2920 * assoc; else endpoint
2922 SCTP_INP_RLOCK(inp);
2923 stcb = LIST_FIRST(&inp->sctp_asoc_list);
2925 SCTP_TCB_LOCK(stcb);
2926 SCTP_INP_RUNLOCK(inp);
2927 } else if (sac->gauth_assoc_id) {
2928 stcb = sctp_findassociation_ep_asocid(inp, sac->gauth_assoc_id, 1);
2935 /* get off the assoc */
2936 chklist = stcb->asoc.local_auth_chunks;
2937 if (chklist == NULL) {
2939 SCTP_TCB_UNLOCK(stcb);
2942 /* is there enough space? */
2943 size = sctp_auth_get_chklist_size(chklist);
2944 if ((size_t)m->m_len < (sizeof(struct sctp_authchunks) + size)) {
2946 SCTP_TCB_UNLOCK(stcb);
2949 /* copy in the chunks */
2950 sctp_serialize_auth_chunks(chklist, sac->gauth_chunks);
2951 SCTP_TCB_UNLOCK(stcb);
2953 /* get off the endpoint */
2954 SCTP_INP_RLOCK(inp);
2955 chklist = inp->sctp_ep.local_auth_chunks;
2956 if (chklist == NULL) {
2958 SCTP_INP_RUNLOCK(inp);
2961 /* is there enough space? */
2962 size = sctp_auth_get_chklist_size(chklist);
2963 if ((size_t)m->m_len < (sizeof(struct sctp_authchunks) + size)) {
2965 SCTP_INP_RUNLOCK(inp);
2968 /* copy in the chunks */
2969 sctp_serialize_auth_chunks(chklist, sac->gauth_chunks);
2970 SCTP_INP_RUNLOCK(inp);
2972 m->m_len = sizeof(struct sctp_authchunks) + size;
2975 case SCTP_PEER_AUTH_CHUNKS:
2977 struct sctp_authchunks *sac;
2978 sctp_auth_chklist_t *chklist = NULL;
2981 if ((size_t)(m->m_len) < sizeof(*sac)) {
2985 sac = mtod(m, struct sctp_authchunks *);
2986 if (inp->sctp_flags & SCTP_PCB_FLAGS_CONNECTED) {
2988 * if one-to-one, get from the connected
2989 * assoc, else endpoint
2991 SCTP_INP_RLOCK(inp);
2992 stcb = LIST_FIRST(&inp->sctp_asoc_list);
2994 SCTP_TCB_LOCK(stcb);
2995 SCTP_INP_RUNLOCK(inp);
2996 } else if (sac->gauth_assoc_id) {
2997 stcb = sctp_findassociation_ep_asocid(inp, sac->gauth_assoc_id, 1);
3003 /* get off the assoc */
3004 chklist = stcb->asoc.peer_auth_chunks;
3005 if (chklist == NULL) {
3007 SCTP_TCB_UNLOCK(stcb);
3010 /* is there enough space? */
3011 size = sctp_auth_get_chklist_size(chklist);
3012 if ((size_t)m->m_len < (sizeof(struct sctp_authchunks) + size)) {
3014 SCTP_TCB_UNLOCK(stcb);
3017 /* copy in the chunks */
3018 sctp_serialize_auth_chunks(chklist, sac->gauth_chunks);
3019 SCTP_TCB_UNLOCK(stcb);
3020 m->m_len = sizeof(struct sctp_authchunks) + size;
3026 error = ENOPROTOOPT;
3029 } /* end switch (sopt->sopt_name) */
3035 sctp_optsset(struct socket *so,
3041 int error, *mopt, set_opt, s;
3043 struct sctp_tcb *stcb = NULL;
3044 struct sctp_inpcb *inp;
3053 inp = (struct sctp_inpcb *)so->so_pcb;
3060 case SCTP_AUTOCLOSE:
3061 case SCTP_AUTO_ASCONF:
3062 case SCTP_EXPLICIT_EOR:
3063 case SCTP_DISABLE_FRAGMENTS:
3064 case SCTP_USE_EXT_RCVINFO:
3065 case SCTP_I_WANT_MAPPED_V4_ADDR:
3066 /* copy in the option value */
3067 if ((size_t)m->m_len < sizeof(int)) {
3071 mopt = mtod(m, int *);
3076 case SCTP_DISABLE_FRAGMENTS:
3077 set_opt = SCTP_PCB_FLAGS_NO_FRAGMENT;
3079 case SCTP_AUTO_ASCONF:
3080 set_opt = SCTP_PCB_FLAGS_AUTO_ASCONF;
3082 case SCTP_EXPLICIT_EOR:
3083 set_opt = SCTP_PCB_FLAGS_EXPLICIT_EOR;
3085 case SCTP_USE_EXT_RCVINFO:
3086 set_opt = SCTP_PCB_FLAGS_EXT_RCVINFO;
3088 case SCTP_I_WANT_MAPPED_V4_ADDR:
3089 if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) {
3090 set_opt = SCTP_PCB_FLAGS_NEEDS_MAPPED_V4;
3096 set_opt = SCTP_PCB_FLAGS_NODELAY;
3098 case SCTP_AUTOCLOSE:
3099 set_opt = SCTP_PCB_FLAGS_AUTOCLOSE;
3101 * The value is in ticks. Note this does not effect
3102 * old associations, only new ones.
3104 inp->sctp_ep.auto_close_time = SEC_TO_TICKS(*mopt);
3107 SCTP_INP_WLOCK(inp);
3109 sctp_feature_on(inp, set_opt);
3111 sctp_feature_off(inp, set_opt);
3113 SCTP_INP_WUNLOCK(inp);
3115 case SCTP_PARTIAL_DELIVERY_POINT:
3117 if ((size_t)m->m_len < sizeof(unsigned int)) {
3121 inp->partial_delivery_point = *mtod(m, unsigned int *);
3122 m->m_len = sizeof(unsigned int);
3125 case SCTP_FRAGMENT_INTERLEAVE:
3126 /* not yet until we re-write sctp_recvmsg() */
3130 if ((size_t)m->m_len < sizeof(int)) {
3134 on_off = *(mtod(m, int *));
3136 sctp_feature_on(inp, SCTP_PCB_FLAGS_FRAG_INTERLEAVE);
3138 sctp_feature_off(inp, SCTP_PCB_FLAGS_FRAG_INTERLEAVE);
3142 case SCTP_CMT_ON_OFF:
3144 struct sctp_assoc_value *av;
3146 if ((size_t)m->m_len < sizeof(struct sctp_assoc_value)) {
3150 av = mtod(m, struct sctp_assoc_value *);
3151 stcb = sctp_findassociation_ep_asocid(inp, av->assoc_id, 1);
3155 if (sctp_cmt_on_off) {
3156 stcb->asoc.sctp_cmt_on_off = (uint8_t) av->assoc_value;
3158 if ((stcb->asoc.sctp_cmt_on_off) && (av->assoc_value == 0)) {
3159 stcb->asoc.sctp_cmt_on_off = 0;
3164 SCTP_TCB_UNLOCK(stcb);
3168 case SCTP_CMT_USE_DAC:
3170 if ((size_t)m->m_len < sizeof(unsigned int)) {
3174 sctp_cmt_sockopt_use_dac = *mtod(m, unsigned int *);
3175 if (sctp_cmt_sockopt_use_dac != 0)
3176 sctp_cmt_sockopt_use_dac = 1;
3179 case SCTP_CLR_STAT_LOG:
3180 #ifdef SCTP_STAT_LOGGING
3181 sctp_clr_stat_log();
3189 struct sctp_assoc_value *av;
3191 if ((size_t)m->m_len < sizeof(struct sctp_assoc_value)) {
3195 av = mtod(m, struct sctp_assoc_value *);
3197 stcb = sctp_findassociation_ep_asocid(inp, av->assoc_id, 1);
3201 stcb->asoc.context = av->assoc_value;
3202 SCTP_TCB_UNLOCK(stcb);
3205 inp->sctp_context = av->assoc_value;
3209 case SCTP_DELAYED_ACK_TIME:
3211 struct sctp_assoc_value *tm;
3213 if ((size_t)m->m_len < sizeof(struct sctp_assoc_value)) {
3217 tm = mtod(m, struct sctp_assoc_value *);
3219 if (inp->sctp_flags & SCTP_PCB_FLAGS_CONNECTED) {
3220 SCTP_INP_WLOCK(inp);
3221 stcb = LIST_FIRST(&inp->sctp_asoc_list);
3223 SCTP_TCB_LOCK(stcb);
3224 stcb->asoc.delayed_ack = tm->assoc_value;
3225 SCTP_TCB_UNLOCK(stcb);
3227 inp->sctp_ep.sctp_timeoutticks[SCTP_TIMER_RECV] = MSEC_TO_TICKS(tm->assoc_value);
3229 SCTP_INP_WUNLOCK(inp);
3232 stcb = sctp_findassociation_ep_asocid(inp, tm->assoc_id, 1);
3236 stcb->asoc.delayed_ack = tm->assoc_value;
3237 SCTP_TCB_UNLOCK(stcb);
3240 SCTP_INP_WLOCK(inp);
3241 inp->sctp_ep.sctp_timeoutticks[SCTP_TIMER_RECV] = MSEC_TO_TICKS(tm->assoc_value);
3242 SCTP_INP_WUNLOCK(inp);
3248 case SCTP_AUTH_CHUNK:
3250 struct sctp_authchunk *sauth;
3252 if ((size_t)m->m_len < sizeof(*sauth)) {
3256 sauth = mtod(m, struct sctp_authchunk *);
3257 if (sctp_auth_add_chunk(sauth->sauth_chunk,
3258 inp->sctp_ep.local_auth_chunks))
3264 struct sctp_authkey *sca;
3265 struct sctp_keyhead *shared_keys;
3266 sctp_sharedkey_t *shared_key;
3267 sctp_key_t *key = NULL;
3270 size = m->m_len - sizeof(*sca);
3275 sca = mtod(m, struct sctp_authkey *);
3276 if (inp->sctp_flags & SCTP_PCB_FLAGS_CONNECTED) {
3278 * if one-to-one, set it on the connected
3279 * assoc; else endpoint
3281 SCTP_INP_RLOCK(inp);
3282 stcb = LIST_FIRST(&inp->sctp_asoc_list);
3284 SCTP_TCB_LOCK(stcb);
3285 SCTP_INP_RUNLOCK(inp);
3286 } else if (sca->sca_assoc_id) {
3287 stcb = sctp_findassociation_ep_asocid(inp, sca->sca_assoc_id, 1);
3294 /* set it on the assoc */
3295 shared_keys = &stcb->asoc.shared_keys;
3296 /* clear the cached keys for this key id */
3297 sctp_clear_cachedkeys(stcb, sca->sca_keynumber);
3299 * create the new shared key and
3303 key = sctp_set_key(sca->sca_key, (uint32_t) size);
3306 SCTP_TCB_UNLOCK(stcb);
3310 shared_key = sctp_alloc_sharedkey();
3311 if (shared_key == NULL) {
3314 SCTP_TCB_UNLOCK(stcb);
3317 shared_key->key = key;
3318 shared_key->keyid = sca->sca_keynumber;
3319 sctp_insert_sharedkey(shared_keys, shared_key);
3320 SCTP_TCB_UNLOCK(stcb);
3322 /* ste it on the endpoint */
3323 SCTP_INP_WLOCK(inp);
3324 shared_keys = &inp->sctp_ep.shared_keys;
3326 * clear the cached keys on all assocs for
3329 sctp_clear_cachedkeys_ep(inp, sca->sca_keynumber);
3331 * create the new shared key and
3335 key = sctp_set_key(sca->sca_key, (uint32_t) size);
3338 SCTP_INP_WUNLOCK(inp);
3342 shared_key = sctp_alloc_sharedkey();
3343 if (shared_key == NULL) {
3346 SCTP_INP_WUNLOCK(inp);
3349 shared_key->key = key;
3350 shared_key->keyid = sca->sca_keynumber;
3351 sctp_insert_sharedkey(shared_keys, shared_key);
3352 SCTP_INP_WUNLOCK(inp);
3356 case SCTP_HMAC_IDENT:
3358 struct sctp_hmacalgo *shmac;
3359 sctp_hmaclist_t *hmaclist;
3363 size = m->m_len - sizeof(*shmac);
3368 shmac = mtod(m, struct sctp_hmacalgo *);
3369 size = size / sizeof(shmac->shmac_idents[0]);
3370 hmaclist = sctp_alloc_hmaclist(size);
3371 if (hmaclist == NULL) {
3375 for (i = 0; i < size; i++) {
3376 hmacid = shmac->shmac_idents[i];
3377 if (sctp_auth_add_hmacid(hmaclist, (uint16_t) hmacid)) {
3378 /* invalid HMACs were found */ ;
3380 goto sctp_set_hmac_done;
3383 /* set it on the endpoint */
3384 SCTP_INP_WLOCK(inp);
3385 if (inp->sctp_ep.local_hmacs)
3386 sctp_free_hmaclist(inp->sctp_ep.local_hmacs);
3387 inp->sctp_ep.local_hmacs = hmaclist;
3388 SCTP_INP_WUNLOCK(inp);
3392 case SCTP_AUTH_ACTIVE_KEY:
3394 struct sctp_authkeyid *scact;
3396 if ((size_t)m->m_len < sizeof(*scact)) {
3400 scact = mtod(m, struct sctp_authkeyid *);
3401 if (inp->sctp_flags & SCTP_PCB_FLAGS_CONNECTED) {
3403 * if one-to-one, set it on the connected
3404 * assoc; else endpoint
3406 SCTP_INP_RLOCK(inp);
3407 stcb = LIST_FIRST(&inp->sctp_asoc_list);
3409 SCTP_TCB_LOCK(stcb);
3410 SCTP_INP_RUNLOCK(inp);
3411 } else if (scact->scact_assoc_id) {
3412 stcb = sctp_findassociation_ep_asocid(inp, scact->scact_assoc_id, 1);
3418 /* set the active key on the right place */
3420 /* set the active key on the assoc */
3421 if (sctp_auth_setactivekey(stcb, scact->scact_keynumber))
3423 SCTP_TCB_UNLOCK(stcb);
3425 /* set the active key on the endpoint */
3426 SCTP_INP_WLOCK(inp);
3427 if (sctp_auth_setactivekey_ep(inp, scact->scact_keynumber))
3429 SCTP_INP_WUNLOCK(inp);
3433 case SCTP_AUTH_DELETE_KEY:
3435 struct sctp_authkeyid *scdel;
3437 if ((size_t)m->m_len < sizeof(*scdel)) {
3441 scdel = mtod(m, struct sctp_authkeyid *);
3442 if (inp->sctp_flags & SCTP_PCB_FLAGS_CONNECTED) {
3444 * if one-to-one, delete from the connected
3445 * assoc; else endpoint
3447 SCTP_INP_RLOCK(inp);
3448 stcb = LIST_FIRST(&inp->sctp_asoc_list);
3450 SCTP_TCB_LOCK(stcb);
3451 SCTP_INP_RUNLOCK(inp);
3452 } else if (scdel->scact_assoc_id) {
3453 stcb = sctp_findassociation_ep_asocid(inp, scdel->scact_assoc_id, 1);
3459 /* delete the key from the right place */
3461 if (sctp_delete_sharedkey(stcb, scdel->scact_keynumber))
3463 SCTP_TCB_UNLOCK(stcb);
3465 SCTP_INP_WLOCK(inp);
3466 if (sctp_delete_sharedkey_ep(inp, scdel->scact_keynumber))
3468 SCTP_INP_WUNLOCK(inp);
3473 case SCTP_RESET_STREAMS:
3475 struct sctp_stream_reset *strrst;
3476 uint8_t send_in = 0, send_tsn = 0, send_out = 0;
3479 if ((size_t)m->m_len < sizeof(struct sctp_stream_reset)) {
3483 strrst = mtod(m, struct sctp_stream_reset *);
3485 if (inp->sctp_flags & SCTP_PCB_FLAGS_CONNECTED) {
3486 SCTP_INP_RLOCK(inp);
3487 stcb = LIST_FIRST(&inp->sctp_asoc_list);
3489 SCTP_TCB_LOCK(stcb);
3490 SCTP_INP_RUNLOCK(inp);
3492 stcb = sctp_findassociation_ep_asocid(inp, strrst->strrst_assoc_id, 1);
3497 if (stcb->asoc.peer_supports_strreset == 0) {
3499 * Peer does not support it, we return
3500 * protocol not supported since this is true
3501 * for this feature and this peer, not the
3502 * socket request in general.
3504 error = EPROTONOSUPPORT;
3505 SCTP_TCB_UNLOCK(stcb);
3508 if (stcb->asoc.stream_reset_outstanding) {
3510 SCTP_TCB_UNLOCK(stcb);
3513 if (strrst->strrst_flags == SCTP_RESET_LOCAL_RECV) {
3515 } else if (strrst->strrst_flags == SCTP_RESET_LOCAL_SEND) {
3517 } else if (strrst->strrst_flags == SCTP_RESET_BOTH) {
3520 } else if (strrst->strrst_flags == SCTP_RESET_TSN) {
3524 SCTP_TCB_UNLOCK(stcb);
3527 for (i = 0; i < strrst->strrst_num_streams; i++) {
3530 (strrst->strrst_list[i] > stcb->asoc.streamincnt)) {
3535 (strrst->strrst_list[i] > stcb->asoc.streamoutcnt)) {
3542 SCTP_TCB_UNLOCK(stcb);
3545 error = sctp_send_str_reset_req(stcb, strrst->strrst_num_streams,
3546 strrst->strrst_list,
3547 send_out, (stcb->asoc.str_reset_seq_in - 3),
3551 sctp_chunk_output(inp, stcb, SCTP_OUTPUT_FROM_STRRST_REQ);
3552 SCTP_TCB_UNLOCK(stcb);
3557 case SCTP_CONNECT_X:
3558 if ((size_t)m->m_len < (sizeof(int) + sizeof(struct sockaddr_in))) {
3562 error = sctp_do_connect_x(so, inp, m, p, 0);
3565 case SCTP_CONNECT_X_DELAYED:
3566 if ((size_t)m->m_len < (sizeof(int) + sizeof(struct sockaddr_in))) {
3570 error = sctp_do_connect_x(so, inp, m, p, 1);
3573 case SCTP_CONNECT_X_COMPLETE:
3575 struct sockaddr *sa;
3576 struct sctp_nets *net;
3578 if ((size_t)m->m_len < sizeof(struct sockaddr_in)) {
3582 sa = mtod(m, struct sockaddr *);
3584 if (inp->sctp_flags & SCTP_PCB_FLAGS_CONNECTED) {
3585 SCTP_INP_RLOCK(inp);
3586 stcb = LIST_FIRST(&inp->sctp_asoc_list);
3588 SCTP_TCB_LOCK(stcb);
3589 net = sctp_findnet(stcb, sa);
3591 SCTP_INP_RUNLOCK(inp);
3593 SCTP_INP_INCR_REF(inp);
3594 stcb = sctp_findassociation_ep_addr(&inp, sa, &net, NULL, NULL);
3596 SCTP_INP_DECR_REF(inp);
3604 if (stcb->asoc.delayed_connection == 1) {
3605 stcb->asoc.delayed_connection = 0;
3606 SCTP_GETTIME_TIMEVAL(&stcb->asoc.time_entered);
3607 sctp_timer_stop(SCTP_TIMER_TYPE_INIT, inp, stcb, stcb->asoc.primary_destination);
3608 sctp_send_initiate(inp, stcb);
3611 * already expired or did not use delayed
3616 SCTP_TCB_UNLOCK(stcb);
3623 SCTP_INP_WLOCK(inp);
3624 burst = mtod(m, uint8_t *);
3626 inp->sctp_ep.max_burst = *burst;
3628 SCTP_INP_WUNLOCK(inp);
3636 if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) {
3637 ovh = SCTP_MED_OVERHEAD;
3639 ovh = SCTP_MED_V4_OVERHEAD;
3641 segsize = mtod(m, uint32_t *);
3646 SCTP_INP_WLOCK(inp);
3647 inp->sctp_frag_point = (*segsize + ovh);
3648 if (inp->sctp_frag_point < MHLEN) {
3649 inp->sctp_frag_point = MHLEN;
3651 SCTP_INP_WUNLOCK(inp);
3654 case SCTP_SET_DEBUG_LEVEL:
3659 if ((size_t)m->m_len < sizeof(uint32_t)) {
3663 level = mtod(m, uint32_t *);
3665 sctp_debug_on = (*level & (SCTP_DEBUG_ALL |
3667 printf("SETTING DEBUG LEVEL to %x\n",
3668 (uint32_t) sctp_debug_on);
3673 #endif /* SCTP_DEBUG */
3677 struct sctp_event_subscribe *events;
3679 if ((size_t)m->m_len < sizeof(struct sctp_event_subscribe)) {
3683 SCTP_INP_WLOCK(inp);
3684 events = mtod(m, struct sctp_event_subscribe *);
3685 if (events->sctp_data_io_event) {
3686 sctp_feature_on(inp, SCTP_PCB_FLAGS_RECVDATAIOEVNT);
3688 sctp_feature_off(inp, SCTP_PCB_FLAGS_RECVDATAIOEVNT);
3691 if (events->sctp_association_event) {
3692 sctp_feature_on(inp, SCTP_PCB_FLAGS_RECVASSOCEVNT);
3694 sctp_feature_off(inp, SCTP_PCB_FLAGS_RECVASSOCEVNT);
3697 if (events->sctp_address_event) {
3698 sctp_feature_on(inp, SCTP_PCB_FLAGS_RECVPADDREVNT);
3700 sctp_feature_off(inp, SCTP_PCB_FLAGS_RECVPADDREVNT);
3703 if (events->sctp_send_failure_event) {
3704 sctp_feature_on(inp, SCTP_PCB_FLAGS_RECVSENDFAILEVNT);
3706 sctp_feature_off(inp, SCTP_PCB_FLAGS_RECVSENDFAILEVNT);
3709 if (events->sctp_peer_error_event) {
3710 sctp_feature_on(inp, SCTP_PCB_FLAGS_RECVPEERERR);
3712 sctp_feature_off(inp, SCTP_PCB_FLAGS_RECVPEERERR);
3715 if (events->sctp_shutdown_event) {
3716 sctp_feature_on(inp, SCTP_PCB_FLAGS_RECVSHUTDOWNEVNT);
3718 sctp_feature_off(inp, SCTP_PCB_FLAGS_RECVSHUTDOWNEVNT);
3721 if (events->sctp_partial_delivery_event) {
3722 sctp_feature_on(inp, SCTP_PCB_FLAGS_PDAPIEVNT);
3724 sctp_feature_off(inp, SCTP_PCB_FLAGS_PDAPIEVNT);
3727 if (events->sctp_adaptation_layer_event) {
3728 sctp_feature_on(inp, SCTP_PCB_FLAGS_ADAPTATIONEVNT);
3730 sctp_feature_off(inp, SCTP_PCB_FLAGS_ADAPTATIONEVNT);
3733 if (events->sctp_authentication_event) {
3734 sctp_feature_on(inp, SCTP_PCB_FLAGS_AUTHEVNT);
3736 sctp_feature_off(inp, SCTP_PCB_FLAGS_AUTHEVNT);
3739 if (events->sctp_stream_reset_events) {
3740 sctp_feature_on(inp, SCTP_PCB_FLAGS_STREAM_RESETEVNT);
3742 sctp_feature_off(inp, SCTP_PCB_FLAGS_STREAM_RESETEVNT);
3744 SCTP_INP_WUNLOCK(inp);
3748 case SCTP_ADAPTATION_LAYER:
3750 struct sctp_setadaptation *adap_bits;
3752 if ((size_t)m->m_len < sizeof(struct sctp_setadaptation)) {
3756 SCTP_INP_WLOCK(inp);
3757 adap_bits = mtod(m, struct sctp_setadaptation *);
3758 inp->sctp_ep.adaptation_layer_indicator = adap_bits->ssb_adaptation_ind;
3759 SCTP_INP_WUNLOCK(inp);
3762 case SCTP_SET_INITIAL_DBG_SEQ:
3766 if ((size_t)m->m_len < sizeof(uint32_t)) {
3770 SCTP_INP_WLOCK(inp);
3771 vvv = mtod(m, uint32_t *);
3772 inp->sctp_ep.initial_sequence_debug = *vvv;
3773 SCTP_INP_WUNLOCK(inp);
3776 case SCTP_DEFAULT_SEND_PARAM:
3778 struct sctp_sndrcvinfo *s_info;
3780 if (m->m_len != sizeof(struct sctp_sndrcvinfo)) {
3784 s_info = mtod(m, struct sctp_sndrcvinfo *);
3786 if (inp->sctp_flags & SCTP_PCB_FLAGS_CONNECTED) {
3787 SCTP_INP_RLOCK(inp);
3788 stcb = LIST_FIRST(&inp->sctp_asoc_list);
3790 SCTP_TCB_LOCK(stcb);
3791 SCTP_INP_RUNLOCK(inp);
3793 if (s_info->sinfo_assoc_id) {
3794 stcb = sctp_findassociation_ep_asocid(inp, s_info->sinfo_assoc_id, 1);
3799 if ((s_info->sinfo_assoc_id == 0) &&
3801 inp->def_send = *s_info;
3802 } else if (stcb == NULL) {
3806 /* Validate things */
3807 if (s_info->sinfo_stream > stcb->asoc.streamoutcnt) {
3808 SCTP_TCB_UNLOCK(stcb);
3813 stcb->asoc.def_send = *s_info;
3814 SCTP_TCB_UNLOCK(stcb);
3817 case SCTP_PEER_ADDR_PARAMS:
3818 /* Applys to the specific association */
3820 struct sctp_paddrparams *paddrp;
3821 struct sctp_nets *net;
3823 if ((size_t)m->m_len < sizeof(struct sctp_paddrparams)) {
3827 paddrp = mtod(m, struct sctp_paddrparams *);
3829 if (paddrp->spp_assoc_id) {
3830 if (inp->sctp_flags & SCTP_PCB_FLAGS_CONNECTED) {
3831 SCTP_INP_RLOCK(inp);
3832 stcb = LIST_FIRST(&inp->sctp_asoc_list);
3834 SCTP_TCB_LOCK(stcb);
3835 net = sctp_findnet(stcb, (struct sockaddr *)&paddrp->spp_address);
3837 SCTP_INP_RUNLOCK(inp);
3839 stcb = sctp_findassociation_ep_asocid(inp, paddrp->spp_assoc_id, 1);
3846 if ((stcb == NULL) &&
3847 ((((struct sockaddr *)&paddrp->spp_address)->sa_family == AF_INET) ||
3848 (((struct sockaddr *)&paddrp->spp_address)->sa_family == AF_INET6))) {
3849 /* Lookup via address */
3850 if (inp->sctp_flags & SCTP_PCB_FLAGS_CONNECTED) {
3851 SCTP_INP_RLOCK(inp);
3852 stcb = LIST_FIRST(&inp->sctp_asoc_list);
3854 SCTP_TCB_LOCK(stcb);
3855 net = sctp_findnet(stcb,
3856 (struct sockaddr *)&paddrp->spp_address);
3858 SCTP_INP_RUNLOCK(inp);
3860 SCTP_INP_INCR_REF(inp);
3861 stcb = sctp_findassociation_ep_addr(&inp,
3862 (struct sockaddr *)&paddrp->spp_address,
3865 SCTP_INP_DECR_REF(inp);
3870 /************************TCB SPECIFIC SET ******************/
3871 /* sack delay first */
3872 if (paddrp->spp_flags & SPP_SACKDELAY_ENABLE) {
3874 * we do NOT support turning it off
3875 * (yet). only setting the delay.
3877 if (paddrp->spp_sackdelay >= SCTP_CLOCK_GRANULARITY)
3878 stcb->asoc.delayed_ack = paddrp->spp_sackdelay;
3880 stcb->asoc.delayed_ack = SCTP_CLOCK_GRANULARITY;
3882 } else if (paddrp->spp_flags & SPP_SACKDELAY_DISABLE) {
3883 stcb->asoc.delayed_ack = 0;
3886 * do we change the timer for HB, we run
3889 if (paddrp->spp_hbinterval)
3890 stcb->asoc.heart_beat_delay = paddrp->spp_hbinterval;
3891 else if (paddrp->spp_flags & SPP_HB_TIME_IS_ZERO)
3892 stcb->asoc.heart_beat_delay = 0;
3894 /* network sets ? */
3896 /************************NET SPECIFIC SET ******************/
3897 if (paddrp->spp_flags & SPP_HB_DEMAND) {
3899 sctp_send_hb(stcb, 1, net);
3901 if (paddrp->spp_flags & SPP_HB_DISABLE) {
3902 net->dest_state |= SCTP_ADDR_NOHB;
3904 if (paddrp->spp_flags & SPP_HB_ENABLE) {
3905 net->dest_state &= ~SCTP_ADDR_NOHB;
3907 if (paddrp->spp_flags & SPP_PMTUD_DISABLE) {
3908 if (callout_pending(&net->pmtu_timer.timer)) {
3909 sctp_timer_stop(SCTP_TIMER_TYPE_PATHMTURAISE, inp, stcb, net);
3911 if (paddrp->spp_pathmtu > SCTP_DEFAULT_MINSEGMENT) {
3912 net->mtu = paddrp->spp_pathmtu;
3913 if (net->mtu < stcb->asoc.smallest_mtu)
3914 sctp_pathmtu_adustment(inp, stcb, net, net->mtu);
3917 if (paddrp->spp_flags & SPP_PMTUD_ENABLE) {
3918 if (callout_pending(&net->pmtu_timer.timer)) {
3919 sctp_timer_start(SCTP_TIMER_TYPE_PATHMTURAISE, inp, stcb, net);
3922 if (paddrp->spp_pathmaxrxt)
3923 net->failure_threshold = paddrp->spp_pathmaxrxt;
3925 if (paddrp->spp_flags & SPP_IPV4_TOS) {
3926 if (net->ro._l_addr.sin.sin_family == AF_INET) {
3927 net->tos_flowlabel = paddrp->spp_ipv4_tos & 0x000000fc;
3932 if (paddrp->spp_flags & SPP_IPV6_FLOWLABEL) {
3933 if (net->ro._l_addr.sin6.sin6_family == AF_INET6) {
3934 net->tos_flowlabel = paddrp->spp_ipv6_flowlabel;
3939 /************************ASSOC ONLY -- NO NET SPECIFIC SET ******************/
3940 if (paddrp->spp_pathmaxrxt)
3941 stcb->asoc.def_net_failure = paddrp->spp_pathmaxrxt;
3943 if (paddrp->spp_flags & SPP_HB_ENABLE) {
3944 /* Turn back on the timer */
3945 stcb->asoc.hb_is_disabled = 0;
3946 sctp_timer_start(SCTP_TIMER_TYPE_HEARTBEAT, inp, stcb, net);
3948 if (paddrp->spp_flags & SPP_HB_DISABLE) {
3949 int cnt_of_unconf = 0;
3950 struct sctp_nets *lnet;
3952 stcb->asoc.hb_is_disabled = 1;
3953 TAILQ_FOREACH(lnet, &stcb->asoc.nets, sctp_next) {
3954 if (lnet->dest_state & SCTP_ADDR_UNCONFIRMED) {
3959 * stop the timer ONLY if we
3960 * have no unconfirmed
3963 if (cnt_of_unconf == 0) {
3964 sctp_timer_stop(SCTP_TIMER_TYPE_HEARTBEAT, inp, stcb, net);
3967 if (paddrp->spp_flags & SPP_HB_ENABLE) {
3968 /* start up the timer. */
3969 sctp_timer_start(SCTP_TIMER_TYPE_HEARTBEAT, inp, stcb, net);
3972 if (paddrp->spp_flags & SPP_IPV4_TOS)
3973 stcb->asoc.default_tos = paddrp->spp_ipv4_tos & 0x000000fc;
3976 if (paddrp->spp_flags & SPP_IPV6_FLOWLABEL)
3977 stcb->asoc.default_flowlabel = paddrp->spp_ipv6_flowlabel;
3981 SCTP_TCB_UNLOCK(stcb);
3983 /************************NO TCB, SET TO default stuff ******************/
3984 SCTP_INP_WLOCK(inp);
3986 * For the TOS/FLOWLABEL stuff you set it
3987 * with the options on the socket
3989 if (paddrp->spp_pathmaxrxt) {
3990 inp->sctp_ep.def_net_failure = paddrp->spp_pathmaxrxt;
3992 if (paddrp->spp_flags & SPP_HB_ENABLE) {
3993 inp->sctp_ep.sctp_timeoutticks[SCTP_TIMER_HEARTBEAT] = MSEC_TO_TICKS(paddrp->spp_hbinterval);
3994 sctp_feature_off(inp, SCTP_PCB_FLAGS_DONOT_HEARTBEAT);
3995 } else if (paddrp->spp_flags & SPP_HB_DISABLE) {
3996 sctp_feature_on(inp, SCTP_PCB_FLAGS_DONOT_HEARTBEAT);
3998 if (paddrp->spp_flags & SPP_SACKDELAY_ENABLE) {
3999 if (paddrp->spp_sackdelay > SCTP_CLOCK_GRANULARITY)
4000 inp->sctp_ep.sctp_timeoutticks[SCTP_TIMER_RECV] = MSEC_TO_TICKS(paddrp->spp_sackdelay);
4002 inp->sctp_ep.sctp_timeoutticks[SCTP_TIMER_RECV] = MSEC_TO_TICKS(SCTP_CLOCK_GRANULARITY);
4004 } else if (paddrp->spp_flags & SPP_SACKDELAY_DISABLE) {
4005 inp->sctp_ep.sctp_timeoutticks[SCTP_TIMER_RECV] = 0;
4007 SCTP_INP_WUNLOCK(inp);
4013 struct sctp_rtoinfo *srto;
4015 if ((size_t)m->m_len < sizeof(struct sctp_rtoinfo)) {
4019 srto = mtod(m, struct sctp_rtoinfo *);
4020 if (srto->srto_assoc_id == 0) {
4021 SCTP_INP_WLOCK(inp);
4023 * If we have a null asoc, its default for
4026 if (srto->srto_initial > 10)
4027 inp->sctp_ep.initial_rto = srto->srto_initial;
4028 if (srto->srto_max > 10)
4029 inp->sctp_ep.sctp_maxrto = srto->srto_max;
4030 if (srto->srto_min > 10)
4031 inp->sctp_ep.sctp_minrto = srto->srto_min;
4032 SCTP_INP_WUNLOCK(inp);
4035 if (inp->sctp_flags & SCTP_PCB_FLAGS_CONNECTED) {
4036 SCTP_INP_RLOCK(inp);
4037 stcb = LIST_FIRST(&inp->sctp_asoc_list);
4039 SCTP_TCB_LOCK(stcb);
4040 SCTP_INP_RUNLOCK(inp);
4042 stcb = sctp_findassociation_ep_asocid(inp, srto->srto_assoc_id, 1);
4047 /* Set in ms we hope :-) */
4048 if (srto->srto_initial > 10)
4049 stcb->asoc.initial_rto = srto->srto_initial;
4050 if (srto->srto_max > 10)
4051 stcb->asoc.maxrto = srto->srto_max;
4052 if (srto->srto_min > 10)
4053 stcb->asoc.minrto = srto->srto_min;
4054 SCTP_TCB_UNLOCK(stcb);
4057 case SCTP_ASSOCINFO:
4059 struct sctp_assocparams *sasoc;
4061 if ((size_t)m->m_len < sizeof(struct sctp_assocparams)) {
4065 sasoc = mtod(m, struct sctp_assocparams *);
4066 if (sasoc->sasoc_assoc_id) {
4067 if (inp->sctp_flags & SCTP_PCB_FLAGS_CONNECTED) {
4068 SCTP_INP_RLOCK(inp);
4069 stcb = LIST_FIRST(&inp->sctp_asoc_list);
4071 SCTP_TCB_LOCK(stcb);
4072 SCTP_INP_RUNLOCK(inp);
4074 stcb = sctp_findassociation_ep_asocid(inp,
4075 sasoc->sasoc_assoc_id, 1);
4084 if (sasoc->sasoc_asocmaxrxt)
4085 stcb->asoc.max_send_times = sasoc->sasoc_asocmaxrxt;
4086 sasoc->sasoc_number_peer_destinations = stcb->asoc.numnets;
4087 sasoc->sasoc_peer_rwnd = 0;
4088 sasoc->sasoc_local_rwnd = 0;
4089 if (stcb->asoc.cookie_life)
4090 stcb->asoc.cookie_life = sasoc->sasoc_cookie_life;
4091 SCTP_TCB_UNLOCK(stcb);
4093 SCTP_INP_WLOCK(inp);
4094 if (sasoc->sasoc_asocmaxrxt)
4095 inp->sctp_ep.max_send_times = sasoc->sasoc_asocmaxrxt;
4096 sasoc->sasoc_number_peer_destinations = 0;
4097 sasoc->sasoc_peer_rwnd = 0;
4098 sasoc->sasoc_local_rwnd = 0;
4099 if (sasoc->sasoc_cookie_life)
4100 inp->sctp_ep.def_cookie_life = sasoc->sasoc_cookie_life;
4101 SCTP_INP_WUNLOCK(inp);
4107 struct sctp_initmsg *sinit;
4109 if ((size_t)m->m_len < sizeof(struct sctp_initmsg)) {
4113 sinit = mtod(m, struct sctp_initmsg *);
4114 SCTP_INP_WLOCK(inp);
4115 if (sinit->sinit_num_ostreams)
4116 inp->sctp_ep.pre_open_stream_count = sinit->sinit_num_ostreams;
4118 if (sinit->sinit_max_instreams)
4119 inp->sctp_ep.max_open_streams_intome = sinit->sinit_max_instreams;
4121 if (sinit->sinit_max_attempts)
4122 inp->sctp_ep.max_init_times = sinit->sinit_max_attempts;
4124 if (sinit->sinit_max_init_timeo > 10)
4126 * We must be at least a 100ms (we set in
4129 inp->sctp_ep.initial_init_rto_max = sinit->sinit_max_init_timeo;
4130 SCTP_INP_WUNLOCK(inp);
4133 case SCTP_PRIMARY_ADDR:
4135 struct sctp_setprim *spa;
4136 struct sctp_nets *net, *lnet;
4138 if ((size_t)m->m_len < sizeof(struct sctp_setprim)) {
4142 spa = mtod(m, struct sctp_setprim *);
4144 if (inp->sctp_flags & SCTP_PCB_FLAGS_CONNECTED) {
4145 SCTP_INP_RLOCK(inp);
4146 stcb = LIST_FIRST(&inp->sctp_asoc_list);
4148 SCTP_TCB_LOCK(stcb);
4153 SCTP_INP_RUNLOCK(inp);
4155 stcb = sctp_findassociation_ep_asocid(inp, spa->ssp_assoc_id, 1);
4158 SCTP_INP_INCR_REF(inp);
4159 stcb = sctp_findassociation_ep_addr(&inp,
4160 (struct sockaddr *)&spa->ssp_addr,
4163 SCTP_INP_DECR_REF(inp);
4169 * find the net, associd or connected lookup
4172 net = sctp_findnet(stcb, (struct sockaddr *)&spa->ssp_addr);
4174 SCTP_TCB_UNLOCK(stcb);
4179 if ((net != stcb->asoc.primary_destination) &&
4180 (!(net->dest_state & SCTP_ADDR_UNCONFIRMED))) {
4181 /* Ok we need to set it */
4182 lnet = stcb->asoc.primary_destination;
4183 if (sctp_set_primary_addr(stcb,
4184 (struct sockaddr *)NULL,
4186 if (net->dest_state & SCTP_ADDR_SWITCH_PRIMARY) {
4187 net->dest_state |= SCTP_ADDR_DOUBLE_SWITCH;
4189 net->dest_state |= SCTP_ADDR_SWITCH_PRIMARY;
4192 SCTP_TCB_UNLOCK(stcb);
4196 case SCTP_SET_PEER_PRIMARY_ADDR:
4198 struct sctp_setpeerprim *sspp;
4200 if ((size_t)m->m_len < sizeof(struct sctp_setpeerprim)) {
4204 sspp = mtod(m, struct sctp_setpeerprim *);
4207 if (inp->sctp_flags & SCTP_PCB_FLAGS_CONNECTED) {
4208 SCTP_INP_RLOCK(inp);
4209 stcb = LIST_FIRST(&inp->sctp_asoc_list);
4211 SCTP_TCB_UNLOCK(stcb);
4212 SCTP_INP_RUNLOCK(inp);
4214 stcb = sctp_findassociation_ep_asocid(inp, sspp->sspp_assoc_id, 1);
4219 if (sctp_set_primary_ip_address_sa(stcb, (struct sockaddr *)&sspp->sspp_addr) != 0) {
4222 SCTP_TCB_UNLOCK(stcb);
4225 case SCTP_BINDX_ADD_ADDR:
4227 struct sctp_getaddresses *addrs;
4228 struct sockaddr *addr_touse;
4229 struct sockaddr_in sin;
4231 /* see if we're bound all already! */
4232 if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUNDALL) {
4236 if ((size_t)m->m_len < sizeof(struct sctp_getaddresses)) {
4240 addrs = mtod(m, struct sctp_getaddresses *);
4241 addr_touse = addrs->addr;
4242 if (addrs->addr->sa_family == AF_INET6) {
4243 struct sockaddr_in6 *sin6;
4245 sin6 = (struct sockaddr_in6 *)addr_touse;
4246 if (IN6_IS_ADDR_V4MAPPED(&sin6->sin6_addr)) {
4247 in6_sin6_2_sin(&sin, sin6);
4248 addr_touse = (struct sockaddr *)&sin;
4251 if (inp->sctp_flags & SCTP_PCB_FLAGS_UNBOUND) {
4253 /* Can't get proc for Net/Open BSD */
4257 error = sctp_inpcb_bind(so, addr_touse, p);
4261 * No locks required here since bind and mgmt_ep_sa
4262 * all do their own locking. If we do something for
4263 * the FIX: below we may need to lock in that case.
4265 if (addrs->sget_assoc_id == 0) {
4266 /* add the address */
4267 struct sctp_inpcb *lep;
4269 ((struct sockaddr_in *)addr_touse)->sin_port = inp->sctp_lport;
4270 lep = sctp_pcb_findep(addr_touse, 1, 0);
4273 * We must decrement the refcount
4274 * since we have the ep already and
4275 * are binding. No remove going on
4278 SCTP_INP_DECR_REF(inp);
4281 /* already bound to it.. ok */
4283 } else if (lep == NULL) {
4284 ((struct sockaddr_in *)addr_touse)->sin_port = 0;
4285 error = sctp_addr_mgmt_ep_sa(inp, addr_touse,
4286 SCTP_ADD_IP_ADDRESS);
4288 error = EADDRNOTAVAIL;
4295 * FIX: decide whether we allow assoc based
4301 case SCTP_BINDX_REM_ADDR:
4303 struct sctp_getaddresses *addrs;
4304 struct sockaddr *addr_touse;
4305 struct sockaddr_in sin;
4307 /* see if we're bound all already! */
4308 if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUNDALL) {
4312 if ((size_t)m->m_len < sizeof(struct sctp_getaddresses)) {
4316 addrs = mtod(m, struct sctp_getaddresses *);
4317 addr_touse = addrs->addr;
4318 if (addrs->addr->sa_family == AF_INET6) {
4319 struct sockaddr_in6 *sin6;
4321 sin6 = (struct sockaddr_in6 *)addr_touse;
4322 if (IN6_IS_ADDR_V4MAPPED(&sin6->sin6_addr)) {
4323 in6_sin6_2_sin(&sin, sin6);
4324 addr_touse = (struct sockaddr *)&sin;
4328 * No lock required mgmt_ep_sa does its own locking.
4329 * If the FIX: below is ever changed we may need to
4330 * lock before calling association level binding.
4332 if (addrs->sget_assoc_id == 0) {
4333 /* delete the address */
4334 sctp_addr_mgmt_ep_sa(inp, addr_touse,
4335 SCTP_DEL_IP_ADDRESS);
4338 * FIX: decide whether we allow assoc based
4345 error = ENOPROTOOPT;
4347 } /* end switch (opt) */
4353 extern int sctp_chatty_mbuf;
4356 sctp_ctloutput(struct socket *so, struct sockopt *sopt)
4358 struct mbuf *m = NULL;
4359 struct sctp_inpcb *inp;
4362 inp = (struct sctp_inpcb *)so->so_pcb;
4366 /* I made the same as TCP since we are not setup? */
4367 return (ECONNRESET);
4369 if (sopt->sopt_level != IPPROTO_SCTP) {
4370 /* wrong proto level... send back up to IP */
4372 if (INP_CHECK_SOCKAF(so, AF_INET6))
4373 error = ip6_ctloutput(so, sopt);
4376 error = ip_ctloutput(so, sopt);
4380 if (sopt->sopt_valsize) {
4381 if (sopt->sopt_valsize < MLEN) {
4382 m = sctp_get_mbuf_for_msg(1, 0, M_WAIT, 1, MT_DATA);
4384 m = sctp_get_mbuf_for_msg(sopt->sopt_valsize, 0, M_WAIT, 1, MT_DATA);
4391 if (sopt->sopt_valsize > M_TRAILINGSPACE(m)) {
4392 /* Limit to actual size gotten */
4393 sopt->sopt_valsize = M_TRAILINGSPACE(m);
4395 error = sooptcopyin(sopt, mtod(m, caddr_t), sopt->sopt_valsize,
4396 sopt->sopt_valsize);
4398 (void)sctp_m_free(m);
4401 m->m_len = sopt->sopt_valsize;
4403 if (sopt->sopt_dir == SOPT_SET) {
4404 error = sctp_optsset(so, sopt->sopt_name, &m, sopt->sopt_td);
4405 } else if (sopt->sopt_dir == SOPT_GET) {
4406 error = sctp_optsget(so, sopt->sopt_name, &m, sopt->sopt_td);
4410 if ((error == 0) && (m != NULL)) {
4411 error = sooptcopyout(sopt, mtod(m, caddr_t), m->m_len);
4413 } else if (m != NULL) {
4423 sctp_connect(struct socket *so, struct sockaddr *addr, struct thread *p)
4428 int create_lock_on = 0;
4429 struct sctp_inpcb *inp;
4430 struct sctp_tcb *stcb = NULL;
4432 inp = (struct sctp_inpcb *)so->so_pcb;
4435 /* I made the same as TCP since we are not setup? */
4436 return (ECONNRESET);
4438 SCTP_ASOC_CREATE_LOCK(inp);
4441 SCTP_INP_INCR_REF(inp);
4442 if ((inp->sctp_flags & SCTP_PCB_FLAGS_SOCKET_ALLGONE) ||
4443 (inp->sctp_flags & SCTP_PCB_FLAGS_SOCKET_GONE)) {
4444 /* Should I really unlock ? */
4449 if (((inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) == 0) &&
4450 (addr->sa_family == AF_INET6)) {
4455 if ((inp->sctp_flags & SCTP_PCB_FLAGS_UNBOUND) ==
4456 SCTP_PCB_FLAGS_UNBOUND) {
4457 /* Bind a ephemeral port */
4458 error = sctp_inpcb_bind(so, NULL, p);
4463 /* Now do we connect? */
4464 if (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) {
4468 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) &&
4469 (inp->sctp_flags & SCTP_PCB_FLAGS_CONNECTED)) {
4470 /* We are already connected AND the TCP model */
4474 if (inp->sctp_flags & SCTP_PCB_FLAGS_CONNECTED) {
4475 SCTP_INP_RLOCK(inp);
4476 stcb = LIST_FIRST(&inp->sctp_asoc_list);
4478 SCTP_TCB_UNLOCK(stcb);
4479 SCTP_INP_RUNLOCK(inp);
4482 * Raise the count a second time, since on sucess
4483 * f-a-ep_addr will decrement it.
4485 SCTP_INP_INCR_REF(inp);
4486 stcb = sctp_findassociation_ep_addr(&inp, addr, NULL, NULL, NULL);
4488 SCTP_INP_DECR_REF(inp);
4492 /* Already have or am bring up an association */
4496 /* We are GOOD to go */
4497 stcb = sctp_aloc_assoc(inp, addr, 1, &error, 0);
4499 /* Gak! no memory */
4503 if (stcb->sctp_ep->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) {
4504 stcb->sctp_ep->sctp_flags |= SCTP_PCB_FLAGS_CONNECTED;
4505 /* Set the connected flag so we can queue data */
4508 stcb->asoc.state = SCTP_STATE_COOKIE_WAIT;
4509 SCTP_GETTIME_TIMEVAL(&stcb->asoc.time_entered);
4511 /* initialize authentication parameters for the assoc */
4512 sctp_initialize_auth_params(inp, stcb);
4514 sctp_send_initiate(inp, stcb);
4517 SCTP_ASOC_CREATE_UNLOCK(inp);
4520 SCTP_TCB_UNLOCK(stcb);
4521 SCTP_INP_DECR_REF(inp);
4527 sctp_listen(struct socket *so, int backlog, struct thread *p)
4530 * Note this module depends on the protocol processing being called
4531 * AFTER any socket level flags and backlog are applied to the
4532 * socket. The traditional way that the socket flags are applied is
4533 * AFTER protocol processing. We have made a change to the
4534 * sys/kern/uipc_socket.c module to reverse this but this MUST be in
4535 * place if the socket API for SCTP is to work properly.
4540 struct sctp_inpcb *inp;
4542 inp = (struct sctp_inpcb *)so->so_pcb;
4545 /* I made the same as TCP since we are not setup? */
4546 return (ECONNRESET);
4548 SCTP_INP_RLOCK(inp);
4549 #ifdef SCTP_LOCK_LOGGING
4550 sctp_log_lock(inp, (struct sctp_tcb *)NULL, SCTP_LOG_LOCK_SOCK);
4553 error = solisten_proto_check(so);
4558 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) &&
4559 (inp->sctp_flags & SCTP_PCB_FLAGS_CONNECTED)) {
4560 /* We are already connected AND the TCP model */
4562 SCTP_INP_RUNLOCK(inp);
4564 return (EADDRINUSE);
4566 if (inp->sctp_flags & SCTP_PCB_FLAGS_UNBOUND) {
4567 /* We must do a bind. */
4568 SCTP_INP_RUNLOCK(inp);
4569 if ((error = sctp_inpcb_bind(so, NULL, p))) {
4570 /* bind error, probably perm */
4576 SCTP_INP_RUNLOCK(inp);
4578 /* It appears for 7.0 and on, we must always call this. */
4579 solisten_proto(so, backlog);
4581 if (inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) {
4582 /* remove the ACCEPTCONN flag for one-to-many sockets */
4583 so->so_options &= ~SO_ACCEPTCONN;
4586 /* turning off listen */
4587 so->so_options &= ~SO_ACCEPTCONN;
4594 static int sctp_defered_wakeup_cnt = 0;
4597 sctp_accept(struct socket *so, struct sockaddr **addr)
4601 struct sctp_tcb *stcb;
4602 struct sctp_inpcb *inp;
4603 union sctp_sockstore store;
4608 inp = (struct sctp_inpcb *)so->so_pcb;
4612 return (ECONNRESET);
4614 SCTP_INP_RLOCK(inp);
4615 if (inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) {
4618 if (so->so_state & SS_ISDISCONNECTED) {
4620 SCTP_INP_RUNLOCK(inp);
4621 return (ECONNABORTED);
4623 stcb = LIST_FIRST(&inp->sctp_asoc_list);
4626 SCTP_INP_RUNLOCK(inp);
4627 return (ECONNRESET);
4629 SCTP_TCB_LOCK(stcb);
4630 SCTP_INP_RUNLOCK(inp);
4631 store = stcb->asoc.primary_destination->ro._l_addr;
4632 SCTP_TCB_UNLOCK(stcb);
4633 if (store.sa.sa_family == AF_INET) {
4634 struct sockaddr_in *sin;
4636 SCTP_MALLOC_SONAME(sin, struct sockaddr_in *, sizeof *sin);
4637 sin->sin_family = AF_INET;
4638 sin->sin_len = sizeof(*sin);
4639 sin->sin_port = ((struct sockaddr_in *)&store)->sin_port;
4640 sin->sin_addr = ((struct sockaddr_in *)&store)->sin_addr;
4641 *addr = (struct sockaddr *)sin;
4643 struct sockaddr_in6 *sin6;
4645 SCTP_MALLOC_SONAME(sin6, struct sockaddr_in6 *, sizeof *sin6);
4646 sin6->sin6_family = AF_INET6;
4647 sin6->sin6_len = sizeof(*sin6);
4648 sin6->sin6_port = ((struct sockaddr_in6 *)&store)->sin6_port;
4650 sin6->sin6_addr = ((struct sockaddr_in6 *)&store)->sin6_addr;
4651 if ((error = sa6_recoverscope(sin6)) != 0)
4653 *addr = (struct sockaddr *)sin6;
4655 /* Wake any delayed sleep action */
4656 if (inp->sctp_flags & SCTP_PCB_FLAGS_DONT_WAKE) {
4657 inp->sctp_flags &= ~SCTP_PCB_FLAGS_DONT_WAKE;
4658 if (inp->sctp_flags & SCTP_PCB_FLAGS_WAKEOUTPUT) {
4659 inp->sctp_flags &= ~SCTP_PCB_FLAGS_WAKEOUTPUT;
4660 SOCKBUF_LOCK(&inp->sctp_socket->so_snd);
4661 if (sowriteable(inp->sctp_socket)) {
4662 sowwakeup_locked(inp->sctp_socket);
4664 SOCKBUF_UNLOCK(&inp->sctp_socket->so_snd);
4667 if (inp->sctp_flags & SCTP_PCB_FLAGS_WAKEINPUT) {
4668 inp->sctp_flags &= ~SCTP_PCB_FLAGS_WAKEINPUT;
4669 SOCKBUF_LOCK(&inp->sctp_socket->so_rcv);
4670 if (soreadable(inp->sctp_socket)) {
4671 sctp_defered_wakeup_cnt++;
4672 sorwakeup_locked(inp->sctp_socket);
4674 SOCKBUF_UNLOCK(&inp->sctp_socket->so_rcv);
4683 sctp_ingetaddr(struct socket *so, struct sockaddr **addr)
4685 struct sockaddr_in *sin;
4688 struct sctp_inpcb *inp;
4691 * Do the malloc first in case it blocks.
4693 SCTP_MALLOC_SONAME(sin, struct sockaddr_in *, sizeof *sin);
4694 sin->sin_family = AF_INET;
4695 sin->sin_len = sizeof(*sin);
4697 inp = (struct sctp_inpcb *)so->so_pcb;
4700 SCTP_FREE_SONAME(sin);
4703 SCTP_INP_RLOCK(inp);
4704 sin->sin_port = inp->sctp_lport;
4705 if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUNDALL) {
4706 if (inp->sctp_flags & SCTP_PCB_FLAGS_CONNECTED) {
4707 struct sctp_tcb *stcb;
4708 struct sockaddr_in *sin_a;
4709 struct sctp_nets *net;
4712 stcb = LIST_FIRST(&inp->sctp_asoc_list);
4718 SCTP_TCB_LOCK(stcb);
4719 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
4720 sin_a = (struct sockaddr_in *)&net->ro._l_addr;
4721 if (sin_a->sin_family == AF_INET) {
4726 if ((!fnd) || (sin_a == NULL)) {
4728 SCTP_TCB_UNLOCK(stcb);
4731 sin->sin_addr = sctp_ipv4_source_address_selection(inp,
4732 stcb, (struct route *)&net->ro, net, 0);
4733 SCTP_TCB_UNLOCK(stcb);
4735 /* For the bound all case you get back 0 */
4737 sin->sin_addr.s_addr = 0;
4741 /* Take the first IPv4 address in the list */
4742 struct sctp_laddr *laddr;
4745 LIST_FOREACH(laddr, &inp->sctp_addr_list, sctp_nxt_addr) {
4746 if (laddr->ifa->ifa_addr->sa_family == AF_INET) {
4747 struct sockaddr_in *sin_a;
4749 sin_a = (struct sockaddr_in *)laddr->ifa->ifa_addr;
4750 sin->sin_addr = sin_a->sin_addr;
4757 SCTP_FREE_SONAME(sin);
4758 SCTP_INP_RUNLOCK(inp);
4762 SCTP_INP_RUNLOCK(inp);
4764 (*addr) = (struct sockaddr *)sin;
4769 sctp_peeraddr(struct socket *so, struct sockaddr **addr)
4771 struct sockaddr_in *sin = (struct sockaddr_in *)*addr;
4774 struct sockaddr_in *sin_a;
4775 struct sctp_inpcb *inp;
4776 struct sctp_tcb *stcb;
4777 struct sctp_nets *net;
4780 /* Do the malloc first in case it blocks. */
4781 inp = (struct sctp_inpcb *)so->so_pcb;
4782 if ((inp == NULL) ||
4783 ((inp->sctp_flags & SCTP_PCB_FLAGS_CONNECTED) == 0)) {
4784 /* UDP type and listeners will drop out here */
4789 SCTP_MALLOC_SONAME(sin, struct sockaddr_in *, sizeof *sin);
4790 sin->sin_family = AF_INET;
4791 sin->sin_len = sizeof(*sin);
4793 /* We must recapture incase we blocked */
4794 inp = (struct sctp_inpcb *)so->so_pcb;
4797 SCTP_FREE_SONAME(sin);
4800 SCTP_INP_RLOCK(inp);
4801 stcb = LIST_FIRST(&inp->sctp_asoc_list);
4803 SCTP_TCB_LOCK(stcb);
4804 SCTP_INP_RUNLOCK(inp);
4807 SCTP_FREE_SONAME(sin);
4811 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
4812 sin_a = (struct sockaddr_in *)&net->ro._l_addr;
4813 if (sin_a->sin_family == AF_INET) {
4815 sin->sin_port = stcb->rport;
4816 sin->sin_addr = sin_a->sin_addr;
4820 SCTP_TCB_UNLOCK(stcb);
4822 /* No IPv4 address */
4824 SCTP_FREE_SONAME(sin);
4828 (*addr) = (struct sockaddr *)sin;
4832 struct pr_usrreqs sctp_usrreqs = {
4833 .pru_abort = sctp_abort,
4834 .pru_accept = sctp_accept,
4835 .pru_attach = sctp_attach,
4836 .pru_bind = sctp_bind,
4837 .pru_connect = sctp_connect,
4838 .pru_control = in_control,
4839 .pru_close = sctp_close,
4840 .pru_detach = sctp_close,
4841 .pru_sopoll = sopoll_generic,
4842 .pru_disconnect = sctp_disconnect,
4843 .pru_listen = sctp_listen,
4844 .pru_peeraddr = sctp_peeraddr,
4845 .pru_send = sctp_sendm,
4846 .pru_shutdown = sctp_shutdown,
4847 .pru_sockaddr = sctp_ingetaddr,
4848 .pru_sosend = sctp_sosend,
4849 .pru_soreceive = sctp_soreceive