]>
Commit | Line | Data |
---|---|---|
1c79356b | 1 | /* |
5ba3f43e | 2 | * Copyright (c) 2000-2017 Apple Inc. All rights reserved. |
5d5c5d0d | 3 | * |
2d21ac55 | 4 | * @APPLE_OSREFERENCE_LICENSE_HEADER_START@ |
39236c6e | 5 | * |
2d21ac55 A |
6 | * This file contains Original Code and/or Modifications of Original Code |
7 | * as defined in and that are subject to the Apple Public Source License | |
8 | * Version 2.0 (the 'License'). You may not use this file except in | |
9 | * compliance with the License. The rights granted to you under the License | |
10 | * may not be used to create, or enable the creation or redistribution of, | |
11 | * unlawful or unlicensed copies of an Apple operating system, or to | |
12 | * circumvent, violate, or enable the circumvention or violation of, any | |
13 | * terms of an Apple operating system software license agreement. | |
39236c6e | 14 | * |
2d21ac55 A |
15 | * Please obtain a copy of the License at |
16 | * http://www.opensource.apple.com/apsl/ and read it before using this file. | |
39236c6e | 17 | * |
2d21ac55 A |
18 | * The Original Code and all software distributed under the License are |
19 | * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER | |
8f6c56a5 A |
20 | * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, |
21 | * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, | |
2d21ac55 A |
22 | * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. |
23 | * Please see the License for the specific language governing rights and | |
24 | * limitations under the License. | |
39236c6e | 25 | * |
2d21ac55 | 26 | * @APPLE_OSREFERENCE_LICENSE_HEADER_END@ |
1c79356b A |
27 | */ |
28 | /* | |
29 | * Copyright (c) 1982, 1986, 1989, 1993 | |
30 | * The Regents of the University of California. All rights reserved. | |
31 | * | |
32 | * Redistribution and use in source and binary forms, with or without | |
33 | * modification, are permitted provided that the following conditions | |
34 | * are met: | |
35 | * 1. Redistributions of source code must retain the above copyright | |
36 | * notice, this list of conditions and the following disclaimer. | |
37 | * 2. Redistributions in binary form must reproduce the above copyright | |
38 | * notice, this list of conditions and the following disclaimer in the | |
39 | * documentation and/or other materials provided with the distribution. | |
40 | * 3. All advertising materials mentioning features or use of this software | |
41 | * must display the following acknowledgement: | |
42 | * This product includes software developed by the University of | |
43 | * California, Berkeley and its contributors. | |
44 | * 4. Neither the name of the University nor the names of its contributors | |
45 | * may be used to endorse or promote products derived from this software | |
46 | * without specific prior written permission. | |
47 | * | |
48 | * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND | |
49 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | |
50 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | |
51 | * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE | |
52 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | |
53 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | |
54 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | |
55 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | |
56 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | |
57 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | |
58 | * SUCH DAMAGE. | |
59 | * | |
60 | * From: @(#)if.h 8.1 (Berkeley) 6/10/93 | |
9bccf70c | 61 | * $FreeBSD: src/sys/net/if_var.h,v 1.18.2.7 2001/07/24 19:10:18 brooks Exp $ |
1c79356b A |
62 | */ |
63 | ||
64 | #ifndef _NET_IF_VAR_H_ | |
65 | #define _NET_IF_VAR_H_ | |
91447636 | 66 | |
9bccf70c | 67 | #include <sys/appleapiopts.h> |
b0d623f7 | 68 | #include <stdint.h> |
91447636 A |
69 | #include <sys/types.h> |
70 | #include <sys/time.h> | |
71 | #include <sys/queue.h> /* get TAILQ macros */ | |
72 | #ifdef KERNEL_PRIVATE | |
73 | #include <kern/locks.h> | |
74 | #endif /* KERNEL_PRIVATE */ | |
b0d623f7 A |
75 | #ifdef PRIVATE |
76 | #include <net/route.h> | |
77 | #endif | |
5ba3f43e A |
78 | #ifdef BSD_KERN_PRIVATE |
79 | #include <sys/eventhandler.h> | |
80 | #endif | |
91447636 A |
81 | |
82 | #ifdef KERNEL | |
83 | #include <net/kpi_interface.h> | |
b0d623f7 | 84 | #endif /* KERNEL */ |
1c79356b | 85 | |
9bccf70c | 86 | #ifdef __APPLE__ |
1c79356b A |
87 | #define APPLE_IF_FAM_LOOPBACK 1 |
88 | #define APPLE_IF_FAM_ETHERNET 2 | |
89 | #define APPLE_IF_FAM_SLIP 3 | |
90 | #define APPLE_IF_FAM_TUN 4 | |
91 | #define APPLE_IF_FAM_VLAN 5 | |
92 | #define APPLE_IF_FAM_PPP 6 | |
93 | #define APPLE_IF_FAM_PVC 7 | |
94 | #define APPLE_IF_FAM_DISC 8 | |
95 | #define APPLE_IF_FAM_MDECAP 9 | |
96 | #define APPLE_IF_FAM_GIF 10 | |
316670eb | 97 | #define APPLE_IF_FAM_FAITH 11 /* deprecated */ |
55e303ae A |
98 | #define APPLE_IF_FAM_STF 12 |
99 | #define APPLE_IF_FAM_FIREWIRE 13 | |
91447636 | 100 | #define APPLE_IF_FAM_BOND 14 |
0c530ab8 | 101 | #endif /* __APPLE__ */ |
91447636 A |
102 | |
103 | /* | |
104 | * 72 was chosen below because it is the size of a TCP/IP | |
105 | * header (40) + the minimum mss (32). | |
106 | */ | |
107 | #define IF_MINMTU 72 | |
108 | #define IF_MAXMTU 65535 | |
1c79356b A |
109 | |
110 | /* | |
111 | * Structures defining a network interface, providing a packet | |
112 | * transport mechanism (ala level 0 of the PUP protocols). | |
113 | * | |
114 | * Each interface accepts output datagrams of a specified maximum | |
115 | * length, and provides higher level routines with input datagrams | |
116 | * received from its medium. | |
117 | * | |
118 | * Output occurs when the routine if_output is called, with three parameters: | |
119 | * (*ifp->if_output)(ifp, m, dst, rt) | |
120 | * Here m is the mbuf chain to be sent and dst is the destination address. | |
121 | * The output routine encapsulates the supplied datagram if necessary, | |
122 | * and then transmits it on its medium. | |
123 | * | |
124 | * On input, each interface unwraps the data received by it, and either | |
125 | * places it on the input queue of a internetwork datagram routine | |
126 | * and posts the associated software interrupt, or passes the datagram to a raw | |
127 | * packet input routine. | |
128 | * | |
129 | * Routines exist for locating interfaces by their addresses | |
130 | * or for locating a interface on a certain network, as well as more general | |
131 | * routing and gateway routines maintaining information used to locate | |
132 | * interfaces. These routines live in the files if.c and route.c | |
133 | */ | |
134 | ||
1c79356b A |
135 | #define IFNAMSIZ 16 |
136 | ||
1c79356b A |
137 | /* This belongs up in socket.h or socketvar.h, depending on how far the |
138 | * event bubbles up. | |
139 | */ | |
140 | ||
141 | struct net_event_data { | |
2d21ac55 A |
142 | u_int32_t if_family; |
143 | u_int32_t if_unit; | |
144 | char if_name[IFNAMSIZ]; | |
1c79356b | 145 | }; |
1c79356b | 146 | |
2d21ac55 | 147 | #if defined(__LP64__) |
39236c6e | 148 | #include <sys/_types/_timeval32.h> |
2d21ac55 A |
149 | #define IF_DATA_TIMEVAL timeval32 |
150 | #else | |
151 | #define IF_DATA_TIMEVAL timeval | |
152 | #endif | |
153 | ||
154 | #pragma pack(4) | |
155 | ||
91447636 A |
156 | /* |
157 | * Structure describing information about an interface | |
158 | * which may be of interest to management entities. | |
159 | */ | |
160 | struct if_data { | |
161 | /* generic interface information */ | |
2d21ac55 A |
162 | u_char ifi_type; /* ethernet, tokenring, etc */ |
163 | u_char ifi_typelen; /* Length of frame type id */ | |
164 | u_char ifi_physical; /* e.g., AUI, Thinnet, 10base-T, etc */ | |
165 | u_char ifi_addrlen; /* media address length */ | |
166 | u_char ifi_hdrlen; /* media header length */ | |
167 | u_char ifi_recvquota; /* polling quota for receive intrs */ | |
168 | u_char ifi_xmitquota; /* polling quota for xmit intrs */ | |
169 | u_char ifi_unused1; /* for future use */ | |
170 | u_int32_t ifi_mtu; /* maximum transmission unit */ | |
171 | u_int32_t ifi_metric; /* routing metric (external only) */ | |
172 | u_int32_t ifi_baudrate; /* linespeed */ | |
91447636 | 173 | /* volatile statistics */ |
2d21ac55 A |
174 | u_int32_t ifi_ipackets; /* packets received on interface */ |
175 | u_int32_t ifi_ierrors; /* input errors on interface */ | |
176 | u_int32_t ifi_opackets; /* packets sent on interface */ | |
177 | u_int32_t ifi_oerrors; /* output errors on interface */ | |
178 | u_int32_t ifi_collisions; /* collisions on csma interfaces */ | |
179 | u_int32_t ifi_ibytes; /* total number of octets received */ | |
180 | u_int32_t ifi_obytes; /* total number of octets sent */ | |
181 | u_int32_t ifi_imcasts; /* packets received via multicast */ | |
182 | u_int32_t ifi_omcasts; /* packets sent via multicast */ | |
183 | u_int32_t ifi_iqdrops; /* dropped on input, this interface */ | |
184 | u_int32_t ifi_noproto; /* destined for unsupported protocol */ | |
185 | u_int32_t ifi_recvtiming; /* usec spent receiving when timing */ | |
186 | u_int32_t ifi_xmittiming; /* usec spent xmitting when timing */ | |
187 | struct IF_DATA_TIMEVAL ifi_lastchange; /* time of last administrative change */ | |
188 | u_int32_t ifi_unused2; /* used to be the default_proto */ | |
189 | u_int32_t ifi_hwassist; /* HW offload capabilities */ | |
190 | u_int32_t ifi_reserved1; /* for future use */ | |
191 | u_int32_t ifi_reserved2; /* for future use */ | |
91447636 | 192 | }; |
4a249263 | 193 | |
1c79356b A |
194 | /* |
195 | * Structure describing information about an interface | |
196 | * which may be of interest to management entities. | |
197 | */ | |
91447636 | 198 | struct if_data64 { |
1c79356b | 199 | /* generic interface information */ |
2d21ac55 A |
200 | u_char ifi_type; /* ethernet, tokenring, etc */ |
201 | u_char ifi_typelen; /* Length of frame type id */ | |
91447636 A |
202 | u_char ifi_physical; /* e.g., AUI, Thinnet, 10base-T, etc */ |
203 | u_char ifi_addrlen; /* media address length */ | |
204 | u_char ifi_hdrlen; /* media header length */ | |
205 | u_char ifi_recvquota; /* polling quota for receive intrs */ | |
206 | u_char ifi_xmitquota; /* polling quota for xmit intrs */ | |
207 | u_char ifi_unused1; /* for future use */ | |
2d21ac55 A |
208 | u_int32_t ifi_mtu; /* maximum transmission unit */ |
209 | u_int32_t ifi_metric; /* routing metric (external only) */ | |
91447636 A |
210 | u_int64_t ifi_baudrate; /* linespeed */ |
211 | /* volatile statistics */ | |
212 | u_int64_t ifi_ipackets; /* packets received on interface */ | |
213 | u_int64_t ifi_ierrors; /* input errors on interface */ | |
214 | u_int64_t ifi_opackets; /* packets sent on interface */ | |
215 | u_int64_t ifi_oerrors; /* output errors on interface */ | |
216 | u_int64_t ifi_collisions; /* collisions on csma interfaces */ | |
217 | u_int64_t ifi_ibytes; /* total number of octets received */ | |
218 | u_int64_t ifi_obytes; /* total number of octets sent */ | |
219 | u_int64_t ifi_imcasts; /* packets received via multicast */ | |
220 | u_int64_t ifi_omcasts; /* packets sent via multicast */ | |
221 | u_int64_t ifi_iqdrops; /* dropped on input, this interface */ | |
222 | u_int64_t ifi_noproto; /* destined for unsupported protocol */ | |
2d21ac55 A |
223 | u_int32_t ifi_recvtiming; /* usec spent receiving when timing */ |
224 | u_int32_t ifi_xmittiming; /* usec spent xmitting when timing */ | |
225 | struct IF_DATA_TIMEVAL ifi_lastchange; /* time of last administrative change */ | |
91447636 A |
226 | }; |
227 | ||
228 | #ifdef PRIVATE | |
d41d1dae | 229 | struct if_traffic_class { |
316670eb A |
230 | u_int64_t ifi_ibepackets; /* TC_BE packets received on interface */ |
231 | u_int64_t ifi_ibebytes; /* TC_BE bytes received on interface */ | |
232 | u_int64_t ifi_obepackets; /* TC_BE packet sent on interface */ | |
233 | u_int64_t ifi_obebytes; /* TC_BE bytes sent on interface */ | |
d41d1dae A |
234 | u_int64_t ifi_ibkpackets; /* TC_BK packets received on interface */ |
235 | u_int64_t ifi_ibkbytes; /* TC_BK bytes received on interface */ | |
236 | u_int64_t ifi_obkpackets; /* TC_BK packet sent on interface */ | |
237 | u_int64_t ifi_obkbytes; /* TC_BK bytes sent on interface */ | |
238 | u_int64_t ifi_ivipackets; /* TC_VI packets received on interface */ | |
239 | u_int64_t ifi_ivibytes; /* TC_VI bytes received on interface */ | |
240 | u_int64_t ifi_ovipackets; /* TC_VI packets sent on interface */ | |
241 | u_int64_t ifi_ovibytes; /* TC_VI bytes sent on interface */ | |
242 | u_int64_t ifi_ivopackets; /* TC_VO packets received on interface */ | |
243 | u_int64_t ifi_ivobytes; /* TC_VO bytes received on interface */ | |
244 | u_int64_t ifi_ovopackets; /* TC_VO packets sent on interface */ | |
245 | u_int64_t ifi_ovobytes; /* TC_VO bytes sent on interface */ | |
316670eb A |
246 | u_int64_t ifi_ipvpackets; /* TC priv packets received on interface */ |
247 | u_int64_t ifi_ipvbytes; /* TC priv bytes received on interface */ | |
248 | u_int64_t ifi_opvpackets; /* TC priv packets sent on interface */ | |
249 | u_int64_t ifi_opvbytes; /* TC priv bytes sent on interface */ | |
250 | }; | |
251 | ||
252 | struct if_data_extended { | |
253 | u_int64_t ifi_alignerrs; /* unaligned (32-bit) input pkts */ | |
39236c6e A |
254 | u_int64_t ifi_dt_bytes; /* Data threshold counter */ |
255 | u_int64_t ifi_fpackets; /* forwarded packets on interface */ | |
256 | u_int64_t ifi_fbytes; /* forwarded bytes on interface */ | |
257 | u_int64_t reserved[12]; /* for future */ | |
316670eb A |
258 | }; |
259 | ||
260 | struct if_packet_stats { | |
261 | /* TCP */ | |
262 | u_int64_t ifi_tcp_badformat; | |
263 | u_int64_t ifi_tcp_unspecv6; | |
264 | u_int64_t ifi_tcp_synfin; | |
265 | u_int64_t ifi_tcp_badformatipsec; | |
266 | u_int64_t ifi_tcp_noconnnolist; | |
267 | u_int64_t ifi_tcp_noconnlist; | |
268 | u_int64_t ifi_tcp_listbadsyn; | |
269 | u_int64_t ifi_tcp_icmp6unreach; | |
270 | u_int64_t ifi_tcp_deprecate6; | |
271 | u_int64_t ifi_tcp_rstinsynrcv; | |
272 | u_int64_t ifi_tcp_ooopacket; | |
273 | u_int64_t ifi_tcp_dospacket; | |
274 | u_int64_t ifi_tcp_cleanup; | |
275 | u_int64_t ifi_tcp_synwindow; | |
39236c6e | 276 | u_int64_t reserved[6]; |
316670eb A |
277 | /* UDP */ |
278 | u_int64_t ifi_udp_port_unreach; | |
279 | u_int64_t ifi_udp_faithprefix; | |
280 | u_int64_t ifi_udp_port0; | |
281 | u_int64_t ifi_udp_badlength; | |
282 | u_int64_t ifi_udp_badchksum; | |
283 | u_int64_t ifi_udp_badmcast; | |
284 | u_int64_t ifi_udp_cleanup; | |
285 | u_int64_t ifi_udp_badipsec; | |
39236c6e | 286 | u_int64_t _reserved[4]; |
316670eb A |
287 | }; |
288 | ||
289 | struct if_description { | |
290 | u_int32_t ifd_maxlen; /* must be IF_DESCSIZE */ | |
291 | u_int32_t ifd_len; /* actual ifd_desc length */ | |
292 | u_int8_t *ifd_desc; /* ptr to desc buffer */ | |
293 | }; | |
294 | ||
295 | struct if_bandwidths { | |
296 | u_int64_t eff_bw; /* effective bandwidth */ | |
297 | u_int64_t max_bw; /* maximum theoretical bandwidth */ | |
298 | }; | |
299 | ||
39236c6e A |
300 | struct if_latencies { |
301 | u_int64_t eff_lt; /* effective latency */ | |
302 | u_int64_t max_lt; /* maximum theoretical latency */ | |
303 | }; | |
304 | ||
316670eb A |
305 | struct if_rxpoll_stats { |
306 | u_int32_t ifi_poll_off_req; /* total # of POLL_OFF reqs */ | |
307 | u_int32_t ifi_poll_off_err; /* total # of POLL_OFF errors */ | |
308 | u_int32_t ifi_poll_on_req; /* total # of POLL_ON reqs */ | |
309 | u_int32_t ifi_poll_on_err; /* total # of POLL_ON errors */ | |
310 | ||
311 | u_int32_t ifi_poll_wakeups_avg; /* avg # of wakeup reqs */ | |
312 | u_int32_t ifi_poll_wakeups_lowat; /* wakeups low watermark */ | |
313 | u_int32_t ifi_poll_wakeups_hiwat; /* wakeups high watermark */ | |
314 | ||
315 | u_int64_t ifi_poll_packets; /* total # of polled packets */ | |
316 | u_int32_t ifi_poll_packets_avg; /* average polled packets */ | |
317 | u_int32_t ifi_poll_packets_min; /* smallest polled packets */ | |
318 | u_int32_t ifi_poll_packets_max; /* largest polled packets */ | |
319 | u_int32_t ifi_poll_packets_lowat; /* packets low watermark */ | |
320 | u_int32_t ifi_poll_packets_hiwat; /* packets high watermark */ | |
321 | ||
322 | u_int64_t ifi_poll_bytes; /* total # of polled bytes */ | |
323 | u_int32_t ifi_poll_bytes_avg; /* average polled bytes */ | |
324 | u_int32_t ifi_poll_bytes_min; /* smallest polled bytes */ | |
325 | u_int32_t ifi_poll_bytes_max; /* largest polled bytes */ | |
326 | u_int32_t ifi_poll_bytes_lowat; /* bytes low watermark */ | |
327 | u_int32_t ifi_poll_bytes_hiwat; /* bytes high watermark */ | |
39236c6e A |
328 | |
329 | u_int32_t ifi_poll_packets_limit; /* max packets per poll call */ | |
330 | u_int64_t ifi_poll_interval_time; /* poll interval (nsec) */ | |
d41d1dae | 331 | }; |
3e170ce0 | 332 | |
4bd07ac2 | 333 | struct if_tcp_ecn_perf_stat { |
490019cf A |
334 | u_int64_t total_txpkts; |
335 | u_int64_t total_rxmitpkts; | |
336 | u_int64_t total_rxpkts; | |
337 | u_int64_t total_oopkts; | |
338 | u_int64_t total_reorderpkts; | |
4bd07ac2 A |
339 | u_int64_t rtt_avg; |
340 | u_int64_t rtt_var; | |
4bd07ac2 | 341 | u_int64_t sack_episodes; |
490019cf A |
342 | u_int64_t rxmit_drop; |
343 | u_int64_t rst_drop; | |
344 | u_int64_t oo_percent; | |
4bd07ac2 A |
345 | u_int64_t reorder_percent; |
346 | u_int64_t rxmit_percent; | |
4bd07ac2 A |
347 | }; |
348 | ||
349 | struct if_tcp_ecn_stat { | |
350 | u_int64_t timestamp; | |
351 | u_int64_t ecn_client_setup; | |
352 | u_int64_t ecn_server_setup; | |
353 | u_int64_t ecn_client_success; | |
354 | u_int64_t ecn_server_success; | |
355 | u_int64_t ecn_peer_nosupport; | |
356 | u_int64_t ecn_syn_lost; | |
357 | u_int64_t ecn_synack_lost; | |
358 | u_int64_t ecn_recv_ce; | |
359 | u_int64_t ecn_recv_ece; | |
360 | u_int64_t ecn_conn_recv_ce; | |
361 | u_int64_t ecn_conn_recv_ece; | |
362 | u_int64_t ecn_conn_plnoce; | |
363 | u_int64_t ecn_conn_plce; | |
364 | u_int64_t ecn_conn_noplce; | |
365 | u_int64_t ecn_fallback_synloss; | |
366 | u_int64_t ecn_fallback_reorder; | |
367 | u_int64_t ecn_fallback_ce; | |
490019cf A |
368 | u_int64_t ecn_off_conn; |
369 | u_int64_t ecn_total_conn; | |
39037602 A |
370 | u_int64_t ecn_fallback_droprst; |
371 | u_int64_t ecn_fallback_droprxmt; | |
5ba3f43e | 372 | u_int64_t ecn_fallback_synrst; |
4bd07ac2 A |
373 | struct if_tcp_ecn_perf_stat ecn_on; |
374 | struct if_tcp_ecn_perf_stat ecn_off; | |
375 | }; | |
376 | ||
5ba3f43e A |
377 | struct if_lim_perf_stat { |
378 | u_int64_t lim_dl_max_bandwidth; /* bits per second */ | |
379 | u_int64_t lim_ul_max_bandwidth; /* bits per second */ | |
380 | u_int64_t lim_total_txpkts; /* Total transmit packets, count */ | |
381 | u_int64_t lim_total_rxpkts; /* Total receive packets, count */ | |
382 | u_int64_t lim_total_retxpkts; /* Total retransmit packets */ | |
383 | u_int64_t lim_packet_loss_percent; /* Packet loss rate */ | |
384 | u_int64_t lim_total_oopkts; /* Total out-of-order packets */ | |
385 | u_int64_t lim_packet_ooo_percent; /* Out-of-order packet rate */ | |
386 | u_int64_t lim_rtt_variance; /* RTT variance, milliseconds */ | |
387 | u_int64_t lim_rtt_average; /* RTT average, milliseconds */ | |
388 | u_int64_t lim_rtt_min; /* RTT minimum, milliseconds */ | |
389 | u_int64_t lim_conn_timeouts; /* connection timeouts */ | |
390 | u_int64_t lim_conn_attempts; /* connection attempts */ | |
391 | u_int64_t lim_conn_timeout_percent; /* Rate of connection timeouts */ | |
392 | u_int64_t lim_bk_txpkts; /* Transmit packets with BK service class, that use delay based algorithms */ | |
393 | u_int64_t lim_dl_detected:1, /* Low internet */ | |
394 | lim_ul_detected:1; | |
395 | }; | |
396 | ||
397 | #define IF_VAR_H_HAS_IFNET_STATS_PER_FLOW 1 | |
398 | struct ifnet_stats_per_flow { | |
399 | u_int64_t bk_txpackets; | |
400 | u_int64_t txpackets; | |
401 | u_int64_t rxpackets; | |
402 | u_int32_t txretransmitbytes; | |
403 | u_int32_t rxoutoforderbytes; | |
404 | u_int32_t rxmitpkts; | |
405 | u_int32_t rcvoopack; | |
406 | u_int32_t pawsdrop; | |
407 | u_int32_t sack_recovery_episodes; | |
408 | u_int32_t reordered_pkts; | |
409 | u_int32_t dsack_sent; | |
410 | u_int32_t dsack_recvd; | |
411 | u_int32_t srtt; | |
412 | u_int32_t rttupdated; | |
413 | u_int32_t rttvar; | |
414 | u_int32_t rttmin; | |
415 | u_int32_t bw_sndbw_max; | |
416 | u_int32_t bw_rcvbw_max; | |
417 | u_int32_t ecn_recv_ece; | |
418 | u_int32_t ecn_recv_ce; | |
419 | u_int16_t ecn_flags; | |
420 | u_int16_t ipv4:1, | |
421 | local:1, | |
422 | connreset:1, | |
423 | conntimeout:1, | |
424 | rxmit_drop:1, | |
425 | ecn_fallback_synloss:1, | |
426 | ecn_fallback_droprst:1, | |
427 | ecn_fallback_droprxmt:1, | |
428 | ecn_fallback_ce:1, | |
429 | ecn_fallback_reorder:1; | |
430 | }; | |
431 | ||
3e170ce0 A |
432 | /* |
433 | * Interface link status report -- includes statistics related to | |
434 | * the link layer technology sent by the driver. The driver will monitor | |
435 | * these statistics over an interval (3-4 secs) and will generate a report | |
436 | * to the network stack. This will give first-hand information about the | |
437 | * status of the first hop of the network path. The version and | |
438 | * length values should be correct for the data to be processed correctly. | |
439 | * The definitions are different for different kind of interfaces like | |
440 | * Wifi, Cellular etc,. | |
441 | */ | |
442 | #define IF_CELLULAR_STATUS_REPORT_VERSION_1 1 | |
443 | #define IF_WIFI_STATUS_REPORT_VERSION_1 1 | |
444 | #define IF_CELLULAR_STATUS_REPORT_CURRENT_VERSION \ | |
445 | IF_CELLULAR_STATUS_REPORT_VERSION_1 | |
446 | #define IF_WIFI_STATUS_REPORT_CURRENT_VERSION IF_WIFI_STATUS_REPORT_VERSION_1 | |
447 | /* | |
448 | * For cellular interface -- | |
449 | * There is no way to share common headers between the Baseband and | |
450 | * the kernel. Any changes to this structure will need to be communicated | |
451 | * to the Baseband team. It is better to use reserved space instead of | |
452 | * changing the size or existing fields in the structure. | |
453 | */ | |
454 | struct if_cellular_status_v1 { | |
455 | u_int32_t valid_bitmask; /* indicates which fields are valid */ | |
456 | #define IF_CELL_LINK_QUALITY_METRIC_VALID 0x1 | |
457 | #define IF_CELL_UL_EFFECTIVE_BANDWIDTH_VALID 0x2 | |
458 | #define IF_CELL_UL_MAX_BANDWIDTH_VALID 0x4 | |
459 | #define IF_CELL_UL_MIN_LATENCY_VALID 0x8 | |
460 | #define IF_CELL_UL_EFFECTIVE_LATENCY_VALID 0x10 | |
461 | #define IF_CELL_UL_MAX_LATENCY_VALID 0x20 | |
462 | #define IF_CELL_UL_RETXT_LEVEL_VALID 0x40 | |
463 | #define IF_CELL_UL_BYTES_LOST_VALID 0x80 | |
464 | #define IF_CELL_UL_MIN_QUEUE_SIZE_VALID 0x100 | |
465 | #define IF_CELL_UL_AVG_QUEUE_SIZE_VALID 0x200 | |
466 | #define IF_CELL_UL_MAX_QUEUE_SIZE_VALID 0x400 | |
467 | #define IF_CELL_DL_EFFECTIVE_BANDWIDTH_VALID 0x800 | |
468 | #define IF_CELL_DL_MAX_BANDWIDTH_VALID 0x1000 | |
469 | #define IF_CELL_CONFIG_INACTIVITY_TIME_VALID 0x2000 | |
470 | #define IF_CELL_CONFIG_BACKOFF_TIME_VALID 0x4000 | |
39037602 A |
471 | #define IF_CELL_UL_MSS_RECOMMENDED_VALID 0x8000 |
472 | ||
3e170ce0 A |
473 | u_int32_t link_quality_metric; |
474 | u_int32_t ul_effective_bandwidth; /* Measured uplink bandwidth based on current activity (bps) */ | |
475 | u_int32_t ul_max_bandwidth; /* Maximum supported uplink bandwidth (bps) */ | |
476 | u_int32_t ul_min_latency; /* min expected uplink latency for first hop (ms) */ | |
477 | u_int32_t ul_effective_latency; /* current expected uplink latency for first hop (ms) */ | |
478 | u_int32_t ul_max_latency; /* max expected uplink latency first hop (ms) */ | |
479 | u_int32_t ul_retxt_level; /* Retransmission metric */ | |
480 | #define IF_CELL_UL_RETXT_LEVEL_NONE 1 | |
481 | #define IF_CELL_UL_RETXT_LEVEL_LOW 2 | |
482 | #define IF_CELL_UL_RETXT_LEVEL_MEDIUM 3 | |
483 | #define IF_CELL_UL_RETXT_LEVEL_HIGH 4 | |
484 | u_int32_t ul_bytes_lost; /* % of total bytes lost on uplink in Q10 format */ | |
485 | u_int32_t ul_min_queue_size; /* minimum bytes in queue */ | |
486 | u_int32_t ul_avg_queue_size; /* average bytes in queue */ | |
487 | u_int32_t ul_max_queue_size; /* maximum bytes in queue */ | |
488 | u_int32_t dl_effective_bandwidth; /* Measured downlink bandwidth based on current activity (bps) */ | |
489 | u_int32_t dl_max_bandwidth; /* Maximum supported downlink bandwidth (bps) */ | |
490 | u_int32_t config_inactivity_time; /* ms */ | |
491 | u_int32_t config_backoff_time; /* new connections backoff time in ms */ | |
39037602 A |
492 | #define IF_CELL_UL_MSS_RECOMMENDED_NONE 0x0 /* Use default */ |
493 | #define IF_CELL_UL_MSS_RECOMMENDED_MEDIUM 0x1 /* 1200 byte MSS */ | |
494 | #define IF_CELL_UL_MSS_RECOMMENDED_LOW 0x2 /* 512 byte MSS */ | |
495 | u_int16_t mss_recommended; | |
496 | u_int16_t reserved_1; | |
497 | u_int32_t reserved_2; | |
3e170ce0 A |
498 | u_int64_t reserved_3; |
499 | u_int64_t reserved_4; | |
500 | u_int64_t reserved_5; | |
39037602 | 501 | u_int64_t reserved_6; |
3e170ce0 A |
502 | } __attribute__((packed)); |
503 | ||
504 | struct if_cellular_status { | |
505 | union { | |
506 | struct if_cellular_status_v1 if_status_v1; | |
507 | } if_cell_u; | |
508 | }; | |
509 | ||
510 | /* | |
511 | * These statistics will be provided by the Wifi driver periodically. | |
512 | * After sending each report, the driver should start computing again | |
513 | * for the next report duration so that the values represent the link | |
514 | * status for one report duration. | |
515 | */ | |
516 | ||
517 | struct if_wifi_status_v1 { | |
518 | u_int32_t valid_bitmask; | |
519 | #define IF_WIFI_LINK_QUALITY_METRIC_VALID 0x1 | |
520 | #define IF_WIFI_UL_EFFECTIVE_BANDWIDTH_VALID 0x2 | |
521 | #define IF_WIFI_UL_MAX_BANDWIDTH_VALID 0x4 | |
522 | #define IF_WIFI_UL_MIN_LATENCY_VALID 0x8 | |
523 | #define IF_WIFI_UL_EFFECTIVE_LATENCY_VALID 0x10 | |
524 | #define IF_WIFI_UL_MAX_LATENCY_VALID 0x20 | |
525 | #define IF_WIFI_UL_RETXT_LEVEL_VALID 0x40 | |
526 | #define IF_WIFI_UL_ERROR_RATE_VALID 0x80 | |
527 | #define IF_WIFI_UL_BYTES_LOST_VALID 0x100 | |
528 | #define IF_WIFI_DL_EFFECTIVE_BANDWIDTH_VALID 0x200 | |
529 | #define IF_WIFI_DL_MAX_BANDWIDTH_VALID 0x400 | |
530 | #define IF_WIFI_DL_MIN_LATENCY_VALID 0x800 | |
531 | #define IF_WIFI_DL_EFFECTIVE_LATENCY_VALID 0x1000 | |
532 | #define IF_WIFI_DL_MAX_LATENCY_VALID 0x2000 | |
533 | #define IF_WIFI_DL_ERROR_RATE_VALID 0x4000 | |
534 | #define IF_WIFI_CONFIG_FREQUENCY_VALID 0x8000 | |
535 | #define IF_WIFI_CONFIG_MULTICAST_RATE_VALID 0x10000 | |
536 | #define IF_WIFI_CONFIG_SCAN_COUNT_VALID 0x20000 | |
537 | #define IF_WIFI_CONFIG_SCAN_DURATION_VALID 0x40000 | |
538 | u_int32_t link_quality_metric; /* link quality metric */ | |
539 | u_int32_t ul_effective_bandwidth; /* Measured uplink bandwidth based on current activity (bps) */ | |
540 | u_int32_t ul_max_bandwidth; /* Maximum supported uplink bandwidth (bps) */ | |
541 | u_int32_t ul_min_latency; /* min expected uplink latency for first hop (ms) */ | |
542 | u_int32_t ul_effective_latency; /* current expected uplink latency for first hop (ms) */ | |
543 | u_int32_t ul_max_latency; /* max expected uplink latency for first hop (ms) */ | |
544 | u_int32_t ul_retxt_level; /* Retransmission metric */ | |
545 | #define IF_WIFI_UL_RETXT_LEVEL_NONE 1 | |
546 | #define IF_WIFI_UL_RETXT_LEVEL_LOW 2 | |
547 | #define IF_WIFI_UL_RETXT_LEVEL_MEDIUM 3 | |
548 | #define IF_WIFI_UL_RETXT_LEVEL_HIGH 4 | |
549 | u_int32_t ul_bytes_lost; /* % of total bytes lost on uplink in Q10 format */ | |
550 | u_int32_t ul_error_rate; /* % of bytes dropped on uplink after many retransmissions in Q10 format */ | |
551 | u_int32_t dl_effective_bandwidth; /* Measured downlink bandwidth based on current activity (bps) */ | |
552 | u_int32_t dl_max_bandwidth; /* Maximum supported downlink bandwidth (bps) */ | |
553 | /* | |
554 | * The download latency values indicate the time AP may have to wait for the | |
555 | * driver to receive the packet. These values give the range of expected latency | |
556 | * mainly due to co-existence events and channel hopping where the interface | |
557 | * becomes unavailable. | |
558 | */ | |
559 | u_int32_t dl_min_latency; /* min expected latency for first hop in ms */ | |
560 | u_int32_t dl_effective_latency; /* current expected latency for first hop in ms */ | |
561 | u_int32_t dl_max_latency; /* max expected latency for first hop in ms */ | |
562 | u_int32_t dl_error_rate; /* % of CRC or other errors in Q10 format */ | |
563 | u_int32_t config_frequency; /* 2.4 or 5 GHz */ | |
564 | #define IF_WIFI_CONFIG_FREQUENCY_2_4_GHZ 1 | |
565 | #define IF_WIFI_CONFIG_FREQUENCY_5_0_GHZ 2 | |
566 | u_int32_t config_multicast_rate; /* bps */ | |
567 | u_int32_t scan_count; /* scan count during the previous period */ | |
568 | u_int32_t scan_duration; /* scan duration in ms */ | |
569 | u_int64_t reserved_1; | |
570 | u_int64_t reserved_2; | |
571 | u_int64_t reserved_3; | |
572 | u_int64_t reserved_4; | |
573 | } __attribute__((packed)); | |
574 | ||
575 | struct if_wifi_status { | |
576 | union { | |
577 | struct if_wifi_status_v1 if_status_v1; | |
578 | } if_wifi_u; | |
579 | }; | |
580 | ||
581 | struct if_link_status { | |
582 | u_int32_t ifsr_version; /* version of this report */ | |
583 | u_int32_t ifsr_len; /* length of the following struct */ | |
584 | union { | |
585 | struct if_cellular_status ifsr_cell; | |
586 | struct if_wifi_status ifsr_wifi; | |
587 | } ifsr_u; | |
588 | }; | |
589 | ||
590 | struct if_interface_state { | |
591 | /* | |
592 | * The bitmask tells which of the fields | |
593 | * to consider: | |
594 | * - When setting, to control which fields | |
595 | * are being modified; | |
596 | * - When getting, it tells which fields are set. | |
597 | */ | |
598 | u_int8_t valid_bitmask; | |
599 | #define IF_INTERFACE_STATE_RRC_STATE_VALID 0x1 | |
600 | #define IF_INTERFACE_STATE_LQM_STATE_VALID 0x2 | |
601 | #define IF_INTERFACE_STATE_INTERFACE_AVAILABILITY_VALID 0x4 | |
602 | ||
603 | /* | |
604 | * Valid only for cellular interface | |
605 | */ | |
606 | u_int8_t rrc_state; | |
607 | #define IF_INTERFACE_STATE_RRC_STATE_IDLE 0x0 | |
608 | #define IF_INTERFACE_STATE_RRC_STATE_CONNECTED 0x1 | |
609 | ||
610 | /* | |
611 | * Values normalized to the edge of the following values | |
612 | * that are defined on <net/if.h>: | |
613 | * IFNET_LQM_THRESH_BAD | |
614 | * IFNET_LQM_THRESH_POOR | |
615 | * IFNET_LQM_THRESH_GOOD | |
616 | */ | |
617 | int8_t lqm_state; | |
618 | ||
619 | /* | |
620 | * Indicate if the underlying link is currently | |
39037602 | 621 | * available |
3e170ce0 A |
622 | */ |
623 | u_int8_t interface_availability; | |
624 | #define IF_INTERFACE_STATE_INTERFACE_AVAILABLE 0x0 | |
625 | #define IF_INTERFACE_STATE_INTERFACE_UNAVAILABLE 0x1 | |
626 | }; | |
627 | ||
628 | struct chain_len_stats { | |
629 | uint64_t cls_one; | |
630 | uint64_t cls_two; | |
631 | uint64_t cls_three; | |
632 | uint64_t cls_four; | |
633 | uint64_t cls_five_or_more; | |
5ba3f43e | 634 | } __attribute__((__aligned__(sizeof (uint64_t)))); |
3e170ce0 | 635 | |
6d2010ae A |
636 | #endif /* PRIVATE */ |
637 | ||
638 | #pragma pack() | |
d41d1dae | 639 | |
6d2010ae A |
640 | /* |
641 | * Structure defining a queue for a network interface. | |
642 | */ | |
643 | struct ifqueue { | |
644 | void *ifq_head; | |
645 | void *ifq_tail; | |
646 | int ifq_len; | |
647 | int ifq_maxlen; | |
648 | int ifq_drops; | |
649 | }; | |
650 | ||
316670eb | 651 | #ifdef BSD_KERNEL_PRIVATE |
91447636 A |
652 | /* |
653 | * Internal storage of if_data. This is bound to change. Various places in the | |
654 | * stack will translate this data structure in to the externally visible | |
6d2010ae A |
655 | * if_data structure above. Note that during interface attach time, the |
656 | * embedded if_data structure in ifnet is cleared, with the exception of | |
657 | * some non-statistics related fields. | |
91447636 A |
658 | */ |
659 | struct if_data_internal { | |
660 | /* generic interface information */ | |
2d21ac55 A |
661 | u_char ifi_type; /* ethernet, tokenring, etc */ |
662 | u_char ifi_typelen; /* Length of frame type id */ | |
663 | u_char ifi_physical; /* e.g., AUI, Thinnet, 10base-T, etc */ | |
664 | u_char ifi_addrlen; /* media address length */ | |
665 | u_char ifi_hdrlen; /* media header length */ | |
666 | u_char ifi_recvquota; /* polling quota for receive intrs */ | |
667 | u_char ifi_xmitquota; /* polling quota for xmit intrs */ | |
668 | u_char ifi_unused1; /* for future use */ | |
669 | u_int32_t ifi_mtu; /* maximum transmission unit */ | |
670 | u_int32_t ifi_metric; /* routing metric (external only) */ | |
671 | u_int32_t ifi_baudrate; /* linespeed */ | |
1c79356b | 672 | /* volatile statistics */ |
91447636 A |
673 | u_int64_t ifi_ipackets; /* packets received on interface */ |
674 | u_int64_t ifi_ierrors; /* input errors on interface */ | |
675 | u_int64_t ifi_opackets; /* packets sent on interface */ | |
676 | u_int64_t ifi_oerrors; /* output errors on interface */ | |
677 | u_int64_t ifi_collisions; /* collisions on csma interfaces */ | |
2d21ac55 A |
678 | u_int64_t ifi_ibytes; /* total number of octets received */ |
679 | u_int64_t ifi_obytes; /* total number of octets sent */ | |
91447636 A |
680 | u_int64_t ifi_imcasts; /* packets received via multicast */ |
681 | u_int64_t ifi_omcasts; /* packets sent via multicast */ | |
682 | u_int64_t ifi_iqdrops; /* dropped on input, this interface */ | |
683 | u_int64_t ifi_noproto; /* destined for unsupported protocol */ | |
2d21ac55 A |
684 | u_int32_t ifi_recvtiming; /* usec spent receiving when timing */ |
685 | u_int32_t ifi_xmittiming; /* usec spent xmitting when timing */ | |
316670eb | 686 | u_int64_t ifi_alignerrs; /* unaligned (32-bit) input pkts */ |
39236c6e A |
687 | u_int64_t ifi_dt_bytes; /* Data threshold counter */ |
688 | u_int64_t ifi_fpackets; /* forwarded packets on interface */ | |
689 | u_int64_t ifi_fbytes; /* forwarded bytes on interface */ | |
1c79356b | 690 | struct timeval ifi_lastchange; /* time of last administrative change */ |
2d21ac55 | 691 | u_int32_t ifi_hwassist; /* HW offload capabilities */ |
b0d623f7 A |
692 | u_int32_t ifi_tso_v4_mtu; /* TCP Segment Offload IPv4 maximum segment size */ |
693 | u_int32_t ifi_tso_v6_mtu; /* TCP Segment Offload IPv6 maximum segment size */ | |
1c79356b | 694 | }; |
316670eb | 695 | #endif /* BSD_KERNEL_PRIVATE */ |
91447636 | 696 | |
6d2010ae | 697 | #ifdef PRIVATE |
91447636 A |
698 | #define if_mtu if_data.ifi_mtu |
699 | #define if_type if_data.ifi_type | |
700 | #define if_typelen if_data.ifi_typelen | |
701 | #define if_physical if_data.ifi_physical | |
702 | #define if_addrlen if_data.ifi_addrlen | |
703 | #define if_hdrlen if_data.ifi_hdrlen | |
704 | #define if_metric if_data.ifi_metric | |
705 | #define if_baudrate if_data.ifi_baudrate | |
706 | #define if_hwassist if_data.ifi_hwassist | |
707 | #define if_ipackets if_data.ifi_ipackets | |
708 | #define if_ierrors if_data.ifi_ierrors | |
709 | #define if_opackets if_data.ifi_opackets | |
710 | #define if_oerrors if_data.ifi_oerrors | |
711 | #define if_collisions if_data.ifi_collisions | |
712 | #define if_ibytes if_data.ifi_ibytes | |
713 | #define if_obytes if_data.ifi_obytes | |
714 | #define if_imcasts if_data.ifi_imcasts | |
715 | #define if_omcasts if_data.ifi_omcasts | |
716 | #define if_iqdrops if_data.ifi_iqdrops | |
717 | #define if_noproto if_data.ifi_noproto | |
718 | #define if_lastchange if_data.ifi_lastchange | |
719 | #define if_recvquota if_data.ifi_recvquota | |
720 | #define if_xmitquota if_data.ifi_xmitquota | |
6d2010ae | 721 | #endif /* PRIVATE */ |
316670eb | 722 | #ifdef BSD_KERNEL_PRIVATE |
b0d623f7 A |
723 | #define if_tso_v4_mtu if_data.ifi_tso_v4_mtu |
724 | #define if_tso_v6_mtu if_data.ifi_tso_v6_mtu | |
316670eb | 725 | #define if_alignerrs if_data.ifi_alignerrs |
39236c6e A |
726 | #define if_dt_bytes if_data.ifi_dt_bytes |
727 | #define if_fpackets if_data.ifi_fpackets | |
728 | #define if_fbytes if_data.ifi_fbytes | |
316670eb | 729 | #endif /* BSD_KERNEL_PRIVATE */ |
91447636 | 730 | |
316670eb | 731 | #ifdef BSD_KERNEL_PRIVATE |
91447636 A |
732 | /* |
733 | * Forward structure declarations for function prototypes [sic]. | |
734 | */ | |
6d2010ae A |
735 | struct proc; |
736 | struct rtentry; | |
737 | struct socket; | |
91447636 | 738 | struct ifnet_filter; |
6d2010ae A |
739 | struct mbuf; |
740 | struct ifaddr; | |
741 | struct tqdummy; | |
742 | struct proto_hash_entry; | |
743 | struct dlil_threading_info; | |
316670eb A |
744 | struct tcpstat_local; |
745 | struct udpstat_local; | |
6d2010ae A |
746 | #if PF |
747 | struct pfi_kif; | |
748 | #endif /* PF */ | |
91447636 | 749 | |
6d2010ae A |
750 | /* we use TAILQs so that the order of instantiation is preserved in the list */ |
751 | TAILQ_HEAD(ifnethead, ifnet); | |
752 | TAILQ_HEAD(ifaddrhead, ifaddr); | |
6d2010ae A |
753 | LIST_HEAD(ifmultihead, ifmultiaddr); |
754 | TAILQ_HEAD(tailq_head, tqdummy); | |
91447636 A |
755 | TAILQ_HEAD(ifnet_filter_head, ifnet_filter); |
756 | TAILQ_HEAD(ddesc_head_name, dlil_demux_desc); | |
5c9f4661 A |
757 | |
758 | extern boolean_t intcoproc_unrestricted; | |
316670eb | 759 | #endif /* BSD_KERNEL_PRIVATE */ |
91447636 | 760 | |
6d2010ae A |
761 | #ifdef PRIVATE |
762 | /* | |
5ba3f43e | 763 | * All of the following IF_HWASSIST_* flags are defined in kpi_interface.h as |
6d2010ae A |
764 | * IFNET_* flags. These are redefined here as constants to avoid failures to |
765 | * build user level programs that can not include kpi_interface.h. It is | |
766 | * important to keep this in sync with the definitions in kpi_interface.h. | |
767 | * The corresponding constant for each definition is mentioned in the comment. | |
b0d623f7 | 768 | * |
6d2010ae | 769 | * Bottom 16 bits reserved for hardware checksum |
b0d623f7 A |
770 | */ |
771 | #define IF_HWASSIST_CSUM_IP 0x0001 /* will csum IP, IFNET_CSUM_IP */ | |
772 | #define IF_HWASSIST_CSUM_TCP 0x0002 /* will csum TCP, IFNET_CSUM_TCP */ | |
773 | #define IF_HWASSIST_CSUM_UDP 0x0004 /* will csum UDP, IFNET_CSUM_UDP */ | |
774 | #define IF_HWASSIST_CSUM_IP_FRAGS 0x0008 /* will csum IP fragments, IFNET_CSUM_FRAGMENT */ | |
775 | #define IF_HWASSIST_CSUM_FRAGMENT 0x0010 /* will do IP fragmentation, IFNET_IP_FRAGMENT */ | |
6d2010ae A |
776 | #define IF_HWASSIST_CSUM_TCPIPV6 0x0020 /* will csum TCPv6, IFNET_CSUM_TCPIPV6 */ |
777 | #define IF_HWASSIST_CSUM_UDPIPV6 0x0040 /* will csum UDPv6, IFNET_CSUM_UDP */ | |
778 | #define IF_HWASSIST_CSUM_FRAGMENT_IPV6 0x0080 /* will do IPv6 fragmentation, IFNET_IPV6_FRAGMENT */ | |
39236c6e | 779 | #define IF_HWASSIST_CSUM_PARTIAL 0x1000 /* simple Sum16 computation, IFNET_CSUM_PARTIAL */ |
5ba3f43e | 780 | #define IF_HWASSIST_CSUM_ZERO_INVERT 0x2000 /* capable of inverting csum of 0 to -0 (0xffff) */ |
91447636 A |
781 | #define IF_HWASSIST_CSUM_MASK 0xffff |
782 | #define IF_HWASSIST_CSUM_FLAGS(hwassist) ((hwassist) & IF_HWASSIST_CSUM_MASK) | |
783 | ||
784 | /* VLAN support */ | |
b0d623f7 A |
785 | #define IF_HWASSIST_VLAN_TAGGING 0x00010000 /* supports VLAN tagging, IFNET_VLAN_TAGGING */ |
786 | #define IF_HWASSIST_VLAN_MTU 0x00020000 /* supports VLAN MTU-sized packet (for software VLAN), IFNET_VLAN_MTU */ | |
787 | ||
788 | /* TCP Segment Offloading support */ | |
789 | ||
790 | #define IF_HWASSIST_TSO_V4 0x00200000 /* will do TCP Segment offload for IPv4, IFNET_TSO_IPV4 */ | |
791 | #define IF_HWASSIST_TSO_V6 0x00400000 /* will do TCP Segment offload for IPv6, IFNET_TSO_IPV6 */ | |
2d21ac55 | 792 | #endif /* PRIVATE */ |
1c79356b | 793 | |
39236c6e A |
794 | #ifdef PRIVATE |
795 | #define IFXNAMSIZ (IFNAMSIZ + 8) /* external name (name + unit) */ | |
796 | #endif | |
797 | ||
316670eb A |
798 | #ifdef BSD_KERNEL_PRIVATE |
799 | /* | |
800 | * ifnet is private to BSD portion of kernel | |
801 | */ | |
39236c6e | 802 | #include <sys/mcache.h> |
6d2010ae A |
803 | #include <sys/tree.h> |
804 | #include <netinet/in.h> | |
39236c6e | 805 | #include <net/if_dl.h> |
316670eb | 806 | #include <net/classq/if_classq.h> |
39236c6e | 807 | #include <net/if_types.h> |
2d21ac55 | 808 | |
6d2010ae | 809 | RB_HEAD(ll_reach_tree, if_llreach); /* define struct ll_reach_tree */ |
91447636 | 810 | |
5ba3f43e A |
811 | |
812 | typedef errno_t (*dlil_input_func)(ifnet_t ifp, mbuf_t m_head, | |
813 | mbuf_t m_tail, const struct ifnet_stat_increment_param *s, | |
814 | boolean_t poll, struct thread *tp); | |
815 | typedef errno_t (*dlil_output_func)(ifnet_t interface, mbuf_t data); | |
816 | ||
39236c6e | 817 | #define if_name(ifp) ifp->if_xname |
1c79356b A |
818 | /* |
819 | * Structure defining a network interface. | |
820 | * | |
821 | * (Would like to call this struct ``if'', but C isn't PL/1.) | |
822 | */ | |
823 | struct ifnet { | |
6d2010ae A |
824 | /* |
825 | * Lock (RW or mutex) to protect this data structure (static storage.) | |
826 | */ | |
827 | decl_lck_rw_data(, if_lock); | |
828 | void *if_softc; /* pointer to driver state */ | |
829 | const char *if_name; /* name, e.g. ``en'' or ``lo'' */ | |
39236c6e | 830 | const char *if_xname; /* external name (name + unit) */ |
316670eb | 831 | struct if_description if_desc; /* extended description */ |
6d2010ae A |
832 | TAILQ_ENTRY(ifnet) if_link; /* all struct ifnets are chained */ |
833 | TAILQ_ENTRY(ifnet) if_detaching_link; /* list of detaching ifnets */ | |
39037602 | 834 | TAILQ_ENTRY(ifnet) if_ordered_link; /* list of ordered ifnets */ |
6d2010ae A |
835 | |
836 | decl_lck_mtx_data(, if_ref_lock) | |
39236c6e | 837 | u_int32_t if_refflags; /* see IFRF flags below */ |
6d2010ae A |
838 | u_int32_t if_refio; /* number of io ops to the underlying driver */ |
839 | ||
840 | #define if_list if_link | |
841 | struct ifaddrhead if_addrhead; /* linked list of addresses per if */ | |
842 | #define if_addrlist if_addrhead | |
843 | struct ifaddr *if_lladdr; /* link address (first/permanent) */ | |
844 | ||
39037602 A |
845 | u_int32_t if_qosmarking_mode; /* generation to use with NECP clients */ |
846 | ||
6d2010ae A |
847 | int if_pcount; /* number of promiscuous listeners */ |
848 | struct bpf_if *if_bpf; /* packet filter structure */ | |
849 | u_short if_index; /* numeric abbreviation for this if */ | |
850 | short if_unit; /* sub-unit for lower level driver */ | |
851 | short if_timer; /* time 'til if_watchdog called */ | |
852 | short if_flags; /* up/down, broadcast, etc. */ | |
853 | u_int32_t if_eflags; /* see <net/if.h> */ | |
39037602 | 854 | u_int32_t if_xflags; /* see <net/if.h> */ |
6d2010ae A |
855 | |
856 | int if_capabilities; /* interface features & capabilities */ | |
857 | int if_capenable; /* enabled features & capabilities */ | |
858 | ||
859 | void *if_linkmib; /* link-type-specific MIB data */ | |
860 | size_t if_linkmiblen; /* length of above data */ | |
861 | ||
862 | struct if_data_internal if_data __attribute__((aligned(8))); | |
863 | ||
864 | ifnet_family_t if_family; /* value assigned by Apple */ | |
39236c6e | 865 | ifnet_subfamily_t if_subfamily; /* value assigned by Apple */ |
6d2010ae | 866 | uintptr_t if_family_cookie; |
5ba3f43e A |
867 | volatile dlil_input_func if_input_dlil; |
868 | volatile dlil_output_func if_output_dlil; | |
869 | volatile ifnet_start_func if_start; | |
91447636 | 870 | ifnet_output_func if_output; |
316670eb | 871 | ifnet_pre_enqueue_func if_pre_enqueue; |
316670eb A |
872 | ifnet_ctl_func if_output_ctl; |
873 | ifnet_input_poll_func if_input_poll; | |
874 | ifnet_ctl_func if_input_ctl; | |
91447636 A |
875 | ifnet_ioctl_func if_ioctl; |
876 | ifnet_set_bpf_tap if_set_bpf_tap; | |
877 | ifnet_detached_func if_free; | |
878 | ifnet_demux_func if_demux; | |
879 | ifnet_event_func if_event; | |
39236c6e A |
880 | ifnet_framer_func if_framer_legacy; |
881 | ifnet_framer_extended_func if_framer; | |
6d2010ae A |
882 | ifnet_add_proto_func if_add_proto; |
883 | ifnet_del_proto_func if_del_proto; | |
884 | ifnet_check_multi if_check_multi; | |
885 | struct proto_hash_entry *if_proto_hash; | |
886 | void *if_kpi_storage; | |
1c79356b | 887 | |
39236c6e A |
888 | u_int32_t if_flowhash; /* interface flow control ID */ |
889 | ||
316670eb | 890 | decl_lck_mtx_data(, if_start_lock); |
39236c6e | 891 | u_int32_t if_start_flags; /* see IFSF flags below */ |
316670eb | 892 | u_int32_t if_start_req; |
3e170ce0 A |
893 | u_int16_t if_start_active; /* output is active */ |
894 | u_int16_t if_start_delayed; | |
895 | u_int16_t if_start_delay_qlen; | |
896 | u_int16_t if_start_delay_idle; | |
897 | u_int64_t if_start_delay_swin; | |
898 | u_int32_t if_start_delay_cnt; | |
899 | u_int32_t if_start_delay_timeout; /* nanoseconds */ | |
316670eb A |
900 | struct timespec if_start_cycle; /* restart interval */ |
901 | struct thread *if_start_thread; | |
902 | ||
903 | struct ifclassq if_snd; /* transmit queue */ | |
904 | u_int32_t if_output_sched_model; /* tx sched model */ | |
905 | ||
906 | struct if_bandwidths if_output_bw; | |
907 | struct if_bandwidths if_input_bw; | |
908 | ||
39236c6e A |
909 | struct if_latencies if_output_lt; |
910 | struct if_latencies if_input_lt; | |
911 | ||
6d2010ae A |
912 | decl_lck_mtx_data(, if_flt_lock) |
913 | u_int32_t if_flt_busy; | |
914 | u_int32_t if_flt_waiters; | |
91447636 | 915 | struct ifnet_filter_head if_flt_head; |
1c79356b | 916 | |
6d2010ae A |
917 | struct ifmultihead if_multiaddrs; /* multicast addresses */ |
918 | u_int32_t if_updatemcasts; /* mcast addrs need updating */ | |
919 | int if_amcount; /* # of all-multicast reqs */ | |
920 | decl_lck_mtx_data(, if_addrconfig_lock); /* for serializing addr config */ | |
921 | struct in_multi *if_allhostsinm; /* store all-hosts inm for this ifp */ | |
1c79356b | 922 | |
316670eb A |
923 | decl_lck_mtx_data(, if_poll_lock); |
924 | u_int16_t if_poll_req; | |
925 | u_int16_t if_poll_update; /* link update */ | |
926 | u_int32_t if_poll_active; /* polling is active */ | |
927 | struct timespec if_poll_cycle; /* poll interval */ | |
928 | struct thread *if_poll_thread; | |
91447636 | 929 | |
316670eb | 930 | struct dlil_threading_info *if_inp; |
91447636 | 931 | |
5ba3f43e A |
932 | /* allocated once along with dlil_ifnet and is never freed */ |
933 | thread_call_t if_dt_tcall; | |
934 | ||
91447636 | 935 | struct { |
b0d623f7 | 936 | u_int32_t length; |
91447636 A |
937 | union { |
938 | u_char buffer[8]; | |
939 | u_char *ptr; | |
940 | } u; | |
941 | } if_broadcast; | |
2d21ac55 | 942 | #if CONFIG_MACF_NET |
6d2010ae | 943 | struct label *if_label; /* interface MAC label */ |
2d21ac55 | 944 | #endif |
b0d623f7 | 945 | |
b0d623f7 | 946 | #if PF |
6d2010ae | 947 | struct pfi_kif *if_pf_kif; |
b0d623f7 | 948 | #endif /* PF */ |
1c79356b | 949 | |
6d2010ae A |
950 | decl_lck_mtx_data(, if_cached_route_lock); |
951 | u_int32_t if_fwd_cacheok; | |
952 | struct route if_fwd_route; /* cached forwarding route */ | |
953 | struct route if_src_route; /* cached ipv4 source route */ | |
954 | struct route_in6 if_src_route6; /* cached ipv6 source route */ | |
91447636 | 955 | |
6d2010ae A |
956 | decl_lck_rw_data(, if_llreach_lock); |
957 | struct ll_reach_tree if_ll_srcs; /* source link-layer tree */ | |
91447636 | 958 | |
6d2010ae A |
959 | void *if_bridge; /* bridge glue */ |
960 | ||
961 | u_int32_t if_want_aggressive_drain; | |
962 | u_int32_t if_idle_flags; /* idle flags */ | |
963 | u_int32_t if_idle_new_flags; /* temporary idle flags */ | |
964 | u_int32_t if_idle_new_flags_mask; /* temporary mask */ | |
965 | u_int32_t if_route_refcnt; /* idle: route ref count */ | |
39037602 | 966 | u_int32_t if_rt_sendts; /* last of a real time packet */ |
6d2010ae A |
967 | |
968 | struct if_traffic_class if_tc __attribute__((aligned(8))); | |
969 | #if INET | |
970 | struct igmp_ifinfo *if_igi; /* for IGMPv3 */ | |
971 | #endif /* INET */ | |
972 | #if INET6 | |
973 | struct mld_ifinfo *if_mli; /* for MLDv2 */ | |
974 | #endif /* INET6 */ | |
316670eb | 975 | |
316670eb A |
976 | struct tcpstat_local *if_tcp_stat; /* TCP specific stats */ |
977 | struct udpstat_local *if_udp_stat; /* UDP specific stats */ | |
39236c6e A |
978 | |
979 | struct { | |
980 | int32_t level; /* cached logging level */ | |
981 | u_int32_t flags; /* cached logging flags */ | |
982 | int32_t category; /* cached category */ | |
983 | int32_t subcategory; /* cached subcategory */ | |
984 | } if_log; | |
985 | ||
986 | struct { | |
987 | struct ifnet *ifp; /* delegated ifp */ | |
988 | u_int32_t type; /* delegated i/f type */ | |
989 | u_int32_t family; /* delegated i/f family */ | |
990 | u_int32_t subfamily; /* delegated i/f sub-family */ | |
fe8ab488 | 991 | uint32_t expensive:1; /* delegated i/f expensive? */ |
39236c6e A |
992 | } if_delegated; |
993 | ||
39037602 A |
994 | uuid_t *if_agentids; /* network agents attached to interface */ |
995 | u_int32_t if_agentcount; | |
3e170ce0 | 996 | |
39037602 | 997 | u_int32_t if_generation; /* generation to use with NECP clients */ |
39236c6e | 998 | u_int32_t if_fg_sendts; /* last send on a fg socket in seconds */ |
39037602 A |
999 | |
1000 | u_int64_t if_data_threshold; | |
1001 | ||
1002 | /* Total bytes in send socket buffer */ | |
1003 | int64_t if_sndbyte_total __attribute__ ((aligned(8))); | |
1004 | /* Total unsent bytes in send socket buffer */ | |
1005 | int64_t if_sndbyte_unsent __attribute__ ((aligned(8))); | |
1006 | /* count of times, when there was data to send when sleep is impending */ | |
1007 | uint32_t if_unsent_data_cnt; | |
39236c6e | 1008 | |
3e170ce0 A |
1009 | #if INET |
1010 | decl_lck_rw_data(, if_inetdata_lock); | |
1011 | void *if_inetdata; | |
1012 | #endif /* INET */ | |
39236c6e A |
1013 | #if INET6 |
1014 | decl_lck_rw_data(, if_inet6data_lock); | |
1015 | void *if_inet6data; | |
1016 | #endif | |
3e170ce0 A |
1017 | decl_lck_rw_data(, if_link_status_lock); |
1018 | struct if_link_status *if_link_status; | |
1019 | struct if_interface_state if_interface_state; | |
4bd07ac2 A |
1020 | struct if_tcp_ecn_stat *if_ipv4_stat; |
1021 | struct if_tcp_ecn_stat *if_ipv6_stat; | |
5ba3f43e A |
1022 | |
1023 | struct if_lim_perf_stat if_lim_stat; | |
6d2010ae A |
1024 | }; |
1025 | ||
5ba3f43e A |
1026 | /* Interface event handling declarations */ |
1027 | extern struct eventhandler_lists_ctxt ifnet_evhdlr_ctxt; | |
1028 | ||
1029 | typedef enum { | |
1030 | INTF_EVENT_CODE_CREATED, | |
1031 | INTF_EVENT_CODE_REMOVED, | |
1032 | INTF_EVENT_CODE_STATUS_UPDATE, | |
1033 | INTF_EVENT_CODE_IPADDR_ATTACHED, | |
1034 | INTF_EVENT_CODE_IPADDR_DETACHED, | |
1035 | INTF_EVENT_CODE_LLADDR_UPDATE, | |
1036 | INTF_EVENT_CODE_MTU_CHANGED, | |
1037 | } intf_event_code_t; | |
1038 | ||
1039 | typedef void (*ifnet_event_fn)(struct eventhandler_entry_arg, struct ifnet *, struct sockaddr *, intf_event_code_t); | |
1040 | EVENTHANDLER_DECLARE(ifnet_event, ifnet_event_fn); | |
1041 | ||
39236c6e A |
1042 | #define IF_TCP_STATINC(_ifp, _s) do { \ |
1043 | if ((_ifp)->if_tcp_stat != NULL) \ | |
1044 | atomic_add_64(&(_ifp)->if_tcp_stat->_s, 1); \ | |
1045 | } while (0); | |
1046 | ||
1047 | #define IF_UDP_STATINC(_ifp, _s) do { \ | |
1048 | if ((_ifp)->if_udp_stat != NULL) \ | |
1049 | atomic_add_64(&(_ifp)->if_udp_stat->_s, 1); \ | |
1050 | } while (0); | |
1051 | ||
6d2010ae | 1052 | /* |
39236c6e | 1053 | * Valid values for if_refflags |
6d2010ae | 1054 | */ |
5ba3f43e A |
1055 | #define IFRF_EMBRYONIC 0x1 /* ifnet is allocated; awaiting attach */ |
1056 | #define IFRF_ATTACHED 0x2 /* ifnet attach is completely done */ | |
1057 | #define IFRF_DETACHING 0x4 /* detach has been requested */ | |
1058 | #define IFRF_ATTACH_MASK \ | |
1059 | (IFRF_EMBRYONIC|IFRF_ATTACHED|IFRF_DETACHING) | |
1060 | ||
1061 | #define IF_FULLY_ATTACHED(_ifp) \ | |
1062 | (((_ifp)->if_refflags & IFRF_ATTACH_MASK) == IFRF_ATTACHED) | |
39236c6e A |
1063 | /* |
1064 | * Valid values for if_start_flags | |
1065 | */ | |
1066 | #define IFSF_FLOW_CONTROLLED 0x1 /* flow controlled */ | |
1067 | ||
4a249263 A |
1068 | /* |
1069 | * Structure describing a `cloning' interface. | |
1070 | */ | |
1071 | struct if_clone { | |
1072 | LIST_ENTRY(if_clone) ifc_list; /* on list of cloners */ | |
6d2010ae A |
1073 | const char *ifc_name; /* name of device, e.g. `vlan' */ |
1074 | size_t ifc_namelen; /* length of name */ | |
1075 | u_int32_t ifc_minifs; /* minimum number of interfaces */ | |
1076 | u_int32_t ifc_maxunit; /* maximum unit number */ | |
1077 | unsigned char *ifc_units; /* bitmap to handle units */ | |
1078 | u_int32_t ifc_bmlen; /* bitmap length */ | |
1079 | ||
1080 | int (*ifc_create)(struct if_clone *, u_int32_t, void *); | |
1081 | int (*ifc_destroy)(struct ifnet *); | |
4a249263 A |
1082 | }; |
1083 | ||
6d2010ae A |
1084 | #define IF_CLONE_INITIALIZER(name, create, destroy, minifs, maxunit) { \ |
1085 | { NULL, NULL }, name, (sizeof (name) - 1), minifs, maxunit, NULL, 0, \ | |
1086 | create, destroy \ | |
1087 | } | |
9bccf70c | 1088 | |
d1ecb069 A |
1089 | #define M_CLONE M_IFADDR |
1090 | ||
1c79356b | 1091 | /* |
6d2010ae A |
1092 | * Macros to manipulate ifqueue. Users of these macros are responsible |
1093 | * for serialization, by holding whatever lock is appropriate for the | |
1094 | * corresponding structure that is referring the ifqueue. | |
1c79356b A |
1095 | */ |
1096 | #define IF_QFULL(ifq) ((ifq)->ifq_len >= (ifq)->ifq_maxlen) | |
1097 | #define IF_DROP(ifq) ((ifq)->ifq_drops++) | |
316670eb A |
1098 | |
1099 | #define IF_ENQUEUE(ifq, m) do { \ | |
6d2010ae A |
1100 | (m)->m_nextpkt = NULL; \ |
1101 | if ((ifq)->ifq_tail == NULL) \ | |
1102 | (ifq)->ifq_head = m; \ | |
1103 | else \ | |
1104 | ((struct mbuf*)(ifq)->ifq_tail)->m_nextpkt = m; \ | |
1105 | (ifq)->ifq_tail = m; \ | |
1106 | (ifq)->ifq_len++; \ | |
316670eb A |
1107 | } while (0) |
1108 | ||
1109 | #define IF_PREPEND(ifq, m) do { \ | |
6d2010ae A |
1110 | (m)->m_nextpkt = (ifq)->ifq_head; \ |
1111 | if ((ifq)->ifq_tail == NULL) \ | |
1112 | (ifq)->ifq_tail = (m); \ | |
1113 | (ifq)->ifq_head = (m); \ | |
1114 | (ifq)->ifq_len++; \ | |
316670eb A |
1115 | } while (0) |
1116 | ||
1117 | #define IF_DEQUEUE(ifq, m) do { \ | |
6d2010ae A |
1118 | (m) = (ifq)->ifq_head; \ |
1119 | if (m != NULL) { \ | |
1120 | if (((ifq)->ifq_head = (m)->m_nextpkt) == NULL) \ | |
1121 | (ifq)->ifq_tail = NULL; \ | |
1122 | (m)->m_nextpkt = NULL; \ | |
1123 | (ifq)->ifq_len--; \ | |
1124 | } \ | |
316670eb A |
1125 | } while (0) |
1126 | ||
1127 | #define IF_REMQUEUE(ifq, m) do { \ | |
6d2010ae A |
1128 | struct mbuf *_p = (ifq)->ifq_head; \ |
1129 | struct mbuf *_n = (m)->m_nextpkt; \ | |
1130 | if ((m) == _p) \ | |
1131 | _p = NULL; \ | |
1132 | while (_p != NULL) { \ | |
1133 | if (_p->m_nextpkt == (m)) \ | |
1134 | break; \ | |
1135 | _p = _p->m_nextpkt; \ | |
1136 | } \ | |
1137 | VERIFY(_p != NULL || ((m) == (ifq)->ifq_head)); \ | |
1138 | if ((m) == (ifq)->ifq_head) \ | |
1139 | (ifq)->ifq_head = _n; \ | |
1140 | if ((m) == (ifq)->ifq_tail) \ | |
1141 | (ifq)->ifq_tail = _p; \ | |
1142 | VERIFY((ifq)->ifq_tail != NULL || (ifq)->ifq_head == NULL); \ | |
1143 | VERIFY((ifq)->ifq_len != 0); \ | |
1144 | --(ifq)->ifq_len; \ | |
1145 | if (_p != NULL) \ | |
1146 | _p->m_nextpkt = _n; \ | |
1147 | (m)->m_nextpkt = NULL; \ | |
316670eb A |
1148 | } while (0) |
1149 | ||
6d2010ae | 1150 | #define IF_DRAIN(ifq) do { \ |
316670eb | 1151 | struct mbuf *_m; \ |
6d2010ae | 1152 | for (;;) { \ |
316670eb A |
1153 | IF_DEQUEUE(ifq, _m); \ |
1154 | if (_m == NULL) \ | |
6d2010ae | 1155 | break; \ |
316670eb | 1156 | m_freem(_m); \ |
6d2010ae A |
1157 | } \ |
1158 | } while (0) | |
1c79356b | 1159 | |
1c79356b A |
1160 | /* |
1161 | * The ifaddr structure contains information about one address | |
1162 | * of an interface. They are maintained by the different address families, | |
1163 | * are allocated and attached when an address is set, and are linked | |
1164 | * together so all addresses for an interface can be located. | |
1165 | */ | |
1166 | struct ifaddr { | |
6d2010ae A |
1167 | decl_lck_mtx_data(, ifa_lock); /* lock for ifaddr */ |
1168 | uint32_t ifa_refcnt; /* ref count, use IFA_{ADD,REM}REF */ | |
1169 | uint32_t ifa_debug; /* debug flags */ | |
1170 | struct sockaddr *ifa_addr; /* address of interface */ | |
1171 | struct sockaddr *ifa_dstaddr; /* other end of p-to-p link */ | |
1c79356b | 1172 | #define ifa_broadaddr ifa_dstaddr /* broadcast address interface */ |
6d2010ae A |
1173 | struct sockaddr *ifa_netmask; /* used to determine subnet */ |
1174 | struct ifnet *ifa_ifp; /* back-pointer to interface */ | |
1c79356b | 1175 | TAILQ_ENTRY(ifaddr) ifa_link; /* queue macro glue */ |
b0d623f7 A |
1176 | void (*ifa_rtrequest) /* check or clean routes (+ or -)'d */ |
1177 | (int, struct rtentry *, struct sockaddr *); | |
6d2010ae A |
1178 | uint32_t ifa_flags; /* mostly rt_flags for cloning */ |
1179 | int32_t ifa_metric; /* cost of going out this interface */ | |
b0d623f7 A |
1180 | void (*ifa_free)(struct ifaddr *); /* callback fn for freeing */ |
1181 | void (*ifa_trace) /* callback fn for tracing refs */ | |
1182 | (struct ifaddr *, int); | |
6d2010ae A |
1183 | void (*ifa_attached)(struct ifaddr *); /* callback fn for attaching */ |
1184 | void (*ifa_detached)(struct ifaddr *); /* callback fn for detaching */ | |
5ba3f43e A |
1185 | #if __arm__ && (__BIGGEST_ALIGNMENT__ > 4) |
1186 | /* For the newer ARMv7k ABI where 64-bit types are 64-bit aligned, but pointers | |
1187 | * are 32-bit: | |
1188 | * Align to 64-bit since we cast to this to struct in6_ifaddr, which is | |
1189 | * 64-bit aligned | |
1190 | */ | |
1191 | } __attribute__ ((aligned(8))); | |
1192 | #else | |
1c79356b | 1193 | }; |
5ba3f43e | 1194 | #endif |
b0d623f7 | 1195 | |
3e170ce0 | 1196 | |
b0d623f7 A |
1197 | /* |
1198 | * Valid values for ifa_flags | |
1199 | */ | |
91447636 A |
1200 | #define IFA_ROUTE RTF_UP /* route installed (0x1) */ |
1201 | #define IFA_CLONING RTF_CLONING /* (0x100) */ | |
b0d623f7 A |
1202 | |
1203 | /* | |
1204 | * Valid values for ifa_debug | |
1205 | */ | |
6d2010ae | 1206 | #define IFD_ATTACHED 0x1 /* attached to list */ |
b0d623f7 A |
1207 | #define IFD_ALLOC 0x2 /* dynamically allocated */ |
1208 | #define IFD_DEBUG 0x4 /* has debugging info */ | |
6d2010ae A |
1209 | #define IFD_LINK 0x8 /* link address */ |
1210 | #define IFD_TRASHED 0x10 /* in trash list */ | |
813fb2f6 | 1211 | #define IFD_DETACHING 0x20 /* detach is in progress */ |
6d2010ae | 1212 | #define IFD_NOTREADY 0x40 /* embryonic; not yet ready */ |
91447636 | 1213 | |
6d2010ae | 1214 | #define IFA_LOCK_ASSERT_HELD(_ifa) \ |
5ba3f43e | 1215 | LCK_MTX_ASSERT(&(_ifa)->ifa_lock, LCK_MTX_ASSERT_OWNED) |
6d2010ae A |
1216 | |
1217 | #define IFA_LOCK_ASSERT_NOTHELD(_ifa) \ | |
5ba3f43e | 1218 | LCK_MTX_ASSERT(&(_ifa)->ifa_lock, LCK_MTX_ASSERT_NOTOWNED) |
6d2010ae A |
1219 | |
1220 | #define IFA_LOCK(_ifa) \ | |
1221 | lck_mtx_lock(&(_ifa)->ifa_lock) | |
1222 | ||
1223 | #define IFA_LOCK_SPIN(_ifa) \ | |
1224 | lck_mtx_lock_spin(&(_ifa)->ifa_lock) | |
1225 | ||
1226 | #define IFA_CONVERT_LOCK(_ifa) do { \ | |
1227 | IFA_LOCK_ASSERT_HELD(_ifa); \ | |
1228 | lck_mtx_convert_spin(&(_ifa)->ifa_lock); \ | |
1229 | } while (0) | |
1230 | ||
1231 | #define IFA_UNLOCK(_ifa) \ | |
1232 | lck_mtx_unlock(&(_ifa)->ifa_lock) | |
1233 | ||
1234 | #define IFA_ADDREF(_ifa) \ | |
1235 | ifa_addref(_ifa, 0) | |
1236 | ||
1237 | #define IFA_ADDREF_LOCKED(_ifa) \ | |
1238 | ifa_addref(_ifa, 1) | |
1239 | ||
1240 | #define IFA_REMREF(_ifa) do { \ | |
1241 | (void) ifa_remref(_ifa, 0); \ | |
1242 | } while (0) | |
1243 | ||
1244 | #define IFA_REMREF_LOCKED(_ifa) \ | |
1245 | ifa_remref(_ifa, 1) | |
1c79356b | 1246 | |
1c79356b A |
1247 | /* |
1248 | * Multicast address structure. This is analogous to the ifaddr | |
1249 | * structure except that it keeps track of multicast addresses. | |
6d2010ae A |
1250 | * Also, the request count here is a count of requests for this |
1251 | * address, not a count of pointers to this structure; anonymous | |
1252 | * membership(s) holds one outstanding request count. | |
1c79356b A |
1253 | */ |
1254 | struct ifmultiaddr { | |
6d2010ae A |
1255 | decl_lck_mtx_data(, ifma_lock); |
1256 | u_int32_t ifma_refcount; /* reference count */ | |
1257 | u_int32_t ifma_anoncnt; /* # of anonymous requests */ | |
1258 | u_int32_t ifma_reqcnt; /* total requests for this address */ | |
1259 | u_int32_t ifma_debug; /* see ifa_debug flags */ | |
1260 | u_int32_t ifma_flags; /* see below */ | |
1c79356b | 1261 | LIST_ENTRY(ifmultiaddr) ifma_link; /* queue macro glue */ |
6d2010ae | 1262 | struct sockaddr *ifma_addr; /* address this membership is for */ |
91447636 | 1263 | struct ifmultiaddr *ifma_ll; /* link-layer translation, if any */ |
6d2010ae A |
1264 | struct ifnet *ifma_ifp; /* back-pointer to interface */ |
1265 | void *ifma_protospec; /* protocol-specific state, if any */ | |
1266 | void (*ifma_trace) /* callback fn for tracing refs */ | |
1267 | (struct ifmultiaddr *, int); | |
1c79356b | 1268 | }; |
1c79356b | 1269 | |
91447636 | 1270 | /* |
6d2010ae | 1271 | * Values for ifma_flags |
91447636 | 1272 | */ |
6d2010ae A |
1273 | #define IFMAF_ANONYMOUS 0x1 /* has anonymous request ref(s) held */ |
1274 | ||
1275 | #define IFMA_LOCK_ASSERT_HELD(_ifma) \ | |
5ba3f43e | 1276 | LCK_MTX_ASSERT(&(_ifma)->ifma_lock, LCK_MTX_ASSERT_OWNED) |
6d2010ae A |
1277 | |
1278 | #define IFMA_LOCK_ASSERT_NOTHELD(_ifma) \ | |
5ba3f43e | 1279 | LCK_MTX_ASSERT(&(_ifma)->ifma_lock, LCK_MTX_ASSERT_NOTOWNED) |
6d2010ae A |
1280 | |
1281 | #define IFMA_LOCK(_ifma) \ | |
1282 | lck_mtx_lock(&(_ifma)->ifma_lock) | |
1283 | ||
1284 | #define IFMA_LOCK_SPIN(_ifma) \ | |
1285 | lck_mtx_lock_spin(&(_ifma)->ifma_lock) | |
1286 | ||
1287 | #define IFMA_CONVERT_LOCK(_ifma) do { \ | |
1288 | IFMA_LOCK_ASSERT_HELD(_ifma); \ | |
1289 | lck_mtx_convert_spin(&(_ifma)->ifma_lock); \ | |
1290 | } while (0) | |
1291 | ||
1292 | #define IFMA_UNLOCK(_ifma) \ | |
1293 | lck_mtx_unlock(&(_ifma)->ifma_lock) | |
1294 | ||
1295 | #define IFMA_ADDREF(_ifma) \ | |
1296 | ifma_addref(_ifma, 0) | |
1297 | ||
1298 | #define IFMA_ADDREF_LOCKED(_ifma) \ | |
1299 | ifma_addref(_ifma, 1) | |
1300 | ||
1301 | #define IFMA_REMREF(_ifma) \ | |
1302 | ifma_remref(_ifma) | |
1303 | ||
39236c6e A |
1304 | /* |
1305 | * Indicate whether or not the immediate interface, or the interface delegated | |
1306 | * by it, is a cellular interface (IFT_CELLULAR). Delegated interface type is | |
1307 | * set/cleared along with the delegated ifp; we cache the type for performance | |
1308 | * to avoid dereferencing delegated ifp each time. | |
1309 | * | |
1310 | * Note that this is meant to be used only for accounting and policy purposes; | |
1311 | * certain places need to explicitly know the immediate interface type, and | |
1312 | * this macro should not be used there. | |
1313 | * | |
1314 | * The test is done against IFT_CELLULAR instead of IFNET_FAMILY_CELLULAR to | |
1315 | * handle certain cases where the family isn't set to the latter. | |
1316 | */ | |
1317 | #define IFNET_IS_CELLULAR(_ifp) \ | |
1318 | ((_ifp)->if_type == IFT_CELLULAR || \ | |
1319 | (_ifp)->if_delegated.type == IFT_CELLULAR) | |
1320 | ||
4bd07ac2 A |
1321 | /* |
1322 | * Indicate whether or not the immediate interface, or the interface delegated | |
1323 | * by it, is an ETHERNET interface. | |
1324 | */ | |
1325 | #define IFNET_IS_ETHERNET(_ifp) \ | |
1326 | ((_ifp)->if_family == IFNET_FAMILY_ETHERNET || \ | |
1327 | (_ifp)->if_delegated.family == IFNET_FAMILY_ETHERNET) | |
39236c6e A |
1328 | /* |
1329 | * Indicate whether or not the immediate interface, or the interface delegated | |
1330 | * by it, is a Wi-Fi interface (IFNET_SUBFAMILY_WIFI). Delegated interface | |
1331 | * subfamily is set/cleared along with the delegated ifp; we cache the subfamily | |
1332 | * for performance to avoid dereferencing delegated ifp each time. | |
1333 | * | |
1334 | * Note that this is meant to be used only for accounting and policy purposes; | |
1335 | * certain places need to explicitly know the immediate interface type, and | |
1336 | * this macro should not be used there. | |
1337 | * | |
1338 | * The test is done against IFNET_SUBFAMILY_WIFI as the family may be set to | |
1339 | * IFNET_FAMILY_ETHERNET (as well as type to IFT_ETHER) which is too generic. | |
1340 | */ | |
1341 | #define IFNET_IS_WIFI(_ifp) \ | |
1342 | ((_ifp)->if_subfamily == IFNET_SUBFAMILY_WIFI || \ | |
1343 | (_ifp)->if_delegated.subfamily == IFNET_SUBFAMILY_WIFI) | |
1344 | ||
fe8ab488 A |
1345 | /* |
1346 | * Indicate whether or not the immediate interface, or the interface delegated | |
1347 | * by it, is a Wired interface (several families). Delegated interface | |
1348 | * family is set/cleared along with the delegated ifp; we cache the family | |
1349 | * for performance to avoid dereferencing delegated ifp each time. | |
1350 | * | |
1351 | * Note that this is meant to be used only for accounting and policy purposes; | |
1352 | * certain places need to explicitly know the immediate interface type, and | |
1353 | * this macro should not be used there. | |
1354 | */ | |
1355 | #define IFNET_IS_WIRED(_ifp) \ | |
1356 | ((_ifp)->if_family == IFNET_FAMILY_ETHERNET || \ | |
1357 | (_ifp)->if_delegated.family == IFNET_FAMILY_ETHERNET || \ | |
1358 | (_ifp)->if_family == IFNET_FAMILY_FIREWIRE || \ | |
1359 | (_ifp)->if_delegated.family == IFNET_FAMILY_FIREWIRE) | |
1360 | ||
39037602 A |
1361 | /* |
1362 | * Indicate whether or not the immediate WiFi interface is on an infrastructure | |
1363 | * network | |
1364 | */ | |
1365 | #define IFNET_IS_WIFI_INFRA(_ifp) \ | |
1366 | ((_ifp)->if_family == IFNET_FAMILY_ETHERNET && \ | |
1367 | (_ifp)->if_subfamily == IFNET_SUBFAMILY_WIFI && \ | |
1368 | !((_ifp)->if_eflags & IFEF_AWDL)) | |
1369 | ||
fe8ab488 A |
1370 | /* |
1371 | * Indicate whether or not the immediate interface, or the interface delegated | |
39037602 A |
1372 | * by it, is marked as expensive. The delegated interface is set/cleared |
1373 | * along with the delegated ifp; we cache the flag for performance to avoid | |
fe8ab488 A |
1374 | * dereferencing delegated ifp each time. |
1375 | * | |
1376 | * Note that this is meant to be used only for policy purposes. | |
1377 | */ | |
1378 | #define IFNET_IS_EXPENSIVE(_ifp) \ | |
1379 | ((_ifp)->if_eflags & IFEF_EXPENSIVE || \ | |
1380 | (_ifp)->if_delegated.expensive) | |
1381 | ||
1382 | /* | |
1383 | * We don't support AWDL interface delegation. | |
1384 | */ | |
1385 | #define IFNET_IS_AWDL_RESTRICTED(_ifp) \ | |
1386 | (((_ifp)->if_eflags & (IFEF_AWDL|IFEF_AWDL_RESTRICTED)) == \ | |
1387 | (IFEF_AWDL|IFEF_AWDL_RESTRICTED)) | |
1388 | ||
39037602 A |
1389 | #define IFNET_IS_INTCOPROC(_ifp) \ |
1390 | ((_ifp)->if_family == IFNET_FAMILY_ETHERNET && \ | |
1391 | (_ifp)->if_subfamily == IFNET_SUBFAMILY_INTCOPROC) | |
fe8ab488 | 1392 | |
39236c6e | 1393 | extern struct ifnethead ifnet_head; |
39037602 | 1394 | extern struct ifnethead ifnet_ordered_head; |
39236c6e A |
1395 | extern struct ifnet **ifindex2ifnet; |
1396 | extern u_int32_t if_sndq_maxlen; | |
1397 | extern u_int32_t if_rcvq_maxlen; | |
1398 | extern int if_index; | |
1399 | extern struct ifaddr **ifnet_addrs; | |
1400 | extern lck_attr_t *ifa_mtx_attr; | |
1401 | extern lck_grp_t *ifa_mtx_grp; | |
1402 | extern lck_grp_t *ifnet_lock_group; | |
1403 | extern lck_attr_t *ifnet_lock_attr; | |
6d2010ae A |
1404 | extern ifnet_t lo_ifp; |
1405 | ||
1406 | extern int if_addmulti(struct ifnet *, const struct sockaddr *, | |
1407 | struct ifmultiaddr **); | |
1408 | extern int if_addmulti_anon(struct ifnet *, const struct sockaddr *, | |
1409 | struct ifmultiaddr **); | |
1410 | extern int if_allmulti(struct ifnet *, int); | |
1411 | extern int if_delmulti(struct ifnet *, const struct sockaddr *); | |
1412 | extern int if_delmulti_ifma(struct ifmultiaddr *); | |
1413 | extern int if_delmulti_anon(struct ifnet *, const struct sockaddr *); | |
1414 | extern void if_down(struct ifnet *); | |
1415 | extern int if_down_all(void); | |
1416 | extern void if_up(struct ifnet *); | |
1417 | __private_extern__ void if_updown(struct ifnet *ifp, int up); | |
1418 | extern int ifioctl(struct socket *, u_long, caddr_t, struct proc *); | |
1419 | extern int ifioctllocked(struct socket *, u_long, caddr_t, struct proc *); | |
1420 | extern struct ifnet *ifunit(const char *); | |
39037602 A |
1421 | extern struct ifnet *ifunit_ref(const char *); |
1422 | extern int ifunit_extract(const char *src, char *dst, size_t dstlen, int *unit); | |
6d2010ae | 1423 | extern struct ifnet *if_withname(struct sockaddr *); |
316670eb A |
1424 | extern void if_qflush(struct ifnet *, int); |
1425 | extern void if_qflush_sc(struct ifnet *, mbuf_svc_class_t, u_int32_t, | |
1426 | u_int32_t *, u_int32_t *, int); | |
6d2010ae A |
1427 | |
1428 | extern struct if_clone *if_clone_lookup(const char *, u_int32_t *); | |
1429 | extern int if_clone_attach(struct if_clone *); | |
1430 | extern void if_clone_detach(struct if_clone *); | |
1431 | ||
39037602 | 1432 | extern u_int32_t if_functional_type(struct ifnet *, bool); |
3e170ce0 | 1433 | |
6d2010ae A |
1434 | extern errno_t if_mcasts_update(struct ifnet *); |
1435 | ||
1436 | typedef enum { | |
1437 | IFNET_LCK_ASSERT_EXCLUSIVE, /* RW: held as writer */ | |
1438 | IFNET_LCK_ASSERT_SHARED, /* RW: held as reader */ | |
1439 | IFNET_LCK_ASSERT_OWNED, /* RW: writer/reader, MTX: held */ | |
1440 | IFNET_LCK_ASSERT_NOTOWNED /* not held */ | |
1441 | } ifnet_lock_assert_t; | |
1442 | ||
39236c6e A |
1443 | #define IF_LLADDR(_ifp) \ |
1444 | (LLADDR(SDL(((_ifp)->if_lladdr)->ifa_addr))) | |
1445 | ||
4d15aeb1 A |
1446 | #define IF_INDEX_IN_RANGE(_ind_) ((_ind_) > 0 && \ |
1447 | (unsigned int)(_ind_) <= (unsigned int)if_index) | |
1448 | ||
6d2010ae A |
1449 | __private_extern__ void ifnet_lock_assert(struct ifnet *, ifnet_lock_assert_t); |
1450 | __private_extern__ void ifnet_lock_shared(struct ifnet *ifp); | |
1451 | __private_extern__ void ifnet_lock_exclusive(struct ifnet *ifp); | |
1452 | __private_extern__ void ifnet_lock_done(struct ifnet *ifp); | |
1453 | ||
3e170ce0 A |
1454 | #if INET |
1455 | __private_extern__ void if_inetdata_lock_shared(struct ifnet *ifp); | |
1456 | __private_extern__ void if_inetdata_lock_exclusive(struct ifnet *ifp); | |
1457 | __private_extern__ void if_inetdata_lock_done(struct ifnet *ifp); | |
1458 | #endif | |
1459 | ||
39236c6e A |
1460 | #if INET6 |
1461 | __private_extern__ void if_inet6data_lock_shared(struct ifnet *ifp); | |
1462 | __private_extern__ void if_inet6data_lock_exclusive(struct ifnet *ifp); | |
1463 | __private_extern__ void if_inet6data_lock_done(struct ifnet *ifp); | |
1464 | #endif | |
1465 | ||
6d2010ae A |
1466 | __private_extern__ void ifnet_head_lock_shared(void); |
1467 | __private_extern__ void ifnet_head_lock_exclusive(void); | |
1468 | __private_extern__ void ifnet_head_done(void); | |
39037602 | 1469 | __private_extern__ void ifnet_head_assert_exclusive(void); |
6d2010ae A |
1470 | |
1471 | __private_extern__ errno_t ifnet_set_idle_flags_locked(ifnet_t, u_int32_t, | |
1472 | u_int32_t); | |
1473 | __private_extern__ int ifnet_is_attached(struct ifnet *, int refio); | |
39037602 | 1474 | __private_extern__ void ifnet_incr_iorefcnt(struct ifnet *); |
6d2010ae | 1475 | __private_extern__ void ifnet_decr_iorefcnt(struct ifnet *); |
316670eb A |
1476 | __private_extern__ void ifnet_set_start_cycle(struct ifnet *, |
1477 | struct timespec *); | |
1478 | __private_extern__ void ifnet_set_poll_cycle(struct ifnet *, | |
1479 | struct timespec *); | |
6d2010ae A |
1480 | |
1481 | __private_extern__ void if_attach_ifa(struct ifnet *, struct ifaddr *); | |
1482 | __private_extern__ void if_attach_link_ifa(struct ifnet *, struct ifaddr *); | |
1483 | __private_extern__ void if_detach_ifa(struct ifnet *, struct ifaddr *); | |
1484 | __private_extern__ void if_detach_link_ifa(struct ifnet *, struct ifaddr *); | |
1485 | ||
7ddcb079 A |
1486 | __private_extern__ void dlil_if_lock(void); |
1487 | __private_extern__ void dlil_if_unlock(void); | |
1488 | __private_extern__ void dlil_if_lock_assert(void); | |
1489 | ||
6d2010ae | 1490 | extern struct ifaddr *ifa_ifwithaddr(const struct sockaddr *); |
39037602 | 1491 | extern struct ifaddr *ifa_ifwithaddr_locked(const struct sockaddr *); |
316670eb A |
1492 | extern struct ifaddr *ifa_ifwithaddr_scoped(const struct sockaddr *, |
1493 | unsigned int); | |
39037602 A |
1494 | extern struct ifaddr *ifa_ifwithaddr_scoped_locked(const struct sockaddr *, |
1495 | unsigned int); | |
6d2010ae A |
1496 | extern struct ifaddr *ifa_ifwithdstaddr(const struct sockaddr *); |
1497 | extern struct ifaddr *ifa_ifwithnet(const struct sockaddr *); | |
316670eb A |
1498 | extern struct ifaddr *ifa_ifwithnet_scoped(const struct sockaddr *, |
1499 | unsigned int); | |
6d2010ae A |
1500 | extern struct ifaddr *ifa_ifwithroute(int, const struct sockaddr *, |
1501 | const struct sockaddr *); | |
316670eb A |
1502 | extern struct ifaddr *ifa_ifwithroute_locked(int, const struct sockaddr *, |
1503 | const struct sockaddr *); | |
1504 | extern struct ifaddr *ifa_ifwithroute_scoped_locked(int, | |
1505 | const struct sockaddr *, const struct sockaddr *, unsigned int); | |
6d2010ae A |
1506 | extern struct ifaddr *ifaof_ifpforaddr(const struct sockaddr *, struct ifnet *); |
1507 | __private_extern__ struct ifaddr *ifa_ifpgetprimary(struct ifnet *, int); | |
1508 | extern void ifa_addref(struct ifaddr *, int); | |
1509 | extern struct ifaddr *ifa_remref(struct ifaddr *, int); | |
1510 | extern void ifa_lock_init(struct ifaddr *); | |
1511 | extern void ifa_lock_destroy(struct ifaddr *); | |
1512 | extern void ifma_addref(struct ifmultiaddr *, int); | |
1513 | extern void ifma_remref(struct ifmultiaddr *); | |
1514 | ||
1515 | extern void ifa_init(void); | |
1516 | ||
1517 | __private_extern__ struct in_ifaddr *ifa_foraddr(unsigned int); | |
1518 | __private_extern__ struct in_ifaddr *ifa_foraddr_scoped(unsigned int, | |
1519 | unsigned int); | |
1520 | ||
316670eb A |
1521 | struct ifreq; |
1522 | extern errno_t ifnet_getset_opportunistic(struct ifnet *, u_long, | |
1523 | struct ifreq *, struct proc *); | |
1524 | extern int ifnet_get_throttle(struct ifnet *, u_int32_t *); | |
1525 | extern int ifnet_set_throttle(struct ifnet *, u_int32_t); | |
39236c6e A |
1526 | extern errno_t ifnet_getset_log(struct ifnet *, u_long, |
1527 | struct ifreq *, struct proc *); | |
1528 | extern int ifnet_set_log(struct ifnet *, int32_t, uint32_t, int32_t, int32_t); | |
1529 | extern int ifnet_get_log(struct ifnet *, int32_t *, uint32_t *, int32_t *, | |
1530 | int32_t *); | |
1531 | extern int ifnet_notify_address(struct ifnet *, int); | |
5ba3f43e A |
1532 | extern void ifnet_notify_data_threshold(struct ifnet *); |
1533 | ||
1534 | #define IF_AFDATA_RLOCK if_afdata_rlock | |
1535 | #define IF_AFDATA_RUNLOCK if_afdata_unlock | |
1536 | #define IF_AFDATA_WLOCK if_afdata_wlock | |
1537 | #define IF_AFDATA_WUNLOCK if_afdata_unlock | |
1538 | #define IF_AFDATA_WLOCK_ASSERT if_afdata_wlock_assert | |
1539 | #define IF_AFDATA_LOCK_ASSERT if_afdata_lock_assert | |
1540 | #define IF_AFDATA_UNLOCK_ASSERT if_afdata_unlock_assert | |
1541 | ||
1542 | static inline void | |
1543 | if_afdata_rlock (struct ifnet *ifp, int af) | |
1544 | { | |
1545 | switch (af) { | |
1546 | #if INET | |
1547 | case AF_INET: | |
1548 | lck_rw_lock_shared(&ifp->if_inetdata_lock); | |
1549 | break; | |
1550 | #endif | |
1551 | #if INET6 | |
1552 | case AF_INET6: | |
1553 | lck_rw_lock_shared(&ifp->if_inet6data_lock); | |
1554 | break; | |
1555 | #endif | |
1556 | default: | |
1557 | VERIFY(0); | |
1558 | /* NOTREACHED */ | |
1559 | } | |
1560 | return; | |
1561 | } | |
1562 | ||
1563 | static inline void | |
1564 | if_afdata_runlock (struct ifnet *ifp, int af) | |
1565 | { | |
1566 | switch (af) { | |
1567 | #if INET | |
1568 | case AF_INET: | |
1569 | lck_rw_done(&ifp->if_inetdata_lock); | |
1570 | break; | |
1571 | #endif | |
1572 | #if INET6 | |
1573 | case AF_INET6: | |
1574 | lck_rw_done(&ifp->if_inet6data_lock); | |
1575 | break; | |
1576 | #endif | |
1577 | default: | |
1578 | VERIFY(0); | |
1579 | /* NOTREACHED */ | |
1580 | } | |
1581 | return; | |
1582 | } | |
1583 | ||
1584 | static inline void | |
1585 | if_afdata_wlock (struct ifnet *ifp, int af) | |
1586 | { | |
1587 | switch (af) { | |
1588 | #if INET | |
1589 | case AF_INET: | |
1590 | lck_rw_lock_exclusive(&ifp->if_inetdata_lock); | |
1591 | break; | |
1592 | #endif | |
1593 | #if INET6 | |
1594 | case AF_INET6: | |
1595 | lck_rw_lock_exclusive(&ifp->if_inet6data_lock); | |
1596 | break; | |
1597 | #endif | |
1598 | default: | |
1599 | VERIFY(0); | |
1600 | /* NOTREACHED */ | |
1601 | } | |
1602 | return; | |
1603 | } | |
1604 | ||
1605 | static inline void | |
1606 | if_afdata_unlock (struct ifnet *ifp, int af) | |
1607 | { | |
1608 | switch (af) { | |
1609 | #if INET | |
1610 | case AF_INET: | |
1611 | lck_rw_done(&ifp->if_inetdata_lock); | |
1612 | break; | |
1613 | #endif | |
1614 | #if INET6 | |
1615 | case AF_INET6: | |
1616 | lck_rw_done(&ifp->if_inet6data_lock); | |
1617 | break; | |
1618 | #endif | |
1619 | default: | |
1620 | VERIFY(0); | |
1621 | /* NOTREACHED */ | |
1622 | } | |
1623 | return; | |
1624 | } | |
1625 | ||
1626 | static inline void | |
1627 | if_afdata_wlock_assert (struct ifnet *ifp, int af) | |
1628 | { | |
1629 | #if !MACH_ASSERT | |
1630 | #pragma unused(ifp) | |
1631 | #endif | |
1632 | switch (af) { | |
1633 | #if INET | |
1634 | case AF_INET: | |
1635 | LCK_RW_ASSERT(&ifp->if_inetdata_lock, LCK_RW_ASSERT_EXCLUSIVE); | |
1636 | break; | |
1637 | #endif | |
1638 | #if INET6 | |
1639 | case AF_INET6: | |
1640 | LCK_RW_ASSERT(&ifp->if_inet6data_lock, LCK_RW_ASSERT_EXCLUSIVE); | |
1641 | break; | |
1642 | #endif | |
1643 | default: | |
1644 | VERIFY(0); | |
1645 | /* NOTREACHED */ | |
1646 | } | |
1647 | return; | |
1648 | } | |
1649 | ||
1650 | static inline void | |
1651 | if_afdata_unlock_assert (struct ifnet *ifp, int af) | |
1652 | { | |
1653 | #if !MACH_ASSERT | |
1654 | #pragma unused(ifp) | |
1655 | #endif | |
1656 | switch (af) { | |
1657 | #if INET | |
1658 | case AF_INET: | |
1659 | LCK_RW_ASSERT(&ifp->if_inetdata_lock, LCK_RW_ASSERT_NOTHELD); | |
1660 | break; | |
1661 | #endif | |
1662 | #if INET6 | |
1663 | case AF_INET6: | |
1664 | LCK_RW_ASSERT(&ifp->if_inet6data_lock, LCK_RW_ASSERT_NOTHELD); | |
1665 | break; | |
1666 | #endif | |
1667 | default: | |
1668 | VERIFY(0); | |
1669 | /* NOTREACHED */ | |
1670 | } | |
1671 | return; | |
1672 | } | |
1673 | ||
1674 | static inline void | |
1675 | if_afdata_lock_assert (struct ifnet *ifp, int af) | |
1676 | { | |
1677 | #if !MACH_ASSERT | |
1678 | #pragma unused(ifp) | |
1679 | #endif | |
1680 | switch (af) { | |
1681 | #if INET | |
1682 | case AF_INET: | |
1683 | LCK_RW_ASSERT(&ifp->if_inetdata_lock, LCK_RW_ASSERT_HELD); | |
1684 | break; | |
1685 | #endif | |
1686 | #if INET6 | |
1687 | case AF_INET6: | |
1688 | LCK_RW_ASSERT(&ifp->if_inet6data_lock, LCK_RW_ASSERT_HELD); | |
1689 | break; | |
1690 | #endif | |
1691 | default: | |
1692 | VERIFY(0); | |
1693 | /* NOTREACHED */ | |
1694 | } | |
1695 | return; | |
1696 | } | |
316670eb | 1697 | |
6d2010ae A |
1698 | #if INET6 |
1699 | struct in6_addr; | |
1700 | __private_extern__ struct in6_ifaddr *ifa_foraddr6(struct in6_addr *); | |
1701 | __private_extern__ struct in6_ifaddr *ifa_foraddr6_scoped(struct in6_addr *, | |
1702 | unsigned int); | |
1703 | #endif /* INET6 */ | |
1704 | ||
1705 | __private_extern__ void if_data_internal_to_if_data(struct ifnet *ifp, | |
1706 | const struct if_data_internal *if_data_int, struct if_data *if_data); | |
1707 | __private_extern__ void if_data_internal_to_if_data64(struct ifnet *ifp, | |
1708 | const struct if_data_internal *if_data_int, struct if_data64 *if_data64); | |
1709 | __private_extern__ void if_copy_traffic_class(struct ifnet *ifp, | |
1710 | struct if_traffic_class *if_tc); | |
316670eb A |
1711 | __private_extern__ void if_copy_data_extended(struct ifnet *ifp, |
1712 | struct if_data_extended *if_de); | |
1713 | __private_extern__ void if_copy_packet_stats(struct ifnet *ifp, | |
1714 | struct if_packet_stats *if_ps); | |
1715 | __private_extern__ void if_copy_rxpoll_stats(struct ifnet *ifp, | |
1716 | struct if_rxpoll_stats *if_rs); | |
6d2010ae A |
1717 | |
1718 | __private_extern__ struct rtentry *ifnet_cached_rtlookup_inet(struct ifnet *, | |
1719 | struct in_addr); | |
1720 | #if INET6 | |
1721 | __private_extern__ struct rtentry *ifnet_cached_rtlookup_inet6(struct ifnet *, | |
1722 | struct in6_addr *); | |
1723 | #endif /* INET6 */ | |
1724 | ||
3e170ce0 A |
1725 | __private_extern__ errno_t if_state_update(struct ifnet *, |
1726 | struct if_interface_state *); | |
1727 | __private_extern__ void if_get_state(struct ifnet *, | |
1728 | struct if_interface_state *); | |
1729 | __private_extern__ errno_t if_probe_connectivity(struct ifnet *ifp, | |
1730 | u_int32_t conn_probe); | |
1731 | __private_extern__ void if_lqm_update(struct ifnet *, int32_t, int); | |
316670eb A |
1732 | __private_extern__ void ifnet_update_sndq(struct ifclassq *, cqev_t); |
1733 | __private_extern__ void ifnet_update_rcv(struct ifnet *, cqev_t); | |
1734 | ||
39236c6e A |
1735 | __private_extern__ void ifnet_flowadv(uint32_t); |
1736 | ||
316670eb A |
1737 | __private_extern__ errno_t ifnet_set_input_bandwidths(struct ifnet *, |
1738 | struct if_bandwidths *); | |
1739 | __private_extern__ errno_t ifnet_set_output_bandwidths(struct ifnet *, | |
1740 | struct if_bandwidths *, boolean_t); | |
1741 | __private_extern__ u_int64_t ifnet_output_linkrate(struct ifnet *); | |
1742 | __private_extern__ u_int64_t ifnet_input_linkrate(struct ifnet *); | |
39236c6e A |
1743 | |
1744 | __private_extern__ errno_t ifnet_set_input_latencies(struct ifnet *, | |
1745 | struct if_latencies *); | |
1746 | __private_extern__ errno_t ifnet_set_output_latencies(struct ifnet *, | |
1747 | struct if_latencies *, boolean_t); | |
1748 | ||
3e170ce0 A |
1749 | __private_extern__ void ifnet_clear_netagent(uuid_t); |
1750 | ||
1751 | __private_extern__ int ifnet_set_netsignature(struct ifnet *, uint8_t, | |
1752 | uint8_t, uint16_t, uint8_t *); | |
1753 | __private_extern__ int ifnet_get_netsignature(struct ifnet *, uint8_t, | |
1754 | uint8_t *, uint16_t *, uint8_t *); | |
1755 | ||
5ba3f43e A |
1756 | #if INET6 |
1757 | struct ipv6_prefix; | |
1758 | __private_extern__ int ifnet_set_nat64prefix(struct ifnet *, | |
1759 | struct ipv6_prefix *); | |
1760 | __private_extern__ int ifnet_get_nat64prefix(struct ifnet *, | |
1761 | struct ipv6_prefix *); | |
1762 | #endif | |
1763 | ||
39037602 A |
1764 | /* Required exclusive ifnet_head lock */ |
1765 | __private_extern__ void ifnet_remove_from_ordered_list(struct ifnet *); | |
1766 | ||
1767 | __private_extern__ void ifnet_increment_generation(struct ifnet *); | |
1768 | __private_extern__ u_int32_t ifnet_get_generation(struct ifnet *); | |
1769 | ||
5ba3f43e A |
1770 | /* Adding and deleting netagents will take ifnet lock */ |
1771 | __private_extern__ int if_add_netagent(struct ifnet *, uuid_t); | |
1772 | __private_extern__ int if_delete_netagent(struct ifnet *, uuid_t); | |
39037602 | 1773 | |
5ba3f43e A |
1774 | extern int if_set_qosmarking_mode(struct ifnet *, u_int32_t); |
1775 | __private_extern__ uint32_t ifnet_mbuf_packetpreamblelen(struct ifnet *); | |
1776 | __private_extern__ void intf_event_enqueue_nwk_wq_entry(struct ifnet *ifp, | |
1777 | struct sockaddr *addrp, uint32_t intf_event_code); | |
1778 | __private_extern__ void ifnet_update_stats_per_flow(struct ifnet_stats_per_flow *, | |
1779 | struct ifnet *); | |
1780 | #if !CONFIG_EMBEDDED | |
39236c6e A |
1781 | __private_extern__ errno_t ifnet_framer_stub(struct ifnet *, struct mbuf **, |
1782 | const struct sockaddr *, const char *, const char *, u_int32_t *, | |
1783 | u_int32_t *); | |
5ba3f43e A |
1784 | #endif /* !CONFIG_EMBEDDED */ |
1785 | __private_extern__ void ifnet_enqueue_multi_setup(struct ifnet *, uint16_t, | |
1786 | uint16_t); | |
1787 | __private_extern__ errno_t ifnet_enqueue_mbuf(struct ifnet *, struct mbuf *, | |
1788 | boolean_t, boolean_t *); | |
316670eb A |
1789 | #endif /* BSD_KERNEL_PRIVATE */ |
1790 | #ifdef XNU_KERNEL_PRIVATE | |
1791 | /* for uuid.c */ | |
1792 | __private_extern__ int uuid_get_ethernet(u_int8_t *); | |
6d2010ae | 1793 | #endif /* XNU_KERNEL_PRIVATE */ |
1c79356b | 1794 | #endif /* !_NET_IF_VAR_H_ */ |