]> git.saurik.com Git - apple/xnu.git/blob - bsd/net/if.h
f5e62b48b5514e69ec3bedc5a333198659654627
[apple/xnu.git] / bsd / net / if.h
1 /*
2 * Copyright (c) 2000-2004 Apple Computer, 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 #define IF_NAMESIZE 16
68
69 #ifndef _POSIX_C_SOURCE
70 #include <sys/appleapiopts.h>
71 #ifdef __APPLE__
72 /*
73 * Define Data-Link event subclass, and associated
74 * events.
75 */
76
77 #define KEV_DL_SUBCLASS 2
78
79 #define KEV_DL_SIFFLAGS 1
80 #define KEV_DL_SIFMETRICS 2
81 #define KEV_DL_SIFMTU 3
82 #define KEV_DL_SIFPHYS 4
83 #define KEV_DL_SIFMEDIA 5
84 #define KEV_DL_SIFGENERIC 6
85 #define KEV_DL_ADDMULTI 7
86 #define KEV_DL_DELMULTI 8
87 #define KEV_DL_IF_ATTACHED 9
88 #define KEV_DL_IF_DETACHING 10
89 #define KEV_DL_IF_DETACHED 11
90 #define KEV_DL_LINK_OFF 12
91 #define KEV_DL_LINK_ON 13
92 #define KEV_DL_PROTO_ATTACHED 14
93 #define KEV_DL_PROTO_DETACHED 15
94 #define KEV_DL_LINK_ADDRESS_CHANGED 16
95
96 #include <net/if_var.h>
97 #include <sys/types.h>
98 #endif
99
100 #ifdef KERNEL_PRIVATE
101 struct if_clonereq {
102 int ifcr_total; /* total cloners (out) */
103 int ifcr_count; /* room for this many in user buffer */
104 char *ifcr_buffer; /* buffer for cloner names */
105 };
106
107 /* in-kernel, LP64-aware version of if_clonereq. all pointers
108 * grow when we're dealing with a 64-bit process.
109 * WARNING - keep in sync with if_clonereq
110 */
111 struct if_clonereq64 {
112 int ifcr_total; /* total cloners (out) */
113 int ifcr_count; /* room for this many in user buffer */
114 union {
115 u_int64_t ifcru_buffer64;
116 char * ifcru_buffer32;
117 } ifcr_ifcru;
118 };
119 #endif KERNEL_PRIVATE
120
121 #define IFF_UP 0x1 /* interface is up */
122 #define IFF_BROADCAST 0x2 /* broadcast address valid */
123 #define IFF_DEBUG 0x4 /* turn on debugging */
124 #define IFF_LOOPBACK 0x8 /* is a loopback net */
125 #define IFF_POINTOPOINT 0x10 /* interface is point-to-point link */
126 #define IFF_NOTRAILERS 0x20 /* obsolete: avoid use of trailers */
127 #define IFF_RUNNING 0x40 /* resources allocated */
128 #define IFF_NOARP 0x80 /* no address resolution protocol */
129 #define IFF_PROMISC 0x100 /* receive all packets */
130 #define IFF_ALLMULTI 0x200 /* receive all multicast packets */
131 #define IFF_OACTIVE 0x400 /* transmission in progress */
132 #define IFF_SIMPLEX 0x800 /* can't hear own transmissions */
133 #define IFF_LINK0 0x1000 /* per link layer defined bit */
134 #define IFF_LINK1 0x2000 /* per link layer defined bit */
135 #define IFF_LINK2 0x4000 /* per link layer defined bit */
136 #define IFF_ALTPHYS IFF_LINK2 /* use alternate physical connection */
137 #define IFF_MULTICAST 0x8000 /* supports multicast */
138
139 #ifdef KERNEL_PRIVATE
140 /* extended flags definitions: (all bits are reserved for internal/future use) */
141 #define IFEF_AUTOCONFIGURING 0x1
142 #define IFEF_DVR_REENTRY_OK 0x20 /* When set, driver may be reentered from its own thread */
143 #define IFEF_ACCEPT_RTADVD 0x40 /* set to accept IPv6 router advertisement on the interface */
144 #define IFEF_DETACHING 0x80 /* Set when interface is detaching */
145 #define IFEF_USEKPI 0x100 /* Set when interface is created through the KPIs */
146 #define IFEF_VLAN 0x200 /* interface has one or more vlans */
147 #define IFEF_BOND 0x400 /* interface is part of bond */
148 #define IFEF_ARPLL 0x800 /* ARP for IPv4LL addresses on this port */
149 #define IFEF_REUSE 0x20000000 /* DLIL ifnet recycler, ifnet is not new */
150 #define IFEF_INUSE 0x40000000 /* DLIL ifnet recycler, ifnet in use */
151 #define IFEF_UPDOWNCHANGE 0x80000000 /* Interface's up/down state is changing */
152
153 /* flags set internally only: */
154 #define IFF_CANTCHANGE \
155 (IFF_BROADCAST|IFF_POINTOPOINT|IFF_RUNNING|IFF_OACTIVE|\
156 IFF_SIMPLEX|IFF_MULTICAST|IFF_ALLMULTI)
157
158 #endif /* KERNEL_PRIVATE */
159
160 #define IFQ_MAXLEN 50
161 #define IFNET_SLOWHZ 1 /* granularity is 1 second */
162
163 /*
164 * Message format for use in obtaining information about interfaces
165 * from sysctl and the routing socket
166 */
167 struct if_msghdr {
168 unsigned short ifm_msglen; /* to skip over non-understood messages */
169 unsigned char ifm_version; /* future binary compatability */
170 unsigned char ifm_type; /* message type */
171 int ifm_addrs; /* like rtm_addrs */
172 int ifm_flags; /* value of if_flags */
173 unsigned short ifm_index; /* index for associated ifp */
174 struct if_data ifm_data; /* statistics and other data about if */
175 };
176
177 /*
178 * Message format for use in obtaining information about interface addresses
179 * from sysctl and the routing socket
180 */
181 struct ifa_msghdr {
182 unsigned short ifam_msglen; /* to skip over non-understood messages */
183 unsigned char ifam_version; /* future binary compatability */
184 unsigned char ifam_type; /* message type */
185 int ifam_addrs; /* like rtm_addrs */
186 int ifam_flags; /* value of ifa_flags */
187 unsigned short ifam_index; /* index for associated ifp */
188 int ifam_metric; /* value of ifa_metric */
189 };
190
191 /*
192 * Message format for use in obtaining information about multicast addresses
193 * from the routing socket
194 */
195 struct ifma_msghdr {
196 unsigned short ifmam_msglen; /* to skip over non-understood messages */
197 unsigned char ifmam_version; /* future binary compatability */
198 unsigned char ifmam_type; /* message type */
199 int ifmam_addrs; /* like rtm_addrs */
200 int ifmam_flags; /* value of ifa_flags */
201 unsigned short ifmam_index; /* index for associated ifp */
202 };
203
204 /*
205 * Message format for use in obtaining information about interfaces
206 * from sysctl
207 */
208 struct if_msghdr2 {
209 u_short ifm_msglen; /* to skip over non-understood messages */
210 u_char ifm_version; /* future binary compatability */
211 u_char ifm_type; /* message type */
212 int ifm_addrs; /* like rtm_addrs */
213 int ifm_flags; /* value of if_flags */
214 u_short ifm_index; /* index for associated ifp */
215 int ifm_snd_len; /* instantaneous length of send queue */
216 int ifm_snd_maxlen; /* maximum length of send queue */
217 int ifm_snd_drops; /* number of drops in send queue */
218 int ifm_timer; /* time until if_watchdog called */
219 struct if_data64 ifm_data; /* statistics and other data about if */
220 };
221
222 /*
223 * Message format for use in obtaining information about multicast addresses
224 * from sysctl
225 */
226 struct ifma_msghdr2 {
227 u_short ifmam_msglen; /* to skip over non-understood messages */
228 u_char ifmam_version; /* future binary compatability */
229 u_char ifmam_type; /* message type */
230 int ifmam_addrs; /* like rtm_addrs */
231 int ifmam_flags; /* value of ifa_flags */
232 u_short ifmam_index; /* index for associated ifp */
233 int32_t ifmam_refcount;
234 };
235
236 /*
237 * ifdevmtu: interface device mtu
238 * Used with SIOCGIFDEVMTU to get the current mtu in use by the device,
239 * as well as the minimum and maximum mtu allowed by the device.
240 */
241 struct ifdevmtu {
242 int ifdm_current;
243 int ifdm_min;
244 int ifdm_max;
245 };
246
247 /*
248 * Interface request structure used for socket
249 * ioctl's. All interface ioctl's must have parameter
250 * definitions which begin with ifr_name. The
251 * remainder may be interface specific.
252 */
253 struct ifreq {
254 #ifndef IFNAMSIZ
255 #define IFNAMSIZ IF_NAMESIZE
256 #endif
257 char ifr_name[IFNAMSIZ]; /* if name, e.g. "en0" */
258 union {
259 struct sockaddr ifru_addr;
260 struct sockaddr ifru_dstaddr;
261 struct sockaddr ifru_broadaddr;
262 short ifru_flags;
263 int ifru_metric;
264 int ifru_mtu;
265 int ifru_phys;
266 int ifru_media;
267 int ifru_intval;
268 caddr_t ifru_data;
269 #ifdef KERNEL_PRIVATE
270 u_int64_t ifru_data64; /* 64-bit ifru_data */
271 #endif KERNEL_PRIVATE
272 struct ifdevmtu ifru_devmtu;
273 } ifr_ifru;
274 #define ifr_addr ifr_ifru.ifru_addr /* address */
275 #define ifr_dstaddr ifr_ifru.ifru_dstaddr /* other end of p-to-p link */
276 #define ifr_broadaddr ifr_ifru.ifru_broadaddr /* broadcast address */
277 #ifdef __APPLE__
278 #define ifr_flags ifr_ifru.ifru_flags /* flags */
279 #else
280 #define ifr_flags ifr_ifru.ifru_flags[0] /* flags */
281 #define ifr_prevflags ifr_ifru.ifru_flags[1] /* flags */
282 #endif /* __APPLE__ */
283 #define ifr_metric ifr_ifru.ifru_metric /* metric */
284 #define ifr_mtu ifr_ifru.ifru_mtu /* mtu */
285 #define ifr_phys ifr_ifru.ifru_phys /* physical wire */
286 #define ifr_media ifr_ifru.ifru_media /* physical media */
287 #define ifr_data ifr_ifru.ifru_data /* for use by interface */
288 #define ifr_devmtu ifr_ifru.ifru_devmtu
289 #define ifr_intval ifr_ifru.ifru_intval /* integer value */
290 #ifdef KERNEL_PRIVATE
291 #define ifr_data64 ifr_ifru.ifru_data64 /* 64-bit pointer */
292 #endif KERNEL_PRIVATE
293 };
294
295 #define _SIZEOF_ADDR_IFREQ(ifr) \
296 ((ifr).ifr_addr.sa_len > sizeof(struct sockaddr) ? \
297 (sizeof(struct ifreq) - sizeof(struct sockaddr) + \
298 (ifr).ifr_addr.sa_len) : sizeof(struct ifreq))
299
300 struct ifaliasreq {
301 char ifra_name[IFNAMSIZ]; /* if name, e.g. "en0" */
302 struct sockaddr ifra_addr;
303 struct sockaddr ifra_broadaddr;
304 struct sockaddr ifra_mask;
305 };
306
307 struct rslvmulti_req {
308 struct sockaddr *sa;
309 struct sockaddr **llsa;
310 };
311
312 struct ifmediareq {
313 char ifm_name[IFNAMSIZ]; /* if name, e.g. "en0" */
314 int ifm_current; /* current media options */
315 int ifm_mask; /* don't care mask */
316 int ifm_status; /* media status */
317 int ifm_active; /* active options */
318 int ifm_count; /* # entries in ifm_ulist array */
319 int *ifm_ulist; /* media words */
320 };
321
322 #ifdef KERNEL_PRIVATE
323 /* LP64 version of ifmediareq. all pointers
324 * grow when we're dealing with a 64-bit process.
325 * WARNING - keep in sync with ifmediareq
326 */
327 struct ifmediareq64 {
328 char ifm_name[IFNAMSIZ]; /* if name, e.g. "en0" */
329 int ifm_current; /* current media options */
330 int ifm_mask; /* don't care mask */
331 int ifm_status; /* media status */
332 int ifm_active; /* active options */
333 int ifm_count; /* # entries in ifm_ulist array */
334 union { /* media words */
335 int * ifmu_ulist32; /* 32-bit pointer */
336 u_int64_t ifmu_ulist64; /* 64-bit pointer */
337 } ifm_ifmu;
338 };
339 #endif // KERNEL_PRIVATE
340
341 /*
342 * Structure used to retrieve aux status data from interfaces.
343 * Kernel suppliers to this interface should respect the formatting
344 * needed by ifconfig(8): each line starts with a TAB and ends with
345 * a newline. The canonical example to copy and paste is in if_tun.c.
346 */
347
348 #define IFSTATMAX 800 /* 10 lines of text */
349 struct ifstat {
350 char ifs_name[IFNAMSIZ]; /* if name, e.g. "en0" */
351 char ascii[IFSTATMAX + 1];
352 };
353
354 /*
355 * Structure used in SIOCGIFCONF request.
356 * Used to retrieve interface configuration
357 * for machine (useful for programs which
358 * must know all networks accessible).
359 */
360 struct ifconf {
361 int ifc_len; /* size of associated buffer */
362 union {
363 caddr_t ifcu_buf;
364 struct ifreq *ifcu_req;
365 } ifc_ifcu;
366 #define ifc_buf ifc_ifcu.ifcu_buf /* buffer address */
367 #define ifc_req ifc_ifcu.ifcu_req /* array of structures returned */
368 };
369
370 #ifdef KERNEL_PRIVATE
371 /* LP64 version of ifconf. all pointers
372 * grow when we're dealing with a 64-bit process.
373 * WARNING - keep in sync with ifconf
374 */
375 struct ifconf64 {
376 int ifc_len; /* size of associated buffer */
377 union {
378 struct ifreq * ifcu_req;
379 u_int64_t ifcu_req64;
380 } ifc_ifcu;
381 };
382 #define ifc_req64 ifc_ifcu.ifcu_req64
383 #endif // KERNEL_PRIVATE
384
385 /*
386 * DLIL KEV_DL_PROTO_ATTACHED/DETACHED structure
387 */
388 struct kev_dl_proto_data {
389 struct net_event_data link_data;
390 unsigned long proto_family;
391 unsigned long proto_remaining_count;
392 };
393
394 /*
395 * Structure for SIOC[AGD]LIFADDR
396 */
397 struct if_laddrreq {
398 char iflr_name[IFNAMSIZ];
399 unsigned int flags;
400 #define IFLR_PREFIX 0x8000 /* in: prefix given out: kernel fills id */
401 unsigned int prefixlen; /* in/out */
402 struct sockaddr_storage addr; /* in/out */
403 struct sockaddr_storage dstaddr; /* out */
404 };
405
406 #ifdef KERNEL
407 #ifdef MALLOC_DECLARE
408 MALLOC_DECLARE(M_IFADDR);
409 MALLOC_DECLARE(M_IFMADDR);
410 #endif
411 #endif
412 #endif /* _POSIX_C_SOURCE */
413
414 #ifndef KERNEL
415 struct if_nameindex {
416 unsigned int if_index; /* 1, 2, ... */
417 char *if_name; /* null terminated name: "le0", ... */
418 };
419
420 __BEGIN_DECLS
421 unsigned int if_nametoindex(const char *);
422 char *if_indextoname(unsigned int, char *);
423 struct if_nameindex *if_nameindex(void);
424 void if_freenameindex(struct if_nameindex *);
425 __END_DECLS
426 #endif
427
428 #ifdef KERNEL
429 #include <net/kpi_interface.h>
430 #endif
431
432 #endif /* !_NET_IF_H_ */