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>
59 #include <sys/protosw.h>
60 #include <sys/socket.h>
61 #include <sys/socketvar.h>
62 #include <sys/sysctl.h>
63 #include <sys/syslog.h>
64 #include <sys/thread2.h>
66 #include <net/if_types.h>
67 #if defined(__FreeBSD__) || defined(__APPLE__) || defined(__DragonFly__)
68 #include <net/if_var.h>
70 #include <net/route.h>
71 #include <netinet/in.h>
72 #include <netinet/in_systm.h>
73 #include <netinet/ip.h>
74 #include <netinet/ip6.h>
75 #include <netinet/in_pcb.h>
76 #include <netinet/in_var.h>
77 #include <netinet/ip_var.h>
78 #include <netinet6/ip6_var.h>
79 #include <netinet6/in6_var.h>
81 #include <netinet/ip_icmp.h>
82 #include <netinet/icmp_var.h>
83 #include <netinet/sctp_pcb.h>
84 #include <netinet/sctp_header.h>
85 #include <netinet/sctp_var.h>
86 #include <netinet/sctp_output.h>
87 #include <netinet/sctp_uio.h>
88 #include <netinet/sctp_asconf.h>
89 #include <netinet/sctputil.h>
90 #include <netinet/sctp_indata.h>
91 #include <netinet/sctp_asconf.h>
94 #include <netinet6/ipsec.h>
95 #include <netproto/key/key.h>
101 #include <net/net_osdep.h>
103 #if defined(HAVE_NRL_INPCB) || defined(__FreeBSD__) || defined(__DragonFly__)
108 #define sotoin6pcb sotoinpcb
113 extern u_int32_t sctp_debug_on
;
114 #endif /* SCTP_DEBUG */
117 * sysctl tunable variables
119 int sctp_auto_asconf
= SCTP_DEFAULT_AUTO_ASCONF
;
120 int sctp_max_burst_default
= SCTP_DEF_MAX_BURST
;
121 int sctp_peer_chunk_oh
= sizeof(struct mbuf
);
122 int sctp_strict_init
= 1;
123 int sctp_no_csum_on_loopback
= 1;
124 unsigned int sctp_max_chunks_on_queue
= SCTP_ASOC_MAX_CHUNKS_ON_QUEUE
;
125 int sctp_sendspace
= (128 * 1024);
126 int sctp_recvspace
= 128 * (1024 +
128 sizeof(struct sockaddr_in6
)
130 sizeof(struct sockaddr_in
)
133 int sctp_strict_sacks
= 0;
135 int sctp_ecn_nonce
= 0;
137 unsigned int sctp_delayed_sack_time_default
= SCTP_RECV_MSEC
;
138 unsigned int sctp_heartbeat_interval_default
= SCTP_HB_DEFAULT_MSEC
;
139 unsigned int sctp_pmtu_raise_time_default
= SCTP_DEF_PMTU_RAISE_SEC
;
140 unsigned int sctp_shutdown_guard_time_default
= SCTP_DEF_MAX_SHUTDOWN_SEC
;
141 unsigned int sctp_secret_lifetime_default
= SCTP_DEFAULT_SECRET_LIFE_SEC
;
142 unsigned int sctp_rto_max_default
= SCTP_RTO_UPPER_BOUND
;
143 unsigned int sctp_rto_min_default
= SCTP_RTO_LOWER_BOUND
;
144 unsigned int sctp_rto_initial_default
= SCTP_RTO_INITIAL
;
145 unsigned int sctp_init_rto_max_default
= SCTP_RTO_UPPER_BOUND
;
146 unsigned int sctp_valid_cookie_life_default
= SCTP_DEFAULT_COOKIE_LIFE
;
147 unsigned int sctp_init_rtx_max_default
= SCTP_DEF_MAX_INIT
;
148 unsigned int sctp_assoc_rtx_max_default
= SCTP_DEF_MAX_SEND
;
149 unsigned int sctp_path_rtx_max_default
= SCTP_DEF_MAX_SEND
/2;
150 unsigned int sctp_nr_outgoing_streams_default
= SCTP_OSTREAM_INITIAL
;
156 #define nmbclusters nmbclust
158 /* Init the SCTP pcb in sctp_pcb.c */
164 if (nmbclusters
> SCTP_ASOC_MAX_CHUNKS_ON_QUEUE
)
165 sctp_max_chunks_on_queue
= nmbclusters
;
167 /* if (nmbclust > SCTP_ASOC_MAX_CHUNKS_ON_QUEUE)
168 sctp_max_chunks_on_queue = nmbclust; FIX ME */
169 sctp_max_chunks_on_queue
= nmbclust
* 2;
172 * Allow a user to take no more than 1/2 the number of clusters
173 * or the SB_MAX whichever is smaller for the send window.
175 sb_max_adj
= (u_long
)((u_quad_t
)(SB_MAX
) * MCLBYTES
/ (MSIZE
+ MCLBYTES
));
176 sctp_sendspace
= min((min(SB_MAX
, sb_max_adj
)),
178 ((nmbclusters
/2) * SCTP_DEFAULT_MAXSEGMENT
));
180 ((nmbclust
/2) * SCTP_DEFAULT_MAXSEGMENT
));
183 * Now for the recv window, should we take the same amount?
184 * or should I do 1/2 the SB_MAX instead in the SB_MAX min above.
185 * For now I will just copy.
187 sctp_recvspace
= sctp_sendspace
;
195 ip_2_ip6_hdr(struct ip6_hdr
*ip6
, struct ip
*ip
)
197 bzero(ip6
, sizeof(*ip6
));
199 ip6
->ip6_vfc
= IPV6_VERSION
;
200 ip6
->ip6_plen
= ip
->ip_len
;
201 ip6
->ip6_nxt
= ip
->ip_p
;
202 ip6
->ip6_hlim
= ip
->ip_ttl
;
203 ip6
->ip6_src
.s6_addr32
[2] = ip6
->ip6_dst
.s6_addr32
[2] =
205 ip6
->ip6_src
.s6_addr32
[3] = ip
->ip_src
.s_addr
;
206 ip6
->ip6_dst
.s6_addr32
[3] = ip
->ip_dst
.s_addr
;
211 sctp_split_chunks(struct sctp_association
*asoc
,
212 struct sctp_stream_out
*strm
,
213 struct sctp_tmit_chunk
*chk
)
215 struct sctp_tmit_chunk
*new_chk
;
217 /* First we need a chunk */
218 new_chk
= (struct sctp_tmit_chunk
*)SCTP_ZONE_GET(sctppcbinfo
.ipi_zone_chunk
);
219 if (new_chk
== NULL
) {
220 chk
->flags
|= CHUNK_FLAGS_FRAGMENT_OK
;
223 sctppcbinfo
.ipi_count_chunk
++;
224 sctppcbinfo
.ipi_gencnt_chunk
++;
228 new_chk
->data
= m_split(chk
->data
, (chk
->send_size
>>1), MB_DONTWAIT
);
229 if (new_chk
->data
== NULL
) {
231 chk
->flags
|= CHUNK_FLAGS_FRAGMENT_OK
;
232 SCTP_ZONE_FREE(sctppcbinfo
.ipi_zone_chunk
, new_chk
);
233 sctppcbinfo
.ipi_count_chunk
--;
234 if ((int)sctppcbinfo
.ipi_count_chunk
< 0) {
235 panic("Chunk count is negative");
237 sctppcbinfo
.ipi_gencnt_chunk
++;
241 /* Data is now split adjust sizes */
242 chk
->send_size
>>= 1;
243 new_chk
->send_size
>>= 1;
245 chk
->book_size
>>= 1;
246 new_chk
->book_size
>>= 1;
248 /* now adjust the marks */
249 chk
->rec
.data
.rcv_flags
|= SCTP_DATA_FIRST_FRAG
;
250 chk
->rec
.data
.rcv_flags
&= ~SCTP_DATA_LAST_FRAG
;
252 new_chk
->rec
.data
.rcv_flags
&= ~SCTP_DATA_FIRST_FRAG
;
253 new_chk
->rec
.data
.rcv_flags
|= SCTP_DATA_LAST_FRAG
;
255 /* Increase ref count if dest is set */
257 new_chk
->whoTo
->ref_count
++;
259 /* now drop it on the end of the list*/
260 asoc
->stream_queue_cnt
++;
261 TAILQ_INSERT_AFTER(&strm
->outqueue
, chk
, new_chk
, sctp_next
);
265 sctp_notify_mbuf(struct sctp_inpcb
*inp
,
266 struct sctp_tcb
*stcb
,
267 struct sctp_nets
*net
,
277 if ((inp
== NULL
) || (stcb
== NULL
) || (net
== NULL
) ||
278 (ip
== NULL
) || (sh
== NULL
)) {
280 SCTP_TCB_UNLOCK(stcb
);
283 /* First job is to verify the vtag matches what I would send */
284 if (ntohl(sh
->v_tag
) != (stcb
->asoc
.peer_vtag
)) {
285 SCTP_TCB_UNLOCK(stcb
);
288 icmph
= (struct icmp
*)((caddr_t
)ip
- (sizeof(struct icmp
) -
290 if (icmph
->icmp_type
!= ICMP_UNREACH
) {
291 /* We only care about unreachable */
292 SCTP_TCB_UNLOCK(stcb
);
295 if (icmph
->icmp_code
!= ICMP_UNREACH_NEEDFRAG
) {
296 /* not a unreachable message due to frag. */
297 SCTP_TCB_UNLOCK(stcb
);
301 nxtsz
= ntohs(icmph
->icmp_seq
);
304 * old type router that does not tell us what the next size
305 * mtu is. Rats we will have to guess (in a educated fashion
308 nxtsz
= find_next_best_mtu(totsz
);
311 /* Stop any PMTU timer */
312 sctp_timer_stop(SCTP_TIMER_TYPE_PATHMTURAISE
, inp
, stcb
, NULL
);
314 /* Adjust destination size limit */
315 if (net
->mtu
> nxtsz
) {
318 /* now what about the ep? */
319 if (stcb
->asoc
.smallest_mtu
> nxtsz
) {
320 struct sctp_tmit_chunk
*chk
, *nchk
;
321 struct sctp_stream_out
*strm
;
322 /* Adjust that too */
323 stcb
->asoc
.smallest_mtu
= nxtsz
;
324 /* now off to subtract IP_DF flag if needed */
326 TAILQ_FOREACH(chk
, &stcb
->asoc
.send_queue
, sctp_next
) {
327 if ((chk
->send_size
+IP_HDR_SIZE
) > nxtsz
) {
328 chk
->flags
|= CHUNK_FLAGS_FRAGMENT_OK
;
331 TAILQ_FOREACH(chk
, &stcb
->asoc
.sent_queue
, sctp_next
) {
332 if ((chk
->send_size
+IP_HDR_SIZE
) > nxtsz
) {
334 * For this guy we also mark for immediate
335 * resend since we sent to big of chunk
337 chk
->flags
|= CHUNK_FLAGS_FRAGMENT_OK
;
338 if (chk
->sent
!= SCTP_DATAGRAM_RESEND
) {
339 stcb
->asoc
.sent_queue_retran_cnt
++;
341 chk
->sent
= SCTP_DATAGRAM_RESEND
;
342 chk
->rec
.data
.doing_fast_retransmit
= 0;
344 /* Clear any time so NO RTT is being done */
346 stcb
->asoc
.total_flight
-= chk
->book_size
;
347 if (stcb
->asoc
.total_flight
< 0) {
348 stcb
->asoc
.total_flight
= 0;
350 stcb
->asoc
.total_flight_count
--;
351 if (stcb
->asoc
.total_flight_count
< 0) {
352 stcb
->asoc
.total_flight_count
= 0;
354 net
->flight_size
-= chk
->book_size
;
355 if (net
->flight_size
< 0) {
356 net
->flight_size
= 0;
360 TAILQ_FOREACH(strm
, &stcb
->asoc
.out_wheel
, next_spoke
) {
361 chk
= TAILQ_FIRST(&strm
->outqueue
);
363 nchk
= TAILQ_NEXT(chk
, sctp_next
);
364 if ((chk
->send_size
+SCTP_MED_OVERHEAD
) > nxtsz
) {
365 sctp_split_chunks(&stcb
->asoc
, strm
, chk
);
371 sctp_timer_start(SCTP_TIMER_TYPE_PATHMTURAISE
, inp
, stcb
, NULL
);
372 SCTP_TCB_UNLOCK(stcb
);
377 sctp_notify(struct sctp_inpcb
*inp
,
381 struct sctp_tcb
*stcb
,
382 struct sctp_nets
*net
)
385 if ((inp
== NULL
) || (stcb
== NULL
) || (net
== NULL
) ||
386 (sh
== NULL
) || (to
== NULL
)) {
388 if (sctp_debug_on
& SCTP_DEBUG_USRREQ1
) {
389 kprintf("sctp-notify, bad call\n");
391 #endif /* SCTP_DEBUG */
394 /* First job is to verify the vtag matches what I would send */
395 if (ntohl(sh
->v_tag
) != (stcb
->asoc
.peer_vtag
)) {
399 /* FIX ME FIX ME PROTOPT i.e. no SCTP should ALWAYS be an ABORT */
401 if ((error
== EHOSTUNREACH
) || /* Host is not reachable */
402 (error
== EHOSTDOWN
) || /* Host is down */
403 (error
== ECONNREFUSED
) || /* Host refused the connection, (not an abort?) */
404 (error
== ENOPROTOOPT
) /* SCTP is not present on host */
407 * Hmm reachablity problems we must examine closely.
408 * If its not reachable, we may have lost a network.
409 * Or if there is NO protocol at the other end named SCTP.
410 * well we consider it a OOTB abort.
412 if ((error
== EHOSTUNREACH
) || (error
== EHOSTDOWN
)) {
413 if (net
->dest_state
& SCTP_ADDR_REACHABLE
) {
414 /* Ok that destination is NOT reachable */
415 net
->dest_state
&= ~SCTP_ADDR_REACHABLE
;
416 net
->dest_state
|= SCTP_ADDR_NOT_REACHABLE
;
417 net
->error_count
= net
->failure_threshold
+ 1;
418 sctp_ulp_notify(SCTP_NOTIFY_INTERFACE_DOWN
,
419 stcb
, SCTP_FAILED_THRESHOLD
,
423 SCTP_TCB_UNLOCK(stcb
);
426 * Here the peer is either playing tricks on us,
427 * including an address that belongs to someone who
428 * does not support SCTP OR was a userland
429 * implementation that shutdown and now is dead. In
430 * either case treat it like a OOTB abort with no TCB
432 sctp_abort_notification(stcb
, SCTP_PEER_FAULTY
);
433 sctp_free_assoc(inp
, stcb
);
434 /* no need to unlock here, since the TCB is gone */
437 /* Send all others to the app */
438 if (inp
->sctp_socket
) {
439 SOCK_LOCK(inp
->sctp_socket
);
440 inp
->sctp_socket
->so_error
= error
;
441 sctp_sowwakeup(inp
, inp
->sctp_socket
);
442 SOCK_UNLOCK(inp
->sctp_socket
);
445 SCTP_TCB_UNLOCK(stcb
);
449 #if defined(__FreeBSD__) || defined(__APPLE__) || defined(__DragonFly__)
454 sctp_ctlinput(int cmd
, struct sockaddr
*sa
, void *vip
)
460 if (sa
->sa_family
!= AF_INET
||
461 ((struct sockaddr_in
*)sa
)->sin_addr
.s_addr
== INADDR_ANY
) {
462 #if defined(__FreeBSD__) || defined(__APPLE__) || defined(__DragonFly__)
469 if (PRC_IS_REDIRECT(cmd
)) {
471 } else if ((unsigned)cmd
>= PRC_NCMDS
|| inetctlerrmap
[cmd
] == 0) {
472 #if defined(__FreeBSD__) || defined(__APPLE__) || defined(__DragonFly__)
479 struct sctp_inpcb
*inp
;
480 struct sctp_tcb
*stcb
;
481 struct sctp_nets
*net
;
482 struct sockaddr_in to
, from
;
484 sh
= (struct sctphdr
*)((caddr_t
)ip
+ (ip
->ip_hl
<< 2));
485 bzero(&to
, sizeof(to
));
486 bzero(&from
, sizeof(from
));
487 from
.sin_family
= to
.sin_family
= AF_INET
;
488 from
.sin_len
= to
.sin_len
= sizeof(to
);
489 from
.sin_port
= sh
->src_port
;
490 from
.sin_addr
= ip
->ip_src
;
491 to
.sin_port
= sh
->dest_port
;
492 to
.sin_addr
= ip
->ip_dst
;
495 * 'to' holds the dest of the packet that failed to be sent.
496 * 'from' holds our local endpoint address.
497 * Thus we reverse the to and the from in the lookup.
500 stcb
= sctp_findassociation_addr_sa((struct sockaddr
*)&from
,
501 (struct sockaddr
*)&to
,
503 if (stcb
!= NULL
&& inp
&& (inp
->sctp_socket
!= NULL
)) {
504 if (cmd
!= PRC_MSGSIZE
) {
506 if (cmd
== PRC_HOSTDEAD
) {
509 cm
= inetctlerrmap
[cmd
];
511 sctp_notify(inp
, cm
, sh
,
512 (struct sockaddr
*)&to
, stcb
,
515 /* handle possible ICMP size messages */
516 sctp_notify_mbuf(inp
, stcb
, net
, ip
, sh
);
519 #if (defined(__FreeBSD__) && __FreeBSD_version < 500000) || defined(__DragonFly__)
520 /* XXX must be fixed for 5.x and higher, leave for 4.x */
521 if (PRC_IS_REDIRECT(cmd
) && inp
) {
522 in_rtchange((struct inpcb
*)inp
,
526 if ((stcb
== NULL
) && (inp
!= NULL
)) {
527 /* reduce ref-count */
529 SCTP_INP_DECR_REF(inp
);
530 SCTP_INP_WUNLOCK(inp
);
536 #if defined(__FreeBSD__) || defined(__APPLE__) || defined(__DragonFly__)
543 #if defined(__FreeBSD__) || defined(__DragonFly__)
545 sctp_getcred(SYSCTL_HANDLER_ARGS
)
547 struct sockaddr_in addrs
[2];
548 struct sctp_inpcb
*inp
;
549 struct sctp_nets
*net
;
550 struct sctp_tcb
*stcb
;
553 #if __FreeBSD_version >= 500000 || defined(__DragonFly__)
554 error
= suser(req
->td
);
556 error
= suser(req
->p
);
560 error
= SYSCTL_IN(req
, addrs
, sizeof(addrs
));
565 stcb
= sctp_findassociation_addr_sa(sintosa(&addrs
[0]),
568 if (stcb
== NULL
|| inp
== NULL
|| inp
->sctp_socket
== NULL
) {
569 if ((inp
!= NULL
) && (stcb
== NULL
)) {
570 /* reduce ref-count */
572 SCTP_INP_DECR_REF(inp
);
573 SCTP_INP_WUNLOCK(inp
);
578 error
= SYSCTL_OUT(req
, inp
->sctp_socket
->so_cred
, sizeof(struct ucred
));
579 SCTP_TCB_UNLOCK(stcb
);
585 SYSCTL_PROC(_net_inet_sctp
, OID_AUTO
, getcred
, CTLTYPE_OPAQUE
|CTLFLAG_RW
,
586 0, 0, sctp_getcred
, "S,ucred", "Get the ucred of a SCTP connection");
587 #endif /* #if defined(__FreeBSD__) || defined(__DragonFly__) */
592 #if defined(__FreeBSD__) || defined (__APPLE__) || defined(__DragonFly__)
594 SYSCTL_DECL(_net_inet
);
596 SYSCTL_NODE(_net_inet
, OID_AUTO
, sctp
, CTLFLAG_RD
, 0,
599 SYSCTL_INT(_net_inet_sctp
, OID_AUTO
, maxdgram
, CTLFLAG_RW
,
600 &sctp_sendspace
, 0, "Maximum outgoing SCTP buffer size");
602 SYSCTL_INT(_net_inet_sctp
, OID_AUTO
, recvspace
, CTLFLAG_RW
,
603 &sctp_recvspace
, 0, "Maximum incoming SCTP buffer size");
605 SYSCTL_INT(_net_inet_sctp
, OID_AUTO
, auto_asconf
, CTLFLAG_RW
,
606 &sctp_auto_asconf
, 0, "Enable SCTP Auto-ASCONF");
608 SYSCTL_INT(_net_inet_sctp
, OID_AUTO
, ecn_enable
, CTLFLAG_RW
,
609 &sctp_ecn
, 0, "Enable SCTP ECN");
611 SYSCTL_INT(_net_inet_sctp
, OID_AUTO
, ecn_nonce
, CTLFLAG_RW
,
612 &sctp_ecn_nonce
, 0, "Enable SCTP ECN Nonce");
614 SYSCTL_INT(_net_inet_sctp
, OID_AUTO
, strict_sacks
, CTLFLAG_RW
,
615 &sctp_strict_sacks
, 0, "Enable SCTP Strict SACK checking");
617 SYSCTL_INT(_net_inet_sctp
, OID_AUTO
, loopback_nocsum
, CTLFLAG_RW
,
618 &sctp_no_csum_on_loopback
, 0,
619 "Enable NO Csum on packets sent on loopback");
621 SYSCTL_INT(_net_inet_sctp
, OID_AUTO
, strict_init
, CTLFLAG_RW
,
622 &sctp_strict_init
, 0,
623 "Enable strict INIT/INIT-ACK singleton enforcement");
625 SYSCTL_INT(_net_inet_sctp
, OID_AUTO
, peer_chkoh
, CTLFLAG_RW
,
626 &sctp_peer_chunk_oh
, 0,
627 "Amount to debit peers rwnd per chunk sent");
629 SYSCTL_INT(_net_inet_sctp
, OID_AUTO
, maxburst
, CTLFLAG_RW
,
630 &sctp_max_burst_default
, 0,
631 "Default max burst for sctp endpoints");
633 SYSCTL_INT(_net_inet_sctp
, OID_AUTO
, maxchunks
, CTLFLAG_RW
,
634 &sctp_max_chunks_on_queue
, 0,
635 "Default max chunks on queue per asoc");
637 SYSCTL_UINT(_net_inet_sctp
, OID_AUTO
, delayed_sack_time
, CTLFLAG_RW
,
638 &sctp_delayed_sack_time_default
, 0,
639 "Default delayed SACK timer in msec");
641 SYSCTL_UINT(_net_inet_sctp
, OID_AUTO
, heartbeat_interval
, CTLFLAG_RW
,
642 &sctp_heartbeat_interval_default
, 0,
643 "Default heartbeat interval in msec");
645 SYSCTL_UINT(_net_inet_sctp
, OID_AUTO
, pmtu_raise_time
, CTLFLAG_RW
,
646 &sctp_pmtu_raise_time_default
, 0,
647 "Default PMTU raise timer in sec");
649 SYSCTL_UINT(_net_inet_sctp
, OID_AUTO
, shutdown_guard_time
, CTLFLAG_RW
,
650 &sctp_shutdown_guard_time_default
, 0,
651 "Default shutdown guard timer in sec");
653 SYSCTL_UINT(_net_inet_sctp
, OID_AUTO
, secret_lifetime
, CTLFLAG_RW
,
654 &sctp_secret_lifetime_default
, 0,
655 "Default secret lifetime in sec");
657 SYSCTL_UINT(_net_inet_sctp
, OID_AUTO
, rto_max
, CTLFLAG_RW
,
658 &sctp_rto_max_default
, 0,
659 "Default maximum retransmission timeout in msec");
661 SYSCTL_UINT(_net_inet_sctp
, OID_AUTO
, rto_min
, CTLFLAG_RW
,
662 &sctp_rto_min_default
, 0,
663 "Default minimum retransmission timeout in msec");
665 SYSCTL_UINT(_net_inet_sctp
, OID_AUTO
, rto_initial
, CTLFLAG_RW
,
666 &sctp_rto_initial_default
, 0,
667 "Default initial retransmission timeout in msec");
669 SYSCTL_UINT(_net_inet_sctp
, OID_AUTO
, init_rto_max
, CTLFLAG_RW
,
670 &sctp_init_rto_max_default
, 0,
671 "Default maximum retransmission timeout during association setup in msec");
673 SYSCTL_UINT(_net_inet_sctp
, OID_AUTO
, valid_cookie_life
, CTLFLAG_RW
,
674 &sctp_valid_cookie_life_default
, 0,
675 "Default cookie lifetime in sec");
677 SYSCTL_UINT(_net_inet_sctp
, OID_AUTO
, init_rtx_max
, CTLFLAG_RW
,
678 &sctp_init_rtx_max_default
, 0,
679 "Default maximum number of retransmission for INIT chunks");
681 SYSCTL_UINT(_net_inet_sctp
, OID_AUTO
, assoc_rtx_max
, CTLFLAG_RW
,
682 &sctp_assoc_rtx_max_default
, 0,
683 "Default maximum number of retransmissions per association");
685 SYSCTL_UINT(_net_inet_sctp
, OID_AUTO
, path_rtx_max
, CTLFLAG_RW
,
686 &sctp_path_rtx_max_default
, 0,
687 "Default maximum of retransmissions per path");
689 SYSCTL_UINT(_net_inet_sctp
, OID_AUTO
, nr_outgoing_streams
, CTLFLAG_RW
,
690 &sctp_nr_outgoing_streams_default
, 0,
691 "Default number of outgoing streams");
694 SYSCTL_INT(_net_inet_sctp
, OID_AUTO
, debug
, CTLFLAG_RW
,
695 &sctp_debug_on
, 0, "Configure debug output");
696 #endif /* SCTP_DEBUG */
700 sctp_abort(struct socket
*so
)
702 struct sctp_inpcb
*inp
;
704 inp
= (struct sctp_inpcb
*)so
->so_pcb
;
706 return EINVAL
; /* ??? possible? panic instead? */
709 sctp_inpcb_free(inp
, 1);
715 #if defined(__FreeBSD__) && __FreeBSD_version >= 500000
716 sctp_attach(struct socket
*so
, int proto
, struct thread
*p
)
717 #elif defined(__DragonFly__)
718 sctp_attach(struct socket
*so
, int proto
, struct pru_attach_info
*ai
)
720 sctp_attach(struct socket
*so
, int proto
, struct proc
*p
)
723 struct sctp_inpcb
*inp
;
724 struct inpcb
*ip_inp
;
728 inp
= (struct sctp_inpcb
*)so
->so_pcb
;
733 error
= soreserve(so
, sctp_sendspace
, sctp_recvspace
, NULL
);
738 error
= sctp_inpcb_alloc(so
);
743 inp
= (struct sctp_inpcb
*)so
->so_pcb
;
746 inp
->sctp_flags
&= ~SCTP_PCB_FLAGS_BOUND_V6
; /* I'm not v6! */
747 ip_inp
= &inp
->ip_inp
.inp
;
748 #if defined(__FreeBSD__) || defined(__APPLE__) || defined(__DragonFly__)
749 ip_inp
->inp_vflag
|= INP_IPV4
;
750 ip_inp
->inp_ip_ttl
= ip_defttl
;
752 inp
->inp_vflag
|= INP_IPV4
;
753 inp
->inp_ip_ttl
= ip_defttl
;
757 #if !(defined(__OpenBSD__) || defined(__APPLE__))
758 error
= ipsec_init_policy(so
, &ip_inp
->inp_sp
);
760 sctp_inpcb_free(inp
, 1);
765 SCTP_INP_WUNLOCK(inp
);
766 #if defined(__NetBSD__)
767 so
->so_send
= sctp_sosend
;
774 #if (defined(__FreeBSD__) && __FreeBSD_version >= 500000) || defined(__DragonFly__)
775 sctp_bind(struct socket
*so
, struct sockaddr
*addr
, struct thread
*p
)
777 #elif defined(__FreeBSD__) || defined(__APPLE__)
778 sctp_bind(struct socket
*so
, struct sockaddr
*addr
, struct proc
*p
)
781 sctp_bind(struct socket
*so
, struct mbuf
*nam
, struct proc
*p
)
783 struct sockaddr
*addr
= nam
? mtod(nam
, struct sockaddr
*) : NULL
;
785 struct sctp_inpcb
*inp
;
789 if (addr
&& addr
->sa_family
!= AF_INET
)
790 /* must be a v4 address! */
794 inp
= (struct sctp_inpcb
*)so
->so_pcb
;
799 error
= sctp_inpcb_bind(so
, addr
, p
);
806 sctp_detach(struct socket
*so
)
808 struct sctp_inpcb
*inp
;
810 inp
= (struct sctp_inpcb
*)so
->so_pcb
;
814 if (((so
->so_options
& SO_LINGER
) && (so
->so_linger
== 0)) ||
815 (so
->so_rcv
.ssb_cc
> 0)) {
816 sctp_inpcb_free(inp
, 1);
818 sctp_inpcb_free(inp
, 0);
825 #if (defined(__FreeBSD__) && __FreeBSD_version >= 500000) || defined(__DragonFly__)
826 sctp_send(struct socket
*so
, int flags
, struct mbuf
*m
, struct sockaddr
*addr
,
827 struct mbuf
*control
, struct thread
*p
);
829 sctp_send(struct socket
*so
, int flags
, struct mbuf
*m
, struct sockaddr
*addr
,
830 struct mbuf
*control
, struct proc
*p
);
834 #if (defined(__FreeBSD__) && __FreeBSD_version >= 500000) || defined(__DragonFly__)
835 sctp_send(struct socket
*so
, int flags
, struct mbuf
*m
, struct sockaddr
*addr
,
836 struct mbuf
*control
, struct thread
*p
)
839 sctp_send(struct socket
*so
, int flags
, struct mbuf
*m
, struct sockaddr
*addr
,
840 struct mbuf
*control
, struct proc
*p
)
843 struct sctp_inpcb
*inp
;
845 inp
= (struct sctp_inpcb
*)so
->so_pcb
;
848 sctp_m_freem(control
);
854 /* Got to have an to address if we are NOT a connected socket */
855 if ((addr
== NULL
) &&
856 ((inp
->sctp_flags
& SCTP_PCB_FLAGS_CONNECTED
) ||
857 (inp
->sctp_flags
& SCTP_PCB_FLAGS_TCPTYPE
))
860 } else if (addr
== NULL
) {
861 error
= EDESTADDRREQ
;
864 sctp_m_freem(control
);
870 if (addr
->sa_family
!= AF_INET
) {
871 /* must be a v4 address! */
874 sctp_m_freem(control
);
877 error
= EDESTADDRREQ
;
882 /* now what about control */
885 kprintf("huh? control set?\n");
886 sctp_m_freem(inp
->control
);
889 inp
->control
= control
;
891 /* add it in possibly */
892 if ((inp
->pkt
) && (inp
->pkt
->m_flags
& M_PKTHDR
)) {
898 for (x
=m
;x
;x
= x
->m_next
) {
901 inp
->pkt
->m_pkthdr
.len
+= c_len
;
905 inp
->pkt_last
->m_next
= m
;
908 inp
->pkt_last
= inp
->pkt
= m
;
911 #if defined (__FreeBSD__) || defined(__APPLE__) || defined(__DragonFly__)
912 /* FreeBSD uses a flag passed */
913 ((flags
& PRUS_MORETOCOME
) == 0)
914 #elif defined( __NetBSD__)
915 /* NetBSD uses the so_state field */
916 ((so
->so_state
& SS_MORETOCOME
) == 0)
918 1 /* Open BSD does not have any "more to come" indication */
922 * note with the current version this code will only be used
923 * by OpenBSD-- NetBSD, FreeBSD, and MacOS have methods for
924 * re-defining sosend to use the sctp_sosend. One can
925 * optionally switch back to this code (by changing back the
926 * definitions) but this is not advisable.
929 ret
= sctp_output(inp
, inp
->pkt
, addr
, inp
->control
, p
, flags
);
939 sctp_disconnect(struct socket
*so
)
941 struct sctp_inpcb
*inp
;
944 inp
= (struct sctp_inpcb
*)so
->so_pcb
;
950 if (inp
->sctp_flags
& SCTP_PCB_FLAGS_TCPTYPE
) {
951 if (LIST_EMPTY(&inp
->sctp_asoc_list
)) {
954 SCTP_INP_RUNLOCK(inp
);
957 int some_on_streamwheel
= 0;
958 struct sctp_association
*asoc
;
959 struct sctp_tcb
*stcb
;
961 stcb
= LIST_FIRST(&inp
->sctp_asoc_list
);
964 SCTP_INP_RUNLOCK(inp
);
969 if (((so
->so_options
& SO_LINGER
) &&
970 (so
->so_linger
== 0)) ||
971 (so
->so_rcv
.ssb_cc
> 0)) {
972 if (SCTP_GET_STATE(asoc
) !=
973 SCTP_STATE_COOKIE_WAIT
) {
974 /* Left with Data unread */
977 MGET(err
, MB_DONTWAIT
, MT_DATA
);
979 /* Fill in the user initiated abort */
980 struct sctp_paramhdr
*ph
;
981 ph
= mtod(err
, struct sctp_paramhdr
*);
982 err
->m_len
= sizeof(struct sctp_paramhdr
);
983 ph
->param_type
= htons(SCTP_CAUSE_USER_INITIATED_ABT
);
984 ph
->param_length
= htons(err
->m_len
);
986 sctp_send_abort_tcb(stcb
, err
);
988 SCTP_INP_RUNLOCK(inp
);
989 sctp_free_assoc(inp
, stcb
);
990 /* No unlock tcb assoc is gone */
994 if (!TAILQ_EMPTY(&asoc
->out_wheel
)) {
995 /* Check to see if some data queued */
996 struct sctp_stream_out
*outs
;
997 TAILQ_FOREACH(outs
, &asoc
->out_wheel
,
999 if (!TAILQ_EMPTY(&outs
->outqueue
)) {
1000 some_on_streamwheel
= 1;
1006 if (TAILQ_EMPTY(&asoc
->send_queue
) &&
1007 TAILQ_EMPTY(&asoc
->sent_queue
) &&
1008 (some_on_streamwheel
== 0)) {
1009 /* there is nothing queued to send, so done */
1010 if ((SCTP_GET_STATE(asoc
) !=
1011 SCTP_STATE_SHUTDOWN_SENT
) &&
1012 (SCTP_GET_STATE(asoc
) !=
1013 SCTP_STATE_SHUTDOWN_ACK_SENT
)) {
1014 /* only send SHUTDOWN 1st time thru */
1016 if (sctp_debug_on
& SCTP_DEBUG_OUTPUT4
) {
1017 kprintf("%s:%d sends a shutdown\n",
1023 sctp_send_shutdown(stcb
,
1024 stcb
->asoc
.primary_destination
);
1025 sctp_chunk_output(stcb
->sctp_ep
, stcb
, 1);
1026 asoc
->state
= SCTP_STATE_SHUTDOWN_SENT
;
1027 sctp_timer_start(SCTP_TIMER_TYPE_SHUTDOWN
,
1028 stcb
->sctp_ep
, stcb
,
1029 asoc
->primary_destination
);
1030 sctp_timer_start(SCTP_TIMER_TYPE_SHUTDOWNGUARD
,
1031 stcb
->sctp_ep
, stcb
,
1032 asoc
->primary_destination
);
1036 * we still got (or just got) data to send,
1037 * so set SHUTDOWN_PENDING
1040 * XXX sockets draft says that MSG_EOF should
1041 * be sent with no data.
1042 * currently, we will allow user data to be
1043 * sent first and move to SHUTDOWN-PENDING
1045 asoc
->state
|= SCTP_STATE_SHUTDOWN_PENDING
;
1047 SCTP_TCB_UNLOCK(stcb
);
1048 SCTP_INP_RUNLOCK(inp
);
1054 /* UDP model does not support this */
1055 SCTP_INP_RUNLOCK(inp
);
1062 sctp_shutdown(struct socket
*so
)
1064 struct sctp_inpcb
*inp
;
1067 inp
= (struct sctp_inpcb
*)so
->so_pcb
;
1072 SCTP_INP_RLOCK(inp
);
1073 /* For UDP model this is a invalid call */
1074 if (inp
->sctp_flags
& SCTP_PCB_FLAGS_UDPTYPE
) {
1075 /* Restore the flags that the soshutdown took away. */
1076 #if defined(__FreeBSD__) && __FreeBSD_version >= 502115
1077 so
->so_rcv
.sb_state
&= ~SBS_CANTRCVMORE
;
1079 so
->so_state
&= ~SS_CANTRCVMORE
;
1081 /* This proc will wakeup for read and do nothing (I hope) */
1083 SCTP_INP_RUNLOCK(inp
);
1084 return (EOPNOTSUPP
);
1087 * Ok if we reach here its the TCP model and it is either a SHUT_WR
1088 * or SHUT_RDWR. This means we put the shutdown flag against it.
1091 int some_on_streamwheel
= 0;
1092 struct sctp_tcb
*stcb
;
1093 struct sctp_association
*asoc
;
1096 stcb
= LIST_FIRST(&inp
->sctp_asoc_list
);
1099 * Ok we hit the case that the shutdown call was made
1100 * after an abort or something. Nothing to do now.
1105 SCTP_TCB_LOCK(stcb
);
1108 if (!TAILQ_EMPTY(&asoc
->out_wheel
)) {
1109 /* Check to see if some data queued */
1110 struct sctp_stream_out
*outs
;
1111 TAILQ_FOREACH(outs
, &asoc
->out_wheel
, next_spoke
) {
1112 if (!TAILQ_EMPTY(&outs
->outqueue
)) {
1113 some_on_streamwheel
= 1;
1118 if (TAILQ_EMPTY(&asoc
->send_queue
) &&
1119 TAILQ_EMPTY(&asoc
->sent_queue
) &&
1120 (some_on_streamwheel
== 0)) {
1121 /* there is nothing queued to send, so I'm done... */
1122 if (SCTP_GET_STATE(asoc
) != SCTP_STATE_SHUTDOWN_SENT
) {
1123 /* only send SHUTDOWN the first time through */
1125 if (sctp_debug_on
& SCTP_DEBUG_OUTPUT4
) {
1126 kprintf("%s:%d sends a shutdown\n",
1132 sctp_send_shutdown(stcb
,
1133 stcb
->asoc
.primary_destination
);
1134 sctp_chunk_output(stcb
->sctp_ep
, stcb
, 1);
1135 asoc
->state
= SCTP_STATE_SHUTDOWN_SENT
;
1136 sctp_timer_start(SCTP_TIMER_TYPE_SHUTDOWN
,
1137 stcb
->sctp_ep
, stcb
,
1138 asoc
->primary_destination
);
1139 sctp_timer_start(SCTP_TIMER_TYPE_SHUTDOWNGUARD
,
1140 stcb
->sctp_ep
, stcb
,
1141 asoc
->primary_destination
);
1145 * we still got (or just got) data to send, so
1146 * set SHUTDOWN_PENDING
1148 asoc
->state
|= SCTP_STATE_SHUTDOWN_PENDING
;
1150 SCTP_TCB_UNLOCK(stcb
);
1152 SCTP_INP_RUNLOCK(inp
);
1158 * copies a "user" presentable address and removes embedded scope, etc.
1159 * returns 0 on success, 1 on error
1162 sctp_fill_user_address(struct sockaddr_storage
*ss
, struct sockaddr
*sa
)
1164 struct sockaddr_in6 lsa6
;
1165 sa
= (struct sockaddr
*)sctp_recover_scope((struct sockaddr_in6
*)sa
,
1167 memcpy(ss
, sa
, sa
->sa_len
);
1172 #if defined(__NetBSD__) || defined(__OpenBSD__)
1174 * On NetBSD and OpenBSD in6_sin_2_v4mapsin6() not used and not exported,
1175 * so we have to export it here.
1177 void in6_sin_2_v4mapsin6(struct sockaddr_in
*sin
, struct sockaddr_in6
*sin6
);
1181 sctp_fill_up_addresses(struct sctp_inpcb
*inp
,
1182 struct sctp_tcb
*stcb
,
1184 struct sockaddr_storage
*sas
)
1187 int loopback_scope
, ipv4_local_scope
, local_scope
, site_scope
, actual
;
1188 int ipv4_addr_legal
, ipv6_addr_legal
;
1194 /* Turn on all the appropriate scope */
1195 loopback_scope
= stcb
->asoc
.loopback_scope
;
1196 ipv4_local_scope
= stcb
->asoc
.ipv4_local_scope
;
1197 local_scope
= stcb
->asoc
.local_scope
;
1198 site_scope
= stcb
->asoc
.site_scope
;
1200 /* Turn on ALL scope, since we look at the EP */
1201 loopback_scope
= ipv4_local_scope
= local_scope
=
1204 ipv4_addr_legal
= ipv6_addr_legal
= 0;
1205 if (inp
->sctp_flags
& SCTP_PCB_FLAGS_BOUND_V6
) {
1206 ipv6_addr_legal
= 1;
1208 #if defined(__OpenBSD__)
1209 (0) /* we always do dual bind */
1210 #elif defined (__NetBSD__)
1211 (((struct in6pcb
*)inp
)->in6p_flags
& IN6P_IPV6_V6ONLY
)
1213 (((struct in6pcb
*)inp
)->inp_flags
& IN6P_IPV6_V6ONLY
)
1216 ipv4_addr_legal
= 1;
1219 ipv4_addr_legal
= 1;
1222 if (inp
->sctp_flags
& SCTP_PCB_FLAGS_BOUNDALL
) {
1223 TAILQ_FOREACH(ifn
, &ifnet
, if_list
) {
1224 struct ifaddr_container
*ifac
;
1226 if ((loopback_scope
== 0) &&
1227 (ifn
->if_type
== IFT_LOOP
)) {
1228 /* Skip loopback if loopback_scope not set */
1231 TAILQ_FOREACH(ifac
, &ifn
->if_addrheads
[mycpuid
],
1233 struct ifaddr
*ifa
= ifac
->ifa
;
1237 * For the BOUND-ALL case, the list
1238 * associated with a TCB is Always
1239 * considered a reverse list.. i.e.
1240 * it lists addresses that are NOT
1241 * part of the association. If this
1242 * is one of those we must skip it.
1244 if (sctp_is_addr_restricted(stcb
,
1249 if ((ifa
->ifa_addr
->sa_family
== AF_INET
) &&
1250 (ipv4_addr_legal
)) {
1251 struct sockaddr_in
*sin
;
1252 sin
= (struct sockaddr_in
*)ifa
->ifa_addr
;
1253 if (sin
->sin_addr
.s_addr
== 0) {
1254 /* we skip unspecifed addresses */
1257 if ((ipv4_local_scope
== 0) &&
1258 (IN4_ISPRIVATE_ADDRESS(&sin
->sin_addr
))) {
1261 if (inp
->sctp_flags
& SCTP_PCB_FLAGS_NEEDS_MAPPED_V4
) {
1262 in6_sin_2_v4mapsin6(sin
, (struct sockaddr_in6
*)sas
);
1263 ((struct sockaddr_in6
*)sas
)->sin6_port
= inp
->sctp_lport
;
1264 sas
= (struct sockaddr_storage
*)((caddr_t
)sas
+ sizeof(struct sockaddr_in6
));
1265 actual
+= sizeof(sizeof(struct sockaddr_in6
));
1267 memcpy(sas
, sin
, sizeof(*sin
));
1268 ((struct sockaddr_in
*)sas
)->sin_port
= inp
->sctp_lport
;
1269 sas
= (struct sockaddr_storage
*)((caddr_t
)sas
+ sizeof(*sin
));
1270 actual
+= sizeof(*sin
);
1272 if (actual
>= limit
) {
1275 } else if ((ifa
->ifa_addr
->sa_family
== AF_INET6
) &&
1276 (ipv6_addr_legal
)) {
1277 struct sockaddr_in6
*sin6
, lsa6
;
1278 sin6
= (struct sockaddr_in6
*)ifa
->ifa_addr
;
1279 if (IN6_IS_ADDR_UNSPECIFIED(&sin6
->sin6_addr
)) {
1280 /* we skip unspecifed addresses */
1283 if (IN6_IS_ADDR_LINKLOCAL(&sin6
->sin6_addr
)) {
1284 if (local_scope
== 0)
1286 if (sin6
->sin6_scope_id
== 0) {
1288 if (in6_recoverscope(&lsa6
,
1291 /* bad link local address */
1296 if ((site_scope
== 0) &&
1297 (IN6_IS_ADDR_SITELOCAL(&sin6
->sin6_addr
))) {
1300 memcpy(sas
, sin6
, sizeof(*sin6
));
1301 ((struct sockaddr_in6
*)sas
)->sin6_port
= inp
->sctp_lport
;
1302 sas
= (struct sockaddr_storage
*)((caddr_t
)sas
+ sizeof(*sin6
));
1303 actual
+= sizeof(*sin6
);
1304 if (actual
>= limit
) {
1311 struct sctp_laddr
*laddr
;
1313 * If we have a TCB and we do NOT support ASCONF (it's
1314 * turned off or otherwise) then the list is always the
1315 * true list of addresses (the else case below). Otherwise
1316 * the list on the association is a list of addresses that
1317 * are NOT part of the association.
1319 if (inp
->sctp_flags
& SCTP_PCB_FLAGS_DO_ASCONF
) {
1320 /* The list is a NEGATIVE list */
1321 LIST_FOREACH(laddr
, &inp
->sctp_addr_list
, sctp_nxt_addr
) {
1323 if (sctp_is_addr_restricted(stcb
, laddr
->ifa
->ifa_addr
)) {
1327 if (sctp_fill_user_address(sas
, laddr
->ifa
->ifa_addr
))
1330 ((struct sockaddr_in6
*)sas
)->sin6_port
= inp
->sctp_lport
;
1331 sas
= (struct sockaddr_storage
*)((caddr_t
)sas
+
1332 laddr
->ifa
->ifa_addr
->sa_len
);
1333 actual
+= laddr
->ifa
->ifa_addr
->sa_len
;
1334 if (actual
>= limit
) {
1339 /* The list is a positive list if present */
1341 /* Must use the specific association list */
1342 LIST_FOREACH(laddr
, &stcb
->asoc
.sctp_local_addr_list
,
1344 if (sctp_fill_user_address(sas
,
1345 laddr
->ifa
->ifa_addr
))
1347 ((struct sockaddr_in6
*)sas
)->sin6_port
= inp
->sctp_lport
;
1348 sas
= (struct sockaddr_storage
*)((caddr_t
)sas
+
1349 laddr
->ifa
->ifa_addr
->sa_len
);
1350 actual
+= laddr
->ifa
->ifa_addr
->sa_len
;
1351 if (actual
>= limit
) {
1356 /* No endpoint so use the endpoints individual list */
1357 LIST_FOREACH(laddr
, &inp
->sctp_addr_list
,
1359 if (sctp_fill_user_address(sas
,
1360 laddr
->ifa
->ifa_addr
))
1362 ((struct sockaddr_in6
*)sas
)->sin6_port
= inp
->sctp_lport
;
1363 sas
= (struct sockaddr_storage
*)((caddr_t
)sas
+
1364 laddr
->ifa
->ifa_addr
->sa_len
);
1365 actual
+= laddr
->ifa
->ifa_addr
->sa_len
;
1366 if (actual
>= limit
) {
1377 sctp_count_max_addresses(struct sctp_inpcb
*inp
)
1381 * In both sub-set bound an bound_all cases we return the MAXIMUM
1382 * number of addresses that you COULD get. In reality the sub-set
1383 * bound may have an exclusion list for a given TCB OR in the
1384 * bound-all case a TCB may NOT include the loopback or other
1385 * addresses as well.
1387 if (inp
->sctp_flags
& SCTP_PCB_FLAGS_BOUNDALL
) {
1390 TAILQ_FOREACH(ifn
, &ifnet
, if_list
) {
1391 struct ifaddr_container
*ifac
;
1393 TAILQ_FOREACH(ifac
, &ifn
->if_addrheads
[mycpuid
], ifa_link
) {
1394 struct ifaddr
*ifa
= ifac
->ifa
;
1396 /* Count them if they are the right type */
1397 if (ifa
->ifa_addr
->sa_family
== AF_INET
) {
1398 if (inp
->sctp_flags
& SCTP_PCB_FLAGS_NEEDS_MAPPED_V4
)
1399 cnt
+= sizeof(struct sockaddr_in6
);
1401 cnt
+= sizeof(struct sockaddr_in
);
1403 } else if (ifa
->ifa_addr
->sa_family
== AF_INET6
)
1404 cnt
+= sizeof(struct sockaddr_in6
);
1408 struct sctp_laddr
*laddr
;
1409 LIST_FOREACH(laddr
, &inp
->sctp_addr_list
, sctp_nxt_addr
) {
1410 if (laddr
->ifa
->ifa_addr
->sa_family
== AF_INET
) {
1411 if (inp
->sctp_flags
& SCTP_PCB_FLAGS_NEEDS_MAPPED_V4
)
1412 cnt
+= sizeof(struct sockaddr_in6
);
1414 cnt
+= sizeof(struct sockaddr_in
);
1416 } else if (laddr
->ifa
->ifa_addr
->sa_family
== AF_INET6
)
1417 cnt
+= sizeof(struct sockaddr_in6
);
1424 sctp_do_connect_x(struct socket
*so
,
1425 struct sctp_inpcb
*inp
,
1427 #if (defined(__FreeBSD__) && __FreeBSD_version >= 500000) || defined(__DragonFly__)
1436 struct sctp_tcb
*stcb
= NULL
;
1437 struct sockaddr
*sa
;
1438 int num_v6
=0, num_v4
=0, *totaddrp
, totaddr
, i
, incr
, at
;
1440 if (sctp_debug_on
& SCTP_DEBUG_PCB1
) {
1441 kprintf("Connectx called\n");
1443 #endif /* SCTP_DEBUG */
1446 if ((inp
->sctp_flags
& SCTP_PCB_FLAGS_TCPTYPE
) &&
1447 (inp
->sctp_flags
& SCTP_PCB_FLAGS_CONNECTED
)) {
1448 /* We are already connected AND the TCP model */
1450 return (EADDRINUSE
);
1452 if (inp
->sctp_flags
& SCTP_PCB_FLAGS_CONNECTED
) {
1453 SCTP_INP_RLOCK(inp
);
1454 stcb
= LIST_FIRST(&inp
->sctp_asoc_list
);
1455 SCTP_INP_RUNLOCK(inp
);
1462 SCTP_ASOC_CREATE_LOCK(inp
);
1463 if ((inp
->sctp_flags
& SCTP_PCB_FLAGS_SOCKET_GONE
) ||
1464 (inp
->sctp_flags
& SCTP_PCB_FLAGS_SOCKET_GONE
)) {
1465 SCTP_ASOC_CREATE_UNLOCK(inp
);
1470 totaddrp
= mtod(m
, int *);
1471 totaddr
= *totaddrp
;
1472 sa
= (struct sockaddr
*)(totaddrp
+ 1);
1474 /* account and validate addresses */
1475 SCTP_INP_WLOCK(inp
);
1476 SCTP_INP_INCR_REF(inp
);
1477 SCTP_INP_WUNLOCK(inp
);
1478 for (i
= 0; i
< totaddr
; i
++) {
1479 if (sa
->sa_family
== AF_INET
) {
1481 incr
= sizeof(struct sockaddr_in
);
1482 } else if (sa
->sa_family
== AF_INET6
) {
1483 struct sockaddr_in6
*sin6
;
1484 sin6
= (struct sockaddr_in6
*)sa
;
1485 if (IN6_IS_ADDR_V4MAPPED(&sin6
->sin6_addr
)) {
1486 /* Must be non-mapped for connectx */
1487 SCTP_ASOC_CREATE_UNLOCK(inp
);
1492 incr
= sizeof(struct sockaddr_in6
);
1497 stcb
= sctp_findassociation_ep_addr(&inp
, sa
, NULL
, NULL
, NULL
);
1499 /* Already have or am bring up an association */
1500 SCTP_ASOC_CREATE_UNLOCK(inp
);
1501 SCTP_TCB_UNLOCK(stcb
);
1505 if ((at
+ incr
) > m
->m_len
) {
1509 sa
= (struct sockaddr
*)((caddr_t
)sa
+ incr
);
1511 sa
= (struct sockaddr
*)(totaddrp
+ 1);
1512 SCTP_INP_WLOCK(inp
);
1513 SCTP_INP_DECR_REF(inp
);
1514 SCTP_INP_WUNLOCK(inp
);
1516 if (((inp
->sctp_flags
& SCTP_PCB_FLAGS_BOUND_V6
) == 0) &&
1519 SCTP_INP_WUNLOCK(inp
);
1520 SCTP_ASOC_CREATE_UNLOCK(inp
);
1523 if ((inp
->sctp_flags
& SCTP_PCB_FLAGS_BOUND_V6
) &&
1525 struct in6pcb
*inp6
;
1526 inp6
= (struct in6pcb
*)inp
;
1528 #if defined(__OpenBSD__)
1529 (0) /* we always do dual bind */
1530 #elif defined (__NetBSD__)
1531 (inp6
->in6p_flags
& IN6P_IPV6_V6ONLY
)
1533 (inp6
->inp_flags
& IN6P_IPV6_V6ONLY
)
1537 * if IPV6_V6ONLY flag, ignore connections
1538 * destined to a v4 addr or v4-mapped addr
1540 SCTP_INP_WUNLOCK(inp
);
1541 SCTP_ASOC_CREATE_UNLOCK(inp
);
1547 if ((inp
->sctp_flags
& SCTP_PCB_FLAGS_UNBOUND
) ==
1548 SCTP_PCB_FLAGS_UNBOUND
) {
1549 /* Bind a ephemeral port */
1550 SCTP_INP_WUNLOCK(inp
);
1551 error
= sctp_inpcb_bind(so
, NULL
, p
);
1553 SCTP_ASOC_CREATE_UNLOCK(inp
);
1558 SCTP_INP_WUNLOCK(inp
);
1560 /* We are GOOD to go */
1561 stcb
= sctp_aloc_assoc(inp
, sa
, 1, &error
, 0);
1563 /* Gak! no memory */
1564 SCTP_ASOC_CREATE_UNLOCK(inp
);
1568 /* move to second address */
1569 if (sa
->sa_family
== AF_INET
)
1570 sa
= (struct sockaddr
*)((caddr_t
)sa
+ sizeof(struct sockaddr_in
));
1572 sa
= (struct sockaddr
*)((caddr_t
)sa
+ sizeof(struct sockaddr_in6
));
1574 for (i
= 1; i
< totaddr
; i
++) {
1575 if (sa
->sa_family
== AF_INET
) {
1576 incr
= sizeof(struct sockaddr_in
);
1577 if (sctp_add_remote_addr(stcb
, sa
, 0, 8)) {
1578 /* assoc gone no un-lock */
1579 sctp_free_assoc(inp
, stcb
);
1580 SCTP_ASOC_CREATE_UNLOCK(inp
);
1585 } else if (sa
->sa_family
== AF_INET6
) {
1586 incr
= sizeof(struct sockaddr_in6
);
1587 if (sctp_add_remote_addr(stcb
, sa
, 0, 8)) {
1588 /* assoc gone no un-lock */
1589 sctp_free_assoc(inp
, stcb
);
1590 SCTP_ASOC_CREATE_UNLOCK(inp
);
1595 sa
= (struct sockaddr
*)((caddr_t
)sa
+ incr
);
1597 stcb
->asoc
.state
= SCTP_STATE_COOKIE_WAIT
;
1599 /* doing delayed connection */
1600 stcb
->asoc
.delayed_connection
= 1;
1601 sctp_timer_start(SCTP_TIMER_TYPE_INIT
, inp
, stcb
, stcb
->asoc
.primary_destination
);
1603 SCTP_GETTIME_TIMEVAL(&stcb
->asoc
.time_entered
);
1604 sctp_send_initiate(inp
, stcb
);
1606 SCTP_TCB_UNLOCK(stcb
);
1607 if (stcb
->sctp_ep
->sctp_flags
& SCTP_PCB_FLAGS_TCPTYPE
) {
1608 stcb
->sctp_ep
->sctp_flags
|= SCTP_PCB_FLAGS_CONNECTED
;
1609 /* Set the connected flag so we can queue data */
1612 SCTP_ASOC_CREATE_UNLOCK(inp
);
1619 sctp_optsget(struct socket
*so
,
1622 #if (defined(__FreeBSD__) && __FreeBSD_version >= 500000) || defined(__DragonFly__)
1629 struct sctp_inpcb
*inp
;
1631 int error
, optval
=0;
1632 struct sctp_tcb
*stcb
= NULL
;
1634 inp
= (struct sctp_inpcb
*)so
->so_pcb
;
1641 if (sctp_debug_on
& SCTP_DEBUG_USRREQ1
) {
1642 kprintf("optsget:MP is NULL EINVAL\n");
1644 #endif /* SCTP_DEBUG */
1649 /* Got to have a mbuf */
1651 if (sctp_debug_on
& SCTP_DEBUG_USRREQ1
) {
1652 kprintf("Huh no mbuf\n");
1654 #endif /* SCTP_DEBUG */
1658 if (sctp_debug_on
& SCTP_DEBUG_USRREQ2
) {
1659 kprintf("optsget opt:%lxx sz:%u\n", (unsigned long)opt
,
1662 #endif /* SCTP_DEBUG */
1666 case SCTP_AUTOCLOSE
:
1667 case SCTP_AUTO_ASCONF
:
1668 case SCTP_DISABLE_FRAGMENTS
:
1669 case SCTP_I_WANT_MAPPED_V4_ADDR
:
1671 if (sctp_debug_on
& SCTP_DEBUG_USRREQ2
) {
1672 kprintf("other stuff\n");
1674 #endif /* SCTP_DEBUG */
1675 SCTP_INP_RLOCK(inp
);
1677 case SCTP_DISABLE_FRAGMENTS
:
1678 optval
= inp
->sctp_flags
& SCTP_PCB_FLAGS_NO_FRAGMENT
;
1680 case SCTP_I_WANT_MAPPED_V4_ADDR
:
1681 optval
= inp
->sctp_flags
& SCTP_PCB_FLAGS_NEEDS_MAPPED_V4
;
1683 case SCTP_AUTO_ASCONF
:
1684 optval
= inp
->sctp_flags
& SCTP_PCB_FLAGS_AUTO_ASCONF
;
1687 optval
= inp
->sctp_flags
& SCTP_PCB_FLAGS_NODELAY
;
1689 case SCTP_AUTOCLOSE
:
1690 if ((inp
->sctp_flags
& SCTP_PCB_FLAGS_AUTOCLOSE
) ==
1691 SCTP_PCB_FLAGS_AUTOCLOSE
)
1692 optval
= inp
->sctp_ep
.auto_close_time
;
1698 error
= ENOPROTOOPT
;
1699 } /* end switch (sopt->sopt_name) */
1700 if (opt
!= SCTP_AUTOCLOSE
) {
1701 /* make it an "on/off" value */
1702 optval
= (optval
!= 0);
1704 if ((size_t)m
->m_len
< sizeof(int)) {
1707 SCTP_INP_RUNLOCK(inp
);
1709 /* return the option value */
1710 *mtod(m
, int *) = optval
;
1711 m
->m_len
= sizeof(optval
);
1714 case SCTP_GET_ASOC_ID_LIST
:
1716 struct sctp_assoc_ids
*ids
;
1720 if ((size_t)m
->m_len
< sizeof(struct sctp_assoc_ids
)) {
1724 ids
= mtod(m
, struct sctp_assoc_ids
*);
1726 SCTP_INP_RLOCK(inp
);
1727 stcb
= LIST_FIRST(&inp
->sctp_asoc_list
);
1730 ids
->asls_numb_present
= 0;
1731 ids
->asls_more_to_get
= 0;
1732 SCTP_INP_RUNLOCK(inp
);
1735 orig
= ids
->asls_assoc_start
;
1736 stcb
= LIST_FIRST(&inp
->sctp_asoc_list
);
1738 stcb
= LIST_NEXT(stcb
, sctp_tcblist
);
1746 ids
->asls_numb_present
= 0;
1747 ids
->asls_more_to_get
= 1;
1748 while(at
< MAX_ASOC_IDS_RET
) {
1749 ids
->asls_assoc_id
[at
] = sctp_get_associd(stcb
);
1751 ids
->asls_numb_present
++;
1752 stcb
= LIST_NEXT(stcb
, sctp_tcblist
);
1754 ids
->asls_more_to_get
= 0;
1758 SCTP_INP_RUNLOCK(inp
);
1761 case SCTP_GET_NONCE_VALUES
:
1763 struct sctp_get_nonce_values
*gnv
;
1764 if ((size_t)m
->m_len
< sizeof(struct sctp_get_nonce_values
)) {
1768 gnv
= mtod(m
, struct sctp_get_nonce_values
*);
1769 stcb
= sctp_findassociation_ep_asocid(inp
, gnv
->gn_assoc_id
);
1773 gnv
->gn_peers_tag
= stcb
->asoc
.peer_vtag
;
1774 gnv
->gn_local_tag
= stcb
->asoc
.my_vtag
;
1775 SCTP_TCB_UNLOCK(stcb
);
1780 case SCTP_PEER_PUBLIC_KEY
:
1781 case SCTP_MY_PUBLIC_KEY
:
1782 case SCTP_SET_AUTH_CHUNKS
:
1783 case SCTP_SET_AUTH_SECRET
:
1784 /* not supported yet and until we refine the draft */
1788 case SCTP_DELAYED_ACK_TIME
:
1791 if ((size_t)m
->m_len
< sizeof(int32_t)) {
1795 tm
= mtod(m
, int32_t *);
1797 *tm
= TICKS_TO_MSEC(inp
->sctp_ep
.sctp_timeoutticks
[SCTP_TIMER_RECV
]);
1801 case SCTP_GET_SNDBUF_USE
:
1802 if ((size_t)m
->m_len
< sizeof(struct sctp_sockstat
)) {
1805 struct sctp_sockstat
*ss
;
1806 struct sctp_tcb
*stcb
;
1807 struct sctp_association
*asoc
;
1808 ss
= mtod(m
, struct sctp_sockstat
*);
1809 stcb
= sctp_findassociation_ep_asocid(inp
, ss
->ss_assoc_id
);
1814 ss
->ss_total_sndbuf
= (u_int32_t
)asoc
->total_output_queue_size
;
1815 ss
->ss_total_mbuf_sndbuf
= (u_int32_t
)asoc
->total_output_mbuf_queue_size
;
1816 ss
->ss_total_recv_buf
= (u_int32_t
)(asoc
->size_on_delivery_queue
+
1817 asoc
->size_on_reasm_queue
+
1818 asoc
->size_on_all_streams
);
1819 SCTP_TCB_UNLOCK(stcb
);
1821 m
->m_len
= sizeof(struct sctp_sockstat
);
1828 burst
= mtod(m
, u_int8_t
*);
1829 SCTP_INP_RLOCK(inp
);
1830 *burst
= inp
->sctp_ep
.max_burst
;
1831 SCTP_INP_RUNLOCK(inp
);
1832 m
->m_len
= sizeof(u_int8_t
);
1838 sctp_assoc_t
*assoc_id
;
1841 if ((size_t)m
->m_len
< sizeof(u_int32_t
)) {
1845 if ((size_t)m
->m_len
< sizeof(sctp_assoc_t
)) {
1849 assoc_id
= mtod(m
, sctp_assoc_t
*);
1850 segsize
= mtod(m
, u_int32_t
*);
1851 m
->m_len
= sizeof(u_int32_t
);
1853 if (((inp
->sctp_flags
& SCTP_PCB_FLAGS_TCPTYPE
) &&
1854 (inp
->sctp_flags
& SCTP_PCB_FLAGS_CONNECTED
)) ||
1855 (inp
->sctp_flags
& SCTP_PCB_FLAGS_IN_TCPPOOL
)) {
1856 struct sctp_tcb
*stcb
;
1857 SCTP_INP_RLOCK(inp
);
1858 stcb
= LIST_FIRST(&inp
->sctp_asoc_list
);
1860 SCTP_TCB_LOCK(stcb
);
1861 SCTP_INP_RUNLOCK(inp
);
1862 *segsize
= sctp_get_frag_point(stcb
, &stcb
->asoc
);
1863 SCTP_TCB_UNLOCK(stcb
);
1865 SCTP_INP_RUNLOCK(inp
);
1869 stcb
= sctp_findassociation_ep_asocid(inp
, *assoc_id
);
1871 *segsize
= sctp_get_frag_point(stcb
, &stcb
->asoc
);
1872 SCTP_TCB_UNLOCK(stcb
);
1876 /* default is to get the max, if I
1877 * can't calculate from an existing association.
1879 if (inp
->sctp_flags
& SCTP_PCB_FLAGS_BOUND_V6
) {
1880 ovh
= SCTP_MED_OVERHEAD
;
1882 ovh
= SCTP_MED_V4_OVERHEAD
;
1884 *segsize
= inp
->sctp_frag_point
- ovh
;
1889 case SCTP_SET_DEBUG_LEVEL
:
1893 if ((size_t)m
->m_len
< sizeof(u_int32_t
)) {
1897 level
= mtod(m
, u_int32_t
*);
1899 *level
= sctp_debug_on
;
1900 m
->m_len
= sizeof(u_int32_t
);
1901 kprintf("Returning DEBUG LEVEL %x is set\n",
1902 (u_int
)sctp_debug_on
);
1904 #else /* SCTP_DEBUG */
1908 case SCTP_GET_STAT_LOG
:
1909 #ifdef SCTP_STAT_LOGGING
1910 error
= sctp_fill_stat_log(m
);
1911 #else /* SCTP_DEBUG */
1918 if ((size_t)m
->m_len
< sizeof(sctp_pegs
)) {
1922 pt
= mtod(m
, u_int32_t
*);
1923 memcpy(pt
, sctp_pegs
, sizeof(sctp_pegs
));
1924 m
->m_len
= sizeof(sctp_pegs
);
1929 struct sctp_event_subscribe
*events
;
1931 if (sctp_debug_on
& SCTP_DEBUG_USRREQ2
) {
1932 kprintf("get events\n");
1934 #endif /* SCTP_DEBUG */
1935 if ((size_t)m
->m_len
< sizeof(struct sctp_event_subscribe
)) {
1937 if (sctp_debug_on
& SCTP_DEBUG_USRREQ2
) {
1938 kprintf("M->M_LEN is %d not %d\n",
1940 (int)sizeof(struct sctp_event_subscribe
));
1942 #endif /* SCTP_DEBUG */
1946 events
= mtod(m
, struct sctp_event_subscribe
*);
1947 memset(events
, 0, sizeof(events
));
1948 SCTP_INP_RLOCK(inp
);
1949 if (inp
->sctp_flags
& SCTP_PCB_FLAGS_RECVDATAIOEVNT
)
1950 events
->sctp_data_io_event
= 1;
1952 if (inp
->sctp_flags
& SCTP_PCB_FLAGS_RECVASSOCEVNT
)
1953 events
->sctp_association_event
= 1;
1955 if (inp
->sctp_flags
& SCTP_PCB_FLAGS_RECVPADDREVNT
)
1956 events
->sctp_address_event
= 1;
1958 if (inp
->sctp_flags
& SCTP_PCB_FLAGS_RECVSENDFAILEVNT
)
1959 events
->sctp_send_failure_event
= 1;
1961 if (inp
->sctp_flags
& SCTP_PCB_FLAGS_RECVPEERERR
)
1962 events
->sctp_peer_error_event
= 1;
1964 if (inp
->sctp_flags
& SCTP_PCB_FLAGS_RECVSHUTDOWNEVNT
)
1965 events
->sctp_shutdown_event
= 1;
1967 if (inp
->sctp_flags
& SCTP_PCB_FLAGS_PDAPIEVNT
)
1968 events
->sctp_partial_delivery_event
= 1;
1970 if (inp
->sctp_flags
& SCTP_PCB_FLAGS_ADAPTIONEVNT
)
1971 events
->sctp_adaption_layer_event
= 1;
1973 if (inp
->sctp_flags
& SCTP_PCB_FLAGS_STREAM_RESETEVNT
)
1974 events
->sctp_stream_reset_events
= 1;
1975 SCTP_INP_RUNLOCK(inp
);
1976 m
->m_len
= sizeof(struct sctp_event_subscribe
);
1981 case SCTP_ADAPTION_LAYER
:
1982 if ((size_t)m
->m_len
< sizeof(int)) {
1987 if (sctp_debug_on
& SCTP_DEBUG_USRREQ1
) {
1988 kprintf("getadaption ind\n");
1990 #endif /* SCTP_DEBUG */
1991 SCTP_INP_RLOCK(inp
);
1992 *mtod(m
, int *) = inp
->sctp_ep
.adaption_layer_indicator
;
1993 SCTP_INP_RUNLOCK(inp
);
1994 m
->m_len
= sizeof(int);
1996 case SCTP_SET_INITIAL_DBG_SEQ
:
1997 if ((size_t)m
->m_len
< sizeof(int)) {
2002 if (sctp_debug_on
& SCTP_DEBUG_USRREQ1
) {
2003 kprintf("get initial dbg seq\n");
2005 #endif /* SCTP_DEBUG */
2006 SCTP_INP_RLOCK(inp
);
2007 *mtod(m
, int *) = inp
->sctp_ep
.initial_sequence_debug
;
2008 SCTP_INP_RUNLOCK(inp
);
2009 m
->m_len
= sizeof(int);
2011 case SCTP_GET_LOCAL_ADDR_SIZE
:
2012 if ((size_t)m
->m_len
< sizeof(int)) {
2017 if (sctp_debug_on
& SCTP_DEBUG_USRREQ1
) {
2018 kprintf("get local sizes\n");
2020 #endif /* SCTP_DEBUG */
2021 SCTP_INP_RLOCK(inp
);
2022 *mtod(m
, int *) = sctp_count_max_addresses(inp
);
2023 SCTP_INP_RUNLOCK(inp
);
2024 m
->m_len
= sizeof(int);
2026 case SCTP_GET_REMOTE_ADDR_SIZE
:
2028 sctp_assoc_t
*assoc_id
;
2030 struct sctp_nets
*net
;
2032 if (sctp_debug_on
& SCTP_DEBUG_USRREQ1
) {
2033 kprintf("get remote size\n");
2035 #endif /* SCTP_DEBUG */
2036 if ((size_t)m
->m_len
< sizeof(sctp_assoc_t
)) {
2038 kprintf("m->m_len:%d not %d\n",
2039 m
->m_len
, sizeof(sctp_assoc_t
));
2040 #endif /* SCTP_DEBUG */
2045 val
= mtod(m
, u_int32_t
*);
2046 if (inp
->sctp_flags
& SCTP_PCB_FLAGS_CONNECTED
) {
2047 SCTP_INP_RLOCK(inp
);
2048 stcb
= LIST_FIRST(&inp
->sctp_asoc_list
);
2050 SCTP_TCB_LOCK(stcb
);
2051 SCTP_INP_RUNLOCK(inp
);
2054 assoc_id
= mtod(m
, sctp_assoc_t
*);
2055 stcb
= sctp_findassociation_ep_asocid(inp
, *assoc_id
);
2064 /* Count the sizes */
2065 TAILQ_FOREACH(net
, &stcb
->asoc
.nets
, sctp_next
) {
2066 if ((stcb
->sctp_ep
->sctp_flags
& SCTP_PCB_FLAGS_NEEDS_MAPPED_V4
) ||
2067 (((struct sockaddr
*)&net
->ro
._l_addr
)->sa_family
== AF_INET6
)) {
2068 sz
+= sizeof(struct sockaddr_in6
);
2069 } else if (((struct sockaddr
*)&net
->ro
._l_addr
)->sa_family
== AF_INET
) {
2070 sz
+= sizeof(struct sockaddr_in
);
2076 SCTP_TCB_UNLOCK(stcb
);
2078 m
->m_len
= sizeof(u_int32_t
);
2081 case SCTP_GET_PEER_ADDRESSES
:
2083 * Get the address information, an array
2084 * is passed in to fill up we pack it.
2088 struct sockaddr_storage
*sas
;
2089 struct sctp_nets
*net
;
2090 struct sctp_getaddresses
*saddr
;
2092 if (sctp_debug_on
& SCTP_DEBUG_USRREQ1
) {
2093 kprintf("get peer addresses\n");
2095 #endif /* SCTP_DEBUG */
2096 if ((size_t)m
->m_len
< sizeof(struct sctp_getaddresses
)) {
2100 left
= m
->m_len
- sizeof(struct sctp_getaddresses
);
2101 saddr
= mtod(m
, struct sctp_getaddresses
*);
2102 if (inp
->sctp_flags
& SCTP_PCB_FLAGS_CONNECTED
) {
2103 SCTP_INP_RLOCK(inp
);
2104 stcb
= LIST_FIRST(&inp
->sctp_asoc_list
);
2106 SCTP_TCB_LOCK(stcb
);
2107 SCTP_INP_RUNLOCK(inp
);
2109 stcb
= sctp_findassociation_ep_asocid(inp
,
2110 saddr
->sget_assoc_id
);
2115 m
->m_len
= sizeof(struct sctp_getaddresses
);
2116 sas
= (struct sockaddr_storage
*)&saddr
->addr
[0];
2118 TAILQ_FOREACH(net
, &stcb
->asoc
.nets
, sctp_next
) {
2119 if ((stcb
->sctp_ep
->sctp_flags
& SCTP_PCB_FLAGS_NEEDS_MAPPED_V4
) ||
2120 (((struct sockaddr
*)&net
->ro
._l_addr
)->sa_family
== AF_INET6
)) {
2121 cpsz
= sizeof(struct sockaddr_in6
);
2122 } else if (((struct sockaddr
*)&net
->ro
._l_addr
)->sa_family
== AF_INET
) {
2123 cpsz
= sizeof(struct sockaddr_in
);
2129 /* not enough room. */
2131 if (sctp_debug_on
& SCTP_DEBUG_USRREQ1
) {
2132 kprintf("Out of room\n");
2134 #endif /* SCTP_DEBUG */
2137 if ((stcb
->sctp_ep
->sctp_flags
& SCTP_PCB_FLAGS_NEEDS_MAPPED_V4
) &&
2138 (((struct sockaddr
*)&net
->ro
._l_addr
)->sa_family
== AF_INET
)) {
2139 /* Must map the address */
2140 in6_sin_2_v4mapsin6((struct sockaddr_in
*)&net
->ro
._l_addr
,
2141 (struct sockaddr_in6
*)sas
);
2143 memcpy(sas
, &net
->ro
._l_addr
, cpsz
);
2145 ((struct sockaddr_in
*)sas
)->sin_port
= stcb
->rport
;
2147 sas
= (struct sockaddr_storage
*)((caddr_t
)sas
+ cpsz
);
2151 if (sctp_debug_on
& SCTP_DEBUG_USRREQ2
) {
2152 kprintf("left now:%d mlen:%d\n",
2155 #endif /* SCTP_DEBUG */
2157 SCTP_TCB_UNLOCK(stcb
);
2160 if (sctp_debug_on
& SCTP_DEBUG_USRREQ1
) {
2161 kprintf("All done\n");
2163 #endif /* SCTP_DEBUG */
2165 case SCTP_GET_LOCAL_ADDRESSES
:
2168 struct sockaddr_storage
*sas
;
2169 struct sctp_getaddresses
*saddr
;
2171 if (sctp_debug_on
& SCTP_DEBUG_USRREQ1
) {
2172 kprintf("get local addresses\n");
2174 #endif /* SCTP_DEBUG */
2175 if ((size_t)m
->m_len
< sizeof(struct sctp_getaddresses
)) {
2179 saddr
= mtod(m
, struct sctp_getaddresses
*);
2181 if (saddr
->sget_assoc_id
) {
2182 if (inp
->sctp_flags
& SCTP_PCB_FLAGS_CONNECTED
) {
2183 SCTP_INP_RLOCK(inp
);
2184 stcb
= LIST_FIRST(&inp
->sctp_asoc_list
);
2186 SCTP_TCB_LOCK(stcb
);
2187 SCTP_INP_RUNLOCK(inp
);
2189 stcb
= sctp_findassociation_ep_asocid(inp
, saddr
->sget_assoc_id
);
2195 * assure that the TCP model does not need a assoc id
2198 if ( (inp
->sctp_flags
& SCTP_PCB_FLAGS_CONNECTED
) &&
2200 SCTP_INP_RLOCK(inp
);
2201 stcb
= LIST_FIRST(&inp
->sctp_asoc_list
);
2203 SCTP_TCB_LOCK(stcb
);
2204 SCTP_INP_RUNLOCK(inp
);
2206 sas
= (struct sockaddr_storage
*)&saddr
->addr
[0];
2207 limit
= m
->m_len
- sizeof(sctp_assoc_t
);
2208 actual
= sctp_fill_up_addresses(inp
, stcb
, limit
, sas
);
2209 SCTP_TCB_UNLOCK(stcb
);
2210 m
->m_len
= sizeof(struct sockaddr_storage
) + actual
;
2213 case SCTP_PEER_ADDR_PARAMS
:
2215 struct sctp_paddrparams
*paddrp
;
2216 struct sctp_nets
*net
;
2219 if (sctp_debug_on
& SCTP_DEBUG_USRREQ1
) {
2220 kprintf("Getting peer_addr_params\n");
2222 #endif /* SCTP_DEBUG */
2223 if ((size_t)m
->m_len
< sizeof(struct sctp_paddrparams
)) {
2225 if (sctp_debug_on
& SCTP_DEBUG_USRREQ2
) {
2226 kprintf("Hmm m->m_len:%d is to small\n",
2229 #endif /* SCTP_DEBUG */
2233 paddrp
= mtod(m
, struct sctp_paddrparams
*);
2236 if (paddrp
->spp_assoc_id
) {
2238 if (sctp_debug_on
& SCTP_DEBUG_USRREQ1
) {
2239 kprintf("In spp_assoc_id find type\n");
2241 #endif /* SCTP_DEBUG */
2242 if (inp
->sctp_flags
& SCTP_PCB_FLAGS_CONNECTED
) {
2243 SCTP_INP_RLOCK(inp
);
2244 stcb
= LIST_FIRST(&inp
->sctp_asoc_list
);
2246 SCTP_TCB_LOCK(stcb
);
2247 net
= sctp_findnet(stcb
, (struct sockaddr
*)&paddrp
->spp_address
);
2249 SCTP_INP_RLOCK(inp
);
2251 stcb
= sctp_findassociation_ep_asocid(inp
, paddrp
->spp_assoc_id
);
2258 if ( (stcb
== NULL
) &&
2259 ((((struct sockaddr
*)&paddrp
->spp_address
)->sa_family
== AF_INET
) ||
2260 (((struct sockaddr
*)&paddrp
->spp_address
)->sa_family
== AF_INET6
))) {
2261 /* Lookup via address */
2263 if (sctp_debug_on
& SCTP_DEBUG_USRREQ1
) {
2264 kprintf("Ok we need to lookup a param\n");
2266 #endif /* SCTP_DEBUG */
2267 if (inp
->sctp_flags
& SCTP_PCB_FLAGS_CONNECTED
) {
2268 SCTP_INP_RLOCK(inp
);
2269 stcb
= LIST_FIRST(&inp
->sctp_asoc_list
);
2271 SCTP_TCB_LOCK(stcb
);
2272 net
= sctp_findnet(stcb
, (struct sockaddr
*)&paddrp
->spp_address
);
2274 SCTP_INP_RUNLOCK(inp
);
2276 SCTP_INP_WLOCK(inp
);
2277 SCTP_INP_INCR_REF(inp
);
2278 SCTP_INP_WUNLOCK(inp
);
2279 stcb
= sctp_findassociation_ep_addr(&inp
,
2280 (struct sockaddr
*)&paddrp
->spp_address
,
2283 SCTP_INP_WLOCK(inp
);
2284 SCTP_INP_DECR_REF(inp
);
2285 SCTP_INP_WUNLOCK(inp
);
2294 /* Effects the Endpoint */
2296 if (sctp_debug_on
& SCTP_DEBUG_USRREQ1
) {
2297 kprintf("User wants EP level info\n");
2299 #endif /* SCTP_DEBUG */
2303 /* Applys to the specific association */
2305 if (sctp_debug_on
& SCTP_DEBUG_USRREQ1
) {
2306 kprintf("In TCB side\n");
2308 #endif /* SCTP_DEBUG */
2310 paddrp
->spp_pathmaxrxt
= net
->failure_threshold
;
2312 /* No destination so return default value */
2313 paddrp
->spp_pathmaxrxt
= stcb
->asoc
.def_net_failure
;
2315 paddrp
->spp_hbinterval
= stcb
->asoc
.heart_beat_delay
;
2316 paddrp
->spp_assoc_id
= sctp_get_associd(stcb
);
2317 SCTP_TCB_UNLOCK(stcb
);
2319 /* Use endpoint defaults */
2320 SCTP_INP_RLOCK(inp
);
2322 if (sctp_debug_on
& SCTP_DEBUG_USRREQ1
) {
2323 kprintf("In EP level info\n");
2325 #endif /* SCTP_DEBUG */
2326 paddrp
->spp_pathmaxrxt
= inp
->sctp_ep
.def_net_failure
;
2327 paddrp
->spp_hbinterval
= inp
->sctp_ep
.sctp_timeoutticks
[SCTP_TIMER_HEARTBEAT
];
2328 paddrp
->spp_assoc_id
= (sctp_assoc_t
)0;
2329 SCTP_INP_RUNLOCK(inp
);
2331 m
->m_len
= sizeof(struct sctp_paddrparams
);
2334 case SCTP_GET_PEER_ADDR_INFO
:
2336 struct sctp_paddrinfo
*paddri
;
2337 struct sctp_nets
*net
;
2339 if (sctp_debug_on
& SCTP_DEBUG_USRREQ1
) {
2340 kprintf("GetPEER ADDR_INFO\n");
2342 #endif /* SCTP_DEBUG */
2343 if ((size_t)m
->m_len
< sizeof(struct sctp_paddrinfo
)) {
2347 paddri
= mtod(m
, struct sctp_paddrinfo
*);
2349 if ((((struct sockaddr
*)&paddri
->spinfo_address
)->sa_family
== AF_INET
) ||
2350 (((struct sockaddr
*)&paddri
->spinfo_address
)->sa_family
== AF_INET6
)) {
2351 /* Lookup via address */
2352 if (inp
->sctp_flags
& SCTP_PCB_FLAGS_CONNECTED
) {
2353 SCTP_INP_RLOCK(inp
);
2354 stcb
= LIST_FIRST(&inp
->sctp_asoc_list
);
2356 SCTP_TCB_LOCK(stcb
);
2357 net
= sctp_findnet(stcb
,
2358 (struct sockaddr
*)&paddri
->spinfo_address
);
2360 SCTP_INP_RUNLOCK(inp
);
2362 SCTP_INP_WLOCK(inp
);
2363 SCTP_INP_INCR_REF(inp
);
2364 SCTP_INP_WUNLOCK(inp
);
2365 stcb
= sctp_findassociation_ep_addr(&inp
,
2366 (struct sockaddr
*)&paddri
->spinfo_address
,
2369 SCTP_INP_WLOCK(inp
);
2370 SCTP_INP_DECR_REF(inp
);
2371 SCTP_INP_WUNLOCK(inp
);
2378 if ((stcb
== NULL
) || (net
== NULL
)) {
2382 m
->m_len
= sizeof(struct sctp_paddrinfo
);
2383 paddri
->spinfo_state
= net
->dest_state
& (SCTP_REACHABLE_MASK
|SCTP_ADDR_NOHB
);
2384 paddri
->spinfo_cwnd
= net
->cwnd
;
2385 paddri
->spinfo_srtt
= ((net
->lastsa
>> 2) + net
->lastsv
) >> 1;
2386 paddri
->spinfo_rto
= net
->RTO
;
2387 paddri
->spinfo_assoc_id
= sctp_get_associd(stcb
);
2388 SCTP_TCB_UNLOCK(stcb
);
2391 case SCTP_PCB_STATUS
:
2393 struct sctp_pcbinfo
*spcb
;
2395 if (sctp_debug_on
& SCTP_DEBUG_USRREQ1
) {
2396 kprintf("PCB status\n");
2398 #endif /* SCTP_DEBUG */
2399 if ((size_t)m
->m_len
< sizeof(struct sctp_pcbinfo
)) {
2403 spcb
= mtod(m
, struct sctp_pcbinfo
*);
2404 sctp_fill_pcbinfo(spcb
);
2405 m
->m_len
= sizeof(struct sctp_pcbinfo
);
2410 struct sctp_nets
*net
;
2411 struct sctp_status
*sstat
;
2413 if (sctp_debug_on
& SCTP_DEBUG_USRREQ1
) {
2414 kprintf("SCTP status\n");
2416 #endif /* SCTP_DEBUG */
2418 if ((size_t)m
->m_len
< sizeof(struct sctp_status
)) {
2422 sstat
= mtod(m
, struct sctp_status
*);
2424 if (inp
->sctp_flags
& SCTP_PCB_FLAGS_CONNECTED
) {
2425 SCTP_INP_RLOCK(inp
);
2426 stcb
= LIST_FIRST(&inp
->sctp_asoc_list
);
2428 SCTP_TCB_LOCK(stcb
);
2429 SCTP_INP_RUNLOCK(inp
);
2431 stcb
= sctp_findassociation_ep_asocid(inp
, sstat
->sstat_assoc_id
);
2438 * I think passing the state is fine since
2439 * sctp_constants.h will be available to the user
2442 sstat
->sstat_state
= stcb
->asoc
.state
;
2443 sstat
->sstat_rwnd
= stcb
->asoc
.peers_rwnd
;
2444 sstat
->sstat_unackdata
= stcb
->asoc
.sent_queue_cnt
;
2446 * We can't include chunks that have been passed
2447 * to the socket layer. Only things in queue.
2449 sstat
->sstat_penddata
= (stcb
->asoc
.cnt_on_delivery_queue
+
2450 stcb
->asoc
.cnt_on_reasm_queue
+
2451 stcb
->asoc
.cnt_on_all_streams
);
2454 sstat
->sstat_instrms
= stcb
->asoc
.streamincnt
;
2455 sstat
->sstat_outstrms
= stcb
->asoc
.streamoutcnt
;
2456 sstat
->sstat_fragmentation_point
= sctp_get_frag_point(stcb
, &stcb
->asoc
);
2457 memcpy(&sstat
->sstat_primary
.spinfo_address
,
2458 &stcb
->asoc
.primary_destination
->ro
._l_addr
,
2459 ((struct sockaddr
*)(&stcb
->asoc
.primary_destination
->ro
._l_addr
))->sa_len
);
2460 net
= stcb
->asoc
.primary_destination
;
2461 ((struct sockaddr_in
*)&sstat
->sstat_primary
.spinfo_address
)->sin_port
= stcb
->rport
;
2463 * Again the user can get info from sctp_constants.h
2464 * for what the state of the network is.
2466 sstat
->sstat_primary
.spinfo_state
= net
->dest_state
& SCTP_REACHABLE_MASK
;
2467 sstat
->sstat_primary
.spinfo_cwnd
= net
->cwnd
;
2468 sstat
->sstat_primary
.spinfo_srtt
= net
->lastsa
;
2469 sstat
->sstat_primary
.spinfo_rto
= net
->RTO
;
2470 sstat
->sstat_primary
.spinfo_mtu
= net
->mtu
;
2471 sstat
->sstat_primary
.spinfo_assoc_id
= sctp_get_associd(stcb
);
2472 SCTP_TCB_UNLOCK(stcb
);
2473 m
->m_len
= sizeof(*sstat
);
2478 struct sctp_rtoinfo
*srto
;
2480 if (sctp_debug_on
& SCTP_DEBUG_USRREQ1
) {
2481 kprintf("RTO Info\n");
2483 #endif /* SCTP_DEBUG */
2484 if ((size_t)m
->m_len
< sizeof(struct sctp_rtoinfo
)) {
2488 srto
= mtod(m
, struct sctp_rtoinfo
*);
2489 if (srto
->srto_assoc_id
== 0) {
2490 /* Endpoint only please */
2491 SCTP_INP_RLOCK(inp
);
2492 srto
->srto_initial
= inp
->sctp_ep
.initial_rto
;
2493 srto
->srto_max
= inp
->sctp_ep
.sctp_maxrto
;
2494 srto
->srto_min
= inp
->sctp_ep
.sctp_minrto
;
2495 SCTP_INP_RUNLOCK(inp
);
2498 if (inp
->sctp_flags
& SCTP_PCB_FLAGS_CONNECTED
) {
2499 SCTP_INP_RLOCK(inp
);
2500 stcb
= LIST_FIRST(&inp
->sctp_asoc_list
);
2502 SCTP_TCB_LOCK(stcb
);
2503 SCTP_INP_RUNLOCK(inp
);
2505 stcb
= sctp_findassociation_ep_asocid(inp
, srto
->srto_assoc_id
);
2511 srto
->srto_initial
= stcb
->asoc
.initial_rto
;
2512 srto
->srto_max
= stcb
->asoc
.maxrto
;
2513 srto
->srto_min
= stcb
->asoc
.minrto
;
2514 SCTP_TCB_UNLOCK(stcb
);
2515 m
->m_len
= sizeof(*srto
);
2518 case SCTP_ASSOCINFO
:
2520 struct sctp_assocparams
*sasoc
;
2522 if (sctp_debug_on
& SCTP_DEBUG_USRREQ1
) {
2523 kprintf("Associnfo\n");
2525 #endif /* SCTP_DEBUG */
2526 if ((size_t)m
->m_len
< sizeof(struct sctp_assocparams
)) {
2530 sasoc
= mtod(m
, struct sctp_assocparams
*);
2533 if (inp
->sctp_flags
& SCTP_PCB_FLAGS_CONNECTED
) {
2534 SCTP_INP_RLOCK(inp
);
2535 stcb
= LIST_FIRST(&inp
->sctp_asoc_list
);
2537 SCTP_TCB_LOCK(stcb
);
2538 SCTP_INP_RUNLOCK(inp
);
2540 if ((sasoc
->sasoc_assoc_id
) && (stcb
== NULL
)) {
2541 stcb
= sctp_findassociation_ep_asocid(inp
,
2542 sasoc
->sasoc_assoc_id
);
2552 sasoc
->sasoc_asocmaxrxt
= stcb
->asoc
.max_send_times
;
2553 sasoc
->sasoc_number_peer_destinations
= stcb
->asoc
.numnets
;
2554 sasoc
->sasoc_peer_rwnd
= stcb
->asoc
.peers_rwnd
;
2555 sasoc
->sasoc_local_rwnd
= stcb
->asoc
.my_rwnd
;
2556 sasoc
->sasoc_cookie_life
= stcb
->asoc
.cookie_life
;
2557 SCTP_TCB_UNLOCK(stcb
);
2559 SCTP_INP_RLOCK(inp
);
2560 sasoc
->sasoc_asocmaxrxt
= inp
->sctp_ep
.max_send_times
;
2561 sasoc
->sasoc_number_peer_destinations
= 0;
2562 sasoc
->sasoc_peer_rwnd
= 0;
2563 sasoc
->sasoc_local_rwnd
= ssb_space(&inp
->sctp_socket
->so_rcv
);
2564 sasoc
->sasoc_cookie_life
= inp
->sctp_ep
.def_cookie_life
;
2565 SCTP_INP_RUNLOCK(inp
);
2567 m
->m_len
= sizeof(*sasoc
);
2570 case SCTP_DEFAULT_SEND_PARAM
:
2572 struct sctp_sndrcvinfo
*s_info
;
2574 if (m
->m_len
!= sizeof(struct sctp_sndrcvinfo
)) {
2578 s_info
= mtod(m
, struct sctp_sndrcvinfo
*);
2579 if (inp
->sctp_flags
& SCTP_PCB_FLAGS_CONNECTED
) {
2580 SCTP_INP_RLOCK(inp
);
2581 stcb
= LIST_FIRST(&inp
->sctp_asoc_list
);
2583 SCTP_TCB_LOCK(stcb
);
2584 SCTP_INP_RUNLOCK(inp
);
2586 stcb
= sctp_findassociation_ep_asocid(inp
, s_info
->sinfo_assoc_id
);
2593 *s_info
= stcb
->asoc
.def_send
;
2594 SCTP_TCB_UNLOCK(stcb
);
2595 m
->m_len
= sizeof(*s_info
);
2599 struct sctp_initmsg
*sinit
;
2601 if (sctp_debug_on
& SCTP_DEBUG_USRREQ1
) {
2602 kprintf("initmsg\n");
2604 #endif /* SCTP_DEBUG */
2605 if ((size_t)m
->m_len
< sizeof(struct sctp_initmsg
)) {
2609 sinit
= mtod(m
, struct sctp_initmsg
*);
2610 SCTP_INP_RLOCK(inp
);
2611 sinit
->sinit_num_ostreams
= inp
->sctp_ep
.pre_open_stream_count
;
2612 sinit
->sinit_max_instreams
= inp
->sctp_ep
.max_open_streams_intome
;
2613 sinit
->sinit_max_attempts
= inp
->sctp_ep
.max_init_times
;
2614 sinit
->sinit_max_init_timeo
= inp
->sctp_ep
.initial_init_rto_max
;
2615 SCTP_INP_RUNLOCK(inp
);
2616 m
->m_len
= sizeof(*sinit
);
2619 case SCTP_PRIMARY_ADDR
:
2620 /* we allow a "get" operation on this */
2622 struct sctp_setprim
*ssp
;
2625 if (sctp_debug_on
& SCTP_DEBUG_USRREQ1
) {
2626 kprintf("setprimary\n");
2628 #endif /* SCTP_DEBUG */
2629 if ((size_t)m
->m_len
< sizeof(struct sctp_setprim
)) {
2633 ssp
= mtod(m
, struct sctp_setprim
*);
2634 if (inp
->sctp_flags
& SCTP_PCB_FLAGS_CONNECTED
) {
2635 SCTP_INP_RLOCK(inp
);
2636 stcb
= LIST_FIRST(&inp
->sctp_asoc_list
);
2638 SCTP_TCB_LOCK(stcb
);
2639 SCTP_INP_RUNLOCK(inp
);
2641 stcb
= sctp_findassociation_ep_asocid(inp
, ssp
->ssp_assoc_id
);
2643 /* one last shot, try it by the address in */
2644 struct sctp_nets
*net
;
2646 SCTP_INP_WLOCK(inp
);
2647 SCTP_INP_INCR_REF(inp
);
2648 SCTP_INP_WUNLOCK(inp
);
2649 stcb
= sctp_findassociation_ep_addr(&inp
,
2650 (struct sockaddr
*)&ssp
->ssp_addr
,
2653 SCTP_INP_WLOCK(inp
);
2654 SCTP_INP_DECR_REF(inp
);
2655 SCTP_INP_WUNLOCK(inp
);
2663 /* simply copy out the sockaddr_storage... */
2664 memcpy(&ssp
->ssp_addr
,
2665 &stcb
->asoc
.primary_destination
->ro
._l_addr
,
2666 ((struct sockaddr
*)&stcb
->asoc
.primary_destination
->ro
._l_addr
)->sa_len
);
2667 SCTP_TCB_UNLOCK(stcb
);
2668 m
->m_len
= sizeof(*ssp
);
2672 error
= ENOPROTOOPT
;
2675 } /* end switch (sopt->sopt_name) */
2680 sctp_optsset(struct socket
*so
,
2683 #if (defined(__FreeBSD__) && __FreeBSD_version >= 500000) || defined(__DragonFly__)
2690 int error
, *mopt
, set_opt
;
2692 struct sctp_tcb
*stcb
= NULL
;
2693 struct sctp_inpcb
*inp
;
2697 if (sctp_debug_on
& SCTP_DEBUG_USRREQ1
) {
2698 kprintf("optsset:MP is NULL EINVAL\n");
2700 #endif /* SCTP_DEBUG */
2707 inp
= (struct sctp_inpcb
*)so
->so_pcb
;
2714 case SCTP_AUTOCLOSE
:
2715 case SCTP_AUTO_ASCONF
:
2716 case SCTP_DISABLE_FRAGMENTS
:
2717 case SCTP_I_WANT_MAPPED_V4_ADDR
:
2718 /* copy in the option value */
2719 if ((size_t)m
->m_len
< sizeof(int)) {
2723 mopt
= mtod(m
, int *);
2728 case SCTP_DISABLE_FRAGMENTS
:
2729 set_opt
= SCTP_PCB_FLAGS_NO_FRAGMENT
;
2731 case SCTP_AUTO_ASCONF
:
2732 set_opt
= SCTP_PCB_FLAGS_AUTO_ASCONF
;
2735 case SCTP_I_WANT_MAPPED_V4_ADDR
:
2736 if (inp
->sctp_flags
& SCTP_PCB_FLAGS_BOUND_V6
) {
2737 set_opt
= SCTP_PCB_FLAGS_NEEDS_MAPPED_V4
;
2743 set_opt
= SCTP_PCB_FLAGS_NODELAY
;
2745 case SCTP_AUTOCLOSE
:
2746 set_opt
= SCTP_PCB_FLAGS_AUTOCLOSE
;
2748 * The value is in ticks.
2749 * Note this does not effect old associations, only
2752 inp
->sctp_ep
.auto_close_time
= (*mopt
* hz
);
2755 SCTP_INP_WLOCK(inp
);
2757 inp
->sctp_flags
|= set_opt
;
2759 inp
->sctp_flags
&= ~set_opt
;
2761 SCTP_INP_WUNLOCK(inp
);
2763 case SCTP_MY_PUBLIC_KEY
: /* set my public key */
2764 case SCTP_SET_AUTH_CHUNKS
: /* set the authenticated chunks required */
2765 case SCTP_SET_AUTH_SECRET
: /* set the actual secret for the endpoint */
2766 /* not supported yet and until we refine the draft */
2770 case SCTP_CLR_STAT_LOG
:
2771 #ifdef SCTP_STAT_LOGGING
2772 sctp_clr_stat_log();
2777 case SCTP_DELAYED_ACK_TIME
:
2780 if ((size_t)m
->m_len
< sizeof(int32_t)) {
2784 tm
= mtod(m
, int32_t *);
2786 if ((*tm
< 10) || (*tm
> 500)) {
2787 /* can't be smaller than 10ms */
2788 /* MUST NOT be larger than 500ms */
2792 inp
->sctp_ep
.sctp_timeoutticks
[SCTP_TIMER_RECV
] = MSEC_TO_TICKS(*tm
);
2795 case SCTP_RESET_STREAMS
:
2797 struct sctp_stream_reset
*strrst
;
2798 uint8_t two_way
, not_peer
;
2800 if ((size_t)m
->m_len
< sizeof(struct sctp_stream_reset
)) {
2804 strrst
= mtod(m
, struct sctp_stream_reset
*);
2806 if (inp
->sctp_flags
& SCTP_PCB_FLAGS_CONNECTED
) {
2807 SCTP_INP_RLOCK(inp
);
2808 stcb
= LIST_FIRST(&inp
->sctp_asoc_list
);
2810 SCTP_TCB_LOCK(stcb
);
2811 SCTP_INP_RUNLOCK(inp
);
2813 stcb
= sctp_findassociation_ep_asocid(inp
, strrst
->strrst_assoc_id
);
2818 if (stcb
->asoc
.peer_supports_strreset
== 0) {
2819 /* Peer does not support it,
2820 * we return protocol not supported since
2821 * this is true for this feature and this
2822 * peer, not the socket request in general.
2824 error
= EPROTONOSUPPORT
;
2825 SCTP_TCB_UNLOCK(stcb
);
2829 /* Having re-thought this code I added as I write the I-D there
2830 * is NO need for it. The peer, if we are requesting a stream-reset
2831 * will send a request to us but will itself do what we do, take
2832 * and copy off the "reset information" we send and queue TSN's
2833 * larger than the send-next in our response message. Thus they
2836 /* if (stcb->asoc.sending_seq != (stcb->asoc.last_acked_seq + 1)) {*/
2837 /* Must have all sending data ack'd before we
2838 * start this procedure. This is a bit restrictive
2839 * and we SHOULD work on changing this so ONLY the
2840 * streams being RESET get held up. So, a reset-all
2841 * would require this.. but a reset specific just
2842 * needs to be sure that the ones being reset have
2843 * nothing on the send_queue. For now we will
2844 * skip this more detailed method and do a course
2845 * way.. i.e. nothing pending ... for future FIX ME!
2851 if (stcb
->asoc
.stream_reset_outstanding
) {
2853 SCTP_TCB_UNLOCK(stcb
);
2856 if (strrst
->strrst_flags
== SCTP_RESET_LOCAL_RECV
) {
2859 } else if (strrst
->strrst_flags
== SCTP_RESET_LOCAL_SEND
) {
2862 } else if (strrst
->strrst_flags
== SCTP_RESET_BOTH
) {
2867 SCTP_TCB_UNLOCK(stcb
);
2870 sctp_send_str_reset_req(stcb
, strrst
->strrst_num_streams
,
2871 strrst
->strrst_list
, two_way
, not_peer
);
2873 sctp_chunk_output(inp
, stcb
, 12);
2874 SCTP_TCB_UNLOCK(stcb
);
2879 case SCTP_RESET_PEGS
:
2880 memset(sctp_pegs
, 0, sizeof(sctp_pegs
));
2883 case SCTP_CONNECT_X
:
2884 if ((size_t)m
->m_len
< (sizeof(int) + sizeof(struct sockaddr_in
))) {
2888 error
= sctp_do_connect_x(so
, inp
, m
, p
, 0);
2891 case SCTP_CONNECT_X_DELAYED
:
2892 if ((size_t)m
->m_len
< (sizeof(int) + sizeof(struct sockaddr_in
))) {
2896 error
= sctp_do_connect_x(so
, inp
, m
, p
, 1);
2899 case SCTP_CONNECT_X_COMPLETE
:
2901 struct sockaddr
*sa
;
2902 struct sctp_nets
*net
;
2903 if ((size_t)m
->m_len
< sizeof(struct sockaddr_in
)) {
2907 sa
= mtod(m
, struct sockaddr
*);
2909 if (inp
->sctp_flags
& SCTP_PCB_FLAGS_CONNECTED
) {
2910 SCTP_INP_RLOCK(inp
);
2911 stcb
= LIST_FIRST(&inp
->sctp_asoc_list
);
2913 SCTP_TCB_LOCK(stcb
);
2914 net
= sctp_findnet(stcb
, sa
);
2916 SCTP_INP_RUNLOCK(inp
);
2918 SCTP_INP_WLOCK(inp
);
2919 SCTP_INP_INCR_REF(inp
);
2920 SCTP_INP_WUNLOCK(inp
);
2921 stcb
= sctp_findassociation_ep_addr(&inp
, sa
, &net
, NULL
, NULL
);
2923 SCTP_INP_WLOCK(inp
);
2924 SCTP_INP_DECR_REF(inp
);
2925 SCTP_INP_WUNLOCK(inp
);
2933 if (stcb
->asoc
.delayed_connection
== 1) {
2934 stcb
->asoc
.delayed_connection
= 0;
2935 SCTP_GETTIME_TIMEVAL(&stcb
->asoc
.time_entered
);
2936 sctp_timer_stop(SCTP_TIMER_TYPE_INIT
, inp
, stcb
, stcb
->asoc
.primary_destination
);
2937 sctp_send_initiate(inp
, stcb
);
2939 /* already expired or did not use delayed connectx */
2942 SCTP_TCB_UNLOCK(stcb
);
2948 SCTP_INP_WLOCK(inp
);
2949 burst
= mtod(m
, u_int8_t
*);
2951 inp
->sctp_ep
.max_burst
= *burst
;
2953 SCTP_INP_WUNLOCK(inp
);
2960 if (inp
->sctp_flags
& SCTP_PCB_FLAGS_BOUND_V6
) {
2961 ovh
= SCTP_MED_OVERHEAD
;
2963 ovh
= SCTP_MED_V4_OVERHEAD
;
2965 segsize
= mtod(m
, u_int32_t
*);
2970 SCTP_INP_WLOCK(inp
);
2971 inp
->sctp_frag_point
= (*segsize
+ovh
);
2972 if (inp
->sctp_frag_point
< MHLEN
) {
2973 inp
->sctp_frag_point
= MHLEN
;
2975 SCTP_INP_WUNLOCK(inp
);
2978 case SCTP_SET_DEBUG_LEVEL
:
2982 if ((size_t)m
->m_len
< sizeof(u_int32_t
)) {
2986 level
= mtod(m
, u_int32_t
*);
2988 sctp_debug_on
= (*level
& (SCTP_DEBUG_ALL
|
2990 kprintf("SETTING DEBUG LEVEL to %x\n",
2991 (u_int
)sctp_debug_on
);
2996 #endif /* SCTP_DEBUG */
3000 struct sctp_event_subscribe
*events
;
3001 if ((size_t)m
->m_len
< sizeof(struct sctp_event_subscribe
)) {
3005 SCTP_INP_WLOCK(inp
);
3006 events
= mtod(m
, struct sctp_event_subscribe
*);
3007 if (events
->sctp_data_io_event
) {
3008 inp
->sctp_flags
|= SCTP_PCB_FLAGS_RECVDATAIOEVNT
;
3010 inp
->sctp_flags
&= ~SCTP_PCB_FLAGS_RECVDATAIOEVNT
;
3013 if (events
->sctp_association_event
) {
3014 inp
->sctp_flags
|= SCTP_PCB_FLAGS_RECVASSOCEVNT
;
3016 inp
->sctp_flags
&= ~SCTP_PCB_FLAGS_RECVASSOCEVNT
;
3019 if (events
->sctp_address_event
) {
3020 inp
->sctp_flags
|= SCTP_PCB_FLAGS_RECVPADDREVNT
;
3022 inp
->sctp_flags
&= ~SCTP_PCB_FLAGS_RECVPADDREVNT
;
3025 if (events
->sctp_send_failure_event
) {
3026 inp
->sctp_flags
|= SCTP_PCB_FLAGS_RECVSENDFAILEVNT
;
3028 inp
->sctp_flags
&= ~SCTP_PCB_FLAGS_RECVSENDFAILEVNT
;
3031 if (events
->sctp_peer_error_event
) {
3032 inp
->sctp_flags
|= SCTP_PCB_FLAGS_RECVPEERERR
;
3034 inp
->sctp_flags
&= ~SCTP_PCB_FLAGS_RECVPEERERR
;
3037 if (events
->sctp_shutdown_event
) {
3038 inp
->sctp_flags
|= SCTP_PCB_FLAGS_RECVSHUTDOWNEVNT
;
3040 inp
->sctp_flags
&= ~SCTP_PCB_FLAGS_RECVSHUTDOWNEVNT
;
3043 if (events
->sctp_partial_delivery_event
) {
3044 inp
->sctp_flags
|= SCTP_PCB_FLAGS_PDAPIEVNT
;
3046 inp
->sctp_flags
&= ~SCTP_PCB_FLAGS_PDAPIEVNT
;
3049 if (events
->sctp_adaption_layer_event
) {
3050 inp
->sctp_flags
|= SCTP_PCB_FLAGS_ADAPTIONEVNT
;
3052 inp
->sctp_flags
&= ~SCTP_PCB_FLAGS_ADAPTIONEVNT
;
3055 if (events
->sctp_stream_reset_events
) {
3056 inp
->sctp_flags
|= SCTP_PCB_FLAGS_STREAM_RESETEVNT
;
3058 inp
->sctp_flags
&= ~SCTP_PCB_FLAGS_STREAM_RESETEVNT
;
3060 SCTP_INP_WUNLOCK(inp
);
3064 case SCTP_ADAPTION_LAYER
:
3066 struct sctp_setadaption
*adap_bits
;
3067 if ((size_t)m
->m_len
< sizeof(struct sctp_setadaption
)) {
3071 SCTP_INP_WLOCK(inp
);
3072 adap_bits
= mtod(m
, struct sctp_setadaption
*);
3073 inp
->sctp_ep
.adaption_layer_indicator
= adap_bits
->ssb_adaption_ind
;
3074 SCTP_INP_WUNLOCK(inp
);
3077 case SCTP_SET_INITIAL_DBG_SEQ
:
3080 if ((size_t)m
->m_len
< sizeof(u_int32_t
)) {
3084 SCTP_INP_WLOCK(inp
);
3085 vvv
= mtod(m
, u_int32_t
*);
3086 inp
->sctp_ep
.initial_sequence_debug
= *vvv
;
3087 SCTP_INP_WUNLOCK(inp
);
3090 case SCTP_DEFAULT_SEND_PARAM
:
3092 struct sctp_sndrcvinfo
*s_info
;
3094 if (m
->m_len
!= sizeof(struct sctp_sndrcvinfo
)) {
3098 s_info
= mtod(m
, struct sctp_sndrcvinfo
*);
3100 if (inp
->sctp_flags
& SCTP_PCB_FLAGS_CONNECTED
) {
3101 SCTP_INP_RLOCK(inp
);
3102 stcb
= LIST_FIRST(&inp
->sctp_asoc_list
);
3104 SCTP_TCB_LOCK(stcb
);
3105 SCTP_INP_RUNLOCK(inp
);
3107 stcb
= sctp_findassociation_ep_asocid(inp
, s_info
->sinfo_assoc_id
);
3113 /* Validate things */
3114 if (s_info
->sinfo_stream
> stcb
->asoc
.streamoutcnt
) {
3115 SCTP_TCB_UNLOCK(stcb
);
3119 /* Mask off the flags that are allowed */
3120 s_info
->sinfo_flags
= (s_info
->sinfo_flags
&
3121 (MSG_UNORDERED
| MSG_ADDR_OVER
|
3122 MSG_PR_SCTP_TTL
| MSG_PR_SCTP_BUF
));
3124 stcb
->asoc
.def_send
= *s_info
;
3125 SCTP_TCB_UNLOCK(stcb
);
3128 case SCTP_PEER_ADDR_PARAMS
:
3130 struct sctp_paddrparams
*paddrp
;
3131 struct sctp_nets
*net
;
3132 if ((size_t)m
->m_len
< sizeof(struct sctp_paddrparams
)) {
3136 paddrp
= mtod(m
, struct sctp_paddrparams
*);
3138 if (paddrp
->spp_assoc_id
) {
3139 if (inp
->sctp_flags
& SCTP_PCB_FLAGS_CONNECTED
) {
3140 SCTP_INP_RLOCK(inp
);
3141 stcb
= LIST_FIRST(&inp
->sctp_asoc_list
);
3143 SCTP_TCB_LOCK(stcb
);
3144 net
= sctp_findnet(stcb
, (struct sockaddr
*)&paddrp
->spp_address
);
3146 SCTP_INP_RUNLOCK(inp
);
3148 stcb
= sctp_findassociation_ep_asocid(inp
, paddrp
->spp_assoc_id
);
3155 if ((stcb
== NULL
) &&
3156 ((((struct sockaddr
*)&paddrp
->spp_address
)->sa_family
== AF_INET
) ||
3157 (((struct sockaddr
*)&paddrp
->spp_address
)->sa_family
== AF_INET6
))) {
3158 /* Lookup via address */
3159 if (inp
->sctp_flags
& SCTP_PCB_FLAGS_CONNECTED
) {
3160 SCTP_INP_RLOCK(inp
);
3161 stcb
= LIST_FIRST(&inp
->sctp_asoc_list
);
3163 SCTP_TCB_LOCK(stcb
);
3164 net
= sctp_findnet(stcb
,
3165 (struct sockaddr
*)&paddrp
->spp_address
);
3167 SCTP_INP_RUNLOCK(inp
);
3169 SCTP_INP_WLOCK(inp
);
3170 SCTP_INP_INCR_REF(inp
);
3171 SCTP_INP_WUNLOCK(inp
);
3172 stcb
= sctp_findassociation_ep_addr(&inp
,
3173 (struct sockaddr
*)&paddrp
->spp_address
,
3176 SCTP_INP_WLOCK(inp
);
3177 SCTP_INP_DECR_REF(inp
);
3178 SCTP_INP_WUNLOCK(inp
);
3182 /* Effects the Endpoint */
3186 /* Applies to the specific association */
3187 if (paddrp
->spp_pathmaxrxt
) {
3189 if (paddrp
->spp_pathmaxrxt
)
3190 net
->failure_threshold
= paddrp
->spp_pathmaxrxt
;
3192 if (paddrp
->spp_pathmaxrxt
)
3193 stcb
->asoc
.def_net_failure
= paddrp
->spp_pathmaxrxt
;
3196 if ((paddrp
->spp_hbinterval
!= 0) && (paddrp
->spp_hbinterval
!= 0xffffffff)) {
3200 net
->dest_state
&= ~SCTP_ADDR_NOHB
;
3202 old
= stcb
->asoc
.heart_beat_delay
;
3203 stcb
->asoc
.heart_beat_delay
= paddrp
->spp_hbinterval
;
3205 /* Turn back on the timer */
3206 sctp_timer_start(SCTP_TIMER_TYPE_HEARTBEAT
, inp
, stcb
, net
);
3209 } else if (paddrp
->spp_hbinterval
== 0xffffffff) {
3211 sctp_send_hb(stcb
, 1, net
);
3214 /* off on association */
3215 if (stcb
->asoc
.heart_beat_delay
) {
3216 int cnt_of_unconf
= 0;
3217 struct sctp_nets
*lnet
;
3218 TAILQ_FOREACH(lnet
, &stcb
->asoc
.nets
, sctp_next
) {
3219 if (lnet
->dest_state
& SCTP_ADDR_UNCONFIRMED
) {
3223 /* stop the timer ONLY if we have no unconfirmed addresses
3225 if (cnt_of_unconf
== 0)
3226 sctp_timer_stop(SCTP_TIMER_TYPE_HEARTBEAT
, inp
, stcb
, net
);
3228 stcb
->asoc
.heart_beat_delay
= 0;
3230 net
->dest_state
|= SCTP_ADDR_NOHB
;
3233 SCTP_TCB_UNLOCK(stcb
);
3235 /* Use endpoint defaults */
3236 SCTP_INP_WLOCK(inp
);
3237 if (paddrp
->spp_pathmaxrxt
)
3238 inp
->sctp_ep
.def_net_failure
= paddrp
->spp_pathmaxrxt
;
3239 if (paddrp
->spp_hbinterval
!= SCTP_ISSUE_HB
)
3240 inp
->sctp_ep
.sctp_timeoutticks
[SCTP_TIMER_HEARTBEAT
] = paddrp
->spp_hbinterval
;
3241 SCTP_INP_WUNLOCK(inp
);
3247 struct sctp_rtoinfo
*srto
;
3248 if ((size_t)m
->m_len
< sizeof(struct sctp_rtoinfo
)) {
3252 srto
= mtod(m
, struct sctp_rtoinfo
*);
3253 if (srto
->srto_assoc_id
== 0) {
3254 SCTP_INP_WLOCK(inp
);
3255 /* If we have a null asoc, its default for the endpoint */
3256 if (srto
->srto_initial
> 10)
3257 inp
->sctp_ep
.initial_rto
= srto
->srto_initial
;
3258 if (srto
->srto_max
> 10)
3259 inp
->sctp_ep
.sctp_maxrto
= srto
->srto_max
;
3260 if (srto
->srto_min
> 10)
3261 inp
->sctp_ep
.sctp_minrto
= srto
->srto_min
;
3262 SCTP_INP_WUNLOCK(inp
);
3265 if (inp
->sctp_flags
& SCTP_PCB_FLAGS_CONNECTED
) {
3266 SCTP_INP_RLOCK(inp
);
3267 stcb
= LIST_FIRST(&inp
->sctp_asoc_list
);
3269 SCTP_TCB_LOCK(stcb
);
3270 SCTP_INP_RUNLOCK(inp
);
3272 stcb
= sctp_findassociation_ep_asocid(inp
, srto
->srto_assoc_id
);
3277 /* Set in ms we hope :-) */
3278 if (srto
->srto_initial
> 10)
3279 stcb
->asoc
.initial_rto
= srto
->srto_initial
;
3280 if (srto
->srto_max
> 10)
3281 stcb
->asoc
.maxrto
= srto
->srto_max
;
3282 if (srto
->srto_min
> 10)
3283 stcb
->asoc
.minrto
= srto
->srto_min
;
3284 SCTP_TCB_UNLOCK(stcb
);
3287 case SCTP_ASSOCINFO
:
3289 struct sctp_assocparams
*sasoc
;
3291 if ((size_t)m
->m_len
< sizeof(struct sctp_assocparams
)) {
3295 sasoc
= mtod(m
, struct sctp_assocparams
*);
3296 if (sasoc
->sasoc_assoc_id
) {
3297 if (inp
->sctp_flags
& SCTP_PCB_FLAGS_CONNECTED
) {
3298 SCTP_INP_RLOCK(inp
);
3299 stcb
= LIST_FIRST(&inp
->sctp_asoc_list
);
3301 SCTP_TCB_LOCK(stcb
);
3302 SCTP_INP_RUNLOCK(inp
);
3304 stcb
= sctp_findassociation_ep_asocid(inp
,
3305 sasoc
->sasoc_assoc_id
);
3315 if (sasoc
->sasoc_asocmaxrxt
)
3316 stcb
->asoc
.max_send_times
= sasoc
->sasoc_asocmaxrxt
;
3317 sasoc
->sasoc_number_peer_destinations
= stcb
->asoc
.numnets
;
3318 sasoc
->sasoc_peer_rwnd
= 0;
3319 sasoc
->sasoc_local_rwnd
= 0;
3320 if (stcb
->asoc
.cookie_life
)
3321 stcb
->asoc
.cookie_life
= sasoc
->sasoc_cookie_life
;
3322 SCTP_TCB_UNLOCK(stcb
);
3324 SCTP_INP_WLOCK(inp
);
3325 if (sasoc
->sasoc_asocmaxrxt
)
3326 inp
->sctp_ep
.max_send_times
= sasoc
->sasoc_asocmaxrxt
;
3327 sasoc
->sasoc_number_peer_destinations
= 0;
3328 sasoc
->sasoc_peer_rwnd
= 0;
3329 sasoc
->sasoc_local_rwnd
= 0;
3330 if (sasoc
->sasoc_cookie_life
)
3331 inp
->sctp_ep
.def_cookie_life
= sasoc
->sasoc_cookie_life
;
3332 SCTP_INP_WUNLOCK(inp
);
3338 struct sctp_initmsg
*sinit
;
3340 if ((size_t)m
->m_len
< sizeof(struct sctp_initmsg
)) {
3344 sinit
= mtod(m
, struct sctp_initmsg
*);
3345 SCTP_INP_WLOCK(inp
);
3346 if (sinit
->sinit_num_ostreams
)
3347 inp
->sctp_ep
.pre_open_stream_count
= sinit
->sinit_num_ostreams
;
3349 if (sinit
->sinit_max_instreams
)
3350 inp
->sctp_ep
.max_open_streams_intome
= sinit
->sinit_max_instreams
;
3352 if (sinit
->sinit_max_attempts
)
3353 inp
->sctp_ep
.max_init_times
= sinit
->sinit_max_attempts
;
3355 if (sinit
->sinit_max_init_timeo
> 10)
3356 /* We must be at least a 100ms (we set in ticks) */
3357 inp
->sctp_ep
.initial_init_rto_max
= sinit
->sinit_max_init_timeo
;
3358 SCTP_INP_WUNLOCK(inp
);
3361 case SCTP_PRIMARY_ADDR
:
3363 struct sctp_setprim
*spa
;
3364 struct sctp_nets
*net
, *lnet
;
3365 if ((size_t)m
->m_len
< sizeof(struct sctp_setprim
)) {
3369 spa
= mtod(m
, struct sctp_setprim
*);
3371 if (inp
->sctp_flags
& SCTP_PCB_FLAGS_CONNECTED
) {
3372 SCTP_INP_RLOCK(inp
);
3373 stcb
= LIST_FIRST(&inp
->sctp_asoc_list
);
3375 SCTP_TCB_LOCK(stcb
);
3380 SCTP_INP_RUNLOCK(inp
);
3382 stcb
= sctp_findassociation_ep_asocid(inp
, spa
->ssp_assoc_id
);
3385 SCTP_INP_WLOCK(inp
);
3386 SCTP_INP_INCR_REF(inp
);
3387 SCTP_INP_WUNLOCK(inp
);
3388 stcb
= sctp_findassociation_ep_addr(&inp
,
3389 (struct sockaddr
*)&spa
->ssp_addr
,
3392 SCTP_INP_WLOCK(inp
);
3393 SCTP_INP_DECR_REF(inp
);
3394 SCTP_INP_WUNLOCK(inp
);
3399 /* find the net, associd or connected lookup type */
3400 net
= sctp_findnet(stcb
, (struct sockaddr
*)&spa
->ssp_addr
);
3402 SCTP_TCB_UNLOCK(stcb
);
3407 if ((net
!= stcb
->asoc
.primary_destination
) &&
3408 (!(net
->dest_state
& SCTP_ADDR_UNCONFIRMED
))) {
3409 /* Ok we need to set it */
3410 lnet
= stcb
->asoc
.primary_destination
;
3411 lnet
->next_tsn_at_change
= net
->next_tsn_at_change
= stcb
->asoc
.sending_seq
;
3412 if (sctp_set_primary_addr(stcb
,
3413 (struct sockaddr
*)NULL
,
3415 if (net
->dest_state
& SCTP_ADDR_SWITCH_PRIMARY
) {
3416 net
->dest_state
|= SCTP_ADDR_DOUBLE_SWITCH
;
3418 net
->dest_state
|= SCTP_ADDR_SWITCH_PRIMARY
;
3421 SCTP_TCB_UNLOCK(stcb
);
3425 case SCTP_SET_PEER_PRIMARY_ADDR
:
3427 struct sctp_setpeerprim
*sspp
;
3428 if ((size_t)m
->m_len
< sizeof(struct sctp_setpeerprim
)) {
3432 sspp
= mtod(m
, struct sctp_setpeerprim
*);
3435 if (inp
->sctp_flags
& SCTP_PCB_FLAGS_CONNECTED
) {
3436 SCTP_INP_RLOCK(inp
);
3437 stcb
= LIST_FIRST(&inp
->sctp_asoc_list
);
3439 SCTP_TCB_UNLOCK(stcb
);
3440 SCTP_INP_RUNLOCK(inp
);
3442 stcb
= sctp_findassociation_ep_asocid(inp
, sspp
->sspp_assoc_id
);
3447 if (sctp_set_primary_ip_address_sa(stcb
, (struct sockaddr
*)&sspp
->sspp_addr
) != 0) {
3450 SCTP_TCB_UNLOCK(stcb
);
3453 case SCTP_BINDX_ADD_ADDR
:
3455 struct sctp_getaddresses
*addrs
;
3456 struct sockaddr
*addr_touse
;
3457 struct sockaddr_in sin
;
3458 /* see if we're bound all already! */
3459 if (inp
->sctp_flags
& SCTP_PCB_FLAGS_BOUNDALL
) {
3463 if ((size_t)m
->m_len
< sizeof(struct sctp_getaddresses
)) {
3467 addrs
= mtod(m
, struct sctp_getaddresses
*);
3468 addr_touse
= addrs
->addr
;
3469 if (addrs
->addr
->sa_family
== AF_INET6
) {
3470 struct sockaddr_in6
*sin6
;
3471 sin6
= (struct sockaddr_in6
*)addr_touse
;
3472 if (IN6_IS_ADDR_V4MAPPED(&sin6
->sin6_addr
)) {
3473 in6_sin6_2_sin(&sin
, sin6
);
3474 addr_touse
= (struct sockaddr
*)&sin
;
3477 if (inp
->sctp_flags
& SCTP_PCB_FLAGS_UNBOUND
) {
3479 /* Can't get proc for Net/Open BSD */
3483 error
= sctp_inpcb_bind(so
, addr_touse
, p
);
3486 /* No locks required here since bind and mgmt_ep_sa all
3487 * do their own locking. If we do something for the FIX:
3488 * below we may need to lock in that case.
3490 if (addrs
->sget_assoc_id
== 0) {
3491 /* add the address */
3492 struct sctp_inpcb
*lep
;
3493 ((struct sockaddr_in
*)addr_touse
)->sin_port
= inp
->sctp_lport
;
3494 lep
= sctp_pcb_findep(addr_touse
, 1, 0);
3496 /* We must decrement the refcount
3497 * since we have the ep already and
3498 * are binding. No remove going on
3501 SCTP_INP_WLOCK(inp
);
3502 SCTP_INP_DECR_REF(inp
);
3503 SCTP_INP_WUNLOCK(inp
);
3506 /* already bound to it.. ok */
3508 } else if (lep
== NULL
) {
3509 ((struct sockaddr_in
*)addr_touse
)->sin_port
= 0;
3510 error
= sctp_addr_mgmt_ep_sa(inp
, addr_touse
,
3511 SCTP_ADD_IP_ADDRESS
);
3513 error
= EADDRNOTAVAIL
;
3519 /* FIX: decide whether we allow assoc based bindx */
3523 case SCTP_BINDX_REM_ADDR
:
3525 struct sctp_getaddresses
*addrs
;
3526 struct sockaddr
*addr_touse
;
3527 struct sockaddr_in sin
;
3528 /* see if we're bound all already! */
3529 if (inp
->sctp_flags
& SCTP_PCB_FLAGS_BOUNDALL
) {
3533 if ((size_t)m
->m_len
< sizeof(struct sctp_getaddresses
)) {
3537 addrs
= mtod(m
, struct sctp_getaddresses
*);
3538 addr_touse
= addrs
->addr
;
3539 if (addrs
->addr
->sa_family
== AF_INET6
) {
3540 struct sockaddr_in6
*sin6
;
3541 sin6
= (struct sockaddr_in6
*)addr_touse
;
3542 if (IN6_IS_ADDR_V4MAPPED(&sin6
->sin6_addr
)) {
3543 in6_sin6_2_sin(&sin
, sin6
);
3544 addr_touse
= (struct sockaddr
*)&sin
;
3547 /* No lock required mgmt_ep_sa does its own locking. If
3548 * the FIX: below is ever changed we may need to
3549 * lock before calling association level binding.
3551 if (addrs
->sget_assoc_id
== 0) {
3552 /* delete the address */
3553 sctp_addr_mgmt_ep_sa(inp
, addr_touse
,
3554 SCTP_DEL_IP_ADDRESS
);
3556 /* FIX: decide whether we allow assoc based bindx */
3561 error
= ENOPROTOOPT
;
3563 } /* end switch (opt) */
3568 #if defined(__FreeBSD__) || defined(__APPLE__) || defined(__DragonFly__)
3570 sctp_ctloutput(struct socket
*so
, struct sockopt
*sopt
)
3572 struct mbuf
*m
= NULL
;
3573 struct sctp_inpcb
*inp
;
3576 inp
= (struct sctp_inpcb
*)so
->so_pcb
;
3580 /* I made the same as TCP since we are not setup? */
3581 return (ECONNRESET
);
3583 if (sopt
->sopt_level
!= IPPROTO_SCTP
) {
3584 /* wrong proto level... send back up to IP */
3586 if (INP_CHECK_SOCKAF(so
, AF_INET6
))
3587 error
= ip6_ctloutput(so
, sopt
);
3590 error
= ip_ctloutput(so
, sopt
);
3594 if (sopt
->sopt_valsize
> MCLBYTES
) {
3596 * Restrict us down to a cluster size, that's all we can
3597 * pass either way...
3599 sopt
->sopt_valsize
= MCLBYTES
;
3601 if (sopt
->sopt_valsize
) {
3603 m
= m_get(MB_WAIT
, MT_DATA
);
3604 if (sopt
->sopt_valsize
> MLEN
) {
3605 MCLGET(m
, MB_DONTWAIT
);
3606 if ((m
->m_flags
& M_EXT
) == 0) {
3612 error
= sooptcopyin(sopt
, mtod(m
, caddr_t
), sopt
->sopt_valsize
,
3613 sopt
->sopt_valsize
);
3618 m
->m_len
= sopt
->sopt_valsize
;
3620 if (sopt
->sopt_dir
== SOPT_SET
) {
3621 #if (defined(__FreeBSD__) && __FreeBSD_version >= 500000) || defined(__DragonFly__)
3622 error
= sctp_optsset(so
, sopt
->sopt_name
, &m
, sopt
->sopt_td
);
3624 error
= sctp_optsset(so
, sopt
->sopt_name
, &m
, sopt
->sopt_p
);
3626 } else if (sopt
->sopt_dir
== SOPT_GET
) {
3627 #if (defined (__FreeBSD__) && __FreeBSD_version >= 500000) || defined(__DragonFly__)
3628 error
= sctp_optsget(so
, sopt
->sopt_name
, &m
, sopt
->sopt_td
);
3630 error
= sctp_optsget(so
, sopt
->sopt_name
, &m
, sopt
->sopt_p
);
3635 if ( (error
== 0) && (m
!= NULL
)) {
3636 error
= sooptcopyout(sopt
, mtod(m
, caddr_t
), m
->m_len
);
3638 } else if (m
!= NULL
) {
3647 /* NetBSD and OpenBSD */
3649 sctp_ctloutput(int op
, struct socket
*so
, int level
, int optname
,
3655 struct in6pcb
*in6p
;
3657 int family
; /* family of the socket */
3659 family
= so
->so_proto
->pr_domain
->dom_family
;
3664 inp
= sotoinpcb(so
);
3672 in6p
= sotoin6pcb(so
);
3677 return EAFNOSUPPORT
;
3682 if (inp
== NULL
&& in6p
== NULL
)
3686 if (op
== PRCO_SETOPT
&& *mp
)
3688 return (ECONNRESET
);
3690 if (level
!= IPPROTO_SCTP
) {
3693 error
= ip_ctloutput(op
, so
, level
, optname
, mp
);
3697 error
= ip6_ctloutput(op
, so
, level
, optname
, mp
);
3704 /* Ok if we reach here it is a SCTP option we hope */
3705 if (op
== PRCO_SETOPT
) {
3706 error
= sctp_optsset(so
, optname
, mp
, (struct proc
*)NULL
);
3709 } else if (op
== PRCO_GETOPT
) {
3710 error
= sctp_optsget(so
, optname
, mp
, (struct proc
*)NULL
);
3721 #if (defined(__FreeBSD__) && __FreeBSD_version >= 500000) || defined(__DragonFly__)
3722 sctp_connect(struct socket
*so
, struct sockaddr
*addr
, struct thread
*p
)
3725 #if defined(__FreeBSD__) || defined(__APPLE__)
3726 sctp_connect(struct socket
*so
, struct sockaddr
*addr
, struct proc
*p
)
3729 sctp_connect(struct socket
*so
, struct mbuf
*nam
, struct proc
*p
)
3731 struct sockaddr
*addr
= mtod(nam
, struct sockaddr
*);
3735 struct sctp_inpcb
*inp
;
3736 struct sctp_tcb
*stcb
;
3739 if (sctp_debug_on
& SCTP_DEBUG_PCB1
) {
3740 kprintf("Connect called in SCTP to ");
3741 sctp_print_address(addr
);
3742 kprintf("Port %d\n", ntohs(((struct sockaddr_in
*)addr
)->sin_port
));
3744 #endif /* SCTP_DEBUG */
3746 inp
= (struct sctp_inpcb
*)so
->so_pcb
;
3749 /* I made the same as TCP since we are not setup? */
3750 return (ECONNRESET
);
3752 SCTP_ASOC_CREATE_LOCK(inp
);
3753 SCTP_INP_WLOCK(inp
);
3754 if ((inp
->sctp_flags
& SCTP_PCB_FLAGS_SOCKET_GONE
) ||
3755 (inp
->sctp_flags
& SCTP_PCB_FLAGS_SOCKET_GONE
)) {
3756 /* Should I really unlock ? */
3757 SCTP_INP_WUNLOCK(inp
);
3758 SCTP_ASOC_CREATE_UNLOCK(inp
);
3763 if (((inp
->sctp_flags
& SCTP_PCB_FLAGS_BOUND_V6
) == 0) &&
3764 (addr
->sa_family
== AF_INET6
)) {
3765 SCTP_INP_WUNLOCK(inp
);
3766 SCTP_ASOC_CREATE_UNLOCK(inp
);
3771 if ((inp
->sctp_flags
& SCTP_PCB_FLAGS_UNBOUND
) ==
3772 SCTP_PCB_FLAGS_UNBOUND
) {
3773 /* Bind a ephemeral port */
3774 SCTP_INP_WUNLOCK(inp
);
3775 error
= sctp_inpcb_bind(so
, NULL
, p
);
3777 SCTP_ASOC_CREATE_UNLOCK(inp
);
3781 SCTP_INP_WLOCK(inp
);
3783 /* Now do we connect? */
3784 if ((inp
->sctp_flags
& SCTP_PCB_FLAGS_TCPTYPE
) &&
3785 (inp
->sctp_flags
& SCTP_PCB_FLAGS_CONNECTED
)) {
3786 /* We are already connected AND the TCP model */
3788 SCTP_INP_WUNLOCK(inp
);
3789 SCTP_ASOC_CREATE_UNLOCK(inp
);
3790 return (EADDRINUSE
);
3792 if (inp
->sctp_flags
& SCTP_PCB_FLAGS_CONNECTED
) {
3793 stcb
= LIST_FIRST(&inp
->sctp_asoc_list
);
3795 SCTP_TCB_UNLOCK(stcb
);
3796 SCTP_INP_WUNLOCK(inp
);
3798 SCTP_INP_INCR_REF(inp
);
3799 SCTP_INP_WUNLOCK(inp
);
3800 stcb
= sctp_findassociation_ep_addr(&inp
, addr
, NULL
, NULL
, NULL
);
3802 SCTP_INP_WLOCK(inp
);
3803 SCTP_INP_DECR_REF(inp
);
3804 SCTP_INP_WUNLOCK(inp
);
3808 /* Already have or am bring up an association */
3809 SCTP_ASOC_CREATE_UNLOCK(inp
);
3810 SCTP_TCB_UNLOCK(stcb
);
3814 /* We are GOOD to go */
3815 stcb
= sctp_aloc_assoc(inp
, addr
, 1, &error
, 0);
3817 /* Gak! no memory */
3821 if (stcb
->sctp_ep
->sctp_flags
& SCTP_PCB_FLAGS_TCPTYPE
) {
3822 stcb
->sctp_ep
->sctp_flags
|= SCTP_PCB_FLAGS_CONNECTED
;
3823 /* Set the connected flag so we can queue data */
3826 stcb
->asoc
.state
= SCTP_STATE_COOKIE_WAIT
;
3827 SCTP_GETTIME_TIMEVAL(&stcb
->asoc
.time_entered
);
3828 sctp_send_initiate(inp
, stcb
);
3829 SCTP_ASOC_CREATE_UNLOCK(inp
);
3830 SCTP_TCB_UNLOCK(stcb
);
3836 sctp_usr_recvd(struct socket
*so
, int flags
)
3838 struct sctp_socket_q_list
*sq
=NULL
;
3840 * The user has received some data, we may be able to stuff more
3841 * up the socket. And we need to possibly update the rwnd.
3843 struct sctp_inpcb
*inp
;
3844 struct sctp_tcb
*stcb
=NULL
;
3846 inp
= (struct sctp_inpcb
*)so
->so_pcb
;
3848 if (sctp_debug_on
& SCTP_DEBUG_USRREQ2
)
3849 kprintf("Read for so:%x inp:%x Flags:%x\n",
3850 (u_int
)so
, (u_int
)inp
, (u_int
)flags
);
3854 /* I made the same as TCP since we are not setup? */
3856 if (sctp_debug_on
& SCTP_DEBUG_USRREQ2
)
3857 kprintf("Nope, connection reset\n");
3859 return (ECONNRESET
);
3863 * Grab the first one on the list. It will re-insert itself if
3864 * it runs out of room
3866 SCTP_INP_WLOCK(inp
);
3867 if ((flags
& MSG_EOR
) && ((inp
->sctp_flags
& SCTP_PCB_FLAGS_IN_TCPPOOL
) == 0)
3868 && ((inp
->sctp_flags
& SCTP_PCB_FLAGS_CONNECTED
) == 0)) {
3869 /* Ok the other part of our grubby tracking
3870 * stuff for our horrible layer violation that
3871 * the tsvwg thinks is ok for sctp_peeloff.. gak!
3872 * We must update the next vtag pending on the
3873 * socket buffer (if any).
3875 inp
->sctp_vtag_first
= sctp_get_first_vtag_from_sb(so
);
3876 sq
= TAILQ_FIRST(&inp
->sctp_queue_list
);
3883 stcb
= LIST_FIRST(&inp
->sctp_asoc_list
);
3886 SCTP_TCB_LOCK(stcb
);
3889 /* all code in normal stcb path assumes
3890 * that you have a tcb_lock only. Thus
3891 * we must release the inp write lock.
3893 if (flags
& MSG_EOR
) {
3894 if (((inp
->sctp_flags
& SCTP_PCB_FLAGS_IN_TCPPOOL
) == 0)
3895 && ((inp
->sctp_flags
& SCTP_PCB_FLAGS_CONNECTED
) == 0)) {
3896 stcb
= sctp_remove_from_socket_q(inp
);
3899 if (sctp_debug_on
& SCTP_DEBUG_USRREQ2
)
3900 kprintf("remove from socket queue for inp:%x tcbret:%x\n",
3901 (u_int
)inp
, (u_int
)stcb
);
3904 stcb
->asoc
.my_rwnd_control_len
= sctp_sbspace_sub(stcb
->asoc
.my_rwnd_control_len
,
3905 sizeof(struct mbuf
));
3906 if (inp
->sctp_flags
& SCTP_PCB_FLAGS_RECVDATAIOEVNT
) {
3907 stcb
->asoc
.my_rwnd_control_len
= sctp_sbspace_sub(stcb
->asoc
.my_rwnd_control_len
,
3908 CMSG_LEN(sizeof(struct sctp_sndrcvinfo
)));
3911 if ((TAILQ_EMPTY(&stcb
->asoc
.delivery_queue
) == 0) ||
3912 (TAILQ_EMPTY(&stcb
->asoc
.reasmqueue
) == 0)) {
3913 /* Deliver if there is something to be delivered */
3914 sctp_service_queues(stcb
, &stcb
->asoc
, 1);
3916 sctp_set_rwnd(stcb
, &stcb
->asoc
);
3917 /* if we increase by 1 or more MTU's (smallest MTUs of all
3918 * nets) we send a window update sack
3920 incr
= stcb
->asoc
.my_rwnd
- stcb
->asoc
.my_last_reported_rwnd
;
3924 if (((uint32_t)incr
>= (stcb
->asoc
.smallest_mtu
* SCTP_SEG_TO_RWND_UPD
)) ||
3925 ((((uint32_t)incr
)*SCTP_SCALE_OF_RWND_TO_UPD
) >= so
->so_rcv
.ssb_hiwat
)) {
3926 if (callout_pending(&stcb
->asoc
.dack_timer
.timer
)) {
3927 /* If the timer is up, stop it */
3928 sctp_timer_stop(SCTP_TIMER_TYPE_RECV
,
3929 stcb
->sctp_ep
, stcb
, NULL
);
3931 /* Send the sack, with the new rwnd */
3932 sctp_send_sack(stcb
);
3933 /* Now do the output */
3934 sctp_chunk_output(inp
, stcb
, 10);
3937 if ((( sq
) && (flags
& MSG_EOR
) && ((inp
->sctp_flags
& SCTP_PCB_FLAGS_IN_TCPPOOL
) == 0))
3938 && ((inp
->sctp_flags
& SCTP_PCB_FLAGS_CONNECTED
) == 0)) {
3939 stcb
= sctp_remove_from_socket_q(inp
);
3942 SOCKBUF_LOCK(&so
->so_rcv
);
3943 if (( so
->so_rcv
.ssb_mb
== NULL
) &&
3944 (TAILQ_EMPTY(&inp
->sctp_queue_list
) == 0)) {
3947 if (sctp_debug_on
& SCTP_DEBUG_USRREQ2
)
3948 kprintf("Something off, inp:%x so->so_rcv->ssb_mb is empty and sockq is not.. cleaning\n",
3951 if (((inp
->sctp_flags
& SCTP_PCB_FLAGS_IN_TCPPOOL
) == 0)
3952 && ((inp
->sctp_flags
& SCTP_PCB_FLAGS_CONNECTED
) == 0)) {
3954 done_yet
= TAILQ_EMPTY(&inp
->sctp_queue_list
);
3957 sctp_remove_from_socket_q(inp
);
3958 done_yet
= TAILQ_EMPTY(&inp
->sctp_queue_list
);
3962 if (sctp_debug_on
& SCTP_DEBUG_USRREQ2
)
3963 kprintf("Cleaned up %d sockq's\n", sq_cnt
);
3966 SOCKBUF_UNLOCK(&so
->so_rcv
);
3968 SCTP_TCB_UNLOCK(stcb
);
3969 SCTP_INP_WUNLOCK(inp
);
3975 #if (defined(__FreeBSD__) && __FreeBSD_version >= 500000) || defined(__DragonFly__)
3976 sctp_listen(struct socket
*so
, struct thread
*p
)
3978 sctp_listen(struct socket
*so
, struct proc
*p
)
3982 * Note this module depends on the protocol processing being
3983 * called AFTER any socket level flags and backlog are applied
3984 * to the socket. The traditional way that the socket flags are
3985 * applied is AFTER protocol processing. We have made a change
3986 * to the sys/kern/uipc_socket.c module to reverse this but this
3987 * MUST be in place if the socket API for SCTP is to work properly.
3990 struct sctp_inpcb
*inp
;
3993 inp
= (struct sctp_inpcb
*)so
->so_pcb
;
3996 /* I made the same as TCP since we are not setup? */
3997 return (ECONNRESET
);
3999 SCTP_INP_RLOCK(inp
);
4000 if ((inp
->sctp_flags
& SCTP_PCB_FLAGS_TCPTYPE
) &&
4001 (inp
->sctp_flags
& SCTP_PCB_FLAGS_CONNECTED
)) {
4002 /* We are already connected AND the TCP model */
4004 SCTP_INP_RUNLOCK(inp
);
4005 return (EADDRINUSE
);
4007 if (inp
->sctp_flags
& SCTP_PCB_FLAGS_UNBOUND
) {
4008 /* We must do a bind. */
4009 SCTP_INP_RUNLOCK(inp
);
4010 if ((error
= sctp_inpcb_bind(so
, NULL
, p
))) {
4011 /* bind error, probably perm */
4016 SCTP_INP_RUNLOCK(inp
);
4019 SCTP_INP_WLOCK(inp
);
4020 if (inp
->sctp_socket
->so_qlimit
) {
4021 if (inp
->sctp_flags
& SCTP_PCB_FLAGS_UDPTYPE
) {
4023 * For the UDP model we must TURN OFF the ACCEPT
4024 * flags since we do NOT allow the accept() call.
4025 * The TCP model (when present) will do accept which
4026 * then prohibits connect().
4028 inp
->sctp_socket
->so_options
&= ~SO_ACCEPTCONN
;
4030 inp
->sctp_flags
|= SCTP_PCB_FLAGS_ACCEPTING
;
4032 if (inp
->sctp_flags
& SCTP_PCB_FLAGS_ACCEPTING
) {
4034 * Turning off the listen flags if the backlog is
4035 * set to 0 (i.e. qlimit is 0).
4037 inp
->sctp_flags
&= ~SCTP_PCB_FLAGS_ACCEPTING
;
4039 inp
->sctp_socket
->so_options
&= ~SO_ACCEPTCONN
;
4041 SCTP_INP_WUNLOCK(inp
);
4048 #if defined(__FreeBSD__) || defined(__APPLE__) || defined(__DragonFly__)
4049 sctp_accept(struct socket
*so
, struct sockaddr
**addr
)
4052 sctp_accept(struct socket
*so
, struct mbuf
*nam
)
4054 struct sockaddr
*addr
= mtod(nam
, struct sockaddr
*);
4056 struct sctp_tcb
*stcb
;
4057 struct sockaddr
*prim
;
4058 struct sctp_inpcb
*inp
;
4061 inp
= (struct sctp_inpcb
*)so
->so_pcb
;
4065 return (ECONNRESET
);
4067 SCTP_INP_RLOCK(inp
);
4068 if (so
->so_state
& SS_ISDISCONNECTED
) {
4070 SCTP_INP_RUNLOCK(inp
);
4071 return (ECONNABORTED
);
4073 stcb
= LIST_FIRST(&inp
->sctp_asoc_list
);
4076 SCTP_INP_RUNLOCK(inp
);
4077 return (ECONNRESET
);
4079 SCTP_TCB_LOCK(stcb
);
4080 SCTP_INP_RUNLOCK(inp
);
4081 prim
= (struct sockaddr
*)&stcb
->asoc
.primary_destination
->ro
._l_addr
;
4082 if (prim
->sa_family
== AF_INET
) {
4083 struct sockaddr_in
*sin
;
4084 #if defined(__FreeBSD__) || defined(__APPLE__) || defined(__DragonFly__)
4085 MALLOC(sin
, struct sockaddr_in
*, sizeof *sin
, M_SONAME
,
4088 sin
= (struct sockaddr_in
*)addr
;
4089 bzero((caddr_t
)sin
, sizeof (*sin
));
4091 sin
->sin_family
= AF_INET
;
4092 sin
->sin_len
= sizeof(*sin
);
4093 sin
->sin_port
= ((struct sockaddr_in
*)prim
)->sin_port
;
4094 sin
->sin_addr
= ((struct sockaddr_in
*)prim
)->sin_addr
;
4095 #if defined(__FreeBSD__) || defined(__APPLE__) || defined(__DragonFly__)
4096 *addr
= (struct sockaddr
*)sin
;
4098 nam
->m_len
= sizeof(*sin
);
4101 struct sockaddr_in6
*sin6
;
4102 #if defined(__FreeBSD__) || defined(__APPLE__) || defined(__DragonFly__)
4103 MALLOC(sin6
, struct sockaddr_in6
*, sizeof *sin6
, M_SONAME
,
4106 sin6
= (struct sockaddr_in6
*)addr
;
4108 bzero((caddr_t
)sin6
, sizeof (*sin6
));
4109 sin6
->sin6_family
= AF_INET6
;
4110 sin6
->sin6_len
= sizeof(*sin6
);
4111 sin6
->sin6_port
= ((struct sockaddr_in6
*)prim
)->sin6_port
;
4113 sin6
->sin6_addr
= ((struct sockaddr_in6
*)prim
)->sin6_addr
;
4114 if (IN6_IS_SCOPE_LINKLOCAL(&sin6
->sin6_addr
))
4115 /* sin6->sin6_scope_id = ntohs(sin6->sin6_addr.s6_addr16[1]);*/
4116 in6_recoverscope(sin6
, &sin6
->sin6_addr
, NULL
); /* skip ifp check */
4118 sin6
->sin6_scope_id
= 0; /*XXX*/
4119 #if defined(__FreeBSD__) || defined (__APPLE__) || defined(__DragonFly__)
4120 *addr
= (struct sockaddr
*)sin6
;
4122 nam
->m_len
= sizeof(*sin6
);
4125 /* Wake any delayed sleep action */
4126 SCTP_TCB_UNLOCK(stcb
);
4127 SCTP_INP_WLOCK(inp
);
4128 if (inp
->sctp_flags
& SCTP_PCB_FLAGS_DONT_WAKE
) {
4129 inp
->sctp_flags
&= ~SCTP_PCB_FLAGS_DONT_WAKE
;
4130 if (inp
->sctp_flags
& SCTP_PCB_FLAGS_WAKEOUTPUT
) {
4131 inp
->sctp_flags
&= ~SCTP_PCB_FLAGS_WAKEOUTPUT
;
4132 #if defined(__NetBSD__)
4133 if (sowritable(inp
->sctp_socket
))
4134 sowwakeup(inp
->sctp_socket
);
4136 if (sowriteable(inp
->sctp_socket
))
4137 sowwakeup(inp
->sctp_socket
);
4140 if (inp
->sctp_flags
& SCTP_PCB_FLAGS_WAKEINPUT
) {
4141 inp
->sctp_flags
&= ~SCTP_PCB_FLAGS_WAKEINPUT
;
4142 if (soreadable(inp
->sctp_socket
))
4143 sorwakeup(inp
->sctp_socket
);
4147 SCTP_INP_WUNLOCK(inp
);
4153 #if defined(__FreeBSD__) || defined(__APPLE__) || defined(__DragonFly__)
4154 sctp_ingetaddr(struct socket
*so
, struct sockaddr
**addr
)
4156 sctp_ingetaddr(struct socket
*so
, struct mbuf
*nam
)
4159 #if defined(__FreeBSD__) || defined(__APPLE__) || defined(__DragonFly__)
4160 struct sockaddr_in
*sin
;
4162 struct sockaddr_in
*sin
= mtod(nam
, struct sockaddr_in
*);
4164 struct sctp_inpcb
*inp
;
4166 * Do the malloc first in case it blocks.
4168 #if defined(__FreeBSD__) || defined(__APPLE__) || defined(__DragonFly__)
4169 MALLOC(sin
, struct sockaddr_in
*, sizeof *sin
, M_SONAME
, M_WAITOK
|
4172 nam
->m_len
= sizeof(*sin
);
4173 memset(sin
, 0, sizeof(*sin
));
4175 sin
->sin_family
= AF_INET
;
4176 sin
->sin_len
= sizeof(*sin
);
4178 inp
= (struct sctp_inpcb
*)so
->so_pcb
;
4181 #if defined(__FreeBSD__) || defined(__APPLE__) || defined(__DragonFly__)
4182 FREE(sin
, M_SONAME
);
4186 SCTP_INP_RLOCK(inp
);
4187 sin
->sin_port
= inp
->sctp_lport
;
4188 if (inp
->sctp_flags
& SCTP_PCB_FLAGS_BOUNDALL
) {
4189 if (inp
->sctp_flags
& SCTP_PCB_FLAGS_CONNECTED
) {
4190 struct sctp_tcb
*stcb
;
4191 struct sockaddr_in
*sin_a
;
4192 struct sctp_nets
*net
;
4195 stcb
= LIST_FIRST(&inp
->sctp_asoc_list
);
4201 SCTP_TCB_LOCK(stcb
);
4202 TAILQ_FOREACH(net
, &stcb
->asoc
.nets
, sctp_next
) {
4203 sin_a
= (struct sockaddr_in
*)&net
->ro
._l_addr
;
4204 if (sin_a
->sin_family
== AF_INET
) {
4209 if ((!fnd
) || (sin_a
== NULL
)) {
4211 SCTP_TCB_UNLOCK(stcb
);
4214 sin
->sin_addr
= sctp_ipv4_source_address_selection(inp
,
4215 stcb
, (struct route
*)&net
->ro
, net
, 0);
4216 SCTP_TCB_UNLOCK(stcb
);
4218 /* For the bound all case you get back 0 */
4220 sin
->sin_addr
.s_addr
= 0;
4224 /* Take the first IPv4 address in the list */
4225 struct sctp_laddr
*laddr
;
4227 LIST_FOREACH(laddr
, &inp
->sctp_addr_list
, sctp_nxt_addr
) {
4228 if (laddr
->ifa
->ifa_addr
->sa_family
== AF_INET
) {
4229 struct sockaddr_in
*sin_a
;
4230 sin_a
= (struct sockaddr_in
*)laddr
->ifa
->ifa_addr
;
4231 sin
->sin_addr
= sin_a
->sin_addr
;
4238 #if defined(__FreeBSD__) || defined(__APPLE__) || defined(__DragonFly__)
4239 FREE(sin
, M_SONAME
);
4241 SCTP_INP_RUNLOCK(inp
);
4245 SCTP_INP_RUNLOCK(inp
);
4247 #if defined(__FreeBSD__) || defined(__APPLE__) || defined(__DragonFly__)
4248 (*addr
) = (struct sockaddr
*)sin
;
4254 #if defined(__FreeBSD__) || defined(__APPLE__) || defined(__DragonFly__)
4255 sctp_peeraddr(struct socket
*so
, struct sockaddr
**addr
)
4257 struct sockaddr_in
*sin
= (struct sockaddr_in
*)*addr
;
4259 sctp_peeraddr(struct socket
*so
, struct mbuf
*nam
)
4261 struct sockaddr_in
*sin
= mtod(nam
, struct sockaddr_in
*);
4264 struct sockaddr_in
*sin_a
;
4265 struct sctp_inpcb
*inp
;
4266 struct sctp_tcb
*stcb
;
4267 struct sctp_nets
*net
;
4269 /* Do the malloc first in case it blocks. */
4270 inp
= (struct sctp_inpcb
*)so
->so_pcb
;
4271 if ((inp
== NULL
) ||
4272 ((inp
->sctp_flags
& SCTP_PCB_FLAGS_CONNECTED
) == 0)) {
4273 /* UDP type and listeners will drop out here */
4278 #if defined(__FreeBSD__) || defined(__APPLE__) || defined(__DragonFly__)
4279 MALLOC(sin
, struct sockaddr_in
*, sizeof *sin
, M_SONAME
, M_WAITOK
|
4282 nam
->m_len
= sizeof(*sin
);
4283 memset(sin
, 0, sizeof(*sin
));
4285 sin
->sin_family
= AF_INET
;
4286 sin
->sin_len
= sizeof(*sin
);
4288 /* We must recapture incase we blocked */
4289 inp
= (struct sctp_inpcb
*)so
->so_pcb
;
4292 #if defined(__FreeBSD__) || defined(__APPLE__) || defined(__DragonFly__)
4293 FREE(sin
, M_SONAME
);
4297 SCTP_INP_RLOCK(inp
);
4298 stcb
= LIST_FIRST(&inp
->sctp_asoc_list
);
4300 SCTP_TCB_LOCK(stcb
);
4301 SCTP_INP_RUNLOCK(inp
);
4304 #if defined(__FreeBSD__) || defined(__APPLE__) || defined(__DragonFly__)
4305 FREE(sin
, M_SONAME
);
4310 TAILQ_FOREACH(net
, &stcb
->asoc
.nets
, sctp_next
) {
4311 sin_a
= (struct sockaddr_in
*)&net
->ro
._l_addr
;
4312 if (sin_a
->sin_family
== AF_INET
) {
4314 sin
->sin_port
= stcb
->rport
;
4315 sin
->sin_addr
= sin_a
->sin_addr
;
4319 SCTP_TCB_UNLOCK(stcb
);
4321 /* No IPv4 address */
4323 #if defined(__FreeBSD__) || defined(__APPLE__) || defined(__DragonFly__)
4324 FREE(sin
, M_SONAME
);
4332 #if defined(__FreeBSD__) || defined(__APPLE__) || defined(__DragonFly__)
4333 struct pr_usrreqs sctp_usrreqs
= {
4334 .pru_abort
= sctp_abort
,
4335 .pru_accept
= sctp_accept
,
4336 .pru_attach
= sctp_attach
,
4337 .pru_bind
= sctp_bind
,
4338 .pru_connect
= sctp_connect
,
4339 .pru_connect2
= pru_connect2_notsupp
,
4340 .pru_control
= in_control
,
4341 .pru_detach
= sctp_detach
,
4342 .pru_disconnect
= sctp_disconnect
,
4343 .pru_listen
= sctp_listen
,
4344 .pru_peeraddr
= sctp_peeraddr
,
4345 .pru_rcvd
= sctp_usr_recvd
,
4346 .pru_rcvoob
= pru_rcvoob_notsupp
,
4347 .pru_send
= sctp_send
,
4348 .pru_sense
= pru_sense_null
,
4349 .pru_shutdown
= sctp_shutdown
,
4350 .pru_sockaddr
= sctp_ingetaddr
,
4351 .pru_sosend
= sctp_sosend
,
4352 .pru_soreceive
= soreceive
,
4353 .pru_sopoll
= sopoll
4357 #if defined(__NetBSD__)
4359 sctp_usrreq(struct socket
*so
, int req
, struct mbuf
*m
, struct mbuf
*nam
,
4360 struct mbuf
*control
, struct proc
*p
)
4364 sctp_usrreq(struct socket
*so
, int req
, struct mbuf
*m
, struct mbuf
*nam
,
4365 struct mbuf
*control
)
4367 struct proc
*p
= curproc
;
4372 family
= so
->so_proto
->pr_domain
->dom_family
;
4375 if (req
== PRU_CONTROL
) {
4378 error
= in_control(so
, (long)m
, (caddr_t
)nam
,
4379 (struct ifnet
*)control
4380 #if defined(__NetBSD__)
4387 error
= in6_control(so
, (long)m
, (caddr_t
)nam
,
4388 (struct ifnet
*)control
, p
);
4392 error
= EAFNOSUPPORT
;
4398 if (req
== PRU_PURGEIF
) {
4401 ifn
= (struct ifnet
*)control
;
4402 TAILQ_FOREACH(ifa
, &ifn
->if_addrlist
, ifa_list
) {
4403 if (ifa
->ifa_addr
->sa_family
== family
) {
4404 sctp_delete_ip_address(ifa
);
4418 return (EAFNOSUPPORT
);
4426 error
= sctp_attach(so
, family
, p
);
4429 error
= sctp_detach(so
);
4436 error
= sctp_bind(so
, nam
, p
);
4439 error
= sctp_listen(so
, p
);
4446 error
= sctp_connect(so
, nam
, p
);
4448 case PRU_DISCONNECT
:
4449 error
= sctp_disconnect(so
);
4456 error
= sctp_accept(so
, nam
);
4459 error
= sctp_shutdown(so
);
4464 * For Open and Net BSD, this is real
4465 * ugly. The mbuf *nam that is passed
4466 * (by soreceive()) is the int flags c
4467 * ast as a (mbuf *) yuck!
4469 error
= sctp_usr_recvd(so
, (int)((long)nam
));
4473 /* Flags are ignored */
4475 if (sctp_debug_on
& SCTP_DEBUG_USRREQ1
) {
4476 kprintf("Send called on V4 side\n");
4480 struct sockaddr
*addr
;
4484 addr
= mtod(nam
, struct sockaddr
*);
4486 error
= sctp_send(so
, 0, m
, addr
, control
, p
);
4490 error
= sctp_abort(so
);
4497 error
= EAFNOSUPPORT
;
4500 error
= EAFNOSUPPORT
;
4503 error
= sctp_peeraddr(so
, nam
);
4506 error
= sctp_ingetaddr(so
, nam
);
4519 /* #if defined(__NetBSD__) || defined(__OpenBSD__) */
4522 * Sysctl for sctp variables.
4525 sctp_sysctl(int *name
, u_int namelen
, void *oldp
, size_t *oldlenp
, void *newp
,
4529 /* All sysctl names at this level are terminal. */
4535 case SCTPCTL_MAXDGRAM
:
4536 return (sysctl_int(oldp
, oldlenp
, newp
, newlen
,
4538 case SCTPCTL_RECVSPACE
:
4539 return (sysctl_int(oldp
, oldlenp
, newp
, newlen
,
4541 case SCTPCTL_AUTOASCONF
:
4542 return (sysctl_int(oldp
, oldlenp
, newp
, newlen
,
4543 &sctp_auto_asconf
));
4544 case SCTPCTL_ECN_ENABLE
:
4545 return (sysctl_int(oldp
, oldlenp
, newp
, newlen
,
4547 case SCTPCTL_ECN_NONCE
:
4548 return (sysctl_int(oldp
, oldlenp
, newp
, newlen
,
4550 case SCTPCTL_STRICT_SACK
:
4551 return (sysctl_int(oldp
, oldlenp
, newp
, newlen
,
4552 &sctp_strict_sacks
));
4553 case SCTPCTL_NOCSUM_LO
:
4554 return (sysctl_int(oldp
, oldlenp
, newp
, newlen
,
4555 &sctp_no_csum_on_loopback
));
4556 case SCTPCTL_STRICT_INIT
:
4557 return (sysctl_int(oldp
, oldlenp
, newp
, newlen
,
4558 &sctp_strict_init
));
4559 case SCTPCTL_PEER_CHK_OH
:
4560 return (sysctl_int(oldp
, oldlenp
, newp
, newlen
,
4561 &sctp_peer_chunk_oh
));
4562 case SCTPCTL_MAXBURST
:
4563 return (sysctl_int(oldp
, oldlenp
, newp
, newlen
,
4564 &sctp_max_burst_default
));
4565 case SCTPCTL_MAXCHUNKONQ
:
4566 return (sysctl_int(oldp
, oldlenp
, newp
, newlen
,
4567 &sctp_max_chunks_on_queue
));
4568 case SCTPCTL_DELAYED_SACK
:
4569 return (sysctl_int(oldp
, oldlenp
, newp
, newlen
,
4570 &sctp_delayed_sack_time_default
));
4571 case SCTPCTL_HB_INTERVAL
:
4572 return (sysctl_int(oldp
, oldlenp
, newp
, newlen
,
4573 &sctp_heartbeat_interval_default
));
4574 case SCTPCTL_PMTU_RAISE
:
4575 return (sysctl_int(oldp
, oldlenp
, newp
, newlen
,
4576 &sctp_pmtu_raise_time_default
));
4577 case SCTPCTL_SHUTDOWN_GUARD
:
4578 return (sysctl_int(oldp
, oldlenp
, newp
, newlen
,
4579 &sctp_shutdown_guard_time_default
));
4580 case SCTPCTL_SECRET_LIFETIME
:
4581 return (sysctl_int(oldp
, oldlenp
, newp
, newlen
,
4582 &sctp_secret_lifetime_default
));
4583 case SCTPCTL_RTO_MAX
:
4584 return (sysctl_int(oldp
, oldlenp
, newp
, newlen
,
4585 &sctp_rto_max_default
));
4586 case SCTPCTL_RTO_MIN
:
4587 return (sysctl_int(oldp
, oldlenp
, newp
, newlen
,
4588 &sctp_rto_min_default
));
4589 case SCTPCTL_RTO_INITIAL
:
4590 return (sysctl_int(oldp
, oldlenp
, newp
, newlen
,
4591 &sctp_rto_initial_default
));
4592 case SCTPCTL_INIT_RTO_MAX
:
4593 return (sysctl_int(oldp
, oldlenp
, newp
, newlen
,
4594 &sctp_init_rto_max_default
));
4595 case SCTPCTL_COOKIE_LIFE
:
4596 return (sysctl_int(oldp
, oldlenp
, newp
, newlen
,
4597 &sctp_valid_cookie_life_default
));
4598 case SCTPCTL_INIT_RTX_MAX
:
4599 return (sysctl_int(oldp
, oldlenp
, newp
, newlen
,
4600 &sctp_init_rtx_max_default
));
4601 case SCTPCTL_ASSOC_RTX_MAX
:
4602 return (sysctl_int(oldp
, oldlenp
, newp
, newlen
,
4603 &sctp_assoc_rtx_max_default
));
4604 case SCTPCTL_PATH_RTX_MAX
:
4605 return (sysctl_int(oldp
, oldlenp
, newp
, newlen
,
4606 &sctp_path_rtx_max_default
));
4607 case SCTPCTL_NR_OUTGOING_STREAMS
:
4608 return (sysctl_int(oldp
, oldlenp
, newp
, newlen
,
4609 &sctp_nr_outgoing_streams_default
));
4612 return (sysctl_int(oldp
, oldlenp
, newp
, newlen
,
4616 return (ENOPROTOOPT
);
4623 * Sysctl for sctp variables.
4625 SYSCTL_SETUP(sysctl_net_inet_sctp_setup
, "sysctl net.inet.sctp subtree setup")
4628 sysctl_createv(clog
, 0, NULL
, NULL
,
4630 CTLTYPE_NODE
, "net", NULL
,
4633 sysctl_createv(clog
, 0, NULL
, NULL
,
4635 CTLTYPE_NODE
, "inet", NULL
,
4637 CTL_NET
, PF_INET
, CTL_EOL
);
4638 sysctl_createv(clog
, 0, NULL
, NULL
,
4640 CTLTYPE_NODE
, "sctp",
4641 SYSCTL_DESCR("sctp related settings"),
4643 CTL_NET
, PF_INET
, IPPROTO_SCTP
, CTL_EOL
);
4645 sysctl_createv(clog
, 0, NULL
, NULL
,
4646 CTLFLAG_PERMANENT
|CTLFLAG_READWRITE
,
4647 CTLTYPE_INT
, "maxdgram",
4648 SYSCTL_DESCR("Maximum outgoing SCTP buffer size"),
4649 NULL
, 0, &sctp_sendspace
, 0,
4650 CTL_NET
, PF_INET
, IPPROTO_SCTP
, SCTPCTL_MAXDGRAM
,
4653 sysctl_createv(clog
, 0, NULL
, NULL
,
4654 CTLFLAG_PERMANENT
|CTLFLAG_READWRITE
,
4655 CTLTYPE_INT
, "recvspace",
4656 SYSCTL_DESCR("Maximum incoming SCTP buffer size"),
4657 NULL
, 0, &sctp_recvspace
, 0,
4658 CTL_NET
, PF_INET
, IPPROTO_SCTP
, SCTPCTL_RECVSPACE
,
4661 sysctl_createv(clog
, 0, NULL
, NULL
,
4662 CTLFLAG_PERMANENT
|CTLFLAG_READWRITE
,
4663 CTLTYPE_INT
, "autoasconf",
4664 SYSCTL_DESCR("Enable SCTP Auto-ASCONF"),
4665 NULL
, 0, &sctp_auto_asconf
, 0,
4666 CTL_NET
, PF_INET
, IPPROTO_SCTP
, SCTPCTL_AUTOASCONF
,
4669 sysctl_createv(clog
, 0, NULL
, NULL
,
4670 CTLFLAG_PERMANENT
|CTLFLAG_READWRITE
,
4671 CTLTYPE_INT
, "ecn_enable",
4672 SYSCTL_DESCR("Enable SCTP ECN"),
4673 NULL
, 0, &sctp_ecn
, 0,
4674 CTL_NET
, PF_INET
, IPPROTO_SCTP
, SCTPCTL_ECN_ENABLE
,
4677 sysctl_createv(clog
, 0, NULL
, NULL
,
4678 CTLFLAG_PERMANENT
|CTLFLAG_READWRITE
,
4679 CTLTYPE_INT
, "ecn_nonce",
4680 SYSCTL_DESCR("Enable SCTP ECN Nonce"),
4681 NULL
, 0, &sctp_ecn_nonce
, 0,
4682 CTL_NET
, PF_INET
, IPPROTO_SCTP
, SCTPCTL_ECN_NONCE
,
4685 sysctl_createv(clog
, 0, NULL
, NULL
,
4686 CTLFLAG_PERMANENT
|CTLFLAG_READWRITE
,
4687 CTLTYPE_INT
, "strict_sack",
4688 SYSCTL_DESCR("Enable SCTP Strict SACK checking"),
4689 NULL
, 0, &sctp_strict_sacks
, 0,
4690 CTL_NET
, PF_INET
, IPPROTO_SCTP
, SCTPCTL_STRICT_SACK
,
4693 sysctl_createv(clog
, 0, NULL
, NULL
,
4694 CTLFLAG_PERMANENT
|CTLFLAG_READWRITE
,
4695 CTLTYPE_INT
, "loopback_nocsum",
4696 SYSCTL_DESCR("Enable NO Csum on packets sent on loopback"),
4697 NULL
, 0, &sctp_no_csum_on_loopback
, 0,
4698 CTL_NET
, PF_INET
, IPPROTO_SCTP
, SCTPCTL_NOCSUM_LO
,
4701 sysctl_createv(clog
, 0, NULL
, NULL
,
4702 CTLFLAG_PERMANENT
|CTLFLAG_READWRITE
,
4703 CTLTYPE_INT
, "strict_init",
4704 SYSCTL_DESCR("Enable strict INIT/INIT-ACK singleton enforcement"),
4705 NULL
, 0, &sctp_strict_init
, 0,
4706 CTL_NET
, PF_INET
, IPPROTO_SCTP
, SCTPCTL_STRICT_INIT
,
4709 sysctl_createv(clog
, 0, NULL
, NULL
,
4710 CTLFLAG_PERMANENT
|CTLFLAG_READWRITE
,
4711 CTLTYPE_INT
, "peer_chkoh",
4712 SYSCTL_DESCR("Amount to debit peers rwnd per chunk sent"),
4713 NULL
, 0, &sctp_peer_chunk_oh
, 0,
4714 CTL_NET
, PF_INET
, IPPROTO_SCTP
, SCTPCTL_PEER_CHK_OH
,
4717 sysctl_createv(clog
, 0, NULL
, NULL
,
4718 CTLFLAG_PERMANENT
|CTLFLAG_READWRITE
,
4719 CTLTYPE_INT
, "maxburst",
4720 SYSCTL_DESCR("Default max burst for sctp endpoints"),
4721 NULL
, 0, &sctp_max_burst_default
, 0,
4722 CTL_NET
, PF_INET
, IPPROTO_SCTP
, SCTPCTL_MAXBURST
,
4725 sysctl_createv(clog
, 0, NULL
, NULL
,
4726 CTLFLAG_PERMANENT
|CTLFLAG_READWRITE
,
4727 CTLTYPE_INT
, "maxchunks",
4728 SYSCTL_DESCR("Default max chunks on queue per asoc"),
4729 NULL
, 0, &sctp_max_chunks_on_queue
, 0,
4730 CTL_NET
, PF_INET
, IPPROTO_SCTP
, SCTPCTL_MAXCHUNKONQ
,