2 * Copyright (c) 2000-2018 Apple Inc. All rights reserved.
4 * @APPLE_OSREFERENCE_LICENSE_HEADER_START@
6 * This file contains Original Code and/or Modifications of Original Code
7 * as defined in and that are subject to the Apple Public Source License
8 * Version 2.0 (the 'License'). You may not use this file except in
9 * compliance with the License. The rights granted to you under the License
10 * may not be used to create, or enable the creation or redistribution of,
11 * unlawful or unlicensed copies of an Apple operating system, or to
12 * circumvent, violate, or enable the circumvention or violation of, any
13 * terms of an Apple operating system software license agreement.
15 * Please obtain a copy of the License at
16 * http://www.opensource.apple.com/apsl/ and read it before using this file.
18 * The Original Code and all software distributed under the License are
19 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
20 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
21 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
22 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
23 * Please see the License for the specific language governing rights and
24 * limitations under the License.
26 * @APPLE_OSREFERENCE_LICENSE_HEADER_END@
29 * Copyright (c) 1980, 1986, 1993
30 * The Regents of the University of California. All rights reserved.
32 * Redistribution and use in source and binary forms, with or without
33 * modification, are permitted provided that the following conditions
35 * 1. Redistributions of source code must retain the above copyright
36 * notice, this list of conditions and the following disclaimer.
37 * 2. Redistributions in binary form must reproduce the above copyright
38 * notice, this list of conditions and the following disclaimer in the
39 * documentation and/or other materials provided with the distribution.
40 * 3. All advertising materials mentioning features or use of this software
41 * must display the following acknowledgement:
42 * This product includes software developed by the University of
43 * California, Berkeley and its contributors.
44 * 4. Neither the name of the University nor the names of its contributors
45 * may be used to endorse or promote products derived from this software
46 * without specific prior written permission.
48 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
49 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
50 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
51 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
52 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
53 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
54 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
55 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
56 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
57 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
60 * @(#)if.c 8.3 (Berkeley) 1/4/94
61 * $FreeBSD: src/sys/net/if.c,v 1.85.2.9 2001/07/24 19:10:17 brooks Exp $
64 * NOTICE: This file was modified by SPARTA, Inc. in 2006 to introduce
65 * support for mandatory and extensible security protections. This notice
66 * is included in support of clause 2.2 (b) of the Apple Public License,
70 #include <kern/locks.h>
72 #include <sys/param.h>
73 #include <sys/malloc.h>
75 #include <sys/systm.h>
77 #include <sys/socket.h>
78 #include <sys/socketvar.h>
79 #include <sys/protosw.h>
80 #include <sys/kernel.h>
81 #include <sys/sockio.h>
82 #include <sys/syslog.h>
83 #include <sys/sysctl.h>
84 #include <sys/mcache.h>
85 #include <sys/kauth.h>
87 #include <kern/zalloc.h>
88 #include <mach/boolean.h>
90 #include <machine/endian.h>
92 #include <pexpert/pexpert.h>
95 #include <net/if_arp.h>
96 #include <net/if_dl.h>
97 #include <net/if_types.h>
98 #include <net/if_var.h>
99 #include <net/if_ppp.h>
100 #include <net/ethernet.h>
101 #include <net/network_agent.h>
102 #include <net/radix.h>
103 #include <net/route.h>
104 #include <net/dlil.h>
105 #include <net/nwk_wq.h>
107 #include <sys/domain.h>
108 #include <libkern/OSAtomic.h>
111 #include <netinet/in.h>
112 #include <netinet/in_var.h>
113 #include <netinet/in_tclass.h>
114 #include <netinet/ip_var.h>
115 #include <netinet/ip6.h>
116 #include <netinet/ip_var.h>
117 #include <netinet/tcp.h>
118 #include <netinet/tcp_var.h>
119 #include <netinet/udp.h>
120 #include <netinet/udp_var.h>
122 #include <netinet6/in6_var.h>
123 #include <netinet6/in6_ifattach.h>
124 #include <netinet6/ip6_var.h>
125 #include <netinet6/nd6.h>
127 #endif /* INET || INET6 */
130 #include <security/mac_framework.h>
134 * System initialization
137 extern char *proc_name_address(void *);
139 /* Lock group and attribute for ifaddr lock */
140 lck_attr_t
*ifa_mtx_attr
;
141 lck_grp_t
*ifa_mtx_grp
;
142 static lck_grp_attr_t
*ifa_mtx_grp_attr
;
144 static int ifioctl_ifreq(struct socket
*, u_long
, struct ifreq
*,
146 static int ifioctl_ifconf(u_long
, caddr_t
);
147 static int ifioctl_ifclone(u_long
, caddr_t
);
148 static int ifioctl_iforder(u_long
, caddr_t
);
149 static int ifioctl_ifdesc(struct ifnet
*, u_long
, caddr_t
, struct proc
*);
150 static int ifioctl_linkparams(struct ifnet
*, u_long
, caddr_t
, struct proc
*);
151 static int ifioctl_qstats(struct ifnet
*, u_long
, caddr_t
);
152 static int ifioctl_throttle(struct ifnet
*, u_long
, caddr_t
, struct proc
*);
153 static int ifioctl_netsignature(struct ifnet
*, u_long
, caddr_t
);
154 static int ifconf(u_long cmd
, user_addr_t ifrp
, int * ret_space
);
155 __private_extern__
void link_rtrequest(int, struct rtentry
*, struct sockaddr
*);
156 void if_rtproto_del(struct ifnet
*ifp
, int protocol
);
158 static int if_addmulti_common(struct ifnet
*, const struct sockaddr
*,
159 struct ifmultiaddr
**, int);
160 static int if_delmulti_common(struct ifmultiaddr
*, struct ifnet
*,
161 const struct sockaddr
*, int);
162 static struct ifnet
*ifunit_common(const char *, boolean_t
);
164 static int if_rtmtu(struct radix_node
*, void *);
165 static void if_rtmtu_update(struct ifnet
*);
167 static int if_clone_list(int, int *, user_addr_t
);
169 MALLOC_DEFINE(M_IFADDR
, "ifaddr", "interface address");
171 struct ifnethead ifnet_head
= TAILQ_HEAD_INITIALIZER(ifnet_head
);
173 /* ifnet_ordered_head and if_ordered_count are protected by the ifnet_head lock */
174 struct ifnethead ifnet_ordered_head
= TAILQ_HEAD_INITIALIZER(ifnet_ordered_head
);
175 static u_int32_t if_ordered_count
= 0;
177 static int if_cloners_count
;
178 LIST_HEAD(, if_clone
) if_cloners
= LIST_HEAD_INITIALIZER(if_cloners
);
180 static struct ifaddr
*ifa_ifwithnet_common(const struct sockaddr
*,
182 static void if_attach_ifa_common(struct ifnet
*, struct ifaddr
*, int);
183 static void if_detach_ifa_common(struct ifnet
*, struct ifaddr
*, int);
185 static void if_attach_ifma(struct ifnet
*, struct ifmultiaddr
*, int);
186 static int if_detach_ifma(struct ifnet
*, struct ifmultiaddr
*, int);
188 static struct ifmultiaddr
*ifma_alloc(int);
189 static void ifma_free(struct ifmultiaddr
*);
190 static void ifma_trace(struct ifmultiaddr
*, int);
193 static unsigned int ifma_debug
= 1; /* debugging (enabled) */
195 static unsigned int ifma_debug
; /* debugging (disabled) */
197 static unsigned int ifma_size
; /* size of zone element */
198 static struct zone
*ifma_zone
; /* zone for ifmultiaddr */
200 #define IFMA_TRACE_HIST_SIZE 32 /* size of trace history */
203 __private_extern__
unsigned int ifma_trace_hist_size
= IFMA_TRACE_HIST_SIZE
;
205 struct ifmultiaddr_dbg
{
206 struct ifmultiaddr ifma
; /* ifmultiaddr */
207 u_int16_t ifma_refhold_cnt
; /* # of ref */
208 u_int16_t ifma_refrele_cnt
; /* # of rele */
210 * Circular lists of IFA_ADDREF and IFA_REMREF callers.
212 ctrace_t ifma_refhold
[IFMA_TRACE_HIST_SIZE
];
213 ctrace_t ifma_refrele
[IFMA_TRACE_HIST_SIZE
];
217 TAILQ_ENTRY(ifmultiaddr_dbg
) ifma_trash_link
;
220 /* List of trash ifmultiaddr entries protected by ifma_trash_lock */
221 static TAILQ_HEAD(, ifmultiaddr_dbg
) ifma_trash_head
;
222 static decl_lck_mtx_data(, ifma_trash_lock
);
224 #define IFMA_ZONE_MAX 64 /* maximum elements in zone */
225 #define IFMA_ZONE_NAME "ifmultiaddr" /* zone name */
229 * XXX: declare here to avoid to include many inet6 related files..
230 * should be more generalized?
232 extern void nd6_setmtu(struct ifnet
*);
233 extern lck_mtx_t
*nd6_mutex
;
236 SYSCTL_NODE(_net
, PF_LINK
, link
, CTLFLAG_RW
|CTLFLAG_LOCKED
, 0, "Link layers");
237 SYSCTL_NODE(_net_link
, 0, generic
, CTLFLAG_RW
|CTLFLAG_LOCKED
, 0,
238 "Generic link-management");
240 SYSCTL_DECL(_net_link_generic_system
);
242 static uint32_t if_verbose
= 0;
243 SYSCTL_INT(_net_link_generic_system
, OID_AUTO
, if_verbose
,
244 CTLFLAG_RW
| CTLFLAG_LOCKED
, &if_verbose
, 0, "");
246 boolean_t intcoproc_unrestricted
;
248 /* Eventhandler context for interface events */
249 struct eventhandler_lists_ctxt ifnet_evhdlr_ctxt
;
254 /* Setup lock group and attribute for ifaddr */
255 ifa_mtx_grp_attr
= lck_grp_attr_alloc_init();
256 ifa_mtx_grp
= lck_grp_alloc_init("ifaddr", ifa_mtx_grp_attr
);
257 ifa_mtx_attr
= lck_attr_alloc_init();
259 PE_parse_boot_argn("ifa_debug", &ifma_debug
, sizeof (ifma_debug
));
261 ifma_size
= (ifma_debug
== 0) ? sizeof (struct ifmultiaddr
) :
262 sizeof (struct ifmultiaddr_dbg
);
264 ifma_zone
= zinit(ifma_size
, IFMA_ZONE_MAX
* ifma_size
, 0,
266 if (ifma_zone
== NULL
) {
267 panic("%s: failed allocating %s", __func__
, IFMA_ZONE_NAME
);
270 zone_change(ifma_zone
, Z_EXPAND
, TRUE
);
271 zone_change(ifma_zone
, Z_CALLERACCT
, FALSE
);
273 lck_mtx_init(&ifma_trash_lock
, ifa_mtx_grp
, ifa_mtx_attr
);
274 TAILQ_INIT(&ifma_trash_head
);
276 PE_parse_boot_argn("intcoproc_unrestricted", &intcoproc_unrestricted
,
277 sizeof (intcoproc_unrestricted
));
281 * Network interface utility routines.
283 * Routines with ifa_ifwith* names take sockaddr *'s as
288 struct ifaddr
**ifnet_addrs
;
289 struct ifnet
**ifindex2ifnet
;
291 __private_extern__
void
292 if_attach_ifa(struct ifnet
*ifp
, struct ifaddr
*ifa
)
294 if_attach_ifa_common(ifp
, ifa
, 0);
297 __private_extern__
void
298 if_attach_link_ifa(struct ifnet
*ifp
, struct ifaddr
*ifa
)
300 if_attach_ifa_common(ifp
, ifa
, 1);
304 if_attach_ifa_common(struct ifnet
*ifp
, struct ifaddr
*ifa
, int link
)
306 ifnet_lock_assert(ifp
, IFNET_LCK_ASSERT_EXCLUSIVE
);
307 IFA_LOCK_ASSERT_HELD(ifa
);
309 if (ifa
->ifa_ifp
!= ifp
) {
310 panic("%s: Mismatch ifa_ifp=%p != ifp=%p", __func__
,
313 } else if (ifa
->ifa_debug
& IFD_ATTACHED
) {
314 panic("%s: Attempt to attach an already attached ifa=%p",
317 } else if (link
&& !(ifa
->ifa_debug
& IFD_LINK
)) {
318 panic("%s: Unexpected non-link address ifa=%p", __func__
, ifa
);
320 } else if (!link
&& (ifa
->ifa_debug
& IFD_LINK
)) {
321 panic("%s: Unexpected link address ifa=%p", __func__
, ifa
);
324 IFA_ADDREF_LOCKED(ifa
);
325 ifa
->ifa_debug
|= IFD_ATTACHED
;
327 TAILQ_INSERT_HEAD(&ifp
->if_addrhead
, ifa
, ifa_link
);
329 TAILQ_INSERT_TAIL(&ifp
->if_addrhead
, ifa
, ifa_link
);
331 if (ifa
->ifa_attached
!= NULL
)
332 (*ifa
->ifa_attached
)(ifa
);
336 __private_extern__
void
337 if_detach_ifa(struct ifnet
*ifp
, struct ifaddr
*ifa
)
339 if_detach_ifa_common(ifp
, ifa
, 0);
342 __private_extern__
void
343 if_detach_link_ifa(struct ifnet
*ifp
, struct ifaddr
*ifa
)
345 if_detach_ifa_common(ifp
, ifa
, 1);
349 if_detach_ifa_common(struct ifnet
*ifp
, struct ifaddr
*ifa
, int link
)
351 ifnet_lock_assert(ifp
, IFNET_LCK_ASSERT_EXCLUSIVE
);
352 IFA_LOCK_ASSERT_HELD(ifa
);
354 if (link
&& !(ifa
->ifa_debug
& IFD_LINK
)) {
355 panic("%s: Unexpected non-link address ifa=%p", __func__
, ifa
);
357 } else if (link
&& ifa
!= TAILQ_FIRST(&ifp
->if_addrhead
)) {
358 panic("%s: Link address ifa=%p not first", __func__
, ifa
);
360 } else if (!link
&& (ifa
->ifa_debug
& IFD_LINK
)) {
361 panic("%s: Unexpected link address ifa=%p", __func__
, ifa
);
363 } else if (!(ifa
->ifa_debug
& IFD_ATTACHED
)) {
364 panic("%s: Attempt to detach an unattached address ifa=%p",
367 } else if (ifa
->ifa_ifp
!= ifp
) {
368 panic("%s: Mismatch ifa_ifp=%p, ifp=%p", __func__
,
371 } else if (ifa
->ifa_debug
& IFD_DEBUG
) {
373 TAILQ_FOREACH(ifa2
, &ifp
->if_addrhead
, ifa_link
) {
378 panic("%s: Attempt to detach a stray address ifa=%p",
383 TAILQ_REMOVE(&ifp
->if_addrhead
, ifa
, ifa_link
);
384 /* This must not be the last reference to the ifaddr */
385 if (IFA_REMREF_LOCKED(ifa
) == NULL
) {
386 panic("%s: unexpected (missing) refcnt ifa=%p", __func__
, ifa
);
389 ifa
->ifa_debug
&= ~(IFD_ATTACHED
| IFD_DETACHING
);
391 if (ifa
->ifa_detached
!= NULL
)
392 (*ifa
->ifa_detached
)(ifa
);
396 #define INITIAL_IF_INDEXLIM 8
399 * Function: if_next_index
401 * Return the next available interface index.
402 * Grow the ifnet_addrs[] and ifindex2ifnet[] arrays to accomodate the
403 * added entry when necessary.
406 * ifnet_addrs[] is indexed by (if_index - 1), whereas
407 * ifindex2ifnet[] is indexed by ifp->if_index. That requires us to
408 * always allocate one extra element to hold ifindex2ifnet[0], which
411 int if_next_index(void);
413 __private_extern__
int
416 static int if_indexlim
= 0;
419 new_index
= ++if_index
;
420 if (if_index
> if_indexlim
) {
423 caddr_t new_ifnet_addrs
;
424 caddr_t new_ifindex2ifnet
;
425 caddr_t old_ifnet_addrs
;
427 old_ifnet_addrs
= (caddr_t
)ifnet_addrs
;
428 if (ifnet_addrs
== NULL
) {
429 new_if_indexlim
= INITIAL_IF_INDEXLIM
;
431 new_if_indexlim
= if_indexlim
<< 1;
434 /* allocate space for the larger arrays */
435 n
= (2 * new_if_indexlim
+ 1) * sizeof(caddr_t
);
436 new_ifnet_addrs
= _MALLOC(n
, M_IFADDR
, M_WAITOK
| M_ZERO
);
437 if (new_ifnet_addrs
== NULL
) {
442 new_ifindex2ifnet
= new_ifnet_addrs
443 + new_if_indexlim
* sizeof(caddr_t
);
444 if (ifnet_addrs
!= NULL
) {
445 /* copy the existing data */
446 bcopy((caddr_t
)ifnet_addrs
, new_ifnet_addrs
,
447 if_indexlim
* sizeof(caddr_t
));
448 bcopy((caddr_t
)ifindex2ifnet
,
450 (if_indexlim
+ 1) * sizeof(caddr_t
));
453 /* switch to the new tables and size */
454 ifnet_addrs
= (struct ifaddr
**)(void *)new_ifnet_addrs
;
455 ifindex2ifnet
= (struct ifnet
**)(void *)new_ifindex2ifnet
;
456 if_indexlim
= new_if_indexlim
;
458 /* release the old data */
459 if (old_ifnet_addrs
!= NULL
) {
460 _FREE((caddr_t
)old_ifnet_addrs
, M_IFADDR
);
467 * Create a clone network interface.
470 if_clone_create(char *name
, int len
, void *params
)
472 struct if_clone
*ifc
;
475 u_int32_t bytoff
, bitoff
;
479 ifc
= if_clone_lookup(name
, &unit
);
483 if (ifunit(name
) != NULL
)
487 wildcard
= (unit
== UINT32_MAX
);
489 * Find a free unit if none was given.
492 while ((bytoff
< ifc
->ifc_bmlen
) &&
493 (ifc
->ifc_units
[bytoff
] == 0xff))
495 if (bytoff
>= ifc
->ifc_bmlen
)
497 while ((ifc
->ifc_units
[bytoff
] & (1 << bitoff
)) != 0)
499 unit
= (bytoff
<< 3) + bitoff
;
502 if (unit
> ifc
->ifc_maxunit
)
505 err
= (*ifc
->ifc_create
)(ifc
, unit
, params
);
511 bitoff
= unit
- (bytoff
<< 3);
515 * Allocate the unit in the bitmap.
517 KASSERT((ifc
->ifc_units
[bytoff
] & (1 << bitoff
)) == 0,
518 ("%s: bit is already set", __func__
));
519 ifc
->ifc_units
[bytoff
] |= (1 << bitoff
);
521 /* In the wildcard case, we need to update the name. */
523 for (dp
= name
; *dp
!= '\0'; dp
++);
524 if (snprintf(dp
, len
- (dp
-name
), "%d", unit
) >
525 len
- (dp
-name
) - 1) {
527 * This can only be a programmer error and
528 * there's no straightforward way to recover if
531 panic("%s: interface name too long", __func__
);
541 * Destroy a clone network interface.
544 if_clone_destroy(const char *name
)
546 struct if_clone
*ifc
;
551 ifc
= if_clone_lookup(name
, &unit
);
555 if (unit
< ifc
->ifc_minifs
)
562 if (ifc
->ifc_destroy
== NULL
)
565 (*ifc
->ifc_destroy
)(ifp
);
568 * Compute offset in the bitmap and deallocate the unit.
571 bitoff
= unit
- (bytoff
<< 3);
572 KASSERT((ifc
->ifc_units
[bytoff
] & (1 << bitoff
)) != 0,
573 ("%s: bit is already cleared", __func__
));
574 ifc
->ifc_units
[bytoff
] &= ~(1 << bitoff
);
579 * Look up a network interface cloner.
582 __private_extern__
struct if_clone
*
583 if_clone_lookup(const char *name
, u_int32_t
*unitp
)
585 struct if_clone
*ifc
;
589 for (ifc
= LIST_FIRST(&if_cloners
); ifc
!= NULL
; ) {
590 for (cp
= name
, i
= 0; i
< ifc
->ifc_namelen
; i
++, cp
++) {
591 if (ifc
->ifc_name
[i
] != *cp
)
596 ifc
= LIST_NEXT(ifc
, ifc_list
);
600 return ((struct if_clone
*)NULL
);
606 for (i
= 0; *cp
!= '\0'; cp
++) {
607 if (*cp
< '0' || *cp
> '9') {
608 /* Bogus unit number. */
611 i
= (i
* 10) + (*cp
- '0');
621 * Register a network interface cloner.
624 if_clone_attach(struct if_clone
*ifc
)
631 KASSERT(ifc
->ifc_minifs
- 1 <= ifc
->ifc_maxunit
,
632 ("%s: %s requested more units then allowed (%d > %d)",
633 __func__
, ifc
->ifc_name
, ifc
->ifc_minifs
,
634 ifc
->ifc_maxunit
+ 1));
636 * Compute bitmap size and allocate it.
638 maxclone
= ifc
->ifc_maxunit
+ 1;
640 if ((len
<< 3) < maxclone
)
642 ifc
->ifc_units
= _MALLOC(len
, M_CLONE
, M_WAITOK
| M_ZERO
);
643 if (ifc
->ifc_units
== NULL
)
645 ifc
->ifc_bmlen
= len
;
647 LIST_INSERT_HEAD(&if_cloners
, ifc
, ifc_list
);
650 for (unit
= 0; unit
< ifc
->ifc_minifs
; unit
++) {
651 err
= (*ifc
->ifc_create
)(ifc
, unit
, NULL
);
653 ("%s: failed to create required interface %s%d",
654 __func__
, ifc
->ifc_name
, unit
));
656 /* Allocate the unit in the bitmap. */
658 bitoff
= unit
- (bytoff
<< 3);
659 ifc
->ifc_units
[bytoff
] |= (1 << bitoff
);
666 * Unregister a network interface cloner.
669 if_clone_detach(struct if_clone
*ifc
)
671 LIST_REMOVE(ifc
, ifc_list
);
672 FREE(ifc
->ifc_units
, M_CLONE
);
677 * Provide list of interface cloners to userspace.
680 if_clone_list(int count
, int *ret_total
, user_addr_t dst
)
682 char outbuf
[IFNAMSIZ
];
683 struct if_clone
*ifc
;
686 *ret_total
= if_cloners_count
;
687 if (dst
== USER_ADDR_NULL
) {
688 /* Just asking how many there are. */
695 count
= (if_cloners_count
< count
) ? if_cloners_count
: count
;
697 for (ifc
= LIST_FIRST(&if_cloners
); ifc
!= NULL
&& count
!= 0;
698 ifc
= LIST_NEXT(ifc
, ifc_list
), count
--, dst
+= IFNAMSIZ
) {
699 bzero(outbuf
, sizeof(outbuf
));
700 strlcpy(outbuf
, ifc
->ifc_name
, IFNAMSIZ
);
701 error
= copyout(outbuf
, dst
, IFNAMSIZ
);
710 if_functional_type(struct ifnet
*ifp
, bool exclude_delegate
)
712 u_int32_t ret
= IFRTYPE_FUNCTIONAL_UNKNOWN
;
714 if (ifp
->if_flags
& IFF_LOOPBACK
) {
715 ret
= IFRTYPE_FUNCTIONAL_LOOPBACK
;
716 } else if ((exclude_delegate
&&
717 (ifp
->if_subfamily
== IFNET_SUBFAMILY_WIFI
)) ||
718 (!exclude_delegate
&& IFNET_IS_WIFI(ifp
))) {
719 if (ifp
->if_eflags
& IFEF_AWDL
)
720 ret
= IFRTYPE_FUNCTIONAL_WIFI_AWDL
;
722 ret
= IFRTYPE_FUNCTIONAL_WIFI_INFRA
;
723 } else if ((exclude_delegate
&&
724 (ifp
->if_type
== IFT_CELLULAR
)) ||
725 (!exclude_delegate
&& IFNET_IS_CELLULAR(ifp
))) {
726 ret
= IFRTYPE_FUNCTIONAL_CELLULAR
;
727 } else if (IFNET_IS_INTCOPROC(ifp
)) {
728 ret
= IFRTYPE_FUNCTIONAL_INTCOPROC
;
729 } else if ((exclude_delegate
&&
730 (ifp
->if_family
== IFNET_FAMILY_ETHERNET
||
731 ifp
->if_family
== IFNET_FAMILY_FIREWIRE
)) ||
732 (!exclude_delegate
&& IFNET_IS_WIRED(ifp
))) {
733 ret
= IFRTYPE_FUNCTIONAL_WIRED
;
741 * Similar to ifa_ifwithaddr, except that this is IPv4 specific
742 * and that it matches only the local (not broadcast) address.
744 __private_extern__
struct in_ifaddr
*
745 ifa_foraddr(unsigned int addr
)
747 return (ifa_foraddr_scoped(addr
, IFSCOPE_NONE
));
751 * Similar to ifa_foraddr, except with the added interface scope
752 * constraint (unless the caller passes in IFSCOPE_NONE in which
753 * case there is no scope restriction).
755 __private_extern__
struct in_ifaddr
*
756 ifa_foraddr_scoped(unsigned int addr
, unsigned int scope
)
758 struct in_ifaddr
*ia
= NULL
;
760 lck_rw_lock_shared(in_ifaddr_rwlock
);
761 TAILQ_FOREACH(ia
, INADDR_HASH(addr
), ia_hash
) {
762 IFA_LOCK_SPIN(&ia
->ia_ifa
);
763 if (ia
->ia_addr
.sin_addr
.s_addr
== addr
&&
764 (scope
== IFSCOPE_NONE
|| ia
->ia_ifp
->if_index
== scope
)) {
765 IFA_ADDREF_LOCKED(&ia
->ia_ifa
); /* for caller */
766 IFA_UNLOCK(&ia
->ia_ifa
);
769 IFA_UNLOCK(&ia
->ia_ifa
);
771 lck_rw_done(in_ifaddr_rwlock
);
777 * Similar to ifa_foraddr, except that this for IPv6.
779 __private_extern__
struct in6_ifaddr
*
780 ifa_foraddr6(struct in6_addr
*addr6
)
782 return (ifa_foraddr6_scoped(addr6
, IFSCOPE_NONE
));
785 __private_extern__
struct in6_ifaddr
*
786 ifa_foraddr6_scoped(struct in6_addr
*addr6
, unsigned int scope
)
788 struct in6_ifaddr
*ia
= NULL
;
790 lck_rw_lock_shared(&in6_ifaddr_rwlock
);
791 for (ia
= in6_ifaddrs
; ia
; ia
= ia
->ia_next
) {
792 IFA_LOCK(&ia
->ia_ifa
);
793 if (IN6_ARE_ADDR_EQUAL(&ia
->ia_addr
.sin6_addr
, addr6
) &&
794 (scope
== IFSCOPE_NONE
|| ia
->ia_ifp
->if_index
== scope
)) {
795 IFA_ADDREF_LOCKED(&ia
->ia_ifa
); /* for caller */
796 IFA_UNLOCK(&ia
->ia_ifa
);
799 IFA_UNLOCK(&ia
->ia_ifa
);
801 lck_rw_done(&in6_ifaddr_rwlock
);
808 * Return the first (primary) address of a given family on an interface.
810 __private_extern__
struct ifaddr
*
811 ifa_ifpgetprimary(struct ifnet
*ifp
, int family
)
815 ifnet_lock_shared(ifp
);
816 TAILQ_FOREACH(ifa
, &ifp
->if_addrhead
, ifa_link
) {
818 if (ifa
->ifa_addr
->sa_family
== family
) {
819 IFA_ADDREF_LOCKED(ifa
); /* for caller */
825 ifnet_lock_done(ifp
);
831 ifa_equal(const struct sockaddr
*sa1
, const struct sockaddr
*sa2
)
836 if (sa1
->sa_len
!= sa2
->sa_len
)
839 return (bcmp(sa1
, sa2
, sa1
->sa_len
) == 0);
843 * Locate an interface based on a complete address.
846 ifa_ifwithaddr_locked(const struct sockaddr
*addr
)
850 struct ifaddr
*result
= NULL
;
852 for (ifp
= ifnet_head
.tqh_first
; ifp
&& !result
;
853 ifp
= ifp
->if_link
.tqe_next
) {
854 ifnet_lock_shared(ifp
);
855 for (ifa
= ifp
->if_addrhead
.tqh_first
; ifa
;
856 ifa
= ifa
->ifa_link
.tqe_next
) {
858 if (ifa
->ifa_addr
->sa_family
!= addr
->sa_family
) {
862 if (ifa_equal(addr
, ifa
->ifa_addr
)) {
864 IFA_ADDREF_LOCKED(ifa
); /* for caller */
868 if ((ifp
->if_flags
& IFF_BROADCAST
) &&
869 ifa
->ifa_broadaddr
!= NULL
&&
870 /* IP6 doesn't have broadcast */
871 ifa
->ifa_broadaddr
->sa_len
!= 0 &&
872 ifa_equal(ifa
->ifa_broadaddr
, addr
)) {
874 IFA_ADDREF_LOCKED(ifa
); /* for caller */
880 ifnet_lock_done(ifp
);
887 ifa_ifwithaddr(const struct sockaddr
*addr
)
889 struct ifaddr
*result
= NULL
;
891 ifnet_head_lock_shared();
893 result
= ifa_ifwithaddr_locked(addr
);
900 * Locate the point to point interface with a given destination address.
904 ifa_ifwithdstaddr(const struct sockaddr
*addr
)
908 struct ifaddr
*result
= NULL
;
910 ifnet_head_lock_shared();
911 for (ifp
= ifnet_head
.tqh_first
; ifp
&& !result
;
912 ifp
= ifp
->if_link
.tqe_next
) {
913 if ((ifp
->if_flags
& IFF_POINTOPOINT
)) {
914 ifnet_lock_shared(ifp
);
915 for (ifa
= ifp
->if_addrhead
.tqh_first
; ifa
;
916 ifa
= ifa
->ifa_link
.tqe_next
) {
918 if (ifa
->ifa_addr
->sa_family
!=
923 if (ifa_equal(addr
, ifa
->ifa_dstaddr
)) {
925 IFA_ADDREF_LOCKED(ifa
); /* for caller */
931 ifnet_lock_done(ifp
);
939 * Locate the source address of an interface based on a complete address.
942 ifa_ifwithaddr_scoped_locked(const struct sockaddr
*addr
, unsigned int ifscope
)
944 struct ifaddr
*result
= NULL
;
947 if (ifscope
== IFSCOPE_NONE
)
948 return (ifa_ifwithaddr_locked(addr
));
950 if (ifscope
> (unsigned int)if_index
) {
954 ifp
= ifindex2ifnet
[ifscope
];
956 struct ifaddr
*ifa
= NULL
;
959 * This is suboptimal; there should be a better way
960 * to search for a given address of an interface
961 * for any given address family.
963 ifnet_lock_shared(ifp
);
964 for (ifa
= ifp
->if_addrhead
.tqh_first
; ifa
!= NULL
;
965 ifa
= ifa
->ifa_link
.tqe_next
) {
967 if (ifa
->ifa_addr
->sa_family
!= addr
->sa_family
) {
971 if (ifa_equal(addr
, ifa
->ifa_addr
)) {
973 IFA_ADDREF_LOCKED(ifa
); /* for caller */
977 if ((ifp
->if_flags
& IFF_BROADCAST
) &&
978 ifa
->ifa_broadaddr
!= NULL
&&
979 /* IP6 doesn't have broadcast */
980 ifa
->ifa_broadaddr
->sa_len
!= 0 &&
981 ifa_equal(ifa
->ifa_broadaddr
, addr
)) {
983 IFA_ADDREF_LOCKED(ifa
); /* for caller */
989 ifnet_lock_done(ifp
);
996 ifa_ifwithaddr_scoped(const struct sockaddr
*addr
, unsigned int ifscope
)
998 struct ifaddr
*result
= NULL
;
1000 ifnet_head_lock_shared();
1002 result
= ifa_ifwithaddr_scoped_locked(addr
, ifscope
);
1010 ifa_ifwithnet(const struct sockaddr
*addr
)
1012 return (ifa_ifwithnet_common(addr
, IFSCOPE_NONE
));
1016 ifa_ifwithnet_scoped(const struct sockaddr
*addr
, unsigned int ifscope
)
1018 return (ifa_ifwithnet_common(addr
, ifscope
));
1022 * Find an interface on a specific network. If many, choice
1023 * is most specific found.
1025 static struct ifaddr
*
1026 ifa_ifwithnet_common(const struct sockaddr
*addr
, unsigned int ifscope
)
1029 struct ifaddr
*ifa
= NULL
;
1030 struct ifaddr
*ifa_maybe
= NULL
;
1031 u_int af
= addr
->sa_family
;
1032 const char *addr_data
= addr
->sa_data
, *cplim
;
1035 if (af
!= AF_INET
&& af
!= AF_INET6
)
1039 ifscope
= IFSCOPE_NONE
;
1041 ifnet_head_lock_shared();
1043 * AF_LINK addresses can be looked up directly by their index number,
1044 * so do that if we can.
1046 if (af
== AF_LINK
) {
1047 const struct sockaddr_dl
*sdl
=
1048 (const struct sockaddr_dl
*)(uintptr_t)(size_t)addr
;
1049 if (sdl
->sdl_index
&& sdl
->sdl_index
<= if_index
) {
1050 ifa
= ifnet_addrs
[sdl
->sdl_index
- 1];
1060 * Scan though each interface, looking for ones that have
1061 * addresses in this address family.
1063 for (ifp
= ifnet_head
.tqh_first
; ifp
; ifp
= ifp
->if_link
.tqe_next
) {
1064 ifnet_lock_shared(ifp
);
1065 for (ifa
= ifp
->if_addrhead
.tqh_first
; ifa
;
1066 ifa
= ifa
->ifa_link
.tqe_next
) {
1067 const char *cp
, *cp2
, *cp3
;
1070 if (ifa
->ifa_addr
== NULL
||
1071 ifa
->ifa_addr
->sa_family
!= af
) {
1077 * If we're looking up with a scope,
1078 * find using a matching interface.
1080 if (ifscope
!= IFSCOPE_NONE
&&
1081 ifp
->if_index
!= ifscope
) {
1087 * Scan all the bits in the ifa's address.
1088 * If a bit dissagrees with what we are
1089 * looking for, mask it with the netmask
1090 * to see if it really matters.
1091 * (A byte at a time)
1093 if (ifa
->ifa_netmask
== 0) {
1098 cp2
= ifa
->ifa_addr
->sa_data
;
1099 cp3
= ifa
->ifa_netmask
->sa_data
;
1100 cplim
= ifa
->ifa_netmask
->sa_len
+
1101 (char *)ifa
->ifa_netmask
;
1103 if ((*cp
++ ^ *cp2
++) & *cp3
++)
1104 goto next
; /* next address! */
1106 * If the netmask of what we just found
1107 * is more specific than what we had before
1108 * (if we had one) then remember the new one
1109 * before continuing to search
1110 * for an even better one.
1112 if (ifa_maybe
== NULL
||
1113 rn_refines((caddr_t
)ifa
->ifa_netmask
,
1114 (caddr_t
)ifa_maybe
->ifa_netmask
)) {
1115 IFA_ADDREF_LOCKED(ifa
); /* ifa_maybe */
1117 if (ifa_maybe
!= NULL
)
1118 IFA_REMREF(ifa_maybe
);
1123 IFA_LOCK_ASSERT_NOTHELD(ifa
);
1125 ifnet_lock_done(ifp
);
1134 else if (ifa_maybe
!= NULL
)
1135 IFA_REMREF(ifa_maybe
);
1141 * Find an interface address specific to an interface best matching
1142 * a given address applying same source address selection rules
1143 * as done in the kernel for implicit source address binding
1146 ifaof_ifpforaddr_select(const struct sockaddr
*addr
, struct ifnet
*ifp
)
1148 u_int af
= addr
->sa_family
;
1151 return (in6_selectsrc_core_ifa(__DECONST(struct sockaddr_in6
*, addr
), ifp
, 0));
1153 return (ifaof_ifpforaddr(addr
, ifp
));
1157 * Find an interface address specific to an interface best matching
1158 * a given address without regards to source address selection.
1160 * This is appropriate for use-cases where we just want to update/init
1161 * some data structure like routing table entries.
1164 ifaof_ifpforaddr(const struct sockaddr
*addr
, struct ifnet
*ifp
)
1166 struct ifaddr
*ifa
= NULL
;
1167 const char *cp
, *cp2
, *cp3
;
1169 struct ifaddr
*ifa_maybe
= NULL
;
1170 struct ifaddr
*better_ifa_maybe
= NULL
;
1171 u_int af
= addr
->sa_family
;
1176 ifnet_lock_shared(ifp
);
1177 for (ifa
= ifp
->if_addrhead
.tqh_first
; ifa
;
1178 ifa
= ifa
->ifa_link
.tqe_next
) {
1180 if (ifa
->ifa_addr
->sa_family
!= af
) {
1184 if (ifa_maybe
== NULL
) {
1185 IFA_ADDREF_LOCKED(ifa
); /* for ifa_maybe */
1188 if (ifa
->ifa_netmask
== 0) {
1189 if (ifa_equal(addr
, ifa
->ifa_addr
) ||
1190 ifa_equal(addr
, ifa
->ifa_dstaddr
)) {
1191 IFA_ADDREF_LOCKED(ifa
); /* for caller */
1198 if (ifp
->if_flags
& IFF_POINTOPOINT
) {
1199 if (ifa_equal(addr
, ifa
->ifa_dstaddr
)) {
1200 IFA_ADDREF_LOCKED(ifa
); /* for caller */
1205 if (ifa_equal(addr
, ifa
->ifa_addr
)) {
1207 IFA_ADDREF_LOCKED(ifa
); /* for caller */
1212 cp2
= ifa
->ifa_addr
->sa_data
;
1213 cp3
= ifa
->ifa_netmask
->sa_data
;
1214 cplim
= ifa
->ifa_netmask
->sa_len
+
1215 (char *)ifa
->ifa_netmask
;
1216 for (; cp3
< cplim
; cp3
++)
1217 if ((*cp
++ ^ *cp2
++) & *cp3
)
1221 if (better_ifa_maybe
== NULL
) {
1222 /* for better_ifa_maybe */
1223 IFA_ADDREF_LOCKED(ifa
);
1224 better_ifa_maybe
= ifa
;
1232 if (better_ifa_maybe
!= NULL
) {
1233 ifa
= better_ifa_maybe
;
1234 better_ifa_maybe
= NULL
;
1241 ifnet_lock_done(ifp
);
1243 if (better_ifa_maybe
!= NULL
)
1244 IFA_REMREF(better_ifa_maybe
);
1245 if (ifa_maybe
!= NULL
)
1246 IFA_REMREF(ifa_maybe
);
1251 #include <net/route.h>
1254 * Default action when installing a route with a Link Level gateway.
1255 * Lookup an appropriate real ifa to point to.
1256 * This should be moved to /sys/net/link.c eventually.
1259 link_rtrequest(int cmd
, struct rtentry
*rt
, struct sockaddr
*sa
)
1262 struct sockaddr
*dst
;
1264 void (*ifa_rtrequest
)(int, struct rtentry
*, struct sockaddr
*);
1266 LCK_MTX_ASSERT(rnh_lock
, LCK_MTX_ASSERT_OWNED
);
1267 RT_LOCK_ASSERT_HELD(rt
);
1269 if (cmd
!= RTM_ADD
|| ((ifa
= rt
->rt_ifa
) == 0) ||
1270 ((ifp
= ifa
->ifa_ifp
) == 0) || ((dst
= rt_key(rt
)) == 0))
1273 /* Become a regular mutex, just in case */
1274 RT_CONVERT_LOCK(rt
);
1276 ifa
= ifaof_ifpforaddr(dst
, ifp
);
1280 ifa_rtrequest
= ifa
->ifa_rtrequest
;
1282 if (ifa_rtrequest
!= NULL
&& ifa_rtrequest
!= link_rtrequest
)
1283 ifa_rtrequest(cmd
, rt
, sa
);
1289 * if_updown will set the interface up or down. It will
1290 * prevent other up/down events from occurring until this
1291 * up/down event has completed.
1293 * Caller must lock ifnet. This function will drop the
1294 * lock. This allows ifnet_set_flags to set the rest of
1295 * the flags after we change the up/down state without
1296 * dropping the interface lock between setting the
1297 * up/down state and updating the rest of the flags.
1299 __private_extern__
void
1300 if_updown( struct ifnet
*ifp
, int up
)
1303 struct ifaddr
**ifa
;
1305 struct ifclassq
*ifq
= &ifp
->if_snd
;
1307 /* Wait until no one else is changing the up/down state */
1308 while ((ifp
->if_eflags
& IFEF_UPDOWNCHANGE
) != 0) {
1310 tv
.tv_nsec
= NSEC_PER_SEC
/ 10;
1311 ifnet_lock_done(ifp
);
1312 msleep(&ifp
->if_eflags
, NULL
, 0, "if_updown", &tv
);
1313 ifnet_lock_exclusive(ifp
);
1316 /* Verify that the interface isn't already in the right state */
1317 if ((!up
&& (ifp
->if_flags
& IFF_UP
) == 0) ||
1318 (up
&& (ifp
->if_flags
& IFF_UP
) == IFF_UP
)) {
1322 /* Indicate that the up/down state is changing */
1323 ifp
->if_eflags
|= IFEF_UPDOWNCHANGE
;
1325 /* Mark interface up or down */
1327 ifp
->if_flags
|= IFF_UP
;
1329 ifp
->if_flags
&= ~IFF_UP
;
1332 ifnet_touch_lastchange(ifp
);
1333 ifnet_touch_lastupdown(ifp
);
1335 /* Drop the lock to notify addresses and route */
1336 ifnet_lock_done(ifp
);
1341 /* Inform all transmit queues about the new link state */
1342 ifnet_update_sndq(ifq
, up
? CLASSQ_EV_LINK_UP
: CLASSQ_EV_LINK_DOWN
);
1345 if (ifnet_get_address_list(ifp
, &ifa
) == 0) {
1346 for (i
= 0; ifa
[i
] != 0; i
++) {
1347 pfctlinput(up
? PRC_IFUP
: PRC_IFDOWN
, ifa
[i
]->ifa_addr
);
1349 ifnet_free_address_list(ifa
);
1353 /* Aquire the lock to clear the changing flag */
1354 ifnet_lock_exclusive(ifp
);
1355 ifp
->if_eflags
&= ~IFEF_UPDOWNCHANGE
;
1356 wakeup(&ifp
->if_eflags
);
1360 * Mark an interface down and notify protocols of
1367 ifnet_lock_exclusive(ifp
);
1369 ifnet_lock_done(ifp
);
1373 * Mark an interface up and notify protocols of
1380 ifnet_lock_exclusive(ifp
);
1382 ifnet_lock_done(ifp
);
1386 * Flush an interface queue.
1389 if_qflush(struct ifnet
*ifp
, int ifq_locked
)
1391 struct ifclassq
*ifq
= &ifp
->if_snd
;
1396 if (IFCQ_IS_ENABLED(ifq
))
1399 VERIFY(IFCQ_IS_EMPTY(ifq
));
1406 if_qflush_sc(struct ifnet
*ifp
, mbuf_svc_class_t sc
, u_int32_t flow
,
1407 u_int32_t
*packets
, u_int32_t
*bytes
, int ifq_locked
)
1409 struct ifclassq
*ifq
= &ifp
->if_snd
;
1410 u_int32_t cnt
= 0, len
= 0;
1411 u_int32_t a_cnt
= 0, a_len
= 0;
1413 VERIFY(sc
== MBUF_SC_UNSPEC
|| MBUF_VALID_SC(sc
));
1419 if (IFCQ_IS_ENABLED(ifq
))
1420 IFCQ_PURGE_SC(ifq
, sc
, flow
, cnt
, len
);
1425 if (packets
!= NULL
)
1426 *packets
= cnt
+ a_cnt
;
1428 *bytes
= len
+ a_len
;
1432 * Extracts interface unit number and name from string, returns -1 upon failure.
1433 * Upon success, returns extracted unit number, and interface name in dst.
1436 ifunit_extract(const char *src
, char *dst
, size_t dstlen
, int *unit
)
1443 if (src
== NULL
|| dst
== NULL
|| dstlen
== 0 || unit
== NULL
)
1447 if (len
< 2 || len
> dstlen
)
1451 if (c
< '0' || c
> '9')
1452 return (-1); /* trailing garbage */
1457 return (-1); /* no interface name */
1460 return (-1); /* number is unreasonable */
1463 } while (c
>= '0' && c
<= '9');
1465 bcopy(src
, dst
, len
);
1473 * Map interface name to
1474 * interface structure pointer.
1476 static struct ifnet
*
1477 ifunit_common(const char *name
, boolean_t hold
)
1479 char namebuf
[IFNAMSIZ
+ 1];
1483 if (ifunit_extract(name
, namebuf
, sizeof (namebuf
), &unit
) < 0)
1486 /* for safety, since we use strcmp() below */
1487 namebuf
[sizeof (namebuf
) - 1] = '\0';
1490 * Now search all the interfaces for this name/number
1492 ifnet_head_lock_shared();
1493 TAILQ_FOREACH(ifp
, &ifnet_head
, if_link
) {
1495 * Use strcmp() rather than strncmp() here,
1496 * since we want to match the entire string.
1498 if (strcmp(ifp
->if_name
, namebuf
))
1500 if (unit
== ifp
->if_unit
)
1504 /* if called from ifunit_ref() and ifnet is not attached, bail */
1505 if (hold
&& ifp
!= NULL
&& !ifnet_is_attached(ifp
, 1))
1513 ifunit(const char *name
)
1515 return (ifunit_common(name
, FALSE
));
1519 * Similar to ifunit(), except that we hold an I/O reference count on an
1520 * attached interface, which must later be released via ifnet_decr_iorefcnt().
1521 * Will return NULL unless interface exists and is fully attached.
1524 ifunit_ref(const char *name
)
1526 return (ifunit_common(name
, TRUE
));
1530 * Map interface name in a sockaddr_dl to
1531 * interface structure pointer.
1534 if_withname(struct sockaddr
*sa
)
1536 char ifname
[IFNAMSIZ
+1];
1537 struct sockaddr_dl
*sdl
= (struct sockaddr_dl
*)(void *)sa
;
1539 if ((sa
->sa_family
!= AF_LINK
) || (sdl
->sdl_nlen
== 0) ||
1540 (sdl
->sdl_nlen
> IFNAMSIZ
))
1544 * ifunit wants a null-terminated name. It may not be null-terminated
1545 * in the sockaddr. We don't want to change the caller's sockaddr,
1546 * and there might not be room to put the trailing null anyway, so we
1547 * make a local copy that we know we can null terminate safely.
1550 bcopy(sdl
->sdl_data
, ifname
, sdl
->sdl_nlen
);
1551 ifname
[sdl
->sdl_nlen
] = '\0';
1552 return (ifunit(ifname
));
1555 static __attribute__((noinline
)) int
1556 ifioctl_ifconf(u_long cmd
, caddr_t data
)
1561 case OSIOCGIFCONF32
: /* struct ifconf32 */
1562 case SIOCGIFCONF32
: { /* struct ifconf32 */
1563 struct ifconf32 ifc
;
1564 bcopy(data
, &ifc
, sizeof (ifc
));
1565 error
= ifconf(cmd
, CAST_USER_ADDR_T(ifc
.ifc_req
),
1567 bcopy(&ifc
, data
, sizeof (ifc
));
1571 case SIOCGIFCONF64
: /* struct ifconf64 */
1572 case OSIOCGIFCONF64
: { /* struct ifconf64 */
1573 struct ifconf64 ifc
;
1574 bcopy(data
, &ifc
, sizeof (ifc
));
1575 error
= ifconf(cmd
, ifc
.ifc_req
, &ifc
.ifc_len
);
1576 bcopy(&ifc
, data
, sizeof (ifc
));
1588 static __attribute__((noinline
)) int
1589 ifioctl_ifclone(u_long cmd
, caddr_t data
)
1594 case SIOCIFGCLONERS32
: { /* struct if_clonereq32 */
1595 struct if_clonereq32 ifcr
;
1596 bcopy(data
, &ifcr
, sizeof (ifcr
));
1597 error
= if_clone_list(ifcr
.ifcr_count
, &ifcr
.ifcr_total
,
1598 CAST_USER_ADDR_T(ifcr
.ifcru_buffer
));
1599 bcopy(&ifcr
, data
, sizeof (ifcr
));
1603 case SIOCIFGCLONERS64
: { /* struct if_clonereq64 */
1604 struct if_clonereq64 ifcr
;
1605 bcopy(data
, &ifcr
, sizeof (ifcr
));
1606 error
= if_clone_list(ifcr
.ifcr_count
, &ifcr
.ifcr_total
,
1608 bcopy(&ifcr
, data
, sizeof (ifcr
));
1620 static __attribute__((noinline
)) int
1621 ifioctl_ifdesc(struct ifnet
*ifp
, u_long cmd
, caddr_t data
, struct proc
*p
)
1623 struct if_descreq
*ifdr
= (struct if_descreq
*)(void *)data
;
1627 VERIFY(ifp
!= NULL
);
1630 case SIOCSIFDESC
: { /* struct if_descreq */
1631 if ((error
= proc_suser(p
)) != 0)
1634 ifnet_lock_exclusive(ifp
);
1635 bcopy(&ifdr
->ifdr_len
, &ifdr_len
, sizeof (ifdr_len
));
1636 if (ifdr_len
> sizeof (ifdr
->ifdr_desc
) ||
1637 ifdr_len
> ifp
->if_desc
.ifd_maxlen
) {
1639 ifnet_lock_done(ifp
);
1643 bzero(ifp
->if_desc
.ifd_desc
, ifp
->if_desc
.ifd_maxlen
);
1644 if ((ifp
->if_desc
.ifd_len
= ifdr_len
) > 0) {
1645 bcopy(ifdr
->ifdr_desc
, ifp
->if_desc
.ifd_desc
,
1646 MIN(ifdr_len
, ifp
->if_desc
.ifd_maxlen
));
1648 ifnet_lock_done(ifp
);
1652 case SIOCGIFDESC
: { /* struct if_descreq */
1653 ifnet_lock_shared(ifp
);
1654 ifdr_len
= MIN(ifp
->if_desc
.ifd_len
, sizeof (ifdr
->ifdr_desc
));
1655 bcopy(&ifdr_len
, &ifdr
->ifdr_len
, sizeof (ifdr_len
));
1656 bzero(&ifdr
->ifdr_desc
, sizeof (ifdr
->ifdr_desc
));
1658 bcopy(ifp
->if_desc
.ifd_desc
, ifdr
->ifdr_desc
, ifdr_len
);
1660 ifnet_lock_done(ifp
);
1672 static __attribute__((noinline
)) int
1673 ifioctl_linkparams(struct ifnet
*ifp
, u_long cmd
, caddr_t data
, struct proc
*p
)
1675 struct if_linkparamsreq
*iflpr
=
1676 (struct if_linkparamsreq
*)(void *)data
;
1677 struct ifclassq
*ifq
;
1680 VERIFY(ifp
!= NULL
);
1684 case SIOCSIFLINKPARAMS
: { /* struct if_linkparamsreq */
1685 struct tb_profile tb
= { 0, 0, 0 };
1687 if ((error
= proc_suser(p
)) != 0)
1692 if (!IFCQ_IS_READY(ifq
)) {
1697 bcopy(&iflpr
->iflpr_output_tbr_rate
, &tb
.rate
,
1699 bcopy(&iflpr
->iflpr_output_tbr_percent
, &tb
.percent
,
1700 sizeof (tb
.percent
));
1701 error
= ifclassq_tbr_set(ifq
, &tb
, TRUE
);
1706 case SIOCGIFLINKPARAMS
: { /* struct if_linkparamsreq */
1707 u_int32_t sched_type
= PKTSCHEDT_NONE
, flags
= 0;
1708 u_int64_t tbr_bw
= 0, tbr_pct
= 0;
1712 if (IFCQ_IS_ENABLED(ifq
))
1713 sched_type
= ifq
->ifcq_type
;
1715 bcopy(&sched_type
, &iflpr
->iflpr_output_sched
,
1716 sizeof (iflpr
->iflpr_output_sched
));
1718 if (IFCQ_TBR_IS_ENABLED(ifq
)) {
1719 tbr_bw
= ifq
->ifcq_tbr
.tbr_rate_raw
;
1720 tbr_pct
= ifq
->ifcq_tbr
.tbr_percent
;
1722 bcopy(&tbr_bw
, &iflpr
->iflpr_output_tbr_rate
,
1723 sizeof (iflpr
->iflpr_output_tbr_rate
));
1724 bcopy(&tbr_pct
, &iflpr
->iflpr_output_tbr_percent
,
1725 sizeof (iflpr
->iflpr_output_tbr_percent
));
1728 if (ifp
->if_output_sched_model
==
1729 IFNET_SCHED_MODEL_DRIVER_MANAGED
)
1730 flags
|= IFLPRF_DRVMANAGED
;
1731 bcopy(&flags
, &iflpr
->iflpr_flags
, sizeof (iflpr
->iflpr_flags
));
1732 bcopy(&ifp
->if_output_bw
, &iflpr
->iflpr_output_bw
,
1733 sizeof (iflpr
->iflpr_output_bw
));
1734 bcopy(&ifp
->if_input_bw
, &iflpr
->iflpr_input_bw
,
1735 sizeof (iflpr
->iflpr_input_bw
));
1736 bcopy(&ifp
->if_output_lt
, &iflpr
->iflpr_output_lt
,
1737 sizeof (iflpr
->iflpr_output_lt
));
1738 bcopy(&ifp
->if_input_lt
, &iflpr
->iflpr_input_lt
,
1739 sizeof (iflpr
->iflpr_input_lt
));
1751 static __attribute__((noinline
)) int
1752 ifioctl_qstats(struct ifnet
*ifp
, u_long cmd
, caddr_t data
)
1754 struct if_qstatsreq
*ifqr
= (struct if_qstatsreq
*)(void *)data
;
1755 u_int32_t ifqr_len
, ifqr_slot
;
1758 VERIFY(ifp
!= NULL
);
1761 case SIOCGIFQUEUESTATS
: { /* struct if_qstatsreq */
1762 bcopy(&ifqr
->ifqr_slot
, &ifqr_slot
, sizeof (ifqr_slot
));
1763 bcopy(&ifqr
->ifqr_len
, &ifqr_len
, sizeof (ifqr_len
));
1764 error
= ifclassq_getqstats(&ifp
->if_snd
, ifqr_slot
,
1765 ifqr
->ifqr_buf
, &ifqr_len
);
1768 bcopy(&ifqr_len
, &ifqr
->ifqr_len
, sizeof (ifqr_len
));
1780 static __attribute__((noinline
)) int
1781 ifioctl_throttle(struct ifnet
*ifp
, u_long cmd
, caddr_t data
, struct proc
*p
)
1783 struct if_throttlereq
*ifthr
= (struct if_throttlereq
*)(void *)data
;
1784 u_int32_t ifthr_level
;
1787 VERIFY(ifp
!= NULL
);
1790 case SIOCSIFTHROTTLE
: { /* struct if_throttlereq */
1792 * XXX: Use priv_check_cred() instead of root check?
1794 if ((error
= proc_suser(p
)) != 0)
1797 bcopy(&ifthr
->ifthr_level
, &ifthr_level
, sizeof (ifthr_level
));
1798 error
= ifnet_set_throttle(ifp
, ifthr_level
);
1799 if (error
== EALREADY
)
1804 case SIOCGIFTHROTTLE
: { /* struct if_throttlereq */
1805 if ((error
= ifnet_get_throttle(ifp
, &ifthr_level
)) == 0) {
1806 bcopy(&ifthr_level
, &ifthr
->ifthr_level
,
1807 sizeof (ifthr_level
));
1821 ifioctl_getnetagents(struct ifnet
*ifp
, u_int32_t
*count
, user_addr_t uuid_p
)
1824 u_int32_t index
= 0;
1825 u_int32_t valid_netagent_count
= 0;
1828 ifnet_lock_assert(ifp
, IFNET_LCK_ASSERT_SHARED
);
1830 if (ifp
->if_agentids
!= NULL
) {
1831 for (index
= 0; index
< ifp
->if_agentcount
; index
++) {
1832 uuid_t
*netagent_uuid
= &(ifp
->if_agentids
[index
]);
1833 if (!uuid_is_null(*netagent_uuid
)) {
1834 if (uuid_p
!= USER_ADDR_NULL
) {
1835 error
= copyout(netagent_uuid
,
1836 uuid_p
+ sizeof(uuid_t
) * valid_netagent_count
,
1842 valid_netagent_count
++;
1846 *count
= valid_netagent_count
;
1851 #define IF_MAXAGENTS 64
1852 #define IF_AGENT_INCREMENT 8
1854 if_add_netagent_locked(struct ifnet
*ifp
, uuid_t new_agent_uuid
)
1856 uuid_t
*first_empty_slot
= NULL
;
1857 u_int32_t index
= 0;
1858 bool already_added
= FALSE
;
1860 if (ifp
->if_agentids
!= NULL
) {
1861 for (index
= 0; index
< ifp
->if_agentcount
; index
++) {
1862 uuid_t
*netagent_uuid
= &(ifp
->if_agentids
[index
]);
1863 if (uuid_compare(*netagent_uuid
, new_agent_uuid
) == 0) {
1864 /* Already present, ignore */
1865 already_added
= TRUE
;
1868 if (first_empty_slot
== NULL
&&
1869 uuid_is_null(*netagent_uuid
)) {
1870 first_empty_slot
= netagent_uuid
;
1874 if (already_added
) {
1875 /* Already added agent, don't return an error */
1878 if (first_empty_slot
== NULL
) {
1879 if (ifp
->if_agentcount
>= IF_MAXAGENTS
) {
1880 /* No room for another netagent UUID, bail */
1883 /* Calculate new array size */
1884 u_int32_t new_agent_count
=
1885 MIN(ifp
->if_agentcount
+ IF_AGENT_INCREMENT
,
1888 /* Reallocate array */
1889 uuid_t
*new_agent_array
= _REALLOC(ifp
->if_agentids
,
1890 sizeof(uuid_t
) * new_agent_count
, M_NETAGENT
,
1892 if (new_agent_array
== NULL
) {
1896 /* Save new array */
1897 ifp
->if_agentids
= new_agent_array
;
1899 /* Set first empty slot */
1901 &(ifp
->if_agentids
[ifp
->if_agentcount
]);
1903 /* Save new array length */
1904 ifp
->if_agentcount
= new_agent_count
;
1907 uuid_copy(*first_empty_slot
, new_agent_uuid
);
1908 netagent_post_updated_interfaces(new_agent_uuid
);
1913 if_add_netagent(struct ifnet
*ifp
, uuid_t new_agent_uuid
)
1915 VERIFY(ifp
!= NULL
);
1917 ifnet_lock_exclusive(ifp
);
1919 int error
= if_add_netagent_locked(ifp
, new_agent_uuid
);
1921 ifnet_lock_done(ifp
);
1927 if_delete_netagent_locked(struct ifnet
*ifp
, uuid_t remove_agent_uuid
)
1929 u_int32_t index
= 0;
1930 bool removed_agent_id
= FALSE
;
1932 if (ifp
->if_agentids
!= NULL
) {
1933 for (index
= 0; index
< ifp
->if_agentcount
; index
++) {
1934 uuid_t
*netagent_uuid
= &(ifp
->if_agentids
[index
]);
1935 if (uuid_compare(*netagent_uuid
,
1936 remove_agent_uuid
) == 0) {
1937 uuid_clear(*netagent_uuid
);
1938 removed_agent_id
= TRUE
;
1943 if (removed_agent_id
)
1944 netagent_post_updated_interfaces(remove_agent_uuid
);
1950 if_delete_netagent(struct ifnet
*ifp
, uuid_t remove_agent_uuid
)
1952 VERIFY(ifp
!= NULL
);
1954 ifnet_lock_exclusive(ifp
);
1956 int error
= if_delete_netagent_locked(ifp
, remove_agent_uuid
);
1958 ifnet_lock_done(ifp
);
1964 if_check_netagent(struct ifnet
*ifp
, uuid_t find_agent_uuid
)
1966 boolean_t found
= FALSE
;
1968 if (!ifp
|| uuid_is_null(find_agent_uuid
))
1971 ifnet_lock_shared(ifp
);
1973 if (ifp
->if_agentids
!= NULL
) {
1974 for (uint32_t index
= 0; index
< ifp
->if_agentcount
; index
++) {
1975 if (uuid_compare(ifp
->if_agentids
[index
], find_agent_uuid
) == 0) {
1982 ifnet_lock_done(ifp
);
1987 static __attribute__((noinline
)) int
1988 ifioctl_netagent(struct ifnet
*ifp
, u_long cmd
, caddr_t data
, struct proc
*p
)
1990 struct if_agentidreq
*ifar
= (struct if_agentidreq
*)(void *)data
;
1992 struct if_agentidsreq32 s32
;
1993 struct if_agentidsreq64 s64
;
1997 VERIFY(ifp
!= NULL
);
1999 /* Get an io ref count if the interface is attached */
2000 if (!ifnet_is_attached(ifp
, 1)) {
2001 return (EOPNOTSUPP
);
2004 if (cmd
== SIOCAIFAGENTID
||
2005 cmd
== SIOCDIFAGENTID
) {
2006 ifnet_lock_exclusive(ifp
);
2008 ifnet_lock_shared(ifp
);
2012 case SIOCAIFAGENTID
: { /* struct if_agentidreq */
2013 // TODO: Use priv_check_cred() instead of root check
2014 if ((error
= proc_suser(p
)) != 0) {
2017 error
= if_add_netagent_locked(ifp
, ifar
->ifar_uuid
);
2020 case SIOCDIFAGENTID
: { /* struct if_agentidreq */
2021 // TODO: Use priv_check_cred() instead of root check
2022 if ((error
= proc_suser(p
)) != 0) {
2025 error
= if_delete_netagent_locked(ifp
, ifar
->ifar_uuid
);
2028 case SIOCGIFAGENTIDS32
: { /* struct if_agentidsreq32 */
2029 bcopy(data
, &u
.s32
, sizeof(u
.s32
));
2030 error
= ifioctl_getnetagents(ifp
, &u
.s32
.ifar_count
,
2033 bcopy(&u
.s32
, data
, sizeof(u
.s32
));
2037 case SIOCGIFAGENTIDS64
: { /* struct if_agentidsreq64 */
2038 bcopy(data
, &u
.s64
, sizeof(u
.s64
));
2039 error
= ifioctl_getnetagents(ifp
, &u
.s64
.ifar_count
,
2042 bcopy(&u
.s64
, data
, sizeof(u
.s64
));
2051 ifnet_lock_done(ifp
);
2052 ifnet_decr_iorefcnt(ifp
);
2058 ifnet_clear_netagent(uuid_t netagent_uuid
)
2060 struct ifnet
*ifp
= NULL
;
2061 u_int32_t index
= 0;
2063 ifnet_head_lock_shared();
2065 TAILQ_FOREACH(ifp
, &ifnet_head
, if_link
) {
2066 ifnet_lock_shared(ifp
);
2067 if (ifp
->if_agentids
!= NULL
) {
2068 for (index
= 0; index
< ifp
->if_agentcount
; index
++) {
2069 uuid_t
*ifp_netagent_uuid
= &(ifp
->if_agentids
[index
]);
2070 if (uuid_compare(*ifp_netagent_uuid
, netagent_uuid
) == 0) {
2071 uuid_clear(*ifp_netagent_uuid
);
2075 ifnet_lock_done(ifp
);
2082 ifnet_increment_generation(ifnet_t interface
)
2084 OSIncrementAtomic(&interface
->if_generation
);
2088 ifnet_get_generation(ifnet_t interface
)
2090 return (interface
->if_generation
);
2094 ifnet_remove_from_ordered_list(struct ifnet
*ifp
)
2096 ifnet_head_assert_exclusive();
2099 TAILQ_REMOVE(&ifnet_ordered_head
, ifp
, if_ordered_link
);
2100 ifp
->if_ordered_link
.tqe_next
= NULL
;
2101 ifp
->if_ordered_link
.tqe_prev
= NULL
;
2103 // Update ordered count
2104 VERIFY(if_ordered_count
> 0);
2109 ifnet_reset_order(u_int32_t
*ordered_indices
, u_int32_t count
)
2111 struct ifnet
*ifp
= NULL
;
2114 ifnet_head_lock_exclusive();
2115 for (u_int32_t order_index
= 0; order_index
< count
; order_index
++) {
2116 if (ordered_indices
[order_index
] == IFSCOPE_NONE
||
2117 ordered_indices
[order_index
] > (uint32_t)if_index
) {
2123 // Flush current ordered list
2124 for (ifp
= TAILQ_FIRST(&ifnet_ordered_head
); ifp
!= NULL
;
2125 ifp
= TAILQ_FIRST(&ifnet_ordered_head
)) {
2126 ifnet_lock_exclusive(ifp
);
2127 ifnet_remove_from_ordered_list(ifp
);
2128 ifnet_lock_done(ifp
);
2131 VERIFY(if_ordered_count
== 0);
2133 for (u_int32_t order_index
= 0; order_index
< count
; order_index
++) {
2134 u_int32_t interface_index
= ordered_indices
[order_index
];
2135 ifp
= ifindex2ifnet
[interface_index
];
2139 ifnet_lock_exclusive(ifp
);
2140 TAILQ_INSERT_TAIL(&ifnet_ordered_head
, ifp
, if_ordered_link
);
2141 ifnet_lock_done(ifp
);
2147 necp_update_all_clients();
2153 if_set_qosmarking_mode(struct ifnet
*ifp
, u_int32_t mode
)
2156 u_int32_t old_mode
= ifp
->if_qosmarking_mode
;
2159 case IFRTYPE_QOSMARKING_MODE_NONE
:
2160 ifp
->if_qosmarking_mode
= IFRTYPE_QOSMARKING_MODE_NONE
;
2161 ifp
->if_eflags
&= ~IFEF_QOSMARKING_CAPABLE
;
2163 case IFRTYPE_QOSMARKING_FASTLANE
:
2164 ifp
->if_qosmarking_mode
= IFRTYPE_QOSMARKING_FASTLANE
;
2165 ifp
->if_eflags
|= IFEF_QOSMARKING_CAPABLE
;
2166 if (net_qos_policy_capable_enabled
!= 0)
2167 ifp
->if_eflags
|= IFEF_QOSMARKING_ENABLED
;
2173 if (error
== 0 && old_mode
!= ifp
->if_qosmarking_mode
) {
2174 dlil_post_msg(ifp
, KEV_DL_SUBCLASS
, KEV_DL_QOS_MODE_CHANGED
,
2175 NULL
, sizeof(struct kev_dl_rrc_state
));
2181 static __attribute__((noinline
)) int
2182 ifioctl_iforder(u_long cmd
, caddr_t data
)
2185 u_int32_t
*ordered_indices
= NULL
;
2191 case SIOCSIFORDER
: { /* struct if_order */
2192 struct if_order
*ifo
= (struct if_order
*)(void *)data
;
2194 if (ifo
->ifo_count
> (u_int32_t
)if_index
) {
2199 size_t length
= (ifo
->ifo_count
* sizeof(u_int32_t
));
2201 if (ifo
->ifo_ordered_indices
== USER_ADDR_NULL
) {
2205 ordered_indices
= _MALLOC(length
, M_NECP
, M_WAITOK
);
2206 if (ordered_indices
== NULL
) {
2211 error
= copyin(ifo
->ifo_ordered_indices
,
2212 ordered_indices
, length
);
2217 /* ordered_indices should not contain duplicates */
2218 bool found_duplicate
= FALSE
;
2219 for (uint32_t i
= 0; i
< (ifo
->ifo_count
- 1) && !found_duplicate
; i
++){
2220 for (uint32_t j
= i
+ 1; j
< ifo
->ifo_count
&& !found_duplicate
; j
++){
2221 if (ordered_indices
[j
] == ordered_indices
[i
]){
2223 found_duplicate
= TRUE
;
2228 if (found_duplicate
) {
2233 error
= ifnet_reset_order(ordered_indices
, ifo
->ifo_count
);
2238 case SIOCGIFORDER
: { /* struct if_order */
2239 struct if_order
*ifo
= (struct if_order
*)(void *)data
;
2240 u_int32_t ordered_count
= *((volatile u_int32_t
*)&if_ordered_count
);
2242 if (ifo
->ifo_count
== 0 ||
2243 ordered_count
== 0) {
2245 } else if (ifo
->ifo_ordered_indices
!= USER_ADDR_NULL
) {
2246 u_int32_t count_to_copy
=
2247 MIN(ordered_count
, ifo
->ifo_count
);
2248 size_t length
= (count_to_copy
* sizeof(u_int32_t
));
2249 struct ifnet
*ifp
= NULL
;
2250 u_int32_t cursor
= 0;
2252 ordered_indices
= _MALLOC(length
, M_NECP
, M_WAITOK
| M_ZERO
);
2253 if (ordered_indices
== NULL
) {
2258 ifnet_head_lock_shared();
2259 TAILQ_FOREACH(ifp
, &ifnet_ordered_head
, if_ordered_link
) {
2260 if (cursor
>= count_to_copy
||
2261 cursor
>= if_ordered_count
) {
2264 ordered_indices
[cursor
] = ifp
->if_index
;
2269 /* We might have parsed less than the original length
2270 * because the list could have changed.
2272 length
= cursor
* sizeof(u_int32_t
);
2273 ifo
->ifo_count
= cursor
;
2274 error
= copyout(ordered_indices
,
2275 ifo
->ifo_ordered_indices
, length
);
2288 if (ordered_indices
!= NULL
) {
2289 _FREE(ordered_indices
, M_NECP
);
2295 static __attribute__((noinline
)) int
2296 ifioctl_netsignature(struct ifnet
*ifp
, u_long cmd
, caddr_t data
)
2298 struct if_nsreq
*ifnsr
= (struct if_nsreq
*)(void *)data
;
2302 VERIFY(ifp
!= NULL
);
2305 case SIOCSIFNETSIGNATURE
: /* struct if_nsreq */
2306 if (ifnsr
->ifnsr_len
> sizeof (ifnsr
->ifnsr_data
)) {
2310 bcopy(&ifnsr
->ifnsr_flags
, &flags
, sizeof (flags
));
2311 error
= ifnet_set_netsignature(ifp
, ifnsr
->ifnsr_family
,
2312 ifnsr
->ifnsr_len
, flags
, ifnsr
->ifnsr_data
);
2315 case SIOCGIFNETSIGNATURE
: /* struct if_nsreq */
2316 ifnsr
->ifnsr_len
= sizeof (ifnsr
->ifnsr_data
);
2317 error
= ifnet_get_netsignature(ifp
, ifnsr
->ifnsr_family
,
2318 &ifnsr
->ifnsr_len
, &flags
, ifnsr
->ifnsr_data
);
2320 bcopy(&flags
, &ifnsr
->ifnsr_flags
, sizeof (flags
));
2322 ifnsr
->ifnsr_len
= 0;
2334 static __attribute__((noinline
)) int
2335 ifioctl_nat64prefix(struct ifnet
*ifp
, u_long cmd
, caddr_t data
)
2337 struct if_nat64req
*ifnat64
= (struct if_nat64req
*)(void *)data
;
2340 VERIFY(ifp
!= NULL
);
2343 case SIOCSIFNAT64PREFIX
: /* struct if_nat64req */
2344 error
= ifnet_set_nat64prefix(ifp
, ifnat64
->ifnat64_prefixes
);
2347 case SIOCGIFNAT64PREFIX
: /* struct if_nat64req */
2348 error
= ifnet_get_nat64prefix(ifp
, ifnat64
->ifnat64_prefixes
);
2362 ifioctl_get_protolist(struct ifnet
*ifp
, u_int32_t
* ret_count
,
2365 u_int32_t actual_count
;
2368 u_int32_t
*list
= NULL
;
2370 /* find out how many */
2371 count
= if_get_protolist(ifp
, NULL
, 0);
2372 if (ifpl
== USER_ADDR_NULL
) {
2376 /* copy out how many there's space for */
2377 if (*ret_count
< count
) {
2383 list
= _MALLOC(count
* sizeof(*list
), M_TEMP
, M_WAITOK
);
2388 actual_count
= if_get_protolist(ifp
, list
, count
);
2389 if (actual_count
< count
) {
2390 count
= actual_count
;
2393 error
= copyout((caddr_t
)list
, ifpl
, count
* sizeof(*list
));
2398 if_free_protolist(list
);
2404 static __attribute__((noinline
)) int
2405 ifioctl_protolist(struct ifnet
*ifp
, u_long cmd
, caddr_t data
)
2410 case SIOCGIFPROTOLIST32
: { /* struct if_protolistreq32 */
2411 struct if_protolistreq32 ifpl
;
2413 bcopy(data
, &ifpl
, sizeof(ifpl
));
2414 if (ifpl
.ifpl_reserved
!= 0) {
2418 error
= ifioctl_get_protolist(ifp
, &ifpl
.ifpl_count
,
2419 CAST_USER_ADDR_T(ifpl
.ifpl_list
));
2420 bcopy(&ifpl
, data
, sizeof(ifpl
));
2423 case SIOCGIFPROTOLIST64
: { /* struct if_protolistreq64 */
2424 struct if_protolistreq64 ifpl
;
2426 bcopy(data
, &ifpl
, sizeof(ifpl
));
2427 if (ifpl
.ifpl_reserved
!= 0) {
2431 error
= ifioctl_get_protolist(ifp
, &ifpl
.ifpl_count
,
2433 bcopy(&ifpl
, data
, sizeof(ifpl
));
2445 * List the ioctl()s we can perform on restricted INTCOPROC interfaces.
2448 ifioctl_restrict_intcoproc(unsigned long cmd
, const char *ifname
,
2449 struct ifnet
*ifp
, struct proc
*p
)
2452 if (intcoproc_unrestricted
== TRUE
) {
2455 if (proc_pid(p
) == 0) {
2459 ifp
= ifunit(ifname
);
2464 if (!IFNET_IS_INTCOPROC(ifp
)) {
2468 case SIOCGIFBRDADDR
:
2479 case SIOCGIFFUNCTIONALTYPE
:
2480 case SIOCGIFPSRCADDR
:
2481 case SIOCGIFPDSTADDR
:
2482 case SIOCGIFGENERIC
:
2486 case SIOCGIFWAKEFLAGS
:
2487 case SIOCGIFGETRTREFCNT
:
2488 case SIOCGIFOPPORTUNISTIC
:
2489 case SIOCGIFLINKQUALITYMETRIC
:
2491 case SIOCGIFDELEGATE
:
2492 case SIOCGIFEXPENSIVE
:
2493 case SIOCGIFINTERFACESTATE
:
2494 case SIOCGIFPROBECONNECTIVITY
:
2495 case SIOCGIFTIMESTAMPENABLED
:
2497 case SIOCGQOSMARKINGMODE
:
2498 case SIOCGQOSMARKINGENABLED
:
2499 case SIOCGIFLOWINTERNET
:
2501 case SIOCGIFMEDIA32
:
2502 case SIOCGIFMEDIA64
:
2504 case SIOCGIFLINKPARAMS
:
2505 case SIOCGIFQUEUESTATS
:
2506 case SIOCGIFTHROTTLE
:
2507 case SIOCGIFAGENTIDS32
:
2508 case SIOCGIFAGENTIDS64
:
2509 case SIOCGIFNETSIGNATURE
:
2510 case SIOCGIFINFO_IN6
:
2511 case SIOCGIFAFLAG_IN6
:
2512 case SIOCGNBRINFO_IN6
:
2513 case SIOCGIFALIFETIME_IN6
:
2514 case SIOCGIFNETMASK_IN6
:
2515 case SIOCGIFPROTOLIST32
:
2516 case SIOCGIFPROTOLIST64
:
2519 #if (DEBUG || DEVELOPMENT)
2520 printf("%s: cmd 0x%lx not allowed (pid %u)\n",
2521 __func__
, cmd
, proc_pid(p
));
2531 * Most of the routines called to handle the ioctls would end up being
2532 * tail-call optimized, which unfortunately causes this routine to
2533 * consume too much stack space; this is the reason for the "noinline"
2534 * attribute used on those routines.
2537 ifioctl(struct socket
*so
, u_long cmd
, caddr_t data
, struct proc
*p
)
2539 char ifname
[IFNAMSIZ
+ 1];
2540 struct ifnet
*ifp
= NULL
;
2541 struct ifstat
*ifs
= NULL
;
2544 bzero(ifname
, sizeof (ifname
));
2547 * ioctls which don't require ifp, or ifreq ioctls
2550 case OSIOCGIFCONF32
: /* struct ifconf32 */
2551 case SIOCGIFCONF32
: /* struct ifconf32 */
2552 case SIOCGIFCONF64
: /* struct ifconf64 */
2553 case OSIOCGIFCONF64
: /* struct ifconf64 */
2554 error
= ifioctl_ifconf(cmd
, data
);
2557 case SIOCIFGCLONERS32
: /* struct if_clonereq32 */
2558 case SIOCIFGCLONERS64
: /* struct if_clonereq64 */
2559 error
= ifioctl_ifclone(cmd
, data
);
2562 case SIOCGIFAGENTDATA32
: /* struct netagent_req32 */
2563 case SIOCGIFAGENTDATA64
: /* struct netagent_req64 */
2564 case SIOCGIFAGENTLIST32
: /* struct netagentlist_req32 */
2565 case SIOCGIFAGENTLIST64
: /* struct netagentlist_req64 */
2566 error
= netagent_ioctl(cmd
, data
);
2569 case SIOCSIFORDER
: /* struct if_order */
2570 case SIOCGIFORDER
: /* struct if_order */
2571 error
= ifioctl_iforder(cmd
, data
);
2574 case SIOCSIFDSTADDR
: /* struct ifreq */
2575 case SIOCSIFADDR
: /* struct ifreq */
2576 case SIOCSIFBRDADDR
: /* struct ifreq */
2577 case SIOCSIFNETMASK
: /* struct ifreq */
2578 case OSIOCGIFADDR
: /* struct ifreq */
2579 case OSIOCGIFDSTADDR
: /* struct ifreq */
2580 case OSIOCGIFBRDADDR
: /* struct ifreq */
2581 case OSIOCGIFNETMASK
: /* struct ifreq */
2582 case SIOCSIFKPI
: /* struct ifreq */
2583 if (so
->so_proto
== NULL
) {
2588 case SIOCIFCREATE
: /* struct ifreq */
2589 case SIOCIFCREATE2
: /* struct ifreq */
2590 case SIOCIFDESTROY
: /* struct ifreq */
2591 case SIOCGIFFLAGS
: /* struct ifreq */
2592 case SIOCGIFEFLAGS
: /* struct ifreq */
2593 case SIOCGIFCAP
: /* struct ifreq */
2595 case SIOCGIFMAC
: /* struct ifreq */
2596 case SIOCSIFMAC
: /* struct ifreq */
2597 #endif /* CONFIG_MACF_NET */
2598 case SIOCGIFMETRIC
: /* struct ifreq */
2599 case SIOCGIFMTU
: /* struct ifreq */
2600 case SIOCGIFPHYS
: /* struct ifreq */
2601 case SIOCSIFFLAGS
: /* struct ifreq */
2602 case SIOCSIFCAP
: /* struct ifreq */
2603 case SIOCSIFMETRIC
: /* struct ifreq */
2604 case SIOCSIFPHYS
: /* struct ifreq */
2605 case SIOCSIFMTU
: /* struct ifreq */
2606 case SIOCADDMULTI
: /* struct ifreq */
2607 case SIOCDELMULTI
: /* struct ifreq */
2608 case SIOCDIFPHYADDR
: /* struct ifreq */
2609 case SIOCSIFMEDIA
: /* struct ifreq */
2610 case SIOCSIFGENERIC
: /* struct ifreq */
2611 case SIOCSIFLLADDR
: /* struct ifreq */
2612 case SIOCSIFALTMTU
: /* struct ifreq */
2613 case SIOCSIFVLAN
: /* struct ifreq */
2614 case SIOCSIFBOND
: /* struct ifreq */
2615 case SIOCGIFLLADDR
: /* struct ifreq */
2616 case SIOCGIFTYPE
: /* struct ifreq */
2617 case SIOCGIFFUNCTIONALTYPE
: /* struct ifreq */
2618 case SIOCGIFPSRCADDR
: /* struct ifreq */
2619 case SIOCGIFPDSTADDR
: /* struct ifreq */
2620 case SIOCGIFGENERIC
: /* struct ifreq */
2621 case SIOCGIFDEVMTU
: /* struct ifreq */
2622 case SIOCGIFVLAN
: /* struct ifreq */
2623 case SIOCGIFBOND
: /* struct ifreq */
2624 case SIOCGIFWAKEFLAGS
: /* struct ifreq */
2625 case SIOCGIFGETRTREFCNT
: /* struct ifreq */
2626 case SIOCSIFOPPORTUNISTIC
: /* struct ifreq */
2627 case SIOCGIFOPPORTUNISTIC
: /* struct ifreq */
2628 case SIOCGIFLINKQUALITYMETRIC
: /* struct ifreq */
2629 case SIOCSIFLOG
: /* struct ifreq */
2630 case SIOCGIFLOG
: /* struct ifreq */
2631 case SIOCGIFDELEGATE
: /* struct ifreq */
2632 case SIOCGIFEXPENSIVE
: /* struct ifreq */
2633 case SIOCSIFEXPENSIVE
: /* struct ifreq */
2634 case SIOCSIF2KCL
: /* struct ifreq */
2635 case SIOCGIF2KCL
: /* struct ifreq */
2636 case SIOCSIFINTERFACESTATE
: /* struct ifreq */
2637 case SIOCGIFINTERFACESTATE
: /* struct ifreq */
2638 case SIOCSIFPROBECONNECTIVITY
: /* struct ifreq */
2639 case SIOCGIFPROBECONNECTIVITY
: /* struct ifreq */
2640 case SIOCGSTARTDELAY
: /* struct ifreq */
2641 case SIOCSIFTIMESTAMPENABLE
: /* struct ifreq */
2642 case SIOCSIFTIMESTAMPDISABLE
: /* struct ifreq */
2643 case SIOCGIFTIMESTAMPENABLED
: /* struct ifreq */
2644 #if (DEBUG || DEVELOPMENT)
2645 case SIOCSIFDISABLEOUTPUT
: /* struct ifreq */
2646 #endif /* (DEBUG || DEVELOPMENT) */
2647 case SIOCGECNMODE
: /* struct ifreq */
2649 case SIOCSQOSMARKINGMODE
: /* struct ifreq */
2650 case SIOCSQOSMARKINGENABLED
: /* struct ifreq */
2651 case SIOCGQOSMARKINGMODE
: /* struct ifreq */
2652 case SIOCGQOSMARKINGENABLED
: /* struct ifreq */
2653 case SIOCSIFLOWINTERNET
: /* struct ifreq */
2654 case SIOCGIFLOWINTERNET
: /* struct ifreq */
2655 { /* struct ifreq */
2657 bcopy(data
, &ifr
, sizeof (ifr
));
2658 ifr
.ifr_name
[IFNAMSIZ
- 1] = '\0';
2659 bcopy(&ifr
.ifr_name
, ifname
, IFNAMSIZ
);
2660 if (ifioctl_restrict_intcoproc(cmd
, ifname
, NULL
, p
) == true) {
2664 error
= ifioctl_ifreq(so
, cmd
, &ifr
, p
);
2665 bcopy(&ifr
, data
, sizeof (ifr
));
2671 * ioctls which require ifp. Note that we acquire dlil_ifnet_lock
2672 * here to ensure that the ifnet, if found, has been fully attached.
2676 case SIOCSIFPHYADDR
: /* struct {if,in_}aliasreq */
2677 bcopy(((struct in_aliasreq
*)(void *)data
)->ifra_name
,
2679 ifp
= ifunit(ifname
);
2683 case SIOCSIFPHYADDR_IN6_32
: /* struct in6_aliasreq_32 */
2684 bcopy(((struct in6_aliasreq_32
*)(void *)data
)->ifra_name
,
2686 ifp
= ifunit(ifname
);
2689 case SIOCSIFPHYADDR_IN6_64
: /* struct in6_aliasreq_64 */
2690 bcopy(((struct in6_aliasreq_64
*)(void *)data
)->ifra_name
,
2692 ifp
= ifunit(ifname
);
2696 case SIOCGIFSTATUS
: /* struct ifstat */
2697 ifs
= _MALLOC(sizeof (*ifs
), M_DEVBUF
, M_WAITOK
);
2703 bcopy(data
, ifs
, sizeof (*ifs
));
2704 ifs
->ifs_name
[IFNAMSIZ
- 1] = '\0';
2705 bcopy(ifs
->ifs_name
, ifname
, IFNAMSIZ
);
2706 ifp
= ifunit(ifname
);
2709 case SIOCGIFMEDIA32
: /* struct ifmediareq32 */
2710 bcopy(((struct ifmediareq32
*)(void *)data
)->ifm_name
,
2712 ifp
= ifunit(ifname
);
2715 case SIOCGIFMEDIA64
: /* struct ifmediareq64 */
2716 bcopy(((struct ifmediareq64
*)(void *)data
)->ifm_name
,
2718 ifp
= ifunit(ifname
);
2721 case SIOCSIFDESC
: /* struct if_descreq */
2722 case SIOCGIFDESC
: /* struct if_descreq */
2723 bcopy(((struct if_descreq
*)(void *)data
)->ifdr_name
,
2725 ifp
= ifunit(ifname
);
2728 case SIOCSIFLINKPARAMS
: /* struct if_linkparamsreq */
2729 case SIOCGIFLINKPARAMS
: /* struct if_linkparamsreq */
2730 bcopy(((struct if_linkparamsreq
*)(void *)data
)->iflpr_name
,
2732 ifp
= ifunit(ifname
);
2735 case SIOCGIFQUEUESTATS
: /* struct if_qstatsreq */
2736 bcopy(((struct if_qstatsreq
*)(void *)data
)->ifqr_name
,
2738 ifp
= ifunit(ifname
);
2741 case SIOCSIFTHROTTLE
: /* struct if_throttlereq */
2742 case SIOCGIFTHROTTLE
: /* struct if_throttlereq */
2743 bcopy(((struct if_throttlereq
*)(void *)data
)->ifthr_name
,
2745 ifp
= ifunit(ifname
);
2748 case SIOCAIFAGENTID
: /* struct if_agentidreq */
2749 case SIOCDIFAGENTID
: /* struct if_agentidreq */
2750 case SIOCGIFAGENTIDS32
: /* struct if_agentidsreq32 */
2751 case SIOCGIFAGENTIDS64
: /* struct if_agentidsreq64 */
2752 bcopy(((struct if_agentidreq
*)(void *)data
)->ifar_name
,
2754 ifp
= ifunit(ifname
);
2757 case SIOCSIFNETSIGNATURE
: /* struct if_nsreq */
2758 case SIOCGIFNETSIGNATURE
: /* struct if_nsreq */
2759 bcopy(((struct if_nsreq
*)(void *)data
)->ifnsr_name
,
2761 ifp
= ifunit(ifname
);
2764 case SIOCGIFPROTOLIST32
: /* struct if_protolistreq32 */
2765 case SIOCGIFPROTOLIST64
: /* struct if_protolistreq64 */
2766 bcopy(((struct if_protolistreq
*)(void *)data
)->ifpl_name
,
2768 ifp
= ifunit(ifname
);
2772 * This is a bad assumption, but the code seems to
2773 * have been doing this in the past; caveat emptor.
2775 bcopy(((struct ifreq
*)(void *)data
)->ifr_name
,
2777 ifp
= ifunit(ifname
);
2787 if (ifioctl_restrict_intcoproc(cmd
, NULL
, ifp
, p
) == true) {
2792 case SIOCSIFPHYADDR
: /* struct {if,in_}aliasreq */
2794 case SIOCSIFPHYADDR_IN6_32
: /* struct in6_aliasreq_32 */
2795 case SIOCSIFPHYADDR_IN6_64
: /* struct in6_aliasreq_64 */
2797 error
= proc_suser(p
);
2801 error
= ifnet_ioctl(ifp
, SOCK_DOM(so
), cmd
, data
);
2805 ifnet_touch_lastchange(ifp
);
2808 case SIOCGIFSTATUS
: /* struct ifstat */
2809 VERIFY(ifs
!= NULL
);
2810 ifs
->ascii
[0] = '\0';
2812 error
= ifnet_ioctl(ifp
, SOCK_DOM(so
), cmd
, (caddr_t
)ifs
);
2814 bcopy(ifs
, data
, sizeof (*ifs
));
2817 case SIOCGIFMEDIA32
: /* struct ifmediareq32 */
2818 case SIOCGIFMEDIA64
: /* struct ifmediareq64 */
2819 error
= ifnet_ioctl(ifp
, SOCK_DOM(so
), cmd
, data
);
2822 case SIOCSIFDESC
: /* struct if_descreq */
2823 case SIOCGIFDESC
: /* struct if_descreq */
2824 error
= ifioctl_ifdesc(ifp
, cmd
, data
, p
);
2827 case SIOCSIFLINKPARAMS
: /* struct if_linkparamsreq */
2828 case SIOCGIFLINKPARAMS
: /* struct if_linkparamsreq */
2829 error
= ifioctl_linkparams(ifp
, cmd
, data
, p
);
2832 case SIOCGIFQUEUESTATS
: /* struct if_qstatsreq */
2833 error
= ifioctl_qstats(ifp
, cmd
, data
);
2836 case SIOCSIFTHROTTLE
: /* struct if_throttlereq */
2837 case SIOCGIFTHROTTLE
: /* struct if_throttlereq */
2838 error
= ifioctl_throttle(ifp
, cmd
, data
, p
);
2841 case SIOCAIFAGENTID
: /* struct if_agentidreq */
2842 case SIOCDIFAGENTID
: /* struct if_agentidreq */
2843 case SIOCGIFAGENTIDS32
: /* struct if_agentidsreq32 */
2844 case SIOCGIFAGENTIDS64
: /* struct if_agentidsreq64 */
2845 error
= ifioctl_netagent(ifp
, cmd
, data
, p
);
2848 case SIOCSIFNETSIGNATURE
: /* struct if_nsreq */
2849 case SIOCGIFNETSIGNATURE
: /* struct if_nsreq */
2850 error
= ifioctl_netsignature(ifp
, cmd
, data
);
2854 case SIOCSIFNAT64PREFIX
: /* struct if_nsreq */
2855 case SIOCGIFNAT64PREFIX
: /* struct if_nsreq */
2856 error
= ifioctl_nat64prefix(ifp
, cmd
, data
);
2860 case SIOCGIFPROTOLIST32
: /* struct if_protolistreq32 */
2861 case SIOCGIFPROTOLIST64
: /* struct if_protolistreq64 */
2862 error
= ifioctl_protolist(ifp
, cmd
, data
);
2866 if (so
->so_proto
== NULL
) {
2872 error
= ((*so
->so_proto
->pr_usrreqs
->pru_control
)(so
, cmd
,
2874 socket_unlock(so
, 1);
2876 if (error
== EOPNOTSUPP
|| error
== ENOTSUP
) {
2877 error
= ifnet_ioctl(ifp
, SOCK_DOM(so
), cmd
, data
);
2884 _FREE(ifs
, M_DEVBUF
);
2887 if (ifname
[0] == '\0')
2888 (void) snprintf(ifname
, sizeof (ifname
), "%s",
2890 else if (ifp
!= NULL
)
2891 (void) snprintf(ifname
, sizeof (ifname
), "%s",
2895 printf("%s[%s,%d]: ifp %s cmd 0x%08lx (%c%c [%lu] "
2896 "%c %lu) error %d\n", __func__
,
2897 proc_name_address(p
), proc_pid(p
),
2898 ifname
, cmd
, (cmd
& IOC_IN
) ? 'I' : ' ',
2899 (cmd
& IOC_OUT
) ? 'O' : ' ', IOCPARM_LEN(cmd
),
2900 (char)IOCGROUP(cmd
), cmd
& 0xff, error
);
2901 } else if (if_verbose
> 1) {
2902 printf("%s[%s,%d]: ifp %s cmd 0x%08lx (%c%c [%lu] "
2903 "%c %lu) OK\n", __func__
,
2904 proc_name_address(p
), proc_pid(p
),
2905 ifname
, cmd
, (cmd
& IOC_IN
) ? 'I' : ' ',
2906 (cmd
& IOC_OUT
) ? 'O' : ' ', IOCPARM_LEN(cmd
),
2907 (char)IOCGROUP(cmd
), cmd
& 0xff);
2914 static __attribute__((noinline
)) int
2915 ifioctl_ifreq(struct socket
*so
, u_long cmd
, struct ifreq
*ifr
, struct proc
*p
)
2920 struct kev_msg ev_msg
;
2921 struct net_event_data ev_data
;
2923 bzero(&ev_data
, sizeof (struct net_event_data
));
2924 bzero(&ev_msg
, sizeof (struct kev_msg
));
2929 error
= proc_suser(p
);
2932 return (if_clone_create(ifr
->ifr_name
, sizeof(ifr
->ifr_name
),
2933 cmd
== SIOCIFCREATE2
? ifr
->ifr_data
: NULL
));
2935 error
= proc_suser(p
);
2938 return (if_clone_destroy(ifr
->ifr_name
));
2942 * ioctls which require ifp. Note that we acquire dlil_ifnet_lock
2943 * here to ensure that the ifnet, if found, has been fully attached.
2946 ifp
= ifunit(ifr
->ifr_name
);
2954 ifnet_lock_shared(ifp
);
2955 ifr
->ifr_flags
= ifp
->if_flags
;
2956 ifnet_lock_done(ifp
);
2960 ifnet_lock_shared(ifp
);
2961 ifr
->ifr_eflags
= ifp
->if_eflags
;
2962 ifnet_lock_done(ifp
);
2966 ifnet_lock_shared(ifp
);
2967 ifr
->ifr_reqcap
= ifp
->if_capabilities
;
2968 ifr
->ifr_curcap
= ifp
->if_capenable
;
2969 ifnet_lock_done(ifp
);
2974 error
= mac_ifnet_label_get(kauth_cred_get(), ifr
, ifp
);
2978 error
= mac_ifnet_label_set(kauth_cred_get(), ifr
, ifp
);
2980 #endif /* CONFIG_MACF_NET */
2983 ifnet_lock_shared(ifp
);
2984 ifr
->ifr_metric
= ifp
->if_metric
;
2985 ifnet_lock_done(ifp
);
2989 ifnet_lock_shared(ifp
);
2990 ifr
->ifr_mtu
= ifp
->if_mtu
;
2991 ifnet_lock_done(ifp
);
2995 ifnet_lock_shared(ifp
);
2996 ifr
->ifr_phys
= ifp
->if_physical
;
2997 ifnet_lock_done(ifp
);
3001 error
= proc_suser(p
);
3005 (void) ifnet_set_flags(ifp
, ifr
->ifr_flags
,
3006 (u_int16_t
)~IFF_CANTCHANGE
);
3009 * Note that we intentionally ignore any error from below
3010 * for the SIOCSIFFLAGS case.
3012 (void) ifnet_ioctl(ifp
, SOCK_DOM(so
), cmd
, (caddr_t
)ifr
);
3015 * Send the event even upon error from the driver because
3016 * we changed the flags.
3018 dlil_post_sifflags_msg(ifp
);
3020 ifnet_touch_lastchange(ifp
);
3024 error
= proc_suser(p
);
3028 if ((ifr
->ifr_reqcap
& ~ifp
->if_capabilities
)) {
3032 error
= ifnet_ioctl(ifp
, SOCK_DOM(so
), cmd
, (caddr_t
)ifr
);
3034 ifnet_touch_lastchange(ifp
);
3038 error
= proc_suser(p
);
3042 ifp
->if_metric
= ifr
->ifr_metric
;
3044 ev_msg
.vendor_code
= KEV_VENDOR_APPLE
;
3045 ev_msg
.kev_class
= KEV_NETWORK_CLASS
;
3046 ev_msg
.kev_subclass
= KEV_DL_SUBCLASS
;
3048 ev_msg
.event_code
= KEV_DL_SIFMETRICS
;
3049 strlcpy(&ev_data
.if_name
[0], ifp
->if_name
, IFNAMSIZ
);
3050 ev_data
.if_family
= ifp
->if_family
;
3051 ev_data
.if_unit
= (u_int32_t
) ifp
->if_unit
;
3052 ev_msg
.dv
[0].data_length
= sizeof(struct net_event_data
);
3053 ev_msg
.dv
[0].data_ptr
= &ev_data
;
3055 ev_msg
.dv
[1].data_length
= 0;
3056 dlil_post_complete_msg(ifp
, &ev_msg
);
3058 ifnet_touch_lastchange(ifp
);
3062 error
= proc_suser(p
);
3066 error
= ifnet_ioctl(ifp
, SOCK_DOM(so
), cmd
, (caddr_t
)ifr
);
3070 ev_msg
.vendor_code
= KEV_VENDOR_APPLE
;
3071 ev_msg
.kev_class
= KEV_NETWORK_CLASS
;
3072 ev_msg
.kev_subclass
= KEV_DL_SUBCLASS
;
3074 ev_msg
.event_code
= KEV_DL_SIFPHYS
;
3075 strlcpy(&ev_data
.if_name
[0], ifp
->if_name
, IFNAMSIZ
);
3076 ev_data
.if_family
= ifp
->if_family
;
3077 ev_data
.if_unit
= (u_int32_t
) ifp
->if_unit
;
3078 ev_msg
.dv
[0].data_length
= sizeof(struct net_event_data
);
3079 ev_msg
.dv
[0].data_ptr
= &ev_data
;
3080 ev_msg
.dv
[1].data_length
= 0;
3081 dlil_post_complete_msg(ifp
, &ev_msg
);
3083 ifnet_touch_lastchange(ifp
);
3087 u_int32_t oldmtu
= ifp
->if_mtu
;
3088 struct ifclassq
*ifq
= &ifp
->if_snd
;
3090 error
= proc_suser(p
);
3094 if (ifp
->if_ioctl
== NULL
) {
3098 if (ifr
->ifr_mtu
< IF_MINMTU
|| ifr
->ifr_mtu
> IF_MAXMTU
) {
3102 error
= ifnet_ioctl(ifp
, SOCK_DOM(so
), cmd
, (caddr_t
)ifr
);
3106 ev_msg
.vendor_code
= KEV_VENDOR_APPLE
;
3107 ev_msg
.kev_class
= KEV_NETWORK_CLASS
;
3108 ev_msg
.kev_subclass
= KEV_DL_SUBCLASS
;
3110 ev_msg
.event_code
= KEV_DL_SIFMTU
;
3111 strlcpy(&ev_data
.if_name
[0], ifp
->if_name
, IFNAMSIZ
);
3112 ev_data
.if_family
= ifp
->if_family
;
3113 ev_data
.if_unit
= (u_int32_t
) ifp
->if_unit
;
3114 ev_msg
.dv
[0].data_length
= sizeof(struct net_event_data
);
3115 ev_msg
.dv
[0].data_ptr
= &ev_data
;
3116 ev_msg
.dv
[1].data_length
= 0;
3117 dlil_post_complete_msg(ifp
, &ev_msg
);
3119 ifnet_touch_lastchange(ifp
);
3123 * If the link MTU changed, do network layer specific procedure
3124 * and update all route entries associated with the interface,
3125 * so that their MTU metric gets updated.
3127 if (ifp
->if_mtu
!= oldmtu
) {
3128 if_rtmtu_update(ifp
);
3132 /* Inform all transmit queues about the new MTU */
3134 ifnet_update_sndq(ifq
, CLASSQ_EV_LINK_MTU
);
3142 error
= proc_suser(p
);
3146 /* Don't allow group membership on non-multicast interfaces. */
3147 if ((ifp
->if_flags
& IFF_MULTICAST
) == 0) {
3152 /* Don't let users screw up protocols' entries. */
3153 if (ifr
->ifr_addr
.sa_family
!= AF_UNSPEC
&&
3154 ifr
->ifr_addr
.sa_family
!= AF_LINK
) {
3160 * User is permitted to anonymously join a particular link
3161 * multicast group via SIOCADDMULTI. Subsequent join requested
3162 * for the same record which has an outstanding refcnt from a
3163 * past if_addmulti_anon() will not result in EADDRINUSE error
3164 * (unlike other BSDs.) Anonymously leaving a group is also
3165 * allowed only as long as there is an outstanding refcnt held
3166 * by a previous anonymous request, or else ENOENT (even if the
3167 * link-layer multicast membership exists for a network-layer
3170 if (cmd
== SIOCADDMULTI
) {
3171 error
= if_addmulti_anon(ifp
, &ifr
->ifr_addr
, NULL
);
3172 ev_msg
.event_code
= KEV_DL_ADDMULTI
;
3174 error
= if_delmulti_anon(ifp
, &ifr
->ifr_addr
);
3175 ev_msg
.event_code
= KEV_DL_DELMULTI
;
3180 ev_msg
.vendor_code
= KEV_VENDOR_APPLE
;
3181 ev_msg
.kev_class
= KEV_NETWORK_CLASS
;
3182 ev_msg
.kev_subclass
= KEV_DL_SUBCLASS
;
3183 strlcpy(&ev_data
.if_name
[0], ifp
->if_name
, IFNAMSIZ
);
3185 ev_data
.if_family
= ifp
->if_family
;
3186 ev_data
.if_unit
= (u_int32_t
) ifp
->if_unit
;
3187 ev_msg
.dv
[0].data_length
= sizeof(struct net_event_data
);
3188 ev_msg
.dv
[0].data_ptr
= &ev_data
;
3189 ev_msg
.dv
[1].data_length
= 0;
3190 dlil_post_complete_msg(ifp
, &ev_msg
);
3192 ifnet_touch_lastchange(ifp
);
3195 case SIOCDIFPHYADDR
:
3197 case SIOCSIFGENERIC
:
3202 error
= proc_suser(p
);
3206 error
= ifnet_ioctl(ifp
, SOCK_DOM(so
), cmd
, (caddr_t
)ifr
);
3210 ifnet_touch_lastchange(ifp
);
3213 case SIOCGIFLLADDR
: {
3214 struct sockaddr_dl
*sdl
= SDL(ifp
->if_lladdr
->ifa_addr
);
3216 if (sdl
->sdl_alen
== 0) {
3217 error
= EADDRNOTAVAIL
;
3220 /* If larger than 14-bytes we'll need another mechanism */
3221 if (sdl
->sdl_alen
> sizeof (ifr
->ifr_addr
.sa_data
)) {
3225 /* Follow the same convention used by SIOCSIFLLADDR */
3226 bzero(&ifr
->ifr_addr
, sizeof (ifr
->ifr_addr
));
3227 ifr
->ifr_addr
.sa_family
= AF_LINK
;
3228 ifr
->ifr_addr
.sa_len
= sdl
->sdl_alen
;
3229 error
= ifnet_guarded_lladdr_copy_bytes(ifp
,
3230 &ifr
->ifr_addr
.sa_data
, sdl
->sdl_alen
);
3235 ifr
->ifr_type
.ift_type
= ifp
->if_type
;
3236 ifr
->ifr_type
.ift_family
= ifp
->if_family
;
3237 ifr
->ifr_type
.ift_subfamily
= ifp
->if_subfamily
;
3240 case SIOCGIFFUNCTIONALTYPE
:
3241 ifr
->ifr_functional_type
= if_functional_type(ifp
, FALSE
);
3244 case SIOCGIFPSRCADDR
:
3245 case SIOCGIFPDSTADDR
:
3246 case SIOCGIFGENERIC
:
3250 error
= ifnet_ioctl(ifp
, SOCK_DOM(so
), cmd
, (caddr_t
)ifr
);
3253 case SIOCGIFWAKEFLAGS
:
3254 ifnet_lock_shared(ifp
);
3255 ifr
->ifr_wake_flags
= ifnet_get_wake_flags(ifp
);
3256 ifnet_lock_done(ifp
);
3259 case SIOCGIFGETRTREFCNT
:
3260 ifnet_lock_shared(ifp
);
3261 ifr
->ifr_route_refcnt
= ifp
->if_route_refcnt
;
3262 ifnet_lock_done(ifp
);
3265 case SIOCSIFOPPORTUNISTIC
:
3266 case SIOCGIFOPPORTUNISTIC
:
3267 error
= ifnet_getset_opportunistic(ifp
, cmd
, ifr
, p
);
3270 case SIOCGIFLINKQUALITYMETRIC
:
3271 ifnet_lock_shared(ifp
);
3272 if ((ifp
->if_interface_state
.valid_bitmask
&
3273 IF_INTERFACE_STATE_LQM_STATE_VALID
)) {
3274 ifr
->ifr_link_quality_metric
=
3275 ifp
->if_interface_state
.lqm_state
;
3276 } else if (IF_FULLY_ATTACHED(ifp
)) {
3277 ifr
->ifr_link_quality_metric
=
3278 IFNET_LQM_THRESH_UNKNOWN
;
3280 ifr
->ifr_link_quality_metric
=
3281 IFNET_LQM_THRESH_OFF
;
3283 ifnet_lock_done(ifp
);
3288 error
= ifnet_getset_log(ifp
, cmd
, ifr
, p
);
3291 case SIOCGIFDELEGATE
:
3292 ifnet_lock_shared(ifp
);
3293 ifr
->ifr_delegated
= ((ifp
->if_delegated
.ifp
!= NULL
) ?
3294 ifp
->if_delegated
.ifp
->if_index
: 0);
3295 ifnet_lock_done(ifp
);
3298 case SIOCGIFEXPENSIVE
:
3299 ifnet_lock_shared(ifp
);
3300 if (ifp
->if_eflags
& IFEF_EXPENSIVE
)
3301 ifr
->ifr_expensive
= 1;
3303 ifr
->ifr_expensive
= 0;
3304 ifnet_lock_done(ifp
);
3307 case SIOCSIFEXPENSIVE
:
3311 if ((error
= priv_check_cred(kauth_cred_get(),
3312 PRIV_NET_INTERFACE_CONTROL
, 0)) != 0)
3314 ifnet_lock_exclusive(ifp
);
3315 if (ifr
->ifr_expensive
)
3316 ifp
->if_eflags
|= IFEF_EXPENSIVE
;
3318 ifp
->if_eflags
&= ~IFEF_EXPENSIVE
;
3319 ifnet_lock_done(ifp
);
3321 * Update the expensive bit in the delegated interface
3324 ifnet_head_lock_shared();
3325 TAILQ_FOREACH(difp
, &ifnet_head
, if_link
) {
3326 ifnet_lock_exclusive(difp
);
3327 if (difp
->if_delegated
.ifp
== ifp
) {
3328 difp
->if_delegated
.expensive
=
3329 ifp
->if_eflags
& IFEF_EXPENSIVE
? 1 : 0;
3332 ifnet_lock_done(difp
);
3339 ifnet_lock_shared(ifp
);
3340 if (ifp
->if_eflags
& IFEF_2KCL
)
3344 ifnet_lock_done(ifp
);
3348 if ((error
= priv_check_cred(kauth_cred_get(),
3349 PRIV_NET_INTERFACE_CONTROL
, 0)) != 0)
3351 ifnet_lock_exclusive(ifp
);
3353 ifp
->if_eflags
|= IFEF_2KCL
;
3355 ifp
->if_eflags
&= ~IFEF_2KCL
;
3356 ifnet_lock_done(ifp
);
3358 case SIOCGSTARTDELAY
:
3359 ifnet_lock_shared(ifp
);
3360 if (ifp
->if_eflags
& IFEF_ENQUEUE_MULTI
) {
3361 ifr
->ifr_start_delay_qlen
=
3362 ifp
->if_start_delay_qlen
;
3363 ifr
->ifr_start_delay_timeout
=
3364 ifp
->if_start_delay_timeout
;
3366 ifr
->ifr_start_delay_qlen
= 0;
3367 ifr
->ifr_start_delay_timeout
= 0;
3369 ifnet_lock_done(ifp
);
3371 case SIOCSIFDSTADDR
:
3373 case SIOCSIFBRDADDR
:
3374 case SIOCSIFNETMASK
:
3376 case OSIOCGIFDSTADDR
:
3377 case OSIOCGIFBRDADDR
:
3378 case OSIOCGIFNETMASK
:
3380 VERIFY(so
->so_proto
!= NULL
);
3382 if (cmd
== SIOCSIFDSTADDR
|| cmd
== SIOCSIFADDR
||
3383 cmd
== SIOCSIFBRDADDR
|| cmd
== SIOCSIFNETMASK
) {
3384 #if BYTE_ORDER != BIG_ENDIAN
3385 if (ifr
->ifr_addr
.sa_family
== 0 &&
3386 ifr
->ifr_addr
.sa_len
< 16) {
3387 ifr
->ifr_addr
.sa_family
= ifr
->ifr_addr
.sa_len
;
3388 ifr
->ifr_addr
.sa_len
= 16;
3391 if (ifr
->ifr_addr
.sa_len
== 0)
3392 ifr
->ifr_addr
.sa_len
= 16;
3394 } else if (cmd
== OSIOCGIFADDR
) {
3395 cmd
= SIOCGIFADDR
; /* struct ifreq */
3396 } else if (cmd
== OSIOCGIFDSTADDR
) {
3397 cmd
= SIOCGIFDSTADDR
; /* struct ifreq */
3398 } else if (cmd
== OSIOCGIFBRDADDR
) {
3399 cmd
= SIOCGIFBRDADDR
; /* struct ifreq */
3400 } else if (cmd
== OSIOCGIFNETMASK
) {
3401 cmd
= SIOCGIFNETMASK
; /* struct ifreq */
3405 error
= ((*so
->so_proto
->pr_usrreqs
->pru_control
)(so
, cmd
,
3406 (caddr_t
)ifr
, ifp
, p
));
3407 socket_unlock(so
, 1);
3411 case OSIOCGIFDSTADDR
:
3412 case OSIOCGIFBRDADDR
:
3413 case OSIOCGIFNETMASK
:
3414 bcopy(&ifr
->ifr_addr
.sa_family
, &ifr
->ifr_addr
,
3418 if (cmd
== SIOCSIFKPI
) {
3419 int temperr
= proc_suser(p
);
3424 if (error
== EOPNOTSUPP
|| error
== ENOTSUP
) {
3425 error
= ifnet_ioctl(ifp
, SOCK_DOM(so
), cmd
,
3430 case SIOCGIFINTERFACESTATE
:
3431 if_get_state(ifp
, &ifr
->ifr_interface_state
);
3434 case SIOCSIFINTERFACESTATE
:
3435 if ((error
= priv_check_cred(kauth_cred_get(),
3436 PRIV_NET_INTERFACE_CONTROL
, 0)) != 0)
3439 error
= if_state_update(ifp
, &ifr
->ifr_interface_state
);
3442 case SIOCSIFPROBECONNECTIVITY
:
3443 if ((error
= priv_check_cred(kauth_cred_get(),
3444 PRIV_NET_INTERFACE_CONTROL
, 0)) != 0)
3446 error
= if_probe_connectivity(ifp
,
3447 ifr
->ifr_probe_connectivity
);
3449 case SIOCGIFPROBECONNECTIVITY
:
3450 if ((error
= priv_check_cred(kauth_cred_get(),
3451 PRIV_NET_INTERFACE_CONTROL
, 0)) != 0)
3453 if (ifp
->if_eflags
& IFEF_PROBE_CONNECTIVITY
)
3454 ifr
->ifr_probe_connectivity
= 1;
3456 ifr
->ifr_probe_connectivity
= 0;
3459 if ((ifp
->if_eflags
& (IFEF_ECN_ENABLE
|IFEF_ECN_DISABLE
)) ==
3461 ifr
->ifr_ecn_mode
= IFRTYPE_ECN_ENABLE
;
3462 else if ((ifp
->if_eflags
& (IFEF_ECN_ENABLE
|IFEF_ECN_DISABLE
)) ==
3464 ifr
->ifr_ecn_mode
= IFRTYPE_ECN_DISABLE
;
3466 ifr
->ifr_ecn_mode
= IFRTYPE_ECN_DEFAULT
;
3469 if ((error
= priv_check_cred(kauth_cred_get(),
3470 PRIV_NET_INTERFACE_CONTROL
, 0)) != 0)
3472 if (ifr
->ifr_ecn_mode
== IFRTYPE_ECN_DEFAULT
) {
3473 ifp
->if_eflags
&= ~(IFEF_ECN_ENABLE
|IFEF_ECN_DISABLE
);
3474 } else if (ifr
->ifr_ecn_mode
== IFRTYPE_ECN_ENABLE
) {
3475 ifp
->if_eflags
|= IFEF_ECN_ENABLE
;
3476 ifp
->if_eflags
&= ~IFEF_ECN_DISABLE
;
3477 } else if (ifr
->ifr_ecn_mode
== IFRTYPE_ECN_DISABLE
) {
3478 ifp
->if_eflags
|= IFEF_ECN_DISABLE
;
3479 ifp
->if_eflags
&= ~IFEF_ECN_ENABLE
;
3483 case SIOCSIFTIMESTAMPENABLE
:
3484 case SIOCSIFTIMESTAMPDISABLE
:
3485 error
= proc_suser(p
);
3489 ifnet_lock_exclusive(ifp
);
3490 if ((cmd
== SIOCSIFTIMESTAMPENABLE
&&
3491 (ifp
->if_xflags
& IFXF_TIMESTAMP_ENABLED
) != 0) ||
3492 (cmd
== SIOCSIFTIMESTAMPDISABLE
&&
3493 (ifp
->if_xflags
& IFXF_TIMESTAMP_ENABLED
) == 0)) {
3494 ifnet_lock_done(ifp
);
3497 if (cmd
== SIOCSIFTIMESTAMPENABLE
)
3498 ifp
->if_xflags
|= IFXF_TIMESTAMP_ENABLED
;
3500 ifp
->if_xflags
&= ~IFXF_TIMESTAMP_ENABLED
;
3501 ifnet_lock_done(ifp
);
3503 * Pass the setting to the interface if it supports either
3504 * software or hardware time stamping
3506 if (ifp
->if_capabilities
& (IFCAP_HW_TIMESTAMP
|
3507 IFCAP_SW_TIMESTAMP
)) {
3508 error
= ifnet_ioctl(ifp
, SOCK_DOM(so
), cmd
,
3512 case SIOCGIFTIMESTAMPENABLED
: {
3513 if ((ifp
->if_xflags
& IFXF_TIMESTAMP_ENABLED
) != 0)
3514 ifr
->ifr_intval
= 1;
3516 ifr
->ifr_intval
= 0;
3519 case SIOCSQOSMARKINGMODE
:
3520 if ((error
= priv_check_cred(kauth_cred_get(),
3521 PRIV_NET_INTERFACE_CONTROL
, 0)) != 0)
3523 error
= if_set_qosmarking_mode(ifp
, ifr
->ifr_qosmarking_mode
);
3526 case SIOCGQOSMARKINGMODE
:
3527 ifr
->ifr_qosmarking_mode
= ifp
->if_qosmarking_mode
;
3530 case SIOCSQOSMARKINGENABLED
:
3531 if ((error
= priv_check_cred(kauth_cred_get(),
3532 PRIV_NET_INTERFACE_CONTROL
, 0)) != 0)
3534 if (ifr
->ifr_qosmarking_enabled
!= 0)
3535 ifp
->if_eflags
|= IFEF_QOSMARKING_ENABLED
;
3537 ifp
->if_eflags
&= ~IFEF_QOSMARKING_ENABLED
;
3540 case SIOCGQOSMARKINGENABLED
:
3541 ifr
->ifr_qosmarking_enabled
=
3542 (ifp
->if_eflags
& IFEF_QOSMARKING_ENABLED
) ? 1 : 0;
3545 case SIOCSIFDISABLEOUTPUT
:
3546 #if (DEBUG || DEVELOPMENT)
3547 if (ifr
->ifr_disable_output
== 1) {
3548 error
= ifnet_disable_output(ifp
);
3549 } else if (ifr
->ifr_disable_output
== 0) {
3550 error
= ifnet_enable_output(ifp
);
3556 #endif /* (DEBUG || DEVELOPMENT) */
3558 case SIOCSIFLOWINTERNET
:
3559 if ((error
= priv_check_cred(kauth_cred_get(),
3560 PRIV_NET_INTERFACE_CONTROL
, 0)) != 0)
3563 ifnet_lock_exclusive(ifp
);
3564 if (ifr
->ifr_low_internet
& IFRTYPE_LOW_INTERNET_ENABLE_UL
)
3565 ifp
->if_xflags
|= IFXF_LOW_INTERNET_UL
;
3567 ifp
->if_xflags
&= ~(IFXF_LOW_INTERNET_UL
);
3568 if (ifr
->ifr_low_internet
& IFRTYPE_LOW_INTERNET_ENABLE_DL
)
3569 ifp
->if_xflags
|= IFXF_LOW_INTERNET_DL
;
3571 ifp
->if_xflags
&= ~(IFXF_LOW_INTERNET_DL
);
3572 ifnet_lock_done(ifp
);
3574 case SIOCGIFLOWINTERNET
:
3575 ifnet_lock_shared(ifp
);
3576 ifr
->ifr_low_internet
= 0;
3577 if (ifp
->if_xflags
& IFXF_LOW_INTERNET_UL
)
3578 ifr
->ifr_low_internet
|=
3579 IFRTYPE_LOW_INTERNET_ENABLE_UL
;
3580 if (ifp
->if_xflags
& IFXF_LOW_INTERNET_DL
)
3581 ifr
->ifr_low_internet
|=
3582 IFRTYPE_LOW_INTERNET_ENABLE_DL
;
3583 ifnet_lock_done(ifp
);
3594 ifioctllocked(struct socket
*so
, u_long cmd
, caddr_t data
, struct proc
*p
)
3598 socket_unlock(so
, 0);
3599 error
= ifioctl(so
, cmd
, data
, p
);
3605 * Set/clear promiscuous mode on interface ifp based on the truth value
3606 * of pswitch. The calls are reference counted so that only the first
3607 * "on" request actually has an effect, as does the final "off" request.
3608 * Results are undefined if the "off" and "on" requests are not matched.
3611 ifnet_set_promiscuous(
3619 ifnet_lock_exclusive(ifp
);
3620 oldflags
= ifp
->if_flags
;
3621 ifp
->if_pcount
+= pswitch
? 1 : -1;
3623 if (ifp
->if_pcount
> 0)
3624 ifp
->if_flags
|= IFF_PROMISC
;
3626 ifp
->if_flags
&= ~IFF_PROMISC
;
3628 newflags
= ifp
->if_flags
;
3629 ifnet_lock_done(ifp
);
3631 if (newflags
!= oldflags
&& (newflags
& IFF_UP
) != 0) {
3632 error
= ifnet_ioctl(ifp
, 0, SIOCSIFFLAGS
, NULL
);
3636 ifnet_lock_exclusive(ifp
);
3638 ifp
->if_pcount
-= pswitch
? 1 : -1;
3639 if (ifp
->if_pcount
> 0)
3640 ifp
->if_flags
|= IFF_PROMISC
;
3642 ifp
->if_flags
&= ~IFF_PROMISC
;
3643 ifnet_lock_done(ifp
);
3647 if (newflags
!= oldflags
) {
3648 log(LOG_INFO
, "%s: promiscuous mode %s%s\n",
3650 (newflags
& IFF_PROMISC
) != 0 ? "enable" : "disable",
3651 error
!= 0 ? " failed" : " succeeded");
3657 * Return interface configuration
3658 * of system. List may be used
3659 * in later ioctl's (above) to get
3660 * other information.
3664 ifconf(u_long cmd
, user_addr_t ifrp
, int *ret_space
)
3666 struct ifnet
*ifp
= NULL
;
3671 net_thread_marks_t marks
;
3673 marks
= net_thread_marks_push(NET_THREAD_CKREQ_LLADDR
);
3676 * Zero the ifr buffer to make sure we don't
3677 * disclose the contents of the stack.
3679 bzero(&ifr
, sizeof (struct ifreq
));
3682 ifnet_head_lock_shared();
3683 for (ifp
= ifnet_head
.tqh_first
; space
> sizeof (ifr
) &&
3684 ifp
; ifp
= ifp
->if_link
.tqe_next
) {
3686 size_t ifnlen
, addrs
;
3688 ifnlen
= snprintf(workbuf
, sizeof (workbuf
),
3689 "%s", if_name(ifp
));
3690 if (ifnlen
+ 1 > sizeof (ifr
.ifr_name
)) {
3691 error
= ENAMETOOLONG
;
3694 strlcpy(ifr
.ifr_name
, workbuf
, IFNAMSIZ
);
3697 ifnet_lock_shared(ifp
);
3700 ifa
= ifp
->if_addrhead
.tqh_first
;
3701 for (; space
> sizeof (ifr
) && ifa
;
3702 ifa
= ifa
->ifa_link
.tqe_next
) {
3703 struct sockaddr
*sa
;
3706 struct sockaddr_dl sdl
;
3707 uint8_t buf
[SOCK_MAXADDRLEN
+ 1];
3711 * Make sure to accomodate the largest possible
3712 * size of SA(if_lladdr)->sa_len.
3714 _CASSERT(sizeof (u
) == (SOCK_MAXADDRLEN
+ 1));
3720 if (ifa
== ifp
->if_lladdr
) {
3721 VERIFY(sa
->sa_family
== AF_LINK
);
3722 bcopy(sa
, &u
, sa
->sa_len
);
3724 ifnet_guarded_lladdr_copy_bytes(ifp
,
3725 LLADDR(&u
.sdl
), u
.sdl
.sdl_alen
);
3730 if (cmd
== OSIOCGIFCONF32
|| cmd
== OSIOCGIFCONF64
) {
3731 struct osockaddr
*osa
=
3732 (struct osockaddr
*)(void *)&ifr
.ifr_addr
;
3734 osa
->sa_family
= sa
->sa_family
;
3735 error
= copyout((caddr_t
)&ifr
, ifrp
,
3737 ifrp
+= sizeof (struct ifreq
);
3738 } else if (sa
->sa_len
<= sizeof (*sa
)) {
3740 error
= copyout((caddr_t
)&ifr
, ifrp
,
3742 ifrp
+= sizeof (struct ifreq
);
3745 sizeof (ifr
) + sa
->sa_len
- sizeof (*sa
)) {
3749 space
-= sa
->sa_len
- sizeof (*sa
);
3750 error
= copyout((caddr_t
)&ifr
, ifrp
,
3751 sizeof (ifr
.ifr_name
));
3753 error
= copyout((caddr_t
)sa
, (ifrp
+
3754 offsetof(struct ifreq
, ifr_addr
)),
3757 ifrp
+= (sa
->sa_len
+ offsetof(struct ifreq
,
3763 space
-= sizeof (ifr
);
3765 ifnet_lock_done(ifp
);
3770 bzero((caddr_t
)&ifr
.ifr_addr
, sizeof (ifr
.ifr_addr
));
3771 error
= copyout((caddr_t
)&ifr
, ifrp
, sizeof (ifr
));
3774 space
-= sizeof (ifr
);
3775 ifrp
+= sizeof (struct ifreq
);
3779 *ret_space
-= space
;
3780 net_thread_marks_pop(marks
);
3785 * Just like if_promisc(), but for all-multicast-reception mode.
3788 if_allmulti(struct ifnet
*ifp
, int onswitch
)
3793 ifnet_lock_exclusive(ifp
);
3796 if (ifp
->if_amcount
++ == 0) {
3797 ifp
->if_flags
|= IFF_ALLMULTI
;
3801 if (ifp
->if_amcount
> 1) {
3804 ifp
->if_amcount
= 0;
3805 ifp
->if_flags
&= ~IFF_ALLMULTI
;
3809 ifnet_lock_done(ifp
);
3812 error
= ifnet_ioctl(ifp
, 0, SIOCSIFFLAGS
, NULL
);
3819 static struct ifmultiaddr
*
3822 struct ifmultiaddr
*ifma
;
3824 ifma
= (how
== M_WAITOK
) ? zalloc(ifma_zone
) :
3825 zalloc_noblock(ifma_zone
);
3828 bzero(ifma
, ifma_size
);
3829 lck_mtx_init(&ifma
->ifma_lock
, ifa_mtx_grp
, ifa_mtx_attr
);
3830 ifma
->ifma_debug
|= IFD_ALLOC
;
3831 if (ifma_debug
!= 0) {
3832 ifma
->ifma_debug
|= IFD_DEBUG
;
3833 ifma
->ifma_trace
= ifma_trace
;
3840 ifma_free(struct ifmultiaddr
*ifma
)
3844 if (ifma
->ifma_protospec
!= NULL
) {
3845 panic("%s: Protospec not NULL for ifma=%p", __func__
, ifma
);
3847 } else if ((ifma
->ifma_flags
& IFMAF_ANONYMOUS
) ||
3848 ifma
->ifma_anoncnt
!= 0) {
3849 panic("%s: Freeing ifma=%p with outstanding anon req",
3852 } else if (ifma
->ifma_debug
& IFD_ATTACHED
) {
3853 panic("%s: ifma=%p attached to ifma_ifp=%p is being freed",
3854 __func__
, ifma
, ifma
->ifma_ifp
);
3856 } else if (!(ifma
->ifma_debug
& IFD_ALLOC
)) {
3857 panic("%s: ifma %p cannot be freed", __func__
, ifma
);
3859 } else if (ifma
->ifma_refcount
!= 0) {
3860 panic("%s: non-zero refcount ifma=%p", __func__
, ifma
);
3862 } else if (ifma
->ifma_reqcnt
!= 0) {
3863 panic("%s: non-zero reqcnt ifma=%p", __func__
, ifma
);
3865 } else if (ifma
->ifma_ifp
!= NULL
) {
3866 panic("%s: non-NULL ifma_ifp=%p for ifma=%p", __func__
,
3867 ifma
->ifma_ifp
, ifma
);
3869 } else if (ifma
->ifma_ll
!= NULL
) {
3870 panic("%s: non-NULL ifma_ll=%p for ifma=%p", __func__
,
3871 ifma
->ifma_ll
, ifma
);
3874 ifma
->ifma_debug
&= ~IFD_ALLOC
;
3875 if ((ifma
->ifma_debug
& (IFD_DEBUG
| IFD_TRASHED
)) ==
3876 (IFD_DEBUG
| IFD_TRASHED
)) {
3877 lck_mtx_lock(&ifma_trash_lock
);
3878 TAILQ_REMOVE(&ifma_trash_head
, (struct ifmultiaddr_dbg
*)ifma
,
3880 lck_mtx_unlock(&ifma_trash_lock
);
3881 ifma
->ifma_debug
&= ~IFD_TRASHED
;
3885 if (ifma
->ifma_addr
!= NULL
) {
3886 FREE(ifma
->ifma_addr
, M_IFADDR
);
3887 ifma
->ifma_addr
= NULL
;
3889 lck_mtx_destroy(&ifma
->ifma_lock
, ifa_mtx_grp
);
3890 zfree(ifma_zone
, ifma
);
3894 ifma_trace(struct ifmultiaddr
*ifma
, int refhold
)
3896 struct ifmultiaddr_dbg
*ifma_dbg
= (struct ifmultiaddr_dbg
*)ifma
;
3901 if (!(ifma
->ifma_debug
& IFD_DEBUG
)) {
3902 panic("%s: ifma %p has no debug structure", __func__
, ifma
);
3906 cnt
= &ifma_dbg
->ifma_refhold_cnt
;
3907 tr
= ifma_dbg
->ifma_refhold
;
3909 cnt
= &ifma_dbg
->ifma_refrele_cnt
;
3910 tr
= ifma_dbg
->ifma_refrele
;
3913 idx
= atomic_add_16_ov(cnt
, 1) % IFMA_TRACE_HIST_SIZE
;
3914 ctrace_record(&tr
[idx
]);
3918 ifma_addref(struct ifmultiaddr
*ifma
, int locked
)
3923 IFMA_LOCK_ASSERT_HELD(ifma
);
3925 if (++ifma
->ifma_refcount
== 0) {
3926 panic("%s: ifma=%p wraparound refcnt", __func__
, ifma
);
3928 } else if (ifma
->ifma_trace
!= NULL
) {
3929 (*ifma
->ifma_trace
)(ifma
, TRUE
);
3936 ifma_remref(struct ifmultiaddr
*ifma
)
3938 struct ifmultiaddr
*ll
;
3942 if (ifma
->ifma_refcount
== 0) {
3943 panic("%s: ifma=%p negative refcnt", __func__
, ifma
);
3945 } else if (ifma
->ifma_trace
!= NULL
) {
3946 (*ifma
->ifma_trace
)(ifma
, FALSE
);
3949 --ifma
->ifma_refcount
;
3950 if (ifma
->ifma_refcount
> 0) {
3956 ifma
->ifma_ifp
= NULL
;
3957 ifma
->ifma_ll
= NULL
;
3959 ifma_free(ifma
); /* deallocate it */
3966 if_attach_ifma(struct ifnet
*ifp
, struct ifmultiaddr
*ifma
, int anon
)
3968 ifnet_lock_assert(ifp
, IFNET_LCK_ASSERT_EXCLUSIVE
);
3969 IFMA_LOCK_ASSERT_HELD(ifma
);
3971 if (ifma
->ifma_ifp
!= ifp
) {
3972 panic("%s: Mismatch ifma_ifp=%p != ifp=%p", __func__
,
3973 ifma
->ifma_ifp
, ifp
);
3975 } else if (ifma
->ifma_debug
& IFD_ATTACHED
) {
3976 panic("%s: Attempt to attach an already attached ifma=%p",
3979 } else if (anon
&& (ifma
->ifma_flags
& IFMAF_ANONYMOUS
)) {
3980 panic("%s: ifma=%p unexpected IFMAF_ANONYMOUS", __func__
, ifma
);
3982 } else if (ifma
->ifma_debug
& IFD_TRASHED
) {
3983 panic("%s: Attempt to reattach a detached ifma=%p",
3988 ifma
->ifma_reqcnt
++;
3989 VERIFY(ifma
->ifma_reqcnt
== 1);
3990 IFMA_ADDREF_LOCKED(ifma
);
3991 ifma
->ifma_debug
|= IFD_ATTACHED
;
3993 ifma
->ifma_anoncnt
++;
3994 VERIFY(ifma
->ifma_anoncnt
== 1);
3995 ifma
->ifma_flags
|= IFMAF_ANONYMOUS
;
3998 LIST_INSERT_HEAD(&ifp
->if_multiaddrs
, ifma
, ifma_link
);
4002 if_detach_ifma(struct ifnet
*ifp
, struct ifmultiaddr
*ifma
, int anon
)
4004 ifnet_lock_assert(ifp
, IFNET_LCK_ASSERT_EXCLUSIVE
);
4005 IFMA_LOCK_ASSERT_HELD(ifma
);
4007 if (ifma
->ifma_reqcnt
== 0) {
4008 panic("%s: ifma=%p negative reqcnt", __func__
, ifma
);
4010 } else if (anon
&& !(ifma
->ifma_flags
& IFMAF_ANONYMOUS
)) {
4011 panic("%s: ifma=%p missing IFMAF_ANONYMOUS", __func__
, ifma
);
4013 } else if (anon
&& ifma
->ifma_anoncnt
== 0) {
4014 panic("%s: ifma=%p negative anonreqcnt", __func__
, ifma
);
4016 } else if (ifma
->ifma_ifp
!= ifp
) {
4017 panic("%s: Mismatch ifma_ifp=%p, ifp=%p", __func__
,
4018 ifma
->ifma_ifp
, ifp
);
4023 --ifma
->ifma_anoncnt
;
4024 if (ifma
->ifma_anoncnt
> 0)
4026 ifma
->ifma_flags
&= ~IFMAF_ANONYMOUS
;
4029 --ifma
->ifma_reqcnt
;
4030 if (ifma
->ifma_reqcnt
> 0)
4033 if (ifma
->ifma_protospec
!= NULL
) {
4034 panic("%s: Protospec not NULL for ifma=%p", __func__
, ifma
);
4036 } else if ((ifma
->ifma_flags
& IFMAF_ANONYMOUS
) ||
4037 ifma
->ifma_anoncnt
!= 0) {
4038 panic("%s: Detaching ifma=%p with outstanding anon req",
4041 } else if (!(ifma
->ifma_debug
& IFD_ATTACHED
)) {
4042 panic("%s: Attempt to detach an unattached address ifma=%p",
4045 } else if (ifma
->ifma_debug
& IFD_TRASHED
) {
4046 panic("%s: ifma %p is already in trash list", __func__
, ifma
);
4051 * NOTE: Caller calls IFMA_REMREF
4053 ifma
->ifma_debug
&= ~IFD_ATTACHED
;
4054 LIST_REMOVE(ifma
, ifma_link
);
4055 if (LIST_EMPTY(&ifp
->if_multiaddrs
))
4056 ifp
->if_updatemcasts
= 0;
4058 if (ifma
->ifma_debug
& IFD_DEBUG
) {
4059 /* Become a regular mutex, just in case */
4060 IFMA_CONVERT_LOCK(ifma
);
4061 lck_mtx_lock(&ifma_trash_lock
);
4062 TAILQ_INSERT_TAIL(&ifma_trash_head
,
4063 (struct ifmultiaddr_dbg
*)ifma
, ifma_trash_link
);
4064 lck_mtx_unlock(&ifma_trash_lock
);
4065 ifma
->ifma_debug
|= IFD_TRASHED
;
4072 * Find an ifmultiaddr that matches a socket address on an interface.
4074 * Caller is responsible for holding the ifnet_lock while calling
4078 if_addmulti_doesexist(struct ifnet
*ifp
, const struct sockaddr
*sa
,
4079 struct ifmultiaddr
**retifma
, int anon
)
4081 struct ifmultiaddr
*ifma
;
4083 for (ifma
= LIST_FIRST(&ifp
->if_multiaddrs
); ifma
!= NULL
;
4084 ifma
= LIST_NEXT(ifma
, ifma_link
)) {
4085 IFMA_LOCK_SPIN(ifma
);
4086 if (!ifa_equal(sa
, ifma
->ifma_addr
)) {
4091 VERIFY(!(ifma
->ifma_flags
& IFMAF_ANONYMOUS
) ||
4092 ifma
->ifma_anoncnt
!= 0);
4093 VERIFY((ifma
->ifma_flags
& IFMAF_ANONYMOUS
) ||
4094 ifma
->ifma_anoncnt
== 0);
4095 ifma
->ifma_anoncnt
++;
4096 if (!(ifma
->ifma_flags
& IFMAF_ANONYMOUS
)) {
4097 VERIFY(ifma
->ifma_anoncnt
== 1);
4098 ifma
->ifma_flags
|= IFMAF_ANONYMOUS
;
4101 if (!anon
|| ifma
->ifma_anoncnt
== 1) {
4102 ifma
->ifma_reqcnt
++;
4103 VERIFY(ifma
->ifma_reqcnt
> 1);
4105 if (retifma
!= NULL
) {
4107 IFMA_ADDREF_LOCKED(ifma
);
4116 * Radar 3642395, make sure all multicasts are in a standard format.
4118 static struct sockaddr
*
4119 copy_and_normalize(const struct sockaddr
*original
)
4122 const u_char
*aptr
= NULL
;
4123 struct sockaddr
*copy
= NULL
;
4124 struct sockaddr_dl
*sdl_new
= NULL
;
4127 if (original
->sa_family
!= AF_LINK
&&
4128 original
->sa_family
!= AF_UNSPEC
) {
4129 /* Just make a copy */
4130 MALLOC(copy
, struct sockaddr
*, original
->sa_len
,
4131 M_IFADDR
, M_WAITOK
);
4133 bcopy(original
, copy
, original
->sa_len
);
4137 switch (original
->sa_family
) {
4139 const struct sockaddr_dl
*sdl_original
=
4140 (struct sockaddr_dl
*)(uintptr_t)(size_t)original
;
4142 if (sdl_original
->sdl_nlen
+ sdl_original
->sdl_alen
+
4143 sdl_original
->sdl_slen
+
4144 offsetof(struct sockaddr_dl
, sdl_data
) >
4145 sdl_original
->sdl_len
)
4148 alen
= sdl_original
->sdl_alen
;
4149 aptr
= CONST_LLADDR(sdl_original
);
4154 if (original
->sa_len
< ETHER_ADDR_LEN
+
4155 offsetof(struct sockaddr
, sa_data
)) {
4159 alen
= ETHER_ADDR_LEN
;
4160 aptr
= (const u_char
*)original
->sa_data
;
4165 if (alen
== 0 || aptr
== NULL
)
4168 len
= alen
+ offsetof(struct sockaddr_dl
, sdl_data
);
4169 MALLOC(sdl_new
, struct sockaddr_dl
*, len
, M_IFADDR
, M_WAITOK
);
4171 if (sdl_new
!= NULL
) {
4172 bzero(sdl_new
, len
);
4173 sdl_new
->sdl_len
= len
;
4174 sdl_new
->sdl_family
= AF_LINK
;
4175 sdl_new
->sdl_alen
= alen
;
4176 bcopy(aptr
, LLADDR(sdl_new
), alen
);
4179 return ((struct sockaddr
*)sdl_new
);
4183 * Network-layer protocol domains which hold references to the underlying
4184 * link-layer record must use this routine.
4187 if_addmulti(struct ifnet
*ifp
, const struct sockaddr
*sa
,
4188 struct ifmultiaddr
**retifma
)
4190 return (if_addmulti_common(ifp
, sa
, retifma
, 0));
4194 * Anything other than network-layer protocol domains which hold references
4195 * to the underlying link-layer record must use this routine: SIOCADDMULTI
4196 * ioctl, ifnet_add_multicast(), if_bond.
4199 if_addmulti_anon(struct ifnet
*ifp
, const struct sockaddr
*sa
,
4200 struct ifmultiaddr
**retifma
)
4202 return (if_addmulti_common(ifp
, sa
, retifma
, 1));
4206 * Register an additional multicast address with a network interface.
4208 * - If the address is already present, bump the reference count on the
4209 * address and return.
4210 * - If the address is not link-layer, look up a link layer address.
4211 * - Allocate address structures for one or both addresses, and attach to the
4212 * multicast address list on the interface. If automatically adding a link
4213 * layer address, the protocol address will own a reference to the link
4214 * layer address, to be freed when it is freed.
4215 * - Notify the network device driver of an addition to the multicast address
4218 * 'sa' points to caller-owned memory with the desired multicast address.
4220 * 'retifma' will be used to return a pointer to the resulting multicast
4221 * address reference, if desired.
4223 * 'anon' indicates a link-layer address with no protocol address reference
4224 * made to it. Anything other than network-layer protocol domain requests
4225 * are considered as anonymous.
4228 if_addmulti_common(struct ifnet
*ifp
, const struct sockaddr
*sa
,
4229 struct ifmultiaddr
**retifma
, int anon
)
4231 struct sockaddr_storage storage
;
4232 struct sockaddr
*llsa
= NULL
;
4233 struct sockaddr
*dupsa
= NULL
;
4234 int error
= 0, ll_firstref
= 0, lladdr
;
4235 struct ifmultiaddr
*ifma
= NULL
;
4236 struct ifmultiaddr
*llifma
= NULL
;
4238 /* Only AF_UNSPEC/AF_LINK is allowed for an "anonymous" address */
4239 VERIFY(!anon
|| sa
->sa_family
== AF_UNSPEC
||
4240 sa
->sa_family
== AF_LINK
);
4242 /* If sa is a AF_LINK or AF_UNSPEC, duplicate and normalize it */
4243 if (sa
->sa_family
== AF_LINK
|| sa
->sa_family
== AF_UNSPEC
) {
4244 dupsa
= copy_and_normalize(sa
);
4245 if (dupsa
== NULL
) {
4252 ifnet_lock_exclusive(ifp
);
4253 if (!(ifp
->if_flags
& IFF_MULTICAST
)) {
4254 error
= EADDRNOTAVAIL
;
4255 ifnet_lock_done(ifp
);
4259 /* If the address is already present, return a new reference to it */
4260 error
= if_addmulti_doesexist(ifp
, sa
, retifma
, anon
);
4261 ifnet_lock_done(ifp
);
4266 * The address isn't already present; give the link layer a chance
4267 * to accept/reject it, and also find out which AF_LINK address this
4268 * maps to, if it isn't one already.
4270 error
= dlil_resolve_multi(ifp
, sa
, (struct sockaddr
*)&storage
,
4272 if (error
== 0 && storage
.ss_len
!= 0) {
4273 llsa
= copy_and_normalize((struct sockaddr
*)&storage
);
4279 llifma
= ifma_alloc(M_WAITOK
);
4280 if (llifma
== NULL
) {
4286 /* to be similar to FreeBSD */
4287 if (error
== EOPNOTSUPP
)
4289 else if (error
!= 0)
4292 /* Allocate while we aren't holding any locks */
4293 if (dupsa
== NULL
) {
4294 dupsa
= copy_and_normalize(sa
);
4295 if (dupsa
== NULL
) {
4300 ifma
= ifma_alloc(M_WAITOK
);
4306 ifnet_lock_exclusive(ifp
);
4308 * Check again for the matching multicast.
4310 error
= if_addmulti_doesexist(ifp
, sa
, retifma
, anon
);
4312 ifnet_lock_done(ifp
);
4316 if (llifma
!= NULL
) {
4317 VERIFY(!anon
); /* must not get here if "anonymous" */
4318 if (if_addmulti_doesexist(ifp
, llsa
, &ifma
->ifma_ll
, 0) == 0) {
4319 FREE(llsa
, M_IFADDR
);
4323 VERIFY(ifma
->ifma_ll
->ifma_ifp
== ifp
);
4326 llifma
->ifma_addr
= llsa
;
4327 llifma
->ifma_ifp
= ifp
;
4329 if_attach_ifma(ifp
, llifma
, 0);
4330 /* add extra refcnt for ifma */
4331 IFMA_ADDREF_LOCKED(llifma
);
4332 IFMA_UNLOCK(llifma
);
4333 ifma
->ifma_ll
= llifma
;
4337 /* "anonymous" request should not result in network address */
4338 VERIFY(!anon
|| ifma
->ifma_ll
== NULL
);
4340 ifma
->ifma_addr
= dupsa
;
4341 ifma
->ifma_ifp
= ifp
;
4343 if_attach_ifma(ifp
, ifma
, anon
);
4344 IFMA_ADDREF_LOCKED(ifma
); /* for this routine */
4345 if (retifma
!= NULL
) {
4347 IFMA_ADDREF_LOCKED(*retifma
); /* for caller */
4349 lladdr
= (ifma
->ifma_addr
->sa_family
== AF_UNSPEC
||
4350 ifma
->ifma_addr
->sa_family
== AF_LINK
);
4352 ifnet_lock_done(ifp
);
4354 rt_newmaddrmsg(RTM_NEWMADDR
, ifma
);
4355 IFMA_REMREF(ifma
); /* for this routine */
4358 * We are certain we have added something, so call down to the
4359 * interface to let them know about it. Do this only for newly-
4360 * added AF_LINK/AF_UNSPEC address in the if_multiaddrs set.
4362 if (lladdr
|| ll_firstref
)
4363 (void) ifnet_ioctl(ifp
, 0, SIOCADDMULTI
, NULL
);
4365 if (ifp
->if_updatemcasts
> 0)
4366 ifp
->if_updatemcasts
= 0;
4374 FREE(dupsa
, M_IFADDR
);
4378 FREE(llsa
, M_IFADDR
);
4384 * Delete a multicast group membership by network-layer group address.
4385 * This routine is deprecated.
4388 if_delmulti(struct ifnet
*ifp
, const struct sockaddr
*sa
)
4390 return (if_delmulti_common(NULL
, ifp
, sa
, 0));
4394 * Delete a multicast group membership by group membership pointer.
4395 * Network-layer protocol domains must use this routine.
4398 if_delmulti_ifma(struct ifmultiaddr
*ifma
)
4400 return (if_delmulti_common(ifma
, NULL
, NULL
, 0));
4404 * Anything other than network-layer protocol domains which hold references
4405 * to the underlying link-layer record must use this routine: SIOCDELMULTI
4406 * ioctl, ifnet_remove_multicast(), if_bond.
4409 if_delmulti_anon(struct ifnet
*ifp
, const struct sockaddr
*sa
)
4411 return (if_delmulti_common(NULL
, ifp
, sa
, 1));
4415 * Delete a multicast group membership by network-layer group address.
4417 * Returns ENOENT if the entry could not be found.
4420 if_delmulti_common(struct ifmultiaddr
*ifma
, struct ifnet
*ifp
,
4421 const struct sockaddr
*sa
, int anon
)
4423 struct sockaddr
*dupsa
= NULL
;
4424 int lastref
, ll_lastref
= 0, lladdr
;
4425 struct ifmultiaddr
*ll
= NULL
;
4427 /* sanity check for callers */
4428 VERIFY(ifma
!= NULL
|| (ifp
!= NULL
&& sa
!= NULL
));
4431 ifp
= ifma
->ifma_ifp
;
4434 (sa
->sa_family
== AF_LINK
|| sa
->sa_family
== AF_UNSPEC
)) {
4435 dupsa
= copy_and_normalize(sa
);
4441 ifnet_lock_exclusive(ifp
);
4443 for (ifma
= LIST_FIRST(&ifp
->if_multiaddrs
); ifma
!= NULL
;
4444 ifma
= LIST_NEXT(ifma
, ifma_link
)) {
4446 if (!ifa_equal(sa
, ifma
->ifma_addr
) ||
4447 (anon
&& !(ifma
->ifma_flags
& IFMAF_ANONYMOUS
))) {
4448 VERIFY(!(ifma
->ifma_flags
& IFMAF_ANONYMOUS
) ||
4449 ifma
->ifma_anoncnt
!= 0);
4453 /* found; keep it locked */
4458 FREE(dupsa
, M_IFADDR
);
4459 ifnet_lock_done(ifp
);
4465 IFMA_LOCK_ASSERT_HELD(ifma
);
4466 IFMA_ADDREF_LOCKED(ifma
); /* for this routine */
4467 lastref
= if_detach_ifma(ifp
, ifma
, anon
);
4468 VERIFY(!lastref
|| (!(ifma
->ifma_debug
& IFD_ATTACHED
) &&
4469 ifma
->ifma_reqcnt
== 0));
4470 VERIFY(!anon
|| ifma
->ifma_ll
== NULL
);
4472 lladdr
= (ifma
->ifma_addr
->sa_family
== AF_UNSPEC
||
4473 ifma
->ifma_addr
->sa_family
== AF_LINK
);
4475 if (lastref
&& ll
!= NULL
) {
4477 ll_lastref
= if_detach_ifma(ifp
, ll
, 0);
4480 ifnet_lock_done(ifp
);
4483 rt_newmaddrmsg(RTM_DELMADDR
, ifma
);
4485 if ((ll
== NULL
&& lastref
&& lladdr
) || ll_lastref
) {
4487 * Make sure the interface driver is notified in the
4488 * case of a link layer mcast group being left. Do
4489 * this only for a AF_LINK/AF_UNSPEC address that has
4490 * been removed from the if_multiaddrs set.
4492 ifnet_ioctl(ifp
, 0, SIOCDELMULTI
, NULL
);
4496 IFMA_REMREF(ifma
); /* for if_multiaddrs list */
4498 IFMA_REMREF(ll
); /* for if_multiaddrs list */
4500 IFMA_REMREF(ifma
); /* for this routine */
4502 FREE(dupsa
, M_IFADDR
);
4508 * Shutdown all network activity. Used boot() when halting
4518 if (ifnet_list_get_all(IFNET_FAMILY_ANY
, &ifp
, &count
) == 0) {
4519 for (i
= 0; i
< count
; i
++) {
4521 dlil_proto_unplumb_all(ifp
[i
]);
4523 ifnet_list_free(ifp
);
4530 * Delete Routes for a Network Interface
4532 * Called for each routing entry via the rnh->rnh_walktree() call above
4533 * to delete all route entries referencing a detaching network interface.
4536 * rn pointer to node in the routing table
4537 * arg argument passed to rnh->rnh_walktree() - detaching interface
4541 * errno failed - reason indicated
4545 if_rtdel(struct radix_node
*rn
, void *arg
)
4547 struct rtentry
*rt
= (struct rtentry
*)rn
;
4548 struct ifnet
*ifp
= arg
;
4554 * Checking against RTF_UP protects against walktree
4555 * recursion problems with cloned routes.
4558 if (rt
->rt_ifp
== ifp
&& (rt
->rt_flags
& RTF_UP
)) {
4560 * Safe to drop rt_lock and use rt_key, rt_gateway,
4561 * since holding rnh_lock here prevents another thread
4562 * from calling rt_setgate() on this route.
4565 err
= rtrequest_locked(RTM_DELETE
, rt_key(rt
), rt
->rt_gateway
,
4566 rt_mask(rt
), rt
->rt_flags
, NULL
);
4568 log(LOG_WARNING
, "if_rtdel: error %d\n", err
);
4577 * Removes routing table reference to a given interface
4578 * for a given protocol family
4581 if_rtproto_del(struct ifnet
*ifp
, int protocol
)
4583 struct radix_node_head
*rnh
;
4585 if ((protocol
<= AF_MAX
) && (protocol
>= 0) &&
4586 ((rnh
= rt_tables
[protocol
]) != NULL
) && (ifp
!= NULL
)) {
4587 lck_mtx_lock(rnh_lock
);
4588 (void) rnh
->rnh_walktree(rnh
, if_rtdel
, ifp
);
4589 lck_mtx_unlock(rnh_lock
);
4594 if_rtmtu(struct radix_node
*rn
, void *arg
)
4596 struct rtentry
*rt
= (struct rtentry
*)rn
;
4597 struct ifnet
*ifp
= arg
;
4600 if (rt
->rt_ifp
== ifp
) {
4602 * Update the MTU of this entry only if the MTU
4603 * has not been locked (RTV_MTU is not set) and
4604 * if it was non-zero to begin with.
4606 if (!(rt
->rt_rmx
.rmx_locks
& RTV_MTU
) && rt
->rt_rmx
.rmx_mtu
)
4607 rt
->rt_rmx
.rmx_mtu
= ifp
->if_mtu
;
4615 * Update the MTU metric of all route entries in all protocol tables
4616 * associated with a particular interface; this is called when the
4617 * MTU of that interface has changed.
4620 if_rtmtu_update(struct ifnet
*ifp
)
4622 struct radix_node_head
*rnh
;
4625 for (p
= 0; p
< AF_MAX
+ 1; p
++) {
4626 if ((rnh
= rt_tables
[p
]) == NULL
)
4629 lck_mtx_lock(rnh_lock
);
4630 (void) rnh
->rnh_walktree(rnh
, if_rtmtu
, ifp
);
4631 lck_mtx_unlock(rnh_lock
);
4633 routegenid_update();
4636 __private_extern__
void
4637 if_data_internal_to_if_data(struct ifnet
*ifp
,
4638 const struct if_data_internal
*if_data_int
, struct if_data
*if_data
)
4641 #define COPYFIELD(fld) if_data->fld = if_data_int->fld
4642 #define COPYFIELD32(fld) if_data->fld = (u_int32_t)(if_data_int->fld)
4643 /* compiler will cast down to 32-bit */
4644 #define COPYFIELD32_ATOMIC(fld) do { \
4645 atomic_get_64(if_data->fld, \
4646 (u_int64_t *)(void *)(uintptr_t)&if_data_int->fld); \
4649 COPYFIELD(ifi_type
);
4650 COPYFIELD(ifi_typelen
);
4651 COPYFIELD(ifi_physical
);
4652 COPYFIELD(ifi_addrlen
);
4653 COPYFIELD(ifi_hdrlen
);
4654 COPYFIELD(ifi_recvquota
);
4655 COPYFIELD(ifi_xmitquota
);
4656 if_data
->ifi_unused1
= 0;
4658 COPYFIELD(ifi_metric
);
4659 if (if_data_int
->ifi_baudrate
& 0xFFFFFFFF00000000LL
) {
4660 if_data
->ifi_baudrate
= 0xFFFFFFFF;
4662 COPYFIELD32(ifi_baudrate
);
4665 COPYFIELD32_ATOMIC(ifi_ipackets
);
4666 COPYFIELD32_ATOMIC(ifi_ierrors
);
4667 COPYFIELD32_ATOMIC(ifi_opackets
);
4668 COPYFIELD32_ATOMIC(ifi_oerrors
);
4669 COPYFIELD32_ATOMIC(ifi_collisions
);
4670 COPYFIELD32_ATOMIC(ifi_ibytes
);
4671 COPYFIELD32_ATOMIC(ifi_obytes
);
4672 COPYFIELD32_ATOMIC(ifi_imcasts
);
4673 COPYFIELD32_ATOMIC(ifi_omcasts
);
4674 COPYFIELD32_ATOMIC(ifi_iqdrops
);
4675 COPYFIELD32_ATOMIC(ifi_noproto
);
4677 COPYFIELD(ifi_recvtiming
);
4678 COPYFIELD(ifi_xmittiming
);
4680 if_data
->ifi_lastchange
.tv_sec
= if_data_int
->ifi_lastchange
.tv_sec
;
4681 if_data
->ifi_lastchange
.tv_usec
= if_data_int
->ifi_lastchange
.tv_usec
;
4683 if_data
->ifi_lastchange
.tv_sec
+= boottime_sec();
4685 if_data
->ifi_unused2
= 0;
4686 COPYFIELD(ifi_hwassist
);
4687 if_data
->ifi_reserved1
= 0;
4688 if_data
->ifi_reserved2
= 0;
4689 #undef COPYFIELD32_ATOMIC
4694 __private_extern__
void
4695 if_data_internal_to_if_data64(struct ifnet
*ifp
,
4696 const struct if_data_internal
*if_data_int
,
4697 struct if_data64
*if_data64
)
4700 #define COPYFIELD64(fld) if_data64->fld = if_data_int->fld
4701 #define COPYFIELD64_ATOMIC(fld) do { \
4702 atomic_get_64(if_data64->fld, \
4703 (u_int64_t *)(void *)(uintptr_t)&if_data_int->fld); \
4706 COPYFIELD64(ifi_type
);
4707 COPYFIELD64(ifi_typelen
);
4708 COPYFIELD64(ifi_physical
);
4709 COPYFIELD64(ifi_addrlen
);
4710 COPYFIELD64(ifi_hdrlen
);
4711 COPYFIELD64(ifi_recvquota
);
4712 COPYFIELD64(ifi_xmitquota
);
4713 if_data64
->ifi_unused1
= 0;
4714 COPYFIELD64(ifi_mtu
);
4715 COPYFIELD64(ifi_metric
);
4716 COPYFIELD64(ifi_baudrate
);
4718 COPYFIELD64_ATOMIC(ifi_ipackets
);
4719 COPYFIELD64_ATOMIC(ifi_ierrors
);
4720 COPYFIELD64_ATOMIC(ifi_opackets
);
4721 COPYFIELD64_ATOMIC(ifi_oerrors
);
4722 COPYFIELD64_ATOMIC(ifi_collisions
);
4723 COPYFIELD64_ATOMIC(ifi_ibytes
);
4724 COPYFIELD64_ATOMIC(ifi_obytes
);
4725 COPYFIELD64_ATOMIC(ifi_imcasts
);
4726 COPYFIELD64_ATOMIC(ifi_omcasts
);
4727 COPYFIELD64_ATOMIC(ifi_iqdrops
);
4728 COPYFIELD64_ATOMIC(ifi_noproto
);
4731 * Note these two fields are actually 32 bit, so doing
4732 * COPYFIELD64_ATOMIC will cause them to be misaligned
4734 COPYFIELD64(ifi_recvtiming
);
4735 COPYFIELD64(ifi_xmittiming
);
4737 if_data64
->ifi_lastchange
.tv_sec
= if_data_int
->ifi_lastchange
.tv_sec
;
4738 if_data64
->ifi_lastchange
.tv_usec
= if_data_int
->ifi_lastchange
.tv_usec
;
4740 if_data64
->ifi_lastchange
.tv_sec
+= boottime_sec();
4745 __private_extern__
void
4746 if_copy_traffic_class(struct ifnet
*ifp
,
4747 struct if_traffic_class
*if_tc
)
4749 #define COPY_IF_TC_FIELD64_ATOMIC(fld) do { \
4750 atomic_get_64(if_tc->fld, \
4751 (u_int64_t *)(void *)(uintptr_t)&ifp->if_tc.fld); \
4754 bzero(if_tc
, sizeof (*if_tc
));
4755 COPY_IF_TC_FIELD64_ATOMIC(ifi_ibepackets
);
4756 COPY_IF_TC_FIELD64_ATOMIC(ifi_ibebytes
);
4757 COPY_IF_TC_FIELD64_ATOMIC(ifi_obepackets
);
4758 COPY_IF_TC_FIELD64_ATOMIC(ifi_obebytes
);
4759 COPY_IF_TC_FIELD64_ATOMIC(ifi_ibkpackets
);
4760 COPY_IF_TC_FIELD64_ATOMIC(ifi_ibkbytes
);
4761 COPY_IF_TC_FIELD64_ATOMIC(ifi_obkpackets
);
4762 COPY_IF_TC_FIELD64_ATOMIC(ifi_obkbytes
);
4763 COPY_IF_TC_FIELD64_ATOMIC(ifi_ivipackets
);
4764 COPY_IF_TC_FIELD64_ATOMIC(ifi_ivibytes
);
4765 COPY_IF_TC_FIELD64_ATOMIC(ifi_ovipackets
);
4766 COPY_IF_TC_FIELD64_ATOMIC(ifi_ovibytes
);
4767 COPY_IF_TC_FIELD64_ATOMIC(ifi_ivopackets
);
4768 COPY_IF_TC_FIELD64_ATOMIC(ifi_ivobytes
);
4769 COPY_IF_TC_FIELD64_ATOMIC(ifi_ovopackets
);
4770 COPY_IF_TC_FIELD64_ATOMIC(ifi_ovobytes
);
4771 COPY_IF_TC_FIELD64_ATOMIC(ifi_ipvpackets
);
4772 COPY_IF_TC_FIELD64_ATOMIC(ifi_ipvbytes
);
4773 COPY_IF_TC_FIELD64_ATOMIC(ifi_opvpackets
);
4774 COPY_IF_TC_FIELD64_ATOMIC(ifi_opvbytes
);
4776 #undef COPY_IF_TC_FIELD64_ATOMIC
4780 if_copy_data_extended(struct ifnet
*ifp
, struct if_data_extended
*if_de
)
4782 #define COPY_IF_DE_FIELD64_ATOMIC(fld) do { \
4783 atomic_get_64(if_de->fld, \
4784 (u_int64_t *)(void *)(uintptr_t)&ifp->if_data.fld); \
4787 bzero(if_de
, sizeof (*if_de
));
4788 COPY_IF_DE_FIELD64_ATOMIC(ifi_alignerrs
);
4789 COPY_IF_DE_FIELD64_ATOMIC(ifi_dt_bytes
);
4790 COPY_IF_DE_FIELD64_ATOMIC(ifi_fpackets
);
4791 COPY_IF_DE_FIELD64_ATOMIC(ifi_fbytes
);
4793 #undef COPY_IF_DE_FIELD64_ATOMIC
4797 if_copy_packet_stats(struct ifnet
*ifp
, struct if_packet_stats
*if_ps
)
4799 #define COPY_IF_PS_TCP_FIELD64_ATOMIC(fld) do { \
4800 atomic_get_64(if_ps->ifi_tcp_##fld, \
4801 (u_int64_t *)(void *)(uintptr_t)&ifp->if_tcp_stat->fld); \
4804 #define COPY_IF_PS_UDP_FIELD64_ATOMIC(fld) do { \
4805 atomic_get_64(if_ps->ifi_udp_##fld, \
4806 (u_int64_t *)(void *)(uintptr_t)&ifp->if_udp_stat->fld); \
4809 COPY_IF_PS_TCP_FIELD64_ATOMIC(badformat
);
4810 COPY_IF_PS_TCP_FIELD64_ATOMIC(unspecv6
);
4811 COPY_IF_PS_TCP_FIELD64_ATOMIC(synfin
);
4812 COPY_IF_PS_TCP_FIELD64_ATOMIC(badformatipsec
);
4813 COPY_IF_PS_TCP_FIELD64_ATOMIC(noconnnolist
);
4814 COPY_IF_PS_TCP_FIELD64_ATOMIC(noconnlist
);
4815 COPY_IF_PS_TCP_FIELD64_ATOMIC(listbadsyn
);
4816 COPY_IF_PS_TCP_FIELD64_ATOMIC(icmp6unreach
);
4817 COPY_IF_PS_TCP_FIELD64_ATOMIC(deprecate6
);
4818 COPY_IF_PS_TCP_FIELD64_ATOMIC(ooopacket
);
4819 COPY_IF_PS_TCP_FIELD64_ATOMIC(rstinsynrcv
);
4820 COPY_IF_PS_TCP_FIELD64_ATOMIC(dospacket
);
4821 COPY_IF_PS_TCP_FIELD64_ATOMIC(cleanup
);
4822 COPY_IF_PS_TCP_FIELD64_ATOMIC(synwindow
);
4824 COPY_IF_PS_UDP_FIELD64_ATOMIC(port_unreach
);
4825 COPY_IF_PS_UDP_FIELD64_ATOMIC(faithprefix
);
4826 COPY_IF_PS_UDP_FIELD64_ATOMIC(port0
);
4827 COPY_IF_PS_UDP_FIELD64_ATOMIC(badlength
);
4828 COPY_IF_PS_UDP_FIELD64_ATOMIC(badchksum
);
4829 COPY_IF_PS_UDP_FIELD64_ATOMIC(badmcast
);
4830 COPY_IF_PS_UDP_FIELD64_ATOMIC(cleanup
);
4831 COPY_IF_PS_UDP_FIELD64_ATOMIC(badipsec
);
4833 #undef COPY_IF_PS_TCP_FIELD64_ATOMIC
4834 #undef COPY_IF_PS_UDP_FIELD64_ATOMIC
4838 if_copy_rxpoll_stats(struct ifnet
*ifp
, struct if_rxpoll_stats
*if_rs
)
4840 bzero(if_rs
, sizeof (*if_rs
));
4841 if (!(ifp
->if_eflags
& IFEF_RXPOLL
) || !ifnet_is_attached(ifp
, 1))
4844 /* by now, ifnet will stay attached so if_inp must be valid */
4845 VERIFY(ifp
->if_inp
!= NULL
);
4846 bcopy(&ifp
->if_inp
->pstats
, if_rs
, sizeof (*if_rs
));
4848 /* Release the IO refcnt */
4849 ifnet_decr_iorefcnt(ifp
);
4853 ifa_remref(struct ifaddr
*ifa
, int locked
)
4858 IFA_LOCK_ASSERT_HELD(ifa
);
4860 if (ifa
->ifa_refcnt
== 0)
4861 panic("%s: ifa %p negative refcnt\n", __func__
, ifa
);
4862 else if (ifa
->ifa_trace
!= NULL
)
4863 (*ifa
->ifa_trace
)(ifa
, FALSE
);
4864 if (--ifa
->ifa_refcnt
== 0) {
4865 if (ifa
->ifa_debug
& IFD_ATTACHED
)
4866 panic("ifa %p attached to ifp is being freed\n", ifa
);
4868 * Some interface addresses are allocated either statically
4869 * or carved out of a larger block. Only free it if it was
4870 * allocated via MALLOC or via the corresponding per-address
4871 * family allocator. Otherwise, leave it alone.
4873 if (ifa
->ifa_debug
& IFD_ALLOC
) {
4874 if (ifa
->ifa_free
== NULL
) {
4876 FREE(ifa
, M_IFADDR
);
4878 /* Become a regular mutex */
4879 IFA_CONVERT_LOCK(ifa
);
4880 /* callee will unlock */
4881 (*ifa
->ifa_free
)(ifa
);
4889 if (!locked
&& ifa
!= NULL
)
4896 ifa_addref(struct ifaddr
*ifa
, int locked
)
4901 IFA_LOCK_ASSERT_HELD(ifa
);
4903 if (++ifa
->ifa_refcnt
== 0) {
4904 panic("%s: ifa %p wraparound refcnt\n", __func__
, ifa
);
4906 } else if (ifa
->ifa_trace
!= NULL
) {
4907 (*ifa
->ifa_trace
)(ifa
, TRUE
);
4914 ifa_lock_init(struct ifaddr
*ifa
)
4916 lck_mtx_init(&ifa
->ifa_lock
, ifa_mtx_grp
, ifa_mtx_attr
);
4920 ifa_lock_destroy(struct ifaddr
*ifa
)
4922 IFA_LOCK_ASSERT_NOTHELD(ifa
);
4923 lck_mtx_destroy(&ifa
->ifa_lock
, ifa_mtx_grp
);
4929 * The switch statement below does nothing at runtime, as it serves as a
4930 * compile time check to ensure that all of the socket 'i' ioctls (those
4931 * in the 'i' group going thru soo_ioctl) that are made available by the
4932 * networking stack is unique. This works as long as this routine gets
4933 * updated each time a new interface ioctl gets added.
4935 * Any failures at compile time indicates duplicated ioctl values.
4937 static __attribute__((unused
)) void
4938 ifioctl_cassert(void)
4941 * This is equivalent to _CASSERT() and the compiler wouldn't
4942 * generate any instructions, thus for compile time only.
4944 switch ((u_long
)0) {
4947 /* bsd/net/if_ppp.h */
4949 case SIOCGPPPCSTATS
:
4952 /* bsd/netinet6/in6_var.h */
4953 case SIOCSIFADDR_IN6
:
4954 case SIOCGIFADDR_IN6
:
4955 case SIOCSIFDSTADDR_IN6
:
4956 case SIOCSIFNETMASK_IN6
:
4957 case SIOCGIFDSTADDR_IN6
:
4958 case SIOCGIFNETMASK_IN6
:
4959 case SIOCDIFADDR_IN6
:
4960 case SIOCAIFADDR_IN6_32
:
4961 case SIOCAIFADDR_IN6_64
:
4962 case SIOCSIFPHYADDR_IN6_32
:
4963 case SIOCSIFPHYADDR_IN6_64
:
4964 case SIOCGIFPSRCADDR_IN6
:
4965 case SIOCGIFPDSTADDR_IN6
:
4966 case SIOCGIFAFLAG_IN6
:
4967 case SIOCGDRLST_IN6_32
:
4968 case SIOCGDRLST_IN6_64
:
4969 case SIOCGPRLST_IN6_32
:
4970 case SIOCGPRLST_IN6_64
:
4971 case OSIOCGIFINFO_IN6
:
4972 case SIOCGIFINFO_IN6
:
4973 case SIOCSNDFLUSH_IN6
:
4974 case SIOCGNBRINFO_IN6_32
:
4975 case SIOCGNBRINFO_IN6_64
:
4976 case SIOCSPFXFLUSH_IN6
:
4977 case SIOCSRTRFLUSH_IN6
:
4978 case SIOCGIFALIFETIME_IN6
:
4979 case SIOCSIFALIFETIME_IN6
:
4980 case SIOCGIFSTAT_IN6
:
4981 case SIOCGIFSTAT_ICMP6
:
4982 case SIOCSDEFIFACE_IN6_32
:
4983 case SIOCSDEFIFACE_IN6_64
:
4984 case SIOCGDEFIFACE_IN6_32
:
4985 case SIOCGDEFIFACE_IN6_64
:
4986 case SIOCSIFINFO_FLAGS
:
4989 case SIOCGSCOPE6DEF
:
4990 case SIOCSIFPREFIX_IN6
:
4991 case SIOCGIFPREFIX_IN6
:
4992 case SIOCDIFPREFIX_IN6
:
4993 case SIOCAIFPREFIX_IN6
:
4994 case SIOCCIFPREFIX_IN6
:
4995 case SIOCSGIFPREFIX_IN6
:
4996 case SIOCPROTOATTACH_IN6_32
:
4997 case SIOCPROTOATTACH_IN6_64
:
4998 case SIOCPROTODETACH_IN6
:
4999 case SIOCLL_START_32
:
5000 case SIOCLL_START_64
:
5002 case SIOCAUTOCONF_START
:
5003 case SIOCAUTOCONF_STOP
:
5004 case SIOCSETROUTERMODE_IN6
:
5005 case SIOCLL_CGASTART_32
:
5006 case SIOCLL_CGASTART_64
:
5007 case SIOCGIFCGAPREP_IN6
:
5008 case SIOCSIFCGAPREP_IN6
:
5011 /* bsd/sys/sockio.h */
5014 case SIOCSIFDSTADDR
:
5015 case OSIOCGIFDSTADDR
:
5018 case OSIOCGIFBRDADDR
:
5019 case SIOCSIFBRDADDR
:
5020 case OSIOCGIFCONF32
:
5021 case OSIOCGIFCONF64
:
5022 case OSIOCGIFNETMASK
:
5023 case SIOCSIFNETMASK
:
5030 case SIOCGIFDSTADDR
:
5031 case SIOCGIFBRDADDR
:
5034 case SIOCGIFNETMASK
:
5036 case SIOCAUTONETMASK
:
5046 case SIOCGIFMEDIA32
:
5047 case SIOCGIFMEDIA64
:
5048 case SIOCSIFGENERIC
:
5049 case SIOCGIFGENERIC
:
5054 case SIOCSIFPHYADDR
:
5055 case SIOCGIFPSRCADDR
:
5056 case SIOCGIFPDSTADDR
:
5057 case SIOCDIFPHYADDR
:
5065 case SIOCPROTOATTACH
:
5066 case SIOCPROTODETACH
:
5075 case SIOCSDRVSPEC32
:
5076 case SIOCGDRVSPEC32
:
5077 case SIOCSDRVSPEC64
:
5078 case SIOCGDRVSPEC64
:
5083 case SIOCIFGCLONERS32
:
5084 case SIOCIFGCLONERS64
:
5086 case SIOCGIFASYNCMAP
:
5087 case SIOCSIFASYNCMAP
:
5091 #endif /* CONFIG_MACF_NET */
5095 case SIOCGIFWAKEFLAGS
:
5097 case SIOCGIFGETRTREFCNT
:
5098 case SIOCGIFLINKQUALITYMETRIC
:
5099 case SIOCSIFOPPORTUNISTIC
:
5100 case SIOCGIFOPPORTUNISTIC
:
5101 case SIOCSETROUTERMODE
:
5105 case SIOCSIFLINKPARAMS
:
5106 case SIOCGIFLINKPARAMS
:
5107 case SIOCGIFQUEUESTATS
:
5108 case SIOCSIFTHROTTLE
:
5109 case SIOCGIFTHROTTLE
:
5111 case SIOCGASSOCIDS32
:
5112 case SIOCGASSOCIDS64
:
5113 case SIOCGCONNIDS32
:
5114 case SIOCGCONNIDS64
:
5115 case SIOCGCONNINFO32
:
5116 case SIOCGCONNINFO64
:
5117 case SIOCSCONNORDER
:
5118 case SIOCGCONNORDER
:
5122 case SIOCGIFDELEGATE
:
5125 case SIOCGIFEXPENSIVE
:
5126 case SIOCSIFEXPENSIVE
:
5129 case SIOCGSTARTDELAY
:
5131 case SIOCAIFAGENTID
:
5132 case SIOCDIFAGENTID
:
5133 case SIOCGIFAGENTIDS32
:
5134 case SIOCGIFAGENTIDS64
:
5135 case SIOCGIFAGENTDATA32
:
5136 case SIOCGIFAGENTDATA64
:
5137 case SIOCGIFAGENTLIST32
:
5138 case SIOCGIFAGENTLIST64
:
5141 case SIOCSIFINTERFACESTATE
:
5142 case SIOCGIFINTERFACESTATE
:
5143 case SIOCSIFPROBECONNECTIVITY
:
5144 case SIOCGIFPROBECONNECTIVITY
:
5146 case SIOCGIFFUNCTIONALTYPE
:
5147 case SIOCSIFNETSIGNATURE
:
5148 case SIOCGIFNETSIGNATURE
:
5153 case SIOCSQOSMARKINGMODE
:
5154 case SIOCSQOSMARKINGENABLED
:
5155 case SIOCGQOSMARKINGMODE
:
5156 case SIOCGQOSMARKINGENABLED
:
5158 case SIOCGIFPROTOLIST32
:
5159 case SIOCGIFPROTOLIST64
:
5165 ifnet_mbuf_packetpreamblelen(struct ifnet
*ifp
)
5171 /* The following is used to enqueue work items for interface events */
5174 union sockaddr_in_4_6 addr
;
5175 uint32_t intf_event_code
;
5179 intf_event_callback(void *arg
)
5181 struct intf_event
*p_intf_ev
= (struct intf_event
*)arg
;
5183 /* Call this before we walk the tree */
5184 EVENTHANDLER_INVOKE(&ifnet_evhdlr_ctxt
, ifnet_event
, p_intf_ev
->ifp
,
5185 (struct sockaddr
*)&(p_intf_ev
->addr
), p_intf_ev
->intf_event_code
);
5188 struct intf_event_nwk_wq_entry
{
5189 struct nwk_wq_entry nwk_wqe
;
5190 struct intf_event intf_ev_arg
;
5194 intf_event_enqueue_nwk_wq_entry(struct ifnet
*ifp
, struct sockaddr
*addrp
,
5195 uint32_t intf_event_code
)
5197 #pragma unused(addrp)
5198 struct intf_event_nwk_wq_entry
*p_intf_ev
= NULL
;
5200 MALLOC(p_intf_ev
, struct intf_event_nwk_wq_entry
*,
5201 sizeof(struct intf_event_nwk_wq_entry
),
5202 M_NWKWQ
, M_WAITOK
| M_ZERO
);
5204 p_intf_ev
->intf_ev_arg
.ifp
= ifp
;
5206 * XXX Not using addr in the arg. This will be used
5207 * once we need IP address add/delete events
5209 p_intf_ev
->intf_ev_arg
.intf_event_code
= intf_event_code
;
5210 p_intf_ev
->nwk_wqe
.func
= intf_event_callback
;
5211 p_intf_ev
->nwk_wqe
.is_arg_managed
= TRUE
;
5212 p_intf_ev
->nwk_wqe
.arg
= &p_intf_ev
->intf_ev_arg
;
5213 nwk_wq_enqueue((struct nwk_wq_entry
*)p_intf_ev
);