]> git.saurik.com Git - apple/xnu.git/blob - bsd/net/if.h
xnu-344.49.tar.gz
[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_INUSE 0x40000000 /* DLIL ifnet recycler, ifnet in use */
124 #define IFEF_REUSE 0x20000000 /* DLIL ifnet recycler, ifnet is not new */
125 #endif /* KERNEL_PRIVATE */
126
127
128 /* flags set internally only: */
129 #define IFF_CANTCHANGE \
130 (IFF_BROADCAST|IFF_POINTOPOINT|IFF_RUNNING|IFF_OACTIVE|\
131 IFF_SIMPLEX|IFF_MULTICAST|IFF_ALLMULTI)
132
133 #define IFQ_MAXLEN 50
134 #define IFNET_SLOWHZ 1 /* granularity is 1 second */
135
136 /*
137 * Message format for use in obtaining information about interfaces
138 * from getkerninfo and the routing socket
139 */
140 struct if_msghdr {
141 u_short ifm_msglen; /* to skip over non-understood messages */
142 u_char ifm_version; /* future binary compatability */
143 u_char ifm_type; /* message type */
144 int ifm_addrs; /* like rtm_addrs */
145 int ifm_flags; /* value of if_flags */
146 u_short ifm_index; /* index for associated ifp */
147 struct if_data ifm_data;/* statistics and other data about if */
148 };
149
150 /*
151 * Message format for use in obtaining information about interface addresses
152 * from getkerninfo and the routing socket
153 */
154 struct ifa_msghdr {
155 u_short ifam_msglen; /* to skip over non-understood messages */
156 u_char ifam_version; /* future binary compatability */
157 u_char ifam_type; /* message type */
158 int ifam_addrs; /* like rtm_addrs */
159 int ifam_flags; /* value of ifa_flags */
160 u_short ifam_index; /* index for associated ifp */
161 int ifam_metric; /* value of ifa_metric */
162 };
163
164 /*
165 * Message format for use in obtaining information about multicast addresses
166 * from the routing socket
167 */
168 struct ifma_msghdr {
169 u_short ifmam_msglen; /* to skip over non-understood messages */
170 u_char ifmam_version; /* future binary compatability */
171 u_char ifmam_type; /* message type */
172 int ifmam_addrs; /* like rtm_addrs */
173 int ifmam_flags; /* value of ifa_flags */
174 u_short ifmam_index; /* index for associated ifp */
175 };
176
177 /*
178 * Interface request structure used for socket
179 * ioctl's. All interface ioctl's must have parameter
180 * definitions which begin with ifr_name. The
181 * remainder may be interface specific.
182 */
183 #define IF_NAMESIZE IFNAMSIZ
184 struct ifreq {
185 #define IFNAMSIZ 16
186 char ifr_name[IFNAMSIZ]; /* if name, e.g. "en0" */
187 union {
188 struct sockaddr ifru_addr;
189 struct sockaddr ifru_dstaddr;
190 struct sockaddr ifru_broadaddr;
191 short ifru_flags;
192 int ifru_metric;
193 int ifru_mtu;
194 int ifru_phys;
195 int ifru_media;
196 caddr_t ifru_data;
197 } ifr_ifru;
198 #define ifr_addr ifr_ifru.ifru_addr /* address */
199 #define ifr_dstaddr ifr_ifru.ifru_dstaddr /* other end of p-to-p link */
200 #define ifr_broadaddr ifr_ifru.ifru_broadaddr /* broadcast address */
201 #ifdef __APPLE__
202 #define ifr_flags ifr_ifru.ifru_flags /* flags */
203 #else
204 #define ifr_flags ifr_ifru.ifru_flags[0] /* flags */
205 #define ifr_prevflags ifr_ifru.ifru_flags[1] /* flags */
206 #endif /* __APPLE__ */
207 #define ifr_metric ifr_ifru.ifru_metric /* metric */
208 #define ifr_mtu ifr_ifru.ifru_mtu /* mtu */
209 #define ifr_phys ifr_ifru.ifru_phys /* physical wire */
210 #define ifr_media ifr_ifru.ifru_media /* physical media */
211 #define ifr_data ifr_ifru.ifru_data /* for use by interface */
212 };
213
214 #define _SIZEOF_ADDR_IFREQ(ifr) \
215 ((ifr).ifr_addr.sa_len > sizeof(struct sockaddr) ? \
216 (sizeof(struct ifreq) - sizeof(struct sockaddr) + \
217 (ifr).ifr_addr.sa_len) : sizeof(struct ifreq))
218
219 struct ifaliasreq {
220 char ifra_name[IFNAMSIZ]; /* if name, e.g. "en0" */
221 struct sockaddr ifra_addr;
222 struct sockaddr ifra_broadaddr;
223 struct sockaddr ifra_mask;
224 };
225
226 struct rslvmulti_req {
227 struct sockaddr *sa;
228 struct sockaddr **llsa;
229 };
230
231 struct ifmediareq {
232 char ifm_name[IFNAMSIZ]; /* if name, e.g. "en0" */
233 int ifm_current; /* current media options */
234 int ifm_mask; /* don't care mask */
235 int ifm_status; /* media status */
236 int ifm_active; /* active options */
237 int ifm_count; /* # entries in ifm_ulist array */
238 int *ifm_ulist; /* media words */
239 };
240
241 /*
242 * Structure used to retrieve aux status data from interfaces.
243 * Kernel suppliers to this interface should respect the formatting
244 * needed by ifconfig(8): each line starts with a TAB and ends with
245 * a newline. The canonical example to copy and paste is in if_tun.c.
246 */
247
248 #define IFSTATMAX 800 /* 10 lines of text */
249 struct ifstat {
250 char ifs_name[IFNAMSIZ]; /* if name, e.g. "en0" */
251 char ascii[IFSTATMAX + 1];
252 };
253
254 /*
255 * Structure used in SIOCGIFCONF request.
256 * Used to retrieve interface configuration
257 * for machine (useful for programs which
258 * must know all networks accessible).
259 */
260 struct ifconf {
261 int ifc_len; /* size of associated buffer */
262 union {
263 caddr_t ifcu_buf;
264 struct ifreq *ifcu_req;
265 } ifc_ifcu;
266 #define ifc_buf ifc_ifcu.ifcu_buf /* buffer address */
267 #define ifc_req ifc_ifcu.ifcu_req /* array of structures returned */
268 };
269
270 #ifdef __APPLE__
271 #ifdef __APPLE_API_UNSTABLE
272 /*
273 * DLIL KEV_DL_PROTO_ATTACHED/DETACHED structure
274 */
275 struct kev_dl_proto_data {
276 struct net_event_data link_data;
277 u_long proto_family;
278 u_long proto_remaining_count;
279 };
280 #endif /* __APPLE_API_UNSTABLE */
281 #endif
282
283
284 /*
285 * Structure for SIOC[AGD]LIFADDR
286 */
287 struct if_laddrreq {
288 char iflr_name[IFNAMSIZ];
289 u_int flags;
290 #define IFLR_PREFIX 0x8000 /* in: prefix given out: kernel fills id */
291 u_int prefixlen; /* in/out */
292 struct sockaddr_storage addr; /* in/out */
293 struct sockaddr_storage dstaddr; /* out */
294 };
295
296 #ifdef KERNEL
297 #ifdef MALLOC_DECLARE
298 MALLOC_DECLARE(M_IFADDR);
299 MALLOC_DECLARE(M_IFMADDR);
300 #endif
301 #endif
302
303 #ifndef KERNEL
304 struct if_nameindex {
305 u_int if_index; /* 1, 2, ... */
306 char *if_name; /* null terminated name: "le0", ... */
307 };
308
309 __BEGIN_DECLS
310 u_int if_nametoindex __P((const char *));
311 char *if_indextoname __P((u_int, char *));
312 struct if_nameindex *if_nameindex __P((void));
313 void if_freenameindex __P((struct if_nameindex *));
314 __END_DECLS
315 #endif
316
317 #ifdef KERNEL
318 #ifndef __APPLE__
319 struct proc;
320
321 int prison_if __P((struct proc *p, struct sockaddr *sa));
322 #endif
323
324 #endif
325
326 #endif /* !_NET_IF_H_ */