2 * Copyright (c) 2000 Apple Computer, Inc. All rights reserved.
4 * @APPLE_OSREFERENCE_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. The rights granted to you under the License
10 * may not be used to create, or enable the creation or redistribution of,
11 * unlawful or unlicensed copies of an Apple operating system, or to
12 * circumvent, violate, or enable the circumvention or violation of, any
13 * terms of an Apple operating system software license agreement.
15 * Please obtain a copy of the License at
16 * http://www.opensource.apple.com/apsl/ and read it before using this file.
18 * The Original Code and all software distributed under the License are
19 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
20 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
21 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
22 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
23 * Please see the License for the specific language governing rights and
24 * limitations under the License.
26 * @APPLE_OSREFERENCE_LICENSE_HEADER_END@
29 * Copyright (c) 1982, 1989, 1993
30 * The Regents of the University of California. All rights reserved.
32 * Redistribution and use in source and binary forms, with or without
33 * modification, are permitted provided that the following conditions
35 * 1. Redistributions of source code must retain the above copyright
36 * notice, this list of conditions and the following disclaimer.
37 * 2. Redistributions in binary form must reproduce the above copyright
38 * notice, this list of conditions and the following disclaimer in the
39 * documentation and/or other materials provided with the distribution.
40 * 3. All advertising materials mentioning features or use of this software
41 * must display the following acknowledgement:
42 * This product includes software developed by the University of
43 * California, Berkeley and its contributors.
44 * 4. Neither the name of the University nor the names of its contributors
45 * may be used to endorse or promote products derived from this software
46 * without specific prior written permission.
48 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
49 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
50 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
51 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
52 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
53 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
54 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
55 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
56 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
57 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
64 #include <sys/param.h>
65 #include <sys/systm.h>
66 #include <sys/kernel.h>
67 #include <sys/malloc.h>
69 #include <sys/socket.h>
70 #include <sys/sockio.h>
71 #include <sys/sysctl.h>
72 #include <kern/lock.h>
75 #include <net/route.h>
76 #include <net/if_llc.h>
77 #include <net/if_dl.h>
78 #include <net/if_types.h>
80 #include <net/kpi_protocol.h>
82 #include <netinet/in.h>
83 #include <netinet/in_var.h>
84 #include <netinet/if_ether.h>
85 #include <netinet/in_systm.h>
86 #include <netinet/ip.h>
89 #include <netinet6/nd6.h>
90 #include <netinet6/in6_ifattach.h>
95 #include <sys/socketvar.h>
101 extern struct ifqueue pkintrq
;
106 #include <net/bridge.h>
109 /* #include "vlan.h" */
111 #include <net/if_vlan_var.h>
112 #endif /* NVLAN > 0 */
114 /* Local function declerations */
115 int ether_attach_inet6(struct ifnet
*ifp
, u_long protocol_family
);
116 int ether_detach_inet6(struct ifnet
*ifp
, u_long protocol_family
);
119 * Process a received Ethernet packet;
120 * the packet is in the mbuf chain m without
121 * the ether header, which is provided separately.
125 __unused ifnet_t ifp
,
126 protocol_family_t protocol
,
128 __unused
char *header
)
130 proto_input(protocol
, packet
);
135 inet6_ether_pre_output(
137 __unused protocol_family_t protocol_family
,
139 const struct sockaddr
*dst_netaddr
,
145 struct sockaddr_dl sdl
;
146 register struct mbuf
*m
= *m0
;
149 * Tell ether_frameout it's ok to loop packet if necessary
151 m
->m_flags
|= M_LOOP
;
153 result
= nd6_lookup_ipv6(ifp
, (const struct sockaddr_in6
*)dst_netaddr
,
154 &sdl
, sizeof(sdl
), route
, *m0
);
157 *(u_int16_t
*)type
= htons(ETHERTYPE_IPV6
);
158 bcopy(LLADDR(&sdl
), edst
, sdl
.sdl_alen
);
167 ether_inet6_resolve_multi(
169 const struct sockaddr
*proto_addr
,
170 struct sockaddr_dl
*out_ll
,
173 static const size_t minsize
= offsetof(struct sockaddr_dl
, sdl_data
[0]) + ETHER_ADDR_LEN
;
174 const struct sockaddr_in6
*sin6
= (const struct sockaddr_in6
*)proto_addr
;
176 if (proto_addr
->sa_family
!= AF_INET6
)
179 if (proto_addr
->sa_len
< sizeof(struct sockaddr_in6
))
182 if (ll_len
< minsize
)
185 bzero(out_ll
, minsize
);
186 out_ll
->sdl_len
= minsize
;
187 out_ll
->sdl_family
= AF_LINK
;
188 out_ll
->sdl_index
= ifp
->if_index
;
189 out_ll
->sdl_type
= IFT_ETHER
;
190 out_ll
->sdl_nlen
= 0;
191 out_ll
->sdl_alen
= ETHER_ADDR_LEN
;
192 out_ll
->sdl_slen
= 0;
193 ETHER_MAP_IPV6_MULTICAST(&sin6
->sin6_addr
, LLADDR(out_ll
));
200 ether_inet6_prmod_ioctl(
202 __unused protocol_family_t protocol_family
,
206 struct ifreq
*ifr
= (struct ifreq
*) data
;
211 if ((ifp
->if_flags
& IFF_RUNNING
) == 0) {
212 ifnet_set_flags(ifp
, IFF_UP
, IFF_UP
);
213 dlil_ioctl(0, ifp
, SIOCSIFFLAGS
, (caddr_t
) 0);
219 ifnet_lladdr_copy_bytes(ifp
, ifr
->ifr_addr
.sa_data
, ETHER_ADDR_LEN
);
224 * IOKit IONetworkFamily will set the right MTU according to the driver
239 __unused u_long protocol_family
)
241 struct ifnet_attach_proto_param proto
;
242 struct ifnet_demux_desc demux
[1];
243 u_short en_6native
=htons(ETHERTYPE_IPV6
);
246 bzero(&proto
, sizeof(proto
));
247 demux
[0].type
= DLIL_DESC_ETYPE2
;
248 demux
[0].data
= &en_6native
;
249 demux
[0].datalen
= sizeof(en_6native
);
250 proto
.demux_list
= demux
;
251 proto
.demux_count
= 1;
252 proto
.input
= inet6_ether_input
;
253 proto
.pre_output
= inet6_ether_pre_output
;
254 proto
.ioctl
= ether_inet6_prmod_ioctl
;
255 proto
.resolve
= ether_inet6_resolve_multi
;
256 error
= ifnet_attach_protocol(ifp
, protocol_family
, &proto
);
257 if (error
&& error
!= EEXIST
) {
258 printf("WARNING: ether_attach_inet6 can't attach ipv6 to %s%d\n",
259 ifp
->if_name
, ifp
->if_unit
);
268 u_long protocol_family
)
272 error
= ifnet_detach_protocol(ifp
, protocol_family
);
273 if (error
&& error
!= ENOENT
) {
274 printf("WARNING: ether_detach_inet6 can't detach ipv6 from %s%d\n",
275 ifp
->if_name
, ifp
->if_unit
);