]>
Commit | Line | Data |
---|---|---|
1 | /* | |
2 | * Copyright (c) 2000-2016 Apple Inc. All rights reserved. | |
3 | * | |
4 | * @APPLE_OSREFERENCE_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. 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. | |
14 | * | |
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 | |
20 | * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, | |
21 | * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, | |
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. | |
25 | * | |
26 | * @APPLE_OSREFERENCE_LICENSE_HEADER_END@ | |
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 | |
61 | * $FreeBSD: src/sys/net/if_var.h,v 1.18.2.7 2001/07/24 19:10:18 brooks Exp $ | |
62 | */ | |
63 | ||
64 | #ifndef _NET_IF_VAR_H_ | |
65 | #define _NET_IF_VAR_H_ | |
66 | ||
67 | #include <sys/appleapiopts.h> | |
68 | #include <stdint.h> | |
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 */ | |
75 | #ifdef PRIVATE | |
76 | #include <net/route.h> | |
77 | #endif | |
78 | ||
79 | #ifdef KERNEL | |
80 | #include <net/kpi_interface.h> | |
81 | #endif /* KERNEL */ | |
82 | ||
83 | #ifdef __APPLE__ | |
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 /* deprecated */ | |
95 | #define APPLE_IF_FAM_STF 12 | |
96 | #define APPLE_IF_FAM_FIREWIRE 13 | |
97 | #define APPLE_IF_FAM_BOND 14 | |
98 | #endif /* __APPLE__ */ | |
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 | |
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 | ||
132 | #define IFNAMSIZ 16 | |
133 | ||
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 { | |
139 | u_int32_t if_family; | |
140 | u_int32_t if_unit; | |
141 | char if_name[IFNAMSIZ]; | |
142 | }; | |
143 | ||
144 | #if defined(__LP64__) | |
145 | #include <sys/_types/_timeval32.h> | |
146 | #define IF_DATA_TIMEVAL timeval32 | |
147 | #else | |
148 | #define IF_DATA_TIMEVAL timeval | |
149 | #endif | |
150 | ||
151 | #pragma pack(4) | |
152 | ||
153 | /* | |
154 | * Structure describing information about an interface | |
155 | * which may be of interest to management entities. | |
156 | */ | |
157 | struct if_data { | |
158 | /* generic interface information */ | |
159 | u_char ifi_type; /* ethernet, tokenring, etc */ | |
160 | u_char ifi_typelen; /* Length of frame type id */ | |
161 | u_char ifi_physical; /* e.g., AUI, Thinnet, 10base-T, etc */ | |
162 | u_char ifi_addrlen; /* media address length */ | |
163 | u_char ifi_hdrlen; /* media header length */ | |
164 | u_char ifi_recvquota; /* polling quota for receive intrs */ | |
165 | u_char ifi_xmitquota; /* polling quota for xmit intrs */ | |
166 | u_char ifi_unused1; /* for future use */ | |
167 | u_int32_t ifi_mtu; /* maximum transmission unit */ | |
168 | u_int32_t ifi_metric; /* routing metric (external only) */ | |
169 | u_int32_t ifi_baudrate; /* linespeed */ | |
170 | /* volatile statistics */ | |
171 | u_int32_t ifi_ipackets; /* packets received on interface */ | |
172 | u_int32_t ifi_ierrors; /* input errors on interface */ | |
173 | u_int32_t ifi_opackets; /* packets sent on interface */ | |
174 | u_int32_t ifi_oerrors; /* output errors on interface */ | |
175 | u_int32_t ifi_collisions; /* collisions on csma interfaces */ | |
176 | u_int32_t ifi_ibytes; /* total number of octets received */ | |
177 | u_int32_t ifi_obytes; /* total number of octets sent */ | |
178 | u_int32_t ifi_imcasts; /* packets received via multicast */ | |
179 | u_int32_t ifi_omcasts; /* packets sent via multicast */ | |
180 | u_int32_t ifi_iqdrops; /* dropped on input, this interface */ | |
181 | u_int32_t ifi_noproto; /* destined for unsupported protocol */ | |
182 | u_int32_t ifi_recvtiming; /* usec spent receiving when timing */ | |
183 | u_int32_t ifi_xmittiming; /* usec spent xmitting when timing */ | |
184 | struct IF_DATA_TIMEVAL ifi_lastchange; /* time of last administrative change */ | |
185 | u_int32_t ifi_unused2; /* used to be the default_proto */ | |
186 | u_int32_t ifi_hwassist; /* HW offload capabilities */ | |
187 | u_int32_t ifi_reserved1; /* for future use */ | |
188 | u_int32_t ifi_reserved2; /* for future use */ | |
189 | }; | |
190 | ||
191 | /* | |
192 | * Structure describing information about an interface | |
193 | * which may be of interest to management entities. | |
194 | */ | |
195 | struct if_data64 { | |
196 | /* generic interface information */ | |
197 | u_char ifi_type; /* ethernet, tokenring, etc */ | |
198 | u_char ifi_typelen; /* Length of frame type id */ | |
199 | u_char ifi_physical; /* e.g., AUI, Thinnet, 10base-T, etc */ | |
200 | u_char ifi_addrlen; /* media address length */ | |
201 | u_char ifi_hdrlen; /* media header length */ | |
202 | u_char ifi_recvquota; /* polling quota for receive intrs */ | |
203 | u_char ifi_xmitquota; /* polling quota for xmit intrs */ | |
204 | u_char ifi_unused1; /* for future use */ | |
205 | u_int32_t ifi_mtu; /* maximum transmission unit */ | |
206 | u_int32_t ifi_metric; /* routing metric (external only) */ | |
207 | u_int64_t ifi_baudrate; /* linespeed */ | |
208 | /* volatile statistics */ | |
209 | u_int64_t ifi_ipackets; /* packets received on interface */ | |
210 | u_int64_t ifi_ierrors; /* input errors on interface */ | |
211 | u_int64_t ifi_opackets; /* packets sent on interface */ | |
212 | u_int64_t ifi_oerrors; /* output errors on interface */ | |
213 | u_int64_t ifi_collisions; /* collisions on csma interfaces */ | |
214 | u_int64_t ifi_ibytes; /* total number of octets received */ | |
215 | u_int64_t ifi_obytes; /* total number of octets sent */ | |
216 | u_int64_t ifi_imcasts; /* packets received via multicast */ | |
217 | u_int64_t ifi_omcasts; /* packets sent via multicast */ | |
218 | u_int64_t ifi_iqdrops; /* dropped on input, this interface */ | |
219 | u_int64_t ifi_noproto; /* destined for unsupported protocol */ | |
220 | u_int32_t ifi_recvtiming; /* usec spent receiving when timing */ | |
221 | u_int32_t ifi_xmittiming; /* usec spent xmitting when timing */ | |
222 | struct IF_DATA_TIMEVAL ifi_lastchange; /* time of last administrative change */ | |
223 | }; | |
224 | ||
225 | #ifdef PRIVATE | |
226 | struct if_traffic_class { | |
227 | u_int64_t ifi_ibepackets; /* TC_BE packets received on interface */ | |
228 | u_int64_t ifi_ibebytes; /* TC_BE bytes received on interface */ | |
229 | u_int64_t ifi_obepackets; /* TC_BE packet sent on interface */ | |
230 | u_int64_t ifi_obebytes; /* TC_BE bytes sent on interface */ | |
231 | u_int64_t ifi_ibkpackets; /* TC_BK packets received on interface */ | |
232 | u_int64_t ifi_ibkbytes; /* TC_BK bytes received on interface */ | |
233 | u_int64_t ifi_obkpackets; /* TC_BK packet sent on interface */ | |
234 | u_int64_t ifi_obkbytes; /* TC_BK bytes sent on interface */ | |
235 | u_int64_t ifi_ivipackets; /* TC_VI packets received on interface */ | |
236 | u_int64_t ifi_ivibytes; /* TC_VI bytes received on interface */ | |
237 | u_int64_t ifi_ovipackets; /* TC_VI packets sent on interface */ | |
238 | u_int64_t ifi_ovibytes; /* TC_VI bytes sent on interface */ | |
239 | u_int64_t ifi_ivopackets; /* TC_VO packets received on interface */ | |
240 | u_int64_t ifi_ivobytes; /* TC_VO bytes received on interface */ | |
241 | u_int64_t ifi_ovopackets; /* TC_VO packets sent on interface */ | |
242 | u_int64_t ifi_ovobytes; /* TC_VO bytes sent on interface */ | |
243 | u_int64_t ifi_ipvpackets; /* TC priv packets received on interface */ | |
244 | u_int64_t ifi_ipvbytes; /* TC priv bytes received on interface */ | |
245 | u_int64_t ifi_opvpackets; /* TC priv packets sent on interface */ | |
246 | u_int64_t ifi_opvbytes; /* TC priv bytes sent on interface */ | |
247 | }; | |
248 | ||
249 | struct if_data_extended { | |
250 | u_int64_t ifi_alignerrs; /* unaligned (32-bit) input pkts */ | |
251 | u_int64_t ifi_dt_bytes; /* Data threshold counter */ | |
252 | u_int64_t ifi_fpackets; /* forwarded packets on interface */ | |
253 | u_int64_t ifi_fbytes; /* forwarded bytes on interface */ | |
254 | u_int64_t reserved[12]; /* for future */ | |
255 | }; | |
256 | ||
257 | struct if_packet_stats { | |
258 | /* TCP */ | |
259 | u_int64_t ifi_tcp_badformat; | |
260 | u_int64_t ifi_tcp_unspecv6; | |
261 | u_int64_t ifi_tcp_synfin; | |
262 | u_int64_t ifi_tcp_badformatipsec; | |
263 | u_int64_t ifi_tcp_noconnnolist; | |
264 | u_int64_t ifi_tcp_noconnlist; | |
265 | u_int64_t ifi_tcp_listbadsyn; | |
266 | u_int64_t ifi_tcp_icmp6unreach; | |
267 | u_int64_t ifi_tcp_deprecate6; | |
268 | u_int64_t ifi_tcp_rstinsynrcv; | |
269 | u_int64_t ifi_tcp_ooopacket; | |
270 | u_int64_t ifi_tcp_dospacket; | |
271 | u_int64_t ifi_tcp_cleanup; | |
272 | u_int64_t ifi_tcp_synwindow; | |
273 | u_int64_t reserved[6]; | |
274 | /* UDP */ | |
275 | u_int64_t ifi_udp_port_unreach; | |
276 | u_int64_t ifi_udp_faithprefix; | |
277 | u_int64_t ifi_udp_port0; | |
278 | u_int64_t ifi_udp_badlength; | |
279 | u_int64_t ifi_udp_badchksum; | |
280 | u_int64_t ifi_udp_badmcast; | |
281 | u_int64_t ifi_udp_cleanup; | |
282 | u_int64_t ifi_udp_badipsec; | |
283 | u_int64_t _reserved[4]; | |
284 | }; | |
285 | ||
286 | struct if_description { | |
287 | u_int32_t ifd_maxlen; /* must be IF_DESCSIZE */ | |
288 | u_int32_t ifd_len; /* actual ifd_desc length */ | |
289 | u_int8_t *ifd_desc; /* ptr to desc buffer */ | |
290 | }; | |
291 | ||
292 | struct if_bandwidths { | |
293 | u_int64_t eff_bw; /* effective bandwidth */ | |
294 | u_int64_t max_bw; /* maximum theoretical bandwidth */ | |
295 | }; | |
296 | ||
297 | struct if_latencies { | |
298 | u_int64_t eff_lt; /* effective latency */ | |
299 | u_int64_t max_lt; /* maximum theoretical latency */ | |
300 | }; | |
301 | ||
302 | struct if_rxpoll_stats { | |
303 | u_int32_t ifi_poll_off_req; /* total # of POLL_OFF reqs */ | |
304 | u_int32_t ifi_poll_off_err; /* total # of POLL_OFF errors */ | |
305 | u_int32_t ifi_poll_on_req; /* total # of POLL_ON reqs */ | |
306 | u_int32_t ifi_poll_on_err; /* total # of POLL_ON errors */ | |
307 | ||
308 | u_int32_t ifi_poll_wakeups_avg; /* avg # of wakeup reqs */ | |
309 | u_int32_t ifi_poll_wakeups_lowat; /* wakeups low watermark */ | |
310 | u_int32_t ifi_poll_wakeups_hiwat; /* wakeups high watermark */ | |
311 | ||
312 | u_int64_t ifi_poll_packets; /* total # of polled packets */ | |
313 | u_int32_t ifi_poll_packets_avg; /* average polled packets */ | |
314 | u_int32_t ifi_poll_packets_min; /* smallest polled packets */ | |
315 | u_int32_t ifi_poll_packets_max; /* largest polled packets */ | |
316 | u_int32_t ifi_poll_packets_lowat; /* packets low watermark */ | |
317 | u_int32_t ifi_poll_packets_hiwat; /* packets high watermark */ | |
318 | ||
319 | u_int64_t ifi_poll_bytes; /* total # of polled bytes */ | |
320 | u_int32_t ifi_poll_bytes_avg; /* average polled bytes */ | |
321 | u_int32_t ifi_poll_bytes_min; /* smallest polled bytes */ | |
322 | u_int32_t ifi_poll_bytes_max; /* largest polled bytes */ | |
323 | u_int32_t ifi_poll_bytes_lowat; /* bytes low watermark */ | |
324 | u_int32_t ifi_poll_bytes_hiwat; /* bytes high watermark */ | |
325 | ||
326 | u_int32_t ifi_poll_packets_limit; /* max packets per poll call */ | |
327 | u_int64_t ifi_poll_interval_time; /* poll interval (nsec) */ | |
328 | }; | |
329 | ||
330 | struct if_tcp_ecn_perf_stat { | |
331 | u_int64_t total_txpkts; | |
332 | u_int64_t total_rxmitpkts; | |
333 | u_int64_t total_rxpkts; | |
334 | u_int64_t total_oopkts; | |
335 | u_int64_t total_reorderpkts; | |
336 | u_int64_t rtt_avg; | |
337 | u_int64_t rtt_var; | |
338 | u_int64_t sack_episodes; | |
339 | u_int64_t rxmit_drop; | |
340 | u_int64_t rst_drop; | |
341 | u_int64_t oo_percent; | |
342 | u_int64_t reorder_percent; | |
343 | u_int64_t rxmit_percent; | |
344 | }; | |
345 | ||
346 | struct if_tcp_ecn_stat { | |
347 | u_int64_t timestamp; | |
348 | u_int64_t ecn_client_setup; | |
349 | u_int64_t ecn_server_setup; | |
350 | u_int64_t ecn_client_success; | |
351 | u_int64_t ecn_server_success; | |
352 | u_int64_t ecn_peer_nosupport; | |
353 | u_int64_t ecn_syn_lost; | |
354 | u_int64_t ecn_synack_lost; | |
355 | u_int64_t ecn_recv_ce; | |
356 | u_int64_t ecn_recv_ece; | |
357 | u_int64_t ecn_conn_recv_ce; | |
358 | u_int64_t ecn_conn_recv_ece; | |
359 | u_int64_t ecn_conn_plnoce; | |
360 | u_int64_t ecn_conn_plce; | |
361 | u_int64_t ecn_conn_noplce; | |
362 | u_int64_t ecn_fallback_synloss; | |
363 | u_int64_t ecn_fallback_reorder; | |
364 | u_int64_t ecn_fallback_ce; | |
365 | u_int64_t ecn_off_conn; | |
366 | u_int64_t ecn_total_conn; | |
367 | u_int64_t ecn_fallback_droprst; | |
368 | u_int64_t ecn_fallback_droprxmt; | |
369 | struct if_tcp_ecn_perf_stat ecn_on; | |
370 | struct if_tcp_ecn_perf_stat ecn_off; | |
371 | }; | |
372 | ||
373 | /* | |
374 | * Interface link status report -- includes statistics related to | |
375 | * the link layer technology sent by the driver. The driver will monitor | |
376 | * these statistics over an interval (3-4 secs) and will generate a report | |
377 | * to the network stack. This will give first-hand information about the | |
378 | * status of the first hop of the network path. The version and | |
379 | * length values should be correct for the data to be processed correctly. | |
380 | * The definitions are different for different kind of interfaces like | |
381 | * Wifi, Cellular etc,. | |
382 | */ | |
383 | #define IF_CELLULAR_STATUS_REPORT_VERSION_1 1 | |
384 | #define IF_WIFI_STATUS_REPORT_VERSION_1 1 | |
385 | #define IF_CELLULAR_STATUS_REPORT_CURRENT_VERSION \ | |
386 | IF_CELLULAR_STATUS_REPORT_VERSION_1 | |
387 | #define IF_WIFI_STATUS_REPORT_CURRENT_VERSION IF_WIFI_STATUS_REPORT_VERSION_1 | |
388 | /* | |
389 | * For cellular interface -- | |
390 | * There is no way to share common headers between the Baseband and | |
391 | * the kernel. Any changes to this structure will need to be communicated | |
392 | * to the Baseband team. It is better to use reserved space instead of | |
393 | * changing the size or existing fields in the structure. | |
394 | */ | |
395 | struct if_cellular_status_v1 { | |
396 | u_int32_t valid_bitmask; /* indicates which fields are valid */ | |
397 | #define IF_CELL_LINK_QUALITY_METRIC_VALID 0x1 | |
398 | #define IF_CELL_UL_EFFECTIVE_BANDWIDTH_VALID 0x2 | |
399 | #define IF_CELL_UL_MAX_BANDWIDTH_VALID 0x4 | |
400 | #define IF_CELL_UL_MIN_LATENCY_VALID 0x8 | |
401 | #define IF_CELL_UL_EFFECTIVE_LATENCY_VALID 0x10 | |
402 | #define IF_CELL_UL_MAX_LATENCY_VALID 0x20 | |
403 | #define IF_CELL_UL_RETXT_LEVEL_VALID 0x40 | |
404 | #define IF_CELL_UL_BYTES_LOST_VALID 0x80 | |
405 | #define IF_CELL_UL_MIN_QUEUE_SIZE_VALID 0x100 | |
406 | #define IF_CELL_UL_AVG_QUEUE_SIZE_VALID 0x200 | |
407 | #define IF_CELL_UL_MAX_QUEUE_SIZE_VALID 0x400 | |
408 | #define IF_CELL_DL_EFFECTIVE_BANDWIDTH_VALID 0x800 | |
409 | #define IF_CELL_DL_MAX_BANDWIDTH_VALID 0x1000 | |
410 | #define IF_CELL_CONFIG_INACTIVITY_TIME_VALID 0x2000 | |
411 | #define IF_CELL_CONFIG_BACKOFF_TIME_VALID 0x4000 | |
412 | #define IF_CELL_UL_MSS_RECOMMENDED_VALID 0x8000 | |
413 | ||
414 | u_int32_t link_quality_metric; | |
415 | u_int32_t ul_effective_bandwidth; /* Measured uplink bandwidth based on current activity (bps) */ | |
416 | u_int32_t ul_max_bandwidth; /* Maximum supported uplink bandwidth (bps) */ | |
417 | u_int32_t ul_min_latency; /* min expected uplink latency for first hop (ms) */ | |
418 | u_int32_t ul_effective_latency; /* current expected uplink latency for first hop (ms) */ | |
419 | u_int32_t ul_max_latency; /* max expected uplink latency first hop (ms) */ | |
420 | u_int32_t ul_retxt_level; /* Retransmission metric */ | |
421 | #define IF_CELL_UL_RETXT_LEVEL_NONE 1 | |
422 | #define IF_CELL_UL_RETXT_LEVEL_LOW 2 | |
423 | #define IF_CELL_UL_RETXT_LEVEL_MEDIUM 3 | |
424 | #define IF_CELL_UL_RETXT_LEVEL_HIGH 4 | |
425 | u_int32_t ul_bytes_lost; /* % of total bytes lost on uplink in Q10 format */ | |
426 | u_int32_t ul_min_queue_size; /* minimum bytes in queue */ | |
427 | u_int32_t ul_avg_queue_size; /* average bytes in queue */ | |
428 | u_int32_t ul_max_queue_size; /* maximum bytes in queue */ | |
429 | u_int32_t dl_effective_bandwidth; /* Measured downlink bandwidth based on current activity (bps) */ | |
430 | u_int32_t dl_max_bandwidth; /* Maximum supported downlink bandwidth (bps) */ | |
431 | u_int32_t config_inactivity_time; /* ms */ | |
432 | u_int32_t config_backoff_time; /* new connections backoff time in ms */ | |
433 | #define IF_CELL_UL_MSS_RECOMMENDED_NONE 0x0 /* Use default */ | |
434 | #define IF_CELL_UL_MSS_RECOMMENDED_MEDIUM 0x1 /* 1200 byte MSS */ | |
435 | #define IF_CELL_UL_MSS_RECOMMENDED_LOW 0x2 /* 512 byte MSS */ | |
436 | u_int16_t mss_recommended; | |
437 | u_int16_t reserved_1; | |
438 | u_int32_t reserved_2; | |
439 | u_int64_t reserved_3; | |
440 | u_int64_t reserved_4; | |
441 | u_int64_t reserved_5; | |
442 | u_int64_t reserved_6; | |
443 | } __attribute__((packed)); | |
444 | ||
445 | struct if_cellular_status { | |
446 | union { | |
447 | struct if_cellular_status_v1 if_status_v1; | |
448 | } if_cell_u; | |
449 | }; | |
450 | ||
451 | /* | |
452 | * These statistics will be provided by the Wifi driver periodically. | |
453 | * After sending each report, the driver should start computing again | |
454 | * for the next report duration so that the values represent the link | |
455 | * status for one report duration. | |
456 | */ | |
457 | ||
458 | struct if_wifi_status_v1 { | |
459 | u_int32_t valid_bitmask; | |
460 | #define IF_WIFI_LINK_QUALITY_METRIC_VALID 0x1 | |
461 | #define IF_WIFI_UL_EFFECTIVE_BANDWIDTH_VALID 0x2 | |
462 | #define IF_WIFI_UL_MAX_BANDWIDTH_VALID 0x4 | |
463 | #define IF_WIFI_UL_MIN_LATENCY_VALID 0x8 | |
464 | #define IF_WIFI_UL_EFFECTIVE_LATENCY_VALID 0x10 | |
465 | #define IF_WIFI_UL_MAX_LATENCY_VALID 0x20 | |
466 | #define IF_WIFI_UL_RETXT_LEVEL_VALID 0x40 | |
467 | #define IF_WIFI_UL_ERROR_RATE_VALID 0x80 | |
468 | #define IF_WIFI_UL_BYTES_LOST_VALID 0x100 | |
469 | #define IF_WIFI_DL_EFFECTIVE_BANDWIDTH_VALID 0x200 | |
470 | #define IF_WIFI_DL_MAX_BANDWIDTH_VALID 0x400 | |
471 | #define IF_WIFI_DL_MIN_LATENCY_VALID 0x800 | |
472 | #define IF_WIFI_DL_EFFECTIVE_LATENCY_VALID 0x1000 | |
473 | #define IF_WIFI_DL_MAX_LATENCY_VALID 0x2000 | |
474 | #define IF_WIFI_DL_ERROR_RATE_VALID 0x4000 | |
475 | #define IF_WIFI_CONFIG_FREQUENCY_VALID 0x8000 | |
476 | #define IF_WIFI_CONFIG_MULTICAST_RATE_VALID 0x10000 | |
477 | #define IF_WIFI_CONFIG_SCAN_COUNT_VALID 0x20000 | |
478 | #define IF_WIFI_CONFIG_SCAN_DURATION_VALID 0x40000 | |
479 | u_int32_t link_quality_metric; /* link quality metric */ | |
480 | u_int32_t ul_effective_bandwidth; /* Measured uplink bandwidth based on current activity (bps) */ | |
481 | u_int32_t ul_max_bandwidth; /* Maximum supported uplink bandwidth (bps) */ | |
482 | u_int32_t ul_min_latency; /* min expected uplink latency for first hop (ms) */ | |
483 | u_int32_t ul_effective_latency; /* current expected uplink latency for first hop (ms) */ | |
484 | u_int32_t ul_max_latency; /* max expected uplink latency for first hop (ms) */ | |
485 | u_int32_t ul_retxt_level; /* Retransmission metric */ | |
486 | #define IF_WIFI_UL_RETXT_LEVEL_NONE 1 | |
487 | #define IF_WIFI_UL_RETXT_LEVEL_LOW 2 | |
488 | #define IF_WIFI_UL_RETXT_LEVEL_MEDIUM 3 | |
489 | #define IF_WIFI_UL_RETXT_LEVEL_HIGH 4 | |
490 | u_int32_t ul_bytes_lost; /* % of total bytes lost on uplink in Q10 format */ | |
491 | u_int32_t ul_error_rate; /* % of bytes dropped on uplink after many retransmissions in Q10 format */ | |
492 | u_int32_t dl_effective_bandwidth; /* Measured downlink bandwidth based on current activity (bps) */ | |
493 | u_int32_t dl_max_bandwidth; /* Maximum supported downlink bandwidth (bps) */ | |
494 | /* | |
495 | * The download latency values indicate the time AP may have to wait for the | |
496 | * driver to receive the packet. These values give the range of expected latency | |
497 | * mainly due to co-existence events and channel hopping where the interface | |
498 | * becomes unavailable. | |
499 | */ | |
500 | u_int32_t dl_min_latency; /* min expected latency for first hop in ms */ | |
501 | u_int32_t dl_effective_latency; /* current expected latency for first hop in ms */ | |
502 | u_int32_t dl_max_latency; /* max expected latency for first hop in ms */ | |
503 | u_int32_t dl_error_rate; /* % of CRC or other errors in Q10 format */ | |
504 | u_int32_t config_frequency; /* 2.4 or 5 GHz */ | |
505 | #define IF_WIFI_CONFIG_FREQUENCY_2_4_GHZ 1 | |
506 | #define IF_WIFI_CONFIG_FREQUENCY_5_0_GHZ 2 | |
507 | u_int32_t config_multicast_rate; /* bps */ | |
508 | u_int32_t scan_count; /* scan count during the previous period */ | |
509 | u_int32_t scan_duration; /* scan duration in ms */ | |
510 | u_int64_t reserved_1; | |
511 | u_int64_t reserved_2; | |
512 | u_int64_t reserved_3; | |
513 | u_int64_t reserved_4; | |
514 | } __attribute__((packed)); | |
515 | ||
516 | struct if_wifi_status { | |
517 | union { | |
518 | struct if_wifi_status_v1 if_status_v1; | |
519 | } if_wifi_u; | |
520 | }; | |
521 | ||
522 | struct if_link_status { | |
523 | u_int32_t ifsr_version; /* version of this report */ | |
524 | u_int32_t ifsr_len; /* length of the following struct */ | |
525 | union { | |
526 | struct if_cellular_status ifsr_cell; | |
527 | struct if_wifi_status ifsr_wifi; | |
528 | } ifsr_u; | |
529 | }; | |
530 | ||
531 | struct if_interface_state { | |
532 | /* | |
533 | * The bitmask tells which of the fields | |
534 | * to consider: | |
535 | * - When setting, to control which fields | |
536 | * are being modified; | |
537 | * - When getting, it tells which fields are set. | |
538 | */ | |
539 | u_int8_t valid_bitmask; | |
540 | #define IF_INTERFACE_STATE_RRC_STATE_VALID 0x1 | |
541 | #define IF_INTERFACE_STATE_LQM_STATE_VALID 0x2 | |
542 | #define IF_INTERFACE_STATE_INTERFACE_AVAILABILITY_VALID 0x4 | |
543 | ||
544 | /* | |
545 | * Valid only for cellular interface | |
546 | */ | |
547 | u_int8_t rrc_state; | |
548 | #define IF_INTERFACE_STATE_RRC_STATE_IDLE 0x0 | |
549 | #define IF_INTERFACE_STATE_RRC_STATE_CONNECTED 0x1 | |
550 | ||
551 | /* | |
552 | * Values normalized to the edge of the following values | |
553 | * that are defined on <net/if.h>: | |
554 | * IFNET_LQM_THRESH_BAD | |
555 | * IFNET_LQM_THRESH_POOR | |
556 | * IFNET_LQM_THRESH_GOOD | |
557 | */ | |
558 | int8_t lqm_state; | |
559 | ||
560 | /* | |
561 | * Indicate if the underlying link is currently | |
562 | * available | |
563 | */ | |
564 | u_int8_t interface_availability; | |
565 | #define IF_INTERFACE_STATE_INTERFACE_AVAILABLE 0x0 | |
566 | #define IF_INTERFACE_STATE_INTERFACE_UNAVAILABLE 0x1 | |
567 | }; | |
568 | ||
569 | struct chain_len_stats { | |
570 | uint64_t cls_one; | |
571 | uint64_t cls_two; | |
572 | uint64_t cls_three; | |
573 | uint64_t cls_four; | |
574 | uint64_t cls_five_or_more; | |
575 | }; | |
576 | ||
577 | #endif /* PRIVATE */ | |
578 | ||
579 | #pragma pack() | |
580 | ||
581 | /* | |
582 | * Structure defining a queue for a network interface. | |
583 | */ | |
584 | struct ifqueue { | |
585 | void *ifq_head; | |
586 | void *ifq_tail; | |
587 | int ifq_len; | |
588 | int ifq_maxlen; | |
589 | int ifq_drops; | |
590 | }; | |
591 | ||
592 | #ifdef BSD_KERNEL_PRIVATE | |
593 | /* | |
594 | * Internal storage of if_data. This is bound to change. Various places in the | |
595 | * stack will translate this data structure in to the externally visible | |
596 | * if_data structure above. Note that during interface attach time, the | |
597 | * embedded if_data structure in ifnet is cleared, with the exception of | |
598 | * some non-statistics related fields. | |
599 | */ | |
600 | struct if_data_internal { | |
601 | /* generic interface information */ | |
602 | u_char ifi_type; /* ethernet, tokenring, etc */ | |
603 | u_char ifi_typelen; /* Length of frame type id */ | |
604 | u_char ifi_physical; /* e.g., AUI, Thinnet, 10base-T, etc */ | |
605 | u_char ifi_addrlen; /* media address length */ | |
606 | u_char ifi_hdrlen; /* media header length */ | |
607 | u_char ifi_recvquota; /* polling quota for receive intrs */ | |
608 | u_char ifi_xmitquota; /* polling quota for xmit intrs */ | |
609 | u_char ifi_unused1; /* for future use */ | |
610 | u_int32_t ifi_mtu; /* maximum transmission unit */ | |
611 | u_int32_t ifi_metric; /* routing metric (external only) */ | |
612 | u_int32_t ifi_baudrate; /* linespeed */ | |
613 | u_int32_t ifi_preamblelen;/* length of the packet preamble */ | |
614 | /* volatile statistics */ | |
615 | u_int64_t ifi_ipackets; /* packets received on interface */ | |
616 | u_int64_t ifi_ierrors; /* input errors on interface */ | |
617 | u_int64_t ifi_opackets; /* packets sent on interface */ | |
618 | u_int64_t ifi_oerrors; /* output errors on interface */ | |
619 | u_int64_t ifi_collisions; /* collisions on csma interfaces */ | |
620 | u_int64_t ifi_ibytes; /* total number of octets received */ | |
621 | u_int64_t ifi_obytes; /* total number of octets sent */ | |
622 | u_int64_t ifi_imcasts; /* packets received via multicast */ | |
623 | u_int64_t ifi_omcasts; /* packets sent via multicast */ | |
624 | u_int64_t ifi_iqdrops; /* dropped on input, this interface */ | |
625 | u_int64_t ifi_noproto; /* destined for unsupported protocol */ | |
626 | u_int32_t ifi_recvtiming; /* usec spent receiving when timing */ | |
627 | u_int32_t ifi_xmittiming; /* usec spent xmitting when timing */ | |
628 | u_int64_t ifi_alignerrs; /* unaligned (32-bit) input pkts */ | |
629 | u_int64_t ifi_dt_bytes; /* Data threshold counter */ | |
630 | u_int64_t ifi_fpackets; /* forwarded packets on interface */ | |
631 | u_int64_t ifi_fbytes; /* forwarded bytes on interface */ | |
632 | struct timeval ifi_lastchange; /* time of last administrative change */ | |
633 | u_int32_t ifi_hwassist; /* HW offload capabilities */ | |
634 | u_int32_t ifi_tso_v4_mtu; /* TCP Segment Offload IPv4 maximum segment size */ | |
635 | u_int32_t ifi_tso_v6_mtu; /* TCP Segment Offload IPv6 maximum segment size */ | |
636 | }; | |
637 | ||
638 | #if MEASURE_BW | |
639 | /* | |
640 | * Fields per interface to measure perceived bandwidth. | |
641 | */ | |
642 | struct if_measured_bw { | |
643 | u_int64_t bw; /* measured bandwidth in bytes per ms */ | |
644 | u_int64_t bytes; /* XXX not needed */ | |
645 | u_int64_t ts; /* XXX not needed */ | |
646 | u_int64_t cur_seq __attribute((aligned(8))); /* current sequence for marking a packet */ | |
647 | u_int64_t start_ts; /* time at which a measurement started */ | |
648 | u_int64_t start_seq; /* sequence at which a measurement should start */ | |
649 | u_int64_t last_seq; /* last recorded seq */ | |
650 | u_int64_t last_ts; /* last recorded ts */ | |
651 | u_int32_t flags __attribute__((aligned(4))); /* flags */ | |
652 | #define IF_MEASURED_BW_INPROGRESS 0x1 | |
653 | #define IF_MEASURED_BW_CALCULATION 0x2 | |
654 | }; | |
655 | #endif /* MEASURE_BW */ | |
656 | #endif /* BSD_KERNEL_PRIVATE */ | |
657 | ||
658 | #ifdef PRIVATE | |
659 | #define if_mtu if_data.ifi_mtu | |
660 | #define if_type if_data.ifi_type | |
661 | #define if_typelen if_data.ifi_typelen | |
662 | #define if_physical if_data.ifi_physical | |
663 | #define if_addrlen if_data.ifi_addrlen | |
664 | #define if_hdrlen if_data.ifi_hdrlen | |
665 | #define if_preamblelen if_data.ifi_preamblelen | |
666 | #define if_metric if_data.ifi_metric | |
667 | #define if_baudrate if_data.ifi_baudrate | |
668 | #define if_hwassist if_data.ifi_hwassist | |
669 | #define if_ipackets if_data.ifi_ipackets | |
670 | #define if_ierrors if_data.ifi_ierrors | |
671 | #define if_opackets if_data.ifi_opackets | |
672 | #define if_oerrors if_data.ifi_oerrors | |
673 | #define if_collisions if_data.ifi_collisions | |
674 | #define if_ibytes if_data.ifi_ibytes | |
675 | #define if_obytes if_data.ifi_obytes | |
676 | #define if_imcasts if_data.ifi_imcasts | |
677 | #define if_omcasts if_data.ifi_omcasts | |
678 | #define if_iqdrops if_data.ifi_iqdrops | |
679 | #define if_noproto if_data.ifi_noproto | |
680 | #define if_lastchange if_data.ifi_lastchange | |
681 | #define if_recvquota if_data.ifi_recvquota | |
682 | #define if_xmitquota if_data.ifi_xmitquota | |
683 | #endif /* PRIVATE */ | |
684 | #ifdef BSD_KERNEL_PRIVATE | |
685 | #define if_tso_v4_mtu if_data.ifi_tso_v4_mtu | |
686 | #define if_tso_v6_mtu if_data.ifi_tso_v6_mtu | |
687 | #define if_alignerrs if_data.ifi_alignerrs | |
688 | #define if_dt_bytes if_data.ifi_dt_bytes | |
689 | #define if_fpackets if_data.ifi_fpackets | |
690 | #define if_fbytes if_data.ifi_fbytes | |
691 | #endif /* BSD_KERNEL_PRIVATE */ | |
692 | ||
693 | #ifdef BSD_KERNEL_PRIVATE | |
694 | /* | |
695 | * Forward structure declarations for function prototypes [sic]. | |
696 | */ | |
697 | struct proc; | |
698 | struct rtentry; | |
699 | struct socket; | |
700 | struct ifnet_filter; | |
701 | struct mbuf; | |
702 | struct ifaddr; | |
703 | struct tqdummy; | |
704 | struct proto_hash_entry; | |
705 | struct dlil_threading_info; | |
706 | struct tcpstat_local; | |
707 | struct udpstat_local; | |
708 | #if PF | |
709 | struct pfi_kif; | |
710 | #endif /* PF */ | |
711 | ||
712 | /* we use TAILQs so that the order of instantiation is preserved in the list */ | |
713 | TAILQ_HEAD(ifnethead, ifnet); | |
714 | TAILQ_HEAD(ifaddrhead, ifaddr); | |
715 | LIST_HEAD(ifmultihead, ifmultiaddr); | |
716 | TAILQ_HEAD(tailq_head, tqdummy); | |
717 | TAILQ_HEAD(ifnet_filter_head, ifnet_filter); | |
718 | TAILQ_HEAD(ddesc_head_name, dlil_demux_desc); | |
719 | #endif /* BSD_KERNEL_PRIVATE */ | |
720 | ||
721 | #ifdef PRIVATE | |
722 | /* | |
723 | * All of the following IF_HWASSIST_* flags are defined in kpi_inteface.h as | |
724 | * IFNET_* flags. These are redefined here as constants to avoid failures to | |
725 | * build user level programs that can not include kpi_interface.h. It is | |
726 | * important to keep this in sync with the definitions in kpi_interface.h. | |
727 | * The corresponding constant for each definition is mentioned in the comment. | |
728 | * | |
729 | * Bottom 16 bits reserved for hardware checksum | |
730 | */ | |
731 | #define IF_HWASSIST_CSUM_IP 0x0001 /* will csum IP, IFNET_CSUM_IP */ | |
732 | #define IF_HWASSIST_CSUM_TCP 0x0002 /* will csum TCP, IFNET_CSUM_TCP */ | |
733 | #define IF_HWASSIST_CSUM_UDP 0x0004 /* will csum UDP, IFNET_CSUM_UDP */ | |
734 | #define IF_HWASSIST_CSUM_IP_FRAGS 0x0008 /* will csum IP fragments, IFNET_CSUM_FRAGMENT */ | |
735 | #define IF_HWASSIST_CSUM_FRAGMENT 0x0010 /* will do IP fragmentation, IFNET_IP_FRAGMENT */ | |
736 | #define IF_HWASSIST_CSUM_TCPIPV6 0x0020 /* will csum TCPv6, IFNET_CSUM_TCPIPV6 */ | |
737 | #define IF_HWASSIST_CSUM_UDPIPV6 0x0040 /* will csum UDPv6, IFNET_CSUM_UDP */ | |
738 | #define IF_HWASSIST_CSUM_FRAGMENT_IPV6 0x0080 /* will do IPv6 fragmentation, IFNET_IPV6_FRAGMENT */ | |
739 | #define IF_HWASSIST_CSUM_PARTIAL 0x1000 /* simple Sum16 computation, IFNET_CSUM_PARTIAL */ | |
740 | #define IF_HWASSIST_CSUM_MASK 0xffff | |
741 | #define IF_HWASSIST_CSUM_FLAGS(hwassist) ((hwassist) & IF_HWASSIST_CSUM_MASK) | |
742 | ||
743 | /* VLAN support */ | |
744 | #define IF_HWASSIST_VLAN_TAGGING 0x00010000 /* supports VLAN tagging, IFNET_VLAN_TAGGING */ | |
745 | #define IF_HWASSIST_VLAN_MTU 0x00020000 /* supports VLAN MTU-sized packet (for software VLAN), IFNET_VLAN_MTU */ | |
746 | ||
747 | /* TCP Segment Offloading support */ | |
748 | ||
749 | #define IF_HWASSIST_TSO_V4 0x00200000 /* will do TCP Segment offload for IPv4, IFNET_TSO_IPV4 */ | |
750 | #define IF_HWASSIST_TSO_V6 0x00400000 /* will do TCP Segment offload for IPv6, IFNET_TSO_IPV6 */ | |
751 | #endif /* PRIVATE */ | |
752 | ||
753 | #ifdef PRIVATE | |
754 | #define IFXNAMSIZ (IFNAMSIZ + 8) /* external name (name + unit) */ | |
755 | #endif | |
756 | ||
757 | #ifdef BSD_KERNEL_PRIVATE | |
758 | /* | |
759 | * ifnet is private to BSD portion of kernel | |
760 | */ | |
761 | #include <sys/mcache.h> | |
762 | #include <sys/tree.h> | |
763 | #include <netinet/in.h> | |
764 | #include <net/if_dl.h> | |
765 | #include <net/classq/if_classq.h> | |
766 | #include <net/if_types.h> | |
767 | ||
768 | RB_HEAD(ll_reach_tree, if_llreach); /* define struct ll_reach_tree */ | |
769 | ||
770 | #define if_name(ifp) ifp->if_xname | |
771 | /* | |
772 | * Structure defining a network interface. | |
773 | * | |
774 | * (Would like to call this struct ``if'', but C isn't PL/1.) | |
775 | */ | |
776 | struct ifnet { | |
777 | /* | |
778 | * Lock (RW or mutex) to protect this data structure (static storage.) | |
779 | */ | |
780 | decl_lck_rw_data(, if_lock); | |
781 | void *if_softc; /* pointer to driver state */ | |
782 | const char *if_name; /* name, e.g. ``en'' or ``lo'' */ | |
783 | const char *if_xname; /* external name (name + unit) */ | |
784 | struct if_description if_desc; /* extended description */ | |
785 | TAILQ_ENTRY(ifnet) if_link; /* all struct ifnets are chained */ | |
786 | TAILQ_ENTRY(ifnet) if_detaching_link; /* list of detaching ifnets */ | |
787 | TAILQ_ENTRY(ifnet) if_ordered_link; /* list of ordered ifnets */ | |
788 | ||
789 | decl_lck_mtx_data(, if_ref_lock) | |
790 | u_int32_t if_refflags; /* see IFRF flags below */ | |
791 | u_int32_t if_refio; /* number of io ops to the underlying driver */ | |
792 | ||
793 | #define if_list if_link | |
794 | struct ifaddrhead if_addrhead; /* linked list of addresses per if */ | |
795 | #define if_addrlist if_addrhead | |
796 | struct ifaddr *if_lladdr; /* link address (first/permanent) */ | |
797 | ||
798 | u_int32_t if_qosmarking_mode; /* generation to use with NECP clients */ | |
799 | ||
800 | int if_pcount; /* number of promiscuous listeners */ | |
801 | struct bpf_if *if_bpf; /* packet filter structure */ | |
802 | u_short if_index; /* numeric abbreviation for this if */ | |
803 | short if_unit; /* sub-unit for lower level driver */ | |
804 | short if_timer; /* time 'til if_watchdog called */ | |
805 | short if_flags; /* up/down, broadcast, etc. */ | |
806 | u_int32_t if_eflags; /* see <net/if.h> */ | |
807 | u_int32_t if_xflags; /* see <net/if.h> */ | |
808 | ||
809 | int if_capabilities; /* interface features & capabilities */ | |
810 | int if_capenable; /* enabled features & capabilities */ | |
811 | ||
812 | void *if_linkmib; /* link-type-specific MIB data */ | |
813 | size_t if_linkmiblen; /* length of above data */ | |
814 | ||
815 | struct if_data_internal if_data __attribute__((aligned(8))); | |
816 | ||
817 | ifnet_family_t if_family; /* value assigned by Apple */ | |
818 | ifnet_subfamily_t if_subfamily; /* value assigned by Apple */ | |
819 | uintptr_t if_family_cookie; | |
820 | ifnet_output_handler_func if_output_handler; | |
821 | ifnet_output_func if_output; | |
822 | ifnet_pre_enqueue_func if_pre_enqueue; | |
823 | ifnet_start_func if_start; | |
824 | ifnet_ctl_func if_output_ctl; | |
825 | ifnet_input_handler_func if_input_handler; | |
826 | ifnet_input_poll_func if_input_poll; | |
827 | ifnet_ctl_func if_input_ctl; | |
828 | ifnet_ioctl_func if_ioctl; | |
829 | ifnet_set_bpf_tap if_set_bpf_tap; | |
830 | ifnet_detached_func if_free; | |
831 | ifnet_demux_func if_demux; | |
832 | ifnet_event_func if_event; | |
833 | ifnet_framer_func if_framer_legacy; | |
834 | ifnet_framer_extended_func if_framer; | |
835 | ifnet_add_proto_func if_add_proto; | |
836 | ifnet_del_proto_func if_del_proto; | |
837 | ifnet_check_multi if_check_multi; | |
838 | struct proto_hash_entry *if_proto_hash; | |
839 | void *if_kpi_storage; | |
840 | ||
841 | u_int32_t if_flowhash; /* interface flow control ID */ | |
842 | ||
843 | decl_lck_mtx_data(, if_start_lock); | |
844 | u_int32_t if_start_flags; /* see IFSF flags below */ | |
845 | u_int32_t if_start_req; | |
846 | u_int16_t if_start_active; /* output is active */ | |
847 | u_int16_t if_start_delayed; | |
848 | u_int16_t if_start_delay_qlen; | |
849 | u_int16_t if_start_delay_idle; | |
850 | u_int64_t if_start_delay_swin; | |
851 | u_int32_t if_start_delay_cnt; | |
852 | u_int32_t if_start_delay_timeout; /* nanoseconds */ | |
853 | struct timespec if_start_cycle; /* restart interval */ | |
854 | struct thread *if_start_thread; | |
855 | ||
856 | struct ifclassq if_snd; /* transmit queue */ | |
857 | u_int32_t if_output_sched_model; /* tx sched model */ | |
858 | ||
859 | struct if_bandwidths if_output_bw; | |
860 | struct if_bandwidths if_input_bw; | |
861 | ||
862 | struct if_latencies if_output_lt; | |
863 | struct if_latencies if_input_lt; | |
864 | ||
865 | decl_lck_mtx_data(, if_flt_lock) | |
866 | u_int32_t if_flt_busy; | |
867 | u_int32_t if_flt_waiters; | |
868 | struct ifnet_filter_head if_flt_head; | |
869 | ||
870 | struct ifmultihead if_multiaddrs; /* multicast addresses */ | |
871 | u_int32_t if_updatemcasts; /* mcast addrs need updating */ | |
872 | int if_amcount; /* # of all-multicast reqs */ | |
873 | decl_lck_mtx_data(, if_addrconfig_lock); /* for serializing addr config */ | |
874 | struct in_multi *if_allhostsinm; /* store all-hosts inm for this ifp */ | |
875 | ||
876 | decl_lck_mtx_data(, if_poll_lock); | |
877 | u_int16_t if_poll_req; | |
878 | u_int16_t if_poll_update; /* link update */ | |
879 | u_int32_t if_poll_active; /* polling is active */ | |
880 | struct timespec if_poll_cycle; /* poll interval */ | |
881 | struct thread *if_poll_thread; | |
882 | ||
883 | struct dlil_threading_info *if_inp; | |
884 | ||
885 | struct { | |
886 | u_int32_t length; | |
887 | union { | |
888 | u_char buffer[8]; | |
889 | u_char *ptr; | |
890 | } u; | |
891 | } if_broadcast; | |
892 | #if CONFIG_MACF_NET | |
893 | struct label *if_label; /* interface MAC label */ | |
894 | #endif | |
895 | ||
896 | #if PF | |
897 | struct pfi_kif *if_pf_kif; | |
898 | #endif /* PF */ | |
899 | ||
900 | decl_lck_mtx_data(, if_cached_route_lock); | |
901 | u_int32_t if_fwd_cacheok; | |
902 | struct route if_fwd_route; /* cached forwarding route */ | |
903 | struct route if_src_route; /* cached ipv4 source route */ | |
904 | struct route_in6 if_src_route6; /* cached ipv6 source route */ | |
905 | ||
906 | decl_lck_rw_data(, if_llreach_lock); | |
907 | struct ll_reach_tree if_ll_srcs; /* source link-layer tree */ | |
908 | ||
909 | void *if_bridge; /* bridge glue */ | |
910 | ||
911 | u_int32_t if_want_aggressive_drain; | |
912 | u_int32_t if_idle_flags; /* idle flags */ | |
913 | u_int32_t if_idle_new_flags; /* temporary idle flags */ | |
914 | u_int32_t if_idle_new_flags_mask; /* temporary mask */ | |
915 | u_int32_t if_route_refcnt; /* idle: route ref count */ | |
916 | u_int32_t if_rt_sendts; /* last of a real time packet */ | |
917 | ||
918 | struct if_traffic_class if_tc __attribute__((aligned(8))); | |
919 | #if INET | |
920 | struct igmp_ifinfo *if_igi; /* for IGMPv3 */ | |
921 | #endif /* INET */ | |
922 | #if INET6 | |
923 | struct mld_ifinfo *if_mli; /* for MLDv2 */ | |
924 | #endif /* INET6 */ | |
925 | ||
926 | #if MEASURE_BW | |
927 | struct if_measured_bw if_bw; | |
928 | #endif /* MEASURE_BW */ | |
929 | struct tcpstat_local *if_tcp_stat; /* TCP specific stats */ | |
930 | struct udpstat_local *if_udp_stat; /* UDP specific stats */ | |
931 | ||
932 | struct { | |
933 | int32_t level; /* cached logging level */ | |
934 | u_int32_t flags; /* cached logging flags */ | |
935 | int32_t category; /* cached category */ | |
936 | int32_t subcategory; /* cached subcategory */ | |
937 | } if_log; | |
938 | ||
939 | struct { | |
940 | struct ifnet *ifp; /* delegated ifp */ | |
941 | u_int32_t type; /* delegated i/f type */ | |
942 | u_int32_t family; /* delegated i/f family */ | |
943 | u_int32_t subfamily; /* delegated i/f sub-family */ | |
944 | uint32_t expensive:1; /* delegated i/f expensive? */ | |
945 | } if_delegated; | |
946 | ||
947 | uuid_t *if_agentids; /* network agents attached to interface */ | |
948 | u_int32_t if_agentcount; | |
949 | ||
950 | u_int32_t if_generation; /* generation to use with NECP clients */ | |
951 | u_int32_t if_fg_sendts; /* last send on a fg socket in seconds */ | |
952 | ||
953 | u_int64_t if_data_threshold; | |
954 | ||
955 | /* Total bytes in send socket buffer */ | |
956 | int64_t if_sndbyte_total __attribute__ ((aligned(8))); | |
957 | /* Total unsent bytes in send socket buffer */ | |
958 | int64_t if_sndbyte_unsent __attribute__ ((aligned(8))); | |
959 | /* count of times, when there was data to send when sleep is impending */ | |
960 | uint32_t if_unsent_data_cnt; | |
961 | ||
962 | #if INET | |
963 | decl_lck_rw_data(, if_inetdata_lock); | |
964 | void *if_inetdata; | |
965 | #endif /* INET */ | |
966 | #if INET6 | |
967 | decl_lck_rw_data(, if_inet6data_lock); | |
968 | void *if_inet6data; | |
969 | #endif | |
970 | decl_lck_rw_data(, if_link_status_lock); | |
971 | struct if_link_status *if_link_status; | |
972 | struct if_interface_state if_interface_state; | |
973 | struct if_tcp_ecn_stat *if_ipv4_stat; | |
974 | struct if_tcp_ecn_stat *if_ipv6_stat; | |
975 | }; | |
976 | ||
977 | #define IF_TCP_STATINC(_ifp, _s) do { \ | |
978 | if ((_ifp)->if_tcp_stat != NULL) \ | |
979 | atomic_add_64(&(_ifp)->if_tcp_stat->_s, 1); \ | |
980 | } while (0); | |
981 | ||
982 | #define IF_UDP_STATINC(_ifp, _s) do { \ | |
983 | if ((_ifp)->if_udp_stat != NULL) \ | |
984 | atomic_add_64(&(_ifp)->if_udp_stat->_s, 1); \ | |
985 | } while (0); | |
986 | ||
987 | /* | |
988 | * Valid values for if_refflags | |
989 | */ | |
990 | #define IFRF_ATTACHED 0x1 /* ifnet attach is completely done */ | |
991 | #define IFRF_DETACHING 0x2 /* detach has been requested */ | |
992 | ||
993 | /* | |
994 | * Valid values for if_start_flags | |
995 | */ | |
996 | #define IFSF_FLOW_CONTROLLED 0x1 /* flow controlled */ | |
997 | ||
998 | /* | |
999 | * Structure describing a `cloning' interface. | |
1000 | */ | |
1001 | struct if_clone { | |
1002 | LIST_ENTRY(if_clone) ifc_list; /* on list of cloners */ | |
1003 | const char *ifc_name; /* name of device, e.g. `vlan' */ | |
1004 | size_t ifc_namelen; /* length of name */ | |
1005 | u_int32_t ifc_minifs; /* minimum number of interfaces */ | |
1006 | u_int32_t ifc_maxunit; /* maximum unit number */ | |
1007 | unsigned char *ifc_units; /* bitmap to handle units */ | |
1008 | u_int32_t ifc_bmlen; /* bitmap length */ | |
1009 | ||
1010 | int (*ifc_create)(struct if_clone *, u_int32_t, void *); | |
1011 | int (*ifc_destroy)(struct ifnet *); | |
1012 | }; | |
1013 | ||
1014 | #define IF_CLONE_INITIALIZER(name, create, destroy, minifs, maxunit) { \ | |
1015 | { NULL, NULL }, name, (sizeof (name) - 1), minifs, maxunit, NULL, 0, \ | |
1016 | create, destroy \ | |
1017 | } | |
1018 | ||
1019 | #define M_CLONE M_IFADDR | |
1020 | ||
1021 | /* | |
1022 | * Macros to manipulate ifqueue. Users of these macros are responsible | |
1023 | * for serialization, by holding whatever lock is appropriate for the | |
1024 | * corresponding structure that is referring the ifqueue. | |
1025 | */ | |
1026 | #define IF_QFULL(ifq) ((ifq)->ifq_len >= (ifq)->ifq_maxlen) | |
1027 | #define IF_DROP(ifq) ((ifq)->ifq_drops++) | |
1028 | ||
1029 | #define IF_ENQUEUE(ifq, m) do { \ | |
1030 | (m)->m_nextpkt = NULL; \ | |
1031 | if ((ifq)->ifq_tail == NULL) \ | |
1032 | (ifq)->ifq_head = m; \ | |
1033 | else \ | |
1034 | ((struct mbuf*)(ifq)->ifq_tail)->m_nextpkt = m; \ | |
1035 | (ifq)->ifq_tail = m; \ | |
1036 | (ifq)->ifq_len++; \ | |
1037 | } while (0) | |
1038 | ||
1039 | #define IF_PREPEND(ifq, m) do { \ | |
1040 | (m)->m_nextpkt = (ifq)->ifq_head; \ | |
1041 | if ((ifq)->ifq_tail == NULL) \ | |
1042 | (ifq)->ifq_tail = (m); \ | |
1043 | (ifq)->ifq_head = (m); \ | |
1044 | (ifq)->ifq_len++; \ | |
1045 | } while (0) | |
1046 | ||
1047 | #define IF_DEQUEUE(ifq, m) do { \ | |
1048 | (m) = (ifq)->ifq_head; \ | |
1049 | if (m != NULL) { \ | |
1050 | if (((ifq)->ifq_head = (m)->m_nextpkt) == NULL) \ | |
1051 | (ifq)->ifq_tail = NULL; \ | |
1052 | (m)->m_nextpkt = NULL; \ | |
1053 | (ifq)->ifq_len--; \ | |
1054 | } \ | |
1055 | } while (0) | |
1056 | ||
1057 | #define IF_REMQUEUE(ifq, m) do { \ | |
1058 | struct mbuf *_p = (ifq)->ifq_head; \ | |
1059 | struct mbuf *_n = (m)->m_nextpkt; \ | |
1060 | if ((m) == _p) \ | |
1061 | _p = NULL; \ | |
1062 | while (_p != NULL) { \ | |
1063 | if (_p->m_nextpkt == (m)) \ | |
1064 | break; \ | |
1065 | _p = _p->m_nextpkt; \ | |
1066 | } \ | |
1067 | VERIFY(_p != NULL || ((m) == (ifq)->ifq_head)); \ | |
1068 | if ((m) == (ifq)->ifq_head) \ | |
1069 | (ifq)->ifq_head = _n; \ | |
1070 | if ((m) == (ifq)->ifq_tail) \ | |
1071 | (ifq)->ifq_tail = _p; \ | |
1072 | VERIFY((ifq)->ifq_tail != NULL || (ifq)->ifq_head == NULL); \ | |
1073 | VERIFY((ifq)->ifq_len != 0); \ | |
1074 | --(ifq)->ifq_len; \ | |
1075 | if (_p != NULL) \ | |
1076 | _p->m_nextpkt = _n; \ | |
1077 | (m)->m_nextpkt = NULL; \ | |
1078 | } while (0) | |
1079 | ||
1080 | #define IF_DRAIN(ifq) do { \ | |
1081 | struct mbuf *_m; \ | |
1082 | for (;;) { \ | |
1083 | IF_DEQUEUE(ifq, _m); \ | |
1084 | if (_m == NULL) \ | |
1085 | break; \ | |
1086 | m_freem(_m); \ | |
1087 | } \ | |
1088 | } while (0) | |
1089 | ||
1090 | /* | |
1091 | * The ifaddr structure contains information about one address | |
1092 | * of an interface. They are maintained by the different address families, | |
1093 | * are allocated and attached when an address is set, and are linked | |
1094 | * together so all addresses for an interface can be located. | |
1095 | */ | |
1096 | struct ifaddr { | |
1097 | decl_lck_mtx_data(, ifa_lock); /* lock for ifaddr */ | |
1098 | uint32_t ifa_refcnt; /* ref count, use IFA_{ADD,REM}REF */ | |
1099 | uint32_t ifa_debug; /* debug flags */ | |
1100 | struct sockaddr *ifa_addr; /* address of interface */ | |
1101 | struct sockaddr *ifa_dstaddr; /* other end of p-to-p link */ | |
1102 | #define ifa_broadaddr ifa_dstaddr /* broadcast address interface */ | |
1103 | struct sockaddr *ifa_netmask; /* used to determine subnet */ | |
1104 | struct ifnet *ifa_ifp; /* back-pointer to interface */ | |
1105 | TAILQ_ENTRY(ifaddr) ifa_link; /* queue macro glue */ | |
1106 | void (*ifa_rtrequest) /* check or clean routes (+ or -)'d */ | |
1107 | (int, struct rtentry *, struct sockaddr *); | |
1108 | uint32_t ifa_flags; /* mostly rt_flags for cloning */ | |
1109 | int32_t ifa_metric; /* cost of going out this interface */ | |
1110 | void (*ifa_free)(struct ifaddr *); /* callback fn for freeing */ | |
1111 | void (*ifa_trace) /* callback fn for tracing refs */ | |
1112 | (struct ifaddr *, int); | |
1113 | void (*ifa_attached)(struct ifaddr *); /* callback fn for attaching */ | |
1114 | void (*ifa_detached)(struct ifaddr *); /* callback fn for detaching */ | |
1115 | }; | |
1116 | ||
1117 | ||
1118 | /* | |
1119 | * Valid values for ifa_flags | |
1120 | */ | |
1121 | #define IFA_ROUTE RTF_UP /* route installed (0x1) */ | |
1122 | #define IFA_CLONING RTF_CLONING /* (0x100) */ | |
1123 | ||
1124 | /* | |
1125 | * Valid values for ifa_debug | |
1126 | */ | |
1127 | #define IFD_ATTACHED 0x1 /* attached to list */ | |
1128 | #define IFD_ALLOC 0x2 /* dynamically allocated */ | |
1129 | #define IFD_DEBUG 0x4 /* has debugging info */ | |
1130 | #define IFD_LINK 0x8 /* link address */ | |
1131 | #define IFD_TRASHED 0x10 /* in trash list */ | |
1132 | #define IFD_SKIP 0x20 /* skip this entry */ | |
1133 | #define IFD_NOTREADY 0x40 /* embryonic; not yet ready */ | |
1134 | ||
1135 | #define IFA_LOCK_ASSERT_HELD(_ifa) \ | |
1136 | lck_mtx_assert(&(_ifa)->ifa_lock, LCK_MTX_ASSERT_OWNED) | |
1137 | ||
1138 | #define IFA_LOCK_ASSERT_NOTHELD(_ifa) \ | |
1139 | lck_mtx_assert(&(_ifa)->ifa_lock, LCK_MTX_ASSERT_NOTOWNED) | |
1140 | ||
1141 | #define IFA_LOCK(_ifa) \ | |
1142 | lck_mtx_lock(&(_ifa)->ifa_lock) | |
1143 | ||
1144 | #define IFA_LOCK_SPIN(_ifa) \ | |
1145 | lck_mtx_lock_spin(&(_ifa)->ifa_lock) | |
1146 | ||
1147 | #define IFA_CONVERT_LOCK(_ifa) do { \ | |
1148 | IFA_LOCK_ASSERT_HELD(_ifa); \ | |
1149 | lck_mtx_convert_spin(&(_ifa)->ifa_lock); \ | |
1150 | } while (0) | |
1151 | ||
1152 | #define IFA_UNLOCK(_ifa) \ | |
1153 | lck_mtx_unlock(&(_ifa)->ifa_lock) | |
1154 | ||
1155 | #define IFA_ADDREF(_ifa) \ | |
1156 | ifa_addref(_ifa, 0) | |
1157 | ||
1158 | #define IFA_ADDREF_LOCKED(_ifa) \ | |
1159 | ifa_addref(_ifa, 1) | |
1160 | ||
1161 | #define IFA_REMREF(_ifa) do { \ | |
1162 | (void) ifa_remref(_ifa, 0); \ | |
1163 | } while (0) | |
1164 | ||
1165 | #define IFA_REMREF_LOCKED(_ifa) \ | |
1166 | ifa_remref(_ifa, 1) | |
1167 | ||
1168 | /* | |
1169 | * Multicast address structure. This is analogous to the ifaddr | |
1170 | * structure except that it keeps track of multicast addresses. | |
1171 | * Also, the request count here is a count of requests for this | |
1172 | * address, not a count of pointers to this structure; anonymous | |
1173 | * membership(s) holds one outstanding request count. | |
1174 | */ | |
1175 | struct ifmultiaddr { | |
1176 | decl_lck_mtx_data(, ifma_lock); | |
1177 | u_int32_t ifma_refcount; /* reference count */ | |
1178 | u_int32_t ifma_anoncnt; /* # of anonymous requests */ | |
1179 | u_int32_t ifma_reqcnt; /* total requests for this address */ | |
1180 | u_int32_t ifma_debug; /* see ifa_debug flags */ | |
1181 | u_int32_t ifma_flags; /* see below */ | |
1182 | LIST_ENTRY(ifmultiaddr) ifma_link; /* queue macro glue */ | |
1183 | struct sockaddr *ifma_addr; /* address this membership is for */ | |
1184 | struct ifmultiaddr *ifma_ll; /* link-layer translation, if any */ | |
1185 | struct ifnet *ifma_ifp; /* back-pointer to interface */ | |
1186 | void *ifma_protospec; /* protocol-specific state, if any */ | |
1187 | void (*ifma_trace) /* callback fn for tracing refs */ | |
1188 | (struct ifmultiaddr *, int); | |
1189 | }; | |
1190 | ||
1191 | /* | |
1192 | * Values for ifma_flags | |
1193 | */ | |
1194 | #define IFMAF_ANONYMOUS 0x1 /* has anonymous request ref(s) held */ | |
1195 | ||
1196 | #define IFMA_LOCK_ASSERT_HELD(_ifma) \ | |
1197 | lck_mtx_assert(&(_ifma)->ifma_lock, LCK_MTX_ASSERT_OWNED) | |
1198 | ||
1199 | #define IFMA_LOCK_ASSERT_NOTHELD(_ifma) \ | |
1200 | lck_mtx_assert(&(_ifma)->ifma_lock, LCK_MTX_ASSERT_NOTOWNED) | |
1201 | ||
1202 | #define IFMA_LOCK(_ifma) \ | |
1203 | lck_mtx_lock(&(_ifma)->ifma_lock) | |
1204 | ||
1205 | #define IFMA_LOCK_SPIN(_ifma) \ | |
1206 | lck_mtx_lock_spin(&(_ifma)->ifma_lock) | |
1207 | ||
1208 | #define IFMA_CONVERT_LOCK(_ifma) do { \ | |
1209 | IFMA_LOCK_ASSERT_HELD(_ifma); \ | |
1210 | lck_mtx_convert_spin(&(_ifma)->ifma_lock); \ | |
1211 | } while (0) | |
1212 | ||
1213 | #define IFMA_UNLOCK(_ifma) \ | |
1214 | lck_mtx_unlock(&(_ifma)->ifma_lock) | |
1215 | ||
1216 | #define IFMA_ADDREF(_ifma) \ | |
1217 | ifma_addref(_ifma, 0) | |
1218 | ||
1219 | #define IFMA_ADDREF_LOCKED(_ifma) \ | |
1220 | ifma_addref(_ifma, 1) | |
1221 | ||
1222 | #define IFMA_REMREF(_ifma) \ | |
1223 | ifma_remref(_ifma) | |
1224 | ||
1225 | /* | |
1226 | * Indicate whether or not the immediate interface, or the interface delegated | |
1227 | * by it, is a cellular interface (IFT_CELLULAR). Delegated interface type is | |
1228 | * set/cleared along with the delegated ifp; we cache the type for performance | |
1229 | * to avoid dereferencing delegated ifp each time. | |
1230 | * | |
1231 | * Note that this is meant to be used only for accounting and policy purposes; | |
1232 | * certain places need to explicitly know the immediate interface type, and | |
1233 | * this macro should not be used there. | |
1234 | * | |
1235 | * The test is done against IFT_CELLULAR instead of IFNET_FAMILY_CELLULAR to | |
1236 | * handle certain cases where the family isn't set to the latter. | |
1237 | */ | |
1238 | #define IFNET_IS_CELLULAR(_ifp) \ | |
1239 | ((_ifp)->if_type == IFT_CELLULAR || \ | |
1240 | (_ifp)->if_delegated.type == IFT_CELLULAR) | |
1241 | ||
1242 | /* | |
1243 | * Indicate whether or not the immediate interface, or the interface delegated | |
1244 | * by it, is an ETHERNET interface. | |
1245 | */ | |
1246 | #define IFNET_IS_ETHERNET(_ifp) \ | |
1247 | ((_ifp)->if_family == IFNET_FAMILY_ETHERNET || \ | |
1248 | (_ifp)->if_delegated.family == IFNET_FAMILY_ETHERNET) | |
1249 | /* | |
1250 | * Indicate whether or not the immediate interface, or the interface delegated | |
1251 | * by it, is a Wi-Fi interface (IFNET_SUBFAMILY_WIFI). Delegated interface | |
1252 | * subfamily is set/cleared along with the delegated ifp; we cache the subfamily | |
1253 | * for performance to avoid dereferencing delegated ifp each time. | |
1254 | * | |
1255 | * Note that this is meant to be used only for accounting and policy purposes; | |
1256 | * certain places need to explicitly know the immediate interface type, and | |
1257 | * this macro should not be used there. | |
1258 | * | |
1259 | * The test is done against IFNET_SUBFAMILY_WIFI as the family may be set to | |
1260 | * IFNET_FAMILY_ETHERNET (as well as type to IFT_ETHER) which is too generic. | |
1261 | */ | |
1262 | #define IFNET_IS_WIFI(_ifp) \ | |
1263 | ((_ifp)->if_subfamily == IFNET_SUBFAMILY_WIFI || \ | |
1264 | (_ifp)->if_delegated.subfamily == IFNET_SUBFAMILY_WIFI) | |
1265 | ||
1266 | /* | |
1267 | * Indicate whether or not the immediate interface, or the interface delegated | |
1268 | * by it, is a Wired interface (several families). Delegated interface | |
1269 | * family is set/cleared along with the delegated ifp; we cache the family | |
1270 | * for performance to avoid dereferencing delegated ifp each time. | |
1271 | * | |
1272 | * Note that this is meant to be used only for accounting and policy purposes; | |
1273 | * certain places need to explicitly know the immediate interface type, and | |
1274 | * this macro should not be used there. | |
1275 | */ | |
1276 | #define IFNET_IS_WIRED(_ifp) \ | |
1277 | ((_ifp)->if_family == IFNET_FAMILY_ETHERNET || \ | |
1278 | (_ifp)->if_delegated.family == IFNET_FAMILY_ETHERNET || \ | |
1279 | (_ifp)->if_family == IFNET_FAMILY_FIREWIRE || \ | |
1280 | (_ifp)->if_delegated.family == IFNET_FAMILY_FIREWIRE) | |
1281 | ||
1282 | /* | |
1283 | * Indicate whether or not the immediate WiFi interface is on an infrastructure | |
1284 | * network | |
1285 | */ | |
1286 | #define IFNET_IS_WIFI_INFRA(_ifp) \ | |
1287 | ((_ifp)->if_family == IFNET_FAMILY_ETHERNET && \ | |
1288 | (_ifp)->if_subfamily == IFNET_SUBFAMILY_WIFI && \ | |
1289 | !((_ifp)->if_eflags & IFEF_AWDL)) | |
1290 | ||
1291 | /* | |
1292 | * Indicate whether or not the immediate interface, or the interface delegated | |
1293 | * by it, is marked as expensive. The delegated interface is set/cleared | |
1294 | * along with the delegated ifp; we cache the flag for performance to avoid | |
1295 | * dereferencing delegated ifp each time. | |
1296 | * | |
1297 | * Note that this is meant to be used only for policy purposes. | |
1298 | */ | |
1299 | #define IFNET_IS_EXPENSIVE(_ifp) \ | |
1300 | ((_ifp)->if_eflags & IFEF_EXPENSIVE || \ | |
1301 | (_ifp)->if_delegated.expensive) | |
1302 | ||
1303 | /* | |
1304 | * We don't support AWDL interface delegation. | |
1305 | */ | |
1306 | #define IFNET_IS_AWDL_RESTRICTED(_ifp) \ | |
1307 | (((_ifp)->if_eflags & (IFEF_AWDL|IFEF_AWDL_RESTRICTED)) == \ | |
1308 | (IFEF_AWDL|IFEF_AWDL_RESTRICTED)) | |
1309 | ||
1310 | #define IFNET_IS_INTCOPROC(_ifp) \ | |
1311 | ((_ifp)->if_family == IFNET_FAMILY_ETHERNET && \ | |
1312 | (_ifp)->if_subfamily == IFNET_SUBFAMILY_INTCOPROC) | |
1313 | ||
1314 | extern struct ifnethead ifnet_head; | |
1315 | extern struct ifnethead ifnet_ordered_head; | |
1316 | extern struct ifnet **ifindex2ifnet; | |
1317 | extern u_int32_t if_sndq_maxlen; | |
1318 | extern u_int32_t if_rcvq_maxlen; | |
1319 | extern int if_index; | |
1320 | extern struct ifaddr **ifnet_addrs; | |
1321 | extern lck_attr_t *ifa_mtx_attr; | |
1322 | extern lck_grp_t *ifa_mtx_grp; | |
1323 | extern lck_grp_t *ifnet_lock_group; | |
1324 | extern lck_attr_t *ifnet_lock_attr; | |
1325 | extern ifnet_t lo_ifp; | |
1326 | extern uint32_t if_bw_measure_size; | |
1327 | extern u_int32_t if_bw_smoothing_val; | |
1328 | ||
1329 | extern int if_addmulti(struct ifnet *, const struct sockaddr *, | |
1330 | struct ifmultiaddr **); | |
1331 | extern int if_addmulti_anon(struct ifnet *, const struct sockaddr *, | |
1332 | struct ifmultiaddr **); | |
1333 | extern int if_allmulti(struct ifnet *, int); | |
1334 | extern int if_delmulti(struct ifnet *, const struct sockaddr *); | |
1335 | extern int if_delmulti_ifma(struct ifmultiaddr *); | |
1336 | extern int if_delmulti_anon(struct ifnet *, const struct sockaddr *); | |
1337 | extern void if_down(struct ifnet *); | |
1338 | extern int if_down_all(void); | |
1339 | extern void if_up(struct ifnet *); | |
1340 | __private_extern__ void if_updown(struct ifnet *ifp, int up); | |
1341 | extern int ifioctl(struct socket *, u_long, caddr_t, struct proc *); | |
1342 | extern int ifioctllocked(struct socket *, u_long, caddr_t, struct proc *); | |
1343 | extern struct ifnet *ifunit(const char *); | |
1344 | extern struct ifnet *ifunit_ref(const char *); | |
1345 | extern int ifunit_extract(const char *src, char *dst, size_t dstlen, int *unit); | |
1346 | extern struct ifnet *if_withname(struct sockaddr *); | |
1347 | extern void if_qflush(struct ifnet *, int); | |
1348 | extern void if_qflush_sc(struct ifnet *, mbuf_svc_class_t, u_int32_t, | |
1349 | u_int32_t *, u_int32_t *, int); | |
1350 | ||
1351 | extern struct if_clone *if_clone_lookup(const char *, u_int32_t *); | |
1352 | extern int if_clone_attach(struct if_clone *); | |
1353 | extern void if_clone_detach(struct if_clone *); | |
1354 | ||
1355 | extern u_int32_t if_functional_type(struct ifnet *, bool); | |
1356 | ||
1357 | extern errno_t if_mcasts_update(struct ifnet *); | |
1358 | ||
1359 | typedef enum { | |
1360 | IFNET_LCK_ASSERT_EXCLUSIVE, /* RW: held as writer */ | |
1361 | IFNET_LCK_ASSERT_SHARED, /* RW: held as reader */ | |
1362 | IFNET_LCK_ASSERT_OWNED, /* RW: writer/reader, MTX: held */ | |
1363 | IFNET_LCK_ASSERT_NOTOWNED /* not held */ | |
1364 | } ifnet_lock_assert_t; | |
1365 | ||
1366 | #define IF_LLADDR(_ifp) \ | |
1367 | (LLADDR(SDL(((_ifp)->if_lladdr)->ifa_addr))) | |
1368 | ||
1369 | __private_extern__ void ifnet_lock_assert(struct ifnet *, ifnet_lock_assert_t); | |
1370 | __private_extern__ void ifnet_lock_shared(struct ifnet *ifp); | |
1371 | __private_extern__ void ifnet_lock_exclusive(struct ifnet *ifp); | |
1372 | __private_extern__ void ifnet_lock_done(struct ifnet *ifp); | |
1373 | ||
1374 | #if INET | |
1375 | __private_extern__ void if_inetdata_lock_shared(struct ifnet *ifp); | |
1376 | __private_extern__ void if_inetdata_lock_exclusive(struct ifnet *ifp); | |
1377 | __private_extern__ void if_inetdata_lock_done(struct ifnet *ifp); | |
1378 | #endif | |
1379 | ||
1380 | #if INET6 | |
1381 | __private_extern__ void if_inet6data_lock_shared(struct ifnet *ifp); | |
1382 | __private_extern__ void if_inet6data_lock_exclusive(struct ifnet *ifp); | |
1383 | __private_extern__ void if_inet6data_lock_done(struct ifnet *ifp); | |
1384 | #endif | |
1385 | ||
1386 | __private_extern__ void ifnet_head_lock_shared(void); | |
1387 | __private_extern__ void ifnet_head_lock_exclusive(void); | |
1388 | __private_extern__ void ifnet_head_done(void); | |
1389 | __private_extern__ void ifnet_head_assert_exclusive(void); | |
1390 | ||
1391 | __private_extern__ errno_t ifnet_set_idle_flags_locked(ifnet_t, u_int32_t, | |
1392 | u_int32_t); | |
1393 | __private_extern__ int ifnet_is_attached(struct ifnet *, int refio); | |
1394 | __private_extern__ void ifnet_incr_iorefcnt(struct ifnet *); | |
1395 | __private_extern__ void ifnet_decr_iorefcnt(struct ifnet *); | |
1396 | __private_extern__ void ifnet_set_start_cycle(struct ifnet *, | |
1397 | struct timespec *); | |
1398 | __private_extern__ void ifnet_set_poll_cycle(struct ifnet *, | |
1399 | struct timespec *); | |
1400 | ||
1401 | __private_extern__ void if_attach_ifa(struct ifnet *, struct ifaddr *); | |
1402 | __private_extern__ void if_attach_link_ifa(struct ifnet *, struct ifaddr *); | |
1403 | __private_extern__ void if_detach_ifa(struct ifnet *, struct ifaddr *); | |
1404 | __private_extern__ void if_detach_link_ifa(struct ifnet *, struct ifaddr *); | |
1405 | ||
1406 | __private_extern__ void dlil_if_lock(void); | |
1407 | __private_extern__ void dlil_if_unlock(void); | |
1408 | __private_extern__ void dlil_if_lock_assert(void); | |
1409 | ||
1410 | extern struct ifaddr *ifa_ifwithaddr(const struct sockaddr *); | |
1411 | extern struct ifaddr *ifa_ifwithaddr_locked(const struct sockaddr *); | |
1412 | extern struct ifaddr *ifa_ifwithaddr_scoped(const struct sockaddr *, | |
1413 | unsigned int); | |
1414 | extern struct ifaddr *ifa_ifwithaddr_scoped_locked(const struct sockaddr *, | |
1415 | unsigned int); | |
1416 | extern struct ifaddr *ifa_ifwithdstaddr(const struct sockaddr *); | |
1417 | extern struct ifaddr *ifa_ifwithnet(const struct sockaddr *); | |
1418 | extern struct ifaddr *ifa_ifwithnet_scoped(const struct sockaddr *, | |
1419 | unsigned int); | |
1420 | extern struct ifaddr *ifa_ifwithroute(int, const struct sockaddr *, | |
1421 | const struct sockaddr *); | |
1422 | extern struct ifaddr *ifa_ifwithroute_locked(int, const struct sockaddr *, | |
1423 | const struct sockaddr *); | |
1424 | extern struct ifaddr *ifa_ifwithroute_scoped_locked(int, | |
1425 | const struct sockaddr *, const struct sockaddr *, unsigned int); | |
1426 | extern struct ifaddr *ifaof_ifpforaddr(const struct sockaddr *, struct ifnet *); | |
1427 | __private_extern__ struct ifaddr *ifa_ifpgetprimary(struct ifnet *, int); | |
1428 | extern void ifa_addref(struct ifaddr *, int); | |
1429 | extern struct ifaddr *ifa_remref(struct ifaddr *, int); | |
1430 | extern void ifa_lock_init(struct ifaddr *); | |
1431 | extern void ifa_lock_destroy(struct ifaddr *); | |
1432 | extern void ifma_addref(struct ifmultiaddr *, int); | |
1433 | extern void ifma_remref(struct ifmultiaddr *); | |
1434 | ||
1435 | extern void ifa_init(void); | |
1436 | ||
1437 | __private_extern__ struct in_ifaddr *ifa_foraddr(unsigned int); | |
1438 | __private_extern__ struct in_ifaddr *ifa_foraddr_scoped(unsigned int, | |
1439 | unsigned int); | |
1440 | ||
1441 | struct ifreq; | |
1442 | extern errno_t ifnet_getset_opportunistic(struct ifnet *, u_long, | |
1443 | struct ifreq *, struct proc *); | |
1444 | extern int ifnet_get_throttle(struct ifnet *, u_int32_t *); | |
1445 | extern int ifnet_set_throttle(struct ifnet *, u_int32_t); | |
1446 | extern errno_t ifnet_getset_log(struct ifnet *, u_long, | |
1447 | struct ifreq *, struct proc *); | |
1448 | extern int ifnet_set_log(struct ifnet *, int32_t, uint32_t, int32_t, int32_t); | |
1449 | extern int ifnet_get_log(struct ifnet *, int32_t *, uint32_t *, int32_t *, | |
1450 | int32_t *); | |
1451 | extern int ifnet_notify_address(struct ifnet *, int); | |
1452 | ||
1453 | #if INET6 | |
1454 | struct in6_addr; | |
1455 | __private_extern__ struct in6_ifaddr *ifa_foraddr6(struct in6_addr *); | |
1456 | __private_extern__ struct in6_ifaddr *ifa_foraddr6_scoped(struct in6_addr *, | |
1457 | unsigned int); | |
1458 | #endif /* INET6 */ | |
1459 | ||
1460 | __private_extern__ void if_data_internal_to_if_data(struct ifnet *ifp, | |
1461 | const struct if_data_internal *if_data_int, struct if_data *if_data); | |
1462 | __private_extern__ void if_data_internal_to_if_data64(struct ifnet *ifp, | |
1463 | const struct if_data_internal *if_data_int, struct if_data64 *if_data64); | |
1464 | __private_extern__ void if_copy_traffic_class(struct ifnet *ifp, | |
1465 | struct if_traffic_class *if_tc); | |
1466 | __private_extern__ void if_copy_data_extended(struct ifnet *ifp, | |
1467 | struct if_data_extended *if_de); | |
1468 | __private_extern__ void if_copy_packet_stats(struct ifnet *ifp, | |
1469 | struct if_packet_stats *if_ps); | |
1470 | __private_extern__ void if_copy_rxpoll_stats(struct ifnet *ifp, | |
1471 | struct if_rxpoll_stats *if_rs); | |
1472 | ||
1473 | __private_extern__ struct rtentry *ifnet_cached_rtlookup_inet(struct ifnet *, | |
1474 | struct in_addr); | |
1475 | #if INET6 | |
1476 | __private_extern__ struct rtentry *ifnet_cached_rtlookup_inet6(struct ifnet *, | |
1477 | struct in6_addr *); | |
1478 | #endif /* INET6 */ | |
1479 | ||
1480 | __private_extern__ errno_t if_state_update(struct ifnet *, | |
1481 | struct if_interface_state *); | |
1482 | __private_extern__ void if_get_state(struct ifnet *, | |
1483 | struct if_interface_state *); | |
1484 | __private_extern__ errno_t if_probe_connectivity(struct ifnet *ifp, | |
1485 | u_int32_t conn_probe); | |
1486 | __private_extern__ void if_lqm_update(struct ifnet *, int32_t, int); | |
1487 | __private_extern__ void ifnet_update_sndq(struct ifclassq *, cqev_t); | |
1488 | __private_extern__ void ifnet_update_rcv(struct ifnet *, cqev_t); | |
1489 | ||
1490 | __private_extern__ void ifnet_flowadv(uint32_t); | |
1491 | ||
1492 | __private_extern__ errno_t ifnet_set_input_bandwidths(struct ifnet *, | |
1493 | struct if_bandwidths *); | |
1494 | __private_extern__ errno_t ifnet_set_output_bandwidths(struct ifnet *, | |
1495 | struct if_bandwidths *, boolean_t); | |
1496 | __private_extern__ u_int64_t ifnet_output_linkrate(struct ifnet *); | |
1497 | __private_extern__ u_int64_t ifnet_input_linkrate(struct ifnet *); | |
1498 | ||
1499 | __private_extern__ errno_t ifnet_set_input_latencies(struct ifnet *, | |
1500 | struct if_latencies *); | |
1501 | __private_extern__ errno_t ifnet_set_output_latencies(struct ifnet *, | |
1502 | struct if_latencies *, boolean_t); | |
1503 | ||
1504 | __private_extern__ void ifnet_clear_netagent(uuid_t); | |
1505 | ||
1506 | __private_extern__ int ifnet_set_netsignature(struct ifnet *, uint8_t, | |
1507 | uint8_t, uint16_t, uint8_t *); | |
1508 | __private_extern__ int ifnet_get_netsignature(struct ifnet *, uint8_t, | |
1509 | uint8_t *, uint16_t *, uint8_t *); | |
1510 | ||
1511 | /* Required exclusive ifnet_head lock */ | |
1512 | __private_extern__ void ifnet_remove_from_ordered_list(struct ifnet *); | |
1513 | ||
1514 | __private_extern__ void ifnet_increment_generation(struct ifnet *); | |
1515 | __private_extern__ u_int32_t ifnet_get_generation(struct ifnet *); | |
1516 | ||
1517 | extern int if_set_qosmarking_mode(struct ifnet *, u_int32_t); | |
1518 | ||
1519 | __private_extern__ errno_t ifnet_framer_stub(struct ifnet *, struct mbuf **, | |
1520 | const struct sockaddr *, const char *, const char *, u_int32_t *, | |
1521 | u_int32_t *); | |
1522 | #endif /* BSD_KERNEL_PRIVATE */ | |
1523 | #ifdef XNU_KERNEL_PRIVATE | |
1524 | /* for uuid.c */ | |
1525 | __private_extern__ int uuid_get_ethernet(u_int8_t *); | |
1526 | #endif /* XNU_KERNEL_PRIVATE */ | |
1527 | #endif /* !_NET_IF_VAR_H_ */ |