1 /* 2 * Copyright (c) 2008-2024 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 * @header kpi_mbuf.h 30 * This header defines an API for interacting with mbufs. mbufs are the 31 * primary method of storing packets in the networking stack. 32 * 33 * mbufs are used to store various items in the networking stack. The 34 * most common usage of an mbuf is to store a packet or data on a 35 * socket waiting to be sent or received. The mbuf is a contiguous 36 * structure with some header followed by some data. To store more data 37 * than would fit in an mbuf, external data is used. Most mbufs with 38 * external data use clusters to store the external data. 39 * 40 * mbufs can be chained, contiguous data in a packet can be found by 41 * following the m_next chain. Packets may be bundled together using 42 * m_nextpacket. Many parts of the stack do not properly handle chains 43 * of packets. When in doubt, don't chain packets. 44 */ 45 46 #ifndef __KPI_MBUF__ 47 #define __KPI_MBUF__ 48 #include <sys/kernel_types.h> 49 #include <mach/vm_types.h> 50 51 #ifndef PRIVATE 52 #include <Availability.h> 53 #define __NKE_API_DEPRECATED __API_DEPRECATED("Network Kernel Extension KPI is deprecated", macos(10.4, 10.15.4)) 54 #else 55 #define __NKE_API_DEPRECATED 56 #endif /* PRIVATE */ 57 58 #ifdef KERNEL_PRIVATE 59 #include <mach/kern_return.h> 60 #endif /* KERNEL_PRIVATE */ 61 62 /*! 63 * @enum mbuf_flags_t 64 * @abstract Constants defining mbuf flags. Only the flags listed below 65 * can be set or retrieved. 66 * @constant MBUF_EXT Indicates this mbuf has external data. 67 * @constant MBUF_PKTHDR Indicates this mbuf has a packet header. 68 * @constant MBUF_EOR Indicates this mbuf is the end of a record. 69 * @constant MBUF_LOOP Indicates this packet is looped back. 70 * @constant MBUF_BCAST Indicates this packet will be sent or was 71 * received as a brodcast. 72 * @constant MBUF_MCAST Indicates this packet will be sent or was 73 * received as a multicast. 74 * @constant MBUF_FRAG Indicates this packet is a fragment of a larger 75 * packet. 76 * @constant MBUF_FIRSTFRAG Indicates this packet is the first fragment. 77 * @constant MBUF_LASTFRAG Indicates this packet is the last fragment. 78 * @constant MBUF_PROMISC Indicates this packet was only received 79 * because the interface is in promiscuous mode. This should be set 80 * by the demux function. These packets will be discarded after 81 * being passed to any interface filters. 82 */ 83 enum { 84 MBUF_EXT = 0x0001, /* has associated external storage */ 85 MBUF_PKTHDR = 0x0002, /* start of record */ 86 MBUF_EOR = 0x0004, /* end of record */ 87 MBUF_LOOP = 0x0040, /* packet is looped back */ 88 89 MBUF_BCAST = 0x0100, /* send/received as link-level broadcast */ 90 MBUF_MCAST = 0x0200, /* send/received as link-level multicast */ 91 MBUF_FRAG = 0x0400, /* packet is a fragment of a larger packet */ 92 MBUF_FIRSTFRAG = 0x0800, /* packet is first fragment */ 93 MBUF_LASTFRAG = 0x1000, /* packet is last fragment */ 94 MBUF_PROMISC = 0x2000, /* packet is promiscuous */ 95 MBUF_HASFCS = 0x4000 /* packet has FCS */ 96 }; 97 typedef u_int32_t mbuf_flags_t; 98 99 /*! 100 * @enum mbuf_type_t 101 * @abstract Types of mbufs. 102 * @discussion Some mbufs represent packets, some represnt data waiting 103 * on sockets. Other mbufs store control data or other various 104 * structures. The mbuf type is used to store what sort of data the 105 * mbuf contains. 106 * @constant MBUF_MT_FREE Indicates the mbuf is free and is 107 * sitting on the queue of free mbufs. If you find that an mbuf you 108 * have a reference to has this type, something has gone terribly 109 * wrong. 110 * @constant MBUF_MT_DATA Indicates this mbuf is being used to store 111 * data. 112 * @constant MBUF_MT_HEADER Indicates this mbuf has a packet header, 113 * this is probably a packet. 114 * @constant MBUF_MT_SOCKET Socket structure. 115 * @constant MBUF_MT_PCB Protocol control block. 116 * @constant MBUF_MT_RTABLE Routing table entry. 117 * @constant MBUF_MT_HTABLE IMP host tables???. 118 * @constant MBUF_MT_ATABLE Address resolution table data. 119 * @constant MBUF_MT_SONAME Socket name, usually a sockaddr of some 120 * sort. 121 * @constant MBUF_MT_FTABLE Fragment reassembly header. 122 * @constant MBUF_MT_RIGHTS Access rights. 123 * @constant MBUF_MT_IFADDR Interface address. 124 * @constant MBUF_MT_CONTROL Extra-data protocol message (control 125 * message). 126 * @constant MBUF_MT_OOBDATA Out of band data. 127 */ 128 enum { 129 MBUF_TYPE_FREE = 0, /* should be on free list */ 130 MBUF_TYPE_DATA = 1, /* dynamic (data) allocation */ 131 MBUF_TYPE_HEADER = 2, /* packet header */ 132 MBUF_TYPE_SOCKET = 3, /* socket structure */ 133 MBUF_TYPE_PCB = 4, /* protocol control block */ 134 MBUF_TYPE_RTABLE = 5, /* routing tables */ 135 MBUF_TYPE_HTABLE = 6, /* IMP host tables */ 136 MBUF_TYPE_ATABLE = 7, /* address resolution tables */ 137 MBUF_TYPE_SONAME = 8, /* socket name */ 138 MBUF_TYPE_SOOPTS = 10, /* socket options */ 139 MBUF_TYPE_FTABLE = 11, /* fragment reassembly header */ 140 MBUF_TYPE_RIGHTS = 12, /* access rights */ 141 MBUF_TYPE_IFADDR = 13, /* interface address */ 142 MBUF_TYPE_CONTROL = 14, /* extra-data protocol message */ 143 MBUF_TYPE_OOBDATA = 15 /* expedited data */ 144 }; 145 typedef u_int32_t mbuf_type_t; 146 147 /*! 148 * @enum mbuf_csum_request_flags_t 149 * @abstract Checksum performed/requested flags. 150 * @discussion Mbufs often contain packets. Some hardware supports 151 * performing checksums in hardware. The stack uses these flags to 152 * indicate to the driver what sort of checksumming should be 153 * handled in by the driver/hardware. These flags will only be set 154 * if the driver indicates that it supports the corresponding 155 * checksums using ifnet_set_offload. 156 * @constant MBUF_CSUM_REQ_IP Indicates the IP checksum has not been 157 * calculated yet. 158 * @constant MBUF_CSUM_REQ_TCP Indicates the TCP checksum has not been 159 * calculated yet. 160 * @constant MBUF_CSUM_REQ_UDP Indicates the UDP checksum has not been 161 * calculated yet. 162 * @constant MBUF_CSUM_REQ_TCPIPV6 Indicates the TCP checksum for IPv6 163 * has not been calculated yet. 164 * @constant MBUF_CSUM_REQ_UDPIPV6 Indicates the UDP checksum for IPv6 165 * has not been calculated yet. 166 */ 167 enum { 168 MBUF_TSO_IPV4 = 0x100000, 169 MBUF_TSO_IPV6 = 0x200000 170 }; 171 typedef u_int32_t mbuf_tso_request_flags_t; 172 173 enum { 174 #ifdef KERNEL_PRIVATE 175 MBUF_CSUM_PARTIAL = 0x1000, /* 16-bit 1's complement sum */ 176 MBUF_CSUM_REQ_SUM16 = MBUF_CSUM_PARTIAL, 177 MBUF_CSUM_REQ_ZERO_INVERT = 0x2000, 178 #endif /* KERNEL_PRIVATE */ 179 MBUF_CSUM_REQ_IP = 0x0001, 180 MBUF_CSUM_REQ_TCP = 0x0002, 181 MBUF_CSUM_REQ_UDP = 0x0004, 182 MBUF_CSUM_REQ_TCPIPV6 = 0x0020, 183 MBUF_CSUM_REQ_UDPIPV6 = 0x0040 184 }; 185 typedef u_int32_t mbuf_csum_request_flags_t; 186 187 /*! 188 * @enum mbuf_csum_performed_flags_t 189 * @abstract Checksum performed/requested flags. 190 * @discussion Mbufs often contain packets. Some hardware supports 191 * performing checksums in hardware. The driver uses these flags to 192 * communicate to the stack the checksums that were calculated in 193 * hardware. 194 * @constant MBUF_CSUM_DID_IP Indicates that the driver/hardware verified 195 * the IP checksum in hardware. 196 * @constant MBUF_CSUM_IP_GOOD Indicates whether or not the IP checksum 197 * was good or bad. Only valid when MBUF_CSUM_DID_IP is set. 198 * @constant MBUF_CSUM_DID_DATA Indicates that the TCP or UDP checksum 199 * was calculated. The value for the checksum calculated in 200 * hardware should be passed as the second parameter of 201 * mbuf_set_csum_performed. The hardware calculated checksum value 202 * can be retrieved using the second parameter passed to 203 * mbuf_get_csum_performed. This should be done for IPv4 or IPv6. 204 * @constant MBUF_CSUM_PSEUDO_HDR If set, this indicates that the 205 * checksum value for MBUF_CSUM_DID_DATA includes the pseudo header 206 * value. If this is not set, the stack will calculate the pseudo 207 * header value and add that to the checksum. The value of this bit 208 * is only valid when MBUF_CSUM_DID_DATA is set. 209 */ 210 enum { 211 #ifdef KERNEL_PRIVATE 212 MBUF_CSUM_TCP_SUM16 = MBUF_CSUM_PARTIAL, 213 #endif /* KERNEL_PRIVATE */ 214 MBUF_CSUM_DID_IP = 0x0100, 215 MBUF_CSUM_IP_GOOD = 0x0200, 216 MBUF_CSUM_DID_DATA = 0x0400, 217 MBUF_CSUM_PSEUDO_HDR = 0x0800 218 }; 219 typedef u_int32_t mbuf_csum_performed_flags_t; 220 221 /*! 222 * @enum mbuf_how_t 223 * @abstract Method of allocating an mbuf. 224 * @discussion Blocking on the input or output path can impact 225 * performance. There are some cases where making a blocking call 226 * is acceptable. When in doubt, use MBUF_DONTWAIT. 227 * @constant MBUF_WAITOK Allow a call to allocate an mbuf to block. 228 * @constant MBUF_DONTWAIT Don't allow the mbuf allocation call to 229 * block, if blocking is necessary fail and return immediately. 230 */ 231 enum { 232 MBUF_WAITOK = 0, /* Ok to block to get memory */ 233 MBUF_DONTWAIT = 1 /* Don't block, fail if blocking would be required */ 234 }; 235 typedef u_int32_t mbuf_how_t; 236 237 typedef u_int32_t mbuf_tag_id_t; 238 typedef u_int16_t mbuf_tag_type_t; 239 240 /*! 241 * @struct mbuf_stat 242 * @discussion The mbuf_stat contains mbuf statistics. 243 * @field mbufs Number of mbufs (free or otherwise). 244 * @field clusters Number of clusters (free or otherwise). 245 * @field clfree Number of free clusters. 246 * @field drops Number of times allocation failed. 247 * @field wait Number of times allocation blocked. 248 * @field drain Number of times protocol drain functions were called. 249 * @field mtypes An array of counts of each type of mbuf allocated. 250 * @field mcfail Number of times m_copym failed. 251 * @field mpfail Number of times m_pullup failed. 252 * @field msize Length of an mbuf. 253 * @field mclbytes Length of an mbuf cluster. 254 * @field minclsize Minimum length of data to allocate a cluster. 255 * Anything smaller than this should be placed in chained mbufs. 256 * @field mlen Length of data in an mbuf. 257 * @field mhlen Length of data in an mbuf with a packet header. 258 * @field bigclusters Number of big clusters. 259 * @field bigclfree Number of unused big clusters. 260 * @field bigmclbytes Length of a big mbuf cluster. 261 */ 262 struct mbuf_stat { 263 u_int32_t mbufs; /* mbufs obtained from page pool */ 264 u_int32_t clusters; /* clusters obtained from page pool */ 265 u_int32_t clfree; /* free clusters */ 266 u_int32_t drops; /* times failed to find space */ 267 u_int32_t wait; /* times waited for space */ 268 u_int32_t drain; /* times drained protocols for space */ 269 u_short mtypes[256]; /* type specific mbuf allocations */ 270 u_int32_t mcfail; /* times m_copym failed */ 271 u_int32_t mpfail; /* times m_pullup failed */ 272 u_int32_t msize; /* length of an mbuf */ 273 u_int32_t mclbytes; /* length of an mbuf cluster */ 274 u_int32_t minclsize; /* min length of data to allocate a cluster */ 275 u_int32_t mlen; /* length of data in an mbuf */ 276 u_int32_t mhlen; /* length of data in a header mbuf */ 277 u_int32_t bigclusters; /* number of big clusters */ 278 u_int32_t bigclfree; /* number of big clustser free */ 279 u_int32_t bigmclbytes; /* length of data in a big cluster */ 280 }; 281 282 /* Parameter for m_copym to copy all bytes */ 283 #define MBUF_COPYALL 1000000000 284 285 __BEGIN_DECLS 286 /* Data access */ 287 /*! 288 * @function mbuf_data 289 * @discussion Returns a pointer to the start of data in this mbuf. 290 * There may be additional data on chained mbufs. The data you're 291 * looking for may not be virtually contiguous if it spans more 292 * than one mbuf. In addition, data that is virtually contiguous 293 * might not be represented by physically contiguous pages; see 294 * further comments in mbuf_data_to_physical. Use mbuf_len to 295 * determine the length of data available in this mbuf. If a data 296 * structure you want to access stradles two mbufs in a chain, 297 * either use mbuf_pullup to get the data contiguous in one mbuf 298 * or copy the pieces of data from each mbuf in to a contiguous 299 * buffer. Using mbuf_pullup has the advantage of not having to 300 * copy the data. On the other hand, if you don't make sure there 301 * is space in the mbuf, mbuf_pullup may fail and free the mbuf. 302 * @param mbuf The mbuf. 303 * @result A pointer to the data in the mbuf. 304 */ 305 extern void *mbuf_data(mbuf_t mbuf) 306 __NKE_API_DEPRECATED; 307 308 /*! 309 * @function mbuf_datastart 310 * @discussion Returns the start of the space set aside for storing 311 * data in an mbuf. An mbuf's data may come from a cluster or be 312 * embedded in the mbuf structure itself. The data pointer 313 * retrieved by mbuf_data may not be at the start of the data 314 * (mbuf_leadingspace will be non-zero). This function will return 315 * a pointer that matches mbuf_data() - mbuf_leadingspace(). 316 * @param mbuf The mbuf. 317 * @result A pointer to smallest possible value for data. 318 */ 319 extern void *mbuf_datastart(mbuf_t mbuf) 320 __NKE_API_DEPRECATED; 321 322 /*! 323 * @function mbuf_setdata 324 * @discussion Sets the data and length values for an mbuf. The data 325 * value must be in a valid range. In the case of an mbuf with a cluster, 326 * the data value must point to a location in the cluster and the data 327 * value plus the length, must be less than the end of the cluster. For 328 * data embedded directly in an mbuf (no cluster), the data value must 329 * fall somewhere between the start and end of the data area in the 330 * mbuf and the data + length must also be in the same range. 331 * @param mbuf The mbuf. 332 * @param data The new pointer value for data. 333 * @param len The new length of data in the mbuf. 334 * @result 0 on success, errno error on failure. 335 */ 336 extern errno_t mbuf_setdata(mbuf_t mbuf, void *data, size_t len) 337 __NKE_API_DEPRECATED; 338 339 /*! 340 * @function mbuf_align_32 341 * @discussion mbuf_align_32 is a replacement for M_ALIGN and MH_ALIGN. 342 * mbuf_align_32 will set the data pointer to a location aligned on 343 * a four byte boundry with at least 'len' bytes between the data 344 * pointer and the end of the data block. 345 * @param mbuf The mbuf. 346 * @param len The minimum length of space that should follow the new 347 * data location. 348 * @result 0 on success, errno error on failure. 349 */ 350 extern errno_t mbuf_align_32(mbuf_t mbuf, size_t len) 351 __NKE_API_DEPRECATED; 352 353 /*! 354 * @function mbuf_data_to_physical 355 * @discussion mbuf_data_to_physical is a replacement for mcl_to_paddr. 356 * Given a pointer returned from mbuf_data of mbuf_datastart, 357 * mbuf_data_to_physical will return the phyical address for that 358 * block of data. Note that even though the data is in virtually 359 * contiguous span, the underlying physical pages might not be 360 * physically contiguous. Because of this, callers must ensure 361 * to call this routine for each page boundary. Device drivers 362 * that deal with DMA are strongly encouraged to utilize the 363 * IOMbufNaturalMemoryCursor and walk down the list of vectors 364 * instead of using this interface to obtain the physical address. 365 * Use of this routine is therefore discouraged. 366 * @param ptr A pointer to data stored in an mbuf. 367 * @result The 64 bit physical address of the mbuf data or NULL if ptr 368 * does not point to data stored in an mbuf. 369 */ 370 extern addr64_t mbuf_data_to_physical(void *ptr) 371 __NKE_API_DEPRECATED; 372 373 374 /* Allocation */ 375 376 /*! 377 * @function mbuf_get 378 * @discussion Allocates an mbuf without a cluster for external data. 379 * @param how Blocking or non-blocking. 380 * @param type The type of the mbuf. 381 * @param mbuf The mbuf. 382 * @result 0 on success, errno error on failure. 383 */ 384 extern errno_t mbuf_get(mbuf_how_t how, mbuf_type_t type, mbuf_t *mbuf) 385 __NKE_API_DEPRECATED; 386 387 /*! 388 * @function mbuf_gethdr 389 * @discussion Allocates an mbuf without a cluster for external data. 390 * Sets a flag to indicate there is a packet header and initializes 391 * the packet header. 392 * @param how Blocking or non-blocking. 393 * @param type The type of the mbuf. 394 * @param mbuf The mbuf. 395 * @result 0 on success, errno error on failure. 396 */ 397 extern errno_t mbuf_gethdr(mbuf_how_t how, mbuf_type_t type, mbuf_t *mbuf) 398 __NKE_API_DEPRECATED; 399 400 /*! 401 * @function mbuf_attachcluster 402 * @discussion Attach an external buffer as a cluster for an mbuf. If mbuf 403 * points to a NULL mbuf_t, an mbuf will be allocated for you. If 404 * mbuf points to a non-NULL mbuf_t, the user-supplied mbuf will 405 * be used instead. The caller is responsible for allocating the 406 * external buffer by calling mbuf_alloccluster(). 407 * @param how Blocking or non-blocking. 408 * @param type The type of the mbuf if mbuf is non-NULL; otherwise ignored. 409 * @param mbuf Pointer to the address of the mbuf; if NULL, an mbuf will 410 * be allocated, otherwise, it must point to a valid mbuf address. 411 * If the user-supplied mbuf is already attached to a cluster, the 412 * current cluster will be freed before the mbuf gets attached to 413 * the supplied external buffer. Note that this routine may return 414 * a different mbuf_t than the one you passed in. 415 * @param extbuf Address of the external buffer. 416 * @param extfree Free routine for the external buffer; the caller is 417 * required to defined a routine that will be invoked when the 418 * mbuf is freed. 419 * @param extsize Size of the external buffer. 420 * @param extarg Private value that will be passed to the free routine 421 * when it is called at the time the mbuf is freed. 422 * @result 0 on success 423 * EINVAL - Invalid parameter 424 * ENOMEM - Not enough memory available 425 */ 426 extern errno_t mbuf_attachcluster(mbuf_how_t how, mbuf_type_t type, 427 mbuf_t *mbuf, caddr_t extbuf __sized_by_or_null(extsize), void (*extfree)(caddr_t, u_int, caddr_t), 428 size_t extsize, caddr_t extarg) 429 __NKE_API_DEPRECATED; 430 431 /*! 432 * @function mbuf_alloccluster 433 * @discussion Allocate a cluster that can be later attached to an 434 * mbuf by calling mbuf_attachcluster(). The allocated cluster 435 * can also be freed (without being attached to an mbuf) by 436 * calling mbuf_freecluster(). At the moment this routine 437 * will either return a cluster of 2048, 4096 or 16384 bytes 438 * depending on the requested size. Note that clusters greater 439 * than 4096 bytes might not be available in all configurations; 440 * the caller must additionally check for ENOTSUP (see below). 441 * @param how Blocking or non-blocking. 442 * @param size Pointer to size of requested cluster. Sizes up to 2048 443 * will be rounded up to 2048; sizes greater than 2048 and up 444 * to 4096 will be rounded up to 4096. Sizes greater than 4096 445 * will be rounded up to 16384. 446 * @param addr Pointer to the address of the requested cluster. 447 * @result 0 on success or ENOMEM if failure. If the caller requests 448 * greater than 4096 bytes and the system is unable to fulfill 449 * the request due to the lack of jumbo clusters support based 450 * on the configuration, this routine will return ENOTSUP. 451 * In this case, the caller is advised to use 4096 bytes or 452 * smaller during subseqent requests. 453 */ 454 extern errno_t mbuf_alloccluster(mbuf_how_t how, size_t *size, char * __sized_by_or_null(*size) * addr) 455 __NKE_API_DEPRECATED; 456 457 /*! 458 * @function mbuf_freecluster 459 * @discussion Free a cluster that was previously allocated by a call 460 * to mbuf_alloccluster(). The caller must pass the actual 461 * size of the cluster as returned by mbuf_alloccluster(), 462 * which at this point must be either 2048, 4096 or 16384 bytes. 463 * @param addr The address of the cluster. 464 * @param size The actual size of the cluster. 465 */ 466 extern void mbuf_freecluster(caddr_t addr, size_t size) 467 __NKE_API_DEPRECATED; 468 469 #ifdef BSD_KERNEL_PRIVATE 470 /* 471 * For now, restrict these to BSD kernel privates, since they are 472 * used only by the Nexus netif compatibility code. 473 */ 474 extern errno_t mbuf_ring_cluster_alloc(mbuf_how_t how, mbuf_type_t type, 475 mbuf_t *mbuf, void (*extfree)(caddr_t, u_int, caddr_t), size_t *size); 476 extern int mbuf_ring_cluster_is_active(mbuf_t mbuf); 477 extern errno_t mbuf_ring_cluster_activate(mbuf_t mbuf); 478 extern errno_t mbuf_cluster_set_prop(mbuf_t mbuf, u_int32_t oldprop, 479 u_int32_t newprop); 480 extern errno_t mbuf_cluster_get_prop(mbuf_t mbuf, u_int32_t *prop); 481 482 #endif /* BSD_KERNEL_PRIVATE */ 483 484 /*! 485 * @function mbuf_getcluster 486 * @discussion Allocate a cluster of the requested size and attach it to 487 * an mbuf for use as external data. If mbuf points to a NULL 488 * mbuf_t, an mbuf will be allocated for you. If mbuf points to 489 * a non-NULL mbuf_t, mbuf_getcluster may return a different 490 * mbuf_t than the one you passed in. 491 * @param how Blocking or non-blocking. 492 * @param type The type of the mbuf. 493 * @param size The size of the cluster to be allocated. Supported sizes 494 * for a cluster are be 2048, 4096, or 16384. Any other value 495 * with return EINVAL. Note that clusters greater than 4096 496 * bytes might not be available in all configurations; the 497 * caller must additionally check for ENOTSUP (see below). 498 * @param mbuf The mbuf the cluster will be attached to. 499 * @result 0 on success, errno error on failure. If you specified NULL 500 * for the mbuf, any intermediate mbuf that may have been allocated 501 * will be freed. If you specify an mbuf value in *mbuf, 502 * mbuf_mclget will not free it. 503 * EINVAL - Invalid parameter 504 * ENOMEM - Not enough memory available 505 * ENOTSUP - The caller had requested greater than 4096 bytes 506 * cluster and the system is unable to fulfill it due to the 507 * lack of jumbo clusters support based on the configuration. 508 * In this case, the caller is advised to use 4096 bytes or 509 * smaller during subsequent requests. 510 */ 511 extern errno_t mbuf_getcluster(mbuf_how_t how, mbuf_type_t type, size_t size, 512 mbuf_t *mbuf) 513 __NKE_API_DEPRECATED; 514 515 /*! 516 * @function mbuf_mclget 517 * @discussion Allocate a cluster and attach it to an mbuf for use as 518 * external data. If mbuf points to a NULL mbuf_t, an mbuf will be 519 * allocated for you. If mbuf points to a non-NULL mbuf_t, 520 * mbuf_mclget may return a different mbuf_t than the one you 521 * passed in. 522 * @param how Blocking or non-blocking. 523 * @param type The type of the mbuf. 524 * @param mbuf The mbuf the cluster will be attached to. 525 * @result 0 on success, errno error on failure. If you specified NULL 526 * for the mbuf, any intermediate mbuf that may have been allocated 527 * will be freed. If you specify an mbuf value in *mbuf, 528 * mbuf_mclget will not free it. 529 */ 530 extern errno_t mbuf_mclget(mbuf_how_t how, mbuf_type_t type, mbuf_t *mbuf) 531 __NKE_API_DEPRECATED; 532 533 /*! 534 * @function mbuf_allocpacket 535 * @discussion Allocate an mbuf chain to store a single packet of the 536 * requested length. According to the requested length, a chain 537 * of mbufs will be created. The mbuf type will be set to 538 * MBUF_TYPE_DATA. The caller may specify the maximum number of 539 * buffer. 540 * @param how Blocking or non-blocking 541 * @param packetlen The total length of the packet mbuf to be allocated. 542 * The length must be greater than zero. 543 * @param maxchunks An input/output pointer to the maximum number of mbufs 544 * segments making up the chain. On input, if maxchunks is NULL, 545 * or the value pointed to by maxchunks is zero, the packet will 546 * be made up of as few or as many buffer segments as necessary 547 * to fit the length. The allocation will fail with ENOBUFS if 548 * the number of segments requested is too small and the sum of 549 * the maximum size of each individual segment is less than the 550 * packet length. On output, if the allocation succeed and 551 * maxchunks is non-NULL, it will point to the actual number 552 * of segments allocated. 553 * Additional notes for packetlen greater than 4096 bytes: 554 * the caller may pass a non-NULL maxchunks and initialize it 555 * with zero such that upon success, it can find out whether 556 * or not the system configuration allows for larger than 557 * 4096 bytes cluster allocations, by checking on the value 558 * pointed to by maxchunks. E.g. a request for 9018 bytes may 559 * result in 1 chunk when jumbo clusters are available, or 560 * 3 chunks otherwise. 561 * @param mbuf Upon success, *mbuf will be a reference to the new mbuf. 562 * @result Returns 0 upon success or the following error code: 563 * EINVAL - Invalid parameter 564 * ENOMEM - Not enough memory available 565 * ENOBUFS - Buffers not big enough for the maximum number of 566 * chunks requested 567 */ 568 extern errno_t mbuf_allocpacket(mbuf_how_t how, size_t packetlen, 569 unsigned int * maxchunks, mbuf_t *mbuf) 570 __NKE_API_DEPRECATED; 571 572 /*! 573 * @function mbuf_allocpacket_list 574 * @discussion Allocate a linked list of packets. According to the 575 * requested length, each packet will made of a chain of one 576 * or more mbufs. The mbuf type will be set to MBUF_TYPE_DATA. 577 * The caller may specify the maximum number of element for 578 * each mbuf chain making up a packet. 579 * @param numpkts Number of packets to allocate 580 * @param how Blocking or non-blocking 581 * @param packetlen The total length of the packet mbuf to be allocated. 582 * The length must be greater than zero. 583 * @param maxchunks An input/output pointer to the maximum number of 584 * mbufs segments making up the chain. On input, if maxchunks is 585 * zero, or the value pointed to by maxchunks is zero, the packet 586 * will be made of as few or as many buffer segments as necessary 587 * to fit the length. The allocation will fail with ENOBUFS if 588 * the number of segments requested is too small and the sum of 589 * the maximum size of each individual segment is less than the 590 * packet length. On output, if the allocation succeed and 591 * maxchunks is non zero, it will point to the actual number 592 * of segments allocated. 593 * Additional notes for packetlen greater than 4096 bytes: 594 * the caller may pass a non-NULL maxchunks and initialize it 595 * with zero such that upon success, it can find out whether 596 * or not the system configuration allows for larger than 597 * 4096 bytes cluster allocations, by checking on the value 598 * pointed to by maxchunks. E.g. a request for 9018 bytes may 599 * result in 1 chunk when jumbo clusters are available, or 600 * 3 chunks otherwise. 601 * @param mbuf Upon success, *mbuf will be a reference to the new mbuf. 602 * @result Returns 0 upon success or the following error code: 603 * EINVAL - Invalid parameter 604 * ENOMEM - Not enough memory available 605 * ENOBUFS - Buffers not big enough for the maximum number of 606 * chunks requested 607 */ 608 extern errno_t mbuf_allocpacket_list(unsigned int numpkts, mbuf_how_t how, 609 size_t packetlen, unsigned int * maxchunks, mbuf_t *mbuf) 610 __NKE_API_DEPRECATED; 611 612 /*! 613 * @function mbuf_getpacket 614 * @discussion Allocate an mbuf, allocate and attach a cluster, and set 615 * the packet header flag. 616 * @param how Blocking or non-blocking. 617 * @param mbuf Upon success, *mbuf will be a reference to the new mbuf. 618 * @result 0 on success, errno error on failure. 619 */ 620 extern errno_t mbuf_getpacket(mbuf_how_t how, mbuf_t *mbuf) 621 __NKE_API_DEPRECATED; 622 623 /*! 624 * @function mbuf_free 625 * @discussion Frees a single mbuf. Not commonly used because it 626 * doesn't touch the rest of the mbufs on the chain. 627 * @param mbuf The mbuf to free. 628 * @result The next mbuf in the chain. 629 */ 630 extern mbuf_t mbuf_free(mbuf_t mbuf) 631 __NKE_API_DEPRECATED; 632 633 /*! 634 * @function mbuf_freem 635 * @discussion Frees a chain of mbufs link through mnext. 636 * @param mbuf The first mbuf in the chain to free. 637 */ 638 extern void mbuf_freem(mbuf_t mbuf) 639 __NKE_API_DEPRECATED; 640 641 /*! 642 * @function mbuf_freem_list 643 * @discussion Frees linked list of mbuf chains. Walks through 644 * mnextpackt and does the equivalent of mbuf_freem to each. 645 * @param mbuf The first mbuf in the linked list to free. 646 * @result The number of mbufs freed. 647 */ 648 extern int mbuf_freem_list(mbuf_t mbuf) 649 __NKE_API_DEPRECATED; 650 651 /*! 652 * @function mbuf_leadingspace 653 * @discussion Determines the space available in the mbuf proceeding 654 * the current data. 655 * @param mbuf The mbuf. 656 * @result The number of unused bytes at the start of the mbuf. 657 */ 658 extern size_t mbuf_leadingspace(const mbuf_t mbuf) 659 __NKE_API_DEPRECATED; 660 661 /*! 662 * @function mbuf_trailingspace 663 * @discussion Determines the space available in the mbuf following 664 * the current data. 665 * @param mbuf The mbuf. 666 * @result The number of unused bytes following the current data. 667 */ 668 extern size_t mbuf_trailingspace(const mbuf_t mbuf) 669 __NKE_API_DEPRECATED; 670 671 /* Manipulation */ 672 673 /*! 674 * @function mbuf_copym 675 * @discussion Copies len bytes from offset from src to a new mbuf. If 676 * the original mbuf contains a packet header, the new mbuf will 677 * contain similar packet header except for any tags which may be 678 * associated with the original mbuf. mbuf_dup() should be used 679 * instead if tags are to be copied to the new mbuf. 680 * @param src The source mbuf. 681 * @param offset The offset in the mbuf to start copying from. 682 * @param len The the number of bytes to copy. 683 * @param how To block or not to block, that is a question. 684 * @param new_mbuf Upon success, the newly allocated mbuf. 685 * @result 0 upon success otherwise the errno error. 686 */ 687 extern errno_t mbuf_copym(const mbuf_t src, size_t offset, size_t len, 688 mbuf_how_t how, mbuf_t *new_mbuf) 689 __NKE_API_DEPRECATED; 690 691 /*! 692 * @function mbuf_dup 693 * @discussion Exactly duplicates an mbuf chain. If the original mbuf 694 * contains a packet header (including tags), the new mbuf will have 695 * the same packet header contents and a copy of each tag associated 696 * with the original mbuf. 697 * @param src The source mbuf. 698 * @param how Blocking or non-blocking. 699 * @param new_mbuf Upon success, the newly allocated mbuf. 700 * @result 0 upon success otherwise the errno error. 701 */ 702 extern errno_t mbuf_dup(const mbuf_t src, mbuf_how_t how, mbuf_t *new_mbuf) 703 __NKE_API_DEPRECATED; 704 705 /*! 706 * @function mbuf_prepend 707 * @discussion Prepend len bytes to an mbuf. If there is space 708 * (mbuf_leadingspace >= len), the mbuf's data ptr is changed and 709 * the same mbuf is returned. If there is no space, a new mbuf may 710 * be allocated and prepended to the mbuf chain. If the operation 711 * fails, the mbuf may be freed (*mbuf will be NULL). 712 * @param mbuf The mbuf to prepend data to. This may change if a new 713 * mbuf must be allocated or may be NULL if the operation fails. 714 * @param len The length, in bytes, to be prepended to the mbuf. 715 * @param how Blocking or non-blocking. 716 * @result 0 upon success otherwise the errno error. 717 */ 718 extern errno_t mbuf_prepend(mbuf_t *mbuf, size_t len, mbuf_how_t how) 719 __NKE_API_DEPRECATED; 720 721 /*! 722 * @function mbuf_split 723 * @discussion Split an mbuf chain at a specific offset. 724 * @param src The mbuf to be split. 725 * @param offset The offset in the buffer where the mbuf should be 726 * split. 727 * @param how Blocking or non-blocking. 728 * @param new_mbuf Upon success, the second half of the split mbuf 729 * chain. 730 * @result 0 upon success otherwise the errno error. In the case of 731 * failure, the original mbuf chain passed in to src will be 732 * preserved. 733 */ 734 extern errno_t mbuf_split(mbuf_t src, size_t offset, mbuf_how_t how, 735 mbuf_t *new_mbuf) 736 __NKE_API_DEPRECATED; 737 738 /*! 739 * @function mbuf_pullup 740 * @discussion Move the next len bytes in to mbuf from other mbufs in 741 * the chain. This is commonly used to get the IP and TCP or UDP 742 * header contiguous in the first mbuf. If mbuf_pullup fails, the 743 * entire mbuf chain will be freed. 744 * @param mbuf The mbuf in the chain the data should be contiguous in. 745 * @param len The number of bytes to pull from the next mbuf(s). 746 * @result 0 upon success otherwise the errno error. In the case of an 747 * error, the mbuf chain has been freed. 748 */ 749 extern errno_t mbuf_pullup(mbuf_t *mbuf, size_t len) 750 __NKE_API_DEPRECATED; 751 752 /*! 753 * @function mbuf_pulldown 754 * @discussion Make length bytes at offset in the mbuf chain 755 * contiguous. Nothing before offset bytes in the chain will be 756 * modified. Upon return, location will be the mbuf the data is 757 * contiguous in and offset will be the offset in that mbuf at 758 * which the data is located. In the case of a failure, the mbuf 759 * chain will be freed. 760 * @param src The start of the mbuf chain. 761 * @param offset Pass in a pointer to a value with the offset of the 762 * data you're interested in making contiguous. Upon success, this 763 * will be overwritten with the offset from the mbuf returned in 764 * location. 765 * @param length The length of data that should be made contiguous. 766 * @param location Upon success, *location will be the mbuf the data is 767 * in. 768 * @result 0 upon success otherwise the errno error. 769 */ 770 extern errno_t mbuf_pulldown(mbuf_t src, size_t *offset, size_t length, 771 mbuf_t *location) 772 __NKE_API_DEPRECATED; 773 774 /*! 775 * @function mbuf_adj 776 * @discussion Trims len bytes from the mbuf. If the length is greater 777 * than zero, the bytes are trimmed from the front of the mbuf. If 778 * the length is less than zero, the bytes are trimmed from the end 779 * of the mbuf chain. 780 * @param mbuf The mbuf chain to trim. 781 * @param len The number of bytes to trim from the mbuf chain. 782 */ 783 extern void mbuf_adj(mbuf_t mbuf, int len) 784 __NKE_API_DEPRECATED; 785 786 /*! 787 * @function mbuf_adjustlen 788 * @discussion Adds amount to the mbuf len. Verifies that the new 789 * length is valid (greater than or equal to zero and less than 790 * maximum amount of data that may be stored in the mbuf). This 791 * function will not adjust the packet header length field or 792 * affect any other mbufs in a chain. 793 * @param mbuf The mbuf to adjust. 794 * @param amount The number of bytes increment the length by. 795 * @result 0 upon success otherwise the errno error. 796 */ 797 extern errno_t mbuf_adjustlen(mbuf_t mbuf, int amount) 798 __NKE_API_DEPRECATED; 799 800 /*! 801 * @function mbuf_concatenate 802 * @discussion Concatenate mbuf chain src to dst using m_next and return 803 * a chain which represents the concatenated chain. The routine 804 * does not prevent two chains of different mbuf types to be 805 * concatenated, nor does it modify any packet header in the 806 * destination chain. Therefore, it's the responsibility of the 807 * caller to ensure that the resulted concatenated mbuf chain is 808 * correct for further usages. 809 * @param dst The destination mbuf chain. 810 * @param src The source mbuf chain. 811 * @result A pointer to the head of the concatenated mbuf chain. This 812 * should be treated as the updated destination mbuf chain; the 813 * caller must no longer refer to the original src or dst mbuf 814 * chain. Otherwise it returns NULL if the original dst mbuf 815 * chain is NULL. 816 */ 817 extern mbuf_t mbuf_concatenate(mbuf_t dst, mbuf_t src) 818 __NKE_API_DEPRECATED; 819 820 /*! 821 * @function mbuf_copydata 822 * @discussion Copies data out of an mbuf in to a specified buffer. If 823 * the data is stored in a chain of mbufs, the data will be copied 824 * from each mbuf in the chain until length bytes have been copied. 825 * @param mbuf The mbuf chain to copy data out of. 826 * @param offset The offset in to the mbuf to start copying. 827 * @param length The number of bytes to copy. 828 * @param out_data A pointer to the location where the data will be 829 * copied. 830 * @result 0 upon success otherwise the errno error. 831 */ 832 extern errno_t mbuf_copydata(const mbuf_t mbuf, size_t offset, size_t length, 833 void *out_data __sized_by_or_null(length)) 834 __NKE_API_DEPRECATED; 835 836 /*! 837 * @function mbuf_copyback 838 * @discussion Copies data from a buffer to an mbuf chain. 839 * mbuf_copyback will grow the chain to fit the specified buffer. 840 * 841 * If mbuf_copydata is unable to allocate enough mbufs to grow the 842 * chain, ENOBUFS will be returned. The mbuf chain will be shorter 843 * than expected but all of the data up to the end of the mbuf 844 * chain will be valid. 845 * 846 * If an offset is specified, mbuf_copyback will skip that many 847 * bytes in the mbuf chain before starting to write the buffer in 848 * to the chain. If the mbuf chain does not contain this many 849 * bytes, mbufs will be allocated to create the space. 850 * @param mbuf The first mbuf in the chain to copy the data in to. 851 * @param offset Offset in bytes to skip before copying data. 852 * @param length The length, in bytes, of the data to copy in to the mbuf 853 * chain. 854 * @param data A pointer to data in the kernel's address space. 855 * @param how Blocking or non-blocking. 856 * @result 0 upon success, EINVAL or ENOBUFS upon failure. 857 */ 858 extern errno_t mbuf_copyback(mbuf_t mbuf, size_t offset, size_t length, 859 const void *data __sized_by_or_null(length), mbuf_how_t how) 860 __NKE_API_DEPRECATED; 861 862 /*! 863 * @function mbuf_mclhasreference 864 * @discussion Check if a cluster of an mbuf is referenced by another mbuf. 865 * References may be taken, for example, as a result of a call to 866 * mbuf_split or mbuf_copym 867 * @param mbuf The mbuf with the cluster to test. 868 * @result 0 if there is no reference by another mbuf, 1 otherwise. 869 */ 870 extern int mbuf_mclhasreference(mbuf_t mbuf) 871 __NKE_API_DEPRECATED; 872 873 874 /* mbuf header */ 875 876 /*! 877 * @function mbuf_next 878 * @discussion Returns the next mbuf in the chain. 879 * @param mbuf The mbuf. 880 * @result The next mbuf in the chain. 881 */ 882 extern mbuf_t mbuf_next(const mbuf_t mbuf) 883 __NKE_API_DEPRECATED; 884 885 /*! 886 * @function mbuf_setnext 887 * @discussion Sets the next mbuf in the chain. 888 * @param mbuf The mbuf. 889 * @param next The new next mbuf. 890 * @result 0 upon success otherwise the errno error. 891 */ 892 extern errno_t mbuf_setnext(mbuf_t mbuf, mbuf_t next) 893 __NKE_API_DEPRECATED; 894 895 /*! 896 * @function mbuf_nextpkt 897 * @discussion Gets the next packet from the mbuf. 898 * @param mbuf The mbuf. 899 * @result The nextpkt. 900 */ 901 extern mbuf_t mbuf_nextpkt(const mbuf_t mbuf) 902 __NKE_API_DEPRECATED; 903 904 /*! 905 * @function mbuf_setnextpkt 906 * @discussion Sets the next packet attached to this mbuf. 907 * @param mbuf The mbuf. 908 * @param nextpkt The new next packet. 909 */ 910 extern void mbuf_setnextpkt(mbuf_t mbuf, mbuf_t nextpkt) 911 __NKE_API_DEPRECATED; 912 913 /*! 914 * @function mbuf_len 915 * @discussion Gets the length of data in this mbuf. 916 * @param mbuf The mbuf. 917 * @result The length. 918 */ 919 extern size_t mbuf_len(const mbuf_t mbuf) 920 __NKE_API_DEPRECATED; 921 922 /*! 923 * @function mbuf_setlen 924 * @discussion Sets the length of data in this packet. Be careful to 925 * not set the length over the space available in the mbuf. 926 * @param mbuf The mbuf. 927 * @param len The new length. 928 */ 929 extern void mbuf_setlen(mbuf_t mbuf, size_t len) 930 __NKE_API_DEPRECATED; 931 932 /*! 933 * @function mbuf_maxlen 934 * @discussion Retrieves the maximum length of data that may be stored 935 * in this mbuf. This value assumes that the data pointer was set 936 * to the start of the possible range for that pointer 937 * (mbuf_data_start). 938 * @param mbuf The mbuf. 939 * @result The maximum lenght of data for this mbuf. 940 */ 941 extern size_t mbuf_maxlen(const mbuf_t mbuf) 942 __NKE_API_DEPRECATED; 943 944 /*! 945 * @function mbuf_type 946 * @discussion Gets the type of mbuf. 947 * @param mbuf The mbuf. 948 * @result The type. 949 */ 950 extern mbuf_type_t mbuf_type(const mbuf_t mbuf) 951 __NKE_API_DEPRECATED; 952 953 /*! 954 * @function mbuf_settype 955 * @discussion Sets the type of mbuf. 956 * @param mbuf The mbuf. 957 * @param new_type The new type. 958 * @result 0 upon success otherwise the errno error. 959 */ 960 extern errno_t mbuf_settype(mbuf_t mbuf, mbuf_type_t new_type) 961 __NKE_API_DEPRECATED; 962 963 /*! 964 * @function mbuf_flags 965 * @discussion Returns the set flags. 966 * @param mbuf The mbuf. 967 * @result The flags. 968 */ 969 extern mbuf_flags_t mbuf_flags(const mbuf_t mbuf) 970 __NKE_API_DEPRECATED; 971 972 /*! 973 * @function mbuf_setflags 974 * @discussion Sets the set of set flags. 975 * @param mbuf The mbuf. 976 * @param flags The flags that should be set, all other flags will be 977 * cleared. Certain flags such as MBUF_EXT cannot be altered. 978 * @result 0 upon success otherwise the errno error. 979 */ 980 extern errno_t mbuf_setflags(mbuf_t mbuf, mbuf_flags_t flags) 981 __NKE_API_DEPRECATED; 982 983 /*! 984 * @function mbuf_setflags_mask 985 * @discussion Useful for setting or clearing individual flags. Easier 986 * than calling mbuf_setflags(m, mbuf_flags(m) | M_FLAG). 987 * @param mbuf The mbuf. 988 * @param flags The flags that should be set or cleared. Certain flags 989 * such as MBUF_EXT cannot be altered. 990 * @param mask The mask controlling which flags will be modified. 991 * @result 0 upon success otherwise the errno error. 992 */ 993 extern errno_t mbuf_setflags_mask(mbuf_t mbuf, mbuf_flags_t flags, 994 mbuf_flags_t mask) 995 __NKE_API_DEPRECATED; 996 997 /*! 998 * @function mbuf_copy_pkthdr 999 * @discussion Copies the packet header from src to dest. 1000 * @param src The mbuf from which the packet header will be copied. 1001 * @param dest The mbuf to which the packet header will be copied. 1002 * @result 0 upon success otherwise the errno error. 1003 */ 1004 extern errno_t mbuf_copy_pkthdr(mbuf_t dest, const mbuf_t src) 1005 __NKE_API_DEPRECATED; 1006 1007 /*! 1008 * @function mbuf_pkthdr_len 1009 * @discussion Returns the length as reported by the packet header. 1010 * @param mbuf The mbuf containing the packet header 1011 * @result The length, in bytes, of the packet. 1012 */ 1013 extern size_t mbuf_pkthdr_len(const mbuf_t mbuf) 1014 __NKE_API_DEPRECATED; 1015 1016 /*! 1017 * @function mbuf_pkthdr_setlen 1018 * @discussion Sets the length of the packet in the packet header. 1019 * @param mbuf The mbuf containing the packet header. 1020 * @param len The new length of the packet. 1021 */ 1022 extern void mbuf_pkthdr_setlen(mbuf_t mbuf, size_t len) 1023 __NKE_API_DEPRECATED; 1024 1025 #ifdef XNU_KERNEL_PRIVATE 1026 /*! 1027 * @function mbuf_pkthdr_maxlen 1028 * @discussion Retrieves the maximum length of data that may be stored 1029 * in this mbuf packet. This value assumes that the data pointer 1030 * was set to the start of the possible range for that pointer 1031 * for each mbuf in the packet chain 1032 * @param mbuf The mbuf. 1033 * @result The maximum lenght of data for this mbuf. 1034 */ 1035 extern size_t mbuf_pkthdr_maxlen(const mbuf_t mbuf); 1036 #endif /* XNU_KERNEL_PRIVATE */ 1037 1038 /*! 1039 * @function mbuf_pkthdr_adjustlen 1040 * @discussion Adjusts the length of the packet in the packet header. 1041 * @param mbuf The mbuf containing the packet header. 1042 * @param amount The number of bytes to adjust the packet header length 1043 * field by. 1044 */ 1045 extern void mbuf_pkthdr_adjustlen(mbuf_t mbuf, int amount) 1046 __NKE_API_DEPRECATED; 1047 1048 /*! 1049 * @function mbuf_pkthdr_rcvif 1050 * @discussion Returns the interface the packet was received on. This 1051 * funciton does not modify the reference count of the interface. 1052 * The interface is only valid for as long as the mbuf is not freed 1053 * and the rcvif for the mbuf is not changed. Take a reference on 1054 * the interface that you will release later before doing any of 1055 * the following: free the mbuf, change the rcvif, pass the mbuf to 1056 * any function that may free the mbuf or change the rcvif. 1057 * @param mbuf The mbuf containing the packet header. 1058 * @result A reference to the interface. 1059 */ 1060 extern ifnet_t mbuf_pkthdr_rcvif(const mbuf_t mbuf) 1061 __NKE_API_DEPRECATED; 1062 1063 /*! 1064 * @function mbuf_pkthdr_setrcvif 1065 * @discussion Sets the interface the packet was received on. 1066 * @param mbuf The mbuf containing the packet header. 1067 * @param ifp A reference to an interface. 1068 * @result 0 upon success otherwise the errno error. 1069 */ 1070 extern errno_t mbuf_pkthdr_setrcvif(mbuf_t mbuf, ifnet_t ifp) 1071 __NKE_API_DEPRECATED; 1072 1073 /*! 1074 * @function mbuf_pkthdr_header 1075 * @discussion Returns a pointer to the packet header. 1076 * @param mbuf The mbuf containing the packet header. 1077 * @result A pointer to the packet header. 1078 */ 1079 extern void *mbuf_pkthdr_header(const mbuf_t mbuf) 1080 __NKE_API_DEPRECATED; 1081 1082 /*! 1083 * @function mbuf_pkthdr_setheader 1084 * @discussion Sets the pointer to the packet header. 1085 * @param mbuf The mbuf containing the packet header. 1086 * @param header A pointer to the header. 1087 */ 1088 extern void mbuf_pkthdr_setheader(mbuf_t mbuf, void *header) 1089 __NKE_API_DEPRECATED; 1090 1091 /* Checksums */ 1092 1093 /*! 1094 * @function mbuf_inbound_modified 1095 * @discussion This function will clear the checksum flags to indicate 1096 * that a hardware checksum should not be used. Any filter 1097 * modifying data should call this function on an mbuf before 1098 * passing the packet up the stack. If a filter modifies a packet 1099 * in a way that affects any checksum, the filter is responsible 1100 * for either modifying the checksum to compensate for the changes 1101 * or verifying the checksum before making the changes and then 1102 * modifying the data and calculating a new checksum only if the 1103 * original checksum was valid. 1104 * @param mbuf The mbuf that has been modified. 1105 */ 1106 extern void mbuf_inbound_modified(mbuf_t mbuf) 1107 __NKE_API_DEPRECATED; 1108 1109 /*! 1110 * @function mbuf_outbound_finalize 1111 * @discussion This function will "finalize" the packet allowing your 1112 * code to inspect the final packet. 1113 * 1114 * There are a number of operations that are performed in hardware, 1115 * such as calculating checksums. This function will perform in 1116 * software the various opterations that were scheduled to be done 1117 * in hardware. Future operations may include IPsec processing or 1118 * vlan support. If you are redirecting a packet to a new interface 1119 * which may not have the same hardware support or encapsulating 1120 * the packet, you should call this function to force the stack to 1121 * calculate and fill out the checksums. This will bypass hardware 1122 * checksums but give you a complete packet to work with. If you 1123 * need to inspect aspects of the packet which may be generated by 1124 * hardware, you must call this function to get an aproximate final 1125 * packet. If you plan to modify the packet in any way, you should 1126 * call this function. 1127 * 1128 * This function should be called before modifying any outbound 1129 * packets. 1130 * 1131 * This function may be called at various levels, in some cases 1132 * additional headers may have already been prepended, such as the 1133 * case of a packet seen by an interface filter. To handle this, 1134 * the caller must pass the protocol family of the packet as well 1135 * as the offset from the start of the packet to the protocol 1136 * header. 1137 * @param mbuf The mbuf that should be finalized. 1138 * @param protocol_family The protocol family of the packet in the 1139 * mbuf. 1140 * @param protocol_offset The offset from the start of the mbuf to the 1141 * protocol header. For an IP packet with an ethernet header, this 1142 * would be the length of an ethernet header. 1143 */ 1144 extern void mbuf_outbound_finalize(mbuf_t mbuf, u_int32_t protocol_family, 1145 size_t protocol_offset) 1146 __NKE_API_DEPRECATED; 1147 1148 /*! 1149 * @function mbuf_set_vlan_tag 1150 * @discussion This function is used by interfaces that support vlan 1151 * tagging in hardware. This function will set properties in the 1152 * mbuf to indicate which vlan the packet was received for. 1153 * @param mbuf The mbuf containing the packet. 1154 * @param vlan The protocol family of the aux data to add. 1155 * @result 0 upon success otherwise the errno error. 1156 */ 1157 extern errno_t mbuf_set_vlan_tag(mbuf_t mbuf, u_int16_t vlan) 1158 __NKE_API_DEPRECATED; 1159 1160 /*! 1161 * @function mbuf_get_vlan_tag 1162 * @discussion This function is used by drivers that support hardware 1163 * vlan tagging to determine which vlan this packet belongs to. To 1164 * differentiate between the case where the vlan tag is zero and 1165 * the case where there is no vlan tag, this function will return 1166 * ENXIO when there is no vlan. 1167 * @param mbuf The mbuf containing the packet. 1168 * @param vlan The protocol family of the aux data to add. 1169 * @result 0 upon success otherwise the errno error. ENXIO indicates 1170 * that the vlan tag is not set. 1171 */ 1172 extern errno_t mbuf_get_vlan_tag(mbuf_t mbuf, u_int16_t *vlan) 1173 __NKE_API_DEPRECATED; 1174 1175 /*! 1176 * @function mbuf_clear_vlan_tag 1177 * @discussion This function will clear any vlan tag associated with 1178 * the mbuf. 1179 * @param mbuf The mbuf containing the packet. 1180 * @result 0 upon success otherwise the errno error. 1181 */ 1182 extern errno_t mbuf_clear_vlan_tag(mbuf_t mbuf) 1183 __NKE_API_DEPRECATED; 1184 1185 #ifdef KERNEL_PRIVATE 1186 /*! 1187 * @function mbuf_set_csum_requested 1188 * @discussion This function is used by the stack to indicate which 1189 * checksums should be calculated in hardware. The stack normally 1190 * sets these flags as the packet is processed in the outbound 1191 * direction. Just before sending the packet to the interface, the 1192 * stack will look at these flags and perform any checksums in 1193 * software that are not supported by the interface. 1194 * @param mbuf The mbuf containing the packet. 1195 * @param request Flags indicating which checksums are being requested 1196 * for this packet. 1197 * @param value This parameter is currently unsupported. 1198 * @result 0 upon success otherwise the errno error. 1199 */ 1200 extern errno_t mbuf_set_csum_requested(mbuf_t mbuf, 1201 mbuf_csum_request_flags_t request, u_int32_t value); 1202 #endif /* KERNEL_PRIVATE */ 1203 1204 /*! 1205 * @function mbuf_get_csum_requested 1206 * @discussion This function is used by the driver to determine which 1207 * checksum operations should be performed in hardware. 1208 * @param mbuf The mbuf containing the packet. 1209 * @param request Flags indicating which checksums are being requested 1210 * for this packet. 1211 * @param value This parameter is currently unsupported. 1212 * @result 0 upon success otherwise the errno error. 1213 */ 1214 extern errno_t mbuf_get_csum_requested(mbuf_t mbuf, 1215 mbuf_csum_request_flags_t *request, u_int32_t *value) 1216 __NKE_API_DEPRECATED; 1217 1218 /*! 1219 * @function mbuf_get_tso_requested 1220 * @discussion This function is used by the driver to determine 1221 * whether TSO should be performed. 1222 * @param mbuf The mbuf containing the packet. 1223 * @param request Flags indicating which TSO offload is requested 1224 * for this packet. 1225 * @param mss The returned MSS. 1226 * @result 0 upon success otherwise the errno error. 1227 */ 1228 extern errno_t mbuf_get_tso_requested(mbuf_t mbuf, 1229 mbuf_tso_request_flags_t *request, u_int32_t *mss) 1230 __NKE_API_DEPRECATED; 1231 1232 1233 #ifdef KERNEL_PRIVATE 1234 1235 enum { 1236 MBUF_GSO_TYPE_NONE = 0, 1237 MBUF_GSO_TYPE_IPV4 = 1, 1238 MBUF_GSO_TYPE_IPV6 = 2, 1239 }; 1240 1241 #define MBUF_GSO_TYPE_NONE MBUF_GSO_TYPE_NONE 1242 1243 typedef uint8_t mbuf_gso_type_t; 1244 1245 /*! 1246 * @function mbuf_get_gso_info 1247 * @discussion This function is used by the driver to determine 1248 * whether segmentation offload (GSO) should be performed. 1249 * @param mbuf The packet to get the offload from. 1250 * @param type The type of offload that is requested for this 1251 * packet (see `mbuf_gso_type_t` above). If none is requested, 1252 * `type` is set to MBUF_GSO_TYPE_NONE. 1253 * `type` must not be NULL. 1254 * @param seg_size The returned segment size. 1255 * `seg_size` must not be NULL. 1256 * @param hdr_len The returned protocol (e.g. IP+TCP) header size, 1257 * `hdr_len` must not be NULL. 1258 * @result 0 upon success otherwise the errno error. 1259 */ 1260 extern errno_t mbuf_get_gso_info(mbuf_t mbuf, mbuf_gso_type_t *type, 1261 uint16_t *seg_size, uint16_t *hdr_len) 1262 __NKE_API_DEPRECATED; 1263 1264 /*! 1265 * @function mbuf_set_gso_info 1266 * @discussion This function is used to set the segmentation 1267 * offload (GSO/TSO) for a packet. 1268 * @param mbuf The packet to set the offload on. 1269 * @param type The type of offload to perform on this packet 1270 * (see `mbuf_gso_type_t` above). Use `MBUF_GSO_TYPE_NONE` 1271 * to clear segmentation offload. 1272 * @param seg_size The segment size. 1273 * @param hdr_len The protocol (e.g. IP+TCP) header size. 1274 * @result 0 upon success otherwise the errno error. 1275 */ 1276 extern errno_t mbuf_set_gso_info(mbuf_t mbuf, 1277 mbuf_gso_type_t type, uint16_t seg_size, uint16_t hdr_len) 1278 __NKE_API_DEPRECATED; 1279 1280 /*! 1281 * @function mbuf_get_lro_info 1282 * @discussion This function is used to retrieve LRO information. 1283 * @param mbuf The mbuf containing the packet. 1284 * @param seg_cnt The number of packets that were coalesced, may be zero. 1285 * If non-zero, will be 2 or greater. 1286 * @param dup_ack_cnt The number of duplicated ACKs (TBD), currently 1287 * always zero. 1288 * @result 0 upon success otherwise the errno error. 1289 */ 1290 extern errno_t mbuf_get_lro_info(mbuf_t mbuf, uint8_t *seg_cnt, 1291 uint8_t *dup_ack_cnt) 1292 __NKE_API_DEPRECATED; 1293 1294 /*! 1295 * @function mbuf_set_lro_info 1296 * @discussion This function is used to set the LRO offload values. 1297 * @param mbuf The mbuf containing the packet. 1298 * @param seg_cnt The number of packets that were coalesced, may be zero. 1299 * If non-zero, must be 2 or greater. 1300 * @param dup_ack_cnt The number of duplicated ACKs (TBD). Must be zero. 1301 * @result 0 upon success otherwise the errno error. 1302 */ 1303 extern errno_t mbuf_set_lro_info(mbuf_t mbuf, uint8_t seg_cnt, 1304 uint8_t dup_ack_cnt) 1305 __NKE_API_DEPRECATED; 1306 1307 #endif /* KERNEL_PRIVATE */ 1308 1309 /*! 1310 * @function mbuf_clear_csum_requested 1311 * @discussion This function clears the checksum request flags. 1312 * @param mbuf The mbuf containing the packet. 1313 * @result 0 upon success otherwise the errno error. 1314 */ 1315 extern errno_t mbuf_clear_csum_requested(mbuf_t mbuf) 1316 __NKE_API_DEPRECATED; 1317 1318 /*! 1319 * @function mbuf_set_csum_performed 1320 * @discussion This is used by the driver to indicate to the stack which 1321 * checksum operations were performed in hardware. 1322 * @param mbuf The mbuf containing the packet. 1323 * @param flags Flags indicating which hardware checksum operations 1324 * were performed. 1325 * @param value If the MBUF_CSUM_DID_DATA flag is set, value should be 1326 * set to the value of the TCP or UDP header as calculated by the 1327 * hardware. 1328 * @result 0 upon success otherwise the errno error. 1329 */ 1330 extern errno_t mbuf_set_csum_performed(mbuf_t mbuf, 1331 mbuf_csum_performed_flags_t flags, u_int32_t value) 1332 __NKE_API_DEPRECATED; 1333 1334 #ifdef KERNEL_PRIVATE 1335 /* 1336 * @function mbuf_get_csum_performed 1337 * @discussion This is used by the stack to determine which checksums 1338 * were calculated in hardware on the inbound path. 1339 * @param mbuf The mbuf containing the packet. 1340 * @param flags Flags indicating which hardware checksum operations 1341 * were performed. 1342 * @param value If the MBUF_CSUM_DID_DATA flag is set, value will be 1343 * set to the value of the TCP or UDP header as calculated by the 1344 * hardware. 1345 * @result 0 upon success otherwise the errno error. 1346 */ 1347 extern errno_t mbuf_get_csum_performed(mbuf_t mbuf, 1348 mbuf_csum_performed_flags_t *flags, u_int32_t *value); 1349 #endif /* KERNEL_PRIVATE */ 1350 1351 /*! 1352 * @function mbuf_get_mlen 1353 * @discussion This routine returns the number of data bytes in a normal 1354 * mbuf, i.e. an mbuf that is not a packet header, nor one with 1355 * an external cluster attached to it. This is equivalent to the 1356 * legacy MLEN macro. 1357 * @result The number of bytes of available data. 1358 */ 1359 extern u_int32_t mbuf_get_mlen(void) 1360 __NKE_API_DEPRECATED; 1361 1362 /*! 1363 * @function mbuf_get_mhlen 1364 * @discussion This routine returns the number of data bytes in a packet 1365 * header mbuf. This is equivalent to the legacy MHLEN macro. 1366 * @result The number of bytes of available data. 1367 */ 1368 extern u_int32_t mbuf_get_mhlen(void) 1369 __NKE_API_DEPRECATED; 1370 1371 /*! 1372 * @function mbuf_get_minclsize 1373 * @discussion This routine returns the minimum number of data bytes 1374 * before an external cluster is used. This is equivalent to the 1375 * legacy MINCLSIZE macro. 1376 * @result The minimum number of bytes before a cluster will be used. 1377 */ 1378 extern u_int32_t mbuf_get_minclsize(void) 1379 __NKE_API_DEPRECATED; 1380 1381 #ifdef XNU_KERNEL_PRIVATE 1382 /* 1383 * @function mbuf_get_minclsize 1384 * @discussion Kernel internal function that returns the size of an mbuf 1385 * @result The size of an mbuf 1386 */ 1387 extern u_int32_t mbuf_get_msize(void); 1388 #endif /* XNU_KERNEL_PRIVATE */ 1389 1390 /*! 1391 * @function mbuf_clear_csum_performed 1392 * @discussion Clears the hardware checksum flags and values. 1393 * @param mbuf The mbuf containing the packet. 1394 * @result 0 upon success otherwise the errno error. 1395 */ 1396 extern errno_t mbuf_clear_csum_performed(mbuf_t mbuf) 1397 __NKE_API_DEPRECATED; 1398 1399 /*! 1400 * @function mbuf_inet_cksum 1401 * @discussion Calculates 16-bit 1's complement Internet checksum of the 1402 * transport segment with or without the pseudo header checksum 1403 * of a given IPv4 packet. If the caller specifies a non-zero 1404 * transport protocol, the checksum returned will also include 1405 * the pseudo header checksum for the corresponding transport 1406 * header. Otherwise, no header parsing will be done and the 1407 * caller may use this to calculate the Internet checksum of 1408 * an arbitrary span of data. 1409 * 1410 * This routine does not modify the contents of the packet. If 1411 * the caller specifies a non-zero protocol and/or offset, the 1412 * routine expects the complete protocol header to be present 1413 * at the beginning of the first mbuf. 1414 * @param mbuf The mbuf (or chain of mbufs) containing the packet. 1415 * @param protocol A zero or non-zero value. A non-zero value specifies 1416 * the transport protocol used for pseudo header checksum. 1417 * @param offset A zero or non-zero value; if the latter, it specifies 1418 * the offset of the transport header from the beginning of mbuf. 1419 * @param length The total (non-zero) length of the transport segment. 1420 * @param csum Pointer to the checksum variable; upon success, this 1421 * routine will return the calculated Internet checksum through 1422 * this variable. The caller must set it to a non-NULL value. 1423 * @result 0 upon success otherwise the errno error. 1424 */ 1425 extern errno_t mbuf_inet_cksum(mbuf_t mbuf, int protocol, u_int32_t offset, 1426 u_int32_t length, u_int16_t *csum) 1427 __NKE_API_DEPRECATED; 1428 1429 /*! 1430 * @function mbuf_inet6_cksum 1431 * @discussion Calculates 16-bit 1's complement Internet checksum of the 1432 * transport segment with or without the pseudo header checksum 1433 * of a given IPv6 packet. If the caller specifies a non-zero 1434 * transport protocol, the checksum returned will also include 1435 * the pseudo header checksum for the corresponding transport 1436 * header. Otherwise, no header parsing will be done and the 1437 * caller may use this to calculate the Internet checksum of 1438 * an arbitrary span of data. 1439 * 1440 * This routine does not modify the contents of the packet. If 1441 * the caller specifies a non-zero protocol and/or offset, the 1442 * routine expects the complete protocol header(s) to be present 1443 * at the beginning of the first mbuf. 1444 * @param mbuf The mbuf (or chain of mbufs) containing the packet. 1445 * @param protocol A zero or non-zero value. A non-zero value specifies 1446 * the transport protocol used for pseudo header checksum. 1447 * @param offset A zero or non-zero value; if the latter, it specifies 1448 * the offset of the transport header from the beginning of mbuf. 1449 * @param length The total (non-zero) length of the transport segment. 1450 * @param csum Pointer to the checksum variable; upon success, this 1451 * routine will return the calculated Internet checksum through 1452 * this variable. The caller must set it to a non-NULL value. 1453 * @result 0 upon success otherwise the errno error. 1454 */ 1455 extern errno_t mbuf_inet6_cksum(mbuf_t mbuf, int protocol, u_int32_t offset, 1456 u_int32_t length, u_int16_t *csum) 1457 __NKE_API_DEPRECATED; 1458 1459 /* mbuf tags */ 1460 1461 /*! 1462 * @function mbuf_tag_id_find 1463 * @discussion Lookup the module id for a string. If there is no module 1464 * id assigned to this string, a new module id will be assigned. 1465 * The string should be the bundle id of the kext. In the case of a 1466 * tag that will be shared across multiple kexts, a common bundle 1467 * id style string should be used. 1468 * 1469 * The lookup operation is not optimized. A module should call this 1470 * function once during startup and chache the module id. The 1471 * module id will not be resassigned until the machine reboots. 1472 * @param module_string A unique string identifying your module. 1473 * Example: com.apple.nke.SharedIP. 1474 * @param module_id Upon return, a unique identifier for use with 1475 * mbuf_tag_* functions. This identifier is valid until the machine 1476 * is rebooted. 1477 * @result 0 upon success otherwise the errno error. 1478 */ 1479 extern errno_t mbuf_tag_id_find(const char *module_string, 1480 mbuf_tag_id_t *module_id) 1481 __NKE_API_DEPRECATED; 1482 1483 /*! 1484 * @function mbuf_tag_allocate 1485 * @discussion Allocate an mbuf tag. Mbuf tags allow various portions 1486 * of the stack to tag mbufs with data that will travel with the 1487 * mbuf through the stack. 1488 * 1489 * Tags may only be added to mbufs with packet headers 1490 * (MBUF_PKTHDR flag is set). Mbuf tags are freed when the mbuf is 1491 * freed or when mbuf_tag_free is called. 1492 * @param mbuf The mbuf to attach this tag to. 1493 * @param module_id A module identifier returned by mbuf_tag_id_find. 1494 * @param type A 16 bit type value. For a given module_id, you can use 1495 * a number of different tag types. 1496 * @param length The length, in bytes, to allocate for storage that 1497 * will be associated with this tag on this mbuf. 1498 * @param how Indicate whether you want to block and wait for memory if 1499 * memory is not immediately available. 1500 * @param data_p Upon successful return, *data_p will point to the 1501 * buffer allocated for the mtag. 1502 * @result 0 upon success otherwise the errno error. 1503 */ 1504 extern errno_t mbuf_tag_allocate(mbuf_t mbuf, mbuf_tag_id_t module_id, 1505 mbuf_tag_type_t type, size_t length, mbuf_how_t how, void **data_p) 1506 __NKE_API_DEPRECATED; 1507 1508 /*! 1509 * @function mbuf_tag_find 1510 * @discussion Find the data associated with an mbuf tag. 1511 * @param mbuf The mbuf the tag is attached to. 1512 * @param module_id A module identifier returned by mbuf_tag_id_find. 1513 * @param type The 16 bit type of the tag to find. 1514 * @param length Upon success, the length of data will be store in 1515 * length. 1516 * @param data_p Upon successful return, *data_p will point to the 1517 * buffer allocated for the mtag. 1518 * @result 0 upon success otherwise the errno error. 1519 */ 1520 extern errno_t mbuf_tag_find(mbuf_t mbuf, mbuf_tag_id_t module_id, 1521 mbuf_tag_type_t type, size_t *length, void **data_p) 1522 __NKE_API_DEPRECATED; 1523 1524 /*! 1525 * @function mbuf_tag_free 1526 * @discussion Frees a previously allocated mbuf tag. 1527 * @param mbuf The mbuf the tag was allocated on. 1528 * @param module_id The ID of the tag to free. 1529 * @param type The type of the tag to free. 1530 */ 1531 extern void mbuf_tag_free(mbuf_t mbuf, mbuf_tag_id_t module_id, 1532 mbuf_tag_type_t type) 1533 __NKE_API_DEPRECATED; 1534 1535 #ifdef KERNEL_PRIVATE 1536 /*! 1537 * @function mbuf_add_drvaux 1538 * @discussion Allocate space for driver auxiliary data and attach it 1539 * to the packet (MBUF_PKTHDR is required.) This space is freed 1540 * when the mbuf is freed or when mbuf_del_drvaux is called. 1541 * Only one instance of driver auxiliary data may be attached to 1542 * a packet. Any attempt to add it to a packet already associated 1543 * with one will yield an error, and the existing one must first 1544 * be removed via mbuf_del_drvaux. The format and length of the 1545 * data depend largely on the family and sub-family. The system 1546 * makes no attempt to define and/or interpret the contents of 1547 * the data, and simply acts as a conduit between its producer 1548 * and consumer. 1549 * @param mbuf The mbuf to attach the auxiliary data to. 1550 * @param how Indicate whether you are willing to block and wait for 1551 * memory, if memory is not immediately available. 1552 * @param family The interface family as defined in net/kpi_interface.h. 1553 * @param subfamily The interface sub-family as defined in 1554 * net/kpi_interface.h. 1555 * @param length The length of the auxiliary data, must be greater than 0. 1556 * @param data_p Upon successful return, *data_p will point to the 1557 * space allocated for the data. Caller may set this to NULL. 1558 * @result 0 upon success otherwise the errno error. 1559 */ 1560 extern errno_t mbuf_add_drvaux(mbuf_t mbuf, mbuf_how_t how, 1561 u_int32_t family, u_int32_t subfamily, size_t length, void **data_p); 1562 1563 /*! 1564 * @function mbuf_find_drvaux 1565 * @discussion Find the driver auxiliary data associated with a packet. 1566 * @param mbuf The mbuf the auxiliary data is attached to. 1567 * @param family_p Upon successful return, *family_p will contain 1568 * the interface family associated with the data, as defined 1569 * in net/kpi_interface.h. Caller may set this to NULL. 1570 * @param subfamily_p Upon successful return, *subfamily_p will contain 1571 * the interface family associated with the data, as defined 1572 * in net/kpi_interface.h. Caller may set this to NULL. 1573 * @param length_p Upon successful return, *length_p will contain 1574 * the length of the driver auxiliary data. Caller may 1575 * set this to NULL. 1576 * @param data_p Upon successful return, *data_p will point to the 1577 * space allocated for the data. 1578 * @result 0 upon success otherwise the errno error. 1579 */ 1580 extern errno_t mbuf_find_drvaux(mbuf_t mbuf, u_int32_t *family_p, 1581 u_int32_t *subfamily_p, u_int32_t *length_p, void **data_p); 1582 1583 /*! 1584 * @function mbuf_del_drvaux 1585 * @discussion Remove and free any driver auxility data associated 1586 * with the packet. 1587 * @param mbuf The mbuf the auxiliary data is attached to. 1588 */ 1589 extern void mbuf_del_drvaux(mbuf_t mbuf); 1590 #endif /* KERNEL_PRIVATE */ 1591 1592 /* mbuf stats */ 1593 1594 /*! 1595 * @function mbuf_stats 1596 * @discussion Get the mbuf statistics. 1597 * @param stats Storage to copy the stats in to. 1598 */ 1599 extern void mbuf_stats(struct mbuf_stat *stats) 1600 __NKE_API_DEPRECATED; 1601 1602 1603 /*! 1604 * @enum mbuf_traffic_class_t 1605 * @abstract Traffic class of a packet 1606 * @discussion Property that represent the category of traffic of a packet. 1607 * This information may be used by the driver and at the link level. 1608 * @constant MBUF_TC_BE Best effort, normal class. 1609 * @constant MBUF_TC_BK Background, low priority or bulk traffic. 1610 * @constant MBUF_TC_VI Interactive video, constant bit rate, low latency. 1611 * @constant MBUF_TC_VO Interactive voice, constant bit rate, lowest latency. 1612 */ 1613 typedef enum { 1614 #ifdef XNU_KERNEL_PRIVATE 1615 MBUF_TC_UNSPEC = -1, /* Internal: not specified */ 1616 #endif 1617 MBUF_TC_BE = 0, 1618 MBUF_TC_BK = 1, 1619 MBUF_TC_VI = 2, 1620 MBUF_TC_VO = 3 1621 #ifdef XNU_KERNEL_PRIVATE 1622 , 1623 MBUF_TC_MAX = 4 /* Internal: traffic class count */ 1624 #endif 1625 } mbuf_traffic_class_t; 1626 1627 /*! 1628 * @function mbuf_get_traffic_class 1629 * @discussion Get the traffic class of an mbuf packet 1630 * @param mbuf The mbuf to get the traffic class of. 1631 * @result The traffic class 1632 */ 1633 extern mbuf_traffic_class_t mbuf_get_traffic_class(mbuf_t mbuf) 1634 __NKE_API_DEPRECATED; 1635 1636 /*! 1637 * @function mbuf_set_traffic_class 1638 * @discussion Set the traffic class of an mbuf packet. 1639 * @param mbuf The mbuf to set the traffic class on. 1640 * @param tc The traffic class 1641 * @result 0 on success, EINVAL if bad parameter is passed 1642 */ 1643 extern errno_t mbuf_set_traffic_class(mbuf_t mbuf, mbuf_traffic_class_t tc) 1644 __NKE_API_DEPRECATED; 1645 1646 /*! 1647 * @function mbuf_is_traffic_class_privileged 1648 * @discussion Returns the privileged status of the traffic class 1649 * of the packet specified by the mbuf. 1650 * @param mbuf The mbuf to retrieve the status from. 1651 * @result Non-zero if privileged, 0 otherwise. 1652 */ 1653 extern int mbuf_is_traffic_class_privileged(mbuf_t mbuf) 1654 __NKE_API_DEPRECATED; 1655 1656 #ifdef KERNEL_PRIVATE 1657 1658 /*! 1659 * @function mbuf_get_traffic_class_max_count 1660 * @discussion Returns the maximum number of mbuf traffic class types 1661 * @result The total count of mbuf traffic classes 1662 */ 1663 extern u_int32_t mbuf_get_traffic_class_max_count(void); 1664 1665 /*! 1666 * @function mbuf_get_traffic_class_index 1667 * @discussion Returns the zero-based index of an mbuf traffic class value 1668 * @param tc The traffic class 1669 * @param index Pointer to the index value 1670 * @result 0 on success, EINVAL if bad parameter is passed 1671 */ 1672 extern errno_t mbuf_get_traffic_class_index(mbuf_traffic_class_t tc, 1673 u_int32_t *index); 1674 1675 /*! 1676 * @enum mbuf_svc_class_t 1677 * @abstract Service class of a packet 1678 * @discussion Property that represents the category of service 1679 * of a packet. This information may be used by the driver 1680 * and at the link level. 1681 * @constant MBUF_SC_BK_SYS "Background System-Initiated", high delay 1682 * tolerant, high loss tolerant, elastic flow, variable size & 1683 * long-lived. 1684 * @constant MBUF_SC_BK "Background", user-initiated, high delay tolerant, 1685 * high loss tolerant, elastic flow, variable size. This level 1686 * corresponds to WMM access class "BG", or MBUF_TC_BK. 1687 * @constant MBUF_SC_BE "Best Effort", unclassified/standard. This is 1688 * the default service class; pretty much a mix of everything. 1689 * This level corresponds to WMM access class "BE" or MBUF_TC_BE. 1690 * @constant MBUF_SC_RD 1691 * "Responsive Data", a notch higher than "Best Effort", medium 1692 * delay tolerant, medium loss tolerant, elastic flow, bursty, 1693 * long-lived. 1694 * @constant MBUF_SC_OAM "Operations, Administration, and Management", 1695 * medium delay tolerant, low-medium loss tolerant, elastic & 1696 * inelastic flows, variable size. 1697 * @constant MBUF_SC_AV "Multimedia Audio/Video Streaming", medium delay 1698 * tolerant, low-medium loss tolerant, elastic flow, constant 1699 * packet interval, variable rate & size. 1700 * @constant MBUF_SC_RV "Responsive Multimedia Audio/Video", low delay 1701 * tolerant, low-medium loss tolerant, elastic flow, variable 1702 * packet interval, rate and size. 1703 * @constant MBUF_SC_VI "Interactive Video", low delay tolerant, low- 1704 * medium loss tolerant, elastic flow, constant packet interval, 1705 * variable rate & size. This level corresponds to WMM access 1706 * class "VI" or MBUF_TC_VI. 1707 * @constant MBUF_SC_SIG "Signaling", low delay tolerant, low loss 1708 * tolerant, inelastic flow, jitter tolerant, rate is bursty but 1709 * short, variable size. e.g. SIP. This level corresponds to WMM 1710 * access class "VI" or MBUF_TC_VI. 1711 * @constant MBUF_SC_VO "Interactive Voice", low delay tolerant, low loss 1712 * tolerant, inelastic flow, constant packet rate, somewhat fixed 1713 * size. This level corresponds to WMM access class "VO" or 1714 * MBUF_TC_VO. 1715 * @constant MBUF_SC_CTL "Network Control", low delay tolerant, low loss 1716 * tolerant, inelastic flow, rate is short & burst, variable size. 1717 */ 1718 typedef enum { 1719 #ifdef XNU_KERNEL_PRIVATE 1720 MBUF_SC_UNSPEC = -1, /* Internal: not specified */ 1721 #endif 1722 MBUF_SC_BK_SYS = 0x00080090, /* lowest class */ 1723 MBUF_SC_BK = 0x00100080, 1724 1725 MBUF_SC_BE = 0x00000000, 1726 MBUF_SC_RD = 0x00180010, 1727 MBUF_SC_OAM = 0x00200020, 1728 1729 MBUF_SC_AV = 0x00280120, 1730 MBUF_SC_RV = 0x00300110, 1731 MBUF_SC_VI = 0x00380100, 1732 MBUF_SC_SIG = 0x00380130, 1733 1734 MBUF_SC_VO = 0x00400180, 1735 MBUF_SC_CTL = 0x00480190, /* highest class */ 1736 } mbuf_svc_class_t; 1737 1738 /*! 1739 * @function mbuf_get_service_class_max_count 1740 * @discussion Returns the maximum number of mbuf service class types. 1741 * @result The total count of mbuf service classes. 1742 */ 1743 extern u_int32_t mbuf_get_service_class_max_count(void); 1744 1745 /*! 1746 * @function mbuf_get_service_class_index 1747 * @discussion Returns the zero-based index of an mbuf service class value 1748 * @param sc The service class 1749 * @param index Pointer to the index value 1750 * @result 0 on success, EINVAL if bad parameter is passed 1751 */ 1752 extern errno_t mbuf_get_service_class_index(mbuf_svc_class_t sc, 1753 u_int32_t *index); 1754 1755 /*! 1756 * @function mbuf_get_service_class 1757 * @discussion Get the service class of an mbuf packet 1758 * @param mbuf The mbuf to get the service class of. 1759 * @result The service class 1760 */ 1761 extern mbuf_svc_class_t mbuf_get_service_class(mbuf_t mbuf); 1762 1763 /*! 1764 * @function mbuf_set_servicec_class 1765 * @discussion Set the service class of an mbuf packet. 1766 * @param mbuf The mbuf to set the service class on. 1767 * @param sc The service class 1768 * @result 0 on success, EINVAL if bad parameter is passed 1769 */ 1770 extern errno_t mbuf_set_service_class(mbuf_t mbuf, mbuf_svc_class_t sc); 1771 1772 /*! 1773 * @function mbuf_is_service_class_privileged 1774 * @discussion Returns the privileged status of the service class 1775 * of the packet specified by the mbuf. 1776 * @param mbuf The mbuf to retrieve the status from. 1777 * @result Non-zero if privileged, 0 otherwise. 1778 */ 1779 extern int mbuf_is_service_class_privileged(mbuf_t mbuf); 1780 1781 /*! 1782 * @enum mbuf_pkthdr_aux_flags_t 1783 * @abstract Constants defining mbuf auxiliary flags. Only the flags 1784 * listed below can be retrieved. 1785 * @constant MBUF_PKTAUXF_INET_RESOLVE_RTR Indicates this is an ARP 1786 * request packet, whose target is the address of the default 1787 * IPv4 router. 1788 * @constant MBUF_PKTAUXF_INET6_RESOLVE_RTR Indicates this is an ICMPv6 1789 * Neighbor Solicitation packet, whose target is the address of 1790 * the default IPv6 router. 1791 */ 1792 enum { 1793 MBUF_PKTAUXF_INET_RESOLVE_RTR = 0x0004, 1794 MBUF_PKTAUXF_INET6_RESOLVE_RTR = 0x0008, 1795 }; 1796 typedef u_int32_t mbuf_pkthdr_aux_flags_t; 1797 1798 /*! 1799 * @function mbuf_pkthdr_aux_flags 1800 * @discussion Returns the auxiliary flags of a packet. 1801 * @param mbuf The mbuf containing the packet header. 1802 * @param paux_flags Pointer to mbuf_pkthdr_aux_flags_t variable. 1803 * @result 0 upon success otherwise the errno error. 1804 */ 1805 extern errno_t mbuf_pkthdr_aux_flags(mbuf_t mbuf, 1806 mbuf_pkthdr_aux_flags_t *paux_flags); 1807 1808 /*! 1809 * @function mbuf_get_driver_scratch 1810 * @discussion Returns a pointer to a driver specific area in the mbuf 1811 * @param m The mbuf whose driver scratch space is to be returned 1812 * @param area A pointer to a location to store the address of the 1813 * driver scratch space. This value is guaranteed to be 32-bit 1814 * aligned. 1815 * @param area_ln A pointer to a location to store the total length of 1816 * the memory location. 1817 */ 1818 extern errno_t mbuf_get_driver_scratch(mbuf_t m, u_int8_t **area, 1819 size_t *area_ln); 1820 1821 /*! 1822 * @function mbuf_get_unsent_data_bytes 1823 * @discussion Returns the amount of data that is waiting to be sent 1824 * on this interface. This is a private SPI used by cellular 1825 * interface as an indication of future activity on that 1826 * interface. 1827 * @param m The mbuf containing the packet header 1828 * @param unsent_data A pointer to an integer where the value of 1829 * unsent data will be set. 1830 * @result 0 upon success otherwise the errno error. If the mbuf 1831 * packet header does not have valid data bytes, the error 1832 * code will be EINVAL 1833 */ 1834 extern errno_t mbuf_get_unsent_data_bytes(const mbuf_t m, 1835 u_int32_t *unsent_data); 1836 1837 typedef struct { 1838 int32_t buf_interface; /* data to send at interface */ 1839 int32_t buf_sndbuf; /* data to send at socket buffer */ 1840 } mbuf_buffer_status_t; 1841 1842 /*! 1843 * @function mbuf_get_buffer_status 1844 * @discussion Returns the amount of data that is waiting to be sent 1845 * on this interface. This is a private SPI used by cellular 1846 * interface as an indication of future activity on that 1847 * interface. 1848 * @param m The mbuf containing the packet header 1849 * @param buf_status A pointer to the structure where the value of 1850 * unsent data will be set. 1851 * @result 0 upon success. If any of the arguments is NULL or if the 1852 * mbuf packet header does not have valid data bytes, 1853 * EINVAL will be returned 1854 */ 1855 extern errno_t mbuf_get_buffer_status(const mbuf_t m, 1856 mbuf_buffer_status_t *buf_status); 1857 1858 /*! 1859 * @function mbuf_pkt_new_flow 1860 * @discussion This function is used to check if the packet is from a 1861 * new flow that can be treated with higher priority. This is 1862 * a private SPI. 1863 * @param m The mbuf containing the packet header 1864 * @param retval A pointer to an integer used as an out argument. The 1865 * value is set to 1 if the packet is from a new flow, 1866 * otherwise it is set to 0. 1867 * @result 0 upon success otherwise the errno error. If any of the 1868 * arguments is NULL or if the mbuf does not have valid packet 1869 * header, the error code will be EINVAL 1870 */ 1871 extern errno_t mbuf_pkt_new_flow(const mbuf_t m, u_int32_t *retval); 1872 1873 /*! 1874 * @function mbuf_last_pkt 1875 * @discussion This function is used to check if the packet is the 1876 * last one sent on a TCP socket. This is an advisory 1877 * for the underlying layers. 1878 * @param m The mbuf containing the packet header 1879 * @param retval A pointer to an integer whose value will be set to 1880 * 1 if the packet is the last packet, otherwise it will 1881 * be set to 0. 1882 * @result 0 upon success otherwise the errno error. If any of the 1883 * arguments is NULL or if the mbuf does not have valid 1884 * packet header, the error code will be EINVAL 1885 */ 1886 extern errno_t mbuf_last_pkt(const mbuf_t m, u_int32_t *retval); 1887 1888 #endif /* KERNEL_PRIVATE */ 1889 1890 #ifdef XNU_KERNEL_PRIVATE 1891 /*! 1892 * @function mbuf_pkt_list_len 1893 * @discussion Retrieves the length of the list of mbuf packets. 1894 * @param mbuf The mbuf. 1895 * @result The length of the mbuf packet list. 1896 */ 1897 extern size_t mbuf_pkt_list_len(const mbuf_t mbuf); 1898 1899 /*! 1900 * @function mbuf_pkt_list_maxlen 1901 * @discussion Retrieves the maximum length of data that may be stored 1902 * in the list of mbuf packet. This value assumes that the data pointer 1903 * was set to the start of the possible range for that pointer 1904 * for each mbuf in the packet chain 1905 * @param mbuf The mbuf. 1906 * @result The maximum length of data for this mbuf. 1907 */ 1908 extern size_t mbuf_pkt_list_maxlen(const mbuf_t mbuf); 1909 #endif /* XNU_KERNEL_PRIVATE */ 1910 1911 #ifdef KERNEL_PRIVATE 1912 /*! 1913 * @function mbuf_get_timestamp 1914 * @discussion Retrieves the timestamp of the packet. 1915 * @param mbuf The mbuf representing the packet. 1916 * @param ts A pointer where the value of the timestamp will be copied 1917 * to. 1918 * @param valid A pointer to a boolean value that indicate if the 1919 * timestamp is valid (i.e. the packet timestamp has been set). 1920 * If "false" the value of "ts" is undetermined. 1921 * @result 0 upon success otherwise the errno error. If the mbuf 1922 * packet header does not have valid data bytes, the error 1923 * code will be EINVAL 1924 */ 1925 extern errno_t mbuf_get_timestamp(mbuf_t mbuf, u_int64_t *ts, boolean_t *valid); 1926 1927 /*! 1928 * @function mbuf_set_timestamp 1929 * @discussion Set the timestamp of the packet. 1930 * @param mbuf The mbuf representing the packet. 1931 * @param ts The value of the timestamp to be stored in the mbuf packet 1932 * header 1933 * @param valid A boolean value that indicate if the timestamp is valid. 1934 * Passing false clears any previous timestamp value. 1935 * @result 0 upon success otherwise the errno error. If the mbuf 1936 * packet header does not have valid data bytes, the error 1937 * code will be EINVAL 1938 */ 1939 extern errno_t mbuf_set_timestamp(mbuf_t mbuf, u_int64_t ts, boolean_t valid); 1940 1941 /*! 1942 * @typedef mbuf_tx_compl_func 1943 * @discussion This callback is used to indicate when a driver has 1944 * transmitted a packet. 1945 * @param pktid The packet indentifier that was returned by 1946 * mbuf_set_timestamp_requested() 1947 * @param ifp The outgoing interface or NULL if the packet was dropped 1948 * before reaching the driver 1949 * @param ts The timestamp in nanoseconds when the packet was transmitted 1950 * @param tx_compl_arg An argument set by the driver 1951 * @param tx_compl_data Additional data set by the driver 1952 * @param tx_compl_val The transmission status is expected to be an 1953 * IOReturn value -- see <IOKit/IOReturn.h> 1954 */ 1955 1956 typedef void (*mbuf_tx_compl_func)(uintptr_t pktid, ifnet_t ifp, u_int64_t ts, 1957 uintptr_t tx_compl_arg, uintptr_t tx_compl_data, kern_return_t tx_compl_val); 1958 1959 /*! 1960 * @function mbuf_register_tx_compl_callback 1961 * @discussion Register a transmit completion callback function. The 1962 * callback function must be unregistered before the calling 1963 * module unloads. 1964 * @param callback The completion callback function to register 1965 * @result 0 upon success otherwise the errno error. ENOSPC is returned 1966 * if too many callbacks are registered. EINVAL is returned when 1967 * the function pointer is invalid. EEXIST is returned when 1968 * the function pointer is already registered. 1969 */ 1970 extern errno_t mbuf_register_tx_compl_callback( 1971 mbuf_tx_compl_func callback); 1972 1973 /*! 1974 * @function mbuf_unregister_tx_compl_callback 1975 * @discussion Unregister a transmit completion callback function. The 1976 * callback function must be unregistered before the calling 1977 * module unloads. 1978 * @param callback The completion callback function to unregister 1979 * @result 0 upon success otherwise the errno error. EINVAL is returned 1980 * when the function pointer is invalid. ENOENT is returned when 1981 * the function pointer is not registered. 1982 */ 1983 extern errno_t mbuf_unregister_tx_compl_callback( 1984 mbuf_tx_compl_func callback); 1985 1986 /*! 1987 * @function mbuf_get_timestamp_requested 1988 * @discussion Tell if the packet timestamp needs to be set. This is meant 1989 * to be used by a driver on egress packets. 1990 * @param mbuf The mbuf representing the packet. 1991 * @param requested A pointer to a boolean value that indicate if the 1992 * timestamp was requested to be set. 1993 * @result 0 upon success otherwise the errno error. If the mbuf 1994 * packet header does not have valid data bytes, the error 1995 * code will be EINVAL 1996 */ 1997 extern errno_t mbuf_get_timestamp_requested(mbuf_t mbuf, boolean_t *requested); 1998 1999 /*! 2000 * @function mbuf_set_timestamp_requested 2001 * @discussion Indicate the callback is expected to be called with the 2002 * transmission complete timestamp. This is meant to be used 2003 * on egress packet by the driver. 2004 * @param mbuf The mbuf representing the packet. 2005 * @param callback A previously registered completion callback function. 2006 * @param pktid An output parameter with an opaque value that can be used 2007 * to identify the packet. 2008 * @result 0 upon success otherwise the errno error. EINVAL is retuned 2009 * if the mbuf is not a valid packet or if one of the parameter 2010 * is NULL. ENOENT if the callback is not registred. 2011 */ 2012 extern errno_t mbuf_set_timestamp_requested(mbuf_t mbuf, 2013 uintptr_t *pktid, mbuf_tx_compl_func callback); 2014 2015 /*! 2016 * @function mbuf_get_status 2017 * @discussion Retrieves the packet completion status. 2018 * @param mbuf The mbuf representing the packet. 2019 * @param status A pointer where the value of the completion status will 2020 * be copied to. 2021 * @result 0 upon success otherwise the errno error. If the mbuf 2022 * packet header does not have valid data bytes, the error 2023 * code will be EINVAL 2024 */ 2025 extern errno_t mbuf_get_status(mbuf_t mbuf, kern_return_t *status); 2026 2027 /*! 2028 * @function mbuf_set_status 2029 * @discussion Store the packet completion status in the mbuf packet 2030 * header. 2031 * @param mbuf The mbuf representing the packet. 2032 * @param status The value of the completion status. 2033 * @result 0 upon success otherwise the errno error. If the mbuf 2034 * packet header does not have valid data bytes, the error 2035 * code will be EINVAL 2036 */ 2037 extern errno_t mbuf_set_status(mbuf_t mbuf, kern_return_t status); 2038 2039 /*! 2040 * @function mbuf_get_tx_compl_data 2041 * @discussion Retrieves the packet completion status. 2042 * @param m The mbuf representing the packet. 2043 * @result 0 upon success otherwise the errno error. If the mbuf 2044 * packet header does not have valid data bytes, the error 2045 * code will be EINVAL 2046 */ 2047 extern errno_t mbuf_get_tx_compl_data(mbuf_t m, uintptr_t *arg, 2048 uintptr_t *data); 2049 2050 /*! 2051 * @function mbuf_set_tx_compl_data 2052 * @discussion Retrieves the packet completion status. 2053 * @param m The mbuf representing the packet. 2054 * @result 0 upon success otherwise the errno error. If the mbuf 2055 * packet header does not have valid data bytes, the error 2056 * code will be EINVAL 2057 */ 2058 extern errno_t mbuf_set_tx_compl_data(mbuf_t m, uintptr_t arg, 2059 uintptr_t data); 2060 2061 /*! 2062 * @function mbuf_get_flowid 2063 * @discussion Retrieve the flow ID of the packet . 2064 * @param mbuf The mbuf representing the packet. 2065 * @param flowid The flow ID of the packet. 2066 * @result 0 upon success otherwise the errno error. If the mbuf 2067 * packet header does not have valid data bytes, the error 2068 * code will be EINVAL 2069 */ 2070 extern errno_t mbuf_get_flowid(mbuf_t mbuf, u_int16_t *flowid); 2071 2072 /*! 2073 * @function mbuf_set_flowid 2074 * @discussion Set the flow ID of the packet . 2075 * @param mbuf The mbuf representing the packet. 2076 * @param flowid The flow ID to be set. 2077 * @result 0 upon success otherwise the errno error. If the mbuf 2078 * packet header does not have valid data bytes, the error 2079 * code will be EINVAL 2080 */ 2081 extern errno_t mbuf_set_flowid(mbuf_t mbuf, u_int16_t flowid); 2082 2083 /*! 2084 * @function mbuf_get_keepalive_flag 2085 * @discussion Tell if it's a keep alive packet. 2086 * @param mbuf The mbuf representing the packet. 2087 * @param is_keepalive A pointer that returns the truth value. 2088 * @result 0 upon success otherwise the errno error. If the mbuf 2089 * packet header does not have valid data bytes, the error 2090 * code will be EINVAL 2091 */ 2092 extern errno_t mbuf_get_keepalive_flag(mbuf_t mbuf, boolean_t *is_keepalive); 2093 2094 /*! 2095 * @function mbuf_set_keepalive_flag 2096 * @discussion Set or clear the packet keep alive flag. 2097 * @param mbuf The mbuf representing the packet. 2098 * @param is_keepalive The boolean value. 2099 * @result 0 upon success otherwise the errno error. If the mbuf 2100 * packet header does not have valid data bytes, the error 2101 * code will be EINVAL 2102 */ 2103 extern errno_t mbuf_set_keepalive_flag(mbuf_t mbuf, boolean_t is_keepalive); 2104 2105 /*! 2106 * @function mbuf_get_wake_packet_flag 2107 * @discussion Tell if the wake packet flag is set. 2108 * @param mbuf The mbuf representing the packet. 2109 * @param is_wake_packet A pointer that returns the truth value. 2110 * @result 0 upon success otherwise the errno error. If the mbuf 2111 * packet header does not have valid data bytes, the error 2112 * code will be EINVAL. 2113 */ 2114 extern errno_t mbuf_get_wake_packet_flag(mbuf_t mbuf, boolean_t *is_wake_packet); 2115 2116 /*! 2117 * @function mbuf_set_wake_packet_flag 2118 * @discussion Set or clear the wake packet flag. 2119 * @param mbuf The mbuf representing the packet. 2120 * @param is_wake_packet The boolean value. 2121 * @result 0 upon success otherwise the errno error. If the mbuf 2122 * packet header does not have valid data bytes, the error 2123 * code will be EINVAL. 2124 */ 2125 extern errno_t mbuf_set_wake_packet_flag(mbuf_t mbuf, boolean_t is_wake_packet); 2126 2127 #endif /* KERNEL_PRIVATE */ 2128 2129 /* IF_QUEUE interaction */ 2130 2131 #define IF_ENQUEUE_MBUF(ifq, m) { \ 2132 mbuf_setnextpkt((m), 0); \ 2133 if ((ifq)->ifq_tail == 0) \ 2134 (ifq)->ifq_head = (m); \ 2135 else \ 2136 mbuf_setnextpkt((mbuf_t)(ifq)->ifq_tail, (m)); \ 2137 (ifq)->ifq_tail = (m); \ 2138 (ifq)->ifq_len++; \ 2139 } 2140 2141 #define IF_PREPEND_MBUF(ifq, m) { \ 2142 mbuf_setnextpkt((m), (ifq)->ifq_head); \ 2143 if ((ifq)->ifq_tail == 0) \ 2144 (ifq)->ifq_tail = (m); \ 2145 (ifq)->ifq_head = (m); \ 2146 (ifq)->ifq_len++; \ 2147 } 2148 2149 #define IF_DEQUEUE_MBUF(ifq, m) { \ 2150 (m) = (ifq)->ifq_head; \ 2151 if (m) { \ 2152 if (((ifq)->ifq_head = mbuf_nextpkt((m))) == 0) \ 2153 (ifq)->ifq_tail = 0; \ 2154 mbuf_setnextpkt((m), 0); \ 2155 (ifq)->ifq_len--; \ 2156 } \ 2157 } 2158 2159 __END_DECLS 2160 #undef __NKE_API_DEPRECATED 2161 #endif /* __KPI_MBUF__ */ 2162