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) */
331 * Interface link status report -- includes statistics related to
332 * the link layer technology sent by the driver. The driver will monitor
333 * these statistics over an interval (3-4 secs) and will generate a report
334 * to the network stack. This will give first-hand information about the
335 * status of the first hop of the network path. The version and
336 * length values should be correct for the data to be processed correctly.
337 * The definitions are different for different kind of interfaces like
338 * Wifi, Cellular etc,.
340 #define IF_CELLULAR_STATUS_REPORT_VERSION_1 1
341 #define IF_WIFI_STATUS_REPORT_VERSION_1 1
342 #define IF_CELLULAR_STATUS_REPORT_CURRENT_VERSION \
343 IF_CELLULAR_STATUS_REPORT_VERSION_1
344 #define IF_WIFI_STATUS_REPORT_CURRENT_VERSION IF_WIFI_STATUS_REPORT_VERSION_1
346 * For cellular interface --
347 * There is no way to share common headers between the Baseband and
348 * the kernel. Any changes to this structure will need to be communicated
349 * to the Baseband team. It is better to use reserved space instead of
350 * changing the size or existing fields in the structure.
352 struct if_cellular_status_v1
{
353 u_int32_t valid_bitmask
; /* indicates which fields are valid */
354 #define IF_CELL_LINK_QUALITY_METRIC_VALID 0x1
355 #define IF_CELL_UL_EFFECTIVE_BANDWIDTH_VALID 0x2
356 #define IF_CELL_UL_MAX_BANDWIDTH_VALID 0x4
357 #define IF_CELL_UL_MIN_LATENCY_VALID 0x8
358 #define IF_CELL_UL_EFFECTIVE_LATENCY_VALID 0x10
359 #define IF_CELL_UL_MAX_LATENCY_VALID 0x20
360 #define IF_CELL_UL_RETXT_LEVEL_VALID 0x40
361 #define IF_CELL_UL_BYTES_LOST_VALID 0x80
362 #define IF_CELL_UL_MIN_QUEUE_SIZE_VALID 0x100
363 #define IF_CELL_UL_AVG_QUEUE_SIZE_VALID 0x200
364 #define IF_CELL_UL_MAX_QUEUE_SIZE_VALID 0x400
365 #define IF_CELL_DL_EFFECTIVE_BANDWIDTH_VALID 0x800
366 #define IF_CELL_DL_MAX_BANDWIDTH_VALID 0x1000
367 #define IF_CELL_CONFIG_INACTIVITY_TIME_VALID 0x2000
368 #define IF_CELL_CONFIG_BACKOFF_TIME_VALID 0x4000
369 u_int32_t link_quality_metric
;
370 u_int32_t ul_effective_bandwidth
; /* Measured uplink bandwidth based on current activity (bps) */
371 u_int32_t ul_max_bandwidth
; /* Maximum supported uplink bandwidth (bps) */
372 u_int32_t ul_min_latency
; /* min expected uplink latency for first hop (ms) */
373 u_int32_t ul_effective_latency
; /* current expected uplink latency for first hop (ms) */
374 u_int32_t ul_max_latency
; /* max expected uplink latency first hop (ms) */
375 u_int32_t ul_retxt_level
; /* Retransmission metric */
376 #define IF_CELL_UL_RETXT_LEVEL_NONE 1
377 #define IF_CELL_UL_RETXT_LEVEL_LOW 2
378 #define IF_CELL_UL_RETXT_LEVEL_MEDIUM 3
379 #define IF_CELL_UL_RETXT_LEVEL_HIGH 4
380 u_int32_t ul_bytes_lost
; /* % of total bytes lost on uplink in Q10 format */
381 u_int32_t ul_min_queue_size
; /* minimum bytes in queue */
382 u_int32_t ul_avg_queue_size
; /* average bytes in queue */
383 u_int32_t ul_max_queue_size
; /* maximum bytes in queue */
384 u_int32_t dl_effective_bandwidth
; /* Measured downlink bandwidth based on current activity (bps) */
385 u_int32_t dl_max_bandwidth
; /* Maximum supported downlink bandwidth (bps) */
386 u_int32_t config_inactivity_time
; /* ms */
387 u_int32_t config_backoff_time
; /* new connections backoff time in ms */
388 u_int64_t reserved_1
;
389 u_int64_t reserved_2
;
390 u_int64_t reserved_3
;
391 u_int64_t reserved_4
;
392 u_int64_t reserved_5
;
393 } __attribute__((packed
));
395 struct if_cellular_status
{
397 struct if_cellular_status_v1 if_status_v1
;
402 * These statistics will be provided by the Wifi driver periodically.
403 * After sending each report, the driver should start computing again
404 * for the next report duration so that the values represent the link
405 * status for one report duration.
408 struct if_wifi_status_v1
{
409 u_int32_t valid_bitmask
;
410 #define IF_WIFI_LINK_QUALITY_METRIC_VALID 0x1
411 #define IF_WIFI_UL_EFFECTIVE_BANDWIDTH_VALID 0x2
412 #define IF_WIFI_UL_MAX_BANDWIDTH_VALID 0x4
413 #define IF_WIFI_UL_MIN_LATENCY_VALID 0x8
414 #define IF_WIFI_UL_EFFECTIVE_LATENCY_VALID 0x10
415 #define IF_WIFI_UL_MAX_LATENCY_VALID 0x20
416 #define IF_WIFI_UL_RETXT_LEVEL_VALID 0x40
417 #define IF_WIFI_UL_ERROR_RATE_VALID 0x80
418 #define IF_WIFI_UL_BYTES_LOST_VALID 0x100
419 #define IF_WIFI_DL_EFFECTIVE_BANDWIDTH_VALID 0x200
420 #define IF_WIFI_DL_MAX_BANDWIDTH_VALID 0x400
421 #define IF_WIFI_DL_MIN_LATENCY_VALID 0x800
422 #define IF_WIFI_DL_EFFECTIVE_LATENCY_VALID 0x1000
423 #define IF_WIFI_DL_MAX_LATENCY_VALID 0x2000
424 #define IF_WIFI_DL_ERROR_RATE_VALID 0x4000
425 #define IF_WIFI_CONFIG_FREQUENCY_VALID 0x8000
426 #define IF_WIFI_CONFIG_MULTICAST_RATE_VALID 0x10000
427 #define IF_WIFI_CONFIG_SCAN_COUNT_VALID 0x20000
428 #define IF_WIFI_CONFIG_SCAN_DURATION_VALID 0x40000
429 u_int32_t link_quality_metric
; /* link quality metric */
430 u_int32_t ul_effective_bandwidth
; /* Measured uplink bandwidth based on current activity (bps) */
431 u_int32_t ul_max_bandwidth
; /* Maximum supported uplink bandwidth (bps) */
432 u_int32_t ul_min_latency
; /* min expected uplink latency for first hop (ms) */
433 u_int32_t ul_effective_latency
; /* current expected uplink latency for first hop (ms) */
434 u_int32_t ul_max_latency
; /* max expected uplink latency for first hop (ms) */
435 u_int32_t ul_retxt_level
; /* Retransmission metric */
436 #define IF_WIFI_UL_RETXT_LEVEL_NONE 1
437 #define IF_WIFI_UL_RETXT_LEVEL_LOW 2
438 #define IF_WIFI_UL_RETXT_LEVEL_MEDIUM 3
439 #define IF_WIFI_UL_RETXT_LEVEL_HIGH 4
440 u_int32_t ul_bytes_lost
; /* % of total bytes lost on uplink in Q10 format */
441 u_int32_t ul_error_rate
; /* % of bytes dropped on uplink after many retransmissions in Q10 format */
442 u_int32_t dl_effective_bandwidth
; /* Measured downlink bandwidth based on current activity (bps) */
443 u_int32_t dl_max_bandwidth
; /* Maximum supported downlink bandwidth (bps) */
445 * The download latency values indicate the time AP may have to wait for the
446 * driver to receive the packet. These values give the range of expected latency
447 * mainly due to co-existence events and channel hopping where the interface
448 * becomes unavailable.
450 u_int32_t dl_min_latency
; /* min expected latency for first hop in ms */
451 u_int32_t dl_effective_latency
; /* current expected latency for first hop in ms */
452 u_int32_t dl_max_latency
; /* max expected latency for first hop in ms */
453 u_int32_t dl_error_rate
; /* % of CRC or other errors in Q10 format */
454 u_int32_t config_frequency
; /* 2.4 or 5 GHz */
455 #define IF_WIFI_CONFIG_FREQUENCY_2_4_GHZ 1
456 #define IF_WIFI_CONFIG_FREQUENCY_5_0_GHZ 2
457 u_int32_t config_multicast_rate
; /* bps */
458 u_int32_t scan_count
; /* scan count during the previous period */
459 u_int32_t scan_duration
; /* scan duration in ms */
460 u_int64_t reserved_1
;
461 u_int64_t reserved_2
;
462 u_int64_t reserved_3
;
463 u_int64_t reserved_4
;
464 } __attribute__((packed
));
466 struct if_wifi_status
{
468 struct if_wifi_status_v1 if_status_v1
;
472 struct if_link_status
{
473 u_int32_t ifsr_version
; /* version of this report */
474 u_int32_t ifsr_len
; /* length of the following struct */
476 struct if_cellular_status ifsr_cell
;
477 struct if_wifi_status ifsr_wifi
;
481 struct if_interface_state
{
483 * The bitmask tells which of the fields
485 * - When setting, to control which fields
486 * are being modified;
487 * - When getting, it tells which fields are set.
489 u_int8_t valid_bitmask
;
490 #define IF_INTERFACE_STATE_RRC_STATE_VALID 0x1
491 #define IF_INTERFACE_STATE_LQM_STATE_VALID 0x2
492 #define IF_INTERFACE_STATE_INTERFACE_AVAILABILITY_VALID 0x4
495 * Valid only for cellular interface
498 #define IF_INTERFACE_STATE_RRC_STATE_IDLE 0x0
499 #define IF_INTERFACE_STATE_RRC_STATE_CONNECTED 0x1
502 * Values normalized to the edge of the following values
503 * that are defined on <net/if.h>:
504 * IFNET_LQM_THRESH_BAD
505 * IFNET_LQM_THRESH_POOR
506 * IFNET_LQM_THRESH_GOOD
511 * Indicate if the underlying link is currently
514 u_int8_t interface_availability
;
515 #define IF_INTERFACE_STATE_INTERFACE_AVAILABLE 0x0
516 #define IF_INTERFACE_STATE_INTERFACE_UNAVAILABLE 0x1
519 struct chain_len_stats
{
524 uint64_t cls_five_or_more
;
532 * Structure defining a queue for a network interface.
542 #ifdef BSD_KERNEL_PRIVATE
544 * Internal storage of if_data. This is bound to change. Various places in the
545 * stack will translate this data structure in to the externally visible
546 * if_data structure above. Note that during interface attach time, the
547 * embedded if_data structure in ifnet is cleared, with the exception of
548 * some non-statistics related fields.
550 struct if_data_internal
{
551 /* generic interface information */
552 u_char ifi_type
; /* ethernet, tokenring, etc */
553 u_char ifi_typelen
; /* Length of frame type id */
554 u_char ifi_physical
; /* e.g., AUI, Thinnet, 10base-T, etc */
555 u_char ifi_addrlen
; /* media address length */
556 u_char ifi_hdrlen
; /* media header length */
557 u_char ifi_recvquota
; /* polling quota for receive intrs */
558 u_char ifi_xmitquota
; /* polling quota for xmit intrs */
559 u_char ifi_unused1
; /* for future use */
560 u_int32_t ifi_mtu
; /* maximum transmission unit */
561 u_int32_t ifi_metric
; /* routing metric (external only) */
562 u_int32_t ifi_baudrate
; /* linespeed */
563 u_int32_t ifi_preamblelen
;/* length of the packet preamble */
564 /* volatile statistics */
565 u_int64_t ifi_ipackets
; /* packets received on interface */
566 u_int64_t ifi_ierrors
; /* input errors on interface */
567 u_int64_t ifi_opackets
; /* packets sent on interface */
568 u_int64_t ifi_oerrors
; /* output errors on interface */
569 u_int64_t ifi_collisions
; /* collisions on csma interfaces */
570 u_int64_t ifi_ibytes
; /* total number of octets received */
571 u_int64_t ifi_obytes
; /* total number of octets sent */
572 u_int64_t ifi_imcasts
; /* packets received via multicast */
573 u_int64_t ifi_omcasts
; /* packets sent via multicast */
574 u_int64_t ifi_iqdrops
; /* dropped on input, this interface */
575 u_int64_t ifi_noproto
; /* destined for unsupported protocol */
576 u_int32_t ifi_recvtiming
; /* usec spent receiving when timing */
577 u_int32_t ifi_xmittiming
; /* usec spent xmitting when timing */
578 u_int64_t ifi_alignerrs
; /* unaligned (32-bit) input pkts */
579 u_int64_t ifi_dt_bytes
; /* Data threshold counter */
580 u_int64_t ifi_fpackets
; /* forwarded packets on interface */
581 u_int64_t ifi_fbytes
; /* forwarded bytes on interface */
582 struct timeval ifi_lastchange
; /* time of last administrative change */
583 u_int32_t ifi_hwassist
; /* HW offload capabilities */
584 u_int32_t ifi_tso_v4_mtu
; /* TCP Segment Offload IPv4 maximum segment size */
585 u_int32_t ifi_tso_v6_mtu
; /* TCP Segment Offload IPv6 maximum segment size */
590 * Fields per interface to measure perceived bandwidth.
592 struct if_measured_bw
{
593 u_int64_t bw
; /* measured bandwidth in bytes per ms */
594 u_int64_t bytes
; /* XXX not needed */
595 u_int64_t ts
; /* XXX not needed */
596 u_int64_t cur_seq
__attribute((aligned(8))); /* current sequence for marking a packet */
597 u_int64_t start_ts
; /* time at which a measurement started */
598 u_int64_t start_seq
; /* sequence at which a measurement should start */
599 u_int64_t last_seq
; /* last recorded seq */
600 u_int64_t last_ts
; /* last recorded ts */
601 u_int32_t flags
__attribute__((aligned(4))); /* flags */
602 #define IF_MEASURED_BW_INPROGRESS 0x1
603 #define IF_MEASURED_BW_CALCULATION 0x2
605 #endif /* MEASURE_BW */
606 #endif /* BSD_KERNEL_PRIVATE */
609 #define if_mtu if_data.ifi_mtu
610 #define if_type if_data.ifi_type
611 #define if_typelen if_data.ifi_typelen
612 #define if_physical if_data.ifi_physical
613 #define if_addrlen if_data.ifi_addrlen
614 #define if_hdrlen if_data.ifi_hdrlen
615 #define if_preamblelen if_data.ifi_preamblelen
616 #define if_metric if_data.ifi_metric
617 #define if_baudrate if_data.ifi_baudrate
618 #define if_hwassist if_data.ifi_hwassist
619 #define if_ipackets if_data.ifi_ipackets
620 #define if_ierrors if_data.ifi_ierrors
621 #define if_opackets if_data.ifi_opackets
622 #define if_oerrors if_data.ifi_oerrors
623 #define if_collisions if_data.ifi_collisions
624 #define if_ibytes if_data.ifi_ibytes
625 #define if_obytes if_data.ifi_obytes
626 #define if_imcasts if_data.ifi_imcasts
627 #define if_omcasts if_data.ifi_omcasts
628 #define if_iqdrops if_data.ifi_iqdrops
629 #define if_noproto if_data.ifi_noproto
630 #define if_lastchange if_data.ifi_lastchange
631 #define if_recvquota if_data.ifi_recvquota
632 #define if_xmitquota if_data.ifi_xmitquota
634 #ifdef BSD_KERNEL_PRIVATE
635 #define if_tso_v4_mtu if_data.ifi_tso_v4_mtu
636 #define if_tso_v6_mtu if_data.ifi_tso_v6_mtu
637 #define if_alignerrs if_data.ifi_alignerrs
638 #define if_dt_bytes if_data.ifi_dt_bytes
639 #define if_fpackets if_data.ifi_fpackets
640 #define if_fbytes if_data.ifi_fbytes
641 #endif /* BSD_KERNEL_PRIVATE */
643 #ifdef BSD_KERNEL_PRIVATE
645 * Forward structure declarations for function prototypes [sic].
654 struct proto_hash_entry
;
655 struct dlil_threading_info
;
656 struct tcpstat_local
;
657 struct udpstat_local
;
662 /* we use TAILQs so that the order of instantiation is preserved in the list */
663 TAILQ_HEAD(ifnethead
, ifnet
);
664 TAILQ_HEAD(ifaddrhead
, ifaddr
);
665 TAILQ_HEAD(ifprefixhead
, ifprefix
);
666 LIST_HEAD(ifmultihead
, ifmultiaddr
);
667 TAILQ_HEAD(tailq_head
, tqdummy
);
668 TAILQ_HEAD(ifnet_filter_head
, ifnet_filter
);
669 TAILQ_HEAD(ddesc_head_name
, dlil_demux_desc
);
670 #endif /* BSD_KERNEL_PRIVATE */
674 * All of the following IF_HWASSIST_* flags are defined in kpi_inteface.h as
675 * IFNET_* flags. These are redefined here as constants to avoid failures to
676 * build user level programs that can not include kpi_interface.h. It is
677 * important to keep this in sync with the definitions in kpi_interface.h.
678 * The corresponding constant for each definition is mentioned in the comment.
680 * Bottom 16 bits reserved for hardware checksum
682 #define IF_HWASSIST_CSUM_IP 0x0001 /* will csum IP, IFNET_CSUM_IP */
683 #define IF_HWASSIST_CSUM_TCP 0x0002 /* will csum TCP, IFNET_CSUM_TCP */
684 #define IF_HWASSIST_CSUM_UDP 0x0004 /* will csum UDP, IFNET_CSUM_UDP */
685 #define IF_HWASSIST_CSUM_IP_FRAGS 0x0008 /* will csum IP fragments, IFNET_CSUM_FRAGMENT */
686 #define IF_HWASSIST_CSUM_FRAGMENT 0x0010 /* will do IP fragmentation, IFNET_IP_FRAGMENT */
687 #define IF_HWASSIST_CSUM_TCPIPV6 0x0020 /* will csum TCPv6, IFNET_CSUM_TCPIPV6 */
688 #define IF_HWASSIST_CSUM_UDPIPV6 0x0040 /* will csum UDPv6, IFNET_CSUM_UDP */
689 #define IF_HWASSIST_CSUM_FRAGMENT_IPV6 0x0080 /* will do IPv6 fragmentation, IFNET_IPV6_FRAGMENT */
690 #define IF_HWASSIST_CSUM_PARTIAL 0x1000 /* simple Sum16 computation, IFNET_CSUM_PARTIAL */
691 #define IF_HWASSIST_CSUM_MASK 0xffff
692 #define IF_HWASSIST_CSUM_FLAGS(hwassist) ((hwassist) & IF_HWASSIST_CSUM_MASK)
695 #define IF_HWASSIST_VLAN_TAGGING 0x00010000 /* supports VLAN tagging, IFNET_VLAN_TAGGING */
696 #define IF_HWASSIST_VLAN_MTU 0x00020000 /* supports VLAN MTU-sized packet (for software VLAN), IFNET_VLAN_MTU */
698 /* TCP Segment Offloading support */
700 #define IF_HWASSIST_TSO_V4 0x00200000 /* will do TCP Segment offload for IPv4, IFNET_TSO_IPV4 */
701 #define IF_HWASSIST_TSO_V6 0x00400000 /* will do TCP Segment offload for IPv6, IFNET_TSO_IPV6 */
705 #define IFXNAMSIZ (IFNAMSIZ + 8) /* external name (name + unit) */
708 #ifdef BSD_KERNEL_PRIVATE
710 * ifnet is private to BSD portion of kernel
712 #include <sys/mcache.h>
713 #include <sys/tree.h>
714 #include <netinet/in.h>
715 #include <net/if_dl.h>
716 #include <net/classq/if_classq.h>
717 #include <net/if_types.h>
719 RB_HEAD(ll_reach_tree
, if_llreach
); /* define struct ll_reach_tree */
721 #define if_name(ifp) ifp->if_xname
723 * Structure defining a network interface.
725 * (Would like to call this struct ``if'', but C isn't PL/1.)
729 * Lock (RW or mutex) to protect this data structure (static storage.)
731 decl_lck_rw_data(, if_lock
);
732 void *if_softc
; /* pointer to driver state */
733 const char *if_name
; /* name, e.g. ``en'' or ``lo'' */
734 const char *if_xname
; /* external name (name + unit) */
735 struct if_description if_desc
; /* extended description */
736 TAILQ_ENTRY(ifnet
) if_link
; /* all struct ifnets are chained */
737 TAILQ_ENTRY(ifnet
) if_detaching_link
; /* list of detaching ifnets */
739 decl_lck_mtx_data(, if_ref_lock
)
740 u_int32_t if_refflags
; /* see IFRF flags below */
741 u_int32_t if_refio
; /* number of io ops to the underlying driver */
743 #define if_list if_link
744 struct ifaddrhead if_addrhead
; /* linked list of addresses per if */
745 #define if_addrlist if_addrhead
746 struct ifaddr
*if_lladdr
; /* link address (first/permanent) */
748 int if_pcount
; /* number of promiscuous listeners */
749 struct bpf_if
*if_bpf
; /* packet filter structure */
750 u_short if_index
; /* numeric abbreviation for this if */
751 short if_unit
; /* sub-unit for lower level driver */
752 short if_timer
; /* time 'til if_watchdog called */
753 short if_flags
; /* up/down, broadcast, etc. */
754 u_int32_t if_eflags
; /* see <net/if.h> */
756 int if_capabilities
; /* interface features & capabilities */
757 int if_capenable
; /* enabled features & capabilities */
759 void *if_linkmib
; /* link-type-specific MIB data */
760 size_t if_linkmiblen
; /* length of above data */
762 struct if_data_internal if_data
__attribute__((aligned(8)));
764 ifnet_family_t if_family
; /* value assigned by Apple */
765 ifnet_subfamily_t if_subfamily
; /* value assigned by Apple */
766 uintptr_t if_family_cookie
;
767 ifnet_output_func if_output
;
768 ifnet_pre_enqueue_func if_pre_enqueue
;
769 ifnet_start_func if_start
;
770 ifnet_ctl_func if_output_ctl
;
771 ifnet_input_poll_func if_input_poll
;
772 ifnet_ctl_func if_input_ctl
;
773 ifnet_ioctl_func if_ioctl
;
774 ifnet_set_bpf_tap if_set_bpf_tap
;
775 ifnet_detached_func if_free
;
776 ifnet_demux_func if_demux
;
777 ifnet_event_func if_event
;
778 ifnet_framer_func if_framer_legacy
;
779 ifnet_framer_extended_func if_framer
;
780 ifnet_add_proto_func if_add_proto
;
781 ifnet_del_proto_func if_del_proto
;
782 ifnet_check_multi if_check_multi
;
783 struct proto_hash_entry
*if_proto_hash
;
784 void *if_kpi_storage
;
786 u_int32_t if_flowhash
; /* interface flow control ID */
788 decl_lck_mtx_data(, if_start_lock
);
789 u_int32_t if_start_flags
; /* see IFSF flags below */
790 u_int32_t if_start_req
;
791 u_int16_t if_start_active
; /* output is active */
792 u_int16_t if_start_delayed
;
793 u_int16_t if_start_delay_qlen
;
794 u_int16_t if_start_delay_idle
;
795 u_int64_t if_start_delay_swin
;
796 u_int32_t if_start_delay_cnt
;
797 u_int32_t if_start_delay_timeout
; /* nanoseconds */
798 struct timespec if_start_cycle
; /* restart interval */
799 struct thread
*if_start_thread
;
801 struct ifclassq if_snd
; /* transmit queue */
802 u_int32_t if_output_sched_model
; /* tx sched model */
804 struct if_bandwidths if_output_bw
;
805 struct if_bandwidths if_input_bw
;
807 struct if_latencies if_output_lt
;
808 struct if_latencies if_input_lt
;
810 decl_lck_mtx_data(, if_flt_lock
)
811 u_int32_t if_flt_busy
;
812 u_int32_t if_flt_waiters
;
813 struct ifnet_filter_head if_flt_head
;
815 struct ifmultihead if_multiaddrs
; /* multicast addresses */
816 u_int32_t if_updatemcasts
; /* mcast addrs need updating */
817 int if_amcount
; /* # of all-multicast reqs */
818 decl_lck_mtx_data(, if_addrconfig_lock
); /* for serializing addr config */
819 struct in_multi
*if_allhostsinm
; /* store all-hosts inm for this ifp */
821 decl_lck_mtx_data(, if_poll_lock
);
822 u_int16_t if_poll_req
;
823 u_int16_t if_poll_update
; /* link update */
824 u_int32_t if_poll_active
; /* polling is active */
825 struct timespec if_poll_cycle
; /* poll interval */
826 struct thread
*if_poll_thread
;
828 struct dlil_threading_info
*if_inp
;
830 struct ifprefixhead if_prefixhead
; /* list of prefixes per if */
839 struct label
*if_label
; /* interface MAC label */
842 u_int32_t if_wake_properties
;
844 struct pfi_kif
*if_pf_kif
;
847 decl_lck_mtx_data(, if_cached_route_lock
);
848 u_int32_t if_fwd_cacheok
;
849 struct route if_fwd_route
; /* cached forwarding route */
850 struct route if_src_route
; /* cached ipv4 source route */
851 struct route_in6 if_src_route6
; /* cached ipv6 source route */
853 decl_lck_rw_data(, if_llreach_lock
);
854 struct ll_reach_tree if_ll_srcs
; /* source link-layer tree */
856 void *if_bridge
; /* bridge glue */
858 u_int32_t if_want_aggressive_drain
;
859 u_int32_t if_idle_flags
; /* idle flags */
860 u_int32_t if_idle_new_flags
; /* temporary idle flags */
861 u_int32_t if_idle_new_flags_mask
; /* temporary mask */
862 u_int32_t if_route_refcnt
; /* idle: route ref count */
864 struct if_traffic_class if_tc
__attribute__((aligned(8)));
866 struct igmp_ifinfo
*if_igi
; /* for IGMPv3 */
869 struct mld_ifinfo
*if_mli
; /* for MLDv2 */
873 struct if_measured_bw if_bw
;
874 #endif /* MEASURE_BW */
875 struct tcpstat_local
*if_tcp_stat
; /* TCP specific stats */
876 struct udpstat_local
*if_udp_stat
; /* UDP specific stats */
879 int32_t level
; /* cached logging level */
880 u_int32_t flags
; /* cached logging flags */
881 int32_t category
; /* cached category */
882 int32_t subcategory
; /* cached subcategory */
886 struct ifnet
*ifp
; /* delegated ifp */
887 u_int32_t type
; /* delegated i/f type */
888 u_int32_t family
; /* delegated i/f family */
889 u_int32_t subfamily
; /* delegated i/f sub-family */
890 uint32_t expensive
:1; /* delegated i/f expensive? */
893 #define IF_MAXAGENTS 8
894 uuid_t if_agentids
[IF_MAXAGENTS
];
896 u_int64_t if_data_threshold
;
897 u_int32_t if_fg_sendts
; /* last send on a fg socket in seconds */
898 u_int32_t if_rt_sendts
; /* last of a real time packet */
901 decl_lck_rw_data(, if_inetdata_lock
);
905 decl_lck_rw_data(, if_inet6data_lock
);
908 decl_lck_rw_data(, if_link_status_lock
);
909 struct if_link_status
*if_link_status
;
910 struct if_interface_state if_interface_state
;
913 #define IF_TCP_STATINC(_ifp, _s) do { \
914 if ((_ifp)->if_tcp_stat != NULL) \
915 atomic_add_64(&(_ifp)->if_tcp_stat->_s, 1); \
918 #define IF_UDP_STATINC(_ifp, _s) do { \
919 if ((_ifp)->if_udp_stat != NULL) \
920 atomic_add_64(&(_ifp)->if_udp_stat->_s, 1); \
924 * Valid values for if_refflags
926 #define IFRF_ATTACHED 0x1 /* ifnet attach is completely done */
927 #define IFRF_DETACHING 0x2 /* detach has been requested */
930 * Valid values for if_start_flags
932 #define IFSF_FLOW_CONTROLLED 0x1 /* flow controlled */
935 * Structure describing a `cloning' interface.
938 LIST_ENTRY(if_clone
) ifc_list
; /* on list of cloners */
939 const char *ifc_name
; /* name of device, e.g. `vlan' */
940 size_t ifc_namelen
; /* length of name */
941 u_int32_t ifc_minifs
; /* minimum number of interfaces */
942 u_int32_t ifc_maxunit
; /* maximum unit number */
943 unsigned char *ifc_units
; /* bitmap to handle units */
944 u_int32_t ifc_bmlen
; /* bitmap length */
946 int (*ifc_create
)(struct if_clone
*, u_int32_t
, void *);
947 int (*ifc_destroy
)(struct ifnet
*);
950 #define IF_CLONE_INITIALIZER(name, create, destroy, minifs, maxunit) { \
951 { NULL, NULL }, name, (sizeof (name) - 1), minifs, maxunit, NULL, 0, \
955 #define M_CLONE M_IFADDR
958 * Macros to manipulate ifqueue. Users of these macros are responsible
959 * for serialization, by holding whatever lock is appropriate for the
960 * corresponding structure that is referring the ifqueue.
962 #define IF_QFULL(ifq) ((ifq)->ifq_len >= (ifq)->ifq_maxlen)
963 #define IF_DROP(ifq) ((ifq)->ifq_drops++)
965 #define IF_ENQUEUE(ifq, m) do { \
966 (m)->m_nextpkt = NULL; \
967 if ((ifq)->ifq_tail == NULL) \
968 (ifq)->ifq_head = m; \
970 ((struct mbuf*)(ifq)->ifq_tail)->m_nextpkt = m; \
971 (ifq)->ifq_tail = m; \
975 #define IF_PREPEND(ifq, m) do { \
976 (m)->m_nextpkt = (ifq)->ifq_head; \
977 if ((ifq)->ifq_tail == NULL) \
978 (ifq)->ifq_tail = (m); \
979 (ifq)->ifq_head = (m); \
983 #define IF_DEQUEUE(ifq, m) do { \
984 (m) = (ifq)->ifq_head; \
986 if (((ifq)->ifq_head = (m)->m_nextpkt) == NULL) \
987 (ifq)->ifq_tail = NULL; \
988 (m)->m_nextpkt = NULL; \
993 #define IF_REMQUEUE(ifq, m) do { \
994 struct mbuf *_p = (ifq)->ifq_head; \
995 struct mbuf *_n = (m)->m_nextpkt; \
998 while (_p != NULL) { \
999 if (_p->m_nextpkt == (m)) \
1001 _p = _p->m_nextpkt; \
1003 VERIFY(_p != NULL || ((m) == (ifq)->ifq_head)); \
1004 if ((m) == (ifq)->ifq_head) \
1005 (ifq)->ifq_head = _n; \
1006 if ((m) == (ifq)->ifq_tail) \
1007 (ifq)->ifq_tail = _p; \
1008 VERIFY((ifq)->ifq_tail != NULL || (ifq)->ifq_head == NULL); \
1009 VERIFY((ifq)->ifq_len != 0); \
1012 _p->m_nextpkt = _n; \
1013 (m)->m_nextpkt = NULL; \
1016 #define IF_DRAIN(ifq) do { \
1019 IF_DEQUEUE(ifq, _m); \
1027 * The ifaddr structure contains information about one address
1028 * of an interface. They are maintained by the different address families,
1029 * are allocated and attached when an address is set, and are linked
1030 * together so all addresses for an interface can be located.
1033 decl_lck_mtx_data(, ifa_lock
); /* lock for ifaddr */
1034 uint32_t ifa_refcnt
; /* ref count, use IFA_{ADD,REM}REF */
1035 uint32_t ifa_debug
; /* debug flags */
1036 struct sockaddr
*ifa_addr
; /* address of interface */
1037 struct sockaddr
*ifa_dstaddr
; /* other end of p-to-p link */
1038 #define ifa_broadaddr ifa_dstaddr /* broadcast address interface */
1039 struct sockaddr
*ifa_netmask
; /* used to determine subnet */
1040 struct ifnet
*ifa_ifp
; /* back-pointer to interface */
1041 TAILQ_ENTRY(ifaddr
) ifa_link
; /* queue macro glue */
1042 void (*ifa_rtrequest
) /* check or clean routes (+ or -)'d */
1043 (int, struct rtentry
*, struct sockaddr
*);
1044 uint32_t ifa_flags
; /* mostly rt_flags for cloning */
1045 int32_t ifa_metric
; /* cost of going out this interface */
1046 void (*ifa_free
)(struct ifaddr
*); /* callback fn for freeing */
1047 void (*ifa_trace
) /* callback fn for tracing refs */
1048 (struct ifaddr
*, int);
1049 void (*ifa_attached
)(struct ifaddr
*); /* callback fn for attaching */
1050 void (*ifa_detached
)(struct ifaddr
*); /* callback fn for detaching */
1055 * Valid values for ifa_flags
1057 #define IFA_ROUTE RTF_UP /* route installed (0x1) */
1058 #define IFA_CLONING RTF_CLONING /* (0x100) */
1061 * Valid values for ifa_debug
1063 #define IFD_ATTACHED 0x1 /* attached to list */
1064 #define IFD_ALLOC 0x2 /* dynamically allocated */
1065 #define IFD_DEBUG 0x4 /* has debugging info */
1066 #define IFD_LINK 0x8 /* link address */
1067 #define IFD_TRASHED 0x10 /* in trash list */
1068 #define IFD_SKIP 0x20 /* skip this entry */
1069 #define IFD_NOTREADY 0x40 /* embryonic; not yet ready */
1071 #define IFA_LOCK_ASSERT_HELD(_ifa) \
1072 lck_mtx_assert(&(_ifa)->ifa_lock, LCK_MTX_ASSERT_OWNED)
1074 #define IFA_LOCK_ASSERT_NOTHELD(_ifa) \
1075 lck_mtx_assert(&(_ifa)->ifa_lock, LCK_MTX_ASSERT_NOTOWNED)
1077 #define IFA_LOCK(_ifa) \
1078 lck_mtx_lock(&(_ifa)->ifa_lock)
1080 #define IFA_LOCK_SPIN(_ifa) \
1081 lck_mtx_lock_spin(&(_ifa)->ifa_lock)
1083 #define IFA_CONVERT_LOCK(_ifa) do { \
1084 IFA_LOCK_ASSERT_HELD(_ifa); \
1085 lck_mtx_convert_spin(&(_ifa)->ifa_lock); \
1088 #define IFA_UNLOCK(_ifa) \
1089 lck_mtx_unlock(&(_ifa)->ifa_lock)
1091 #define IFA_ADDREF(_ifa) \
1094 #define IFA_ADDREF_LOCKED(_ifa) \
1097 #define IFA_REMREF(_ifa) do { \
1098 (void) ifa_remref(_ifa, 0); \
1101 #define IFA_REMREF_LOCKED(_ifa) \
1105 * The prefix structure contains information about one prefix
1106 * of an interface. They are maintained by the different address families,
1107 * are allocated and attached when an prefix or an address is set,
1108 * and are linked together so all prefixes for an interface can be located.
1111 struct sockaddr
*ifpr_prefix
; /* prefix of interface */
1112 struct ifnet
*ifpr_ifp
; /* back-pointer to interface */
1113 TAILQ_ENTRY(ifprefix
) ifpr_list
; /* queue macro glue */
1114 u_char ifpr_plen
; /* prefix length in bits */
1115 u_char ifpr_type
; /* protocol dependent prefix type */
1119 * Multicast address structure. This is analogous to the ifaddr
1120 * structure except that it keeps track of multicast addresses.
1121 * Also, the request count here is a count of requests for this
1122 * address, not a count of pointers to this structure; anonymous
1123 * membership(s) holds one outstanding request count.
1125 struct ifmultiaddr
{
1126 decl_lck_mtx_data(, ifma_lock
);
1127 u_int32_t ifma_refcount
; /* reference count */
1128 u_int32_t ifma_anoncnt
; /* # of anonymous requests */
1129 u_int32_t ifma_reqcnt
; /* total requests for this address */
1130 u_int32_t ifma_debug
; /* see ifa_debug flags */
1131 u_int32_t ifma_flags
; /* see below */
1132 LIST_ENTRY(ifmultiaddr
) ifma_link
; /* queue macro glue */
1133 struct sockaddr
*ifma_addr
; /* address this membership is for */
1134 struct ifmultiaddr
*ifma_ll
; /* link-layer translation, if any */
1135 struct ifnet
*ifma_ifp
; /* back-pointer to interface */
1136 void *ifma_protospec
; /* protocol-specific state, if any */
1137 void (*ifma_trace
) /* callback fn for tracing refs */
1138 (struct ifmultiaddr
*, int);
1142 * Values for ifma_flags
1144 #define IFMAF_ANONYMOUS 0x1 /* has anonymous request ref(s) held */
1146 #define IFMA_LOCK_ASSERT_HELD(_ifma) \
1147 lck_mtx_assert(&(_ifma)->ifma_lock, LCK_MTX_ASSERT_OWNED)
1149 #define IFMA_LOCK_ASSERT_NOTHELD(_ifma) \
1150 lck_mtx_assert(&(_ifma)->ifma_lock, LCK_MTX_ASSERT_NOTOWNED)
1152 #define IFMA_LOCK(_ifma) \
1153 lck_mtx_lock(&(_ifma)->ifma_lock)
1155 #define IFMA_LOCK_SPIN(_ifma) \
1156 lck_mtx_lock_spin(&(_ifma)->ifma_lock)
1158 #define IFMA_CONVERT_LOCK(_ifma) do { \
1159 IFMA_LOCK_ASSERT_HELD(_ifma); \
1160 lck_mtx_convert_spin(&(_ifma)->ifma_lock); \
1163 #define IFMA_UNLOCK(_ifma) \
1164 lck_mtx_unlock(&(_ifma)->ifma_lock)
1166 #define IFMA_ADDREF(_ifma) \
1167 ifma_addref(_ifma, 0)
1169 #define IFMA_ADDREF_LOCKED(_ifma) \
1170 ifma_addref(_ifma, 1)
1172 #define IFMA_REMREF(_ifma) \
1176 * Indicate whether or not the immediate interface, or the interface delegated
1177 * by it, is a cellular interface (IFT_CELLULAR). Delegated interface type is
1178 * set/cleared along with the delegated ifp; we cache the type for performance
1179 * to avoid dereferencing delegated ifp each time.
1181 * Note that this is meant to be used only for accounting and policy purposes;
1182 * certain places need to explicitly know the immediate interface type, and
1183 * this macro should not be used there.
1185 * The test is done against IFT_CELLULAR instead of IFNET_FAMILY_CELLULAR to
1186 * handle certain cases where the family isn't set to the latter.
1188 #define IFNET_IS_CELLULAR(_ifp) \
1189 ((_ifp)->if_type == IFT_CELLULAR || \
1190 (_ifp)->if_delegated.type == IFT_CELLULAR)
1193 * Indicate whether or not the immediate interface, or the interface delegated
1194 * by it, is a Wi-Fi interface (IFNET_SUBFAMILY_WIFI). Delegated interface
1195 * subfamily is set/cleared along with the delegated ifp; we cache the subfamily
1196 * for performance to avoid dereferencing delegated ifp each time.
1198 * Note that this is meant to be used only for accounting and policy purposes;
1199 * certain places need to explicitly know the immediate interface type, and
1200 * this macro should not be used there.
1202 * The test is done against IFNET_SUBFAMILY_WIFI as the family may be set to
1203 * IFNET_FAMILY_ETHERNET (as well as type to IFT_ETHER) which is too generic.
1205 #define IFNET_IS_WIFI(_ifp) \
1206 ((_ifp)->if_subfamily == IFNET_SUBFAMILY_WIFI || \
1207 (_ifp)->if_delegated.subfamily == IFNET_SUBFAMILY_WIFI)
1210 * Indicate whether or not the immediate interface, or the interface delegated
1211 * by it, is a Wired interface (several families). Delegated interface
1212 * family is set/cleared along with the delegated ifp; we cache the family
1213 * for performance to avoid dereferencing delegated ifp each time.
1215 * Note that this is meant to be used only for accounting and policy purposes;
1216 * certain places need to explicitly know the immediate interface type, and
1217 * this macro should not be used there.
1219 #define IFNET_IS_WIRED(_ifp) \
1220 ((_ifp)->if_family == IFNET_FAMILY_ETHERNET || \
1221 (_ifp)->if_delegated.family == IFNET_FAMILY_ETHERNET || \
1222 (_ifp)->if_family == IFNET_FAMILY_FIREWIRE || \
1223 (_ifp)->if_delegated.family == IFNET_FAMILY_FIREWIRE)
1226 * Indicate whether or not the immediate interface, or the interface delegated
1227 * by it, is marked as expensive. The delegated interface is set/cleared
1228 * along with the delegated ifp; we cache the flag for performance to avoid
1229 * dereferencing delegated ifp each time.
1231 * Note that this is meant to be used only for policy purposes.
1233 #define IFNET_IS_EXPENSIVE(_ifp) \
1234 ((_ifp)->if_eflags & IFEF_EXPENSIVE || \
1235 (_ifp)->if_delegated.expensive)
1238 * We don't support AWDL interface delegation.
1240 #define IFNET_IS_AWDL_RESTRICTED(_ifp) \
1241 (((_ifp)->if_eflags & (IFEF_AWDL|IFEF_AWDL_RESTRICTED)) == \
1242 (IFEF_AWDL|IFEF_AWDL_RESTRICTED))
1245 extern struct ifnethead ifnet_head
;
1246 extern struct ifnet
**ifindex2ifnet
;
1247 extern u_int32_t if_sndq_maxlen
;
1248 extern u_int32_t if_rcvq_maxlen
;
1249 extern int if_index
;
1250 extern struct ifaddr
**ifnet_addrs
;
1251 extern lck_attr_t
*ifa_mtx_attr
;
1252 extern lck_grp_t
*ifa_mtx_grp
;
1253 extern lck_grp_t
*ifnet_lock_group
;
1254 extern lck_attr_t
*ifnet_lock_attr
;
1255 extern ifnet_t lo_ifp
;
1256 extern uint32_t if_bw_measure_size
;
1257 extern u_int32_t if_bw_smoothing_val
;
1259 extern int if_addmulti(struct ifnet
*, const struct sockaddr
*,
1260 struct ifmultiaddr
**);
1261 extern int if_addmulti_anon(struct ifnet
*, const struct sockaddr
*,
1262 struct ifmultiaddr
**);
1263 extern int if_allmulti(struct ifnet
*, int);
1264 extern int if_delmulti(struct ifnet
*, const struct sockaddr
*);
1265 extern int if_delmulti_ifma(struct ifmultiaddr
*);
1266 extern int if_delmulti_anon(struct ifnet
*, const struct sockaddr
*);
1267 extern void if_down(struct ifnet
*);
1268 extern int if_down_all(void);
1269 extern void if_up(struct ifnet
*);
1270 __private_extern__
void if_updown(struct ifnet
*ifp
, int up
);
1271 extern int ifioctl(struct socket
*, u_long
, caddr_t
, struct proc
*);
1272 extern int ifioctllocked(struct socket
*, u_long
, caddr_t
, struct proc
*);
1273 extern struct ifnet
*ifunit(const char *);
1274 extern struct ifnet
*if_withname(struct sockaddr
*);
1275 extern void if_qflush(struct ifnet
*, int);
1276 extern void if_qflush_sc(struct ifnet
*, mbuf_svc_class_t
, u_int32_t
,
1277 u_int32_t
*, u_int32_t
*, int);
1279 extern struct if_clone
*if_clone_lookup(const char *, u_int32_t
*);
1280 extern int if_clone_attach(struct if_clone
*);
1281 extern void if_clone_detach(struct if_clone
*);
1283 extern u_int32_t
if_functional_type(struct ifnet
*);
1285 extern errno_t
if_mcasts_update(struct ifnet
*);
1286 extern int32_t total_snd_byte_count
;
1289 IFNET_LCK_ASSERT_EXCLUSIVE
, /* RW: held as writer */
1290 IFNET_LCK_ASSERT_SHARED
, /* RW: held as reader */
1291 IFNET_LCK_ASSERT_OWNED
, /* RW: writer/reader, MTX: held */
1292 IFNET_LCK_ASSERT_NOTOWNED
/* not held */
1293 } ifnet_lock_assert_t
;
1295 #define IF_LLADDR(_ifp) \
1296 (LLADDR(SDL(((_ifp)->if_lladdr)->ifa_addr)))
1298 __private_extern__
void ifnet_lock_assert(struct ifnet
*, ifnet_lock_assert_t
);
1299 __private_extern__
void ifnet_lock_shared(struct ifnet
*ifp
);
1300 __private_extern__
void ifnet_lock_exclusive(struct ifnet
*ifp
);
1301 __private_extern__
void ifnet_lock_done(struct ifnet
*ifp
);
1304 __private_extern__
void if_inetdata_lock_shared(struct ifnet
*ifp
);
1305 __private_extern__
void if_inetdata_lock_exclusive(struct ifnet
*ifp
);
1306 __private_extern__
void if_inetdata_lock_done(struct ifnet
*ifp
);
1310 __private_extern__
void if_inet6data_lock_shared(struct ifnet
*ifp
);
1311 __private_extern__
void if_inet6data_lock_exclusive(struct ifnet
*ifp
);
1312 __private_extern__
void if_inet6data_lock_done(struct ifnet
*ifp
);
1315 __private_extern__
void ifnet_head_lock_shared(void);
1316 __private_extern__
void ifnet_head_lock_exclusive(void);
1317 __private_extern__
void ifnet_head_done(void);
1319 __private_extern__ errno_t
ifnet_set_idle_flags_locked(ifnet_t
, u_int32_t
,
1321 __private_extern__
int ifnet_is_attached(struct ifnet
*, int refio
);
1322 __private_extern__
void ifnet_decr_iorefcnt(struct ifnet
*);
1323 __private_extern__
void ifnet_set_start_cycle(struct ifnet
*,
1325 __private_extern__
void ifnet_set_poll_cycle(struct ifnet
*,
1328 __private_extern__
void if_attach_ifa(struct ifnet
*, struct ifaddr
*);
1329 __private_extern__
void if_attach_link_ifa(struct ifnet
*, struct ifaddr
*);
1330 __private_extern__
void if_detach_ifa(struct ifnet
*, struct ifaddr
*);
1331 __private_extern__
void if_detach_link_ifa(struct ifnet
*, struct ifaddr
*);
1333 __private_extern__
void dlil_if_lock(void);
1334 __private_extern__
void dlil_if_unlock(void);
1335 __private_extern__
void dlil_if_lock_assert(void);
1337 extern struct ifaddr
*ifa_ifwithaddr(const struct sockaddr
*);
1338 extern struct ifaddr
*ifa_ifwithaddr_scoped(const struct sockaddr
*,
1340 extern struct ifaddr
*ifa_ifwithdstaddr(const struct sockaddr
*);
1341 extern struct ifaddr
*ifa_ifwithnet(const struct sockaddr
*);
1342 extern struct ifaddr
*ifa_ifwithnet_scoped(const struct sockaddr
*,
1344 extern struct ifaddr
*ifa_ifwithroute(int, const struct sockaddr
*,
1345 const struct sockaddr
*);
1346 extern struct ifaddr
*ifa_ifwithroute_locked(int, const struct sockaddr
*,
1347 const struct sockaddr
*);
1348 extern struct ifaddr
*ifa_ifwithroute_scoped_locked(int,
1349 const struct sockaddr
*, const struct sockaddr
*, unsigned int);
1350 extern struct ifaddr
*ifaof_ifpforaddr(const struct sockaddr
*, struct ifnet
*);
1351 __private_extern__
struct ifaddr
*ifa_ifpgetprimary(struct ifnet
*, int);
1352 extern void ifa_addref(struct ifaddr
*, int);
1353 extern struct ifaddr
*ifa_remref(struct ifaddr
*, int);
1354 extern void ifa_lock_init(struct ifaddr
*);
1355 extern void ifa_lock_destroy(struct ifaddr
*);
1356 extern void ifma_addref(struct ifmultiaddr
*, int);
1357 extern void ifma_remref(struct ifmultiaddr
*);
1359 extern void ifa_init(void);
1361 __private_extern__
struct in_ifaddr
*ifa_foraddr(unsigned int);
1362 __private_extern__
struct in_ifaddr
*ifa_foraddr_scoped(unsigned int,
1366 extern errno_t
ifnet_getset_opportunistic(struct ifnet
*, u_long
,
1367 struct ifreq
*, struct proc
*);
1368 extern int ifnet_get_throttle(struct ifnet
*, u_int32_t
*);
1369 extern int ifnet_set_throttle(struct ifnet
*, u_int32_t
);
1370 extern errno_t
ifnet_getset_log(struct ifnet
*, u_long
,
1371 struct ifreq
*, struct proc
*);
1372 extern int ifnet_set_log(struct ifnet
*, int32_t, uint32_t, int32_t, int32_t);
1373 extern int ifnet_get_log(struct ifnet
*, int32_t *, uint32_t *, int32_t *,
1375 extern int ifnet_notify_address(struct ifnet
*, int);
1379 __private_extern__
struct in6_ifaddr
*ifa_foraddr6(struct in6_addr
*);
1380 __private_extern__
struct in6_ifaddr
*ifa_foraddr6_scoped(struct in6_addr
*,
1384 __private_extern__
void if_data_internal_to_if_data(struct ifnet
*ifp
,
1385 const struct if_data_internal
*if_data_int
, struct if_data
*if_data
);
1386 __private_extern__
void if_data_internal_to_if_data64(struct ifnet
*ifp
,
1387 const struct if_data_internal
*if_data_int
, struct if_data64
*if_data64
);
1388 __private_extern__
void if_copy_traffic_class(struct ifnet
*ifp
,
1389 struct if_traffic_class
*if_tc
);
1390 __private_extern__
void if_copy_data_extended(struct ifnet
*ifp
,
1391 struct if_data_extended
*if_de
);
1392 __private_extern__
void if_copy_packet_stats(struct ifnet
*ifp
,
1393 struct if_packet_stats
*if_ps
);
1394 __private_extern__
void if_copy_rxpoll_stats(struct ifnet
*ifp
,
1395 struct if_rxpoll_stats
*if_rs
);
1397 __private_extern__
struct rtentry
*ifnet_cached_rtlookup_inet(struct ifnet
*,
1400 __private_extern__
struct rtentry
*ifnet_cached_rtlookup_inet6(struct ifnet
*,
1404 __private_extern__ errno_t
if_state_update(struct ifnet
*,
1405 struct if_interface_state
*);
1406 __private_extern__
void if_get_state(struct ifnet
*,
1407 struct if_interface_state
*);
1408 __private_extern__ errno_t
if_probe_connectivity(struct ifnet
*ifp
,
1409 u_int32_t conn_probe
);
1410 __private_extern__
void if_lqm_update(struct ifnet
*, int32_t, int);
1411 __private_extern__
void ifnet_update_sndq(struct ifclassq
*, cqev_t
);
1412 __private_extern__
void ifnet_update_rcv(struct ifnet
*, cqev_t
);
1414 __private_extern__
void ifnet_flowadv(uint32_t);
1416 __private_extern__ errno_t
ifnet_set_input_bandwidths(struct ifnet
*,
1417 struct if_bandwidths
*);
1418 __private_extern__ errno_t
ifnet_set_output_bandwidths(struct ifnet
*,
1419 struct if_bandwidths
*, boolean_t
);
1420 __private_extern__ u_int64_t
ifnet_output_linkrate(struct ifnet
*);
1421 __private_extern__ u_int64_t
ifnet_input_linkrate(struct ifnet
*);
1423 __private_extern__ errno_t
ifnet_set_input_latencies(struct ifnet
*,
1424 struct if_latencies
*);
1425 __private_extern__ errno_t
ifnet_set_output_latencies(struct ifnet
*,
1426 struct if_latencies
*, boolean_t
);
1428 __private_extern__
void ifnet_clear_netagent(uuid_t
);
1430 __private_extern__
int ifnet_set_netsignature(struct ifnet
*, uint8_t,
1431 uint8_t, uint16_t, uint8_t *);
1432 __private_extern__
int ifnet_get_netsignature(struct ifnet
*, uint8_t,
1433 uint8_t *, uint16_t *, uint8_t *);
1435 __private_extern__ errno_t
ifnet_framer_stub(struct ifnet
*, struct mbuf
**,
1436 const struct sockaddr
*, const char *, const char *, u_int32_t
*,
1438 #endif /* BSD_KERNEL_PRIVATE */
1439 #ifdef XNU_KERNEL_PRIVATE
1441 __private_extern__
int uuid_get_ethernet(u_int8_t
*);
1442 #endif /* XNU_KERNEL_PRIVATE */
1443 #endif /* !_NET_IF_VAR_H_ */