]> git.saurik.com Git - apple/xnu.git/blame - bsd/net/if_var.h
xnu-2422.115.4.tar.gz
[apple/xnu.git] / bsd / net / if_var.h
CommitLineData
1c79356b 1/*
39236c6e 2 * Copyright (c) 2000-2013 Apple Inc. All rights reserved.
5d5c5d0d 3 *
2d21ac55 4 * @APPLE_OSREFERENCE_LICENSE_HEADER_START@
39236c6e 5 *
2d21ac55
A
6 * This file contains Original Code and/or Modifications of Original Code
7 * as defined in and that are subject to the Apple Public Source License
8 * Version 2.0 (the 'License'). You may not use this file except in
9 * compliance with the License. The rights granted to you under the License
10 * may not be used to create, or enable the creation or redistribution of,
11 * unlawful or unlicensed copies of an Apple operating system, or to
12 * circumvent, violate, or enable the circumvention or violation of, any
13 * terms of an Apple operating system software license agreement.
39236c6e 14 *
2d21ac55
A
15 * Please obtain a copy of the License at
16 * http://www.opensource.apple.com/apsl/ and read it before using this file.
39236c6e 17 *
2d21ac55
A
18 * The Original Code and all software distributed under the License are
19 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
8f6c56a5
A
20 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
21 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
2d21ac55
A
22 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
23 * Please see the License for the specific language governing rights and
24 * limitations under the License.
39236c6e 25 *
2d21ac55 26 * @APPLE_OSREFERENCE_LICENSE_HEADER_END@
1c79356b
A
27 */
28/*
29 * Copyright (c) 1982, 1986, 1989, 1993
30 * The Regents of the University of California. All rights reserved.
31 *
32 * Redistribution and use in source and binary forms, with or without
33 * modification, are permitted provided that the following conditions
34 * are met:
35 * 1. Redistributions of source code must retain the above copyright
36 * notice, this list of conditions and the following disclaimer.
37 * 2. Redistributions in binary form must reproduce the above copyright
38 * notice, this list of conditions and the following disclaimer in the
39 * documentation and/or other materials provided with the distribution.
40 * 3. All advertising materials mentioning features or use of this software
41 * must display the following acknowledgement:
42 * This product includes software developed by the University of
43 * California, Berkeley and its contributors.
44 * 4. Neither the name of the University nor the names of its contributors
45 * may be used to endorse or promote products derived from this software
46 * without specific prior written permission.
47 *
48 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
49 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
50 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
51 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
52 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
53 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
54 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
55 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
56 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
57 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
58 * SUCH DAMAGE.
59 *
60 * From: @(#)if.h 8.1 (Berkeley) 6/10/93
9bccf70c 61 * $FreeBSD: src/sys/net/if_var.h,v 1.18.2.7 2001/07/24 19:10:18 brooks Exp $
1c79356b
A
62 */
63
64#ifndef _NET_IF_VAR_H_
65#define _NET_IF_VAR_H_
91447636 66
9bccf70c 67#include <sys/appleapiopts.h>
b0d623f7 68#include <stdint.h>
91447636
A
69#include <sys/types.h>
70#include <sys/time.h>
71#include <sys/queue.h> /* get TAILQ macros */
72#ifdef KERNEL_PRIVATE
73#include <kern/locks.h>
74#endif /* KERNEL_PRIVATE */
b0d623f7
A
75#ifdef PRIVATE
76#include <net/route.h>
77#endif
91447636
A
78
79#ifdef KERNEL
80#include <net/kpi_interface.h>
b0d623f7 81#endif /* KERNEL */
1c79356b 82
9bccf70c 83#ifdef __APPLE__
1c79356b
A
84#define APPLE_IF_FAM_LOOPBACK 1
85#define APPLE_IF_FAM_ETHERNET 2
86#define APPLE_IF_FAM_SLIP 3
87#define APPLE_IF_FAM_TUN 4
88#define APPLE_IF_FAM_VLAN 5
89#define APPLE_IF_FAM_PPP 6
90#define APPLE_IF_FAM_PVC 7
91#define APPLE_IF_FAM_DISC 8
92#define APPLE_IF_FAM_MDECAP 9
93#define APPLE_IF_FAM_GIF 10
316670eb 94#define APPLE_IF_FAM_FAITH 11 /* deprecated */
55e303ae
A
95#define APPLE_IF_FAM_STF 12
96#define APPLE_IF_FAM_FIREWIRE 13
91447636 97#define APPLE_IF_FAM_BOND 14
0c530ab8 98#endif /* __APPLE__ */
91447636
A
99
100/*
101 * 72 was chosen below because it is the size of a TCP/IP
102 * header (40) + the minimum mss (32).
103 */
104#define IF_MINMTU 72
105#define IF_MAXMTU 65535
1c79356b
A
106
107/*
108 * Structures defining a network interface, providing a packet
109 * transport mechanism (ala level 0 of the PUP protocols).
110 *
111 * Each interface accepts output datagrams of a specified maximum
112 * length, and provides higher level routines with input datagrams
113 * received from its medium.
114 *
115 * Output occurs when the routine if_output is called, with three parameters:
116 * (*ifp->if_output)(ifp, m, dst, rt)
117 * Here m is the mbuf chain to be sent and dst is the destination address.
118 * The output routine encapsulates the supplied datagram if necessary,
119 * and then transmits it on its medium.
120 *
121 * On input, each interface unwraps the data received by it, and either
122 * places it on the input queue of a internetwork datagram routine
123 * and posts the associated software interrupt, or passes the datagram to a raw
124 * packet input routine.
125 *
126 * Routines exist for locating interfaces by their addresses
127 * or for locating a interface on a certain network, as well as more general
128 * routing and gateway routines maintaining information used to locate
129 * interfaces. These routines live in the files if.c and route.c
130 */
131
1c79356b
A
132#define IFNAMSIZ 16
133
1c79356b
A
134/* This belongs up in socket.h or socketvar.h, depending on how far the
135 * event bubbles up.
136 */
137
138struct net_event_data {
2d21ac55
A
139 u_int32_t if_family;
140 u_int32_t if_unit;
141 char if_name[IFNAMSIZ];
1c79356b 142};
1c79356b 143
2d21ac55 144#if defined(__LP64__)
39236c6e 145#include <sys/_types/_timeval32.h>
2d21ac55
A
146#define IF_DATA_TIMEVAL timeval32
147#else
148#define IF_DATA_TIMEVAL timeval
149#endif
150
151#pragma pack(4)
152
91447636
A
153/*
154 * Structure describing information about an interface
155 * which may be of interest to management entities.
156 */
157struct if_data {
158 /* generic interface information */
2d21ac55
A
159 u_char ifi_type; /* ethernet, tokenring, etc */
160 u_char ifi_typelen; /* Length of frame type id */
161 u_char ifi_physical; /* e.g., AUI, Thinnet, 10base-T, etc */
162 u_char ifi_addrlen; /* media address length */
163 u_char ifi_hdrlen; /* media header length */
164 u_char ifi_recvquota; /* polling quota for receive intrs */
165 u_char ifi_xmitquota; /* polling quota for xmit intrs */
166 u_char ifi_unused1; /* for future use */
167 u_int32_t ifi_mtu; /* maximum transmission unit */
168 u_int32_t ifi_metric; /* routing metric (external only) */
169 u_int32_t ifi_baudrate; /* linespeed */
91447636 170 /* volatile statistics */
2d21ac55
A
171 u_int32_t ifi_ipackets; /* packets received on interface */
172 u_int32_t ifi_ierrors; /* input errors on interface */
173 u_int32_t ifi_opackets; /* packets sent on interface */
174 u_int32_t ifi_oerrors; /* output errors on interface */
175 u_int32_t ifi_collisions; /* collisions on csma interfaces */
176 u_int32_t ifi_ibytes; /* total number of octets received */
177 u_int32_t ifi_obytes; /* total number of octets sent */
178 u_int32_t ifi_imcasts; /* packets received via multicast */
179 u_int32_t ifi_omcasts; /* packets sent via multicast */
180 u_int32_t ifi_iqdrops; /* dropped on input, this interface */
181 u_int32_t ifi_noproto; /* destined for unsupported protocol */
182 u_int32_t ifi_recvtiming; /* usec spent receiving when timing */
183 u_int32_t ifi_xmittiming; /* usec spent xmitting when timing */
184 struct IF_DATA_TIMEVAL ifi_lastchange; /* time of last administrative change */
185 u_int32_t ifi_unused2; /* used to be the default_proto */
186 u_int32_t ifi_hwassist; /* HW offload capabilities */
187 u_int32_t ifi_reserved1; /* for future use */
188 u_int32_t ifi_reserved2; /* for future use */
91447636 189};
4a249263 190
1c79356b
A
191/*
192 * Structure describing information about an interface
193 * which may be of interest to management entities.
194 */
91447636 195struct if_data64 {
1c79356b 196 /* generic interface information */
2d21ac55
A
197 u_char ifi_type; /* ethernet, tokenring, etc */
198 u_char ifi_typelen; /* Length of frame type id */
91447636
A
199 u_char ifi_physical; /* e.g., AUI, Thinnet, 10base-T, etc */
200 u_char ifi_addrlen; /* media address length */
201 u_char ifi_hdrlen; /* media header length */
202 u_char ifi_recvquota; /* polling quota for receive intrs */
203 u_char ifi_xmitquota; /* polling quota for xmit intrs */
204 u_char ifi_unused1; /* for future use */
2d21ac55
A
205 u_int32_t ifi_mtu; /* maximum transmission unit */
206 u_int32_t ifi_metric; /* routing metric (external only) */
91447636
A
207 u_int64_t ifi_baudrate; /* linespeed */
208 /* volatile statistics */
209 u_int64_t ifi_ipackets; /* packets received on interface */
210 u_int64_t ifi_ierrors; /* input errors on interface */
211 u_int64_t ifi_opackets; /* packets sent on interface */
212 u_int64_t ifi_oerrors; /* output errors on interface */
213 u_int64_t ifi_collisions; /* collisions on csma interfaces */
214 u_int64_t ifi_ibytes; /* total number of octets received */
215 u_int64_t ifi_obytes; /* total number of octets sent */
216 u_int64_t ifi_imcasts; /* packets received via multicast */
217 u_int64_t ifi_omcasts; /* packets sent via multicast */
218 u_int64_t ifi_iqdrops; /* dropped on input, this interface */
219 u_int64_t ifi_noproto; /* destined for unsupported protocol */
2d21ac55
A
220 u_int32_t ifi_recvtiming; /* usec spent receiving when timing */
221 u_int32_t ifi_xmittiming; /* usec spent xmitting when timing */
222 struct IF_DATA_TIMEVAL ifi_lastchange; /* time of last administrative change */
91447636
A
223};
224
225#ifdef PRIVATE
d41d1dae 226struct if_traffic_class {
316670eb
A
227 u_int64_t ifi_ibepackets; /* TC_BE packets received on interface */
228 u_int64_t ifi_ibebytes; /* TC_BE bytes received on interface */
229 u_int64_t ifi_obepackets; /* TC_BE packet sent on interface */
230 u_int64_t ifi_obebytes; /* TC_BE bytes sent on interface */
d41d1dae
A
231 u_int64_t ifi_ibkpackets; /* TC_BK packets received on interface */
232 u_int64_t ifi_ibkbytes; /* TC_BK bytes received on interface */
233 u_int64_t ifi_obkpackets; /* TC_BK packet sent on interface */
234 u_int64_t ifi_obkbytes; /* TC_BK bytes sent on interface */
235 u_int64_t ifi_ivipackets; /* TC_VI packets received on interface */
236 u_int64_t ifi_ivibytes; /* TC_VI bytes received on interface */
237 u_int64_t ifi_ovipackets; /* TC_VI packets sent on interface */
238 u_int64_t ifi_ovibytes; /* TC_VI bytes sent on interface */
239 u_int64_t ifi_ivopackets; /* TC_VO packets received on interface */
240 u_int64_t ifi_ivobytes; /* TC_VO bytes received on interface */
241 u_int64_t ifi_ovopackets; /* TC_VO packets sent on interface */
242 u_int64_t ifi_ovobytes; /* TC_VO bytes sent on interface */
316670eb
A
243 u_int64_t ifi_ipvpackets; /* TC priv packets received on interface */
244 u_int64_t ifi_ipvbytes; /* TC priv bytes received on interface */
245 u_int64_t ifi_opvpackets; /* TC priv packets sent on interface */
246 u_int64_t ifi_opvbytes; /* TC priv bytes sent on interface */
247};
248
249struct if_data_extended {
250 u_int64_t ifi_alignerrs; /* unaligned (32-bit) input pkts */
39236c6e
A
251 u_int64_t ifi_dt_bytes; /* Data threshold counter */
252 u_int64_t ifi_fpackets; /* forwarded packets on interface */
253 u_int64_t ifi_fbytes; /* forwarded bytes on interface */
254 u_int64_t reserved[12]; /* for future */
316670eb
A
255};
256
257struct if_packet_stats {
258 /* TCP */
259 u_int64_t ifi_tcp_badformat;
260 u_int64_t ifi_tcp_unspecv6;
261 u_int64_t ifi_tcp_synfin;
262 u_int64_t ifi_tcp_badformatipsec;
263 u_int64_t ifi_tcp_noconnnolist;
264 u_int64_t ifi_tcp_noconnlist;
265 u_int64_t ifi_tcp_listbadsyn;
266 u_int64_t ifi_tcp_icmp6unreach;
267 u_int64_t ifi_tcp_deprecate6;
268 u_int64_t ifi_tcp_rstinsynrcv;
269 u_int64_t ifi_tcp_ooopacket;
270 u_int64_t ifi_tcp_dospacket;
271 u_int64_t ifi_tcp_cleanup;
272 u_int64_t ifi_tcp_synwindow;
39236c6e 273 u_int64_t reserved[6];
316670eb
A
274 /* UDP */
275 u_int64_t ifi_udp_port_unreach;
276 u_int64_t ifi_udp_faithprefix;
277 u_int64_t ifi_udp_port0;
278 u_int64_t ifi_udp_badlength;
279 u_int64_t ifi_udp_badchksum;
280 u_int64_t ifi_udp_badmcast;
281 u_int64_t ifi_udp_cleanup;
282 u_int64_t ifi_udp_badipsec;
39236c6e 283 u_int64_t _reserved[4];
316670eb
A
284};
285
286struct if_description {
287 u_int32_t ifd_maxlen; /* must be IF_DESCSIZE */
288 u_int32_t ifd_len; /* actual ifd_desc length */
289 u_int8_t *ifd_desc; /* ptr to desc buffer */
290};
291
292struct if_bandwidths {
293 u_int64_t eff_bw; /* effective bandwidth */
294 u_int64_t max_bw; /* maximum theoretical bandwidth */
295};
296
39236c6e
A
297struct if_latencies {
298 u_int64_t eff_lt; /* effective latency */
299 u_int64_t max_lt; /* maximum theoretical latency */
300};
301
316670eb
A
302struct if_rxpoll_stats {
303 u_int32_t ifi_poll_off_req; /* total # of POLL_OFF reqs */
304 u_int32_t ifi_poll_off_err; /* total # of POLL_OFF errors */
305 u_int32_t ifi_poll_on_req; /* total # of POLL_ON reqs */
306 u_int32_t ifi_poll_on_err; /* total # of POLL_ON errors */
307
308 u_int32_t ifi_poll_wakeups_avg; /* avg # of wakeup reqs */
309 u_int32_t ifi_poll_wakeups_lowat; /* wakeups low watermark */
310 u_int32_t ifi_poll_wakeups_hiwat; /* wakeups high watermark */
311
312 u_int64_t ifi_poll_packets; /* total # of polled packets */
313 u_int32_t ifi_poll_packets_avg; /* average polled packets */
314 u_int32_t ifi_poll_packets_min; /* smallest polled packets */
315 u_int32_t ifi_poll_packets_max; /* largest polled packets */
316 u_int32_t ifi_poll_packets_lowat; /* packets low watermark */
317 u_int32_t ifi_poll_packets_hiwat; /* packets high watermark */
318
319 u_int64_t ifi_poll_bytes; /* total # of polled bytes */
320 u_int32_t ifi_poll_bytes_avg; /* average polled bytes */
321 u_int32_t ifi_poll_bytes_min; /* smallest polled bytes */
322 u_int32_t ifi_poll_bytes_max; /* largest polled bytes */
323 u_int32_t ifi_poll_bytes_lowat; /* bytes low watermark */
324 u_int32_t ifi_poll_bytes_hiwat; /* bytes high watermark */
39236c6e
A
325
326 u_int32_t ifi_poll_packets_limit; /* max packets per poll call */
327 u_int64_t ifi_poll_interval_time; /* poll interval (nsec) */
d41d1dae 328};
6d2010ae
A
329#endif /* PRIVATE */
330
331#pragma pack()
d41d1dae 332
6d2010ae
A
333/*
334 * Structure defining a queue for a network interface.
335 */
336struct ifqueue {
337 void *ifq_head;
338 void *ifq_tail;
339 int ifq_len;
340 int ifq_maxlen;
341 int ifq_drops;
342};
343
316670eb 344#ifdef BSD_KERNEL_PRIVATE
91447636
A
345/*
346 * Internal storage of if_data. This is bound to change. Various places in the
347 * stack will translate this data structure in to the externally visible
6d2010ae
A
348 * if_data structure above. Note that during interface attach time, the
349 * embedded if_data structure in ifnet is cleared, with the exception of
350 * some non-statistics related fields.
91447636
A
351 */
352struct if_data_internal {
353 /* generic interface information */
2d21ac55
A
354 u_char ifi_type; /* ethernet, tokenring, etc */
355 u_char ifi_typelen; /* Length of frame type id */
356 u_char ifi_physical; /* e.g., AUI, Thinnet, 10base-T, etc */
357 u_char ifi_addrlen; /* media address length */
358 u_char ifi_hdrlen; /* media header length */
359 u_char ifi_recvquota; /* polling quota for receive intrs */
360 u_char ifi_xmitquota; /* polling quota for xmit intrs */
361 u_char ifi_unused1; /* for future use */
362 u_int32_t ifi_mtu; /* maximum transmission unit */
363 u_int32_t ifi_metric; /* routing metric (external only) */
364 u_int32_t ifi_baudrate; /* linespeed */
6d2010ae 365 u_int32_t _pad;
1c79356b 366 /* volatile statistics */
91447636
A
367 u_int64_t ifi_ipackets; /* packets received on interface */
368 u_int64_t ifi_ierrors; /* input errors on interface */
369 u_int64_t ifi_opackets; /* packets sent on interface */
370 u_int64_t ifi_oerrors; /* output errors on interface */
371 u_int64_t ifi_collisions; /* collisions on csma interfaces */
2d21ac55
A
372 u_int64_t ifi_ibytes; /* total number of octets received */
373 u_int64_t ifi_obytes; /* total number of octets sent */
91447636
A
374 u_int64_t ifi_imcasts; /* packets received via multicast */
375 u_int64_t ifi_omcasts; /* packets sent via multicast */
376 u_int64_t ifi_iqdrops; /* dropped on input, this interface */
377 u_int64_t ifi_noproto; /* destined for unsupported protocol */
2d21ac55
A
378 u_int32_t ifi_recvtiming; /* usec spent receiving when timing */
379 u_int32_t ifi_xmittiming; /* usec spent xmitting when timing */
316670eb 380 u_int64_t ifi_alignerrs; /* unaligned (32-bit) input pkts */
39236c6e
A
381 u_int64_t ifi_dt_bytes; /* Data threshold counter */
382 u_int64_t ifi_fpackets; /* forwarded packets on interface */
383 u_int64_t ifi_fbytes; /* forwarded bytes on interface */
1c79356b 384 struct timeval ifi_lastchange; /* time of last administrative change */
2d21ac55 385 u_int32_t ifi_hwassist; /* HW offload capabilities */
b0d623f7
A
386 u_int32_t ifi_tso_v4_mtu; /* TCP Segment Offload IPv4 maximum segment size */
387 u_int32_t ifi_tso_v6_mtu; /* TCP Segment Offload IPv6 maximum segment size */
1c79356b 388};
316670eb 389
39236c6e 390#if MEASURE_BW
316670eb
A
391/*
392 * Fields per interface to measure perceived bandwidth.
393 */
316670eb
A
394struct if_measured_bw {
395 u_int64_t bw; /* measured bandwidth in bytes per ms */
396 u_int64_t bytes; /* XXX not needed */
397 u_int64_t ts; /* XXX not needed */
398 u_int64_t cur_seq __attribute((aligned(8))); /* current sequence for marking a packet */
399 u_int64_t start_ts; /* time at which a measurement started */
400 u_int64_t start_seq; /* sequence at which a measurement should start */
401 u_int64_t last_seq; /* last recorded seq */
402 u_int64_t last_ts; /* last recorded ts */
403 u_int32_t flags __attribute__((aligned(4))); /* flags */
404#define IF_MEASURED_BW_INPROGRESS 0x1
405#define IF_MEASURED_BW_CALCULATION 0x2
406};
39236c6e 407#endif /* MEASURE_BW */
316670eb 408#endif /* BSD_KERNEL_PRIVATE */
91447636 409
6d2010ae 410#ifdef PRIVATE
91447636
A
411#define if_mtu if_data.ifi_mtu
412#define if_type if_data.ifi_type
413#define if_typelen if_data.ifi_typelen
414#define if_physical if_data.ifi_physical
415#define if_addrlen if_data.ifi_addrlen
416#define if_hdrlen if_data.ifi_hdrlen
417#define if_metric if_data.ifi_metric
418#define if_baudrate if_data.ifi_baudrate
419#define if_hwassist if_data.ifi_hwassist
420#define if_ipackets if_data.ifi_ipackets
421#define if_ierrors if_data.ifi_ierrors
422#define if_opackets if_data.ifi_opackets
423#define if_oerrors if_data.ifi_oerrors
424#define if_collisions if_data.ifi_collisions
425#define if_ibytes if_data.ifi_ibytes
426#define if_obytes if_data.ifi_obytes
427#define if_imcasts if_data.ifi_imcasts
428#define if_omcasts if_data.ifi_omcasts
429#define if_iqdrops if_data.ifi_iqdrops
430#define if_noproto if_data.ifi_noproto
431#define if_lastchange if_data.ifi_lastchange
432#define if_recvquota if_data.ifi_recvquota
433#define if_xmitquota if_data.ifi_xmitquota
6d2010ae 434#endif /* PRIVATE */
316670eb 435#ifdef BSD_KERNEL_PRIVATE
b0d623f7
A
436#define if_tso_v4_mtu if_data.ifi_tso_v4_mtu
437#define if_tso_v6_mtu if_data.ifi_tso_v6_mtu
316670eb 438#define if_alignerrs if_data.ifi_alignerrs
39236c6e
A
439#define if_dt_bytes if_data.ifi_dt_bytes
440#define if_fpackets if_data.ifi_fpackets
441#define if_fbytes if_data.ifi_fbytes
316670eb 442#endif /* BSD_KERNEL_PRIVATE */
91447636 443
316670eb 444#ifdef BSD_KERNEL_PRIVATE
91447636
A
445/*
446 * Forward structure declarations for function prototypes [sic].
447 */
6d2010ae
A
448struct proc;
449struct rtentry;
450struct socket;
91447636 451struct ifnet_filter;
6d2010ae
A
452struct mbuf;
453struct ifaddr;
454struct tqdummy;
455struct proto_hash_entry;
456struct dlil_threading_info;
316670eb
A
457struct tcpstat_local;
458struct udpstat_local;
6d2010ae
A
459#if PF
460struct pfi_kif;
461#endif /* PF */
91447636 462
6d2010ae
A
463/* we use TAILQs so that the order of instantiation is preserved in the list */
464TAILQ_HEAD(ifnethead, ifnet);
465TAILQ_HEAD(ifaddrhead, ifaddr);
466TAILQ_HEAD(ifprefixhead, ifprefix);
467LIST_HEAD(ifmultihead, ifmultiaddr);
468TAILQ_HEAD(tailq_head, tqdummy);
91447636
A
469TAILQ_HEAD(ifnet_filter_head, ifnet_filter);
470TAILQ_HEAD(ddesc_head_name, dlil_demux_desc);
316670eb 471#endif /* BSD_KERNEL_PRIVATE */
91447636 472
6d2010ae
A
473#ifdef PRIVATE
474/*
475 * All of the following IF_HWASSIST_* flags are defined in kpi_inteface.h as
476 * IFNET_* flags. These are redefined here as constants to avoid failures to
477 * build user level programs that can not include kpi_interface.h. It is
478 * important to keep this in sync with the definitions in kpi_interface.h.
479 * The corresponding constant for each definition is mentioned in the comment.
b0d623f7 480 *
6d2010ae 481 * Bottom 16 bits reserved for hardware checksum
b0d623f7
A
482 */
483#define IF_HWASSIST_CSUM_IP 0x0001 /* will csum IP, IFNET_CSUM_IP */
484#define IF_HWASSIST_CSUM_TCP 0x0002 /* will csum TCP, IFNET_CSUM_TCP */
485#define IF_HWASSIST_CSUM_UDP 0x0004 /* will csum UDP, IFNET_CSUM_UDP */
486#define IF_HWASSIST_CSUM_IP_FRAGS 0x0008 /* will csum IP fragments, IFNET_CSUM_FRAGMENT */
487#define IF_HWASSIST_CSUM_FRAGMENT 0x0010 /* will do IP fragmentation, IFNET_IP_FRAGMENT */
6d2010ae
A
488#define IF_HWASSIST_CSUM_TCPIPV6 0x0020 /* will csum TCPv6, IFNET_CSUM_TCPIPV6 */
489#define IF_HWASSIST_CSUM_UDPIPV6 0x0040 /* will csum UDPv6, IFNET_CSUM_UDP */
490#define IF_HWASSIST_CSUM_FRAGMENT_IPV6 0x0080 /* will do IPv6 fragmentation, IFNET_IPV6_FRAGMENT */
39236c6e 491#define IF_HWASSIST_CSUM_PARTIAL 0x1000 /* simple Sum16 computation, IFNET_CSUM_PARTIAL */
91447636
A
492#define IF_HWASSIST_CSUM_MASK 0xffff
493#define IF_HWASSIST_CSUM_FLAGS(hwassist) ((hwassist) & IF_HWASSIST_CSUM_MASK)
494
495/* VLAN support */
b0d623f7
A
496#define IF_HWASSIST_VLAN_TAGGING 0x00010000 /* supports VLAN tagging, IFNET_VLAN_TAGGING */
497#define IF_HWASSIST_VLAN_MTU 0x00020000 /* supports VLAN MTU-sized packet (for software VLAN), IFNET_VLAN_MTU */
498
499/* TCP Segment Offloading support */
500
501#define IF_HWASSIST_TSO_V4 0x00200000 /* will do TCP Segment offload for IPv4, IFNET_TSO_IPV4 */
502#define IF_HWASSIST_TSO_V6 0x00400000 /* will do TCP Segment offload for IPv6, IFNET_TSO_IPV6 */
2d21ac55 503#endif /* PRIVATE */
1c79356b 504
39236c6e
A
505#ifdef PRIVATE
506#define IFXNAMSIZ (IFNAMSIZ + 8) /* external name (name + unit) */
507#endif
508
316670eb
A
509#ifdef BSD_KERNEL_PRIVATE
510/*
511 * ifnet is private to BSD portion of kernel
512 */
39236c6e 513#include <sys/mcache.h>
6d2010ae
A
514#include <sys/tree.h>
515#include <netinet/in.h>
39236c6e 516#include <net/if_dl.h>
316670eb 517#include <net/classq/if_classq.h>
39236c6e 518#include <net/if_types.h>
2d21ac55 519
6d2010ae 520RB_HEAD(ll_reach_tree, if_llreach); /* define struct ll_reach_tree */
91447636 521
39236c6e 522#define if_name(ifp) ifp->if_xname
1c79356b
A
523/*
524 * Structure defining a network interface.
525 *
526 * (Would like to call this struct ``if'', but C isn't PL/1.)
527 */
528struct ifnet {
6d2010ae
A
529 /*
530 * Lock (RW or mutex) to protect this data structure (static storage.)
531 */
532 decl_lck_rw_data(, if_lock);
533 void *if_softc; /* pointer to driver state */
534 const char *if_name; /* name, e.g. ``en'' or ``lo'' */
39236c6e 535 const char *if_xname; /* external name (name + unit) */
316670eb 536 struct if_description if_desc; /* extended description */
6d2010ae
A
537 TAILQ_ENTRY(ifnet) if_link; /* all struct ifnets are chained */
538 TAILQ_ENTRY(ifnet) if_detaching_link; /* list of detaching ifnets */
539
540 decl_lck_mtx_data(, if_ref_lock)
39236c6e 541 u_int32_t if_refflags; /* see IFRF flags below */
6d2010ae
A
542 u_int32_t if_refio; /* number of io ops to the underlying driver */
543
544#define if_list if_link
545 struct ifaddrhead if_addrhead; /* linked list of addresses per if */
546#define if_addrlist if_addrhead
547 struct ifaddr *if_lladdr; /* link address (first/permanent) */
548
549 int if_pcount; /* number of promiscuous listeners */
550 struct bpf_if *if_bpf; /* packet filter structure */
551 u_short if_index; /* numeric abbreviation for this if */
552 short if_unit; /* sub-unit for lower level driver */
553 short if_timer; /* time 'til if_watchdog called */
554 short if_flags; /* up/down, broadcast, etc. */
555 u_int32_t if_eflags; /* see <net/if.h> */
556
557 int if_capabilities; /* interface features & capabilities */
558 int if_capenable; /* enabled features & capabilities */
559
560 void *if_linkmib; /* link-type-specific MIB data */
561 size_t if_linkmiblen; /* length of above data */
562
563 struct if_data_internal if_data __attribute__((aligned(8)));
564
565 ifnet_family_t if_family; /* value assigned by Apple */
39236c6e 566 ifnet_subfamily_t if_subfamily; /* value assigned by Apple */
6d2010ae 567 uintptr_t if_family_cookie;
91447636 568 ifnet_output_func if_output;
316670eb
A
569 ifnet_pre_enqueue_func if_pre_enqueue;
570 ifnet_start_func if_start;
571 ifnet_ctl_func if_output_ctl;
572 ifnet_input_poll_func if_input_poll;
573 ifnet_ctl_func if_input_ctl;
91447636
A
574 ifnet_ioctl_func if_ioctl;
575 ifnet_set_bpf_tap if_set_bpf_tap;
576 ifnet_detached_func if_free;
577 ifnet_demux_func if_demux;
578 ifnet_event_func if_event;
39236c6e
A
579 ifnet_framer_func if_framer_legacy;
580 ifnet_framer_extended_func if_framer;
6d2010ae
A
581 ifnet_add_proto_func if_add_proto;
582 ifnet_del_proto_func if_del_proto;
583 ifnet_check_multi if_check_multi;
584 struct proto_hash_entry *if_proto_hash;
585 void *if_kpi_storage;
1c79356b 586
39236c6e
A
587 u_int32_t if_flowhash; /* interface flow control ID */
588
316670eb 589 decl_lck_mtx_data(, if_start_lock);
39236c6e 590 u_int32_t if_start_flags; /* see IFSF flags below */
316670eb
A
591 u_int32_t if_start_req;
592 u_int32_t if_start_active; /* output is active */
593 struct timespec if_start_cycle; /* restart interval */
594 struct thread *if_start_thread;
595
596 struct ifclassq if_snd; /* transmit queue */
597 u_int32_t if_output_sched_model; /* tx sched model */
598
599 struct if_bandwidths if_output_bw;
600 struct if_bandwidths if_input_bw;
601
39236c6e
A
602 struct if_latencies if_output_lt;
603 struct if_latencies if_input_lt;
604
6d2010ae
A
605 decl_lck_mtx_data(, if_flt_lock)
606 u_int32_t if_flt_busy;
607 u_int32_t if_flt_waiters;
91447636 608 struct ifnet_filter_head if_flt_head;
1c79356b 609
6d2010ae
A
610 struct ifmultihead if_multiaddrs; /* multicast addresses */
611 u_int32_t if_updatemcasts; /* mcast addrs need updating */
612 int if_amcount; /* # of all-multicast reqs */
613 decl_lck_mtx_data(, if_addrconfig_lock); /* for serializing addr config */
614 struct in_multi *if_allhostsinm; /* store all-hosts inm for this ifp */
1c79356b 615
316670eb
A
616 decl_lck_mtx_data(, if_poll_lock);
617 u_int16_t if_poll_req;
618 u_int16_t if_poll_update; /* link update */
619 u_int32_t if_poll_active; /* polling is active */
620 struct timespec if_poll_cycle; /* poll interval */
621 struct thread *if_poll_thread;
91447636 622
316670eb 623 struct dlil_threading_info *if_inp;
91447636 624
6d2010ae 625 struct ifprefixhead if_prefixhead; /* list of prefixes per if */
91447636 626 struct {
b0d623f7 627 u_int32_t length;
91447636
A
628 union {
629 u_char buffer[8];
630 u_char *ptr;
631 } u;
632 } if_broadcast;
2d21ac55 633#if CONFIG_MACF_NET
6d2010ae 634 struct label *if_label; /* interface MAC label */
2d21ac55 635#endif
b0d623f7 636
6d2010ae 637 u_int32_t if_wake_properties;
b0d623f7 638#if PF
6d2010ae 639 struct pfi_kif *if_pf_kif;
b0d623f7 640#endif /* PF */
1c79356b 641
6d2010ae
A
642 decl_lck_mtx_data(, if_cached_route_lock);
643 u_int32_t if_fwd_cacheok;
644 struct route if_fwd_route; /* cached forwarding route */
645 struct route if_src_route; /* cached ipv4 source route */
646 struct route_in6 if_src_route6; /* cached ipv6 source route */
91447636 647
6d2010ae
A
648 decl_lck_rw_data(, if_llreach_lock);
649 struct ll_reach_tree if_ll_srcs; /* source link-layer tree */
91447636 650
6d2010ae
A
651 void *if_bridge; /* bridge glue */
652
653 u_int32_t if_want_aggressive_drain;
654 u_int32_t if_idle_flags; /* idle flags */
655 u_int32_t if_idle_new_flags; /* temporary idle flags */
656 u_int32_t if_idle_new_flags_mask; /* temporary mask */
657 u_int32_t if_route_refcnt; /* idle: route ref count */
658
659 struct if_traffic_class if_tc __attribute__((aligned(8)));
660#if INET
661 struct igmp_ifinfo *if_igi; /* for IGMPv3 */
662#endif /* INET */
663#if INET6
664 struct mld_ifinfo *if_mli; /* for MLDv2 */
665#endif /* INET6 */
316670eb
A
666
667 int if_lqm; /* link quality metric */
39236c6e 668#if MEASURE_BW
316670eb 669 struct if_measured_bw if_bw;
39236c6e 670#endif /* MEASURE_BW */
316670eb
A
671 struct tcpstat_local *if_tcp_stat; /* TCP specific stats */
672 struct udpstat_local *if_udp_stat; /* UDP specific stats */
39236c6e
A
673
674 struct {
675 int32_t level; /* cached logging level */
676 u_int32_t flags; /* cached logging flags */
677 int32_t category; /* cached category */
678 int32_t subcategory; /* cached subcategory */
679 } if_log;
680
681 struct {
682 struct ifnet *ifp; /* delegated ifp */
683 u_int32_t type; /* delegated i/f type */
684 u_int32_t family; /* delegated i/f family */
685 u_int32_t subfamily; /* delegated i/f sub-family */
686 } if_delegated;
687
688 u_int64_t if_data_threshold;
689 u_int32_t if_fg_sendts; /* last send on a fg socket in seconds */
690
691#if INET6
692 decl_lck_rw_data(, if_inet6data_lock);
693 void *if_inet6data;
694#endif
6d2010ae
A
695};
696
39236c6e
A
697#define IF_TCP_STATINC(_ifp, _s) do { \
698 if ((_ifp)->if_tcp_stat != NULL) \
699 atomic_add_64(&(_ifp)->if_tcp_stat->_s, 1); \
700} while (0);
701
702#define IF_UDP_STATINC(_ifp, _s) do { \
703 if ((_ifp)->if_udp_stat != NULL) \
704 atomic_add_64(&(_ifp)->if_udp_stat->_s, 1); \
705} while (0);
706
6d2010ae 707/*
39236c6e 708 * Valid values for if_refflags
6d2010ae
A
709 */
710#define IFRF_ATTACHED 0x1 /* ifnet attach is completely done */
711#define IFRF_DETACHING 0x2 /* detach has been requested */
91447636 712
39236c6e
A
713/*
714 * Valid values for if_start_flags
715 */
716#define IFSF_FLOW_CONTROLLED 0x1 /* flow controlled */
717
4a249263
A
718/*
719 * Structure describing a `cloning' interface.
720 */
721struct if_clone {
722 LIST_ENTRY(if_clone) ifc_list; /* on list of cloners */
6d2010ae
A
723 const char *ifc_name; /* name of device, e.g. `vlan' */
724 size_t ifc_namelen; /* length of name */
725 u_int32_t ifc_minifs; /* minimum number of interfaces */
726 u_int32_t ifc_maxunit; /* maximum unit number */
727 unsigned char *ifc_units; /* bitmap to handle units */
728 u_int32_t ifc_bmlen; /* bitmap length */
729
730 int (*ifc_create)(struct if_clone *, u_int32_t, void *);
731 int (*ifc_destroy)(struct ifnet *);
4a249263
A
732};
733
6d2010ae
A
734#define IF_CLONE_INITIALIZER(name, create, destroy, minifs, maxunit) { \
735 { NULL, NULL }, name, (sizeof (name) - 1), minifs, maxunit, NULL, 0, \
736 create, destroy \
737}
9bccf70c 738
d1ecb069
A
739#define M_CLONE M_IFADDR
740
1c79356b 741/*
6d2010ae
A
742 * Macros to manipulate ifqueue. Users of these macros are responsible
743 * for serialization, by holding whatever lock is appropriate for the
744 * corresponding structure that is referring the ifqueue.
1c79356b
A
745 */
746#define IF_QFULL(ifq) ((ifq)->ifq_len >= (ifq)->ifq_maxlen)
747#define IF_DROP(ifq) ((ifq)->ifq_drops++)
316670eb
A
748
749#define IF_ENQUEUE(ifq, m) do { \
6d2010ae
A
750 (m)->m_nextpkt = NULL; \
751 if ((ifq)->ifq_tail == NULL) \
752 (ifq)->ifq_head = m; \
753 else \
754 ((struct mbuf*)(ifq)->ifq_tail)->m_nextpkt = m; \
755 (ifq)->ifq_tail = m; \
756 (ifq)->ifq_len++; \
316670eb
A
757} while (0)
758
759#define IF_PREPEND(ifq, m) do { \
6d2010ae
A
760 (m)->m_nextpkt = (ifq)->ifq_head; \
761 if ((ifq)->ifq_tail == NULL) \
762 (ifq)->ifq_tail = (m); \
763 (ifq)->ifq_head = (m); \
764 (ifq)->ifq_len++; \
316670eb
A
765} while (0)
766
767#define IF_DEQUEUE(ifq, m) do { \
6d2010ae
A
768 (m) = (ifq)->ifq_head; \
769 if (m != NULL) { \
770 if (((ifq)->ifq_head = (m)->m_nextpkt) == NULL) \
771 (ifq)->ifq_tail = NULL; \
772 (m)->m_nextpkt = NULL; \
773 (ifq)->ifq_len--; \
774 } \
316670eb
A
775} while (0)
776
777#define IF_REMQUEUE(ifq, m) do { \
6d2010ae
A
778 struct mbuf *_p = (ifq)->ifq_head; \
779 struct mbuf *_n = (m)->m_nextpkt; \
780 if ((m) == _p) \
781 _p = NULL; \
782 while (_p != NULL) { \
783 if (_p->m_nextpkt == (m)) \
784 break; \
785 _p = _p->m_nextpkt; \
786 } \
787 VERIFY(_p != NULL || ((m) == (ifq)->ifq_head)); \
788 if ((m) == (ifq)->ifq_head) \
789 (ifq)->ifq_head = _n; \
790 if ((m) == (ifq)->ifq_tail) \
791 (ifq)->ifq_tail = _p; \
792 VERIFY((ifq)->ifq_tail != NULL || (ifq)->ifq_head == NULL); \
793 VERIFY((ifq)->ifq_len != 0); \
794 --(ifq)->ifq_len; \
795 if (_p != NULL) \
796 _p->m_nextpkt = _n; \
797 (m)->m_nextpkt = NULL; \
316670eb
A
798} while (0)
799
6d2010ae 800#define IF_DRAIN(ifq) do { \
316670eb 801 struct mbuf *_m; \
6d2010ae 802 for (;;) { \
316670eb
A
803 IF_DEQUEUE(ifq, _m); \
804 if (_m == NULL) \
6d2010ae 805 break; \
316670eb 806 m_freem(_m); \
6d2010ae
A
807 } \
808} while (0)
1c79356b 809
1c79356b
A
810/*
811 * The ifaddr structure contains information about one address
812 * of an interface. They are maintained by the different address families,
813 * are allocated and attached when an address is set, and are linked
814 * together so all addresses for an interface can be located.
815 */
816struct ifaddr {
6d2010ae
A
817 decl_lck_mtx_data(, ifa_lock); /* lock for ifaddr */
818 uint32_t ifa_refcnt; /* ref count, use IFA_{ADD,REM}REF */
819 uint32_t ifa_debug; /* debug flags */
820 struct sockaddr *ifa_addr; /* address of interface */
821 struct sockaddr *ifa_dstaddr; /* other end of p-to-p link */
1c79356b 822#define ifa_broadaddr ifa_dstaddr /* broadcast address interface */
6d2010ae
A
823 struct sockaddr *ifa_netmask; /* used to determine subnet */
824 struct ifnet *ifa_ifp; /* back-pointer to interface */
1c79356b 825 TAILQ_ENTRY(ifaddr) ifa_link; /* queue macro glue */
b0d623f7
A
826 void (*ifa_rtrequest) /* check or clean routes (+ or -)'d */
827 (int, struct rtentry *, struct sockaddr *);
6d2010ae
A
828 uint32_t ifa_flags; /* mostly rt_flags for cloning */
829 int32_t ifa_metric; /* cost of going out this interface */
b0d623f7
A
830 void (*ifa_free)(struct ifaddr *); /* callback fn for freeing */
831 void (*ifa_trace) /* callback fn for tracing refs */
832 (struct ifaddr *, int);
6d2010ae
A
833 void (*ifa_attached)(struct ifaddr *); /* callback fn for attaching */
834 void (*ifa_detached)(struct ifaddr *); /* callback fn for detaching */
1c79356b 835};
b0d623f7
A
836
837/*
838 * Valid values for ifa_flags
839 */
91447636
A
840#define IFA_ROUTE RTF_UP /* route installed (0x1) */
841#define IFA_CLONING RTF_CLONING /* (0x100) */
b0d623f7
A
842
843/*
844 * Valid values for ifa_debug
845 */
6d2010ae 846#define IFD_ATTACHED 0x1 /* attached to list */
b0d623f7
A
847#define IFD_ALLOC 0x2 /* dynamically allocated */
848#define IFD_DEBUG 0x4 /* has debugging info */
6d2010ae
A
849#define IFD_LINK 0x8 /* link address */
850#define IFD_TRASHED 0x10 /* in trash list */
851#define IFD_SKIP 0x20 /* skip this entry */
852#define IFD_NOTREADY 0x40 /* embryonic; not yet ready */
91447636 853
6d2010ae
A
854#define IFA_LOCK_ASSERT_HELD(_ifa) \
855 lck_mtx_assert(&(_ifa)->ifa_lock, LCK_MTX_ASSERT_OWNED)
856
857#define IFA_LOCK_ASSERT_NOTHELD(_ifa) \
858 lck_mtx_assert(&(_ifa)->ifa_lock, LCK_MTX_ASSERT_NOTOWNED)
859
860#define IFA_LOCK(_ifa) \
861 lck_mtx_lock(&(_ifa)->ifa_lock)
862
863#define IFA_LOCK_SPIN(_ifa) \
864 lck_mtx_lock_spin(&(_ifa)->ifa_lock)
865
866#define IFA_CONVERT_LOCK(_ifa) do { \
867 IFA_LOCK_ASSERT_HELD(_ifa); \
868 lck_mtx_convert_spin(&(_ifa)->ifa_lock); \
869} while (0)
870
871#define IFA_UNLOCK(_ifa) \
872 lck_mtx_unlock(&(_ifa)->ifa_lock)
873
874#define IFA_ADDREF(_ifa) \
875 ifa_addref(_ifa, 0)
876
877#define IFA_ADDREF_LOCKED(_ifa) \
878 ifa_addref(_ifa, 1)
879
880#define IFA_REMREF(_ifa) do { \
881 (void) ifa_remref(_ifa, 0); \
882} while (0)
883
884#define IFA_REMREF_LOCKED(_ifa) \
885 ifa_remref(_ifa, 1)
1c79356b
A
886
887/*
888 * The prefix structure contains information about one prefix
889 * of an interface. They are maintained by the different address families,
890 * are allocated and attached when an prefix or an address is set,
891 * and are linked together so all prefixes for an interface can be located.
892 */
893struct ifprefix {
894 struct sockaddr *ifpr_prefix; /* prefix of interface */
895 struct ifnet *ifpr_ifp; /* back-pointer to interface */
9bccf70c 896 TAILQ_ENTRY(ifprefix) ifpr_list; /* queue macro glue */
1c79356b
A
897 u_char ifpr_plen; /* prefix length in bits */
898 u_char ifpr_type; /* protocol dependent prefix type */
899};
900
901/*
902 * Multicast address structure. This is analogous to the ifaddr
903 * structure except that it keeps track of multicast addresses.
6d2010ae
A
904 * Also, the request count here is a count of requests for this
905 * address, not a count of pointers to this structure; anonymous
906 * membership(s) holds one outstanding request count.
1c79356b
A
907 */
908struct ifmultiaddr {
6d2010ae
A
909 decl_lck_mtx_data(, ifma_lock);
910 u_int32_t ifma_refcount; /* reference count */
911 u_int32_t ifma_anoncnt; /* # of anonymous requests */
912 u_int32_t ifma_reqcnt; /* total requests for this address */
913 u_int32_t ifma_debug; /* see ifa_debug flags */
914 u_int32_t ifma_flags; /* see below */
1c79356b 915 LIST_ENTRY(ifmultiaddr) ifma_link; /* queue macro glue */
6d2010ae 916 struct sockaddr *ifma_addr; /* address this membership is for */
91447636 917 struct ifmultiaddr *ifma_ll; /* link-layer translation, if any */
6d2010ae
A
918 struct ifnet *ifma_ifp; /* back-pointer to interface */
919 void *ifma_protospec; /* protocol-specific state, if any */
920 void (*ifma_trace) /* callback fn for tracing refs */
921 (struct ifmultiaddr *, int);
1c79356b 922};
1c79356b 923
91447636 924/*
6d2010ae 925 * Values for ifma_flags
91447636 926 */
6d2010ae
A
927#define IFMAF_ANONYMOUS 0x1 /* has anonymous request ref(s) held */
928
929#define IFMA_LOCK_ASSERT_HELD(_ifma) \
930 lck_mtx_assert(&(_ifma)->ifma_lock, LCK_MTX_ASSERT_OWNED)
931
932#define IFMA_LOCK_ASSERT_NOTHELD(_ifma) \
933 lck_mtx_assert(&(_ifma)->ifma_lock, LCK_MTX_ASSERT_NOTOWNED)
934
935#define IFMA_LOCK(_ifma) \
936 lck_mtx_lock(&(_ifma)->ifma_lock)
937
938#define IFMA_LOCK_SPIN(_ifma) \
939 lck_mtx_lock_spin(&(_ifma)->ifma_lock)
940
941#define IFMA_CONVERT_LOCK(_ifma) do { \
942 IFMA_LOCK_ASSERT_HELD(_ifma); \
943 lck_mtx_convert_spin(&(_ifma)->ifma_lock); \
944} while (0)
945
946#define IFMA_UNLOCK(_ifma) \
947 lck_mtx_unlock(&(_ifma)->ifma_lock)
948
949#define IFMA_ADDREF(_ifma) \
950 ifma_addref(_ifma, 0)
951
952#define IFMA_ADDREF_LOCKED(_ifma) \
953 ifma_addref(_ifma, 1)
954
955#define IFMA_REMREF(_ifma) \
956 ifma_remref(_ifma)
957
39236c6e
A
958/*
959 * Indicate whether or not the immediate interface, or the interface delegated
960 * by it, is a cellular interface (IFT_CELLULAR). Delegated interface type is
961 * set/cleared along with the delegated ifp; we cache the type for performance
962 * to avoid dereferencing delegated ifp each time.
963 *
964 * Note that this is meant to be used only for accounting and policy purposes;
965 * certain places need to explicitly know the immediate interface type, and
966 * this macro should not be used there.
967 *
968 * The test is done against IFT_CELLULAR instead of IFNET_FAMILY_CELLULAR to
969 * handle certain cases where the family isn't set to the latter.
970 */
971#define IFNET_IS_CELLULAR(_ifp) \
972 ((_ifp)->if_type == IFT_CELLULAR || \
973 (_ifp)->if_delegated.type == IFT_CELLULAR)
974
975/*
976 * Indicate whether or not the immediate interface, or the interface delegated
977 * by it, is a Wi-Fi interface (IFNET_SUBFAMILY_WIFI). Delegated interface
978 * subfamily is set/cleared along with the delegated ifp; we cache the subfamily
979 * for performance to avoid dereferencing delegated ifp each time.
980 *
981 * Note that this is meant to be used only for accounting and policy purposes;
982 * certain places need to explicitly know the immediate interface type, and
983 * this macro should not be used there.
984 *
985 * The test is done against IFNET_SUBFAMILY_WIFI as the family may be set to
986 * IFNET_FAMILY_ETHERNET (as well as type to IFT_ETHER) which is too generic.
987 */
988#define IFNET_IS_WIFI(_ifp) \
989 ((_ifp)->if_subfamily == IFNET_SUBFAMILY_WIFI || \
990 (_ifp)->if_delegated.subfamily == IFNET_SUBFAMILY_WIFI)
991
992extern struct ifnethead ifnet_head;
993extern struct ifnet **ifindex2ifnet;
994extern u_int32_t if_sndq_maxlen;
995extern u_int32_t if_rcvq_maxlen;
996extern int if_index;
997extern struct ifaddr **ifnet_addrs;
998extern lck_attr_t *ifa_mtx_attr;
999extern lck_grp_t *ifa_mtx_grp;
1000extern lck_grp_t *ifnet_lock_group;
1001extern lck_attr_t *ifnet_lock_attr;
6d2010ae 1002extern ifnet_t lo_ifp;
316670eb
A
1003extern uint32_t if_bw_measure_size;
1004extern u_int32_t if_bw_smoothing_val;
6d2010ae
A
1005
1006extern int if_addmulti(struct ifnet *, const struct sockaddr *,
1007 struct ifmultiaddr **);
1008extern int if_addmulti_anon(struct ifnet *, const struct sockaddr *,
1009 struct ifmultiaddr **);
1010extern int if_allmulti(struct ifnet *, int);
1011extern int if_delmulti(struct ifnet *, const struct sockaddr *);
1012extern int if_delmulti_ifma(struct ifmultiaddr *);
1013extern int if_delmulti_anon(struct ifnet *, const struct sockaddr *);
1014extern void if_down(struct ifnet *);
1015extern int if_down_all(void);
1016extern void if_up(struct ifnet *);
1017__private_extern__ void if_updown(struct ifnet *ifp, int up);
1018extern int ifioctl(struct socket *, u_long, caddr_t, struct proc *);
1019extern int ifioctllocked(struct socket *, u_long, caddr_t, struct proc *);
1020extern struct ifnet *ifunit(const char *);
1021extern struct ifnet *if_withname(struct sockaddr *);
316670eb
A
1022extern void if_qflush(struct ifnet *, int);
1023extern void if_qflush_sc(struct ifnet *, mbuf_svc_class_t, u_int32_t,
1024 u_int32_t *, u_int32_t *, int);
6d2010ae
A
1025
1026extern struct if_clone *if_clone_lookup(const char *, u_int32_t *);
1027extern int if_clone_attach(struct if_clone *);
1028extern void if_clone_detach(struct if_clone *);
1029
1030extern errno_t if_mcasts_update(struct ifnet *);
1031
1032typedef enum {
1033 IFNET_LCK_ASSERT_EXCLUSIVE, /* RW: held as writer */
1034 IFNET_LCK_ASSERT_SHARED, /* RW: held as reader */
1035 IFNET_LCK_ASSERT_OWNED, /* RW: writer/reader, MTX: held */
1036 IFNET_LCK_ASSERT_NOTOWNED /* not held */
1037} ifnet_lock_assert_t;
1038
39236c6e
A
1039#define IF_LLADDR(_ifp) \
1040 (LLADDR(SDL(((_ifp)->if_lladdr)->ifa_addr)))
1041
6d2010ae
A
1042__private_extern__ void ifnet_lock_assert(struct ifnet *, ifnet_lock_assert_t);
1043__private_extern__ void ifnet_lock_shared(struct ifnet *ifp);
1044__private_extern__ void ifnet_lock_exclusive(struct ifnet *ifp);
1045__private_extern__ void ifnet_lock_done(struct ifnet *ifp);
1046
39236c6e
A
1047#if INET6
1048__private_extern__ void if_inet6data_lock_shared(struct ifnet *ifp);
1049__private_extern__ void if_inet6data_lock_exclusive(struct ifnet *ifp);
1050__private_extern__ void if_inet6data_lock_done(struct ifnet *ifp);
1051#endif
1052
6d2010ae
A
1053__private_extern__ void ifnet_head_lock_shared(void);
1054__private_extern__ void ifnet_head_lock_exclusive(void);
1055__private_extern__ void ifnet_head_done(void);
1056
1057__private_extern__ errno_t ifnet_set_idle_flags_locked(ifnet_t, u_int32_t,
1058 u_int32_t);
1059__private_extern__ int ifnet_is_attached(struct ifnet *, int refio);
1060__private_extern__ void ifnet_decr_iorefcnt(struct ifnet *);
316670eb
A
1061__private_extern__ void ifnet_set_start_cycle(struct ifnet *,
1062 struct timespec *);
1063__private_extern__ void ifnet_set_poll_cycle(struct ifnet *,
1064 struct timespec *);
6d2010ae
A
1065
1066__private_extern__ void if_attach_ifa(struct ifnet *, struct ifaddr *);
1067__private_extern__ void if_attach_link_ifa(struct ifnet *, struct ifaddr *);
1068__private_extern__ void if_detach_ifa(struct ifnet *, struct ifaddr *);
1069__private_extern__ void if_detach_link_ifa(struct ifnet *, struct ifaddr *);
1070
7ddcb079
A
1071__private_extern__ void dlil_if_lock(void);
1072__private_extern__ void dlil_if_unlock(void);
1073__private_extern__ void dlil_if_lock_assert(void);
1074
6d2010ae 1075extern struct ifaddr *ifa_ifwithaddr(const struct sockaddr *);
316670eb
A
1076extern struct ifaddr *ifa_ifwithaddr_scoped(const struct sockaddr *,
1077 unsigned int);
6d2010ae
A
1078extern struct ifaddr *ifa_ifwithdstaddr(const struct sockaddr *);
1079extern struct ifaddr *ifa_ifwithnet(const struct sockaddr *);
316670eb
A
1080extern struct ifaddr *ifa_ifwithnet_scoped(const struct sockaddr *,
1081 unsigned int);
6d2010ae
A
1082extern struct ifaddr *ifa_ifwithroute(int, const struct sockaddr *,
1083 const struct sockaddr *);
316670eb
A
1084extern struct ifaddr *ifa_ifwithroute_locked(int, const struct sockaddr *,
1085 const struct sockaddr *);
1086extern struct ifaddr *ifa_ifwithroute_scoped_locked(int,
1087 const struct sockaddr *, const struct sockaddr *, unsigned int);
6d2010ae
A
1088extern struct ifaddr *ifaof_ifpforaddr(const struct sockaddr *, struct ifnet *);
1089__private_extern__ struct ifaddr *ifa_ifpgetprimary(struct ifnet *, int);
1090extern void ifa_addref(struct ifaddr *, int);
1091extern struct ifaddr *ifa_remref(struct ifaddr *, int);
1092extern void ifa_lock_init(struct ifaddr *);
1093extern void ifa_lock_destroy(struct ifaddr *);
1094extern void ifma_addref(struct ifmultiaddr *, int);
1095extern void ifma_remref(struct ifmultiaddr *);
1096
1097extern void ifa_init(void);
1098
1099__private_extern__ struct in_ifaddr *ifa_foraddr(unsigned int);
1100__private_extern__ struct in_ifaddr *ifa_foraddr_scoped(unsigned int,
1101 unsigned int);
1102
316670eb
A
1103struct ifreq;
1104extern errno_t ifnet_getset_opportunistic(struct ifnet *, u_long,
1105 struct ifreq *, struct proc *);
1106extern int ifnet_get_throttle(struct ifnet *, u_int32_t *);
1107extern int ifnet_set_throttle(struct ifnet *, u_int32_t);
39236c6e
A
1108extern errno_t ifnet_getset_log(struct ifnet *, u_long,
1109 struct ifreq *, struct proc *);
1110extern int ifnet_set_log(struct ifnet *, int32_t, uint32_t, int32_t, int32_t);
1111extern int ifnet_get_log(struct ifnet *, int32_t *, uint32_t *, int32_t *,
1112 int32_t *);
1113extern int ifnet_notify_address(struct ifnet *, int);
316670eb 1114
6d2010ae
A
1115#if INET6
1116struct in6_addr;
1117__private_extern__ struct in6_ifaddr *ifa_foraddr6(struct in6_addr *);
1118__private_extern__ struct in6_ifaddr *ifa_foraddr6_scoped(struct in6_addr *,
1119 unsigned int);
1120#endif /* INET6 */
1121
1122__private_extern__ void if_data_internal_to_if_data(struct ifnet *ifp,
1123 const struct if_data_internal *if_data_int, struct if_data *if_data);
1124__private_extern__ void if_data_internal_to_if_data64(struct ifnet *ifp,
1125 const struct if_data_internal *if_data_int, struct if_data64 *if_data64);
1126__private_extern__ void if_copy_traffic_class(struct ifnet *ifp,
1127 struct if_traffic_class *if_tc);
316670eb
A
1128__private_extern__ void if_copy_data_extended(struct ifnet *ifp,
1129 struct if_data_extended *if_de);
1130__private_extern__ void if_copy_packet_stats(struct ifnet *ifp,
1131 struct if_packet_stats *if_ps);
1132__private_extern__ void if_copy_rxpoll_stats(struct ifnet *ifp,
1133 struct if_rxpoll_stats *if_rs);
6d2010ae
A
1134
1135__private_extern__ struct rtentry *ifnet_cached_rtlookup_inet(struct ifnet *,
1136 struct in_addr);
1137#if INET6
1138__private_extern__ struct rtentry *ifnet_cached_rtlookup_inet6(struct ifnet *,
1139 struct in6_addr *);
1140#endif /* INET6 */
1141
316670eb
A
1142__private_extern__ void if_lqm_update(struct ifnet *, int32_t);
1143__private_extern__ void ifnet_update_sndq(struct ifclassq *, cqev_t);
1144__private_extern__ void ifnet_update_rcv(struct ifnet *, cqev_t);
1145
39236c6e
A
1146__private_extern__ void ifnet_flowadv(uint32_t);
1147
316670eb
A
1148__private_extern__ errno_t ifnet_set_input_bandwidths(struct ifnet *,
1149 struct if_bandwidths *);
1150__private_extern__ errno_t ifnet_set_output_bandwidths(struct ifnet *,
1151 struct if_bandwidths *, boolean_t);
1152__private_extern__ u_int64_t ifnet_output_linkrate(struct ifnet *);
1153__private_extern__ u_int64_t ifnet_input_linkrate(struct ifnet *);
39236c6e
A
1154
1155__private_extern__ errno_t ifnet_set_input_latencies(struct ifnet *,
1156 struct if_latencies *);
1157__private_extern__ errno_t ifnet_set_output_latencies(struct ifnet *,
1158 struct if_latencies *, boolean_t);
1159
1160__private_extern__ errno_t ifnet_framer_stub(struct ifnet *, struct mbuf **,
1161 const struct sockaddr *, const char *, const char *, u_int32_t *,
1162 u_int32_t *);
316670eb
A
1163#endif /* BSD_KERNEL_PRIVATE */
1164#ifdef XNU_KERNEL_PRIVATE
1165/* for uuid.c */
1166__private_extern__ int uuid_get_ethernet(u_int8_t *);
6d2010ae 1167#endif /* XNU_KERNEL_PRIVATE */
1c79356b 1168#endif /* !_NET_IF_VAR_H_ */