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