2 * Copyright (c) 2000-2015 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>
80 #include <net/kpi_interface.h>
84 #define APPLE_IF_FAM_LOOPBACK 1
85 #define APPLE_IF_FAM_ETHERNET 2
86 #define APPLE_IF_FAM_SLIP 3
87 #define APPLE_IF_FAM_TUN 4
88 #define APPLE_IF_FAM_VLAN 5
89 #define APPLE_IF_FAM_PPP 6
90 #define APPLE_IF_FAM_PVC 7
91 #define APPLE_IF_FAM_DISC 8
92 #define APPLE_IF_FAM_MDECAP 9
93 #define APPLE_IF_FAM_GIF 10
94 #define APPLE_IF_FAM_FAITH 11 /* deprecated */
95 #define APPLE_IF_FAM_STF 12
96 #define APPLE_IF_FAM_FIREWIRE 13
97 #define APPLE_IF_FAM_BOND 14
98 #endif /* __APPLE__ */
101 * 72 was chosen below because it is the size of a TCP/IP
102 * header (40) + the minimum mss (32).
105 #define IF_MAXMTU 65535
108 * Structures defining a network interface, providing a packet
109 * transport mechanism (ala level 0 of the PUP protocols).
111 * Each interface accepts output datagrams of a specified maximum
112 * length, and provides higher level routines with input datagrams
113 * received from its medium.
115 * Output occurs when the routine if_output is called, with three parameters:
116 * (*ifp->if_output)(ifp, m, dst, rt)
117 * Here m is the mbuf chain to be sent and dst is the destination address.
118 * The output routine encapsulates the supplied datagram if necessary,
119 * and then transmits it on its medium.
121 * On input, each interface unwraps the data received by it, and either
122 * places it on the input queue of a internetwork datagram routine
123 * and posts the associated software interrupt, or passes the datagram to a raw
124 * packet input routine.
126 * Routines exist for locating interfaces by their addresses
127 * or for locating a interface on a certain network, as well as more general
128 * routing and gateway routines maintaining information used to locate
129 * interfaces. These routines live in the files if.c and route.c
134 /* This belongs up in socket.h or socketvar.h, depending on how far the
138 struct net_event_data
{
141 char if_name
[IFNAMSIZ
];
144 #if defined(__LP64__)
145 #include <sys/_types/_timeval32.h>
146 #define IF_DATA_TIMEVAL timeval32
148 #define IF_DATA_TIMEVAL timeval
154 * Structure describing information about an interface
155 * which may be of interest to management entities.
158 /* generic interface information */
159 u_char ifi_type
; /* ethernet, tokenring, etc */
160 u_char ifi_typelen
; /* Length of frame type id */
161 u_char ifi_physical
; /* e.g., AUI, Thinnet, 10base-T, etc */
162 u_char ifi_addrlen
; /* media address length */
163 u_char ifi_hdrlen
; /* media header length */
164 u_char ifi_recvquota
; /* polling quota for receive intrs */
165 u_char ifi_xmitquota
; /* polling quota for xmit intrs */
166 u_char ifi_unused1
; /* for future use */
167 u_int32_t ifi_mtu
; /* maximum transmission unit */
168 u_int32_t ifi_metric
; /* routing metric (external only) */
169 u_int32_t ifi_baudrate
; /* linespeed */
170 /* volatile statistics */
171 u_int32_t ifi_ipackets
; /* packets received on interface */
172 u_int32_t ifi_ierrors
; /* input errors on interface */
173 u_int32_t ifi_opackets
; /* packets sent on interface */
174 u_int32_t ifi_oerrors
; /* output errors on interface */
175 u_int32_t ifi_collisions
; /* collisions on csma interfaces */
176 u_int32_t ifi_ibytes
; /* total number of octets received */
177 u_int32_t ifi_obytes
; /* total number of octets sent */
178 u_int32_t ifi_imcasts
; /* packets received via multicast */
179 u_int32_t ifi_omcasts
; /* packets sent via multicast */
180 u_int32_t ifi_iqdrops
; /* dropped on input, this interface */
181 u_int32_t ifi_noproto
; /* destined for unsupported protocol */
182 u_int32_t ifi_recvtiming
; /* usec spent receiving when timing */
183 u_int32_t ifi_xmittiming
; /* usec spent xmitting when timing */
184 struct IF_DATA_TIMEVAL ifi_lastchange
; /* time of last administrative change */
185 u_int32_t ifi_unused2
; /* used to be the default_proto */
186 u_int32_t ifi_hwassist
; /* HW offload capabilities */
187 u_int32_t ifi_reserved1
; /* for future use */
188 u_int32_t ifi_reserved2
; /* for future use */
192 * Structure describing information about an interface
193 * which may be of interest to management entities.
196 /* generic interface information */
197 u_char ifi_type
; /* ethernet, tokenring, etc */
198 u_char ifi_typelen
; /* Length of frame type id */
199 u_char ifi_physical
; /* e.g., AUI, Thinnet, 10base-T, etc */
200 u_char ifi_addrlen
; /* media address length */
201 u_char ifi_hdrlen
; /* media header length */
202 u_char ifi_recvquota
; /* polling quota for receive intrs */
203 u_char ifi_xmitquota
; /* polling quota for xmit intrs */
204 u_char ifi_unused1
; /* for future use */
205 u_int32_t ifi_mtu
; /* maximum transmission unit */
206 u_int32_t ifi_metric
; /* routing metric (external only) */
207 u_int64_t ifi_baudrate
; /* linespeed */
208 /* volatile statistics */
209 u_int64_t ifi_ipackets
; /* packets received on interface */
210 u_int64_t ifi_ierrors
; /* input errors on interface */
211 u_int64_t ifi_opackets
; /* packets sent on interface */
212 u_int64_t ifi_oerrors
; /* output errors on interface */
213 u_int64_t ifi_collisions
; /* collisions on csma interfaces */
214 u_int64_t ifi_ibytes
; /* total number of octets received */
215 u_int64_t ifi_obytes
; /* total number of octets sent */
216 u_int64_t ifi_imcasts
; /* packets received via multicast */
217 u_int64_t ifi_omcasts
; /* packets sent via multicast */
218 u_int64_t ifi_iqdrops
; /* dropped on input, this interface */
219 u_int64_t ifi_noproto
; /* destined for unsupported protocol */
220 u_int32_t ifi_recvtiming
; /* usec spent receiving when timing */
221 u_int32_t ifi_xmittiming
; /* usec spent xmitting when timing */
222 struct IF_DATA_TIMEVAL ifi_lastchange
; /* time of last administrative change */
226 struct if_traffic_class
{
227 u_int64_t ifi_ibepackets
; /* TC_BE packets received on interface */
228 u_int64_t ifi_ibebytes
; /* TC_BE bytes received on interface */
229 u_int64_t ifi_obepackets
; /* TC_BE packet sent on interface */
230 u_int64_t ifi_obebytes
; /* TC_BE bytes sent on interface */
231 u_int64_t ifi_ibkpackets
; /* TC_BK packets received on interface */
232 u_int64_t ifi_ibkbytes
; /* TC_BK bytes received on interface */
233 u_int64_t ifi_obkpackets
; /* TC_BK packet sent on interface */
234 u_int64_t ifi_obkbytes
; /* TC_BK bytes sent on interface */
235 u_int64_t ifi_ivipackets
; /* TC_VI packets received on interface */
236 u_int64_t ifi_ivibytes
; /* TC_VI bytes received on interface */
237 u_int64_t ifi_ovipackets
; /* TC_VI packets sent on interface */
238 u_int64_t ifi_ovibytes
; /* TC_VI bytes sent on interface */
239 u_int64_t ifi_ivopackets
; /* TC_VO packets received on interface */
240 u_int64_t ifi_ivobytes
; /* TC_VO bytes received on interface */
241 u_int64_t ifi_ovopackets
; /* TC_VO packets sent on interface */
242 u_int64_t ifi_ovobytes
; /* TC_VO bytes sent on interface */
243 u_int64_t ifi_ipvpackets
; /* TC priv packets received on interface */
244 u_int64_t ifi_ipvbytes
; /* TC priv bytes received on interface */
245 u_int64_t ifi_opvpackets
; /* TC priv packets sent on interface */
246 u_int64_t ifi_opvbytes
; /* TC priv bytes sent on interface */
249 struct if_data_extended
{
250 u_int64_t ifi_alignerrs
; /* unaligned (32-bit) input pkts */
251 u_int64_t ifi_dt_bytes
; /* Data threshold counter */
252 u_int64_t ifi_fpackets
; /* forwarded packets on interface */
253 u_int64_t ifi_fbytes
; /* forwarded bytes on interface */
254 u_int64_t reserved
[12]; /* for future */
257 struct if_packet_stats
{
259 u_int64_t ifi_tcp_badformat
;
260 u_int64_t ifi_tcp_unspecv6
;
261 u_int64_t ifi_tcp_synfin
;
262 u_int64_t ifi_tcp_badformatipsec
;
263 u_int64_t ifi_tcp_noconnnolist
;
264 u_int64_t ifi_tcp_noconnlist
;
265 u_int64_t ifi_tcp_listbadsyn
;
266 u_int64_t ifi_tcp_icmp6unreach
;
267 u_int64_t ifi_tcp_deprecate6
;
268 u_int64_t ifi_tcp_rstinsynrcv
;
269 u_int64_t ifi_tcp_ooopacket
;
270 u_int64_t ifi_tcp_dospacket
;
271 u_int64_t ifi_tcp_cleanup
;
272 u_int64_t ifi_tcp_synwindow
;
273 u_int64_t reserved
[6];
275 u_int64_t ifi_udp_port_unreach
;
276 u_int64_t ifi_udp_faithprefix
;
277 u_int64_t ifi_udp_port0
;
278 u_int64_t ifi_udp_badlength
;
279 u_int64_t ifi_udp_badchksum
;
280 u_int64_t ifi_udp_badmcast
;
281 u_int64_t ifi_udp_cleanup
;
282 u_int64_t ifi_udp_badipsec
;
283 u_int64_t _reserved
[4];
286 struct if_description
{
287 u_int32_t ifd_maxlen
; /* must be IF_DESCSIZE */
288 u_int32_t ifd_len
; /* actual ifd_desc length */
289 u_int8_t
*ifd_desc
; /* ptr to desc buffer */
292 struct if_bandwidths
{
293 u_int64_t eff_bw
; /* effective bandwidth */
294 u_int64_t max_bw
; /* maximum theoretical bandwidth */
297 struct if_latencies
{
298 u_int64_t eff_lt
; /* effective latency */
299 u_int64_t max_lt
; /* maximum theoretical latency */
302 struct if_rxpoll_stats
{
303 u_int32_t ifi_poll_off_req
; /* total # of POLL_OFF reqs */
304 u_int32_t ifi_poll_off_err
; /* total # of POLL_OFF errors */
305 u_int32_t ifi_poll_on_req
; /* total # of POLL_ON reqs */
306 u_int32_t ifi_poll_on_err
; /* total # of POLL_ON errors */
308 u_int32_t ifi_poll_wakeups_avg
; /* avg # of wakeup reqs */
309 u_int32_t ifi_poll_wakeups_lowat
; /* wakeups low watermark */
310 u_int32_t ifi_poll_wakeups_hiwat
; /* wakeups high watermark */
312 u_int64_t ifi_poll_packets
; /* total # of polled packets */
313 u_int32_t ifi_poll_packets_avg
; /* average polled packets */
314 u_int32_t ifi_poll_packets_min
; /* smallest polled packets */
315 u_int32_t ifi_poll_packets_max
; /* largest polled packets */
316 u_int32_t ifi_poll_packets_lowat
; /* packets low watermark */
317 u_int32_t ifi_poll_packets_hiwat
; /* packets high watermark */
319 u_int64_t ifi_poll_bytes
; /* total # of polled bytes */
320 u_int32_t ifi_poll_bytes_avg
; /* average polled bytes */
321 u_int32_t ifi_poll_bytes_min
; /* smallest polled bytes */
322 u_int32_t ifi_poll_bytes_max
; /* largest polled bytes */
323 u_int32_t ifi_poll_bytes_lowat
; /* bytes low watermark */
324 u_int32_t ifi_poll_bytes_hiwat
; /* bytes high watermark */
326 u_int32_t ifi_poll_packets_limit
; /* max packets per poll call */
327 u_int64_t ifi_poll_interval_time
; /* poll interval (nsec) */
330 struct if_tcp_ecn_perf_stat
{
331 u_int64_t total_txpkts
;
332 u_int64_t total_rxmitpkts
;
333 u_int64_t total_rxpkts
;
334 u_int64_t total_oopkts
;
335 u_int64_t total_reorderpkts
;
338 u_int64_t sack_episodes
;
339 u_int64_t rxmit_drop
;
341 u_int64_t oo_percent
;
342 u_int64_t reorder_percent
;
343 u_int64_t rxmit_percent
;
346 struct if_tcp_ecn_stat
{
348 u_int64_t ecn_client_setup
;
349 u_int64_t ecn_server_setup
;
350 u_int64_t ecn_client_success
;
351 u_int64_t ecn_server_success
;
352 u_int64_t ecn_peer_nosupport
;
353 u_int64_t ecn_syn_lost
;
354 u_int64_t ecn_synack_lost
;
355 u_int64_t ecn_recv_ce
;
356 u_int64_t ecn_recv_ece
;
357 u_int64_t ecn_conn_recv_ce
;
358 u_int64_t ecn_conn_recv_ece
;
359 u_int64_t ecn_conn_plnoce
;
360 u_int64_t ecn_conn_plce
;
361 u_int64_t ecn_conn_noplce
;
362 u_int64_t ecn_fallback_synloss
;
363 u_int64_t ecn_fallback_reorder
;
364 u_int64_t ecn_fallback_ce
;
365 u_int64_t ecn_off_conn
;
366 u_int64_t ecn_total_conn
;
367 struct if_tcp_ecn_perf_stat ecn_on
;
368 struct if_tcp_ecn_perf_stat ecn_off
;
372 * Interface link status report -- includes statistics related to
373 * the link layer technology sent by the driver. The driver will monitor
374 * these statistics over an interval (3-4 secs) and will generate a report
375 * to the network stack. This will give first-hand information about the
376 * status of the first hop of the network path. The version and
377 * length values should be correct for the data to be processed correctly.
378 * The definitions are different for different kind of interfaces like
379 * Wifi, Cellular etc,.
381 #define IF_CELLULAR_STATUS_REPORT_VERSION_1 1
382 #define IF_WIFI_STATUS_REPORT_VERSION_1 1
383 #define IF_CELLULAR_STATUS_REPORT_CURRENT_VERSION \
384 IF_CELLULAR_STATUS_REPORT_VERSION_1
385 #define IF_WIFI_STATUS_REPORT_CURRENT_VERSION IF_WIFI_STATUS_REPORT_VERSION_1
387 * For cellular interface --
388 * There is no way to share common headers between the Baseband and
389 * the kernel. Any changes to this structure will need to be communicated
390 * to the Baseband team. It is better to use reserved space instead of
391 * changing the size or existing fields in the structure.
393 struct if_cellular_status_v1
{
394 u_int32_t valid_bitmask
; /* indicates which fields are valid */
395 #define IF_CELL_LINK_QUALITY_METRIC_VALID 0x1
396 #define IF_CELL_UL_EFFECTIVE_BANDWIDTH_VALID 0x2
397 #define IF_CELL_UL_MAX_BANDWIDTH_VALID 0x4
398 #define IF_CELL_UL_MIN_LATENCY_VALID 0x8
399 #define IF_CELL_UL_EFFECTIVE_LATENCY_VALID 0x10
400 #define IF_CELL_UL_MAX_LATENCY_VALID 0x20
401 #define IF_CELL_UL_RETXT_LEVEL_VALID 0x40
402 #define IF_CELL_UL_BYTES_LOST_VALID 0x80
403 #define IF_CELL_UL_MIN_QUEUE_SIZE_VALID 0x100
404 #define IF_CELL_UL_AVG_QUEUE_SIZE_VALID 0x200
405 #define IF_CELL_UL_MAX_QUEUE_SIZE_VALID 0x400
406 #define IF_CELL_DL_EFFECTIVE_BANDWIDTH_VALID 0x800
407 #define IF_CELL_DL_MAX_BANDWIDTH_VALID 0x1000
408 #define IF_CELL_CONFIG_INACTIVITY_TIME_VALID 0x2000
409 #define IF_CELL_CONFIG_BACKOFF_TIME_VALID 0x4000
410 u_int32_t link_quality_metric
;
411 u_int32_t ul_effective_bandwidth
; /* Measured uplink bandwidth based on current activity (bps) */
412 u_int32_t ul_max_bandwidth
; /* Maximum supported uplink bandwidth (bps) */
413 u_int32_t ul_min_latency
; /* min expected uplink latency for first hop (ms) */
414 u_int32_t ul_effective_latency
; /* current expected uplink latency for first hop (ms) */
415 u_int32_t ul_max_latency
; /* max expected uplink latency first hop (ms) */
416 u_int32_t ul_retxt_level
; /* Retransmission metric */
417 #define IF_CELL_UL_RETXT_LEVEL_NONE 1
418 #define IF_CELL_UL_RETXT_LEVEL_LOW 2
419 #define IF_CELL_UL_RETXT_LEVEL_MEDIUM 3
420 #define IF_CELL_UL_RETXT_LEVEL_HIGH 4
421 u_int32_t ul_bytes_lost
; /* % of total bytes lost on uplink in Q10 format */
422 u_int32_t ul_min_queue_size
; /* minimum bytes in queue */
423 u_int32_t ul_avg_queue_size
; /* average bytes in queue */
424 u_int32_t ul_max_queue_size
; /* maximum bytes in queue */
425 u_int32_t dl_effective_bandwidth
; /* Measured downlink bandwidth based on current activity (bps) */
426 u_int32_t dl_max_bandwidth
; /* Maximum supported downlink bandwidth (bps) */
427 u_int32_t config_inactivity_time
; /* ms */
428 u_int32_t config_backoff_time
; /* new connections backoff time in ms */
429 u_int64_t reserved_1
;
430 u_int64_t reserved_2
;
431 u_int64_t reserved_3
;
432 u_int64_t reserved_4
;
433 u_int64_t reserved_5
;
434 } __attribute__((packed
));
436 struct if_cellular_status
{
438 struct if_cellular_status_v1 if_status_v1
;
443 * These statistics will be provided by the Wifi driver periodically.
444 * After sending each report, the driver should start computing again
445 * for the next report duration so that the values represent the link
446 * status for one report duration.
449 struct if_wifi_status_v1
{
450 u_int32_t valid_bitmask
;
451 #define IF_WIFI_LINK_QUALITY_METRIC_VALID 0x1
452 #define IF_WIFI_UL_EFFECTIVE_BANDWIDTH_VALID 0x2
453 #define IF_WIFI_UL_MAX_BANDWIDTH_VALID 0x4
454 #define IF_WIFI_UL_MIN_LATENCY_VALID 0x8
455 #define IF_WIFI_UL_EFFECTIVE_LATENCY_VALID 0x10
456 #define IF_WIFI_UL_MAX_LATENCY_VALID 0x20
457 #define IF_WIFI_UL_RETXT_LEVEL_VALID 0x40
458 #define IF_WIFI_UL_ERROR_RATE_VALID 0x80
459 #define IF_WIFI_UL_BYTES_LOST_VALID 0x100
460 #define IF_WIFI_DL_EFFECTIVE_BANDWIDTH_VALID 0x200
461 #define IF_WIFI_DL_MAX_BANDWIDTH_VALID 0x400
462 #define IF_WIFI_DL_MIN_LATENCY_VALID 0x800
463 #define IF_WIFI_DL_EFFECTIVE_LATENCY_VALID 0x1000
464 #define IF_WIFI_DL_MAX_LATENCY_VALID 0x2000
465 #define IF_WIFI_DL_ERROR_RATE_VALID 0x4000
466 #define IF_WIFI_CONFIG_FREQUENCY_VALID 0x8000
467 #define IF_WIFI_CONFIG_MULTICAST_RATE_VALID 0x10000
468 #define IF_WIFI_CONFIG_SCAN_COUNT_VALID 0x20000
469 #define IF_WIFI_CONFIG_SCAN_DURATION_VALID 0x40000
470 u_int32_t link_quality_metric
; /* link quality metric */
471 u_int32_t ul_effective_bandwidth
; /* Measured uplink bandwidth based on current activity (bps) */
472 u_int32_t ul_max_bandwidth
; /* Maximum supported uplink bandwidth (bps) */
473 u_int32_t ul_min_latency
; /* min expected uplink latency for first hop (ms) */
474 u_int32_t ul_effective_latency
; /* current expected uplink latency for first hop (ms) */
475 u_int32_t ul_max_latency
; /* max expected uplink latency for first hop (ms) */
476 u_int32_t ul_retxt_level
; /* Retransmission metric */
477 #define IF_WIFI_UL_RETXT_LEVEL_NONE 1
478 #define IF_WIFI_UL_RETXT_LEVEL_LOW 2
479 #define IF_WIFI_UL_RETXT_LEVEL_MEDIUM 3
480 #define IF_WIFI_UL_RETXT_LEVEL_HIGH 4
481 u_int32_t ul_bytes_lost
; /* % of total bytes lost on uplink in Q10 format */
482 u_int32_t ul_error_rate
; /* % of bytes dropped on uplink after many retransmissions in Q10 format */
483 u_int32_t dl_effective_bandwidth
; /* Measured downlink bandwidth based on current activity (bps) */
484 u_int32_t dl_max_bandwidth
; /* Maximum supported downlink bandwidth (bps) */
486 * The download latency values indicate the time AP may have to wait for the
487 * driver to receive the packet. These values give the range of expected latency
488 * mainly due to co-existence events and channel hopping where the interface
489 * becomes unavailable.
491 u_int32_t dl_min_latency
; /* min expected latency for first hop in ms */
492 u_int32_t dl_effective_latency
; /* current expected latency for first hop in ms */
493 u_int32_t dl_max_latency
; /* max expected latency for first hop in ms */
494 u_int32_t dl_error_rate
; /* % of CRC or other errors in Q10 format */
495 u_int32_t config_frequency
; /* 2.4 or 5 GHz */
496 #define IF_WIFI_CONFIG_FREQUENCY_2_4_GHZ 1
497 #define IF_WIFI_CONFIG_FREQUENCY_5_0_GHZ 2
498 u_int32_t config_multicast_rate
; /* bps */
499 u_int32_t scan_count
; /* scan count during the previous period */
500 u_int32_t scan_duration
; /* scan duration in ms */
501 u_int64_t reserved_1
;
502 u_int64_t reserved_2
;
503 u_int64_t reserved_3
;
504 u_int64_t reserved_4
;
505 } __attribute__((packed
));
507 struct if_wifi_status
{
509 struct if_wifi_status_v1 if_status_v1
;
513 struct if_link_status
{
514 u_int32_t ifsr_version
; /* version of this report */
515 u_int32_t ifsr_len
; /* length of the following struct */
517 struct if_cellular_status ifsr_cell
;
518 struct if_wifi_status ifsr_wifi
;
522 struct if_interface_state
{
524 * The bitmask tells which of the fields
526 * - When setting, to control which fields
527 * are being modified;
528 * - When getting, it tells which fields are set.
530 u_int8_t valid_bitmask
;
531 #define IF_INTERFACE_STATE_RRC_STATE_VALID 0x1
532 #define IF_INTERFACE_STATE_LQM_STATE_VALID 0x2
533 #define IF_INTERFACE_STATE_INTERFACE_AVAILABILITY_VALID 0x4
536 * Valid only for cellular interface
539 #define IF_INTERFACE_STATE_RRC_STATE_IDLE 0x0
540 #define IF_INTERFACE_STATE_RRC_STATE_CONNECTED 0x1
543 * Values normalized to the edge of the following values
544 * that are defined on <net/if.h>:
545 * IFNET_LQM_THRESH_BAD
546 * IFNET_LQM_THRESH_POOR
547 * IFNET_LQM_THRESH_GOOD
552 * Indicate if the underlying link is currently
555 u_int8_t interface_availability
;
556 #define IF_INTERFACE_STATE_INTERFACE_AVAILABLE 0x0
557 #define IF_INTERFACE_STATE_INTERFACE_UNAVAILABLE 0x1
560 struct chain_len_stats
{
565 uint64_t cls_five_or_more
;
573 * Structure defining a queue for a network interface.
583 #ifdef BSD_KERNEL_PRIVATE
585 * Internal storage of if_data. This is bound to change. Various places in the
586 * stack will translate this data structure in to the externally visible
587 * if_data structure above. Note that during interface attach time, the
588 * embedded if_data structure in ifnet is cleared, with the exception of
589 * some non-statistics related fields.
591 struct if_data_internal
{
592 /* generic interface information */
593 u_char ifi_type
; /* ethernet, tokenring, etc */
594 u_char ifi_typelen
; /* Length of frame type id */
595 u_char ifi_physical
; /* e.g., AUI, Thinnet, 10base-T, etc */
596 u_char ifi_addrlen
; /* media address length */
597 u_char ifi_hdrlen
; /* media header length */
598 u_char ifi_recvquota
; /* polling quota for receive intrs */
599 u_char ifi_xmitquota
; /* polling quota for xmit intrs */
600 u_char ifi_unused1
; /* for future use */
601 u_int32_t ifi_mtu
; /* maximum transmission unit */
602 u_int32_t ifi_metric
; /* routing metric (external only) */
603 u_int32_t ifi_baudrate
; /* linespeed */
604 u_int32_t ifi_preamblelen
;/* length of the packet preamble */
605 /* volatile statistics */
606 u_int64_t ifi_ipackets
; /* packets received on interface */
607 u_int64_t ifi_ierrors
; /* input errors on interface */
608 u_int64_t ifi_opackets
; /* packets sent on interface */
609 u_int64_t ifi_oerrors
; /* output errors on interface */
610 u_int64_t ifi_collisions
; /* collisions on csma interfaces */
611 u_int64_t ifi_ibytes
; /* total number of octets received */
612 u_int64_t ifi_obytes
; /* total number of octets sent */
613 u_int64_t ifi_imcasts
; /* packets received via multicast */
614 u_int64_t ifi_omcasts
; /* packets sent via multicast */
615 u_int64_t ifi_iqdrops
; /* dropped on input, this interface */
616 u_int64_t ifi_noproto
; /* destined for unsupported protocol */
617 u_int32_t ifi_recvtiming
; /* usec spent receiving when timing */
618 u_int32_t ifi_xmittiming
; /* usec spent xmitting when timing */
619 u_int64_t ifi_alignerrs
; /* unaligned (32-bit) input pkts */
620 u_int64_t ifi_dt_bytes
; /* Data threshold counter */
621 u_int64_t ifi_fpackets
; /* forwarded packets on interface */
622 u_int64_t ifi_fbytes
; /* forwarded bytes on interface */
623 struct timeval ifi_lastchange
; /* time of last administrative change */
624 u_int32_t ifi_hwassist
; /* HW offload capabilities */
625 u_int32_t ifi_tso_v4_mtu
; /* TCP Segment Offload IPv4 maximum segment size */
626 u_int32_t ifi_tso_v6_mtu
; /* TCP Segment Offload IPv6 maximum segment size */
631 * Fields per interface to measure perceived bandwidth.
633 struct if_measured_bw
{
634 u_int64_t bw
; /* measured bandwidth in bytes per ms */
635 u_int64_t bytes
; /* XXX not needed */
636 u_int64_t ts
; /* XXX not needed */
637 u_int64_t cur_seq
__attribute((aligned(8))); /* current sequence for marking a packet */
638 u_int64_t start_ts
; /* time at which a measurement started */
639 u_int64_t start_seq
; /* sequence at which a measurement should start */
640 u_int64_t last_seq
; /* last recorded seq */
641 u_int64_t last_ts
; /* last recorded ts */
642 u_int32_t flags
__attribute__((aligned(4))); /* flags */
643 #define IF_MEASURED_BW_INPROGRESS 0x1
644 #define IF_MEASURED_BW_CALCULATION 0x2
646 #endif /* MEASURE_BW */
647 #endif /* BSD_KERNEL_PRIVATE */
650 #define if_mtu if_data.ifi_mtu
651 #define if_type if_data.ifi_type
652 #define if_typelen if_data.ifi_typelen
653 #define if_physical if_data.ifi_physical
654 #define if_addrlen if_data.ifi_addrlen
655 #define if_hdrlen if_data.ifi_hdrlen
656 #define if_preamblelen if_data.ifi_preamblelen
657 #define if_metric if_data.ifi_metric
658 #define if_baudrate if_data.ifi_baudrate
659 #define if_hwassist if_data.ifi_hwassist
660 #define if_ipackets if_data.ifi_ipackets
661 #define if_ierrors if_data.ifi_ierrors
662 #define if_opackets if_data.ifi_opackets
663 #define if_oerrors if_data.ifi_oerrors
664 #define if_collisions if_data.ifi_collisions
665 #define if_ibytes if_data.ifi_ibytes
666 #define if_obytes if_data.ifi_obytes
667 #define if_imcasts if_data.ifi_imcasts
668 #define if_omcasts if_data.ifi_omcasts
669 #define if_iqdrops if_data.ifi_iqdrops
670 #define if_noproto if_data.ifi_noproto
671 #define if_lastchange if_data.ifi_lastchange
672 #define if_recvquota if_data.ifi_recvquota
673 #define if_xmitquota if_data.ifi_xmitquota
675 #ifdef BSD_KERNEL_PRIVATE
676 #define if_tso_v4_mtu if_data.ifi_tso_v4_mtu
677 #define if_tso_v6_mtu if_data.ifi_tso_v6_mtu
678 #define if_alignerrs if_data.ifi_alignerrs
679 #define if_dt_bytes if_data.ifi_dt_bytes
680 #define if_fpackets if_data.ifi_fpackets
681 #define if_fbytes if_data.ifi_fbytes
682 #endif /* BSD_KERNEL_PRIVATE */
684 #ifdef BSD_KERNEL_PRIVATE
686 * Forward structure declarations for function prototypes [sic].
695 struct proto_hash_entry
;
696 struct dlil_threading_info
;
697 struct tcpstat_local
;
698 struct udpstat_local
;
703 /* we use TAILQs so that the order of instantiation is preserved in the list */
704 TAILQ_HEAD(ifnethead
, ifnet
);
705 TAILQ_HEAD(ifaddrhead
, ifaddr
);
706 TAILQ_HEAD(ifprefixhead
, ifprefix
);
707 LIST_HEAD(ifmultihead
, ifmultiaddr
);
708 TAILQ_HEAD(tailq_head
, tqdummy
);
709 TAILQ_HEAD(ifnet_filter_head
, ifnet_filter
);
710 TAILQ_HEAD(ddesc_head_name
, dlil_demux_desc
);
711 #endif /* BSD_KERNEL_PRIVATE */
715 * All of the following IF_HWASSIST_* flags are defined in kpi_inteface.h as
716 * IFNET_* flags. These are redefined here as constants to avoid failures to
717 * build user level programs that can not include kpi_interface.h. It is
718 * important to keep this in sync with the definitions in kpi_interface.h.
719 * The corresponding constant for each definition is mentioned in the comment.
721 * Bottom 16 bits reserved for hardware checksum
723 #define IF_HWASSIST_CSUM_IP 0x0001 /* will csum IP, IFNET_CSUM_IP */
724 #define IF_HWASSIST_CSUM_TCP 0x0002 /* will csum TCP, IFNET_CSUM_TCP */
725 #define IF_HWASSIST_CSUM_UDP 0x0004 /* will csum UDP, IFNET_CSUM_UDP */
726 #define IF_HWASSIST_CSUM_IP_FRAGS 0x0008 /* will csum IP fragments, IFNET_CSUM_FRAGMENT */
727 #define IF_HWASSIST_CSUM_FRAGMENT 0x0010 /* will do IP fragmentation, IFNET_IP_FRAGMENT */
728 #define IF_HWASSIST_CSUM_TCPIPV6 0x0020 /* will csum TCPv6, IFNET_CSUM_TCPIPV6 */
729 #define IF_HWASSIST_CSUM_UDPIPV6 0x0040 /* will csum UDPv6, IFNET_CSUM_UDP */
730 #define IF_HWASSIST_CSUM_FRAGMENT_IPV6 0x0080 /* will do IPv6 fragmentation, IFNET_IPV6_FRAGMENT */
731 #define IF_HWASSIST_CSUM_PARTIAL 0x1000 /* simple Sum16 computation, IFNET_CSUM_PARTIAL */
732 #define IF_HWASSIST_CSUM_MASK 0xffff
733 #define IF_HWASSIST_CSUM_FLAGS(hwassist) ((hwassist) & IF_HWASSIST_CSUM_MASK)
736 #define IF_HWASSIST_VLAN_TAGGING 0x00010000 /* supports VLAN tagging, IFNET_VLAN_TAGGING */
737 #define IF_HWASSIST_VLAN_MTU 0x00020000 /* supports VLAN MTU-sized packet (for software VLAN), IFNET_VLAN_MTU */
739 /* TCP Segment Offloading support */
741 #define IF_HWASSIST_TSO_V4 0x00200000 /* will do TCP Segment offload for IPv4, IFNET_TSO_IPV4 */
742 #define IF_HWASSIST_TSO_V6 0x00400000 /* will do TCP Segment offload for IPv6, IFNET_TSO_IPV6 */
746 #define IFXNAMSIZ (IFNAMSIZ + 8) /* external name (name + unit) */
749 #ifdef BSD_KERNEL_PRIVATE
751 * ifnet is private to BSD portion of kernel
753 #include <sys/mcache.h>
754 #include <sys/tree.h>
755 #include <netinet/in.h>
756 #include <net/if_dl.h>
757 #include <net/classq/if_classq.h>
758 #include <net/if_types.h>
760 RB_HEAD(ll_reach_tree
, if_llreach
); /* define struct ll_reach_tree */
762 #define if_name(ifp) ifp->if_xname
764 * Structure defining a network interface.
766 * (Would like to call this struct ``if'', but C isn't PL/1.)
770 * Lock (RW or mutex) to protect this data structure (static storage.)
772 decl_lck_rw_data(, if_lock
);
773 void *if_softc
; /* pointer to driver state */
774 const char *if_name
; /* name, e.g. ``en'' or ``lo'' */
775 const char *if_xname
; /* external name (name + unit) */
776 struct if_description if_desc
; /* extended description */
777 TAILQ_ENTRY(ifnet
) if_link
; /* all struct ifnets are chained */
778 TAILQ_ENTRY(ifnet
) if_detaching_link
; /* list of detaching ifnets */
780 decl_lck_mtx_data(, if_ref_lock
)
781 u_int32_t if_refflags
; /* see IFRF flags below */
782 u_int32_t if_refio
; /* number of io ops to the underlying driver */
784 #define if_list if_link
785 struct ifaddrhead if_addrhead
; /* linked list of addresses per if */
786 #define if_addrlist if_addrhead
787 struct ifaddr
*if_lladdr
; /* link address (first/permanent) */
789 int if_pcount
; /* number of promiscuous listeners */
790 struct bpf_if
*if_bpf
; /* packet filter structure */
791 u_short if_index
; /* numeric abbreviation for this if */
792 short if_unit
; /* sub-unit for lower level driver */
793 short if_timer
; /* time 'til if_watchdog called */
794 short if_flags
; /* up/down, broadcast, etc. */
795 u_int32_t if_eflags
; /* see <net/if.h> */
797 int if_capabilities
; /* interface features & capabilities */
798 int if_capenable
; /* enabled features & capabilities */
800 void *if_linkmib
; /* link-type-specific MIB data */
801 size_t if_linkmiblen
; /* length of above data */
803 struct if_data_internal if_data
__attribute__((aligned(8)));
805 ifnet_family_t if_family
; /* value assigned by Apple */
806 ifnet_subfamily_t if_subfamily
; /* value assigned by Apple */
807 uintptr_t if_family_cookie
;
808 ifnet_output_func if_output
;
809 ifnet_pre_enqueue_func if_pre_enqueue
;
810 ifnet_start_func if_start
;
811 ifnet_ctl_func if_output_ctl
;
812 ifnet_input_poll_func if_input_poll
;
813 ifnet_ctl_func if_input_ctl
;
814 ifnet_ioctl_func if_ioctl
;
815 ifnet_set_bpf_tap if_set_bpf_tap
;
816 ifnet_detached_func if_free
;
817 ifnet_demux_func if_demux
;
818 ifnet_event_func if_event
;
819 ifnet_framer_func if_framer_legacy
;
820 ifnet_framer_extended_func if_framer
;
821 ifnet_add_proto_func if_add_proto
;
822 ifnet_del_proto_func if_del_proto
;
823 ifnet_check_multi if_check_multi
;
824 struct proto_hash_entry
*if_proto_hash
;
825 void *if_kpi_storage
;
827 u_int32_t if_flowhash
; /* interface flow control ID */
829 decl_lck_mtx_data(, if_start_lock
);
830 u_int32_t if_start_flags
; /* see IFSF flags below */
831 u_int32_t if_start_req
;
832 u_int16_t if_start_active
; /* output is active */
833 u_int16_t if_start_delayed
;
834 u_int16_t if_start_delay_qlen
;
835 u_int16_t if_start_delay_idle
;
836 u_int64_t if_start_delay_swin
;
837 u_int32_t if_start_delay_cnt
;
838 u_int32_t if_start_delay_timeout
; /* nanoseconds */
839 struct timespec if_start_cycle
; /* restart interval */
840 struct thread
*if_start_thread
;
842 struct ifclassq if_snd
; /* transmit queue */
843 u_int32_t if_output_sched_model
; /* tx sched model */
845 struct if_bandwidths if_output_bw
;
846 struct if_bandwidths if_input_bw
;
848 struct if_latencies if_output_lt
;
849 struct if_latencies if_input_lt
;
851 decl_lck_mtx_data(, if_flt_lock
)
852 u_int32_t if_flt_busy
;
853 u_int32_t if_flt_waiters
;
854 struct ifnet_filter_head if_flt_head
;
856 struct ifmultihead if_multiaddrs
; /* multicast addresses */
857 u_int32_t if_updatemcasts
; /* mcast addrs need updating */
858 int if_amcount
; /* # of all-multicast reqs */
859 decl_lck_mtx_data(, if_addrconfig_lock
); /* for serializing addr config */
860 struct in_multi
*if_allhostsinm
; /* store all-hosts inm for this ifp */
862 decl_lck_mtx_data(, if_poll_lock
);
863 u_int16_t if_poll_req
;
864 u_int16_t if_poll_update
; /* link update */
865 u_int32_t if_poll_active
; /* polling is active */
866 struct timespec if_poll_cycle
; /* poll interval */
867 struct thread
*if_poll_thread
;
869 struct dlil_threading_info
*if_inp
;
871 struct ifprefixhead if_prefixhead
; /* list of prefixes per if */
880 struct label
*if_label
; /* interface MAC label */
883 u_int32_t if_wake_properties
;
885 struct pfi_kif
*if_pf_kif
;
888 decl_lck_mtx_data(, if_cached_route_lock
);
889 u_int32_t if_fwd_cacheok
;
890 struct route if_fwd_route
; /* cached forwarding route */
891 struct route if_src_route
; /* cached ipv4 source route */
892 struct route_in6 if_src_route6
; /* cached ipv6 source route */
894 decl_lck_rw_data(, if_llreach_lock
);
895 struct ll_reach_tree if_ll_srcs
; /* source link-layer tree */
897 void *if_bridge
; /* bridge glue */
899 u_int32_t if_want_aggressive_drain
;
900 u_int32_t if_idle_flags
; /* idle flags */
901 u_int32_t if_idle_new_flags
; /* temporary idle flags */
902 u_int32_t if_idle_new_flags_mask
; /* temporary mask */
903 u_int32_t if_route_refcnt
; /* idle: route ref count */
905 struct if_traffic_class if_tc
__attribute__((aligned(8)));
907 struct igmp_ifinfo
*if_igi
; /* for IGMPv3 */
910 struct mld_ifinfo
*if_mli
; /* for MLDv2 */
914 struct if_measured_bw if_bw
;
915 #endif /* MEASURE_BW */
916 struct tcpstat_local
*if_tcp_stat
; /* TCP specific stats */
917 struct udpstat_local
*if_udp_stat
; /* UDP specific stats */
920 int32_t level
; /* cached logging level */
921 u_int32_t flags
; /* cached logging flags */
922 int32_t category
; /* cached category */
923 int32_t subcategory
; /* cached subcategory */
927 struct ifnet
*ifp
; /* delegated ifp */
928 u_int32_t type
; /* delegated i/f type */
929 u_int32_t family
; /* delegated i/f family */
930 u_int32_t subfamily
; /* delegated i/f sub-family */
931 uint32_t expensive
:1; /* delegated i/f expensive? */
934 #define IF_MAXAGENTS 8
935 uuid_t if_agentids
[IF_MAXAGENTS
];
937 u_int64_t if_data_threshold
;
938 u_int32_t if_fg_sendts
; /* last send on a fg socket in seconds */
939 u_int32_t if_rt_sendts
; /* last of a real time packet */
942 decl_lck_rw_data(, if_inetdata_lock
);
946 decl_lck_rw_data(, if_inet6data_lock
);
949 decl_lck_rw_data(, if_link_status_lock
);
950 struct if_link_status
*if_link_status
;
951 struct if_interface_state if_interface_state
;
952 struct if_tcp_ecn_stat
*if_ipv4_stat
;
953 struct if_tcp_ecn_stat
*if_ipv6_stat
;
956 #define IF_TCP_STATINC(_ifp, _s) do { \
957 if ((_ifp)->if_tcp_stat != NULL) \
958 atomic_add_64(&(_ifp)->if_tcp_stat->_s, 1); \
961 #define IF_UDP_STATINC(_ifp, _s) do { \
962 if ((_ifp)->if_udp_stat != NULL) \
963 atomic_add_64(&(_ifp)->if_udp_stat->_s, 1); \
967 * Valid values for if_refflags
969 #define IFRF_ATTACHED 0x1 /* ifnet attach is completely done */
970 #define IFRF_DETACHING 0x2 /* detach has been requested */
973 * Valid values for if_start_flags
975 #define IFSF_FLOW_CONTROLLED 0x1 /* flow controlled */
978 * Structure describing a `cloning' interface.
981 LIST_ENTRY(if_clone
) ifc_list
; /* on list of cloners */
982 const char *ifc_name
; /* name of device, e.g. `vlan' */
983 size_t ifc_namelen
; /* length of name */
984 u_int32_t ifc_minifs
; /* minimum number of interfaces */
985 u_int32_t ifc_maxunit
; /* maximum unit number */
986 unsigned char *ifc_units
; /* bitmap to handle units */
987 u_int32_t ifc_bmlen
; /* bitmap length */
989 int (*ifc_create
)(struct if_clone
*, u_int32_t
, void *);
990 int (*ifc_destroy
)(struct ifnet
*);
993 #define IF_CLONE_INITIALIZER(name, create, destroy, minifs, maxunit) { \
994 { NULL, NULL }, name, (sizeof (name) - 1), minifs, maxunit, NULL, 0, \
998 #define M_CLONE M_IFADDR
1001 * Macros to manipulate ifqueue. Users of these macros are responsible
1002 * for serialization, by holding whatever lock is appropriate for the
1003 * corresponding structure that is referring the ifqueue.
1005 #define IF_QFULL(ifq) ((ifq)->ifq_len >= (ifq)->ifq_maxlen)
1006 #define IF_DROP(ifq) ((ifq)->ifq_drops++)
1008 #define IF_ENQUEUE(ifq, m) do { \
1009 (m)->m_nextpkt = NULL; \
1010 if ((ifq)->ifq_tail == NULL) \
1011 (ifq)->ifq_head = m; \
1013 ((struct mbuf*)(ifq)->ifq_tail)->m_nextpkt = m; \
1014 (ifq)->ifq_tail = m; \
1018 #define IF_PREPEND(ifq, m) do { \
1019 (m)->m_nextpkt = (ifq)->ifq_head; \
1020 if ((ifq)->ifq_tail == NULL) \
1021 (ifq)->ifq_tail = (m); \
1022 (ifq)->ifq_head = (m); \
1026 #define IF_DEQUEUE(ifq, m) do { \
1027 (m) = (ifq)->ifq_head; \
1029 if (((ifq)->ifq_head = (m)->m_nextpkt) == NULL) \
1030 (ifq)->ifq_tail = NULL; \
1031 (m)->m_nextpkt = NULL; \
1036 #define IF_REMQUEUE(ifq, m) do { \
1037 struct mbuf *_p = (ifq)->ifq_head; \
1038 struct mbuf *_n = (m)->m_nextpkt; \
1041 while (_p != NULL) { \
1042 if (_p->m_nextpkt == (m)) \
1044 _p = _p->m_nextpkt; \
1046 VERIFY(_p != NULL || ((m) == (ifq)->ifq_head)); \
1047 if ((m) == (ifq)->ifq_head) \
1048 (ifq)->ifq_head = _n; \
1049 if ((m) == (ifq)->ifq_tail) \
1050 (ifq)->ifq_tail = _p; \
1051 VERIFY((ifq)->ifq_tail != NULL || (ifq)->ifq_head == NULL); \
1052 VERIFY((ifq)->ifq_len != 0); \
1055 _p->m_nextpkt = _n; \
1056 (m)->m_nextpkt = NULL; \
1059 #define IF_DRAIN(ifq) do { \
1062 IF_DEQUEUE(ifq, _m); \
1070 * The ifaddr structure contains information about one address
1071 * of an interface. They are maintained by the different address families,
1072 * are allocated and attached when an address is set, and are linked
1073 * together so all addresses for an interface can be located.
1076 decl_lck_mtx_data(, ifa_lock
); /* lock for ifaddr */
1077 uint32_t ifa_refcnt
; /* ref count, use IFA_{ADD,REM}REF */
1078 uint32_t ifa_debug
; /* debug flags */
1079 struct sockaddr
*ifa_addr
; /* address of interface */
1080 struct sockaddr
*ifa_dstaddr
; /* other end of p-to-p link */
1081 #define ifa_broadaddr ifa_dstaddr /* broadcast address interface */
1082 struct sockaddr
*ifa_netmask
; /* used to determine subnet */
1083 struct ifnet
*ifa_ifp
; /* back-pointer to interface */
1084 TAILQ_ENTRY(ifaddr
) ifa_link
; /* queue macro glue */
1085 void (*ifa_rtrequest
) /* check or clean routes (+ or -)'d */
1086 (int, struct rtentry
*, struct sockaddr
*);
1087 uint32_t ifa_flags
; /* mostly rt_flags for cloning */
1088 int32_t ifa_metric
; /* cost of going out this interface */
1089 void (*ifa_free
)(struct ifaddr
*); /* callback fn for freeing */
1090 void (*ifa_trace
) /* callback fn for tracing refs */
1091 (struct ifaddr
*, int);
1092 void (*ifa_attached
)(struct ifaddr
*); /* callback fn for attaching */
1093 void (*ifa_detached
)(struct ifaddr
*); /* callback fn for detaching */
1098 * Valid values for ifa_flags
1100 #define IFA_ROUTE RTF_UP /* route installed (0x1) */
1101 #define IFA_CLONING RTF_CLONING /* (0x100) */
1104 * Valid values for ifa_debug
1106 #define IFD_ATTACHED 0x1 /* attached to list */
1107 #define IFD_ALLOC 0x2 /* dynamically allocated */
1108 #define IFD_DEBUG 0x4 /* has debugging info */
1109 #define IFD_LINK 0x8 /* link address */
1110 #define IFD_TRASHED 0x10 /* in trash list */
1111 #define IFD_SKIP 0x20 /* skip this entry */
1112 #define IFD_NOTREADY 0x40 /* embryonic; not yet ready */
1114 #define IFA_LOCK_ASSERT_HELD(_ifa) \
1115 lck_mtx_assert(&(_ifa)->ifa_lock, LCK_MTX_ASSERT_OWNED)
1117 #define IFA_LOCK_ASSERT_NOTHELD(_ifa) \
1118 lck_mtx_assert(&(_ifa)->ifa_lock, LCK_MTX_ASSERT_NOTOWNED)
1120 #define IFA_LOCK(_ifa) \
1121 lck_mtx_lock(&(_ifa)->ifa_lock)
1123 #define IFA_LOCK_SPIN(_ifa) \
1124 lck_mtx_lock_spin(&(_ifa)->ifa_lock)
1126 #define IFA_CONVERT_LOCK(_ifa) do { \
1127 IFA_LOCK_ASSERT_HELD(_ifa); \
1128 lck_mtx_convert_spin(&(_ifa)->ifa_lock); \
1131 #define IFA_UNLOCK(_ifa) \
1132 lck_mtx_unlock(&(_ifa)->ifa_lock)
1134 #define IFA_ADDREF(_ifa) \
1137 #define IFA_ADDREF_LOCKED(_ifa) \
1140 #define IFA_REMREF(_ifa) do { \
1141 (void) ifa_remref(_ifa, 0); \
1144 #define IFA_REMREF_LOCKED(_ifa) \
1148 * The prefix structure contains information about one prefix
1149 * of an interface. They are maintained by the different address families,
1150 * are allocated and attached when an prefix or an address is set,
1151 * and are linked together so all prefixes for an interface can be located.
1154 struct sockaddr
*ifpr_prefix
; /* prefix of interface */
1155 struct ifnet
*ifpr_ifp
; /* back-pointer to interface */
1156 TAILQ_ENTRY(ifprefix
) ifpr_list
; /* queue macro glue */
1157 u_char ifpr_plen
; /* prefix length in bits */
1158 u_char ifpr_type
; /* protocol dependent prefix type */
1162 * Multicast address structure. This is analogous to the ifaddr
1163 * structure except that it keeps track of multicast addresses.
1164 * Also, the request count here is a count of requests for this
1165 * address, not a count of pointers to this structure; anonymous
1166 * membership(s) holds one outstanding request count.
1168 struct ifmultiaddr
{
1169 decl_lck_mtx_data(, ifma_lock
);
1170 u_int32_t ifma_refcount
; /* reference count */
1171 u_int32_t ifma_anoncnt
; /* # of anonymous requests */
1172 u_int32_t ifma_reqcnt
; /* total requests for this address */
1173 u_int32_t ifma_debug
; /* see ifa_debug flags */
1174 u_int32_t ifma_flags
; /* see below */
1175 LIST_ENTRY(ifmultiaddr
) ifma_link
; /* queue macro glue */
1176 struct sockaddr
*ifma_addr
; /* address this membership is for */
1177 struct ifmultiaddr
*ifma_ll
; /* link-layer translation, if any */
1178 struct ifnet
*ifma_ifp
; /* back-pointer to interface */
1179 void *ifma_protospec
; /* protocol-specific state, if any */
1180 void (*ifma_trace
) /* callback fn for tracing refs */
1181 (struct ifmultiaddr
*, int);
1185 * Values for ifma_flags
1187 #define IFMAF_ANONYMOUS 0x1 /* has anonymous request ref(s) held */
1189 #define IFMA_LOCK_ASSERT_HELD(_ifma) \
1190 lck_mtx_assert(&(_ifma)->ifma_lock, LCK_MTX_ASSERT_OWNED)
1192 #define IFMA_LOCK_ASSERT_NOTHELD(_ifma) \
1193 lck_mtx_assert(&(_ifma)->ifma_lock, LCK_MTX_ASSERT_NOTOWNED)
1195 #define IFMA_LOCK(_ifma) \
1196 lck_mtx_lock(&(_ifma)->ifma_lock)
1198 #define IFMA_LOCK_SPIN(_ifma) \
1199 lck_mtx_lock_spin(&(_ifma)->ifma_lock)
1201 #define IFMA_CONVERT_LOCK(_ifma) do { \
1202 IFMA_LOCK_ASSERT_HELD(_ifma); \
1203 lck_mtx_convert_spin(&(_ifma)->ifma_lock); \
1206 #define IFMA_UNLOCK(_ifma) \
1207 lck_mtx_unlock(&(_ifma)->ifma_lock)
1209 #define IFMA_ADDREF(_ifma) \
1210 ifma_addref(_ifma, 0)
1212 #define IFMA_ADDREF_LOCKED(_ifma) \
1213 ifma_addref(_ifma, 1)
1215 #define IFMA_REMREF(_ifma) \
1219 * Indicate whether or not the immediate interface, or the interface delegated
1220 * by it, is a cellular interface (IFT_CELLULAR). Delegated interface type is
1221 * set/cleared along with the delegated ifp; we cache the type for performance
1222 * to avoid dereferencing delegated ifp each time.
1224 * Note that this is meant to be used only for accounting and policy purposes;
1225 * certain places need to explicitly know the immediate interface type, and
1226 * this macro should not be used there.
1228 * The test is done against IFT_CELLULAR instead of IFNET_FAMILY_CELLULAR to
1229 * handle certain cases where the family isn't set to the latter.
1231 #define IFNET_IS_CELLULAR(_ifp) \
1232 ((_ifp)->if_type == IFT_CELLULAR || \
1233 (_ifp)->if_delegated.type == IFT_CELLULAR)
1236 * Indicate whether or not the immediate interface, or the interface delegated
1237 * by it, is an ETHERNET interface.
1239 #define IFNET_IS_ETHERNET(_ifp) \
1240 ((_ifp)->if_family == IFNET_FAMILY_ETHERNET || \
1241 (_ifp)->if_delegated.family == IFNET_FAMILY_ETHERNET)
1243 * Indicate whether or not the immediate interface, or the interface delegated
1244 * by it, is a Wi-Fi interface (IFNET_SUBFAMILY_WIFI). Delegated interface
1245 * subfamily is set/cleared along with the delegated ifp; we cache the subfamily
1246 * for performance to avoid dereferencing delegated ifp each time.
1248 * Note that this is meant to be used only for accounting and policy purposes;
1249 * certain places need to explicitly know the immediate interface type, and
1250 * this macro should not be used there.
1252 * The test is done against IFNET_SUBFAMILY_WIFI as the family may be set to
1253 * IFNET_FAMILY_ETHERNET (as well as type to IFT_ETHER) which is too generic.
1255 #define IFNET_IS_WIFI(_ifp) \
1256 ((_ifp)->if_subfamily == IFNET_SUBFAMILY_WIFI || \
1257 (_ifp)->if_delegated.subfamily == IFNET_SUBFAMILY_WIFI)
1260 * Indicate whether or not the immediate interface, or the interface delegated
1261 * by it, is a Wired interface (several families). Delegated interface
1262 * family is set/cleared along with the delegated ifp; we cache the family
1263 * for performance to avoid dereferencing delegated ifp each time.
1265 * Note that this is meant to be used only for accounting and policy purposes;
1266 * certain places need to explicitly know the immediate interface type, and
1267 * this macro should not be used there.
1269 #define IFNET_IS_WIRED(_ifp) \
1270 ((_ifp)->if_family == IFNET_FAMILY_ETHERNET || \
1271 (_ifp)->if_delegated.family == IFNET_FAMILY_ETHERNET || \
1272 (_ifp)->if_family == IFNET_FAMILY_FIREWIRE || \
1273 (_ifp)->if_delegated.family == IFNET_FAMILY_FIREWIRE)
1276 * Indicate whether or not the immediate interface, or the interface delegated
1277 * by it, is marked as expensive. The delegated interface is set/cleared
1278 * along with the delegated ifp; we cache the flag for performance to avoid
1279 * dereferencing delegated ifp each time.
1281 * Note that this is meant to be used only for policy purposes.
1283 #define IFNET_IS_EXPENSIVE(_ifp) \
1284 ((_ifp)->if_eflags & IFEF_EXPENSIVE || \
1285 (_ifp)->if_delegated.expensive)
1288 * We don't support AWDL interface delegation.
1290 #define IFNET_IS_AWDL_RESTRICTED(_ifp) \
1291 (((_ifp)->if_eflags & (IFEF_AWDL|IFEF_AWDL_RESTRICTED)) == \
1292 (IFEF_AWDL|IFEF_AWDL_RESTRICTED))
1295 extern struct ifnethead ifnet_head
;
1296 extern struct ifnet
**ifindex2ifnet
;
1297 extern u_int32_t if_sndq_maxlen
;
1298 extern u_int32_t if_rcvq_maxlen
;
1299 extern int if_index
;
1300 extern struct ifaddr
**ifnet_addrs
;
1301 extern lck_attr_t
*ifa_mtx_attr
;
1302 extern lck_grp_t
*ifa_mtx_grp
;
1303 extern lck_grp_t
*ifnet_lock_group
;
1304 extern lck_attr_t
*ifnet_lock_attr
;
1305 extern ifnet_t lo_ifp
;
1306 extern uint32_t if_bw_measure_size
;
1307 extern u_int32_t if_bw_smoothing_val
;
1309 extern int if_addmulti(struct ifnet
*, const struct sockaddr
*,
1310 struct ifmultiaddr
**);
1311 extern int if_addmulti_anon(struct ifnet
*, const struct sockaddr
*,
1312 struct ifmultiaddr
**);
1313 extern int if_allmulti(struct ifnet
*, int);
1314 extern int if_delmulti(struct ifnet
*, const struct sockaddr
*);
1315 extern int if_delmulti_ifma(struct ifmultiaddr
*);
1316 extern int if_delmulti_anon(struct ifnet
*, const struct sockaddr
*);
1317 extern void if_down(struct ifnet
*);
1318 extern int if_down_all(void);
1319 extern void if_up(struct ifnet
*);
1320 __private_extern__
void if_updown(struct ifnet
*ifp
, int up
);
1321 extern int ifioctl(struct socket
*, u_long
, caddr_t
, struct proc
*);
1322 extern int ifioctllocked(struct socket
*, u_long
, caddr_t
, struct proc
*);
1323 extern struct ifnet
*ifunit(const char *);
1324 extern struct ifnet
*if_withname(struct sockaddr
*);
1325 extern void if_qflush(struct ifnet
*, int);
1326 extern void if_qflush_sc(struct ifnet
*, mbuf_svc_class_t
, u_int32_t
,
1327 u_int32_t
*, u_int32_t
*, int);
1329 extern struct if_clone
*if_clone_lookup(const char *, u_int32_t
*);
1330 extern int if_clone_attach(struct if_clone
*);
1331 extern void if_clone_detach(struct if_clone
*);
1333 extern u_int32_t
if_functional_type(struct ifnet
*);
1335 extern errno_t
if_mcasts_update(struct ifnet
*);
1336 extern int32_t total_snd_byte_count
;
1339 IFNET_LCK_ASSERT_EXCLUSIVE
, /* RW: held as writer */
1340 IFNET_LCK_ASSERT_SHARED
, /* RW: held as reader */
1341 IFNET_LCK_ASSERT_OWNED
, /* RW: writer/reader, MTX: held */
1342 IFNET_LCK_ASSERT_NOTOWNED
/* not held */
1343 } ifnet_lock_assert_t
;
1345 #define IF_LLADDR(_ifp) \
1346 (LLADDR(SDL(((_ifp)->if_lladdr)->ifa_addr)))
1348 __private_extern__
void ifnet_lock_assert(struct ifnet
*, ifnet_lock_assert_t
);
1349 __private_extern__
void ifnet_lock_shared(struct ifnet
*ifp
);
1350 __private_extern__
void ifnet_lock_exclusive(struct ifnet
*ifp
);
1351 __private_extern__
void ifnet_lock_done(struct ifnet
*ifp
);
1354 __private_extern__
void if_inetdata_lock_shared(struct ifnet
*ifp
);
1355 __private_extern__
void if_inetdata_lock_exclusive(struct ifnet
*ifp
);
1356 __private_extern__
void if_inetdata_lock_done(struct ifnet
*ifp
);
1360 __private_extern__
void if_inet6data_lock_shared(struct ifnet
*ifp
);
1361 __private_extern__
void if_inet6data_lock_exclusive(struct ifnet
*ifp
);
1362 __private_extern__
void if_inet6data_lock_done(struct ifnet
*ifp
);
1365 __private_extern__
void ifnet_head_lock_shared(void);
1366 __private_extern__
void ifnet_head_lock_exclusive(void);
1367 __private_extern__
void ifnet_head_done(void);
1369 __private_extern__ errno_t
ifnet_set_idle_flags_locked(ifnet_t
, u_int32_t
,
1371 __private_extern__
int ifnet_is_attached(struct ifnet
*, int refio
);
1372 __private_extern__
void ifnet_decr_iorefcnt(struct ifnet
*);
1373 __private_extern__
void ifnet_set_start_cycle(struct ifnet
*,
1375 __private_extern__
void ifnet_set_poll_cycle(struct ifnet
*,
1378 __private_extern__
void if_attach_ifa(struct ifnet
*, struct ifaddr
*);
1379 __private_extern__
void if_attach_link_ifa(struct ifnet
*, struct ifaddr
*);
1380 __private_extern__
void if_detach_ifa(struct ifnet
*, struct ifaddr
*);
1381 __private_extern__
void if_detach_link_ifa(struct ifnet
*, struct ifaddr
*);
1383 __private_extern__
void dlil_if_lock(void);
1384 __private_extern__
void dlil_if_unlock(void);
1385 __private_extern__
void dlil_if_lock_assert(void);
1387 extern struct ifaddr
*ifa_ifwithaddr(const struct sockaddr
*);
1388 extern struct ifaddr
*ifa_ifwithaddr_scoped(const struct sockaddr
*,
1390 extern struct ifaddr
*ifa_ifwithdstaddr(const struct sockaddr
*);
1391 extern struct ifaddr
*ifa_ifwithnet(const struct sockaddr
*);
1392 extern struct ifaddr
*ifa_ifwithnet_scoped(const struct sockaddr
*,
1394 extern struct ifaddr
*ifa_ifwithroute(int, const struct sockaddr
*,
1395 const struct sockaddr
*);
1396 extern struct ifaddr
*ifa_ifwithroute_locked(int, const struct sockaddr
*,
1397 const struct sockaddr
*);
1398 extern struct ifaddr
*ifa_ifwithroute_scoped_locked(int,
1399 const struct sockaddr
*, const struct sockaddr
*, unsigned int);
1400 extern struct ifaddr
*ifaof_ifpforaddr(const struct sockaddr
*, struct ifnet
*);
1401 __private_extern__
struct ifaddr
*ifa_ifpgetprimary(struct ifnet
*, int);
1402 extern void ifa_addref(struct ifaddr
*, int);
1403 extern struct ifaddr
*ifa_remref(struct ifaddr
*, int);
1404 extern void ifa_lock_init(struct ifaddr
*);
1405 extern void ifa_lock_destroy(struct ifaddr
*);
1406 extern void ifma_addref(struct ifmultiaddr
*, int);
1407 extern void ifma_remref(struct ifmultiaddr
*);
1409 extern void ifa_init(void);
1411 __private_extern__
struct in_ifaddr
*ifa_foraddr(unsigned int);
1412 __private_extern__
struct in_ifaddr
*ifa_foraddr_scoped(unsigned int,
1416 extern errno_t
ifnet_getset_opportunistic(struct ifnet
*, u_long
,
1417 struct ifreq
*, struct proc
*);
1418 extern int ifnet_get_throttle(struct ifnet
*, u_int32_t
*);
1419 extern int ifnet_set_throttle(struct ifnet
*, u_int32_t
);
1420 extern errno_t
ifnet_getset_log(struct ifnet
*, u_long
,
1421 struct ifreq
*, struct proc
*);
1422 extern int ifnet_set_log(struct ifnet
*, int32_t, uint32_t, int32_t, int32_t);
1423 extern int ifnet_get_log(struct ifnet
*, int32_t *, uint32_t *, int32_t *,
1425 extern int ifnet_notify_address(struct ifnet
*, int);
1429 __private_extern__
struct in6_ifaddr
*ifa_foraddr6(struct in6_addr
*);
1430 __private_extern__
struct in6_ifaddr
*ifa_foraddr6_scoped(struct in6_addr
*,
1434 __private_extern__
void if_data_internal_to_if_data(struct ifnet
*ifp
,
1435 const struct if_data_internal
*if_data_int
, struct if_data
*if_data
);
1436 __private_extern__
void if_data_internal_to_if_data64(struct ifnet
*ifp
,
1437 const struct if_data_internal
*if_data_int
, struct if_data64
*if_data64
);
1438 __private_extern__
void if_copy_traffic_class(struct ifnet
*ifp
,
1439 struct if_traffic_class
*if_tc
);
1440 __private_extern__
void if_copy_data_extended(struct ifnet
*ifp
,
1441 struct if_data_extended
*if_de
);
1442 __private_extern__
void if_copy_packet_stats(struct ifnet
*ifp
,
1443 struct if_packet_stats
*if_ps
);
1444 __private_extern__
void if_copy_rxpoll_stats(struct ifnet
*ifp
,
1445 struct if_rxpoll_stats
*if_rs
);
1447 __private_extern__
struct rtentry
*ifnet_cached_rtlookup_inet(struct ifnet
*,
1450 __private_extern__
struct rtentry
*ifnet_cached_rtlookup_inet6(struct ifnet
*,
1454 __private_extern__ errno_t
if_state_update(struct ifnet
*,
1455 struct if_interface_state
*);
1456 __private_extern__
void if_get_state(struct ifnet
*,
1457 struct if_interface_state
*);
1458 __private_extern__ errno_t
if_probe_connectivity(struct ifnet
*ifp
,
1459 u_int32_t conn_probe
);
1460 __private_extern__
void if_lqm_update(struct ifnet
*, int32_t, int);
1461 __private_extern__
void ifnet_update_sndq(struct ifclassq
*, cqev_t
);
1462 __private_extern__
void ifnet_update_rcv(struct ifnet
*, cqev_t
);
1464 __private_extern__
void ifnet_flowadv(uint32_t);
1466 __private_extern__ errno_t
ifnet_set_input_bandwidths(struct ifnet
*,
1467 struct if_bandwidths
*);
1468 __private_extern__ errno_t
ifnet_set_output_bandwidths(struct ifnet
*,
1469 struct if_bandwidths
*, boolean_t
);
1470 __private_extern__ u_int64_t
ifnet_output_linkrate(struct ifnet
*);
1471 __private_extern__ u_int64_t
ifnet_input_linkrate(struct ifnet
*);
1473 __private_extern__ errno_t
ifnet_set_input_latencies(struct ifnet
*,
1474 struct if_latencies
*);
1475 __private_extern__ errno_t
ifnet_set_output_latencies(struct ifnet
*,
1476 struct if_latencies
*, boolean_t
);
1478 __private_extern__
void ifnet_clear_netagent(uuid_t
);
1480 __private_extern__
int ifnet_set_netsignature(struct ifnet
*, uint8_t,
1481 uint8_t, uint16_t, uint8_t *);
1482 __private_extern__
int ifnet_get_netsignature(struct ifnet
*, uint8_t,
1483 uint8_t *, uint16_t *, uint8_t *);
1485 __private_extern__ errno_t
ifnet_framer_stub(struct ifnet
*, struct mbuf
**,
1486 const struct sockaddr
*, const char *, const char *, u_int32_t
*,
1488 #endif /* BSD_KERNEL_PRIVATE */
1489 #ifdef XNU_KERNEL_PRIVATE
1491 __private_extern__
int uuid_get_ethernet(u_int8_t
*);
1492 #endif /* XNU_KERNEL_PRIVATE */
1493 #endif /* !_NET_IF_VAR_H_ */