1 /* $KAME: sctp6_usrreq.c,v 1.35 2004/08/17 06:28:03 t-momose Exp $ */
2 /* $DragonFly: src/sys/netinet6/sctp6_usrreq.c,v 1.10 2007/04/22 01:13:14 dillon Exp $ */
5 * Copyright (c) 2001, 2002, 2003, 2004 Cisco Systems, Inc.
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
11 * 1. Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in the
15 * documentation and/or other materials provided with the distribution.
16 * 3. All advertising materials mentioning features or use of this software
17 * must display the following acknowledgement:
18 * This product includes software developed by Cisco Systems, Inc.
19 * 4. Neither the name of the project nor the names of its contributors
20 * may be used to endorse or promote products derived from this software
21 * without specific prior written permission.
23 * THIS SOFTWARE IS PROVIDED BY CISCO SYSTEMS AND CONTRIBUTORS ``AS IS'' AND
24 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
25 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
26 * ARE DISCLAIMED. IN NO EVENT SHALL CISCO SYSTEMS OR CONTRIBUTORS BE LIABLE
27 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
28 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
29 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
30 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
31 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
32 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
35 #if !(defined(__OpenBSD__) || defined(__APPLE__))
38 #if defined(__FreeBSD__) || defined(__DragonFly__)
39 #include "opt_inet6.h"
45 #if !(defined(__OpenBSD__) || defined(__APPLE__))
46 #include "opt_ipsec.h"
50 #elif !defined(__OpenBSD__)
54 #include <sys/param.h>
55 #include <sys/kernel.h>
57 #include <sys/domain.h>
58 #include <sys/protosw.h>
59 #include <sys/socket.h>
60 #include <sys/malloc.h>
61 #include <sys/socketvar.h>
62 #include <sys/sysctl.h>
63 #include <sys/errno.h>
65 #include <sys/systm.h>
66 #include <sys/syslog.h>
69 #include <sys/thread2.h>
70 #include <sys/msgport2.h>
73 #include <net/route.h>
74 #include <net/if_types.h>
75 #include <netinet/in.h>
76 #include <netinet/in_systm.h>
77 #include <netinet/ip.h>
78 #include <netinet/in_pcb.h>
79 #include <netinet/in_var.h>
80 #include <netinet/ip_var.h>
81 #include <netinet/sctp_pcb.h>
82 #include <netinet/sctp_header.h>
83 #include <netinet/sctp_var.h>
84 #include <netinet/sctputil.h>
85 #include <netinet/sctp_output.h>
86 #include <netinet/sctp_input.h>
87 #include <netinet/sctp_asconf.h>
88 #include <netinet6/ip6_var.h>
89 #include <netinet/ip6.h>
90 #if !defined(__OpenBSD__)
91 #include <netinet6/in6_pcb.h>
93 #include <netinet/icmp6.h>
94 #include <netinet6/sctp6_var.h>
95 #include <netinet6/ip6protosw.h>
96 #include <netinet6/nd6.h>
100 #include <netinet6/ipsec6.h>
101 #include <netinet6/ipsec.h>
107 #if defined(NFAITH) && NFAITH > 0
108 #include <net/if_faith.h>
111 #include <net/net_osdep.h>
113 extern struct protosw inetsw[];
115 #if defined(HAVE_NRL_INPCB) || defined(__FreeBSD__) || defined(__DragonFly__)
120 #define sotoin6pcb sotoinpcb
125 extern u_int32_t sctp_debug_on;
128 #if !(defined(__FreeBSD__) || defined(__APPLE__) || defined(__DragonFly__))
129 extern void in6_sin_2_v4mapsin6 (struct sockaddr_in *sin,
130 struct sockaddr_in6 *sin6);
131 extern void in6_sin6_2_sin (struct sockaddr_in *,
132 struct sockaddr_in6 *sin6);
133 extern void in6_sin6_2_sin_in_sock(struct sockaddr *nam);
136 * Convert sockaddr_in6 to sockaddr_in. Original sockaddr_in6 must be
137 * v4 mapped addr or v4 compat addr
140 in6_sin6_2_sin(struct sockaddr_in *sin, struct sockaddr_in6 *sin6)
142 bzero(sin, sizeof(*sin));
143 sin->sin_len = sizeof(struct sockaddr_in);
144 sin->sin_family = AF_INET;
145 sin->sin_port = sin6->sin6_port;
146 sin->sin_addr.s_addr = sin6->sin6_addr.s6_addr32[3];
149 /* Convert sockaddr_in to sockaddr_in6 in v4 mapped addr format. */
151 in6_sin_2_v4mapsin6(struct sockaddr_in *sin, struct sockaddr_in6 *sin6)
153 bzero(sin6, sizeof(*sin6));
154 sin6->sin6_len = sizeof(struct sockaddr_in6);
155 sin6->sin6_family = AF_INET6;
156 sin6->sin6_port = sin->sin_port;
157 sin6->sin6_addr.s6_addr32[0] = 0;
158 sin6->sin6_addr.s6_addr32[1] = 0;
159 sin6->sin6_addr.s6_addr32[2] = IPV6_ADDR_INT32_SMP;
160 sin6->sin6_addr.s6_addr32[3] = sin->sin_addr.s_addr;
163 /* Convert sockaddr_in6 into sockaddr_in. */
165 in6_sin6_2_sin_in_sock(struct sockaddr *nam)
167 struct sockaddr_in *sin_p;
168 struct sockaddr_in6 sin6;
170 /* save original sockaddr_in6 addr and convert it to sockaddr_in */
171 sin6 = *(struct sockaddr_in6 *)nam;
172 sin_p = (struct sockaddr_in *)nam;
173 in6_sin6_2_sin(sin_p, &sin6);
176 #endif /* !(__FreeBSD__ || __APPLE__) */
178 static int sctp6_bind_oncpu(struct socket *so, struct sockaddr *addr, thread_t td);
181 extern int sctp_no_csum_on_loopback;
184 sctp6_input(struct mbuf **mp, int *offp, int proto)
186 struct mbuf *m = *mp;
189 struct sctp_inpcb *in6p = NULL;
190 struct sctp_nets *net;
192 u_int32_t check, calc_check;
193 struct inpcb *in6p_ip;
194 struct sctp_chunkhdr *ch;
195 struct mbuf *opts = NULL;
196 int length, mlen, offset, iphlen;
198 struct sctp_tcb *stcb = NULL;
201 ip6 = mtod(m, struct ip6_hdr *);
202 #ifndef PULLDOWN_TEST
203 /* If PULLDOWN_TEST off, must be in a single mbuf. */
204 IP6_EXTHDR_CHECK(m, off, (int)(sizeof(*sh) + sizeof(*ch)), IPPROTO_DONE);
205 sh = (struct sctphdr *)((caddr_t)ip6 + off);
206 ch = (struct sctp_chunkhdr *)((caddr_t)sh + sizeof(*sh));
208 /* Ensure that (sctphdr + sctp_chunkhdr) in a row. */
209 IP6_EXTHDR_GET(sh, struct sctphdr *, m, off, sizeof(*sh) + sizeof(*ch));
211 sctp_pegs[SCTP_HDR_DROPS]++;
214 ch = (struct sctp_chunkhdr *)((caddr_t)sh + sizeof(struct sctphdr));
218 offset = iphlen + sizeof(*sh) + sizeof(*ch);
220 #if defined(NFAITH) && NFAITH > 0
221 #if defined(__FreeBSD_cc_version) && __FreeBSD_cc_version <= 430000
222 #if defined(NFAITH) && 0 < NFAITH
223 if (faithprefix(&ip6h->ip6_dst)) {
224 /* XXX send icmp6 host/port unreach? */
231 if (faithprefix_p != NULL && (*faithprefix_p)(&ip6->ip6_dst)) {
232 /* XXX send icmp6 host/port unreach? */
236 if (faithprefix(&ip6->ip6_dst))
239 #endif /* __FreeBSD_cc_version */
241 #endif /* NFAITH defined and > 0 */
242 sctp_pegs[SCTP_INPKTS]++;
244 if (sctp_debug_on & SCTP_DEBUG_INPUT1) {
245 kprintf("V6 input gets a packet iphlen:%d pktlen:%d\n", iphlen, m->m_pkthdr.len);
248 if (IN6_IS_ADDR_MULTICAST(&ip6->ip6_dst)) {
249 /* No multi-cast support in SCTP */
250 sctp_pegs[SCTP_IN_MCAST]++;
253 /* destination port of 0 is illegal, based on RFC2960. */
254 if (sh->dest_port == 0)
256 if ((sctp_no_csum_on_loopback == 0) ||
257 (m->m_pkthdr.rcvif == NULL) ||
258 (m->m_pkthdr.rcvif->if_type != IFT_LOOP)) {
259 /* we do NOT validate things from the loopback if the
260 * sysctl is set to 1.
262 check = sh->checksum; /* save incoming checksum */
263 if ((check == 0) && (sctp_no_csum_on_loopback)) {
264 /* special hook for where we got a local address
265 * somehow routed across a non IFT_LOOP type interface
267 if (IN6_ARE_ADDR_EQUAL(&ip6->ip6_src, &ip6->ip6_dst))
270 sh->checksum = 0; /* prepare for calc */
271 calc_check = sctp_calculate_sum(m, &mlen, iphlen);
272 if (calc_check != check) {
274 if (sctp_debug_on & SCTP_DEBUG_INPUT1) {
275 kprintf("Bad CSUM on SCTP packet calc_check:%x check:%x m:%x mlen:%d iphlen:%d\n",
276 calc_check, check, (u_int)m,
280 stcb = sctp_findassociation_addr(m, iphlen, offset - sizeof(*ch),
281 sh, ch, &in6p, &net);
282 /* in6p's ref-count increased && stcb locked */
283 if ((in6p) && (stcb)) {
284 sctp_send_packet_dropped(stcb, net, m, iphlen, 1);
285 sctp_chunk_output((struct sctp_inpcb *)in6p, stcb, 2);
286 } else if ((in6p != NULL) && (stcb == NULL)) {
289 sctp_pegs[SCTP_BAD_CSUM]++;
292 sh->checksum = calc_check;
295 mlen = m->m_pkthdr.len;
299 * Locate pcb and tcb for datagram
300 * sctp_findassociation_addr() wants IP/SCTP/first chunk header...
303 if (sctp_debug_on & SCTP_DEBUG_INPUT1) {
304 kprintf("V6 Find the association\n");
307 stcb = sctp_findassociation_addr(m, iphlen, offset - sizeof(*ch),
308 sh, ch, &in6p, &net);
309 /* in6p's ref-count increased */
311 struct sctp_init_chunk *init_chk, chunk_buf;
313 sctp_pegs[SCTP_NOPORTS]++;
314 if (ch->chunk_type == SCTP_INITIATION) {
315 /* we do a trick here to get the INIT tag,
316 * dig in and get the tag from the INIT and
317 * put it in the common header.
319 init_chk = (struct sctp_init_chunk *)sctp_m_getptr(m,
320 iphlen + sizeof(*sh), sizeof(*init_chk),
321 (u_int8_t *)&chunk_buf);
322 sh->v_tag = init_chk->init.initiate_tag;
324 sctp_send_abort(m, iphlen, sh, 0, NULL);
326 } else if (stcb == NULL) {
329 in6p_ip = (struct inpcb *)in6p;
332 * Check AH/ESP integrity.
338 struct tdb_ident *tdbi;
342 /* Find most recent IPsec tag */
343 i_inp = (struct inpcb *)in6p;
344 mtag = m_tag_find(m, PACKET_TAG_IPSEC_IN_DONE, NULL);
347 tdbi = (struct tdb_ident *)(mtag + 1);
348 tdb = gettdb(tdbi->spi, &tdbi->dst, tdbi->proto);
352 ipsp_spd_lookup(m, af, iphlen, &error, IPSP_DIRECTION_IN,
360 if (i_inp->inp_tdb_in != tdb) {
362 tdb_add_inp(tdb, i_inp, 1);
363 if (i_inp->inp_ipo == NULL) {
364 i_inp->inp_ipo = ipsec_add_policy(i_inp,
365 af, IPSP_DIRECTION_OUT);
366 if (i_inp->inp_ipo == NULL) {
371 if (i_inp->inp_ipo->ipo_dstid == NULL &&
372 tdb->tdb_srcid != NULL) {
373 i_inp->inp_ipo->ipo_dstid =
375 tdb->tdb_srcid->ref_count++;
377 if (i_inp->inp_ipsec_remotecred == NULL &&
378 tdb->tdb_remote_cred != NULL) {
379 i_inp->inp_ipsec_remotecred =
380 tdb->tdb_remote_cred;
381 tdb->tdb_remote_cred->ref_count++;
383 if (i_inp->inp_ipsec_remoteauth == NULL &&
384 tdb->tdb_remote_auth != NULL) {
385 i_inp->inp_ipsec_remoteauth =
386 tdb->tdb_remote_auth;
387 tdb->tdb_remote_auth->ref_count++;
389 } else { /* Just reset */
390 TAILQ_REMOVE(&i_inp->inp_tdb_in->tdb_inp_in,
391 i_inp, binp_tdb_in_next);
392 i_inp->inp_tdb_in = NULL;
398 if (ipsec6_in_reject_so(m, in6p->sctp_socket)) {
401 /* FIX ME: need to find right stat for __APPLE__ */
402 ipsec6stat.in_polvio++;
410 * Construct sockaddr format source address.
411 * Stuff source address and datagram in user buffer.
413 if ((in6p->ip_inp.inp.inp_flags & INP_CONTROLOPTS)
415 || (in6p->sctp_socket->so_options & SO_TIMESTAMP)
418 #if defined(__FreeBSD__) || defined(__APPLE__) || defined(__DragonFly__)
419 #if (defined(SCTP_BASE_FREEBSD) && __FreeBSD_version < 501113) || \
420 defined(__APPLE__) || defined(__DragonFly__)
421 ip6_savecontrol(in6p_ip, &opts, ip6, m);
422 #elif __FreeBSD_version >= 440000 || (defined(SCTP_BASE_FREEBSD) && __FreeBSD_version >= 501113)
423 ip6_savecontrol(in6p_ip, m, &opts);
425 ip6_savecontrol(in6p_ip, m, &opts, NULL);
428 ip6_savecontrol((struct in6pcb *)in6p_ip, m, &opts);
433 * CONTROL chunk processing
435 length = ntohs(ip6->ip6_plen) + iphlen;
436 offset -= sizeof(*ch);
437 ecn_bits = ((ntohl(ip6->ip6_flow) >> 20) & 0x000000ff);
439 sctp_common_input_processing(&m, iphlen, offset, length, sh, ch,
440 in6p, stcb, net, ecn_bits);
441 /* inp's ref-count reduced && stcb unlocked */
443 /* XXX this stuff below gets moved to appropriate parts later... */
449 if ((in6p) && refcount_up){
450 /* reduce ref-count */
451 SCTP_INP_WLOCK(in6p);
452 SCTP_INP_DECR_REF(in6p);
453 SCTP_INP_WUNLOCK(in6p);
460 SCTP_TCB_UNLOCK(stcb);
462 if ((in6p) && refcount_up){
463 /* reduce ref-count */
464 SCTP_INP_WLOCK(in6p);
465 SCTP_INP_DECR_REF(in6p);
466 SCTP_INP_WUNLOCK(in6p);
477 sctp6_notify_mbuf(struct sctp_inpcb *inp,
478 struct icmp6_hdr *icmp6,
480 struct sctp_tcb *stcb,
481 struct sctp_nets *net)
485 if ((inp == NULL) || (stcb == NULL) || (net == NULL) ||
486 (icmp6 == NULL) || (sh == NULL)) {
490 /* First do we even look at it? */
491 if (ntohl(sh->v_tag) != (stcb->asoc.peer_vtag))
494 if (icmp6->icmp6_type != ICMP6_PACKET_TOO_BIG) {
495 /* not PACKET TO BIG */
499 * ok we need to look closely. We could even get smarter and
500 * look at anyone that we sent to in case we get a different
501 * ICMP that tells us there is no way to reach a host, but for
502 * this impl, all we care about is MTU discovery.
504 nxtsz = ntohl(icmp6->icmp6_mtu);
505 /* Stop any PMTU timer */
506 sctp_timer_stop(SCTP_TIMER_TYPE_PATHMTURAISE, inp, stcb, NULL);
508 /* Adjust destination size limit */
509 if (net->mtu > nxtsz) {
512 /* now what about the ep? */
513 if (stcb->asoc.smallest_mtu > nxtsz) {
514 struct sctp_tmit_chunk *chk;
515 struct sctp_stream_out *strm;
516 /* Adjust that too */
517 stcb->asoc.smallest_mtu = nxtsz;
518 /* now off to subtract IP_DF flag if needed */
520 TAILQ_FOREACH(chk, &stcb->asoc.send_queue, sctp_next) {
521 if ((chk->send_size+IP_HDR_SIZE) > nxtsz) {
522 chk->flags |= CHUNK_FLAGS_FRAGMENT_OK;
525 TAILQ_FOREACH(chk, &stcb->asoc.sent_queue, sctp_next) {
526 if ((chk->send_size+IP_HDR_SIZE) > nxtsz) {
528 * For this guy we also mark for immediate
529 * resend since we sent to big of chunk
531 chk->flags |= CHUNK_FLAGS_FRAGMENT_OK;
532 if (chk->sent != SCTP_DATAGRAM_RESEND)
533 stcb->asoc.sent_queue_retran_cnt++;
534 chk->sent = SCTP_DATAGRAM_RESEND;
535 chk->rec.data.doing_fast_retransmit = 0;
537 chk->sent = SCTP_DATAGRAM_RESEND;
538 /* Clear any time so NO RTT is being done */
539 chk->sent_rcv_time.tv_sec = 0;
540 chk->sent_rcv_time.tv_usec = 0;
541 stcb->asoc.total_flight -= chk->send_size;
542 net->flight_size -= chk->send_size;
545 TAILQ_FOREACH(strm, &stcb->asoc.out_wheel, next_spoke) {
546 TAILQ_FOREACH(chk, &strm->outqueue, sctp_next) {
547 if ((chk->send_size+IP_HDR_SIZE) > nxtsz) {
548 chk->flags |= CHUNK_FLAGS_FRAGMENT_OK;
553 sctp_timer_start(SCTP_TIMER_TYPE_PATHMTURAISE, inp, stcb, NULL);
556 /* reduce inp's ref-count */
558 SCTP_INP_DECR_REF(inp);
559 SCTP_INP_WUNLOCK(inp);
562 SCTP_TCB_UNLOCK(stcb);
567 sctp6_ctlinput(int cmd, struct sockaddr *pktdst, void *d)
570 struct ip6ctlparam *ip6cp = NULL;
573 if (pktdst->sa_family != AF_INET6 ||
574 pktdst->sa_len != sizeof(struct sockaddr_in6))
577 if ((unsigned)cmd >= PRC_NCMDS)
579 if (PRC_IS_REDIRECT(cmd)) {
581 } else if (inet6ctlerrmap[cmd] == 0) {
585 /* if the parameter is from icmp6, decode it. */
587 ip6cp = (struct ip6ctlparam *)d;
594 * XXX: We assume that when IPV6 is non NULL,
595 * M and OFF are valid.
597 /* check if we can safely examine src and dst ports */
598 struct sctp_inpcb *inp;
599 struct sctp_tcb *stcb;
600 struct sctp_nets *net;
601 struct sockaddr_in6 final;
603 if (ip6cp->ip6c_m == NULL ||
604 (size_t)ip6cp->ip6c_m->m_pkthdr.len < (ip6cp->ip6c_off + sizeof(sh)))
607 bzero(&sh, sizeof(sh));
608 bzero(&final, sizeof(final));
611 m_copydata(ip6cp->ip6c_m, ip6cp->ip6c_off, sizeof(sh),
613 ip6cp->ip6c_src->sin6_port = sh.src_port;
614 final.sin6_len = sizeof(final);
615 final.sin6_family = AF_INET6;
616 #if defined(__FreeBSD__) && __FreeBSD_cc_version < 440000
617 final.sin6_addr = *ip6cp->ip6c_finaldst;
619 final.sin6_addr = ((struct sockaddr_in6 *)pktdst)->sin6_addr;
620 #endif /* __FreeBSD_cc_version */
621 final.sin6_port = sh.dest_port;
623 stcb = sctp_findassociation_addr_sa((struct sockaddr *)ip6cp->ip6c_src,
624 (struct sockaddr *)&final,
626 /* inp's ref-count increased && stcb locked */
627 if (stcb != NULL && inp && (inp->sctp_socket != NULL)) {
628 if (cmd == PRC_MSGSIZE) {
629 sctp6_notify_mbuf(inp,
634 /* inp's ref-count reduced && stcb unlocked */
636 if (cmd == PRC_HOSTDEAD) {
639 cm = inet6ctlerrmap[cmd];
641 sctp_notify(inp, cm, &sh,
642 (struct sockaddr *)&final,
644 /* inp's ref-count reduced && stcb unlocked */
647 if (PRC_IS_REDIRECT(cmd) && inp) {
649 in_rtchange((struct inpcb *)inp,
652 in6_rtchange((struct in6pcb *)inp,
653 inet6ctlerrmap[cmd]);
657 /* reduce inp's ref-count */
659 SCTP_INP_DECR_REF(inp);
660 SCTP_INP_WUNLOCK(inp);
663 SCTP_TCB_UNLOCK(stcb);
670 * this routine can probably be collasped into the one in sctp_userreq.c
671 * since they do the same thing and now we lookup with a sockaddr
675 sctp6_getcred(SYSCTL_HANDLER_ARGS)
677 struct sockaddr_in6 addrs[2];
678 struct sctp_inpcb *inp;
679 struct sctp_nets *net;
680 struct sctp_tcb *stcb;
683 #if defined(__FreeBSD__) && __FreeBSD_version >= 500000
684 error = suser(req->td);
686 error = suser(req->p);
691 if (req->newlen != sizeof(addrs))
693 if (req->oldlen != sizeof(struct ucred))
695 error = SYSCTL_IN(req, addrs, sizeof(addrs));
700 stcb = sctp_findassociation_addr_sa(sin6tosa(&addrs[0]),
703 if (stcb == NULL || inp == NULL || inp->sctp_socket == NULL) {
707 SCTP_INP_DECR_REF(inp);
708 SCTP_INP_WUNLOCK(inp);
712 error = SYSCTL_OUT(req, inp->sctp_socket->so_cred,
713 sizeof(struct ucred));
715 SCTP_TCB_UNLOCK (stcb);
721 SYSCTL_PROC(_net_inet6_sctp6, OID_AUTO, getcred, CTLTYPE_OPAQUE|CTLFLAG_RW,
723 sctp6_getcred, "S,ucred", "Get the ucred of a SCTP6 connection");
728 * NOTE: (so) is referenced from soabort*() and netmsg_pru_abort()
729 * will sofree() it when we return.
732 sctp6_abort(netmsg_t msg)
734 struct socket *so = msg->abort.base.nm_so;
735 struct sctp_inpcb *inp;
738 inp = (struct sctp_inpcb *)so->so_pcb;
740 soisdisconnected(so);
741 sctp_inpcb_free(inp, 1);
746 lwkt_replymsg(&msg->lmsg, error);
750 sctp6_attach(netmsg_t msg)
752 struct socket *so = msg->attach.base.nm_so;
755 struct sctp_inpcb *inp;
757 inp = (struct sctp_inpcb *)so->so_pcb;
763 if (so->so_snd.ssb_hiwat == 0 || so->so_rcv.ssb_hiwat == 0) {
764 error = soreserve(so, sctp_sendspace, sctp_recvspace, NULL);
769 error = sctp_inpcb_alloc(so);
773 inp = (struct sctp_inpcb *)so->so_pcb;
774 inp->sctp_flags |= SCTP_PCB_FLAGS_BOUND_V6; /* I'm v6! */
775 inp6 = (struct in6pcb *)inp;
777 #if defined(__FreeBSD__) || defined(__APPLE__) || defined(__DragonFly__)
778 inp6->inp_vflag |= INP_IPV6;
780 #if defined(__OpenBSD__)
781 inp->ip_inp.inp.inp_flags |= INP_IPV6;
783 inp->inp_vflag |= INP_IPV6;
786 #if defined(__NetBSD__)
788 inp6->in6p_flags |= IN6P_IPV6_V6ONLY;
790 so->so_send = sctp_sosend;
792 inp6->in6p_hops = -1; /* use kernel default */
793 inp6->in6p_cksum = -1; /* just to be sure */
797 * IPv4 TTL initialization is necessary for an IPv6 socket as well,
798 * because the socket may be bound to an IPv6 wildcard address,
799 * which may match an IPv4-mapped IPv6 address.
801 #if defined(__FreeBSD__) || defined(__APPLE__) || defined(__DragonFly__)
802 inp6->inp_ip_ttl = ip_defttl;
804 inp->inp_ip_ttl = ip_defttl;
808 * Hmm what about the IPSEC stuff that is missing here but
813 lwkt_replymsg(&msg->lmsg, error);
817 sctp6_bind(netmsg_t msg)
821 error = sctp6_bind_oncpu(msg->bind.base.nm_so,
824 lwkt_replymsg(&msg->lmsg, error);
828 sctp6_bind_oncpu(struct socket *so, struct sockaddr *addr, thread_t td)
830 struct sctp_inpcb *inp;
834 inp = (struct sctp_inpcb *)so->so_pcb;
840 inp6 = (struct in6pcb *)inp;
841 #if defined(__FreeBSD__) || defined(__APPLE__) || defined(__DragonFly__)
842 inp6->inp_vflag &= ~INP_IPV4;
843 inp6->inp_vflag |= INP_IPV6;
845 #if defined(__OpenBSD__)
846 inp->ip_inp.inp.inp_flags &= ~INP_IPV4;
847 inp->ip_inp.inp.inp_flags |= INP_IPV6;
849 inp->inp_vflag &= ~INP_IPV4;
850 inp->inp_vflag |= INP_IPV6;
854 #if defined(__OpenBSD__)
855 (0) /* we always do dual bind */
856 #elif defined (__NetBSD__)
857 !(inp6->in6p_flags & IN6P_IPV6_V6ONLY)
859 !(inp6->inp_flags & IN6P_IPV6_V6ONLY)
862 if (addr->sa_family == AF_INET) {
863 /* binding v4 addr to v6 socket, so reset flags */
864 #if defined(__FreeBSD__) || defined(__APPLE__) || defined(__DragonFly__)
865 inp6->inp_vflag |= INP_IPV4;
866 inp6->inp_vflag &= ~INP_IPV6;
868 #if defined(__OpenBSD__)
869 inp->ip_inp.inp.inp_flags |= INP_IPV4;
870 inp->ip_inp.inp.inp_flags &= ~INP_IPV6;
872 inp->inp_vflag |= INP_IPV4;
873 inp->inp_vflag &= ~INP_IPV6;
877 struct sockaddr_in6 *sin6_p;
878 sin6_p = (struct sockaddr_in6 *)addr;
880 if (IN6_IS_ADDR_UNSPECIFIED(&sin6_p->sin6_addr)) {
881 #if defined(__FreeBSD__) || defined(__APPLE__) || defined(__DragonFly__)
882 inp6->inp_vflag |= INP_IPV4;
884 #if defined(__OpenBSD__)
885 inp->ip_inp.inp.inp_flags |= INP_IPV4;
887 inp->inp_vflag |= INP_IPV4;
891 else if (IN6_IS_ADDR_V4MAPPED(&sin6_p->sin6_addr)) {
892 struct sockaddr_in sin;
893 in6_sin6_2_sin(&sin, sin6_p);
894 #if defined(__FreeBSD__) || defined(__APPLE__) || defined(__DragonFly__)
895 inp6->inp_vflag |= INP_IPV4;
896 inp6->inp_vflag &= ~INP_IPV6;
898 #if defined(__OpenBSD__)
899 inp->ip_inp.inp.inp_flags |= INP_IPV4;
900 inp->ip_inp.inp.inp_flags &= ~INP_IPV6;
903 inp->inp_vflag |= INP_IPV4;
904 inp->inp_vflag &= ~INP_IPV6;
908 error = sctp_inpcb_bind(so,
909 (struct sockaddr *)&sin,
915 } else if (addr != NULL) {
916 /* IPV6_V6ONLY socket */
917 if (addr->sa_family == AF_INET) {
918 /* can't bind v4 addr to v6 only socket! */
922 struct sockaddr_in6 *sin6_p;
923 sin6_p = (struct sockaddr_in6 *)addr;
925 if (IN6_IS_ADDR_V4MAPPED(&sin6_p->sin6_addr)) {
926 /* can't bind v4-mapped addrs either! */
927 /* NOTE: we don't support SIIT */
934 error = sctp_inpcb_bind(so, addr, td);
940 /*This could be made common with sctp_detach() since they are identical */
942 sctp6_detach(netmsg_t msg)
944 struct socket *so = msg->detach.base.nm_so;
945 struct sctp_inpcb *inp;
948 inp = (struct sctp_inpcb *)so->so_pcb;
954 if (((so->so_options & SO_LINGER) && (so->so_linger == 0)) ||
955 (so->so_rcv.ssb_cc > 0))
956 sctp_inpcb_free(inp, 1);
958 sctp_inpcb_free(inp, 0);
962 lwkt_replymsg(&msg->lmsg, error);
966 sctp6_disconnect(netmsg_t msg)
968 struct socket *so = msg->disconnect.base.nm_so;
969 struct sctp_inpcb *inp;
973 inp = (struct sctp_inpcb *)so->so_pcb;
979 if (inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) {
980 if (LIST_EMPTY(&inp->sctp_asoc_list)) {
985 int some_on_streamwheel = 0;
986 struct sctp_association *asoc;
987 struct sctp_tcb *stcb;
989 stcb = LIST_FIRST(&inp->sctp_asoc_list);
996 if (!TAILQ_EMPTY(&asoc->out_wheel)) {
997 /* Check to see if some data queued */
998 struct sctp_stream_out *outs;
999 TAILQ_FOREACH(outs, &asoc->out_wheel,
1001 if (!TAILQ_EMPTY(&outs->outqueue)) {
1002 some_on_streamwheel = 1;
1008 if (TAILQ_EMPTY(&asoc->send_queue) &&
1009 TAILQ_EMPTY(&asoc->sent_queue) &&
1010 (some_on_streamwheel == 0)) {
1011 /* nothing queued to send, so I'm done... */
1012 if ((SCTP_GET_STATE(asoc) !=
1013 SCTP_STATE_SHUTDOWN_SENT) &&
1014 (SCTP_GET_STATE(asoc) !=
1015 SCTP_STATE_SHUTDOWN_ACK_SENT)) {
1016 /* only send SHUTDOWN the first time */
1018 if (sctp_debug_on & SCTP_DEBUG_OUTPUT4) {
1019 kprintf("%s:%d sends a shutdown\n",
1025 sctp_send_shutdown(stcb, stcb->asoc.primary_destination);
1026 sctp_chunk_output(stcb->sctp_ep, stcb, 1);
1027 asoc->state = SCTP_STATE_SHUTDOWN_SENT;
1028 sctp_timer_start(SCTP_TIMER_TYPE_SHUTDOWN,
1029 stcb->sctp_ep, stcb,
1030 asoc->primary_destination);
1031 sctp_timer_start(SCTP_TIMER_TYPE_SHUTDOWNGUARD,
1032 stcb->sctp_ep, stcb,
1033 asoc->primary_destination);
1037 * we still got (or just got) data to send,
1038 * so set SHUTDOWN_PENDING
1041 * XXX sockets draft says that MSG_EOF should
1042 * be sent with no data. currently, we will
1043 * allow user data to be sent first and move
1044 * to SHUTDOWN-PENDING
1046 asoc->state |= SCTP_STATE_SHUTDOWN_PENDING;
1052 /* UDP model does not support this */
1057 lwkt_replymsg(&msg->lmsg, error);
1062 sctp6_send(netmsg_t msg)
1064 struct socket *so = msg->send.base.nm_so;
1065 struct mbuf *m = msg->send.nm_m;
1066 struct mbuf *control = msg->send.nm_control;
1067 struct sockaddr *addr = msg->send.nm_addr;
1068 struct sctp_inpcb *inp;
1069 struct inpcb *in_inp;
1070 struct in6pcb *inp6;
1071 int flags = msg->send.nm_flags;
1073 struct sockaddr_in6 *sin6;
1076 /* No SPL needed since sctp_output does this */
1078 inp = (struct sctp_inpcb *)so->so_pcb;
1088 in_inp = (struct inpcb *)inp;
1089 inp6 = (struct in6pcb *)inp;
1090 /* For the TCP model we may get a NULL addr, if we
1091 * are a connected socket thats ok.
1093 if ((inp->sctp_flags & SCTP_PCB_FLAGS_CONNECTED) &&
1095 goto connected_type;
1103 error = EDESTADDRREQ;
1108 sin6 = (struct sockaddr_in6 *)addr;
1111 #if defined(__OpenBSD__)
1112 (0) /* we always do dual bind */
1113 #elif defined (__NetBSD__)
1114 (inp6->in6p_flags & IN6P_IPV6_V6ONLY)
1116 (inp6->inp_flags & IN6P_IPV6_V6ONLY)
1120 * if IPV6_V6ONLY flag, we discard datagrams
1121 * destined to a v4 addr or v4-mapped addr
1123 if (addr->sa_family == AF_INET) {
1127 if (IN6_IS_ADDR_V4MAPPED(&sin6->sin6_addr)) {
1133 if (IN6_IS_ADDR_V4MAPPED(&sin6->sin6_addr)) {
1135 struct sockaddr_in *sin;
1137 sin = kmalloc(sizeof(*sin), M_LWKTMSG, M_INTWAIT);
1138 /* convert v4-mapped into v4 addr and send */
1139 in6_sin6_2_sin(sin, sin6);
1140 msg->send.nm_addr = (struct sockaddr *)sin;
1141 msg->send.nm_flags |= PRUS_NAMALLOC;
1143 /* msg invalid now */
1146 /* mapped addresses aren't enabled */
1153 /* now what about control */
1156 kprintf("huh? control set?\n");
1157 m_freem(inp->control);
1158 inp->control = NULL;
1160 inp->control = control;
1162 /* add it in possibly */
1164 (inp->pkt->m_flags & M_PKTHDR)) {
1170 for (x=m;x;x = x->m_next) {
1173 inp->pkt->m_pkthdr.len += c_len;
1175 /* Place the data */
1177 inp->pkt_last->m_next = m;
1180 inp->pkt_last = inp->pkt = m;
1183 #if defined(__FreeBSD__) || defined(__APPLE__) || defined(__DragonFly__)
1184 /* FreeBSD and MacOSX uses a flag passed */
1185 (!(flags & PRUS_MORETOCOME))
1186 #elif defined(__NetBSD__)
1187 /* NetBSD uses the so_state field */
1188 (!(so->so_state & SS_MORETOCOME))
1190 1 /* Open BSD does not have any "more to come" indication */
1194 * note with the current version this code will only be
1195 * used by OpenBSD, NetBSD and FreeBSD have methods for
1196 * re-defining sosend() to use sctp_sosend(). One can
1197 * optionaly switch back to this code (by changing back
1198 * the defininitions but this is not advisable.
1200 error = sctp_output(inp, inp->pkt, addr,
1201 inp->control, msg->send.nm_td, flags);
1203 inp->control = NULL;
1208 lwkt_replymsg(&msg->lmsg, error);
1212 sctp6_connect(netmsg_t msg)
1214 struct socket *so = msg->connect.base.nm_so;
1215 struct sockaddr *addr = msg->connect.nm_nam;
1216 struct sctp_inpcb *inp;
1217 struct in6pcb *inp6;
1218 struct sctp_tcb *stcb;
1220 struct sockaddr_in6 *sin6;
1221 struct sockaddr_storage ss;
1226 inp6 = (struct in6pcb *)so->so_pcb;
1227 inp = (struct sctp_inpcb *)so->so_pcb;
1230 error = ECONNRESET; /* I made the same as TCP since
1231 * we are not setup? */
1234 SCTP_ASOC_CREATE_LOCK(inp);
1235 SCTP_INP_RLOCK(inp);
1236 if ((inp->sctp_flags & SCTP_PCB_FLAGS_UNBOUND) ==
1237 SCTP_PCB_FLAGS_UNBOUND) {
1238 /* Bind a ephemeral port */
1239 SCTP_INP_RUNLOCK(inp);
1240 error = sctp6_bind_oncpu(so, NULL, msg->connect.nm_td);
1243 SCTP_ASOC_CREATE_UNLOCK(inp);
1246 SCTP_INP_RLOCK(inp);
1249 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) &&
1250 (inp->sctp_flags & SCTP_PCB_FLAGS_CONNECTED)) {
1251 /* We are already connected AND the TCP model */
1253 SCTP_INP_RUNLOCK(inp);
1254 SCTP_ASOC_CREATE_UNLOCK(inp);
1260 sin6 = (struct sockaddr_in6 *)addr;
1262 #if defined(__OpenBSD__)
1263 (0) /* we always do dual bind */
1264 #elif defined (__NetBSD__)
1265 (inp6->in6p_flags & IN6P_IPV6_V6ONLY)
1267 (inp6->inp_flags & IN6P_IPV6_V6ONLY)
1271 * if IPV6_V6ONLY flag, ignore connections
1272 * destined to a v4 addr or v4-mapped addr
1274 if (addr->sa_family == AF_INET) {
1276 SCTP_INP_RUNLOCK(inp);
1277 SCTP_ASOC_CREATE_UNLOCK(inp);
1281 if (IN6_IS_ADDR_V4MAPPED(&sin6->sin6_addr)) {
1283 SCTP_INP_RUNLOCK(inp);
1284 SCTP_ASOC_CREATE_UNLOCK(inp);
1290 if (IN6_IS_ADDR_V4MAPPED(&sin6->sin6_addr)) {
1292 /* convert v4-mapped into v4 addr */
1293 in6_sin6_2_sin((struct sockaddr_in *)&ss, sin6);
1294 addr = (struct sockaddr *)&ss;
1296 /* mapped addresses aren't enabled */
1298 SCTP_INP_RUNLOCK(inp);
1299 SCTP_ASOC_CREATE_UNLOCK(inp);
1305 addr = addr; /* for true v6 address case */
1307 /* Now do we connect? */
1308 if (inp->sctp_flags & SCTP_PCB_FLAGS_CONNECTED) {
1309 stcb = LIST_FIRST(&inp->sctp_asoc_list);
1311 SCTP_TCB_UNLOCK (stcb);
1312 SCTP_INP_RUNLOCK(inp);
1314 SCTP_INP_RUNLOCK(inp);
1315 SCTP_INP_WLOCK(inp);
1316 SCTP_INP_INCR_REF(inp);
1317 SCTP_INP_WUNLOCK(inp);
1318 stcb = sctp_findassociation_ep_addr(&inp, addr, NULL, NULL, NULL);
1320 SCTP_INP_WLOCK(inp);
1321 SCTP_INP_DECR_REF(inp);
1322 SCTP_INP_WUNLOCK(inp);
1327 /* Already have or am bring up an association */
1328 SCTP_ASOC_CREATE_UNLOCK(inp);
1329 SCTP_TCB_UNLOCK (stcb);
1334 /* We are GOOD to go */
1335 stcb = sctp_aloc_assoc(inp, addr, 1, &error, 0);
1336 SCTP_ASOC_CREATE_UNLOCK(inp);
1338 /* Gak! no memory */
1342 if (stcb->sctp_ep->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) {
1343 stcb->sctp_ep->sctp_flags |= SCTP_PCB_FLAGS_CONNECTED;
1344 /* Set the connected flag so we can queue data */
1347 stcb->asoc.state = SCTP_STATE_COOKIE_WAIT;
1348 SCTP_GETTIME_TIMEVAL(&stcb->asoc.time_entered);
1349 sctp_send_initiate(inp, stcb);
1350 SCTP_TCB_UNLOCK (stcb);
1353 lwkt_replymsg(&msg->lmsg, error);
1357 #if defined(__FreeBSD__) || defined(__APPLE__) || defined(__DragonFly__)
1358 sctp6_getaddr(struct socket *so, struct sockaddr **addr)
1360 struct sockaddr_in6 *sin6;
1362 sctp6_getaddr(struct socket *so, struct mbuf *nam)
1364 struct sockaddr_in6 *sin6 = mtod(nam, struct sockaddr_in6 *);
1366 struct sctp_inpcb *inp;
1368 * Do the malloc first in case it blocks.
1370 #if defined(__FreeBSD__) || defined(__APPLE__) || defined(__DragonFly__)
1371 MALLOC(sin6, struct sockaddr_in6 *, sizeof *sin6, M_SONAME,
1374 nam->m_len = sizeof(*sin6);
1376 bzero(sin6, sizeof(*sin6));
1377 sin6->sin6_family = AF_INET6;
1378 sin6->sin6_len = sizeof(*sin6);
1380 inp = (struct sctp_inpcb *)so->so_pcb;
1382 #if defined(__FreeBSD__) || defined(__APPLE__) || defined(__DragonFly__)
1383 FREE(sin6, M_SONAME);
1388 sin6->sin6_port = inp->sctp_lport;
1389 if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUNDALL) {
1390 /* For the bound all case you get back 0 */
1391 if (inp->sctp_flags & SCTP_PCB_FLAGS_CONNECTED) {
1392 struct sctp_tcb *stcb;
1393 struct sockaddr_in6 *sin_a6;
1394 struct sctp_nets *net;
1397 stcb = LIST_FIRST(&inp->sctp_asoc_list);
1403 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
1404 sin_a6 = (struct sockaddr_in6 *)&net->ro._l_addr;
1405 if (sin_a6->sin6_family == AF_INET6) {
1410 if ((!fnd) || (sin_a6 == NULL)) {
1414 sin6->sin6_addr = sctp_ipv6_source_address_selection(
1415 inp, stcb, (struct route *)&net->ro, net, 0);
1418 /* For the bound all case you get back 0 */
1420 memset(&sin6->sin6_addr, 0, sizeof(sin6->sin6_addr));
1423 /* Take the first IPv6 address in the list */
1424 struct sctp_laddr *laddr;
1426 LIST_FOREACH(laddr, &inp->sctp_addr_list, sctp_nxt_addr) {
1427 if (laddr->ifa->ifa_addr->sa_family == AF_INET6) {
1428 struct sockaddr_in6 *sin_a;
1429 sin_a = (struct sockaddr_in6 *)laddr->ifa->ifa_addr;
1430 sin6->sin6_addr = sin_a->sin6_addr;
1436 #if defined(__FreeBSD__) || defined(__APPLE__) || defined(__DragonFly__)
1437 FREE(sin6, M_SONAME);
1442 /* Scoping things for v6 */
1443 if (IN6_IS_SCOPE_LINKLOCAL(&sin6->sin6_addr))
1444 /* skip ifp check below */
1445 in6_recoverscope(sin6, &sin6->sin6_addr, NULL);
1447 sin6->sin6_scope_id = 0; /*XXX*/
1448 #if defined(__FreeBSD__) || defined(__APPLE__) || defined(__DragonFly__)
1449 (*addr) = (struct sockaddr *)sin6;
1455 #if defined(__FreeBSD__) || defined(__APPLE__) || defined(__DragonFly__)
1456 sctp6_peeraddr(struct socket *so, struct sockaddr **addr)
1458 struct sockaddr_in6 *sin6 = (struct sockaddr_in6 *)*addr;
1460 sctp6_peeraddr(struct socket *so, struct mbuf *nam)
1462 struct sockaddr_in6 *sin6 = mtod(nam, struct sockaddr_in6 *);
1465 struct sockaddr_in6 *sin_a6;
1466 struct sctp_inpcb *inp;
1467 struct sctp_tcb *stcb;
1468 struct sctp_nets *net;
1470 * Do the malloc first in case it blocks.
1472 inp = (struct sctp_inpcb *)so->so_pcb;
1473 if (!(inp->sctp_flags & SCTP_PCB_FLAGS_CONNECTED)) {
1474 /* UDP type and listeners will drop out here */
1477 #if defined(__FreeBSD__) || defined(__APPLE__) || defined(__DragonFly__)
1478 MALLOC(sin6, struct sockaddr_in6 *, sizeof *sin6, M_SONAME,
1481 nam->m_len = sizeof(*sin6);
1483 bzero(sin6, sizeof(*sin6));
1484 sin6->sin6_family = AF_INET6;
1485 sin6->sin6_len = sizeof(*sin6);
1487 /* We must recapture incase we blocked */
1488 inp = (struct sctp_inpcb *)so->so_pcb;
1490 #if defined(__FreeBSD__) || defined(__APPLE__) || defined(__DragonFly__)
1491 FREE(sin6, M_SONAME);
1495 stcb = LIST_FIRST(&inp->sctp_asoc_list);
1497 #if defined(__FreeBSD__) || defined(__APPLE__) || defined(__DragonFly__)
1498 FREE(sin6, M_SONAME);
1503 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
1504 sin_a6 = (struct sockaddr_in6 *)&net->ro._l_addr;
1505 if (sin_a6->sin6_family == AF_INET6) {
1507 sin6->sin6_port = stcb->rport;
1508 sin6->sin6_addr = sin_a6->sin6_addr;
1513 /* No IPv4 address */
1514 #if defined(__FreeBSD__) || defined(__APPLE__) || defined(__DragonFly__)
1515 FREE(sin6, M_SONAME);
1519 in6_recoverscope(sin6, &sin6->sin6_addr, NULL);
1520 #if defined(__FreeBSD__) || defined(__APPLE__) || defined(__DragonFly__)
1521 *addr = (struct sockaddr *)sin6;
1527 sctp6_in6getaddr(netmsg_t msg)
1529 struct socket *so = msg->sockaddr.base.nm_so;;
1530 struct sockaddr **nam = msg->sockaddr.nm_nam;
1531 struct sockaddr *addr;
1532 struct in6pcb *inp6 = sotoin6pcb(so);
1541 /* allow v6 addresses precedence */
1542 error = sctp6_getaddr(so, nam);
1544 /* try v4 next if v6 failed */
1545 error = sctp_ingetaddr_oncpu(so, nam);
1550 #if defined(__FreeBSD__) || defined(__APPLE__) || defined(__DragonFly__)
1553 /* if I'm V6ONLY, convert it to v4-mapped */
1555 #if defined(__OpenBSD__)
1556 (0) /* we always do dual bind */
1557 #elif defined (__NetBSD__)
1558 (inp6->in6p_flags & IN6P_IPV6_V6ONLY)
1560 (inp6->inp_flags & IN6P_IPV6_V6ONLY)
1563 struct sockaddr_in6 sin6;
1564 in6_sin_2_v4mapsin6((struct sockaddr_in *)addr, &sin6);
1565 memcpy(addr, &sin6, sizeof(struct sockaddr_in6));
1566 #if !(defined(__FreeBSD__) || defined(__APPLE__) || defined(__DragonFly__))
1567 nam->m_len = sizeof(sin6);
1569 #if !(defined(__FreeBSD__) || defined(__APPLE__) || defined(__DragonFly__))
1571 nam->m_len = sizeof(struct sockaddr_in);
1574 #if !(defined(__FreeBSD__) || defined(__APPLE__) || defined(__DragonFly__))
1576 nam->m_len = sizeof(struct sockaddr_in6);
1581 lwkt_replymsg(&msg->lmsg, error);
1585 sctp6_getpeeraddr(netmsg_t msg)
1587 struct socket *so = msg->peeraddr.base.nm_so;
1588 struct sockaddr **nam = msg->peeraddr.nm_nam;
1589 struct sockaddr *addr = *nam;
1590 struct in6pcb *inp6 = sotoin6pcb(so);
1599 /* allow v6 addresses precedence */
1600 error = sctp6_peeraddr(so, nam);
1602 /* try v4 next if v6 failed */
1603 error = sctp_peeraddr_oncpu(so, nam);
1608 /* if I'm V6ONLY, convert it to v4-mapped */
1610 #if defined(__OpenBSD__)
1611 (0) /* we always do dual bind */
1612 #elif defined (__NetBSD__)
1613 (inp6->in6p_flags & IN6P_IPV6_V6ONLY)
1615 (inp6->inp_flags & IN6P_IPV6_V6ONLY)
1618 struct sockaddr_in6 sin6;
1619 in6_sin_2_v4mapsin6((struct sockaddr_in *)addr, &sin6);
1620 memcpy(addr, &sin6, sizeof(struct sockaddr_in6));
1621 #if !(defined(__FreeBSD__) || defined(__APPLE__) || defined(__DragonFly__))
1622 nam->m_len = sizeof(sin6);
1624 #if !(defined(__FreeBSD__) || defined(__APPLE__) || defined(__DragonFly__))
1626 nam->m_len = sizeof(struct sockaddr_in);
1629 #if !(defined(__FreeBSD__) || defined(__APPLE__) || defined(__DragonFly__))
1631 nam->m_len = sizeof(struct sockaddr_in6);
1636 lwkt_replymsg(&msg->lmsg, error);
1639 #if defined(__FreeBSD__) || defined(__APPLE__) || defined(__DragonFly__)
1640 struct pr_usrreqs sctp6_usrreqs = {
1641 .pru_abort = sctp6_abort,
1642 .pru_accept = sctp_accept,
1643 .pru_attach = sctp6_attach,
1644 .pru_bind = sctp6_bind,
1645 .pru_connect = sctp6_connect,
1646 .pru_connect2 = pr_generic_notsupp,
1647 .pru_control = in6_control_dispatch,
1648 .pru_detach = sctp6_detach,
1649 .pru_disconnect = sctp6_disconnect,
1650 .pru_listen = sctp_listen,
1651 .pru_peeraddr = sctp6_getpeeraddr,
1652 .pru_rcvd = sctp_usr_recvd,
1653 .pru_rcvoob = pr_generic_notsupp,
1654 .pru_send = sctp6_send,
1655 .pru_sense = pru_sense_null,
1656 .pru_shutdown = sctp_shutdown,
1657 .pru_sockaddr = sctp6_in6getaddr,
1658 .pru_sosend = sctp_sosend,
1659 .pru_soreceive = soreceive
1667 sctp6_usrreq(struct socket *so, int req, struct mbuf *m, struct mbuf *nam,
1668 struct mbuf *control, struct proc *p)
1674 #if defined(__OpenBSD__)
1678 family = so->so_proto->pr_domain->dom_family;
1680 if (req == PRU_CONTROL) {
1683 error = in_control(so, (long)m, (caddr_t)nam,
1684 (struct ifnet *)control
1685 #if defined(__NetBSD__)
1691 error = in6_control(so, (long)m, (caddr_t)nam,
1692 (struct ifnet *)control, p);
1695 error = EAFNOSUPPORT;
1701 if (req == PRU_PURGEIF) {
1704 ifn = (struct ifnet *)control;
1705 TAILQ_FOREACH(ifa, &ifn->if_addrlist, ifa_list) {
1706 if (ifa->ifa_addr->sa_family == family) {
1707 sctp_delete_ip_address(ifa);
1721 return (EAFNOSUPPORT);
1729 error = sctp6_attach(so, family, p);
1732 error = sctp6_detach(so);
1737 error = sctp6_bind(so, nam, p);
1740 error = sctp_listen(so, p);
1745 error = sctp6_connect(so, nam, p);
1747 case PRU_DISCONNECT:
1748 error = sctp6_disconnect(so);
1753 error = sctp_accept(so, nam);
1756 error = sctp_shutdown(so);
1761 * For OpenBSD and NetBSD, this is real ugly. The (mbuf *)
1762 * nam that is passed (by soreceive()) is the int flags
1763 * cast as a (mbuf *) yuck!
1765 error = sctp_usr_recvd(so, (int)((long)nam));
1769 /* Flags are ignored */
1770 error = sctp6_send(so, 0, m, nam, control, p);
1773 error = sctp6_abort(so);
1780 error = EAFNOSUPPORT;
1783 error = EAFNOSUPPORT;
1786 error = sctp6_getpeeraddr(so, nam);
1789 error = sctp6_in6getaddr(so, nam);