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/ip6.h>
116 #include <netinet/ip_var.h>
117 #include <netinet/tcp.h>
118 #include <netinet/tcp_var.h>
119 #include <netinet/udp.h>
120 #include <netinet/udp_var.h>
122 #include <netinet6/in6_var.h>
123 #include <netinet6/in6_ifattach.h>
124 #include <netinet6/ip6_var.h>
125 #include <netinet6/nd6.h>
127 #endif /* INET || INET6 */
130 #include <security/mac_framework.h>
134 * System initialization
137 extern char *proc_name_address(void *);
139 /* Lock group and attribute for ifaddr lock */
140 lck_attr_t
*ifa_mtx_attr
;
141 lck_grp_t
*ifa_mtx_grp
;
142 static lck_grp_attr_t
*ifa_mtx_grp_attr
;
144 static int ifioctl_ifreq(struct socket
*, u_long
, struct ifreq
*,
146 static int ifioctl_ifconf(u_long
, caddr_t
);
147 static int ifioctl_ifclone(u_long
, caddr_t
);
148 static int ifioctl_iforder(u_long
, caddr_t
);
149 static int ifioctl_ifdesc(struct ifnet
*, u_long
, caddr_t
, struct proc
*);
150 static int ifioctl_linkparams(struct ifnet
*, u_long
, caddr_t
, struct proc
*);
151 static int ifioctl_qstats(struct ifnet
*, u_long
, caddr_t
);
152 static int ifioctl_throttle(struct ifnet
*, u_long
, caddr_t
, struct proc
*);
153 static int ifioctl_netsignature(struct ifnet
*, u_long
, caddr_t
);
154 static int ifconf(u_long cmd
, user_addr_t ifrp
, int * ret_space
);
155 __private_extern__
void link_rtrequest(int, struct rtentry
*, struct sockaddr
*);
156 void if_rtproto_del(struct ifnet
*ifp
, int protocol
);
158 static int if_addmulti_common(struct ifnet
*, const struct sockaddr
*,
159 struct ifmultiaddr
**, int);
160 static int if_delmulti_common(struct ifmultiaddr
*, struct ifnet
*,
161 const struct sockaddr
*, int);
162 static struct ifnet
*ifunit_common(const char *, boolean_t
);
164 static int if_rtmtu(struct radix_node
*, void *);
165 static void if_rtmtu_update(struct ifnet
*);
167 static int if_clone_list(int, int *, user_addr_t
);
169 MALLOC_DEFINE(M_IFADDR
, "ifaddr", "interface address");
171 struct ifnethead ifnet_head
= TAILQ_HEAD_INITIALIZER(ifnet_head
);
173 /* ifnet_ordered_head and if_ordered_count are protected by the ifnet_head lock */
174 struct ifnethead ifnet_ordered_head
= TAILQ_HEAD_INITIALIZER(ifnet_ordered_head
);
175 static u_int32_t if_ordered_count
= 0;
177 static int if_cloners_count
;
178 LIST_HEAD(, if_clone
) if_cloners
= LIST_HEAD_INITIALIZER(if_cloners
);
180 static struct ifaddr
*ifa_ifwithnet_common(const struct sockaddr
*,
182 static void if_attach_ifa_common(struct ifnet
*, struct ifaddr
*, int);
183 static void if_detach_ifa_common(struct ifnet
*, struct ifaddr
*, int);
185 static void if_attach_ifma(struct ifnet
*, struct ifmultiaddr
*, int);
186 static int if_detach_ifma(struct ifnet
*, struct ifmultiaddr
*, int);
188 static struct ifmultiaddr
*ifma_alloc(int);
189 static void ifma_free(struct ifmultiaddr
*);
190 static void ifma_trace(struct ifmultiaddr
*, int);
193 static unsigned int ifma_debug
= 1; /* debugging (enabled) */
195 static unsigned int ifma_debug
; /* debugging (disabled) */
197 static unsigned int ifma_size
; /* size of zone element */
198 static struct zone
*ifma_zone
; /* zone for ifmultiaddr */
200 #define IFMA_TRACE_HIST_SIZE 32 /* size of trace history */
203 __private_extern__
unsigned int ifma_trace_hist_size
= IFMA_TRACE_HIST_SIZE
;
205 struct ifmultiaddr_dbg
{
206 struct ifmultiaddr ifma
; /* ifmultiaddr */
207 u_int16_t ifma_refhold_cnt
; /* # of ref */
208 u_int16_t ifma_refrele_cnt
; /* # of rele */
210 * Circular lists of IFA_ADDREF and IFA_REMREF callers.
212 ctrace_t ifma_refhold
[IFMA_TRACE_HIST_SIZE
];
213 ctrace_t ifma_refrele
[IFMA_TRACE_HIST_SIZE
];
217 TAILQ_ENTRY(ifmultiaddr_dbg
) ifma_trash_link
;
220 /* List of trash ifmultiaddr entries protected by ifma_trash_lock */
221 static TAILQ_HEAD(, ifmultiaddr_dbg
) ifma_trash_head
;
222 static decl_lck_mtx_data(, ifma_trash_lock
);
224 #define IFMA_ZONE_MAX 64 /* maximum elements in zone */
225 #define IFMA_ZONE_NAME "ifmultiaddr" /* zone name */
229 * XXX: declare here to avoid to include many inet6 related files..
230 * should be more generalized?
232 extern void nd6_setmtu(struct ifnet
*);
233 extern lck_mtx_t
*nd6_mutex
;
236 SYSCTL_NODE(_net
, PF_LINK
, link
, CTLFLAG_RW
|CTLFLAG_LOCKED
, 0, "Link layers");
237 SYSCTL_NODE(_net_link
, 0, generic
, CTLFLAG_RW
|CTLFLAG_LOCKED
, 0,
238 "Generic link-management");
240 SYSCTL_DECL(_net_link_generic_system
);
242 static uint32_t if_verbose
= 0;
243 SYSCTL_INT(_net_link_generic_system
, OID_AUTO
, if_verbose
,
244 CTLFLAG_RW
| CTLFLAG_LOCKED
, &if_verbose
, 0, "");
246 boolean_t intcoproc_unrestricted
;
248 /* Eventhandler context for interface events */
249 struct eventhandler_lists_ctxt ifnet_evhdlr_ctxt
;
254 /* Setup lock group and attribute for ifaddr */
255 ifa_mtx_grp_attr
= lck_grp_attr_alloc_init();
256 ifa_mtx_grp
= lck_grp_alloc_init("ifaddr", ifa_mtx_grp_attr
);
257 ifa_mtx_attr
= lck_attr_alloc_init();
259 PE_parse_boot_argn("ifa_debug", &ifma_debug
, sizeof (ifma_debug
));
261 ifma_size
= (ifma_debug
== 0) ? sizeof (struct ifmultiaddr
) :
262 sizeof (struct ifmultiaddr_dbg
);
264 ifma_zone
= zinit(ifma_size
, IFMA_ZONE_MAX
* ifma_size
, 0,
266 if (ifma_zone
== NULL
) {
267 panic("%s: failed allocating %s", __func__
, IFMA_ZONE_NAME
);
270 zone_change(ifma_zone
, Z_EXPAND
, TRUE
);
271 zone_change(ifma_zone
, Z_CALLERACCT
, FALSE
);
273 lck_mtx_init(&ifma_trash_lock
, ifa_mtx_grp
, ifa_mtx_attr
);
274 TAILQ_INIT(&ifma_trash_head
);
276 PE_parse_boot_argn("intcoproc_unrestricted", &intcoproc_unrestricted
,
277 sizeof (intcoproc_unrestricted
));
281 * Network interface utility routines.
283 * Routines with ifa_ifwith* names take sockaddr *'s as
288 struct ifaddr
**ifnet_addrs
;
289 struct ifnet
**ifindex2ifnet
;
291 __private_extern__
void
292 if_attach_ifa(struct ifnet
*ifp
, struct ifaddr
*ifa
)
294 if_attach_ifa_common(ifp
, ifa
, 0);
297 __private_extern__
void
298 if_attach_link_ifa(struct ifnet
*ifp
, struct ifaddr
*ifa
)
300 if_attach_ifa_common(ifp
, ifa
, 1);
304 if_attach_ifa_common(struct ifnet
*ifp
, struct ifaddr
*ifa
, int link
)
306 ifnet_lock_assert(ifp
, IFNET_LCK_ASSERT_EXCLUSIVE
);
307 IFA_LOCK_ASSERT_HELD(ifa
);
309 if (ifa
->ifa_ifp
!= ifp
) {
310 panic("%s: Mismatch ifa_ifp=%p != ifp=%p", __func__
,
313 } else if (ifa
->ifa_debug
& IFD_ATTACHED
) {
314 panic("%s: Attempt to attach an already attached ifa=%p",
317 } else if (link
&& !(ifa
->ifa_debug
& IFD_LINK
)) {
318 panic("%s: Unexpected non-link address ifa=%p", __func__
, ifa
);
320 } else if (!link
&& (ifa
->ifa_debug
& IFD_LINK
)) {
321 panic("%s: Unexpected link address ifa=%p", __func__
, ifa
);
324 IFA_ADDREF_LOCKED(ifa
);
325 ifa
->ifa_debug
|= IFD_ATTACHED
;
327 TAILQ_INSERT_HEAD(&ifp
->if_addrhead
, ifa
, ifa_link
);
329 TAILQ_INSERT_TAIL(&ifp
->if_addrhead
, ifa
, ifa_link
);
331 if (ifa
->ifa_attached
!= NULL
)
332 (*ifa
->ifa_attached
)(ifa
);
336 __private_extern__
void
337 if_detach_ifa(struct ifnet
*ifp
, struct ifaddr
*ifa
)
339 if_detach_ifa_common(ifp
, ifa
, 0);
342 __private_extern__
void
343 if_detach_link_ifa(struct ifnet
*ifp
, struct ifaddr
*ifa
)
345 if_detach_ifa_common(ifp
, ifa
, 1);
349 if_detach_ifa_common(struct ifnet
*ifp
, struct ifaddr
*ifa
, int link
)
351 ifnet_lock_assert(ifp
, IFNET_LCK_ASSERT_EXCLUSIVE
);
352 IFA_LOCK_ASSERT_HELD(ifa
);
354 if (link
&& !(ifa
->ifa_debug
& IFD_LINK
)) {
355 panic("%s: Unexpected non-link address ifa=%p", __func__
, ifa
);
357 } else if (link
&& ifa
!= TAILQ_FIRST(&ifp
->if_addrhead
)) {
358 panic("%s: Link address ifa=%p not first", __func__
, ifa
);
360 } else if (!link
&& (ifa
->ifa_debug
& IFD_LINK
)) {
361 panic("%s: Unexpected link address ifa=%p", __func__
, ifa
);
363 } else if (!(ifa
->ifa_debug
& IFD_ATTACHED
)) {
364 panic("%s: Attempt to detach an unattached address ifa=%p",
367 } else if (ifa
->ifa_ifp
!= ifp
) {
368 panic("%s: Mismatch ifa_ifp=%p, ifp=%p", __func__
,
371 } else if (ifa
->ifa_debug
& IFD_DEBUG
) {
373 TAILQ_FOREACH(ifa2
, &ifp
->if_addrhead
, ifa_link
) {
378 panic("%s: Attempt to detach a stray address ifa=%p",
383 TAILQ_REMOVE(&ifp
->if_addrhead
, ifa
, ifa_link
);
384 /* This must not be the last reference to the ifaddr */
385 if (IFA_REMREF_LOCKED(ifa
) == NULL
) {
386 panic("%s: unexpected (missing) refcnt ifa=%p", __func__
, ifa
);
389 ifa
->ifa_debug
&= ~(IFD_ATTACHED
| IFD_DETACHING
);
391 if (ifa
->ifa_detached
!= NULL
)
392 (*ifa
->ifa_detached
)(ifa
);
396 #define INITIAL_IF_INDEXLIM 8
399 * Function: if_next_index
401 * Return the next available interface index.
402 * Grow the ifnet_addrs[] and ifindex2ifnet[] arrays to accomodate the
403 * added entry when necessary.
406 * ifnet_addrs[] is indexed by (if_index - 1), whereas
407 * ifindex2ifnet[] is indexed by ifp->if_index. That requires us to
408 * always allocate one extra element to hold ifindex2ifnet[0], which
411 int if_next_index(void);
413 __private_extern__
int
416 static int if_indexlim
= 0;
419 new_index
= ++if_index
;
420 if (if_index
> if_indexlim
) {
423 caddr_t new_ifnet_addrs
;
424 caddr_t new_ifindex2ifnet
;
425 caddr_t old_ifnet_addrs
;
427 old_ifnet_addrs
= (caddr_t
)ifnet_addrs
;
428 if (ifnet_addrs
== NULL
) {
429 new_if_indexlim
= INITIAL_IF_INDEXLIM
;
431 new_if_indexlim
= if_indexlim
<< 1;
434 /* allocate space for the larger arrays */
435 n
= (2 * new_if_indexlim
+ 1) * sizeof(caddr_t
);
436 new_ifnet_addrs
= _MALLOC(n
, M_IFADDR
, M_WAITOK
| M_ZERO
);
437 if (new_ifnet_addrs
== NULL
) {
442 new_ifindex2ifnet
= new_ifnet_addrs
443 + new_if_indexlim
* sizeof(caddr_t
);
444 if (ifnet_addrs
!= NULL
) {
445 /* copy the existing data */
446 bcopy((caddr_t
)ifnet_addrs
, new_ifnet_addrs
,
447 if_indexlim
* sizeof(caddr_t
));
448 bcopy((caddr_t
)ifindex2ifnet
,
450 (if_indexlim
+ 1) * sizeof(caddr_t
));
453 /* switch to the new tables and size */
454 ifnet_addrs
= (struct ifaddr
**)(void *)new_ifnet_addrs
;
455 ifindex2ifnet
= (struct ifnet
**)(void *)new_ifindex2ifnet
;
456 if_indexlim
= new_if_indexlim
;
458 /* release the old data */
459 if (old_ifnet_addrs
!= NULL
) {
460 _FREE((caddr_t
)old_ifnet_addrs
, M_IFADDR
);
467 * Create a clone network interface.
470 if_clone_create(char *name
, int len
, void *params
)
472 struct if_clone
*ifc
;
475 u_int32_t bytoff
, bitoff
;
479 ifc
= if_clone_lookup(name
, &unit
);
483 if (ifunit(name
) != NULL
)
487 wildcard
= (unit
== UINT32_MAX
);
489 * Find a free unit if none was given.
492 while ((bytoff
< ifc
->ifc_bmlen
) &&
493 (ifc
->ifc_units
[bytoff
] == 0xff))
495 if (bytoff
>= ifc
->ifc_bmlen
)
497 while ((ifc
->ifc_units
[bytoff
] & (1 << bitoff
)) != 0)
499 unit
= (bytoff
<< 3) + bitoff
;
502 if (unit
> ifc
->ifc_maxunit
)
505 err
= (*ifc
->ifc_create
)(ifc
, unit
, params
);
511 bitoff
= unit
- (bytoff
<< 3);
515 * Allocate the unit in the bitmap.
517 KASSERT((ifc
->ifc_units
[bytoff
] & (1 << bitoff
)) == 0,
518 ("%s: bit is already set", __func__
));
519 ifc
->ifc_units
[bytoff
] |= (1 << bitoff
);
521 /* In the wildcard case, we need to update the name. */
523 for (dp
= name
; *dp
!= '\0'; dp
++);
524 if (snprintf(dp
, len
- (dp
-name
), "%d", unit
) >
525 len
- (dp
-name
) - 1) {
527 * This can only be a programmer error and
528 * there's no straightforward way to recover if
531 panic("%s: interface name too long", __func__
);
541 * Destroy a clone network interface.
544 if_clone_destroy(const char *name
)
546 struct if_clone
*ifc
;
551 ifc
= if_clone_lookup(name
, &unit
);
555 if (unit
< ifc
->ifc_minifs
)
562 if (ifc
->ifc_destroy
== NULL
)
565 (*ifc
->ifc_destroy
)(ifp
);
568 * Compute offset in the bitmap and deallocate the unit.
571 bitoff
= unit
- (bytoff
<< 3);
572 KASSERT((ifc
->ifc_units
[bytoff
] & (1 << bitoff
)) != 0,
573 ("%s: bit is already cleared", __func__
));
574 ifc
->ifc_units
[bytoff
] &= ~(1 << bitoff
);
579 * Look up a network interface cloner.
582 __private_extern__
struct if_clone
*
583 if_clone_lookup(const char *name
, u_int32_t
*unitp
)
585 struct if_clone
*ifc
;
589 for (ifc
= LIST_FIRST(&if_cloners
); ifc
!= NULL
; ) {
590 for (cp
= name
, i
= 0; i
< ifc
->ifc_namelen
; i
++, cp
++) {
591 if (ifc
->ifc_name
[i
] != *cp
)
596 ifc
= LIST_NEXT(ifc
, ifc_list
);
600 return ((struct if_clone
*)NULL
);
606 for (i
= 0; *cp
!= '\0'; cp
++) {
607 if (*cp
< '0' || *cp
> '9') {
608 /* Bogus unit number. */
611 i
= (i
* 10) + (*cp
- '0');
621 * Register a network interface cloner.
624 if_clone_attach(struct if_clone
*ifc
)
631 KASSERT(ifc
->ifc_minifs
- 1 <= ifc
->ifc_maxunit
,
632 ("%s: %s requested more units then allowed (%d > %d)",
633 __func__
, ifc
->ifc_name
, ifc
->ifc_minifs
,
634 ifc
->ifc_maxunit
+ 1));
636 * Compute bitmap size and allocate it.
638 maxclone
= ifc
->ifc_maxunit
+ 1;
640 if ((len
<< 3) < maxclone
)
642 ifc
->ifc_units
= _MALLOC(len
, M_CLONE
, M_WAITOK
| M_ZERO
);
643 if (ifc
->ifc_units
== NULL
)
645 ifc
->ifc_bmlen
= len
;
647 LIST_INSERT_HEAD(&if_cloners
, ifc
, ifc_list
);
650 for (unit
= 0; unit
< ifc
->ifc_minifs
; unit
++) {
651 err
= (*ifc
->ifc_create
)(ifc
, unit
, NULL
);
653 ("%s: failed to create required interface %s%d",
654 __func__
, ifc
->ifc_name
, unit
));
656 /* Allocate the unit in the bitmap. */
658 bitoff
= unit
- (bytoff
<< 3);
659 ifc
->ifc_units
[bytoff
] |= (1 << bitoff
);
666 * Unregister a network interface cloner.
669 if_clone_detach(struct if_clone
*ifc
)
671 LIST_REMOVE(ifc
, ifc_list
);
672 FREE(ifc
->ifc_units
, M_CLONE
);
677 * Provide list of interface cloners to userspace.
680 if_clone_list(int count
, int *ret_total
, user_addr_t dst
)
682 char outbuf
[IFNAMSIZ
];
683 struct if_clone
*ifc
;
686 *ret_total
= if_cloners_count
;
687 if (dst
== USER_ADDR_NULL
) {
688 /* Just asking how many there are. */
695 count
= (if_cloners_count
< count
) ? if_cloners_count
: count
;
697 for (ifc
= LIST_FIRST(&if_cloners
); ifc
!= NULL
&& count
!= 0;
698 ifc
= LIST_NEXT(ifc
, ifc_list
), count
--, dst
+= IFNAMSIZ
) {
699 bzero(outbuf
, sizeof(outbuf
));
700 strlcpy(outbuf
, ifc
->ifc_name
, IFNAMSIZ
);
701 error
= copyout(outbuf
, dst
, IFNAMSIZ
);
710 if_functional_type(struct ifnet
*ifp
, bool exclude_delegate
)
712 u_int32_t ret
= IFRTYPE_FUNCTIONAL_UNKNOWN
;
714 if (ifp
->if_flags
& IFF_LOOPBACK
) {
715 ret
= IFRTYPE_FUNCTIONAL_LOOPBACK
;
716 } else if ((exclude_delegate
&&
717 (ifp
->if_subfamily
== IFNET_SUBFAMILY_WIFI
)) ||
718 (!exclude_delegate
&& IFNET_IS_WIFI(ifp
))) {
719 if (ifp
->if_eflags
& IFEF_AWDL
)
720 ret
= IFRTYPE_FUNCTIONAL_WIFI_AWDL
;
722 ret
= IFRTYPE_FUNCTIONAL_WIFI_INFRA
;
723 } else if ((exclude_delegate
&&
724 (ifp
->if_type
== IFT_CELLULAR
)) ||
725 (!exclude_delegate
&& IFNET_IS_CELLULAR(ifp
))) {
726 ret
= IFRTYPE_FUNCTIONAL_CELLULAR
;
727 } else if (IFNET_IS_INTCOPROC(ifp
)) {
728 ret
= IFRTYPE_FUNCTIONAL_INTCOPROC
;
729 } else if ((exclude_delegate
&&
730 (ifp
->if_family
== IFNET_FAMILY_ETHERNET
||
731 ifp
->if_family
== IFNET_FAMILY_FIREWIRE
)) ||
732 (!exclude_delegate
&& IFNET_IS_WIRED(ifp
))) {
733 ret
= IFRTYPE_FUNCTIONAL_WIRED
;
741 * Similar to ifa_ifwithaddr, except that this is IPv4 specific
742 * and that it matches only the local (not broadcast) address.
744 __private_extern__
struct in_ifaddr
*
745 ifa_foraddr(unsigned int addr
)
747 return (ifa_foraddr_scoped(addr
, IFSCOPE_NONE
));
751 * Similar to ifa_foraddr, except with the added interface scope
752 * constraint (unless the caller passes in IFSCOPE_NONE in which
753 * case there is no scope restriction).
755 __private_extern__
struct in_ifaddr
*
756 ifa_foraddr_scoped(unsigned int addr
, unsigned int scope
)
758 struct in_ifaddr
*ia
= NULL
;
760 lck_rw_lock_shared(in_ifaddr_rwlock
);
761 TAILQ_FOREACH(ia
, INADDR_HASH(addr
), ia_hash
) {
762 IFA_LOCK_SPIN(&ia
->ia_ifa
);
763 if (ia
->ia_addr
.sin_addr
.s_addr
== addr
&&
764 (scope
== IFSCOPE_NONE
|| ia
->ia_ifp
->if_index
== scope
)) {
765 IFA_ADDREF_LOCKED(&ia
->ia_ifa
); /* for caller */
766 IFA_UNLOCK(&ia
->ia_ifa
);
769 IFA_UNLOCK(&ia
->ia_ifa
);
771 lck_rw_done(in_ifaddr_rwlock
);
777 * Similar to ifa_foraddr, except that this for IPv6.
779 __private_extern__
struct in6_ifaddr
*
780 ifa_foraddr6(struct in6_addr
*addr6
)
782 return (ifa_foraddr6_scoped(addr6
, IFSCOPE_NONE
));
785 __private_extern__
struct in6_ifaddr
*
786 ifa_foraddr6_scoped(struct in6_addr
*addr6
, unsigned int scope
)
788 struct in6_ifaddr
*ia
= NULL
;
790 lck_rw_lock_shared(&in6_ifaddr_rwlock
);
791 for (ia
= in6_ifaddrs
; ia
; ia
= ia
->ia_next
) {
792 IFA_LOCK(&ia
->ia_ifa
);
793 if (IN6_ARE_ADDR_EQUAL(&ia
->ia_addr
.sin6_addr
, addr6
) &&
794 (scope
== IFSCOPE_NONE
|| ia
->ia_ifp
->if_index
== scope
)) {
795 IFA_ADDREF_LOCKED(&ia
->ia_ifa
); /* for caller */
796 IFA_UNLOCK(&ia
->ia_ifa
);
799 IFA_UNLOCK(&ia
->ia_ifa
);
801 lck_rw_done(&in6_ifaddr_rwlock
);
808 * Return the first (primary) address of a given family on an interface.
810 __private_extern__
struct ifaddr
*
811 ifa_ifpgetprimary(struct ifnet
*ifp
, int family
)
815 ifnet_lock_shared(ifp
);
816 TAILQ_FOREACH(ifa
, &ifp
->if_addrhead
, ifa_link
) {
818 if (ifa
->ifa_addr
->sa_family
== family
) {
819 IFA_ADDREF_LOCKED(ifa
); /* for caller */
825 ifnet_lock_done(ifp
);
831 ifa_equal(const struct sockaddr
*sa1
, const struct sockaddr
*sa2
)
836 if (sa1
->sa_len
!= sa2
->sa_len
)
839 return (bcmp(sa1
, sa2
, sa1
->sa_len
) == 0);
843 * Locate an interface based on a complete address.
846 ifa_ifwithaddr_locked(const struct sockaddr
*addr
)
850 struct ifaddr
*result
= NULL
;
852 for (ifp
= ifnet_head
.tqh_first
; ifp
&& !result
;
853 ifp
= ifp
->if_link
.tqe_next
) {
854 ifnet_lock_shared(ifp
);
855 for (ifa
= ifp
->if_addrhead
.tqh_first
; ifa
;
856 ifa
= ifa
->ifa_link
.tqe_next
) {
858 if (ifa
->ifa_addr
->sa_family
!= addr
->sa_family
) {
862 if (ifa_equal(addr
, ifa
->ifa_addr
)) {
864 IFA_ADDREF_LOCKED(ifa
); /* for caller */
868 if ((ifp
->if_flags
& IFF_BROADCAST
) &&
869 ifa
->ifa_broadaddr
!= NULL
&&
870 /* IP6 doesn't have broadcast */
871 ifa
->ifa_broadaddr
->sa_len
!= 0 &&
872 ifa_equal(ifa
->ifa_broadaddr
, addr
)) {
874 IFA_ADDREF_LOCKED(ifa
); /* for caller */
880 ifnet_lock_done(ifp
);
887 ifa_ifwithaddr(const struct sockaddr
*addr
)
889 struct ifaddr
*result
= NULL
;
891 ifnet_head_lock_shared();
893 result
= ifa_ifwithaddr_locked(addr
);
900 * Locate the point to point interface with a given destination address.
904 ifa_ifwithdstaddr(const struct sockaddr
*addr
)
908 struct ifaddr
*result
= NULL
;
910 ifnet_head_lock_shared();
911 for (ifp
= ifnet_head
.tqh_first
; ifp
&& !result
;
912 ifp
= ifp
->if_link
.tqe_next
) {
913 if ((ifp
->if_flags
& IFF_POINTOPOINT
)) {
914 ifnet_lock_shared(ifp
);
915 for (ifa
= ifp
->if_addrhead
.tqh_first
; ifa
;
916 ifa
= ifa
->ifa_link
.tqe_next
) {
918 if (ifa
->ifa_addr
->sa_family
!=
923 if (ifa_equal(addr
, ifa
->ifa_dstaddr
)) {
925 IFA_ADDREF_LOCKED(ifa
); /* for caller */
931 ifnet_lock_done(ifp
);
939 * Locate the source address of an interface based on a complete address.
942 ifa_ifwithaddr_scoped_locked(const struct sockaddr
*addr
, unsigned int ifscope
)
944 struct ifaddr
*result
= NULL
;
947 if (ifscope
== IFSCOPE_NONE
)
948 return (ifa_ifwithaddr_locked(addr
));
950 if (ifscope
> (unsigned int)if_index
) {
954 ifp
= ifindex2ifnet
[ifscope
];
956 struct ifaddr
*ifa
= NULL
;
959 * This is suboptimal; there should be a better way
960 * to search for a given address of an interface
961 * for any given address family.
963 ifnet_lock_shared(ifp
);
964 for (ifa
= ifp
->if_addrhead
.tqh_first
; ifa
!= NULL
;
965 ifa
= ifa
->ifa_link
.tqe_next
) {
967 if (ifa
->ifa_addr
->sa_family
!= addr
->sa_family
) {
971 if (ifa_equal(addr
, ifa
->ifa_addr
)) {
973 IFA_ADDREF_LOCKED(ifa
); /* for caller */
977 if ((ifp
->if_flags
& IFF_BROADCAST
) &&
978 ifa
->ifa_broadaddr
!= NULL
&&
979 /* IP6 doesn't have broadcast */
980 ifa
->ifa_broadaddr
->sa_len
!= 0 &&
981 ifa_equal(ifa
->ifa_broadaddr
, addr
)) {
983 IFA_ADDREF_LOCKED(ifa
); /* for caller */
989 ifnet_lock_done(ifp
);
996 ifa_ifwithaddr_scoped(const struct sockaddr
*addr
, unsigned int ifscope
)
998 struct ifaddr
*result
= NULL
;
1000 ifnet_head_lock_shared();
1002 result
= ifa_ifwithaddr_scoped_locked(addr
, ifscope
);
1010 ifa_ifwithnet(const struct sockaddr
*addr
)
1012 return (ifa_ifwithnet_common(addr
, IFSCOPE_NONE
));
1016 ifa_ifwithnet_scoped(const struct sockaddr
*addr
, unsigned int ifscope
)
1018 return (ifa_ifwithnet_common(addr
, ifscope
));
1022 * Find an interface on a specific network. If many, choice
1023 * is most specific found.
1025 static struct ifaddr
*
1026 ifa_ifwithnet_common(const struct sockaddr
*addr
, unsigned int ifscope
)
1029 struct ifaddr
*ifa
= NULL
;
1030 struct ifaddr
*ifa_maybe
= NULL
;
1031 u_int af
= addr
->sa_family
;
1032 const char *addr_data
= addr
->sa_data
, *cplim
;
1035 if (af
!= AF_INET
&& af
!= AF_INET6
)
1039 ifscope
= IFSCOPE_NONE
;
1041 ifnet_head_lock_shared();
1043 * AF_LINK addresses can be looked up directly by their index number,
1044 * so do that if we can.
1046 if (af
== AF_LINK
) {
1047 const struct sockaddr_dl
*sdl
=
1048 (const struct sockaddr_dl
*)(uintptr_t)(size_t)addr
;
1049 if (sdl
->sdl_index
&& sdl
->sdl_index
<= if_index
) {
1050 ifa
= ifnet_addrs
[sdl
->sdl_index
- 1];
1060 * Scan though each interface, looking for ones that have
1061 * addresses in this address family.
1063 for (ifp
= ifnet_head
.tqh_first
; ifp
; ifp
= ifp
->if_link
.tqe_next
) {
1064 ifnet_lock_shared(ifp
);
1065 for (ifa
= ifp
->if_addrhead
.tqh_first
; ifa
;
1066 ifa
= ifa
->ifa_link
.tqe_next
) {
1067 const char *cp
, *cp2
, *cp3
;
1070 if (ifa
->ifa_addr
== NULL
||
1071 ifa
->ifa_addr
->sa_family
!= af
) {
1077 * If we're looking up with a scope,
1078 * find using a matching interface.
1080 if (ifscope
!= IFSCOPE_NONE
&&
1081 ifp
->if_index
!= ifscope
) {
1087 * Scan all the bits in the ifa's address.
1088 * If a bit dissagrees with what we are
1089 * looking for, mask it with the netmask
1090 * to see if it really matters.
1091 * (A byte at a time)
1093 if (ifa
->ifa_netmask
== 0) {
1098 cp2
= ifa
->ifa_addr
->sa_data
;
1099 cp3
= ifa
->ifa_netmask
->sa_data
;
1100 cplim
= ifa
->ifa_netmask
->sa_len
+
1101 (char *)ifa
->ifa_netmask
;
1103 if ((*cp
++ ^ *cp2
++) & *cp3
++)
1104 goto next
; /* next address! */
1106 * If the netmask of what we just found
1107 * is more specific than what we had before
1108 * (if we had one) then remember the new one
1109 * before continuing to search
1110 * for an even better one.
1112 if (ifa_maybe
== NULL
||
1113 rn_refines((caddr_t
)ifa
->ifa_netmask
,
1114 (caddr_t
)ifa_maybe
->ifa_netmask
)) {
1115 IFA_ADDREF_LOCKED(ifa
); /* ifa_maybe */
1117 if (ifa_maybe
!= NULL
)
1118 IFA_REMREF(ifa_maybe
);
1123 IFA_LOCK_ASSERT_NOTHELD(ifa
);
1125 ifnet_lock_done(ifp
);
1134 else if (ifa_maybe
!= NULL
)
1135 IFA_REMREF(ifa_maybe
);
1141 * Find an interface address specific to an interface best matching
1145 ifaof_ifpforaddr(const struct sockaddr
*addr
, struct ifnet
*ifp
)
1147 struct ifaddr
*ifa
= NULL
;
1148 const char *cp
, *cp2
, *cp3
;
1150 struct ifaddr
*ifa_maybe
= NULL
;
1151 struct ifaddr
*better_ifa_maybe
= NULL
;
1152 u_int af
= addr
->sa_family
;
1157 ifnet_lock_shared(ifp
);
1158 for (ifa
= ifp
->if_addrhead
.tqh_first
; ifa
;
1159 ifa
= ifa
->ifa_link
.tqe_next
) {
1161 if (ifa
->ifa_addr
->sa_family
!= af
) {
1165 if (ifa_maybe
== NULL
) {
1166 IFA_ADDREF_LOCKED(ifa
); /* for ifa_maybe */
1169 if (ifa
->ifa_netmask
== 0) {
1170 if (ifa_equal(addr
, ifa
->ifa_addr
) ||
1171 ifa_equal(addr
, ifa
->ifa_dstaddr
)) {
1172 IFA_ADDREF_LOCKED(ifa
); /* for caller */
1179 if (ifp
->if_flags
& IFF_POINTOPOINT
) {
1180 if (ifa_equal(addr
, ifa
->ifa_dstaddr
)) {
1181 IFA_ADDREF_LOCKED(ifa
); /* for caller */
1186 if (ifa_equal(addr
, ifa
->ifa_addr
)) {
1188 IFA_ADDREF_LOCKED(ifa
); /* for caller */
1193 cp2
= ifa
->ifa_addr
->sa_data
;
1194 cp3
= ifa
->ifa_netmask
->sa_data
;
1195 cplim
= ifa
->ifa_netmask
->sa_len
+
1196 (char *)ifa
->ifa_netmask
;
1197 for (; cp3
< cplim
; cp3
++)
1198 if ((*cp
++ ^ *cp2
++) & *cp3
)
1202 if (better_ifa_maybe
== NULL
) {
1203 /* for better_ifa_maybe */
1204 IFA_ADDREF_LOCKED(ifa
);
1205 better_ifa_maybe
= ifa
;
1213 if (better_ifa_maybe
!= NULL
) {
1214 ifa
= better_ifa_maybe
;
1215 better_ifa_maybe
= NULL
;
1222 ifnet_lock_done(ifp
);
1224 if (better_ifa_maybe
!= NULL
)
1225 IFA_REMREF(better_ifa_maybe
);
1226 if (ifa_maybe
!= NULL
)
1227 IFA_REMREF(ifa_maybe
);
1232 #include <net/route.h>
1235 * Default action when installing a route with a Link Level gateway.
1236 * Lookup an appropriate real ifa to point to.
1237 * This should be moved to /sys/net/link.c eventually.
1240 link_rtrequest(int cmd
, struct rtentry
*rt
, struct sockaddr
*sa
)
1243 struct sockaddr
*dst
;
1245 void (*ifa_rtrequest
)(int, struct rtentry
*, struct sockaddr
*);
1247 LCK_MTX_ASSERT(rnh_lock
, LCK_MTX_ASSERT_OWNED
);
1248 RT_LOCK_ASSERT_HELD(rt
);
1250 if (cmd
!= RTM_ADD
|| ((ifa
= rt
->rt_ifa
) == 0) ||
1251 ((ifp
= ifa
->ifa_ifp
) == 0) || ((dst
= rt_key(rt
)) == 0))
1254 /* Become a regular mutex, just in case */
1255 RT_CONVERT_LOCK(rt
);
1257 ifa
= ifaof_ifpforaddr(dst
, ifp
);
1261 ifa_rtrequest
= ifa
->ifa_rtrequest
;
1263 if (ifa_rtrequest
!= NULL
&& ifa_rtrequest
!= link_rtrequest
)
1264 ifa_rtrequest(cmd
, rt
, sa
);
1270 * if_updown will set the interface up or down. It will
1271 * prevent other up/down events from occurring until this
1272 * up/down event has completed.
1274 * Caller must lock ifnet. This function will drop the
1275 * lock. This allows ifnet_set_flags to set the rest of
1276 * the flags after we change the up/down state without
1277 * dropping the interface lock between setting the
1278 * up/down state and updating the rest of the flags.
1280 __private_extern__
void
1281 if_updown( struct ifnet
*ifp
, int up
)
1284 struct ifaddr
**ifa
;
1286 struct ifclassq
*ifq
= &ifp
->if_snd
;
1288 /* Wait until no one else is changing the up/down state */
1289 while ((ifp
->if_eflags
& IFEF_UPDOWNCHANGE
) != 0) {
1291 tv
.tv_nsec
= NSEC_PER_SEC
/ 10;
1292 ifnet_lock_done(ifp
);
1293 msleep(&ifp
->if_eflags
, NULL
, 0, "if_updown", &tv
);
1294 ifnet_lock_exclusive(ifp
);
1297 /* Verify that the interface isn't already in the right state */
1298 if ((!up
&& (ifp
->if_flags
& IFF_UP
) == 0) ||
1299 (up
&& (ifp
->if_flags
& IFF_UP
) == IFF_UP
)) {
1303 /* Indicate that the up/down state is changing */
1304 ifp
->if_eflags
|= IFEF_UPDOWNCHANGE
;
1306 /* Mark interface up or down */
1308 ifp
->if_flags
|= IFF_UP
;
1310 ifp
->if_flags
&= ~IFF_UP
;
1313 ifnet_touch_lastchange(ifp
);
1315 /* Drop the lock to notify addresses and route */
1316 ifnet_lock_done(ifp
);
1321 /* Inform all transmit queues about the new link state */
1322 ifnet_update_sndq(ifq
, up
? CLASSQ_EV_LINK_UP
: CLASSQ_EV_LINK_DOWN
);
1325 if (ifnet_get_address_list(ifp
, &ifa
) == 0) {
1326 for (i
= 0; ifa
[i
] != 0; i
++) {
1327 pfctlinput(up
? PRC_IFUP
: PRC_IFDOWN
, ifa
[i
]->ifa_addr
);
1329 ifnet_free_address_list(ifa
);
1333 /* Aquire the lock to clear the changing flag */
1334 ifnet_lock_exclusive(ifp
);
1335 ifp
->if_eflags
&= ~IFEF_UPDOWNCHANGE
;
1336 wakeup(&ifp
->if_eflags
);
1340 * Mark an interface down and notify protocols of
1347 ifnet_lock_exclusive(ifp
);
1349 ifnet_lock_done(ifp
);
1353 * Mark an interface up and notify protocols of
1360 ifnet_lock_exclusive(ifp
);
1362 ifnet_lock_done(ifp
);
1366 * Flush an interface queue.
1369 if_qflush(struct ifnet
*ifp
, int ifq_locked
)
1371 struct ifclassq
*ifq
= &ifp
->if_snd
;
1376 if (IFCQ_IS_ENABLED(ifq
))
1379 VERIFY(IFCQ_IS_EMPTY(ifq
));
1386 if_qflush_sc(struct ifnet
*ifp
, mbuf_svc_class_t sc
, u_int32_t flow
,
1387 u_int32_t
*packets
, u_int32_t
*bytes
, int ifq_locked
)
1389 struct ifclassq
*ifq
= &ifp
->if_snd
;
1390 u_int32_t cnt
= 0, len
= 0;
1391 u_int32_t a_cnt
= 0, a_len
= 0;
1393 VERIFY(sc
== MBUF_SC_UNSPEC
|| MBUF_VALID_SC(sc
));
1399 if (IFCQ_IS_ENABLED(ifq
))
1400 IFCQ_PURGE_SC(ifq
, sc
, flow
, cnt
, len
);
1405 if (packets
!= NULL
)
1406 *packets
= cnt
+ a_cnt
;
1408 *bytes
= len
+ a_len
;
1412 * Extracts interface unit number and name from string, returns -1 upon failure.
1413 * Upon success, returns extracted unit number, and interface name in dst.
1416 ifunit_extract(const char *src
, char *dst
, size_t dstlen
, int *unit
)
1423 if (src
== NULL
|| dst
== NULL
|| dstlen
== 0 || unit
== NULL
)
1427 if (len
< 2 || len
> dstlen
)
1431 if (c
< '0' || c
> '9')
1432 return (-1); /* trailing garbage */
1437 return (-1); /* no interface name */
1440 return (-1); /* number is unreasonable */
1443 } while (c
>= '0' && c
<= '9');
1445 bcopy(src
, dst
, len
);
1453 * Map interface name to
1454 * interface structure pointer.
1456 static struct ifnet
*
1457 ifunit_common(const char *name
, boolean_t hold
)
1459 char namebuf
[IFNAMSIZ
+ 1];
1463 if (ifunit_extract(name
, namebuf
, sizeof (namebuf
), &unit
) < 0)
1466 /* for safety, since we use strcmp() below */
1467 namebuf
[sizeof (namebuf
) - 1] = '\0';
1470 * Now search all the interfaces for this name/number
1472 ifnet_head_lock_shared();
1473 TAILQ_FOREACH(ifp
, &ifnet_head
, if_link
) {
1475 * Use strcmp() rather than strncmp() here,
1476 * since we want to match the entire string.
1478 if (strcmp(ifp
->if_name
, namebuf
))
1480 if (unit
== ifp
->if_unit
)
1484 /* if called from ifunit_ref() and ifnet is not attached, bail */
1485 if (hold
&& ifp
!= NULL
&& !ifnet_is_attached(ifp
, 1))
1493 ifunit(const char *name
)
1495 return (ifunit_common(name
, FALSE
));
1499 * Similar to ifunit(), except that we hold an I/O reference count on an
1500 * attached interface, which must later be released via ifnet_decr_iorefcnt().
1501 * Will return NULL unless interface exists and is fully attached.
1504 ifunit_ref(const char *name
)
1506 return (ifunit_common(name
, TRUE
));
1510 * Map interface name in a sockaddr_dl to
1511 * interface structure pointer.
1514 if_withname(struct sockaddr
*sa
)
1516 char ifname
[IFNAMSIZ
+1];
1517 struct sockaddr_dl
*sdl
= (struct sockaddr_dl
*)(void *)sa
;
1519 if ((sa
->sa_family
!= AF_LINK
) || (sdl
->sdl_nlen
== 0) ||
1520 (sdl
->sdl_nlen
> IFNAMSIZ
))
1524 * ifunit wants a null-terminated name. It may not be null-terminated
1525 * in the sockaddr. We don't want to change the caller's sockaddr,
1526 * and there might not be room to put the trailing null anyway, so we
1527 * make a local copy that we know we can null terminate safely.
1530 bcopy(sdl
->sdl_data
, ifname
, sdl
->sdl_nlen
);
1531 ifname
[sdl
->sdl_nlen
] = '\0';
1532 return (ifunit(ifname
));
1535 static __attribute__((noinline
)) int
1536 ifioctl_ifconf(u_long cmd
, caddr_t data
)
1541 case OSIOCGIFCONF32
: /* struct ifconf32 */
1542 case SIOCGIFCONF32
: { /* struct ifconf32 */
1543 struct ifconf32 ifc
;
1544 bcopy(data
, &ifc
, sizeof (ifc
));
1545 error
= ifconf(cmd
, CAST_USER_ADDR_T(ifc
.ifc_req
),
1547 bcopy(&ifc
, data
, sizeof (ifc
));
1551 case SIOCGIFCONF64
: /* struct ifconf64 */
1552 case OSIOCGIFCONF64
: { /* struct ifconf64 */
1553 struct ifconf64 ifc
;
1554 bcopy(data
, &ifc
, sizeof (ifc
));
1555 error
= ifconf(cmd
, ifc
.ifc_req
, &ifc
.ifc_len
);
1556 bcopy(&ifc
, data
, sizeof (ifc
));
1568 static __attribute__((noinline
)) int
1569 ifioctl_ifclone(u_long cmd
, caddr_t data
)
1574 case SIOCIFGCLONERS32
: { /* struct if_clonereq32 */
1575 struct if_clonereq32 ifcr
;
1576 bcopy(data
, &ifcr
, sizeof (ifcr
));
1577 error
= if_clone_list(ifcr
.ifcr_count
, &ifcr
.ifcr_total
,
1578 CAST_USER_ADDR_T(ifcr
.ifcru_buffer
));
1579 bcopy(&ifcr
, data
, sizeof (ifcr
));
1583 case SIOCIFGCLONERS64
: { /* struct if_clonereq64 */
1584 struct if_clonereq64 ifcr
;
1585 bcopy(data
, &ifcr
, sizeof (ifcr
));
1586 error
= if_clone_list(ifcr
.ifcr_count
, &ifcr
.ifcr_total
,
1588 bcopy(&ifcr
, data
, sizeof (ifcr
));
1600 static __attribute__((noinline
)) int
1601 ifioctl_ifdesc(struct ifnet
*ifp
, u_long cmd
, caddr_t data
, struct proc
*p
)
1603 struct if_descreq
*ifdr
= (struct if_descreq
*)(void *)data
;
1607 VERIFY(ifp
!= NULL
);
1610 case SIOCSIFDESC
: { /* struct if_descreq */
1611 if ((error
= proc_suser(p
)) != 0)
1614 ifnet_lock_exclusive(ifp
);
1615 bcopy(&ifdr
->ifdr_len
, &ifdr_len
, sizeof (ifdr_len
));
1616 if (ifdr_len
> sizeof (ifdr
->ifdr_desc
) ||
1617 ifdr_len
> ifp
->if_desc
.ifd_maxlen
) {
1619 ifnet_lock_done(ifp
);
1623 bzero(ifp
->if_desc
.ifd_desc
, ifp
->if_desc
.ifd_maxlen
);
1624 if ((ifp
->if_desc
.ifd_len
= ifdr_len
) > 0) {
1625 bcopy(ifdr
->ifdr_desc
, ifp
->if_desc
.ifd_desc
,
1626 MIN(ifdr_len
, ifp
->if_desc
.ifd_maxlen
));
1628 ifnet_lock_done(ifp
);
1632 case SIOCGIFDESC
: { /* struct if_descreq */
1633 ifnet_lock_shared(ifp
);
1634 ifdr_len
= MIN(ifp
->if_desc
.ifd_len
, sizeof (ifdr
->ifdr_desc
));
1635 bcopy(&ifdr_len
, &ifdr
->ifdr_len
, sizeof (ifdr_len
));
1636 bzero(&ifdr
->ifdr_desc
, sizeof (ifdr
->ifdr_desc
));
1638 bcopy(ifp
->if_desc
.ifd_desc
, ifdr
->ifdr_desc
, ifdr_len
);
1640 ifnet_lock_done(ifp
);
1652 static __attribute__((noinline
)) int
1653 ifioctl_linkparams(struct ifnet
*ifp
, u_long cmd
, caddr_t data
, struct proc
*p
)
1655 struct if_linkparamsreq
*iflpr
=
1656 (struct if_linkparamsreq
*)(void *)data
;
1657 struct ifclassq
*ifq
;
1660 VERIFY(ifp
!= NULL
);
1664 case SIOCSIFLINKPARAMS
: { /* struct if_linkparamsreq */
1665 struct tb_profile tb
= { 0, 0, 0 };
1667 if ((error
= proc_suser(p
)) != 0)
1672 if (!IFCQ_IS_READY(ifq
)) {
1677 bcopy(&iflpr
->iflpr_output_tbr_rate
, &tb
.rate
,
1679 bcopy(&iflpr
->iflpr_output_tbr_percent
, &tb
.percent
,
1680 sizeof (tb
.percent
));
1681 error
= ifclassq_tbr_set(ifq
, &tb
, TRUE
);
1686 case SIOCGIFLINKPARAMS
: { /* struct if_linkparamsreq */
1687 u_int32_t sched_type
= PKTSCHEDT_NONE
, flags
= 0;
1688 u_int64_t tbr_bw
= 0, tbr_pct
= 0;
1692 if (IFCQ_IS_ENABLED(ifq
))
1693 sched_type
= ifq
->ifcq_type
;
1695 bcopy(&sched_type
, &iflpr
->iflpr_output_sched
,
1696 sizeof (iflpr
->iflpr_output_sched
));
1698 if (IFCQ_TBR_IS_ENABLED(ifq
)) {
1699 tbr_bw
= ifq
->ifcq_tbr
.tbr_rate_raw
;
1700 tbr_pct
= ifq
->ifcq_tbr
.tbr_percent
;
1702 bcopy(&tbr_bw
, &iflpr
->iflpr_output_tbr_rate
,
1703 sizeof (iflpr
->iflpr_output_tbr_rate
));
1704 bcopy(&tbr_pct
, &iflpr
->iflpr_output_tbr_percent
,
1705 sizeof (iflpr
->iflpr_output_tbr_percent
));
1708 if (ifp
->if_output_sched_model
==
1709 IFNET_SCHED_MODEL_DRIVER_MANAGED
)
1710 flags
|= IFLPRF_DRVMANAGED
;
1711 bcopy(&flags
, &iflpr
->iflpr_flags
, sizeof (iflpr
->iflpr_flags
));
1712 bcopy(&ifp
->if_output_bw
, &iflpr
->iflpr_output_bw
,
1713 sizeof (iflpr
->iflpr_output_bw
));
1714 bcopy(&ifp
->if_input_bw
, &iflpr
->iflpr_input_bw
,
1715 sizeof (iflpr
->iflpr_input_bw
));
1716 bcopy(&ifp
->if_output_lt
, &iflpr
->iflpr_output_lt
,
1717 sizeof (iflpr
->iflpr_output_lt
));
1718 bcopy(&ifp
->if_input_lt
, &iflpr
->iflpr_input_lt
,
1719 sizeof (iflpr
->iflpr_input_lt
));
1731 static __attribute__((noinline
)) int
1732 ifioctl_qstats(struct ifnet
*ifp
, u_long cmd
, caddr_t data
)
1734 struct if_qstatsreq
*ifqr
= (struct if_qstatsreq
*)(void *)data
;
1735 u_int32_t ifqr_len
, ifqr_slot
;
1738 VERIFY(ifp
!= NULL
);
1741 case SIOCGIFQUEUESTATS
: { /* struct if_qstatsreq */
1742 bcopy(&ifqr
->ifqr_slot
, &ifqr_slot
, sizeof (ifqr_slot
));
1743 bcopy(&ifqr
->ifqr_len
, &ifqr_len
, sizeof (ifqr_len
));
1744 error
= ifclassq_getqstats(&ifp
->if_snd
, ifqr_slot
,
1745 ifqr
->ifqr_buf
, &ifqr_len
);
1748 bcopy(&ifqr_len
, &ifqr
->ifqr_len
, sizeof (ifqr_len
));
1760 static __attribute__((noinline
)) int
1761 ifioctl_throttle(struct ifnet
*ifp
, u_long cmd
, caddr_t data
, struct proc
*p
)
1763 struct if_throttlereq
*ifthr
= (struct if_throttlereq
*)(void *)data
;
1764 u_int32_t ifthr_level
;
1767 VERIFY(ifp
!= NULL
);
1770 case SIOCSIFTHROTTLE
: { /* struct if_throttlereq */
1772 * XXX: Use priv_check_cred() instead of root check?
1774 if ((error
= proc_suser(p
)) != 0)
1777 bcopy(&ifthr
->ifthr_level
, &ifthr_level
, sizeof (ifthr_level
));
1778 error
= ifnet_set_throttle(ifp
, ifthr_level
);
1779 if (error
== EALREADY
)
1784 case SIOCGIFTHROTTLE
: { /* struct if_throttlereq */
1785 if ((error
= ifnet_get_throttle(ifp
, &ifthr_level
)) == 0) {
1786 bcopy(&ifthr_level
, &ifthr
->ifthr_level
,
1787 sizeof (ifthr_level
));
1801 ifioctl_getnetagents(struct ifnet
*ifp
, u_int32_t
*count
, user_addr_t uuid_p
)
1804 u_int32_t index
= 0;
1805 u_int32_t valid_netagent_count
= 0;
1808 ifnet_lock_assert(ifp
, IFNET_LCK_ASSERT_SHARED
);
1810 if (ifp
->if_agentids
!= NULL
) {
1811 for (index
= 0; index
< ifp
->if_agentcount
; index
++) {
1812 uuid_t
*netagent_uuid
= &(ifp
->if_agentids
[index
]);
1813 if (!uuid_is_null(*netagent_uuid
)) {
1814 if (uuid_p
!= USER_ADDR_NULL
) {
1815 error
= copyout(netagent_uuid
,
1816 uuid_p
+ sizeof(uuid_t
) * valid_netagent_count
,
1822 valid_netagent_count
++;
1826 *count
= valid_netagent_count
;
1831 #define IF_MAXAGENTS 64
1832 #define IF_AGENT_INCREMENT 8
1834 if_add_netagent_locked(struct ifnet
*ifp
, uuid_t new_agent_uuid
)
1836 uuid_t
*first_empty_slot
= NULL
;
1837 u_int32_t index
= 0;
1838 bool already_added
= FALSE
;
1840 if (ifp
->if_agentids
!= NULL
) {
1841 for (index
= 0; index
< ifp
->if_agentcount
; index
++) {
1842 uuid_t
*netagent_uuid
= &(ifp
->if_agentids
[index
]);
1843 if (uuid_compare(*netagent_uuid
, new_agent_uuid
) == 0) {
1844 /* Already present, ignore */
1845 already_added
= TRUE
;
1848 if (first_empty_slot
== NULL
&&
1849 uuid_is_null(*netagent_uuid
)) {
1850 first_empty_slot
= netagent_uuid
;
1854 if (already_added
) {
1855 /* Already added agent, don't return an error */
1858 if (first_empty_slot
== NULL
) {
1859 if (ifp
->if_agentcount
>= IF_MAXAGENTS
) {
1860 /* No room for another netagent UUID, bail */
1863 /* Calculate new array size */
1864 u_int32_t new_agent_count
=
1865 MIN(ifp
->if_agentcount
+ IF_AGENT_INCREMENT
,
1868 /* Reallocate array */
1869 uuid_t
*new_agent_array
= _REALLOC(ifp
->if_agentids
,
1870 sizeof(uuid_t
) * new_agent_count
, M_NETAGENT
,
1872 if (new_agent_array
== NULL
) {
1876 /* Save new array */
1877 ifp
->if_agentids
= new_agent_array
;
1879 /* Set first empty slot */
1881 &(ifp
->if_agentids
[ifp
->if_agentcount
]);
1883 /* Save new array length */
1884 ifp
->if_agentcount
= new_agent_count
;
1887 uuid_copy(*first_empty_slot
, new_agent_uuid
);
1888 netagent_post_updated_interfaces(new_agent_uuid
);
1893 if_add_netagent(struct ifnet
*ifp
, uuid_t new_agent_uuid
)
1895 VERIFY(ifp
!= NULL
);
1897 ifnet_lock_exclusive(ifp
);
1899 int error
= if_add_netagent_locked(ifp
, new_agent_uuid
);
1901 ifnet_lock_done(ifp
);
1907 if_delete_netagent_locked(struct ifnet
*ifp
, uuid_t remove_agent_uuid
)
1909 u_int32_t index
= 0;
1910 bool removed_agent_id
= FALSE
;
1912 if (ifp
->if_agentids
!= NULL
) {
1913 for (index
= 0; index
< ifp
->if_agentcount
; index
++) {
1914 uuid_t
*netagent_uuid
= &(ifp
->if_agentids
[index
]);
1915 if (uuid_compare(*netagent_uuid
,
1916 remove_agent_uuid
) == 0) {
1917 uuid_clear(*netagent_uuid
);
1918 removed_agent_id
= TRUE
;
1923 if (removed_agent_id
)
1924 netagent_post_updated_interfaces(remove_agent_uuid
);
1930 if_delete_netagent(struct ifnet
*ifp
, uuid_t remove_agent_uuid
)
1932 VERIFY(ifp
!= NULL
);
1934 ifnet_lock_exclusive(ifp
);
1936 int error
= if_delete_netagent_locked(ifp
, remove_agent_uuid
);
1938 ifnet_lock_done(ifp
);
1944 if_check_netagent(struct ifnet
*ifp
, uuid_t find_agent_uuid
)
1946 boolean_t found
= FALSE
;
1948 if (!ifp
|| uuid_is_null(find_agent_uuid
))
1951 ifnet_lock_shared(ifp
);
1953 if (ifp
->if_agentids
!= NULL
) {
1954 for (uint32_t index
= 0; index
< ifp
->if_agentcount
; index
++) {
1955 if (uuid_compare(ifp
->if_agentids
[index
], find_agent_uuid
) == 0) {
1962 ifnet_lock_done(ifp
);
1967 static __attribute__((noinline
)) int
1968 ifioctl_netagent(struct ifnet
*ifp
, u_long cmd
, caddr_t data
, struct proc
*p
)
1970 struct if_agentidreq
*ifar
= (struct if_agentidreq
*)(void *)data
;
1972 struct if_agentidsreq32 s32
;
1973 struct if_agentidsreq64 s64
;
1977 VERIFY(ifp
!= NULL
);
1979 /* Get an io ref count if the interface is attached */
1980 if (!ifnet_is_attached(ifp
, 1)) {
1981 return (EOPNOTSUPP
);
1984 if (cmd
== SIOCAIFAGENTID
||
1985 cmd
== SIOCDIFAGENTID
) {
1986 ifnet_lock_exclusive(ifp
);
1988 ifnet_lock_shared(ifp
);
1992 case SIOCAIFAGENTID
: { /* struct if_agentidreq */
1993 // TODO: Use priv_check_cred() instead of root check
1994 if ((error
= proc_suser(p
)) != 0) {
1997 error
= if_add_netagent_locked(ifp
, ifar
->ifar_uuid
);
2000 case SIOCDIFAGENTID
: { /* struct if_agentidreq */
2001 // TODO: Use priv_check_cred() instead of root check
2002 if ((error
= proc_suser(p
)) != 0) {
2005 error
= if_delete_netagent_locked(ifp
, ifar
->ifar_uuid
);
2008 case SIOCGIFAGENTIDS32
: { /* struct if_agentidsreq32 */
2009 bcopy(data
, &u
.s32
, sizeof(u
.s32
));
2010 error
= ifioctl_getnetagents(ifp
, &u
.s32
.ifar_count
,
2013 bcopy(&u
.s32
, data
, sizeof(u
.s32
));
2017 case SIOCGIFAGENTIDS64
: { /* struct if_agentidsreq64 */
2018 bcopy(data
, &u
.s64
, sizeof(u
.s64
));
2019 error
= ifioctl_getnetagents(ifp
, &u
.s64
.ifar_count
,
2022 bcopy(&u
.s64
, data
, sizeof(u
.s64
));
2031 ifnet_lock_done(ifp
);
2032 ifnet_decr_iorefcnt(ifp
);
2038 ifnet_clear_netagent(uuid_t netagent_uuid
)
2040 struct ifnet
*ifp
= NULL
;
2041 u_int32_t index
= 0;
2043 ifnet_head_lock_shared();
2045 TAILQ_FOREACH(ifp
, &ifnet_head
, if_link
) {
2046 ifnet_lock_shared(ifp
);
2047 if (ifp
->if_agentids
!= NULL
) {
2048 for (index
= 0; index
< ifp
->if_agentcount
; index
++) {
2049 uuid_t
*ifp_netagent_uuid
= &(ifp
->if_agentids
[index
]);
2050 if (uuid_compare(*ifp_netagent_uuid
, netagent_uuid
) == 0) {
2051 uuid_clear(*ifp_netagent_uuid
);
2055 ifnet_lock_done(ifp
);
2062 ifnet_increment_generation(ifnet_t interface
)
2064 OSIncrementAtomic(&interface
->if_generation
);
2068 ifnet_get_generation(ifnet_t interface
)
2070 return (interface
->if_generation
);
2074 ifnet_remove_from_ordered_list(struct ifnet
*ifp
)
2076 ifnet_head_assert_exclusive();
2079 TAILQ_REMOVE(&ifnet_ordered_head
, ifp
, if_ordered_link
);
2080 ifp
->if_ordered_link
.tqe_next
= NULL
;
2081 ifp
->if_ordered_link
.tqe_prev
= NULL
;
2083 // Update ordered count
2084 VERIFY(if_ordered_count
> 0);
2089 ifnet_reset_order(u_int32_t
*ordered_indices
, u_int32_t count
)
2091 struct ifnet
*ifp
= NULL
;
2094 ifnet_head_lock_exclusive();
2095 for (u_int32_t order_index
= 0; order_index
< count
; order_index
++) {
2096 if (ordered_indices
[order_index
] == IFSCOPE_NONE
||
2097 ordered_indices
[order_index
] > (uint32_t)if_index
) {
2103 // Flush current ordered list
2104 for (ifp
= TAILQ_FIRST(&ifnet_ordered_head
); ifp
!= NULL
;
2105 ifp
= TAILQ_FIRST(&ifnet_ordered_head
)) {
2106 ifnet_lock_exclusive(ifp
);
2107 ifnet_remove_from_ordered_list(ifp
);
2108 ifnet_lock_done(ifp
);
2111 VERIFY(if_ordered_count
== 0);
2113 for (u_int32_t order_index
= 0; order_index
< count
; order_index
++) {
2114 u_int32_t interface_index
= ordered_indices
[order_index
];
2115 ifp
= ifindex2ifnet
[interface_index
];
2119 ifnet_lock_exclusive(ifp
);
2120 TAILQ_INSERT_TAIL(&ifnet_ordered_head
, ifp
, if_ordered_link
);
2121 ifnet_lock_done(ifp
);
2127 necp_update_all_clients();
2133 if_set_qosmarking_mode(struct ifnet
*ifp
, u_int32_t mode
)
2136 u_int32_t old_mode
= ifp
->if_qosmarking_mode
;
2139 case IFRTYPE_QOSMARKING_MODE_NONE
:
2140 ifp
->if_qosmarking_mode
= IFRTYPE_QOSMARKING_MODE_NONE
;
2141 ifp
->if_eflags
&= ~IFEF_QOSMARKING_CAPABLE
;
2143 case IFRTYPE_QOSMARKING_FASTLANE
:
2144 ifp
->if_qosmarking_mode
= IFRTYPE_QOSMARKING_FASTLANE
;
2145 ifp
->if_eflags
|= IFEF_QOSMARKING_CAPABLE
;
2146 if (net_qos_policy_capable_enabled
!= 0)
2147 ifp
->if_eflags
|= IFEF_QOSMARKING_ENABLED
;
2153 if (error
== 0 && old_mode
!= ifp
->if_qosmarking_mode
) {
2154 dlil_post_msg(ifp
, KEV_DL_SUBCLASS
, KEV_DL_QOS_MODE_CHANGED
,
2155 NULL
, sizeof(struct kev_dl_rrc_state
));
2161 static __attribute__((noinline
)) int
2162 ifioctl_iforder(u_long cmd
, caddr_t data
)
2165 u_int32_t
*ordered_indices
= NULL
;
2171 case SIOCSIFORDER
: { /* struct if_order */
2172 struct if_order
*ifo
= (struct if_order
*)(void *)data
;
2174 if (ifo
->ifo_count
> (u_int32_t
)if_index
) {
2179 size_t length
= (ifo
->ifo_count
* sizeof(u_int32_t
));
2181 if (ifo
->ifo_ordered_indices
== USER_ADDR_NULL
) {
2185 ordered_indices
= _MALLOC(length
, M_NECP
, M_WAITOK
);
2186 if (ordered_indices
== NULL
) {
2191 error
= copyin(ifo
->ifo_ordered_indices
,
2192 ordered_indices
, length
);
2197 /* ordered_indices should not contain duplicates */
2198 bool found_duplicate
= FALSE
;
2199 for (uint32_t i
= 0; i
< (ifo
->ifo_count
- 1) && !found_duplicate
; i
++){
2200 for (uint32_t j
= i
+ 1; j
< ifo
->ifo_count
&& !found_duplicate
; j
++){
2201 if (ordered_indices
[j
] == ordered_indices
[i
]){
2203 found_duplicate
= TRUE
;
2208 if (found_duplicate
) {
2213 error
= ifnet_reset_order(ordered_indices
, ifo
->ifo_count
);
2218 case SIOCGIFORDER
: { /* struct if_order */
2219 struct if_order
*ifo
= (struct if_order
*)(void *)data
;
2220 u_int32_t ordered_count
= *((volatile u_int32_t
*)&if_ordered_count
);
2222 if (ifo
->ifo_count
== 0 ||
2223 ordered_count
== 0) {
2225 } else if (ifo
->ifo_ordered_indices
!= USER_ADDR_NULL
) {
2226 u_int32_t count_to_copy
=
2227 MIN(ordered_count
, ifo
->ifo_count
);
2228 size_t length
= (count_to_copy
* sizeof(u_int32_t
));
2229 struct ifnet
*ifp
= NULL
;
2230 u_int32_t cursor
= 0;
2232 ordered_indices
= _MALLOC(length
, M_NECP
, M_WAITOK
| M_ZERO
);
2233 if (ordered_indices
== NULL
) {
2238 ifnet_head_lock_shared();
2239 TAILQ_FOREACH(ifp
, &ifnet_ordered_head
, if_ordered_link
) {
2240 if (cursor
>= count_to_copy
||
2241 cursor
>= if_ordered_count
) {
2244 ordered_indices
[cursor
] = ifp
->if_index
;
2249 /* We might have parsed less than the original length
2250 * because the list could have changed.
2252 length
= cursor
* sizeof(u_int32_t
);
2253 ifo
->ifo_count
= cursor
;
2254 error
= copyout(ordered_indices
,
2255 ifo
->ifo_ordered_indices
, length
);
2268 if (ordered_indices
!= NULL
) {
2269 _FREE(ordered_indices
, M_NECP
);
2275 static __attribute__((noinline
)) int
2276 ifioctl_netsignature(struct ifnet
*ifp
, u_long cmd
, caddr_t data
)
2278 struct if_nsreq
*ifnsr
= (struct if_nsreq
*)(void *)data
;
2282 VERIFY(ifp
!= NULL
);
2285 case SIOCSIFNETSIGNATURE
: /* struct if_nsreq */
2286 if (ifnsr
->ifnsr_len
> sizeof (ifnsr
->ifnsr_data
)) {
2290 bcopy(&ifnsr
->ifnsr_flags
, &flags
, sizeof (flags
));
2291 error
= ifnet_set_netsignature(ifp
, ifnsr
->ifnsr_family
,
2292 ifnsr
->ifnsr_len
, flags
, ifnsr
->ifnsr_data
);
2295 case SIOCGIFNETSIGNATURE
: /* struct if_nsreq */
2296 ifnsr
->ifnsr_len
= sizeof (ifnsr
->ifnsr_data
);
2297 error
= ifnet_get_netsignature(ifp
, ifnsr
->ifnsr_family
,
2298 &ifnsr
->ifnsr_len
, &flags
, ifnsr
->ifnsr_data
);
2300 bcopy(&flags
, &ifnsr
->ifnsr_flags
, sizeof (flags
));
2302 ifnsr
->ifnsr_len
= 0;
2314 static __attribute__((noinline
)) int
2315 ifioctl_nat64prefix(struct ifnet
*ifp
, u_long cmd
, caddr_t data
)
2317 struct if_nat64req
*ifnat64
= (struct if_nat64req
*)(void *)data
;
2320 VERIFY(ifp
!= NULL
);
2323 case SIOCSIFNAT64PREFIX
: /* struct if_nat64req */
2324 error
= ifnet_set_nat64prefix(ifp
, ifnat64
->ifnat64_prefixes
);
2327 case SIOCGIFNAT64PREFIX
: /* struct if_nat64req */
2328 error
= ifnet_get_nat64prefix(ifp
, ifnat64
->ifnat64_prefixes
);
2342 ifioctl_get_protolist(struct ifnet
*ifp
, u_int32_t
* ret_count
,
2345 u_int32_t actual_count
;
2348 u_int32_t
*list
= NULL
;
2350 /* find out how many */
2351 count
= if_get_protolist(ifp
, NULL
, 0);
2352 if (ifpl
== USER_ADDR_NULL
) {
2356 /* copy out how many there's space for */
2357 if (*ret_count
< count
) {
2363 list
= _MALLOC(count
* sizeof(*list
), M_TEMP
, M_WAITOK
);
2368 actual_count
= if_get_protolist(ifp
, list
, count
);
2369 if (actual_count
< count
) {
2370 count
= actual_count
;
2373 error
= copyout((caddr_t
)list
, ifpl
, count
* sizeof(*list
));
2378 if_free_protolist(list
);
2384 static __attribute__((noinline
)) int
2385 ifioctl_protolist(struct ifnet
*ifp
, u_long cmd
, caddr_t data
)
2390 case SIOCGIFPROTOLIST32
: { /* struct if_protolistreq32 */
2391 struct if_protolistreq32 ifpl
;
2393 bcopy(data
, &ifpl
, sizeof(ifpl
));
2394 if (ifpl
.ifpl_reserved
!= 0) {
2398 error
= ifioctl_get_protolist(ifp
, &ifpl
.ifpl_count
,
2399 CAST_USER_ADDR_T(ifpl
.ifpl_list
));
2400 bcopy(&ifpl
, data
, sizeof(ifpl
));
2403 case SIOCGIFPROTOLIST64
: { /* struct if_protolistreq64 */
2404 struct if_protolistreq64 ifpl
;
2406 bcopy(data
, &ifpl
, sizeof(ifpl
));
2407 if (ifpl
.ifpl_reserved
!= 0) {
2411 error
= ifioctl_get_protolist(ifp
, &ifpl
.ifpl_count
,
2413 bcopy(&ifpl
, data
, sizeof(ifpl
));
2425 * List the ioctl()s we can perform on restricted INTCOPROC interfaces.
2428 ifioctl_restrict_intcoproc(unsigned long cmd
, const char *ifname
,
2429 struct ifnet
*ifp
, struct proc
*p
)
2432 if (intcoproc_unrestricted
== TRUE
) {
2435 if (proc_pid(p
) == 0) {
2439 ifp
= ifunit(ifname
);
2444 if (!IFNET_IS_INTCOPROC(ifp
)) {
2448 case SIOCGIFBRDADDR
:
2459 case SIOCGIFFUNCTIONALTYPE
:
2460 case SIOCGIFPSRCADDR
:
2461 case SIOCGIFPDSTADDR
:
2462 case SIOCGIFGENERIC
:
2466 case SIOCGIFWAKEFLAGS
:
2467 case SIOCGIFGETRTREFCNT
:
2468 case SIOCGIFOPPORTUNISTIC
:
2469 case SIOCGIFLINKQUALITYMETRIC
:
2471 case SIOCGIFDELEGATE
:
2472 case SIOCGIFEXPENSIVE
:
2473 case SIOCGIFINTERFACESTATE
:
2474 case SIOCGIFPROBECONNECTIVITY
:
2475 case SIOCGIFTIMESTAMPENABLED
:
2477 case SIOCGQOSMARKINGMODE
:
2478 case SIOCGQOSMARKINGENABLED
:
2479 case SIOCGIFLOWINTERNET
:
2481 case SIOCGIFMEDIA32
:
2482 case SIOCGIFMEDIA64
:
2484 case SIOCGIFLINKPARAMS
:
2485 case SIOCGIFQUEUESTATS
:
2486 case SIOCGIFTHROTTLE
:
2487 case SIOCGIFAGENTIDS32
:
2488 case SIOCGIFAGENTIDS64
:
2489 case SIOCGIFNETSIGNATURE
:
2490 case SIOCGIFINFO_IN6
:
2491 case SIOCGIFAFLAG_IN6
:
2492 case SIOCGNBRINFO_IN6
:
2493 case SIOCGIFALIFETIME_IN6
:
2494 case SIOCGIFNETMASK_IN6
:
2495 case SIOCGIFPROTOLIST32
:
2496 case SIOCGIFPROTOLIST64
:
2499 #if (DEBUG || DEVELOPMENT)
2500 printf("%s: cmd 0x%lx not allowed (pid %u)\n",
2501 __func__
, cmd
, proc_pid(p
));
2511 * Most of the routines called to handle the ioctls would end up being
2512 * tail-call optimized, which unfortunately causes this routine to
2513 * consume too much stack space; this is the reason for the "noinline"
2514 * attribute used on those routines.
2517 ifioctl(struct socket
*so
, u_long cmd
, caddr_t data
, struct proc
*p
)
2519 char ifname
[IFNAMSIZ
+ 1];
2520 struct ifnet
*ifp
= NULL
;
2521 struct ifstat
*ifs
= NULL
;
2524 bzero(ifname
, sizeof (ifname
));
2527 * ioctls which don't require ifp, or ifreq ioctls
2530 case OSIOCGIFCONF32
: /* struct ifconf32 */
2531 case SIOCGIFCONF32
: /* struct ifconf32 */
2532 case SIOCGIFCONF64
: /* struct ifconf64 */
2533 case OSIOCGIFCONF64
: /* struct ifconf64 */
2534 error
= ifioctl_ifconf(cmd
, data
);
2537 case SIOCIFGCLONERS32
: /* struct if_clonereq32 */
2538 case SIOCIFGCLONERS64
: /* struct if_clonereq64 */
2539 error
= ifioctl_ifclone(cmd
, data
);
2542 case SIOCGIFAGENTDATA32
: /* struct netagent_req32 */
2543 case SIOCGIFAGENTDATA64
: /* struct netagent_req64 */
2544 case SIOCGIFAGENTLIST32
: /* struct netagentlist_req32 */
2545 case SIOCGIFAGENTLIST64
: /* struct netagentlist_req64 */
2546 error
= netagent_ioctl(cmd
, data
);
2549 case SIOCSIFORDER
: /* struct if_order */
2550 case SIOCGIFORDER
: /* struct if_order */
2551 error
= ifioctl_iforder(cmd
, data
);
2554 case SIOCSIFDSTADDR
: /* struct ifreq */
2555 case SIOCSIFADDR
: /* struct ifreq */
2556 case SIOCSIFBRDADDR
: /* struct ifreq */
2557 case SIOCSIFNETMASK
: /* struct ifreq */
2558 case OSIOCGIFADDR
: /* struct ifreq */
2559 case OSIOCGIFDSTADDR
: /* struct ifreq */
2560 case OSIOCGIFBRDADDR
: /* struct ifreq */
2561 case OSIOCGIFNETMASK
: /* struct ifreq */
2562 case SIOCSIFKPI
: /* struct ifreq */
2563 if (so
->so_proto
== NULL
) {
2568 case SIOCIFCREATE
: /* struct ifreq */
2569 case SIOCIFCREATE2
: /* struct ifreq */
2570 case SIOCIFDESTROY
: /* struct ifreq */
2571 case SIOCGIFFLAGS
: /* struct ifreq */
2572 case SIOCGIFEFLAGS
: /* struct ifreq */
2573 case SIOCGIFCAP
: /* struct ifreq */
2575 case SIOCGIFMAC
: /* struct ifreq */
2576 case SIOCSIFMAC
: /* struct ifreq */
2577 #endif /* CONFIG_MACF_NET */
2578 case SIOCGIFMETRIC
: /* struct ifreq */
2579 case SIOCGIFMTU
: /* struct ifreq */
2580 case SIOCGIFPHYS
: /* struct ifreq */
2581 case SIOCSIFFLAGS
: /* struct ifreq */
2582 case SIOCSIFCAP
: /* struct ifreq */
2583 case SIOCSIFMETRIC
: /* struct ifreq */
2584 case SIOCSIFPHYS
: /* struct ifreq */
2585 case SIOCSIFMTU
: /* struct ifreq */
2586 case SIOCADDMULTI
: /* struct ifreq */
2587 case SIOCDELMULTI
: /* struct ifreq */
2588 case SIOCDIFPHYADDR
: /* struct ifreq */
2589 case SIOCSIFMEDIA
: /* struct ifreq */
2590 case SIOCSIFGENERIC
: /* struct ifreq */
2591 case SIOCSIFLLADDR
: /* struct ifreq */
2592 case SIOCSIFALTMTU
: /* struct ifreq */
2593 case SIOCSIFVLAN
: /* struct ifreq */
2594 case SIOCSIFBOND
: /* struct ifreq */
2595 case SIOCGIFLLADDR
: /* struct ifreq */
2596 case SIOCGIFTYPE
: /* struct ifreq */
2597 case SIOCGIFFUNCTIONALTYPE
: /* struct ifreq */
2598 case SIOCGIFPSRCADDR
: /* struct ifreq */
2599 case SIOCGIFPDSTADDR
: /* struct ifreq */
2600 case SIOCGIFGENERIC
: /* struct ifreq */
2601 case SIOCGIFDEVMTU
: /* struct ifreq */
2602 case SIOCGIFVLAN
: /* struct ifreq */
2603 case SIOCGIFBOND
: /* struct ifreq */
2604 case SIOCGIFWAKEFLAGS
: /* struct ifreq */
2605 case SIOCGIFGETRTREFCNT
: /* struct ifreq */
2606 case SIOCSIFOPPORTUNISTIC
: /* struct ifreq */
2607 case SIOCGIFOPPORTUNISTIC
: /* struct ifreq */
2608 case SIOCGIFLINKQUALITYMETRIC
: /* struct ifreq */
2609 case SIOCSIFLOG
: /* struct ifreq */
2610 case SIOCGIFLOG
: /* struct ifreq */
2611 case SIOCGIFDELEGATE
: /* struct ifreq */
2612 case SIOCGIFEXPENSIVE
: /* struct ifreq */
2613 case SIOCSIFEXPENSIVE
: /* struct ifreq */
2614 case SIOCSIF2KCL
: /* struct ifreq */
2615 case SIOCGIF2KCL
: /* struct ifreq */
2616 case SIOCSIFINTERFACESTATE
: /* struct ifreq */
2617 case SIOCGIFINTERFACESTATE
: /* struct ifreq */
2618 case SIOCSIFPROBECONNECTIVITY
: /* struct ifreq */
2619 case SIOCGIFPROBECONNECTIVITY
: /* struct ifreq */
2620 case SIOCGSTARTDELAY
: /* struct ifreq */
2621 case SIOCSIFTIMESTAMPENABLE
: /* struct ifreq */
2622 case SIOCSIFTIMESTAMPDISABLE
: /* struct ifreq */
2623 case SIOCGIFTIMESTAMPENABLED
: /* struct ifreq */
2624 #if (DEBUG || DEVELOPMENT)
2625 case SIOCSIFDISABLEOUTPUT
: /* struct ifreq */
2626 #endif /* (DEBUG || DEVELOPMENT) */
2627 case SIOCGECNMODE
: /* struct ifreq */
2629 case SIOCSQOSMARKINGMODE
: /* struct ifreq */
2630 case SIOCSQOSMARKINGENABLED
: /* struct ifreq */
2631 case SIOCGQOSMARKINGMODE
: /* struct ifreq */
2632 case SIOCGQOSMARKINGENABLED
: /* struct ifreq */
2633 case SIOCSIFLOWINTERNET
: /* struct ifreq */
2634 case SIOCGIFLOWINTERNET
: /* struct ifreq */
2635 { /* struct ifreq */
2637 bcopy(data
, &ifr
, sizeof (ifr
));
2638 ifr
.ifr_name
[IFNAMSIZ
- 1] = '\0';
2639 bcopy(&ifr
.ifr_name
, ifname
, IFNAMSIZ
);
2640 if (ifioctl_restrict_intcoproc(cmd
, ifname
, NULL
, p
) == true) {
2644 error
= ifioctl_ifreq(so
, cmd
, &ifr
, p
);
2645 bcopy(&ifr
, data
, sizeof (ifr
));
2651 * ioctls which require ifp. Note that we acquire dlil_ifnet_lock
2652 * here to ensure that the ifnet, if found, has been fully attached.
2656 case SIOCSIFPHYADDR
: /* struct {if,in_}aliasreq */
2657 bcopy(((struct in_aliasreq
*)(void *)data
)->ifra_name
,
2659 ifp
= ifunit(ifname
);
2663 case SIOCSIFPHYADDR_IN6_32
: /* struct in6_aliasreq_32 */
2664 bcopy(((struct in6_aliasreq_32
*)(void *)data
)->ifra_name
,
2666 ifp
= ifunit(ifname
);
2669 case SIOCSIFPHYADDR_IN6_64
: /* struct in6_aliasreq_64 */
2670 bcopy(((struct in6_aliasreq_64
*)(void *)data
)->ifra_name
,
2672 ifp
= ifunit(ifname
);
2676 case SIOCGIFSTATUS
: /* struct ifstat */
2677 ifs
= _MALLOC(sizeof (*ifs
), M_DEVBUF
, M_WAITOK
);
2683 bcopy(data
, ifs
, sizeof (*ifs
));
2684 ifs
->ifs_name
[IFNAMSIZ
- 1] = '\0';
2685 bcopy(ifs
->ifs_name
, ifname
, IFNAMSIZ
);
2686 ifp
= ifunit(ifname
);
2689 case SIOCGIFMEDIA32
: /* struct ifmediareq32 */
2690 bcopy(((struct ifmediareq32
*)(void *)data
)->ifm_name
,
2692 ifp
= ifunit(ifname
);
2695 case SIOCGIFMEDIA64
: /* struct ifmediareq64 */
2696 bcopy(((struct ifmediareq64
*)(void *)data
)->ifm_name
,
2698 ifp
= ifunit(ifname
);
2701 case SIOCSIFDESC
: /* struct if_descreq */
2702 case SIOCGIFDESC
: /* struct if_descreq */
2703 bcopy(((struct if_descreq
*)(void *)data
)->ifdr_name
,
2705 ifp
= ifunit(ifname
);
2708 case SIOCSIFLINKPARAMS
: /* struct if_linkparamsreq */
2709 case SIOCGIFLINKPARAMS
: /* struct if_linkparamsreq */
2710 bcopy(((struct if_linkparamsreq
*)(void *)data
)->iflpr_name
,
2712 ifp
= ifunit(ifname
);
2715 case SIOCGIFQUEUESTATS
: /* struct if_qstatsreq */
2716 bcopy(((struct if_qstatsreq
*)(void *)data
)->ifqr_name
,
2718 ifp
= ifunit(ifname
);
2721 case SIOCSIFTHROTTLE
: /* struct if_throttlereq */
2722 case SIOCGIFTHROTTLE
: /* struct if_throttlereq */
2723 bcopy(((struct if_throttlereq
*)(void *)data
)->ifthr_name
,
2725 ifp
= ifunit(ifname
);
2728 case SIOCAIFAGENTID
: /* struct if_agentidreq */
2729 case SIOCDIFAGENTID
: /* struct if_agentidreq */
2730 case SIOCGIFAGENTIDS32
: /* struct if_agentidsreq32 */
2731 case SIOCGIFAGENTIDS64
: /* struct if_agentidsreq64 */
2732 bcopy(((struct if_agentidreq
*)(void *)data
)->ifar_name
,
2734 ifp
= ifunit(ifname
);
2737 case SIOCSIFNETSIGNATURE
: /* struct if_nsreq */
2738 case SIOCGIFNETSIGNATURE
: /* struct if_nsreq */
2739 bcopy(((struct if_nsreq
*)(void *)data
)->ifnsr_name
,
2741 ifp
= ifunit(ifname
);
2744 case SIOCGIFPROTOLIST32
: /* struct if_protolistreq32 */
2745 case SIOCGIFPROTOLIST64
: /* struct if_protolistreq64 */
2746 bcopy(((struct if_protolistreq
*)(void *)data
)->ifpl_name
,
2748 ifp
= ifunit(ifname
);
2752 * This is a bad assumption, but the code seems to
2753 * have been doing this in the past; caveat emptor.
2755 bcopy(((struct ifreq
*)(void *)data
)->ifr_name
,
2757 ifp
= ifunit(ifname
);
2767 if (ifioctl_restrict_intcoproc(cmd
, NULL
, ifp
, p
) == true) {
2772 case SIOCSIFPHYADDR
: /* struct {if,in_}aliasreq */
2774 case SIOCSIFPHYADDR_IN6_32
: /* struct in6_aliasreq_32 */
2775 case SIOCSIFPHYADDR_IN6_64
: /* struct in6_aliasreq_64 */
2777 error
= proc_suser(p
);
2781 error
= ifnet_ioctl(ifp
, SOCK_DOM(so
), cmd
, data
);
2785 ifnet_touch_lastchange(ifp
);
2788 case SIOCGIFSTATUS
: /* struct ifstat */
2789 VERIFY(ifs
!= NULL
);
2790 ifs
->ascii
[0] = '\0';
2792 error
= ifnet_ioctl(ifp
, SOCK_DOM(so
), cmd
, (caddr_t
)ifs
);
2794 bcopy(ifs
, data
, sizeof (*ifs
));
2797 case SIOCGIFMEDIA32
: /* struct ifmediareq32 */
2798 case SIOCGIFMEDIA64
: /* struct ifmediareq64 */
2799 error
= ifnet_ioctl(ifp
, SOCK_DOM(so
), cmd
, data
);
2802 case SIOCSIFDESC
: /* struct if_descreq */
2803 case SIOCGIFDESC
: /* struct if_descreq */
2804 error
= ifioctl_ifdesc(ifp
, cmd
, data
, p
);
2807 case SIOCSIFLINKPARAMS
: /* struct if_linkparamsreq */
2808 case SIOCGIFLINKPARAMS
: /* struct if_linkparamsreq */
2809 error
= ifioctl_linkparams(ifp
, cmd
, data
, p
);
2812 case SIOCGIFQUEUESTATS
: /* struct if_qstatsreq */
2813 error
= ifioctl_qstats(ifp
, cmd
, data
);
2816 case SIOCSIFTHROTTLE
: /* struct if_throttlereq */
2817 case SIOCGIFTHROTTLE
: /* struct if_throttlereq */
2818 error
= ifioctl_throttle(ifp
, cmd
, data
, p
);
2821 case SIOCAIFAGENTID
: /* struct if_agentidreq */
2822 case SIOCDIFAGENTID
: /* struct if_agentidreq */
2823 case SIOCGIFAGENTIDS32
: /* struct if_agentidsreq32 */
2824 case SIOCGIFAGENTIDS64
: /* struct if_agentidsreq64 */
2825 error
= ifioctl_netagent(ifp
, cmd
, data
, p
);
2828 case SIOCSIFNETSIGNATURE
: /* struct if_nsreq */
2829 case SIOCGIFNETSIGNATURE
: /* struct if_nsreq */
2830 error
= ifioctl_netsignature(ifp
, cmd
, data
);
2834 case SIOCSIFNAT64PREFIX
: /* struct if_nsreq */
2835 case SIOCGIFNAT64PREFIX
: /* struct if_nsreq */
2836 error
= ifioctl_nat64prefix(ifp
, cmd
, data
);
2840 case SIOCGIFPROTOLIST32
: /* struct if_protolistreq32 */
2841 case SIOCGIFPROTOLIST64
: /* struct if_protolistreq64 */
2842 error
= ifioctl_protolist(ifp
, cmd
, data
);
2846 if (so
->so_proto
== NULL
) {
2852 error
= ((*so
->so_proto
->pr_usrreqs
->pru_control
)(so
, cmd
,
2854 socket_unlock(so
, 1);
2856 if (error
== EOPNOTSUPP
|| error
== ENOTSUP
) {
2857 error
= ifnet_ioctl(ifp
, SOCK_DOM(so
), cmd
, data
);
2864 _FREE(ifs
, M_DEVBUF
);
2867 if (ifname
[0] == '\0')
2868 (void) snprintf(ifname
, sizeof (ifname
), "%s",
2870 else if (ifp
!= NULL
)
2871 (void) snprintf(ifname
, sizeof (ifname
), "%s",
2875 printf("%s[%s,%d]: ifp %s cmd 0x%08lx (%c%c [%lu] "
2876 "%c %lu) error %d\n", __func__
,
2877 proc_name_address(p
), proc_pid(p
),
2878 ifname
, cmd
, (cmd
& IOC_IN
) ? 'I' : ' ',
2879 (cmd
& IOC_OUT
) ? 'O' : ' ', IOCPARM_LEN(cmd
),
2880 (char)IOCGROUP(cmd
), cmd
& 0xff, error
);
2881 } else if (if_verbose
> 1) {
2882 printf("%s[%s,%d]: ifp %s cmd 0x%08lx (%c%c [%lu] "
2883 "%c %lu) OK\n", __func__
,
2884 proc_name_address(p
), proc_pid(p
),
2885 ifname
, cmd
, (cmd
& IOC_IN
) ? 'I' : ' ',
2886 (cmd
& IOC_OUT
) ? 'O' : ' ', IOCPARM_LEN(cmd
),
2887 (char)IOCGROUP(cmd
), cmd
& 0xff);
2894 static __attribute__((noinline
)) int
2895 ifioctl_ifreq(struct socket
*so
, u_long cmd
, struct ifreq
*ifr
, struct proc
*p
)
2900 struct kev_msg ev_msg
;
2901 struct net_event_data ev_data
;
2903 bzero(&ev_data
, sizeof (struct net_event_data
));
2904 bzero(&ev_msg
, sizeof (struct kev_msg
));
2909 error
= proc_suser(p
);
2912 return (if_clone_create(ifr
->ifr_name
, sizeof(ifr
->ifr_name
),
2913 cmd
== SIOCIFCREATE2
? ifr
->ifr_data
: NULL
));
2915 error
= proc_suser(p
);
2918 return (if_clone_destroy(ifr
->ifr_name
));
2922 * ioctls which require ifp. Note that we acquire dlil_ifnet_lock
2923 * here to ensure that the ifnet, if found, has been fully attached.
2926 ifp
= ifunit(ifr
->ifr_name
);
2934 ifnet_lock_shared(ifp
);
2935 ifr
->ifr_flags
= ifp
->if_flags
;
2936 ifnet_lock_done(ifp
);
2940 ifnet_lock_shared(ifp
);
2941 ifr
->ifr_eflags
= ifp
->if_eflags
;
2942 ifnet_lock_done(ifp
);
2946 ifnet_lock_shared(ifp
);
2947 ifr
->ifr_reqcap
= ifp
->if_capabilities
;
2948 ifr
->ifr_curcap
= ifp
->if_capenable
;
2949 ifnet_lock_done(ifp
);
2954 error
= mac_ifnet_label_get(kauth_cred_get(), ifr
, ifp
);
2958 error
= mac_ifnet_label_set(kauth_cred_get(), ifr
, ifp
);
2960 #endif /* CONFIG_MACF_NET */
2963 ifnet_lock_shared(ifp
);
2964 ifr
->ifr_metric
= ifp
->if_metric
;
2965 ifnet_lock_done(ifp
);
2969 ifnet_lock_shared(ifp
);
2970 ifr
->ifr_mtu
= ifp
->if_mtu
;
2971 ifnet_lock_done(ifp
);
2975 ifnet_lock_shared(ifp
);
2976 ifr
->ifr_phys
= ifp
->if_physical
;
2977 ifnet_lock_done(ifp
);
2981 error
= proc_suser(p
);
2985 (void) ifnet_set_flags(ifp
, ifr
->ifr_flags
,
2986 (u_int16_t
)~IFF_CANTCHANGE
);
2989 * Note that we intentionally ignore any error from below
2990 * for the SIOCSIFFLAGS case.
2992 (void) ifnet_ioctl(ifp
, SOCK_DOM(so
), cmd
, (caddr_t
)ifr
);
2995 * Send the event even upon error from the driver because
2996 * we changed the flags.
2998 dlil_post_sifflags_msg(ifp
);
3000 ifnet_touch_lastchange(ifp
);
3004 error
= proc_suser(p
);
3008 if ((ifr
->ifr_reqcap
& ~ifp
->if_capabilities
)) {
3012 error
= ifnet_ioctl(ifp
, SOCK_DOM(so
), cmd
, (caddr_t
)ifr
);
3014 ifnet_touch_lastchange(ifp
);
3018 error
= proc_suser(p
);
3022 ifp
->if_metric
= ifr
->ifr_metric
;
3024 ev_msg
.vendor_code
= KEV_VENDOR_APPLE
;
3025 ev_msg
.kev_class
= KEV_NETWORK_CLASS
;
3026 ev_msg
.kev_subclass
= KEV_DL_SUBCLASS
;
3028 ev_msg
.event_code
= KEV_DL_SIFMETRICS
;
3029 strlcpy(&ev_data
.if_name
[0], ifp
->if_name
, IFNAMSIZ
);
3030 ev_data
.if_family
= ifp
->if_family
;
3031 ev_data
.if_unit
= (u_int32_t
) ifp
->if_unit
;
3032 ev_msg
.dv
[0].data_length
= sizeof(struct net_event_data
);
3033 ev_msg
.dv
[0].data_ptr
= &ev_data
;
3035 ev_msg
.dv
[1].data_length
= 0;
3036 dlil_post_complete_msg(ifp
, &ev_msg
);
3038 ifnet_touch_lastchange(ifp
);
3042 error
= proc_suser(p
);
3046 error
= ifnet_ioctl(ifp
, SOCK_DOM(so
), cmd
, (caddr_t
)ifr
);
3050 ev_msg
.vendor_code
= KEV_VENDOR_APPLE
;
3051 ev_msg
.kev_class
= KEV_NETWORK_CLASS
;
3052 ev_msg
.kev_subclass
= KEV_DL_SUBCLASS
;
3054 ev_msg
.event_code
= KEV_DL_SIFPHYS
;
3055 strlcpy(&ev_data
.if_name
[0], ifp
->if_name
, IFNAMSIZ
);
3056 ev_data
.if_family
= ifp
->if_family
;
3057 ev_data
.if_unit
= (u_int32_t
) ifp
->if_unit
;
3058 ev_msg
.dv
[0].data_length
= sizeof(struct net_event_data
);
3059 ev_msg
.dv
[0].data_ptr
= &ev_data
;
3060 ev_msg
.dv
[1].data_length
= 0;
3061 dlil_post_complete_msg(ifp
, &ev_msg
);
3063 ifnet_touch_lastchange(ifp
);
3067 u_int32_t oldmtu
= ifp
->if_mtu
;
3068 struct ifclassq
*ifq
= &ifp
->if_snd
;
3070 error
= proc_suser(p
);
3074 if (ifp
->if_ioctl
== NULL
) {
3078 if (ifr
->ifr_mtu
< IF_MINMTU
|| ifr
->ifr_mtu
> IF_MAXMTU
) {
3082 error
= ifnet_ioctl(ifp
, SOCK_DOM(so
), cmd
, (caddr_t
)ifr
);
3086 ev_msg
.vendor_code
= KEV_VENDOR_APPLE
;
3087 ev_msg
.kev_class
= KEV_NETWORK_CLASS
;
3088 ev_msg
.kev_subclass
= KEV_DL_SUBCLASS
;
3090 ev_msg
.event_code
= KEV_DL_SIFMTU
;
3091 strlcpy(&ev_data
.if_name
[0], ifp
->if_name
, IFNAMSIZ
);
3092 ev_data
.if_family
= ifp
->if_family
;
3093 ev_data
.if_unit
= (u_int32_t
) ifp
->if_unit
;
3094 ev_msg
.dv
[0].data_length
= sizeof(struct net_event_data
);
3095 ev_msg
.dv
[0].data_ptr
= &ev_data
;
3096 ev_msg
.dv
[1].data_length
= 0;
3097 dlil_post_complete_msg(ifp
, &ev_msg
);
3099 ifnet_touch_lastchange(ifp
);
3103 * If the link MTU changed, do network layer specific procedure
3104 * and update all route entries associated with the interface,
3105 * so that their MTU metric gets updated.
3107 if (ifp
->if_mtu
!= oldmtu
) {
3108 if_rtmtu_update(ifp
);
3112 /* Inform all transmit queues about the new MTU */
3114 ifnet_update_sndq(ifq
, CLASSQ_EV_LINK_MTU
);
3122 error
= proc_suser(p
);
3126 /* Don't allow group membership on non-multicast interfaces. */
3127 if ((ifp
->if_flags
& IFF_MULTICAST
) == 0) {
3132 /* Don't let users screw up protocols' entries. */
3133 if (ifr
->ifr_addr
.sa_family
!= AF_UNSPEC
&&
3134 ifr
->ifr_addr
.sa_family
!= AF_LINK
) {
3140 * User is permitted to anonymously join a particular link
3141 * multicast group via SIOCADDMULTI. Subsequent join requested
3142 * for the same record which has an outstanding refcnt from a
3143 * past if_addmulti_anon() will not result in EADDRINUSE error
3144 * (unlike other BSDs.) Anonymously leaving a group is also
3145 * allowed only as long as there is an outstanding refcnt held
3146 * by a previous anonymous request, or else ENOENT (even if the
3147 * link-layer multicast membership exists for a network-layer
3150 if (cmd
== SIOCADDMULTI
) {
3151 error
= if_addmulti_anon(ifp
, &ifr
->ifr_addr
, NULL
);
3152 ev_msg
.event_code
= KEV_DL_ADDMULTI
;
3154 error
= if_delmulti_anon(ifp
, &ifr
->ifr_addr
);
3155 ev_msg
.event_code
= KEV_DL_DELMULTI
;
3160 ev_msg
.vendor_code
= KEV_VENDOR_APPLE
;
3161 ev_msg
.kev_class
= KEV_NETWORK_CLASS
;
3162 ev_msg
.kev_subclass
= KEV_DL_SUBCLASS
;
3163 strlcpy(&ev_data
.if_name
[0], ifp
->if_name
, IFNAMSIZ
);
3165 ev_data
.if_family
= ifp
->if_family
;
3166 ev_data
.if_unit
= (u_int32_t
) ifp
->if_unit
;
3167 ev_msg
.dv
[0].data_length
= sizeof(struct net_event_data
);
3168 ev_msg
.dv
[0].data_ptr
= &ev_data
;
3169 ev_msg
.dv
[1].data_length
= 0;
3170 dlil_post_complete_msg(ifp
, &ev_msg
);
3172 ifnet_touch_lastchange(ifp
);
3175 case SIOCDIFPHYADDR
:
3177 case SIOCSIFGENERIC
:
3182 error
= proc_suser(p
);
3186 error
= ifnet_ioctl(ifp
, SOCK_DOM(so
), cmd
, (caddr_t
)ifr
);
3190 ifnet_touch_lastchange(ifp
);
3193 case SIOCGIFLLADDR
: {
3194 struct sockaddr_dl
*sdl
= SDL(ifp
->if_lladdr
->ifa_addr
);
3196 if (sdl
->sdl_alen
== 0) {
3197 error
= EADDRNOTAVAIL
;
3200 /* If larger than 14-bytes we'll need another mechanism */
3201 if (sdl
->sdl_alen
> sizeof (ifr
->ifr_addr
.sa_data
)) {
3205 /* Follow the same convention used by SIOCSIFLLADDR */
3206 bzero(&ifr
->ifr_addr
, sizeof (ifr
->ifr_addr
));
3207 ifr
->ifr_addr
.sa_family
= AF_LINK
;
3208 ifr
->ifr_addr
.sa_len
= sdl
->sdl_alen
;
3209 error
= ifnet_guarded_lladdr_copy_bytes(ifp
,
3210 &ifr
->ifr_addr
.sa_data
, sdl
->sdl_alen
);
3215 ifr
->ifr_type
.ift_type
= ifp
->if_type
;
3216 ifr
->ifr_type
.ift_family
= ifp
->if_family
;
3217 ifr
->ifr_type
.ift_subfamily
= ifp
->if_subfamily
;
3220 case SIOCGIFFUNCTIONALTYPE
:
3221 ifr
->ifr_functional_type
= if_functional_type(ifp
, FALSE
);
3224 case SIOCGIFPSRCADDR
:
3225 case SIOCGIFPDSTADDR
:
3226 case SIOCGIFGENERIC
:
3230 error
= ifnet_ioctl(ifp
, SOCK_DOM(so
), cmd
, (caddr_t
)ifr
);
3233 case SIOCGIFWAKEFLAGS
:
3234 ifnet_lock_shared(ifp
);
3235 ifr
->ifr_wake_flags
= ifnet_get_wake_flags(ifp
);
3236 ifnet_lock_done(ifp
);
3239 case SIOCGIFGETRTREFCNT
:
3240 ifnet_lock_shared(ifp
);
3241 ifr
->ifr_route_refcnt
= ifp
->if_route_refcnt
;
3242 ifnet_lock_done(ifp
);
3245 case SIOCSIFOPPORTUNISTIC
:
3246 case SIOCGIFOPPORTUNISTIC
:
3247 error
= ifnet_getset_opportunistic(ifp
, cmd
, ifr
, p
);
3250 case SIOCGIFLINKQUALITYMETRIC
:
3251 ifnet_lock_shared(ifp
);
3252 if ((ifp
->if_interface_state
.valid_bitmask
&
3253 IF_INTERFACE_STATE_LQM_STATE_VALID
)) {
3254 ifr
->ifr_link_quality_metric
=
3255 ifp
->if_interface_state
.lqm_state
;
3256 } else if (IF_FULLY_ATTACHED(ifp
)) {
3257 ifr
->ifr_link_quality_metric
=
3258 IFNET_LQM_THRESH_UNKNOWN
;
3260 ifr
->ifr_link_quality_metric
=
3261 IFNET_LQM_THRESH_OFF
;
3263 ifnet_lock_done(ifp
);
3268 error
= ifnet_getset_log(ifp
, cmd
, ifr
, p
);
3271 case SIOCGIFDELEGATE
:
3272 ifnet_lock_shared(ifp
);
3273 ifr
->ifr_delegated
= ((ifp
->if_delegated
.ifp
!= NULL
) ?
3274 ifp
->if_delegated
.ifp
->if_index
: 0);
3275 ifnet_lock_done(ifp
);
3278 case SIOCGIFEXPENSIVE
:
3279 ifnet_lock_shared(ifp
);
3280 if (ifp
->if_eflags
& IFEF_EXPENSIVE
)
3281 ifr
->ifr_expensive
= 1;
3283 ifr
->ifr_expensive
= 0;
3284 ifnet_lock_done(ifp
);
3287 case SIOCSIFEXPENSIVE
:
3291 if ((error
= priv_check_cred(kauth_cred_get(),
3292 PRIV_NET_INTERFACE_CONTROL
, 0)) != 0)
3294 ifnet_lock_exclusive(ifp
);
3295 if (ifr
->ifr_expensive
)
3296 ifp
->if_eflags
|= IFEF_EXPENSIVE
;
3298 ifp
->if_eflags
&= ~IFEF_EXPENSIVE
;
3299 ifnet_lock_done(ifp
);
3301 * Update the expensive bit in the delegated interface
3304 ifnet_head_lock_shared();
3305 TAILQ_FOREACH(difp
, &ifnet_head
, if_link
) {
3306 ifnet_lock_exclusive(difp
);
3307 if (difp
->if_delegated
.ifp
== ifp
) {
3308 difp
->if_delegated
.expensive
=
3309 ifp
->if_eflags
& IFEF_EXPENSIVE
? 1 : 0;
3312 ifnet_lock_done(difp
);
3319 ifnet_lock_shared(ifp
);
3320 if (ifp
->if_eflags
& IFEF_2KCL
)
3324 ifnet_lock_done(ifp
);
3328 if ((error
= priv_check_cred(kauth_cred_get(),
3329 PRIV_NET_INTERFACE_CONTROL
, 0)) != 0)
3331 ifnet_lock_exclusive(ifp
);
3333 ifp
->if_eflags
|= IFEF_2KCL
;
3335 ifp
->if_eflags
&= ~IFEF_2KCL
;
3336 ifnet_lock_done(ifp
);
3338 case SIOCGSTARTDELAY
:
3339 ifnet_lock_shared(ifp
);
3340 if (ifp
->if_eflags
& IFEF_ENQUEUE_MULTI
) {
3341 ifr
->ifr_start_delay_qlen
=
3342 ifp
->if_start_delay_qlen
;
3343 ifr
->ifr_start_delay_timeout
=
3344 ifp
->if_start_delay_timeout
;
3346 ifr
->ifr_start_delay_qlen
= 0;
3347 ifr
->ifr_start_delay_timeout
= 0;
3349 ifnet_lock_done(ifp
);
3351 case SIOCSIFDSTADDR
:
3353 case SIOCSIFBRDADDR
:
3354 case SIOCSIFNETMASK
:
3356 case OSIOCGIFDSTADDR
:
3357 case OSIOCGIFBRDADDR
:
3358 case OSIOCGIFNETMASK
:
3360 VERIFY(so
->so_proto
!= NULL
);
3362 if (cmd
== SIOCSIFDSTADDR
|| cmd
== SIOCSIFADDR
||
3363 cmd
== SIOCSIFBRDADDR
|| cmd
== SIOCSIFNETMASK
) {
3364 #if BYTE_ORDER != BIG_ENDIAN
3365 if (ifr
->ifr_addr
.sa_family
== 0 &&
3366 ifr
->ifr_addr
.sa_len
< 16) {
3367 ifr
->ifr_addr
.sa_family
= ifr
->ifr_addr
.sa_len
;
3368 ifr
->ifr_addr
.sa_len
= 16;
3371 if (ifr
->ifr_addr
.sa_len
== 0)
3372 ifr
->ifr_addr
.sa_len
= 16;
3374 } else if (cmd
== OSIOCGIFADDR
) {
3375 cmd
= SIOCGIFADDR
; /* struct ifreq */
3376 } else if (cmd
== OSIOCGIFDSTADDR
) {
3377 cmd
= SIOCGIFDSTADDR
; /* struct ifreq */
3378 } else if (cmd
== OSIOCGIFBRDADDR
) {
3379 cmd
= SIOCGIFBRDADDR
; /* struct ifreq */
3380 } else if (cmd
== OSIOCGIFNETMASK
) {
3381 cmd
= SIOCGIFNETMASK
; /* struct ifreq */
3385 error
= ((*so
->so_proto
->pr_usrreqs
->pru_control
)(so
, cmd
,
3386 (caddr_t
)ifr
, ifp
, p
));
3387 socket_unlock(so
, 1);
3391 case OSIOCGIFDSTADDR
:
3392 case OSIOCGIFBRDADDR
:
3393 case OSIOCGIFNETMASK
:
3394 bcopy(&ifr
->ifr_addr
.sa_family
, &ifr
->ifr_addr
,
3398 if (cmd
== SIOCSIFKPI
) {
3399 int temperr
= proc_suser(p
);
3404 if (error
== EOPNOTSUPP
|| error
== ENOTSUP
) {
3405 error
= ifnet_ioctl(ifp
, SOCK_DOM(so
), cmd
,
3410 case SIOCGIFINTERFACESTATE
:
3411 if_get_state(ifp
, &ifr
->ifr_interface_state
);
3414 case SIOCSIFINTERFACESTATE
:
3415 if ((error
= priv_check_cred(kauth_cred_get(),
3416 PRIV_NET_INTERFACE_CONTROL
, 0)) != 0)
3419 error
= if_state_update(ifp
, &ifr
->ifr_interface_state
);
3422 case SIOCSIFPROBECONNECTIVITY
:
3423 if ((error
= priv_check_cred(kauth_cred_get(),
3424 PRIV_NET_INTERFACE_CONTROL
, 0)) != 0)
3426 error
= if_probe_connectivity(ifp
,
3427 ifr
->ifr_probe_connectivity
);
3429 case SIOCGIFPROBECONNECTIVITY
:
3430 if ((error
= priv_check_cred(kauth_cred_get(),
3431 PRIV_NET_INTERFACE_CONTROL
, 0)) != 0)
3433 if (ifp
->if_eflags
& IFEF_PROBE_CONNECTIVITY
)
3434 ifr
->ifr_probe_connectivity
= 1;
3436 ifr
->ifr_probe_connectivity
= 0;
3439 if ((ifp
->if_eflags
& (IFEF_ECN_ENABLE
|IFEF_ECN_DISABLE
)) ==
3441 ifr
->ifr_ecn_mode
= IFRTYPE_ECN_ENABLE
;
3442 else if ((ifp
->if_eflags
& (IFEF_ECN_ENABLE
|IFEF_ECN_DISABLE
)) ==
3444 ifr
->ifr_ecn_mode
= IFRTYPE_ECN_DISABLE
;
3446 ifr
->ifr_ecn_mode
= IFRTYPE_ECN_DEFAULT
;
3449 if ((error
= priv_check_cred(kauth_cred_get(),
3450 PRIV_NET_INTERFACE_CONTROL
, 0)) != 0)
3452 if (ifr
->ifr_ecn_mode
== IFRTYPE_ECN_DEFAULT
) {
3453 ifp
->if_eflags
&= ~(IFEF_ECN_ENABLE
|IFEF_ECN_DISABLE
);
3454 } else if (ifr
->ifr_ecn_mode
== IFRTYPE_ECN_ENABLE
) {
3455 ifp
->if_eflags
|= IFEF_ECN_ENABLE
;
3456 ifp
->if_eflags
&= ~IFEF_ECN_DISABLE
;
3457 } else if (ifr
->ifr_ecn_mode
== IFRTYPE_ECN_DISABLE
) {
3458 ifp
->if_eflags
|= IFEF_ECN_DISABLE
;
3459 ifp
->if_eflags
&= ~IFEF_ECN_ENABLE
;
3463 case SIOCSIFTIMESTAMPENABLE
:
3464 case SIOCSIFTIMESTAMPDISABLE
:
3465 error
= proc_suser(p
);
3469 ifnet_lock_exclusive(ifp
);
3470 if ((cmd
== SIOCSIFTIMESTAMPENABLE
&&
3471 (ifp
->if_xflags
& IFXF_TIMESTAMP_ENABLED
) != 0) ||
3472 (cmd
== SIOCSIFTIMESTAMPDISABLE
&&
3473 (ifp
->if_xflags
& IFXF_TIMESTAMP_ENABLED
) == 0)) {
3474 ifnet_lock_done(ifp
);
3477 if (cmd
== SIOCSIFTIMESTAMPENABLE
)
3478 ifp
->if_xflags
|= IFXF_TIMESTAMP_ENABLED
;
3480 ifp
->if_xflags
&= ~IFXF_TIMESTAMP_ENABLED
;
3481 ifnet_lock_done(ifp
);
3483 * Pass the setting to the interface if it supports either
3484 * software or hardware time stamping
3486 if (ifp
->if_capabilities
& (IFCAP_HW_TIMESTAMP
|
3487 IFCAP_SW_TIMESTAMP
)) {
3488 error
= ifnet_ioctl(ifp
, SOCK_DOM(so
), cmd
,
3492 case SIOCGIFTIMESTAMPENABLED
: {
3493 if ((ifp
->if_xflags
& IFXF_TIMESTAMP_ENABLED
) != 0)
3494 ifr
->ifr_intval
= 1;
3496 ifr
->ifr_intval
= 0;
3499 case SIOCSQOSMARKINGMODE
:
3500 if ((error
= priv_check_cred(kauth_cred_get(),
3501 PRIV_NET_INTERFACE_CONTROL
, 0)) != 0)
3503 error
= if_set_qosmarking_mode(ifp
, ifr
->ifr_qosmarking_mode
);
3506 case SIOCGQOSMARKINGMODE
:
3507 ifr
->ifr_qosmarking_mode
= ifp
->if_qosmarking_mode
;
3510 case SIOCSQOSMARKINGENABLED
:
3511 if ((error
= priv_check_cred(kauth_cred_get(),
3512 PRIV_NET_INTERFACE_CONTROL
, 0)) != 0)
3514 if (ifr
->ifr_qosmarking_enabled
!= 0)
3515 ifp
->if_eflags
|= IFEF_QOSMARKING_ENABLED
;
3517 ifp
->if_eflags
&= ~IFEF_QOSMARKING_ENABLED
;
3520 case SIOCGQOSMARKINGENABLED
:
3521 ifr
->ifr_qosmarking_enabled
=
3522 (ifp
->if_eflags
& IFEF_QOSMARKING_ENABLED
) ? 1 : 0;
3525 case SIOCSIFDISABLEOUTPUT
:
3526 #if (DEBUG || DEVELOPMENT)
3527 if (ifr
->ifr_disable_output
== 1) {
3528 error
= ifnet_disable_output(ifp
);
3529 } else if (ifr
->ifr_disable_output
== 0) {
3530 error
= ifnet_enable_output(ifp
);
3536 #endif /* (DEBUG || DEVELOPMENT) */
3538 case SIOCSIFLOWINTERNET
:
3539 if ((error
= priv_check_cred(kauth_cred_get(),
3540 PRIV_NET_INTERFACE_CONTROL
, 0)) != 0)
3543 ifnet_lock_exclusive(ifp
);
3544 if (ifr
->ifr_low_internet
& IFRTYPE_LOW_INTERNET_ENABLE_UL
)
3545 ifp
->if_xflags
|= IFXF_LOW_INTERNET_UL
;
3547 ifp
->if_xflags
&= ~(IFXF_LOW_INTERNET_UL
);
3548 if (ifr
->ifr_low_internet
& IFRTYPE_LOW_INTERNET_ENABLE_DL
)
3549 ifp
->if_xflags
|= IFXF_LOW_INTERNET_DL
;
3551 ifp
->if_xflags
&= ~(IFXF_LOW_INTERNET_DL
);
3552 ifnet_lock_done(ifp
);
3554 case SIOCGIFLOWINTERNET
:
3555 ifnet_lock_shared(ifp
);
3556 ifr
->ifr_low_internet
= 0;
3557 if (ifp
->if_xflags
& IFXF_LOW_INTERNET_UL
)
3558 ifr
->ifr_low_internet
|=
3559 IFRTYPE_LOW_INTERNET_ENABLE_UL
;
3560 if (ifp
->if_xflags
& IFXF_LOW_INTERNET_DL
)
3561 ifr
->ifr_low_internet
|=
3562 IFRTYPE_LOW_INTERNET_ENABLE_DL
;
3563 ifnet_lock_done(ifp
);
3574 ifioctllocked(struct socket
*so
, u_long cmd
, caddr_t data
, struct proc
*p
)
3578 socket_unlock(so
, 0);
3579 error
= ifioctl(so
, cmd
, data
, p
);
3585 * Set/clear promiscuous mode on interface ifp based on the truth value
3586 * of pswitch. The calls are reference counted so that only the first
3587 * "on" request actually has an effect, as does the final "off" request.
3588 * Results are undefined if the "off" and "on" requests are not matched.
3591 ifnet_set_promiscuous(
3599 ifnet_lock_exclusive(ifp
);
3600 oldflags
= ifp
->if_flags
;
3601 ifp
->if_pcount
+= pswitch
? 1 : -1;
3603 if (ifp
->if_pcount
> 0)
3604 ifp
->if_flags
|= IFF_PROMISC
;
3606 ifp
->if_flags
&= ~IFF_PROMISC
;
3608 newflags
= ifp
->if_flags
;
3609 ifnet_lock_done(ifp
);
3611 if (newflags
!= oldflags
&& (newflags
& IFF_UP
) != 0) {
3612 error
= ifnet_ioctl(ifp
, 0, SIOCSIFFLAGS
, NULL
);
3616 ifnet_lock_exclusive(ifp
);
3618 ifp
->if_pcount
-= pswitch
? 1 : -1;
3619 if (ifp
->if_pcount
> 0)
3620 ifp
->if_flags
|= IFF_PROMISC
;
3622 ifp
->if_flags
&= ~IFF_PROMISC
;
3623 ifnet_lock_done(ifp
);
3627 if (newflags
!= oldflags
) {
3628 log(LOG_INFO
, "%s: promiscuous mode %s%s\n",
3630 (newflags
& IFF_PROMISC
) != 0 ? "enable" : "disable",
3631 error
!= 0 ? " failed" : " succeeded");
3637 * Return interface configuration
3638 * of system. List may be used
3639 * in later ioctl's (above) to get
3640 * other information.
3644 ifconf(u_long cmd
, user_addr_t ifrp
, int *ret_space
)
3646 struct ifnet
*ifp
= NULL
;
3651 net_thread_marks_t marks
;
3653 marks
= net_thread_marks_push(NET_THREAD_CKREQ_LLADDR
);
3656 * Zero the ifr buffer to make sure we don't
3657 * disclose the contents of the stack.
3659 bzero(&ifr
, sizeof (struct ifreq
));
3662 ifnet_head_lock_shared();
3663 for (ifp
= ifnet_head
.tqh_first
; space
> sizeof (ifr
) &&
3664 ifp
; ifp
= ifp
->if_link
.tqe_next
) {
3666 size_t ifnlen
, addrs
;
3668 ifnlen
= snprintf(workbuf
, sizeof (workbuf
),
3669 "%s", if_name(ifp
));
3670 if (ifnlen
+ 1 > sizeof (ifr
.ifr_name
)) {
3671 error
= ENAMETOOLONG
;
3674 strlcpy(ifr
.ifr_name
, workbuf
, IFNAMSIZ
);
3677 ifnet_lock_shared(ifp
);
3680 ifa
= ifp
->if_addrhead
.tqh_first
;
3681 for (; space
> sizeof (ifr
) && ifa
;
3682 ifa
= ifa
->ifa_link
.tqe_next
) {
3683 struct sockaddr
*sa
;
3686 struct sockaddr_dl sdl
;
3687 uint8_t buf
[SOCK_MAXADDRLEN
+ 1];
3691 * Make sure to accomodate the largest possible
3692 * size of SA(if_lladdr)->sa_len.
3694 _CASSERT(sizeof (u
) == (SOCK_MAXADDRLEN
+ 1));
3700 if (ifa
== ifp
->if_lladdr
) {
3701 VERIFY(sa
->sa_family
== AF_LINK
);
3702 bcopy(sa
, &u
, sa
->sa_len
);
3704 ifnet_guarded_lladdr_copy_bytes(ifp
,
3705 LLADDR(&u
.sdl
), u
.sdl
.sdl_alen
);
3710 if (cmd
== OSIOCGIFCONF32
|| cmd
== OSIOCGIFCONF64
) {
3711 struct osockaddr
*osa
=
3712 (struct osockaddr
*)(void *)&ifr
.ifr_addr
;
3714 osa
->sa_family
= sa
->sa_family
;
3715 error
= copyout((caddr_t
)&ifr
, ifrp
,
3717 ifrp
+= sizeof (struct ifreq
);
3718 } else if (sa
->sa_len
<= sizeof (*sa
)) {
3720 error
= copyout((caddr_t
)&ifr
, ifrp
,
3722 ifrp
+= sizeof (struct ifreq
);
3725 sizeof (ifr
) + sa
->sa_len
- sizeof (*sa
)) {
3729 space
-= sa
->sa_len
- sizeof (*sa
);
3730 error
= copyout((caddr_t
)&ifr
, ifrp
,
3731 sizeof (ifr
.ifr_name
));
3733 error
= copyout((caddr_t
)sa
, (ifrp
+
3734 offsetof(struct ifreq
, ifr_addr
)),
3737 ifrp
+= (sa
->sa_len
+ offsetof(struct ifreq
,
3743 space
-= sizeof (ifr
);
3745 ifnet_lock_done(ifp
);
3750 bzero((caddr_t
)&ifr
.ifr_addr
, sizeof (ifr
.ifr_addr
));
3751 error
= copyout((caddr_t
)&ifr
, ifrp
, sizeof (ifr
));
3754 space
-= sizeof (ifr
);
3755 ifrp
+= sizeof (struct ifreq
);
3759 *ret_space
-= space
;
3760 net_thread_marks_pop(marks
);
3765 * Just like if_promisc(), but for all-multicast-reception mode.
3768 if_allmulti(struct ifnet
*ifp
, int onswitch
)
3773 ifnet_lock_exclusive(ifp
);
3776 if (ifp
->if_amcount
++ == 0) {
3777 ifp
->if_flags
|= IFF_ALLMULTI
;
3781 if (ifp
->if_amcount
> 1) {
3784 ifp
->if_amcount
= 0;
3785 ifp
->if_flags
&= ~IFF_ALLMULTI
;
3789 ifnet_lock_done(ifp
);
3792 error
= ifnet_ioctl(ifp
, 0, SIOCSIFFLAGS
, NULL
);
3799 static struct ifmultiaddr
*
3802 struct ifmultiaddr
*ifma
;
3804 ifma
= (how
== M_WAITOK
) ? zalloc(ifma_zone
) :
3805 zalloc_noblock(ifma_zone
);
3808 bzero(ifma
, ifma_size
);
3809 lck_mtx_init(&ifma
->ifma_lock
, ifa_mtx_grp
, ifa_mtx_attr
);
3810 ifma
->ifma_debug
|= IFD_ALLOC
;
3811 if (ifma_debug
!= 0) {
3812 ifma
->ifma_debug
|= IFD_DEBUG
;
3813 ifma
->ifma_trace
= ifma_trace
;
3820 ifma_free(struct ifmultiaddr
*ifma
)
3824 if (ifma
->ifma_protospec
!= NULL
) {
3825 panic("%s: Protospec not NULL for ifma=%p", __func__
, ifma
);
3827 } else if ((ifma
->ifma_flags
& IFMAF_ANONYMOUS
) ||
3828 ifma
->ifma_anoncnt
!= 0) {
3829 panic("%s: Freeing ifma=%p with outstanding anon req",
3832 } else if (ifma
->ifma_debug
& IFD_ATTACHED
) {
3833 panic("%s: ifma=%p attached to ifma_ifp=%p is being freed",
3834 __func__
, ifma
, ifma
->ifma_ifp
);
3836 } else if (!(ifma
->ifma_debug
& IFD_ALLOC
)) {
3837 panic("%s: ifma %p cannot be freed", __func__
, ifma
);
3839 } else if (ifma
->ifma_refcount
!= 0) {
3840 panic("%s: non-zero refcount ifma=%p", __func__
, ifma
);
3842 } else if (ifma
->ifma_reqcnt
!= 0) {
3843 panic("%s: non-zero reqcnt ifma=%p", __func__
, ifma
);
3845 } else if (ifma
->ifma_ifp
!= NULL
) {
3846 panic("%s: non-NULL ifma_ifp=%p for ifma=%p", __func__
,
3847 ifma
->ifma_ifp
, ifma
);
3849 } else if (ifma
->ifma_ll
!= NULL
) {
3850 panic("%s: non-NULL ifma_ll=%p for ifma=%p", __func__
,
3851 ifma
->ifma_ll
, ifma
);
3854 ifma
->ifma_debug
&= ~IFD_ALLOC
;
3855 if ((ifma
->ifma_debug
& (IFD_DEBUG
| IFD_TRASHED
)) ==
3856 (IFD_DEBUG
| IFD_TRASHED
)) {
3857 lck_mtx_lock(&ifma_trash_lock
);
3858 TAILQ_REMOVE(&ifma_trash_head
, (struct ifmultiaddr_dbg
*)ifma
,
3860 lck_mtx_unlock(&ifma_trash_lock
);
3861 ifma
->ifma_debug
&= ~IFD_TRASHED
;
3865 if (ifma
->ifma_addr
!= NULL
) {
3866 FREE(ifma
->ifma_addr
, M_IFADDR
);
3867 ifma
->ifma_addr
= NULL
;
3869 lck_mtx_destroy(&ifma
->ifma_lock
, ifa_mtx_grp
);
3870 zfree(ifma_zone
, ifma
);
3874 ifma_trace(struct ifmultiaddr
*ifma
, int refhold
)
3876 struct ifmultiaddr_dbg
*ifma_dbg
= (struct ifmultiaddr_dbg
*)ifma
;
3881 if (!(ifma
->ifma_debug
& IFD_DEBUG
)) {
3882 panic("%s: ifma %p has no debug structure", __func__
, ifma
);
3886 cnt
= &ifma_dbg
->ifma_refhold_cnt
;
3887 tr
= ifma_dbg
->ifma_refhold
;
3889 cnt
= &ifma_dbg
->ifma_refrele_cnt
;
3890 tr
= ifma_dbg
->ifma_refrele
;
3893 idx
= atomic_add_16_ov(cnt
, 1) % IFMA_TRACE_HIST_SIZE
;
3894 ctrace_record(&tr
[idx
]);
3898 ifma_addref(struct ifmultiaddr
*ifma
, int locked
)
3903 IFMA_LOCK_ASSERT_HELD(ifma
);
3905 if (++ifma
->ifma_refcount
== 0) {
3906 panic("%s: ifma=%p wraparound refcnt", __func__
, ifma
);
3908 } else if (ifma
->ifma_trace
!= NULL
) {
3909 (*ifma
->ifma_trace
)(ifma
, TRUE
);
3916 ifma_remref(struct ifmultiaddr
*ifma
)
3918 struct ifmultiaddr
*ll
;
3922 if (ifma
->ifma_refcount
== 0) {
3923 panic("%s: ifma=%p negative refcnt", __func__
, ifma
);
3925 } else if (ifma
->ifma_trace
!= NULL
) {
3926 (*ifma
->ifma_trace
)(ifma
, FALSE
);
3929 --ifma
->ifma_refcount
;
3930 if (ifma
->ifma_refcount
> 0) {
3936 ifma
->ifma_ifp
= NULL
;
3937 ifma
->ifma_ll
= NULL
;
3939 ifma_free(ifma
); /* deallocate it */
3946 if_attach_ifma(struct ifnet
*ifp
, struct ifmultiaddr
*ifma
, int anon
)
3948 ifnet_lock_assert(ifp
, IFNET_LCK_ASSERT_EXCLUSIVE
);
3949 IFMA_LOCK_ASSERT_HELD(ifma
);
3951 if (ifma
->ifma_ifp
!= ifp
) {
3952 panic("%s: Mismatch ifma_ifp=%p != ifp=%p", __func__
,
3953 ifma
->ifma_ifp
, ifp
);
3955 } else if (ifma
->ifma_debug
& IFD_ATTACHED
) {
3956 panic("%s: Attempt to attach an already attached ifma=%p",
3959 } else if (anon
&& (ifma
->ifma_flags
& IFMAF_ANONYMOUS
)) {
3960 panic("%s: ifma=%p unexpected IFMAF_ANONYMOUS", __func__
, ifma
);
3962 } else if (ifma
->ifma_debug
& IFD_TRASHED
) {
3963 panic("%s: Attempt to reattach a detached ifma=%p",
3968 ifma
->ifma_reqcnt
++;
3969 VERIFY(ifma
->ifma_reqcnt
== 1);
3970 IFMA_ADDREF_LOCKED(ifma
);
3971 ifma
->ifma_debug
|= IFD_ATTACHED
;
3973 ifma
->ifma_anoncnt
++;
3974 VERIFY(ifma
->ifma_anoncnt
== 1);
3975 ifma
->ifma_flags
|= IFMAF_ANONYMOUS
;
3978 LIST_INSERT_HEAD(&ifp
->if_multiaddrs
, ifma
, ifma_link
);
3982 if_detach_ifma(struct ifnet
*ifp
, struct ifmultiaddr
*ifma
, int anon
)
3984 ifnet_lock_assert(ifp
, IFNET_LCK_ASSERT_EXCLUSIVE
);
3985 IFMA_LOCK_ASSERT_HELD(ifma
);
3987 if (ifma
->ifma_reqcnt
== 0) {
3988 panic("%s: ifma=%p negative reqcnt", __func__
, ifma
);
3990 } else if (anon
&& !(ifma
->ifma_flags
& IFMAF_ANONYMOUS
)) {
3991 panic("%s: ifma=%p missing IFMAF_ANONYMOUS", __func__
, ifma
);
3993 } else if (anon
&& ifma
->ifma_anoncnt
== 0) {
3994 panic("%s: ifma=%p negative anonreqcnt", __func__
, ifma
);
3996 } else if (ifma
->ifma_ifp
!= ifp
) {
3997 panic("%s: Mismatch ifma_ifp=%p, ifp=%p", __func__
,
3998 ifma
->ifma_ifp
, ifp
);
4003 --ifma
->ifma_anoncnt
;
4004 if (ifma
->ifma_anoncnt
> 0)
4006 ifma
->ifma_flags
&= ~IFMAF_ANONYMOUS
;
4009 --ifma
->ifma_reqcnt
;
4010 if (ifma
->ifma_reqcnt
> 0)
4013 if (ifma
->ifma_protospec
!= NULL
) {
4014 panic("%s: Protospec not NULL for ifma=%p", __func__
, ifma
);
4016 } else if ((ifma
->ifma_flags
& IFMAF_ANONYMOUS
) ||
4017 ifma
->ifma_anoncnt
!= 0) {
4018 panic("%s: Detaching ifma=%p with outstanding anon req",
4021 } else if (!(ifma
->ifma_debug
& IFD_ATTACHED
)) {
4022 panic("%s: Attempt to detach an unattached address ifma=%p",
4025 } else if (ifma
->ifma_debug
& IFD_TRASHED
) {
4026 panic("%s: ifma %p is already in trash list", __func__
, ifma
);
4031 * NOTE: Caller calls IFMA_REMREF
4033 ifma
->ifma_debug
&= ~IFD_ATTACHED
;
4034 LIST_REMOVE(ifma
, ifma_link
);
4035 if (LIST_EMPTY(&ifp
->if_multiaddrs
))
4036 ifp
->if_updatemcasts
= 0;
4038 if (ifma
->ifma_debug
& IFD_DEBUG
) {
4039 /* Become a regular mutex, just in case */
4040 IFMA_CONVERT_LOCK(ifma
);
4041 lck_mtx_lock(&ifma_trash_lock
);
4042 TAILQ_INSERT_TAIL(&ifma_trash_head
,
4043 (struct ifmultiaddr_dbg
*)ifma
, ifma_trash_link
);
4044 lck_mtx_unlock(&ifma_trash_lock
);
4045 ifma
->ifma_debug
|= IFD_TRASHED
;
4052 * Find an ifmultiaddr that matches a socket address on an interface.
4054 * Caller is responsible for holding the ifnet_lock while calling
4058 if_addmulti_doesexist(struct ifnet
*ifp
, const struct sockaddr
*sa
,
4059 struct ifmultiaddr
**retifma
, int anon
)
4061 struct ifmultiaddr
*ifma
;
4063 for (ifma
= LIST_FIRST(&ifp
->if_multiaddrs
); ifma
!= NULL
;
4064 ifma
= LIST_NEXT(ifma
, ifma_link
)) {
4065 IFMA_LOCK_SPIN(ifma
);
4066 if (!ifa_equal(sa
, ifma
->ifma_addr
)) {
4071 VERIFY(!(ifma
->ifma_flags
& IFMAF_ANONYMOUS
) ||
4072 ifma
->ifma_anoncnt
!= 0);
4073 VERIFY((ifma
->ifma_flags
& IFMAF_ANONYMOUS
) ||
4074 ifma
->ifma_anoncnt
== 0);
4075 ifma
->ifma_anoncnt
++;
4076 if (!(ifma
->ifma_flags
& IFMAF_ANONYMOUS
)) {
4077 VERIFY(ifma
->ifma_anoncnt
== 1);
4078 ifma
->ifma_flags
|= IFMAF_ANONYMOUS
;
4081 if (!anon
|| ifma
->ifma_anoncnt
== 1) {
4082 ifma
->ifma_reqcnt
++;
4083 VERIFY(ifma
->ifma_reqcnt
> 1);
4085 if (retifma
!= NULL
) {
4087 IFMA_ADDREF_LOCKED(ifma
);
4096 * Radar 3642395, make sure all multicasts are in a standard format.
4098 static struct sockaddr
*
4099 copy_and_normalize(const struct sockaddr
*original
)
4102 const u_char
*aptr
= NULL
;
4103 struct sockaddr
*copy
= NULL
;
4104 struct sockaddr_dl
*sdl_new
= NULL
;
4107 if (original
->sa_family
!= AF_LINK
&&
4108 original
->sa_family
!= AF_UNSPEC
) {
4109 /* Just make a copy */
4110 MALLOC(copy
, struct sockaddr
*, original
->sa_len
,
4111 M_IFADDR
, M_WAITOK
);
4113 bcopy(original
, copy
, original
->sa_len
);
4117 switch (original
->sa_family
) {
4119 const struct sockaddr_dl
*sdl_original
=
4120 (struct sockaddr_dl
*)(uintptr_t)(size_t)original
;
4122 if (sdl_original
->sdl_nlen
+ sdl_original
->sdl_alen
+
4123 sdl_original
->sdl_slen
+
4124 offsetof(struct sockaddr_dl
, sdl_data
) >
4125 sdl_original
->sdl_len
)
4128 alen
= sdl_original
->sdl_alen
;
4129 aptr
= CONST_LLADDR(sdl_original
);
4134 if (original
->sa_len
< ETHER_ADDR_LEN
+
4135 offsetof(struct sockaddr
, sa_data
)) {
4139 alen
= ETHER_ADDR_LEN
;
4140 aptr
= (const u_char
*)original
->sa_data
;
4145 if (alen
== 0 || aptr
== NULL
)
4148 len
= alen
+ offsetof(struct sockaddr_dl
, sdl_data
);
4149 MALLOC(sdl_new
, struct sockaddr_dl
*, len
, M_IFADDR
, M_WAITOK
);
4151 if (sdl_new
!= NULL
) {
4152 bzero(sdl_new
, len
);
4153 sdl_new
->sdl_len
= len
;
4154 sdl_new
->sdl_family
= AF_LINK
;
4155 sdl_new
->sdl_alen
= alen
;
4156 bcopy(aptr
, LLADDR(sdl_new
), alen
);
4159 return ((struct sockaddr
*)sdl_new
);
4163 * Network-layer protocol domains which hold references to the underlying
4164 * link-layer record must use this routine.
4167 if_addmulti(struct ifnet
*ifp
, const struct sockaddr
*sa
,
4168 struct ifmultiaddr
**retifma
)
4170 return (if_addmulti_common(ifp
, sa
, retifma
, 0));
4174 * Anything other than network-layer protocol domains which hold references
4175 * to the underlying link-layer record must use this routine: SIOCADDMULTI
4176 * ioctl, ifnet_add_multicast(), if_bond.
4179 if_addmulti_anon(struct ifnet
*ifp
, const struct sockaddr
*sa
,
4180 struct ifmultiaddr
**retifma
)
4182 return (if_addmulti_common(ifp
, sa
, retifma
, 1));
4186 * Register an additional multicast address with a network interface.
4188 * - If the address is already present, bump the reference count on the
4189 * address and return.
4190 * - If the address is not link-layer, look up a link layer address.
4191 * - Allocate address structures for one or both addresses, and attach to the
4192 * multicast address list on the interface. If automatically adding a link
4193 * layer address, the protocol address will own a reference to the link
4194 * layer address, to be freed when it is freed.
4195 * - Notify the network device driver of an addition to the multicast address
4198 * 'sa' points to caller-owned memory with the desired multicast address.
4200 * 'retifma' will be used to return a pointer to the resulting multicast
4201 * address reference, if desired.
4203 * 'anon' indicates a link-layer address with no protocol address reference
4204 * made to it. Anything other than network-layer protocol domain requests
4205 * are considered as anonymous.
4208 if_addmulti_common(struct ifnet
*ifp
, const struct sockaddr
*sa
,
4209 struct ifmultiaddr
**retifma
, int anon
)
4211 struct sockaddr_storage storage
;
4212 struct sockaddr
*llsa
= NULL
;
4213 struct sockaddr
*dupsa
= NULL
;
4214 int error
= 0, ll_firstref
= 0, lladdr
;
4215 struct ifmultiaddr
*ifma
= NULL
;
4216 struct ifmultiaddr
*llifma
= NULL
;
4218 /* Only AF_UNSPEC/AF_LINK is allowed for an "anonymous" address */
4219 VERIFY(!anon
|| sa
->sa_family
== AF_UNSPEC
||
4220 sa
->sa_family
== AF_LINK
);
4222 /* If sa is a AF_LINK or AF_UNSPEC, duplicate and normalize it */
4223 if (sa
->sa_family
== AF_LINK
|| sa
->sa_family
== AF_UNSPEC
) {
4224 dupsa
= copy_and_normalize(sa
);
4225 if (dupsa
== NULL
) {
4232 ifnet_lock_exclusive(ifp
);
4233 if (!(ifp
->if_flags
& IFF_MULTICAST
)) {
4234 error
= EADDRNOTAVAIL
;
4235 ifnet_lock_done(ifp
);
4239 /* If the address is already present, return a new reference to it */
4240 error
= if_addmulti_doesexist(ifp
, sa
, retifma
, anon
);
4241 ifnet_lock_done(ifp
);
4246 * The address isn't already present; give the link layer a chance
4247 * to accept/reject it, and also find out which AF_LINK address this
4248 * maps to, if it isn't one already.
4250 error
= dlil_resolve_multi(ifp
, sa
, (struct sockaddr
*)&storage
,
4252 if (error
== 0 && storage
.ss_len
!= 0) {
4253 llsa
= copy_and_normalize((struct sockaddr
*)&storage
);
4259 llifma
= ifma_alloc(M_WAITOK
);
4260 if (llifma
== NULL
) {
4266 /* to be similar to FreeBSD */
4267 if (error
== EOPNOTSUPP
)
4269 else if (error
!= 0)
4272 /* Allocate while we aren't holding any locks */
4273 if (dupsa
== NULL
) {
4274 dupsa
= copy_and_normalize(sa
);
4275 if (dupsa
== NULL
) {
4280 ifma
= ifma_alloc(M_WAITOK
);
4286 ifnet_lock_exclusive(ifp
);
4288 * Check again for the matching multicast.
4290 error
= if_addmulti_doesexist(ifp
, sa
, retifma
, anon
);
4292 ifnet_lock_done(ifp
);
4296 if (llifma
!= NULL
) {
4297 VERIFY(!anon
); /* must not get here if "anonymous" */
4298 if (if_addmulti_doesexist(ifp
, llsa
, &ifma
->ifma_ll
, 0) == 0) {
4299 FREE(llsa
, M_IFADDR
);
4303 VERIFY(ifma
->ifma_ll
->ifma_ifp
== ifp
);
4306 llifma
->ifma_addr
= llsa
;
4307 llifma
->ifma_ifp
= ifp
;
4309 if_attach_ifma(ifp
, llifma
, 0);
4310 /* add extra refcnt for ifma */
4311 IFMA_ADDREF_LOCKED(llifma
);
4312 IFMA_UNLOCK(llifma
);
4313 ifma
->ifma_ll
= llifma
;
4317 /* "anonymous" request should not result in network address */
4318 VERIFY(!anon
|| ifma
->ifma_ll
== NULL
);
4320 ifma
->ifma_addr
= dupsa
;
4321 ifma
->ifma_ifp
= ifp
;
4323 if_attach_ifma(ifp
, ifma
, anon
);
4324 IFMA_ADDREF_LOCKED(ifma
); /* for this routine */
4325 if (retifma
!= NULL
) {
4327 IFMA_ADDREF_LOCKED(*retifma
); /* for caller */
4329 lladdr
= (ifma
->ifma_addr
->sa_family
== AF_UNSPEC
||
4330 ifma
->ifma_addr
->sa_family
== AF_LINK
);
4332 ifnet_lock_done(ifp
);
4334 rt_newmaddrmsg(RTM_NEWMADDR
, ifma
);
4335 IFMA_REMREF(ifma
); /* for this routine */
4338 * We are certain we have added something, so call down to the
4339 * interface to let them know about it. Do this only for newly-
4340 * added AF_LINK/AF_UNSPEC address in the if_multiaddrs set.
4342 if (lladdr
|| ll_firstref
)
4343 (void) ifnet_ioctl(ifp
, 0, SIOCADDMULTI
, NULL
);
4345 if (ifp
->if_updatemcasts
> 0)
4346 ifp
->if_updatemcasts
= 0;
4354 FREE(dupsa
, M_IFADDR
);
4358 FREE(llsa
, M_IFADDR
);
4364 * Delete a multicast group membership by network-layer group address.
4365 * This routine is deprecated.
4368 if_delmulti(struct ifnet
*ifp
, const struct sockaddr
*sa
)
4370 return (if_delmulti_common(NULL
, ifp
, sa
, 0));
4374 * Delete a multicast group membership by group membership pointer.
4375 * Network-layer protocol domains must use this routine.
4378 if_delmulti_ifma(struct ifmultiaddr
*ifma
)
4380 return (if_delmulti_common(ifma
, NULL
, NULL
, 0));
4384 * Anything other than network-layer protocol domains which hold references
4385 * to the underlying link-layer record must use this routine: SIOCDELMULTI
4386 * ioctl, ifnet_remove_multicast(), if_bond.
4389 if_delmulti_anon(struct ifnet
*ifp
, const struct sockaddr
*sa
)
4391 return (if_delmulti_common(NULL
, ifp
, sa
, 1));
4395 * Delete a multicast group membership by network-layer group address.
4397 * Returns ENOENT if the entry could not be found.
4400 if_delmulti_common(struct ifmultiaddr
*ifma
, struct ifnet
*ifp
,
4401 const struct sockaddr
*sa
, int anon
)
4403 struct sockaddr
*dupsa
= NULL
;
4404 int lastref
, ll_lastref
= 0, lladdr
;
4405 struct ifmultiaddr
*ll
= NULL
;
4407 /* sanity check for callers */
4408 VERIFY(ifma
!= NULL
|| (ifp
!= NULL
&& sa
!= NULL
));
4411 ifp
= ifma
->ifma_ifp
;
4414 (sa
->sa_family
== AF_LINK
|| sa
->sa_family
== AF_UNSPEC
)) {
4415 dupsa
= copy_and_normalize(sa
);
4421 ifnet_lock_exclusive(ifp
);
4423 for (ifma
= LIST_FIRST(&ifp
->if_multiaddrs
); ifma
!= NULL
;
4424 ifma
= LIST_NEXT(ifma
, ifma_link
)) {
4426 if (!ifa_equal(sa
, ifma
->ifma_addr
) ||
4427 (anon
&& !(ifma
->ifma_flags
& IFMAF_ANONYMOUS
))) {
4428 VERIFY(!(ifma
->ifma_flags
& IFMAF_ANONYMOUS
) ||
4429 ifma
->ifma_anoncnt
!= 0);
4433 /* found; keep it locked */
4438 FREE(dupsa
, M_IFADDR
);
4439 ifnet_lock_done(ifp
);
4445 IFMA_LOCK_ASSERT_HELD(ifma
);
4446 IFMA_ADDREF_LOCKED(ifma
); /* for this routine */
4447 lastref
= if_detach_ifma(ifp
, ifma
, anon
);
4448 VERIFY(!lastref
|| (!(ifma
->ifma_debug
& IFD_ATTACHED
) &&
4449 ifma
->ifma_reqcnt
== 0));
4450 VERIFY(!anon
|| ifma
->ifma_ll
== NULL
);
4452 lladdr
= (ifma
->ifma_addr
->sa_family
== AF_UNSPEC
||
4453 ifma
->ifma_addr
->sa_family
== AF_LINK
);
4455 if (lastref
&& ll
!= NULL
) {
4457 ll_lastref
= if_detach_ifma(ifp
, ll
, 0);
4460 ifnet_lock_done(ifp
);
4463 rt_newmaddrmsg(RTM_DELMADDR
, ifma
);
4465 if ((ll
== NULL
&& lastref
&& lladdr
) || ll_lastref
) {
4467 * Make sure the interface driver is notified in the
4468 * case of a link layer mcast group being left. Do
4469 * this only for a AF_LINK/AF_UNSPEC address that has
4470 * been removed from the if_multiaddrs set.
4472 ifnet_ioctl(ifp
, 0, SIOCDELMULTI
, NULL
);
4476 IFMA_REMREF(ifma
); /* for if_multiaddrs list */
4478 IFMA_REMREF(ll
); /* for if_multiaddrs list */
4480 IFMA_REMREF(ifma
); /* for this routine */
4482 FREE(dupsa
, M_IFADDR
);
4488 * Shutdown all network activity. Used boot() when halting
4498 if (ifnet_list_get_all(IFNET_FAMILY_ANY
, &ifp
, &count
) == 0) {
4499 for (i
= 0; i
< count
; i
++) {
4501 dlil_proto_unplumb_all(ifp
[i
]);
4503 ifnet_list_free(ifp
);
4510 * Delete Routes for a Network Interface
4512 * Called for each routing entry via the rnh->rnh_walktree() call above
4513 * to delete all route entries referencing a detaching network interface.
4516 * rn pointer to node in the routing table
4517 * arg argument passed to rnh->rnh_walktree() - detaching interface
4521 * errno failed - reason indicated
4525 if_rtdel(struct radix_node
*rn
, void *arg
)
4527 struct rtentry
*rt
= (struct rtentry
*)rn
;
4528 struct ifnet
*ifp
= arg
;
4534 * Checking against RTF_UP protects against walktree
4535 * recursion problems with cloned routes.
4538 if (rt
->rt_ifp
== ifp
&& (rt
->rt_flags
& RTF_UP
)) {
4540 * Safe to drop rt_lock and use rt_key, rt_gateway,
4541 * since holding rnh_lock here prevents another thread
4542 * from calling rt_setgate() on this route.
4545 err
= rtrequest_locked(RTM_DELETE
, rt_key(rt
), rt
->rt_gateway
,
4546 rt_mask(rt
), rt
->rt_flags
, NULL
);
4548 log(LOG_WARNING
, "if_rtdel: error %d\n", err
);
4557 * Removes routing table reference to a given interface
4558 * for a given protocol family
4561 if_rtproto_del(struct ifnet
*ifp
, int protocol
)
4563 struct radix_node_head
*rnh
;
4565 if ((protocol
<= AF_MAX
) && (protocol
>= 0) &&
4566 ((rnh
= rt_tables
[protocol
]) != NULL
) && (ifp
!= NULL
)) {
4567 lck_mtx_lock(rnh_lock
);
4568 (void) rnh
->rnh_walktree(rnh
, if_rtdel
, ifp
);
4569 lck_mtx_unlock(rnh_lock
);
4574 if_rtmtu(struct radix_node
*rn
, void *arg
)
4576 struct rtentry
*rt
= (struct rtentry
*)rn
;
4577 struct ifnet
*ifp
= arg
;
4580 if (rt
->rt_ifp
== ifp
) {
4582 * Update the MTU of this entry only if the MTU
4583 * has not been locked (RTV_MTU is not set) and
4584 * if it was non-zero to begin with.
4586 if (!(rt
->rt_rmx
.rmx_locks
& RTV_MTU
) && rt
->rt_rmx
.rmx_mtu
)
4587 rt
->rt_rmx
.rmx_mtu
= ifp
->if_mtu
;
4595 * Update the MTU metric of all route entries in all protocol tables
4596 * associated with a particular interface; this is called when the
4597 * MTU of that interface has changed.
4600 if_rtmtu_update(struct ifnet
*ifp
)
4602 struct radix_node_head
*rnh
;
4605 for (p
= 0; p
< AF_MAX
+ 1; p
++) {
4606 if ((rnh
= rt_tables
[p
]) == NULL
)
4609 lck_mtx_lock(rnh_lock
);
4610 (void) rnh
->rnh_walktree(rnh
, if_rtmtu
, ifp
);
4611 lck_mtx_unlock(rnh_lock
);
4613 routegenid_update();
4616 __private_extern__
void
4617 if_data_internal_to_if_data(struct ifnet
*ifp
,
4618 const struct if_data_internal
*if_data_int
, struct if_data
*if_data
)
4621 #define COPYFIELD(fld) if_data->fld = if_data_int->fld
4622 #define COPYFIELD32(fld) if_data->fld = (u_int32_t)(if_data_int->fld)
4623 /* compiler will cast down to 32-bit */
4624 #define COPYFIELD32_ATOMIC(fld) do { \
4625 atomic_get_64(if_data->fld, \
4626 (u_int64_t *)(void *)(uintptr_t)&if_data_int->fld); \
4629 COPYFIELD(ifi_type
);
4630 COPYFIELD(ifi_typelen
);
4631 COPYFIELD(ifi_physical
);
4632 COPYFIELD(ifi_addrlen
);
4633 COPYFIELD(ifi_hdrlen
);
4634 COPYFIELD(ifi_recvquota
);
4635 COPYFIELD(ifi_xmitquota
);
4636 if_data
->ifi_unused1
= 0;
4638 COPYFIELD(ifi_metric
);
4639 if (if_data_int
->ifi_baudrate
& 0xFFFFFFFF00000000LL
) {
4640 if_data
->ifi_baudrate
= 0xFFFFFFFF;
4642 COPYFIELD32(ifi_baudrate
);
4645 COPYFIELD32_ATOMIC(ifi_ipackets
);
4646 COPYFIELD32_ATOMIC(ifi_ierrors
);
4647 COPYFIELD32_ATOMIC(ifi_opackets
);
4648 COPYFIELD32_ATOMIC(ifi_oerrors
);
4649 COPYFIELD32_ATOMIC(ifi_collisions
);
4650 COPYFIELD32_ATOMIC(ifi_ibytes
);
4651 COPYFIELD32_ATOMIC(ifi_obytes
);
4652 COPYFIELD32_ATOMIC(ifi_imcasts
);
4653 COPYFIELD32_ATOMIC(ifi_omcasts
);
4654 COPYFIELD32_ATOMIC(ifi_iqdrops
);
4655 COPYFIELD32_ATOMIC(ifi_noproto
);
4657 COPYFIELD(ifi_recvtiming
);
4658 COPYFIELD(ifi_xmittiming
);
4660 if_data
->ifi_lastchange
.tv_sec
= if_data_int
->ifi_lastchange
.tv_sec
;
4661 if_data
->ifi_lastchange
.tv_usec
= if_data_int
->ifi_lastchange
.tv_usec
;
4663 if_data
->ifi_lastchange
.tv_sec
+= boottime_sec();
4665 if_data
->ifi_unused2
= 0;
4666 COPYFIELD(ifi_hwassist
);
4667 if_data
->ifi_reserved1
= 0;
4668 if_data
->ifi_reserved2
= 0;
4669 #undef COPYFIELD32_ATOMIC
4674 __private_extern__
void
4675 if_data_internal_to_if_data64(struct ifnet
*ifp
,
4676 const struct if_data_internal
*if_data_int
,
4677 struct if_data64
*if_data64
)
4680 #define COPYFIELD64(fld) if_data64->fld = if_data_int->fld
4681 #define COPYFIELD64_ATOMIC(fld) do { \
4682 atomic_get_64(if_data64->fld, \
4683 (u_int64_t *)(void *)(uintptr_t)&if_data_int->fld); \
4686 COPYFIELD64(ifi_type
);
4687 COPYFIELD64(ifi_typelen
);
4688 COPYFIELD64(ifi_physical
);
4689 COPYFIELD64(ifi_addrlen
);
4690 COPYFIELD64(ifi_hdrlen
);
4691 COPYFIELD64(ifi_recvquota
);
4692 COPYFIELD64(ifi_xmitquota
);
4693 if_data64
->ifi_unused1
= 0;
4694 COPYFIELD64(ifi_mtu
);
4695 COPYFIELD64(ifi_metric
);
4696 COPYFIELD64(ifi_baudrate
);
4698 COPYFIELD64_ATOMIC(ifi_ipackets
);
4699 COPYFIELD64_ATOMIC(ifi_ierrors
);
4700 COPYFIELD64_ATOMIC(ifi_opackets
);
4701 COPYFIELD64_ATOMIC(ifi_oerrors
);
4702 COPYFIELD64_ATOMIC(ifi_collisions
);
4703 COPYFIELD64_ATOMIC(ifi_ibytes
);
4704 COPYFIELD64_ATOMIC(ifi_obytes
);
4705 COPYFIELD64_ATOMIC(ifi_imcasts
);
4706 COPYFIELD64_ATOMIC(ifi_omcasts
);
4707 COPYFIELD64_ATOMIC(ifi_iqdrops
);
4708 COPYFIELD64_ATOMIC(ifi_noproto
);
4711 * Note these two fields are actually 32 bit, so doing
4712 * COPYFIELD64_ATOMIC will cause them to be misaligned
4714 COPYFIELD64(ifi_recvtiming
);
4715 COPYFIELD64(ifi_xmittiming
);
4717 if_data64
->ifi_lastchange
.tv_sec
= if_data_int
->ifi_lastchange
.tv_sec
;
4718 if_data64
->ifi_lastchange
.tv_usec
= if_data_int
->ifi_lastchange
.tv_usec
;
4720 if_data64
->ifi_lastchange
.tv_sec
+= boottime_sec();
4725 __private_extern__
void
4726 if_copy_traffic_class(struct ifnet
*ifp
,
4727 struct if_traffic_class
*if_tc
)
4729 #define COPY_IF_TC_FIELD64_ATOMIC(fld) do { \
4730 atomic_get_64(if_tc->fld, \
4731 (u_int64_t *)(void *)(uintptr_t)&ifp->if_tc.fld); \
4734 bzero(if_tc
, sizeof (*if_tc
));
4735 COPY_IF_TC_FIELD64_ATOMIC(ifi_ibepackets
);
4736 COPY_IF_TC_FIELD64_ATOMIC(ifi_ibebytes
);
4737 COPY_IF_TC_FIELD64_ATOMIC(ifi_obepackets
);
4738 COPY_IF_TC_FIELD64_ATOMIC(ifi_obebytes
);
4739 COPY_IF_TC_FIELD64_ATOMIC(ifi_ibkpackets
);
4740 COPY_IF_TC_FIELD64_ATOMIC(ifi_ibkbytes
);
4741 COPY_IF_TC_FIELD64_ATOMIC(ifi_obkpackets
);
4742 COPY_IF_TC_FIELD64_ATOMIC(ifi_obkbytes
);
4743 COPY_IF_TC_FIELD64_ATOMIC(ifi_ivipackets
);
4744 COPY_IF_TC_FIELD64_ATOMIC(ifi_ivibytes
);
4745 COPY_IF_TC_FIELD64_ATOMIC(ifi_ovipackets
);
4746 COPY_IF_TC_FIELD64_ATOMIC(ifi_ovibytes
);
4747 COPY_IF_TC_FIELD64_ATOMIC(ifi_ivopackets
);
4748 COPY_IF_TC_FIELD64_ATOMIC(ifi_ivobytes
);
4749 COPY_IF_TC_FIELD64_ATOMIC(ifi_ovopackets
);
4750 COPY_IF_TC_FIELD64_ATOMIC(ifi_ovobytes
);
4751 COPY_IF_TC_FIELD64_ATOMIC(ifi_ipvpackets
);
4752 COPY_IF_TC_FIELD64_ATOMIC(ifi_ipvbytes
);
4753 COPY_IF_TC_FIELD64_ATOMIC(ifi_opvpackets
);
4754 COPY_IF_TC_FIELD64_ATOMIC(ifi_opvbytes
);
4756 #undef COPY_IF_TC_FIELD64_ATOMIC
4760 if_copy_data_extended(struct ifnet
*ifp
, struct if_data_extended
*if_de
)
4762 #define COPY_IF_DE_FIELD64_ATOMIC(fld) do { \
4763 atomic_get_64(if_de->fld, \
4764 (u_int64_t *)(void *)(uintptr_t)&ifp->if_data.fld); \
4767 bzero(if_de
, sizeof (*if_de
));
4768 COPY_IF_DE_FIELD64_ATOMIC(ifi_alignerrs
);
4769 COPY_IF_DE_FIELD64_ATOMIC(ifi_dt_bytes
);
4770 COPY_IF_DE_FIELD64_ATOMIC(ifi_fpackets
);
4771 COPY_IF_DE_FIELD64_ATOMIC(ifi_fbytes
);
4773 #undef COPY_IF_DE_FIELD64_ATOMIC
4777 if_copy_packet_stats(struct ifnet
*ifp
, struct if_packet_stats
*if_ps
)
4779 #define COPY_IF_PS_TCP_FIELD64_ATOMIC(fld) do { \
4780 atomic_get_64(if_ps->ifi_tcp_##fld, \
4781 (u_int64_t *)(void *)(uintptr_t)&ifp->if_tcp_stat->fld); \
4784 #define COPY_IF_PS_UDP_FIELD64_ATOMIC(fld) do { \
4785 atomic_get_64(if_ps->ifi_udp_##fld, \
4786 (u_int64_t *)(void *)(uintptr_t)&ifp->if_udp_stat->fld); \
4789 COPY_IF_PS_TCP_FIELD64_ATOMIC(badformat
);
4790 COPY_IF_PS_TCP_FIELD64_ATOMIC(unspecv6
);
4791 COPY_IF_PS_TCP_FIELD64_ATOMIC(synfin
);
4792 COPY_IF_PS_TCP_FIELD64_ATOMIC(badformatipsec
);
4793 COPY_IF_PS_TCP_FIELD64_ATOMIC(noconnnolist
);
4794 COPY_IF_PS_TCP_FIELD64_ATOMIC(noconnlist
);
4795 COPY_IF_PS_TCP_FIELD64_ATOMIC(listbadsyn
);
4796 COPY_IF_PS_TCP_FIELD64_ATOMIC(icmp6unreach
);
4797 COPY_IF_PS_TCP_FIELD64_ATOMIC(deprecate6
);
4798 COPY_IF_PS_TCP_FIELD64_ATOMIC(ooopacket
);
4799 COPY_IF_PS_TCP_FIELD64_ATOMIC(rstinsynrcv
);
4800 COPY_IF_PS_TCP_FIELD64_ATOMIC(dospacket
);
4801 COPY_IF_PS_TCP_FIELD64_ATOMIC(cleanup
);
4802 COPY_IF_PS_TCP_FIELD64_ATOMIC(synwindow
);
4804 COPY_IF_PS_UDP_FIELD64_ATOMIC(port_unreach
);
4805 COPY_IF_PS_UDP_FIELD64_ATOMIC(faithprefix
);
4806 COPY_IF_PS_UDP_FIELD64_ATOMIC(port0
);
4807 COPY_IF_PS_UDP_FIELD64_ATOMIC(badlength
);
4808 COPY_IF_PS_UDP_FIELD64_ATOMIC(badchksum
);
4809 COPY_IF_PS_UDP_FIELD64_ATOMIC(badmcast
);
4810 COPY_IF_PS_UDP_FIELD64_ATOMIC(cleanup
);
4811 COPY_IF_PS_UDP_FIELD64_ATOMIC(badipsec
);
4813 #undef COPY_IF_PS_TCP_FIELD64_ATOMIC
4814 #undef COPY_IF_PS_UDP_FIELD64_ATOMIC
4818 if_copy_rxpoll_stats(struct ifnet
*ifp
, struct if_rxpoll_stats
*if_rs
)
4820 bzero(if_rs
, sizeof (*if_rs
));
4821 if (!(ifp
->if_eflags
& IFEF_RXPOLL
) || !ifnet_is_attached(ifp
, 1))
4824 /* by now, ifnet will stay attached so if_inp must be valid */
4825 VERIFY(ifp
->if_inp
!= NULL
);
4826 bcopy(&ifp
->if_inp
->pstats
, if_rs
, sizeof (*if_rs
));
4828 /* Release the IO refcnt */
4829 ifnet_decr_iorefcnt(ifp
);
4833 ifa_remref(struct ifaddr
*ifa
, int locked
)
4838 IFA_LOCK_ASSERT_HELD(ifa
);
4840 if (ifa
->ifa_refcnt
== 0)
4841 panic("%s: ifa %p negative refcnt\n", __func__
, ifa
);
4842 else if (ifa
->ifa_trace
!= NULL
)
4843 (*ifa
->ifa_trace
)(ifa
, FALSE
);
4844 if (--ifa
->ifa_refcnt
== 0) {
4845 if (ifa
->ifa_debug
& IFD_ATTACHED
)
4846 panic("ifa %p attached to ifp is being freed\n", ifa
);
4848 * Some interface addresses are allocated either statically
4849 * or carved out of a larger block. Only free it if it was
4850 * allocated via MALLOC or via the corresponding per-address
4851 * family allocator. Otherwise, leave it alone.
4853 if (ifa
->ifa_debug
& IFD_ALLOC
) {
4854 if (ifa
->ifa_free
== NULL
) {
4856 FREE(ifa
, M_IFADDR
);
4858 /* Become a regular mutex */
4859 IFA_CONVERT_LOCK(ifa
);
4860 /* callee will unlock */
4861 (*ifa
->ifa_free
)(ifa
);
4869 if (!locked
&& ifa
!= NULL
)
4876 ifa_addref(struct ifaddr
*ifa
, int locked
)
4881 IFA_LOCK_ASSERT_HELD(ifa
);
4883 if (++ifa
->ifa_refcnt
== 0) {
4884 panic("%s: ifa %p wraparound refcnt\n", __func__
, ifa
);
4886 } else if (ifa
->ifa_trace
!= NULL
) {
4887 (*ifa
->ifa_trace
)(ifa
, TRUE
);
4894 ifa_lock_init(struct ifaddr
*ifa
)
4896 lck_mtx_init(&ifa
->ifa_lock
, ifa_mtx_grp
, ifa_mtx_attr
);
4900 ifa_lock_destroy(struct ifaddr
*ifa
)
4902 IFA_LOCK_ASSERT_NOTHELD(ifa
);
4903 lck_mtx_destroy(&ifa
->ifa_lock
, ifa_mtx_grp
);
4909 * The switch statement below does nothing at runtime, as it serves as a
4910 * compile time check to ensure that all of the socket 'i' ioctls (those
4911 * in the 'i' group going thru soo_ioctl) that are made available by the
4912 * networking stack is unique. This works as long as this routine gets
4913 * updated each time a new interface ioctl gets added.
4915 * Any failures at compile time indicates duplicated ioctl values.
4917 static __attribute__((unused
)) void
4918 ifioctl_cassert(void)
4921 * This is equivalent to _CASSERT() and the compiler wouldn't
4922 * generate any instructions, thus for compile time only.
4924 switch ((u_long
)0) {
4927 /* bsd/net/if_ppp.h */
4929 case SIOCGPPPCSTATS
:
4932 /* bsd/netinet6/in6_var.h */
4933 case SIOCSIFADDR_IN6
:
4934 case SIOCGIFADDR_IN6
:
4935 case SIOCSIFDSTADDR_IN6
:
4936 case SIOCSIFNETMASK_IN6
:
4937 case SIOCGIFDSTADDR_IN6
:
4938 case SIOCGIFNETMASK_IN6
:
4939 case SIOCDIFADDR_IN6
:
4940 case SIOCAIFADDR_IN6_32
:
4941 case SIOCAIFADDR_IN6_64
:
4942 case SIOCSIFPHYADDR_IN6_32
:
4943 case SIOCSIFPHYADDR_IN6_64
:
4944 case SIOCGIFPSRCADDR_IN6
:
4945 case SIOCGIFPDSTADDR_IN6
:
4946 case SIOCGIFAFLAG_IN6
:
4947 case SIOCGDRLST_IN6_32
:
4948 case SIOCGDRLST_IN6_64
:
4949 case SIOCGPRLST_IN6_32
:
4950 case SIOCGPRLST_IN6_64
:
4951 case OSIOCGIFINFO_IN6
:
4952 case SIOCGIFINFO_IN6
:
4953 case SIOCSNDFLUSH_IN6
:
4954 case SIOCGNBRINFO_IN6_32
:
4955 case SIOCGNBRINFO_IN6_64
:
4956 case SIOCSPFXFLUSH_IN6
:
4957 case SIOCSRTRFLUSH_IN6
:
4958 case SIOCGIFALIFETIME_IN6
:
4959 case SIOCSIFALIFETIME_IN6
:
4960 case SIOCGIFSTAT_IN6
:
4961 case SIOCGIFSTAT_ICMP6
:
4962 case SIOCSDEFIFACE_IN6_32
:
4963 case SIOCSDEFIFACE_IN6_64
:
4964 case SIOCGDEFIFACE_IN6_32
:
4965 case SIOCGDEFIFACE_IN6_64
:
4966 case SIOCSIFINFO_FLAGS
:
4969 case SIOCGSCOPE6DEF
:
4970 case SIOCSIFPREFIX_IN6
:
4971 case SIOCGIFPREFIX_IN6
:
4972 case SIOCDIFPREFIX_IN6
:
4973 case SIOCAIFPREFIX_IN6
:
4974 case SIOCCIFPREFIX_IN6
:
4975 case SIOCSGIFPREFIX_IN6
:
4976 case SIOCPROTOATTACH_IN6_32
:
4977 case SIOCPROTOATTACH_IN6_64
:
4978 case SIOCPROTODETACH_IN6
:
4979 case SIOCLL_START_32
:
4980 case SIOCLL_START_64
:
4982 case SIOCAUTOCONF_START
:
4983 case SIOCAUTOCONF_STOP
:
4984 case SIOCSETROUTERMODE_IN6
:
4985 case SIOCLL_CGASTART_32
:
4986 case SIOCLL_CGASTART_64
:
4987 case SIOCGIFCGAPREP_IN6
:
4988 case SIOCSIFCGAPREP_IN6
:
4991 /* bsd/sys/sockio.h */
4994 case SIOCSIFDSTADDR
:
4995 case OSIOCGIFDSTADDR
:
4998 case OSIOCGIFBRDADDR
:
4999 case SIOCSIFBRDADDR
:
5000 case OSIOCGIFCONF32
:
5001 case OSIOCGIFCONF64
:
5002 case OSIOCGIFNETMASK
:
5003 case SIOCSIFNETMASK
:
5010 case SIOCGIFDSTADDR
:
5011 case SIOCGIFBRDADDR
:
5014 case SIOCGIFNETMASK
:
5016 case SIOCAUTONETMASK
:
5026 case SIOCGIFMEDIA32
:
5027 case SIOCGIFMEDIA64
:
5028 case SIOCSIFGENERIC
:
5029 case SIOCGIFGENERIC
:
5034 case SIOCSIFPHYADDR
:
5035 case SIOCGIFPSRCADDR
:
5036 case SIOCGIFPDSTADDR
:
5037 case SIOCDIFPHYADDR
:
5045 case SIOCPROTOATTACH
:
5046 case SIOCPROTODETACH
:
5055 case SIOCSDRVSPEC32
:
5056 case SIOCGDRVSPEC32
:
5057 case SIOCSDRVSPEC64
:
5058 case SIOCGDRVSPEC64
:
5063 case SIOCIFGCLONERS32
:
5064 case SIOCIFGCLONERS64
:
5066 case SIOCGIFASYNCMAP
:
5067 case SIOCSIFASYNCMAP
:
5071 #endif /* CONFIG_MACF_NET */
5075 case SIOCGIFWAKEFLAGS
:
5077 case SIOCGIFGETRTREFCNT
:
5078 case SIOCGIFLINKQUALITYMETRIC
:
5079 case SIOCSIFOPPORTUNISTIC
:
5080 case SIOCGIFOPPORTUNISTIC
:
5081 case SIOCSETROUTERMODE
:
5085 case SIOCSIFLINKPARAMS
:
5086 case SIOCGIFLINKPARAMS
:
5087 case SIOCGIFQUEUESTATS
:
5088 case SIOCSIFTHROTTLE
:
5089 case SIOCGIFTHROTTLE
:
5091 case SIOCGASSOCIDS32
:
5092 case SIOCGASSOCIDS64
:
5093 case SIOCGCONNIDS32
:
5094 case SIOCGCONNIDS64
:
5095 case SIOCGCONNINFO32
:
5096 case SIOCGCONNINFO64
:
5097 case SIOCSCONNORDER
:
5098 case SIOCGCONNORDER
:
5102 case SIOCGIFDELEGATE
:
5105 case SIOCGIFEXPENSIVE
:
5106 case SIOCSIFEXPENSIVE
:
5109 case SIOCGSTARTDELAY
:
5111 case SIOCAIFAGENTID
:
5112 case SIOCDIFAGENTID
:
5113 case SIOCGIFAGENTIDS32
:
5114 case SIOCGIFAGENTIDS64
:
5115 case SIOCGIFAGENTDATA32
:
5116 case SIOCGIFAGENTDATA64
:
5117 case SIOCGIFAGENTLIST32
:
5118 case SIOCGIFAGENTLIST64
:
5121 case SIOCSIFINTERFACESTATE
:
5122 case SIOCGIFINTERFACESTATE
:
5123 case SIOCSIFPROBECONNECTIVITY
:
5124 case SIOCGIFPROBECONNECTIVITY
:
5126 case SIOCGIFFUNCTIONALTYPE
:
5127 case SIOCSIFNETSIGNATURE
:
5128 case SIOCGIFNETSIGNATURE
:
5133 case SIOCSQOSMARKINGMODE
:
5134 case SIOCSQOSMARKINGENABLED
:
5135 case SIOCGQOSMARKINGMODE
:
5136 case SIOCGQOSMARKINGENABLED
:
5138 case SIOCGIFPROTOLIST32
:
5139 case SIOCGIFPROTOLIST64
:
5145 ifnet_mbuf_packetpreamblelen(struct ifnet
*ifp
)
5151 /* The following is used to enqueue work items for interface events */
5154 union sockaddr_in_4_6 addr
;
5155 uint32_t intf_event_code
;
5159 intf_event_callback(void *arg
)
5161 struct intf_event
*p_intf_ev
= (struct intf_event
*)arg
;
5163 /* Call this before we walk the tree */
5164 EVENTHANDLER_INVOKE(&ifnet_evhdlr_ctxt
, ifnet_event
, p_intf_ev
->ifp
,
5165 (struct sockaddr
*)&(p_intf_ev
->addr
), p_intf_ev
->intf_event_code
);
5168 struct intf_event_nwk_wq_entry
{
5169 struct nwk_wq_entry nwk_wqe
;
5170 struct intf_event intf_ev_arg
;
5174 intf_event_enqueue_nwk_wq_entry(struct ifnet
*ifp
, struct sockaddr
*addrp
,
5175 uint32_t intf_event_code
)
5177 #pragma unused(addrp)
5178 struct intf_event_nwk_wq_entry
*p_intf_ev
= NULL
;
5180 MALLOC(p_intf_ev
, struct intf_event_nwk_wq_entry
*,
5181 sizeof(struct intf_event_nwk_wq_entry
),
5182 M_NWKWQ
, M_WAITOK
| M_ZERO
);
5184 p_intf_ev
->intf_ev_arg
.ifp
= ifp
;
5186 * XXX Not using addr in the arg. This will be used
5187 * once we need IP address add/delete events
5189 p_intf_ev
->intf_ev_arg
.intf_event_code
= intf_event_code
;
5190 p_intf_ev
->nwk_wqe
.func
= intf_event_callback
;
5191 p_intf_ev
->nwk_wqe
.is_arg_managed
= TRUE
;
5192 p_intf_ev
->nwk_wqe
.arg
= &p_intf_ev
->intf_ev_arg
;
5193 nwk_wq_enqueue((struct nwk_wq_entry
*)p_intf_ev
);