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>
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 */
94 u_char etherbroadcastaddr
[6] = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff };
96 #define IFP2AC(IFP) ((struct arpcom *)IFP)
108 * Temp static for protocol registration XXX
111 #define MAX_EN_COUNT 30
113 static struct dl_es_at_entry en_at_array
[MAX_EN_COUNT
];
116 * Process a received Ethernet packet;
117 * the packet is in the mbuf chain m without
118 * the ether header, which is provided separately.
121 at_ether_input(m
, frame_header
, ifp
, dl_tag
, sync_ok
)
129 register struct ether_header
*eh
= (struct ether_header
*) frame_header
;
130 register struct ifqueue
*inq
=0;
133 u_int16_t ptype
= -1;
134 unsigned char buf
[18];
137 register struct llc
*l
;
140 if ((ifp
->if_flags
& IFF_UP
) == 0) {
145 ifp
->if_lastchange
= time
;
147 if (eh
->ether_dhost
[0] & 1) {
148 if (bcmp((caddr_t
)etherbroadcastaddr
, (caddr_t
)eh
->ether_dhost
,
149 sizeof(etherbroadcastaddr
)) == 0)
150 m
->m_flags
|= M_BCAST
;
152 m
->m_flags
|= M_MCAST
;
154 if (m
->m_flags
& (M_BCAST
|M_MCAST
))
157 ether_type
= ntohs(eh
->ether_type
);
160 if (ether_type
== vlan_proto
) {
161 if (vlan_input(eh
, m
) < 0)
162 ifp
->if_data
.ifi_noproto
++;
165 #endif /* NVLAN > 0 */
167 if (ether_type
> ETHERMTU
)
171 l
= mtod(m
, struct llc
*);
173 switch (l
->llc_dsap
) {
176 /* Temporary hack: check for AppleTalk and AARP packets */
177 /* WARNING we're checking only on the "ether_type" (the 2 bytes
178 * of the SNAP header. This shouldn't be a big deal,
179 * AppleTalk pat_input is making sure we have the right packets
180 * because it needs to discrimante AARP from EtherTalk packets.
183 if (l
->llc_ssap
== LLC_SNAP_LSAP
&&
184 l
->llc_un
.type_snap
.control
== 0x03) {
186 #ifdef APPLETALK_DEBUG
187 printf("new_ether_input: SNAP Cntrol type=0x%x Src=%s\n",
188 l
->llc_un
.type_snap
.ether_type
,
189 ether_sprintf(buf
, &eh
->ether_shost
));
191 ether_sprintf(buf
, &eh
->ether_dhost
));
192 #endif /* APPLETALK_DEBUG */
194 if ((l
->llc_un
.type_snap
.ether_type
== 0x809B) ||
195 (l
->llc_un
.type_snap
.ether_type
== 0x80F3)) {
199 * note: for AppleTalk we need to pass the enet header of the
200 * packet up stack. To do so, we made sure in that the FULL packet
201 * is copied in the mbuf by the mace driver, and only the m_data and
202 * length have been shifted to make IP and the other guys happy.
205 m
->m_data
-= sizeof(*eh
);
206 m
->m_len
+= sizeof(*eh
);
207 m
->m_pkthdr
.len
+= sizeof(*eh
);
208 #ifdef APPLETALK_DEBUG
209 l
== (struct llc
*)(eh
+1);
210 if (l
->llc_un
.type_snap
.ether_type
== 0x80F3) {
211 kprintf("new_ether_input: RCV AppleTalk type=0x%x Src=%s\n",
212 l
->llc_un
.type_snap
.ether_type
,
213 ether_sprintf(buf
, &eh
->ether_shost
));
215 ether_sprintf(buf
, &eh
->ether_dhost
));
217 #endif /* APPLETALK_DEBUG */
218 schednetisr(NETISR_APPLETALK
);
254 ether_pre_output(ifp
, m0
, dst_netaddr
, route
, type
, edst
, dl_tag
)
257 struct sockaddr
*dst_netaddr
;
264 register struct mbuf
*m
= *m0
;
265 register struct rtentry
*rt
;
266 register struct ether_header
*eh
;
267 int off
, len
= m
->m_pkthdr
.len
;
268 int hlen
; /* link layer header lenght */
269 struct arpcom
*ac
= IFP2AC(ifp
);
273 if ((ifp
->if_flags
& (IFF_UP
|IFF_RUNNING
)) != (IFF_UP
|IFF_RUNNING
))
276 hlen
= ETHER_HDR_LEN
;
279 * Tell ether_frameout it's ok to loop packet unless negated below.
281 m
->m_flags
|= M_LOOP
;
283 switch (dst_netaddr
->sa_family
) {
285 m
->m_flags
&= ~M_LOOP
;
286 eh
= (struct ether_header
*)dst_netaddr
->sa_data
;
287 (void)memcpy(edst
, eh
->ether_dhost
, 6);
288 *(u_short
*)type
= eh
->ether_type
;
294 eh
= (struct ether_header
*)dst_netaddr
->sa_data
;
295 bcopy((caddr_t
)eh
->ether_dhost
, (caddr_t
)edst
, 6);
297 *(u_short
*)type
= m
->m_pkthdr
.len
;
303 kprintf("%s%d: can't handle af%d\n", ifp
->if_name
, ifp
->if_unit
,
304 dst_netaddr
->sa_family
);
317 ether_prmod_ioctl(dl_tag
, ifp
, command
, data
)
323 struct ifaddr
*ifa
= (struct ifaddr
*) data
;
324 struct ifreq
*ifr
= (struct ifreq
*) data
;
326 boolean_t funnel_state
;
327 struct arpcom
*ac
= (struct arpcom
*) ifp
;
328 struct sockaddr_dl
*sdl
;
329 struct sockaddr_in
*sin
;
333 funnel_state
= thread_funnel_set(network_flock
, TRUE
);
338 if ((ifp
->if_flags
& IFF_RUNNING
) == 0) {
339 ifp
->if_flags
|= IFF_UP
;
340 dlil_ioctl(0, ifp
, SIOCSIFFLAGS
, (caddr_t
) 0);
349 sa
= (struct sockaddr
*) & ifr
->ifr_data
;
350 bcopy(IFP2AC(ifp
)->ac_enaddr
,
351 (caddr_t
) sa
->sa_data
, ETHER_ADDR_LEN
);
357 * Set the interface MTU.
359 if (ifr
->ifr_mtu
> ETHERMTU
) {
362 ifp
->if_mtu
= ifr
->ifr_mtu
;
370 (void) thread_funnel_set(network_flock
, funnel_state
);
378 ether_attach_at(struct ifnet
*ifp
, u_long
*at_dl_tag
, u_long
*aarp_dl_tag
)
380 struct dlil_proto_reg_str reg
;
381 struct dlil_demux_desc desc
;
382 struct dlil_demux_desc desc2
;
383 u_short native
= 0; /* 802.2 frames use a length here */
389 first_empty
= MAX_EN_COUNT
;
390 for (i
=0; i
< MAX_EN_COUNT
; i
++) {
391 if (en_at_array
[i
].ifp
== 0)
394 if (en_at_array
[i
].ifp
== ifp
) {
395 en_at_array
[i
].ref_count
++;
396 *at_dl_tag
= *aarp_dl_tag
= en_at_array
[i
].dl_tag
;
401 if (first_empty
== MAX_EN_COUNT
)
404 TAILQ_INIT(®
.demux_desc_head
);
405 desc
.type
= DLIL_DESC_802_2_SNAP
;
406 desc
.variants
.desc_802_2_SNAP
.dsap
= LLC_SNAP_LSAP
;
407 desc
.variants
.desc_802_2_SNAP
.ssap
= LLC_SNAP_LSAP
;
408 desc
.variants
.desc_802_2_SNAP
.control_code
= 0x03;
409 desc
.variants
.desc_802_2_SNAP
.org
[0] = 0x08;
410 desc
.variants
.desc_802_2_SNAP
.org
[1] = 0x00;
411 desc
.variants
.desc_802_2_SNAP
.org
[2] = 0x07;
412 desc
.variants
.desc_802_2_SNAP
.protocol_type
= 0x809B;
413 desc
.native_type
= NULL
;
414 TAILQ_INSERT_TAIL(®
.demux_desc_head
, &desc
, next
);
415 reg
.interface_family
= ifp
->if_family
;
416 reg
.unit_number
= ifp
->if_unit
;
417 reg
.input
= at_ether_input
;
418 reg
.pre_output
= ether_pre_output
;
421 reg
.ioctl
= ether_prmod_ioctl
;
422 reg
.default_proto
= 0;
423 reg
.protocol_family
= PF_APPLETALK
;
426 desc2
.variants
.desc_802_2_SNAP
.protocol_type
= 0x80F3;
427 desc2
.variants
.desc_802_2_SNAP
.org
[0] = 0;
428 desc2
.variants
.desc_802_2_SNAP
.org
[1] = 0;
429 desc2
.variants
.desc_802_2_SNAP
.org
[2] = 0;
431 TAILQ_INSERT_TAIL(®
.demux_desc_head
, &desc2
, next
);
433 stat
= dlil_attach_protocol(®
, at_dl_tag
);
435 printf("WARNING: ether_attach_at can't attach at to interface\n");
439 *aarp_dl_tag
= *at_dl_tag
;
441 en_at_array
[first_empty
].ifp
= ifp
;
442 en_at_array
[first_empty
].dl_tag
= *at_dl_tag
;
443 en_at_array
[first_empty
].ref_count
= 1;
445 } /* ether_attach_at */
449 ether_detach_at(struct ifnet
*ifp
)
453 for (i
=0; i
< MAX_EN_COUNT
; i
++) {
454 if (en_at_array
[i
].ifp
== ifp
)
458 if (i
< MAX_EN_COUNT
) {
459 if (en_at_array
[i
].ref_count
> 1)
460 en_at_array
[i
].ref_count
--;
462 if (en_at_array
[i
].ref_count
== 1) {
463 dlil_detach_protocol(en_at_array
[i
].dl_tag
);
464 en_at_array
[i
].ifp
= 0;