]> git.saurik.com Git - apple/xnu.git/blob - bsd/net/if.h
xnu-1504.15.3.tar.gz
[apple/xnu.git] / bsd / net / if.h
1 /*
2 * Copyright (c) 2000-2009 Apple Inc. All rights reserved.
3 *
4 * @APPLE_OSREFERENCE_LICENSE_HEADER_START@
5 *
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.
14 *
15 * Please obtain a copy of the License at
16 * http://www.opensource.apple.com/apsl/ and read it before using this file.
17 *
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.
25 *
26 * @APPLE_OSREFERENCE_LICENSE_HEADER_END@
27 */
28 /*
29 * Copyright (c) 1982, 1986, 1989, 1993
30 * The Regents of the University of California. All rights reserved.
31 *
32 * Redistribution and use in source and binary forms, with or without
33 * modification, are permitted provided that the following conditions
34 * are met:
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.
47 *
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
58 * SUCH DAMAGE.
59 *
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 $
62 */
63
64 #ifndef _NET_IF_H_
65 #define _NET_IF_H_
66
67 #include <sys/cdefs.h>
68
69 #define IF_NAMESIZE 16
70
71 #if !defined(_POSIX_C_SOURCE) || defined(_DARWIN_C_SOURCE)
72 #include <sys/appleapiopts.h>
73 #ifdef __APPLE__
74 /*
75 * Define Data-Link event subclass, and associated
76 * events.
77 */
78
79 #define KEV_DL_SUBCLASS 2
80
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
98 #define KEV_DL_IF_IDLE_ROUTE_REFCNT 18
99
100 #include <net/if_var.h>
101 #include <sys/types.h>
102 #endif
103
104 #ifdef KERNEL_PRIVATE
105 #define IF_MAXUNIT 0x7fff /* historical value */
106
107 struct if_clonereq {
108 int ifcr_total; /* total cloners (out) */
109 int ifcr_count; /* room for this many in user buffer */
110 char *ifcr_buffer; /* buffer for cloner names */
111 };
112
113 struct if_clonereq64 {
114 int ifcr_total; /* total cloners (out) */
115 int ifcr_count; /* room for this many in user buffer */
116 user64_addr_t ifcru_buffer __attribute__((aligned(8)));
117 };
118
119 struct if_clonereq32 {
120 int ifcr_total; /* total cloners (out) */
121 int ifcr_count; /* room for this many in user buffer */
122 user32_addr_t ifcru_buffer;
123 };
124 #endif /* KERNEL_PRIVATE */
125
126 #define IFF_UP 0x1 /* interface is up */
127 #define IFF_BROADCAST 0x2 /* broadcast address valid */
128 #define IFF_DEBUG 0x4 /* turn on debugging */
129 #define IFF_LOOPBACK 0x8 /* is a loopback net */
130 #define IFF_POINTOPOINT 0x10 /* interface is point-to-point link */
131 #define IFF_NOTRAILERS 0x20 /* obsolete: avoid use of trailers */
132 #define IFF_RUNNING 0x40 /* resources allocated */
133 #define IFF_NOARP 0x80 /* no address resolution protocol */
134 #define IFF_PROMISC 0x100 /* receive all packets */
135 #define IFF_ALLMULTI 0x200 /* receive all multicast packets */
136 #define IFF_OACTIVE 0x400 /* transmission in progress */
137 #define IFF_SIMPLEX 0x800 /* can't hear own transmissions */
138 #define IFF_LINK0 0x1000 /* per link layer defined bit */
139 #define IFF_LINK1 0x2000 /* per link layer defined bit */
140 #define IFF_LINK2 0x4000 /* per link layer defined bit */
141 #define IFF_ALTPHYS IFF_LINK2 /* use alternate physical connection */
142 #define IFF_MULTICAST 0x8000 /* supports multicast */
143
144 #ifdef KERNEL_PRIVATE
145 /* extended flags definitions: (all bits are reserved for internal/future use) */
146 #define IFEF_AUTOCONFIGURING 0x1
147 #define IFEF_DVR_REENTRY_OK 0x20 /* When set, driver may be reentered from its own thread */
148 #define IFEF_ACCEPT_RTADVD 0x40 /* set to accept IPv6 router advertisement on the interface */
149 #define IFEF_DETACHING 0x80 /* Set when interface is detaching */
150 #define IFEF_USEKPI 0x100 /* Set when interface is created through the KPIs */
151 #define IFEF_VLAN 0x200 /* interface has one or more vlans */
152 #define IFEF_BOND 0x400 /* interface is part of bond */
153 #define IFEF_ARPLL 0x800 /* ARP for IPv4LL addresses on this port */
154 #define IFEF_NOWINDOWSCALE 0x1000 /* Don't scale TCP window on iface */
155 #define IFEF_NOAUTOIPV6LL 0x2000 /* Interface IPv6 LinkLocal address not provided by kernel */
156 #define IFEF_SENDLIST 0x10000000 /* Interface supports sending a list of packets */
157 #define IFEF_REUSE 0x20000000 /* DLIL ifnet recycler, ifnet is not new */
158 #define IFEF_INUSE 0x40000000 /* DLIL ifnet recycler, ifnet in use */
159 #define IFEF_UPDOWNCHANGE 0x80000000 /* Interface's up/down state is changing */
160
161 /*
162 * !!! NOTE !!!
163 *
164 * if_idle_flags definitions: (all bits are reserved for internal/future
165 * use). Setting these flags MUST be done via the ifnet_set_idle_flags()
166 * KPI due to the associated reference counting. Clearing them may be done by
167 * calling the KPI, otherwise implicitly at interface detach time. Setting
168 * the if_idle_flags field to a non-zero value will cause the networking
169 * stack to aggressively purge expired objects (routes, etc.)
170 */
171 #define IFRF_IDLE_NOTIFY 0x1 /* Generate notifications on idle */
172
173 /* flags set internally only: */
174 #define IFF_CANTCHANGE \
175 (IFF_BROADCAST|IFF_POINTOPOINT|IFF_RUNNING|IFF_OACTIVE|\
176 IFF_SIMPLEX|IFF_MULTICAST|IFF_ALLMULTI)
177
178 #endif /* KERNEL_PRIVATE */
179
180 #define IFQ_MAXLEN 50
181 #define IFNET_SLOWHZ 1 /* granularity is 1 second */
182
183 /*
184 * Message format for use in obtaining information about interfaces
185 * from sysctl and the routing socket
186 */
187 struct if_msghdr {
188 unsigned short ifm_msglen; /* to skip over non-understood messages */
189 unsigned char ifm_version; /* future binary compatability */
190 unsigned char ifm_type; /* message type */
191 int ifm_addrs; /* like rtm_addrs */
192 int ifm_flags; /* value of if_flags */
193 unsigned short ifm_index; /* index for associated ifp */
194 struct if_data ifm_data; /* statistics and other data about if */
195 };
196
197 /*
198 * Message format for use in obtaining information about interface addresses
199 * from sysctl and the routing socket
200 */
201 struct ifa_msghdr {
202 unsigned short ifam_msglen; /* to skip over non-understood messages */
203 unsigned char ifam_version; /* future binary compatability */
204 unsigned char ifam_type; /* message type */
205 int ifam_addrs; /* like rtm_addrs */
206 int ifam_flags; /* value of ifa_flags */
207 unsigned short ifam_index; /* index for associated ifp */
208 int ifam_metric; /* value of ifa_metric */
209 };
210
211 /*
212 * Message format for use in obtaining information about multicast addresses
213 * from the routing socket
214 */
215 struct ifma_msghdr {
216 unsigned short ifmam_msglen; /* to skip over non-understood messages */
217 unsigned char ifmam_version; /* future binary compatability */
218 unsigned char ifmam_type; /* message type */
219 int ifmam_addrs; /* like rtm_addrs */
220 int ifmam_flags; /* value of ifa_flags */
221 unsigned short ifmam_index; /* index for associated ifp */
222 };
223
224 /*
225 * Message format for use in obtaining information about interfaces
226 * from sysctl
227 */
228 struct if_msghdr2 {
229 u_short ifm_msglen; /* to skip over non-understood messages */
230 u_char ifm_version; /* future binary compatability */
231 u_char ifm_type; /* message type */
232 int ifm_addrs; /* like rtm_addrs */
233 int ifm_flags; /* value of if_flags */
234 u_short ifm_index; /* index for associated ifp */
235 int ifm_snd_len; /* instantaneous length of send queue */
236 int ifm_snd_maxlen; /* maximum length of send queue */
237 int ifm_snd_drops; /* number of drops in send queue */
238 int ifm_timer; /* time until if_watchdog called */
239 struct if_data64 ifm_data; /* statistics and other data about if */
240 };
241
242 /*
243 * Message format for use in obtaining information about multicast addresses
244 * from sysctl
245 */
246 struct ifma_msghdr2 {
247 u_short ifmam_msglen; /* to skip over non-understood messages */
248 u_char ifmam_version; /* future binary compatability */
249 u_char ifmam_type; /* message type */
250 int ifmam_addrs; /* like rtm_addrs */
251 int ifmam_flags; /* value of ifa_flags */
252 u_short ifmam_index; /* index for associated ifp */
253 int32_t ifmam_refcount;
254 };
255
256 /*
257 * ifdevmtu: interface device mtu
258 * Used with SIOCGIFDEVMTU to get the current mtu in use by the device,
259 * as well as the minimum and maximum mtu allowed by the device.
260 */
261 struct ifdevmtu {
262 int ifdm_current;
263 int ifdm_min;
264 int ifdm_max;
265 };
266
267 #pragma pack(4)
268
269 /*
270 ifkpi: interface kpi ioctl
271 Used with SIOCSIFKPI and SIOCGIFKPI.
272
273 ifk_module_id - From in the kernel, a value from kev_vendor_code_find. From
274 user space, a value from SIOCGKEVVENDOR ioctl on a kernel event socket.
275 ifk_type - The type. Types are specific to each module id.
276 ifk_data - The data. ifk_ptr may be a 64bit pointer for 64 bit processes.
277
278 Copying data between user space and kernel space is done using copyin
279 and copyout. A process may be running in 64bit mode. In such a case,
280 the pointer will be a 64bit pointer, not a 32bit pointer. The following
281 sample is a safe way to copy the data in to the kernel from either a
282 32bit or 64bit process:
283
284 user_addr_t tmp_ptr;
285 if (IS_64BIT_PROCESS(current_proc())) {
286 tmp_ptr = CAST_USER_ADDR_T(ifkpi.ifk_data.ifk_ptr64);
287 }
288 else {
289 tmp_ptr = CAST_USER_ADDR_T(ifkpi.ifk_data.ifk_ptr);
290 }
291 error = copyin(tmp_ptr, allocated_dst_buffer, size of allocated_dst_buffer);
292 */
293
294 struct ifkpi {
295 unsigned int ifk_module_id;
296 unsigned int ifk_type;
297 union {
298 void *ifk_ptr;
299 int ifk_value;
300 #ifdef KERNEL
301 u_int64_t ifk_ptr64;
302 #endif /* KERNEL */
303 } ifk_data;
304 };
305
306 /* Wake capabilities of a interface */
307 #define IF_WAKE_ON_MAGIC_PACKET 0x01
308 #ifdef KERNEL_PRIVATE
309 #define IF_WAKE_VALID_FLAGS IF_WAKE_ON_MAGIC_PACKET
310 #endif /* KERNEL_PRIVATE */
311
312
313 #pragma pack()
314
315 /*
316 * Interface request structure used for socket
317 * ioctl's. All interface ioctl's must have parameter
318 * definitions which begin with ifr_name. The
319 * remainder may be interface specific.
320 */
321 struct ifreq {
322 #ifndef IFNAMSIZ
323 #define IFNAMSIZ IF_NAMESIZE
324 #endif
325 char ifr_name[IFNAMSIZ]; /* if name, e.g. "en0" */
326 union {
327 struct sockaddr ifru_addr;
328 struct sockaddr ifru_dstaddr;
329 struct sockaddr ifru_broadaddr;
330 short ifru_flags;
331 int ifru_metric;
332 int ifru_mtu;
333 int ifru_phys;
334 int ifru_media;
335 int ifru_intval;
336 caddr_t ifru_data;
337 #ifdef KERNEL_PRIVATE
338 u_int64_t ifru_data64; /* 64-bit ifru_data */
339 #endif /* KERNEL_PRIVATE */
340 struct ifdevmtu ifru_devmtu;
341 struct ifkpi ifru_kpi;
342 u_int32_t ifru_wake_flags;
343 u_int32_t ifru_route_refcnt;
344 } ifr_ifru;
345 #define ifr_addr ifr_ifru.ifru_addr /* address */
346 #define ifr_dstaddr ifr_ifru.ifru_dstaddr /* other end of p-to-p link */
347 #define ifr_broadaddr ifr_ifru.ifru_broadaddr /* broadcast address */
348 #ifdef __APPLE__
349 #define ifr_flags ifr_ifru.ifru_flags /* flags */
350 #else
351 #define ifr_flags ifr_ifru.ifru_flags[0] /* flags */
352 #define ifr_prevflags ifr_ifru.ifru_flags[1] /* flags */
353 #endif /* __APPLE__ */
354 #define ifr_metric ifr_ifru.ifru_metric /* metric */
355 #define ifr_mtu ifr_ifru.ifru_mtu /* mtu */
356 #define ifr_phys ifr_ifru.ifru_phys /* physical wire */
357 #define ifr_media ifr_ifru.ifru_media /* physical media */
358 #define ifr_data ifr_ifru.ifru_data /* for use by interface */
359 #define ifr_devmtu ifr_ifru.ifru_devmtu
360 #define ifr_intval ifr_ifru.ifru_intval /* integer value */
361 #ifdef KERNEL_PRIVATE
362 #define ifr_data64 ifr_ifru.ifru_data64 /* 64-bit pointer */
363 #endif /* KERNEL_PRIVATE */
364 #define ifr_kpi ifr_ifru.ifru_kpi
365 #define ifr_wake_flags ifr_ifru.ifru_wake_flags /* wake capabilities of devive */
366 #define ifr_route_refcnt ifr_ifru.ifru_route_refcnt /* route references on interface */
367 };
368
369 #define _SIZEOF_ADDR_IFREQ(ifr) \
370 ((ifr).ifr_addr.sa_len > sizeof(struct sockaddr) ? \
371 (sizeof(struct ifreq) - sizeof(struct sockaddr) + \
372 (ifr).ifr_addr.sa_len) : sizeof(struct ifreq))
373
374 struct ifaliasreq {
375 char ifra_name[IFNAMSIZ]; /* if name, e.g. "en0" */
376 struct sockaddr ifra_addr;
377 struct sockaddr ifra_broadaddr;
378 struct sockaddr ifra_mask;
379 };
380
381 struct rslvmulti_req {
382 struct sockaddr *sa;
383 struct sockaddr **llsa;
384 };
385
386 #if !defined(KERNEL) || defined(KERNEL_PRIVATE)
387 #pragma pack(4)
388
389 struct ifmediareq {
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 int *ifm_ulist; /* media words */
397 };
398
399 #pragma pack()
400 #endif /* !KERNEL || KERNEL_PRIVATE */
401
402 #ifdef KERNEL_PRIVATE
403 #pragma pack(4)
404 struct ifmediareq64 {
405 char ifm_name[IFNAMSIZ]; /* if name, e.g. "en0" */
406 int ifm_current; /* current media options */
407 int ifm_mask; /* don't care mask */
408 int ifm_status; /* media status */
409 int ifm_active; /* active options */
410 int ifm_count; /* # entries in ifm_ulist array */
411 user64_addr_t ifmu_ulist __attribute__((aligned(8)));
412 };
413
414 struct ifmediareq32 {
415 char ifm_name[IFNAMSIZ]; /* if name, e.g. "en0" */
416 int ifm_current; /* current media options */
417 int ifm_mask; /* don't care mask */
418 int ifm_status; /* media status */
419 int ifm_active; /* active options */
420 int ifm_count; /* # entries in ifm_ulist array */
421 user32_addr_t ifmu_ulist; /* 32-bit pointer */
422 };
423 #pragma pack()
424 #endif /* KERNEL_PRIVATE */
425
426
427 #pragma pack(4)
428 struct ifdrv {
429 char ifd_name[IFNAMSIZ]; /* if name, e.g. "en0" */
430 unsigned long ifd_cmd;
431 size_t ifd_len;
432 void *ifd_data;
433 };
434 #pragma pack()
435
436 #ifdef KERNEL_PRIVATE
437 #pragma pack(4)
438 struct ifdrv32 {
439 char ifd_name[IFNAMSIZ]; /* if name, e.g. "en0" */
440 u_int32_t ifd_cmd;
441 u_int32_t ifd_len;
442 user32_addr_t ifd_data;
443 };
444
445 struct ifdrv64 {
446 char ifd_name[IFNAMSIZ]; /* if name, e.g. "en0" */
447 u_int64_t ifd_cmd;
448 u_int64_t ifd_len;
449 user64_addr_t ifd_data;
450 };
451 #pragma pack()
452 #endif /* KERNEL_PRIVATE */
453
454 /*
455 * Structure used to retrieve aux status data from interfaces.
456 * Kernel suppliers to this interface should respect the formatting
457 * needed by ifconfig(8): each line starts with a TAB and ends with
458 * a newline. The canonical example to copy and paste is in if_tun.c.
459 */
460
461 #define IFSTATMAX 800 /* 10 lines of text */
462 struct ifstat {
463 char ifs_name[IFNAMSIZ]; /* if name, e.g. "en0" */
464 char ascii[IFSTATMAX + 1];
465 };
466
467 #if !defined(KERNEL) || defined(KERNEL_PRIVATE)
468 /*
469 * Structure used in SIOCGIFCONF request.
470 * Used to retrieve interface configuration
471 * for machine (useful for programs which
472 * must know all networks accessible).
473 */
474 #pragma pack(4)
475 struct ifconf {
476 int ifc_len; /* size of associated buffer */
477 union {
478 caddr_t ifcu_buf;
479 struct ifreq *ifcu_req;
480 } ifc_ifcu;
481 };
482 #pragma pack()
483 #define ifc_buf ifc_ifcu.ifcu_buf /* buffer address */
484 #define ifc_req ifc_ifcu.ifcu_req /* array of structures returned */
485 #endif /* !KERNEL || KERNEL_PRIVATE */
486
487 #if defined(KERNEL_PRIVATE)
488 #pragma pack(4)
489 struct ifconf32 {
490 int ifc_len; /* size of associated buffer */
491 struct {
492 user32_addr_t ifcu_req;
493 } ifc_ifcu;
494 };
495
496 struct ifconf64 {
497 int ifc_len; /* size of associated buffer */
498 struct {
499 user64_addr_t ifcu_req __attribute__((aligned(8)));
500 } ifc_ifcu;
501 };
502 #pragma pack()
503 #endif /* KERNEL_PRIVATE */
504
505 /*
506 * DLIL KEV_DL_PROTO_ATTACHED/DETACHED structure
507 */
508 struct kev_dl_proto_data {
509 struct net_event_data link_data;
510 u_int32_t proto_family;
511 u_int32_t proto_remaining_count;
512 };
513
514 /*
515 * Structure for SIOC[AGD]LIFADDR
516 */
517 struct if_laddrreq {
518 char iflr_name[IFNAMSIZ];
519 unsigned int flags;
520 #define IFLR_PREFIX 0x8000 /* in: prefix given out: kernel fills id */
521 unsigned int prefixlen; /* in/out */
522 struct sockaddr_storage addr; /* in/out */
523 struct sockaddr_storage dstaddr; /* out */
524 };
525
526 #ifdef KERNEL
527 #ifdef MALLOC_DECLARE
528 MALLOC_DECLARE(M_IFADDR);
529 MALLOC_DECLARE(M_IFMADDR);
530 #endif
531 #endif
532 #endif /* (_POSIX_C_SOURCE && !_DARWIN_C_SOURCE) */
533
534 #ifndef KERNEL
535 struct if_nameindex {
536 unsigned int if_index; /* 1, 2, ... */
537 char *if_name; /* null terminated name: "le0", ... */
538 };
539
540 __BEGIN_DECLS
541 unsigned int if_nametoindex(const char *);
542 char *if_indextoname(unsigned int, char *);
543 struct if_nameindex *if_nameindex(void);
544 void if_freenameindex(struct if_nameindex *);
545 __END_DECLS
546 #endif
547
548 #ifdef KERNEL
549 #include <net/kpi_interface.h>
550 #endif
551
552 #endif /* !_NET_IF_H_ */