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 #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 BSD_KERN_PRIVATE 73 #include <net/pktsched/pktsched.h> 74 #include <sys/eventhandler.h> 75 #endif 76 77 78 #ifdef __APPLE__ 79 #define APPLE_IF_FAM_LOOPBACK 1 80 #define APPLE_IF_FAM_ETHERNET 2 81 #define APPLE_IF_FAM_SLIP 3 82 #define APPLE_IF_FAM_TUN 4 83 #define APPLE_IF_FAM_VLAN 5 84 #define APPLE_IF_FAM_PPP 6 85 #define APPLE_IF_FAM_PVC 7 86 #define APPLE_IF_FAM_DISC 8 87 #define APPLE_IF_FAM_MDECAP 9 88 #define APPLE_IF_FAM_GIF 10 89 #define APPLE_IF_FAM_FAITH 11 /* deprecated */ 90 #define APPLE_IF_FAM_STF 12 91 #define APPLE_IF_FAM_FIREWIRE 13 92 #define APPLE_IF_FAM_BOND 14 93 #define APPLE_IF_FAM_CELLULAR 15 94 #define APPLE_IF_FAM_6LOWPAN 16 95 #define APPLE_IF_FAM_UTUN 17 96 #define APPLE_IF_FAM_IPSEC 18 97 #endif /* __APPLE__ */ 98 99 /* 100 * 72 was chosen below because it is the size of a TCP/IP 101 * header (40) + the minimum mss (32). 102 */ 103 #define IF_MINMTU 72 104 #define IF_MAXMTU 65535 105 106 /* 107 * Structures defining a network interface, providing a packet 108 * transport mechanism (ala level 0 of the PUP protocols). 109 * 110 * Each interface accepts output datagrams of a specified maximum 111 * length, and provides higher level routines with input datagrams 112 * received from its medium. 113 * 114 * Output occurs when the routine if_output is called, with three parameters: 115 * (*ifp->if_output)(ifp, m, dst, rt) 116 * Here m is the mbuf chain to be sent and dst is the destination address. 117 * The output routine encapsulates the supplied datagram if necessary, 118 * and then transmits it on its medium. 119 * 120 * On input, each interface unwraps the data received by it, and either 121 * places it on the input queue of a internetwork datagram routine 122 * and posts the associated software interrupt, or passes the datagram to a raw 123 * packet input routine. 124 * 125 * Routines exist for locating interfaces by their addresses 126 * or for locating a interface on a certain network, as well as more general 127 * routing and gateway routines maintaining information used to locate 128 * interfaces. These routines live in the files if.c and route.c 129 */ 130 131 #define IFNAMSIZ 16 132 133 /* This belongs up in socket.h or socketvar.h, depending on how far the 134 * event bubbles up. 135 */ 136 137 struct net_event_data { 138 u_int32_t if_family; 139 u_int32_t if_unit; 140 char if_name[IFNAMSIZ]; 141 }; 142 143 #if defined(__LP64__) 144 #include <sys/_types/_timeval32.h> 145 #define IF_DATA_TIMEVAL timeval32 146 #else 147 #define IF_DATA_TIMEVAL timeval 148 #endif 149 150 #pragma pack(4) 151 152 /* 153 * Structure describing information about an interface 154 * which may be of interest to management entities. 155 */ 156 struct if_data { 157 /* generic interface information */ 158 u_char ifi_type; /* ethernet, tokenring, etc */ 159 u_char ifi_typelen; /* Length of frame type id */ 160 u_char ifi_physical; /* e.g., AUI, Thinnet, 10base-T, etc */ 161 u_char ifi_addrlen; /* media address length */ 162 u_char ifi_hdrlen; /* media header length */ 163 u_char ifi_recvquota; /* polling quota for receive intrs */ 164 u_char ifi_xmitquota; /* polling quota for xmit intrs */ 165 u_char ifi_unused1; /* for future use */ 166 u_int32_t ifi_mtu; /* maximum transmission unit */ 167 u_int32_t ifi_metric; /* routing metric (external only) */ 168 u_int32_t ifi_baudrate; /* linespeed */ 169 /* volatile statistics */ 170 u_int32_t ifi_ipackets; /* packets received on interface */ 171 u_int32_t ifi_ierrors; /* input errors on interface */ 172 u_int32_t ifi_opackets; /* packets sent on interface */ 173 u_int32_t ifi_oerrors; /* output errors on interface */ 174 u_int32_t ifi_collisions; /* collisions on csma interfaces */ 175 u_int32_t ifi_ibytes; /* total number of octets received */ 176 u_int32_t ifi_obytes; /* total number of octets sent */ 177 u_int32_t ifi_imcasts; /* packets received via multicast */ 178 u_int32_t ifi_omcasts; /* packets sent via multicast */ 179 u_int32_t ifi_iqdrops; /* dropped on input, this interface */ 180 u_int32_t ifi_noproto; /* destined for unsupported protocol */ 181 u_int32_t ifi_recvtiming; /* usec spent receiving when timing */ 182 u_int32_t ifi_xmittiming; /* usec spent xmitting when timing */ 183 struct IF_DATA_TIMEVAL ifi_lastchange; /* time of last administrative change */ 184 u_int32_t ifi_unused2; /* used to be the default_proto */ 185 u_int32_t ifi_hwassist; /* HW offload capabilities */ 186 u_int32_t ifi_reserved1; /* for future use */ 187 u_int32_t ifi_reserved2; /* for future use */ 188 }; 189 190 /* 191 * Structure describing information about an interface 192 * which may be of interest to management entities. 193 */ 194 struct if_data64 { 195 /* generic interface information */ 196 u_char ifi_type; /* ethernet, tokenring, etc */ 197 u_char ifi_typelen; /* Length of frame type id */ 198 u_char ifi_physical; /* e.g., AUI, Thinnet, 10base-T, etc */ 199 u_char ifi_addrlen; /* media address length */ 200 u_char ifi_hdrlen; /* media header length */ 201 u_char ifi_recvquota; /* polling quota for receive intrs */ 202 u_char ifi_xmitquota; /* polling quota for xmit intrs */ 203 u_char ifi_unused1; /* for future use */ 204 u_int32_t ifi_mtu; /* maximum transmission unit */ 205 u_int32_t ifi_metric; /* routing metric (external only) */ 206 u_int64_t ifi_baudrate; /* linespeed */ 207 /* volatile statistics */ 208 u_int64_t ifi_ipackets; /* packets received on interface */ 209 u_int64_t ifi_ierrors; /* input errors on interface */ 210 u_int64_t ifi_opackets; /* packets sent on interface */ 211 u_int64_t ifi_oerrors; /* output errors on interface */ 212 u_int64_t ifi_collisions; /* collisions on csma interfaces */ 213 u_int64_t ifi_ibytes; /* total number of octets received */ 214 u_int64_t ifi_obytes; /* total number of octets sent */ 215 u_int64_t ifi_imcasts; /* packets received via multicast */ 216 u_int64_t ifi_omcasts; /* packets sent via multicast */ 217 u_int64_t ifi_iqdrops; /* dropped on input, this interface */ 218 u_int64_t ifi_noproto; /* destined for unsupported protocol */ 219 u_int32_t ifi_recvtiming; /* usec spent receiving when timing */ 220 u_int32_t ifi_xmittiming; /* usec spent xmitting when timing */ 221 struct IF_DATA_TIMEVAL ifi_lastchange; /* time of last administrative change */ 222 }; 223 224 225 #if defined (PRIVATE) || defined (DRIVERKIT_PRIVATE) 226 /* 227 * This structure is used to define the parameters for advisory notifications 228 * on an interface. 229 */ 230 #pragma pack(push, 1) 231 struct ifnet_interface_advisory { 232 /* The current structure version */ 233 uint8_t version; 234 #define IF_INTERFACE_ADVISORY_VERSION_1 0x1 235 #define IF_INTERFACE_ADVISORY_VERSION_CURRENT IF_INTERFACE_ADVISORY_VERSION_1 236 /* Specifies if the advisory is for transmit or receive path */ 237 uint8_t direction; 238 #define IF_INTERFACE_ADVISORY_DIRECTION_TX 0x1 239 #define IF_INTERFACE_ADVISORY_DIRECTION_RX 0x2 240 /* reserved for future use */ 241 uint16_t _reserved; 242 /* 243 * suggestion for data rate change to keep the latency low. 244 * unit: bits per second (bps) 245 * NOTE: if the interface cannot provide suggestions in terms of bps, 246 * it should use the following values: 247 * INT32_MAX : ramp up 248 * INT32_MIN : ramp down 249 * 0 : neutral 250 */ 251 #define IF_INTERFACE_ADVISORY_RATE_SUGGESTION_RAMP_UP INT32_MAX 252 #define IF_INTERFACE_ADVISORY_RATE_SUGGESTION_RAMP_DOWN INT32_MIN 253 #define IF_INTERFACE_ADVISORY_RATE_SUGGESTION_RAMP_NEUTRAL 0 254 int32_t rate_trend_suggestion; 255 /* 256 * Time of the issue of advisory. 257 * Timestamp should be in the host domain. 258 * unit: mach absolute time 259 */ 260 uint64_t timestamp; 261 /* 262 * Maximum theoretical bandwidth of the interface. 263 * unit: bits per second (bps) 264 */ 265 uint64_t max_bandwidth; 266 /* 267 * Total bytes sent or received on the interface. 268 * wrap around possible and the application should account for that. 269 * unit: byte 270 */ 271 uint64_t total_byte_count; 272 /* 273 * average throughput observed at the driver stack. 274 * unit: bits per second (bps) 275 */ 276 uint64_t average_throughput; 277 /* 278 * flushable queue size at the driver. 279 * should be set to UINT32_MAX if not available. 280 * unit: byte 281 */ 282 uint32_t flushable_queue_size; 283 /* 284 * non flushable queue size at the driver. 285 * should be set to UINT32_MAX if not available. 286 * unit: byte 287 */ 288 uint32_t non_flushable_queue_size; 289 /* 290 * average delay observed at the interface. 291 * unit: milliseconds (ms) 292 */ 293 uint32_t average_delay; 294 /* 295 * Current frequency band (enumeration). 296 */ 297 #define IF_INTERFACE_ADVISORY_FREQ_BAND_NOT_AVAIL 0 298 #define IF_INTERFACE_ADVISORY_FREQ_BAND_WIFI_24GHZ 1 299 #define IF_INTERFACE_ADVISORY_FREQ_BAND_WIFI_5GHZ 2 300 #define IF_INTERFACE_ADVISORY_FREQ_BAND_WIFI_6GHZ 3 301 uint8_t frequency_band; 302 /* 303 * Intermittent WiFi state [true(1)/false(0)] 304 */ 305 uint8_t intermittent_state; 306 /* 307 * Estimated period for which intermittent state is expected to last. 308 * 1 tick -> 1 ms UNDEF => UINT16_MAX 309 */ 310 uint16_t estimated_intermittent_period; 311 /* 312 * Expected wifi outage period during intermittent state 313 * 1 tick -> 1 ms UNDEF => UINT16_MAX 314 */ 315 uint16_t single_outage_period; 316 317 /* 318 * WiFi-BT coexistence, 1-ON, 0-OFF 319 */ 320 uint8_t bt_coex; 321 /* 322 * on scale of 1 to 5 323 */ 324 uint8_t quality_score_delay; 325 /* 326 * on scale of 1 to 5 327 */ 328 uint8_t quality_score_loss; 329 /* 330 * on scale of 1 to 5 331 */ 332 uint8_t quality_score_channel; 333 } __attribute__((aligned(sizeof(uint64_t)))); 334 #pragma pack(pop) 335 336 #else 337 338 struct ifnet_interface_advisory; 339 340 #endif /* defined (PRIVATE) || defined (DRIVERKIT_PRIVATE) */ 341 342 343 #pragma pack() 344 345 /* 346 * Structure defining a queue for a network interface. 347 */ 348 struct ifqueue { 349 void *ifq_head; 350 void *ifq_tail; 351 int ifq_len; 352 int ifq_maxlen; 353 int ifq_drops; 354 }; 355 356 357 358 359 360 361 #endif /* !_NET_IF_VAR_H_ */