2 * Copyright (c) 2000-2018 Apple Inc. All rights reserved.
4 * @APPLE_OSREFERENCE_LICENSE_HEADER_START@
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.
15 * Please obtain a copy of the License at
16 * http://www.opensource.apple.com/apsl/ and read it before using this file.
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
20 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
21 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
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.
26 * @APPLE_OSREFERENCE_LICENSE_HEADER_END@
29 * Copyright (c) 1980, 1986, 1993
30 * The Regents of the University of California. All rights reserved.
32 * Redistribution and use in source and binary forms, with or without
33 * modification, are permitted provided that the following conditions
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.
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
60 * @(#)if.c 8.3 (Berkeley) 1/4/94
61 * $FreeBSD: src/sys/net/if.c,v 1.85.2.9 2001/07/24 19:10:17 brooks Exp $
64 * NOTICE: This file was modified by SPARTA, Inc. in 2006 to introduce
65 * support for mandatory and extensible security protections. This notice
66 * is included in support of clause 2.2 (b) of the Apple Public License,
70 #include <kern/locks.h>
72 #include <sys/param.h>
73 #include <sys/malloc.h>
75 #include <sys/systm.h>
77 #include <sys/socket.h>
78 #include <sys/socketvar.h>
79 #include <sys/protosw.h>
80 #include <sys/kernel.h>
81 #include <sys/sockio.h>
82 #include <sys/syslog.h>
83 #include <sys/sysctl.h>
84 #include <sys/mcache.h>
85 #include <sys/kauth.h>
87 #include <kern/zalloc.h>
88 #include <mach/boolean.h>
90 #include <machine/endian.h>
92 #include <pexpert/pexpert.h>
95 #include <net/if_arp.h>
96 #include <net/if_dl.h>
97 #include <net/if_types.h>
98 #include <net/if_var.h>
99 #include <net/if_ppp.h>
100 #include <net/ethernet.h>
101 #include <net/network_agent.h>
102 #include <net/radix.h>
103 #include <net/route.h>
104 #include <net/dlil.h>
105 #include <net/nwk_wq.h>
107 #include <sys/domain.h>
108 #include <libkern/OSAtomic.h>
111 #include <netinet/in.h>
112 #include <netinet/in_var.h>
113 #include <netinet/in_tclass.h>
114 #include <netinet/ip_var.h>
115 #include <netinet/ip.h>
116 #include <netinet/ip6.h>
117 #include <netinet/ip_var.h>
118 #include <netinet/tcp.h>
119 #include <netinet/tcp_var.h>
120 #include <netinet/udp.h>
121 #include <netinet/udp_var.h>
123 #include <netinet6/in6_var.h>
124 #include <netinet6/in6_ifattach.h>
125 #include <netinet6/ip6_var.h>
126 #include <netinet6/nd6.h>
128 #endif /* INET || INET6 */
131 #include <security/mac_framework.h>
135 * System initialization
138 extern char *proc_name_address(void *);
140 /* Lock group and attribute for ifaddr lock */
141 lck_attr_t
*ifa_mtx_attr
;
142 lck_grp_t
*ifa_mtx_grp
;
143 static lck_grp_attr_t
*ifa_mtx_grp_attr
;
145 static int ifioctl_ifreq(struct socket
*, u_long
, struct ifreq
*,
147 static int ifioctl_ifconf(u_long
, caddr_t
);
148 static int ifioctl_ifclone(u_long
, caddr_t
);
149 static int ifioctl_iforder(u_long
, caddr_t
);
150 static int ifioctl_ifdesc(struct ifnet
*, u_long
, caddr_t
, struct proc
*);
151 static int ifioctl_linkparams(struct ifnet
*, u_long
, caddr_t
, struct proc
*);
152 static int ifioctl_qstats(struct ifnet
*, u_long
, caddr_t
);
153 static int ifioctl_throttle(struct ifnet
*, u_long
, caddr_t
, struct proc
*);
154 static int ifioctl_netsignature(struct ifnet
*, u_long
, caddr_t
);
155 static int ifconf(u_long cmd
, user_addr_t ifrp
, int * ret_space
);
156 __private_extern__
void link_rtrequest(int, struct rtentry
*, struct sockaddr
*);
157 void if_rtproto_del(struct ifnet
*ifp
, int protocol
);
159 static int if_addmulti_common(struct ifnet
*, const struct sockaddr
*,
160 struct ifmultiaddr
**, int);
161 static int if_delmulti_common(struct ifmultiaddr
*, struct ifnet
*,
162 const struct sockaddr
*, int);
163 static struct ifnet
*ifunit_common(const char *, boolean_t
);
165 static int if_rtmtu(struct radix_node
*, void *);
166 static void if_rtmtu_update(struct ifnet
*);
168 static int if_clone_list(int, int *, user_addr_t
);
170 MALLOC_DEFINE(M_IFADDR
, "ifaddr", "interface address");
172 struct ifnethead ifnet_head
= TAILQ_HEAD_INITIALIZER(ifnet_head
);
174 /* ifnet_ordered_head and if_ordered_count are protected by the ifnet_head lock */
175 struct ifnethead ifnet_ordered_head
= TAILQ_HEAD_INITIALIZER(ifnet_ordered_head
);
176 static u_int32_t if_ordered_count
= 0;
178 static int if_cloners_count
;
179 LIST_HEAD(, if_clone
) if_cloners
= LIST_HEAD_INITIALIZER(if_cloners
);
181 static struct ifaddr
*ifa_ifwithnet_common(const struct sockaddr
*,
183 static void if_attach_ifa_common(struct ifnet
*, struct ifaddr
*, int);
184 static void if_detach_ifa_common(struct ifnet
*, struct ifaddr
*, int);
186 static void if_attach_ifma(struct ifnet
*, struct ifmultiaddr
*, int);
187 static int if_detach_ifma(struct ifnet
*, struct ifmultiaddr
*, int);
189 static struct ifmultiaddr
*ifma_alloc(int);
190 static void ifma_free(struct ifmultiaddr
*);
191 static void ifma_trace(struct ifmultiaddr
*, int);
194 static unsigned int ifma_debug
= 1; /* debugging (enabled) */
196 static unsigned int ifma_debug
; /* debugging (disabled) */
198 static unsigned int ifma_size
; /* size of zone element */
199 static struct zone
*ifma_zone
; /* zone for ifmultiaddr */
201 #define IFMA_TRACE_HIST_SIZE 32 /* size of trace history */
204 __private_extern__
unsigned int ifma_trace_hist_size
= IFMA_TRACE_HIST_SIZE
;
206 struct ifmultiaddr_dbg
{
207 struct ifmultiaddr ifma
; /* ifmultiaddr */
208 u_int16_t ifma_refhold_cnt
; /* # of ref */
209 u_int16_t ifma_refrele_cnt
; /* # of rele */
211 * Circular lists of IFA_ADDREF and IFA_REMREF callers.
213 ctrace_t ifma_refhold
[IFMA_TRACE_HIST_SIZE
];
214 ctrace_t ifma_refrele
[IFMA_TRACE_HIST_SIZE
];
218 TAILQ_ENTRY(ifmultiaddr_dbg
) ifma_trash_link
;
221 /* List of trash ifmultiaddr entries protected by ifma_trash_lock */
222 static TAILQ_HEAD(, ifmultiaddr_dbg
) ifma_trash_head
;
223 static decl_lck_mtx_data(, ifma_trash_lock
);
225 #define IFMA_ZONE_MAX 64 /* maximum elements in zone */
226 #define IFMA_ZONE_NAME "ifmultiaddr" /* zone name */
230 * XXX: declare here to avoid to include many inet6 related files..
231 * should be more generalized?
233 extern void nd6_setmtu(struct ifnet
*);
234 extern lck_mtx_t
*nd6_mutex
;
237 SYSCTL_NODE(_net
, PF_LINK
, link
, CTLFLAG_RW
|CTLFLAG_LOCKED
, 0, "Link layers");
238 SYSCTL_NODE(_net_link
, 0, generic
, CTLFLAG_RW
|CTLFLAG_LOCKED
, 0,
239 "Generic link-management");
241 SYSCTL_DECL(_net_link_generic_system
);
243 static uint32_t if_verbose
= 0;
244 SYSCTL_INT(_net_link_generic_system
, OID_AUTO
, if_verbose
,
245 CTLFLAG_RW
| CTLFLAG_LOCKED
, &if_verbose
, 0, "");
247 boolean_t intcoproc_unrestricted
;
249 /* Eventhandler context for interface events */
250 struct eventhandler_lists_ctxt ifnet_evhdlr_ctxt
;
255 /* Setup lock group and attribute for ifaddr */
256 ifa_mtx_grp_attr
= lck_grp_attr_alloc_init();
257 ifa_mtx_grp
= lck_grp_alloc_init("ifaddr", ifa_mtx_grp_attr
);
258 ifa_mtx_attr
= lck_attr_alloc_init();
260 PE_parse_boot_argn("ifa_debug", &ifma_debug
, sizeof (ifma_debug
));
262 ifma_size
= (ifma_debug
== 0) ? sizeof (struct ifmultiaddr
) :
263 sizeof (struct ifmultiaddr_dbg
);
265 ifma_zone
= zinit(ifma_size
, IFMA_ZONE_MAX
* ifma_size
, 0,
267 if (ifma_zone
== NULL
) {
268 panic("%s: failed allocating %s", __func__
, IFMA_ZONE_NAME
);
271 zone_change(ifma_zone
, Z_EXPAND
, TRUE
);
272 zone_change(ifma_zone
, Z_CALLERACCT
, FALSE
);
274 lck_mtx_init(&ifma_trash_lock
, ifa_mtx_grp
, ifa_mtx_attr
);
275 TAILQ_INIT(&ifma_trash_head
);
277 PE_parse_boot_argn("intcoproc_unrestricted", &intcoproc_unrestricted
,
278 sizeof (intcoproc_unrestricted
));
282 * Network interface utility routines.
284 * Routines with ifa_ifwith* names take sockaddr *'s as
289 struct ifaddr
**ifnet_addrs
;
290 struct ifnet
**ifindex2ifnet
;
292 __private_extern__
void
293 if_attach_ifa(struct ifnet
*ifp
, struct ifaddr
*ifa
)
295 if_attach_ifa_common(ifp
, ifa
, 0);
298 __private_extern__
void
299 if_attach_link_ifa(struct ifnet
*ifp
, struct ifaddr
*ifa
)
301 if_attach_ifa_common(ifp
, ifa
, 1);
305 if_attach_ifa_common(struct ifnet
*ifp
, struct ifaddr
*ifa
, int link
)
307 ifnet_lock_assert(ifp
, IFNET_LCK_ASSERT_EXCLUSIVE
);
308 IFA_LOCK_ASSERT_HELD(ifa
);
310 if (ifa
->ifa_ifp
!= ifp
) {
311 panic("%s: Mismatch ifa_ifp=%p != ifp=%p", __func__
,
314 } else if (ifa
->ifa_debug
& IFD_ATTACHED
) {
315 panic("%s: Attempt to attach an already attached ifa=%p",
318 } else if (link
&& !(ifa
->ifa_debug
& IFD_LINK
)) {
319 panic("%s: Unexpected non-link address ifa=%p", __func__
, ifa
);
321 } else if (!link
&& (ifa
->ifa_debug
& IFD_LINK
)) {
322 panic("%s: Unexpected link address ifa=%p", __func__
, ifa
);
325 IFA_ADDREF_LOCKED(ifa
);
326 ifa
->ifa_debug
|= IFD_ATTACHED
;
328 TAILQ_INSERT_HEAD(&ifp
->if_addrhead
, ifa
, ifa_link
);
330 TAILQ_INSERT_TAIL(&ifp
->if_addrhead
, ifa
, ifa_link
);
332 if (ifa
->ifa_attached
!= NULL
)
333 (*ifa
->ifa_attached
)(ifa
);
337 __private_extern__
void
338 if_detach_ifa(struct ifnet
*ifp
, struct ifaddr
*ifa
)
340 if_detach_ifa_common(ifp
, ifa
, 0);
343 __private_extern__
void
344 if_detach_link_ifa(struct ifnet
*ifp
, struct ifaddr
*ifa
)
346 if_detach_ifa_common(ifp
, ifa
, 1);
350 if_detach_ifa_common(struct ifnet
*ifp
, struct ifaddr
*ifa
, int link
)
352 ifnet_lock_assert(ifp
, IFNET_LCK_ASSERT_EXCLUSIVE
);
353 IFA_LOCK_ASSERT_HELD(ifa
);
355 if (link
&& !(ifa
->ifa_debug
& IFD_LINK
)) {
356 panic("%s: Unexpected non-link address ifa=%p", __func__
, ifa
);
358 } else if (link
&& ifa
!= TAILQ_FIRST(&ifp
->if_addrhead
)) {
359 panic("%s: Link address ifa=%p not first", __func__
, ifa
);
361 } else if (!link
&& (ifa
->ifa_debug
& IFD_LINK
)) {
362 panic("%s: Unexpected link address ifa=%p", __func__
, ifa
);
364 } else if (!(ifa
->ifa_debug
& IFD_ATTACHED
)) {
365 panic("%s: Attempt to detach an unattached address ifa=%p",
368 } else if (ifa
->ifa_ifp
!= ifp
) {
369 panic("%s: Mismatch ifa_ifp=%p, ifp=%p", __func__
,
372 } else if (ifa
->ifa_debug
& IFD_DEBUG
) {
374 TAILQ_FOREACH(ifa2
, &ifp
->if_addrhead
, ifa_link
) {
379 panic("%s: Attempt to detach a stray address ifa=%p",
384 TAILQ_REMOVE(&ifp
->if_addrhead
, ifa
, ifa_link
);
385 /* This must not be the last reference to the ifaddr */
386 if (IFA_REMREF_LOCKED(ifa
) == NULL
) {
387 panic("%s: unexpected (missing) refcnt ifa=%p", __func__
, ifa
);
390 ifa
->ifa_debug
&= ~(IFD_ATTACHED
| IFD_DETACHING
);
392 if (ifa
->ifa_detached
!= NULL
)
393 (*ifa
->ifa_detached
)(ifa
);
397 #define INITIAL_IF_INDEXLIM 8
400 * Function: if_next_index
402 * Return the next available interface index.
403 * Grow the ifnet_addrs[] and ifindex2ifnet[] arrays to accomodate the
404 * added entry when necessary.
407 * ifnet_addrs[] is indexed by (if_index - 1), whereas
408 * ifindex2ifnet[] is indexed by ifp->if_index. That requires us to
409 * always allocate one extra element to hold ifindex2ifnet[0], which
412 int if_next_index(void);
414 __private_extern__
int
417 static int if_indexlim
= 0;
420 new_index
= ++if_index
;
421 if (if_index
> if_indexlim
) {
424 caddr_t new_ifnet_addrs
;
425 caddr_t new_ifindex2ifnet
;
426 caddr_t old_ifnet_addrs
;
428 old_ifnet_addrs
= (caddr_t
)ifnet_addrs
;
429 if (ifnet_addrs
== NULL
) {
430 new_if_indexlim
= INITIAL_IF_INDEXLIM
;
432 new_if_indexlim
= if_indexlim
<< 1;
435 /* allocate space for the larger arrays */
436 n
= (2 * new_if_indexlim
+ 1) * sizeof(caddr_t
);
437 new_ifnet_addrs
= _MALLOC(n
, M_IFADDR
, M_WAITOK
| M_ZERO
);
438 if (new_ifnet_addrs
== NULL
) {
443 new_ifindex2ifnet
= new_ifnet_addrs
444 + new_if_indexlim
* sizeof(caddr_t
);
445 if (ifnet_addrs
!= NULL
) {
446 /* copy the existing data */
447 bcopy((caddr_t
)ifnet_addrs
, new_ifnet_addrs
,
448 if_indexlim
* sizeof(caddr_t
));
449 bcopy((caddr_t
)ifindex2ifnet
,
451 (if_indexlim
+ 1) * sizeof(caddr_t
));
454 /* switch to the new tables and size */
455 ifnet_addrs
= (struct ifaddr
**)(void *)new_ifnet_addrs
;
456 ifindex2ifnet
= (struct ifnet
**)(void *)new_ifindex2ifnet
;
457 if_indexlim
= new_if_indexlim
;
459 /* release the old data */
460 if (old_ifnet_addrs
!= NULL
) {
461 _FREE((caddr_t
)old_ifnet_addrs
, M_IFADDR
);
468 * Create a clone network interface.
471 if_clone_create(char *name
, int len
, void *params
)
473 struct if_clone
*ifc
;
476 u_int32_t bytoff
, bitoff
;
480 ifc
= if_clone_lookup(name
, &unit
);
484 if (ifunit(name
) != NULL
)
488 wildcard
= (unit
== UINT32_MAX
);
490 * Find a free unit if none was given.
493 while ((bytoff
< ifc
->ifc_bmlen
) &&
494 (ifc
->ifc_units
[bytoff
] == 0xff))
496 if (bytoff
>= ifc
->ifc_bmlen
)
498 while ((ifc
->ifc_units
[bytoff
] & (1 << bitoff
)) != 0)
500 unit
= (bytoff
<< 3) + bitoff
;
503 if (unit
> ifc
->ifc_maxunit
)
506 lck_mtx_lock(&ifc
->ifc_mutex
);
507 err
= (*ifc
->ifc_create
)(ifc
, unit
, params
);
509 lck_mtx_unlock(&ifc
->ifc_mutex
);
515 bitoff
= unit
- (bytoff
<< 3);
519 * Allocate the unit in the bitmap.
521 KASSERT((ifc
->ifc_units
[bytoff
] & (1 << bitoff
)) == 0,
522 ("%s: bit is already set", __func__
));
523 ifc
->ifc_units
[bytoff
] |= (1 << bitoff
);
525 /* In the wildcard case, we need to update the name. */
527 for (dp
= name
; *dp
!= '\0'; dp
++);
528 if (snprintf(dp
, len
- (dp
-name
), "%d", unit
) >
529 len
- (dp
-name
) - 1) {
531 * This can only be a programmer error and
532 * there's no straightforward way to recover if
535 panic("%s: interface name too long", __func__
);
540 lck_mtx_unlock(&ifc
->ifc_mutex
);
546 * Destroy a clone network interface.
549 if_clone_destroy(const char *name
)
551 struct if_clone
*ifc
= NULL
;
552 struct ifnet
*ifp
= NULL
;
557 ifc
= if_clone_lookup(name
, &unit
);
564 if (unit
< ifc
->ifc_minifs
) {
569 ifp
= ifunit_ref(name
);
575 if (ifc
->ifc_destroy
== NULL
) {
580 lck_mtx_lock(&ifc
->ifc_mutex
);
581 error
= (*ifc
->ifc_destroy
)(ifp
);
584 lck_mtx_unlock(&ifc
->ifc_mutex
);
588 /* Compute offset in the bitmap and deallocate the unit. */
590 bitoff
= unit
- (bytoff
<< 3);
591 KASSERT((ifc
->ifc_units
[bytoff
] & (1 << bitoff
)) != 0,
592 ("%s: bit is already cleared", __func__
));
593 ifc
->ifc_units
[bytoff
] &= ~(1 << bitoff
);
594 lck_mtx_unlock(&ifc
->ifc_mutex
);
598 ifnet_decr_iorefcnt(ifp
);
603 * Look up a network interface cloner.
606 __private_extern__
struct if_clone
*
607 if_clone_lookup(const char *name
, u_int32_t
*unitp
)
609 struct if_clone
*ifc
;
613 for (ifc
= LIST_FIRST(&if_cloners
); ifc
!= NULL
; ) {
614 for (cp
= name
, i
= 0; i
< ifc
->ifc_namelen
; i
++, cp
++) {
615 if (ifc
->ifc_name
[i
] != *cp
)
620 ifc
= LIST_NEXT(ifc
, ifc_list
);
624 return ((struct if_clone
*)NULL
);
630 for (i
= 0; *cp
!= '\0'; cp
++) {
631 if (*cp
< '0' || *cp
> '9') {
632 /* Bogus unit number. */
635 i
= (i
* 10) + (*cp
- '0');
645 if_clone_softc_allocate(const struct if_clone
*ifc
)
647 void *p_clone
= NULL
;
651 p_clone
= zalloc(ifc
->ifc_zone
);
653 bzero(p_clone
, ifc
->ifc_softc_size
);
659 if_clone_softc_deallocate(const struct if_clone
*ifc
, void *p_softc
)
661 VERIFY(ifc
!= NULL
&& p_softc
!= NULL
);
662 bzero(p_softc
, ifc
->ifc_softc_size
);
663 zfree(ifc
->ifc_zone
, p_softc
);
667 * Register a network interface cloner.
670 if_clone_attach(struct if_clone
*ifc
)
677 KASSERT(ifc
->ifc_minifs
- 1 <= ifc
->ifc_maxunit
,
678 ("%s: %s requested more units then allowed (%d > %d)",
679 __func__
, ifc
->ifc_name
, ifc
->ifc_minifs
,
680 ifc
->ifc_maxunit
+ 1));
682 * Compute bitmap size and allocate it.
684 maxclone
= ifc
->ifc_maxunit
+ 1;
686 if ((len
<< 3) < maxclone
)
688 ifc
->ifc_units
= _MALLOC(len
, M_CLONE
, M_WAITOK
| M_ZERO
);
689 if (ifc
->ifc_units
== NULL
)
691 ifc
->ifc_bmlen
= len
;
692 lck_mtx_init(&ifc
->ifc_mutex
, ifnet_lock_group
, ifnet_lock_attr
);
694 if (ifc
->ifc_softc_size
!= 0) {
695 ifc
->ifc_zone
= zinit(ifc
->ifc_softc_size
,
696 ifc
->ifc_zone_max_elem
* ifc
->ifc_softc_size
, 0, ifc
->ifc_name
);
697 if (ifc
->ifc_zone
== NULL
) {
698 FREE(ifc
->ifc_units
, M_CLONE
);
701 zone_change(ifc
->ifc_zone
, Z_EXPAND
, TRUE
);
702 zone_change(ifc
->ifc_zone
, Z_CALLERACCT
, FALSE
);
705 LIST_INSERT_HEAD(&if_cloners
, ifc
, ifc_list
);
708 for (unit
= 0; unit
< ifc
->ifc_minifs
; unit
++) {
709 err
= (*ifc
->ifc_create
)(ifc
, unit
, NULL
);
711 ("%s: failed to create required interface %s%d",
712 __func__
, ifc
->ifc_name
, unit
));
714 /* Allocate the unit in the bitmap. */
716 bitoff
= unit
- (bytoff
<< 3);
717 ifc
->ifc_units
[bytoff
] |= (1 << bitoff
);
724 * Unregister a network interface cloner.
727 if_clone_detach(struct if_clone
*ifc
)
729 LIST_REMOVE(ifc
, ifc_list
);
730 FREE(ifc
->ifc_units
, M_CLONE
);
731 if (ifc
->ifc_softc_size
!= 0)
732 zdestroy(ifc
->ifc_zone
);
734 lck_mtx_destroy(&ifc
->ifc_mutex
, ifnet_lock_group
);
739 * Provide list of interface cloners to userspace.
742 if_clone_list(int count
, int *ret_total
, user_addr_t dst
)
744 char outbuf
[IFNAMSIZ
];
745 struct if_clone
*ifc
;
748 *ret_total
= if_cloners_count
;
749 if (dst
== USER_ADDR_NULL
) {
750 /* Just asking how many there are. */
757 count
= (if_cloners_count
< count
) ? if_cloners_count
: count
;
759 for (ifc
= LIST_FIRST(&if_cloners
); ifc
!= NULL
&& count
!= 0;
760 ifc
= LIST_NEXT(ifc
, ifc_list
), count
--, dst
+= IFNAMSIZ
) {
761 bzero(outbuf
, sizeof(outbuf
));
762 strlcpy(outbuf
, ifc
->ifc_name
, IFNAMSIZ
);
763 error
= copyout(outbuf
, dst
, IFNAMSIZ
);
772 if_functional_type(struct ifnet
*ifp
, bool exclude_delegate
)
774 u_int32_t ret
= IFRTYPE_FUNCTIONAL_UNKNOWN
;
776 if (ifp
->if_flags
& IFF_LOOPBACK
) {
777 ret
= IFRTYPE_FUNCTIONAL_LOOPBACK
;
778 } else if ((exclude_delegate
&&
779 (ifp
->if_subfamily
== IFNET_SUBFAMILY_WIFI
)) ||
780 (!exclude_delegate
&& IFNET_IS_WIFI(ifp
))) {
781 if (ifp
->if_eflags
& IFEF_AWDL
)
782 ret
= IFRTYPE_FUNCTIONAL_WIFI_AWDL
;
784 ret
= IFRTYPE_FUNCTIONAL_WIFI_INFRA
;
785 } else if ((exclude_delegate
&&
786 (ifp
->if_type
== IFT_CELLULAR
)) ||
787 (!exclude_delegate
&& IFNET_IS_CELLULAR(ifp
))) {
788 ret
= IFRTYPE_FUNCTIONAL_CELLULAR
;
789 } else if (IFNET_IS_INTCOPROC(ifp
)) {
790 ret
= IFRTYPE_FUNCTIONAL_INTCOPROC
;
791 } else if ((exclude_delegate
&&
792 (ifp
->if_family
== IFNET_FAMILY_ETHERNET
||
793 ifp
->if_family
== IFNET_FAMILY_BOND
||
794 ifp
->if_family
== IFNET_FAMILY_VLAN
||
795 ifp
->if_family
== IFNET_FAMILY_FIREWIRE
)) ||
796 (!exclude_delegate
&& IFNET_IS_WIRED(ifp
))) {
797 ret
= IFRTYPE_FUNCTIONAL_WIRED
;
805 * Similar to ifa_ifwithaddr, except that this is IPv4 specific
806 * and that it matches only the local (not broadcast) address.
808 __private_extern__
struct in_ifaddr
*
809 ifa_foraddr(unsigned int addr
)
811 return (ifa_foraddr_scoped(addr
, IFSCOPE_NONE
));
815 * Similar to ifa_foraddr, except with the added interface scope
816 * constraint (unless the caller passes in IFSCOPE_NONE in which
817 * case there is no scope restriction).
819 __private_extern__
struct in_ifaddr
*
820 ifa_foraddr_scoped(unsigned int addr
, unsigned int scope
)
822 struct in_ifaddr
*ia
= NULL
;
824 lck_rw_lock_shared(in_ifaddr_rwlock
);
825 TAILQ_FOREACH(ia
, INADDR_HASH(addr
), ia_hash
) {
826 IFA_LOCK_SPIN(&ia
->ia_ifa
);
827 if (ia
->ia_addr
.sin_addr
.s_addr
== addr
&&
828 (scope
== IFSCOPE_NONE
|| ia
->ia_ifp
->if_index
== scope
)) {
829 IFA_ADDREF_LOCKED(&ia
->ia_ifa
); /* for caller */
830 IFA_UNLOCK(&ia
->ia_ifa
);
833 IFA_UNLOCK(&ia
->ia_ifa
);
835 lck_rw_done(in_ifaddr_rwlock
);
841 * Similar to ifa_foraddr, except that this for IPv6.
843 __private_extern__
struct in6_ifaddr
*
844 ifa_foraddr6(struct in6_addr
*addr6
)
846 return (ifa_foraddr6_scoped(addr6
, IFSCOPE_NONE
));
849 __private_extern__
struct in6_ifaddr
*
850 ifa_foraddr6_scoped(struct in6_addr
*addr6
, unsigned int scope
)
852 struct in6_ifaddr
*ia
= NULL
;
854 lck_rw_lock_shared(&in6_ifaddr_rwlock
);
855 for (ia
= in6_ifaddrs
; ia
; ia
= ia
->ia_next
) {
856 IFA_LOCK(&ia
->ia_ifa
);
857 if (IN6_ARE_ADDR_EQUAL(&ia
->ia_addr
.sin6_addr
, addr6
) &&
858 (scope
== IFSCOPE_NONE
|| ia
->ia_ifp
->if_index
== scope
)) {
859 IFA_ADDREF_LOCKED(&ia
->ia_ifa
); /* for caller */
860 IFA_UNLOCK(&ia
->ia_ifa
);
863 IFA_UNLOCK(&ia
->ia_ifa
);
865 lck_rw_done(&in6_ifaddr_rwlock
);
872 * Return the first (primary) address of a given family on an interface.
874 __private_extern__
struct ifaddr
*
875 ifa_ifpgetprimary(struct ifnet
*ifp
, int family
)
879 ifnet_lock_shared(ifp
);
880 TAILQ_FOREACH(ifa
, &ifp
->if_addrhead
, ifa_link
) {
882 if (ifa
->ifa_addr
->sa_family
== family
) {
883 IFA_ADDREF_LOCKED(ifa
); /* for caller */
889 ifnet_lock_done(ifp
);
895 ifa_equal(const struct sockaddr
*sa1
, const struct sockaddr
*sa2
)
900 if (sa1
->sa_len
!= sa2
->sa_len
)
903 return (bcmp(sa1
, sa2
, sa1
->sa_len
) == 0);
907 * Locate an interface based on a complete address.
910 ifa_ifwithaddr_locked(const struct sockaddr
*addr
)
914 struct ifaddr
*result
= NULL
;
916 for (ifp
= ifnet_head
.tqh_first
; ifp
&& !result
;
917 ifp
= ifp
->if_link
.tqe_next
) {
918 ifnet_lock_shared(ifp
);
919 for (ifa
= ifp
->if_addrhead
.tqh_first
; ifa
;
920 ifa
= ifa
->ifa_link
.tqe_next
) {
922 if (ifa
->ifa_addr
->sa_family
!= addr
->sa_family
) {
926 if (ifa_equal(addr
, ifa
->ifa_addr
)) {
928 IFA_ADDREF_LOCKED(ifa
); /* for caller */
932 if ((ifp
->if_flags
& IFF_BROADCAST
) &&
933 ifa
->ifa_broadaddr
!= NULL
&&
934 /* IP6 doesn't have broadcast */
935 ifa
->ifa_broadaddr
->sa_len
!= 0 &&
936 ifa_equal(ifa
->ifa_broadaddr
, addr
)) {
938 IFA_ADDREF_LOCKED(ifa
); /* for caller */
944 ifnet_lock_done(ifp
);
951 ifa_ifwithaddr(const struct sockaddr
*addr
)
953 struct ifaddr
*result
= NULL
;
955 ifnet_head_lock_shared();
957 result
= ifa_ifwithaddr_locked(addr
);
964 * Locate the point to point interface with a given destination address.
968 ifa_ifwithdstaddr(const struct sockaddr
*addr
)
972 struct ifaddr
*result
= NULL
;
974 ifnet_head_lock_shared();
975 for (ifp
= ifnet_head
.tqh_first
; ifp
&& !result
;
976 ifp
= ifp
->if_link
.tqe_next
) {
977 if ((ifp
->if_flags
& IFF_POINTOPOINT
)) {
978 ifnet_lock_shared(ifp
);
979 for (ifa
= ifp
->if_addrhead
.tqh_first
; ifa
;
980 ifa
= ifa
->ifa_link
.tqe_next
) {
982 if (ifa
->ifa_addr
->sa_family
!=
987 if (ifa_equal(addr
, ifa
->ifa_dstaddr
)) {
989 IFA_ADDREF_LOCKED(ifa
); /* for caller */
995 ifnet_lock_done(ifp
);
1003 * Locate the source address of an interface based on a complete address.
1006 ifa_ifwithaddr_scoped_locked(const struct sockaddr
*addr
, unsigned int ifscope
)
1008 struct ifaddr
*result
= NULL
;
1011 if (ifscope
== IFSCOPE_NONE
)
1012 return (ifa_ifwithaddr_locked(addr
));
1014 if (ifscope
> (unsigned int)if_index
) {
1018 ifp
= ifindex2ifnet
[ifscope
];
1020 struct ifaddr
*ifa
= NULL
;
1023 * This is suboptimal; there should be a better way
1024 * to search for a given address of an interface
1025 * for any given address family.
1027 ifnet_lock_shared(ifp
);
1028 for (ifa
= ifp
->if_addrhead
.tqh_first
; ifa
!= NULL
;
1029 ifa
= ifa
->ifa_link
.tqe_next
) {
1031 if (ifa
->ifa_addr
->sa_family
!= addr
->sa_family
) {
1035 if (ifa_equal(addr
, ifa
->ifa_addr
)) {
1037 IFA_ADDREF_LOCKED(ifa
); /* for caller */
1041 if ((ifp
->if_flags
& IFF_BROADCAST
) &&
1042 ifa
->ifa_broadaddr
!= NULL
&&
1043 /* IP6 doesn't have broadcast */
1044 ifa
->ifa_broadaddr
->sa_len
!= 0 &&
1045 ifa_equal(ifa
->ifa_broadaddr
, addr
)) {
1047 IFA_ADDREF_LOCKED(ifa
); /* for caller */
1053 ifnet_lock_done(ifp
);
1060 ifa_ifwithaddr_scoped(const struct sockaddr
*addr
, unsigned int ifscope
)
1062 struct ifaddr
*result
= NULL
;
1064 ifnet_head_lock_shared();
1066 result
= ifa_ifwithaddr_scoped_locked(addr
, ifscope
);
1074 ifa_ifwithnet(const struct sockaddr
*addr
)
1076 return (ifa_ifwithnet_common(addr
, IFSCOPE_NONE
));
1080 ifa_ifwithnet_scoped(const struct sockaddr
*addr
, unsigned int ifscope
)
1082 return (ifa_ifwithnet_common(addr
, ifscope
));
1086 * Find an interface on a specific network. If many, choice
1087 * is most specific found.
1089 static struct ifaddr
*
1090 ifa_ifwithnet_common(const struct sockaddr
*addr
, unsigned int ifscope
)
1093 struct ifaddr
*ifa
= NULL
;
1094 struct ifaddr
*ifa_maybe
= NULL
;
1095 u_int af
= addr
->sa_family
;
1096 const char *addr_data
= addr
->sa_data
, *cplim
;
1099 if (af
!= AF_INET
&& af
!= AF_INET6
)
1103 ifscope
= IFSCOPE_NONE
;
1105 ifnet_head_lock_shared();
1107 * AF_LINK addresses can be looked up directly by their index number,
1108 * so do that if we can.
1110 if (af
== AF_LINK
) {
1111 const struct sockaddr_dl
*sdl
=
1112 (const struct sockaddr_dl
*)(uintptr_t)(size_t)addr
;
1113 if (sdl
->sdl_index
&& sdl
->sdl_index
<= if_index
) {
1114 ifa
= ifnet_addrs
[sdl
->sdl_index
- 1];
1124 * Scan though each interface, looking for ones that have
1125 * addresses in this address family.
1127 for (ifp
= ifnet_head
.tqh_first
; ifp
; ifp
= ifp
->if_link
.tqe_next
) {
1128 ifnet_lock_shared(ifp
);
1129 for (ifa
= ifp
->if_addrhead
.tqh_first
; ifa
;
1130 ifa
= ifa
->ifa_link
.tqe_next
) {
1131 const char *cp
, *cp2
, *cp3
;
1134 if (ifa
->ifa_addr
== NULL
||
1135 ifa
->ifa_addr
->sa_family
!= af
) {
1141 * If we're looking up with a scope,
1142 * find using a matching interface.
1144 if (ifscope
!= IFSCOPE_NONE
&&
1145 ifp
->if_index
!= ifscope
) {
1151 * Scan all the bits in the ifa's address.
1152 * If a bit dissagrees with what we are
1153 * looking for, mask it with the netmask
1154 * to see if it really matters.
1155 * (A byte at a time)
1157 if (ifa
->ifa_netmask
== 0) {
1162 cp2
= ifa
->ifa_addr
->sa_data
;
1163 cp3
= ifa
->ifa_netmask
->sa_data
;
1164 cplim
= ifa
->ifa_netmask
->sa_len
+
1165 (char *)ifa
->ifa_netmask
;
1167 if ((*cp
++ ^ *cp2
++) & *cp3
++)
1168 goto next
; /* next address! */
1170 * If the netmask of what we just found
1171 * is more specific than what we had before
1172 * (if we had one) then remember the new one
1173 * before continuing to search
1174 * for an even better one.
1176 if (ifa_maybe
== NULL
||
1177 rn_refines((caddr_t
)ifa
->ifa_netmask
,
1178 (caddr_t
)ifa_maybe
->ifa_netmask
)) {
1179 IFA_ADDREF_LOCKED(ifa
); /* ifa_maybe */
1181 if (ifa_maybe
!= NULL
)
1182 IFA_REMREF(ifa_maybe
);
1187 IFA_LOCK_ASSERT_NOTHELD(ifa
);
1189 ifnet_lock_done(ifp
);
1198 else if (ifa_maybe
!= NULL
)
1199 IFA_REMREF(ifa_maybe
);
1205 * Find an interface address specific to an interface best matching
1206 * a given address applying same source address selection rules
1207 * as done in the kernel for implicit source address binding
1210 ifaof_ifpforaddr_select(const struct sockaddr
*addr
, struct ifnet
*ifp
)
1212 u_int af
= addr
->sa_family
;
1215 return (in6_selectsrc_core_ifa(__DECONST(struct sockaddr_in6
*, addr
), ifp
, 0));
1217 return (ifaof_ifpforaddr(addr
, ifp
));
1221 * Find an interface address specific to an interface best matching
1222 * a given address without regards to source address selection.
1224 * This is appropriate for use-cases where we just want to update/init
1225 * some data structure like routing table entries.
1228 ifaof_ifpforaddr(const struct sockaddr
*addr
, struct ifnet
*ifp
)
1230 struct ifaddr
*ifa
= NULL
;
1231 const char *cp
, *cp2
, *cp3
;
1233 struct ifaddr
*ifa_maybe
= NULL
;
1234 struct ifaddr
*better_ifa_maybe
= NULL
;
1235 u_int af
= addr
->sa_family
;
1240 ifnet_lock_shared(ifp
);
1241 for (ifa
= ifp
->if_addrhead
.tqh_first
; ifa
;
1242 ifa
= ifa
->ifa_link
.tqe_next
) {
1244 if (ifa
->ifa_addr
->sa_family
!= af
) {
1248 if (ifa_maybe
== NULL
) {
1249 IFA_ADDREF_LOCKED(ifa
); /* for ifa_maybe */
1252 if (ifa
->ifa_netmask
== 0) {
1253 if (ifa_equal(addr
, ifa
->ifa_addr
) ||
1254 ifa_equal(addr
, ifa
->ifa_dstaddr
)) {
1255 IFA_ADDREF_LOCKED(ifa
); /* for caller */
1262 if (ifp
->if_flags
& IFF_POINTOPOINT
) {
1263 if (ifa_equal(addr
, ifa
->ifa_dstaddr
)) {
1264 IFA_ADDREF_LOCKED(ifa
); /* for caller */
1269 if (ifa_equal(addr
, ifa
->ifa_addr
)) {
1271 IFA_ADDREF_LOCKED(ifa
); /* for caller */
1276 cp2
= ifa
->ifa_addr
->sa_data
;
1277 cp3
= ifa
->ifa_netmask
->sa_data
;
1278 cplim
= ifa
->ifa_netmask
->sa_len
+
1279 (char *)ifa
->ifa_netmask
;
1280 for (; cp3
< cplim
; cp3
++)
1281 if ((*cp
++ ^ *cp2
++) & *cp3
)
1285 if (better_ifa_maybe
== NULL
) {
1286 /* for better_ifa_maybe */
1287 IFA_ADDREF_LOCKED(ifa
);
1288 better_ifa_maybe
= ifa
;
1296 if (better_ifa_maybe
!= NULL
) {
1297 ifa
= better_ifa_maybe
;
1298 better_ifa_maybe
= NULL
;
1305 ifnet_lock_done(ifp
);
1307 if (better_ifa_maybe
!= NULL
)
1308 IFA_REMREF(better_ifa_maybe
);
1309 if (ifa_maybe
!= NULL
)
1310 IFA_REMREF(ifa_maybe
);
1315 #include <net/route.h>
1318 * Default action when installing a route with a Link Level gateway.
1319 * Lookup an appropriate real ifa to point to.
1320 * This should be moved to /sys/net/link.c eventually.
1323 link_rtrequest(int cmd
, struct rtentry
*rt
, struct sockaddr
*sa
)
1326 struct sockaddr
*dst
;
1328 void (*ifa_rtrequest
)(int, struct rtentry
*, struct sockaddr
*);
1330 LCK_MTX_ASSERT(rnh_lock
, LCK_MTX_ASSERT_OWNED
);
1331 RT_LOCK_ASSERT_HELD(rt
);
1333 if (cmd
!= RTM_ADD
|| ((ifa
= rt
->rt_ifa
) == 0) ||
1334 ((ifp
= ifa
->ifa_ifp
) == 0) || ((dst
= rt_key(rt
)) == 0))
1337 /* Become a regular mutex, just in case */
1338 RT_CONVERT_LOCK(rt
);
1340 ifa
= ifaof_ifpforaddr(dst
, ifp
);
1344 ifa_rtrequest
= ifa
->ifa_rtrequest
;
1346 if (ifa_rtrequest
!= NULL
&& ifa_rtrequest
!= link_rtrequest
)
1347 ifa_rtrequest(cmd
, rt
, sa
);
1353 * if_updown will set the interface up or down. It will
1354 * prevent other up/down events from occurring until this
1355 * up/down event has completed.
1357 * Caller must lock ifnet. This function will drop the
1358 * lock. This allows ifnet_set_flags to set the rest of
1359 * the flags after we change the up/down state without
1360 * dropping the interface lock between setting the
1361 * up/down state and updating the rest of the flags.
1363 __private_extern__
void
1364 if_updown( struct ifnet
*ifp
, int up
)
1367 struct ifaddr
**ifa
;
1369 struct ifclassq
*ifq
= &ifp
->if_snd
;
1371 /* Wait until no one else is changing the up/down state */
1372 while ((ifp
->if_eflags
& IFEF_UPDOWNCHANGE
) != 0) {
1374 tv
.tv_nsec
= NSEC_PER_SEC
/ 10;
1375 ifnet_lock_done(ifp
);
1376 msleep(&ifp
->if_eflags
, NULL
, 0, "if_updown", &tv
);
1377 ifnet_lock_exclusive(ifp
);
1380 /* Verify that the interface isn't already in the right state */
1381 if ((!up
&& (ifp
->if_flags
& IFF_UP
) == 0) ||
1382 (up
&& (ifp
->if_flags
& IFF_UP
) == IFF_UP
)) {
1386 /* Indicate that the up/down state is changing */
1387 ifp
->if_eflags
|= IFEF_UPDOWNCHANGE
;
1389 /* Mark interface up or down */
1391 ifp
->if_flags
|= IFF_UP
;
1393 ifp
->if_flags
&= ~IFF_UP
;
1396 ifnet_touch_lastchange(ifp
);
1397 ifnet_touch_lastupdown(ifp
);
1399 /* Drop the lock to notify addresses and route */
1400 ifnet_lock_done(ifp
);
1405 /* Inform all transmit queues about the new link state */
1406 ifnet_update_sndq(ifq
, up
? CLASSQ_EV_LINK_UP
: CLASSQ_EV_LINK_DOWN
);
1409 if (ifnet_get_address_list(ifp
, &ifa
) == 0) {
1410 for (i
= 0; ifa
[i
] != 0; i
++) {
1411 pfctlinput(up
? PRC_IFUP
: PRC_IFDOWN
, ifa
[i
]->ifa_addr
);
1413 ifnet_free_address_list(ifa
);
1417 /* Aquire the lock to clear the changing flag */
1418 ifnet_lock_exclusive(ifp
);
1419 ifp
->if_eflags
&= ~IFEF_UPDOWNCHANGE
;
1420 wakeup(&ifp
->if_eflags
);
1424 * Mark an interface down and notify protocols of
1431 ifnet_lock_exclusive(ifp
);
1433 ifnet_lock_done(ifp
);
1437 * Mark an interface up and notify protocols of
1444 ifnet_lock_exclusive(ifp
);
1446 ifnet_lock_done(ifp
);
1450 * Flush an interface queue.
1453 if_qflush(struct ifnet
*ifp
, int ifq_locked
)
1455 struct ifclassq
*ifq
= &ifp
->if_snd
;
1460 if (IFCQ_IS_ENABLED(ifq
))
1463 VERIFY(IFCQ_IS_EMPTY(ifq
));
1470 if_qflush_sc(struct ifnet
*ifp
, mbuf_svc_class_t sc
, u_int32_t flow
,
1471 u_int32_t
*packets
, u_int32_t
*bytes
, int ifq_locked
)
1473 struct ifclassq
*ifq
= &ifp
->if_snd
;
1474 u_int32_t cnt
= 0, len
= 0;
1475 u_int32_t a_cnt
= 0, a_len
= 0;
1477 VERIFY(sc
== MBUF_SC_UNSPEC
|| MBUF_VALID_SC(sc
));
1483 if (IFCQ_IS_ENABLED(ifq
))
1484 IFCQ_PURGE_SC(ifq
, sc
, flow
, cnt
, len
);
1489 if (packets
!= NULL
)
1490 *packets
= cnt
+ a_cnt
;
1492 *bytes
= len
+ a_len
;
1496 * Extracts interface unit number and name from string, returns -1 upon failure.
1497 * Upon success, returns extracted unit number, and interface name in dst.
1500 ifunit_extract(const char *src
, char *dst
, size_t dstlen
, int *unit
)
1507 if (src
== NULL
|| dst
== NULL
|| dstlen
== 0 || unit
== NULL
)
1511 if (len
< 2 || len
> dstlen
)
1515 if (c
< '0' || c
> '9')
1516 return (-1); /* trailing garbage */
1521 return (-1); /* no interface name */
1524 return (-1); /* number is unreasonable */
1527 } while (c
>= '0' && c
<= '9');
1529 bcopy(src
, dst
, len
);
1537 * Map interface name to
1538 * interface structure pointer.
1540 static struct ifnet
*
1541 ifunit_common(const char *name
, boolean_t hold
)
1543 char namebuf
[IFNAMSIZ
+ 1];
1547 if (ifunit_extract(name
, namebuf
, sizeof (namebuf
), &unit
) < 0)
1550 /* for safety, since we use strcmp() below */
1551 namebuf
[sizeof (namebuf
) - 1] = '\0';
1554 * Now search all the interfaces for this name/number
1556 ifnet_head_lock_shared();
1557 TAILQ_FOREACH(ifp
, &ifnet_head
, if_link
) {
1559 * Use strcmp() rather than strncmp() here,
1560 * since we want to match the entire string.
1562 if (strcmp(ifp
->if_name
, namebuf
))
1564 if (unit
== ifp
->if_unit
)
1568 /* if called from ifunit_ref() and ifnet is not attached, bail */
1569 if (hold
&& ifp
!= NULL
&& !ifnet_is_attached(ifp
, 1))
1577 ifunit(const char *name
)
1579 return (ifunit_common(name
, FALSE
));
1583 * Similar to ifunit(), except that we hold an I/O reference count on an
1584 * attached interface, which must later be released via ifnet_decr_iorefcnt().
1585 * Will return NULL unless interface exists and is fully attached.
1588 ifunit_ref(const char *name
)
1590 return (ifunit_common(name
, TRUE
));
1594 * Map interface name in a sockaddr_dl to
1595 * interface structure pointer.
1598 if_withname(struct sockaddr
*sa
)
1600 char ifname
[IFNAMSIZ
+1];
1601 struct sockaddr_dl
*sdl
= (struct sockaddr_dl
*)(void *)sa
;
1603 if ((sa
->sa_family
!= AF_LINK
) || (sdl
->sdl_nlen
== 0) ||
1604 (sdl
->sdl_nlen
> IFNAMSIZ
))
1608 * ifunit wants a null-terminated name. It may not be null-terminated
1609 * in the sockaddr. We don't want to change the caller's sockaddr,
1610 * and there might not be room to put the trailing null anyway, so we
1611 * make a local copy that we know we can null terminate safely.
1614 bcopy(sdl
->sdl_data
, ifname
, sdl
->sdl_nlen
);
1615 ifname
[sdl
->sdl_nlen
] = '\0';
1616 return (ifunit(ifname
));
1619 static __attribute__((noinline
)) int
1620 ifioctl_ifconf(u_long cmd
, caddr_t data
)
1625 case OSIOCGIFCONF32
: /* struct ifconf32 */
1626 case SIOCGIFCONF32
: { /* struct ifconf32 */
1627 struct ifconf32 ifc
;
1628 bcopy(data
, &ifc
, sizeof (ifc
));
1629 error
= ifconf(cmd
, CAST_USER_ADDR_T(ifc
.ifc_req
),
1631 bcopy(&ifc
, data
, sizeof (ifc
));
1635 case SIOCGIFCONF64
: /* struct ifconf64 */
1636 case OSIOCGIFCONF64
: { /* struct ifconf64 */
1637 struct ifconf64 ifc
;
1638 bcopy(data
, &ifc
, sizeof (ifc
));
1639 error
= ifconf(cmd
, ifc
.ifc_req
, &ifc
.ifc_len
);
1640 bcopy(&ifc
, data
, sizeof (ifc
));
1652 static __attribute__((noinline
)) int
1653 ifioctl_ifclone(u_long cmd
, caddr_t data
)
1658 case SIOCIFGCLONERS32
: { /* struct if_clonereq32 */
1659 struct if_clonereq32 ifcr
;
1660 bcopy(data
, &ifcr
, sizeof (ifcr
));
1661 error
= if_clone_list(ifcr
.ifcr_count
, &ifcr
.ifcr_total
,
1662 CAST_USER_ADDR_T(ifcr
.ifcru_buffer
));
1663 bcopy(&ifcr
, data
, sizeof (ifcr
));
1667 case SIOCIFGCLONERS64
: { /* struct if_clonereq64 */
1668 struct if_clonereq64 ifcr
;
1669 bcopy(data
, &ifcr
, sizeof (ifcr
));
1670 error
= if_clone_list(ifcr
.ifcr_count
, &ifcr
.ifcr_total
,
1672 bcopy(&ifcr
, data
, sizeof (ifcr
));
1684 static __attribute__((noinline
)) int
1685 ifioctl_ifdesc(struct ifnet
*ifp
, u_long cmd
, caddr_t data
, struct proc
*p
)
1687 struct if_descreq
*ifdr
= (struct if_descreq
*)(void *)data
;
1691 VERIFY(ifp
!= NULL
);
1694 case SIOCSIFDESC
: { /* struct if_descreq */
1695 if ((error
= proc_suser(p
)) != 0)
1698 ifnet_lock_exclusive(ifp
);
1699 bcopy(&ifdr
->ifdr_len
, &ifdr_len
, sizeof (ifdr_len
));
1700 if (ifdr_len
> sizeof (ifdr
->ifdr_desc
) ||
1701 ifdr_len
> ifp
->if_desc
.ifd_maxlen
) {
1703 ifnet_lock_done(ifp
);
1707 bzero(ifp
->if_desc
.ifd_desc
, ifp
->if_desc
.ifd_maxlen
);
1708 if ((ifp
->if_desc
.ifd_len
= ifdr_len
) > 0) {
1709 bcopy(ifdr
->ifdr_desc
, ifp
->if_desc
.ifd_desc
,
1710 MIN(ifdr_len
, ifp
->if_desc
.ifd_maxlen
));
1712 ifnet_lock_done(ifp
);
1716 case SIOCGIFDESC
: { /* struct if_descreq */
1717 ifnet_lock_shared(ifp
);
1718 ifdr_len
= MIN(ifp
->if_desc
.ifd_len
, sizeof (ifdr
->ifdr_desc
));
1719 bcopy(&ifdr_len
, &ifdr
->ifdr_len
, sizeof (ifdr_len
));
1720 bzero(&ifdr
->ifdr_desc
, sizeof (ifdr
->ifdr_desc
));
1722 bcopy(ifp
->if_desc
.ifd_desc
, ifdr
->ifdr_desc
, ifdr_len
);
1724 ifnet_lock_done(ifp
);
1736 static __attribute__((noinline
)) int
1737 ifioctl_linkparams(struct ifnet
*ifp
, u_long cmd
, caddr_t data
, struct proc
*p
)
1739 struct if_linkparamsreq
*iflpr
=
1740 (struct if_linkparamsreq
*)(void *)data
;
1741 struct ifclassq
*ifq
;
1744 VERIFY(ifp
!= NULL
);
1748 case SIOCSIFLINKPARAMS
: { /* struct if_linkparamsreq */
1749 struct tb_profile tb
= { 0, 0, 0 };
1751 if ((error
= proc_suser(p
)) != 0)
1756 if (!IFCQ_IS_READY(ifq
)) {
1761 bcopy(&iflpr
->iflpr_output_tbr_rate
, &tb
.rate
,
1763 bcopy(&iflpr
->iflpr_output_tbr_percent
, &tb
.percent
,
1764 sizeof (tb
.percent
));
1765 error
= ifclassq_tbr_set(ifq
, &tb
, TRUE
);
1770 case SIOCGIFLINKPARAMS
: { /* struct if_linkparamsreq */
1771 u_int32_t sched_type
= PKTSCHEDT_NONE
, flags
= 0;
1772 u_int64_t tbr_bw
= 0, tbr_pct
= 0;
1776 if (IFCQ_IS_ENABLED(ifq
))
1777 sched_type
= ifq
->ifcq_type
;
1779 bcopy(&sched_type
, &iflpr
->iflpr_output_sched
,
1780 sizeof (iflpr
->iflpr_output_sched
));
1782 if (IFCQ_TBR_IS_ENABLED(ifq
)) {
1783 tbr_bw
= ifq
->ifcq_tbr
.tbr_rate_raw
;
1784 tbr_pct
= ifq
->ifcq_tbr
.tbr_percent
;
1786 bcopy(&tbr_bw
, &iflpr
->iflpr_output_tbr_rate
,
1787 sizeof (iflpr
->iflpr_output_tbr_rate
));
1788 bcopy(&tbr_pct
, &iflpr
->iflpr_output_tbr_percent
,
1789 sizeof (iflpr
->iflpr_output_tbr_percent
));
1792 if (ifp
->if_output_sched_model
==
1793 IFNET_SCHED_MODEL_DRIVER_MANAGED
)
1794 flags
|= IFLPRF_DRVMANAGED
;
1795 bcopy(&flags
, &iflpr
->iflpr_flags
, sizeof (iflpr
->iflpr_flags
));
1796 bcopy(&ifp
->if_output_bw
, &iflpr
->iflpr_output_bw
,
1797 sizeof (iflpr
->iflpr_output_bw
));
1798 bcopy(&ifp
->if_input_bw
, &iflpr
->iflpr_input_bw
,
1799 sizeof (iflpr
->iflpr_input_bw
));
1800 bcopy(&ifp
->if_output_lt
, &iflpr
->iflpr_output_lt
,
1801 sizeof (iflpr
->iflpr_output_lt
));
1802 bcopy(&ifp
->if_input_lt
, &iflpr
->iflpr_input_lt
,
1803 sizeof (iflpr
->iflpr_input_lt
));
1815 static __attribute__((noinline
)) int
1816 ifioctl_qstats(struct ifnet
*ifp
, u_long cmd
, caddr_t data
)
1818 struct if_qstatsreq
*ifqr
= (struct if_qstatsreq
*)(void *)data
;
1819 u_int32_t ifqr_len
, ifqr_slot
;
1822 VERIFY(ifp
!= NULL
);
1825 case SIOCGIFQUEUESTATS
: { /* struct if_qstatsreq */
1826 bcopy(&ifqr
->ifqr_slot
, &ifqr_slot
, sizeof (ifqr_slot
));
1827 bcopy(&ifqr
->ifqr_len
, &ifqr_len
, sizeof (ifqr_len
));
1828 error
= ifclassq_getqstats(&ifp
->if_snd
, ifqr_slot
,
1829 ifqr
->ifqr_buf
, &ifqr_len
);
1832 bcopy(&ifqr_len
, &ifqr
->ifqr_len
, sizeof (ifqr_len
));
1844 static __attribute__((noinline
)) int
1845 ifioctl_throttle(struct ifnet
*ifp
, u_long cmd
, caddr_t data
, struct proc
*p
)
1847 struct if_throttlereq
*ifthr
= (struct if_throttlereq
*)(void *)data
;
1848 u_int32_t ifthr_level
;
1851 VERIFY(ifp
!= NULL
);
1854 case SIOCSIFTHROTTLE
: { /* struct if_throttlereq */
1856 * XXX: Use priv_check_cred() instead of root check?
1858 if ((error
= proc_suser(p
)) != 0)
1861 bcopy(&ifthr
->ifthr_level
, &ifthr_level
, sizeof (ifthr_level
));
1862 error
= ifnet_set_throttle(ifp
, ifthr_level
);
1863 if (error
== EALREADY
)
1868 case SIOCGIFTHROTTLE
: { /* struct if_throttlereq */
1869 if ((error
= ifnet_get_throttle(ifp
, &ifthr_level
)) == 0) {
1870 bcopy(&ifthr_level
, &ifthr
->ifthr_level
,
1871 sizeof (ifthr_level
));
1885 ifioctl_getnetagents(struct ifnet
*ifp
, u_int32_t
*count
, user_addr_t uuid_p
)
1888 u_int32_t index
= 0;
1889 u_int32_t valid_netagent_count
= 0;
1892 ifnet_lock_assert(ifp
, IFNET_LCK_ASSERT_SHARED
);
1894 if (ifp
->if_agentids
!= NULL
) {
1895 for (index
= 0; index
< ifp
->if_agentcount
; index
++) {
1896 uuid_t
*netagent_uuid
= &(ifp
->if_agentids
[index
]);
1897 if (!uuid_is_null(*netagent_uuid
)) {
1898 if (uuid_p
!= USER_ADDR_NULL
) {
1899 error
= copyout(netagent_uuid
,
1900 uuid_p
+ sizeof(uuid_t
) * valid_netagent_count
,
1906 valid_netagent_count
++;
1910 *count
= valid_netagent_count
;
1915 #define IF_MAXAGENTS 64
1916 #define IF_AGENT_INCREMENT 8
1918 if_add_netagent_locked(struct ifnet
*ifp
, uuid_t new_agent_uuid
)
1920 uuid_t
*first_empty_slot
= NULL
;
1921 u_int32_t index
= 0;
1922 bool already_added
= FALSE
;
1924 if (ifp
->if_agentids
!= NULL
) {
1925 for (index
= 0; index
< ifp
->if_agentcount
; index
++) {
1926 uuid_t
*netagent_uuid
= &(ifp
->if_agentids
[index
]);
1927 if (uuid_compare(*netagent_uuid
, new_agent_uuid
) == 0) {
1928 /* Already present, ignore */
1929 already_added
= TRUE
;
1932 if (first_empty_slot
== NULL
&&
1933 uuid_is_null(*netagent_uuid
)) {
1934 first_empty_slot
= netagent_uuid
;
1938 if (already_added
) {
1939 /* Already added agent, don't return an error */
1942 if (first_empty_slot
== NULL
) {
1943 if (ifp
->if_agentcount
>= IF_MAXAGENTS
) {
1944 /* No room for another netagent UUID, bail */
1947 /* Calculate new array size */
1948 u_int32_t new_agent_count
=
1949 MIN(ifp
->if_agentcount
+ IF_AGENT_INCREMENT
,
1952 /* Reallocate array */
1953 uuid_t
*new_agent_array
= _REALLOC(ifp
->if_agentids
,
1954 sizeof(uuid_t
) * new_agent_count
, M_NETAGENT
,
1956 if (new_agent_array
== NULL
) {
1960 /* Save new array */
1961 ifp
->if_agentids
= new_agent_array
;
1963 /* Set first empty slot */
1965 &(ifp
->if_agentids
[ifp
->if_agentcount
]);
1967 /* Save new array length */
1968 ifp
->if_agentcount
= new_agent_count
;
1971 uuid_copy(*first_empty_slot
, new_agent_uuid
);
1972 netagent_post_updated_interfaces(new_agent_uuid
);
1977 if_add_netagent(struct ifnet
*ifp
, uuid_t new_agent_uuid
)
1979 VERIFY(ifp
!= NULL
);
1981 ifnet_lock_exclusive(ifp
);
1983 int error
= if_add_netagent_locked(ifp
, new_agent_uuid
);
1985 ifnet_lock_done(ifp
);
1991 if_delete_netagent_locked(struct ifnet
*ifp
, uuid_t remove_agent_uuid
)
1993 u_int32_t index
= 0;
1994 bool removed_agent_id
= FALSE
;
1996 if (ifp
->if_agentids
!= NULL
) {
1997 for (index
= 0; index
< ifp
->if_agentcount
; index
++) {
1998 uuid_t
*netagent_uuid
= &(ifp
->if_agentids
[index
]);
1999 if (uuid_compare(*netagent_uuid
,
2000 remove_agent_uuid
) == 0) {
2001 uuid_clear(*netagent_uuid
);
2002 removed_agent_id
= TRUE
;
2007 if (removed_agent_id
)
2008 netagent_post_updated_interfaces(remove_agent_uuid
);
2014 if_delete_netagent(struct ifnet
*ifp
, uuid_t remove_agent_uuid
)
2016 VERIFY(ifp
!= NULL
);
2018 ifnet_lock_exclusive(ifp
);
2020 int error
= if_delete_netagent_locked(ifp
, remove_agent_uuid
);
2022 ifnet_lock_done(ifp
);
2028 if_check_netagent(struct ifnet
*ifp
, uuid_t find_agent_uuid
)
2030 boolean_t found
= FALSE
;
2032 if (!ifp
|| uuid_is_null(find_agent_uuid
))
2035 ifnet_lock_shared(ifp
);
2037 if (ifp
->if_agentids
!= NULL
) {
2038 for (uint32_t index
= 0; index
< ifp
->if_agentcount
; index
++) {
2039 if (uuid_compare(ifp
->if_agentids
[index
], find_agent_uuid
) == 0) {
2046 ifnet_lock_done(ifp
);
2051 static __attribute__((noinline
)) int
2052 ifioctl_netagent(struct ifnet
*ifp
, u_long cmd
, caddr_t data
, struct proc
*p
)
2054 struct if_agentidreq
*ifar
= (struct if_agentidreq
*)(void *)data
;
2056 struct if_agentidsreq32 s32
;
2057 struct if_agentidsreq64 s64
;
2061 VERIFY(ifp
!= NULL
);
2063 /* Get an io ref count if the interface is attached */
2064 if (!ifnet_is_attached(ifp
, 1)) {
2065 return (EOPNOTSUPP
);
2068 if (cmd
== SIOCAIFAGENTID
||
2069 cmd
== SIOCDIFAGENTID
) {
2070 ifnet_lock_exclusive(ifp
);
2072 ifnet_lock_shared(ifp
);
2076 case SIOCAIFAGENTID
: { /* struct if_agentidreq */
2077 // TODO: Use priv_check_cred() instead of root check
2078 if ((error
= proc_suser(p
)) != 0) {
2081 error
= if_add_netagent_locked(ifp
, ifar
->ifar_uuid
);
2084 case SIOCDIFAGENTID
: { /* struct if_agentidreq */
2085 // TODO: Use priv_check_cred() instead of root check
2086 if ((error
= proc_suser(p
)) != 0) {
2089 error
= if_delete_netagent_locked(ifp
, ifar
->ifar_uuid
);
2092 case SIOCGIFAGENTIDS32
: { /* struct if_agentidsreq32 */
2093 bcopy(data
, &u
.s32
, sizeof(u
.s32
));
2094 error
= ifioctl_getnetagents(ifp
, &u
.s32
.ifar_count
,
2097 bcopy(&u
.s32
, data
, sizeof(u
.s32
));
2101 case SIOCGIFAGENTIDS64
: { /* struct if_agentidsreq64 */
2102 bcopy(data
, &u
.s64
, sizeof(u
.s64
));
2103 error
= ifioctl_getnetagents(ifp
, &u
.s64
.ifar_count
,
2106 bcopy(&u
.s64
, data
, sizeof(u
.s64
));
2115 ifnet_lock_done(ifp
);
2116 ifnet_decr_iorefcnt(ifp
);
2122 ifnet_clear_netagent(uuid_t netagent_uuid
)
2124 struct ifnet
*ifp
= NULL
;
2125 u_int32_t index
= 0;
2127 ifnet_head_lock_shared();
2129 TAILQ_FOREACH(ifp
, &ifnet_head
, if_link
) {
2130 ifnet_lock_shared(ifp
);
2131 if (ifp
->if_agentids
!= NULL
) {
2132 for (index
= 0; index
< ifp
->if_agentcount
; index
++) {
2133 uuid_t
*ifp_netagent_uuid
= &(ifp
->if_agentids
[index
]);
2134 if (uuid_compare(*ifp_netagent_uuid
, netagent_uuid
) == 0) {
2135 uuid_clear(*ifp_netagent_uuid
);
2139 ifnet_lock_done(ifp
);
2146 ifnet_increment_generation(ifnet_t interface
)
2148 OSIncrementAtomic(&interface
->if_generation
);
2152 ifnet_get_generation(ifnet_t interface
)
2154 return (interface
->if_generation
);
2158 ifnet_remove_from_ordered_list(struct ifnet
*ifp
)
2160 ifnet_head_assert_exclusive();
2163 TAILQ_REMOVE(&ifnet_ordered_head
, ifp
, if_ordered_link
);
2164 ifp
->if_ordered_link
.tqe_next
= NULL
;
2165 ifp
->if_ordered_link
.tqe_prev
= NULL
;
2167 // Update ordered count
2168 VERIFY(if_ordered_count
> 0);
2173 ifnet_reset_order(u_int32_t
*ordered_indices
, u_int32_t count
)
2175 struct ifnet
*ifp
= NULL
;
2178 ifnet_head_lock_exclusive();
2179 for (u_int32_t order_index
= 0; order_index
< count
; order_index
++) {
2180 if (ordered_indices
[order_index
] == IFSCOPE_NONE
||
2181 ordered_indices
[order_index
] > (uint32_t)if_index
) {
2187 // Flush current ordered list
2188 for (ifp
= TAILQ_FIRST(&ifnet_ordered_head
); ifp
!= NULL
;
2189 ifp
= TAILQ_FIRST(&ifnet_ordered_head
)) {
2190 ifnet_lock_exclusive(ifp
);
2191 ifnet_remove_from_ordered_list(ifp
);
2192 ifnet_lock_done(ifp
);
2195 VERIFY(if_ordered_count
== 0);
2197 for (u_int32_t order_index
= 0; order_index
< count
; order_index
++) {
2198 u_int32_t interface_index
= ordered_indices
[order_index
];
2199 ifp
= ifindex2ifnet
[interface_index
];
2203 ifnet_lock_exclusive(ifp
);
2204 TAILQ_INSERT_TAIL(&ifnet_ordered_head
, ifp
, if_ordered_link
);
2205 ifnet_lock_done(ifp
);
2211 necp_update_all_clients();
2217 if_set_qosmarking_mode(struct ifnet
*ifp
, u_int32_t mode
)
2220 u_int32_t old_mode
= ifp
->if_qosmarking_mode
;
2223 case IFRTYPE_QOSMARKING_MODE_NONE
:
2224 ifp
->if_qosmarking_mode
= IFRTYPE_QOSMARKING_MODE_NONE
;
2225 ifp
->if_eflags
&= ~IFEF_QOSMARKING_CAPABLE
;
2227 case IFRTYPE_QOSMARKING_FASTLANE
:
2228 ifp
->if_qosmarking_mode
= IFRTYPE_QOSMARKING_FASTLANE
;
2229 ifp
->if_eflags
|= IFEF_QOSMARKING_CAPABLE
;
2230 if (net_qos_policy_capable_enabled
!= 0)
2231 ifp
->if_eflags
|= IFEF_QOSMARKING_ENABLED
;
2237 if (error
== 0 && old_mode
!= ifp
->if_qosmarking_mode
) {
2238 dlil_post_msg(ifp
, KEV_DL_SUBCLASS
, KEV_DL_QOS_MODE_CHANGED
,
2239 NULL
, sizeof(struct kev_dl_rrc_state
));
2245 static __attribute__((noinline
)) int
2246 ifioctl_iforder(u_long cmd
, caddr_t data
)
2249 u_int32_t
*ordered_indices
= NULL
;
2255 case SIOCSIFORDER
: { /* struct if_order */
2256 struct if_order
*ifo
= (struct if_order
*)(void *)data
;
2258 if (ifo
->ifo_count
> (u_int32_t
)if_index
) {
2263 size_t length
= (ifo
->ifo_count
* sizeof(u_int32_t
));
2265 if (ifo
->ifo_ordered_indices
== USER_ADDR_NULL
) {
2269 ordered_indices
= _MALLOC(length
, M_NECP
, M_WAITOK
);
2270 if (ordered_indices
== NULL
) {
2275 error
= copyin(ifo
->ifo_ordered_indices
,
2276 ordered_indices
, length
);
2281 /* ordered_indices should not contain duplicates */
2282 bool found_duplicate
= FALSE
;
2283 for (uint32_t i
= 0; i
< (ifo
->ifo_count
- 1) && !found_duplicate
; i
++){
2284 for (uint32_t j
= i
+ 1; j
< ifo
->ifo_count
&& !found_duplicate
; j
++){
2285 if (ordered_indices
[j
] == ordered_indices
[i
]){
2287 found_duplicate
= TRUE
;
2292 if (found_duplicate
) {
2297 error
= ifnet_reset_order(ordered_indices
, ifo
->ifo_count
);
2308 if (ordered_indices
!= NULL
) {
2309 _FREE(ordered_indices
, M_NECP
);
2315 static __attribute__((noinline
)) int
2316 ifioctl_netsignature(struct ifnet
*ifp
, u_long cmd
, caddr_t data
)
2318 struct if_nsreq
*ifnsr
= (struct if_nsreq
*)(void *)data
;
2322 VERIFY(ifp
!= NULL
);
2325 case SIOCSIFNETSIGNATURE
: /* struct if_nsreq */
2326 if (ifnsr
->ifnsr_len
> sizeof (ifnsr
->ifnsr_data
)) {
2330 bcopy(&ifnsr
->ifnsr_flags
, &flags
, sizeof (flags
));
2331 error
= ifnet_set_netsignature(ifp
, ifnsr
->ifnsr_family
,
2332 ifnsr
->ifnsr_len
, flags
, ifnsr
->ifnsr_data
);
2335 case SIOCGIFNETSIGNATURE
: /* struct if_nsreq */
2336 ifnsr
->ifnsr_len
= sizeof (ifnsr
->ifnsr_data
);
2337 error
= ifnet_get_netsignature(ifp
, ifnsr
->ifnsr_family
,
2338 &ifnsr
->ifnsr_len
, &flags
, ifnsr
->ifnsr_data
);
2340 bcopy(&flags
, &ifnsr
->ifnsr_flags
, sizeof (flags
));
2342 ifnsr
->ifnsr_len
= 0;
2354 static __attribute__((noinline
)) int
2355 ifioctl_nat64prefix(struct ifnet
*ifp
, u_long cmd
, caddr_t data
)
2357 struct if_nat64req
*ifnat64
= (struct if_nat64req
*)(void *)data
;
2360 VERIFY(ifp
!= NULL
);
2363 case SIOCSIFNAT64PREFIX
: /* struct if_nat64req */
2364 error
= ifnet_set_nat64prefix(ifp
, ifnat64
->ifnat64_prefixes
);
2366 ip6stat
.ip6s_clat464_plat64_pfx_setfail
++;
2369 case SIOCGIFNAT64PREFIX
: /* struct if_nat64req */
2370 error
= ifnet_get_nat64prefix(ifp
, ifnat64
->ifnat64_prefixes
);
2372 ip6stat
.ip6s_clat464_plat64_pfx_getfail
++;
2383 static __attribute__((noinline
)) int
2384 ifioctl_clat46addr(struct ifnet
*ifp
, u_long cmd
, caddr_t data
)
2386 struct if_clat46req
*ifclat46
= (struct if_clat46req
*)(void *)data
;
2387 struct in6_ifaddr
*ia6_clat
= NULL
;
2390 VERIFY(ifp
!= NULL
);
2393 case SIOCGIFCLAT46ADDR
:
2394 ia6_clat
= in6ifa_ifpwithflag(ifp
, IN6_IFF_CLAT46
);
2395 if (ia6_clat
== NULL
) {
2400 bcopy(&ia6_clat
->ia_addr
.sin6_addr
, &ifclat46
->ifclat46_addr
.v6_address
,
2401 sizeof(ifclat46
->ifclat46_addr
.v6_address
));
2402 ifclat46
->ifclat46_addr
.v6_prefixlen
= ia6_clat
->ia_plen
;
2403 IFA_REMREF(&ia6_clat
->ia_ifa
);
2416 ifioctl_get_protolist(struct ifnet
*ifp
, u_int32_t
* ret_count
,
2419 u_int32_t actual_count
;
2422 u_int32_t
*list
= NULL
;
2424 /* find out how many */
2425 count
= if_get_protolist(ifp
, NULL
, 0);
2426 if (ifpl
== USER_ADDR_NULL
) {
2430 /* copy out how many there's space for */
2431 if (*ret_count
< count
) {
2437 list
= _MALLOC(count
* sizeof(*list
), M_TEMP
, M_WAITOK
| M_ZERO
);
2442 actual_count
= if_get_protolist(ifp
, list
, count
);
2443 if (actual_count
< count
) {
2444 count
= actual_count
;
2447 error
= copyout((caddr_t
)list
, ifpl
, count
* sizeof(*list
));
2452 if_free_protolist(list
);
2458 static __attribute__((noinline
)) int
2459 ifioctl_protolist(struct ifnet
*ifp
, u_long cmd
, caddr_t data
)
2464 case SIOCGIFPROTOLIST32
: { /* struct if_protolistreq32 */
2465 struct if_protolistreq32 ifpl
;
2467 bcopy(data
, &ifpl
, sizeof(ifpl
));
2468 if (ifpl
.ifpl_reserved
!= 0) {
2472 error
= ifioctl_get_protolist(ifp
, &ifpl
.ifpl_count
,
2473 CAST_USER_ADDR_T(ifpl
.ifpl_list
));
2474 bcopy(&ifpl
, data
, sizeof(ifpl
));
2477 case SIOCGIFPROTOLIST64
: { /* struct if_protolistreq64 */
2478 struct if_protolistreq64 ifpl
;
2480 bcopy(data
, &ifpl
, sizeof(ifpl
));
2481 if (ifpl
.ifpl_reserved
!= 0) {
2485 error
= ifioctl_get_protolist(ifp
, &ifpl
.ifpl_count
,
2487 bcopy(&ifpl
, data
, sizeof(ifpl
));
2499 * List the ioctl()s we can perform on restricted INTCOPROC interfaces.
2502 ifioctl_restrict_intcoproc(unsigned long cmd
, const char *ifname
,
2503 struct ifnet
*ifp
, struct proc
*p
)
2506 if (intcoproc_unrestricted
== TRUE
) {
2509 if (proc_pid(p
) == 0) {
2513 ifp
= ifunit(ifname
);
2518 if (!IFNET_IS_INTCOPROC(ifp
)) {
2522 case SIOCGIFBRDADDR
:
2533 case SIOCGIFFUNCTIONALTYPE
:
2534 case SIOCGIFPSRCADDR
:
2535 case SIOCGIFPDSTADDR
:
2536 case SIOCGIFGENERIC
:
2540 case SIOCGIFWAKEFLAGS
:
2541 case SIOCGIFGETRTREFCNT
:
2542 case SIOCGIFOPPORTUNISTIC
:
2543 case SIOCGIFLINKQUALITYMETRIC
:
2545 case SIOCGIFDELEGATE
:
2546 case SIOCGIFEXPENSIVE
:
2547 case SIOCGIFINTERFACESTATE
:
2548 case SIOCGIFPROBECONNECTIVITY
:
2549 case SIOCGIFTIMESTAMPENABLED
:
2551 case SIOCGQOSMARKINGMODE
:
2552 case SIOCGQOSMARKINGENABLED
:
2553 case SIOCGIFLOWINTERNET
:
2555 case SIOCGIFMEDIA32
:
2556 case SIOCGIFMEDIA64
:
2558 case SIOCGIFLINKPARAMS
:
2559 case SIOCGIFQUEUESTATS
:
2560 case SIOCGIFTHROTTLE
:
2561 case SIOCGIFAGENTIDS32
:
2562 case SIOCGIFAGENTIDS64
:
2563 case SIOCGIFNETSIGNATURE
:
2564 case SIOCGIFINFO_IN6
:
2565 case SIOCGIFAFLAG_IN6
:
2566 case SIOCGNBRINFO_IN6
:
2567 case SIOCGIFALIFETIME_IN6
:
2568 case SIOCGIFNETMASK_IN6
:
2569 case SIOCGIFPROTOLIST32
:
2570 case SIOCGIFPROTOLIST64
:
2573 #if (DEBUG || DEVELOPMENT)
2574 printf("%s: cmd 0x%lx not allowed (pid %u)\n",
2575 __func__
, cmd
, proc_pid(p
));
2585 * Most of the routines called to handle the ioctls would end up being
2586 * tail-call optimized, which unfortunately causes this routine to
2587 * consume too much stack space; this is the reason for the "noinline"
2588 * attribute used on those routines.
2591 ifioctl(struct socket
*so
, u_long cmd
, caddr_t data
, struct proc
*p
)
2593 char ifname
[IFNAMSIZ
+ 1];
2594 struct ifnet
*ifp
= NULL
;
2595 struct ifstat
*ifs
= NULL
;
2598 bzero(ifname
, sizeof (ifname
));
2601 * ioctls which don't require ifp, or ifreq ioctls
2604 case OSIOCGIFCONF32
: /* struct ifconf32 */
2605 case SIOCGIFCONF32
: /* struct ifconf32 */
2606 case SIOCGIFCONF64
: /* struct ifconf64 */
2607 case OSIOCGIFCONF64
: /* struct ifconf64 */
2608 error
= ifioctl_ifconf(cmd
, data
);
2611 case SIOCIFGCLONERS32
: /* struct if_clonereq32 */
2612 case SIOCIFGCLONERS64
: /* struct if_clonereq64 */
2613 error
= ifioctl_ifclone(cmd
, data
);
2616 case SIOCGIFAGENTDATA32
: /* struct netagent_req32 */
2617 case SIOCGIFAGENTDATA64
: /* struct netagent_req64 */
2618 case SIOCGIFAGENTLIST32
: /* struct netagentlist_req32 */
2619 case SIOCGIFAGENTLIST64
: /* struct netagentlist_req64 */
2620 error
= netagent_ioctl(cmd
, data
);
2623 case SIOCSIFORDER
: /* struct if_order */
2624 error
= ifioctl_iforder(cmd
, data
);
2627 case SIOCSIFDSTADDR
: /* struct ifreq */
2628 case SIOCSIFADDR
: /* struct ifreq */
2629 case SIOCSIFBRDADDR
: /* struct ifreq */
2630 case SIOCSIFNETMASK
: /* struct ifreq */
2631 case OSIOCGIFADDR
: /* struct ifreq */
2632 case OSIOCGIFDSTADDR
: /* struct ifreq */
2633 case OSIOCGIFBRDADDR
: /* struct ifreq */
2634 case OSIOCGIFNETMASK
: /* struct ifreq */
2635 case SIOCSIFKPI
: /* struct ifreq */
2636 if (so
->so_proto
== NULL
) {
2641 case SIOCIFCREATE
: /* struct ifreq */
2642 case SIOCIFCREATE2
: /* struct ifreq */
2643 case SIOCIFDESTROY
: /* struct ifreq */
2644 case SIOCGIFFLAGS
: /* struct ifreq */
2645 case SIOCGIFEFLAGS
: /* struct ifreq */
2646 case SIOCGIFCAP
: /* struct ifreq */
2648 case SIOCGIFMAC
: /* struct ifreq */
2649 case SIOCSIFMAC
: /* struct ifreq */
2650 #endif /* CONFIG_MACF_NET */
2651 case SIOCGIFMETRIC
: /* struct ifreq */
2652 case SIOCGIFMTU
: /* struct ifreq */
2653 case SIOCGIFPHYS
: /* struct ifreq */
2654 case SIOCSIFFLAGS
: /* struct ifreq */
2655 case SIOCSIFCAP
: /* struct ifreq */
2656 case SIOCSIFMETRIC
: /* struct ifreq */
2657 case SIOCSIFPHYS
: /* struct ifreq */
2658 case SIOCSIFMTU
: /* struct ifreq */
2659 case SIOCADDMULTI
: /* struct ifreq */
2660 case SIOCDELMULTI
: /* struct ifreq */
2661 case SIOCDIFPHYADDR
: /* struct ifreq */
2662 case SIOCSIFMEDIA
: /* struct ifreq */
2663 case SIOCSIFGENERIC
: /* struct ifreq */
2664 case SIOCSIFLLADDR
: /* struct ifreq */
2665 case SIOCSIFALTMTU
: /* struct ifreq */
2666 case SIOCSIFVLAN
: /* struct ifreq */
2667 case SIOCSIFBOND
: /* struct ifreq */
2668 case SIOCGIFLLADDR
: /* struct ifreq */
2669 case SIOCGIFTYPE
: /* struct ifreq */
2670 case SIOCGIFFUNCTIONALTYPE
: /* struct ifreq */
2671 case SIOCGIFPSRCADDR
: /* struct ifreq */
2672 case SIOCGIFPDSTADDR
: /* struct ifreq */
2673 case SIOCGIFGENERIC
: /* struct ifreq */
2674 case SIOCGIFDEVMTU
: /* struct ifreq */
2675 case SIOCGIFVLAN
: /* struct ifreq */
2676 case SIOCGIFBOND
: /* struct ifreq */
2677 case SIOCGIFWAKEFLAGS
: /* struct ifreq */
2678 case SIOCGIFGETRTREFCNT
: /* struct ifreq */
2679 case SIOCSIFOPPORTUNISTIC
: /* struct ifreq */
2680 case SIOCGIFOPPORTUNISTIC
: /* struct ifreq */
2681 case SIOCGIFLINKQUALITYMETRIC
: /* struct ifreq */
2682 case SIOCSIFLOG
: /* struct ifreq */
2683 case SIOCGIFLOG
: /* struct ifreq */
2684 case SIOCGIFDELEGATE
: /* struct ifreq */
2685 case SIOCGIFEXPENSIVE
: /* struct ifreq */
2686 case SIOCSIFEXPENSIVE
: /* struct ifreq */
2687 case SIOCSIF2KCL
: /* struct ifreq */
2688 case SIOCGIF2KCL
: /* struct ifreq */
2689 case SIOCSIFINTERFACESTATE
: /* struct ifreq */
2690 case SIOCGIFINTERFACESTATE
: /* struct ifreq */
2691 case SIOCSIFPROBECONNECTIVITY
: /* struct ifreq */
2692 case SIOCGIFPROBECONNECTIVITY
: /* struct ifreq */
2693 case SIOCGSTARTDELAY
: /* struct ifreq */
2694 case SIOCSIFTIMESTAMPENABLE
: /* struct ifreq */
2695 case SIOCSIFTIMESTAMPDISABLE
: /* struct ifreq */
2696 case SIOCGIFTIMESTAMPENABLED
: /* struct ifreq */
2697 #if (DEBUG || DEVELOPMENT)
2698 case SIOCSIFDISABLEOUTPUT
: /* struct ifreq */
2699 #endif /* (DEBUG || DEVELOPMENT) */
2700 case SIOCGECNMODE
: /* struct ifreq */
2702 case SIOCSQOSMARKINGMODE
: /* struct ifreq */
2703 case SIOCSQOSMARKINGENABLED
: /* struct ifreq */
2704 case SIOCGQOSMARKINGMODE
: /* struct ifreq */
2705 case SIOCGQOSMARKINGENABLED
: /* struct ifreq */
2706 case SIOCSIFLOWINTERNET
: /* struct ifreq */
2707 case SIOCGIFLOWINTERNET
: /* struct ifreq */
2708 case SIOCGIFLOWPOWER
: /* struct ifreq */
2709 case SIOCSIFLOWPOWER
: /* struct ifreq */
2710 { /* struct ifreq */
2712 bcopy(data
, &ifr
, sizeof (ifr
));
2713 ifr
.ifr_name
[IFNAMSIZ
- 1] = '\0';
2714 bcopy(&ifr
.ifr_name
, ifname
, IFNAMSIZ
);
2715 if (ifioctl_restrict_intcoproc(cmd
, ifname
, NULL
, p
) == true) {
2719 error
= ifioctl_ifreq(so
, cmd
, &ifr
, p
);
2720 bcopy(&ifr
, data
, sizeof (ifr
));
2726 * ioctls which require ifp. Note that we acquire dlil_ifnet_lock
2727 * here to ensure that the ifnet, if found, has been fully attached.
2731 case SIOCSIFPHYADDR
: /* struct {if,in_}aliasreq */
2732 bcopy(((struct in_aliasreq
*)(void *)data
)->ifra_name
,
2734 ifp
= ifunit(ifname
);
2738 case SIOCSIFPHYADDR_IN6_32
: /* struct in6_aliasreq_32 */
2739 bcopy(((struct in6_aliasreq_32
*)(void *)data
)->ifra_name
,
2741 ifp
= ifunit(ifname
);
2744 case SIOCSIFPHYADDR_IN6_64
: /* struct in6_aliasreq_64 */
2745 bcopy(((struct in6_aliasreq_64
*)(void *)data
)->ifra_name
,
2747 ifp
= ifunit(ifname
);
2751 case SIOCGIFSTATUS
: /* struct ifstat */
2752 ifs
= _MALLOC(sizeof (*ifs
), M_DEVBUF
, M_WAITOK
);
2758 bcopy(data
, ifs
, sizeof (*ifs
));
2759 ifs
->ifs_name
[IFNAMSIZ
- 1] = '\0';
2760 bcopy(ifs
->ifs_name
, ifname
, IFNAMSIZ
);
2761 ifp
= ifunit(ifname
);
2764 case SIOCGIFMEDIA32
: /* struct ifmediareq32 */
2765 bcopy(((struct ifmediareq32
*)(void *)data
)->ifm_name
,
2767 ifp
= ifunit(ifname
);
2770 case SIOCGIFMEDIA64
: /* struct ifmediareq64 */
2771 bcopy(((struct ifmediareq64
*)(void *)data
)->ifm_name
,
2773 ifp
= ifunit(ifname
);
2776 case SIOCSIFDESC
: /* struct if_descreq */
2777 case SIOCGIFDESC
: /* struct if_descreq */
2778 bcopy(((struct if_descreq
*)(void *)data
)->ifdr_name
,
2780 ifp
= ifunit(ifname
);
2783 case SIOCSIFLINKPARAMS
: /* struct if_linkparamsreq */
2784 case SIOCGIFLINKPARAMS
: /* struct if_linkparamsreq */
2785 bcopy(((struct if_linkparamsreq
*)(void *)data
)->iflpr_name
,
2787 ifp
= ifunit(ifname
);
2790 case SIOCGIFQUEUESTATS
: /* struct if_qstatsreq */
2791 bcopy(((struct if_qstatsreq
*)(void *)data
)->ifqr_name
,
2793 ifp
= ifunit(ifname
);
2796 case SIOCSIFTHROTTLE
: /* struct if_throttlereq */
2797 case SIOCGIFTHROTTLE
: /* struct if_throttlereq */
2798 bcopy(((struct if_throttlereq
*)(void *)data
)->ifthr_name
,
2800 ifp
= ifunit(ifname
);
2803 case SIOCAIFAGENTID
: /* struct if_agentidreq */
2804 case SIOCDIFAGENTID
: /* struct if_agentidreq */
2805 case SIOCGIFAGENTIDS32
: /* struct if_agentidsreq32 */
2806 case SIOCGIFAGENTIDS64
: /* struct if_agentidsreq64 */
2807 bcopy(((struct if_agentidreq
*)(void *)data
)->ifar_name
,
2809 ifp
= ifunit(ifname
);
2812 case SIOCSIFNETSIGNATURE
: /* struct if_nsreq */
2813 case SIOCGIFNETSIGNATURE
: /* struct if_nsreq */
2814 bcopy(((struct if_nsreq
*)(void *)data
)->ifnsr_name
,
2816 ifp
= ifunit(ifname
);
2819 case SIOCGIFPROTOLIST32
: /* struct if_protolistreq32 */
2820 case SIOCGIFPROTOLIST64
: /* struct if_protolistreq64 */
2821 bcopy(((struct if_protolistreq
*)(void *)data
)->ifpl_name
,
2823 ifp
= ifunit(ifname
);
2827 * This is a bad assumption, but the code seems to
2828 * have been doing this in the past; caveat emptor.
2830 bcopy(((struct ifreq
*)(void *)data
)->ifr_name
,
2832 ifp
= ifunit(ifname
);
2842 if (ifioctl_restrict_intcoproc(cmd
, NULL
, ifp
, p
) == true) {
2847 case SIOCSIFPHYADDR
: /* struct {if,in_}aliasreq */
2849 case SIOCSIFPHYADDR_IN6_32
: /* struct in6_aliasreq_32 */
2850 case SIOCSIFPHYADDR_IN6_64
: /* struct in6_aliasreq_64 */
2852 error
= proc_suser(p
);
2856 error
= ifnet_ioctl(ifp
, SOCK_DOM(so
), cmd
, data
);
2860 ifnet_touch_lastchange(ifp
);
2863 case SIOCGIFSTATUS
: /* struct ifstat */
2864 VERIFY(ifs
!= NULL
);
2865 ifs
->ascii
[0] = '\0';
2867 error
= ifnet_ioctl(ifp
, SOCK_DOM(so
), cmd
, (caddr_t
)ifs
);
2869 bcopy(ifs
, data
, sizeof (*ifs
));
2872 case SIOCGIFMEDIA32
: /* struct ifmediareq32 */
2873 case SIOCGIFMEDIA64
: /* struct ifmediareq64 */
2874 error
= ifnet_ioctl(ifp
, SOCK_DOM(so
), cmd
, data
);
2877 case SIOCSIFDESC
: /* struct if_descreq */
2878 case SIOCGIFDESC
: /* struct if_descreq */
2879 error
= ifioctl_ifdesc(ifp
, cmd
, data
, p
);
2882 case SIOCSIFLINKPARAMS
: /* struct if_linkparamsreq */
2883 case SIOCGIFLINKPARAMS
: /* struct if_linkparamsreq */
2884 error
= ifioctl_linkparams(ifp
, cmd
, data
, p
);
2887 case SIOCGIFQUEUESTATS
: /* struct if_qstatsreq */
2888 error
= ifioctl_qstats(ifp
, cmd
, data
);
2891 case SIOCSIFTHROTTLE
: /* struct if_throttlereq */
2892 case SIOCGIFTHROTTLE
: /* struct if_throttlereq */
2893 error
= ifioctl_throttle(ifp
, cmd
, data
, p
);
2896 case SIOCAIFAGENTID
: /* struct if_agentidreq */
2897 case SIOCDIFAGENTID
: /* struct if_agentidreq */
2898 case SIOCGIFAGENTIDS32
: /* struct if_agentidsreq32 */
2899 case SIOCGIFAGENTIDS64
: /* struct if_agentidsreq64 */
2900 error
= ifioctl_netagent(ifp
, cmd
, data
, p
);
2903 case SIOCSIFNETSIGNATURE
: /* struct if_nsreq */
2904 case SIOCGIFNETSIGNATURE
: /* struct if_nsreq */
2905 error
= ifioctl_netsignature(ifp
, cmd
, data
);
2909 case SIOCSIFNAT64PREFIX
: /* struct if_nat64req */
2910 case SIOCGIFNAT64PREFIX
: /* struct if_nat64req */
2911 error
= ifioctl_nat64prefix(ifp
, cmd
, data
);
2914 case SIOCGIFCLAT46ADDR
: /* struct if_clat46req */
2915 error
= ifioctl_clat46addr(ifp
, cmd
, data
);
2919 case SIOCGIFPROTOLIST32
: /* struct if_protolistreq32 */
2920 case SIOCGIFPROTOLIST64
: /* struct if_protolistreq64 */
2921 error
= ifioctl_protolist(ifp
, cmd
, data
);
2925 if (so
->so_proto
== NULL
) {
2931 error
= ((*so
->so_proto
->pr_usrreqs
->pru_control
)(so
, cmd
,
2933 socket_unlock(so
, 1);
2935 if (error
== EOPNOTSUPP
|| error
== ENOTSUP
) {
2936 error
= ifnet_ioctl(ifp
, SOCK_DOM(so
), cmd
, data
);
2943 _FREE(ifs
, M_DEVBUF
);
2946 if (ifname
[0] == '\0')
2947 (void) snprintf(ifname
, sizeof (ifname
), "%s",
2949 else if (ifp
!= NULL
)
2950 (void) snprintf(ifname
, sizeof (ifname
), "%s",
2954 printf("%s[%s,%d]: ifp %s cmd 0x%08lx (%c%c [%lu] "
2955 "%c %lu) error %d\n", __func__
,
2956 proc_name_address(p
), proc_pid(p
),
2957 ifname
, cmd
, (cmd
& IOC_IN
) ? 'I' : ' ',
2958 (cmd
& IOC_OUT
) ? 'O' : ' ', IOCPARM_LEN(cmd
),
2959 (char)IOCGROUP(cmd
), cmd
& 0xff, error
);
2960 } else if (if_verbose
> 1) {
2961 printf("%s[%s,%d]: ifp %s cmd 0x%08lx (%c%c [%lu] "
2962 "%c %lu) OK\n", __func__
,
2963 proc_name_address(p
), proc_pid(p
),
2964 ifname
, cmd
, (cmd
& IOC_IN
) ? 'I' : ' ',
2965 (cmd
& IOC_OUT
) ? 'O' : ' ', IOCPARM_LEN(cmd
),
2966 (char)IOCGROUP(cmd
), cmd
& 0xff);
2973 static __attribute__((noinline
)) int
2974 ifioctl_ifreq(struct socket
*so
, u_long cmd
, struct ifreq
*ifr
, struct proc
*p
)
2979 struct kev_msg ev_msg
;
2980 struct net_event_data ev_data
;
2982 bzero(&ev_data
, sizeof (struct net_event_data
));
2983 bzero(&ev_msg
, sizeof (struct kev_msg
));
2988 error
= proc_suser(p
);
2991 return (if_clone_create(ifr
->ifr_name
, sizeof(ifr
->ifr_name
),
2992 cmd
== SIOCIFCREATE2
? ifr
->ifr_data
: NULL
));
2994 error
= proc_suser(p
);
2997 return (if_clone_destroy(ifr
->ifr_name
));
3001 * ioctls which require ifp. Note that we acquire dlil_ifnet_lock
3002 * here to ensure that the ifnet, if found, has been fully attached.
3005 ifp
= ifunit(ifr
->ifr_name
);
3013 ifnet_lock_shared(ifp
);
3014 ifr
->ifr_flags
= ifp
->if_flags
;
3015 ifnet_lock_done(ifp
);
3019 ifnet_lock_shared(ifp
);
3020 ifr
->ifr_eflags
= ifp
->if_eflags
;
3021 ifnet_lock_done(ifp
);
3025 ifnet_lock_shared(ifp
);
3026 ifr
->ifr_reqcap
= ifp
->if_capabilities
;
3027 ifr
->ifr_curcap
= ifp
->if_capenable
;
3028 ifnet_lock_done(ifp
);
3033 error
= mac_ifnet_label_get(kauth_cred_get(), ifr
, ifp
);
3037 error
= mac_ifnet_label_set(kauth_cred_get(), ifr
, ifp
);
3039 #endif /* CONFIG_MACF_NET */
3042 ifnet_lock_shared(ifp
);
3043 ifr
->ifr_metric
= ifp
->if_metric
;
3044 ifnet_lock_done(ifp
);
3048 ifnet_lock_shared(ifp
);
3049 ifr
->ifr_mtu
= ifp
->if_mtu
;
3050 ifnet_lock_done(ifp
);
3054 ifnet_lock_shared(ifp
);
3055 ifr
->ifr_phys
= ifp
->if_physical
;
3056 ifnet_lock_done(ifp
);
3060 error
= proc_suser(p
);
3064 (void) ifnet_set_flags(ifp
, ifr
->ifr_flags
,
3065 (u_int16_t
)~IFF_CANTCHANGE
);
3068 * Note that we intentionally ignore any error from below
3069 * for the SIOCSIFFLAGS case.
3071 (void) ifnet_ioctl(ifp
, SOCK_DOM(so
), cmd
, (caddr_t
)ifr
);
3074 * Send the event even upon error from the driver because
3075 * we changed the flags.
3077 dlil_post_sifflags_msg(ifp
);
3079 ifnet_touch_lastchange(ifp
);
3083 error
= proc_suser(p
);
3087 if ((ifr
->ifr_reqcap
& ~ifp
->if_capabilities
)) {
3091 error
= ifnet_ioctl(ifp
, SOCK_DOM(so
), cmd
, (caddr_t
)ifr
);
3093 ifnet_touch_lastchange(ifp
);
3097 error
= proc_suser(p
);
3101 ifp
->if_metric
= ifr
->ifr_metric
;
3103 ev_msg
.vendor_code
= KEV_VENDOR_APPLE
;
3104 ev_msg
.kev_class
= KEV_NETWORK_CLASS
;
3105 ev_msg
.kev_subclass
= KEV_DL_SUBCLASS
;
3107 ev_msg
.event_code
= KEV_DL_SIFMETRICS
;
3108 strlcpy(&ev_data
.if_name
[0], ifp
->if_name
, IFNAMSIZ
);
3109 ev_data
.if_family
= ifp
->if_family
;
3110 ev_data
.if_unit
= (u_int32_t
) ifp
->if_unit
;
3111 ev_msg
.dv
[0].data_length
= sizeof(struct net_event_data
);
3112 ev_msg
.dv
[0].data_ptr
= &ev_data
;
3114 ev_msg
.dv
[1].data_length
= 0;
3115 dlil_post_complete_msg(ifp
, &ev_msg
);
3117 ifnet_touch_lastchange(ifp
);
3121 error
= proc_suser(p
);
3125 error
= ifnet_ioctl(ifp
, SOCK_DOM(so
), cmd
, (caddr_t
)ifr
);
3129 ev_msg
.vendor_code
= KEV_VENDOR_APPLE
;
3130 ev_msg
.kev_class
= KEV_NETWORK_CLASS
;
3131 ev_msg
.kev_subclass
= KEV_DL_SUBCLASS
;
3133 ev_msg
.event_code
= KEV_DL_SIFPHYS
;
3134 strlcpy(&ev_data
.if_name
[0], ifp
->if_name
, IFNAMSIZ
);
3135 ev_data
.if_family
= ifp
->if_family
;
3136 ev_data
.if_unit
= (u_int32_t
) ifp
->if_unit
;
3137 ev_msg
.dv
[0].data_length
= sizeof(struct net_event_data
);
3138 ev_msg
.dv
[0].data_ptr
= &ev_data
;
3139 ev_msg
.dv
[1].data_length
= 0;
3140 dlil_post_complete_msg(ifp
, &ev_msg
);
3142 ifnet_touch_lastchange(ifp
);
3146 u_int32_t oldmtu
= ifp
->if_mtu
;
3147 struct ifclassq
*ifq
= &ifp
->if_snd
;
3149 error
= proc_suser(p
);
3153 if (ifp
->if_ioctl
== NULL
) {
3157 if (ifr
->ifr_mtu
< IF_MINMTU
|| ifr
->ifr_mtu
> IF_MAXMTU
) {
3161 error
= ifnet_ioctl(ifp
, SOCK_DOM(so
), cmd
, (caddr_t
)ifr
);
3165 ev_msg
.vendor_code
= KEV_VENDOR_APPLE
;
3166 ev_msg
.kev_class
= KEV_NETWORK_CLASS
;
3167 ev_msg
.kev_subclass
= KEV_DL_SUBCLASS
;
3169 ev_msg
.event_code
= KEV_DL_SIFMTU
;
3170 strlcpy(&ev_data
.if_name
[0], ifp
->if_name
, IFNAMSIZ
);
3171 ev_data
.if_family
= ifp
->if_family
;
3172 ev_data
.if_unit
= (u_int32_t
) ifp
->if_unit
;
3173 ev_msg
.dv
[0].data_length
= sizeof(struct net_event_data
);
3174 ev_msg
.dv
[0].data_ptr
= &ev_data
;
3175 ev_msg
.dv
[1].data_length
= 0;
3176 dlil_post_complete_msg(ifp
, &ev_msg
);
3178 ifnet_touch_lastchange(ifp
);
3182 * If the link MTU changed, do network layer specific procedure
3183 * and update all route entries associated with the interface,
3184 * so that their MTU metric gets updated.
3186 if (ifp
->if_mtu
!= oldmtu
) {
3187 if_rtmtu_update(ifp
);
3191 /* Inform all transmit queues about the new MTU */
3193 ifnet_update_sndq(ifq
, CLASSQ_EV_LINK_MTU
);
3201 error
= proc_suser(p
);
3205 /* Don't allow group membership on non-multicast interfaces. */
3206 if ((ifp
->if_flags
& IFF_MULTICAST
) == 0) {
3211 /* Don't let users screw up protocols' entries. */
3212 if (ifr
->ifr_addr
.sa_family
!= AF_UNSPEC
&&
3213 ifr
->ifr_addr
.sa_family
!= AF_LINK
) {
3219 * User is permitted to anonymously join a particular link
3220 * multicast group via SIOCADDMULTI. Subsequent join requested
3221 * for the same record which has an outstanding refcnt from a
3222 * past if_addmulti_anon() will not result in EADDRINUSE error
3223 * (unlike other BSDs.) Anonymously leaving a group is also
3224 * allowed only as long as there is an outstanding refcnt held
3225 * by a previous anonymous request, or else ENOENT (even if the
3226 * link-layer multicast membership exists for a network-layer
3229 if (cmd
== SIOCADDMULTI
) {
3230 error
= if_addmulti_anon(ifp
, &ifr
->ifr_addr
, NULL
);
3231 ev_msg
.event_code
= KEV_DL_ADDMULTI
;
3233 error
= if_delmulti_anon(ifp
, &ifr
->ifr_addr
);
3234 ev_msg
.event_code
= KEV_DL_DELMULTI
;
3239 ev_msg
.vendor_code
= KEV_VENDOR_APPLE
;
3240 ev_msg
.kev_class
= KEV_NETWORK_CLASS
;
3241 ev_msg
.kev_subclass
= KEV_DL_SUBCLASS
;
3242 strlcpy(&ev_data
.if_name
[0], ifp
->if_name
, IFNAMSIZ
);
3244 ev_data
.if_family
= ifp
->if_family
;
3245 ev_data
.if_unit
= (u_int32_t
) ifp
->if_unit
;
3246 ev_msg
.dv
[0].data_length
= sizeof(struct net_event_data
);
3247 ev_msg
.dv
[0].data_ptr
= &ev_data
;
3248 ev_msg
.dv
[1].data_length
= 0;
3249 dlil_post_complete_msg(ifp
, &ev_msg
);
3251 ifnet_touch_lastchange(ifp
);
3254 case SIOCDIFPHYADDR
:
3256 case SIOCSIFGENERIC
:
3261 error
= proc_suser(p
);
3265 error
= ifnet_ioctl(ifp
, SOCK_DOM(so
), cmd
, (caddr_t
)ifr
);
3269 ifnet_touch_lastchange(ifp
);
3272 case SIOCGIFLLADDR
: {
3273 struct sockaddr_dl
*sdl
= SDL(ifp
->if_lladdr
->ifa_addr
);
3275 if (sdl
->sdl_alen
== 0) {
3276 error
= EADDRNOTAVAIL
;
3279 /* If larger than 14-bytes we'll need another mechanism */
3280 if (sdl
->sdl_alen
> sizeof (ifr
->ifr_addr
.sa_data
)) {
3284 /* Follow the same convention used by SIOCSIFLLADDR */
3285 bzero(&ifr
->ifr_addr
, sizeof (ifr
->ifr_addr
));
3286 ifr
->ifr_addr
.sa_family
= AF_LINK
;
3287 ifr
->ifr_addr
.sa_len
= sdl
->sdl_alen
;
3288 error
= ifnet_guarded_lladdr_copy_bytes(ifp
,
3289 &ifr
->ifr_addr
.sa_data
, sdl
->sdl_alen
);
3294 ifr
->ifr_type
.ift_type
= ifp
->if_type
;
3295 ifr
->ifr_type
.ift_family
= ifp
->if_family
;
3296 ifr
->ifr_type
.ift_subfamily
= ifp
->if_subfamily
;
3299 case SIOCGIFFUNCTIONALTYPE
:
3300 ifr
->ifr_functional_type
= if_functional_type(ifp
, FALSE
);
3303 case SIOCGIFPSRCADDR
:
3304 case SIOCGIFPDSTADDR
:
3305 case SIOCGIFGENERIC
:
3309 error
= ifnet_ioctl(ifp
, SOCK_DOM(so
), cmd
, (caddr_t
)ifr
);
3312 case SIOCGIFWAKEFLAGS
:
3313 ifnet_lock_shared(ifp
);
3314 ifr
->ifr_wake_flags
= ifnet_get_wake_flags(ifp
);
3315 ifnet_lock_done(ifp
);
3318 case SIOCGIFGETRTREFCNT
:
3319 ifnet_lock_shared(ifp
);
3320 ifr
->ifr_route_refcnt
= ifp
->if_route_refcnt
;
3321 ifnet_lock_done(ifp
);
3324 case SIOCSIFOPPORTUNISTIC
:
3325 case SIOCGIFOPPORTUNISTIC
:
3326 error
= ifnet_getset_opportunistic(ifp
, cmd
, ifr
, p
);
3329 case SIOCGIFLINKQUALITYMETRIC
:
3330 ifnet_lock_shared(ifp
);
3331 if ((ifp
->if_interface_state
.valid_bitmask
&
3332 IF_INTERFACE_STATE_LQM_STATE_VALID
)) {
3333 ifr
->ifr_link_quality_metric
=
3334 ifp
->if_interface_state
.lqm_state
;
3335 } else if (IF_FULLY_ATTACHED(ifp
)) {
3336 ifr
->ifr_link_quality_metric
=
3337 IFNET_LQM_THRESH_UNKNOWN
;
3339 ifr
->ifr_link_quality_metric
=
3340 IFNET_LQM_THRESH_OFF
;
3342 ifnet_lock_done(ifp
);
3347 error
= ifnet_getset_log(ifp
, cmd
, ifr
, p
);
3350 case SIOCGIFDELEGATE
:
3351 ifnet_lock_shared(ifp
);
3352 ifr
->ifr_delegated
= ((ifp
->if_delegated
.ifp
!= NULL
) ?
3353 ifp
->if_delegated
.ifp
->if_index
: 0);
3354 ifnet_lock_done(ifp
);
3357 case SIOCGIFEXPENSIVE
:
3358 ifnet_lock_shared(ifp
);
3359 if (ifp
->if_eflags
& IFEF_EXPENSIVE
)
3360 ifr
->ifr_expensive
= 1;
3362 ifr
->ifr_expensive
= 0;
3363 ifnet_lock_done(ifp
);
3366 case SIOCSIFEXPENSIVE
:
3370 if ((error
= priv_check_cred(kauth_cred_get(),
3371 PRIV_NET_INTERFACE_CONTROL
, 0)) != 0)
3373 ifnet_lock_exclusive(ifp
);
3374 if (ifr
->ifr_expensive
)
3375 ifp
->if_eflags
|= IFEF_EXPENSIVE
;
3377 ifp
->if_eflags
&= ~IFEF_EXPENSIVE
;
3378 ifnet_lock_done(ifp
);
3380 * Update the expensive bit in the delegated interface
3383 ifnet_head_lock_shared();
3384 TAILQ_FOREACH(difp
, &ifnet_head
, if_link
) {
3385 ifnet_lock_exclusive(difp
);
3386 if (difp
->if_delegated
.ifp
== ifp
) {
3387 difp
->if_delegated
.expensive
=
3388 ifp
->if_eflags
& IFEF_EXPENSIVE
? 1 : 0;
3391 ifnet_lock_done(difp
);
3398 ifnet_lock_shared(ifp
);
3399 if (ifp
->if_eflags
& IFEF_2KCL
)
3403 ifnet_lock_done(ifp
);
3407 if ((error
= priv_check_cred(kauth_cred_get(),
3408 PRIV_NET_INTERFACE_CONTROL
, 0)) != 0)
3410 ifnet_lock_exclusive(ifp
);
3412 ifp
->if_eflags
|= IFEF_2KCL
;
3414 ifp
->if_eflags
&= ~IFEF_2KCL
;
3415 ifnet_lock_done(ifp
);
3417 case SIOCGSTARTDELAY
:
3418 ifnet_lock_shared(ifp
);
3419 if (ifp
->if_eflags
& IFEF_ENQUEUE_MULTI
) {
3420 ifr
->ifr_start_delay_qlen
=
3421 ifp
->if_start_delay_qlen
;
3422 ifr
->ifr_start_delay_timeout
=
3423 ifp
->if_start_delay_timeout
;
3425 ifr
->ifr_start_delay_qlen
= 0;
3426 ifr
->ifr_start_delay_timeout
= 0;
3428 ifnet_lock_done(ifp
);
3430 case SIOCSIFDSTADDR
:
3432 case SIOCSIFBRDADDR
:
3433 case SIOCSIFNETMASK
:
3435 case OSIOCGIFDSTADDR
:
3436 case OSIOCGIFBRDADDR
:
3437 case OSIOCGIFNETMASK
:
3439 VERIFY(so
->so_proto
!= NULL
);
3441 if (cmd
== SIOCSIFDSTADDR
|| cmd
== SIOCSIFADDR
||
3442 cmd
== SIOCSIFBRDADDR
|| cmd
== SIOCSIFNETMASK
) {
3443 #if BYTE_ORDER != BIG_ENDIAN
3444 if (ifr
->ifr_addr
.sa_family
== 0 &&
3445 ifr
->ifr_addr
.sa_len
< 16) {
3446 ifr
->ifr_addr
.sa_family
= ifr
->ifr_addr
.sa_len
;
3447 ifr
->ifr_addr
.sa_len
= 16;
3450 if (ifr
->ifr_addr
.sa_len
== 0)
3451 ifr
->ifr_addr
.sa_len
= 16;
3453 } else if (cmd
== OSIOCGIFADDR
) {
3454 cmd
= SIOCGIFADDR
; /* struct ifreq */
3455 } else if (cmd
== OSIOCGIFDSTADDR
) {
3456 cmd
= SIOCGIFDSTADDR
; /* struct ifreq */
3457 } else if (cmd
== OSIOCGIFBRDADDR
) {
3458 cmd
= SIOCGIFBRDADDR
; /* struct ifreq */
3459 } else if (cmd
== OSIOCGIFNETMASK
) {
3460 cmd
= SIOCGIFNETMASK
; /* struct ifreq */
3464 error
= ((*so
->so_proto
->pr_usrreqs
->pru_control
)(so
, cmd
,
3465 (caddr_t
)ifr
, ifp
, p
));
3466 socket_unlock(so
, 1);
3470 case OSIOCGIFDSTADDR
:
3471 case OSIOCGIFBRDADDR
:
3472 case OSIOCGIFNETMASK
:
3473 bcopy(&ifr
->ifr_addr
.sa_family
, &ifr
->ifr_addr
,
3477 if (cmd
== SIOCSIFKPI
) {
3478 int temperr
= proc_suser(p
);
3483 if (error
== EOPNOTSUPP
|| error
== ENOTSUP
) {
3484 error
= ifnet_ioctl(ifp
, SOCK_DOM(so
), cmd
,
3489 case SIOCGIFINTERFACESTATE
:
3490 if_get_state(ifp
, &ifr
->ifr_interface_state
);
3493 case SIOCSIFINTERFACESTATE
:
3494 if ((error
= priv_check_cred(kauth_cred_get(),
3495 PRIV_NET_INTERFACE_CONTROL
, 0)) != 0)
3498 error
= if_state_update(ifp
, &ifr
->ifr_interface_state
);
3501 case SIOCSIFPROBECONNECTIVITY
:
3502 if ((error
= priv_check_cred(kauth_cred_get(),
3503 PRIV_NET_INTERFACE_CONTROL
, 0)) != 0)
3505 error
= if_probe_connectivity(ifp
,
3506 ifr
->ifr_probe_connectivity
);
3508 case SIOCGIFPROBECONNECTIVITY
:
3509 if ((error
= priv_check_cred(kauth_cred_get(),
3510 PRIV_NET_INTERFACE_CONTROL
, 0)) != 0)
3512 if (ifp
->if_eflags
& IFEF_PROBE_CONNECTIVITY
)
3513 ifr
->ifr_probe_connectivity
= 1;
3515 ifr
->ifr_probe_connectivity
= 0;
3518 if ((ifp
->if_eflags
& (IFEF_ECN_ENABLE
|IFEF_ECN_DISABLE
)) ==
3520 ifr
->ifr_ecn_mode
= IFRTYPE_ECN_ENABLE
;
3521 else if ((ifp
->if_eflags
& (IFEF_ECN_ENABLE
|IFEF_ECN_DISABLE
)) ==
3523 ifr
->ifr_ecn_mode
= IFRTYPE_ECN_DISABLE
;
3525 ifr
->ifr_ecn_mode
= IFRTYPE_ECN_DEFAULT
;
3528 if ((error
= priv_check_cred(kauth_cred_get(),
3529 PRIV_NET_INTERFACE_CONTROL
, 0)) != 0)
3531 if (ifr
->ifr_ecn_mode
== IFRTYPE_ECN_DEFAULT
) {
3532 ifp
->if_eflags
&= ~(IFEF_ECN_ENABLE
|IFEF_ECN_DISABLE
);
3533 } else if (ifr
->ifr_ecn_mode
== IFRTYPE_ECN_ENABLE
) {
3534 ifp
->if_eflags
|= IFEF_ECN_ENABLE
;
3535 ifp
->if_eflags
&= ~IFEF_ECN_DISABLE
;
3536 } else if (ifr
->ifr_ecn_mode
== IFRTYPE_ECN_DISABLE
) {
3537 ifp
->if_eflags
|= IFEF_ECN_DISABLE
;
3538 ifp
->if_eflags
&= ~IFEF_ECN_ENABLE
;
3542 case SIOCSIFTIMESTAMPENABLE
:
3543 case SIOCSIFTIMESTAMPDISABLE
:
3544 error
= proc_suser(p
);
3548 ifnet_lock_exclusive(ifp
);
3549 if ((cmd
== SIOCSIFTIMESTAMPENABLE
&&
3550 (ifp
->if_xflags
& IFXF_TIMESTAMP_ENABLED
) != 0) ||
3551 (cmd
== SIOCSIFTIMESTAMPDISABLE
&&
3552 (ifp
->if_xflags
& IFXF_TIMESTAMP_ENABLED
) == 0)) {
3553 ifnet_lock_done(ifp
);
3556 if (cmd
== SIOCSIFTIMESTAMPENABLE
)
3557 ifp
->if_xflags
|= IFXF_TIMESTAMP_ENABLED
;
3559 ifp
->if_xflags
&= ~IFXF_TIMESTAMP_ENABLED
;
3560 ifnet_lock_done(ifp
);
3562 * Pass the setting to the interface if it supports either
3563 * software or hardware time stamping
3565 if (ifp
->if_capabilities
& (IFCAP_HW_TIMESTAMP
|
3566 IFCAP_SW_TIMESTAMP
)) {
3567 error
= ifnet_ioctl(ifp
, SOCK_DOM(so
), cmd
,
3571 case SIOCGIFTIMESTAMPENABLED
: {
3572 if ((ifp
->if_xflags
& IFXF_TIMESTAMP_ENABLED
) != 0)
3573 ifr
->ifr_intval
= 1;
3575 ifr
->ifr_intval
= 0;
3578 case SIOCSQOSMARKINGMODE
:
3579 if ((error
= priv_check_cred(kauth_cred_get(),
3580 PRIV_NET_INTERFACE_CONTROL
, 0)) != 0)
3582 error
= if_set_qosmarking_mode(ifp
, ifr
->ifr_qosmarking_mode
);
3585 case SIOCGQOSMARKINGMODE
:
3586 ifr
->ifr_qosmarking_mode
= ifp
->if_qosmarking_mode
;
3589 case SIOCSQOSMARKINGENABLED
:
3590 if ((error
= priv_check_cred(kauth_cred_get(),
3591 PRIV_NET_INTERFACE_CONTROL
, 0)) != 0)
3593 if (ifr
->ifr_qosmarking_enabled
!= 0)
3594 ifp
->if_eflags
|= IFEF_QOSMARKING_ENABLED
;
3596 ifp
->if_eflags
&= ~IFEF_QOSMARKING_ENABLED
;
3599 case SIOCGQOSMARKINGENABLED
:
3600 ifr
->ifr_qosmarking_enabled
=
3601 (ifp
->if_eflags
& IFEF_QOSMARKING_ENABLED
) ? 1 : 0;
3604 case SIOCSIFDISABLEOUTPUT
:
3605 #if (DEBUG || DEVELOPMENT)
3606 if (ifr
->ifr_disable_output
== 1) {
3607 error
= ifnet_disable_output(ifp
);
3608 } else if (ifr
->ifr_disable_output
== 0) {
3609 error
= ifnet_enable_output(ifp
);
3615 #endif /* (DEBUG || DEVELOPMENT) */
3617 case SIOCSIFLOWINTERNET
:
3618 if ((error
= priv_check_cred(kauth_cred_get(),
3619 PRIV_NET_INTERFACE_CONTROL
, 0)) != 0)
3622 ifnet_lock_exclusive(ifp
);
3623 if (ifr
->ifr_low_internet
& IFRTYPE_LOW_INTERNET_ENABLE_UL
)
3624 ifp
->if_xflags
|= IFXF_LOW_INTERNET_UL
;
3626 ifp
->if_xflags
&= ~(IFXF_LOW_INTERNET_UL
);
3627 if (ifr
->ifr_low_internet
& IFRTYPE_LOW_INTERNET_ENABLE_DL
)
3628 ifp
->if_xflags
|= IFXF_LOW_INTERNET_DL
;
3630 ifp
->if_xflags
&= ~(IFXF_LOW_INTERNET_DL
);
3631 ifnet_lock_done(ifp
);
3633 case SIOCGIFLOWINTERNET
:
3634 ifnet_lock_shared(ifp
);
3635 ifr
->ifr_low_internet
= 0;
3636 if (ifp
->if_xflags
& IFXF_LOW_INTERNET_UL
)
3637 ifr
->ifr_low_internet
|=
3638 IFRTYPE_LOW_INTERNET_ENABLE_UL
;
3639 if (ifp
->if_xflags
& IFXF_LOW_INTERNET_DL
)
3640 ifr
->ifr_low_internet
|=
3641 IFRTYPE_LOW_INTERNET_ENABLE_DL
;
3642 ifnet_lock_done(ifp
);
3644 case SIOCGIFLOWPOWER
:
3645 ifr
->ifr_low_power_mode
=
3646 !!(ifp
->if_xflags
& IFXF_LOW_POWER
);
3648 case SIOCSIFLOWPOWER
:
3649 #if (DEVELOPMENT || DEBUG)
3650 error
= if_set_low_power(ifp
, !!(ifr
->ifr_low_power_mode
));
3651 #else /* DEVELOPMENT || DEBUG */
3653 #endif /* DEVELOPMENT || DEBUG */
3664 ifioctllocked(struct socket
*so
, u_long cmd
, caddr_t data
, struct proc
*p
)
3668 socket_unlock(so
, 0);
3669 error
= ifioctl(so
, cmd
, data
, p
);
3675 * Set/clear promiscuous mode on interface ifp based on the truth value
3676 * of pswitch. The calls are reference counted so that only the first
3677 * "on" request actually has an effect, as does the final "off" request.
3678 * Results are undefined if the "off" and "on" requests are not matched.
3681 ifnet_set_promiscuous(
3689 ifnet_lock_exclusive(ifp
);
3690 oldflags
= ifp
->if_flags
;
3691 ifp
->if_pcount
+= pswitch
? 1 : -1;
3693 if (ifp
->if_pcount
> 0)
3694 ifp
->if_flags
|= IFF_PROMISC
;
3696 ifp
->if_flags
&= ~IFF_PROMISC
;
3698 newflags
= ifp
->if_flags
;
3699 ifnet_lock_done(ifp
);
3701 if (newflags
!= oldflags
&& (newflags
& IFF_UP
) != 0) {
3702 error
= ifnet_ioctl(ifp
, 0, SIOCSIFFLAGS
, NULL
);
3706 ifnet_lock_exclusive(ifp
);
3708 ifp
->if_pcount
-= pswitch
? 1 : -1;
3709 if (ifp
->if_pcount
> 0)
3710 ifp
->if_flags
|= IFF_PROMISC
;
3712 ifp
->if_flags
&= ~IFF_PROMISC
;
3713 ifnet_lock_done(ifp
);
3717 if (newflags
!= oldflags
) {
3718 log(LOG_INFO
, "%s: promiscuous mode %s%s\n",
3720 (newflags
& IFF_PROMISC
) != 0 ? "enable" : "disable",
3721 error
!= 0 ? " failed" : " succeeded");
3727 * Return interface configuration
3728 * of system. List may be used
3729 * in later ioctl's (above) to get
3730 * other information.
3734 ifconf(u_long cmd
, user_addr_t ifrp
, int *ret_space
)
3736 struct ifnet
*ifp
= NULL
;
3741 net_thread_marks_t marks
;
3743 marks
= net_thread_marks_push(NET_THREAD_CKREQ_LLADDR
);
3746 * Zero the ifr buffer to make sure we don't
3747 * disclose the contents of the stack.
3749 bzero(&ifr
, sizeof (struct ifreq
));
3752 ifnet_head_lock_shared();
3753 for (ifp
= ifnet_head
.tqh_first
; space
> sizeof (ifr
) &&
3754 ifp
; ifp
= ifp
->if_link
.tqe_next
) {
3756 size_t ifnlen
, addrs
;
3758 ifnlen
= snprintf(workbuf
, sizeof (workbuf
),
3759 "%s", if_name(ifp
));
3760 if (ifnlen
+ 1 > sizeof (ifr
.ifr_name
)) {
3761 error
= ENAMETOOLONG
;
3764 strlcpy(ifr
.ifr_name
, workbuf
, IFNAMSIZ
);
3767 ifnet_lock_shared(ifp
);
3770 ifa
= ifp
->if_addrhead
.tqh_first
;
3771 for (; space
> sizeof (ifr
) && ifa
;
3772 ifa
= ifa
->ifa_link
.tqe_next
) {
3773 struct sockaddr
*sa
;
3776 struct sockaddr_dl sdl
;
3777 uint8_t buf
[SOCK_MAXADDRLEN
+ 1];
3781 * Make sure to accomodate the largest possible
3782 * size of SA(if_lladdr)->sa_len.
3784 _CASSERT(sizeof (u
) == (SOCK_MAXADDRLEN
+ 1));
3790 if (ifa
== ifp
->if_lladdr
) {
3791 VERIFY(sa
->sa_family
== AF_LINK
);
3792 bcopy(sa
, &u
, sa
->sa_len
);
3794 ifnet_guarded_lladdr_copy_bytes(ifp
,
3795 LLADDR(&u
.sdl
), u
.sdl
.sdl_alen
);
3800 if (cmd
== OSIOCGIFCONF32
|| cmd
== OSIOCGIFCONF64
) {
3801 struct osockaddr
*osa
=
3802 (struct osockaddr
*)(void *)&ifr
.ifr_addr
;
3804 osa
->sa_family
= sa
->sa_family
;
3805 error
= copyout((caddr_t
)&ifr
, ifrp
,
3807 ifrp
+= sizeof (struct ifreq
);
3808 } else if (sa
->sa_len
<= sizeof (*sa
)) {
3810 error
= copyout((caddr_t
)&ifr
, ifrp
,
3812 ifrp
+= sizeof (struct ifreq
);
3815 sizeof (ifr
) + sa
->sa_len
- sizeof (*sa
)) {
3819 space
-= sa
->sa_len
- sizeof (*sa
);
3820 error
= copyout((caddr_t
)&ifr
, ifrp
,
3821 sizeof (ifr
.ifr_name
));
3823 error
= copyout((caddr_t
)sa
, (ifrp
+
3824 offsetof(struct ifreq
, ifr_addr
)),
3827 ifrp
+= (sa
->sa_len
+ offsetof(struct ifreq
,
3833 space
-= sizeof (ifr
);
3835 ifnet_lock_done(ifp
);
3840 bzero((caddr_t
)&ifr
.ifr_addr
, sizeof (ifr
.ifr_addr
));
3841 error
= copyout((caddr_t
)&ifr
, ifrp
, sizeof (ifr
));
3844 space
-= sizeof (ifr
);
3845 ifrp
+= sizeof (struct ifreq
);
3849 *ret_space
-= space
;
3850 net_thread_marks_pop(marks
);
3855 * Just like if_promisc(), but for all-multicast-reception mode.
3858 if_allmulti(struct ifnet
*ifp
, int onswitch
)
3863 ifnet_lock_exclusive(ifp
);
3866 if (ifp
->if_amcount
++ == 0) {
3867 ifp
->if_flags
|= IFF_ALLMULTI
;
3871 if (ifp
->if_amcount
> 1) {
3874 ifp
->if_amcount
= 0;
3875 ifp
->if_flags
&= ~IFF_ALLMULTI
;
3879 ifnet_lock_done(ifp
);
3882 error
= ifnet_ioctl(ifp
, 0, SIOCSIFFLAGS
, NULL
);
3889 static struct ifmultiaddr
*
3892 struct ifmultiaddr
*ifma
;
3894 ifma
= (how
== M_WAITOK
) ? zalloc(ifma_zone
) :
3895 zalloc_noblock(ifma_zone
);
3898 bzero(ifma
, ifma_size
);
3899 lck_mtx_init(&ifma
->ifma_lock
, ifa_mtx_grp
, ifa_mtx_attr
);
3900 ifma
->ifma_debug
|= IFD_ALLOC
;
3901 if (ifma_debug
!= 0) {
3902 ifma
->ifma_debug
|= IFD_DEBUG
;
3903 ifma
->ifma_trace
= ifma_trace
;
3910 ifma_free(struct ifmultiaddr
*ifma
)
3914 if (ifma
->ifma_protospec
!= NULL
) {
3915 panic("%s: Protospec not NULL for ifma=%p", __func__
, ifma
);
3917 } else if ((ifma
->ifma_flags
& IFMAF_ANONYMOUS
) ||
3918 ifma
->ifma_anoncnt
!= 0) {
3919 panic("%s: Freeing ifma=%p with outstanding anon req",
3922 } else if (ifma
->ifma_debug
& IFD_ATTACHED
) {
3923 panic("%s: ifma=%p attached to ifma_ifp=%p is being freed",
3924 __func__
, ifma
, ifma
->ifma_ifp
);
3926 } else if (!(ifma
->ifma_debug
& IFD_ALLOC
)) {
3927 panic("%s: ifma %p cannot be freed", __func__
, ifma
);
3929 } else if (ifma
->ifma_refcount
!= 0) {
3930 panic("%s: non-zero refcount ifma=%p", __func__
, ifma
);
3932 } else if (ifma
->ifma_reqcnt
!= 0) {
3933 panic("%s: non-zero reqcnt ifma=%p", __func__
, ifma
);
3935 } else if (ifma
->ifma_ifp
!= NULL
) {
3936 panic("%s: non-NULL ifma_ifp=%p for ifma=%p", __func__
,
3937 ifma
->ifma_ifp
, ifma
);
3939 } else if (ifma
->ifma_ll
!= NULL
) {
3940 panic("%s: non-NULL ifma_ll=%p for ifma=%p", __func__
,
3941 ifma
->ifma_ll
, ifma
);
3944 ifma
->ifma_debug
&= ~IFD_ALLOC
;
3945 if ((ifma
->ifma_debug
& (IFD_DEBUG
| IFD_TRASHED
)) ==
3946 (IFD_DEBUG
| IFD_TRASHED
)) {
3947 lck_mtx_lock(&ifma_trash_lock
);
3948 TAILQ_REMOVE(&ifma_trash_head
, (struct ifmultiaddr_dbg
*)ifma
,
3950 lck_mtx_unlock(&ifma_trash_lock
);
3951 ifma
->ifma_debug
&= ~IFD_TRASHED
;
3955 if (ifma
->ifma_addr
!= NULL
) {
3956 FREE(ifma
->ifma_addr
, M_IFADDR
);
3957 ifma
->ifma_addr
= NULL
;
3959 lck_mtx_destroy(&ifma
->ifma_lock
, ifa_mtx_grp
);
3960 zfree(ifma_zone
, ifma
);
3964 ifma_trace(struct ifmultiaddr
*ifma
, int refhold
)
3966 struct ifmultiaddr_dbg
*ifma_dbg
= (struct ifmultiaddr_dbg
*)ifma
;
3971 if (!(ifma
->ifma_debug
& IFD_DEBUG
)) {
3972 panic("%s: ifma %p has no debug structure", __func__
, ifma
);
3976 cnt
= &ifma_dbg
->ifma_refhold_cnt
;
3977 tr
= ifma_dbg
->ifma_refhold
;
3979 cnt
= &ifma_dbg
->ifma_refrele_cnt
;
3980 tr
= ifma_dbg
->ifma_refrele
;
3983 idx
= atomic_add_16_ov(cnt
, 1) % IFMA_TRACE_HIST_SIZE
;
3984 ctrace_record(&tr
[idx
]);
3988 ifma_addref(struct ifmultiaddr
*ifma
, int locked
)
3993 IFMA_LOCK_ASSERT_HELD(ifma
);
3995 if (++ifma
->ifma_refcount
== 0) {
3996 panic("%s: ifma=%p wraparound refcnt", __func__
, ifma
);
3998 } else if (ifma
->ifma_trace
!= NULL
) {
3999 (*ifma
->ifma_trace
)(ifma
, TRUE
);
4006 ifma_remref(struct ifmultiaddr
*ifma
)
4008 struct ifmultiaddr
*ll
;
4012 if (ifma
->ifma_refcount
== 0) {
4013 panic("%s: ifma=%p negative refcnt", __func__
, ifma
);
4015 } else if (ifma
->ifma_trace
!= NULL
) {
4016 (*ifma
->ifma_trace
)(ifma
, FALSE
);
4019 --ifma
->ifma_refcount
;
4020 if (ifma
->ifma_refcount
> 0) {
4026 ifma
->ifma_ifp
= NULL
;
4027 ifma
->ifma_ll
= NULL
;
4029 ifma_free(ifma
); /* deallocate it */
4036 if_attach_ifma(struct ifnet
*ifp
, struct ifmultiaddr
*ifma
, int anon
)
4038 ifnet_lock_assert(ifp
, IFNET_LCK_ASSERT_EXCLUSIVE
);
4039 IFMA_LOCK_ASSERT_HELD(ifma
);
4041 if (ifma
->ifma_ifp
!= ifp
) {
4042 panic("%s: Mismatch ifma_ifp=%p != ifp=%p", __func__
,
4043 ifma
->ifma_ifp
, ifp
);
4045 } else if (ifma
->ifma_debug
& IFD_ATTACHED
) {
4046 panic("%s: Attempt to attach an already attached ifma=%p",
4049 } else if (anon
&& (ifma
->ifma_flags
& IFMAF_ANONYMOUS
)) {
4050 panic("%s: ifma=%p unexpected IFMAF_ANONYMOUS", __func__
, ifma
);
4052 } else if (ifma
->ifma_debug
& IFD_TRASHED
) {
4053 panic("%s: Attempt to reattach a detached ifma=%p",
4058 ifma
->ifma_reqcnt
++;
4059 VERIFY(ifma
->ifma_reqcnt
== 1);
4060 IFMA_ADDREF_LOCKED(ifma
);
4061 ifma
->ifma_debug
|= IFD_ATTACHED
;
4063 ifma
->ifma_anoncnt
++;
4064 VERIFY(ifma
->ifma_anoncnt
== 1);
4065 ifma
->ifma_flags
|= IFMAF_ANONYMOUS
;
4068 LIST_INSERT_HEAD(&ifp
->if_multiaddrs
, ifma
, ifma_link
);
4072 if_detach_ifma(struct ifnet
*ifp
, struct ifmultiaddr
*ifma
, int anon
)
4074 ifnet_lock_assert(ifp
, IFNET_LCK_ASSERT_EXCLUSIVE
);
4075 IFMA_LOCK_ASSERT_HELD(ifma
);
4077 if (ifma
->ifma_reqcnt
== 0) {
4078 panic("%s: ifma=%p negative reqcnt", __func__
, ifma
);
4080 } else if (anon
&& !(ifma
->ifma_flags
& IFMAF_ANONYMOUS
)) {
4081 panic("%s: ifma=%p missing IFMAF_ANONYMOUS", __func__
, ifma
);
4083 } else if (anon
&& ifma
->ifma_anoncnt
== 0) {
4084 panic("%s: ifma=%p negative anonreqcnt", __func__
, ifma
);
4086 } else if (ifma
->ifma_ifp
!= ifp
) {
4087 panic("%s: Mismatch ifma_ifp=%p, ifp=%p", __func__
,
4088 ifma
->ifma_ifp
, ifp
);
4093 --ifma
->ifma_anoncnt
;
4094 if (ifma
->ifma_anoncnt
> 0)
4096 ifma
->ifma_flags
&= ~IFMAF_ANONYMOUS
;
4099 --ifma
->ifma_reqcnt
;
4100 if (ifma
->ifma_reqcnt
> 0)
4103 if (ifma
->ifma_protospec
!= NULL
) {
4104 panic("%s: Protospec not NULL for ifma=%p", __func__
, ifma
);
4106 } else if ((ifma
->ifma_flags
& IFMAF_ANONYMOUS
) ||
4107 ifma
->ifma_anoncnt
!= 0) {
4108 panic("%s: Detaching ifma=%p with outstanding anon req",
4111 } else if (!(ifma
->ifma_debug
& IFD_ATTACHED
)) {
4112 panic("%s: Attempt to detach an unattached address ifma=%p",
4115 } else if (ifma
->ifma_debug
& IFD_TRASHED
) {
4116 panic("%s: ifma %p is already in trash list", __func__
, ifma
);
4121 * NOTE: Caller calls IFMA_REMREF
4123 ifma
->ifma_debug
&= ~IFD_ATTACHED
;
4124 LIST_REMOVE(ifma
, ifma_link
);
4125 if (LIST_EMPTY(&ifp
->if_multiaddrs
))
4126 ifp
->if_updatemcasts
= 0;
4128 if (ifma
->ifma_debug
& IFD_DEBUG
) {
4129 /* Become a regular mutex, just in case */
4130 IFMA_CONVERT_LOCK(ifma
);
4131 lck_mtx_lock(&ifma_trash_lock
);
4132 TAILQ_INSERT_TAIL(&ifma_trash_head
,
4133 (struct ifmultiaddr_dbg
*)ifma
, ifma_trash_link
);
4134 lck_mtx_unlock(&ifma_trash_lock
);
4135 ifma
->ifma_debug
|= IFD_TRASHED
;
4142 * Find an ifmultiaddr that matches a socket address on an interface.
4144 * Caller is responsible for holding the ifnet_lock while calling
4148 if_addmulti_doesexist(struct ifnet
*ifp
, const struct sockaddr
*sa
,
4149 struct ifmultiaddr
**retifma
, int anon
)
4151 struct ifmultiaddr
*ifma
;
4153 for (ifma
= LIST_FIRST(&ifp
->if_multiaddrs
); ifma
!= NULL
;
4154 ifma
= LIST_NEXT(ifma
, ifma_link
)) {
4155 IFMA_LOCK_SPIN(ifma
);
4156 if (!ifa_equal(sa
, ifma
->ifma_addr
)) {
4161 VERIFY(!(ifma
->ifma_flags
& IFMAF_ANONYMOUS
) ||
4162 ifma
->ifma_anoncnt
!= 0);
4163 VERIFY((ifma
->ifma_flags
& IFMAF_ANONYMOUS
) ||
4164 ifma
->ifma_anoncnt
== 0);
4165 ifma
->ifma_anoncnt
++;
4166 if (!(ifma
->ifma_flags
& IFMAF_ANONYMOUS
)) {
4167 VERIFY(ifma
->ifma_anoncnt
== 1);
4168 ifma
->ifma_flags
|= IFMAF_ANONYMOUS
;
4171 if (!anon
|| ifma
->ifma_anoncnt
== 1) {
4172 ifma
->ifma_reqcnt
++;
4173 VERIFY(ifma
->ifma_reqcnt
> 1);
4175 if (retifma
!= NULL
) {
4177 IFMA_ADDREF_LOCKED(ifma
);
4186 * Radar 3642395, make sure all multicasts are in a standard format.
4188 static struct sockaddr
*
4189 copy_and_normalize(const struct sockaddr
*original
)
4192 const u_char
*aptr
= NULL
;
4193 struct sockaddr
*copy
= NULL
;
4194 struct sockaddr_dl
*sdl_new
= NULL
;
4197 if (original
->sa_family
!= AF_LINK
&&
4198 original
->sa_family
!= AF_UNSPEC
) {
4199 /* Just make a copy */
4200 MALLOC(copy
, struct sockaddr
*, original
->sa_len
,
4201 M_IFADDR
, M_WAITOK
);
4203 bcopy(original
, copy
, original
->sa_len
);
4207 switch (original
->sa_family
) {
4209 const struct sockaddr_dl
*sdl_original
=
4210 (struct sockaddr_dl
*)(uintptr_t)(size_t)original
;
4212 if (sdl_original
->sdl_nlen
+ sdl_original
->sdl_alen
+
4213 sdl_original
->sdl_slen
+
4214 offsetof(struct sockaddr_dl
, sdl_data
) >
4215 sdl_original
->sdl_len
)
4218 alen
= sdl_original
->sdl_alen
;
4219 aptr
= CONST_LLADDR(sdl_original
);
4224 if (original
->sa_len
< ETHER_ADDR_LEN
+
4225 offsetof(struct sockaddr
, sa_data
)) {
4229 alen
= ETHER_ADDR_LEN
;
4230 aptr
= (const u_char
*)original
->sa_data
;
4235 if (alen
== 0 || aptr
== NULL
)
4238 len
= alen
+ offsetof(struct sockaddr_dl
, sdl_data
);
4239 MALLOC(sdl_new
, struct sockaddr_dl
*, len
, M_IFADDR
, M_WAITOK
);
4241 if (sdl_new
!= NULL
) {
4242 bzero(sdl_new
, len
);
4243 sdl_new
->sdl_len
= len
;
4244 sdl_new
->sdl_family
= AF_LINK
;
4245 sdl_new
->sdl_alen
= alen
;
4246 bcopy(aptr
, LLADDR(sdl_new
), alen
);
4249 return ((struct sockaddr
*)sdl_new
);
4253 * Network-layer protocol domains which hold references to the underlying
4254 * link-layer record must use this routine.
4257 if_addmulti(struct ifnet
*ifp
, const struct sockaddr
*sa
,
4258 struct ifmultiaddr
**retifma
)
4260 return (if_addmulti_common(ifp
, sa
, retifma
, 0));
4264 * Anything other than network-layer protocol domains which hold references
4265 * to the underlying link-layer record must use this routine: SIOCADDMULTI
4266 * ioctl, ifnet_add_multicast(), if_bond.
4269 if_addmulti_anon(struct ifnet
*ifp
, const struct sockaddr
*sa
,
4270 struct ifmultiaddr
**retifma
)
4272 return (if_addmulti_common(ifp
, sa
, retifma
, 1));
4276 * Register an additional multicast address with a network interface.
4278 * - If the address is already present, bump the reference count on the
4279 * address and return.
4280 * - If the address is not link-layer, look up a link layer address.
4281 * - Allocate address structures for one or both addresses, and attach to the
4282 * multicast address list on the interface. If automatically adding a link
4283 * layer address, the protocol address will own a reference to the link
4284 * layer address, to be freed when it is freed.
4285 * - Notify the network device driver of an addition to the multicast address
4288 * 'sa' points to caller-owned memory with the desired multicast address.
4290 * 'retifma' will be used to return a pointer to the resulting multicast
4291 * address reference, if desired.
4293 * 'anon' indicates a link-layer address with no protocol address reference
4294 * made to it. Anything other than network-layer protocol domain requests
4295 * are considered as anonymous.
4298 if_addmulti_common(struct ifnet
*ifp
, const struct sockaddr
*sa
,
4299 struct ifmultiaddr
**retifma
, int anon
)
4301 struct sockaddr_storage storage
;
4302 struct sockaddr
*llsa
= NULL
;
4303 struct sockaddr
*dupsa
= NULL
;
4304 int error
= 0, ll_firstref
= 0, lladdr
;
4305 struct ifmultiaddr
*ifma
= NULL
;
4306 struct ifmultiaddr
*llifma
= NULL
;
4308 /* Only AF_UNSPEC/AF_LINK is allowed for an "anonymous" address */
4309 VERIFY(!anon
|| sa
->sa_family
== AF_UNSPEC
||
4310 sa
->sa_family
== AF_LINK
);
4312 /* If sa is a AF_LINK or AF_UNSPEC, duplicate and normalize it */
4313 if (sa
->sa_family
== AF_LINK
|| sa
->sa_family
== AF_UNSPEC
) {
4314 dupsa
= copy_and_normalize(sa
);
4315 if (dupsa
== NULL
) {
4322 ifnet_lock_exclusive(ifp
);
4323 if (!(ifp
->if_flags
& IFF_MULTICAST
)) {
4324 error
= EADDRNOTAVAIL
;
4325 ifnet_lock_done(ifp
);
4329 /* If the address is already present, return a new reference to it */
4330 error
= if_addmulti_doesexist(ifp
, sa
, retifma
, anon
);
4331 ifnet_lock_done(ifp
);
4336 * The address isn't already present; give the link layer a chance
4337 * to accept/reject it, and also find out which AF_LINK address this
4338 * maps to, if it isn't one already.
4340 error
= dlil_resolve_multi(ifp
, sa
, (struct sockaddr
*)&storage
,
4342 if (error
== 0 && storage
.ss_len
!= 0) {
4343 llsa
= copy_and_normalize((struct sockaddr
*)&storage
);
4349 llifma
= ifma_alloc(M_WAITOK
);
4350 if (llifma
== NULL
) {
4356 /* to be similar to FreeBSD */
4357 if (error
== EOPNOTSUPP
)
4359 else if (error
!= 0)
4362 /* Allocate while we aren't holding any locks */
4363 if (dupsa
== NULL
) {
4364 dupsa
= copy_and_normalize(sa
);
4365 if (dupsa
== NULL
) {
4370 ifma
= ifma_alloc(M_WAITOK
);
4376 ifnet_lock_exclusive(ifp
);
4378 * Check again for the matching multicast.
4380 error
= if_addmulti_doesexist(ifp
, sa
, retifma
, anon
);
4382 ifnet_lock_done(ifp
);
4386 if (llifma
!= NULL
) {
4387 VERIFY(!anon
); /* must not get here if "anonymous" */
4388 if (if_addmulti_doesexist(ifp
, llsa
, &ifma
->ifma_ll
, 0) == 0) {
4389 FREE(llsa
, M_IFADDR
);
4393 VERIFY(ifma
->ifma_ll
->ifma_ifp
== ifp
);
4396 llifma
->ifma_addr
= llsa
;
4397 llifma
->ifma_ifp
= ifp
;
4399 if_attach_ifma(ifp
, llifma
, 0);
4400 /* add extra refcnt for ifma */
4401 IFMA_ADDREF_LOCKED(llifma
);
4402 IFMA_UNLOCK(llifma
);
4403 ifma
->ifma_ll
= llifma
;
4407 /* "anonymous" request should not result in network address */
4408 VERIFY(!anon
|| ifma
->ifma_ll
== NULL
);
4410 ifma
->ifma_addr
= dupsa
;
4411 ifma
->ifma_ifp
= ifp
;
4413 if_attach_ifma(ifp
, ifma
, anon
);
4414 IFMA_ADDREF_LOCKED(ifma
); /* for this routine */
4415 if (retifma
!= NULL
) {
4417 IFMA_ADDREF_LOCKED(*retifma
); /* for caller */
4419 lladdr
= (ifma
->ifma_addr
->sa_family
== AF_UNSPEC
||
4420 ifma
->ifma_addr
->sa_family
== AF_LINK
);
4422 ifnet_lock_done(ifp
);
4424 rt_newmaddrmsg(RTM_NEWMADDR
, ifma
);
4425 IFMA_REMREF(ifma
); /* for this routine */
4428 * We are certain we have added something, so call down to the
4429 * interface to let them know about it. Do this only for newly-
4430 * added AF_LINK/AF_UNSPEC address in the if_multiaddrs set.
4432 if (lladdr
|| ll_firstref
)
4433 (void) ifnet_ioctl(ifp
, 0, SIOCADDMULTI
, NULL
);
4435 if (ifp
->if_updatemcasts
> 0)
4436 ifp
->if_updatemcasts
= 0;
4444 FREE(dupsa
, M_IFADDR
);
4448 FREE(llsa
, M_IFADDR
);
4454 * Delete a multicast group membership by network-layer group address.
4455 * This routine is deprecated.
4458 if_delmulti(struct ifnet
*ifp
, const struct sockaddr
*sa
)
4460 return (if_delmulti_common(NULL
, ifp
, sa
, 0));
4464 * Delete a multicast group membership by group membership pointer.
4465 * Network-layer protocol domains must use this routine.
4468 if_delmulti_ifma(struct ifmultiaddr
*ifma
)
4470 return (if_delmulti_common(ifma
, NULL
, NULL
, 0));
4474 * Anything other than network-layer protocol domains which hold references
4475 * to the underlying link-layer record must use this routine: SIOCDELMULTI
4476 * ioctl, ifnet_remove_multicast(), if_bond.
4479 if_delmulti_anon(struct ifnet
*ifp
, const struct sockaddr
*sa
)
4481 return (if_delmulti_common(NULL
, ifp
, sa
, 1));
4485 * Delete a multicast group membership by network-layer group address.
4487 * Returns ENOENT if the entry could not be found.
4490 if_delmulti_common(struct ifmultiaddr
*ifma
, struct ifnet
*ifp
,
4491 const struct sockaddr
*sa
, int anon
)
4493 struct sockaddr
*dupsa
= NULL
;
4494 int lastref
, ll_lastref
= 0, lladdr
;
4495 struct ifmultiaddr
*ll
= NULL
;
4497 /* sanity check for callers */
4498 VERIFY(ifma
!= NULL
|| (ifp
!= NULL
&& sa
!= NULL
));
4501 ifp
= ifma
->ifma_ifp
;
4504 (sa
->sa_family
== AF_LINK
|| sa
->sa_family
== AF_UNSPEC
)) {
4505 dupsa
= copy_and_normalize(sa
);
4511 ifnet_lock_exclusive(ifp
);
4513 for (ifma
= LIST_FIRST(&ifp
->if_multiaddrs
); ifma
!= NULL
;
4514 ifma
= LIST_NEXT(ifma
, ifma_link
)) {
4516 if (!ifa_equal(sa
, ifma
->ifma_addr
) ||
4517 (anon
&& !(ifma
->ifma_flags
& IFMAF_ANONYMOUS
))) {
4518 VERIFY(!(ifma
->ifma_flags
& IFMAF_ANONYMOUS
) ||
4519 ifma
->ifma_anoncnt
!= 0);
4523 /* found; keep it locked */
4528 FREE(dupsa
, M_IFADDR
);
4529 ifnet_lock_done(ifp
);
4535 IFMA_LOCK_ASSERT_HELD(ifma
);
4536 IFMA_ADDREF_LOCKED(ifma
); /* for this routine */
4537 lastref
= if_detach_ifma(ifp
, ifma
, anon
);
4538 VERIFY(!lastref
|| (!(ifma
->ifma_debug
& IFD_ATTACHED
) &&
4539 ifma
->ifma_reqcnt
== 0));
4540 VERIFY(!anon
|| ifma
->ifma_ll
== NULL
);
4542 lladdr
= (ifma
->ifma_addr
->sa_family
== AF_UNSPEC
||
4543 ifma
->ifma_addr
->sa_family
== AF_LINK
);
4545 if (lastref
&& ll
!= NULL
) {
4547 ll_lastref
= if_detach_ifma(ifp
, ll
, 0);
4550 ifnet_lock_done(ifp
);
4553 rt_newmaddrmsg(RTM_DELMADDR
, ifma
);
4555 if ((ll
== NULL
&& lastref
&& lladdr
) || ll_lastref
) {
4557 * Make sure the interface driver is notified in the
4558 * case of a link layer mcast group being left. Do
4559 * this only for a AF_LINK/AF_UNSPEC address that has
4560 * been removed from the if_multiaddrs set.
4562 ifnet_ioctl(ifp
, 0, SIOCDELMULTI
, NULL
);
4566 IFMA_REMREF(ifma
); /* for if_multiaddrs list */
4568 IFMA_REMREF(ll
); /* for if_multiaddrs list */
4570 IFMA_REMREF(ifma
); /* for this routine */
4572 FREE(dupsa
, M_IFADDR
);
4578 * Shutdown all network activity. Used boot() when halting
4588 if (ifnet_list_get_all(IFNET_FAMILY_ANY
, &ifp
, &count
) == 0) {
4589 for (i
= 0; i
< count
; i
++) {
4591 dlil_proto_unplumb_all(ifp
[i
]);
4593 ifnet_list_free(ifp
);
4600 * Delete Routes for a Network Interface
4602 * Called for each routing entry via the rnh->rnh_walktree() call above
4603 * to delete all route entries referencing a detaching network interface.
4606 * rn pointer to node in the routing table
4607 * arg argument passed to rnh->rnh_walktree() - detaching interface
4611 * errno failed - reason indicated
4615 if_rtdel(struct radix_node
*rn
, void *arg
)
4617 struct rtentry
*rt
= (struct rtentry
*)rn
;
4618 struct ifnet
*ifp
= arg
;
4624 * Checking against RTF_UP protects against walktree
4625 * recursion problems with cloned routes.
4628 if (rt
->rt_ifp
== ifp
&& (rt
->rt_flags
& RTF_UP
)) {
4630 * Safe to drop rt_lock and use rt_key, rt_gateway,
4631 * since holding rnh_lock here prevents another thread
4632 * from calling rt_setgate() on this route.
4635 err
= rtrequest_locked(RTM_DELETE
, rt_key(rt
), rt
->rt_gateway
,
4636 rt_mask(rt
), rt
->rt_flags
, NULL
);
4638 log(LOG_WARNING
, "if_rtdel: error %d\n", err
);
4647 * Removes routing table reference to a given interface
4648 * for a given protocol family
4651 if_rtproto_del(struct ifnet
*ifp
, int protocol
)
4653 struct radix_node_head
*rnh
;
4655 if ((protocol
<= AF_MAX
) && (protocol
>= 0) &&
4656 ((rnh
= rt_tables
[protocol
]) != NULL
) && (ifp
!= NULL
)) {
4657 lck_mtx_lock(rnh_lock
);
4658 (void) rnh
->rnh_walktree(rnh
, if_rtdel
, ifp
);
4659 lck_mtx_unlock(rnh_lock
);
4664 if_rtmtu(struct radix_node
*rn
, void *arg
)
4666 struct rtentry
*rt
= (struct rtentry
*)rn
;
4667 struct ifnet
*ifp
= arg
;
4670 if (rt
->rt_ifp
== ifp
) {
4672 * Update the MTU of this entry only if the MTU
4673 * has not been locked (RTV_MTU is not set) and
4674 * if it was non-zero to begin with.
4676 if (!(rt
->rt_rmx
.rmx_locks
& RTV_MTU
) && rt
->rt_rmx
.rmx_mtu
) {
4677 rt
->rt_rmx
.rmx_mtu
= ifp
->if_mtu
;
4678 if (rt_key(rt
)->sa_family
== AF_INET
&&
4679 INTF_ADJUST_MTU_FOR_CLAT46(ifp
)) {
4680 rt
->rt_rmx
.rmx_mtu
= IN6_LINKMTU(ifp
);
4681 /* Further adjust the size for CLAT46 expansion */
4682 rt
->rt_rmx
.rmx_mtu
-= CLAT46_HDR_EXPANSION_OVERHD
;
4692 * Update the MTU metric of all route entries in all protocol tables
4693 * associated with a particular interface; this is called when the
4694 * MTU of that interface has changed.
4697 if_rtmtu_update(struct ifnet
*ifp
)
4699 struct radix_node_head
*rnh
;
4702 for (p
= 0; p
< AF_MAX
+ 1; p
++) {
4703 if ((rnh
= rt_tables
[p
]) == NULL
)
4706 lck_mtx_lock(rnh_lock
);
4707 (void) rnh
->rnh_walktree(rnh
, if_rtmtu
, ifp
);
4708 lck_mtx_unlock(rnh_lock
);
4710 routegenid_update();
4713 __private_extern__
void
4714 if_data_internal_to_if_data(struct ifnet
*ifp
,
4715 const struct if_data_internal
*if_data_int
, struct if_data
*if_data
)
4718 #define COPYFIELD(fld) if_data->fld = if_data_int->fld
4719 #define COPYFIELD32(fld) if_data->fld = (u_int32_t)(if_data_int->fld)
4720 /* compiler will cast down to 32-bit */
4721 #define COPYFIELD32_ATOMIC(fld) do { \
4722 atomic_get_64(if_data->fld, \
4723 (u_int64_t *)(void *)(uintptr_t)&if_data_int->fld); \
4726 COPYFIELD(ifi_type
);
4727 COPYFIELD(ifi_typelen
);
4728 COPYFIELD(ifi_physical
);
4729 COPYFIELD(ifi_addrlen
);
4730 COPYFIELD(ifi_hdrlen
);
4731 COPYFIELD(ifi_recvquota
);
4732 COPYFIELD(ifi_xmitquota
);
4733 if_data
->ifi_unused1
= 0;
4735 COPYFIELD(ifi_metric
);
4736 if (if_data_int
->ifi_baudrate
& 0xFFFFFFFF00000000LL
) {
4737 if_data
->ifi_baudrate
= 0xFFFFFFFF;
4739 COPYFIELD32(ifi_baudrate
);
4742 COPYFIELD32_ATOMIC(ifi_ipackets
);
4743 COPYFIELD32_ATOMIC(ifi_ierrors
);
4744 COPYFIELD32_ATOMIC(ifi_opackets
);
4745 COPYFIELD32_ATOMIC(ifi_oerrors
);
4746 COPYFIELD32_ATOMIC(ifi_collisions
);
4747 COPYFIELD32_ATOMIC(ifi_ibytes
);
4748 COPYFIELD32_ATOMIC(ifi_obytes
);
4749 COPYFIELD32_ATOMIC(ifi_imcasts
);
4750 COPYFIELD32_ATOMIC(ifi_omcasts
);
4751 COPYFIELD32_ATOMIC(ifi_iqdrops
);
4752 COPYFIELD32_ATOMIC(ifi_noproto
);
4754 COPYFIELD(ifi_recvtiming
);
4755 COPYFIELD(ifi_xmittiming
);
4757 if_data
->ifi_lastchange
.tv_sec
= if_data_int
->ifi_lastchange
.tv_sec
;
4758 if_data
->ifi_lastchange
.tv_usec
= if_data_int
->ifi_lastchange
.tv_usec
;
4760 if_data
->ifi_lastchange
.tv_sec
+= boottime_sec();
4762 if_data
->ifi_unused2
= 0;
4763 COPYFIELD(ifi_hwassist
);
4764 if_data
->ifi_reserved1
= 0;
4765 if_data
->ifi_reserved2
= 0;
4766 #undef COPYFIELD32_ATOMIC
4771 __private_extern__
void
4772 if_data_internal_to_if_data64(struct ifnet
*ifp
,
4773 const struct if_data_internal
*if_data_int
,
4774 struct if_data64
*if_data64
)
4777 #define COPYFIELD64(fld) if_data64->fld = if_data_int->fld
4778 #define COPYFIELD64_ATOMIC(fld) do { \
4779 atomic_get_64(if_data64->fld, \
4780 (u_int64_t *)(void *)(uintptr_t)&if_data_int->fld); \
4783 COPYFIELD64(ifi_type
);
4784 COPYFIELD64(ifi_typelen
);
4785 COPYFIELD64(ifi_physical
);
4786 COPYFIELD64(ifi_addrlen
);
4787 COPYFIELD64(ifi_hdrlen
);
4788 COPYFIELD64(ifi_recvquota
);
4789 COPYFIELD64(ifi_xmitquota
);
4790 if_data64
->ifi_unused1
= 0;
4791 COPYFIELD64(ifi_mtu
);
4792 COPYFIELD64(ifi_metric
);
4793 COPYFIELD64(ifi_baudrate
);
4795 COPYFIELD64_ATOMIC(ifi_ipackets
);
4796 COPYFIELD64_ATOMIC(ifi_ierrors
);
4797 COPYFIELD64_ATOMIC(ifi_opackets
);
4798 COPYFIELD64_ATOMIC(ifi_oerrors
);
4799 COPYFIELD64_ATOMIC(ifi_collisions
);
4800 COPYFIELD64_ATOMIC(ifi_ibytes
);
4801 COPYFIELD64_ATOMIC(ifi_obytes
);
4802 COPYFIELD64_ATOMIC(ifi_imcasts
);
4803 COPYFIELD64_ATOMIC(ifi_omcasts
);
4804 COPYFIELD64_ATOMIC(ifi_iqdrops
);
4805 COPYFIELD64_ATOMIC(ifi_noproto
);
4808 * Note these two fields are actually 32 bit, so doing
4809 * COPYFIELD64_ATOMIC will cause them to be misaligned
4811 COPYFIELD64(ifi_recvtiming
);
4812 COPYFIELD64(ifi_xmittiming
);
4814 if_data64
->ifi_lastchange
.tv_sec
= if_data_int
->ifi_lastchange
.tv_sec
;
4815 if_data64
->ifi_lastchange
.tv_usec
= if_data_int
->ifi_lastchange
.tv_usec
;
4817 if_data64
->ifi_lastchange
.tv_sec
+= boottime_sec();
4822 __private_extern__
void
4823 if_copy_traffic_class(struct ifnet
*ifp
,
4824 struct if_traffic_class
*if_tc
)
4826 #define COPY_IF_TC_FIELD64_ATOMIC(fld) do { \
4827 atomic_get_64(if_tc->fld, \
4828 (u_int64_t *)(void *)(uintptr_t)&ifp->if_tc.fld); \
4831 bzero(if_tc
, sizeof (*if_tc
));
4832 COPY_IF_TC_FIELD64_ATOMIC(ifi_ibepackets
);
4833 COPY_IF_TC_FIELD64_ATOMIC(ifi_ibebytes
);
4834 COPY_IF_TC_FIELD64_ATOMIC(ifi_obepackets
);
4835 COPY_IF_TC_FIELD64_ATOMIC(ifi_obebytes
);
4836 COPY_IF_TC_FIELD64_ATOMIC(ifi_ibkpackets
);
4837 COPY_IF_TC_FIELD64_ATOMIC(ifi_ibkbytes
);
4838 COPY_IF_TC_FIELD64_ATOMIC(ifi_obkpackets
);
4839 COPY_IF_TC_FIELD64_ATOMIC(ifi_obkbytes
);
4840 COPY_IF_TC_FIELD64_ATOMIC(ifi_ivipackets
);
4841 COPY_IF_TC_FIELD64_ATOMIC(ifi_ivibytes
);
4842 COPY_IF_TC_FIELD64_ATOMIC(ifi_ovipackets
);
4843 COPY_IF_TC_FIELD64_ATOMIC(ifi_ovibytes
);
4844 COPY_IF_TC_FIELD64_ATOMIC(ifi_ivopackets
);
4845 COPY_IF_TC_FIELD64_ATOMIC(ifi_ivobytes
);
4846 COPY_IF_TC_FIELD64_ATOMIC(ifi_ovopackets
);
4847 COPY_IF_TC_FIELD64_ATOMIC(ifi_ovobytes
);
4848 COPY_IF_TC_FIELD64_ATOMIC(ifi_ipvpackets
);
4849 COPY_IF_TC_FIELD64_ATOMIC(ifi_ipvbytes
);
4850 COPY_IF_TC_FIELD64_ATOMIC(ifi_opvpackets
);
4851 COPY_IF_TC_FIELD64_ATOMIC(ifi_opvbytes
);
4853 #undef COPY_IF_TC_FIELD64_ATOMIC
4857 if_copy_data_extended(struct ifnet
*ifp
, struct if_data_extended
*if_de
)
4859 #define COPY_IF_DE_FIELD64_ATOMIC(fld) do { \
4860 atomic_get_64(if_de->fld, \
4861 (u_int64_t *)(void *)(uintptr_t)&ifp->if_data.fld); \
4864 bzero(if_de
, sizeof (*if_de
));
4865 COPY_IF_DE_FIELD64_ATOMIC(ifi_alignerrs
);
4866 COPY_IF_DE_FIELD64_ATOMIC(ifi_dt_bytes
);
4867 COPY_IF_DE_FIELD64_ATOMIC(ifi_fpackets
);
4868 COPY_IF_DE_FIELD64_ATOMIC(ifi_fbytes
);
4870 #undef COPY_IF_DE_FIELD64_ATOMIC
4874 if_copy_packet_stats(struct ifnet
*ifp
, struct if_packet_stats
*if_ps
)
4876 #define COPY_IF_PS_TCP_FIELD64_ATOMIC(fld) do { \
4877 atomic_get_64(if_ps->ifi_tcp_##fld, \
4878 (u_int64_t *)(void *)(uintptr_t)&ifp->if_tcp_stat->fld); \
4881 #define COPY_IF_PS_UDP_FIELD64_ATOMIC(fld) do { \
4882 atomic_get_64(if_ps->ifi_udp_##fld, \
4883 (u_int64_t *)(void *)(uintptr_t)&ifp->if_udp_stat->fld); \
4886 COPY_IF_PS_TCP_FIELD64_ATOMIC(badformat
);
4887 COPY_IF_PS_TCP_FIELD64_ATOMIC(unspecv6
);
4888 COPY_IF_PS_TCP_FIELD64_ATOMIC(synfin
);
4889 COPY_IF_PS_TCP_FIELD64_ATOMIC(badformatipsec
);
4890 COPY_IF_PS_TCP_FIELD64_ATOMIC(noconnnolist
);
4891 COPY_IF_PS_TCP_FIELD64_ATOMIC(noconnlist
);
4892 COPY_IF_PS_TCP_FIELD64_ATOMIC(listbadsyn
);
4893 COPY_IF_PS_TCP_FIELD64_ATOMIC(icmp6unreach
);
4894 COPY_IF_PS_TCP_FIELD64_ATOMIC(deprecate6
);
4895 COPY_IF_PS_TCP_FIELD64_ATOMIC(ooopacket
);
4896 COPY_IF_PS_TCP_FIELD64_ATOMIC(rstinsynrcv
);
4897 COPY_IF_PS_TCP_FIELD64_ATOMIC(dospacket
);
4898 COPY_IF_PS_TCP_FIELD64_ATOMIC(cleanup
);
4899 COPY_IF_PS_TCP_FIELD64_ATOMIC(synwindow
);
4901 COPY_IF_PS_UDP_FIELD64_ATOMIC(port_unreach
);
4902 COPY_IF_PS_UDP_FIELD64_ATOMIC(faithprefix
);
4903 COPY_IF_PS_UDP_FIELD64_ATOMIC(port0
);
4904 COPY_IF_PS_UDP_FIELD64_ATOMIC(badlength
);
4905 COPY_IF_PS_UDP_FIELD64_ATOMIC(badchksum
);
4906 COPY_IF_PS_UDP_FIELD64_ATOMIC(badmcast
);
4907 COPY_IF_PS_UDP_FIELD64_ATOMIC(cleanup
);
4908 COPY_IF_PS_UDP_FIELD64_ATOMIC(badipsec
);
4910 #undef COPY_IF_PS_TCP_FIELD64_ATOMIC
4911 #undef COPY_IF_PS_UDP_FIELD64_ATOMIC
4915 if_copy_rxpoll_stats(struct ifnet
*ifp
, struct if_rxpoll_stats
*if_rs
)
4917 bzero(if_rs
, sizeof (*if_rs
));
4918 if (!(ifp
->if_eflags
& IFEF_RXPOLL
) || !ifnet_is_attached(ifp
, 1))
4921 /* by now, ifnet will stay attached so if_inp must be valid */
4922 VERIFY(ifp
->if_inp
!= NULL
);
4923 bcopy(&ifp
->if_inp
->pstats
, if_rs
, sizeof (*if_rs
));
4925 /* Release the IO refcnt */
4926 ifnet_decr_iorefcnt(ifp
);
4930 ifa_remref(struct ifaddr
*ifa
, int locked
)
4935 IFA_LOCK_ASSERT_HELD(ifa
);
4937 if (ifa
->ifa_refcnt
== 0)
4938 panic("%s: ifa %p negative refcnt\n", __func__
, ifa
);
4939 else if (ifa
->ifa_trace
!= NULL
)
4940 (*ifa
->ifa_trace
)(ifa
, FALSE
);
4941 if (--ifa
->ifa_refcnt
== 0) {
4942 if (ifa
->ifa_debug
& IFD_ATTACHED
)
4943 panic("ifa %p attached to ifp is being freed\n", ifa
);
4945 * Some interface addresses are allocated either statically
4946 * or carved out of a larger block. Only free it if it was
4947 * allocated via MALLOC or via the corresponding per-address
4948 * family allocator. Otherwise, leave it alone.
4950 if (ifa
->ifa_debug
& IFD_ALLOC
) {
4951 if (ifa
->ifa_free
== NULL
) {
4953 FREE(ifa
, M_IFADDR
);
4955 /* Become a regular mutex */
4956 IFA_CONVERT_LOCK(ifa
);
4957 /* callee will unlock */
4958 (*ifa
->ifa_free
)(ifa
);
4966 if (!locked
&& ifa
!= NULL
)
4973 ifa_addref(struct ifaddr
*ifa
, int locked
)
4978 IFA_LOCK_ASSERT_HELD(ifa
);
4980 if (++ifa
->ifa_refcnt
== 0) {
4981 panic("%s: ifa %p wraparound refcnt\n", __func__
, ifa
);
4983 } else if (ifa
->ifa_trace
!= NULL
) {
4984 (*ifa
->ifa_trace
)(ifa
, TRUE
);
4991 ifa_lock_init(struct ifaddr
*ifa
)
4993 lck_mtx_init(&ifa
->ifa_lock
, ifa_mtx_grp
, ifa_mtx_attr
);
4997 ifa_lock_destroy(struct ifaddr
*ifa
)
4999 IFA_LOCK_ASSERT_NOTHELD(ifa
);
5000 lck_mtx_destroy(&ifa
->ifa_lock
, ifa_mtx_grp
);
5006 * The switch statement below does nothing at runtime, as it serves as a
5007 * compile time check to ensure that all of the socket 'i' ioctls (those
5008 * in the 'i' group going thru soo_ioctl) that are made available by the
5009 * networking stack is unique. This works as long as this routine gets
5010 * updated each time a new interface ioctl gets added.
5012 * Any failures at compile time indicates duplicated ioctl values.
5014 static __attribute__((unused
)) void
5015 ifioctl_cassert(void)
5018 * This is equivalent to _CASSERT() and the compiler wouldn't
5019 * generate any instructions, thus for compile time only.
5021 switch ((u_long
)0) {
5024 /* bsd/net/if_ppp.h */
5026 case SIOCGPPPCSTATS
:
5029 /* bsd/netinet6/in6_var.h */
5030 case SIOCSIFADDR_IN6
:
5031 case SIOCGIFADDR_IN6
:
5032 case SIOCSIFDSTADDR_IN6
:
5033 case SIOCSIFNETMASK_IN6
:
5034 case SIOCGIFDSTADDR_IN6
:
5035 case SIOCGIFNETMASK_IN6
:
5036 case SIOCDIFADDR_IN6
:
5037 case SIOCAIFADDR_IN6_32
:
5038 case SIOCAIFADDR_IN6_64
:
5039 case SIOCSIFPHYADDR_IN6_32
:
5040 case SIOCSIFPHYADDR_IN6_64
:
5041 case SIOCGIFPSRCADDR_IN6
:
5042 case SIOCGIFPDSTADDR_IN6
:
5043 case SIOCGIFAFLAG_IN6
:
5044 case SIOCGDRLST_IN6_32
:
5045 case SIOCGDRLST_IN6_64
:
5046 case SIOCGPRLST_IN6_32
:
5047 case SIOCGPRLST_IN6_64
:
5048 case OSIOCGIFINFO_IN6
:
5049 case SIOCGIFINFO_IN6
:
5050 case SIOCSNDFLUSH_IN6
:
5051 case SIOCGNBRINFO_IN6_32
:
5052 case SIOCGNBRINFO_IN6_64
:
5053 case SIOCSPFXFLUSH_IN6
:
5054 case SIOCSRTRFLUSH_IN6
:
5055 case SIOCGIFALIFETIME_IN6
:
5056 case SIOCSIFALIFETIME_IN6
:
5057 case SIOCGIFSTAT_IN6
:
5058 case SIOCGIFSTAT_ICMP6
:
5059 case SIOCSDEFIFACE_IN6_32
:
5060 case SIOCSDEFIFACE_IN6_64
:
5061 case SIOCGDEFIFACE_IN6_32
:
5062 case SIOCGDEFIFACE_IN6_64
:
5063 case SIOCSIFINFO_FLAGS
:
5066 case SIOCGSCOPE6DEF
:
5067 case SIOCSIFPREFIX_IN6
:
5068 case SIOCGIFPREFIX_IN6
:
5069 case SIOCDIFPREFIX_IN6
:
5070 case SIOCAIFPREFIX_IN6
:
5071 case SIOCCIFPREFIX_IN6
:
5072 case SIOCSGIFPREFIX_IN6
:
5073 case SIOCPROTOATTACH_IN6_32
:
5074 case SIOCPROTOATTACH_IN6_64
:
5075 case SIOCPROTODETACH_IN6
:
5076 case SIOCLL_START_32
:
5077 case SIOCLL_START_64
:
5079 case SIOCAUTOCONF_START
:
5080 case SIOCAUTOCONF_STOP
:
5081 case SIOCSETROUTERMODE_IN6
:
5082 case SIOCLL_CGASTART_32
:
5083 case SIOCLL_CGASTART_64
:
5084 case SIOCGIFCGAPREP_IN6
:
5085 case SIOCSIFCGAPREP_IN6
:
5088 /* bsd/sys/sockio.h */
5091 case SIOCSIFDSTADDR
:
5092 case OSIOCGIFDSTADDR
:
5095 case OSIOCGIFBRDADDR
:
5096 case SIOCSIFBRDADDR
:
5097 case OSIOCGIFCONF32
:
5098 case OSIOCGIFCONF64
:
5099 case OSIOCGIFNETMASK
:
5100 case SIOCSIFNETMASK
:
5107 case SIOCGIFDSTADDR
:
5108 case SIOCGIFBRDADDR
:
5111 case SIOCGIFNETMASK
:
5113 case SIOCAUTONETMASK
:
5123 case SIOCGIFMEDIA32
:
5124 case SIOCGIFMEDIA64
:
5125 case SIOCSIFGENERIC
:
5126 case SIOCGIFGENERIC
:
5131 case SIOCSIFPHYADDR
:
5132 case SIOCGIFPSRCADDR
:
5133 case SIOCGIFPDSTADDR
:
5134 case SIOCDIFPHYADDR
:
5142 case SIOCPROTOATTACH
:
5143 case SIOCPROTODETACH
:
5152 case SIOCSDRVSPEC32
:
5153 case SIOCGDRVSPEC32
:
5154 case SIOCSDRVSPEC64
:
5155 case SIOCGDRVSPEC64
:
5160 case SIOCIFGCLONERS32
:
5161 case SIOCIFGCLONERS64
:
5163 case SIOCGIFASYNCMAP
:
5164 case SIOCSIFASYNCMAP
:
5168 #endif /* CONFIG_MACF_NET */
5172 case SIOCGIFWAKEFLAGS
:
5174 case SIOCGIFGETRTREFCNT
:
5175 case SIOCGIFLINKQUALITYMETRIC
:
5176 case SIOCSIFOPPORTUNISTIC
:
5177 case SIOCGIFOPPORTUNISTIC
:
5178 case SIOCSETROUTERMODE
:
5182 case SIOCSIFLINKPARAMS
:
5183 case SIOCGIFLINKPARAMS
:
5184 case SIOCGIFQUEUESTATS
:
5185 case SIOCSIFTHROTTLE
:
5186 case SIOCGIFTHROTTLE
:
5188 case SIOCGASSOCIDS32
:
5189 case SIOCGASSOCIDS64
:
5190 case SIOCGCONNIDS32
:
5191 case SIOCGCONNIDS64
:
5192 case SIOCGCONNINFO32
:
5193 case SIOCGCONNINFO64
:
5194 case SIOCSCONNORDER
:
5195 case SIOCGCONNORDER
:
5199 case SIOCGIFDELEGATE
:
5202 case SIOCGIFEXPENSIVE
:
5203 case SIOCSIFEXPENSIVE
:
5206 case SIOCGSTARTDELAY
:
5208 case SIOCAIFAGENTID
:
5209 case SIOCDIFAGENTID
:
5210 case SIOCGIFAGENTIDS32
:
5211 case SIOCGIFAGENTIDS64
:
5212 case SIOCGIFAGENTDATA32
:
5213 case SIOCGIFAGENTDATA64
:
5215 case SIOCSIFINTERFACESTATE
:
5216 case SIOCGIFINTERFACESTATE
:
5217 case SIOCSIFPROBECONNECTIVITY
:
5218 case SIOCGIFPROBECONNECTIVITY
:
5220 case SIOCGIFFUNCTIONALTYPE
:
5221 case SIOCSIFNETSIGNATURE
:
5222 case SIOCGIFNETSIGNATURE
:
5229 case SIOCSQOSMARKINGMODE
:
5230 case SIOCSQOSMARKINGENABLED
:
5231 case SIOCGQOSMARKINGMODE
:
5232 case SIOCGQOSMARKINGENABLED
:
5234 case SIOCSIFTIMESTAMPENABLE
:
5235 case SIOCSIFTIMESTAMPDISABLE
:
5236 case SIOCGIFTIMESTAMPENABLED
:
5238 case SIOCSIFDISABLEOUTPUT
:
5240 case SIOCGIFAGENTLIST32
:
5241 case SIOCGIFAGENTLIST64
:
5243 case SIOCSIFLOWINTERNET
:
5244 case SIOCGIFLOWINTERNET
:
5247 case SIOCGIFNAT64PREFIX
:
5248 case SIOCSIFNAT64PREFIX
:
5250 case SIOCGIFCLAT46ADDR
:
5253 case SIOCGIFPROTOLIST32
:
5254 case SIOCGIFPROTOLIST64
:
5256 case SIOCGIFLOWPOWER
:
5257 case SIOCSIFLOWPOWER
:
5263 ifnet_mbuf_packetpreamblelen(struct ifnet
*ifp
)
5269 /* The following is used to enqueue work items for interface events */
5272 union sockaddr_in_4_6 addr
;
5273 uint32_t intf_event_code
;
5277 intf_event_callback(void *arg
)
5279 struct intf_event
*p_intf_ev
= (struct intf_event
*)arg
;
5281 /* Call this before we walk the tree */
5282 EVENTHANDLER_INVOKE(&ifnet_evhdlr_ctxt
, ifnet_event
, p_intf_ev
->ifp
,
5283 (struct sockaddr
*)&(p_intf_ev
->addr
), p_intf_ev
->intf_event_code
);
5286 struct intf_event_nwk_wq_entry
{
5287 struct nwk_wq_entry nwk_wqe
;
5288 struct intf_event intf_ev_arg
;
5292 intf_event_enqueue_nwk_wq_entry(struct ifnet
*ifp
, struct sockaddr
*addrp
,
5293 uint32_t intf_event_code
)
5295 #pragma unused(addrp)
5296 struct intf_event_nwk_wq_entry
*p_intf_ev
= NULL
;
5298 MALLOC(p_intf_ev
, struct intf_event_nwk_wq_entry
*,
5299 sizeof(struct intf_event_nwk_wq_entry
),
5300 M_NWKWQ
, M_WAITOK
| M_ZERO
);
5302 p_intf_ev
->intf_ev_arg
.ifp
= ifp
;
5304 * XXX Not using addr in the arg. This will be used
5305 * once we need IP address add/delete events
5307 p_intf_ev
->intf_ev_arg
.intf_event_code
= intf_event_code
;
5308 p_intf_ev
->nwk_wqe
.func
= intf_event_callback
;
5309 p_intf_ev
->nwk_wqe
.is_arg_managed
= TRUE
;
5310 p_intf_ev
->nwk_wqe
.arg
= &p_intf_ev
->intf_ev_arg
;
5311 nwk_wq_enqueue((struct nwk_wq_entry
*)p_intf_ev
);