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>
68 #include <net/route.h>
69 #include <net/if_llc.h>
70 #include <net/if_dl.h>
71 #include <net/if_types.h>
72 #include <netinet/if_ether.h>
74 #include <sys/socketvar.h>
77 #include <netat/at_pat.h>
79 extern struct ifqueue atalkintrq
;
84 #include <net/bridge.h>
87 /* #include "vlan.h" */
89 #include <net/if_vlan_var.h>
90 #endif /* NVLAN > 0 */
98 /* Local fuction declerations */
99 int at_ether_input(struct mbuf
*m
, char *frame_header
, struct ifnet
*ifp
,
100 u_long protocol_family
, int sync_ok
);
101 int ether_pre_output(struct ifnet
*ifp
, u_long protocol_family
, struct mbuf
**m0
,
102 const struct sockaddr
*dst_netaddr
, caddr_t route
, char *type
, char *edst
);
103 int ether_prmod_ioctl(u_long protocol_family
, struct ifnet
*ifp
, u_long command
,
105 int ether_attach_at(struct ifnet
*ifp
);
106 void ether_detach_at(struct ifnet
*ifp
);
110 * Temp static for protocol registration XXX
113 #define MAX_EN_COUNT 30
115 static struct dl_es_at_entry en_at_array
[MAX_EN_COUNT
];
118 * Process a received Ethernet packet;
119 * the packet is in the mbuf chain m without
120 * the ether header, which is provided separately.
125 __unused
char *frame_header
,
126 __unused
struct ifnet
*ifp
,
127 __unused u_long protocol_family
,
128 __unused
int sync_ok
)
132 * note: for AppleTalk we need to pass the enet header of the
133 * packet up stack. To do so, we made sure in that the FULL packet
134 * is copied in the mbuf by the mace driver, and only the m_data and
135 * length have been shifted to make IP and the other guys happy.
138 m
->m_data
-= sizeof(struct ether_header
);
139 m
->m_len
+= sizeof(struct ether_header
);
140 m
->m_pkthdr
.len
+= sizeof(struct ether_header
);
141 proto_input(PF_APPLETALK
, m
);
151 __unused u_long protocol_family
,
153 const struct sockaddr
*dst_netaddr
,
154 __unused caddr_t route
,
158 register struct mbuf
*m
= *m0
;
159 register struct ether_header
*eh
;
160 int hlen
; /* link layer header lenght */
164 if ((ifp
->if_flags
& (IFF_UP
|IFF_RUNNING
)) != (IFF_UP
|IFF_RUNNING
))
167 hlen
= ETHER_HDR_LEN
;
170 * Tell ether_frameout it's ok to loop packet unless negated below.
172 m
->m_flags
|= M_LOOP
;
174 switch (dst_netaddr
->sa_family
) {
176 m
->m_flags
&= ~M_LOOP
;
177 eh
= (struct ether_header
*)dst_netaddr
->sa_data
;
178 (void)memcpy(edst
, eh
->ether_dhost
, 6);
179 *(u_short
*)type
= eh
->ether_type
;
185 eh
= (struct ether_header
*)dst_netaddr
->sa_data
;
186 bcopy((caddr_t
)eh
->ether_dhost
, (caddr_t
)edst
, 6);
188 *(u_short
*)type
= m
->m_pkthdr
.len
;
194 kprintf("%s%d: can't handle af%d\n", ifp
->if_name
, ifp
->if_unit
,
195 dst_netaddr
->sa_family
);
209 __unused u_long protocol_family
,
214 struct ifreq
*ifr
= (struct ifreq
*) data
;
220 if ((ifp
->if_flags
& IFF_RUNNING
) == 0) {
221 ifnet_set_flags(ifp
, IFF_UP
, IFF_UP
);
222 dlil_ioctl(0, ifp
, SIOCSIFFLAGS
, (caddr_t
) 0);
228 ifnet_lladdr_copy_bytes(ifp
, ifr
->ifr_addr
.sa_data
, ETHER_ADDR_LEN
);
233 * Set the interface MTU.
235 if (ifr
->ifr_mtu
> ETHERMTU
) {
238 ifp
->if_mtu
= ifr
->ifr_mtu
;
256 struct dlil_proto_reg_str reg
;
257 struct dlil_demux_desc desc
;
258 struct dlil_demux_desc desc2
;
262 u_int8_t atalk_snap
[5] = {0x08, 0x00, 0x07, 0x80, 0x9b};
263 u_int8_t aarp_snap
[5] = {0x00, 0x00, 0x00, 0x80, 0xf3};
265 first_empty
= MAX_EN_COUNT
;
266 for (i
=0; i
< MAX_EN_COUNT
; i
++) {
267 if (en_at_array
[i
].ifp
== 0)
270 if (en_at_array
[i
].ifp
== ifp
) {
271 en_at_array
[i
].ref_count
++;
276 if (first_empty
== MAX_EN_COUNT
)
279 bzero(®
, sizeof(reg
));
280 bzero(&desc
, sizeof(desc
));
281 bzero(&desc2
, sizeof(desc2
));
283 TAILQ_INIT(®
.demux_desc_head
);
284 reg
.interface_family
= ifp
->if_family
;
285 reg
.unit_number
= ifp
->if_unit
;
286 reg
.input
= at_ether_input
;
287 reg
.pre_output
= ether_pre_output
;
288 reg
.ioctl
= ether_prmod_ioctl
;
289 reg
.protocol_family
= PF_APPLETALK
;
291 desc
.type
= DLIL_DESC_SNAP
;
292 desc
.native_type
= atalk_snap
;
293 desc
.variants
.native_type_length
= sizeof(atalk_snap
);
294 TAILQ_INSERT_TAIL(®
.demux_desc_head
, &desc
, next
);
296 desc2
.type
= DLIL_DESC_SNAP
;
297 desc2
.native_type
= aarp_snap
;
298 desc2
.variants
.native_type_length
= sizeof(aarp_snap
);
299 TAILQ_INSERT_TAIL(®
.demux_desc_head
, &desc2
, next
);
301 stat
= dlil_attach_protocol(®
);
303 printf("WARNING: ether_attach_at can't attach at to interface\n");
307 en_at_array
[first_empty
].ifp
= ifp
;
308 en_at_array
[first_empty
].ref_count
= 1;
311 } /* ether_attach_at */
315 ether_detach_at(struct ifnet
*ifp
)
319 for (i
=0; i
< MAX_EN_COUNT
; i
++) {
320 if (en_at_array
[i
].ifp
== ifp
)
324 if (i
< MAX_EN_COUNT
) {
325 if (en_at_array
[i
].ref_count
> 1)
326 en_at_array
[i
].ref_count
--;
328 if (en_at_array
[i
].ref_count
== 1) {
329 dlil_detach_protocol(ifp
, PF_APPLETALK
);
330 en_at_array
[i
].ifp
= 0;