xref: /onnv-gate/usr/src/uts/common/io/mac/plugins/mac_6to4.c (revision 10616:3be00c4a6835)
1*10616SSebastien.Roy@Sun.COM /*
2*10616SSebastien.Roy@Sun.COM  * CDDL HEADER START
3*10616SSebastien.Roy@Sun.COM  *
4*10616SSebastien.Roy@Sun.COM  * The contents of this file are subject to the terms of the
5*10616SSebastien.Roy@Sun.COM  * Common Development and Distribution License (the "License").
6*10616SSebastien.Roy@Sun.COM  * You may not use this file except in compliance with the License.
7*10616SSebastien.Roy@Sun.COM  *
8*10616SSebastien.Roy@Sun.COM  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9*10616SSebastien.Roy@Sun.COM  * or http://www.opensolaris.org/os/licensing.
10*10616SSebastien.Roy@Sun.COM  * See the License for the specific language governing permissions
11*10616SSebastien.Roy@Sun.COM  * and limitations under the License.
12*10616SSebastien.Roy@Sun.COM  *
13*10616SSebastien.Roy@Sun.COM  * When distributing Covered Code, include this CDDL HEADER in each
14*10616SSebastien.Roy@Sun.COM  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15*10616SSebastien.Roy@Sun.COM  * If applicable, add the following below this CDDL HEADER, with the
16*10616SSebastien.Roy@Sun.COM  * fields enclosed by brackets "[]" replaced with your own identifying
17*10616SSebastien.Roy@Sun.COM  * information: Portions Copyright [yyyy] [name of copyright owner]
18*10616SSebastien.Roy@Sun.COM  *
19*10616SSebastien.Roy@Sun.COM  * CDDL HEADER END
20*10616SSebastien.Roy@Sun.COM  */
21*10616SSebastien.Roy@Sun.COM /*
22*10616SSebastien.Roy@Sun.COM  * Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
23*10616SSebastien.Roy@Sun.COM  * Use is subject to license terms.
24*10616SSebastien.Roy@Sun.COM  */
25*10616SSebastien.Roy@Sun.COM 
26*10616SSebastien.Roy@Sun.COM /*
27*10616SSebastien.Roy@Sun.COM  * DL_6TO4 MAC Type plugin for the Nemo mac module
28*10616SSebastien.Roy@Sun.COM  */
29*10616SSebastien.Roy@Sun.COM 
30*10616SSebastien.Roy@Sun.COM #include <sys/modctl.h>
31*10616SSebastien.Roy@Sun.COM #include <sys/dlpi.h>
32*10616SSebastien.Roy@Sun.COM #include <inet/ip.h>
33*10616SSebastien.Roy@Sun.COM #include <sys/mac.h>
34*10616SSebastien.Roy@Sun.COM #include <sys/mac_6to4.h>
35*10616SSebastien.Roy@Sun.COM #include <sys/mac_ipv4_impl.h>
36*10616SSebastien.Roy@Sun.COM 
37*10616SSebastien.Roy@Sun.COM static struct modlmisc mac_6to4_modlmisc = {
38*10616SSebastien.Roy@Sun.COM 	&mod_miscops,
39*10616SSebastien.Roy@Sun.COM 	"6to4 tunneling MAC plugin"
40*10616SSebastien.Roy@Sun.COM };
41*10616SSebastien.Roy@Sun.COM 
42*10616SSebastien.Roy@Sun.COM static struct modlinkage mac_6to4_modlinkage = {
43*10616SSebastien.Roy@Sun.COM 	MODREV_1,
44*10616SSebastien.Roy@Sun.COM 	&mac_6to4_modlmisc,
45*10616SSebastien.Roy@Sun.COM 	NULL
46*10616SSebastien.Roy@Sun.COM };
47*10616SSebastien.Roy@Sun.COM 
48*10616SSebastien.Roy@Sun.COM static mactype_ops_t mac_6to4_type_ops;
49*10616SSebastien.Roy@Sun.COM 
50*10616SSebastien.Roy@Sun.COM int
_init(void)51*10616SSebastien.Roy@Sun.COM _init(void)
52*10616SSebastien.Roy@Sun.COM {
53*10616SSebastien.Roy@Sun.COM 	mactype_register_t *mtrp;
54*10616SSebastien.Roy@Sun.COM 	int	err;
55*10616SSebastien.Roy@Sun.COM 
56*10616SSebastien.Roy@Sun.COM 	if ((mtrp = mactype_alloc(MACTYPE_VERSION)) == NULL)
57*10616SSebastien.Roy@Sun.COM 		return (ENOTSUP);
58*10616SSebastien.Roy@Sun.COM 	mtrp->mtr_ident = MAC_PLUGIN_IDENT_6TO4;
59*10616SSebastien.Roy@Sun.COM 	mtrp->mtr_ops = &mac_6to4_type_ops;
60*10616SSebastien.Roy@Sun.COM 	mtrp->mtr_mactype = DL_6TO4;
61*10616SSebastien.Roy@Sun.COM 	mtrp->mtr_nativetype = DL_6TO4;
62*10616SSebastien.Roy@Sun.COM 	mtrp->mtr_addrlen = sizeof (ipaddr_t);
63*10616SSebastien.Roy@Sun.COM 	if ((err = mactype_register(mtrp)) == 0) {
64*10616SSebastien.Roy@Sun.COM 		if ((err = mod_install(&mac_6to4_modlinkage)) != 0)
65*10616SSebastien.Roy@Sun.COM 			(void) mactype_unregister(MAC_PLUGIN_IDENT_6TO4);
66*10616SSebastien.Roy@Sun.COM 	}
67*10616SSebastien.Roy@Sun.COM 	mactype_free(mtrp);
68*10616SSebastien.Roy@Sun.COM 	return (err);
69*10616SSebastien.Roy@Sun.COM }
70*10616SSebastien.Roy@Sun.COM 
71*10616SSebastien.Roy@Sun.COM int
_fini(void)72*10616SSebastien.Roy@Sun.COM _fini(void)
73*10616SSebastien.Roy@Sun.COM {
74*10616SSebastien.Roy@Sun.COM 	int	err;
75*10616SSebastien.Roy@Sun.COM 	if ((err = mactype_unregister(MAC_PLUGIN_IDENT_6TO4)) != 0)
76*10616SSebastien.Roy@Sun.COM 		return (err);
77*10616SSebastien.Roy@Sun.COM 	return (mod_remove(&mac_6to4_modlinkage));
78*10616SSebastien.Roy@Sun.COM }
79*10616SSebastien.Roy@Sun.COM 
80*10616SSebastien.Roy@Sun.COM int
_info(struct modinfo * modinfop)81*10616SSebastien.Roy@Sun.COM _info(struct modinfo *modinfop)
82*10616SSebastien.Roy@Sun.COM {
83*10616SSebastien.Roy@Sun.COM 	return (mod_info(&mac_6to4_modlinkage, modinfop));
84*10616SSebastien.Roy@Sun.COM }
85*10616SSebastien.Roy@Sun.COM 
86*10616SSebastien.Roy@Sun.COM /*
87*10616SSebastien.Roy@Sun.COM  * MAC Type plugin operations.  Note that because 6to4 is a form of
88*10616SSebastien.Roy@Sun.COM  * tunneling over IPv4, this plugin is able to steal most of its operations
89*10616SSebastien.Roy@Sun.COM  * from the IPv4 plugin.
90*10616SSebastien.Roy@Sun.COM  */
91*10616SSebastien.Roy@Sun.COM 
92*10616SSebastien.Roy@Sun.COM /*
93*10616SSebastien.Roy@Sun.COM  * Check the legality of a 6to4 tunnel SAP value.  The only acceptable
94*10616SSebastien.Roy@Sun.COM  * values are IPPROTO_IPV6 (IPv6 in IPv4 tunneling) and 0 (for snoop).
95*10616SSebastien.Roy@Sun.COM  */
96*10616SSebastien.Roy@Sun.COM /* ARGSUSED */
97*10616SSebastien.Roy@Sun.COM boolean_t
mac_6to4_sap_verify(uint32_t sap,uint32_t * bind_sap,void * pdata)98*10616SSebastien.Roy@Sun.COM mac_6to4_sap_verify(uint32_t sap, uint32_t *bind_sap, void *pdata)
99*10616SSebastien.Roy@Sun.COM {
100*10616SSebastien.Roy@Sun.COM 	if (sap == IPPROTO_IPV6 || sap == 0) {
101*10616SSebastien.Roy@Sun.COM 		if (bind_sap != NULL)
102*10616SSebastien.Roy@Sun.COM 			*bind_sap = sap;
103*10616SSebastien.Roy@Sun.COM 		return (B_TRUE);
104*10616SSebastien.Roy@Sun.COM 	}
105*10616SSebastien.Roy@Sun.COM 	return (B_FALSE);
106*10616SSebastien.Roy@Sun.COM }
107*10616SSebastien.Roy@Sun.COM 
108*10616SSebastien.Roy@Sun.COM static mactype_ops_t	mac_6to4_type_ops = {
109*10616SSebastien.Roy@Sun.COM 	MTOPS_PDATA_VERIFY,
110*10616SSebastien.Roy@Sun.COM 	mac_ipv4_unicst_verify,
111*10616SSebastien.Roy@Sun.COM 	mac_ipv4_multicst_verify,
112*10616SSebastien.Roy@Sun.COM 	mac_6to4_sap_verify,
113*10616SSebastien.Roy@Sun.COM 	mac_ipv4_header,
114*10616SSebastien.Roy@Sun.COM 	mac_ipv4_header_info,
115*10616SSebastien.Roy@Sun.COM 	mac_ipv4_pdata_verify,
116*10616SSebastien.Roy@Sun.COM 	NULL,
117*10616SSebastien.Roy@Sun.COM 	NULL,
118*10616SSebastien.Roy@Sun.COM 	NULL
119*10616SSebastien.Roy@Sun.COM };
120