]>
Commit | Line | Data |
---|---|---|
1c79356b | 1 | /* |
a39ff7e2 | 2 | * Copyright (c) 2000-2018 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 | |
d9a64523 | 78 | #ifdef BSD_KERNEL_PRIVATE |
5ba3f43e A |
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 |
d9a64523 A |
652 | #define IFNETS_MAX 64 |
653 | ||
91447636 A |
654 | /* |
655 | * Internal storage of if_data. This is bound to change. Various places in the | |
656 | * stack will translate this data structure in to the externally visible | |
6d2010ae A |
657 | * if_data structure above. Note that during interface attach time, the |
658 | * embedded if_data structure in ifnet is cleared, with the exception of | |
659 | * some non-statistics related fields. | |
91447636 A |
660 | */ |
661 | struct if_data_internal { | |
662 | /* generic interface information */ | |
2d21ac55 A |
663 | u_char ifi_type; /* ethernet, tokenring, etc */ |
664 | u_char ifi_typelen; /* Length of frame type id */ | |
665 | u_char ifi_physical; /* e.g., AUI, Thinnet, 10base-T, etc */ | |
666 | u_char ifi_addrlen; /* media address length */ | |
667 | u_char ifi_hdrlen; /* media header length */ | |
668 | u_char ifi_recvquota; /* polling quota for receive intrs */ | |
669 | u_char ifi_xmitquota; /* polling quota for xmit intrs */ | |
670 | u_char ifi_unused1; /* for future use */ | |
671 | u_int32_t ifi_mtu; /* maximum transmission unit */ | |
672 | u_int32_t ifi_metric; /* routing metric (external only) */ | |
673 | u_int32_t ifi_baudrate; /* linespeed */ | |
1c79356b | 674 | /* volatile statistics */ |
91447636 A |
675 | u_int64_t ifi_ipackets; /* packets received on interface */ |
676 | u_int64_t ifi_ierrors; /* input errors on interface */ | |
677 | u_int64_t ifi_opackets; /* packets sent on interface */ | |
678 | u_int64_t ifi_oerrors; /* output errors on interface */ | |
679 | u_int64_t ifi_collisions; /* collisions on csma interfaces */ | |
2d21ac55 A |
680 | u_int64_t ifi_ibytes; /* total number of octets received */ |
681 | u_int64_t ifi_obytes; /* total number of octets sent */ | |
91447636 A |
682 | u_int64_t ifi_imcasts; /* packets received via multicast */ |
683 | u_int64_t ifi_omcasts; /* packets sent via multicast */ | |
684 | u_int64_t ifi_iqdrops; /* dropped on input, this interface */ | |
685 | u_int64_t ifi_noproto; /* destined for unsupported protocol */ | |
2d21ac55 A |
686 | u_int32_t ifi_recvtiming; /* usec spent receiving when timing */ |
687 | u_int32_t ifi_xmittiming; /* usec spent xmitting when timing */ | |
316670eb | 688 | u_int64_t ifi_alignerrs; /* unaligned (32-bit) input pkts */ |
39236c6e A |
689 | u_int64_t ifi_dt_bytes; /* Data threshold counter */ |
690 | u_int64_t ifi_fpackets; /* forwarded packets on interface */ | |
691 | u_int64_t ifi_fbytes; /* forwarded bytes on interface */ | |
1c79356b | 692 | struct timeval ifi_lastchange; /* time of last administrative change */ |
9d749ea3 | 693 | struct timeval ifi_lastupdown; /* time of last up/down event */ |
2d21ac55 | 694 | u_int32_t ifi_hwassist; /* HW offload capabilities */ |
b0d623f7 A |
695 | u_int32_t ifi_tso_v4_mtu; /* TCP Segment Offload IPv4 maximum segment size */ |
696 | u_int32_t ifi_tso_v6_mtu; /* TCP Segment Offload IPv6 maximum segment size */ | |
1c79356b | 697 | }; |
316670eb | 698 | #endif /* BSD_KERNEL_PRIVATE */ |
91447636 | 699 | |
6d2010ae | 700 | #ifdef PRIVATE |
91447636 A |
701 | #define if_mtu if_data.ifi_mtu |
702 | #define if_type if_data.ifi_type | |
703 | #define if_typelen if_data.ifi_typelen | |
704 | #define if_physical if_data.ifi_physical | |
705 | #define if_addrlen if_data.ifi_addrlen | |
706 | #define if_hdrlen if_data.ifi_hdrlen | |
707 | #define if_metric if_data.ifi_metric | |
708 | #define if_baudrate if_data.ifi_baudrate | |
709 | #define if_hwassist if_data.ifi_hwassist | |
710 | #define if_ipackets if_data.ifi_ipackets | |
711 | #define if_ierrors if_data.ifi_ierrors | |
712 | #define if_opackets if_data.ifi_opackets | |
713 | #define if_oerrors if_data.ifi_oerrors | |
714 | #define if_collisions if_data.ifi_collisions | |
715 | #define if_ibytes if_data.ifi_ibytes | |
716 | #define if_obytes if_data.ifi_obytes | |
717 | #define if_imcasts if_data.ifi_imcasts | |
718 | #define if_omcasts if_data.ifi_omcasts | |
719 | #define if_iqdrops if_data.ifi_iqdrops | |
720 | #define if_noproto if_data.ifi_noproto | |
721 | #define if_lastchange if_data.ifi_lastchange | |
722 | #define if_recvquota if_data.ifi_recvquota | |
723 | #define if_xmitquota if_data.ifi_xmitquota | |
6d2010ae | 724 | #endif /* PRIVATE */ |
316670eb | 725 | #ifdef BSD_KERNEL_PRIVATE |
b0d623f7 A |
726 | #define if_tso_v4_mtu if_data.ifi_tso_v4_mtu |
727 | #define if_tso_v6_mtu if_data.ifi_tso_v6_mtu | |
316670eb | 728 | #define if_alignerrs if_data.ifi_alignerrs |
39236c6e A |
729 | #define if_dt_bytes if_data.ifi_dt_bytes |
730 | #define if_fpackets if_data.ifi_fpackets | |
731 | #define if_fbytes if_data.ifi_fbytes | |
9d749ea3 | 732 | #define if_lastupdown if_data.ifi_lastupdown |
316670eb | 733 | #endif /* BSD_KERNEL_PRIVATE */ |
91447636 | 734 | |
316670eb | 735 | #ifdef BSD_KERNEL_PRIVATE |
91447636 A |
736 | /* |
737 | * Forward structure declarations for function prototypes [sic]. | |
738 | */ | |
6d2010ae A |
739 | struct proc; |
740 | struct rtentry; | |
741 | struct socket; | |
91447636 | 742 | struct ifnet_filter; |
6d2010ae A |
743 | struct mbuf; |
744 | struct ifaddr; | |
745 | struct tqdummy; | |
746 | struct proto_hash_entry; | |
747 | struct dlil_threading_info; | |
316670eb A |
748 | struct tcpstat_local; |
749 | struct udpstat_local; | |
6d2010ae A |
750 | #if PF |
751 | struct pfi_kif; | |
752 | #endif /* PF */ | |
91447636 | 753 | |
6d2010ae A |
754 | /* we use TAILQs so that the order of instantiation is preserved in the list */ |
755 | TAILQ_HEAD(ifnethead, ifnet); | |
756 | TAILQ_HEAD(ifaddrhead, ifaddr); | |
6d2010ae A |
757 | LIST_HEAD(ifmultihead, ifmultiaddr); |
758 | TAILQ_HEAD(tailq_head, tqdummy); | |
91447636 A |
759 | TAILQ_HEAD(ifnet_filter_head, ifnet_filter); |
760 | TAILQ_HEAD(ddesc_head_name, dlil_demux_desc); | |
5c9f4661 A |
761 | |
762 | extern boolean_t intcoproc_unrestricted; | |
316670eb | 763 | #endif /* BSD_KERNEL_PRIVATE */ |
91447636 | 764 | |
6d2010ae A |
765 | #ifdef PRIVATE |
766 | /* | |
5ba3f43e | 767 | * All of the following IF_HWASSIST_* flags are defined in kpi_interface.h as |
6d2010ae A |
768 | * IFNET_* flags. These are redefined here as constants to avoid failures to |
769 | * build user level programs that can not include kpi_interface.h. It is | |
770 | * important to keep this in sync with the definitions in kpi_interface.h. | |
771 | * The corresponding constant for each definition is mentioned in the comment. | |
b0d623f7 | 772 | * |
6d2010ae | 773 | * Bottom 16 bits reserved for hardware checksum |
b0d623f7 A |
774 | */ |
775 | #define IF_HWASSIST_CSUM_IP 0x0001 /* will csum IP, IFNET_CSUM_IP */ | |
776 | #define IF_HWASSIST_CSUM_TCP 0x0002 /* will csum TCP, IFNET_CSUM_TCP */ | |
777 | #define IF_HWASSIST_CSUM_UDP 0x0004 /* will csum UDP, IFNET_CSUM_UDP */ | |
778 | #define IF_HWASSIST_CSUM_IP_FRAGS 0x0008 /* will csum IP fragments, IFNET_CSUM_FRAGMENT */ | |
779 | #define IF_HWASSIST_CSUM_FRAGMENT 0x0010 /* will do IP fragmentation, IFNET_IP_FRAGMENT */ | |
6d2010ae A |
780 | #define IF_HWASSIST_CSUM_TCPIPV6 0x0020 /* will csum TCPv6, IFNET_CSUM_TCPIPV6 */ |
781 | #define IF_HWASSIST_CSUM_UDPIPV6 0x0040 /* will csum UDPv6, IFNET_CSUM_UDP */ | |
782 | #define IF_HWASSIST_CSUM_FRAGMENT_IPV6 0x0080 /* will do IPv6 fragmentation, IFNET_IPV6_FRAGMENT */ | |
39236c6e | 783 | #define IF_HWASSIST_CSUM_PARTIAL 0x1000 /* simple Sum16 computation, IFNET_CSUM_PARTIAL */ |
5ba3f43e | 784 | #define IF_HWASSIST_CSUM_ZERO_INVERT 0x2000 /* capable of inverting csum of 0 to -0 (0xffff) */ |
91447636 A |
785 | #define IF_HWASSIST_CSUM_MASK 0xffff |
786 | #define IF_HWASSIST_CSUM_FLAGS(hwassist) ((hwassist) & IF_HWASSIST_CSUM_MASK) | |
787 | ||
788 | /* VLAN support */ | |
b0d623f7 A |
789 | #define IF_HWASSIST_VLAN_TAGGING 0x00010000 /* supports VLAN tagging, IFNET_VLAN_TAGGING */ |
790 | #define IF_HWASSIST_VLAN_MTU 0x00020000 /* supports VLAN MTU-sized packet (for software VLAN), IFNET_VLAN_MTU */ | |
791 | ||
792 | /* TCP Segment Offloading support */ | |
793 | ||
794 | #define IF_HWASSIST_TSO_V4 0x00200000 /* will do TCP Segment offload for IPv4, IFNET_TSO_IPV4 */ | |
795 | #define IF_HWASSIST_TSO_V6 0x00400000 /* will do TCP Segment offload for IPv6, IFNET_TSO_IPV6 */ | |
2d21ac55 | 796 | #endif /* PRIVATE */ |
1c79356b | 797 | |
39236c6e A |
798 | #ifdef PRIVATE |
799 | #define IFXNAMSIZ (IFNAMSIZ + 8) /* external name (name + unit) */ | |
800 | #endif | |
801 | ||
316670eb A |
802 | #ifdef BSD_KERNEL_PRIVATE |
803 | /* | |
804 | * ifnet is private to BSD portion of kernel | |
805 | */ | |
39236c6e | 806 | #include <sys/mcache.h> |
6d2010ae A |
807 | #include <sys/tree.h> |
808 | #include <netinet/in.h> | |
39236c6e | 809 | #include <net/if_dl.h> |
316670eb | 810 | #include <net/classq/if_classq.h> |
39236c6e | 811 | #include <net/if_types.h> |
2d21ac55 | 812 | |
6d2010ae | 813 | RB_HEAD(ll_reach_tree, if_llreach); /* define struct ll_reach_tree */ |
91447636 | 814 | |
5ba3f43e A |
815 | |
816 | typedef errno_t (*dlil_input_func)(ifnet_t ifp, mbuf_t m_head, | |
817 | mbuf_t m_tail, const struct ifnet_stat_increment_param *s, | |
818 | boolean_t poll, struct thread *tp); | |
819 | typedef errno_t (*dlil_output_func)(ifnet_t interface, mbuf_t data); | |
820 | ||
39236c6e | 821 | #define if_name(ifp) ifp->if_xname |
1c79356b A |
822 | /* |
823 | * Structure defining a network interface. | |
824 | * | |
825 | * (Would like to call this struct ``if'', but C isn't PL/1.) | |
826 | */ | |
827 | struct ifnet { | |
6d2010ae A |
828 | /* |
829 | * Lock (RW or mutex) to protect this data structure (static storage.) | |
830 | */ | |
831 | decl_lck_rw_data(, if_lock); | |
832 | void *if_softc; /* pointer to driver state */ | |
833 | const char *if_name; /* name, e.g. ``en'' or ``lo'' */ | |
39236c6e | 834 | const char *if_xname; /* external name (name + unit) */ |
316670eb | 835 | struct if_description if_desc; /* extended description */ |
6d2010ae A |
836 | TAILQ_ENTRY(ifnet) if_link; /* all struct ifnets are chained */ |
837 | TAILQ_ENTRY(ifnet) if_detaching_link; /* list of detaching ifnets */ | |
39037602 | 838 | TAILQ_ENTRY(ifnet) if_ordered_link; /* list of ordered ifnets */ |
6d2010ae A |
839 | |
840 | decl_lck_mtx_data(, if_ref_lock) | |
39236c6e | 841 | u_int32_t if_refflags; /* see IFRF flags below */ |
6d2010ae A |
842 | u_int32_t if_refio; /* number of io ops to the underlying driver */ |
843 | ||
844 | #define if_list if_link | |
845 | struct ifaddrhead if_addrhead; /* linked list of addresses per if */ | |
846 | #define if_addrlist if_addrhead | |
847 | struct ifaddr *if_lladdr; /* link address (first/permanent) */ | |
848 | ||
39037602 A |
849 | u_int32_t if_qosmarking_mode; /* generation to use with NECP clients */ |
850 | ||
6d2010ae A |
851 | int if_pcount; /* number of promiscuous listeners */ |
852 | struct bpf_if *if_bpf; /* packet filter structure */ | |
853 | u_short if_index; /* numeric abbreviation for this if */ | |
854 | short if_unit; /* sub-unit for lower level driver */ | |
855 | short if_timer; /* time 'til if_watchdog called */ | |
856 | short if_flags; /* up/down, broadcast, etc. */ | |
857 | u_int32_t if_eflags; /* see <net/if.h> */ | |
39037602 | 858 | u_int32_t if_xflags; /* see <net/if.h> */ |
6d2010ae A |
859 | |
860 | int if_capabilities; /* interface features & capabilities */ | |
861 | int if_capenable; /* enabled features & capabilities */ | |
862 | ||
863 | void *if_linkmib; /* link-type-specific MIB data */ | |
864 | size_t if_linkmiblen; /* length of above data */ | |
865 | ||
866 | struct if_data_internal if_data __attribute__((aligned(8))); | |
867 | ||
868 | ifnet_family_t if_family; /* value assigned by Apple */ | |
39236c6e | 869 | ifnet_subfamily_t if_subfamily; /* value assigned by Apple */ |
6d2010ae | 870 | uintptr_t if_family_cookie; |
5ba3f43e A |
871 | volatile dlil_input_func if_input_dlil; |
872 | volatile dlil_output_func if_output_dlil; | |
873 | volatile ifnet_start_func if_start; | |
91447636 | 874 | ifnet_output_func if_output; |
316670eb | 875 | ifnet_pre_enqueue_func if_pre_enqueue; |
316670eb A |
876 | ifnet_ctl_func if_output_ctl; |
877 | ifnet_input_poll_func if_input_poll; | |
878 | ifnet_ctl_func if_input_ctl; | |
91447636 A |
879 | ifnet_ioctl_func if_ioctl; |
880 | ifnet_set_bpf_tap if_set_bpf_tap; | |
881 | ifnet_detached_func if_free; | |
882 | ifnet_demux_func if_demux; | |
883 | ifnet_event_func if_event; | |
39236c6e A |
884 | ifnet_framer_func if_framer_legacy; |
885 | ifnet_framer_extended_func if_framer; | |
6d2010ae A |
886 | ifnet_add_proto_func if_add_proto; |
887 | ifnet_del_proto_func if_del_proto; | |
888 | ifnet_check_multi if_check_multi; | |
889 | struct proto_hash_entry *if_proto_hash; | |
890 | void *if_kpi_storage; | |
1c79356b | 891 | |
39236c6e A |
892 | u_int32_t if_flowhash; /* interface flow control ID */ |
893 | ||
316670eb | 894 | decl_lck_mtx_data(, if_start_lock); |
39236c6e | 895 | u_int32_t if_start_flags; /* see IFSF flags below */ |
316670eb | 896 | u_int32_t if_start_req; |
3e170ce0 A |
897 | u_int16_t if_start_active; /* output is active */ |
898 | u_int16_t if_start_delayed; | |
899 | u_int16_t if_start_delay_qlen; | |
900 | u_int16_t if_start_delay_idle; | |
901 | u_int64_t if_start_delay_swin; | |
902 | u_int32_t if_start_delay_cnt; | |
903 | u_int32_t if_start_delay_timeout; /* nanoseconds */ | |
316670eb A |
904 | struct timespec if_start_cycle; /* restart interval */ |
905 | struct thread *if_start_thread; | |
906 | ||
907 | struct ifclassq if_snd; /* transmit queue */ | |
908 | u_int32_t if_output_sched_model; /* tx sched model */ | |
909 | ||
910 | struct if_bandwidths if_output_bw; | |
911 | struct if_bandwidths if_input_bw; | |
912 | ||
39236c6e A |
913 | struct if_latencies if_output_lt; |
914 | struct if_latencies if_input_lt; | |
915 | ||
6d2010ae A |
916 | decl_lck_mtx_data(, if_flt_lock) |
917 | u_int32_t if_flt_busy; | |
918 | u_int32_t if_flt_waiters; | |
91447636 | 919 | struct ifnet_filter_head if_flt_head; |
1c79356b | 920 | |
6d2010ae A |
921 | struct ifmultihead if_multiaddrs; /* multicast addresses */ |
922 | u_int32_t if_updatemcasts; /* mcast addrs need updating */ | |
923 | int if_amcount; /* # of all-multicast reqs */ | |
924 | decl_lck_mtx_data(, if_addrconfig_lock); /* for serializing addr config */ | |
925 | struct in_multi *if_allhostsinm; /* store all-hosts inm for this ifp */ | |
1c79356b | 926 | |
316670eb A |
927 | decl_lck_mtx_data(, if_poll_lock); |
928 | u_int16_t if_poll_req; | |
929 | u_int16_t if_poll_update; /* link update */ | |
930 | u_int32_t if_poll_active; /* polling is active */ | |
931 | struct timespec if_poll_cycle; /* poll interval */ | |
932 | struct thread *if_poll_thread; | |
91447636 | 933 | |
316670eb | 934 | struct dlil_threading_info *if_inp; |
91447636 | 935 | |
5ba3f43e A |
936 | /* allocated once along with dlil_ifnet and is never freed */ |
937 | thread_call_t if_dt_tcall; | |
938 | ||
91447636 | 939 | struct { |
b0d623f7 | 940 | u_int32_t length; |
91447636 A |
941 | union { |
942 | u_char buffer[8]; | |
943 | u_char *ptr; | |
944 | } u; | |
945 | } if_broadcast; | |
2d21ac55 | 946 | #if CONFIG_MACF_NET |
6d2010ae | 947 | struct label *if_label; /* interface MAC label */ |
2d21ac55 | 948 | #endif |
b0d623f7 | 949 | |
b0d623f7 | 950 | #if PF |
6d2010ae | 951 | struct pfi_kif *if_pf_kif; |
b0d623f7 | 952 | #endif /* PF */ |
1c79356b | 953 | |
6d2010ae A |
954 | decl_lck_mtx_data(, if_cached_route_lock); |
955 | u_int32_t if_fwd_cacheok; | |
956 | struct route if_fwd_route; /* cached forwarding route */ | |
957 | struct route if_src_route; /* cached ipv4 source route */ | |
958 | struct route_in6 if_src_route6; /* cached ipv6 source route */ | |
91447636 | 959 | |
6d2010ae A |
960 | decl_lck_rw_data(, if_llreach_lock); |
961 | struct ll_reach_tree if_ll_srcs; /* source link-layer tree */ | |
91447636 | 962 | |
6d2010ae A |
963 | void *if_bridge; /* bridge glue */ |
964 | ||
965 | u_int32_t if_want_aggressive_drain; | |
966 | u_int32_t if_idle_flags; /* idle flags */ | |
967 | u_int32_t if_idle_new_flags; /* temporary idle flags */ | |
968 | u_int32_t if_idle_new_flags_mask; /* temporary mask */ | |
969 | u_int32_t if_route_refcnt; /* idle: route ref count */ | |
39037602 | 970 | u_int32_t if_rt_sendts; /* last of a real time packet */ |
6d2010ae A |
971 | |
972 | struct if_traffic_class if_tc __attribute__((aligned(8))); | |
973 | #if INET | |
974 | struct igmp_ifinfo *if_igi; /* for IGMPv3 */ | |
975 | #endif /* INET */ | |
976 | #if INET6 | |
977 | struct mld_ifinfo *if_mli; /* for MLDv2 */ | |
978 | #endif /* INET6 */ | |
316670eb | 979 | |
316670eb A |
980 | struct tcpstat_local *if_tcp_stat; /* TCP specific stats */ |
981 | struct udpstat_local *if_udp_stat; /* UDP specific stats */ | |
39236c6e A |
982 | |
983 | struct { | |
984 | int32_t level; /* cached logging level */ | |
985 | u_int32_t flags; /* cached logging flags */ | |
986 | int32_t category; /* cached category */ | |
987 | int32_t subcategory; /* cached subcategory */ | |
988 | } if_log; | |
989 | ||
990 | struct { | |
991 | struct ifnet *ifp; /* delegated ifp */ | |
992 | u_int32_t type; /* delegated i/f type */ | |
993 | u_int32_t family; /* delegated i/f family */ | |
994 | u_int32_t subfamily; /* delegated i/f sub-family */ | |
fe8ab488 | 995 | uint32_t expensive:1; /* delegated i/f expensive? */ |
39236c6e A |
996 | } if_delegated; |
997 | ||
39037602 A |
998 | uuid_t *if_agentids; /* network agents attached to interface */ |
999 | u_int32_t if_agentcount; | |
3e170ce0 | 1000 | |
d9a64523 A |
1001 | volatile uint32_t if_low_power_gencnt; |
1002 | ||
39037602 | 1003 | u_int32_t if_generation; /* generation to use with NECP clients */ |
39236c6e | 1004 | u_int32_t if_fg_sendts; /* last send on a fg socket in seconds */ |
39037602 A |
1005 | |
1006 | u_int64_t if_data_threshold; | |
1007 | ||
1008 | /* Total bytes in send socket buffer */ | |
1009 | int64_t if_sndbyte_total __attribute__ ((aligned(8))); | |
1010 | /* Total unsent bytes in send socket buffer */ | |
1011 | int64_t if_sndbyte_unsent __attribute__ ((aligned(8))); | |
1012 | /* count of times, when there was data to send when sleep is impending */ | |
1013 | uint32_t if_unsent_data_cnt; | |
39236c6e | 1014 | |
3e170ce0 A |
1015 | #if INET |
1016 | decl_lck_rw_data(, if_inetdata_lock); | |
1017 | void *if_inetdata; | |
1018 | #endif /* INET */ | |
39236c6e A |
1019 | #if INET6 |
1020 | decl_lck_rw_data(, if_inet6data_lock); | |
1021 | void *if_inet6data; | |
1022 | #endif | |
3e170ce0 A |
1023 | decl_lck_rw_data(, if_link_status_lock); |
1024 | struct if_link_status *if_link_status; | |
1025 | struct if_interface_state if_interface_state; | |
4bd07ac2 A |
1026 | struct if_tcp_ecn_stat *if_ipv4_stat; |
1027 | struct if_tcp_ecn_stat *if_ipv6_stat; | |
5ba3f43e A |
1028 | |
1029 | struct if_lim_perf_stat if_lim_stat; | |
6d2010ae A |
1030 | }; |
1031 | ||
5ba3f43e A |
1032 | /* Interface event handling declarations */ |
1033 | extern struct eventhandler_lists_ctxt ifnet_evhdlr_ctxt; | |
1034 | ||
1035 | typedef enum { | |
1036 | INTF_EVENT_CODE_CREATED, | |
1037 | INTF_EVENT_CODE_REMOVED, | |
1038 | INTF_EVENT_CODE_STATUS_UPDATE, | |
1039 | INTF_EVENT_CODE_IPADDR_ATTACHED, | |
1040 | INTF_EVENT_CODE_IPADDR_DETACHED, | |
1041 | INTF_EVENT_CODE_LLADDR_UPDATE, | |
1042 | INTF_EVENT_CODE_MTU_CHANGED, | |
d9a64523 | 1043 | INTF_EVENT_CODE_LOW_POWER_UPDATE, |
5ba3f43e A |
1044 | } intf_event_code_t; |
1045 | ||
1046 | typedef void (*ifnet_event_fn)(struct eventhandler_entry_arg, struct ifnet *, struct sockaddr *, intf_event_code_t); | |
1047 | EVENTHANDLER_DECLARE(ifnet_event, ifnet_event_fn); | |
1048 | ||
39236c6e A |
1049 | #define IF_TCP_STATINC(_ifp, _s) do { \ |
1050 | if ((_ifp)->if_tcp_stat != NULL) \ | |
1051 | atomic_add_64(&(_ifp)->if_tcp_stat->_s, 1); \ | |
1052 | } while (0); | |
1053 | ||
1054 | #define IF_UDP_STATINC(_ifp, _s) do { \ | |
1055 | if ((_ifp)->if_udp_stat != NULL) \ | |
1056 | atomic_add_64(&(_ifp)->if_udp_stat->_s, 1); \ | |
1057 | } while (0); | |
1058 | ||
6d2010ae | 1059 | /* |
39236c6e | 1060 | * Valid values for if_refflags |
6d2010ae | 1061 | */ |
5ba3f43e A |
1062 | #define IFRF_EMBRYONIC 0x1 /* ifnet is allocated; awaiting attach */ |
1063 | #define IFRF_ATTACHED 0x2 /* ifnet attach is completely done */ | |
1064 | #define IFRF_DETACHING 0x4 /* detach has been requested */ | |
1065 | #define IFRF_ATTACH_MASK \ | |
1066 | (IFRF_EMBRYONIC|IFRF_ATTACHED|IFRF_DETACHING) | |
1067 | ||
1068 | #define IF_FULLY_ATTACHED(_ifp) \ | |
1069 | (((_ifp)->if_refflags & IFRF_ATTACH_MASK) == IFRF_ATTACHED) | |
39236c6e A |
1070 | /* |
1071 | * Valid values for if_start_flags | |
1072 | */ | |
1073 | #define IFSF_FLOW_CONTROLLED 0x1 /* flow controlled */ | |
1074 | ||
4a249263 A |
1075 | /* |
1076 | * Structure describing a `cloning' interface. | |
1077 | */ | |
1078 | struct if_clone { | |
1079 | LIST_ENTRY(if_clone) ifc_list; /* on list of cloners */ | |
d9a64523 | 1080 | decl_lck_mtx_data(, ifc_mutex); /* To serialize clone create/delete */ |
6d2010ae A |
1081 | const char *ifc_name; /* name of device, e.g. `vlan' */ |
1082 | size_t ifc_namelen; /* length of name */ | |
1083 | u_int32_t ifc_minifs; /* minimum number of interfaces */ | |
1084 | u_int32_t ifc_maxunit; /* maximum unit number */ | |
1085 | unsigned char *ifc_units; /* bitmap to handle units */ | |
1086 | u_int32_t ifc_bmlen; /* bitmap length */ | |
d9a64523 A |
1087 | u_int32_t ifc_zone_max_elem; /* Max elements for this zone type */ |
1088 | u_int32_t ifc_softc_size; /* size of softc for the device */ | |
1089 | struct zone *ifc_zone; /* if_clone allocation zone */ | |
6d2010ae A |
1090 | int (*ifc_create)(struct if_clone *, u_int32_t, void *); |
1091 | int (*ifc_destroy)(struct ifnet *); | |
4a249263 A |
1092 | }; |
1093 | ||
d9a64523 A |
1094 | #define IF_CLONE_INITIALIZER(name, create, destroy, minifs, maxunit, zone_max_elem, softc_size) { \ |
1095 | .ifc_list = { NULL, NULL }, \ | |
1096 | .ifc_mutex = {}, \ | |
1097 | .ifc_name = name, \ | |
1098 | .ifc_namelen = (sizeof (name) - 1), \ | |
1099 | .ifc_minifs = minifs, \ | |
1100 | .ifc_maxunit = maxunit, \ | |
1101 | .ifc_units = NULL, \ | |
1102 | .ifc_bmlen = 0, \ | |
1103 | .ifc_zone_max_elem = zone_max_elem, \ | |
1104 | .ifc_softc_size = softc_size, \ | |
1105 | .ifc_zone = NULL, \ | |
1106 | .ifc_create = create, \ | |
1107 | .ifc_destroy = destroy \ | |
6d2010ae | 1108 | } |
9bccf70c | 1109 | |
d1ecb069 A |
1110 | #define M_CLONE M_IFADDR |
1111 | ||
1c79356b | 1112 | /* |
6d2010ae A |
1113 | * Macros to manipulate ifqueue. Users of these macros are responsible |
1114 | * for serialization, by holding whatever lock is appropriate for the | |
1115 | * corresponding structure that is referring the ifqueue. | |
1c79356b A |
1116 | */ |
1117 | #define IF_QFULL(ifq) ((ifq)->ifq_len >= (ifq)->ifq_maxlen) | |
1118 | #define IF_DROP(ifq) ((ifq)->ifq_drops++) | |
316670eb A |
1119 | |
1120 | #define IF_ENQUEUE(ifq, m) do { \ | |
6d2010ae A |
1121 | (m)->m_nextpkt = NULL; \ |
1122 | if ((ifq)->ifq_tail == NULL) \ | |
1123 | (ifq)->ifq_head = m; \ | |
1124 | else \ | |
1125 | ((struct mbuf*)(ifq)->ifq_tail)->m_nextpkt = m; \ | |
1126 | (ifq)->ifq_tail = m; \ | |
1127 | (ifq)->ifq_len++; \ | |
316670eb A |
1128 | } while (0) |
1129 | ||
1130 | #define IF_PREPEND(ifq, m) do { \ | |
6d2010ae A |
1131 | (m)->m_nextpkt = (ifq)->ifq_head; \ |
1132 | if ((ifq)->ifq_tail == NULL) \ | |
1133 | (ifq)->ifq_tail = (m); \ | |
1134 | (ifq)->ifq_head = (m); \ | |
1135 | (ifq)->ifq_len++; \ | |
316670eb A |
1136 | } while (0) |
1137 | ||
1138 | #define IF_DEQUEUE(ifq, m) do { \ | |
6d2010ae A |
1139 | (m) = (ifq)->ifq_head; \ |
1140 | if (m != NULL) { \ | |
1141 | if (((ifq)->ifq_head = (m)->m_nextpkt) == NULL) \ | |
1142 | (ifq)->ifq_tail = NULL; \ | |
1143 | (m)->m_nextpkt = NULL; \ | |
1144 | (ifq)->ifq_len--; \ | |
1145 | } \ | |
316670eb A |
1146 | } while (0) |
1147 | ||
1148 | #define IF_REMQUEUE(ifq, m) do { \ | |
6d2010ae A |
1149 | struct mbuf *_p = (ifq)->ifq_head; \ |
1150 | struct mbuf *_n = (m)->m_nextpkt; \ | |
1151 | if ((m) == _p) \ | |
1152 | _p = NULL; \ | |
1153 | while (_p != NULL) { \ | |
1154 | if (_p->m_nextpkt == (m)) \ | |
1155 | break; \ | |
1156 | _p = _p->m_nextpkt; \ | |
1157 | } \ | |
1158 | VERIFY(_p != NULL || ((m) == (ifq)->ifq_head)); \ | |
1159 | if ((m) == (ifq)->ifq_head) \ | |
1160 | (ifq)->ifq_head = _n; \ | |
1161 | if ((m) == (ifq)->ifq_tail) \ | |
1162 | (ifq)->ifq_tail = _p; \ | |
1163 | VERIFY((ifq)->ifq_tail != NULL || (ifq)->ifq_head == NULL); \ | |
1164 | VERIFY((ifq)->ifq_len != 0); \ | |
1165 | --(ifq)->ifq_len; \ | |
1166 | if (_p != NULL) \ | |
1167 | _p->m_nextpkt = _n; \ | |
1168 | (m)->m_nextpkt = NULL; \ | |
316670eb A |
1169 | } while (0) |
1170 | ||
6d2010ae | 1171 | #define IF_DRAIN(ifq) do { \ |
316670eb | 1172 | struct mbuf *_m; \ |
6d2010ae | 1173 | for (;;) { \ |
316670eb A |
1174 | IF_DEQUEUE(ifq, _m); \ |
1175 | if (_m == NULL) \ | |
6d2010ae | 1176 | break; \ |
316670eb | 1177 | m_freem(_m); \ |
6d2010ae A |
1178 | } \ |
1179 | } while (0) | |
1c79356b | 1180 | |
1c79356b A |
1181 | /* |
1182 | * The ifaddr structure contains information about one address | |
1183 | * of an interface. They are maintained by the different address families, | |
1184 | * are allocated and attached when an address is set, and are linked | |
1185 | * together so all addresses for an interface can be located. | |
1186 | */ | |
1187 | struct ifaddr { | |
6d2010ae A |
1188 | decl_lck_mtx_data(, ifa_lock); /* lock for ifaddr */ |
1189 | uint32_t ifa_refcnt; /* ref count, use IFA_{ADD,REM}REF */ | |
1190 | uint32_t ifa_debug; /* debug flags */ | |
1191 | struct sockaddr *ifa_addr; /* address of interface */ | |
1192 | struct sockaddr *ifa_dstaddr; /* other end of p-to-p link */ | |
1c79356b | 1193 | #define ifa_broadaddr ifa_dstaddr /* broadcast address interface */ |
6d2010ae A |
1194 | struct sockaddr *ifa_netmask; /* used to determine subnet */ |
1195 | struct ifnet *ifa_ifp; /* back-pointer to interface */ | |
1c79356b | 1196 | TAILQ_ENTRY(ifaddr) ifa_link; /* queue macro glue */ |
b0d623f7 A |
1197 | void (*ifa_rtrequest) /* check or clean routes (+ or -)'d */ |
1198 | (int, struct rtentry *, struct sockaddr *); | |
6d2010ae A |
1199 | uint32_t ifa_flags; /* mostly rt_flags for cloning */ |
1200 | int32_t ifa_metric; /* cost of going out this interface */ | |
b0d623f7 A |
1201 | void (*ifa_free)(struct ifaddr *); /* callback fn for freeing */ |
1202 | void (*ifa_trace) /* callback fn for tracing refs */ | |
1203 | (struct ifaddr *, int); | |
6d2010ae A |
1204 | void (*ifa_attached)(struct ifaddr *); /* callback fn for attaching */ |
1205 | void (*ifa_detached)(struct ifaddr *); /* callback fn for detaching */ | |
5ba3f43e A |
1206 | #if __arm__ && (__BIGGEST_ALIGNMENT__ > 4) |
1207 | /* For the newer ARMv7k ABI where 64-bit types are 64-bit aligned, but pointers | |
1208 | * are 32-bit: | |
1209 | * Align to 64-bit since we cast to this to struct in6_ifaddr, which is | |
1210 | * 64-bit aligned | |
1211 | */ | |
1212 | } __attribute__ ((aligned(8))); | |
1213 | #else | |
1c79356b | 1214 | }; |
5ba3f43e | 1215 | #endif |
b0d623f7 | 1216 | |
3e170ce0 | 1217 | |
b0d623f7 A |
1218 | /* |
1219 | * Valid values for ifa_flags | |
1220 | */ | |
91447636 A |
1221 | #define IFA_ROUTE RTF_UP /* route installed (0x1) */ |
1222 | #define IFA_CLONING RTF_CLONING /* (0x100) */ | |
b0d623f7 A |
1223 | |
1224 | /* | |
1225 | * Valid values for ifa_debug | |
1226 | */ | |
6d2010ae | 1227 | #define IFD_ATTACHED 0x1 /* attached to list */ |
b0d623f7 A |
1228 | #define IFD_ALLOC 0x2 /* dynamically allocated */ |
1229 | #define IFD_DEBUG 0x4 /* has debugging info */ | |
6d2010ae A |
1230 | #define IFD_LINK 0x8 /* link address */ |
1231 | #define IFD_TRASHED 0x10 /* in trash list */ | |
813fb2f6 | 1232 | #define IFD_DETACHING 0x20 /* detach is in progress */ |
6d2010ae | 1233 | #define IFD_NOTREADY 0x40 /* embryonic; not yet ready */ |
91447636 | 1234 | |
6d2010ae | 1235 | #define IFA_LOCK_ASSERT_HELD(_ifa) \ |
5ba3f43e | 1236 | LCK_MTX_ASSERT(&(_ifa)->ifa_lock, LCK_MTX_ASSERT_OWNED) |
6d2010ae A |
1237 | |
1238 | #define IFA_LOCK_ASSERT_NOTHELD(_ifa) \ | |
5ba3f43e | 1239 | LCK_MTX_ASSERT(&(_ifa)->ifa_lock, LCK_MTX_ASSERT_NOTOWNED) |
6d2010ae A |
1240 | |
1241 | #define IFA_LOCK(_ifa) \ | |
1242 | lck_mtx_lock(&(_ifa)->ifa_lock) | |
1243 | ||
1244 | #define IFA_LOCK_SPIN(_ifa) \ | |
1245 | lck_mtx_lock_spin(&(_ifa)->ifa_lock) | |
1246 | ||
1247 | #define IFA_CONVERT_LOCK(_ifa) do { \ | |
1248 | IFA_LOCK_ASSERT_HELD(_ifa); \ | |
1249 | lck_mtx_convert_spin(&(_ifa)->ifa_lock); \ | |
1250 | } while (0) | |
1251 | ||
1252 | #define IFA_UNLOCK(_ifa) \ | |
1253 | lck_mtx_unlock(&(_ifa)->ifa_lock) | |
1254 | ||
1255 | #define IFA_ADDREF(_ifa) \ | |
1256 | ifa_addref(_ifa, 0) | |
1257 | ||
1258 | #define IFA_ADDREF_LOCKED(_ifa) \ | |
1259 | ifa_addref(_ifa, 1) | |
1260 | ||
1261 | #define IFA_REMREF(_ifa) do { \ | |
1262 | (void) ifa_remref(_ifa, 0); \ | |
1263 | } while (0) | |
1264 | ||
1265 | #define IFA_REMREF_LOCKED(_ifa) \ | |
1266 | ifa_remref(_ifa, 1) | |
1c79356b | 1267 | |
1c79356b A |
1268 | /* |
1269 | * Multicast address structure. This is analogous to the ifaddr | |
1270 | * structure except that it keeps track of multicast addresses. | |
6d2010ae A |
1271 | * Also, the request count here is a count of requests for this |
1272 | * address, not a count of pointers to this structure; anonymous | |
1273 | * membership(s) holds one outstanding request count. | |
1c79356b A |
1274 | */ |
1275 | struct ifmultiaddr { | |
6d2010ae A |
1276 | decl_lck_mtx_data(, ifma_lock); |
1277 | u_int32_t ifma_refcount; /* reference count */ | |
1278 | u_int32_t ifma_anoncnt; /* # of anonymous requests */ | |
1279 | u_int32_t ifma_reqcnt; /* total requests for this address */ | |
1280 | u_int32_t ifma_debug; /* see ifa_debug flags */ | |
1281 | u_int32_t ifma_flags; /* see below */ | |
1c79356b | 1282 | LIST_ENTRY(ifmultiaddr) ifma_link; /* queue macro glue */ |
6d2010ae | 1283 | struct sockaddr *ifma_addr; /* address this membership is for */ |
91447636 | 1284 | struct ifmultiaddr *ifma_ll; /* link-layer translation, if any */ |
6d2010ae A |
1285 | struct ifnet *ifma_ifp; /* back-pointer to interface */ |
1286 | void *ifma_protospec; /* protocol-specific state, if any */ | |
1287 | void (*ifma_trace) /* callback fn for tracing refs */ | |
1288 | (struct ifmultiaddr *, int); | |
1c79356b | 1289 | }; |
1c79356b | 1290 | |
91447636 | 1291 | /* |
6d2010ae | 1292 | * Values for ifma_flags |
91447636 | 1293 | */ |
6d2010ae A |
1294 | #define IFMAF_ANONYMOUS 0x1 /* has anonymous request ref(s) held */ |
1295 | ||
1296 | #define IFMA_LOCK_ASSERT_HELD(_ifma) \ | |
5ba3f43e | 1297 | LCK_MTX_ASSERT(&(_ifma)->ifma_lock, LCK_MTX_ASSERT_OWNED) |
6d2010ae A |
1298 | |
1299 | #define IFMA_LOCK_ASSERT_NOTHELD(_ifma) \ | |
5ba3f43e | 1300 | LCK_MTX_ASSERT(&(_ifma)->ifma_lock, LCK_MTX_ASSERT_NOTOWNED) |
6d2010ae A |
1301 | |
1302 | #define IFMA_LOCK(_ifma) \ | |
1303 | lck_mtx_lock(&(_ifma)->ifma_lock) | |
1304 | ||
1305 | #define IFMA_LOCK_SPIN(_ifma) \ | |
1306 | lck_mtx_lock_spin(&(_ifma)->ifma_lock) | |
1307 | ||
1308 | #define IFMA_CONVERT_LOCK(_ifma) do { \ | |
1309 | IFMA_LOCK_ASSERT_HELD(_ifma); \ | |
1310 | lck_mtx_convert_spin(&(_ifma)->ifma_lock); \ | |
1311 | } while (0) | |
1312 | ||
1313 | #define IFMA_UNLOCK(_ifma) \ | |
1314 | lck_mtx_unlock(&(_ifma)->ifma_lock) | |
1315 | ||
1316 | #define IFMA_ADDREF(_ifma) \ | |
1317 | ifma_addref(_ifma, 0) | |
1318 | ||
1319 | #define IFMA_ADDREF_LOCKED(_ifma) \ | |
1320 | ifma_addref(_ifma, 1) | |
1321 | ||
1322 | #define IFMA_REMREF(_ifma) \ | |
1323 | ifma_remref(_ifma) | |
1324 | ||
39236c6e A |
1325 | /* |
1326 | * Indicate whether or not the immediate interface, or the interface delegated | |
1327 | * by it, is a cellular interface (IFT_CELLULAR). Delegated interface type is | |
1328 | * set/cleared along with the delegated ifp; we cache the type for performance | |
1329 | * to avoid dereferencing delegated ifp each time. | |
1330 | * | |
1331 | * Note that this is meant to be used only for accounting and policy purposes; | |
1332 | * certain places need to explicitly know the immediate interface type, and | |
1333 | * this macro should not be used there. | |
1334 | * | |
1335 | * The test is done against IFT_CELLULAR instead of IFNET_FAMILY_CELLULAR to | |
1336 | * handle certain cases where the family isn't set to the latter. | |
1337 | */ | |
1338 | #define IFNET_IS_CELLULAR(_ifp) \ | |
1339 | ((_ifp)->if_type == IFT_CELLULAR || \ | |
1340 | (_ifp)->if_delegated.type == IFT_CELLULAR) | |
1341 | ||
4bd07ac2 A |
1342 | /* |
1343 | * Indicate whether or not the immediate interface, or the interface delegated | |
1344 | * by it, is an ETHERNET interface. | |
1345 | */ | |
1346 | #define IFNET_IS_ETHERNET(_ifp) \ | |
1347 | ((_ifp)->if_family == IFNET_FAMILY_ETHERNET || \ | |
1348 | (_ifp)->if_delegated.family == IFNET_FAMILY_ETHERNET) | |
39236c6e A |
1349 | /* |
1350 | * Indicate whether or not the immediate interface, or the interface delegated | |
1351 | * by it, is a Wi-Fi interface (IFNET_SUBFAMILY_WIFI). Delegated interface | |
1352 | * subfamily is set/cleared along with the delegated ifp; we cache the subfamily | |
1353 | * for performance to avoid dereferencing delegated ifp each time. | |
1354 | * | |
1355 | * Note that this is meant to be used only for accounting and policy purposes; | |
1356 | * certain places need to explicitly know the immediate interface type, and | |
1357 | * this macro should not be used there. | |
1358 | * | |
1359 | * The test is done against IFNET_SUBFAMILY_WIFI as the family may be set to | |
1360 | * IFNET_FAMILY_ETHERNET (as well as type to IFT_ETHER) which is too generic. | |
1361 | */ | |
1362 | #define IFNET_IS_WIFI(_ifp) \ | |
1363 | ((_ifp)->if_subfamily == IFNET_SUBFAMILY_WIFI || \ | |
1364 | (_ifp)->if_delegated.subfamily == IFNET_SUBFAMILY_WIFI) | |
1365 | ||
fe8ab488 A |
1366 | /* |
1367 | * Indicate whether or not the immediate interface, or the interface delegated | |
1368 | * by it, is a Wired interface (several families). Delegated interface | |
1369 | * family is set/cleared along with the delegated ifp; we cache the family | |
1370 | * for performance to avoid dereferencing delegated ifp each time. | |
1371 | * | |
1372 | * Note that this is meant to be used only for accounting and policy purposes; | |
1373 | * certain places need to explicitly know the immediate interface type, and | |
1374 | * this macro should not be used there. | |
1375 | */ | |
1376 | #define IFNET_IS_WIRED(_ifp) \ | |
1377 | ((_ifp)->if_family == IFNET_FAMILY_ETHERNET || \ | |
1378 | (_ifp)->if_delegated.family == IFNET_FAMILY_ETHERNET || \ | |
1379 | (_ifp)->if_family == IFNET_FAMILY_FIREWIRE || \ | |
1380 | (_ifp)->if_delegated.family == IFNET_FAMILY_FIREWIRE) | |
1381 | ||
39037602 A |
1382 | /* |
1383 | * Indicate whether or not the immediate WiFi interface is on an infrastructure | |
1384 | * network | |
1385 | */ | |
1386 | #define IFNET_IS_WIFI_INFRA(_ifp) \ | |
1387 | ((_ifp)->if_family == IFNET_FAMILY_ETHERNET && \ | |
1388 | (_ifp)->if_subfamily == IFNET_SUBFAMILY_WIFI && \ | |
1389 | !((_ifp)->if_eflags & IFEF_AWDL)) | |
1390 | ||
fe8ab488 A |
1391 | /* |
1392 | * Indicate whether or not the immediate interface, or the interface delegated | |
39037602 A |
1393 | * by it, is marked as expensive. The delegated interface is set/cleared |
1394 | * along with the delegated ifp; we cache the flag for performance to avoid | |
fe8ab488 A |
1395 | * dereferencing delegated ifp each time. |
1396 | * | |
1397 | * Note that this is meant to be used only for policy purposes. | |
1398 | */ | |
1399 | #define IFNET_IS_EXPENSIVE(_ifp) \ | |
1400 | ((_ifp)->if_eflags & IFEF_EXPENSIVE || \ | |
1401 | (_ifp)->if_delegated.expensive) | |
1402 | ||
d9a64523 A |
1403 | #define IFNET_IS_LOW_POWER(_ifp) \ |
1404 | (if_low_power_restricted != 0 && \ | |
1405 | ((_ifp)->if_xflags & IFXF_LOW_POWER) || \ | |
1406 | ((_ifp)->if_delegated.ifp != NULL && \ | |
1407 | ((_ifp)->if_delegated.ifp->if_xflags & IFXF_LOW_POWER))) | |
1408 | ||
fe8ab488 A |
1409 | /* |
1410 | * We don't support AWDL interface delegation. | |
1411 | */ | |
1412 | #define IFNET_IS_AWDL_RESTRICTED(_ifp) \ | |
1413 | (((_ifp)->if_eflags & (IFEF_AWDL|IFEF_AWDL_RESTRICTED)) == \ | |
1414 | (IFEF_AWDL|IFEF_AWDL_RESTRICTED)) | |
1415 | ||
39037602 A |
1416 | #define IFNET_IS_INTCOPROC(_ifp) \ |
1417 | ((_ifp)->if_family == IFNET_FAMILY_ETHERNET && \ | |
1418 | (_ifp)->if_subfamily == IFNET_SUBFAMILY_INTCOPROC) | |
fe8ab488 | 1419 | |
39236c6e | 1420 | extern struct ifnethead ifnet_head; |
39037602 | 1421 | extern struct ifnethead ifnet_ordered_head; |
39236c6e A |
1422 | extern struct ifnet **ifindex2ifnet; |
1423 | extern u_int32_t if_sndq_maxlen; | |
1424 | extern u_int32_t if_rcvq_maxlen; | |
1425 | extern int if_index; | |
1426 | extern struct ifaddr **ifnet_addrs; | |
1427 | extern lck_attr_t *ifa_mtx_attr; | |
1428 | extern lck_grp_t *ifa_mtx_grp; | |
1429 | extern lck_grp_t *ifnet_lock_group; | |
1430 | extern lck_attr_t *ifnet_lock_attr; | |
6d2010ae A |
1431 | extern ifnet_t lo_ifp; |
1432 | ||
1433 | extern int if_addmulti(struct ifnet *, const struct sockaddr *, | |
1434 | struct ifmultiaddr **); | |
1435 | extern int if_addmulti_anon(struct ifnet *, const struct sockaddr *, | |
1436 | struct ifmultiaddr **); | |
1437 | extern int if_allmulti(struct ifnet *, int); | |
1438 | extern int if_delmulti(struct ifnet *, const struct sockaddr *); | |
1439 | extern int if_delmulti_ifma(struct ifmultiaddr *); | |
1440 | extern int if_delmulti_anon(struct ifnet *, const struct sockaddr *); | |
1441 | extern void if_down(struct ifnet *); | |
1442 | extern int if_down_all(void); | |
1443 | extern void if_up(struct ifnet *); | |
1444 | __private_extern__ void if_updown(struct ifnet *ifp, int up); | |
1445 | extern int ifioctl(struct socket *, u_long, caddr_t, struct proc *); | |
1446 | extern int ifioctllocked(struct socket *, u_long, caddr_t, struct proc *); | |
1447 | extern struct ifnet *ifunit(const char *); | |
39037602 A |
1448 | extern struct ifnet *ifunit_ref(const char *); |
1449 | extern int ifunit_extract(const char *src, char *dst, size_t dstlen, int *unit); | |
6d2010ae | 1450 | extern struct ifnet *if_withname(struct sockaddr *); |
316670eb A |
1451 | extern void if_qflush(struct ifnet *, int); |
1452 | extern void if_qflush_sc(struct ifnet *, mbuf_svc_class_t, u_int32_t, | |
1453 | u_int32_t *, u_int32_t *, int); | |
6d2010ae A |
1454 | |
1455 | extern struct if_clone *if_clone_lookup(const char *, u_int32_t *); | |
1456 | extern int if_clone_attach(struct if_clone *); | |
1457 | extern void if_clone_detach(struct if_clone *); | |
d9a64523 A |
1458 | extern void *if_clone_softc_allocate(const struct if_clone *); |
1459 | extern void if_clone_softc_deallocate(const struct if_clone *, void *); | |
39037602 | 1460 | extern u_int32_t if_functional_type(struct ifnet *, bool); |
3e170ce0 | 1461 | |
6d2010ae A |
1462 | extern errno_t if_mcasts_update(struct ifnet *); |
1463 | ||
1464 | typedef enum { | |
1465 | IFNET_LCK_ASSERT_EXCLUSIVE, /* RW: held as writer */ | |
1466 | IFNET_LCK_ASSERT_SHARED, /* RW: held as reader */ | |
1467 | IFNET_LCK_ASSERT_OWNED, /* RW: writer/reader, MTX: held */ | |
1468 | IFNET_LCK_ASSERT_NOTOWNED /* not held */ | |
1469 | } ifnet_lock_assert_t; | |
1470 | ||
39236c6e A |
1471 | #define IF_LLADDR(_ifp) \ |
1472 | (LLADDR(SDL(((_ifp)->if_lladdr)->ifa_addr))) | |
1473 | ||
4d15aeb1 A |
1474 | #define IF_INDEX_IN_RANGE(_ind_) ((_ind_) > 0 && \ |
1475 | (unsigned int)(_ind_) <= (unsigned int)if_index) | |
1476 | ||
6d2010ae A |
1477 | __private_extern__ void ifnet_lock_assert(struct ifnet *, ifnet_lock_assert_t); |
1478 | __private_extern__ void ifnet_lock_shared(struct ifnet *ifp); | |
1479 | __private_extern__ void ifnet_lock_exclusive(struct ifnet *ifp); | |
1480 | __private_extern__ void ifnet_lock_done(struct ifnet *ifp); | |
1481 | ||
3e170ce0 A |
1482 | #if INET |
1483 | __private_extern__ void if_inetdata_lock_shared(struct ifnet *ifp); | |
1484 | __private_extern__ void if_inetdata_lock_exclusive(struct ifnet *ifp); | |
1485 | __private_extern__ void if_inetdata_lock_done(struct ifnet *ifp); | |
1486 | #endif | |
1487 | ||
39236c6e A |
1488 | #if INET6 |
1489 | __private_extern__ void if_inet6data_lock_shared(struct ifnet *ifp); | |
1490 | __private_extern__ void if_inet6data_lock_exclusive(struct ifnet *ifp); | |
1491 | __private_extern__ void if_inet6data_lock_done(struct ifnet *ifp); | |
1492 | #endif | |
1493 | ||
6d2010ae A |
1494 | __private_extern__ void ifnet_head_lock_shared(void); |
1495 | __private_extern__ void ifnet_head_lock_exclusive(void); | |
1496 | __private_extern__ void ifnet_head_done(void); | |
39037602 | 1497 | __private_extern__ void ifnet_head_assert_exclusive(void); |
6d2010ae A |
1498 | |
1499 | __private_extern__ errno_t ifnet_set_idle_flags_locked(ifnet_t, u_int32_t, | |
1500 | u_int32_t); | |
1501 | __private_extern__ int ifnet_is_attached(struct ifnet *, int refio); | |
39037602 | 1502 | __private_extern__ void ifnet_incr_iorefcnt(struct ifnet *); |
6d2010ae | 1503 | __private_extern__ void ifnet_decr_iorefcnt(struct ifnet *); |
316670eb A |
1504 | __private_extern__ void ifnet_set_start_cycle(struct ifnet *, |
1505 | struct timespec *); | |
1506 | __private_extern__ void ifnet_set_poll_cycle(struct ifnet *, | |
1507 | struct timespec *); | |
6d2010ae A |
1508 | |
1509 | __private_extern__ void if_attach_ifa(struct ifnet *, struct ifaddr *); | |
1510 | __private_extern__ void if_attach_link_ifa(struct ifnet *, struct ifaddr *); | |
1511 | __private_extern__ void if_detach_ifa(struct ifnet *, struct ifaddr *); | |
1512 | __private_extern__ void if_detach_link_ifa(struct ifnet *, struct ifaddr *); | |
1513 | ||
7ddcb079 A |
1514 | __private_extern__ void dlil_if_lock(void); |
1515 | __private_extern__ void dlil_if_unlock(void); | |
1516 | __private_extern__ void dlil_if_lock_assert(void); | |
1517 | ||
6d2010ae | 1518 | extern struct ifaddr *ifa_ifwithaddr(const struct sockaddr *); |
39037602 | 1519 | extern struct ifaddr *ifa_ifwithaddr_locked(const struct sockaddr *); |
316670eb A |
1520 | extern struct ifaddr *ifa_ifwithaddr_scoped(const struct sockaddr *, |
1521 | unsigned int); | |
39037602 A |
1522 | extern struct ifaddr *ifa_ifwithaddr_scoped_locked(const struct sockaddr *, |
1523 | unsigned int); | |
6d2010ae A |
1524 | extern struct ifaddr *ifa_ifwithdstaddr(const struct sockaddr *); |
1525 | extern struct ifaddr *ifa_ifwithnet(const struct sockaddr *); | |
316670eb A |
1526 | extern struct ifaddr *ifa_ifwithnet_scoped(const struct sockaddr *, |
1527 | unsigned int); | |
6d2010ae A |
1528 | extern struct ifaddr *ifa_ifwithroute(int, const struct sockaddr *, |
1529 | const struct sockaddr *); | |
316670eb A |
1530 | extern struct ifaddr *ifa_ifwithroute_locked(int, const struct sockaddr *, |
1531 | const struct sockaddr *); | |
1532 | extern struct ifaddr *ifa_ifwithroute_scoped_locked(int, | |
1533 | const struct sockaddr *, const struct sockaddr *, unsigned int); | |
9d749ea3 | 1534 | extern struct ifaddr *ifaof_ifpforaddr_select(const struct sockaddr *, struct ifnet *); |
6d2010ae A |
1535 | extern struct ifaddr *ifaof_ifpforaddr(const struct sockaddr *, struct ifnet *); |
1536 | __private_extern__ struct ifaddr *ifa_ifpgetprimary(struct ifnet *, int); | |
1537 | extern void ifa_addref(struct ifaddr *, int); | |
1538 | extern struct ifaddr *ifa_remref(struct ifaddr *, int); | |
1539 | extern void ifa_lock_init(struct ifaddr *); | |
1540 | extern void ifa_lock_destroy(struct ifaddr *); | |
1541 | extern void ifma_addref(struct ifmultiaddr *, int); | |
1542 | extern void ifma_remref(struct ifmultiaddr *); | |
1543 | ||
1544 | extern void ifa_init(void); | |
1545 | ||
1546 | __private_extern__ struct in_ifaddr *ifa_foraddr(unsigned int); | |
1547 | __private_extern__ struct in_ifaddr *ifa_foraddr_scoped(unsigned int, | |
1548 | unsigned int); | |
1549 | ||
316670eb A |
1550 | struct ifreq; |
1551 | extern errno_t ifnet_getset_opportunistic(struct ifnet *, u_long, | |
1552 | struct ifreq *, struct proc *); | |
1553 | extern int ifnet_get_throttle(struct ifnet *, u_int32_t *); | |
1554 | extern int ifnet_set_throttle(struct ifnet *, u_int32_t); | |
39236c6e A |
1555 | extern errno_t ifnet_getset_log(struct ifnet *, u_long, |
1556 | struct ifreq *, struct proc *); | |
1557 | extern int ifnet_set_log(struct ifnet *, int32_t, uint32_t, int32_t, int32_t); | |
1558 | extern int ifnet_get_log(struct ifnet *, int32_t *, uint32_t *, int32_t *, | |
1559 | int32_t *); | |
1560 | extern int ifnet_notify_address(struct ifnet *, int); | |
5ba3f43e A |
1561 | extern void ifnet_notify_data_threshold(struct ifnet *); |
1562 | ||
1563 | #define IF_AFDATA_RLOCK if_afdata_rlock | |
1564 | #define IF_AFDATA_RUNLOCK if_afdata_unlock | |
1565 | #define IF_AFDATA_WLOCK if_afdata_wlock | |
1566 | #define IF_AFDATA_WUNLOCK if_afdata_unlock | |
1567 | #define IF_AFDATA_WLOCK_ASSERT if_afdata_wlock_assert | |
1568 | #define IF_AFDATA_LOCK_ASSERT if_afdata_lock_assert | |
1569 | #define IF_AFDATA_UNLOCK_ASSERT if_afdata_unlock_assert | |
1570 | ||
1571 | static inline void | |
1572 | if_afdata_rlock (struct ifnet *ifp, int af) | |
1573 | { | |
1574 | switch (af) { | |
1575 | #if INET | |
1576 | case AF_INET: | |
1577 | lck_rw_lock_shared(&ifp->if_inetdata_lock); | |
1578 | break; | |
1579 | #endif | |
1580 | #if INET6 | |
1581 | case AF_INET6: | |
1582 | lck_rw_lock_shared(&ifp->if_inet6data_lock); | |
1583 | break; | |
1584 | #endif | |
1585 | default: | |
1586 | VERIFY(0); | |
1587 | /* NOTREACHED */ | |
1588 | } | |
1589 | return; | |
1590 | } | |
1591 | ||
1592 | static inline void | |
1593 | if_afdata_runlock (struct ifnet *ifp, int af) | |
1594 | { | |
1595 | switch (af) { | |
1596 | #if INET | |
1597 | case AF_INET: | |
1598 | lck_rw_done(&ifp->if_inetdata_lock); | |
1599 | break; | |
1600 | #endif | |
1601 | #if INET6 | |
1602 | case AF_INET6: | |
1603 | lck_rw_done(&ifp->if_inet6data_lock); | |
1604 | break; | |
1605 | #endif | |
1606 | default: | |
1607 | VERIFY(0); | |
1608 | /* NOTREACHED */ | |
1609 | } | |
1610 | return; | |
1611 | } | |
1612 | ||
1613 | static inline void | |
1614 | if_afdata_wlock (struct ifnet *ifp, int af) | |
1615 | { | |
1616 | switch (af) { | |
1617 | #if INET | |
1618 | case AF_INET: | |
1619 | lck_rw_lock_exclusive(&ifp->if_inetdata_lock); | |
1620 | break; | |
1621 | #endif | |
1622 | #if INET6 | |
1623 | case AF_INET6: | |
1624 | lck_rw_lock_exclusive(&ifp->if_inet6data_lock); | |
1625 | break; | |
1626 | #endif | |
1627 | default: | |
1628 | VERIFY(0); | |
1629 | /* NOTREACHED */ | |
1630 | } | |
1631 | return; | |
1632 | } | |
1633 | ||
1634 | static inline void | |
1635 | if_afdata_unlock (struct ifnet *ifp, int af) | |
1636 | { | |
1637 | switch (af) { | |
1638 | #if INET | |
1639 | case AF_INET: | |
1640 | lck_rw_done(&ifp->if_inetdata_lock); | |
1641 | break; | |
1642 | #endif | |
1643 | #if INET6 | |
1644 | case AF_INET6: | |
1645 | lck_rw_done(&ifp->if_inet6data_lock); | |
1646 | break; | |
1647 | #endif | |
1648 | default: | |
1649 | VERIFY(0); | |
1650 | /* NOTREACHED */ | |
1651 | } | |
1652 | return; | |
1653 | } | |
1654 | ||
1655 | static inline void | |
1656 | if_afdata_wlock_assert (struct ifnet *ifp, int af) | |
1657 | { | |
1658 | #if !MACH_ASSERT | |
1659 | #pragma unused(ifp) | |
1660 | #endif | |
1661 | switch (af) { | |
1662 | #if INET | |
1663 | case AF_INET: | |
1664 | LCK_RW_ASSERT(&ifp->if_inetdata_lock, LCK_RW_ASSERT_EXCLUSIVE); | |
1665 | break; | |
1666 | #endif | |
1667 | #if INET6 | |
1668 | case AF_INET6: | |
1669 | LCK_RW_ASSERT(&ifp->if_inet6data_lock, LCK_RW_ASSERT_EXCLUSIVE); | |
1670 | break; | |
1671 | #endif | |
1672 | default: | |
1673 | VERIFY(0); | |
1674 | /* NOTREACHED */ | |
1675 | } | |
1676 | return; | |
1677 | } | |
1678 | ||
1679 | static inline void | |
1680 | if_afdata_unlock_assert (struct ifnet *ifp, int af) | |
1681 | { | |
1682 | #if !MACH_ASSERT | |
1683 | #pragma unused(ifp) | |
1684 | #endif | |
1685 | switch (af) { | |
1686 | #if INET | |
1687 | case AF_INET: | |
1688 | LCK_RW_ASSERT(&ifp->if_inetdata_lock, LCK_RW_ASSERT_NOTHELD); | |
1689 | break; | |
1690 | #endif | |
1691 | #if INET6 | |
1692 | case AF_INET6: | |
1693 | LCK_RW_ASSERT(&ifp->if_inet6data_lock, LCK_RW_ASSERT_NOTHELD); | |
1694 | break; | |
1695 | #endif | |
1696 | default: | |
1697 | VERIFY(0); | |
1698 | /* NOTREACHED */ | |
1699 | } | |
1700 | return; | |
1701 | } | |
1702 | ||
1703 | static inline void | |
1704 | if_afdata_lock_assert (struct ifnet *ifp, int af) | |
1705 | { | |
1706 | #if !MACH_ASSERT | |
1707 | #pragma unused(ifp) | |
1708 | #endif | |
1709 | switch (af) { | |
1710 | #if INET | |
1711 | case AF_INET: | |
1712 | LCK_RW_ASSERT(&ifp->if_inetdata_lock, LCK_RW_ASSERT_HELD); | |
1713 | break; | |
1714 | #endif | |
1715 | #if INET6 | |
1716 | case AF_INET6: | |
1717 | LCK_RW_ASSERT(&ifp->if_inet6data_lock, LCK_RW_ASSERT_HELD); | |
1718 | break; | |
1719 | #endif | |
1720 | default: | |
1721 | VERIFY(0); | |
1722 | /* NOTREACHED */ | |
1723 | } | |
1724 | return; | |
1725 | } | |
316670eb | 1726 | |
6d2010ae A |
1727 | #if INET6 |
1728 | struct in6_addr; | |
1729 | __private_extern__ struct in6_ifaddr *ifa_foraddr6(struct in6_addr *); | |
1730 | __private_extern__ struct in6_ifaddr *ifa_foraddr6_scoped(struct in6_addr *, | |
1731 | unsigned int); | |
1732 | #endif /* INET6 */ | |
1733 | ||
1734 | __private_extern__ void if_data_internal_to_if_data(struct ifnet *ifp, | |
1735 | const struct if_data_internal *if_data_int, struct if_data *if_data); | |
1736 | __private_extern__ void if_data_internal_to_if_data64(struct ifnet *ifp, | |
1737 | const struct if_data_internal *if_data_int, struct if_data64 *if_data64); | |
1738 | __private_extern__ void if_copy_traffic_class(struct ifnet *ifp, | |
1739 | struct if_traffic_class *if_tc); | |
316670eb A |
1740 | __private_extern__ void if_copy_data_extended(struct ifnet *ifp, |
1741 | struct if_data_extended *if_de); | |
1742 | __private_extern__ void if_copy_packet_stats(struct ifnet *ifp, | |
1743 | struct if_packet_stats *if_ps); | |
1744 | __private_extern__ void if_copy_rxpoll_stats(struct ifnet *ifp, | |
1745 | struct if_rxpoll_stats *if_rs); | |
6d2010ae A |
1746 | |
1747 | __private_extern__ struct rtentry *ifnet_cached_rtlookup_inet(struct ifnet *, | |
1748 | struct in_addr); | |
1749 | #if INET6 | |
1750 | __private_extern__ struct rtentry *ifnet_cached_rtlookup_inet6(struct ifnet *, | |
1751 | struct in6_addr *); | |
1752 | #endif /* INET6 */ | |
1753 | ||
a39ff7e2 A |
1754 | __private_extern__ u_int32_t if_get_protolist(struct ifnet * ifp, |
1755 | u_int32_t *protolist, u_int32_t count); | |
1756 | __private_extern__ void if_free_protolist(u_int32_t *list); | |
3e170ce0 A |
1757 | __private_extern__ errno_t if_state_update(struct ifnet *, |
1758 | struct if_interface_state *); | |
1759 | __private_extern__ void if_get_state(struct ifnet *, | |
1760 | struct if_interface_state *); | |
1761 | __private_extern__ errno_t if_probe_connectivity(struct ifnet *ifp, | |
1762 | u_int32_t conn_probe); | |
1763 | __private_extern__ void if_lqm_update(struct ifnet *, int32_t, int); | |
316670eb A |
1764 | __private_extern__ void ifnet_update_sndq(struct ifclassq *, cqev_t); |
1765 | __private_extern__ void ifnet_update_rcv(struct ifnet *, cqev_t); | |
1766 | ||
39236c6e A |
1767 | __private_extern__ void ifnet_flowadv(uint32_t); |
1768 | ||
316670eb A |
1769 | __private_extern__ errno_t ifnet_set_input_bandwidths(struct ifnet *, |
1770 | struct if_bandwidths *); | |
1771 | __private_extern__ errno_t ifnet_set_output_bandwidths(struct ifnet *, | |
1772 | struct if_bandwidths *, boolean_t); | |
1773 | __private_extern__ u_int64_t ifnet_output_linkrate(struct ifnet *); | |
1774 | __private_extern__ u_int64_t ifnet_input_linkrate(struct ifnet *); | |
39236c6e A |
1775 | |
1776 | __private_extern__ errno_t ifnet_set_input_latencies(struct ifnet *, | |
1777 | struct if_latencies *); | |
1778 | __private_extern__ errno_t ifnet_set_output_latencies(struct ifnet *, | |
1779 | struct if_latencies *, boolean_t); | |
1780 | ||
3e170ce0 A |
1781 | __private_extern__ void ifnet_clear_netagent(uuid_t); |
1782 | ||
1783 | __private_extern__ int ifnet_set_netsignature(struct ifnet *, uint8_t, | |
1784 | uint8_t, uint16_t, uint8_t *); | |
1785 | __private_extern__ int ifnet_get_netsignature(struct ifnet *, uint8_t, | |
1786 | uint8_t *, uint16_t *, uint8_t *); | |
1787 | ||
5ba3f43e A |
1788 | #if INET6 |
1789 | struct ipv6_prefix; | |
1790 | __private_extern__ int ifnet_set_nat64prefix(struct ifnet *, | |
1791 | struct ipv6_prefix *); | |
1792 | __private_extern__ int ifnet_get_nat64prefix(struct ifnet *, | |
1793 | struct ipv6_prefix *); | |
1794 | #endif | |
1795 | ||
39037602 A |
1796 | /* Required exclusive ifnet_head lock */ |
1797 | __private_extern__ void ifnet_remove_from_ordered_list(struct ifnet *); | |
1798 | ||
1799 | __private_extern__ void ifnet_increment_generation(struct ifnet *); | |
1800 | __private_extern__ u_int32_t ifnet_get_generation(struct ifnet *); | |
1801 | ||
5ba3f43e A |
1802 | /* Adding and deleting netagents will take ifnet lock */ |
1803 | __private_extern__ int if_add_netagent(struct ifnet *, uuid_t); | |
1804 | __private_extern__ int if_delete_netagent(struct ifnet *, uuid_t); | |
a39ff7e2 A |
1805 | __private_extern__ boolean_t if_check_netagent(struct ifnet *, uuid_t); |
1806 | ||
39037602 | 1807 | |
5ba3f43e A |
1808 | extern int if_set_qosmarking_mode(struct ifnet *, u_int32_t); |
1809 | __private_extern__ uint32_t ifnet_mbuf_packetpreamblelen(struct ifnet *); | |
1810 | __private_extern__ void intf_event_enqueue_nwk_wq_entry(struct ifnet *ifp, | |
1811 | struct sockaddr *addrp, uint32_t intf_event_code); | |
1812 | __private_extern__ void ifnet_update_stats_per_flow(struct ifnet_stats_per_flow *, | |
1813 | struct ifnet *); | |
1814 | #if !CONFIG_EMBEDDED | |
39236c6e A |
1815 | __private_extern__ errno_t ifnet_framer_stub(struct ifnet *, struct mbuf **, |
1816 | const struct sockaddr *, const char *, const char *, u_int32_t *, | |
1817 | u_int32_t *); | |
5ba3f43e A |
1818 | #endif /* !CONFIG_EMBEDDED */ |
1819 | __private_extern__ void ifnet_enqueue_multi_setup(struct ifnet *, uint16_t, | |
1820 | uint16_t); | |
1821 | __private_extern__ errno_t ifnet_enqueue_mbuf(struct ifnet *, struct mbuf *, | |
1822 | boolean_t, boolean_t *); | |
d9a64523 A |
1823 | |
1824 | extern int if_low_power_verbose; | |
1825 | extern int if_low_power_restricted; | |
1826 | extern void if_low_power_evhdlr_init(void); | |
1827 | extern int if_set_low_power(struct ifnet *, bool); | |
1828 | ||
316670eb A |
1829 | #endif /* BSD_KERNEL_PRIVATE */ |
1830 | #ifdef XNU_KERNEL_PRIVATE | |
1831 | /* for uuid.c */ | |
1832 | __private_extern__ int uuid_get_ethernet(u_int8_t *); | |
6d2010ae | 1833 | #endif /* XNU_KERNEL_PRIVATE */ |
1c79356b | 1834 | #endif /* !_NET_IF_VAR_H_ */ |