]> git.saurik.com Git - apple/xnu.git/blob - bsd/sys/kpi_mbuf.h
xnu-2782.30.5.tar.gz
[apple/xnu.git] / bsd / sys / kpi_mbuf.h
1 /*
2 * Copyright (c) 2008-2014 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 /*!
52 @enum mbuf_flags_t
53 @abstract Constants defining mbuf flags. Only the flags listed below
54 can be set or retrieved.
55 @constant MBUF_EXT Indicates this mbuf has external data.
56 @constant MBUF_PKTHDR Indicates this mbuf has a packet header.
57 @constant MBUF_EOR Indicates this mbuf is the end of a record.
58 @constant MBUF_LOOP Indicates this packet is looped back.
59 @constant MBUF_BCAST Indicates this packet will be sent or was
60 received as a brodcast.
61 @constant MBUF_MCAST Indicates this packet will be sent or was
62 received as a multicast.
63 @constant MBUF_FRAG Indicates this packet is a fragment of a larger
64 packet.
65 @constant MBUF_FIRSTFRAG Indicates this packet is the first fragment.
66 @constant MBUF_LASTFRAG Indicates this packet is the last fragment.
67 @constant MBUF_PROMISC Indicates this packet was only received
68 because the interface is in promiscuous mode. This should be set
69 by the demux function. These packets will be discarded after
70 being passed to any interface filters.
71 */
72 enum {
73 MBUF_EXT = 0x0001, /* has associated external storage */
74 MBUF_PKTHDR = 0x0002, /* start of record */
75 MBUF_EOR = 0x0004, /* end of record */
76 MBUF_LOOP = 0x0040, /* packet is looped back */
77
78 MBUF_BCAST = 0x0100, /* send/received as link-level broadcast */
79 MBUF_MCAST = 0x0200, /* send/received as link-level multicast */
80 MBUF_FRAG = 0x0400, /* packet is a fragment of a larger packet */
81 MBUF_FIRSTFRAG = 0x0800, /* packet is first fragment */
82 MBUF_LASTFRAG = 0x1000, /* packet is last fragment */
83 MBUF_PROMISC = 0x2000, /* packet is promiscuous */
84 MBUF_HASFCS = 0x4000 /* packet has FCS */
85 };
86 typedef u_int32_t mbuf_flags_t;
87
88 /*!
89 @enum mbuf_type_t
90 @abstract Types of mbufs.
91 @discussion Some mbufs represent packets, some represnt data waiting
92 on sockets. Other mbufs store control data or other various
93 structures. The mbuf type is used to store what sort of data the
94 mbuf contains.
95 @constant MBUF_MT_FREE Indicates the mbuf is free and is
96 sitting on the queue of free mbufs. If you find that an mbuf you
97 have a reference to has this type, something has gone terribly
98 wrong.
99 @constant MBUF_MT_DATA Indicates this mbuf is being used to store
100 data.
101 @constant MBUF_MT_HEADER Indicates this mbuf has a packet header,
102 this is probably a packet.
103 @constant MBUF_MT_SOCKET Socket structure.
104 @constant MBUF_MT_PCB Protocol control block.
105 @constant MBUF_MT_RTABLE Routing table entry.
106 @constant MBUF_MT_HTABLE IMP host tables???.
107 @constant MBUF_MT_ATABLE Address resolution table data.
108 @constant MBUF_MT_SONAME Socket name, usually a sockaddr of some
109 sort.
110 @constant MBUF_MT_FTABLE Fragment reassembly header.
111 @constant MBUF_MT_RIGHTS Access rights.
112 @constant MBUF_MT_IFADDR Interface address.
113 @constant MBUF_MT_CONTROL Extra-data protocol message (control
114 message).
115 @constant MBUF_MT_OOBDATA Out of band data.
116 */
117 enum {
118 MBUF_TYPE_FREE = 0, /* should be on free list */
119 MBUF_TYPE_DATA = 1, /* dynamic (data) allocation */
120 MBUF_TYPE_HEADER = 2, /* packet header */
121 MBUF_TYPE_SOCKET = 3, /* socket structure */
122 MBUF_TYPE_PCB = 4, /* protocol control block */
123 MBUF_TYPE_RTABLE = 5, /* routing tables */
124 MBUF_TYPE_HTABLE = 6, /* IMP host tables */
125 MBUF_TYPE_ATABLE = 7, /* address resolution tables */
126 MBUF_TYPE_SONAME = 8, /* socket name */
127 MBUF_TYPE_SOOPTS = 10, /* socket options */
128 MBUF_TYPE_FTABLE = 11, /* fragment reassembly header */
129 MBUF_TYPE_RIGHTS = 12, /* access rights */
130 MBUF_TYPE_IFADDR = 13, /* interface address */
131 MBUF_TYPE_CONTROL = 14, /* extra-data protocol message */
132 MBUF_TYPE_OOBDATA = 15 /* expedited data */
133 };
134 typedef u_int32_t mbuf_type_t;
135
136 /*!
137 @enum mbuf_csum_request_flags_t
138 @abstract Checksum performed/requested flags.
139 @discussion Mbufs often contain packets. Some hardware supports
140 performing checksums in hardware. The stack uses these flags to
141 indicate to the driver what sort of checksumming should be
142 handled in by the driver/hardware. These flags will only be set
143 if the driver indicates that it supports the corresponding
144 checksums using ifnet_set_offload.
145 @constant MBUF_CSUM_REQ_IP Indicates the IP checksum has not been
146 calculated yet.
147 @constant MBUF_CSUM_REQ_TCP Indicates the TCP checksum has not been
148 calculated yet.
149 @constant MBUF_CSUM_REQ_UDP Indicates the UDP checksum has not been
150 calculated yet.
151 @constant MBUF_CSUM_REQ_TCPIPV6 Indicates the TCP checksum for IPv6
152 has not been calculated yet.
153 @constant MBUF_CSUM_REQ_UDPIPV6 Indicates the UDP checksum for IPv6
154 has not been calculated yet.
155 */
156 enum {
157 MBUF_TSO_IPV4 = 0x100000,
158 MBUF_TSO_IPV6 = 0x200000
159 };
160 typedef u_int32_t mbuf_tso_request_flags_t;
161
162 enum {
163 #ifdef KERNEL_PRIVATE
164 MBUF_CSUM_PARTIAL = 0x1000, /* 16-bit 1's complement sum */
165 MBUF_CSUM_REQ_SUM16 = MBUF_CSUM_PARTIAL,
166 #endif /* KERNEL_PRIVATE */
167 MBUF_CSUM_REQ_IP = 0x0001,
168 MBUF_CSUM_REQ_TCP = 0x0002,
169 MBUF_CSUM_REQ_UDP = 0x0004,
170 MBUF_CSUM_REQ_TCPIPV6 = 0x0020,
171 MBUF_CSUM_REQ_UDPIPV6 = 0x0040
172 };
173 typedef u_int32_t mbuf_csum_request_flags_t;
174
175 /*!
176 @enum mbuf_csum_performed_flags_t
177 @abstract Checksum performed/requested flags.
178 @discussion Mbufs often contain packets. Some hardware supports
179 performing checksums in hardware. The driver uses these flags to
180 communicate to the stack the checksums that were calculated in
181 hardware.
182 @constant MBUF_CSUM_DID_IP Indicates that the driver/hardware verified
183 the IP checksum in hardware.
184 @constant MBUF_CSUM_IP_GOOD Indicates whether or not the IP checksum
185 was good or bad. Only valid when MBUF_CSUM_DID_IP is set.
186 @constant MBUF_CSUM_DID_DATA Indicates that the TCP or UDP checksum
187 was calculated. The value for the checksum calculated in
188 hardware should be passed as the second parameter of
189 mbuf_set_csum_performed. The hardware calculated checksum value
190 can be retrieved using the second parameter passed to
191 mbuf_get_csum_performed. This should be done for IPv4 or IPv6.
192 @constant MBUF_CSUM_PSEUDO_HDR If set, this indicates that the
193 checksum value for MBUF_CSUM_DID_DATA includes the pseudo header
194 value. If this is not set, the stack will calculate the pseudo
195 header value and add that to the checksum. The value of this bit
196 is only valid when MBUF_CSUM_DID_DATA is set.
197 */
198 enum {
199 #ifdef KERNEL_PRIVATE
200 MBUF_CSUM_TCP_SUM16 = MBUF_CSUM_PARTIAL,
201 #endif /* KERNEL_PRIVATE */
202 MBUF_CSUM_DID_IP = 0x0100,
203 MBUF_CSUM_IP_GOOD = 0x0200,
204 MBUF_CSUM_DID_DATA = 0x0400,
205 MBUF_CSUM_PSEUDO_HDR = 0x0800
206 };
207 typedef u_int32_t mbuf_csum_performed_flags_t;
208
209 /*!
210 @enum mbuf_how_t
211 @abstract Method of allocating an mbuf.
212 @discussion Blocking on the input or output path can impact
213 performance. There are some cases where making a blocking call
214 is acceptable. When in doubt, use MBUF_DONTWAIT.
215 @constant MBUF_WAITOK Allow a call to allocate an mbuf to block.
216 @constant MBUF_DONTWAIT Don't allow the mbuf allocation call to
217 block, if blocking is necessary fail and return immediately.
218 */
219 enum {
220 MBUF_WAITOK = 0, /* Ok to block to get memory */
221 MBUF_DONTWAIT = 1 /* Don't block, fail if blocking would be required */
222 };
223 typedef u_int32_t mbuf_how_t;
224
225 typedef u_int32_t mbuf_tag_id_t;
226 typedef u_int16_t mbuf_tag_type_t;
227
228 /*!
229 @struct mbuf_stat
230 @discussion The mbuf_stat contains mbuf statistics.
231 @field mbufs Number of mbufs (free or otherwise).
232 @field clusters Number of clusters (free or otherwise).
233 @field clfree Number of free clusters.
234 @field drops Number of times allocation failed.
235 @field wait Number of times allocation blocked.
236 @field drain Number of times protocol drain functions were called.
237 @field mtypes An array of counts of each type of mbuf allocated.
238 @field mcfail Number of times m_copym failed.
239 @field mpfail Number of times m_pullup failed.
240 @field msize Length of an mbuf.
241 @field mclbytes Length of an mbuf cluster.
242 @field minclsize Minimum length of data to allocate a cluster.
243 Anything smaller than this should be placed in chained mbufs.
244 @field mlen Length of data in an mbuf.
245 @field mhlen Length of data in an mbuf with a packet header.
246 @field bigclusters Number of big clusters.
247 @field bigclfree Number of unused big clusters.
248 @field bigmclbytes Length of a big mbuf cluster.
249 */
250 struct mbuf_stat {
251 u_int32_t mbufs; /* mbufs obtained from page pool */
252 u_int32_t clusters; /* clusters obtained from page pool */
253 u_int32_t clfree; /* free clusters */
254 u_int32_t drops; /* times failed to find space */
255 u_int32_t wait; /* times waited for space */
256 u_int32_t drain; /* times drained protocols for space */
257 u_short mtypes[256]; /* type specific mbuf allocations */
258 u_int32_t mcfail; /* times m_copym failed */
259 u_int32_t mpfail; /* times m_pullup failed */
260 u_int32_t msize; /* length of an mbuf */
261 u_int32_t mclbytes; /* length of an mbuf cluster */
262 u_int32_t minclsize; /* min length of data to allocate a cluster */
263 u_int32_t mlen; /* length of data in an mbuf */
264 u_int32_t mhlen; /* length of data in a header mbuf */
265 u_int32_t bigclusters; /* number of big clusters */
266 u_int32_t bigclfree; /* number of big clustser free */
267 u_int32_t bigmclbytes; /* length of data in a big cluster */
268 };
269
270 /* Parameter for m_copym to copy all bytes */
271 #define MBUF_COPYALL 1000000000
272
273 __BEGIN_DECLS
274 /* Data access */
275 /*!
276 @function mbuf_data
277 @discussion Returns a pointer to the start of data in this mbuf.
278 There may be additional data on chained mbufs. The data you're
279 looking for may not be virtually contiguous if it spans more
280 than one mbuf. In addition, data that is virtually contiguous
281 might not be represented by physically contiguous pages; see
282 further comments in mbuf_data_to_physical. Use mbuf_len to
283 determine the lenght of data available in this mbuf. If a data
284 structure you want to access stradles two mbufs in a chain,
285 either use mbuf_pullup to get the data contiguous in one mbuf
286 or copy the pieces of data from each mbuf in to a contiguous
287 buffer. Using mbuf_pullup has the advantage of not having to
288 copy the data. On the other hand, if you don't make sure there
289 is space in the mbuf, mbuf_pullup may fail and free the mbuf.
290 @param mbuf The mbuf.
291 @result A pointer to the data in the mbuf.
292 */
293 extern void *mbuf_data(mbuf_t mbuf);
294
295 /*!
296 @function mbuf_datastart
297 @discussion Returns the start of the space set aside for storing
298 data in an mbuf. An mbuf's data may come from a cluster or be
299 embedded in the mbuf structure itself. The data pointer
300 retrieved by mbuf_data may not be at the start of the data
301 (mbuf_leadingspace will be non-zero). This function will return
302 a pointer that matches mbuf_data() - mbuf_leadingspace().
303 @param mbuf The mbuf.
304 @result A pointer to smallest possible value for data.
305 */
306 extern void *mbuf_datastart(mbuf_t mbuf);
307
308 /*!
309 @function mbuf_setdata
310 @discussion Sets the data and length values for an mbuf. The data
311 value must be in a valid range. In the case of an mbuf with a cluster,
312 the data value must point to a location in the cluster and the data
313 value plus the length, must be less than the end of the cluster. For
314 data embedded directly in an mbuf (no cluster), the data value must
315 fall somewhere between the start and end of the data area in the
316 mbuf and the data + length must also be in the same range.
317 @param mbuf The mbuf.
318 @param data The new pointer value for data.
319 @param len The new length of data in the mbuf.
320 @result 0 on success, errno error on failure.
321 */
322 extern errno_t mbuf_setdata(mbuf_t mbuf, void *data, size_t len);
323
324 /*!
325 @function mbuf_align_32
326 @discussion mbuf_align_32 is a replacement for M_ALIGN and MH_ALIGN.
327 mbuf_align_32 will set the data pointer to a location aligned on
328 a four byte boundry with at least 'len' bytes between the data
329 pointer and the end of the data block.
330 @param mbuf The mbuf.
331 @param len The minimum length of space that should follow the new
332 data location.
333 @result 0 on success, errno error on failure.
334 */
335 extern errno_t mbuf_align_32(mbuf_t mbuf, size_t len);
336
337 /*!
338 @function mbuf_data_to_physical
339 @discussion mbuf_data_to_physical is a replacement for mcl_to_paddr.
340 Given a pointer returned from mbuf_data of mbuf_datastart,
341 mbuf_data_to_physical will return the phyical address for that
342 block of data. Note that even though the data is in virtually
343 contiguous span, the underlying physical pages might not be
344 physically contiguous. Because of this, callers must ensure
345 to call this routine for each page boundary. Device drivers
346 that deal with DMA are strongly encouraged to utilize the
347 IOMbufNaturalMemoryCursor and walk down the list of vectors
348 instead of using this interface to obtain the physical address.
349 Use of this routine is therefore discouraged.
350 @param ptr A pointer to data stored in an mbuf.
351 @result The 64 bit physical address of the mbuf data or NULL if ptr
352 does not point to data stored in an mbuf.
353 */
354 extern addr64_t mbuf_data_to_physical(void *ptr);
355
356
357 /* Allocation */
358
359 /*!
360 @function mbuf_get
361 @discussion Allocates an mbuf without a cluster for external data.
362 @param how Blocking or non-blocking.
363 @param type The type of the mbuf.
364 @param mbuf The mbuf.
365 @result 0 on success, errno error on failure.
366 */
367 extern errno_t mbuf_get(mbuf_how_t how, mbuf_type_t type, mbuf_t *mbuf);
368
369 /*!
370 @function mbuf_gethdr
371 @discussion Allocates an mbuf without a cluster for external data.
372 Sets a flag to indicate there is a packet header and initializes
373 the packet header.
374 @param how Blocking or non-blocking.
375 @param type The type of the mbuf.
376 @param mbuf The mbuf.
377 @result 0 on success, errno error on failure.
378 */
379 extern errno_t mbuf_gethdr(mbuf_how_t how, mbuf_type_t type, mbuf_t *mbuf);
380
381 /*!
382 @function mbuf_attachcluster
383 @discussion Attach an external buffer as a cluster for an mbuf. If mbuf
384 points to a NULL mbuf_t, an mbuf will be allocated for you. If
385 mbuf points to a non-NULL mbuf_t, the user-supplied mbuf will
386 be used instead. The caller is responsible for allocating the
387 external buffer by calling mbuf_alloccluster().
388 @param how Blocking or non-blocking.
389 @param type The type of the mbuf if mbuf is non-NULL; otherwise ignored.
390 @param mbuf Pointer to the address of the mbuf; if NULL, an mbuf will
391 be allocated, otherwise, it must point to a valid mbuf address.
392 If the user-supplied mbuf is already attached to a cluster, the
393 current cluster will be freed before the mbuf gets attached to
394 the supplied external buffer. Note that this routine may return
395 a different mbuf_t than the one you passed in.
396 @param extbuf Address of the external buffer.
397 @param extfree Free routine for the external buffer; the caller is
398 required to defined a routine that will be invoked when the
399 mbuf is freed.
400 @param extsize Size of the external buffer.
401 @param extarg Private value that will be passed to the free routine
402 when it is called at the time the mbuf is freed.
403 @result 0 on success
404 EINVAL - Invalid parameter
405 ENOMEM - Not enough memory available
406 */
407 extern errno_t mbuf_attachcluster(mbuf_how_t how, mbuf_type_t type,
408 mbuf_t *mbuf, caddr_t extbuf, void (*extfree)(caddr_t , u_int, caddr_t),
409 size_t extsize, caddr_t extarg);
410
411 /*!
412 @function mbuf_alloccluster
413 @discussion Allocate a cluster that can be later attached to an
414 mbuf by calling mbuf_attachcluster(). The allocated cluster
415 can also be freed (without being attached to an mbuf) by
416 calling mbuf_freecluster(). At the moment this routine
417 will either return a cluster of 2048, 4096 or 16384 bytes
418 depending on the requested size. Note that clusters greater
419 than 4096 bytes might not be available in all configurations;
420 the caller must additionally check for ENOTSUP (see below).
421 @param how Blocking or non-blocking.
422 @param size Pointer to size of requested cluster. Sizes up to 2048
423 will be rounded up to 2048; sizes greater than 2048 and up
424 to 4096 will be rounded up to 4096. Sizes greater than 4096
425 will be rounded up to 16384.
426 @param addr Pointer to the address of the requested cluster.
427 @result 0 on success or ENOMEM if failure. If the caller requests
428 greater than 4096 bytes and the system is unable to fulfill
429 the request due to the lack of jumbo clusters support based
430 on the configuration, this routine will return ENOTSUP.
431 In this case, the caller is advised to use 4096 bytes or
432 smaller during subseqent requests.
433 */
434 extern errno_t mbuf_alloccluster(mbuf_how_t how, size_t *size, caddr_t *addr);
435
436 /*!
437 @function mbuf_freecluster
438 @discussion Free a cluster that was previously allocated by a call
439 to mbuf_alloccluster(). The caller must pass the actual
440 size of the cluster as returned by mbuf_alloccluster(),
441 which at this point must be either 2048, 4096 or 16384 bytes.
442 @param addr The address of the cluster.
443 @param size The actual size of the cluster.
444 */
445 extern void mbuf_freecluster(caddr_t addr, size_t size);
446
447 /*!
448 @function mbuf_getcluster
449 @discussion Allocate a cluster of the requested size and attach it to
450 an mbuf for use as external data. If mbuf points to a NULL
451 mbuf_t, an mbuf will be allocated for you. If mbuf points to
452 a non-NULL mbuf_t, mbuf_getcluster may return a different
453 mbuf_t than the one you passed in.
454 @param how Blocking or non-blocking.
455 @param type The type of the mbuf.
456 @param size The size of the cluster to be allocated. Supported sizes
457 for a cluster are be 2048, 4096, or 16384. Any other value
458 with return EINVAL. Note that clusters greater than 4096
459 bytes might not be available in all configurations; the
460 caller must additionally check for ENOTSUP (see below).
461 @param mbuf The mbuf the cluster will be attached to.
462 @result 0 on success, errno error on failure. If you specified NULL
463 for the mbuf, any intermediate mbuf that may have been allocated
464 will be freed. If you specify an mbuf value in *mbuf,
465 mbuf_mclget will not free it.
466 EINVAL - Invalid parameter
467 ENOMEM - Not enough memory available
468 ENOTSUP - The caller had requested greater than 4096 bytes
469 cluster and the system is unable to fulfill it due to the
470 lack of jumbo clusters support based on the configuration.
471 In this case, the caller is advised to use 4096 bytes or
472 smaller during subsequent requests.
473 */
474 extern errno_t mbuf_getcluster(mbuf_how_t how, mbuf_type_t type, size_t size,
475 mbuf_t *mbuf);
476
477 /*!
478 @function mbuf_mclget
479 @discussion Allocate a cluster and attach it to an mbuf for use as
480 external data. If mbuf points to a NULL mbuf_t, an mbuf will be
481 allocated for you. If mbuf points to a non-NULL mbuf_t,
482 mbuf_mclget may return a different mbuf_t than the one you
483 passed in.
484 @param how Blocking or non-blocking.
485 @param type The type of the mbuf.
486 @param mbuf The mbuf the cluster will be attached to.
487 @result 0 on success, errno error on failure. If you specified NULL
488 for the mbuf, any intermediate mbuf that may have been allocated
489 will be freed. If you specify an mbuf value in *mbuf,
490 mbuf_mclget will not free it.
491 */
492 extern errno_t mbuf_mclget(mbuf_how_t how, mbuf_type_t type, mbuf_t *mbuf);
493
494 /*!
495 @function mbuf_allocpacket
496 @discussion Allocate an mbuf chain to store a single packet of the
497 requested length. According to the requested length, a chain
498 of mbufs will be created. The mbuf type will be set to
499 MBUF_TYPE_DATA. The caller may specify the maximum number of
500 buffer.
501 @param how Blocking or non-blocking
502 @param packetlen The total length of the packet mbuf to be allocated.
503 The length must be greater than zero.
504 @param maxchunks An input/output pointer to the maximum number of mbufs
505 segments making up the chain. On input, if maxchunks is NULL,
506 or the value pointed to by maxchunks is zero, the packet will
507 be made up of as few or as many buffer segments as necessary
508 to fit the length. The allocation will fail with ENOBUFS if
509 the number of segments requested is too small and the sum of
510 the maximum size of each individual segment is less than the
511 packet length. On output, if the allocation succeed and
512 maxchunks is non-NULL, it will point to the actual number
513 of segments allocated.
514 Additional notes for packetlen greater than 4096 bytes:
515 the caller may pass a non-NULL maxchunks and initialize it
516 with zero such that upon success, it can find out whether
517 or not the system configuration allows for larger than
518 4096 bytes cluster allocations, by checking on the value
519 pointed to by maxchunks. E.g. a request for 9018 bytes may
520 result in 1 chunk when jumbo clusters are available, or
521 3 chunks otherwise.
522 @param Upon success, *mbuf will be a reference to the new mbuf.
523 @result Returns 0 upon success or the following error code:
524 EINVAL - Invalid parameter
525 ENOMEM - Not enough memory available
526 ENOBUFS - Buffers not big enough for the maximum number of
527 chunks requested
528 */
529 extern errno_t mbuf_allocpacket(mbuf_how_t how, size_t packetlen,
530 unsigned int * maxchunks, mbuf_t *mbuf);
531
532 /*!
533 @function mbuf_allocpacket_list
534 @discussion Allocate a linked list of packets. According to the
535 requested length, each packet will made of a chain of one
536 or more mbufs. The mbuf type will be set to MBUF_TYPE_DATA.
537 The caller may specify the maximum number of element for
538 each mbuf chain making up a packet.
539 @param numpkts Number of packets to allocate
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
544 mbufs segments making up the chain. On input, if maxchunks is
545 zero, or the value pointed to by maxchunks is zero, the packet
546 will be made 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 zero, 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 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_list(unsigned int numpkts, mbuf_how_t how,
569 size_t packetlen, unsigned int * maxchunks, mbuf_t *mbuf);
570
571
572 /*!
573 @function mbuf_getpacket
574 @discussion Allocate an mbuf, allocate and attach a cluster, and set
575 the packet header flag.
576 @param how Blocking or non-blocking.
577 @param mbuf Upon success, *mbuf will be a reference to the new mbuf.
578 @result 0 on success, errno error on failure.
579 */
580 extern errno_t mbuf_getpacket(mbuf_how_t how, mbuf_t *mbuf);
581
582 /*!
583 @function mbuf_free
584 @discussion Frees a single mbuf. Not commonly used because it
585 doesn't touch the rest of the mbufs on the chain.
586 @param mbuf The mbuf to free.
587 @result The next mbuf in the chain.
588 */
589 extern mbuf_t mbuf_free(mbuf_t mbuf);
590
591 /*!
592 @function mbuf_freem
593 @discussion Frees a chain of mbufs link through mnext.
594 @param mbuf The first mbuf in the chain to free.
595 */
596 extern void mbuf_freem(mbuf_t mbuf);
597
598 /*!
599 @function mbuf_freem_list
600 @discussion Frees linked list of mbuf chains. Walks through
601 mnextpackt and does the equivalent of mbuf_freem to each.
602 @param mbuf The first mbuf in the linked list to free.
603 @result The number of mbufs freed.
604 */
605 extern int mbuf_freem_list(mbuf_t mbuf);
606
607 /*!
608 @function mbuf_leadingspace
609 @discussion Determines the space available in the mbuf proceeding
610 the current data.
611 @param mbuf The mbuf.
612 @result The number of unused bytes at the start of the mbuf.
613 */
614 extern size_t mbuf_leadingspace(const mbuf_t mbuf);
615
616 /*!
617 @function mbuf_trailingspace
618 @discussion Determines the space available in the mbuf following
619 the current data.
620 @param mbuf The mbuf.
621 @result The number of unused bytes following the current data.
622 */
623 extern size_t mbuf_trailingspace(const mbuf_t mbuf);
624
625 /* Manipulation */
626
627 /*!
628 @function mbuf_copym
629 @discussion Copies len bytes from offset from src to a new mbuf. If
630 the original mbuf contains a packet header, the new mbuf will
631 contain similar packet header except for any tags which may be
632 associated with the original mbuf. mbuf_dup() should be used
633 instead if tags are to be copied to the new mbuf.
634 @param src The source mbuf.
635 @param offset The offset in the mbuf to start copying from.
636 @param len The the number of bytes to copy.
637 @param how To block or not to block, that is a question.
638 @param new_mbuf Upon success, the newly allocated mbuf.
639 @result 0 upon success otherwise the errno error.
640 */
641 extern errno_t mbuf_copym(const mbuf_t src, size_t offset, size_t len,
642 mbuf_how_t how, mbuf_t *new_mbuf);
643
644 /*!
645 @function mbuf_dup
646 @discussion Exactly duplicates an mbuf chain. If the original mbuf
647 contains a packet header (including tags), the new mbuf will have
648 the same packet header contents and a copy of each tag associated
649 with the original mbuf.
650 @param src The source mbuf.
651 @param how Blocking or non-blocking.
652 @param new_mbuf Upon success, the newly allocated mbuf.
653 @result 0 upon success otherwise the errno error.
654 */
655 extern errno_t mbuf_dup(const mbuf_t src, mbuf_how_t how, mbuf_t *new_mbuf);
656
657 /*!
658 @function mbuf_prepend
659 @discussion Prepend len bytes to an mbuf. If there is space
660 (mbuf_leadingspace >= len), the mbuf's data ptr is changed and
661 the same mbuf is returned. If there is no space, a new mbuf may
662 be allocated and prepended to the mbuf chain. If the operation
663 fails, the mbuf may be freed (*mbuf will be NULL).
664 @param mbuf The mbuf to prepend data to. This may change if a new
665 mbuf must be allocated or may be NULL if the operation fails.
666 @param len The length, in bytes, to be prepended to the mbuf.
667 @param how Blocking or non-blocking.
668 @result 0 upon success otherwise the errno error.
669 */
670 extern errno_t mbuf_prepend(mbuf_t *mbuf, size_t len, mbuf_how_t how);
671
672 /*!
673 @function mbuf_split
674 @discussion Split an mbuf chain at a specific offset.
675 @param src The mbuf to be split.
676 @param offset The offset in the buffer where the mbuf should be
677 split.
678 @param how Blocking or non-blocking.
679 @param new_mbuf Upon success, the second half of the split mbuf
680 chain.
681 @result 0 upon success otherwise the errno error. In the case of
682 failure, the original mbuf chain passed in to src will be
683 preserved.
684 */
685 extern errno_t mbuf_split(mbuf_t src, size_t offset, mbuf_how_t how,
686 mbuf_t *new_mbuf);
687
688 /*!
689 @function mbuf_pullup
690 @discussion Move the next len bytes in to mbuf from other mbufs in
691 the chain. This is commonly used to get the IP and TCP or UDP
692 header contiguous in the first mbuf. If mbuf_pullup fails, the
693 entire mbuf chain will be freed.
694 @param mbuf The mbuf in the chain the data should be contiguous in.
695 @param len The number of bytes to pull from the next mbuf(s).
696 @result 0 upon success otherwise the errno error. In the case of an
697 error, the mbuf chain has been freed.
698 */
699 extern errno_t mbuf_pullup(mbuf_t *mbuf, size_t len);
700
701 /*!
702 @function mbuf_pulldown
703 @discussion Make length bytes at offset in the mbuf chain
704 contiguous. Nothing before offset bytes in the chain will be
705 modified. Upon return, location will be the mbuf the data is
706 contiguous in and offset will be the offset in that mbuf at
707 which the data is located. In the case of a failure, the mbuf
708 chain will be freed.
709 @param src The start of the mbuf chain.
710 @param offset Pass in a pointer to a value with the offset of the
711 data you're interested in making contiguous. Upon success, this
712 will be overwritten with the offset from the mbuf returned in
713 location.
714 @param length The length of data that should be made contiguous.
715 @param location Upon success, *location will be the mbuf the data is
716 in.
717 @result 0 upon success otherwise the errno error.
718 */
719 extern errno_t mbuf_pulldown(mbuf_t src, size_t *offset, size_t length,
720 mbuf_t *location);
721
722 /*!
723 @function mbuf_adj
724 @discussion Trims len bytes from the mbuf. If the length is greater
725 than zero, the bytes are trimmed from the front of the mbuf. If
726 the length is less than zero, the bytes are trimmed from the end
727 of the mbuf chain.
728 @param mbuf The mbuf chain to trim.
729 @param len The number of bytes to trim from the mbuf chain.
730 */
731 extern void mbuf_adj(mbuf_t mbuf, int len);
732
733 /*!
734 @function mbuf_adjustlen
735 @discussion Adds amount to the mbuf len. Verifies that the new
736 length is valid (greater than or equal to zero and less than
737 maximum amount of data that may be stored in the mbuf). This
738 function will not adjust the packet header length field or
739 affect any other mbufs in a chain.
740 @param mbuf The mbuf to adjust.
741 @param amount The number of bytes increment the length by.
742 @result 0 upon success otherwise the errno error.
743 */
744 extern errno_t mbuf_adjustlen(mbuf_t mbuf, int amount);
745
746 /*!
747 @function mbuf_concatenate
748 @discussion Concatenate mbuf chain src to dst using m_next and return
749 a chain which represents the concatenated chain. The routine
750 does not prevent two chains of different mbuf types to be
751 concatenated, nor does it modify any packet header in the
752 destination chain. Therefore, it's the responsibility of the
753 caller to ensure that the resulted concatenated mbuf chain is
754 correct for further usages.
755 @param dst The destination mbuf chain.
756 @param src The source mbuf chain.
757 @result A pointer to the head of the concatenated mbuf chain. This
758 should be treated as the updated destination mbuf chain; the
759 caller must no longer refer to the original src or dst mbuf
760 chain. Otherwise it returns NULL if the original dst mbuf
761 chain is NULL.
762 */
763 extern mbuf_t mbuf_concatenate(mbuf_t dst, mbuf_t src);
764
765 /*!
766 @function mbuf_copydata
767 @discussion Copies data out of an mbuf in to a specified buffer. If
768 the data is stored in a chain of mbufs, the data will be copied
769 from each mbuf in the chain until length bytes have been copied.
770 @param mbuf The mbuf chain to copy data out of.
771 @param offset The offset in to the mbuf to start copying.
772 @param length The number of bytes to copy.
773 @param out_data A pointer to the location where the data will be
774 copied.
775 @result 0 upon success otherwise the errno error.
776 */
777 extern errno_t mbuf_copydata(const mbuf_t mbuf, size_t offset, size_t length,
778 void *out_data);
779
780 /*!
781 @function mbuf_copyback
782 @discussion Copies data from a buffer to an mbuf chain.
783 mbuf_copyback will grow the chain to fit the specified buffer.
784
785 If mbuf_copydata is unable to allocate enough mbufs to grow the
786 chain, ENOBUFS will be returned. The mbuf chain will be shorter
787 than expected but all of the data up to the end of the mbuf
788 chain will be valid.
789
790 If an offset is specified, mbuf_copyback will skip that many
791 bytes in the mbuf chain before starting to write the buffer in
792 to the chain. If the mbuf chain does not contain this many
793 bytes, mbufs will be allocated to create the space.
794 @param mbuf The first mbuf in the chain to copy the data in to.
795 @param offset Offset in bytes to skip before copying data.
796 @param length The length, in bytes, of the data to copy in to the mbuf
797 chain.
798 @param data A pointer to data in the kernel's address space.
799 @param how Blocking or non-blocking.
800 @result 0 upon success, EINVAL or ENOBUFS upon failure.
801 */
802 extern errno_t mbuf_copyback(mbuf_t mbuf, size_t offset, size_t length,
803 const void *data, mbuf_how_t how);
804
805 /*!
806 @function mbuf_mclhasreference
807 @discussion Check if a cluster of an mbuf is referenced by another mbuf.
808 References may be taken, for example, as a result of a call to
809 mbuf_split or mbuf_copym
810 @param mbuf The mbuf with the cluster to test.
811 @result 0 if there is no reference by another mbuf, 1 otherwise.
812 */
813 extern int mbuf_mclhasreference(mbuf_t mbuf);
814
815
816 /* mbuf header */
817
818 /*!
819 @function mbuf_next
820 @discussion Returns the next mbuf in the chain.
821 @param mbuf The mbuf.
822 @result The next mbuf in the chain.
823 */
824 extern mbuf_t mbuf_next(const mbuf_t mbuf);
825
826 /*!
827 @function mbuf_setnext
828 @discussion Sets the next mbuf in the chain.
829 @param mbuf The mbuf.
830 @param next The new next mbuf.
831 @result 0 upon success otherwise the errno error.
832 */
833 extern errno_t mbuf_setnext(mbuf_t mbuf, mbuf_t next);
834
835 /*!
836 @function mbuf_nextpkt
837 @discussion Gets the next packet from the mbuf.
838 @param mbuf The mbuf.
839 @result The nextpkt.
840 */
841 extern mbuf_t mbuf_nextpkt(const mbuf_t mbuf);
842
843 /*!
844 @function mbuf_setnextpkt
845 @discussion Sets the next packet attached to this mbuf.
846 @param mbuf The mbuf.
847 @param nextpkt The new next packet.
848 */
849 extern void mbuf_setnextpkt(mbuf_t mbuf, mbuf_t nextpkt);
850
851 /*!
852 @function mbuf_len
853 @discussion Gets the length of data in this mbuf.
854 @param mbuf The mbuf.
855 @result The length.
856 */
857 extern size_t mbuf_len(const mbuf_t mbuf);
858
859 /*!
860 @function mbuf_setlen
861 @discussion Sets the length of data in this packet. Be careful to
862 not set the length over the space available in the mbuf.
863 @param mbuf The mbuf.
864 @param len The new length.
865 @result 0 upon success otherwise the errno error.
866 */
867 extern void mbuf_setlen(mbuf_t mbuf, size_t len);
868
869 /*!
870 @function mbuf_maxlen
871 @discussion Retrieves the maximum length of data that may be stored
872 in this mbuf. This value assumes that the data pointer was set
873 to the start of the possible range for that pointer
874 (mbuf_data_start).
875 @param mbuf The mbuf.
876 @result The maximum lenght of data for this mbuf.
877 */
878 extern size_t mbuf_maxlen(const mbuf_t mbuf);
879
880 /*!
881 @function mbuf_type
882 @discussion Gets the type of mbuf.
883 @param mbuf The mbuf.
884 @result The type.
885 */
886 extern mbuf_type_t mbuf_type(const mbuf_t mbuf);
887
888 /*!
889 @function mbuf_settype
890 @discussion Sets the type of mbuf.
891 @param mbuf The mbuf.
892 @param new_type The new type.
893 @result 0 upon success otherwise the errno error.
894 */
895 extern errno_t mbuf_settype(mbuf_t mbuf, mbuf_type_t new_type);
896
897 /*!
898 @function mbuf_flags
899 @discussion Returns the set flags.
900 @param mbuf The mbuf.
901 @result The flags.
902 */
903 extern mbuf_flags_t mbuf_flags(const mbuf_t mbuf);
904
905 /*!
906 @function mbuf_setflags
907 @discussion Sets the set of set flags.
908 @param mbuf The mbuf.
909 @param flags The flags that should be set, all other flags will be
910 cleared. Certain flags such as MBUF_EXT cannot be altered.
911 @result 0 upon success otherwise the errno error.
912 */
913 extern errno_t mbuf_setflags(mbuf_t mbuf, mbuf_flags_t flags);
914
915 /*!
916 @function mbuf_setflags_mask
917 @discussion Useful for setting or clearing individual flags. Easier
918 than calling mbuf_setflags(m, mbuf_flags(m) | M_FLAG).
919 @param mbuf The mbuf.
920 @param flags The flags that should be set or cleared. Certain flags
921 such as MBUF_EXT cannot be altered.
922 @param mask The mask controlling which flags will be modified.
923 @result 0 upon success otherwise the errno error.
924 */
925 extern errno_t mbuf_setflags_mask(mbuf_t mbuf, mbuf_flags_t flags,
926 mbuf_flags_t mask);
927
928 /*!
929 @function mbuf_copy_pkthdr
930 @discussion Copies the packet header from src to dest.
931 @param src The mbuf from which the packet header will be copied.
932 @param mbuf The mbuf to which the packet header will be copied.
933 @result 0 upon success otherwise the errno error.
934 */
935 extern errno_t mbuf_copy_pkthdr(mbuf_t dest, const mbuf_t src);
936
937 /*!
938 @function mbuf_pkthdr_len
939 @discussion Returns the length as reported by the packet header.
940 @param mbuf The mbuf containing the packet header with the length to
941 be changed.
942 @result The length, in bytes, of the packet.
943 */
944 extern size_t mbuf_pkthdr_len(const mbuf_t mbuf);
945
946 /*!
947 @function mbuf_pkthdr_setlen
948 @discussion Sets the length of the packet in the packet header.
949 @param mbuf The mbuf containing the packet header.
950 @param len The new length of the packet.
951 */
952 extern void mbuf_pkthdr_setlen(mbuf_t mbuf, size_t len);
953
954 #ifdef XNU_KERNEL_PRIVATE
955 /*!
956 @function mbuf_pkthdr_maxlen
957 @discussion Retrieves the maximum length of data that may be stored
958 in this mbuf packet. This value assumes that the data pointer
959 was set to the start of the possible range for that pointer
960 for each mbuf in the packet chain
961 @param mbuf The mbuf.
962 @result The maximum lenght of data for this mbuf.
963 */
964 extern size_t mbuf_pkthdr_maxlen(const mbuf_t mbuf);
965 #endif /* XNU_KERNEL_PRIVATE */
966
967 /*!
968 @function mbuf_pkthdr_adjustlen
969 @discussion Adjusts the length of the packet in the packet header.
970 @param mbuf The mbuf containing the packet header.
971 @param amount The number of bytes to adjust the packet header length
972 field by.
973 */
974 extern void mbuf_pkthdr_adjustlen(mbuf_t mbuf, int amount);
975
976 /*!
977 @function mbuf_pkthdr_rcvif
978 @discussion Returns the interface the packet was received on. This
979 funciton does not modify the reference count of the interface.
980 The interface is only valid for as long as the mbuf is not freed
981 and the rcvif for the mbuf is not changed. Take a reference on
982 the interface that you will release later before doing any of
983 the following: free the mbuf, change the rcvif, pass the mbuf to
984 any function that may free the mbuf or change the rcvif.
985 @param mbuf The mbuf containing the packet header.
986 @result A reference to the interface.
987 */
988 extern ifnet_t mbuf_pkthdr_rcvif(const mbuf_t mbuf);
989
990 /*!
991 @function mbuf_pkthdr_setrcvif
992 @discussion Sets the interface the packet was received on.
993 @param mbuf The mbuf containing the packet header.
994 @param ifnet A reference to an interface.
995 @result 0 upon success otherwise the errno error.
996 */
997 extern errno_t mbuf_pkthdr_setrcvif(mbuf_t mbuf, ifnet_t ifp);
998
999 /*!
1000 @function mbuf_pkthdr_header
1001 @discussion Returns a pointer to the packet header.
1002 @param mbuf The mbuf containing the packet header.
1003 @result A pointer to the packet header.
1004 */
1005 extern void *mbuf_pkthdr_header(const mbuf_t mbuf);
1006
1007 /*!
1008 @function mbuf_pkthdr_setheader
1009 @discussion Sets the pointer to the packet header.
1010 @param mbuf The mbuf containing the packet header.
1011 @param ifnet A pointer to the header.
1012 @result 0 upon success otherwise the errno error.
1013 */
1014 extern void mbuf_pkthdr_setheader(mbuf_t mbuf, void *header);
1015
1016 /* Checksums */
1017
1018 /*!
1019 @function mbuf_inbound_modified
1020 @discussion This function will clear the checksum flags to indicate
1021 that a hardware checksum should not be used. Any filter
1022 modifying data should call this function on an mbuf before
1023 passing the packet up the stack. If a filter modifies a packet
1024 in a way that affects any checksum, the filter is responsible
1025 for either modifying the checksum to compensate for the changes
1026 or verifying the checksum before making the changes and then
1027 modifying the data and calculating a new checksum only if the
1028 original checksum was valid.
1029 @param mbuf The mbuf that has been modified.
1030 */
1031 extern void mbuf_inbound_modified(mbuf_t mbuf);
1032
1033 /*!
1034 @function mbuf_outbound_finalize
1035 @discussion This function will "finalize" the packet allowing your
1036 code to inspect the final packet.
1037
1038 There are a number of operations that are performed in hardware,
1039 such as calculating checksums. This function will perform in
1040 software the various opterations that were scheduled to be done
1041 in hardware. Future operations may include IPSec processing or
1042 vlan support. If you are redirecting a packet to a new interface
1043 which may not have the same hardware support or encapsulating
1044 the packet, you should call this function to force the stack to
1045 calculate and fill out the checksums. This will bypass hardware
1046 checksums but give you a complete packet to work with. If you
1047 need to inspect aspects of the packet which may be generated by
1048 hardware, you must call this function to get an aproximate final
1049 packet. If you plan to modify the packet in any way, you should
1050 call this function.
1051
1052 This function should be called before modifying any outbound
1053 packets.
1054
1055 This function may be called at various levels, in some cases
1056 additional headers may have already been prepended, such as the
1057 case of a packet seen by an interface filter. To handle this,
1058 the caller must pass the protocol family of the packet as well
1059 as the offset from the start of the packet to the protocol
1060 header.
1061 @param mbuf The mbuf that should be finalized.
1062 @param protocol_family The protocol family of the packet in the
1063 mbuf.
1064 @param protocol_offset The offset from the start of the mbuf to the
1065 protocol header. For an IP packet with an ethernet header, this
1066 would be the length of an ethernet header.
1067 */
1068 extern void mbuf_outbound_finalize(mbuf_t mbuf, u_int32_t protocol_family,
1069 size_t protocol_offset);
1070
1071 /*!
1072 @function mbuf_set_vlan_tag
1073 @discussion This function is used by interfaces that support vlan
1074 tagging in hardware. This function will set properties in the
1075 mbuf to indicate which vlan the packet was received for.
1076 @param mbuf The mbuf containing the packet.
1077 @param vlan The protocol family of the aux data to add.
1078 @result 0 upon success otherwise the errno error.
1079 */
1080 extern errno_t mbuf_set_vlan_tag(mbuf_t mbuf, u_int16_t vlan);
1081
1082 /*!
1083 @function mbuf_get_vlan_tag
1084 @discussion This function is used by drivers that support hardware
1085 vlan tagging to determine which vlan this packet belongs to. To
1086 differentiate between the case where the vlan tag is zero and
1087 the case where there is no vlan tag, this function will return
1088 ENXIO when there is no vlan.
1089 @param mbuf The mbuf containing the packet.
1090 @param vlan The protocol family of the aux data to add.
1091 @result 0 upon success otherwise the errno error. ENXIO indicates
1092 that the vlan tag is not set.
1093 */
1094 extern errno_t mbuf_get_vlan_tag(mbuf_t mbuf, u_int16_t *vlan);
1095
1096 /*!
1097 @function mbuf_clear_vlan_tag
1098 @discussion This function will clear any vlan tag associated with
1099 the mbuf.
1100 @param mbuf The mbuf containing the packet.
1101 @result 0 upon success otherwise the errno error.
1102 */
1103 extern errno_t mbuf_clear_vlan_tag(mbuf_t mbuf);
1104
1105 #ifdef KERNEL_PRIVATE
1106 /*
1107 @function mbuf_set_csum_requested
1108 @discussion This function is used by the stack to indicate which
1109 checksums should be calculated in hardware. The stack normally
1110 sets these flags as the packet is processed in the outbound
1111 direction. Just before send the packe to the interface, the
1112 stack will look at these flags and perform any checksums in
1113 software that are not supported by the interface.
1114 @param mbuf The mbuf containing the packet.
1115 @param request Flags indicating which checksums are being requested
1116 for this packet.
1117 @param value This parameter is currently unsupported.
1118 @result 0 upon success otherwise the errno error.
1119 */
1120 extern errno_t mbuf_set_csum_requested(mbuf_t mbuf,
1121 mbuf_csum_request_flags_t request, u_int32_t value);
1122 #endif /* KERNEL_PRIVATE */
1123
1124 /*!
1125 @function mbuf_get_csum_requested
1126 @discussion This function is used by the driver to determine which
1127 checksum operations should be performed in hardware.
1128 @param mbuf The mbuf containing the packet.
1129 @param request Flags indicating which checksums are being requested
1130 for this packet.
1131 @param value This parameter is currently unsupported.
1132 @result 0 upon success otherwise the errno error.
1133 */
1134 extern errno_t mbuf_get_csum_requested(mbuf_t mbuf,
1135 mbuf_csum_request_flags_t *request, u_int32_t *value);
1136
1137 /*!
1138 @function mbuf_get_tso_requested
1139 @discussion This function is used by the driver to determine which
1140 checksum operations should be performed in hardware.
1141 @param mbuf The mbuf containing the packet.
1142 @param request Flags indicating which values are being requested
1143 for this packet.
1144 @param value The requested value.
1145 @result 0 upon success otherwise the errno error.
1146 */
1147 extern errno_t mbuf_get_tso_requested(mbuf_t mbuf,
1148 mbuf_tso_request_flags_t *request, u_int32_t *value);
1149
1150 /*!
1151 @function mbuf_clear_csum_requested
1152 @discussion This function clears the checksum request flags.
1153 @param mbuf The mbuf containing the packet.
1154 @result 0 upon success otherwise the errno error.
1155 */
1156 extern errno_t mbuf_clear_csum_requested(mbuf_t mbuf);
1157
1158 /*!
1159 @function mbuf_set_csum_performed
1160 @discussion This is used by the driver to indicate to the stack which
1161 checksum operations were performed in hardware.
1162 @param mbuf The mbuf containing the packet.
1163 @param flags Flags indicating which hardware checksum operations
1164 were performed.
1165 @param value If the MBUF_CSUM_DID_DATA flag is set, value should be
1166 set to the value of the TCP or UDP header as calculated by the
1167 hardware.
1168 @result 0 upon success otherwise the errno error.
1169 */
1170 extern errno_t mbuf_set_csum_performed(mbuf_t mbuf,
1171 mbuf_csum_performed_flags_t flags, u_int32_t value);
1172
1173 #ifdef KERNEL_PRIVATE
1174 /*
1175 @function mbuf_get_csum_performed
1176 @discussion This is used by the stack to determine which checksums
1177 were calculated in hardware on the inbound path.
1178 @param mbuf The mbuf containing the packet.
1179 @param flags Flags indicating which hardware checksum operations
1180 were performed.
1181 @param value If the MBUF_CSUM_DID_DATA flag is set, value will be
1182 set to the value of the TCP or UDP header as calculated by the
1183 hardware.
1184 @result 0 upon success otherwise the errno error.
1185 */
1186 extern errno_t mbuf_get_csum_performed(mbuf_t mbuf,
1187 mbuf_csum_performed_flags_t *flags, u_int32_t *value);
1188 #endif /* KERNEL_PRIVATE */
1189
1190 /*!
1191 @function mbuf_get_mlen
1192 @discussion This routine returns the number of data bytes in a normal
1193 mbuf, i.e. an mbuf that is not a packet header, nor one with
1194 an external cluster attached to it. This is equivalent to the
1195 legacy MLEN macro.
1196 @result The number of bytes of available data.
1197 */
1198 extern u_int32_t mbuf_get_mlen(void);
1199
1200 /*!
1201 @function mbuf_get_mhlen
1202 @discussion This routine returns the number of data bytes in a packet
1203 header mbuf. This is equivalent to the legacy MHLEN macro.
1204 @result The number of bytes of available data.
1205 */
1206 extern u_int32_t mbuf_get_mhlen(void);
1207
1208 /*!
1209 @function mbuf_get_minclsize
1210 @discussion This routine returns the minimum number of data bytes
1211 before an external cluster is used. This is equivalent to the
1212 legacy MINCLSIZE macro.
1213 @result The minimum number of bytes before a cluster will be used.
1214 */
1215 extern u_int32_t mbuf_get_minclsize(void);
1216
1217 /*!
1218 @function mbuf_clear_csum_performed
1219 @discussion Clears the hardware checksum flags and values.
1220 @param mbuf The mbuf containing the packet.
1221 @result 0 upon success otherwise the errno error.
1222 */
1223 extern errno_t mbuf_clear_csum_performed(mbuf_t mbuf);
1224
1225 /*!
1226 @function mbuf_inet_cksum
1227 @discussions Calculates 16-bit 1's complement Internet checksum of the
1228 transport segment with or without the pseudo header checksum
1229 of a given IPv4 packet. If the caller specifies a non-zero
1230 transport protocol, the checksum returned will also include
1231 the pseudo header checksum for the corresponding transport
1232 header. Otherwise, no header parsing will be done and the
1233 caller may use this to calculate the Internet checksum of
1234 an arbitrary span of data.
1235
1236 This routine does not modify the contents of the packet. If
1237 the caller specifies a non-zero protocol and/or offset, the
1238 routine expects the complete protocol header to be present
1239 at the beginning of the first mbuf.
1240 @param mbuf The mbuf (or chain of mbufs) containing the packet.
1241 @param protocol A zero or non-zero value. A non-zero value specifies
1242 the transport protocol used for pseudo header checksum.
1243 @param offset A zero or non-zero value; if the latter, it specifies
1244 the offset of the transport header from the beginning of mbuf.
1245 @param length The total (non-zero) length of the transport segment.
1246 @param csum Pointer to the checksum variable; upon success, this
1247 routine will return the calculated Internet checksum through
1248 this variable. The caller must set it to a non-NULL value.
1249 @result 0 upon success otherwise the errno error.
1250 */
1251 extern errno_t mbuf_inet_cksum(mbuf_t mbuf, int protocol, u_int32_t offset,
1252 u_int32_t length, u_int16_t *csum);
1253
1254 /*!
1255 @function mbuf_inet6_cksum
1256 @discussions Calculates 16-bit 1's complement Internet checksum of the
1257 transport segment with or without the pseudo header checksum
1258 of a given IPv6 packet. If the caller specifies a non-zero
1259 transport protocol, the checksum returned will also include
1260 the pseudo header checksum for the corresponding transport
1261 header. Otherwise, no header parsing will be done and the
1262 caller may use this to calculate the Internet checksum of
1263 an arbitrary span of data.
1264
1265 This routine does not modify the contents of the packet. If
1266 the caller specifies a non-zero protocol and/or offset, the
1267 routine expects the complete protocol header(s) to be present
1268 at the beginning of the first mbuf.
1269 @param mbuf The mbuf (or chain of mbufs) containing the packet.
1270 @param protocol A zero or non-zero value. A non-zero value specifies
1271 the transport protocol used for pseudo header checksum.
1272 @param offset A zero or non-zero value; if the latter, it specifies
1273 the offset of the transport header from the beginning of mbuf.
1274 @param length The total (non-zero) length of the transport segment.
1275 @param csum Pointer to the checksum variable; upon success, this
1276 routine will return the calculated Internet checksum through
1277 this variable. The caller must set it to a non-NULL value.
1278 @result 0 upon success otherwise the errno error.
1279 */
1280 extern errno_t mbuf_inet6_cksum(mbuf_t mbuf, int protocol, u_int32_t offset,
1281 u_int32_t length, u_int16_t *csum);
1282
1283 /* mbuf tags */
1284
1285 /*!
1286 @function mbuf_tag_id_find
1287 @discussion Lookup the module id for a string. If there is no module
1288 id assigned to this string, a new module id will be assigned.
1289 The string should be the bundle id of the kext. In the case of a
1290 tag that will be shared across multiple kexts, a common bundle
1291 id style string should be used.
1292
1293 The lookup operation is not optimized. A module should call this
1294 function once during startup and chache the module id. The
1295 module id will not be resassigned until the machine reboots.
1296 @param module_string A unique string identifying your module.
1297 Example: com.apple.nke.SharedIP.
1298 @param module_id Upon return, a unique identifier for use with
1299 mbuf_tag_* functions. This identifier is valid until the machine
1300 is rebooted.
1301 @result 0 upon success otherwise the errno error.
1302 */
1303 extern errno_t mbuf_tag_id_find(const char *module_string,
1304 mbuf_tag_id_t *module_id);
1305
1306 /*!
1307 @function mbuf_tag_allocate
1308 @discussion Allocate an mbuf tag. Mbuf tags allow various portions
1309 of the stack to tag mbufs with data that will travel with the
1310 mbuf through the stack.
1311
1312 Tags may only be added to mbufs with packet headers
1313 (MBUF_PKTHDR flag is set). Mbuf tags are freed when the mbuf is
1314 freed or when mbuf_tag_free is called.
1315 @param mbuf The mbuf to attach this tag to.
1316 @param module_id A module identifier returned by mbuf_tag_id_find.
1317 @param type A 16 bit type value. For a given module_id, you can use
1318 a number of different tag types.
1319 @param length The length, in bytes, to allocate for storage that
1320 will be associated with this tag on this mbuf.
1321 @param how Indicate whether you want to block and wait for memory if
1322 memory is not immediately available.
1323 @param data_p Upon successful return, *data_p will point to the
1324 buffer allocated for the mtag.
1325 @result 0 upon success otherwise the errno error.
1326 */
1327 extern errno_t mbuf_tag_allocate(mbuf_t mbuf, mbuf_tag_id_t module_id,
1328 mbuf_tag_type_t type, size_t length, mbuf_how_t how, void **data_p);
1329
1330 /*!
1331 @function mbuf_tag_find
1332 @discussion Find the data associated with an mbuf tag.
1333 @param mbuf The mbuf the tag is attached to.
1334 @param module_id A module identifier returned by mbuf_tag_id_find.
1335 @param type The 16 bit type of the tag to find.
1336 @param length Upon success, the length of data will be store in
1337 *length.
1338 @param data_p Upon successful return, *data_p will point to the
1339 buffer allocated for the mtag.
1340 @result 0 upon success otherwise the errno error.
1341 */
1342 extern errno_t mbuf_tag_find(mbuf_t mbuf, mbuf_tag_id_t module_id,
1343 mbuf_tag_type_t type, size_t *length, void **data_p);
1344
1345 /*!
1346 @function mbuf_tag_free
1347 @discussion Frees a previously allocated mbuf tag.
1348 @param mbuf The mbuf the tag was allocated on.
1349 @param module_id The ID of the tag to free.
1350 @param type The type of the tag to free.
1351 */
1352 extern void mbuf_tag_free(mbuf_t mbuf, mbuf_tag_id_t module_id,
1353 mbuf_tag_type_t type);
1354
1355 #ifdef KERNEL_PRIVATE
1356 /*
1357 @function mbuf_add_drvaux
1358 @discussion Allocate space for driver auxiliary data and attach it
1359 to the packet (MBUF_PKTHDR is required.) This space is freed
1360 when the mbuf is freed or when mbuf_del_drvaux is called.
1361 Only one instance of driver auxiliary data may be attached to
1362 a packet. Any attempt to add it to a packet already associated
1363 with one will yield an error, and the existing one must first
1364 be removed via mbuf_del_drvaux. The format and length of the
1365 data depend largely on the family and sub-family. The system
1366 makes no attempt to define and/or interpret the contents of
1367 the data, and simply acts as a conduit between its producer
1368 and consumer.
1369 @param mbuf The mbuf to attach the auxiliary data to.
1370 @param how Indicate whether you are willing to block and wait for
1371 memory, if memory is not immediately available.
1372 @param family The interface family as defined in net/kpi_interface.h.
1373 @param subfamily The interface sub-family as defined in
1374 net/kpi_interface.h.
1375 @param length The length of the auxiliary data, must be greater than 0.
1376 @param data_p Upon successful return, *data_p will point to the
1377 space allocated for the data. Caller may set this to NULL.
1378 @result 0 upon success otherwise the errno error.
1379 */
1380 extern errno_t mbuf_add_drvaux(mbuf_t mbuf, mbuf_how_t how,
1381 u_int32_t family, u_int32_t subfamily, size_t length, void **data_p);
1382
1383 /*
1384 @function mbuf_find_drvaux
1385 @discussion Find the driver auxiliary data associated with a packet.
1386 @param mbuf The mbuf the auxiliary data is attached to.
1387 @param family_p Upon successful return, *family_p will contain
1388 the interface family associated with the data, as defined
1389 in net/kpi_interface.h. Caller may set this to NULL.
1390 @param subfamily_p Upon successful return, *subfamily_p will contain
1391 the interface family associated with the data, as defined
1392 in net/kpi_interface.h. Caller may set this to NULL.
1393 @param length_p Upon successful return, *length_p will contain
1394 the length of the driver auxiliary data. Caller may
1395 set this to NULL.
1396 @param data_p Upon successful return, *data_p will point to the
1397 space allocated for the data.
1398 @result 0 upon success otherwise the errno error.
1399 */
1400 extern errno_t mbuf_find_drvaux(mbuf_t mbuf, u_int32_t *family_p,
1401 u_int32_t *subfamily_p, u_int32_t *length_p, void **data_p);
1402
1403 /*
1404 @function mbuf_del_drvaux
1405 @discussion Remove and free any driver auxility data associated
1406 with the packet.
1407 @param mbuf The mbuf the auxiliary data is attached to.
1408 */
1409 extern void mbuf_del_drvaux(mbuf_t mbuf);
1410 #endif /* KERNEL_PRIVATE */
1411
1412 /* mbuf stats */
1413
1414 /*!
1415 @function mbuf_stats
1416 @discussion Get the mbuf statistics.
1417 @param stats Storage to copy the stats in to.
1418 */
1419 extern void mbuf_stats(struct mbuf_stat *stats);
1420
1421
1422 /*!
1423 @enum mbuf_traffic_class_t
1424 @abstract Traffic class of a packet
1425 @discussion Property that represent the category of traffic of a packet.
1426 This information may be used by the driver and at the link level.
1427 @constant MBUF_TC_BE Best effort, normal class.
1428 @constant MBUF_TC_BK Background, low priority or bulk traffic.
1429 @constant MBUF_TC_VI Interactive video, constant bit rate, low latency.
1430 @constant MBUF_TC_VO Interactive voice, constant bit rate, lowest latency.
1431 */
1432 typedef enum {
1433 #ifdef XNU_KERNEL_PRIVATE
1434 MBUF_TC_UNSPEC = -1, /* Internal: not specified */
1435 #endif
1436 MBUF_TC_BE = 0,
1437 MBUF_TC_BK = 1,
1438 MBUF_TC_VI = 2,
1439 MBUF_TC_VO = 3
1440 #ifdef XNU_KERNEL_PRIVATE
1441 ,
1442 MBUF_TC_MAX = 4 /* Internal: traffic class count */
1443 #endif
1444 } mbuf_traffic_class_t;
1445
1446 /*!
1447 @function mbuf_get_traffic_class
1448 @discussion Get the traffic class of an mbuf packet
1449 @param mbuf The mbuf to get the traffic class of.
1450 @result The traffic class
1451 */
1452 extern mbuf_traffic_class_t mbuf_get_traffic_class(mbuf_t mbuf);
1453
1454 /*!
1455 @function mbuf_set_traffic_class
1456 @discussion Set the traffic class of an mbuf packet.
1457 @param mbuf The mbuf to set the traffic class on.
1458 @tc The traffic class
1459 @result 0 on success, EINVAL if bad parameter is passed
1460 */
1461 extern errno_t mbuf_set_traffic_class(mbuf_t mbuf, mbuf_traffic_class_t tc);
1462
1463 /*!
1464 @function mbuf_is_traffic_class_privileged
1465 @discussion Returns the privileged status of the traffic class
1466 of the packet specified by the mbuf.
1467 @param mbuf The mbuf to retrieve the status from.
1468 @result Non-zero if privileged, 0 otherwise.
1469 */
1470 extern int mbuf_is_traffic_class_privileged(mbuf_t mbuf);
1471
1472 #ifdef KERNEL_PRIVATE
1473
1474 /*!
1475 @function mbuf_get_traffic_class_max_count
1476 @discussion Returns the maximum number of mbuf traffic class types
1477 @result The total count of mbuf traffic classes
1478 */
1479 extern u_int32_t mbuf_get_traffic_class_max_count(void);
1480
1481 /*!
1482 @function mbuf_get_traffic_class_index
1483 @discussion Returns the zero-based index of an mbuf traffic class value
1484 @param tc The traffic class
1485 @param index Pointer to the index value
1486 @result 0 on success, EINVAL if bad parameter is passed
1487 */
1488 extern errno_t mbuf_get_traffic_class_index(mbuf_traffic_class_t tc,
1489 u_int32_t *index);
1490
1491 /*!
1492 @enum mbuf_svc_class_t
1493 @abstract Service class of a packet
1494 @discussion Property that represents the category of service
1495 of a packet. This information may be used by the driver
1496 and at the link level.
1497 @constant MBUF_SC_BK_SYS "Background System-Initiated", high delay
1498 tolerant, high loss tolerant, elastic flow, variable size &
1499 long-lived.
1500 @constant MBUF_SC_BK "Background", user-initiated, high delay tolerant,
1501 high loss tolerant, elastic flow, variable size. This level
1502 corresponds to WMM access class "BG", or MBUF_TC_BK.
1503 @constant MBUF_SC_BE "Best Effort", unclassified/standard. This is
1504 the default service class; pretty much a mix of everything.
1505 This level corresponds to WMM access class "BE" or MBUF_TC_BE.
1506 @constant MBUF_SC_RD
1507 "Responsive Data", a notch higher than "Best Effort", medium
1508 delay tolerant, medium loss tolerant, elastic flow, bursty,
1509 long-lived.
1510 @constant MBUF_SC_OAM "Operations, Administration, and Management",
1511 medium delay tolerant, low-medium loss tolerant, elastic &
1512 inelastic flows, variable size.
1513 @constant MBUF_SC_AV "Multimedia Audio/Video Streaming", medium delay
1514 tolerant, low-medium loss tolerant, elastic flow, constant
1515 packet interval, variable rate & size.
1516 @constant MBUF_SC_RV "Responsive Multimedia Audio/Video", low delay
1517 tolerant, low-medium loss tolerant, elastic flow, variable
1518 packet interval, rate and size.
1519 @constant MBUF_SC_VI "Interactive Video", low delay tolerant, low-
1520 medium loss tolerant, elastic flow, constant packet interval,
1521 variable rate & size. This level corresponds to WMM access
1522 class "VI" or MBUF_TC_VI.
1523 @constant MBUF_SC_VO "Interactive Voice", low delay tolerant, low loss
1524 tolerant, inelastic flow, constant packet rate, somewhat fixed
1525 size. This level corresponds to WMM access class "VO" or
1526 MBUF_TC_VO.
1527 @constant MBUF_SC_CTL "Network Control", low delay tolerant, low loss
1528 tolerant, inelastic flow, rate is short & burst, variable size.
1529 */
1530 typedef enum {
1531 #ifdef XNU_KERNEL_PRIVATE
1532 MBUF_SC_UNSPEC = -1, /* Internal: not specified */
1533 #endif
1534 MBUF_SC_BK_SYS = 0x00080090, /* lowest class */
1535 MBUF_SC_BK = 0x00100080,
1536
1537 MBUF_SC_BE = 0x00000000,
1538 MBUF_SC_RD = 0x00180010,
1539 MBUF_SC_OAM = 0x00200020,
1540
1541 MBUF_SC_AV = 0x00280120,
1542 MBUF_SC_RV = 0x00300110,
1543 MBUF_SC_VI = 0x00380100,
1544
1545 MBUF_SC_VO = 0x00400180,
1546 MBUF_SC_CTL = 0x00480190, /* highest class */
1547 } mbuf_svc_class_t;
1548
1549 /*!
1550 @function mbuf_get_service_class_max_count
1551 @discussion Returns the maximum number of mbuf service class types.
1552 @result The total count of mbuf service classes.
1553 */
1554 extern u_int32_t mbuf_get_service_class_max_count(void);
1555
1556 /*!
1557 @function mbuf_get_service_class_index
1558 @discussion Returns the zero-based index of an mbuf service class value
1559 @param sc The service class
1560 @param index Pointer to the index value
1561 @result 0 on success, EINVAL if bad parameter is passed
1562 */
1563 extern errno_t mbuf_get_service_class_index(mbuf_svc_class_t sc,
1564 u_int32_t *index);
1565
1566 /*!
1567 @function mbuf_get_service_class
1568 @discussion Get the service class of an mbuf packet
1569 @param mbuf The mbuf to get the service class of.
1570 @result The service class
1571 */
1572 extern mbuf_svc_class_t mbuf_get_service_class(mbuf_t mbuf);
1573
1574 /*!
1575 @function mbuf_set_servicec_class
1576 @discussion Set the service class of an mbuf packet.
1577 @param mbuf The mbuf to set the service class on.
1578 @sc The service class
1579 @result 0 on success, EINVAL if bad parameter is passed
1580 */
1581 extern errno_t mbuf_set_service_class(mbuf_t mbuf, mbuf_svc_class_t sc);
1582
1583 /*!
1584 @function mbuf_is_service_class_privileged
1585 @discussion Returns the privileged status of the service class
1586 of the packet specified by the mbuf.
1587 @param mbuf The mbuf to retrieve the status from.
1588 @result Non-zero if privileged, 0 otherwise.
1589 */
1590 extern int mbuf_is_service_class_privileged(mbuf_t mbuf);
1591
1592 /*
1593 @enum mbuf_pkthdr_aux_flags_t
1594 @abstract Constants defining mbuf auxiliary flags. Only the flags
1595 listed below can be retrieved.
1596 @constant MBUF_PKTAUXF_INET_RESOLVE_RTR Indicates this is an ARP
1597 request packet, whose target is the address of the default
1598 IPv4 router.
1599 @constant MBUF_PKTAUXF_INET6_RESOLVE_RTR Indicates this is an ICMPv6
1600 Neighbor Solicitation packet, whose target is the address of
1601 the default IPv6 router.
1602 */
1603 enum {
1604 MBUF_PKTAUXF_INET_RESOLVE_RTR = 0x0004,
1605 MBUF_PKTAUXF_INET6_RESOLVE_RTR = 0x0008,
1606 };
1607 typedef u_int32_t mbuf_pkthdr_aux_flags_t;
1608
1609 /*
1610 @function mbuf_pkthdr_aux_flags
1611 @discussion Returns the auxiliary flags of a packet.
1612 @param mbuf The mbuf containing the packet header.
1613 @param paux_flags Pointer to mbuf_pkthdr_aux_flags_t variable.
1614 @result 0 upon success otherwise the errno error.
1615 */
1616 extern errno_t mbuf_pkthdr_aux_flags(mbuf_t mbuf,
1617 mbuf_pkthdr_aux_flags_t *paux_flags);
1618
1619 /*
1620 @function mbuf_get_driver_scratch
1621 @discussion Returns a pointer to a driver specific area in the mbuf
1622 @param m The mbuf whose driver scratch space is to be returned
1623 @param area A pointer to a location to store the address of the
1624 driver scratch space. This value is guaranteed to be 32-bit
1625 aligned.
1626 @param area_ln A pointer to a location to store the total length of
1627 the memory location.
1628 */
1629 extern errno_t mbuf_get_driver_scratch(mbuf_t m, u_int8_t **area,
1630 size_t *area_ln);
1631 #endif /* KERNEL_PRIVATE */
1632
1633 #ifdef XNU_KERNEL_PRIVATE
1634 /*!
1635 @function mbuf_pkt_list_len
1636 @discussion Retrieves the length of the list of mbuf packets.
1637 @param mbuf The mbuf.
1638 @result The length of the mbuf packet list.
1639 */
1640 extern size_t mbuf_pkt_list_len(const mbuf_t mbuf);
1641
1642 /*!
1643 @function mbuf_pkt_list_maxlen
1644 @discussion Retrieves the maximum length of data that may be stored
1645 in the list of mbuf packet. This value assumes that the data pointer
1646 was set to the start of the possible range for that pointer
1647 for each mbuf in the packet chain
1648 @param mbuf The mbuf.
1649 @result The maximum length of data for this mbuf.
1650 */
1651 extern size_t mbuf_pkt_list_maxlen(const mbuf_t mbuf);
1652 #endif /* XNU_KERNEL_PRIVATE */
1653
1654 /* IF_QUEUE interaction */
1655
1656 #define IF_ENQUEUE_MBUF(ifq, m) { \
1657 mbuf_setnextpkt((m), 0); \
1658 if ((ifq)->ifq_tail == 0) \
1659 (ifq)->ifq_head = (m); \
1660 else \
1661 mbuf_setnextpkt((mbuf_t)(ifq)->ifq_tail, (m)); \
1662 (ifq)->ifq_tail = (m); \
1663 (ifq)->ifq_len++; \
1664 }
1665
1666 #define IF_PREPEND_MBUF(ifq, m) { \
1667 mbuf_setnextpkt((m), (ifq)->ifq_head); \
1668 if ((ifq)->ifq_tail == 0) \
1669 (ifq)->ifq_tail = (m); \
1670 (ifq)->ifq_head = (m); \
1671 (ifq)->ifq_len++; \
1672 }
1673
1674 #define IF_DEQUEUE_MBUF(ifq, m) { \
1675 (m) = (ifq)->ifq_head; \
1676 if (m) { \
1677 if (((ifq)->ifq_head = mbuf_nextpkt((m))) == 0) \
1678 (ifq)->ifq_tail = 0; \
1679 mbuf_setnextpkt((m), 0); \
1680 (ifq)->ifq_len--; \
1681 } \
1682 }
1683
1684 __END_DECLS
1685 #endif /* __KPI_MBUF__ */