2 * Copyright (c) 2000 Apple Computer, Inc. All rights reserved.
4 * @APPLE_LICENSE_OSREFERENCE_HEADER_START@
6 * This file contains Original Code and/or Modifications of Original Code
7 * as defined in and that are subject to the Apple Public Source License
8 * Version 2.0 (the 'License'). You may not use this file except in
9 * compliance with the License. The rights granted to you under the
10 * License may not be used to create, or enable the creation or
11 * redistribution of, unlawful or unlicensed copies of an Apple operating
12 * system, or to circumvent, violate, or enable the circumvention or
13 * violation of, any terms of an Apple operating system software license
16 * Please obtain a copy of the License at
17 * http://www.opensource.apple.com/apsl/ and read it before using this
20 * The Original Code and all software distributed under the License are
21 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
22 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
23 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
24 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
25 * Please see the License for the specific language governing rights and
26 * limitations under the License.
28 * @APPLE_LICENSE_OSREFERENCE_HEADER_END@
31 * Copyright (c) 1982, 1989, 1993
32 * The Regents of the University of California. All rights reserved.
34 * Redistribution and use in source and binary forms, with or without
35 * modification, are permitted provided that the following conditions
37 * 1. Redistributions of source code must retain the above copyright
38 * notice, this list of conditions and the following disclaimer.
39 * 2. Redistributions in binary form must reproduce the above copyright
40 * notice, this list of conditions and the following disclaimer in the
41 * documentation and/or other materials provided with the distribution.
42 * 3. All advertising materials mentioning features or use of this software
43 * must display the following acknowledgement:
44 * This product includes software developed by the University of
45 * California, Berkeley and its contributors.
46 * 4. Neither the name of the University nor the names of its contributors
47 * may be used to endorse or promote products derived from this software
48 * without specific prior written permission.
50 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
51 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
52 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
53 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
54 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
55 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
56 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
57 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
58 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
59 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
66 #include <sys/param.h>
67 #include <sys/systm.h>
68 #include <sys/kernel.h>
69 #include <sys/malloc.h>
71 #include <sys/socket.h>
72 #include <sys/sockio.h>
73 #include <sys/sysctl.h>
74 #include <kern/lock.h>
77 #include <net/route.h>
78 #include <net/if_llc.h>
79 #include <net/if_dl.h>
80 #include <net/if_types.h>
82 #include <net/kpi_protocol.h>
84 #include <netinet/in.h>
85 #include <netinet/in_var.h>
86 #include <netinet/if_ether.h>
87 #include <netinet/in_systm.h>
88 #include <netinet/ip.h>
91 #include <netinet6/nd6.h>
92 #include <netinet6/in6_ifattach.h>
97 #include <sys/socketvar.h>
103 extern struct ifqueue pkintrq
;
108 #include <net/bridge.h>
111 /* #include "vlan.h" */
113 #include <net/if_vlan_var.h>
114 #endif /* NVLAN > 0 */
116 /* Local function declerations */
117 int ether_attach_inet6(struct ifnet
*ifp
, u_long protocol_family
);
118 int ether_detach_inet6(struct ifnet
*ifp
, u_long protocol_family
);
121 * Process a received Ethernet packet;
122 * the packet is in the mbuf chain m without
123 * the ether header, which is provided separately.
127 __unused ifnet_t ifp
,
128 protocol_family_t protocol
,
130 __unused
char *header
)
132 proto_input(protocol
, packet
);
137 inet6_ether_pre_output(
139 __unused protocol_family_t protocol_family
,
141 const struct sockaddr
*dst_netaddr
,
147 struct sockaddr_dl sdl
;
148 register struct mbuf
*m
= *m0
;
151 * Tell ether_frameout it's ok to loop packet if necessary
153 m
->m_flags
|= M_LOOP
;
155 result
= nd6_lookup_ipv6(ifp
, (const struct sockaddr_in6
*)dst_netaddr
,
156 &sdl
, sizeof(sdl
), route
, *m0
);
159 *(u_int16_t
*)type
= htons(ETHERTYPE_IPV6
);
160 bcopy(LLADDR(&sdl
), edst
, sdl
.sdl_alen
);
169 ether_inet6_resolve_multi(
171 const struct sockaddr
*proto_addr
,
172 struct sockaddr_dl
*out_ll
,
175 static const size_t minsize
= offsetof(struct sockaddr_dl
, sdl_data
[0]) + ETHER_ADDR_LEN
;
176 const struct sockaddr_in6
*sin6
= (const struct sockaddr_in6
*)proto_addr
;
178 if (proto_addr
->sa_family
!= AF_INET6
)
181 if (proto_addr
->sa_len
< sizeof(struct sockaddr_in6
))
184 if (ll_len
< minsize
)
187 bzero(out_ll
, minsize
);
188 out_ll
->sdl_len
= minsize
;
189 out_ll
->sdl_family
= AF_LINK
;
190 out_ll
->sdl_index
= ifp
->if_index
;
191 out_ll
->sdl_type
= IFT_ETHER
;
192 out_ll
->sdl_nlen
= 0;
193 out_ll
->sdl_alen
= ETHER_ADDR_LEN
;
194 out_ll
->sdl_slen
= 0;
195 ETHER_MAP_IPV6_MULTICAST(&sin6
->sin6_addr
, LLADDR(out_ll
));
202 ether_inet6_prmod_ioctl(
204 __unused protocol_family_t protocol_family
,
208 struct ifreq
*ifr
= (struct ifreq
*) data
;
213 if ((ifp
->if_flags
& IFF_RUNNING
) == 0) {
214 ifnet_set_flags(ifp
, IFF_UP
, IFF_UP
);
215 dlil_ioctl(0, ifp
, SIOCSIFFLAGS
, (caddr_t
) 0);
221 ifnet_lladdr_copy_bytes(ifp
, ifr
->ifr_addr
.sa_data
, ETHER_ADDR_LEN
);
226 * IOKit IONetworkFamily will set the right MTU according to the driver
241 __unused u_long protocol_family
)
243 struct ifnet_attach_proto_param proto
;
244 struct ifnet_demux_desc demux
[1];
245 u_short en_6native
=htons(ETHERTYPE_IPV6
);
248 bzero(&proto
, sizeof(proto
));
249 demux
[0].type
= DLIL_DESC_ETYPE2
;
250 demux
[0].data
= &en_6native
;
251 demux
[0].datalen
= sizeof(en_6native
);
252 proto
.demux_list
= demux
;
253 proto
.demux_count
= 1;
254 proto
.input
= inet6_ether_input
;
255 proto
.pre_output
= inet6_ether_pre_output
;
256 proto
.ioctl
= ether_inet6_prmod_ioctl
;
257 proto
.resolve
= ether_inet6_resolve_multi
;
258 error
= ifnet_attach_protocol(ifp
, protocol_family
, &proto
);
259 if (error
&& error
!= EEXIST
) {
260 printf("WARNING: ether_attach_inet6 can't attach ipv6 to %s%d\n",
261 ifp
->if_name
, ifp
->if_unit
);
270 u_long protocol_family
)
274 error
= ifnet_detach_protocol(ifp
, protocol_family
);
275 if (error
&& error
!= ENOENT
) {
276 printf("WARNING: ether_detach_inet6 can't detach ipv6 from %s%d\n",
277 ifp
->if_name
, ifp
->if_unit
);