2 * Copyright (c) 2000 Apple Computer, Inc. All rights reserved.
4 * @APPLE_LICENSE_HEADER_START@
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.
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
20 * @APPLE_LICENSE_HEADER_END@
23 * Copyright (c) 1982, 1989, 1993
24 * The Regents of the University of California. All rights reserved.
26 * Redistribution and use in source and binary forms, with or without
27 * modification, are permitted provided that the following conditions
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.
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
58 #include <sys/param.h>
59 #include <sys/systm.h>
60 #include <sys/kernel.h>
61 #include <sys/malloc.h>
63 #include <sys/socket.h>
64 #include <sys/sockio.h>
65 #include <sys/sysctl.h>
66 #include <kern/lock.h>
69 #include <net/route.h>
70 #include <net/if_llc.h>
71 #include <net/if_dl.h>
72 #include <net/if_types.h>
74 #include <net/kpi_protocol.h>
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>
83 #include <netinet6/nd6.h>
84 #include <netinet6/in6_ifattach.h>
89 #include <sys/socketvar.h>
95 extern struct ifqueue pkintrq
;
100 #include <net/bridge.h>
103 /* #include "vlan.h" */
105 #include <net/if_vlan_var.h>
106 #endif /* NVLAN > 0 */
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
);
113 * Process a received Ethernet packet;
114 * the packet is in the mbuf chain m without
115 * the ether header, which is provided separately.
119 __unused ifnet_t ifp
,
120 protocol_family_t protocol
,
122 __unused
char *header
)
124 proto_input(protocol
, packet
);
129 inet6_ether_pre_output(
131 __unused protocol_family_t protocol_family
,
133 const struct sockaddr
*dst_netaddr
,
139 struct sockaddr_dl sdl
;
140 register struct mbuf
*m
= *m0
;
143 * Tell ether_frameout it's ok to loop packet if necessary
145 m
->m_flags
|= M_LOOP
;
147 result
= nd6_lookup_ipv6(ifp
, (const struct sockaddr_in6
*)dst_netaddr
,
148 &sdl
, sizeof(sdl
), route
, *m0
);
151 *(u_int16_t
*)type
= htons(ETHERTYPE_IPV6
);
152 bcopy(LLADDR(&sdl
), edst
, sdl
.sdl_alen
);
161 ether_inet6_resolve_multi(
163 const struct sockaddr
*proto_addr
,
164 struct sockaddr_dl
*out_ll
,
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
;
170 if (proto_addr
->sa_family
!= AF_INET6
)
173 if (proto_addr
->sa_len
< sizeof(struct sockaddr_in6
))
176 if (ll_len
< minsize
)
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
));
194 ether_inet6_prmod_ioctl(
196 __unused protocol_family_t protocol_family
,
200 struct ifreq
*ifr
= (struct ifreq
*) data
;
205 if ((ifp
->if_flags
& IFF_RUNNING
) == 0) {
206 ifnet_set_flags(ifp
, IFF_UP
, IFF_UP
);
207 dlil_ioctl(0, ifp
, SIOCSIFFLAGS
, (caddr_t
) 0);
213 ifnet_lladdr_copy_bytes(ifp
, ifr
->ifr_addr
.sa_data
, ETHER_ADDR_LEN
);
218 * IOKit IONetworkFamily will set the right MTU according to the driver
233 __unused u_long protocol_family
)
235 struct ifnet_attach_proto_param proto
;
236 struct ifnet_demux_desc demux
[1];
237 u_short en_6native
=htons(ETHERTYPE_IPV6
);
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
);
262 u_long protocol_family
)
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
);