2 * Copyright (c) 2000-2020 Apple Inc. All rights reserved.
4 * @APPLE_OSREFERENCE_LICENSE_HEADER_START@
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.
15 * Please obtain a copy of the License at
16 * http://www.opensource.apple.com/apsl/ and read it before using this file.
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.
26 * @APPLE_OSREFERENCE_LICENSE_HEADER_END@
29 * Copyright (c) 1982, 1986, 1989, 1993
30 * The Regents of the University of California. All rights reserved.
32 * Redistribution and use in source and binary forms, with or without
33 * modification, are permitted provided that the following conditions
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.
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
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 $
64 #ifndef _NET_IF_VAR_H_
65 #define _NET_IF_VAR_H_
67 #include <sys/appleapiopts.h>
69 #include <sys/types.h>
71 #include <sys/queue.h> /* get TAILQ macros */
73 #include <kern/locks.h>
74 #endif /* KERNEL_PRIVATE */
76 #include <net/route.h>
78 #ifdef BSD_KERN_PRIVATE
79 #include <net/pktsched/pktsched.h>
80 #include <sys/eventhandler.h>
84 #include <net/kpi_interface.h>
88 #define APPLE_IF_FAM_LOOPBACK 1
89 #define APPLE_IF_FAM_ETHERNET 2
90 #define APPLE_IF_FAM_SLIP 3
91 #define APPLE_IF_FAM_TUN 4
92 #define APPLE_IF_FAM_VLAN 5
93 #define APPLE_IF_FAM_PPP 6
94 #define APPLE_IF_FAM_PVC 7
95 #define APPLE_IF_FAM_DISC 8
96 #define APPLE_IF_FAM_MDECAP 9
97 #define APPLE_IF_FAM_GIF 10
98 #define APPLE_IF_FAM_FAITH 11 /* deprecated */
99 #define APPLE_IF_FAM_STF 12
100 #define APPLE_IF_FAM_FIREWIRE 13
101 #define APPLE_IF_FAM_BOND 14
102 #define APPLE_IF_FAM_CELLULAR 15
103 #define APPLE_IF_FAM_6LOWPAN 16
104 #define APPLE_IF_FAM_UTUN 17
105 #define APPLE_IF_FAM_IPSEC 18
106 #endif /* __APPLE__ */
109 * 72 was chosen below because it is the size of a TCP/IP
110 * header (40) + the minimum mss (32).
113 #define IF_MAXMTU 65535
116 * Structures defining a network interface, providing a packet
117 * transport mechanism (ala level 0 of the PUP protocols).
119 * Each interface accepts output datagrams of a specified maximum
120 * length, and provides higher level routines with input datagrams
121 * received from its medium.
123 * Output occurs when the routine if_output is called, with three parameters:
124 * (*ifp->if_output)(ifp, m, dst, rt)
125 * Here m is the mbuf chain to be sent and dst is the destination address.
126 * The output routine encapsulates the supplied datagram if necessary,
127 * and then transmits it on its medium.
129 * On input, each interface unwraps the data received by it, and either
130 * places it on the input queue of a internetwork datagram routine
131 * and posts the associated software interrupt, or passes the datagram to a raw
132 * packet input routine.
134 * Routines exist for locating interfaces by their addresses
135 * or for locating a interface on a certain network, as well as more general
136 * routing and gateway routines maintaining information used to locate
137 * interfaces. These routines live in the files if.c and route.c
142 /* This belongs up in socket.h or socketvar.h, depending on how far the
146 struct net_event_data
{
149 char if_name
[IFNAMSIZ
];
152 #if defined(__LP64__)
153 #include <sys/_types/_timeval32.h>
154 #define IF_DATA_TIMEVAL timeval32
156 #define IF_DATA_TIMEVAL timeval
162 * Structure describing information about an interface
163 * which may be of interest to management entities.
166 /* generic interface information */
167 u_char ifi_type
; /* ethernet, tokenring, etc */
168 u_char ifi_typelen
; /* Length of frame type id */
169 u_char ifi_physical
; /* e.g., AUI, Thinnet, 10base-T, etc */
170 u_char ifi_addrlen
; /* media address length */
171 u_char ifi_hdrlen
; /* media header length */
172 u_char ifi_recvquota
; /* polling quota for receive intrs */
173 u_char ifi_xmitquota
; /* polling quota for xmit intrs */
174 u_char ifi_unused1
; /* for future use */
175 u_int32_t ifi_mtu
; /* maximum transmission unit */
176 u_int32_t ifi_metric
; /* routing metric (external only) */
177 u_int32_t ifi_baudrate
; /* linespeed */
178 /* volatile statistics */
179 u_int32_t ifi_ipackets
; /* packets received on interface */
180 u_int32_t ifi_ierrors
; /* input errors on interface */
181 u_int32_t ifi_opackets
; /* packets sent on interface */
182 u_int32_t ifi_oerrors
; /* output errors on interface */
183 u_int32_t ifi_collisions
; /* collisions on csma interfaces */
184 u_int32_t ifi_ibytes
; /* total number of octets received */
185 u_int32_t ifi_obytes
; /* total number of octets sent */
186 u_int32_t ifi_imcasts
; /* packets received via multicast */
187 u_int32_t ifi_omcasts
; /* packets sent via multicast */
188 u_int32_t ifi_iqdrops
; /* dropped on input, this interface */
189 u_int32_t ifi_noproto
; /* destined for unsupported protocol */
190 u_int32_t ifi_recvtiming
; /* usec spent receiving when timing */
191 u_int32_t ifi_xmittiming
; /* usec spent xmitting when timing */
192 struct IF_DATA_TIMEVAL ifi_lastchange
; /* time of last administrative change */
193 u_int32_t ifi_unused2
; /* used to be the default_proto */
194 u_int32_t ifi_hwassist
; /* HW offload capabilities */
195 u_int32_t ifi_reserved1
; /* for future use */
196 u_int32_t ifi_reserved2
; /* for future use */
200 * Structure describing information about an interface
201 * which may be of interest to management entities.
204 /* generic interface information */
205 u_char ifi_type
; /* ethernet, tokenring, etc */
206 u_char ifi_typelen
; /* Length of frame type id */
207 u_char ifi_physical
; /* e.g., AUI, Thinnet, 10base-T, etc */
208 u_char ifi_addrlen
; /* media address length */
209 u_char ifi_hdrlen
; /* media header length */
210 u_char ifi_recvquota
; /* polling quota for receive intrs */
211 u_char ifi_xmitquota
; /* polling quota for xmit intrs */
212 u_char ifi_unused1
; /* for future use */
213 u_int32_t ifi_mtu
; /* maximum transmission unit */
214 u_int32_t ifi_metric
; /* routing metric (external only) */
215 u_int64_t ifi_baudrate
; /* linespeed */
216 /* volatile statistics */
217 u_int64_t ifi_ipackets
; /* packets received on interface */
218 u_int64_t ifi_ierrors
; /* input errors on interface */
219 u_int64_t ifi_opackets
; /* packets sent on interface */
220 u_int64_t ifi_oerrors
; /* output errors on interface */
221 u_int64_t ifi_collisions
; /* collisions on csma interfaces */
222 u_int64_t ifi_ibytes
; /* total number of octets received */
223 u_int64_t ifi_obytes
; /* total number of octets sent */
224 u_int64_t ifi_imcasts
; /* packets received via multicast */
225 u_int64_t ifi_omcasts
; /* packets sent via multicast */
226 u_int64_t ifi_iqdrops
; /* dropped on input, this interface */
227 u_int64_t ifi_noproto
; /* destined for unsupported protocol */
228 u_int32_t ifi_recvtiming
; /* usec spent receiving when timing */
229 u_int32_t ifi_xmittiming
; /* usec spent xmitting when timing */
230 struct IF_DATA_TIMEVAL ifi_lastchange
; /* time of last administrative change */
234 struct if_traffic_class
{
235 u_int64_t ifi_ibepackets
; /* TC_BE packets received on interface */
236 u_int64_t ifi_ibebytes
; /* TC_BE bytes received on interface */
237 u_int64_t ifi_obepackets
; /* TC_BE packet sent on interface */
238 u_int64_t ifi_obebytes
; /* TC_BE bytes sent on interface */
239 u_int64_t ifi_ibkpackets
; /* TC_BK packets received on interface */
240 u_int64_t ifi_ibkbytes
; /* TC_BK bytes received on interface */
241 u_int64_t ifi_obkpackets
; /* TC_BK packet sent on interface */
242 u_int64_t ifi_obkbytes
; /* TC_BK bytes sent on interface */
243 u_int64_t ifi_ivipackets
; /* TC_VI packets received on interface */
244 u_int64_t ifi_ivibytes
; /* TC_VI bytes received on interface */
245 u_int64_t ifi_ovipackets
; /* TC_VI packets sent on interface */
246 u_int64_t ifi_ovibytes
; /* TC_VI bytes sent on interface */
247 u_int64_t ifi_ivopackets
; /* TC_VO packets received on interface */
248 u_int64_t ifi_ivobytes
; /* TC_VO bytes received on interface */
249 u_int64_t ifi_ovopackets
; /* TC_VO packets sent on interface */
250 u_int64_t ifi_ovobytes
; /* TC_VO bytes sent on interface */
251 u_int64_t ifi_ipvpackets
; /* TC priv packets received on interface */
252 u_int64_t ifi_ipvbytes
; /* TC priv bytes received on interface */
253 u_int64_t ifi_opvpackets
; /* TC priv packets sent on interface */
254 u_int64_t ifi_opvbytes
; /* TC priv bytes sent on interface */
257 struct if_data_extended
{
258 u_int64_t ifi_alignerrs
; /* unaligned (32-bit) input pkts */
259 u_int64_t ifi_dt_bytes
; /* Data threshold counter */
260 u_int64_t ifi_fpackets
; /* forwarded packets on interface */
261 u_int64_t ifi_fbytes
; /* forwarded bytes on interface */
262 u_int64_t reserved
[12]; /* for future */
265 struct if_packet_stats
{
267 u_int64_t ifi_tcp_badformat
;
268 u_int64_t ifi_tcp_unspecv6
;
269 u_int64_t ifi_tcp_synfin
;
270 u_int64_t ifi_tcp_badformatipsec
;
271 u_int64_t ifi_tcp_noconnnolist
;
272 u_int64_t ifi_tcp_noconnlist
;
273 u_int64_t ifi_tcp_listbadsyn
;
274 u_int64_t ifi_tcp_icmp6unreach
;
275 u_int64_t ifi_tcp_deprecate6
;
276 u_int64_t ifi_tcp_rstinsynrcv
;
277 u_int64_t ifi_tcp_ooopacket
;
278 u_int64_t ifi_tcp_dospacket
;
279 u_int64_t ifi_tcp_cleanup
;
280 u_int64_t ifi_tcp_synwindow
;
281 u_int64_t reserved
[6];
283 u_int64_t ifi_udp_port_unreach
;
284 u_int64_t ifi_udp_faithprefix
;
285 u_int64_t ifi_udp_port0
;
286 u_int64_t ifi_udp_badlength
;
287 u_int64_t ifi_udp_badchksum
;
288 u_int64_t ifi_udp_badmcast
;
289 u_int64_t ifi_udp_cleanup
;
290 u_int64_t ifi_udp_badipsec
;
291 u_int64_t _reserved
[4];
294 struct if_description
{
295 u_int32_t ifd_maxlen
; /* must be IF_DESCSIZE */
296 u_int32_t ifd_len
; /* actual ifd_desc length */
297 u_int8_t
*ifd_desc
; /* ptr to desc buffer */
300 struct if_bandwidths
{
301 uint64_t eff_bw
; /* effective bandwidth */
302 uint64_t max_bw
; /* maximum theoretical bandwidth */
305 struct if_latencies
{
306 u_int64_t eff_lt
; /* effective latency */
307 u_int64_t max_lt
; /* maximum theoretical latency */
310 #define IF_NETEM_PARAMS_PSCALE 100000
311 struct if_netem_params
{
312 /* bandwidth limit */
313 uint64_t ifnetem_bandwidth_bps
;
315 /* latency (normal distribution with jitter as stdev) */
316 uint32_t ifnetem_latency_ms
;
317 uint32_t ifnetem_jitter_ms
;
320 * NetEm probabilistic model parameters has a scaling factor of 100,000
321 * for 5 digits precision. For instance, probability 12.345% is
322 * expressed as uint32_t fixed point 12345 in ifnet_*_p variable below.
324 /* random packet corruption */
325 uint32_t ifnetem_corruption_p
;
327 /* random packet duplication */
328 uint32_t ifnetem_duplication_p
;
330 /* 4 state Markov loss model */
331 uint32_t ifnetem_loss_p_gr_gl
; /* P( gap_loss | gap_rx ) */
332 uint32_t ifnetem_loss_p_gr_bl
; /* P( burst_loss | gap_rx ) */
333 uint32_t ifnetem_loss_p_bl_br
; /* P( burst_rx | burst_loss ) */
334 uint32_t ifnetem_loss_p_bl_gr
; /* P( gap_rx | burst_loss ) */
335 uint32_t ifnetem_loss_p_br_bl
; /* P( burst_loss | burst_rx ) */
337 /* random packet reordering */
338 uint32_t ifnetem_reordering_p
;
341 struct if_rxpoll_stats
{
342 u_int32_t ifi_poll_off_req
; /* total # of POLL_OFF reqs */
343 u_int32_t ifi_poll_off_err
; /* total # of POLL_OFF errors */
344 u_int32_t ifi_poll_on_req
; /* total # of POLL_ON reqs */
345 u_int32_t ifi_poll_on_err
; /* total # of POLL_ON errors */
347 u_int32_t ifi_poll_wakeups_avg
; /* avg # of wakeup reqs */
348 u_int32_t ifi_poll_wakeups_lowat
; /* wakeups low watermark */
349 u_int32_t ifi_poll_wakeups_hiwat
; /* wakeups high watermark */
351 u_int64_t ifi_poll_packets
; /* total # of polled packets */
352 u_int32_t ifi_poll_packets_avg
; /* average polled packets */
353 u_int32_t ifi_poll_packets_min
; /* smallest polled packets */
354 u_int32_t ifi_poll_packets_max
; /* largest polled packets */
355 u_int32_t ifi_poll_packets_lowat
; /* packets low watermark */
356 u_int32_t ifi_poll_packets_hiwat
; /* packets high watermark */
358 u_int64_t ifi_poll_bytes
; /* total # of polled bytes */
359 u_int32_t ifi_poll_bytes_avg
; /* average polled bytes */
360 u_int32_t ifi_poll_bytes_min
; /* smallest polled bytes */
361 u_int32_t ifi_poll_bytes_max
; /* largest polled bytes */
362 u_int32_t ifi_poll_bytes_lowat
; /* bytes low watermark */
363 u_int32_t ifi_poll_bytes_hiwat
; /* bytes high watermark */
365 u_int32_t ifi_poll_packets_limit
; /* max packets per poll call */
366 u_int64_t ifi_poll_interval_time
; /* poll interval (nsec) */
369 struct if_netif_stats
{
370 u_int64_t ifn_rx_mit_interval
; /* rx mitigation ival (nsec) */
371 u_int32_t ifn_rx_mit_mode
; /* 0: static, 1: dynamic */
372 u_int32_t ifn_rx_mit_packets_avg
; /* average # of packets */
373 u_int32_t ifn_rx_mit_packets_min
; /* smallest # of packets */
374 u_int32_t ifn_rx_mit_packets_max
; /* largest # of packets */
375 u_int32_t ifn_rx_mit_bytes_avg
; /* average # of bytes */
376 u_int32_t ifn_rx_mit_bytes_min
; /* smallest # of bytes */
377 u_int32_t ifn_rx_mit_bytes_max
; /* largest # of bytes */
378 u_int32_t ifn_rx_mit_cfg_idx
; /* current config selector */
379 u_int32_t ifn_rx_mit_cfg_packets_lowat
; /* pkts low watermark */
380 u_int32_t ifn_rx_mit_cfg_packets_hiwat
; /* pkts high watermark */
381 u_int32_t ifn_rx_mit_cfg_bytes_lowat
; /* bytes low watermark */
382 u_int32_t ifn_rx_mit_cfg_bytes_hiwat
; /* bytes high watermark */
383 u_int32_t ifn_rx_mit_cfg_interval
; /* delay interval (nsec) */
386 struct if_tcp_ecn_perf_stat
{
387 u_int64_t total_txpkts
;
388 u_int64_t total_rxmitpkts
;
389 u_int64_t total_rxpkts
;
390 u_int64_t total_oopkts
;
391 u_int64_t total_reorderpkts
;
394 u_int64_t sack_episodes
;
395 u_int64_t rxmit_drop
;
397 u_int64_t oo_percent
;
398 u_int64_t reorder_percent
;
399 u_int64_t rxmit_percent
;
402 struct if_tcp_ecn_stat
{
404 u_int64_t ecn_client_setup
;
405 u_int64_t ecn_server_setup
;
406 u_int64_t ecn_client_success
;
407 u_int64_t ecn_server_success
;
408 u_int64_t ecn_peer_nosupport
;
409 u_int64_t ecn_syn_lost
;
410 u_int64_t ecn_synack_lost
;
411 u_int64_t ecn_recv_ce
;
412 u_int64_t ecn_recv_ece
;
413 u_int64_t ecn_conn_recv_ce
;
414 u_int64_t ecn_conn_recv_ece
;
415 u_int64_t ecn_conn_plnoce
;
416 u_int64_t ecn_conn_plce
;
417 u_int64_t ecn_conn_noplce
;
418 u_int64_t ecn_fallback_synloss
;
419 u_int64_t ecn_fallback_reorder
;
420 u_int64_t ecn_fallback_ce
;
421 u_int64_t ecn_off_conn
;
422 u_int64_t ecn_total_conn
;
423 u_int64_t ecn_fallback_droprst
;
424 u_int64_t ecn_fallback_droprxmt
;
425 u_int64_t ecn_fallback_synrst
;
426 struct if_tcp_ecn_perf_stat ecn_on
;
427 struct if_tcp_ecn_perf_stat ecn_off
;
430 struct if_lim_perf_stat
{
431 u_int64_t lim_dl_max_bandwidth
; /* bits per second */
432 u_int64_t lim_ul_max_bandwidth
; /* bits per second */
433 u_int64_t lim_total_txpkts
; /* Total transmit packets, count */
434 u_int64_t lim_total_rxpkts
; /* Total receive packets, count */
435 u_int64_t lim_total_retxpkts
; /* Total retransmit packets */
436 u_int64_t lim_packet_loss_percent
; /* Packet loss rate */
437 u_int64_t lim_total_oopkts
; /* Total out-of-order packets */
438 u_int64_t lim_packet_ooo_percent
; /* Out-of-order packet rate */
439 u_int64_t lim_rtt_variance
; /* RTT variance, milliseconds */
440 u_int64_t lim_rtt_average
; /* RTT average, milliseconds */
441 u_int64_t lim_rtt_min
; /* RTT minimum, milliseconds */
442 u_int64_t lim_conn_timeouts
; /* connection timeouts */
443 u_int64_t lim_conn_attempts
; /* connection attempts */
444 u_int64_t lim_conn_timeout_percent
; /* Rate of connection timeouts */
445 u_int64_t lim_bk_txpkts
; /* Transmit packets with BK service class, that use delay based algorithms */
446 u_int64_t lim_dl_detected
:1, /* Low internet */
450 #define IF_VAR_H_HAS_IFNET_STATS_PER_FLOW 1
451 struct ifnet_stats_per_flow
{
452 u_int64_t bk_txpackets
;
455 u_int32_t txretransmitbytes
;
456 u_int32_t rxoutoforderbytes
;
460 u_int32_t sack_recovery_episodes
;
461 u_int32_t reordered_pkts
;
462 u_int32_t dsack_sent
;
463 u_int32_t dsack_recvd
;
465 u_int32_t rttupdated
;
468 u_int32_t bw_sndbw_max
;
469 u_int32_t bw_rcvbw_max
;
470 u_int32_t ecn_recv_ece
;
471 u_int32_t ecn_recv_ce
;
478 ecn_fallback_synloss
:1,
479 ecn_fallback_droprst
:1,
480 ecn_fallback_droprxmt
:1,
482 ecn_fallback_reorder
:1;
486 * Interface link status report -- includes statistics related to
487 * the link layer technology sent by the driver. The driver will monitor
488 * these statistics over an interval (3-4 secs) and will generate a report
489 * to the network stack. This will give first-hand information about the
490 * status of the first hop of the network path. The version and
491 * length values should be correct for the data to be processed correctly.
492 * The definitions are different for different kind of interfaces like
493 * Wifi, Cellular etc,.
495 #define IF_CELLULAR_STATUS_REPORT_VERSION_1 1
496 #define IF_WIFI_STATUS_REPORT_VERSION_1 1
497 #define IF_CELLULAR_STATUS_REPORT_CURRENT_VERSION \
498 IF_CELLULAR_STATUS_REPORT_VERSION_1
499 #define IF_WIFI_STATUS_REPORT_CURRENT_VERSION IF_WIFI_STATUS_REPORT_VERSION_1
501 * For cellular interface --
502 * There is no way to share common headers between the Baseband and
503 * the kernel. Any changes to this structure will need to be communicated
504 * to the Baseband team. It is better to use reserved space instead of
505 * changing the size or existing fields in the structure.
507 struct if_cellular_status_v1
{
508 u_int32_t valid_bitmask
; /* indicates which fields are valid */
509 #define IF_CELL_LINK_QUALITY_METRIC_VALID 0x1
510 #define IF_CELL_UL_EFFECTIVE_BANDWIDTH_VALID 0x2
511 #define IF_CELL_UL_MAX_BANDWIDTH_VALID 0x4
512 #define IF_CELL_UL_MIN_LATENCY_VALID 0x8
513 #define IF_CELL_UL_EFFECTIVE_LATENCY_VALID 0x10
514 #define IF_CELL_UL_MAX_LATENCY_VALID 0x20
515 #define IF_CELL_UL_RETXT_LEVEL_VALID 0x40
516 #define IF_CELL_UL_BYTES_LOST_VALID 0x80
517 #define IF_CELL_UL_MIN_QUEUE_SIZE_VALID 0x100
518 #define IF_CELL_UL_AVG_QUEUE_SIZE_VALID 0x200
519 #define IF_CELL_UL_MAX_QUEUE_SIZE_VALID 0x400
520 #define IF_CELL_DL_EFFECTIVE_BANDWIDTH_VALID 0x800
521 #define IF_CELL_DL_MAX_BANDWIDTH_VALID 0x1000
522 #define IF_CELL_CONFIG_INACTIVITY_TIME_VALID 0x2000
523 #define IF_CELL_CONFIG_BACKOFF_TIME_VALID 0x4000
524 #define IF_CELL_UL_MSS_RECOMMENDED_VALID 0x8000
526 u_int32_t link_quality_metric
;
527 u_int32_t ul_effective_bandwidth
; /* Measured uplink bandwidth based on current activity (bps) */
528 u_int32_t ul_max_bandwidth
; /* Maximum supported uplink bandwidth (bps) */
529 u_int32_t ul_min_latency
; /* min expected uplink latency for first hop (ms) */
530 u_int32_t ul_effective_latency
; /* current expected uplink latency for first hop (ms) */
531 u_int32_t ul_max_latency
; /* max expected uplink latency first hop (ms) */
532 u_int32_t ul_retxt_level
; /* Retransmission metric */
533 #define IF_CELL_UL_RETXT_LEVEL_NONE 1
534 #define IF_CELL_UL_RETXT_LEVEL_LOW 2
535 #define IF_CELL_UL_RETXT_LEVEL_MEDIUM 3
536 #define IF_CELL_UL_RETXT_LEVEL_HIGH 4
537 u_int32_t ul_bytes_lost
; /* % of total bytes lost on uplink in Q10 format */
538 u_int32_t ul_min_queue_size
; /* minimum bytes in queue */
539 u_int32_t ul_avg_queue_size
; /* average bytes in queue */
540 u_int32_t ul_max_queue_size
; /* maximum bytes in queue */
541 u_int32_t dl_effective_bandwidth
; /* Measured downlink bandwidth based on current activity (bps) */
542 u_int32_t dl_max_bandwidth
; /* Maximum supported downlink bandwidth (bps) */
543 u_int32_t config_inactivity_time
; /* ms */
544 u_int32_t config_backoff_time
; /* new connections backoff time in ms */
545 #define IF_CELL_UL_MSS_RECOMMENDED_NONE 0x0 /* Use default */
546 #define IF_CELL_UL_MSS_RECOMMENDED_MEDIUM 0x1 /* 1200 byte MSS */
547 #define IF_CELL_UL_MSS_RECOMMENDED_LOW 0x2 /* 512 byte MSS */
548 u_int16_t mss_recommended
;
549 u_int16_t reserved_1
;
550 u_int32_t reserved_2
;
551 u_int64_t reserved_3
;
552 u_int64_t reserved_4
;
553 u_int64_t reserved_5
;
554 u_int64_t reserved_6
;
555 } __attribute__((packed
));
557 struct if_cellular_status
{
559 struct if_cellular_status_v1 if_status_v1
;
564 * These statistics will be provided by the Wifi driver periodically.
565 * After sending each report, the driver should start computing again
566 * for the next report duration so that the values represent the link
567 * status for one report duration.
570 struct if_wifi_status_v1
{
571 u_int32_t valid_bitmask
;
572 #define IF_WIFI_LINK_QUALITY_METRIC_VALID 0x1
573 #define IF_WIFI_UL_EFFECTIVE_BANDWIDTH_VALID 0x2
574 #define IF_WIFI_UL_MAX_BANDWIDTH_VALID 0x4
575 #define IF_WIFI_UL_MIN_LATENCY_VALID 0x8
576 #define IF_WIFI_UL_EFFECTIVE_LATENCY_VALID 0x10
577 #define IF_WIFI_UL_MAX_LATENCY_VALID 0x20
578 #define IF_WIFI_UL_RETXT_LEVEL_VALID 0x40
579 #define IF_WIFI_UL_ERROR_RATE_VALID 0x80
580 #define IF_WIFI_UL_BYTES_LOST_VALID 0x100
581 #define IF_WIFI_DL_EFFECTIVE_BANDWIDTH_VALID 0x200
582 #define IF_WIFI_DL_MAX_BANDWIDTH_VALID 0x400
583 #define IF_WIFI_DL_MIN_LATENCY_VALID 0x800
584 #define IF_WIFI_DL_EFFECTIVE_LATENCY_VALID 0x1000
585 #define IF_WIFI_DL_MAX_LATENCY_VALID 0x2000
586 #define IF_WIFI_DL_ERROR_RATE_VALID 0x4000
587 #define IF_WIFI_CONFIG_FREQUENCY_VALID 0x8000
588 #define IF_WIFI_CONFIG_MULTICAST_RATE_VALID 0x10000
589 #define IF_WIFI_CONFIG_SCAN_COUNT_VALID 0x20000
590 #define IF_WIFI_CONFIG_SCAN_DURATION_VALID 0x40000
591 u_int32_t link_quality_metric
; /* link quality metric */
592 u_int32_t ul_effective_bandwidth
; /* Measured uplink bandwidth based on current activity (bps) */
593 u_int32_t ul_max_bandwidth
; /* Maximum supported uplink bandwidth (bps) */
594 u_int32_t ul_min_latency
; /* min expected uplink latency for first hop (ms) */
595 u_int32_t ul_effective_latency
; /* current expected uplink latency for first hop (ms) */
596 u_int32_t ul_max_latency
; /* max expected uplink latency for first hop (ms) */
597 u_int32_t ul_retxt_level
; /* Retransmission metric */
598 #define IF_WIFI_UL_RETXT_LEVEL_NONE 1
599 #define IF_WIFI_UL_RETXT_LEVEL_LOW 2
600 #define IF_WIFI_UL_RETXT_LEVEL_MEDIUM 3
601 #define IF_WIFI_UL_RETXT_LEVEL_HIGH 4
602 u_int32_t ul_bytes_lost
; /* % of total bytes lost on uplink in Q10 format */
603 u_int32_t ul_error_rate
; /* % of bytes dropped on uplink after many retransmissions in Q10 format */
604 u_int32_t dl_effective_bandwidth
; /* Measured downlink bandwidth based on current activity (bps) */
605 u_int32_t dl_max_bandwidth
; /* Maximum supported downlink bandwidth (bps) */
607 * The download latency values indicate the time AP may have to wait for the
608 * driver to receive the packet. These values give the range of expected latency
609 * mainly due to co-existence events and channel hopping where the interface
610 * becomes unavailable.
612 u_int32_t dl_min_latency
; /* min expected latency for first hop in ms */
613 u_int32_t dl_effective_latency
; /* current expected latency for first hop in ms */
614 u_int32_t dl_max_latency
; /* max expected latency for first hop in ms */
615 u_int32_t dl_error_rate
; /* % of CRC or other errors in Q10 format */
616 u_int32_t config_frequency
; /* 2.4 or 5 GHz */
617 #define IF_WIFI_CONFIG_FREQUENCY_2_4_GHZ 1
618 #define IF_WIFI_CONFIG_FREQUENCY_5_0_GHZ 2
619 u_int32_t config_multicast_rate
; /* bps */
620 u_int32_t scan_count
; /* scan count during the previous period */
621 u_int32_t scan_duration
; /* scan duration in ms */
622 u_int64_t reserved_1
;
623 u_int64_t reserved_2
;
624 u_int64_t reserved_3
;
625 u_int64_t reserved_4
;
626 } __attribute__((packed
));
628 struct if_wifi_status
{
630 struct if_wifi_status_v1 if_status_v1
;
634 struct if_link_status
{
635 u_int32_t ifsr_version
; /* version of this report */
636 u_int32_t ifsr_len
; /* length of the following struct */
638 struct if_cellular_status ifsr_cell
;
639 struct if_wifi_status ifsr_wifi
;
643 struct if_interface_state
{
645 * The bitmask tells which of the fields
647 * - When setting, to control which fields
648 * are being modified;
649 * - When getting, it tells which fields are set.
651 u_int8_t valid_bitmask
;
652 #define IF_INTERFACE_STATE_RRC_STATE_VALID 0x1
653 #define IF_INTERFACE_STATE_LQM_STATE_VALID 0x2
654 #define IF_INTERFACE_STATE_INTERFACE_AVAILABILITY_VALID 0x4
657 * Valid only for cellular interface
660 #define IF_INTERFACE_STATE_RRC_STATE_IDLE 0x0
661 #define IF_INTERFACE_STATE_RRC_STATE_CONNECTED 0x1
664 * Values normalized to the edge of the following values
665 * that are defined on <net/if.h>:
666 * IFNET_LQM_THRESH_BAD
667 * IFNET_LQM_THRESH_POOR
668 * IFNET_LQM_THRESH_GOOD
673 * Indicate if the underlying link is currently
676 u_int8_t interface_availability
;
677 #define IF_INTERFACE_STATE_INTERFACE_AVAILABLE 0x0
678 #define IF_INTERFACE_STATE_INTERFACE_UNAVAILABLE 0x1
681 struct chain_len_stats
{
686 uint64_t cls_five_or_more
;
687 } __attribute__((__aligned__(sizeof(uint64_t))));
690 * This structure is used to define the parameters for advisory notifications
693 #pragma pack(push, 1)
694 struct ifnet_interface_advisory
{
695 /* The current structure version */
697 #define IF_INTERFACE_ADVISORY_VERSION_1 0x1
698 #define IF_INTERFACE_ADVISORY_VERSION_CURRENT IF_INTERFACE_ADVISORY_VERSION_1
699 /* Specifies if the advisory is for transmit or receive path */
701 #define IF_INTERFACE_ADVISORY_DIRECTION_TX 0x1
702 #define IF_INTERFACE_ADVISORY_DIRECTION_RX 0x2
703 /* reserved for future use */
706 * suggestion for data rate change to keep the latency low.
707 * unit: bits per second (bps)
708 * NOTE: if the interface cannot provide suggestions in terms of bps,
709 * it should use the following values:
710 * INT32_MAX : ramp up
711 * INT32_MIN : ramp down
714 #define IF_INTERFACE_ADVISORY_RATE_SUGGESTION_RAMP_UP INT32_MAX
715 #define IF_INTERFACE_ADVISORY_RATE_SUGGESTION_RAMP_DOWN INT32_MIN
716 #define IF_INTERFACE_ADVISORY_RATE_SUGGESTION_RAMP_NEUTRAL 0
717 int32_t rate_trend_suggestion
;
719 * Time of the issue of advisory.
720 * Timestamp should be in the host domain.
721 * unit: mach absolute time
725 * Maximum theoretical bandwidth of the interface.
726 * unit: bits per second (bps)
728 uint64_t max_bandwidth
;
730 * Total bytes sent or received on the interface.
731 * wrap around possible and the application should account for that.
734 uint64_t total_byte_count
;
736 * average throughput observed at the driver stack.
737 * unit: bits per second (bps)
739 uint64_t average_throughput
;
741 * flushable queue size at the driver.
742 * should be set to UINT32_MAX if not available.
745 uint32_t flushable_queue_size
;
747 * non flushable queue size at the driver.
748 * should be set to UINT32_MAX if not available.
751 uint32_t non_flushable_queue_size
;
753 * average delay observed at the interface.
754 * unit: milliseconds (ms)
756 uint32_t average_delay
;
757 } __attribute__((aligned(sizeof(uint64_t))));
765 * Structure defining a queue for a network interface.
775 #ifdef BSD_KERNEL_PRIVATE
776 #define IFNETS_MAX 64
779 * Internal storage of if_data. This is bound to change. Various places in the
780 * stack will translate this data structure in to the externally visible
781 * if_data structure above. Note that during interface attach time, the
782 * embedded if_data structure in ifnet is cleared, with the exception of
783 * some non-statistics related fields.
785 struct if_data_internal
{
786 /* generic interface information */
787 u_char ifi_type
; /* ethernet, tokenring, etc */
788 u_char ifi_typelen
; /* Length of frame type id */
789 u_char ifi_physical
; /* e.g., AUI, Thinnet, 10base-T, etc */
790 u_char ifi_addrlen
; /* media address length */
791 u_char ifi_hdrlen
; /* media header length */
792 u_char ifi_recvquota
; /* polling quota for receive intrs */
793 u_char ifi_xmitquota
; /* polling quota for xmit intrs */
794 u_char ifi_unused1
; /* for future use */
795 u_int32_t ifi_mtu
; /* maximum transmission unit */
796 u_int32_t ifi_metric
; /* routing metric (external only) */
797 u_int32_t ifi_baudrate
; /* linespeed */
798 /* volatile statistics */
799 u_int64_t ifi_ipackets
; /* packets received on interface */
800 u_int64_t ifi_ierrors
; /* input errors on interface */
801 u_int64_t ifi_opackets
; /* packets sent on interface */
802 u_int64_t ifi_oerrors
; /* output errors on interface */
803 u_int64_t ifi_collisions
; /* collisions on csma interfaces */
804 u_int64_t ifi_ibytes
; /* total number of octets received */
805 u_int64_t ifi_obytes
; /* total number of octets sent */
806 u_int64_t ifi_imcasts
; /* packets received via multicast */
807 u_int64_t ifi_omcasts
; /* packets sent via multicast */
808 u_int64_t ifi_iqdrops
; /* dropped on input, this interface */
809 u_int64_t ifi_noproto
; /* destined for unsupported protocol */
810 u_int32_t ifi_recvtiming
; /* usec spent receiving when timing */
811 u_int32_t ifi_xmittiming
; /* usec spent xmitting when timing */
812 u_int64_t ifi_alignerrs
; /* unaligned (32-bit) input pkts */
813 u_int64_t ifi_dt_bytes
; /* Data threshold counter */
814 u_int64_t ifi_fpackets
; /* forwarded packets on interface */
815 u_int64_t ifi_fbytes
; /* forwarded bytes on interface */
816 struct timeval ifi_lastchange
; /* time of last administrative change */
817 struct timeval ifi_lastupdown
; /* time of last up/down event */
818 u_int32_t ifi_hwassist
; /* HW offload capabilities */
819 u_int32_t ifi_tso_v4_mtu
; /* TCP Segment Offload IPv4 maximum segment size */
820 u_int32_t ifi_tso_v6_mtu
; /* TCP Segment Offload IPv6 maximum segment size */
822 #endif /* BSD_KERNEL_PRIVATE */
825 #define if_mtu if_data.ifi_mtu
826 #define if_type if_data.ifi_type
827 #define if_typelen if_data.ifi_typelen
828 #define if_physical if_data.ifi_physical
829 #define if_addrlen if_data.ifi_addrlen
830 #define if_hdrlen if_data.ifi_hdrlen
831 #define if_metric if_data.ifi_metric
832 #define if_baudrate if_data.ifi_baudrate
833 #define if_hwassist if_data.ifi_hwassist
834 #define if_ipackets if_data.ifi_ipackets
835 #define if_ierrors if_data.ifi_ierrors
836 #define if_opackets if_data.ifi_opackets
837 #define if_oerrors if_data.ifi_oerrors
838 #define if_collisions if_data.ifi_collisions
839 #define if_ibytes if_data.ifi_ibytes
840 #define if_obytes if_data.ifi_obytes
841 #define if_imcasts if_data.ifi_imcasts
842 #define if_omcasts if_data.ifi_omcasts
843 #define if_iqdrops if_data.ifi_iqdrops
844 #define if_noproto if_data.ifi_noproto
845 #define if_lastchange if_data.ifi_lastchange
846 #define if_recvquota if_data.ifi_recvquota
847 #define if_xmitquota if_data.ifi_xmitquota
849 #ifdef BSD_KERNEL_PRIVATE
850 #define if_tso_v4_mtu if_data.ifi_tso_v4_mtu
851 #define if_tso_v6_mtu if_data.ifi_tso_v6_mtu
852 #define if_alignerrs if_data.ifi_alignerrs
853 #define if_dt_bytes if_data.ifi_dt_bytes
854 #define if_fpackets if_data.ifi_fpackets
855 #define if_fbytes if_data.ifi_fbytes
856 #define if_lastupdown if_data.ifi_lastupdown
857 #endif /* BSD_KERNEL_PRIVATE */
859 #ifdef BSD_KERNEL_PRIVATE
861 * Forward structure declarations for function prototypes [sic].
870 struct proto_hash_entry
;
871 struct dlil_threading_info
;
872 struct tcpstat_local
;
873 struct udpstat_local
;
878 /* we use TAILQs so that the order of instantiation is preserved in the list */
879 TAILQ_HEAD(ifnethead
, ifnet
);
880 TAILQ_HEAD(ifaddrhead
, ifaddr
);
881 LIST_HEAD(ifmultihead
, ifmultiaddr
);
882 TAILQ_HEAD(tailq_head
, tqdummy
);
883 TAILQ_HEAD(ifnet_filter_head
, ifnet_filter
);
884 TAILQ_HEAD(ddesc_head_name
, dlil_demux_desc
);
886 extern boolean_t intcoproc_unrestricted
;
887 #endif /* BSD_KERNEL_PRIVATE */
891 * All of the following IF_HWASSIST_* flags are defined in kpi_interface.h as
892 * IFNET_* flags. These are redefined here as constants to avoid failures to
893 * build user level programs that can not include kpi_interface.h. It is
894 * important to keep this in sync with the definitions in kpi_interface.h.
895 * The corresponding constant for each definition is mentioned in the comment.
897 * Bottom 16 bits reserved for hardware checksum
899 #define IF_HWASSIST_CSUM_IP 0x0001 /* will csum IP, IFNET_CSUM_IP */
900 #define IF_HWASSIST_CSUM_TCP 0x0002 /* will csum TCP, IFNET_CSUM_TCP */
901 #define IF_HWASSIST_CSUM_UDP 0x0004 /* will csum UDP, IFNET_CSUM_UDP */
902 #define IF_HWASSIST_CSUM_IP_FRAGS 0x0008 /* will csum IP fragments, IFNET_CSUM_FRAGMENT */
903 #define IF_HWASSIST_CSUM_FRAGMENT 0x0010 /* will do IP fragmentation, IFNET_IP_FRAGMENT */
904 #define IF_HWASSIST_CSUM_TCPIPV6 0x0020 /* will csum TCPv6, IFNET_CSUM_TCPIPV6 */
905 #define IF_HWASSIST_CSUM_UDPIPV6 0x0040 /* will csum UDPv6, IFNET_CSUM_UDP */
906 #define IF_HWASSIST_CSUM_FRAGMENT_IPV6 0x0080 /* will do IPv6 fragmentation, IFNET_IPV6_FRAGMENT */
907 #define IF_HWASSIST_CSUM_PARTIAL 0x1000 /* simple Sum16 computation, IFNET_CSUM_PARTIAL */
908 #define IF_HWASSIST_CSUM_ZERO_INVERT 0x2000 /* capable of inverting csum of 0 to -0 (0xffff) */
909 #define IF_HWASSIST_CSUM_MASK 0xffff
910 #define IF_HWASSIST_CSUM_FLAGS(hwassist) ((hwassist) & IF_HWASSIST_CSUM_MASK)
913 #define IF_HWASSIST_VLAN_TAGGING 0x00010000 /* supports VLAN tagging, IFNET_VLAN_TAGGING */
914 #define IF_HWASSIST_VLAN_MTU 0x00020000 /* supports VLAN MTU-sized packet (for software VLAN), IFNET_VLAN_MTU */
916 /* TCP Segment Offloading support */
918 #define IF_HWASSIST_TSO_V4 0x00200000 /* will do TCP Segment offload for IPv4, IFNET_TSO_IPV4 */
919 #define IF_HWASSIST_TSO_V6 0x00400000 /* will do TCP Segment offload for IPv6, IFNET_TSO_IPV6 */
923 #define IFXNAMSIZ (IFNAMSIZ + 8) /* external name (name + unit) */
924 #define IFNET_NETWORK_ID_LEN 32
927 #ifdef BSD_KERNEL_PRIVATE
929 * ifnet is private to BSD portion of kernel
931 #include <sys/mcache.h>
932 #include <sys/tree.h>
933 #include <netinet/in.h>
934 #include <net/if_dl.h>
935 #include <net/classq/if_classq.h>
936 #include <net/if_types.h>
938 RB_HEAD(ll_reach_tree
, if_llreach
); /* define struct ll_reach_tree */
941 typedef errno_t (*dlil_input_func
)(ifnet_t ifp
, mbuf_t m_head
,
942 mbuf_t m_tail
, const struct ifnet_stat_increment_param
*s
,
943 boolean_t poll
, struct thread
*tp
);
944 typedef errno_t (*dlil_output_func
)(ifnet_t interface
, mbuf_t data
);
946 typedef u_int8_t ipv6_router_mode_t
;
948 #define if_name(ifp) ifp->if_xname
950 * Structure defining a network interface.
952 * (Would like to call this struct ``if'', but C isn't PL/1.)
956 * Lock (RW or mutex) to protect this data structure (static storage.)
958 decl_lck_rw_data(, if_lock
);
959 void *if_softc
; /* pointer to driver state */
960 const char *if_name
; /* name, e.g. ``en'' or ``lo'' */
961 const char *if_xname
; /* external name (name + unit) */
962 struct if_description if_desc
; /* extended description */
963 TAILQ_ENTRY(ifnet
) if_link
; /* all struct ifnets are chained */
964 TAILQ_ENTRY(ifnet
) if_detaching_link
; /* list of detaching ifnets */
965 TAILQ_ENTRY(ifnet
) if_ordered_link
; /* list of ordered ifnets */
967 decl_lck_mtx_data(, if_ref_lock
);
968 u_int32_t if_refflags
; /* see IFRF flags below */
969 u_int32_t if_refio
; /* number of io ops to the underlying driver */
970 u_int32_t if_threads_pending
; /* Threads created but waiting for first run */
971 u_int32_t if_datamov
; /* number of threads moving data */
972 u_int32_t if_drainers
; /* number of draining threads */
973 u_int32_t if_suspend
; /* number of suspend requests */
975 #define if_list if_link
976 struct ifaddrhead if_addrhead
; /* linked list of addresses per if */
977 #define if_addrlist if_addrhead
978 struct ifaddr
*if_lladdr
; /* link address (first/permanent) */
980 u_int32_t if_qosmarking_mode
; /* generation to use with NECP clients */
982 int if_pcount
; /* number of promiscuous listeners */
983 struct bpf_if
*if_bpf
; /* packet filter structure */
984 u_short if_index
; /* numeric abbreviation for this if */
985 short if_unit
; /* sub-unit for lower level driver */
986 short if_timer
; /* time 'til if_watchdog called */
987 short if_flags
; /* up/down, broadcast, etc. */
988 u_int32_t if_eflags
; /* see <net/if.h> */
989 u_int32_t if_xflags
; /* see <net/if.h> */
991 int if_capabilities
; /* interface features & capabilities */
992 int if_capenable
; /* enabled features & capabilities */
994 void *if_linkmib
; /* link-type-specific MIB data */
995 uint32_t if_linkmiblen
; /* length of above data */
997 struct if_data_internal if_data
__attribute__((aligned(8)));
999 ifnet_family_t if_family
; /* value assigned by Apple */
1000 ifnet_subfamily_t if_subfamily
; /* value assigned by Apple */
1001 uintptr_t if_family_cookie
;
1002 volatile dlil_input_func if_input_dlil
;
1003 volatile dlil_output_func if_output_dlil
;
1004 volatile ifnet_start_func if_start
;
1005 ifnet_output_func if_output
;
1006 ifnet_pre_enqueue_func if_pre_enqueue
;
1007 ifnet_ctl_func if_output_ctl
;
1008 ifnet_input_poll_func if_input_poll
;
1009 ifnet_ctl_func if_input_ctl
;
1010 ifnet_ioctl_func if_ioctl
;
1011 ifnet_set_bpf_tap if_set_bpf_tap
;
1012 ifnet_detached_func if_free
;
1013 ifnet_demux_func if_demux
;
1014 ifnet_event_func if_event
;
1015 ifnet_framer_func if_framer_legacy
;
1016 ifnet_framer_extended_func if_framer
;
1017 ifnet_add_proto_func if_add_proto
;
1018 ifnet_del_proto_func if_del_proto
;
1019 ifnet_check_multi if_check_multi
;
1020 struct proto_hash_entry
*if_proto_hash
;
1021 void *if_kpi_storage
;
1023 u_int32_t if_flowhash
; /* interface flow control ID */
1025 decl_lck_mtx_data(, if_start_lock
);
1026 u_int32_t if_start_flags
; /* see IFSF flags below */
1027 u_int32_t if_start_req
;
1028 u_int8_t if_start_embryonic
;
1029 u_int8_t if_start_active
; /* output is active */
1030 u_int16_t if_start_delayed
;
1031 u_int16_t if_start_delay_qlen
;
1032 u_int16_t if_start_delay_idle
;
1033 u_int64_t if_start_delay_swin
;
1034 u_int32_t if_start_delay_cnt
;
1035 u_int32_t if_start_delay_timeout
; /* nanoseconds */
1036 struct timespec if_start_cycle
; /* restart interval */
1037 struct thread
*if_start_thread
;
1039 struct ifclassq if_snd
; /* transmit queue */
1040 u_int32_t if_output_sched_model
; /* tx sched model */
1042 struct if_bandwidths if_output_bw
;
1043 struct if_bandwidths if_input_bw
;
1045 struct if_latencies if_output_lt
;
1046 struct if_latencies if_input_lt
;
1048 decl_lck_mtx_data(, if_flt_lock
);
1049 u_int32_t if_flt_busy
;
1050 u_int32_t if_flt_waiters
;
1051 struct ifnet_filter_head if_flt_head
;
1053 struct ifmultihead if_multiaddrs
; /* multicast addresses */
1054 u_int32_t if_updatemcasts
; /* mcast addrs need updating */
1055 int if_amcount
; /* # of all-multicast reqs */
1056 decl_lck_mtx_data(, if_addrconfig_lock
); /* for serializing addr config */
1057 struct in_multi
*if_allhostsinm
; /* store all-hosts inm for this ifp */
1060 * Opportunistic polling parameters.
1062 decl_lck_mtx_data(, if_poll_lock
);
1063 struct if_poll_params
{
1065 u_int16_t poll_update
; /* link update */
1066 u_int32_t poll_flags
;
1067 #define IF_POLLF_READY 0x1 /* poll thread is ready */
1068 #define IF_POLLF_RUNNING 0x2 /* poll thread is running/active */
1069 #define IF_POLLF_EMBRYONIC 0x8000 /* poll thread is being setup */
1070 struct timespec poll_cycle
; /* poll interval */
1071 struct thread
*poll_thread
;
1073 ifnet_model_t poll_mode
; /* current mode */
1074 struct pktcntr poll_tstats
; /* incremental polling statistics */
1075 struct if_rxpoll_stats poll_pstats
; /* polling statistics */
1076 struct pktcntr poll_sstats
; /* packets and bytes per sampling */
1077 struct timespec poll_mode_holdtime
; /* mode holdtime in nsec */
1078 struct timespec poll_mode_lasttime
; /* last mode change time in nsec */
1079 struct timespec poll_sample_holdtime
; /* sampling holdtime in nsec */
1080 struct timespec poll_sample_lasttime
; /* last sampling time in nsec */
1081 struct timespec poll_dbg_lasttime
; /* last debug message time in nsec */
1083 #define if_poll_req rxpoll_params.poll_req
1084 #define if_poll_update rxpoll_params.poll_update
1085 #define if_poll_flags rxpoll_params.poll_flags
1086 #define if_poll_cycle rxpoll_params.poll_cycle
1087 #define if_poll_thread rxpoll_params.poll_thread
1088 #define if_poll_mode rxpoll_params.poll_mode
1089 #define if_poll_tstats rxpoll_params.poll_tstats
1090 #define if_poll_sstats rxpoll_params.poll_sstats
1091 #define if_poll_pstats rxpoll_params.poll_pstats
1093 #define if_poll_mode_holdtime rxpoll_params.poll_mode_holdtime
1094 #define if_poll_mode_lasttime rxpoll_params.poll_mode_lasttime
1095 #define if_poll_sample_holdtime rxpoll_params.poll_sample_holdtime
1096 #define if_poll_sample_lasttime rxpoll_params.poll_sample_lasttime
1097 #define if_poll_dbg_lasttime rxpoll_params.poll_dbg_lasttime
1099 #define if_rxpoll_offreq rxpoll_params.poll_pstats.ifi_poll_off_req
1100 #define if_rxpoll_offerr rxpoll_params.poll_pstats.ifi_poll_off_err
1101 #define if_rxpoll_onreq rxpoll_params.poll_pstats.ifi_poll_on_req
1102 #define if_rxpoll_onerr rxpoll_params.poll_pstats.ifi_poll_on_err
1103 #define if_rxpoll_wavg rxpoll_params.poll_pstats.ifi_poll_wakeups_avg
1104 #define if_rxpoll_wlowat rxpoll_params.poll_pstats.ifi_poll_wakeups_lowat
1105 #define if_rxpoll_whiwat rxpoll_params.poll_pstats.ifi_poll_wakeups_hiwat
1106 #define if_rxpoll_pavg rxpoll_params.poll_pstats.ifi_poll_packets_avg
1107 #define if_rxpoll_pmin rxpoll_params.poll_pstats.ifi_poll_packets_min
1108 #define if_rxpoll_pmax rxpoll_params.poll_pstats.ifi_poll_packets_max
1109 #define if_rxpoll_plowat rxpoll_params.poll_pstats.ifi_poll_packets_lowat
1110 #define if_rxpoll_phiwat rxpoll_params.poll_pstats.ifi_poll_packets_hiwat
1111 #define if_rxpoll_bavg rxpoll_params.poll_pstats.ifi_poll_bytes_avg
1112 #define if_rxpoll_bmin rxpoll_params.poll_pstats.ifi_poll_bytes_min
1113 #define if_rxpoll_bmax rxpoll_params.poll_pstats.ifi_poll_bytes_max
1114 #define if_rxpoll_blowat rxpoll_params.poll_pstats.ifi_poll_bytes_lowat
1115 #define if_rxpoll_bhiwat rxpoll_params.poll_pstats.ifi_poll_bytes_hiwat
1116 #define if_rxpoll_plim rxpoll_params.poll_pstats.ifi_poll_packets_limit
1117 #define if_rxpoll_ival rxpoll_params.poll_pstats.ifi_poll_interval_time
1119 struct dlil_threading_info
*if_inp
;
1121 /* allocated once along with dlil_ifnet and is never freed */
1122 thread_call_t if_dt_tcall
;
1133 struct pfi_kif
*if_pf_kif
;
1136 decl_lck_mtx_data(, if_cached_route_lock
);
1137 u_int32_t if_fwd_cacheok
;
1138 struct route if_fwd_route
; /* cached forwarding route */
1139 struct route if_src_route
; /* cached ipv4 source route */
1140 struct route_in6 if_src_route6
; /* cached ipv6 source route */
1142 decl_lck_rw_data(, if_llreach_lock
);
1143 struct ll_reach_tree if_ll_srcs
; /* source link-layer tree */
1145 void *if_bridge
; /* bridge glue */
1147 u_int32_t if_want_aggressive_drain
;
1148 u_int32_t if_idle_flags
; /* idle flags */
1149 u_int32_t if_idle_new_flags
; /* temporary idle flags */
1150 u_int32_t if_idle_new_flags_mask
; /* temporary mask */
1151 u_int32_t if_route_refcnt
; /* idle: route ref count */
1152 u_int32_t if_rt_sendts
; /* last of a real time packet */
1154 struct if_traffic_class if_tc
__attribute__((aligned(8)));
1156 struct igmp_ifinfo
*if_igi
; /* for IGMPv3 */
1158 struct mld_ifinfo
*if_mli
; /* for MLDv2 */
1160 struct tcpstat_local
*if_tcp_stat
; /* TCP specific stats */
1161 struct udpstat_local
*if_udp_stat
; /* UDP specific stats */
1164 int32_t level
; /* cached logging level */
1165 u_int32_t flags
; /* cached logging flags */
1166 int32_t category
; /* cached category */
1167 int32_t subcategory
; /* cached subcategory */
1171 struct ifnet
*ifp
; /* delegated ifp */
1172 u_int32_t type
; /* delegated i/f type */
1173 u_int32_t family
; /* delegated i/f family */
1174 u_int32_t subfamily
; /* delegated i/f sub-family */
1175 uint32_t expensive
:1, /* delegated i/f expensive? */
1176 constrained
:1; /* delegated i/f constrained? */
1179 uuid_t
*if_agentids
; /* network agents attached to interface */
1180 u_int32_t if_agentcount
;
1182 volatile uint32_t if_low_power_gencnt
;
1184 u_int32_t if_generation
; /* generation to use with NECP clients */
1185 u_int32_t if_fg_sendts
; /* last send on a fg socket in seconds */
1187 u_int64_t if_data_threshold
;
1189 /* Total bytes in send socket buffer */
1190 int64_t if_sndbyte_total
__attribute__ ((aligned(8)));
1191 /* Total unsent bytes in send socket buffer */
1192 int64_t if_sndbyte_unsent
__attribute__ ((aligned(8)));
1193 /* count of times, when there was data to send when sleep is impending */
1194 uint32_t if_unsent_data_cnt
;
1197 decl_lck_rw_data(, if_inetdata_lock
);
1200 decl_lck_rw_data(, if_inet6data_lock
);
1202 decl_lck_rw_data(, if_link_status_lock
);
1203 struct if_link_status
*if_link_status
;
1204 struct if_interface_state if_interface_state
;
1205 struct if_tcp_ecn_stat
*if_ipv4_stat
;
1206 struct if_tcp_ecn_stat
*if_ipv6_stat
;
1208 struct if_lim_perf_stat if_lim_stat
;
1210 uint32_t if_tcp_kao_max
;
1211 uint32_t if_tcp_kao_cnt
;
1213 struct netem
*if_output_netem
;
1215 ipv6_router_mode_t if_ipv6_router_mode
; /* see <netinet6/in6_var.h> */
1217 uint8_t network_id
[IFNET_NETWORK_ID_LEN
];
1218 uint8_t network_id_len
;
1221 /* Interface event handling declarations */
1222 extern struct eventhandler_lists_ctxt ifnet_evhdlr_ctxt
;
1225 INTF_EVENT_CODE_CREATED
,
1226 INTF_EVENT_CODE_REMOVED
,
1227 INTF_EVENT_CODE_STATUS_UPDATE
,
1228 INTF_EVENT_CODE_IPADDR_ATTACHED
,
1229 INTF_EVENT_CODE_IPADDR_DETACHED
,
1230 INTF_EVENT_CODE_LLADDR_UPDATE
,
1231 INTF_EVENT_CODE_MTU_CHANGED
,
1232 INTF_EVENT_CODE_LOW_POWER_UPDATE
,
1233 } intf_event_code_t
;
1235 typedef void (*ifnet_event_fn
)(struct eventhandler_entry_arg
, struct ifnet
*, struct sockaddr
*, intf_event_code_t
);
1236 EVENTHANDLER_DECLARE(ifnet_event
, ifnet_event_fn
);
1238 #define IF_TCP_STATINC(_ifp, _s) do { \
1239 if ((_ifp)->if_tcp_stat != NULL) \
1240 atomic_add_64(&(_ifp)->if_tcp_stat->_s, 1); \
1243 #define IF_UDP_STATINC(_ifp, _s) do { \
1244 if ((_ifp)->if_udp_stat != NULL) \
1245 atomic_add_64(&(_ifp)->if_udp_stat->_s, 1); \
1249 * Valid values for if_refflags
1251 #define IFRF_EMBRYONIC 0x1 /* ifnet is allocated; awaiting attach */
1252 #define IFRF_ATTACHED 0x2 /* ifnet attach is completely done */
1253 #define IFRF_DETACHING 0x4 /* detach has been requested */
1254 #define IFRF_READY 0x8 /* data path is ready */
1256 #define IFRF_ATTACH_MASK \
1257 (IFRF_EMBRYONIC|IFRF_ATTACHED|IFRF_DETACHING)
1259 #define IF_FULLY_ATTACHED(_ifp) \
1260 (((_ifp)->if_refflags & IFRF_ATTACH_MASK) == IFRF_ATTACHED)
1262 #define IF_FULLY_ATTACHED_AND_READY(_ifp) \
1263 (IF_FULLY_ATTACHED(_ifp) && ((_ifp)->if_refflags & IFRF_READY))
1265 * Valid values for if_start_flags
1267 #define IFSF_FLOW_CONTROLLED 0x1 /* flow controlled */
1270 * Structure describing a `cloning' interface.
1273 LIST_ENTRY(if_clone
) ifc_list
; /* on list of cloners */
1274 decl_lck_mtx_data(, ifc_mutex
); /* To serialize clone create/delete */
1275 const char *ifc_name
; /* name of device, e.g. `vlan' */
1276 size_t ifc_namelen
; /* length of name */
1277 u_int32_t ifc_minifs
; /* minimum number of interfaces */
1278 u_int32_t ifc_maxunit
; /* maximum unit number */
1279 unsigned char *ifc_units
; /* bitmap to handle units */
1280 u_int32_t ifc_bmlen
; /* bitmap length */
1281 u_int32_t ifc_zone_max_elem
; /* Max elements for this zone type */
1282 u_int32_t ifc_softc_size
; /* size of softc for the device */
1283 struct zone
*ifc_zone
; /* if_clone allocation zone */
1284 int (*ifc_create
)(struct if_clone
*, u_int32_t
, void *);
1285 int (*ifc_destroy
)(struct ifnet
*);
1288 #define IF_CLONE_INITIALIZER(name, create, destroy, minifs, maxunit, zone_max_elem, softc_size) { \
1289 .ifc_list = { NULL, NULL }, \
1292 .ifc_namelen = (sizeof (name) - 1), \
1293 .ifc_minifs = minifs, \
1294 .ifc_maxunit = maxunit, \
1295 .ifc_units = NULL, \
1297 .ifc_zone_max_elem = zone_max_elem, \
1298 .ifc_softc_size = softc_size, \
1300 .ifc_create = create, \
1301 .ifc_destroy = destroy \
1304 #define M_CLONE M_IFADDR
1307 * Macros to manipulate ifqueue. Users of these macros are responsible
1308 * for serialization, by holding whatever lock is appropriate for the
1309 * corresponding structure that is referring the ifqueue.
1311 #define IF_QFULL(ifq) ((ifq)->ifq_len >= (ifq)->ifq_maxlen)
1312 #define IF_DROP(ifq) ((ifq)->ifq_drops++)
1314 #define IF_ENQUEUE(ifq, m) do { \
1315 (m)->m_nextpkt = NULL; \
1316 if ((ifq)->ifq_tail == NULL) \
1317 (ifq)->ifq_head = m; \
1319 ((struct mbuf*)(ifq)->ifq_tail)->m_nextpkt = m; \
1320 (ifq)->ifq_tail = m; \
1324 #define IF_PREPEND(ifq, m) do { \
1325 (m)->m_nextpkt = (ifq)->ifq_head; \
1326 if ((ifq)->ifq_tail == NULL) \
1327 (ifq)->ifq_tail = (m); \
1328 (ifq)->ifq_head = (m); \
1332 #define IF_DEQUEUE(ifq, m) do { \
1333 (m) = (ifq)->ifq_head; \
1335 if (((ifq)->ifq_head = (m)->m_nextpkt) == NULL) \
1336 (ifq)->ifq_tail = NULL; \
1337 (m)->m_nextpkt = NULL; \
1342 #define IF_REMQUEUE(ifq, m) do { \
1343 struct mbuf *_p = (ifq)->ifq_head; \
1344 struct mbuf *_n = (m)->m_nextpkt; \
1347 while (_p != NULL) { \
1348 if (_p->m_nextpkt == (m)) \
1350 _p = _p->m_nextpkt; \
1352 VERIFY(_p != NULL || ((m) == (ifq)->ifq_head)); \
1353 if ((m) == (ifq)->ifq_head) \
1354 (ifq)->ifq_head = _n; \
1355 if ((m) == (ifq)->ifq_tail) \
1356 (ifq)->ifq_tail = _p; \
1357 VERIFY((ifq)->ifq_tail != NULL || (ifq)->ifq_head == NULL); \
1358 VERIFY((ifq)->ifq_len != 0); \
1361 _p->m_nextpkt = _n; \
1362 (m)->m_nextpkt = NULL; \
1365 #define IF_DRAIN(ifq) do { \
1368 IF_DEQUEUE(ifq, _m); \
1376 * The ifaddr structure contains information about one address
1377 * of an interface. They are maintained by the different address families,
1378 * are allocated and attached when an address is set, and are linked
1379 * together so all addresses for an interface can be located.
1382 decl_lck_mtx_data(, ifa_lock
); /* lock for ifaddr */
1383 uint32_t ifa_refcnt
; /* ref count, use IFA_{ADD,REM}REF */
1384 uint32_t ifa_debug
; /* debug flags */
1385 struct sockaddr
*ifa_addr
; /* address of interface */
1386 struct sockaddr
*ifa_dstaddr
; /* other end of p-to-p link */
1387 #define ifa_broadaddr ifa_dstaddr /* broadcast address interface */
1388 struct sockaddr
*ifa_netmask
; /* used to determine subnet */
1389 struct ifnet
*ifa_ifp
; /* back-pointer to interface */
1390 TAILQ_ENTRY(ifaddr
) ifa_link
; /* queue macro glue */
1391 void (*ifa_rtrequest
) /* check or clean routes (+ or -)'d */
1392 (int, struct rtentry
*, struct sockaddr
*);
1393 uint32_t ifa_flags
; /* mostly rt_flags for cloning */
1394 int32_t ifa_metric
; /* cost of going out this interface */
1395 void (*ifa_free
)(struct ifaddr
*); /* callback fn for freeing */
1396 void (*ifa_trace
) /* callback fn for tracing refs */
1397 (struct ifaddr
*, int);
1398 void (*ifa_attached
)(struct ifaddr
*); /* callback fn for attaching */
1399 void (*ifa_detached
)(struct ifaddr
*); /* callback fn for detaching */
1400 void *ifa_del_wc
; /* Wait channel to avoid address deletion races */
1401 int ifa_del_waiters
; /* Threads in wait to delete the address */
1402 #if __arm__ && (__BIGGEST_ALIGNMENT__ > 4)
1403 /* For the newer ARMv7k ABI where 64-bit types are 64-bit aligned, but pointers
1405 * Align to 64-bit since we cast to this to struct in6_ifaddr, which is
1408 } __attribute__ ((aligned(8)));
1415 * Valid values for ifa_flags
1417 #define IFA_ROUTE RTF_UP /* route installed (0x1) */
1418 #define IFA_CLONING RTF_CLONING /* (0x100) */
1421 * Valid values for ifa_debug
1423 #define IFD_ATTACHED 0x1 /* attached to list */
1424 #define IFD_ALLOC 0x2 /* dynamically allocated */
1425 #define IFD_DEBUG 0x4 /* has debugging info */
1426 #define IFD_LINK 0x8 /* link address */
1427 #define IFD_TRASHED 0x10 /* in trash list */
1428 #define IFD_DETACHING 0x20 /* detach is in progress */
1429 #define IFD_NOTREADY 0x40 /* embryonic; not yet ready */
1431 #define IFA_LOCK_ASSERT_HELD(_ifa) \
1432 LCK_MTX_ASSERT(&(_ifa)->ifa_lock, LCK_MTX_ASSERT_OWNED)
1434 #define IFA_LOCK_ASSERT_NOTHELD(_ifa) \
1435 LCK_MTX_ASSERT(&(_ifa)->ifa_lock, LCK_MTX_ASSERT_NOTOWNED)
1437 #define IFA_LOCK(_ifa) \
1438 lck_mtx_lock(&(_ifa)->ifa_lock)
1440 #define IFA_LOCK_SPIN(_ifa) \
1441 lck_mtx_lock_spin(&(_ifa)->ifa_lock)
1443 #define IFA_CONVERT_LOCK(_ifa) do { \
1444 IFA_LOCK_ASSERT_HELD(_ifa); \
1445 lck_mtx_convert_spin(&(_ifa)->ifa_lock); \
1448 #define IFA_UNLOCK(_ifa) \
1449 lck_mtx_unlock(&(_ifa)->ifa_lock)
1451 #define IFA_ADDREF(_ifa) \
1454 #define IFA_ADDREF_LOCKED(_ifa) \
1457 #define IFA_REMREF(_ifa) do { \
1458 (void) ifa_remref(_ifa, 0); \
1461 #define IFA_REMREF_LOCKED(_ifa) \
1465 * Multicast address structure. This is analogous to the ifaddr
1466 * structure except that it keeps track of multicast addresses.
1467 * Also, the request count here is a count of requests for this
1468 * address, not a count of pointers to this structure; anonymous
1469 * membership(s) holds one outstanding request count.
1471 struct ifmultiaddr
{
1472 decl_lck_mtx_data(, ifma_lock
);
1473 u_int32_t ifma_refcount
; /* reference count */
1474 u_int32_t ifma_anoncnt
; /* # of anonymous requests */
1475 u_int32_t ifma_reqcnt
; /* total requests for this address */
1476 u_int32_t ifma_debug
; /* see ifa_debug flags */
1477 u_int32_t ifma_flags
; /* see below */
1478 LIST_ENTRY(ifmultiaddr
) ifma_link
; /* queue macro glue */
1479 struct sockaddr
*ifma_addr
; /* address this membership is for */
1480 struct ifmultiaddr
*ifma_ll
; /* link-layer translation, if any */
1481 struct ifnet
*ifma_ifp
; /* back-pointer to interface */
1482 void *ifma_protospec
; /* protocol-specific state, if any */
1483 void (*ifma_trace
) /* callback fn for tracing refs */
1484 (struct ifmultiaddr
*, int);
1488 * Values for ifma_flags
1490 #define IFMAF_ANONYMOUS 0x1 /* has anonymous request ref(s) held */
1492 #define IFMA_LOCK_ASSERT_HELD(_ifma) \
1493 LCK_MTX_ASSERT(&(_ifma)->ifma_lock, LCK_MTX_ASSERT_OWNED)
1495 #define IFMA_LOCK_ASSERT_NOTHELD(_ifma) \
1496 LCK_MTX_ASSERT(&(_ifma)->ifma_lock, LCK_MTX_ASSERT_NOTOWNED)
1498 #define IFMA_LOCK(_ifma) \
1499 lck_mtx_lock(&(_ifma)->ifma_lock)
1501 #define IFMA_LOCK_SPIN(_ifma) \
1502 lck_mtx_lock_spin(&(_ifma)->ifma_lock)
1504 #define IFMA_CONVERT_LOCK(_ifma) do { \
1505 IFMA_LOCK_ASSERT_HELD(_ifma); \
1506 lck_mtx_convert_spin(&(_ifma)->ifma_lock); \
1509 #define IFMA_UNLOCK(_ifma) \
1510 lck_mtx_unlock(&(_ifma)->ifma_lock)
1512 #define IFMA_ADDREF(_ifma) \
1513 ifma_addref(_ifma, 0)
1515 #define IFMA_ADDREF_LOCKED(_ifma) \
1516 ifma_addref(_ifma, 1)
1518 #define IFMA_REMREF(_ifma) \
1522 * Indicate whether or not the immediate interface, or the interface delegated
1523 * by it, is a cellular interface (IFT_CELLULAR). Delegated interface type is
1524 * set/cleared along with the delegated ifp; we cache the type for performance
1525 * to avoid dereferencing delegated ifp each time.
1527 * Note that this is meant to be used only for accounting and policy purposes;
1528 * certain places need to explicitly know the immediate interface type, and
1529 * this macro should not be used there.
1531 * The test is done against IFT_CELLULAR instead of IFNET_FAMILY_CELLULAR to
1532 * handle certain cases where the family isn't set to the latter.
1534 #define IFNET_IS_CELLULAR(_ifp) \
1535 ((_ifp)->if_type == IFT_CELLULAR || \
1536 (_ifp)->if_delegated.type == IFT_CELLULAR)
1539 * Indicate whether or not the immediate interface, or the interface delegated
1540 * by it, is an ETHERNET interface.
1542 #define IFNET_IS_ETHERNET(_ifp) \
1543 ((_ifp)->if_family == IFNET_FAMILY_ETHERNET || \
1544 (_ifp)->if_delegated.family == IFNET_FAMILY_ETHERNET)
1546 * Indicate whether or not the immediate interface, or the interface delegated
1547 * by it, is a Wi-Fi interface (IFNET_SUBFAMILY_WIFI). Delegated interface
1548 * subfamily is set/cleared along with the delegated ifp; we cache the subfamily
1549 * for performance to avoid dereferencing delegated ifp each time.
1551 * Note that this is meant to be used only for accounting and policy purposes;
1552 * certain places need to explicitly know the immediate interface type, and
1553 * this macro should not be used there.
1555 * The test is done against IFNET_SUBFAMILY_WIFI as the family may be set to
1556 * IFNET_FAMILY_ETHERNET (as well as type to IFT_ETHER) which is too generic.
1558 #define IFNET_IS_WIFI(_ifp) \
1559 (((_ifp)->if_family == IFNET_FAMILY_ETHERNET && \
1560 (_ifp)->if_subfamily == IFNET_SUBFAMILY_WIFI) || \
1561 ((_ifp)->if_delegated.family == IFNET_FAMILY_ETHERNET && \
1562 (_ifp)->if_delegated.subfamily == IFNET_SUBFAMILY_WIFI))
1565 * Indicate whether or not the immediate interface, or the interface delegated
1566 * by it, is a Wired interface (several families). Delegated interface
1567 * family is set/cleared along with the delegated ifp; we cache the family
1568 * for performance to avoid dereferencing delegated ifp each time.
1570 * Note that this is meant to be used only for accounting and policy purposes;
1571 * certain places need to explicitly know the immediate interface type, and
1572 * this macro should not be used there.
1574 #define IFNET_IS_WIRED(_ifp) \
1575 ((_ifp)->if_family == IFNET_FAMILY_ETHERNET || \
1576 (_ifp)->if_delegated.family == IFNET_FAMILY_ETHERNET || \
1577 (_ifp)->if_family == IFNET_FAMILY_FIREWIRE || \
1578 (_ifp)->if_delegated.family == IFNET_FAMILY_FIREWIRE)
1581 * Indicate whether or not the immediate WiFi interface is on an infrastructure
1584 #define IFNET_IS_WIFI_INFRA(_ifp) \
1585 ((_ifp)->if_family == IFNET_FAMILY_ETHERNET && \
1586 (_ifp)->if_subfamily == IFNET_SUBFAMILY_WIFI && \
1587 !((_ifp)->if_eflags & IFEF_AWDL))
1590 * Indicate whether or not the immediate interface is a companion link
1593 #define IFNET_IS_COMPANION_LINK(_ifp) \
1594 ((_ifp)->if_family == IFNET_FAMILY_IPSEC && \
1595 ((_ifp)->if_subfamily == IFNET_SUBFAMILY_BLUETOOTH || \
1596 (_ifp)->if_subfamily == IFNET_SUBFAMILY_WIFI || \
1597 (_ifp)->if_subfamily == IFNET_SUBFAMILY_QUICKRELAY || \
1598 (_ifp)->if_subfamily == IFNET_SUBFAMILY_DEFAULT))
1601 * Indicate whether or not the immediate interface, or the interface delegated
1602 * by it, is marked as expensive. The delegated interface is set/cleared
1603 * along with the delegated ifp; we cache the flag for performance to avoid
1604 * dereferencing delegated ifp each time.
1606 * Note that this is meant to be used only for policy purposes.
1608 #define IFNET_IS_EXPENSIVE(_ifp) \
1609 ((_ifp)->if_eflags & IFEF_EXPENSIVE || \
1610 (_ifp)->if_delegated.expensive)
1612 #define IFNET_IS_LOW_POWER(_ifp) \
1613 (if_low_power_restricted != 0 && \
1614 ((_ifp)->if_xflags & IFXF_LOW_POWER) || \
1615 ((_ifp)->if_delegated.ifp != NULL && \
1616 ((_ifp)->if_delegated.ifp->if_xflags & IFXF_LOW_POWER)))
1618 #define IFNET_IS_CONSTRAINED(_ifp) \
1619 ((_ifp)->if_xflags & IFXF_CONSTRAINED || \
1620 (_ifp)->if_delegated.constrained)
1623 * We don't support AWDL interface delegation.
1625 #define IFNET_IS_AWDL_RESTRICTED(_ifp) \
1626 (((_ifp)->if_eflags & (IFEF_AWDL|IFEF_AWDL_RESTRICTED)) == \
1627 (IFEF_AWDL|IFEF_AWDL_RESTRICTED))
1629 #define IFNET_IS_INTCOPROC(_ifp) \
1630 ((_ifp)->if_family == IFNET_FAMILY_ETHERNET && \
1631 (_ifp)->if_subfamily == IFNET_SUBFAMILY_INTCOPROC)
1633 extern struct ifnethead ifnet_head
;
1634 extern struct ifnethead ifnet_ordered_head
;
1635 extern struct ifnet
**ifindex2ifnet
;
1636 extern u_int32_t if_sndq_maxlen
;
1637 extern u_int32_t if_rcvq_maxlen
;
1638 extern int if_index
;
1639 extern struct ifaddr
**ifnet_addrs
;
1640 extern lck_attr_t
*ifa_mtx_attr
;
1641 extern lck_grp_t
*ifa_mtx_grp
;
1642 extern lck_grp_t
*ifnet_lock_group
;
1643 extern lck_attr_t
*ifnet_lock_attr
;
1644 extern ifnet_t lo_ifp
;
1646 extern int if_addmulti(struct ifnet
*, const struct sockaddr
*,
1647 struct ifmultiaddr
**);
1648 extern int if_addmulti_anon(struct ifnet
*, const struct sockaddr
*,
1649 struct ifmultiaddr
**);
1650 extern int if_allmulti(struct ifnet
*, int);
1651 extern int if_delmulti(struct ifnet
*, const struct sockaddr
*);
1652 extern int if_delmulti_ifma(struct ifmultiaddr
*);
1653 extern int if_delmulti_anon(struct ifnet
*, const struct sockaddr
*);
1654 extern void if_down(struct ifnet
*);
1655 extern int if_down_all(void);
1656 extern void if_up(struct ifnet
*);
1657 __private_extern__
void if_updown(struct ifnet
*ifp
, int up
);
1658 extern int ifioctl(struct socket
*, u_long
, caddr_t
, struct proc
*);
1659 extern int ifioctllocked(struct socket
*, u_long
, caddr_t
, struct proc
*);
1660 extern struct ifnet
*ifunit(const char *);
1661 extern struct ifnet
*ifunit_ref(const char *);
1662 extern int ifunit_extract(const char *src
, char *dst
, size_t dstlen
, int *unit
);
1663 extern struct ifnet
*if_withname(struct sockaddr
*);
1664 extern void if_qflush(struct ifnet
*, int);
1665 extern void if_qflush_sc(struct ifnet
*, mbuf_svc_class_t
, u_int32_t
,
1666 u_int32_t
*, u_int32_t
*, int);
1668 extern struct if_clone
*if_clone_lookup(const char *, u_int32_t
*);
1669 extern int if_clone_attach(struct if_clone
*);
1670 extern void if_clone_detach(struct if_clone
*);
1671 extern void *if_clone_softc_allocate(const struct if_clone
*);
1672 extern void if_clone_softc_deallocate(const struct if_clone
*, void *);
1673 extern u_int32_t
if_functional_type(struct ifnet
*, bool);
1675 extern errno_t
if_mcasts_update(struct ifnet
*);
1678 IFNET_LCK_ASSERT_EXCLUSIVE
, /* RW: held as writer */
1679 IFNET_LCK_ASSERT_SHARED
, /* RW: held as reader */
1680 IFNET_LCK_ASSERT_OWNED
, /* RW: writer/reader, MTX: held */
1681 IFNET_LCK_ASSERT_NOTOWNED
/* not held */
1682 } ifnet_lock_assert_t
;
1684 #define IF_LLADDR(_ifp) \
1685 (LLADDR(SDL(((_ifp)->if_lladdr)->ifa_addr)))
1687 #define IF_INDEX_IN_RANGE(_ind_) ((_ind_) > 0 && \
1688 (unsigned int)(_ind_) <= (unsigned int)if_index)
1690 __private_extern__
void ifnet_lock_assert(struct ifnet
*, ifnet_lock_assert_t
);
1691 __private_extern__
void ifnet_lock_shared(struct ifnet
*ifp
);
1692 __private_extern__
void ifnet_lock_exclusive(struct ifnet
*ifp
);
1693 __private_extern__
void ifnet_lock_done(struct ifnet
*ifp
);
1696 __private_extern__
void if_inetdata_lock_shared(struct ifnet
*ifp
);
1697 __private_extern__
void if_inetdata_lock_exclusive(struct ifnet
*ifp
);
1698 __private_extern__
void if_inetdata_lock_done(struct ifnet
*ifp
);
1701 __private_extern__
void if_inet6data_lock_shared(struct ifnet
*ifp
);
1702 __private_extern__
void if_inet6data_lock_exclusive(struct ifnet
*ifp
);
1703 __private_extern__
void if_inet6data_lock_done(struct ifnet
*ifp
);
1705 __private_extern__
void ifnet_head_lock_shared(void);
1706 __private_extern__
void ifnet_head_lock_exclusive(void);
1707 __private_extern__
void ifnet_head_done(void);
1708 __private_extern__
void ifnet_head_assert_exclusive(void);
1710 __private_extern__ errno_t
ifnet_set_idle_flags_locked(ifnet_t
, u_int32_t
,
1712 __private_extern__
int ifnet_is_attached(struct ifnet
*, int refio
);
1713 __private_extern__
void ifnet_incr_pending_thread_count(struct ifnet
*);
1714 __private_extern__
void ifnet_decr_pending_thread_count(struct ifnet
*);
1715 __private_extern__
void ifnet_incr_iorefcnt(struct ifnet
*);
1716 __private_extern__
void ifnet_decr_iorefcnt(struct ifnet
*);
1717 __private_extern__ boolean_t
ifnet_datamov_begin(struct ifnet
*);
1718 __private_extern__
void ifnet_datamov_end(struct ifnet
*);
1719 __private_extern__
void ifnet_datamov_suspend(struct ifnet
*);
1720 __private_extern__
void ifnet_datamov_drain(struct ifnet
*);
1721 __private_extern__
void ifnet_datamov_resume(struct ifnet
*);
1722 __private_extern__
void ifnet_set_start_cycle(struct ifnet
*,
1724 __private_extern__
void ifnet_set_poll_cycle(struct ifnet
*,
1727 __private_extern__
void if_attach_ifa(struct ifnet
*, struct ifaddr
*);
1728 __private_extern__
void if_attach_link_ifa(struct ifnet
*, struct ifaddr
*);
1729 __private_extern__
void if_detach_ifa(struct ifnet
*, struct ifaddr
*);
1730 __private_extern__
void if_detach_link_ifa(struct ifnet
*, struct ifaddr
*);
1732 __private_extern__
void dlil_if_lock(void);
1733 __private_extern__
void dlil_if_unlock(void);
1734 __private_extern__
void dlil_if_lock_assert(void);
1736 extern struct ifaddr
*ifa_ifwithaddr(const struct sockaddr
*);
1737 extern struct ifaddr
*ifa_ifwithaddr_locked(const struct sockaddr
*);
1738 extern struct ifaddr
*ifa_ifwithaddr_scoped(const struct sockaddr
*,
1740 extern struct ifaddr
*ifa_ifwithaddr_scoped_locked(const struct sockaddr
*,
1742 extern struct ifaddr
*ifa_ifwithdstaddr(const struct sockaddr
*);
1743 extern struct ifaddr
*ifa_ifwithnet(const struct sockaddr
*);
1744 extern struct ifaddr
*ifa_ifwithnet_scoped(const struct sockaddr
*,
1746 extern struct ifaddr
*ifa_ifwithroute(int, const struct sockaddr
*,
1747 const struct sockaddr
*);
1748 extern struct ifaddr
*ifa_ifwithroute_locked(int, const struct sockaddr
*,
1749 const struct sockaddr
*);
1750 extern struct ifaddr
*ifa_ifwithroute_scoped_locked(int,
1751 const struct sockaddr
*, const struct sockaddr
*, unsigned int);
1752 extern struct ifaddr
*ifaof_ifpforaddr_select(const struct sockaddr
*, struct ifnet
*);
1753 extern struct ifaddr
*ifaof_ifpforaddr(const struct sockaddr
*, struct ifnet
*);
1754 __private_extern__
struct ifaddr
*ifa_ifpgetprimary(struct ifnet
*, int);
1755 extern void ifa_addref(struct ifaddr
*, int);
1756 extern struct ifaddr
*ifa_remref(struct ifaddr
*, int);
1757 extern void ifa_lock_init(struct ifaddr
*);
1758 extern void ifa_lock_destroy(struct ifaddr
*);
1759 extern void ifma_addref(struct ifmultiaddr
*, int);
1760 extern void ifma_remref(struct ifmultiaddr
*);
1762 extern void ifa_init(void);
1764 __private_extern__
struct in_ifaddr
*ifa_foraddr(unsigned int);
1765 __private_extern__
struct in_ifaddr
*ifa_foraddr_scoped(unsigned int,
1769 extern errno_t
ifnet_getset_opportunistic(struct ifnet
*, u_long
,
1770 struct ifreq
*, struct proc
*);
1771 extern int ifnet_get_throttle(struct ifnet
*, u_int32_t
*);
1772 extern int ifnet_set_throttle(struct ifnet
*, u_int32_t
);
1773 extern errno_t
ifnet_getset_log(struct ifnet
*, u_long
,
1774 struct ifreq
*, struct proc
*);
1775 extern int ifnet_set_log(struct ifnet
*, int32_t, uint32_t, int32_t, int32_t);
1776 extern int ifnet_get_log(struct ifnet
*, int32_t *, uint32_t *, int32_t *,
1778 extern int ifnet_notify_address(struct ifnet
*, int);
1779 extern void ifnet_notify_data_threshold(struct ifnet
*);
1781 #define IF_AFDATA_RLOCK if_afdata_rlock
1782 #define IF_AFDATA_RUNLOCK if_afdata_unlock
1783 #define IF_AFDATA_WLOCK if_afdata_wlock
1784 #define IF_AFDATA_WUNLOCK if_afdata_unlock
1785 #define IF_AFDATA_WLOCK_ASSERT if_afdata_wlock_assert
1786 #define IF_AFDATA_LOCK_ASSERT if_afdata_lock_assert
1787 #define IF_AFDATA_UNLOCK_ASSERT if_afdata_unlock_assert
1790 if_afdata_rlock(struct ifnet
*ifp
, int af
)
1795 lck_rw_lock_shared(&ifp
->if_inetdata_lock
);
1799 lck_rw_lock_shared(&ifp
->if_inet6data_lock
);
1809 if_afdata_runlock(struct ifnet
*ifp
, int af
)
1814 lck_rw_done(&ifp
->if_inetdata_lock
);
1818 lck_rw_done(&ifp
->if_inet6data_lock
);
1828 if_afdata_wlock(struct ifnet
*ifp
, int af
)
1833 lck_rw_lock_exclusive(&ifp
->if_inetdata_lock
);
1837 lck_rw_lock_exclusive(&ifp
->if_inet6data_lock
);
1847 if_afdata_unlock(struct ifnet
*ifp
, int af
)
1852 lck_rw_done(&ifp
->if_inetdata_lock
);
1856 lck_rw_done(&ifp
->if_inet6data_lock
);
1866 if_afdata_wlock_assert(struct ifnet
*ifp
, int af
)
1874 LCK_RW_ASSERT(&ifp
->if_inetdata_lock
, LCK_RW_ASSERT_EXCLUSIVE
);
1878 LCK_RW_ASSERT(&ifp
->if_inet6data_lock
, LCK_RW_ASSERT_EXCLUSIVE
);
1888 if_afdata_unlock_assert(struct ifnet
*ifp
, int af
)
1896 LCK_RW_ASSERT(&ifp
->if_inetdata_lock
, LCK_RW_ASSERT_NOTHELD
);
1900 LCK_RW_ASSERT(&ifp
->if_inet6data_lock
, LCK_RW_ASSERT_NOTHELD
);
1910 if_afdata_lock_assert(struct ifnet
*ifp
, int af
)
1918 LCK_RW_ASSERT(&ifp
->if_inetdata_lock
, LCK_RW_ASSERT_HELD
);
1922 LCK_RW_ASSERT(&ifp
->if_inet6data_lock
, LCK_RW_ASSERT_HELD
);
1932 __private_extern__
struct in6_ifaddr
*ifa_foraddr6(struct in6_addr
*);
1933 __private_extern__
struct in6_ifaddr
*ifa_foraddr6_scoped(struct in6_addr
*,
1936 __private_extern__
void if_data_internal_to_if_data(struct ifnet
*ifp
,
1937 const struct if_data_internal
*if_data_int
, struct if_data
*if_data
);
1938 __private_extern__
void if_data_internal_to_if_data64(struct ifnet
*ifp
,
1939 const struct if_data_internal
*if_data_int
, struct if_data64
*if_data64
);
1940 __private_extern__
void if_copy_traffic_class(struct ifnet
*ifp
,
1941 struct if_traffic_class
*if_tc
);
1942 __private_extern__
void if_copy_data_extended(struct ifnet
*ifp
,
1943 struct if_data_extended
*if_de
);
1944 __private_extern__
void if_copy_packet_stats(struct ifnet
*ifp
,
1945 struct if_packet_stats
*if_ps
);
1946 __private_extern__
void if_copy_rxpoll_stats(struct ifnet
*ifp
,
1947 struct if_rxpoll_stats
*if_rs
);
1948 __private_extern__
void if_copy_netif_stats(struct ifnet
*ifp
,
1949 struct if_netif_stats
*if_ns
);
1951 __private_extern__
struct rtentry
*ifnet_cached_rtlookup_inet(struct ifnet
*,
1953 __private_extern__
struct rtentry
*ifnet_cached_rtlookup_inet6(struct ifnet
*,
1956 __private_extern__ u_int32_t
if_get_protolist(struct ifnet
* ifp
,
1957 u_int32_t
*protolist
, u_int32_t count
);
1958 __private_extern__
void if_free_protolist(u_int32_t
*list
);
1959 __private_extern__ errno_t
if_state_update(struct ifnet
*,
1960 struct if_interface_state
*);
1961 __private_extern__
void if_get_state(struct ifnet
*,
1962 struct if_interface_state
*);
1963 __private_extern__ errno_t
if_probe_connectivity(struct ifnet
*ifp
,
1964 u_int32_t conn_probe
);
1965 __private_extern__
void if_lqm_update(struct ifnet
*, int32_t, int);
1966 __private_extern__
void ifnet_update_sndq(struct ifclassq
*, cqev_t
);
1967 __private_extern__
void ifnet_update_rcv(struct ifnet
*, cqev_t
);
1969 __private_extern__
void ifnet_flowadv(uint32_t);
1971 __private_extern__ errno_t
ifnet_set_input_bandwidths(struct ifnet
*,
1972 struct if_bandwidths
*);
1973 __private_extern__ errno_t
ifnet_set_output_bandwidths(struct ifnet
*,
1974 struct if_bandwidths
*, boolean_t
);
1975 __private_extern__ u_int64_t
ifnet_output_linkrate(struct ifnet
*);
1976 __private_extern__ u_int64_t
ifnet_input_linkrate(struct ifnet
*);
1978 __private_extern__ errno_t
ifnet_set_input_latencies(struct ifnet
*,
1979 struct if_latencies
*);
1980 __private_extern__ errno_t
ifnet_set_output_latencies(struct ifnet
*,
1981 struct if_latencies
*, boolean_t
);
1983 __private_extern__
void ifnet_clear_netagent(uuid_t
);
1985 __private_extern__
int ifnet_set_netsignature(struct ifnet
*, uint8_t,
1986 uint8_t, uint16_t, uint8_t *);
1987 __private_extern__
int ifnet_get_netsignature(struct ifnet
*, uint8_t,
1988 uint8_t *, uint16_t *, uint8_t *);
1991 __private_extern__
int ifnet_set_nat64prefix(struct ifnet
*,
1992 struct ipv6_prefix
*);
1993 __private_extern__
int ifnet_get_nat64prefix(struct ifnet
*,
1994 struct ipv6_prefix
*);
1996 /* Required exclusive ifnet_head lock */
1997 __private_extern__
void ifnet_remove_from_ordered_list(struct ifnet
*);
1999 __private_extern__
void ifnet_increment_generation(struct ifnet
*);
2000 __private_extern__ u_int32_t
ifnet_get_generation(struct ifnet
*);
2002 /* Adding and deleting netagents will take ifnet lock */
2003 __private_extern__
int if_add_netagent(struct ifnet
*, uuid_t
);
2004 __private_extern__
int if_add_netagent_locked(struct ifnet
*, uuid_t
);
2005 __private_extern__
int if_delete_netagent(struct ifnet
*, uuid_t
);
2006 __private_extern__ boolean_t
if_check_netagent(struct ifnet
*, uuid_t
);
2009 extern int if_set_qosmarking_mode(struct ifnet
*, u_int32_t
);
2010 __private_extern__
uint32_t ifnet_mbuf_packetpreamblelen(struct ifnet
*);
2011 __private_extern__
void intf_event_enqueue_nwk_wq_entry(struct ifnet
*ifp
,
2012 struct sockaddr
*addrp
, uint32_t intf_event_code
);
2013 __private_extern__
void ifnet_update_stats_per_flow(struct ifnet_stats_per_flow
*,
2015 __private_extern__
int if_get_tcp_kao_max(struct ifnet
*);
2016 #if XNU_TARGET_OS_OSX
2017 __private_extern__ errno_t
ifnet_framer_stub(struct ifnet
*, struct mbuf
**,
2018 const struct sockaddr
*, const char *, const char *, u_int32_t
*,
2020 #endif /* XNU_TARGET_OS_OSX */
2021 __private_extern__
void ifnet_enqueue_multi_setup(struct ifnet
*, uint16_t,
2023 __private_extern__ errno_t
ifnet_enqueue_mbuf(struct ifnet
*, struct mbuf
*,
2024 boolean_t
, boolean_t
*);
2025 __private_extern__ errno_t
ifnet_enqueue_mbuf_chain(struct ifnet
*,
2026 struct mbuf
*, struct mbuf
*, uint32_t, uint32_t, boolean_t
, boolean_t
*);
2027 __private_extern__
int ifnet_enqueue_netem(void *handle
, pktsched_pkt_t
*pkts
,
2030 extern int if_low_power_verbose
;
2031 extern int if_low_power_restricted
;
2032 extern void if_low_power_evhdlr_init(void);
2033 extern int if_set_low_power(struct ifnet
*, bool);
2034 extern u_int32_t
if_set_eflags(ifnet_t
, u_int32_t
);
2035 extern void if_clear_eflags(ifnet_t
, u_int32_t
);
2036 extern u_int32_t
if_set_xflags(ifnet_t
, u_int32_t
);
2037 extern void if_clear_xflags(ifnet_t
, u_int32_t
);
2039 #endif /* BSD_KERNEL_PRIVATE */
2040 #ifdef XNU_KERNEL_PRIVATE
2042 __private_extern__
int uuid_get_ethernet(u_int8_t
*);
2043 #endif /* XNU_KERNEL_PRIVATE */
2044 #endif /* !_NET_IF_VAR_H_ */