X-Git-Url: https://git.saurik.com/apple/xnu.git/blobdiff_plain/91447636331957f3d9b5ca5b508f07c526b0074d..7ee9d059c4eecf68ae4f8b0fb99ae2471eda79af:/bsd/sys/kpi_mbuf.h diff --git a/bsd/sys/kpi_mbuf.h b/bsd/sys/kpi_mbuf.h index 5a1d26d8e..24239b9f4 100644 --- a/bsd/sys/kpi_mbuf.h +++ b/bsd/sys/kpi_mbuf.h @@ -1,36 +1,42 @@ /* - * Copyright (c) 2004 Apple Computer, Inc. All rights reserved. + * Copyright (c) 2008-2010 Apple Inc. All rights reserved. * - * @APPLE_LICENSE_HEADER_START@ + * @APPLE_OSREFERENCE_LICENSE_HEADER_START@ * - * The contents of this file constitute Original Code as defined in and - * are subject to the Apple Public Source License Version 1.1 (the - * "License"). You may not use this file except in compliance with the - * License. Please obtain a copy of the License at - * http://www.apple.com/publicsource and read it before using this file. + * This file contains Original Code and/or Modifications of Original Code + * as defined in and that are subject to the Apple Public Source License + * Version 2.0 (the 'License'). You may not use this file except in + * compliance with the License. The rights granted to you under the License + * may not be used to create, or enable the creation or redistribution of, + * unlawful or unlicensed copies of an Apple operating system, or to + * circumvent, violate, or enable the circumvention or violation of, any + * terms of an Apple operating system software license agreement. * - * This Original Code and all software distributed under the License are - * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER + * Please obtain a copy of the License at + * http://www.opensource.apple.com/apsl/ and read it before using this file. + * + * The Original Code and all software distributed under the License are + * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the - * License for the specific language governing rights and limitations - * under the License. + * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. + * Please see the License for the specific language governing rights and + * limitations under the License. * - * @APPLE_LICENSE_HEADER_END@ + * @APPLE_OSREFERENCE_LICENSE_HEADER_END@ */ /*! @header kpi_mbuf.h This header defines an API for interacting with mbufs. mbufs are the primary method of storing packets in the networking stack. - + mbufs are used to store various items in the networking stack. The most common usage of an mbuf is to store a packet or data on a socket waiting to be sent or received. The mbuf is a contiguous structure with some header followed by some data. To store more data than would fit in an mbuf, external data is used. Most mbufs with external data use clusters to store the external data. - + mbufs can be chained, contiguous data in a packet can be found by following the m_next chain. Packets may be bundled together using m_nextpacket. Many parts of the stack do not properly handle chains @@ -45,10 +51,11 @@ /*! @enum mbuf_flags_t @abstract Constants defining mbuf flags. Only the flags listed below - can be set or retreieved. + can be set or retrieved. @constant MBUF_EXT Indicates this mbuf has external data. @constant MBUF_PKTHDR Indicates this mbuf has a packet header. @constant MBUF_EOR Indicates this mbuf is the end of a record. + @constant MBUF_LOOP Indicates this packet is looped back. @constant MBUF_BCAST Indicates this packet will be sent or was received as a brodcast. @constant MBUF_MCAST Indicates this packet will be sent or was @@ -63,16 +70,18 @@ being passed to any interface filters. */ enum { - MBUF_EXT = 0x0001, /* has associated external storage */ - MBUF_PKTHDR = 0x0002, /* start of record */ - MBUF_EOR = 0x0004, /* end of record */ - - MBUF_BCAST = 0x0100, /* send/received as link-level broadcast */ - MBUF_MCAST = 0x0200, /* send/received as link-level multicast */ - MBUF_FRAG = 0x0400, /* packet is a fragment of a larger packet */ + MBUF_EXT = 0x0001, /* has associated external storage */ + MBUF_PKTHDR = 0x0002, /* start of record */ + MBUF_EOR = 0x0004, /* end of record */ + MBUF_LOOP = 0x0040, /* packet is looped back */ + + MBUF_BCAST = 0x0100, /* send/received as link-level broadcast */ + MBUF_MCAST = 0x0200, /* send/received as link-level multicast */ + MBUF_FRAG = 0x0400, /* packet is a fragment of a larger packet */ MBUF_FIRSTFRAG = 0x0800, /* packet is first fragment */ MBUF_LASTFRAG = 0x1000, /* packet is last fragment */ - MBUF_PROMISC = 0x2000 /* packet is promiscuous */ + MBUF_PROMISC = 0x2000, /* packet is promiscuous */ + MBUF_HASFCS = 0x4000 /* packet has FCS */ }; typedef u_int32_t mbuf_flags_t; @@ -113,7 +122,7 @@ enum { MBUF_TYPE_PCB = 4, /* protocol control block */ MBUF_TYPE_RTABLE = 5, /* routing tables */ MBUF_TYPE_HTABLE = 6, /* IMP host tables */ - MBUF_TYPE_ATABLE = 7, /* address resolution tables */ + MBUF_TYPE_ATABLE = 7, /* address resolution tables */ MBUF_TYPE_SONAME = 8, /* socket name */ MBUF_TYPE_SOOPTS = 10, /* socket options */ MBUF_TYPE_FTABLE = 11, /* fragment reassembly header */ @@ -139,14 +148,26 @@ typedef u_int32_t mbuf_type_t; calculated yet. @constant MBUF_CSUM_REQ_UDP Indicates the UDP checksum has not been calculated yet. + @constant MBUF_CSUM_REQ_TCPIPV6 Indicates the TCP checksum for IPv6 + has not been calculated yet. + @constant MBUF_CSUM_REQ_UDPIPV6 Indicates the UDP checksum for IPv6 + has not been calculated yet. */ +enum { + MBUF_TSO_IPV4 = 0x100000, + MBUF_TSO_IPV6 = 0x200000 +}; +typedef u_int32_t mbuf_tso_request_flags_t; + enum { #ifdef KERNEL_PRIVATE MBUF_CSUM_REQ_SUM16 = 0x1000, /* Weird apple hardware checksum */ -#endif KERNEL_PRIVATE +#endif /* KERNEL_PRIVATE */ MBUF_CSUM_REQ_IP = 0x0001, MBUF_CSUM_REQ_TCP = 0x0002, - MBUF_CSUM_REQ_UDP = 0x0004 + MBUF_CSUM_REQ_UDP = 0x0004, + MBUF_CSUM_REQ_TCPIPV6 = 0x0020, + MBUF_CSUM_REQ_UDPIPV6 = 0x0040 }; typedef u_int32_t mbuf_csum_request_flags_t; @@ -166,7 +187,7 @@ typedef u_int32_t mbuf_csum_request_flags_t; hardware should be passed as the second parameter of mbuf_set_csum_performed. The hardware calculated checksum value can be retrieved using the second parameter passed to - mbuf_get_csum_performed. + mbuf_get_csum_performed. This should be done for IPv4 or IPv6. @constant MBUF_CSUM_PSEUDO_HDR If set, this indicates that the checksum value for MBUF_CSUM_DID_DATA includes the pseudo header value. If this is not set, the stack will calculate the pseudo @@ -175,11 +196,11 @@ typedef u_int32_t mbuf_csum_request_flags_t; */ enum { #ifdef KERNEL_PRIVATE - MBUF_CSUM_TCP_SUM16 = MBUF_CSUM_REQ_SUM16, /* Weird apple hardware checksum */ -#endif - MBUF_CSUM_DID_IP = 0x0100, - MBUF_CSUM_IP_GOOD = 0x0200, - MBUF_CSUM_DID_DATA = 0x0400, + MBUF_CSUM_TCP_SUM16 = MBUF_CSUM_REQ_SUM16, /* Weird apple hardware checksum */ +#endif /* KERNEL_PRIVATE */ + MBUF_CSUM_DID_IP = 0x0100, + MBUF_CSUM_IP_GOOD = 0x0200, + MBUF_CSUM_DID_DATA = 0x0400, MBUF_CSUM_PSEUDO_HDR = 0x0800 }; typedef u_int32_t mbuf_csum_performed_flags_t; @@ -198,8 +219,8 @@ typedef u_int32_t mbuf_csum_performed_flags_t; block, if blocking is necessary fail and return immediately. */ enum { - MBUF_WAITOK = 0, /* Ok to block to get memory */ - MBUF_DONTWAIT = 1 /* Don't block, fail if blocking would be required */ + MBUF_WAITOK = 0, /* Ok to block to get memory */ + MBUF_DONTWAIT = 1 /* Don't block, fail if blocking would be required */ }; typedef u_int32_t mbuf_how_t; @@ -229,46 +250,49 @@ typedef u_int16_t mbuf_tag_type_t; @field bigmclbytes Length of a big mbuf cluster. */ struct mbuf_stat { - u_long mbufs; /* mbufs obtained from page pool */ - u_long clusters; /* clusters obtained from page pool */ - u_long clfree; /* free clusters */ - u_long drops; /* times failed to find space */ - u_long wait; /* times waited for space */ - u_long drain; /* times drained protocols for space */ - u_short mtypes[256]; /* type specific mbuf allocations */ - u_long mcfail; /* times m_copym failed */ - u_long mpfail; /* times m_pullup failed */ - u_long msize; /* length of an mbuf */ - u_long mclbytes; /* length of an mbuf cluster */ - u_long minclsize; /* min length of data to allocate a cluster */ - u_long mlen; /* length of data in an mbuf */ - u_long mhlen; /* length of data in a header mbuf */ - u_long bigclusters; /* number of big clusters */ - u_long bigclfree; /* number of big clustser free */ - u_long bigmclbytes; /* length of data in a big cluster */ + u_int32_t mbufs; /* mbufs obtained from page pool */ + u_int32_t clusters; /* clusters obtained from page pool */ + u_int32_t clfree; /* free clusters */ + u_int32_t drops; /* times failed to find space */ + u_int32_t wait; /* times waited for space */ + u_int32_t drain; /* times drained protocols for space */ + u_short mtypes[256]; /* type specific mbuf allocations */ + u_int32_t mcfail; /* times m_copym failed */ + u_int32_t mpfail; /* times m_pullup failed */ + u_int32_t msize; /* length of an mbuf */ + u_int32_t mclbytes; /* length of an mbuf cluster */ + u_int32_t minclsize; /* min length of data to allocate a cluster */ + u_int32_t mlen; /* length of data in an mbuf */ + u_int32_t mhlen; /* length of data in a header mbuf */ + u_int32_t bigclusters; /* number of big clusters */ + u_int32_t bigclfree; /* number of big clustser free */ + u_int32_t bigmclbytes; /* length of data in a big cluster */ }; /* Parameter for m_copym to copy all bytes */ #define MBUF_COPYALL 1000000000 +__BEGIN_DECLS /* Data access */ /*! @function mbuf_data @discussion Returns a pointer to the start of data in this mbuf. There may be additional data on chained mbufs. The data you're - looking for may not be contiguous if it spans more than one - mbuf. Use mbuf_len to determine the lenght of data available in - this mbuf. If a data structure you want to access stradles two - mbufs in a chain, either use mbuf_pullup to get the data - contiguous in one mbuf or copy the pieces of data from each mbuf - in to a contiguous buffer. Using mbuf_pullup has the advantage - of not having to copy the data. On the other hand, if you don't - make sure there is space in the mbuf, mbuf_pullup may fail and - free the mbuf. + looking for may not be virtually contiguous if it spans more + than one mbuf. In addition, data that is virtually contiguous + might not be represented by physically contiguous pages; see + further comments in mbuf_data_to_physical. Use mbuf_len to + determine the lenght of data available in this mbuf. If a data + structure you want to access stradles two mbufs in a chain, + either use mbuf_pullup to get the data contiguous in one mbuf + or copy the pieces of data from each mbuf in to a contiguous + buffer. Using mbuf_pullup has the advantage of not having to + copy the data. On the other hand, if you don't make sure there + is space in the mbuf, mbuf_pullup may fail and free the mbuf. @param mbuf The mbuf. @result A pointer to the data in the mbuf. */ -void* mbuf_data(mbuf_t mbuf); +extern void *mbuf_data(mbuf_t mbuf); /*! @function mbuf_datastart @@ -276,12 +300,12 @@ void* mbuf_data(mbuf_t mbuf); data in an mbuf. An mbuf's data may come from a cluster or be embedded in the mbuf structure itself. The data pointer retrieved by mbuf_data may not be at the start of the data - (mbuf_leadingspace will be non-zero). This function will return to - you a pointer that matches mbuf_data() - mbuf_leadingspace(). + (mbuf_leadingspace will be non-zero). This function will return + a pointer that matches mbuf_data() - mbuf_leadingspace(). @param mbuf The mbuf. @result A pointer to smallest possible value for data. */ -void* mbuf_datastart(mbuf_t mbuf); +extern void *mbuf_datastart(mbuf_t mbuf); /*! @function mbuf_setdata @@ -297,7 +321,7 @@ void* mbuf_datastart(mbuf_t mbuf); @param len The new length of data in the mbuf. @result 0 on success, errno error on failure. */ -errno_t mbuf_setdata(mbuf_t mbuf, void *data, size_t len); +extern errno_t mbuf_setdata(mbuf_t mbuf, void *data, size_t len); /*! @function mbuf_align_32 @@ -310,19 +334,26 @@ errno_t mbuf_setdata(mbuf_t mbuf, void *data, size_t len); data location. @result 0 on success, errno error on failure. */ -errno_t mbuf_align_32(mbuf_t mbuf, size_t len); +extern errno_t mbuf_align_32(mbuf_t mbuf, size_t len); /*! @function mbuf_data_to_physical @discussion mbuf_data_to_physical is a replacement for mcl_to_paddr. Given a pointer returned from mbuf_data of mbuf_datastart, mbuf_data_to_physical will return the phyical address for that - block of data. + block of data. Note that even though the data is in virtually + contiguous span, the underlying physical pages might not be + physically contiguous. Because of this, callers must ensure + to call this routine for each page boundary. Device drivers + that deal with DMA are strongly encouraged to utilize the + IOMbufNaturalMemoryCursor and walk down the list of vectors + instead of using this interface to obtain the physical address. + Use of this routine is therefore discouraged. @param ptr A pointer to data stored in an mbuf. @result The 64 bit physical address of the mbuf data or NULL if ptr does not point to data stored in an mbuf. */ -addr64_t mbuf_data_to_physical(void* ptr); +extern addr64_t mbuf_data_to_physical(void *ptr); /* Allocation */ @@ -335,7 +366,7 @@ addr64_t mbuf_data_to_physical(void* ptr); @param mbuf The mbuf. @result 0 on success, errno error on failure. */ -errno_t mbuf_get(mbuf_how_t how, mbuf_type_t type, mbuf_t* mbuf); +extern errno_t mbuf_get(mbuf_how_t how, mbuf_type_t type, mbuf_t *mbuf); /*! @function mbuf_gethdr @@ -347,20 +378,88 @@ errno_t mbuf_get(mbuf_how_t how, mbuf_type_t type, mbuf_t* mbuf); @param mbuf The mbuf. @result 0 on success, errno error on failure. */ -errno_t mbuf_gethdr(mbuf_how_t how, mbuf_type_t type, mbuf_t* mbuf); +extern errno_t mbuf_gethdr(mbuf_how_t how, mbuf_type_t type, mbuf_t *mbuf); + +/*! + @function mbuf_attachcluster + @discussion Attach an external buffer as a cluster for an mbuf. If mbuf + points to a NULL mbuf_t, an mbuf will be allocated for you. If + mbuf points to a non-NULL mbuf_t, the user-supplied mbuf will + be used instead. The caller is responsible for allocating the + external buffer by calling mbuf_alloccluster(). + @param how Blocking or non-blocking. + @param type The type of the mbuf if mbuf is non-NULL; otherwise ignored. + @param mbuf Pointer to the address of the mbuf; if NULL, an mbuf will + be allocated, otherwise, it must point to a valid mbuf address. + If the user-supplied mbuf is already attached to a cluster, the + current cluster will be freed before the mbuf gets attached to + the supplied external buffer. Note that this routine may return + a different mbuf_t than the one you passed in. + @param extbuf Address of the external buffer. + @param extfree Free routine for the external buffer; the caller is + required to defined a routine that will be invoked when the + mbuf is freed. + @param extsize Size of the external buffer. + @param extarg Private value that will be passed to the free routine + when it is called at the time the mbuf is freed. + @result 0 on success + EINVAL - Invalid parameter + ENOMEM - Not enough memory available + */ +extern errno_t mbuf_attachcluster(mbuf_how_t how, mbuf_type_t type, + mbuf_t *mbuf, caddr_t extbuf, void (*extfree)(caddr_t , u_int, caddr_t), + size_t extsize, caddr_t extarg); +/*! + @function mbuf_alloccluster + @discussion Allocate a cluster that can be later attached to an + mbuf by calling mbuf_attachcluster(). The allocated cluster + can also be freed (without being attached to an mbuf) by + calling mbuf_freecluster(). At the moment this routine + will either return a cluster of 2048, 4096 or 16384 bytes + depending on the requested size. Note that clusters greater + than 4096 bytes might not be available in all configurations; + the caller must additionally check for ENOTSUP (see below). + @param how Blocking or non-blocking. + @param size Pointer to size of requested cluster. Sizes up to 2048 + will be rounded up to 2048; sizes greater than 2048 and up + to 4096 will be rounded up to 4096. Sizes greater than 4096 + will be rounded up to 16384. + @param addr Pointer to the address of the requested cluster. + @result 0 on success or ENOMEM if failure. If the caller requests + greater than 4096 bytes and the system is unable to fulfill + the request due to the lack of jumbo clusters support based + on the configuration, this routine will return ENOTSUP. + In this case, the caller is advised to use 4096 bytes or + smaller during subseqent requests. + */ +extern errno_t mbuf_alloccluster(mbuf_how_t how, size_t *size, caddr_t *addr); + +/*! + @function mbuf_freecluster + @discussion Free a cluster that was previously allocated by a call + to mbuf_alloccluster(). The caller must pass the actual + size of the cluster as returned by mbuf_alloccluster(), + which at this point must be either 2048, 4096 or 16384 bytes. + @param addr The address of the cluster. + @param size The actual size of the cluster. + */ +extern void mbuf_freecluster(caddr_t addr, size_t size); /*! @function mbuf_getcluster @discussion Allocate a cluster of the requested size and attach it to - an mbuf for use as external data. If mbuf points to a NULL mbuf_t, - an mbuf will be allocated for you. If mbuf points to a non-NULL mbuf_t, - mbuf_getcluster may return a different mbuf_t than the one you - passed in. + an mbuf for use as external data. If mbuf points to a NULL + mbuf_t, an mbuf will be allocated for you. If mbuf points to + a non-NULL mbuf_t, mbuf_getcluster may return a different + mbuf_t than the one you passed in. @param how Blocking or non-blocking. @param type The type of the mbuf. - @param size The size of the cluster to be allocated. Supported sizes for a - cluster are be 2048 or 4096. Any other value with return EINVAL. + @param size The size of the cluster to be allocated. Supported sizes + for a cluster are be 2048, 4096, or 16384. Any other value + with return EINVAL. Note that clusters greater than 4096 + bytes might not be available in all configurations; the + caller must additionally check for ENOTSUP (see below). @param mbuf The mbuf the cluster will be attached to. @result 0 on success, errno error on failure. If you specified NULL for the mbuf, any intermediate mbuf that may have been allocated @@ -368,8 +467,14 @@ errno_t mbuf_gethdr(mbuf_how_t how, mbuf_type_t type, mbuf_t* mbuf); mbuf_mclget will not free it. EINVAL - Invalid parameter ENOMEM - Not enough memory available + ENOTSUP - The caller had requested greater than 4096 bytes + cluster and the system is unable to fulfill it due to the + lack of jumbo clusters support based on the configuration. + In this case, the caller is advised to use 4096 bytes or + smaller during subsequent requests. */ -errno_t mbuf_getcluster(mbuf_how_t how, mbuf_type_t type, size_t size, mbuf_t* mbuf); +extern errno_t mbuf_getcluster(mbuf_how_t how, mbuf_type_t type, size_t size, + mbuf_t *mbuf); /*! @function mbuf_mclget @@ -386,31 +491,85 @@ errno_t mbuf_getcluster(mbuf_how_t how, mbuf_type_t type, size_t size, mbuf_t* will be freed. If you specify an mbuf value in *mbuf, mbuf_mclget will not free it. */ -errno_t mbuf_mclget(mbuf_how_t how, mbuf_type_t type, mbuf_t* mbuf); +extern errno_t mbuf_mclget(mbuf_how_t how, mbuf_type_t type, mbuf_t *mbuf); /*! @function mbuf_allocpacket - @discussion Allocate an mbuf chain to store a single packet of the requested length. - According to the requested length, a chain of mbufs will be created. The mbuf type - will be set to MBUF_TYPE_DATA. The caller may specify the maximum number of - buffer + @discussion Allocate an mbuf chain to store a single packet of the + requested length. According to the requested length, a chain + of mbufs will be created. The mbuf type will be set to + MBUF_TYPE_DATA. The caller may specify the maximum number of + buffer. @param how Blocking or non-blocking @param packetlen The total length of the packet mbuf to be allocated. The length must be greater than zero. - @param maxchunks An input/output pointer to the maximum number of mbufs segments making up the chain. - On input if maxchunks is zero, or the value pointed to by maxchunks is zero, - the packet will be made of as many buffer segments as necessary to fit the length. - The allocation will fail with ENOBUFS if the number of segments requested is too small and - the sum of the maximum size of each individual segment is less than the packet length. - On output, if the allocation succeed and maxchunks is non zero, it will point to - the actual number of segments allocated. + @param maxchunks An input/output pointer to the maximum number of mbufs + segments making up the chain. On input, if maxchunks is NULL, + or the value pointed to by maxchunks is zero, the packet will + be made up of as few or as many buffer segments as necessary + to fit the length. The allocation will fail with ENOBUFS if + the number of segments requested is too small and the sum of + the maximum size of each individual segment is less than the + packet length. On output, if the allocation succeed and + maxchunks is non-NULL, it will point to the actual number + of segments allocated. + Additional notes for packetlen greater than 4096 bytes: + the caller may pass a non-NULL maxchunks and initialize it + with zero such that upon success, it can find out whether + or not the system configuration allows for larger than + 4096 bytes cluster allocations, by checking on the value + pointed to by maxchunks. E.g. a request for 9018 bytes may + result in 1 chunk when jumbo clusters are available, or + 3 chunks otherwise. @param Upon success, *mbuf will be a reference to the new mbuf. @result Returns 0 upon success or the following error code: EINVAL - Invalid parameter ENOMEM - Not enough memory available - ENOBUFS - Buffers not big enough for the maximum number of chunks requested + ENOBUFS - Buffers not big enough for the maximum number of + chunks requested */ -errno_t mbuf_allocpacket(mbuf_how_t how, size_t packetlen, unsigned int * maxchunks, mbuf_t *mbuf); +extern errno_t mbuf_allocpacket(mbuf_how_t how, size_t packetlen, + unsigned int * maxchunks, mbuf_t *mbuf); + +/*! + @function mbuf_allocpacket_list + @discussion Allocate a linked list of packets. According to the + requested length, each packet will made of a chain of one + or more mbufs. The mbuf type will be set to MBUF_TYPE_DATA. + The caller may specify the maximum number of element for + each mbuf chain making up a packet. + @param numpkts Number of packets to allocate + @param how Blocking or non-blocking + @param packetlen The total length of the packet mbuf to be allocated. + The length must be greater than zero. + @param maxchunks An input/output pointer to the maximum number of + mbufs segments making up the chain. On input, if maxchunks is + zero, or the value pointed to by maxchunks is zero, the packet + will be made of as few or as many buffer segments as necessary + to fit the length. The allocation will fail with ENOBUFS if + the number of segments requested is too small and the sum of + the maximum size of each individual segment is less than the + packet length. On output, if the allocation succeed and + maxchunks is non zero, it will point to the actual number + of segments allocated. + Additional notes for packetlen greater than 4096 bytes: + the caller may pass a non-NULL maxchunks and initialize it + with zero such that upon success, it can find out whether + or not the system configuration allows for larger than + 4096 bytes cluster allocations, by checking on the value + pointed to by maxchunks. E.g. a request for 9018 bytes may + result in 1 chunk when jumbo clusters are available, or + 3 chunks otherwise. + @param Upon success, *mbuf will be a reference to the new mbuf. + @result Returns 0 upon success or the following error code: + EINVAL - Invalid parameter + ENOMEM - Not enough memory available + ENOBUFS - Buffers not big enough for the maximum number of + chunks requested +*/ +extern errno_t mbuf_allocpacket_list(unsigned int numpkts, mbuf_how_t how, + size_t packetlen, unsigned int * maxchunks, mbuf_t *mbuf); + /*! @function mbuf_getpacket @@ -420,7 +579,7 @@ errno_t mbuf_allocpacket(mbuf_how_t how, size_t packetlen, unsigned int * maxchu @param mbuf Upon success, *mbuf will be a reference to the new mbuf. @result 0 on success, errno error on failure. */ -errno_t mbuf_getpacket(mbuf_how_t how, mbuf_t* mbuf); +extern errno_t mbuf_getpacket(mbuf_how_t how, mbuf_t *mbuf); /*! @function mbuf_free @@ -429,23 +588,23 @@ errno_t mbuf_getpacket(mbuf_how_t how, mbuf_t* mbuf); @param mbuf The mbuf to free. @result The next mbuf in the chain. */ -mbuf_t mbuf_free(mbuf_t mbuf); +extern mbuf_t mbuf_free(mbuf_t mbuf); /*! @function mbuf_freem @discussion Frees a chain of mbufs link through mnext. @param mbuf The first mbuf in the chain to free. */ -void mbuf_freem(mbuf_t mbuf); +extern void mbuf_freem(mbuf_t mbuf); /*! @function mbuf_freem_list @discussion Frees linked list of mbuf chains. Walks through - mnextpackt and does the equivalent of mbuf_mfreem to each. + mnextpackt and does the equivalent of mbuf_freem to each. @param mbuf The first mbuf in the linked list to free. @result The number of mbufs freed. */ -int mbuf_freem_list(mbuf_t mbuf); +extern int mbuf_freem_list(mbuf_t mbuf); /*! @function mbuf_leadingspace @@ -454,7 +613,7 @@ int mbuf_freem_list(mbuf_t mbuf); @param mbuf The mbuf. @result The number of unused bytes at the start of the mbuf. */ -size_t mbuf_leadingspace(mbuf_t mbuf); +extern size_t mbuf_leadingspace(const mbuf_t mbuf); /*! @function mbuf_trailingspace @@ -463,13 +622,17 @@ size_t mbuf_leadingspace(mbuf_t mbuf); @param mbuf The mbuf. @result The number of unused bytes following the current data. */ -size_t mbuf_trailingspace(mbuf_t mbuf); +extern size_t mbuf_trailingspace(const mbuf_t mbuf); /* Manipulation */ /*! @function mbuf_copym - @discussion Copies len bytes from offset from src to a new mbuf. + @discussion Copies len bytes from offset from src to a new mbuf. If + the original mbuf contains a packet header, the new mbuf will + contain similar packet header except for any tags which may be + associated with the original mbuf. mbuf_dup() should be used + instead if tags are to be copied to the new mbuf. @param src The source mbuf. @param offset The offset in the mbuf to start copying from. @param len The the number of bytes to copy. @@ -477,18 +640,21 @@ size_t mbuf_trailingspace(mbuf_t mbuf); @param new_mbuf Upon success, the newly allocated mbuf. @result 0 upon success otherwise the errno error. */ -errno_t mbuf_copym(mbuf_t src, size_t offset, size_t len, - mbuf_how_t how, mbuf_t* new_mbuf); +extern errno_t mbuf_copym(const mbuf_t src, size_t offset, size_t len, + mbuf_how_t how, mbuf_t *new_mbuf); /*! @function mbuf_dup - @discussion Exactly duplicates an mbuf chain. + @discussion Exactly duplicates an mbuf chain. If the original mbuf + contains a packet header (including tags), the new mbuf will have + the same packet header contents and a copy of each tag associated + with the original mbuf. @param src The source mbuf. @param how Blocking or non-blocking. @param new_mbuf Upon success, the newly allocated mbuf. @result 0 upon success otherwise the errno error. */ -errno_t mbuf_dup(mbuf_t src, mbuf_how_t how, mbuf_t* new_mbuf); +extern errno_t mbuf_dup(const mbuf_t src, mbuf_how_t how, mbuf_t *new_mbuf); /*! @function mbuf_prepend @@ -503,7 +669,7 @@ errno_t mbuf_dup(mbuf_t src, mbuf_how_t how, mbuf_t* new_mbuf); @param how Blocking or non-blocking. @result 0 upon success otherwise the errno error. */ -errno_t mbuf_prepend(mbuf_t* mbuf, size_t len, mbuf_how_t how); +extern errno_t mbuf_prepend(mbuf_t *mbuf, size_t len, mbuf_how_t how); /*! @function mbuf_split @@ -518,8 +684,8 @@ errno_t mbuf_prepend(mbuf_t* mbuf, size_t len, mbuf_how_t how); failure, the original mbuf chain passed in to src will be preserved. */ -errno_t mbuf_split(mbuf_t src, size_t offset, - mbuf_how_t how, mbuf_t* new_mbuf); +extern errno_t mbuf_split(mbuf_t src, size_t offset, mbuf_how_t how, + mbuf_t *new_mbuf); /*! @function mbuf_pullup @@ -532,7 +698,7 @@ errno_t mbuf_split(mbuf_t src, size_t offset, @result 0 upon success otherwise the errno error. In the case of an error, the mbuf chain has been freed. */ -errno_t mbuf_pullup(mbuf_t* mbuf, size_t len); +extern errno_t mbuf_pullup(mbuf_t *mbuf, size_t len); /*! @function mbuf_pulldown @@ -552,7 +718,8 @@ errno_t mbuf_pullup(mbuf_t* mbuf, size_t len); in. @result 0 upon success otherwise the errno error. */ -errno_t mbuf_pulldown(mbuf_t src, size_t *offset, size_t length, mbuf_t *location); +extern errno_t mbuf_pulldown(mbuf_t src, size_t *offset, size_t length, + mbuf_t *location); /*! @function mbuf_adj @@ -562,9 +729,40 @@ errno_t mbuf_pulldown(mbuf_t src, size_t *offset, size_t length, mbuf_t *locati of the mbuf chain. @param mbuf The mbuf chain to trim. @param len The number of bytes to trim from the mbuf chain. + */ +extern void mbuf_adj(mbuf_t mbuf, int len); + +/*! + @function mbuf_adjustlen + @discussion Adds amount to the mbuf len. Verifies that the new + length is valid (greater than or equal to zero and less than + maximum amount of data that may be stored in the mbuf). This + function will not adjust the packet header length field or + affect any other mbufs in a chain. + @param mbuf The mbuf to adjust. + @param amount The number of bytes increment the length by. @result 0 upon success otherwise the errno error. */ -void mbuf_adj(mbuf_t mbuf, int len); +extern errno_t mbuf_adjustlen(mbuf_t mbuf, int amount); + +/*! + @function mbuf_concatenate + @discussion Concatenate mbuf chain src to dst using m_next and return + a chain which represents the concatenated chain. The routine + does not prevent two chains of different mbuf types to be + concatenated, nor does it modify any packet header in the + destination chain. Therefore, it's the responsibility of the + caller to ensure that the resulted concatenated mbuf chain is + correct for further usages. + @param dst The destination mbuf chain. + @param src The source mbuf chain. + @result A pointer to the head of the concatenated mbuf chain. This + should be treated as the updated destination mbuf chain; the + caller must no longer refer to the original src or dst mbuf + chain. Otherwise it returns NULL if the original dst mbuf + chain is NULL. + */ +extern mbuf_t mbuf_concatenate(mbuf_t dst, mbuf_t src); /*! @function mbuf_copydata @@ -578,18 +776,19 @@ void mbuf_adj(mbuf_t mbuf, int len); copied. @result 0 upon success otherwise the errno error. */ -errno_t mbuf_copydata(mbuf_t mbuf, size_t offset, size_t length, void* out_data); +extern errno_t mbuf_copydata(const mbuf_t mbuf, size_t offset, size_t length, + void *out_data); /*! @function mbuf_copyback @discussion Copies data from a buffer to an mbuf chain. mbuf_copyback will grow the chain to fit the specified buffer. - + If mbuf_copydata is unable to allocate enough mbufs to grow the chain, ENOBUFS will be returned. The mbuf chain will be shorter than expected but all of the data up to the end of the mbuf chain will be valid. - + If an offset is specified, mbuf_copyback will skip that many bytes in the mbuf chain before starting to write the buffer in to the chain. If the mbuf chain does not contain this many @@ -602,26 +801,8 @@ errno_t mbuf_copydata(mbuf_t mbuf, size_t offset, size_t length, void* out_data @param how Blocking or non-blocking. @result 0 upon success, EINVAL or ENOBUFS upon failure. */ -errno_t mbuf_copyback(mbuf_t mbuf, size_t offset, size_t length, - const void *data, mbuf_how_t how); - -#ifdef KERNEL_PRIVATE -/*! - @function mbuf_mclref - @discussion Incrememnt the reference count of the cluster. - @param mbuf The mbuf with the cluster to increment the refcount of. - @result 0 upon success otherwise the errno error. - */ -int mbuf_mclref(mbuf_t mbuf); - -/*! - @function mbuf_mclunref - @discussion Decrement the reference count of the cluster. - @param mbuf The mbuf with the cluster to decrement the refcount of. - @result 0 upon success otherwise the errno error. - */ -int mbuf_mclunref(mbuf_t mbuf); -#endif +extern errno_t mbuf_copyback(mbuf_t mbuf, size_t offset, size_t length, + const void *data, mbuf_how_t how); /*! @function mbuf_mclhasreference @@ -631,7 +812,7 @@ int mbuf_mclunref(mbuf_t mbuf); @param mbuf The mbuf with the cluster to test. @result 0 if there is no reference by another mbuf, 1 otherwise. */ -int mbuf_mclhasreference(mbuf_t mbuf); +extern int mbuf_mclhasreference(mbuf_t mbuf); /* mbuf header */ @@ -642,7 +823,7 @@ int mbuf_mclhasreference(mbuf_t mbuf); @param mbuf The mbuf. @result The next mbuf in the chain. */ -mbuf_t mbuf_next(mbuf_t mbuf); +extern mbuf_t mbuf_next(const mbuf_t mbuf); /*! @function mbuf_setnext @@ -651,7 +832,7 @@ mbuf_t mbuf_next(mbuf_t mbuf); @param next The new next mbuf. @result 0 upon success otherwise the errno error. */ -errno_t mbuf_setnext(mbuf_t mbuf, mbuf_t next); +extern errno_t mbuf_setnext(mbuf_t mbuf, mbuf_t next); /*! @function mbuf_nextpkt @@ -659,7 +840,7 @@ errno_t mbuf_setnext(mbuf_t mbuf, mbuf_t next); @param mbuf The mbuf. @result The nextpkt. */ -mbuf_t mbuf_nextpkt(mbuf_t mbuf); +extern mbuf_t mbuf_nextpkt(const mbuf_t mbuf); /*! @function mbuf_setnextpkt @@ -667,7 +848,7 @@ mbuf_t mbuf_nextpkt(mbuf_t mbuf); @param mbuf The mbuf. @param nextpkt The new next packet. */ -void mbuf_setnextpkt(mbuf_t mbuf, mbuf_t nextpkt); +extern void mbuf_setnextpkt(mbuf_t mbuf, mbuf_t nextpkt); /*! @function mbuf_len @@ -675,7 +856,7 @@ void mbuf_setnextpkt(mbuf_t mbuf, mbuf_t nextpkt); @param mbuf The mbuf. @result The length. */ -size_t mbuf_len(mbuf_t mbuf); +extern size_t mbuf_len(const mbuf_t mbuf); /*! @function mbuf_setlen @@ -685,7 +866,7 @@ size_t mbuf_len(mbuf_t mbuf); @param len The new length. @result 0 upon success otherwise the errno error. */ -void mbuf_setlen(mbuf_t mbuf, size_t len); +extern void mbuf_setlen(mbuf_t mbuf, size_t len); /*! @function mbuf_maxlen @@ -696,7 +877,7 @@ void mbuf_setlen(mbuf_t mbuf, size_t len); @param mbuf The mbuf. @result The maximum lenght of data for this mbuf. */ -size_t mbuf_maxlen(mbuf_t mbuf); +extern size_t mbuf_maxlen(const mbuf_t mbuf); /*! @function mbuf_type @@ -704,7 +885,7 @@ size_t mbuf_maxlen(mbuf_t mbuf); @param mbuf The mbuf. @result The type. */ -mbuf_type_t mbuf_type(mbuf_t mbuf); +extern mbuf_type_t mbuf_type(const mbuf_t mbuf); /*! @function mbuf_settype @@ -713,7 +894,7 @@ mbuf_type_t mbuf_type(mbuf_t mbuf); @param new_type The new type. @result 0 upon success otherwise the errno error. */ -errno_t mbuf_settype(mbuf_t mbuf, mbuf_type_t new_type); +extern errno_t mbuf_settype(mbuf_t mbuf, mbuf_type_t new_type); /*! @function mbuf_flags @@ -721,7 +902,7 @@ errno_t mbuf_settype(mbuf_t mbuf, mbuf_type_t new_type); @param mbuf The mbuf. @result The flags. */ -mbuf_flags_t mbuf_flags(mbuf_t mbuf); +extern mbuf_flags_t mbuf_flags(const mbuf_t mbuf); /*! @function mbuf_setflags @@ -730,7 +911,7 @@ mbuf_flags_t mbuf_flags(mbuf_t mbuf); @param flags The flags that should be set, all other flags will be cleared. @result 0 upon success otherwise the errno error. */ -errno_t mbuf_setflags(mbuf_t mbuf, mbuf_flags_t flags); +extern errno_t mbuf_setflags(mbuf_t mbuf, mbuf_flags_t flags); /*! @function mbuf_setflags_mask @@ -741,8 +922,8 @@ errno_t mbuf_setflags(mbuf_t mbuf, mbuf_flags_t flags); @param mask The mask controlling which flags will be modified. @result 0 upon success otherwise the errno error. */ -errno_t mbuf_setflags_mask(mbuf_t mbuf, mbuf_flags_t flags, - mbuf_flags_t mask); +extern errno_t mbuf_setflags_mask(mbuf_t mbuf, mbuf_flags_t flags, + mbuf_flags_t mask); /*! @function mbuf_copy_pkthdr @@ -751,7 +932,7 @@ errno_t mbuf_setflags_mask(mbuf_t mbuf, mbuf_flags_t flags, @param mbuf The mbuf to which the packet header will be copied. @result 0 upon success otherwise the errno error. */ -errno_t mbuf_copy_pkthdr(mbuf_t dest, mbuf_t src); +extern errno_t mbuf_copy_pkthdr(mbuf_t dest, const mbuf_t src); /*! @function mbuf_pkthdr_len @@ -760,27 +941,38 @@ errno_t mbuf_copy_pkthdr(mbuf_t dest, mbuf_t src); be changed. @result The length, in bytes, of the packet. */ -size_t mbuf_pkthdr_len(mbuf_t mbuf); +extern size_t mbuf_pkthdr_len(const mbuf_t mbuf); /*! @function mbuf_pkthdr_setlen @discussion Sets the length of the packet in the packet header. @param mbuf The mbuf containing the packet header. @param len The new length of the packet. - @result 0 upon success otherwise the errno error. */ -void mbuf_pkthdr_setlen(mbuf_t mbuf, size_t len); +extern void mbuf_pkthdr_setlen(mbuf_t mbuf, size_t len); + +/*! + @function mbuf_pkthdr_adjustlen + @discussion Adjusts the length of the packet in the packet header. + @param mbuf The mbuf containing the packet header. + @param amount The number of bytes to adjust the packet header length + field by. + */ +extern void mbuf_pkthdr_adjustlen(mbuf_t mbuf, int amount); /*! @function mbuf_pkthdr_rcvif - @discussion Returns a reference to the interface the packet was - received on. Increments the reference count of the interface - before returning. Caller is responsible for releasing - the reference by calling ifnet_release. + @discussion Returns the interface the packet was received on. This + funciton does not modify the reference count of the interface. + The interface is only valid for as long as the mbuf is not freed + and the rcvif for the mbuf is not changed. Take a reference on + the interface that you will release later before doing any of + the following: free the mbuf, change the rcvif, pass the mbuf to + any function that may free the mbuf or change the rcvif. @param mbuf The mbuf containing the packet header. @result A reference to the interface. */ -ifnet_t mbuf_pkthdr_rcvif(mbuf_t mbuf); +extern ifnet_t mbuf_pkthdr_rcvif(const mbuf_t mbuf); /*! @function mbuf_pkthdr_setrcvif @@ -789,7 +981,7 @@ ifnet_t mbuf_pkthdr_rcvif(mbuf_t mbuf); @param ifnet A reference to an interface. @result 0 upon success otherwise the errno error. */ -errno_t mbuf_pkthdr_setrcvif(mbuf_t mbuf, ifnet_t ifnet); +extern errno_t mbuf_pkthdr_setrcvif(mbuf_t mbuf, ifnet_t ifp); /*! @function mbuf_pkthdr_header @@ -797,7 +989,7 @@ errno_t mbuf_pkthdr_setrcvif(mbuf_t mbuf, ifnet_t ifnet); @param mbuf The mbuf containing the packet header. @result A pointer to the packet header. */ -void* mbuf_pkthdr_header(mbuf_t mbuf); +extern void *mbuf_pkthdr_header(const mbuf_t mbuf); /*! @function mbuf_pkthdr_setheader @@ -806,41 +998,7 @@ void* mbuf_pkthdr_header(mbuf_t mbuf); @param ifnet A pointer to the header. @result 0 upon success otherwise the errno error. */ -void mbuf_pkthdr_setheader(mbuf_t mbuf, void* header); -#ifdef KERNEL_PRIVATE - -/* mbuf aux data */ - -/*! - @function mbuf_aux_add - @discussion Adds auxiliary data in the form of an mbuf. - @param mbuf The mbuf to add aux data to. - @param family The protocol family of the aux data to add. - @param type The mbuf type of the aux data to add. - @param aux_mbuf The aux mbuf allocated for you. - @result 0 upon success otherwise the errno error. - */ -errno_t mbuf_aux_add(mbuf_t mbuf, int family, mbuf_type_t type, mbuf_t *aux_mbuf); - -/*! - @function mbuf_aux_find - @discussion Finds auxiliary data attached to an mbuf. - @param mbuf The mbuf to find aux data on. - @param family The protocol family of the aux data to add. - @param type The mbuf type of the aux data to add. - @result The aux data mbuf or NULL if there isn't one. - */ -mbuf_t mbuf_aux_find(mbuf_t mbuf, int family, mbuf_type_t type); - -/*! - @function mbuf_aux_delete - @discussion Free an mbuf used as aux data and disassosciate it from - the mbuf. - @param mbuf The mbuf to find aux data on. - @param aux The aux data to free. - */ -void mbuf_aux_delete(mbuf_t mbuf, mbuf_t aux); -#endif /* KERNEL_PRIVATE */ +extern void mbuf_pkthdr_setheader(mbuf_t mbuf, void *header); /* Checksums */ @@ -857,13 +1015,13 @@ void mbuf_aux_delete(mbuf_t mbuf, mbuf_t aux); original checksum was valid. @param mbuf The mbuf that has been modified. */ -void mbuf_inbound_modified(mbuf_t mbuf); +extern void mbuf_inbound_modified(mbuf_t mbuf); /*! @function mbuf_outbound_finalize @discussion This function will "finalize" the packet allowing your code to inspect the final packet. - + There are a number of operations that are performed in hardware, such as calculating checksums. This function will perform in software the various opterations that were scheduled to be done @@ -877,10 +1035,10 @@ void mbuf_inbound_modified(mbuf_t mbuf); hardware, you must call this function to get an aproximate final packet. If you plan to modify the packet in any way, you should call this function. - + This function should be called before modifying any outbound packets. - + This function may be called at various levels, in some cases additional headers may have already been prepended, such as the case of a packet seen by an interface filter. To handle this, @@ -894,8 +1052,8 @@ void mbuf_inbound_modified(mbuf_t mbuf); protocol header. For an IP packet with an ethernet header, this would be the length of an ethernet header. */ -void mbuf_outbound_finalize(mbuf_t mbuf, u_long protocol_family, - size_t protocol_offset); +extern void mbuf_outbound_finalize(mbuf_t mbuf, u_int32_t protocol_family, + size_t protocol_offset); /*! @function mbuf_set_vlan_tag @@ -906,7 +1064,7 @@ void mbuf_outbound_finalize(mbuf_t mbuf, u_long protocol_family, @param vlan The protocol family of the aux data to add. @result 0 upon success otherwise the errno error. */ -errno_t mbuf_set_vlan_tag(mbuf_t mbuf, u_int16_t vlan); +extern errno_t mbuf_set_vlan_tag(mbuf_t mbuf, u_int16_t vlan); /*! @function mbuf_get_vlan_tag @@ -920,7 +1078,7 @@ errno_t mbuf_set_vlan_tag(mbuf_t mbuf, u_int16_t vlan); @result 0 upon success otherwise the errno error. ENXIO indicates that the vlan tag is not set. */ -errno_t mbuf_get_vlan_tag(mbuf_t mbuf, u_int16_t *vlan); +extern errno_t mbuf_get_vlan_tag(mbuf_t mbuf, u_int16_t *vlan); /*! @function mbuf_clear_vlan_tag @@ -929,10 +1087,10 @@ errno_t mbuf_get_vlan_tag(mbuf_t mbuf, u_int16_t *vlan); @param mbuf The mbuf containing the packet. @result 0 upon success otherwise the errno error. */ -errno_t mbuf_clear_vlan_tag(mbuf_t mbuf); +extern errno_t mbuf_clear_vlan_tag(mbuf_t mbuf); #ifdef KERNEL_PRIVATE -/*! +/* @function mbuf_set_csum_requested @discussion This function is used by the stack to indicate which checksums should be calculated in hardware. The stack normally @@ -946,9 +1104,9 @@ errno_t mbuf_clear_vlan_tag(mbuf_t mbuf); @param value This parameter is currently unsupported. @result 0 upon success otherwise the errno error. */ -errno_t mbuf_set_csum_requested(mbuf_t mbuf, - mbuf_csum_request_flags_t request, u_int32_t value); -#endif +extern errno_t mbuf_set_csum_requested(mbuf_t mbuf, + mbuf_csum_request_flags_t request, u_int32_t value); +#endif /* KERNEL_PRIVATE */ /*! @function mbuf_get_csum_requested @@ -960,8 +1118,21 @@ errno_t mbuf_set_csum_requested(mbuf_t mbuf, @param value This parameter is currently unsupported. @result 0 upon success otherwise the errno error. */ -errno_t mbuf_get_csum_requested(mbuf_t mbuf, - mbuf_csum_request_flags_t *request, u_int32_t *value); +extern errno_t mbuf_get_csum_requested(mbuf_t mbuf, + mbuf_csum_request_flags_t *request, u_int32_t *value); + +/*! + @function mbuf_get_tso_requested + @discussion This function is used by the driver to determine which + checksum operations should be performed in hardware. + @param mbuf The mbuf containing the packet. + @param request Flags indicating which values are being requested + for this packet. + @param value The requested value. + @result 0 upon success otherwise the errno error. + */ +extern errno_t mbuf_get_tso_requested(mbuf_t mbuf, + mbuf_tso_request_flags_t *request, u_int32_t *value); /*! @function mbuf_clear_csum_requested @@ -969,7 +1140,7 @@ errno_t mbuf_get_csum_requested(mbuf_t mbuf, @param mbuf The mbuf containing the packet. @result 0 upon success otherwise the errno error. */ -errno_t mbuf_clear_csum_requested(mbuf_t mbuf); +extern errno_t mbuf_clear_csum_requested(mbuf_t mbuf); /*! @function mbuf_set_csum_performed @@ -983,11 +1154,11 @@ errno_t mbuf_clear_csum_requested(mbuf_t mbuf); hardware. @result 0 upon success otherwise the errno error. */ -errno_t mbuf_set_csum_performed(mbuf_t mbuf, - mbuf_csum_performed_flags_t flags, u_int32_t value); +extern errno_t mbuf_set_csum_performed(mbuf_t mbuf, + mbuf_csum_performed_flags_t flags, u_int32_t value); #ifdef KERNEL_PRIVATE -/*! +/* @function mbuf_get_csum_performed @discussion This is used by the stack to determine which checksums were calculated in hardware on the inbound path. @@ -999,9 +1170,36 @@ errno_t mbuf_set_csum_performed(mbuf_t mbuf, hardware. @result 0 upon success otherwise the errno error. */ -errno_t mbuf_get_csum_performed(mbuf_t mbuf, - mbuf_csum_performed_flags_t *flags, u_int32_t *value); -#endif +extern errno_t mbuf_get_csum_performed(mbuf_t mbuf, + mbuf_csum_performed_flags_t *flags, u_int32_t *value); +#endif /* KERNEL_PRIVATE */ + +/*! + @function mbuf_get_mlen + @discussion This routine returns the number of data bytes in a normal + mbuf, i.e. an mbuf that is not a packet header, nor one with + an external cluster attached to it. This is equivalent to the + legacy MLEN macro. + @result The number of bytes of available data. + */ +extern u_int32_t mbuf_get_mlen(void); + +/*! + @function mbuf_get_mhlen + @discussion This routine returns the number of data bytes in a packet + header mbuf. This is equivalent to the legacy MHLEN macro. + @result The number of bytes of available data. + */ +extern u_int32_t mbuf_get_mhlen(void); + +/*! + @function mbuf_get_minclsize + @discussion This routine returns the minimum number of data bytes + before an external cluster is used. This is equivalent to the + legacy MINCLSIZE macro. + @result The minimum number of bytes before a cluster will be used. + */ +extern u_int32_t mbuf_get_minclsize(void); /*! @function mbuf_clear_csum_performed @@ -1009,7 +1207,65 @@ errno_t mbuf_get_csum_performed(mbuf_t mbuf, @param mbuf The mbuf containing the packet. @result 0 upon success otherwise the errno error. */ -errno_t mbuf_clear_csum_performed(mbuf_t mbuf); +extern errno_t mbuf_clear_csum_performed(mbuf_t mbuf); + +/*! + @function mbuf_inet_cksum + @discussions Calculates 16-bit 1's complement Internet checksum of the + transport segment with or without the pseudo header checksum + of a given IPv4 packet. If the caller specifies a non-zero + transport protocol, the checksum returned will also include + the pseudo header checksum for the corresponding transport + header. Otherwise, no header parsing will be done and the + caller may use this to calculate the Internet checksum of + an arbitrary span of data. + + This routine does not modify the contents of the packet. If + the caller specifies a non-zero protocol and/or offset, the + routine expects the complete protocol header to be present + at the beginning of the first mbuf. + @param mbuf The mbuf (or chain of mbufs) containing the packet. + @param protocol A zero or non-zero value. A non-zero value specifies + the transport protocol used for pseudo header checksum. + @param offset A zero or non-zero value; if the latter, it specifies + the offset of the transport header from the beginning of mbuf. + @param length The total (non-zero) length of the transport segment. + @param csum Pointer to the checksum variable; upon success, this + routine will return the calculated Internet checksum through + this variable. The caller must set it to a non-NULL value. + @result 0 upon success otherwise the errno error. + */ +extern errno_t mbuf_inet_cksum(mbuf_t mbuf, int protocol, u_int32_t offset, + u_int32_t length, u_int16_t *csum); + +/*! + @function mbuf_inet6_cksum + @discussions Calculates 16-bit 1's complement Internet checksum of the + transport segment with or without the pseudo header checksum + of a given IPv6 packet. If the caller specifies a non-zero + transport protocol, the checksum returned will also include + the pseudo header checksum for the corresponding transport + header. Otherwise, no header parsing will be done and the + caller may use this to calculate the Internet checksum of + an arbitrary span of data. + + This routine does not modify the contents of the packet. If + the caller specifies a non-zero protocol and/or offset, the + routine expects the complete protocol header(s) to be present + at the beginning of the first mbuf. + @param mbuf The mbuf (or chain of mbufs) containing the packet. + @param protocol A zero or non-zero value. A non-zero value specifies + the transport protocol used for pseudo header checksum. + @param offset A zero or non-zero value; if the latter, it specifies + the offset of the transport header from the beginning of mbuf. + @param length The total (non-zero) length of the transport segment. + @param csum Pointer to the checksum variable; upon success, this + routine will return the calculated Internet checksum through + this variable. The caller must set it to a non-NULL value. + @result 0 upon success otherwise the errno error. + */ +extern errno_t mbuf_inet6_cksum(mbuf_t mbuf, int protocol, u_int32_t offset, + u_int32_t length, u_int16_t *csum); /* mbuf tags */ @@ -1018,12 +1274,12 @@ errno_t mbuf_clear_csum_performed(mbuf_t mbuf); @discussion Lookup the module id for a string. If there is no module id assigned to this string, a new module id will be assigned. The string should be the bundle id of the kext. In the case of a - tag that will be shared across multiple kexts, a common bundle id - style string should be used. - + tag that will be shared across multiple kexts, a common bundle + id style string should be used. + The lookup operation is not optimized. A module should call this - function once during startup and chache the module id. The module id - will not be resassigned until the machine reboots. + function once during startup and chache the module id. The + module id will not be resassigned until the machine reboots. @param module_string A unique string identifying your module. Example: com.apple.nke.SharedIP. @param module_id Upon return, a unique identifier for use with @@ -1031,16 +1287,16 @@ errno_t mbuf_clear_csum_performed(mbuf_t mbuf); is rebooted. @result 0 upon success otherwise the errno error. */ -errno_t mbuf_tag_id_find(const char *module_string, - mbuf_tag_id_t *module_id); +extern errno_t mbuf_tag_id_find(const char *module_string, + mbuf_tag_id_t *module_id); /*! @function mbuf_tag_allocate @discussion Allocate an mbuf tag. Mbuf tags allow various portions of the stack to tag mbufs with data that will travel with the mbuf through the stack. - - Tags may only be added to mbufs with packet headers + + Tags may only be added to mbufs with packet headers (MBUF_PKTHDR flag is set). Mbuf tags are freed when the mbuf is freed or when mbuf_tag_free is called. @param mbuf The mbuf to attach this tag to. @@ -1055,9 +1311,8 @@ errno_t mbuf_tag_id_find(const char *module_string, buffer allocated for the mtag. @result 0 upon success otherwise the errno error. */ -errno_t mbuf_tag_allocate(mbuf_t mbuf, mbuf_tag_id_t module_id, - mbuf_tag_type_t type, size_t length, - mbuf_how_t how, void** data_p); +extern errno_t mbuf_tag_allocate(mbuf_t mbuf, mbuf_tag_id_t module_id, + mbuf_tag_type_t type, size_t length, mbuf_how_t how, void **data_p); /*! @function mbuf_tag_find @@ -1071,8 +1326,8 @@ errno_t mbuf_tag_allocate(mbuf_t mbuf, mbuf_tag_id_t module_id, buffer allocated for the mtag. @result 0 upon success otherwise the errno error. */ -errno_t mbuf_tag_find(mbuf_t mbuf, mbuf_tag_id_t module_id, - mbuf_tag_type_t type, size_t *length, void** data_p); +extern errno_t mbuf_tag_find(mbuf_t mbuf, mbuf_tag_id_t module_id, + mbuf_tag_type_t type, size_t *length, void **data_p); /*! @function mbuf_tag_free @@ -1081,8 +1336,8 @@ errno_t mbuf_tag_find(mbuf_t mbuf, mbuf_tag_id_t module_id, @param module_id The ID of the tag to free. @param type The type of the tag to free. */ -void mbuf_tag_free(mbuf_t mbuf, mbuf_tag_id_t module_id, - mbuf_tag_type_t type); +extern void mbuf_tag_free(mbuf_t mbuf, mbuf_tag_id_t module_id, + mbuf_tag_type_t type); /* mbuf stats */ @@ -1091,37 +1346,79 @@ void mbuf_tag_free(mbuf_t mbuf, mbuf_tag_id_t module_id, @discussion Get the mbuf statistics. @param stats Storage to copy the stats in to. */ -void mbuf_stats(struct mbuf_stat* stats); +extern void mbuf_stats(struct mbuf_stat *stats); +/*! + @enum mbuf_traffic_class_t + @abstract Traffic class of a packet + @discussion Property that represent the category of traffic of a packet. + This information may be used by the driver and at the link level. + @constant MBUF_TC_BE Best effort, normal class. + @constant MBUF_TC_BK Background, low priority or bulk traffic. + @constant MBUF_TC_VI Interactive video, constant bit rate, low latency. + @constant MBUF_TC_VO Interactive voice, constant bit rate, lowest latency. +*/ +typedef enum { +#ifdef XNU_KERNEL_PRIVATE + MBUF_TC_UNSPEC = -1, /* Internal: not specified */ +#endif + MBUF_TC_BE = 0, + MBUF_TC_BK = 1, + MBUF_TC_VI = 2, + MBUF_TC_VO = 3 +#ifdef XNU_KERNEL_PRIVATE + , + MBUF_TC_MAX = 4 /* Internal: traffic class count */ +#endif +} mbuf_traffic_class_t; + +/*! + @function mbuf_get_traffic_class + @discussion Get the traffic class of an mbuf packet + @param mbuf The mbuf to get the traffic class of. + @result The traffic class +*/ +extern mbuf_traffic_class_t mbuf_get_traffic_class(mbuf_t mbuf); + +/*! + @function mbuf_set_traffic_class + @discussion Set the traffic class of an mbuf packet. + @param mbuf The mbuf to set the traffic class on. + @ac The traffic class + @result 0 on success, EINVAL if bad paramater is passed +*/ +extern errno_t mbuf_set_traffic_class(mbuf_t mbuf, mbuf_traffic_class_t tc); /* IF_QUEUE interaction */ -#define IF_ENQUEUE_MBUF(ifq, m) { \ - mbuf_setnextpkt((m), 0); \ - if ((ifq)->ifq_tail == 0) \ - (ifq)->ifq_head = (m); \ - else \ - mbuf_setnextpkt((mbuf_t)(ifq)->ifq_tail, (m)); \ - (ifq)->ifq_tail = (m); \ - (ifq)->ifq_len++; \ -} -#define IF_PREPEND_MBUF(ifq, m) { \ - mbuf_setnextpkt((m), (ifq)->ifq_head); \ - if ((ifq)->ifq_tail == 0) \ - (ifq)->ifq_tail = (m); \ - (ifq)->ifq_head = (m); \ - (ifq)->ifq_len++; \ +#define IF_ENQUEUE_MBUF(ifq, m) { \ + mbuf_setnextpkt((m), 0); \ + if ((ifq)->ifq_tail == 0) \ + (ifq)->ifq_head = (m); \ + else \ + mbuf_setnextpkt((mbuf_t)(ifq)->ifq_tail, (m)); \ + (ifq)->ifq_tail = (m); \ + (ifq)->ifq_len++; \ } -#define IF_DEQUEUE_MBUF(ifq, m) { \ - (m) = (ifq)->ifq_head; \ - if (m) { \ - if (((ifq)->ifq_head = mbuf_nextpkt((m))) == 0) \ - (ifq)->ifq_tail = 0; \ - mbuf_setnextpkt((m), 0); \ - (ifq)->ifq_len--; \ - } \ + +#define IF_PREPEND_MBUF(ifq, m) { \ + mbuf_setnextpkt((m), (ifq)->ifq_head); \ + if ((ifq)->ifq_tail == 0) \ + (ifq)->ifq_tail = (m); \ + (ifq)->ifq_head = (m); \ + (ifq)->ifq_len++; \ } +#define IF_DEQUEUE_MBUF(ifq, m) { \ + (m) = (ifq)->ifq_head; \ + if (m) { \ + if (((ifq)->ifq_head = mbuf_nextpkt((m))) == 0) \ + (ifq)->ifq_tail = 0; \ + mbuf_setnextpkt((m), 0); \ + (ifq)->ifq_len--; \ + } \ +} -#endif +__END_DECLS +#endif /* __KPI_MBUF__ */