]>
Commit | Line | Data |
---|---|---|
1c79356b A |
1 | /* |
2 | * Copyright (c) 2000 Apple Computer, Inc. All rights reserved. | |
3 | * | |
4 | * @APPLE_LICENSE_HEADER_START@ | |
5 | * | |
37839358 A |
6 | * The contents of this file constitute Original Code as defined in and |
7 | * are subject to the Apple Public Source License Version 1.1 (the | |
8 | * "License"). You may not use this file except in compliance with the | |
9 | * License. Please obtain a copy of the License at | |
10 | * http://www.apple.com/publicsource and read it before using this file. | |
1c79356b | 11 | * |
37839358 A |
12 | * This Original Code and all software distributed under the License are |
13 | * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER | |
1c79356b A |
14 | * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, |
15 | * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, | |
37839358 A |
16 | * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the |
17 | * License for the specific language governing rights and limitations | |
18 | * under the License. | |
1c79356b A |
19 | * |
20 | * @APPLE_LICENSE_HEADER_END@ | |
21 | */ | |
22 | /* | |
23 | * Copyright (c) 1982, 1989, 1993 | |
24 | * The Regents of the University of California. All rights reserved. | |
25 | * | |
26 | * Redistribution and use in source and binary forms, with or without | |
27 | * modification, are permitted provided that the following conditions | |
28 | * are met: | |
29 | * 1. Redistributions of source code must retain the above copyright | |
30 | * notice, this list of conditions and the following disclaimer. | |
31 | * 2. Redistributions in binary form must reproduce the above copyright | |
32 | * notice, this list of conditions and the following disclaimer in the | |
33 | * documentation and/or other materials provided with the distribution. | |
34 | * 3. All advertising materials mentioning features or use of this software | |
35 | * must display the following acknowledgement: | |
36 | * This product includes software developed by the University of | |
37 | * California, Berkeley and its contributors. | |
38 | * 4. Neither the name of the University nor the names of its contributors | |
39 | * may be used to endorse or promote products derived from this software | |
40 | * without specific prior written permission. | |
41 | * | |
42 | * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND | |
43 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | |
44 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | |
45 | * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE | |
46 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | |
47 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | |
48 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | |
49 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | |
50 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | |
51 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | |
52 | * SUCH DAMAGE. | |
53 | * | |
54 | */ | |
55 | ||
56 | ||
57 | ||
58 | #include <sys/param.h> | |
59 | #include <sys/systm.h> | |
60 | #include <sys/kernel.h> | |
61 | #include <sys/malloc.h> | |
62 | #include <sys/mbuf.h> | |
63 | #include <sys/socket.h> | |
64 | #include <sys/sockio.h> | |
65 | #include <sys/sysctl.h> | |
91447636 | 66 | #include <kern/lock.h> |
1c79356b A |
67 | |
68 | #include <net/if.h> | |
1c79356b A |
69 | #include <net/route.h> |
70 | #include <net/if_llc.h> | |
71 | #include <net/if_dl.h> | |
72 | #include <net/if_types.h> | |
73 | #include <net/ndrv.h> | |
91447636 | 74 | #include <net/kpi_protocol.h> |
1c79356b A |
75 | |
76 | #include <netinet/in.h> | |
77 | #include <netinet/in_var.h> | |
78 | #include <netinet/if_ether.h> | |
79 | #include <netinet/in_systm.h> | |
80 | #include <netinet/ip.h> | |
81 | ||
82 | #if INET6 | |
83 | #include <netinet6/nd6.h> | |
84 | #include <netinet6/in6_ifattach.h> | |
85 | #endif | |
86 | ||
87 | ||
88 | ||
89 | #include <sys/socketvar.h> | |
1c79356b A |
90 | |
91 | #include <net/dlil.h> | |
92 | ||
93 | ||
94 | #if LLC && CCITT | |
95 | extern struct ifqueue pkintrq; | |
96 | #endif | |
97 | ||
98 | ||
99 | #if BRIDGE | |
100 | #include <net/bridge.h> | |
101 | #endif | |
102 | ||
103 | /* #include "vlan.h" */ | |
104 | #if NVLAN > 0 | |
105 | #include <net/if_vlan_var.h> | |
106 | #endif /* NVLAN > 0 */ | |
107 | ||
91447636 A |
108 | /* Local function declerations */ |
109 | int ether_attach_inet6(struct ifnet *ifp, u_long protocol_family); | |
110 | int ether_detach_inet6(struct ifnet *ifp, u_long protocol_family); | |
1c79356b A |
111 | |
112 | /* | |
113 | * Process a received Ethernet packet; | |
114 | * the packet is in the mbuf chain m without | |
115 | * the ether header, which is provided separately. | |
116 | */ | |
91447636 A |
117 | static errno_t |
118 | inet6_ether_input( | |
119 | __unused ifnet_t ifp, | |
120 | protocol_family_t protocol, | |
121 | mbuf_t packet, | |
122 | __unused char *header) | |
1c79356b | 123 | { |
91447636 A |
124 | proto_input(protocol, packet); |
125 | return 0; | |
126 | } | |
1c79356b | 127 | |
91447636 A |
128 | static errno_t |
129 | inet6_ether_pre_output( | |
130 | ifnet_t ifp, | |
131 | __unused protocol_family_t protocol_family, | |
132 | mbuf_t *m0, | |
133 | const struct sockaddr *dst_netaddr, | |
134 | void *route, | |
135 | char *type, | |
136 | char *edst) | |
137 | { | |
138 | errno_t result; | |
139 | struct sockaddr_dl sdl; | |
140 | register struct mbuf *m = *m0; | |
1c79356b | 141 | |
91447636 A |
142 | /* |
143 | * Tell ether_frameout it's ok to loop packet if necessary | |
144 | */ | |
145 | m->m_flags |= M_LOOP; | |
146 | ||
147 | result = nd6_lookup_ipv6(ifp, (const struct sockaddr_in6*)dst_netaddr, | |
148 | &sdl, sizeof(sdl), route, *m0); | |
149 | ||
150 | if (result == 0) { | |
151 | *(u_int16_t*)type = htons(ETHERTYPE_IPV6); | |
152 | bcopy(LLADDR(&sdl), edst, sdl.sdl_alen); | |
1c79356b | 153 | } |
1c79356b | 154 | |
1c79356b A |
155 | |
156 | ||
91447636 | 157 | return result; |
1c79356b A |
158 | } |
159 | ||
91447636 A |
160 | static int |
161 | ether_inet6_resolve_multi( | |
162 | ifnet_t ifp, | |
163 | const struct sockaddr *proto_addr, | |
164 | struct sockaddr_dl *out_ll, | |
165 | size_t ll_len) | |
1c79356b | 166 | { |
91447636 A |
167 | static const size_t minsize = offsetof(struct sockaddr_dl, sdl_data[0]) + ETHER_ADDR_LEN; |
168 | const struct sockaddr_in6 *sin6 = (const struct sockaddr_in6*)proto_addr; | |
1c79356b | 169 | |
91447636 A |
170 | if (proto_addr->sa_family != AF_INET6) |
171 | return EAFNOSUPPORT; | |
172 | ||
173 | if (proto_addr->sa_len < sizeof(struct sockaddr_in6)) | |
174 | return EINVAL; | |
175 | ||
176 | if (ll_len < minsize) | |
177 | return EMSGSIZE; | |
178 | ||
179 | bzero(out_ll, minsize); | |
180 | out_ll->sdl_len = minsize; | |
181 | out_ll->sdl_family = AF_LINK; | |
182 | out_ll->sdl_index = ifp->if_index; | |
183 | out_ll->sdl_type = IFT_ETHER; | |
184 | out_ll->sdl_nlen = 0; | |
185 | out_ll->sdl_alen = ETHER_ADDR_LEN; | |
186 | out_ll->sdl_slen = 0; | |
187 | ETHER_MAP_IPV6_MULTICAST(&sin6->sin6_addr, LLADDR(out_ll)); | |
188 | ||
189 | return 0; | |
1c79356b A |
190 | } |
191 | ||
192 | ||
91447636 A |
193 | static errno_t |
194 | ether_inet6_prmod_ioctl( | |
195 | ifnet_t ifp, | |
196 | __unused protocol_family_t protocol_family, | |
197 | u_int32_t command, | |
198 | void* data) | |
1c79356b | 199 | { |
1c79356b | 200 | struct ifreq *ifr = (struct ifreq *) data; |
1c79356b | 201 | int error = 0; |
1c79356b | 202 | |
1c79356b | 203 | switch (command) { |
1c79356b A |
204 | case SIOCSIFADDR: |
205 | if ((ifp->if_flags & IFF_RUNNING) == 0) { | |
91447636 | 206 | ifnet_set_flags(ifp, IFF_UP, IFF_UP); |
1c79356b A |
207 | dlil_ioctl(0, ifp, SIOCSIFFLAGS, (caddr_t) 0); |
208 | } | |
209 | ||
210 | break; | |
211 | ||
212 | case SIOCGIFADDR: | |
91447636 | 213 | ifnet_lladdr_copy_bytes(ifp, ifr->ifr_addr.sa_data, ETHER_ADDR_LEN); |
1c79356b A |
214 | break; |
215 | ||
216 | case SIOCSIFMTU: | |
217 | /* | |
9bccf70c | 218 | * IOKit IONetworkFamily will set the right MTU according to the driver |
1c79356b | 219 | */ |
9bccf70c A |
220 | |
221 | return (0); | |
1c79356b A |
222 | |
223 | default: | |
224 | return EOPNOTSUPP; | |
225 | } | |
226 | ||
1c79356b A |
227 | return (error); |
228 | } | |
229 | ||
91447636 A |
230 | int |
231 | ether_attach_inet6( | |
232 | struct ifnet *ifp, | |
233 | __unused u_long protocol_family) | |
1c79356b | 234 | { |
91447636 A |
235 | struct ifnet_attach_proto_param proto; |
236 | struct ifnet_demux_desc demux[1]; | |
237 | u_short en_6native=htons(ETHERTYPE_IPV6); | |
238 | errno_t error; | |
239 | ||
240 | bzero(&proto, sizeof(proto)); | |
241 | demux[0].type = DLIL_DESC_ETYPE2; | |
242 | demux[0].data = &en_6native; | |
243 | demux[0].datalen = sizeof(en_6native); | |
244 | proto.demux_list = demux; | |
245 | proto.demux_count = 1; | |
246 | proto.input = inet6_ether_input; | |
247 | proto.pre_output = inet6_ether_pre_output; | |
248 | proto.ioctl = ether_inet6_prmod_ioctl; | |
249 | proto.resolve = ether_inet6_resolve_multi; | |
250 | error = ifnet_attach_protocol(ifp, protocol_family, &proto); | |
251 | if (error && error != EEXIST) { | |
252 | printf("WARNING: ether_attach_inet6 can't attach ipv6 to %s%d\n", | |
253 | ifp->if_name, ifp->if_unit); | |
254 | } | |
255 | ||
256 | return error; | |
1c79356b | 257 | } |
9bccf70c | 258 | |
91447636 A |
259 | int |
260 | ether_detach_inet6( | |
261 | struct ifnet *ifp, | |
262 | u_long protocol_family) | |
9bccf70c | 263 | { |
91447636 A |
264 | errno_t error; |
265 | ||
266 | error = ifnet_detach_protocol(ifp, protocol_family); | |
267 | if (error && error != ENOENT) { | |
268 | printf("WARNING: ether_detach_inet6 can't detach ipv6 from %s%d\n", | |
269 | ifp->if_name, ifp->if_unit); | |
270 | } | |
271 | ||
272 | return error; | |
9bccf70c A |
273 | } |
274 |