xref: /xnu-8792.81.2/bsd/net/if_var.h (revision 19c3b8c28c31cb8130e034cfb5df6bf9ba342d90)
1 /*
2  * Copyright (c) 2000-2021 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 #ifdef DRIVERKIT
68 #include <stddef.h>
69 #include <stdint.h>
70 #else
71 #include <sys/appleapiopts.h>
72 #include <stdint.h>
73 #include <sys/types.h>
74 #include <sys/time.h>
75 #include <sys/queue.h>          /* get TAILQ macros */
76 #ifdef BSD_KERN_PRIVATE
77 #include <net/pktsched/pktsched.h>
78 #include <sys/eventhandler.h>
79 #endif
80 
81 #ifdef KERNEL
82 #include <net/kpi_interface.h>
83 #endif /* KERNEL */
84 
85 #ifdef __APPLE__
86 #define APPLE_IF_FAM_LOOPBACK  1
87 #define APPLE_IF_FAM_ETHERNET  2
88 #define APPLE_IF_FAM_SLIP      3
89 #define APPLE_IF_FAM_TUN       4
90 #define APPLE_IF_FAM_VLAN      5
91 #define APPLE_IF_FAM_PPP       6
92 #define APPLE_IF_FAM_PVC       7
93 #define APPLE_IF_FAM_DISC      8
94 #define APPLE_IF_FAM_MDECAP    9
95 #define APPLE_IF_FAM_GIF       10
96 #define APPLE_IF_FAM_FAITH     11       /* deprecated */
97 #define APPLE_IF_FAM_STF       12
98 #define APPLE_IF_FAM_FIREWIRE  13
99 #define APPLE_IF_FAM_BOND      14
100 #define APPLE_IF_FAM_CELLULAR  15
101 #define APPLE_IF_FAM_UNUSED_16 16       /* Un-used */
102 #define APPLE_IF_FAM_UTUN      17
103 #define APPLE_IF_FAM_IPSEC     18
104 #endif /* __APPLE__ */
105 
106 /*
107  * 72 was chosen below because it is the size of a TCP/IP
108  * header (40) + the minimum mss (32).
109  */
110 #define IF_MINMTU       72
111 #define IF_MAXMTU       65535
112 
113 /*
114  * Structures defining a network interface, providing a packet
115  * transport mechanism (ala level 0 of the PUP protocols).
116  *
117  * Each interface accepts output datagrams of a specified maximum
118  * length, and provides higher level routines with input datagrams
119  * received from its medium.
120  *
121  * Output occurs when the routine if_output is called, with three parameters:
122  *	(*ifp->if_output)(ifp, m, dst, rt)
123  * Here m is the mbuf chain to be sent and dst is the destination address.
124  * The output routine encapsulates the supplied datagram if necessary,
125  * and then transmits it on its medium.
126  *
127  * On input, each interface unwraps the data received by it, and either
128  * places it on the input queue of a internetwork datagram routine
129  * and posts the associated software interrupt, or passes the datagram to a raw
130  * packet input routine.
131  *
132  * Routines exist for locating interfaces by their addresses
133  * or for locating a interface on a certain network, as well as more general
134  * routing and gateway routines maintaining information used to locate
135  * interfaces.  These routines live in the files if.c and route.c
136  */
137 
138 #define IFNAMSIZ        16
139 
140 /* This belongs up in socket.h or socketvar.h, depending on how far the
141  *   event bubbles up.
142  */
143 
144 struct net_event_data {
145 	u_int32_t       if_family;
146 	u_int32_t       if_unit;
147 	char            if_name[IFNAMSIZ];
148 };
149 
150 #if defined(__LP64__)
151 #include <sys/_types/_timeval32.h>
152 #define IF_DATA_TIMEVAL timeval32
153 #else
154 #define IF_DATA_TIMEVAL timeval
155 #endif
156 
157 #pragma pack(4)
158 
159 /*
160  * Structure describing information about an interface
161  * which may be of interest to management entities.
162  */
163 struct if_data {
164 	/* generic interface information */
165 	u_char          ifi_type;       /* ethernet, tokenring, etc */
166 	u_char          ifi_typelen;    /* Length of frame type id */
167 	u_char          ifi_physical;   /* e.g., AUI, Thinnet, 10base-T, etc */
168 	u_char          ifi_addrlen;    /* media address length */
169 	u_char          ifi_hdrlen;     /* media header length */
170 	u_char          ifi_recvquota;  /* polling quota for receive intrs */
171 	u_char          ifi_xmitquota;  /* polling quota for xmit intrs */
172 	u_char          ifi_unused1;    /* for future use */
173 	u_int32_t       ifi_mtu;        /* maximum transmission unit */
174 	u_int32_t       ifi_metric;     /* routing metric (external only) */
175 	u_int32_t       ifi_baudrate;   /* linespeed */
176 	/* volatile statistics */
177 	u_int32_t       ifi_ipackets;   /* packets received on interface */
178 	u_int32_t       ifi_ierrors;    /* input errors on interface */
179 	u_int32_t       ifi_opackets;   /* packets sent on interface */
180 	u_int32_t       ifi_oerrors;    /* output errors on interface */
181 	u_int32_t       ifi_collisions; /* collisions on csma interfaces */
182 	u_int32_t       ifi_ibytes;     /* total number of octets received */
183 	u_int32_t       ifi_obytes;     /* total number of octets sent */
184 	u_int32_t       ifi_imcasts;    /* packets received via multicast */
185 	u_int32_t       ifi_omcasts;    /* packets sent via multicast */
186 	u_int32_t       ifi_iqdrops;    /* dropped on input, this interface */
187 	u_int32_t       ifi_noproto;    /* destined for unsupported protocol */
188 	u_int32_t       ifi_recvtiming; /* usec spent receiving when timing */
189 	u_int32_t       ifi_xmittiming; /* usec spent xmitting when timing */
190 	struct IF_DATA_TIMEVAL ifi_lastchange;  /* time of last administrative change */
191 	u_int32_t       ifi_unused2;    /* used to be the default_proto */
192 	u_int32_t       ifi_hwassist;   /* HW offload capabilities */
193 	u_int32_t       ifi_reserved1;  /* for future use */
194 	u_int32_t       ifi_reserved2;  /* for future use */
195 };
196 
197 /*
198  * Structure describing information about an interface
199  * which may be of interest to management entities.
200  */
201 struct if_data64 {
202 	/* generic interface information */
203 	u_char          ifi_type;               /* ethernet, tokenring, etc */
204 	u_char          ifi_typelen;            /* Length of frame type id */
205 	u_char          ifi_physical;           /* e.g., AUI, Thinnet, 10base-T, etc */
206 	u_char          ifi_addrlen;            /* media address length */
207 	u_char          ifi_hdrlen;             /* media header length */
208 	u_char          ifi_recvquota;          /* polling quota for receive intrs */
209 	u_char          ifi_xmitquota;          /* polling quota for xmit intrs */
210 	u_char          ifi_unused1;            /* for future use */
211 	u_int32_t       ifi_mtu;                /* maximum transmission unit */
212 	u_int32_t       ifi_metric;             /* routing metric (external only) */
213 	u_int64_t       ifi_baudrate;           /* linespeed */
214 	/* volatile statistics */
215 	u_int64_t       ifi_ipackets;           /* packets received on interface */
216 	u_int64_t       ifi_ierrors;            /* input errors on interface */
217 	u_int64_t       ifi_opackets;           /* packets sent on interface */
218 	u_int64_t       ifi_oerrors;            /* output errors on interface */
219 	u_int64_t       ifi_collisions;         /* collisions on csma interfaces */
220 	u_int64_t       ifi_ibytes;             /* total number of octets received */
221 	u_int64_t       ifi_obytes;             /* total number of octets sent */
222 	u_int64_t       ifi_imcasts;            /* packets received via multicast */
223 	u_int64_t       ifi_omcasts;            /* packets sent via multicast */
224 	u_int64_t       ifi_iqdrops;            /* dropped on input, this interface */
225 	u_int64_t       ifi_noproto;            /* destined for unsupported protocol */
226 	u_int32_t       ifi_recvtiming;         /* usec spent receiving when timing */
227 	u_int32_t       ifi_xmittiming;         /* usec spent xmitting when timing */
228 	struct IF_DATA_TIMEVAL ifi_lastchange;  /* time of last administrative change */
229 };
230 
231 #ifdef PRIVATE
232 /* See if_var_private.h for macros to access some of these fields */
233 #endif /* PRIVATE */
234 
235 #pragma pack()
236 #endif /* DRIVERKIT */
237 
238 #if defined(DRIVERKIT) || defined(PRIVATE) || defined(DRIVERKIT_PRIVATE)
239 #include <net/if_var_status.h>
240 #else
241 struct ifnet_interface_advisory;
242 #endif /* defined(DRIVERKIT) || defined(PRIVATE) || defined(DRIVERKIT_PRIVATE) */
243 
244 #ifndef DRIVERKIT
245 
246 /*
247  * Structure defining a queue for a network interface.
248  */
249 struct  ifqueue {
250 	void    *ifq_head;
251 	void    *ifq_tail;
252 	int     ifq_len;
253 	int     ifq_maxlen;
254 	int     ifq_drops;
255 };
256 
257 #ifdef XNU_KERNEL_PRIVATE
258 /* for uuid.c */
259 __private_extern__ int uuid_get_ethernet(u_int8_t *);
260 #endif /* XNU_KERNEL_PRIVATE */
261 #endif /* DRIVERKIT */
262 
263 #ifdef PRIVATE
264 #include <net/if_var_private.h>
265 #endif /* PRIVATE */
266 
267 #endif /* !_NET_IF_VAR_H_ */
268