xref: /dragonfly/sys/netinet6/ip6_demux.c (revision 73e0051e)
1 /*
2  * Copyright (c) 2003, 2004 Jeffrey M. Hsu.  All rights reserved.
3  * Copyright (c) 2003, 2004 The DragonFly Project.  All rights reserved.
4  *
5  * This code is derived from software contributed to The DragonFly Project
6  * by Jeffrey M. Hsu.
7  *
8  * Redistribution and use in source and binary forms, with or without
9  * modification, are permitted provided that the following conditions
10  * are met:
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. Neither the name of The DragonFly Project nor the names of its
17  *    contributors may be used to endorse or promote products derived
18  *    from this software without specific, prior written permission.
19  *
20  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
23  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE
24  * COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
25  * INCIDENTAL, SPECIAL, EXEMPLARY OR CONSEQUENTIAL DAMAGES (INCLUDING,
26  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
27  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
28  * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
29  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
30  * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
31  * SUCH DAMAGE.
32  */
33 
34 #include "opt_inet6.h"
35 
36 #include <sys/param.h>
37 #include <sys/systm.h>
38 #include <sys/kernel.h>
39 #include <sys/socket.h>
40 #include <sys/socketvar.h>
41 
42 #include <netinet/tcp_var.h>
43 #include <netinet6/tcp6_var.h>
44 
45 lwkt_port_t
46 tcp6_soport(struct socket *so, struct sockaddr *nam, struct mbuf **m0, int req)
47 {
48 	struct inpcb *inp;
49 
50 	/*
51 	 * Use IPv6 default tcp soport (cpu0_soport) if:
52 	 * - No socket yet
53 	 * - No inp, connection reset by peer
54 	 * - IPv6 only
55 	 * - Not IPv4 mapped
56 	 */
57 	if (so == NULL || (inp = so->so_pcb) == NULL ||
58 	    (inp->inp_flags & IN6P_IPV6_V6ONLY) ||
59 	    (inp->inp_vflag & INP_IPV4) == 0)
60 		return cpu0_soport(so, nam, m0, req);
61 
62 	/* IPv4 mapped, fall back to IPv4 tcp_soport */
63 	return tcp_soport(so, nam, m0, req);
64 }
65 
66 /*
67  * XXX hack
68  */
69 lwkt_port_t
70 tcp6_addrport(void)
71 {
72 	return(tcp_addrport0());
73 }
74