]> git.saurik.com Git - apple/xnu.git/blob - bsd/net/if.h
36eb4d2b8e322eeaf73ee5ccd57455537504ccb2
[apple/xnu.git] / bsd / net / if.h
1 /*
2 * Copyright (c) 2000-2004 Apple Computer, Inc. All rights reserved.
3 *
4 * @APPLE_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. Please obtain a copy of the License at
10 * http://www.opensource.apple.com/apsl/ and read it before using this
11 * file.
12 *
13 * The Original Code and all software distributed under the License are
14 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
15 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
16 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
18 * Please see the License for the specific language governing rights and
19 * limitations under the License.
20 *
21 * @APPLE_LICENSE_HEADER_END@
22 */
23 /*
24 * Copyright (c) 1982, 1986, 1989, 1993
25 * The Regents of the University of California. All rights reserved.
26 *
27 * Redistribution and use in source and binary forms, with or without
28 * modification, are permitted provided that the following conditions
29 * are met:
30 * 1. Redistributions of source code must retain the above copyright
31 * notice, this list of conditions and the following disclaimer.
32 * 2. Redistributions in binary form must reproduce the above copyright
33 * notice, this list of conditions and the following disclaimer in the
34 * documentation and/or other materials provided with the distribution.
35 * 3. All advertising materials mentioning features or use of this software
36 * must display the following acknowledgement:
37 * This product includes software developed by the University of
38 * California, Berkeley and its contributors.
39 * 4. Neither the name of the University nor the names of its contributors
40 * may be used to endorse or promote products derived from this software
41 * without specific prior written permission.
42 *
43 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
44 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
45 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
46 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
47 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
48 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
49 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
50 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
51 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
52 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
53 * SUCH DAMAGE.
54 *
55 * @(#)if.h 8.1 (Berkeley) 6/10/93
56 * $FreeBSD: src/sys/net/if.h,v 1.58.2.2 2001/07/24 19:10:18 brooks Exp $
57 */
58
59 #ifndef _NET_IF_H_
60 #define _NET_IF_H_
61
62 #define IF_NAMESIZE 16
63
64 #ifndef _POSIX_C_SOURCE
65 #include <sys/appleapiopts.h>
66 #ifdef __APPLE__
67 /*
68 * Define Data-Link event subclass, and associated
69 * events.
70 */
71
72 #define KEV_DL_SUBCLASS 2
73
74 #define KEV_DL_SIFFLAGS 1
75 #define KEV_DL_SIFMETRICS 2
76 #define KEV_DL_SIFMTU 3
77 #define KEV_DL_SIFPHYS 4
78 #define KEV_DL_SIFMEDIA 5
79 #define KEV_DL_SIFGENERIC 6
80 #define KEV_DL_ADDMULTI 7
81 #define KEV_DL_DELMULTI 8
82 #define KEV_DL_IF_ATTACHED 9
83 #define KEV_DL_IF_DETACHING 10
84 #define KEV_DL_IF_DETACHED 11
85 #define KEV_DL_LINK_OFF 12
86 #define KEV_DL_LINK_ON 13
87 #define KEV_DL_PROTO_ATTACHED 14
88 #define KEV_DL_PROTO_DETACHED 15
89 #define KEV_DL_LINK_ADDRESS_CHANGED 16
90
91 #include <net/if_var.h>
92 #include <sys/types.h>
93 #endif
94
95 #ifdef KERNEL_PRIVATE
96 struct if_clonereq {
97 int ifcr_total; /* total cloners (out) */
98 int ifcr_count; /* room for this many in user buffer */
99 char *ifcr_buffer; /* buffer for cloner names */
100 };
101
102 /* in-kernel, LP64-aware version of if_clonereq. all pointers
103 * grow when we're dealing with a 64-bit process.
104 * WARNING - keep in sync with if_clonereq
105 */
106 struct if_clonereq64 {
107 int ifcr_total; /* total cloners (out) */
108 int ifcr_count; /* room for this many in user buffer */
109 union {
110 u_int64_t ifcru_buffer64;
111 char * ifcru_buffer32;
112 } ifcr_ifcru;
113 };
114 #endif KERNEL_PRIVATE
115
116 #define IFF_UP 0x1 /* interface is up */
117 #define IFF_BROADCAST 0x2 /* broadcast address valid */
118 #define IFF_DEBUG 0x4 /* turn on debugging */
119 #define IFF_LOOPBACK 0x8 /* is a loopback net */
120 #define IFF_POINTOPOINT 0x10 /* interface is point-to-point link */
121 #define IFF_NOTRAILERS 0x20 /* obsolete: avoid use of trailers */
122 #define IFF_RUNNING 0x40 /* resources allocated */
123 #define IFF_NOARP 0x80 /* no address resolution protocol */
124 #define IFF_PROMISC 0x100 /* receive all packets */
125 #define IFF_ALLMULTI 0x200 /* receive all multicast packets */
126 #define IFF_OACTIVE 0x400 /* transmission in progress */
127 #define IFF_SIMPLEX 0x800 /* can't hear own transmissions */
128 #define IFF_LINK0 0x1000 /* per link layer defined bit */
129 #define IFF_LINK1 0x2000 /* per link layer defined bit */
130 #define IFF_LINK2 0x4000 /* per link layer defined bit */
131 #define IFF_ALTPHYS IFF_LINK2 /* use alternate physical connection */
132 #define IFF_MULTICAST 0x8000 /* supports multicast */
133
134 #ifdef KERNEL_PRIVATE
135 /* extended flags definitions: (all bits are reserved for internal/future use) */
136 #define IFEF_AUTOCONFIGURING 0x1
137 #define IFEF_DVR_REENTRY_OK 0x20 /* When set, driver may be reentered from its own thread */
138 #define IFEF_ACCEPT_RTADVD 0x40 /* set to accept IPv6 router advertisement on the interface */
139 #define IFEF_DETACHING 0x80 /* Set when interface is detaching */
140 #define IFEF_USEKPI 0x100 /* Set when interface is created through the KPIs */
141 #define IFEF_VLAN 0x200 /* interface has one or more vlans */
142 #define IFEF_BOND 0x400 /* interface is part of bond */
143 #define IFEF_ARPLL 0x800 /* ARP for IPv4LL addresses on this port */
144 #define IFEF_REUSE 0x20000000 /* DLIL ifnet recycler, ifnet is not new */
145 #define IFEF_INUSE 0x40000000 /* DLIL ifnet recycler, ifnet in use */
146 #define IFEF_UPDOWNCHANGE 0x80000000 /* Interface's up/down state is changing */
147
148 /* flags set internally only: */
149 #define IFF_CANTCHANGE \
150 (IFF_BROADCAST|IFF_POINTOPOINT|IFF_RUNNING|IFF_OACTIVE|\
151 IFF_SIMPLEX|IFF_MULTICAST|IFF_ALLMULTI)
152
153 #endif /* KERNEL_PRIVATE */
154
155 #define IFQ_MAXLEN 50
156 #define IFNET_SLOWHZ 1 /* granularity is 1 second */
157
158 /*
159 * Message format for use in obtaining information about interfaces
160 * from sysctl and the routing socket
161 */
162 struct if_msghdr {
163 unsigned short ifm_msglen; /* to skip over non-understood messages */
164 unsigned char ifm_version; /* future binary compatability */
165 unsigned char ifm_type; /* message type */
166 int ifm_addrs; /* like rtm_addrs */
167 int ifm_flags; /* value of if_flags */
168 unsigned short ifm_index; /* index for associated ifp */
169 struct if_data ifm_data; /* statistics and other data about if */
170 };
171
172 /*
173 * Message format for use in obtaining information about interface addresses
174 * from sysctl and the routing socket
175 */
176 struct ifa_msghdr {
177 unsigned short ifam_msglen; /* to skip over non-understood messages */
178 unsigned char ifam_version; /* future binary compatability */
179 unsigned char ifam_type; /* message type */
180 int ifam_addrs; /* like rtm_addrs */
181 int ifam_flags; /* value of ifa_flags */
182 unsigned short ifam_index; /* index for associated ifp */
183 int ifam_metric; /* value of ifa_metric */
184 };
185
186 /*
187 * Message format for use in obtaining information about multicast addresses
188 * from the routing socket
189 */
190 struct ifma_msghdr {
191 unsigned short ifmam_msglen; /* to skip over non-understood messages */
192 unsigned char ifmam_version; /* future binary compatability */
193 unsigned char ifmam_type; /* message type */
194 int ifmam_addrs; /* like rtm_addrs */
195 int ifmam_flags; /* value of ifa_flags */
196 unsigned short ifmam_index; /* index for associated ifp */
197 };
198
199 /*
200 * Message format for use in obtaining information about interfaces
201 * from sysctl
202 */
203 struct if_msghdr2 {
204 u_short ifm_msglen; /* to skip over non-understood messages */
205 u_char ifm_version; /* future binary compatability */
206 u_char ifm_type; /* message type */
207 int ifm_addrs; /* like rtm_addrs */
208 int ifm_flags; /* value of if_flags */
209 u_short ifm_index; /* index for associated ifp */
210 int ifm_snd_len; /* instantaneous length of send queue */
211 int ifm_snd_maxlen; /* maximum length of send queue */
212 int ifm_snd_drops; /* number of drops in send queue */
213 int ifm_timer; /* time until if_watchdog called */
214 struct if_data64 ifm_data; /* statistics and other data about if */
215 };
216
217 /*
218 * Message format for use in obtaining information about multicast addresses
219 * from sysctl
220 */
221 struct ifma_msghdr2 {
222 u_short ifmam_msglen; /* to skip over non-understood messages */
223 u_char ifmam_version; /* future binary compatability */
224 u_char ifmam_type; /* message type */
225 int ifmam_addrs; /* like rtm_addrs */
226 int ifmam_flags; /* value of ifa_flags */
227 u_short ifmam_index; /* index for associated ifp */
228 int32_t ifmam_refcount;
229 };
230
231 /*
232 * ifdevmtu: interface device mtu
233 * Used with SIOCGIFDEVMTU to get the current mtu in use by the device,
234 * as well as the minimum and maximum mtu allowed by the device.
235 */
236 struct ifdevmtu {
237 int ifdm_current;
238 int ifdm_min;
239 int ifdm_max;
240 };
241
242 /*
243 * Interface request structure used for socket
244 * ioctl's. All interface ioctl's must have parameter
245 * definitions which begin with ifr_name. The
246 * remainder may be interface specific.
247 */
248 struct ifreq {
249 #ifndef IFNAMSIZ
250 #define IFNAMSIZ IF_NAMESIZE
251 #endif
252 char ifr_name[IFNAMSIZ]; /* if name, e.g. "en0" */
253 union {
254 struct sockaddr ifru_addr;
255 struct sockaddr ifru_dstaddr;
256 struct sockaddr ifru_broadaddr;
257 short ifru_flags;
258 int ifru_metric;
259 int ifru_mtu;
260 int ifru_phys;
261 int ifru_media;
262 int ifru_intval;
263 caddr_t ifru_data;
264 #ifdef KERNEL_PRIVATE
265 u_int64_t ifru_data64; /* 64-bit ifru_data */
266 #endif KERNEL_PRIVATE
267 struct ifdevmtu ifru_devmtu;
268 } ifr_ifru;
269 #define ifr_addr ifr_ifru.ifru_addr /* address */
270 #define ifr_dstaddr ifr_ifru.ifru_dstaddr /* other end of p-to-p link */
271 #define ifr_broadaddr ifr_ifru.ifru_broadaddr /* broadcast address */
272 #ifdef __APPLE__
273 #define ifr_flags ifr_ifru.ifru_flags /* flags */
274 #else
275 #define ifr_flags ifr_ifru.ifru_flags[0] /* flags */
276 #define ifr_prevflags ifr_ifru.ifru_flags[1] /* flags */
277 #endif /* __APPLE__ */
278 #define ifr_metric ifr_ifru.ifru_metric /* metric */
279 #define ifr_mtu ifr_ifru.ifru_mtu /* mtu */
280 #define ifr_phys ifr_ifru.ifru_phys /* physical wire */
281 #define ifr_media ifr_ifru.ifru_media /* physical media */
282 #define ifr_data ifr_ifru.ifru_data /* for use by interface */
283 #define ifr_devmtu ifr_ifru.ifru_devmtu
284 #define ifr_intval ifr_ifru.ifru_intval /* integer value */
285 #ifdef KERNEL_PRIVATE
286 #define ifr_data64 ifr_ifru.ifru_data64 /* 64-bit pointer */
287 #endif KERNEL_PRIVATE
288 };
289
290 #define _SIZEOF_ADDR_IFREQ(ifr) \
291 ((ifr).ifr_addr.sa_len > sizeof(struct sockaddr) ? \
292 (sizeof(struct ifreq) - sizeof(struct sockaddr) + \
293 (ifr).ifr_addr.sa_len) : sizeof(struct ifreq))
294
295 struct ifaliasreq {
296 char ifra_name[IFNAMSIZ]; /* if name, e.g. "en0" */
297 struct sockaddr ifra_addr;
298 struct sockaddr ifra_broadaddr;
299 struct sockaddr ifra_mask;
300 };
301
302 struct rslvmulti_req {
303 struct sockaddr *sa;
304 struct sockaddr **llsa;
305 };
306
307 struct ifmediareq {
308 char ifm_name[IFNAMSIZ]; /* if name, e.g. "en0" */
309 int ifm_current; /* current media options */
310 int ifm_mask; /* don't care mask */
311 int ifm_status; /* media status */
312 int ifm_active; /* active options */
313 int ifm_count; /* # entries in ifm_ulist array */
314 int *ifm_ulist; /* media words */
315 };
316
317 #ifdef KERNEL_PRIVATE
318 /* LP64 version of ifmediareq. all pointers
319 * grow when we're dealing with a 64-bit process.
320 * WARNING - keep in sync with ifmediareq
321 */
322 struct ifmediareq64 {
323 char ifm_name[IFNAMSIZ]; /* if name, e.g. "en0" */
324 int ifm_current; /* current media options */
325 int ifm_mask; /* don't care mask */
326 int ifm_status; /* media status */
327 int ifm_active; /* active options */
328 int ifm_count; /* # entries in ifm_ulist array */
329 union { /* media words */
330 int * ifmu_ulist32; /* 32-bit pointer */
331 u_int64_t ifmu_ulist64; /* 64-bit pointer */
332 } ifm_ifmu;
333 };
334 #endif // KERNEL_PRIVATE
335
336 /*
337 * Structure used to retrieve aux status data from interfaces.
338 * Kernel suppliers to this interface should respect the formatting
339 * needed by ifconfig(8): each line starts with a TAB and ends with
340 * a newline. The canonical example to copy and paste is in if_tun.c.
341 */
342
343 #define IFSTATMAX 800 /* 10 lines of text */
344 struct ifstat {
345 char ifs_name[IFNAMSIZ]; /* if name, e.g. "en0" */
346 char ascii[IFSTATMAX + 1];
347 };
348
349 /*
350 * Structure used in SIOCGIFCONF request.
351 * Used to retrieve interface configuration
352 * for machine (useful for programs which
353 * must know all networks accessible).
354 */
355 struct ifconf {
356 int ifc_len; /* size of associated buffer */
357 union {
358 caddr_t ifcu_buf;
359 struct ifreq *ifcu_req;
360 } ifc_ifcu;
361 #define ifc_buf ifc_ifcu.ifcu_buf /* buffer address */
362 #define ifc_req ifc_ifcu.ifcu_req /* array of structures returned */
363 };
364
365 #ifdef KERNEL_PRIVATE
366 /* LP64 version of ifconf. all pointers
367 * grow when we're dealing with a 64-bit process.
368 * WARNING - keep in sync with ifconf
369 */
370 struct ifconf64 {
371 int ifc_len; /* size of associated buffer */
372 union {
373 struct ifreq * ifcu_req;
374 u_int64_t ifcu_req64;
375 } ifc_ifcu;
376 };
377 #define ifc_req64 ifc_ifcu.ifcu_req64
378 #endif // KERNEL_PRIVATE
379
380 /*
381 * DLIL KEV_DL_PROTO_ATTACHED/DETACHED structure
382 */
383 struct kev_dl_proto_data {
384 struct net_event_data link_data;
385 unsigned long proto_family;
386 unsigned long proto_remaining_count;
387 };
388
389 /*
390 * Structure for SIOC[AGD]LIFADDR
391 */
392 struct if_laddrreq {
393 char iflr_name[IFNAMSIZ];
394 unsigned int flags;
395 #define IFLR_PREFIX 0x8000 /* in: prefix given out: kernel fills id */
396 unsigned int prefixlen; /* in/out */
397 struct sockaddr_storage addr; /* in/out */
398 struct sockaddr_storage dstaddr; /* out */
399 };
400
401 #ifdef KERNEL
402 #ifdef MALLOC_DECLARE
403 MALLOC_DECLARE(M_IFADDR);
404 MALLOC_DECLARE(M_IFMADDR);
405 #endif
406 #endif
407 #endif /* _POSIX_C_SOURCE */
408
409 #ifndef KERNEL
410 struct if_nameindex {
411 unsigned int if_index; /* 1, 2, ... */
412 char *if_name; /* null terminated name: "le0", ... */
413 };
414
415 __BEGIN_DECLS
416 unsigned int if_nametoindex(const char *);
417 char *if_indextoname(unsigned int, char *);
418 struct if_nameindex *if_nameindex(void);
419 void if_freenameindex(struct if_nameindex *);
420 __END_DECLS
421 #endif
422
423 #ifdef KERNEL
424 #include <net/kpi_interface.h>
425 #endif
426
427 #endif /* !_NET_IF_H_ */