2 * Copyright (c) 2000-2017 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
);
335 __private_extern__
void
336 if_detach_ifa(struct ifnet
*ifp
, struct ifaddr
*ifa
)
338 if_detach_ifa_common(ifp
, ifa
, 0);
341 __private_extern__
void
342 if_detach_link_ifa(struct ifnet
*ifp
, struct ifaddr
*ifa
)
344 if_detach_ifa_common(ifp
, ifa
, 1);
348 if_detach_ifa_common(struct ifnet
*ifp
, struct ifaddr
*ifa
, int link
)
350 ifnet_lock_assert(ifp
, IFNET_LCK_ASSERT_EXCLUSIVE
);
351 IFA_LOCK_ASSERT_HELD(ifa
);
353 if (link
&& !(ifa
->ifa_debug
& IFD_LINK
)) {
354 panic("%s: Unexpected non-link address ifa=%p", __func__
, ifa
);
356 } else if (link
&& ifa
!= TAILQ_FIRST(&ifp
->if_addrhead
)) {
357 panic("%s: Link address ifa=%p not first", __func__
, ifa
);
359 } else if (!link
&& (ifa
->ifa_debug
& IFD_LINK
)) {
360 panic("%s: Unexpected link address ifa=%p", __func__
, ifa
);
362 } else if (!(ifa
->ifa_debug
& IFD_ATTACHED
)) {
363 panic("%s: Attempt to detach an unattached address ifa=%p",
366 } else if (ifa
->ifa_ifp
!= ifp
) {
367 panic("%s: Mismatch ifa_ifp=%p, ifp=%p", __func__
,
370 } else if (ifa
->ifa_debug
& IFD_DEBUG
) {
372 TAILQ_FOREACH(ifa2
, &ifp
->if_addrhead
, ifa_link
) {
377 panic("%s: Attempt to detach a stray address ifa=%p",
382 TAILQ_REMOVE(&ifp
->if_addrhead
, ifa
, ifa_link
);
383 /* This must not be the last reference to the ifaddr */
384 if (IFA_REMREF_LOCKED(ifa
) == NULL
) {
385 panic("%s: unexpected (missing) refcnt ifa=%p", __func__
, ifa
);
388 ifa
->ifa_debug
&= ~(IFD_ATTACHED
| IFD_DETACHING
);
390 if (ifa
->ifa_detached
!= NULL
)
391 (*ifa
->ifa_detached
)(ifa
);
395 #define INITIAL_IF_INDEXLIM 8
398 * Function: if_next_index
400 * Return the next available interface index.
401 * Grow the ifnet_addrs[] and ifindex2ifnet[] arrays to accomodate the
402 * added entry when necessary.
405 * ifnet_addrs[] is indexed by (if_index - 1), whereas
406 * ifindex2ifnet[] is indexed by ifp->if_index. That requires us to
407 * always allocate one extra element to hold ifindex2ifnet[0], which
410 int if_next_index(void);
412 __private_extern__
int
415 static int if_indexlim
= 0;
418 new_index
= ++if_index
;
419 if (if_index
> if_indexlim
) {
422 caddr_t new_ifnet_addrs
;
423 caddr_t new_ifindex2ifnet
;
424 caddr_t old_ifnet_addrs
;
426 old_ifnet_addrs
= (caddr_t
)ifnet_addrs
;
427 if (ifnet_addrs
== NULL
) {
428 new_if_indexlim
= INITIAL_IF_INDEXLIM
;
430 new_if_indexlim
= if_indexlim
<< 1;
433 /* allocate space for the larger arrays */
434 n
= (2 * new_if_indexlim
+ 1) * sizeof(caddr_t
);
435 new_ifnet_addrs
= _MALLOC(n
, M_IFADDR
, M_WAITOK
| M_ZERO
);
436 if (new_ifnet_addrs
== NULL
) {
441 new_ifindex2ifnet
= new_ifnet_addrs
442 + new_if_indexlim
* sizeof(caddr_t
);
443 if (ifnet_addrs
!= NULL
) {
444 /* copy the existing data */
445 bcopy((caddr_t
)ifnet_addrs
, new_ifnet_addrs
,
446 if_indexlim
* sizeof(caddr_t
));
447 bcopy((caddr_t
)ifindex2ifnet
,
449 (if_indexlim
+ 1) * sizeof(caddr_t
));
452 /* switch to the new tables and size */
453 ifnet_addrs
= (struct ifaddr
**)(void *)new_ifnet_addrs
;
454 ifindex2ifnet
= (struct ifnet
**)(void *)new_ifindex2ifnet
;
455 if_indexlim
= new_if_indexlim
;
457 /* release the old data */
458 if (old_ifnet_addrs
!= NULL
) {
459 _FREE((caddr_t
)old_ifnet_addrs
, M_IFADDR
);
466 * Create a clone network interface.
469 if_clone_create(char *name
, int len
, void *params
)
471 struct if_clone
*ifc
;
474 u_int32_t bytoff
, bitoff
;
478 ifc
= if_clone_lookup(name
, &unit
);
482 if (ifunit(name
) != NULL
)
486 wildcard
= (unit
== UINT32_MAX
);
488 * Find a free unit if none was given.
491 while ((bytoff
< ifc
->ifc_bmlen
) &&
492 (ifc
->ifc_units
[bytoff
] == 0xff))
494 if (bytoff
>= ifc
->ifc_bmlen
)
496 while ((ifc
->ifc_units
[bytoff
] & (1 << bitoff
)) != 0)
498 unit
= (bytoff
<< 3) + bitoff
;
501 if (unit
> ifc
->ifc_maxunit
)
504 err
= (*ifc
->ifc_create
)(ifc
, unit
, params
);
510 bitoff
= unit
- (bytoff
<< 3);
514 * Allocate the unit in the bitmap.
516 KASSERT((ifc
->ifc_units
[bytoff
] & (1 << bitoff
)) == 0,
517 ("%s: bit is already set", __func__
));
518 ifc
->ifc_units
[bytoff
] |= (1 << bitoff
);
520 /* In the wildcard case, we need to update the name. */
522 for (dp
= name
; *dp
!= '\0'; dp
++);
523 if (snprintf(dp
, len
- (dp
-name
), "%d", unit
) >
524 len
- (dp
-name
) - 1) {
526 * This can only be a programmer error and
527 * there's no straightforward way to recover if
530 panic("%s: interface name too long", __func__
);
540 * Destroy a clone network interface.
543 if_clone_destroy(const char *name
)
545 struct if_clone
*ifc
;
550 ifc
= if_clone_lookup(name
, &unit
);
554 if (unit
< ifc
->ifc_minifs
)
561 if (ifc
->ifc_destroy
== NULL
)
564 (*ifc
->ifc_destroy
)(ifp
);
567 * Compute offset in the bitmap and deallocate the unit.
570 bitoff
= unit
- (bytoff
<< 3);
571 KASSERT((ifc
->ifc_units
[bytoff
] & (1 << bitoff
)) != 0,
572 ("%s: bit is already cleared", __func__
));
573 ifc
->ifc_units
[bytoff
] &= ~(1 << bitoff
);
578 * Look up a network interface cloner.
581 __private_extern__
struct if_clone
*
582 if_clone_lookup(const char *name
, u_int32_t
*unitp
)
584 struct if_clone
*ifc
;
588 for (ifc
= LIST_FIRST(&if_cloners
); ifc
!= NULL
; ) {
589 for (cp
= name
, i
= 0; i
< ifc
->ifc_namelen
; i
++, cp
++) {
590 if (ifc
->ifc_name
[i
] != *cp
)
595 ifc
= LIST_NEXT(ifc
, ifc_list
);
599 return ((struct if_clone
*)NULL
);
605 for (i
= 0; *cp
!= '\0'; cp
++) {
606 if (*cp
< '0' || *cp
> '9') {
607 /* Bogus unit number. */
610 i
= (i
* 10) + (*cp
- '0');
620 * Register a network interface cloner.
623 if_clone_attach(struct if_clone
*ifc
)
630 KASSERT(ifc
->ifc_minifs
- 1 <= ifc
->ifc_maxunit
,
631 ("%s: %s requested more units then allowed (%d > %d)",
632 __func__
, ifc
->ifc_name
, ifc
->ifc_minifs
,
633 ifc
->ifc_maxunit
+ 1));
635 * Compute bitmap size and allocate it.
637 maxclone
= ifc
->ifc_maxunit
+ 1;
639 if ((len
<< 3) < maxclone
)
641 ifc
->ifc_units
= _MALLOC(len
, M_CLONE
, M_WAITOK
| M_ZERO
);
642 if (ifc
->ifc_units
== NULL
)
644 ifc
->ifc_bmlen
= len
;
646 LIST_INSERT_HEAD(&if_cloners
, ifc
, ifc_list
);
649 for (unit
= 0; unit
< ifc
->ifc_minifs
; unit
++) {
650 err
= (*ifc
->ifc_create
)(ifc
, unit
, NULL
);
652 ("%s: failed to create required interface %s%d",
653 __func__
, ifc
->ifc_name
, unit
));
655 /* Allocate the unit in the bitmap. */
657 bitoff
= unit
- (bytoff
<< 3);
658 ifc
->ifc_units
[bytoff
] |= (1 << bitoff
);
665 * Unregister a network interface cloner.
668 if_clone_detach(struct if_clone
*ifc
)
670 LIST_REMOVE(ifc
, ifc_list
);
671 FREE(ifc
->ifc_units
, M_CLONE
);
676 * Provide list of interface cloners to userspace.
679 if_clone_list(int count
, int *ret_total
, user_addr_t dst
)
681 char outbuf
[IFNAMSIZ
];
682 struct if_clone
*ifc
;
685 *ret_total
= if_cloners_count
;
686 if (dst
== USER_ADDR_NULL
) {
687 /* Just asking how many there are. */
694 count
= (if_cloners_count
< count
) ? if_cloners_count
: count
;
696 for (ifc
= LIST_FIRST(&if_cloners
); ifc
!= NULL
&& count
!= 0;
697 ifc
= LIST_NEXT(ifc
, ifc_list
), count
--, dst
+= IFNAMSIZ
) {
698 bzero(outbuf
, sizeof(outbuf
));
699 strlcpy(outbuf
, ifc
->ifc_name
,
700 min(strlen(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)
1671 if (!IFCQ_IS_READY(ifq
)) {
1676 bcopy(&iflpr
->iflpr_output_tbr_rate
, &tb
.rate
,
1678 bcopy(&iflpr
->iflpr_output_tbr_percent
, &tb
.percent
,
1679 sizeof (tb
.percent
));
1680 error
= ifclassq_tbr_set(ifq
, &tb
, TRUE
);
1685 case SIOCGIFLINKPARAMS
: { /* struct if_linkparamsreq */
1686 u_int32_t sched_type
= PKTSCHEDT_NONE
, flags
= 0;
1687 u_int64_t tbr_bw
= 0, tbr_pct
= 0;
1691 if (IFCQ_IS_ENABLED(ifq
))
1692 sched_type
= ifq
->ifcq_type
;
1694 bcopy(&sched_type
, &iflpr
->iflpr_output_sched
,
1695 sizeof (iflpr
->iflpr_output_sched
));
1697 if (IFCQ_TBR_IS_ENABLED(ifq
)) {
1698 tbr_bw
= ifq
->ifcq_tbr
.tbr_rate_raw
;
1699 tbr_pct
= ifq
->ifcq_tbr
.tbr_percent
;
1701 bcopy(&tbr_bw
, &iflpr
->iflpr_output_tbr_rate
,
1702 sizeof (iflpr
->iflpr_output_tbr_rate
));
1703 bcopy(&tbr_pct
, &iflpr
->iflpr_output_tbr_percent
,
1704 sizeof (iflpr
->iflpr_output_tbr_percent
));
1707 if (ifp
->if_output_sched_model
==
1708 IFNET_SCHED_MODEL_DRIVER_MANAGED
)
1709 flags
|= IFLPRF_DRVMANAGED
;
1710 bcopy(&flags
, &iflpr
->iflpr_flags
, sizeof (iflpr
->iflpr_flags
));
1711 bcopy(&ifp
->if_output_bw
, &iflpr
->iflpr_output_bw
,
1712 sizeof (iflpr
->iflpr_output_bw
));
1713 bcopy(&ifp
->if_input_bw
, &iflpr
->iflpr_input_bw
,
1714 sizeof (iflpr
->iflpr_input_bw
));
1715 bcopy(&ifp
->if_output_lt
, &iflpr
->iflpr_output_lt
,
1716 sizeof (iflpr
->iflpr_output_lt
));
1717 bcopy(&ifp
->if_input_lt
, &iflpr
->iflpr_input_lt
,
1718 sizeof (iflpr
->iflpr_input_lt
));
1730 static __attribute__((noinline
)) int
1731 ifioctl_qstats(struct ifnet
*ifp
, u_long cmd
, caddr_t data
)
1733 struct if_qstatsreq
*ifqr
= (struct if_qstatsreq
*)(void *)data
;
1734 u_int32_t ifqr_len
, ifqr_slot
;
1737 VERIFY(ifp
!= NULL
);
1740 case SIOCGIFQUEUESTATS
: { /* struct if_qstatsreq */
1741 bcopy(&ifqr
->ifqr_slot
, &ifqr_slot
, sizeof (ifqr_slot
));
1742 bcopy(&ifqr
->ifqr_len
, &ifqr_len
, sizeof (ifqr_len
));
1743 error
= ifclassq_getqstats(&ifp
->if_snd
, ifqr_slot
,
1744 ifqr
->ifqr_buf
, &ifqr_len
);
1747 bcopy(&ifqr_len
, &ifqr
->ifqr_len
, sizeof (ifqr_len
));
1759 static __attribute__((noinline
)) int
1760 ifioctl_throttle(struct ifnet
*ifp
, u_long cmd
, caddr_t data
, struct proc
*p
)
1762 struct if_throttlereq
*ifthr
= (struct if_throttlereq
*)(void *)data
;
1763 u_int32_t ifthr_level
;
1766 VERIFY(ifp
!= NULL
);
1769 case SIOCSIFTHROTTLE
: { /* struct if_throttlereq */
1771 * XXX: Use priv_check_cred() instead of root check?
1773 if ((error
= proc_suser(p
)) != 0)
1776 bcopy(&ifthr
->ifthr_level
, &ifthr_level
, sizeof (ifthr_level
));
1777 error
= ifnet_set_throttle(ifp
, ifthr_level
);
1778 if (error
== EALREADY
)
1783 case SIOCGIFTHROTTLE
: { /* struct if_throttlereq */
1784 if ((error
= ifnet_get_throttle(ifp
, &ifthr_level
)) == 0) {
1785 bcopy(&ifthr_level
, &ifthr
->ifthr_level
,
1786 sizeof (ifthr_level
));
1800 ifioctl_getnetagents(struct ifnet
*ifp
, u_int32_t
*count
, user_addr_t uuid_p
)
1803 u_int32_t index
= 0;
1804 u_int32_t valid_netagent_count
= 0;
1807 ifnet_lock_assert(ifp
, IFNET_LCK_ASSERT_SHARED
);
1809 if (ifp
->if_agentids
!= NULL
) {
1810 for (index
= 0; index
< ifp
->if_agentcount
; index
++) {
1811 uuid_t
*netagent_uuid
= &(ifp
->if_agentids
[index
]);
1812 if (!uuid_is_null(*netagent_uuid
)) {
1813 if (uuid_p
!= USER_ADDR_NULL
) {
1814 error
= copyout(netagent_uuid
,
1815 uuid_p
+ sizeof(uuid_t
) * valid_netagent_count
,
1821 valid_netagent_count
++;
1825 *count
= valid_netagent_count
;
1830 #define IF_MAXAGENTS 64
1831 #define IF_AGENT_INCREMENT 8
1833 if_add_netagent_locked(struct ifnet
*ifp
, uuid_t new_agent_uuid
)
1835 uuid_t
*first_empty_slot
= NULL
;
1836 u_int32_t index
= 0;
1837 bool already_added
= FALSE
;
1839 if (ifp
->if_agentids
!= NULL
) {
1840 for (index
= 0; index
< ifp
->if_agentcount
; index
++) {
1841 uuid_t
*netagent_uuid
= &(ifp
->if_agentids
[index
]);
1842 if (uuid_compare(*netagent_uuid
, new_agent_uuid
) == 0) {
1843 /* Already present, ignore */
1844 already_added
= TRUE
;
1847 if (first_empty_slot
== NULL
&&
1848 uuid_is_null(*netagent_uuid
)) {
1849 first_empty_slot
= netagent_uuid
;
1853 if (already_added
) {
1854 /* Already added agent, don't return an error */
1857 if (first_empty_slot
== NULL
) {
1858 if (ifp
->if_agentcount
>= IF_MAXAGENTS
) {
1859 /* No room for another netagent UUID, bail */
1862 /* Calculate new array size */
1863 u_int32_t new_agent_count
=
1864 MIN(ifp
->if_agentcount
+ IF_AGENT_INCREMENT
,
1867 /* Reallocate array */
1868 uuid_t
*new_agent_array
= _REALLOC(ifp
->if_agentids
,
1869 sizeof(uuid_t
) * new_agent_count
, M_NETAGENT
,
1871 if (new_agent_array
== NULL
) {
1875 /* Save new array */
1876 ifp
->if_agentids
= new_agent_array
;
1878 /* Set first empty slot */
1880 &(ifp
->if_agentids
[ifp
->if_agentcount
]);
1882 /* Save new array length */
1883 ifp
->if_agentcount
= new_agent_count
;
1886 uuid_copy(*first_empty_slot
, new_agent_uuid
);
1887 netagent_post_updated_interfaces(new_agent_uuid
);
1892 if_add_netagent(struct ifnet
*ifp
, uuid_t new_agent_uuid
)
1894 VERIFY(ifp
!= NULL
);
1896 ifnet_lock_exclusive(ifp
);
1898 int error
= if_add_netagent_locked(ifp
, new_agent_uuid
);
1900 ifnet_lock_done(ifp
);
1906 if_delete_netagent_locked(struct ifnet
*ifp
, uuid_t remove_agent_uuid
)
1908 u_int32_t index
= 0;
1909 bool removed_agent_id
= FALSE
;
1911 if (ifp
->if_agentids
!= NULL
) {
1912 for (index
= 0; index
< ifp
->if_agentcount
; index
++) {
1913 uuid_t
*netagent_uuid
= &(ifp
->if_agentids
[index
]);
1914 if (uuid_compare(*netagent_uuid
,
1915 remove_agent_uuid
) == 0) {
1916 uuid_clear(*netagent_uuid
);
1917 removed_agent_id
= TRUE
;
1922 if (removed_agent_id
)
1923 netagent_post_updated_interfaces(remove_agent_uuid
);
1929 if_delete_netagent(struct ifnet
*ifp
, uuid_t remove_agent_uuid
)
1931 VERIFY(ifp
!= NULL
);
1933 ifnet_lock_exclusive(ifp
);
1935 int error
= if_delete_netagent_locked(ifp
, remove_agent_uuid
);
1937 ifnet_lock_done(ifp
);
1942 static __attribute__((noinline
)) int
1943 ifioctl_netagent(struct ifnet
*ifp
, u_long cmd
, caddr_t data
, struct proc
*p
)
1945 struct if_agentidreq
*ifar
= (struct if_agentidreq
*)(void *)data
;
1947 struct if_agentidsreq32 s32
;
1948 struct if_agentidsreq64 s64
;
1952 VERIFY(ifp
!= NULL
);
1954 /* Get an io ref count if the interface is attached */
1955 if (!ifnet_is_attached(ifp
, 1)) {
1956 return (EOPNOTSUPP
);
1959 if (cmd
== SIOCAIFAGENTID
||
1960 cmd
== SIOCDIFAGENTID
) {
1961 ifnet_lock_exclusive(ifp
);
1963 ifnet_lock_shared(ifp
);
1967 case SIOCAIFAGENTID
: { /* struct if_agentidreq */
1968 // TODO: Use priv_check_cred() instead of root check
1969 if ((error
= proc_suser(p
)) != 0) {
1972 error
= if_add_netagent_locked(ifp
, ifar
->ifar_uuid
);
1975 case SIOCDIFAGENTID
: { /* struct if_agentidreq */
1976 // TODO: Use priv_check_cred() instead of root check
1977 if ((error
= proc_suser(p
)) != 0) {
1980 error
= if_delete_netagent_locked(ifp
, ifar
->ifar_uuid
);
1983 case SIOCGIFAGENTIDS32
: { /* struct if_agentidsreq32 */
1984 bcopy(data
, &u
.s32
, sizeof(u
.s32
));
1985 error
= ifioctl_getnetagents(ifp
, &u
.s32
.ifar_count
,
1988 bcopy(&u
.s32
, data
, sizeof(u
.s32
));
1992 case SIOCGIFAGENTIDS64
: { /* struct if_agentidsreq64 */
1993 bcopy(data
, &u
.s64
, sizeof(u
.s64
));
1994 error
= ifioctl_getnetagents(ifp
, &u
.s64
.ifar_count
,
1997 bcopy(&u
.s64
, data
, sizeof(u
.s64
));
2006 ifnet_lock_done(ifp
);
2007 ifnet_decr_iorefcnt(ifp
);
2013 ifnet_clear_netagent(uuid_t netagent_uuid
)
2015 struct ifnet
*ifp
= NULL
;
2016 u_int32_t index
= 0;
2018 ifnet_head_lock_shared();
2020 TAILQ_FOREACH(ifp
, &ifnet_head
, if_link
) {
2021 ifnet_lock_shared(ifp
);
2022 if (ifp
->if_agentids
!= NULL
) {
2023 for (index
= 0; index
< ifp
->if_agentcount
; index
++) {
2024 uuid_t
*ifp_netagent_uuid
= &(ifp
->if_agentids
[index
]);
2025 if (uuid_compare(*ifp_netagent_uuid
, netagent_uuid
) == 0) {
2026 uuid_clear(*ifp_netagent_uuid
);
2030 ifnet_lock_done(ifp
);
2037 ifnet_increment_generation(ifnet_t interface
)
2039 OSIncrementAtomic(&interface
->if_generation
);
2043 ifnet_get_generation(ifnet_t interface
)
2045 return (interface
->if_generation
);
2049 ifnet_remove_from_ordered_list(struct ifnet
*ifp
)
2051 ifnet_head_assert_exclusive();
2054 TAILQ_REMOVE(&ifnet_ordered_head
, ifp
, if_ordered_link
);
2055 ifp
->if_ordered_link
.tqe_next
= NULL
;
2056 ifp
->if_ordered_link
.tqe_prev
= NULL
;
2058 // Update ordered count
2059 VERIFY(if_ordered_count
> 0);
2064 ifnet_reset_order(u_int32_t
*ordered_indices
, u_int32_t count
)
2066 struct ifnet
*ifp
= NULL
;
2069 ifnet_head_lock_exclusive();
2070 for (u_int32_t order_index
= 0; order_index
< count
; order_index
++) {
2071 if (ordered_indices
[order_index
] == IFSCOPE_NONE
||
2072 ordered_indices
[order_index
] > (uint32_t)if_index
) {
2078 // Flush current ordered list
2079 for (ifp
= TAILQ_FIRST(&ifnet_ordered_head
); ifp
!= NULL
;
2080 ifp
= TAILQ_FIRST(&ifnet_ordered_head
)) {
2081 ifnet_lock_exclusive(ifp
);
2082 ifnet_remove_from_ordered_list(ifp
);
2083 ifnet_lock_done(ifp
);
2086 VERIFY(if_ordered_count
== 0);
2088 for (u_int32_t order_index
= 0; order_index
< count
; order_index
++) {
2089 u_int32_t interface_index
= ordered_indices
[order_index
];
2090 ifp
= ifindex2ifnet
[interface_index
];
2094 ifnet_lock_exclusive(ifp
);
2095 TAILQ_INSERT_TAIL(&ifnet_ordered_head
, ifp
, if_ordered_link
);
2096 ifnet_lock_done(ifp
);
2102 necp_update_all_clients();
2108 if_set_qosmarking_mode(struct ifnet
*ifp
, u_int32_t mode
)
2111 u_int32_t old_mode
= ifp
->if_qosmarking_mode
;
2114 case IFRTYPE_QOSMARKING_MODE_NONE
:
2115 ifp
->if_qosmarking_mode
= IFRTYPE_QOSMARKING_MODE_NONE
;
2116 ifp
->if_eflags
&= ~IFEF_QOSMARKING_CAPABLE
;
2118 case IFRTYPE_QOSMARKING_FASTLANE
:
2119 ifp
->if_qosmarking_mode
= IFRTYPE_QOSMARKING_FASTLANE
;
2120 ifp
->if_eflags
|= IFEF_QOSMARKING_CAPABLE
;
2121 if (net_qos_policy_capable_enabled
!= 0)
2122 ifp
->if_eflags
|= IFEF_QOSMARKING_ENABLED
;
2128 if (error
== 0 && old_mode
!= ifp
->if_qosmarking_mode
) {
2129 dlil_post_msg(ifp
, KEV_DL_SUBCLASS
, KEV_DL_QOS_MODE_CHANGED
,
2130 NULL
, sizeof(struct kev_dl_rrc_state
));
2136 static __attribute__((noinline
)) int
2137 ifioctl_iforder(u_long cmd
, caddr_t data
)
2140 u_int32_t
*ordered_indices
= NULL
;
2146 case SIOCSIFORDER
: { /* struct if_order */
2147 struct if_order
*ifo
= (struct if_order
*)(void *)data
;
2149 if (ifo
->ifo_count
== 0 || ifo
->ifo_count
> (u_int32_t
)if_index
) {
2154 size_t length
= (ifo
->ifo_count
* sizeof(u_int32_t
));
2156 if (ifo
->ifo_ordered_indices
== USER_ADDR_NULL
) {
2160 ordered_indices
= _MALLOC(length
, M_NECP
, M_WAITOK
);
2161 if (ordered_indices
== NULL
) {
2166 error
= copyin(ifo
->ifo_ordered_indices
,
2167 ordered_indices
, length
);
2172 /* ordered_indices should not contain duplicates */
2173 bool found_duplicate
= FALSE
;
2174 for (uint32_t i
= 0; i
< (ifo
->ifo_count
- 1) && !found_duplicate
; i
++){
2175 for (uint32_t j
= i
+ 1; j
< ifo
->ifo_count
&& !found_duplicate
; j
++){
2176 if (ordered_indices
[j
] == ordered_indices
[i
]){
2178 found_duplicate
= TRUE
;
2183 if (found_duplicate
)
2186 error
= ifnet_reset_order(ordered_indices
, ifo
->ifo_count
);
2191 case SIOCGIFORDER
: { /* struct if_order */
2192 struct if_order
*ifo
= (struct if_order
*)(void *)data
;
2193 u_int32_t ordered_count
= *((volatile u_int32_t
*)&if_ordered_count
);
2195 if (ifo
->ifo_count
== 0 ||
2196 ordered_count
== 0) {
2198 } else if (ifo
->ifo_ordered_indices
!= USER_ADDR_NULL
) {
2199 u_int32_t count_to_copy
=
2200 MIN(ordered_count
, ifo
->ifo_count
);
2201 size_t length
= (count_to_copy
* sizeof(u_int32_t
));
2202 struct ifnet
*ifp
= NULL
;
2203 u_int32_t cursor
= 0;
2205 ordered_indices
= _MALLOC(length
, M_NECP
, M_WAITOK
| M_ZERO
);
2206 if (ordered_indices
== NULL
) {
2211 ifnet_head_lock_shared();
2212 TAILQ_FOREACH(ifp
, &ifnet_ordered_head
, if_ordered_link
) {
2213 if (cursor
>= count_to_copy
||
2214 cursor
>= if_ordered_count
) {
2217 ordered_indices
[cursor
] = ifp
->if_index
;
2222 /* We might have parsed less than the original length
2223 * because the list could have changed.
2225 length
= cursor
* sizeof(u_int32_t
);
2226 ifo
->ifo_count
= cursor
;
2227 error
= copyout(ordered_indices
,
2228 ifo
->ifo_ordered_indices
, length
);
2241 if (ordered_indices
!= NULL
) {
2242 _FREE(ordered_indices
, M_NECP
);
2248 static __attribute__((noinline
)) int
2249 ifioctl_netsignature(struct ifnet
*ifp
, u_long cmd
, caddr_t data
)
2251 struct if_nsreq
*ifnsr
= (struct if_nsreq
*)(void *)data
;
2255 VERIFY(ifp
!= NULL
);
2258 case SIOCSIFNETSIGNATURE
: /* struct if_nsreq */
2259 if (ifnsr
->ifnsr_len
> sizeof (ifnsr
->ifnsr_data
)) {
2263 bcopy(&ifnsr
->ifnsr_flags
, &flags
, sizeof (flags
));
2264 error
= ifnet_set_netsignature(ifp
, ifnsr
->ifnsr_family
,
2265 ifnsr
->ifnsr_len
, flags
, ifnsr
->ifnsr_data
);
2268 case SIOCGIFNETSIGNATURE
: /* struct if_nsreq */
2269 ifnsr
->ifnsr_len
= sizeof (ifnsr
->ifnsr_data
);
2270 error
= ifnet_get_netsignature(ifp
, ifnsr
->ifnsr_family
,
2271 &ifnsr
->ifnsr_len
, &flags
, ifnsr
->ifnsr_data
);
2273 bcopy(&flags
, &ifnsr
->ifnsr_flags
, sizeof (flags
));
2275 ifnsr
->ifnsr_len
= 0;
2287 static __attribute__((noinline
)) int
2288 ifioctl_nat64prefix(struct ifnet
*ifp
, u_long cmd
, caddr_t data
)
2290 struct if_nat64req
*ifnat64
= (struct if_nat64req
*)(void *)data
;
2293 VERIFY(ifp
!= NULL
);
2296 case SIOCSIFNAT64PREFIX
: /* struct if_nat64req */
2297 error
= ifnet_set_nat64prefix(ifp
, ifnat64
->ifnat64_prefixes
);
2300 case SIOCGIFNAT64PREFIX
: /* struct if_nat64req */
2301 error
= ifnet_get_nat64prefix(ifp
, ifnat64
->ifnat64_prefixes
);
2315 * List the ioctl()s we can perform on restricted INTCOPROC interfaces.
2318 ifioctl_restrict_intcoproc(unsigned long cmd
, const char *ifname
,
2319 struct ifnet
*ifp
, struct proc
*p
)
2322 if (intcoproc_unrestricted
== TRUE
) {
2325 if (proc_pid(p
) == 0) {
2329 ifp
= ifunit(ifname
);
2334 if (!IFNET_IS_INTCOPROC(ifp
)) {
2338 case SIOCGIFBRDADDR
:
2349 case SIOCGIFFUNCTIONALTYPE
:
2350 case SIOCGIFPSRCADDR
:
2351 case SIOCGIFPDSTADDR
:
2352 case SIOCGIFGENERIC
:
2356 case SIOCGIFWAKEFLAGS
:
2357 case SIOCGIFGETRTREFCNT
:
2358 case SIOCGIFOPPORTUNISTIC
:
2359 case SIOCGIFLINKQUALITYMETRIC
:
2361 case SIOCGIFDELEGATE
:
2362 case SIOCGIFEXPENSIVE
:
2363 case SIOCGIFINTERFACESTATE
:
2364 case SIOCGIFPROBECONNECTIVITY
:
2365 case SIOCGIFTIMESTAMPENABLED
:
2367 case SIOCGQOSMARKINGMODE
:
2368 case SIOCGQOSMARKINGENABLED
:
2369 case SIOCGIFLOWINTERNET
:
2371 case SIOCGIFMEDIA32
:
2372 case SIOCGIFMEDIA64
:
2374 case SIOCGIFLINKPARAMS
:
2375 case SIOCGIFQUEUESTATS
:
2376 case SIOCGIFTHROTTLE
:
2377 case SIOCGIFAGENTIDS32
:
2378 case SIOCGIFAGENTIDS64
:
2379 case SIOCGIFNETSIGNATURE
:
2380 case SIOCGIFINFO_IN6
:
2381 case SIOCGIFAFLAG_IN6
:
2382 case SIOCGNBRINFO_IN6
:
2383 case SIOCGIFALIFETIME_IN6
:
2384 case SIOCGIFNETMASK_IN6
:
2387 #if (DEBUG || DEVELOPMENT)
2388 printf("%s: cmd 0x%lx not allowed (pid %u)\n",
2389 __func__
, cmd
, proc_pid(p
));
2399 * Most of the routines called to handle the ioctls would end up being
2400 * tail-call optimized, which unfortunately causes this routine to
2401 * consume too much stack space; this is the reason for the "noinline"
2402 * attribute used on those routines.
2405 ifioctl(struct socket
*so
, u_long cmd
, caddr_t data
, struct proc
*p
)
2407 char ifname
[IFNAMSIZ
+ 1];
2408 struct ifnet
*ifp
= NULL
;
2409 struct ifstat
*ifs
= NULL
;
2412 bzero(ifname
, sizeof (ifname
));
2415 * ioctls which don't require ifp, or ifreq ioctls
2418 case OSIOCGIFCONF32
: /* struct ifconf32 */
2419 case SIOCGIFCONF32
: /* struct ifconf32 */
2420 case SIOCGIFCONF64
: /* struct ifconf64 */
2421 case OSIOCGIFCONF64
: /* struct ifconf64 */
2422 error
= ifioctl_ifconf(cmd
, data
);
2425 case SIOCIFGCLONERS32
: /* struct if_clonereq32 */
2426 case SIOCIFGCLONERS64
: /* struct if_clonereq64 */
2427 error
= ifioctl_ifclone(cmd
, data
);
2430 case SIOCGIFAGENTDATA32
: /* struct netagent_req32 */
2431 case SIOCGIFAGENTDATA64
: /* struct netagent_req64 */
2432 case SIOCGIFAGENTLIST32
: /* struct netagentlist_req32 */
2433 case SIOCGIFAGENTLIST64
: /* struct netagentlist_req64 */
2434 error
= netagent_ioctl(cmd
, data
);
2437 case SIOCSIFORDER
: /* struct if_order */
2438 case SIOCGIFORDER
: /* struct if_order */
2439 error
= ifioctl_iforder(cmd
, data
);
2442 case SIOCSIFDSTADDR
: /* struct ifreq */
2443 case SIOCSIFADDR
: /* struct ifreq */
2444 case SIOCSIFBRDADDR
: /* struct ifreq */
2445 case SIOCSIFNETMASK
: /* struct ifreq */
2446 case OSIOCGIFADDR
: /* struct ifreq */
2447 case OSIOCGIFDSTADDR
: /* struct ifreq */
2448 case OSIOCGIFBRDADDR
: /* struct ifreq */
2449 case OSIOCGIFNETMASK
: /* struct ifreq */
2450 case SIOCSIFKPI
: /* struct ifreq */
2451 if (so
->so_proto
== NULL
) {
2456 case SIOCIFCREATE
: /* struct ifreq */
2457 case SIOCIFCREATE2
: /* struct ifreq */
2458 case SIOCIFDESTROY
: /* struct ifreq */
2459 case SIOCGIFFLAGS
: /* struct ifreq */
2460 case SIOCGIFEFLAGS
: /* struct ifreq */
2461 case SIOCGIFCAP
: /* struct ifreq */
2463 case SIOCGIFMAC
: /* struct ifreq */
2464 case SIOCSIFMAC
: /* struct ifreq */
2465 #endif /* CONFIG_MACF_NET */
2466 case SIOCGIFMETRIC
: /* struct ifreq */
2467 case SIOCGIFMTU
: /* struct ifreq */
2468 case SIOCGIFPHYS
: /* struct ifreq */
2469 case SIOCSIFFLAGS
: /* struct ifreq */
2470 case SIOCSIFCAP
: /* struct ifreq */
2471 case SIOCSIFMETRIC
: /* struct ifreq */
2472 case SIOCSIFPHYS
: /* struct ifreq */
2473 case SIOCSIFMTU
: /* struct ifreq */
2474 case SIOCADDMULTI
: /* struct ifreq */
2475 case SIOCDELMULTI
: /* struct ifreq */
2476 case SIOCDIFPHYADDR
: /* struct ifreq */
2477 case SIOCSIFMEDIA
: /* struct ifreq */
2478 case SIOCSIFGENERIC
: /* struct ifreq */
2479 case SIOCSIFLLADDR
: /* struct ifreq */
2480 case SIOCSIFALTMTU
: /* struct ifreq */
2481 case SIOCSIFVLAN
: /* struct ifreq */
2482 case SIOCSIFBOND
: /* struct ifreq */
2483 case SIOCGIFLLADDR
: /* struct ifreq */
2484 case SIOCGIFTYPE
: /* struct ifreq */
2485 case SIOCGIFFUNCTIONALTYPE
: /* struct ifreq */
2486 case SIOCGIFPSRCADDR
: /* struct ifreq */
2487 case SIOCGIFPDSTADDR
: /* struct ifreq */
2488 case SIOCGIFGENERIC
: /* struct ifreq */
2489 case SIOCGIFDEVMTU
: /* struct ifreq */
2490 case SIOCGIFVLAN
: /* struct ifreq */
2491 case SIOCGIFBOND
: /* struct ifreq */
2492 case SIOCGIFWAKEFLAGS
: /* struct ifreq */
2493 case SIOCGIFGETRTREFCNT
: /* struct ifreq */
2494 case SIOCSIFOPPORTUNISTIC
: /* struct ifreq */
2495 case SIOCGIFOPPORTUNISTIC
: /* struct ifreq */
2496 case SIOCGIFLINKQUALITYMETRIC
: /* struct ifreq */
2497 case SIOCSIFLOG
: /* struct ifreq */
2498 case SIOCGIFLOG
: /* struct ifreq */
2499 case SIOCGIFDELEGATE
: /* struct ifreq */
2500 case SIOCGIFEXPENSIVE
: /* struct ifreq */
2501 case SIOCSIFEXPENSIVE
: /* struct ifreq */
2502 case SIOCSIF2KCL
: /* struct ifreq */
2503 case SIOCGIF2KCL
: /* struct ifreq */
2504 case SIOCSIFINTERFACESTATE
: /* struct ifreq */
2505 case SIOCGIFINTERFACESTATE
: /* struct ifreq */
2506 case SIOCSIFPROBECONNECTIVITY
: /* struct ifreq */
2507 case SIOCGIFPROBECONNECTIVITY
: /* struct ifreq */
2508 case SIOCGSTARTDELAY
: /* struct ifreq */
2509 case SIOCSIFTIMESTAMPENABLE
: /* struct ifreq */
2510 case SIOCSIFTIMESTAMPDISABLE
: /* struct ifreq */
2511 case SIOCGIFTIMESTAMPENABLED
: /* struct ifreq */
2512 #if (DEBUG || DEVELOPMENT)
2513 case SIOCSIFDISABLEOUTPUT
: /* struct ifreq */
2514 #endif /* (DEBUG || DEVELOPMENT) */
2515 case SIOCGECNMODE
: /* struct ifreq */
2517 case SIOCSQOSMARKINGMODE
: /* struct ifreq */
2518 case SIOCSQOSMARKINGENABLED
: /* struct ifreq */
2519 case SIOCGQOSMARKINGMODE
: /* struct ifreq */
2520 case SIOCGQOSMARKINGENABLED
: /* struct ifreq */
2521 case SIOCSIFLOWINTERNET
: /* struct ifreq */
2522 case SIOCGIFLOWINTERNET
: /* struct ifreq */
2523 { /* struct ifreq */
2525 bcopy(data
, &ifr
, sizeof (ifr
));
2526 ifr
.ifr_name
[IFNAMSIZ
- 1] = '\0';
2527 bcopy(&ifr
.ifr_name
, ifname
, IFNAMSIZ
);
2528 if (ifioctl_restrict_intcoproc(cmd
, ifname
, NULL
, p
) == true) {
2532 error
= ifioctl_ifreq(so
, cmd
, &ifr
, p
);
2533 bcopy(&ifr
, data
, sizeof (ifr
));
2539 * ioctls which require ifp. Note that we acquire dlil_ifnet_lock
2540 * here to ensure that the ifnet, if found, has been fully attached.
2544 case SIOCSIFPHYADDR
: /* struct {if,in_}aliasreq */
2545 bcopy(((struct in_aliasreq
*)(void *)data
)->ifra_name
,
2547 ifp
= ifunit(ifname
);
2551 case SIOCSIFPHYADDR_IN6_32
: /* struct in6_aliasreq_32 */
2552 bcopy(((struct in6_aliasreq_32
*)(void *)data
)->ifra_name
,
2554 ifp
= ifunit(ifname
);
2557 case SIOCSIFPHYADDR_IN6_64
: /* struct in6_aliasreq_64 */
2558 bcopy(((struct in6_aliasreq_64
*)(void *)data
)->ifra_name
,
2560 ifp
= ifunit(ifname
);
2564 case SIOCGIFSTATUS
: /* struct ifstat */
2565 ifs
= _MALLOC(sizeof (*ifs
), M_DEVBUF
, M_WAITOK
);
2571 bcopy(data
, ifs
, sizeof (*ifs
));
2572 ifs
->ifs_name
[IFNAMSIZ
- 1] = '\0';
2573 bcopy(ifs
->ifs_name
, ifname
, IFNAMSIZ
);
2574 ifp
= ifunit(ifname
);
2577 case SIOCGIFMEDIA32
: /* struct ifmediareq32 */
2578 bcopy(((struct ifmediareq32
*)(void *)data
)->ifm_name
,
2580 ifp
= ifunit(ifname
);
2583 case SIOCGIFMEDIA64
: /* struct ifmediareq64 */
2584 bcopy(((struct ifmediareq64
*)(void *)data
)->ifm_name
,
2586 ifp
= ifunit(ifname
);
2589 case SIOCSIFDESC
: /* struct if_descreq */
2590 case SIOCGIFDESC
: /* struct if_descreq */
2591 bcopy(((struct if_descreq
*)(void *)data
)->ifdr_name
,
2593 ifp
= ifunit(ifname
);
2596 case SIOCSIFLINKPARAMS
: /* struct if_linkparamsreq */
2597 case SIOCGIFLINKPARAMS
: /* struct if_linkparamsreq */
2598 bcopy(((struct if_linkparamsreq
*)(void *)data
)->iflpr_name
,
2600 ifp
= ifunit(ifname
);
2603 case SIOCGIFQUEUESTATS
: /* struct if_qstatsreq */
2604 bcopy(((struct if_qstatsreq
*)(void *)data
)->ifqr_name
,
2606 ifp
= ifunit(ifname
);
2609 case SIOCSIFTHROTTLE
: /* struct if_throttlereq */
2610 case SIOCGIFTHROTTLE
: /* struct if_throttlereq */
2611 bcopy(((struct if_throttlereq
*)(void *)data
)->ifthr_name
,
2613 ifp
= ifunit(ifname
);
2616 case SIOCAIFAGENTID
: /* struct if_agentidreq */
2617 case SIOCDIFAGENTID
: /* struct if_agentidreq */
2618 case SIOCGIFAGENTIDS32
: /* struct if_agentidsreq32 */
2619 case SIOCGIFAGENTIDS64
: /* struct if_agentidsreq64 */
2620 bcopy(((struct if_agentidreq
*)(void *)data
)->ifar_name
,
2622 ifp
= ifunit(ifname
);
2625 case SIOCSIFNETSIGNATURE
: /* struct if_nsreq */
2626 case SIOCGIFNETSIGNATURE
: /* struct if_nsreq */
2627 bcopy(((struct if_nsreq
*)(void *)data
)->ifnsr_name
,
2629 ifp
= ifunit(ifname
);
2634 * This is a bad assumption, but the code seems to
2635 * have been doing this in the past; caveat emptor.
2637 bcopy(((struct ifreq
*)(void *)data
)->ifr_name
,
2639 ifp
= ifunit(ifname
);
2649 if (ifioctl_restrict_intcoproc(cmd
, NULL
, ifp
, p
) == true) {
2654 case SIOCSIFPHYADDR
: /* struct {if,in_}aliasreq */
2656 case SIOCSIFPHYADDR_IN6_32
: /* struct in6_aliasreq_32 */
2657 case SIOCSIFPHYADDR_IN6_64
: /* struct in6_aliasreq_64 */
2659 error
= proc_suser(p
);
2663 error
= ifnet_ioctl(ifp
, SOCK_DOM(so
), cmd
, data
);
2667 ifnet_touch_lastchange(ifp
);
2670 case SIOCGIFSTATUS
: /* struct ifstat */
2671 VERIFY(ifs
!= NULL
);
2672 ifs
->ascii
[0] = '\0';
2674 error
= ifnet_ioctl(ifp
, SOCK_DOM(so
), cmd
, (caddr_t
)ifs
);
2676 bcopy(ifs
, data
, sizeof (*ifs
));
2679 case SIOCGIFMEDIA32
: /* struct ifmediareq32 */
2680 case SIOCGIFMEDIA64
: /* struct ifmediareq64 */
2681 error
= ifnet_ioctl(ifp
, SOCK_DOM(so
), cmd
, data
);
2684 case SIOCSIFDESC
: /* struct if_descreq */
2685 case SIOCGIFDESC
: /* struct if_descreq */
2686 error
= ifioctl_ifdesc(ifp
, cmd
, data
, p
);
2689 case SIOCSIFLINKPARAMS
: /* struct if_linkparamsreq */
2690 case SIOCGIFLINKPARAMS
: /* struct if_linkparamsreq */
2691 error
= ifioctl_linkparams(ifp
, cmd
, data
, p
);
2694 case SIOCGIFQUEUESTATS
: /* struct if_qstatsreq */
2695 error
= ifioctl_qstats(ifp
, cmd
, data
);
2698 case SIOCSIFTHROTTLE
: /* struct if_throttlereq */
2699 case SIOCGIFTHROTTLE
: /* struct if_throttlereq */
2700 error
= ifioctl_throttle(ifp
, cmd
, data
, p
);
2703 case SIOCAIFAGENTID
: /* struct if_agentidreq */
2704 case SIOCDIFAGENTID
: /* struct if_agentidreq */
2705 case SIOCGIFAGENTIDS32
: /* struct if_agentidsreq32 */
2706 case SIOCGIFAGENTIDS64
: /* struct if_agentidsreq64 */
2707 error
= ifioctl_netagent(ifp
, cmd
, data
, p
);
2710 case SIOCSIFNETSIGNATURE
: /* struct if_nsreq */
2711 case SIOCGIFNETSIGNATURE
: /* struct if_nsreq */
2712 error
= ifioctl_netsignature(ifp
, cmd
, data
);
2716 case SIOCSIFNAT64PREFIX
: /* struct if_nsreq */
2717 case SIOCGIFNAT64PREFIX
: /* struct if_nsreq */
2718 error
= ifioctl_nat64prefix(ifp
, cmd
, data
);
2722 if (so
->so_proto
== NULL
) {
2728 error
= ((*so
->so_proto
->pr_usrreqs
->pru_control
)(so
, cmd
,
2730 socket_unlock(so
, 1);
2732 if (error
== EOPNOTSUPP
|| error
== ENOTSUP
) {
2733 error
= ifnet_ioctl(ifp
, SOCK_DOM(so
), cmd
, data
);
2740 _FREE(ifs
, M_DEVBUF
);
2743 if (ifname
[0] == '\0')
2744 (void) snprintf(ifname
, sizeof (ifname
), "%s",
2746 else if (ifp
!= NULL
)
2747 (void) snprintf(ifname
, sizeof (ifname
), "%s",
2751 printf("%s[%s,%d]: ifp %s cmd 0x%08lx (%c%c [%lu] "
2752 "%c %lu) error %d\n", __func__
,
2753 proc_name_address(p
), proc_pid(p
),
2754 ifname
, cmd
, (cmd
& IOC_IN
) ? 'I' : ' ',
2755 (cmd
& IOC_OUT
) ? 'O' : ' ', IOCPARM_LEN(cmd
),
2756 (char)IOCGROUP(cmd
), cmd
& 0xff, error
);
2757 } else if (if_verbose
> 1) {
2758 printf("%s[%s,%d]: ifp %s cmd 0x%08lx (%c%c [%lu] "
2759 "%c %lu) OK\n", __func__
,
2760 proc_name_address(p
), proc_pid(p
),
2761 ifname
, cmd
, (cmd
& IOC_IN
) ? 'I' : ' ',
2762 (cmd
& IOC_OUT
) ? 'O' : ' ', IOCPARM_LEN(cmd
),
2763 (char)IOCGROUP(cmd
), cmd
& 0xff);
2770 static __attribute__((noinline
)) int
2771 ifioctl_ifreq(struct socket
*so
, u_long cmd
, struct ifreq
*ifr
, struct proc
*p
)
2776 struct kev_msg ev_msg
;
2777 struct net_event_data ev_data
;
2779 bzero(&ev_data
, sizeof (struct net_event_data
));
2780 bzero(&ev_msg
, sizeof (struct kev_msg
));
2785 error
= proc_suser(p
);
2788 return (if_clone_create(ifr
->ifr_name
, sizeof(ifr
->ifr_name
),
2789 cmd
== SIOCIFCREATE2
? ifr
->ifr_data
: NULL
));
2791 error
= proc_suser(p
);
2794 return (if_clone_destroy(ifr
->ifr_name
));
2798 * ioctls which require ifp. Note that we acquire dlil_ifnet_lock
2799 * here to ensure that the ifnet, if found, has been fully attached.
2802 ifp
= ifunit(ifr
->ifr_name
);
2810 ifnet_lock_shared(ifp
);
2811 ifr
->ifr_flags
= ifp
->if_flags
;
2812 ifnet_lock_done(ifp
);
2816 ifnet_lock_shared(ifp
);
2817 ifr
->ifr_eflags
= ifp
->if_eflags
;
2818 ifnet_lock_done(ifp
);
2822 ifnet_lock_shared(ifp
);
2823 ifr
->ifr_reqcap
= ifp
->if_capabilities
;
2824 ifr
->ifr_curcap
= ifp
->if_capenable
;
2825 ifnet_lock_done(ifp
);
2830 error
= mac_ifnet_label_get(kauth_cred_get(), ifr
, ifp
);
2834 error
= mac_ifnet_label_set(kauth_cred_get(), ifr
, ifp
);
2836 #endif /* CONFIG_MACF_NET */
2839 ifnet_lock_shared(ifp
);
2840 ifr
->ifr_metric
= ifp
->if_metric
;
2841 ifnet_lock_done(ifp
);
2845 ifnet_lock_shared(ifp
);
2846 ifr
->ifr_mtu
= ifp
->if_mtu
;
2847 ifnet_lock_done(ifp
);
2851 ifnet_lock_shared(ifp
);
2852 ifr
->ifr_phys
= ifp
->if_physical
;
2853 ifnet_lock_done(ifp
);
2857 error
= proc_suser(p
);
2861 (void) ifnet_set_flags(ifp
, ifr
->ifr_flags
,
2862 (u_int16_t
)~IFF_CANTCHANGE
);
2865 * Note that we intentionally ignore any error from below
2866 * for the SIOCSIFFLAGS case.
2868 (void) ifnet_ioctl(ifp
, SOCK_DOM(so
), cmd
, (caddr_t
)ifr
);
2871 * Send the event even upon error from the driver because
2872 * we changed the flags.
2874 ev_msg
.vendor_code
= KEV_VENDOR_APPLE
;
2875 ev_msg
.kev_class
= KEV_NETWORK_CLASS
;
2876 ev_msg
.kev_subclass
= KEV_DL_SUBCLASS
;
2878 ev_msg
.event_code
= KEV_DL_SIFFLAGS
;
2879 strlcpy(&ev_data
.if_name
[0], ifp
->if_name
, IFNAMSIZ
);
2880 ev_data
.if_family
= ifp
->if_family
;
2881 ev_data
.if_unit
= (u_int32_t
) ifp
->if_unit
;
2882 ev_msg
.dv
[0].data_length
= sizeof(struct net_event_data
);
2883 ev_msg
.dv
[0].data_ptr
= &ev_data
;
2884 ev_msg
.dv
[1].data_length
= 0;
2885 dlil_post_complete_msg(ifp
, &ev_msg
);
2887 ifnet_touch_lastchange(ifp
);
2891 error
= proc_suser(p
);
2895 if ((ifr
->ifr_reqcap
& ~ifp
->if_capabilities
)) {
2899 error
= ifnet_ioctl(ifp
, SOCK_DOM(so
), cmd
, (caddr_t
)ifr
);
2901 ifnet_touch_lastchange(ifp
);
2905 error
= proc_suser(p
);
2909 ifp
->if_metric
= ifr
->ifr_metric
;
2911 ev_msg
.vendor_code
= KEV_VENDOR_APPLE
;
2912 ev_msg
.kev_class
= KEV_NETWORK_CLASS
;
2913 ev_msg
.kev_subclass
= KEV_DL_SUBCLASS
;
2915 ev_msg
.event_code
= KEV_DL_SIFMETRICS
;
2916 strlcpy(&ev_data
.if_name
[0], ifp
->if_name
, IFNAMSIZ
);
2917 ev_data
.if_family
= ifp
->if_family
;
2918 ev_data
.if_unit
= (u_int32_t
) ifp
->if_unit
;
2919 ev_msg
.dv
[0].data_length
= sizeof(struct net_event_data
);
2920 ev_msg
.dv
[0].data_ptr
= &ev_data
;
2922 ev_msg
.dv
[1].data_length
= 0;
2923 dlil_post_complete_msg(ifp
, &ev_msg
);
2925 ifnet_touch_lastchange(ifp
);
2929 error
= proc_suser(p
);
2933 error
= ifnet_ioctl(ifp
, SOCK_DOM(so
), cmd
, (caddr_t
)ifr
);
2937 ev_msg
.vendor_code
= KEV_VENDOR_APPLE
;
2938 ev_msg
.kev_class
= KEV_NETWORK_CLASS
;
2939 ev_msg
.kev_subclass
= KEV_DL_SUBCLASS
;
2941 ev_msg
.event_code
= KEV_DL_SIFPHYS
;
2942 strlcpy(&ev_data
.if_name
[0], ifp
->if_name
, IFNAMSIZ
);
2943 ev_data
.if_family
= ifp
->if_family
;
2944 ev_data
.if_unit
= (u_int32_t
) ifp
->if_unit
;
2945 ev_msg
.dv
[0].data_length
= sizeof(struct net_event_data
);
2946 ev_msg
.dv
[0].data_ptr
= &ev_data
;
2947 ev_msg
.dv
[1].data_length
= 0;
2948 dlil_post_complete_msg(ifp
, &ev_msg
);
2950 ifnet_touch_lastchange(ifp
);
2954 u_int32_t oldmtu
= ifp
->if_mtu
;
2955 struct ifclassq
*ifq
= &ifp
->if_snd
;
2957 error
= proc_suser(p
);
2961 if (ifp
->if_ioctl
== NULL
) {
2965 if (ifr
->ifr_mtu
< IF_MINMTU
|| ifr
->ifr_mtu
> IF_MAXMTU
) {
2969 error
= ifnet_ioctl(ifp
, SOCK_DOM(so
), cmd
, (caddr_t
)ifr
);
2973 ev_msg
.vendor_code
= KEV_VENDOR_APPLE
;
2974 ev_msg
.kev_class
= KEV_NETWORK_CLASS
;
2975 ev_msg
.kev_subclass
= KEV_DL_SUBCLASS
;
2977 ev_msg
.event_code
= KEV_DL_SIFMTU
;
2978 strlcpy(&ev_data
.if_name
[0], ifp
->if_name
, IFNAMSIZ
);
2979 ev_data
.if_family
= ifp
->if_family
;
2980 ev_data
.if_unit
= (u_int32_t
) ifp
->if_unit
;
2981 ev_msg
.dv
[0].data_length
= sizeof(struct net_event_data
);
2982 ev_msg
.dv
[0].data_ptr
= &ev_data
;
2983 ev_msg
.dv
[1].data_length
= 0;
2984 dlil_post_complete_msg(ifp
, &ev_msg
);
2986 ifnet_touch_lastchange(ifp
);
2990 * If the link MTU changed, do network layer specific procedure
2991 * and update all route entries associated with the interface,
2992 * so that their MTU metric gets updated.
2994 if (ifp
->if_mtu
!= oldmtu
) {
2995 if_rtmtu_update(ifp
);
2999 /* Inform all transmit queues about the new MTU */
3001 ifnet_update_sndq(ifq
, CLASSQ_EV_LINK_MTU
);
3009 error
= proc_suser(p
);
3013 /* Don't allow group membership on non-multicast interfaces. */
3014 if ((ifp
->if_flags
& IFF_MULTICAST
) == 0) {
3019 /* Don't let users screw up protocols' entries. */
3020 if (ifr
->ifr_addr
.sa_family
!= AF_UNSPEC
&&
3021 ifr
->ifr_addr
.sa_family
!= AF_LINK
) {
3027 * User is permitted to anonymously join a particular link
3028 * multicast group via SIOCADDMULTI. Subsequent join requested
3029 * for the same record which has an outstanding refcnt from a
3030 * past if_addmulti_anon() will not result in EADDRINUSE error
3031 * (unlike other BSDs.) Anonymously leaving a group is also
3032 * allowed only as long as there is an outstanding refcnt held
3033 * by a previous anonymous request, or else ENOENT (even if the
3034 * link-layer multicast membership exists for a network-layer
3037 if (cmd
== SIOCADDMULTI
) {
3038 error
= if_addmulti_anon(ifp
, &ifr
->ifr_addr
, NULL
);
3039 ev_msg
.event_code
= KEV_DL_ADDMULTI
;
3041 error
= if_delmulti_anon(ifp
, &ifr
->ifr_addr
);
3042 ev_msg
.event_code
= KEV_DL_DELMULTI
;
3047 ev_msg
.vendor_code
= KEV_VENDOR_APPLE
;
3048 ev_msg
.kev_class
= KEV_NETWORK_CLASS
;
3049 ev_msg
.kev_subclass
= KEV_DL_SUBCLASS
;
3050 strlcpy(&ev_data
.if_name
[0], ifp
->if_name
, IFNAMSIZ
);
3052 ev_data
.if_family
= ifp
->if_family
;
3053 ev_data
.if_unit
= (u_int32_t
) ifp
->if_unit
;
3054 ev_msg
.dv
[0].data_length
= sizeof(struct net_event_data
);
3055 ev_msg
.dv
[0].data_ptr
= &ev_data
;
3056 ev_msg
.dv
[1].data_length
= 0;
3057 dlil_post_complete_msg(ifp
, &ev_msg
);
3059 ifnet_touch_lastchange(ifp
);
3062 case SIOCDIFPHYADDR
:
3064 case SIOCSIFGENERIC
:
3069 error
= proc_suser(p
);
3073 error
= ifnet_ioctl(ifp
, SOCK_DOM(so
), cmd
, (caddr_t
)ifr
);
3077 ifnet_touch_lastchange(ifp
);
3080 case SIOCGIFLLADDR
: {
3081 struct sockaddr_dl
*sdl
= SDL(ifp
->if_lladdr
->ifa_addr
);
3083 if (sdl
->sdl_alen
== 0) {
3084 error
= EADDRNOTAVAIL
;
3087 /* If larger than 14-bytes we'll need another mechanism */
3088 if (sdl
->sdl_alen
> sizeof (ifr
->ifr_addr
.sa_data
)) {
3092 /* Follow the same convention used by SIOCSIFLLADDR */
3093 bzero(&ifr
->ifr_addr
, sizeof (ifr
->ifr_addr
));
3094 ifr
->ifr_addr
.sa_family
= AF_LINK
;
3095 ifr
->ifr_addr
.sa_len
= sdl
->sdl_alen
;
3096 error
= ifnet_guarded_lladdr_copy_bytes(ifp
,
3097 &ifr
->ifr_addr
.sa_data
, sdl
->sdl_alen
);
3102 ifr
->ifr_type
.ift_type
= ifp
->if_type
;
3103 ifr
->ifr_type
.ift_family
= ifp
->if_family
;
3104 ifr
->ifr_type
.ift_subfamily
= ifp
->if_subfamily
;
3107 case SIOCGIFFUNCTIONALTYPE
:
3108 ifr
->ifr_functional_type
= if_functional_type(ifp
, FALSE
);
3111 case SIOCGIFPSRCADDR
:
3112 case SIOCGIFPDSTADDR
:
3113 case SIOCGIFGENERIC
:
3117 error
= ifnet_ioctl(ifp
, SOCK_DOM(so
), cmd
, (caddr_t
)ifr
);
3120 case SIOCGIFWAKEFLAGS
:
3121 ifnet_lock_shared(ifp
);
3122 ifr
->ifr_wake_flags
= ifnet_get_wake_flags(ifp
);
3123 ifnet_lock_done(ifp
);
3126 case SIOCGIFGETRTREFCNT
:
3127 ifnet_lock_shared(ifp
);
3128 ifr
->ifr_route_refcnt
= ifp
->if_route_refcnt
;
3129 ifnet_lock_done(ifp
);
3132 case SIOCSIFOPPORTUNISTIC
:
3133 case SIOCGIFOPPORTUNISTIC
:
3134 error
= ifnet_getset_opportunistic(ifp
, cmd
, ifr
, p
);
3137 case SIOCGIFLINKQUALITYMETRIC
:
3138 ifnet_lock_shared(ifp
);
3139 if ((ifp
->if_interface_state
.valid_bitmask
&
3140 IF_INTERFACE_STATE_LQM_STATE_VALID
)) {
3141 ifr
->ifr_link_quality_metric
=
3142 ifp
->if_interface_state
.lqm_state
;
3143 } else if (IF_FULLY_ATTACHED(ifp
)) {
3144 ifr
->ifr_link_quality_metric
=
3145 IFNET_LQM_THRESH_UNKNOWN
;
3147 ifr
->ifr_link_quality_metric
=
3148 IFNET_LQM_THRESH_OFF
;
3150 ifnet_lock_done(ifp
);
3155 error
= ifnet_getset_log(ifp
, cmd
, ifr
, p
);
3158 case SIOCGIFDELEGATE
:
3159 ifnet_lock_shared(ifp
);
3160 ifr
->ifr_delegated
= ((ifp
->if_delegated
.ifp
!= NULL
) ?
3161 ifp
->if_delegated
.ifp
->if_index
: 0);
3162 ifnet_lock_done(ifp
);
3165 case SIOCGIFEXPENSIVE
:
3166 ifnet_lock_shared(ifp
);
3167 if (ifp
->if_eflags
& IFEF_EXPENSIVE
)
3168 ifr
->ifr_expensive
= 1;
3170 ifr
->ifr_expensive
= 0;
3171 ifnet_lock_done(ifp
);
3174 case SIOCSIFEXPENSIVE
:
3178 if ((error
= priv_check_cred(kauth_cred_get(),
3179 PRIV_NET_INTERFACE_CONTROL
, 0)) != 0)
3181 ifnet_lock_exclusive(ifp
);
3182 if (ifr
->ifr_expensive
)
3183 ifp
->if_eflags
|= IFEF_EXPENSIVE
;
3185 ifp
->if_eflags
&= ~IFEF_EXPENSIVE
;
3186 ifnet_lock_done(ifp
);
3188 * Update the expensive bit in the delegated interface
3191 ifnet_head_lock_shared();
3192 TAILQ_FOREACH(difp
, &ifnet_head
, if_link
) {
3193 ifnet_lock_exclusive(difp
);
3194 if (difp
->if_delegated
.ifp
== ifp
) {
3195 difp
->if_delegated
.expensive
=
3196 ifp
->if_eflags
& IFEF_EXPENSIVE
? 1 : 0;
3199 ifnet_lock_done(difp
);
3206 ifnet_lock_shared(ifp
);
3207 if (ifp
->if_eflags
& IFEF_2KCL
)
3211 ifnet_lock_done(ifp
);
3215 if ((error
= priv_check_cred(kauth_cred_get(),
3216 PRIV_NET_INTERFACE_CONTROL
, 0)) != 0)
3218 ifnet_lock_exclusive(ifp
);
3220 ifp
->if_eflags
|= IFEF_2KCL
;
3222 ifp
->if_eflags
&= ~IFEF_2KCL
;
3223 ifnet_lock_done(ifp
);
3225 case SIOCGSTARTDELAY
:
3226 ifnet_lock_shared(ifp
);
3227 if (ifp
->if_eflags
& IFEF_ENQUEUE_MULTI
) {
3228 ifr
->ifr_start_delay_qlen
=
3229 ifp
->if_start_delay_qlen
;
3230 ifr
->ifr_start_delay_timeout
=
3231 ifp
->if_start_delay_timeout
;
3233 ifr
->ifr_start_delay_qlen
= 0;
3234 ifr
->ifr_start_delay_timeout
= 0;
3236 ifnet_lock_done(ifp
);
3238 case SIOCSIFDSTADDR
:
3240 case SIOCSIFBRDADDR
:
3241 case SIOCSIFNETMASK
:
3243 case OSIOCGIFDSTADDR
:
3244 case OSIOCGIFBRDADDR
:
3245 case OSIOCGIFNETMASK
:
3247 VERIFY(so
->so_proto
!= NULL
);
3249 if (cmd
== SIOCSIFDSTADDR
|| cmd
== SIOCSIFADDR
||
3250 cmd
== SIOCSIFBRDADDR
|| cmd
== SIOCSIFNETMASK
) {
3251 #if BYTE_ORDER != BIG_ENDIAN
3252 if (ifr
->ifr_addr
.sa_family
== 0 &&
3253 ifr
->ifr_addr
.sa_len
< 16) {
3254 ifr
->ifr_addr
.sa_family
= ifr
->ifr_addr
.sa_len
;
3255 ifr
->ifr_addr
.sa_len
= 16;
3258 if (ifr
->ifr_addr
.sa_len
== 0)
3259 ifr
->ifr_addr
.sa_len
= 16;
3261 } else if (cmd
== OSIOCGIFADDR
) {
3262 cmd
= SIOCGIFADDR
; /* struct ifreq */
3263 } else if (cmd
== OSIOCGIFDSTADDR
) {
3264 cmd
= SIOCGIFDSTADDR
; /* struct ifreq */
3265 } else if (cmd
== OSIOCGIFBRDADDR
) {
3266 cmd
= SIOCGIFBRDADDR
; /* struct ifreq */
3267 } else if (cmd
== OSIOCGIFNETMASK
) {
3268 cmd
= SIOCGIFNETMASK
; /* struct ifreq */
3272 error
= ((*so
->so_proto
->pr_usrreqs
->pru_control
)(so
, cmd
,
3273 (caddr_t
)ifr
, ifp
, p
));
3274 socket_unlock(so
, 1);
3278 case OSIOCGIFDSTADDR
:
3279 case OSIOCGIFBRDADDR
:
3280 case OSIOCGIFNETMASK
:
3281 bcopy(&ifr
->ifr_addr
.sa_family
, &ifr
->ifr_addr
,
3285 if (cmd
== SIOCSIFKPI
) {
3286 int temperr
= proc_suser(p
);
3291 if (error
== EOPNOTSUPP
|| error
== ENOTSUP
) {
3292 error
= ifnet_ioctl(ifp
, SOCK_DOM(so
), cmd
,
3297 case SIOCGIFINTERFACESTATE
:
3298 if_get_state(ifp
, &ifr
->ifr_interface_state
);
3301 case SIOCSIFINTERFACESTATE
:
3302 if ((error
= priv_check_cred(kauth_cred_get(),
3303 PRIV_NET_INTERFACE_CONTROL
, 0)) != 0)
3306 error
= if_state_update(ifp
, &ifr
->ifr_interface_state
);
3309 case SIOCSIFPROBECONNECTIVITY
:
3310 if ((error
= priv_check_cred(kauth_cred_get(),
3311 PRIV_NET_INTERFACE_CONTROL
, 0)) != 0)
3313 error
= if_probe_connectivity(ifp
,
3314 ifr
->ifr_probe_connectivity
);
3316 case SIOCGIFPROBECONNECTIVITY
:
3317 if ((error
= priv_check_cred(kauth_cred_get(),
3318 PRIV_NET_INTERFACE_CONTROL
, 0)) != 0)
3320 if (ifp
->if_eflags
& IFEF_PROBE_CONNECTIVITY
)
3321 ifr
->ifr_probe_connectivity
= 1;
3323 ifr
->ifr_probe_connectivity
= 0;
3326 if ((ifp
->if_eflags
& (IFEF_ECN_ENABLE
|IFEF_ECN_DISABLE
)) ==
3328 ifr
->ifr_ecn_mode
= IFRTYPE_ECN_ENABLE
;
3329 else if ((ifp
->if_eflags
& (IFEF_ECN_ENABLE
|IFEF_ECN_DISABLE
)) ==
3331 ifr
->ifr_ecn_mode
= IFRTYPE_ECN_DISABLE
;
3333 ifr
->ifr_ecn_mode
= IFRTYPE_ECN_DEFAULT
;
3336 if ((error
= priv_check_cred(kauth_cred_get(),
3337 PRIV_NET_INTERFACE_CONTROL
, 0)) != 0)
3339 if (ifr
->ifr_ecn_mode
== IFRTYPE_ECN_DEFAULT
) {
3340 ifp
->if_eflags
&= ~(IFEF_ECN_ENABLE
|IFEF_ECN_DISABLE
);
3341 } else if (ifr
->ifr_ecn_mode
== IFRTYPE_ECN_ENABLE
) {
3342 ifp
->if_eflags
|= IFEF_ECN_ENABLE
;
3343 ifp
->if_eflags
&= ~IFEF_ECN_DISABLE
;
3344 } else if (ifr
->ifr_ecn_mode
== IFRTYPE_ECN_DISABLE
) {
3345 ifp
->if_eflags
|= IFEF_ECN_DISABLE
;
3346 ifp
->if_eflags
&= ~IFEF_ECN_ENABLE
;
3350 case SIOCSIFTIMESTAMPENABLE
:
3351 case SIOCSIFTIMESTAMPDISABLE
:
3352 error
= proc_suser(p
);
3356 ifnet_lock_exclusive(ifp
);
3357 if ((cmd
== SIOCSIFTIMESTAMPENABLE
&&
3358 (ifp
->if_xflags
& IFXF_TIMESTAMP_ENABLED
) != 0) ||
3359 (cmd
== SIOCSIFTIMESTAMPDISABLE
&&
3360 (ifp
->if_xflags
& IFXF_TIMESTAMP_ENABLED
) == 0)) {
3361 ifnet_lock_done(ifp
);
3364 if (cmd
== SIOCSIFTIMESTAMPENABLE
)
3365 ifp
->if_xflags
|= IFXF_TIMESTAMP_ENABLED
;
3367 ifp
->if_xflags
&= ~IFXF_TIMESTAMP_ENABLED
;
3368 ifnet_lock_done(ifp
);
3370 * Pass the setting to the interface if it supports either
3371 * software or hardware time stamping
3373 if (ifp
->if_capabilities
& (IFCAP_HW_TIMESTAMP
|
3374 IFCAP_SW_TIMESTAMP
)) {
3375 error
= ifnet_ioctl(ifp
, SOCK_DOM(so
), cmd
,
3379 case SIOCGIFTIMESTAMPENABLED
: {
3380 if ((ifp
->if_xflags
& IFXF_TIMESTAMP_ENABLED
) != 0)
3381 ifr
->ifr_intval
= 1;
3383 ifr
->ifr_intval
= 0;
3386 case SIOCSQOSMARKINGMODE
:
3387 if ((error
= priv_check_cred(kauth_cred_get(),
3388 PRIV_NET_INTERFACE_CONTROL
, 0)) != 0)
3390 error
= if_set_qosmarking_mode(ifp
, ifr
->ifr_qosmarking_mode
);
3393 case SIOCGQOSMARKINGMODE
:
3394 ifr
->ifr_qosmarking_mode
= ifp
->if_qosmarking_mode
;
3397 case SIOCSQOSMARKINGENABLED
:
3398 if ((error
= priv_check_cred(kauth_cred_get(),
3399 PRIV_NET_INTERFACE_CONTROL
, 0)) != 0)
3401 if (ifr
->ifr_qosmarking_enabled
!= 0)
3402 ifp
->if_eflags
|= IFEF_QOSMARKING_ENABLED
;
3404 ifp
->if_eflags
&= ~IFEF_QOSMARKING_ENABLED
;
3407 case SIOCGQOSMARKINGENABLED
:
3408 ifr
->ifr_qosmarking_enabled
=
3409 (ifp
->if_eflags
& IFEF_QOSMARKING_ENABLED
) ? 1 : 0;
3412 case SIOCSIFDISABLEOUTPUT
:
3413 #if (DEBUG || DEVELOPMENT)
3414 if (ifr
->ifr_disable_output
== 1) {
3415 error
= ifnet_disable_output(ifp
);
3416 } else if (ifr
->ifr_disable_output
== 0) {
3417 error
= ifnet_enable_output(ifp
);
3423 #endif /* (DEBUG || DEVELOPMENT) */
3425 case SIOCSIFLOWINTERNET
:
3426 if ((error
= priv_check_cred(kauth_cred_get(),
3427 PRIV_NET_INTERFACE_CONTROL
, 0)) != 0)
3430 ifnet_lock_exclusive(ifp
);
3431 if (ifr
->ifr_low_internet
& IFRTYPE_LOW_INTERNET_ENABLE_UL
)
3432 ifp
->if_xflags
|= IFXF_LOW_INTERNET_UL
;
3434 ifp
->if_xflags
&= ~(IFXF_LOW_INTERNET_UL
);
3435 if (ifr
->ifr_low_internet
& IFRTYPE_LOW_INTERNET_ENABLE_DL
)
3436 ifp
->if_xflags
|= IFXF_LOW_INTERNET_DL
;
3438 ifp
->if_xflags
&= ~(IFXF_LOW_INTERNET_DL
);
3439 ifnet_lock_done(ifp
);
3441 case SIOCGIFLOWINTERNET
:
3442 ifnet_lock_shared(ifp
);
3443 ifr
->ifr_low_internet
= 0;
3444 if (ifp
->if_xflags
& IFXF_LOW_INTERNET_UL
)
3445 ifr
->ifr_low_internet
|=
3446 IFRTYPE_LOW_INTERNET_ENABLE_UL
;
3447 if (ifp
->if_xflags
& IFXF_LOW_INTERNET_DL
)
3448 ifr
->ifr_low_internet
|=
3449 IFRTYPE_LOW_INTERNET_ENABLE_DL
;
3450 ifnet_lock_done(ifp
);
3461 ifioctllocked(struct socket
*so
, u_long cmd
, caddr_t data
, struct proc
*p
)
3465 socket_unlock(so
, 0);
3466 error
= ifioctl(so
, cmd
, data
, p
);
3472 * Set/clear promiscuous mode on interface ifp based on the truth value
3473 * of pswitch. The calls are reference counted so that only the first
3474 * "on" request actually has an effect, as does the final "off" request.
3475 * Results are undefined if the "off" and "on" requests are not matched.
3478 ifnet_set_promiscuous(
3486 ifnet_lock_exclusive(ifp
);
3487 oldflags
= ifp
->if_flags
;
3488 ifp
->if_pcount
+= pswitch
? 1 : -1;
3490 if (ifp
->if_pcount
> 0)
3491 ifp
->if_flags
|= IFF_PROMISC
;
3493 ifp
->if_flags
&= ~IFF_PROMISC
;
3495 newflags
= ifp
->if_flags
;
3496 ifnet_lock_done(ifp
);
3498 if (newflags
!= oldflags
&& (newflags
& IFF_UP
) != 0) {
3499 error
= ifnet_ioctl(ifp
, 0, SIOCSIFFLAGS
, NULL
);
3503 ifnet_lock_exclusive(ifp
);
3505 ifp
->if_pcount
-= pswitch
? 1 : -1;
3506 if (ifp
->if_pcount
> 0)
3507 ifp
->if_flags
|= IFF_PROMISC
;
3509 ifp
->if_flags
&= ~IFF_PROMISC
;
3510 ifnet_lock_done(ifp
);
3514 if (newflags
!= oldflags
) {
3515 log(LOG_INFO
, "%s: promiscuous mode %s%s\n",
3517 (newflags
& IFF_PROMISC
) != 0 ? "enable" : "disable",
3518 error
!= 0 ? " failed" : " succeeded");
3524 * Return interface configuration
3525 * of system. List may be used
3526 * in later ioctl's (above) to get
3527 * other information.
3531 ifconf(u_long cmd
, user_addr_t ifrp
, int *ret_space
)
3533 struct ifnet
*ifp
= NULL
;
3538 net_thread_marks_t marks
;
3540 marks
= net_thread_marks_push(NET_THREAD_CKREQ_LLADDR
);
3543 * Zero the ifr buffer to make sure we don't
3544 * disclose the contents of the stack.
3546 bzero(&ifr
, sizeof (struct ifreq
));
3549 ifnet_head_lock_shared();
3550 for (ifp
= ifnet_head
.tqh_first
; space
> sizeof (ifr
) &&
3551 ifp
; ifp
= ifp
->if_link
.tqe_next
) {
3553 size_t ifnlen
, addrs
;
3555 ifnlen
= snprintf(workbuf
, sizeof (workbuf
),
3556 "%s", if_name(ifp
));
3557 if (ifnlen
+ 1 > sizeof (ifr
.ifr_name
)) {
3558 error
= ENAMETOOLONG
;
3561 strlcpy(ifr
.ifr_name
, workbuf
, IFNAMSIZ
);
3564 ifnet_lock_shared(ifp
);
3567 ifa
= ifp
->if_addrhead
.tqh_first
;
3568 for (; space
> sizeof (ifr
) && ifa
;
3569 ifa
= ifa
->ifa_link
.tqe_next
) {
3570 struct sockaddr
*sa
;
3573 struct sockaddr_dl sdl
;
3574 uint8_t buf
[SOCK_MAXADDRLEN
+ 1];
3578 * Make sure to accomodate the largest possible
3579 * size of SA(if_lladdr)->sa_len.
3581 _CASSERT(sizeof (u
) == (SOCK_MAXADDRLEN
+ 1));
3587 if (ifa
== ifp
->if_lladdr
) {
3588 VERIFY(sa
->sa_family
== AF_LINK
);
3589 bcopy(sa
, &u
, sa
->sa_len
);
3591 ifnet_guarded_lladdr_copy_bytes(ifp
,
3592 LLADDR(&u
.sdl
), u
.sdl
.sdl_alen
);
3597 if (cmd
== OSIOCGIFCONF32
|| cmd
== OSIOCGIFCONF64
) {
3598 struct osockaddr
*osa
=
3599 (struct osockaddr
*)(void *)&ifr
.ifr_addr
;
3601 osa
->sa_family
= sa
->sa_family
;
3602 error
= copyout((caddr_t
)&ifr
, ifrp
,
3604 ifrp
+= sizeof (struct ifreq
);
3605 } else if (sa
->sa_len
<= sizeof (*sa
)) {
3607 error
= copyout((caddr_t
)&ifr
, ifrp
,
3609 ifrp
+= sizeof (struct ifreq
);
3612 sizeof (ifr
) + sa
->sa_len
- sizeof (*sa
)) {
3616 space
-= sa
->sa_len
- sizeof (*sa
);
3617 error
= copyout((caddr_t
)&ifr
, ifrp
,
3618 sizeof (ifr
.ifr_name
));
3620 error
= copyout((caddr_t
)sa
, (ifrp
+
3621 offsetof(struct ifreq
, ifr_addr
)),
3624 ifrp
+= (sa
->sa_len
+ offsetof(struct ifreq
,
3630 space
-= sizeof (ifr
);
3632 ifnet_lock_done(ifp
);
3637 bzero((caddr_t
)&ifr
.ifr_addr
, sizeof (ifr
.ifr_addr
));
3638 error
= copyout((caddr_t
)&ifr
, ifrp
, sizeof (ifr
));
3641 space
-= sizeof (ifr
);
3642 ifrp
+= sizeof (struct ifreq
);
3646 *ret_space
-= space
;
3647 net_thread_marks_pop(marks
);
3652 * Just like if_promisc(), but for all-multicast-reception mode.
3655 if_allmulti(struct ifnet
*ifp
, int onswitch
)
3660 ifnet_lock_exclusive(ifp
);
3663 if (ifp
->if_amcount
++ == 0) {
3664 ifp
->if_flags
|= IFF_ALLMULTI
;
3668 if (ifp
->if_amcount
> 1) {
3671 ifp
->if_amcount
= 0;
3672 ifp
->if_flags
&= ~IFF_ALLMULTI
;
3676 ifnet_lock_done(ifp
);
3679 error
= ifnet_ioctl(ifp
, 0, SIOCSIFFLAGS
, NULL
);
3686 static struct ifmultiaddr
*
3689 struct ifmultiaddr
*ifma
;
3691 ifma
= (how
== M_WAITOK
) ? zalloc(ifma_zone
) :
3692 zalloc_noblock(ifma_zone
);
3695 bzero(ifma
, ifma_size
);
3696 lck_mtx_init(&ifma
->ifma_lock
, ifa_mtx_grp
, ifa_mtx_attr
);
3697 ifma
->ifma_debug
|= IFD_ALLOC
;
3698 if (ifma_debug
!= 0) {
3699 ifma
->ifma_debug
|= IFD_DEBUG
;
3700 ifma
->ifma_trace
= ifma_trace
;
3707 ifma_free(struct ifmultiaddr
*ifma
)
3711 if (ifma
->ifma_protospec
!= NULL
) {
3712 panic("%s: Protospec not NULL for ifma=%p", __func__
, ifma
);
3714 } else if ((ifma
->ifma_flags
& IFMAF_ANONYMOUS
) ||
3715 ifma
->ifma_anoncnt
!= 0) {
3716 panic("%s: Freeing ifma=%p with outstanding anon req",
3719 } else if (ifma
->ifma_debug
& IFD_ATTACHED
) {
3720 panic("%s: ifma=%p attached to ifma_ifp=%p is being freed",
3721 __func__
, ifma
, ifma
->ifma_ifp
);
3723 } else if (!(ifma
->ifma_debug
& IFD_ALLOC
)) {
3724 panic("%s: ifma %p cannot be freed", __func__
, ifma
);
3726 } else if (ifma
->ifma_refcount
!= 0) {
3727 panic("%s: non-zero refcount ifma=%p", __func__
, ifma
);
3729 } else if (ifma
->ifma_reqcnt
!= 0) {
3730 panic("%s: non-zero reqcnt ifma=%p", __func__
, ifma
);
3732 } else if (ifma
->ifma_ifp
!= NULL
) {
3733 panic("%s: non-NULL ifma_ifp=%p for ifma=%p", __func__
,
3734 ifma
->ifma_ifp
, ifma
);
3736 } else if (ifma
->ifma_ll
!= NULL
) {
3737 panic("%s: non-NULL ifma_ll=%p for ifma=%p", __func__
,
3738 ifma
->ifma_ll
, ifma
);
3741 ifma
->ifma_debug
&= ~IFD_ALLOC
;
3742 if ((ifma
->ifma_debug
& (IFD_DEBUG
| IFD_TRASHED
)) ==
3743 (IFD_DEBUG
| IFD_TRASHED
)) {
3744 lck_mtx_lock(&ifma_trash_lock
);
3745 TAILQ_REMOVE(&ifma_trash_head
, (struct ifmultiaddr_dbg
*)ifma
,
3747 lck_mtx_unlock(&ifma_trash_lock
);
3748 ifma
->ifma_debug
&= ~IFD_TRASHED
;
3752 if (ifma
->ifma_addr
!= NULL
) {
3753 FREE(ifma
->ifma_addr
, M_IFADDR
);
3754 ifma
->ifma_addr
= NULL
;
3756 lck_mtx_destroy(&ifma
->ifma_lock
, ifa_mtx_grp
);
3757 zfree(ifma_zone
, ifma
);
3761 ifma_trace(struct ifmultiaddr
*ifma
, int refhold
)
3763 struct ifmultiaddr_dbg
*ifma_dbg
= (struct ifmultiaddr_dbg
*)ifma
;
3768 if (!(ifma
->ifma_debug
& IFD_DEBUG
)) {
3769 panic("%s: ifma %p has no debug structure", __func__
, ifma
);
3773 cnt
= &ifma_dbg
->ifma_refhold_cnt
;
3774 tr
= ifma_dbg
->ifma_refhold
;
3776 cnt
= &ifma_dbg
->ifma_refrele_cnt
;
3777 tr
= ifma_dbg
->ifma_refrele
;
3780 idx
= atomic_add_16_ov(cnt
, 1) % IFMA_TRACE_HIST_SIZE
;
3781 ctrace_record(&tr
[idx
]);
3785 ifma_addref(struct ifmultiaddr
*ifma
, int locked
)
3790 IFMA_LOCK_ASSERT_HELD(ifma
);
3792 if (++ifma
->ifma_refcount
== 0) {
3793 panic("%s: ifma=%p wraparound refcnt", __func__
, ifma
);
3795 } else if (ifma
->ifma_trace
!= NULL
) {
3796 (*ifma
->ifma_trace
)(ifma
, TRUE
);
3803 ifma_remref(struct ifmultiaddr
*ifma
)
3805 struct ifmultiaddr
*ll
;
3809 if (ifma
->ifma_refcount
== 0) {
3810 panic("%s: ifma=%p negative refcnt", __func__
, ifma
);
3812 } else if (ifma
->ifma_trace
!= NULL
) {
3813 (*ifma
->ifma_trace
)(ifma
, FALSE
);
3816 --ifma
->ifma_refcount
;
3817 if (ifma
->ifma_refcount
> 0) {
3823 ifma
->ifma_ifp
= NULL
;
3824 ifma
->ifma_ll
= NULL
;
3826 ifma_free(ifma
); /* deallocate it */
3833 if_attach_ifma(struct ifnet
*ifp
, struct ifmultiaddr
*ifma
, int anon
)
3835 ifnet_lock_assert(ifp
, IFNET_LCK_ASSERT_EXCLUSIVE
);
3836 IFMA_LOCK_ASSERT_HELD(ifma
);
3838 if (ifma
->ifma_ifp
!= ifp
) {
3839 panic("%s: Mismatch ifma_ifp=%p != ifp=%p", __func__
,
3840 ifma
->ifma_ifp
, ifp
);
3842 } else if (ifma
->ifma_debug
& IFD_ATTACHED
) {
3843 panic("%s: Attempt to attach an already attached ifma=%p",
3846 } else if (anon
&& (ifma
->ifma_flags
& IFMAF_ANONYMOUS
)) {
3847 panic("%s: ifma=%p unexpected IFMAF_ANONYMOUS", __func__
, ifma
);
3849 } else if (ifma
->ifma_debug
& IFD_TRASHED
) {
3850 panic("%s: Attempt to reattach a detached ifma=%p",
3855 ifma
->ifma_reqcnt
++;
3856 VERIFY(ifma
->ifma_reqcnt
== 1);
3857 IFMA_ADDREF_LOCKED(ifma
);
3858 ifma
->ifma_debug
|= IFD_ATTACHED
;
3860 ifma
->ifma_anoncnt
++;
3861 VERIFY(ifma
->ifma_anoncnt
== 1);
3862 ifma
->ifma_flags
|= IFMAF_ANONYMOUS
;
3865 LIST_INSERT_HEAD(&ifp
->if_multiaddrs
, ifma
, ifma_link
);
3869 if_detach_ifma(struct ifnet
*ifp
, struct ifmultiaddr
*ifma
, int anon
)
3871 ifnet_lock_assert(ifp
, IFNET_LCK_ASSERT_EXCLUSIVE
);
3872 IFMA_LOCK_ASSERT_HELD(ifma
);
3874 if (ifma
->ifma_reqcnt
== 0) {
3875 panic("%s: ifma=%p negative reqcnt", __func__
, ifma
);
3877 } else if (anon
&& !(ifma
->ifma_flags
& IFMAF_ANONYMOUS
)) {
3878 panic("%s: ifma=%p missing IFMAF_ANONYMOUS", __func__
, ifma
);
3880 } else if (anon
&& ifma
->ifma_anoncnt
== 0) {
3881 panic("%s: ifma=%p negative anonreqcnt", __func__
, ifma
);
3883 } else if (ifma
->ifma_ifp
!= ifp
) {
3884 panic("%s: Mismatch ifma_ifp=%p, ifp=%p", __func__
,
3885 ifma
->ifma_ifp
, ifp
);
3890 --ifma
->ifma_anoncnt
;
3891 if (ifma
->ifma_anoncnt
> 0)
3893 ifma
->ifma_flags
&= ~IFMAF_ANONYMOUS
;
3896 --ifma
->ifma_reqcnt
;
3897 if (ifma
->ifma_reqcnt
> 0)
3900 if (ifma
->ifma_protospec
!= NULL
) {
3901 panic("%s: Protospec not NULL for ifma=%p", __func__
, ifma
);
3903 } else if ((ifma
->ifma_flags
& IFMAF_ANONYMOUS
) ||
3904 ifma
->ifma_anoncnt
!= 0) {
3905 panic("%s: Detaching ifma=%p with outstanding anon req",
3908 } else if (!(ifma
->ifma_debug
& IFD_ATTACHED
)) {
3909 panic("%s: Attempt to detach an unattached address ifma=%p",
3912 } else if (ifma
->ifma_debug
& IFD_TRASHED
) {
3913 panic("%s: ifma %p is already in trash list", __func__
, ifma
);
3918 * NOTE: Caller calls IFMA_REMREF
3920 ifma
->ifma_debug
&= ~IFD_ATTACHED
;
3921 LIST_REMOVE(ifma
, ifma_link
);
3922 if (LIST_EMPTY(&ifp
->if_multiaddrs
))
3923 ifp
->if_updatemcasts
= 0;
3925 if (ifma
->ifma_debug
& IFD_DEBUG
) {
3926 /* Become a regular mutex, just in case */
3927 IFMA_CONVERT_LOCK(ifma
);
3928 lck_mtx_lock(&ifma_trash_lock
);
3929 TAILQ_INSERT_TAIL(&ifma_trash_head
,
3930 (struct ifmultiaddr_dbg
*)ifma
, ifma_trash_link
);
3931 lck_mtx_unlock(&ifma_trash_lock
);
3932 ifma
->ifma_debug
|= IFD_TRASHED
;
3939 * Find an ifmultiaddr that matches a socket address on an interface.
3941 * Caller is responsible for holding the ifnet_lock while calling
3945 if_addmulti_doesexist(struct ifnet
*ifp
, const struct sockaddr
*sa
,
3946 struct ifmultiaddr
**retifma
, int anon
)
3948 struct ifmultiaddr
*ifma
;
3950 for (ifma
= LIST_FIRST(&ifp
->if_multiaddrs
); ifma
!= NULL
;
3951 ifma
= LIST_NEXT(ifma
, ifma_link
)) {
3952 IFMA_LOCK_SPIN(ifma
);
3953 if (!ifa_equal(sa
, ifma
->ifma_addr
)) {
3958 VERIFY(!(ifma
->ifma_flags
& IFMAF_ANONYMOUS
) ||
3959 ifma
->ifma_anoncnt
!= 0);
3960 VERIFY((ifma
->ifma_flags
& IFMAF_ANONYMOUS
) ||
3961 ifma
->ifma_anoncnt
== 0);
3962 ifma
->ifma_anoncnt
++;
3963 if (!(ifma
->ifma_flags
& IFMAF_ANONYMOUS
)) {
3964 VERIFY(ifma
->ifma_anoncnt
== 1);
3965 ifma
->ifma_flags
|= IFMAF_ANONYMOUS
;
3968 if (!anon
|| ifma
->ifma_anoncnt
== 1) {
3969 ifma
->ifma_reqcnt
++;
3970 VERIFY(ifma
->ifma_reqcnt
> 1);
3972 if (retifma
!= NULL
) {
3974 IFMA_ADDREF_LOCKED(ifma
);
3983 * Radar 3642395, make sure all multicasts are in a standard format.
3985 static struct sockaddr
*
3986 copy_and_normalize(const struct sockaddr
*original
)
3989 const u_char
*aptr
= NULL
;
3990 struct sockaddr
*copy
= NULL
;
3991 struct sockaddr_dl
*sdl_new
= NULL
;
3994 if (original
->sa_family
!= AF_LINK
&&
3995 original
->sa_family
!= AF_UNSPEC
) {
3996 /* Just make a copy */
3997 MALLOC(copy
, struct sockaddr
*, original
->sa_len
,
3998 M_IFADDR
, M_WAITOK
);
4000 bcopy(original
, copy
, original
->sa_len
);
4004 switch (original
->sa_family
) {
4006 const struct sockaddr_dl
*sdl_original
=
4007 (struct sockaddr_dl
*)(uintptr_t)(size_t)original
;
4009 if (sdl_original
->sdl_nlen
+ sdl_original
->sdl_alen
+
4010 sdl_original
->sdl_slen
+
4011 offsetof(struct sockaddr_dl
, sdl_data
) >
4012 sdl_original
->sdl_len
)
4015 alen
= sdl_original
->sdl_alen
;
4016 aptr
= CONST_LLADDR(sdl_original
);
4021 if (original
->sa_len
< ETHER_ADDR_LEN
+
4022 offsetof(struct sockaddr
, sa_data
)) {
4026 alen
= ETHER_ADDR_LEN
;
4027 aptr
= (const u_char
*)original
->sa_data
;
4032 if (alen
== 0 || aptr
== NULL
)
4035 len
= alen
+ offsetof(struct sockaddr_dl
, sdl_data
);
4036 MALLOC(sdl_new
, struct sockaddr_dl
*, len
, M_IFADDR
, M_WAITOK
);
4038 if (sdl_new
!= NULL
) {
4039 bzero(sdl_new
, len
);
4040 sdl_new
->sdl_len
= len
;
4041 sdl_new
->sdl_family
= AF_LINK
;
4042 sdl_new
->sdl_alen
= alen
;
4043 bcopy(aptr
, LLADDR(sdl_new
), alen
);
4046 return ((struct sockaddr
*)sdl_new
);
4050 * Network-layer protocol domains which hold references to the underlying
4051 * link-layer record must use this routine.
4054 if_addmulti(struct ifnet
*ifp
, const struct sockaddr
*sa
,
4055 struct ifmultiaddr
**retifma
)
4057 return (if_addmulti_common(ifp
, sa
, retifma
, 0));
4061 * Anything other than network-layer protocol domains which hold references
4062 * to the underlying link-layer record must use this routine: SIOCADDMULTI
4063 * ioctl, ifnet_add_multicast(), if_bond.
4066 if_addmulti_anon(struct ifnet
*ifp
, const struct sockaddr
*sa
,
4067 struct ifmultiaddr
**retifma
)
4069 return (if_addmulti_common(ifp
, sa
, retifma
, 1));
4073 * Register an additional multicast address with a network interface.
4075 * - If the address is already present, bump the reference count on the
4076 * address and return.
4077 * - If the address is not link-layer, look up a link layer address.
4078 * - Allocate address structures for one or both addresses, and attach to the
4079 * multicast address list on the interface. If automatically adding a link
4080 * layer address, the protocol address will own a reference to the link
4081 * layer address, to be freed when it is freed.
4082 * - Notify the network device driver of an addition to the multicast address
4085 * 'sa' points to caller-owned memory with the desired multicast address.
4087 * 'retifma' will be used to return a pointer to the resulting multicast
4088 * address reference, if desired.
4090 * 'anon' indicates a link-layer address with no protocol address reference
4091 * made to it. Anything other than network-layer protocol domain requests
4092 * are considered as anonymous.
4095 if_addmulti_common(struct ifnet
*ifp
, const struct sockaddr
*sa
,
4096 struct ifmultiaddr
**retifma
, int anon
)
4098 struct sockaddr_storage storage
;
4099 struct sockaddr
*llsa
= NULL
;
4100 struct sockaddr
*dupsa
= NULL
;
4101 int error
= 0, ll_firstref
= 0, lladdr
;
4102 struct ifmultiaddr
*ifma
= NULL
;
4103 struct ifmultiaddr
*llifma
= NULL
;
4105 /* Only AF_UNSPEC/AF_LINK is allowed for an "anonymous" address */
4106 VERIFY(!anon
|| sa
->sa_family
== AF_UNSPEC
||
4107 sa
->sa_family
== AF_LINK
);
4109 /* If sa is a AF_LINK or AF_UNSPEC, duplicate and normalize it */
4110 if (sa
->sa_family
== AF_LINK
|| sa
->sa_family
== AF_UNSPEC
) {
4111 dupsa
= copy_and_normalize(sa
);
4112 if (dupsa
== NULL
) {
4119 ifnet_lock_exclusive(ifp
);
4120 if (!(ifp
->if_flags
& IFF_MULTICAST
)) {
4121 error
= EADDRNOTAVAIL
;
4122 ifnet_lock_done(ifp
);
4126 /* If the address is already present, return a new reference to it */
4127 error
= if_addmulti_doesexist(ifp
, sa
, retifma
, anon
);
4128 ifnet_lock_done(ifp
);
4133 * The address isn't already present; give the link layer a chance
4134 * to accept/reject it, and also find out which AF_LINK address this
4135 * maps to, if it isn't one already.
4137 error
= dlil_resolve_multi(ifp
, sa
, (struct sockaddr
*)&storage
,
4139 if (error
== 0 && storage
.ss_len
!= 0) {
4140 llsa
= copy_and_normalize((struct sockaddr
*)&storage
);
4146 llifma
= ifma_alloc(M_WAITOK
);
4147 if (llifma
== NULL
) {
4153 /* to be similar to FreeBSD */
4154 if (error
== EOPNOTSUPP
)
4156 else if (error
!= 0)
4159 /* Allocate while we aren't holding any locks */
4160 if (dupsa
== NULL
) {
4161 dupsa
= copy_and_normalize(sa
);
4162 if (dupsa
== NULL
) {
4167 ifma
= ifma_alloc(M_WAITOK
);
4173 ifnet_lock_exclusive(ifp
);
4175 * Check again for the matching multicast.
4177 error
= if_addmulti_doesexist(ifp
, sa
, retifma
, anon
);
4179 ifnet_lock_done(ifp
);
4183 if (llifma
!= NULL
) {
4184 VERIFY(!anon
); /* must not get here if "anonymous" */
4185 if (if_addmulti_doesexist(ifp
, llsa
, &ifma
->ifma_ll
, 0) == 0) {
4186 FREE(llsa
, M_IFADDR
);
4190 VERIFY(ifma
->ifma_ll
->ifma_ifp
== ifp
);
4193 llifma
->ifma_addr
= llsa
;
4194 llifma
->ifma_ifp
= ifp
;
4196 if_attach_ifma(ifp
, llifma
, 0);
4197 /* add extra refcnt for ifma */
4198 IFMA_ADDREF_LOCKED(llifma
);
4199 IFMA_UNLOCK(llifma
);
4200 ifma
->ifma_ll
= llifma
;
4204 /* "anonymous" request should not result in network address */
4205 VERIFY(!anon
|| ifma
->ifma_ll
== NULL
);
4207 ifma
->ifma_addr
= dupsa
;
4208 ifma
->ifma_ifp
= ifp
;
4210 if_attach_ifma(ifp
, ifma
, anon
);
4211 IFMA_ADDREF_LOCKED(ifma
); /* for this routine */
4212 if (retifma
!= NULL
) {
4214 IFMA_ADDREF_LOCKED(*retifma
); /* for caller */
4216 lladdr
= (ifma
->ifma_addr
->sa_family
== AF_UNSPEC
||
4217 ifma
->ifma_addr
->sa_family
== AF_LINK
);
4219 ifnet_lock_done(ifp
);
4221 rt_newmaddrmsg(RTM_NEWMADDR
, ifma
);
4222 IFMA_REMREF(ifma
); /* for this routine */
4225 * We are certain we have added something, so call down to the
4226 * interface to let them know about it. Do this only for newly-
4227 * added AF_LINK/AF_UNSPEC address in the if_multiaddrs set.
4229 if (lladdr
|| ll_firstref
)
4230 (void) ifnet_ioctl(ifp
, 0, SIOCADDMULTI
, NULL
);
4232 if (ifp
->if_updatemcasts
> 0)
4233 ifp
->if_updatemcasts
= 0;
4241 FREE(dupsa
, M_IFADDR
);
4245 FREE(llsa
, M_IFADDR
);
4251 * Delete a multicast group membership by network-layer group address.
4252 * This routine is deprecated.
4255 if_delmulti(struct ifnet
*ifp
, const struct sockaddr
*sa
)
4257 return (if_delmulti_common(NULL
, ifp
, sa
, 0));
4261 * Delete a multicast group membership by group membership pointer.
4262 * Network-layer protocol domains must use this routine.
4265 if_delmulti_ifma(struct ifmultiaddr
*ifma
)
4267 return (if_delmulti_common(ifma
, NULL
, NULL
, 0));
4271 * Anything other than network-layer protocol domains which hold references
4272 * to the underlying link-layer record must use this routine: SIOCDELMULTI
4273 * ioctl, ifnet_remove_multicast(), if_bond.
4276 if_delmulti_anon(struct ifnet
*ifp
, const struct sockaddr
*sa
)
4278 return (if_delmulti_common(NULL
, ifp
, sa
, 1));
4282 * Delete a multicast group membership by network-layer group address.
4284 * Returns ENOENT if the entry could not be found.
4287 if_delmulti_common(struct ifmultiaddr
*ifma
, struct ifnet
*ifp
,
4288 const struct sockaddr
*sa
, int anon
)
4290 struct sockaddr
*dupsa
= NULL
;
4291 int lastref
, ll_lastref
= 0, lladdr
;
4292 struct ifmultiaddr
*ll
= NULL
;
4294 /* sanity check for callers */
4295 VERIFY(ifma
!= NULL
|| (ifp
!= NULL
&& sa
!= NULL
));
4298 ifp
= ifma
->ifma_ifp
;
4301 (sa
->sa_family
== AF_LINK
|| sa
->sa_family
== AF_UNSPEC
)) {
4302 dupsa
= copy_and_normalize(sa
);
4308 ifnet_lock_exclusive(ifp
);
4310 for (ifma
= LIST_FIRST(&ifp
->if_multiaddrs
); ifma
!= NULL
;
4311 ifma
= LIST_NEXT(ifma
, ifma_link
)) {
4313 if (!ifa_equal(sa
, ifma
->ifma_addr
) ||
4314 (anon
&& !(ifma
->ifma_flags
& IFMAF_ANONYMOUS
))) {
4315 VERIFY(!(ifma
->ifma_flags
& IFMAF_ANONYMOUS
) ||
4316 ifma
->ifma_anoncnt
!= 0);
4320 /* found; keep it locked */
4325 FREE(dupsa
, M_IFADDR
);
4326 ifnet_lock_done(ifp
);
4332 IFMA_LOCK_ASSERT_HELD(ifma
);
4333 IFMA_ADDREF_LOCKED(ifma
); /* for this routine */
4334 lastref
= if_detach_ifma(ifp
, ifma
, anon
);
4335 VERIFY(!lastref
|| (!(ifma
->ifma_debug
& IFD_ATTACHED
) &&
4336 ifma
->ifma_reqcnt
== 0));
4337 VERIFY(!anon
|| ifma
->ifma_ll
== NULL
);
4339 lladdr
= (ifma
->ifma_addr
->sa_family
== AF_UNSPEC
||
4340 ifma
->ifma_addr
->sa_family
== AF_LINK
);
4342 if (lastref
&& ll
!= NULL
) {
4344 ll_lastref
= if_detach_ifma(ifp
, ll
, 0);
4347 ifnet_lock_done(ifp
);
4350 rt_newmaddrmsg(RTM_DELMADDR
, ifma
);
4352 if ((ll
== NULL
&& lastref
&& lladdr
) || ll_lastref
) {
4354 * Make sure the interface driver is notified in the
4355 * case of a link layer mcast group being left. Do
4356 * this only for a AF_LINK/AF_UNSPEC address that has
4357 * been removed from the if_multiaddrs set.
4359 ifnet_ioctl(ifp
, 0, SIOCDELMULTI
, NULL
);
4363 IFMA_REMREF(ifma
); /* for if_multiaddrs list */
4365 IFMA_REMREF(ll
); /* for if_multiaddrs list */
4367 IFMA_REMREF(ifma
); /* for this routine */
4369 FREE(dupsa
, M_IFADDR
);
4375 * Shutdown all network activity. Used boot() when halting
4385 if (ifnet_list_get_all(IFNET_FAMILY_ANY
, &ifp
, &count
) == 0) {
4386 for (i
= 0; i
< count
; i
++) {
4388 dlil_proto_unplumb_all(ifp
[i
]);
4390 ifnet_list_free(ifp
);
4397 * Delete Routes for a Network Interface
4399 * Called for each routing entry via the rnh->rnh_walktree() call above
4400 * to delete all route entries referencing a detaching network interface.
4403 * rn pointer to node in the routing table
4404 * arg argument passed to rnh->rnh_walktree() - detaching interface
4408 * errno failed - reason indicated
4412 if_rtdel(struct radix_node
*rn
, void *arg
)
4414 struct rtentry
*rt
= (struct rtentry
*)rn
;
4415 struct ifnet
*ifp
= arg
;
4421 * Checking against RTF_UP protects against walktree
4422 * recursion problems with cloned routes.
4425 if (rt
->rt_ifp
== ifp
&& (rt
->rt_flags
& RTF_UP
)) {
4427 * Safe to drop rt_lock and use rt_key, rt_gateway,
4428 * since holding rnh_lock here prevents another thread
4429 * from calling rt_setgate() on this route.
4432 err
= rtrequest_locked(RTM_DELETE
, rt_key(rt
), rt
->rt_gateway
,
4433 rt_mask(rt
), rt
->rt_flags
, NULL
);
4435 log(LOG_WARNING
, "if_rtdel: error %d\n", err
);
4444 * Removes routing table reference to a given interface
4445 * for a given protocol family
4448 if_rtproto_del(struct ifnet
*ifp
, int protocol
)
4450 struct radix_node_head
*rnh
;
4452 if ((protocol
<= AF_MAX
) && (protocol
>= 0) &&
4453 ((rnh
= rt_tables
[protocol
]) != NULL
) && (ifp
!= NULL
)) {
4454 lck_mtx_lock(rnh_lock
);
4455 (void) rnh
->rnh_walktree(rnh
, if_rtdel
, ifp
);
4456 lck_mtx_unlock(rnh_lock
);
4461 if_rtmtu(struct radix_node
*rn
, void *arg
)
4463 struct rtentry
*rt
= (struct rtentry
*)rn
;
4464 struct ifnet
*ifp
= arg
;
4467 if (rt
->rt_ifp
== ifp
) {
4469 * Update the MTU of this entry only if the MTU
4470 * has not been locked (RTV_MTU is not set) and
4471 * if it was non-zero to begin with.
4473 if (!(rt
->rt_rmx
.rmx_locks
& RTV_MTU
) && rt
->rt_rmx
.rmx_mtu
)
4474 rt
->rt_rmx
.rmx_mtu
= ifp
->if_mtu
;
4482 * Update the MTU metric of all route entries in all protocol tables
4483 * associated with a particular interface; this is called when the
4484 * MTU of that interface has changed.
4487 if_rtmtu_update(struct ifnet
*ifp
)
4489 struct radix_node_head
*rnh
;
4492 for (p
= 0; p
< AF_MAX
+ 1; p
++) {
4493 if ((rnh
= rt_tables
[p
]) == NULL
)
4496 lck_mtx_lock(rnh_lock
);
4497 (void) rnh
->rnh_walktree(rnh
, if_rtmtu
, ifp
);
4498 lck_mtx_unlock(rnh_lock
);
4500 routegenid_update();
4503 __private_extern__
void
4504 if_data_internal_to_if_data(struct ifnet
*ifp
,
4505 const struct if_data_internal
*if_data_int
, struct if_data
*if_data
)
4508 #define COPYFIELD(fld) if_data->fld = if_data_int->fld
4509 #define COPYFIELD32(fld) if_data->fld = (u_int32_t)(if_data_int->fld)
4510 /* compiler will cast down to 32-bit */
4511 #define COPYFIELD32_ATOMIC(fld) do { \
4512 atomic_get_64(if_data->fld, \
4513 (u_int64_t *)(void *)(uintptr_t)&if_data_int->fld); \
4516 COPYFIELD(ifi_type
);
4517 COPYFIELD(ifi_typelen
);
4518 COPYFIELD(ifi_physical
);
4519 COPYFIELD(ifi_addrlen
);
4520 COPYFIELD(ifi_hdrlen
);
4521 COPYFIELD(ifi_recvquota
);
4522 COPYFIELD(ifi_xmitquota
);
4523 if_data
->ifi_unused1
= 0;
4525 COPYFIELD(ifi_metric
);
4526 if (if_data_int
->ifi_baudrate
& 0xFFFFFFFF00000000LL
) {
4527 if_data
->ifi_baudrate
= 0xFFFFFFFF;
4529 COPYFIELD32(ifi_baudrate
);
4532 COPYFIELD32_ATOMIC(ifi_ipackets
);
4533 COPYFIELD32_ATOMIC(ifi_ierrors
);
4534 COPYFIELD32_ATOMIC(ifi_opackets
);
4535 COPYFIELD32_ATOMIC(ifi_oerrors
);
4536 COPYFIELD32_ATOMIC(ifi_collisions
);
4537 COPYFIELD32_ATOMIC(ifi_ibytes
);
4538 COPYFIELD32_ATOMIC(ifi_obytes
);
4539 COPYFIELD32_ATOMIC(ifi_imcasts
);
4540 COPYFIELD32_ATOMIC(ifi_omcasts
);
4541 COPYFIELD32_ATOMIC(ifi_iqdrops
);
4542 COPYFIELD32_ATOMIC(ifi_noproto
);
4544 COPYFIELD(ifi_recvtiming
);
4545 COPYFIELD(ifi_xmittiming
);
4547 if_data
->ifi_lastchange
.tv_sec
= if_data_int
->ifi_lastchange
.tv_sec
;
4548 if_data
->ifi_lastchange
.tv_usec
= if_data_int
->ifi_lastchange
.tv_usec
;
4550 if_data
->ifi_lastchange
.tv_sec
+= boottime_sec();
4552 if_data
->ifi_unused2
= 0;
4553 COPYFIELD(ifi_hwassist
);
4554 if_data
->ifi_reserved1
= 0;
4555 if_data
->ifi_reserved2
= 0;
4556 #undef COPYFIELD32_ATOMIC
4561 __private_extern__
void
4562 if_data_internal_to_if_data64(struct ifnet
*ifp
,
4563 const struct if_data_internal
*if_data_int
,
4564 struct if_data64
*if_data64
)
4567 #define COPYFIELD64(fld) if_data64->fld = if_data_int->fld
4568 #define COPYFIELD64_ATOMIC(fld) do { \
4569 atomic_get_64(if_data64->fld, \
4570 (u_int64_t *)(void *)(uintptr_t)&if_data_int->fld); \
4573 COPYFIELD64(ifi_type
);
4574 COPYFIELD64(ifi_typelen
);
4575 COPYFIELD64(ifi_physical
);
4576 COPYFIELD64(ifi_addrlen
);
4577 COPYFIELD64(ifi_hdrlen
);
4578 COPYFIELD64(ifi_recvquota
);
4579 COPYFIELD64(ifi_xmitquota
);
4580 if_data64
->ifi_unused1
= 0;
4581 COPYFIELD64(ifi_mtu
);
4582 COPYFIELD64(ifi_metric
);
4583 COPYFIELD64(ifi_baudrate
);
4585 COPYFIELD64_ATOMIC(ifi_ipackets
);
4586 COPYFIELD64_ATOMIC(ifi_ierrors
);
4587 COPYFIELD64_ATOMIC(ifi_opackets
);
4588 COPYFIELD64_ATOMIC(ifi_oerrors
);
4589 COPYFIELD64_ATOMIC(ifi_collisions
);
4590 COPYFIELD64_ATOMIC(ifi_ibytes
);
4591 COPYFIELD64_ATOMIC(ifi_obytes
);
4592 COPYFIELD64_ATOMIC(ifi_imcasts
);
4593 COPYFIELD64_ATOMIC(ifi_omcasts
);
4594 COPYFIELD64_ATOMIC(ifi_iqdrops
);
4595 COPYFIELD64_ATOMIC(ifi_noproto
);
4598 * Note these two fields are actually 32 bit, so doing
4599 * COPYFIELD64_ATOMIC will cause them to be misaligned
4601 COPYFIELD64(ifi_recvtiming
);
4602 COPYFIELD64(ifi_xmittiming
);
4604 if_data64
->ifi_lastchange
.tv_sec
= if_data_int
->ifi_lastchange
.tv_sec
;
4605 if_data64
->ifi_lastchange
.tv_usec
= if_data_int
->ifi_lastchange
.tv_usec
;
4607 if_data64
->ifi_lastchange
.tv_sec
+= boottime_sec();
4612 __private_extern__
void
4613 if_copy_traffic_class(struct ifnet
*ifp
,
4614 struct if_traffic_class
*if_tc
)
4616 #define COPY_IF_TC_FIELD64_ATOMIC(fld) do { \
4617 atomic_get_64(if_tc->fld, \
4618 (u_int64_t *)(void *)(uintptr_t)&ifp->if_tc.fld); \
4621 bzero(if_tc
, sizeof (*if_tc
));
4622 COPY_IF_TC_FIELD64_ATOMIC(ifi_ibepackets
);
4623 COPY_IF_TC_FIELD64_ATOMIC(ifi_ibebytes
);
4624 COPY_IF_TC_FIELD64_ATOMIC(ifi_obepackets
);
4625 COPY_IF_TC_FIELD64_ATOMIC(ifi_obebytes
);
4626 COPY_IF_TC_FIELD64_ATOMIC(ifi_ibkpackets
);
4627 COPY_IF_TC_FIELD64_ATOMIC(ifi_ibkbytes
);
4628 COPY_IF_TC_FIELD64_ATOMIC(ifi_obkpackets
);
4629 COPY_IF_TC_FIELD64_ATOMIC(ifi_obkbytes
);
4630 COPY_IF_TC_FIELD64_ATOMIC(ifi_ivipackets
);
4631 COPY_IF_TC_FIELD64_ATOMIC(ifi_ivibytes
);
4632 COPY_IF_TC_FIELD64_ATOMIC(ifi_ovipackets
);
4633 COPY_IF_TC_FIELD64_ATOMIC(ifi_ovibytes
);
4634 COPY_IF_TC_FIELD64_ATOMIC(ifi_ivopackets
);
4635 COPY_IF_TC_FIELD64_ATOMIC(ifi_ivobytes
);
4636 COPY_IF_TC_FIELD64_ATOMIC(ifi_ovopackets
);
4637 COPY_IF_TC_FIELD64_ATOMIC(ifi_ovobytes
);
4638 COPY_IF_TC_FIELD64_ATOMIC(ifi_ipvpackets
);
4639 COPY_IF_TC_FIELD64_ATOMIC(ifi_ipvbytes
);
4640 COPY_IF_TC_FIELD64_ATOMIC(ifi_opvpackets
);
4641 COPY_IF_TC_FIELD64_ATOMIC(ifi_opvbytes
);
4643 #undef COPY_IF_TC_FIELD64_ATOMIC
4647 if_copy_data_extended(struct ifnet
*ifp
, struct if_data_extended
*if_de
)
4649 #define COPY_IF_DE_FIELD64_ATOMIC(fld) do { \
4650 atomic_get_64(if_de->fld, \
4651 (u_int64_t *)(void *)(uintptr_t)&ifp->if_data.fld); \
4654 bzero(if_de
, sizeof (*if_de
));
4655 COPY_IF_DE_FIELD64_ATOMIC(ifi_alignerrs
);
4656 COPY_IF_DE_FIELD64_ATOMIC(ifi_dt_bytes
);
4657 COPY_IF_DE_FIELD64_ATOMIC(ifi_fpackets
);
4658 COPY_IF_DE_FIELD64_ATOMIC(ifi_fbytes
);
4660 #undef COPY_IF_DE_FIELD64_ATOMIC
4664 if_copy_packet_stats(struct ifnet
*ifp
, struct if_packet_stats
*if_ps
)
4666 #define COPY_IF_PS_TCP_FIELD64_ATOMIC(fld) do { \
4667 atomic_get_64(if_ps->ifi_tcp_##fld, \
4668 (u_int64_t *)(void *)(uintptr_t)&ifp->if_tcp_stat->fld); \
4671 #define COPY_IF_PS_UDP_FIELD64_ATOMIC(fld) do { \
4672 atomic_get_64(if_ps->ifi_udp_##fld, \
4673 (u_int64_t *)(void *)(uintptr_t)&ifp->if_udp_stat->fld); \
4676 COPY_IF_PS_TCP_FIELD64_ATOMIC(badformat
);
4677 COPY_IF_PS_TCP_FIELD64_ATOMIC(unspecv6
);
4678 COPY_IF_PS_TCP_FIELD64_ATOMIC(synfin
);
4679 COPY_IF_PS_TCP_FIELD64_ATOMIC(badformatipsec
);
4680 COPY_IF_PS_TCP_FIELD64_ATOMIC(noconnnolist
);
4681 COPY_IF_PS_TCP_FIELD64_ATOMIC(noconnlist
);
4682 COPY_IF_PS_TCP_FIELD64_ATOMIC(listbadsyn
);
4683 COPY_IF_PS_TCP_FIELD64_ATOMIC(icmp6unreach
);
4684 COPY_IF_PS_TCP_FIELD64_ATOMIC(deprecate6
);
4685 COPY_IF_PS_TCP_FIELD64_ATOMIC(ooopacket
);
4686 COPY_IF_PS_TCP_FIELD64_ATOMIC(rstinsynrcv
);
4687 COPY_IF_PS_TCP_FIELD64_ATOMIC(dospacket
);
4688 COPY_IF_PS_TCP_FIELD64_ATOMIC(cleanup
);
4689 COPY_IF_PS_TCP_FIELD64_ATOMIC(synwindow
);
4691 COPY_IF_PS_UDP_FIELD64_ATOMIC(port_unreach
);
4692 COPY_IF_PS_UDP_FIELD64_ATOMIC(faithprefix
);
4693 COPY_IF_PS_UDP_FIELD64_ATOMIC(port0
);
4694 COPY_IF_PS_UDP_FIELD64_ATOMIC(badlength
);
4695 COPY_IF_PS_UDP_FIELD64_ATOMIC(badchksum
);
4696 COPY_IF_PS_UDP_FIELD64_ATOMIC(badmcast
);
4697 COPY_IF_PS_UDP_FIELD64_ATOMIC(cleanup
);
4698 COPY_IF_PS_UDP_FIELD64_ATOMIC(badipsec
);
4700 #undef COPY_IF_PS_TCP_FIELD64_ATOMIC
4701 #undef COPY_IF_PS_UDP_FIELD64_ATOMIC
4705 if_copy_rxpoll_stats(struct ifnet
*ifp
, struct if_rxpoll_stats
*if_rs
)
4707 bzero(if_rs
, sizeof (*if_rs
));
4708 if (!(ifp
->if_eflags
& IFEF_RXPOLL
) || !ifnet_is_attached(ifp
, 1))
4711 /* by now, ifnet will stay attached so if_inp must be valid */
4712 VERIFY(ifp
->if_inp
!= NULL
);
4713 bcopy(&ifp
->if_inp
->pstats
, if_rs
, sizeof (*if_rs
));
4715 /* Release the IO refcnt */
4716 ifnet_decr_iorefcnt(ifp
);
4720 ifa_remref(struct ifaddr
*ifa
, int locked
)
4725 IFA_LOCK_ASSERT_HELD(ifa
);
4727 if (ifa
->ifa_refcnt
== 0)
4728 panic("%s: ifa %p negative refcnt\n", __func__
, ifa
);
4729 else if (ifa
->ifa_trace
!= NULL
)
4730 (*ifa
->ifa_trace
)(ifa
, FALSE
);
4731 if (--ifa
->ifa_refcnt
== 0) {
4732 if (ifa
->ifa_debug
& IFD_ATTACHED
)
4733 panic("ifa %p attached to ifp is being freed\n", ifa
);
4735 * Some interface addresses are allocated either statically
4736 * or carved out of a larger block. Only free it if it was
4737 * allocated via MALLOC or via the corresponding per-address
4738 * family allocator. Otherwise, leave it alone.
4740 if (ifa
->ifa_debug
& IFD_ALLOC
) {
4741 if (ifa
->ifa_free
== NULL
) {
4743 FREE(ifa
, M_IFADDR
);
4745 /* Become a regular mutex */
4746 IFA_CONVERT_LOCK(ifa
);
4747 /* callee will unlock */
4748 (*ifa
->ifa_free
)(ifa
);
4756 if (!locked
&& ifa
!= NULL
)
4763 ifa_addref(struct ifaddr
*ifa
, int locked
)
4768 IFA_LOCK_ASSERT_HELD(ifa
);
4770 if (++ifa
->ifa_refcnt
== 0) {
4771 panic("%s: ifa %p wraparound refcnt\n", __func__
, ifa
);
4773 } else if (ifa
->ifa_trace
!= NULL
) {
4774 (*ifa
->ifa_trace
)(ifa
, TRUE
);
4781 ifa_lock_init(struct ifaddr
*ifa
)
4783 lck_mtx_init(&ifa
->ifa_lock
, ifa_mtx_grp
, ifa_mtx_attr
);
4787 ifa_lock_destroy(struct ifaddr
*ifa
)
4789 IFA_LOCK_ASSERT_NOTHELD(ifa
);
4790 lck_mtx_destroy(&ifa
->ifa_lock
, ifa_mtx_grp
);
4796 * The switch statement below does nothing at runtime, as it serves as a
4797 * compile time check to ensure that all of the socket 'i' ioctls (those
4798 * in the 'i' group going thru soo_ioctl) that are made available by the
4799 * networking stack is unique. This works as long as this routine gets
4800 * updated each time a new interface ioctl gets added.
4802 * Any failures at compile time indicates duplicated ioctl values.
4804 static __attribute__((unused
)) void
4805 ifioctl_cassert(void)
4808 * This is equivalent to _CASSERT() and the compiler wouldn't
4809 * generate any instructions, thus for compile time only.
4811 switch ((u_long
)0) {
4814 /* bsd/net/if_ppp.h */
4816 case SIOCGPPPCSTATS
:
4819 /* bsd/netinet6/in6_var.h */
4820 case SIOCSIFADDR_IN6
:
4821 case SIOCGIFADDR_IN6
:
4822 case SIOCSIFDSTADDR_IN6
:
4823 case SIOCSIFNETMASK_IN6
:
4824 case SIOCGIFDSTADDR_IN6
:
4825 case SIOCGIFNETMASK_IN6
:
4826 case SIOCDIFADDR_IN6
:
4827 case SIOCAIFADDR_IN6_32
:
4828 case SIOCAIFADDR_IN6_64
:
4829 case SIOCSIFPHYADDR_IN6_32
:
4830 case SIOCSIFPHYADDR_IN6_64
:
4831 case SIOCGIFPSRCADDR_IN6
:
4832 case SIOCGIFPDSTADDR_IN6
:
4833 case SIOCGIFAFLAG_IN6
:
4834 case SIOCGDRLST_IN6_32
:
4835 case SIOCGDRLST_IN6_64
:
4836 case SIOCGPRLST_IN6_32
:
4837 case SIOCGPRLST_IN6_64
:
4838 case OSIOCGIFINFO_IN6
:
4839 case SIOCGIFINFO_IN6
:
4840 case SIOCSNDFLUSH_IN6
:
4841 case SIOCGNBRINFO_IN6_32
:
4842 case SIOCGNBRINFO_IN6_64
:
4843 case SIOCSPFXFLUSH_IN6
:
4844 case SIOCSRTRFLUSH_IN6
:
4845 case SIOCGIFALIFETIME_IN6
:
4846 case SIOCSIFALIFETIME_IN6
:
4847 case SIOCGIFSTAT_IN6
:
4848 case SIOCGIFSTAT_ICMP6
:
4849 case SIOCSDEFIFACE_IN6_32
:
4850 case SIOCSDEFIFACE_IN6_64
:
4851 case SIOCGDEFIFACE_IN6_32
:
4852 case SIOCGDEFIFACE_IN6_64
:
4853 case SIOCSIFINFO_FLAGS
:
4856 case SIOCGSCOPE6DEF
:
4857 case SIOCSIFPREFIX_IN6
:
4858 case SIOCGIFPREFIX_IN6
:
4859 case SIOCDIFPREFIX_IN6
:
4860 case SIOCAIFPREFIX_IN6
:
4861 case SIOCCIFPREFIX_IN6
:
4862 case SIOCSGIFPREFIX_IN6
:
4863 case SIOCPROTOATTACH_IN6_32
:
4864 case SIOCPROTOATTACH_IN6_64
:
4865 case SIOCPROTODETACH_IN6
:
4866 case SIOCLL_START_32
:
4867 case SIOCLL_START_64
:
4869 case SIOCAUTOCONF_START
:
4870 case SIOCAUTOCONF_STOP
:
4871 case SIOCSETROUTERMODE_IN6
:
4872 case SIOCLL_CGASTART_32
:
4873 case SIOCLL_CGASTART_64
:
4874 case SIOCGIFCGAPREP_IN6
:
4875 case SIOCSIFCGAPREP_IN6
:
4878 /* bsd/sys/sockio.h */
4881 case SIOCSIFDSTADDR
:
4882 case OSIOCGIFDSTADDR
:
4885 case OSIOCGIFBRDADDR
:
4886 case SIOCSIFBRDADDR
:
4887 case OSIOCGIFCONF32
:
4888 case OSIOCGIFCONF64
:
4889 case OSIOCGIFNETMASK
:
4890 case SIOCSIFNETMASK
:
4897 case SIOCGIFDSTADDR
:
4898 case SIOCGIFBRDADDR
:
4901 case SIOCGIFNETMASK
:
4903 case SIOCAUTONETMASK
:
4913 case SIOCGIFMEDIA32
:
4914 case SIOCGIFMEDIA64
:
4915 case SIOCSIFGENERIC
:
4916 case SIOCGIFGENERIC
:
4921 case SIOCSIFPHYADDR
:
4922 case SIOCGIFPSRCADDR
:
4923 case SIOCGIFPDSTADDR
:
4924 case SIOCDIFPHYADDR
:
4932 case SIOCPROTOATTACH
:
4933 case SIOCPROTODETACH
:
4942 case SIOCSDRVSPEC32
:
4943 case SIOCGDRVSPEC32
:
4944 case SIOCSDRVSPEC64
:
4945 case SIOCGDRVSPEC64
:
4950 case SIOCIFGCLONERS32
:
4951 case SIOCIFGCLONERS64
:
4953 case SIOCGIFASYNCMAP
:
4954 case SIOCSIFASYNCMAP
:
4958 #endif /* CONFIG_MACF_NET */
4962 case SIOCGIFWAKEFLAGS
:
4964 case SIOCGIFGETRTREFCNT
:
4965 case SIOCGIFLINKQUALITYMETRIC
:
4966 case SIOCSIFOPPORTUNISTIC
:
4967 case SIOCGIFOPPORTUNISTIC
:
4968 case SIOCSETROUTERMODE
:
4972 case SIOCSIFLINKPARAMS
:
4973 case SIOCGIFLINKPARAMS
:
4974 case SIOCGIFQUEUESTATS
:
4975 case SIOCSIFTHROTTLE
:
4976 case SIOCGIFTHROTTLE
:
4978 case SIOCGASSOCIDS32
:
4979 case SIOCGASSOCIDS64
:
4980 case SIOCGCONNIDS32
:
4981 case SIOCGCONNIDS64
:
4982 case SIOCGCONNINFO32
:
4983 case SIOCGCONNINFO64
:
4984 case SIOCSCONNORDER
:
4985 case SIOCGCONNORDER
:
4989 case SIOCGIFDELEGATE
:
4992 case SIOCGIFEXPENSIVE
:
4993 case SIOCSIFEXPENSIVE
:
4996 case SIOCGSTARTDELAY
:
4998 case SIOCAIFAGENTID
:
4999 case SIOCDIFAGENTID
:
5000 case SIOCGIFAGENTIDS32
:
5001 case SIOCGIFAGENTIDS64
:
5002 case SIOCGIFAGENTDATA32
:
5003 case SIOCGIFAGENTDATA64
:
5004 case SIOCGIFAGENTLIST32
:
5005 case SIOCGIFAGENTLIST64
:
5008 case SIOCSIFINTERFACESTATE
:
5009 case SIOCGIFINTERFACESTATE
:
5010 case SIOCSIFPROBECONNECTIVITY
:
5011 case SIOCGIFPROBECONNECTIVITY
:
5013 case SIOCGIFFUNCTIONALTYPE
:
5014 case SIOCSIFNETSIGNATURE
:
5015 case SIOCGIFNETSIGNATURE
:
5020 case SIOCSQOSMARKINGMODE
:
5021 case SIOCSQOSMARKINGENABLED
:
5022 case SIOCGQOSMARKINGMODE
:
5023 case SIOCGQOSMARKINGENABLED
:
5029 * XXX: This API is only used by BSD stack and for now will always return 0.
5030 * For Skywalk native drivers, preamble space need not be allocated in mbuf
5031 * as the preamble will be reserved in the translated skywalk packet
5032 * which is transmitted to the driver.
5033 * For Skywalk compat drivers currently headroom is always set to zero.
5036 ifnet_mbuf_packetpreamblelen(struct ifnet
*ifp
)
5042 /* The following is used to enqueue work items for interface events */
5045 union sockaddr_in_4_6 addr
;
5046 uint32_t intf_event_code
;
5050 intf_event_callback(void *arg
)
5052 struct intf_event
*p_intf_ev
= (struct intf_event
*)arg
;
5054 /* Call this before we walk the tree */
5055 EVENTHANDLER_INVOKE(&ifnet_evhdlr_ctxt
, ifnet_event
, p_intf_ev
->ifp
,
5056 (struct sockaddr
*)&(p_intf_ev
->addr
), p_intf_ev
->intf_event_code
);
5059 struct intf_event_nwk_wq_entry
{
5060 struct nwk_wq_entry nwk_wqe
;
5061 struct intf_event intf_ev_arg
;
5065 intf_event_enqueue_nwk_wq_entry(struct ifnet
*ifp
, struct sockaddr
*addrp
,
5066 uint32_t intf_event_code
)
5068 #pragma unused(addrp)
5069 struct intf_event_nwk_wq_entry
*p_intf_ev
= NULL
;
5071 MALLOC(p_intf_ev
, struct intf_event_nwk_wq_entry
*,
5072 sizeof(struct intf_event_nwk_wq_entry
),
5073 M_NWKWQ
, M_WAITOK
| M_ZERO
);
5075 p_intf_ev
->intf_ev_arg
.ifp
= ifp
;
5077 * XXX Not using addr in the arg. This will be used
5078 * once we need IP address add/delete events
5080 p_intf_ev
->intf_ev_arg
.intf_event_code
= intf_event_code
;
5081 p_intf_ev
->nwk_wqe
.func
= intf_event_callback
;
5082 p_intf_ev
->nwk_wqe
.is_arg_managed
= TRUE
;
5083 p_intf_ev
->nwk_wqe
.arg
= &p_intf_ev
->intf_ev_arg
;
5084 nwk_wq_enqueue((struct nwk_wq_entry
*)p_intf_ev
);