2 * Copyright (c) 2000 Apple Computer, Inc. All rights reserved.
4 * @APPLE_LICENSE_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. Please obtain a copy of the License at
10 * http://www.opensource.apple.com/apsl/ and read it before using this
13 * The Original Code and all software distributed under the License are
14 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
15 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
16 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
18 * Please see the License for the specific language governing rights and
19 * limitations under the License.
21 * @APPLE_LICENSE_HEADER_END@
24 * Copyright (c) 1982, 1989, 1993
25 * The Regents of the University of California. All rights reserved.
27 * Redistribution and use in source and binary forms, with or without
28 * modification, are permitted provided that the following conditions
30 * 1. Redistributions of source code must retain the above copyright
31 * notice, this list of conditions and the following disclaimer.
32 * 2. Redistributions in binary form must reproduce the above copyright
33 * notice, this list of conditions and the following disclaimer in the
34 * documentation and/or other materials provided with the distribution.
35 * 3. All advertising materials mentioning features or use of this software
36 * must display the following acknowledgement:
37 * This product includes software developed by the University of
38 * California, Berkeley and its contributors.
39 * 4. Neither the name of the University nor the names of its contributors
40 * may be used to endorse or promote products derived from this software
41 * without specific prior written permission.
43 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
44 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
45 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
46 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
47 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
48 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
49 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
50 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
51 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
52 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
59 #include <sys/param.h>
60 #include <sys/systm.h>
61 #include <sys/kernel.h>
62 #include <sys/malloc.h>
64 #include <sys/socket.h>
65 #include <sys/sockio.h>
66 #include <sys/sysctl.h>
67 #include <kern/lock.h>
70 #include <net/route.h>
71 #include <net/if_llc.h>
72 #include <net/if_dl.h>
73 #include <net/if_types.h>
75 #include <net/kpi_protocol.h>
77 #include <netinet/in.h>
78 #include <netinet/in_var.h>
79 #include <netinet/if_ether.h>
80 #include <netinet/in_systm.h>
81 #include <netinet/ip.h>
84 #include <netinet6/nd6.h>
85 #include <netinet6/in6_ifattach.h>
90 #include <sys/socketvar.h>
96 extern struct ifqueue pkintrq
;
101 #include <net/bridge.h>
104 /* #include "vlan.h" */
106 #include <net/if_vlan_var.h>
107 #endif /* NVLAN > 0 */
109 /* Local function declerations */
110 int ether_attach_inet6(struct ifnet
*ifp
, u_long protocol_family
);
111 int ether_detach_inet6(struct ifnet
*ifp
, u_long protocol_family
);
114 * Process a received Ethernet packet;
115 * the packet is in the mbuf chain m without
116 * the ether header, which is provided separately.
120 __unused ifnet_t ifp
,
121 protocol_family_t protocol
,
123 __unused
char *header
)
125 proto_input(protocol
, packet
);
130 inet6_ether_pre_output(
132 __unused protocol_family_t protocol_family
,
134 const struct sockaddr
*dst_netaddr
,
140 struct sockaddr_dl sdl
;
141 register struct mbuf
*m
= *m0
;
144 * Tell ether_frameout it's ok to loop packet if necessary
146 m
->m_flags
|= M_LOOP
;
148 result
= nd6_lookup_ipv6(ifp
, (const struct sockaddr_in6
*)dst_netaddr
,
149 &sdl
, sizeof(sdl
), route
, *m0
);
152 *(u_int16_t
*)type
= htons(ETHERTYPE_IPV6
);
153 bcopy(LLADDR(&sdl
), edst
, sdl
.sdl_alen
);
162 ether_inet6_resolve_multi(
164 const struct sockaddr
*proto_addr
,
165 struct sockaddr_dl
*out_ll
,
168 static const size_t minsize
= offsetof(struct sockaddr_dl
, sdl_data
[0]) + ETHER_ADDR_LEN
;
169 const struct sockaddr_in6
*sin6
= (const struct sockaddr_in6
*)proto_addr
;
171 if (proto_addr
->sa_family
!= AF_INET6
)
174 if (proto_addr
->sa_len
< sizeof(struct sockaddr_in6
))
177 if (ll_len
< minsize
)
180 bzero(out_ll
, minsize
);
181 out_ll
->sdl_len
= minsize
;
182 out_ll
->sdl_family
= AF_LINK
;
183 out_ll
->sdl_index
= ifp
->if_index
;
184 out_ll
->sdl_type
= IFT_ETHER
;
185 out_ll
->sdl_nlen
= 0;
186 out_ll
->sdl_alen
= ETHER_ADDR_LEN
;
187 out_ll
->sdl_slen
= 0;
188 ETHER_MAP_IPV6_MULTICAST(&sin6
->sin6_addr
, LLADDR(out_ll
));
195 ether_inet6_prmod_ioctl(
197 __unused protocol_family_t protocol_family
,
201 struct ifreq
*ifr
= (struct ifreq
*) data
;
206 if ((ifp
->if_flags
& IFF_RUNNING
) == 0) {
207 ifnet_set_flags(ifp
, IFF_UP
, IFF_UP
);
208 dlil_ioctl(0, ifp
, SIOCSIFFLAGS
, (caddr_t
) 0);
214 ifnet_lladdr_copy_bytes(ifp
, ifr
->ifr_addr
.sa_data
, ETHER_ADDR_LEN
);
219 * IOKit IONetworkFamily will set the right MTU according to the driver
234 __unused u_long protocol_family
)
236 struct ifnet_attach_proto_param proto
;
237 struct ifnet_demux_desc demux
[1];
238 u_short en_6native
=htons(ETHERTYPE_IPV6
);
241 bzero(&proto
, sizeof(proto
));
242 demux
[0].type
= DLIL_DESC_ETYPE2
;
243 demux
[0].data
= &en_6native
;
244 demux
[0].datalen
= sizeof(en_6native
);
245 proto
.demux_list
= demux
;
246 proto
.demux_count
= 1;
247 proto
.input
= inet6_ether_input
;
248 proto
.pre_output
= inet6_ether_pre_output
;
249 proto
.ioctl
= ether_inet6_prmod_ioctl
;
250 proto
.resolve
= ether_inet6_resolve_multi
;
251 error
= ifnet_attach_protocol(ifp
, protocol_family
, &proto
);
252 if (error
&& error
!= EEXIST
) {
253 printf("WARNING: ether_attach_inet6 can't attach ipv6 to %s%d\n",
254 ifp
->if_name
, ifp
->if_unit
);
263 u_long protocol_family
)
267 error
= ifnet_detach_protocol(ifp
, protocol_family
);
268 if (error
&& error
!= ENOENT
) {
269 printf("WARNING: ether_detach_inet6 can't detach ipv6 from %s%d\n",
270 ifp
->if_name
, ifp
->if_unit
);