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>
69 #include <net/route.h>
70 #include <net/if_llc.h>
71 #include <net/if_dl.h>
72 #include <net/if_types.h>
73 #include <netinet/if_ether.h>
75 #include <sys/socketvar.h>
78 #include <netat/at_pat.h>
80 extern struct ifqueue atalkintrq
;
85 #include <net/bridge.h>
88 /* #include "vlan.h" */
90 #include <net/if_vlan_var.h>
91 #endif /* NVLAN > 0 */
99 /* Local fuction declerations */
100 int at_ether_input(struct mbuf
*m
, char *frame_header
, struct ifnet
*ifp
,
101 u_long protocol_family
, int sync_ok
);
102 int ether_pre_output(struct ifnet
*ifp
, u_long protocol_family
, struct mbuf
**m0
,
103 const struct sockaddr
*dst_netaddr
, caddr_t route
, char *type
, char *edst
);
104 int ether_prmod_ioctl(u_long protocol_family
, struct ifnet
*ifp
, u_long command
,
106 int ether_attach_at(struct ifnet
*ifp
);
107 void ether_detach_at(struct ifnet
*ifp
);
111 * Temp static for protocol registration XXX
114 #define MAX_EN_COUNT 30
116 static struct dl_es_at_entry en_at_array
[MAX_EN_COUNT
];
119 * Process a received Ethernet packet;
120 * the packet is in the mbuf chain m without
121 * the ether header, which is provided separately.
126 __unused
char *frame_header
,
127 __unused
struct ifnet
*ifp
,
128 __unused u_long protocol_family
,
129 __unused
int sync_ok
)
133 * note: for AppleTalk we need to pass the enet header of the
134 * packet up stack. To do so, we made sure in that the FULL packet
135 * is copied in the mbuf by the mace driver, and only the m_data and
136 * length have been shifted to make IP and the other guys happy.
139 m
->m_data
-= sizeof(struct ether_header
);
140 m
->m_len
+= sizeof(struct ether_header
);
141 m
->m_pkthdr
.len
+= sizeof(struct ether_header
);
142 proto_input(PF_APPLETALK
, m
);
152 __unused u_long protocol_family
,
154 const struct sockaddr
*dst_netaddr
,
155 __unused caddr_t route
,
159 register struct mbuf
*m
= *m0
;
160 register struct ether_header
*eh
;
161 int hlen
; /* link layer header lenght */
165 if ((ifp
->if_flags
& (IFF_UP
|IFF_RUNNING
)) != (IFF_UP
|IFF_RUNNING
))
168 hlen
= ETHER_HDR_LEN
;
171 * Tell ether_frameout it's ok to loop packet unless negated below.
173 m
->m_flags
|= M_LOOP
;
175 switch (dst_netaddr
->sa_family
) {
177 m
->m_flags
&= ~M_LOOP
;
178 eh
= (struct ether_header
*)dst_netaddr
->sa_data
;
179 (void)memcpy(edst
, eh
->ether_dhost
, 6);
180 *(u_short
*)type
= eh
->ether_type
;
186 eh
= (struct ether_header
*)dst_netaddr
->sa_data
;
187 bcopy((caddr_t
)eh
->ether_dhost
, (caddr_t
)edst
, 6);
189 *(u_short
*)type
= m
->m_pkthdr
.len
;
195 kprintf("%s%d: can't handle af%d\n", ifp
->if_name
, ifp
->if_unit
,
196 dst_netaddr
->sa_family
);
210 __unused u_long protocol_family
,
215 struct ifreq
*ifr
= (struct ifreq
*) data
;
221 if ((ifp
->if_flags
& IFF_RUNNING
) == 0) {
222 ifnet_set_flags(ifp
, IFF_UP
, IFF_UP
);
223 dlil_ioctl(0, ifp
, SIOCSIFFLAGS
, (caddr_t
) 0);
229 ifnet_lladdr_copy_bytes(ifp
, ifr
->ifr_addr
.sa_data
, ETHER_ADDR_LEN
);
234 * Set the interface MTU.
236 if (ifr
->ifr_mtu
> ETHERMTU
) {
239 ifp
->if_mtu
= ifr
->ifr_mtu
;
257 struct dlil_proto_reg_str reg
;
258 struct dlil_demux_desc desc
;
259 struct dlil_demux_desc desc2
;
263 u_int8_t atalk_snap
[5] = {0x08, 0x00, 0x07, 0x80, 0x9b};
264 u_int8_t aarp_snap
[5] = {0x00, 0x00, 0x00, 0x80, 0xf3};
266 first_empty
= MAX_EN_COUNT
;
267 for (i
=0; i
< MAX_EN_COUNT
; i
++) {
268 if (en_at_array
[i
].ifp
== 0)
271 if (en_at_array
[i
].ifp
== ifp
) {
272 en_at_array
[i
].ref_count
++;
277 if (first_empty
== MAX_EN_COUNT
)
280 bzero(®
, sizeof(reg
));
281 bzero(&desc
, sizeof(desc
));
282 bzero(&desc2
, sizeof(desc2
));
284 TAILQ_INIT(®
.demux_desc_head
);
285 reg
.interface_family
= ifp
->if_family
;
286 reg
.unit_number
= ifp
->if_unit
;
287 reg
.input
= at_ether_input
;
288 reg
.pre_output
= ether_pre_output
;
289 reg
.ioctl
= ether_prmod_ioctl
;
290 reg
.protocol_family
= PF_APPLETALK
;
292 desc
.type
= DLIL_DESC_SNAP
;
293 desc
.native_type
= atalk_snap
;
294 desc
.variants
.native_type_length
= sizeof(atalk_snap
);
295 TAILQ_INSERT_TAIL(®
.demux_desc_head
, &desc
, next
);
297 desc2
.type
= DLIL_DESC_SNAP
;
298 desc2
.native_type
= aarp_snap
;
299 desc2
.variants
.native_type_length
= sizeof(aarp_snap
);
300 TAILQ_INSERT_TAIL(®
.demux_desc_head
, &desc2
, next
);
302 stat
= dlil_attach_protocol(®
);
304 printf("WARNING: ether_attach_at can't attach at to interface\n");
308 en_at_array
[first_empty
].ifp
= ifp
;
309 en_at_array
[first_empty
].ref_count
= 1;
312 } /* ether_attach_at */
316 ether_detach_at(struct ifnet
*ifp
)
320 for (i
=0; i
< MAX_EN_COUNT
; i
++) {
321 if (en_at_array
[i
].ifp
== ifp
)
325 if (i
< MAX_EN_COUNT
) {
326 if (en_at_array
[i
].ref_count
> 1)
327 en_at_array
[i
].ref_count
--;
329 if (en_at_array
[i
].ref_count
== 1) {
330 dlil_detach_protocol(ifp
, PF_APPLETALK
);
331 en_at_array
[i
].ifp
= 0;