1 /* $KAME: sctp_usrreq.c,v 1.47 2005/03/06 16:04:18 itojun Exp $ */
4 * Copyright (c) 2001, 2002, 2003, 2004 Cisco Systems, Inc.
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
15 * 3. All advertising materials mentioning features or use of this software
16 * must display the following acknowledgement:
17 * This product includes software developed by Cisco Systems, Inc.
18 * 4. Neither the name of the project nor the names of its contributors
19 * may be used to endorse or promote products derived from this software
20 * without specific prior written permission.
22 * THIS SOFTWARE IS PROVIDED BY CISCO SYSTEMS AND CONTRIBUTORS ``AS IS'' AND
23 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
24 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
25 * ARE DISCLAIMED. IN NO EVENT SHALL CISCO SYSTEMS OR CONTRIBUTORS BE LIABLE
26 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
27 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
28 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
29 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
31 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
34 #if !(defined(__OpenBSD__) || defined(__APPLE__))
35 #include "opt_ipsec.h"
37 #if defined(__FreeBSD__) || defined(__DragonFly__)
38 #include "opt_inet6.h"
41 #if defined(__NetBSD__)
47 #elif !defined(__OpenBSD__)
51 #include <sys/param.h>
52 #include <sys/systm.h>
53 #include <sys/kernel.h>
54 #include <sys/malloc.h>
56 #include <sys/domain.h>
59 #include <sys/protosw.h>
60 #include <sys/socket.h>
61 #include <sys/socketvar.h>
62 #include <sys/socketvar2.h>
63 #include <sys/sysctl.h>
64 #include <sys/syslog.h>
66 #include <sys/thread2.h>
67 #include <sys/msgport2.h>
70 #include <net/if_types.h>
71 #if defined(__FreeBSD__) || defined(__APPLE__) || defined(__DragonFly__)
72 #include <net/if_var.h>
74 #include <net/route.h>
75 #include <netinet/in.h>
76 #include <netinet/in_systm.h>
77 #include <netinet/ip.h>
78 #include <netinet/ip6.h>
79 #include <netinet/in_pcb.h>
80 #include <netinet/in_var.h>
81 #include <netinet/ip_var.h>
82 #include <netinet6/ip6_var.h>
83 #include <netinet6/in6_var.h>
85 #include <netinet/ip_icmp.h>
86 #include <netinet/icmp_var.h>
87 #include <netinet/sctp_pcb.h>
88 #include <netinet/sctp_header.h>
89 #include <netinet/sctp_var.h>
90 #include <netinet/sctp_output.h>
91 #include <netinet/sctp_uio.h>
92 #include <netinet/sctp_asconf.h>
93 #include <netinet/sctputil.h>
94 #include <netinet/sctp_indata.h>
95 #include <netinet/sctp_asconf.h>
98 #include <netinet6/ipsec.h>
99 #include <netproto/key/key.h>
105 #include <net/net_osdep.h>
107 #if defined(HAVE_NRL_INPCB) || defined(__FreeBSD__) || defined(__DragonFly__)
112 #define sotoin6pcb sotoinpcb
117 extern u_int32_t sctp_debug_on
;
118 #endif /* SCTP_DEBUG */
121 * sysctl tunable variables
123 int sctp_auto_asconf
= SCTP_DEFAULT_AUTO_ASCONF
;
124 int sctp_max_burst_default
= SCTP_DEF_MAX_BURST
;
125 int sctp_peer_chunk_oh
= sizeof(struct mbuf
);
126 int sctp_strict_init
= 1;
127 int sctp_no_csum_on_loopback
= 1;
128 unsigned int sctp_max_chunks_on_queue
= SCTP_ASOC_MAX_CHUNKS_ON_QUEUE
;
129 int sctp_sendspace
= (128 * 1024);
130 int sctp_recvspace
= 128 * (1024 +
132 sizeof(struct sockaddr_in6
)
134 sizeof(struct sockaddr_in
)
137 int sctp_strict_sacks
= 0;
139 int sctp_ecn_nonce
= 0;
141 unsigned int sctp_delayed_sack_time_default
= SCTP_RECV_MSEC
;
142 unsigned int sctp_heartbeat_interval_default
= SCTP_HB_DEFAULT_MSEC
;
143 unsigned int sctp_pmtu_raise_time_default
= SCTP_DEF_PMTU_RAISE_SEC
;
144 unsigned int sctp_shutdown_guard_time_default
= SCTP_DEF_MAX_SHUTDOWN_SEC
;
145 unsigned int sctp_secret_lifetime_default
= SCTP_DEFAULT_SECRET_LIFE_SEC
;
146 unsigned int sctp_rto_max_default
= SCTP_RTO_UPPER_BOUND
;
147 unsigned int sctp_rto_min_default
= SCTP_RTO_LOWER_BOUND
;
148 unsigned int sctp_rto_initial_default
= SCTP_RTO_INITIAL
;
149 unsigned int sctp_init_rto_max_default
= SCTP_RTO_UPPER_BOUND
;
150 unsigned int sctp_valid_cookie_life_default
= SCTP_DEFAULT_COOKIE_LIFE
;
151 unsigned int sctp_init_rtx_max_default
= SCTP_DEF_MAX_INIT
;
152 unsigned int sctp_assoc_rtx_max_default
= SCTP_DEF_MAX_SEND
;
153 unsigned int sctp_path_rtx_max_default
= SCTP_DEF_MAX_SEND
/2;
154 unsigned int sctp_nr_outgoing_streams_default
= SCTP_OSTREAM_INITIAL
;
160 #define nmbclusters nmbclust
162 /* Init the SCTP pcb in sctp_pcb.c */
168 if (nmbclusters
> SCTP_ASOC_MAX_CHUNKS_ON_QUEUE
)
169 sctp_max_chunks_on_queue
= nmbclusters
;
171 /* if (nmbclust > SCTP_ASOC_MAX_CHUNKS_ON_QUEUE)
172 sctp_max_chunks_on_queue = nmbclust; FIX ME */
173 sctp_max_chunks_on_queue
= nmbclust
* 2;
176 * Allow a user to take no more than 1/2 the number of clusters
177 * or the SB_MAX whichever is smaller for the send window.
179 sb_max_adj
= (u_long
)((u_quad_t
)(SB_MAX
) * MCLBYTES
/ (MSIZE
+ MCLBYTES
));
180 sctp_sendspace
= min((min(SB_MAX
, sb_max_adj
)),
182 ((nmbclusters
/2) * SCTP_DEFAULT_MAXSEGMENT
));
184 ((nmbclust
/2) * SCTP_DEFAULT_MAXSEGMENT
));
187 * Now for the recv window, should we take the same amount?
188 * or should I do 1/2 the SB_MAX instead in the SB_MAX min above.
189 * For now I will just copy.
191 sctp_recvspace
= sctp_sendspace
;
199 ip_2_ip6_hdr(struct ip6_hdr
*ip6
, struct ip
*ip
)
201 bzero(ip6
, sizeof(*ip6
));
203 ip6
->ip6_vfc
= IPV6_VERSION
;
204 ip6
->ip6_plen
= ip
->ip_len
;
205 ip6
->ip6_nxt
= ip
->ip_p
;
206 ip6
->ip6_hlim
= ip
->ip_ttl
;
207 ip6
->ip6_src
.s6_addr32
[2] = ip6
->ip6_dst
.s6_addr32
[2] =
209 ip6
->ip6_src
.s6_addr32
[3] = ip
->ip_src
.s_addr
;
210 ip6
->ip6_dst
.s6_addr32
[3] = ip
->ip_dst
.s_addr
;
215 sctp_split_chunks(struct sctp_association
*asoc
,
216 struct sctp_stream_out
*strm
,
217 struct sctp_tmit_chunk
*chk
)
219 struct sctp_tmit_chunk
*new_chk
;
221 /* First we need a chunk */
222 new_chk
= (struct sctp_tmit_chunk
*)SCTP_ZONE_GET(sctppcbinfo
.ipi_zone_chunk
);
223 if (new_chk
== NULL
) {
224 chk
->flags
|= CHUNK_FLAGS_FRAGMENT_OK
;
227 sctppcbinfo
.ipi_count_chunk
++;
228 sctppcbinfo
.ipi_gencnt_chunk
++;
232 new_chk
->data
= m_split(chk
->data
, (chk
->send_size
>>1), MB_DONTWAIT
);
233 if (new_chk
->data
== NULL
) {
235 chk
->flags
|= CHUNK_FLAGS_FRAGMENT_OK
;
236 SCTP_ZONE_FREE(sctppcbinfo
.ipi_zone_chunk
, new_chk
);
237 sctppcbinfo
.ipi_count_chunk
--;
238 if ((int)sctppcbinfo
.ipi_count_chunk
< 0) {
239 panic("Chunk count is negative");
241 sctppcbinfo
.ipi_gencnt_chunk
++;
245 /* Data is now split adjust sizes */
246 chk
->send_size
>>= 1;
247 new_chk
->send_size
>>= 1;
249 chk
->book_size
>>= 1;
250 new_chk
->book_size
>>= 1;
252 /* now adjust the marks */
253 chk
->rec
.data
.rcv_flags
|= SCTP_DATA_FIRST_FRAG
;
254 chk
->rec
.data
.rcv_flags
&= ~SCTP_DATA_LAST_FRAG
;
256 new_chk
->rec
.data
.rcv_flags
&= ~SCTP_DATA_FIRST_FRAG
;
257 new_chk
->rec
.data
.rcv_flags
|= SCTP_DATA_LAST_FRAG
;
259 /* Increase ref count if dest is set */
261 new_chk
->whoTo
->ref_count
++;
263 /* now drop it on the end of the list*/
264 asoc
->stream_queue_cnt
++;
265 TAILQ_INSERT_AFTER(&strm
->outqueue
, chk
, new_chk
, sctp_next
);
269 sctp_notify_mbuf(struct sctp_inpcb
*inp
,
270 struct sctp_tcb
*stcb
,
271 struct sctp_nets
*net
,
281 if ((inp
== NULL
) || (stcb
== NULL
) || (net
== NULL
) ||
282 (ip
== NULL
) || (sh
== NULL
)) {
284 SCTP_TCB_UNLOCK(stcb
);
287 /* First job is to verify the vtag matches what I would send */
288 if (ntohl(sh
->v_tag
) != (stcb
->asoc
.peer_vtag
)) {
289 SCTP_TCB_UNLOCK(stcb
);
292 icmph
= (struct icmp
*)((caddr_t
)ip
- (sizeof(struct icmp
) -
294 if (icmph
->icmp_type
!= ICMP_UNREACH
) {
295 /* We only care about unreachable */
296 SCTP_TCB_UNLOCK(stcb
);
299 if (icmph
->icmp_code
!= ICMP_UNREACH_NEEDFRAG
) {
300 /* not a unreachable message due to frag. */
301 SCTP_TCB_UNLOCK(stcb
);
305 nxtsz
= ntohs(icmph
->icmp_seq
);
308 * old type router that does not tell us what the next size
309 * mtu is. Rats we will have to guess (in a educated fashion
312 nxtsz
= find_next_best_mtu(totsz
);
315 /* Stop any PMTU timer */
316 sctp_timer_stop(SCTP_TIMER_TYPE_PATHMTURAISE
, inp
, stcb
, NULL
);
318 /* Adjust destination size limit */
319 if (net
->mtu
> nxtsz
) {
322 /* now what about the ep? */
323 if (stcb
->asoc
.smallest_mtu
> nxtsz
) {
324 struct sctp_tmit_chunk
*chk
, *nchk
;
325 struct sctp_stream_out
*strm
;
326 /* Adjust that too */
327 stcb
->asoc
.smallest_mtu
= nxtsz
;
328 /* now off to subtract IP_DF flag if needed */
330 TAILQ_FOREACH(chk
, &stcb
->asoc
.send_queue
, sctp_next
) {
331 if ((chk
->send_size
+IP_HDR_SIZE
) > nxtsz
) {
332 chk
->flags
|= CHUNK_FLAGS_FRAGMENT_OK
;
335 TAILQ_FOREACH(chk
, &stcb
->asoc
.sent_queue
, sctp_next
) {
336 if ((chk
->send_size
+IP_HDR_SIZE
) > nxtsz
) {
338 * For this guy we also mark for immediate
339 * resend since we sent to big of chunk
341 chk
->flags
|= CHUNK_FLAGS_FRAGMENT_OK
;
342 if (chk
->sent
!= SCTP_DATAGRAM_RESEND
) {
343 stcb
->asoc
.sent_queue_retran_cnt
++;
345 chk
->sent
= SCTP_DATAGRAM_RESEND
;
346 chk
->rec
.data
.doing_fast_retransmit
= 0;
348 /* Clear any time so NO RTT is being done */
350 stcb
->asoc
.total_flight
-= chk
->book_size
;
351 if (stcb
->asoc
.total_flight
< 0) {
352 stcb
->asoc
.total_flight
= 0;
354 stcb
->asoc
.total_flight_count
--;
355 if (stcb
->asoc
.total_flight_count
< 0) {
356 stcb
->asoc
.total_flight_count
= 0;
358 net
->flight_size
-= chk
->book_size
;
359 if (net
->flight_size
< 0) {
360 net
->flight_size
= 0;
364 TAILQ_FOREACH(strm
, &stcb
->asoc
.out_wheel
, next_spoke
) {
365 chk
= TAILQ_FIRST(&strm
->outqueue
);
367 nchk
= TAILQ_NEXT(chk
, sctp_next
);
368 if ((chk
->send_size
+SCTP_MED_OVERHEAD
) > nxtsz
) {
369 sctp_split_chunks(&stcb
->asoc
, strm
, chk
);
375 sctp_timer_start(SCTP_TIMER_TYPE_PATHMTURAISE
, inp
, stcb
, NULL
);
376 SCTP_TCB_UNLOCK(stcb
);
381 sctp_notify(struct sctp_inpcb
*inp
,
385 struct sctp_tcb
*stcb
,
386 struct sctp_nets
*net
)
389 if ((inp
== NULL
) || (stcb
== NULL
) || (net
== NULL
) ||
390 (sh
== NULL
) || (to
== NULL
)) {
392 if (sctp_debug_on
& SCTP_DEBUG_USRREQ1
) {
393 kprintf("sctp-notify, bad call\n");
395 #endif /* SCTP_DEBUG */
398 /* First job is to verify the vtag matches what I would send */
399 if (ntohl(sh
->v_tag
) != (stcb
->asoc
.peer_vtag
)) {
403 /* FIX ME FIX ME PROTOPT i.e. no SCTP should ALWAYS be an ABORT */
405 if ((error
== EHOSTUNREACH
) || /* Host is not reachable */
406 (error
== EHOSTDOWN
) || /* Host is down */
407 (error
== ECONNREFUSED
) || /* Host refused the connection, (not an abort?) */
408 (error
== ENOPROTOOPT
) /* SCTP is not present on host */
411 * Hmm reachablity problems we must examine closely.
412 * If its not reachable, we may have lost a network.
413 * Or if there is NO protocol at the other end named SCTP.
414 * well we consider it a OOTB abort.
416 if ((error
== EHOSTUNREACH
) || (error
== EHOSTDOWN
)) {
417 if (net
->dest_state
& SCTP_ADDR_REACHABLE
) {
418 /* Ok that destination is NOT reachable */
419 net
->dest_state
&= ~SCTP_ADDR_REACHABLE
;
420 net
->dest_state
|= SCTP_ADDR_NOT_REACHABLE
;
421 net
->error_count
= net
->failure_threshold
+ 1;
422 sctp_ulp_notify(SCTP_NOTIFY_INTERFACE_DOWN
,
423 stcb
, SCTP_FAILED_THRESHOLD
,
427 SCTP_TCB_UNLOCK(stcb
);
430 * Here the peer is either playing tricks on us,
431 * including an address that belongs to someone who
432 * does not support SCTP OR was a userland
433 * implementation that shutdown and now is dead. In
434 * either case treat it like a OOTB abort with no TCB
436 sctp_abort_notification(stcb
, SCTP_PEER_FAULTY
);
437 sctp_free_assoc(inp
, stcb
);
438 /* no need to unlock here, since the TCB is gone */
441 /* Send all others to the app */
442 if (inp
->sctp_socket
) {
443 SOCK_LOCK(inp
->sctp_socket
);
444 inp
->sctp_socket
->so_error
= error
;
445 sctp_sowwakeup(inp
, inp
->sctp_socket
);
446 SOCK_UNLOCK(inp
->sctp_socket
);
449 SCTP_TCB_UNLOCK(stcb
);
454 sctp_ctlinput(netmsg_t msg
)
456 int cmd
= msg
->ctlinput
.nm_cmd
;
457 struct sockaddr
*sa
= msg
->ctlinput
.nm_arg
;
458 struct ip
*ip
= msg
->ctlinput
.nm_extra
;
461 if (sa
->sa_family
!= AF_INET
||
462 ((struct sockaddr_in
*)sa
)->sin_addr
.s_addr
== INADDR_ANY
) {
466 if (PRC_IS_REDIRECT(cmd
)) {
468 } else if ((unsigned)cmd
>= PRC_NCMDS
|| inetctlerrmap
[cmd
] == 0) {
472 struct sctp_inpcb
*inp
;
473 struct sctp_tcb
*stcb
;
474 struct sctp_nets
*net
;
475 struct sockaddr_in to
, from
;
477 sh
= (struct sctphdr
*)((caddr_t
)ip
+ (ip
->ip_hl
<< 2));
478 bzero(&to
, sizeof(to
));
479 bzero(&from
, sizeof(from
));
480 from
.sin_family
= to
.sin_family
= AF_INET
;
481 from
.sin_len
= to
.sin_len
= sizeof(to
);
482 from
.sin_port
= sh
->src_port
;
483 from
.sin_addr
= ip
->ip_src
;
484 to
.sin_port
= sh
->dest_port
;
485 to
.sin_addr
= ip
->ip_dst
;
488 * 'to' holds the dest of the packet that failed to be sent.
489 * 'from' holds our local endpoint address.
490 * Thus we reverse the to and the from in the lookup.
492 stcb
= sctp_findassociation_addr_sa((struct sockaddr
*)&from
,
493 (struct sockaddr
*)&to
,
495 if (stcb
!= NULL
&& inp
&& (inp
->sctp_socket
!= NULL
)) {
496 if (cmd
!= PRC_MSGSIZE
) {
498 if (cmd
== PRC_HOSTDEAD
) {
501 cm
= inetctlerrmap
[cmd
];
503 sctp_notify(inp
, cm
, sh
,
504 (struct sockaddr
*)&to
, stcb
,
507 /* handle possible ICMP size messages */
508 sctp_notify_mbuf(inp
, stcb
, net
, ip
, sh
);
511 #if (defined(__FreeBSD__) && __FreeBSD_version < 500000) || defined(__DragonFly__)
512 /* XXX must be fixed for 5.x and higher, leave for 4.x */
513 if (PRC_IS_REDIRECT(cmd
) && inp
) {
514 in_rtchange((struct inpcb
*)inp
,
518 if ((stcb
== NULL
) && (inp
!= NULL
)) {
519 /* reduce ref-count */
521 SCTP_INP_DECR_REF(inp
);
522 SCTP_INP_WUNLOCK(inp
);
528 lwkt_replymsg(&msg
->lmsg
, 0);
531 #if defined(__FreeBSD__) || defined(__DragonFly__)
533 sctp_getcred(SYSCTL_HANDLER_ARGS
)
535 struct sockaddr_in addrs
[2];
536 struct sctp_inpcb
*inp
;
537 struct sctp_nets
*net
;
538 struct sctp_tcb
*stcb
;
541 #if __FreeBSD_version >= 500000 || defined(__DragonFly__)
542 error
= priv_check(req
->td
, PRIV_ROOT
);
544 error
= suser(req
->p
);
548 error
= SYSCTL_IN(req
, addrs
, sizeof(addrs
));
552 stcb
= sctp_findassociation_addr_sa(sintosa(&addrs
[0]),
555 if (stcb
== NULL
|| inp
== NULL
|| inp
->sctp_socket
== NULL
) {
556 if ((inp
!= NULL
) && (stcb
== NULL
)) {
557 /* reduce ref-count */
559 SCTP_INP_DECR_REF(inp
);
560 SCTP_INP_WUNLOCK(inp
);
565 error
= SYSCTL_OUT(req
, inp
->sctp_socket
->so_cred
, sizeof(struct ucred
));
566 SCTP_TCB_UNLOCK(stcb
);
571 SYSCTL_PROC(_net_inet_sctp
, OID_AUTO
, getcred
, CTLTYPE_OPAQUE
|CTLFLAG_RW
,
572 0, 0, sctp_getcred
, "S,ucred", "Get the ucred of a SCTP connection");
573 #endif /* #if defined(__FreeBSD__) || defined(__DragonFly__) */
578 #if defined(__FreeBSD__) || defined (__APPLE__) || defined(__DragonFly__)
580 SYSCTL_DECL(_net_inet
);
582 SYSCTL_NODE(_net_inet
, OID_AUTO
, sctp
, CTLFLAG_RD
, 0,
585 SYSCTL_INT(_net_inet_sctp
, OID_AUTO
, maxdgram
, CTLFLAG_RW
,
586 &sctp_sendspace
, 0, "Maximum outgoing SCTP buffer size");
588 SYSCTL_INT(_net_inet_sctp
, OID_AUTO
, recvspace
, CTLFLAG_RW
,
589 &sctp_recvspace
, 0, "Maximum incoming SCTP buffer size");
591 SYSCTL_INT(_net_inet_sctp
, OID_AUTO
, auto_asconf
, CTLFLAG_RW
,
592 &sctp_auto_asconf
, 0, "Enable SCTP Auto-ASCONF");
594 SYSCTL_INT(_net_inet_sctp
, OID_AUTO
, ecn_enable
, CTLFLAG_RW
,
595 &sctp_ecn
, 0, "Enable SCTP ECN");
597 SYSCTL_INT(_net_inet_sctp
, OID_AUTO
, ecn_nonce
, CTLFLAG_RW
,
598 &sctp_ecn_nonce
, 0, "Enable SCTP ECN Nonce");
600 SYSCTL_INT(_net_inet_sctp
, OID_AUTO
, strict_sacks
, CTLFLAG_RW
,
601 &sctp_strict_sacks
, 0, "Enable SCTP Strict SACK checking");
603 SYSCTL_INT(_net_inet_sctp
, OID_AUTO
, loopback_nocsum
, CTLFLAG_RW
,
604 &sctp_no_csum_on_loopback
, 0,
605 "Enable NO Csum on packets sent on loopback");
607 SYSCTL_INT(_net_inet_sctp
, OID_AUTO
, strict_init
, CTLFLAG_RW
,
608 &sctp_strict_init
, 0,
609 "Enable strict INIT/INIT-ACK singleton enforcement");
611 SYSCTL_INT(_net_inet_sctp
, OID_AUTO
, peer_chkoh
, CTLFLAG_RW
,
612 &sctp_peer_chunk_oh
, 0,
613 "Amount to debit peers rwnd per chunk sent");
615 SYSCTL_INT(_net_inet_sctp
, OID_AUTO
, maxburst
, CTLFLAG_RW
,
616 &sctp_max_burst_default
, 0,
617 "Default max burst for sctp endpoints");
619 SYSCTL_INT(_net_inet_sctp
, OID_AUTO
, maxchunks
, CTLFLAG_RW
,
620 &sctp_max_chunks_on_queue
, 0,
621 "Default max chunks on queue per asoc");
623 SYSCTL_UINT(_net_inet_sctp
, OID_AUTO
, delayed_sack_time
, CTLFLAG_RW
,
624 &sctp_delayed_sack_time_default
, 0,
625 "Default delayed SACK timer in msec");
627 SYSCTL_UINT(_net_inet_sctp
, OID_AUTO
, heartbeat_interval
, CTLFLAG_RW
,
628 &sctp_heartbeat_interval_default
, 0,
629 "Default heartbeat interval in msec");
631 SYSCTL_UINT(_net_inet_sctp
, OID_AUTO
, pmtu_raise_time
, CTLFLAG_RW
,
632 &sctp_pmtu_raise_time_default
, 0,
633 "Default PMTU raise timer in sec");
635 SYSCTL_UINT(_net_inet_sctp
, OID_AUTO
, shutdown_guard_time
, CTLFLAG_RW
,
636 &sctp_shutdown_guard_time_default
, 0,
637 "Default shutdown guard timer in sec");
639 SYSCTL_UINT(_net_inet_sctp
, OID_AUTO
, secret_lifetime
, CTLFLAG_RW
,
640 &sctp_secret_lifetime_default
, 0,
641 "Default secret lifetime in sec");
643 SYSCTL_UINT(_net_inet_sctp
, OID_AUTO
, rto_max
, CTLFLAG_RW
,
644 &sctp_rto_max_default
, 0,
645 "Default maximum retransmission timeout in msec");
647 SYSCTL_UINT(_net_inet_sctp
, OID_AUTO
, rto_min
, CTLFLAG_RW
,
648 &sctp_rto_min_default
, 0,
649 "Default minimum retransmission timeout in msec");
651 SYSCTL_UINT(_net_inet_sctp
, OID_AUTO
, rto_initial
, CTLFLAG_RW
,
652 &sctp_rto_initial_default
, 0,
653 "Default initial retransmission timeout in msec");
655 SYSCTL_UINT(_net_inet_sctp
, OID_AUTO
, init_rto_max
, CTLFLAG_RW
,
656 &sctp_init_rto_max_default
, 0,
657 "Default maximum retransmission timeout during association setup in msec");
659 SYSCTL_UINT(_net_inet_sctp
, OID_AUTO
, valid_cookie_life
, CTLFLAG_RW
,
660 &sctp_valid_cookie_life_default
, 0,
661 "Default cookie lifetime in sec");
663 SYSCTL_UINT(_net_inet_sctp
, OID_AUTO
, init_rtx_max
, CTLFLAG_RW
,
664 &sctp_init_rtx_max_default
, 0,
665 "Default maximum number of retransmission for INIT chunks");
667 SYSCTL_UINT(_net_inet_sctp
, OID_AUTO
, assoc_rtx_max
, CTLFLAG_RW
,
668 &sctp_assoc_rtx_max_default
, 0,
669 "Default maximum number of retransmissions per association");
671 SYSCTL_UINT(_net_inet_sctp
, OID_AUTO
, path_rtx_max
, CTLFLAG_RW
,
672 &sctp_path_rtx_max_default
, 0,
673 "Default maximum of retransmissions per path");
675 SYSCTL_UINT(_net_inet_sctp
, OID_AUTO
, nr_outgoing_streams
, CTLFLAG_RW
,
676 &sctp_nr_outgoing_streams_default
, 0,
677 "Default number of outgoing streams");
680 SYSCTL_INT(_net_inet_sctp
, OID_AUTO
, debug
, CTLFLAG_RW
,
681 &sctp_debug_on
, 0, "Configure debug output");
682 #endif /* SCTP_DEBUG */
686 * NOTE: (so) is referenced from soabort*() and netmsg_pru_abort()
687 * will sofree() it when we return.
690 sctp_abort(netmsg_t msg
)
692 struct socket
*so
= msg
->abort
.base
.nm_so
;
693 struct sctp_inpcb
*inp
;
696 inp
= (struct sctp_inpcb
*)so
->so_pcb
;
698 sctp_inpcb_free(inp
, 1);
703 lwkt_replymsg(&msg
->lmsg
, error
);
707 sctp_attach(netmsg_t msg
)
709 struct socket
*so
= msg
->attach
.base
.nm_so
;
710 struct sctp_inpcb
*inp
;
711 struct inpcb
*ip_inp
;
714 inp
= (struct sctp_inpcb
*)so
->so_pcb
;
719 error
= soreserve(so
, sctp_sendspace
, sctp_recvspace
, NULL
);
722 error
= sctp_inpcb_alloc(so
);
725 inp
= (struct sctp_inpcb
*)so
->so_pcb
;
728 inp
->sctp_flags
&= ~SCTP_PCB_FLAGS_BOUND_V6
; /* I'm not v6! */
729 ip_inp
= &inp
->ip_inp
.inp
;
730 ip_inp
->inp_vflag
|= INP_IPV4
;
731 ip_inp
->inp_ip_ttl
= ip_defttl
;
734 #if !(defined(__OpenBSD__) || defined(__APPLE__))
735 error
= ipsec_init_policy(so
, &ip_inp
->inp_sp
);
737 sctp_inpcb_free(inp
, 1);
742 SCTP_INP_WUNLOCK(inp
);
743 #if defined(__NetBSD__)
744 so
->so_send
= sctp_sosend
;
748 lwkt_replymsg(&msg
->lmsg
, error
);
752 sctp_bind(netmsg_t msg
)
754 struct socket
*so
= msg
->bind
.base
.nm_so
;
755 struct sockaddr
*addr
= msg
->bind
.nm_nam
;
756 thread_t td
= msg
->bind
.nm_td
;
757 struct sctp_inpcb
*inp
;
761 if (addr
&& addr
->sa_family
!= AF_INET
) {
762 /* must be a v4 address! */
768 inp
= (struct sctp_inpcb
*)so
->so_pcb
;
770 error
= sctp_inpcb_bind(so
, addr
, td
);
775 lwkt_replymsg(&msg
->lmsg
, error
);
780 sctp_detach(netmsg_t msg
)
782 struct socket
*so
= msg
->detach
.base
.nm_so
;
783 struct sctp_inpcb
*inp
;
786 inp
= (struct sctp_inpcb
*)so
->so_pcb
;
791 if (((so
->so_options
& SO_LINGER
) && (so
->so_linger
== 0)) ||
792 (so
->so_rcv
.ssb_cc
> 0)) {
793 sctp_inpcb_free(inp
, 1);
795 sctp_inpcb_free(inp
, 0);
799 lwkt_replymsg(&msg
->lmsg
, error
);
803 sctp_send(netmsg_t msg
)
805 struct socket
*so
= msg
->send
.base
.nm_so
;
806 int flags
= msg
->send
.nm_flags
;
807 struct mbuf
*m
= msg
->send
.nm_m
;
808 struct mbuf
*control
= msg
->send
.nm_control
;
809 struct sockaddr
*addr
= msg
->send
.nm_addr
;
810 struct thread
*td
= msg
->send
.nm_td
;
812 struct sctp_inpcb
*inp
;
813 inp
= (struct sctp_inpcb
*)so
->so_pcb
;
816 sctp_m_freem(control
);
823 /* Got to have an to address if we are NOT a connected socket */
824 if ((addr
== NULL
) &&
825 ((inp
->sctp_flags
& SCTP_PCB_FLAGS_CONNECTED
) ||
826 (inp
->sctp_flags
& SCTP_PCB_FLAGS_TCPTYPE
))
829 } else if (addr
== NULL
) {
830 error
= EDESTADDRREQ
;
833 sctp_m_freem(control
);
839 if (addr
->sa_family
!= AF_INET
) {
840 /* must be a v4 address! */
843 sctp_m_freem(control
);
846 error
= EDESTADDRREQ
; /* XXX huh? */
852 /* now what about control */
855 kprintf("huh? control set?\n");
856 sctp_m_freem(inp
->control
);
859 inp
->control
= control
;
861 /* add it in possibly */
862 if ((inp
->pkt
) && (inp
->pkt
->m_flags
& M_PKTHDR
)) {
868 for (x
=m
;x
;x
= x
->m_next
) {
871 inp
->pkt
->m_pkthdr
.len
+= c_len
;
875 inp
->pkt_last
->m_next
= m
;
878 inp
->pkt_last
= inp
->pkt
= m
;
881 #if defined (__FreeBSD__) || defined(__APPLE__) || defined(__DragonFly__)
882 /* FreeBSD uses a flag passed */
883 ((flags
& PRUS_MORETOCOME
) == 0)
884 #elif defined( __NetBSD__)
885 /* NetBSD uses the so_state field */
886 ((so
->so_state
& SS_MORETOCOME
) == 0)
888 1 /* Open BSD does not have any "more to come" indication */
892 * note with the current version this code will only be used
893 * by OpenBSD-- NetBSD, FreeBSD, and MacOS have methods for
894 * re-defining sosend to use the sctp_sosend. One can
895 * optionally switch back to this code (by changing back the
896 * definitions) but this is not advisable.
898 error
= sctp_output(inp
, inp
->pkt
, addr
,
899 inp
->control
, td
, flags
);
906 if (msg
->send
.nm_flags
& PRUS_NAMALLOC
) {
907 kfree(msg
->send
.nm_addr
, M_LWKTMSG
);
908 msg
->send
.nm_addr
= NULL
;
910 lwkt_replymsg(&msg
->lmsg
, error
);
914 sctp_disconnect(netmsg_t msg
)
916 struct socket
*so
= msg
->disconnect
.base
.nm_so
;
917 struct sctp_inpcb
*inp
;
920 inp
= (struct sctp_inpcb
*)so
->so_pcb
;
926 if (inp
->sctp_flags
& SCTP_PCB_FLAGS_TCPTYPE
) {
927 if (LIST_EMPTY(&inp
->sctp_asoc_list
)) {
929 SCTP_INP_RUNLOCK(inp
);
933 int some_on_streamwheel
= 0;
934 struct sctp_association
*asoc
;
935 struct sctp_tcb
*stcb
;
937 stcb
= LIST_FIRST(&inp
->sctp_asoc_list
);
939 SCTP_INP_RUNLOCK(inp
);
945 if (((so
->so_options
& SO_LINGER
) &&
946 (so
->so_linger
== 0)) ||
947 (so
->so_rcv
.ssb_cc
> 0)) {
948 if (SCTP_GET_STATE(asoc
) !=
949 SCTP_STATE_COOKIE_WAIT
) {
950 /* Left with Data unread */
953 MGET(err
, MB_DONTWAIT
, MT_DATA
);
955 /* Fill in the user initiated abort */
956 struct sctp_paramhdr
*ph
;
957 ph
= mtod(err
, struct sctp_paramhdr
*);
958 err
->m_len
= sizeof(struct sctp_paramhdr
);
959 ph
->param_type
= htons(SCTP_CAUSE_USER_INITIATED_ABT
);
960 ph
->param_length
= htons(err
->m_len
);
962 sctp_send_abort_tcb(stcb
, err
);
964 SCTP_INP_RUNLOCK(inp
);
965 sctp_free_assoc(inp
, stcb
);
966 /* No unlock tcb assoc is gone */
970 if (!TAILQ_EMPTY(&asoc
->out_wheel
)) {
971 /* Check to see if some data queued */
972 struct sctp_stream_out
*outs
;
973 TAILQ_FOREACH(outs
, &asoc
->out_wheel
,
975 if (!TAILQ_EMPTY(&outs
->outqueue
)) {
976 some_on_streamwheel
= 1;
982 if (TAILQ_EMPTY(&asoc
->send_queue
) &&
983 TAILQ_EMPTY(&asoc
->sent_queue
) &&
984 (some_on_streamwheel
== 0)) {
985 /* there is nothing queued to send, so done */
986 if ((SCTP_GET_STATE(asoc
) !=
987 SCTP_STATE_SHUTDOWN_SENT
) &&
988 (SCTP_GET_STATE(asoc
) !=
989 SCTP_STATE_SHUTDOWN_ACK_SENT
)) {
990 /* only send SHUTDOWN 1st time thru */
992 if (sctp_debug_on
& SCTP_DEBUG_OUTPUT4
) {
993 kprintf("%s:%d sends a shutdown\n",
999 sctp_send_shutdown(stcb
,
1000 stcb
->asoc
.primary_destination
);
1001 sctp_chunk_output(stcb
->sctp_ep
, stcb
, 1);
1002 asoc
->state
= SCTP_STATE_SHUTDOWN_SENT
;
1003 sctp_timer_start(SCTP_TIMER_TYPE_SHUTDOWN
,
1004 stcb
->sctp_ep
, stcb
,
1005 asoc
->primary_destination
);
1006 sctp_timer_start(SCTP_TIMER_TYPE_SHUTDOWNGUARD
,
1007 stcb
->sctp_ep
, stcb
,
1008 asoc
->primary_destination
);
1012 * we still got (or just got) data to send,
1013 * so set SHUTDOWN_PENDING
1016 * XXX sockets draft says that MSG_EOF should
1017 * be sent with no data.
1018 * currently, we will allow user data to be
1019 * sent first and move to SHUTDOWN-PENDING
1021 asoc
->state
|= SCTP_STATE_SHUTDOWN_PENDING
;
1023 SCTP_TCB_UNLOCK(stcb
);
1024 SCTP_INP_RUNLOCK(inp
);
1028 /* UDP model does not support this */
1029 SCTP_INP_RUNLOCK(inp
);
1033 lwkt_replymsg(&msg
->lmsg
, error
);
1036 /* also called from ipv6 sctp code */
1038 sctp_shutdown(netmsg_t msg
)
1040 struct socket
*so
= msg
->shutdown
.base
.nm_so
;
1041 struct sctp_inpcb
*inp
;
1044 inp
= (struct sctp_inpcb
*)so
->so_pcb
;
1049 SCTP_INP_RLOCK(inp
);
1050 /* For UDP model this is a invalid call */
1051 if (inp
->sctp_flags
& SCTP_PCB_FLAGS_UDPTYPE
) {
1052 /* Restore the flags that the soshutdown took away. */
1053 #if defined(__FreeBSD__) && __FreeBSD_version >= 502115
1054 so
->so_rcv
.sb_state
&= ~SBS_CANTRCVMORE
;
1056 soclrstate(so
, SS_CANTRCVMORE
);
1058 /* This proc will wakeup for read and do nothing (I hope) */
1059 SCTP_INP_RUNLOCK(inp
);
1064 * Ok if we reach here its the TCP model and it is either a SHUT_WR
1065 * or SHUT_RDWR. This means we put the shutdown flag against it.
1068 int some_on_streamwheel
= 0;
1069 struct sctp_tcb
*stcb
;
1070 struct sctp_association
*asoc
;
1073 stcb
= LIST_FIRST(&inp
->sctp_asoc_list
);
1076 * Ok we hit the case that the shutdown call was made
1077 * after an abort or something. Nothing to do now.
1082 SCTP_TCB_LOCK(stcb
);
1085 if (!TAILQ_EMPTY(&asoc
->out_wheel
)) {
1086 /* Check to see if some data queued */
1087 struct sctp_stream_out
*outs
;
1088 TAILQ_FOREACH(outs
, &asoc
->out_wheel
, next_spoke
) {
1089 if (!TAILQ_EMPTY(&outs
->outqueue
)) {
1090 some_on_streamwheel
= 1;
1095 if (TAILQ_EMPTY(&asoc
->send_queue
) &&
1096 TAILQ_EMPTY(&asoc
->sent_queue
) &&
1097 (some_on_streamwheel
== 0)) {
1098 /* there is nothing queued to send, so I'm done... */
1099 if (SCTP_GET_STATE(asoc
) != SCTP_STATE_SHUTDOWN_SENT
) {
1100 /* only send SHUTDOWN the first time through */
1102 if (sctp_debug_on
& SCTP_DEBUG_OUTPUT4
) {
1103 kprintf("%s:%d sends a shutdown\n",
1109 sctp_send_shutdown(stcb
,
1110 stcb
->asoc
.primary_destination
);
1111 sctp_chunk_output(stcb
->sctp_ep
, stcb
, 1);
1112 asoc
->state
= SCTP_STATE_SHUTDOWN_SENT
;
1113 sctp_timer_start(SCTP_TIMER_TYPE_SHUTDOWN
,
1114 stcb
->sctp_ep
, stcb
,
1115 asoc
->primary_destination
);
1116 sctp_timer_start(SCTP_TIMER_TYPE_SHUTDOWNGUARD
,
1117 stcb
->sctp_ep
, stcb
,
1118 asoc
->primary_destination
);
1122 * we still got (or just got) data to send, so
1123 * set SHUTDOWN_PENDING
1125 asoc
->state
|= SCTP_STATE_SHUTDOWN_PENDING
;
1127 SCTP_TCB_UNLOCK(stcb
);
1129 SCTP_INP_RUNLOCK(inp
);
1132 lwkt_replymsg(&msg
->lmsg
, error
);
1136 * copies a "user" presentable address and removes embedded scope, etc.
1137 * returns 0 on success, 1 on error
1140 sctp_fill_user_address(struct sockaddr_storage
*ss
, struct sockaddr
*sa
)
1142 struct sockaddr_in6 lsa6
;
1143 sa
= (struct sockaddr
*)sctp_recover_scope((struct sockaddr_in6
*)sa
,
1145 memcpy(ss
, sa
, sa
->sa_len
);
1150 #if defined(__NetBSD__) || defined(__OpenBSD__)
1152 * On NetBSD and OpenBSD in6_sin_2_v4mapsin6() not used and not exported,
1153 * so we have to export it here.
1155 void in6_sin_2_v4mapsin6(struct sockaddr_in
*sin
, struct sockaddr_in6
*sin6
);
1159 sctp_fill_up_addresses(struct sctp_inpcb
*inp
,
1160 struct sctp_tcb
*stcb
,
1162 struct sockaddr_storage
*sas
)
1165 int loopback_scope
, ipv4_local_scope
, local_scope
, site_scope
, actual
;
1166 int ipv4_addr_legal
, ipv6_addr_legal
;
1172 /* Turn on all the appropriate scope */
1173 loopback_scope
= stcb
->asoc
.loopback_scope
;
1174 ipv4_local_scope
= stcb
->asoc
.ipv4_local_scope
;
1175 local_scope
= stcb
->asoc
.local_scope
;
1176 site_scope
= stcb
->asoc
.site_scope
;
1178 /* Turn on ALL scope, since we look at the EP */
1179 loopback_scope
= ipv4_local_scope
= local_scope
=
1182 ipv4_addr_legal
= ipv6_addr_legal
= 0;
1183 if (inp
->sctp_flags
& SCTP_PCB_FLAGS_BOUND_V6
) {
1184 ipv6_addr_legal
= 1;
1186 #if defined(__OpenBSD__)
1187 (0) /* we always do dual bind */
1188 #elif defined (__NetBSD__)
1189 (((struct in6pcb
*)inp
)->in6p_flags
& IN6P_IPV6_V6ONLY
)
1191 (((struct in6pcb
*)inp
)->inp_flags
& IN6P_IPV6_V6ONLY
)
1194 ipv4_addr_legal
= 1;
1197 ipv4_addr_legal
= 1;
1200 if (inp
->sctp_flags
& SCTP_PCB_FLAGS_BOUNDALL
) {
1201 TAILQ_FOREACH(ifn
, &ifnet
, if_list
) {
1202 struct ifaddr_container
*ifac
;
1204 if ((loopback_scope
== 0) &&
1205 (ifn
->if_type
== IFT_LOOP
)) {
1206 /* Skip loopback if loopback_scope not set */
1209 TAILQ_FOREACH(ifac
, &ifn
->if_addrheads
[mycpuid
],
1211 struct ifaddr
*ifa
= ifac
->ifa
;
1215 * For the BOUND-ALL case, the list
1216 * associated with a TCB is Always
1217 * considered a reverse list.. i.e.
1218 * it lists addresses that are NOT
1219 * part of the association. If this
1220 * is one of those we must skip it.
1222 if (sctp_is_addr_restricted(stcb
,
1227 if ((ifa
->ifa_addr
->sa_family
== AF_INET
) &&
1228 (ipv4_addr_legal
)) {
1229 struct sockaddr_in
*sin
;
1230 sin
= (struct sockaddr_in
*)ifa
->ifa_addr
;
1231 if (sin
->sin_addr
.s_addr
== 0) {
1232 /* we skip unspecifed addresses */
1235 if ((ipv4_local_scope
== 0) &&
1236 (IN4_ISPRIVATE_ADDRESS(&sin
->sin_addr
))) {
1239 if (inp
->sctp_flags
& SCTP_PCB_FLAGS_NEEDS_MAPPED_V4
) {
1240 in6_sin_2_v4mapsin6(sin
, (struct sockaddr_in6
*)sas
);
1241 ((struct sockaddr_in6
*)sas
)->sin6_port
= inp
->sctp_lport
;
1242 sas
= (struct sockaddr_storage
*)((caddr_t
)sas
+ sizeof(struct sockaddr_in6
));
1243 actual
+= sizeof(struct sockaddr_in6
);
1245 memcpy(sas
, sin
, sizeof(*sin
));
1246 ((struct sockaddr_in
*)sas
)->sin_port
= inp
->sctp_lport
;
1247 sas
= (struct sockaddr_storage
*)((caddr_t
)sas
+ sizeof(*sin
));
1248 actual
+= sizeof(*sin
);
1250 if (actual
>= limit
) {
1253 } else if ((ifa
->ifa_addr
->sa_family
== AF_INET6
) &&
1254 (ipv6_addr_legal
)) {
1255 struct sockaddr_in6
*sin6
, lsa6
;
1256 sin6
= (struct sockaddr_in6
*)ifa
->ifa_addr
;
1257 if (IN6_IS_ADDR_UNSPECIFIED(&sin6
->sin6_addr
)) {
1258 /* we skip unspecifed addresses */
1261 if (IN6_IS_ADDR_LINKLOCAL(&sin6
->sin6_addr
)) {
1262 if (local_scope
== 0)
1264 if (sin6
->sin6_scope_id
== 0) {
1266 if (in6_recoverscope(&lsa6
,
1269 /* bad link local address */
1274 if ((site_scope
== 0) &&
1275 (IN6_IS_ADDR_SITELOCAL(&sin6
->sin6_addr
))) {
1278 memcpy(sas
, sin6
, sizeof(*sin6
));
1279 ((struct sockaddr_in6
*)sas
)->sin6_port
= inp
->sctp_lport
;
1280 sas
= (struct sockaddr_storage
*)((caddr_t
)sas
+ sizeof(*sin6
));
1281 actual
+= sizeof(*sin6
);
1282 if (actual
>= limit
) {
1289 struct sctp_laddr
*laddr
;
1291 * If we have a TCB and we do NOT support ASCONF (it's
1292 * turned off or otherwise) then the list is always the
1293 * true list of addresses (the else case below). Otherwise
1294 * the list on the association is a list of addresses that
1295 * are NOT part of the association.
1297 if (inp
->sctp_flags
& SCTP_PCB_FLAGS_DO_ASCONF
) {
1298 /* The list is a NEGATIVE list */
1299 LIST_FOREACH(laddr
, &inp
->sctp_addr_list
, sctp_nxt_addr
) {
1301 if (sctp_is_addr_restricted(stcb
, laddr
->ifa
->ifa_addr
)) {
1305 if (sctp_fill_user_address(sas
, laddr
->ifa
->ifa_addr
))
1308 ((struct sockaddr_in6
*)sas
)->sin6_port
= inp
->sctp_lport
;
1309 sas
= (struct sockaddr_storage
*)((caddr_t
)sas
+
1310 laddr
->ifa
->ifa_addr
->sa_len
);
1311 actual
+= laddr
->ifa
->ifa_addr
->sa_len
;
1312 if (actual
>= limit
) {
1317 /* The list is a positive list if present */
1319 /* Must use the specific association list */
1320 LIST_FOREACH(laddr
, &stcb
->asoc
.sctp_local_addr_list
,
1322 if (sctp_fill_user_address(sas
,
1323 laddr
->ifa
->ifa_addr
))
1325 ((struct sockaddr_in6
*)sas
)->sin6_port
= inp
->sctp_lport
;
1326 sas
= (struct sockaddr_storage
*)((caddr_t
)sas
+
1327 laddr
->ifa
->ifa_addr
->sa_len
);
1328 actual
+= laddr
->ifa
->ifa_addr
->sa_len
;
1329 if (actual
>= limit
) {
1334 /* No endpoint so use the endpoints individual list */
1335 LIST_FOREACH(laddr
, &inp
->sctp_addr_list
,
1337 if (sctp_fill_user_address(sas
,
1338 laddr
->ifa
->ifa_addr
))
1340 ((struct sockaddr_in6
*)sas
)->sin6_port
= inp
->sctp_lport
;
1341 sas
= (struct sockaddr_storage
*)((caddr_t
)sas
+
1342 laddr
->ifa
->ifa_addr
->sa_len
);
1343 actual
+= laddr
->ifa
->ifa_addr
->sa_len
;
1344 if (actual
>= limit
) {
1355 sctp_count_max_addresses(struct sctp_inpcb
*inp
)
1359 * In both sub-set bound an bound_all cases we return the MAXIMUM
1360 * number of addresses that you COULD get. In reality the sub-set
1361 * bound may have an exclusion list for a given TCB OR in the
1362 * bound-all case a TCB may NOT include the loopback or other
1363 * addresses as well.
1365 if (inp
->sctp_flags
& SCTP_PCB_FLAGS_BOUNDALL
) {
1368 TAILQ_FOREACH(ifn
, &ifnet
, if_list
) {
1369 struct ifaddr_container
*ifac
;
1371 TAILQ_FOREACH(ifac
, &ifn
->if_addrheads
[mycpuid
], ifa_link
) {
1372 struct ifaddr
*ifa
= ifac
->ifa
;
1374 /* Count them if they are the right type */
1375 if (ifa
->ifa_addr
->sa_family
== AF_INET
) {
1376 if (inp
->sctp_flags
& SCTP_PCB_FLAGS_NEEDS_MAPPED_V4
)
1377 cnt
+= sizeof(struct sockaddr_in6
);
1379 cnt
+= sizeof(struct sockaddr_in
);
1381 } else if (ifa
->ifa_addr
->sa_family
== AF_INET6
)
1382 cnt
+= sizeof(struct sockaddr_in6
);
1386 struct sctp_laddr
*laddr
;
1387 LIST_FOREACH(laddr
, &inp
->sctp_addr_list
, sctp_nxt_addr
) {
1388 if (laddr
->ifa
->ifa_addr
->sa_family
== AF_INET
) {
1389 if (inp
->sctp_flags
& SCTP_PCB_FLAGS_NEEDS_MAPPED_V4
)
1390 cnt
+= sizeof(struct sockaddr_in6
);
1392 cnt
+= sizeof(struct sockaddr_in
);
1394 } else if (laddr
->ifa
->ifa_addr
->sa_family
== AF_INET6
)
1395 cnt
+= sizeof(struct sockaddr_in6
);
1402 sctp_do_connect_x(struct socket
*so
,
1403 struct sctp_inpcb
*inp
,
1405 #if (defined(__FreeBSD__) && __FreeBSD_version >= 500000) || defined(__DragonFly__)
1414 struct sctp_tcb
*stcb
= NULL
;
1415 struct sockaddr
*sa
;
1416 int num_v6
=0, num_v4
=0, *totaddrp
, totaddr
, i
, incr
, at
;
1418 if (sctp_debug_on
& SCTP_DEBUG_PCB1
) {
1419 kprintf("Connectx called\n");
1421 #endif /* SCTP_DEBUG */
1423 if ((inp
->sctp_flags
& SCTP_PCB_FLAGS_TCPTYPE
) &&
1424 (inp
->sctp_flags
& SCTP_PCB_FLAGS_CONNECTED
)) {
1425 /* We are already connected AND the TCP model */
1426 return (EADDRINUSE
);
1428 if (inp
->sctp_flags
& SCTP_PCB_FLAGS_CONNECTED
) {
1429 SCTP_INP_RLOCK(inp
);
1430 stcb
= LIST_FIRST(&inp
->sctp_asoc_list
);
1431 SCTP_INP_RUNLOCK(inp
);
1437 SCTP_ASOC_CREATE_LOCK(inp
);
1438 if ((inp
->sctp_flags
& SCTP_PCB_FLAGS_SOCKET_GONE
) ||
1439 (inp
->sctp_flags
& SCTP_PCB_FLAGS_SOCKET_GONE
)) {
1440 SCTP_ASOC_CREATE_UNLOCK(inp
);
1444 totaddrp
= mtod(m
, int *);
1445 totaddr
= *totaddrp
;
1446 sa
= (struct sockaddr
*)(totaddrp
+ 1);
1448 /* account and validate addresses */
1449 SCTP_INP_WLOCK(inp
);
1450 SCTP_INP_INCR_REF(inp
);
1451 SCTP_INP_WUNLOCK(inp
);
1452 for (i
= 0; i
< totaddr
; i
++) {
1453 if (sa
->sa_family
== AF_INET
) {
1455 incr
= sizeof(struct sockaddr_in
);
1456 } else if (sa
->sa_family
== AF_INET6
) {
1457 struct sockaddr_in6
*sin6
;
1458 sin6
= (struct sockaddr_in6
*)sa
;
1459 if (IN6_IS_ADDR_V4MAPPED(&sin6
->sin6_addr
)) {
1460 /* Must be non-mapped for connectx */
1461 SCTP_ASOC_CREATE_UNLOCK(inp
);
1465 incr
= sizeof(struct sockaddr_in6
);
1470 stcb
= sctp_findassociation_ep_addr(&inp
, sa
, NULL
, NULL
, NULL
);
1472 /* Already have or am bring up an association */
1473 SCTP_ASOC_CREATE_UNLOCK(inp
);
1474 SCTP_TCB_UNLOCK(stcb
);
1477 if ((at
+ incr
) > m
->m_len
) {
1481 sa
= (struct sockaddr
*)((caddr_t
)sa
+ incr
);
1483 sa
= (struct sockaddr
*)(totaddrp
+ 1);
1484 SCTP_INP_WLOCK(inp
);
1485 SCTP_INP_DECR_REF(inp
);
1486 SCTP_INP_WUNLOCK(inp
);
1488 if (((inp
->sctp_flags
& SCTP_PCB_FLAGS_BOUND_V6
) == 0) &&
1490 SCTP_INP_WUNLOCK(inp
);
1491 SCTP_ASOC_CREATE_UNLOCK(inp
);
1494 if ((inp
->sctp_flags
& SCTP_PCB_FLAGS_BOUND_V6
) &&
1496 struct in6pcb
*inp6
;
1497 inp6
= (struct in6pcb
*)inp
;
1499 #if defined(__OpenBSD__)
1500 (0) /* we always do dual bind */
1501 #elif defined (__NetBSD__)
1502 (inp6
->in6p_flags
& IN6P_IPV6_V6ONLY
)
1504 (inp6
->inp_flags
& IN6P_IPV6_V6ONLY
)
1508 * if IPV6_V6ONLY flag, ignore connections
1509 * destined to a v4 addr or v4-mapped addr
1511 SCTP_INP_WUNLOCK(inp
);
1512 SCTP_ASOC_CREATE_UNLOCK(inp
);
1517 if ((inp
->sctp_flags
& SCTP_PCB_FLAGS_UNBOUND
) ==
1518 SCTP_PCB_FLAGS_UNBOUND
) {
1519 /* Bind a ephemeral port */
1520 SCTP_INP_WUNLOCK(inp
);
1521 error
= sctp_inpcb_bind(so
, NULL
, p
);
1523 SCTP_ASOC_CREATE_UNLOCK(inp
);
1527 SCTP_INP_WUNLOCK(inp
);
1529 /* We are GOOD to go */
1530 stcb
= sctp_aloc_assoc(inp
, sa
, 1, &error
, 0);
1532 /* Gak! no memory */
1533 SCTP_ASOC_CREATE_UNLOCK(inp
);
1536 /* move to second address */
1537 if (sa
->sa_family
== AF_INET
)
1538 sa
= (struct sockaddr
*)((caddr_t
)sa
+ sizeof(struct sockaddr_in
));
1540 sa
= (struct sockaddr
*)((caddr_t
)sa
+ sizeof(struct sockaddr_in6
));
1542 for (i
= 1; i
< totaddr
; i
++) {
1543 if (sa
->sa_family
== AF_INET
) {
1544 incr
= sizeof(struct sockaddr_in
);
1545 if (sctp_add_remote_addr(stcb
, sa
, 0, 8)) {
1546 /* assoc gone no un-lock */
1547 sctp_free_assoc(inp
, stcb
);
1548 SCTP_ASOC_CREATE_UNLOCK(inp
);
1552 } else if (sa
->sa_family
== AF_INET6
) {
1553 incr
= sizeof(struct sockaddr_in6
);
1554 if (sctp_add_remote_addr(stcb
, sa
, 0, 8)) {
1555 /* assoc gone no un-lock */
1556 sctp_free_assoc(inp
, stcb
);
1557 SCTP_ASOC_CREATE_UNLOCK(inp
);
1561 sa
= (struct sockaddr
*)((caddr_t
)sa
+ incr
);
1563 stcb
->asoc
.state
= SCTP_STATE_COOKIE_WAIT
;
1565 /* doing delayed connection */
1566 stcb
->asoc
.delayed_connection
= 1;
1567 sctp_timer_start(SCTP_TIMER_TYPE_INIT
, inp
, stcb
, stcb
->asoc
.primary_destination
);
1569 SCTP_GETTIME_TIMEVAL(&stcb
->asoc
.time_entered
);
1570 sctp_send_initiate(inp
, stcb
);
1572 SCTP_TCB_UNLOCK(stcb
);
1573 if (stcb
->sctp_ep
->sctp_flags
& SCTP_PCB_FLAGS_TCPTYPE
) {
1574 stcb
->sctp_ep
->sctp_flags
|= SCTP_PCB_FLAGS_CONNECTED
;
1575 /* Set the connected flag so we can queue data */
1578 SCTP_ASOC_CREATE_UNLOCK(inp
);
1584 sctp_optsget(struct socket
*so
,
1587 #if (defined(__FreeBSD__) && __FreeBSD_version >= 500000) || defined(__DragonFly__)
1594 struct sctp_inpcb
*inp
;
1596 int error
, optval
=0;
1597 struct sctp_tcb
*stcb
= NULL
;
1599 inp
= (struct sctp_inpcb
*)so
->so_pcb
;
1606 if (sctp_debug_on
& SCTP_DEBUG_USRREQ1
) {
1607 kprintf("optsget:MP is NULL EINVAL\n");
1609 #endif /* SCTP_DEBUG */
1614 /* Got to have a mbuf */
1616 if (sctp_debug_on
& SCTP_DEBUG_USRREQ1
) {
1617 kprintf("Huh no mbuf\n");
1619 #endif /* SCTP_DEBUG */
1623 if (sctp_debug_on
& SCTP_DEBUG_USRREQ2
) {
1624 kprintf("optsget opt:%lxx sz:%u\n", (unsigned long)opt
,
1627 #endif /* SCTP_DEBUG */
1631 case SCTP_AUTOCLOSE
:
1632 case SCTP_AUTO_ASCONF
:
1633 case SCTP_DISABLE_FRAGMENTS
:
1634 case SCTP_I_WANT_MAPPED_V4_ADDR
:
1636 if (sctp_debug_on
& SCTP_DEBUG_USRREQ2
) {
1637 kprintf("other stuff\n");
1639 #endif /* SCTP_DEBUG */
1640 SCTP_INP_RLOCK(inp
);
1642 case SCTP_DISABLE_FRAGMENTS
:
1643 optval
= inp
->sctp_flags
& SCTP_PCB_FLAGS_NO_FRAGMENT
;
1645 case SCTP_I_WANT_MAPPED_V4_ADDR
:
1646 optval
= inp
->sctp_flags
& SCTP_PCB_FLAGS_NEEDS_MAPPED_V4
;
1648 case SCTP_AUTO_ASCONF
:
1649 optval
= inp
->sctp_flags
& SCTP_PCB_FLAGS_AUTO_ASCONF
;
1652 optval
= inp
->sctp_flags
& SCTP_PCB_FLAGS_NODELAY
;
1654 case SCTP_AUTOCLOSE
:
1655 if ((inp
->sctp_flags
& SCTP_PCB_FLAGS_AUTOCLOSE
) ==
1656 SCTP_PCB_FLAGS_AUTOCLOSE
)
1657 optval
= inp
->sctp_ep
.auto_close_time
;
1663 error
= ENOPROTOOPT
;
1664 } /* end switch (sopt->sopt_name) */
1665 if (opt
!= SCTP_AUTOCLOSE
) {
1666 /* make it an "on/off" value */
1667 optval
= (optval
!= 0);
1669 if ((size_t)m
->m_len
< sizeof(int)) {
1672 SCTP_INP_RUNLOCK(inp
);
1674 /* return the option value */
1675 *mtod(m
, int *) = optval
;
1676 m
->m_len
= sizeof(optval
);
1679 case SCTP_GET_ASOC_ID_LIST
:
1681 struct sctp_assoc_ids
*ids
;
1685 if ((size_t)m
->m_len
< sizeof(struct sctp_assoc_ids
)) {
1689 ids
= mtod(m
, struct sctp_assoc_ids
*);
1691 SCTP_INP_RLOCK(inp
);
1692 stcb
= LIST_FIRST(&inp
->sctp_asoc_list
);
1695 ids
->asls_numb_present
= 0;
1696 ids
->asls_more_to_get
= 0;
1697 SCTP_INP_RUNLOCK(inp
);
1700 orig
= ids
->asls_assoc_start
;
1701 stcb
= LIST_FIRST(&inp
->sctp_asoc_list
);
1703 stcb
= LIST_NEXT(stcb
, sctp_tcblist
);
1711 ids
->asls_numb_present
= 0;
1712 ids
->asls_more_to_get
= 1;
1713 while(at
< MAX_ASOC_IDS_RET
) {
1714 ids
->asls_assoc_id
[at
] = sctp_get_associd(stcb
);
1716 ids
->asls_numb_present
++;
1717 stcb
= LIST_NEXT(stcb
, sctp_tcblist
);
1719 ids
->asls_more_to_get
= 0;
1723 SCTP_INP_RUNLOCK(inp
);
1726 case SCTP_GET_NONCE_VALUES
:
1728 struct sctp_get_nonce_values
*gnv
;
1729 if ((size_t)m
->m_len
< sizeof(struct sctp_get_nonce_values
)) {
1733 gnv
= mtod(m
, struct sctp_get_nonce_values
*);
1734 stcb
= sctp_findassociation_ep_asocid(inp
, gnv
->gn_assoc_id
);
1738 gnv
->gn_peers_tag
= stcb
->asoc
.peer_vtag
;
1739 gnv
->gn_local_tag
= stcb
->asoc
.my_vtag
;
1740 SCTP_TCB_UNLOCK(stcb
);
1745 case SCTP_PEER_PUBLIC_KEY
:
1746 case SCTP_MY_PUBLIC_KEY
:
1747 case SCTP_SET_AUTH_CHUNKS
:
1748 case SCTP_SET_AUTH_SECRET
:
1749 /* not supported yet and until we refine the draft */
1753 case SCTP_DELAYED_ACK_TIME
:
1756 if ((size_t)m
->m_len
< sizeof(int32_t)) {
1760 tm
= mtod(m
, int32_t *);
1762 *tm
= TICKS_TO_MSEC(inp
->sctp_ep
.sctp_timeoutticks
[SCTP_TIMER_RECV
]);
1766 case SCTP_GET_SNDBUF_USE
:
1767 if ((size_t)m
->m_len
< sizeof(struct sctp_sockstat
)) {
1770 struct sctp_sockstat
*ss
;
1771 struct sctp_tcb
*stcb
;
1772 struct sctp_association
*asoc
;
1773 ss
= mtod(m
, struct sctp_sockstat
*);
1774 stcb
= sctp_findassociation_ep_asocid(inp
, ss
->ss_assoc_id
);
1779 ss
->ss_total_sndbuf
= (u_int32_t
)asoc
->total_output_queue_size
;
1780 ss
->ss_total_mbuf_sndbuf
= (u_int32_t
)asoc
->total_output_mbuf_queue_size
;
1781 ss
->ss_total_recv_buf
= (u_int32_t
)(asoc
->size_on_delivery_queue
+
1782 asoc
->size_on_reasm_queue
+
1783 asoc
->size_on_all_streams
);
1784 SCTP_TCB_UNLOCK(stcb
);
1786 m
->m_len
= sizeof(struct sctp_sockstat
);
1793 burst
= mtod(m
, u_int8_t
*);
1794 SCTP_INP_RLOCK(inp
);
1795 *burst
= inp
->sctp_ep
.max_burst
;
1796 SCTP_INP_RUNLOCK(inp
);
1797 m
->m_len
= sizeof(u_int8_t
);
1803 sctp_assoc_t
*assoc_id
;
1806 if ((size_t)m
->m_len
< sizeof(u_int32_t
)) {
1810 if ((size_t)m
->m_len
< sizeof(sctp_assoc_t
)) {
1814 assoc_id
= mtod(m
, sctp_assoc_t
*);
1815 segsize
= mtod(m
, u_int32_t
*);
1816 m
->m_len
= sizeof(u_int32_t
);
1818 if (((inp
->sctp_flags
& SCTP_PCB_FLAGS_TCPTYPE
) &&
1819 (inp
->sctp_flags
& SCTP_PCB_FLAGS_CONNECTED
)) ||
1820 (inp
->sctp_flags
& SCTP_PCB_FLAGS_IN_TCPPOOL
)) {
1821 struct sctp_tcb
*stcb
;
1822 SCTP_INP_RLOCK(inp
);
1823 stcb
= LIST_FIRST(&inp
->sctp_asoc_list
);
1825 SCTP_TCB_LOCK(stcb
);
1826 SCTP_INP_RUNLOCK(inp
);
1827 *segsize
= sctp_get_frag_point(stcb
, &stcb
->asoc
);
1828 SCTP_TCB_UNLOCK(stcb
);
1830 SCTP_INP_RUNLOCK(inp
);
1834 stcb
= sctp_findassociation_ep_asocid(inp
, *assoc_id
);
1836 *segsize
= sctp_get_frag_point(stcb
, &stcb
->asoc
);
1837 SCTP_TCB_UNLOCK(stcb
);
1841 /* default is to get the max, if I
1842 * can't calculate from an existing association.
1844 if (inp
->sctp_flags
& SCTP_PCB_FLAGS_BOUND_V6
) {
1845 ovh
= SCTP_MED_OVERHEAD
;
1847 ovh
= SCTP_MED_V4_OVERHEAD
;
1849 *segsize
= inp
->sctp_frag_point
- ovh
;
1854 case SCTP_SET_DEBUG_LEVEL
:
1858 if ((size_t)m
->m_len
< sizeof(u_int32_t
)) {
1862 level
= mtod(m
, u_int32_t
*);
1864 *level
= sctp_debug_on
;
1865 m
->m_len
= sizeof(u_int32_t
);
1866 kprintf("Returning DEBUG LEVEL %x is set\n",
1867 (u_int
)sctp_debug_on
);
1869 #else /* SCTP_DEBUG */
1873 case SCTP_GET_STAT_LOG
:
1874 #ifdef SCTP_STAT_LOGGING
1875 error
= sctp_fill_stat_log(m
);
1876 #else /* SCTP_DEBUG */
1883 if ((size_t)m
->m_len
< sizeof(sctp_pegs
)) {
1887 pt
= mtod(m
, u_int32_t
*);
1888 memcpy(pt
, sctp_pegs
, sizeof(sctp_pegs
));
1889 m
->m_len
= sizeof(sctp_pegs
);
1894 struct sctp_event_subscribe
*events
;
1896 if (sctp_debug_on
& SCTP_DEBUG_USRREQ2
) {
1897 kprintf("get events\n");
1899 #endif /* SCTP_DEBUG */
1900 if ((size_t)m
->m_len
< sizeof(struct sctp_event_subscribe
)) {
1902 if (sctp_debug_on
& SCTP_DEBUG_USRREQ2
) {
1903 kprintf("M->M_LEN is %d not %d\n",
1905 (int)sizeof(struct sctp_event_subscribe
));
1907 #endif /* SCTP_DEBUG */
1911 events
= mtod(m
, struct sctp_event_subscribe
*);
1912 memset(events
, 0, sizeof(*events
));
1913 SCTP_INP_RLOCK(inp
);
1914 if (inp
->sctp_flags
& SCTP_PCB_FLAGS_RECVDATAIOEVNT
)
1915 events
->sctp_data_io_event
= 1;
1917 if (inp
->sctp_flags
& SCTP_PCB_FLAGS_RECVASSOCEVNT
)
1918 events
->sctp_association_event
= 1;
1920 if (inp
->sctp_flags
& SCTP_PCB_FLAGS_RECVPADDREVNT
)
1921 events
->sctp_address_event
= 1;
1923 if (inp
->sctp_flags
& SCTP_PCB_FLAGS_RECVSENDFAILEVNT
)
1924 events
->sctp_send_failure_event
= 1;
1926 if (inp
->sctp_flags
& SCTP_PCB_FLAGS_RECVPEERERR
)
1927 events
->sctp_peer_error_event
= 1;
1929 if (inp
->sctp_flags
& SCTP_PCB_FLAGS_RECVSHUTDOWNEVNT
)
1930 events
->sctp_shutdown_event
= 1;
1932 if (inp
->sctp_flags
& SCTP_PCB_FLAGS_PDAPIEVNT
)
1933 events
->sctp_partial_delivery_event
= 1;
1935 if (inp
->sctp_flags
& SCTP_PCB_FLAGS_ADAPTIONEVNT
)
1936 events
->sctp_adaption_layer_event
= 1;
1938 if (inp
->sctp_flags
& SCTP_PCB_FLAGS_STREAM_RESETEVNT
)
1939 events
->sctp_stream_reset_events
= 1;
1940 SCTP_INP_RUNLOCK(inp
);
1941 m
->m_len
= sizeof(struct sctp_event_subscribe
);
1946 case SCTP_ADAPTION_LAYER
:
1947 if ((size_t)m
->m_len
< sizeof(int)) {
1952 if (sctp_debug_on
& SCTP_DEBUG_USRREQ1
) {
1953 kprintf("getadaption ind\n");
1955 #endif /* SCTP_DEBUG */
1956 SCTP_INP_RLOCK(inp
);
1957 *mtod(m
, int *) = inp
->sctp_ep
.adaption_layer_indicator
;
1958 SCTP_INP_RUNLOCK(inp
);
1959 m
->m_len
= sizeof(int);
1961 case SCTP_SET_INITIAL_DBG_SEQ
:
1962 if ((size_t)m
->m_len
< sizeof(int)) {
1967 if (sctp_debug_on
& SCTP_DEBUG_USRREQ1
) {
1968 kprintf("get initial dbg seq\n");
1970 #endif /* SCTP_DEBUG */
1971 SCTP_INP_RLOCK(inp
);
1972 *mtod(m
, int *) = inp
->sctp_ep
.initial_sequence_debug
;
1973 SCTP_INP_RUNLOCK(inp
);
1974 m
->m_len
= sizeof(int);
1976 case SCTP_GET_LOCAL_ADDR_SIZE
:
1977 if ((size_t)m
->m_len
< sizeof(int)) {
1982 if (sctp_debug_on
& SCTP_DEBUG_USRREQ1
) {
1983 kprintf("get local sizes\n");
1985 #endif /* SCTP_DEBUG */
1986 SCTP_INP_RLOCK(inp
);
1987 *mtod(m
, int *) = sctp_count_max_addresses(inp
);
1988 SCTP_INP_RUNLOCK(inp
);
1989 m
->m_len
= sizeof(int);
1991 case SCTP_GET_REMOTE_ADDR_SIZE
:
1993 sctp_assoc_t
*assoc_id
;
1995 struct sctp_nets
*net
;
1997 if (sctp_debug_on
& SCTP_DEBUG_USRREQ1
) {
1998 kprintf("get remote size\n");
2000 #endif /* SCTP_DEBUG */
2001 if ((size_t)m
->m_len
< sizeof(sctp_assoc_t
)) {
2003 kprintf("m->m_len:%d not %zd\n",
2004 m
->m_len
, sizeof(sctp_assoc_t
));
2005 #endif /* SCTP_DEBUG */
2010 val
= mtod(m
, u_int32_t
*);
2011 if (inp
->sctp_flags
& SCTP_PCB_FLAGS_CONNECTED
) {
2012 SCTP_INP_RLOCK(inp
);
2013 stcb
= LIST_FIRST(&inp
->sctp_asoc_list
);
2015 SCTP_TCB_LOCK(stcb
);
2016 SCTP_INP_RUNLOCK(inp
);
2019 assoc_id
= mtod(m
, sctp_assoc_t
*);
2020 stcb
= sctp_findassociation_ep_asocid(inp
, *assoc_id
);
2029 /* Count the sizes */
2030 TAILQ_FOREACH(net
, &stcb
->asoc
.nets
, sctp_next
) {
2031 if ((stcb
->sctp_ep
->sctp_flags
& SCTP_PCB_FLAGS_NEEDS_MAPPED_V4
) ||
2032 (((struct sockaddr
*)&net
->ro
._l_addr
)->sa_family
== AF_INET6
)) {
2033 sz
+= sizeof(struct sockaddr_in6
);
2034 } else if (((struct sockaddr
*)&net
->ro
._l_addr
)->sa_family
== AF_INET
) {
2035 sz
+= sizeof(struct sockaddr_in
);
2041 SCTP_TCB_UNLOCK(stcb
);
2043 m
->m_len
= sizeof(u_int32_t
);
2046 case SCTP_GET_PEER_ADDRESSES
:
2048 * Get the address information, an array
2049 * is passed in to fill up we pack it.
2053 struct sockaddr_storage
*sas
;
2054 struct sctp_nets
*net
;
2055 struct sctp_getaddresses
*saddr
;
2057 if (sctp_debug_on
& SCTP_DEBUG_USRREQ1
) {
2058 kprintf("get peer addresses\n");
2060 #endif /* SCTP_DEBUG */
2061 if ((size_t)m
->m_len
< sizeof(struct sctp_getaddresses
)) {
2065 left
= m
->m_len
- sizeof(struct sctp_getaddresses
);
2066 saddr
= mtod(m
, struct sctp_getaddresses
*);
2067 if (inp
->sctp_flags
& SCTP_PCB_FLAGS_CONNECTED
) {
2068 SCTP_INP_RLOCK(inp
);
2069 stcb
= LIST_FIRST(&inp
->sctp_asoc_list
);
2071 SCTP_TCB_LOCK(stcb
);
2072 SCTP_INP_RUNLOCK(inp
);
2074 stcb
= sctp_findassociation_ep_asocid(inp
,
2075 saddr
->sget_assoc_id
);
2080 m
->m_len
= sizeof(struct sctp_getaddresses
);
2081 sas
= (struct sockaddr_storage
*)&saddr
->addr
[0];
2083 TAILQ_FOREACH(net
, &stcb
->asoc
.nets
, sctp_next
) {
2084 if ((stcb
->sctp_ep
->sctp_flags
& SCTP_PCB_FLAGS_NEEDS_MAPPED_V4
) ||
2085 (((struct sockaddr
*)&net
->ro
._l_addr
)->sa_family
== AF_INET6
)) {
2086 cpsz
= sizeof(struct sockaddr_in6
);
2087 } else if (((struct sockaddr
*)&net
->ro
._l_addr
)->sa_family
== AF_INET
) {
2088 cpsz
= sizeof(struct sockaddr_in
);
2094 /* not enough room. */
2096 if (sctp_debug_on
& SCTP_DEBUG_USRREQ1
) {
2097 kprintf("Out of room\n");
2099 #endif /* SCTP_DEBUG */
2102 if ((stcb
->sctp_ep
->sctp_flags
& SCTP_PCB_FLAGS_NEEDS_MAPPED_V4
) &&
2103 (((struct sockaddr
*)&net
->ro
._l_addr
)->sa_family
== AF_INET
)) {
2104 /* Must map the address */
2105 in6_sin_2_v4mapsin6((struct sockaddr_in
*)&net
->ro
._l_addr
,
2106 (struct sockaddr_in6
*)sas
);
2108 memcpy(sas
, &net
->ro
._l_addr
, cpsz
);
2110 ((struct sockaddr_in
*)sas
)->sin_port
= stcb
->rport
;
2112 sas
= (struct sockaddr_storage
*)((caddr_t
)sas
+ cpsz
);
2116 if (sctp_debug_on
& SCTP_DEBUG_USRREQ2
) {
2117 kprintf("left now:%d mlen:%d\n",
2120 #endif /* SCTP_DEBUG */
2122 SCTP_TCB_UNLOCK(stcb
);
2125 if (sctp_debug_on
& SCTP_DEBUG_USRREQ1
) {
2126 kprintf("All done\n");
2128 #endif /* SCTP_DEBUG */
2130 case SCTP_GET_LOCAL_ADDRESSES
:
2133 struct sockaddr_storage
*sas
;
2134 struct sctp_getaddresses
*saddr
;
2136 if (sctp_debug_on
& SCTP_DEBUG_USRREQ1
) {
2137 kprintf("get local addresses\n");
2139 #endif /* SCTP_DEBUG */
2140 if ((size_t)m
->m_len
< sizeof(struct sctp_getaddresses
)) {
2144 saddr
= mtod(m
, struct sctp_getaddresses
*);
2146 if (saddr
->sget_assoc_id
) {
2147 if (inp
->sctp_flags
& SCTP_PCB_FLAGS_CONNECTED
) {
2148 SCTP_INP_RLOCK(inp
);
2149 stcb
= LIST_FIRST(&inp
->sctp_asoc_list
);
2151 SCTP_TCB_LOCK(stcb
);
2152 SCTP_INP_RUNLOCK(inp
);
2154 stcb
= sctp_findassociation_ep_asocid(inp
, saddr
->sget_assoc_id
);
2160 * assure that the TCP model does not need a assoc id
2163 if ( (inp
->sctp_flags
& SCTP_PCB_FLAGS_CONNECTED
) &&
2165 SCTP_INP_RLOCK(inp
);
2166 stcb
= LIST_FIRST(&inp
->sctp_asoc_list
);
2168 SCTP_TCB_LOCK(stcb
);
2169 SCTP_INP_RUNLOCK(inp
);
2171 sas
= (struct sockaddr_storage
*)&saddr
->addr
[0];
2172 limit
= m
->m_len
- sizeof(sctp_assoc_t
);
2173 actual
= sctp_fill_up_addresses(inp
, stcb
, limit
, sas
);
2174 SCTP_TCB_UNLOCK(stcb
);
2175 m
->m_len
= sizeof(struct sockaddr_storage
) + actual
;
2178 case SCTP_PEER_ADDR_PARAMS
:
2180 struct sctp_paddrparams
*paddrp
;
2181 struct sctp_nets
*net
;
2184 if (sctp_debug_on
& SCTP_DEBUG_USRREQ1
) {
2185 kprintf("Getting peer_addr_params\n");
2187 #endif /* SCTP_DEBUG */
2188 if ((size_t)m
->m_len
< sizeof(struct sctp_paddrparams
)) {
2190 if (sctp_debug_on
& SCTP_DEBUG_USRREQ2
) {
2191 kprintf("Hmm m->m_len:%d is to small\n",
2194 #endif /* SCTP_DEBUG */
2198 paddrp
= mtod(m
, struct sctp_paddrparams
*);
2201 if (paddrp
->spp_assoc_id
) {
2203 if (sctp_debug_on
& SCTP_DEBUG_USRREQ1
) {
2204 kprintf("In spp_assoc_id find type\n");
2206 #endif /* SCTP_DEBUG */
2207 if (inp
->sctp_flags
& SCTP_PCB_FLAGS_CONNECTED
) {
2208 SCTP_INP_RLOCK(inp
);
2209 stcb
= LIST_FIRST(&inp
->sctp_asoc_list
);
2211 SCTP_TCB_LOCK(stcb
);
2212 net
= sctp_findnet(stcb
, (struct sockaddr
*)&paddrp
->spp_address
);
2214 SCTP_INP_RLOCK(inp
);
2216 stcb
= sctp_findassociation_ep_asocid(inp
, paddrp
->spp_assoc_id
);
2223 if ( (stcb
== NULL
) &&
2224 ((((struct sockaddr
*)&paddrp
->spp_address
)->sa_family
== AF_INET
) ||
2225 (((struct sockaddr
*)&paddrp
->spp_address
)->sa_family
== AF_INET6
))) {
2226 /* Lookup via address */
2228 if (sctp_debug_on
& SCTP_DEBUG_USRREQ1
) {
2229 kprintf("Ok we need to lookup a param\n");
2231 #endif /* SCTP_DEBUG */
2232 if (inp
->sctp_flags
& SCTP_PCB_FLAGS_CONNECTED
) {
2233 SCTP_INP_RLOCK(inp
);
2234 stcb
= LIST_FIRST(&inp
->sctp_asoc_list
);
2236 SCTP_TCB_LOCK(stcb
);
2237 net
= sctp_findnet(stcb
, (struct sockaddr
*)&paddrp
->spp_address
);
2239 SCTP_INP_RUNLOCK(inp
);
2241 SCTP_INP_WLOCK(inp
);
2242 SCTP_INP_INCR_REF(inp
);
2243 SCTP_INP_WUNLOCK(inp
);
2244 stcb
= sctp_findassociation_ep_addr(&inp
,
2245 (struct sockaddr
*)&paddrp
->spp_address
,
2248 SCTP_INP_WLOCK(inp
);
2249 SCTP_INP_DECR_REF(inp
);
2250 SCTP_INP_WUNLOCK(inp
);
2259 /* Effects the Endpoint */
2261 if (sctp_debug_on
& SCTP_DEBUG_USRREQ1
) {
2262 kprintf("User wants EP level info\n");
2264 #endif /* SCTP_DEBUG */
2268 /* Applys to the specific association */
2270 if (sctp_debug_on
& SCTP_DEBUG_USRREQ1
) {
2271 kprintf("In TCB side\n");
2273 #endif /* SCTP_DEBUG */
2275 paddrp
->spp_pathmaxrxt
= net
->failure_threshold
;
2277 /* No destination so return default value */
2278 paddrp
->spp_pathmaxrxt
= stcb
->asoc
.def_net_failure
;
2280 paddrp
->spp_hbinterval
= stcb
->asoc
.heart_beat_delay
;
2281 paddrp
->spp_assoc_id
= sctp_get_associd(stcb
);
2282 SCTP_TCB_UNLOCK(stcb
);
2284 /* Use endpoint defaults */
2285 SCTP_INP_RLOCK(inp
);
2287 if (sctp_debug_on
& SCTP_DEBUG_USRREQ1
) {
2288 kprintf("In EP level info\n");
2290 #endif /* SCTP_DEBUG */
2291 paddrp
->spp_pathmaxrxt
= inp
->sctp_ep
.def_net_failure
;
2292 paddrp
->spp_hbinterval
= inp
->sctp_ep
.sctp_timeoutticks
[SCTP_TIMER_HEARTBEAT
];
2293 paddrp
->spp_assoc_id
= (sctp_assoc_t
)0;
2294 SCTP_INP_RUNLOCK(inp
);
2296 m
->m_len
= sizeof(struct sctp_paddrparams
);
2299 case SCTP_GET_PEER_ADDR_INFO
:
2301 struct sctp_paddrinfo
*paddri
;
2302 struct sctp_nets
*net
;
2304 if (sctp_debug_on
& SCTP_DEBUG_USRREQ1
) {
2305 kprintf("GetPEER ADDR_INFO\n");
2307 #endif /* SCTP_DEBUG */
2308 if ((size_t)m
->m_len
< sizeof(struct sctp_paddrinfo
)) {
2312 paddri
= mtod(m
, struct sctp_paddrinfo
*);
2314 if ((((struct sockaddr
*)&paddri
->spinfo_address
)->sa_family
== AF_INET
) ||
2315 (((struct sockaddr
*)&paddri
->spinfo_address
)->sa_family
== AF_INET6
)) {
2316 /* Lookup via address */
2317 if (inp
->sctp_flags
& SCTP_PCB_FLAGS_CONNECTED
) {
2318 SCTP_INP_RLOCK(inp
);
2319 stcb
= LIST_FIRST(&inp
->sctp_asoc_list
);
2321 SCTP_TCB_LOCK(stcb
);
2322 net
= sctp_findnet(stcb
,
2323 (struct sockaddr
*)&paddri
->spinfo_address
);
2325 SCTP_INP_RUNLOCK(inp
);
2327 SCTP_INP_WLOCK(inp
);
2328 SCTP_INP_INCR_REF(inp
);
2329 SCTP_INP_WUNLOCK(inp
);
2330 stcb
= sctp_findassociation_ep_addr(&inp
,
2331 (struct sockaddr
*)&paddri
->spinfo_address
,
2334 SCTP_INP_WLOCK(inp
);
2335 SCTP_INP_DECR_REF(inp
);
2336 SCTP_INP_WUNLOCK(inp
);
2343 if ((stcb
== NULL
) || (net
== NULL
)) {
2347 m
->m_len
= sizeof(struct sctp_paddrinfo
);
2348 paddri
->spinfo_state
= net
->dest_state
& (SCTP_REACHABLE_MASK
|SCTP_ADDR_NOHB
);
2349 paddri
->spinfo_cwnd
= net
->cwnd
;
2350 paddri
->spinfo_srtt
= ((net
->lastsa
>> 2) + net
->lastsv
) >> 1;
2351 paddri
->spinfo_rto
= net
->RTO
;
2352 paddri
->spinfo_assoc_id
= sctp_get_associd(stcb
);
2353 SCTP_TCB_UNLOCK(stcb
);
2356 case SCTP_PCB_STATUS
:
2358 struct sctp_pcbinfo
*spcb
;
2360 if (sctp_debug_on
& SCTP_DEBUG_USRREQ1
) {
2361 kprintf("PCB status\n");
2363 #endif /* SCTP_DEBUG */
2364 if ((size_t)m
->m_len
< sizeof(struct sctp_pcbinfo
)) {
2368 spcb
= mtod(m
, struct sctp_pcbinfo
*);
2369 sctp_fill_pcbinfo(spcb
);
2370 m
->m_len
= sizeof(struct sctp_pcbinfo
);
2375 struct sctp_nets
*net
;
2376 struct sctp_status
*sstat
;
2378 if (sctp_debug_on
& SCTP_DEBUG_USRREQ1
) {
2379 kprintf("SCTP status\n");
2381 #endif /* SCTP_DEBUG */
2383 if ((size_t)m
->m_len
< sizeof(struct sctp_status
)) {
2387 sstat
= mtod(m
, struct sctp_status
*);
2389 if (inp
->sctp_flags
& SCTP_PCB_FLAGS_CONNECTED
) {
2390 SCTP_INP_RLOCK(inp
);
2391 stcb
= LIST_FIRST(&inp
->sctp_asoc_list
);
2393 SCTP_TCB_LOCK(stcb
);
2394 SCTP_INP_RUNLOCK(inp
);
2396 stcb
= sctp_findassociation_ep_asocid(inp
, sstat
->sstat_assoc_id
);
2403 * I think passing the state is fine since
2404 * sctp_constants.h will be available to the user
2407 sstat
->sstat_state
= stcb
->asoc
.state
;
2408 sstat
->sstat_rwnd
= stcb
->asoc
.peers_rwnd
;
2409 sstat
->sstat_unackdata
= stcb
->asoc
.sent_queue_cnt
;
2411 * We can't include chunks that have been passed
2412 * to the socket layer. Only things in queue.
2414 sstat
->sstat_penddata
= (stcb
->asoc
.cnt_on_delivery_queue
+
2415 stcb
->asoc
.cnt_on_reasm_queue
+
2416 stcb
->asoc
.cnt_on_all_streams
);
2419 sstat
->sstat_instrms
= stcb
->asoc
.streamincnt
;
2420 sstat
->sstat_outstrms
= stcb
->asoc
.streamoutcnt
;
2421 sstat
->sstat_fragmentation_point
= sctp_get_frag_point(stcb
, &stcb
->asoc
);
2422 memcpy(&sstat
->sstat_primary
.spinfo_address
,
2423 &stcb
->asoc
.primary_destination
->ro
._l_addr
,
2424 ((struct sockaddr
*)(&stcb
->asoc
.primary_destination
->ro
._l_addr
))->sa_len
);
2425 net
= stcb
->asoc
.primary_destination
;
2426 ((struct sockaddr_in
*)&sstat
->sstat_primary
.spinfo_address
)->sin_port
= stcb
->rport
;
2428 * Again the user can get info from sctp_constants.h
2429 * for what the state of the network is.
2431 sstat
->sstat_primary
.spinfo_state
= net
->dest_state
& SCTP_REACHABLE_MASK
;
2432 sstat
->sstat_primary
.spinfo_cwnd
= net
->cwnd
;
2433 sstat
->sstat_primary
.spinfo_srtt
= net
->lastsa
;
2434 sstat
->sstat_primary
.spinfo_rto
= net
->RTO
;
2435 sstat
->sstat_primary
.spinfo_mtu
= net
->mtu
;
2436 sstat
->sstat_primary
.spinfo_assoc_id
= sctp_get_associd(stcb
);
2437 SCTP_TCB_UNLOCK(stcb
);
2438 m
->m_len
= sizeof(*sstat
);
2443 struct sctp_rtoinfo
*srto
;
2445 if (sctp_debug_on
& SCTP_DEBUG_USRREQ1
) {
2446 kprintf("RTO Info\n");
2448 #endif /* SCTP_DEBUG */
2449 if ((size_t)m
->m_len
< sizeof(struct sctp_rtoinfo
)) {
2453 srto
= mtod(m
, struct sctp_rtoinfo
*);
2454 if (srto
->srto_assoc_id
== 0) {
2455 /* Endpoint only please */
2456 SCTP_INP_RLOCK(inp
);
2457 srto
->srto_initial
= inp
->sctp_ep
.initial_rto
;
2458 srto
->srto_max
= inp
->sctp_ep
.sctp_maxrto
;
2459 srto
->srto_min
= inp
->sctp_ep
.sctp_minrto
;
2460 SCTP_INP_RUNLOCK(inp
);
2463 if (inp
->sctp_flags
& SCTP_PCB_FLAGS_CONNECTED
) {
2464 SCTP_INP_RLOCK(inp
);
2465 stcb
= LIST_FIRST(&inp
->sctp_asoc_list
);
2467 SCTP_TCB_LOCK(stcb
);
2468 SCTP_INP_RUNLOCK(inp
);
2470 stcb
= sctp_findassociation_ep_asocid(inp
, srto
->srto_assoc_id
);
2476 srto
->srto_initial
= stcb
->asoc
.initial_rto
;
2477 srto
->srto_max
= stcb
->asoc
.maxrto
;
2478 srto
->srto_min
= stcb
->asoc
.minrto
;
2479 SCTP_TCB_UNLOCK(stcb
);
2480 m
->m_len
= sizeof(*srto
);
2483 case SCTP_ASSOCINFO
:
2485 struct sctp_assocparams
*sasoc
;
2487 if (sctp_debug_on
& SCTP_DEBUG_USRREQ1
) {
2488 kprintf("Associnfo\n");
2490 #endif /* SCTP_DEBUG */
2491 if ((size_t)m
->m_len
< sizeof(struct sctp_assocparams
)) {
2495 sasoc
= mtod(m
, struct sctp_assocparams
*);
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 if ((sasoc
->sasoc_assoc_id
) && (stcb
== NULL
)) {
2506 stcb
= sctp_findassociation_ep_asocid(inp
,
2507 sasoc
->sasoc_assoc_id
);
2517 sasoc
->sasoc_asocmaxrxt
= stcb
->asoc
.max_send_times
;
2518 sasoc
->sasoc_number_peer_destinations
= stcb
->asoc
.numnets
;
2519 sasoc
->sasoc_peer_rwnd
= stcb
->asoc
.peers_rwnd
;
2520 sasoc
->sasoc_local_rwnd
= stcb
->asoc
.my_rwnd
;
2521 sasoc
->sasoc_cookie_life
= stcb
->asoc
.cookie_life
;
2522 SCTP_TCB_UNLOCK(stcb
);
2524 SCTP_INP_RLOCK(inp
);
2525 sasoc
->sasoc_asocmaxrxt
= inp
->sctp_ep
.max_send_times
;
2526 sasoc
->sasoc_number_peer_destinations
= 0;
2527 sasoc
->sasoc_peer_rwnd
= 0;
2528 sasoc
->sasoc_local_rwnd
= ssb_space(&inp
->sctp_socket
->so_rcv
);
2529 sasoc
->sasoc_cookie_life
= inp
->sctp_ep
.def_cookie_life
;
2530 SCTP_INP_RUNLOCK(inp
);
2532 m
->m_len
= sizeof(*sasoc
);
2535 case SCTP_DEFAULT_SEND_PARAM
:
2537 struct sctp_sndrcvinfo
*s_info
;
2539 if (m
->m_len
!= sizeof(struct sctp_sndrcvinfo
)) {
2543 s_info
= mtod(m
, struct sctp_sndrcvinfo
*);
2544 if (inp
->sctp_flags
& SCTP_PCB_FLAGS_CONNECTED
) {
2545 SCTP_INP_RLOCK(inp
);
2546 stcb
= LIST_FIRST(&inp
->sctp_asoc_list
);
2548 SCTP_TCB_LOCK(stcb
);
2549 SCTP_INP_RUNLOCK(inp
);
2551 stcb
= sctp_findassociation_ep_asocid(inp
, s_info
->sinfo_assoc_id
);
2558 *s_info
= stcb
->asoc
.def_send
;
2559 SCTP_TCB_UNLOCK(stcb
);
2560 m
->m_len
= sizeof(*s_info
);
2564 struct sctp_initmsg
*sinit
;
2566 if (sctp_debug_on
& SCTP_DEBUG_USRREQ1
) {
2567 kprintf("initmsg\n");
2569 #endif /* SCTP_DEBUG */
2570 if ((size_t)m
->m_len
< sizeof(struct sctp_initmsg
)) {
2574 sinit
= mtod(m
, struct sctp_initmsg
*);
2575 SCTP_INP_RLOCK(inp
);
2576 sinit
->sinit_num_ostreams
= inp
->sctp_ep
.pre_open_stream_count
;
2577 sinit
->sinit_max_instreams
= inp
->sctp_ep
.max_open_streams_intome
;
2578 sinit
->sinit_max_attempts
= inp
->sctp_ep
.max_init_times
;
2579 sinit
->sinit_max_init_timeo
= inp
->sctp_ep
.initial_init_rto_max
;
2580 SCTP_INP_RUNLOCK(inp
);
2581 m
->m_len
= sizeof(*sinit
);
2584 case SCTP_PRIMARY_ADDR
:
2585 /* we allow a "get" operation on this */
2587 struct sctp_setprim
*ssp
;
2590 if (sctp_debug_on
& SCTP_DEBUG_USRREQ1
) {
2591 kprintf("setprimary\n");
2593 #endif /* SCTP_DEBUG */
2594 if ((size_t)m
->m_len
< sizeof(struct sctp_setprim
)) {
2598 ssp
= mtod(m
, struct sctp_setprim
*);
2599 if (inp
->sctp_flags
& SCTP_PCB_FLAGS_CONNECTED
) {
2600 SCTP_INP_RLOCK(inp
);
2601 stcb
= LIST_FIRST(&inp
->sctp_asoc_list
);
2603 SCTP_TCB_LOCK(stcb
);
2604 SCTP_INP_RUNLOCK(inp
);
2606 stcb
= sctp_findassociation_ep_asocid(inp
, ssp
->ssp_assoc_id
);
2608 /* one last shot, try it by the address in */
2609 struct sctp_nets
*net
;
2611 SCTP_INP_WLOCK(inp
);
2612 SCTP_INP_INCR_REF(inp
);
2613 SCTP_INP_WUNLOCK(inp
);
2614 stcb
= sctp_findassociation_ep_addr(&inp
,
2615 (struct sockaddr
*)&ssp
->ssp_addr
,
2618 SCTP_INP_WLOCK(inp
);
2619 SCTP_INP_DECR_REF(inp
);
2620 SCTP_INP_WUNLOCK(inp
);
2628 /* simply copy out the sockaddr_storage... */
2629 memcpy(&ssp
->ssp_addr
,
2630 &stcb
->asoc
.primary_destination
->ro
._l_addr
,
2631 ((struct sockaddr
*)&stcb
->asoc
.primary_destination
->ro
._l_addr
)->sa_len
);
2632 SCTP_TCB_UNLOCK(stcb
);
2633 m
->m_len
= sizeof(*ssp
);
2637 error
= ENOPROTOOPT
;
2640 } /* end switch (sopt->sopt_name) */
2645 sctp_optsset(struct socket
*so
,
2648 #if (defined(__FreeBSD__) && __FreeBSD_version >= 500000) || defined(__DragonFly__)
2655 int error
, *mopt
, set_opt
;
2657 struct sctp_tcb
*stcb
= NULL
;
2658 struct sctp_inpcb
*inp
;
2662 if (sctp_debug_on
& SCTP_DEBUG_USRREQ1
) {
2663 kprintf("optsset:MP is NULL EINVAL\n");
2665 #endif /* SCTP_DEBUG */
2672 inp
= (struct sctp_inpcb
*)so
->so_pcb
;
2679 case SCTP_AUTOCLOSE
:
2680 case SCTP_AUTO_ASCONF
:
2681 case SCTP_DISABLE_FRAGMENTS
:
2682 case SCTP_I_WANT_MAPPED_V4_ADDR
:
2683 /* copy in the option value */
2684 if ((size_t)m
->m_len
< sizeof(int)) {
2688 mopt
= mtod(m
, int *);
2693 case SCTP_DISABLE_FRAGMENTS
:
2694 set_opt
= SCTP_PCB_FLAGS_NO_FRAGMENT
;
2696 case SCTP_AUTO_ASCONF
:
2697 set_opt
= SCTP_PCB_FLAGS_AUTO_ASCONF
;
2700 case SCTP_I_WANT_MAPPED_V4_ADDR
:
2701 if (inp
->sctp_flags
& SCTP_PCB_FLAGS_BOUND_V6
) {
2702 set_opt
= SCTP_PCB_FLAGS_NEEDS_MAPPED_V4
;
2708 set_opt
= SCTP_PCB_FLAGS_NODELAY
;
2710 case SCTP_AUTOCLOSE
:
2711 set_opt
= SCTP_PCB_FLAGS_AUTOCLOSE
;
2713 * The value is in ticks.
2714 * Note this does not effect old associations, only
2717 inp
->sctp_ep
.auto_close_time
= (*mopt
* hz
);
2720 SCTP_INP_WLOCK(inp
);
2722 inp
->sctp_flags
|= set_opt
;
2724 inp
->sctp_flags
&= ~set_opt
;
2726 SCTP_INP_WUNLOCK(inp
);
2728 case SCTP_MY_PUBLIC_KEY
: /* set my public key */
2729 case SCTP_SET_AUTH_CHUNKS
: /* set the authenticated chunks required */
2730 case SCTP_SET_AUTH_SECRET
: /* set the actual secret for the endpoint */
2731 /* not supported yet and until we refine the draft */
2735 case SCTP_CLR_STAT_LOG
:
2736 #ifdef SCTP_STAT_LOGGING
2737 sctp_clr_stat_log();
2742 case SCTP_DELAYED_ACK_TIME
:
2745 if ((size_t)m
->m_len
< sizeof(int32_t)) {
2749 tm
= mtod(m
, int32_t *);
2751 if ((*tm
< 10) || (*tm
> 500)) {
2752 /* can't be smaller than 10ms */
2753 /* MUST NOT be larger than 500ms */
2757 inp
->sctp_ep
.sctp_timeoutticks
[SCTP_TIMER_RECV
] = MSEC_TO_TICKS(*tm
);
2760 case SCTP_RESET_STREAMS
:
2762 struct sctp_stream_reset
*strrst
;
2763 uint8_t two_way
, not_peer
;
2765 if ((size_t)m
->m_len
< sizeof(struct sctp_stream_reset
)) {
2769 strrst
= mtod(m
, struct sctp_stream_reset
*);
2771 if (inp
->sctp_flags
& SCTP_PCB_FLAGS_CONNECTED
) {
2772 SCTP_INP_RLOCK(inp
);
2773 stcb
= LIST_FIRST(&inp
->sctp_asoc_list
);
2775 SCTP_TCB_LOCK(stcb
);
2776 SCTP_INP_RUNLOCK(inp
);
2778 stcb
= sctp_findassociation_ep_asocid(inp
, strrst
->strrst_assoc_id
);
2783 if (stcb
->asoc
.peer_supports_strreset
== 0) {
2784 /* Peer does not support it,
2785 * we return protocol not supported since
2786 * this is true for this feature and this
2787 * peer, not the socket request in general.
2789 error
= EPROTONOSUPPORT
;
2790 SCTP_TCB_UNLOCK(stcb
);
2794 /* Having re-thought this code I added as I write the I-D there
2795 * is NO need for it. The peer, if we are requesting a stream-reset
2796 * will send a request to us but will itself do what we do, take
2797 * and copy off the "reset information" we send and queue TSN's
2798 * larger than the send-next in our response message. Thus they
2801 /* if (stcb->asoc.sending_seq != (stcb->asoc.last_acked_seq + 1)) {*/
2802 /* Must have all sending data ack'd before we
2803 * start this procedure. This is a bit restrictive
2804 * and we SHOULD work on changing this so ONLY the
2805 * streams being RESET get held up. So, a reset-all
2806 * would require this.. but a reset specific just
2807 * needs to be sure that the ones being reset have
2808 * nothing on the send_queue. For now we will
2809 * skip this more detailed method and do a course
2810 * way.. i.e. nothing pending ... for future FIX ME!
2816 if (stcb
->asoc
.stream_reset_outstanding
) {
2818 SCTP_TCB_UNLOCK(stcb
);
2821 if (strrst
->strrst_flags
== SCTP_RESET_LOCAL_RECV
) {
2824 } else if (strrst
->strrst_flags
== SCTP_RESET_LOCAL_SEND
) {
2827 } else if (strrst
->strrst_flags
== SCTP_RESET_BOTH
) {
2832 SCTP_TCB_UNLOCK(stcb
);
2835 sctp_send_str_reset_req(stcb
, strrst
->strrst_num_streams
,
2836 strrst
->strrst_list
, two_way
, not_peer
);
2837 sctp_chunk_output(inp
, stcb
, 12);
2838 SCTP_TCB_UNLOCK(stcb
);
2842 case SCTP_RESET_PEGS
:
2843 memset(sctp_pegs
, 0, sizeof(sctp_pegs
));
2846 case SCTP_CONNECT_X
:
2847 if ((size_t)m
->m_len
< (sizeof(int) + sizeof(struct sockaddr_in
))) {
2851 error
= sctp_do_connect_x(so
, inp
, m
, p
, 0);
2854 case SCTP_CONNECT_X_DELAYED
:
2855 if ((size_t)m
->m_len
< (sizeof(int) + sizeof(struct sockaddr_in
))) {
2859 error
= sctp_do_connect_x(so
, inp
, m
, p
, 1);
2862 case SCTP_CONNECT_X_COMPLETE
:
2864 struct sockaddr
*sa
;
2865 struct sctp_nets
*net
;
2866 if ((size_t)m
->m_len
< sizeof(struct sockaddr_in
)) {
2870 sa
= mtod(m
, struct sockaddr
*);
2872 if (inp
->sctp_flags
& SCTP_PCB_FLAGS_CONNECTED
) {
2873 SCTP_INP_RLOCK(inp
);
2874 stcb
= LIST_FIRST(&inp
->sctp_asoc_list
);
2876 SCTP_TCB_LOCK(stcb
);
2877 net
= sctp_findnet(stcb
, sa
);
2879 SCTP_INP_RUNLOCK(inp
);
2881 SCTP_INP_WLOCK(inp
);
2882 SCTP_INP_INCR_REF(inp
);
2883 SCTP_INP_WUNLOCK(inp
);
2884 stcb
= sctp_findassociation_ep_addr(&inp
, sa
, &net
, NULL
, NULL
);
2886 SCTP_INP_WLOCK(inp
);
2887 SCTP_INP_DECR_REF(inp
);
2888 SCTP_INP_WUNLOCK(inp
);
2896 if (stcb
->asoc
.delayed_connection
== 1) {
2897 stcb
->asoc
.delayed_connection
= 0;
2898 SCTP_GETTIME_TIMEVAL(&stcb
->asoc
.time_entered
);
2899 sctp_timer_stop(SCTP_TIMER_TYPE_INIT
, inp
, stcb
, stcb
->asoc
.primary_destination
);
2900 sctp_send_initiate(inp
, stcb
);
2902 /* already expired or did not use delayed connectx */
2905 SCTP_TCB_UNLOCK(stcb
);
2911 SCTP_INP_WLOCK(inp
);
2912 burst
= mtod(m
, u_int8_t
*);
2914 inp
->sctp_ep
.max_burst
= *burst
;
2916 SCTP_INP_WUNLOCK(inp
);
2923 if (inp
->sctp_flags
& SCTP_PCB_FLAGS_BOUND_V6
) {
2924 ovh
= SCTP_MED_OVERHEAD
;
2926 ovh
= SCTP_MED_V4_OVERHEAD
;
2928 segsize
= mtod(m
, u_int32_t
*);
2933 SCTP_INP_WLOCK(inp
);
2934 inp
->sctp_frag_point
= (*segsize
+ovh
);
2935 if (inp
->sctp_frag_point
< MHLEN
) {
2936 inp
->sctp_frag_point
= MHLEN
;
2938 SCTP_INP_WUNLOCK(inp
);
2941 case SCTP_SET_DEBUG_LEVEL
:
2945 if ((size_t)m
->m_len
< sizeof(u_int32_t
)) {
2949 level
= mtod(m
, u_int32_t
*);
2951 sctp_debug_on
= (*level
& (SCTP_DEBUG_ALL
|
2953 kprintf("SETTING DEBUG LEVEL to %x\n",
2954 (u_int
)sctp_debug_on
);
2959 #endif /* SCTP_DEBUG */
2963 struct sctp_event_subscribe
*events
;
2964 if ((size_t)m
->m_len
< sizeof(struct sctp_event_subscribe
)) {
2968 SCTP_INP_WLOCK(inp
);
2969 events
= mtod(m
, struct sctp_event_subscribe
*);
2970 if (events
->sctp_data_io_event
) {
2971 inp
->sctp_flags
|= SCTP_PCB_FLAGS_RECVDATAIOEVNT
;
2973 inp
->sctp_flags
&= ~SCTP_PCB_FLAGS_RECVDATAIOEVNT
;
2976 if (events
->sctp_association_event
) {
2977 inp
->sctp_flags
|= SCTP_PCB_FLAGS_RECVASSOCEVNT
;
2979 inp
->sctp_flags
&= ~SCTP_PCB_FLAGS_RECVASSOCEVNT
;
2982 if (events
->sctp_address_event
) {
2983 inp
->sctp_flags
|= SCTP_PCB_FLAGS_RECVPADDREVNT
;
2985 inp
->sctp_flags
&= ~SCTP_PCB_FLAGS_RECVPADDREVNT
;
2988 if (events
->sctp_send_failure_event
) {
2989 inp
->sctp_flags
|= SCTP_PCB_FLAGS_RECVSENDFAILEVNT
;
2991 inp
->sctp_flags
&= ~SCTP_PCB_FLAGS_RECVSENDFAILEVNT
;
2994 if (events
->sctp_peer_error_event
) {
2995 inp
->sctp_flags
|= SCTP_PCB_FLAGS_RECVPEERERR
;
2997 inp
->sctp_flags
&= ~SCTP_PCB_FLAGS_RECVPEERERR
;
3000 if (events
->sctp_shutdown_event
) {
3001 inp
->sctp_flags
|= SCTP_PCB_FLAGS_RECVSHUTDOWNEVNT
;
3003 inp
->sctp_flags
&= ~SCTP_PCB_FLAGS_RECVSHUTDOWNEVNT
;
3006 if (events
->sctp_partial_delivery_event
) {
3007 inp
->sctp_flags
|= SCTP_PCB_FLAGS_PDAPIEVNT
;
3009 inp
->sctp_flags
&= ~SCTP_PCB_FLAGS_PDAPIEVNT
;
3012 if (events
->sctp_adaption_layer_event
) {
3013 inp
->sctp_flags
|= SCTP_PCB_FLAGS_ADAPTIONEVNT
;
3015 inp
->sctp_flags
&= ~SCTP_PCB_FLAGS_ADAPTIONEVNT
;
3018 if (events
->sctp_stream_reset_events
) {
3019 inp
->sctp_flags
|= SCTP_PCB_FLAGS_STREAM_RESETEVNT
;
3021 inp
->sctp_flags
&= ~SCTP_PCB_FLAGS_STREAM_RESETEVNT
;
3023 SCTP_INP_WUNLOCK(inp
);
3027 case SCTP_ADAPTION_LAYER
:
3029 struct sctp_setadaption
*adap_bits
;
3030 if ((size_t)m
->m_len
< sizeof(struct sctp_setadaption
)) {
3034 SCTP_INP_WLOCK(inp
);
3035 adap_bits
= mtod(m
, struct sctp_setadaption
*);
3036 inp
->sctp_ep
.adaption_layer_indicator
= adap_bits
->ssb_adaption_ind
;
3037 SCTP_INP_WUNLOCK(inp
);
3040 case SCTP_SET_INITIAL_DBG_SEQ
:
3043 if ((size_t)m
->m_len
< sizeof(u_int32_t
)) {
3047 SCTP_INP_WLOCK(inp
);
3048 vvv
= mtod(m
, u_int32_t
*);
3049 inp
->sctp_ep
.initial_sequence_debug
= *vvv
;
3050 SCTP_INP_WUNLOCK(inp
);
3053 case SCTP_DEFAULT_SEND_PARAM
:
3055 struct sctp_sndrcvinfo
*s_info
;
3057 if (m
->m_len
!= sizeof(struct sctp_sndrcvinfo
)) {
3061 s_info
= mtod(m
, struct sctp_sndrcvinfo
*);
3063 if (inp
->sctp_flags
& SCTP_PCB_FLAGS_CONNECTED
) {
3064 SCTP_INP_RLOCK(inp
);
3065 stcb
= LIST_FIRST(&inp
->sctp_asoc_list
);
3067 SCTP_TCB_LOCK(stcb
);
3068 SCTP_INP_RUNLOCK(inp
);
3070 stcb
= sctp_findassociation_ep_asocid(inp
, s_info
->sinfo_assoc_id
);
3076 /* Validate things */
3077 if (s_info
->sinfo_stream
> stcb
->asoc
.streamoutcnt
) {
3078 SCTP_TCB_UNLOCK(stcb
);
3082 /* Mask off the flags that are allowed */
3083 s_info
->sinfo_flags
= (s_info
->sinfo_flags
&
3084 (MSG_UNORDERED
| MSG_ADDR_OVER
|
3085 MSG_PR_SCTP_TTL
| MSG_PR_SCTP_BUF
));
3087 stcb
->asoc
.def_send
= *s_info
;
3088 SCTP_TCB_UNLOCK(stcb
);
3091 case SCTP_PEER_ADDR_PARAMS
:
3093 struct sctp_paddrparams
*paddrp
;
3094 struct sctp_nets
*net
;
3095 if ((size_t)m
->m_len
< sizeof(struct sctp_paddrparams
)) {
3099 paddrp
= mtod(m
, struct sctp_paddrparams
*);
3101 if (paddrp
->spp_assoc_id
) {
3102 if (inp
->sctp_flags
& SCTP_PCB_FLAGS_CONNECTED
) {
3103 SCTP_INP_RLOCK(inp
);
3104 stcb
= LIST_FIRST(&inp
->sctp_asoc_list
);
3106 SCTP_TCB_LOCK(stcb
);
3107 net
= sctp_findnet(stcb
, (struct sockaddr
*)&paddrp
->spp_address
);
3109 SCTP_INP_RUNLOCK(inp
);
3111 stcb
= sctp_findassociation_ep_asocid(inp
, paddrp
->spp_assoc_id
);
3118 if ((stcb
== NULL
) &&
3119 ((((struct sockaddr
*)&paddrp
->spp_address
)->sa_family
== AF_INET
) ||
3120 (((struct sockaddr
*)&paddrp
->spp_address
)->sa_family
== AF_INET6
))) {
3121 /* Lookup via address */
3122 if (inp
->sctp_flags
& SCTP_PCB_FLAGS_CONNECTED
) {
3123 SCTP_INP_RLOCK(inp
);
3124 stcb
= LIST_FIRST(&inp
->sctp_asoc_list
);
3126 SCTP_TCB_LOCK(stcb
);
3127 net
= sctp_findnet(stcb
,
3128 (struct sockaddr
*)&paddrp
->spp_address
);
3130 SCTP_INP_RUNLOCK(inp
);
3132 SCTP_INP_WLOCK(inp
);
3133 SCTP_INP_INCR_REF(inp
);
3134 SCTP_INP_WUNLOCK(inp
);
3135 stcb
= sctp_findassociation_ep_addr(&inp
,
3136 (struct sockaddr
*)&paddrp
->spp_address
,
3139 SCTP_INP_WLOCK(inp
);
3140 SCTP_INP_DECR_REF(inp
);
3141 SCTP_INP_WUNLOCK(inp
);
3145 /* Effects the Endpoint */
3149 /* Applies to the specific association */
3150 if (paddrp
->spp_pathmaxrxt
) {
3152 if (paddrp
->spp_pathmaxrxt
)
3153 net
->failure_threshold
= paddrp
->spp_pathmaxrxt
;
3155 if (paddrp
->spp_pathmaxrxt
)
3156 stcb
->asoc
.def_net_failure
= paddrp
->spp_pathmaxrxt
;
3159 if ((paddrp
->spp_hbinterval
!= 0) && (paddrp
->spp_hbinterval
!= 0xffffffff)) {
3163 net
->dest_state
&= ~SCTP_ADDR_NOHB
;
3165 old
= stcb
->asoc
.heart_beat_delay
;
3166 stcb
->asoc
.heart_beat_delay
= paddrp
->spp_hbinterval
;
3168 /* Turn back on the timer */
3169 sctp_timer_start(SCTP_TIMER_TYPE_HEARTBEAT
, inp
, stcb
, net
);
3172 } else if (paddrp
->spp_hbinterval
== 0xffffffff) {
3174 sctp_send_hb(stcb
, 1, net
);
3177 /* off on association */
3178 if (stcb
->asoc
.heart_beat_delay
) {
3179 int cnt_of_unconf
= 0;
3180 struct sctp_nets
*lnet
;
3181 TAILQ_FOREACH(lnet
, &stcb
->asoc
.nets
, sctp_next
) {
3182 if (lnet
->dest_state
& SCTP_ADDR_UNCONFIRMED
) {
3186 /* stop the timer ONLY if we have no unconfirmed addresses
3188 if (cnt_of_unconf
== 0)
3189 sctp_timer_stop(SCTP_TIMER_TYPE_HEARTBEAT
, inp
, stcb
, net
);
3191 stcb
->asoc
.heart_beat_delay
= 0;
3193 net
->dest_state
|= SCTP_ADDR_NOHB
;
3196 SCTP_TCB_UNLOCK(stcb
);
3198 /* Use endpoint defaults */
3199 SCTP_INP_WLOCK(inp
);
3200 if (paddrp
->spp_pathmaxrxt
)
3201 inp
->sctp_ep
.def_net_failure
= paddrp
->spp_pathmaxrxt
;
3202 if (paddrp
->spp_hbinterval
!= SCTP_ISSUE_HB
)
3203 inp
->sctp_ep
.sctp_timeoutticks
[SCTP_TIMER_HEARTBEAT
] = paddrp
->spp_hbinterval
;
3204 SCTP_INP_WUNLOCK(inp
);
3210 struct sctp_rtoinfo
*srto
;
3211 if ((size_t)m
->m_len
< sizeof(struct sctp_rtoinfo
)) {
3215 srto
= mtod(m
, struct sctp_rtoinfo
*);
3216 if (srto
->srto_assoc_id
== 0) {
3217 SCTP_INP_WLOCK(inp
);
3218 /* If we have a null asoc, its default for the endpoint */
3219 if (srto
->srto_initial
> 10)
3220 inp
->sctp_ep
.initial_rto
= srto
->srto_initial
;
3221 if (srto
->srto_max
> 10)
3222 inp
->sctp_ep
.sctp_maxrto
= srto
->srto_max
;
3223 if (srto
->srto_min
> 10)
3224 inp
->sctp_ep
.sctp_minrto
= srto
->srto_min
;
3225 SCTP_INP_WUNLOCK(inp
);
3228 if (inp
->sctp_flags
& SCTP_PCB_FLAGS_CONNECTED
) {
3229 SCTP_INP_RLOCK(inp
);
3230 stcb
= LIST_FIRST(&inp
->sctp_asoc_list
);
3232 SCTP_TCB_LOCK(stcb
);
3233 SCTP_INP_RUNLOCK(inp
);
3235 stcb
= sctp_findassociation_ep_asocid(inp
, srto
->srto_assoc_id
);
3240 /* Set in ms we hope :-) */
3241 if (srto
->srto_initial
> 10)
3242 stcb
->asoc
.initial_rto
= srto
->srto_initial
;
3243 if (srto
->srto_max
> 10)
3244 stcb
->asoc
.maxrto
= srto
->srto_max
;
3245 if (srto
->srto_min
> 10)
3246 stcb
->asoc
.minrto
= srto
->srto_min
;
3247 SCTP_TCB_UNLOCK(stcb
);
3250 case SCTP_ASSOCINFO
:
3252 struct sctp_assocparams
*sasoc
;
3254 if ((size_t)m
->m_len
< sizeof(struct sctp_assocparams
)) {
3258 sasoc
= mtod(m
, struct sctp_assocparams
*);
3259 if (sasoc
->sasoc_assoc_id
) {
3260 if (inp
->sctp_flags
& SCTP_PCB_FLAGS_CONNECTED
) {
3261 SCTP_INP_RLOCK(inp
);
3262 stcb
= LIST_FIRST(&inp
->sctp_asoc_list
);
3264 SCTP_TCB_LOCK(stcb
);
3265 SCTP_INP_RUNLOCK(inp
);
3267 stcb
= sctp_findassociation_ep_asocid(inp
,
3268 sasoc
->sasoc_assoc_id
);
3278 if (sasoc
->sasoc_asocmaxrxt
)
3279 stcb
->asoc
.max_send_times
= sasoc
->sasoc_asocmaxrxt
;
3280 sasoc
->sasoc_number_peer_destinations
= stcb
->asoc
.numnets
;
3281 sasoc
->sasoc_peer_rwnd
= 0;
3282 sasoc
->sasoc_local_rwnd
= 0;
3283 if (stcb
->asoc
.cookie_life
)
3284 stcb
->asoc
.cookie_life
= sasoc
->sasoc_cookie_life
;
3285 SCTP_TCB_UNLOCK(stcb
);
3287 SCTP_INP_WLOCK(inp
);
3288 if (sasoc
->sasoc_asocmaxrxt
)
3289 inp
->sctp_ep
.max_send_times
= sasoc
->sasoc_asocmaxrxt
;
3290 sasoc
->sasoc_number_peer_destinations
= 0;
3291 sasoc
->sasoc_peer_rwnd
= 0;
3292 sasoc
->sasoc_local_rwnd
= 0;
3293 if (sasoc
->sasoc_cookie_life
)
3294 inp
->sctp_ep
.def_cookie_life
= sasoc
->sasoc_cookie_life
;
3295 SCTP_INP_WUNLOCK(inp
);
3301 struct sctp_initmsg
*sinit
;
3303 if ((size_t)m
->m_len
< sizeof(struct sctp_initmsg
)) {
3307 sinit
= mtod(m
, struct sctp_initmsg
*);
3308 SCTP_INP_WLOCK(inp
);
3309 if (sinit
->sinit_num_ostreams
)
3310 inp
->sctp_ep
.pre_open_stream_count
= sinit
->sinit_num_ostreams
;
3312 if (sinit
->sinit_max_instreams
)
3313 inp
->sctp_ep
.max_open_streams_intome
= sinit
->sinit_max_instreams
;
3315 if (sinit
->sinit_max_attempts
)
3316 inp
->sctp_ep
.max_init_times
= sinit
->sinit_max_attempts
;
3318 if (sinit
->sinit_max_init_timeo
> 10)
3319 /* We must be at least a 100ms (we set in ticks) */
3320 inp
->sctp_ep
.initial_init_rto_max
= sinit
->sinit_max_init_timeo
;
3321 SCTP_INP_WUNLOCK(inp
);
3324 case SCTP_PRIMARY_ADDR
:
3326 struct sctp_setprim
*spa
;
3327 struct sctp_nets
*net
, *lnet
;
3328 if ((size_t)m
->m_len
< sizeof(struct sctp_setprim
)) {
3332 spa
= mtod(m
, struct sctp_setprim
*);
3334 if (inp
->sctp_flags
& SCTP_PCB_FLAGS_CONNECTED
) {
3335 SCTP_INP_RLOCK(inp
);
3336 stcb
= LIST_FIRST(&inp
->sctp_asoc_list
);
3338 SCTP_TCB_LOCK(stcb
);
3343 SCTP_INP_RUNLOCK(inp
);
3345 stcb
= sctp_findassociation_ep_asocid(inp
, spa
->ssp_assoc_id
);
3348 SCTP_INP_WLOCK(inp
);
3349 SCTP_INP_INCR_REF(inp
);
3350 SCTP_INP_WUNLOCK(inp
);
3351 stcb
= sctp_findassociation_ep_addr(&inp
,
3352 (struct sockaddr
*)&spa
->ssp_addr
,
3355 SCTP_INP_WLOCK(inp
);
3356 SCTP_INP_DECR_REF(inp
);
3357 SCTP_INP_WUNLOCK(inp
);
3362 /* find the net, associd or connected lookup type */
3363 net
= sctp_findnet(stcb
, (struct sockaddr
*)&spa
->ssp_addr
);
3365 SCTP_TCB_UNLOCK(stcb
);
3370 if ((net
!= stcb
->asoc
.primary_destination
) &&
3371 (!(net
->dest_state
& SCTP_ADDR_UNCONFIRMED
))) {
3372 /* Ok we need to set it */
3373 lnet
= stcb
->asoc
.primary_destination
;
3374 lnet
->next_tsn_at_change
= net
->next_tsn_at_change
= stcb
->asoc
.sending_seq
;
3375 if (sctp_set_primary_addr(stcb
,
3378 if (net
->dest_state
& SCTP_ADDR_SWITCH_PRIMARY
) {
3379 net
->dest_state
|= SCTP_ADDR_DOUBLE_SWITCH
;
3381 net
->dest_state
|= SCTP_ADDR_SWITCH_PRIMARY
;
3384 SCTP_TCB_UNLOCK(stcb
);
3388 case SCTP_SET_PEER_PRIMARY_ADDR
:
3390 struct sctp_setpeerprim
*sspp
;
3391 if ((size_t)m
->m_len
< sizeof(struct sctp_setpeerprim
)) {
3395 sspp
= mtod(m
, struct sctp_setpeerprim
*);
3398 if (inp
->sctp_flags
& SCTP_PCB_FLAGS_CONNECTED
) {
3399 SCTP_INP_RLOCK(inp
);
3400 stcb
= LIST_FIRST(&inp
->sctp_asoc_list
);
3402 SCTP_TCB_UNLOCK(stcb
);
3403 SCTP_INP_RUNLOCK(inp
);
3405 stcb
= sctp_findassociation_ep_asocid(inp
, sspp
->sspp_assoc_id
);
3410 if (sctp_set_primary_ip_address_sa(stcb
, (struct sockaddr
*)&sspp
->sspp_addr
) != 0) {
3413 SCTP_TCB_UNLOCK(stcb
);
3416 case SCTP_BINDX_ADD_ADDR
:
3418 struct sctp_getaddresses
*addrs
;
3419 struct sockaddr
*addr_touse
;
3420 struct sockaddr_in sin
;
3421 /* see if we're bound all already! */
3422 if (inp
->sctp_flags
& SCTP_PCB_FLAGS_BOUNDALL
) {
3426 if ((size_t)m
->m_len
< sizeof(struct sctp_getaddresses
)) {
3430 addrs
= mtod(m
, struct sctp_getaddresses
*);
3431 addr_touse
= addrs
->addr
;
3432 if (addrs
->addr
->sa_family
== AF_INET6
) {
3433 struct sockaddr_in6
*sin6
;
3434 sin6
= (struct sockaddr_in6
*)addr_touse
;
3435 if (IN6_IS_ADDR_V4MAPPED(&sin6
->sin6_addr
)) {
3436 in6_sin6_2_sin(&sin
, sin6
);
3437 addr_touse
= (struct sockaddr
*)&sin
;
3440 if (inp
->sctp_flags
& SCTP_PCB_FLAGS_UNBOUND
) {
3442 /* Can't get proc for Net/Open BSD */
3446 error
= sctp_inpcb_bind(so
, addr_touse
, p
);
3449 /* No locks required here since bind and mgmt_ep_sa all
3450 * do their own locking. If we do something for the FIX:
3451 * below we may need to lock in that case.
3453 if (addrs
->sget_assoc_id
== 0) {
3454 /* add the address */
3455 struct sctp_inpcb
*lep
;
3456 ((struct sockaddr_in
*)addr_touse
)->sin_port
= inp
->sctp_lport
;
3457 lep
= sctp_pcb_findep(addr_touse
, 1, 0);
3459 /* We must decrement the refcount
3460 * since we have the ep already and
3461 * are binding. No remove going on
3464 SCTP_INP_WLOCK(inp
);
3465 SCTP_INP_DECR_REF(inp
);
3466 SCTP_INP_WUNLOCK(inp
);
3469 /* already bound to it.. ok */
3471 } else if (lep
== NULL
) {
3472 ((struct sockaddr_in
*)addr_touse
)->sin_port
= 0;
3473 error
= sctp_addr_mgmt_ep_sa(inp
, addr_touse
,
3474 SCTP_ADD_IP_ADDRESS
);
3476 error
= EADDRNOTAVAIL
;
3482 /* FIX: decide whether we allow assoc based bindx */
3486 case SCTP_BINDX_REM_ADDR
:
3488 struct sctp_getaddresses
*addrs
;
3489 struct sockaddr
*addr_touse
;
3490 struct sockaddr_in sin
;
3491 /* see if we're bound all already! */
3492 if (inp
->sctp_flags
& SCTP_PCB_FLAGS_BOUNDALL
) {
3496 if ((size_t)m
->m_len
< sizeof(struct sctp_getaddresses
)) {
3500 addrs
= mtod(m
, struct sctp_getaddresses
*);
3501 addr_touse
= addrs
->addr
;
3502 if (addrs
->addr
->sa_family
== AF_INET6
) {
3503 struct sockaddr_in6
*sin6
;
3504 sin6
= (struct sockaddr_in6
*)addr_touse
;
3505 if (IN6_IS_ADDR_V4MAPPED(&sin6
->sin6_addr
)) {
3506 in6_sin6_2_sin(&sin
, sin6
);
3507 addr_touse
= (struct sockaddr
*)&sin
;
3510 /* No lock required mgmt_ep_sa does its own locking. If
3511 * the FIX: below is ever changed we may need to
3512 * lock before calling association level binding.
3514 if (addrs
->sget_assoc_id
== 0) {
3515 /* delete the address */
3516 sctp_addr_mgmt_ep_sa(inp
, addr_touse
,
3517 SCTP_DEL_IP_ADDRESS
);
3519 /* FIX: decide whether we allow assoc based bindx */
3524 error
= ENOPROTOOPT
;
3526 } /* end switch (opt) */
3531 sctp_ctloutput(netmsg_t msg
)
3533 struct socket
*so
= msg
->ctloutput
.base
.nm_so
;
3534 struct sockopt
*sopt
= msg
->ctloutput
.nm_sopt
;
3535 struct mbuf
*m
= NULL
;
3536 struct sctp_inpcb
*inp
;
3539 inp
= (struct sctp_inpcb
*)so
->so_pcb
;
3542 /* I made the same as TCP since we are not setup? */
3546 if (sopt
->sopt_level
!= IPPROTO_SCTP
) {
3547 /* wrong proto level... send back up to IP */
3549 if (INP_CHECK_SOCKAF(so
, AF_INET6
))
3550 ip6_ctloutput_dispatch(msg
);
3554 /* msg invalid now */
3557 if (sopt
->sopt_valsize
> MCLBYTES
) {
3559 * Restrict us down to a cluster size, that's all we can
3560 * pass either way...
3562 sopt
->sopt_valsize
= MCLBYTES
;
3564 if (sopt
->sopt_valsize
) {
3566 m
= m_get(MB_WAIT
, MT_DATA
);
3567 if (sopt
->sopt_valsize
> MLEN
) {
3568 MCLGET(m
, MB_DONTWAIT
);
3569 if ((m
->m_flags
& M_EXT
) == 0) {
3575 error
= sooptcopyin(sopt
, mtod(m
, caddr_t
), sopt
->sopt_valsize
,
3576 sopt
->sopt_valsize
);
3581 m
->m_len
= sopt
->sopt_valsize
;
3583 if (sopt
->sopt_dir
== SOPT_SET
) {
3584 #if (defined(__FreeBSD__) && __FreeBSD_version >= 500000) || defined(__DragonFly__)
3585 error
= sctp_optsset(so
, sopt
->sopt_name
, &m
, sopt
->sopt_td
);
3587 error
= sctp_optsset(so
, sopt
->sopt_name
, &m
, sopt
->sopt_p
);
3589 } else if (sopt
->sopt_dir
== SOPT_GET
) {
3590 #if (defined (__FreeBSD__) && __FreeBSD_version >= 500000) || defined(__DragonFly__)
3591 error
= sctp_optsget(so
, sopt
->sopt_name
, &m
, sopt
->sopt_td
);
3593 error
= sctp_optsget(so
, sopt
->sopt_name
, &m
, sopt
->sopt_p
);
3598 if ( (error
== 0) && (m
!= NULL
)) {
3599 error
= sooptcopyout(sopt
, mtod(m
, caddr_t
), m
->m_len
);
3601 } else if (m
!= NULL
) {
3605 lwkt_replymsg(&msg
->lmsg
, error
);
3609 sctp_connect(netmsg_t msg
)
3611 struct socket
*so
= msg
->connect
.base
.nm_so
;
3612 struct sockaddr
*addr
= msg
->connect
.nm_nam
;
3613 struct sctp_inpcb
*inp
;
3614 struct sctp_tcb
*stcb
;
3618 if (sctp_debug_on
& SCTP_DEBUG_PCB1
) {
3619 kprintf("Connect called in SCTP to ");
3620 sctp_print_address(addr
);
3621 kprintf("Port %d\n", ntohs(((struct sockaddr_in
*)addr
)->sin_port
));
3623 #endif /* SCTP_DEBUG */
3624 inp
= (struct sctp_inpcb
*)so
->so_pcb
;
3626 /* I made the same as TCP since we are not setup? */
3630 SCTP_ASOC_CREATE_LOCK(inp
);
3631 SCTP_INP_WLOCK(inp
);
3632 if ((inp
->sctp_flags
& SCTP_PCB_FLAGS_SOCKET_GONE
) ||
3633 (inp
->sctp_flags
& SCTP_PCB_FLAGS_SOCKET_GONE
)) {
3634 /* Should I really unlock ? */
3635 SCTP_INP_WUNLOCK(inp
);
3636 SCTP_ASOC_CREATE_UNLOCK(inp
);
3641 if (((inp
->sctp_flags
& SCTP_PCB_FLAGS_BOUND_V6
) == 0) &&
3642 (addr
->sa_family
== AF_INET6
)) {
3643 SCTP_INP_WUNLOCK(inp
);
3644 SCTP_ASOC_CREATE_UNLOCK(inp
);
3649 if ((inp
->sctp_flags
& SCTP_PCB_FLAGS_UNBOUND
) ==
3650 SCTP_PCB_FLAGS_UNBOUND
) {
3651 /* Bind a ephemeral port */
3652 SCTP_INP_WUNLOCK(inp
);
3653 error
= sctp_inpcb_bind(so
, NULL
, msg
->connect
.nm_td
);
3655 SCTP_ASOC_CREATE_UNLOCK(inp
);
3658 SCTP_INP_WLOCK(inp
);
3660 /* Now do we connect? */
3661 if ((inp
->sctp_flags
& SCTP_PCB_FLAGS_TCPTYPE
) &&
3662 (inp
->sctp_flags
& SCTP_PCB_FLAGS_CONNECTED
)) {
3663 /* We are already connected AND the TCP model */
3664 SCTP_INP_WUNLOCK(inp
);
3665 SCTP_ASOC_CREATE_UNLOCK(inp
);
3669 if (inp
->sctp_flags
& SCTP_PCB_FLAGS_CONNECTED
) {
3670 stcb
= LIST_FIRST(&inp
->sctp_asoc_list
);
3672 SCTP_TCB_UNLOCK(stcb
);
3673 SCTP_INP_WUNLOCK(inp
);
3675 SCTP_INP_INCR_REF(inp
);
3676 SCTP_INP_WUNLOCK(inp
);
3677 stcb
= sctp_findassociation_ep_addr(&inp
, addr
, NULL
, NULL
, NULL
);
3679 SCTP_INP_WLOCK(inp
);
3680 SCTP_INP_DECR_REF(inp
);
3681 SCTP_INP_WUNLOCK(inp
);
3685 /* Already have or am bring up an association */
3686 SCTP_ASOC_CREATE_UNLOCK(inp
);
3687 SCTP_TCB_UNLOCK(stcb
);
3691 /* We are GOOD to go */
3692 stcb
= sctp_aloc_assoc(inp
, addr
, 1, &error
, 0);
3694 /* Gak! no memory */
3697 if (stcb
->sctp_ep
->sctp_flags
& SCTP_PCB_FLAGS_TCPTYPE
) {
3698 stcb
->sctp_ep
->sctp_flags
|= SCTP_PCB_FLAGS_CONNECTED
;
3699 /* Set the connected flag so we can queue data */
3702 stcb
->asoc
.state
= SCTP_STATE_COOKIE_WAIT
;
3703 SCTP_GETTIME_TIMEVAL(&stcb
->asoc
.time_entered
);
3704 sctp_send_initiate(inp
, stcb
);
3705 SCTP_ASOC_CREATE_UNLOCK(inp
);
3706 SCTP_TCB_UNLOCK(stcb
);
3708 lwkt_replymsg(&msg
->lmsg
, error
);
3712 sctp_usr_recvd(netmsg_t msg
)
3714 struct socket
*so
= msg
->rcvd
.base
.nm_so
;
3715 struct sctp_socket_q_list
*sq
= NULL
;
3716 int flags
= msg
->rcvd
.nm_flags
;
3720 * The user has received some data, we may be able to stuff more
3721 * up the socket. And we need to possibly update the rwnd.
3723 struct sctp_inpcb
*inp
;
3724 struct sctp_tcb
*stcb
=NULL
;
3726 inp
= (struct sctp_inpcb
*)so
->so_pcb
;
3728 if (sctp_debug_on
& SCTP_DEBUG_USRREQ2
)
3729 kprintf("Read for so:%p inp:%p Flags:%x\n",
3730 so
, inp
, (u_int
)flags
);
3734 /* I made the same as TCP since we are not setup? */
3736 if (sctp_debug_on
& SCTP_DEBUG_USRREQ2
)
3737 kprintf("Nope, connection reset\n");
3743 * Grab the first one on the list. It will re-insert itself if
3744 * it runs out of room
3746 SCTP_INP_WLOCK(inp
);
3747 if ((flags
& MSG_EOR
) && ((inp
->sctp_flags
& SCTP_PCB_FLAGS_IN_TCPPOOL
) == 0)
3748 && ((inp
->sctp_flags
& SCTP_PCB_FLAGS_CONNECTED
) == 0)) {
3749 /* Ok the other part of our grubby tracking
3750 * stuff for our horrible layer violation that
3751 * the tsvwg thinks is ok for sctp_peeloff.. gak!
3752 * We must update the next vtag pending on the
3753 * socket buffer (if any).
3755 inp
->sctp_vtag_first
= sctp_get_first_vtag_from_sb(so
);
3756 sq
= TAILQ_FIRST(&inp
->sctp_queue_list
);
3763 stcb
= LIST_FIRST(&inp
->sctp_asoc_list
);
3766 SCTP_TCB_LOCK(stcb
);
3769 /* all code in normal stcb path assumes
3770 * that you have a tcb_lock only. Thus
3771 * we must release the inp write lock.
3773 if (flags
& MSG_EOR
) {
3774 if (((inp
->sctp_flags
& SCTP_PCB_FLAGS_IN_TCPPOOL
) == 0)
3775 && ((inp
->sctp_flags
& SCTP_PCB_FLAGS_CONNECTED
) == 0)) {
3776 stcb
= sctp_remove_from_socket_q(inp
);
3779 if (sctp_debug_on
& SCTP_DEBUG_USRREQ2
)
3780 kprintf("remove from socket queue for inp:%p tcbret:%p\n",
3784 stcb
->asoc
.my_rwnd_control_len
= sctp_sbspace_sub(stcb
->asoc
.my_rwnd_control_len
,
3785 sizeof(struct mbuf
));
3786 if (inp
->sctp_flags
& SCTP_PCB_FLAGS_RECVDATAIOEVNT
) {
3787 stcb
->asoc
.my_rwnd_control_len
= sctp_sbspace_sub(stcb
->asoc
.my_rwnd_control_len
,
3788 CMSG_LEN(sizeof(struct sctp_sndrcvinfo
)));
3791 if ((TAILQ_EMPTY(&stcb
->asoc
.delivery_queue
) == 0) ||
3792 (TAILQ_EMPTY(&stcb
->asoc
.reasmqueue
) == 0)) {
3793 /* Deliver if there is something to be delivered */
3794 sctp_service_queues(stcb
, &stcb
->asoc
, 1);
3796 sctp_set_rwnd(stcb
, &stcb
->asoc
);
3797 /* if we increase by 1 or more MTU's (smallest MTUs of all
3798 * nets) we send a window update sack
3800 incr
= stcb
->asoc
.my_rwnd
- stcb
->asoc
.my_last_reported_rwnd
;
3804 if (((uint32_t)incr
>= (stcb
->asoc
.smallest_mtu
* SCTP_SEG_TO_RWND_UPD
)) ||
3805 ((((uint32_t)incr
)*SCTP_SCALE_OF_RWND_TO_UPD
) >= so
->so_rcv
.ssb_hiwat
)) {
3806 if (callout_pending(&stcb
->asoc
.dack_timer
.timer
)) {
3807 /* If the timer is up, stop it */
3808 sctp_timer_stop(SCTP_TIMER_TYPE_RECV
,
3809 stcb
->sctp_ep
, stcb
, NULL
);
3811 /* Send the sack, with the new rwnd */
3812 sctp_send_sack(stcb
);
3813 /* Now do the output */
3814 sctp_chunk_output(inp
, stcb
, 10);
3817 if ((( sq
) && (flags
& MSG_EOR
) && ((inp
->sctp_flags
& SCTP_PCB_FLAGS_IN_TCPPOOL
) == 0))
3818 && ((inp
->sctp_flags
& SCTP_PCB_FLAGS_CONNECTED
) == 0)) {
3819 stcb
= sctp_remove_from_socket_q(inp
);
3822 SOCKBUF_LOCK(&so
->so_rcv
);
3823 if (( so
->so_rcv
.ssb_mb
== NULL
) &&
3824 (TAILQ_EMPTY(&inp
->sctp_queue_list
) == 0)) {
3827 if (sctp_debug_on
& SCTP_DEBUG_USRREQ2
)
3828 kprintf("Something off, inp:%p so->so_rcv->ssb_mb is empty and sockq is not.. cleaning\n",
3831 if (((inp
->sctp_flags
& SCTP_PCB_FLAGS_IN_TCPPOOL
) == 0)
3832 && ((inp
->sctp_flags
& SCTP_PCB_FLAGS_CONNECTED
) == 0)) {
3834 done_yet
= TAILQ_EMPTY(&inp
->sctp_queue_list
);
3837 sctp_remove_from_socket_q(inp
);
3838 done_yet
= TAILQ_EMPTY(&inp
->sctp_queue_list
);
3842 if (sctp_debug_on
& SCTP_DEBUG_USRREQ2
)
3843 kprintf("Cleaned up %d sockq's\n", sq_cnt
);
3846 SOCKBUF_UNLOCK(&so
->so_rcv
);
3848 SCTP_TCB_UNLOCK(stcb
);
3849 SCTP_INP_WUNLOCK(inp
);
3852 lwkt_replymsg(&msg
->lmsg
, error
);
3856 sctp_listen(netmsg_t msg
)
3858 struct socket
*so
= msg
->listen
.base
.nm_so
;
3862 * Note this module depends on the protocol processing being
3863 * called AFTER any socket level flags and backlog are applied
3864 * to the socket. The traditional way that the socket flags are
3865 * applied is AFTER protocol processing. We have made a change
3866 * to the sys/kern/uipc_socket.c module to reverse this but this
3867 * MUST be in place if the socket API for SCTP is to work properly.
3869 struct sctp_inpcb
*inp
;
3871 inp
= (struct sctp_inpcb
*)so
->so_pcb
;
3873 /* I made the same as TCP since we are not setup? */
3877 SCTP_INP_RLOCK(inp
);
3878 if ((inp
->sctp_flags
& SCTP_PCB_FLAGS_TCPTYPE
) &&
3879 (inp
->sctp_flags
& SCTP_PCB_FLAGS_CONNECTED
)) {
3880 /* We are already connected AND the TCP model */
3881 SCTP_INP_RUNLOCK(inp
);
3885 if (inp
->sctp_flags
& SCTP_PCB_FLAGS_UNBOUND
) {
3886 /* We must do a bind. */
3887 SCTP_INP_RUNLOCK(inp
);
3888 if ((error
= sctp_inpcb_bind(so
, NULL
, msg
->listen
.nm_td
))) {
3889 /* bind error, probably perm */
3893 SCTP_INP_RUNLOCK(inp
);
3896 SCTP_INP_WLOCK(inp
);
3897 if (inp
->sctp_socket
->so_qlimit
) {
3898 if (inp
->sctp_flags
& SCTP_PCB_FLAGS_UDPTYPE
) {
3900 * For the UDP model we must TURN OFF the ACCEPT
3901 * flags since we do NOT allow the accept() call.
3902 * The TCP model (when present) will do accept which
3903 * then prohibits connect().
3905 inp
->sctp_socket
->so_options
&= ~SO_ACCEPTCONN
;
3907 inp
->sctp_flags
|= SCTP_PCB_FLAGS_ACCEPTING
;
3909 if (inp
->sctp_flags
& SCTP_PCB_FLAGS_ACCEPTING
) {
3911 * Turning off the listen flags if the backlog is
3912 * set to 0 (i.e. qlimit is 0).
3914 inp
->sctp_flags
&= ~SCTP_PCB_FLAGS_ACCEPTING
;
3916 inp
->sctp_socket
->so_options
&= ~SO_ACCEPTCONN
;
3918 SCTP_INP_WUNLOCK(inp
);
3922 lwkt_replymsg(&msg
->lmsg
, error
);
3926 sctp_accept(netmsg_t msg
)
3928 struct socket
*so
= msg
->accept
.base
.nm_so
;
3929 struct sockaddr
**addr
= msg
->accept
.nm_nam
;
3930 struct sctp_tcb
*stcb
;
3931 struct sockaddr
*prim
;
3932 struct sctp_inpcb
*inp
;
3935 inp
= (struct sctp_inpcb
*)so
->so_pcb
;
3941 SCTP_INP_RLOCK(inp
);
3942 if (so
->so_state
& SS_ISDISCONNECTED
) {
3943 SCTP_INP_RUNLOCK(inp
);
3944 error
= ECONNABORTED
;
3947 stcb
= LIST_FIRST(&inp
->sctp_asoc_list
);
3949 SCTP_INP_RUNLOCK(inp
);
3953 SCTP_TCB_LOCK(stcb
);
3954 SCTP_INP_RUNLOCK(inp
);
3955 prim
= (struct sockaddr
*)&stcb
->asoc
.primary_destination
->ro
._l_addr
;
3956 if (prim
->sa_family
== AF_INET
) {
3957 struct sockaddr_in
*sin
;
3958 #if defined(__FreeBSD__) || defined(__APPLE__) || defined(__DragonFly__)
3959 sin
= kmalloc(sizeof *sin
, M_SONAME
, M_WAITOK
| M_ZERO
);
3961 sin
= (struct sockaddr_in
*)addr
;
3962 bzero((caddr_t
)sin
, sizeof (*sin
));
3964 sin
->sin_family
= AF_INET
;
3965 sin
->sin_len
= sizeof(*sin
);
3966 sin
->sin_port
= ((struct sockaddr_in
*)prim
)->sin_port
;
3967 sin
->sin_addr
= ((struct sockaddr_in
*)prim
)->sin_addr
;
3968 #if defined(__FreeBSD__) || defined(__APPLE__) || defined(__DragonFly__)
3969 *addr
= (struct sockaddr
*)sin
;
3971 nam
->m_len
= sizeof(*sin
);
3974 struct sockaddr_in6
*sin6
;
3975 #if defined(__FreeBSD__) || defined(__APPLE__) || defined(__DragonFly__)
3976 sin6
= kmalloc(sizeof *sin6
, M_SONAME
, M_WAITOK
| M_ZERO
);
3978 sin6
= (struct sockaddr_in6
*)addr
;
3980 bzero((caddr_t
)sin6
, sizeof (*sin6
));
3981 sin6
->sin6_family
= AF_INET6
;
3982 sin6
->sin6_len
= sizeof(*sin6
);
3983 sin6
->sin6_port
= ((struct sockaddr_in6
*)prim
)->sin6_port
;
3985 sin6
->sin6_addr
= ((struct sockaddr_in6
*)prim
)->sin6_addr
;
3986 if (IN6_IS_SCOPE_LINKLOCAL(&sin6
->sin6_addr
))
3987 /* sin6->sin6_scope_id = ntohs(sin6->sin6_addr.s6_addr16[1]);*/
3988 in6_recoverscope(sin6
, &sin6
->sin6_addr
, NULL
); /* skip ifp check */
3990 sin6
->sin6_scope_id
= 0; /*XXX*/
3991 #if defined(__FreeBSD__) || defined (__APPLE__) || defined(__DragonFly__)
3992 *addr
= (struct sockaddr
*)sin6
;
3994 nam
->m_len
= sizeof(*sin6
);
3997 /* Wake any delayed sleep action */
3998 SCTP_TCB_UNLOCK(stcb
);
3999 SCTP_INP_WLOCK(inp
);
4000 if (inp
->sctp_flags
& SCTP_PCB_FLAGS_DONT_WAKE
) {
4001 inp
->sctp_flags
&= ~SCTP_PCB_FLAGS_DONT_WAKE
;
4002 if (inp
->sctp_flags
& SCTP_PCB_FLAGS_WAKEOUTPUT
) {
4003 inp
->sctp_flags
&= ~SCTP_PCB_FLAGS_WAKEOUTPUT
;
4004 #if defined(__NetBSD__)
4005 if (sowritable(inp
->sctp_socket
))
4006 sowwakeup(inp
->sctp_socket
);
4008 if (sowriteable(inp
->sctp_socket
))
4009 sowwakeup(inp
->sctp_socket
);
4012 if (inp
->sctp_flags
& SCTP_PCB_FLAGS_WAKEINPUT
) {
4013 inp
->sctp_flags
&= ~SCTP_PCB_FLAGS_WAKEINPUT
;
4014 if (soreadable(inp
->sctp_socket
))
4015 sorwakeup(inp
->sctp_socket
);
4019 SCTP_INP_WUNLOCK(inp
);
4022 lwkt_replymsg(&msg
->lmsg
, error
);
4027 sctp_ingetaddr(netmsg_t msg
)
4031 error
= sctp_ingetaddr_oncpu(msg
->sockaddr
.base
.nm_so
,
4032 msg
->sockaddr
.nm_nam
);
4033 lwkt_replymsg(&msg
->lmsg
, error
);
4037 sctp_ingetaddr_oncpu(struct socket
*so
, struct sockaddr
**addr
)
4039 struct sockaddr_in
*sin
;
4040 struct sctp_inpcb
*inp
;
4042 * Do the malloc first in case it blocks.
4044 #if defined(__FreeBSD__) || defined(__APPLE__) || defined(__DragonFly__)
4045 sin
= kmalloc(sizeof *sin
, M_SONAME
, M_WAITOK
| M_ZERO
);
4047 nam
->m_len
= sizeof(*sin
);
4048 memset(sin
, 0, sizeof(*sin
));
4050 sin
->sin_family
= AF_INET
;
4051 sin
->sin_len
= sizeof(*sin
);
4052 inp
= (struct sctp_inpcb
*)so
->so_pcb
;
4054 #if defined(__FreeBSD__) || defined(__APPLE__) || defined(__DragonFly__)
4055 kfree(sin
, M_SONAME
);
4059 SCTP_INP_RLOCK(inp
);
4060 sin
->sin_port
= inp
->sctp_lport
;
4061 if (inp
->sctp_flags
& SCTP_PCB_FLAGS_BOUNDALL
) {
4062 if (inp
->sctp_flags
& SCTP_PCB_FLAGS_CONNECTED
) {
4063 struct sctp_tcb
*stcb
;
4064 struct sockaddr_in
*sin_a
;
4065 struct sctp_nets
*net
;
4068 stcb
= LIST_FIRST(&inp
->sctp_asoc_list
);
4074 SCTP_TCB_LOCK(stcb
);
4075 TAILQ_FOREACH(net
, &stcb
->asoc
.nets
, sctp_next
) {
4076 sin_a
= (struct sockaddr_in
*)&net
->ro
._l_addr
;
4077 if (sin_a
->sin_family
== AF_INET
) {
4082 if ((!fnd
) || (sin_a
== NULL
)) {
4084 SCTP_TCB_UNLOCK(stcb
);
4087 sin
->sin_addr
= sctp_ipv4_source_address_selection(inp
,
4088 stcb
, (struct route
*)&net
->ro
, net
, 0);
4089 SCTP_TCB_UNLOCK(stcb
);
4091 /* For the bound all case you get back 0 */
4093 sin
->sin_addr
.s_addr
= 0;
4097 /* Take the first IPv4 address in the list */
4098 struct sctp_laddr
*laddr
;
4100 LIST_FOREACH(laddr
, &inp
->sctp_addr_list
, sctp_nxt_addr
) {
4101 if (laddr
->ifa
->ifa_addr
->sa_family
== AF_INET
) {
4102 struct sockaddr_in
*sin_a
;
4103 sin_a
= (struct sockaddr_in
*)laddr
->ifa
->ifa_addr
;
4104 sin
->sin_addr
= sin_a
->sin_addr
;
4110 #if defined(__FreeBSD__) || defined(__APPLE__) || defined(__DragonFly__)
4111 kfree(sin
, M_SONAME
);
4113 SCTP_INP_RUNLOCK(inp
);
4117 SCTP_INP_RUNLOCK(inp
);
4118 #if defined(__FreeBSD__) || defined(__APPLE__) || defined(__DragonFly__)
4119 (*addr
) = (struct sockaddr
*)sin
;
4125 sctp_peeraddr(netmsg_t msg
)
4129 error
= sctp_peeraddr_oncpu(msg
->peeraddr
.base
.nm_so
,
4130 msg
->peeraddr
.nm_nam
);
4131 lwkt_replymsg(&msg
->lmsg
, error
);
4135 sctp_peeraddr_oncpu(struct socket
*so
, struct sockaddr
**addr
)
4137 struct sockaddr_in
*sin
= (struct sockaddr_in
*)*addr
;
4138 struct sockaddr_in
*sin_a
;
4139 struct sctp_inpcb
*inp
;
4140 struct sctp_tcb
*stcb
;
4141 struct sctp_nets
*net
;
4145 /* Do the malloc first in case it blocks. */
4146 inp
= (struct sctp_inpcb
*)so
->so_pcb
;
4147 if ((inp
== NULL
) ||
4148 ((inp
->sctp_flags
& SCTP_PCB_FLAGS_CONNECTED
) == 0)) {
4149 /* UDP type and listeners will drop out here */
4154 #if defined(__FreeBSD__) || defined(__APPLE__) || defined(__DragonFly__)
4155 /* XXX huh? why assign it above and then allocate it here? */
4156 sin
= kmalloc(sizeof *sin
, M_SONAME
, M_WAITOK
| M_ZERO
);
4158 nam
->m_len
= sizeof(*sin
);
4159 memset(sin
, 0, sizeof(*sin
));
4161 sin
->sin_family
= AF_INET
;
4162 sin
->sin_len
= sizeof(*sin
);
4164 /* We must recapture incase we blocked */
4165 inp
= (struct sctp_inpcb
*)so
->so_pcb
;
4167 #if defined(__FreeBSD__) || defined(__APPLE__) || defined(__DragonFly__)
4168 kfree(sin
, M_SONAME
);
4173 SCTP_INP_RLOCK(inp
);
4174 stcb
= LIST_FIRST(&inp
->sctp_asoc_list
);
4176 SCTP_TCB_LOCK(stcb
);
4177 SCTP_INP_RUNLOCK(inp
);
4179 #if defined(__FreeBSD__) || defined(__APPLE__) || defined(__DragonFly__)
4180 kfree(sin
, M_SONAME
);
4186 TAILQ_FOREACH(net
, &stcb
->asoc
.nets
, sctp_next
) {
4187 sin_a
= (struct sockaddr_in
*)&net
->ro
._l_addr
;
4188 if (sin_a
->sin_family
== AF_INET
) {
4190 sin
->sin_port
= stcb
->rport
;
4191 sin
->sin_addr
= sin_a
->sin_addr
;
4195 SCTP_TCB_UNLOCK(stcb
);
4197 /* No IPv4 address */
4198 #if defined(__FreeBSD__) || defined(__APPLE__) || defined(__DragonFly__)
4199 kfree(sin
, M_SONAME
);
4209 #if defined(__FreeBSD__) || defined(__APPLE__) || defined(__DragonFly__)
4210 struct pr_usrreqs sctp_usrreqs
= {
4211 .pru_abort
= sctp_abort
,
4212 .pru_accept
= sctp_accept
,
4213 .pru_attach
= sctp_attach
,
4214 .pru_bind
= sctp_bind
,
4215 .pru_connect
= sctp_connect
,
4216 .pru_connect2
= pr_generic_notsupp
,
4217 .pru_control
= in_control_dispatch
,
4218 .pru_detach
= sctp_detach
,
4219 .pru_disconnect
= sctp_disconnect
,
4220 .pru_listen
= sctp_listen
,
4221 .pru_peeraddr
= sctp_peeraddr
,
4222 .pru_rcvd
= sctp_usr_recvd
,
4223 .pru_rcvoob
= pr_generic_notsupp
,
4224 .pru_send
= sctp_send
,
4225 .pru_sense
= pru_sense_null
,
4226 .pru_shutdown
= sctp_shutdown
,
4227 .pru_sockaddr
= sctp_ingetaddr
,
4228 .pru_sosend
= sctp_sosend
,
4229 .pru_soreceive
= soreceive
4233 #if defined(__NetBSD__)
4235 sctp_usrreq(struct socket
*so
, int req
, struct mbuf
*m
, struct mbuf
*nam
,
4236 struct mbuf
*control
, struct proc
*p
)
4241 sctp_usrreq(struct socket
*so
, int req
, struct mbuf
*m
, struct mbuf
*nam
,
4242 struct mbuf
*control
)
4244 struct proc
*p
= curproc
;
4249 family
= so
->so_proto
->pr_domain
->dom_family
;
4251 if (req
== PRU_CONTROL
) {
4254 error
= in_control(so
, (long)m
, (caddr_t
)nam
,
4255 (struct ifnet
*)control
4256 #if defined(__NetBSD__)
4263 error
= in6_control(so
, (long)m
, (caddr_t
)nam
,
4264 (struct ifnet
*)control
, p
);
4268 error
= EAFNOSUPPORT
;
4273 if (req
== PRU_PURGEIF
) {
4276 ifn
= (struct ifnet
*)control
;
4277 TAILQ_FOREACH(ifa
, &ifn
->if_addrlist
, ifa_list
) {
4278 if (ifa
->ifa_addr
->sa_family
== family
) {
4279 sctp_delete_ip_address(ifa
);
4292 return (EAFNOSUPPORT
);
4299 error
= sctp_attach(so
, family
, p
);
4302 error
= sctp_detach(so
);
4308 error
= sctp_bind(so
, nam
, p
);
4311 error
= sctp_listen(so
, p
);
4317 error
= sctp_connect(so
, nam
, p
);
4319 case PRU_DISCONNECT
:
4320 error
= sctp_disconnect(so
);
4326 error
= sctp_accept(so
, nam
);
4329 error
= sctp_shutdown(so
);
4334 * For Open and Net BSD, this is real
4335 * ugly. The mbuf *nam that is passed
4336 * (by soreceive()) is the int flags c
4337 * ast as a (mbuf *) yuck!
4339 error
= sctp_usr_recvd(so
, (int)((long)nam
));
4343 /* Flags are ignored */
4345 if (sctp_debug_on
& SCTP_DEBUG_USRREQ1
) {
4346 kprintf("Send called on V4 side\n");
4350 struct sockaddr
*addr
;
4354 addr
= mtod(nam
, struct sockaddr
*);
4356 error
= sctp_send(so
, 0, m
, addr
, control
, p
);
4360 error
= sctp_abort(so
);
4367 error
= EAFNOSUPPORT
;
4370 error
= EAFNOSUPPORT
;
4373 error
= sctp_peeraddr(so
, nam
);
4376 error
= sctp_ingetaddr(so
, nam
);
4388 /* #if defined(__NetBSD__) || defined(__OpenBSD__) */
4391 * Sysctl for sctp variables.
4394 sctp_sysctl(int *name
, u_int namelen
, void *oldp
, size_t *oldlenp
, void *newp
,
4398 /* All sysctl names at this level are terminal. */
4404 case SCTPCTL_MAXDGRAM
:
4405 return (sysctl_int(oldp
, oldlenp
, newp
, newlen
,
4407 case SCTPCTL_RECVSPACE
:
4408 return (sysctl_int(oldp
, oldlenp
, newp
, newlen
,
4410 case SCTPCTL_AUTOASCONF
:
4411 return (sysctl_int(oldp
, oldlenp
, newp
, newlen
,
4412 &sctp_auto_asconf
));
4413 case SCTPCTL_ECN_ENABLE
:
4414 return (sysctl_int(oldp
, oldlenp
, newp
, newlen
,
4416 case SCTPCTL_ECN_NONCE
:
4417 return (sysctl_int(oldp
, oldlenp
, newp
, newlen
,
4419 case SCTPCTL_STRICT_SACK
:
4420 return (sysctl_int(oldp
, oldlenp
, newp
, newlen
,
4421 &sctp_strict_sacks
));
4422 case SCTPCTL_NOCSUM_LO
:
4423 return (sysctl_int(oldp
, oldlenp
, newp
, newlen
,
4424 &sctp_no_csum_on_loopback
));
4425 case SCTPCTL_STRICT_INIT
:
4426 return (sysctl_int(oldp
, oldlenp
, newp
, newlen
,
4427 &sctp_strict_init
));
4428 case SCTPCTL_PEER_CHK_OH
:
4429 return (sysctl_int(oldp
, oldlenp
, newp
, newlen
,
4430 &sctp_peer_chunk_oh
));
4431 case SCTPCTL_MAXBURST
:
4432 return (sysctl_int(oldp
, oldlenp
, newp
, newlen
,
4433 &sctp_max_burst_default
));
4434 case SCTPCTL_MAXCHUNKONQ
:
4435 return (sysctl_int(oldp
, oldlenp
, newp
, newlen
,
4436 &sctp_max_chunks_on_queue
));
4437 case SCTPCTL_DELAYED_SACK
:
4438 return (sysctl_int(oldp
, oldlenp
, newp
, newlen
,
4439 &sctp_delayed_sack_time_default
));
4440 case SCTPCTL_HB_INTERVAL
:
4441 return (sysctl_int(oldp
, oldlenp
, newp
, newlen
,
4442 &sctp_heartbeat_interval_default
));
4443 case SCTPCTL_PMTU_RAISE
:
4444 return (sysctl_int(oldp
, oldlenp
, newp
, newlen
,
4445 &sctp_pmtu_raise_time_default
));
4446 case SCTPCTL_SHUTDOWN_GUARD
:
4447 return (sysctl_int(oldp
, oldlenp
, newp
, newlen
,
4448 &sctp_shutdown_guard_time_default
));
4449 case SCTPCTL_SECRET_LIFETIME
:
4450 return (sysctl_int(oldp
, oldlenp
, newp
, newlen
,
4451 &sctp_secret_lifetime_default
));
4452 case SCTPCTL_RTO_MAX
:
4453 return (sysctl_int(oldp
, oldlenp
, newp
, newlen
,
4454 &sctp_rto_max_default
));
4455 case SCTPCTL_RTO_MIN
:
4456 return (sysctl_int(oldp
, oldlenp
, newp
, newlen
,
4457 &sctp_rto_min_default
));
4458 case SCTPCTL_RTO_INITIAL
:
4459 return (sysctl_int(oldp
, oldlenp
, newp
, newlen
,
4460 &sctp_rto_initial_default
));
4461 case SCTPCTL_INIT_RTO_MAX
:
4462 return (sysctl_int(oldp
, oldlenp
, newp
, newlen
,
4463 &sctp_init_rto_max_default
));
4464 case SCTPCTL_COOKIE_LIFE
:
4465 return (sysctl_int(oldp
, oldlenp
, newp
, newlen
,
4466 &sctp_valid_cookie_life_default
));
4467 case SCTPCTL_INIT_RTX_MAX
:
4468 return (sysctl_int(oldp
, oldlenp
, newp
, newlen
,
4469 &sctp_init_rtx_max_default
));
4470 case SCTPCTL_ASSOC_RTX_MAX
:
4471 return (sysctl_int(oldp
, oldlenp
, newp
, newlen
,
4472 &sctp_assoc_rtx_max_default
));
4473 case SCTPCTL_PATH_RTX_MAX
:
4474 return (sysctl_int(oldp
, oldlenp
, newp
, newlen
,
4475 &sctp_path_rtx_max_default
));
4476 case SCTPCTL_NR_OUTGOING_STREAMS
:
4477 return (sysctl_int(oldp
, oldlenp
, newp
, newlen
,
4478 &sctp_nr_outgoing_streams_default
));
4481 return (sysctl_int(oldp
, oldlenp
, newp
, newlen
,
4485 return (ENOPROTOOPT
);
4492 * Sysctl for sctp variables.
4494 SYSCTL_SETUP(sysctl_net_inet_sctp_setup
, "sysctl net.inet.sctp subtree setup")
4497 sysctl_createv(clog
, 0, NULL
, NULL
,
4499 CTLTYPE_NODE
, "net", NULL
,
4502 sysctl_createv(clog
, 0, NULL
, NULL
,
4504 CTLTYPE_NODE
, "inet", NULL
,
4506 CTL_NET
, PF_INET
, CTL_EOL
);
4507 sysctl_createv(clog
, 0, NULL
, NULL
,
4509 CTLTYPE_NODE
, "sctp",
4510 SYSCTL_DESCR("sctp related settings"),
4512 CTL_NET
, PF_INET
, IPPROTO_SCTP
, CTL_EOL
);
4514 sysctl_createv(clog
, 0, NULL
, NULL
,
4515 CTLFLAG_PERMANENT
|CTLFLAG_READWRITE
,
4516 CTLTYPE_INT
, "maxdgram",
4517 SYSCTL_DESCR("Maximum outgoing SCTP buffer size"),
4518 NULL
, 0, &sctp_sendspace
, 0,
4519 CTL_NET
, PF_INET
, IPPROTO_SCTP
, SCTPCTL_MAXDGRAM
,
4522 sysctl_createv(clog
, 0, NULL
, NULL
,
4523 CTLFLAG_PERMANENT
|CTLFLAG_READWRITE
,
4524 CTLTYPE_INT
, "recvspace",
4525 SYSCTL_DESCR("Maximum incoming SCTP buffer size"),
4526 NULL
, 0, &sctp_recvspace
, 0,
4527 CTL_NET
, PF_INET
, IPPROTO_SCTP
, SCTPCTL_RECVSPACE
,
4530 sysctl_createv(clog
, 0, NULL
, NULL
,
4531 CTLFLAG_PERMANENT
|CTLFLAG_READWRITE
,
4532 CTLTYPE_INT
, "autoasconf",
4533 SYSCTL_DESCR("Enable SCTP Auto-ASCONF"),
4534 NULL
, 0, &sctp_auto_asconf
, 0,
4535 CTL_NET
, PF_INET
, IPPROTO_SCTP
, SCTPCTL_AUTOASCONF
,
4538 sysctl_createv(clog
, 0, NULL
, NULL
,
4539 CTLFLAG_PERMANENT
|CTLFLAG_READWRITE
,
4540 CTLTYPE_INT
, "ecn_enable",
4541 SYSCTL_DESCR("Enable SCTP ECN"),
4542 NULL
, 0, &sctp_ecn
, 0,
4543 CTL_NET
, PF_INET
, IPPROTO_SCTP
, SCTPCTL_ECN_ENABLE
,
4546 sysctl_createv(clog
, 0, NULL
, NULL
,
4547 CTLFLAG_PERMANENT
|CTLFLAG_READWRITE
,
4548 CTLTYPE_INT
, "ecn_nonce",
4549 SYSCTL_DESCR("Enable SCTP ECN Nonce"),
4550 NULL
, 0, &sctp_ecn_nonce
, 0,
4551 CTL_NET
, PF_INET
, IPPROTO_SCTP
, SCTPCTL_ECN_NONCE
,
4554 sysctl_createv(clog
, 0, NULL
, NULL
,
4555 CTLFLAG_PERMANENT
|CTLFLAG_READWRITE
,
4556 CTLTYPE_INT
, "strict_sack",
4557 SYSCTL_DESCR("Enable SCTP Strict SACK checking"),
4558 NULL
, 0, &sctp_strict_sacks
, 0,
4559 CTL_NET
, PF_INET
, IPPROTO_SCTP
, SCTPCTL_STRICT_SACK
,
4562 sysctl_createv(clog
, 0, NULL
, NULL
,
4563 CTLFLAG_PERMANENT
|CTLFLAG_READWRITE
,
4564 CTLTYPE_INT
, "loopback_nocsum",
4565 SYSCTL_DESCR("Enable NO Csum on packets sent on loopback"),
4566 NULL
, 0, &sctp_no_csum_on_loopback
, 0,
4567 CTL_NET
, PF_INET
, IPPROTO_SCTP
, SCTPCTL_NOCSUM_LO
,
4570 sysctl_createv(clog
, 0, NULL
, NULL
,
4571 CTLFLAG_PERMANENT
|CTLFLAG_READWRITE
,
4572 CTLTYPE_INT
, "strict_init",
4573 SYSCTL_DESCR("Enable strict INIT/INIT-ACK singleton enforcement"),
4574 NULL
, 0, &sctp_strict_init
, 0,
4575 CTL_NET
, PF_INET
, IPPROTO_SCTP
, SCTPCTL_STRICT_INIT
,
4578 sysctl_createv(clog
, 0, NULL
, NULL
,
4579 CTLFLAG_PERMANENT
|CTLFLAG_READWRITE
,
4580 CTLTYPE_INT
, "peer_chkoh",
4581 SYSCTL_DESCR("Amount to debit peers rwnd per chunk sent"),
4582 NULL
, 0, &sctp_peer_chunk_oh
, 0,
4583 CTL_NET
, PF_INET
, IPPROTO_SCTP
, SCTPCTL_PEER_CHK_OH
,
4586 sysctl_createv(clog
, 0, NULL
, NULL
,
4587 CTLFLAG_PERMANENT
|CTLFLAG_READWRITE
,
4588 CTLTYPE_INT
, "maxburst",
4589 SYSCTL_DESCR("Default max burst for sctp endpoints"),
4590 NULL
, 0, &sctp_max_burst_default
, 0,
4591 CTL_NET
, PF_INET
, IPPROTO_SCTP
, SCTPCTL_MAXBURST
,
4594 sysctl_createv(clog
, 0, NULL
, NULL
,
4595 CTLFLAG_PERMANENT
|CTLFLAG_READWRITE
,
4596 CTLTYPE_INT
, "maxchunks",
4597 SYSCTL_DESCR("Default max chunks on queue per asoc"),
4598 NULL
, 0, &sctp_max_chunks_on_queue
, 0,
4599 CTL_NET
, PF_INET
, IPPROTO_SCTP
, SCTPCTL_MAXCHUNKONQ
,