2 * Copyright (c) 2000-2009 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) 1982, 1986, 1989, 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.h 8.1 (Berkeley) 6/10/93
61 * $FreeBSD: src/sys/net/if.h,v 1.58.2.2 2001/07/24 19:10:18 brooks Exp $
67 #include <sys/cdefs.h>
69 #define IF_NAMESIZE 16
71 #if !defined(_POSIX_C_SOURCE) || defined(_DARWIN_C_SOURCE)
72 #include <sys/appleapiopts.h>
75 * Define Data-Link event subclass, and associated
79 #define KEV_DL_SUBCLASS 2
81 #define KEV_DL_SIFFLAGS 1
82 #define KEV_DL_SIFMETRICS 2
83 #define KEV_DL_SIFMTU 3
84 #define KEV_DL_SIFPHYS 4
85 #define KEV_DL_SIFMEDIA 5
86 #define KEV_DL_SIFGENERIC 6
87 #define KEV_DL_ADDMULTI 7
88 #define KEV_DL_DELMULTI 8
89 #define KEV_DL_IF_ATTACHED 9
90 #define KEV_DL_IF_DETACHING 10
91 #define KEV_DL_IF_DETACHED 11
92 #define KEV_DL_LINK_OFF 12
93 #define KEV_DL_LINK_ON 13
94 #define KEV_DL_PROTO_ATTACHED 14
95 #define KEV_DL_PROTO_DETACHED 15
96 #define KEV_DL_LINK_ADDRESS_CHANGED 16
97 #define KEV_DL_WAKEFLAGS_CHANGED 17
99 #include <net/if_var.h>
100 #include <sys/types.h>
103 #ifdef KERNEL_PRIVATE
104 #define IF_MAXUNIT 0x7fff /* historical value */
107 int ifcr_total
; /* total cloners (out) */
108 int ifcr_count
; /* room for this many in user buffer */
109 char *ifcr_buffer
; /* buffer for cloner names */
112 struct if_clonereq64
{
113 int ifcr_total
; /* total cloners (out) */
114 int ifcr_count
; /* room for this many in user buffer */
115 user64_addr_t ifcru_buffer
__attribute__((aligned(8)));
118 struct if_clonereq32
{
119 int ifcr_total
; /* total cloners (out) */
120 int ifcr_count
; /* room for this many in user buffer */
121 user32_addr_t ifcru_buffer
;
123 #endif /* KERNEL_PRIVATE */
125 #define IFF_UP 0x1 /* interface is up */
126 #define IFF_BROADCAST 0x2 /* broadcast address valid */
127 #define IFF_DEBUG 0x4 /* turn on debugging */
128 #define IFF_LOOPBACK 0x8 /* is a loopback net */
129 #define IFF_POINTOPOINT 0x10 /* interface is point-to-point link */
130 #define IFF_NOTRAILERS 0x20 /* obsolete: avoid use of trailers */
131 #define IFF_RUNNING 0x40 /* resources allocated */
132 #define IFF_NOARP 0x80 /* no address resolution protocol */
133 #define IFF_PROMISC 0x100 /* receive all packets */
134 #define IFF_ALLMULTI 0x200 /* receive all multicast packets */
135 #define IFF_OACTIVE 0x400 /* transmission in progress */
136 #define IFF_SIMPLEX 0x800 /* can't hear own transmissions */
137 #define IFF_LINK0 0x1000 /* per link layer defined bit */
138 #define IFF_LINK1 0x2000 /* per link layer defined bit */
139 #define IFF_LINK2 0x4000 /* per link layer defined bit */
140 #define IFF_ALTPHYS IFF_LINK2 /* use alternate physical connection */
141 #define IFF_MULTICAST 0x8000 /* supports multicast */
143 #ifdef KERNEL_PRIVATE
144 /* extended flags definitions: (all bits are reserved for internal/future use) */
145 #define IFEF_AUTOCONFIGURING 0x1
146 #define IFEF_DVR_REENTRY_OK 0x20 /* When set, driver may be reentered from its own thread */
147 #define IFEF_ACCEPT_RTADVD 0x40 /* set to accept IPv6 router advertisement on the interface */
148 #define IFEF_DETACHING 0x80 /* Set when interface is detaching */
149 #define IFEF_USEKPI 0x100 /* Set when interface is created through the KPIs */
150 #define IFEF_VLAN 0x200 /* interface has one or more vlans */
151 #define IFEF_BOND 0x400 /* interface is part of bond */
152 #define IFEF_ARPLL 0x800 /* ARP for IPv4LL addresses on this port */
153 #define IFEF_NOWINDOWSCALE 0x1000 /* Don't scale TCP window on iface */
154 #define IFEF_NOAUTOIPV6LL 0x2000 /* Interface IPv6 LinkLocal address not provided by kernel */
155 #define IFEF_SENDLIST 0x10000000 /* Interface supports sending a list of packets */
156 #define IFEF_REUSE 0x20000000 /* DLIL ifnet recycler, ifnet is not new */
157 #define IFEF_INUSE 0x40000000 /* DLIL ifnet recycler, ifnet in use */
158 #define IFEF_UPDOWNCHANGE 0x80000000 /* Interface's up/down state is changing */
160 /* flags set internally only: */
161 #define IFF_CANTCHANGE \
162 (IFF_BROADCAST|IFF_POINTOPOINT|IFF_RUNNING|IFF_OACTIVE|\
163 IFF_SIMPLEX|IFF_MULTICAST|IFF_ALLMULTI)
165 #endif /* KERNEL_PRIVATE */
167 #define IFQ_MAXLEN 50
168 #define IFNET_SLOWHZ 1 /* granularity is 1 second */
171 * Message format for use in obtaining information about interfaces
172 * from sysctl and the routing socket
175 unsigned short ifm_msglen
; /* to skip over non-understood messages */
176 unsigned char ifm_version
; /* future binary compatability */
177 unsigned char ifm_type
; /* message type */
178 int ifm_addrs
; /* like rtm_addrs */
179 int ifm_flags
; /* value of if_flags */
180 unsigned short ifm_index
; /* index for associated ifp */
181 struct if_data ifm_data
; /* statistics and other data about if */
185 * Message format for use in obtaining information about interface addresses
186 * from sysctl and the routing socket
189 unsigned short ifam_msglen
; /* to skip over non-understood messages */
190 unsigned char ifam_version
; /* future binary compatability */
191 unsigned char ifam_type
; /* message type */
192 int ifam_addrs
; /* like rtm_addrs */
193 int ifam_flags
; /* value of ifa_flags */
194 unsigned short ifam_index
; /* index for associated ifp */
195 int ifam_metric
; /* value of ifa_metric */
199 * Message format for use in obtaining information about multicast addresses
200 * from the routing socket
203 unsigned short ifmam_msglen
; /* to skip over non-understood messages */
204 unsigned char ifmam_version
; /* future binary compatability */
205 unsigned char ifmam_type
; /* message type */
206 int ifmam_addrs
; /* like rtm_addrs */
207 int ifmam_flags
; /* value of ifa_flags */
208 unsigned short ifmam_index
; /* index for associated ifp */
212 * Message format for use in obtaining information about interfaces
216 u_short ifm_msglen
; /* to skip over non-understood messages */
217 u_char ifm_version
; /* future binary compatability */
218 u_char ifm_type
; /* message type */
219 int ifm_addrs
; /* like rtm_addrs */
220 int ifm_flags
; /* value of if_flags */
221 u_short ifm_index
; /* index for associated ifp */
222 int ifm_snd_len
; /* instantaneous length of send queue */
223 int ifm_snd_maxlen
; /* maximum length of send queue */
224 int ifm_snd_drops
; /* number of drops in send queue */
225 int ifm_timer
; /* time until if_watchdog called */
226 struct if_data64 ifm_data
; /* statistics and other data about if */
230 * Message format for use in obtaining information about multicast addresses
233 struct ifma_msghdr2
{
234 u_short ifmam_msglen
; /* to skip over non-understood messages */
235 u_char ifmam_version
; /* future binary compatability */
236 u_char ifmam_type
; /* message type */
237 int ifmam_addrs
; /* like rtm_addrs */
238 int ifmam_flags
; /* value of ifa_flags */
239 u_short ifmam_index
; /* index for associated ifp */
240 int32_t ifmam_refcount
;
244 * ifdevmtu: interface device mtu
245 * Used with SIOCGIFDEVMTU to get the current mtu in use by the device,
246 * as well as the minimum and maximum mtu allowed by the device.
257 ifkpi: interface kpi ioctl
258 Used with SIOCSIFKPI and SIOCGIFKPI.
260 ifk_module_id - From in the kernel, a value from kev_vendor_code_find. From
261 user space, a value from SIOCGKEVVENDOR ioctl on a kernel event socket.
262 ifk_type - The type. Types are specific to each module id.
263 ifk_data - The data. ifk_ptr may be a 64bit pointer for 64 bit processes.
265 Copying data between user space and kernel space is done using copyin
266 and copyout. A process may be running in 64bit mode. In such a case,
267 the pointer will be a 64bit pointer, not a 32bit pointer. The following
268 sample is a safe way to copy the data in to the kernel from either a
269 32bit or 64bit process:
272 if (IS_64BIT_PROCESS(current_proc())) {
273 tmp_ptr = CAST_USER_ADDR_T(ifkpi.ifk_data.ifk_ptr64);
276 tmp_ptr = CAST_USER_ADDR_T(ifkpi.ifk_data.ifk_ptr);
278 error = copyin(tmp_ptr, allocated_dst_buffer, size of allocated_dst_buffer);
282 unsigned int ifk_module_id
;
283 unsigned int ifk_type
;
293 /* Wake capabilities of a interface */
294 #define IF_WAKE_ON_MAGIC_PACKET 0x01
295 #ifdef KERNEL_PRIVATE
296 #define IF_WAKE_VALID_FLAGS IF_WAKE_ON_MAGIC_PACKET
297 #endif /* KERNEL_PRIVATE */
303 * Interface request structure used for socket
304 * ioctl's. All interface ioctl's must have parameter
305 * definitions which begin with ifr_name. The
306 * remainder may be interface specific.
310 #define IFNAMSIZ IF_NAMESIZE
312 char ifr_name
[IFNAMSIZ
]; /* if name, e.g. "en0" */
314 struct sockaddr ifru_addr
;
315 struct sockaddr ifru_dstaddr
;
316 struct sockaddr ifru_broadaddr
;
324 #ifdef KERNEL_PRIVATE
325 u_int64_t ifru_data64
; /* 64-bit ifru_data */
326 #endif /* KERNEL_PRIVATE */
327 struct ifdevmtu ifru_devmtu
;
328 struct ifkpi ifru_kpi
;
329 u_int32_t ifru_wake_flags
;
331 #define ifr_addr ifr_ifru.ifru_addr /* address */
332 #define ifr_dstaddr ifr_ifru.ifru_dstaddr /* other end of p-to-p link */
333 #define ifr_broadaddr ifr_ifru.ifru_broadaddr /* broadcast address */
335 #define ifr_flags ifr_ifru.ifru_flags /* flags */
337 #define ifr_flags ifr_ifru.ifru_flags[0] /* flags */
338 #define ifr_prevflags ifr_ifru.ifru_flags[1] /* flags */
339 #endif /* __APPLE__ */
340 #define ifr_metric ifr_ifru.ifru_metric /* metric */
341 #define ifr_mtu ifr_ifru.ifru_mtu /* mtu */
342 #define ifr_phys ifr_ifru.ifru_phys /* physical wire */
343 #define ifr_media ifr_ifru.ifru_media /* physical media */
344 #define ifr_data ifr_ifru.ifru_data /* for use by interface */
345 #define ifr_devmtu ifr_ifru.ifru_devmtu
346 #define ifr_intval ifr_ifru.ifru_intval /* integer value */
347 #ifdef KERNEL_PRIVATE
348 #define ifr_data64 ifr_ifru.ifru_data64 /* 64-bit pointer */
349 #endif /* KERNEL_PRIVATE */
350 #define ifr_kpi ifr_ifru.ifru_kpi
351 #define ifr_wake_flags ifr_ifru.ifru_wake_flags /* wake capabilities of devive */
354 #define _SIZEOF_ADDR_IFREQ(ifr) \
355 ((ifr).ifr_addr.sa_len > sizeof(struct sockaddr) ? \
356 (sizeof(struct ifreq) - sizeof(struct sockaddr) + \
357 (ifr).ifr_addr.sa_len) : sizeof(struct ifreq))
360 char ifra_name
[IFNAMSIZ
]; /* if name, e.g. "en0" */
361 struct sockaddr ifra_addr
;
362 struct sockaddr ifra_broadaddr
;
363 struct sockaddr ifra_mask
;
366 struct rslvmulti_req
{
368 struct sockaddr
**llsa
;
371 #if !defined(KERNEL) || defined(KERNEL_PRIVATE)
375 char ifm_name
[IFNAMSIZ
]; /* if name, e.g. "en0" */
376 int ifm_current
; /* current media options */
377 int ifm_mask
; /* don't care mask */
378 int ifm_status
; /* media status */
379 int ifm_active
; /* active options */
380 int ifm_count
; /* # entries in ifm_ulist array */
381 int *ifm_ulist
; /* media words */
385 #endif /* !KERNEL || KERNEL_PRIVATE */
387 #ifdef KERNEL_PRIVATE
389 struct ifmediareq64
{
390 char ifm_name
[IFNAMSIZ
]; /* if name, e.g. "en0" */
391 int ifm_current
; /* current media options */
392 int ifm_mask
; /* don't care mask */
393 int ifm_status
; /* media status */
394 int ifm_active
; /* active options */
395 int ifm_count
; /* # entries in ifm_ulist array */
396 user64_addr_t ifmu_ulist
__attribute__((aligned(8)));
399 struct ifmediareq32
{
400 char ifm_name
[IFNAMSIZ
]; /* if name, e.g. "en0" */
401 int ifm_current
; /* current media options */
402 int ifm_mask
; /* don't care mask */
403 int ifm_status
; /* media status */
404 int ifm_active
; /* active options */
405 int ifm_count
; /* # entries in ifm_ulist array */
406 user32_addr_t ifmu_ulist
; /* 32-bit pointer */
409 #endif /* KERNEL_PRIVATE */
414 char ifd_name
[IFNAMSIZ
]; /* if name, e.g. "en0" */
415 unsigned long ifd_cmd
;
421 #ifdef KERNEL_PRIVATE
424 char ifd_name
[IFNAMSIZ
]; /* if name, e.g. "en0" */
427 user32_addr_t ifd_data
;
431 char ifd_name
[IFNAMSIZ
]; /* if name, e.g. "en0" */
434 user64_addr_t ifd_data
;
437 #endif /* KERNEL_PRIVATE */
440 * Structure used to retrieve aux status data from interfaces.
441 * Kernel suppliers to this interface should respect the formatting
442 * needed by ifconfig(8): each line starts with a TAB and ends with
443 * a newline. The canonical example to copy and paste is in if_tun.c.
446 #define IFSTATMAX 800 /* 10 lines of text */
448 char ifs_name
[IFNAMSIZ
]; /* if name, e.g. "en0" */
449 char ascii
[IFSTATMAX
+ 1];
452 #if !defined(KERNEL) || defined(KERNEL_PRIVATE)
454 * Structure used in SIOCGIFCONF request.
455 * Used to retrieve interface configuration
456 * for machine (useful for programs which
457 * must know all networks accessible).
461 int ifc_len
; /* size of associated buffer */
464 struct ifreq
*ifcu_req
;
468 #define ifc_buf ifc_ifcu.ifcu_buf /* buffer address */
469 #define ifc_req ifc_ifcu.ifcu_req /* array of structures returned */
470 #endif /* !KERNEL || KERNEL_PRIVATE */
472 #if defined(KERNEL_PRIVATE)
475 int ifc_len
; /* size of associated buffer */
477 user32_addr_t ifcu_req
;
482 int ifc_len
; /* size of associated buffer */
484 user64_addr_t ifcu_req
__attribute__((aligned(8)));
488 #endif /* KERNEL_PRIVATE */
491 * DLIL KEV_DL_PROTO_ATTACHED/DETACHED structure
493 struct kev_dl_proto_data
{
494 struct net_event_data link_data
;
495 u_int32_t proto_family
;
496 u_int32_t proto_remaining_count
;
500 * Structure for SIOC[AGD]LIFADDR
503 char iflr_name
[IFNAMSIZ
];
505 #define IFLR_PREFIX 0x8000 /* in: prefix given out: kernel fills id */
506 unsigned int prefixlen
; /* in/out */
507 struct sockaddr_storage addr
; /* in/out */
508 struct sockaddr_storage dstaddr
; /* out */
512 #ifdef MALLOC_DECLARE
513 MALLOC_DECLARE(M_IFADDR
);
514 MALLOC_DECLARE(M_IFMADDR
);
517 #endif /* (_POSIX_C_SOURCE && !_DARWIN_C_SOURCE) */
520 struct if_nameindex
{
521 unsigned int if_index
; /* 1, 2, ... */
522 char *if_name
; /* null terminated name: "le0", ... */
526 unsigned int if_nametoindex(const char *);
527 char *if_indextoname(unsigned int, char *);
528 struct if_nameindex
*if_nameindex(void);
529 void if_freenameindex(struct if_nameindex
*);
534 #include <net/kpi_interface.h>
537 #endif /* !_NET_IF_H_ */