]> git.saurik.com Git - apple/xnu.git/blob - bsd/net/if.h
e034a4faa0509954fcbe5d28ad1184ae13ef42d0
[apple/xnu.git] / bsd / net / if.h
1 /*
2 * Copyright (c) 2000 Apple Computer, Inc. All rights reserved.
3 *
4 * @APPLE_LICENSE_HEADER_START@
5 *
6 * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
7 *
8 * This file contains Original Code and/or Modifications of Original Code
9 * as defined in and that are subject to the Apple Public Source License
10 * Version 2.0 (the 'License'). You may not use this file except in
11 * compliance with the License. Please obtain a copy of the License at
12 * http://www.opensource.apple.com/apsl/ and read it before using this
13 * file.
14 *
15 * The Original Code and all software distributed under the License are
16 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
17 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
18 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
19 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
20 * Please see the License for the specific language governing rights and
21 * limitations under the License.
22 *
23 * @APPLE_LICENSE_HEADER_END@
24 */
25 /*
26 * Copyright (c) 1982, 1986, 1989, 1993
27 * The Regents of the University of California. All rights reserved.
28 *
29 * Redistribution and use in source and binary forms, with or without
30 * modification, are permitted provided that the following conditions
31 * are met:
32 * 1. Redistributions of source code must retain the above copyright
33 * notice, this list of conditions and the following disclaimer.
34 * 2. Redistributions in binary form must reproduce the above copyright
35 * notice, this list of conditions and the following disclaimer in the
36 * documentation and/or other materials provided with the distribution.
37 * 3. All advertising materials mentioning features or use of this software
38 * must display the following acknowledgement:
39 * This product includes software developed by the University of
40 * California, Berkeley and its contributors.
41 * 4. Neither the name of the University nor the names of its contributors
42 * may be used to endorse or promote products derived from this software
43 * without specific prior written permission.
44 *
45 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
46 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
47 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
48 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
49 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
50 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
51 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
52 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
53 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
54 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
55 * SUCH DAMAGE.
56 *
57 * @(#)if.h 8.1 (Berkeley) 6/10/93
58 * $FreeBSD: src/sys/net/if.h,v 1.58.2.2 2001/07/24 19:10:18 brooks Exp $
59 */
60
61 #ifndef _NET_IF_H_
62 #define _NET_IF_H_
63 #include <sys/appleapiopts.h>
64
65 #ifdef __APPLE__
66 /*
67 * Define Data-Link event subclass, and associated
68 * events.
69 */
70
71 #define KEV_DL_SUBCLASS 2
72
73 #define KEV_DL_SIFFLAGS 1
74 #define KEV_DL_SIFMETRICS 2
75 #define KEV_DL_SIFMTU 3
76 #define KEV_DL_SIFPHYS 4
77 #define KEV_DL_SIFMEDIA 5
78 #define KEV_DL_SIFGENERIC 6
79 #define KEV_DL_ADDMULTI 7
80 #define KEV_DL_DELMULTI 8
81 #define KEV_DL_IF_ATTACHED 9
82 #define KEV_DL_IF_DETACHING 10
83 #define KEV_DL_IF_DETACHED 11
84 #define KEV_DL_LINK_OFF 12
85 #define KEV_DL_LINK_ON 13
86 #define KEV_DL_PROTO_ATTACHED 14
87 #define KEV_DL_PROTO_DETACHED 15
88 #endif
89
90 /*
91 * <net/if.h> does not depend on <sys/time.h> on most other systems. This
92 * helps userland compatability. (struct timeval ifi_lastchange)
93 */
94 #include <sys/time.h>
95
96 #ifdef __APPLE__
97 #include <net/if_var.h>
98 #endif
99
100
101 #define IFF_UP 0x1 /* interface is up */
102 #define IFF_BROADCAST 0x2 /* broadcast address valid */
103 #define IFF_DEBUG 0x4 /* turn on debugging */
104 #define IFF_LOOPBACK 0x8 /* is a loopback net */
105 #define IFF_POINTOPOINT 0x10 /* interface is point-to-point link */
106 #define IFF_NOTRAILERS 0x20 /* obsolete: avoid use of trailers */
107 #define IFF_RUNNING 0x40 /* resources allocated */
108 #define IFF_NOARP 0x80 /* no address resolution protocol */
109 #define IFF_PROMISC 0x100 /* receive all packets */
110 #define IFF_ALLMULTI 0x200 /* receive all multicast packets */
111 #define IFF_OACTIVE 0x400 /* transmission in progress */
112 #define IFF_SIMPLEX 0x800 /* can't hear own transmissions */
113 #define IFF_LINK0 0x1000 /* per link layer defined bit */
114 #define IFF_LINK1 0x2000 /* per link layer defined bit */
115 #define IFF_LINK2 0x4000 /* per link layer defined bit */
116 #define IFF_ALTPHYS IFF_LINK2 /* use alternate physical connection */
117 #define IFF_MULTICAST 0x8000 /* supports multicast */
118
119 #if KERNEL_PRIVATE
120 /* extended flags definitions: (all bits are reserved for internal/future use) */
121 #define IFEF_AUTOCONFIGURING 0x1
122 #define IFEF_DVR_REENTRY_OK 0x20 /* When set, driver may be reentered from its own thread */
123 #define IFEF_ACCEPT_RTADVD 0x40 /* set to accept IPv6 router advertisement on the interface */
124 #define IFEF_INUSE 0x40000000 /* DLIL ifnet recycler, ifnet in use */
125 #define IFEF_REUSE 0x20000000 /* DLIL ifnet recycler, ifnet is not new */
126 #endif /* KERNEL_PRIVATE */
127
128
129 /* flags set internally only: */
130 #define IFF_CANTCHANGE \
131 (IFF_BROADCAST|IFF_POINTOPOINT|IFF_RUNNING|IFF_OACTIVE|\
132 IFF_SIMPLEX|IFF_MULTICAST|IFF_ALLMULTI)
133
134 #define IFQ_MAXLEN 50
135 #define IFNET_SLOWHZ 1 /* granularity is 1 second */
136
137 /*
138 * Message format for use in obtaining information about interfaces
139 * from getkerninfo and the routing socket
140 */
141 struct if_msghdr {
142 u_short ifm_msglen; /* to skip over non-understood messages */
143 u_char ifm_version; /* future binary compatability */
144 u_char ifm_type; /* message type */
145 int ifm_addrs; /* like rtm_addrs */
146 int ifm_flags; /* value of if_flags */
147 u_short ifm_index; /* index for associated ifp */
148 struct if_data ifm_data;/* statistics and other data about if */
149 };
150
151 /*
152 * Message format for use in obtaining information about interface addresses
153 * from getkerninfo and the routing socket
154 */
155 struct ifa_msghdr {
156 u_short ifam_msglen; /* to skip over non-understood messages */
157 u_char ifam_version; /* future binary compatability */
158 u_char ifam_type; /* message type */
159 int ifam_addrs; /* like rtm_addrs */
160 int ifam_flags; /* value of ifa_flags */
161 u_short ifam_index; /* index for associated ifp */
162 int ifam_metric; /* value of ifa_metric */
163 };
164
165 /*
166 * Message format for use in obtaining information about multicast addresses
167 * from the routing socket
168 */
169 struct ifma_msghdr {
170 u_short ifmam_msglen; /* to skip over non-understood messages */
171 u_char ifmam_version; /* future binary compatability */
172 u_char ifmam_type; /* message type */
173 int ifmam_addrs; /* like rtm_addrs */
174 int ifmam_flags; /* value of ifa_flags */
175 u_short ifmam_index; /* index for associated ifp */
176 };
177
178 /*
179 * Interface request structure used for socket
180 * ioctl's. All interface ioctl's must have parameter
181 * definitions which begin with ifr_name. The
182 * remainder may be interface specific.
183 */
184 #define IF_NAMESIZE IFNAMSIZ
185 struct ifreq {
186 #define IFNAMSIZ 16
187 char ifr_name[IFNAMSIZ]; /* if name, e.g. "en0" */
188 union {
189 struct sockaddr ifru_addr;
190 struct sockaddr ifru_dstaddr;
191 struct sockaddr ifru_broadaddr;
192 short ifru_flags;
193 int ifru_metric;
194 int ifru_mtu;
195 int ifru_phys;
196 int ifru_media;
197 caddr_t ifru_data;
198 } ifr_ifru;
199 #define ifr_addr ifr_ifru.ifru_addr /* address */
200 #define ifr_dstaddr ifr_ifru.ifru_dstaddr /* other end of p-to-p link */
201 #define ifr_broadaddr ifr_ifru.ifru_broadaddr /* broadcast address */
202 #ifdef __APPLE__
203 #define ifr_flags ifr_ifru.ifru_flags /* flags */
204 #else
205 #define ifr_flags ifr_ifru.ifru_flags[0] /* flags */
206 #define ifr_prevflags ifr_ifru.ifru_flags[1] /* flags */
207 #endif /* __APPLE__ */
208 #define ifr_metric ifr_ifru.ifru_metric /* metric */
209 #define ifr_mtu ifr_ifru.ifru_mtu /* mtu */
210 #define ifr_phys ifr_ifru.ifru_phys /* physical wire */
211 #define ifr_media ifr_ifru.ifru_media /* physical media */
212 #define ifr_data ifr_ifru.ifru_data /* for use by interface */
213 };
214
215 #define _SIZEOF_ADDR_IFREQ(ifr) \
216 ((ifr).ifr_addr.sa_len > sizeof(struct sockaddr) ? \
217 (sizeof(struct ifreq) - sizeof(struct sockaddr) + \
218 (ifr).ifr_addr.sa_len) : sizeof(struct ifreq))
219
220 struct ifaliasreq {
221 char ifra_name[IFNAMSIZ]; /* if name, e.g. "en0" */
222 struct sockaddr ifra_addr;
223 struct sockaddr ifra_broadaddr;
224 struct sockaddr ifra_mask;
225 };
226
227 struct rslvmulti_req {
228 struct sockaddr *sa;
229 struct sockaddr **llsa;
230 };
231
232 struct ifmediareq {
233 char ifm_name[IFNAMSIZ]; /* if name, e.g. "en0" */
234 int ifm_current; /* current media options */
235 int ifm_mask; /* don't care mask */
236 int ifm_status; /* media status */
237 int ifm_active; /* active options */
238 int ifm_count; /* # entries in ifm_ulist array */
239 int *ifm_ulist; /* media words */
240 };
241
242 /*
243 * Structure used to retrieve aux status data from interfaces.
244 * Kernel suppliers to this interface should respect the formatting
245 * needed by ifconfig(8): each line starts with a TAB and ends with
246 * a newline. The canonical example to copy and paste is in if_tun.c.
247 */
248
249 #define IFSTATMAX 800 /* 10 lines of text */
250 struct ifstat {
251 char ifs_name[IFNAMSIZ]; /* if name, e.g. "en0" */
252 char ascii[IFSTATMAX + 1];
253 };
254
255 /*
256 * Structure used in SIOCGIFCONF request.
257 * Used to retrieve interface configuration
258 * for machine (useful for programs which
259 * must know all networks accessible).
260 */
261 struct ifconf {
262 int ifc_len; /* size of associated buffer */
263 union {
264 caddr_t ifcu_buf;
265 struct ifreq *ifcu_req;
266 } ifc_ifcu;
267 #define ifc_buf ifc_ifcu.ifcu_buf /* buffer address */
268 #define ifc_req ifc_ifcu.ifcu_req /* array of structures returned */
269 };
270
271 #ifdef __APPLE__
272 #ifdef __APPLE_API_UNSTABLE
273 /*
274 * DLIL KEV_DL_PROTO_ATTACHED/DETACHED structure
275 */
276 struct kev_dl_proto_data {
277 struct net_event_data link_data;
278 u_long proto_family;
279 u_long proto_remaining_count;
280 };
281 #endif /* __APPLE_API_UNSTABLE */
282 #endif
283
284
285 /*
286 * Structure for SIOC[AGD]LIFADDR
287 */
288 struct if_laddrreq {
289 char iflr_name[IFNAMSIZ];
290 u_int flags;
291 #define IFLR_PREFIX 0x8000 /* in: prefix given out: kernel fills id */
292 u_int prefixlen; /* in/out */
293 struct sockaddr_storage addr; /* in/out */
294 struct sockaddr_storage dstaddr; /* out */
295 };
296
297 #ifdef KERNEL
298 #ifdef MALLOC_DECLARE
299 MALLOC_DECLARE(M_IFADDR);
300 MALLOC_DECLARE(M_IFMADDR);
301 #endif
302 #endif
303
304 #ifndef KERNEL
305 struct if_nameindex {
306 u_int if_index; /* 1, 2, ... */
307 char *if_name; /* null terminated name: "le0", ... */
308 };
309
310 __BEGIN_DECLS
311 u_int if_nametoindex __P((const char *));
312 char *if_indextoname __P((u_int, char *));
313 struct if_nameindex *if_nameindex __P((void));
314 void if_freenameindex __P((struct if_nameindex *));
315 __END_DECLS
316 #endif
317
318 #ifdef KERNEL
319 #ifndef __APPLE__
320 struct proc;
321
322 int prison_if __P((struct proc *p, struct sockaddr *sa));
323 #endif
324
325 #endif
326
327 #endif /* !_NET_IF_H_ */