xref: /xnu-12377.81.4/bsd/net/if_var_private.h (revision 043036a2b3718f7f0be807e2870f8f47d3fa0796)
1 /*
2  * Copyright (c) 2000-2023 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_PRIVATE_H_
65 #define _NET_IF_VAR_PRIVATE_H_
66 
67 #ifndef DRIVERKIT
68 #ifndef DRIVERKIT_PRIVATE
69 #include <net/if_var_status.h>
70 #endif
71 #include <net/route.h>
72 #include <stdint.h>
73 #include <sys/types.h>
74 #include <sys/ioccom.h>
75 #ifdef KERNEL_PRIVATE
76 #include <kern/locks.h>
77 #include <net/kpi_interface.h>
78 #endif /* KERNEL_PRIVATE */
79 
80 struct if_traffic_class {
81 	u_int64_t               ifi_ibepackets;/* TC_BE packets received on interface */
82 	u_int64_t               ifi_ibebytes;/* TC_BE bytes received on interface */
83 	u_int64_t               ifi_obepackets;/* TC_BE packet sent on interface */
84 	u_int64_t               ifi_obebytes;/* TC_BE bytes sent on interface */
85 	u_int64_t               ifi_ibkpackets;/* TC_BK packets received on interface */
86 	u_int64_t               ifi_ibkbytes;/* TC_BK bytes received on interface */
87 	u_int64_t               ifi_obkpackets;/* TC_BK packet sent on interface */
88 	u_int64_t               ifi_obkbytes;/* TC_BK bytes sent on interface */
89 	u_int64_t               ifi_ivipackets;/* TC_VI packets received on interface */
90 	u_int64_t               ifi_ivibytes;/* TC_VI bytes received on interface */
91 	u_int64_t               ifi_ovipackets;/* TC_VI packets sent on interface */
92 	u_int64_t               ifi_ovibytes;/* TC_VI bytes sent on interface */
93 	u_int64_t               ifi_ivopackets;/* TC_VO packets received on interface */
94 	u_int64_t               ifi_ivobytes;/* TC_VO bytes received on interface */
95 	u_int64_t               ifi_ovopackets;/* TC_VO packets sent on interface */
96 	u_int64_t               ifi_ovobytes;/* TC_VO bytes sent on interface */
97 	u_int64_t               ifi_ipvpackets;/* TC priv packets received on interface */
98 	u_int64_t               ifi_ipvbytes;/* TC priv bytes received on interface */
99 	u_int64_t               ifi_opvpackets;/* TC priv packets sent on interface */
100 	u_int64_t               ifi_opvbytes;/* TC priv bytes sent on interface */
101 };
102 
103 struct if_data_extended {
104 	u_int64_t       ifi_alignerrs;/* unaligned (32-bit) input pkts */
105 	u_int64_t       ifi_dt_bytes;/* Data threshold counter */
106 	u_int64_t       ifi_fpackets;/* forwarded packets on interface */
107 	u_int64_t       ifi_fbytes; /* forwarded bytes on interface */
108 	u_int64_t       reserved[12];/* for future */
109 };
110 
111 struct if_packet_stats {
112 	/* TCP */
113 	u_int64_t               ifi_tcp_badformat;
114 	u_int64_t               ifi_tcp_unspecv6;
115 	u_int64_t               ifi_tcp_synfin;
116 	u_int64_t               ifi_tcp_badformatipsec;
117 	u_int64_t               ifi_tcp_noconnnolist;
118 	u_int64_t               ifi_tcp_noconnlist;
119 	u_int64_t               ifi_tcp_listbadsyn;
120 	u_int64_t               ifi_tcp_icmp6unreach;
121 	u_int64_t               ifi_tcp_deprecate6;
122 	u_int64_t               ifi_tcp_rstinsynrcv;
123 	u_int64_t               ifi_tcp_ooopacket;
124 	u_int64_t               ifi_tcp_dospacket;
125 	u_int64_t               ifi_tcp_cleanup;
126 	u_int64_t               ifi_tcp_synwindow;
127 	u_int64_t               reserved[6];
128 	/* UDP */
129 	u_int64_t               ifi_udp_port_unreach;
130 	u_int64_t               ifi_udp_faithprefix;
131 	u_int64_t               ifi_udp_port0;
132 	u_int64_t               ifi_udp_badlength;
133 	u_int64_t               ifi_udp_badchksum;
134 	u_int64_t               ifi_udp_badmcast;
135 	u_int64_t               ifi_udp_cleanup;
136 	u_int64_t               ifi_udp_badipsec;
137 	u_int64_t               _reserved[4];
138 };
139 
140 /*
141  * Structure to report link heuristics
142  */
143 #define HAS_IF_LINK_HEURISTICS_STATS 1
144 struct if_linkheuristics {
145 	u_int64_t       iflh_link_heuristics_cnt;  /* Count of congested link indications */
146 	u_int64_t       iflh_link_heuristics_time; /* Duration of congested link indications (msec) */
147 
148 	u_int64_t       iflh_congested_link_cnt;  /* Count of congested link indications */
149 	u_int64_t       iflh_congested_link_time; /* Duration of congested link indications (msec) */
150 
151 	u_int64_t       iflh_lqm_good_cnt;       /* Count of LQM good */
152 	u_int64_t       iflh_lqm_good_time;      /* Duration of LQM good (msec) */
153 
154 	u_int64_t       iflh_lqm_poor_cnt;       /* Count of LQM poor */
155 	u_int64_t       iflh_lqm_poor_time;      /* Duration of LQM poor (msec) */
156 
157 	u_int64_t       iflh_lqm_min_viable_cnt;  /* Count of LQM minimally viable */
158 	u_int64_t       iflh_lqm_min_viable_time; /* Duration of LQM minimally viable (msec) */
159 
160 	u_int64_t       iflh_lqm_bad_cnt;         /* Count of LQM bad */
161 	u_int64_t       iflh_lqm_bad_time;        /* Duration of LQM bad (msec) */
162 
163 	u_int64_t       iflh_tcp_linkheur_stealthdrop;
164 	u_int64_t       iflh_tcp_linkheur_noackpri;
165 	u_int64_t       iflh_tcp_linkheur_comprxmt;
166 	u_int64_t       iflh_tcp_linkheur_synrxmt;
167 	u_int64_t       iflh_tcp_linkheur_rxmtfloor;
168 
169 	u_int64_t       iflh_udp_linkheur_stealthdrop;
170 };
171 
172 struct if_description {
173 	u_int32_t       ifd_maxlen; /* must be IF_DESCSIZE */
174 	u_int32_t       ifd_len;    /* actual ifd_desc length */
175 	u_int8_t        *__sized_by(ifd_maxlen) ifd_desc;  /* ptr to desc buffer */
176 };
177 
178 struct if_bandwidths {
179 	uint64_t       eff_bw;     /* effective bandwidth */
180 	uint64_t       max_bw;     /* maximum theoretical bandwidth */
181 };
182 
183 struct if_latencies {
184 	u_int64_t       eff_lt;     /* effective latency */
185 	u_int64_t       max_lt;     /* maximum theoretical latency */
186 };
187 
188 typedef enum {
189 	IF_NETEM_MODEL_NULL = 0,
190 	IF_NETEM_MODEL_NLC = 1,
191 } if_netem_model_t;
192 
193 #define IF_NETEM_PARAMS_PSCALE  100000
194 struct if_netem_params {
195 	/* packet scheduler model */
196 	if_netem_model_t        ifnetem_model;
197 
198 	/* bandwidth limit */
199 	uint64_t        ifnetem_bandwidth_bps;
200 
201 	/* latency (normal distribution with jitter as stdev) */
202 	uint32_t        ifnetem_latency_ms;
203 	uint32_t        ifnetem_jitter_ms;
204 
205 	/*
206 	 * NetEm probabilistic model parameters has a scaling factor of 100,000
207 	 * for 5 digits precision. For instance, probability 12.345% is
208 	 * expressed as uint32_t fixed point 12345 in ifnet_*_p variable below.
209 	 */
210 	/* random packet corruption */
211 	uint32_t        ifnetem_corruption_p;
212 
213 	/* random packet duplication */
214 	uint32_t        ifnetem_duplication_p;
215 
216 	/* 4 state Markov loss model */
217 	uint32_t        ifnetem_loss_p_gr_gl;/* P( gap_loss   | gap_rx     ) */
218 	uint32_t        ifnetem_loss_p_gr_bl;/* P( burst_loss | gap_rx     ) */
219 	uint32_t        ifnetem_loss_p_bl_br;/* P( burst_rx   | burst_loss ) */
220 	uint32_t        ifnetem_loss_p_bl_gr;/* P( gap_rx     | burst_loss ) */
221 	uint32_t        ifnetem_loss_p_br_bl;/* P( burst_loss | burst_rx   ) */
222 
223 	uint32_t        ifnetem_loss_recovery_ms;/* time to recovery loss */
224 
225 	/* random packet reordering */
226 	uint32_t        ifnetem_reordering_p;/* reorder probability */
227 
228 	/*
229 	 * NetEm output scheduler by default is waken up upon input event as
230 	 * well as timer interval to avoid excessive delay. If
231 	 * ifnetem_output_ival is set to non-zero value, it overrides the
232 	 * default output interval as well as disables output scheduler wakeup
233 	 * upon input events.
234 	 */
235 	uint32_t        ifnetem_output_ival_ms;/* output interval */
236 };
237 
238 struct if_rxpoll_stats {
239 	u_int32_t       ifi_poll_off_req;   /* total # of POLL_OFF reqs */
240 	u_int32_t       ifi_poll_off_err;   /* total # of POLL_OFF errors */
241 	u_int32_t       ifi_poll_on_req;    /* total # of POLL_ON reqs */
242 	u_int32_t       ifi_poll_on_err;    /* total # of POLL_ON errors */
243 
244 	u_int32_t       ifi_poll_wakeups_avg;/* avg # of wakeup reqs */
245 	u_int32_t       ifi_poll_wakeups_lowat;/* wakeups low watermark */
246 	u_int32_t       ifi_poll_wakeups_hiwat;/* wakeups high watermark */
247 
248 	u_int64_t       ifi_poll_packets;   /* total # of polled packets */
249 	u_int32_t       ifi_poll_packets_avg;/* average polled packets */
250 	u_int32_t       ifi_poll_packets_min;/* smallest polled packets */
251 	u_int32_t       ifi_poll_packets_max;/* largest polled packets */
252 	u_int32_t       ifi_poll_packets_lowat;/* packets low watermark */
253 	u_int32_t       ifi_poll_packets_hiwat;/* packets high watermark */
254 
255 	u_int64_t       ifi_poll_bytes;     /* total # of polled bytes */
256 	u_int32_t       ifi_poll_bytes_avg; /* average polled bytes */
257 	u_int32_t       ifi_poll_bytes_min; /* smallest polled bytes */
258 	u_int32_t       ifi_poll_bytes_max; /* largest polled bytes */
259 	u_int32_t       ifi_poll_bytes_lowat;/* bytes low watermark */
260 	u_int32_t       ifi_poll_bytes_hiwat;/* bytes high watermark */
261 
262 	u_int32_t       ifi_poll_packets_limit;/* max packets per poll call */
263 	u_int64_t       ifi_poll_interval_time;/* poll interval (nsec) */
264 };
265 
266 struct if_netif_stats {
267 	u_int64_t       ifn_rx_mit_interval;/* rx mitigation ival (nsec) */
268 	u_int32_t       ifn_rx_mit_mode;    /* 0: static, 1: dynamic */
269 	u_int32_t       ifn_rx_mit_packets_avg;/* average # of packets */
270 	u_int32_t       ifn_rx_mit_packets_min;/* smallest # of packets */
271 	u_int32_t       ifn_rx_mit_packets_max;/* largest # of packets */
272 	u_int32_t       ifn_rx_mit_bytes_avg;/* average # of bytes */
273 	u_int32_t       ifn_rx_mit_bytes_min;/* smallest # of bytes */
274 	u_int32_t       ifn_rx_mit_bytes_max;/* largest # of bytes */
275 	u_int32_t       ifn_rx_mit_cfg_idx; /* current config selector */
276 	u_int32_t       ifn_rx_mit_cfg_packets_lowat;/* pkts low watermark */
277 	u_int32_t       ifn_rx_mit_cfg_packets_hiwat;/* pkts high watermark */
278 	u_int32_t       ifn_rx_mit_cfg_bytes_lowat;/* bytes low watermark */
279 	u_int32_t       ifn_rx_mit_cfg_bytes_hiwat;/* bytes high watermark */
280 	u_int32_t       ifn_rx_mit_cfg_interval;/* delay interval (nsec) */
281 };
282 
283 struct if_tcp_ecn_perf_stat {
284 	u_int64_t total_txpkts;
285 	u_int64_t total_rxmitpkts;
286 	u_int64_t total_rxpkts;
287 	u_int64_t total_oopkts;
288 	u_int64_t total_reorderpkts;
289 	u_int64_t rtt_avg;
290 	u_int64_t rtt_var;
291 	u_int64_t sack_episodes;
292 	u_int64_t rxmit_drop;
293 	u_int64_t rst_drop;
294 	u_int64_t oo_percent;
295 	u_int64_t reorder_percent;
296 	u_int64_t rxmit_percent;
297 };
298 
299 struct if_tcp_ecn_stat {
300 	u_int64_t timestamp;
301 	u_int64_t ecn_client_setup;
302 	u_int64_t ecn_server_setup;
303 	u_int64_t ecn_client_success;
304 	u_int64_t ecn_server_success;
305 	u_int64_t ecn_peer_nosupport;
306 	u_int64_t ecn_syn_lost;
307 	u_int64_t ecn_synack_lost;
308 	u_int64_t ecn_recv_ce;
309 	u_int64_t ecn_recv_ece;
310 	u_int64_t ecn_conn_recv_ce;
311 	u_int64_t ecn_conn_recv_ece;
312 	u_int64_t ecn_conn_plnoce;
313 	u_int64_t ecn_conn_plce;
314 	u_int64_t ecn_conn_noplce;
315 	u_int64_t ecn_fallback_synloss;
316 	u_int64_t ecn_fallback_reorder;
317 	u_int64_t ecn_fallback_ce;
318 	u_int64_t ecn_off_conn;
319 	u_int64_t ecn_total_conn;
320 	u_int64_t ecn_fallback_droprst;
321 	u_int64_t ecn_fallback_droprxmt;
322 	u_int64_t ecn_fallback_synrst;
323 	struct if_tcp_ecn_perf_stat ecn_on;
324 	struct if_tcp_ecn_perf_stat ecn_off;
325 };
326 
327 struct if_lim_perf_stat {
328 	u_int64_t lim_dl_max_bandwidth; /* bits per second */
329 	u_int64_t lim_ul_max_bandwidth; /* bits per second */
330 	u_int64_t lim_total_txpkts; /* Total transmit packets, count */
331 	u_int64_t lim_total_rxpkts; /* Total receive packets, count */
332 	u_int64_t lim_total_retxpkts; /* Total retransmit packets */
333 	u_int64_t lim_packet_loss_percent; /* Packet loss rate */
334 	u_int64_t lim_total_oopkts; /* Total out-of-order packets */
335 	u_int64_t lim_packet_ooo_percent; /* Out-of-order packet rate */
336 	u_int64_t lim_rtt_variance; /* RTT variance, milliseconds */
337 	u_int64_t lim_rtt_average;  /* RTT average, milliseconds */
338 	u_int64_t lim_rtt_min;      /* RTT minimum, milliseconds */
339 	u_int64_t lim_conn_timeouts; /* connection timeouts */
340 	u_int64_t lim_conn_attempts; /* connection attempts */
341 	u_int64_t lim_conn_timeout_percent; /* Rate of connection timeouts */
342 	u_int64_t lim_bk_txpkts;    /* Transmit packets with BK service class, that use delay based algorithms */
343 	u_int64_t lim_dl_detected:1, /* Low internet */
344 	    lim_ul_detected:1;
345 };
346 
347 #define IF_VAR_H_HAS_IFNET_STATS_PER_FLOW 1
348 #define IF_VAR_H_HAS_IFNET_STATS_PER_FLOW_LINKHEUR 1
349 struct ifnet_stats_per_flow {
350 	u_int64_t bk_txpackets;
351 	u_int64_t txpackets;
352 	u_int64_t rxpackets;
353 	u_int32_t txretransmitbytes;
354 	u_int32_t rxoutoforderbytes;
355 	u_int32_t rxmitpkts;
356 	u_int32_t rcvoopack;
357 	u_int32_t pawsdrop;
358 	u_int32_t sack_recovery_episodes;
359 	u_int32_t reordered_pkts;
360 	u_int32_t dsack_sent;
361 	u_int32_t dsack_recvd;
362 	u_int32_t srtt;
363 	u_int32_t rttupdated;
364 	u_int32_t rttvar;
365 	u_int32_t rttmin;
366 	u_int32_t bw_sndbw_max;
367 	u_int32_t bw_rcvbw_max;
368 	u_int32_t ecn_recv_ece;
369 	u_int32_t ecn_recv_ce;
370 	u_int32_t ecn_flags;
371 	u_int16_t ipv4:1,
372 	    local:1,
373 	    connreset:1,
374 	    conntimeout:1,
375 	    rxmit_drop:1,
376 	    ecn_fallback_synloss:1,
377 	    ecn_fallback_droprst:1,
378 	    ecn_fallback_droprxmt:1,
379 	    ecn_fallback_ce:1,
380 	    ecn_fallback_reorder:1,
381 	    _reserved_6:6;
382 	u_int16_t _reserved_16;
383 	u_int32_t _reserved_32;
384 	u_int64_t linkheur_noackpri;
385 	u_int64_t linkheur_comprxmt;
386 	u_int64_t linkheur_synrxmt;
387 	u_int64_t linkheur_rxmtfloor;
388 };
389 
390 struct if_interface_state {
391 	/*
392 	 * The bitmask tells which of the fields
393 	 * to consider:
394 	 * - When setting, to control which fields
395 	 *   are being modified;
396 	 * - When getting, it tells which fields are set.
397 	 */
398 	u_int8_t valid_bitmask;
399 #define IF_INTERFACE_STATE_RRC_STATE_VALID              0x1
400 #define IF_INTERFACE_STATE_LQM_STATE_VALID              0x2
401 #define IF_INTERFACE_STATE_INTERFACE_AVAILABILITY_VALID 0x4
402 
403 	/*
404 	 * Valid only for cellular interface
405 	 */
406 	u_int8_t rrc_state;
407 #define IF_INTERFACE_STATE_RRC_STATE_IDLE       0x0
408 #define IF_INTERFACE_STATE_RRC_STATE_CONNECTED  0x1
409 
410 	/*
411 	 * Values normalized to the edge of the following values
412 	 * that are defined on <net/if.h>:
413 	 *  IFNET_LQM_THRESH_BAD
414 	 *  IFNET_LQM_THRESH_POOR
415 	 *  IFNET_LQM_THRESH_GOOD
416 	 */
417 	int8_t lqm_state;
418 
419 	/*
420 	 * Indicate if the underlying link is currently
421 	 * available
422 	 */
423 	u_int8_t interface_availability;
424 #define IF_INTERFACE_STATE_INTERFACE_AVAILABLE          0x0
425 #define IF_INTERFACE_STATE_INTERFACE_UNAVAILABLE        0x1
426 };
427 
428 struct chain_len_stats {
429 	uint64_t        cls_one;
430 	uint64_t        cls_two;
431 	uint64_t        cls_three;
432 	uint64_t        cls_four;
433 	uint64_t        cls_five_or_more;
434 } __attribute__((__aligned__(sizeof(uint64_t))));
435 
436 #ifdef BSD_KERNEL_PRIVATE
437 #define IFNETS_MAX      64
438 
439 /*
440  * Internal storage of if_data. This is bound to change. Various places in the
441  * stack will translate this data structure in to the externally visible
442  * if_data structure above.  Note that during interface attach time, the
443  * embedded if_data structure in ifnet is cleared, with the exception of
444  * some non-statistics related fields.
445  */
446 struct if_data_internal {
447 	/* generic interface information */
448 	u_char          ifi_type;       /* ethernet, tokenring, etc */
449 	u_char          ifi_typelen;    /* Length of frame type id */
450 	u_char          ifi_physical;   /* e.g., AUI, Thinnet, 10base-T, etc */
451 	u_char          ifi_addrlen;    /* media address length */
452 	u_char          ifi_hdrlen;     /* media header length */
453 	u_char          ifi_recvquota;  /* polling quota for receive intrs */
454 	u_char          ifi_xmitquota;  /* polling quota for xmit intrs */
455 	u_char          ifi_unused1;    /* for future use */
456 	u_int32_t       ifi_mtu;        /* maximum transmission unit */
457 	u_int32_t       ifi_metric;     /* routing metric (external only) */
458 	u_int32_t       ifi_baudrate;   /* linespeed */
459 	/* volatile statistics */
460 	u_int64_t       ifi_ipackets;   /* packets received on interface */
461 	u_int64_t       ifi_ierrors;    /* input errors on interface */
462 	u_int64_t       ifi_opackets;   /* packets sent on interface */
463 	u_int64_t       ifi_oerrors;    /* output errors on interface */
464 	u_int64_t       ifi_collisions; /* collisions on csma interfaces */
465 	u_int64_t       ifi_ibytes;     /* total number of octets received */
466 	u_int64_t       ifi_obytes;     /* total number of octets sent */
467 	u_int64_t       ifi_imcasts;    /* packets received via multicast */
468 	u_int64_t       ifi_omcasts;    /* packets sent via multicast */
469 	u_int64_t       ifi_iqdrops;    /* dropped on input, this interface */
470 	u_int64_t       ifi_noproto;    /* destined for unsupported protocol */
471 	u_int32_t       ifi_recvtiming; /* usec spent receiving when timing */
472 	u_int32_t       ifi_xmittiming; /* usec spent xmitting when timing */
473 	u_int64_t       ifi_alignerrs;  /* unaligned (32-bit) input pkts */
474 	u_int64_t       ifi_dt_bytes;   /* Data threshold counter */
475 	u_int64_t       ifi_fpackets;   /* forwarded packets on interface */
476 	u_int64_t       ifi_fbytes;     /* forwarded bytes on interface */
477 	u_int64_t       ifi_link_heuristics_cnt;  /* Count of link heuristics enabled */
478 	u_int64_t       ifi_link_heuristics_time; /* Duration of link heuristics enabled (msec) */
479 	u_int64_t       ifi_congested_link_cnt;  /* Count of congested link indications */
480 	u_int64_t       ifi_congested_link_time; /* Duration of congested link indications (msec) */
481 	u_int64_t       ifi_lqm_good_cnt;  /* Count of lqm good*/
482 	u_int64_t       ifi_lqm_good_time; /* Duration of lqm good (msec) */
483 	u_int64_t       ifi_lqm_poor_cnt;  /* Count of lqm poor */
484 	u_int64_t       ifi_lqm_poor_time; /* Duration of lqm poor (msec) */
485 	u_int64_t       ifi_lqm_min_viable_cnt;  /* Count of lqm minimally viable */
486 	u_int64_t       ifi_lqm_min_viable_time; /* Duration of lqm minimally viable (msec) */
487 	u_int64_t       ifi_lqm_bad_cnt;  /* Count of lqm bad */
488 	u_int64_t       ifi_lqm_bad_time; /* Duration of lqm bad (msec) */
489 	struct timeval  ifi_lastchange; /* time of last administrative change */
490 	struct timeval  ifi_lastupdown; /* time of last up/down event */
491 	u_int32_t       ifi_hwassist;   /* HW offload capabilities */
492 	u_int32_t       ifi_tso_v4_mtu; /* TCP Segment Offload IPv4 maximum segment size */
493 	u_int32_t       ifi_tso_v6_mtu; /* TCP Segment Offload IPv6 maximum segment size */
494 };
495 
496 /*
497  * List of if_proto structures in if_proto_hash[] is protected by
498  * the ifnet lock.  The rest of the fields are initialized at protocol
499  * attach time and never change, thus no lock required as long as
500  * a reference to it is valid, via if_proto_ref().
501  */
502 struct if_proto {
503 	SLIST_ENTRY(if_proto)       next_hash;
504 	u_int32_t                   refcount;
505 	u_int32_t                   detached;
506 	struct ifnet                *ifp;
507 	protocol_family_t           protocol_family;
508 	int                         proto_kpi;
509 	union {
510 		struct {
511 			proto_media_input               input;
512 			proto_media_preout              pre_output;
513 			proto_media_event               event;
514 			proto_media_ioctl               ioctl;
515 			proto_media_detached            detached;
516 			proto_media_resolve_multi       resolve_multi;
517 			proto_media_send_arp            send_arp;
518 		} v1;
519 		struct {
520 			proto_media_input_v2            input;
521 			proto_media_preout              pre_output;
522 			proto_media_event               event;
523 			proto_media_ioctl               ioctl;
524 			proto_media_detached            detached;
525 			proto_media_resolve_multi       resolve_multi;
526 			proto_media_send_arp            send_arp;
527 		} v2;
528 	} kpi;
529 };
530 
531 SLIST_HEAD(proto_hash_entry, if_proto);
532 
533 __CCT_DECLARE_CONSTRAINED_PTR_TYPES(struct if_proto, if_proto);
534 
535 #endif /* BSD_KERNEL_PRIVATE */
536 
537 #define if_mtu          if_data.ifi_mtu
538 #define if_type         if_data.ifi_type
539 #define if_typelen      if_data.ifi_typelen
540 #define if_physical     if_data.ifi_physical
541 #define if_addrlen      if_data.ifi_addrlen
542 #define if_hdrlen       if_data.ifi_hdrlen
543 #define if_metric       if_data.ifi_metric
544 #define if_baudrate     if_data.ifi_baudrate
545 #define if_hwassist     if_data.ifi_hwassist
546 #define if_ipackets     if_data.ifi_ipackets
547 #define if_ierrors      if_data.ifi_ierrors
548 #define if_opackets     if_data.ifi_opackets
549 #define if_oerrors      if_data.ifi_oerrors
550 #define if_collisions   if_data.ifi_collisions
551 #define if_ibytes       if_data.ifi_ibytes
552 #define if_obytes       if_data.ifi_obytes
553 #define if_imcasts      if_data.ifi_imcasts
554 #define if_omcasts      if_data.ifi_omcasts
555 #define if_iqdrops      if_data.ifi_iqdrops
556 #define if_noproto      if_data.ifi_noproto
557 #define if_lastchange   if_data.ifi_lastchange
558 #define if_recvquota    if_data.ifi_recvquota
559 #define if_xmitquota    if_data.ifi_xmitquota
560 #ifdef BSD_KERNEL_PRIVATE
561 #define if_tso_v4_mtu   if_data.ifi_tso_v4_mtu
562 #define if_tso_v6_mtu   if_data.ifi_tso_v6_mtu
563 #define if_alignerrs    if_data.ifi_alignerrs
564 #define if_dt_bytes     if_data.ifi_dt_bytes
565 #define if_fpackets     if_data.ifi_fpackets
566 #define if_fbytes       if_data.ifi_fbytes
567 #define if_lastupdown   if_data.ifi_lastupdown
568 #define if_link_heuristics_cnt    if_data.ifi_link_heuristics_cnt
569 #define if_link_heuristics_time   if_data.ifi_link_heuristics_time
570 #define if_congested_link_cnt    if_data.ifi_congested_link_cnt
571 #define if_congested_link_time   if_data.ifi_congested_link_time
572 #define if_lqm_good_cnt         if_data.ifi_lqm_good_cnt
573 #define if_lqm_good_time        if_data.ifi_lqm_good_time
574 #define if_lqm_poor_cnt         if_data.ifi_lqm_poor_cnt
575 #define if_lqm_poor_time        if_data.ifi_lqm_poor_time
576 #define if_lqm_min_viable_cnt   if_data.ifi_lqm_min_viable_cnt
577 #define if_lqm_min_viable_time  if_data.ifi_lqm_min_viable_time
578 #define if_lqm_bad_cnt          if_data.ifi_lqm_bad_cnt
579 #define if_lqm_bad_time         if_data.ifi_lqm_bad_time
580 
581 /*
582  * Forward structure declarations for function prototypes [sic].
583  */
584 struct proc;
585 struct rtentry;
586 struct socket;
587 struct ifnet_filter;
588 struct mbuf;
589 struct ifaddr;
590 struct tqdummy;
591 struct dlil_threading_info;
592 struct tcpstat_local;
593 struct udpstat_local;
594 #if PF
595 struct pfi_kif;
596 #endif /* PF */
597 #if SKYWALK
598 struct nexus_netif_adapter;
599 #endif /* SKYWALK */
600 
601 /* we use TAILQs so that the order of instantiation is preserved in the list */
602 TAILQ_HEAD(ifnethead, ifnet);
603 TAILQ_HEAD(ifaddrhead, ifaddr);
604 LIST_HEAD(ifmultihead, ifmultiaddr);
605 TAILQ_HEAD(tailq_head, tqdummy);
606 TAILQ_HEAD(ifnet_filter_head, ifnet_filter);
607 TAILQ_HEAD(ddesc_head_name, dlil_demux_desc);
608 
609 extern bool intcoproc_unrestricted;
610 extern bool management_data_unrestricted;
611 extern bool management_control_unrestricted;
612 extern bool if_management_interface_check_needed;
613 extern int if_management_verbose;
614 extern int if_ultra_constrained_default_allowed;
615 extern bool if_ultra_constrained_check_needed;
616 #endif /* BSD_KERNEL_PRIVATE */
617 
618 /*
619  * All of the following IF_HWASSIST_* flags are defined in kpi_interface.h as
620  * IFNET_* flags. These are redefined here as constants to avoid failures to
621  * build user level programs that can not include kpi_interface.h. It is
622  * important to keep this in sync with the definitions in kpi_interface.h.
623  * The corresponding constant for each definition is mentioned in the comment.
624  *
625  * Bottom 16 bits reserved for hardware checksum
626  */
627 #define IF_HWASSIST_CSUM_IP             0x0001  /* will csum IP, IFNET_CSUM_IP */
628 #define IF_HWASSIST_CSUM_TCP            0x0002  /* will csum TCP, IFNET_CSUM_TCP */
629 #define IF_HWASSIST_CSUM_UDP            0x0004  /* will csum UDP, IFNET_CSUM_UDP */
630 #define IF_HWASSIST_CSUM_IP_FRAGS       0x0008  /* will csum IP fragments, IFNET_CSUM_FRAGMENT */
631 #define IF_HWASSIST_CSUM_FRAGMENT       0x0010  /* will do IP fragmentation, IFNET_IP_FRAGMENT */
632 #define IF_HWASSIST_CSUM_TCPIPV6        0x0020  /* will csum TCPv6, IFNET_CSUM_TCPIPV6 */
633 #define IF_HWASSIST_CSUM_UDPIPV6        0x0040  /* will csum UDPv6, IFNET_CSUM_UDP */
634 #define IF_HWASSIST_CSUM_FRAGMENT_IPV6  0x0080  /* will do IPv6 fragmentation, IFNET_IPV6_FRAGMENT */
635 #define IF_HWASSIST_CSUM_PARTIAL        0x1000  /* simple Sum16 computation, IFNET_CSUM_PARTIAL */
636 #define IF_HWASSIST_CSUM_ZERO_INVERT    0x2000  /* capable of inverting csum of 0 to -0 (0xffff) */
637 #define IF_HWASSIST_CSUM_MASK           0xffff
638 #define IF_HWASSIST_CSUM_FLAGS(hwassist)        ((hwassist) & IF_HWASSIST_CSUM_MASK)
639 
640 /* VLAN support */
641 #define IF_HWASSIST_VLAN_TAGGING        0x00010000      /* supports VLAN tagging, IFNET_VLAN_TAGGING */
642 #define IF_HWASSIST_VLAN_MTU            0x00020000      /* supports VLAN MTU-sized packet (for software VLAN), IFNET_VLAN_MTU */
643 
644 /* TCP Segment Offloading support */
645 
646 #define IF_HWASSIST_TSO_V4              0x00200000      /* will do TCP Segment offload for IPv4, IFNET_TSO_IPV4 */
647 #define IF_HWASSIST_TSO_V6              0x00400000      /* will do TCP Segment offload for IPv6, IFNET_TSO_IPV6 */
648 
649 #define IFXNAMSIZ       (IFNAMSIZ + 8)  /* external name (name + unit) */
650 #define IFNET_NETWORK_ID_LEN 32
651 
652 #ifdef BSD_KERNEL_PRIVATE
653 /*
654  * ifnet is private to BSD portion of kernel
655  */
656 #include <sys/mcache.h>
657 #include <sys/tree.h>
658 #include <netinet/in.h>
659 #include <net/if_dl.h>
660 #include <net/classq/if_classq.h>
661 #include <net/if_types.h>
662 #include <net/route.h>
663 
664 RB_HEAD(ll_reach_tree, if_llreach);     /* define struct ll_reach_tree */
665 
666 #if SKYWALK
667 struct nexus_ifnet_ops {
668 	void (*ni_finalize)(struct nexus_netif_adapter *, struct ifnet *);
669 	void (*ni_reap)(struct nexus_netif_adapter *, struct ifnet *,
670 	    uint32_t, boolean_t);
671 	errno_t (*ni_dequeue)(struct nexus_netif_adapter *, uint32_t,
672 	    uint32_t, uint32_t, classq_pkt_t *, classq_pkt_t *, uint32_t *,
673 	    uint32_t *, boolean_t, errno_t);
674 	errno_t (*ni_get_len)(struct nexus_netif_adapter *, uint32_t,
675 	    uint32_t *, uint32_t *, errno_t);
676 };
677 typedef struct {
678 	uuid_t          if_nif_provider;
679 	uuid_t          if_nif_instance;
680 	uuid_t          if_nif_attach;
681 } if_nexus_netif, *if_nexus_netif_t;
682 
683 typedef struct {
684 	uuid_t          if_fsw_provider;
685 	uuid_t          if_fsw_instance;
686 	uuid_t          if_fsw_device;
687 	uint32_t        if_fsw_ipaddr_gencnt;
688 } if_nexus_flowswitch, *if_nexus_flowswitch_t;
689 
690 typedef void (*ifnet_fsw_rx_cb_t)(void *, struct pktq *);
691 typedef void (*ifnet_detach_notify_cb_t)(void *);
692 #endif /* SKYWALK */
693 
694 typedef errno_t (*dlil_input_func)(ifnet_t ifp, mbuf_t m_head,
695     mbuf_t m_tail, const struct ifnet_stat_increment_param *s,
696     boolean_t poll, struct thread *tp);
697 typedef errno_t (*dlil_output_func)(ifnet_t interface, mbuf_t data);
698 
699 typedef u_int8_t        ipv6_router_mode_t;
700 
701 #define if_name(ifp)    ifp->if_xname
702 /*
703  * Structure defining a network interface.
704  *
705  * (Would like to call this struct ``if'', but C isn't PL/1.)
706  */
707 struct ifnet {
708 	/*
709 	 * Lock (RW or mutex) to protect this data structure (static storage.)
710 	 */
711 	decl_lck_rw_data(, if_lock);
712 	void            *if_softc;      /* pointer to driver state */
713 	const char      *if_name;       /* name, e.g. ``en'' or ``lo'' */
714 	const char      *if_xname;      /* external name (name + unit) */
715 	struct if_description if_desc;  /* extended description */
716 	TAILQ_ENTRY(ifnet) if_link;     /* all struct ifnets are chained */
717 	TAILQ_ENTRY(ifnet) if_detaching_link; /* list of detaching ifnets */
718 	TAILQ_ENTRY(ifnet) if_ordered_link;     /* list of ordered ifnets */
719 
720 	decl_lck_mtx_data(, if_ref_lock);
721 	u_int32_t       if_refflags;    /* see IFRF flags below */
722 	os_refcnt_t     if_refio;       /* number of io ops to the underlying driver */
723 	u_int32_t       if_threads_pending;    /* Threads created but waiting for first run */
724 	os_ref_atomic_t if_datamov;     /* number of threads moving data */
725 	u_int32_t       if_suspend;     /* number of suspend requests */
726 
727 #define if_list         if_link
728 	struct ifaddrhead if_addrhead;  /* linked list of addresses per if */
729 #define if_addrlist     if_addrhead
730 	struct ifaddr   *if_lladdr;     /* link address (first/permanent) */
731 
732 	u_int32_t       if_qosmarking_mode;     /* generation to use with NECP clients */
733 
734 	int             if_pcount;      /* number of promiscuous listeners */
735 	struct bpf_if   *if_bpf;        /* packet filter structure */
736 	u_short         if_index;       /* numeric abbreviation for this if  */
737 	short           if_unit;        /* sub-unit for lower level driver */
738 	short           if_timer;       /* time 'til if_watchdog called */
739 	short           if_flags;       /* up/down, broadcast, etc. */
740 	u_int32_t       if_eflags;      /* see <net/if.h> */
741 	u_int32_t       if_xflags;      /* see <net/if.h> */
742 
743 	int             if_capabilities;        /* interface features & capabilities */
744 	int             if_capenable;           /* enabled features & capabilities */
745 
746 	void *__sized_by(if_linkmiblen) if_linkmib; /* link-type-specific MIB data */
747 	uint32_t         if_linkmiblen;  /* length of above data */
748 
749 	struct if_data_internal if_data __attribute__((aligned(8)));
750 
751 	ifnet_family_t          if_family;      /* value assigned by Apple */
752 	ifnet_subfamily_t       if_subfamily;   /* value assigned by Apple */
753 	u_int32_t               peer_egress_functional_type; /* value assigned by Apple */
754 
755 	uintptr_t               if_family_cookie;
756 	volatile dlil_input_func if_input_dlil;
757 	volatile dlil_output_func if_output_dlil;
758 	volatile ifnet_start_func if_start;
759 	ifnet_output_func       if_output;
760 	ifnet_pre_enqueue_func  if_pre_enqueue;
761 	ifnet_ctl_func          if_output_ctl;
762 	ifnet_input_poll_func   if_input_poll;
763 	ifnet_ctl_func          if_input_ctl;
764 	ifnet_ioctl_func        if_ioctl;
765 	ifnet_set_bpf_tap       if_set_bpf_tap;
766 	ifnet_detached_func     if_free;
767 	ifnet_demux_func        if_demux;
768 	ifnet_event_func        if_event;
769 	ifnet_framer_func       if_framer_legacy;
770 	ifnet_framer_extended_func if_framer;
771 	ifnet_add_proto_func    if_add_proto;
772 	ifnet_del_proto_func    if_del_proto;
773 	ifnet_check_multi       if_check_multi;
774 	size_t                  if_proto_hash_count;
775 	struct proto_hash_entry *__counted_by(if_proto_hash_count) if_proto_hash;
776 	ifnet_detached_func     if_detach;
777 
778 	u_int32_t               if_flowhash;    /* interface flow control ID */
779 
780 	decl_lck_mtx_data(, if_start_lock);
781 	u_int32_t               if_start_flags; /* see IFSF flags below */
782 	u_int32_t               if_start_req;
783 	u_int8_t                if_start_embryonic;
784 	u_int8_t                if_start_active; /* output is active */
785 	u_int16_t               if_start_delayed;
786 	u_int16_t               if_start_delay_qlen;
787 	u_int16_t               if_start_delay_idle;
788 	u_int64_t               if_start_delay_swin;
789 	u_int32_t               if_start_delay_cnt;
790 	u_int32_t               if_start_delay_timeout; /* nanoseconds */
791 	struct timespec         if_start_cycle;  /* restart interval */
792 	struct thread           *if_start_thread;
793 
794 	struct ifclassq         *if_snd;         /* transmit queue */
795 	u_int32_t               if_output_sched_model;  /* tx sched model */
796 
797 	struct if_bandwidths    if_output_bw;
798 	struct if_bandwidths    if_input_bw;
799 
800 	struct if_latencies     if_output_lt;
801 	struct if_latencies     if_input_lt;
802 
803 	decl_lck_mtx_data(, if_flt_lock);
804 	u_int32_t               if_flt_busy;
805 	u_int32_t               if_flt_waiters;
806 	struct ifnet_filter_head if_flt_head;
807 	uint32_t                if_flt_non_os_count;
808 	uint32_t                if_flt_no_tso_count;
809 
810 	struct ifmultihead      if_multiaddrs;  /* multicast addresses */
811 	u_int32_t               if_updatemcasts; /* mcast addrs need updating */
812 	int                     if_amcount;     /* # of all-multicast reqs */
813 	decl_lck_mtx_data(, if_addrconfig_lock); /* for serializing addr config */
814 	struct in_multi         *if_allhostsinm; /* store all-hosts inm for this ifp */
815 
816 	/*
817 	 * Opportunistic polling parameters.
818 	 */
819 	decl_lck_mtx_data(, if_poll_lock);
820 	struct if_poll_params {
821 		u_int16_t       poll_req;
822 		u_int16_t       poll_update; /* link update */
823 		u_int32_t       poll_flags;
824 #define IF_POLLF_READY          0x1     /* poll thread is ready */
825 #define IF_POLLF_RUNNING        0x2     /* poll thread is running/active */
826 #define IF_POLLF_TERMINATING    0x4     /* poll thread is terminating */
827 #define IF_POLLF_EMBRYONIC      0x8000  /* poll thread is being setup */
828 		struct timespec poll_cycle;  /* poll interval */
829 		struct thread   *poll_thread;
830 
831 		ifnet_model_t   poll_mode;   /* current mode */
832 		struct pktcntr  poll_tstats; /* incremental polling statistics */
833 		struct if_rxpoll_stats poll_pstats;  /* polling statistics */
834 		struct pktcntr  poll_sstats; /* packets and bytes per sampling */
835 		struct timespec poll_mode_holdtime; /* mode holdtime in nsec */
836 		struct timespec poll_mode_lasttime; /* last mode change time in nsec */
837 		struct timespec poll_sample_holdtime; /* sampling holdtime in nsec */
838 		struct timespec poll_sample_lasttime; /* last sampling time in nsec */
839 		struct timespec poll_dbg_lasttime; /* last debug message time in nsec */
840 	} rxpoll_params;
841 #define if_poll_req     rxpoll_params.poll_req
842 #define if_poll_update  rxpoll_params.poll_update
843 #define if_poll_flags   rxpoll_params.poll_flags
844 #define if_poll_cycle   rxpoll_params.poll_cycle
845 #define if_poll_thread  rxpoll_params.poll_thread
846 #define if_poll_mode    rxpoll_params.poll_mode
847 #define if_poll_tstats  rxpoll_params.poll_tstats
848 #define if_poll_sstats  rxpoll_params.poll_sstats
849 #define if_poll_pstats  rxpoll_params.poll_pstats
850 
851 #define if_poll_mode_holdtime    rxpoll_params.poll_mode_holdtime
852 #define if_poll_mode_lasttime    rxpoll_params.poll_mode_lasttime
853 #define if_poll_sample_holdtime  rxpoll_params.poll_sample_holdtime
854 #define if_poll_sample_lasttime  rxpoll_params.poll_sample_lasttime
855 #define if_poll_dbg_lasttime     rxpoll_params.poll_dbg_lasttime
856 
857 #define if_rxpoll_offreq   rxpoll_params.poll_pstats.ifi_poll_off_req
858 #define if_rxpoll_offerr   rxpoll_params.poll_pstats.ifi_poll_off_err
859 #define if_rxpoll_onreq    rxpoll_params.poll_pstats.ifi_poll_on_req
860 #define if_rxpoll_onerr    rxpoll_params.poll_pstats.ifi_poll_on_err
861 #define if_rxpoll_wavg     rxpoll_params.poll_pstats.ifi_poll_wakeups_avg
862 #define if_rxpoll_wlowat   rxpoll_params.poll_pstats.ifi_poll_wakeups_lowat
863 #define if_rxpoll_whiwat   rxpoll_params.poll_pstats.ifi_poll_wakeups_hiwat
864 #define if_rxpoll_pavg     rxpoll_params.poll_pstats.ifi_poll_packets_avg
865 #define if_rxpoll_pmin     rxpoll_params.poll_pstats.ifi_poll_packets_min
866 #define if_rxpoll_pmax     rxpoll_params.poll_pstats.ifi_poll_packets_max
867 #define if_rxpoll_plowat   rxpoll_params.poll_pstats.ifi_poll_packets_lowat
868 #define if_rxpoll_phiwat   rxpoll_params.poll_pstats.ifi_poll_packets_hiwat
869 #define if_rxpoll_bavg     rxpoll_params.poll_pstats.ifi_poll_bytes_avg
870 #define if_rxpoll_bmin     rxpoll_params.poll_pstats.ifi_poll_bytes_min
871 #define if_rxpoll_bmax     rxpoll_params.poll_pstats.ifi_poll_bytes_max
872 #define if_rxpoll_blowat   rxpoll_params.poll_pstats.ifi_poll_bytes_lowat
873 #define if_rxpoll_bhiwat   rxpoll_params.poll_pstats.ifi_poll_bytes_hiwat
874 #define if_rxpoll_plim     rxpoll_params.poll_pstats.ifi_poll_packets_limit
875 #define if_rxpoll_ival     rxpoll_params.poll_pstats.ifi_poll_interval_time
876 
877 	struct dlil_threading_info *if_inp;
878 
879 	/* allocated once along with dlil_ifnet and is never freed */
880 	thread_call_t           if_dt_tcall;
881 
882 	struct {
883 		u_int32_t       length;
884 		u_char *__sized_by(length) ptr;
885 	} if_broadcast;
886 
887 #if PF
888 	struct pfi_kif          *if_pf_kif;
889 #endif /* PF */
890 #if SKYWALK
891 	struct nexus_ifnet_ops *if_na_ops;
892 	struct nexus_netif_adapter *if_na;
893 
894 	/* compat netif attachment */
895 	if_nexus_netif          if_nx_netif;
896 
897 	/* flowswitch attachment */
898 	if_nexus_flowswitch     if_nx_flowswitch;
899 
900 	/* headroom space to be reserved in tx packets */
901 	uint16_t                if_tx_headroom;
902 
903 	/* trailer space to be reserved in tx packets */
904 	uint16_t                if_tx_trailer;
905 
906 	/*
907 	 * mitigation interval in microseconds for the rx interrupt mitigation
908 	 * logic while operating in the high throughput mode.
909 	 */
910 	uint32_t                if_rx_mit_ival;
911 
912 	/*
913 	 * Number of threads waiting for the start callback to be finished;
914 	 * access is protected by if_start_lock; also serves as wait channel.
915 	 */
916 	uint32_t                if_start_waiters;
917 
918 	ifnet_start_func        if_save_start;
919 	ifnet_output_func       if_save_output;
920 
921 	/*
922 	 * Used for intercepting packets meant for the host stack.
923 	 */
924 	ifnet_fsw_rx_cb_t       if_fsw_rx_cb;
925 	void                    *if_fsw_rx_cb_arg;
926 	uint32_t                if_fsw_rx_cb_ref;
927 
928 	uint32_t                if_delegate_parent_ref;
929 	struct ifnet            *if_delegate_parent;
930 	decl_lck_mtx_data(, if_delegate_lock);
931 
932 	/*
933 	 * Detach notify callback. Used by llw and redirect interfaces.
934 	 */
935 	ifnet_detach_notify_cb_t if_detach_notify;
936 	void                     *if_detach_notify_arg;
937 #endif /* SKYWALK */
938 
939 	decl_lck_mtx_data(, if_cached_route_lock);
940 	u_int32_t               if_fwd_cacheok;
941 	struct route            if_fwd_route;   /* cached forwarding route */
942 	struct route            if_src_route;   /* cached ipv4 source route */
943 	struct route_in6        if_src_route6;  /* cached ipv6 source route */
944 
945 	decl_lck_rw_data(, if_llreach_lock);
946 	struct ll_reach_tree    if_ll_srcs;     /* source link-layer tree */
947 
948 	void                    *if_bridge;     /* bridge glue */
949 
950 	u_int32_t               if_idle_flags;  /* idle flags */
951 	u_int32_t               if_idle_new_flags; /* temporary idle flags */
952 	u_int32_t               if_idle_new_flags_mask; /* temporary mask */
953 	u_int32_t               if_route_refcnt; /* idle: route ref count */
954 	u_int32_t               if_rt_sendts;   /* last of a real time packet */
955 
956 	struct if_traffic_class if_tc __attribute__((aligned(8)));
957 #if INET
958 	struct igmp_ifinfo      *if_igi;        /* for IGMPv3 */
959 #endif /* INET */
960 	struct mld_ifinfo       *if_mli;        /* for MLDv2 */
961 
962 	struct tcpstat_local    *if_tcp_stat;   /* TCP specific stats */
963 	struct udpstat_local    *if_udp_stat;   /* UDP specific stats */
964 
965 	struct {
966 		int32_t         level;          /* cached logging level */
967 		u_int32_t       flags;          /* cached logging flags */
968 		int32_t         category;       /* cached category */
969 		int32_t         subcategory;    /* cached subcategory */
970 	} if_log;
971 
972 	struct {
973 		struct ifnet    *ifp;           /* delegated ifp */
974 		u_int32_t       type;           /* delegated i/f type */
975 		u_int32_t       family;         /* delegated i/f family */
976 		u_int32_t       subfamily;      /* delegated i/f sub-family */
977 		uint32_t        expensive:1,    /* delegated i/f expensive? */
978 		    constrained:1,              /* delegated i/f constrained? */
979 		    ultra_constrained:1;      /* delegated i/f ultra constrained? */
980 	} if_delegated;
981 
982 	uuid_t                  *if_agentids __counted_by(if_agentcount);   /* network agents attached to interface */
983 	u_int32_t               if_agentcount;
984 
985 	volatile uint32_t       if_low_power_gencnt;
986 
987 	u_int32_t               if_generation;  /* generation to use with NECP clients */
988 	u_int32_t               if_fg_sendts;   /* last send on a fg socket in seconds */
989 
990 	u_int64_t               if_data_threshold;
991 
992 	/* Total bytes in send socket buffer */
993 	int64_t                 if_sndbyte_total __attribute__ ((aligned(8)));
994 	/* Total unsent bytes in send socket buffer */
995 	int64_t                 if_sndbyte_unsent __attribute__ ((aligned(8)));
996 	/* count of times, when there was data to send when sleep is impending */
997 	uint32_t                if_unsent_data_cnt;
998 
999 	boolean_t   if_inet6_ioctl_busy;
1000 	decl_lck_mtx_data(, if_inet6_ioctl_lock);
1001 
1002 #if INET
1003 	decl_lck_rw_data(, if_inetdata_lock);
1004 	struct in_ifextra       *if_inetdata;
1005 #endif /* INET */
1006 	decl_lck_rw_data(, if_inet6data_lock);
1007 	struct in6_ifextra      *if_inet6data;
1008 	decl_lck_rw_data(, if_link_status_lock);
1009 	struct if_link_status   *if_link_status;
1010 
1011 	struct if_interface_state       if_interface_state;
1012 	uint64_t                        if_link_heuristics_start_time; /* milliseconds */
1013 	uint64_t                        if_congested_link_start_time; /* milliseconds */
1014 	uint64_t                        if_lqmstate_start_time;      /* milliseconds */
1015 	thread_call_t                   if_link_heuristics_tcall;
1016 
1017 	struct if_tcp_ecn_stat *if_ipv4_stat;
1018 	struct if_tcp_ecn_stat *if_ipv6_stat;
1019 
1020 
1021 #if SKYWALK
1022 	/* Keeps track of local ports bound to this interface
1023 	 * Protected by the global lock in skywalk/netns/netns.c */
1024 	LIST_HEAD(, ns_token) if_netns_tokens;
1025 #endif /* SKYWALK */
1026 	struct if_lim_perf_stat if_lim_stat;
1027 
1028 	uint32_t        if_tcp_kao_max;
1029 	uint32_t        if_tcp_kao_cnt;
1030 
1031 #if SKYWALK
1032 	struct netem    *if_input_netem;
1033 #endif /* SKYWALK */
1034 	struct netem    *if_output_netem;
1035 
1036 	ipv6_router_mode_t if_ipv6_router_mode; /* see <netinet6/in6_var.h> */
1037 
1038 	u_int8_t        if_estimated_up_bucket;
1039 	u_int8_t        if_estimated_down_bucket;
1040 	u_int8_t        if_radio_type;
1041 	u_int8_t        if_radio_channel;
1042 
1043 	uint8_t         network_id[IFNET_NETWORK_ID_LEN];
1044 	uint8_t         network_id_len;
1045 
1046 	uint8_t         if_l4s_mode; /* L4S capability on an interface */
1047 
1048 	atomic_bool     if_mcast_add_signaled;
1049 	atomic_bool     if_mcast_del_signaled;
1050 
1051 	uint32_t        if_inet_traffic_rule_count;
1052 	uint32_t        if_eth_traffic_rule_count;
1053 	uint32_t        if_traffic_rule_genid;
1054 
1055 	/*
1056 	 * if_creation_generation_id is assigned the value of a global counter that
1057 	 * is incremented when the interface is allocated and when it is freed.
1058 	 *
1059 	 * This allows to discriminate between different instances of an interface
1060 	 * that has the same name or same index
1061 	 */
1062 	uint64_t        if_creation_generation_id;
1063 };
1064 
1065 /* Interface event handling declarations */
1066 extern struct eventhandler_lists_ctxt ifnet_evhdlr_ctxt;
1067 
1068 typedef enum {
1069 	INTF_EVENT_CODE_CREATED,
1070 	INTF_EVENT_CODE_REMOVED,
1071 	INTF_EVENT_CODE_STATUS_UPDATE,
1072 	INTF_EVENT_CODE_IPADDR_ATTACHED,
1073 	INTF_EVENT_CODE_IPADDR_DETACHED,
1074 	INTF_EVENT_CODE_LLADDR_UPDATE,
1075 	INTF_EVENT_CODE_MTU_CHANGED,
1076 	INTF_EVENT_CODE_LOW_POWER_UPDATE,
1077 } intf_event_code_t;
1078 
1079 typedef void (*ifnet_event_fn)(struct eventhandler_entry_arg, struct ifnet *, struct sockaddr *, intf_event_code_t);
1080 EVENTHANDLER_DECLARE(ifnet_event, ifnet_event_fn);
1081 
1082 #define IF_TCP_STATINC(_ifp, _s) do {                               \
1083     if ((_ifp)->if_tcp_stat != NULL)                                \
1084 	    os_atomic_inc(&(_ifp)->if_tcp_stat->_s, relaxed);       \
1085 } while (0);
1086 
1087 #define IF_UDP_STATINC(_ifp, _s) do {                               \
1088     if ((_ifp)->if_udp_stat != NULL)                                \
1089 	    os_atomic_inc(&(_ifp)->if_udp_stat->_s, relaxed);       \
1090 } while (0);
1091 
1092 /*
1093  * Valid values for if_refflags
1094  */
1095 #define IFRF_EMBRYONIC  0x1     /* ifnet is allocated; awaiting attach */
1096 #define IFRF_ATTACHED   0x2     /* ifnet attach is completely done */
1097 #define IFRF_DETACHING  0x4     /* detach has been requested */
1098 #define IFRF_READY      0x8     /* data path is ready */
1099 
1100 #define IFRF_ATTACH_MASK (IFRF_EMBRYONIC|IFRF_ATTACHED|IFRF_DETACHING)
1101 
1102 static inline bool
ifnet_is_fully_attached(const struct ifnet * ifp)1103 ifnet_is_fully_attached(const struct ifnet *ifp)
1104 {
1105 	return (ifp->if_refflags & IFRF_ATTACH_MASK) == IFRF_ATTACHED;
1106 }
1107 
1108 static inline bool
ifnet_is_attached_and_ready(const struct ifnet * ifp)1109 ifnet_is_attached_and_ready(const struct ifnet *ifp)
1110 {
1111 	return ifp->if_refflags == (IFRF_ATTACHED | IFRF_READY);
1112 }
1113 
1114 /*
1115  * Valid values for if_start_flags
1116  */
1117 #define IFSF_FLOW_CONTROLLED     0x1     /* flow controlled */
1118 #define IFSF_TERMINATING         0x2     /* terminating */
1119 #define IFSF_NO_DELAY            0x4     /* no delay */
1120 #define IFSF_FLOW_RESUME_PENDING 0x8     /* ignore next flow control event */
1121 
1122 /*
1123  * Structure describing a `cloning' interface.
1124  */
1125 struct if_clone {
1126 	LIST_ENTRY(if_clone) ifc_list;  /* on list of cloners */
1127 	decl_lck_mtx_data(, ifc_mutex); /* To serialize clone create/delete */
1128 	u_int32_t       ifc_minifs;     /* minimum number of interfaces */
1129 	u_int32_t       ifc_maxunit;    /* maximum unit number */
1130 	u_int32_t       ifc_bmlen;      /* bitmap length */
1131 	unsigned char   *__counted_by(ifc_bmlen) ifc_units;     /* bitmap to handle units */
1132 	int             (*ifc_create)(struct if_clone *, u_int32_t, void *);
1133 	int             (*ifc_destroy)(struct ifnet *);
1134 	uint8_t         ifc_namelen;    /* length of name */
1135 	char            ifc_name[IFNAMSIZ + 1]; /* name of device, e.g. `vlan' */
1136 };
1137 
1138 #define IF_CLONE_INITIALIZER(name, create, destroy, minifs, maxunit) {          \
1139     .ifc_name = "" name,                                                        \
1140     .ifc_namelen = (sizeof(name) - 1),                                          \
1141     .ifc_minifs = (minifs),                                                     \
1142     .ifc_maxunit = (maxunit),                                                   \
1143     .ifc_create = (create),                                                     \
1144     .ifc_destroy = (destroy)                                                    \
1145 }
1146 
1147 /*
1148  * Macros to manipulate ifqueue.  Users of these macros are responsible
1149  * for serialization, by holding whatever lock is appropriate for the
1150  * corresponding structure that is referring the ifqueue.
1151  */
1152 #define IF_QFULL(ifq)           ((ifq)->ifq_len >= (ifq)->ifq_maxlen)
1153 #define IF_DROP(ifq)            ((ifq)->ifq_drops++)
1154 
1155 #define IF_ENQUEUE(ifq, m) do {                                     \
1156     (m)->m_nextpkt = NULL;                                          \
1157     if ((ifq)->ifq_tail == NULL)                                    \
1158 	    (ifq)->ifq_head = m;                                    \
1159     else                                                            \
1160 	    ((struct mbuf*)(ifq)->ifq_tail)->m_nextpkt = m;         \
1161     (ifq)->ifq_tail = m;                                            \
1162     (ifq)->ifq_len++;                                               \
1163 } while (0)
1164 
1165 #define IF_PREPEND(ifq, m) do {                                     \
1166     (m)->m_nextpkt = (mbuf_ref_t)(ifq)->ifq_head;                   \
1167     if ((ifq)->ifq_tail == NULL)                                    \
1168 	    (ifq)->ifq_tail = (m);                                  \
1169     (ifq)->ifq_head = (m);                                          \
1170     (ifq)->ifq_len++;                                               \
1171 } while (0)
1172 
1173 #define IF_DEQUEUE(ifq, m) do {                                     \
1174     (m) = (mbuf_ref_t)(ifq)->ifq_head;                              \
1175     if (m != NULL) {                                                \
1176 	    if (((ifq)->ifq_head = (m)->m_nextpkt) == NULL)         \
1177 	            (ifq)->ifq_tail = NULL;                         \
1178 	    (m)->m_nextpkt = NULL;                                  \
1179 	    (ifq)->ifq_len--;                                       \
1180     }                                                               \
1181 } while (0)
1182 
1183 #define IF_REMQUEUE(ifq, m) do {                                    \
1184     mbuf_ref_t _p = (mbuf_ref_t)(ifq)->ifq_head;                    \
1185     mbuf_ref_t _n = (m)->m_nextpkt;                                 \
1186     if ((m) == _p)                                                  \
1187 	    _p = NULL;                                              \
1188     while (_p != NULL) {                                            \
1189 	    if (_p->m_nextpkt == (m))                               \
1190 	            break;                                          \
1191 	    _p = _p->m_nextpkt;                                     \
1192     }                                                               \
1193     VERIFY(_p != NULL || ((m) == (ifq)->ifq_head));                 \
1194     if ((m) == (ifq)->ifq_head)                                     \
1195 	    (ifq)->ifq_head = _n;                                   \
1196     if ((m) == (ifq)->ifq_tail)                                     \
1197 	    (ifq)->ifq_tail = _p;                                   \
1198     VERIFY((ifq)->ifq_tail != NULL || (ifq)->ifq_head == NULL);     \
1199     VERIFY((ifq)->ifq_len != 0);                                    \
1200     --(ifq)->ifq_len;                                               \
1201     if (_p != NULL)                                                 \
1202 	    _p->m_nextpkt = _n;                                     \
1203     (m)->m_nextpkt = NULL;                                          \
1204 } while (0)
1205 
1206 #define IF_DRAIN(ifq) do {                                          \
1207     struct mbuf *_m;                                                \
1208     for (;;) {                                                      \
1209 	    IF_DEQUEUE(ifq, _m);                                    \
1210 	    if (_m == NULL)                                         \
1211 	            break;                                          \
1212 	    m_freem(_m);                                            \
1213     }                                                               \
1214 } while (0)
1215 
1216 /*
1217  * The ifaddr structure contains information about one address
1218  * of an interface.  They are maintained by the different address families,
1219  * are allocated and attached when an address is set, and are linked
1220  * together so all addresses for an interface can be located.
1221  */
1222 struct ifaddr {
1223 	decl_lck_mtx_data(, ifa_lock);  /* lock for ifaddr */
1224 	os_refcnt_t     ifa_refcnt;     /* ref count, use IFA_{ADD,REM}REF */
1225 	uint32_t        ifa_debug;      /* debug flags */
1226 	struct sockaddr *ifa_addr;      /* address of interface */
1227 	struct sockaddr *ifa_dstaddr;   /* other end of p-to-p link */
1228 #define ifa_broadaddr   ifa_dstaddr     /* broadcast address interface */
1229 	struct sockaddr *ifa_netmask;   /* used to determine subnet */
1230 	struct ifnet    *ifa_ifp;       /* back-pointer to interface */
1231 	TAILQ_ENTRY(ifaddr) ifa_link;   /* queue macro glue */
1232 	void (*ifa_rtrequest)           /* check or clean routes (+ or -)'d */
1233 	(int, struct rtentry *, struct sockaddr *);
1234 	uint32_t        ifa_flags;      /* mostly rt_flags for cloning */
1235 	int32_t         ifa_metric;     /* cost of going out this interface */
1236 	void (*ifa_free)(struct ifaddr *); /* callback fn for freeing */
1237 	void *ifa_del_wc;               /* Wait channel to avoid address deletion races */
1238 	int ifa_del_waiters;            /* Threads in wait to delete the address */
1239 };
1240 
1241 /*
1242  * Valid values for ifa_flags
1243  */
1244 #define IFA_ROUTE       RTF_UP          /* route installed (0x1) */
1245 #define IFA_CLONING     RTF_CLONING     /* (0x100) */
1246 
1247 /*
1248  * Valid values for ifa_debug
1249  */
1250 #define IFD_ATTACHED    0x1             /* attached to list */
1251 #define IFD_ALLOC       0x2             /* dynamically allocated */
1252 #define IFD_DEBUG       0x4             /* has debugging info */
1253 #define IFD_LINK        0x8             /* link address */
1254 #define IFD_TRASHED     0x10            /* in trash list */
1255 #define IFD_DETACHING   0x20            /* detach is in progress */
1256 #define IFD_NOTREADY    0x40            /* embryonic; not yet ready */
1257 
1258 #define IFA_LOCK_ASSERT_HELD(_ifa)                                      \
1259     LCK_MTX_ASSERT(&(_ifa)->ifa_lock, LCK_MTX_ASSERT_OWNED)
1260 
1261 #define IFA_LOCK_ASSERT_NOTHELD(_ifa)                                   \
1262     LCK_MTX_ASSERT(&(_ifa)->ifa_lock, LCK_MTX_ASSERT_NOTOWNED)
1263 
1264 #define IFA_LOCK(_ifa)                                                  \
1265     lck_mtx_lock(&(_ifa)->ifa_lock)
1266 
1267 #define IFA_LOCK_SPIN(_ifa)                                             \
1268     lck_mtx_lock_spin(&(_ifa)->ifa_lock)
1269 
1270 #define IFA_CONVERT_LOCK(_ifa) do {                                     \
1271     IFA_LOCK_ASSERT_HELD(_ifa);                                         \
1272     lck_mtx_convert_spin(&(_ifa)->ifa_lock);                            \
1273 } while (0)
1274 
1275 #define IFA_UNLOCK(_ifa)                                                \
1276     lck_mtx_unlock(&(_ifa)->ifa_lock)
1277 
1278 static inline void
ifa_addref(struct ifaddr * ifa)1279 ifa_addref(struct ifaddr *ifa)
1280 {
1281 	os_ref_retain(&ifa->ifa_refcnt);
1282 }
1283 
1284 __private_extern__ void ifa_deallocated(struct ifaddr *ifa);
1285 
1286 static inline void
ifa_remref(struct ifaddr * ifa)1287 ifa_remref(struct ifaddr *ifa)
1288 {
1289 	/* We can use _relaxed, because if we hit 0 we make sure the lock is held */
1290 	if (os_ref_release_relaxed(&ifa->ifa_refcnt) == 0) {
1291 		ifa_deallocated(ifa);
1292 	}
1293 }
1294 
1295 /*
1296  * Multicast address structure.  This is analogous to the ifaddr
1297  * structure except that it keeps track of multicast addresses.
1298  * Also, the request count here is a count of requests for this
1299  * address, not a count of pointers to this structure; anonymous
1300  * membership(s) holds one outstanding request count.
1301  */
1302 struct ifmultiaddr {
1303 	decl_lck_mtx_data(, ifma_lock);
1304 	u_int32_t ifma_refcount;        /* reference count */
1305 	u_int32_t ifma_anoncnt;         /* # of anonymous requests */
1306 	u_int32_t ifma_reqcnt;          /* total requests for this address */
1307 	u_int32_t ifma_debug;           /* see ifa_debug flags */
1308 	u_int32_t ifma_flags;           /* see below */
1309 	LIST_ENTRY(ifmultiaddr) ifma_link; /* queue macro glue */
1310 	struct sockaddr *ifma_addr;     /* address this membership is for */
1311 	struct ifmultiaddr *ifma_ll;    /* link-layer translation, if any */
1312 	struct ifnet *ifma_ifp;         /* back-pointer to interface */
1313 	void *ifma_protospec;           /* protocol-specific state, if any */
1314 	void (*ifma_trace)              /* callback fn for tracing refs */
1315 	(struct ifmultiaddr *, int);
1316 };
1317 
1318 /*
1319  * Values for ifma_flags
1320  */
1321 #define IFMAF_ANONYMOUS         0x1     /* has anonymous request ref(s) held */
1322 
1323 #define IFMA_LOCK_ASSERT_HELD(_ifma)                                    \
1324     LCK_MTX_ASSERT(&(_ifma)->ifma_lock, LCK_MTX_ASSERT_OWNED)
1325 
1326 #define IFMA_LOCK_ASSERT_NOTHELD(_ifma)                                 \
1327     LCK_MTX_ASSERT(&(_ifma)->ifma_lock, LCK_MTX_ASSERT_NOTOWNED)
1328 
1329 #define IFMA_LOCK(_ifma)                                                \
1330     lck_mtx_lock(&(_ifma)->ifma_lock)
1331 
1332 #define IFMA_LOCK_SPIN(_ifma)                                           \
1333     lck_mtx_lock_spin(&(_ifma)->ifma_lock)
1334 
1335 #define IFMA_CONVERT_LOCK(_ifma) do {                                   \
1336     IFMA_LOCK_ASSERT_HELD(_ifma);                                       \
1337     lck_mtx_convert_spin(&(_ifma)->ifma_lock);                          \
1338 } while (0)
1339 
1340 #define IFMA_UNLOCK(_ifma)                                              \
1341     lck_mtx_unlock(&(_ifma)->ifma_lock)
1342 
1343 #define IFMA_ADDREF(_ifma)                                              \
1344     ifma_addref(_ifma, 0)
1345 
1346 #define IFMA_ADDREF_LOCKED(_ifma)                                       \
1347     ifma_addref(_ifma, 1)
1348 
1349 #define IFMA_REMREF(_ifma)                                              \
1350     ifma_remref(_ifma)
1351 
1352 /*
1353  * Indicate whether or not the immediate interface, or the interface delegated
1354  * by it, is a cellular interface (IFT_CELLULAR).  Delegated interface type is
1355  * set/cleared along with the delegated ifp; we cache the type for performance
1356  * to avoid dereferencing delegated ifp each time.
1357  *
1358  * Note that this is meant to be used only for accounting and policy purposes;
1359  * certain places need to explicitly know the immediate interface type, and
1360  * this macro should not be used there.
1361  *
1362  * The test is done against IFT_CELLULAR instead of IFNET_FAMILY_CELLULAR to
1363  * handle certain cases where the family isn't set to the latter.
1364  *
1365  * This macro also handles the case of IFNET_FAMILY_ETHERNET with
1366  * IFNET_SUBFAMILY_SIMCELL which is used to simulate a cellular interface
1367  * for testing purposes. The underlying interface is Ethernet but we treat
1368  * it as cellular for accounting and policy purposes.
1369  */
1370 #define IFNET_IS_CELLULAR(_ifp)                                     \
1371     ((_ifp)->if_type == IFT_CELLULAR ||                             \
1372     (_ifp)->if_delegated.type == IFT_CELLULAR ||                    \
1373     (((_ifp)->if_family == IFNET_FAMILY_ETHERNET  &&                \
1374     (_ifp)->if_subfamily == IFNET_SUBFAMILY_SIMCELL)) ||            \
1375     ((_ifp)->if_delegated.family == IFNET_FAMILY_ETHERNET &&        \
1376     (_ifp)->if_delegated.subfamily == IFNET_SUBFAMILY_SIMCELL))
1377 
1378 /*
1379  * Indicate whether or not the immediate interface, or the interface delegated
1380  * by it, is an ETHERNET interface.
1381  */
1382 #define IFNET_IS_ETHERNET(_ifp)                                     \
1383     ((_ifp)->if_family == IFNET_FAMILY_ETHERNET ||                  \
1384     (_ifp)->if_delegated.family == IFNET_FAMILY_ETHERNET)
1385 /*
1386  * Indicate whether or not the immediate interface, or the interface delegated
1387  * by it, is a Wi-Fi interface (IFNET_SUBFAMILY_WIFI).  Delegated interface
1388  * subfamily is set/cleared along with the delegated ifp; we cache the subfamily
1389  * for performance to avoid dereferencing delegated ifp each time.
1390  *
1391  * Note that this is meant to be used only for accounting and policy purposes;
1392  * certain places need to explicitly know the immediate interface type, and
1393  * this macro should not be used there.
1394  *
1395  * The test is done against IFNET_SUBFAMILY_WIFI as the family may be set to
1396  * IFNET_FAMILY_ETHERNET (as well as type to IFT_ETHER) which is too generic.
1397  */
1398 #define IFNET_IS_WIFI(_ifp)                                         \
1399     (((_ifp)->if_family == IFNET_FAMILY_ETHERNET  &&                \
1400     (_ifp)->if_subfamily == IFNET_SUBFAMILY_WIFI) ||                \
1401     ((_ifp)->if_delegated.family == IFNET_FAMILY_ETHERNET &&        \
1402     (_ifp)->if_delegated.subfamily == IFNET_SUBFAMILY_WIFI))
1403 
1404 /*
1405  * Indicate whether or not the immediate interface, or the interface delegated
1406  * by it, is a Wired interface (several families).  Delegated interface
1407  * family is set/cleared along with the delegated ifp; we cache the family
1408  * for performance to avoid dereferencing delegated ifp each time.
1409  *
1410  * Note that this is meant to be used only for accounting and policy purposes;
1411  * certain places need to explicitly know the immediate interface type, and
1412  * this macro should not be used there.
1413  */
1414 #define IFNET_IS_WIRED(_ifp)                                        \
1415     ((_ifp)->if_family == IFNET_FAMILY_ETHERNET ||                  \
1416     (_ifp)->if_delegated.family == IFNET_FAMILY_ETHERNET ||         \
1417     (_ifp)->if_family == IFNET_FAMILY_FIREWIRE ||                   \
1418     (_ifp)->if_delegated.family == IFNET_FAMILY_FIREWIRE)
1419 
1420 /*
1421  * Indicate whether or not the immediate WiFi interface is on an infrastructure
1422  * network
1423  */
1424 #define IFNET_IS_WIFI_INFRA(_ifp)                           \
1425     ((_ifp)->if_family == IFNET_FAMILY_ETHERNET &&          \
1426     (_ifp)->if_subfamily == IFNET_SUBFAMILY_WIFI &&         \
1427     !((_ifp)->if_eflags & IFEF_AWDL) &&                     \
1428     !((_ifp)->if_xflags & IFXF_LOW_LATENCY))
1429 
1430 /*
1431  * Indicate whether or not the immediate WiFi interface is on an AWDL link
1432  */
1433 #define IFNET_IS_WIFI_AWDL(_ifp)                           \
1434     ((_ifp)->if_family == IFNET_FAMILY_ETHERNET &&          \
1435     (_ifp)->if_subfamily == IFNET_SUBFAMILY_WIFI &&         \
1436     ((_ifp)->if_eflags & IFEF_AWDL))
1437 
1438 
1439 /*
1440  * Indicate whether or not the immediate interface is a companion link
1441  * interface.
1442  */
1443 #define IFNET_IS_COMPANION_LINK(_ifp)                       \
1444     ((_ifp)->if_xflags & IFXF_IS_COMPANIONLINK)
1445 
1446 /*
1447  * Indicate whether or not the immediate interface is a companion link
1448  * interface using Bluetooth
1449  */
1450 #define IFNET_IS_COMPANION_LINK_BLUETOOTH(_ifp)             \
1451     (IFNET_IS_COMPANION_LINK(_ifp) &&                       \
1452     (_ifp)->if_subfamily == IFNET_SUBFAMILY_BLUETOOTH)
1453 
1454 /*
1455  * Indicate whether or not the immediate interface, or the interface delegated
1456  * by it, is marked as expensive.  The delegated interface is set/cleared
1457  * along with the delegated ifp; we cache the flag for performance to avoid
1458  * dereferencing delegated ifp each time.
1459  *
1460  * Note that this is meant to be used only for policy purposes.
1461  */
1462 #define IFNET_IS_EXPENSIVE(_ifp)                                        \
1463     ((_ifp)->if_eflags & IFEF_EXPENSIVE ||                              \
1464     (_ifp)->if_delegated.expensive)
1465 
1466 #define IFNET_IS_LOW_POWER(_ifp)                                    \
1467     (if_low_power_restricted != 0 &&                                \
1468     ((_ifp)->if_xflags & IFXF_LOW_POWER) ||                         \
1469     ((_ifp)->if_delegated.ifp != NULL &&                            \
1470     ((_ifp)->if_delegated.ifp->if_xflags & IFXF_LOW_POWER)))
1471 
1472 #define IFNET_IS_CONSTRAINED(_ifp)                                      \
1473     ((_ifp)->if_xflags & IFXF_CONSTRAINED ||                            \
1474     (_ifp)->if_delegated.constrained ||                                 \
1475     (_ifp)->if_xflags & IFXF_ULTRA_CONSTRAINED ||                       \
1476     (_ifp)->if_delegated.ultra_constrained)
1477 
1478 #define IFNET_IS_ULTRA_CONSTRAINED(_ifp)                                \
1479     ((_ifp)->if_xflags & IFXF_ULTRA_CONSTRAINED ||                      \
1480     (_ifp)->if_delegated.ultra_constrained)
1481 
1482 #define IFNET_IS_VPN(_ifp)                                          \
1483 	((_ifp)->if_xflags & IFXF_IS_VPN)
1484 
1485 #define IFNET_IS_LOOPBACK(_ifp)                                     \
1486 	((_ifp)->if_flags & IFF_LOOPBACK)
1487 
1488 /*
1489  * We don't support AWDL interface delegation.
1490  */
1491 #define IFNET_IS_AWDL_RESTRICTED(_ifp)                              \
1492     (((_ifp)->if_eflags & (IFEF_AWDL|IFEF_AWDL_RESTRICTED)) ==      \
1493     (IFEF_AWDL|IFEF_AWDL_RESTRICTED))
1494 
1495 #define IFNET_IS_INTCOPROC(_ifp)                                    \
1496     ((_ifp)->if_family == IFNET_FAMILY_ETHERNET &&                  \
1497      (_ifp)->if_subfamily == IFNET_SUBFAMILY_INTCOPROC)
1498 
1499 #define IFNET_IS_VMNET(_ifp)                                        \
1500     ((_ifp)->if_family == IFNET_FAMILY_ETHERNET &&                  \
1501      (_ifp)->if_subfamily == IFNET_SUBFAMILY_VMNET)
1502 
1503 #define IFNET_IS_MANAGEMENT(_ifp)                                        \
1504      (((_ifp)->if_xflags & IFXF_MANAGEMENT) != 0)
1505 
1506 /*
1507  * Indicate whether or not the immediate interface is IP over Thunderbolt.
1508  */
1509 #define IFNET_IS_THUNDERBOLT_IP(_ifp)                            \
1510     ((_ifp)->if_family == IFNET_FAMILY_ETHERNET &&               \
1511      (_ifp)->if_subfamily == IFNET_SUBFAMILY_THUNDERBOLT)
1512 
1513 #define IFNET_IS_REDIRECT(_ifp)                       \
1514     (((_ifp)->if_family == IFNET_FAMILY_ETHERNET ||   \
1515     (_ifp)->if_family == IFNET_FAMILY_CELLULAR) &&    \
1516     (_ifp)->if_subfamily == IFNET_SUBFAMILY_REDIRECT)
1517 
1518 /*
1519  * Indicate whether or not the interface requires joining cellular thread group
1520  */
1521 #define IFNET_REQUIRES_CELL_GROUP(_ifp)                     \
1522     ((_ifp)->if_family == IFNET_FAMILY_CELLULAR &&          \
1523     ((_ifp)->if_xflags & IFXF_REQUIRE_CELL_THREAD_GROUP))
1524 
1525 extern int if_index;
1526 extern int if_indexcount;
1527 extern uint32_t ifindex2ifnetcount;
1528 extern struct ifnethead ifnet_head;
1529 extern struct ifnethead ifnet_ordered_head;
1530 extern struct ifnet **__counted_by_or_null(ifindex2ifnetcount) ifindex2ifnet;
1531 extern u_int32_t if_sndq_maxlen;
1532 extern u_int32_t if_rcvq_maxlen;
1533 extern struct ifaddr **__counted_by_or_null(if_indexcount) ifnet_addrs;
1534 extern lck_attr_t ifa_mtx_attr;
1535 extern lck_grp_t ifa_mtx_grp;
1536 extern lck_grp_t ifnet_lock_group;
1537 extern lck_attr_t ifnet_lock_attr;
1538 extern ifnet_t lo_ifp;
1539 extern uint32_t net_wake_pkt_debug;
1540 
1541 extern int if_addmulti(struct ifnet *, const struct sockaddr *,
1542     struct ifmultiaddr **);
1543 extern int if_addmulti_anon(struct ifnet *, const struct sockaddr *,
1544     struct ifmultiaddr **);
1545 extern int if_allmulti(struct ifnet *, int);
1546 extern int if_delmulti(struct ifnet *, const struct sockaddr *);
1547 extern int if_delmulti_ifma(struct ifmultiaddr *);
1548 extern int if_delmulti_anon(struct ifnet *, const struct sockaddr *);
1549 extern void if_down(struct ifnet *);
1550 extern int if_down_all(void);
1551 extern void if_up(struct ifnet *);
1552 __private_extern__ void if_updown(struct ifnet *ifp, int up);
1553 extern int ifioctl(struct socket *, u_long cmd, caddr_t __sized_by(IOCPARM_LEN(cmd)), struct proc *);
1554 extern int ifioctllocked(struct socket *, u_long cmd, caddr_t __sized_by(IOCPARM_LEN(cmd)), struct proc *);
1555 extern struct ifnet *ifunit(const char *);
1556 extern struct ifnet *ifunit_ref(const char *);
1557 extern int ifunit_extract(const char *src, char *__counted_by(dstlen)dst, size_t dstlen, int *unit);
1558 extern struct ifnet *if_withname(struct sockaddr *);
1559 extern void if_qflush(struct ifnet *, struct ifclassq *);
1560 extern void if_qflush_sc(struct ifnet *, mbuf_svc_class_t, u_int32_t,
1561     u_int32_t *, u_int32_t *);
1562 
1563 extern struct if_clone *if_clone_lookup(const char *__counted_by(namelen) name, size_t namelen, u_int32_t *);
1564 extern int if_clone_attach(struct if_clone *);
1565 extern void if_clone_detach(struct if_clone *);
1566 extern u_int32_t if_functional_type(struct ifnet *, bool);
1567 extern u_int32_t if_peer_egress_functional_type(struct ifnet *, bool);
1568 
1569 extern errno_t if_mcasts_update(struct ifnet *);
1570 
1571 extern const char *intf_event2str(int);
1572 
1573 extern uint32_t if_get_driver_hwassist(struct ifnet *ifp);
1574 
1575 typedef enum {
1576 	IFNET_LCK_ASSERT_EXCLUSIVE,     /* RW: held as writer */
1577 	IFNET_LCK_ASSERT_SHARED,        /* RW: held as reader */
1578 	IFNET_LCK_ASSERT_OWNED,         /* RW: writer/reader, MTX: held */
1579 	IFNET_LCK_ASSERT_NOTOWNED       /* not held */
1580 } ifnet_lock_assert_t;
1581 
1582 static inline char *__header_indexable
if_inline_lladdr(struct ifnet * ifp)1583 if_inline_lladdr(struct ifnet *ifp)
1584 {
1585 	// N.B.: unable to use SDL() from sockaddr_utils.h yet.
1586 	struct sockaddr *s = ifp->if_lladdr->ifa_addr;
1587 #pragma clang diagnostic push
1588 #pragma clang diagnostic ignored "-Wcast-align"
1589 	struct sockaddr_dl *dl = __unsafe_forge_bidi_indexable(struct sockaddr_dl *,
1590 	    s, s->sa_len);
1591 #pragma clang diagnostic pop
1592 
1593 	return LLADDR(dl);
1594 }
1595 #define IF_LLADDR(_ifp) if_inline_lladdr(_ifp)
1596 
1597 #define IF_INDEX_IN_RANGE(_ind_) ((_ind_) > 0 && \
1598     (unsigned int)(_ind_) <= (unsigned int)if_index)
1599 
1600 __private_extern__ void ifnet_lock_assert(struct ifnet *, ifnet_lock_assert_t);
1601 __private_extern__ void ifnet_lock_shared(struct ifnet *ifp);
1602 __private_extern__ void ifnet_lock_exclusive(struct ifnet *ifp);
1603 __private_extern__ void ifnet_lock_done(struct ifnet *ifp);
1604 
1605 #if INET
1606 __private_extern__ void if_inetdata_lock_shared(struct ifnet *ifp);
1607 __private_extern__ void if_inetdata_lock_exclusive(struct ifnet *ifp);
1608 __private_extern__ void if_inetdata_lock_done(struct ifnet *ifp);
1609 #endif
1610 
1611 __private_extern__ void if_inet6data_lock_shared(struct ifnet *ifp);
1612 __private_extern__ void if_inet6data_lock_exclusive(struct ifnet *ifp);
1613 __private_extern__ void if_inet6data_lock_done(struct ifnet *ifp);
1614 
1615 __private_extern__ void ifnet_head_lock_shared(void);
1616 __private_extern__ void ifnet_head_lock_exclusive(void);
1617 __private_extern__ void ifnet_head_done(void);
1618 __private_extern__ void ifnet_head_assert_exclusive(void);
1619 
1620 __private_extern__ errno_t ifnet_set_idle_flags_locked(ifnet_t, u_int32_t,
1621     u_int32_t);
1622 __private_extern__ int ifnet_get_ioref(struct ifnet *ifp);
1623 __private_extern__ void ifnet_incr_pending_thread_count(struct ifnet *);
1624 __private_extern__ void ifnet_decr_pending_thread_count(struct ifnet *);
1625 __private_extern__ void ifnet_incr_iorefcnt(struct ifnet *);
1626 __private_extern__ void ifnet_decr_iorefcnt(struct ifnet *);
1627 __private_extern__ boolean_t ifnet_datamov_begin(struct ifnet *);
1628 __private_extern__ void ifnet_datamov_end(struct ifnet *);
1629 __private_extern__ boolean_t ifnet_datamov_suspend_if_needed(struct ifnet *);
1630 __private_extern__ void ifnet_datamov_drain(struct ifnet *);
1631 __private_extern__ void ifnet_datamov_suspend_and_drain(struct ifnet *);
1632 __private_extern__ void ifnet_datamov_resume(struct ifnet *);
1633 __private_extern__ void ifnet_set_start_cycle(struct ifnet *,
1634     struct timespec *);
1635 __private_extern__ void ifnet_set_poll_cycle(struct ifnet *,
1636     struct timespec *);
1637 
1638 __private_extern__ void if_attach_ifa(struct ifnet *, struct ifaddr *);
1639 __private_extern__ void if_attach_link_ifa(struct ifnet *, struct ifaddr *);
1640 __private_extern__ void if_detach_ifa(struct ifnet *, struct ifaddr *);
1641 __private_extern__ void if_detach_link_ifa(struct ifnet *, struct ifaddr *);
1642 
1643 __private_extern__ void dlil_if_lock(void);
1644 __private_extern__ void dlil_if_unlock(void);
1645 __private_extern__ void dlil_if_lock_assert(void);
1646 
1647 extern struct ifaddr *ifa_ifwithaddr(const struct sockaddr *);
1648 extern struct ifaddr *ifa_ifwithaddr_locked(const struct sockaddr *);
1649 extern struct ifaddr *ifa_ifwithaddr_scoped(const struct sockaddr *,
1650     unsigned int);
1651 extern struct ifaddr *ifa_ifwithaddr_scoped_locked(const struct sockaddr *,
1652     unsigned int);
1653 extern struct ifaddr *ifa_ifwithdstaddr(const struct sockaddr *);
1654 extern struct ifaddr *ifa_ifwithdstaddr_scoped(const struct sockaddr *,
1655     unsigned int);
1656 extern struct ifaddr *ifa_ifwithnet(const struct sockaddr *);
1657 extern struct ifaddr *ifa_ifwithnet_scoped(const struct sockaddr *,
1658     unsigned int);
1659 extern struct ifaddr *ifa_ifwithroute(int, const struct sockaddr *,
1660     const struct sockaddr *);
1661 extern struct   ifaddr *ifa_ifwithroute_locked(int, const struct sockaddr *,
1662     const struct sockaddr *);
1663 extern struct ifaddr *ifa_ifwithroute_scoped_locked(int,
1664     const struct sockaddr *, const struct sockaddr *, unsigned int);
1665 extern struct ifaddr *ifaof_ifpforaddr_select(const struct sockaddr *, struct ifnet *);
1666 extern struct ifaddr *ifaof_ifpforaddr(const struct sockaddr *, struct ifnet *);
1667 __private_extern__ struct ifaddr *ifa_ifpgetprimary(struct ifnet *, int);
1668 extern void ifa_initref(struct ifaddr *);
1669 extern void ifa_lock_init(struct ifaddr *);
1670 extern void ifa_lock_destroy(struct ifaddr *);
1671 extern void ifma_addref(struct ifmultiaddr *, int);
1672 extern void ifma_remref(struct ifmultiaddr *);
1673 
1674 extern void ifa_init(void);
1675 
1676 __private_extern__ struct in_ifaddr *ifa_foraddr(unsigned int);
1677 __private_extern__ struct in_ifaddr *ifa_foraddr_scoped(unsigned int,
1678     unsigned int);
1679 
1680 struct ifreq;
1681 extern errno_t ifnet_getset_opportunistic(struct ifnet *, u_long,
1682     struct ifreq *, struct proc *);
1683 extern int ifnet_get_throttle(struct ifnet *, u_int32_t *);
1684 extern int ifnet_set_throttle(struct ifnet *, u_int32_t);
1685 extern errno_t ifnet_getset_log(struct ifnet *, u_long,
1686     struct ifreq *, struct proc *);
1687 extern int ifnet_set_log(struct ifnet *, int32_t, uint32_t, int32_t, int32_t);
1688 extern int ifnet_get_log(struct ifnet *, int32_t *, uint32_t *, int32_t *,
1689     int32_t *);
1690 extern int ifnet_notify_address(struct ifnet *, int);
1691 extern void ifnet_notify_data_threshold(struct ifnet *);
1692 
1693 struct in6_addr;
1694 __private_extern__ struct in6_ifaddr *ifa_foraddr6(struct in6_addr *);
1695 __private_extern__ struct in6_ifaddr *ifa_foraddr6_scoped(struct in6_addr *,
1696     unsigned int);
1697 
1698 __private_extern__ void if_data_internal_to_if_data(struct ifnet *ifp,
1699     const struct if_data_internal *if_data_int, struct if_data *if_data);
1700 __private_extern__ void if_data_internal_to_if_data64(struct ifnet *ifp,
1701     const struct if_data_internal *if_data_int, struct if_data64 *if_data64);
1702 __private_extern__ void if_copy_traffic_class(struct ifnet *ifp,
1703     struct if_traffic_class *if_tc);
1704 __private_extern__ void if_copy_data_extended(struct ifnet *ifp,
1705     struct if_data_extended *if_de);
1706 __private_extern__ void if_copy_packet_stats(struct ifnet *ifp,
1707     struct if_packet_stats *if_ps);
1708 __private_extern__ void if_copy_rxpoll_stats(struct ifnet *ifp,
1709     struct if_rxpoll_stats *if_rs);
1710 __private_extern__ void if_copy_netif_stats(struct ifnet *ifp,
1711     struct if_netif_stats *if_ns);
1712 
1713 extern void if_copy_link_heuristics_stats(struct ifnet *ifp,
1714     struct if_linkheuristics *if_lh);
1715 
1716 __private_extern__ struct rtentry *ifnet_cached_rtlookup_inet(struct ifnet *,
1717     struct in_addr);
1718 __private_extern__ struct rtentry *ifnet_cached_rtlookup_inet6(struct ifnet *,
1719     struct in6_addr *);
1720 
1721 __private_extern__ u_int32_t if_get_protolist(struct ifnet * ifp,
1722     u_int32_t *__counted_by(count) protolist, u_int32_t count);
1723 __private_extern__ void if_free_protolist(u_int32_t *list);
1724 __private_extern__ errno_t if_state_update(struct ifnet *,
1725     struct if_interface_state *);
1726 __private_extern__ void if_get_state(struct ifnet *,
1727     struct if_interface_state *);
1728 __private_extern__ errno_t if_probe_connectivity(struct ifnet *ifp,
1729     u_int32_t conn_probe);
1730 __private_extern__ void if_lqm_update(struct ifnet *, int32_t, int);
1731 __private_extern__ void ifnet_update_rcv(struct ifnet *, cqev_t);
1732 
1733 __private_extern__ void ifnet_flowadv(uint32_t);
1734 
1735 __private_extern__ errno_t ifnet_set_input_bandwidths(struct ifnet *,
1736     struct if_bandwidths *);
1737 __private_extern__ errno_t ifnet_set_output_bandwidths(struct ifnet *,
1738     struct if_bandwidths *);
1739 __private_extern__ u_int64_t ifnet_output_linkrate(struct ifnet *);
1740 __private_extern__ u_int64_t ifnet_input_linkrate(struct ifnet *);
1741 
1742 __private_extern__ errno_t ifnet_set_input_latencies(struct ifnet *,
1743     struct if_latencies *);
1744 __private_extern__ errno_t ifnet_set_output_latencies(struct ifnet *,
1745     struct if_latencies *);
1746 
1747 __private_extern__ void ifnet_clear_netagent(uuid_t);
1748 
1749 __private_extern__ int ifnet_set_netsignature(struct ifnet *, uint8_t,
1750     uint8_t len, uint16_t, uint8_t *__sized_by(len));
1751 __private_extern__ int ifnet_get_netsignature(struct ifnet *, uint8_t,
1752     uint8_t *len, uint16_t *, uint8_t *__sized_by(*len));
1753 
1754 /* Required exclusive ifnet_head lock */
1755 __private_extern__ void ifnet_remove_from_ordered_list(struct ifnet *);
1756 
1757 __private_extern__ void ifnet_increment_generation(struct ifnet *);
1758 __private_extern__ u_int32_t ifnet_get_generation(struct ifnet *);
1759 
1760 /* Adding and deleting netagents will take ifnet lock */
1761 __private_extern__ int if_add_netagent(struct ifnet *, uuid_t);
1762 __private_extern__ int if_add_netagent_locked(struct ifnet *, uuid_t);
1763 __private_extern__ int if_delete_netagent(struct ifnet *, uuid_t);
1764 __private_extern__ boolean_t if_check_netagent(struct ifnet *, uuid_t);
1765 
1766 #if SKYWALK
1767 extern unsigned int if_enable_fsw_ip_netagent;
1768 static inline boolean_t
if_is_fsw_ip_netagent_enabled(void)1769 if_is_fsw_ip_netagent_enabled(void)
1770 {
1771 	return if_enable_fsw_ip_netagent != 0;
1772 }
1773 extern unsigned int if_enable_fsw_transport_netagent;
1774 static inline boolean_t
if_is_fsw_transport_netagent_enabled(void)1775 if_is_fsw_transport_netagent_enabled(void)
1776 {
1777 	return if_enable_fsw_transport_netagent != 0;
1778 }
1779 static inline boolean_t
if_is_fsw_netagent_enabled(void)1780 if_is_fsw_netagent_enabled(void)
1781 {
1782 	return if_is_fsw_transport_netagent_enabled() ||
1783 	       if_is_fsw_ip_netagent_enabled();
1784 }
1785 #endif /* SKYWALK */
1786 
1787 extern int if_set_qosmarking_mode(struct ifnet *, u_int32_t);
1788 __private_extern__ uint32_t ifnet_mbuf_packetpreamblelen(struct ifnet *);
1789 __private_extern__ void intf_event_enqueue_nwk_wq_entry(struct ifnet *ifp,
1790     struct sockaddr *addrp, uint32_t intf_event_code);
1791 __private_extern__ void ifnet_update_stats_per_flow(struct ifnet_stats_per_flow *,
1792     struct ifnet *);
1793 __private_extern__ int if_get_tcp_kao_max(struct ifnet *);
1794 #if XNU_TARGET_OS_OSX
1795 __private_extern__ errno_t ifnet_framer_stub(struct ifnet *, struct mbuf **,
1796     const struct sockaddr *,
1797     IFNET_LLADDR_T dest_lladdr,
1798     IFNET_FRAME_TYPE_T frame_type,
1799     u_int32_t *,
1800     u_int32_t *);
1801 #endif /* XNU_TARGET_OS_OSX */
1802 __private_extern__ void ifnet_enqueue_multi_setup(struct ifnet *, uint16_t,
1803     uint16_t);
1804 __private_extern__ errno_t ifnet_enqueue_mbuf(struct ifnet *, struct mbuf *,
1805     boolean_t, boolean_t *);
1806 __private_extern__ errno_t ifnet_enqueue_mbuf_chain(struct ifnet *,
1807     struct mbuf *, struct mbuf *, uint32_t, uint32_t, boolean_t, boolean_t *);
1808 __private_extern__ int ifnet_enqueue_netem(void *handle,
1809     pktsched_pkt_t *__sized_by(n_pkts) pkts, uint32_t n_pkts);
1810 #if SKYWALK
1811 struct __kern_packet;
1812 extern errno_t ifnet_enqueue_pkt(struct ifnet *, struct ifclassq *ifcq,
1813     struct __kern_packet *, boolean_t, boolean_t *);
1814 extern errno_t ifnet_enqueue_pkt_chain(struct ifnet *, struct ifclassq *,
1815     struct __kern_packet *, struct __kern_packet *, uint32_t, uint32_t,
1816     boolean_t, boolean_t *);
1817 extern errno_t ifnet_set_output_handler(struct ifnet *, ifnet_output_func);
1818 extern void ifnet_reset_output_handler(struct ifnet *);
1819 extern errno_t ifnet_set_start_handler(struct ifnet *, ifnet_start_func);
1820 extern void ifnet_reset_start_handler(struct ifnet *);
1821 
1822 #define SK_NXS_MS_IF_ADDR_GENCNT_INC(ifp)        \
1823     os_atomic_inc(&(ifp)->if_nx_flowswitch.if_fsw_ipaddr_gencnt, relaxed);
1824 #endif /* SKYWALK */
1825 
1826 extern int if_low_power_verbose;
1827 extern int if_low_power_restricted;
1828 extern void if_low_power_evhdlr_init(void);
1829 extern int if_set_low_power(struct ifnet *, bool);
1830 extern u_int32_t if_set_eflags(ifnet_t, u_int32_t);
1831 extern void if_clear_eflags(ifnet_t, u_int32_t);
1832 extern u_int32_t if_set_xflags(ifnet_t, u_int32_t);
1833 extern u_int32_t if_clear_xflags(ifnet_t, u_int32_t);
1834 extern boolean_t sa_equal(const struct sockaddr *, const struct sockaddr *);
1835 extern void ifnet_update_traffic_rule_genid(struct ifnet *);
1836 extern boolean_t ifnet_sync_traffic_rule_genid(struct ifnet *, uint32_t *);
1837 extern void ifnet_update_inet_traffic_rule_count(struct ifnet *, uint32_t);
1838 extern void ifnet_update_eth_traffic_rule_count(struct ifnet *, uint32_t);
1839 
1840 extern bool if_update_link_heuristic(struct ifnet *);
1841 
1842 #endif /* BSD_KERNEL_PRIVATE */
1843 #endif /* DRIVERKIT */
1844 
1845 #endif /* !_NET_IF_VAR_PRIVATE_H_ */
1846