1 /*
2 * Copyright (c) 2000-2022 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 #ifdef DRIVERKIT
68 #include <stddef.h>
69 #else
70 #include <sys/appleapiopts.h>
71 #include <stdint.h>
72 #include <sys/types.h>
73 #include <sys/time.h>
74 #include <sys/queue.h> /* get TAILQ macros */
75 #ifdef KERNEL_PRIVATE
76 #include <kern/locks.h>
77 #endif /* KERNEL_PRIVATE */
78 #ifdef PRIVATE
79 #include <net/route.h>
80 #endif
81 #ifdef BSD_KERN_PRIVATE
82 #include <net/pktsched/pktsched.h>
83 #include <sys/eventhandler.h>
84 #endif
85
86 #ifdef KERNEL
87 #include <net/kpi_interface.h>
88 #endif /* KERNEL */
89
90 #ifdef __APPLE__
91 #define APPLE_IF_FAM_LOOPBACK 1
92 #define APPLE_IF_FAM_ETHERNET 2
93 #define APPLE_IF_FAM_SLIP 3
94 #define APPLE_IF_FAM_TUN 4
95 #define APPLE_IF_FAM_VLAN 5
96 #define APPLE_IF_FAM_PPP 6
97 #define APPLE_IF_FAM_PVC 7
98 #define APPLE_IF_FAM_DISC 8
99 #define APPLE_IF_FAM_MDECAP 9
100 #define APPLE_IF_FAM_GIF 10
101 #define APPLE_IF_FAM_FAITH 11 /* deprecated */
102 #define APPLE_IF_FAM_STF 12
103 #define APPLE_IF_FAM_FIREWIRE 13
104 #define APPLE_IF_FAM_BOND 14
105 #define APPLE_IF_FAM_CELLULAR 15
106 #define APPLE_IF_FAM_6LOWPAN 16
107 #define APPLE_IF_FAM_UTUN 17
108 #define APPLE_IF_FAM_IPSEC 18
109 #endif /* __APPLE__ */
110
111 /*
112 * 72 was chosen below because it is the size of a TCP/IP
113 * header (40) + the minimum mss (32).
114 */
115 #define IF_MINMTU 72
116 #define IF_MAXMTU 65535
117
118 /*
119 * Structures defining a network interface, providing a packet
120 * transport mechanism (ala level 0 of the PUP protocols).
121 *
122 * Each interface accepts output datagrams of a specified maximum
123 * length, and provides higher level routines with input datagrams
124 * received from its medium.
125 *
126 * Output occurs when the routine if_output is called, with three parameters:
127 * (*ifp->if_output)(ifp, m, dst, rt)
128 * Here m is the mbuf chain to be sent and dst is the destination address.
129 * The output routine encapsulates the supplied datagram if necessary,
130 * and then transmits it on its medium.
131 *
132 * On input, each interface unwraps the data received by it, and either
133 * places it on the input queue of a internetwork datagram routine
134 * and posts the associated software interrupt, or passes the datagram to a raw
135 * packet input routine.
136 *
137 * Routines exist for locating interfaces by their addresses
138 * or for locating a interface on a certain network, as well as more general
139 * routing and gateway routines maintaining information used to locate
140 * interfaces. These routines live in the files if.c and route.c
141 */
142
143 #define IFNAMSIZ 16
144
145 /* This belongs up in socket.h or socketvar.h, depending on how far the
146 * event bubbles up.
147 */
148
149 struct net_event_data {
150 u_int32_t if_family;
151 u_int32_t if_unit;
152 char if_name[IFNAMSIZ];
153 };
154
155 #if defined(__LP64__)
156 #include <sys/_types/_timeval32.h>
157 #define IF_DATA_TIMEVAL timeval32
158 #else
159 #define IF_DATA_TIMEVAL timeval
160 #endif
161
162 #pragma pack(4)
163
164 /*
165 * Structure describing information about an interface
166 * which may be of interest to management entities.
167 */
168 struct if_data {
169 /* generic interface information */
170 u_char ifi_type; /* ethernet, tokenring, etc */
171 u_char ifi_typelen; /* Length of frame type id */
172 u_char ifi_physical; /* e.g., AUI, Thinnet, 10base-T, etc */
173 u_char ifi_addrlen; /* media address length */
174 u_char ifi_hdrlen; /* media header length */
175 u_char ifi_recvquota; /* polling quota for receive intrs */
176 u_char ifi_xmitquota; /* polling quota for xmit intrs */
177 u_char ifi_unused1; /* for future use */
178 u_int32_t ifi_mtu; /* maximum transmission unit */
179 u_int32_t ifi_metric; /* routing metric (external only) */
180 u_int32_t ifi_baudrate; /* linespeed */
181 /* volatile statistics */
182 u_int32_t ifi_ipackets; /* packets received on interface */
183 u_int32_t ifi_ierrors; /* input errors on interface */
184 u_int32_t ifi_opackets; /* packets sent on interface */
185 u_int32_t ifi_oerrors; /* output errors on interface */
186 u_int32_t ifi_collisions; /* collisions on csma interfaces */
187 u_int32_t ifi_ibytes; /* total number of octets received */
188 u_int32_t ifi_obytes; /* total number of octets sent */
189 u_int32_t ifi_imcasts; /* packets received via multicast */
190 u_int32_t ifi_omcasts; /* packets sent via multicast */
191 u_int32_t ifi_iqdrops; /* dropped on input, this interface */
192 u_int32_t ifi_noproto; /* destined for unsupported protocol */
193 u_int32_t ifi_recvtiming; /* usec spent receiving when timing */
194 u_int32_t ifi_xmittiming; /* usec spent xmitting when timing */
195 struct IF_DATA_TIMEVAL ifi_lastchange; /* time of last administrative change */
196 u_int32_t ifi_unused2; /* used to be the default_proto */
197 u_int32_t ifi_hwassist; /* HW offload capabilities */
198 u_int32_t ifi_reserved1; /* for future use */
199 u_int32_t ifi_reserved2; /* for future use */
200 };
201
202 /*
203 * Structure describing information about an interface
204 * which may be of interest to management entities.
205 */
206 struct if_data64 {
207 /* generic interface information */
208 u_char ifi_type; /* ethernet, tokenring, etc */
209 u_char ifi_typelen; /* Length of frame type id */
210 u_char ifi_physical; /* e.g., AUI, Thinnet, 10base-T, etc */
211 u_char ifi_addrlen; /* media address length */
212 u_char ifi_hdrlen; /* media header length */
213 u_char ifi_recvquota; /* polling quota for receive intrs */
214 u_char ifi_xmitquota; /* polling quota for xmit intrs */
215 u_char ifi_unused1; /* for future use */
216 u_int32_t ifi_mtu; /* maximum transmission unit */
217 u_int32_t ifi_metric; /* routing metric (external only) */
218 u_int64_t ifi_baudrate; /* linespeed */
219 /* volatile statistics */
220 u_int64_t ifi_ipackets; /* packets received on interface */
221 u_int64_t ifi_ierrors; /* input errors on interface */
222 u_int64_t ifi_opackets; /* packets sent on interface */
223 u_int64_t ifi_oerrors; /* output errors on interface */
224 u_int64_t ifi_collisions; /* collisions on csma interfaces */
225 u_int64_t ifi_ibytes; /* total number of octets received */
226 u_int64_t ifi_obytes; /* total number of octets sent */
227 u_int64_t ifi_imcasts; /* packets received via multicast */
228 u_int64_t ifi_omcasts; /* packets sent via multicast */
229 u_int64_t ifi_iqdrops; /* dropped on input, this interface */
230 u_int64_t ifi_noproto; /* destined for unsupported protocol */
231 u_int32_t ifi_recvtiming; /* usec spent receiving when timing */
232 u_int32_t ifi_xmittiming; /* usec spent xmitting when timing */
233 struct IF_DATA_TIMEVAL ifi_lastchange; /* time of last administrative change */
234 };
235
236 #ifdef PRIVATE
237 struct if_traffic_class {
238 u_int64_t ifi_ibepackets; /* TC_BE packets received on interface */
239 u_int64_t ifi_ibebytes; /* TC_BE bytes received on interface */
240 u_int64_t ifi_obepackets; /* TC_BE packet sent on interface */
241 u_int64_t ifi_obebytes; /* TC_BE bytes sent on interface */
242 u_int64_t ifi_ibkpackets; /* TC_BK packets received on interface */
243 u_int64_t ifi_ibkbytes; /* TC_BK bytes received on interface */
244 u_int64_t ifi_obkpackets; /* TC_BK packet sent on interface */
245 u_int64_t ifi_obkbytes; /* TC_BK bytes sent on interface */
246 u_int64_t ifi_ivipackets; /* TC_VI packets received on interface */
247 u_int64_t ifi_ivibytes; /* TC_VI bytes received on interface */
248 u_int64_t ifi_ovipackets; /* TC_VI packets sent on interface */
249 u_int64_t ifi_ovibytes; /* TC_VI bytes sent on interface */
250 u_int64_t ifi_ivopackets; /* TC_VO packets received on interface */
251 u_int64_t ifi_ivobytes; /* TC_VO bytes received on interface */
252 u_int64_t ifi_ovopackets; /* TC_VO packets sent on interface */
253 u_int64_t ifi_ovobytes; /* TC_VO bytes sent on interface */
254 u_int64_t ifi_ipvpackets; /* TC priv packets received on interface */
255 u_int64_t ifi_ipvbytes; /* TC priv bytes received on interface */
256 u_int64_t ifi_opvpackets; /* TC priv packets sent on interface */
257 u_int64_t ifi_opvbytes; /* TC priv bytes sent on interface */
258 };
259
260 struct if_data_extended {
261 u_int64_t ifi_alignerrs; /* unaligned (32-bit) input pkts */
262 u_int64_t ifi_dt_bytes; /* Data threshold counter */
263 u_int64_t ifi_fpackets; /* forwarded packets on interface */
264 u_int64_t ifi_fbytes; /* forwarded bytes on interface */
265 u_int64_t reserved[12]; /* for future */
266 };
267
268 struct if_packet_stats {
269 /* TCP */
270 u_int64_t ifi_tcp_badformat;
271 u_int64_t ifi_tcp_unspecv6;
272 u_int64_t ifi_tcp_synfin;
273 u_int64_t ifi_tcp_badformatipsec;
274 u_int64_t ifi_tcp_noconnnolist;
275 u_int64_t ifi_tcp_noconnlist;
276 u_int64_t ifi_tcp_listbadsyn;
277 u_int64_t ifi_tcp_icmp6unreach;
278 u_int64_t ifi_tcp_deprecate6;
279 u_int64_t ifi_tcp_rstinsynrcv;
280 u_int64_t ifi_tcp_ooopacket;
281 u_int64_t ifi_tcp_dospacket;
282 u_int64_t ifi_tcp_cleanup;
283 u_int64_t ifi_tcp_synwindow;
284 u_int64_t reserved[6];
285 /* UDP */
286 u_int64_t ifi_udp_port_unreach;
287 u_int64_t ifi_udp_faithprefix;
288 u_int64_t ifi_udp_port0;
289 u_int64_t ifi_udp_badlength;
290 u_int64_t ifi_udp_badchksum;
291 u_int64_t ifi_udp_badmcast;
292 u_int64_t ifi_udp_cleanup;
293 u_int64_t ifi_udp_badipsec;
294 u_int64_t _reserved[4];
295 };
296
297 struct if_description {
298 u_int32_t ifd_maxlen; /* must be IF_DESCSIZE */
299 u_int32_t ifd_len; /* actual ifd_desc length */
300 u_int8_t *ifd_desc; /* ptr to desc buffer */
301 };
302
303 struct if_bandwidths {
304 uint64_t eff_bw; /* effective bandwidth */
305 uint64_t max_bw; /* maximum theoretical bandwidth */
306 };
307
308 struct if_latencies {
309 u_int64_t eff_lt; /* effective latency */
310 u_int64_t max_lt; /* maximum theoretical latency */
311 };
312
313 #define IF_NETEM_PARAMS_PSCALE 100000
314 struct if_netem_params {
315 /* bandwidth limit */
316 uint64_t ifnetem_bandwidth_bps;
317
318 /* latency (normal distribution with jitter as stdev) */
319 uint32_t ifnetem_latency_ms;
320 uint32_t ifnetem_jitter_ms;
321
322 /*
323 * NetEm probabilistic model parameters has a scaling factor of 100,000
324 * for 5 digits precision. For instance, probability 12.345% is
325 * expressed as uint32_t fixed point 12345 in ifnet_*_p variable below.
326 */
327 /* random packet corruption */
328 uint32_t ifnetem_corruption_p;
329
330 /* random packet duplication */
331 uint32_t ifnetem_duplication_p;
332
333 /* 4 state Markov loss model */
334 uint32_t ifnetem_loss_p_gr_gl; /* P( gap_loss | gap_rx ) */
335 uint32_t ifnetem_loss_p_gr_bl; /* P( burst_loss | gap_rx ) */
336 uint32_t ifnetem_loss_p_bl_br; /* P( burst_rx | burst_loss ) */
337 uint32_t ifnetem_loss_p_bl_gr; /* P( gap_rx | burst_loss ) */
338 uint32_t ifnetem_loss_p_br_bl; /* P( burst_loss | burst_rx ) */
339
340 /* random packet reordering */
341 uint32_t ifnetem_reordering_p;
342 };
343
344 struct if_rxpoll_stats {
345 u_int32_t ifi_poll_off_req; /* total # of POLL_OFF reqs */
346 u_int32_t ifi_poll_off_err; /* total # of POLL_OFF errors */
347 u_int32_t ifi_poll_on_req; /* total # of POLL_ON reqs */
348 u_int32_t ifi_poll_on_err; /* total # of POLL_ON errors */
349
350 u_int32_t ifi_poll_wakeups_avg; /* avg # of wakeup reqs */
351 u_int32_t ifi_poll_wakeups_lowat; /* wakeups low watermark */
352 u_int32_t ifi_poll_wakeups_hiwat; /* wakeups high watermark */
353
354 u_int64_t ifi_poll_packets; /* total # of polled packets */
355 u_int32_t ifi_poll_packets_avg; /* average polled packets */
356 u_int32_t ifi_poll_packets_min; /* smallest polled packets */
357 u_int32_t ifi_poll_packets_max; /* largest polled packets */
358 u_int32_t ifi_poll_packets_lowat; /* packets low watermark */
359 u_int32_t ifi_poll_packets_hiwat; /* packets high watermark */
360
361 u_int64_t ifi_poll_bytes; /* total # of polled bytes */
362 u_int32_t ifi_poll_bytes_avg; /* average polled bytes */
363 u_int32_t ifi_poll_bytes_min; /* smallest polled bytes */
364 u_int32_t ifi_poll_bytes_max; /* largest polled bytes */
365 u_int32_t ifi_poll_bytes_lowat; /* bytes low watermark */
366 u_int32_t ifi_poll_bytes_hiwat; /* bytes high watermark */
367
368 u_int32_t ifi_poll_packets_limit; /* max packets per poll call */
369 u_int64_t ifi_poll_interval_time; /* poll interval (nsec) */
370 };
371
372 struct if_netif_stats {
373 u_int64_t ifn_rx_mit_interval; /* rx mitigation ival (nsec) */
374 u_int32_t ifn_rx_mit_mode; /* 0: static, 1: dynamic */
375 u_int32_t ifn_rx_mit_packets_avg; /* average # of packets */
376 u_int32_t ifn_rx_mit_packets_min; /* smallest # of packets */
377 u_int32_t ifn_rx_mit_packets_max; /* largest # of packets */
378 u_int32_t ifn_rx_mit_bytes_avg; /* average # of bytes */
379 u_int32_t ifn_rx_mit_bytes_min; /* smallest # of bytes */
380 u_int32_t ifn_rx_mit_bytes_max; /* largest # of bytes */
381 u_int32_t ifn_rx_mit_cfg_idx; /* current config selector */
382 u_int32_t ifn_rx_mit_cfg_packets_lowat; /* pkts low watermark */
383 u_int32_t ifn_rx_mit_cfg_packets_hiwat; /* pkts high watermark */
384 u_int32_t ifn_rx_mit_cfg_bytes_lowat; /* bytes low watermark */
385 u_int32_t ifn_rx_mit_cfg_bytes_hiwat; /* bytes high watermark */
386 u_int32_t ifn_rx_mit_cfg_interval; /* delay interval (nsec) */
387 };
388
389 struct if_tcp_ecn_perf_stat {
390 u_int64_t total_txpkts;
391 u_int64_t total_rxmitpkts;
392 u_int64_t total_rxpkts;
393 u_int64_t total_oopkts;
394 u_int64_t total_reorderpkts;
395 u_int64_t rtt_avg;
396 u_int64_t rtt_var;
397 u_int64_t sack_episodes;
398 u_int64_t rxmit_drop;
399 u_int64_t rst_drop;
400 u_int64_t oo_percent;
401 u_int64_t reorder_percent;
402 u_int64_t rxmit_percent;
403 };
404
405 struct if_tcp_ecn_stat {
406 u_int64_t timestamp;
407 u_int64_t ecn_client_setup;
408 u_int64_t ecn_server_setup;
409 u_int64_t ecn_client_success;
410 u_int64_t ecn_server_success;
411 u_int64_t ecn_peer_nosupport;
412 u_int64_t ecn_syn_lost;
413 u_int64_t ecn_synack_lost;
414 u_int64_t ecn_recv_ce;
415 u_int64_t ecn_recv_ece;
416 u_int64_t ecn_conn_recv_ce;
417 u_int64_t ecn_conn_recv_ece;
418 u_int64_t ecn_conn_plnoce;
419 u_int64_t ecn_conn_plce;
420 u_int64_t ecn_conn_noplce;
421 u_int64_t ecn_fallback_synloss;
422 u_int64_t ecn_fallback_reorder;
423 u_int64_t ecn_fallback_ce;
424 u_int64_t ecn_off_conn;
425 u_int64_t ecn_total_conn;
426 u_int64_t ecn_fallback_droprst;
427 u_int64_t ecn_fallback_droprxmt;
428 u_int64_t ecn_fallback_synrst;
429 struct if_tcp_ecn_perf_stat ecn_on;
430 struct if_tcp_ecn_perf_stat ecn_off;
431 };
432
433 struct if_lim_perf_stat {
434 u_int64_t lim_dl_max_bandwidth; /* bits per second */
435 u_int64_t lim_ul_max_bandwidth; /* bits per second */
436 u_int64_t lim_total_txpkts; /* Total transmit packets, count */
437 u_int64_t lim_total_rxpkts; /* Total receive packets, count */
438 u_int64_t lim_total_retxpkts; /* Total retransmit packets */
439 u_int64_t lim_packet_loss_percent; /* Packet loss rate */
440 u_int64_t lim_total_oopkts; /* Total out-of-order packets */
441 u_int64_t lim_packet_ooo_percent; /* Out-of-order packet rate */
442 u_int64_t lim_rtt_variance; /* RTT variance, milliseconds */
443 u_int64_t lim_rtt_average; /* RTT average, milliseconds */
444 u_int64_t lim_rtt_min; /* RTT minimum, milliseconds */
445 u_int64_t lim_conn_timeouts; /* connection timeouts */
446 u_int64_t lim_conn_attempts; /* connection attempts */
447 u_int64_t lim_conn_timeout_percent; /* Rate of connection timeouts */
448 u_int64_t lim_bk_txpkts; /* Transmit packets with BK service class, that use delay based algorithms */
449 u_int64_t lim_dl_detected:1, /* Low internet */
450 lim_ul_detected:1;
451 };
452
453 #define IF_VAR_H_HAS_IFNET_STATS_PER_FLOW 1
454 struct ifnet_stats_per_flow {
455 u_int64_t bk_txpackets;
456 u_int64_t txpackets;
457 u_int64_t rxpackets;
458 u_int32_t txretransmitbytes;
459 u_int32_t rxoutoforderbytes;
460 u_int32_t rxmitpkts;
461 u_int32_t rcvoopack;
462 u_int32_t pawsdrop;
463 u_int32_t sack_recovery_episodes;
464 u_int32_t reordered_pkts;
465 u_int32_t dsack_sent;
466 u_int32_t dsack_recvd;
467 u_int32_t srtt;
468 u_int32_t rttupdated;
469 u_int32_t rttvar;
470 u_int32_t rttmin;
471 u_int32_t bw_sndbw_max;
472 u_int32_t bw_rcvbw_max;
473 u_int32_t ecn_recv_ece;
474 u_int32_t ecn_recv_ce;
475 u_int16_t ecn_flags;
476 u_int16_t ipv4:1,
477 local:1,
478 connreset:1,
479 conntimeout:1,
480 rxmit_drop:1,
481 ecn_fallback_synloss:1,
482 ecn_fallback_droprst:1,
483 ecn_fallback_droprxmt:1,
484 ecn_fallback_ce:1,
485 ecn_fallback_reorder:1;
486 };
487
488 /*
489 * Interface link status report -- includes statistics related to
490 * the link layer technology sent by the driver. The driver will monitor
491 * these statistics over an interval (3-4 secs) and will generate a report
492 * to the network stack. This will give first-hand information about the
493 * status of the first hop of the network path. The version and
494 * length values should be correct for the data to be processed correctly.
495 * The definitions are different for different kind of interfaces like
496 * Wifi, Cellular etc,.
497 */
498 #define IF_CELLULAR_STATUS_REPORT_VERSION_1 1
499 #define IF_WIFI_STATUS_REPORT_VERSION_1 1
500 #define IF_CELLULAR_STATUS_REPORT_CURRENT_VERSION \
501 IF_CELLULAR_STATUS_REPORT_VERSION_1
502 #define IF_WIFI_STATUS_REPORT_CURRENT_VERSION IF_WIFI_STATUS_REPORT_VERSION_1
503 /*
504 * For cellular interface --
505 * There is no way to share common headers between the Baseband and
506 * the kernel. Any changes to this structure will need to be communicated
507 * to the Baseband team. It is better to use reserved space instead of
508 * changing the size or existing fields in the structure.
509 */
510 struct if_cellular_status_v1 {
511 u_int32_t valid_bitmask; /* indicates which fields are valid */
512 #define IF_CELL_LINK_QUALITY_METRIC_VALID 0x1
513 #define IF_CELL_UL_EFFECTIVE_BANDWIDTH_VALID 0x2
514 #define IF_CELL_UL_MAX_BANDWIDTH_VALID 0x4
515 #define IF_CELL_UL_MIN_LATENCY_VALID 0x8
516 #define IF_CELL_UL_EFFECTIVE_LATENCY_VALID 0x10
517 #define IF_CELL_UL_MAX_LATENCY_VALID 0x20
518 #define IF_CELL_UL_RETXT_LEVEL_VALID 0x40
519 #define IF_CELL_UL_BYTES_LOST_VALID 0x80
520 #define IF_CELL_UL_MIN_QUEUE_SIZE_VALID 0x100
521 #define IF_CELL_UL_AVG_QUEUE_SIZE_VALID 0x200
522 #define IF_CELL_UL_MAX_QUEUE_SIZE_VALID 0x400
523 #define IF_CELL_DL_EFFECTIVE_BANDWIDTH_VALID 0x800
524 #define IF_CELL_DL_MAX_BANDWIDTH_VALID 0x1000
525 #define IF_CELL_CONFIG_INACTIVITY_TIME_VALID 0x2000
526 #define IF_CELL_CONFIG_BACKOFF_TIME_VALID 0x4000
527 #define IF_CELL_UL_MSS_RECOMMENDED_VALID 0x8000
528
529 u_int32_t link_quality_metric;
530 u_int32_t ul_effective_bandwidth; /* Measured uplink bandwidth based on current activity (bps) */
531 u_int32_t ul_max_bandwidth; /* Maximum supported uplink bandwidth (bps) */
532 u_int32_t ul_min_latency; /* min expected uplink latency for first hop (ms) */
533 u_int32_t ul_effective_latency; /* current expected uplink latency for first hop (ms) */
534 u_int32_t ul_max_latency; /* max expected uplink latency first hop (ms) */
535 u_int32_t ul_retxt_level; /* Retransmission metric */
536 #define IF_CELL_UL_RETXT_LEVEL_NONE 1
537 #define IF_CELL_UL_RETXT_LEVEL_LOW 2
538 #define IF_CELL_UL_RETXT_LEVEL_MEDIUM 3
539 #define IF_CELL_UL_RETXT_LEVEL_HIGH 4
540 u_int32_t ul_bytes_lost; /* % of total bytes lost on uplink in Q10 format */
541 u_int32_t ul_min_queue_size; /* minimum bytes in queue */
542 u_int32_t ul_avg_queue_size; /* average bytes in queue */
543 u_int32_t ul_max_queue_size; /* maximum bytes in queue */
544 u_int32_t dl_effective_bandwidth; /* Measured downlink bandwidth based on current activity (bps) */
545 u_int32_t dl_max_bandwidth; /* Maximum supported downlink bandwidth (bps) */
546 u_int32_t config_inactivity_time; /* ms */
547 u_int32_t config_backoff_time; /* new connections backoff time in ms */
548 #define IF_CELL_UL_MSS_RECOMMENDED_NONE 0x0 /* Use default */
549 #define IF_CELL_UL_MSS_RECOMMENDED_MEDIUM 0x1 /* 1200 byte MSS */
550 #define IF_CELL_UL_MSS_RECOMMENDED_LOW 0x2 /* 512 byte MSS */
551 u_int16_t mss_recommended;
552 u_int16_t reserved_1;
553 u_int32_t reserved_2;
554 u_int64_t reserved_3;
555 u_int64_t reserved_4;
556 u_int64_t reserved_5;
557 u_int64_t reserved_6;
558 } __attribute__((packed));
559
560 struct if_cellular_status {
561 union {
562 struct if_cellular_status_v1 if_status_v1;
563 } if_cell_u;
564 };
565
566 /*
567 * These statistics will be provided by the Wifi driver periodically.
568 * After sending each report, the driver should start computing again
569 * for the next report duration so that the values represent the link
570 * status for one report duration.
571 */
572
573 struct if_wifi_status_v1 {
574 u_int32_t valid_bitmask;
575 #define IF_WIFI_LINK_QUALITY_METRIC_VALID 0x1
576 #define IF_WIFI_UL_EFFECTIVE_BANDWIDTH_VALID 0x2
577 #define IF_WIFI_UL_MAX_BANDWIDTH_VALID 0x4
578 #define IF_WIFI_UL_MIN_LATENCY_VALID 0x8
579 #define IF_WIFI_UL_EFFECTIVE_LATENCY_VALID 0x10
580 #define IF_WIFI_UL_MAX_LATENCY_VALID 0x20
581 #define IF_WIFI_UL_RETXT_LEVEL_VALID 0x40
582 #define IF_WIFI_UL_ERROR_RATE_VALID 0x80
583 #define IF_WIFI_UL_BYTES_LOST_VALID 0x100
584 #define IF_WIFI_DL_EFFECTIVE_BANDWIDTH_VALID 0x200
585 #define IF_WIFI_DL_MAX_BANDWIDTH_VALID 0x400
586 #define IF_WIFI_DL_MIN_LATENCY_VALID 0x800
587 #define IF_WIFI_DL_EFFECTIVE_LATENCY_VALID 0x1000
588 #define IF_WIFI_DL_MAX_LATENCY_VALID 0x2000
589 #define IF_WIFI_DL_ERROR_RATE_VALID 0x4000
590 #define IF_WIFI_CONFIG_FREQUENCY_VALID 0x8000
591 #define IF_WIFI_CONFIG_MULTICAST_RATE_VALID 0x10000
592 #define IF_WIFI_CONFIG_SCAN_COUNT_VALID 0x20000
593 #define IF_WIFI_CONFIG_SCAN_DURATION_VALID 0x40000
594 u_int32_t link_quality_metric; /* link quality metric */
595 u_int32_t ul_effective_bandwidth; /* Measured uplink bandwidth based on current activity (bps) */
596 u_int32_t ul_max_bandwidth; /* Maximum supported uplink bandwidth (bps) */
597 u_int32_t ul_min_latency; /* min expected uplink latency for first hop (ms) */
598 u_int32_t ul_effective_latency; /* current expected uplink latency for first hop (ms) */
599 u_int32_t ul_max_latency; /* max expected uplink latency for first hop (ms) */
600 u_int32_t ul_retxt_level; /* Retransmission metric */
601 #define IF_WIFI_UL_RETXT_LEVEL_NONE 1
602 #define IF_WIFI_UL_RETXT_LEVEL_LOW 2
603 #define IF_WIFI_UL_RETXT_LEVEL_MEDIUM 3
604 #define IF_WIFI_UL_RETXT_LEVEL_HIGH 4
605 u_int32_t ul_bytes_lost; /* % of total bytes lost on uplink in Q10 format */
606 u_int32_t ul_error_rate; /* % of bytes dropped on uplink after many retransmissions in Q10 format */
607 u_int32_t dl_effective_bandwidth; /* Measured downlink bandwidth based on current activity (bps) */
608 u_int32_t dl_max_bandwidth; /* Maximum supported downlink bandwidth (bps) */
609 /*
610 * The download latency values indicate the time AP may have to wait for the
611 * driver to receive the packet. These values give the range of expected latency
612 * mainly due to co-existence events and channel hopping where the interface
613 * becomes unavailable.
614 */
615 u_int32_t dl_min_latency; /* min expected latency for first hop in ms */
616 u_int32_t dl_effective_latency; /* current expected latency for first hop in ms */
617 u_int32_t dl_max_latency; /* max expected latency for first hop in ms */
618 u_int32_t dl_error_rate; /* % of CRC or other errors in Q10 format */
619 u_int32_t config_frequency; /* 2.4 or 5 GHz */
620 #define IF_WIFI_CONFIG_FREQUENCY_2_4_GHZ 1
621 #define IF_WIFI_CONFIG_FREQUENCY_5_0_GHZ 2
622 u_int32_t config_multicast_rate; /* bps */
623 u_int32_t scan_count; /* scan count during the previous period */
624 u_int32_t scan_duration; /* scan duration in ms */
625 u_int64_t reserved_1;
626 u_int64_t reserved_2;
627 u_int64_t reserved_3;
628 u_int64_t reserved_4;
629 } __attribute__((packed));
630
631 struct if_wifi_status {
632 union {
633 struct if_wifi_status_v1 if_status_v1;
634 } if_wifi_u;
635 };
636
637 struct if_link_status {
638 u_int32_t ifsr_version; /* version of this report */
639 u_int32_t ifsr_len; /* length of the following struct */
640 union {
641 struct if_cellular_status ifsr_cell;
642 struct if_wifi_status ifsr_wifi;
643 } ifsr_u;
644 };
645
646 struct if_interface_state {
647 /*
648 * The bitmask tells which of the fields
649 * to consider:
650 * - When setting, to control which fields
651 * are being modified;
652 * - When getting, it tells which fields are set.
653 */
654 u_int8_t valid_bitmask;
655 #define IF_INTERFACE_STATE_RRC_STATE_VALID 0x1
656 #define IF_INTERFACE_STATE_LQM_STATE_VALID 0x2
657 #define IF_INTERFACE_STATE_INTERFACE_AVAILABILITY_VALID 0x4
658
659 /*
660 * Valid only for cellular interface
661 */
662 u_int8_t rrc_state;
663 #define IF_INTERFACE_STATE_RRC_STATE_IDLE 0x0
664 #define IF_INTERFACE_STATE_RRC_STATE_CONNECTED 0x1
665
666 /*
667 * Values normalized to the edge of the following values
668 * that are defined on <net/if.h>:
669 * IFNET_LQM_THRESH_BAD
670 * IFNET_LQM_THRESH_POOR
671 * IFNET_LQM_THRESH_GOOD
672 */
673 int8_t lqm_state;
674
675 /*
676 * Indicate if the underlying link is currently
677 * available
678 */
679 u_int8_t interface_availability;
680 #define IF_INTERFACE_STATE_INTERFACE_AVAILABLE 0x0
681 #define IF_INTERFACE_STATE_INTERFACE_UNAVAILABLE 0x1
682 };
683
684 struct chain_len_stats {
685 uint64_t cls_one;
686 uint64_t cls_two;
687 uint64_t cls_three;
688 uint64_t cls_four;
689 uint64_t cls_five_or_more;
690 } __attribute__((__aligned__(sizeof(uint64_t))));
691
692 #endif /* PRIVATE */
693 #endif /* DRIVERKIT */
694
695 #if defined (PRIVATE) || defined (DRIVERKIT_PRIVATE)
696 /*
697 * This structure is used to define the parameters for advisory notifications
698 * on an interface.
699 */
700 #pragma pack(push, 1)
701 struct ifnet_interface_advisory {
702 /* The current structure version */
703 uint8_t version;
704 #define IF_INTERFACE_ADVISORY_VERSION_1 0x1
705 #define IF_INTERFACE_ADVISORY_VERSION_CURRENT IF_INTERFACE_ADVISORY_VERSION_1
706 /* Specifies if the advisory is for transmit or receive path */
707 uint8_t direction;
708 #define IF_INTERFACE_ADVISORY_DIRECTION_TX 0x1
709 #define IF_INTERFACE_ADVISORY_DIRECTION_RX 0x2
710 /* reserved for future use */
711 uint16_t _reserved;
712 /*
713 * suggestion for data rate change to keep the latency low.
714 * unit: bits per second (bps)
715 * NOTE: if the interface cannot provide suggestions in terms of bps,
716 * it should use the following values:
717 * INT32_MAX : ramp up
718 * INT32_MIN : ramp down
719 * 0 : neutral
720 */
721 #define IF_INTERFACE_ADVISORY_RATE_SUGGESTION_RAMP_UP INT32_MAX
722 #define IF_INTERFACE_ADVISORY_RATE_SUGGESTION_RAMP_DOWN INT32_MIN
723 #define IF_INTERFACE_ADVISORY_RATE_SUGGESTION_RAMP_NEUTRAL 0
724 int32_t rate_trend_suggestion;
725 /*
726 * Time of the issue of advisory.
727 * Timestamp should be in the host domain.
728 * unit: mach absolute time
729 */
730 uint64_t timestamp;
731 /*
732 * Maximum theoretical bandwidth of the interface.
733 * unit: bits per second (bps)
734 */
735 uint64_t max_bandwidth;
736 /*
737 * Total bytes sent or received on the interface.
738 * wrap around possible and the application should account for that.
739 * unit: byte
740 */
741 uint64_t total_byte_count;
742 /*
743 * average throughput observed at the driver stack.
744 * unit: bits per second (bps)
745 */
746 uint64_t average_throughput;
747 /*
748 * flushable queue size at the driver.
749 * should be set to UINT32_MAX if not available.
750 * unit: byte
751 */
752 uint32_t flushable_queue_size;
753 /*
754 * non flushable queue size at the driver.
755 * should be set to UINT32_MAX if not available.
756 * unit: byte
757 */
758 uint32_t non_flushable_queue_size;
759 /*
760 * average delay observed at the interface.
761 * unit: milliseconds (ms)
762 */
763 uint32_t average_delay;
764 /*
765 * Current frequency band (enumeration).
766 */
767 #define IF_INTERFACE_ADVISORY_FREQ_BAND_NOT_AVAIL 0
768 #define IF_INTERFACE_ADVISORY_FREQ_BAND_WIFI_24GHZ 1
769 #define IF_INTERFACE_ADVISORY_FREQ_BAND_WIFI_5GHZ 2
770 #define IF_INTERFACE_ADVISORY_FREQ_BAND_WIFI_6GHZ 3
771 uint8_t frequency_band;
772 /*
773 * Intermittent WiFi state [true(1)/false(0)]
774 */
775 uint8_t intermittent_state;
776 /*
777 * Estimated period for which intermittent state is expected to last.
778 * 1 tick -> 1 ms UNDEF => UINT16_MAX
779 */
780 uint16_t estimated_intermittent_period;
781 /*
782 * Expected wifi outage period during intermittent state
783 * 1 tick -> 1 ms UNDEF => UINT16_MAX
784 */
785 uint16_t single_outage_period;
786
787 /*
788 * WiFi-BT coexistence, 1-ON, 0-OFF
789 */
790 uint8_t bt_coex;
791 /*
792 * on scale of 1 to 5
793 */
794 uint8_t quality_score_delay;
795 /*
796 * on scale of 1 to 5
797 */
798 uint8_t quality_score_loss;
799 /*
800 * on scale of 1 to 5
801 */
802 uint8_t quality_score_channel;
803 } __attribute__((aligned(sizeof(uint64_t))));
804 #pragma pack(pop)
805
806 #else
807
808 struct ifnet_interface_advisory;
809
810 #endif /* defined (PRIVATE) || defined (DRIVERKIT_PRIVATE) */
811
812 #ifndef DRIVERKIT
813
814 #pragma pack()
815
816 /*
817 * Structure defining a queue for a network interface.
818 */
819 struct ifqueue {
820 void *ifq_head;
821 void *ifq_tail;
822 int ifq_len;
823 int ifq_maxlen;
824 int ifq_drops;
825 };
826
827 #ifdef BSD_KERNEL_PRIVATE
828 #define IFNETS_MAX 64
829
830 /*
831 * Internal storage of if_data. This is bound to change. Various places in the
832 * stack will translate this data structure in to the externally visible
833 * if_data structure above. Note that during interface attach time, the
834 * embedded if_data structure in ifnet is cleared, with the exception of
835 * some non-statistics related fields.
836 */
837 struct if_data_internal {
838 /* generic interface information */
839 u_char ifi_type; /* ethernet, tokenring, etc */
840 u_char ifi_typelen; /* Length of frame type id */
841 u_char ifi_physical; /* e.g., AUI, Thinnet, 10base-T, etc */
842 u_char ifi_addrlen; /* media address length */
843 u_char ifi_hdrlen; /* media header length */
844 u_char ifi_recvquota; /* polling quota for receive intrs */
845 u_char ifi_xmitquota; /* polling quota for xmit intrs */
846 u_char ifi_unused1; /* for future use */
847 u_int32_t ifi_mtu; /* maximum transmission unit */
848 u_int32_t ifi_metric; /* routing metric (external only) */
849 u_int32_t ifi_baudrate; /* linespeed */
850 /* volatile statistics */
851 u_int64_t ifi_ipackets; /* packets received on interface */
852 u_int64_t ifi_ierrors; /* input errors on interface */
853 u_int64_t ifi_opackets; /* packets sent on interface */
854 u_int64_t ifi_oerrors; /* output errors on interface */
855 u_int64_t ifi_collisions; /* collisions on csma interfaces */
856 u_int64_t ifi_ibytes; /* total number of octets received */
857 u_int64_t ifi_obytes; /* total number of octets sent */
858 u_int64_t ifi_imcasts; /* packets received via multicast */
859 u_int64_t ifi_omcasts; /* packets sent via multicast */
860 u_int64_t ifi_iqdrops; /* dropped on input, this interface */
861 u_int64_t ifi_noproto; /* destined for unsupported protocol */
862 u_int32_t ifi_recvtiming; /* usec spent receiving when timing */
863 u_int32_t ifi_xmittiming; /* usec spent xmitting when timing */
864 u_int64_t ifi_alignerrs; /* unaligned (32-bit) input pkts */
865 u_int64_t ifi_dt_bytes; /* Data threshold counter */
866 u_int64_t ifi_fpackets; /* forwarded packets on interface */
867 u_int64_t ifi_fbytes; /* forwarded bytes on interface */
868 struct timeval ifi_lastchange; /* time of last administrative change */
869 struct timeval ifi_lastupdown; /* time of last up/down event */
870 u_int32_t ifi_hwassist; /* HW offload capabilities */
871 u_int32_t ifi_tso_v4_mtu; /* TCP Segment Offload IPv4 maximum segment size */
872 u_int32_t ifi_tso_v6_mtu; /* TCP Segment Offload IPv6 maximum segment size */
873 };
874 #endif /* BSD_KERNEL_PRIVATE */
875
876 #ifdef PRIVATE
877 #define if_mtu if_data.ifi_mtu
878 #define if_type if_data.ifi_type
879 #define if_typelen if_data.ifi_typelen
880 #define if_physical if_data.ifi_physical
881 #define if_addrlen if_data.ifi_addrlen
882 #define if_hdrlen if_data.ifi_hdrlen
883 #define if_metric if_data.ifi_metric
884 #define if_baudrate if_data.ifi_baudrate
885 #define if_hwassist if_data.ifi_hwassist
886 #define if_ipackets if_data.ifi_ipackets
887 #define if_ierrors if_data.ifi_ierrors
888 #define if_opackets if_data.ifi_opackets
889 #define if_oerrors if_data.ifi_oerrors
890 #define if_collisions if_data.ifi_collisions
891 #define if_ibytes if_data.ifi_ibytes
892 #define if_obytes if_data.ifi_obytes
893 #define if_imcasts if_data.ifi_imcasts
894 #define if_omcasts if_data.ifi_omcasts
895 #define if_iqdrops if_data.ifi_iqdrops
896 #define if_noproto if_data.ifi_noproto
897 #define if_lastchange if_data.ifi_lastchange
898 #define if_recvquota if_data.ifi_recvquota
899 #define if_xmitquota if_data.ifi_xmitquota
900 #endif /* PRIVATE */
901 #ifdef BSD_KERNEL_PRIVATE
902 #define if_tso_v4_mtu if_data.ifi_tso_v4_mtu
903 #define if_tso_v6_mtu if_data.ifi_tso_v6_mtu
904 #define if_alignerrs if_data.ifi_alignerrs
905 #define if_dt_bytes if_data.ifi_dt_bytes
906 #define if_fpackets if_data.ifi_fpackets
907 #define if_fbytes if_data.ifi_fbytes
908 #define if_lastupdown if_data.ifi_lastupdown
909 #endif /* BSD_KERNEL_PRIVATE */
910
911 #ifdef BSD_KERNEL_PRIVATE
912 /*
913 * Forward structure declarations for function prototypes [sic].
914 */
915 struct proc;
916 struct rtentry;
917 struct socket;
918 struct ifnet_filter;
919 struct mbuf;
920 struct ifaddr;
921 struct tqdummy;
922 struct proto_hash_entry;
923 struct dlil_threading_info;
924 struct tcpstat_local;
925 struct udpstat_local;
926 #if PF
927 struct pfi_kif;
928 #endif /* PF */
929 #if SKYWALK
930 struct nexus_netif_adapter;
931 #endif /* SKYWALK */
932
933 /* we use TAILQs so that the order of instantiation is preserved in the list */
934 TAILQ_HEAD(ifnethead, ifnet);
935 TAILQ_HEAD(ifaddrhead, ifaddr);
936 LIST_HEAD(ifmultihead, ifmultiaddr);
937 TAILQ_HEAD(tailq_head, tqdummy);
938 TAILQ_HEAD(ifnet_filter_head, ifnet_filter);
939 TAILQ_HEAD(ddesc_head_name, dlil_demux_desc);
940
941 extern bool intcoproc_unrestricted;
942 #endif /* BSD_KERNEL_PRIVATE */
943
944 #ifdef PRIVATE
945 /*
946 * All of the following IF_HWASSIST_* flags are defined in kpi_interface.h as
947 * IFNET_* flags. These are redefined here as constants to avoid failures to
948 * build user level programs that can not include kpi_interface.h. It is
949 * important to keep this in sync with the definitions in kpi_interface.h.
950 * The corresponding constant for each definition is mentioned in the comment.
951 *
952 * Bottom 16 bits reserved for hardware checksum
953 */
954 #define IF_HWASSIST_CSUM_IP 0x0001 /* will csum IP, IFNET_CSUM_IP */
955 #define IF_HWASSIST_CSUM_TCP 0x0002 /* will csum TCP, IFNET_CSUM_TCP */
956 #define IF_HWASSIST_CSUM_UDP 0x0004 /* will csum UDP, IFNET_CSUM_UDP */
957 #define IF_HWASSIST_CSUM_IP_FRAGS 0x0008 /* will csum IP fragments, IFNET_CSUM_FRAGMENT */
958 #define IF_HWASSIST_CSUM_FRAGMENT 0x0010 /* will do IP fragmentation, IFNET_IP_FRAGMENT */
959 #define IF_HWASSIST_CSUM_TCPIPV6 0x0020 /* will csum TCPv6, IFNET_CSUM_TCPIPV6 */
960 #define IF_HWASSIST_CSUM_UDPIPV6 0x0040 /* will csum UDPv6, IFNET_CSUM_UDP */
961 #define IF_HWASSIST_CSUM_FRAGMENT_IPV6 0x0080 /* will do IPv6 fragmentation, IFNET_IPV6_FRAGMENT */
962 #define IF_HWASSIST_CSUM_PARTIAL 0x1000 /* simple Sum16 computation, IFNET_CSUM_PARTIAL */
963 #define IF_HWASSIST_CSUM_ZERO_INVERT 0x2000 /* capable of inverting csum of 0 to -0 (0xffff) */
964 #define IF_HWASSIST_CSUM_MASK 0xffff
965 #define IF_HWASSIST_CSUM_FLAGS(hwassist) ((hwassist) & IF_HWASSIST_CSUM_MASK)
966
967 /* VLAN support */
968 #define IF_HWASSIST_VLAN_TAGGING 0x00010000 /* supports VLAN tagging, IFNET_VLAN_TAGGING */
969 #define IF_HWASSIST_VLAN_MTU 0x00020000 /* supports VLAN MTU-sized packet (for software VLAN), IFNET_VLAN_MTU */
970
971 /* TCP Segment Offloading support */
972
973 #define IF_HWASSIST_TSO_V4 0x00200000 /* will do TCP Segment offload for IPv4, IFNET_TSO_IPV4 */
974 #define IF_HWASSIST_TSO_V6 0x00400000 /* will do TCP Segment offload for IPv6, IFNET_TSO_IPV6 */
975 #endif /* PRIVATE */
976
977 #ifdef PRIVATE
978 #define IFXNAMSIZ (IFNAMSIZ + 8) /* external name (name + unit) */
979 #define IFNET_NETWORK_ID_LEN 32
980 #endif
981
982 #ifdef BSD_KERNEL_PRIVATE
983 /*
984 * ifnet is private to BSD portion of kernel
985 */
986 #include <sys/mcache.h>
987 #include <sys/tree.h>
988 #include <netinet/in.h>
989 #include <net/if_dl.h>
990 #include <net/classq/if_classq.h>
991 #include <net/if_types.h>
992
993 RB_HEAD(ll_reach_tree, if_llreach); /* define struct ll_reach_tree */
994
995 #if SKYWALK
996 struct nexus_ifnet_ops {
997 void (*ni_finalize)(struct nexus_netif_adapter *, struct ifnet *);
998 void (*ni_reap)(struct nexus_netif_adapter *, struct ifnet *,
999 uint32_t, boolean_t);
1000 errno_t (*ni_dequeue)(struct nexus_netif_adapter *, uint32_t,
1001 uint32_t, uint32_t, classq_pkt_t *, classq_pkt_t *, uint32_t *,
1002 uint32_t *, boolean_t, errno_t);
1003 errno_t (*ni_get_len)(struct nexus_netif_adapter *, uint32_t,
1004 uint32_t *, uint32_t *, errno_t);
1005 };
1006 typedef struct {
1007 uuid_t if_nif_provider;
1008 uuid_t if_nif_instance;
1009 uuid_t if_nif_attach;
1010 } if_nexus_netif, *if_nexus_netif_t;
1011
1012 typedef struct {
1013 uuid_t if_fsw_provider;
1014 uuid_t if_fsw_instance;
1015 uuid_t if_fsw_device;
1016 uint32_t if_fsw_ipaddr_gencnt;
1017 } if_nexus_flowswitch, *if_nexus_flowswitch_t;
1018 #endif /* SKYWALK */
1019
1020 typedef errno_t (*dlil_input_func)(ifnet_t ifp, mbuf_t m_head,
1021 mbuf_t m_tail, const struct ifnet_stat_increment_param *s,
1022 boolean_t poll, struct thread *tp);
1023 typedef errno_t (*dlil_output_func)(ifnet_t interface, mbuf_t data);
1024
1025 typedef u_int8_t ipv6_router_mode_t;
1026
1027 #define if_name(ifp) ifp->if_xname
1028 /*
1029 * Structure defining a network interface.
1030 *
1031 * (Would like to call this struct ``if'', but C isn't PL/1.)
1032 */
1033 struct ifnet {
1034 /*
1035 * Lock (RW or mutex) to protect this data structure (static storage.)
1036 */
1037 decl_lck_rw_data(, if_lock);
1038 void *if_softc; /* pointer to driver state */
1039 const char *if_name; /* name, e.g. ``en'' or ``lo'' */
1040 const char *if_xname; /* external name (name + unit) */
1041 struct if_description if_desc; /* extended description */
1042 TAILQ_ENTRY(ifnet) if_link; /* all struct ifnets are chained */
1043 TAILQ_ENTRY(ifnet) if_detaching_link; /* list of detaching ifnets */
1044 TAILQ_ENTRY(ifnet) if_ordered_link; /* list of ordered ifnets */
1045
1046 decl_lck_mtx_data(, if_ref_lock);
1047 u_int32_t if_refflags; /* see IFRF flags below */
1048 u_int32_t if_refio; /* number of io ops to the underlying driver */
1049 u_int32_t if_threads_pending; /* Threads created but waiting for first run */
1050 u_int32_t if_datamov; /* number of threads moving data */
1051 u_int32_t if_drainers; /* number of draining threads */
1052 u_int32_t if_suspend; /* number of suspend requests */
1053
1054 #define if_list if_link
1055 struct ifaddrhead if_addrhead; /* linked list of addresses per if */
1056 #define if_addrlist if_addrhead
1057 struct ifaddr *if_lladdr; /* link address (first/permanent) */
1058
1059 u_int32_t if_qosmarking_mode; /* generation to use with NECP clients */
1060
1061 int if_pcount; /* number of promiscuous listeners */
1062 struct bpf_if *if_bpf; /* packet filter structure */
1063 u_short if_index; /* numeric abbreviation for this if */
1064 short if_unit; /* sub-unit for lower level driver */
1065 short if_timer; /* time 'til if_watchdog called */
1066 short if_flags; /* up/down, broadcast, etc. */
1067 u_int32_t if_eflags; /* see <net/if.h> */
1068 u_int32_t if_xflags; /* see <net/if.h> */
1069
1070 int if_capabilities; /* interface features & capabilities */
1071 int if_capenable; /* enabled features & capabilities */
1072
1073 void *if_linkmib; /* link-type-specific MIB data */
1074 uint32_t if_linkmiblen; /* length of above data */
1075
1076 struct if_data_internal if_data __attribute__((aligned(8)));
1077
1078 ifnet_family_t if_family; /* value assigned by Apple */
1079 ifnet_subfamily_t if_subfamily; /* value assigned by Apple */
1080 uintptr_t if_family_cookie;
1081 volatile dlil_input_func if_input_dlil;
1082 volatile dlil_output_func if_output_dlil;
1083 volatile ifnet_start_func if_start;
1084 ifnet_output_func if_output;
1085 ifnet_pre_enqueue_func if_pre_enqueue;
1086 ifnet_ctl_func if_output_ctl;
1087 ifnet_input_poll_func if_input_poll;
1088 ifnet_ctl_func if_input_ctl;
1089 ifnet_ioctl_func if_ioctl;
1090 ifnet_set_bpf_tap if_set_bpf_tap;
1091 ifnet_detached_func if_free;
1092 ifnet_demux_func if_demux;
1093 ifnet_event_func if_event;
1094 ifnet_framer_func if_framer_legacy;
1095 ifnet_framer_extended_func if_framer;
1096 ifnet_add_proto_func if_add_proto;
1097 ifnet_del_proto_func if_del_proto;
1098 ifnet_check_multi if_check_multi;
1099 struct proto_hash_entry *if_proto_hash;
1100 ifnet_detached_func if_detach;
1101
1102 u_int32_t if_flowhash; /* interface flow control ID */
1103
1104 decl_lck_mtx_data(, if_start_lock);
1105 u_int32_t if_start_flags; /* see IFSF flags below */
1106 u_int32_t if_start_req;
1107 u_int8_t if_start_embryonic;
1108 u_int8_t if_start_active; /* output is active */
1109 u_int16_t if_start_delayed;
1110 u_int16_t if_start_delay_qlen;
1111 u_int16_t if_start_delay_idle;
1112 u_int64_t if_start_delay_swin;
1113 u_int32_t if_start_delay_cnt;
1114 u_int32_t if_start_delay_timeout; /* nanoseconds */
1115 struct timespec if_start_cycle; /* restart interval */
1116 struct thread *if_start_thread;
1117
1118 struct ifclassq *if_snd; /* transmit queue */
1119 u_int32_t if_output_sched_model; /* tx sched model */
1120
1121 struct if_bandwidths if_output_bw;
1122 struct if_bandwidths if_input_bw;
1123
1124 struct if_latencies if_output_lt;
1125 struct if_latencies if_input_lt;
1126
1127 decl_lck_mtx_data(, if_flt_lock);
1128 u_int32_t if_flt_busy;
1129 u_int32_t if_flt_waiters;
1130 struct ifnet_filter_head if_flt_head;
1131 uint32_t if_flt_non_os_count;
1132 uint32_t if_flt_no_tso_count;
1133
1134 struct ifmultihead if_multiaddrs; /* multicast addresses */
1135 u_int32_t if_updatemcasts; /* mcast addrs need updating */
1136 int if_amcount; /* # of all-multicast reqs */
1137 decl_lck_mtx_data(, if_addrconfig_lock); /* for serializing addr config */
1138 struct in_multi *if_allhostsinm; /* store all-hosts inm for this ifp */
1139
1140 /*
1141 * Opportunistic polling parameters.
1142 */
1143 decl_lck_mtx_data(, if_poll_lock);
1144 struct if_poll_params {
1145 u_int16_t poll_req;
1146 u_int16_t poll_update; /* link update */
1147 u_int32_t poll_flags;
1148 #define IF_POLLF_READY 0x1 /* poll thread is ready */
1149 #define IF_POLLF_RUNNING 0x2 /* poll thread is running/active */
1150 #define IF_POLLF_TERMINATING 0x4 /* poll thread is terminating */
1151 #define IF_POLLF_EMBRYONIC 0x8000 /* poll thread is being setup */
1152 struct timespec poll_cycle; /* poll interval */
1153 struct thread *poll_thread;
1154
1155 ifnet_model_t poll_mode; /* current mode */
1156 struct pktcntr poll_tstats; /* incremental polling statistics */
1157 struct if_rxpoll_stats poll_pstats; /* polling statistics */
1158 struct pktcntr poll_sstats; /* packets and bytes per sampling */
1159 struct timespec poll_mode_holdtime; /* mode holdtime in nsec */
1160 struct timespec poll_mode_lasttime; /* last mode change time in nsec */
1161 struct timespec poll_sample_holdtime; /* sampling holdtime in nsec */
1162 struct timespec poll_sample_lasttime; /* last sampling time in nsec */
1163 struct timespec poll_dbg_lasttime; /* last debug message time in nsec */
1164 } rxpoll_params;
1165 #define if_poll_req rxpoll_params.poll_req
1166 #define if_poll_update rxpoll_params.poll_update
1167 #define if_poll_flags rxpoll_params.poll_flags
1168 #define if_poll_cycle rxpoll_params.poll_cycle
1169 #define if_poll_thread rxpoll_params.poll_thread
1170 #define if_poll_mode rxpoll_params.poll_mode
1171 #define if_poll_tstats rxpoll_params.poll_tstats
1172 #define if_poll_sstats rxpoll_params.poll_sstats
1173 #define if_poll_pstats rxpoll_params.poll_pstats
1174
1175 #define if_poll_mode_holdtime rxpoll_params.poll_mode_holdtime
1176 #define if_poll_mode_lasttime rxpoll_params.poll_mode_lasttime
1177 #define if_poll_sample_holdtime rxpoll_params.poll_sample_holdtime
1178 #define if_poll_sample_lasttime rxpoll_params.poll_sample_lasttime
1179 #define if_poll_dbg_lasttime rxpoll_params.poll_dbg_lasttime
1180
1181 #define if_rxpoll_offreq rxpoll_params.poll_pstats.ifi_poll_off_req
1182 #define if_rxpoll_offerr rxpoll_params.poll_pstats.ifi_poll_off_err
1183 #define if_rxpoll_onreq rxpoll_params.poll_pstats.ifi_poll_on_req
1184 #define if_rxpoll_onerr rxpoll_params.poll_pstats.ifi_poll_on_err
1185 #define if_rxpoll_wavg rxpoll_params.poll_pstats.ifi_poll_wakeups_avg
1186 #define if_rxpoll_wlowat rxpoll_params.poll_pstats.ifi_poll_wakeups_lowat
1187 #define if_rxpoll_whiwat rxpoll_params.poll_pstats.ifi_poll_wakeups_hiwat
1188 #define if_rxpoll_pavg rxpoll_params.poll_pstats.ifi_poll_packets_avg
1189 #define if_rxpoll_pmin rxpoll_params.poll_pstats.ifi_poll_packets_min
1190 #define if_rxpoll_pmax rxpoll_params.poll_pstats.ifi_poll_packets_max
1191 #define if_rxpoll_plowat rxpoll_params.poll_pstats.ifi_poll_packets_lowat
1192 #define if_rxpoll_phiwat rxpoll_params.poll_pstats.ifi_poll_packets_hiwat
1193 #define if_rxpoll_bavg rxpoll_params.poll_pstats.ifi_poll_bytes_avg
1194 #define if_rxpoll_bmin rxpoll_params.poll_pstats.ifi_poll_bytes_min
1195 #define if_rxpoll_bmax rxpoll_params.poll_pstats.ifi_poll_bytes_max
1196 #define if_rxpoll_blowat rxpoll_params.poll_pstats.ifi_poll_bytes_lowat
1197 #define if_rxpoll_bhiwat rxpoll_params.poll_pstats.ifi_poll_bytes_hiwat
1198 #define if_rxpoll_plim rxpoll_params.poll_pstats.ifi_poll_packets_limit
1199 #define if_rxpoll_ival rxpoll_params.poll_pstats.ifi_poll_interval_time
1200
1201 struct dlil_threading_info *if_inp;
1202
1203 /* allocated once along with dlil_ifnet and is never freed */
1204 thread_call_t if_dt_tcall;
1205
1206 struct {
1207 u_int32_t length;
1208 union {
1209 u_char buffer[8];
1210 u_char *ptr;
1211 } u;
1212 } if_broadcast;
1213
1214 #if PF
1215 struct pfi_kif *if_pf_kif;
1216 #endif /* PF */
1217 #if SKYWALK
1218 struct nexus_ifnet_ops *if_na_ops;
1219 struct nexus_netif_adapter *if_na;
1220
1221 /* compat netif attachment */
1222 if_nexus_netif if_nx_netif;
1223
1224 /* flowswitch attachment */
1225 if_nexus_flowswitch if_nx_flowswitch;
1226
1227 /* headroom space to be reserved in tx packets */
1228 uint16_t if_tx_headroom;
1229
1230 /* trailer space to be reserved in tx packets */
1231 uint16_t if_tx_trailer;
1232
1233 /*
1234 * mitigation interval in microseconds for the rx interrupt mitigation
1235 * logic while operating in the high throughput mode.
1236 */
1237 uint32_t if_rx_mit_ival;
1238
1239 ifnet_start_func if_save_start;
1240 ifnet_output_func if_save_output;
1241
1242 /*
1243 * Number of threads waiting for the start callback to be finished;
1244 * access is protected by if_start_lock; also serves as wait channel.
1245 */
1246 uint32_t if_start_waiters;
1247 #endif /* SKYWALK */
1248
1249 decl_lck_mtx_data(, if_cached_route_lock);
1250 u_int32_t if_fwd_cacheok;
1251 struct route if_fwd_route; /* cached forwarding route */
1252 struct route if_src_route; /* cached ipv4 source route */
1253 struct route_in6 if_src_route6; /* cached ipv6 source route */
1254
1255 decl_lck_rw_data(, if_llreach_lock);
1256 struct ll_reach_tree if_ll_srcs; /* source link-layer tree */
1257
1258 void *if_bridge; /* bridge glue */
1259
1260 u_int32_t if_idle_flags; /* idle flags */
1261 u_int32_t if_idle_new_flags; /* temporary idle flags */
1262 u_int32_t if_idle_new_flags_mask; /* temporary mask */
1263 u_int32_t if_route_refcnt; /* idle: route ref count */
1264 u_int32_t if_rt_sendts; /* last of a real time packet */
1265
1266 struct if_traffic_class if_tc __attribute__((aligned(8)));
1267 #if INET
1268 struct igmp_ifinfo *if_igi; /* for IGMPv3 */
1269 #endif /* INET */
1270 struct mld_ifinfo *if_mli; /* for MLDv2 */
1271
1272 struct tcpstat_local *if_tcp_stat; /* TCP specific stats */
1273 struct udpstat_local *if_udp_stat; /* UDP specific stats */
1274
1275 struct {
1276 int32_t level; /* cached logging level */
1277 u_int32_t flags; /* cached logging flags */
1278 int32_t category; /* cached category */
1279 int32_t subcategory; /* cached subcategory */
1280 } if_log;
1281
1282 struct {
1283 struct ifnet *ifp; /* delegated ifp */
1284 u_int32_t type; /* delegated i/f type */
1285 u_int32_t family; /* delegated i/f family */
1286 u_int32_t subfamily; /* delegated i/f sub-family */
1287 uint32_t expensive:1, /* delegated i/f expensive? */
1288 constrained:1; /* delegated i/f constrained? */
1289 } if_delegated;
1290
1291 uuid_t *if_agentids; /* network agents attached to interface */
1292 u_int32_t if_agentcount;
1293
1294 volatile uint32_t if_low_power_gencnt;
1295
1296 u_int32_t if_generation; /* generation to use with NECP clients */
1297 u_int32_t if_fg_sendts; /* last send on a fg socket in seconds */
1298
1299 u_int64_t if_data_threshold;
1300
1301 /* Total bytes in send socket buffer */
1302 int64_t if_sndbyte_total __attribute__ ((aligned(8)));
1303 /* Total unsent bytes in send socket buffer */
1304 int64_t if_sndbyte_unsent __attribute__ ((aligned(8)));
1305 /* count of times, when there was data to send when sleep is impending */
1306 uint32_t if_unsent_data_cnt;
1307
1308 #if INET
1309 decl_lck_rw_data(, if_inetdata_lock);
1310 struct in_ifextra *if_inetdata;
1311 #endif /* INET */
1312 decl_lck_mtx_data(, if_inet6_ioctl_lock);
1313 boolean_t if_inet6_ioctl_busy;
1314 decl_lck_rw_data(, if_inet6data_lock);
1315 struct in6_ifextra *if_inet6data;
1316 decl_lck_rw_data(, if_link_status_lock);
1317 struct if_link_status *if_link_status;
1318 struct if_interface_state if_interface_state;
1319 struct if_tcp_ecn_stat *if_ipv4_stat;
1320 struct if_tcp_ecn_stat *if_ipv6_stat;
1321
1322 #if SKYWALK
1323 /* Keeps track of local ports bound to this interface
1324 * Protected by the global lock in skywalk/netns/netns.c */
1325 SLIST_HEAD(, ns_token) if_netns_tokens;
1326 #endif /* SKYWALK */
1327 struct if_lim_perf_stat if_lim_stat;
1328
1329 uint32_t if_tcp_kao_max;
1330 uint32_t if_tcp_kao_cnt;
1331
1332 #if SKYWALK
1333 struct netem *if_input_netem;
1334 #endif /* SKYWALK */
1335 struct netem *if_output_netem;
1336
1337 ipv6_router_mode_t if_ipv6_router_mode; /* see <netinet6/in6_var.h> */
1338
1339 u_int8_t if_estimated_up_bucket;
1340 u_int8_t if_estimated_down_bucket;
1341 u_int8_t if_radio_type;
1342 u_int8_t if_radio_channel;
1343
1344 uint8_t network_id[IFNET_NETWORK_ID_LEN];
1345 uint8_t network_id_len;
1346 };
1347
1348 /* Interface event handling declarations */
1349 extern struct eventhandler_lists_ctxt ifnet_evhdlr_ctxt;
1350
1351 typedef enum {
1352 INTF_EVENT_CODE_CREATED,
1353 INTF_EVENT_CODE_REMOVED,
1354 INTF_EVENT_CODE_STATUS_UPDATE,
1355 INTF_EVENT_CODE_IPADDR_ATTACHED,
1356 INTF_EVENT_CODE_IPADDR_DETACHED,
1357 INTF_EVENT_CODE_LLADDR_UPDATE,
1358 INTF_EVENT_CODE_MTU_CHANGED,
1359 INTF_EVENT_CODE_LOW_POWER_UPDATE,
1360 } intf_event_code_t;
1361
1362 typedef void (*ifnet_event_fn)(struct eventhandler_entry_arg, struct ifnet *, struct sockaddr *, intf_event_code_t);
1363 EVENTHANDLER_DECLARE(ifnet_event, ifnet_event_fn);
1364
1365 #define IF_TCP_STATINC(_ifp, _s) do { \
1366 if ((_ifp)->if_tcp_stat != NULL) \
1367 atomic_add_64(&(_ifp)->if_tcp_stat->_s, 1); \
1368 } while (0);
1369
1370 #define IF_UDP_STATINC(_ifp, _s) do { \
1371 if ((_ifp)->if_udp_stat != NULL) \
1372 atomic_add_64(&(_ifp)->if_udp_stat->_s, 1); \
1373 } while (0);
1374
1375 /*
1376 * Valid values for if_refflags
1377 */
1378 #define IFRF_EMBRYONIC 0x1 /* ifnet is allocated; awaiting attach */
1379 #define IFRF_ATTACHED 0x2 /* ifnet attach is completely done */
1380 #define IFRF_DETACHING 0x4 /* detach has been requested */
1381 #define IFRF_READY 0x8 /* data path is ready */
1382
1383 #define IFRF_ATTACH_MASK \
1384 (IFRF_EMBRYONIC|IFRF_ATTACHED|IFRF_DETACHING)
1385
1386 #define IF_FULLY_ATTACHED(_ifp) \
1387 (((_ifp)->if_refflags & IFRF_ATTACH_MASK) == IFRF_ATTACHED)
1388
1389 #define IF_FULLY_ATTACHED_AND_READY(_ifp) \
1390 (IF_FULLY_ATTACHED(_ifp) && ((_ifp)->if_refflags & IFRF_READY))
1391 /*
1392 * Valid values for if_start_flags
1393 */
1394 #define IFSF_FLOW_CONTROLLED 0x1 /* flow controlled */
1395 #define IFSF_TERMINATING 0x2 /* terminating */
1396
1397 /*
1398 * Structure describing a `cloning' interface.
1399 */
1400 struct if_clone {
1401 LIST_ENTRY(if_clone) ifc_list; /* on list of cloners */
1402 decl_lck_mtx_data(, ifc_mutex); /* To serialize clone create/delete */
1403 u_int32_t ifc_minifs; /* minimum number of interfaces */
1404 u_int32_t ifc_maxunit; /* maximum unit number */
1405 unsigned char *ifc_units; /* bitmap to handle units */
1406 u_int32_t ifc_bmlen; /* bitmap length */
1407 u_int32_t ifc_zone_max_elem; /* Max elements for this zone type */
1408 u_int32_t ifc_softc_size; /* size of softc for the device */
1409 struct zone *ifc_zone; /* if_clone allocation zone */
1410 int (*ifc_create)(struct if_clone *, u_int32_t, void *);
1411 int (*ifc_destroy)(struct ifnet *);
1412 uint8_t ifc_namelen; /* length of name */
1413 char ifc_name[IFNAMSIZ + 1]; /* name of device, e.g. `vlan' */
1414 };
1415
1416 #define IF_CLONE_INITIALIZER(name, create, destroy, minifs, maxunit, zone_max_elem, softc_size) { \
1417 .ifc_list = { NULL, NULL }, \
1418 .ifc_mutex = {}, \
1419 .ifc_name = name, \
1420 .ifc_namelen = (sizeof (name) - 1), \
1421 .ifc_minifs = minifs, \
1422 .ifc_maxunit = maxunit, \
1423 .ifc_units = NULL, \
1424 .ifc_bmlen = 0, \
1425 .ifc_zone_max_elem = zone_max_elem, \
1426 .ifc_softc_size = softc_size, \
1427 .ifc_zone = NULL, \
1428 .ifc_create = create, \
1429 .ifc_destroy = destroy \
1430 }
1431
1432 /*
1433 * Macros to manipulate ifqueue. Users of these macros are responsible
1434 * for serialization, by holding whatever lock is appropriate for the
1435 * corresponding structure that is referring the ifqueue.
1436 */
1437 #define IF_QFULL(ifq) ((ifq)->ifq_len >= (ifq)->ifq_maxlen)
1438 #define IF_DROP(ifq) ((ifq)->ifq_drops++)
1439
1440 #define IF_ENQUEUE(ifq, m) do { \
1441 (m)->m_nextpkt = NULL; \
1442 if ((ifq)->ifq_tail == NULL) \
1443 (ifq)->ifq_head = m; \
1444 else \
1445 ((struct mbuf*)(ifq)->ifq_tail)->m_nextpkt = m; \
1446 (ifq)->ifq_tail = m; \
1447 (ifq)->ifq_len++; \
1448 } while (0)
1449
1450 #define IF_PREPEND(ifq, m) do { \
1451 (m)->m_nextpkt = (ifq)->ifq_head; \
1452 if ((ifq)->ifq_tail == NULL) \
1453 (ifq)->ifq_tail = (m); \
1454 (ifq)->ifq_head = (m); \
1455 (ifq)->ifq_len++; \
1456 } while (0)
1457
1458 #define IF_DEQUEUE(ifq, m) do { \
1459 (m) = (ifq)->ifq_head; \
1460 if (m != NULL) { \
1461 if (((ifq)->ifq_head = (m)->m_nextpkt) == NULL) \
1462 (ifq)->ifq_tail = NULL; \
1463 (m)->m_nextpkt = NULL; \
1464 (ifq)->ifq_len--; \
1465 } \
1466 } while (0)
1467
1468 #define IF_REMQUEUE(ifq, m) do { \
1469 struct mbuf *_p = (ifq)->ifq_head; \
1470 struct mbuf *_n = (m)->m_nextpkt; \
1471 if ((m) == _p) \
1472 _p = NULL; \
1473 while (_p != NULL) { \
1474 if (_p->m_nextpkt == (m)) \
1475 break; \
1476 _p = _p->m_nextpkt; \
1477 } \
1478 VERIFY(_p != NULL || ((m) == (ifq)->ifq_head)); \
1479 if ((m) == (ifq)->ifq_head) \
1480 (ifq)->ifq_head = _n; \
1481 if ((m) == (ifq)->ifq_tail) \
1482 (ifq)->ifq_tail = _p; \
1483 VERIFY((ifq)->ifq_tail != NULL || (ifq)->ifq_head == NULL); \
1484 VERIFY((ifq)->ifq_len != 0); \
1485 --(ifq)->ifq_len; \
1486 if (_p != NULL) \
1487 _p->m_nextpkt = _n; \
1488 (m)->m_nextpkt = NULL; \
1489 } while (0)
1490
1491 #define IF_DRAIN(ifq) do { \
1492 struct mbuf *_m; \
1493 for (;;) { \
1494 IF_DEQUEUE(ifq, _m); \
1495 if (_m == NULL) \
1496 break; \
1497 m_freem(_m); \
1498 } \
1499 } while (0)
1500
1501 /*
1502 * The ifaddr structure contains information about one address
1503 * of an interface. They are maintained by the different address families,
1504 * are allocated and attached when an address is set, and are linked
1505 * together so all addresses for an interface can be located.
1506 */
1507 struct ifaddr {
1508 decl_lck_mtx_data(, ifa_lock); /* lock for ifaddr */
1509 uint32_t ifa_refcnt; /* ref count, use IFA_{ADD,REM}REF */
1510 uint32_t ifa_debug; /* debug flags */
1511 struct sockaddr *ifa_addr; /* address of interface */
1512 struct sockaddr *ifa_dstaddr; /* other end of p-to-p link */
1513 #define ifa_broadaddr ifa_dstaddr /* broadcast address interface */
1514 struct sockaddr *ifa_netmask; /* used to determine subnet */
1515 struct ifnet *ifa_ifp; /* back-pointer to interface */
1516 TAILQ_ENTRY(ifaddr) ifa_link; /* queue macro glue */
1517 void (*ifa_rtrequest) /* check or clean routes (+ or -)'d */
1518 (int, struct rtentry *, struct sockaddr *);
1519 uint32_t ifa_flags; /* mostly rt_flags for cloning */
1520 int32_t ifa_metric; /* cost of going out this interface */
1521 void (*ifa_free)(struct ifaddr *); /* callback fn for freeing */
1522 void (*ifa_trace) /* callback fn for tracing refs */
1523 (struct ifaddr *, int);
1524 void (*ifa_attached)(struct ifaddr *); /* callback fn for attaching */
1525 void (*ifa_detached)(struct ifaddr *); /* callback fn for detaching */
1526 void *ifa_del_wc; /* Wait channel to avoid address deletion races */
1527 int ifa_del_waiters; /* Threads in wait to delete the address */
1528 #if __arm__ && (__BIGGEST_ALIGNMENT__ > 4)
1529 /* For the newer ARMv7k ABI where 64-bit types are 64-bit aligned, but pointers
1530 * are 32-bit:
1531 * Align to 64-bit since we cast to this to struct in6_ifaddr, which is
1532 * 64-bit aligned
1533 */
1534 } __attribute__ ((aligned(8)));
1535 #else
1536 };
1537 #endif
1538
1539
1540 /*
1541 * Valid values for ifa_flags
1542 */
1543 #define IFA_ROUTE RTF_UP /* route installed (0x1) */
1544 #define IFA_CLONING RTF_CLONING /* (0x100) */
1545
1546 /*
1547 * Valid values for ifa_debug
1548 */
1549 #define IFD_ATTACHED 0x1 /* attached to list */
1550 #define IFD_ALLOC 0x2 /* dynamically allocated */
1551 #define IFD_DEBUG 0x4 /* has debugging info */
1552 #define IFD_LINK 0x8 /* link address */
1553 #define IFD_TRASHED 0x10 /* in trash list */
1554 #define IFD_DETACHING 0x20 /* detach is in progress */
1555 #define IFD_NOTREADY 0x40 /* embryonic; not yet ready */
1556
1557 #define IFA_LOCK_ASSERT_HELD(_ifa) \
1558 LCK_MTX_ASSERT(&(_ifa)->ifa_lock, LCK_MTX_ASSERT_OWNED)
1559
1560 #define IFA_LOCK_ASSERT_NOTHELD(_ifa) \
1561 LCK_MTX_ASSERT(&(_ifa)->ifa_lock, LCK_MTX_ASSERT_NOTOWNED)
1562
1563 #define IFA_LOCK(_ifa) \
1564 lck_mtx_lock(&(_ifa)->ifa_lock)
1565
1566 #define IFA_LOCK_SPIN(_ifa) \
1567 lck_mtx_lock_spin(&(_ifa)->ifa_lock)
1568
1569 #define IFA_CONVERT_LOCK(_ifa) do { \
1570 IFA_LOCK_ASSERT_HELD(_ifa); \
1571 lck_mtx_convert_spin(&(_ifa)->ifa_lock); \
1572 } while (0)
1573
1574 #define IFA_UNLOCK(_ifa) \
1575 lck_mtx_unlock(&(_ifa)->ifa_lock)
1576
1577 #define IFA_ADDREF(_ifa) \
1578 ifa_addref(_ifa, 0)
1579
1580 #define IFA_ADDREF_LOCKED(_ifa) \
1581 ifa_addref(_ifa, 1)
1582
1583 #define IFA_REMREF(_ifa) do { \
1584 (void) ifa_remref(_ifa, 0); \
1585 } while (0)
1586
1587 #define IFA_REMREF_LOCKED(_ifa) \
1588 ifa_remref(_ifa, 1)
1589
1590 /*
1591 * Multicast address structure. This is analogous to the ifaddr
1592 * structure except that it keeps track of multicast addresses.
1593 * Also, the request count here is a count of requests for this
1594 * address, not a count of pointers to this structure; anonymous
1595 * membership(s) holds one outstanding request count.
1596 */
1597 struct ifmultiaddr {
1598 decl_lck_mtx_data(, ifma_lock);
1599 u_int32_t ifma_refcount; /* reference count */
1600 u_int32_t ifma_anoncnt; /* # of anonymous requests */
1601 u_int32_t ifma_reqcnt; /* total requests for this address */
1602 u_int32_t ifma_debug; /* see ifa_debug flags */
1603 u_int32_t ifma_flags; /* see below */
1604 LIST_ENTRY(ifmultiaddr) ifma_link; /* queue macro glue */
1605 struct sockaddr *ifma_addr; /* address this membership is for */
1606 struct ifmultiaddr *ifma_ll; /* link-layer translation, if any */
1607 struct ifnet *ifma_ifp; /* back-pointer to interface */
1608 void *ifma_protospec; /* protocol-specific state, if any */
1609 void (*ifma_trace) /* callback fn for tracing refs */
1610 (struct ifmultiaddr *, int);
1611 };
1612
1613 /*
1614 * Values for ifma_flags
1615 */
1616 #define IFMAF_ANONYMOUS 0x1 /* has anonymous request ref(s) held */
1617
1618 #define IFMA_LOCK_ASSERT_HELD(_ifma) \
1619 LCK_MTX_ASSERT(&(_ifma)->ifma_lock, LCK_MTX_ASSERT_OWNED)
1620
1621 #define IFMA_LOCK_ASSERT_NOTHELD(_ifma) \
1622 LCK_MTX_ASSERT(&(_ifma)->ifma_lock, LCK_MTX_ASSERT_NOTOWNED)
1623
1624 #define IFMA_LOCK(_ifma) \
1625 lck_mtx_lock(&(_ifma)->ifma_lock)
1626
1627 #define IFMA_LOCK_SPIN(_ifma) \
1628 lck_mtx_lock_spin(&(_ifma)->ifma_lock)
1629
1630 #define IFMA_CONVERT_LOCK(_ifma) do { \
1631 IFMA_LOCK_ASSERT_HELD(_ifma); \
1632 lck_mtx_convert_spin(&(_ifma)->ifma_lock); \
1633 } while (0)
1634
1635 #define IFMA_UNLOCK(_ifma) \
1636 lck_mtx_unlock(&(_ifma)->ifma_lock)
1637
1638 #define IFMA_ADDREF(_ifma) \
1639 ifma_addref(_ifma, 0)
1640
1641 #define IFMA_ADDREF_LOCKED(_ifma) \
1642 ifma_addref(_ifma, 1)
1643
1644 #define IFMA_REMREF(_ifma) \
1645 ifma_remref(_ifma)
1646
1647 /*
1648 * Indicate whether or not the immediate interface, or the interface delegated
1649 * by it, is a cellular interface (IFT_CELLULAR). Delegated interface type is
1650 * set/cleared along with the delegated ifp; we cache the type for performance
1651 * to avoid dereferencing delegated ifp each time.
1652 *
1653 * Note that this is meant to be used only for accounting and policy purposes;
1654 * certain places need to explicitly know the immediate interface type, and
1655 * this macro should not be used there.
1656 *
1657 * The test is done against IFT_CELLULAR instead of IFNET_FAMILY_CELLULAR to
1658 * handle certain cases where the family isn't set to the latter.
1659 */
1660 #define IFNET_IS_CELLULAR(_ifp) \
1661 ((_ifp)->if_type == IFT_CELLULAR || \
1662 (_ifp)->if_delegated.type == IFT_CELLULAR)
1663
1664 /*
1665 * Indicate whether or not the immediate interface, or the interface delegated
1666 * by it, is an ETHERNET interface.
1667 */
1668 #define IFNET_IS_ETHERNET(_ifp) \
1669 ((_ifp)->if_family == IFNET_FAMILY_ETHERNET || \
1670 (_ifp)->if_delegated.family == IFNET_FAMILY_ETHERNET)
1671 /*
1672 * Indicate whether or not the immediate interface, or the interface delegated
1673 * by it, is a Wi-Fi interface (IFNET_SUBFAMILY_WIFI). Delegated interface
1674 * subfamily is set/cleared along with the delegated ifp; we cache the subfamily
1675 * for performance to avoid dereferencing delegated ifp each time.
1676 *
1677 * Note that this is meant to be used only for accounting and policy purposes;
1678 * certain places need to explicitly know the immediate interface type, and
1679 * this macro should not be used there.
1680 *
1681 * The test is done against IFNET_SUBFAMILY_WIFI as the family may be set to
1682 * IFNET_FAMILY_ETHERNET (as well as type to IFT_ETHER) which is too generic.
1683 */
1684 #define IFNET_IS_WIFI(_ifp) \
1685 (((_ifp)->if_family == IFNET_FAMILY_ETHERNET && \
1686 (_ifp)->if_subfamily == IFNET_SUBFAMILY_WIFI) || \
1687 ((_ifp)->if_delegated.family == IFNET_FAMILY_ETHERNET && \
1688 (_ifp)->if_delegated.subfamily == IFNET_SUBFAMILY_WIFI))
1689
1690 /*
1691 * Indicate whether or not the immediate interface, or the interface delegated
1692 * by it, is a Wired interface (several families). Delegated interface
1693 * family is set/cleared along with the delegated ifp; we cache the family
1694 * for performance to avoid dereferencing delegated ifp each time.
1695 *
1696 * Note that this is meant to be used only for accounting and policy purposes;
1697 * certain places need to explicitly know the immediate interface type, and
1698 * this macro should not be used there.
1699 */
1700 #define IFNET_IS_WIRED(_ifp) \
1701 ((_ifp)->if_family == IFNET_FAMILY_ETHERNET || \
1702 (_ifp)->if_delegated.family == IFNET_FAMILY_ETHERNET || \
1703 (_ifp)->if_family == IFNET_FAMILY_FIREWIRE || \
1704 (_ifp)->if_delegated.family == IFNET_FAMILY_FIREWIRE)
1705
1706 /*
1707 * Indicate whether or not the immediate WiFi interface is on an infrastructure
1708 * network
1709 */
1710 #define IFNET_IS_WIFI_INFRA(_ifp) \
1711 ((_ifp)->if_family == IFNET_FAMILY_ETHERNET && \
1712 (_ifp)->if_subfamily == IFNET_SUBFAMILY_WIFI && \
1713 !((_ifp)->if_eflags & IFEF_AWDL) && \
1714 !((_ifp)->if_xflags & IFXF_LOW_LATENCY))
1715
1716 /*
1717 * Indicate whether or not the immediate interface is a companion link
1718 * interface.
1719 */
1720 #define IFNET_IS_COMPANION_LINK(_ifp) \
1721 ((_ifp)->if_family == IFNET_FAMILY_IPSEC && \
1722 ((_ifp)->if_subfamily == IFNET_SUBFAMILY_BLUETOOTH || \
1723 (_ifp)->if_subfamily == IFNET_SUBFAMILY_WIFI || \
1724 (_ifp)->if_subfamily == IFNET_SUBFAMILY_QUICKRELAY || \
1725 (_ifp)->if_subfamily == IFNET_SUBFAMILY_DEFAULT))
1726
1727 /*
1728 * Indicate whether or not the immediate interface, or the interface delegated
1729 * by it, is marked as expensive. The delegated interface is set/cleared
1730 * along with the delegated ifp; we cache the flag for performance to avoid
1731 * dereferencing delegated ifp each time.
1732 *
1733 * Note that this is meant to be used only for policy purposes.
1734 */
1735 #define IFNET_IS_EXPENSIVE(_ifp) \
1736 ((_ifp)->if_eflags & IFEF_EXPENSIVE || \
1737 (_ifp)->if_delegated.expensive)
1738
1739 #define IFNET_IS_LOW_POWER(_ifp) \
1740 (if_low_power_restricted != 0 && \
1741 ((_ifp)->if_xflags & IFXF_LOW_POWER) || \
1742 ((_ifp)->if_delegated.ifp != NULL && \
1743 ((_ifp)->if_delegated.ifp->if_xflags & IFXF_LOW_POWER)))
1744
1745 #define IFNET_IS_CONSTRAINED(_ifp) \
1746 ((_ifp)->if_xflags & IFXF_CONSTRAINED || \
1747 (_ifp)->if_delegated.constrained)
1748
1749 /*
1750 * We don't support AWDL interface delegation.
1751 */
1752 #define IFNET_IS_AWDL_RESTRICTED(_ifp) \
1753 (((_ifp)->if_eflags & (IFEF_AWDL|IFEF_AWDL_RESTRICTED)) == \
1754 (IFEF_AWDL|IFEF_AWDL_RESTRICTED))
1755
1756 #define IFNET_IS_INTCOPROC(_ifp) \
1757 ((_ifp)->if_family == IFNET_FAMILY_ETHERNET && \
1758 (_ifp)->if_subfamily == IFNET_SUBFAMILY_INTCOPROC)
1759
1760 #define IFNET_IS_VMNET(_ifp) \
1761 ((_ifp)->if_family == IFNET_FAMILY_ETHERNET && \
1762 (_ifp)->if_subfamily == IFNET_SUBFAMILY_VMNET)
1763 /*
1764 * Indicate whether or not the immediate interface is IP over Thunderbolt.
1765 */
1766 #define IFNET_IS_THUNDERBOLT_IP(_ifp) \
1767 ((_ifp)->if_family == IFNET_FAMILY_ETHERNET && \
1768 (_ifp)->if_subfamily == IFNET_SUBFAMILY_THUNDERBOLT)
1769
1770 extern struct ifnethead ifnet_head;
1771 extern struct ifnethead ifnet_ordered_head;
1772 extern struct ifnet **ifindex2ifnet;
1773 extern u_int32_t if_sndq_maxlen;
1774 extern u_int32_t if_rcvq_maxlen;
1775 extern int if_index;
1776 extern struct ifaddr **ifnet_addrs;
1777 extern lck_attr_t ifa_mtx_attr;
1778 extern lck_grp_t ifa_mtx_grp;
1779 extern lck_grp_t ifnet_lock_group;
1780 extern lck_attr_t ifnet_lock_attr;
1781 extern ifnet_t lo_ifp;
1782 extern uint32_t net_wake_pkt_debug;
1783
1784 extern int if_addmulti(struct ifnet *, const struct sockaddr *,
1785 struct ifmultiaddr **);
1786 extern int if_addmulti_anon(struct ifnet *, const struct sockaddr *,
1787 struct ifmultiaddr **);
1788 extern int if_allmulti(struct ifnet *, int);
1789 extern int if_delmulti(struct ifnet *, const struct sockaddr *);
1790 extern int if_delmulti_ifma(struct ifmultiaddr *);
1791 extern int if_delmulti_anon(struct ifnet *, const struct sockaddr *);
1792 extern void if_down(struct ifnet *);
1793 extern int if_down_all(void);
1794 extern void if_up(struct ifnet *);
1795 __private_extern__ void if_updown(struct ifnet *ifp, int up);
1796 extern int ifioctl(struct socket *, u_long, caddr_t, struct proc *);
1797 extern int ifioctllocked(struct socket *, u_long, caddr_t, struct proc *);
1798 extern struct ifnet *ifunit(const char *);
1799 extern struct ifnet *ifunit_ref(const char *);
1800 extern int ifunit_extract(const char *src, char *dst, size_t dstlen, int *unit);
1801 extern struct ifnet *if_withname(struct sockaddr *);
1802 extern void if_qflush(struct ifnet *, struct ifclassq *, bool);
1803 extern void if_qflush_snd(struct ifnet *, bool);
1804 extern void if_qflush_sc(struct ifnet *, mbuf_svc_class_t, u_int32_t,
1805 u_int32_t *, u_int32_t *, int);
1806
1807 extern struct if_clone *if_clone_lookup(const char *, u_int32_t *);
1808 extern int if_clone_attach(struct if_clone *);
1809 extern void if_clone_detach(struct if_clone *);
1810 extern void *if_clone_softc_allocate(const struct if_clone *);
1811 extern void if_clone_softc_deallocate(const struct if_clone *, void *);
1812 extern u_int32_t if_functional_type(struct ifnet *, bool);
1813
1814 extern errno_t if_mcasts_update(struct ifnet *);
1815
1816 typedef enum {
1817 IFNET_LCK_ASSERT_EXCLUSIVE, /* RW: held as writer */
1818 IFNET_LCK_ASSERT_SHARED, /* RW: held as reader */
1819 IFNET_LCK_ASSERT_OWNED, /* RW: writer/reader, MTX: held */
1820 IFNET_LCK_ASSERT_NOTOWNED /* not held */
1821 } ifnet_lock_assert_t;
1822
1823 #define IF_LLADDR(_ifp) \
1824 (LLADDR(SDL(((_ifp)->if_lladdr)->ifa_addr)))
1825
1826 #define IF_INDEX_IN_RANGE(_ind_) ((_ind_) > 0 && \
1827 (unsigned int)(_ind_) <= (unsigned int)if_index)
1828
1829 __private_extern__ void ifnet_lock_assert(struct ifnet *, ifnet_lock_assert_t);
1830 __private_extern__ void ifnet_lock_shared(struct ifnet *ifp);
1831 __private_extern__ void ifnet_lock_exclusive(struct ifnet *ifp);
1832 __private_extern__ void ifnet_lock_done(struct ifnet *ifp);
1833
1834 #if INET
1835 __private_extern__ void if_inetdata_lock_shared(struct ifnet *ifp);
1836 __private_extern__ void if_inetdata_lock_exclusive(struct ifnet *ifp);
1837 __private_extern__ void if_inetdata_lock_done(struct ifnet *ifp);
1838 #endif
1839
1840 __private_extern__ void if_inet6data_lock_shared(struct ifnet *ifp);
1841 __private_extern__ void if_inet6data_lock_exclusive(struct ifnet *ifp);
1842 __private_extern__ void if_inet6data_lock_done(struct ifnet *ifp);
1843
1844 __private_extern__ void ifnet_head_lock_shared(void);
1845 __private_extern__ void ifnet_head_lock_exclusive(void);
1846 __private_extern__ void ifnet_head_done(void);
1847 __private_extern__ void ifnet_head_assert_exclusive(void);
1848
1849 __private_extern__ errno_t ifnet_set_idle_flags_locked(ifnet_t, u_int32_t,
1850 u_int32_t);
1851 __private_extern__ int ifnet_is_attached(struct ifnet *, int refio);
1852 __private_extern__ void ifnet_incr_pending_thread_count(struct ifnet *);
1853 __private_extern__ void ifnet_decr_pending_thread_count(struct ifnet *);
1854 __private_extern__ void ifnet_incr_iorefcnt(struct ifnet *);
1855 __private_extern__ void ifnet_decr_iorefcnt(struct ifnet *);
1856 __private_extern__ boolean_t ifnet_datamov_begin(struct ifnet *);
1857 __private_extern__ void ifnet_datamov_end(struct ifnet *);
1858 __private_extern__ void ifnet_datamov_suspend(struct ifnet *);
1859 __private_extern__ boolean_t ifnet_datamov_suspend_if_needed(struct ifnet *);
1860 __private_extern__ void ifnet_datamov_drain(struct ifnet *);
1861 __private_extern__ void ifnet_datamov_suspend_and_drain(struct ifnet *);
1862 __private_extern__ void ifnet_datamov_resume(struct ifnet *);
1863 __private_extern__ void ifnet_set_start_cycle(struct ifnet *,
1864 struct timespec *);
1865 __private_extern__ void ifnet_set_poll_cycle(struct ifnet *,
1866 struct timespec *);
1867
1868 __private_extern__ void if_attach_ifa(struct ifnet *, struct ifaddr *);
1869 __private_extern__ void if_attach_link_ifa(struct ifnet *, struct ifaddr *);
1870 __private_extern__ void if_detach_ifa(struct ifnet *, struct ifaddr *);
1871 __private_extern__ void if_detach_link_ifa(struct ifnet *, struct ifaddr *);
1872
1873 __private_extern__ void dlil_if_lock(void);
1874 __private_extern__ void dlil_if_unlock(void);
1875 __private_extern__ void dlil_if_lock_assert(void);
1876
1877 extern struct ifaddr *ifa_ifwithaddr(const struct sockaddr *);
1878 extern struct ifaddr *ifa_ifwithaddr_locked(const struct sockaddr *);
1879 extern struct ifaddr *ifa_ifwithaddr_scoped(const struct sockaddr *,
1880 unsigned int);
1881 extern struct ifaddr *ifa_ifwithaddr_scoped_locked(const struct sockaddr *,
1882 unsigned int);
1883 extern struct ifaddr *ifa_ifwithdstaddr(const struct sockaddr *);
1884 extern struct ifaddr *ifa_ifwithnet(const struct sockaddr *);
1885 extern struct ifaddr *ifa_ifwithnet_scoped(const struct sockaddr *,
1886 unsigned int);
1887 extern struct ifaddr *ifa_ifwithroute(int, const struct sockaddr *,
1888 const struct sockaddr *);
1889 extern struct ifaddr *ifa_ifwithroute_locked(int, const struct sockaddr *,
1890 const struct sockaddr *);
1891 extern struct ifaddr *ifa_ifwithroute_scoped_locked(int,
1892 const struct sockaddr *, const struct sockaddr *, unsigned int);
1893 extern struct ifaddr *ifaof_ifpforaddr_select(const struct sockaddr *, struct ifnet *);
1894 extern struct ifaddr *ifaof_ifpforaddr(const struct sockaddr *, struct ifnet *);
1895 __private_extern__ struct ifaddr *ifa_ifpgetprimary(struct ifnet *, int);
1896 extern void ifa_addref(struct ifaddr *, int);
1897 extern struct ifaddr *ifa_remref(struct ifaddr *, int);
1898 extern void ifa_lock_init(struct ifaddr *);
1899 extern void ifa_lock_destroy(struct ifaddr *);
1900 extern void ifma_addref(struct ifmultiaddr *, int);
1901 extern void ifma_remref(struct ifmultiaddr *);
1902
1903 extern void ifa_init(void);
1904
1905 __private_extern__ struct in_ifaddr *ifa_foraddr(unsigned int);
1906 __private_extern__ struct in_ifaddr *ifa_foraddr_scoped(unsigned int,
1907 unsigned int);
1908
1909 struct ifreq;
1910 extern errno_t ifnet_getset_opportunistic(struct ifnet *, u_long,
1911 struct ifreq *, struct proc *);
1912 extern int ifnet_get_throttle(struct ifnet *, u_int32_t *);
1913 extern int ifnet_set_throttle(struct ifnet *, u_int32_t);
1914 extern errno_t ifnet_getset_log(struct ifnet *, u_long,
1915 struct ifreq *, struct proc *);
1916 extern int ifnet_set_log(struct ifnet *, int32_t, uint32_t, int32_t, int32_t);
1917 extern int ifnet_get_log(struct ifnet *, int32_t *, uint32_t *, int32_t *,
1918 int32_t *);
1919 extern int ifnet_notify_address(struct ifnet *, int);
1920 extern void ifnet_notify_data_threshold(struct ifnet *);
1921
1922 #define IF_AFDATA_RLOCK if_afdata_rlock
1923 #define IF_AFDATA_RUNLOCK if_afdata_unlock
1924 #define IF_AFDATA_WLOCK if_afdata_wlock
1925 #define IF_AFDATA_WUNLOCK if_afdata_unlock
1926 #define IF_AFDATA_WLOCK_ASSERT if_afdata_wlock_assert
1927 #define IF_AFDATA_LOCK_ASSERT if_afdata_lock_assert
1928 #define IF_AFDATA_UNLOCK_ASSERT if_afdata_unlock_assert
1929
1930 static inline void
if_afdata_rlock(struct ifnet * ifp,int af)1931 if_afdata_rlock(struct ifnet *ifp, int af)
1932 {
1933 switch (af) {
1934 #if INET
1935 case AF_INET:
1936 lck_rw_lock_shared(&ifp->if_inetdata_lock);
1937 break;
1938 #endif
1939 case AF_INET6:
1940 lck_rw_lock_shared(&ifp->if_inet6data_lock);
1941 break;
1942 default:
1943 VERIFY(0);
1944 /* NOTREACHED */
1945 }
1946 return;
1947 }
1948
1949 static inline void
if_afdata_runlock(struct ifnet * ifp,int af)1950 if_afdata_runlock(struct ifnet *ifp, int af)
1951 {
1952 switch (af) {
1953 #if INET
1954 case AF_INET:
1955 lck_rw_done(&ifp->if_inetdata_lock);
1956 break;
1957 #endif
1958 case AF_INET6:
1959 lck_rw_done(&ifp->if_inet6data_lock);
1960 break;
1961 default:
1962 VERIFY(0);
1963 /* NOTREACHED */
1964 }
1965 return;
1966 }
1967
1968 static inline void
if_afdata_wlock(struct ifnet * ifp,int af)1969 if_afdata_wlock(struct ifnet *ifp, int af)
1970 {
1971 switch (af) {
1972 #if INET
1973 case AF_INET:
1974 lck_rw_lock_exclusive(&ifp->if_inetdata_lock);
1975 break;
1976 #endif
1977 case AF_INET6:
1978 lck_rw_lock_exclusive(&ifp->if_inet6data_lock);
1979 break;
1980 default:
1981 VERIFY(0);
1982 /* NOTREACHED */
1983 }
1984 return;
1985 }
1986
1987 static inline void
if_afdata_unlock(struct ifnet * ifp,int af)1988 if_afdata_unlock(struct ifnet *ifp, int af)
1989 {
1990 switch (af) {
1991 #if INET
1992 case AF_INET:
1993 lck_rw_done(&ifp->if_inetdata_lock);
1994 break;
1995 #endif
1996 case AF_INET6:
1997 lck_rw_done(&ifp->if_inet6data_lock);
1998 break;
1999 default:
2000 VERIFY(0);
2001 /* NOTREACHED */
2002 }
2003 return;
2004 }
2005
2006 static inline void
if_afdata_wlock_assert(struct ifnet * ifp,int af)2007 if_afdata_wlock_assert(struct ifnet *ifp, int af)
2008 {
2009 #if !MACH_ASSERT
2010 #pragma unused(ifp)
2011 #endif
2012 switch (af) {
2013 #if INET
2014 case AF_INET:
2015 LCK_RW_ASSERT(&ifp->if_inetdata_lock, LCK_RW_ASSERT_EXCLUSIVE);
2016 break;
2017 #endif
2018 case AF_INET6:
2019 LCK_RW_ASSERT(&ifp->if_inet6data_lock, LCK_RW_ASSERT_EXCLUSIVE);
2020 break;
2021 default:
2022 VERIFY(0);
2023 /* NOTREACHED */
2024 }
2025 return;
2026 }
2027
2028 static inline void
if_afdata_unlock_assert(struct ifnet * ifp,int af)2029 if_afdata_unlock_assert(struct ifnet *ifp, int af)
2030 {
2031 #if !MACH_ASSERT
2032 #pragma unused(ifp)
2033 #endif
2034 switch (af) {
2035 #if INET
2036 case AF_INET:
2037 LCK_RW_ASSERT(&ifp->if_inetdata_lock, LCK_RW_ASSERT_NOTHELD);
2038 break;
2039 #endif
2040 case AF_INET6:
2041 LCK_RW_ASSERT(&ifp->if_inet6data_lock, LCK_RW_ASSERT_NOTHELD);
2042 break;
2043 default:
2044 VERIFY(0);
2045 /* NOTREACHED */
2046 }
2047 return;
2048 }
2049
2050 static inline void
if_afdata_lock_assert(struct ifnet * ifp,int af)2051 if_afdata_lock_assert(struct ifnet *ifp, int af)
2052 {
2053 #if !MACH_ASSERT
2054 #pragma unused(ifp)
2055 #endif
2056 switch (af) {
2057 #if INET
2058 case AF_INET:
2059 LCK_RW_ASSERT(&ifp->if_inetdata_lock, LCK_RW_ASSERT_HELD);
2060 break;
2061 #endif
2062 case AF_INET6:
2063 LCK_RW_ASSERT(&ifp->if_inet6data_lock, LCK_RW_ASSERT_HELD);
2064 break;
2065 default:
2066 VERIFY(0);
2067 /* NOTREACHED */
2068 }
2069 return;
2070 }
2071
2072 struct in6_addr;
2073 __private_extern__ struct in6_ifaddr *ifa_foraddr6(struct in6_addr *);
2074 __private_extern__ struct in6_ifaddr *ifa_foraddr6_scoped(struct in6_addr *,
2075 unsigned int);
2076
2077 __private_extern__ void if_data_internal_to_if_data(struct ifnet *ifp,
2078 const struct if_data_internal *if_data_int, struct if_data *if_data);
2079 __private_extern__ void if_data_internal_to_if_data64(struct ifnet *ifp,
2080 const struct if_data_internal *if_data_int, struct if_data64 *if_data64);
2081 __private_extern__ void if_copy_traffic_class(struct ifnet *ifp,
2082 struct if_traffic_class *if_tc);
2083 __private_extern__ void if_copy_data_extended(struct ifnet *ifp,
2084 struct if_data_extended *if_de);
2085 __private_extern__ void if_copy_packet_stats(struct ifnet *ifp,
2086 struct if_packet_stats *if_ps);
2087 __private_extern__ void if_copy_rxpoll_stats(struct ifnet *ifp,
2088 struct if_rxpoll_stats *if_rs);
2089 __private_extern__ void if_copy_netif_stats(struct ifnet *ifp,
2090 struct if_netif_stats *if_ns);
2091
2092 __private_extern__ struct rtentry *ifnet_cached_rtlookup_inet(struct ifnet *,
2093 struct in_addr);
2094 __private_extern__ struct rtentry *ifnet_cached_rtlookup_inet6(struct ifnet *,
2095 struct in6_addr *);
2096
2097 __private_extern__ u_int32_t if_get_protolist(struct ifnet * ifp,
2098 u_int32_t *protolist, u_int32_t count);
2099 __private_extern__ void if_free_protolist(u_int32_t *list);
2100 __private_extern__ errno_t if_state_update(struct ifnet *,
2101 struct if_interface_state *);
2102 __private_extern__ void if_get_state(struct ifnet *,
2103 struct if_interface_state *);
2104 __private_extern__ errno_t if_probe_connectivity(struct ifnet *ifp,
2105 u_int32_t conn_probe);
2106 __private_extern__ void if_lqm_update(struct ifnet *, int32_t, int);
2107 __private_extern__ void ifnet_update_sndq(struct ifclassq *, cqev_t);
2108 __private_extern__ void ifnet_update_rcv(struct ifnet *, cqev_t);
2109
2110 __private_extern__ void ifnet_flowadv(uint32_t);
2111
2112 __private_extern__ errno_t ifnet_set_input_bandwidths(struct ifnet *,
2113 struct if_bandwidths *);
2114 __private_extern__ errno_t ifnet_set_output_bandwidths(struct ifnet *,
2115 struct if_bandwidths *, boolean_t);
2116 __private_extern__ u_int64_t ifnet_output_linkrate(struct ifnet *);
2117 __private_extern__ u_int64_t ifnet_input_linkrate(struct ifnet *);
2118
2119 __private_extern__ errno_t ifnet_set_input_latencies(struct ifnet *,
2120 struct if_latencies *);
2121 __private_extern__ errno_t ifnet_set_output_latencies(struct ifnet *,
2122 struct if_latencies *, boolean_t);
2123
2124 __private_extern__ void ifnet_clear_netagent(uuid_t);
2125
2126 __private_extern__ int ifnet_set_netsignature(struct ifnet *, uint8_t,
2127 uint8_t, uint16_t, uint8_t *);
2128 __private_extern__ int ifnet_get_netsignature(struct ifnet *, uint8_t,
2129 uint8_t *, uint16_t *, uint8_t *);
2130
2131 struct ipv6_prefix;
2132 __private_extern__ int ifnet_set_nat64prefix(struct ifnet *,
2133 struct ipv6_prefix *);
2134 __private_extern__ int ifnet_get_nat64prefix(struct ifnet *,
2135 struct ipv6_prefix *);
2136
2137 /* Required exclusive ifnet_head lock */
2138 __private_extern__ void ifnet_remove_from_ordered_list(struct ifnet *);
2139
2140 __private_extern__ void ifnet_increment_generation(struct ifnet *);
2141 __private_extern__ u_int32_t ifnet_get_generation(struct ifnet *);
2142
2143 /* Adding and deleting netagents will take ifnet lock */
2144 __private_extern__ int if_add_netagent(struct ifnet *, uuid_t);
2145 __private_extern__ int if_add_netagent_locked(struct ifnet *, uuid_t);
2146 __private_extern__ int if_delete_netagent(struct ifnet *, uuid_t);
2147 __private_extern__ boolean_t if_check_netagent(struct ifnet *, uuid_t);
2148
2149 #if SKYWALK
2150 extern unsigned int if_enable_fsw_ip_netagent;
2151 static inline boolean_t
if_is_fsw_ip_netagent_enabled(void)2152 if_is_fsw_ip_netagent_enabled(void)
2153 {
2154 return if_enable_fsw_ip_netagent != 0;
2155 }
2156 extern unsigned int if_enable_fsw_transport_netagent;
2157 static inline boolean_t
if_is_fsw_transport_netagent_enabled(void)2158 if_is_fsw_transport_netagent_enabled(void)
2159 {
2160 return if_enable_fsw_transport_netagent != 0;
2161 }
2162 static inline boolean_t
if_is_fsw_netagent_enabled(void)2163 if_is_fsw_netagent_enabled(void)
2164 {
2165 return if_is_fsw_transport_netagent_enabled() ||
2166 if_is_fsw_ip_netagent_enabled();
2167 }
2168 #endif /* SKYWALK */
2169
2170 extern int if_set_qosmarking_mode(struct ifnet *, u_int32_t);
2171 __private_extern__ uint32_t ifnet_mbuf_packetpreamblelen(struct ifnet *);
2172 __private_extern__ void intf_event_enqueue_nwk_wq_entry(struct ifnet *ifp,
2173 struct sockaddr *addrp, uint32_t intf_event_code);
2174 __private_extern__ void ifnet_update_stats_per_flow(struct ifnet_stats_per_flow *,
2175 struct ifnet *);
2176 __private_extern__ int if_get_tcp_kao_max(struct ifnet *);
2177 #if XNU_TARGET_OS_OSX
2178 __private_extern__ errno_t ifnet_framer_stub(struct ifnet *, struct mbuf **,
2179 const struct sockaddr *, const char *, const char *, u_int32_t *,
2180 u_int32_t *);
2181 #endif /* XNU_TARGET_OS_OSX */
2182 __private_extern__ void ifnet_enqueue_multi_setup(struct ifnet *, uint16_t,
2183 uint16_t);
2184 __private_extern__ errno_t ifnet_enqueue_mbuf(struct ifnet *, struct mbuf *,
2185 boolean_t, boolean_t *);
2186 __private_extern__ errno_t ifnet_enqueue_mbuf_chain(struct ifnet *,
2187 struct mbuf *, struct mbuf *, uint32_t, uint32_t, boolean_t, boolean_t *);
2188 __private_extern__ int ifnet_enqueue_netem(void *handle, pktsched_pkt_t *pkts,
2189 uint32_t n_pkts);
2190 #if SKYWALK
2191 struct __kern_packet;
2192 extern errno_t ifnet_enqueue_pkt(struct ifnet *,
2193 struct __kern_packet *, boolean_t, boolean_t *);
2194 extern errno_t ifnet_enqueue_ifcq_pkt(struct ifnet *, struct ifclassq *,
2195 struct __kern_packet *, boolean_t, boolean_t *);
2196 extern errno_t ifnet_enqueue_pkt_chain(struct ifnet *, struct __kern_packet *,
2197 struct __kern_packet *, uint32_t, uint32_t, boolean_t, boolean_t *);
2198 extern errno_t ifnet_set_output_handler(struct ifnet *, ifnet_output_func);
2199 extern void ifnet_reset_output_handler(struct ifnet *);
2200 extern errno_t ifnet_set_start_handler(struct ifnet *, ifnet_start_func);
2201 extern void ifnet_reset_start_handler(struct ifnet *);
2202
2203 #define SK_NXS_MS_IF_ADDR_GENCNT_INC(ifp) \
2204 atomic_add_32(&(ifp)->if_nx_flowswitch.if_fsw_ipaddr_gencnt, 1);
2205 #endif /* SKYWALK */
2206
2207 extern int if_low_power_verbose;
2208 extern int if_low_power_restricted;
2209 extern void if_low_power_evhdlr_init(void);
2210 extern int if_set_low_power(struct ifnet *, bool);
2211 extern u_int32_t if_set_eflags(ifnet_t, u_int32_t);
2212 extern void if_clear_eflags(ifnet_t, u_int32_t);
2213 extern u_int32_t if_set_xflags(ifnet_t, u_int32_t);
2214 extern void if_clear_xflags(ifnet_t, u_int32_t);
2215
2216 #endif /* BSD_KERNEL_PRIVATE */
2217 #ifdef XNU_KERNEL_PRIVATE
2218 /* for uuid.c */
2219 __private_extern__ int uuid_get_ethernet(u_int8_t *);
2220 #endif /* XNU_KERNEL_PRIVATE */
2221 #endif /* DRIVERKIT */
2222 #endif /* !_NET_IF_VAR_H_ */
2223