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
55 * @(#)if_ethersubr.c 8.1 (Berkeley) 6/10/93
56 * $FreeBSD: src/sys/net/if_ethersubr.c,v 1.70.2.17 2001/08/01 00:47:49 fenner Exp $
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>
69 #include <net/route.h>
70 #include <net/if_llc.h>
71 #include <net/if_dl.h>
72 #include <net/if_types.h>
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>
83 #include <netipx/ipx.h>
84 #include <netipx/ipx_if.h>
87 #include <sys/socketvar.h>
90 extern struct ifqueue pkintrq
;
94 #include <net/bridge.h>
97 /* #include "vlan.h" */
99 #include <net/if_vlan_var.h>
100 #endif /* NVLAN > 0 */
102 extern u_char etherbroadcastaddr
[];
103 #define senderr(e) do { error = (e); goto bad;} while (0)
106 * Perform common duties while attaching to interface list
112 struct sockaddr
**llsa
,
115 struct sockaddr_dl
*sdl
;
116 struct sockaddr_in
*sin
;
119 struct sockaddr_in6
*sin6
;
123 switch(sa
->sa_family
) {
125 /* AppleTalk uses AF_UNSPEC for multicast registration.
126 * No mapping needed. Just check that it's a valid MC address.
128 e_addr
= &sa
->sa_data
[0];
129 if ((e_addr
[0] & 1) != 1)
130 return EADDRNOTAVAIL
;
136 * No mapping needed. Just check that it's a valid MC address.
138 sdl
= (struct sockaddr_dl
*)sa
;
139 e_addr
= LLADDR(sdl
);
140 if ((e_addr
[0] & 1) != 1)
141 return EADDRNOTAVAIL
;
147 sin
= (struct sockaddr_in
*)sa
;
148 if (!IN_MULTICAST(ntohl(sin
->sin_addr
.s_addr
)))
149 return EADDRNOTAVAIL
;
150 MALLOC(sdl
, struct sockaddr_dl
*, sizeof *sdl
, M_IFMADDR
,
152 sdl
->sdl_len
= sizeof *sdl
;
153 sdl
->sdl_family
= AF_LINK
;
154 sdl
->sdl_index
= ifp
->if_index
;
155 sdl
->sdl_type
= IFT_ETHER
;
157 sdl
->sdl_alen
= ETHER_ADDR_LEN
;
159 e_addr
= LLADDR(sdl
);
160 ETHER_MAP_IP_MULTICAST(&sin
->sin_addr
, e_addr
);
161 *llsa
= (struct sockaddr
*)sdl
;
166 sin6
= (struct sockaddr_in6
*)sa
;
167 if (IN6_IS_ADDR_UNSPECIFIED(&sin6
->sin6_addr
)) {
169 * An IP6 address of 0 means listen to all
170 * of the Ethernet multicast address used for IP6.
171 * (This is used for multicast routers.)
173 ifp
->if_flags
|= IFF_ALLMULTI
;
177 MALLOC(sdl
, struct sockaddr_dl
*, sizeof *sdl
, M_IFMADDR
,
179 sdl
->sdl_len
= sizeof *sdl
;
180 sdl
->sdl_family
= AF_LINK
;
181 sdl
->sdl_index
= ifp
->if_index
;
182 sdl
->sdl_type
= IFT_ETHER
;
184 sdl
->sdl_alen
= ETHER_ADDR_LEN
;
186 e_addr
= LLADDR(sdl
);
187 ETHER_MAP_IPV6_MULTICAST(&sin6
->sin6_addr
, e_addr
);
188 kprintf("ether_resolvemulti Adding %x:%x:%x:%x:%x:%x\n",
189 e_addr
[0], e_addr
[1], e_addr
[2], e_addr
[3], e_addr
[4], e_addr
[5]);
190 *llsa
= (struct sockaddr
*)sdl
;
196 * Well, the text isn't quite right, but it's the name
205 * Convert Ethernet address to printable (loggable) representation.
207 static u_char digits
[] = "0123456789abcdef";
215 for (cp
= p
, i
= 0; i
< 6; i
++) {
216 *cp
++ = digits
[*ap
>> 4];
217 *cp
++ = digits
[*ap
++ & 0xf];