]>
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 | ||
2d21ac55 A |
73 | #include <pexpert/pexpert.h> |
74 | ||
b0d623f7 | 75 | #define etherbroadcastaddr fugly |
1c79356b | 76 | #include <net/if.h> |
1c79356b A |
77 | #include <net/route.h> |
78 | #include <net/if_llc.h> | |
79 | #include <net/if_dl.h> | |
80 | #include <net/if_types.h> | |
91447636 | 81 | #include <net/if_ether.h> |
1c79356b | 82 | #include <netinet/if_ether.h> |
9bccf70c | 83 | #include <netinet/in.h> /* For M_LOOP */ |
2d21ac55 A |
84 | #include <net/kpi_interface.h> |
85 | #include <net/kpi_protocol.h> | |
b0d623f7 | 86 | #undef etherbroadcastaddr |
1c79356b A |
87 | |
88 | /* | |
89 | #if INET | |
90 | #include <netinet/in.h> | |
91 | #include <netinet/in_var.h> | |
92 | ||
93 | #include <netinet/in_systm.h> | |
94 | #include <netinet/ip.h> | |
95 | #endif | |
96 | */ | |
2d21ac55 | 97 | #include <net/ether_if_module.h> |
1c79356b | 98 | #include <sys/socketvar.h> |
4a249263 | 99 | #include <net/if_vlan_var.h> |
91447636 | 100 | #include <net/if_bond_var.h> |
1c79356b A |
101 | |
102 | #include <net/dlil.h> | |
103 | ||
1c79356b A |
104 | #if LLC && CCITT |
105 | extern struct ifqueue pkintrq; | |
106 | #endif | |
107 | ||
108 | /* General stuff from if_ethersubr.c - may not need some of it */ | |
109 | ||
110 | #include <netat/at_pat.h> | |
111 | #if NETAT | |
112 | extern struct ifqueue atalkintrq; | |
113 | #endif | |
114 | ||
115 | ||
91447636 A |
116 | #define memcpy(x,y,z) bcopy(y, x, z) |
117 | ||
1c79356b | 118 | |
91447636 | 119 | SYSCTL_DECL(_net_link); |
2d21ac55 | 120 | SYSCTL_NODE(_net_link, IFT_ETHER, ether, CTLFLAG_RW|CTLFLAG_LOCKED, 0, "Ethernet"); |
1c79356b | 121 | |
1c79356b | 122 | struct en_desc { |
91447636 | 123 | u_int16_t type; /* Type of protocol stored in data */ |
b0d623f7 A |
124 | u_int32_t protocol_family; /* Protocol family */ |
125 | u_int32_t data[2]; /* Protocol data */ | |
1c79356b | 126 | }; |
2d21ac55 | 127 | |
91447636 | 128 | /* descriptors are allocated in blocks of ETHER_DESC_BLK_SIZE */ |
2d21ac55 A |
129 | #if CONFIG_EMBEDDED |
130 | #define ETHER_DESC_BLK_SIZE (2) /* IP, ARP */ | |
131 | #else | |
132 | #define ETHER_DESC_BLK_SIZE (10) | |
133 | #endif | |
1c79356b A |
134 | |
135 | /* | |
91447636 | 136 | * Header for the demux list, hangs off of IFP at family_cookie |
1c79356b A |
137 | */ |
138 | ||
139 | struct ether_desc_blk_str { | |
b0d623f7 A |
140 | u_int32_t n_max_used; |
141 | u_int32_t n_count; | |
142 | u_int32_t n_used; | |
91447636 | 143 | struct en_desc block_ptr[1]; |
1c79356b | 144 | }; |
91447636 | 145 | /* Size of the above struct before the array of struct en_desc */ |
2d21ac55 | 146 | #define ETHER_DESC_HEADER_SIZE ((size_t)offsetof(struct ether_desc_blk_str, block_ptr)) |
91447636 A |
147 | __private_extern__ u_char etherbroadcastaddr[ETHER_ADDR_LEN] = |
148 | { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff }; | |
1c79356b | 149 | |
2d21ac55 A |
150 | static __inline__ int |
151 | _ether_cmp(const void * a, const void * b) | |
152 | { | |
153 | const u_int16_t * a_s = (const u_int16_t *)a; | |
154 | const u_int16_t * b_s = (const u_int16_t *)b; | |
155 | ||
156 | if (a_s[0] != b_s[0] | |
157 | || a_s[1] != b_s[1] | |
158 | || a_s[2] != b_s[2]) { | |
159 | return (1); | |
160 | } | |
161 | return (0); | |
162 | } | |
55e303ae | 163 | |
1c79356b | 164 | /* |
91447636 | 165 | * Release all descriptor entries owned by this protocol (there may be several). |
7b1edb79 | 166 | * Setting the type to 0 releases the entry. Eventually we should compact-out |
1c79356b A |
167 | * the unused entries. |
168 | */ | |
91447636 A |
169 | int |
170 | ether_del_proto( | |
171 | ifnet_t ifp, | |
172 | protocol_family_t protocol_family) | |
1c79356b | 173 | { |
91447636 | 174 | struct ether_desc_blk_str *desc_blk = (struct ether_desc_blk_str *)ifp->family_cookie; |
b0d623f7 | 175 | u_int32_t current = 0; |
91447636 A |
176 | int found = 0; |
177 | ||
178 | if (desc_blk == NULL) | |
179 | return 0; | |
180 | ||
181 | for (current = desc_blk->n_max_used; current > 0; current--) { | |
182 | if (desc_blk->block_ptr[current - 1].protocol_family == protocol_family) { | |
183 | found = 1; | |
184 | desc_blk->block_ptr[current - 1].type = 0; | |
185 | desc_blk->n_used--; | |
186 | } | |
187 | } | |
188 | ||
189 | if (desc_blk->n_used == 0) { | |
190 | FREE(ifp->family_cookie, M_IFADDR); | |
191 | ifp->family_cookie = 0; | |
192 | } | |
193 | else { | |
194 | /* Decrement n_max_used */ | |
195 | for (; desc_blk->n_max_used > 0 && desc_blk->block_ptr[desc_blk->n_max_used - 1].type == 0; desc_blk->n_max_used--) | |
196 | ; | |
197 | } | |
198 | ||
199 | return 0; | |
1c79356b A |
200 | } |
201 | ||
202 | ||
91447636 A |
203 | static int |
204 | ether_add_proto_internal( | |
205 | struct ifnet *ifp, | |
206 | protocol_family_t protocol, | |
207 | const struct ifnet_demux_desc *demux) | |
208 | { | |
209 | struct en_desc *ed; | |
210 | struct ether_desc_blk_str *desc_blk = (struct ether_desc_blk_str *)ifp->family_cookie; | |
211 | u_int32_t i; | |
212 | ||
213 | switch (demux->type) { | |
214 | /* These types are supported */ | |
215 | /* Top three are preferred */ | |
216 | case DLIL_DESC_ETYPE2: | |
217 | if (demux->datalen != 2) { | |
218 | return EINVAL; | |
219 | } | |
220 | break; | |
221 | ||
222 | case DLIL_DESC_SAP: | |
223 | if (demux->datalen != 3) { | |
224 | return EINVAL; | |
225 | } | |
226 | break; | |
227 | ||
228 | case DLIL_DESC_SNAP: | |
229 | if (demux->datalen != 5) { | |
230 | return EINVAL; | |
231 | } | |
232 | break; | |
233 | ||
234 | default: | |
235 | return ENOTSUP; | |
236 | } | |
237 | ||
238 | // Verify a matching descriptor does not exist. | |
239 | if (desc_blk != NULL) { | |
240 | switch (demux->type) { | |
241 | case DLIL_DESC_ETYPE2: | |
242 | for (i = 0; i < desc_blk->n_max_used; i++) { | |
243 | if (desc_blk->block_ptr[i].type == DLIL_DESC_ETYPE2 && | |
244 | desc_blk->block_ptr[i].data[0] == | |
245 | *(u_int16_t*)demux->data) { | |
246 | return EADDRINUSE; | |
247 | } | |
248 | } | |
249 | break; | |
250 | case DLIL_DESC_SAP: | |
251 | case DLIL_DESC_SNAP: | |
252 | for (i = 0; i < desc_blk->n_max_used; i++) { | |
253 | if (desc_blk->block_ptr[i].type == demux->type && | |
254 | bcmp(desc_blk->block_ptr[i].data, demux->data, | |
255 | demux->datalen) == 0) { | |
256 | return EADDRINUSE; | |
257 | } | |
258 | } | |
259 | break; | |
260 | } | |
261 | } | |
262 | ||
263 | // Check for case where all of the descriptor blocks are in use | |
264 | if (desc_blk == NULL || desc_blk->n_used == desc_blk->n_count) { | |
265 | struct ether_desc_blk_str *tmp; | |
b0d623f7 A |
266 | u_int32_t new_count = ETHER_DESC_BLK_SIZE; |
267 | u_int32_t new_size; | |
268 | u_int32_t old_size = 0; | |
91447636 A |
269 | |
270 | i = 0; | |
271 | ||
272 | if (desc_blk) { | |
273 | new_count += desc_blk->n_count; | |
274 | old_size = desc_blk->n_count * sizeof(struct en_desc) + ETHER_DESC_HEADER_SIZE; | |
275 | i = desc_blk->n_used; | |
276 | } | |
277 | ||
278 | new_size = new_count * sizeof(struct en_desc) + ETHER_DESC_HEADER_SIZE; | |
279 | ||
280 | tmp = _MALLOC(new_size, M_IFADDR, M_WAITOK); | |
281 | if (tmp == 0) { | |
282 | /* | |
283 | * Remove any previous descriptors set in the call. | |
284 | */ | |
285 | return ENOMEM; | |
286 | } | |
2d21ac55 A |
287 | |
288 | bzero(((char *)tmp) + old_size, new_size - old_size); | |
91447636 A |
289 | if (desc_blk) { |
290 | bcopy(desc_blk, tmp, old_size); | |
291 | FREE(desc_blk, M_IFADDR); | |
292 | } | |
293 | desc_blk = tmp; | |
b0d623f7 | 294 | ifp->family_cookie = (uintptr_t)desc_blk; |
91447636 A |
295 | desc_blk->n_count = new_count; |
296 | } | |
297 | else { | |
298 | /* Find a free entry */ | |
299 | for (i = 0; i < desc_blk->n_count; i++) { | |
300 | if (desc_blk->block_ptr[i].type == 0) { | |
301 | break; | |
302 | } | |
303 | } | |
304 | } | |
305 | ||
306 | /* Bump n_max_used if appropriate */ | |
307 | if (i + 1 > desc_blk->n_max_used) { | |
308 | desc_blk->n_max_used = i + 1; | |
309 | } | |
310 | ||
311 | ed = &desc_blk->block_ptr[i]; | |
312 | ed->protocol_family = protocol; | |
313 | ed->data[0] = 0; | |
314 | ed->data[1] = 0; | |
315 | ||
316 | switch (demux->type) { | |
317 | case DLIL_DESC_ETYPE2: | |
318 | /* 2 byte ethernet raw protocol type is at native_type */ | |
319 | /* prtocol must be in network byte order */ | |
320 | ed->type = DLIL_DESC_ETYPE2; | |
321 | ed->data[0] = *(u_int16_t*)demux->data; | |
322 | break; | |
323 | ||
324 | case DLIL_DESC_SAP: | |
325 | ed->type = DLIL_DESC_SAP; | |
326 | bcopy(demux->data, &ed->data[0], 3); | |
327 | break; | |
328 | ||
329 | case DLIL_DESC_SNAP: { | |
330 | u_int8_t* pDest = ((u_int8_t*)&ed->data[0]) + 3; | |
331 | ed->type = DLIL_DESC_SNAP; | |
332 | bcopy(demux->data, pDest, 5); | |
333 | } | |
334 | break; | |
335 | } | |
336 | ||
337 | desc_blk->n_used++; | |
338 | ||
339 | return 0; | |
340 | } | |
1c79356b | 341 | |
91447636 A |
342 | int |
343 | ether_add_proto( | |
344 | ifnet_t ifp, | |
345 | protocol_family_t protocol, | |
346 | const struct ifnet_demux_desc *demux_list, | |
347 | u_int32_t demux_count) | |
348 | { | |
349 | int error = 0; | |
350 | u_int32_t i; | |
351 | ||
352 | for (i = 0; i < demux_count; i++) { | |
353 | error = ether_add_proto_internal(ifp, protocol, &demux_list[i]); | |
354 | if (error) { | |
355 | ether_del_proto(ifp, protocol); | |
356 | break; | |
357 | } | |
358 | } | |
359 | ||
360 | return error; | |
361 | } | |
4a249263 | 362 | |
91447636 A |
363 | int |
364 | ether_demux( | |
365 | ifnet_t ifp, | |
366 | mbuf_t m, | |
367 | char *frame_header, | |
368 | protocol_family_t *protocol_family) | |
1c79356b | 369 | { |
91447636 A |
370 | struct ether_header *eh = (struct ether_header *)frame_header; |
371 | u_short ether_type = eh->ether_type; | |
372 | u_int16_t type; | |
373 | u_int8_t *data; | |
b0d623f7 | 374 | u_int32_t i = 0; |
91447636 | 375 | struct ether_desc_blk_str *desc_blk = (struct ether_desc_blk_str *)ifp->family_cookie; |
b0d623f7 | 376 | u_int32_t maxd = desc_blk ? desc_blk->n_max_used : 0; |
91447636 A |
377 | struct en_desc *ed = desc_blk ? desc_blk->block_ptr : NULL; |
378 | u_int32_t extProto1 = 0; | |
379 | u_int32_t extProto2 = 0; | |
380 | ||
381 | if (eh->ether_dhost[0] & 1) { | |
382 | /* Check for broadcast */ | |
2d21ac55 | 383 | if (_ether_cmp(etherbroadcastaddr, eh->ether_dhost) == 0) |
91447636 A |
384 | m->m_flags |= M_BCAST; |
385 | else | |
386 | m->m_flags |= M_MCAST; | |
387 | } | |
1c79356b | 388 | |
91447636 A |
389 | if (ifp->if_eflags & IFEF_BOND) { |
390 | /* if we're bonded, bond "protocol" gets all the packets */ | |
391 | *protocol_family = PF_BOND; | |
392 | return (0); | |
393 | } | |
1c79356b | 394 | |
91447636 A |
395 | if ((eh->ether_dhost[0] & 1) == 0) { |
396 | /* | |
2d21ac55 A |
397 | * When the driver is put into promiscuous mode we may receive unicast |
398 | * frames that are not intended for our interfaces. They are marked here | |
399 | * as being promiscuous so the caller may dispose of them after passing | |
400 | * the packets to any interface filters. | |
401 | */ | |
402 | if (_ether_cmp(eh->ether_dhost, ifnet_lladdr(ifp))) { | |
91447636 A |
403 | m->m_flags |= M_PROMISC; |
404 | } | |
405 | } | |
406 | ||
593a1d5f A |
407 | /* check for VLAN */ |
408 | if ((m->m_pkthdr.csum_flags & CSUM_VLAN_TAG_VALID) != 0) { | |
409 | if (EVL_VLANOFTAG(m->m_pkthdr.vlan_tag) != 0) { | |
410 | *protocol_family = PF_VLAN; | |
411 | return (0); | |
412 | } | |
413 | /* the packet is just priority-tagged, clear the bit */ | |
414 | m->m_pkthdr.csum_flags &= ~CSUM_VLAN_TAG_VALID; | |
415 | } | |
416 | else if (ether_type == htons(ETHERTYPE_VLAN)) { | |
417 | struct ether_vlan_header * evl; | |
418 | ||
419 | evl = (struct ether_vlan_header *)frame_header; | |
420 | if (m->m_len < ETHER_VLAN_ENCAP_LEN | |
421 | || ntohs(evl->evl_proto) == ETHERTYPE_VLAN | |
422 | || EVL_VLANOFTAG(ntohs(evl->evl_tag)) != 0) { | |
423 | *protocol_family = PF_VLAN; | |
424 | return 0; | |
425 | } | |
426 | /* the packet is just priority-tagged */ | |
427 | ||
428 | /* make the encapsulated ethertype the actual ethertype */ | |
429 | ether_type = evl->evl_encap_proto = evl->evl_proto; | |
430 | ||
431 | /* remove the encapsulation header */ | |
432 | m->m_len -= ETHER_VLAN_ENCAP_LEN; | |
433 | m->m_data += ETHER_VLAN_ENCAP_LEN; | |
434 | m->m_pkthdr.len -= ETHER_VLAN_ENCAP_LEN; | |
435 | m->m_pkthdr.csum_flags = 0; /* can't trust hardware checksum */ | |
91447636 A |
436 | } |
437 | ||
438 | data = mtod(m, u_int8_t*); | |
439 | ||
440 | /* | |
441 | * Determine the packet's protocol type and stuff the protocol into | |
442 | * longs for quick compares. | |
443 | */ | |
444 | ||
445 | if (ntohs(ether_type) <= 1500) { | |
446 | extProto1 = *(u_int32_t*)data; | |
447 | ||
448 | // SAP or SNAP | |
449 | if ((extProto1 & htonl(0xFFFFFF00)) == htonl(0xAAAA0300)) { | |
450 | // SNAP | |
451 | type = DLIL_DESC_SNAP; | |
452 | extProto2 = *(u_int32_t*)(data + sizeof(u_int32_t)); | |
453 | extProto1 &= htonl(0x000000FF); | |
454 | } else { | |
455 | type = DLIL_DESC_SAP; | |
456 | extProto1 &= htonl(0xFFFFFF00); | |
457 | } | |
458 | } else { | |
459 | type = DLIL_DESC_ETYPE2; | |
460 | } | |
461 | ||
462 | /* | |
463 | * Search through the connected protocols for a match. | |
464 | */ | |
465 | ||
466 | switch (type) { | |
467 | case DLIL_DESC_ETYPE2: | |
468 | for (i = 0; i < maxd; i++) { | |
469 | if ((ed[i].type == type) && (ed[i].data[0] == ether_type)) { | |
470 | *protocol_family = ed[i].protocol_family; | |
471 | return 0; | |
472 | } | |
473 | } | |
474 | break; | |
475 | ||
476 | case DLIL_DESC_SAP: | |
477 | for (i = 0; i < maxd; i++) { | |
478 | if ((ed[i].type == type) && (ed[i].data[0] == extProto1)) { | |
479 | *protocol_family = ed[i].protocol_family; | |
480 | return 0; | |
481 | } | |
482 | } | |
483 | break; | |
484 | ||
485 | case DLIL_DESC_SNAP: | |
486 | for (i = 0; i < maxd; i++) { | |
487 | if ((ed[i].type == type) && (ed[i].data[0] == extProto1) && | |
488 | (ed[i].data[1] == extProto2)) { | |
489 | *protocol_family = ed[i].protocol_family; | |
490 | return 0; | |
491 | } | |
492 | } | |
493 | break; | |
494 | } | |
495 | ||
496 | return ENOENT; | |
497 | } | |
1c79356b A |
498 | |
499 | /* | |
500 | * Ethernet output routine. | |
501 | * Encapsulate a packet of type family for the local net. | |
502 | * Use trailer local net encapsulation if enough data in first | |
503 | * packet leaves a multiple of 512 bytes of data in remainder. | |
1c79356b A |
504 | */ |
505 | int | |
91447636 A |
506 | ether_frameout( |
507 | struct ifnet *ifp, | |
508 | struct mbuf **m, | |
509 | const struct sockaddr *ndest, | |
510 | const char *edst, | |
511 | const char *ether_type) | |
1c79356b | 512 | { |
91447636 | 513 | struct ether_header *eh; |
4a249263 | 514 | int hlen; /* link layer header length */ |
1c79356b A |
515 | |
516 | hlen = ETHER_HDR_LEN; | |
517 | ||
518 | /* | |
519 | * If a simplex interface, and the packet is being sent to our | |
520 | * Ethernet address or a broadcast address, loopback a copy. | |
521 | * XXX To make a simplex device behave exactly like a duplex | |
522 | * device, we should copy in the case of sending to our own | |
523 | * ethernet address (thus letting the original actually appear | |
524 | * on the wire). However, we don't do that here for security | |
525 | * reasons and compatibility with the original behavior. | |
526 | */ | |
527 | if ((ifp->if_flags & IFF_SIMPLEX) && | |
528 | ((*m)->m_flags & M_LOOP)) { | |
91447636 | 529 | if (lo_ifp) { |
7b1edb79 A |
530 | if ((*m)->m_flags & M_BCAST) { |
531 | struct mbuf *n = m_copy(*m, 0, (int)M_COPYALL); | |
532 | if (n != NULL) | |
2d21ac55 | 533 | dlil_output(lo_ifp, ndest->sa_family, n, NULL, ndest, 0); |
91447636 A |
534 | } |
535 | else { | |
2d21ac55 A |
536 | if (_ether_cmp(edst, ifnet_lladdr(ifp)) == 0) { |
537 | dlil_output(lo_ifp, ndest->sa_family, *m, NULL, ndest, 0); | |
7b1edb79 A |
538 | return EJUSTRETURN; |
539 | } | |
540 | } | |
1c79356b A |
541 | } |
542 | } | |
7b1edb79 | 543 | |
1c79356b A |
544 | /* |
545 | * Add local net header. If no space in first mbuf, | |
546 | * allocate another. | |
547 | */ | |
548 | M_PREPEND(*m, sizeof (struct ether_header), M_DONTWAIT); | |
549 | if (*m == 0) { | |
550 | return (EJUSTRETURN); | |
551 | } | |
552 | ||
553 | ||
554 | eh = mtod(*m, struct ether_header *); | |
555 | (void)memcpy(&eh->ether_type, ether_type, | |
556 | sizeof(eh->ether_type)); | |
2d21ac55 | 557 | (void)memcpy(eh->ether_dhost, edst, ETHER_ADDR_LEN); |
91447636 | 558 | ifnet_lladdr_copy_bytes(ifp, eh->ether_shost, ETHER_ADDR_LEN); |
1c79356b A |
559 | |
560 | return 0; | |
561 | } | |
562 | ||
91447636 A |
563 | errno_t |
564 | ether_check_multi( | |
2d21ac55 | 565 | __unused ifnet_t ifp, |
91447636 A |
566 | const struct sockaddr *proto_addr) |
567 | { | |
568 | errno_t result = EAFNOSUPPORT; | |
569 | const u_char *e_addr; | |
570 | ||
571 | /* | |
572 | * AF_SPEC and AF_LINK don't require translation. We do | |
573 | * want to verify that they specify a valid multicast. | |
574 | */ | |
575 | switch(proto_addr->sa_family) { | |
576 | case AF_UNSPEC: | |
577 | e_addr = (const u_char*)&proto_addr->sa_data[0]; | |
578 | if ((e_addr[0] & 0x01) != 0x01) | |
579 | result = EADDRNOTAVAIL; | |
580 | else | |
581 | result = 0; | |
582 | break; | |
583 | ||
584 | case AF_LINK: | |
585 | e_addr = CONST_LLADDR((const struct sockaddr_dl*)proto_addr); | |
586 | if ((e_addr[0] & 0x01) != 0x01) | |
587 | result = EADDRNOTAVAIL; | |
588 | else | |
589 | result = 0; | |
590 | break; | |
591 | } | |
592 | ||
593 | return result; | |
594 | } | |
595 | ||
1c79356b | 596 | int |
91447636 A |
597 | ether_ioctl( |
598 | __unused ifnet_t ifp, | |
599 | __unused u_int32_t command, | |
600 | __unused void* data) | |
1c79356b | 601 | { |
91447636 | 602 | return EOPNOTSUPP; |
1c79356b A |
603 | } |
604 | ||
2d21ac55 | 605 | __private_extern__ int ether_family_init(void) |
1c79356b | 606 | { |
2d21ac55 A |
607 | errno_t error = 0; |
608 | ||
91447636 | 609 | /* Register protocol registration functions */ |
2d21ac55 | 610 | if ((error = proto_register_plumber(PF_INET, APPLE_IF_FAM_ETHERNET, |
91447636 | 611 | ether_attach_inet, ether_detach_inet)) != 0) { |
2d21ac55 | 612 | printf("proto_register_plumber failed for PF_INET error=%d\n", error); |
91447636 A |
613 | goto done; |
614 | } | |
2d21ac55 A |
615 | #if INET6 |
616 | if ((error = proto_register_plumber(PF_INET6, APPLE_IF_FAM_ETHERNET, | |
91447636 | 617 | ether_attach_inet6, ether_detach_inet6)) != 0) { |
2d21ac55 A |
618 | printf("proto_register_plumber failed for PF_INET6 error=%d\n", error); |
619 | goto done; | |
620 | } | |
621 | #endif /* INET6 */ | |
622 | #if NETAT | |
623 | if ((error = proto_register_plumber(PF_APPLETALK, APPLE_IF_FAM_ETHERNET, | |
624 | ether_attach_at, ether_detach_at)) != 0) { | |
625 | printf("proto_register_plumber failed PF_APPLETALK error=%d\n", error); | |
91447636 A |
626 | goto done; |
627 | } | |
2d21ac55 A |
628 | #endif /* NETAT */ |
629 | #if VLAN | |
91447636 | 630 | vlan_family_init(); |
2d21ac55 A |
631 | #endif /* VLAN */ |
632 | #if BOND | |
91447636 | 633 | bond_family_init(); |
2d21ac55 | 634 | #endif /* BOND */ |
55e303ae | 635 | |
4a249263 | 636 | done: |
9bccf70c | 637 | |
55e303ae | 638 | return (error); |
1c79356b | 639 | } |