]>
Commit | Line | Data |
---|---|---|
1c79356b | 1 | /* |
c910b4d9 | 2 | * Copyright (c) 2000-2008 Apple Inc. All rights reserved. |
5d5c5d0d | 3 | * |
2d21ac55 | 4 | * @APPLE_OSREFERENCE_LICENSE_HEADER_START@ |
1c79356b | 5 | * |
2d21ac55 A |
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. | |
8f6c56a5 | 14 | * |
2d21ac55 A |
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 | |
8f6c56a5 A |
20 | * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, |
21 | * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, | |
2d21ac55 A |
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. | |
8f6c56a5 | 25 | * |
2d21ac55 | 26 | * @APPLE_OSREFERENCE_LICENSE_HEADER_END@ |
1c79356b A |
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 | * From: @(#)if.h 8.1 (Berkeley) 6/10/93 | |
9bccf70c | 61 | * $FreeBSD: src/sys/net/if_var.h,v 1.18.2.7 2001/07/24 19:10:18 brooks Exp $ |
1c79356b A |
62 | */ |
63 | ||
64 | #ifndef _NET_IF_VAR_H_ | |
65 | #define _NET_IF_VAR_H_ | |
91447636 | 66 | |
9bccf70c | 67 | #include <sys/appleapiopts.h> |
b0d623f7 | 68 | #include <stdint.h> |
91447636 A |
69 | #include <sys/types.h> |
70 | #include <sys/time.h> | |
71 | #include <sys/queue.h> /* get TAILQ macros */ | |
72 | #ifdef KERNEL_PRIVATE | |
73 | #include <kern/locks.h> | |
74 | #endif /* KERNEL_PRIVATE */ | |
b0d623f7 A |
75 | #ifdef PRIVATE |
76 | #include <net/route.h> | |
77 | #endif | |
91447636 A |
78 | |
79 | #ifdef KERNEL | |
80 | #include <net/kpi_interface.h> | |
b0d623f7 | 81 | #endif /* KERNEL */ |
1c79356b | 82 | |
9bccf70c | 83 | #ifdef __APPLE__ |
1c79356b A |
84 | #define APPLE_IF_FAM_LOOPBACK 1 |
85 | #define APPLE_IF_FAM_ETHERNET 2 | |
86 | #define APPLE_IF_FAM_SLIP 3 | |
87 | #define APPLE_IF_FAM_TUN 4 | |
88 | #define APPLE_IF_FAM_VLAN 5 | |
89 | #define APPLE_IF_FAM_PPP 6 | |
90 | #define APPLE_IF_FAM_PVC 7 | |
91 | #define APPLE_IF_FAM_DISC 8 | |
92 | #define APPLE_IF_FAM_MDECAP 9 | |
93 | #define APPLE_IF_FAM_GIF 10 | |
94 | #define APPLE_IF_FAM_FAITH 11 | |
55e303ae A |
95 | #define APPLE_IF_FAM_STF 12 |
96 | #define APPLE_IF_FAM_FIREWIRE 13 | |
91447636 | 97 | #define APPLE_IF_FAM_BOND 14 |
0c530ab8 | 98 | #endif /* __APPLE__ */ |
91447636 A |
99 | |
100 | /* | |
101 | * 72 was chosen below because it is the size of a TCP/IP | |
102 | * header (40) + the minimum mss (32). | |
103 | */ | |
104 | #define IF_MINMTU 72 | |
105 | #define IF_MAXMTU 65535 | |
1c79356b A |
106 | |
107 | /* | |
108 | * Structures defining a network interface, providing a packet | |
109 | * transport mechanism (ala level 0 of the PUP protocols). | |
110 | * | |
111 | * Each interface accepts output datagrams of a specified maximum | |
112 | * length, and provides higher level routines with input datagrams | |
113 | * received from its medium. | |
114 | * | |
115 | * Output occurs when the routine if_output is called, with three parameters: | |
116 | * (*ifp->if_output)(ifp, m, dst, rt) | |
117 | * Here m is the mbuf chain to be sent and dst is the destination address. | |
118 | * The output routine encapsulates the supplied datagram if necessary, | |
119 | * and then transmits it on its medium. | |
120 | * | |
121 | * On input, each interface unwraps the data received by it, and either | |
122 | * places it on the input queue of a internetwork datagram routine | |
123 | * and posts the associated software interrupt, or passes the datagram to a raw | |
124 | * packet input routine. | |
125 | * | |
126 | * Routines exist for locating interfaces by their addresses | |
127 | * or for locating a interface on a certain network, as well as more general | |
128 | * routing and gateway routines maintaining information used to locate | |
129 | * interfaces. These routines live in the files if.c and route.c | |
130 | */ | |
131 | ||
1c79356b A |
132 | #define IFNAMSIZ 16 |
133 | ||
1c79356b A |
134 | /* This belongs up in socket.h or socketvar.h, depending on how far the |
135 | * event bubbles up. | |
136 | */ | |
137 | ||
138 | struct net_event_data { | |
2d21ac55 A |
139 | u_int32_t if_family; |
140 | u_int32_t if_unit; | |
141 | char if_name[IFNAMSIZ]; | |
1c79356b | 142 | }; |
1c79356b | 143 | |
2d21ac55 A |
144 | #if defined(__LP64__) |
145 | #define __need_struct_timeval32 | |
146 | #include <sys/_structs.h> | |
147 | #define IF_DATA_TIMEVAL timeval32 | |
148 | #else | |
149 | #define IF_DATA_TIMEVAL timeval | |
150 | #endif | |
151 | ||
152 | #pragma pack(4) | |
153 | ||
91447636 A |
154 | /* |
155 | * Structure describing information about an interface | |
156 | * which may be of interest to management entities. | |
157 | */ | |
158 | struct if_data { | |
159 | /* generic interface information */ | |
2d21ac55 A |
160 | u_char ifi_type; /* ethernet, tokenring, etc */ |
161 | u_char ifi_typelen; /* Length of frame type id */ | |
162 | u_char ifi_physical; /* e.g., AUI, Thinnet, 10base-T, etc */ | |
163 | u_char ifi_addrlen; /* media address length */ | |
164 | u_char ifi_hdrlen; /* media header length */ | |
165 | u_char ifi_recvquota; /* polling quota for receive intrs */ | |
166 | u_char ifi_xmitquota; /* polling quota for xmit intrs */ | |
167 | u_char ifi_unused1; /* for future use */ | |
168 | u_int32_t ifi_mtu; /* maximum transmission unit */ | |
169 | u_int32_t ifi_metric; /* routing metric (external only) */ | |
170 | u_int32_t ifi_baudrate; /* linespeed */ | |
91447636 | 171 | /* volatile statistics */ |
2d21ac55 A |
172 | u_int32_t ifi_ipackets; /* packets received on interface */ |
173 | u_int32_t ifi_ierrors; /* input errors on interface */ | |
174 | u_int32_t ifi_opackets; /* packets sent on interface */ | |
175 | u_int32_t ifi_oerrors; /* output errors on interface */ | |
176 | u_int32_t ifi_collisions; /* collisions on csma interfaces */ | |
177 | u_int32_t ifi_ibytes; /* total number of octets received */ | |
178 | u_int32_t ifi_obytes; /* total number of octets sent */ | |
179 | u_int32_t ifi_imcasts; /* packets received via multicast */ | |
180 | u_int32_t ifi_omcasts; /* packets sent via multicast */ | |
181 | u_int32_t ifi_iqdrops; /* dropped on input, this interface */ | |
182 | u_int32_t ifi_noproto; /* destined for unsupported protocol */ | |
183 | u_int32_t ifi_recvtiming; /* usec spent receiving when timing */ | |
184 | u_int32_t ifi_xmittiming; /* usec spent xmitting when timing */ | |
185 | struct IF_DATA_TIMEVAL ifi_lastchange; /* time of last administrative change */ | |
186 | u_int32_t ifi_unused2; /* used to be the default_proto */ | |
187 | u_int32_t ifi_hwassist; /* HW offload capabilities */ | |
188 | u_int32_t ifi_reserved1; /* for future use */ | |
189 | u_int32_t ifi_reserved2; /* for future use */ | |
91447636 | 190 | }; |
4a249263 | 191 | |
1c79356b A |
192 | /* |
193 | * Structure describing information about an interface | |
194 | * which may be of interest to management entities. | |
195 | */ | |
91447636 | 196 | struct if_data64 { |
1c79356b | 197 | /* generic interface information */ |
2d21ac55 A |
198 | u_char ifi_type; /* ethernet, tokenring, etc */ |
199 | u_char ifi_typelen; /* Length of frame type id */ | |
91447636 A |
200 | u_char ifi_physical; /* e.g., AUI, Thinnet, 10base-T, etc */ |
201 | u_char ifi_addrlen; /* media address length */ | |
202 | u_char ifi_hdrlen; /* media header length */ | |
203 | u_char ifi_recvquota; /* polling quota for receive intrs */ | |
204 | u_char ifi_xmitquota; /* polling quota for xmit intrs */ | |
205 | u_char ifi_unused1; /* for future use */ | |
2d21ac55 A |
206 | u_int32_t ifi_mtu; /* maximum transmission unit */ |
207 | u_int32_t ifi_metric; /* routing metric (external only) */ | |
91447636 A |
208 | u_int64_t ifi_baudrate; /* linespeed */ |
209 | /* volatile statistics */ | |
210 | u_int64_t ifi_ipackets; /* packets received on interface */ | |
211 | u_int64_t ifi_ierrors; /* input errors on interface */ | |
212 | u_int64_t ifi_opackets; /* packets sent on interface */ | |
213 | u_int64_t ifi_oerrors; /* output errors on interface */ | |
214 | u_int64_t ifi_collisions; /* collisions on csma interfaces */ | |
215 | u_int64_t ifi_ibytes; /* total number of octets received */ | |
216 | u_int64_t ifi_obytes; /* total number of octets sent */ | |
217 | u_int64_t ifi_imcasts; /* packets received via multicast */ | |
218 | u_int64_t ifi_omcasts; /* packets sent via multicast */ | |
219 | u_int64_t ifi_iqdrops; /* dropped on input, this interface */ | |
220 | u_int64_t ifi_noproto; /* destined for unsupported protocol */ | |
2d21ac55 A |
221 | u_int32_t ifi_recvtiming; /* usec spent receiving when timing */ |
222 | u_int32_t ifi_xmittiming; /* usec spent xmitting when timing */ | |
223 | struct IF_DATA_TIMEVAL ifi_lastchange; /* time of last administrative change */ | |
91447636 A |
224 | }; |
225 | ||
2d21ac55 A |
226 | #pragma pack() |
227 | ||
91447636 A |
228 | #ifdef PRIVATE |
229 | /* | |
230 | * Internal storage of if_data. This is bound to change. Various places in the | |
231 | * stack will translate this data structure in to the externally visible | |
232 | * if_data structure above. | |
233 | */ | |
234 | struct if_data_internal { | |
235 | /* generic interface information */ | |
2d21ac55 A |
236 | u_char ifi_type; /* ethernet, tokenring, etc */ |
237 | u_char ifi_typelen; /* Length of frame type id */ | |
238 | u_char ifi_physical; /* e.g., AUI, Thinnet, 10base-T, etc */ | |
239 | u_char ifi_addrlen; /* media address length */ | |
240 | u_char ifi_hdrlen; /* media header length */ | |
241 | u_char ifi_recvquota; /* polling quota for receive intrs */ | |
242 | u_char ifi_xmitquota; /* polling quota for xmit intrs */ | |
243 | u_char ifi_unused1; /* for future use */ | |
244 | u_int32_t ifi_mtu; /* maximum transmission unit */ | |
245 | u_int32_t ifi_metric; /* routing metric (external only) */ | |
246 | u_int32_t ifi_baudrate; /* linespeed */ | |
1c79356b | 247 | /* volatile statistics */ |
91447636 A |
248 | u_int64_t ifi_ipackets; /* packets received on interface */ |
249 | u_int64_t ifi_ierrors; /* input errors on interface */ | |
250 | u_int64_t ifi_opackets; /* packets sent on interface */ | |
251 | u_int64_t ifi_oerrors; /* output errors on interface */ | |
252 | u_int64_t ifi_collisions; /* collisions on csma interfaces */ | |
2d21ac55 A |
253 | u_int64_t ifi_ibytes; /* total number of octets received */ |
254 | u_int64_t ifi_obytes; /* total number of octets sent */ | |
91447636 A |
255 | u_int64_t ifi_imcasts; /* packets received via multicast */ |
256 | u_int64_t ifi_omcasts; /* packets sent via multicast */ | |
257 | u_int64_t ifi_iqdrops; /* dropped on input, this interface */ | |
258 | u_int64_t ifi_noproto; /* destined for unsupported protocol */ | |
2d21ac55 A |
259 | u_int32_t ifi_recvtiming; /* usec spent receiving when timing */ |
260 | u_int32_t ifi_xmittiming; /* usec spent xmitting when timing */ | |
91447636 | 261 | #define IF_LASTCHANGEUPTIME 1 /* lastchange: 1-uptime 0-calendar time */ |
1c79356b | 262 | struct timeval ifi_lastchange; /* time of last administrative change */ |
2d21ac55 | 263 | u_int32_t ifi_hwassist; /* HW offload capabilities */ |
b0d623f7 A |
264 | u_int32_t ifi_tso_v4_mtu; /* TCP Segment Offload IPv4 maximum segment size */ |
265 | u_int32_t ifi_tso_v6_mtu; /* TCP Segment Offload IPv6 maximum segment size */ | |
1c79356b | 266 | }; |
91447636 A |
267 | |
268 | #define if_mtu if_data.ifi_mtu | |
269 | #define if_type if_data.ifi_type | |
270 | #define if_typelen if_data.ifi_typelen | |
271 | #define if_physical if_data.ifi_physical | |
272 | #define if_addrlen if_data.ifi_addrlen | |
273 | #define if_hdrlen if_data.ifi_hdrlen | |
274 | #define if_metric if_data.ifi_metric | |
275 | #define if_baudrate if_data.ifi_baudrate | |
276 | #define if_hwassist if_data.ifi_hwassist | |
277 | #define if_ipackets if_data.ifi_ipackets | |
278 | #define if_ierrors if_data.ifi_ierrors | |
279 | #define if_opackets if_data.ifi_opackets | |
280 | #define if_oerrors if_data.ifi_oerrors | |
281 | #define if_collisions if_data.ifi_collisions | |
282 | #define if_ibytes if_data.ifi_ibytes | |
283 | #define if_obytes if_data.ifi_obytes | |
284 | #define if_imcasts if_data.ifi_imcasts | |
285 | #define if_omcasts if_data.ifi_omcasts | |
286 | #define if_iqdrops if_data.ifi_iqdrops | |
287 | #define if_noproto if_data.ifi_noproto | |
288 | #define if_lastchange if_data.ifi_lastchange | |
289 | #define if_recvquota if_data.ifi_recvquota | |
290 | #define if_xmitquota if_data.ifi_xmitquota | |
291 | #define if_iflags if_data.ifi_iflags | |
b0d623f7 A |
292 | #define if_tso_v4_mtu if_data.ifi_tso_v4_mtu |
293 | #define if_tso_v6_mtu if_data.ifi_tso_v6_mtu | |
91447636 A |
294 | |
295 | struct mbuf; | |
296 | struct ifaddr; | |
297 | TAILQ_HEAD(ifnethead, ifnet); /* we use TAILQs so that the order of */ | |
298 | TAILQ_HEAD(ifaddrhead, ifaddr); /* instantiation is preserved in the list */ | |
299 | TAILQ_HEAD(ifprefixhead, ifprefix); | |
300 | LIST_HEAD(ifmultihead, ifmultiaddr); | |
301 | struct tqdummy; | |
302 | TAILQ_HEAD(tailq_head, tqdummy); | |
303 | ||
304 | /* | |
305 | * Forward structure declarations for function prototypes [sic]. | |
306 | */ | |
307 | struct proc; | |
308 | struct rtentry; | |
309 | struct socket; | |
310 | struct ether_header; | |
311 | struct sockaddr_dl; | |
312 | struct ifnet_filter; | |
313 | ||
314 | TAILQ_HEAD(ifnet_filter_head, ifnet_filter); | |
315 | TAILQ_HEAD(ddesc_head_name, dlil_demux_desc); | |
316 | ||
b0d623f7 A |
317 | /* All of the following IF_HWASSIST_* flags are defined |
318 | * in kpi_inteface.h as IFNET_* flags. These are redefined | |
319 | * here as constants to avoid failures to build user level | |
320 | * programs that can not include kpi_interface.h. It is | |
321 | * important to keep this in sync with the definitions in | |
322 | * kpi_interface.h. The corresponding constant for each | |
323 | * definition is mentioned in the comment. | |
324 | * | |
325 | * Bottom 16 bits reserved for hardware checksum | |
326 | */ | |
327 | #define IF_HWASSIST_CSUM_IP 0x0001 /* will csum IP, IFNET_CSUM_IP */ | |
328 | #define IF_HWASSIST_CSUM_TCP 0x0002 /* will csum TCP, IFNET_CSUM_TCP */ | |
329 | #define IF_HWASSIST_CSUM_UDP 0x0004 /* will csum UDP, IFNET_CSUM_UDP */ | |
330 | #define IF_HWASSIST_CSUM_IP_FRAGS 0x0008 /* will csum IP fragments, IFNET_CSUM_FRAGMENT */ | |
331 | #define IF_HWASSIST_CSUM_FRAGMENT 0x0010 /* will do IP fragmentation, IFNET_IP_FRAGMENT */ | |
332 | #define IF_HWASSIST_CSUM_TCP_SUM16 0x1000 /* simple TCP Sum16 computation, IFNET_CSUM_SUM16 */ | |
91447636 A |
333 | #define IF_HWASSIST_CSUM_MASK 0xffff |
334 | #define IF_HWASSIST_CSUM_FLAGS(hwassist) ((hwassist) & IF_HWASSIST_CSUM_MASK) | |
335 | ||
336 | /* VLAN support */ | |
b0d623f7 A |
337 | #define IF_HWASSIST_VLAN_TAGGING 0x00010000 /* supports VLAN tagging, IFNET_VLAN_TAGGING */ |
338 | #define IF_HWASSIST_VLAN_MTU 0x00020000 /* supports VLAN MTU-sized packet (for software VLAN), IFNET_VLAN_MTU */ | |
339 | ||
340 | /* TCP Segment Offloading support */ | |
341 | ||
342 | #define IF_HWASSIST_TSO_V4 0x00200000 /* will do TCP Segment offload for IPv4, IFNET_TSO_IPV4 */ | |
343 | #define IF_HWASSIST_TSO_V6 0x00400000 /* will do TCP Segment offload for IPv6, IFNET_TSO_IPV6 */ | |
91447636 A |
344 | |
345 | #define IFNET_RW_LOCK 1 | |
1c79356b | 346 | |
2d21ac55 | 347 | #endif /* PRIVATE */ |
1c79356b A |
348 | /* |
349 | * Structure defining a queue for a network interface. | |
350 | */ | |
351 | struct ifqueue { | |
91447636 A |
352 | void *ifq_head; |
353 | void *ifq_tail; | |
1c79356b A |
354 | int ifq_len; |
355 | int ifq_maxlen; | |
356 | int ifq_drops; | |
357 | }; | |
358 | ||
2d21ac55 A |
359 | #ifdef PRIVATE |
360 | ||
91447636 A |
361 | struct ddesc_head_str; |
362 | struct proto_hash_entry; | |
363 | struct kev_msg; | |
2d21ac55 | 364 | struct dlil_threading_info; |
b0d623f7 A |
365 | #if PF |
366 | struct pfi_kif; | |
367 | #endif /* PF */ | |
91447636 | 368 | |
1c79356b A |
369 | /* |
370 | * Structure defining a network interface. | |
371 | * | |
372 | * (Would like to call this struct ``if'', but C isn't PL/1.) | |
373 | */ | |
374 | struct ifnet { | |
375 | void *if_softc; /* pointer to driver state */ | |
91447636 | 376 | const char *if_name; /* name, e.g. ``en'' or ``lo'' */ |
1c79356b A |
377 | TAILQ_ENTRY(ifnet) if_link; /* all struct ifnets are chained */ |
378 | struct ifaddrhead if_addrhead; /* linked list of addresses per if */ | |
b0d623f7 | 379 | u_int32_t if_refcnt; |
91447636 A |
380 | #ifdef __KPI_INTERFACE__ |
381 | ifnet_check_multi if_check_multi; | |
382 | #else | |
383 | void* if_check_multi; | |
b0d623f7 | 384 | #endif /* __KPI_INTERFACE__ */ |
91447636 | 385 | int if_pcount; /* number of promiscuous listeners */ |
1c79356b A |
386 | struct bpf_if *if_bpf; /* packet filter structure */ |
387 | u_short if_index; /* numeric abbreviation for this if */ | |
388 | short if_unit; /* sub-unit for lower level driver */ | |
389 | short if_timer; /* time 'til if_watchdog called */ | |
390 | short if_flags; /* up/down, broadcast, etc. */ | |
391 | int if_ipending; /* interrupts pending */ | |
392 | void *if_linkmib; /* link-type-specific MIB data */ | |
393 | size_t if_linkmiblen; /* length of above data */ | |
91447636 | 394 | struct if_data_internal if_data; |
1c79356b A |
395 | |
396 | /* New with DLIL */ | |
91447636 A |
397 | #ifdef BSD_KERNEL_PRIVATE |
398 | int if_usecnt; | |
399 | #else | |
1c79356b | 400 | int refcnt; |
91447636 | 401 | #endif |
91447636 A |
402 | #ifdef __KPI_INTERFACE__ |
403 | ifnet_output_func if_output; | |
404 | ifnet_ioctl_func if_ioctl; | |
405 | ifnet_set_bpf_tap if_set_bpf_tap; | |
406 | ifnet_detached_func if_free; | |
407 | ifnet_demux_func if_demux; | |
408 | ifnet_event_func if_event; | |
409 | ifnet_framer_func if_framer; | |
b0d623f7 | 410 | ifnet_family_t if_family; /* value assigned by Apple */ |
91447636 A |
411 | #else |
412 | void* if_output; | |
413 | void* if_ioctl; | |
414 | void* if_set_bpf_tap; | |
415 | void* if_free; | |
416 | void* if_demux; | |
417 | void* if_event; | |
418 | void* if_framer; | |
b0d623f7 | 419 | u_int32_t if_family; /* value assigned by Apple */ |
91447636 | 420 | #endif |
1c79356b | 421 | |
91447636 | 422 | struct ifnet_filter_head if_flt_head; |
1c79356b A |
423 | |
424 | /* End DLIL specific */ | |
425 | ||
b0d623f7 | 426 | u_int32_t if_delayed_detach; /* need to perform delayed detach */ |
9bccf70c | 427 | void *if_private; /* private to interface */ |
1c79356b | 428 | long if_eflags; /* autoaddr, autoaddr done, etc. */ |
1c79356b A |
429 | |
430 | struct ifmultihead if_multiaddrs; /* multicast addresses configured */ | |
431 | int if_amcount; /* number of all-multicast requests */ | |
432 | /* procedure handles */ | |
91447636 | 433 | #ifdef __KPI_INTERFACE__ |
2d21ac55 | 434 | ifnet_add_proto_func if_add_proto; |
91447636 | 435 | ifnet_del_proto_func if_del_proto; |
b0d623f7 | 436 | #else /* !__KPI_INTERFACE__ */ |
91447636 A |
437 | void* if_add_proto; |
438 | void* if_del_proto; | |
b0d623f7 | 439 | #endif /* !__KPI_INTERFACE__ */ |
91447636 A |
440 | struct proto_hash_entry *if_proto_hash; |
441 | void *if_kpi_storage; | |
2d21ac55 | 442 | #if 0 |
91447636 | 443 | void *unused_was_init; |
2d21ac55 A |
444 | #else |
445 | struct dlil_threading_info *if_input_thread; | |
446 | #endif | |
91447636 A |
447 | void *unused_was_resolvemulti; |
448 | ||
449 | struct ifqueue if_snd; | |
b0d623f7 | 450 | u_int32_t unused_2[1]; |
9bccf70c | 451 | #ifdef __APPLE__ |
b0d623f7 | 452 | uintptr_t family_cookie; |
9bccf70c | 453 | struct ifprefixhead if_prefixhead; /* list of prefixes per if */ |
91447636 A |
454 | |
455 | #ifdef _KERN_LOCKS_H_ | |
456 | #if IFNET_RW_LOCK | |
457 | lck_rw_t *if_lock; /* Lock to protect this interface */ | |
458 | #else | |
459 | lck_mtx_t *if_lock; /* Lock to protect this interface */ | |
460 | #endif | |
461 | #else | |
462 | void *if_lock; | |
463 | #endif | |
464 | ||
9bccf70c A |
465 | #else |
466 | struct ifprefixhead if_prefixhead; /* list of prefixes per if */ | |
467 | #endif /* __APPLE__ */ | |
91447636 | 468 | struct { |
b0d623f7 | 469 | u_int32_t length; |
91447636 A |
470 | union { |
471 | u_char buffer[8]; | |
472 | u_char *ptr; | |
473 | } u; | |
474 | } if_broadcast; | |
2d21ac55 A |
475 | #if CONFIG_MACF_NET |
476 | struct label *if_label; /* interface MAC label */ | |
477 | #endif | |
b0d623f7 A |
478 | |
479 | u_int32_t if_wake_properties; | |
480 | #if PF | |
481 | struct thread *if_pf_curthread; | |
482 | struct pfi_kif *if_pf_kif; | |
483 | #endif /* PF */ | |
484 | #ifdef _KERN_LOCKS_H_ | |
485 | lck_mtx_t *if_fwd_route_lock; | |
486 | #else | |
487 | void *if_fwd_route_lock; | |
488 | #endif | |
489 | struct route if_fwd_route; /* cached IPv4 forwarding route */ | |
1c79356b | 490 | }; |
1c79356b | 491 | |
9bccf70c A |
492 | #ifndef __APPLE__ |
493 | /* for compatibility with other BSDs */ | |
494 | #define if_addrlist if_addrhead | |
495 | #define if_list if_link | |
b0d623f7 | 496 | #endif /* !__APPLE__ */ |
91447636 A |
497 | |
498 | ||
499 | #endif /* PRIVATE */ | |
500 | ||
4a249263 A |
501 | #ifdef KERNEL_PRIVATE |
502 | /* | |
503 | * Structure describing a `cloning' interface. | |
504 | */ | |
505 | struct if_clone { | |
506 | LIST_ENTRY(if_clone) ifc_list; /* on list of cloners */ | |
91447636 | 507 | const char *ifc_name; /* name of device, e.g. `vlan' */ |
4a249263 A |
508 | size_t ifc_namelen; /* length of name */ |
509 | int ifc_minifs; /* minimum number of interfaces */ | |
510 | int ifc_maxunit; /* maximum unit number */ | |
511 | unsigned char *ifc_units; /* bitmap to handle units */ | |
512 | int ifc_bmlen; /* bitmap length */ | |
513 | ||
514 | int (*ifc_create)(struct if_clone *, int); | |
515 | void (*ifc_destroy)(struct ifnet *); | |
516 | }; | |
517 | ||
518 | #define IF_CLONE_INITIALIZER(name, create, destroy, minifs, maxunit) \ | |
2d21ac55 | 519 | { { NULL, NULL }, name, sizeof(name) - 1, minifs, maxunit, NULL, 0, create, destroy } |
9bccf70c | 520 | |
1c79356b A |
521 | /* |
522 | * Bit values in if_ipending | |
523 | */ | |
524 | #define IFI_RECV 1 /* I want to receive */ | |
525 | #define IFI_XMIT 2 /* I want to transmit */ | |
526 | ||
527 | /* | |
528 | * Output queues (ifp->if_snd) and slow device input queues (*ifp->if_slowq) | |
529 | * are queues of messages stored on ifqueue structures | |
530 | * (defined above). Entries are added to and deleted from these structures | |
531 | * by these macros, which should be called with ipl raised to splimp(). | |
532 | */ | |
533 | #define IF_QFULL(ifq) ((ifq)->ifq_len >= (ifq)->ifq_maxlen) | |
534 | #define IF_DROP(ifq) ((ifq)->ifq_drops++) | |
535 | #define IF_ENQUEUE(ifq, m) { \ | |
536 | (m)->m_nextpkt = 0; \ | |
537 | if ((ifq)->ifq_tail == 0) \ | |
538 | (ifq)->ifq_head = m; \ | |
539 | else \ | |
91447636 | 540 | ((struct mbuf*)(ifq)->ifq_tail)->m_nextpkt = m; \ |
1c79356b A |
541 | (ifq)->ifq_tail = m; \ |
542 | (ifq)->ifq_len++; \ | |
543 | } | |
544 | #define IF_PREPEND(ifq, m) { \ | |
545 | (m)->m_nextpkt = (ifq)->ifq_head; \ | |
546 | if ((ifq)->ifq_tail == 0) \ | |
547 | (ifq)->ifq_tail = (m); \ | |
548 | (ifq)->ifq_head = (m); \ | |
549 | (ifq)->ifq_len++; \ | |
550 | } | |
551 | #define IF_DEQUEUE(ifq, m) { \ | |
552 | (m) = (ifq)->ifq_head; \ | |
553 | if (m) { \ | |
554 | if (((ifq)->ifq_head = (m)->m_nextpkt) == 0) \ | |
555 | (ifq)->ifq_tail = 0; \ | |
556 | (m)->m_nextpkt = 0; \ | |
557 | (ifq)->ifq_len--; \ | |
558 | } \ | |
559 | } | |
560 | ||
1c79356b A |
561 | #define IF_ENQ_DROP(ifq, m) if_enq_drop(ifq, m) |
562 | ||
563 | #if defined(__GNUC__) && defined(MT_HEADER) | |
564 | static __inline int | |
91447636 | 565 | if_queue_drop(struct ifqueue *ifq, __unused struct mbuf *m) |
1c79356b A |
566 | { |
567 | IF_DROP(ifq); | |
568 | return 0; | |
569 | } | |
570 | ||
571 | static __inline int | |
572 | if_enq_drop(struct ifqueue *ifq, struct mbuf *m) | |
573 | { | |
574 | if (IF_QFULL(ifq) && | |
575 | !if_queue_drop(ifq, m)) | |
576 | return 0; | |
577 | IF_ENQUEUE(ifq, m); | |
578 | return 1; | |
579 | } | |
580 | #else | |
581 | ||
582 | #ifdef MT_HEADER | |
91447636 | 583 | int if_enq_drop(struct ifqueue *, struct mbuf *); |
b0d623f7 | 584 | #endif /* MT_HEADER */ |
1c79356b | 585 | |
b0d623f7 | 586 | #endif /* defined(__GNUC__) && defined(MT_HEADER) */ |
9bccf70c | 587 | |
91447636 | 588 | #endif /* KERNEL_PRIVATE */ |
9bccf70c | 589 | |
1c79356b | 590 | |
91447636 | 591 | #ifdef PRIVATE |
1c79356b A |
592 | /* |
593 | * The ifaddr structure contains information about one address | |
594 | * of an interface. They are maintained by the different address families, | |
595 | * are allocated and attached when an address is set, and are linked | |
596 | * together so all addresses for an interface can be located. | |
597 | */ | |
598 | struct ifaddr { | |
599 | struct sockaddr *ifa_addr; /* address of interface */ | |
600 | struct sockaddr *ifa_dstaddr; /* other end of p-to-p link */ | |
601 | #define ifa_broadaddr ifa_dstaddr /* broadcast address interface */ | |
602 | struct sockaddr *ifa_netmask; /* used to determine subnet */ | |
603 | struct ifnet *ifa_ifp; /* back-pointer to interface */ | |
604 | TAILQ_ENTRY(ifaddr) ifa_link; /* queue macro glue */ | |
b0d623f7 A |
605 | void (*ifa_rtrequest) /* check or clean routes (+ or -)'d */ |
606 | (int, struct rtentry *, struct sockaddr *); | |
607 | uint32_t ifa_flags; /* mostly rt_flags for cloning */ | |
608 | int32_t ifa_refcnt; /* ref count, use ifaref, ifafree */ | |
609 | int32_t ifa_metric; /* cost of going out this interface */ | |
610 | void (*ifa_free)(struct ifaddr *); /* callback fn for freeing */ | |
611 | void (*ifa_trace) /* callback fn for tracing refs */ | |
612 | (struct ifaddr *, int); | |
613 | uint32_t ifa_debug; /* debug flags */ | |
1c79356b | 614 | }; |
b0d623f7 A |
615 | |
616 | /* | |
617 | * Valid values for ifa_flags | |
618 | */ | |
91447636 A |
619 | #define IFA_ROUTE RTF_UP /* route installed (0x1) */ |
620 | #define IFA_CLONING RTF_CLONING /* (0x100) */ | |
b0d623f7 A |
621 | |
622 | /* | |
623 | * Valid values for ifa_debug | |
624 | */ | |
625 | #define IFD_ATTACHED 0x1 /* attached to an interface */ | |
626 | #define IFD_ALLOC 0x2 /* dynamically allocated */ | |
627 | #define IFD_DEBUG 0x4 /* has debugging info */ | |
91447636 A |
628 | |
629 | #endif /* PRIVATE */ | |
1c79356b | 630 | |
91447636 | 631 | #ifdef KERNEL_PRIVATE |
1c79356b A |
632 | /* |
633 | * The prefix structure contains information about one prefix | |
634 | * of an interface. They are maintained by the different address families, | |
635 | * are allocated and attached when an prefix or an address is set, | |
636 | * and are linked together so all prefixes for an interface can be located. | |
637 | */ | |
638 | struct ifprefix { | |
639 | struct sockaddr *ifpr_prefix; /* prefix of interface */ | |
640 | struct ifnet *ifpr_ifp; /* back-pointer to interface */ | |
9bccf70c | 641 | TAILQ_ENTRY(ifprefix) ifpr_list; /* queue macro glue */ |
1c79356b A |
642 | u_char ifpr_plen; /* prefix length in bits */ |
643 | u_char ifpr_type; /* protocol dependent prefix type */ | |
644 | }; | |
91447636 A |
645 | #endif /* KERNEL_PRIVATE */ |
646 | ||
647 | #ifdef PRIVATE | |
648 | typedef void (*ifma_protospec_free_func)(void* ifma_protospec); | |
1c79356b A |
649 | |
650 | /* | |
651 | * Multicast address structure. This is analogous to the ifaddr | |
652 | * structure except that it keeps track of multicast addresses. | |
653 | * Also, the reference count here is a count of requests for this | |
654 | * address, not a count of pointers to this structure. | |
655 | */ | |
656 | struct ifmultiaddr { | |
657 | LIST_ENTRY(ifmultiaddr) ifma_link; /* queue macro glue */ | |
658 | struct sockaddr *ifma_addr; /* address this membership is for */ | |
91447636 A |
659 | struct ifmultiaddr *ifma_ll; /* link-layer translation, if any */ |
660 | struct ifnet *ifma_ifp; /* back-pointer to interface */ | |
661 | u_int ifma_usecount; /* use count, protected by ifp's lock */ | |
662 | void *ifma_protospec; /* protocol-specific state, if any */ | |
663 | int32_t ifma_refcount; /* reference count, atomically protected */ | |
664 | ifma_protospec_free_func ifma_free; /* function called to free ifma_protospec */ | |
1c79356b | 665 | }; |
91447636 | 666 | #endif /* PRIVATE */ |
1c79356b | 667 | |
91447636 | 668 | #ifdef KERNEL_PRIVATE |
9bccf70c A |
669 | #define IFAREF(ifa) ifaref(ifa) |
670 | #define IFAFREE(ifa) ifafree(ifa) | |
1c79356b | 671 | |
91447636 A |
672 | /* |
673 | * To preserve kmem compatibility, we define | |
674 | * ifnet_head to ifnet. This should be temp. | |
675 | */ | |
676 | #define ifnet_head ifnet | |
677 | extern struct ifnethead ifnet_head; | |
1c79356b A |
678 | extern struct ifnet **ifindex2ifnet; |
679 | extern int ifqmaxlen; | |
2d21ac55 | 680 | extern ifnet_t lo_ifp; |
1c79356b A |
681 | extern int if_index; |
682 | extern struct ifaddr **ifnet_addrs; | |
91447636 A |
683 | |
684 | int if_addmulti(struct ifnet *, const struct sockaddr *, struct ifmultiaddr **); | |
685 | int if_allmulti(struct ifnet *, int); | |
686 | void if_attach(struct ifnet *); | |
687 | int if_delmultiaddr(struct ifmultiaddr *ifma, int locked); | |
688 | int if_delmulti(struct ifnet *, const struct sockaddr *); | |
689 | void if_down(struct ifnet *); | |
2d21ac55 | 690 | int if_down_all(void); |
91447636 A |
691 | void if_route(struct ifnet *, int flag, int fam); |
692 | void if_unroute(struct ifnet *, int flag, int fam); | |
693 | void if_up(struct ifnet *); | |
694 | void if_updown(struct ifnet *ifp, int up); | |
695 | /*void ifinit(void));*/ /* declared in systm.h for main( */ | |
696 | int ifioctl(struct socket *, u_long, caddr_t, struct proc *); | |
697 | int ifioctllocked(struct socket *, u_long, caddr_t, struct proc *); | |
698 | struct ifnet *ifunit(const char *); | |
699 | struct ifnet *if_withname(struct sockaddr *); | |
9bccf70c | 700 | |
b0d623f7 | 701 | int if_clone_attach(struct if_clone *); |
4a249263 | 702 | void if_clone_detach(struct if_clone *); |
1c79356b | 703 | |
91447636 A |
704 | void ifnet_lock_assert(struct ifnet *ifp, int what); |
705 | void ifnet_lock_shared(struct ifnet *ifp); | |
706 | void ifnet_lock_exclusive(struct ifnet *ifp); | |
707 | void ifnet_lock_done(struct ifnet *ifp); | |
708 | ||
709 | void ifnet_head_lock_shared(void); | |
710 | void ifnet_head_lock_exclusive(void); | |
711 | void ifnet_head_done(void); | |
712 | ||
713 | void if_attach_ifa(struct ifnet * ifp, struct ifaddr *ifa); | |
714 | void if_detach_ifa(struct ifnet * ifp, struct ifaddr *ifa); | |
715 | ||
716 | void ifma_reference(struct ifmultiaddr *ifma); | |
717 | void ifma_release(struct ifmultiaddr *ifma); | |
718 | ||
719 | struct ifaddr *ifa_ifwithaddr(const struct sockaddr *); | |
c910b4d9 | 720 | struct ifaddr *ifa_ifwithaddr_scoped(const struct sockaddr *, unsigned int); |
91447636 A |
721 | struct ifaddr *ifa_ifwithdstaddr(const struct sockaddr *); |
722 | struct ifaddr *ifa_ifwithnet(const struct sockaddr *); | |
c910b4d9 | 723 | struct ifaddr *ifa_ifwithnet_scoped(const struct sockaddr *, unsigned int); |
91447636 | 724 | struct ifaddr *ifa_ifwithroute(int, const struct sockaddr *, const struct sockaddr *); |
2d21ac55 | 725 | struct ifaddr *ifa_ifwithroute_locked(int, const struct sockaddr *, const struct sockaddr *); |
c910b4d9 A |
726 | struct ifaddr *ifa_ifwithroute_scoped_locked(int, const struct sockaddr *, |
727 | const struct sockaddr *, unsigned int); | |
91447636 | 728 | struct ifaddr *ifaof_ifpforaddr(const struct sockaddr *, struct ifnet *); |
2d21ac55 | 729 | struct ifaddr *ifa_ifpgetprimary(struct ifnet *, int); |
91447636 A |
730 | void ifafree(struct ifaddr *); |
731 | void ifaref(struct ifaddr *); | |
732 | ||
733 | struct ifmultiaddr *ifmaof_ifpforaddr(const struct sockaddr *, struct ifnet *); | |
734 | ||
b0d623f7 A |
735 | extern struct in_ifaddr *ifa_foraddr(unsigned int); |
736 | extern struct in_ifaddr *ifa_foraddr_scoped(unsigned int, unsigned int); | |
2d21ac55 | 737 | |
91447636 | 738 | #ifdef BSD_KERNEL_PRIVATE |
2d21ac55 A |
739 | enum { |
740 | kIfNetUseCount_MayBeZero = 0, | |
741 | kIfNetUseCount_MustNotBeZero = 1 | |
742 | }; | |
743 | ||
744 | int ifp_use(struct ifnet *ifp, int handle_zero); | |
745 | int ifp_unuse(struct ifnet *ifp); | |
746 | void ifp_use_reached_zero(struct ifnet *ifp); | |
747 | ||
748 | void if_data_internal_to_if_data(struct ifnet *ifp, const struct if_data_internal *if_data_int, | |
749 | struct if_data *if_data); | |
750 | void if_data_internal_to_if_data64(struct ifnet *ifp, const struct if_data_internal *if_data_int, | |
91447636 A |
751 | struct if_data64 *if_data64); |
752 | #endif /* BSD_KERNEL_PRIVATE */ | |
753 | #endif /* KERNEL_PRIVATE */ | |
1c79356b | 754 | #endif /* !_NET_IF_VAR_H_ */ |