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/netisr.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 <netinet/if_ether.h>
76 #include <sys/socketvar.h>
79 #include <netat/at_pat.h>
81 extern struct ifqueue atalkintrq
;
86 #include <net/bridge.h>
89 /* #include "vlan.h" */
91 #include <net/if_vlan_var.h>
92 #endif /* NVLAN > 0 */
95 u_char etherbroadcastaddr
[6] = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff };
97 #define IFP2AC(IFP) ((struct arpcom *)IFP)
100 struct dl_es_at_entry
109 * Temp static for protocol registration XXX
112 #define MAX_EN_COUNT 30
114 static struct dl_es_at_entry en_at_array
[MAX_EN_COUNT
];
117 * Process a received Ethernet packet;
118 * the packet is in the mbuf chain m without
119 * the ether header, which is provided separately.
122 at_ether_input(m
, frame_header
, ifp
, dl_tag
, sync_ok
)
130 register struct ether_header
*eh
= (struct ether_header
*) frame_header
;
131 register struct ifqueue
*inq
=0;
134 u_int16_t ptype
= -1;
135 unsigned char buf
[18];
138 register struct llc
*l
;
141 if ((ifp
->if_flags
& IFF_UP
) == 0) {
146 ifp
->if_lastchange
= time
;
148 if (eh
->ether_dhost
[0] & 1) {
149 if (bcmp((caddr_t
)etherbroadcastaddr
, (caddr_t
)eh
->ether_dhost
,
150 sizeof(etherbroadcastaddr
)) == 0)
151 m
->m_flags
|= M_BCAST
;
153 m
->m_flags
|= M_MCAST
;
155 if (m
->m_flags
& (M_BCAST
|M_MCAST
))
158 ether_type
= ntohs(eh
->ether_type
);
161 if (ether_type
== vlan_proto
) {
162 if (vlan_input(eh
, m
) < 0)
163 ifp
->if_data
.ifi_noproto
++;
166 #endif /* NVLAN > 0 */
168 if (ether_type
> ETHERMTU
)
172 l
= mtod(m
, struct llc
*);
174 switch (l
->llc_dsap
) {
177 /* Temporary hack: check for AppleTalk and AARP packets */
178 /* WARNING we're checking only on the "ether_type" (the 2 bytes
179 * of the SNAP header. This shouldn't be a big deal,
180 * AppleTalk pat_input is making sure we have the right packets
181 * because it needs to discrimante AARP from EtherTalk packets.
184 if (l
->llc_ssap
== LLC_SNAP_LSAP
&&
185 l
->llc_un
.type_snap
.control
== 0x03) {
187 #ifdef APPLETALK_DEBUG
188 printf("new_ether_input: SNAP Cntrol type=0x%x Src=%s\n",
189 l
->llc_un
.type_snap
.ether_type
,
190 ether_sprintf(buf
, &eh
->ether_shost
));
192 ether_sprintf(buf
, &eh
->ether_dhost
));
193 #endif /* APPLETALK_DEBUG */
195 if ((l
->llc_un
.type_snap
.ether_type
== 0x809B) ||
196 (l
->llc_un
.type_snap
.ether_type
== 0x80F3)) {
200 * note: for AppleTalk we need to pass the enet header of the
201 * packet up stack. To do so, we made sure in that the FULL packet
202 * is copied in the mbuf by the mace driver, and only the m_data and
203 * length have been shifted to make IP and the other guys happy.
206 m
->m_data
-= sizeof(*eh
);
207 m
->m_len
+= sizeof(*eh
);
208 m
->m_pkthdr
.len
+= sizeof(*eh
);
209 #ifdef APPLETALK_DEBUG
210 l
== (struct llc
*)(eh
+1);
211 if (l
->llc_un
.type_snap
.ether_type
== 0x80F3) {
212 kprintf("new_ether_input: RCV AppleTalk type=0x%x Src=%s\n",
213 l
->llc_un
.type_snap
.ether_type
,
214 ether_sprintf(buf
, &eh
->ether_shost
));
216 ether_sprintf(buf
, &eh
->ether_dhost
));
218 #endif /* APPLETALK_DEBUG */
219 schednetisr(NETISR_APPLETALK
);
255 ether_pre_output(ifp
, m0
, dst_netaddr
, route
, type
, edst
, dl_tag
)
258 struct sockaddr
*dst_netaddr
;
265 register struct mbuf
*m
= *m0
;
266 register struct rtentry
*rt
;
267 register struct ether_header
*eh
;
268 int off
, len
= m
->m_pkthdr
.len
;
269 int hlen
; /* link layer header lenght */
270 struct arpcom
*ac
= IFP2AC(ifp
);
274 if ((ifp
->if_flags
& (IFF_UP
|IFF_RUNNING
)) != (IFF_UP
|IFF_RUNNING
))
277 hlen
= ETHER_HDR_LEN
;
280 * Tell ether_frameout it's ok to loop packet unless negated below.
282 m
->m_flags
|= M_LOOP
;
284 switch (dst_netaddr
->sa_family
) {
286 m
->m_flags
&= ~M_LOOP
;
287 eh
= (struct ether_header
*)dst_netaddr
->sa_data
;
288 (void)memcpy(edst
, eh
->ether_dhost
, 6);
289 *(u_short
*)type
= eh
->ether_type
;
295 eh
= (struct ether_header
*)dst_netaddr
->sa_data
;
296 bcopy((caddr_t
)eh
->ether_dhost
, (caddr_t
)edst
, 6);
298 *(u_short
*)type
= m
->m_pkthdr
.len
;
304 kprintf("%s%d: can't handle af%d\n", ifp
->if_name
, ifp
->if_unit
,
305 dst_netaddr
->sa_family
);
318 ether_prmod_ioctl(dl_tag
, ifp
, command
, data
)
324 struct ifaddr
*ifa
= (struct ifaddr
*) data
;
325 struct ifreq
*ifr
= (struct ifreq
*) data
;
327 boolean_t funnel_state
;
328 struct arpcom
*ac
= (struct arpcom
*) ifp
;
329 struct sockaddr_dl
*sdl
;
330 struct sockaddr_in
*sin
;
334 funnel_state
= thread_funnel_set(network_flock
, TRUE
);
339 if ((ifp
->if_flags
& IFF_RUNNING
) == 0) {
340 ifp
->if_flags
|= IFF_UP
;
341 dlil_ioctl(0, ifp
, SIOCSIFFLAGS
, (caddr_t
) 0);
350 sa
= (struct sockaddr
*) & ifr
->ifr_data
;
351 bcopy(IFP2AC(ifp
)->ac_enaddr
,
352 (caddr_t
) sa
->sa_data
, ETHER_ADDR_LEN
);
358 * Set the interface MTU.
360 if (ifr
->ifr_mtu
> ETHERMTU
) {
363 ifp
->if_mtu
= ifr
->ifr_mtu
;
371 (void) thread_funnel_set(network_flock
, funnel_state
);
379 ether_attach_at(struct ifnet
*ifp
, u_long
*at_dl_tag
, u_long
*aarp_dl_tag
)
381 struct dlil_proto_reg_str reg
;
382 struct dlil_demux_desc desc
;
383 struct dlil_demux_desc desc2
;
384 u_short native
= 0; /* 802.2 frames use a length here */
390 first_empty
= MAX_EN_COUNT
;
391 for (i
=0; i
< MAX_EN_COUNT
; i
++) {
392 if (en_at_array
[i
].ifp
== 0)
395 if (en_at_array
[i
].ifp
== ifp
) {
396 en_at_array
[i
].ref_count
++;
397 *at_dl_tag
= *aarp_dl_tag
= en_at_array
[i
].dl_tag
;
402 if (first_empty
== MAX_EN_COUNT
)
405 TAILQ_INIT(®
.demux_desc_head
);
406 desc
.type
= DLIL_DESC_802_2_SNAP
;
407 desc
.variants
.desc_802_2_SNAP
.dsap
= LLC_SNAP_LSAP
;
408 desc
.variants
.desc_802_2_SNAP
.ssap
= LLC_SNAP_LSAP
;
409 desc
.variants
.desc_802_2_SNAP
.control_code
= 0x03;
410 desc
.variants
.desc_802_2_SNAP
.org
[0] = 0x08;
411 desc
.variants
.desc_802_2_SNAP
.org
[1] = 0x00;
412 desc
.variants
.desc_802_2_SNAP
.org
[2] = 0x07;
413 desc
.variants
.desc_802_2_SNAP
.protocol_type
= 0x809B;
414 desc
.native_type
= (char *) &native
;
415 TAILQ_INSERT_TAIL(®
.demux_desc_head
, &desc
, next
);
416 reg
.interface_family
= ifp
->if_family
;
417 reg
.unit_number
= ifp
->if_unit
;
418 reg
.input
= at_ether_input
;
419 reg
.pre_output
= ether_pre_output
;
422 reg
.ioctl
= ether_prmod_ioctl
;
423 reg
.default_proto
= 0;
424 reg
.protocol_family
= PF_APPLETALK
;
427 desc2
.variants
.desc_802_2_SNAP
.protocol_type
= 0x80F3;
428 desc2
.variants
.desc_802_2_SNAP
.org
[0] = 0;
429 desc2
.variants
.desc_802_2_SNAP
.org
[1] = 0;
430 desc2
.variants
.desc_802_2_SNAP
.org
[2] = 0;
432 TAILQ_INSERT_TAIL(®
.demux_desc_head
, &desc2
, next
);
434 stat
= dlil_attach_protocol(®
, at_dl_tag
);
436 printf("WARNING: ether_attach_at can't attach at to interface\n");
440 *aarp_dl_tag
= *at_dl_tag
;
442 en_at_array
[first_empty
].ifp
= ifp
;
443 en_at_array
[first_empty
].dl_tag
= *at_dl_tag
;
444 en_at_array
[first_empty
].ref_count
= 1;
446 } /* ether_attach_at */
450 ether_detach_at(struct ifnet
*ifp
)
454 for (i
=0; i
< MAX_EN_COUNT
; i
++) {
455 if (en_at_array
[i
].ifp
== ifp
)
459 if (i
< MAX_EN_COUNT
) {
460 if (en_at_array
[i
].ref_count
> 1)
461 en_at_array
[i
].ref_count
--;
463 if (en_at_array
[i
].ref_count
== 1) {
464 dlil_detach_protocol(en_at_array
[i
].dl_tag
);
465 en_at_array
[i
].ifp
= 0;