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