2 * Copyright (c) 2000-2015 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>
89 #include <machine/endian.h>
91 #include <pexpert/pexpert.h>
94 #include <net/if_arp.h>
95 #include <net/if_dl.h>
96 #include <net/if_types.h>
97 #include <net/if_var.h>
98 #include <net/if_ppp.h>
99 #include <net/ethernet.h>
100 #include <net/network_agent.h>
102 #include <net/radix.h>
103 #include <net/route.h>
104 #include <net/dlil.h>
105 #include <sys/domain.h>
106 #include <libkern/OSAtomic.h>
110 #include <netinet/in.h>
111 #include <netinet/in_var.h>
112 #include <netinet/ip_var.h>
113 #include <netinet/ip6.h>
114 #include <netinet/ip_var.h>
115 #include <netinet/tcp.h>
116 #include <netinet/tcp_var.h>
117 #include <netinet/udp.h>
118 #include <netinet/udp_var.h>
120 #include <netinet6/in6_var.h>
121 #include <netinet6/in6_ifattach.h>
122 #include <netinet6/ip6_var.h>
123 #include <netinet6/nd6.h>
125 #endif /* INET || INET6 */
128 #include <security/mac_framework.h>
132 #include <net/altq/if_altq.h>
133 #endif /* !PF_ALTQ */
136 * System initialization
139 extern char *proc_name_address(void *);
141 /* Lock group and attribute for ifaddr lock */
142 lck_attr_t
*ifa_mtx_attr
;
143 lck_grp_t
*ifa_mtx_grp
;
144 static lck_grp_attr_t
*ifa_mtx_grp_attr
;
146 static int ifioctl_ifreq(struct socket
*, u_long
, struct ifreq
*,
148 static int ifioctl_ifconf(u_long
, caddr_t
);
149 static int ifioctl_ifclone(u_long
, caddr_t
);
150 static int ifioctl_ifdesc(struct ifnet
*, u_long
, caddr_t
, struct proc
*);
151 static int ifioctl_linkparams(struct ifnet
*, u_long
, caddr_t
, struct proc
*);
152 static int ifioctl_qstats(struct ifnet
*, u_long
, caddr_t
);
153 static int ifioctl_throttle(struct ifnet
*, u_long
, caddr_t
, struct proc
*);
154 static int ifioctl_netsignature(struct ifnet
*, u_long
, caddr_t
);
155 static int ifconf(u_long cmd
, user_addr_t ifrp
, int * ret_space
);
156 __private_extern__
void link_rtrequest(int, struct rtentry
*, struct sockaddr
*);
157 void if_rtproto_del(struct ifnet
*ifp
, int protocol
);
159 static int if_addmulti_common(struct ifnet
*, const struct sockaddr
*,
160 struct ifmultiaddr
**, int);
161 static int if_delmulti_common(struct ifmultiaddr
*, struct ifnet
*,
162 const struct sockaddr
*, int);
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 static int if_cloners_count
;
174 LIST_HEAD(, if_clone
) if_cloners
= LIST_HEAD_INITIALIZER(if_cloners
);
176 static struct ifaddr
*ifa_ifwithnet_common(const struct sockaddr
*,
178 static void if_attach_ifa_common(struct ifnet
*, struct ifaddr
*, int);
179 static void if_detach_ifa_common(struct ifnet
*, struct ifaddr
*, int);
181 static void if_attach_ifma(struct ifnet
*, struct ifmultiaddr
*, int);
182 static int if_detach_ifma(struct ifnet
*, struct ifmultiaddr
*, int);
184 static struct ifmultiaddr
*ifma_alloc(int);
185 static void ifma_free(struct ifmultiaddr
*);
186 static void ifma_trace(struct ifmultiaddr
*, int);
189 static unsigned int ifma_debug
= 1; /* debugging (enabled) */
191 static unsigned int ifma_debug
; /* debugging (disabled) */
193 static unsigned int ifma_size
; /* size of zone element */
194 static struct zone
*ifma_zone
; /* zone for ifmultiaddr */
196 #define IFMA_TRACE_HIST_SIZE 32 /* size of trace history */
199 __private_extern__
unsigned int ifma_trace_hist_size
= IFMA_TRACE_HIST_SIZE
;
201 struct ifmultiaddr_dbg
{
202 struct ifmultiaddr ifma
; /* ifmultiaddr */
203 u_int16_t ifma_refhold_cnt
; /* # of ref */
204 u_int16_t ifma_refrele_cnt
; /* # of rele */
206 * Circular lists of IFA_ADDREF and IFA_REMREF callers.
208 ctrace_t ifma_refhold
[IFMA_TRACE_HIST_SIZE
];
209 ctrace_t ifma_refrele
[IFMA_TRACE_HIST_SIZE
];
213 TAILQ_ENTRY(ifmultiaddr_dbg
) ifma_trash_link
;
216 /* List of trash ifmultiaddr entries protected by ifma_trash_lock */
217 static TAILQ_HEAD(, ifmultiaddr_dbg
) ifma_trash_head
;
218 static decl_lck_mtx_data(, ifma_trash_lock
);
220 #define IFMA_ZONE_MAX 64 /* maximum elements in zone */
221 #define IFMA_ZONE_NAME "ifmultiaddr" /* zone name */
225 * XXX: declare here to avoid to include many inet6 related files..
226 * should be more generalized?
228 extern void nd6_setmtu(struct ifnet
*);
229 extern lck_mtx_t
*nd6_mutex
;
232 SYSCTL_NODE(_net
, PF_LINK
, link
, CTLFLAG_RW
|CTLFLAG_LOCKED
, 0, "Link layers");
233 SYSCTL_NODE(_net_link
, 0, generic
, CTLFLAG_RW
|CTLFLAG_LOCKED
, 0,
234 "Generic link-management");
236 SYSCTL_DECL(_net_link_generic_system
);
238 static uint32_t if_verbose
= 0;
239 SYSCTL_INT(_net_link_generic_system
, OID_AUTO
, if_verbose
,
240 CTLFLAG_RW
| CTLFLAG_LOCKED
, &if_verbose
, 0, "");
245 /* Setup lock group and attribute for ifaddr */
246 ifa_mtx_grp_attr
= lck_grp_attr_alloc_init();
247 ifa_mtx_grp
= lck_grp_alloc_init("ifaddr", ifa_mtx_grp_attr
);
248 ifa_mtx_attr
= lck_attr_alloc_init();
250 PE_parse_boot_argn("ifa_debug", &ifma_debug
, sizeof (ifma_debug
));
252 ifma_size
= (ifma_debug
== 0) ? sizeof (struct ifmultiaddr
) :
253 sizeof (struct ifmultiaddr_dbg
);
255 ifma_zone
= zinit(ifma_size
, IFMA_ZONE_MAX
* ifma_size
, 0,
257 if (ifma_zone
== NULL
) {
258 panic("%s: failed allocating %s", __func__
, IFMA_ZONE_NAME
);
261 zone_change(ifma_zone
, Z_EXPAND
, TRUE
);
262 zone_change(ifma_zone
, Z_CALLERACCT
, FALSE
);
264 lck_mtx_init(&ifma_trash_lock
, ifa_mtx_grp
, ifa_mtx_attr
);
265 TAILQ_INIT(&ifma_trash_head
);
269 * Network interface utility routines.
271 * Routines with ifa_ifwith* names take sockaddr *'s as
276 struct ifaddr
**ifnet_addrs
;
277 struct ifnet
**ifindex2ifnet
;
279 __private_extern__
void
280 if_attach_ifa(struct ifnet
*ifp
, struct ifaddr
*ifa
)
282 if_attach_ifa_common(ifp
, ifa
, 0);
285 __private_extern__
void
286 if_attach_link_ifa(struct ifnet
*ifp
, struct ifaddr
*ifa
)
288 if_attach_ifa_common(ifp
, ifa
, 1);
292 if_attach_ifa_common(struct ifnet
*ifp
, struct ifaddr
*ifa
, int link
)
294 ifnet_lock_assert(ifp
, IFNET_LCK_ASSERT_EXCLUSIVE
);
295 IFA_LOCK_ASSERT_HELD(ifa
);
297 if (ifa
->ifa_ifp
!= ifp
) {
298 panic("%s: Mismatch ifa_ifp=%p != ifp=%p", __func__
,
301 } else if (ifa
->ifa_debug
& IFD_ATTACHED
) {
302 panic("%s: Attempt to attach an already attached ifa=%p",
305 } else if (link
&& !(ifa
->ifa_debug
& IFD_LINK
)) {
306 panic("%s: Unexpected non-link address ifa=%p", __func__
, ifa
);
308 } else if (!link
&& (ifa
->ifa_debug
& IFD_LINK
)) {
309 panic("%s: Unexpected link address ifa=%p", __func__
, ifa
);
312 IFA_ADDREF_LOCKED(ifa
);
313 ifa
->ifa_debug
|= IFD_ATTACHED
;
315 TAILQ_INSERT_HEAD(&ifp
->if_addrhead
, ifa
, ifa_link
);
317 TAILQ_INSERT_TAIL(&ifp
->if_addrhead
, ifa
, ifa_link
);
319 if (ifa
->ifa_attached
!= NULL
)
320 (*ifa
->ifa_attached
)(ifa
);
323 __private_extern__
void
324 if_detach_ifa(struct ifnet
*ifp
, struct ifaddr
*ifa
)
326 if_detach_ifa_common(ifp
, ifa
, 0);
329 __private_extern__
void
330 if_detach_link_ifa(struct ifnet
*ifp
, struct ifaddr
*ifa
)
332 if_detach_ifa_common(ifp
, ifa
, 1);
336 if_detach_ifa_common(struct ifnet
*ifp
, struct ifaddr
*ifa
, int link
)
338 ifnet_lock_assert(ifp
, IFNET_LCK_ASSERT_EXCLUSIVE
);
339 IFA_LOCK_ASSERT_HELD(ifa
);
341 if (link
&& !(ifa
->ifa_debug
& IFD_LINK
)) {
342 panic("%s: Unexpected non-link address ifa=%p", __func__
, ifa
);
344 } else if (link
&& ifa
!= TAILQ_FIRST(&ifp
->if_addrhead
)) {
345 panic("%s: Link address ifa=%p not first", __func__
, ifa
);
347 } else if (!link
&& (ifa
->ifa_debug
& IFD_LINK
)) {
348 panic("%s: Unexpected link address ifa=%p", __func__
, ifa
);
350 } else if (!(ifa
->ifa_debug
& IFD_ATTACHED
)) {
351 panic("%s: Attempt to detach an unattached address ifa=%p",
354 } else if (ifa
->ifa_ifp
!= ifp
) {
355 panic("%s: Mismatch ifa_ifp=%p, ifp=%p", __func__
,
358 } else if (ifa
->ifa_debug
& IFD_DEBUG
) {
360 TAILQ_FOREACH(ifa2
, &ifp
->if_addrhead
, ifa_link
) {
365 panic("%s: Attempt to detach a stray address ifa=%p",
370 TAILQ_REMOVE(&ifp
->if_addrhead
, ifa
, ifa_link
);
371 /* This must not be the last reference to the ifaddr */
372 if (IFA_REMREF_LOCKED(ifa
) == NULL
) {
373 panic("%s: unexpected (missing) refcnt ifa=%p", __func__
, ifa
);
376 ifa
->ifa_debug
&= ~IFD_ATTACHED
;
378 if (ifa
->ifa_detached
!= NULL
)
379 (*ifa
->ifa_detached
)(ifa
);
382 #define INITIAL_IF_INDEXLIM 8
385 * Function: if_next_index
387 * Return the next available interface index.
388 * Grow the ifnet_addrs[] and ifindex2ifnet[] arrays to accomodate the
389 * added entry when necessary.
392 * ifnet_addrs[] is indexed by (if_index - 1), whereas
393 * ifindex2ifnet[] is indexed by ifp->if_index. That requires us to
394 * always allocate one extra element to hold ifindex2ifnet[0], which
397 int if_next_index(void);
399 __private_extern__
int
402 static int if_indexlim
= 0;
405 new_index
= ++if_index
;
406 if (if_index
> if_indexlim
) {
409 caddr_t new_ifnet_addrs
;
410 caddr_t new_ifindex2ifnet
;
411 caddr_t old_ifnet_addrs
;
413 old_ifnet_addrs
= (caddr_t
)ifnet_addrs
;
414 if (ifnet_addrs
== NULL
) {
415 new_if_indexlim
= INITIAL_IF_INDEXLIM
;
417 new_if_indexlim
= if_indexlim
<< 1;
420 /* allocate space for the larger arrays */
421 n
= (2 * new_if_indexlim
+ 1) * sizeof(caddr_t
);
422 new_ifnet_addrs
= _MALLOC(n
, M_IFADDR
, M_WAITOK
| M_ZERO
);
423 if (new_ifnet_addrs
== NULL
) {
428 new_ifindex2ifnet
= new_ifnet_addrs
429 + new_if_indexlim
* sizeof(caddr_t
);
430 if (ifnet_addrs
!= NULL
) {
431 /* copy the existing data */
432 bcopy((caddr_t
)ifnet_addrs
, new_ifnet_addrs
,
433 if_indexlim
* sizeof(caddr_t
));
434 bcopy((caddr_t
)ifindex2ifnet
,
436 (if_indexlim
+ 1) * sizeof(caddr_t
));
439 /* switch to the new tables and size */
440 ifnet_addrs
= (struct ifaddr
**)(void *)new_ifnet_addrs
;
441 ifindex2ifnet
= (struct ifnet
**)(void *)new_ifindex2ifnet
;
442 if_indexlim
= new_if_indexlim
;
444 /* release the old data */
445 if (old_ifnet_addrs
!= NULL
) {
446 _FREE((caddr_t
)old_ifnet_addrs
, M_IFADDR
);
453 * Create a clone network interface.
456 if_clone_create(char *name
, int len
, void *params
)
458 struct if_clone
*ifc
;
461 u_int32_t bytoff
, bitoff
;
465 ifc
= if_clone_lookup(name
, &unit
);
469 if (ifunit(name
) != NULL
)
473 wildcard
= (unit
== UINT32_MAX
);
475 * Find a free unit if none was given.
478 while ((bytoff
< ifc
->ifc_bmlen
)
479 && (ifc
->ifc_units
[bytoff
] == 0xff))
481 if (bytoff
>= ifc
->ifc_bmlen
)
483 while ((ifc
->ifc_units
[bytoff
] & (1 << bitoff
)) != 0)
485 unit
= (bytoff
<< 3) + bitoff
;
488 if (unit
> ifc
->ifc_maxunit
)
491 err
= (*ifc
->ifc_create
)(ifc
, unit
, params
);
497 bitoff
= unit
- (bytoff
<< 3);
501 * Allocate the unit in the bitmap.
503 KASSERT((ifc
->ifc_units
[bytoff
] & (1 << bitoff
)) == 0,
504 ("%s: bit is already set", __func__
));
505 ifc
->ifc_units
[bytoff
] |= (1 << bitoff
);
507 /* In the wildcard case, we need to update the name. */
509 for (dp
= name
; *dp
!= '\0'; dp
++);
510 if (snprintf(dp
, len
- (dp
-name
), "%d", unit
) >
511 len
- (dp
-name
) - 1) {
513 * This can only be a programmer error and
514 * there's no straightforward way to recover if
517 panic("%s: interface name too long", __func__
);
527 * Destroy a clone network interface.
530 if_clone_destroy(const char *name
)
532 struct if_clone
*ifc
;
537 ifc
= if_clone_lookup(name
, &unit
);
541 if (unit
< ifc
->ifc_minifs
)
548 if (ifc
->ifc_destroy
== NULL
)
551 (*ifc
->ifc_destroy
)(ifp
);
554 * Compute offset in the bitmap and deallocate the unit.
557 bitoff
= unit
- (bytoff
<< 3);
558 KASSERT((ifc
->ifc_units
[bytoff
] & (1 << bitoff
)) != 0,
559 ("%s: bit is already cleared", __func__
));
560 ifc
->ifc_units
[bytoff
] &= ~(1 << bitoff
);
565 * Look up a network interface cloner.
568 __private_extern__
struct if_clone
*
569 if_clone_lookup(const char *name
, u_int32_t
*unitp
)
571 struct if_clone
*ifc
;
575 for (ifc
= LIST_FIRST(&if_cloners
); ifc
!= NULL
;) {
576 for (cp
= name
, i
= 0; i
< ifc
->ifc_namelen
; i
++, cp
++) {
577 if (ifc
->ifc_name
[i
] != *cp
)
582 ifc
= LIST_NEXT(ifc
, ifc_list
);
586 return ((struct if_clone
*)NULL
);
592 for (i
= 0; *cp
!= '\0'; cp
++) {
593 if (*cp
< '0' || *cp
> '9') {
594 /* Bogus unit number. */
597 i
= (i
* 10) + (*cp
- '0');
607 * Register a network interface cloner.
610 if_clone_attach(struct if_clone
*ifc
)
617 KASSERT(ifc
->ifc_minifs
- 1 <= ifc
->ifc_maxunit
,
618 ("%s: %s requested more units then allowed (%d > %d)",
619 __func__
, ifc
->ifc_name
, ifc
->ifc_minifs
,
620 ifc
->ifc_maxunit
+ 1));
622 * Compute bitmap size and allocate it.
624 maxclone
= ifc
->ifc_maxunit
+ 1;
626 if ((len
<< 3) < maxclone
)
628 ifc
->ifc_units
= _MALLOC(len
, M_CLONE
, M_WAITOK
| M_ZERO
);
629 if (ifc
->ifc_units
== NULL
)
631 ifc
->ifc_bmlen
= len
;
633 LIST_INSERT_HEAD(&if_cloners
, ifc
, ifc_list
);
636 for (unit
= 0; unit
< ifc
->ifc_minifs
; unit
++) {
637 err
= (*ifc
->ifc_create
)(ifc
, unit
, NULL
);
639 ("%s: failed to create required interface %s%d",
640 __func__
, ifc
->ifc_name
, unit
));
642 /* Allocate the unit in the bitmap. */
644 bitoff
= unit
- (bytoff
<< 3);
645 ifc
->ifc_units
[bytoff
] |= (1 << bitoff
);
652 * Unregister a network interface cloner.
655 if_clone_detach(struct if_clone
*ifc
)
657 LIST_REMOVE(ifc
, ifc_list
);
658 FREE(ifc
->ifc_units
, M_CLONE
);
663 * Provide list of interface cloners to userspace.
666 if_clone_list(int count
, int *ret_total
, user_addr_t dst
)
668 char outbuf
[IFNAMSIZ
];
669 struct if_clone
*ifc
;
672 *ret_total
= if_cloners_count
;
673 if (dst
== USER_ADDR_NULL
) {
674 /* Just asking how many there are. */
681 count
= (if_cloners_count
< count
) ? if_cloners_count
: count
;
683 for (ifc
= LIST_FIRST(&if_cloners
); ifc
!= NULL
&& count
!= 0;
684 ifc
= LIST_NEXT(ifc
, ifc_list
), count
--, dst
+= IFNAMSIZ
) {
685 bzero(outbuf
, sizeof(outbuf
));
686 strlcpy(outbuf
, ifc
->ifc_name
,
687 min(strlen(ifc
->ifc_name
), IFNAMSIZ
));
688 error
= copyout(outbuf
, dst
, IFNAMSIZ
);
697 if_functional_type(struct ifnet
*ifp
)
699 u_int32_t ret
= IFRTYPE_FUNCTIONAL_UNKNOWN
;
701 if (ifp
->if_flags
& IFF_LOOPBACK
) {
702 ret
= IFRTYPE_FUNCTIONAL_LOOPBACK
;
703 } else if (IFNET_IS_WIFI(ifp
)) {
704 if (ifp
->if_eflags
& IFEF_AWDL
)
705 ret
= IFRTYPE_FUNCTIONAL_WIFI_AWDL
;
707 ret
= IFRTYPE_FUNCTIONAL_WIFI_INFRA
;
708 } else if (IFNET_IS_CELLULAR(ifp
)) {
709 ret
= IFRTYPE_FUNCTIONAL_CELLULAR
;
710 } else if (IFNET_IS_WIRED(ifp
)) {
711 ret
= IFRTYPE_FUNCTIONAL_WIRED
;
719 * Similar to ifa_ifwithaddr, except that this is IPv4 specific
720 * and that it matches only the local (not broadcast) address.
722 __private_extern__
struct in_ifaddr
*
723 ifa_foraddr(unsigned int addr
)
725 return (ifa_foraddr_scoped(addr
, IFSCOPE_NONE
));
729 * Similar to ifa_foraddr, except with the added interface scope
730 * constraint (unless the caller passes in IFSCOPE_NONE in which
731 * case there is no scope restriction).
733 __private_extern__
struct in_ifaddr
*
734 ifa_foraddr_scoped(unsigned int addr
, unsigned int scope
)
736 struct in_ifaddr
*ia
= NULL
;
738 lck_rw_lock_shared(in_ifaddr_rwlock
);
739 TAILQ_FOREACH(ia
, INADDR_HASH(addr
), ia_hash
) {
740 IFA_LOCK_SPIN(&ia
->ia_ifa
);
741 if (ia
->ia_addr
.sin_addr
.s_addr
== addr
&&
742 (scope
== IFSCOPE_NONE
|| ia
->ia_ifp
->if_index
== scope
)) {
743 IFA_ADDREF_LOCKED(&ia
->ia_ifa
); /* for caller */
744 IFA_UNLOCK(&ia
->ia_ifa
);
747 IFA_UNLOCK(&ia
->ia_ifa
);
749 lck_rw_done(in_ifaddr_rwlock
);
755 * Similar to ifa_foraddr, except that this for IPv6.
757 __private_extern__
struct in6_ifaddr
*
758 ifa_foraddr6(struct in6_addr
*addr6
)
760 return (ifa_foraddr6_scoped(addr6
, IFSCOPE_NONE
));
763 __private_extern__
struct in6_ifaddr
*
764 ifa_foraddr6_scoped(struct in6_addr
*addr6
, unsigned int scope
)
766 struct in6_ifaddr
*ia
= NULL
;
768 lck_rw_lock_shared(&in6_ifaddr_rwlock
);
769 for (ia
= in6_ifaddrs
; ia
; ia
= ia
->ia_next
) {
770 IFA_LOCK(&ia
->ia_ifa
);
771 if (IN6_ARE_ADDR_EQUAL(&ia
->ia_addr
.sin6_addr
, addr6
) &&
772 (scope
== IFSCOPE_NONE
|| ia
->ia_ifp
->if_index
== scope
)) {
773 IFA_ADDREF_LOCKED(&ia
->ia_ifa
); /* for caller */
774 IFA_UNLOCK(&ia
->ia_ifa
);
777 IFA_UNLOCK(&ia
->ia_ifa
);
779 lck_rw_done(&in6_ifaddr_rwlock
);
786 * Return the first (primary) address of a given family on an interface.
788 __private_extern__
struct ifaddr
*
789 ifa_ifpgetprimary(struct ifnet
*ifp
, int family
)
793 ifnet_lock_shared(ifp
);
794 TAILQ_FOREACH(ifa
, &ifp
->if_addrhead
, ifa_link
) {
796 if (ifa
->ifa_addr
->sa_family
== family
) {
797 IFA_ADDREF_LOCKED(ifa
); /* for caller */
803 ifnet_lock_done(ifp
);
809 * Locate an interface based on a complete address.
813 ifa_ifwithaddr(const struct sockaddr
*addr
)
817 struct ifaddr
*result
= NULL
;
819 #define equal(a1, a2) \
820 (bcmp((const void*)(a1), (const void*)(a2), \
821 ((const struct sockaddr *)(a1))->sa_len) == 0)
823 ifnet_head_lock_shared();
824 for (ifp
= ifnet_head
.tqh_first
; ifp
&& !result
;
825 ifp
= ifp
->if_link
.tqe_next
) {
826 ifnet_lock_shared(ifp
);
827 for (ifa
= ifp
->if_addrhead
.tqh_first
; ifa
;
828 ifa
= ifa
->ifa_link
.tqe_next
) {
830 if (ifa
->ifa_addr
->sa_family
!= addr
->sa_family
) {
834 if (equal(addr
, ifa
->ifa_addr
)) {
836 IFA_ADDREF_LOCKED(ifa
); /* for caller */
840 if ((ifp
->if_flags
& IFF_BROADCAST
) &&
841 ifa
->ifa_broadaddr
!= NULL
&&
842 /* IP6 doesn't have broadcast */
843 ifa
->ifa_broadaddr
->sa_len
!= 0 &&
844 equal(ifa
->ifa_broadaddr
, addr
)) {
846 IFA_ADDREF_LOCKED(ifa
); /* for caller */
852 ifnet_lock_done(ifp
);
859 * Locate the point to point interface with a given destination address.
863 ifa_ifwithdstaddr(const struct sockaddr
*addr
)
867 struct ifaddr
*result
= NULL
;
869 ifnet_head_lock_shared();
870 for (ifp
= ifnet_head
.tqh_first
; ifp
&& !result
;
871 ifp
= ifp
->if_link
.tqe_next
) {
872 if ((ifp
->if_flags
& IFF_POINTOPOINT
)) {
873 ifnet_lock_shared(ifp
);
874 for (ifa
= ifp
->if_addrhead
.tqh_first
; ifa
;
875 ifa
= ifa
->ifa_link
.tqe_next
) {
877 if (ifa
->ifa_addr
->sa_family
!=
882 if (ifa
->ifa_dstaddr
&&
883 equal(addr
, ifa
->ifa_dstaddr
)) {
885 IFA_ADDREF_LOCKED(ifa
); /* for caller */
891 ifnet_lock_done(ifp
);
899 * Locate the source address of an interface based on a complete address.
902 ifa_ifwithaddr_scoped(const struct sockaddr
*addr
, unsigned int ifscope
)
904 struct ifaddr
*result
= NULL
;
907 if (ifscope
== IFSCOPE_NONE
)
908 return (ifa_ifwithaddr(addr
));
910 ifnet_head_lock_shared();
911 if (ifscope
> (unsigned int)if_index
) {
916 ifp
= ifindex2ifnet
[ifscope
];
918 struct ifaddr
*ifa
= NULL
;
921 * This is suboptimal; there should be a better way
922 * to search for a given address of an interface
923 * for any given address family.
925 ifnet_lock_shared(ifp
);
926 for (ifa
= ifp
->if_addrhead
.tqh_first
; ifa
!= NULL
;
927 ifa
= ifa
->ifa_link
.tqe_next
) {
929 if (ifa
->ifa_addr
->sa_family
!= addr
->sa_family
) {
933 if (equal(addr
, ifa
->ifa_addr
)) {
935 IFA_ADDREF_LOCKED(ifa
); /* for caller */
939 if ((ifp
->if_flags
& IFF_BROADCAST
) &&
940 ifa
->ifa_broadaddr
!= NULL
&&
941 /* IP6 doesn't have broadcast */
942 ifa
->ifa_broadaddr
->sa_len
!= 0 &&
943 equal(ifa
->ifa_broadaddr
, addr
)) {
945 IFA_ADDREF_LOCKED(ifa
); /* for caller */
951 ifnet_lock_done(ifp
);
959 ifa_ifwithnet(const struct sockaddr
*addr
)
961 return (ifa_ifwithnet_common(addr
, IFSCOPE_NONE
));
965 ifa_ifwithnet_scoped(const struct sockaddr
*addr
, unsigned int ifscope
)
967 return (ifa_ifwithnet_common(addr
, ifscope
));
971 * Find an interface on a specific network. If many, choice
972 * is most specific found.
974 static struct ifaddr
*
975 ifa_ifwithnet_common(const struct sockaddr
*addr
, unsigned int ifscope
)
978 struct ifaddr
*ifa
= NULL
;
979 struct ifaddr
*ifa_maybe
= NULL
;
980 u_int af
= addr
->sa_family
;
981 const char *addr_data
= addr
->sa_data
, *cplim
;
984 if ((af
!= AF_INET
&& af
!= AF_INET6
) ||
985 (af
== AF_INET
&& !ip_doscopedroute
) ||
986 (af
== AF_INET6
&& !ip6_doscopedroute
))
988 if (af
!= AF_INET
|| !ip_doscopedroute
)
990 ifscope
= IFSCOPE_NONE
;
992 ifnet_head_lock_shared();
994 * AF_LINK addresses can be looked up directly by their index number,
995 * so do that if we can.
998 const struct sockaddr_dl
*sdl
=
999 (const struct sockaddr_dl
*)(uintptr_t)(size_t)addr
;
1000 if (sdl
->sdl_index
&& sdl
->sdl_index
<= if_index
) {
1001 ifa
= ifnet_addrs
[sdl
->sdl_index
- 1];
1011 * Scan though each interface, looking for ones that have
1012 * addresses in this address family.
1014 for (ifp
= ifnet_head
.tqh_first
; ifp
; ifp
= ifp
->if_link
.tqe_next
) {
1015 ifnet_lock_shared(ifp
);
1016 for (ifa
= ifp
->if_addrhead
.tqh_first
; ifa
;
1017 ifa
= ifa
->ifa_link
.tqe_next
) {
1018 const char *cp
, *cp2
, *cp3
;
1021 if (ifa
->ifa_addr
== NULL
||
1022 ifa
->ifa_addr
->sa_family
!= af
) {
1028 * If we're looking up with a scope,
1029 * find using a matching interface.
1031 if (ifscope
!= IFSCOPE_NONE
&&
1032 ifp
->if_index
!= ifscope
) {
1038 * Scan all the bits in the ifa's address.
1039 * If a bit dissagrees with what we are
1040 * looking for, mask it with the netmask
1041 * to see if it really matters.
1042 * (A byte at a time)
1044 if (ifa
->ifa_netmask
== 0) {
1049 cp2
= ifa
->ifa_addr
->sa_data
;
1050 cp3
= ifa
->ifa_netmask
->sa_data
;
1051 cplim
= ifa
->ifa_netmask
->sa_len
+
1052 (char *)ifa
->ifa_netmask
;
1054 if ((*cp
++ ^ *cp2
++) & *cp3
++)
1055 goto next
; /* next address! */
1057 * If the netmask of what we just found
1058 * is more specific than what we had before
1059 * (if we had one) then remember the new one
1060 * before continuing to search
1061 * for an even better one.
1063 if (ifa_maybe
== NULL
||
1064 rn_refines((caddr_t
)ifa
->ifa_netmask
,
1065 (caddr_t
)ifa_maybe
->ifa_netmask
)) {
1066 IFA_ADDREF_LOCKED(ifa
); /* ifa_maybe */
1068 if (ifa_maybe
!= NULL
)
1069 IFA_REMREF(ifa_maybe
);
1074 IFA_LOCK_ASSERT_NOTHELD(ifa
);
1076 ifnet_lock_done(ifp
);
1085 else if (ifa_maybe
!= NULL
)
1086 IFA_REMREF(ifa_maybe
);
1092 * Find an interface address specific to an interface best matching
1096 ifaof_ifpforaddr(const struct sockaddr
*addr
, struct ifnet
*ifp
)
1098 struct ifaddr
*ifa
= NULL
;
1099 const char *cp
, *cp2
, *cp3
;
1101 struct ifaddr
*ifa_maybe
= NULL
;
1102 struct ifaddr
*better_ifa_maybe
= NULL
;
1103 u_int af
= addr
->sa_family
;
1108 ifnet_lock_shared(ifp
);
1109 for (ifa
= ifp
->if_addrhead
.tqh_first
; ifa
;
1110 ifa
= ifa
->ifa_link
.tqe_next
) {
1112 if (ifa
->ifa_addr
->sa_family
!= af
) {
1116 if (ifa_maybe
== NULL
) {
1117 IFA_ADDREF_LOCKED(ifa
); /* for ifa_maybe */
1120 if (ifa
->ifa_netmask
== 0) {
1121 if (equal(addr
, ifa
->ifa_addr
) || (ifa
->ifa_dstaddr
&&
1122 equal(addr
, ifa
->ifa_dstaddr
))) {
1123 IFA_ADDREF_LOCKED(ifa
); /* for caller */
1130 if (ifp
->if_flags
& IFF_POINTOPOINT
) {
1131 if (ifa
->ifa_dstaddr
&& equal(addr
, ifa
->ifa_dstaddr
)) {
1132 IFA_ADDREF_LOCKED(ifa
); /* for caller */
1137 if (equal(addr
, ifa
->ifa_addr
)) {
1139 IFA_ADDREF_LOCKED(ifa
); /* for caller */
1144 cp2
= ifa
->ifa_addr
->sa_data
;
1145 cp3
= ifa
->ifa_netmask
->sa_data
;
1146 cplim
= ifa
->ifa_netmask
->sa_len
+
1147 (char *)ifa
->ifa_netmask
;
1148 for (; cp3
< cplim
; cp3
++)
1149 if ((*cp
++ ^ *cp2
++) & *cp3
)
1153 if (better_ifa_maybe
== NULL
) {
1154 /* for better_ifa_maybe */
1155 IFA_ADDREF_LOCKED(ifa
);
1156 better_ifa_maybe
= ifa
;
1164 if (better_ifa_maybe
!= NULL
) {
1165 ifa
= better_ifa_maybe
;
1166 better_ifa_maybe
= NULL
;
1173 ifnet_lock_done(ifp
);
1175 if (better_ifa_maybe
!= NULL
)
1176 IFA_REMREF(better_ifa_maybe
);
1177 if (ifa_maybe
!= NULL
)
1178 IFA_REMREF(ifa_maybe
);
1183 #include <net/route.h>
1186 * Default action when installing a route with a Link Level gateway.
1187 * Lookup an appropriate real ifa to point to.
1188 * This should be moved to /sys/net/link.c eventually.
1191 link_rtrequest(int cmd
, struct rtentry
*rt
, struct sockaddr
*sa
)
1194 struct sockaddr
*dst
;
1196 void (*ifa_rtrequest
)(int, struct rtentry
*, struct sockaddr
*);
1198 lck_mtx_assert(rnh_lock
, LCK_MTX_ASSERT_OWNED
);
1199 RT_LOCK_ASSERT_HELD(rt
);
1201 if (cmd
!= RTM_ADD
|| ((ifa
= rt
->rt_ifa
) == 0) ||
1202 ((ifp
= ifa
->ifa_ifp
) == 0) || ((dst
= rt_key(rt
)) == 0))
1205 /* Become a regular mutex, just in case */
1206 RT_CONVERT_LOCK(rt
);
1208 ifa
= ifaof_ifpforaddr(dst
, ifp
);
1212 ifa_rtrequest
= ifa
->ifa_rtrequest
;
1214 if (ifa_rtrequest
!= NULL
&& ifa_rtrequest
!= link_rtrequest
)
1215 ifa_rtrequest(cmd
, rt
, sa
);
1221 * if_updown will set the interface up or down. It will
1222 * prevent other up/down events from occurring until this
1223 * up/down event has completed.
1225 * Caller must lock ifnet. This function will drop the
1226 * lock. This allows ifnet_set_flags to set the rest of
1227 * the flags after we change the up/down state without
1228 * dropping the interface lock between setting the
1229 * up/down state and updating the rest of the flags.
1231 __private_extern__
void
1237 struct ifaddr
**ifa
;
1239 struct ifclassq
*ifq
= &ifp
->if_snd
;
1241 /* Wait until no one else is changing the up/down state */
1242 while ((ifp
->if_eflags
& IFEF_UPDOWNCHANGE
) != 0) {
1244 tv
.tv_nsec
= NSEC_PER_SEC
/ 10;
1245 ifnet_lock_done(ifp
);
1246 msleep(&ifp
->if_eflags
, NULL
, 0, "if_updown", &tv
);
1247 ifnet_lock_exclusive(ifp
);
1250 /* Verify that the interface isn't already in the right state */
1251 if ((!up
&& (ifp
->if_flags
& IFF_UP
) == 0) ||
1252 (up
&& (ifp
->if_flags
& IFF_UP
) == IFF_UP
)) {
1256 /* Indicate that the up/down state is changing */
1257 ifp
->if_eflags
|= IFEF_UPDOWNCHANGE
;
1259 /* Mark interface up or down */
1261 ifp
->if_flags
|= IFF_UP
;
1264 ifp
->if_flags
&= ~IFF_UP
;
1267 ifnet_touch_lastchange(ifp
);
1269 /* Drop the lock to notify addresses and route */
1270 ifnet_lock_done(ifp
);
1271 if (ifnet_get_address_list(ifp
, &ifa
) == 0) {
1272 for (i
= 0; ifa
[i
] != 0; i
++) {
1273 pfctlinput(up
? PRC_IFUP
: PRC_IFDOWN
, ifa
[i
]->ifa_addr
);
1275 ifnet_free_address_list(ifa
);
1282 /* Inform all transmit queues about the new link state */
1284 ifnet_update_sndq(ifq
, up
? CLASSQ_EV_LINK_UP
: CLASSQ_EV_LINK_DOWN
);
1287 /* Aquire the lock to clear the changing flag */
1288 ifnet_lock_exclusive(ifp
);
1289 ifp
->if_eflags
&= ~IFEF_UPDOWNCHANGE
;
1290 wakeup(&ifp
->if_eflags
);
1294 * Mark an interface down and notify protocols of
1301 ifnet_lock_exclusive(ifp
);
1303 ifnet_lock_done(ifp
);
1307 * Mark an interface up and notify protocols of
1314 ifnet_lock_exclusive(ifp
);
1316 ifnet_lock_done(ifp
);
1320 * Flush an interface queue.
1323 if_qflush(struct ifnet
*ifp
, int ifq_locked
)
1325 struct ifclassq
*ifq
= &ifp
->if_snd
;
1330 if (IFCQ_IS_ENABLED(ifq
))
1333 if (IFCQ_IS_DRAINING(ifq
))
1334 ifq
->ifcq_drain
= 0;
1335 if (ALTQ_IS_ENABLED(IFCQ_ALTQ(ifq
)))
1336 ALTQ_PURGE(IFCQ_ALTQ(ifq
));
1337 #endif /* PF_ALTQ */
1339 VERIFY(IFCQ_IS_EMPTY(ifq
));
1346 if_qflush_sc(struct ifnet
*ifp
, mbuf_svc_class_t sc
, u_int32_t flow
,
1347 u_int32_t
*packets
, u_int32_t
*bytes
, int ifq_locked
)
1349 struct ifclassq
*ifq
= &ifp
->if_snd
;
1350 u_int32_t cnt
= 0, len
= 0;
1351 u_int32_t a_cnt
= 0, a_len
= 0;
1353 VERIFY(sc
== MBUF_SC_UNSPEC
|| MBUF_VALID_SC(sc
));
1359 if (IFCQ_IS_ENABLED(ifq
))
1360 IFCQ_PURGE_SC(ifq
, sc
, flow
, cnt
, len
);
1362 if (IFCQ_IS_DRAINING(ifq
)) {
1363 VERIFY((signed)(ifq
->ifcq_drain
- cnt
) >= 0);
1364 ifq
->ifcq_drain
-= cnt
;
1366 if (ALTQ_IS_ENABLED(IFCQ_ALTQ(ifq
)))
1367 ALTQ_PURGE_SC(IFCQ_ALTQ(ifq
), sc
, flow
, a_cnt
, a_len
);
1368 #endif /* PF_ALTQ */
1373 if (packets
!= NULL
)
1374 *packets
= cnt
+ a_cnt
;
1376 *bytes
= len
+ a_len
;
1380 * Map interface name to
1381 * interface structure pointer.
1384 ifunit(const char *name
)
1386 char namebuf
[IFNAMSIZ
+ 1];
1394 if (len
< 2 || len
> IFNAMSIZ
)
1396 cp
= name
+ len
- 1;
1398 if (c
< '0' || c
> '9')
1399 return (NULL
); /* trailing garbage */
1404 return (NULL
); /* no interface name */
1405 unit
+= (c
- '0') * m
;
1407 return (NULL
); /* number is unreasonable */
1410 } while (c
>= '0' && c
<= '9');
1411 len
= cp
- name
+ 1;
1412 bcopy(name
, namebuf
, len
);
1413 namebuf
[len
] = '\0';
1415 * Now search all the interfaces for this name/number
1417 ifnet_head_lock_shared();
1418 TAILQ_FOREACH(ifp
, &ifnet_head
, if_link
) {
1419 if (strncmp(ifp
->if_name
, namebuf
, len
))
1421 if (unit
== ifp
->if_unit
)
1430 * Map interface name in a sockaddr_dl to
1431 * interface structure pointer.
1434 if_withname(struct sockaddr
*sa
)
1436 char ifname
[IFNAMSIZ
+1];
1437 struct sockaddr_dl
*sdl
= (struct sockaddr_dl
*)(void *)sa
;
1439 if ( (sa
->sa_family
!= AF_LINK
) || (sdl
->sdl_nlen
== 0) ||
1440 (sdl
->sdl_nlen
> IFNAMSIZ
) )
1444 * ifunit wants a null-terminated name. It may not be null-terminated
1445 * in the sockaddr. We don't want to change the caller's sockaddr,
1446 * and there might not be room to put the trailing null anyway, so we
1447 * make a local copy that we know we can null terminate safely.
1450 bcopy(sdl
->sdl_data
, ifname
, sdl
->sdl_nlen
);
1451 ifname
[sdl
->sdl_nlen
] = '\0';
1452 return (ifunit(ifname
));
1455 static __attribute__((noinline
)) int
1456 ifioctl_ifconf(u_long cmd
, caddr_t data
)
1461 case OSIOCGIFCONF32
: /* struct ifconf32 */
1462 case SIOCGIFCONF32
: { /* struct ifconf32 */
1463 struct ifconf32 ifc
;
1464 bcopy(data
, &ifc
, sizeof (ifc
));
1465 error
= ifconf(cmd
, CAST_USER_ADDR_T(ifc
.ifc_req
),
1467 bcopy(&ifc
, data
, sizeof (ifc
));
1471 case SIOCGIFCONF64
: /* struct ifconf64 */
1472 case OSIOCGIFCONF64
: { /* struct ifconf64 */
1473 struct ifconf64 ifc
;
1474 bcopy(data
, &ifc
, sizeof (ifc
));
1475 error
= ifconf(cmd
, ifc
.ifc_req
, &ifc
.ifc_len
);
1476 bcopy(&ifc
, data
, sizeof (ifc
));
1488 static __attribute__((noinline
)) int
1489 ifioctl_ifclone(u_long cmd
, caddr_t data
)
1494 case SIOCIFGCLONERS32
: { /* struct if_clonereq32 */
1495 struct if_clonereq32 ifcr
;
1496 bcopy(data
, &ifcr
, sizeof (ifcr
));
1497 error
= if_clone_list(ifcr
.ifcr_count
, &ifcr
.ifcr_total
,
1498 CAST_USER_ADDR_T(ifcr
.ifcru_buffer
));
1499 bcopy(&ifcr
, data
, sizeof (ifcr
));
1503 case SIOCIFGCLONERS64
: { /* struct if_clonereq64 */
1504 struct if_clonereq64 ifcr
;
1505 bcopy(data
, &ifcr
, sizeof (ifcr
));
1506 error
= if_clone_list(ifcr
.ifcr_count
, &ifcr
.ifcr_total
,
1508 bcopy(&ifcr
, data
, sizeof (ifcr
));
1520 static __attribute__((noinline
)) int
1521 ifioctl_ifdesc(struct ifnet
*ifp
, u_long cmd
, caddr_t data
, struct proc
*p
)
1523 struct if_descreq
*ifdr
= (struct if_descreq
*)(void *)data
;
1527 VERIFY(ifp
!= NULL
);
1530 case SIOCSIFDESC
: { /* struct if_descreq */
1531 if ((error
= proc_suser(p
)) != 0)
1534 ifnet_lock_exclusive(ifp
);
1535 bcopy(&ifdr
->ifdr_len
, &ifdr_len
, sizeof (ifdr_len
));
1536 if (ifdr_len
> sizeof (ifdr
->ifdr_desc
) ||
1537 ifdr_len
> ifp
->if_desc
.ifd_maxlen
) {
1539 ifnet_lock_done(ifp
);
1543 bzero(ifp
->if_desc
.ifd_desc
, ifp
->if_desc
.ifd_maxlen
);
1544 if ((ifp
->if_desc
.ifd_len
= ifdr_len
) > 0) {
1545 bcopy(ifdr
->ifdr_desc
, ifp
->if_desc
.ifd_desc
,
1546 MIN(ifdr_len
, ifp
->if_desc
.ifd_maxlen
));
1548 ifnet_lock_done(ifp
);
1552 case SIOCGIFDESC
: { /* struct if_descreq */
1553 ifnet_lock_shared(ifp
);
1554 ifdr_len
= MIN(ifp
->if_desc
.ifd_len
, sizeof (ifdr
->ifdr_desc
));
1555 bcopy(&ifdr_len
, &ifdr
->ifdr_len
, sizeof (ifdr_len
));
1556 bzero(&ifdr
->ifdr_desc
, sizeof (ifdr
->ifdr_desc
));
1558 bcopy(ifp
->if_desc
.ifd_desc
, ifdr
->ifdr_desc
, ifdr_len
);
1560 ifnet_lock_done(ifp
);
1572 static __attribute__((noinline
)) int
1573 ifioctl_linkparams(struct ifnet
*ifp
, u_long cmd
, caddr_t data
, struct proc
*p
)
1575 struct if_linkparamsreq
*iflpr
=
1576 (struct if_linkparamsreq
*)(void *)data
;
1577 struct ifclassq
*ifq
;
1580 VERIFY(ifp
!= NULL
);
1584 case SIOCSIFLINKPARAMS
: { /* struct if_linkparamsreq */
1585 struct tb_profile tb
= { 0, 0, 0 };
1587 if ((error
= proc_suser(p
)) != 0)
1591 if (!IFCQ_IS_READY(ifq
)) {
1596 bcopy(&iflpr
->iflpr_output_tbr_rate
, &tb
.rate
,
1598 bcopy(&iflpr
->iflpr_output_tbr_percent
, &tb
.percent
,
1599 sizeof (tb
.percent
));
1600 error
= ifclassq_tbr_set(ifq
, &tb
, TRUE
);
1605 case SIOCGIFLINKPARAMS
: { /* struct if_linkparamsreq */
1606 u_int32_t sched_type
= PKTSCHEDT_NONE
, flags
= 0;
1607 u_int64_t tbr_bw
= 0, tbr_pct
= 0;
1611 if (ALTQ_IS_ENABLED(IFCQ_ALTQ(ifq
))) {
1612 sched_type
= IFCQ_ALTQ(ifq
)->altq_type
;
1613 flags
|= IFLPRF_ALTQ
;
1615 #endif /* PF_ALTQ */
1617 if (IFCQ_IS_ENABLED(ifq
))
1618 sched_type
= ifq
->ifcq_type
;
1620 bcopy(&sched_type
, &iflpr
->iflpr_output_sched
,
1621 sizeof (iflpr
->iflpr_output_sched
));
1623 if (IFCQ_TBR_IS_ENABLED(ifq
)) {
1624 tbr_bw
= ifq
->ifcq_tbr
.tbr_rate_raw
;
1625 tbr_pct
= ifq
->ifcq_tbr
.tbr_percent
;
1627 bcopy(&tbr_bw
, &iflpr
->iflpr_output_tbr_rate
,
1628 sizeof (iflpr
->iflpr_output_tbr_rate
));
1629 bcopy(&tbr_pct
, &iflpr
->iflpr_output_tbr_percent
,
1630 sizeof (iflpr
->iflpr_output_tbr_percent
));
1633 if (ifp
->if_output_sched_model
==
1634 IFNET_SCHED_MODEL_DRIVER_MANAGED
)
1635 flags
|= IFLPRF_DRVMANAGED
;
1636 bcopy(&flags
, &iflpr
->iflpr_flags
, sizeof (iflpr
->iflpr_flags
));
1637 bcopy(&ifp
->if_output_bw
, &iflpr
->iflpr_output_bw
,
1638 sizeof (iflpr
->iflpr_output_bw
));
1639 bcopy(&ifp
->if_input_bw
, &iflpr
->iflpr_input_bw
,
1640 sizeof (iflpr
->iflpr_input_bw
));
1641 bcopy(&ifp
->if_output_lt
, &iflpr
->iflpr_output_lt
,
1642 sizeof (iflpr
->iflpr_output_lt
));
1643 bcopy(&ifp
->if_input_lt
, &iflpr
->iflpr_input_lt
,
1644 sizeof (iflpr
->iflpr_input_lt
));
1656 static __attribute__((noinline
)) int
1657 ifioctl_qstats(struct ifnet
*ifp
, u_long cmd
, caddr_t data
)
1659 struct if_qstatsreq
*ifqr
= (struct if_qstatsreq
*)(void *)data
;
1660 u_int32_t ifqr_len
, ifqr_slot
;
1663 VERIFY(ifp
!= NULL
);
1666 case SIOCGIFQUEUESTATS
: { /* struct if_qstatsreq */
1667 bcopy(&ifqr
->ifqr_slot
, &ifqr_slot
, sizeof (ifqr_slot
));
1668 bcopy(&ifqr
->ifqr_len
, &ifqr_len
, sizeof (ifqr_len
));
1669 error
= ifclassq_getqstats(&ifp
->if_snd
, ifqr_slot
,
1670 ifqr
->ifqr_buf
, &ifqr_len
);
1673 bcopy(&ifqr_len
, &ifqr
->ifqr_len
, sizeof (ifqr_len
));
1685 static __attribute__((noinline
)) int
1686 ifioctl_throttle(struct ifnet
*ifp
, u_long cmd
, caddr_t data
, struct proc
*p
)
1688 struct if_throttlereq
*ifthr
= (struct if_throttlereq
*)(void *)data
;
1689 u_int32_t ifthr_level
;
1692 VERIFY(ifp
!= NULL
);
1695 case SIOCSIFTHROTTLE
: { /* struct if_throttlereq */
1697 * XXX: Use priv_check_cred() instead of root check?
1699 if ((error
= proc_suser(p
)) != 0)
1702 bcopy(&ifthr
->ifthr_level
, &ifthr_level
, sizeof (ifthr_level
));
1703 error
= ifnet_set_throttle(ifp
, ifthr_level
);
1704 if (error
== EALREADY
)
1709 case SIOCGIFTHROTTLE
: { /* struct if_throttlereq */
1710 if ((error
= ifnet_get_throttle(ifp
, &ifthr_level
)) == 0) {
1711 bcopy(&ifthr_level
, &ifthr
->ifthr_level
,
1712 sizeof (ifthr_level
));
1726 ifioctl_getnetagents(struct ifnet
*ifp
, u_int32_t
*count
, user_addr_t uuid_p
)
1730 u_int32_t valid_netagent_count
= 0;
1732 for (index
= 0; index
< IF_MAXAGENTS
; index
++) {
1733 uuid_t
*netagent_uuid
= &(ifp
->if_agentids
[index
]);
1734 if (!uuid_is_null(*netagent_uuid
)) {
1735 if (uuid_p
!= USER_ADDR_NULL
) {
1736 if ((error
= copyout(netagent_uuid
,
1737 uuid_p
+ sizeof(uuid_t
) * valid_netagent_count
,
1738 sizeof(uuid_t
))) != 0) {
1742 valid_netagent_count
++;
1745 *count
= valid_netagent_count
;
1750 static __attribute__((noinline
)) int
1751 ifioctl_netagent(struct ifnet
*ifp
, u_long cmd
, caddr_t data
, struct proc
*p
)
1753 struct if_agentidreq
*ifar
= (struct if_agentidreq
*)(void *)data
;
1755 struct if_agentidsreq32 s32
;
1756 struct if_agentidsreq64 s64
;
1761 VERIFY(ifp
!= NULL
);
1764 case SIOCAIFAGENTID
: { /* struct if_agentidreq */
1765 uuid_t
*first_empty_slot
= NULL
;
1766 // TODO: Use priv_check_cred() instead of root check
1767 if ((error
= proc_suser(p
)) != 0) {
1770 for (index
= 0; index
< IF_MAXAGENTS
; index
++) {
1771 uuid_t
*netagent_uuid
= &(ifp
->if_agentids
[index
]);
1772 if (uuid_compare(*netagent_uuid
, ifar
->ifar_uuid
) == 0) {
1773 /* Already present, ignore */
1776 if (first_empty_slot
== NULL
&&
1777 uuid_is_null(*netagent_uuid
)) {
1778 first_empty_slot
= netagent_uuid
;
1781 if (first_empty_slot
== NULL
) {
1782 error
= ENOMEM
; /* No empty slot for a netagent UUID, bail */
1785 uuid_copy(*first_empty_slot
, ifar
->ifar_uuid
);
1786 netagent_post_updated_interfaces(ifar
->ifar_uuid
);
1789 case SIOCDIFAGENTID
: { /* struct if_agentidreq */
1790 bool removed_agent_id
= FALSE
;
1791 // TODO: Use priv_check_cred() instead of root check
1792 if ((error
= proc_suser(p
)) != 0) {
1795 for (index
= 0; index
< IF_MAXAGENTS
; index
++) {
1796 uuid_t
*netagent_uuid
= &(ifp
->if_agentids
[index
]);
1797 if (uuid_compare(*netagent_uuid
, ifar
->ifar_uuid
) == 0) {
1798 uuid_clear(*netagent_uuid
);
1799 removed_agent_id
= TRUE
;
1803 if (removed_agent_id
) {
1804 netagent_post_updated_interfaces(ifar
->ifar_uuid
);
1808 case SIOCGIFAGENTIDS32
: { /* struct if_agentidsreq32 */
1809 bcopy(data
, &u
.s32
, sizeof(u
.s32
));
1810 error
= ifioctl_getnetagents(ifp
, &u
.s32
.ifar_count
, u
.s32
.ifar_uuids
);
1812 bcopy(&u
.s32
, data
, sizeof(u
.s32
));
1816 case SIOCGIFAGENTIDS64
: { /* struct if_agentidsreq64 */
1817 bcopy(data
, &u
.s64
, sizeof(u
.s64
));
1818 error
= ifioctl_getnetagents(ifp
, &u
.s64
.ifar_count
, u
.s64
.ifar_uuids
);
1820 bcopy(&u
.s64
, data
, sizeof(u
.s64
));
1833 ifnet_clear_netagent(uuid_t netagent_uuid
)
1835 struct ifnet
*ifp
= NULL
;
1837 bool removed_agent_id
= FALSE
;
1839 ifnet_head_lock_shared();
1841 TAILQ_FOREACH(ifp
, &ifnet_head
, if_link
) {
1842 for (index
= 0; index
< IF_MAXAGENTS
; index
++) {
1843 uuid_t
*ifp_netagent_uuid
= &(ifp
->if_agentids
[index
]);
1844 if (uuid_compare(*ifp_netagent_uuid
, netagent_uuid
) == 0) {
1845 uuid_clear(*ifp_netagent_uuid
);
1846 removed_agent_id
= TRUE
;
1854 static __attribute__((noinline
)) int
1855 ifioctl_netsignature(struct ifnet
*ifp
, u_long cmd
, caddr_t data
)
1857 struct if_nsreq
*ifnsr
= (struct if_nsreq
*)(void *)data
;
1861 VERIFY(ifp
!= NULL
);
1864 case SIOCSIFNETSIGNATURE
: /* struct if_nsreq */
1865 if (ifnsr
->ifnsr_len
> sizeof (ifnsr
->ifnsr_data
)) {
1869 bcopy(&ifnsr
->ifnsr_flags
, &flags
, sizeof (flags
));
1870 error
= ifnet_set_netsignature(ifp
, ifnsr
->ifnsr_family
,
1871 ifnsr
->ifnsr_len
, flags
, ifnsr
->ifnsr_data
);
1874 case SIOCGIFNETSIGNATURE
: /* struct if_nsreq */
1875 ifnsr
->ifnsr_len
= sizeof (ifnsr
->ifnsr_data
);
1876 error
= ifnet_get_netsignature(ifp
, ifnsr
->ifnsr_family
,
1877 &ifnsr
->ifnsr_len
, &flags
, ifnsr
->ifnsr_data
);
1879 bcopy(&flags
, &ifnsr
->ifnsr_flags
, sizeof (flags
));
1881 ifnsr
->ifnsr_len
= 0;
1895 * Most of the routines called to handle the ioctls would end up being
1896 * tail-call optimized, which unfortunately causes this routine to
1897 * consume too much stack space; this is the reason for the "noinline"
1898 * attribute used on those routines.
1901 ifioctl(struct socket
*so
, u_long cmd
, caddr_t data
, struct proc
*p
)
1903 char ifname
[IFNAMSIZ
+ 1];
1904 struct ifnet
*ifp
= NULL
;
1905 struct ifstat
*ifs
= NULL
;
1908 bzero(ifname
, sizeof (ifname
));
1911 * ioctls which don't require ifp, or ifreq ioctls
1914 case OSIOCGIFCONF32
: /* struct ifconf32 */
1915 case SIOCGIFCONF32
: /* struct ifconf32 */
1916 case SIOCGIFCONF64
: /* struct ifconf64 */
1917 case OSIOCGIFCONF64
: /* struct ifconf64 */
1918 error
= ifioctl_ifconf(cmd
, data
);
1921 case SIOCIFGCLONERS32
: /* struct if_clonereq32 */
1922 case SIOCIFGCLONERS64
: /* struct if_clonereq64 */
1923 error
= ifioctl_ifclone(cmd
, data
);
1926 case SIOCGIFAGENTDATA32
: /* struct netagent_req32 */
1927 case SIOCGIFAGENTDATA64
: /* struct netagent_req64 */
1928 error
= netagent_ioctl(cmd
, data
);
1931 case SIOCSIFDSTADDR
: /* struct ifreq */
1932 case SIOCSIFADDR
: /* struct ifreq */
1933 case SIOCSIFBRDADDR
: /* struct ifreq */
1934 case SIOCSIFNETMASK
: /* struct ifreq */
1935 case OSIOCGIFADDR
: /* struct ifreq */
1936 case OSIOCGIFDSTADDR
: /* struct ifreq */
1937 case OSIOCGIFBRDADDR
: /* struct ifreq */
1938 case OSIOCGIFNETMASK
: /* struct ifreq */
1939 case SIOCSIFKPI
: /* struct ifreq */
1940 if (so
->so_proto
== NULL
) {
1945 case SIOCIFCREATE
: /* struct ifreq */
1946 case SIOCIFCREATE2
: /* struct ifreq */
1947 case SIOCIFDESTROY
: /* struct ifreq */
1948 case SIOCGIFFLAGS
: /* struct ifreq */
1949 case SIOCGIFEFLAGS
: /* struct ifreq */
1950 case SIOCGIFCAP
: /* struct ifreq */
1952 case SIOCGIFMAC
: /* struct ifreq */
1953 case SIOCSIFMAC
: /* struct ifreq */
1954 #endif /* CONFIG_MACF_NET */
1955 case SIOCGIFMETRIC
: /* struct ifreq */
1956 case SIOCGIFMTU
: /* struct ifreq */
1957 case SIOCGIFPHYS
: /* struct ifreq */
1958 case SIOCSIFFLAGS
: /* struct ifreq */
1959 case SIOCSIFCAP
: /* struct ifreq */
1960 case SIOCSIFMETRIC
: /* struct ifreq */
1961 case SIOCSIFPHYS
: /* struct ifreq */
1962 case SIOCSIFMTU
: /* struct ifreq */
1963 case SIOCADDMULTI
: /* struct ifreq */
1964 case SIOCDELMULTI
: /* struct ifreq */
1965 case SIOCDIFPHYADDR
: /* struct ifreq */
1966 case SIOCSIFMEDIA
: /* struct ifreq */
1967 case SIOCSIFGENERIC
: /* struct ifreq */
1968 case SIOCSIFLLADDR
: /* struct ifreq */
1969 case SIOCSIFALTMTU
: /* struct ifreq */
1970 case SIOCSIFVLAN
: /* struct ifreq */
1971 case SIOCSIFBOND
: /* struct ifreq */
1972 case SIOCGIFLLADDR
: /* struct ifreq */
1973 case SIOCGIFTYPE
: /* struct ifreq */
1974 case SIOCGIFFUNCTIONALTYPE
: /* struct ifreq */
1975 case SIOCGIFPSRCADDR
: /* struct ifreq */
1976 case SIOCGIFPDSTADDR
: /* struct ifreq */
1977 case SIOCGIFGENERIC
: /* struct ifreq */
1978 case SIOCGIFDEVMTU
: /* struct ifreq */
1979 case SIOCGIFVLAN
: /* struct ifreq */
1980 case SIOCGIFBOND
: /* struct ifreq */
1981 case SIOCGIFWAKEFLAGS
: /* struct ifreq */
1982 case SIOCGIFGETRTREFCNT
: /* struct ifreq */
1983 case SIOCSIFOPPORTUNISTIC
: /* struct ifreq */
1984 case SIOCGIFOPPORTUNISTIC
: /* struct ifreq */
1985 case SIOCGIFLINKQUALITYMETRIC
: /* struct ifreq */
1986 case SIOCSIFLOG
: /* struct ifreq */
1987 case SIOCGIFLOG
: /* struct ifreq */
1988 case SIOCGIFDELEGATE
: /* struct ifreq */
1989 case SIOCGIFEXPENSIVE
: /* struct ifreq */
1990 case SIOCSIFEXPENSIVE
: /* struct ifreq */
1991 case SIOCSIF2KCL
: /* struct ifreq */
1992 case SIOCGIF2KCL
: /* struct ifreq */
1993 case SIOCSIFINTERFACESTATE
: /* struct ifreq */
1994 case SIOCGIFINTERFACESTATE
: /* struct ifreq */
1995 case SIOCSIFPROBECONNECTIVITY
: /* struct ifreq */
1996 case SIOCGIFPROBECONNECTIVITY
: /* struct ifreq */
1997 case SIOCGSTARTDELAY
: /* struct ifreq */
1998 case SIOCGECNMODE
: /* struct ifreq */
1999 case SIOCSECNMODE
: { /* struct ifreq */
2001 bcopy(data
, &ifr
, sizeof (ifr
));
2002 ifr
.ifr_name
[IFNAMSIZ
- 1] = '\0';
2003 bcopy(&ifr
.ifr_name
, ifname
, IFNAMSIZ
);
2004 error
= ifioctl_ifreq(so
, cmd
, &ifr
, p
);
2005 bcopy(&ifr
, data
, sizeof (ifr
));
2011 * ioctls which require ifp. Note that we acquire dlil_ifnet_lock
2012 * here to ensure that the ifnet, if found, has been fully attached.
2016 case SIOCSIFPHYADDR
: /* struct {if,in_}aliasreq */
2017 bcopy(((struct in_aliasreq
*)(void *)data
)->ifra_name
,
2019 ifp
= ifunit(ifname
);
2023 case SIOCSIFPHYADDR_IN6_32
: /* struct in6_aliasreq_32 */
2024 bcopy(((struct in6_aliasreq_32
*)(void *)data
)->ifra_name
,
2026 ifp
= ifunit(ifname
);
2029 case SIOCSIFPHYADDR_IN6_64
: /* struct in6_aliasreq_64 */
2030 bcopy(((struct in6_aliasreq_64
*)(void *)data
)->ifra_name
,
2032 ifp
= ifunit(ifname
);
2036 case SIOCGIFSTATUS
: /* struct ifstat */
2037 ifs
= _MALLOC(sizeof (*ifs
), M_DEVBUF
, M_WAITOK
);
2043 bcopy(data
, ifs
, sizeof (*ifs
));
2044 ifs
->ifs_name
[IFNAMSIZ
- 1] = '\0';
2045 bcopy(ifs
->ifs_name
, ifname
, IFNAMSIZ
);
2046 ifp
= ifunit(ifname
);
2049 case SIOCGIFMEDIA32
: /* struct ifmediareq32 */
2050 bcopy(((struct ifmediareq32
*)(void *)data
)->ifm_name
,
2052 ifp
= ifunit(ifname
);
2055 case SIOCGIFMEDIA64
: /* struct ifmediareq64 */
2056 bcopy(((struct ifmediareq64
*)(void *)data
)->ifm_name
,
2058 ifp
= ifunit(ifname
);
2061 case SIOCSIFDESC
: /* struct if_descreq */
2062 case SIOCGIFDESC
: /* struct if_descreq */
2063 bcopy(((struct if_descreq
*)(void *)data
)->ifdr_name
,
2065 ifp
= ifunit(ifname
);
2068 case SIOCSIFLINKPARAMS
: /* struct if_linkparamsreq */
2069 case SIOCGIFLINKPARAMS
: /* struct if_linkparamsreq */
2070 bcopy(((struct if_linkparamsreq
*)(void *)data
)->iflpr_name
,
2072 ifp
= ifunit(ifname
);
2075 case SIOCGIFQUEUESTATS
: /* struct if_qstatsreq */
2076 bcopy(((struct if_qstatsreq
*)(void *)data
)->ifqr_name
,
2078 ifp
= ifunit(ifname
);
2081 case SIOCSIFTHROTTLE
: /* struct if_throttlereq */
2082 case SIOCGIFTHROTTLE
: /* struct if_throttlereq */
2083 bcopy(((struct if_throttlereq
*)(void *)data
)->ifthr_name
,
2085 ifp
= ifunit(ifname
);
2088 case SIOCAIFAGENTID
: /* struct if_agentidreq */
2089 case SIOCDIFAGENTID
: /* struct if_agentidreq */
2090 case SIOCGIFAGENTIDS32
: /* struct if_agentidsreq32 */
2091 case SIOCGIFAGENTIDS64
: /* struct if_agentidsreq64 */
2092 bcopy(((struct if_agentidreq
*)(void *)data
)->ifar_name
,
2094 ifp
= ifunit(ifname
);
2097 case SIOCSIFNETSIGNATURE
: /* struct if_nsreq */
2098 case SIOCGIFNETSIGNATURE
: /* struct if_nsreq */
2099 bcopy(((struct if_nsreq
*)(void *)data
)->ifnsr_name
,
2101 ifp
= ifunit(ifname
);
2106 * This is a bad assumption, but the code seems to
2107 * have been doing this in the past; caveat emptor.
2109 bcopy(((struct ifreq
*)(void *)data
)->ifr_name
,
2111 ifp
= ifunit(ifname
);
2122 case SIOCSIFPHYADDR
: /* struct {if,in_}aliasreq */
2124 case SIOCSIFPHYADDR_IN6_32
: /* struct in6_aliasreq_32 */
2125 case SIOCSIFPHYADDR_IN6_64
: /* struct in6_aliasreq_64 */
2127 error
= proc_suser(p
);
2131 error
= ifnet_ioctl(ifp
, SOCK_DOM(so
), cmd
, data
);
2135 ifnet_touch_lastchange(ifp
);
2138 case SIOCGIFSTATUS
: /* struct ifstat */
2139 VERIFY(ifs
!= NULL
);
2140 ifs
->ascii
[0] = '\0';
2142 error
= ifnet_ioctl(ifp
, SOCK_DOM(so
), cmd
, (caddr_t
)ifs
);
2144 bcopy(ifs
, data
, sizeof (*ifs
));
2147 case SIOCGIFMEDIA32
: /* struct ifmediareq32 */
2148 case SIOCGIFMEDIA64
: /* struct ifmediareq64 */
2149 error
= ifnet_ioctl(ifp
, SOCK_DOM(so
), cmd
, data
);
2152 case SIOCSIFDESC
: /* struct if_descreq */
2153 case SIOCGIFDESC
: /* struct if_descreq */
2154 error
= ifioctl_ifdesc(ifp
, cmd
, data
, p
);
2157 case SIOCSIFLINKPARAMS
: /* struct if_linkparamsreq */
2158 case SIOCGIFLINKPARAMS
: /* struct if_linkparamsreq */
2159 error
= ifioctl_linkparams(ifp
, cmd
, data
, p
);
2162 case SIOCGIFQUEUESTATS
: /* struct if_qstatsreq */
2163 error
= ifioctl_qstats(ifp
, cmd
, data
);
2166 case SIOCSIFTHROTTLE
: /* struct if_throttlereq */
2167 case SIOCGIFTHROTTLE
: /* struct if_throttlereq */
2168 error
= ifioctl_throttle(ifp
, cmd
, data
, p
);
2171 case SIOCAIFAGENTID
: /* struct if_agentidreq */
2172 case SIOCDIFAGENTID
: /* struct if_agentidreq */
2173 case SIOCGIFAGENTIDS32
: /* struct if_agentidsreq32 */
2174 case SIOCGIFAGENTIDS64
: /* struct if_agentidsreq64 */
2175 error
= ifioctl_netagent(ifp
, cmd
, data
, p
);
2178 case SIOCSIFNETSIGNATURE
: /* struct if_nsreq */
2179 case SIOCGIFNETSIGNATURE
: /* struct if_nsreq */
2180 error
= ifioctl_netsignature(ifp
, cmd
, data
);
2184 if (so
->so_proto
== NULL
) {
2190 error
= ((*so
->so_proto
->pr_usrreqs
->pru_control
)(so
, cmd
,
2192 socket_unlock(so
, 1);
2194 if (error
== EOPNOTSUPP
|| error
== ENOTSUP
) {
2195 error
= ifnet_ioctl(ifp
, SOCK_DOM(so
), cmd
, data
);
2202 _FREE(ifs
, M_DEVBUF
);
2205 if (ifname
[0] == '\0')
2206 (void) snprintf(ifname
, sizeof (ifname
), "%s",
2208 else if (ifp
!= NULL
)
2209 (void) snprintf(ifname
, sizeof (ifname
), "%s",
2213 printf("%s[%s,%d]: ifp %s cmd 0x%08lx (%c%c [%lu] "
2214 "%c %lu) error %d\n", __func__
,
2215 proc_name_address(p
), proc_pid(p
),
2216 ifname
, cmd
, (cmd
& IOC_IN
) ? 'I' : ' ',
2217 (cmd
& IOC_OUT
) ? 'O' : ' ', IOCPARM_LEN(cmd
),
2218 (char)IOCGROUP(cmd
), cmd
& 0xff, error
);
2219 } else if (if_verbose
> 1) {
2220 printf("%s[%s,%d]: ifp %s cmd 0x%08lx (%c%c [%lu] "
2221 "%c %lu) OK\n", __func__
,
2222 proc_name_address(p
), proc_pid(p
),
2223 ifname
, cmd
, (cmd
& IOC_IN
) ? 'I' : ' ',
2224 (cmd
& IOC_OUT
) ? 'O' : ' ', IOCPARM_LEN(cmd
),
2225 (char)IOCGROUP(cmd
), cmd
& 0xff);
2232 static __attribute__((noinline
)) int
2233 ifioctl_ifreq(struct socket
*so
, u_long cmd
, struct ifreq
*ifr
, struct proc
*p
)
2238 struct kev_msg ev_msg
;
2239 struct net_event_data ev_data
;
2241 bzero(&ev_data
, sizeof (struct net_event_data
));
2242 bzero(&ev_msg
, sizeof (struct kev_msg
));
2247 error
= proc_suser(p
);
2250 return (if_clone_create(ifr
->ifr_name
, sizeof(ifr
->ifr_name
),
2251 cmd
== SIOCIFCREATE2
? ifr
->ifr_data
: NULL
));
2253 error
= proc_suser(p
);
2256 return (if_clone_destroy(ifr
->ifr_name
));
2260 * ioctls which require ifp. Note that we acquire dlil_ifnet_lock
2261 * here to ensure that the ifnet, if found, has been fully attached.
2264 ifp
= ifunit(ifr
->ifr_name
);
2272 ifnet_lock_shared(ifp
);
2273 ifr
->ifr_flags
= ifp
->if_flags
;
2274 ifnet_lock_done(ifp
);
2278 ifnet_lock_shared(ifp
);
2279 ifr
->ifr_eflags
= ifp
->if_eflags
;
2280 ifnet_lock_done(ifp
);
2284 ifnet_lock_shared(ifp
);
2285 ifr
->ifr_reqcap
= ifp
->if_capabilities
;
2286 ifr
->ifr_curcap
= ifp
->if_capenable
;
2287 ifnet_lock_done(ifp
);
2292 error
= mac_ifnet_label_get(kauth_cred_get(), ifr
, ifp
);
2296 error
= mac_ifnet_label_set(kauth_cred_get(), ifr
, ifp
);
2298 #endif /* CONFIG_MACF_NET */
2301 ifnet_lock_shared(ifp
);
2302 ifr
->ifr_metric
= ifp
->if_metric
;
2303 ifnet_lock_done(ifp
);
2307 ifnet_lock_shared(ifp
);
2308 ifr
->ifr_mtu
= ifp
->if_mtu
;
2309 ifnet_lock_done(ifp
);
2313 ifnet_lock_shared(ifp
);
2314 ifr
->ifr_phys
= ifp
->if_physical
;
2315 ifnet_lock_done(ifp
);
2319 error
= proc_suser(p
);
2323 (void) ifnet_set_flags(ifp
, ifr
->ifr_flags
,
2324 (u_int16_t
)~IFF_CANTCHANGE
);
2327 * Note that we intentionally ignore any error from below
2328 * for the SIOCSIFFLAGS case.
2330 (void) ifnet_ioctl(ifp
, SOCK_DOM(so
), cmd
, (caddr_t
)ifr
);
2333 * Send the event even upon error from the driver because
2334 * we changed the flags.
2336 ev_msg
.vendor_code
= KEV_VENDOR_APPLE
;
2337 ev_msg
.kev_class
= KEV_NETWORK_CLASS
;
2338 ev_msg
.kev_subclass
= KEV_DL_SUBCLASS
;
2340 ev_msg
.event_code
= KEV_DL_SIFFLAGS
;
2341 strlcpy(&ev_data
.if_name
[0], ifp
->if_name
, IFNAMSIZ
);
2342 ev_data
.if_family
= ifp
->if_family
;
2343 ev_data
.if_unit
= (u_int32_t
) ifp
->if_unit
;
2344 ev_msg
.dv
[0].data_length
= sizeof(struct net_event_data
);
2345 ev_msg
.dv
[0].data_ptr
= &ev_data
;
2346 ev_msg
.dv
[1].data_length
= 0;
2347 kev_post_msg(&ev_msg
);
2349 ifnet_touch_lastchange(ifp
);
2353 error
= proc_suser(p
);
2357 if ((ifr
->ifr_reqcap
& ~ifp
->if_capabilities
)) {
2361 error
= ifnet_ioctl(ifp
, SOCK_DOM(so
), cmd
, (caddr_t
)ifr
);
2363 ifnet_touch_lastchange(ifp
);
2367 error
= proc_suser(p
);
2371 ifp
->if_metric
= ifr
->ifr_metric
;
2373 ev_msg
.vendor_code
= KEV_VENDOR_APPLE
;
2374 ev_msg
.kev_class
= KEV_NETWORK_CLASS
;
2375 ev_msg
.kev_subclass
= KEV_DL_SUBCLASS
;
2377 ev_msg
.event_code
= KEV_DL_SIFMETRICS
;
2378 strlcpy(&ev_data
.if_name
[0], ifp
->if_name
, IFNAMSIZ
);
2379 ev_data
.if_family
= ifp
->if_family
;
2380 ev_data
.if_unit
= (u_int32_t
) ifp
->if_unit
;
2381 ev_msg
.dv
[0].data_length
= sizeof(struct net_event_data
);
2382 ev_msg
.dv
[0].data_ptr
= &ev_data
;
2384 ev_msg
.dv
[1].data_length
= 0;
2385 kev_post_msg(&ev_msg
);
2387 ifnet_touch_lastchange(ifp
);
2391 error
= proc_suser(p
);
2395 error
= ifnet_ioctl(ifp
, SOCK_DOM(so
), cmd
, (caddr_t
)ifr
);
2399 ev_msg
.vendor_code
= KEV_VENDOR_APPLE
;
2400 ev_msg
.kev_class
= KEV_NETWORK_CLASS
;
2401 ev_msg
.kev_subclass
= KEV_DL_SUBCLASS
;
2403 ev_msg
.event_code
= KEV_DL_SIFPHYS
;
2404 strlcpy(&ev_data
.if_name
[0], ifp
->if_name
, IFNAMSIZ
);
2405 ev_data
.if_family
= ifp
->if_family
;
2406 ev_data
.if_unit
= (u_int32_t
) ifp
->if_unit
;
2407 ev_msg
.dv
[0].data_length
= sizeof(struct net_event_data
);
2408 ev_msg
.dv
[0].data_ptr
= &ev_data
;
2409 ev_msg
.dv
[1].data_length
= 0;
2410 kev_post_msg(&ev_msg
);
2412 ifnet_touch_lastchange(ifp
);
2416 u_int32_t oldmtu
= ifp
->if_mtu
;
2417 struct ifclassq
*ifq
= &ifp
->if_snd
;
2419 error
= proc_suser(p
);
2423 if (ifp
->if_ioctl
== NULL
) {
2427 if (ifr
->ifr_mtu
< IF_MINMTU
|| ifr
->ifr_mtu
> IF_MAXMTU
) {
2431 error
= ifnet_ioctl(ifp
, SOCK_DOM(so
), cmd
, (caddr_t
)ifr
);
2435 ev_msg
.vendor_code
= KEV_VENDOR_APPLE
;
2436 ev_msg
.kev_class
= KEV_NETWORK_CLASS
;
2437 ev_msg
.kev_subclass
= KEV_DL_SUBCLASS
;
2439 ev_msg
.event_code
= KEV_DL_SIFMTU
;
2440 strlcpy(&ev_data
.if_name
[0], ifp
->if_name
, IFNAMSIZ
);
2441 ev_data
.if_family
= ifp
->if_family
;
2442 ev_data
.if_unit
= (u_int32_t
) ifp
->if_unit
;
2443 ev_msg
.dv
[0].data_length
= sizeof(struct net_event_data
);
2444 ev_msg
.dv
[0].data_ptr
= &ev_data
;
2445 ev_msg
.dv
[1].data_length
= 0;
2446 kev_post_msg(&ev_msg
);
2448 ifnet_touch_lastchange(ifp
);
2452 * If the link MTU changed, do network layer specific procedure
2453 * and update all route entries associated with the interface,
2454 * so that their MTU metric gets updated.
2456 if (ifp
->if_mtu
!= oldmtu
) {
2457 if_rtmtu_update(ifp
);
2461 /* Inform all transmit queues about the new MTU */
2463 ifnet_update_sndq(ifq
, CLASSQ_EV_LINK_MTU
);
2471 error
= proc_suser(p
);
2475 /* Don't allow group membership on non-multicast interfaces. */
2476 if ((ifp
->if_flags
& IFF_MULTICAST
) == 0) {
2481 /* Don't let users screw up protocols' entries. */
2482 if (ifr
->ifr_addr
.sa_family
!= AF_UNSPEC
&&
2483 ifr
->ifr_addr
.sa_family
!= AF_LINK
) {
2489 * User is permitted to anonymously join a particular link
2490 * multicast group via SIOCADDMULTI. Subsequent join requested
2491 * for the same record which has an outstanding refcnt from a
2492 * past if_addmulti_anon() will not result in EADDRINUSE error
2493 * (unlike other BSDs.) Anonymously leaving a group is also
2494 * allowed only as long as there is an outstanding refcnt held
2495 * by a previous anonymous request, or else ENOENT (even if the
2496 * link-layer multicast membership exists for a network-layer
2499 if (cmd
== SIOCADDMULTI
) {
2500 error
= if_addmulti_anon(ifp
, &ifr
->ifr_addr
, NULL
);
2501 ev_msg
.event_code
= KEV_DL_ADDMULTI
;
2503 error
= if_delmulti_anon(ifp
, &ifr
->ifr_addr
);
2504 ev_msg
.event_code
= KEV_DL_DELMULTI
;
2509 ev_msg
.vendor_code
= KEV_VENDOR_APPLE
;
2510 ev_msg
.kev_class
= KEV_NETWORK_CLASS
;
2511 ev_msg
.kev_subclass
= KEV_DL_SUBCLASS
;
2512 strlcpy(&ev_data
.if_name
[0], ifp
->if_name
, IFNAMSIZ
);
2514 ev_data
.if_family
= ifp
->if_family
;
2515 ev_data
.if_unit
= (u_int32_t
) ifp
->if_unit
;
2516 ev_msg
.dv
[0].data_length
= sizeof(struct net_event_data
);
2517 ev_msg
.dv
[0].data_ptr
= &ev_data
;
2518 ev_msg
.dv
[1].data_length
= 0;
2519 kev_post_msg(&ev_msg
);
2521 ifnet_touch_lastchange(ifp
);
2524 case SIOCDIFPHYADDR
:
2526 case SIOCSIFGENERIC
:
2531 error
= proc_suser(p
);
2535 error
= ifnet_ioctl(ifp
, SOCK_DOM(so
), cmd
, (caddr_t
)ifr
);
2539 ifnet_touch_lastchange(ifp
);
2542 case SIOCGIFLLADDR
: {
2543 struct sockaddr_dl
*sdl
= SDL(ifp
->if_lladdr
->ifa_addr
);
2545 if (sdl
->sdl_alen
== 0) {
2546 error
= EADDRNOTAVAIL
;
2549 /* If larger than 14-bytes we'll need another mechanism */
2550 if (sdl
->sdl_alen
> sizeof (ifr
->ifr_addr
.sa_data
)) {
2554 /* Follow the same convention used by SIOCSIFLLADDR */
2555 bzero(&ifr
->ifr_addr
, sizeof (ifr
->ifr_addr
));
2556 ifr
->ifr_addr
.sa_family
= AF_LINK
;
2557 ifr
->ifr_addr
.sa_len
= sdl
->sdl_alen
;
2558 error
= ifnet_guarded_lladdr_copy_bytes(ifp
,
2559 &ifr
->ifr_addr
.sa_data
, sdl
->sdl_alen
);
2564 ifr
->ifr_type
.ift_type
= ifp
->if_type
;
2565 ifr
->ifr_type
.ift_family
= ifp
->if_family
;
2566 ifr
->ifr_type
.ift_subfamily
= ifp
->if_subfamily
;
2569 case SIOCGIFFUNCTIONALTYPE
:
2570 ifr
->ifr_functional_type
= if_functional_type(ifp
);
2573 case SIOCGIFPSRCADDR
:
2574 case SIOCGIFPDSTADDR
:
2575 case SIOCGIFGENERIC
:
2579 error
= ifnet_ioctl(ifp
, SOCK_DOM(so
), cmd
, (caddr_t
)ifr
);
2582 case SIOCGIFWAKEFLAGS
:
2583 ifnet_lock_shared(ifp
);
2584 ifr
->ifr_wake_flags
= ifnet_get_wake_flags(ifp
);
2585 ifnet_lock_done(ifp
);
2588 case SIOCGIFGETRTREFCNT
:
2589 ifnet_lock_shared(ifp
);
2590 ifr
->ifr_route_refcnt
= ifp
->if_route_refcnt
;
2591 ifnet_lock_done(ifp
);
2594 case SIOCSIFOPPORTUNISTIC
:
2595 case SIOCGIFOPPORTUNISTIC
:
2596 error
= ifnet_getset_opportunistic(ifp
, cmd
, ifr
, p
);
2599 case SIOCGIFLINKQUALITYMETRIC
:
2600 ifnet_lock_shared(ifp
);
2601 if ((ifp
->if_interface_state
.valid_bitmask
&
2602 IF_INTERFACE_STATE_LQM_STATE_VALID
))
2603 ifr
->ifr_link_quality_metric
=
2604 ifp
->if_interface_state
.lqm_state
;
2605 else if ((ifp
->if_refflags
& IFRF_ATTACHED
)) {
2606 ifr
->ifr_link_quality_metric
=
2607 IFNET_LQM_THRESH_UNKNOWN
;
2609 ifr
->ifr_link_quality_metric
=
2610 IFNET_LQM_THRESH_OFF
;
2612 ifnet_lock_done(ifp
);
2617 error
= ifnet_getset_log(ifp
, cmd
, ifr
, p
);
2620 case SIOCGIFDELEGATE
:
2621 ifnet_lock_shared(ifp
);
2622 ifr
->ifr_delegated
= ((ifp
->if_delegated
.ifp
!= NULL
) ?
2623 ifp
->if_delegated
.ifp
->if_index
: 0);
2624 ifnet_lock_done(ifp
);
2627 case SIOCGIFEXPENSIVE
:
2628 ifnet_lock_shared(ifp
);
2629 if (ifp
->if_eflags
& IFEF_EXPENSIVE
)
2630 ifr
->ifr_expensive
= 1;
2632 ifr
->ifr_expensive
= 0;
2633 ifnet_lock_done(ifp
);
2636 case SIOCSIFEXPENSIVE
:
2640 if ((error
= priv_check_cred(kauth_cred_get(),
2641 PRIV_NET_INTERFACE_CONTROL
, 0)) != 0)
2643 ifnet_lock_exclusive(ifp
);
2644 if (ifr
->ifr_expensive
)
2645 ifp
->if_eflags
|= IFEF_EXPENSIVE
;
2647 ifp
->if_eflags
&= ~IFEF_EXPENSIVE
;
2648 ifnet_lock_done(ifp
);
2650 * Update the expensive bit in the delegated interface
2653 ifnet_head_lock_shared();
2654 TAILQ_FOREACH(difp
, &ifnet_head
, if_link
) {
2655 ifnet_lock_exclusive(difp
);
2656 if (difp
->if_delegated
.ifp
== ifp
) {
2657 difp
->if_delegated
.expensive
=
2658 ifp
->if_eflags
& IFEF_EXPENSIVE
? 1 : 0;
2661 ifnet_lock_done(difp
);
2668 ifnet_lock_shared(ifp
);
2669 if (ifp
->if_eflags
& IFEF_2KCL
)
2673 ifnet_lock_done(ifp
);
2677 if ((error
= priv_check_cred(kauth_cred_get(),
2678 PRIV_NET_INTERFACE_CONTROL
, 0)) != 0)
2680 ifnet_lock_exclusive(ifp
);
2682 ifp
->if_eflags
|= IFEF_2KCL
;
2684 ifp
->if_eflags
&= ~IFEF_2KCL
;
2685 ifnet_lock_done(ifp
);
2687 case SIOCGSTARTDELAY
:
2688 ifnet_lock_shared(ifp
);
2689 if (ifp
->if_eflags
& IFEF_ENQUEUE_MULTI
) {
2690 ifr
->ifr_start_delay_qlen
=
2691 ifp
->if_start_delay_qlen
;
2692 ifr
->ifr_start_delay_timeout
=
2693 ifp
->if_start_delay_timeout
;
2695 ifr
->ifr_start_delay_qlen
= 0;
2696 ifr
->ifr_start_delay_timeout
= 0;
2698 ifnet_lock_done(ifp
);
2700 case SIOCSIFDSTADDR
:
2702 case SIOCSIFBRDADDR
:
2703 case SIOCSIFNETMASK
:
2705 case OSIOCGIFDSTADDR
:
2706 case OSIOCGIFBRDADDR
:
2707 case OSIOCGIFNETMASK
:
2709 VERIFY(so
->so_proto
!= NULL
);
2711 if (cmd
== SIOCSIFDSTADDR
|| cmd
== SIOCSIFADDR
||
2712 cmd
== SIOCSIFBRDADDR
|| cmd
== SIOCSIFNETMASK
) {
2713 #if BYTE_ORDER != BIG_ENDIAN
2714 if (ifr
->ifr_addr
.sa_family
== 0 &&
2715 ifr
->ifr_addr
.sa_len
< 16) {
2716 ifr
->ifr_addr
.sa_family
= ifr
->ifr_addr
.sa_len
;
2717 ifr
->ifr_addr
.sa_len
= 16;
2720 if (ifr
->ifr_addr
.sa_len
== 0)
2721 ifr
->ifr_addr
.sa_len
= 16;
2723 } else if (cmd
== OSIOCGIFADDR
) {
2724 cmd
= SIOCGIFADDR
; /* struct ifreq */
2725 } else if (cmd
== OSIOCGIFDSTADDR
) {
2726 cmd
= SIOCGIFDSTADDR
; /* struct ifreq */
2727 } else if (cmd
== OSIOCGIFBRDADDR
) {
2728 cmd
= SIOCGIFBRDADDR
; /* struct ifreq */
2729 } else if (cmd
== OSIOCGIFNETMASK
) {
2730 cmd
= SIOCGIFNETMASK
; /* struct ifreq */
2734 error
= ((*so
->so_proto
->pr_usrreqs
->pru_control
)(so
, cmd
,
2735 (caddr_t
)ifr
, ifp
, p
));
2736 socket_unlock(so
, 1);
2740 case OSIOCGIFDSTADDR
:
2741 case OSIOCGIFBRDADDR
:
2742 case OSIOCGIFNETMASK
:
2743 bcopy(&ifr
->ifr_addr
.sa_family
, &ifr
->ifr_addr
,
2747 if (cmd
== SIOCSIFKPI
) {
2748 int temperr
= proc_suser(p
);
2753 if (error
== EOPNOTSUPP
|| error
== ENOTSUP
) {
2754 error
= ifnet_ioctl(ifp
, SOCK_DOM(so
), cmd
,
2759 case SIOCGIFINTERFACESTATE
:
2760 if_get_state(ifp
, &ifr
->ifr_interface_state
);
2763 case SIOCSIFINTERFACESTATE
:
2764 if ((error
= priv_check_cred(kauth_cred_get(),
2765 PRIV_NET_INTERFACE_CONTROL
, 0)) != 0)
2768 error
= if_state_update(ifp
, &ifr
->ifr_interface_state
);
2771 case SIOCSIFPROBECONNECTIVITY
:
2772 if ((error
= priv_check_cred(kauth_cred_get(),
2773 PRIV_NET_INTERFACE_CONTROL
, 0)) != 0)
2775 error
= if_probe_connectivity(ifp
,
2776 ifr
->ifr_probe_connectivity
);
2778 case SIOCGIFPROBECONNECTIVITY
:
2779 if ((error
= priv_check_cred(kauth_cred_get(),
2780 PRIV_NET_INTERFACE_CONTROL
, 0)) != 0)
2782 if (ifp
->if_eflags
& IFEF_PROBE_CONNECTIVITY
)
2783 ifr
->ifr_probe_connectivity
= 1;
2785 ifr
->ifr_probe_connectivity
= 0;
2788 if ((ifp
->if_eflags
& (IFEF_ECN_ENABLE
|IFEF_ECN_DISABLE
)) ==
2790 ifr
->ifr_ecn_mode
= IFRTYPE_ECN_ENABLE
;
2791 else if ((ifp
->if_eflags
& (IFEF_ECN_ENABLE
|IFEF_ECN_DISABLE
)) ==
2793 ifr
->ifr_ecn_mode
= IFRTYPE_ECN_DISABLE
;
2795 ifr
->ifr_ecn_mode
= IFRTYPE_ECN_DEFAULT
;
2798 if (ifr
->ifr_ecn_mode
== IFRTYPE_ECN_DEFAULT
) {
2799 ifp
->if_eflags
&= ~(IFEF_ECN_ENABLE
|IFEF_ECN_DISABLE
);
2800 } else if (ifr
->ifr_ecn_mode
== IFRTYPE_ECN_ENABLE
) {
2801 ifp
->if_eflags
|= IFEF_ECN_ENABLE
;
2802 ifp
->if_eflags
&= ~IFEF_ECN_DISABLE
;
2803 } else if (ifr
->ifr_ecn_mode
== IFRTYPE_ECN_DISABLE
) {
2804 ifp
->if_eflags
|= IFEF_ECN_DISABLE
;
2805 ifp
->if_eflags
&= ~IFEF_ECN_ENABLE
;
2818 ifioctllocked(struct socket
*so
, u_long cmd
, caddr_t data
, struct proc
*p
)
2822 socket_unlock(so
, 0);
2823 error
= ifioctl(so
, cmd
, data
, p
);
2829 * Set/clear promiscuous mode on interface ifp based on the truth value
2830 * of pswitch. The calls are reference counted so that only the first
2831 * "on" request actually has an effect, as does the final "off" request.
2832 * Results are undefined if the "off" and "on" requests are not matched.
2835 ifnet_set_promiscuous(
2843 ifnet_lock_exclusive(ifp
);
2844 oldflags
= ifp
->if_flags
;
2845 ifp
->if_pcount
+= pswitch
? 1 : -1;
2847 if (ifp
->if_pcount
> 0)
2848 ifp
->if_flags
|= IFF_PROMISC
;
2850 ifp
->if_flags
&= ~IFF_PROMISC
;
2852 newflags
= ifp
->if_flags
;
2853 ifnet_lock_done(ifp
);
2855 if (newflags
!= oldflags
&& (newflags
& IFF_UP
) != 0) {
2856 error
= ifnet_ioctl(ifp
, 0, SIOCSIFFLAGS
, NULL
);
2860 ifnet_lock_exclusive(ifp
);
2862 ifp
->if_pcount
-= pswitch
? 1 : -1;
2863 if (ifp
->if_pcount
> 0)
2864 ifp
->if_flags
|= IFF_PROMISC
;
2866 ifp
->if_flags
&= ~IFF_PROMISC
;
2867 ifnet_lock_done(ifp
);
2871 if (newflags
!= oldflags
) {
2872 log(LOG_INFO
, "%s: promiscuous mode %s%s\n",
2874 (newflags
& IFF_PROMISC
) != 0 ? "enable" : "disable",
2875 error
!= 0 ? " failed" : " succeeded");
2881 * Return interface configuration
2882 * of system. List may be used
2883 * in later ioctl's (above) to get
2884 * other information.
2888 ifconf(u_long cmd
, user_addr_t ifrp
, int *ret_space
)
2890 struct ifnet
*ifp
= NULL
;
2895 net_thread_marks_t marks
;
2897 marks
= net_thread_marks_push(NET_THREAD_CKREQ_LLADDR
);
2900 * Zero the ifr buffer to make sure we don't
2901 * disclose the contents of the stack.
2903 bzero(&ifr
, sizeof (struct ifreq
));
2906 ifnet_head_lock_shared();
2907 for (ifp
= ifnet_head
.tqh_first
; space
> sizeof (ifr
) &&
2908 ifp
; ifp
= ifp
->if_link
.tqe_next
) {
2910 size_t ifnlen
, addrs
;
2912 ifnlen
= snprintf(workbuf
, sizeof (workbuf
),
2913 "%s", if_name(ifp
));
2914 if (ifnlen
+ 1 > sizeof (ifr
.ifr_name
)) {
2915 error
= ENAMETOOLONG
;
2918 strlcpy(ifr
.ifr_name
, workbuf
, IFNAMSIZ
);
2921 ifnet_lock_shared(ifp
);
2924 ifa
= ifp
->if_addrhead
.tqh_first
;
2925 for (; space
> sizeof (ifr
) && ifa
;
2926 ifa
= ifa
->ifa_link
.tqe_next
) {
2927 struct sockaddr
*sa
;
2930 struct sockaddr_dl sdl
;
2931 uint8_t buf
[SOCK_MAXADDRLEN
+ 1];
2935 * Make sure to accomodate the largest possible
2936 * size of SA(if_lladdr)->sa_len.
2938 _CASSERT(sizeof (u
) == (SOCK_MAXADDRLEN
+ 1));
2944 if (ifa
== ifp
->if_lladdr
) {
2945 VERIFY(sa
->sa_family
== AF_LINK
);
2946 bcopy(sa
, &u
, sa
->sa_len
);
2948 ifnet_guarded_lladdr_copy_bytes(ifp
,
2949 LLADDR(&u
.sdl
), u
.sdl
.sdl_alen
);
2954 if (cmd
== OSIOCGIFCONF32
|| cmd
== OSIOCGIFCONF64
) {
2955 struct osockaddr
*osa
=
2956 (struct osockaddr
*)(void *)&ifr
.ifr_addr
;
2958 osa
->sa_family
= sa
->sa_family
;
2959 error
= copyout((caddr_t
)&ifr
, ifrp
,
2961 ifrp
+= sizeof (struct ifreq
);
2962 } else if (sa
->sa_len
<= sizeof (*sa
)) {
2964 error
= copyout((caddr_t
)&ifr
, ifrp
,
2966 ifrp
+= sizeof (struct ifreq
);
2969 sizeof (ifr
) + sa
->sa_len
- sizeof (*sa
)) {
2973 space
-= sa
->sa_len
- sizeof (*sa
);
2974 error
= copyout((caddr_t
)&ifr
, ifrp
,
2975 sizeof (ifr
.ifr_name
));
2977 error
= copyout((caddr_t
)sa
, (ifrp
+
2978 offsetof(struct ifreq
, ifr_addr
)),
2981 ifrp
+= (sa
->sa_len
+ offsetof(struct ifreq
,
2987 space
-= sizeof (ifr
);
2989 ifnet_lock_done(ifp
);
2994 bzero((caddr_t
)&ifr
.ifr_addr
, sizeof (ifr
.ifr_addr
));
2995 error
= copyout((caddr_t
)&ifr
, ifrp
, sizeof (ifr
));
2998 space
-= sizeof (ifr
);
2999 ifrp
+= sizeof (struct ifreq
);
3003 *ret_space
-= space
;
3004 net_thread_marks_pop(marks
);
3009 * Just like if_promisc(), but for all-multicast-reception mode.
3012 if_allmulti(struct ifnet
*ifp
, int onswitch
)
3017 ifnet_lock_exclusive(ifp
);
3020 if (ifp
->if_amcount
++ == 0) {
3021 ifp
->if_flags
|= IFF_ALLMULTI
;
3025 if (ifp
->if_amcount
> 1) {
3028 ifp
->if_amcount
= 0;
3029 ifp
->if_flags
&= ~IFF_ALLMULTI
;
3033 ifnet_lock_done(ifp
);
3036 error
= ifnet_ioctl(ifp
, 0, SIOCSIFFLAGS
, NULL
);
3043 static struct ifmultiaddr
*
3046 struct ifmultiaddr
*ifma
;
3048 ifma
= (how
== M_WAITOK
) ? zalloc(ifma_zone
) :
3049 zalloc_noblock(ifma_zone
);
3052 bzero(ifma
, ifma_size
);
3053 lck_mtx_init(&ifma
->ifma_lock
, ifa_mtx_grp
, ifa_mtx_attr
);
3054 ifma
->ifma_debug
|= IFD_ALLOC
;
3055 if (ifma_debug
!= 0) {
3056 ifma
->ifma_debug
|= IFD_DEBUG
;
3057 ifma
->ifma_trace
= ifma_trace
;
3064 ifma_free(struct ifmultiaddr
*ifma
)
3068 if (ifma
->ifma_protospec
!= NULL
) {
3069 panic("%s: Protospec not NULL for ifma=%p", __func__
, ifma
);
3071 } else if ((ifma
->ifma_flags
& IFMAF_ANONYMOUS
) ||
3072 ifma
->ifma_anoncnt
!= 0) {
3073 panic("%s: Freeing ifma=%p with outstanding anon req",
3076 } else if (ifma
->ifma_debug
& IFD_ATTACHED
) {
3077 panic("%s: ifma=%p attached to ifma_ifp=%p is being freed",
3078 __func__
, ifma
, ifma
->ifma_ifp
);
3080 } else if (!(ifma
->ifma_debug
& IFD_ALLOC
)) {
3081 panic("%s: ifma %p cannot be freed", __func__
, ifma
);
3083 } else if (ifma
->ifma_refcount
!= 0) {
3084 panic("%s: non-zero refcount ifma=%p", __func__
, ifma
);
3086 } else if (ifma
->ifma_reqcnt
!= 0) {
3087 panic("%s: non-zero reqcnt ifma=%p", __func__
, ifma
);
3089 } else if (ifma
->ifma_ifp
!= NULL
) {
3090 panic("%s: non-NULL ifma_ifp=%p for ifma=%p", __func__
,
3091 ifma
->ifma_ifp
, ifma
);
3093 } else if (ifma
->ifma_ll
!= NULL
) {
3094 panic("%s: non-NULL ifma_ll=%p for ifma=%p", __func__
,
3095 ifma
->ifma_ll
, ifma
);
3098 ifma
->ifma_debug
&= ~IFD_ALLOC
;
3099 if ((ifma
->ifma_debug
& (IFD_DEBUG
| IFD_TRASHED
)) ==
3100 (IFD_DEBUG
| IFD_TRASHED
)) {
3101 lck_mtx_lock(&ifma_trash_lock
);
3102 TAILQ_REMOVE(&ifma_trash_head
, (struct ifmultiaddr_dbg
*)ifma
,
3104 lck_mtx_unlock(&ifma_trash_lock
);
3105 ifma
->ifma_debug
&= ~IFD_TRASHED
;
3109 if (ifma
->ifma_addr
!= NULL
) {
3110 FREE(ifma
->ifma_addr
, M_IFADDR
);
3111 ifma
->ifma_addr
= NULL
;
3113 lck_mtx_destroy(&ifma
->ifma_lock
, ifa_mtx_grp
);
3114 zfree(ifma_zone
, ifma
);
3118 ifma_trace(struct ifmultiaddr
*ifma
, int refhold
)
3120 struct ifmultiaddr_dbg
*ifma_dbg
= (struct ifmultiaddr_dbg
*)ifma
;
3125 if (!(ifma
->ifma_debug
& IFD_DEBUG
)) {
3126 panic("%s: ifma %p has no debug structure", __func__
, ifma
);
3130 cnt
= &ifma_dbg
->ifma_refhold_cnt
;
3131 tr
= ifma_dbg
->ifma_refhold
;
3133 cnt
= &ifma_dbg
->ifma_refrele_cnt
;
3134 tr
= ifma_dbg
->ifma_refrele
;
3137 idx
= atomic_add_16_ov(cnt
, 1) % IFMA_TRACE_HIST_SIZE
;
3138 ctrace_record(&tr
[idx
]);
3142 ifma_addref(struct ifmultiaddr
*ifma
, int locked
)
3147 IFMA_LOCK_ASSERT_HELD(ifma
);
3149 if (++ifma
->ifma_refcount
== 0) {
3150 panic("%s: ifma=%p wraparound refcnt", __func__
, ifma
);
3152 } else if (ifma
->ifma_trace
!= NULL
) {
3153 (*ifma
->ifma_trace
)(ifma
, TRUE
);
3160 ifma_remref(struct ifmultiaddr
*ifma
)
3162 struct ifmultiaddr
*ll
;
3166 if (ifma
->ifma_refcount
== 0) {
3167 panic("%s: ifma=%p negative refcnt", __func__
, ifma
);
3169 } else if (ifma
->ifma_trace
!= NULL
) {
3170 (*ifma
->ifma_trace
)(ifma
, FALSE
);
3173 --ifma
->ifma_refcount
;
3174 if (ifma
->ifma_refcount
> 0) {
3180 ifma
->ifma_ifp
= NULL
;
3181 ifma
->ifma_ll
= NULL
;
3183 ifma_free(ifma
); /* deallocate it */
3190 if_attach_ifma(struct ifnet
*ifp
, struct ifmultiaddr
*ifma
, int anon
)
3192 ifnet_lock_assert(ifp
, IFNET_LCK_ASSERT_EXCLUSIVE
);
3193 IFMA_LOCK_ASSERT_HELD(ifma
);
3195 if (ifma
->ifma_ifp
!= ifp
) {
3196 panic("%s: Mismatch ifma_ifp=%p != ifp=%p", __func__
,
3197 ifma
->ifma_ifp
, ifp
);
3199 } else if (ifma
->ifma_debug
& IFD_ATTACHED
) {
3200 panic("%s: Attempt to attach an already attached ifma=%p",
3203 } else if (anon
&& (ifma
->ifma_flags
& IFMAF_ANONYMOUS
)) {
3204 panic("%s: ifma=%p unexpected IFMAF_ANONYMOUS", __func__
, ifma
);
3206 } else if (ifma
->ifma_debug
& IFD_TRASHED
) {
3207 panic("%s: Attempt to reattach a detached ifma=%p",
3212 ifma
->ifma_reqcnt
++;
3213 VERIFY(ifma
->ifma_reqcnt
== 1);
3214 IFMA_ADDREF_LOCKED(ifma
);
3215 ifma
->ifma_debug
|= IFD_ATTACHED
;
3217 ifma
->ifma_anoncnt
++;
3218 VERIFY(ifma
->ifma_anoncnt
== 1);
3219 ifma
->ifma_flags
|= IFMAF_ANONYMOUS
;
3222 LIST_INSERT_HEAD(&ifp
->if_multiaddrs
, ifma
, ifma_link
);
3226 if_detach_ifma(struct ifnet
*ifp
, struct ifmultiaddr
*ifma
, int anon
)
3228 ifnet_lock_assert(ifp
, IFNET_LCK_ASSERT_EXCLUSIVE
);
3229 IFMA_LOCK_ASSERT_HELD(ifma
);
3231 if (ifma
->ifma_reqcnt
== 0) {
3232 panic("%s: ifma=%p negative reqcnt", __func__
, ifma
);
3234 } else if (anon
&& !(ifma
->ifma_flags
& IFMAF_ANONYMOUS
)) {
3235 panic("%s: ifma=%p missing IFMAF_ANONYMOUS", __func__
, ifma
);
3237 } else if (anon
&& ifma
->ifma_anoncnt
== 0) {
3238 panic("%s: ifma=%p negative anonreqcnt", __func__
, ifma
);
3240 } else if (ifma
->ifma_ifp
!= ifp
) {
3241 panic("%s: Mismatch ifma_ifp=%p, ifp=%p", __func__
,
3242 ifma
->ifma_ifp
, ifp
);
3247 --ifma
->ifma_anoncnt
;
3248 if (ifma
->ifma_anoncnt
> 0)
3250 ifma
->ifma_flags
&= ~IFMAF_ANONYMOUS
;
3253 --ifma
->ifma_reqcnt
;
3254 if (ifma
->ifma_reqcnt
> 0)
3257 if (ifma
->ifma_protospec
!= NULL
) {
3258 panic("%s: Protospec not NULL for ifma=%p", __func__
, ifma
);
3260 } else if ((ifma
->ifma_flags
& IFMAF_ANONYMOUS
) ||
3261 ifma
->ifma_anoncnt
!= 0) {
3262 panic("%s: Detaching ifma=%p with outstanding anon req",
3265 } else if (!(ifma
->ifma_debug
& IFD_ATTACHED
)) {
3266 panic("%s: Attempt to detach an unattached address ifma=%p",
3269 } else if (ifma
->ifma_debug
& IFD_TRASHED
) {
3270 panic("%s: ifma %p is already in trash list", __func__
, ifma
);
3275 * NOTE: Caller calls IFMA_REMREF
3277 ifma
->ifma_debug
&= ~IFD_ATTACHED
;
3278 LIST_REMOVE(ifma
, ifma_link
);
3279 if (LIST_EMPTY(&ifp
->if_multiaddrs
))
3280 ifp
->if_updatemcasts
= 0;
3282 if (ifma
->ifma_debug
& IFD_DEBUG
) {
3283 /* Become a regular mutex, just in case */
3284 IFMA_CONVERT_LOCK(ifma
);
3285 lck_mtx_lock(&ifma_trash_lock
);
3286 TAILQ_INSERT_TAIL(&ifma_trash_head
,
3287 (struct ifmultiaddr_dbg
*)ifma
, ifma_trash_link
);
3288 lck_mtx_unlock(&ifma_trash_lock
);
3289 ifma
->ifma_debug
|= IFD_TRASHED
;
3296 * Find an ifmultiaddr that matches a socket address on an interface.
3298 * Caller is responsible for holding the ifnet_lock while calling
3302 if_addmulti_doesexist(struct ifnet
*ifp
, const struct sockaddr
*sa
,
3303 struct ifmultiaddr
**retifma
, int anon
)
3305 struct ifmultiaddr
*ifma
;
3307 for (ifma
= LIST_FIRST(&ifp
->if_multiaddrs
); ifma
!= NULL
;
3308 ifma
= LIST_NEXT(ifma
, ifma_link
)) {
3309 IFMA_LOCK_SPIN(ifma
);
3310 if (!equal(sa
, ifma
->ifma_addr
)) {
3315 VERIFY(!(ifma
->ifma_flags
& IFMAF_ANONYMOUS
) ||
3316 ifma
->ifma_anoncnt
!= 0);
3317 VERIFY((ifma
->ifma_flags
& IFMAF_ANONYMOUS
) ||
3318 ifma
->ifma_anoncnt
== 0);
3319 ifma
->ifma_anoncnt
++;
3320 if (!(ifma
->ifma_flags
& IFMAF_ANONYMOUS
)) {
3321 VERIFY(ifma
->ifma_anoncnt
== 1);
3322 ifma
->ifma_flags
|= IFMAF_ANONYMOUS
;
3325 if (!anon
|| ifma
->ifma_anoncnt
== 1) {
3326 ifma
->ifma_reqcnt
++;
3327 VERIFY(ifma
->ifma_reqcnt
> 1);
3329 if (retifma
!= NULL
) {
3331 IFMA_ADDREF_LOCKED(ifma
);
3340 * Radar 3642395, make sure all multicasts are in a standard format.
3342 static struct sockaddr
*
3343 copy_and_normalize(const struct sockaddr
*original
)
3346 const u_char
*aptr
= NULL
;
3347 struct sockaddr
*copy
= NULL
;
3348 struct sockaddr_dl
*sdl_new
= NULL
;
3351 if (original
->sa_family
!= AF_LINK
&&
3352 original
->sa_family
!= AF_UNSPEC
) {
3353 /* Just make a copy */
3354 MALLOC(copy
, struct sockaddr
*, original
->sa_len
,
3355 M_IFADDR
, M_WAITOK
);
3357 bcopy(original
, copy
, original
->sa_len
);
3361 switch (original
->sa_family
) {
3363 const struct sockaddr_dl
*sdl_original
=
3364 (struct sockaddr_dl
*)(uintptr_t)(size_t)original
;
3366 if (sdl_original
->sdl_nlen
+ sdl_original
->sdl_alen
+
3367 sdl_original
->sdl_slen
+
3368 offsetof(struct sockaddr_dl
, sdl_data
) >
3369 sdl_original
->sdl_len
)
3372 alen
= sdl_original
->sdl_alen
;
3373 aptr
= CONST_LLADDR(sdl_original
);
3378 if (original
->sa_len
< ETHER_ADDR_LEN
+
3379 offsetof(struct sockaddr
, sa_data
)) {
3383 alen
= ETHER_ADDR_LEN
;
3384 aptr
= (const u_char
*)original
->sa_data
;
3389 if (alen
== 0 || aptr
== NULL
)
3392 len
= alen
+ offsetof(struct sockaddr_dl
, sdl_data
);
3393 MALLOC(sdl_new
, struct sockaddr_dl
*, len
, M_IFADDR
, M_WAITOK
);
3395 if (sdl_new
!= NULL
) {
3396 bzero(sdl_new
, len
);
3397 sdl_new
->sdl_len
= len
;
3398 sdl_new
->sdl_family
= AF_LINK
;
3399 sdl_new
->sdl_alen
= alen
;
3400 bcopy(aptr
, LLADDR(sdl_new
), alen
);
3403 return ((struct sockaddr
*)sdl_new
);
3407 * Network-layer protocol domains which hold references to the underlying
3408 * link-layer record must use this routine.
3411 if_addmulti(struct ifnet
*ifp
, const struct sockaddr
*sa
,
3412 struct ifmultiaddr
**retifma
)
3414 return (if_addmulti_common(ifp
, sa
, retifma
, 0));
3418 * Anything other than network-layer protocol domains which hold references
3419 * to the underlying link-layer record must use this routine: SIOCADDMULTI
3420 * ioctl, ifnet_add_multicast(), if_bond.
3423 if_addmulti_anon(struct ifnet
*ifp
, const struct sockaddr
*sa
,
3424 struct ifmultiaddr
**retifma
)
3426 return (if_addmulti_common(ifp
, sa
, retifma
, 1));
3430 * Register an additional multicast address with a network interface.
3432 * - If the address is already present, bump the reference count on the
3433 * address and return.
3434 * - If the address is not link-layer, look up a link layer address.
3435 * - Allocate address structures for one or both addresses, and attach to the
3436 * multicast address list on the interface. If automatically adding a link
3437 * layer address, the protocol address will own a reference to the link
3438 * layer address, to be freed when it is freed.
3439 * - Notify the network device driver of an addition to the multicast address
3442 * 'sa' points to caller-owned memory with the desired multicast address.
3444 * 'retifma' will be used to return a pointer to the resulting multicast
3445 * address reference, if desired.
3447 * 'anon' indicates a link-layer address with no protocol address reference
3448 * made to it. Anything other than network-layer protocol domain requests
3449 * are considered as anonymous.
3452 if_addmulti_common(struct ifnet
*ifp
, const struct sockaddr
*sa
,
3453 struct ifmultiaddr
**retifma
, int anon
)
3455 struct sockaddr_storage storage
;
3456 struct sockaddr
*llsa
= NULL
;
3457 struct sockaddr
*dupsa
= NULL
;
3458 int error
= 0, ll_firstref
= 0, lladdr
;
3459 struct ifmultiaddr
*ifma
= NULL
;
3460 struct ifmultiaddr
*llifma
= NULL
;
3462 /* Only AF_UNSPEC/AF_LINK is allowed for an "anonymous" address */
3463 VERIFY(!anon
|| sa
->sa_family
== AF_UNSPEC
||
3464 sa
->sa_family
== AF_LINK
);
3466 /* If sa is a AF_LINK or AF_UNSPEC, duplicate and normalize it */
3467 if (sa
->sa_family
== AF_LINK
|| sa
->sa_family
== AF_UNSPEC
) {
3468 dupsa
= copy_and_normalize(sa
);
3469 if (dupsa
== NULL
) {
3476 ifnet_lock_exclusive(ifp
);
3477 if (!(ifp
->if_flags
& IFF_MULTICAST
)) {
3478 error
= EADDRNOTAVAIL
;
3479 ifnet_lock_done(ifp
);
3483 /* If the address is already present, return a new reference to it */
3484 error
= if_addmulti_doesexist(ifp
, sa
, retifma
, anon
);
3485 ifnet_lock_done(ifp
);
3490 * The address isn't already present; give the link layer a chance
3491 * to accept/reject it, and also find out which AF_LINK address this
3492 * maps to, if it isn't one already.
3494 error
= dlil_resolve_multi(ifp
, sa
, (struct sockaddr
*)&storage
,
3496 if (error
== 0 && storage
.ss_len
!= 0) {
3497 llsa
= copy_and_normalize((struct sockaddr
*)&storage
);
3503 llifma
= ifma_alloc(M_WAITOK
);
3504 if (llifma
== NULL
) {
3510 /* to be similar to FreeBSD */
3511 if (error
== EOPNOTSUPP
)
3513 else if (error
!= 0)
3516 /* Allocate while we aren't holding any locks */
3517 if (dupsa
== NULL
) {
3518 dupsa
= copy_and_normalize(sa
);
3519 if (dupsa
== NULL
) {
3524 ifma
= ifma_alloc(M_WAITOK
);
3530 ifnet_lock_exclusive(ifp
);
3532 * Check again for the matching multicast.
3534 error
= if_addmulti_doesexist(ifp
, sa
, retifma
, anon
);
3536 ifnet_lock_done(ifp
);
3540 if (llifma
!= NULL
) {
3541 VERIFY(!anon
); /* must not get here if "anonymous" */
3542 if (if_addmulti_doesexist(ifp
, llsa
, &ifma
->ifma_ll
, 0) == 0) {
3543 FREE(llsa
, M_IFADDR
);
3547 VERIFY(ifma
->ifma_ll
->ifma_ifp
== ifp
);
3550 llifma
->ifma_addr
= llsa
;
3551 llifma
->ifma_ifp
= ifp
;
3553 if_attach_ifma(ifp
, llifma
, 0);
3554 /* add extra refcnt for ifma */
3555 IFMA_ADDREF_LOCKED(llifma
);
3556 IFMA_UNLOCK(llifma
);
3557 ifma
->ifma_ll
= llifma
;
3561 /* "anonymous" request should not result in network address */
3562 VERIFY(!anon
|| ifma
->ifma_ll
== NULL
);
3564 ifma
->ifma_addr
= dupsa
;
3565 ifma
->ifma_ifp
= ifp
;
3567 if_attach_ifma(ifp
, ifma
, anon
);
3568 IFMA_ADDREF_LOCKED(ifma
); /* for this routine */
3569 if (retifma
!= NULL
) {
3571 IFMA_ADDREF_LOCKED(*retifma
); /* for caller */
3573 lladdr
= (ifma
->ifma_addr
->sa_family
== AF_UNSPEC
||
3574 ifma
->ifma_addr
->sa_family
== AF_LINK
);
3576 ifnet_lock_done(ifp
);
3578 rt_newmaddrmsg(RTM_NEWMADDR
, ifma
);
3579 IFMA_REMREF(ifma
); /* for this routine */
3582 * We are certain we have added something, so call down to the
3583 * interface to let them know about it. Do this only for newly-
3584 * added AF_LINK/AF_UNSPEC address in the if_multiaddrs set.
3586 if (lladdr
|| ll_firstref
)
3587 (void) ifnet_ioctl(ifp
, 0, SIOCADDMULTI
, NULL
);
3589 if (ifp
->if_updatemcasts
> 0)
3590 ifp
->if_updatemcasts
= 0;
3598 FREE(dupsa
, M_IFADDR
);
3602 FREE(llsa
, M_IFADDR
);
3608 * Delete a multicast group membership by network-layer group address.
3609 * This routine is deprecated.
3612 if_delmulti(struct ifnet
*ifp
, const struct sockaddr
*sa
)
3614 return (if_delmulti_common(NULL
, ifp
, sa
, 0));
3618 * Delete a multicast group membership by group membership pointer.
3619 * Network-layer protocol domains must use this routine.
3622 if_delmulti_ifma(struct ifmultiaddr
*ifma
)
3624 return (if_delmulti_common(ifma
, NULL
, NULL
, 0));
3628 * Anything other than network-layer protocol domains which hold references
3629 * to the underlying link-layer record must use this routine: SIOCDELMULTI
3630 * ioctl, ifnet_remove_multicast(), if_bond.
3633 if_delmulti_anon(struct ifnet
*ifp
, const struct sockaddr
*sa
)
3635 return (if_delmulti_common(NULL
, ifp
, sa
, 1));
3639 * Delete a multicast group membership by network-layer group address.
3641 * Returns ENOENT if the entry could not be found.
3644 if_delmulti_common(struct ifmultiaddr
*ifma
, struct ifnet
*ifp
,
3645 const struct sockaddr
*sa
, int anon
)
3647 struct sockaddr
*dupsa
= NULL
;
3648 int lastref
, ll_lastref
= 0, lladdr
;
3649 struct ifmultiaddr
*ll
= NULL
;
3651 /* sanity check for callers */
3652 VERIFY(ifma
!= NULL
|| (ifp
!= NULL
&& sa
!= NULL
));
3655 ifp
= ifma
->ifma_ifp
;
3658 (sa
->sa_family
== AF_LINK
|| sa
->sa_family
== AF_UNSPEC
)) {
3659 dupsa
= copy_and_normalize(sa
);
3665 ifnet_lock_exclusive(ifp
);
3667 for (ifma
= LIST_FIRST(&ifp
->if_multiaddrs
); ifma
!= NULL
;
3668 ifma
= LIST_NEXT(ifma
, ifma_link
)) {
3670 if (!equal(sa
, ifma
->ifma_addr
) ||
3671 (anon
&& !(ifma
->ifma_flags
& IFMAF_ANONYMOUS
))) {
3672 VERIFY(!(ifma
->ifma_flags
& IFMAF_ANONYMOUS
) ||
3673 ifma
->ifma_anoncnt
!= 0);
3677 /* found; keep it locked */
3682 FREE(dupsa
, M_IFADDR
);
3683 ifnet_lock_done(ifp
);
3689 IFMA_LOCK_ASSERT_HELD(ifma
);
3690 IFMA_ADDREF_LOCKED(ifma
); /* for this routine */
3691 lastref
= if_detach_ifma(ifp
, ifma
, anon
);
3692 VERIFY(!lastref
|| (!(ifma
->ifma_debug
& IFD_ATTACHED
) &&
3693 ifma
->ifma_reqcnt
== 0));
3694 VERIFY(!anon
|| ifma
->ifma_ll
== NULL
);
3696 lladdr
= (ifma
->ifma_addr
->sa_family
== AF_UNSPEC
||
3697 ifma
->ifma_addr
->sa_family
== AF_LINK
);
3699 if (lastref
&& ll
!= NULL
) {
3701 ll_lastref
= if_detach_ifma(ifp
, ll
, 0);
3704 ifnet_lock_done(ifp
);
3707 rt_newmaddrmsg(RTM_DELMADDR
, ifma
);
3709 if ((ll
== NULL
&& lastref
&& lladdr
) || ll_lastref
) {
3711 * Make sure the interface driver is notified in the
3712 * case of a link layer mcast group being left. Do
3713 * this only for a AF_LINK/AF_UNSPEC address that has
3714 * been removed from the if_multiaddrs set.
3716 ifnet_ioctl(ifp
, 0, SIOCDELMULTI
, NULL
);
3720 IFMA_REMREF(ifma
); /* for if_multiaddrs list */
3722 IFMA_REMREF(ll
); /* for if_multiaddrs list */
3724 IFMA_REMREF(ifma
); /* for this routine */
3726 FREE(dupsa
, M_IFADDR
);
3732 * Shutdown all network activity. Used boot() when halting
3742 if (ifnet_list_get_all(IFNET_FAMILY_ANY
, &ifp
, &count
) == 0) {
3743 for (i
= 0; i
< count
; i
++) {
3745 dlil_proto_unplumb_all(ifp
[i
]);
3747 ifnet_list_free(ifp
);
3754 * Delete Routes for a Network Interface
3756 * Called for each routing entry via the rnh->rnh_walktree() call above
3757 * to delete all route entries referencing a detaching network interface.
3760 * rn pointer to node in the routing table
3761 * arg argument passed to rnh->rnh_walktree() - detaching interface
3765 * errno failed - reason indicated
3769 if_rtdel(struct radix_node
*rn
, void *arg
)
3771 struct rtentry
*rt
= (struct rtentry
*)rn
;
3772 struct ifnet
*ifp
= arg
;
3778 * Checking against RTF_UP protects against walktree
3779 * recursion problems with cloned routes.
3782 if (rt
->rt_ifp
== ifp
&& (rt
->rt_flags
& RTF_UP
)) {
3784 * Safe to drop rt_lock and use rt_key, rt_gateway,
3785 * since holding rnh_lock here prevents another thread
3786 * from calling rt_setgate() on this route.
3789 err
= rtrequest_locked(RTM_DELETE
, rt_key(rt
), rt
->rt_gateway
,
3790 rt_mask(rt
), rt
->rt_flags
, NULL
);
3792 log(LOG_WARNING
, "if_rtdel: error %d\n", err
);
3801 * Removes routing table reference to a given interface
3802 * for a given protocol family
3805 if_rtproto_del(struct ifnet
*ifp
, int protocol
)
3807 struct radix_node_head
*rnh
;
3809 if ((protocol
<= AF_MAX
) && (protocol
>= 0) &&
3810 ((rnh
= rt_tables
[protocol
]) != NULL
) && (ifp
!= NULL
)) {
3811 lck_mtx_lock(rnh_lock
);
3812 (void) rnh
->rnh_walktree(rnh
, if_rtdel
, ifp
);
3813 lck_mtx_unlock(rnh_lock
);
3818 if_rtmtu(struct radix_node
*rn
, void *arg
)
3820 struct rtentry
*rt
= (struct rtentry
*)rn
;
3821 struct ifnet
*ifp
= arg
;
3824 if (rt
->rt_ifp
== ifp
) {
3826 * Update the MTU of this entry only if the MTU
3827 * has not been locked (RTV_MTU is not set) and
3828 * if it was non-zero to begin with.
3830 if (!(rt
->rt_rmx
.rmx_locks
& RTV_MTU
) && rt
->rt_rmx
.rmx_mtu
)
3831 rt
->rt_rmx
.rmx_mtu
= ifp
->if_mtu
;
3839 * Update the MTU metric of all route entries in all protocol tables
3840 * associated with a particular interface; this is called when the
3841 * MTU of that interface has changed.
3844 void if_rtmtu_update(struct ifnet
*ifp
)
3846 struct radix_node_head
*rnh
;
3849 for (p
= 0; p
< AF_MAX
+ 1; p
++) {
3850 if ((rnh
= rt_tables
[p
]) == NULL
)
3853 lck_mtx_lock(rnh_lock
);
3854 (void) rnh
->rnh_walktree(rnh
, if_rtmtu
, ifp
);
3855 lck_mtx_unlock(rnh_lock
);
3857 routegenid_update();
3860 __private_extern__
void
3861 if_data_internal_to_if_data(struct ifnet
*ifp
,
3862 const struct if_data_internal
*if_data_int
, struct if_data
*if_data
)
3865 #define COPYFIELD(fld) if_data->fld = if_data_int->fld
3866 #define COPYFIELD32(fld) if_data->fld = (u_int32_t)(if_data_int->fld)
3867 /* compiler will cast down to 32-bit */
3868 #define COPYFIELD32_ATOMIC(fld) do { \
3869 atomic_get_64(if_data->fld, \
3870 (u_int64_t *)(void *)(uintptr_t)&if_data_int->fld); \
3873 COPYFIELD(ifi_type
);
3874 COPYFIELD(ifi_typelen
);
3875 COPYFIELD(ifi_physical
);
3876 COPYFIELD(ifi_addrlen
);
3877 COPYFIELD(ifi_hdrlen
);
3878 COPYFIELD(ifi_recvquota
);
3879 COPYFIELD(ifi_xmitquota
);
3880 if_data
->ifi_unused1
= 0;
3882 COPYFIELD(ifi_metric
);
3883 if (if_data_int
->ifi_baudrate
& 0xFFFFFFFF00000000LL
) {
3884 if_data
->ifi_baudrate
= 0xFFFFFFFF;
3886 COPYFIELD32(ifi_baudrate
);
3889 COPYFIELD32_ATOMIC(ifi_ipackets
);
3890 COPYFIELD32_ATOMIC(ifi_ierrors
);
3891 COPYFIELD32_ATOMIC(ifi_opackets
);
3892 COPYFIELD32_ATOMIC(ifi_oerrors
);
3893 COPYFIELD32_ATOMIC(ifi_collisions
);
3894 COPYFIELD32_ATOMIC(ifi_ibytes
);
3895 COPYFIELD32_ATOMIC(ifi_obytes
);
3896 COPYFIELD32_ATOMIC(ifi_imcasts
);
3897 COPYFIELD32_ATOMIC(ifi_omcasts
);
3898 COPYFIELD32_ATOMIC(ifi_iqdrops
);
3899 COPYFIELD32_ATOMIC(ifi_noproto
);
3901 COPYFIELD(ifi_recvtiming
);
3902 COPYFIELD(ifi_xmittiming
);
3904 if_data
->ifi_lastchange
.tv_sec
= if_data_int
->ifi_lastchange
.tv_sec
;
3905 if_data
->ifi_lastchange
.tv_usec
= if_data_int
->ifi_lastchange
.tv_usec
;
3907 if_data
->ifi_lastchange
.tv_sec
+= boottime_sec();
3909 if_data
->ifi_unused2
= 0;
3910 COPYFIELD(ifi_hwassist
);
3911 if_data
->ifi_reserved1
= 0;
3912 if_data
->ifi_reserved2
= 0;
3913 #undef COPYFIELD32_ATOMIC
3918 __private_extern__
void
3919 if_data_internal_to_if_data64(struct ifnet
*ifp
,
3920 const struct if_data_internal
*if_data_int
,
3921 struct if_data64
*if_data64
)
3924 #define COPYFIELD64(fld) if_data64->fld = if_data_int->fld
3925 #define COPYFIELD64_ATOMIC(fld) do { \
3926 atomic_get_64(if_data64->fld, \
3927 (u_int64_t *)(void *)(uintptr_t)&if_data_int->fld); \
3930 COPYFIELD64(ifi_type
);
3931 COPYFIELD64(ifi_typelen
);
3932 COPYFIELD64(ifi_physical
);
3933 COPYFIELD64(ifi_addrlen
);
3934 COPYFIELD64(ifi_hdrlen
);
3935 COPYFIELD64(ifi_recvquota
);
3936 COPYFIELD64(ifi_xmitquota
);
3937 if_data64
->ifi_unused1
= 0;
3938 COPYFIELD64(ifi_mtu
);
3939 COPYFIELD64(ifi_metric
);
3940 COPYFIELD64(ifi_baudrate
);
3942 COPYFIELD64_ATOMIC(ifi_ipackets
);
3943 COPYFIELD64_ATOMIC(ifi_ierrors
);
3944 COPYFIELD64_ATOMIC(ifi_opackets
);
3945 COPYFIELD64_ATOMIC(ifi_oerrors
);
3946 COPYFIELD64_ATOMIC(ifi_collisions
);
3947 COPYFIELD64_ATOMIC(ifi_ibytes
);
3948 COPYFIELD64_ATOMIC(ifi_obytes
);
3949 COPYFIELD64_ATOMIC(ifi_imcasts
);
3950 COPYFIELD64_ATOMIC(ifi_omcasts
);
3951 COPYFIELD64_ATOMIC(ifi_iqdrops
);
3952 COPYFIELD64_ATOMIC(ifi_noproto
);
3954 /* Note these two fields are actually 32 bit, so doing COPYFIELD64_ATOMIC will
3955 * cause them to be misaligned
3957 COPYFIELD64(ifi_recvtiming
);
3958 COPYFIELD64(ifi_xmittiming
);
3960 if_data64
->ifi_lastchange
.tv_sec
= if_data_int
->ifi_lastchange
.tv_sec
;
3961 if_data64
->ifi_lastchange
.tv_usec
= if_data_int
->ifi_lastchange
.tv_usec
;
3963 if_data64
->ifi_lastchange
.tv_sec
+= boottime_sec();
3968 __private_extern__
void
3969 if_copy_traffic_class(struct ifnet
*ifp
,
3970 struct if_traffic_class
*if_tc
)
3972 #define COPY_IF_TC_FIELD64_ATOMIC(fld) do { \
3973 atomic_get_64(if_tc->fld, \
3974 (u_int64_t *)(void *)(uintptr_t)&ifp->if_tc.fld); \
3977 bzero(if_tc
, sizeof (*if_tc
));
3978 COPY_IF_TC_FIELD64_ATOMIC(ifi_ibepackets
);
3979 COPY_IF_TC_FIELD64_ATOMIC(ifi_ibebytes
);
3980 COPY_IF_TC_FIELD64_ATOMIC(ifi_obepackets
);
3981 COPY_IF_TC_FIELD64_ATOMIC(ifi_obebytes
);
3982 COPY_IF_TC_FIELD64_ATOMIC(ifi_ibkpackets
);
3983 COPY_IF_TC_FIELD64_ATOMIC(ifi_ibkbytes
);
3984 COPY_IF_TC_FIELD64_ATOMIC(ifi_obkpackets
);
3985 COPY_IF_TC_FIELD64_ATOMIC(ifi_obkbytes
);
3986 COPY_IF_TC_FIELD64_ATOMIC(ifi_ivipackets
);
3987 COPY_IF_TC_FIELD64_ATOMIC(ifi_ivibytes
);
3988 COPY_IF_TC_FIELD64_ATOMIC(ifi_ovipackets
);
3989 COPY_IF_TC_FIELD64_ATOMIC(ifi_ovibytes
);
3990 COPY_IF_TC_FIELD64_ATOMIC(ifi_ivopackets
);
3991 COPY_IF_TC_FIELD64_ATOMIC(ifi_ivobytes
);
3992 COPY_IF_TC_FIELD64_ATOMIC(ifi_ovopackets
);
3993 COPY_IF_TC_FIELD64_ATOMIC(ifi_ovobytes
);
3994 COPY_IF_TC_FIELD64_ATOMIC(ifi_ipvpackets
);
3995 COPY_IF_TC_FIELD64_ATOMIC(ifi_ipvbytes
);
3996 COPY_IF_TC_FIELD64_ATOMIC(ifi_opvpackets
);
3997 COPY_IF_TC_FIELD64_ATOMIC(ifi_opvbytes
);
3999 #undef COPY_IF_TC_FIELD64_ATOMIC
4003 if_copy_data_extended(struct ifnet
*ifp
, struct if_data_extended
*if_de
)
4005 #define COPY_IF_DE_FIELD64_ATOMIC(fld) do { \
4006 atomic_get_64(if_de->fld, \
4007 (u_int64_t *)(void *)(uintptr_t)&ifp->if_data.fld); \
4010 bzero(if_de
, sizeof (*if_de
));
4011 COPY_IF_DE_FIELD64_ATOMIC(ifi_alignerrs
);
4012 COPY_IF_DE_FIELD64_ATOMIC(ifi_dt_bytes
);
4013 COPY_IF_DE_FIELD64_ATOMIC(ifi_fpackets
);
4014 COPY_IF_DE_FIELD64_ATOMIC(ifi_fbytes
);
4016 #undef COPY_IF_DE_FIELD64_ATOMIC
4020 if_copy_packet_stats(struct ifnet
*ifp
, struct if_packet_stats
*if_ps
)
4022 #define COPY_IF_PS_TCP_FIELD64_ATOMIC(fld) do { \
4023 atomic_get_64(if_ps->ifi_tcp_##fld, \
4024 (u_int64_t *)(void *)(uintptr_t)&ifp->if_tcp_stat->fld); \
4027 #define COPY_IF_PS_UDP_FIELD64_ATOMIC(fld) do { \
4028 atomic_get_64(if_ps->ifi_udp_##fld, \
4029 (u_int64_t *)(void *)(uintptr_t)&ifp->if_udp_stat->fld); \
4032 COPY_IF_PS_TCP_FIELD64_ATOMIC(badformat
);
4033 COPY_IF_PS_TCP_FIELD64_ATOMIC(unspecv6
);
4034 COPY_IF_PS_TCP_FIELD64_ATOMIC(synfin
);
4035 COPY_IF_PS_TCP_FIELD64_ATOMIC(badformatipsec
);
4036 COPY_IF_PS_TCP_FIELD64_ATOMIC(noconnnolist
);
4037 COPY_IF_PS_TCP_FIELD64_ATOMIC(noconnlist
);
4038 COPY_IF_PS_TCP_FIELD64_ATOMIC(listbadsyn
);
4039 COPY_IF_PS_TCP_FIELD64_ATOMIC(icmp6unreach
);
4040 COPY_IF_PS_TCP_FIELD64_ATOMIC(deprecate6
);
4041 COPY_IF_PS_TCP_FIELD64_ATOMIC(ooopacket
);
4042 COPY_IF_PS_TCP_FIELD64_ATOMIC(rstinsynrcv
);
4043 COPY_IF_PS_TCP_FIELD64_ATOMIC(dospacket
);
4044 COPY_IF_PS_TCP_FIELD64_ATOMIC(cleanup
);
4045 COPY_IF_PS_TCP_FIELD64_ATOMIC(synwindow
);
4047 COPY_IF_PS_UDP_FIELD64_ATOMIC(port_unreach
);
4048 COPY_IF_PS_UDP_FIELD64_ATOMIC(faithprefix
);
4049 COPY_IF_PS_UDP_FIELD64_ATOMIC(port0
);
4050 COPY_IF_PS_UDP_FIELD64_ATOMIC(badlength
);
4051 COPY_IF_PS_UDP_FIELD64_ATOMIC(badchksum
);
4052 COPY_IF_PS_UDP_FIELD64_ATOMIC(badmcast
);
4053 COPY_IF_PS_UDP_FIELD64_ATOMIC(cleanup
);
4054 COPY_IF_PS_UDP_FIELD64_ATOMIC(badipsec
);
4056 #undef COPY_IF_PS_TCP_FIELD64_ATOMIC
4057 #undef COPY_IF_PS_UDP_FIELD64_ATOMIC
4061 if_copy_rxpoll_stats(struct ifnet
*ifp
, struct if_rxpoll_stats
*if_rs
)
4063 bzero(if_rs
, sizeof (*if_rs
));
4064 if (!(ifp
->if_eflags
& IFEF_RXPOLL
) || !ifnet_is_attached(ifp
, 1))
4067 /* by now, ifnet will stay attached so if_inp must be valid */
4068 VERIFY(ifp
->if_inp
!= NULL
);
4069 bcopy(&ifp
->if_inp
->pstats
, if_rs
, sizeof (*if_rs
));
4071 /* Release the IO refcnt */
4072 ifnet_decr_iorefcnt(ifp
);
4076 ifa_remref(struct ifaddr
*ifa
, int locked
)
4081 IFA_LOCK_ASSERT_HELD(ifa
);
4083 if (ifa
->ifa_refcnt
== 0)
4084 panic("%s: ifa %p negative refcnt\n", __func__
, ifa
);
4085 else if (ifa
->ifa_trace
!= NULL
)
4086 (*ifa
->ifa_trace
)(ifa
, FALSE
);
4087 if (--ifa
->ifa_refcnt
== 0) {
4088 if (ifa
->ifa_debug
& IFD_ATTACHED
)
4089 panic("ifa %p attached to ifp is being freed\n", ifa
);
4091 * Some interface addresses are allocated either statically
4092 * or carved out of a larger block. Only free it if it was
4093 * allocated via MALLOC or via the corresponding per-address
4094 * family allocator. Otherwise, leave it alone.
4096 if (ifa
->ifa_debug
& IFD_ALLOC
) {
4097 if (ifa
->ifa_free
== NULL
) {
4099 FREE(ifa
, M_IFADDR
);
4101 /* Become a regular mutex */
4102 IFA_CONVERT_LOCK(ifa
);
4103 /* callee will unlock */
4104 (*ifa
->ifa_free
)(ifa
);
4112 if (!locked
&& ifa
!= NULL
)
4119 ifa_addref(struct ifaddr
*ifa
, int locked
)
4124 IFA_LOCK_ASSERT_HELD(ifa
);
4126 if (++ifa
->ifa_refcnt
== 0) {
4127 panic("%s: ifa %p wraparound refcnt\n", __func__
, ifa
);
4129 } else if (ifa
->ifa_trace
!= NULL
) {
4130 (*ifa
->ifa_trace
)(ifa
, TRUE
);
4137 ifa_lock_init(struct ifaddr
*ifa
)
4139 lck_mtx_init(&ifa
->ifa_lock
, ifa_mtx_grp
, ifa_mtx_attr
);
4143 ifa_lock_destroy(struct ifaddr
*ifa
)
4145 IFA_LOCK_ASSERT_NOTHELD(ifa
);
4146 lck_mtx_destroy(&ifa
->ifa_lock
, ifa_mtx_grp
);
4152 * The switch statement below does nothing at runtime, as it serves as a
4153 * compile time check to ensure that all of the socket 'i' ioctls (those
4154 * in the 'i' group going thru soo_ioctl) that are made available by the
4155 * networking stack is unique. This works as long as this routine gets
4156 * updated each time a new interface ioctl gets added.
4158 * Any failures at compile time indicates duplicated ioctl values.
4160 static __attribute__((unused
)) void
4161 ifioctl_cassert(void)
4164 * This is equivalent to _CASSERT() and the compiler wouldn't
4165 * generate any instructions, thus for compile time only.
4167 switch ((u_long
)0) {
4170 /* bsd/net/if_ppp.h */
4172 case SIOCGPPPCSTATS
:
4175 /* bsd/netinet6/in6_var.h */
4176 case SIOCSIFADDR_IN6
:
4177 case SIOCGIFADDR_IN6
:
4178 case SIOCSIFDSTADDR_IN6
:
4179 case SIOCSIFNETMASK_IN6
:
4180 case SIOCGIFDSTADDR_IN6
:
4181 case SIOCGIFNETMASK_IN6
:
4182 case SIOCDIFADDR_IN6
:
4183 case SIOCAIFADDR_IN6_32
:
4184 case SIOCAIFADDR_IN6_64
:
4185 case SIOCSIFPHYADDR_IN6_32
:
4186 case SIOCSIFPHYADDR_IN6_64
:
4187 case SIOCGIFPSRCADDR_IN6
:
4188 case SIOCGIFPDSTADDR_IN6
:
4189 case SIOCGIFAFLAG_IN6
:
4190 case SIOCGDRLST_IN6_32
:
4191 case SIOCGDRLST_IN6_64
:
4192 case SIOCGPRLST_IN6_32
:
4193 case SIOCGPRLST_IN6_64
:
4194 case OSIOCGIFINFO_IN6
:
4195 case SIOCGIFINFO_IN6
:
4196 case SIOCSNDFLUSH_IN6
:
4197 case SIOCGNBRINFO_IN6_32
:
4198 case SIOCGNBRINFO_IN6_64
:
4199 case SIOCSPFXFLUSH_IN6
:
4200 case SIOCSRTRFLUSH_IN6
:
4201 case SIOCGIFALIFETIME_IN6
:
4202 case SIOCSIFALIFETIME_IN6
:
4203 case SIOCGIFSTAT_IN6
:
4204 case SIOCGIFSTAT_ICMP6
:
4205 case SIOCSDEFIFACE_IN6_32
:
4206 case SIOCSDEFIFACE_IN6_64
:
4207 case SIOCGDEFIFACE_IN6_32
:
4208 case SIOCGDEFIFACE_IN6_64
:
4209 case SIOCSIFINFO_FLAGS
:
4212 case SIOCGSCOPE6DEF
:
4213 case SIOCSIFPREFIX_IN6
:
4214 case SIOCGIFPREFIX_IN6
:
4215 case SIOCDIFPREFIX_IN6
:
4216 case SIOCAIFPREFIX_IN6
:
4217 case SIOCCIFPREFIX_IN6
:
4218 case SIOCSGIFPREFIX_IN6
:
4219 case SIOCPROTOATTACH_IN6_32
:
4220 case SIOCPROTOATTACH_IN6_64
:
4221 case SIOCPROTODETACH_IN6
:
4222 case SIOCLL_START_32
:
4223 case SIOCLL_START_64
:
4225 case SIOCAUTOCONF_START
:
4226 case SIOCAUTOCONF_STOP
:
4227 case SIOCSETROUTERMODE_IN6
:
4228 case SIOCLL_CGASTART_32
:
4229 case SIOCLL_CGASTART_64
:
4232 /* bsd/sys/sockio.h */
4235 case SIOCSIFDSTADDR
:
4236 case OSIOCGIFDSTADDR
:
4239 case OSIOCGIFBRDADDR
:
4240 case SIOCSIFBRDADDR
:
4241 case OSIOCGIFCONF32
:
4242 case OSIOCGIFCONF64
:
4243 case OSIOCGIFNETMASK
:
4244 case SIOCSIFNETMASK
:
4250 case SIOCGIFDSTADDR
:
4251 case SIOCGIFBRDADDR
:
4254 case SIOCGIFNETMASK
:
4256 case SIOCAUTONETMASK
:
4265 case SIOCGIFMEDIA32
:
4266 case SIOCGIFMEDIA64
:
4267 case SIOCSIFGENERIC
:
4268 case SIOCGIFGENERIC
:
4272 case SIOCSIFPHYADDR
:
4273 case SIOCGIFPSRCADDR
:
4274 case SIOCGIFPDSTADDR
:
4275 case SIOCDIFPHYADDR
:
4281 case SIOCPROTOATTACH
:
4282 case SIOCPROTODETACH
:
4288 case SIOCSDRVSPEC32
:
4289 case SIOCGDRVSPEC32
:
4290 case SIOCSDRVSPEC64
:
4291 case SIOCGDRVSPEC64
:
4294 case SIOCIFGCLONERS32
:
4295 case SIOCIFGCLONERS64
:
4296 case SIOCGIFASYNCMAP
:
4297 case SIOCSIFASYNCMAP
:
4301 #endif /* CONFIG_MACF_NET */
4304 case SIOCGIFWAKEFLAGS
:
4305 case SIOCGIFGETRTREFCNT
:
4306 case SIOCGIFLINKQUALITYMETRIC
:
4307 case SIOCSIFOPPORTUNISTIC
:
4308 case SIOCGIFOPPORTUNISTIC
:
4309 case SIOCSETROUTERMODE
:
4313 case SIOCSIFLINKPARAMS
:
4314 case SIOCGIFLINKPARAMS
:
4315 case SIOCGIFQUEUESTATS
:
4316 case SIOCSIFTHROTTLE
:
4317 case SIOCGIFTHROTTLE
:
4320 case SIOCGIFDELEGATE
:
4323 case SIOCGIFFUNCTIONALTYPE
:
4324 case SIOCAIFAGENTID
:
4325 case SIOCDIFAGENTID
:
4326 case SIOCGIFAGENTIDS32
:
4327 case SIOCGIFAGENTIDS64
:
4328 case SIOCGIFAGENTDATA32
:
4329 case SIOCGIFAGENTDATA64
:
4330 case SIOCSIFINTERFACESTATE
:
4331 case SIOCGIFINTERFACESTATE
:
4332 case SIOCSIFPROBECONNECTIVITY
:
4333 case SIOCGIFPROBECONNECTIVITY
: