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