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>
76 #include <net/route.h>
77 #include <net/if_llc.h>
78 #include <net/if_dl.h>
79 #include <net/if_types.h>
80 #include <netinet/if_ether.h>
82 #include <sys/socketvar.h>
85 #include <netat/at_pat.h>
87 extern struct ifqueue atalkintrq
;
92 #include <net/bridge.h>
95 /* #include "vlan.h" */
97 #include <net/if_vlan_var.h>
98 #endif /* NVLAN > 0 */
100 struct dl_es_at_entry
106 /* Local fuction declerations */
107 int at_ether_input(struct mbuf
*m
, char *frame_header
, struct ifnet
*ifp
,
108 u_long protocol_family
, int sync_ok
);
109 int ether_pre_output(struct ifnet
*ifp
, u_long protocol_family
, struct mbuf
**m0
,
110 const struct sockaddr
*dst_netaddr
, caddr_t route
, char *type
, char *edst
);
111 int ether_prmod_ioctl(u_long protocol_family
, struct ifnet
*ifp
, u_long command
,
113 int ether_attach_at(struct ifnet
*ifp
);
114 void ether_detach_at(struct ifnet
*ifp
);
118 * Temp static for protocol registration XXX
121 #define MAX_EN_COUNT 30
123 static struct dl_es_at_entry en_at_array
[MAX_EN_COUNT
];
126 * Process a received Ethernet packet;
127 * the packet is in the mbuf chain m without
128 * the ether header, which is provided separately.
133 __unused
char *frame_header
,
134 __unused
struct ifnet
*ifp
,
135 __unused u_long protocol_family
,
136 __unused
int sync_ok
)
140 * note: for AppleTalk we need to pass the enet header of the
141 * packet up stack. To do so, we made sure in that the FULL packet
142 * is copied in the mbuf by the mace driver, and only the m_data and
143 * length have been shifted to make IP and the other guys happy.
146 m
->m_data
-= sizeof(struct ether_header
);
147 m
->m_len
+= sizeof(struct ether_header
);
148 m
->m_pkthdr
.len
+= sizeof(struct ether_header
);
149 proto_input(PF_APPLETALK
, m
);
159 __unused u_long protocol_family
,
161 const struct sockaddr
*dst_netaddr
,
162 __unused caddr_t route
,
166 register struct mbuf
*m
= *m0
;
167 register struct ether_header
*eh
;
168 int hlen
; /* link layer header lenght */
172 if ((ifp
->if_flags
& (IFF_UP
|IFF_RUNNING
)) != (IFF_UP
|IFF_RUNNING
))
175 hlen
= ETHER_HDR_LEN
;
178 * Tell ether_frameout it's ok to loop packet unless negated below.
180 m
->m_flags
|= M_LOOP
;
182 switch (dst_netaddr
->sa_family
) {
184 m
->m_flags
&= ~M_LOOP
;
185 eh
= (struct ether_header
*)dst_netaddr
->sa_data
;
186 (void)memcpy(edst
, eh
->ether_dhost
, 6);
187 *(u_short
*)type
= eh
->ether_type
;
193 eh
= (struct ether_header
*)dst_netaddr
->sa_data
;
194 bcopy((caddr_t
)eh
->ether_dhost
, (caddr_t
)edst
, 6);
196 *(u_short
*)type
= htons(m
->m_pkthdr
.len
);
202 kprintf("%s%d: can't handle af%d\n", ifp
->if_name
, ifp
->if_unit
,
203 dst_netaddr
->sa_family
);
217 __unused u_long protocol_family
,
222 struct ifreq
*ifr
= (struct ifreq
*) data
;
228 if ((ifp
->if_flags
& IFF_RUNNING
) == 0) {
229 ifnet_set_flags(ifp
, IFF_UP
, IFF_UP
);
230 dlil_ioctl(0, ifp
, SIOCSIFFLAGS
, (caddr_t
) 0);
236 ifnet_lladdr_copy_bytes(ifp
, ifr
->ifr_addr
.sa_data
, ETHER_ADDR_LEN
);
241 * Set the interface MTU.
243 if (ifr
->ifr_mtu
> ETHERMTU
) {
246 ifp
->if_mtu
= ifr
->ifr_mtu
;
264 struct dlil_proto_reg_str reg
;
265 struct dlil_demux_desc desc
;
266 struct dlil_demux_desc desc2
;
270 u_int8_t atalk_snap
[5] = {0x08, 0x00, 0x07, 0x80, 0x9b};
271 u_int8_t aarp_snap
[5] = {0x00, 0x00, 0x00, 0x80, 0xf3};
273 first_empty
= MAX_EN_COUNT
;
274 for (i
=0; i
< MAX_EN_COUNT
; i
++) {
275 if (en_at_array
[i
].ifp
== 0)
278 if (en_at_array
[i
].ifp
== ifp
) {
279 en_at_array
[i
].ref_count
++;
284 if (first_empty
== MAX_EN_COUNT
)
287 bzero(®
, sizeof(reg
));
288 bzero(&desc
, sizeof(desc
));
289 bzero(&desc2
, sizeof(desc2
));
291 TAILQ_INIT(®
.demux_desc_head
);
292 reg
.interface_family
= ifp
->if_family
;
293 reg
.unit_number
= ifp
->if_unit
;
294 reg
.input
= at_ether_input
;
295 reg
.pre_output
= ether_pre_output
;
296 reg
.ioctl
= ether_prmod_ioctl
;
297 reg
.protocol_family
= PF_APPLETALK
;
299 desc
.type
= DLIL_DESC_SNAP
;
300 desc
.native_type
= atalk_snap
;
301 desc
.variants
.native_type_length
= sizeof(atalk_snap
);
302 TAILQ_INSERT_TAIL(®
.demux_desc_head
, &desc
, next
);
304 desc2
.type
= DLIL_DESC_SNAP
;
305 desc2
.native_type
= aarp_snap
;
306 desc2
.variants
.native_type_length
= sizeof(aarp_snap
);
307 TAILQ_INSERT_TAIL(®
.demux_desc_head
, &desc2
, next
);
309 stat
= dlil_attach_protocol(®
);
311 printf("WARNING: ether_attach_at can't attach at to interface\n");
315 en_at_array
[first_empty
].ifp
= ifp
;
316 en_at_array
[first_empty
].ref_count
= 1;
319 } /* ether_attach_at */
323 ether_detach_at(struct ifnet
*ifp
)
327 for (i
=0; i
< MAX_EN_COUNT
; i
++) {
328 if (en_at_array
[i
].ifp
== ifp
)
332 if (i
< MAX_EN_COUNT
) {
333 if (en_at_array
[i
].ref_count
> 1)
334 en_at_array
[i
].ref_count
--;
336 if (en_at_array
[i
].ref_count
== 1) {
337 dlil_detach_protocol(ifp
, PF_APPLETALK
);
338 en_at_array
[i
].ifp
= 0;