xref: /xnu-8796.121.2/bsd/skywalk/packet/os_packet.h (revision c54f35ca767986246321eb901baf8f5ff7923f6a)
1 /*
2  * Copyright (c) 2016-2022 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 #ifndef _SKYWALK_OS_PACKET_H_
30 #define _SKYWALK_OS_PACKET_H_
31 
32 #ifdef PRIVATE
33 
34 #include <stdint.h>
35 #include <sys/types.h>
36 #include <sys/cdefs.h>
37 #include <uuid/uuid.h>
38 #include <mach/boolean.h>
39 #include <mach/vm_types.h>
40 #include <skywalk/os_nexus.h>
41 
42 /*
43  * @enum packet_svc_class_t
44  * @abstract Service class of a packet
45  * @discussion Property that represents the category of service
46  *      of a packet. This information may be used by the driver
47  *      and at the link level.
48  * @constant PKT_SC_BK_SYS "Background System-Initiated", high delay
49  *      tolerant, high loss tolerant, elastic flow, variable size &
50  *      long-lived.
51  * @constant PKT_SC_BK "Background", user-initiated, high delay tolerant,
52  *      high loss tolerant, elastic flow, variable size.  This level
53  *      corresponds to WMM access class "BG".
54  * @constant PKT_SC_BE "Best Effort", unclassified/standard.  This is
55  *      the default service class; pretty much a mix of everything.
56  *      This level corresponds to WMM access class "BE".
57  * @constant PKT_SC_RD
58  *      "Responsive Data", a notch higher than "Best Effort", medium
59  *      delay tolerant, medium loss tolerant, elastic flow, bursty,
60  *      long-lived.
61  * @constant PKT_SC_OAM "Operations, Administration, and Management",
62  *      medium delay tolerant, low-medium loss tolerant, elastic &
63  *      inelastic flows, variable size.
64  * @constant PKT_SC_AV "Multimedia Audio/Video Streaming", medium delay
65  *      tolerant, low-medium loss tolerant, elastic flow, constant
66  *      packet interval, variable rate & size.
67  * @constant PKT_SC_RV "Responsive Multimedia Audio/Video", low delay
68  *      tolerant, low-medium loss tolerant, elastic flow, variable
69  *      packet interval, rate and size.
70  * @constant PKT_SC_VI "Interactive Video", low delay tolerant, low-
71  *      medium loss tolerant, elastic flow, constant packet interval,
72  *      variable rate & size.  This level corresponds to WMM access
73  *      class "VI".
74  * @constant PKT_SC_SIG "Signaling", low delay tolerant, low loss
75  *      tolerant, inelastic flow, jitter tolerant, rate is bursty but
76  *      short, variable size. e.g. SIP.  This level corresponds to WMM
77  *      access class "VI".
78  * @constant PKT_SC_VO "Interactive Voice", low delay tolerant, low loss
79  *      tolerant, inelastic flow, constant packet rate, somewhat fixed
80  *      size.  This level corresponds to WMM access class "VO" or
81  *      PKT_TC_VO.
82  * @constant PKT_SC_CTL "Network Control", low delay tolerant, low loss
83  *      tolerant, inelastic flow, rate is short & burst, variable size.
84  */
85 typedef enum {
86 	PKT_SC_BK_SYS   = 0x00080090, /* lowest class */
87 	PKT_SC_BK       = 0x00100080,
88 
89 	PKT_SC_BE       = 0x00000000,
90 	PKT_SC_RD       = 0x00180010,
91 	PKT_SC_OAM      = 0x00200020,
92 
93 	PKT_SC_AV       = 0x00280120,
94 	PKT_SC_RV       = 0x00300110,
95 	PKT_SC_VI       = 0x00380100,
96 	PKT_SC_SIG      = 0x00380130,
97 
98 	PKT_SC_VO       = 0x00400180,
99 	PKT_SC_CTL      = 0x00480190, /* highest class */
100 } packet_svc_class_t;
101 
102 /* CSTYLED */
103 /*!
104  * @enum packet_traffic_class_t
105  * @abstract Traffic class of a packet
106  * @discussion Property that represent the category of traffic of a packet.
107  *	This information may be used by the driver and at the link level.
108  * @constant PKT_TC_BE Best effort, normal class.
109  * @constant PKT_TC_BK Background, low priority or bulk traffic.
110  * @constant PKT_TC_VI Interactive video, constant bit rate, low latency.
111  * @constant PKT_TC_VO Interactive voice, constant bit rate, lowest latency.
112  */
113 typedef enum {
114 	PKT_TC_BE       = 0,
115 	PKT_TC_BK       = 1,
116 	PKT_TC_VI       = 2,
117 	PKT_TC_VO       = 3,
118 } packet_traffic_class_t;
119 
120 /*
121  * These conversion macros rely on the corresponding PKT_SC and
122  * PKT_TC values in order to establish the following mapping:
123  *
124  *	PKT_SC_BK_SYS	] ==>	PKT_TC_BK
125  *	PKT_SC_BK	]
126  *
127  *	PKT_SC_BE	] ==>	PKT_TC_BE
128  *	PKT_SC_RD	]
129  *	PKT_SC_OAM	]
130  *
131  *	PKT_SC_AV	] ==>	PKT_TC_VI
132  *	PKT_SC_RV	]
133  *	PKT_SC_VI	]
134  *	PKT_SC_SIG	]
135  *
136  *	PKT_SC_VO	] ==>	PKT_TC_VO
137  *	PKT_SC_CTL	]
138  *
139  * The values assigned to each service class allows for a fast mapping to
140  * the corresponding PKT_TC traffic class values, as well as to retrieve the
141  * assigned index; therefore care must be taken when comparing against these
142  * values.  Use the corresponding class and index macros to retrieve the
143  * corresponding portion, and never assume that a higher class corresponds
144  * to a higher index.
145  */
146 #define PKT_SCVAL(x)            ((x) & 0xffff)
147 #define PKT_SC2TC(_sc)          (PKT_SCVAL(_sc) >> 7)
148 #define PKT_TC2SCVAL(_tc)       ((_tc) << 7)
149 
150 #define PKT_SCVAL_BK_SYS        PKT_SCVAL(PKT_SC_BK_SYS)
151 #define PKT_SCVAL_BK            PKT_SCVAL(PKT_SC_BK)
152 #define PKT_SCVAL_BE            PKT_SCVAL(PKT_SC_BE)
153 #define PKT_SCVAL_RD            PKT_SCVAL(PKT_SC_RD)
154 #define PKT_SCVAL_OAM           PKT_SCVAL(PKT_SC_OAM)
155 #define PKT_SCVAL_AV            PKT_SCVAL(PKT_SC_AV)
156 #define PKT_SCVAL_RV            PKT_SCVAL(PKT_SC_RV)
157 #define PKT_SCVAL_VI            PKT_SCVAL(PKT_SC_VI)
158 #define PKT_SCVAL_SIG           PKT_SCVAL(PKT_SC_SIG)
159 #define PKT_SCVAL_VO            PKT_SCVAL(PKT_SC_VO)
160 #define PKT_SCVAL_CTL           PKT_SCVAL(PKT_SC_CTL)
161 
162 /*
163  * Packet checksum offload flags.
164  */
165 typedef uint32_t packet_csum_flags_t;
166 typedef uint32_t packet_trace_id_t;
167 typedef uint32_t packet_flowid_t;
168 typedef uint16_t packet_trace_tag_t;
169 
170 /*
171  * PACKET_CSUM_PARTIAL indicates the following:
172  *
173  * On transmit, the start and stuff offsets are significant, and that the
174  * module setting this information is requesting that the layer below it
175  * compute 16-bit 1's complement sum from the location marked by the start
176  * offset to the end of the packet, and store the resulted sum at the
177  * location marked by the stuff offset.  If PACKET_CSUM_ZERO_INVERT is set,
178  * and if the resulted sum is 0, it will be converted to -0 (0xffff).
179  *
180  * On receive, the start offset and checksum value are significant, and
181  * that the module computing the 16-bit 1's complement and setting this
182  * information is requesting that the layer above it perform any necessary
183  * adjustments to exclude/include data span that's not applicable, as well
184  * as to validate the checksum value.
185  */
186 #define PACKET_CSUM_PARTIAL     0x01     /* partial one's complement */
187 #define PACKET_CSUM_ZERO_INVERT 0x02     /* invert resulted 0 to 0xffff */
188 
189 /*
190  * Below flags are for RX.
191  */
192 #define PACKET_CSUM_IP_CHECKED  0x0100    /* did IP checksum */
193 #define PACKET_CSUM_IP_VALID    0x0200    /* and the IP checksum is valid */
194 #define PACKET_CSUM_DATA_VALID  0x0400    /* csum_rx_val is valid */
195 #define PACKET_CSUM_PSEUDO_HDR  0x0800    /* csum_rx_val includes pseudo hdr */
196 
197 typedef enum : uint32_t {
198 	PACKET_TSO_IPV4  = 0x00100000,
199 	PACKET_TSO_IPV6  = 0x00200000,
200 } packet_tso_flags_t;
201 
202 #define PACKET_HAS_VALID_IP_CSUM(_p) \
203     (((_p)->pkt_csum_flags & (PACKET_CSUM_IP_CHECKED | PACKET_CSUM_IP_VALID)) \
204      == (PACKET_CSUM_IP_CHECKED | PACKET_CSUM_IP_VALID))
205 
206 #define PACKET_HAS_PARTIAL_CHECKSUM(_p) \
207 	((_p)->pkt_csum_flags & (PACKET_CSUM_PARTIAL))
208 
209 #define PACKET_CSUM_RX_FULL_FLAGS \
210 	(PACKET_CSUM_IP_CHECKED | PACKET_CSUM_IP_VALID | \
211 	PACKET_CSUM_DATA_VALID | PACKET_CSUM_PSEUDO_HDR)
212 
213 #define PACKET_CSUM_RX_FLAGS \
214 	(PACKET_CSUM_RX_FULL_FLAGS | PACKET_CSUM_PARTIAL)
215 
216 #define PACKET_CSUM_TSO_FLAGS \
217 	(PACKET_TSO_IPV4 | PACKET_TSO_IPV6)
218 
219 #define PACKET_HAS_FULL_CHECKSUM_FLAGS(_p) \
220 	(((_p)->pkt_csum_flags & PACKET_CSUM_RX_FULL_FLAGS) == PACKET_CSUM_RX_FULL_FLAGS)
221 
222 /*
223  * TODO: [email protected] -- these are temporary and should be removed later.
224  */
225 #define OS_PACKET_HAS_CHECKSUM_API      1
226 #define OS_PACKET_HAS_SEGMENT_COUNT     1
227 #define OS_PACKET_HAS_TRACING_API       1
228 #define OS_PACKET_HAS_SEGMENT_SIZE      1
229 
230 /*
231  * Valid values for pkt_aggr_type.
232  */
233 #define PKT_AGGR_NONE                0x00 /* no aggregation */
234 #define PKT_AGGR_IP_CHAIN            0x01 /* buflet chain of discrete IP packets containing contiguous L4 frames */
235 #define PKT_AGGR_SINGLE_IP           0x02 /* buflet chain representing single IP packet */
236 #define PKT_AGGR_SINGLE_IP_PACKED    0x03 /* buflet chain representing single IP packet in packed format */
237 
238 /*
239  * packet_id is a per packet metadata which can be set on a packet by the
240  * application. It can be used to identify either an individual or a group
241  * of packets within the networking stack and driver.
242  */
243 typedef struct packet_id {
244 	/*
245 	 * version of this structure.
246 	 */
247 	uint8_t     pktid_version;
248 #define OS_PACKET_PKTID_VERSION_1          1
249 #define OS_PACKET_PKTID_VERSION_CURRENT    OS_PACKET_PKTID_VERSION_1
250 	/*
251 	 * payload type of the packet, opaque to the network stack.
252 	 */
253 	uint8_t     pktid_payload_type;
254 	/*
255 	 * packet sequence number, monotonically increasing.
256 	 */
257 	uint16_t    pktid_sequence_number;
258 	/*
259 	 * packet timestamp, monotonically increasing and opaque to the
260 	 * network stack. Sample rate of the timestamp clock is determined
261 	 * by the application.
262 	 */
263 	uint32_t    pktid_timestamp;
264 	/*
265 	 * Identifier for streams defined by the application.
266 	 */
267 	uint32_t    pktid_stream_identifier;
268 	/*
269 	 * reserved for future use.
270 	 */
271 	uint32_t    _reserved;
272 } packet_id_t;
273 
274 /*
275  * Packet Trace code
276  * Used with os_packet_trace_* functions.
277  * Total of 12bit (0xABC) code space available, current sub-code allocation is:
278  *     0x00C code space for FSW Rx path.
279  *     0x01C code space for FSW Tx path.
280  *
281  * More sub-code can be added for other packet data path, e.g. uPipe, BSD, etc.
282  *
283  * Note:
284  *     1. Needs to include <sys/kdebug.h> to use the values.
285  *     2. When making changes to sub-code/value, update static assertions in
286  *        pp_init and probe list ariadne-plists/skywalk-tracepoints.plist.
287  *
288  */
289 /* Rx Group */
290 #define PKT_TRACE_RX_DRV_START      (SKYWALKDBG_CODE(DBG_SKYWALK_PACKET, 0x001) | DBG_FUNC_START)
291 #define PKT_TRACE_RX_DRV_END        (SKYWALKDBG_CODE(DBG_SKYWALK_PACKET, 0x001) | DBG_FUNC_END)
292 
293 #define PKT_TRACE_RX_FSW_START      (SKYWALKDBG_CODE(DBG_SKYWALK_PACKET, 0x002) | DBG_FUNC_START)
294 #define PKT_TRACE_RX_FSW_END        (SKYWALKDBG_CODE(DBG_SKYWALK_PACKET, 0x002) | DBG_FUNC_END)
295 
296 #define PKT_TRACE_RX_CHN_START      (SKYWALKDBG_CODE(DBG_SKYWALK_PACKET, 0x003) | DBG_FUNC_START)
297 #define PKT_TRACE_RX_CHN_END        (SKYWALKDBG_CODE(DBG_SKYWALK_PACKET, 0x003) | DBG_FUNC_END)
298 
299 
300 /* Tx Group */
301 #define PKT_TRACE_TX_FSW_START      (SKYWALKDBG_CODE(DBG_SKYWALK_PACKET, 0x010) | DBG_FUNC_START)
302 #define PKT_TRACE_TX_FSW_END        (SKYWALKDBG_CODE(DBG_SKYWALK_PACKET, 0x010) | DBG_FUNC_END)
303 
304 #define PKT_TRACE_TX_AQM_START      (SKYWALKDBG_CODE(DBG_SKYWALK_PACKET, 0x011) | DBG_FUNC_START)
305 #define PKT_TRACE_TX_AQM_END        (SKYWALKDBG_CODE(DBG_SKYWALK_PACKET, 0x011) | DBG_FUNC_END)
306 
307 #define PKT_TRACE_TX_DRV_START      (SKYWALKDBG_CODE(DBG_SKYWALK_PACKET, 0x012) | DBG_FUNC_START)
308 #define PKT_TRACE_TX_DRV_END        (SKYWALKDBG_CODE(DBG_SKYWALK_PACKET, 0x012) | DBG_FUNC_END)
309 
310 /*
311  * @enum packet_expiry_action_t
312  * @abstract The desired action(s) to take upon the expiration of the packet
313  * @discussion Bitfield property to express the desired actions to take when the packet expires.
314  *    At the moment the actions are only taken for the TX packets.
315  *
316  * @constant PACKET_EXPIRY_ACTION_DROP      - drop the packet
317  * @constant PACKET_EXPIRY_ACTION_NOTIFY    - notify the upper layers
318  */
319 typedef enum {
320 	PACKET_EXPIRY_ACTION_NONE   = 0x0,
321 	PACKET_EXPIRY_ACTION_DROP   = 0x1,
322 	PACKET_EXPIRY_ACTION_NOTIFY = 0x2,
323 } packet_expiry_action_t;
324 
325 /*
326  * @enum packet_app_metadata_type_t
327  * @abstract Application specific metadata which can be used by the Network
328  *           Stack or Network Interface Driver/firmware.
329  * @discussion Supported Application types are:
330  * @constant PACKET_APP_METADATA_TYPE_VOICE  - voice application
331  */
332 typedef enum : uint8_t {
333 #if defined(LIBSYSCALL_INTERFACE) || defined(BSD_KERNEL_PRIVATE)
334 	PACKET_APP_METADATA_TYPE_UNSPECIFIED = 0,
335 #endif /* LIBSYSCALL_INTERFACE || BSD_KERNEL_PRIVATE */
336 	PACKET_APP_METADATA_TYPE_VOICE = 1,
337 #if defined(LIBSYSCALL_INTERFACE) || defined(BSD_KERNEL_PRIVATE)
338 	PACKET_APP_METADATA_TYPE_MIN = PACKET_APP_METADATA_TYPE_VOICE,
339 	PACKET_APP_METADATA_TYPE_MAX = PACKET_APP_METADATA_TYPE_VOICE,
340 #endif /* LIBSYSCALL_INTERFACE || BSD_KERNEL_PRIVATE */
341 } packet_app_metadata_type_t;
342 
343 /*
344  * @enum packet_voice_app_metadata_t
345  * @abstract Voice application specific metadata.
346  * @discussion Supported Voice application metadata values are:
347  * @constant PACKET_VOICE_APP_METADATA_UNSPECIFIED  - metadata not specified.
348  * @constant PACKET_VOICE_APP_METADATA_SPEECH   - speech frame.
349  * @constant PACKET_VOICE_APP_METADATA_SILENCE  - silence frame.
350  * @constant PACKET_VOICE_APP_METADATA_OTHER  - RTCP XR, RTCP, or DTMF.
351  */
352 typedef enum : uint8_t {
353 	PACKET_VOICE_APP_METADATA_UNSPECIFIED    = 0x0,
354 	PACKET_VOICE_APP_METADATA_SPEECH         = 0x1,
355 	PACKET_VOICE_APP_METADATA_SILENCE        = 0x2,
356 	PACKET_VOICE_APP_METADATA_OTHER          = 0x3,
357 } packet_voice_app_metadata_t;
358 
359 #ifndef KERNEL
360 /*
361  * User APIs.
362  */
363 
364 /*
365  * Opaque handles.
366  */
367 struct __user_buflet;
368 typedef uint64_t                        packet_t;
369 typedef struct __user_buflet            *buflet_t;
370 
371 #if !defined(_POSIX_C_SOURCE) || defined(_DARWIN_C_SOURCE)
372 __BEGIN_DECLS
373 /*
374  * Packets specific.
375  */
376 extern int os_packet_set_headroom(const packet_t, const uint8_t);
377 extern uint8_t os_packet_get_headroom(const packet_t);
378 extern int os_packet_set_link_header_length(const packet_t, const uint8_t);
379 extern uint8_t os_packet_get_link_header_length(const packet_t);
380 extern int os_packet_set_link_broadcast(const packet_t);
381 extern boolean_t os_packet_get_link_broadcast(const packet_t);
382 extern int os_packet_set_link_multicast(const packet_t);
383 extern boolean_t os_packet_get_link_multicast(const packet_t);
384 extern int os_packet_set_link_ethfcs(const packet_t);
385 extern boolean_t os_packet_get_link_ethfcs(const packet_t);
386 extern int os_packet_set_transport_traffic_background(const packet_t);
387 extern boolean_t os_packet_get_transport_traffic_background(const packet_t);
388 extern int os_packet_set_transport_traffic_realtime(const packet_t);
389 extern boolean_t os_packet_get_transport_traffic_realtime(const packet_t);
390 extern int os_packet_set_transport_retransmit(const packet_t);
391 extern boolean_t os_packet_get_transport_retransmit(const packet_t);
392 extern int os_packet_set_transport_last_packet(const packet_t);
393 extern int os_packet_set_service_class(const packet_t,
394     const packet_svc_class_t);
395 extern packet_svc_class_t os_packet_get_service_class(const packet_t);
396 extern int os_packet_set_compression_generation_count(const packet_t, const uint32_t);
397 extern int os_packet_get_compression_generation_count(const packet_t, uint32_t *);
398 extern int os_packet_set_traffic_class(const packet_t, packet_traffic_class_t);
399 extern packet_traffic_class_t os_packet_get_traffic_class(const packet_t);
400 extern int os_packet_set_inet_checksum(const packet_t,
401     const packet_csum_flags_t, const uint16_t, const uint16_t);
402 extern packet_csum_flags_t os_packet_get_inet_checksum(const packet_t,
403     uint16_t *, uint16_t *);
404 extern void os_packet_set_group_start(const packet_t);
405 extern boolean_t os_packet_get_group_start(const packet_t);
406 extern void os_packet_set_group_end(const packet_t);
407 extern boolean_t os_packet_get_group_end(const packet_t);
408 extern int os_packet_set_expire_time(const packet_t, const uint64_t);
409 extern int os_packet_get_expire_time(const packet_t, uint64_t *);
410 #define HAS_OS_PACKET_EXPIRY_ACTION 1
411 extern int os_packet_set_expiry_action(const packet_t, const packet_expiry_action_t);
412 extern int os_packet_get_expiry_action(const packet_t, packet_expiry_action_t *);
413 extern int os_packet_set_token(const packet_t, const void *, const uint16_t);
414 extern int os_packet_get_packetid(const packet_t, packet_id_t *);
415 extern int os_packet_set_packetid(const packet_t, packet_id_t *);
416 extern int os_packet_set_vlan_tag(const packet_t, const uint16_t,
417     const boolean_t);
418 extern int os_packet_get_vlan_tag(const packet_t, uint16_t *, boolean_t *);
419 extern uint16_t os_packet_get_vlan_id(const uint16_t);
420 extern uint8_t os_packet_get_vlan_priority(const uint16_t);
421 #define HAS_OS_PACKET_GET_WAKE_FLAG 1
422 extern boolean_t os_packet_get_wake_flag(const packet_t);
423 #define HAS_OS_PACKET_KEEP_ALIVE 1
424 extern boolean_t os_packet_get_keep_alive(const packet_t);
425 extern void os_packet_set_keep_alive(const packet_t, const boolean_t);
426 extern boolean_t os_packet_get_truncated(const packet_t);
427 extern uint8_t os_packet_get_aggregation_type(const packet_t);
428 extern int os_packet_set_app_metadata(const packet_t,
429     const packet_app_metadata_type_t, const uint8_t);
430 extern int os_packet_set_protocol_segment_size(const packet_t, const uint16_t);
431 extern void os_packet_set_tso_flags(const packet_t, packet_tso_flags_t);
432 extern void os_packet_set_l4s_flag(const packet_t, const boolean_t);
433 /*
434  * Quantum & Packets.
435  */
436 extern void os_packet_set_flow_uuid(const packet_t, const uuid_t flow_uuid);
437 extern void os_packet_get_flow_uuid(const packet_t, uuid_t *flow_uuid);
438 extern void os_packet_clear_flow_uuid(const packet_t);
439 extern uint32_t os_packet_get_data_length(const packet_t);
440 extern uint32_t os_packet_get_buflet_count(const packet_t);
441 extern buflet_t os_packet_get_next_buflet(const packet_t, const buflet_t);
442 extern uint32_t os_packet_get_segment_count(const packet_t ph);
443 extern int os_packet_finalize(const packet_t);
444 extern int os_packet_add_buflet(const packet_t ph, const buflet_t bprev,
445     const buflet_t bnew);
446 /* increment use count on packet */
447 extern int os_packet_increment_use_count(const packet_t ph);
448 /* decrement use count on packet and retrieve new value  */
449 extern int os_packet_decrement_use_count(const packet_t ph, uint16_t *use_cnt);
450 
451 extern packet_trace_id_t os_packet_get_trace_id(const packet_t ph);
452 extern void os_packet_set_trace_id(const packet_t ph, packet_trace_id_t);
453 extern void os_packet_trace_event(const packet_t ph, uint32_t);
454 
455 /*
456  * Misc.
457  */
458 extern uint32_t os_inet_checksum(const void *, uint32_t, uint32_t);
459 extern uint32_t os_copy_and_inet_checksum(const void *, void *,
460     uint32_t, uint32_t);
461 
462 /*
463  * Buflets.
464  */
465 extern int os_buflet_set_data_offset(const buflet_t, const uint16_t);
466 extern uint16_t os_buflet_get_data_offset(const buflet_t);
467 extern int os_buflet_set_data_length(const buflet_t, const uint16_t);
468 extern uint16_t os_buflet_get_data_length(const buflet_t);
469 extern void *os_buflet_get_object_address(const buflet_t);
470 extern uint32_t os_buflet_get_object_limit(const buflet_t);
471 extern void *os_buflet_get_data_address(const buflet_t);
472 extern uint16_t os_buflet_get_data_limit(const buflet_t);
473 extern uint16_t os_buflet_get_object_offset(const buflet_t);
474 extern uint16_t os_buflet_get_gro_len(const buflet_t);
475 extern void *os_buflet_get_next_buf(const buflet_t, const void *);
476 __END_DECLS
477 #endif  /* (!_POSIX_C_SOURCE || _DARWIN_C_SOURCE) */
478 #else /* KERNEL */
479 /*
480  * Kernel APIs.
481  */
482 
483 /*
484  * Opaque handles.
485  */
486 struct __kern_buflet;
487 struct kern_pbufpool;
488 struct sksegment;
489 
490 typedef struct kern_pbufpool            *kern_pbufpool_t;
491 typedef uint64_t                        kern_packet_t;
492 typedef uint32_t                        kern_packet_idx_t;
493 typedef struct __kern_buflet            *kern_buflet_t;
494 typedef uint32_t                        kern_obj_idx_seg_t;
495 typedef struct sksegment                *kern_segment_t;
496 typedef uint32_t                        kern_segment_idx_t;
497 
498 /*
499  * @typedef pbuf_seg_ctor_fn_t
500  * @abstract Buffer segment constructor callback.
501  * @param buf_seg Buffer segment handle.
502  * @param buf_desc IOSKMemoryDescriptor handle for buffer segment.
503  * @discussion This callback is invoked when a segment has been activated.
504  *      If applicable, the owner should wire/prepare the memory and insert
505  *      it into the memory mapper (IOMMU/DART) prior to returning.
506  */
507 typedef void (*pbuf_seg_ctor_fn_t)(const kern_pbufpool_t,
508     const kern_segment_t buf_seg, const IOSKMemoryDescriptor buf_desc);
509 
510 /*
511  * @typedef pbuf_seg_dtor_fn_t
512  * @abstract Buffer segment destructor callback.
513  * @param buf_seg Buffer segment handle.
514  * @param buf_desc IOSKMemoryDescriptor handle for buffer segment.
515  * @discussion This callback is invoked when a segment is about to be
516  *      freed.  The owner should reverse what had been done earlier
517  *      at pbuf_seg_ctor_fn_t() constructor time.  If applicable,
518  *      it should remove the memory from mapper (IOMMU/DART), and
519  *      unwire/complete it prior to returning.
520  */
521 typedef void (*pbuf_seg_dtor_fn_t)(const kern_pbufpool_t,
522     const kern_segment_t buf_seg, const IOSKMemoryDescriptor buf_desc);
523 
524 typedef void (*pbuf_ctx_retain_fn_t)(void *const ctx);
525 typedef void (*pbuf_ctx_release_fn_t)(void *const ctx);
526 
527 typedef uint8_t pbufpool_name_t[64];
528 
529 /*
530  * Kernel packet buffer pool init.
531  */
532 struct kern_pbufpool_init {
533 	uint32_t                kbi_version;    /* current version */
534 	pbufpool_name_t         kbi_name;       /* optional */
535 	uint32_t                kbi_flags;      /* see KBI_* */
536 	uint32_t                kbi_packets;    /* required */
537 	uint32_t                kbi_max_frags;  /* max buflets per packet */
538 	uint32_t                kbi_buflets;    /* >= packets (optional) */
539 	uint32_t                kbi_bufsize;    /* required */
540 	uint32_t                kbi_buf_seg_size; /* optional */
541 	pbuf_seg_ctor_fn_t      kbi_buf_seg_ctor; /* optional */
542 	pbuf_seg_dtor_fn_t      kbi_buf_seg_dtor; /* optional */
543 	void *                  kbi_ctx;         /* optional */
544 	pbuf_ctx_retain_fn_t    kbi_ctx_retain;  /* optional */
545 	pbuf_ctx_release_fn_t   kbi_ctx_release; /* optional */
546 };
547 
548 #define KBIF_QUANTUM            0x1     /* simple packet (non-networking) */
549 #define KBIF_PERSISTENT         0x2     /* persistent memory (wired) */
550 #define KBIF_MONOLITHIC         0x4     /* single segment mode */
551 #define KBIF_BUFFER_ON_DEMAND   0x8     /* attach/detach buffers on demand */
552 #define KBIF_INHIBIT_CACHE      0x10    /* caching-inhibited */
553 #define KBIF_USER_ACCESS        0x20    /* allow userspace access */
554 #define KBIF_VIRTUAL_DEVICE     0x40    /* device is virtual (no DMA) */
555 #define KBIF_PHYS_CONTIGUOUS    0x80    /* physically-contiguous segment(s) */
556 #define KBIF_IODIR_IN           0x100   /* io direction in (device to host) */
557 #define KBIF_IODIR_OUT          0x200   /* io direction out (host to device) */
558 #define KBIF_KERNEL_READONLY    0x400   /* kernel read-only */
559 #define KBIF_NO_MAGAZINES       0x800   /* disable per-CPU magazines layer */
560 #define KBIF_RAW_BFLT           0x1000  /* configure raw buflet */
561 #define KBIF_THREADSAFE         0x2000  /* thread safe memory descriptor */
562 
563 #define KERN_PBUFPOOL_VERSION_1         1
564 #define KERN_PBUFPOOL_VERSION_2         2       /* added ctx retain/release */
565 #define KERN_PBUFPOOL_CURRENT_VERSION   KERN_PBUFPOOL_VERSION_2
566 
567 /*
568  * Kernel packet buffer pool memory info.
569  */
570 struct kern_pbufpool_memory_info {
571 	uint32_t    kpm_flags;      /* see KPMF_* */
572 	uint32_t    kpm_packets;    /* number of packets */
573 	uint32_t    kpm_max_frags;  /* max buflets per packet */
574 	uint32_t    kpm_buflets;    /* number of buflets */
575 	uint32_t    kpm_bufsize;    /* size of each buffer */
576 	uint32_t    kpm_bufsegs;    /* number of buffer segments */
577 	uint32_t    kpm_buf_seg_size; /* size of a buffer segment */
578 	uint32_t    kpm_buf_obj_size; /* size of the shared buffer object */
579 } __attribute__((aligned(64)));
580 
581 #define KPMF_EXTERNAL           0x1             /* externally configured */
582 
583 /*
584  * Kernel packet representation of packet_svc_class_t.
585  *
586  * We have a separate enum to separate the namespace just in case we need it.
587  */
588 typedef enum {
589 #ifdef BSD_KERNEL_PRIVATE
590 	KPKT_SC_UNSPEC  = -1, /* Internal: not specified */
591 #endif /* BSD_KERNEL_PRIVATE */
592 	KPKT_SC_BK_SYS  = PKT_SC_BK_SYS, /* lowest class */
593 	KPKT_SC_BK      = PKT_SC_BK,
594 
595 	KPKT_SC_BE      = PKT_SC_BE,
596 	KPKT_SC_RD      = PKT_SC_RD,
597 	KPKT_SC_OAM     = PKT_SC_OAM,
598 
599 	KPKT_SC_AV      = PKT_SC_AV,
600 	KPKT_SC_RV      = PKT_SC_RV,
601 	KPKT_SC_VI      = PKT_SC_VI,
602 	KPKT_SC_SIG     = PKT_SC_SIG,
603 
604 	KPKT_SC_VO      = PKT_SC_VO,
605 	KPKT_SC_CTL     = PKT_SC_CTL, /* highest class */
606 } kern_packet_svc_class_t;
607 
608 /* Maximum number of KPKT_SC values (excluding KPKT_SC_UNSPEC) */
609 #define KPKT_SC_MAX_CLASSES     10
610 
611 #define KPKT_VALID_SVC(c)                                               \
612 	(c == KPKT_SC_BK_SYS || c == KPKT_SC_BK || c == KPKT_SC_BE ||   \
613 	c == KPKT_SC_RD || c == KPKT_SC_OAM || c == KPKT_SC_AV ||       \
614 	c == KPKT_SC_RV || c == KPKT_SC_VI || c == KPKT_SC_SIG ||       \
615 	c == KPKT_SC_VO || c == KPKT_SC_CTL)
616 
617 #define KPKT_SVCIDX(c)          ((((c) >> 16) & 0xff) >> 3)
618 
619 /*
620  * Kernel packet representation of packet_traffic_class_t.
621  *
622  * We have a separate enum to separate the namespace just in case we need it.
623  */
624 typedef enum {
625 #ifdef BSD_KERNEL_PRIVATE
626 	KPKT_TC_UNSPEC  = -1,           /* Internal: not specified */
627 #endif /* BSD_KERNEL_PRIVATE */
628 	KPKT_TC_BE      = PKT_TC_BE,
629 	KPKT_TC_BK      = PKT_TC_BK,
630 	KPKT_TC_VI      = PKT_TC_VI,
631 	KPKT_TC_VO      = PKT_TC_VO,
632 #ifdef BSD_KERNEL_PRIVATE
633 	KPKT_TC_MAX     = 4,            /* Internal: traffic class count */
634 #endif /* BSD_KERNEL_PRIVATE */
635 } kern_packet_traffic_class_t;
636 
637 /*
638  * Modes for cloning a kernel packet.
639  *
640  * The "heavy" mode copies most of the metadata (except those pertaining
641  * to linkages to other objects), allocates new buffer(s) for the
642  * cloned packet, and copies old buffer(s) to new one(s).
643  *
644  * The "light" mode is to be used on a packet that's recently allocated,
645  * as the cloning process involves copying minimal metadata information,
646  * as well as adding reference(s) to the buffer(s) rather than copying.
647  */
648 typedef enum {
649 	KPKT_COPY_HEAVY = 0,   /* copy everything including buffers */
650 	KPKT_COPY_LIGHT        /* minimal copy, adding refs to buffers */
651 } kern_packet_copy_mode_t;
652 
653 
654 __BEGIN_DECLS
655 /*
656  * Packets specific.
657  */
658 extern errno_t kern_packet_set_headroom(const kern_packet_t, const uint8_t);
659 extern uint8_t kern_packet_get_headroom(const kern_packet_t);
660 /* deprecated -- use kern_packet_set_headroom instead */
661 extern errno_t kern_packet_set_link_header_offset(const kern_packet_t,
662     const uint8_t);
663 /* deprecated -- use kern_packet_get_headroom instead */
664 extern uint16_t kern_packet_get_link_header_offset(const kern_packet_t);
665 extern errno_t kern_packet_set_link_header_length(const kern_packet_t,
666     const uint8_t);
667 extern uint8_t kern_packet_get_link_header_length(const kern_packet_t);
668 extern errno_t kern_packet_set_link_broadcast(const kern_packet_t);
669 extern boolean_t kern_packet_get_link_broadcast(const kern_packet_t);
670 extern errno_t kern_packet_set_link_multicast(const kern_packet_t);
671 extern boolean_t kern_packet_get_link_multicast(const kern_packet_t);
672 extern errno_t kern_packet_set_link_ethfcs(const kern_packet_t);
673 extern boolean_t kern_packet_get_link_ethfcs(const kern_packet_t);
674 /* deprecated -- use kern_packet_set_link_header_length instead */
675 extern errno_t kern_packet_set_network_header_offset(const kern_packet_t,
676     const uint16_t);
677 /* deprecated -- use kern_packet_get_link_header_length instead */
678 extern uint16_t kern_packet_get_network_header_offset(const kern_packet_t);
679 extern errno_t kern_packet_set_transport_traffic_background(
680 	const kern_packet_t);
681 extern boolean_t kern_packet_get_transport_traffic_background(
682 	const kern_packet_t);
683 extern errno_t kern_packet_set_transport_traffic_realtime(const kern_packet_t);
684 extern boolean_t kern_packet_get_transport_traffic_realtime(
685 	const kern_packet_t);
686 /* deprecated */
687 extern errno_t kern_packet_set_transport_header_offset(const kern_packet_t,
688     const uint16_t);
689 /* deprecated */
690 extern uint16_t kern_packet_get_transport_header_offset(const kern_packet_t);
691 extern errno_t kern_packet_set_transport_retransmit(const kern_packet_t);
692 extern boolean_t kern_packet_get_transport_retransmit(const kern_packet_t);
693 extern boolean_t kern_packet_get_transport_new_flow(const kern_packet_t);
694 extern boolean_t kern_packet_get_transport_last_packet(const kern_packet_t);
695 extern errno_t kern_packet_set_service_class(const kern_packet_t,
696     const kern_packet_svc_class_t);
697 extern kern_packet_svc_class_t kern_packet_get_service_class(
698 	const kern_packet_t);
699 extern errno_t kern_packet_get_service_class_index(
700 	const kern_packet_svc_class_t, uint32_t *);
701 #define HAS_KERN_PACKET_COMPRESSION_GENERATION_COUNT 1
702 extern errno_t kern_packet_set_compression_generation_count(const kern_packet_t,
703     const uint32_t);
704 extern errno_t kern_packet_get_compression_generation_count(const kern_packet_t, uint32_t *);
705 extern boolean_t kern_packet_is_high_priority(
706 	const kern_packet_t);
707 extern errno_t kern_packet_set_traffic_class(const kern_packet_t,
708     kern_packet_traffic_class_t);
709 extern kern_packet_traffic_class_t kern_packet_get_traffic_class(
710 	const kern_packet_t);
711 extern errno_t kern_packet_set_inet_checksum(const kern_packet_t,
712     const packet_csum_flags_t, const uint16_t, const uint16_t, boolean_t);
713 extern packet_csum_flags_t kern_packet_get_inet_checksum(const kern_packet_t,
714     uint16_t *, uint16_t *, boolean_t);
715 extern errno_t kern_packet_get_timestamp(const kern_packet_t, uint64_t *,
716     boolean_t *);
717 extern errno_t kern_packet_set_timestamp(const kern_packet_t, uint64_t,
718     boolean_t);
719 extern errno_t kern_packet_get_timestamp_requested(const kern_packet_t,
720     boolean_t *);
721 extern errno_t kern_packet_get_tx_completion_status(const kern_packet_t,
722     kern_return_t *);
723 extern errno_t kern_packet_set_tx_completion_status(const kern_packet_t,
724     kern_return_t);
725 extern void kern_packet_tx_completion(const kern_packet_t, ifnet_t);
726 extern void kern_packet_set_group_start(const kern_packet_t);
727 extern boolean_t kern_packet_get_group_start(const kern_packet_t);
728 extern void kern_packet_set_group_end(const kern_packet_t);
729 extern boolean_t kern_packet_get_group_end(const kern_packet_t);
730 extern errno_t kern_packet_set_expire_time(const kern_packet_t, const uint64_t);
731 extern errno_t kern_packet_get_expire_time(const kern_packet_t, uint64_t *);
732 extern errno_t kern_packet_set_expiry_action(const kern_packet_t, const packet_expiry_action_t);
733 extern errno_t kern_packet_get_expiry_action(const kern_packet_t, packet_expiry_action_t *);
734 extern errno_t kern_packet_set_token(const kern_packet_t, const void *,
735     const uint16_t);
736 extern errno_t kern_packet_get_token(const kern_packet_t, void *, uint16_t *);
737 extern errno_t kern_packet_get_packetid(const kern_packet_t, packet_id_t *);
738 extern errno_t kern_packet_set_vlan_tag(const kern_packet_t, const uint16_t,
739     const boolean_t);
740 extern errno_t kern_packet_get_vlan_tag(const kern_packet_t, uint16_t *,
741     boolean_t *);
742 extern uint16_t kern_packet_get_vlan_id(const uint16_t);
743 extern uint8_t kern_packet_get_vlan_priority(const uint16_t);
744 extern void kern_packet_set_wake_flag(const kern_packet_t);
745 extern boolean_t kern_packet_get_wake_flag(const kern_packet_t);
746 extern errno_t kern_packet_get_flowid(const kern_packet_t, packet_flowid_t *);
747 extern void kern_packet_set_trace_tag(const kern_packet_t ph, packet_trace_tag_t tag);
748 extern packet_trace_tag_t kern_packet_get_trace_tag(const kern_packet_t ph);
749 extern errno_t kern_packet_get_tx_nexus_port_id(const kern_packet_t,
750     uint32_t *);
751 extern errno_t kern_packet_get_app_metadata(const kern_packet_t,
752     packet_app_metadata_type_t *, uint8_t *);
753 extern errno_t kern_packet_get_protocol_segment_size(const kern_packet_t,
754     uint16_t *);
755 extern void * kern_packet_get_priv(const kern_packet_t);
756 extern void kern_packet_set_priv(const kern_packet_t, void *);
757 extern void kern_packet_get_tso_flags(const kern_packet_t, packet_tso_flags_t *);
758 void kern_packet_set_segment_count(const kern_packet_t, uint8_t);
759 
760 /*
761  * Quantum & Packets.
762  */
763 extern void kern_packet_set_flow_uuid(const kern_packet_t, const uuid_t);
764 extern void kern_packet_get_flow_uuid(const kern_packet_t, uuid_t *);
765 extern void kern_packet_clear_flow_uuid(const kern_packet_t);
766 extern void kern_packet_get_euuid(const kern_packet_t, uuid_t);
767 extern void kern_packet_set_policy_id(const kern_packet_t, uint32_t);
768 extern uint32_t kern_packet_get_policy_id(const kern_packet_t);
769 extern kern_packet_idx_t kern_packet_get_object_index(const kern_packet_t);
770 extern uint32_t kern_packet_get_data_length(const kern_packet_t);
771 extern uint32_t kern_packet_get_buflet_count(const kern_packet_t);
772 extern errno_t kern_packet_set_buflet_count(const kern_packet_t, uint32_t);
773 extern kern_buflet_t kern_packet_get_next_buflet(const kern_packet_t,
774     const kern_buflet_t);
775 extern errno_t kern_packet_finalize(const kern_packet_t);
776 extern errno_t kern_packet_clone(const kern_packet_t, kern_packet_t *,
777     kern_packet_copy_mode_t);
778 extern errno_t kern_packet_clone_nosleep(const kern_packet_t, kern_packet_t *,
779     kern_packet_copy_mode_t);
780 extern errno_t kern_packet_add_buflet(const kern_packet_t ph,
781     const kern_buflet_t bprev, const kern_buflet_t bnew);
782 extern void kern_packet_append(const kern_packet_t, const kern_packet_t);
783 extern kern_packet_t kern_packet_get_next(const kern_packet_t);
784 extern void kern_packet_set_next(const kern_packet_t, const kern_packet_t);
785 extern void kern_packet_set_chain_counts(const kern_packet_t, uint32_t,
786     uint32_t);
787 extern void kern_packet_get_chain_counts(const kern_packet_t, uint32_t *,
788     uint32_t *);
789 
790 /*
791  * Misc.
792  */
793 extern uint32_t kern_inet_checksum(const void *, uint32_t, uint32_t);
794 extern uint32_t kern_copy_and_inet_checksum(const void *, void *,
795     uint32_t, uint32_t);
796 extern void kern_packet_set_trace_id(const kern_packet_t, packet_trace_id_t);
797 extern packet_trace_id_t kern_packet_get_trace_id(const kern_packet_t);
798 extern void kern_packet_trace_event(const kern_packet_t, uint32_t);
799 extern errno_t kern_packet_copy_bytes(const kern_packet_t, size_t, size_t,
800     void*);
801 
802 /*
803  * Buflets.
804  */
805 extern errno_t kern_buflet_set_data_address(const kern_buflet_t, const void *);
806 extern void *kern_buflet_get_data_address(const kern_buflet_t);
807 extern errno_t kern_buflet_set_data_offset(const kern_buflet_t, const uint16_t);
808 extern uint16_t kern_buflet_get_data_offset(const kern_buflet_t);
809 extern errno_t kern_buflet_set_data_length(const kern_buflet_t, const uint16_t);
810 extern uint16_t kern_buflet_get_data_length(const kern_buflet_t);
811 extern void *kern_buflet_get_object_address(const kern_buflet_t);
812 extern uint32_t kern_buflet_get_object_limit(const kern_buflet_t);
813 extern kern_segment_t kern_buflet_get_object_segment(const kern_buflet_t,
814     kern_obj_idx_seg_t *);
815 extern errno_t kern_buflet_set_data_limit(const kern_buflet_t, const uint16_t);
816 extern uint16_t kern_buflet_get_data_limit(const kern_buflet_t);
817 extern errno_t kern_buflet_set_buffer_offset(const kern_buflet_t buf,
818     const uint16_t off);
819 extern uint16_t kern_buflet_get_buffer_offset(const kern_buflet_t buf);
820 extern errno_t kern_buflet_set_gro_len(const kern_buflet_t buf,
821     const uint16_t len);
822 extern uint16_t kern_buflet_get_gro_len(const kern_buflet_t buf);
823 extern void *kern_buflet_get_next_buf(const kern_buflet_t buflet,
824     const void *prev_buf);
825 extern errno_t kern_buflet_clone(const kern_buflet_t buf1,
826     kern_buflet_t *pbuf_array, uint32_t *size, struct kern_pbufpool *pool);
827 extern errno_t kern_buflet_clone_nosleep(const kern_buflet_t buf1,
828     kern_buflet_t *pbuf_array, uint32_t *size, struct kern_pbufpool *pool);
829 
830 /*
831  * Packet buffer pool.
832  */
833 typedef void (*alloc_cb_func_t)(kern_packet_t packet, uint32_t pkt_index,
834     const void *ctx);
835 extern errno_t kern_pbufpool_create(const struct kern_pbufpool_init *,
836     kern_pbufpool_t *, struct kern_pbufpool_memory_info *);
837 extern void *kern_pbufpool_get_context(const kern_pbufpool_t pbufpool);
838 extern errno_t kern_pbufpool_get_memory_info(const kern_pbufpool_t pbufpool,
839     struct kern_pbufpool_memory_info *pbufpool_mem_ref);
840 extern errno_t kern_pbufpool_alloc(const kern_pbufpool_t pbufpool,
841     const uint32_t bufcnt, kern_packet_t *packet);
842 extern errno_t kern_pbufpool_alloc_batch(const kern_pbufpool_t pbufpool,
843     const uint32_t bufcnt, kern_packet_t *array, uint32_t *size);
844 extern errno_t kern_pbufpool_alloc_batch_callback(
845 	const kern_pbufpool_t pbufpool, const uint32_t bufcnt, kern_packet_t *array,
846 	uint32_t *size, alloc_cb_func_t cb, const void *ctx);
847 extern errno_t kern_pbufpool_alloc_nosleep(const kern_pbufpool_t pbufpool,
848     const uint32_t bufcnt, kern_packet_t *packet);
849 extern errno_t kern_pbufpool_alloc_batch_nosleep(const kern_pbufpool_t pbufpool,
850     const uint32_t bufcnt, kern_packet_t *array, uint32_t *size);
851 extern errno_t kern_pbufpool_alloc_batch_nosleep_callback(
852 	const kern_pbufpool_t pbufpool, const uint32_t bufcnt,
853 	kern_packet_t *array, uint32_t *size, alloc_cb_func_t cb, const void *ctx);
854 extern void kern_pbufpool_free(const kern_pbufpool_t pbufpool, kern_packet_t);
855 extern void kern_pbufpool_free_batch(const kern_pbufpool_t pbufpool,
856     kern_packet_t *array, uint32_t size);
857 extern void kern_pbufpool_free_chain(const kern_pbufpool_t pbufpool,
858     kern_packet_t chain);
859 extern errno_t kern_pbufpool_alloc_buffer(const kern_pbufpool_t pbufpool,
860     mach_vm_address_t *buffer, kern_segment_t *sg, kern_obj_idx_seg_t *sg_idx);
861 extern errno_t kern_pbufpool_alloc_buffer_nosleep(const kern_pbufpool_t
862     pbufpool, mach_vm_address_t *buffer, kern_segment_t *sg,
863     kern_obj_idx_seg_t *sg_idx);
864 extern void kern_pbufpool_free_buffer(const kern_pbufpool_t pbufpool,
865     mach_vm_address_t baddr);
866 extern errno_t kern_pbufpool_alloc_buflet(const kern_pbufpool_t,
867     kern_buflet_t *, bool);
868 extern errno_t kern_pbufpool_alloc_buflet_nosleep(const kern_pbufpool_t,
869     kern_buflet_t *, bool);
870 extern errno_t kern_pbufpool_alloc_batch_buflet(const kern_pbufpool_t,
871     kern_buflet_t *, uint32_t *size, bool);
872 extern errno_t kern_pbufpool_alloc_batch_buflet_nosleep(const kern_pbufpool_t,
873     kern_buflet_t *, uint32_t *size, bool);
874 extern void kern_pbufpool_free_buflet(const kern_pbufpool_t pp,
875     kern_buflet_t pbuf);
876 extern void kern_pbufpool_destroy(kern_pbufpool_t);
877 extern kern_segment_idx_t kern_segment_get_index(const kern_segment_t);
878 __END_DECLS
879 #endif /* KERNEL */
880 #endif /* PRIVATE */
881 #endif /* !_SKYWALK_OS_PACKET_H_ */
882