]>
Commit | Line | Data |
---|---|---|
1c79356b | 1 | /* |
8ad349bb | 2 | * Copyright (c) 2006 Apple Computer, Inc. All Rights Reserved. |
1c79356b | 3 | * |
8ad349bb | 4 | * @APPLE_LICENSE_OSREFERENCE_HEADER_START@ |
1c79356b | 5 | * |
8ad349bb 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 | |
10 | * License may not be used to create, or enable the creation or | |
11 | * redistribution of, unlawful or unlicensed copies of an Apple operating | |
12 | * system, or to circumvent, violate, or enable the circumvention or | |
13 | * violation of, any terms of an Apple operating system software license | |
14 | * agreement. | |
15 | * | |
16 | * Please obtain a copy of the License at | |
17 | * http://www.opensource.apple.com/apsl/ and read it before using this | |
18 | * file. | |
19 | * | |
20 | * The Original Code and all software distributed under the License are | |
21 | * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER | |
22 | * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, | |
23 | * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, | |
24 | * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. | |
25 | * Please see the License for the specific language governing rights and | |
26 | * limitations under the License. | |
27 | * | |
28 | * @APPLE_LICENSE_OSREFERENCE_HEADER_END@ | |
1c79356b A |
29 | */ |
30 | /* | |
31 | * Copyright (c) 1982, 1986, 1989, 1993 | |
32 | * The Regents of the University of California. All rights reserved. | |
33 | * | |
34 | * Redistribution and use in source and binary forms, with or without | |
35 | * modification, are permitted provided that the following conditions | |
36 | * are met: | |
37 | * 1. Redistributions of source code must retain the above copyright | |
38 | * notice, this list of conditions and the following disclaimer. | |
39 | * 2. Redistributions in binary form must reproduce the above copyright | |
40 | * notice, this list of conditions and the following disclaimer in the | |
41 | * documentation and/or other materials provided with the distribution. | |
42 | * 3. All advertising materials mentioning features or use of this software | |
43 | * must display the following acknowledgement: | |
44 | * This product includes software developed by the University of | |
45 | * California, Berkeley and its contributors. | |
46 | * 4. Neither the name of the University nor the names of its contributors | |
47 | * may be used to endorse or promote products derived from this software | |
48 | * without specific prior written permission. | |
49 | * | |
50 | * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND | |
51 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | |
52 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | |
53 | * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE | |
54 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | |
55 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | |
56 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | |
57 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | |
58 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | |
59 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | |
60 | * SUCH DAMAGE. | |
61 | * | |
62 | * From: @(#)if.h 8.1 (Berkeley) 6/10/93 | |
9bccf70c | 63 | * $FreeBSD: src/sys/net/if_var.h,v 1.18.2.7 2001/07/24 19:10:18 brooks Exp $ |
1c79356b A |
64 | */ |
65 | ||
66 | #ifndef _NET_IF_VAR_H_ | |
67 | #define _NET_IF_VAR_H_ | |
91447636 | 68 | |
9bccf70c | 69 | #include <sys/appleapiopts.h> |
91447636 A |
70 | #include <sys/types.h> |
71 | #include <sys/time.h> | |
72 | #include <sys/queue.h> /* get TAILQ macros */ | |
73 | #ifdef KERNEL_PRIVATE | |
74 | #include <kern/locks.h> | |
75 | #endif /* KERNEL_PRIVATE */ | |
76 | ||
77 | #ifdef KERNEL | |
78 | #include <net/kpi_interface.h> | |
79 | #endif KERNEL | |
1c79356b | 80 | |
9bccf70c | 81 | #ifdef __APPLE__ |
1c79356b A |
82 | #define APPLE_IF_FAM_LOOPBACK 1 |
83 | #define APPLE_IF_FAM_ETHERNET 2 | |
84 | #define APPLE_IF_FAM_SLIP 3 | |
85 | #define APPLE_IF_FAM_TUN 4 | |
86 | #define APPLE_IF_FAM_VLAN 5 | |
87 | #define APPLE_IF_FAM_PPP 6 | |
88 | #define APPLE_IF_FAM_PVC 7 | |
89 | #define APPLE_IF_FAM_DISC 8 | |
90 | #define APPLE_IF_FAM_MDECAP 9 | |
91 | #define APPLE_IF_FAM_GIF 10 | |
92 | #define APPLE_IF_FAM_FAITH 11 | |
55e303ae A |
93 | #define APPLE_IF_FAM_STF 12 |
94 | #define APPLE_IF_FAM_FIREWIRE 13 | |
91447636 | 95 | #define APPLE_IF_FAM_BOND 14 |
8ad349bb | 96 | #endif __APPLE__ |
91447636 A |
97 | |
98 | /* | |
99 | * 72 was chosen below because it is the size of a TCP/IP | |
100 | * header (40) + the minimum mss (32). | |
101 | */ | |
102 | #define IF_MINMTU 72 | |
103 | #define IF_MAXMTU 65535 | |
1c79356b A |
104 | |
105 | /* | |
106 | * Structures defining a network interface, providing a packet | |
107 | * transport mechanism (ala level 0 of the PUP protocols). | |
108 | * | |
109 | * Each interface accepts output datagrams of a specified maximum | |
110 | * length, and provides higher level routines with input datagrams | |
111 | * received from its medium. | |
112 | * | |
113 | * Output occurs when the routine if_output is called, with three parameters: | |
114 | * (*ifp->if_output)(ifp, m, dst, rt) | |
115 | * Here m is the mbuf chain to be sent and dst is the destination address. | |
116 | * The output routine encapsulates the supplied datagram if necessary, | |
117 | * and then transmits it on its medium. | |
118 | * | |
119 | * On input, each interface unwraps the data received by it, and either | |
120 | * places it on the input queue of a internetwork datagram routine | |
121 | * and posts the associated software interrupt, or passes the datagram to a raw | |
122 | * packet input routine. | |
123 | * | |
124 | * Routines exist for locating interfaces by their addresses | |
125 | * or for locating a interface on a certain network, as well as more general | |
126 | * routing and gateway routines maintaining information used to locate | |
127 | * interfaces. These routines live in the files if.c and route.c | |
128 | */ | |
129 | ||
1c79356b A |
130 | #define IFNAMSIZ 16 |
131 | ||
1c79356b A |
132 | /* This belongs up in socket.h or socketvar.h, depending on how far the |
133 | * event bubbles up. | |
134 | */ | |
135 | ||
136 | struct net_event_data { | |
91447636 A |
137 | unsigned long if_family; |
138 | unsigned long if_unit; | |
1c79356b A |
139 | char if_name[IFNAMSIZ]; |
140 | }; | |
1c79356b | 141 | |
91447636 A |
142 | /* |
143 | * Structure describing information about an interface | |
144 | * which may be of interest to management entities. | |
145 | */ | |
146 | struct if_data { | |
147 | /* generic interface information */ | |
148 | unsigned char ifi_type; /* ethernet, tokenring, etc */ | |
9bccf70c | 149 | #ifdef __APPLE__ |
91447636 A |
150 | unsigned char ifi_typelen; /* Length of frame type id */ |
151 | #endif | |
152 | unsigned char ifi_physical; /* e.g., AUI, Thinnet, 10base-T, etc */ | |
153 | unsigned char ifi_addrlen; /* media address length */ | |
154 | unsigned char ifi_hdrlen; /* media header length */ | |
155 | unsigned char ifi_recvquota; /* polling quota for receive intrs */ | |
156 | unsigned char ifi_xmitquota; /* polling quota for xmit intrs */ | |
157 | unsigned char ifi_unused1; /* for future use */ | |
158 | unsigned long ifi_mtu; /* maximum transmission unit */ | |
159 | unsigned long ifi_metric; /* routing metric (external only) */ | |
160 | unsigned long ifi_baudrate; /* linespeed */ | |
161 | /* volatile statistics */ | |
162 | unsigned long ifi_ipackets; /* packets received on interface */ | |
163 | unsigned long ifi_ierrors; /* input errors on interface */ | |
164 | unsigned long ifi_opackets; /* packets sent on interface */ | |
165 | unsigned long ifi_oerrors; /* output errors on interface */ | |
166 | unsigned long ifi_collisions; /* collisions on csma interfaces */ | |
167 | unsigned long ifi_ibytes; /* total number of octets received */ | |
168 | unsigned long ifi_obytes; /* total number of octets sent */ | |
169 | unsigned long ifi_imcasts; /* packets received via multicast */ | |
170 | unsigned long ifi_omcasts; /* packets sent via multicast */ | |
171 | unsigned long ifi_iqdrops; /* dropped on input, this interface */ | |
172 | unsigned long ifi_noproto; /* destined for unsupported protocol */ | |
173 | unsigned long ifi_recvtiming; /* usec spent receiving when timing */ | |
174 | unsigned long ifi_xmittiming; /* usec spent xmitting when timing */ | |
175 | struct timeval ifi_lastchange; /* time of last administrative change */ | |
176 | unsigned long ifi_unused2; /* used to be the default_proto */ | |
177 | unsigned long ifi_hwassist; /* HW offload capabilities */ | |
178 | unsigned long ifi_reserved1; /* for future use */ | |
179 | unsigned long ifi_reserved2; /* for future use */ | |
180 | }; | |
4a249263 | 181 | |
1c79356b A |
182 | /* |
183 | * Structure describing information about an interface | |
184 | * which may be of interest to management entities. | |
185 | */ | |
91447636 | 186 | struct if_data64 { |
1c79356b A |
187 | /* generic interface information */ |
188 | u_char ifi_type; /* ethernet, tokenring, etc */ | |
9bccf70c A |
189 | #ifdef __APPLE__ |
190 | u_char ifi_typelen; /* Length of frame type id */ | |
191 | #endif | |
91447636 A |
192 | u_char ifi_physical; /* e.g., AUI, Thinnet, 10base-T, etc */ |
193 | u_char ifi_addrlen; /* media address length */ | |
194 | u_char ifi_hdrlen; /* media header length */ | |
195 | u_char ifi_recvquota; /* polling quota for receive intrs */ | |
196 | u_char ifi_xmitquota; /* polling quota for xmit intrs */ | |
197 | u_char ifi_unused1; /* for future use */ | |
198 | u_long ifi_mtu; /* maximum transmission unit */ | |
199 | u_long ifi_metric; /* routing metric (external only) */ | |
200 | u_int64_t ifi_baudrate; /* linespeed */ | |
201 | /* volatile statistics */ | |
202 | u_int64_t ifi_ipackets; /* packets received on interface */ | |
203 | u_int64_t ifi_ierrors; /* input errors on interface */ | |
204 | u_int64_t ifi_opackets; /* packets sent on interface */ | |
205 | u_int64_t ifi_oerrors; /* output errors on interface */ | |
206 | u_int64_t ifi_collisions; /* collisions on csma interfaces */ | |
207 | u_int64_t ifi_ibytes; /* total number of octets received */ | |
208 | u_int64_t ifi_obytes; /* total number of octets sent */ | |
209 | u_int64_t ifi_imcasts; /* packets received via multicast */ | |
210 | u_int64_t ifi_omcasts; /* packets sent via multicast */ | |
211 | u_int64_t ifi_iqdrops; /* dropped on input, this interface */ | |
212 | u_int64_t ifi_noproto; /* destined for unsupported protocol */ | |
213 | u_long ifi_recvtiming; /* usec spent receiving when timing */ | |
214 | u_long ifi_xmittiming; /* usec spent xmitting when timing */ | |
215 | struct timeval ifi_lastchange; /* time of last administrative change */ | |
216 | }; | |
217 | ||
218 | #ifdef PRIVATE | |
219 | /* | |
220 | * Internal storage of if_data. This is bound to change. Various places in the | |
221 | * stack will translate this data structure in to the externally visible | |
222 | * if_data structure above. | |
223 | */ | |
224 | struct if_data_internal { | |
225 | /* generic interface information */ | |
226 | u_char ifi_type; /* ethernet, tokenring, etc */ | |
227 | u_char ifi_typelen; /* Length of frame type id */ | |
228 | u_char ifi_physical; /* e.g., AUI, Thinnet, 10base-T, etc */ | |
229 | u_char ifi_addrlen; /* media address length */ | |
1c79356b | 230 | u_char ifi_hdrlen; /* media header length */ |
91447636 A |
231 | u_char ifi_recvquota; /* polling quota for receive intrs */ |
232 | u_char ifi_xmitquota; /* polling quota for xmit intrs */ | |
233 | u_char ifi_unused1; /* for future use */ | |
1c79356b A |
234 | u_long ifi_mtu; /* maximum transmission unit */ |
235 | u_long ifi_metric; /* routing metric (external only) */ | |
91447636 | 236 | u_long ifi_baudrate; /* linespeed */ |
1c79356b | 237 | /* volatile statistics */ |
91447636 A |
238 | u_int64_t ifi_ipackets; /* packets received on interface */ |
239 | u_int64_t ifi_ierrors; /* input errors on interface */ | |
240 | u_int64_t ifi_opackets; /* packets sent on interface */ | |
241 | u_int64_t ifi_oerrors; /* output errors on interface */ | |
242 | u_int64_t ifi_collisions; /* collisions on csma interfaces */ | |
243 | u_int64_t ifi_ibytes; /* total number of octets received */ | |
244 | u_int64_t ifi_obytes; /* total number of octets sent */ | |
245 | u_int64_t ifi_imcasts; /* packets received via multicast */ | |
246 | u_int64_t ifi_omcasts; /* packets sent via multicast */ | |
247 | u_int64_t ifi_iqdrops; /* dropped on input, this interface */ | |
248 | u_int64_t ifi_noproto; /* destined for unsupported protocol */ | |
1c79356b A |
249 | u_long ifi_recvtiming; /* usec spent receiving when timing */ |
250 | u_long ifi_xmittiming; /* usec spent xmitting when timing */ | |
91447636 | 251 | #define IF_LASTCHANGEUPTIME 1 /* lastchange: 1-uptime 0-calendar time */ |
1c79356b | 252 | struct timeval ifi_lastchange; /* time of last administrative change */ |
9bccf70c | 253 | u_long ifi_hwassist; /* HW offload capabilities */ |
1c79356b | 254 | }; |
91447636 A |
255 | |
256 | #define if_mtu if_data.ifi_mtu | |
257 | #define if_type if_data.ifi_type | |
258 | #define if_typelen if_data.ifi_typelen | |
259 | #define if_physical if_data.ifi_physical | |
260 | #define if_addrlen if_data.ifi_addrlen | |
261 | #define if_hdrlen if_data.ifi_hdrlen | |
262 | #define if_metric if_data.ifi_metric | |
263 | #define if_baudrate if_data.ifi_baudrate | |
264 | #define if_hwassist if_data.ifi_hwassist | |
265 | #define if_ipackets if_data.ifi_ipackets | |
266 | #define if_ierrors if_data.ifi_ierrors | |
267 | #define if_opackets if_data.ifi_opackets | |
268 | #define if_oerrors if_data.ifi_oerrors | |
269 | #define if_collisions if_data.ifi_collisions | |
270 | #define if_ibytes if_data.ifi_ibytes | |
271 | #define if_obytes if_data.ifi_obytes | |
272 | #define if_imcasts if_data.ifi_imcasts | |
273 | #define if_omcasts if_data.ifi_omcasts | |
274 | #define if_iqdrops if_data.ifi_iqdrops | |
275 | #define if_noproto if_data.ifi_noproto | |
276 | #define if_lastchange if_data.ifi_lastchange | |
277 | #define if_recvquota if_data.ifi_recvquota | |
278 | #define if_xmitquota if_data.ifi_xmitquota | |
279 | #define if_iflags if_data.ifi_iflags | |
280 | ||
281 | struct mbuf; | |
282 | struct ifaddr; | |
283 | TAILQ_HEAD(ifnethead, ifnet); /* we use TAILQs so that the order of */ | |
284 | TAILQ_HEAD(ifaddrhead, ifaddr); /* instantiation is preserved in the list */ | |
285 | TAILQ_HEAD(ifprefixhead, ifprefix); | |
286 | LIST_HEAD(ifmultihead, ifmultiaddr); | |
287 | struct tqdummy; | |
288 | TAILQ_HEAD(tailq_head, tqdummy); | |
289 | ||
290 | /* | |
291 | * Forward structure declarations for function prototypes [sic]. | |
292 | */ | |
293 | struct proc; | |
294 | struct rtentry; | |
295 | struct socket; | |
296 | struct ether_header; | |
297 | struct sockaddr_dl; | |
298 | struct ifnet_filter; | |
299 | ||
300 | TAILQ_HEAD(ifnet_filter_head, ifnet_filter); | |
301 | TAILQ_HEAD(ddesc_head_name, dlil_demux_desc); | |
302 | ||
303 | /* bottom 16 bits reserved for hardware checksum */ | |
304 | #define IF_HWASSIST_CSUM_IP 0x0001 /* will csum IP */ | |
305 | #define IF_HWASSIST_CSUM_TCP 0x0002 /* will csum TCP */ | |
306 | #define IF_HWASSIST_CSUM_UDP 0x0004 /* will csum UDP */ | |
307 | #define IF_HWASSIST_CSUM_IP_FRAGS 0x0008 /* will csum IP fragments */ | |
308 | #define IF_HWASSIST_CSUM_FRAGMENT 0x0010 /* will do IP fragmentation */ | |
309 | #define IF_HWASSIST_CSUM_TCP_SUM16 0x1000 /* simple TCP Sum16 computation */ | |
310 | #define IF_HWASSIST_CSUM_MASK 0xffff | |
311 | #define IF_HWASSIST_CSUM_FLAGS(hwassist) ((hwassist) & IF_HWASSIST_CSUM_MASK) | |
312 | ||
313 | /* VLAN support */ | |
314 | #define IF_HWASSIST_VLAN_TAGGING 0x10000 /* supports VLAN tagging */ | |
315 | #define IF_HWASSIST_VLAN_MTU 0x20000 /* supports VLAN MTU-sized packet (for software VLAN) */ | |
316 | ||
317 | #define IFNET_RW_LOCK 1 | |
1c79356b A |
318 | |
319 | /* | |
320 | * Structure defining a queue for a network interface. | |
321 | */ | |
322 | struct ifqueue { | |
91447636 A |
323 | void *ifq_head; |
324 | void *ifq_tail; | |
1c79356b A |
325 | int ifq_len; |
326 | int ifq_maxlen; | |
327 | int ifq_drops; | |
328 | }; | |
329 | ||
91447636 A |
330 | struct ddesc_head_str; |
331 | struct proto_hash_entry; | |
332 | struct kev_msg; | |
333 | ||
1c79356b A |
334 | /* |
335 | * Structure defining a network interface. | |
336 | * | |
337 | * (Would like to call this struct ``if'', but C isn't PL/1.) | |
338 | */ | |
339 | struct ifnet { | |
340 | void *if_softc; /* pointer to driver state */ | |
91447636 | 341 | const char *if_name; /* name, e.g. ``en'' or ``lo'' */ |
1c79356b A |
342 | TAILQ_ENTRY(ifnet) if_link; /* all struct ifnets are chained */ |
343 | struct ifaddrhead if_addrhead; /* linked list of addresses per if */ | |
91447636 A |
344 | u_long if_refcnt; |
345 | #ifdef __KPI_INTERFACE__ | |
346 | ifnet_check_multi if_check_multi; | |
347 | #else | |
348 | void* if_check_multi; | |
349 | #endif __KPI_INTERFACE__ | |
350 | int if_pcount; /* number of promiscuous listeners */ | |
1c79356b A |
351 | struct bpf_if *if_bpf; /* packet filter structure */ |
352 | u_short if_index; /* numeric abbreviation for this if */ | |
353 | short if_unit; /* sub-unit for lower level driver */ | |
354 | short if_timer; /* time 'til if_watchdog called */ | |
355 | short if_flags; /* up/down, broadcast, etc. */ | |
356 | int if_ipending; /* interrupts pending */ | |
357 | void *if_linkmib; /* link-type-specific MIB data */ | |
358 | size_t if_linkmiblen; /* length of above data */ | |
91447636 | 359 | struct if_data_internal if_data; |
1c79356b A |
360 | |
361 | /* New with DLIL */ | |
91447636 A |
362 | #ifdef BSD_KERNEL_PRIVATE |
363 | int if_usecnt; | |
364 | #else | |
1c79356b | 365 | int refcnt; |
91447636 | 366 | #endif |
1c79356b | 367 | int offercnt; |
91447636 A |
368 | #ifdef __KPI_INTERFACE__ |
369 | ifnet_output_func if_output; | |
370 | ifnet_ioctl_func if_ioctl; | |
371 | ifnet_set_bpf_tap if_set_bpf_tap; | |
372 | ifnet_detached_func if_free; | |
373 | ifnet_demux_func if_demux; | |
374 | ifnet_event_func if_event; | |
375 | ifnet_framer_func if_framer; | |
376 | ifnet_family_t if_family; /* ulong assigned by Apple */ | |
377 | #else | |
378 | void* if_output; | |
379 | void* if_ioctl; | |
380 | void* if_set_bpf_tap; | |
381 | void* if_free; | |
382 | void* if_demux; | |
383 | void* if_event; | |
384 | void* if_framer; | |
385 | u_long if_family; /* ulong assigned by Apple */ | |
386 | #endif | |
1c79356b | 387 | |
91447636 | 388 | struct ifnet_filter_head if_flt_head; |
1c79356b A |
389 | |
390 | /* End DLIL specific */ | |
391 | ||
91447636 | 392 | u_long if_delayed_detach; /* need to perform delayed detach */ |
9bccf70c | 393 | void *if_private; /* private to interface */ |
1c79356b | 394 | long if_eflags; /* autoaddr, autoaddr done, etc. */ |
1c79356b A |
395 | |
396 | struct ifmultihead if_multiaddrs; /* multicast addresses configured */ | |
397 | int if_amcount; /* number of all-multicast requests */ | |
398 | /* procedure handles */ | |
91447636 A |
399 | #ifdef __KPI_INTERFACE__ |
400 | union { | |
401 | int (*original)(struct ifnet *ifp, u_long protocol_family, | |
402 | struct ddesc_head_str *demux_desc_head); | |
403 | ifnet_add_proto_func kpi; | |
404 | } if_add_proto_u; | |
405 | ifnet_del_proto_func if_del_proto; | |
406 | #else __KPI_INTERFACE__ | |
407 | void* if_add_proto; | |
408 | void* if_del_proto; | |
409 | #endif __KPI_INTERFACE__ | |
410 | struct proto_hash_entry *if_proto_hash; | |
411 | void *if_kpi_storage; | |
412 | ||
413 | void *unused_was_init; | |
414 | void *unused_was_resolvemulti; | |
415 | ||
416 | struct ifqueue if_snd; | |
417 | u_long unused_2[1]; | |
9bccf70c | 418 | #ifdef __APPLE__ |
91447636 | 419 | u_long family_cookie; |
9bccf70c | 420 | struct ifprefixhead if_prefixhead; /* list of prefixes per if */ |
91447636 A |
421 | |
422 | #ifdef _KERN_LOCKS_H_ | |
423 | #if IFNET_RW_LOCK | |
424 | lck_rw_t *if_lock; /* Lock to protect this interface */ | |
425 | #else | |
426 | lck_mtx_t *if_lock; /* Lock to protect this interface */ | |
427 | #endif | |
428 | #else | |
429 | void *if_lock; | |
430 | #endif | |
431 | ||
9bccf70c A |
432 | #else |
433 | struct ifprefixhead if_prefixhead; /* list of prefixes per if */ | |
434 | #endif /* __APPLE__ */ | |
91447636 A |
435 | struct { |
436 | u_long length; | |
437 | union { | |
438 | u_char buffer[8]; | |
439 | u_char *ptr; | |
440 | } u; | |
441 | } if_broadcast; | |
1c79356b | 442 | }; |
1c79356b | 443 | |
91447636 | 444 | #define if_add_proto if_add_proto_u.original |
1c79356b | 445 | |
9bccf70c A |
446 | #ifndef __APPLE__ |
447 | /* for compatibility with other BSDs */ | |
448 | #define if_addrlist if_addrhead | |
449 | #define if_list if_link | |
91447636 A |
450 | #endif !__APPLE__ |
451 | ||
452 | ||
453 | #endif /* PRIVATE */ | |
454 | ||
4a249263 A |
455 | #ifdef KERNEL_PRIVATE |
456 | /* | |
457 | * Structure describing a `cloning' interface. | |
458 | */ | |
459 | struct if_clone { | |
460 | LIST_ENTRY(if_clone) ifc_list; /* on list of cloners */ | |
91447636 | 461 | const char *ifc_name; /* name of device, e.g. `vlan' */ |
4a249263 A |
462 | size_t ifc_namelen; /* length of name */ |
463 | int ifc_minifs; /* minimum number of interfaces */ | |
464 | int ifc_maxunit; /* maximum unit number */ | |
465 | unsigned char *ifc_units; /* bitmap to handle units */ | |
466 | int ifc_bmlen; /* bitmap length */ | |
467 | ||
468 | int (*ifc_create)(struct if_clone *, int); | |
469 | void (*ifc_destroy)(struct ifnet *); | |
470 | }; | |
471 | ||
472 | #define IF_CLONE_INITIALIZER(name, create, destroy, minifs, maxunit) \ | |
91447636 | 473 | { { 0, 0 }, name, sizeof(name) - 1, minifs, maxunit, NULL, 0, create, destroy } |
9bccf70c | 474 | |
1c79356b A |
475 | /* |
476 | * Bit values in if_ipending | |
477 | */ | |
478 | #define IFI_RECV 1 /* I want to receive */ | |
479 | #define IFI_XMIT 2 /* I want to transmit */ | |
480 | ||
481 | /* | |
482 | * Output queues (ifp->if_snd) and slow device input queues (*ifp->if_slowq) | |
483 | * are queues of messages stored on ifqueue structures | |
484 | * (defined above). Entries are added to and deleted from these structures | |
485 | * by these macros, which should be called with ipl raised to splimp(). | |
486 | */ | |
487 | #define IF_QFULL(ifq) ((ifq)->ifq_len >= (ifq)->ifq_maxlen) | |
488 | #define IF_DROP(ifq) ((ifq)->ifq_drops++) | |
489 | #define IF_ENQUEUE(ifq, m) { \ | |
490 | (m)->m_nextpkt = 0; \ | |
491 | if ((ifq)->ifq_tail == 0) \ | |
492 | (ifq)->ifq_head = m; \ | |
493 | else \ | |
91447636 | 494 | ((struct mbuf*)(ifq)->ifq_tail)->m_nextpkt = m; \ |
1c79356b A |
495 | (ifq)->ifq_tail = m; \ |
496 | (ifq)->ifq_len++; \ | |
497 | } | |
498 | #define IF_PREPEND(ifq, m) { \ | |
499 | (m)->m_nextpkt = (ifq)->ifq_head; \ | |
500 | if ((ifq)->ifq_tail == 0) \ | |
501 | (ifq)->ifq_tail = (m); \ | |
502 | (ifq)->ifq_head = (m); \ | |
503 | (ifq)->ifq_len++; \ | |
504 | } | |
505 | #define IF_DEQUEUE(ifq, m) { \ | |
506 | (m) = (ifq)->ifq_head; \ | |
507 | if (m) { \ | |
508 | if (((ifq)->ifq_head = (m)->m_nextpkt) == 0) \ | |
509 | (ifq)->ifq_tail = 0; \ | |
510 | (m)->m_nextpkt = 0; \ | |
511 | (ifq)->ifq_len--; \ | |
512 | } \ | |
513 | } | |
514 | ||
1c79356b A |
515 | #define IF_ENQ_DROP(ifq, m) if_enq_drop(ifq, m) |
516 | ||
517 | #if defined(__GNUC__) && defined(MT_HEADER) | |
518 | static __inline int | |
91447636 | 519 | if_queue_drop(struct ifqueue *ifq, __unused struct mbuf *m) |
1c79356b A |
520 | { |
521 | IF_DROP(ifq); | |
522 | return 0; | |
523 | } | |
524 | ||
525 | static __inline int | |
526 | if_enq_drop(struct ifqueue *ifq, struct mbuf *m) | |
527 | { | |
528 | if (IF_QFULL(ifq) && | |
529 | !if_queue_drop(ifq, m)) | |
530 | return 0; | |
531 | IF_ENQUEUE(ifq, m); | |
532 | return 1; | |
533 | } | |
534 | #else | |
535 | ||
536 | #ifdef MT_HEADER | |
91447636 A |
537 | int if_enq_drop(struct ifqueue *, struct mbuf *); |
538 | #endif MT_HEADER | |
1c79356b | 539 | |
91447636 | 540 | #endif defined(__GNUC__) && defined(MT_HEADER) |
9bccf70c | 541 | |
91447636 | 542 | #endif /* KERNEL_PRIVATE */ |
9bccf70c | 543 | |
1c79356b | 544 | |
91447636 | 545 | #ifdef PRIVATE |
1c79356b A |
546 | /* |
547 | * The ifaddr structure contains information about one address | |
548 | * of an interface. They are maintained by the different address families, | |
549 | * are allocated and attached when an address is set, and are linked | |
550 | * together so all addresses for an interface can be located. | |
551 | */ | |
552 | struct ifaddr { | |
553 | struct sockaddr *ifa_addr; /* address of interface */ | |
554 | struct sockaddr *ifa_dstaddr; /* other end of p-to-p link */ | |
555 | #define ifa_broadaddr ifa_dstaddr /* broadcast address interface */ | |
556 | struct sockaddr *ifa_netmask; /* used to determine subnet */ | |
557 | struct ifnet *ifa_ifp; /* back-pointer to interface */ | |
558 | TAILQ_ENTRY(ifaddr) ifa_link; /* queue macro glue */ | |
559 | void (*ifa_rtrequest) /* check or clean routes (+ or -)'d */ | |
91447636 | 560 | (int, struct rtentry *, struct sockaddr *); |
1c79356b | 561 | u_short ifa_flags; /* mostly rt_flags for cloning */ |
91447636 | 562 | int ifa_refcnt;/* 32bit ref count, use ifaref, ifafree */ |
1c79356b A |
563 | int ifa_metric; /* cost of going out this interface */ |
564 | #ifdef notdef | |
565 | struct rtentry *ifa_rt; /* XXXX for ROUTETOIF ????? */ | |
566 | #endif | |
1c79356b | 567 | int (*ifa_claim_addr) /* check if an addr goes to this if */ |
91447636 A |
568 | (struct ifaddr *, const struct sockaddr *); |
569 | u_long ifa_debug; /* debug flags */ | |
1c79356b | 570 | }; |
91447636 A |
571 | #define IFA_ROUTE RTF_UP /* route installed (0x1) */ |
572 | #define IFA_CLONING RTF_CLONING /* (0x100) */ | |
573 | #define IFA_ATTACHED 0x1 /* ifa_debug: IFA is attached to an interface */ | |
574 | ||
575 | #endif /* PRIVATE */ | |
1c79356b | 576 | |
91447636 | 577 | #ifdef KERNEL_PRIVATE |
1c79356b A |
578 | /* |
579 | * The prefix structure contains information about one prefix | |
580 | * of an interface. They are maintained by the different address families, | |
581 | * are allocated and attached when an prefix or an address is set, | |
582 | * and are linked together so all prefixes for an interface can be located. | |
583 | */ | |
584 | struct ifprefix { | |
585 | struct sockaddr *ifpr_prefix; /* prefix of interface */ | |
586 | struct ifnet *ifpr_ifp; /* back-pointer to interface */ | |
9bccf70c | 587 | TAILQ_ENTRY(ifprefix) ifpr_list; /* queue macro glue */ |
1c79356b A |
588 | u_char ifpr_plen; /* prefix length in bits */ |
589 | u_char ifpr_type; /* protocol dependent prefix type */ | |
590 | }; | |
91447636 A |
591 | #endif /* KERNEL_PRIVATE */ |
592 | ||
593 | #ifdef PRIVATE | |
594 | typedef void (*ifma_protospec_free_func)(void* ifma_protospec); | |
1c79356b A |
595 | |
596 | /* | |
597 | * Multicast address structure. This is analogous to the ifaddr | |
598 | * structure except that it keeps track of multicast addresses. | |
599 | * Also, the reference count here is a count of requests for this | |
600 | * address, not a count of pointers to this structure. | |
601 | */ | |
602 | struct ifmultiaddr { | |
603 | LIST_ENTRY(ifmultiaddr) ifma_link; /* queue macro glue */ | |
604 | struct sockaddr *ifma_addr; /* address this membership is for */ | |
91447636 A |
605 | struct ifmultiaddr *ifma_ll; /* link-layer translation, if any */ |
606 | struct ifnet *ifma_ifp; /* back-pointer to interface */ | |
607 | u_int ifma_usecount; /* use count, protected by ifp's lock */ | |
608 | void *ifma_protospec; /* protocol-specific state, if any */ | |
609 | int32_t ifma_refcount; /* reference count, atomically protected */ | |
610 | ifma_protospec_free_func ifma_free; /* function called to free ifma_protospec */ | |
1c79356b | 611 | }; |
91447636 | 612 | #endif /* PRIVATE */ |
1c79356b | 613 | |
91447636 | 614 | #ifdef KERNEL_PRIVATE |
9bccf70c A |
615 | #define IFAREF(ifa) ifaref(ifa) |
616 | #define IFAFREE(ifa) ifafree(ifa) | |
1c79356b | 617 | |
91447636 A |
618 | /* |
619 | * To preserve kmem compatibility, we define | |
620 | * ifnet_head to ifnet. This should be temp. | |
621 | */ | |
622 | #define ifnet_head ifnet | |
623 | extern struct ifnethead ifnet_head; | |
1c79356b A |
624 | extern struct ifnet **ifindex2ifnet; |
625 | extern int ifqmaxlen; | |
626 | extern struct ifnet loif[]; | |
627 | extern int if_index; | |
628 | extern struct ifaddr **ifnet_addrs; | |
91447636 A |
629 | extern struct ifnet *lo_ifp; |
630 | ||
631 | int if_addmulti(struct ifnet *, const struct sockaddr *, struct ifmultiaddr **); | |
632 | int if_allmulti(struct ifnet *, int); | |
633 | void if_attach(struct ifnet *); | |
634 | int if_delmultiaddr(struct ifmultiaddr *ifma, int locked); | |
635 | int if_delmulti(struct ifnet *, const struct sockaddr *); | |
636 | void if_down(struct ifnet *); | |
637 | void if_route(struct ifnet *, int flag, int fam); | |
638 | void if_unroute(struct ifnet *, int flag, int fam); | |
639 | void if_up(struct ifnet *); | |
640 | void if_updown(struct ifnet *ifp, int up); | |
641 | /*void ifinit(void));*/ /* declared in systm.h for main( */ | |
642 | int ifioctl(struct socket *, u_long, caddr_t, struct proc *); | |
643 | int ifioctllocked(struct socket *, u_long, caddr_t, struct proc *); | |
644 | struct ifnet *ifunit(const char *); | |
645 | struct ifnet *if_withname(struct sockaddr *); | |
9bccf70c | 646 | |
4a249263 A |
647 | void if_clone_attach(struct if_clone *); |
648 | void if_clone_detach(struct if_clone *); | |
1c79356b | 649 | |
91447636 A |
650 | void ifnet_lock_assert(struct ifnet *ifp, int what); |
651 | void ifnet_lock_shared(struct ifnet *ifp); | |
652 | void ifnet_lock_exclusive(struct ifnet *ifp); | |
653 | void ifnet_lock_done(struct ifnet *ifp); | |
654 | ||
655 | void ifnet_head_lock_shared(void); | |
656 | void ifnet_head_lock_exclusive(void); | |
657 | void ifnet_head_done(void); | |
658 | ||
659 | void if_attach_ifa(struct ifnet * ifp, struct ifaddr *ifa); | |
660 | void if_detach_ifa(struct ifnet * ifp, struct ifaddr *ifa); | |
661 | ||
662 | void ifma_reference(struct ifmultiaddr *ifma); | |
663 | void ifma_release(struct ifmultiaddr *ifma); | |
664 | ||
665 | struct ifaddr *ifa_ifwithaddr(const struct sockaddr *); | |
666 | struct ifaddr *ifa_ifwithdstaddr(const struct sockaddr *); | |
667 | struct ifaddr *ifa_ifwithnet(const struct sockaddr *); | |
668 | struct ifaddr *ifa_ifwithroute(int, const struct sockaddr *, const struct sockaddr *); | |
669 | struct ifaddr *ifaof_ifpforaddr(const struct sockaddr *, struct ifnet *); | |
670 | void ifafree(struct ifaddr *); | |
671 | void ifaref(struct ifaddr *); | |
672 | ||
673 | struct ifmultiaddr *ifmaof_ifpforaddr(const struct sockaddr *, struct ifnet *); | |
674 | ||
675 | #ifdef BSD_KERNEL_PRIVATE | |
676 | void if_data_internal_to_if_data(const struct if_data_internal *if_data_int, | |
677 | struct if_data *if_data); | |
678 | void if_data_internal_to_if_data64(const struct if_data_internal *if_data_int, | |
679 | struct if_data64 *if_data64); | |
680 | #endif /* BSD_KERNEL_PRIVATE */ | |
681 | #endif /* KERNEL_PRIVATE */ | |
1c79356b | 682 | #endif /* !_NET_IF_VAR_H_ */ |