1*19c3b8c2SApple OSS Distributions /*
2*19c3b8c2SApple OSS Distributions * Copyright (c) 2000-2021 Apple Inc. All rights reserved.
3*19c3b8c2SApple OSS Distributions *
4*19c3b8c2SApple OSS Distributions * @APPLE_OSREFERENCE_LICENSE_HEADER_START@
5*19c3b8c2SApple OSS Distributions *
6*19c3b8c2SApple OSS Distributions * This file contains Original Code and/or Modifications of Original Code
7*19c3b8c2SApple OSS Distributions * as defined in and that are subject to the Apple Public Source License
8*19c3b8c2SApple OSS Distributions * Version 2.0 (the 'License'). You may not use this file except in
9*19c3b8c2SApple OSS Distributions * compliance with the License. The rights granted to you under the License
10*19c3b8c2SApple OSS Distributions * may not be used to create, or enable the creation or redistribution of,
11*19c3b8c2SApple OSS Distributions * unlawful or unlicensed copies of an Apple operating system, or to
12*19c3b8c2SApple OSS Distributions * circumvent, violate, or enable the circumvention or violation of, any
13*19c3b8c2SApple OSS Distributions * terms of an Apple operating system software license agreement.
14*19c3b8c2SApple OSS Distributions *
15*19c3b8c2SApple OSS Distributions * Please obtain a copy of the License at
16*19c3b8c2SApple OSS Distributions * http://www.opensource.apple.com/apsl/ and read it before using this file.
17*19c3b8c2SApple OSS Distributions *
18*19c3b8c2SApple OSS Distributions * The Original Code and all software distributed under the License are
19*19c3b8c2SApple OSS Distributions * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
20*19c3b8c2SApple OSS Distributions * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
21*19c3b8c2SApple OSS Distributions * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
22*19c3b8c2SApple OSS Distributions * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
23*19c3b8c2SApple OSS Distributions * Please see the License for the specific language governing rights and
24*19c3b8c2SApple OSS Distributions * limitations under the License.
25*19c3b8c2SApple OSS Distributions *
26*19c3b8c2SApple OSS Distributions * @APPLE_OSREFERENCE_LICENSE_HEADER_END@
27*19c3b8c2SApple OSS Distributions */
28*19c3b8c2SApple OSS Distributions /*
29*19c3b8c2SApple OSS Distributions * Copyright (c) 1982, 1989, 1993
30*19c3b8c2SApple OSS Distributions * The Regents of the University of California. All rights reserved.
31*19c3b8c2SApple OSS Distributions *
32*19c3b8c2SApple OSS Distributions * Redistribution and use in source and binary forms, with or without
33*19c3b8c2SApple OSS Distributions * modification, are permitted provided that the following conditions
34*19c3b8c2SApple OSS Distributions * are met:
35*19c3b8c2SApple OSS Distributions * 1. Redistributions of source code must retain the above copyright
36*19c3b8c2SApple OSS Distributions * notice, this list of conditions and the following disclaimer.
37*19c3b8c2SApple OSS Distributions * 2. Redistributions in binary form must reproduce the above copyright
38*19c3b8c2SApple OSS Distributions * notice, this list of conditions and the following disclaimer in the
39*19c3b8c2SApple OSS Distributions * documentation and/or other materials provided with the distribution.
40*19c3b8c2SApple OSS Distributions * 3. All advertising materials mentioning features or use of this software
41*19c3b8c2SApple OSS Distributions * must display the following acknowledgement:
42*19c3b8c2SApple OSS Distributions * This product includes software developed by the University of
43*19c3b8c2SApple OSS Distributions * California, Berkeley and its contributors.
44*19c3b8c2SApple OSS Distributions * 4. Neither the name of the University nor the names of its contributors
45*19c3b8c2SApple OSS Distributions * may be used to endorse or promote products derived from this software
46*19c3b8c2SApple OSS Distributions * without specific prior written permission.
47*19c3b8c2SApple OSS Distributions *
48*19c3b8c2SApple OSS Distributions * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
49*19c3b8c2SApple OSS Distributions * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
50*19c3b8c2SApple OSS Distributions * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
51*19c3b8c2SApple OSS Distributions * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
52*19c3b8c2SApple OSS Distributions * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
53*19c3b8c2SApple OSS Distributions * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
54*19c3b8c2SApple OSS Distributions * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
55*19c3b8c2SApple OSS Distributions * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
56*19c3b8c2SApple OSS Distributions * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
57*19c3b8c2SApple OSS Distributions * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
58*19c3b8c2SApple OSS Distributions * SUCH DAMAGE.
59*19c3b8c2SApple OSS Distributions *
60*19c3b8c2SApple OSS Distributions */
61*19c3b8c2SApple OSS Distributions
62*19c3b8c2SApple OSS Distributions #include <sys/param.h>
63*19c3b8c2SApple OSS Distributions #include <sys/systm.h>
64*19c3b8c2SApple OSS Distributions #include <sys/kernel.h>
65*19c3b8c2SApple OSS Distributions #include <sys/malloc.h>
66*19c3b8c2SApple OSS Distributions #include <sys/mbuf.h>
67*19c3b8c2SApple OSS Distributions #include <sys/socket.h>
68*19c3b8c2SApple OSS Distributions #include <sys/sockio.h>
69*19c3b8c2SApple OSS Distributions #include <sys/sysctl.h>
70*19c3b8c2SApple OSS Distributions
71*19c3b8c2SApple OSS Distributions #include <pexpert/pexpert.h>
72*19c3b8c2SApple OSS Distributions
73*19c3b8c2SApple OSS Distributions #define etherbroadcastaddr fugly
74*19c3b8c2SApple OSS Distributions #include <net/if.h>
75*19c3b8c2SApple OSS Distributions #include <net/route.h>
76*19c3b8c2SApple OSS Distributions #include <net/if_llc.h>
77*19c3b8c2SApple OSS Distributions #include <net/if_dl.h>
78*19c3b8c2SApple OSS Distributions #include <net/if_types.h>
79*19c3b8c2SApple OSS Distributions #include <net/if_ether.h>
80*19c3b8c2SApple OSS Distributions #include <net/if_gif.h>
81*19c3b8c2SApple OSS Distributions #include <netinet/if_ether.h>
82*19c3b8c2SApple OSS Distributions #include <netinet/in.h> /* For M_LOOP */
83*19c3b8c2SApple OSS Distributions #include <net/kpi_interface.h>
84*19c3b8c2SApple OSS Distributions #include <net/kpi_protocol.h>
85*19c3b8c2SApple OSS Distributions #undef etherbroadcastaddr
86*19c3b8c2SApple OSS Distributions
87*19c3b8c2SApple OSS Distributions /*
88*19c3b8c2SApple OSS Distributions #if INET
89*19c3b8c2SApple OSS Distributions #include <netinet/in.h>
90*19c3b8c2SApple OSS Distributions #include <netinet/in_var.h>
91*19c3b8c2SApple OSS Distributions *
92*19c3b8c2SApple OSS Distributions #include <netinet/in_systm.h>
93*19c3b8c2SApple OSS Distributions #include <netinet/ip.h>
94*19c3b8c2SApple OSS Distributions #endif
95*19c3b8c2SApple OSS Distributions */
96*19c3b8c2SApple OSS Distributions #include <net/ether_if_module.h>
97*19c3b8c2SApple OSS Distributions #include <sys/socketvar.h>
98*19c3b8c2SApple OSS Distributions #include <net/if_vlan_var.h>
99*19c3b8c2SApple OSS Distributions #if BOND
100*19c3b8c2SApple OSS Distributions #include <net/if_bond_internal.h>
101*19c3b8c2SApple OSS Distributions #endif /* BOND */
102*19c3b8c2SApple OSS Distributions #if IF_BRIDGE
103*19c3b8c2SApple OSS Distributions #include <net/if_bridgevar.h>
104*19c3b8c2SApple OSS Distributions #endif /* IF_BRIDGE */
105*19c3b8c2SApple OSS Distributions #if IF_FAKE
106*19c3b8c2SApple OSS Distributions #include <net/if_fake_var.h>
107*19c3b8c2SApple OSS Distributions #endif /* IF_FAKE */
108*19c3b8c2SApple OSS Distributions #if IF_HEADLESS
109*19c3b8c2SApple OSS Distributions extern void if_headless_init(void);
110*19c3b8c2SApple OSS Distributions #endif /* IF_HEADLESS */
111*19c3b8c2SApple OSS Distributions
112*19c3b8c2SApple OSS Distributions #include <net/dlil.h>
113*19c3b8c2SApple OSS Distributions
114*19c3b8c2SApple OSS Distributions SYSCTL_DECL(_net_link);
115*19c3b8c2SApple OSS Distributions SYSCTL_NODE(_net_link, IFT_ETHER, ether, CTLFLAG_RW | CTLFLAG_LOCKED, 0,
116*19c3b8c2SApple OSS Distributions "Ethernet");
117*19c3b8c2SApple OSS Distributions
118*19c3b8c2SApple OSS Distributions struct en_desc {
119*19c3b8c2SApple OSS Distributions u_int16_t type; /* Type of protocol stored in data */
120*19c3b8c2SApple OSS Distributions u_int32_t protocol_family; /* Protocol family */
121*19c3b8c2SApple OSS Distributions u_int32_t data[2]; /* Protocol data */
122*19c3b8c2SApple OSS Distributions };
123*19c3b8c2SApple OSS Distributions
124*19c3b8c2SApple OSS Distributions /* descriptors are allocated in blocks of ETHER_DESC_BLK_SIZE */
125*19c3b8c2SApple OSS Distributions #if !XNU_TARGET_OS_OSX
126*19c3b8c2SApple OSS Distributions #define ETHER_DESC_BLK_SIZE (2) /* IP, ARP */
127*19c3b8c2SApple OSS Distributions #else /* XNU_TARGET_OS_OSX */
128*19c3b8c2SApple OSS Distributions #define ETHER_DESC_BLK_SIZE (10)
129*19c3b8c2SApple OSS Distributions #endif /* XNU_TARGET_OS_OSX */
130*19c3b8c2SApple OSS Distributions
131*19c3b8c2SApple OSS Distributions /*
132*19c3b8c2SApple OSS Distributions * Header for the demux list, hangs off of IFP at if_family_cookie
133*19c3b8c2SApple OSS Distributions */
134*19c3b8c2SApple OSS Distributions struct ether_desc_blk_str {
135*19c3b8c2SApple OSS Distributions u_int32_t n_max_used;
136*19c3b8c2SApple OSS Distributions u_int32_t n_count;
137*19c3b8c2SApple OSS Distributions u_int32_t n_used;
138*19c3b8c2SApple OSS Distributions struct en_desc block_ptr[1];
139*19c3b8c2SApple OSS Distributions };
140*19c3b8c2SApple OSS Distributions
141*19c3b8c2SApple OSS Distributions /* Size of the above struct before the array of struct en_desc */
142*19c3b8c2SApple OSS Distributions #define ETHER_DESC_HEADER_SIZE \
143*19c3b8c2SApple OSS Distributions ((size_t) offsetof(struct ether_desc_blk_str, block_ptr))
144*19c3b8c2SApple OSS Distributions
145*19c3b8c2SApple OSS Distributions __private_extern__ u_char etherbroadcastaddr[ETHER_ADDR_LEN] =
146*19c3b8c2SApple OSS Distributions { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff };
147*19c3b8c2SApple OSS Distributions
148*19c3b8c2SApple OSS Distributions /*
149*19c3b8c2SApple OSS Distributions * Release all descriptor entries owned by this protocol (there may be several).
150*19c3b8c2SApple OSS Distributions * Setting the type to 0 releases the entry. Eventually we should compact-out
151*19c3b8c2SApple OSS Distributions * the unused entries.
152*19c3b8c2SApple OSS Distributions */
153*19c3b8c2SApple OSS Distributions int
ether_del_proto(ifnet_t ifp,protocol_family_t protocol_family)154*19c3b8c2SApple OSS Distributions ether_del_proto(ifnet_t ifp, protocol_family_t protocol_family)
155*19c3b8c2SApple OSS Distributions {
156*19c3b8c2SApple OSS Distributions struct ether_desc_blk_str *desc_blk =
157*19c3b8c2SApple OSS Distributions (struct ether_desc_blk_str *)ifp->if_family_cookie;
158*19c3b8c2SApple OSS Distributions u_int32_t current = 0;
159*19c3b8c2SApple OSS Distributions int found = 0;
160*19c3b8c2SApple OSS Distributions
161*19c3b8c2SApple OSS Distributions if (desc_blk == NULL) {
162*19c3b8c2SApple OSS Distributions return 0;
163*19c3b8c2SApple OSS Distributions }
164*19c3b8c2SApple OSS Distributions
165*19c3b8c2SApple OSS Distributions for (current = desc_blk->n_max_used; current > 0; current--) {
166*19c3b8c2SApple OSS Distributions if (desc_blk->block_ptr[current - 1].protocol_family ==
167*19c3b8c2SApple OSS Distributions protocol_family) {
168*19c3b8c2SApple OSS Distributions found = 1;
169*19c3b8c2SApple OSS Distributions desc_blk->block_ptr[current - 1].type = 0;
170*19c3b8c2SApple OSS Distributions desc_blk->n_used--;
171*19c3b8c2SApple OSS Distributions }
172*19c3b8c2SApple OSS Distributions }
173*19c3b8c2SApple OSS Distributions
174*19c3b8c2SApple OSS Distributions if (desc_blk->n_used == 0) {
175*19c3b8c2SApple OSS Distributions u_int32_t size = desc_blk->n_count * sizeof(struct en_desc) +
176*19c3b8c2SApple OSS Distributions ETHER_DESC_HEADER_SIZE;
177*19c3b8c2SApple OSS Distributions kfree_data(ifp->if_family_cookie, size);
178*19c3b8c2SApple OSS Distributions ifp->if_family_cookie = 0;
179*19c3b8c2SApple OSS Distributions } else {
180*19c3b8c2SApple OSS Distributions /* Decrement n_max_used */
181*19c3b8c2SApple OSS Distributions for (; desc_blk->n_max_used > 0 &&
182*19c3b8c2SApple OSS Distributions desc_blk->block_ptr[desc_blk->n_max_used - 1].type == 0;
183*19c3b8c2SApple OSS Distributions desc_blk->n_max_used--) {
184*19c3b8c2SApple OSS Distributions ;
185*19c3b8c2SApple OSS Distributions }
186*19c3b8c2SApple OSS Distributions }
187*19c3b8c2SApple OSS Distributions
188*19c3b8c2SApple OSS Distributions return 0;
189*19c3b8c2SApple OSS Distributions }
190*19c3b8c2SApple OSS Distributions
191*19c3b8c2SApple OSS Distributions static int
ether_add_proto_internal(struct ifnet * ifp,protocol_family_t protocol,const struct ifnet_demux_desc * demux)192*19c3b8c2SApple OSS Distributions ether_add_proto_internal(struct ifnet *ifp, protocol_family_t protocol,
193*19c3b8c2SApple OSS Distributions const struct ifnet_demux_desc *demux)
194*19c3b8c2SApple OSS Distributions {
195*19c3b8c2SApple OSS Distributions struct en_desc *ed;
196*19c3b8c2SApple OSS Distributions struct ether_desc_blk_str *desc_blk =
197*19c3b8c2SApple OSS Distributions (struct ether_desc_blk_str *)ifp->if_family_cookie;
198*19c3b8c2SApple OSS Distributions u_int32_t i;
199*19c3b8c2SApple OSS Distributions
200*19c3b8c2SApple OSS Distributions switch (demux->type) {
201*19c3b8c2SApple OSS Distributions /* These types are supported */
202*19c3b8c2SApple OSS Distributions /* Top three are preferred */
203*19c3b8c2SApple OSS Distributions case DLIL_DESC_ETYPE2:
204*19c3b8c2SApple OSS Distributions if (demux->datalen != 2) {
205*19c3b8c2SApple OSS Distributions return EINVAL;
206*19c3b8c2SApple OSS Distributions }
207*19c3b8c2SApple OSS Distributions break;
208*19c3b8c2SApple OSS Distributions
209*19c3b8c2SApple OSS Distributions case DLIL_DESC_SAP:
210*19c3b8c2SApple OSS Distributions if (demux->datalen != 3) {
211*19c3b8c2SApple OSS Distributions return EINVAL;
212*19c3b8c2SApple OSS Distributions }
213*19c3b8c2SApple OSS Distributions break;
214*19c3b8c2SApple OSS Distributions
215*19c3b8c2SApple OSS Distributions case DLIL_DESC_SNAP:
216*19c3b8c2SApple OSS Distributions if (demux->datalen != 5) {
217*19c3b8c2SApple OSS Distributions return EINVAL;
218*19c3b8c2SApple OSS Distributions }
219*19c3b8c2SApple OSS Distributions break;
220*19c3b8c2SApple OSS Distributions
221*19c3b8c2SApple OSS Distributions default:
222*19c3b8c2SApple OSS Distributions return ENOTSUP;
223*19c3b8c2SApple OSS Distributions }
224*19c3b8c2SApple OSS Distributions
225*19c3b8c2SApple OSS Distributions /* Verify a matching descriptor does not exist */
226*19c3b8c2SApple OSS Distributions if (desc_blk != NULL) {
227*19c3b8c2SApple OSS Distributions switch (demux->type) {
228*19c3b8c2SApple OSS Distributions case DLIL_DESC_ETYPE2:
229*19c3b8c2SApple OSS Distributions for (i = 0; i < desc_blk->n_max_used; i++) {
230*19c3b8c2SApple OSS Distributions if (desc_blk->block_ptr[i].type ==
231*19c3b8c2SApple OSS Distributions DLIL_DESC_ETYPE2 &&
232*19c3b8c2SApple OSS Distributions desc_blk->block_ptr[i].data[0] ==
233*19c3b8c2SApple OSS Distributions *(u_int16_t*)demux->data) {
234*19c3b8c2SApple OSS Distributions return EADDRINUSE;
235*19c3b8c2SApple OSS Distributions }
236*19c3b8c2SApple OSS Distributions }
237*19c3b8c2SApple OSS Distributions break;
238*19c3b8c2SApple OSS Distributions case DLIL_DESC_SAP:
239*19c3b8c2SApple OSS Distributions case DLIL_DESC_SNAP:
240*19c3b8c2SApple OSS Distributions for (i = 0; i < desc_blk->n_max_used; i++) {
241*19c3b8c2SApple OSS Distributions if (desc_blk->block_ptr[i].type ==
242*19c3b8c2SApple OSS Distributions demux->type &&
243*19c3b8c2SApple OSS Distributions bcmp(desc_blk->block_ptr[i].data,
244*19c3b8c2SApple OSS Distributions demux->data, demux->datalen) == 0) {
245*19c3b8c2SApple OSS Distributions return EADDRINUSE;
246*19c3b8c2SApple OSS Distributions }
247*19c3b8c2SApple OSS Distributions }
248*19c3b8c2SApple OSS Distributions break;
249*19c3b8c2SApple OSS Distributions }
250*19c3b8c2SApple OSS Distributions }
251*19c3b8c2SApple OSS Distributions
252*19c3b8c2SApple OSS Distributions /* Check for case where all of the descriptor blocks are in use */
253*19c3b8c2SApple OSS Distributions if (desc_blk == NULL || desc_blk->n_used == desc_blk->n_count) {
254*19c3b8c2SApple OSS Distributions struct ether_desc_blk_str *tmp;
255*19c3b8c2SApple OSS Distributions u_int32_t new_count = ETHER_DESC_BLK_SIZE;
256*19c3b8c2SApple OSS Distributions u_int32_t new_size;
257*19c3b8c2SApple OSS Distributions u_int32_t old_size = 0;
258*19c3b8c2SApple OSS Distributions
259*19c3b8c2SApple OSS Distributions i = 0;
260*19c3b8c2SApple OSS Distributions
261*19c3b8c2SApple OSS Distributions if (desc_blk) {
262*19c3b8c2SApple OSS Distributions new_count += desc_blk->n_count;
263*19c3b8c2SApple OSS Distributions old_size = desc_blk->n_count * sizeof(struct en_desc) +
264*19c3b8c2SApple OSS Distributions ETHER_DESC_HEADER_SIZE;
265*19c3b8c2SApple OSS Distributions i = desc_blk->n_used;
266*19c3b8c2SApple OSS Distributions }
267*19c3b8c2SApple OSS Distributions
268*19c3b8c2SApple OSS Distributions new_size = new_count * sizeof(struct en_desc) +
269*19c3b8c2SApple OSS Distributions ETHER_DESC_HEADER_SIZE;
270*19c3b8c2SApple OSS Distributions
271*19c3b8c2SApple OSS Distributions tmp = (struct ether_desc_blk_str *)kalloc_data(new_size, Z_WAITOK);
272*19c3b8c2SApple OSS Distributions if (tmp == NULL) {
273*19c3b8c2SApple OSS Distributions /*
274*19c3b8c2SApple OSS Distributions * Remove any previous descriptors set in the call.
275*19c3b8c2SApple OSS Distributions */
276*19c3b8c2SApple OSS Distributions return ENOMEM;
277*19c3b8c2SApple OSS Distributions }
278*19c3b8c2SApple OSS Distributions
279*19c3b8c2SApple OSS Distributions bzero(((char *)tmp) + old_size, new_size - old_size);
280*19c3b8c2SApple OSS Distributions if (desc_blk) {
281*19c3b8c2SApple OSS Distributions bcopy(desc_blk, tmp, old_size);
282*19c3b8c2SApple OSS Distributions kfree_data(desc_blk, old_size);
283*19c3b8c2SApple OSS Distributions }
284*19c3b8c2SApple OSS Distributions desc_blk = tmp;
285*19c3b8c2SApple OSS Distributions ifp->if_family_cookie = (uintptr_t)desc_blk;
286*19c3b8c2SApple OSS Distributions desc_blk->n_count = new_count;
287*19c3b8c2SApple OSS Distributions } else {
288*19c3b8c2SApple OSS Distributions /* Find a free entry */
289*19c3b8c2SApple OSS Distributions for (i = 0; i < desc_blk->n_count; i++) {
290*19c3b8c2SApple OSS Distributions if (desc_blk->block_ptr[i].type == 0) {
291*19c3b8c2SApple OSS Distributions break;
292*19c3b8c2SApple OSS Distributions }
293*19c3b8c2SApple OSS Distributions }
294*19c3b8c2SApple OSS Distributions }
295*19c3b8c2SApple OSS Distributions
296*19c3b8c2SApple OSS Distributions /* Bump n_max_used if appropriate */
297*19c3b8c2SApple OSS Distributions if (i + 1 > desc_blk->n_max_used) {
298*19c3b8c2SApple OSS Distributions desc_blk->n_max_used = i + 1;
299*19c3b8c2SApple OSS Distributions }
300*19c3b8c2SApple OSS Distributions
301*19c3b8c2SApple OSS Distributions ed = &desc_blk->block_ptr[i];
302*19c3b8c2SApple OSS Distributions ed->protocol_family = protocol;
303*19c3b8c2SApple OSS Distributions ed->data[0] = 0;
304*19c3b8c2SApple OSS Distributions ed->data[1] = 0;
305*19c3b8c2SApple OSS Distributions
306*19c3b8c2SApple OSS Distributions switch (demux->type) {
307*19c3b8c2SApple OSS Distributions case DLIL_DESC_ETYPE2:
308*19c3b8c2SApple OSS Distributions /* 2 byte ethernet raw protocol type is at native_type */
309*19c3b8c2SApple OSS Distributions /* prtocol must be in network byte order */
310*19c3b8c2SApple OSS Distributions ed->type = DLIL_DESC_ETYPE2;
311*19c3b8c2SApple OSS Distributions ed->data[0] = *(u_int16_t*)demux->data;
312*19c3b8c2SApple OSS Distributions break;
313*19c3b8c2SApple OSS Distributions
314*19c3b8c2SApple OSS Distributions case DLIL_DESC_SAP:
315*19c3b8c2SApple OSS Distributions ed->type = DLIL_DESC_SAP;
316*19c3b8c2SApple OSS Distributions bcopy(demux->data, &ed->data[0], 3);
317*19c3b8c2SApple OSS Distributions break;
318*19c3b8c2SApple OSS Distributions
319*19c3b8c2SApple OSS Distributions case DLIL_DESC_SNAP: {
320*19c3b8c2SApple OSS Distributions u_int8_t* pDest = ((u_int8_t*)&ed->data[0]) + 3;
321*19c3b8c2SApple OSS Distributions ed->type = DLIL_DESC_SNAP;
322*19c3b8c2SApple OSS Distributions bcopy(demux->data, pDest, 5);
323*19c3b8c2SApple OSS Distributions break;
324*19c3b8c2SApple OSS Distributions }
325*19c3b8c2SApple OSS Distributions }
326*19c3b8c2SApple OSS Distributions
327*19c3b8c2SApple OSS Distributions desc_blk->n_used++;
328*19c3b8c2SApple OSS Distributions
329*19c3b8c2SApple OSS Distributions return 0;
330*19c3b8c2SApple OSS Distributions }
331*19c3b8c2SApple OSS Distributions
332*19c3b8c2SApple OSS Distributions int
ether_add_proto(ifnet_t ifp,protocol_family_t protocol,const struct ifnet_demux_desc * demux_list,u_int32_t demux_count)333*19c3b8c2SApple OSS Distributions ether_add_proto(ifnet_t ifp, protocol_family_t protocol,
334*19c3b8c2SApple OSS Distributions const struct ifnet_demux_desc *demux_list, u_int32_t demux_count)
335*19c3b8c2SApple OSS Distributions {
336*19c3b8c2SApple OSS Distributions int error = 0;
337*19c3b8c2SApple OSS Distributions u_int32_t i;
338*19c3b8c2SApple OSS Distributions
339*19c3b8c2SApple OSS Distributions for (i = 0; i < demux_count; i++) {
340*19c3b8c2SApple OSS Distributions error = ether_add_proto_internal(ifp, protocol, &demux_list[i]);
341*19c3b8c2SApple OSS Distributions if (error) {
342*19c3b8c2SApple OSS Distributions ether_del_proto(ifp, protocol);
343*19c3b8c2SApple OSS Distributions break;
344*19c3b8c2SApple OSS Distributions }
345*19c3b8c2SApple OSS Distributions }
346*19c3b8c2SApple OSS Distributions
347*19c3b8c2SApple OSS Distributions return error;
348*19c3b8c2SApple OSS Distributions }
349*19c3b8c2SApple OSS Distributions
350*19c3b8c2SApple OSS Distributions int
ether_demux(ifnet_t ifp,mbuf_t m,char * frame_header,protocol_family_t * protocol_family)351*19c3b8c2SApple OSS Distributions ether_demux(ifnet_t ifp, mbuf_t m, char *frame_header,
352*19c3b8c2SApple OSS Distributions protocol_family_t *protocol_family)
353*19c3b8c2SApple OSS Distributions {
354*19c3b8c2SApple OSS Distributions struct ether_header *eh = (struct ether_header *)(void *)frame_header;
355*19c3b8c2SApple OSS Distributions u_short ether_type = eh->ether_type;
356*19c3b8c2SApple OSS Distributions u_int16_t type;
357*19c3b8c2SApple OSS Distributions u_int8_t *data;
358*19c3b8c2SApple OSS Distributions u_int32_t i = 0;
359*19c3b8c2SApple OSS Distributions struct ether_desc_blk_str *desc_blk =
360*19c3b8c2SApple OSS Distributions (struct ether_desc_blk_str *)ifp->if_family_cookie;
361*19c3b8c2SApple OSS Distributions u_int32_t maxd = desc_blk ? desc_blk->n_max_used : 0;
362*19c3b8c2SApple OSS Distributions struct en_desc *ed = desc_blk ? desc_blk->block_ptr : NULL;
363*19c3b8c2SApple OSS Distributions u_int32_t extProto1 = 0;
364*19c3b8c2SApple OSS Distributions u_int32_t extProto2 = 0;
365*19c3b8c2SApple OSS Distributions
366*19c3b8c2SApple OSS Distributions if (eh->ether_dhost[0] & 1) {
367*19c3b8c2SApple OSS Distributions /* Check for broadcast */
368*19c3b8c2SApple OSS Distributions if (_ether_cmp(etherbroadcastaddr, eh->ether_dhost) == 0) {
369*19c3b8c2SApple OSS Distributions m->m_flags |= M_BCAST;
370*19c3b8c2SApple OSS Distributions } else {
371*19c3b8c2SApple OSS Distributions m->m_flags |= M_MCAST;
372*19c3b8c2SApple OSS Distributions }
373*19c3b8c2SApple OSS Distributions }
374*19c3b8c2SApple OSS Distributions
375*19c3b8c2SApple OSS Distributions if (m->m_flags & M_HASFCS) {
376*19c3b8c2SApple OSS Distributions /*
377*19c3b8c2SApple OSS Distributions * If the M_HASFCS is set by the driver we want to make sure
378*19c3b8c2SApple OSS Distributions * that we strip off the trailing FCS data before handing it
379*19c3b8c2SApple OSS Distributions * up the stack.
380*19c3b8c2SApple OSS Distributions */
381*19c3b8c2SApple OSS Distributions m_adj(m, -ETHER_CRC_LEN);
382*19c3b8c2SApple OSS Distributions m->m_flags &= ~M_HASFCS;
383*19c3b8c2SApple OSS Distributions }
384*19c3b8c2SApple OSS Distributions
385*19c3b8c2SApple OSS Distributions if ((eh->ether_dhost[0] & 1) == 0) {
386*19c3b8c2SApple OSS Distributions /*
387*19c3b8c2SApple OSS Distributions * When the driver is put into promiscuous mode we may receive
388*19c3b8c2SApple OSS Distributions * unicast frames that are not intended for our interfaces.
389*19c3b8c2SApple OSS Distributions * They are marked here as being promiscuous so the caller may
390*19c3b8c2SApple OSS Distributions * dispose of them after passing the packets to any interface
391*19c3b8c2SApple OSS Distributions * filters.
392*19c3b8c2SApple OSS Distributions */
393*19c3b8c2SApple OSS Distributions if (_ether_cmp(eh->ether_dhost, IF_LLADDR(ifp))) {
394*19c3b8c2SApple OSS Distributions m->m_flags |= M_PROMISC;
395*19c3b8c2SApple OSS Distributions }
396*19c3b8c2SApple OSS Distributions }
397*19c3b8c2SApple OSS Distributions
398*19c3b8c2SApple OSS Distributions /* check for VLAN */
399*19c3b8c2SApple OSS Distributions if ((m->m_pkthdr.csum_flags & CSUM_VLAN_TAG_VALID) != 0) {
400*19c3b8c2SApple OSS Distributions if (EVL_VLANOFTAG(m->m_pkthdr.vlan_tag) != 0) {
401*19c3b8c2SApple OSS Distributions *protocol_family = PF_VLAN;
402*19c3b8c2SApple OSS Distributions return 0;
403*19c3b8c2SApple OSS Distributions }
404*19c3b8c2SApple OSS Distributions /* the packet is just priority-tagged, clear the bit */
405*19c3b8c2SApple OSS Distributions m->m_pkthdr.csum_flags &= ~CSUM_VLAN_TAG_VALID;
406*19c3b8c2SApple OSS Distributions } else if (ether_type == htons(ETHERTYPE_VLAN)) {
407*19c3b8c2SApple OSS Distributions struct ether_vlan_header * evl;
408*19c3b8c2SApple OSS Distributions
409*19c3b8c2SApple OSS Distributions evl = (struct ether_vlan_header *)(void *)frame_header;
410*19c3b8c2SApple OSS Distributions if (m->m_len < ETHER_VLAN_ENCAP_LEN ||
411*19c3b8c2SApple OSS Distributions ntohs(evl->evl_proto) == ETHERTYPE_VLAN ||
412*19c3b8c2SApple OSS Distributions EVL_VLANOFTAG(ntohs(evl->evl_tag)) != 0) {
413*19c3b8c2SApple OSS Distributions *protocol_family = PF_VLAN;
414*19c3b8c2SApple OSS Distributions return 0;
415*19c3b8c2SApple OSS Distributions }
416*19c3b8c2SApple OSS Distributions /* the packet is just priority-tagged */
417*19c3b8c2SApple OSS Distributions
418*19c3b8c2SApple OSS Distributions /* make the encapsulated ethertype the actual ethertype */
419*19c3b8c2SApple OSS Distributions ether_type = evl->evl_encap_proto = evl->evl_proto;
420*19c3b8c2SApple OSS Distributions
421*19c3b8c2SApple OSS Distributions /* remove the encapsulation header */
422*19c3b8c2SApple OSS Distributions m->m_len -= ETHER_VLAN_ENCAP_LEN;
423*19c3b8c2SApple OSS Distributions m->m_data += ETHER_VLAN_ENCAP_LEN;
424*19c3b8c2SApple OSS Distributions m->m_pkthdr.len -= ETHER_VLAN_ENCAP_LEN;
425*19c3b8c2SApple OSS Distributions m->m_pkthdr.csum_flags = 0; /* can't trust hardware checksum */
426*19c3b8c2SApple OSS Distributions } else if (ether_type == htons(ETHERTYPE_ARP)) {
427*19c3b8c2SApple OSS Distributions m->m_pkthdr.pkt_flags |= PKTF_INET_RESOLVE; /* ARP packet */
428*19c3b8c2SApple OSS Distributions }
429*19c3b8c2SApple OSS Distributions data = mtod(m, u_int8_t*);
430*19c3b8c2SApple OSS Distributions
431*19c3b8c2SApple OSS Distributions /*
432*19c3b8c2SApple OSS Distributions * Determine the packet's protocol type and stuff the protocol into
433*19c3b8c2SApple OSS Distributions * longs for quick compares.
434*19c3b8c2SApple OSS Distributions */
435*19c3b8c2SApple OSS Distributions if (ntohs(ether_type) <= 1500) {
436*19c3b8c2SApple OSS Distributions bcopy(data, &extProto1, sizeof(u_int32_t));
437*19c3b8c2SApple OSS Distributions
438*19c3b8c2SApple OSS Distributions /* SAP or SNAP */
439*19c3b8c2SApple OSS Distributions if ((extProto1 & htonl(0xFFFFFF00)) == htonl(0xAAAA0300)) {
440*19c3b8c2SApple OSS Distributions /* SNAP */
441*19c3b8c2SApple OSS Distributions type = DLIL_DESC_SNAP;
442*19c3b8c2SApple OSS Distributions bcopy(data + sizeof(u_int32_t), &extProto2,
443*19c3b8c2SApple OSS Distributions sizeof(u_int32_t));
444*19c3b8c2SApple OSS Distributions extProto1 &= htonl(0x000000FF);
445*19c3b8c2SApple OSS Distributions } else {
446*19c3b8c2SApple OSS Distributions type = DLIL_DESC_SAP;
447*19c3b8c2SApple OSS Distributions extProto1 &= htonl(0xFFFFFF00);
448*19c3b8c2SApple OSS Distributions }
449*19c3b8c2SApple OSS Distributions } else {
450*19c3b8c2SApple OSS Distributions type = DLIL_DESC_ETYPE2;
451*19c3b8c2SApple OSS Distributions }
452*19c3b8c2SApple OSS Distributions
453*19c3b8c2SApple OSS Distributions /*
454*19c3b8c2SApple OSS Distributions * Search through the connected protocols for a match.
455*19c3b8c2SApple OSS Distributions */
456*19c3b8c2SApple OSS Distributions switch (type) {
457*19c3b8c2SApple OSS Distributions case DLIL_DESC_ETYPE2:
458*19c3b8c2SApple OSS Distributions for (i = 0; i < maxd; i++) {
459*19c3b8c2SApple OSS Distributions if ((ed[i].type == type) &&
460*19c3b8c2SApple OSS Distributions (ed[i].data[0] == ether_type)) {
461*19c3b8c2SApple OSS Distributions *protocol_family = ed[i].protocol_family;
462*19c3b8c2SApple OSS Distributions return 0;
463*19c3b8c2SApple OSS Distributions }
464*19c3b8c2SApple OSS Distributions }
465*19c3b8c2SApple OSS Distributions break;
466*19c3b8c2SApple OSS Distributions
467*19c3b8c2SApple OSS Distributions case DLIL_DESC_SAP:
468*19c3b8c2SApple OSS Distributions for (i = 0; i < maxd; i++) {
469*19c3b8c2SApple OSS Distributions if ((ed[i].type == type) &&
470*19c3b8c2SApple OSS Distributions (ed[i].data[0] == extProto1)) {
471*19c3b8c2SApple OSS Distributions *protocol_family = ed[i].protocol_family;
472*19c3b8c2SApple OSS Distributions return 0;
473*19c3b8c2SApple OSS Distributions }
474*19c3b8c2SApple OSS Distributions }
475*19c3b8c2SApple OSS Distributions break;
476*19c3b8c2SApple OSS Distributions
477*19c3b8c2SApple OSS Distributions case DLIL_DESC_SNAP:
478*19c3b8c2SApple OSS Distributions for (i = 0; i < maxd; i++) {
479*19c3b8c2SApple OSS Distributions if ((ed[i].type == type) &&
480*19c3b8c2SApple OSS Distributions (ed[i].data[0] == extProto1) &&
481*19c3b8c2SApple OSS Distributions (ed[i].data[1] == extProto2)) {
482*19c3b8c2SApple OSS Distributions *protocol_family = ed[i].protocol_family;
483*19c3b8c2SApple OSS Distributions return 0;
484*19c3b8c2SApple OSS Distributions }
485*19c3b8c2SApple OSS Distributions }
486*19c3b8c2SApple OSS Distributions break;
487*19c3b8c2SApple OSS Distributions }
488*19c3b8c2SApple OSS Distributions
489*19c3b8c2SApple OSS Distributions return ENOENT;
490*19c3b8c2SApple OSS Distributions }
491*19c3b8c2SApple OSS Distributions
492*19c3b8c2SApple OSS Distributions /*
493*19c3b8c2SApple OSS Distributions * On embedded, ether_frameout is practicaly ether_frameout_extended.
494*19c3b8c2SApple OSS Distributions * On non-embedded, ether_frameout has long been exposed as a public KPI,
495*19c3b8c2SApple OSS Distributions * and therefore its signature must remain the same (without the pre- and
496*19c3b8c2SApple OSS Distributions * postpend length parameters.)
497*19c3b8c2SApple OSS Distributions */
498*19c3b8c2SApple OSS Distributions #if KPI_INTERFACE_EMBEDDED
499*19c3b8c2SApple OSS Distributions int
ether_frameout(struct ifnet * ifp,struct mbuf ** m,const struct sockaddr * ndest,const char * edst,const char * ether_type,u_int32_t * prepend_len,u_int32_t * postpend_len)500*19c3b8c2SApple OSS Distributions ether_frameout(struct ifnet *ifp, struct mbuf **m,
501*19c3b8c2SApple OSS Distributions const struct sockaddr *ndest, const char *edst,
502*19c3b8c2SApple OSS Distributions const char *ether_type, u_int32_t *prepend_len, u_int32_t *postpend_len)
503*19c3b8c2SApple OSS Distributions #else /* !KPI_INTERFACE_EMBEDDED */
504*19c3b8c2SApple OSS Distributions int
505*19c3b8c2SApple OSS Distributions ether_frameout(struct ifnet *ifp, struct mbuf **m,
506*19c3b8c2SApple OSS Distributions const struct sockaddr *ndest, const char *edst,
507*19c3b8c2SApple OSS Distributions const char *ether_type)
508*19c3b8c2SApple OSS Distributions #endif /* KPI_INTERFACE_EMBEDDED */
509*19c3b8c2SApple OSS Distributions {
510*19c3b8c2SApple OSS Distributions #if KPI_INTERFACE_EMBEDDED
511*19c3b8c2SApple OSS Distributions return ether_frameout_extended(ifp, m, ndest, edst, ether_type,
512*19c3b8c2SApple OSS Distributions prepend_len, postpend_len);
513*19c3b8c2SApple OSS Distributions #else /* !KPI_INTERFACE_EMBEDDED */
514*19c3b8c2SApple OSS Distributions return ether_frameout_extended(ifp, m, ndest, edst, ether_type,
515*19c3b8c2SApple OSS Distributions NULL, NULL);
516*19c3b8c2SApple OSS Distributions #endif /* !KPI_INTERFACE_EMBEDDED */
517*19c3b8c2SApple OSS Distributions }
518*19c3b8c2SApple OSS Distributions
519*19c3b8c2SApple OSS Distributions /*
520*19c3b8c2SApple OSS Distributions * Ethernet output routine.
521*19c3b8c2SApple OSS Distributions * Encapsulate a packet of type family for the local net.
522*19c3b8c2SApple OSS Distributions * Use trailer local net encapsulation if enough data in first
523*19c3b8c2SApple OSS Distributions * packet leaves a multiple of 512 bytes of data in remainder.
524*19c3b8c2SApple OSS Distributions */
525*19c3b8c2SApple OSS Distributions int
ether_frameout_extended(struct ifnet * ifp,struct mbuf ** m,const struct sockaddr * ndest,const char * edst,const char * ether_type,u_int32_t * prepend_len,u_int32_t * postpend_len)526*19c3b8c2SApple OSS Distributions ether_frameout_extended(struct ifnet *ifp, struct mbuf **m,
527*19c3b8c2SApple OSS Distributions const struct sockaddr *ndest, const char *edst,
528*19c3b8c2SApple OSS Distributions const char *ether_type, u_int32_t *prepend_len, u_int32_t *postpend_len)
529*19c3b8c2SApple OSS Distributions {
530*19c3b8c2SApple OSS Distributions struct ether_header *eh;
531*19c3b8c2SApple OSS Distributions int hlen; /* link layer header length */
532*19c3b8c2SApple OSS Distributions
533*19c3b8c2SApple OSS Distributions hlen = ETHER_HDR_LEN;
534*19c3b8c2SApple OSS Distributions
535*19c3b8c2SApple OSS Distributions /*
536*19c3b8c2SApple OSS Distributions * If a simplex interface, and the packet is being sent to our
537*19c3b8c2SApple OSS Distributions * Ethernet address or a broadcast address, loopback a copy.
538*19c3b8c2SApple OSS Distributions * XXX To make a simplex device behave exactly like a duplex
539*19c3b8c2SApple OSS Distributions * device, we should copy in the case of sending to our own
540*19c3b8c2SApple OSS Distributions * ethernet address (thus letting the original actually appear
541*19c3b8c2SApple OSS Distributions * on the wire). However, we don't do that here for security
542*19c3b8c2SApple OSS Distributions * reasons and compatibility with the original behavior.
543*19c3b8c2SApple OSS Distributions */
544*19c3b8c2SApple OSS Distributions if ((ifp->if_flags & IFF_SIMPLEX) &&
545*19c3b8c2SApple OSS Distributions ((*m)->m_flags & M_LOOP) && lo_ifp != NULL) {
546*19c3b8c2SApple OSS Distributions if ((*m)->m_flags & M_BCAST) {
547*19c3b8c2SApple OSS Distributions struct mbuf *n = m_copy(*m, 0, (int)M_COPYALL);
548*19c3b8c2SApple OSS Distributions if (n != NULL) {
549*19c3b8c2SApple OSS Distributions dlil_output(lo_ifp, ndest->sa_family,
550*19c3b8c2SApple OSS Distributions n, NULL, ndest, 0, NULL);
551*19c3b8c2SApple OSS Distributions }
552*19c3b8c2SApple OSS Distributions } else if (_ether_cmp(edst, IF_LLADDR(ifp)) == 0) {
553*19c3b8c2SApple OSS Distributions dlil_output(lo_ifp, ndest->sa_family, *m,
554*19c3b8c2SApple OSS Distributions NULL, ndest, 0, NULL);
555*19c3b8c2SApple OSS Distributions return EJUSTRETURN;
556*19c3b8c2SApple OSS Distributions }
557*19c3b8c2SApple OSS Distributions }
558*19c3b8c2SApple OSS Distributions
559*19c3b8c2SApple OSS Distributions /*
560*19c3b8c2SApple OSS Distributions * Add local net header. If no space in first mbuf,
561*19c3b8c2SApple OSS Distributions * allocate another.
562*19c3b8c2SApple OSS Distributions */
563*19c3b8c2SApple OSS Distributions M_PREPEND(*m, sizeof(struct ether_header), M_DONTWAIT, 0);
564*19c3b8c2SApple OSS Distributions if (*m == NULL) {
565*19c3b8c2SApple OSS Distributions return EJUSTRETURN;
566*19c3b8c2SApple OSS Distributions }
567*19c3b8c2SApple OSS Distributions
568*19c3b8c2SApple OSS Distributions if (prepend_len != NULL) {
569*19c3b8c2SApple OSS Distributions *prepend_len = sizeof(struct ether_header);
570*19c3b8c2SApple OSS Distributions }
571*19c3b8c2SApple OSS Distributions if (postpend_len != NULL) {
572*19c3b8c2SApple OSS Distributions *postpend_len = 0;
573*19c3b8c2SApple OSS Distributions }
574*19c3b8c2SApple OSS Distributions
575*19c3b8c2SApple OSS Distributions eh = mtod(*m, struct ether_header *);
576*19c3b8c2SApple OSS Distributions (void) memcpy(&eh->ether_type, ether_type, sizeof(eh->ether_type));
577*19c3b8c2SApple OSS Distributions (void) memcpy(eh->ether_dhost, edst, ETHER_ADDR_LEN);
578*19c3b8c2SApple OSS Distributions ifnet_lladdr_copy_bytes(ifp, eh->ether_shost, ETHER_ADDR_LEN);
579*19c3b8c2SApple OSS Distributions
580*19c3b8c2SApple OSS Distributions return 0;
581*19c3b8c2SApple OSS Distributions }
582*19c3b8c2SApple OSS Distributions
583*19c3b8c2SApple OSS Distributions errno_t
ether_check_multi(ifnet_t ifp,const struct sockaddr * proto_addr)584*19c3b8c2SApple OSS Distributions ether_check_multi(ifnet_t ifp, const struct sockaddr *proto_addr)
585*19c3b8c2SApple OSS Distributions {
586*19c3b8c2SApple OSS Distributions #pragma unused(ifp)
587*19c3b8c2SApple OSS Distributions errno_t result = EAFNOSUPPORT;
588*19c3b8c2SApple OSS Distributions const u_char *e_addr;
589*19c3b8c2SApple OSS Distributions
590*19c3b8c2SApple OSS Distributions /*
591*19c3b8c2SApple OSS Distributions * AF_SPEC and AF_LINK don't require translation. We do
592*19c3b8c2SApple OSS Distributions * want to verify that they specify a valid multicast.
593*19c3b8c2SApple OSS Distributions */
594*19c3b8c2SApple OSS Distributions switch (proto_addr->sa_family) {
595*19c3b8c2SApple OSS Distributions case AF_UNSPEC:
596*19c3b8c2SApple OSS Distributions e_addr = (const u_char*)&proto_addr->sa_data[0];
597*19c3b8c2SApple OSS Distributions if ((e_addr[0] & 0x01) != 0x01) {
598*19c3b8c2SApple OSS Distributions result = EADDRNOTAVAIL;
599*19c3b8c2SApple OSS Distributions } else {
600*19c3b8c2SApple OSS Distributions result = 0;
601*19c3b8c2SApple OSS Distributions }
602*19c3b8c2SApple OSS Distributions break;
603*19c3b8c2SApple OSS Distributions
604*19c3b8c2SApple OSS Distributions case AF_LINK:
605*19c3b8c2SApple OSS Distributions e_addr = CONST_LLADDR((const struct sockaddr_dl*)
606*19c3b8c2SApple OSS Distributions (uintptr_t)(size_t)proto_addr);
607*19c3b8c2SApple OSS Distributions if ((e_addr[0] & 0x01) != 0x01) {
608*19c3b8c2SApple OSS Distributions result = EADDRNOTAVAIL;
609*19c3b8c2SApple OSS Distributions } else {
610*19c3b8c2SApple OSS Distributions result = 0;
611*19c3b8c2SApple OSS Distributions }
612*19c3b8c2SApple OSS Distributions break;
613*19c3b8c2SApple OSS Distributions }
614*19c3b8c2SApple OSS Distributions
615*19c3b8c2SApple OSS Distributions return result;
616*19c3b8c2SApple OSS Distributions }
617*19c3b8c2SApple OSS Distributions
618*19c3b8c2SApple OSS Distributions int
ether_ioctl(ifnet_t ifp,u_int32_t command,void * data)619*19c3b8c2SApple OSS Distributions ether_ioctl(ifnet_t ifp, u_int32_t command, void *data)
620*19c3b8c2SApple OSS Distributions {
621*19c3b8c2SApple OSS Distributions #pragma unused(ifp, command, data)
622*19c3b8c2SApple OSS Distributions return EOPNOTSUPP;
623*19c3b8c2SApple OSS Distributions }
624*19c3b8c2SApple OSS Distributions
625*19c3b8c2SApple OSS Distributions __private_extern__ int
ether_family_init(void)626*19c3b8c2SApple OSS Distributions ether_family_init(void)
627*19c3b8c2SApple OSS Distributions {
628*19c3b8c2SApple OSS Distributions errno_t error = 0;
629*19c3b8c2SApple OSS Distributions
630*19c3b8c2SApple OSS Distributions /* Register protocol registration functions */
631*19c3b8c2SApple OSS Distributions if ((error = proto_register_plumber(PF_INET, APPLE_IF_FAM_ETHERNET,
632*19c3b8c2SApple OSS Distributions ether_attach_inet, ether_detach_inet)) != 0) {
633*19c3b8c2SApple OSS Distributions printf("proto_register_plumber failed for PF_INET error=%d\n",
634*19c3b8c2SApple OSS Distributions error);
635*19c3b8c2SApple OSS Distributions goto done;
636*19c3b8c2SApple OSS Distributions }
637*19c3b8c2SApple OSS Distributions if ((error = proto_register_plumber(PF_INET6, APPLE_IF_FAM_ETHERNET,
638*19c3b8c2SApple OSS Distributions ether_attach_inet6, ether_detach_inet6)) != 0) {
639*19c3b8c2SApple OSS Distributions printf("proto_register_plumber failed for PF_INET6 error=%d\n",
640*19c3b8c2SApple OSS Distributions error);
641*19c3b8c2SApple OSS Distributions goto done;
642*19c3b8c2SApple OSS Distributions }
643*19c3b8c2SApple OSS Distributions #if VLAN
644*19c3b8c2SApple OSS Distributions vlan_family_init();
645*19c3b8c2SApple OSS Distributions #endif /* VLAN */
646*19c3b8c2SApple OSS Distributions #if BOND
647*19c3b8c2SApple OSS Distributions bond_family_init();
648*19c3b8c2SApple OSS Distributions #endif /* BOND */
649*19c3b8c2SApple OSS Distributions #if IF_BRIDGE
650*19c3b8c2SApple OSS Distributions bridgeattach(0);
651*19c3b8c2SApple OSS Distributions #endif /* IF_BRIDGE */
652*19c3b8c2SApple OSS Distributions #if IF_FAKE
653*19c3b8c2SApple OSS Distributions if_fake_init();
654*19c3b8c2SApple OSS Distributions #endif /* IF_FAKE */
655*19c3b8c2SApple OSS Distributions #if IF_HEADLESS
656*19c3b8c2SApple OSS Distributions if_headless_init();
657*19c3b8c2SApple OSS Distributions #endif /* IF_HEADLESS */
658*19c3b8c2SApple OSS Distributions done:
659*19c3b8c2SApple OSS Distributions
660*19c3b8c2SApple OSS Distributions return error;
661*19c3b8c2SApple OSS Distributions }
662