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