]> git.saurik.com Git - apple/xnu.git/blame - bsd/net/if_var.h
xnu-3789.60.24.tar.gz
[apple/xnu.git] / bsd / net / if_var.h
CommitLineData
1c79356b 1/*
39037602 2 * Copyright (c) 2000-2016 Apple Inc. All rights reserved.
5d5c5d0d 3 *
2d21ac55 4 * @APPLE_OSREFERENCE_LICENSE_HEADER_START@
39236c6e 5 *
2d21ac55
A
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.
39236c6e 14 *
2d21ac55
A
15 * Please obtain a copy of the License at
16 * http://www.opensource.apple.com/apsl/ and read it before using this file.
39236c6e 17 *
2d21ac55
A
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
8f6c56a5
A
20 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
21 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
2d21ac55
A
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.
39236c6e 25 *
2d21ac55 26 * @APPLE_OSREFERENCE_LICENSE_HEADER_END@
1c79356b
A
27 */
28/*
29 * Copyright (c) 1982, 1986, 1989, 1993
30 * The Regents of the University of California. All rights reserved.
31 *
32 * Redistribution and use in source and binary forms, with or without
33 * modification, are permitted provided that the following conditions
34 * are met:
35 * 1. Redistributions of source code must retain the above copyright
36 * notice, this list of conditions and the following disclaimer.
37 * 2. Redistributions in binary form must reproduce the above copyright
38 * notice, this list of conditions and the following disclaimer in the
39 * documentation and/or other materials provided with the distribution.
40 * 3. All advertising materials mentioning features or use of this software
41 * must display the following acknowledgement:
42 * This product includes software developed by the University of
43 * California, Berkeley and its contributors.
44 * 4. Neither the name of the University nor the names of its contributors
45 * may be used to endorse or promote products derived from this software
46 * without specific prior written permission.
47 *
48 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
49 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
50 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
51 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
52 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
53 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
54 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
55 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
56 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
57 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
58 * SUCH DAMAGE.
59 *
60 * From: @(#)if.h 8.1 (Berkeley) 6/10/93
9bccf70c 61 * $FreeBSD: src/sys/net/if_var.h,v 1.18.2.7 2001/07/24 19:10:18 brooks Exp $
1c79356b
A
62 */
63
64#ifndef _NET_IF_VAR_H_
65#define _NET_IF_VAR_H_
91447636 66
9bccf70c 67#include <sys/appleapiopts.h>
b0d623f7 68#include <stdint.h>
91447636
A
69#include <sys/types.h>
70#include <sys/time.h>
71#include <sys/queue.h> /* get TAILQ macros */
72#ifdef KERNEL_PRIVATE
73#include <kern/locks.h>
74#endif /* KERNEL_PRIVATE */
b0d623f7
A
75#ifdef PRIVATE
76#include <net/route.h>
77#endif
91447636
A
78
79#ifdef KERNEL
80#include <net/kpi_interface.h>
b0d623f7 81#endif /* KERNEL */
1c79356b 82
9bccf70c 83#ifdef __APPLE__
1c79356b
A
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
316670eb 94#define APPLE_IF_FAM_FAITH 11 /* deprecated */
55e303ae
A
95#define APPLE_IF_FAM_STF 12
96#define APPLE_IF_FAM_FIREWIRE 13
91447636 97#define APPLE_IF_FAM_BOND 14
0c530ab8 98#endif /* __APPLE__ */
91447636
A
99
100/*
101 * 72 was chosen below because it is the size of a TCP/IP
102 * header (40) + the minimum mss (32).
103 */
104#define IF_MINMTU 72
105#define IF_MAXMTU 65535
1c79356b
A
106
107/*
108 * Structures defining a network interface, providing a packet
109 * transport mechanism (ala level 0 of the PUP protocols).
110 *
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.
114 *
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.
120 *
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.
125 *
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
130 */
131
1c79356b
A
132#define IFNAMSIZ 16
133
1c79356b
A
134/* This belongs up in socket.h or socketvar.h, depending on how far the
135 * event bubbles up.
136 */
137
138struct net_event_data {
2d21ac55
A
139 u_int32_t if_family;
140 u_int32_t if_unit;
141 char if_name[IFNAMSIZ];
1c79356b 142};
1c79356b 143
2d21ac55 144#if defined(__LP64__)
39236c6e 145#include <sys/_types/_timeval32.h>
2d21ac55
A
146#define IF_DATA_TIMEVAL timeval32
147#else
148#define IF_DATA_TIMEVAL timeval
149#endif
150
151#pragma pack(4)
152
91447636
A
153/*
154 * Structure describing information about an interface
155 * which may be of interest to management entities.
156 */
157struct if_data {
158 /* generic interface information */
2d21ac55
A
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 */
91447636 170 /* volatile statistics */
2d21ac55
A
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 */
91447636 189};
4a249263 190
1c79356b
A
191/*
192 * Structure describing information about an interface
193 * which may be of interest to management entities.
194 */
91447636 195struct if_data64 {
1c79356b 196 /* generic interface information */
2d21ac55
A
197 u_char ifi_type; /* ethernet, tokenring, etc */
198 u_char ifi_typelen; /* Length of frame type id */
91447636
A
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 */
2d21ac55
A
205 u_int32_t ifi_mtu; /* maximum transmission unit */
206 u_int32_t ifi_metric; /* routing metric (external only) */
91447636
A
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 */
2d21ac55
A
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 */
91447636
A
223};
224
225#ifdef PRIVATE
d41d1dae 226struct if_traffic_class {
316670eb
A
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 */
d41d1dae
A
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 */
316670eb
A
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 */
247};
248
249struct if_data_extended {
250 u_int64_t ifi_alignerrs; /* unaligned (32-bit) input pkts */
39236c6e
A
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 */
316670eb
A
255};
256
257struct if_packet_stats {
258 /* TCP */
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;
39236c6e 273 u_int64_t reserved[6];
316670eb
A
274 /* UDP */
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;
39236c6e 283 u_int64_t _reserved[4];
316670eb
A
284};
285
286struct 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 */
290};
291
292struct if_bandwidths {
293 u_int64_t eff_bw; /* effective bandwidth */
294 u_int64_t max_bw; /* maximum theoretical bandwidth */
295};
296
39236c6e
A
297struct if_latencies {
298 u_int64_t eff_lt; /* effective latency */
299 u_int64_t max_lt; /* maximum theoretical latency */
300};
301
316670eb
A
302struct 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 */
307
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 */
311
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 */
318
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 */
39236c6e
A
325
326 u_int32_t ifi_poll_packets_limit; /* max packets per poll call */
327 u_int64_t ifi_poll_interval_time; /* poll interval (nsec) */
d41d1dae 328};
3e170ce0 329
4bd07ac2 330struct if_tcp_ecn_perf_stat {
490019cf
A
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;
4bd07ac2
A
336 u_int64_t rtt_avg;
337 u_int64_t rtt_var;
4bd07ac2 338 u_int64_t sack_episodes;
490019cf
A
339 u_int64_t rxmit_drop;
340 u_int64_t rst_drop;
341 u_int64_t oo_percent;
4bd07ac2
A
342 u_int64_t reorder_percent;
343 u_int64_t rxmit_percent;
4bd07ac2
A
344};
345
346struct if_tcp_ecn_stat {
347 u_int64_t timestamp;
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;
490019cf
A
365 u_int64_t ecn_off_conn;
366 u_int64_t ecn_total_conn;
39037602
A
367 u_int64_t ecn_fallback_droprst;
368 u_int64_t ecn_fallback_droprxmt;
4bd07ac2
A
369 struct if_tcp_ecn_perf_stat ecn_on;
370 struct if_tcp_ecn_perf_stat ecn_off;
371};
372
3e170ce0
A
373/*
374 * Interface link status report -- includes statistics related to
375 * the link layer technology sent by the driver. The driver will monitor
376 * these statistics over an interval (3-4 secs) and will generate a report
377 * to the network stack. This will give first-hand information about the
378 * status of the first hop of the network path. The version and
379 * length values should be correct for the data to be processed correctly.
380 * The definitions are different for different kind of interfaces like
381 * Wifi, Cellular etc,.
382 */
383#define IF_CELLULAR_STATUS_REPORT_VERSION_1 1
384#define IF_WIFI_STATUS_REPORT_VERSION_1 1
385#define IF_CELLULAR_STATUS_REPORT_CURRENT_VERSION \
386 IF_CELLULAR_STATUS_REPORT_VERSION_1
387#define IF_WIFI_STATUS_REPORT_CURRENT_VERSION IF_WIFI_STATUS_REPORT_VERSION_1
388/*
389 * For cellular interface --
390 * There is no way to share common headers between the Baseband and
391 * the kernel. Any changes to this structure will need to be communicated
392 * to the Baseband team. It is better to use reserved space instead of
393 * changing the size or existing fields in the structure.
394 */
395struct if_cellular_status_v1 {
396 u_int32_t valid_bitmask; /* indicates which fields are valid */
397#define IF_CELL_LINK_QUALITY_METRIC_VALID 0x1
398#define IF_CELL_UL_EFFECTIVE_BANDWIDTH_VALID 0x2
399#define IF_CELL_UL_MAX_BANDWIDTH_VALID 0x4
400#define IF_CELL_UL_MIN_LATENCY_VALID 0x8
401#define IF_CELL_UL_EFFECTIVE_LATENCY_VALID 0x10
402#define IF_CELL_UL_MAX_LATENCY_VALID 0x20
403#define IF_CELL_UL_RETXT_LEVEL_VALID 0x40
404#define IF_CELL_UL_BYTES_LOST_VALID 0x80
405#define IF_CELL_UL_MIN_QUEUE_SIZE_VALID 0x100
406#define IF_CELL_UL_AVG_QUEUE_SIZE_VALID 0x200
407#define IF_CELL_UL_MAX_QUEUE_SIZE_VALID 0x400
408#define IF_CELL_DL_EFFECTIVE_BANDWIDTH_VALID 0x800
409#define IF_CELL_DL_MAX_BANDWIDTH_VALID 0x1000
410#define IF_CELL_CONFIG_INACTIVITY_TIME_VALID 0x2000
411#define IF_CELL_CONFIG_BACKOFF_TIME_VALID 0x4000
39037602
A
412#define IF_CELL_UL_MSS_RECOMMENDED_VALID 0x8000
413
3e170ce0
A
414 u_int32_t link_quality_metric;
415 u_int32_t ul_effective_bandwidth; /* Measured uplink bandwidth based on current activity (bps) */
416 u_int32_t ul_max_bandwidth; /* Maximum supported uplink bandwidth (bps) */
417 u_int32_t ul_min_latency; /* min expected uplink latency for first hop (ms) */
418 u_int32_t ul_effective_latency; /* current expected uplink latency for first hop (ms) */
419 u_int32_t ul_max_latency; /* max expected uplink latency first hop (ms) */
420 u_int32_t ul_retxt_level; /* Retransmission metric */
421#define IF_CELL_UL_RETXT_LEVEL_NONE 1
422#define IF_CELL_UL_RETXT_LEVEL_LOW 2
423#define IF_CELL_UL_RETXT_LEVEL_MEDIUM 3
424#define IF_CELL_UL_RETXT_LEVEL_HIGH 4
425 u_int32_t ul_bytes_lost; /* % of total bytes lost on uplink in Q10 format */
426 u_int32_t ul_min_queue_size; /* minimum bytes in queue */
427 u_int32_t ul_avg_queue_size; /* average bytes in queue */
428 u_int32_t ul_max_queue_size; /* maximum bytes in queue */
429 u_int32_t dl_effective_bandwidth; /* Measured downlink bandwidth based on current activity (bps) */
430 u_int32_t dl_max_bandwidth; /* Maximum supported downlink bandwidth (bps) */
431 u_int32_t config_inactivity_time; /* ms */
432 u_int32_t config_backoff_time; /* new connections backoff time in ms */
39037602
A
433#define IF_CELL_UL_MSS_RECOMMENDED_NONE 0x0 /* Use default */
434#define IF_CELL_UL_MSS_RECOMMENDED_MEDIUM 0x1 /* 1200 byte MSS */
435#define IF_CELL_UL_MSS_RECOMMENDED_LOW 0x2 /* 512 byte MSS */
436 u_int16_t mss_recommended;
437 u_int16_t reserved_1;
438 u_int32_t reserved_2;
3e170ce0
A
439 u_int64_t reserved_3;
440 u_int64_t reserved_4;
441 u_int64_t reserved_5;
39037602 442 u_int64_t reserved_6;
3e170ce0
A
443} __attribute__((packed));
444
445struct if_cellular_status {
446 union {
447 struct if_cellular_status_v1 if_status_v1;
448 } if_cell_u;
449};
450
451/*
452 * These statistics will be provided by the Wifi driver periodically.
453 * After sending each report, the driver should start computing again
454 * for the next report duration so that the values represent the link
455 * status for one report duration.
456 */
457
458struct if_wifi_status_v1 {
459 u_int32_t valid_bitmask;
460#define IF_WIFI_LINK_QUALITY_METRIC_VALID 0x1
461#define IF_WIFI_UL_EFFECTIVE_BANDWIDTH_VALID 0x2
462#define IF_WIFI_UL_MAX_BANDWIDTH_VALID 0x4
463#define IF_WIFI_UL_MIN_LATENCY_VALID 0x8
464#define IF_WIFI_UL_EFFECTIVE_LATENCY_VALID 0x10
465#define IF_WIFI_UL_MAX_LATENCY_VALID 0x20
466#define IF_WIFI_UL_RETXT_LEVEL_VALID 0x40
467#define IF_WIFI_UL_ERROR_RATE_VALID 0x80
468#define IF_WIFI_UL_BYTES_LOST_VALID 0x100
469#define IF_WIFI_DL_EFFECTIVE_BANDWIDTH_VALID 0x200
470#define IF_WIFI_DL_MAX_BANDWIDTH_VALID 0x400
471#define IF_WIFI_DL_MIN_LATENCY_VALID 0x800
472#define IF_WIFI_DL_EFFECTIVE_LATENCY_VALID 0x1000
473#define IF_WIFI_DL_MAX_LATENCY_VALID 0x2000
474#define IF_WIFI_DL_ERROR_RATE_VALID 0x4000
475#define IF_WIFI_CONFIG_FREQUENCY_VALID 0x8000
476#define IF_WIFI_CONFIG_MULTICAST_RATE_VALID 0x10000
477#define IF_WIFI_CONFIG_SCAN_COUNT_VALID 0x20000
478#define IF_WIFI_CONFIG_SCAN_DURATION_VALID 0x40000
479 u_int32_t link_quality_metric; /* link quality metric */
480 u_int32_t ul_effective_bandwidth; /* Measured uplink bandwidth based on current activity (bps) */
481 u_int32_t ul_max_bandwidth; /* Maximum supported uplink bandwidth (bps) */
482 u_int32_t ul_min_latency; /* min expected uplink latency for first hop (ms) */
483 u_int32_t ul_effective_latency; /* current expected uplink latency for first hop (ms) */
484 u_int32_t ul_max_latency; /* max expected uplink latency for first hop (ms) */
485 u_int32_t ul_retxt_level; /* Retransmission metric */
486#define IF_WIFI_UL_RETXT_LEVEL_NONE 1
487#define IF_WIFI_UL_RETXT_LEVEL_LOW 2
488#define IF_WIFI_UL_RETXT_LEVEL_MEDIUM 3
489#define IF_WIFI_UL_RETXT_LEVEL_HIGH 4
490 u_int32_t ul_bytes_lost; /* % of total bytes lost on uplink in Q10 format */
491 u_int32_t ul_error_rate; /* % of bytes dropped on uplink after many retransmissions in Q10 format */
492 u_int32_t dl_effective_bandwidth; /* Measured downlink bandwidth based on current activity (bps) */
493 u_int32_t dl_max_bandwidth; /* Maximum supported downlink bandwidth (bps) */
494 /*
495 * The download latency values indicate the time AP may have to wait for the
496 * driver to receive the packet. These values give the range of expected latency
497 * mainly due to co-existence events and channel hopping where the interface
498 * becomes unavailable.
499 */
500 u_int32_t dl_min_latency; /* min expected latency for first hop in ms */
501 u_int32_t dl_effective_latency; /* current expected latency for first hop in ms */
502 u_int32_t dl_max_latency; /* max expected latency for first hop in ms */
503 u_int32_t dl_error_rate; /* % of CRC or other errors in Q10 format */
504 u_int32_t config_frequency; /* 2.4 or 5 GHz */
505#define IF_WIFI_CONFIG_FREQUENCY_2_4_GHZ 1
506#define IF_WIFI_CONFIG_FREQUENCY_5_0_GHZ 2
507 u_int32_t config_multicast_rate; /* bps */
508 u_int32_t scan_count; /* scan count during the previous period */
509 u_int32_t scan_duration; /* scan duration in ms */
510 u_int64_t reserved_1;
511 u_int64_t reserved_2;
512 u_int64_t reserved_3;
513 u_int64_t reserved_4;
514} __attribute__((packed));
515
516struct if_wifi_status {
517 union {
518 struct if_wifi_status_v1 if_status_v1;
519 } if_wifi_u;
520};
521
522struct if_link_status {
523 u_int32_t ifsr_version; /* version of this report */
524 u_int32_t ifsr_len; /* length of the following struct */
525 union {
526 struct if_cellular_status ifsr_cell;
527 struct if_wifi_status ifsr_wifi;
528 } ifsr_u;
529};
530
531struct if_interface_state {
532 /*
533 * The bitmask tells which of the fields
534 * to consider:
535 * - When setting, to control which fields
536 * are being modified;
537 * - When getting, it tells which fields are set.
538 */
539 u_int8_t valid_bitmask;
540#define IF_INTERFACE_STATE_RRC_STATE_VALID 0x1
541#define IF_INTERFACE_STATE_LQM_STATE_VALID 0x2
542#define IF_INTERFACE_STATE_INTERFACE_AVAILABILITY_VALID 0x4
543
544 /*
545 * Valid only for cellular interface
546 */
547 u_int8_t rrc_state;
548#define IF_INTERFACE_STATE_RRC_STATE_IDLE 0x0
549#define IF_INTERFACE_STATE_RRC_STATE_CONNECTED 0x1
550
551 /*
552 * Values normalized to the edge of the following values
553 * that are defined on <net/if.h>:
554 * IFNET_LQM_THRESH_BAD
555 * IFNET_LQM_THRESH_POOR
556 * IFNET_LQM_THRESH_GOOD
557 */
558 int8_t lqm_state;
559
560 /*
561 * Indicate if the underlying link is currently
39037602 562 * available
3e170ce0
A
563 */
564 u_int8_t interface_availability;
565#define IF_INTERFACE_STATE_INTERFACE_AVAILABLE 0x0
566#define IF_INTERFACE_STATE_INTERFACE_UNAVAILABLE 0x1
567};
568
569struct chain_len_stats {
570 uint64_t cls_one;
571 uint64_t cls_two;
572 uint64_t cls_three;
573 uint64_t cls_four;
574 uint64_t cls_five_or_more;
575};
576
6d2010ae
A
577#endif /* PRIVATE */
578
579#pragma pack()
d41d1dae 580
6d2010ae
A
581/*
582 * Structure defining a queue for a network interface.
583 */
584struct ifqueue {
585 void *ifq_head;
586 void *ifq_tail;
587 int ifq_len;
588 int ifq_maxlen;
589 int ifq_drops;
590};
591
316670eb 592#ifdef BSD_KERNEL_PRIVATE
91447636
A
593/*
594 * Internal storage of if_data. This is bound to change. Various places in the
595 * stack will translate this data structure in to the externally visible
6d2010ae
A
596 * if_data structure above. Note that during interface attach time, the
597 * embedded if_data structure in ifnet is cleared, with the exception of
598 * some non-statistics related fields.
91447636
A
599 */
600struct if_data_internal {
601 /* generic interface information */
2d21ac55
A
602 u_char ifi_type; /* ethernet, tokenring, etc */
603 u_char ifi_typelen; /* Length of frame type id */
604 u_char ifi_physical; /* e.g., AUI, Thinnet, 10base-T, etc */
605 u_char ifi_addrlen; /* media address length */
606 u_char ifi_hdrlen; /* media header length */
607 u_char ifi_recvquota; /* polling quota for receive intrs */
608 u_char ifi_xmitquota; /* polling quota for xmit intrs */
609 u_char ifi_unused1; /* for future use */
610 u_int32_t ifi_mtu; /* maximum transmission unit */
611 u_int32_t ifi_metric; /* routing metric (external only) */
612 u_int32_t ifi_baudrate; /* linespeed */
3e170ce0 613 u_int32_t ifi_preamblelen;/* length of the packet preamble */
1c79356b 614 /* volatile statistics */
91447636
A
615 u_int64_t ifi_ipackets; /* packets received on interface */
616 u_int64_t ifi_ierrors; /* input errors on interface */
617 u_int64_t ifi_opackets; /* packets sent on interface */
618 u_int64_t ifi_oerrors; /* output errors on interface */
619 u_int64_t ifi_collisions; /* collisions on csma interfaces */
2d21ac55
A
620 u_int64_t ifi_ibytes; /* total number of octets received */
621 u_int64_t ifi_obytes; /* total number of octets sent */
91447636
A
622 u_int64_t ifi_imcasts; /* packets received via multicast */
623 u_int64_t ifi_omcasts; /* packets sent via multicast */
624 u_int64_t ifi_iqdrops; /* dropped on input, this interface */
625 u_int64_t ifi_noproto; /* destined for unsupported protocol */
2d21ac55
A
626 u_int32_t ifi_recvtiming; /* usec spent receiving when timing */
627 u_int32_t ifi_xmittiming; /* usec spent xmitting when timing */
316670eb 628 u_int64_t ifi_alignerrs; /* unaligned (32-bit) input pkts */
39236c6e
A
629 u_int64_t ifi_dt_bytes; /* Data threshold counter */
630 u_int64_t ifi_fpackets; /* forwarded packets on interface */
631 u_int64_t ifi_fbytes; /* forwarded bytes on interface */
1c79356b 632 struct timeval ifi_lastchange; /* time of last administrative change */
2d21ac55 633 u_int32_t ifi_hwassist; /* HW offload capabilities */
b0d623f7
A
634 u_int32_t ifi_tso_v4_mtu; /* TCP Segment Offload IPv4 maximum segment size */
635 u_int32_t ifi_tso_v6_mtu; /* TCP Segment Offload IPv6 maximum segment size */
1c79356b 636};
316670eb 637
39236c6e 638#if MEASURE_BW
316670eb
A
639/*
640 * Fields per interface to measure perceived bandwidth.
641 */
316670eb
A
642struct if_measured_bw {
643 u_int64_t bw; /* measured bandwidth in bytes per ms */
644 u_int64_t bytes; /* XXX not needed */
645 u_int64_t ts; /* XXX not needed */
646 u_int64_t cur_seq __attribute((aligned(8))); /* current sequence for marking a packet */
647 u_int64_t start_ts; /* time at which a measurement started */
648 u_int64_t start_seq; /* sequence at which a measurement should start */
649 u_int64_t last_seq; /* last recorded seq */
650 u_int64_t last_ts; /* last recorded ts */
651 u_int32_t flags __attribute__((aligned(4))); /* flags */
652#define IF_MEASURED_BW_INPROGRESS 0x1
653#define IF_MEASURED_BW_CALCULATION 0x2
654};
39236c6e 655#endif /* MEASURE_BW */
316670eb 656#endif /* BSD_KERNEL_PRIVATE */
91447636 657
6d2010ae 658#ifdef PRIVATE
91447636
A
659#define if_mtu if_data.ifi_mtu
660#define if_type if_data.ifi_type
661#define if_typelen if_data.ifi_typelen
662#define if_physical if_data.ifi_physical
663#define if_addrlen if_data.ifi_addrlen
664#define if_hdrlen if_data.ifi_hdrlen
3e170ce0 665#define if_preamblelen if_data.ifi_preamblelen
91447636
A
666#define if_metric if_data.ifi_metric
667#define if_baudrate if_data.ifi_baudrate
668#define if_hwassist if_data.ifi_hwassist
669#define if_ipackets if_data.ifi_ipackets
670#define if_ierrors if_data.ifi_ierrors
671#define if_opackets if_data.ifi_opackets
672#define if_oerrors if_data.ifi_oerrors
673#define if_collisions if_data.ifi_collisions
674#define if_ibytes if_data.ifi_ibytes
675#define if_obytes if_data.ifi_obytes
676#define if_imcasts if_data.ifi_imcasts
677#define if_omcasts if_data.ifi_omcasts
678#define if_iqdrops if_data.ifi_iqdrops
679#define if_noproto if_data.ifi_noproto
680#define if_lastchange if_data.ifi_lastchange
681#define if_recvquota if_data.ifi_recvquota
682#define if_xmitquota if_data.ifi_xmitquota
6d2010ae 683#endif /* PRIVATE */
316670eb 684#ifdef BSD_KERNEL_PRIVATE
b0d623f7
A
685#define if_tso_v4_mtu if_data.ifi_tso_v4_mtu
686#define if_tso_v6_mtu if_data.ifi_tso_v6_mtu
316670eb 687#define if_alignerrs if_data.ifi_alignerrs
39236c6e
A
688#define if_dt_bytes if_data.ifi_dt_bytes
689#define if_fpackets if_data.ifi_fpackets
690#define if_fbytes if_data.ifi_fbytes
316670eb 691#endif /* BSD_KERNEL_PRIVATE */
91447636 692
316670eb 693#ifdef BSD_KERNEL_PRIVATE
91447636
A
694/*
695 * Forward structure declarations for function prototypes [sic].
696 */
6d2010ae
A
697struct proc;
698struct rtentry;
699struct socket;
91447636 700struct ifnet_filter;
6d2010ae
A
701struct mbuf;
702struct ifaddr;
703struct tqdummy;
704struct proto_hash_entry;
705struct dlil_threading_info;
316670eb
A
706struct tcpstat_local;
707struct udpstat_local;
6d2010ae
A
708#if PF
709struct pfi_kif;
710#endif /* PF */
91447636 711
6d2010ae
A
712/* we use TAILQs so that the order of instantiation is preserved in the list */
713TAILQ_HEAD(ifnethead, ifnet);
714TAILQ_HEAD(ifaddrhead, ifaddr);
6d2010ae
A
715LIST_HEAD(ifmultihead, ifmultiaddr);
716TAILQ_HEAD(tailq_head, tqdummy);
91447636
A
717TAILQ_HEAD(ifnet_filter_head, ifnet_filter);
718TAILQ_HEAD(ddesc_head_name, dlil_demux_desc);
316670eb 719#endif /* BSD_KERNEL_PRIVATE */
91447636 720
6d2010ae
A
721#ifdef PRIVATE
722/*
723 * All of the following IF_HWASSIST_* flags are defined in kpi_inteface.h as
724 * IFNET_* flags. These are redefined here as constants to avoid failures to
725 * build user level programs that can not include kpi_interface.h. It is
726 * important to keep this in sync with the definitions in kpi_interface.h.
727 * The corresponding constant for each definition is mentioned in the comment.
b0d623f7 728 *
6d2010ae 729 * Bottom 16 bits reserved for hardware checksum
b0d623f7
A
730 */
731#define IF_HWASSIST_CSUM_IP 0x0001 /* will csum IP, IFNET_CSUM_IP */
732#define IF_HWASSIST_CSUM_TCP 0x0002 /* will csum TCP, IFNET_CSUM_TCP */
733#define IF_HWASSIST_CSUM_UDP 0x0004 /* will csum UDP, IFNET_CSUM_UDP */
734#define IF_HWASSIST_CSUM_IP_FRAGS 0x0008 /* will csum IP fragments, IFNET_CSUM_FRAGMENT */
735#define IF_HWASSIST_CSUM_FRAGMENT 0x0010 /* will do IP fragmentation, IFNET_IP_FRAGMENT */
6d2010ae
A
736#define IF_HWASSIST_CSUM_TCPIPV6 0x0020 /* will csum TCPv6, IFNET_CSUM_TCPIPV6 */
737#define IF_HWASSIST_CSUM_UDPIPV6 0x0040 /* will csum UDPv6, IFNET_CSUM_UDP */
738#define IF_HWASSIST_CSUM_FRAGMENT_IPV6 0x0080 /* will do IPv6 fragmentation, IFNET_IPV6_FRAGMENT */
39236c6e 739#define IF_HWASSIST_CSUM_PARTIAL 0x1000 /* simple Sum16 computation, IFNET_CSUM_PARTIAL */
91447636
A
740#define IF_HWASSIST_CSUM_MASK 0xffff
741#define IF_HWASSIST_CSUM_FLAGS(hwassist) ((hwassist) & IF_HWASSIST_CSUM_MASK)
742
743/* VLAN support */
b0d623f7
A
744#define IF_HWASSIST_VLAN_TAGGING 0x00010000 /* supports VLAN tagging, IFNET_VLAN_TAGGING */
745#define IF_HWASSIST_VLAN_MTU 0x00020000 /* supports VLAN MTU-sized packet (for software VLAN), IFNET_VLAN_MTU */
746
747/* TCP Segment Offloading support */
748
749#define IF_HWASSIST_TSO_V4 0x00200000 /* will do TCP Segment offload for IPv4, IFNET_TSO_IPV4 */
750#define IF_HWASSIST_TSO_V6 0x00400000 /* will do TCP Segment offload for IPv6, IFNET_TSO_IPV6 */
2d21ac55 751#endif /* PRIVATE */
1c79356b 752
39236c6e
A
753#ifdef PRIVATE
754#define IFXNAMSIZ (IFNAMSIZ + 8) /* external name (name + unit) */
755#endif
756
316670eb
A
757#ifdef BSD_KERNEL_PRIVATE
758/*
759 * ifnet is private to BSD portion of kernel
760 */
39236c6e 761#include <sys/mcache.h>
6d2010ae
A
762#include <sys/tree.h>
763#include <netinet/in.h>
39236c6e 764#include <net/if_dl.h>
316670eb 765#include <net/classq/if_classq.h>
39236c6e 766#include <net/if_types.h>
2d21ac55 767
6d2010ae 768RB_HEAD(ll_reach_tree, if_llreach); /* define struct ll_reach_tree */
91447636 769
39236c6e 770#define if_name(ifp) ifp->if_xname
1c79356b
A
771/*
772 * Structure defining a network interface.
773 *
774 * (Would like to call this struct ``if'', but C isn't PL/1.)
775 */
776struct ifnet {
6d2010ae
A
777 /*
778 * Lock (RW or mutex) to protect this data structure (static storage.)
779 */
780 decl_lck_rw_data(, if_lock);
781 void *if_softc; /* pointer to driver state */
782 const char *if_name; /* name, e.g. ``en'' or ``lo'' */
39236c6e 783 const char *if_xname; /* external name (name + unit) */
316670eb 784 struct if_description if_desc; /* extended description */
6d2010ae
A
785 TAILQ_ENTRY(ifnet) if_link; /* all struct ifnets are chained */
786 TAILQ_ENTRY(ifnet) if_detaching_link; /* list of detaching ifnets */
39037602 787 TAILQ_ENTRY(ifnet) if_ordered_link; /* list of ordered ifnets */
6d2010ae
A
788
789 decl_lck_mtx_data(, if_ref_lock)
39236c6e 790 u_int32_t if_refflags; /* see IFRF flags below */
6d2010ae
A
791 u_int32_t if_refio; /* number of io ops to the underlying driver */
792
793#define if_list if_link
794 struct ifaddrhead if_addrhead; /* linked list of addresses per if */
795#define if_addrlist if_addrhead
796 struct ifaddr *if_lladdr; /* link address (first/permanent) */
797
39037602
A
798 u_int32_t if_qosmarking_mode; /* generation to use with NECP clients */
799
6d2010ae
A
800 int if_pcount; /* number of promiscuous listeners */
801 struct bpf_if *if_bpf; /* packet filter structure */
802 u_short if_index; /* numeric abbreviation for this if */
803 short if_unit; /* sub-unit for lower level driver */
804 short if_timer; /* time 'til if_watchdog called */
805 short if_flags; /* up/down, broadcast, etc. */
806 u_int32_t if_eflags; /* see <net/if.h> */
39037602 807 u_int32_t if_xflags; /* see <net/if.h> */
6d2010ae
A
808
809 int if_capabilities; /* interface features & capabilities */
810 int if_capenable; /* enabled features & capabilities */
811
812 void *if_linkmib; /* link-type-specific MIB data */
813 size_t if_linkmiblen; /* length of above data */
814
815 struct if_data_internal if_data __attribute__((aligned(8)));
816
817 ifnet_family_t if_family; /* value assigned by Apple */
39236c6e 818 ifnet_subfamily_t if_subfamily; /* value assigned by Apple */
6d2010ae 819 uintptr_t if_family_cookie;
39037602 820 ifnet_output_handler_func if_output_handler;
91447636 821 ifnet_output_func if_output;
316670eb
A
822 ifnet_pre_enqueue_func if_pre_enqueue;
823 ifnet_start_func if_start;
824 ifnet_ctl_func if_output_ctl;
39037602 825 ifnet_input_handler_func if_input_handler;
316670eb
A
826 ifnet_input_poll_func if_input_poll;
827 ifnet_ctl_func if_input_ctl;
91447636
A
828 ifnet_ioctl_func if_ioctl;
829 ifnet_set_bpf_tap if_set_bpf_tap;
830 ifnet_detached_func if_free;
831 ifnet_demux_func if_demux;
832 ifnet_event_func if_event;
39236c6e
A
833 ifnet_framer_func if_framer_legacy;
834 ifnet_framer_extended_func if_framer;
6d2010ae
A
835 ifnet_add_proto_func if_add_proto;
836 ifnet_del_proto_func if_del_proto;
837 ifnet_check_multi if_check_multi;
838 struct proto_hash_entry *if_proto_hash;
839 void *if_kpi_storage;
1c79356b 840
39236c6e
A
841 u_int32_t if_flowhash; /* interface flow control ID */
842
316670eb 843 decl_lck_mtx_data(, if_start_lock);
39236c6e 844 u_int32_t if_start_flags; /* see IFSF flags below */
316670eb 845 u_int32_t if_start_req;
3e170ce0
A
846 u_int16_t if_start_active; /* output is active */
847 u_int16_t if_start_delayed;
848 u_int16_t if_start_delay_qlen;
849 u_int16_t if_start_delay_idle;
850 u_int64_t if_start_delay_swin;
851 u_int32_t if_start_delay_cnt;
852 u_int32_t if_start_delay_timeout; /* nanoseconds */
316670eb
A
853 struct timespec if_start_cycle; /* restart interval */
854 struct thread *if_start_thread;
855
856 struct ifclassq if_snd; /* transmit queue */
857 u_int32_t if_output_sched_model; /* tx sched model */
858
859 struct if_bandwidths if_output_bw;
860 struct if_bandwidths if_input_bw;
861
39236c6e
A
862 struct if_latencies if_output_lt;
863 struct if_latencies if_input_lt;
864
6d2010ae
A
865 decl_lck_mtx_data(, if_flt_lock)
866 u_int32_t if_flt_busy;
867 u_int32_t if_flt_waiters;
91447636 868 struct ifnet_filter_head if_flt_head;
1c79356b 869
6d2010ae
A
870 struct ifmultihead if_multiaddrs; /* multicast addresses */
871 u_int32_t if_updatemcasts; /* mcast addrs need updating */
872 int if_amcount; /* # of all-multicast reqs */
873 decl_lck_mtx_data(, if_addrconfig_lock); /* for serializing addr config */
874 struct in_multi *if_allhostsinm; /* store all-hosts inm for this ifp */
1c79356b 875
316670eb
A
876 decl_lck_mtx_data(, if_poll_lock);
877 u_int16_t if_poll_req;
878 u_int16_t if_poll_update; /* link update */
879 u_int32_t if_poll_active; /* polling is active */
880 struct timespec if_poll_cycle; /* poll interval */
881 struct thread *if_poll_thread;
91447636 882
316670eb 883 struct dlil_threading_info *if_inp;
91447636 884
91447636 885 struct {
b0d623f7 886 u_int32_t length;
91447636
A
887 union {
888 u_char buffer[8];
889 u_char *ptr;
890 } u;
891 } if_broadcast;
2d21ac55 892#if CONFIG_MACF_NET
6d2010ae 893 struct label *if_label; /* interface MAC label */
2d21ac55 894#endif
b0d623f7 895
b0d623f7 896#if PF
6d2010ae 897 struct pfi_kif *if_pf_kif;
b0d623f7 898#endif /* PF */
1c79356b 899
6d2010ae
A
900 decl_lck_mtx_data(, if_cached_route_lock);
901 u_int32_t if_fwd_cacheok;
902 struct route if_fwd_route; /* cached forwarding route */
903 struct route if_src_route; /* cached ipv4 source route */
904 struct route_in6 if_src_route6; /* cached ipv6 source route */
91447636 905
6d2010ae
A
906 decl_lck_rw_data(, if_llreach_lock);
907 struct ll_reach_tree if_ll_srcs; /* source link-layer tree */
91447636 908
6d2010ae
A
909 void *if_bridge; /* bridge glue */
910
911 u_int32_t if_want_aggressive_drain;
912 u_int32_t if_idle_flags; /* idle flags */
913 u_int32_t if_idle_new_flags; /* temporary idle flags */
914 u_int32_t if_idle_new_flags_mask; /* temporary mask */
915 u_int32_t if_route_refcnt; /* idle: route ref count */
39037602 916 u_int32_t if_rt_sendts; /* last of a real time packet */
6d2010ae
A
917
918 struct if_traffic_class if_tc __attribute__((aligned(8)));
919#if INET
920 struct igmp_ifinfo *if_igi; /* for IGMPv3 */
921#endif /* INET */
922#if INET6
923 struct mld_ifinfo *if_mli; /* for MLDv2 */
924#endif /* INET6 */
316670eb 925
39236c6e 926#if MEASURE_BW
316670eb 927 struct if_measured_bw if_bw;
39236c6e 928#endif /* MEASURE_BW */
316670eb
A
929 struct tcpstat_local *if_tcp_stat; /* TCP specific stats */
930 struct udpstat_local *if_udp_stat; /* UDP specific stats */
39236c6e
A
931
932 struct {
933 int32_t level; /* cached logging level */
934 u_int32_t flags; /* cached logging flags */
935 int32_t category; /* cached category */
936 int32_t subcategory; /* cached subcategory */
937 } if_log;
938
939 struct {
940 struct ifnet *ifp; /* delegated ifp */
941 u_int32_t type; /* delegated i/f type */
942 u_int32_t family; /* delegated i/f family */
943 u_int32_t subfamily; /* delegated i/f sub-family */
fe8ab488 944 uint32_t expensive:1; /* delegated i/f expensive? */
39236c6e
A
945 } if_delegated;
946
39037602
A
947 uuid_t *if_agentids; /* network agents attached to interface */
948 u_int32_t if_agentcount;
3e170ce0 949
39037602 950 u_int32_t if_generation; /* generation to use with NECP clients */
39236c6e 951 u_int32_t if_fg_sendts; /* last send on a fg socket in seconds */
39037602
A
952
953 u_int64_t if_data_threshold;
954
955 /* Total bytes in send socket buffer */
956 int64_t if_sndbyte_total __attribute__ ((aligned(8)));
957 /* Total unsent bytes in send socket buffer */
958 int64_t if_sndbyte_unsent __attribute__ ((aligned(8)));
959 /* count of times, when there was data to send when sleep is impending */
960 uint32_t if_unsent_data_cnt;
39236c6e 961
3e170ce0
A
962#if INET
963 decl_lck_rw_data(, if_inetdata_lock);
964 void *if_inetdata;
965#endif /* INET */
39236c6e
A
966#if INET6
967 decl_lck_rw_data(, if_inet6data_lock);
968 void *if_inet6data;
969#endif
3e170ce0
A
970 decl_lck_rw_data(, if_link_status_lock);
971 struct if_link_status *if_link_status;
972 struct if_interface_state if_interface_state;
4bd07ac2
A
973 struct if_tcp_ecn_stat *if_ipv4_stat;
974 struct if_tcp_ecn_stat *if_ipv6_stat;
6d2010ae
A
975};
976
39236c6e
A
977#define IF_TCP_STATINC(_ifp, _s) do { \
978 if ((_ifp)->if_tcp_stat != NULL) \
979 atomic_add_64(&(_ifp)->if_tcp_stat->_s, 1); \
980} while (0);
981
982#define IF_UDP_STATINC(_ifp, _s) do { \
983 if ((_ifp)->if_udp_stat != NULL) \
984 atomic_add_64(&(_ifp)->if_udp_stat->_s, 1); \
985} while (0);
986
6d2010ae 987/*
39236c6e 988 * Valid values for if_refflags
6d2010ae
A
989 */
990#define IFRF_ATTACHED 0x1 /* ifnet attach is completely done */
991#define IFRF_DETACHING 0x2 /* detach has been requested */
91447636 992
39236c6e
A
993/*
994 * Valid values for if_start_flags
995 */
996#define IFSF_FLOW_CONTROLLED 0x1 /* flow controlled */
997
4a249263
A
998/*
999 * Structure describing a `cloning' interface.
1000 */
1001struct if_clone {
1002 LIST_ENTRY(if_clone) ifc_list; /* on list of cloners */
6d2010ae
A
1003 const char *ifc_name; /* name of device, e.g. `vlan' */
1004 size_t ifc_namelen; /* length of name */
1005 u_int32_t ifc_minifs; /* minimum number of interfaces */
1006 u_int32_t ifc_maxunit; /* maximum unit number */
1007 unsigned char *ifc_units; /* bitmap to handle units */
1008 u_int32_t ifc_bmlen; /* bitmap length */
1009
1010 int (*ifc_create)(struct if_clone *, u_int32_t, void *);
1011 int (*ifc_destroy)(struct ifnet *);
4a249263
A
1012};
1013
6d2010ae
A
1014#define IF_CLONE_INITIALIZER(name, create, destroy, minifs, maxunit) { \
1015 { NULL, NULL }, name, (sizeof (name) - 1), minifs, maxunit, NULL, 0, \
1016 create, destroy \
1017}
9bccf70c 1018
d1ecb069
A
1019#define M_CLONE M_IFADDR
1020
1c79356b 1021/*
6d2010ae
A
1022 * Macros to manipulate ifqueue. Users of these macros are responsible
1023 * for serialization, by holding whatever lock is appropriate for the
1024 * corresponding structure that is referring the ifqueue.
1c79356b
A
1025 */
1026#define IF_QFULL(ifq) ((ifq)->ifq_len >= (ifq)->ifq_maxlen)
1027#define IF_DROP(ifq) ((ifq)->ifq_drops++)
316670eb
A
1028
1029#define IF_ENQUEUE(ifq, m) do { \
6d2010ae
A
1030 (m)->m_nextpkt = NULL; \
1031 if ((ifq)->ifq_tail == NULL) \
1032 (ifq)->ifq_head = m; \
1033 else \
1034 ((struct mbuf*)(ifq)->ifq_tail)->m_nextpkt = m; \
1035 (ifq)->ifq_tail = m; \
1036 (ifq)->ifq_len++; \
316670eb
A
1037} while (0)
1038
1039#define IF_PREPEND(ifq, m) do { \
6d2010ae
A
1040 (m)->m_nextpkt = (ifq)->ifq_head; \
1041 if ((ifq)->ifq_tail == NULL) \
1042 (ifq)->ifq_tail = (m); \
1043 (ifq)->ifq_head = (m); \
1044 (ifq)->ifq_len++; \
316670eb
A
1045} while (0)
1046
1047#define IF_DEQUEUE(ifq, m) do { \
6d2010ae
A
1048 (m) = (ifq)->ifq_head; \
1049 if (m != NULL) { \
1050 if (((ifq)->ifq_head = (m)->m_nextpkt) == NULL) \
1051 (ifq)->ifq_tail = NULL; \
1052 (m)->m_nextpkt = NULL; \
1053 (ifq)->ifq_len--; \
1054 } \
316670eb
A
1055} while (0)
1056
1057#define IF_REMQUEUE(ifq, m) do { \
6d2010ae
A
1058 struct mbuf *_p = (ifq)->ifq_head; \
1059 struct mbuf *_n = (m)->m_nextpkt; \
1060 if ((m) == _p) \
1061 _p = NULL; \
1062 while (_p != NULL) { \
1063 if (_p->m_nextpkt == (m)) \
1064 break; \
1065 _p = _p->m_nextpkt; \
1066 } \
1067 VERIFY(_p != NULL || ((m) == (ifq)->ifq_head)); \
1068 if ((m) == (ifq)->ifq_head) \
1069 (ifq)->ifq_head = _n; \
1070 if ((m) == (ifq)->ifq_tail) \
1071 (ifq)->ifq_tail = _p; \
1072 VERIFY((ifq)->ifq_tail != NULL || (ifq)->ifq_head == NULL); \
1073 VERIFY((ifq)->ifq_len != 0); \
1074 --(ifq)->ifq_len; \
1075 if (_p != NULL) \
1076 _p->m_nextpkt = _n; \
1077 (m)->m_nextpkt = NULL; \
316670eb
A
1078} while (0)
1079
6d2010ae 1080#define IF_DRAIN(ifq) do { \
316670eb 1081 struct mbuf *_m; \
6d2010ae 1082 for (;;) { \
316670eb
A
1083 IF_DEQUEUE(ifq, _m); \
1084 if (_m == NULL) \
6d2010ae 1085 break; \
316670eb 1086 m_freem(_m); \
6d2010ae
A
1087 } \
1088} while (0)
1c79356b 1089
1c79356b
A
1090/*
1091 * The ifaddr structure contains information about one address
1092 * of an interface. They are maintained by the different address families,
1093 * are allocated and attached when an address is set, and are linked
1094 * together so all addresses for an interface can be located.
1095 */
1096struct ifaddr {
6d2010ae
A
1097 decl_lck_mtx_data(, ifa_lock); /* lock for ifaddr */
1098 uint32_t ifa_refcnt; /* ref count, use IFA_{ADD,REM}REF */
1099 uint32_t ifa_debug; /* debug flags */
1100 struct sockaddr *ifa_addr; /* address of interface */
1101 struct sockaddr *ifa_dstaddr; /* other end of p-to-p link */
1c79356b 1102#define ifa_broadaddr ifa_dstaddr /* broadcast address interface */
6d2010ae
A
1103 struct sockaddr *ifa_netmask; /* used to determine subnet */
1104 struct ifnet *ifa_ifp; /* back-pointer to interface */
1c79356b 1105 TAILQ_ENTRY(ifaddr) ifa_link; /* queue macro glue */
b0d623f7
A
1106 void (*ifa_rtrequest) /* check or clean routes (+ or -)'d */
1107 (int, struct rtentry *, struct sockaddr *);
6d2010ae
A
1108 uint32_t ifa_flags; /* mostly rt_flags for cloning */
1109 int32_t ifa_metric; /* cost of going out this interface */
b0d623f7
A
1110 void (*ifa_free)(struct ifaddr *); /* callback fn for freeing */
1111 void (*ifa_trace) /* callback fn for tracing refs */
1112 (struct ifaddr *, int);
6d2010ae
A
1113 void (*ifa_attached)(struct ifaddr *); /* callback fn for attaching */
1114 void (*ifa_detached)(struct ifaddr *); /* callback fn for detaching */
1c79356b 1115};
b0d623f7 1116
3e170ce0 1117
b0d623f7
A
1118/*
1119 * Valid values for ifa_flags
1120 */
91447636
A
1121#define IFA_ROUTE RTF_UP /* route installed (0x1) */
1122#define IFA_CLONING RTF_CLONING /* (0x100) */
b0d623f7
A
1123
1124/*
1125 * Valid values for ifa_debug
1126 */
6d2010ae 1127#define IFD_ATTACHED 0x1 /* attached to list */
b0d623f7
A
1128#define IFD_ALLOC 0x2 /* dynamically allocated */
1129#define IFD_DEBUG 0x4 /* has debugging info */
6d2010ae
A
1130#define IFD_LINK 0x8 /* link address */
1131#define IFD_TRASHED 0x10 /* in trash list */
813fb2f6 1132#define IFD_DETACHING 0x20 /* detach is in progress */
6d2010ae 1133#define IFD_NOTREADY 0x40 /* embryonic; not yet ready */
91447636 1134
6d2010ae
A
1135#define IFA_LOCK_ASSERT_HELD(_ifa) \
1136 lck_mtx_assert(&(_ifa)->ifa_lock, LCK_MTX_ASSERT_OWNED)
1137
1138#define IFA_LOCK_ASSERT_NOTHELD(_ifa) \
1139 lck_mtx_assert(&(_ifa)->ifa_lock, LCK_MTX_ASSERT_NOTOWNED)
1140
1141#define IFA_LOCK(_ifa) \
1142 lck_mtx_lock(&(_ifa)->ifa_lock)
1143
1144#define IFA_LOCK_SPIN(_ifa) \
1145 lck_mtx_lock_spin(&(_ifa)->ifa_lock)
1146
1147#define IFA_CONVERT_LOCK(_ifa) do { \
1148 IFA_LOCK_ASSERT_HELD(_ifa); \
1149 lck_mtx_convert_spin(&(_ifa)->ifa_lock); \
1150} while (0)
1151
1152#define IFA_UNLOCK(_ifa) \
1153 lck_mtx_unlock(&(_ifa)->ifa_lock)
1154
1155#define IFA_ADDREF(_ifa) \
1156 ifa_addref(_ifa, 0)
1157
1158#define IFA_ADDREF_LOCKED(_ifa) \
1159 ifa_addref(_ifa, 1)
1160
1161#define IFA_REMREF(_ifa) do { \
1162 (void) ifa_remref(_ifa, 0); \
1163} while (0)
1164
1165#define IFA_REMREF_LOCKED(_ifa) \
1166 ifa_remref(_ifa, 1)
1c79356b 1167
1c79356b
A
1168/*
1169 * Multicast address structure. This is analogous to the ifaddr
1170 * structure except that it keeps track of multicast addresses.
6d2010ae
A
1171 * Also, the request count here is a count of requests for this
1172 * address, not a count of pointers to this structure; anonymous
1173 * membership(s) holds one outstanding request count.
1c79356b
A
1174 */
1175struct ifmultiaddr {
6d2010ae
A
1176 decl_lck_mtx_data(, ifma_lock);
1177 u_int32_t ifma_refcount; /* reference count */
1178 u_int32_t ifma_anoncnt; /* # of anonymous requests */
1179 u_int32_t ifma_reqcnt; /* total requests for this address */
1180 u_int32_t ifma_debug; /* see ifa_debug flags */
1181 u_int32_t ifma_flags; /* see below */
1c79356b 1182 LIST_ENTRY(ifmultiaddr) ifma_link; /* queue macro glue */
6d2010ae 1183 struct sockaddr *ifma_addr; /* address this membership is for */
91447636 1184 struct ifmultiaddr *ifma_ll; /* link-layer translation, if any */
6d2010ae
A
1185 struct ifnet *ifma_ifp; /* back-pointer to interface */
1186 void *ifma_protospec; /* protocol-specific state, if any */
1187 void (*ifma_trace) /* callback fn for tracing refs */
1188 (struct ifmultiaddr *, int);
1c79356b 1189};
1c79356b 1190
91447636 1191/*
6d2010ae 1192 * Values for ifma_flags
91447636 1193 */
6d2010ae
A
1194#define IFMAF_ANONYMOUS 0x1 /* has anonymous request ref(s) held */
1195
1196#define IFMA_LOCK_ASSERT_HELD(_ifma) \
1197 lck_mtx_assert(&(_ifma)->ifma_lock, LCK_MTX_ASSERT_OWNED)
1198
1199#define IFMA_LOCK_ASSERT_NOTHELD(_ifma) \
1200 lck_mtx_assert(&(_ifma)->ifma_lock, LCK_MTX_ASSERT_NOTOWNED)
1201
1202#define IFMA_LOCK(_ifma) \
1203 lck_mtx_lock(&(_ifma)->ifma_lock)
1204
1205#define IFMA_LOCK_SPIN(_ifma) \
1206 lck_mtx_lock_spin(&(_ifma)->ifma_lock)
1207
1208#define IFMA_CONVERT_LOCK(_ifma) do { \
1209 IFMA_LOCK_ASSERT_HELD(_ifma); \
1210 lck_mtx_convert_spin(&(_ifma)->ifma_lock); \
1211} while (0)
1212
1213#define IFMA_UNLOCK(_ifma) \
1214 lck_mtx_unlock(&(_ifma)->ifma_lock)
1215
1216#define IFMA_ADDREF(_ifma) \
1217 ifma_addref(_ifma, 0)
1218
1219#define IFMA_ADDREF_LOCKED(_ifma) \
1220 ifma_addref(_ifma, 1)
1221
1222#define IFMA_REMREF(_ifma) \
1223 ifma_remref(_ifma)
1224
39236c6e
A
1225/*
1226 * Indicate whether or not the immediate interface, or the interface delegated
1227 * by it, is a cellular interface (IFT_CELLULAR). Delegated interface type is
1228 * set/cleared along with the delegated ifp; we cache the type for performance
1229 * to avoid dereferencing delegated ifp each time.
1230 *
1231 * Note that this is meant to be used only for accounting and policy purposes;
1232 * certain places need to explicitly know the immediate interface type, and
1233 * this macro should not be used there.
1234 *
1235 * The test is done against IFT_CELLULAR instead of IFNET_FAMILY_CELLULAR to
1236 * handle certain cases where the family isn't set to the latter.
1237 */
1238#define IFNET_IS_CELLULAR(_ifp) \
1239 ((_ifp)->if_type == IFT_CELLULAR || \
1240 (_ifp)->if_delegated.type == IFT_CELLULAR)
1241
4bd07ac2
A
1242/*
1243 * Indicate whether or not the immediate interface, or the interface delegated
1244 * by it, is an ETHERNET interface.
1245 */
1246#define IFNET_IS_ETHERNET(_ifp) \
1247 ((_ifp)->if_family == IFNET_FAMILY_ETHERNET || \
1248 (_ifp)->if_delegated.family == IFNET_FAMILY_ETHERNET)
39236c6e
A
1249/*
1250 * Indicate whether or not the immediate interface, or the interface delegated
1251 * by it, is a Wi-Fi interface (IFNET_SUBFAMILY_WIFI). Delegated interface
1252 * subfamily is set/cleared along with the delegated ifp; we cache the subfamily
1253 * for performance to avoid dereferencing delegated ifp each time.
1254 *
1255 * Note that this is meant to be used only for accounting and policy purposes;
1256 * certain places need to explicitly know the immediate interface type, and
1257 * this macro should not be used there.
1258 *
1259 * The test is done against IFNET_SUBFAMILY_WIFI as the family may be set to
1260 * IFNET_FAMILY_ETHERNET (as well as type to IFT_ETHER) which is too generic.
1261 */
1262#define IFNET_IS_WIFI(_ifp) \
1263 ((_ifp)->if_subfamily == IFNET_SUBFAMILY_WIFI || \
1264 (_ifp)->if_delegated.subfamily == IFNET_SUBFAMILY_WIFI)
1265
fe8ab488
A
1266/*
1267 * Indicate whether or not the immediate interface, or the interface delegated
1268 * by it, is a Wired interface (several families). Delegated interface
1269 * family is set/cleared along with the delegated ifp; we cache the family
1270 * for performance to avoid dereferencing delegated ifp each time.
1271 *
1272 * Note that this is meant to be used only for accounting and policy purposes;
1273 * certain places need to explicitly know the immediate interface type, and
1274 * this macro should not be used there.
1275 */
1276#define IFNET_IS_WIRED(_ifp) \
1277 ((_ifp)->if_family == IFNET_FAMILY_ETHERNET || \
1278 (_ifp)->if_delegated.family == IFNET_FAMILY_ETHERNET || \
1279 (_ifp)->if_family == IFNET_FAMILY_FIREWIRE || \
1280 (_ifp)->if_delegated.family == IFNET_FAMILY_FIREWIRE)
1281
39037602
A
1282/*
1283 * Indicate whether or not the immediate WiFi interface is on an infrastructure
1284 * network
1285 */
1286#define IFNET_IS_WIFI_INFRA(_ifp) \
1287 ((_ifp)->if_family == IFNET_FAMILY_ETHERNET && \
1288 (_ifp)->if_subfamily == IFNET_SUBFAMILY_WIFI && \
1289 !((_ifp)->if_eflags & IFEF_AWDL))
1290
fe8ab488
A
1291/*
1292 * Indicate whether or not the immediate interface, or the interface delegated
39037602
A
1293 * by it, is marked as expensive. The delegated interface is set/cleared
1294 * along with the delegated ifp; we cache the flag for performance to avoid
fe8ab488
A
1295 * dereferencing delegated ifp each time.
1296 *
1297 * Note that this is meant to be used only for policy purposes.
1298 */
1299#define IFNET_IS_EXPENSIVE(_ifp) \
1300 ((_ifp)->if_eflags & IFEF_EXPENSIVE || \
1301 (_ifp)->if_delegated.expensive)
1302
1303/*
1304 * We don't support AWDL interface delegation.
1305 */
1306#define IFNET_IS_AWDL_RESTRICTED(_ifp) \
1307 (((_ifp)->if_eflags & (IFEF_AWDL|IFEF_AWDL_RESTRICTED)) == \
1308 (IFEF_AWDL|IFEF_AWDL_RESTRICTED))
1309
39037602
A
1310#define IFNET_IS_INTCOPROC(_ifp) \
1311 ((_ifp)->if_family == IFNET_FAMILY_ETHERNET && \
1312 (_ifp)->if_subfamily == IFNET_SUBFAMILY_INTCOPROC)
fe8ab488 1313
39236c6e 1314extern struct ifnethead ifnet_head;
39037602 1315extern struct ifnethead ifnet_ordered_head;
39236c6e
A
1316extern struct ifnet **ifindex2ifnet;
1317extern u_int32_t if_sndq_maxlen;
1318extern u_int32_t if_rcvq_maxlen;
1319extern int if_index;
1320extern struct ifaddr **ifnet_addrs;
1321extern lck_attr_t *ifa_mtx_attr;
1322extern lck_grp_t *ifa_mtx_grp;
1323extern lck_grp_t *ifnet_lock_group;
1324extern lck_attr_t *ifnet_lock_attr;
6d2010ae 1325extern ifnet_t lo_ifp;
316670eb
A
1326extern uint32_t if_bw_measure_size;
1327extern u_int32_t if_bw_smoothing_val;
6d2010ae
A
1328
1329extern int if_addmulti(struct ifnet *, const struct sockaddr *,
1330 struct ifmultiaddr **);
1331extern int if_addmulti_anon(struct ifnet *, const struct sockaddr *,
1332 struct ifmultiaddr **);
1333extern int if_allmulti(struct ifnet *, int);
1334extern int if_delmulti(struct ifnet *, const struct sockaddr *);
1335extern int if_delmulti_ifma(struct ifmultiaddr *);
1336extern int if_delmulti_anon(struct ifnet *, const struct sockaddr *);
1337extern void if_down(struct ifnet *);
1338extern int if_down_all(void);
1339extern void if_up(struct ifnet *);
1340__private_extern__ void if_updown(struct ifnet *ifp, int up);
1341extern int ifioctl(struct socket *, u_long, caddr_t, struct proc *);
1342extern int ifioctllocked(struct socket *, u_long, caddr_t, struct proc *);
1343extern struct ifnet *ifunit(const char *);
39037602
A
1344extern struct ifnet *ifunit_ref(const char *);
1345extern int ifunit_extract(const char *src, char *dst, size_t dstlen, int *unit);
6d2010ae 1346extern struct ifnet *if_withname(struct sockaddr *);
316670eb
A
1347extern void if_qflush(struct ifnet *, int);
1348extern void if_qflush_sc(struct ifnet *, mbuf_svc_class_t, u_int32_t,
1349 u_int32_t *, u_int32_t *, int);
6d2010ae
A
1350
1351extern struct if_clone *if_clone_lookup(const char *, u_int32_t *);
1352extern int if_clone_attach(struct if_clone *);
1353extern void if_clone_detach(struct if_clone *);
1354
39037602 1355extern u_int32_t if_functional_type(struct ifnet *, bool);
3e170ce0 1356
6d2010ae
A
1357extern errno_t if_mcasts_update(struct ifnet *);
1358
1359typedef enum {
1360 IFNET_LCK_ASSERT_EXCLUSIVE, /* RW: held as writer */
1361 IFNET_LCK_ASSERT_SHARED, /* RW: held as reader */
1362 IFNET_LCK_ASSERT_OWNED, /* RW: writer/reader, MTX: held */
1363 IFNET_LCK_ASSERT_NOTOWNED /* not held */
1364} ifnet_lock_assert_t;
1365
39236c6e
A
1366#define IF_LLADDR(_ifp) \
1367 (LLADDR(SDL(((_ifp)->if_lladdr)->ifa_addr)))
1368
6d2010ae
A
1369__private_extern__ void ifnet_lock_assert(struct ifnet *, ifnet_lock_assert_t);
1370__private_extern__ void ifnet_lock_shared(struct ifnet *ifp);
1371__private_extern__ void ifnet_lock_exclusive(struct ifnet *ifp);
1372__private_extern__ void ifnet_lock_done(struct ifnet *ifp);
1373
3e170ce0
A
1374#if INET
1375__private_extern__ void if_inetdata_lock_shared(struct ifnet *ifp);
1376__private_extern__ void if_inetdata_lock_exclusive(struct ifnet *ifp);
1377__private_extern__ void if_inetdata_lock_done(struct ifnet *ifp);
1378#endif
1379
39236c6e
A
1380#if INET6
1381__private_extern__ void if_inet6data_lock_shared(struct ifnet *ifp);
1382__private_extern__ void if_inet6data_lock_exclusive(struct ifnet *ifp);
1383__private_extern__ void if_inet6data_lock_done(struct ifnet *ifp);
1384#endif
1385
6d2010ae
A
1386__private_extern__ void ifnet_head_lock_shared(void);
1387__private_extern__ void ifnet_head_lock_exclusive(void);
1388__private_extern__ void ifnet_head_done(void);
39037602 1389__private_extern__ void ifnet_head_assert_exclusive(void);
6d2010ae
A
1390
1391__private_extern__ errno_t ifnet_set_idle_flags_locked(ifnet_t, u_int32_t,
1392 u_int32_t);
1393__private_extern__ int ifnet_is_attached(struct ifnet *, int refio);
39037602 1394__private_extern__ void ifnet_incr_iorefcnt(struct ifnet *);
6d2010ae 1395__private_extern__ void ifnet_decr_iorefcnt(struct ifnet *);
316670eb
A
1396__private_extern__ void ifnet_set_start_cycle(struct ifnet *,
1397 struct timespec *);
1398__private_extern__ void ifnet_set_poll_cycle(struct ifnet *,
1399 struct timespec *);
6d2010ae
A
1400
1401__private_extern__ void if_attach_ifa(struct ifnet *, struct ifaddr *);
1402__private_extern__ void if_attach_link_ifa(struct ifnet *, struct ifaddr *);
1403__private_extern__ void if_detach_ifa(struct ifnet *, struct ifaddr *);
1404__private_extern__ void if_detach_link_ifa(struct ifnet *, struct ifaddr *);
1405
7ddcb079
A
1406__private_extern__ void dlil_if_lock(void);
1407__private_extern__ void dlil_if_unlock(void);
1408__private_extern__ void dlil_if_lock_assert(void);
1409
6d2010ae 1410extern struct ifaddr *ifa_ifwithaddr(const struct sockaddr *);
39037602 1411extern struct ifaddr *ifa_ifwithaddr_locked(const struct sockaddr *);
316670eb
A
1412extern struct ifaddr *ifa_ifwithaddr_scoped(const struct sockaddr *,
1413 unsigned int);
39037602
A
1414extern struct ifaddr *ifa_ifwithaddr_scoped_locked(const struct sockaddr *,
1415 unsigned int);
6d2010ae
A
1416extern struct ifaddr *ifa_ifwithdstaddr(const struct sockaddr *);
1417extern struct ifaddr *ifa_ifwithnet(const struct sockaddr *);
316670eb
A
1418extern struct ifaddr *ifa_ifwithnet_scoped(const struct sockaddr *,
1419 unsigned int);
6d2010ae
A
1420extern struct ifaddr *ifa_ifwithroute(int, const struct sockaddr *,
1421 const struct sockaddr *);
316670eb
A
1422extern struct ifaddr *ifa_ifwithroute_locked(int, const struct sockaddr *,
1423 const struct sockaddr *);
1424extern struct ifaddr *ifa_ifwithroute_scoped_locked(int,
1425 const struct sockaddr *, const struct sockaddr *, unsigned int);
6d2010ae
A
1426extern struct ifaddr *ifaof_ifpforaddr(const struct sockaddr *, struct ifnet *);
1427__private_extern__ struct ifaddr *ifa_ifpgetprimary(struct ifnet *, int);
1428extern void ifa_addref(struct ifaddr *, int);
1429extern struct ifaddr *ifa_remref(struct ifaddr *, int);
1430extern void ifa_lock_init(struct ifaddr *);
1431extern void ifa_lock_destroy(struct ifaddr *);
1432extern void ifma_addref(struct ifmultiaddr *, int);
1433extern void ifma_remref(struct ifmultiaddr *);
1434
1435extern void ifa_init(void);
1436
1437__private_extern__ struct in_ifaddr *ifa_foraddr(unsigned int);
1438__private_extern__ struct in_ifaddr *ifa_foraddr_scoped(unsigned int,
1439 unsigned int);
1440
316670eb
A
1441struct ifreq;
1442extern errno_t ifnet_getset_opportunistic(struct ifnet *, u_long,
1443 struct ifreq *, struct proc *);
1444extern int ifnet_get_throttle(struct ifnet *, u_int32_t *);
1445extern int ifnet_set_throttle(struct ifnet *, u_int32_t);
39236c6e
A
1446extern errno_t ifnet_getset_log(struct ifnet *, u_long,
1447 struct ifreq *, struct proc *);
1448extern int ifnet_set_log(struct ifnet *, int32_t, uint32_t, int32_t, int32_t);
1449extern int ifnet_get_log(struct ifnet *, int32_t *, uint32_t *, int32_t *,
1450 int32_t *);
1451extern int ifnet_notify_address(struct ifnet *, int);
316670eb 1452
6d2010ae
A
1453#if INET6
1454struct in6_addr;
1455__private_extern__ struct in6_ifaddr *ifa_foraddr6(struct in6_addr *);
1456__private_extern__ struct in6_ifaddr *ifa_foraddr6_scoped(struct in6_addr *,
1457 unsigned int);
1458#endif /* INET6 */
1459
1460__private_extern__ void if_data_internal_to_if_data(struct ifnet *ifp,
1461 const struct if_data_internal *if_data_int, struct if_data *if_data);
1462__private_extern__ void if_data_internal_to_if_data64(struct ifnet *ifp,
1463 const struct if_data_internal *if_data_int, struct if_data64 *if_data64);
1464__private_extern__ void if_copy_traffic_class(struct ifnet *ifp,
1465 struct if_traffic_class *if_tc);
316670eb
A
1466__private_extern__ void if_copy_data_extended(struct ifnet *ifp,
1467 struct if_data_extended *if_de);
1468__private_extern__ void if_copy_packet_stats(struct ifnet *ifp,
1469 struct if_packet_stats *if_ps);
1470__private_extern__ void if_copy_rxpoll_stats(struct ifnet *ifp,
1471 struct if_rxpoll_stats *if_rs);
6d2010ae
A
1472
1473__private_extern__ struct rtentry *ifnet_cached_rtlookup_inet(struct ifnet *,
1474 struct in_addr);
1475#if INET6
1476__private_extern__ struct rtentry *ifnet_cached_rtlookup_inet6(struct ifnet *,
1477 struct in6_addr *);
1478#endif /* INET6 */
1479
3e170ce0
A
1480__private_extern__ errno_t if_state_update(struct ifnet *,
1481 struct if_interface_state *);
1482__private_extern__ void if_get_state(struct ifnet *,
1483 struct if_interface_state *);
1484__private_extern__ errno_t if_probe_connectivity(struct ifnet *ifp,
1485 u_int32_t conn_probe);
1486__private_extern__ void if_lqm_update(struct ifnet *, int32_t, int);
316670eb
A
1487__private_extern__ void ifnet_update_sndq(struct ifclassq *, cqev_t);
1488__private_extern__ void ifnet_update_rcv(struct ifnet *, cqev_t);
1489
39236c6e
A
1490__private_extern__ void ifnet_flowadv(uint32_t);
1491
316670eb
A
1492__private_extern__ errno_t ifnet_set_input_bandwidths(struct ifnet *,
1493 struct if_bandwidths *);
1494__private_extern__ errno_t ifnet_set_output_bandwidths(struct ifnet *,
1495 struct if_bandwidths *, boolean_t);
1496__private_extern__ u_int64_t ifnet_output_linkrate(struct ifnet *);
1497__private_extern__ u_int64_t ifnet_input_linkrate(struct ifnet *);
39236c6e
A
1498
1499__private_extern__ errno_t ifnet_set_input_latencies(struct ifnet *,
1500 struct if_latencies *);
1501__private_extern__ errno_t ifnet_set_output_latencies(struct ifnet *,
1502 struct if_latencies *, boolean_t);
1503
3e170ce0
A
1504__private_extern__ void ifnet_clear_netagent(uuid_t);
1505
1506__private_extern__ int ifnet_set_netsignature(struct ifnet *, uint8_t,
1507 uint8_t, uint16_t, uint8_t *);
1508__private_extern__ int ifnet_get_netsignature(struct ifnet *, uint8_t,
1509 uint8_t *, uint16_t *, uint8_t *);
1510
39037602
A
1511/* Required exclusive ifnet_head lock */
1512__private_extern__ void ifnet_remove_from_ordered_list(struct ifnet *);
1513
1514__private_extern__ void ifnet_increment_generation(struct ifnet *);
1515__private_extern__ u_int32_t ifnet_get_generation(struct ifnet *);
1516
1517extern int if_set_qosmarking_mode(struct ifnet *, u_int32_t);
1518
39236c6e
A
1519__private_extern__ errno_t ifnet_framer_stub(struct ifnet *, struct mbuf **,
1520 const struct sockaddr *, const char *, const char *, u_int32_t *,
1521 u_int32_t *);
316670eb
A
1522#endif /* BSD_KERNEL_PRIVATE */
1523#ifdef XNU_KERNEL_PRIVATE
1524/* for uuid.c */
1525__private_extern__ int uuid_get_ethernet(u_int8_t *);
6d2010ae 1526#endif /* XNU_KERNEL_PRIVATE */
1c79356b 1527#endif /* !_NET_IF_VAR_H_ */