1 /* $KAME: sctp_usrreq.c,v 1.47 2005/03/06 16:04:18 itojun Exp $ */
2 /* $DragonFly: src/sys/netinet/sctp_usrreq.c,v 1.14 2008/04/20 13:44:25 swildner Exp $ */
5 * Copyright (c) 2001, 2002, 2003, 2004 Cisco Systems, Inc.
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
11 * 1. Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in the
15 * documentation and/or other materials provided with the distribution.
16 * 3. All advertising materials mentioning features or use of this software
17 * must display the following acknowledgement:
18 * This product includes software developed by Cisco Systems, Inc.
19 * 4. Neither the name of the project nor the names of its contributors
20 * may be used to endorse or promote products derived from this software
21 * without specific prior written permission.
23 * THIS SOFTWARE IS PROVIDED BY CISCO SYSTEMS AND CONTRIBUTORS ``AS IS'' AND
24 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
25 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
26 * ARE DISCLAIMED. IN NO EVENT SHALL CISCO SYSTEMS OR CONTRIBUTORS BE LIABLE
27 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
28 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
29 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
30 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
31 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
32 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
35 #if !(defined(__OpenBSD__) || defined(__APPLE__))
36 #include "opt_ipsec.h"
38 #if defined(__FreeBSD__) || defined(__DragonFly__)
39 #include "opt_inet6.h"
42 #if defined(__NetBSD__)
48 #elif !defined(__OpenBSD__)
52 #include <sys/param.h>
53 #include <sys/systm.h>
54 #include <sys/kernel.h>
55 #include <sys/malloc.h>
57 #include <sys/domain.h>
60 #include <sys/protosw.h>
61 #include <sys/socket.h>
62 #include <sys/socketvar.h>
63 #include <sys/sysctl.h>
64 #include <sys/syslog.h>
65 #include <sys/thread2.h>
67 #include <net/if_types.h>
68 #if defined(__FreeBSD__) || defined(__APPLE__) || defined(__DragonFly__)
69 #include <net/if_var.h>
71 #include <net/route.h>
72 #include <netinet/in.h>
73 #include <netinet/in_systm.h>
74 #include <netinet/ip.h>
75 #include <netinet/ip6.h>
76 #include <netinet/in_pcb.h>
77 #include <netinet/in_var.h>
78 #include <netinet/ip_var.h>
79 #include <netinet6/ip6_var.h>
80 #include <netinet6/in6_var.h>
82 #include <netinet/ip_icmp.h>
83 #include <netinet/icmp_var.h>
84 #include <netinet/sctp_pcb.h>
85 #include <netinet/sctp_header.h>
86 #include <netinet/sctp_var.h>
87 #include <netinet/sctp_output.h>
88 #include <netinet/sctp_uio.h>
89 #include <netinet/sctp_asconf.h>
90 #include <netinet/sctputil.h>
91 #include <netinet/sctp_indata.h>
92 #include <netinet/sctp_asconf.h>
95 #include <netinet6/ipsec.h>
96 #include <netproto/key/key.h>
102 #include <net/net_osdep.h>
104 #if defined(HAVE_NRL_INPCB) || defined(__FreeBSD__) || defined(__DragonFly__)
109 #define sotoin6pcb sotoinpcb
114 extern u_int32_t sctp_debug_on
;
115 #endif /* SCTP_DEBUG */
118 * sysctl tunable variables
120 int sctp_auto_asconf
= SCTP_DEFAULT_AUTO_ASCONF
;
121 int sctp_max_burst_default
= SCTP_DEF_MAX_BURST
;
122 int sctp_peer_chunk_oh
= sizeof(struct mbuf
);
123 int sctp_strict_init
= 1;
124 int sctp_no_csum_on_loopback
= 1;
125 unsigned int sctp_max_chunks_on_queue
= SCTP_ASOC_MAX_CHUNKS_ON_QUEUE
;
126 int sctp_sendspace
= (128 * 1024);
127 int sctp_recvspace
= 128 * (1024 +
129 sizeof(struct sockaddr_in6
)
131 sizeof(struct sockaddr_in
)
134 int sctp_strict_sacks
= 0;
136 int sctp_ecn_nonce
= 0;
138 unsigned int sctp_delayed_sack_time_default
= SCTP_RECV_MSEC
;
139 unsigned int sctp_heartbeat_interval_default
= SCTP_HB_DEFAULT_MSEC
;
140 unsigned int sctp_pmtu_raise_time_default
= SCTP_DEF_PMTU_RAISE_SEC
;
141 unsigned int sctp_shutdown_guard_time_default
= SCTP_DEF_MAX_SHUTDOWN_SEC
;
142 unsigned int sctp_secret_lifetime_default
= SCTP_DEFAULT_SECRET_LIFE_SEC
;
143 unsigned int sctp_rto_max_default
= SCTP_RTO_UPPER_BOUND
;
144 unsigned int sctp_rto_min_default
= SCTP_RTO_LOWER_BOUND
;
145 unsigned int sctp_rto_initial_default
= SCTP_RTO_INITIAL
;
146 unsigned int sctp_init_rto_max_default
= SCTP_RTO_UPPER_BOUND
;
147 unsigned int sctp_valid_cookie_life_default
= SCTP_DEFAULT_COOKIE_LIFE
;
148 unsigned int sctp_init_rtx_max_default
= SCTP_DEF_MAX_INIT
;
149 unsigned int sctp_assoc_rtx_max_default
= SCTP_DEF_MAX_SEND
;
150 unsigned int sctp_path_rtx_max_default
= SCTP_DEF_MAX_SEND
/2;
151 unsigned int sctp_nr_outgoing_streams_default
= SCTP_OSTREAM_INITIAL
;
157 #define nmbclusters nmbclust
159 /* Init the SCTP pcb in sctp_pcb.c */
165 if (nmbclusters
> SCTP_ASOC_MAX_CHUNKS_ON_QUEUE
)
166 sctp_max_chunks_on_queue
= nmbclusters
;
168 /* if (nmbclust > SCTP_ASOC_MAX_CHUNKS_ON_QUEUE)
169 sctp_max_chunks_on_queue = nmbclust; FIX ME */
170 sctp_max_chunks_on_queue
= nmbclust
* 2;
173 * Allow a user to take no more than 1/2 the number of clusters
174 * or the SB_MAX whichever is smaller for the send window.
176 sb_max_adj
= (u_long
)((u_quad_t
)(SB_MAX
) * MCLBYTES
/ (MSIZE
+ MCLBYTES
));
177 sctp_sendspace
= min((min(SB_MAX
, sb_max_adj
)),
179 ((nmbclusters
/2) * SCTP_DEFAULT_MAXSEGMENT
));
181 ((nmbclust
/2) * SCTP_DEFAULT_MAXSEGMENT
));
184 * Now for the recv window, should we take the same amount?
185 * or should I do 1/2 the SB_MAX instead in the SB_MAX min above.
186 * For now I will just copy.
188 sctp_recvspace
= sctp_sendspace
;
196 ip_2_ip6_hdr(struct ip6_hdr
*ip6
, struct ip
*ip
)
198 bzero(ip6
, sizeof(*ip6
));
200 ip6
->ip6_vfc
= IPV6_VERSION
;
201 ip6
->ip6_plen
= ip
->ip_len
;
202 ip6
->ip6_nxt
= ip
->ip_p
;
203 ip6
->ip6_hlim
= ip
->ip_ttl
;
204 ip6
->ip6_src
.s6_addr32
[2] = ip6
->ip6_dst
.s6_addr32
[2] =
206 ip6
->ip6_src
.s6_addr32
[3] = ip
->ip_src
.s_addr
;
207 ip6
->ip6_dst
.s6_addr32
[3] = ip
->ip_dst
.s_addr
;
212 sctp_split_chunks(struct sctp_association
*asoc
,
213 struct sctp_stream_out
*strm
,
214 struct sctp_tmit_chunk
*chk
)
216 struct sctp_tmit_chunk
*new_chk
;
218 /* First we need a chunk */
219 new_chk
= (struct sctp_tmit_chunk
*)SCTP_ZONE_GET(sctppcbinfo
.ipi_zone_chunk
);
220 if (new_chk
== NULL
) {
221 chk
->flags
|= CHUNK_FLAGS_FRAGMENT_OK
;
224 sctppcbinfo
.ipi_count_chunk
++;
225 sctppcbinfo
.ipi_gencnt_chunk
++;
229 new_chk
->data
= m_split(chk
->data
, (chk
->send_size
>>1), MB_DONTWAIT
);
230 if (new_chk
->data
== NULL
) {
232 chk
->flags
|= CHUNK_FLAGS_FRAGMENT_OK
;
233 SCTP_ZONE_FREE(sctppcbinfo
.ipi_zone_chunk
, new_chk
);
234 sctppcbinfo
.ipi_count_chunk
--;
235 if ((int)sctppcbinfo
.ipi_count_chunk
< 0) {
236 panic("Chunk count is negative");
238 sctppcbinfo
.ipi_gencnt_chunk
++;
242 /* Data is now split adjust sizes */
243 chk
->send_size
>>= 1;
244 new_chk
->send_size
>>= 1;
246 chk
->book_size
>>= 1;
247 new_chk
->book_size
>>= 1;
249 /* now adjust the marks */
250 chk
->rec
.data
.rcv_flags
|= SCTP_DATA_FIRST_FRAG
;
251 chk
->rec
.data
.rcv_flags
&= ~SCTP_DATA_LAST_FRAG
;
253 new_chk
->rec
.data
.rcv_flags
&= ~SCTP_DATA_FIRST_FRAG
;
254 new_chk
->rec
.data
.rcv_flags
|= SCTP_DATA_LAST_FRAG
;
256 /* Increase ref count if dest is set */
258 new_chk
->whoTo
->ref_count
++;
260 /* now drop it on the end of the list*/
261 asoc
->stream_queue_cnt
++;
262 TAILQ_INSERT_AFTER(&strm
->outqueue
, chk
, new_chk
, sctp_next
);
266 sctp_notify_mbuf(struct sctp_inpcb
*inp
,
267 struct sctp_tcb
*stcb
,
268 struct sctp_nets
*net
,
278 if ((inp
== NULL
) || (stcb
== NULL
) || (net
== NULL
) ||
279 (ip
== NULL
) || (sh
== NULL
)) {
281 SCTP_TCB_UNLOCK(stcb
);
284 /* First job is to verify the vtag matches what I would send */
285 if (ntohl(sh
->v_tag
) != (stcb
->asoc
.peer_vtag
)) {
286 SCTP_TCB_UNLOCK(stcb
);
289 icmph
= (struct icmp
*)((caddr_t
)ip
- (sizeof(struct icmp
) -
291 if (icmph
->icmp_type
!= ICMP_UNREACH
) {
292 /* We only care about unreachable */
293 SCTP_TCB_UNLOCK(stcb
);
296 if (icmph
->icmp_code
!= ICMP_UNREACH_NEEDFRAG
) {
297 /* not a unreachable message due to frag. */
298 SCTP_TCB_UNLOCK(stcb
);
302 nxtsz
= ntohs(icmph
->icmp_seq
);
305 * old type router that does not tell us what the next size
306 * mtu is. Rats we will have to guess (in a educated fashion
309 nxtsz
= find_next_best_mtu(totsz
);
312 /* Stop any PMTU timer */
313 sctp_timer_stop(SCTP_TIMER_TYPE_PATHMTURAISE
, inp
, stcb
, NULL
);
315 /* Adjust destination size limit */
316 if (net
->mtu
> nxtsz
) {
319 /* now what about the ep? */
320 if (stcb
->asoc
.smallest_mtu
> nxtsz
) {
321 struct sctp_tmit_chunk
*chk
, *nchk
;
322 struct sctp_stream_out
*strm
;
323 /* Adjust that too */
324 stcb
->asoc
.smallest_mtu
= nxtsz
;
325 /* now off to subtract IP_DF flag if needed */
327 TAILQ_FOREACH(chk
, &stcb
->asoc
.send_queue
, sctp_next
) {
328 if ((chk
->send_size
+IP_HDR_SIZE
) > nxtsz
) {
329 chk
->flags
|= CHUNK_FLAGS_FRAGMENT_OK
;
332 TAILQ_FOREACH(chk
, &stcb
->asoc
.sent_queue
, sctp_next
) {
333 if ((chk
->send_size
+IP_HDR_SIZE
) > nxtsz
) {
335 * For this guy we also mark for immediate
336 * resend since we sent to big of chunk
338 chk
->flags
|= CHUNK_FLAGS_FRAGMENT_OK
;
339 if (chk
->sent
!= SCTP_DATAGRAM_RESEND
) {
340 stcb
->asoc
.sent_queue_retran_cnt
++;
342 chk
->sent
= SCTP_DATAGRAM_RESEND
;
343 chk
->rec
.data
.doing_fast_retransmit
= 0;
345 /* Clear any time so NO RTT is being done */
347 stcb
->asoc
.total_flight
-= chk
->book_size
;
348 if (stcb
->asoc
.total_flight
< 0) {
349 stcb
->asoc
.total_flight
= 0;
351 stcb
->asoc
.total_flight_count
--;
352 if (stcb
->asoc
.total_flight_count
< 0) {
353 stcb
->asoc
.total_flight_count
= 0;
355 net
->flight_size
-= chk
->book_size
;
356 if (net
->flight_size
< 0) {
357 net
->flight_size
= 0;
361 TAILQ_FOREACH(strm
, &stcb
->asoc
.out_wheel
, next_spoke
) {
362 chk
= TAILQ_FIRST(&strm
->outqueue
);
364 nchk
= TAILQ_NEXT(chk
, sctp_next
);
365 if ((chk
->send_size
+SCTP_MED_OVERHEAD
) > nxtsz
) {
366 sctp_split_chunks(&stcb
->asoc
, strm
, chk
);
372 sctp_timer_start(SCTP_TIMER_TYPE_PATHMTURAISE
, inp
, stcb
, NULL
);
373 SCTP_TCB_UNLOCK(stcb
);
378 sctp_notify(struct sctp_inpcb
*inp
,
382 struct sctp_tcb
*stcb
,
383 struct sctp_nets
*net
)
386 if ((inp
== NULL
) || (stcb
== NULL
) || (net
== NULL
) ||
387 (sh
== NULL
) || (to
== NULL
)) {
389 if (sctp_debug_on
& SCTP_DEBUG_USRREQ1
) {
390 kprintf("sctp-notify, bad call\n");
392 #endif /* SCTP_DEBUG */
395 /* First job is to verify the vtag matches what I would send */
396 if (ntohl(sh
->v_tag
) != (stcb
->asoc
.peer_vtag
)) {
400 /* FIX ME FIX ME PROTOPT i.e. no SCTP should ALWAYS be an ABORT */
402 if ((error
== EHOSTUNREACH
) || /* Host is not reachable */
403 (error
== EHOSTDOWN
) || /* Host is down */
404 (error
== ECONNREFUSED
) || /* Host refused the connection, (not an abort?) */
405 (error
== ENOPROTOOPT
) /* SCTP is not present on host */
408 * Hmm reachablity problems we must examine closely.
409 * If its not reachable, we may have lost a network.
410 * Or if there is NO protocol at the other end named SCTP.
411 * well we consider it a OOTB abort.
413 if ((error
== EHOSTUNREACH
) || (error
== EHOSTDOWN
)) {
414 if (net
->dest_state
& SCTP_ADDR_REACHABLE
) {
415 /* Ok that destination is NOT reachable */
416 net
->dest_state
&= ~SCTP_ADDR_REACHABLE
;
417 net
->dest_state
|= SCTP_ADDR_NOT_REACHABLE
;
418 net
->error_count
= net
->failure_threshold
+ 1;
419 sctp_ulp_notify(SCTP_NOTIFY_INTERFACE_DOWN
,
420 stcb
, SCTP_FAILED_THRESHOLD
,
424 SCTP_TCB_UNLOCK(stcb
);
427 * Here the peer is either playing tricks on us,
428 * including an address that belongs to someone who
429 * does not support SCTP OR was a userland
430 * implementation that shutdown and now is dead. In
431 * either case treat it like a OOTB abort with no TCB
433 sctp_abort_notification(stcb
, SCTP_PEER_FAULTY
);
434 sctp_free_assoc(inp
, stcb
);
435 /* no need to unlock here, since the TCB is gone */
438 /* Send all others to the app */
439 if (inp
->sctp_socket
) {
440 SOCK_LOCK(inp
->sctp_socket
);
441 inp
->sctp_socket
->so_error
= error
;
442 sctp_sowwakeup(inp
, inp
->sctp_socket
);
443 SOCK_UNLOCK(inp
->sctp_socket
);
446 SCTP_TCB_UNLOCK(stcb
);
450 #if defined(__FreeBSD__) || defined(__APPLE__) || defined(__DragonFly__)
455 sctp_ctlinput(int cmd
, struct sockaddr
*sa
, void *vip
)
461 if (sa
->sa_family
!= AF_INET
||
462 ((struct sockaddr_in
*)sa
)->sin_addr
.s_addr
== INADDR_ANY
) {
463 #if defined(__FreeBSD__) || defined(__APPLE__) || defined(__DragonFly__)
470 if (PRC_IS_REDIRECT(cmd
)) {
472 } else if ((unsigned)cmd
>= PRC_NCMDS
|| inetctlerrmap
[cmd
] == 0) {
473 #if defined(__FreeBSD__) || defined(__APPLE__) || defined(__DragonFly__)
480 struct sctp_inpcb
*inp
;
481 struct sctp_tcb
*stcb
;
482 struct sctp_nets
*net
;
483 struct sockaddr_in to
, from
;
485 sh
= (struct sctphdr
*)((caddr_t
)ip
+ (ip
->ip_hl
<< 2));
486 bzero(&to
, sizeof(to
));
487 bzero(&from
, sizeof(from
));
488 from
.sin_family
= to
.sin_family
= AF_INET
;
489 from
.sin_len
= to
.sin_len
= sizeof(to
);
490 from
.sin_port
= sh
->src_port
;
491 from
.sin_addr
= ip
->ip_src
;
492 to
.sin_port
= sh
->dest_port
;
493 to
.sin_addr
= ip
->ip_dst
;
496 * 'to' holds the dest of the packet that failed to be sent.
497 * 'from' holds our local endpoint address.
498 * Thus we reverse the to and the from in the lookup.
501 stcb
= sctp_findassociation_addr_sa((struct sockaddr
*)&from
,
502 (struct sockaddr
*)&to
,
504 if (stcb
!= NULL
&& inp
&& (inp
->sctp_socket
!= NULL
)) {
505 if (cmd
!= PRC_MSGSIZE
) {
507 if (cmd
== PRC_HOSTDEAD
) {
510 cm
= inetctlerrmap
[cmd
];
512 sctp_notify(inp
, cm
, sh
,
513 (struct sockaddr
*)&to
, stcb
,
516 /* handle possible ICMP size messages */
517 sctp_notify_mbuf(inp
, stcb
, net
, ip
, sh
);
520 #if (defined(__FreeBSD__) && __FreeBSD_version < 500000) || defined(__DragonFly__)
521 /* XXX must be fixed for 5.x and higher, leave for 4.x */
522 if (PRC_IS_REDIRECT(cmd
) && inp
) {
523 in_rtchange((struct inpcb
*)inp
,
527 if ((stcb
== NULL
) && (inp
!= NULL
)) {
528 /* reduce ref-count */
530 SCTP_INP_DECR_REF(inp
);
531 SCTP_INP_WUNLOCK(inp
);
537 #if defined(__FreeBSD__) || defined(__APPLE__) || defined(__DragonFly__)
544 #if defined(__FreeBSD__) || defined(__DragonFly__)
546 sctp_getcred(SYSCTL_HANDLER_ARGS
)
548 struct sockaddr_in addrs
[2];
549 struct sctp_inpcb
*inp
;
550 struct sctp_nets
*net
;
551 struct sctp_tcb
*stcb
;
554 #if __FreeBSD_version >= 500000 || defined(__DragonFly__)
555 error
= priv_check(req
->td
, PRIV_ROOT
);
557 error
= suser(req
->p
);
561 error
= SYSCTL_IN(req
, addrs
, sizeof(addrs
));
566 stcb
= sctp_findassociation_addr_sa(sintosa(&addrs
[0]),
569 if (stcb
== NULL
|| inp
== NULL
|| inp
->sctp_socket
== NULL
) {
570 if ((inp
!= NULL
) && (stcb
== NULL
)) {
571 /* reduce ref-count */
573 SCTP_INP_DECR_REF(inp
);
574 SCTP_INP_WUNLOCK(inp
);
579 error
= SYSCTL_OUT(req
, inp
->sctp_socket
->so_cred
, sizeof(struct ucred
));
580 SCTP_TCB_UNLOCK(stcb
);
586 SYSCTL_PROC(_net_inet_sctp
, OID_AUTO
, getcred
, CTLTYPE_OPAQUE
|CTLFLAG_RW
,
587 0, 0, sctp_getcred
, "S,ucred", "Get the ucred of a SCTP connection");
588 #endif /* #if defined(__FreeBSD__) || defined(__DragonFly__) */
593 #if defined(__FreeBSD__) || defined (__APPLE__) || defined(__DragonFly__)
595 SYSCTL_DECL(_net_inet
);
597 SYSCTL_NODE(_net_inet
, OID_AUTO
, sctp
, CTLFLAG_RD
, 0,
600 SYSCTL_INT(_net_inet_sctp
, OID_AUTO
, maxdgram
, CTLFLAG_RW
,
601 &sctp_sendspace
, 0, "Maximum outgoing SCTP buffer size");
603 SYSCTL_INT(_net_inet_sctp
, OID_AUTO
, recvspace
, CTLFLAG_RW
,
604 &sctp_recvspace
, 0, "Maximum incoming SCTP buffer size");
606 SYSCTL_INT(_net_inet_sctp
, OID_AUTO
, auto_asconf
, CTLFLAG_RW
,
607 &sctp_auto_asconf
, 0, "Enable SCTP Auto-ASCONF");
609 SYSCTL_INT(_net_inet_sctp
, OID_AUTO
, ecn_enable
, CTLFLAG_RW
,
610 &sctp_ecn
, 0, "Enable SCTP ECN");
612 SYSCTL_INT(_net_inet_sctp
, OID_AUTO
, ecn_nonce
, CTLFLAG_RW
,
613 &sctp_ecn_nonce
, 0, "Enable SCTP ECN Nonce");
615 SYSCTL_INT(_net_inet_sctp
, OID_AUTO
, strict_sacks
, CTLFLAG_RW
,
616 &sctp_strict_sacks
, 0, "Enable SCTP Strict SACK checking");
618 SYSCTL_INT(_net_inet_sctp
, OID_AUTO
, loopback_nocsum
, CTLFLAG_RW
,
619 &sctp_no_csum_on_loopback
, 0,
620 "Enable NO Csum on packets sent on loopback");
622 SYSCTL_INT(_net_inet_sctp
, OID_AUTO
, strict_init
, CTLFLAG_RW
,
623 &sctp_strict_init
, 0,
624 "Enable strict INIT/INIT-ACK singleton enforcement");
626 SYSCTL_INT(_net_inet_sctp
, OID_AUTO
, peer_chkoh
, CTLFLAG_RW
,
627 &sctp_peer_chunk_oh
, 0,
628 "Amount to debit peers rwnd per chunk sent");
630 SYSCTL_INT(_net_inet_sctp
, OID_AUTO
, maxburst
, CTLFLAG_RW
,
631 &sctp_max_burst_default
, 0,
632 "Default max burst for sctp endpoints");
634 SYSCTL_INT(_net_inet_sctp
, OID_AUTO
, maxchunks
, CTLFLAG_RW
,
635 &sctp_max_chunks_on_queue
, 0,
636 "Default max chunks on queue per asoc");
638 SYSCTL_UINT(_net_inet_sctp
, OID_AUTO
, delayed_sack_time
, CTLFLAG_RW
,
639 &sctp_delayed_sack_time_default
, 0,
640 "Default delayed SACK timer in msec");
642 SYSCTL_UINT(_net_inet_sctp
, OID_AUTO
, heartbeat_interval
, CTLFLAG_RW
,
643 &sctp_heartbeat_interval_default
, 0,
644 "Default heartbeat interval in msec");
646 SYSCTL_UINT(_net_inet_sctp
, OID_AUTO
, pmtu_raise_time
, CTLFLAG_RW
,
647 &sctp_pmtu_raise_time_default
, 0,
648 "Default PMTU raise timer in sec");
650 SYSCTL_UINT(_net_inet_sctp
, OID_AUTO
, shutdown_guard_time
, CTLFLAG_RW
,
651 &sctp_shutdown_guard_time_default
, 0,
652 "Default shutdown guard timer in sec");
654 SYSCTL_UINT(_net_inet_sctp
, OID_AUTO
, secret_lifetime
, CTLFLAG_RW
,
655 &sctp_secret_lifetime_default
, 0,
656 "Default secret lifetime in sec");
658 SYSCTL_UINT(_net_inet_sctp
, OID_AUTO
, rto_max
, CTLFLAG_RW
,
659 &sctp_rto_max_default
, 0,
660 "Default maximum retransmission timeout in msec");
662 SYSCTL_UINT(_net_inet_sctp
, OID_AUTO
, rto_min
, CTLFLAG_RW
,
663 &sctp_rto_min_default
, 0,
664 "Default minimum retransmission timeout in msec");
666 SYSCTL_UINT(_net_inet_sctp
, OID_AUTO
, rto_initial
, CTLFLAG_RW
,
667 &sctp_rto_initial_default
, 0,
668 "Default initial retransmission timeout in msec");
670 SYSCTL_UINT(_net_inet_sctp
, OID_AUTO
, init_rto_max
, CTLFLAG_RW
,
671 &sctp_init_rto_max_default
, 0,
672 "Default maximum retransmission timeout during association setup in msec");
674 SYSCTL_UINT(_net_inet_sctp
, OID_AUTO
, valid_cookie_life
, CTLFLAG_RW
,
675 &sctp_valid_cookie_life_default
, 0,
676 "Default cookie lifetime in sec");
678 SYSCTL_UINT(_net_inet_sctp
, OID_AUTO
, init_rtx_max
, CTLFLAG_RW
,
679 &sctp_init_rtx_max_default
, 0,
680 "Default maximum number of retransmission for INIT chunks");
682 SYSCTL_UINT(_net_inet_sctp
, OID_AUTO
, assoc_rtx_max
, CTLFLAG_RW
,
683 &sctp_assoc_rtx_max_default
, 0,
684 "Default maximum number of retransmissions per association");
686 SYSCTL_UINT(_net_inet_sctp
, OID_AUTO
, path_rtx_max
, CTLFLAG_RW
,
687 &sctp_path_rtx_max_default
, 0,
688 "Default maximum of retransmissions per path");
690 SYSCTL_UINT(_net_inet_sctp
, OID_AUTO
, nr_outgoing_streams
, CTLFLAG_RW
,
691 &sctp_nr_outgoing_streams_default
, 0,
692 "Default number of outgoing streams");
695 SYSCTL_INT(_net_inet_sctp
, OID_AUTO
, debug
, CTLFLAG_RW
,
696 &sctp_debug_on
, 0, "Configure debug output");
697 #endif /* SCTP_DEBUG */
701 sctp_abort(struct socket
*so
)
703 struct sctp_inpcb
*inp
;
705 inp
= (struct sctp_inpcb
*)so
->so_pcb
;
707 return EINVAL
; /* ??? possible? panic instead? */
710 sctp_inpcb_free(inp
, 1);
716 #if defined(__FreeBSD__) && __FreeBSD_version >= 500000
717 sctp_attach(struct socket
*so
, int proto
, struct thread
*p
)
718 #elif defined(__DragonFly__)
719 sctp_attach(struct socket
*so
, int proto
, struct pru_attach_info
*ai
)
721 sctp_attach(struct socket
*so
, int proto
, struct proc
*p
)
724 struct sctp_inpcb
*inp
;
725 struct inpcb
*ip_inp
;
729 inp
= (struct sctp_inpcb
*)so
->so_pcb
;
734 error
= soreserve(so
, sctp_sendspace
, sctp_recvspace
, NULL
);
739 error
= sctp_inpcb_alloc(so
);
744 inp
= (struct sctp_inpcb
*)so
->so_pcb
;
747 inp
->sctp_flags
&= ~SCTP_PCB_FLAGS_BOUND_V6
; /* I'm not v6! */
748 ip_inp
= &inp
->ip_inp
.inp
;
749 #if defined(__FreeBSD__) || defined(__APPLE__) || defined(__DragonFly__)
750 ip_inp
->inp_vflag
|= INP_IPV4
;
751 ip_inp
->inp_ip_ttl
= ip_defttl
;
753 inp
->inp_vflag
|= INP_IPV4
;
754 inp
->inp_ip_ttl
= ip_defttl
;
758 #if !(defined(__OpenBSD__) || defined(__APPLE__))
759 error
= ipsec_init_policy(so
, &ip_inp
->inp_sp
);
761 sctp_inpcb_free(inp
, 1);
766 SCTP_INP_WUNLOCK(inp
);
767 #if defined(__NetBSD__)
768 so
->so_send
= sctp_sosend
;
775 #if (defined(__FreeBSD__) && __FreeBSD_version >= 500000) || defined(__DragonFly__)
776 sctp_bind(struct socket
*so
, struct sockaddr
*addr
, struct thread
*p
)
778 #elif defined(__FreeBSD__) || defined(__APPLE__)
779 sctp_bind(struct socket
*so
, struct sockaddr
*addr
, struct proc
*p
)
782 sctp_bind(struct socket
*so
, struct mbuf
*nam
, struct proc
*p
)
784 struct sockaddr
*addr
= nam
? mtod(nam
, struct sockaddr
*) : NULL
;
786 struct sctp_inpcb
*inp
;
790 if (addr
&& addr
->sa_family
!= AF_INET
)
791 /* must be a v4 address! */
795 inp
= (struct sctp_inpcb
*)so
->so_pcb
;
800 error
= sctp_inpcb_bind(so
, addr
, p
);
807 sctp_detach(struct socket
*so
)
809 struct sctp_inpcb
*inp
;
811 inp
= (struct sctp_inpcb
*)so
->so_pcb
;
815 if (((so
->so_options
& SO_LINGER
) && (so
->so_linger
== 0)) ||
816 (so
->so_rcv
.ssb_cc
> 0)) {
817 sctp_inpcb_free(inp
, 1);
819 sctp_inpcb_free(inp
, 0);
826 #if (defined(__FreeBSD__) && __FreeBSD_version >= 500000) || defined(__DragonFly__)
827 sctp_send(struct socket
*so
, int flags
, struct mbuf
*m
, struct sockaddr
*addr
,
828 struct mbuf
*control
, struct thread
*p
);
830 sctp_send(struct socket
*so
, int flags
, struct mbuf
*m
, struct sockaddr
*addr
,
831 struct mbuf
*control
, struct proc
*p
);
835 #if (defined(__FreeBSD__) && __FreeBSD_version >= 500000) || defined(__DragonFly__)
836 sctp_send(struct socket
*so
, int flags
, struct mbuf
*m
, struct sockaddr
*addr
,
837 struct mbuf
*control
, struct thread
*p
)
840 sctp_send(struct socket
*so
, int flags
, struct mbuf
*m
, struct sockaddr
*addr
,
841 struct mbuf
*control
, struct proc
*p
)
844 struct sctp_inpcb
*inp
;
846 inp
= (struct sctp_inpcb
*)so
->so_pcb
;
849 sctp_m_freem(control
);
855 /* Got to have an to address if we are NOT a connected socket */
856 if ((addr
== NULL
) &&
857 ((inp
->sctp_flags
& SCTP_PCB_FLAGS_CONNECTED
) ||
858 (inp
->sctp_flags
& SCTP_PCB_FLAGS_TCPTYPE
))
861 } else if (addr
== NULL
) {
862 error
= EDESTADDRREQ
;
865 sctp_m_freem(control
);
871 if (addr
->sa_family
!= AF_INET
) {
872 /* must be a v4 address! */
875 sctp_m_freem(control
);
878 error
= EDESTADDRREQ
;
883 /* now what about control */
886 kprintf("huh? control set?\n");
887 sctp_m_freem(inp
->control
);
890 inp
->control
= control
;
892 /* add it in possibly */
893 if ((inp
->pkt
) && (inp
->pkt
->m_flags
& M_PKTHDR
)) {
899 for (x
=m
;x
;x
= x
->m_next
) {
902 inp
->pkt
->m_pkthdr
.len
+= c_len
;
906 inp
->pkt_last
->m_next
= m
;
909 inp
->pkt_last
= inp
->pkt
= m
;
912 #if defined (__FreeBSD__) || defined(__APPLE__) || defined(__DragonFly__)
913 /* FreeBSD uses a flag passed */
914 ((flags
& PRUS_MORETOCOME
) == 0)
915 #elif defined( __NetBSD__)
916 /* NetBSD uses the so_state field */
917 ((so
->so_state
& SS_MORETOCOME
) == 0)
919 1 /* Open BSD does not have any "more to come" indication */
923 * note with the current version this code will only be used
924 * by OpenBSD-- NetBSD, FreeBSD, and MacOS have methods for
925 * re-defining sosend to use the sctp_sosend. One can
926 * optionally switch back to this code (by changing back the
927 * definitions) but this is not advisable.
930 ret
= sctp_output(inp
, inp
->pkt
, addr
, inp
->control
, p
, flags
);
940 sctp_disconnect(struct socket
*so
)
942 struct sctp_inpcb
*inp
;
945 inp
= (struct sctp_inpcb
*)so
->so_pcb
;
951 if (inp
->sctp_flags
& SCTP_PCB_FLAGS_TCPTYPE
) {
952 if (LIST_EMPTY(&inp
->sctp_asoc_list
)) {
955 SCTP_INP_RUNLOCK(inp
);
958 int some_on_streamwheel
= 0;
959 struct sctp_association
*asoc
;
960 struct sctp_tcb
*stcb
;
962 stcb
= LIST_FIRST(&inp
->sctp_asoc_list
);
965 SCTP_INP_RUNLOCK(inp
);
970 if (((so
->so_options
& SO_LINGER
) &&
971 (so
->so_linger
== 0)) ||
972 (so
->so_rcv
.ssb_cc
> 0)) {
973 if (SCTP_GET_STATE(asoc
) !=
974 SCTP_STATE_COOKIE_WAIT
) {
975 /* Left with Data unread */
978 MGET(err
, MB_DONTWAIT
, MT_DATA
);
980 /* Fill in the user initiated abort */
981 struct sctp_paramhdr
*ph
;
982 ph
= mtod(err
, struct sctp_paramhdr
*);
983 err
->m_len
= sizeof(struct sctp_paramhdr
);
984 ph
->param_type
= htons(SCTP_CAUSE_USER_INITIATED_ABT
);
985 ph
->param_length
= htons(err
->m_len
);
987 sctp_send_abort_tcb(stcb
, err
);
989 SCTP_INP_RUNLOCK(inp
);
990 sctp_free_assoc(inp
, stcb
);
991 /* No unlock tcb assoc is gone */
995 if (!TAILQ_EMPTY(&asoc
->out_wheel
)) {
996 /* Check to see if some data queued */
997 struct sctp_stream_out
*outs
;
998 TAILQ_FOREACH(outs
, &asoc
->out_wheel
,
1000 if (!TAILQ_EMPTY(&outs
->outqueue
)) {
1001 some_on_streamwheel
= 1;
1007 if (TAILQ_EMPTY(&asoc
->send_queue
) &&
1008 TAILQ_EMPTY(&asoc
->sent_queue
) &&
1009 (some_on_streamwheel
== 0)) {
1010 /* there is nothing queued to send, so done */
1011 if ((SCTP_GET_STATE(asoc
) !=
1012 SCTP_STATE_SHUTDOWN_SENT
) &&
1013 (SCTP_GET_STATE(asoc
) !=
1014 SCTP_STATE_SHUTDOWN_ACK_SENT
)) {
1015 /* only send SHUTDOWN 1st time thru */
1017 if (sctp_debug_on
& SCTP_DEBUG_OUTPUT4
) {
1018 kprintf("%s:%d sends a shutdown\n",
1024 sctp_send_shutdown(stcb
,
1025 stcb
->asoc
.primary_destination
);
1026 sctp_chunk_output(stcb
->sctp_ep
, stcb
, 1);
1027 asoc
->state
= SCTP_STATE_SHUTDOWN_SENT
;
1028 sctp_timer_start(SCTP_TIMER_TYPE_SHUTDOWN
,
1029 stcb
->sctp_ep
, stcb
,
1030 asoc
->primary_destination
);
1031 sctp_timer_start(SCTP_TIMER_TYPE_SHUTDOWNGUARD
,
1032 stcb
->sctp_ep
, stcb
,
1033 asoc
->primary_destination
);
1037 * we still got (or just got) data to send,
1038 * so set SHUTDOWN_PENDING
1041 * XXX sockets draft says that MSG_EOF should
1042 * be sent with no data.
1043 * currently, we will allow user data to be
1044 * sent first and move to SHUTDOWN-PENDING
1046 asoc
->state
|= SCTP_STATE_SHUTDOWN_PENDING
;
1048 SCTP_TCB_UNLOCK(stcb
);
1049 SCTP_INP_RUNLOCK(inp
);
1055 /* UDP model does not support this */
1056 SCTP_INP_RUNLOCK(inp
);
1063 sctp_shutdown(struct socket
*so
)
1065 struct sctp_inpcb
*inp
;
1068 inp
= (struct sctp_inpcb
*)so
->so_pcb
;
1073 SCTP_INP_RLOCK(inp
);
1074 /* For UDP model this is a invalid call */
1075 if (inp
->sctp_flags
& SCTP_PCB_FLAGS_UDPTYPE
) {
1076 /* Restore the flags that the soshutdown took away. */
1077 #if defined(__FreeBSD__) && __FreeBSD_version >= 502115
1078 so
->so_rcv
.sb_state
&= ~SBS_CANTRCVMORE
;
1080 so
->so_state
&= ~SS_CANTRCVMORE
;
1082 /* This proc will wakeup for read and do nothing (I hope) */
1084 SCTP_INP_RUNLOCK(inp
);
1085 return (EOPNOTSUPP
);
1088 * Ok if we reach here its the TCP model and it is either a SHUT_WR
1089 * or SHUT_RDWR. This means we put the shutdown flag against it.
1092 int some_on_streamwheel
= 0;
1093 struct sctp_tcb
*stcb
;
1094 struct sctp_association
*asoc
;
1097 stcb
= LIST_FIRST(&inp
->sctp_asoc_list
);
1100 * Ok we hit the case that the shutdown call was made
1101 * after an abort or something. Nothing to do now.
1106 SCTP_TCB_LOCK(stcb
);
1109 if (!TAILQ_EMPTY(&asoc
->out_wheel
)) {
1110 /* Check to see if some data queued */
1111 struct sctp_stream_out
*outs
;
1112 TAILQ_FOREACH(outs
, &asoc
->out_wheel
, next_spoke
) {
1113 if (!TAILQ_EMPTY(&outs
->outqueue
)) {
1114 some_on_streamwheel
= 1;
1119 if (TAILQ_EMPTY(&asoc
->send_queue
) &&
1120 TAILQ_EMPTY(&asoc
->sent_queue
) &&
1121 (some_on_streamwheel
== 0)) {
1122 /* there is nothing queued to send, so I'm done... */
1123 if (SCTP_GET_STATE(asoc
) != SCTP_STATE_SHUTDOWN_SENT
) {
1124 /* only send SHUTDOWN the first time through */
1126 if (sctp_debug_on
& SCTP_DEBUG_OUTPUT4
) {
1127 kprintf("%s:%d sends a shutdown\n",
1133 sctp_send_shutdown(stcb
,
1134 stcb
->asoc
.primary_destination
);
1135 sctp_chunk_output(stcb
->sctp_ep
, stcb
, 1);
1136 asoc
->state
= SCTP_STATE_SHUTDOWN_SENT
;
1137 sctp_timer_start(SCTP_TIMER_TYPE_SHUTDOWN
,
1138 stcb
->sctp_ep
, stcb
,
1139 asoc
->primary_destination
);
1140 sctp_timer_start(SCTP_TIMER_TYPE_SHUTDOWNGUARD
,
1141 stcb
->sctp_ep
, stcb
,
1142 asoc
->primary_destination
);
1146 * we still got (or just got) data to send, so
1147 * set SHUTDOWN_PENDING
1149 asoc
->state
|= SCTP_STATE_SHUTDOWN_PENDING
;
1151 SCTP_TCB_UNLOCK(stcb
);
1153 SCTP_INP_RUNLOCK(inp
);
1159 * copies a "user" presentable address and removes embedded scope, etc.
1160 * returns 0 on success, 1 on error
1163 sctp_fill_user_address(struct sockaddr_storage
*ss
, struct sockaddr
*sa
)
1165 struct sockaddr_in6 lsa6
;
1166 sa
= (struct sockaddr
*)sctp_recover_scope((struct sockaddr_in6
*)sa
,
1168 memcpy(ss
, sa
, sa
->sa_len
);
1173 #if defined(__NetBSD__) || defined(__OpenBSD__)
1175 * On NetBSD and OpenBSD in6_sin_2_v4mapsin6() not used and not exported,
1176 * so we have to export it here.
1178 void in6_sin_2_v4mapsin6(struct sockaddr_in
*sin
, struct sockaddr_in6
*sin6
);
1182 sctp_fill_up_addresses(struct sctp_inpcb
*inp
,
1183 struct sctp_tcb
*stcb
,
1185 struct sockaddr_storage
*sas
)
1188 int loopback_scope
, ipv4_local_scope
, local_scope
, site_scope
, actual
;
1189 int ipv4_addr_legal
, ipv6_addr_legal
;
1195 /* Turn on all the appropriate scope */
1196 loopback_scope
= stcb
->asoc
.loopback_scope
;
1197 ipv4_local_scope
= stcb
->asoc
.ipv4_local_scope
;
1198 local_scope
= stcb
->asoc
.local_scope
;
1199 site_scope
= stcb
->asoc
.site_scope
;
1201 /* Turn on ALL scope, since we look at the EP */
1202 loopback_scope
= ipv4_local_scope
= local_scope
=
1205 ipv4_addr_legal
= ipv6_addr_legal
= 0;
1206 if (inp
->sctp_flags
& SCTP_PCB_FLAGS_BOUND_V6
) {
1207 ipv6_addr_legal
= 1;
1209 #if defined(__OpenBSD__)
1210 (0) /* we always do dual bind */
1211 #elif defined (__NetBSD__)
1212 (((struct in6pcb
*)inp
)->in6p_flags
& IN6P_IPV6_V6ONLY
)
1214 (((struct in6pcb
*)inp
)->inp_flags
& IN6P_IPV6_V6ONLY
)
1217 ipv4_addr_legal
= 1;
1220 ipv4_addr_legal
= 1;
1223 if (inp
->sctp_flags
& SCTP_PCB_FLAGS_BOUNDALL
) {
1224 TAILQ_FOREACH(ifn
, &ifnet
, if_list
) {
1225 struct ifaddr_container
*ifac
;
1227 if ((loopback_scope
== 0) &&
1228 (ifn
->if_type
== IFT_LOOP
)) {
1229 /* Skip loopback if loopback_scope not set */
1232 TAILQ_FOREACH(ifac
, &ifn
->if_addrheads
[mycpuid
],
1234 struct ifaddr
*ifa
= ifac
->ifa
;
1238 * For the BOUND-ALL case, the list
1239 * associated with a TCB is Always
1240 * considered a reverse list.. i.e.
1241 * it lists addresses that are NOT
1242 * part of the association. If this
1243 * is one of those we must skip it.
1245 if (sctp_is_addr_restricted(stcb
,
1250 if ((ifa
->ifa_addr
->sa_family
== AF_INET
) &&
1251 (ipv4_addr_legal
)) {
1252 struct sockaddr_in
*sin
;
1253 sin
= (struct sockaddr_in
*)ifa
->ifa_addr
;
1254 if (sin
->sin_addr
.s_addr
== 0) {
1255 /* we skip unspecifed addresses */
1258 if ((ipv4_local_scope
== 0) &&
1259 (IN4_ISPRIVATE_ADDRESS(&sin
->sin_addr
))) {
1262 if (inp
->sctp_flags
& SCTP_PCB_FLAGS_NEEDS_MAPPED_V4
) {
1263 in6_sin_2_v4mapsin6(sin
, (struct sockaddr_in6
*)sas
);
1264 ((struct sockaddr_in6
*)sas
)->sin6_port
= inp
->sctp_lport
;
1265 sas
= (struct sockaddr_storage
*)((caddr_t
)sas
+ sizeof(struct sockaddr_in6
));
1266 actual
+= sizeof(sizeof(struct sockaddr_in6
));
1268 memcpy(sas
, sin
, sizeof(*sin
));
1269 ((struct sockaddr_in
*)sas
)->sin_port
= inp
->sctp_lport
;
1270 sas
= (struct sockaddr_storage
*)((caddr_t
)sas
+ sizeof(*sin
));
1271 actual
+= sizeof(*sin
);
1273 if (actual
>= limit
) {
1276 } else if ((ifa
->ifa_addr
->sa_family
== AF_INET6
) &&
1277 (ipv6_addr_legal
)) {
1278 struct sockaddr_in6
*sin6
, lsa6
;
1279 sin6
= (struct sockaddr_in6
*)ifa
->ifa_addr
;
1280 if (IN6_IS_ADDR_UNSPECIFIED(&sin6
->sin6_addr
)) {
1281 /* we skip unspecifed addresses */
1284 if (IN6_IS_ADDR_LINKLOCAL(&sin6
->sin6_addr
)) {
1285 if (local_scope
== 0)
1287 if (sin6
->sin6_scope_id
== 0) {
1289 if (in6_recoverscope(&lsa6
,
1292 /* bad link local address */
1297 if ((site_scope
== 0) &&
1298 (IN6_IS_ADDR_SITELOCAL(&sin6
->sin6_addr
))) {
1301 memcpy(sas
, sin6
, sizeof(*sin6
));
1302 ((struct sockaddr_in6
*)sas
)->sin6_port
= inp
->sctp_lport
;
1303 sas
= (struct sockaddr_storage
*)((caddr_t
)sas
+ sizeof(*sin6
));
1304 actual
+= sizeof(*sin6
);
1305 if (actual
>= limit
) {
1312 struct sctp_laddr
*laddr
;
1314 * If we have a TCB and we do NOT support ASCONF (it's
1315 * turned off or otherwise) then the list is always the
1316 * true list of addresses (the else case below). Otherwise
1317 * the list on the association is a list of addresses that
1318 * are NOT part of the association.
1320 if (inp
->sctp_flags
& SCTP_PCB_FLAGS_DO_ASCONF
) {
1321 /* The list is a NEGATIVE list */
1322 LIST_FOREACH(laddr
, &inp
->sctp_addr_list
, sctp_nxt_addr
) {
1324 if (sctp_is_addr_restricted(stcb
, laddr
->ifa
->ifa_addr
)) {
1328 if (sctp_fill_user_address(sas
, laddr
->ifa
->ifa_addr
))
1331 ((struct sockaddr_in6
*)sas
)->sin6_port
= inp
->sctp_lport
;
1332 sas
= (struct sockaddr_storage
*)((caddr_t
)sas
+
1333 laddr
->ifa
->ifa_addr
->sa_len
);
1334 actual
+= laddr
->ifa
->ifa_addr
->sa_len
;
1335 if (actual
>= limit
) {
1340 /* The list is a positive list if present */
1342 /* Must use the specific association list */
1343 LIST_FOREACH(laddr
, &stcb
->asoc
.sctp_local_addr_list
,
1345 if (sctp_fill_user_address(sas
,
1346 laddr
->ifa
->ifa_addr
))
1348 ((struct sockaddr_in6
*)sas
)->sin6_port
= inp
->sctp_lport
;
1349 sas
= (struct sockaddr_storage
*)((caddr_t
)sas
+
1350 laddr
->ifa
->ifa_addr
->sa_len
);
1351 actual
+= laddr
->ifa
->ifa_addr
->sa_len
;
1352 if (actual
>= limit
) {
1357 /* No endpoint so use the endpoints individual list */
1358 LIST_FOREACH(laddr
, &inp
->sctp_addr_list
,
1360 if (sctp_fill_user_address(sas
,
1361 laddr
->ifa
->ifa_addr
))
1363 ((struct sockaddr_in6
*)sas
)->sin6_port
= inp
->sctp_lport
;
1364 sas
= (struct sockaddr_storage
*)((caddr_t
)sas
+
1365 laddr
->ifa
->ifa_addr
->sa_len
);
1366 actual
+= laddr
->ifa
->ifa_addr
->sa_len
;
1367 if (actual
>= limit
) {
1378 sctp_count_max_addresses(struct sctp_inpcb
*inp
)
1382 * In both sub-set bound an bound_all cases we return the MAXIMUM
1383 * number of addresses that you COULD get. In reality the sub-set
1384 * bound may have an exclusion list for a given TCB OR in the
1385 * bound-all case a TCB may NOT include the loopback or other
1386 * addresses as well.
1388 if (inp
->sctp_flags
& SCTP_PCB_FLAGS_BOUNDALL
) {
1391 TAILQ_FOREACH(ifn
, &ifnet
, if_list
) {
1392 struct ifaddr_container
*ifac
;
1394 TAILQ_FOREACH(ifac
, &ifn
->if_addrheads
[mycpuid
], ifa_link
) {
1395 struct ifaddr
*ifa
= ifac
->ifa
;
1397 /* Count them if they are the right type */
1398 if (ifa
->ifa_addr
->sa_family
== AF_INET
) {
1399 if (inp
->sctp_flags
& SCTP_PCB_FLAGS_NEEDS_MAPPED_V4
)
1400 cnt
+= sizeof(struct sockaddr_in6
);
1402 cnt
+= sizeof(struct sockaddr_in
);
1404 } else if (ifa
->ifa_addr
->sa_family
== AF_INET6
)
1405 cnt
+= sizeof(struct sockaddr_in6
);
1409 struct sctp_laddr
*laddr
;
1410 LIST_FOREACH(laddr
, &inp
->sctp_addr_list
, sctp_nxt_addr
) {
1411 if (laddr
->ifa
->ifa_addr
->sa_family
== AF_INET
) {
1412 if (inp
->sctp_flags
& SCTP_PCB_FLAGS_NEEDS_MAPPED_V4
)
1413 cnt
+= sizeof(struct sockaddr_in6
);
1415 cnt
+= sizeof(struct sockaddr_in
);
1417 } else if (laddr
->ifa
->ifa_addr
->sa_family
== AF_INET6
)
1418 cnt
+= sizeof(struct sockaddr_in6
);
1425 sctp_do_connect_x(struct socket
*so
,
1426 struct sctp_inpcb
*inp
,
1428 #if (defined(__FreeBSD__) && __FreeBSD_version >= 500000) || defined(__DragonFly__)
1437 struct sctp_tcb
*stcb
= NULL
;
1438 struct sockaddr
*sa
;
1439 int num_v6
=0, num_v4
=0, *totaddrp
, totaddr
, i
, incr
, at
;
1441 if (sctp_debug_on
& SCTP_DEBUG_PCB1
) {
1442 kprintf("Connectx called\n");
1444 #endif /* SCTP_DEBUG */
1447 if ((inp
->sctp_flags
& SCTP_PCB_FLAGS_TCPTYPE
) &&
1448 (inp
->sctp_flags
& SCTP_PCB_FLAGS_CONNECTED
)) {
1449 /* We are already connected AND the TCP model */
1451 return (EADDRINUSE
);
1453 if (inp
->sctp_flags
& SCTP_PCB_FLAGS_CONNECTED
) {
1454 SCTP_INP_RLOCK(inp
);
1455 stcb
= LIST_FIRST(&inp
->sctp_asoc_list
);
1456 SCTP_INP_RUNLOCK(inp
);
1463 SCTP_ASOC_CREATE_LOCK(inp
);
1464 if ((inp
->sctp_flags
& SCTP_PCB_FLAGS_SOCKET_GONE
) ||
1465 (inp
->sctp_flags
& SCTP_PCB_FLAGS_SOCKET_GONE
)) {
1466 SCTP_ASOC_CREATE_UNLOCK(inp
);
1471 totaddrp
= mtod(m
, int *);
1472 totaddr
= *totaddrp
;
1473 sa
= (struct sockaddr
*)(totaddrp
+ 1);
1475 /* account and validate addresses */
1476 SCTP_INP_WLOCK(inp
);
1477 SCTP_INP_INCR_REF(inp
);
1478 SCTP_INP_WUNLOCK(inp
);
1479 for (i
= 0; i
< totaddr
; i
++) {
1480 if (sa
->sa_family
== AF_INET
) {
1482 incr
= sizeof(struct sockaddr_in
);
1483 } else if (sa
->sa_family
== AF_INET6
) {
1484 struct sockaddr_in6
*sin6
;
1485 sin6
= (struct sockaddr_in6
*)sa
;
1486 if (IN6_IS_ADDR_V4MAPPED(&sin6
->sin6_addr
)) {
1487 /* Must be non-mapped for connectx */
1488 SCTP_ASOC_CREATE_UNLOCK(inp
);
1493 incr
= sizeof(struct sockaddr_in6
);
1498 stcb
= sctp_findassociation_ep_addr(&inp
, sa
, NULL
, NULL
, NULL
);
1500 /* Already have or am bring up an association */
1501 SCTP_ASOC_CREATE_UNLOCK(inp
);
1502 SCTP_TCB_UNLOCK(stcb
);
1506 if ((at
+ incr
) > m
->m_len
) {
1510 sa
= (struct sockaddr
*)((caddr_t
)sa
+ incr
);
1512 sa
= (struct sockaddr
*)(totaddrp
+ 1);
1513 SCTP_INP_WLOCK(inp
);
1514 SCTP_INP_DECR_REF(inp
);
1515 SCTP_INP_WUNLOCK(inp
);
1517 if (((inp
->sctp_flags
& SCTP_PCB_FLAGS_BOUND_V6
) == 0) &&
1520 SCTP_INP_WUNLOCK(inp
);
1521 SCTP_ASOC_CREATE_UNLOCK(inp
);
1524 if ((inp
->sctp_flags
& SCTP_PCB_FLAGS_BOUND_V6
) &&
1526 struct in6pcb
*inp6
;
1527 inp6
= (struct in6pcb
*)inp
;
1529 #if defined(__OpenBSD__)
1530 (0) /* we always do dual bind */
1531 #elif defined (__NetBSD__)
1532 (inp6
->in6p_flags
& IN6P_IPV6_V6ONLY
)
1534 (inp6
->inp_flags
& IN6P_IPV6_V6ONLY
)
1538 * if IPV6_V6ONLY flag, ignore connections
1539 * destined to a v4 addr or v4-mapped addr
1541 SCTP_INP_WUNLOCK(inp
);
1542 SCTP_ASOC_CREATE_UNLOCK(inp
);
1548 if ((inp
->sctp_flags
& SCTP_PCB_FLAGS_UNBOUND
) ==
1549 SCTP_PCB_FLAGS_UNBOUND
) {
1550 /* Bind a ephemeral port */
1551 SCTP_INP_WUNLOCK(inp
);
1552 error
= sctp_inpcb_bind(so
, NULL
, p
);
1554 SCTP_ASOC_CREATE_UNLOCK(inp
);
1559 SCTP_INP_WUNLOCK(inp
);
1561 /* We are GOOD to go */
1562 stcb
= sctp_aloc_assoc(inp
, sa
, 1, &error
, 0);
1564 /* Gak! no memory */
1565 SCTP_ASOC_CREATE_UNLOCK(inp
);
1569 /* move to second address */
1570 if (sa
->sa_family
== AF_INET
)
1571 sa
= (struct sockaddr
*)((caddr_t
)sa
+ sizeof(struct sockaddr_in
));
1573 sa
= (struct sockaddr
*)((caddr_t
)sa
+ sizeof(struct sockaddr_in6
));
1575 for (i
= 1; i
< totaddr
; i
++) {
1576 if (sa
->sa_family
== AF_INET
) {
1577 incr
= sizeof(struct sockaddr_in
);
1578 if (sctp_add_remote_addr(stcb
, sa
, 0, 8)) {
1579 /* assoc gone no un-lock */
1580 sctp_free_assoc(inp
, stcb
);
1581 SCTP_ASOC_CREATE_UNLOCK(inp
);
1586 } else if (sa
->sa_family
== AF_INET6
) {
1587 incr
= sizeof(struct sockaddr_in6
);
1588 if (sctp_add_remote_addr(stcb
, sa
, 0, 8)) {
1589 /* assoc gone no un-lock */
1590 sctp_free_assoc(inp
, stcb
);
1591 SCTP_ASOC_CREATE_UNLOCK(inp
);
1596 sa
= (struct sockaddr
*)((caddr_t
)sa
+ incr
);
1598 stcb
->asoc
.state
= SCTP_STATE_COOKIE_WAIT
;
1600 /* doing delayed connection */
1601 stcb
->asoc
.delayed_connection
= 1;
1602 sctp_timer_start(SCTP_TIMER_TYPE_INIT
, inp
, stcb
, stcb
->asoc
.primary_destination
);
1604 SCTP_GETTIME_TIMEVAL(&stcb
->asoc
.time_entered
);
1605 sctp_send_initiate(inp
, stcb
);
1607 SCTP_TCB_UNLOCK(stcb
);
1608 if (stcb
->sctp_ep
->sctp_flags
& SCTP_PCB_FLAGS_TCPTYPE
) {
1609 stcb
->sctp_ep
->sctp_flags
|= SCTP_PCB_FLAGS_CONNECTED
;
1610 /* Set the connected flag so we can queue data */
1613 SCTP_ASOC_CREATE_UNLOCK(inp
);
1620 sctp_optsget(struct socket
*so
,
1623 #if (defined(__FreeBSD__) && __FreeBSD_version >= 500000) || defined(__DragonFly__)
1630 struct sctp_inpcb
*inp
;
1632 int error
, optval
=0;
1633 struct sctp_tcb
*stcb
= NULL
;
1635 inp
= (struct sctp_inpcb
*)so
->so_pcb
;
1642 if (sctp_debug_on
& SCTP_DEBUG_USRREQ1
) {
1643 kprintf("optsget:MP is NULL EINVAL\n");
1645 #endif /* SCTP_DEBUG */
1650 /* Got to have a mbuf */
1652 if (sctp_debug_on
& SCTP_DEBUG_USRREQ1
) {
1653 kprintf("Huh no mbuf\n");
1655 #endif /* SCTP_DEBUG */
1659 if (sctp_debug_on
& SCTP_DEBUG_USRREQ2
) {
1660 kprintf("optsget opt:%lxx sz:%u\n", (unsigned long)opt
,
1663 #endif /* SCTP_DEBUG */
1667 case SCTP_AUTOCLOSE
:
1668 case SCTP_AUTO_ASCONF
:
1669 case SCTP_DISABLE_FRAGMENTS
:
1670 case SCTP_I_WANT_MAPPED_V4_ADDR
:
1672 if (sctp_debug_on
& SCTP_DEBUG_USRREQ2
) {
1673 kprintf("other stuff\n");
1675 #endif /* SCTP_DEBUG */
1676 SCTP_INP_RLOCK(inp
);
1678 case SCTP_DISABLE_FRAGMENTS
:
1679 optval
= inp
->sctp_flags
& SCTP_PCB_FLAGS_NO_FRAGMENT
;
1681 case SCTP_I_WANT_MAPPED_V4_ADDR
:
1682 optval
= inp
->sctp_flags
& SCTP_PCB_FLAGS_NEEDS_MAPPED_V4
;
1684 case SCTP_AUTO_ASCONF
:
1685 optval
= inp
->sctp_flags
& SCTP_PCB_FLAGS_AUTO_ASCONF
;
1688 optval
= inp
->sctp_flags
& SCTP_PCB_FLAGS_NODELAY
;
1690 case SCTP_AUTOCLOSE
:
1691 if ((inp
->sctp_flags
& SCTP_PCB_FLAGS_AUTOCLOSE
) ==
1692 SCTP_PCB_FLAGS_AUTOCLOSE
)
1693 optval
= inp
->sctp_ep
.auto_close_time
;
1699 error
= ENOPROTOOPT
;
1700 } /* end switch (sopt->sopt_name) */
1701 if (opt
!= SCTP_AUTOCLOSE
) {
1702 /* make it an "on/off" value */
1703 optval
= (optval
!= 0);
1705 if ((size_t)m
->m_len
< sizeof(int)) {
1708 SCTP_INP_RUNLOCK(inp
);
1710 /* return the option value */
1711 *mtod(m
, int *) = optval
;
1712 m
->m_len
= sizeof(optval
);
1715 case SCTP_GET_ASOC_ID_LIST
:
1717 struct sctp_assoc_ids
*ids
;
1721 if ((size_t)m
->m_len
< sizeof(struct sctp_assoc_ids
)) {
1725 ids
= mtod(m
, struct sctp_assoc_ids
*);
1727 SCTP_INP_RLOCK(inp
);
1728 stcb
= LIST_FIRST(&inp
->sctp_asoc_list
);
1731 ids
->asls_numb_present
= 0;
1732 ids
->asls_more_to_get
= 0;
1733 SCTP_INP_RUNLOCK(inp
);
1736 orig
= ids
->asls_assoc_start
;
1737 stcb
= LIST_FIRST(&inp
->sctp_asoc_list
);
1739 stcb
= LIST_NEXT(stcb
, sctp_tcblist
);
1747 ids
->asls_numb_present
= 0;
1748 ids
->asls_more_to_get
= 1;
1749 while(at
< MAX_ASOC_IDS_RET
) {
1750 ids
->asls_assoc_id
[at
] = sctp_get_associd(stcb
);
1752 ids
->asls_numb_present
++;
1753 stcb
= LIST_NEXT(stcb
, sctp_tcblist
);
1755 ids
->asls_more_to_get
= 0;
1759 SCTP_INP_RUNLOCK(inp
);
1762 case SCTP_GET_NONCE_VALUES
:
1764 struct sctp_get_nonce_values
*gnv
;
1765 if ((size_t)m
->m_len
< sizeof(struct sctp_get_nonce_values
)) {
1769 gnv
= mtod(m
, struct sctp_get_nonce_values
*);
1770 stcb
= sctp_findassociation_ep_asocid(inp
, gnv
->gn_assoc_id
);
1774 gnv
->gn_peers_tag
= stcb
->asoc
.peer_vtag
;
1775 gnv
->gn_local_tag
= stcb
->asoc
.my_vtag
;
1776 SCTP_TCB_UNLOCK(stcb
);
1781 case SCTP_PEER_PUBLIC_KEY
:
1782 case SCTP_MY_PUBLIC_KEY
:
1783 case SCTP_SET_AUTH_CHUNKS
:
1784 case SCTP_SET_AUTH_SECRET
:
1785 /* not supported yet and until we refine the draft */
1789 case SCTP_DELAYED_ACK_TIME
:
1792 if ((size_t)m
->m_len
< sizeof(int32_t)) {
1796 tm
= mtod(m
, int32_t *);
1798 *tm
= TICKS_TO_MSEC(inp
->sctp_ep
.sctp_timeoutticks
[SCTP_TIMER_RECV
]);
1802 case SCTP_GET_SNDBUF_USE
:
1803 if ((size_t)m
->m_len
< sizeof(struct sctp_sockstat
)) {
1806 struct sctp_sockstat
*ss
;
1807 struct sctp_tcb
*stcb
;
1808 struct sctp_association
*asoc
;
1809 ss
= mtod(m
, struct sctp_sockstat
*);
1810 stcb
= sctp_findassociation_ep_asocid(inp
, ss
->ss_assoc_id
);
1815 ss
->ss_total_sndbuf
= (u_int32_t
)asoc
->total_output_queue_size
;
1816 ss
->ss_total_mbuf_sndbuf
= (u_int32_t
)asoc
->total_output_mbuf_queue_size
;
1817 ss
->ss_total_recv_buf
= (u_int32_t
)(asoc
->size_on_delivery_queue
+
1818 asoc
->size_on_reasm_queue
+
1819 asoc
->size_on_all_streams
);
1820 SCTP_TCB_UNLOCK(stcb
);
1822 m
->m_len
= sizeof(struct sctp_sockstat
);
1829 burst
= mtod(m
, u_int8_t
*);
1830 SCTP_INP_RLOCK(inp
);
1831 *burst
= inp
->sctp_ep
.max_burst
;
1832 SCTP_INP_RUNLOCK(inp
);
1833 m
->m_len
= sizeof(u_int8_t
);
1839 sctp_assoc_t
*assoc_id
;
1842 if ((size_t)m
->m_len
< sizeof(u_int32_t
)) {
1846 if ((size_t)m
->m_len
< sizeof(sctp_assoc_t
)) {
1850 assoc_id
= mtod(m
, sctp_assoc_t
*);
1851 segsize
= mtod(m
, u_int32_t
*);
1852 m
->m_len
= sizeof(u_int32_t
);
1854 if (((inp
->sctp_flags
& SCTP_PCB_FLAGS_TCPTYPE
) &&
1855 (inp
->sctp_flags
& SCTP_PCB_FLAGS_CONNECTED
)) ||
1856 (inp
->sctp_flags
& SCTP_PCB_FLAGS_IN_TCPPOOL
)) {
1857 struct sctp_tcb
*stcb
;
1858 SCTP_INP_RLOCK(inp
);
1859 stcb
= LIST_FIRST(&inp
->sctp_asoc_list
);
1861 SCTP_TCB_LOCK(stcb
);
1862 SCTP_INP_RUNLOCK(inp
);
1863 *segsize
= sctp_get_frag_point(stcb
, &stcb
->asoc
);
1864 SCTP_TCB_UNLOCK(stcb
);
1866 SCTP_INP_RUNLOCK(inp
);
1870 stcb
= sctp_findassociation_ep_asocid(inp
, *assoc_id
);
1872 *segsize
= sctp_get_frag_point(stcb
, &stcb
->asoc
);
1873 SCTP_TCB_UNLOCK(stcb
);
1877 /* default is to get the max, if I
1878 * can't calculate from an existing association.
1880 if (inp
->sctp_flags
& SCTP_PCB_FLAGS_BOUND_V6
) {
1881 ovh
= SCTP_MED_OVERHEAD
;
1883 ovh
= SCTP_MED_V4_OVERHEAD
;
1885 *segsize
= inp
->sctp_frag_point
- ovh
;
1890 case SCTP_SET_DEBUG_LEVEL
:
1894 if ((size_t)m
->m_len
< sizeof(u_int32_t
)) {
1898 level
= mtod(m
, u_int32_t
*);
1900 *level
= sctp_debug_on
;
1901 m
->m_len
= sizeof(u_int32_t
);
1902 kprintf("Returning DEBUG LEVEL %x is set\n",
1903 (u_int
)sctp_debug_on
);
1905 #else /* SCTP_DEBUG */
1909 case SCTP_GET_STAT_LOG
:
1910 #ifdef SCTP_STAT_LOGGING
1911 error
= sctp_fill_stat_log(m
);
1912 #else /* SCTP_DEBUG */
1919 if ((size_t)m
->m_len
< sizeof(sctp_pegs
)) {
1923 pt
= mtod(m
, u_int32_t
*);
1924 memcpy(pt
, sctp_pegs
, sizeof(sctp_pegs
));
1925 m
->m_len
= sizeof(sctp_pegs
);
1930 struct sctp_event_subscribe
*events
;
1932 if (sctp_debug_on
& SCTP_DEBUG_USRREQ2
) {
1933 kprintf("get events\n");
1935 #endif /* SCTP_DEBUG */
1936 if ((size_t)m
->m_len
< sizeof(struct sctp_event_subscribe
)) {
1938 if (sctp_debug_on
& SCTP_DEBUG_USRREQ2
) {
1939 kprintf("M->M_LEN is %d not %d\n",
1941 (int)sizeof(struct sctp_event_subscribe
));
1943 #endif /* SCTP_DEBUG */
1947 events
= mtod(m
, struct sctp_event_subscribe
*);
1948 memset(events
, 0, sizeof(events
));
1949 SCTP_INP_RLOCK(inp
);
1950 if (inp
->sctp_flags
& SCTP_PCB_FLAGS_RECVDATAIOEVNT
)
1951 events
->sctp_data_io_event
= 1;
1953 if (inp
->sctp_flags
& SCTP_PCB_FLAGS_RECVASSOCEVNT
)
1954 events
->sctp_association_event
= 1;
1956 if (inp
->sctp_flags
& SCTP_PCB_FLAGS_RECVPADDREVNT
)
1957 events
->sctp_address_event
= 1;
1959 if (inp
->sctp_flags
& SCTP_PCB_FLAGS_RECVSENDFAILEVNT
)
1960 events
->sctp_send_failure_event
= 1;
1962 if (inp
->sctp_flags
& SCTP_PCB_FLAGS_RECVPEERERR
)
1963 events
->sctp_peer_error_event
= 1;
1965 if (inp
->sctp_flags
& SCTP_PCB_FLAGS_RECVSHUTDOWNEVNT
)
1966 events
->sctp_shutdown_event
= 1;
1968 if (inp
->sctp_flags
& SCTP_PCB_FLAGS_PDAPIEVNT
)
1969 events
->sctp_partial_delivery_event
= 1;
1971 if (inp
->sctp_flags
& SCTP_PCB_FLAGS_ADAPTIONEVNT
)
1972 events
->sctp_adaption_layer_event
= 1;
1974 if (inp
->sctp_flags
& SCTP_PCB_FLAGS_STREAM_RESETEVNT
)
1975 events
->sctp_stream_reset_events
= 1;
1976 SCTP_INP_RUNLOCK(inp
);
1977 m
->m_len
= sizeof(struct sctp_event_subscribe
);
1982 case SCTP_ADAPTION_LAYER
:
1983 if ((size_t)m
->m_len
< sizeof(int)) {
1988 if (sctp_debug_on
& SCTP_DEBUG_USRREQ1
) {
1989 kprintf("getadaption ind\n");
1991 #endif /* SCTP_DEBUG */
1992 SCTP_INP_RLOCK(inp
);
1993 *mtod(m
, int *) = inp
->sctp_ep
.adaption_layer_indicator
;
1994 SCTP_INP_RUNLOCK(inp
);
1995 m
->m_len
= sizeof(int);
1997 case SCTP_SET_INITIAL_DBG_SEQ
:
1998 if ((size_t)m
->m_len
< sizeof(int)) {
2003 if (sctp_debug_on
& SCTP_DEBUG_USRREQ1
) {
2004 kprintf("get initial dbg seq\n");
2006 #endif /* SCTP_DEBUG */
2007 SCTP_INP_RLOCK(inp
);
2008 *mtod(m
, int *) = inp
->sctp_ep
.initial_sequence_debug
;
2009 SCTP_INP_RUNLOCK(inp
);
2010 m
->m_len
= sizeof(int);
2012 case SCTP_GET_LOCAL_ADDR_SIZE
:
2013 if ((size_t)m
->m_len
< sizeof(int)) {
2018 if (sctp_debug_on
& SCTP_DEBUG_USRREQ1
) {
2019 kprintf("get local sizes\n");
2021 #endif /* SCTP_DEBUG */
2022 SCTP_INP_RLOCK(inp
);
2023 *mtod(m
, int *) = sctp_count_max_addresses(inp
);
2024 SCTP_INP_RUNLOCK(inp
);
2025 m
->m_len
= sizeof(int);
2027 case SCTP_GET_REMOTE_ADDR_SIZE
:
2029 sctp_assoc_t
*assoc_id
;
2031 struct sctp_nets
*net
;
2033 if (sctp_debug_on
& SCTP_DEBUG_USRREQ1
) {
2034 kprintf("get remote size\n");
2036 #endif /* SCTP_DEBUG */
2037 if ((size_t)m
->m_len
< sizeof(sctp_assoc_t
)) {
2039 kprintf("m->m_len:%d not %d\n",
2040 m
->m_len
, sizeof(sctp_assoc_t
));
2041 #endif /* SCTP_DEBUG */
2046 val
= mtod(m
, u_int32_t
*);
2047 if (inp
->sctp_flags
& SCTP_PCB_FLAGS_CONNECTED
) {
2048 SCTP_INP_RLOCK(inp
);
2049 stcb
= LIST_FIRST(&inp
->sctp_asoc_list
);
2051 SCTP_TCB_LOCK(stcb
);
2052 SCTP_INP_RUNLOCK(inp
);
2055 assoc_id
= mtod(m
, sctp_assoc_t
*);
2056 stcb
= sctp_findassociation_ep_asocid(inp
, *assoc_id
);
2065 /* Count the sizes */
2066 TAILQ_FOREACH(net
, &stcb
->asoc
.nets
, sctp_next
) {
2067 if ((stcb
->sctp_ep
->sctp_flags
& SCTP_PCB_FLAGS_NEEDS_MAPPED_V4
) ||
2068 (((struct sockaddr
*)&net
->ro
._l_addr
)->sa_family
== AF_INET6
)) {
2069 sz
+= sizeof(struct sockaddr_in6
);
2070 } else if (((struct sockaddr
*)&net
->ro
._l_addr
)->sa_family
== AF_INET
) {
2071 sz
+= sizeof(struct sockaddr_in
);
2077 SCTP_TCB_UNLOCK(stcb
);
2079 m
->m_len
= sizeof(u_int32_t
);
2082 case SCTP_GET_PEER_ADDRESSES
:
2084 * Get the address information, an array
2085 * is passed in to fill up we pack it.
2089 struct sockaddr_storage
*sas
;
2090 struct sctp_nets
*net
;
2091 struct sctp_getaddresses
*saddr
;
2093 if (sctp_debug_on
& SCTP_DEBUG_USRREQ1
) {
2094 kprintf("get peer addresses\n");
2096 #endif /* SCTP_DEBUG */
2097 if ((size_t)m
->m_len
< sizeof(struct sctp_getaddresses
)) {
2101 left
= m
->m_len
- sizeof(struct sctp_getaddresses
);
2102 saddr
= mtod(m
, struct sctp_getaddresses
*);
2103 if (inp
->sctp_flags
& SCTP_PCB_FLAGS_CONNECTED
) {
2104 SCTP_INP_RLOCK(inp
);
2105 stcb
= LIST_FIRST(&inp
->sctp_asoc_list
);
2107 SCTP_TCB_LOCK(stcb
);
2108 SCTP_INP_RUNLOCK(inp
);
2110 stcb
= sctp_findassociation_ep_asocid(inp
,
2111 saddr
->sget_assoc_id
);
2116 m
->m_len
= sizeof(struct sctp_getaddresses
);
2117 sas
= (struct sockaddr_storage
*)&saddr
->addr
[0];
2119 TAILQ_FOREACH(net
, &stcb
->asoc
.nets
, sctp_next
) {
2120 if ((stcb
->sctp_ep
->sctp_flags
& SCTP_PCB_FLAGS_NEEDS_MAPPED_V4
) ||
2121 (((struct sockaddr
*)&net
->ro
._l_addr
)->sa_family
== AF_INET6
)) {
2122 cpsz
= sizeof(struct sockaddr_in6
);
2123 } else if (((struct sockaddr
*)&net
->ro
._l_addr
)->sa_family
== AF_INET
) {
2124 cpsz
= sizeof(struct sockaddr_in
);
2130 /* not enough room. */
2132 if (sctp_debug_on
& SCTP_DEBUG_USRREQ1
) {
2133 kprintf("Out of room\n");
2135 #endif /* SCTP_DEBUG */
2138 if ((stcb
->sctp_ep
->sctp_flags
& SCTP_PCB_FLAGS_NEEDS_MAPPED_V4
) &&
2139 (((struct sockaddr
*)&net
->ro
._l_addr
)->sa_family
== AF_INET
)) {
2140 /* Must map the address */
2141 in6_sin_2_v4mapsin6((struct sockaddr_in
*)&net
->ro
._l_addr
,
2142 (struct sockaddr_in6
*)sas
);
2144 memcpy(sas
, &net
->ro
._l_addr
, cpsz
);
2146 ((struct sockaddr_in
*)sas
)->sin_port
= stcb
->rport
;
2148 sas
= (struct sockaddr_storage
*)((caddr_t
)sas
+ cpsz
);
2152 if (sctp_debug_on
& SCTP_DEBUG_USRREQ2
) {
2153 kprintf("left now:%d mlen:%d\n",
2156 #endif /* SCTP_DEBUG */
2158 SCTP_TCB_UNLOCK(stcb
);
2161 if (sctp_debug_on
& SCTP_DEBUG_USRREQ1
) {
2162 kprintf("All done\n");
2164 #endif /* SCTP_DEBUG */
2166 case SCTP_GET_LOCAL_ADDRESSES
:
2169 struct sockaddr_storage
*sas
;
2170 struct sctp_getaddresses
*saddr
;
2172 if (sctp_debug_on
& SCTP_DEBUG_USRREQ1
) {
2173 kprintf("get local addresses\n");
2175 #endif /* SCTP_DEBUG */
2176 if ((size_t)m
->m_len
< sizeof(struct sctp_getaddresses
)) {
2180 saddr
= mtod(m
, struct sctp_getaddresses
*);
2182 if (saddr
->sget_assoc_id
) {
2183 if (inp
->sctp_flags
& SCTP_PCB_FLAGS_CONNECTED
) {
2184 SCTP_INP_RLOCK(inp
);
2185 stcb
= LIST_FIRST(&inp
->sctp_asoc_list
);
2187 SCTP_TCB_LOCK(stcb
);
2188 SCTP_INP_RUNLOCK(inp
);
2190 stcb
= sctp_findassociation_ep_asocid(inp
, saddr
->sget_assoc_id
);
2196 * assure that the TCP model does not need a assoc id
2199 if ( (inp
->sctp_flags
& SCTP_PCB_FLAGS_CONNECTED
) &&
2201 SCTP_INP_RLOCK(inp
);
2202 stcb
= LIST_FIRST(&inp
->sctp_asoc_list
);
2204 SCTP_TCB_LOCK(stcb
);
2205 SCTP_INP_RUNLOCK(inp
);
2207 sas
= (struct sockaddr_storage
*)&saddr
->addr
[0];
2208 limit
= m
->m_len
- sizeof(sctp_assoc_t
);
2209 actual
= sctp_fill_up_addresses(inp
, stcb
, limit
, sas
);
2210 SCTP_TCB_UNLOCK(stcb
);
2211 m
->m_len
= sizeof(struct sockaddr_storage
) + actual
;
2214 case SCTP_PEER_ADDR_PARAMS
:
2216 struct sctp_paddrparams
*paddrp
;
2217 struct sctp_nets
*net
;
2220 if (sctp_debug_on
& SCTP_DEBUG_USRREQ1
) {
2221 kprintf("Getting peer_addr_params\n");
2223 #endif /* SCTP_DEBUG */
2224 if ((size_t)m
->m_len
< sizeof(struct sctp_paddrparams
)) {
2226 if (sctp_debug_on
& SCTP_DEBUG_USRREQ2
) {
2227 kprintf("Hmm m->m_len:%d is to small\n",
2230 #endif /* SCTP_DEBUG */
2234 paddrp
= mtod(m
, struct sctp_paddrparams
*);
2237 if (paddrp
->spp_assoc_id
) {
2239 if (sctp_debug_on
& SCTP_DEBUG_USRREQ1
) {
2240 kprintf("In spp_assoc_id find type\n");
2242 #endif /* SCTP_DEBUG */
2243 if (inp
->sctp_flags
& SCTP_PCB_FLAGS_CONNECTED
) {
2244 SCTP_INP_RLOCK(inp
);
2245 stcb
= LIST_FIRST(&inp
->sctp_asoc_list
);
2247 SCTP_TCB_LOCK(stcb
);
2248 net
= sctp_findnet(stcb
, (struct sockaddr
*)&paddrp
->spp_address
);
2250 SCTP_INP_RLOCK(inp
);
2252 stcb
= sctp_findassociation_ep_asocid(inp
, paddrp
->spp_assoc_id
);
2259 if ( (stcb
== NULL
) &&
2260 ((((struct sockaddr
*)&paddrp
->spp_address
)->sa_family
== AF_INET
) ||
2261 (((struct sockaddr
*)&paddrp
->spp_address
)->sa_family
== AF_INET6
))) {
2262 /* Lookup via address */
2264 if (sctp_debug_on
& SCTP_DEBUG_USRREQ1
) {
2265 kprintf("Ok we need to lookup a param\n");
2267 #endif /* SCTP_DEBUG */
2268 if (inp
->sctp_flags
& SCTP_PCB_FLAGS_CONNECTED
) {
2269 SCTP_INP_RLOCK(inp
);
2270 stcb
= LIST_FIRST(&inp
->sctp_asoc_list
);
2272 SCTP_TCB_LOCK(stcb
);
2273 net
= sctp_findnet(stcb
, (struct sockaddr
*)&paddrp
->spp_address
);
2275 SCTP_INP_RUNLOCK(inp
);
2277 SCTP_INP_WLOCK(inp
);
2278 SCTP_INP_INCR_REF(inp
);
2279 SCTP_INP_WUNLOCK(inp
);
2280 stcb
= sctp_findassociation_ep_addr(&inp
,
2281 (struct sockaddr
*)&paddrp
->spp_address
,
2284 SCTP_INP_WLOCK(inp
);
2285 SCTP_INP_DECR_REF(inp
);
2286 SCTP_INP_WUNLOCK(inp
);
2295 /* Effects the Endpoint */
2297 if (sctp_debug_on
& SCTP_DEBUG_USRREQ1
) {
2298 kprintf("User wants EP level info\n");
2300 #endif /* SCTP_DEBUG */
2304 /* Applys to the specific association */
2306 if (sctp_debug_on
& SCTP_DEBUG_USRREQ1
) {
2307 kprintf("In TCB side\n");
2309 #endif /* SCTP_DEBUG */
2311 paddrp
->spp_pathmaxrxt
= net
->failure_threshold
;
2313 /* No destination so return default value */
2314 paddrp
->spp_pathmaxrxt
= stcb
->asoc
.def_net_failure
;
2316 paddrp
->spp_hbinterval
= stcb
->asoc
.heart_beat_delay
;
2317 paddrp
->spp_assoc_id
= sctp_get_associd(stcb
);
2318 SCTP_TCB_UNLOCK(stcb
);
2320 /* Use endpoint defaults */
2321 SCTP_INP_RLOCK(inp
);
2323 if (sctp_debug_on
& SCTP_DEBUG_USRREQ1
) {
2324 kprintf("In EP level info\n");
2326 #endif /* SCTP_DEBUG */
2327 paddrp
->spp_pathmaxrxt
= inp
->sctp_ep
.def_net_failure
;
2328 paddrp
->spp_hbinterval
= inp
->sctp_ep
.sctp_timeoutticks
[SCTP_TIMER_HEARTBEAT
];
2329 paddrp
->spp_assoc_id
= (sctp_assoc_t
)0;
2330 SCTP_INP_RUNLOCK(inp
);
2332 m
->m_len
= sizeof(struct sctp_paddrparams
);
2335 case SCTP_GET_PEER_ADDR_INFO
:
2337 struct sctp_paddrinfo
*paddri
;
2338 struct sctp_nets
*net
;
2340 if (sctp_debug_on
& SCTP_DEBUG_USRREQ1
) {
2341 kprintf("GetPEER ADDR_INFO\n");
2343 #endif /* SCTP_DEBUG */
2344 if ((size_t)m
->m_len
< sizeof(struct sctp_paddrinfo
)) {
2348 paddri
= mtod(m
, struct sctp_paddrinfo
*);
2350 if ((((struct sockaddr
*)&paddri
->spinfo_address
)->sa_family
== AF_INET
) ||
2351 (((struct sockaddr
*)&paddri
->spinfo_address
)->sa_family
== AF_INET6
)) {
2352 /* Lookup via address */
2353 if (inp
->sctp_flags
& SCTP_PCB_FLAGS_CONNECTED
) {
2354 SCTP_INP_RLOCK(inp
);
2355 stcb
= LIST_FIRST(&inp
->sctp_asoc_list
);
2357 SCTP_TCB_LOCK(stcb
);
2358 net
= sctp_findnet(stcb
,
2359 (struct sockaddr
*)&paddri
->spinfo_address
);
2361 SCTP_INP_RUNLOCK(inp
);
2363 SCTP_INP_WLOCK(inp
);
2364 SCTP_INP_INCR_REF(inp
);
2365 SCTP_INP_WUNLOCK(inp
);
2366 stcb
= sctp_findassociation_ep_addr(&inp
,
2367 (struct sockaddr
*)&paddri
->spinfo_address
,
2370 SCTP_INP_WLOCK(inp
);
2371 SCTP_INP_DECR_REF(inp
);
2372 SCTP_INP_WUNLOCK(inp
);
2379 if ((stcb
== NULL
) || (net
== NULL
)) {
2383 m
->m_len
= sizeof(struct sctp_paddrinfo
);
2384 paddri
->spinfo_state
= net
->dest_state
& (SCTP_REACHABLE_MASK
|SCTP_ADDR_NOHB
);
2385 paddri
->spinfo_cwnd
= net
->cwnd
;
2386 paddri
->spinfo_srtt
= ((net
->lastsa
>> 2) + net
->lastsv
) >> 1;
2387 paddri
->spinfo_rto
= net
->RTO
;
2388 paddri
->spinfo_assoc_id
= sctp_get_associd(stcb
);
2389 SCTP_TCB_UNLOCK(stcb
);
2392 case SCTP_PCB_STATUS
:
2394 struct sctp_pcbinfo
*spcb
;
2396 if (sctp_debug_on
& SCTP_DEBUG_USRREQ1
) {
2397 kprintf("PCB status\n");
2399 #endif /* SCTP_DEBUG */
2400 if ((size_t)m
->m_len
< sizeof(struct sctp_pcbinfo
)) {
2404 spcb
= mtod(m
, struct sctp_pcbinfo
*);
2405 sctp_fill_pcbinfo(spcb
);
2406 m
->m_len
= sizeof(struct sctp_pcbinfo
);
2411 struct sctp_nets
*net
;
2412 struct sctp_status
*sstat
;
2414 if (sctp_debug_on
& SCTP_DEBUG_USRREQ1
) {
2415 kprintf("SCTP status\n");
2417 #endif /* SCTP_DEBUG */
2419 if ((size_t)m
->m_len
< sizeof(struct sctp_status
)) {
2423 sstat
= mtod(m
, struct sctp_status
*);
2425 if (inp
->sctp_flags
& SCTP_PCB_FLAGS_CONNECTED
) {
2426 SCTP_INP_RLOCK(inp
);
2427 stcb
= LIST_FIRST(&inp
->sctp_asoc_list
);
2429 SCTP_TCB_LOCK(stcb
);
2430 SCTP_INP_RUNLOCK(inp
);
2432 stcb
= sctp_findassociation_ep_asocid(inp
, sstat
->sstat_assoc_id
);
2439 * I think passing the state is fine since
2440 * sctp_constants.h will be available to the user
2443 sstat
->sstat_state
= stcb
->asoc
.state
;
2444 sstat
->sstat_rwnd
= stcb
->asoc
.peers_rwnd
;
2445 sstat
->sstat_unackdata
= stcb
->asoc
.sent_queue_cnt
;
2447 * We can't include chunks that have been passed
2448 * to the socket layer. Only things in queue.
2450 sstat
->sstat_penddata
= (stcb
->asoc
.cnt_on_delivery_queue
+
2451 stcb
->asoc
.cnt_on_reasm_queue
+
2452 stcb
->asoc
.cnt_on_all_streams
);
2455 sstat
->sstat_instrms
= stcb
->asoc
.streamincnt
;
2456 sstat
->sstat_outstrms
= stcb
->asoc
.streamoutcnt
;
2457 sstat
->sstat_fragmentation_point
= sctp_get_frag_point(stcb
, &stcb
->asoc
);
2458 memcpy(&sstat
->sstat_primary
.spinfo_address
,
2459 &stcb
->asoc
.primary_destination
->ro
._l_addr
,
2460 ((struct sockaddr
*)(&stcb
->asoc
.primary_destination
->ro
._l_addr
))->sa_len
);
2461 net
= stcb
->asoc
.primary_destination
;
2462 ((struct sockaddr_in
*)&sstat
->sstat_primary
.spinfo_address
)->sin_port
= stcb
->rport
;
2464 * Again the user can get info from sctp_constants.h
2465 * for what the state of the network is.
2467 sstat
->sstat_primary
.spinfo_state
= net
->dest_state
& SCTP_REACHABLE_MASK
;
2468 sstat
->sstat_primary
.spinfo_cwnd
= net
->cwnd
;
2469 sstat
->sstat_primary
.spinfo_srtt
= net
->lastsa
;
2470 sstat
->sstat_primary
.spinfo_rto
= net
->RTO
;
2471 sstat
->sstat_primary
.spinfo_mtu
= net
->mtu
;
2472 sstat
->sstat_primary
.spinfo_assoc_id
= sctp_get_associd(stcb
);
2473 SCTP_TCB_UNLOCK(stcb
);
2474 m
->m_len
= sizeof(*sstat
);
2479 struct sctp_rtoinfo
*srto
;
2481 if (sctp_debug_on
& SCTP_DEBUG_USRREQ1
) {
2482 kprintf("RTO Info\n");
2484 #endif /* SCTP_DEBUG */
2485 if ((size_t)m
->m_len
< sizeof(struct sctp_rtoinfo
)) {
2489 srto
= mtod(m
, struct sctp_rtoinfo
*);
2490 if (srto
->srto_assoc_id
== 0) {
2491 /* Endpoint only please */
2492 SCTP_INP_RLOCK(inp
);
2493 srto
->srto_initial
= inp
->sctp_ep
.initial_rto
;
2494 srto
->srto_max
= inp
->sctp_ep
.sctp_maxrto
;
2495 srto
->srto_min
= inp
->sctp_ep
.sctp_minrto
;
2496 SCTP_INP_RUNLOCK(inp
);
2499 if (inp
->sctp_flags
& SCTP_PCB_FLAGS_CONNECTED
) {
2500 SCTP_INP_RLOCK(inp
);
2501 stcb
= LIST_FIRST(&inp
->sctp_asoc_list
);
2503 SCTP_TCB_LOCK(stcb
);
2504 SCTP_INP_RUNLOCK(inp
);
2506 stcb
= sctp_findassociation_ep_asocid(inp
, srto
->srto_assoc_id
);
2512 srto
->srto_initial
= stcb
->asoc
.initial_rto
;
2513 srto
->srto_max
= stcb
->asoc
.maxrto
;
2514 srto
->srto_min
= stcb
->asoc
.minrto
;
2515 SCTP_TCB_UNLOCK(stcb
);
2516 m
->m_len
= sizeof(*srto
);
2519 case SCTP_ASSOCINFO
:
2521 struct sctp_assocparams
*sasoc
;
2523 if (sctp_debug_on
& SCTP_DEBUG_USRREQ1
) {
2524 kprintf("Associnfo\n");
2526 #endif /* SCTP_DEBUG */
2527 if ((size_t)m
->m_len
< sizeof(struct sctp_assocparams
)) {
2531 sasoc
= mtod(m
, struct sctp_assocparams
*);
2534 if (inp
->sctp_flags
& SCTP_PCB_FLAGS_CONNECTED
) {
2535 SCTP_INP_RLOCK(inp
);
2536 stcb
= LIST_FIRST(&inp
->sctp_asoc_list
);
2538 SCTP_TCB_LOCK(stcb
);
2539 SCTP_INP_RUNLOCK(inp
);
2541 if ((sasoc
->sasoc_assoc_id
) && (stcb
== NULL
)) {
2542 stcb
= sctp_findassociation_ep_asocid(inp
,
2543 sasoc
->sasoc_assoc_id
);
2553 sasoc
->sasoc_asocmaxrxt
= stcb
->asoc
.max_send_times
;
2554 sasoc
->sasoc_number_peer_destinations
= stcb
->asoc
.numnets
;
2555 sasoc
->sasoc_peer_rwnd
= stcb
->asoc
.peers_rwnd
;
2556 sasoc
->sasoc_local_rwnd
= stcb
->asoc
.my_rwnd
;
2557 sasoc
->sasoc_cookie_life
= stcb
->asoc
.cookie_life
;
2558 SCTP_TCB_UNLOCK(stcb
);
2560 SCTP_INP_RLOCK(inp
);
2561 sasoc
->sasoc_asocmaxrxt
= inp
->sctp_ep
.max_send_times
;
2562 sasoc
->sasoc_number_peer_destinations
= 0;
2563 sasoc
->sasoc_peer_rwnd
= 0;
2564 sasoc
->sasoc_local_rwnd
= ssb_space(&inp
->sctp_socket
->so_rcv
);
2565 sasoc
->sasoc_cookie_life
= inp
->sctp_ep
.def_cookie_life
;
2566 SCTP_INP_RUNLOCK(inp
);
2568 m
->m_len
= sizeof(*sasoc
);
2571 case SCTP_DEFAULT_SEND_PARAM
:
2573 struct sctp_sndrcvinfo
*s_info
;
2575 if (m
->m_len
!= sizeof(struct sctp_sndrcvinfo
)) {
2579 s_info
= mtod(m
, struct sctp_sndrcvinfo
*);
2580 if (inp
->sctp_flags
& SCTP_PCB_FLAGS_CONNECTED
) {
2581 SCTP_INP_RLOCK(inp
);
2582 stcb
= LIST_FIRST(&inp
->sctp_asoc_list
);
2584 SCTP_TCB_LOCK(stcb
);
2585 SCTP_INP_RUNLOCK(inp
);
2587 stcb
= sctp_findassociation_ep_asocid(inp
, s_info
->sinfo_assoc_id
);
2594 *s_info
= stcb
->asoc
.def_send
;
2595 SCTP_TCB_UNLOCK(stcb
);
2596 m
->m_len
= sizeof(*s_info
);
2600 struct sctp_initmsg
*sinit
;
2602 if (sctp_debug_on
& SCTP_DEBUG_USRREQ1
) {
2603 kprintf("initmsg\n");
2605 #endif /* SCTP_DEBUG */
2606 if ((size_t)m
->m_len
< sizeof(struct sctp_initmsg
)) {
2610 sinit
= mtod(m
, struct sctp_initmsg
*);
2611 SCTP_INP_RLOCK(inp
);
2612 sinit
->sinit_num_ostreams
= inp
->sctp_ep
.pre_open_stream_count
;
2613 sinit
->sinit_max_instreams
= inp
->sctp_ep
.max_open_streams_intome
;
2614 sinit
->sinit_max_attempts
= inp
->sctp_ep
.max_init_times
;
2615 sinit
->sinit_max_init_timeo
= inp
->sctp_ep
.initial_init_rto_max
;
2616 SCTP_INP_RUNLOCK(inp
);
2617 m
->m_len
= sizeof(*sinit
);
2620 case SCTP_PRIMARY_ADDR
:
2621 /* we allow a "get" operation on this */
2623 struct sctp_setprim
*ssp
;
2626 if (sctp_debug_on
& SCTP_DEBUG_USRREQ1
) {
2627 kprintf("setprimary\n");
2629 #endif /* SCTP_DEBUG */
2630 if ((size_t)m
->m_len
< sizeof(struct sctp_setprim
)) {
2634 ssp
= mtod(m
, struct sctp_setprim
*);
2635 if (inp
->sctp_flags
& SCTP_PCB_FLAGS_CONNECTED
) {
2636 SCTP_INP_RLOCK(inp
);
2637 stcb
= LIST_FIRST(&inp
->sctp_asoc_list
);
2639 SCTP_TCB_LOCK(stcb
);
2640 SCTP_INP_RUNLOCK(inp
);
2642 stcb
= sctp_findassociation_ep_asocid(inp
, ssp
->ssp_assoc_id
);
2644 /* one last shot, try it by the address in */
2645 struct sctp_nets
*net
;
2647 SCTP_INP_WLOCK(inp
);
2648 SCTP_INP_INCR_REF(inp
);
2649 SCTP_INP_WUNLOCK(inp
);
2650 stcb
= sctp_findassociation_ep_addr(&inp
,
2651 (struct sockaddr
*)&ssp
->ssp_addr
,
2654 SCTP_INP_WLOCK(inp
);
2655 SCTP_INP_DECR_REF(inp
);
2656 SCTP_INP_WUNLOCK(inp
);
2664 /* simply copy out the sockaddr_storage... */
2665 memcpy(&ssp
->ssp_addr
,
2666 &stcb
->asoc
.primary_destination
->ro
._l_addr
,
2667 ((struct sockaddr
*)&stcb
->asoc
.primary_destination
->ro
._l_addr
)->sa_len
);
2668 SCTP_TCB_UNLOCK(stcb
);
2669 m
->m_len
= sizeof(*ssp
);
2673 error
= ENOPROTOOPT
;
2676 } /* end switch (sopt->sopt_name) */
2681 sctp_optsset(struct socket
*so
,
2684 #if (defined(__FreeBSD__) && __FreeBSD_version >= 500000) || defined(__DragonFly__)
2691 int error
, *mopt
, set_opt
;
2693 struct sctp_tcb
*stcb
= NULL
;
2694 struct sctp_inpcb
*inp
;
2698 if (sctp_debug_on
& SCTP_DEBUG_USRREQ1
) {
2699 kprintf("optsset:MP is NULL EINVAL\n");
2701 #endif /* SCTP_DEBUG */
2708 inp
= (struct sctp_inpcb
*)so
->so_pcb
;
2715 case SCTP_AUTOCLOSE
:
2716 case SCTP_AUTO_ASCONF
:
2717 case SCTP_DISABLE_FRAGMENTS
:
2718 case SCTP_I_WANT_MAPPED_V4_ADDR
:
2719 /* copy in the option value */
2720 if ((size_t)m
->m_len
< sizeof(int)) {
2724 mopt
= mtod(m
, int *);
2729 case SCTP_DISABLE_FRAGMENTS
:
2730 set_opt
= SCTP_PCB_FLAGS_NO_FRAGMENT
;
2732 case SCTP_AUTO_ASCONF
:
2733 set_opt
= SCTP_PCB_FLAGS_AUTO_ASCONF
;
2736 case SCTP_I_WANT_MAPPED_V4_ADDR
:
2737 if (inp
->sctp_flags
& SCTP_PCB_FLAGS_BOUND_V6
) {
2738 set_opt
= SCTP_PCB_FLAGS_NEEDS_MAPPED_V4
;
2744 set_opt
= SCTP_PCB_FLAGS_NODELAY
;
2746 case SCTP_AUTOCLOSE
:
2747 set_opt
= SCTP_PCB_FLAGS_AUTOCLOSE
;
2749 * The value is in ticks.
2750 * Note this does not effect old associations, only
2753 inp
->sctp_ep
.auto_close_time
= (*mopt
* hz
);
2756 SCTP_INP_WLOCK(inp
);
2758 inp
->sctp_flags
|= set_opt
;
2760 inp
->sctp_flags
&= ~set_opt
;
2762 SCTP_INP_WUNLOCK(inp
);
2764 case SCTP_MY_PUBLIC_KEY
: /* set my public key */
2765 case SCTP_SET_AUTH_CHUNKS
: /* set the authenticated chunks required */
2766 case SCTP_SET_AUTH_SECRET
: /* set the actual secret for the endpoint */
2767 /* not supported yet and until we refine the draft */
2771 case SCTP_CLR_STAT_LOG
:
2772 #ifdef SCTP_STAT_LOGGING
2773 sctp_clr_stat_log();
2778 case SCTP_DELAYED_ACK_TIME
:
2781 if ((size_t)m
->m_len
< sizeof(int32_t)) {
2785 tm
= mtod(m
, int32_t *);
2787 if ((*tm
< 10) || (*tm
> 500)) {
2788 /* can't be smaller than 10ms */
2789 /* MUST NOT be larger than 500ms */
2793 inp
->sctp_ep
.sctp_timeoutticks
[SCTP_TIMER_RECV
] = MSEC_TO_TICKS(*tm
);
2796 case SCTP_RESET_STREAMS
:
2798 struct sctp_stream_reset
*strrst
;
2799 uint8_t two_way
, not_peer
;
2801 if ((size_t)m
->m_len
< sizeof(struct sctp_stream_reset
)) {
2805 strrst
= mtod(m
, struct sctp_stream_reset
*);
2807 if (inp
->sctp_flags
& SCTP_PCB_FLAGS_CONNECTED
) {
2808 SCTP_INP_RLOCK(inp
);
2809 stcb
= LIST_FIRST(&inp
->sctp_asoc_list
);
2811 SCTP_TCB_LOCK(stcb
);
2812 SCTP_INP_RUNLOCK(inp
);
2814 stcb
= sctp_findassociation_ep_asocid(inp
, strrst
->strrst_assoc_id
);
2819 if (stcb
->asoc
.peer_supports_strreset
== 0) {
2820 /* Peer does not support it,
2821 * we return protocol not supported since
2822 * this is true for this feature and this
2823 * peer, not the socket request in general.
2825 error
= EPROTONOSUPPORT
;
2826 SCTP_TCB_UNLOCK(stcb
);
2830 /* Having re-thought this code I added as I write the I-D there
2831 * is NO need for it. The peer, if we are requesting a stream-reset
2832 * will send a request to us but will itself do what we do, take
2833 * and copy off the "reset information" we send and queue TSN's
2834 * larger than the send-next in our response message. Thus they
2837 /* if (stcb->asoc.sending_seq != (stcb->asoc.last_acked_seq + 1)) {*/
2838 /* Must have all sending data ack'd before we
2839 * start this procedure. This is a bit restrictive
2840 * and we SHOULD work on changing this so ONLY the
2841 * streams being RESET get held up. So, a reset-all
2842 * would require this.. but a reset specific just
2843 * needs to be sure that the ones being reset have
2844 * nothing on the send_queue. For now we will
2845 * skip this more detailed method and do a course
2846 * way.. i.e. nothing pending ... for future FIX ME!
2852 if (stcb
->asoc
.stream_reset_outstanding
) {
2854 SCTP_TCB_UNLOCK(stcb
);
2857 if (strrst
->strrst_flags
== SCTP_RESET_LOCAL_RECV
) {
2860 } else if (strrst
->strrst_flags
== SCTP_RESET_LOCAL_SEND
) {
2863 } else if (strrst
->strrst_flags
== SCTP_RESET_BOTH
) {
2868 SCTP_TCB_UNLOCK(stcb
);
2871 sctp_send_str_reset_req(stcb
, strrst
->strrst_num_streams
,
2872 strrst
->strrst_list
, two_way
, not_peer
);
2874 sctp_chunk_output(inp
, stcb
, 12);
2875 SCTP_TCB_UNLOCK(stcb
);
2880 case SCTP_RESET_PEGS
:
2881 memset(sctp_pegs
, 0, sizeof(sctp_pegs
));
2884 case SCTP_CONNECT_X
:
2885 if ((size_t)m
->m_len
< (sizeof(int) + sizeof(struct sockaddr_in
))) {
2889 error
= sctp_do_connect_x(so
, inp
, m
, p
, 0);
2892 case SCTP_CONNECT_X_DELAYED
:
2893 if ((size_t)m
->m_len
< (sizeof(int) + sizeof(struct sockaddr_in
))) {
2897 error
= sctp_do_connect_x(so
, inp
, m
, p
, 1);
2900 case SCTP_CONNECT_X_COMPLETE
:
2902 struct sockaddr
*sa
;
2903 struct sctp_nets
*net
;
2904 if ((size_t)m
->m_len
< sizeof(struct sockaddr_in
)) {
2908 sa
= mtod(m
, struct sockaddr
*);
2910 if (inp
->sctp_flags
& SCTP_PCB_FLAGS_CONNECTED
) {
2911 SCTP_INP_RLOCK(inp
);
2912 stcb
= LIST_FIRST(&inp
->sctp_asoc_list
);
2914 SCTP_TCB_LOCK(stcb
);
2915 net
= sctp_findnet(stcb
, sa
);
2917 SCTP_INP_RUNLOCK(inp
);
2919 SCTP_INP_WLOCK(inp
);
2920 SCTP_INP_INCR_REF(inp
);
2921 SCTP_INP_WUNLOCK(inp
);
2922 stcb
= sctp_findassociation_ep_addr(&inp
, sa
, &net
, NULL
, NULL
);
2924 SCTP_INP_WLOCK(inp
);
2925 SCTP_INP_DECR_REF(inp
);
2926 SCTP_INP_WUNLOCK(inp
);
2934 if (stcb
->asoc
.delayed_connection
== 1) {
2935 stcb
->asoc
.delayed_connection
= 0;
2936 SCTP_GETTIME_TIMEVAL(&stcb
->asoc
.time_entered
);
2937 sctp_timer_stop(SCTP_TIMER_TYPE_INIT
, inp
, stcb
, stcb
->asoc
.primary_destination
);
2938 sctp_send_initiate(inp
, stcb
);
2940 /* already expired or did not use delayed connectx */
2943 SCTP_TCB_UNLOCK(stcb
);
2949 SCTP_INP_WLOCK(inp
);
2950 burst
= mtod(m
, u_int8_t
*);
2952 inp
->sctp_ep
.max_burst
= *burst
;
2954 SCTP_INP_WUNLOCK(inp
);
2961 if (inp
->sctp_flags
& SCTP_PCB_FLAGS_BOUND_V6
) {
2962 ovh
= SCTP_MED_OVERHEAD
;
2964 ovh
= SCTP_MED_V4_OVERHEAD
;
2966 segsize
= mtod(m
, u_int32_t
*);
2971 SCTP_INP_WLOCK(inp
);
2972 inp
->sctp_frag_point
= (*segsize
+ovh
);
2973 if (inp
->sctp_frag_point
< MHLEN
) {
2974 inp
->sctp_frag_point
= MHLEN
;
2976 SCTP_INP_WUNLOCK(inp
);
2979 case SCTP_SET_DEBUG_LEVEL
:
2983 if ((size_t)m
->m_len
< sizeof(u_int32_t
)) {
2987 level
= mtod(m
, u_int32_t
*);
2989 sctp_debug_on
= (*level
& (SCTP_DEBUG_ALL
|
2991 kprintf("SETTING DEBUG LEVEL to %x\n",
2992 (u_int
)sctp_debug_on
);
2997 #endif /* SCTP_DEBUG */
3001 struct sctp_event_subscribe
*events
;
3002 if ((size_t)m
->m_len
< sizeof(struct sctp_event_subscribe
)) {
3006 SCTP_INP_WLOCK(inp
);
3007 events
= mtod(m
, struct sctp_event_subscribe
*);
3008 if (events
->sctp_data_io_event
) {
3009 inp
->sctp_flags
|= SCTP_PCB_FLAGS_RECVDATAIOEVNT
;
3011 inp
->sctp_flags
&= ~SCTP_PCB_FLAGS_RECVDATAIOEVNT
;
3014 if (events
->sctp_association_event
) {
3015 inp
->sctp_flags
|= SCTP_PCB_FLAGS_RECVASSOCEVNT
;
3017 inp
->sctp_flags
&= ~SCTP_PCB_FLAGS_RECVASSOCEVNT
;
3020 if (events
->sctp_address_event
) {
3021 inp
->sctp_flags
|= SCTP_PCB_FLAGS_RECVPADDREVNT
;
3023 inp
->sctp_flags
&= ~SCTP_PCB_FLAGS_RECVPADDREVNT
;
3026 if (events
->sctp_send_failure_event
) {
3027 inp
->sctp_flags
|= SCTP_PCB_FLAGS_RECVSENDFAILEVNT
;
3029 inp
->sctp_flags
&= ~SCTP_PCB_FLAGS_RECVSENDFAILEVNT
;
3032 if (events
->sctp_peer_error_event
) {
3033 inp
->sctp_flags
|= SCTP_PCB_FLAGS_RECVPEERERR
;
3035 inp
->sctp_flags
&= ~SCTP_PCB_FLAGS_RECVPEERERR
;
3038 if (events
->sctp_shutdown_event
) {
3039 inp
->sctp_flags
|= SCTP_PCB_FLAGS_RECVSHUTDOWNEVNT
;
3041 inp
->sctp_flags
&= ~SCTP_PCB_FLAGS_RECVSHUTDOWNEVNT
;
3044 if (events
->sctp_partial_delivery_event
) {
3045 inp
->sctp_flags
|= SCTP_PCB_FLAGS_PDAPIEVNT
;
3047 inp
->sctp_flags
&= ~SCTP_PCB_FLAGS_PDAPIEVNT
;
3050 if (events
->sctp_adaption_layer_event
) {
3051 inp
->sctp_flags
|= SCTP_PCB_FLAGS_ADAPTIONEVNT
;
3053 inp
->sctp_flags
&= ~SCTP_PCB_FLAGS_ADAPTIONEVNT
;
3056 if (events
->sctp_stream_reset_events
) {
3057 inp
->sctp_flags
|= SCTP_PCB_FLAGS_STREAM_RESETEVNT
;
3059 inp
->sctp_flags
&= ~SCTP_PCB_FLAGS_STREAM_RESETEVNT
;
3061 SCTP_INP_WUNLOCK(inp
);
3065 case SCTP_ADAPTION_LAYER
:
3067 struct sctp_setadaption
*adap_bits
;
3068 if ((size_t)m
->m_len
< sizeof(struct sctp_setadaption
)) {
3072 SCTP_INP_WLOCK(inp
);
3073 adap_bits
= mtod(m
, struct sctp_setadaption
*);
3074 inp
->sctp_ep
.adaption_layer_indicator
= adap_bits
->ssb_adaption_ind
;
3075 SCTP_INP_WUNLOCK(inp
);
3078 case SCTP_SET_INITIAL_DBG_SEQ
:
3081 if ((size_t)m
->m_len
< sizeof(u_int32_t
)) {
3085 SCTP_INP_WLOCK(inp
);
3086 vvv
= mtod(m
, u_int32_t
*);
3087 inp
->sctp_ep
.initial_sequence_debug
= *vvv
;
3088 SCTP_INP_WUNLOCK(inp
);
3091 case SCTP_DEFAULT_SEND_PARAM
:
3093 struct sctp_sndrcvinfo
*s_info
;
3095 if (m
->m_len
!= sizeof(struct sctp_sndrcvinfo
)) {
3099 s_info
= mtod(m
, struct sctp_sndrcvinfo
*);
3101 if (inp
->sctp_flags
& SCTP_PCB_FLAGS_CONNECTED
) {
3102 SCTP_INP_RLOCK(inp
);
3103 stcb
= LIST_FIRST(&inp
->sctp_asoc_list
);
3105 SCTP_TCB_LOCK(stcb
);
3106 SCTP_INP_RUNLOCK(inp
);
3108 stcb
= sctp_findassociation_ep_asocid(inp
, s_info
->sinfo_assoc_id
);
3114 /* Validate things */
3115 if (s_info
->sinfo_stream
> stcb
->asoc
.streamoutcnt
) {
3116 SCTP_TCB_UNLOCK(stcb
);
3120 /* Mask off the flags that are allowed */
3121 s_info
->sinfo_flags
= (s_info
->sinfo_flags
&
3122 (MSG_UNORDERED
| MSG_ADDR_OVER
|
3123 MSG_PR_SCTP_TTL
| MSG_PR_SCTP_BUF
));
3125 stcb
->asoc
.def_send
= *s_info
;
3126 SCTP_TCB_UNLOCK(stcb
);
3129 case SCTP_PEER_ADDR_PARAMS
:
3131 struct sctp_paddrparams
*paddrp
;
3132 struct sctp_nets
*net
;
3133 if ((size_t)m
->m_len
< sizeof(struct sctp_paddrparams
)) {
3137 paddrp
= mtod(m
, struct sctp_paddrparams
*);
3139 if (paddrp
->spp_assoc_id
) {
3140 if (inp
->sctp_flags
& SCTP_PCB_FLAGS_CONNECTED
) {
3141 SCTP_INP_RLOCK(inp
);
3142 stcb
= LIST_FIRST(&inp
->sctp_asoc_list
);
3144 SCTP_TCB_LOCK(stcb
);
3145 net
= sctp_findnet(stcb
, (struct sockaddr
*)&paddrp
->spp_address
);
3147 SCTP_INP_RUNLOCK(inp
);
3149 stcb
= sctp_findassociation_ep_asocid(inp
, paddrp
->spp_assoc_id
);
3156 if ((stcb
== NULL
) &&
3157 ((((struct sockaddr
*)&paddrp
->spp_address
)->sa_family
== AF_INET
) ||
3158 (((struct sockaddr
*)&paddrp
->spp_address
)->sa_family
== AF_INET6
))) {
3159 /* Lookup via address */
3160 if (inp
->sctp_flags
& SCTP_PCB_FLAGS_CONNECTED
) {
3161 SCTP_INP_RLOCK(inp
);
3162 stcb
= LIST_FIRST(&inp
->sctp_asoc_list
);
3164 SCTP_TCB_LOCK(stcb
);
3165 net
= sctp_findnet(stcb
,
3166 (struct sockaddr
*)&paddrp
->spp_address
);
3168 SCTP_INP_RUNLOCK(inp
);
3170 SCTP_INP_WLOCK(inp
);
3171 SCTP_INP_INCR_REF(inp
);
3172 SCTP_INP_WUNLOCK(inp
);
3173 stcb
= sctp_findassociation_ep_addr(&inp
,
3174 (struct sockaddr
*)&paddrp
->spp_address
,
3177 SCTP_INP_WLOCK(inp
);
3178 SCTP_INP_DECR_REF(inp
);
3179 SCTP_INP_WUNLOCK(inp
);
3183 /* Effects the Endpoint */
3187 /* Applies to the specific association */
3188 if (paddrp
->spp_pathmaxrxt
) {
3190 if (paddrp
->spp_pathmaxrxt
)
3191 net
->failure_threshold
= paddrp
->spp_pathmaxrxt
;
3193 if (paddrp
->spp_pathmaxrxt
)
3194 stcb
->asoc
.def_net_failure
= paddrp
->spp_pathmaxrxt
;
3197 if ((paddrp
->spp_hbinterval
!= 0) && (paddrp
->spp_hbinterval
!= 0xffffffff)) {
3201 net
->dest_state
&= ~SCTP_ADDR_NOHB
;
3203 old
= stcb
->asoc
.heart_beat_delay
;
3204 stcb
->asoc
.heart_beat_delay
= paddrp
->spp_hbinterval
;
3206 /* Turn back on the timer */
3207 sctp_timer_start(SCTP_TIMER_TYPE_HEARTBEAT
, inp
, stcb
, net
);
3210 } else if (paddrp
->spp_hbinterval
== 0xffffffff) {
3212 sctp_send_hb(stcb
, 1, net
);
3215 /* off on association */
3216 if (stcb
->asoc
.heart_beat_delay
) {
3217 int cnt_of_unconf
= 0;
3218 struct sctp_nets
*lnet
;
3219 TAILQ_FOREACH(lnet
, &stcb
->asoc
.nets
, sctp_next
) {
3220 if (lnet
->dest_state
& SCTP_ADDR_UNCONFIRMED
) {
3224 /* stop the timer ONLY if we have no unconfirmed addresses
3226 if (cnt_of_unconf
== 0)
3227 sctp_timer_stop(SCTP_TIMER_TYPE_HEARTBEAT
, inp
, stcb
, net
);
3229 stcb
->asoc
.heart_beat_delay
= 0;
3231 net
->dest_state
|= SCTP_ADDR_NOHB
;
3234 SCTP_TCB_UNLOCK(stcb
);
3236 /* Use endpoint defaults */
3237 SCTP_INP_WLOCK(inp
);
3238 if (paddrp
->spp_pathmaxrxt
)
3239 inp
->sctp_ep
.def_net_failure
= paddrp
->spp_pathmaxrxt
;
3240 if (paddrp
->spp_hbinterval
!= SCTP_ISSUE_HB
)
3241 inp
->sctp_ep
.sctp_timeoutticks
[SCTP_TIMER_HEARTBEAT
] = paddrp
->spp_hbinterval
;
3242 SCTP_INP_WUNLOCK(inp
);
3248 struct sctp_rtoinfo
*srto
;
3249 if ((size_t)m
->m_len
< sizeof(struct sctp_rtoinfo
)) {
3253 srto
= mtod(m
, struct sctp_rtoinfo
*);
3254 if (srto
->srto_assoc_id
== 0) {
3255 SCTP_INP_WLOCK(inp
);
3256 /* If we have a null asoc, its default for the endpoint */
3257 if (srto
->srto_initial
> 10)
3258 inp
->sctp_ep
.initial_rto
= srto
->srto_initial
;
3259 if (srto
->srto_max
> 10)
3260 inp
->sctp_ep
.sctp_maxrto
= srto
->srto_max
;
3261 if (srto
->srto_min
> 10)
3262 inp
->sctp_ep
.sctp_minrto
= srto
->srto_min
;
3263 SCTP_INP_WUNLOCK(inp
);
3266 if (inp
->sctp_flags
& SCTP_PCB_FLAGS_CONNECTED
) {
3267 SCTP_INP_RLOCK(inp
);
3268 stcb
= LIST_FIRST(&inp
->sctp_asoc_list
);
3270 SCTP_TCB_LOCK(stcb
);
3271 SCTP_INP_RUNLOCK(inp
);
3273 stcb
= sctp_findassociation_ep_asocid(inp
, srto
->srto_assoc_id
);
3278 /* Set in ms we hope :-) */
3279 if (srto
->srto_initial
> 10)
3280 stcb
->asoc
.initial_rto
= srto
->srto_initial
;
3281 if (srto
->srto_max
> 10)
3282 stcb
->asoc
.maxrto
= srto
->srto_max
;
3283 if (srto
->srto_min
> 10)
3284 stcb
->asoc
.minrto
= srto
->srto_min
;
3285 SCTP_TCB_UNLOCK(stcb
);
3288 case SCTP_ASSOCINFO
:
3290 struct sctp_assocparams
*sasoc
;
3292 if ((size_t)m
->m_len
< sizeof(struct sctp_assocparams
)) {
3296 sasoc
= mtod(m
, struct sctp_assocparams
*);
3297 if (sasoc
->sasoc_assoc_id
) {
3298 if (inp
->sctp_flags
& SCTP_PCB_FLAGS_CONNECTED
) {
3299 SCTP_INP_RLOCK(inp
);
3300 stcb
= LIST_FIRST(&inp
->sctp_asoc_list
);
3302 SCTP_TCB_LOCK(stcb
);
3303 SCTP_INP_RUNLOCK(inp
);
3305 stcb
= sctp_findassociation_ep_asocid(inp
,
3306 sasoc
->sasoc_assoc_id
);
3316 if (sasoc
->sasoc_asocmaxrxt
)
3317 stcb
->asoc
.max_send_times
= sasoc
->sasoc_asocmaxrxt
;
3318 sasoc
->sasoc_number_peer_destinations
= stcb
->asoc
.numnets
;
3319 sasoc
->sasoc_peer_rwnd
= 0;
3320 sasoc
->sasoc_local_rwnd
= 0;
3321 if (stcb
->asoc
.cookie_life
)
3322 stcb
->asoc
.cookie_life
= sasoc
->sasoc_cookie_life
;
3323 SCTP_TCB_UNLOCK(stcb
);
3325 SCTP_INP_WLOCK(inp
);
3326 if (sasoc
->sasoc_asocmaxrxt
)
3327 inp
->sctp_ep
.max_send_times
= sasoc
->sasoc_asocmaxrxt
;
3328 sasoc
->sasoc_number_peer_destinations
= 0;
3329 sasoc
->sasoc_peer_rwnd
= 0;
3330 sasoc
->sasoc_local_rwnd
= 0;
3331 if (sasoc
->sasoc_cookie_life
)
3332 inp
->sctp_ep
.def_cookie_life
= sasoc
->sasoc_cookie_life
;
3333 SCTP_INP_WUNLOCK(inp
);
3339 struct sctp_initmsg
*sinit
;
3341 if ((size_t)m
->m_len
< sizeof(struct sctp_initmsg
)) {
3345 sinit
= mtod(m
, struct sctp_initmsg
*);
3346 SCTP_INP_WLOCK(inp
);
3347 if (sinit
->sinit_num_ostreams
)
3348 inp
->sctp_ep
.pre_open_stream_count
= sinit
->sinit_num_ostreams
;
3350 if (sinit
->sinit_max_instreams
)
3351 inp
->sctp_ep
.max_open_streams_intome
= sinit
->sinit_max_instreams
;
3353 if (sinit
->sinit_max_attempts
)
3354 inp
->sctp_ep
.max_init_times
= sinit
->sinit_max_attempts
;
3356 if (sinit
->sinit_max_init_timeo
> 10)
3357 /* We must be at least a 100ms (we set in ticks) */
3358 inp
->sctp_ep
.initial_init_rto_max
= sinit
->sinit_max_init_timeo
;
3359 SCTP_INP_WUNLOCK(inp
);
3362 case SCTP_PRIMARY_ADDR
:
3364 struct sctp_setprim
*spa
;
3365 struct sctp_nets
*net
, *lnet
;
3366 if ((size_t)m
->m_len
< sizeof(struct sctp_setprim
)) {
3370 spa
= mtod(m
, struct sctp_setprim
*);
3372 if (inp
->sctp_flags
& SCTP_PCB_FLAGS_CONNECTED
) {
3373 SCTP_INP_RLOCK(inp
);
3374 stcb
= LIST_FIRST(&inp
->sctp_asoc_list
);
3376 SCTP_TCB_LOCK(stcb
);
3381 SCTP_INP_RUNLOCK(inp
);
3383 stcb
= sctp_findassociation_ep_asocid(inp
, spa
->ssp_assoc_id
);
3386 SCTP_INP_WLOCK(inp
);
3387 SCTP_INP_INCR_REF(inp
);
3388 SCTP_INP_WUNLOCK(inp
);
3389 stcb
= sctp_findassociation_ep_addr(&inp
,
3390 (struct sockaddr
*)&spa
->ssp_addr
,
3393 SCTP_INP_WLOCK(inp
);
3394 SCTP_INP_DECR_REF(inp
);
3395 SCTP_INP_WUNLOCK(inp
);
3400 /* find the net, associd or connected lookup type */
3401 net
= sctp_findnet(stcb
, (struct sockaddr
*)&spa
->ssp_addr
);
3403 SCTP_TCB_UNLOCK(stcb
);
3408 if ((net
!= stcb
->asoc
.primary_destination
) &&
3409 (!(net
->dest_state
& SCTP_ADDR_UNCONFIRMED
))) {
3410 /* Ok we need to set it */
3411 lnet
= stcb
->asoc
.primary_destination
;
3412 lnet
->next_tsn_at_change
= net
->next_tsn_at_change
= stcb
->asoc
.sending_seq
;
3413 if (sctp_set_primary_addr(stcb
,
3416 if (net
->dest_state
& SCTP_ADDR_SWITCH_PRIMARY
) {
3417 net
->dest_state
|= SCTP_ADDR_DOUBLE_SWITCH
;
3419 net
->dest_state
|= SCTP_ADDR_SWITCH_PRIMARY
;
3422 SCTP_TCB_UNLOCK(stcb
);
3426 case SCTP_SET_PEER_PRIMARY_ADDR
:
3428 struct sctp_setpeerprim
*sspp
;
3429 if ((size_t)m
->m_len
< sizeof(struct sctp_setpeerprim
)) {
3433 sspp
= mtod(m
, struct sctp_setpeerprim
*);
3436 if (inp
->sctp_flags
& SCTP_PCB_FLAGS_CONNECTED
) {
3437 SCTP_INP_RLOCK(inp
);
3438 stcb
= LIST_FIRST(&inp
->sctp_asoc_list
);
3440 SCTP_TCB_UNLOCK(stcb
);
3441 SCTP_INP_RUNLOCK(inp
);
3443 stcb
= sctp_findassociation_ep_asocid(inp
, sspp
->sspp_assoc_id
);
3448 if (sctp_set_primary_ip_address_sa(stcb
, (struct sockaddr
*)&sspp
->sspp_addr
) != 0) {
3451 SCTP_TCB_UNLOCK(stcb
);
3454 case SCTP_BINDX_ADD_ADDR
:
3456 struct sctp_getaddresses
*addrs
;
3457 struct sockaddr
*addr_touse
;
3458 struct sockaddr_in sin
;
3459 /* see if we're bound all already! */
3460 if (inp
->sctp_flags
& SCTP_PCB_FLAGS_BOUNDALL
) {
3464 if ((size_t)m
->m_len
< sizeof(struct sctp_getaddresses
)) {
3468 addrs
= mtod(m
, struct sctp_getaddresses
*);
3469 addr_touse
= addrs
->addr
;
3470 if (addrs
->addr
->sa_family
== AF_INET6
) {
3471 struct sockaddr_in6
*sin6
;
3472 sin6
= (struct sockaddr_in6
*)addr_touse
;
3473 if (IN6_IS_ADDR_V4MAPPED(&sin6
->sin6_addr
)) {
3474 in6_sin6_2_sin(&sin
, sin6
);
3475 addr_touse
= (struct sockaddr
*)&sin
;
3478 if (inp
->sctp_flags
& SCTP_PCB_FLAGS_UNBOUND
) {
3480 /* Can't get proc for Net/Open BSD */
3484 error
= sctp_inpcb_bind(so
, addr_touse
, p
);
3487 /* No locks required here since bind and mgmt_ep_sa all
3488 * do their own locking. If we do something for the FIX:
3489 * below we may need to lock in that case.
3491 if (addrs
->sget_assoc_id
== 0) {
3492 /* add the address */
3493 struct sctp_inpcb
*lep
;
3494 ((struct sockaddr_in
*)addr_touse
)->sin_port
= inp
->sctp_lport
;
3495 lep
= sctp_pcb_findep(addr_touse
, 1, 0);
3497 /* We must decrement the refcount
3498 * since we have the ep already and
3499 * are binding. No remove going on
3502 SCTP_INP_WLOCK(inp
);
3503 SCTP_INP_DECR_REF(inp
);
3504 SCTP_INP_WUNLOCK(inp
);
3507 /* already bound to it.. ok */
3509 } else if (lep
== NULL
) {
3510 ((struct sockaddr_in
*)addr_touse
)->sin_port
= 0;
3511 error
= sctp_addr_mgmt_ep_sa(inp
, addr_touse
,
3512 SCTP_ADD_IP_ADDRESS
);
3514 error
= EADDRNOTAVAIL
;
3520 /* FIX: decide whether we allow assoc based bindx */
3524 case SCTP_BINDX_REM_ADDR
:
3526 struct sctp_getaddresses
*addrs
;
3527 struct sockaddr
*addr_touse
;
3528 struct sockaddr_in sin
;
3529 /* see if we're bound all already! */
3530 if (inp
->sctp_flags
& SCTP_PCB_FLAGS_BOUNDALL
) {
3534 if ((size_t)m
->m_len
< sizeof(struct sctp_getaddresses
)) {
3538 addrs
= mtod(m
, struct sctp_getaddresses
*);
3539 addr_touse
= addrs
->addr
;
3540 if (addrs
->addr
->sa_family
== AF_INET6
) {
3541 struct sockaddr_in6
*sin6
;
3542 sin6
= (struct sockaddr_in6
*)addr_touse
;
3543 if (IN6_IS_ADDR_V4MAPPED(&sin6
->sin6_addr
)) {
3544 in6_sin6_2_sin(&sin
, sin6
);
3545 addr_touse
= (struct sockaddr
*)&sin
;
3548 /* No lock required mgmt_ep_sa does its own locking. If
3549 * the FIX: below is ever changed we may need to
3550 * lock before calling association level binding.
3552 if (addrs
->sget_assoc_id
== 0) {
3553 /* delete the address */
3554 sctp_addr_mgmt_ep_sa(inp
, addr_touse
,
3555 SCTP_DEL_IP_ADDRESS
);
3557 /* FIX: decide whether we allow assoc based bindx */
3562 error
= ENOPROTOOPT
;
3564 } /* end switch (opt) */
3569 #if defined(__FreeBSD__) || defined(__APPLE__) || defined(__DragonFly__)
3571 sctp_ctloutput(struct socket
*so
, struct sockopt
*sopt
)
3573 struct mbuf
*m
= NULL
;
3574 struct sctp_inpcb
*inp
;
3577 inp
= (struct sctp_inpcb
*)so
->so_pcb
;
3581 /* I made the same as TCP since we are not setup? */
3582 return (ECONNRESET
);
3584 if (sopt
->sopt_level
!= IPPROTO_SCTP
) {
3585 /* wrong proto level... send back up to IP */
3587 if (INP_CHECK_SOCKAF(so
, AF_INET6
))
3588 error
= ip6_ctloutput(so
, sopt
);
3591 error
= ip_ctloutput(so
, sopt
);
3595 if (sopt
->sopt_valsize
> MCLBYTES
) {
3597 * Restrict us down to a cluster size, that's all we can
3598 * pass either way...
3600 sopt
->sopt_valsize
= MCLBYTES
;
3602 if (sopt
->sopt_valsize
) {
3604 m
= m_get(MB_WAIT
, MT_DATA
);
3605 if (sopt
->sopt_valsize
> MLEN
) {
3606 MCLGET(m
, MB_DONTWAIT
);
3607 if ((m
->m_flags
& M_EXT
) == 0) {
3613 error
= sooptcopyin(sopt
, mtod(m
, caddr_t
), sopt
->sopt_valsize
,
3614 sopt
->sopt_valsize
);
3619 m
->m_len
= sopt
->sopt_valsize
;
3621 if (sopt
->sopt_dir
== SOPT_SET
) {
3622 #if (defined(__FreeBSD__) && __FreeBSD_version >= 500000) || defined(__DragonFly__)
3623 error
= sctp_optsset(so
, sopt
->sopt_name
, &m
, sopt
->sopt_td
);
3625 error
= sctp_optsset(so
, sopt
->sopt_name
, &m
, sopt
->sopt_p
);
3627 } else if (sopt
->sopt_dir
== SOPT_GET
) {
3628 #if (defined (__FreeBSD__) && __FreeBSD_version >= 500000) || defined(__DragonFly__)
3629 error
= sctp_optsget(so
, sopt
->sopt_name
, &m
, sopt
->sopt_td
);
3631 error
= sctp_optsget(so
, sopt
->sopt_name
, &m
, sopt
->sopt_p
);
3636 if ( (error
== 0) && (m
!= NULL
)) {
3637 error
= sooptcopyout(sopt
, mtod(m
, caddr_t
), m
->m_len
);
3639 } else if (m
!= NULL
) {
3648 /* NetBSD and OpenBSD */
3650 sctp_ctloutput(int op
, struct socket
*so
, int level
, int optname
,
3656 struct in6pcb
*in6p
;
3658 int family
; /* family of the socket */
3660 family
= so
->so_proto
->pr_domain
->dom_family
;
3665 inp
= sotoinpcb(so
);
3673 in6p
= sotoin6pcb(so
);
3678 return EAFNOSUPPORT
;
3683 if (inp
== NULL
&& in6p
== NULL
)
3687 if (op
== PRCO_SETOPT
&& *mp
)
3689 return (ECONNRESET
);
3691 if (level
!= IPPROTO_SCTP
) {
3694 error
= ip_ctloutput(op
, so
, level
, optname
, mp
);
3698 error
= ip6_ctloutput(op
, so
, level
, optname
, mp
);
3705 /* Ok if we reach here it is a SCTP option we hope */
3706 if (op
== PRCO_SETOPT
) {
3707 error
= sctp_optsset(so
, optname
, mp
, NULL
);
3710 } else if (op
== PRCO_GETOPT
) {
3711 error
= sctp_optsget(so
, optname
, mp
, NULL
);
3722 #if (defined(__FreeBSD__) && __FreeBSD_version >= 500000) || defined(__DragonFly__)
3723 sctp_connect(struct socket
*so
, struct sockaddr
*addr
, struct thread
*p
)
3726 #if defined(__FreeBSD__) || defined(__APPLE__)
3727 sctp_connect(struct socket
*so
, struct sockaddr
*addr
, struct proc
*p
)
3730 sctp_connect(struct socket
*so
, struct mbuf
*nam
, struct proc
*p
)
3732 struct sockaddr
*addr
= mtod(nam
, struct sockaddr
*);
3736 struct sctp_inpcb
*inp
;
3737 struct sctp_tcb
*stcb
;
3740 if (sctp_debug_on
& SCTP_DEBUG_PCB1
) {
3741 kprintf("Connect called in SCTP to ");
3742 sctp_print_address(addr
);
3743 kprintf("Port %d\n", ntohs(((struct sockaddr_in
*)addr
)->sin_port
));
3745 #endif /* SCTP_DEBUG */
3747 inp
= (struct sctp_inpcb
*)so
->so_pcb
;
3750 /* I made the same as TCP since we are not setup? */
3751 return (ECONNRESET
);
3753 SCTP_ASOC_CREATE_LOCK(inp
);
3754 SCTP_INP_WLOCK(inp
);
3755 if ((inp
->sctp_flags
& SCTP_PCB_FLAGS_SOCKET_GONE
) ||
3756 (inp
->sctp_flags
& SCTP_PCB_FLAGS_SOCKET_GONE
)) {
3757 /* Should I really unlock ? */
3758 SCTP_INP_WUNLOCK(inp
);
3759 SCTP_ASOC_CREATE_UNLOCK(inp
);
3764 if (((inp
->sctp_flags
& SCTP_PCB_FLAGS_BOUND_V6
) == 0) &&
3765 (addr
->sa_family
== AF_INET6
)) {
3766 SCTP_INP_WUNLOCK(inp
);
3767 SCTP_ASOC_CREATE_UNLOCK(inp
);
3772 if ((inp
->sctp_flags
& SCTP_PCB_FLAGS_UNBOUND
) ==
3773 SCTP_PCB_FLAGS_UNBOUND
) {
3774 /* Bind a ephemeral port */
3775 SCTP_INP_WUNLOCK(inp
);
3776 error
= sctp_inpcb_bind(so
, NULL
, p
);
3778 SCTP_ASOC_CREATE_UNLOCK(inp
);
3782 SCTP_INP_WLOCK(inp
);
3784 /* Now do we connect? */
3785 if ((inp
->sctp_flags
& SCTP_PCB_FLAGS_TCPTYPE
) &&
3786 (inp
->sctp_flags
& SCTP_PCB_FLAGS_CONNECTED
)) {
3787 /* We are already connected AND the TCP model */
3789 SCTP_INP_WUNLOCK(inp
);
3790 SCTP_ASOC_CREATE_UNLOCK(inp
);
3791 return (EADDRINUSE
);
3793 if (inp
->sctp_flags
& SCTP_PCB_FLAGS_CONNECTED
) {
3794 stcb
= LIST_FIRST(&inp
->sctp_asoc_list
);
3796 SCTP_TCB_UNLOCK(stcb
);
3797 SCTP_INP_WUNLOCK(inp
);
3799 SCTP_INP_INCR_REF(inp
);
3800 SCTP_INP_WUNLOCK(inp
);
3801 stcb
= sctp_findassociation_ep_addr(&inp
, addr
, NULL
, NULL
, NULL
);
3803 SCTP_INP_WLOCK(inp
);
3804 SCTP_INP_DECR_REF(inp
);
3805 SCTP_INP_WUNLOCK(inp
);
3809 /* Already have or am bring up an association */
3810 SCTP_ASOC_CREATE_UNLOCK(inp
);
3811 SCTP_TCB_UNLOCK(stcb
);
3815 /* We are GOOD to go */
3816 stcb
= sctp_aloc_assoc(inp
, addr
, 1, &error
, 0);
3818 /* Gak! no memory */
3822 if (stcb
->sctp_ep
->sctp_flags
& SCTP_PCB_FLAGS_TCPTYPE
) {
3823 stcb
->sctp_ep
->sctp_flags
|= SCTP_PCB_FLAGS_CONNECTED
;
3824 /* Set the connected flag so we can queue data */
3827 stcb
->asoc
.state
= SCTP_STATE_COOKIE_WAIT
;
3828 SCTP_GETTIME_TIMEVAL(&stcb
->asoc
.time_entered
);
3829 sctp_send_initiate(inp
, stcb
);
3830 SCTP_ASOC_CREATE_UNLOCK(inp
);
3831 SCTP_TCB_UNLOCK(stcb
);
3837 sctp_usr_recvd(struct socket
*so
, int flags
)
3839 struct sctp_socket_q_list
*sq
=NULL
;
3841 * The user has received some data, we may be able to stuff more
3842 * up the socket. And we need to possibly update the rwnd.
3844 struct sctp_inpcb
*inp
;
3845 struct sctp_tcb
*stcb
=NULL
;
3847 inp
= (struct sctp_inpcb
*)so
->so_pcb
;
3849 if (sctp_debug_on
& SCTP_DEBUG_USRREQ2
)
3850 kprintf("Read for so:%x inp:%x Flags:%x\n",
3851 (u_int
)so
, (u_int
)inp
, (u_int
)flags
);
3855 /* I made the same as TCP since we are not setup? */
3857 if (sctp_debug_on
& SCTP_DEBUG_USRREQ2
)
3858 kprintf("Nope, connection reset\n");
3860 return (ECONNRESET
);
3864 * Grab the first one on the list. It will re-insert itself if
3865 * it runs out of room
3867 SCTP_INP_WLOCK(inp
);
3868 if ((flags
& MSG_EOR
) && ((inp
->sctp_flags
& SCTP_PCB_FLAGS_IN_TCPPOOL
) == 0)
3869 && ((inp
->sctp_flags
& SCTP_PCB_FLAGS_CONNECTED
) == 0)) {
3870 /* Ok the other part of our grubby tracking
3871 * stuff for our horrible layer violation that
3872 * the tsvwg thinks is ok for sctp_peeloff.. gak!
3873 * We must update the next vtag pending on the
3874 * socket buffer (if any).
3876 inp
->sctp_vtag_first
= sctp_get_first_vtag_from_sb(so
);
3877 sq
= TAILQ_FIRST(&inp
->sctp_queue_list
);
3884 stcb
= LIST_FIRST(&inp
->sctp_asoc_list
);
3887 SCTP_TCB_LOCK(stcb
);
3890 /* all code in normal stcb path assumes
3891 * that you have a tcb_lock only. Thus
3892 * we must release the inp write lock.
3894 if (flags
& MSG_EOR
) {
3895 if (((inp
->sctp_flags
& SCTP_PCB_FLAGS_IN_TCPPOOL
) == 0)
3896 && ((inp
->sctp_flags
& SCTP_PCB_FLAGS_CONNECTED
) == 0)) {
3897 stcb
= sctp_remove_from_socket_q(inp
);
3900 if (sctp_debug_on
& SCTP_DEBUG_USRREQ2
)
3901 kprintf("remove from socket queue for inp:%x tcbret:%x\n",
3902 (u_int
)inp
, (u_int
)stcb
);
3905 stcb
->asoc
.my_rwnd_control_len
= sctp_sbspace_sub(stcb
->asoc
.my_rwnd_control_len
,
3906 sizeof(struct mbuf
));
3907 if (inp
->sctp_flags
& SCTP_PCB_FLAGS_RECVDATAIOEVNT
) {
3908 stcb
->asoc
.my_rwnd_control_len
= sctp_sbspace_sub(stcb
->asoc
.my_rwnd_control_len
,
3909 CMSG_LEN(sizeof(struct sctp_sndrcvinfo
)));
3912 if ((TAILQ_EMPTY(&stcb
->asoc
.delivery_queue
) == 0) ||
3913 (TAILQ_EMPTY(&stcb
->asoc
.reasmqueue
) == 0)) {
3914 /* Deliver if there is something to be delivered */
3915 sctp_service_queues(stcb
, &stcb
->asoc
, 1);
3917 sctp_set_rwnd(stcb
, &stcb
->asoc
);
3918 /* if we increase by 1 or more MTU's (smallest MTUs of all
3919 * nets) we send a window update sack
3921 incr
= stcb
->asoc
.my_rwnd
- stcb
->asoc
.my_last_reported_rwnd
;
3925 if (((uint32_t)incr
>= (stcb
->asoc
.smallest_mtu
* SCTP_SEG_TO_RWND_UPD
)) ||
3926 ((((uint32_t)incr
)*SCTP_SCALE_OF_RWND_TO_UPD
) >= so
->so_rcv
.ssb_hiwat
)) {
3927 if (callout_pending(&stcb
->asoc
.dack_timer
.timer
)) {
3928 /* If the timer is up, stop it */
3929 sctp_timer_stop(SCTP_TIMER_TYPE_RECV
,
3930 stcb
->sctp_ep
, stcb
, NULL
);
3932 /* Send the sack, with the new rwnd */
3933 sctp_send_sack(stcb
);
3934 /* Now do the output */
3935 sctp_chunk_output(inp
, stcb
, 10);
3938 if ((( sq
) && (flags
& MSG_EOR
) && ((inp
->sctp_flags
& SCTP_PCB_FLAGS_IN_TCPPOOL
) == 0))
3939 && ((inp
->sctp_flags
& SCTP_PCB_FLAGS_CONNECTED
) == 0)) {
3940 stcb
= sctp_remove_from_socket_q(inp
);
3943 SOCKBUF_LOCK(&so
->so_rcv
);
3944 if (( so
->so_rcv
.ssb_mb
== NULL
) &&
3945 (TAILQ_EMPTY(&inp
->sctp_queue_list
) == 0)) {
3948 if (sctp_debug_on
& SCTP_DEBUG_USRREQ2
)
3949 kprintf("Something off, inp:%x so->so_rcv->ssb_mb is empty and sockq is not.. cleaning\n",
3952 if (((inp
->sctp_flags
& SCTP_PCB_FLAGS_IN_TCPPOOL
) == 0)
3953 && ((inp
->sctp_flags
& SCTP_PCB_FLAGS_CONNECTED
) == 0)) {
3955 done_yet
= TAILQ_EMPTY(&inp
->sctp_queue_list
);
3958 sctp_remove_from_socket_q(inp
);
3959 done_yet
= TAILQ_EMPTY(&inp
->sctp_queue_list
);
3963 if (sctp_debug_on
& SCTP_DEBUG_USRREQ2
)
3964 kprintf("Cleaned up %d sockq's\n", sq_cnt
);
3967 SOCKBUF_UNLOCK(&so
->so_rcv
);
3969 SCTP_TCB_UNLOCK(stcb
);
3970 SCTP_INP_WUNLOCK(inp
);
3976 #if (defined(__FreeBSD__) && __FreeBSD_version >= 500000) || defined(__DragonFly__)
3977 sctp_listen(struct socket
*so
, struct thread
*p
)
3979 sctp_listen(struct socket
*so
, struct proc
*p
)
3983 * Note this module depends on the protocol processing being
3984 * called AFTER any socket level flags and backlog are applied
3985 * to the socket. The traditional way that the socket flags are
3986 * applied is AFTER protocol processing. We have made a change
3987 * to the sys/kern/uipc_socket.c module to reverse this but this
3988 * MUST be in place if the socket API for SCTP is to work properly.
3991 struct sctp_inpcb
*inp
;
3994 inp
= (struct sctp_inpcb
*)so
->so_pcb
;
3997 /* I made the same as TCP since we are not setup? */
3998 return (ECONNRESET
);
4000 SCTP_INP_RLOCK(inp
);
4001 if ((inp
->sctp_flags
& SCTP_PCB_FLAGS_TCPTYPE
) &&
4002 (inp
->sctp_flags
& SCTP_PCB_FLAGS_CONNECTED
)) {
4003 /* We are already connected AND the TCP model */
4005 SCTP_INP_RUNLOCK(inp
);
4006 return (EADDRINUSE
);
4008 if (inp
->sctp_flags
& SCTP_PCB_FLAGS_UNBOUND
) {
4009 /* We must do a bind. */
4010 SCTP_INP_RUNLOCK(inp
);
4011 if ((error
= sctp_inpcb_bind(so
, NULL
, p
))) {
4012 /* bind error, probably perm */
4017 SCTP_INP_RUNLOCK(inp
);
4020 SCTP_INP_WLOCK(inp
);
4021 if (inp
->sctp_socket
->so_qlimit
) {
4022 if (inp
->sctp_flags
& SCTP_PCB_FLAGS_UDPTYPE
) {
4024 * For the UDP model we must TURN OFF the ACCEPT
4025 * flags since we do NOT allow the accept() call.
4026 * The TCP model (when present) will do accept which
4027 * then prohibits connect().
4029 inp
->sctp_socket
->so_options
&= ~SO_ACCEPTCONN
;
4031 inp
->sctp_flags
|= SCTP_PCB_FLAGS_ACCEPTING
;
4033 if (inp
->sctp_flags
& SCTP_PCB_FLAGS_ACCEPTING
) {
4035 * Turning off the listen flags if the backlog is
4036 * set to 0 (i.e. qlimit is 0).
4038 inp
->sctp_flags
&= ~SCTP_PCB_FLAGS_ACCEPTING
;
4040 inp
->sctp_socket
->so_options
&= ~SO_ACCEPTCONN
;
4042 SCTP_INP_WUNLOCK(inp
);
4049 #if defined(__FreeBSD__) || defined(__APPLE__) || defined(__DragonFly__)
4050 sctp_accept(struct socket
*so
, struct sockaddr
**addr
)
4053 sctp_accept(struct socket
*so
, struct mbuf
*nam
)
4055 struct sockaddr
*addr
= mtod(nam
, struct sockaddr
*);
4057 struct sctp_tcb
*stcb
;
4058 struct sockaddr
*prim
;
4059 struct sctp_inpcb
*inp
;
4062 inp
= (struct sctp_inpcb
*)so
->so_pcb
;
4066 return (ECONNRESET
);
4068 SCTP_INP_RLOCK(inp
);
4069 if (so
->so_state
& SS_ISDISCONNECTED
) {
4071 SCTP_INP_RUNLOCK(inp
);
4072 return (ECONNABORTED
);
4074 stcb
= LIST_FIRST(&inp
->sctp_asoc_list
);
4077 SCTP_INP_RUNLOCK(inp
);
4078 return (ECONNRESET
);
4080 SCTP_TCB_LOCK(stcb
);
4081 SCTP_INP_RUNLOCK(inp
);
4082 prim
= (struct sockaddr
*)&stcb
->asoc
.primary_destination
->ro
._l_addr
;
4083 if (prim
->sa_family
== AF_INET
) {
4084 struct sockaddr_in
*sin
;
4085 #if defined(__FreeBSD__) || defined(__APPLE__) || defined(__DragonFly__)
4086 MALLOC(sin
, struct sockaddr_in
*, sizeof *sin
, M_SONAME
,
4089 sin
= (struct sockaddr_in
*)addr
;
4090 bzero((caddr_t
)sin
, sizeof (*sin
));
4092 sin
->sin_family
= AF_INET
;
4093 sin
->sin_len
= sizeof(*sin
);
4094 sin
->sin_port
= ((struct sockaddr_in
*)prim
)->sin_port
;
4095 sin
->sin_addr
= ((struct sockaddr_in
*)prim
)->sin_addr
;
4096 #if defined(__FreeBSD__) || defined(__APPLE__) || defined(__DragonFly__)
4097 *addr
= (struct sockaddr
*)sin
;
4099 nam
->m_len
= sizeof(*sin
);
4102 struct sockaddr_in6
*sin6
;
4103 #if defined(__FreeBSD__) || defined(__APPLE__) || defined(__DragonFly__)
4104 MALLOC(sin6
, struct sockaddr_in6
*, sizeof *sin6
, M_SONAME
,
4107 sin6
= (struct sockaddr_in6
*)addr
;
4109 bzero((caddr_t
)sin6
, sizeof (*sin6
));
4110 sin6
->sin6_family
= AF_INET6
;
4111 sin6
->sin6_len
= sizeof(*sin6
);
4112 sin6
->sin6_port
= ((struct sockaddr_in6
*)prim
)->sin6_port
;
4114 sin6
->sin6_addr
= ((struct sockaddr_in6
*)prim
)->sin6_addr
;
4115 if (IN6_IS_SCOPE_LINKLOCAL(&sin6
->sin6_addr
))
4116 /* sin6->sin6_scope_id = ntohs(sin6->sin6_addr.s6_addr16[1]);*/
4117 in6_recoverscope(sin6
, &sin6
->sin6_addr
, NULL
); /* skip ifp check */
4119 sin6
->sin6_scope_id
= 0; /*XXX*/
4120 #if defined(__FreeBSD__) || defined (__APPLE__) || defined(__DragonFly__)
4121 *addr
= (struct sockaddr
*)sin6
;
4123 nam
->m_len
= sizeof(*sin6
);
4126 /* Wake any delayed sleep action */
4127 SCTP_TCB_UNLOCK(stcb
);
4128 SCTP_INP_WLOCK(inp
);
4129 if (inp
->sctp_flags
& SCTP_PCB_FLAGS_DONT_WAKE
) {
4130 inp
->sctp_flags
&= ~SCTP_PCB_FLAGS_DONT_WAKE
;
4131 if (inp
->sctp_flags
& SCTP_PCB_FLAGS_WAKEOUTPUT
) {
4132 inp
->sctp_flags
&= ~SCTP_PCB_FLAGS_WAKEOUTPUT
;
4133 #if defined(__NetBSD__)
4134 if (sowritable(inp
->sctp_socket
))
4135 sowwakeup(inp
->sctp_socket
);
4137 if (sowriteable(inp
->sctp_socket
))
4138 sowwakeup(inp
->sctp_socket
);
4141 if (inp
->sctp_flags
& SCTP_PCB_FLAGS_WAKEINPUT
) {
4142 inp
->sctp_flags
&= ~SCTP_PCB_FLAGS_WAKEINPUT
;
4143 if (soreadable(inp
->sctp_socket
))
4144 sorwakeup(inp
->sctp_socket
);
4148 SCTP_INP_WUNLOCK(inp
);
4154 #if defined(__FreeBSD__) || defined(__APPLE__) || defined(__DragonFly__)
4155 sctp_ingetaddr(struct socket
*so
, struct sockaddr
**addr
)
4157 sctp_ingetaddr(struct socket
*so
, struct mbuf
*nam
)
4160 #if defined(__FreeBSD__) || defined(__APPLE__) || defined(__DragonFly__)
4161 struct sockaddr_in
*sin
;
4163 struct sockaddr_in
*sin
= mtod(nam
, struct sockaddr_in
*);
4165 struct sctp_inpcb
*inp
;
4167 * Do the malloc first in case it blocks.
4169 #if defined(__FreeBSD__) || defined(__APPLE__) || defined(__DragonFly__)
4170 MALLOC(sin
, struct sockaddr_in
*, sizeof *sin
, M_SONAME
, M_WAITOK
|
4173 nam
->m_len
= sizeof(*sin
);
4174 memset(sin
, 0, sizeof(*sin
));
4176 sin
->sin_family
= AF_INET
;
4177 sin
->sin_len
= sizeof(*sin
);
4179 inp
= (struct sctp_inpcb
*)so
->so_pcb
;
4182 #if defined(__FreeBSD__) || defined(__APPLE__) || defined(__DragonFly__)
4183 FREE(sin
, M_SONAME
);
4187 SCTP_INP_RLOCK(inp
);
4188 sin
->sin_port
= inp
->sctp_lport
;
4189 if (inp
->sctp_flags
& SCTP_PCB_FLAGS_BOUNDALL
) {
4190 if (inp
->sctp_flags
& SCTP_PCB_FLAGS_CONNECTED
) {
4191 struct sctp_tcb
*stcb
;
4192 struct sockaddr_in
*sin_a
;
4193 struct sctp_nets
*net
;
4196 stcb
= LIST_FIRST(&inp
->sctp_asoc_list
);
4202 SCTP_TCB_LOCK(stcb
);
4203 TAILQ_FOREACH(net
, &stcb
->asoc
.nets
, sctp_next
) {
4204 sin_a
= (struct sockaddr_in
*)&net
->ro
._l_addr
;
4205 if (sin_a
->sin_family
== AF_INET
) {
4210 if ((!fnd
) || (sin_a
== NULL
)) {
4212 SCTP_TCB_UNLOCK(stcb
);
4215 sin
->sin_addr
= sctp_ipv4_source_address_selection(inp
,
4216 stcb
, (struct route
*)&net
->ro
, net
, 0);
4217 SCTP_TCB_UNLOCK(stcb
);
4219 /* For the bound all case you get back 0 */
4221 sin
->sin_addr
.s_addr
= 0;
4225 /* Take the first IPv4 address in the list */
4226 struct sctp_laddr
*laddr
;
4228 LIST_FOREACH(laddr
, &inp
->sctp_addr_list
, sctp_nxt_addr
) {
4229 if (laddr
->ifa
->ifa_addr
->sa_family
== AF_INET
) {
4230 struct sockaddr_in
*sin_a
;
4231 sin_a
= (struct sockaddr_in
*)laddr
->ifa
->ifa_addr
;
4232 sin
->sin_addr
= sin_a
->sin_addr
;
4239 #if defined(__FreeBSD__) || defined(__APPLE__) || defined(__DragonFly__)
4240 FREE(sin
, M_SONAME
);
4242 SCTP_INP_RUNLOCK(inp
);
4246 SCTP_INP_RUNLOCK(inp
);
4248 #if defined(__FreeBSD__) || defined(__APPLE__) || defined(__DragonFly__)
4249 (*addr
) = (struct sockaddr
*)sin
;
4255 #if defined(__FreeBSD__) || defined(__APPLE__) || defined(__DragonFly__)
4256 sctp_peeraddr(struct socket
*so
, struct sockaddr
**addr
)
4258 struct sockaddr_in
*sin
= (struct sockaddr_in
*)*addr
;
4260 sctp_peeraddr(struct socket
*so
, struct mbuf
*nam
)
4262 struct sockaddr_in
*sin
= mtod(nam
, struct sockaddr_in
*);
4265 struct sockaddr_in
*sin_a
;
4266 struct sctp_inpcb
*inp
;
4267 struct sctp_tcb
*stcb
;
4268 struct sctp_nets
*net
;
4270 /* Do the malloc first in case it blocks. */
4271 inp
= (struct sctp_inpcb
*)so
->so_pcb
;
4272 if ((inp
== NULL
) ||
4273 ((inp
->sctp_flags
& SCTP_PCB_FLAGS_CONNECTED
) == 0)) {
4274 /* UDP type and listeners will drop out here */
4279 #if defined(__FreeBSD__) || defined(__APPLE__) || defined(__DragonFly__)
4280 MALLOC(sin
, struct sockaddr_in
*, sizeof *sin
, M_SONAME
, M_WAITOK
|
4283 nam
->m_len
= sizeof(*sin
);
4284 memset(sin
, 0, sizeof(*sin
));
4286 sin
->sin_family
= AF_INET
;
4287 sin
->sin_len
= sizeof(*sin
);
4289 /* We must recapture incase we blocked */
4290 inp
= (struct sctp_inpcb
*)so
->so_pcb
;
4293 #if defined(__FreeBSD__) || defined(__APPLE__) || defined(__DragonFly__)
4294 FREE(sin
, M_SONAME
);
4298 SCTP_INP_RLOCK(inp
);
4299 stcb
= LIST_FIRST(&inp
->sctp_asoc_list
);
4301 SCTP_TCB_LOCK(stcb
);
4302 SCTP_INP_RUNLOCK(inp
);
4305 #if defined(__FreeBSD__) || defined(__APPLE__) || defined(__DragonFly__)
4306 FREE(sin
, M_SONAME
);
4311 TAILQ_FOREACH(net
, &stcb
->asoc
.nets
, sctp_next
) {
4312 sin_a
= (struct sockaddr_in
*)&net
->ro
._l_addr
;
4313 if (sin_a
->sin_family
== AF_INET
) {
4315 sin
->sin_port
= stcb
->rport
;
4316 sin
->sin_addr
= sin_a
->sin_addr
;
4320 SCTP_TCB_UNLOCK(stcb
);
4322 /* No IPv4 address */
4324 #if defined(__FreeBSD__) || defined(__APPLE__) || defined(__DragonFly__)
4325 FREE(sin
, M_SONAME
);
4333 #if defined(__FreeBSD__) || defined(__APPLE__) || defined(__DragonFly__)
4334 struct pr_usrreqs sctp_usrreqs
= {
4335 .pru_abort
= sctp_abort
,
4336 .pru_accept
= sctp_accept
,
4337 .pru_attach
= sctp_attach
,
4338 .pru_bind
= sctp_bind
,
4339 .pru_connect
= sctp_connect
,
4340 .pru_connect2
= pru_connect2_notsupp
,
4341 .pru_control
= in_control
,
4342 .pru_detach
= sctp_detach
,
4343 .pru_disconnect
= sctp_disconnect
,
4344 .pru_listen
= sctp_listen
,
4345 .pru_peeraddr
= sctp_peeraddr
,
4346 .pru_rcvd
= sctp_usr_recvd
,
4347 .pru_rcvoob
= pru_rcvoob_notsupp
,
4348 .pru_send
= sctp_send
,
4349 .pru_sense
= pru_sense_null
,
4350 .pru_shutdown
= sctp_shutdown
,
4351 .pru_sockaddr
= sctp_ingetaddr
,
4352 .pru_sosend
= sctp_sosend
,
4353 .pru_soreceive
= soreceive
,
4354 .pru_sopoll
= sopoll
4358 #if defined(__NetBSD__)
4360 sctp_usrreq(struct socket
*so
, int req
, struct mbuf
*m
, struct mbuf
*nam
,
4361 struct mbuf
*control
, struct proc
*p
)
4365 sctp_usrreq(struct socket
*so
, int req
, struct mbuf
*m
, struct mbuf
*nam
,
4366 struct mbuf
*control
)
4368 struct proc
*p
= curproc
;
4373 family
= so
->so_proto
->pr_domain
->dom_family
;
4376 if (req
== PRU_CONTROL
) {
4379 error
= in_control(so
, (long)m
, (caddr_t
)nam
,
4380 (struct ifnet
*)control
4381 #if defined(__NetBSD__)
4388 error
= in6_control(so
, (long)m
, (caddr_t
)nam
,
4389 (struct ifnet
*)control
, p
);
4393 error
= EAFNOSUPPORT
;
4399 if (req
== PRU_PURGEIF
) {
4402 ifn
= (struct ifnet
*)control
;
4403 TAILQ_FOREACH(ifa
, &ifn
->if_addrlist
, ifa_list
) {
4404 if (ifa
->ifa_addr
->sa_family
== family
) {
4405 sctp_delete_ip_address(ifa
);
4419 return (EAFNOSUPPORT
);
4427 error
= sctp_attach(so
, family
, p
);
4430 error
= sctp_detach(so
);
4437 error
= sctp_bind(so
, nam
, p
);
4440 error
= sctp_listen(so
, p
);
4447 error
= sctp_connect(so
, nam
, p
);
4449 case PRU_DISCONNECT
:
4450 error
= sctp_disconnect(so
);
4457 error
= sctp_accept(so
, nam
);
4460 error
= sctp_shutdown(so
);
4465 * For Open and Net BSD, this is real
4466 * ugly. The mbuf *nam that is passed
4467 * (by soreceive()) is the int flags c
4468 * ast as a (mbuf *) yuck!
4470 error
= sctp_usr_recvd(so
, (int)((long)nam
));
4474 /* Flags are ignored */
4476 if (sctp_debug_on
& SCTP_DEBUG_USRREQ1
) {
4477 kprintf("Send called on V4 side\n");
4481 struct sockaddr
*addr
;
4485 addr
= mtod(nam
, struct sockaddr
*);
4487 error
= sctp_send(so
, 0, m
, addr
, control
, p
);
4491 error
= sctp_abort(so
);
4498 error
= EAFNOSUPPORT
;
4501 error
= EAFNOSUPPORT
;
4504 error
= sctp_peeraddr(so
, nam
);
4507 error
= sctp_ingetaddr(so
, nam
);
4520 /* #if defined(__NetBSD__) || defined(__OpenBSD__) */
4523 * Sysctl for sctp variables.
4526 sctp_sysctl(int *name
, u_int namelen
, void *oldp
, size_t *oldlenp
, void *newp
,
4530 /* All sysctl names at this level are terminal. */
4536 case SCTPCTL_MAXDGRAM
:
4537 return (sysctl_int(oldp
, oldlenp
, newp
, newlen
,
4539 case SCTPCTL_RECVSPACE
:
4540 return (sysctl_int(oldp
, oldlenp
, newp
, newlen
,
4542 case SCTPCTL_AUTOASCONF
:
4543 return (sysctl_int(oldp
, oldlenp
, newp
, newlen
,
4544 &sctp_auto_asconf
));
4545 case SCTPCTL_ECN_ENABLE
:
4546 return (sysctl_int(oldp
, oldlenp
, newp
, newlen
,
4548 case SCTPCTL_ECN_NONCE
:
4549 return (sysctl_int(oldp
, oldlenp
, newp
, newlen
,
4551 case SCTPCTL_STRICT_SACK
:
4552 return (sysctl_int(oldp
, oldlenp
, newp
, newlen
,
4553 &sctp_strict_sacks
));
4554 case SCTPCTL_NOCSUM_LO
:
4555 return (sysctl_int(oldp
, oldlenp
, newp
, newlen
,
4556 &sctp_no_csum_on_loopback
));
4557 case SCTPCTL_STRICT_INIT
:
4558 return (sysctl_int(oldp
, oldlenp
, newp
, newlen
,
4559 &sctp_strict_init
));
4560 case SCTPCTL_PEER_CHK_OH
:
4561 return (sysctl_int(oldp
, oldlenp
, newp
, newlen
,
4562 &sctp_peer_chunk_oh
));
4563 case SCTPCTL_MAXBURST
:
4564 return (sysctl_int(oldp
, oldlenp
, newp
, newlen
,
4565 &sctp_max_burst_default
));
4566 case SCTPCTL_MAXCHUNKONQ
:
4567 return (sysctl_int(oldp
, oldlenp
, newp
, newlen
,
4568 &sctp_max_chunks_on_queue
));
4569 case SCTPCTL_DELAYED_SACK
:
4570 return (sysctl_int(oldp
, oldlenp
, newp
, newlen
,
4571 &sctp_delayed_sack_time_default
));
4572 case SCTPCTL_HB_INTERVAL
:
4573 return (sysctl_int(oldp
, oldlenp
, newp
, newlen
,
4574 &sctp_heartbeat_interval_default
));
4575 case SCTPCTL_PMTU_RAISE
:
4576 return (sysctl_int(oldp
, oldlenp
, newp
, newlen
,
4577 &sctp_pmtu_raise_time_default
));
4578 case SCTPCTL_SHUTDOWN_GUARD
:
4579 return (sysctl_int(oldp
, oldlenp
, newp
, newlen
,
4580 &sctp_shutdown_guard_time_default
));
4581 case SCTPCTL_SECRET_LIFETIME
:
4582 return (sysctl_int(oldp
, oldlenp
, newp
, newlen
,
4583 &sctp_secret_lifetime_default
));
4584 case SCTPCTL_RTO_MAX
:
4585 return (sysctl_int(oldp
, oldlenp
, newp
, newlen
,
4586 &sctp_rto_max_default
));
4587 case SCTPCTL_RTO_MIN
:
4588 return (sysctl_int(oldp
, oldlenp
, newp
, newlen
,
4589 &sctp_rto_min_default
));
4590 case SCTPCTL_RTO_INITIAL
:
4591 return (sysctl_int(oldp
, oldlenp
, newp
, newlen
,
4592 &sctp_rto_initial_default
));
4593 case SCTPCTL_INIT_RTO_MAX
:
4594 return (sysctl_int(oldp
, oldlenp
, newp
, newlen
,
4595 &sctp_init_rto_max_default
));
4596 case SCTPCTL_COOKIE_LIFE
:
4597 return (sysctl_int(oldp
, oldlenp
, newp
, newlen
,
4598 &sctp_valid_cookie_life_default
));
4599 case SCTPCTL_INIT_RTX_MAX
:
4600 return (sysctl_int(oldp
, oldlenp
, newp
, newlen
,
4601 &sctp_init_rtx_max_default
));
4602 case SCTPCTL_ASSOC_RTX_MAX
:
4603 return (sysctl_int(oldp
, oldlenp
, newp
, newlen
,
4604 &sctp_assoc_rtx_max_default
));
4605 case SCTPCTL_PATH_RTX_MAX
:
4606 return (sysctl_int(oldp
, oldlenp
, newp
, newlen
,
4607 &sctp_path_rtx_max_default
));
4608 case SCTPCTL_NR_OUTGOING_STREAMS
:
4609 return (sysctl_int(oldp
, oldlenp
, newp
, newlen
,
4610 &sctp_nr_outgoing_streams_default
));
4613 return (sysctl_int(oldp
, oldlenp
, newp
, newlen
,
4617 return (ENOPROTOOPT
);
4624 * Sysctl for sctp variables.
4626 SYSCTL_SETUP(sysctl_net_inet_sctp_setup
, "sysctl net.inet.sctp subtree setup")
4629 sysctl_createv(clog
, 0, NULL
, NULL
,
4631 CTLTYPE_NODE
, "net", NULL
,
4634 sysctl_createv(clog
, 0, NULL
, NULL
,
4636 CTLTYPE_NODE
, "inet", NULL
,
4638 CTL_NET
, PF_INET
, CTL_EOL
);
4639 sysctl_createv(clog
, 0, NULL
, NULL
,
4641 CTLTYPE_NODE
, "sctp",
4642 SYSCTL_DESCR("sctp related settings"),
4644 CTL_NET
, PF_INET
, IPPROTO_SCTP
, CTL_EOL
);
4646 sysctl_createv(clog
, 0, NULL
, NULL
,
4647 CTLFLAG_PERMANENT
|CTLFLAG_READWRITE
,
4648 CTLTYPE_INT
, "maxdgram",
4649 SYSCTL_DESCR("Maximum outgoing SCTP buffer size"),
4650 NULL
, 0, &sctp_sendspace
, 0,
4651 CTL_NET
, PF_INET
, IPPROTO_SCTP
, SCTPCTL_MAXDGRAM
,
4654 sysctl_createv(clog
, 0, NULL
, NULL
,
4655 CTLFLAG_PERMANENT
|CTLFLAG_READWRITE
,
4656 CTLTYPE_INT
, "recvspace",
4657 SYSCTL_DESCR("Maximum incoming SCTP buffer size"),
4658 NULL
, 0, &sctp_recvspace
, 0,
4659 CTL_NET
, PF_INET
, IPPROTO_SCTP
, SCTPCTL_RECVSPACE
,
4662 sysctl_createv(clog
, 0, NULL
, NULL
,
4663 CTLFLAG_PERMANENT
|CTLFLAG_READWRITE
,
4664 CTLTYPE_INT
, "autoasconf",
4665 SYSCTL_DESCR("Enable SCTP Auto-ASCONF"),
4666 NULL
, 0, &sctp_auto_asconf
, 0,
4667 CTL_NET
, PF_INET
, IPPROTO_SCTP
, SCTPCTL_AUTOASCONF
,
4670 sysctl_createv(clog
, 0, NULL
, NULL
,
4671 CTLFLAG_PERMANENT
|CTLFLAG_READWRITE
,
4672 CTLTYPE_INT
, "ecn_enable",
4673 SYSCTL_DESCR("Enable SCTP ECN"),
4674 NULL
, 0, &sctp_ecn
, 0,
4675 CTL_NET
, PF_INET
, IPPROTO_SCTP
, SCTPCTL_ECN_ENABLE
,
4678 sysctl_createv(clog
, 0, NULL
, NULL
,
4679 CTLFLAG_PERMANENT
|CTLFLAG_READWRITE
,
4680 CTLTYPE_INT
, "ecn_nonce",
4681 SYSCTL_DESCR("Enable SCTP ECN Nonce"),
4682 NULL
, 0, &sctp_ecn_nonce
, 0,
4683 CTL_NET
, PF_INET
, IPPROTO_SCTP
, SCTPCTL_ECN_NONCE
,
4686 sysctl_createv(clog
, 0, NULL
, NULL
,
4687 CTLFLAG_PERMANENT
|CTLFLAG_READWRITE
,
4688 CTLTYPE_INT
, "strict_sack",
4689 SYSCTL_DESCR("Enable SCTP Strict SACK checking"),
4690 NULL
, 0, &sctp_strict_sacks
, 0,
4691 CTL_NET
, PF_INET
, IPPROTO_SCTP
, SCTPCTL_STRICT_SACK
,
4694 sysctl_createv(clog
, 0, NULL
, NULL
,
4695 CTLFLAG_PERMANENT
|CTLFLAG_READWRITE
,
4696 CTLTYPE_INT
, "loopback_nocsum",
4697 SYSCTL_DESCR("Enable NO Csum on packets sent on loopback"),
4698 NULL
, 0, &sctp_no_csum_on_loopback
, 0,
4699 CTL_NET
, PF_INET
, IPPROTO_SCTP
, SCTPCTL_NOCSUM_LO
,
4702 sysctl_createv(clog
, 0, NULL
, NULL
,
4703 CTLFLAG_PERMANENT
|CTLFLAG_READWRITE
,
4704 CTLTYPE_INT
, "strict_init",
4705 SYSCTL_DESCR("Enable strict INIT/INIT-ACK singleton enforcement"),
4706 NULL
, 0, &sctp_strict_init
, 0,
4707 CTL_NET
, PF_INET
, IPPROTO_SCTP
, SCTPCTL_STRICT_INIT
,
4710 sysctl_createv(clog
, 0, NULL
, NULL
,
4711 CTLFLAG_PERMANENT
|CTLFLAG_READWRITE
,
4712 CTLTYPE_INT
, "peer_chkoh",
4713 SYSCTL_DESCR("Amount to debit peers rwnd per chunk sent"),
4714 NULL
, 0, &sctp_peer_chunk_oh
, 0,
4715 CTL_NET
, PF_INET
, IPPROTO_SCTP
, SCTPCTL_PEER_CHK_OH
,
4718 sysctl_createv(clog
, 0, NULL
, NULL
,
4719 CTLFLAG_PERMANENT
|CTLFLAG_READWRITE
,
4720 CTLTYPE_INT
, "maxburst",
4721 SYSCTL_DESCR("Default max burst for sctp endpoints"),
4722 NULL
, 0, &sctp_max_burst_default
, 0,
4723 CTL_NET
, PF_INET
, IPPROTO_SCTP
, SCTPCTL_MAXBURST
,
4726 sysctl_createv(clog
, 0, NULL
, NULL
,
4727 CTLFLAG_PERMANENT
|CTLFLAG_READWRITE
,
4728 CTLTYPE_INT
, "maxchunks",
4729 SYSCTL_DESCR("Default max chunks on queue per asoc"),
4730 NULL
, 0, &sctp_max_chunks_on_queue
, 0,
4731 CTL_NET
, PF_INET
, IPPROTO_SCTP
, SCTPCTL_MAXCHUNKONQ
,