]>
Commit | Line | Data |
---|---|---|
1c79356b A |
1 | /* |
2 | * Copyright (c) 2000 Apple Computer, Inc. All rights reserved. | |
3 | * | |
4 | * @APPLE_LICENSE_HEADER_START@ | |
5 | * | |
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. | |
11 | * | |
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 | |
14 | * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, | |
15 | * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, | |
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. | |
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> | |
66 | ||
67 | #include <net/if.h> | |
68 | #include <net/netisr.h> | |
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> | |
74 | ||
75 | #include <netinet/in.h> | |
76 | #include <netinet/in_var.h> | |
77 | #include <netinet/if_ether.h> | |
78 | #include <netinet/in_systm.h> | |
79 | #include <netinet/ip.h> | |
80 | ||
81 | #if INET6 | |
82 | #include <netinet6/nd6.h> | |
83 | #include <netinet6/in6_ifattach.h> | |
84 | #endif | |
85 | ||
86 | ||
87 | ||
88 | #include <sys/socketvar.h> | |
89 | #include <net/if_blue.h> | |
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 | ||
108 | ||
109 | extern struct ifnet_blue *blue_if; | |
110 | extern struct mbuf *splitter_input(struct mbuf *, struct ifnet *); | |
111 | ||
112 | static u_long lo_dlt = 0; | |
113 | static ivedonethis = 0; | |
114 | static u_char etherbroadcastaddr[6] = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff }; | |
115 | ||
116 | #define IFP2AC(IFP) ((struct arpcom *)IFP) | |
117 | ||
118 | ||
119 | ||
120 | ||
121 | /* | |
122 | * Process a received Ethernet packet; | |
123 | * the packet is in the mbuf chain m without | |
124 | * the ether header, which is provided separately. | |
125 | */ | |
126 | int | |
127 | inet6_ether_input(m, frame_header, ifp, dl_tag, sync_ok) | |
128 | struct mbuf *m; | |
129 | char *frame_header; | |
130 | struct ifnet *ifp; | |
131 | u_long dl_tag; | |
132 | int sync_ok; | |
133 | ||
134 | { | |
135 | register struct ether_header *eh = (struct ether_header *) frame_header; | |
136 | register struct ifqueue *inq=0; | |
137 | u_short ether_type; | |
138 | int s; | |
139 | u_int16_t ptype = -1; | |
140 | unsigned char buf[18]; | |
141 | ||
142 | ||
143 | ||
144 | if ((ifp->if_flags & IFF_UP) == 0) { | |
145 | m_freem(m); | |
146 | return EJUSTRETURN; | |
147 | } | |
148 | ||
149 | ifp->if_lastchange = time; | |
150 | ||
151 | if (eh->ether_dhost[0] & 1) { | |
152 | if (bcmp((caddr_t)etherbroadcastaddr, (caddr_t)eh->ether_dhost, | |
153 | sizeof(etherbroadcastaddr)) == 0) | |
154 | m->m_flags |= M_BCAST; | |
155 | else | |
156 | m->m_flags |= M_MCAST; | |
157 | } | |
158 | if (m->m_flags & (M_BCAST|M_MCAST)) | |
159 | ifp->if_imcasts++; | |
160 | ||
161 | ether_type = ntohs(eh->ether_type); | |
162 | ||
163 | ||
164 | switch (ether_type) { | |
165 | ||
166 | case ETHERTYPE_IPV6: | |
167 | schednetisr(NETISR_IPV6); | |
168 | inq = &ip6intrq; | |
169 | break; | |
170 | ||
171 | default: { | |
172 | return ENOENT; | |
173 | } | |
174 | } | |
175 | ||
176 | if (inq == 0) | |
177 | return ENOENT; | |
178 | ||
179 | s = splimp(); | |
180 | if (IF_QFULL(inq)) { | |
181 | IF_DROP(inq); | |
182 | m_freem(m); | |
183 | splx(s); | |
184 | return EJUSTRETURN; | |
185 | } else | |
186 | IF_ENQUEUE(inq, m); | |
187 | splx(s); | |
188 | ||
189 | ||
190 | return 0; | |
191 | } | |
192 | ||
193 | ||
194 | ||
195 | ||
196 | int | |
197 | inet6_ether_pre_output(ifp, m0, dst_netaddr, route, type, edst, dl_tag ) | |
198 | struct ifnet *ifp; | |
199 | struct mbuf **m0; | |
200 | struct sockaddr *dst_netaddr; | |
201 | caddr_t route; | |
202 | char *type; | |
203 | char *edst; | |
204 | u_long dl_tag; | |
205 | { | |
206 | struct rtentry *rt0 = (struct rtentry *) route; | |
207 | int s; | |
208 | register struct mbuf *m = *m0; | |
209 | register struct rtentry *rt; | |
210 | register struct ether_header *eh; | |
211 | int off, len = m->m_pkthdr.len; | |
212 | int hlen; /* link layer header lenght */ | |
213 | struct arpcom *ac = IFP2AC(ifp); | |
214 | ||
215 | ||
216 | ||
217 | if ((ifp->if_flags & (IFF_UP|IFF_RUNNING)) != (IFF_UP|IFF_RUNNING)) | |
218 | return ENETDOWN; | |
219 | ||
220 | rt = rt0; | |
221 | if (rt) { | |
222 | if ((rt->rt_flags & RTF_UP) == 0) { | |
223 | rt0 = rt = rtalloc1(dst_netaddr, 1, 0UL); | |
224 | if (rt0) | |
225 | rt->rt_refcnt--; | |
226 | else | |
227 | return EHOSTUNREACH; | |
228 | } | |
229 | ||
230 | if (rt->rt_flags & RTF_GATEWAY) { | |
231 | if (rt->rt_gwroute == 0) | |
232 | goto lookup; | |
233 | if (((rt = rt->rt_gwroute)->rt_flags & RTF_UP) == 0) { | |
234 | rtfree(rt); rt = rt0; | |
235 | lookup: rt->rt_gwroute = rtalloc1(rt->rt_gateway, 1, | |
236 | 0UL); | |
237 | if ((rt = rt->rt_gwroute) == 0) | |
238 | return (EHOSTUNREACH); | |
239 | } | |
240 | } | |
241 | ||
242 | ||
243 | if (rt->rt_flags & RTF_REJECT) | |
244 | if (rt->rt_rmx.rmx_expire == 0 || | |
245 | time_second < rt->rt_rmx.rmx_expire) | |
246 | return (rt == rt0 ? EHOSTDOWN : EHOSTUNREACH); | |
247 | } | |
248 | ||
249 | hlen = ETHER_HDR_LEN; | |
250 | ||
251 | /* | |
252 | * Tell ether_frameout it's ok to loop packet unless negated below. | |
253 | */ | |
254 | m->m_flags |= M_LOOP; | |
255 | ||
256 | switch (dst_netaddr->sa_family) { | |
257 | ||
258 | ||
259 | case AF_INET6: | |
260 | if (!nd6_storelladdr(&ac->ac_if, rt, m, dst_netaddr, (u_char *)edst)) { | |
261 | /* this must be impossible, so we bark */ | |
262 | printf("nd6_storelladdr failed\n"); | |
263 | return(0); | |
264 | } | |
265 | off = m->m_pkthdr.len - m->m_len; | |
266 | *(u_short *)type = htons(ETHERTYPE_IPV6); | |
267 | break; | |
268 | ||
269 | default: | |
270 | printf("%s%d: can't handle af%d\n", ifp->if_name, ifp->if_unit, | |
271 | dst_netaddr->sa_family); | |
272 | ||
273 | return EAFNOSUPPORT; | |
274 | } | |
275 | ||
276 | return (0); | |
277 | } | |
278 | ||
279 | ||
280 | int | |
281 | ether_inet6_prmod_ioctl(dl_tag, ifp, command, data) | |
282 | u_long dl_tag; | |
283 | struct ifnet *ifp; | |
284 | int command; | |
285 | caddr_t data; | |
286 | { | |
287 | struct ifaddr *ifa = (struct ifaddr *) data; | |
288 | struct ifreq *ifr = (struct ifreq *) data; | |
289 | struct rslvmulti_req *rsreq = (struct rslvmulti_req *) data; | |
290 | int error = 0; | |
291 | boolean_t funnel_state; | |
292 | struct arpcom *ac = (struct arpcom *) ifp; | |
293 | struct sockaddr_dl *sdl; | |
294 | struct sockaddr_in *sin; | |
295 | struct sockaddr_in6 *sin6; | |
296 | ||
297 | u_char *e_addr; | |
298 | ||
299 | ||
300 | funnel_state = thread_funnel_set(TRUE); | |
301 | ||
302 | switch (command) { | |
303 | case SIOCRSLVMULTI: { | |
304 | switch(rsreq->sa->sa_family) { | |
305 | ||
306 | case AF_INET6: | |
307 | sin6 = (struct sockaddr_in6 *)rsreq->sa; | |
308 | if (IN6_IS_ADDR_UNSPECIFIED(&sin6->sin6_addr)) { | |
309 | /* | |
310 | * An IP6 address of 0 means listen to all | |
311 | * of the Ethernet multicast address used for IP6. | |
312 | * (This is used for multicast routers.) | |
313 | */ | |
314 | ifp->if_flags |= IFF_ALLMULTI; | |
315 | *rsreq->llsa = 0; | |
316 | return 0; | |
317 | } | |
318 | MALLOC(sdl, struct sockaddr_dl *, sizeof *sdl, M_IFMADDR, | |
319 | M_WAITOK); | |
320 | sdl->sdl_len = sizeof *sdl; | |
321 | sdl->sdl_family = AF_LINK; | |
322 | sdl->sdl_index = ifp->if_index; | |
323 | sdl->sdl_type = IFT_ETHER; | |
324 | sdl->sdl_nlen = 0; | |
325 | sdl->sdl_alen = ETHER_ADDR_LEN; | |
326 | sdl->sdl_slen = 0; | |
327 | e_addr = LLADDR(sdl); | |
328 | ETHER_MAP_IPV6_MULTICAST(&sin6->sin6_addr, e_addr); | |
329 | printf("ether_resolvemulti AF_INET6 Adding %x:%x:%x:%x:%x:%x\n", | |
330 | e_addr[0], e_addr[1], e_addr[2], e_addr[3], e_addr[4], e_addr[5]); | |
331 | *rsreq->llsa = (struct sockaddr *)sdl; | |
332 | return 0; | |
333 | ||
334 | default: | |
335 | /* | |
336 | * Well, the text isn't quite right, but it's the name | |
337 | * that counts... | |
338 | */ | |
339 | return EAFNOSUPPORT; | |
340 | } | |
341 | ||
342 | } | |
343 | case SIOCSIFADDR: | |
344 | if ((ifp->if_flags & IFF_RUNNING) == 0) { | |
345 | ifp->if_flags |= IFF_UP; | |
346 | dlil_ioctl(0, ifp, SIOCSIFFLAGS, (caddr_t) 0); | |
347 | } | |
348 | ||
349 | break; | |
350 | ||
351 | case SIOCGIFADDR: | |
352 | { | |
353 | struct sockaddr *sa; | |
354 | ||
355 | sa = (struct sockaddr *) & ifr->ifr_data; | |
356 | bcopy(IFP2AC(ifp)->ac_enaddr, | |
357 | (caddr_t) sa->sa_data, ETHER_ADDR_LEN); | |
358 | } | |
359 | break; | |
360 | ||
361 | case SIOCSIFMTU: | |
362 | /* | |
363 | * Set the interface MTU. | |
364 | */ | |
365 | if (ifr->ifr_mtu > ETHERMTU) { | |
366 | error = EINVAL; | |
367 | } else { | |
368 | ifp->if_mtu = ifr->ifr_mtu; | |
369 | } | |
370 | break; | |
371 | ||
372 | default: | |
373 | return EOPNOTSUPP; | |
374 | } | |
375 | ||
376 | (void) thread_funnel_set(funnel_state); | |
377 | ||
378 | return (error); | |
379 | } | |
380 | ||
381 | ||
382 | ||
383 | ||
384 | ||
385 | u_long ether_attach_inet6(struct ifnet *ifp) | |
386 | { | |
387 | struct dlil_proto_reg_str reg; | |
388 | struct dlil_demux_desc desc; | |
389 | u_long ip_dl_tag=0; | |
390 | u_short en_6native=ETHERTYPE_IPV6; | |
391 | int stat; | |
392 | int i; | |
393 | ||
394 | ||
395 | stat = dlil_find_dltag(ifp->if_family, ifp->if_unit, PF_INET6, &ip_dl_tag); | |
396 | if (stat == 0) | |
397 | return ip_dl_tag; | |
398 | ||
399 | TAILQ_INIT(®.demux_desc_head); | |
400 | desc.type = DLIL_DESC_RAW; | |
401 | desc.variants.bitmask.proto_id_length = 0; | |
402 | desc.variants.bitmask.proto_id = 0; | |
403 | desc.variants.bitmask.proto_id_mask = 0; | |
404 | desc.native_type = (char *) &en_6native; | |
405 | TAILQ_INSERT_TAIL(®.demux_desc_head, &desc, next); | |
406 | reg.interface_family = ifp->if_family; | |
407 | reg.unit_number = ifp->if_unit; | |
408 | reg.input = inet6_ether_input; | |
409 | reg.pre_output = inet6_ether_pre_output; | |
410 | reg.event = 0; | |
411 | reg.offer = 0; | |
412 | reg.ioctl = ether_inet6_prmod_ioctl; | |
413 | reg.default_proto = 1; | |
414 | reg.protocol_family = PF_INET6; | |
415 | ||
416 | stat = dlil_attach_protocol(®, &ip_dl_tag); | |
417 | if (stat) { | |
418 | printf("WARNING: ether_attach_inet6 can't attach ip to interface\n"); | |
419 | return stat; | |
420 | } | |
421 | ||
422 | return ip_dl_tag; | |
423 | } |