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