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 strlcpy(outbuf
, ifc
->ifc_name
, IFNAMSIZ
);
686 error
= copyout(outbuf
, dst
, IFNAMSIZ
);
695 if_functional_type(struct ifnet
*ifp
)
697 u_int32_t ret
= IFRTYPE_FUNCTIONAL_UNKNOWN
;
699 if (ifp
->if_flags
& IFF_LOOPBACK
) {
700 ret
= IFRTYPE_FUNCTIONAL_LOOPBACK
;
701 } else if (IFNET_IS_WIFI(ifp
)) {
702 if (ifp
->if_eflags
& IFEF_AWDL
)
703 ret
= IFRTYPE_FUNCTIONAL_WIFI_AWDL
;
705 ret
= IFRTYPE_FUNCTIONAL_WIFI_INFRA
;
706 } else if (IFNET_IS_CELLULAR(ifp
)) {
707 ret
= IFRTYPE_FUNCTIONAL_CELLULAR
;
708 } else if (IFNET_IS_WIRED(ifp
)) {
709 ret
= IFRTYPE_FUNCTIONAL_WIRED
;
717 * Similar to ifa_ifwithaddr, except that this is IPv4 specific
718 * and that it matches only the local (not broadcast) address.
720 __private_extern__
struct in_ifaddr
*
721 ifa_foraddr(unsigned int addr
)
723 return (ifa_foraddr_scoped(addr
, IFSCOPE_NONE
));
727 * Similar to ifa_foraddr, except with the added interface scope
728 * constraint (unless the caller passes in IFSCOPE_NONE in which
729 * case there is no scope restriction).
731 __private_extern__
struct in_ifaddr
*
732 ifa_foraddr_scoped(unsigned int addr
, unsigned int scope
)
734 struct in_ifaddr
*ia
= NULL
;
736 lck_rw_lock_shared(in_ifaddr_rwlock
);
737 TAILQ_FOREACH(ia
, INADDR_HASH(addr
), ia_hash
) {
738 IFA_LOCK_SPIN(&ia
->ia_ifa
);
739 if (ia
->ia_addr
.sin_addr
.s_addr
== addr
&&
740 (scope
== IFSCOPE_NONE
|| ia
->ia_ifp
->if_index
== scope
)) {
741 IFA_ADDREF_LOCKED(&ia
->ia_ifa
); /* for caller */
742 IFA_UNLOCK(&ia
->ia_ifa
);
745 IFA_UNLOCK(&ia
->ia_ifa
);
747 lck_rw_done(in_ifaddr_rwlock
);
753 * Similar to ifa_foraddr, except that this for IPv6.
755 __private_extern__
struct in6_ifaddr
*
756 ifa_foraddr6(struct in6_addr
*addr6
)
758 return (ifa_foraddr6_scoped(addr6
, IFSCOPE_NONE
));
761 __private_extern__
struct in6_ifaddr
*
762 ifa_foraddr6_scoped(struct in6_addr
*addr6
, unsigned int scope
)
764 struct in6_ifaddr
*ia
= NULL
;
766 lck_rw_lock_shared(&in6_ifaddr_rwlock
);
767 for (ia
= in6_ifaddrs
; ia
; ia
= ia
->ia_next
) {
768 IFA_LOCK(&ia
->ia_ifa
);
769 if (IN6_ARE_ADDR_EQUAL(&ia
->ia_addr
.sin6_addr
, addr6
) &&
770 (scope
== IFSCOPE_NONE
|| ia
->ia_ifp
->if_index
== scope
)) {
771 IFA_ADDREF_LOCKED(&ia
->ia_ifa
); /* for caller */
772 IFA_UNLOCK(&ia
->ia_ifa
);
775 IFA_UNLOCK(&ia
->ia_ifa
);
777 lck_rw_done(&in6_ifaddr_rwlock
);
784 * Return the first (primary) address of a given family on an interface.
786 __private_extern__
struct ifaddr
*
787 ifa_ifpgetprimary(struct ifnet
*ifp
, int family
)
791 ifnet_lock_shared(ifp
);
792 TAILQ_FOREACH(ifa
, &ifp
->if_addrhead
, ifa_link
) {
794 if (ifa
->ifa_addr
->sa_family
== family
) {
795 IFA_ADDREF_LOCKED(ifa
); /* for caller */
801 ifnet_lock_done(ifp
);
807 * Locate an interface based on a complete address.
811 ifa_ifwithaddr(const struct sockaddr
*addr
)
815 struct ifaddr
*result
= NULL
;
817 #define equal(a1, a2) \
818 (bcmp((const void*)(a1), (const void*)(a2), \
819 ((const struct sockaddr *)(a1))->sa_len) == 0)
821 ifnet_head_lock_shared();
822 for (ifp
= ifnet_head
.tqh_first
; ifp
&& !result
;
823 ifp
= ifp
->if_link
.tqe_next
) {
824 ifnet_lock_shared(ifp
);
825 for (ifa
= ifp
->if_addrhead
.tqh_first
; ifa
;
826 ifa
= ifa
->ifa_link
.tqe_next
) {
828 if (ifa
->ifa_addr
->sa_family
!= addr
->sa_family
) {
832 if (equal(addr
, ifa
->ifa_addr
)) {
834 IFA_ADDREF_LOCKED(ifa
); /* for caller */
838 if ((ifp
->if_flags
& IFF_BROADCAST
) &&
839 ifa
->ifa_broadaddr
!= NULL
&&
840 /* IP6 doesn't have broadcast */
841 ifa
->ifa_broadaddr
->sa_len
!= 0 &&
842 equal(ifa
->ifa_broadaddr
, addr
)) {
844 IFA_ADDREF_LOCKED(ifa
); /* for caller */
850 ifnet_lock_done(ifp
);
857 * Locate the point to point interface with a given destination address.
861 ifa_ifwithdstaddr(const struct sockaddr
*addr
)
865 struct ifaddr
*result
= NULL
;
867 ifnet_head_lock_shared();
868 for (ifp
= ifnet_head
.tqh_first
; ifp
&& !result
;
869 ifp
= ifp
->if_link
.tqe_next
) {
870 if ((ifp
->if_flags
& IFF_POINTOPOINT
)) {
871 ifnet_lock_shared(ifp
);
872 for (ifa
= ifp
->if_addrhead
.tqh_first
; ifa
;
873 ifa
= ifa
->ifa_link
.tqe_next
) {
875 if (ifa
->ifa_addr
->sa_family
!=
880 if (ifa
->ifa_dstaddr
&&
881 equal(addr
, ifa
->ifa_dstaddr
)) {
883 IFA_ADDREF_LOCKED(ifa
); /* for caller */
889 ifnet_lock_done(ifp
);
897 * Locate the source address of an interface based on a complete address.
900 ifa_ifwithaddr_scoped(const struct sockaddr
*addr
, unsigned int ifscope
)
902 struct ifaddr
*result
= NULL
;
905 if (ifscope
== IFSCOPE_NONE
)
906 return (ifa_ifwithaddr(addr
));
908 ifnet_head_lock_shared();
909 if (ifscope
> (unsigned int)if_index
) {
914 ifp
= ifindex2ifnet
[ifscope
];
916 struct ifaddr
*ifa
= NULL
;
919 * This is suboptimal; there should be a better way
920 * to search for a given address of an interface
921 * for any given address family.
923 ifnet_lock_shared(ifp
);
924 for (ifa
= ifp
->if_addrhead
.tqh_first
; ifa
!= NULL
;
925 ifa
= ifa
->ifa_link
.tqe_next
) {
927 if (ifa
->ifa_addr
->sa_family
!= addr
->sa_family
) {
931 if (equal(addr
, ifa
->ifa_addr
)) {
933 IFA_ADDREF_LOCKED(ifa
); /* for caller */
937 if ((ifp
->if_flags
& IFF_BROADCAST
) &&
938 ifa
->ifa_broadaddr
!= NULL
&&
939 /* IP6 doesn't have broadcast */
940 ifa
->ifa_broadaddr
->sa_len
!= 0 &&
941 equal(ifa
->ifa_broadaddr
, addr
)) {
943 IFA_ADDREF_LOCKED(ifa
); /* for caller */
949 ifnet_lock_done(ifp
);
957 ifa_ifwithnet(const struct sockaddr
*addr
)
959 return (ifa_ifwithnet_common(addr
, IFSCOPE_NONE
));
963 ifa_ifwithnet_scoped(const struct sockaddr
*addr
, unsigned int ifscope
)
965 return (ifa_ifwithnet_common(addr
, ifscope
));
969 * Find an interface on a specific network. If many, choice
970 * is most specific found.
972 static struct ifaddr
*
973 ifa_ifwithnet_common(const struct sockaddr
*addr
, unsigned int ifscope
)
976 struct ifaddr
*ifa
= NULL
;
977 struct ifaddr
*ifa_maybe
= NULL
;
978 u_int af
= addr
->sa_family
;
979 const char *addr_data
= addr
->sa_data
, *cplim
;
982 if ((af
!= AF_INET
&& af
!= AF_INET6
) ||
983 (af
== AF_INET
&& !ip_doscopedroute
) ||
984 (af
== AF_INET6
&& !ip6_doscopedroute
))
986 if (af
!= AF_INET
|| !ip_doscopedroute
)
988 ifscope
= IFSCOPE_NONE
;
990 ifnet_head_lock_shared();
992 * AF_LINK addresses can be looked up directly by their index number,
993 * so do that if we can.
996 const struct sockaddr_dl
*sdl
=
997 (const struct sockaddr_dl
*)(uintptr_t)(size_t)addr
;
998 if (sdl
->sdl_index
&& sdl
->sdl_index
<= if_index
) {
999 ifa
= ifnet_addrs
[sdl
->sdl_index
- 1];
1009 * Scan though each interface, looking for ones that have
1010 * addresses in this address family.
1012 for (ifp
= ifnet_head
.tqh_first
; ifp
; ifp
= ifp
->if_link
.tqe_next
) {
1013 ifnet_lock_shared(ifp
);
1014 for (ifa
= ifp
->if_addrhead
.tqh_first
; ifa
;
1015 ifa
= ifa
->ifa_link
.tqe_next
) {
1016 const char *cp
, *cp2
, *cp3
;
1019 if (ifa
->ifa_addr
== NULL
||
1020 ifa
->ifa_addr
->sa_family
!= af
) {
1026 * If we're looking up with a scope,
1027 * find using a matching interface.
1029 if (ifscope
!= IFSCOPE_NONE
&&
1030 ifp
->if_index
!= ifscope
) {
1036 * Scan all the bits in the ifa's address.
1037 * If a bit dissagrees with what we are
1038 * looking for, mask it with the netmask
1039 * to see if it really matters.
1040 * (A byte at a time)
1042 if (ifa
->ifa_netmask
== 0) {
1047 cp2
= ifa
->ifa_addr
->sa_data
;
1048 cp3
= ifa
->ifa_netmask
->sa_data
;
1049 cplim
= ifa
->ifa_netmask
->sa_len
+
1050 (char *)ifa
->ifa_netmask
;
1052 if ((*cp
++ ^ *cp2
++) & *cp3
++)
1053 goto next
; /* next address! */
1055 * If the netmask of what we just found
1056 * is more specific than what we had before
1057 * (if we had one) then remember the new one
1058 * before continuing to search
1059 * for an even better one.
1061 if (ifa_maybe
== NULL
||
1062 rn_refines((caddr_t
)ifa
->ifa_netmask
,
1063 (caddr_t
)ifa_maybe
->ifa_netmask
)) {
1064 IFA_ADDREF_LOCKED(ifa
); /* ifa_maybe */
1066 if (ifa_maybe
!= NULL
)
1067 IFA_REMREF(ifa_maybe
);
1072 IFA_LOCK_ASSERT_NOTHELD(ifa
);
1074 ifnet_lock_done(ifp
);
1083 else if (ifa_maybe
!= NULL
)
1084 IFA_REMREF(ifa_maybe
);
1090 * Find an interface address specific to an interface best matching
1094 ifaof_ifpforaddr(const struct sockaddr
*addr
, struct ifnet
*ifp
)
1096 struct ifaddr
*ifa
= NULL
;
1097 const char *cp
, *cp2
, *cp3
;
1099 struct ifaddr
*ifa_maybe
= NULL
;
1100 struct ifaddr
*better_ifa_maybe
= NULL
;
1101 u_int af
= addr
->sa_family
;
1106 ifnet_lock_shared(ifp
);
1107 for (ifa
= ifp
->if_addrhead
.tqh_first
; ifa
;
1108 ifa
= ifa
->ifa_link
.tqe_next
) {
1110 if (ifa
->ifa_addr
->sa_family
!= af
) {
1114 if (ifa_maybe
== NULL
) {
1115 IFA_ADDREF_LOCKED(ifa
); /* for ifa_maybe */
1118 if (ifa
->ifa_netmask
== 0) {
1119 if (equal(addr
, ifa
->ifa_addr
) || (ifa
->ifa_dstaddr
&&
1120 equal(addr
, ifa
->ifa_dstaddr
))) {
1121 IFA_ADDREF_LOCKED(ifa
); /* for caller */
1128 if (ifp
->if_flags
& IFF_POINTOPOINT
) {
1129 if (ifa
->ifa_dstaddr
&& equal(addr
, ifa
->ifa_dstaddr
)) {
1130 IFA_ADDREF_LOCKED(ifa
); /* for caller */
1135 if (equal(addr
, ifa
->ifa_addr
)) {
1137 IFA_ADDREF_LOCKED(ifa
); /* for caller */
1142 cp2
= ifa
->ifa_addr
->sa_data
;
1143 cp3
= ifa
->ifa_netmask
->sa_data
;
1144 cplim
= ifa
->ifa_netmask
->sa_len
+
1145 (char *)ifa
->ifa_netmask
;
1146 for (; cp3
< cplim
; cp3
++)
1147 if ((*cp
++ ^ *cp2
++) & *cp3
)
1151 if (better_ifa_maybe
== NULL
) {
1152 /* for better_ifa_maybe */
1153 IFA_ADDREF_LOCKED(ifa
);
1154 better_ifa_maybe
= ifa
;
1162 if (better_ifa_maybe
!= NULL
) {
1163 ifa
= better_ifa_maybe
;
1164 better_ifa_maybe
= NULL
;
1171 ifnet_lock_done(ifp
);
1173 if (better_ifa_maybe
!= NULL
)
1174 IFA_REMREF(better_ifa_maybe
);
1175 if (ifa_maybe
!= NULL
)
1176 IFA_REMREF(ifa_maybe
);
1181 #include <net/route.h>
1184 * Default action when installing a route with a Link Level gateway.
1185 * Lookup an appropriate real ifa to point to.
1186 * This should be moved to /sys/net/link.c eventually.
1189 link_rtrequest(int cmd
, struct rtentry
*rt
, struct sockaddr
*sa
)
1192 struct sockaddr
*dst
;
1194 void (*ifa_rtrequest
)(int, struct rtentry
*, struct sockaddr
*);
1196 lck_mtx_assert(rnh_lock
, LCK_MTX_ASSERT_OWNED
);
1197 RT_LOCK_ASSERT_HELD(rt
);
1199 if (cmd
!= RTM_ADD
|| ((ifa
= rt
->rt_ifa
) == 0) ||
1200 ((ifp
= ifa
->ifa_ifp
) == 0) || ((dst
= rt_key(rt
)) == 0))
1203 /* Become a regular mutex, just in case */
1204 RT_CONVERT_LOCK(rt
);
1206 ifa
= ifaof_ifpforaddr(dst
, ifp
);
1210 ifa_rtrequest
= ifa
->ifa_rtrequest
;
1212 if (ifa_rtrequest
!= NULL
&& ifa_rtrequest
!= link_rtrequest
)
1213 ifa_rtrequest(cmd
, rt
, sa
);
1219 * if_updown will set the interface up or down. It will
1220 * prevent other up/down events from occurring until this
1221 * up/down event has completed.
1223 * Caller must lock ifnet. This function will drop the
1224 * lock. This allows ifnet_set_flags to set the rest of
1225 * the flags after we change the up/down state without
1226 * dropping the interface lock between setting the
1227 * up/down state and updating the rest of the flags.
1229 __private_extern__
void
1235 struct ifaddr
**ifa
;
1237 struct ifclassq
*ifq
= &ifp
->if_snd
;
1239 /* Wait until no one else is changing the up/down state */
1240 while ((ifp
->if_eflags
& IFEF_UPDOWNCHANGE
) != 0) {
1242 tv
.tv_nsec
= NSEC_PER_SEC
/ 10;
1243 ifnet_lock_done(ifp
);
1244 msleep(&ifp
->if_eflags
, NULL
, 0, "if_updown", &tv
);
1245 ifnet_lock_exclusive(ifp
);
1248 /* Verify that the interface isn't already in the right state */
1249 if ((!up
&& (ifp
->if_flags
& IFF_UP
) == 0) ||
1250 (up
&& (ifp
->if_flags
& IFF_UP
) == IFF_UP
)) {
1254 /* Indicate that the up/down state is changing */
1255 ifp
->if_eflags
|= IFEF_UPDOWNCHANGE
;
1257 /* Mark interface up or down */
1259 ifp
->if_flags
|= IFF_UP
;
1262 ifp
->if_flags
&= ~IFF_UP
;
1265 ifnet_touch_lastchange(ifp
);
1267 /* Drop the lock to notify addresses and route */
1268 ifnet_lock_done(ifp
);
1269 if (ifnet_get_address_list(ifp
, &ifa
) == 0) {
1270 for (i
= 0; ifa
[i
] != 0; i
++) {
1271 pfctlinput(up
? PRC_IFUP
: PRC_IFDOWN
, ifa
[i
]->ifa_addr
);
1273 ifnet_free_address_list(ifa
);
1280 /* Inform all transmit queues about the new link state */
1282 ifnet_update_sndq(ifq
, up
? CLASSQ_EV_LINK_UP
: CLASSQ_EV_LINK_DOWN
);
1285 /* Aquire the lock to clear the changing flag */
1286 ifnet_lock_exclusive(ifp
);
1287 ifp
->if_eflags
&= ~IFEF_UPDOWNCHANGE
;
1288 wakeup(&ifp
->if_eflags
);
1292 * Mark an interface down and notify protocols of
1299 ifnet_lock_exclusive(ifp
);
1301 ifnet_lock_done(ifp
);
1305 * Mark an interface up and notify protocols of
1312 ifnet_lock_exclusive(ifp
);
1314 ifnet_lock_done(ifp
);
1318 * Flush an interface queue.
1321 if_qflush(struct ifnet
*ifp
, int ifq_locked
)
1323 struct ifclassq
*ifq
= &ifp
->if_snd
;
1328 if (IFCQ_IS_ENABLED(ifq
))
1331 if (IFCQ_IS_DRAINING(ifq
))
1332 ifq
->ifcq_drain
= 0;
1333 if (ALTQ_IS_ENABLED(IFCQ_ALTQ(ifq
)))
1334 ALTQ_PURGE(IFCQ_ALTQ(ifq
));
1335 #endif /* PF_ALTQ */
1337 VERIFY(IFCQ_IS_EMPTY(ifq
));
1344 if_qflush_sc(struct ifnet
*ifp
, mbuf_svc_class_t sc
, u_int32_t flow
,
1345 u_int32_t
*packets
, u_int32_t
*bytes
, int ifq_locked
)
1347 struct ifclassq
*ifq
= &ifp
->if_snd
;
1348 u_int32_t cnt
= 0, len
= 0;
1349 u_int32_t a_cnt
= 0, a_len
= 0;
1351 VERIFY(sc
== MBUF_SC_UNSPEC
|| MBUF_VALID_SC(sc
));
1357 if (IFCQ_IS_ENABLED(ifq
))
1358 IFCQ_PURGE_SC(ifq
, sc
, flow
, cnt
, len
);
1360 if (IFCQ_IS_DRAINING(ifq
)) {
1361 VERIFY((signed)(ifq
->ifcq_drain
- cnt
) >= 0);
1362 ifq
->ifcq_drain
-= cnt
;
1364 if (ALTQ_IS_ENABLED(IFCQ_ALTQ(ifq
)))
1365 ALTQ_PURGE_SC(IFCQ_ALTQ(ifq
), sc
, flow
, a_cnt
, a_len
);
1366 #endif /* PF_ALTQ */
1371 if (packets
!= NULL
)
1372 *packets
= cnt
+ a_cnt
;
1374 *bytes
= len
+ a_len
;
1378 * Map interface name to
1379 * interface structure pointer.
1382 ifunit(const char *name
)
1384 char namebuf
[IFNAMSIZ
+ 1];
1392 if (len
< 2 || len
> IFNAMSIZ
)
1394 cp
= name
+ len
- 1;
1396 if (c
< '0' || c
> '9')
1397 return (NULL
); /* trailing garbage */
1402 return (NULL
); /* no interface name */
1403 unit
+= (c
- '0') * m
;
1405 return (NULL
); /* number is unreasonable */
1408 } while (c
>= '0' && c
<= '9');
1409 len
= cp
- name
+ 1;
1410 bcopy(name
, namebuf
, len
);
1411 namebuf
[len
] = '\0';
1413 * Now search all the interfaces for this name/number
1415 ifnet_head_lock_shared();
1416 TAILQ_FOREACH(ifp
, &ifnet_head
, if_link
) {
1417 if (strncmp(ifp
->if_name
, namebuf
, len
))
1419 if (unit
== ifp
->if_unit
)
1428 * Map interface name in a sockaddr_dl to
1429 * interface structure pointer.
1432 if_withname(struct sockaddr
*sa
)
1434 char ifname
[IFNAMSIZ
+1];
1435 struct sockaddr_dl
*sdl
= (struct sockaddr_dl
*)(void *)sa
;
1437 if ( (sa
->sa_family
!= AF_LINK
) || (sdl
->sdl_nlen
== 0) ||
1438 (sdl
->sdl_nlen
> IFNAMSIZ
) )
1442 * ifunit wants a null-terminated name. It may not be null-terminated
1443 * in the sockaddr. We don't want to change the caller's sockaddr,
1444 * and there might not be room to put the trailing null anyway, so we
1445 * make a local copy that we know we can null terminate safely.
1448 bcopy(sdl
->sdl_data
, ifname
, sdl
->sdl_nlen
);
1449 ifname
[sdl
->sdl_nlen
] = '\0';
1450 return (ifunit(ifname
));
1453 static __attribute__((noinline
)) int
1454 ifioctl_ifconf(u_long cmd
, caddr_t data
)
1459 case OSIOCGIFCONF32
: /* struct ifconf32 */
1460 case SIOCGIFCONF32
: { /* struct ifconf32 */
1461 struct ifconf32 ifc
;
1462 bcopy(data
, &ifc
, sizeof (ifc
));
1463 error
= ifconf(cmd
, CAST_USER_ADDR_T(ifc
.ifc_req
),
1465 bcopy(&ifc
, data
, sizeof (ifc
));
1469 case SIOCGIFCONF64
: /* struct ifconf64 */
1470 case OSIOCGIFCONF64
: { /* struct ifconf64 */
1471 struct ifconf64 ifc
;
1472 bcopy(data
, &ifc
, sizeof (ifc
));
1473 error
= ifconf(cmd
, ifc
.ifc_req
, &ifc
.ifc_len
);
1474 bcopy(&ifc
, data
, sizeof (ifc
));
1486 static __attribute__((noinline
)) int
1487 ifioctl_ifclone(u_long cmd
, caddr_t data
)
1492 case SIOCIFGCLONERS32
: { /* struct if_clonereq32 */
1493 struct if_clonereq32 ifcr
;
1494 bcopy(data
, &ifcr
, sizeof (ifcr
));
1495 error
= if_clone_list(ifcr
.ifcr_count
, &ifcr
.ifcr_total
,
1496 CAST_USER_ADDR_T(ifcr
.ifcru_buffer
));
1497 bcopy(&ifcr
, data
, sizeof (ifcr
));
1501 case SIOCIFGCLONERS64
: { /* struct if_clonereq64 */
1502 struct if_clonereq64 ifcr
;
1503 bcopy(data
, &ifcr
, sizeof (ifcr
));
1504 error
= if_clone_list(ifcr
.ifcr_count
, &ifcr
.ifcr_total
,
1506 bcopy(&ifcr
, data
, sizeof (ifcr
));
1518 static __attribute__((noinline
)) int
1519 ifioctl_ifdesc(struct ifnet
*ifp
, u_long cmd
, caddr_t data
, struct proc
*p
)
1521 struct if_descreq
*ifdr
= (struct if_descreq
*)(void *)data
;
1525 VERIFY(ifp
!= NULL
);
1528 case SIOCSIFDESC
: { /* struct if_descreq */
1529 if ((error
= proc_suser(p
)) != 0)
1532 ifnet_lock_exclusive(ifp
);
1533 bcopy(&ifdr
->ifdr_len
, &ifdr_len
, sizeof (ifdr_len
));
1534 if (ifdr_len
> sizeof (ifdr
->ifdr_desc
) ||
1535 ifdr_len
> ifp
->if_desc
.ifd_maxlen
) {
1537 ifnet_lock_done(ifp
);
1541 bzero(ifp
->if_desc
.ifd_desc
, ifp
->if_desc
.ifd_maxlen
);
1542 if ((ifp
->if_desc
.ifd_len
= ifdr_len
) > 0) {
1543 bcopy(ifdr
->ifdr_desc
, ifp
->if_desc
.ifd_desc
,
1544 MIN(ifdr_len
, ifp
->if_desc
.ifd_maxlen
));
1546 ifnet_lock_done(ifp
);
1550 case SIOCGIFDESC
: { /* struct if_descreq */
1551 ifnet_lock_shared(ifp
);
1552 ifdr_len
= MIN(ifp
->if_desc
.ifd_len
, sizeof (ifdr
->ifdr_desc
));
1553 bcopy(&ifdr_len
, &ifdr
->ifdr_len
, sizeof (ifdr_len
));
1554 bzero(&ifdr
->ifdr_desc
, sizeof (ifdr
->ifdr_desc
));
1556 bcopy(ifp
->if_desc
.ifd_desc
, ifdr
->ifdr_desc
, ifdr_len
);
1558 ifnet_lock_done(ifp
);
1570 static __attribute__((noinline
)) int
1571 ifioctl_linkparams(struct ifnet
*ifp
, u_long cmd
, caddr_t data
, struct proc
*p
)
1573 struct if_linkparamsreq
*iflpr
=
1574 (struct if_linkparamsreq
*)(void *)data
;
1575 struct ifclassq
*ifq
;
1578 VERIFY(ifp
!= NULL
);
1582 case SIOCSIFLINKPARAMS
: { /* struct if_linkparamsreq */
1583 struct tb_profile tb
= { 0, 0, 0 };
1585 if ((error
= proc_suser(p
)) != 0)
1589 if (!IFCQ_IS_READY(ifq
)) {
1594 bcopy(&iflpr
->iflpr_output_tbr_rate
, &tb
.rate
,
1596 bcopy(&iflpr
->iflpr_output_tbr_percent
, &tb
.percent
,
1597 sizeof (tb
.percent
));
1598 error
= ifclassq_tbr_set(ifq
, &tb
, TRUE
);
1603 case SIOCGIFLINKPARAMS
: { /* struct if_linkparamsreq */
1604 u_int32_t sched_type
= PKTSCHEDT_NONE
, flags
= 0;
1605 u_int64_t tbr_bw
= 0, tbr_pct
= 0;
1609 if (ALTQ_IS_ENABLED(IFCQ_ALTQ(ifq
))) {
1610 sched_type
= IFCQ_ALTQ(ifq
)->altq_type
;
1611 flags
|= IFLPRF_ALTQ
;
1613 #endif /* PF_ALTQ */
1615 if (IFCQ_IS_ENABLED(ifq
))
1616 sched_type
= ifq
->ifcq_type
;
1618 bcopy(&sched_type
, &iflpr
->iflpr_output_sched
,
1619 sizeof (iflpr
->iflpr_output_sched
));
1621 if (IFCQ_TBR_IS_ENABLED(ifq
)) {
1622 tbr_bw
= ifq
->ifcq_tbr
.tbr_rate_raw
;
1623 tbr_pct
= ifq
->ifcq_tbr
.tbr_percent
;
1625 bcopy(&tbr_bw
, &iflpr
->iflpr_output_tbr_rate
,
1626 sizeof (iflpr
->iflpr_output_tbr_rate
));
1627 bcopy(&tbr_pct
, &iflpr
->iflpr_output_tbr_percent
,
1628 sizeof (iflpr
->iflpr_output_tbr_percent
));
1631 if (ifp
->if_output_sched_model
==
1632 IFNET_SCHED_MODEL_DRIVER_MANAGED
)
1633 flags
|= IFLPRF_DRVMANAGED
;
1634 bcopy(&flags
, &iflpr
->iflpr_flags
, sizeof (iflpr
->iflpr_flags
));
1635 bcopy(&ifp
->if_output_bw
, &iflpr
->iflpr_output_bw
,
1636 sizeof (iflpr
->iflpr_output_bw
));
1637 bcopy(&ifp
->if_input_bw
, &iflpr
->iflpr_input_bw
,
1638 sizeof (iflpr
->iflpr_input_bw
));
1639 bcopy(&ifp
->if_output_lt
, &iflpr
->iflpr_output_lt
,
1640 sizeof (iflpr
->iflpr_output_lt
));
1641 bcopy(&ifp
->if_input_lt
, &iflpr
->iflpr_input_lt
,
1642 sizeof (iflpr
->iflpr_input_lt
));
1654 static __attribute__((noinline
)) int
1655 ifioctl_qstats(struct ifnet
*ifp
, u_long cmd
, caddr_t data
)
1657 struct if_qstatsreq
*ifqr
= (struct if_qstatsreq
*)(void *)data
;
1658 u_int32_t ifqr_len
, ifqr_slot
;
1661 VERIFY(ifp
!= NULL
);
1664 case SIOCGIFQUEUESTATS
: { /* struct if_qstatsreq */
1665 bcopy(&ifqr
->ifqr_slot
, &ifqr_slot
, sizeof (ifqr_slot
));
1666 bcopy(&ifqr
->ifqr_len
, &ifqr_len
, sizeof (ifqr_len
));
1667 error
= ifclassq_getqstats(&ifp
->if_snd
, ifqr_slot
,
1668 ifqr
->ifqr_buf
, &ifqr_len
);
1671 bcopy(&ifqr_len
, &ifqr
->ifqr_len
, sizeof (ifqr_len
));
1683 static __attribute__((noinline
)) int
1684 ifioctl_throttle(struct ifnet
*ifp
, u_long cmd
, caddr_t data
, struct proc
*p
)
1686 struct if_throttlereq
*ifthr
= (struct if_throttlereq
*)(void *)data
;
1687 u_int32_t ifthr_level
;
1690 VERIFY(ifp
!= NULL
);
1693 case SIOCSIFTHROTTLE
: { /* struct if_throttlereq */
1695 * XXX: Use priv_check_cred() instead of root check?
1697 if ((error
= proc_suser(p
)) != 0)
1700 bcopy(&ifthr
->ifthr_level
, &ifthr_level
, sizeof (ifthr_level
));
1701 error
= ifnet_set_throttle(ifp
, ifthr_level
);
1702 if (error
== EALREADY
)
1707 case SIOCGIFTHROTTLE
: { /* struct if_throttlereq */
1708 if ((error
= ifnet_get_throttle(ifp
, &ifthr_level
)) == 0) {
1709 bcopy(&ifthr_level
, &ifthr
->ifthr_level
,
1710 sizeof (ifthr_level
));
1724 ifioctl_getnetagents(struct ifnet
*ifp
, u_int32_t
*count
, user_addr_t uuid_p
)
1728 u_int32_t valid_netagent_count
= 0;
1730 for (index
= 0; index
< IF_MAXAGENTS
; index
++) {
1731 uuid_t
*netagent_uuid
= &(ifp
->if_agentids
[index
]);
1732 if (!uuid_is_null(*netagent_uuid
)) {
1733 if (uuid_p
!= USER_ADDR_NULL
) {
1734 if ((error
= copyout(netagent_uuid
,
1735 uuid_p
+ sizeof(uuid_t
) * valid_netagent_count
,
1736 sizeof(uuid_t
))) != 0) {
1740 valid_netagent_count
++;
1743 *count
= valid_netagent_count
;
1748 static __attribute__((noinline
)) int
1749 ifioctl_netagent(struct ifnet
*ifp
, u_long cmd
, caddr_t data
, struct proc
*p
)
1751 struct if_agentidreq
*ifar
= (struct if_agentidreq
*)(void *)data
;
1753 struct if_agentidsreq32 s32
;
1754 struct if_agentidsreq64 s64
;
1759 VERIFY(ifp
!= NULL
);
1762 case SIOCAIFAGENTID
: { /* struct if_agentidreq */
1763 uuid_t
*first_empty_slot
= NULL
;
1764 // TODO: Use priv_check_cred() instead of root check
1765 if ((error
= proc_suser(p
)) != 0) {
1768 for (index
= 0; index
< IF_MAXAGENTS
; index
++) {
1769 uuid_t
*netagent_uuid
= &(ifp
->if_agentids
[index
]);
1770 if (uuid_compare(*netagent_uuid
, ifar
->ifar_uuid
) == 0) {
1771 /* Already present, ignore */
1774 if (first_empty_slot
== NULL
&&
1775 uuid_is_null(*netagent_uuid
)) {
1776 first_empty_slot
= netagent_uuid
;
1779 if (first_empty_slot
== NULL
) {
1780 error
= ENOMEM
; /* No empty slot for a netagent UUID, bail */
1783 uuid_copy(*first_empty_slot
, ifar
->ifar_uuid
);
1784 netagent_post_updated_interfaces(ifar
->ifar_uuid
);
1787 case SIOCDIFAGENTID
: { /* struct if_agentidreq */
1788 bool removed_agent_id
= FALSE
;
1789 // TODO: Use priv_check_cred() instead of root check
1790 if ((error
= proc_suser(p
)) != 0) {
1793 for (index
= 0; index
< IF_MAXAGENTS
; index
++) {
1794 uuid_t
*netagent_uuid
= &(ifp
->if_agentids
[index
]);
1795 if (uuid_compare(*netagent_uuid
, ifar
->ifar_uuid
) == 0) {
1796 uuid_clear(*netagent_uuid
);
1797 removed_agent_id
= TRUE
;
1801 if (removed_agent_id
) {
1802 netagent_post_updated_interfaces(ifar
->ifar_uuid
);
1806 case SIOCGIFAGENTIDS32
: { /* struct if_agentidsreq32 */
1807 bcopy(data
, &u
.s32
, sizeof(u
.s32
));
1808 error
= ifioctl_getnetagents(ifp
, &u
.s32
.ifar_count
, u
.s32
.ifar_uuids
);
1810 bcopy(&u
.s32
, data
, sizeof(u
.s32
));
1814 case SIOCGIFAGENTIDS64
: { /* struct if_agentidsreq64 */
1815 bcopy(data
, &u
.s64
, sizeof(u
.s64
));
1816 error
= ifioctl_getnetagents(ifp
, &u
.s64
.ifar_count
, u
.s64
.ifar_uuids
);
1818 bcopy(&u
.s64
, data
, sizeof(u
.s64
));
1831 ifnet_clear_netagent(uuid_t netagent_uuid
)
1833 struct ifnet
*ifp
= NULL
;
1835 bool removed_agent_id
= FALSE
;
1837 ifnet_head_lock_shared();
1839 TAILQ_FOREACH(ifp
, &ifnet_head
, if_link
) {
1840 for (index
= 0; index
< IF_MAXAGENTS
; index
++) {
1841 uuid_t
*ifp_netagent_uuid
= &(ifp
->if_agentids
[index
]);
1842 if (uuid_compare(*ifp_netagent_uuid
, netagent_uuid
) == 0) {
1843 uuid_clear(*ifp_netagent_uuid
);
1844 removed_agent_id
= TRUE
;
1852 static __attribute__((noinline
)) int
1853 ifioctl_netsignature(struct ifnet
*ifp
, u_long cmd
, caddr_t data
)
1855 struct if_nsreq
*ifnsr
= (struct if_nsreq
*)(void *)data
;
1859 VERIFY(ifp
!= NULL
);
1862 case SIOCSIFNETSIGNATURE
: /* struct if_nsreq */
1863 if (ifnsr
->ifnsr_len
> sizeof (ifnsr
->ifnsr_data
)) {
1867 bcopy(&ifnsr
->ifnsr_flags
, &flags
, sizeof (flags
));
1868 error
= ifnet_set_netsignature(ifp
, ifnsr
->ifnsr_family
,
1869 ifnsr
->ifnsr_len
, flags
, ifnsr
->ifnsr_data
);
1872 case SIOCGIFNETSIGNATURE
: /* struct if_nsreq */
1873 ifnsr
->ifnsr_len
= sizeof (ifnsr
->ifnsr_data
);
1874 error
= ifnet_get_netsignature(ifp
, ifnsr
->ifnsr_family
,
1875 &ifnsr
->ifnsr_len
, &flags
, ifnsr
->ifnsr_data
);
1877 bcopy(&flags
, &ifnsr
->ifnsr_flags
, sizeof (flags
));
1879 ifnsr
->ifnsr_len
= 0;
1893 * Most of the routines called to handle the ioctls would end up being
1894 * tail-call optimized, which unfortunately causes this routine to
1895 * consume too much stack space; this is the reason for the "noinline"
1896 * attribute used on those routines.
1899 ifioctl(struct socket
*so
, u_long cmd
, caddr_t data
, struct proc
*p
)
1901 char ifname
[IFNAMSIZ
+ 1];
1902 struct ifnet
*ifp
= NULL
;
1903 struct ifstat
*ifs
= NULL
;
1906 bzero(ifname
, sizeof (ifname
));
1909 * ioctls which don't require ifp, or ifreq ioctls
1912 case OSIOCGIFCONF32
: /* struct ifconf32 */
1913 case SIOCGIFCONF32
: /* struct ifconf32 */
1914 case SIOCGIFCONF64
: /* struct ifconf64 */
1915 case OSIOCGIFCONF64
: /* struct ifconf64 */
1916 error
= ifioctl_ifconf(cmd
, data
);
1919 case SIOCIFGCLONERS32
: /* struct if_clonereq32 */
1920 case SIOCIFGCLONERS64
: /* struct if_clonereq64 */
1921 error
= ifioctl_ifclone(cmd
, data
);
1924 case SIOCGIFAGENTDATA32
: /* struct netagent_req32 */
1925 case SIOCGIFAGENTDATA64
: /* struct netagent_req64 */
1926 error
= netagent_ioctl(cmd
, data
);
1929 case SIOCSIFDSTADDR
: /* struct ifreq */
1930 case SIOCSIFADDR
: /* struct ifreq */
1931 case SIOCSIFBRDADDR
: /* struct ifreq */
1932 case SIOCSIFNETMASK
: /* struct ifreq */
1933 case OSIOCGIFADDR
: /* struct ifreq */
1934 case OSIOCGIFDSTADDR
: /* struct ifreq */
1935 case OSIOCGIFBRDADDR
: /* struct ifreq */
1936 case OSIOCGIFNETMASK
: /* struct ifreq */
1937 case SIOCSIFKPI
: /* struct ifreq */
1938 if (so
->so_proto
== NULL
) {
1943 case SIOCIFCREATE
: /* struct ifreq */
1944 case SIOCIFCREATE2
: /* struct ifreq */
1945 case SIOCIFDESTROY
: /* struct ifreq */
1946 case SIOCGIFFLAGS
: /* struct ifreq */
1947 case SIOCGIFEFLAGS
: /* struct ifreq */
1948 case SIOCGIFCAP
: /* struct ifreq */
1950 case SIOCGIFMAC
: /* struct ifreq */
1951 case SIOCSIFMAC
: /* struct ifreq */
1952 #endif /* CONFIG_MACF_NET */
1953 case SIOCGIFMETRIC
: /* struct ifreq */
1954 case SIOCGIFMTU
: /* struct ifreq */
1955 case SIOCGIFPHYS
: /* struct ifreq */
1956 case SIOCSIFFLAGS
: /* struct ifreq */
1957 case SIOCSIFCAP
: /* struct ifreq */
1958 case SIOCSIFMETRIC
: /* struct ifreq */
1959 case SIOCSIFPHYS
: /* struct ifreq */
1960 case SIOCSIFMTU
: /* struct ifreq */
1961 case SIOCADDMULTI
: /* struct ifreq */
1962 case SIOCDELMULTI
: /* struct ifreq */
1963 case SIOCDIFPHYADDR
: /* struct ifreq */
1964 case SIOCSIFMEDIA
: /* struct ifreq */
1965 case SIOCSIFGENERIC
: /* struct ifreq */
1966 case SIOCSIFLLADDR
: /* struct ifreq */
1967 case SIOCSIFALTMTU
: /* struct ifreq */
1968 case SIOCSIFVLAN
: /* struct ifreq */
1969 case SIOCSIFBOND
: /* struct ifreq */
1970 case SIOCGIFLLADDR
: /* struct ifreq */
1971 case SIOCGIFTYPE
: /* struct ifreq */
1972 case SIOCGIFFUNCTIONALTYPE
: /* struct ifreq */
1973 case SIOCGIFPSRCADDR
: /* struct ifreq */
1974 case SIOCGIFPDSTADDR
: /* struct ifreq */
1975 case SIOCGIFGENERIC
: /* struct ifreq */
1976 case SIOCGIFDEVMTU
: /* struct ifreq */
1977 case SIOCGIFVLAN
: /* struct ifreq */
1978 case SIOCGIFBOND
: /* struct ifreq */
1979 case SIOCGIFWAKEFLAGS
: /* struct ifreq */
1980 case SIOCGIFGETRTREFCNT
: /* struct ifreq */
1981 case SIOCSIFOPPORTUNISTIC
: /* struct ifreq */
1982 case SIOCGIFOPPORTUNISTIC
: /* struct ifreq */
1983 case SIOCGIFLINKQUALITYMETRIC
: /* struct ifreq */
1984 case SIOCSIFLOG
: /* struct ifreq */
1985 case SIOCGIFLOG
: /* struct ifreq */
1986 case SIOCGIFDELEGATE
: /* struct ifreq */
1987 case SIOCGIFEXPENSIVE
: /* struct ifreq */
1988 case SIOCSIFEXPENSIVE
: /* struct ifreq */
1989 case SIOCSIF2KCL
: /* struct ifreq */
1990 case SIOCGIF2KCL
: /* struct ifreq */
1991 case SIOCSIFINTERFACESTATE
: /* struct ifreq */
1992 case SIOCGIFINTERFACESTATE
: /* struct ifreq */
1993 case SIOCSIFPROBECONNECTIVITY
: /* struct ifreq */
1994 case SIOCGIFPROBECONNECTIVITY
: /* struct ifreq */
1995 case SIOCGSTARTDELAY
: /* struct ifreq */
1996 case SIOCGECNMODE
: /* struct ifreq */
1997 case SIOCSECNMODE
: { /* struct ifreq */
1999 bcopy(data
, &ifr
, sizeof (ifr
));
2000 ifr
.ifr_name
[IFNAMSIZ
- 1] = '\0';
2001 bcopy(&ifr
.ifr_name
, ifname
, IFNAMSIZ
);
2002 error
= ifioctl_ifreq(so
, cmd
, &ifr
, p
);
2003 bcopy(&ifr
, data
, sizeof (ifr
));
2009 * ioctls which require ifp. Note that we acquire dlil_ifnet_lock
2010 * here to ensure that the ifnet, if found, has been fully attached.
2014 case SIOCSIFPHYADDR
: /* struct {if,in_}aliasreq */
2015 bcopy(((struct in_aliasreq
*)(void *)data
)->ifra_name
,
2017 ifp
= ifunit(ifname
);
2021 case SIOCSIFPHYADDR_IN6_32
: /* struct in6_aliasreq_32 */
2022 bcopy(((struct in6_aliasreq_32
*)(void *)data
)->ifra_name
,
2024 ifp
= ifunit(ifname
);
2027 case SIOCSIFPHYADDR_IN6_64
: /* struct in6_aliasreq_64 */
2028 bcopy(((struct in6_aliasreq_64
*)(void *)data
)->ifra_name
,
2030 ifp
= ifunit(ifname
);
2034 case SIOCGIFSTATUS
: /* struct ifstat */
2035 ifs
= _MALLOC(sizeof (*ifs
), M_DEVBUF
, M_WAITOK
);
2041 bcopy(data
, ifs
, sizeof (*ifs
));
2042 ifs
->ifs_name
[IFNAMSIZ
- 1] = '\0';
2043 bcopy(ifs
->ifs_name
, ifname
, IFNAMSIZ
);
2044 ifp
= ifunit(ifname
);
2047 case SIOCGIFMEDIA32
: /* struct ifmediareq32 */
2048 bcopy(((struct ifmediareq32
*)(void *)data
)->ifm_name
,
2050 ifp
= ifunit(ifname
);
2053 case SIOCGIFMEDIA64
: /* struct ifmediareq64 */
2054 bcopy(((struct ifmediareq64
*)(void *)data
)->ifm_name
,
2056 ifp
= ifunit(ifname
);
2059 case SIOCSIFDESC
: /* struct if_descreq */
2060 case SIOCGIFDESC
: /* struct if_descreq */
2061 bcopy(((struct if_descreq
*)(void *)data
)->ifdr_name
,
2063 ifp
= ifunit(ifname
);
2066 case SIOCSIFLINKPARAMS
: /* struct if_linkparamsreq */
2067 case SIOCGIFLINKPARAMS
: /* struct if_linkparamsreq */
2068 bcopy(((struct if_linkparamsreq
*)(void *)data
)->iflpr_name
,
2070 ifp
= ifunit(ifname
);
2073 case SIOCGIFQUEUESTATS
: /* struct if_qstatsreq */
2074 bcopy(((struct if_qstatsreq
*)(void *)data
)->ifqr_name
,
2076 ifp
= ifunit(ifname
);
2079 case SIOCSIFTHROTTLE
: /* struct if_throttlereq */
2080 case SIOCGIFTHROTTLE
: /* struct if_throttlereq */
2081 bcopy(((struct if_throttlereq
*)(void *)data
)->ifthr_name
,
2083 ifp
= ifunit(ifname
);
2086 case SIOCAIFAGENTID
: /* struct if_agentidreq */
2087 case SIOCDIFAGENTID
: /* struct if_agentidreq */
2088 case SIOCGIFAGENTIDS32
: /* struct if_agentidsreq32 */
2089 case SIOCGIFAGENTIDS64
: /* struct if_agentidsreq64 */
2090 bcopy(((struct if_agentidreq
*)(void *)data
)->ifar_name
,
2092 ifp
= ifunit(ifname
);
2095 case SIOCSIFNETSIGNATURE
: /* struct if_nsreq */
2096 case SIOCGIFNETSIGNATURE
: /* struct if_nsreq */
2097 bcopy(((struct if_nsreq
*)(void *)data
)->ifnsr_name
,
2099 ifp
= ifunit(ifname
);
2104 * This is a bad assumption, but the code seems to
2105 * have been doing this in the past; caveat emptor.
2107 bcopy(((struct ifreq
*)(void *)data
)->ifr_name
,
2109 ifp
= ifunit(ifname
);
2120 case SIOCSIFPHYADDR
: /* struct {if,in_}aliasreq */
2122 case SIOCSIFPHYADDR_IN6_32
: /* struct in6_aliasreq_32 */
2123 case SIOCSIFPHYADDR_IN6_64
: /* struct in6_aliasreq_64 */
2125 error
= proc_suser(p
);
2129 error
= ifnet_ioctl(ifp
, SOCK_DOM(so
), cmd
, data
);
2133 ifnet_touch_lastchange(ifp
);
2136 case SIOCGIFSTATUS
: /* struct ifstat */
2137 VERIFY(ifs
!= NULL
);
2138 ifs
->ascii
[0] = '\0';
2140 error
= ifnet_ioctl(ifp
, SOCK_DOM(so
), cmd
, (caddr_t
)ifs
);
2142 bcopy(ifs
, data
, sizeof (*ifs
));
2145 case SIOCGIFMEDIA32
: /* struct ifmediareq32 */
2146 case SIOCGIFMEDIA64
: /* struct ifmediareq64 */
2147 error
= ifnet_ioctl(ifp
, SOCK_DOM(so
), cmd
, data
);
2150 case SIOCSIFDESC
: /* struct if_descreq */
2151 case SIOCGIFDESC
: /* struct if_descreq */
2152 error
= ifioctl_ifdesc(ifp
, cmd
, data
, p
);
2155 case SIOCSIFLINKPARAMS
: /* struct if_linkparamsreq */
2156 case SIOCGIFLINKPARAMS
: /* struct if_linkparamsreq */
2157 error
= ifioctl_linkparams(ifp
, cmd
, data
, p
);
2160 case SIOCGIFQUEUESTATS
: /* struct if_qstatsreq */
2161 error
= ifioctl_qstats(ifp
, cmd
, data
);
2164 case SIOCSIFTHROTTLE
: /* struct if_throttlereq */
2165 case SIOCGIFTHROTTLE
: /* struct if_throttlereq */
2166 error
= ifioctl_throttle(ifp
, cmd
, data
, p
);
2169 case SIOCAIFAGENTID
: /* struct if_agentidreq */
2170 case SIOCDIFAGENTID
: /* struct if_agentidreq */
2171 case SIOCGIFAGENTIDS32
: /* struct if_agentidsreq32 */
2172 case SIOCGIFAGENTIDS64
: /* struct if_agentidsreq64 */
2173 error
= ifioctl_netagent(ifp
, cmd
, data
, p
);
2176 case SIOCSIFNETSIGNATURE
: /* struct if_nsreq */
2177 case SIOCGIFNETSIGNATURE
: /* struct if_nsreq */
2178 error
= ifioctl_netsignature(ifp
, cmd
, data
);
2182 if (so
->so_proto
== NULL
) {
2188 error
= ((*so
->so_proto
->pr_usrreqs
->pru_control
)(so
, cmd
,
2190 socket_unlock(so
, 1);
2192 if (error
== EOPNOTSUPP
|| error
== ENOTSUP
) {
2193 error
= ifnet_ioctl(ifp
, SOCK_DOM(so
), cmd
, data
);
2200 _FREE(ifs
, M_DEVBUF
);
2203 if (ifname
[0] == '\0')
2204 (void) snprintf(ifname
, sizeof (ifname
), "%s",
2206 else if (ifp
!= NULL
)
2207 (void) snprintf(ifname
, sizeof (ifname
), "%s",
2211 printf("%s[%s,%d]: ifp %s cmd 0x%08lx (%c%c [%lu] "
2212 "%c %lu) error %d\n", __func__
,
2213 proc_name_address(p
), proc_pid(p
),
2214 ifname
, cmd
, (cmd
& IOC_IN
) ? 'I' : ' ',
2215 (cmd
& IOC_OUT
) ? 'O' : ' ', IOCPARM_LEN(cmd
),
2216 (char)IOCGROUP(cmd
), cmd
& 0xff, error
);
2217 } else if (if_verbose
> 1) {
2218 printf("%s[%s,%d]: ifp %s cmd 0x%08lx (%c%c [%lu] "
2219 "%c %lu) OK\n", __func__
,
2220 proc_name_address(p
), proc_pid(p
),
2221 ifname
, cmd
, (cmd
& IOC_IN
) ? 'I' : ' ',
2222 (cmd
& IOC_OUT
) ? 'O' : ' ', IOCPARM_LEN(cmd
),
2223 (char)IOCGROUP(cmd
), cmd
& 0xff);
2230 static __attribute__((noinline
)) int
2231 ifioctl_ifreq(struct socket
*so
, u_long cmd
, struct ifreq
*ifr
, struct proc
*p
)
2236 struct kev_msg ev_msg
;
2237 struct net_event_data ev_data
;
2239 bzero(&ev_data
, sizeof (struct net_event_data
));
2240 bzero(&ev_msg
, sizeof (struct kev_msg
));
2245 error
= proc_suser(p
);
2248 return (if_clone_create(ifr
->ifr_name
, sizeof(ifr
->ifr_name
),
2249 cmd
== SIOCIFCREATE2
? ifr
->ifr_data
: NULL
));
2251 error
= proc_suser(p
);
2254 return (if_clone_destroy(ifr
->ifr_name
));
2258 * ioctls which require ifp. Note that we acquire dlil_ifnet_lock
2259 * here to ensure that the ifnet, if found, has been fully attached.
2262 ifp
= ifunit(ifr
->ifr_name
);
2270 ifnet_lock_shared(ifp
);
2271 ifr
->ifr_flags
= ifp
->if_flags
;
2272 ifnet_lock_done(ifp
);
2276 ifnet_lock_shared(ifp
);
2277 ifr
->ifr_eflags
= ifp
->if_eflags
;
2278 ifnet_lock_done(ifp
);
2282 ifnet_lock_shared(ifp
);
2283 ifr
->ifr_reqcap
= ifp
->if_capabilities
;
2284 ifr
->ifr_curcap
= ifp
->if_capenable
;
2285 ifnet_lock_done(ifp
);
2290 error
= mac_ifnet_label_get(kauth_cred_get(), ifr
, ifp
);
2294 error
= mac_ifnet_label_set(kauth_cred_get(), ifr
, ifp
);
2296 #endif /* CONFIG_MACF_NET */
2299 ifnet_lock_shared(ifp
);
2300 ifr
->ifr_metric
= ifp
->if_metric
;
2301 ifnet_lock_done(ifp
);
2305 ifnet_lock_shared(ifp
);
2306 ifr
->ifr_mtu
= ifp
->if_mtu
;
2307 ifnet_lock_done(ifp
);
2311 ifnet_lock_shared(ifp
);
2312 ifr
->ifr_phys
= ifp
->if_physical
;
2313 ifnet_lock_done(ifp
);
2317 error
= proc_suser(p
);
2321 (void) ifnet_set_flags(ifp
, ifr
->ifr_flags
,
2322 (u_int16_t
)~IFF_CANTCHANGE
);
2325 * Note that we intentionally ignore any error from below
2326 * for the SIOCSIFFLAGS case.
2328 (void) ifnet_ioctl(ifp
, SOCK_DOM(so
), cmd
, (caddr_t
)ifr
);
2331 * Send the event even upon error from the driver because
2332 * we changed the flags.
2334 ev_msg
.vendor_code
= KEV_VENDOR_APPLE
;
2335 ev_msg
.kev_class
= KEV_NETWORK_CLASS
;
2336 ev_msg
.kev_subclass
= KEV_DL_SUBCLASS
;
2338 ev_msg
.event_code
= KEV_DL_SIFFLAGS
;
2339 strlcpy(&ev_data
.if_name
[0], ifp
->if_name
, IFNAMSIZ
);
2340 ev_data
.if_family
= ifp
->if_family
;
2341 ev_data
.if_unit
= (u_int32_t
) ifp
->if_unit
;
2342 ev_msg
.dv
[0].data_length
= sizeof(struct net_event_data
);
2343 ev_msg
.dv
[0].data_ptr
= &ev_data
;
2344 ev_msg
.dv
[1].data_length
= 0;
2345 kev_post_msg(&ev_msg
);
2347 ifnet_touch_lastchange(ifp
);
2351 error
= proc_suser(p
);
2355 if ((ifr
->ifr_reqcap
& ~ifp
->if_capabilities
)) {
2359 error
= ifnet_ioctl(ifp
, SOCK_DOM(so
), cmd
, (caddr_t
)ifr
);
2361 ifnet_touch_lastchange(ifp
);
2365 error
= proc_suser(p
);
2369 ifp
->if_metric
= ifr
->ifr_metric
;
2371 ev_msg
.vendor_code
= KEV_VENDOR_APPLE
;
2372 ev_msg
.kev_class
= KEV_NETWORK_CLASS
;
2373 ev_msg
.kev_subclass
= KEV_DL_SUBCLASS
;
2375 ev_msg
.event_code
= KEV_DL_SIFMETRICS
;
2376 strlcpy(&ev_data
.if_name
[0], ifp
->if_name
, IFNAMSIZ
);
2377 ev_data
.if_family
= ifp
->if_family
;
2378 ev_data
.if_unit
= (u_int32_t
) ifp
->if_unit
;
2379 ev_msg
.dv
[0].data_length
= sizeof(struct net_event_data
);
2380 ev_msg
.dv
[0].data_ptr
= &ev_data
;
2382 ev_msg
.dv
[1].data_length
= 0;
2383 kev_post_msg(&ev_msg
);
2385 ifnet_touch_lastchange(ifp
);
2389 error
= proc_suser(p
);
2393 error
= ifnet_ioctl(ifp
, SOCK_DOM(so
), cmd
, (caddr_t
)ifr
);
2397 ev_msg
.vendor_code
= KEV_VENDOR_APPLE
;
2398 ev_msg
.kev_class
= KEV_NETWORK_CLASS
;
2399 ev_msg
.kev_subclass
= KEV_DL_SUBCLASS
;
2401 ev_msg
.event_code
= KEV_DL_SIFPHYS
;
2402 strlcpy(&ev_data
.if_name
[0], ifp
->if_name
, IFNAMSIZ
);
2403 ev_data
.if_family
= ifp
->if_family
;
2404 ev_data
.if_unit
= (u_int32_t
) ifp
->if_unit
;
2405 ev_msg
.dv
[0].data_length
= sizeof(struct net_event_data
);
2406 ev_msg
.dv
[0].data_ptr
= &ev_data
;
2407 ev_msg
.dv
[1].data_length
= 0;
2408 kev_post_msg(&ev_msg
);
2410 ifnet_touch_lastchange(ifp
);
2414 u_int32_t oldmtu
= ifp
->if_mtu
;
2415 struct ifclassq
*ifq
= &ifp
->if_snd
;
2417 error
= proc_suser(p
);
2421 if (ifp
->if_ioctl
== NULL
) {
2425 if (ifr
->ifr_mtu
< IF_MINMTU
|| ifr
->ifr_mtu
> IF_MAXMTU
) {
2429 error
= ifnet_ioctl(ifp
, SOCK_DOM(so
), cmd
, (caddr_t
)ifr
);
2433 ev_msg
.vendor_code
= KEV_VENDOR_APPLE
;
2434 ev_msg
.kev_class
= KEV_NETWORK_CLASS
;
2435 ev_msg
.kev_subclass
= KEV_DL_SUBCLASS
;
2437 ev_msg
.event_code
= KEV_DL_SIFMTU
;
2438 strlcpy(&ev_data
.if_name
[0], ifp
->if_name
, IFNAMSIZ
);
2439 ev_data
.if_family
= ifp
->if_family
;
2440 ev_data
.if_unit
= (u_int32_t
) ifp
->if_unit
;
2441 ev_msg
.dv
[0].data_length
= sizeof(struct net_event_data
);
2442 ev_msg
.dv
[0].data_ptr
= &ev_data
;
2443 ev_msg
.dv
[1].data_length
= 0;
2444 kev_post_msg(&ev_msg
);
2446 ifnet_touch_lastchange(ifp
);
2450 * If the link MTU changed, do network layer specific procedure
2451 * and update all route entries associated with the interface,
2452 * so that their MTU metric gets updated.
2454 if (ifp
->if_mtu
!= oldmtu
) {
2455 if_rtmtu_update(ifp
);
2459 /* Inform all transmit queues about the new MTU */
2461 ifnet_update_sndq(ifq
, CLASSQ_EV_LINK_MTU
);
2469 error
= proc_suser(p
);
2473 /* Don't allow group membership on non-multicast interfaces. */
2474 if ((ifp
->if_flags
& IFF_MULTICAST
) == 0) {
2479 /* Don't let users screw up protocols' entries. */
2480 if (ifr
->ifr_addr
.sa_family
!= AF_UNSPEC
&&
2481 ifr
->ifr_addr
.sa_family
!= AF_LINK
) {
2487 * User is permitted to anonymously join a particular link
2488 * multicast group via SIOCADDMULTI. Subsequent join requested
2489 * for the same record which has an outstanding refcnt from a
2490 * past if_addmulti_anon() will not result in EADDRINUSE error
2491 * (unlike other BSDs.) Anonymously leaving a group is also
2492 * allowed only as long as there is an outstanding refcnt held
2493 * by a previous anonymous request, or else ENOENT (even if the
2494 * link-layer multicast membership exists for a network-layer
2497 if (cmd
== SIOCADDMULTI
) {
2498 error
= if_addmulti_anon(ifp
, &ifr
->ifr_addr
, NULL
);
2499 ev_msg
.event_code
= KEV_DL_ADDMULTI
;
2501 error
= if_delmulti_anon(ifp
, &ifr
->ifr_addr
);
2502 ev_msg
.event_code
= KEV_DL_DELMULTI
;
2507 ev_msg
.vendor_code
= KEV_VENDOR_APPLE
;
2508 ev_msg
.kev_class
= KEV_NETWORK_CLASS
;
2509 ev_msg
.kev_subclass
= KEV_DL_SUBCLASS
;
2510 strlcpy(&ev_data
.if_name
[0], ifp
->if_name
, IFNAMSIZ
);
2512 ev_data
.if_family
= ifp
->if_family
;
2513 ev_data
.if_unit
= (u_int32_t
) ifp
->if_unit
;
2514 ev_msg
.dv
[0].data_length
= sizeof(struct net_event_data
);
2515 ev_msg
.dv
[0].data_ptr
= &ev_data
;
2516 ev_msg
.dv
[1].data_length
= 0;
2517 kev_post_msg(&ev_msg
);
2519 ifnet_touch_lastchange(ifp
);
2522 case SIOCDIFPHYADDR
:
2524 case SIOCSIFGENERIC
:
2529 error
= proc_suser(p
);
2533 error
= ifnet_ioctl(ifp
, SOCK_DOM(so
), cmd
, (caddr_t
)ifr
);
2537 ifnet_touch_lastchange(ifp
);
2540 case SIOCGIFLLADDR
: {
2541 struct sockaddr_dl
*sdl
= SDL(ifp
->if_lladdr
->ifa_addr
);
2543 if (sdl
->sdl_alen
== 0) {
2544 error
= EADDRNOTAVAIL
;
2547 /* If larger than 14-bytes we'll need another mechanism */
2548 if (sdl
->sdl_alen
> sizeof (ifr
->ifr_addr
.sa_data
)) {
2552 /* Follow the same convention used by SIOCSIFLLADDR */
2553 bzero(&ifr
->ifr_addr
, sizeof (ifr
->ifr_addr
));
2554 ifr
->ifr_addr
.sa_family
= AF_LINK
;
2555 ifr
->ifr_addr
.sa_len
= sdl
->sdl_alen
;
2556 error
= ifnet_guarded_lladdr_copy_bytes(ifp
,
2557 &ifr
->ifr_addr
.sa_data
, sdl
->sdl_alen
);
2562 ifr
->ifr_type
.ift_type
= ifp
->if_type
;
2563 ifr
->ifr_type
.ift_family
= ifp
->if_family
;
2564 ifr
->ifr_type
.ift_subfamily
= ifp
->if_subfamily
;
2567 case SIOCGIFFUNCTIONALTYPE
:
2568 ifr
->ifr_functional_type
= if_functional_type(ifp
);
2571 case SIOCGIFPSRCADDR
:
2572 case SIOCGIFPDSTADDR
:
2573 case SIOCGIFGENERIC
:
2577 error
= ifnet_ioctl(ifp
, SOCK_DOM(so
), cmd
, (caddr_t
)ifr
);
2580 case SIOCGIFWAKEFLAGS
:
2581 ifnet_lock_shared(ifp
);
2582 ifr
->ifr_wake_flags
= ifnet_get_wake_flags(ifp
);
2583 ifnet_lock_done(ifp
);
2586 case SIOCGIFGETRTREFCNT
:
2587 ifnet_lock_shared(ifp
);
2588 ifr
->ifr_route_refcnt
= ifp
->if_route_refcnt
;
2589 ifnet_lock_done(ifp
);
2592 case SIOCSIFOPPORTUNISTIC
:
2593 case SIOCGIFOPPORTUNISTIC
:
2594 error
= ifnet_getset_opportunistic(ifp
, cmd
, ifr
, p
);
2597 case SIOCGIFLINKQUALITYMETRIC
:
2598 ifnet_lock_shared(ifp
);
2599 if ((ifp
->if_interface_state
.valid_bitmask
&
2600 IF_INTERFACE_STATE_LQM_STATE_VALID
))
2601 ifr
->ifr_link_quality_metric
=
2602 ifp
->if_interface_state
.lqm_state
;
2603 else if ((ifp
->if_refflags
& IFRF_ATTACHED
)) {
2604 ifr
->ifr_link_quality_metric
=
2605 IFNET_LQM_THRESH_UNKNOWN
;
2607 ifr
->ifr_link_quality_metric
=
2608 IFNET_LQM_THRESH_OFF
;
2610 ifnet_lock_done(ifp
);
2615 error
= ifnet_getset_log(ifp
, cmd
, ifr
, p
);
2618 case SIOCGIFDELEGATE
:
2619 ifnet_lock_shared(ifp
);
2620 ifr
->ifr_delegated
= ((ifp
->if_delegated
.ifp
!= NULL
) ?
2621 ifp
->if_delegated
.ifp
->if_index
: 0);
2622 ifnet_lock_done(ifp
);
2625 case SIOCGIFEXPENSIVE
:
2626 ifnet_lock_shared(ifp
);
2627 if (ifp
->if_eflags
& IFEF_EXPENSIVE
)
2628 ifr
->ifr_expensive
= 1;
2630 ifr
->ifr_expensive
= 0;
2631 ifnet_lock_done(ifp
);
2634 case SIOCSIFEXPENSIVE
:
2638 if ((error
= priv_check_cred(kauth_cred_get(),
2639 PRIV_NET_INTERFACE_CONTROL
, 0)) != 0)
2641 ifnet_lock_exclusive(ifp
);
2642 if (ifr
->ifr_expensive
)
2643 ifp
->if_eflags
|= IFEF_EXPENSIVE
;
2645 ifp
->if_eflags
&= ~IFEF_EXPENSIVE
;
2646 ifnet_lock_done(ifp
);
2648 * Update the expensive bit in the delegated interface
2651 ifnet_head_lock_shared();
2652 TAILQ_FOREACH(difp
, &ifnet_head
, if_link
) {
2653 ifnet_lock_exclusive(difp
);
2654 if (difp
->if_delegated
.ifp
== ifp
) {
2655 difp
->if_delegated
.expensive
=
2656 ifp
->if_eflags
& IFEF_EXPENSIVE
? 1 : 0;
2659 ifnet_lock_done(difp
);
2666 ifnet_lock_shared(ifp
);
2667 if (ifp
->if_eflags
& IFEF_2KCL
)
2671 ifnet_lock_done(ifp
);
2675 if ((error
= priv_check_cred(kauth_cred_get(),
2676 PRIV_NET_INTERFACE_CONTROL
, 0)) != 0)
2678 ifnet_lock_exclusive(ifp
);
2680 ifp
->if_eflags
|= IFEF_2KCL
;
2682 ifp
->if_eflags
&= ~IFEF_2KCL
;
2683 ifnet_lock_done(ifp
);
2685 case SIOCGSTARTDELAY
:
2686 ifnet_lock_shared(ifp
);
2687 if (ifp
->if_eflags
& IFEF_ENQUEUE_MULTI
) {
2688 ifr
->ifr_start_delay_qlen
=
2689 ifp
->if_start_delay_qlen
;
2690 ifr
->ifr_start_delay_timeout
=
2691 ifp
->if_start_delay_timeout
;
2693 ifr
->ifr_start_delay_qlen
= 0;
2694 ifr
->ifr_start_delay_timeout
= 0;
2696 ifnet_lock_done(ifp
);
2698 case SIOCSIFDSTADDR
:
2700 case SIOCSIFBRDADDR
:
2701 case SIOCSIFNETMASK
:
2703 case OSIOCGIFDSTADDR
:
2704 case OSIOCGIFBRDADDR
:
2705 case OSIOCGIFNETMASK
:
2707 VERIFY(so
->so_proto
!= NULL
);
2709 if (cmd
== SIOCSIFDSTADDR
|| cmd
== SIOCSIFADDR
||
2710 cmd
== SIOCSIFBRDADDR
|| cmd
== SIOCSIFNETMASK
) {
2711 #if BYTE_ORDER != BIG_ENDIAN
2712 if (ifr
->ifr_addr
.sa_family
== 0 &&
2713 ifr
->ifr_addr
.sa_len
< 16) {
2714 ifr
->ifr_addr
.sa_family
= ifr
->ifr_addr
.sa_len
;
2715 ifr
->ifr_addr
.sa_len
= 16;
2718 if (ifr
->ifr_addr
.sa_len
== 0)
2719 ifr
->ifr_addr
.sa_len
= 16;
2721 } else if (cmd
== OSIOCGIFADDR
) {
2722 cmd
= SIOCGIFADDR
; /* struct ifreq */
2723 } else if (cmd
== OSIOCGIFDSTADDR
) {
2724 cmd
= SIOCGIFDSTADDR
; /* struct ifreq */
2725 } else if (cmd
== OSIOCGIFBRDADDR
) {
2726 cmd
= SIOCGIFBRDADDR
; /* struct ifreq */
2727 } else if (cmd
== OSIOCGIFNETMASK
) {
2728 cmd
= SIOCGIFNETMASK
; /* struct ifreq */
2732 error
= ((*so
->so_proto
->pr_usrreqs
->pru_control
)(so
, cmd
,
2733 (caddr_t
)ifr
, ifp
, p
));
2734 socket_unlock(so
, 1);
2738 case OSIOCGIFDSTADDR
:
2739 case OSIOCGIFBRDADDR
:
2740 case OSIOCGIFNETMASK
:
2741 bcopy(&ifr
->ifr_addr
.sa_family
, &ifr
->ifr_addr
,
2745 if (cmd
== SIOCSIFKPI
) {
2746 int temperr
= proc_suser(p
);
2751 if (error
== EOPNOTSUPP
|| error
== ENOTSUP
) {
2752 error
= ifnet_ioctl(ifp
, SOCK_DOM(so
), cmd
,
2757 case SIOCGIFINTERFACESTATE
:
2758 if_get_state(ifp
, &ifr
->ifr_interface_state
);
2761 case SIOCSIFINTERFACESTATE
:
2762 if ((error
= priv_check_cred(kauth_cred_get(),
2763 PRIV_NET_INTERFACE_CONTROL
, 0)) != 0)
2766 error
= if_state_update(ifp
, &ifr
->ifr_interface_state
);
2769 case SIOCSIFPROBECONNECTIVITY
:
2770 if ((error
= priv_check_cred(kauth_cred_get(),
2771 PRIV_NET_INTERFACE_CONTROL
, 0)) != 0)
2773 error
= if_probe_connectivity(ifp
,
2774 ifr
->ifr_probe_connectivity
);
2776 case SIOCGIFPROBECONNECTIVITY
:
2777 if ((error
= priv_check_cred(kauth_cred_get(),
2778 PRIV_NET_INTERFACE_CONTROL
, 0)) != 0)
2780 if (ifp
->if_eflags
& IFEF_PROBE_CONNECTIVITY
)
2781 ifr
->ifr_probe_connectivity
= 1;
2783 ifr
->ifr_probe_connectivity
= 0;
2786 if ((ifp
->if_eflags
& (IFEF_ECN_ENABLE
|IFEF_ECN_DISABLE
)) ==
2788 ifr
->ifr_ecn_mode
= IFRTYPE_ECN_ENABLE
;
2789 else if ((ifp
->if_eflags
& (IFEF_ECN_ENABLE
|IFEF_ECN_DISABLE
)) ==
2791 ifr
->ifr_ecn_mode
= IFRTYPE_ECN_DISABLE
;
2793 ifr
->ifr_ecn_mode
= IFRTYPE_ECN_DEFAULT
;
2796 if (ifr
->ifr_ecn_mode
== IFRTYPE_ECN_DEFAULT
) {
2797 ifp
->if_eflags
&= ~(IFEF_ECN_ENABLE
|IFEF_ECN_DISABLE
);
2798 } else if (ifr
->ifr_ecn_mode
== IFRTYPE_ECN_ENABLE
) {
2799 ifp
->if_eflags
|= IFEF_ECN_ENABLE
;
2800 ifp
->if_eflags
&= ~IFEF_ECN_DISABLE
;
2801 } else if (ifr
->ifr_ecn_mode
== IFRTYPE_ECN_DISABLE
) {
2802 ifp
->if_eflags
|= IFEF_ECN_DISABLE
;
2803 ifp
->if_eflags
&= ~IFEF_ECN_ENABLE
;
2816 ifioctllocked(struct socket
*so
, u_long cmd
, caddr_t data
, struct proc
*p
)
2820 socket_unlock(so
, 0);
2821 error
= ifioctl(so
, cmd
, data
, p
);
2827 * Set/clear promiscuous mode on interface ifp based on the truth value
2828 * of pswitch. The calls are reference counted so that only the first
2829 * "on" request actually has an effect, as does the final "off" request.
2830 * Results are undefined if the "off" and "on" requests are not matched.
2833 ifnet_set_promiscuous(
2841 ifnet_lock_exclusive(ifp
);
2842 oldflags
= ifp
->if_flags
;
2843 ifp
->if_pcount
+= pswitch
? 1 : -1;
2845 if (ifp
->if_pcount
> 0)
2846 ifp
->if_flags
|= IFF_PROMISC
;
2848 ifp
->if_flags
&= ~IFF_PROMISC
;
2850 newflags
= ifp
->if_flags
;
2851 ifnet_lock_done(ifp
);
2853 if (newflags
!= oldflags
&& (newflags
& IFF_UP
) != 0) {
2854 error
= ifnet_ioctl(ifp
, 0, SIOCSIFFLAGS
, NULL
);
2858 ifnet_lock_exclusive(ifp
);
2860 ifp
->if_pcount
-= pswitch
? 1 : -1;
2861 if (ifp
->if_pcount
> 0)
2862 ifp
->if_flags
|= IFF_PROMISC
;
2864 ifp
->if_flags
&= ~IFF_PROMISC
;
2865 ifnet_lock_done(ifp
);
2869 if (newflags
!= oldflags
) {
2870 log(LOG_INFO
, "%s: promiscuous mode %s%s\n",
2872 (newflags
& IFF_PROMISC
) != 0 ? "enable" : "disable",
2873 error
!= 0 ? " failed" : " succeeded");
2879 * Return interface configuration
2880 * of system. List may be used
2881 * in later ioctl's (above) to get
2882 * other information.
2886 ifconf(u_long cmd
, user_addr_t ifrp
, int *ret_space
)
2888 struct ifnet
*ifp
= NULL
;
2893 net_thread_marks_t marks
;
2895 marks
= net_thread_marks_push(NET_THREAD_CKREQ_LLADDR
);
2898 * Zero the ifr buffer to make sure we don't
2899 * disclose the contents of the stack.
2901 bzero(&ifr
, sizeof (struct ifreq
));
2904 ifnet_head_lock_shared();
2905 for (ifp
= ifnet_head
.tqh_first
; space
> sizeof (ifr
) &&
2906 ifp
; ifp
= ifp
->if_link
.tqe_next
) {
2908 size_t ifnlen
, addrs
;
2910 ifnlen
= snprintf(workbuf
, sizeof (workbuf
),
2911 "%s", if_name(ifp
));
2912 if (ifnlen
+ 1 > sizeof (ifr
.ifr_name
)) {
2913 error
= ENAMETOOLONG
;
2916 strlcpy(ifr
.ifr_name
, workbuf
, IFNAMSIZ
);
2919 ifnet_lock_shared(ifp
);
2922 ifa
= ifp
->if_addrhead
.tqh_first
;
2923 for (; space
> sizeof (ifr
) && ifa
;
2924 ifa
= ifa
->ifa_link
.tqe_next
) {
2925 struct sockaddr
*sa
;
2928 struct sockaddr_dl sdl
;
2929 uint8_t buf
[SOCK_MAXADDRLEN
+ 1];
2933 * Make sure to accomodate the largest possible
2934 * size of SA(if_lladdr)->sa_len.
2936 _CASSERT(sizeof (u
) == (SOCK_MAXADDRLEN
+ 1));
2942 if (ifa
== ifp
->if_lladdr
) {
2943 VERIFY(sa
->sa_family
== AF_LINK
);
2944 bcopy(sa
, &u
, sa
->sa_len
);
2946 ifnet_guarded_lladdr_copy_bytes(ifp
,
2947 LLADDR(&u
.sdl
), u
.sdl
.sdl_alen
);
2952 if (cmd
== OSIOCGIFCONF32
|| cmd
== OSIOCGIFCONF64
) {
2953 struct osockaddr
*osa
=
2954 (struct osockaddr
*)(void *)&ifr
.ifr_addr
;
2956 osa
->sa_family
= sa
->sa_family
;
2957 error
= copyout((caddr_t
)&ifr
, ifrp
,
2959 ifrp
+= sizeof (struct ifreq
);
2960 } else if (sa
->sa_len
<= sizeof (*sa
)) {
2962 error
= copyout((caddr_t
)&ifr
, ifrp
,
2964 ifrp
+= sizeof (struct ifreq
);
2967 sizeof (ifr
) + sa
->sa_len
- sizeof (*sa
)) {
2971 space
-= sa
->sa_len
- sizeof (*sa
);
2972 error
= copyout((caddr_t
)&ifr
, ifrp
,
2973 sizeof (ifr
.ifr_name
));
2975 error
= copyout((caddr_t
)sa
, (ifrp
+
2976 offsetof(struct ifreq
, ifr_addr
)),
2979 ifrp
+= (sa
->sa_len
+ offsetof(struct ifreq
,
2985 space
-= sizeof (ifr
);
2987 ifnet_lock_done(ifp
);
2992 bzero((caddr_t
)&ifr
.ifr_addr
, sizeof (ifr
.ifr_addr
));
2993 error
= copyout((caddr_t
)&ifr
, ifrp
, sizeof (ifr
));
2996 space
-= sizeof (ifr
);
2997 ifrp
+= sizeof (struct ifreq
);
3001 *ret_space
-= space
;
3002 net_thread_marks_pop(marks
);
3007 * Just like if_promisc(), but for all-multicast-reception mode.
3010 if_allmulti(struct ifnet
*ifp
, int onswitch
)
3015 ifnet_lock_exclusive(ifp
);
3018 if (ifp
->if_amcount
++ == 0) {
3019 ifp
->if_flags
|= IFF_ALLMULTI
;
3023 if (ifp
->if_amcount
> 1) {
3026 ifp
->if_amcount
= 0;
3027 ifp
->if_flags
&= ~IFF_ALLMULTI
;
3031 ifnet_lock_done(ifp
);
3034 error
= ifnet_ioctl(ifp
, 0, SIOCSIFFLAGS
, NULL
);
3041 static struct ifmultiaddr
*
3044 struct ifmultiaddr
*ifma
;
3046 ifma
= (how
== M_WAITOK
) ? zalloc(ifma_zone
) :
3047 zalloc_noblock(ifma_zone
);
3050 bzero(ifma
, ifma_size
);
3051 lck_mtx_init(&ifma
->ifma_lock
, ifa_mtx_grp
, ifa_mtx_attr
);
3052 ifma
->ifma_debug
|= IFD_ALLOC
;
3053 if (ifma_debug
!= 0) {
3054 ifma
->ifma_debug
|= IFD_DEBUG
;
3055 ifma
->ifma_trace
= ifma_trace
;
3062 ifma_free(struct ifmultiaddr
*ifma
)
3066 if (ifma
->ifma_protospec
!= NULL
) {
3067 panic("%s: Protospec not NULL for ifma=%p", __func__
, ifma
);
3069 } else if ((ifma
->ifma_flags
& IFMAF_ANONYMOUS
) ||
3070 ifma
->ifma_anoncnt
!= 0) {
3071 panic("%s: Freeing ifma=%p with outstanding anon req",
3074 } else if (ifma
->ifma_debug
& IFD_ATTACHED
) {
3075 panic("%s: ifma=%p attached to ifma_ifp=%p is being freed",
3076 __func__
, ifma
, ifma
->ifma_ifp
);
3078 } else if (!(ifma
->ifma_debug
& IFD_ALLOC
)) {
3079 panic("%s: ifma %p cannot be freed", __func__
, ifma
);
3081 } else if (ifma
->ifma_refcount
!= 0) {
3082 panic("%s: non-zero refcount ifma=%p", __func__
, ifma
);
3084 } else if (ifma
->ifma_reqcnt
!= 0) {
3085 panic("%s: non-zero reqcnt ifma=%p", __func__
, ifma
);
3087 } else if (ifma
->ifma_ifp
!= NULL
) {
3088 panic("%s: non-NULL ifma_ifp=%p for ifma=%p", __func__
,
3089 ifma
->ifma_ifp
, ifma
);
3091 } else if (ifma
->ifma_ll
!= NULL
) {
3092 panic("%s: non-NULL ifma_ll=%p for ifma=%p", __func__
,
3093 ifma
->ifma_ll
, ifma
);
3096 ifma
->ifma_debug
&= ~IFD_ALLOC
;
3097 if ((ifma
->ifma_debug
& (IFD_DEBUG
| IFD_TRASHED
)) ==
3098 (IFD_DEBUG
| IFD_TRASHED
)) {
3099 lck_mtx_lock(&ifma_trash_lock
);
3100 TAILQ_REMOVE(&ifma_trash_head
, (struct ifmultiaddr_dbg
*)ifma
,
3102 lck_mtx_unlock(&ifma_trash_lock
);
3103 ifma
->ifma_debug
&= ~IFD_TRASHED
;
3107 if (ifma
->ifma_addr
!= NULL
) {
3108 FREE(ifma
->ifma_addr
, M_IFADDR
);
3109 ifma
->ifma_addr
= NULL
;
3111 lck_mtx_destroy(&ifma
->ifma_lock
, ifa_mtx_grp
);
3112 zfree(ifma_zone
, ifma
);
3116 ifma_trace(struct ifmultiaddr
*ifma
, int refhold
)
3118 struct ifmultiaddr_dbg
*ifma_dbg
= (struct ifmultiaddr_dbg
*)ifma
;
3123 if (!(ifma
->ifma_debug
& IFD_DEBUG
)) {
3124 panic("%s: ifma %p has no debug structure", __func__
, ifma
);
3128 cnt
= &ifma_dbg
->ifma_refhold_cnt
;
3129 tr
= ifma_dbg
->ifma_refhold
;
3131 cnt
= &ifma_dbg
->ifma_refrele_cnt
;
3132 tr
= ifma_dbg
->ifma_refrele
;
3135 idx
= atomic_add_16_ov(cnt
, 1) % IFMA_TRACE_HIST_SIZE
;
3136 ctrace_record(&tr
[idx
]);
3140 ifma_addref(struct ifmultiaddr
*ifma
, int locked
)
3145 IFMA_LOCK_ASSERT_HELD(ifma
);
3147 if (++ifma
->ifma_refcount
== 0) {
3148 panic("%s: ifma=%p wraparound refcnt", __func__
, ifma
);
3150 } else if (ifma
->ifma_trace
!= NULL
) {
3151 (*ifma
->ifma_trace
)(ifma
, TRUE
);
3158 ifma_remref(struct ifmultiaddr
*ifma
)
3160 struct ifmultiaddr
*ll
;
3164 if (ifma
->ifma_refcount
== 0) {
3165 panic("%s: ifma=%p negative refcnt", __func__
, ifma
);
3167 } else if (ifma
->ifma_trace
!= NULL
) {
3168 (*ifma
->ifma_trace
)(ifma
, FALSE
);
3171 --ifma
->ifma_refcount
;
3172 if (ifma
->ifma_refcount
> 0) {
3178 ifma
->ifma_ifp
= NULL
;
3179 ifma
->ifma_ll
= NULL
;
3181 ifma_free(ifma
); /* deallocate it */
3188 if_attach_ifma(struct ifnet
*ifp
, struct ifmultiaddr
*ifma
, int anon
)
3190 ifnet_lock_assert(ifp
, IFNET_LCK_ASSERT_EXCLUSIVE
);
3191 IFMA_LOCK_ASSERT_HELD(ifma
);
3193 if (ifma
->ifma_ifp
!= ifp
) {
3194 panic("%s: Mismatch ifma_ifp=%p != ifp=%p", __func__
,
3195 ifma
->ifma_ifp
, ifp
);
3197 } else if (ifma
->ifma_debug
& IFD_ATTACHED
) {
3198 panic("%s: Attempt to attach an already attached ifma=%p",
3201 } else if (anon
&& (ifma
->ifma_flags
& IFMAF_ANONYMOUS
)) {
3202 panic("%s: ifma=%p unexpected IFMAF_ANONYMOUS", __func__
, ifma
);
3204 } else if (ifma
->ifma_debug
& IFD_TRASHED
) {
3205 panic("%s: Attempt to reattach a detached ifma=%p",
3210 ifma
->ifma_reqcnt
++;
3211 VERIFY(ifma
->ifma_reqcnt
== 1);
3212 IFMA_ADDREF_LOCKED(ifma
);
3213 ifma
->ifma_debug
|= IFD_ATTACHED
;
3215 ifma
->ifma_anoncnt
++;
3216 VERIFY(ifma
->ifma_anoncnt
== 1);
3217 ifma
->ifma_flags
|= IFMAF_ANONYMOUS
;
3220 LIST_INSERT_HEAD(&ifp
->if_multiaddrs
, ifma
, ifma_link
);
3224 if_detach_ifma(struct ifnet
*ifp
, struct ifmultiaddr
*ifma
, int anon
)
3226 ifnet_lock_assert(ifp
, IFNET_LCK_ASSERT_EXCLUSIVE
);
3227 IFMA_LOCK_ASSERT_HELD(ifma
);
3229 if (ifma
->ifma_reqcnt
== 0) {
3230 panic("%s: ifma=%p negative reqcnt", __func__
, ifma
);
3232 } else if (anon
&& !(ifma
->ifma_flags
& IFMAF_ANONYMOUS
)) {
3233 panic("%s: ifma=%p missing IFMAF_ANONYMOUS", __func__
, ifma
);
3235 } else if (anon
&& ifma
->ifma_anoncnt
== 0) {
3236 panic("%s: ifma=%p negative anonreqcnt", __func__
, ifma
);
3238 } else if (ifma
->ifma_ifp
!= ifp
) {
3239 panic("%s: Mismatch ifma_ifp=%p, ifp=%p", __func__
,
3240 ifma
->ifma_ifp
, ifp
);
3245 --ifma
->ifma_anoncnt
;
3246 if (ifma
->ifma_anoncnt
> 0)
3248 ifma
->ifma_flags
&= ~IFMAF_ANONYMOUS
;
3251 --ifma
->ifma_reqcnt
;
3252 if (ifma
->ifma_reqcnt
> 0)
3255 if (ifma
->ifma_protospec
!= NULL
) {
3256 panic("%s: Protospec not NULL for ifma=%p", __func__
, ifma
);
3258 } else if ((ifma
->ifma_flags
& IFMAF_ANONYMOUS
) ||
3259 ifma
->ifma_anoncnt
!= 0) {
3260 panic("%s: Detaching ifma=%p with outstanding anon req",
3263 } else if (!(ifma
->ifma_debug
& IFD_ATTACHED
)) {
3264 panic("%s: Attempt to detach an unattached address ifma=%p",
3267 } else if (ifma
->ifma_debug
& IFD_TRASHED
) {
3268 panic("%s: ifma %p is already in trash list", __func__
, ifma
);
3273 * NOTE: Caller calls IFMA_REMREF
3275 ifma
->ifma_debug
&= ~IFD_ATTACHED
;
3276 LIST_REMOVE(ifma
, ifma_link
);
3277 if (LIST_EMPTY(&ifp
->if_multiaddrs
))
3278 ifp
->if_updatemcasts
= 0;
3280 if (ifma
->ifma_debug
& IFD_DEBUG
) {
3281 /* Become a regular mutex, just in case */
3282 IFMA_CONVERT_LOCK(ifma
);
3283 lck_mtx_lock(&ifma_trash_lock
);
3284 TAILQ_INSERT_TAIL(&ifma_trash_head
,
3285 (struct ifmultiaddr_dbg
*)ifma
, ifma_trash_link
);
3286 lck_mtx_unlock(&ifma_trash_lock
);
3287 ifma
->ifma_debug
|= IFD_TRASHED
;
3294 * Find an ifmultiaddr that matches a socket address on an interface.
3296 * Caller is responsible for holding the ifnet_lock while calling
3300 if_addmulti_doesexist(struct ifnet
*ifp
, const struct sockaddr
*sa
,
3301 struct ifmultiaddr
**retifma
, int anon
)
3303 struct ifmultiaddr
*ifma
;
3305 for (ifma
= LIST_FIRST(&ifp
->if_multiaddrs
); ifma
!= NULL
;
3306 ifma
= LIST_NEXT(ifma
, ifma_link
)) {
3307 IFMA_LOCK_SPIN(ifma
);
3308 if (!equal(sa
, ifma
->ifma_addr
)) {
3313 VERIFY(!(ifma
->ifma_flags
& IFMAF_ANONYMOUS
) ||
3314 ifma
->ifma_anoncnt
!= 0);
3315 VERIFY((ifma
->ifma_flags
& IFMAF_ANONYMOUS
) ||
3316 ifma
->ifma_anoncnt
== 0);
3317 ifma
->ifma_anoncnt
++;
3318 if (!(ifma
->ifma_flags
& IFMAF_ANONYMOUS
)) {
3319 VERIFY(ifma
->ifma_anoncnt
== 1);
3320 ifma
->ifma_flags
|= IFMAF_ANONYMOUS
;
3323 if (!anon
|| ifma
->ifma_anoncnt
== 1) {
3324 ifma
->ifma_reqcnt
++;
3325 VERIFY(ifma
->ifma_reqcnt
> 1);
3327 if (retifma
!= NULL
) {
3329 IFMA_ADDREF_LOCKED(ifma
);
3338 * Radar 3642395, make sure all multicasts are in a standard format.
3340 static struct sockaddr
*
3341 copy_and_normalize(const struct sockaddr
*original
)
3344 const u_char
*aptr
= NULL
;
3345 struct sockaddr
*copy
= NULL
;
3346 struct sockaddr_dl
*sdl_new
= NULL
;
3349 if (original
->sa_family
!= AF_LINK
&&
3350 original
->sa_family
!= AF_UNSPEC
) {
3351 /* Just make a copy */
3352 MALLOC(copy
, struct sockaddr
*, original
->sa_len
,
3353 M_IFADDR
, M_WAITOK
);
3355 bcopy(original
, copy
, original
->sa_len
);
3359 switch (original
->sa_family
) {
3361 const struct sockaddr_dl
*sdl_original
=
3362 (struct sockaddr_dl
*)(uintptr_t)(size_t)original
;
3364 if (sdl_original
->sdl_nlen
+ sdl_original
->sdl_alen
+
3365 sdl_original
->sdl_slen
+
3366 offsetof(struct sockaddr_dl
, sdl_data
) >
3367 sdl_original
->sdl_len
)
3370 alen
= sdl_original
->sdl_alen
;
3371 aptr
= CONST_LLADDR(sdl_original
);
3376 if (original
->sa_len
< ETHER_ADDR_LEN
+
3377 offsetof(struct sockaddr
, sa_data
)) {
3381 alen
= ETHER_ADDR_LEN
;
3382 aptr
= (const u_char
*)original
->sa_data
;
3387 if (alen
== 0 || aptr
== NULL
)
3390 len
= alen
+ offsetof(struct sockaddr_dl
, sdl_data
);
3391 MALLOC(sdl_new
, struct sockaddr_dl
*, len
, M_IFADDR
, M_WAITOK
);
3393 if (sdl_new
!= NULL
) {
3394 bzero(sdl_new
, len
);
3395 sdl_new
->sdl_len
= len
;
3396 sdl_new
->sdl_family
= AF_LINK
;
3397 sdl_new
->sdl_alen
= alen
;
3398 bcopy(aptr
, LLADDR(sdl_new
), alen
);
3401 return ((struct sockaddr
*)sdl_new
);
3405 * Network-layer protocol domains which hold references to the underlying
3406 * link-layer record must use this routine.
3409 if_addmulti(struct ifnet
*ifp
, const struct sockaddr
*sa
,
3410 struct ifmultiaddr
**retifma
)
3412 return (if_addmulti_common(ifp
, sa
, retifma
, 0));
3416 * Anything other than network-layer protocol domains which hold references
3417 * to the underlying link-layer record must use this routine: SIOCADDMULTI
3418 * ioctl, ifnet_add_multicast(), if_bond.
3421 if_addmulti_anon(struct ifnet
*ifp
, const struct sockaddr
*sa
,
3422 struct ifmultiaddr
**retifma
)
3424 return (if_addmulti_common(ifp
, sa
, retifma
, 1));
3428 * Register an additional multicast address with a network interface.
3430 * - If the address is already present, bump the reference count on the
3431 * address and return.
3432 * - If the address is not link-layer, look up a link layer address.
3433 * - Allocate address structures for one or both addresses, and attach to the
3434 * multicast address list on the interface. If automatically adding a link
3435 * layer address, the protocol address will own a reference to the link
3436 * layer address, to be freed when it is freed.
3437 * - Notify the network device driver of an addition to the multicast address
3440 * 'sa' points to caller-owned memory with the desired multicast address.
3442 * 'retifma' will be used to return a pointer to the resulting multicast
3443 * address reference, if desired.
3445 * 'anon' indicates a link-layer address with no protocol address reference
3446 * made to it. Anything other than network-layer protocol domain requests
3447 * are considered as anonymous.
3450 if_addmulti_common(struct ifnet
*ifp
, const struct sockaddr
*sa
,
3451 struct ifmultiaddr
**retifma
, int anon
)
3453 struct sockaddr_storage storage
;
3454 struct sockaddr
*llsa
= NULL
;
3455 struct sockaddr
*dupsa
= NULL
;
3456 int error
= 0, ll_firstref
= 0, lladdr
;
3457 struct ifmultiaddr
*ifma
= NULL
;
3458 struct ifmultiaddr
*llifma
= NULL
;
3460 /* Only AF_UNSPEC/AF_LINK is allowed for an "anonymous" address */
3461 VERIFY(!anon
|| sa
->sa_family
== AF_UNSPEC
||
3462 sa
->sa_family
== AF_LINK
);
3464 /* If sa is a AF_LINK or AF_UNSPEC, duplicate and normalize it */
3465 if (sa
->sa_family
== AF_LINK
|| sa
->sa_family
== AF_UNSPEC
) {
3466 dupsa
= copy_and_normalize(sa
);
3467 if (dupsa
== NULL
) {
3474 ifnet_lock_exclusive(ifp
);
3475 if (!(ifp
->if_flags
& IFF_MULTICAST
)) {
3476 error
= EADDRNOTAVAIL
;
3477 ifnet_lock_done(ifp
);
3481 /* If the address is already present, return a new reference to it */
3482 error
= if_addmulti_doesexist(ifp
, sa
, retifma
, anon
);
3483 ifnet_lock_done(ifp
);
3488 * The address isn't already present; give the link layer a chance
3489 * to accept/reject it, and also find out which AF_LINK address this
3490 * maps to, if it isn't one already.
3492 error
= dlil_resolve_multi(ifp
, sa
, (struct sockaddr
*)&storage
,
3494 if (error
== 0 && storage
.ss_len
!= 0) {
3495 llsa
= copy_and_normalize((struct sockaddr
*)&storage
);
3501 llifma
= ifma_alloc(M_WAITOK
);
3502 if (llifma
== NULL
) {
3508 /* to be similar to FreeBSD */
3509 if (error
== EOPNOTSUPP
)
3511 else if (error
!= 0)
3514 /* Allocate while we aren't holding any locks */
3515 if (dupsa
== NULL
) {
3516 dupsa
= copy_and_normalize(sa
);
3517 if (dupsa
== NULL
) {
3522 ifma
= ifma_alloc(M_WAITOK
);
3528 ifnet_lock_exclusive(ifp
);
3530 * Check again for the matching multicast.
3532 error
= if_addmulti_doesexist(ifp
, sa
, retifma
, anon
);
3534 ifnet_lock_done(ifp
);
3538 if (llifma
!= NULL
) {
3539 VERIFY(!anon
); /* must not get here if "anonymous" */
3540 if (if_addmulti_doesexist(ifp
, llsa
, &ifma
->ifma_ll
, 0) == 0) {
3541 FREE(llsa
, M_IFADDR
);
3545 VERIFY(ifma
->ifma_ll
->ifma_ifp
== ifp
);
3548 llifma
->ifma_addr
= llsa
;
3549 llifma
->ifma_ifp
= ifp
;
3551 if_attach_ifma(ifp
, llifma
, 0);
3552 /* add extra refcnt for ifma */
3553 IFMA_ADDREF_LOCKED(llifma
);
3554 IFMA_UNLOCK(llifma
);
3555 ifma
->ifma_ll
= llifma
;
3559 /* "anonymous" request should not result in network address */
3560 VERIFY(!anon
|| ifma
->ifma_ll
== NULL
);
3562 ifma
->ifma_addr
= dupsa
;
3563 ifma
->ifma_ifp
= ifp
;
3565 if_attach_ifma(ifp
, ifma
, anon
);
3566 IFMA_ADDREF_LOCKED(ifma
); /* for this routine */
3567 if (retifma
!= NULL
) {
3569 IFMA_ADDREF_LOCKED(*retifma
); /* for caller */
3571 lladdr
= (ifma
->ifma_addr
->sa_family
== AF_UNSPEC
||
3572 ifma
->ifma_addr
->sa_family
== AF_LINK
);
3574 ifnet_lock_done(ifp
);
3576 rt_newmaddrmsg(RTM_NEWMADDR
, ifma
);
3577 IFMA_REMREF(ifma
); /* for this routine */
3580 * We are certain we have added something, so call down to the
3581 * interface to let them know about it. Do this only for newly-
3582 * added AF_LINK/AF_UNSPEC address in the if_multiaddrs set.
3584 if (lladdr
|| ll_firstref
)
3585 (void) ifnet_ioctl(ifp
, 0, SIOCADDMULTI
, NULL
);
3587 if (ifp
->if_updatemcasts
> 0)
3588 ifp
->if_updatemcasts
= 0;
3596 FREE(dupsa
, M_IFADDR
);
3600 FREE(llsa
, M_IFADDR
);
3606 * Delete a multicast group membership by network-layer group address.
3607 * This routine is deprecated.
3610 if_delmulti(struct ifnet
*ifp
, const struct sockaddr
*sa
)
3612 return (if_delmulti_common(NULL
, ifp
, sa
, 0));
3616 * Delete a multicast group membership by group membership pointer.
3617 * Network-layer protocol domains must use this routine.
3620 if_delmulti_ifma(struct ifmultiaddr
*ifma
)
3622 return (if_delmulti_common(ifma
, NULL
, NULL
, 0));
3626 * Anything other than network-layer protocol domains which hold references
3627 * to the underlying link-layer record must use this routine: SIOCDELMULTI
3628 * ioctl, ifnet_remove_multicast(), if_bond.
3631 if_delmulti_anon(struct ifnet
*ifp
, const struct sockaddr
*sa
)
3633 return (if_delmulti_common(NULL
, ifp
, sa
, 1));
3637 * Delete a multicast group membership by network-layer group address.
3639 * Returns ENOENT if the entry could not be found.
3642 if_delmulti_common(struct ifmultiaddr
*ifma
, struct ifnet
*ifp
,
3643 const struct sockaddr
*sa
, int anon
)
3645 struct sockaddr
*dupsa
= NULL
;
3646 int lastref
, ll_lastref
= 0, lladdr
;
3647 struct ifmultiaddr
*ll
= NULL
;
3649 /* sanity check for callers */
3650 VERIFY(ifma
!= NULL
|| (ifp
!= NULL
&& sa
!= NULL
));
3653 ifp
= ifma
->ifma_ifp
;
3656 (sa
->sa_family
== AF_LINK
|| sa
->sa_family
== AF_UNSPEC
)) {
3657 dupsa
= copy_and_normalize(sa
);
3663 ifnet_lock_exclusive(ifp
);
3665 for (ifma
= LIST_FIRST(&ifp
->if_multiaddrs
); ifma
!= NULL
;
3666 ifma
= LIST_NEXT(ifma
, ifma_link
)) {
3668 if (!equal(sa
, ifma
->ifma_addr
) ||
3669 (anon
&& !(ifma
->ifma_flags
& IFMAF_ANONYMOUS
))) {
3670 VERIFY(!(ifma
->ifma_flags
& IFMAF_ANONYMOUS
) ||
3671 ifma
->ifma_anoncnt
!= 0);
3675 /* found; keep it locked */
3680 FREE(dupsa
, M_IFADDR
);
3681 ifnet_lock_done(ifp
);
3687 IFMA_LOCK_ASSERT_HELD(ifma
);
3688 IFMA_ADDREF_LOCKED(ifma
); /* for this routine */
3689 lastref
= if_detach_ifma(ifp
, ifma
, anon
);
3690 VERIFY(!lastref
|| (!(ifma
->ifma_debug
& IFD_ATTACHED
) &&
3691 ifma
->ifma_reqcnt
== 0));
3692 VERIFY(!anon
|| ifma
->ifma_ll
== NULL
);
3694 lladdr
= (ifma
->ifma_addr
->sa_family
== AF_UNSPEC
||
3695 ifma
->ifma_addr
->sa_family
== AF_LINK
);
3697 if (lastref
&& ll
!= NULL
) {
3699 ll_lastref
= if_detach_ifma(ifp
, ll
, 0);
3702 ifnet_lock_done(ifp
);
3705 rt_newmaddrmsg(RTM_DELMADDR
, ifma
);
3707 if ((ll
== NULL
&& lastref
&& lladdr
) || ll_lastref
) {
3709 * Make sure the interface driver is notified in the
3710 * case of a link layer mcast group being left. Do
3711 * this only for a AF_LINK/AF_UNSPEC address that has
3712 * been removed from the if_multiaddrs set.
3714 ifnet_ioctl(ifp
, 0, SIOCDELMULTI
, NULL
);
3718 IFMA_REMREF(ifma
); /* for if_multiaddrs list */
3720 IFMA_REMREF(ll
); /* for if_multiaddrs list */
3722 IFMA_REMREF(ifma
); /* for this routine */
3724 FREE(dupsa
, M_IFADDR
);
3730 * Shutdown all network activity. Used boot() when halting
3740 if (ifnet_list_get_all(IFNET_FAMILY_ANY
, &ifp
, &count
) == 0) {
3741 for (i
= 0; i
< count
; i
++) {
3743 dlil_proto_unplumb_all(ifp
[i
]);
3745 ifnet_list_free(ifp
);
3752 * Delete Routes for a Network Interface
3754 * Called for each routing entry via the rnh->rnh_walktree() call above
3755 * to delete all route entries referencing a detaching network interface.
3758 * rn pointer to node in the routing table
3759 * arg argument passed to rnh->rnh_walktree() - detaching interface
3763 * errno failed - reason indicated
3767 if_rtdel(struct radix_node
*rn
, void *arg
)
3769 struct rtentry
*rt
= (struct rtentry
*)rn
;
3770 struct ifnet
*ifp
= arg
;
3776 * Checking against RTF_UP protects against walktree
3777 * recursion problems with cloned routes.
3780 if (rt
->rt_ifp
== ifp
&& (rt
->rt_flags
& RTF_UP
)) {
3782 * Safe to drop rt_lock and use rt_key, rt_gateway,
3783 * since holding rnh_lock here prevents another thread
3784 * from calling rt_setgate() on this route.
3787 err
= rtrequest_locked(RTM_DELETE
, rt_key(rt
), rt
->rt_gateway
,
3788 rt_mask(rt
), rt
->rt_flags
, NULL
);
3790 log(LOG_WARNING
, "if_rtdel: error %d\n", err
);
3799 * Removes routing table reference to a given interface
3800 * for a given protocol family
3803 if_rtproto_del(struct ifnet
*ifp
, int protocol
)
3805 struct radix_node_head
*rnh
;
3807 if ((protocol
<= AF_MAX
) && (protocol
>= 0) &&
3808 ((rnh
= rt_tables
[protocol
]) != NULL
) && (ifp
!= NULL
)) {
3809 lck_mtx_lock(rnh_lock
);
3810 (void) rnh
->rnh_walktree(rnh
, if_rtdel
, ifp
);
3811 lck_mtx_unlock(rnh_lock
);
3816 if_rtmtu(struct radix_node
*rn
, void *arg
)
3818 struct rtentry
*rt
= (struct rtentry
*)rn
;
3819 struct ifnet
*ifp
= arg
;
3822 if (rt
->rt_ifp
== ifp
) {
3824 * Update the MTU of this entry only if the MTU
3825 * has not been locked (RTV_MTU is not set) and
3826 * if it was non-zero to begin with.
3828 if (!(rt
->rt_rmx
.rmx_locks
& RTV_MTU
) && rt
->rt_rmx
.rmx_mtu
)
3829 rt
->rt_rmx
.rmx_mtu
= ifp
->if_mtu
;
3837 * Update the MTU metric of all route entries in all protocol tables
3838 * associated with a particular interface; this is called when the
3839 * MTU of that interface has changed.
3842 void if_rtmtu_update(struct ifnet
*ifp
)
3844 struct radix_node_head
*rnh
;
3847 for (p
= 0; p
< AF_MAX
+ 1; p
++) {
3848 if ((rnh
= rt_tables
[p
]) == NULL
)
3851 lck_mtx_lock(rnh_lock
);
3852 (void) rnh
->rnh_walktree(rnh
, if_rtmtu
, ifp
);
3853 lck_mtx_unlock(rnh_lock
);
3855 routegenid_update();
3858 __private_extern__
void
3859 if_data_internal_to_if_data(struct ifnet
*ifp
,
3860 const struct if_data_internal
*if_data_int
, struct if_data
*if_data
)
3863 #define COPYFIELD(fld) if_data->fld = if_data_int->fld
3864 #define COPYFIELD32(fld) if_data->fld = (u_int32_t)(if_data_int->fld)
3865 /* compiler will cast down to 32-bit */
3866 #define COPYFIELD32_ATOMIC(fld) do { \
3867 atomic_get_64(if_data->fld, \
3868 (u_int64_t *)(void *)(uintptr_t)&if_data_int->fld); \
3871 COPYFIELD(ifi_type
);
3872 COPYFIELD(ifi_typelen
);
3873 COPYFIELD(ifi_physical
);
3874 COPYFIELD(ifi_addrlen
);
3875 COPYFIELD(ifi_hdrlen
);
3876 COPYFIELD(ifi_recvquota
);
3877 COPYFIELD(ifi_xmitquota
);
3878 if_data
->ifi_unused1
= 0;
3880 COPYFIELD(ifi_metric
);
3881 if (if_data_int
->ifi_baudrate
& 0xFFFFFFFF00000000LL
) {
3882 if_data
->ifi_baudrate
= 0xFFFFFFFF;
3884 COPYFIELD32(ifi_baudrate
);
3887 COPYFIELD32_ATOMIC(ifi_ipackets
);
3888 COPYFIELD32_ATOMIC(ifi_ierrors
);
3889 COPYFIELD32_ATOMIC(ifi_opackets
);
3890 COPYFIELD32_ATOMIC(ifi_oerrors
);
3891 COPYFIELD32_ATOMIC(ifi_collisions
);
3892 COPYFIELD32_ATOMIC(ifi_ibytes
);
3893 COPYFIELD32_ATOMIC(ifi_obytes
);
3894 COPYFIELD32_ATOMIC(ifi_imcasts
);
3895 COPYFIELD32_ATOMIC(ifi_omcasts
);
3896 COPYFIELD32_ATOMIC(ifi_iqdrops
);
3897 COPYFIELD32_ATOMIC(ifi_noproto
);
3899 COPYFIELD(ifi_recvtiming
);
3900 COPYFIELD(ifi_xmittiming
);
3902 if_data
->ifi_lastchange
.tv_sec
= if_data_int
->ifi_lastchange
.tv_sec
;
3903 if_data
->ifi_lastchange
.tv_usec
= if_data_int
->ifi_lastchange
.tv_usec
;
3905 if_data
->ifi_lastchange
.tv_sec
+= boottime_sec();
3907 if_data
->ifi_unused2
= 0;
3908 COPYFIELD(ifi_hwassist
);
3909 if_data
->ifi_reserved1
= 0;
3910 if_data
->ifi_reserved2
= 0;
3911 #undef COPYFIELD32_ATOMIC
3916 __private_extern__
void
3917 if_data_internal_to_if_data64(struct ifnet
*ifp
,
3918 const struct if_data_internal
*if_data_int
,
3919 struct if_data64
*if_data64
)
3922 #define COPYFIELD64(fld) if_data64->fld = if_data_int->fld
3923 #define COPYFIELD64_ATOMIC(fld) do { \
3924 atomic_get_64(if_data64->fld, \
3925 (u_int64_t *)(void *)(uintptr_t)&if_data_int->fld); \
3928 COPYFIELD64(ifi_type
);
3929 COPYFIELD64(ifi_typelen
);
3930 COPYFIELD64(ifi_physical
);
3931 COPYFIELD64(ifi_addrlen
);
3932 COPYFIELD64(ifi_hdrlen
);
3933 COPYFIELD64(ifi_recvquota
);
3934 COPYFIELD64(ifi_xmitquota
);
3935 if_data64
->ifi_unused1
= 0;
3936 COPYFIELD64(ifi_mtu
);
3937 COPYFIELD64(ifi_metric
);
3938 COPYFIELD64(ifi_baudrate
);
3940 COPYFIELD64_ATOMIC(ifi_ipackets
);
3941 COPYFIELD64_ATOMIC(ifi_ierrors
);
3942 COPYFIELD64_ATOMIC(ifi_opackets
);
3943 COPYFIELD64_ATOMIC(ifi_oerrors
);
3944 COPYFIELD64_ATOMIC(ifi_collisions
);
3945 COPYFIELD64_ATOMIC(ifi_ibytes
);
3946 COPYFIELD64_ATOMIC(ifi_obytes
);
3947 COPYFIELD64_ATOMIC(ifi_imcasts
);
3948 COPYFIELD64_ATOMIC(ifi_omcasts
);
3949 COPYFIELD64_ATOMIC(ifi_iqdrops
);
3950 COPYFIELD64_ATOMIC(ifi_noproto
);
3952 /* Note these two fields are actually 32 bit, so doing COPYFIELD64_ATOMIC will
3953 * cause them to be misaligned
3955 COPYFIELD64(ifi_recvtiming
);
3956 COPYFIELD64(ifi_xmittiming
);
3958 if_data64
->ifi_lastchange
.tv_sec
= if_data_int
->ifi_lastchange
.tv_sec
;
3959 if_data64
->ifi_lastchange
.tv_usec
= if_data_int
->ifi_lastchange
.tv_usec
;
3961 if_data64
->ifi_lastchange
.tv_sec
+= boottime_sec();
3966 __private_extern__
void
3967 if_copy_traffic_class(struct ifnet
*ifp
,
3968 struct if_traffic_class
*if_tc
)
3970 #define COPY_IF_TC_FIELD64_ATOMIC(fld) do { \
3971 atomic_get_64(if_tc->fld, \
3972 (u_int64_t *)(void *)(uintptr_t)&ifp->if_tc.fld); \
3975 bzero(if_tc
, sizeof (*if_tc
));
3976 COPY_IF_TC_FIELD64_ATOMIC(ifi_ibepackets
);
3977 COPY_IF_TC_FIELD64_ATOMIC(ifi_ibebytes
);
3978 COPY_IF_TC_FIELD64_ATOMIC(ifi_obepackets
);
3979 COPY_IF_TC_FIELD64_ATOMIC(ifi_obebytes
);
3980 COPY_IF_TC_FIELD64_ATOMIC(ifi_ibkpackets
);
3981 COPY_IF_TC_FIELD64_ATOMIC(ifi_ibkbytes
);
3982 COPY_IF_TC_FIELD64_ATOMIC(ifi_obkpackets
);
3983 COPY_IF_TC_FIELD64_ATOMIC(ifi_obkbytes
);
3984 COPY_IF_TC_FIELD64_ATOMIC(ifi_ivipackets
);
3985 COPY_IF_TC_FIELD64_ATOMIC(ifi_ivibytes
);
3986 COPY_IF_TC_FIELD64_ATOMIC(ifi_ovipackets
);
3987 COPY_IF_TC_FIELD64_ATOMIC(ifi_ovibytes
);
3988 COPY_IF_TC_FIELD64_ATOMIC(ifi_ivopackets
);
3989 COPY_IF_TC_FIELD64_ATOMIC(ifi_ivobytes
);
3990 COPY_IF_TC_FIELD64_ATOMIC(ifi_ovopackets
);
3991 COPY_IF_TC_FIELD64_ATOMIC(ifi_ovobytes
);
3992 COPY_IF_TC_FIELD64_ATOMIC(ifi_ipvpackets
);
3993 COPY_IF_TC_FIELD64_ATOMIC(ifi_ipvbytes
);
3994 COPY_IF_TC_FIELD64_ATOMIC(ifi_opvpackets
);
3995 COPY_IF_TC_FIELD64_ATOMIC(ifi_opvbytes
);
3997 #undef COPY_IF_TC_FIELD64_ATOMIC
4001 if_copy_data_extended(struct ifnet
*ifp
, struct if_data_extended
*if_de
)
4003 #define COPY_IF_DE_FIELD64_ATOMIC(fld) do { \
4004 atomic_get_64(if_de->fld, \
4005 (u_int64_t *)(void *)(uintptr_t)&ifp->if_data.fld); \
4008 bzero(if_de
, sizeof (*if_de
));
4009 COPY_IF_DE_FIELD64_ATOMIC(ifi_alignerrs
);
4010 COPY_IF_DE_FIELD64_ATOMIC(ifi_dt_bytes
);
4011 COPY_IF_DE_FIELD64_ATOMIC(ifi_fpackets
);
4012 COPY_IF_DE_FIELD64_ATOMIC(ifi_fbytes
);
4014 #undef COPY_IF_DE_FIELD64_ATOMIC
4018 if_copy_packet_stats(struct ifnet
*ifp
, struct if_packet_stats
*if_ps
)
4020 #define COPY_IF_PS_TCP_FIELD64_ATOMIC(fld) do { \
4021 atomic_get_64(if_ps->ifi_tcp_##fld, \
4022 (u_int64_t *)(void *)(uintptr_t)&ifp->if_tcp_stat->fld); \
4025 #define COPY_IF_PS_UDP_FIELD64_ATOMIC(fld) do { \
4026 atomic_get_64(if_ps->ifi_udp_##fld, \
4027 (u_int64_t *)(void *)(uintptr_t)&ifp->if_udp_stat->fld); \
4030 COPY_IF_PS_TCP_FIELD64_ATOMIC(badformat
);
4031 COPY_IF_PS_TCP_FIELD64_ATOMIC(unspecv6
);
4032 COPY_IF_PS_TCP_FIELD64_ATOMIC(synfin
);
4033 COPY_IF_PS_TCP_FIELD64_ATOMIC(badformatipsec
);
4034 COPY_IF_PS_TCP_FIELD64_ATOMIC(noconnnolist
);
4035 COPY_IF_PS_TCP_FIELD64_ATOMIC(noconnlist
);
4036 COPY_IF_PS_TCP_FIELD64_ATOMIC(listbadsyn
);
4037 COPY_IF_PS_TCP_FIELD64_ATOMIC(icmp6unreach
);
4038 COPY_IF_PS_TCP_FIELD64_ATOMIC(deprecate6
);
4039 COPY_IF_PS_TCP_FIELD64_ATOMIC(ooopacket
);
4040 COPY_IF_PS_TCP_FIELD64_ATOMIC(rstinsynrcv
);
4041 COPY_IF_PS_TCP_FIELD64_ATOMIC(dospacket
);
4042 COPY_IF_PS_TCP_FIELD64_ATOMIC(cleanup
);
4043 COPY_IF_PS_TCP_FIELD64_ATOMIC(synwindow
);
4045 COPY_IF_PS_UDP_FIELD64_ATOMIC(port_unreach
);
4046 COPY_IF_PS_UDP_FIELD64_ATOMIC(faithprefix
);
4047 COPY_IF_PS_UDP_FIELD64_ATOMIC(port0
);
4048 COPY_IF_PS_UDP_FIELD64_ATOMIC(badlength
);
4049 COPY_IF_PS_UDP_FIELD64_ATOMIC(badchksum
);
4050 COPY_IF_PS_UDP_FIELD64_ATOMIC(badmcast
);
4051 COPY_IF_PS_UDP_FIELD64_ATOMIC(cleanup
);
4052 COPY_IF_PS_UDP_FIELD64_ATOMIC(badipsec
);
4054 #undef COPY_IF_PS_TCP_FIELD64_ATOMIC
4055 #undef COPY_IF_PS_UDP_FIELD64_ATOMIC
4059 if_copy_rxpoll_stats(struct ifnet
*ifp
, struct if_rxpoll_stats
*if_rs
)
4061 bzero(if_rs
, sizeof (*if_rs
));
4062 if (!(ifp
->if_eflags
& IFEF_RXPOLL
) || !ifnet_is_attached(ifp
, 1))
4065 /* by now, ifnet will stay attached so if_inp must be valid */
4066 VERIFY(ifp
->if_inp
!= NULL
);
4067 bcopy(&ifp
->if_inp
->pstats
, if_rs
, sizeof (*if_rs
));
4069 /* Release the IO refcnt */
4070 ifnet_decr_iorefcnt(ifp
);
4074 ifa_remref(struct ifaddr
*ifa
, int locked
)
4079 IFA_LOCK_ASSERT_HELD(ifa
);
4081 if (ifa
->ifa_refcnt
== 0)
4082 panic("%s: ifa %p negative refcnt\n", __func__
, ifa
);
4083 else if (ifa
->ifa_trace
!= NULL
)
4084 (*ifa
->ifa_trace
)(ifa
, FALSE
);
4085 if (--ifa
->ifa_refcnt
== 0) {
4086 if (ifa
->ifa_debug
& IFD_ATTACHED
)
4087 panic("ifa %p attached to ifp is being freed\n", ifa
);
4089 * Some interface addresses are allocated either statically
4090 * or carved out of a larger block. Only free it if it was
4091 * allocated via MALLOC or via the corresponding per-address
4092 * family allocator. Otherwise, leave it alone.
4094 if (ifa
->ifa_debug
& IFD_ALLOC
) {
4095 if (ifa
->ifa_free
== NULL
) {
4097 FREE(ifa
, M_IFADDR
);
4099 /* Become a regular mutex */
4100 IFA_CONVERT_LOCK(ifa
);
4101 /* callee will unlock */
4102 (*ifa
->ifa_free
)(ifa
);
4110 if (!locked
&& ifa
!= NULL
)
4117 ifa_addref(struct ifaddr
*ifa
, int locked
)
4122 IFA_LOCK_ASSERT_HELD(ifa
);
4124 if (++ifa
->ifa_refcnt
== 0) {
4125 panic("%s: ifa %p wraparound refcnt\n", __func__
, ifa
);
4127 } else if (ifa
->ifa_trace
!= NULL
) {
4128 (*ifa
->ifa_trace
)(ifa
, TRUE
);
4135 ifa_lock_init(struct ifaddr
*ifa
)
4137 lck_mtx_init(&ifa
->ifa_lock
, ifa_mtx_grp
, ifa_mtx_attr
);
4141 ifa_lock_destroy(struct ifaddr
*ifa
)
4143 IFA_LOCK_ASSERT_NOTHELD(ifa
);
4144 lck_mtx_destroy(&ifa
->ifa_lock
, ifa_mtx_grp
);
4150 * The switch statement below does nothing at runtime, as it serves as a
4151 * compile time check to ensure that all of the socket 'i' ioctls (those
4152 * in the 'i' group going thru soo_ioctl) that are made available by the
4153 * networking stack is unique. This works as long as this routine gets
4154 * updated each time a new interface ioctl gets added.
4156 * Any failures at compile time indicates duplicated ioctl values.
4158 static __attribute__((unused
)) void
4159 ifioctl_cassert(void)
4162 * This is equivalent to _CASSERT() and the compiler wouldn't
4163 * generate any instructions, thus for compile time only.
4165 switch ((u_long
)0) {
4168 /* bsd/net/if_ppp.h */
4170 case SIOCGPPPCSTATS
:
4173 /* bsd/netinet6/in6_var.h */
4174 case SIOCSIFADDR_IN6
:
4175 case SIOCGIFADDR_IN6
:
4176 case SIOCSIFDSTADDR_IN6
:
4177 case SIOCSIFNETMASK_IN6
:
4178 case SIOCGIFDSTADDR_IN6
:
4179 case SIOCGIFNETMASK_IN6
:
4180 case SIOCDIFADDR_IN6
:
4181 case SIOCAIFADDR_IN6_32
:
4182 case SIOCAIFADDR_IN6_64
:
4183 case SIOCSIFPHYADDR_IN6_32
:
4184 case SIOCSIFPHYADDR_IN6_64
:
4185 case SIOCGIFPSRCADDR_IN6
:
4186 case SIOCGIFPDSTADDR_IN6
:
4187 case SIOCGIFAFLAG_IN6
:
4188 case SIOCGDRLST_IN6_32
:
4189 case SIOCGDRLST_IN6_64
:
4190 case SIOCGPRLST_IN6_32
:
4191 case SIOCGPRLST_IN6_64
:
4192 case OSIOCGIFINFO_IN6
:
4193 case SIOCGIFINFO_IN6
:
4194 case SIOCSNDFLUSH_IN6
:
4195 case SIOCGNBRINFO_IN6_32
:
4196 case SIOCGNBRINFO_IN6_64
:
4197 case SIOCSPFXFLUSH_IN6
:
4198 case SIOCSRTRFLUSH_IN6
:
4199 case SIOCGIFALIFETIME_IN6
:
4200 case SIOCSIFALIFETIME_IN6
:
4201 case SIOCGIFSTAT_IN6
:
4202 case SIOCGIFSTAT_ICMP6
:
4203 case SIOCSDEFIFACE_IN6_32
:
4204 case SIOCSDEFIFACE_IN6_64
:
4205 case SIOCGDEFIFACE_IN6_32
:
4206 case SIOCGDEFIFACE_IN6_64
:
4207 case SIOCSIFINFO_FLAGS
:
4210 case SIOCGSCOPE6DEF
:
4211 case SIOCSIFPREFIX_IN6
:
4212 case SIOCGIFPREFIX_IN6
:
4213 case SIOCDIFPREFIX_IN6
:
4214 case SIOCAIFPREFIX_IN6
:
4215 case SIOCCIFPREFIX_IN6
:
4216 case SIOCSGIFPREFIX_IN6
:
4217 case SIOCPROTOATTACH_IN6_32
:
4218 case SIOCPROTOATTACH_IN6_64
:
4219 case SIOCPROTODETACH_IN6
:
4220 case SIOCLL_START_32
:
4221 case SIOCLL_START_64
:
4223 case SIOCAUTOCONF_START
:
4224 case SIOCAUTOCONF_STOP
:
4225 case SIOCSETROUTERMODE_IN6
:
4226 case SIOCLL_CGASTART_32
:
4227 case SIOCLL_CGASTART_64
:
4230 /* bsd/sys/sockio.h */
4233 case SIOCSIFDSTADDR
:
4234 case OSIOCGIFDSTADDR
:
4237 case OSIOCGIFBRDADDR
:
4238 case SIOCSIFBRDADDR
:
4239 case OSIOCGIFCONF32
:
4240 case OSIOCGIFCONF64
:
4241 case OSIOCGIFNETMASK
:
4242 case SIOCSIFNETMASK
:
4248 case SIOCGIFDSTADDR
:
4249 case SIOCGIFBRDADDR
:
4252 case SIOCGIFNETMASK
:
4254 case SIOCAUTONETMASK
:
4263 case SIOCGIFMEDIA32
:
4264 case SIOCGIFMEDIA64
:
4265 case SIOCSIFGENERIC
:
4266 case SIOCGIFGENERIC
:
4270 case SIOCSIFPHYADDR
:
4271 case SIOCGIFPSRCADDR
:
4272 case SIOCGIFPDSTADDR
:
4273 case SIOCDIFPHYADDR
:
4279 case SIOCPROTOATTACH
:
4280 case SIOCPROTODETACH
:
4286 case SIOCSDRVSPEC32
:
4287 case SIOCGDRVSPEC32
:
4288 case SIOCSDRVSPEC64
:
4289 case SIOCGDRVSPEC64
:
4292 case SIOCIFGCLONERS32
:
4293 case SIOCIFGCLONERS64
:
4294 case SIOCGIFASYNCMAP
:
4295 case SIOCSIFASYNCMAP
:
4299 #endif /* CONFIG_MACF_NET */
4302 case SIOCGIFWAKEFLAGS
:
4303 case SIOCGIFGETRTREFCNT
:
4304 case SIOCGIFLINKQUALITYMETRIC
:
4305 case SIOCSIFOPPORTUNISTIC
:
4306 case SIOCGIFOPPORTUNISTIC
:
4307 case SIOCSETROUTERMODE
:
4311 case SIOCSIFLINKPARAMS
:
4312 case SIOCGIFLINKPARAMS
:
4313 case SIOCGIFQUEUESTATS
:
4314 case SIOCSIFTHROTTLE
:
4315 case SIOCGIFTHROTTLE
:
4318 case SIOCGIFDELEGATE
:
4321 case SIOCGIFFUNCTIONALTYPE
:
4322 case SIOCAIFAGENTID
:
4323 case SIOCDIFAGENTID
:
4324 case SIOCGIFAGENTIDS32
:
4325 case SIOCGIFAGENTIDS64
:
4326 case SIOCGIFAGENTDATA32
:
4327 case SIOCGIFAGENTDATA64
:
4328 case SIOCSIFINTERFACESTATE
:
4329 case SIOCGIFINTERFACESTATE
:
4330 case SIOCSIFPROBECONNECTIVITY
:
4331 case SIOCGIFPROBECONNECTIVITY
: