]>
Commit | Line | Data |
---|---|---|
1c79356b | 1 | /* |
b7266188 | 2 | * Copyright (c) 2000,2009 Apple Inc. All rights reserved. |
5d5c5d0d | 3 | * |
2d21ac55 | 4 | * @APPLE_OSREFERENCE_LICENSE_HEADER_START@ |
1c79356b | 5 | * |
2d21ac55 A |
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 License | |
10 | * may not be used to create, or enable the creation or redistribution of, | |
11 | * unlawful or unlicensed copies of an Apple operating system, or to | |
12 | * circumvent, violate, or enable the circumvention or violation of, any | |
13 | * terms of an Apple operating system software license agreement. | |
8f6c56a5 | 14 | * |
2d21ac55 A |
15 | * Please obtain a copy of the License at |
16 | * http://www.opensource.apple.com/apsl/ and read it before using this file. | |
17 | * | |
18 | * The Original Code and all software distributed under the License are | |
19 | * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER | |
8f6c56a5 A |
20 | * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, |
21 | * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, | |
2d21ac55 A |
22 | * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. |
23 | * Please see the License for the specific language governing rights and | |
24 | * limitations under the License. | |
8f6c56a5 | 25 | * |
2d21ac55 | 26 | * @APPLE_OSREFERENCE_LICENSE_HEADER_END@ |
1c79356b A |
27 | */ |
28 | /* | |
29 | * Copyright (c) 1982, 1989, 1993 | |
30 | * The Regents of the University of California. All rights reserved. | |
31 | * | |
32 | * Redistribution and use in source and binary forms, with or without | |
33 | * modification, are permitted provided that the following conditions | |
34 | * are met: | |
35 | * 1. Redistributions of source code must retain the above copyright | |
36 | * notice, this list of conditions and the following disclaimer. | |
37 | * 2. Redistributions in binary form must reproduce the above copyright | |
38 | * notice, this list of conditions and the following disclaimer in the | |
39 | * documentation and/or other materials provided with the distribution. | |
40 | * 3. All advertising materials mentioning features or use of this software | |
41 | * must display the following acknowledgement: | |
42 | * This product includes software developed by the University of | |
43 | * California, Berkeley and its contributors. | |
44 | * 4. Neither the name of the University nor the names of its contributors | |
45 | * may be used to endorse or promote products derived from this software | |
46 | * without specific prior written permission. | |
47 | * | |
48 | * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND | |
49 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | |
50 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | |
51 | * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE | |
52 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | |
53 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | |
54 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | |
55 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | |
56 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | |
57 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | |
58 | * SUCH DAMAGE. | |
59 | * | |
60 | */ | |
61 | ||
62 | ||
63 | ||
64 | #include <sys/param.h> | |
65 | #include <sys/systm.h> | |
66 | #include <sys/kernel.h> | |
67 | #include <sys/malloc.h> | |
68 | #include <sys/mbuf.h> | |
69 | #include <sys/socket.h> | |
70 | #include <sys/sockio.h> | |
71 | #include <sys/sysctl.h> | |
72 | ||
73 | #include <net/if.h> | |
1c79356b A |
74 | #include <net/route.h> |
75 | #include <net/if_llc.h> | |
76 | #include <net/if_dl.h> | |
77 | #include <net/if_types.h> | |
1c79356b | 78 | #include <netinet/if_ether.h> |
2d21ac55 A |
79 | #include <net/kpi_interface.h> |
80 | #include <net/kpi_protocol.h> | |
1c79356b A |
81 | |
82 | #include <sys/socketvar.h> | |
83 | ||
84 | #include <net/dlil.h> | |
85 | #include <netat/at_pat.h> | |
86 | #if NETAT | |
87 | extern struct ifqueue atalkintrq; | |
88 | #endif | |
89 | ||
90 | ||
1c79356b A |
91 | /* #include "vlan.h" */ |
92 | #if NVLAN > 0 | |
93 | #include <net/if_vlan_var.h> | |
94 | #endif /* NVLAN > 0 */ | |
95 | ||
2d21ac55 | 96 | #include <net/ether_if_module.h> |
1c79356b A |
97 | |
98 | /* | |
99 | * Process a received Ethernet packet; | |
100 | * the packet is in the mbuf chain m without | |
101 | * the ether header, which is provided separately. | |
102 | */ | |
2d21ac55 A |
103 | static errno_t |
104 | ether_at_input( | |
105 | __unused ifnet_t ifp, | |
106 | __unused protocol_family_t protocol_family, | |
107 | mbuf_t m, | |
108 | __unused char *frame_header) | |
1c79356b | 109 | { |
2d21ac55 A |
110 | errno_t error; |
111 | /* | |
112 | * note: for AppleTalk we need to pass the enet header of the | |
113 | * packet up stack. To do so, we made sure in that the FULL packet | |
114 | * is copied in the mbuf by the driver, and only the m_data and | |
115 | * length have been shifted to make IP and the other guys happy. | |
116 | */ | |
91447636 A |
117 | |
118 | m->m_data -= sizeof(struct ether_header); | |
119 | m->m_len += sizeof(struct ether_header); | |
120 | m->m_pkthdr.len += sizeof(struct ether_header); | |
1c79356b | 121 | |
2d21ac55 A |
122 | error = proto_input(PF_APPLETALK, m); |
123 | ||
124 | if (error) | |
125 | m_freem(m); | |
126 | ||
127 | return error; | |
1c79356b A |
128 | } |
129 | ||
130 | ||
131 | ||
2d21ac55 A |
132 | static errno_t |
133 | ether_at_pre_output( | |
134 | ifnet_t ifp, | |
135 | __unused protocol_family_t protocol_family, | |
136 | mbuf_t *m0, | |
137 | const struct sockaddr *dst_netaddr, | |
138 | __unused void *route, | |
139 | char *type, | |
140 | char *edst) | |
1c79356b | 141 | { |
2d21ac55 A |
142 | struct mbuf *m = *m0; |
143 | const struct ether_header *eh; | |
144 | int hlen; /* link layer header length */ | |
1c79356b | 145 | |
2d21ac55 A |
146 | if ((ifp->if_flags & (IFF_UP|IFF_RUNNING)) != (IFF_UP|IFF_RUNNING)) |
147 | return ENETDOWN; | |
1c79356b | 148 | |
2d21ac55 | 149 | hlen = ETHER_HDR_LEN; |
1c79356b | 150 | |
2d21ac55 A |
151 | /* |
152 | * Tell ether_frameout it's ok to loop packet unless negated below. | |
153 | */ | |
154 | m->m_flags |= M_LOOP; | |
155 | ||
156 | switch (dst_netaddr->sa_family) { | |
157 | case AF_UNSPEC: | |
158 | m->m_flags &= ~M_LOOP; | |
159 | eh = (const struct ether_header *)dst_netaddr->sa_data; | |
160 | (void)memcpy(edst, eh->ether_dhost, 6); | |
161 | *(u_short *)type = eh->ether_type; | |
162 | break; | |
1c79356b | 163 | |
2d21ac55 A |
164 | case AF_APPLETALK: |
165 | eh = (const struct ether_header *)dst_netaddr->sa_data; | |
166 | (void)memcpy(edst, eh->ether_dhost, 6); | |
167 | *(u_short *)type = htons(m->m_pkthdr.len); | |
168 | break; | |
1c79356b | 169 | |
2d21ac55 A |
170 | default: |
171 | printf("%s%d: can't handle af%d\n", ifp->if_name, ifp->if_unit, | |
172 | dst_netaddr->sa_family); | |
173 | return EAFNOSUPPORT; | |
174 | } | |
175 | ||
176 | return (0); | |
1c79356b A |
177 | } |
178 | ||
179 | ||
180 | ||
181 | ||
2d21ac55 A |
182 | static errno_t |
183 | ether_at_prmod_ioctl( | |
184 | ifnet_t ifp, | |
185 | __unused protocol_family_t protocol_family, | |
186 | u_int32_t command, | |
187 | void *data) | |
1c79356b | 188 | { |
2d21ac55 | 189 | struct ifreq *ifr = data; |
1c79356b | 190 | int error = 0; |
1c79356b A |
191 | |
192 | switch (command) { | |
193 | ||
194 | case SIOCSIFADDR: | |
195 | if ((ifp->if_flags & IFF_RUNNING) == 0) { | |
91447636 | 196 | ifnet_set_flags(ifp, IFF_UP, IFF_UP); |
2d21ac55 | 197 | ifnet_ioctl(ifp, 0, SIOCSIFFLAGS, NULL); |
1c79356b A |
198 | } |
199 | ||
200 | break; | |
201 | ||
202 | case SIOCGIFADDR: | |
91447636 | 203 | ifnet_lladdr_copy_bytes(ifp, ifr->ifr_addr.sa_data, ETHER_ADDR_LEN); |
1c79356b A |
204 | break; |
205 | ||
206 | default: | |
2d21ac55 A |
207 | error = EOPNOTSUPP; |
208 | break; | |
1c79356b | 209 | } |
1c79356b A |
210 | return (error); |
211 | } | |
212 | ||
213 | ||
214 | ||
2d21ac55 | 215 | __private_extern__ errno_t |
91447636 | 216 | ether_attach_at( |
2d21ac55 A |
217 | ifnet_t ifp, |
218 | __unused protocol_family_t proto_family) | |
1c79356b | 219 | { |
2d21ac55 A |
220 | struct ifnet_attach_proto_param proto; |
221 | struct ifnet_demux_desc demux[2]; | |
91447636 A |
222 | u_int8_t atalk_snap[5] = {0x08, 0x00, 0x07, 0x80, 0x9b}; |
223 | u_int8_t aarp_snap[5] = {0x00, 0x00, 0x00, 0x80, 0xf3}; | |
2d21ac55 A |
224 | int error; |
225 | ||
226 | bzero(demux, sizeof(demux)); | |
227 | demux[0].type = DLIL_DESC_SNAP; | |
228 | demux[0].data = atalk_snap; | |
229 | demux[0].datalen = sizeof(atalk_snap); | |
230 | demux[1].type = DLIL_DESC_SNAP; | |
231 | demux[1].data = aarp_snap; | |
232 | demux[1].datalen = sizeof(aarp_snap); | |
233 | ||
234 | bzero(&proto, sizeof(proto)); | |
235 | proto.demux_list = demux; | |
236 | proto.demux_count = sizeof(demux) / sizeof(demux[0]); | |
237 | proto.input = ether_at_input; | |
238 | proto.pre_output = ether_at_pre_output; | |
239 | proto.ioctl = ether_at_prmod_ioctl; | |
91447636 | 240 | |
2d21ac55 A |
241 | error = ifnet_attach_protocol(ifp, PF_APPLETALK, &proto); |
242 | if (error && error != EEXIST) { | |
243 | printf("WARNING: ether_attach_at failed to attach" | |
244 | " AppleTalk to %s%d\n", ifp->if_name, ifp->if_unit); | |
91447636 | 245 | } |
2d21ac55 A |
246 | return (error); |
247 | } | |
1c79356b | 248 | |
2d21ac55 A |
249 | __private_extern__ void |
250 | ether_detach_at( | |
251 | ifnet_t ifp, | |
252 | __unused protocol_family_t proto_family) | |
1c79356b | 253 | { |
2d21ac55 | 254 | (void)ifnet_detach_protocol(ifp, PF_APPLETALK); |
1c79356b | 255 | } |