1 /*
2 * Copyright (c) 2015-2024 Apple Inc. All rights reserved.
3 *
4 * @APPLE_OSREFERENCE_LICENSE_HEADER_START@
5 *
6 * This file contains Original Code and/or Modifications of Original Code
7 * as defined in and that are subject to the Apple Public Source License
8 * Version 2.0 (the 'License'). You may not use this file except in
9 * compliance with the License. The rights granted to you under the License
10 * may not be used to create, or enable the creation or redistribution of,
11 * unlawful or unlicensed copies of an Apple operating system, or to
12 * circumvent, violate, or enable the circumvention or violation of, any
13 * terms of an Apple operating system software license agreement.
14 *
15 * Please obtain a copy of the License at
16 * http://www.opensource.apple.com/apsl/ and read it before using this file.
17 *
18 * The Original Code and all software distributed under the License are
19 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
20 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
21 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
22 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
23 * Please see the License for the specific language governing rights and
24 * limitations under the License.
25 *
26 * @APPLE_OSREFERENCE_LICENSE_HEADER_END@
27 */
28
29
30 #include <stdlib.h>
31 #include <stddef.h>
32 #include <string.h>
33 #include <strings.h>
34 #include <unistd.h>
35 #include <errno.h>
36 #include <skywalk/os_skywalk_private.h>
37
38 #ifndef LIBSYSCALL_INTERFACE
39 #error "LIBSYSCALL_INTERFACE not defined"
40 #endif /* !LIBSYSCALL_INTERFACE */
41
42 int
os_packet_set_headroom(const packet_t ph,const uint8_t headroom)43 os_packet_set_headroom(const packet_t ph, const uint8_t headroom)
44 {
45 return __packet_set_headroom(ph, headroom);
46 }
47
48 uint8_t
os_packet_get_headroom(const packet_t ph)49 os_packet_get_headroom(const packet_t ph)
50 {
51 return __packet_get_headroom(ph);
52 }
53
54 int
os_packet_set_link_header_length(const packet_t ph,const uint8_t off)55 os_packet_set_link_header_length(const packet_t ph, const uint8_t off)
56 {
57 return __packet_set_link_header_length(ph, off);
58 }
59
60 uint8_t
os_packet_get_link_header_length(const packet_t ph)61 os_packet_get_link_header_length(const packet_t ph)
62 {
63 return __packet_get_link_header_length(ph);
64 }
65
66 int
os_packet_set_link_broadcast(const packet_t ph)67 os_packet_set_link_broadcast(const packet_t ph)
68 {
69 return __packet_set_link_broadcast(ph);
70 }
71
72 boolean_t
os_packet_get_link_broadcast(const packet_t ph)73 os_packet_get_link_broadcast(const packet_t ph)
74 {
75 return __packet_get_link_broadcast(ph);
76 }
77
78 int
os_packet_set_link_multicast(const packet_t ph)79 os_packet_set_link_multicast(const packet_t ph)
80 {
81 return __packet_set_link_multicast(ph);
82 }
83
84 boolean_t
os_packet_get_link_multicast(const packet_t ph)85 os_packet_get_link_multicast(const packet_t ph)
86 {
87 return __packet_get_link_multicast(ph);
88 }
89
90 int
os_packet_set_link_ethfcs(const packet_t ph)91 os_packet_set_link_ethfcs(const packet_t ph)
92 {
93 return __packet_set_link_ethfcs(ph);
94 }
95
96 boolean_t
os_packet_get_link_ethfcs(const packet_t ph)97 os_packet_get_link_ethfcs(const packet_t ph)
98 {
99 return __packet_get_link_ethfcs(ph);
100 }
101
102 int
os_packet_set_transport_traffic_background(const packet_t ph)103 os_packet_set_transport_traffic_background(const packet_t ph)
104 {
105 return __packet_set_transport_traffic_background(ph);
106 }
107
108 boolean_t
os_packet_get_transport_traffic_background(const packet_t ph)109 os_packet_get_transport_traffic_background(const packet_t ph)
110 {
111 return __packet_get_transport_traffic_background(ph);
112 }
113
114 int
os_packet_set_transport_traffic_realtime(const packet_t ph)115 os_packet_set_transport_traffic_realtime(const packet_t ph)
116 {
117 return __packet_set_transport_traffic_realtime(ph);
118 }
119
120 boolean_t
os_packet_get_transport_traffic_realtime(const packet_t ph)121 os_packet_get_transport_traffic_realtime(const packet_t ph)
122 {
123 return __packet_get_transport_traffic_realtime(ph);
124 }
125
126 int
os_packet_set_transport_retransmit(const packet_t ph)127 os_packet_set_transport_retransmit(const packet_t ph)
128 {
129 return __packet_set_transport_retransmit(ph);
130 }
131
132 boolean_t
os_packet_get_transport_retransmit(const packet_t ph)133 os_packet_get_transport_retransmit(const packet_t ph)
134 {
135 return __packet_get_transport_retransmit(ph);
136 }
137
138 int
os_packet_set_transport_last_packet(const packet_t ph)139 os_packet_set_transport_last_packet(const packet_t ph)
140 {
141 return __packet_set_transport_last_packet(ph);
142 }
143
144 int
os_packet_set_service_class(const packet_t ph,const packet_svc_class_t sc)145 os_packet_set_service_class(const packet_t ph, const packet_svc_class_t sc)
146 {
147 return __packet_set_service_class(ph, sc);
148 }
149
150 packet_svc_class_t
os_packet_get_service_class(const packet_t ph)151 os_packet_get_service_class(const packet_t ph)
152 {
153 return __packet_get_service_class(ph);
154 }
155
156 int
os_packet_set_compression_generation_count(const packet_t ph,const uint32_t gencnt)157 os_packet_set_compression_generation_count(const packet_t ph, const uint32_t gencnt)
158 {
159 return __packet_set_comp_gencnt(ph, gencnt);
160 }
161
162 int
os_packet_get_compression_generation_count(const packet_t ph,uint32_t * pgencnt)163 os_packet_get_compression_generation_count(const packet_t ph, uint32_t *pgencnt)
164 {
165 return __packet_get_comp_gencnt(ph, pgencnt);
166 }
167
168 int
os_packet_set_traffic_class(const packet_t ph,packet_traffic_class_t tc)169 os_packet_set_traffic_class(const packet_t ph, packet_traffic_class_t tc)
170 {
171 return __packet_set_traffic_class(ph, tc);
172 }
173
174 packet_traffic_class_t
os_packet_get_traffic_class(const packet_t ph)175 os_packet_get_traffic_class(const packet_t ph)
176 {
177 return __packet_get_traffic_class(ph);
178 }
179
180 int
os_packet_set_inet_checksum(const packet_t ph,const packet_csum_flags_t flags,const uint16_t start,const uint16_t stuff)181 os_packet_set_inet_checksum(const packet_t ph, const packet_csum_flags_t flags,
182 const uint16_t start, const uint16_t stuff)
183 {
184 return __packet_set_inet_checksum(ph, flags, start, stuff, TRUE);
185 }
186
187 void
os_packet_add_inet_csum_flags(const packet_t ph,const packet_csum_flags_t flags)188 os_packet_add_inet_csum_flags(const packet_t ph, const packet_csum_flags_t flags)
189 {
190 __packet_add_inet_csum_flags(ph, flags);
191 }
192
193 packet_csum_flags_t
os_packet_get_inet_checksum(const packet_t ph,uint16_t * start,uint16_t * val)194 os_packet_get_inet_checksum(const packet_t ph, uint16_t *start, uint16_t *val)
195 {
196 return __packet_get_inet_checksum(ph, start, val, FALSE);
197 }
198
199 void
os_packet_get_flow_uuid(const packet_t ph,uuid_t * flow_uuid)200 os_packet_get_flow_uuid(const packet_t ph, uuid_t *flow_uuid)
201 {
202 __packet_get_flow_uuid(ph, *flow_uuid);
203 }
204
205 void
os_packet_set_flow_uuid(const packet_t ph,const uuid_t flow_uuid)206 os_packet_set_flow_uuid(const packet_t ph, const uuid_t flow_uuid)
207 {
208 __packet_set_flow_uuid(ph, flow_uuid);
209 }
210
211 void
os_packet_clear_flow_uuid(const packet_t ph)212 os_packet_clear_flow_uuid(const packet_t ph)
213 {
214 __packet_clear_flow_uuid(ph);
215 }
216
217 void
os_packet_set_group_start(const packet_t ph)218 os_packet_set_group_start(const packet_t ph)
219 {
220 (void) __packet_set_group_start(ph);
221 }
222
223 boolean_t
os_packet_get_group_start(const packet_t ph)224 os_packet_get_group_start(const packet_t ph)
225 {
226 return __packet_get_group_start(ph);
227 }
228
229 void
os_packet_set_group_end(const packet_t ph)230 os_packet_set_group_end(const packet_t ph)
231 {
232 (void) __packet_set_group_end(ph);
233 }
234
235 boolean_t
os_packet_get_group_end(const packet_t ph)236 os_packet_get_group_end(const packet_t ph)
237 {
238 return __packet_get_group_end(ph);
239 }
240
241 int
os_packet_get_expire_time(const packet_t ph,uint64_t * ts)242 os_packet_get_expire_time(const packet_t ph, uint64_t *ts)
243 {
244 return __packet_get_expire_time(ph, ts);
245 }
246
247 int
os_packet_set_expire_time(const packet_t ph,const uint64_t ts)248 os_packet_set_expire_time(const packet_t ph, const uint64_t ts)
249 {
250 return __packet_set_expire_time(ph, ts);
251 }
252
253 int
os_packet_get_expiry_action(const packet_t ph,packet_expiry_action_t * pea)254 os_packet_get_expiry_action(const packet_t ph, packet_expiry_action_t *pea)
255 {
256 return __packet_get_expiry_action(ph, pea);
257 }
258
259 int
os_packet_set_expiry_action(const packet_t ph,const packet_expiry_action_t pea)260 os_packet_set_expiry_action(const packet_t ph, const packet_expiry_action_t pea)
261 {
262 return __packet_set_expiry_action(ph, pea);
263 }
264
265 int
os_packet_get_token(const packet_t ph,void * token,uint16_t * len)266 os_packet_get_token(const packet_t ph, void *token, uint16_t *len)
267 {
268 return __packet_get_token(ph, token, len);
269 }
270
271 int
os_packet_set_token(const packet_t ph,const void * token,const uint16_t len)272 os_packet_set_token(const packet_t ph, const void *token,
273 const uint16_t len)
274 {
275 return __packet_set_token(ph, token, len);
276 }
277
278 int
os_packet_get_packetid(const packet_t ph,packet_id_t * pktid)279 os_packet_get_packetid(const packet_t ph, packet_id_t *pktid)
280 {
281 return __packet_get_packetid(ph, pktid);
282 }
283
284 int
os_packet_set_packetid(const packet_t ph,packet_id_t * pktid)285 os_packet_set_packetid(const packet_t ph, packet_id_t *pktid)
286 {
287 return __packet_set_packetid(ph, pktid);
288 }
289
290 int
os_packet_set_vlan_tag(const packet_t ph,const uint16_t tag)291 os_packet_set_vlan_tag(const packet_t ph, const uint16_t tag)
292 {
293 return __packet_set_vlan_tag(ph, tag);
294 }
295
296 int
os_packet_get_vlan_tag(const packet_t ph,uint16_t * tag)297 os_packet_get_vlan_tag(const packet_t ph, uint16_t *tag)
298 {
299 return __packet_get_vlan_tag(ph, tag);
300 }
301
302 uint16_t
os_packet_get_vlan_id(const uint16_t tag)303 os_packet_get_vlan_id(const uint16_t tag)
304 {
305 return __packet_get_vlan_id(tag);
306 }
307
308 uint8_t
os_packet_get_vlan_priority(const uint16_t tag)309 os_packet_get_vlan_priority(const uint16_t tag)
310 {
311 return __packet_get_vlan_priority(tag);
312 }
313
314 int
os_packet_set_app_metadata(const packet_t ph,const packet_app_metadata_type_t app_type,const uint8_t app_metadata)315 os_packet_set_app_metadata(const packet_t ph,
316 const packet_app_metadata_type_t app_type, const uint8_t app_metadata)
317 {
318 return __packet_set_app_metadata(ph, app_type, app_metadata);
319 }
320
321 boolean_t
os_packet_get_wake_flag(const packet_t ph)322 os_packet_get_wake_flag(const packet_t ph)
323 {
324 return __packet_get_wake_flag(ph);
325 }
326
327 void
os_packet_set_wake_flag(const packet_t ph)328 os_packet_set_wake_flag(const packet_t ph)
329 {
330 __packet_set_wake_flag(ph);
331 }
332
333 boolean_t
os_packet_get_keep_alive(const packet_t ph)334 os_packet_get_keep_alive(const packet_t ph)
335 {
336 return __packet_get_keep_alive(ph);
337 }
338
339 void
os_packet_set_keep_alive(const packet_t ph,const boolean_t is_keep_alive)340 os_packet_set_keep_alive(const packet_t ph, const boolean_t is_keep_alive)
341 {
342 __packet_set_keep_alive(ph, is_keep_alive);
343 }
344
345 boolean_t
os_packet_get_truncated(const packet_t ph)346 os_packet_get_truncated(const packet_t ph)
347 {
348 return __packet_get_truncated(ph);
349 }
350
351 void
os_packet_set_l4s_flag(const packet_t ph)352 os_packet_set_l4s_flag(const packet_t ph)
353 {
354 __packet_set_l4s_flag(ph);
355 }
356
357 uint32_t
os_packet_get_data_length(const packet_t ph)358 os_packet_get_data_length(const packet_t ph)
359 {
360 return __packet_get_data_length(ph);
361 }
362
363 uint32_t
os_packet_get_buflet_count(const packet_t ph)364 os_packet_get_buflet_count(const packet_t ph)
365 {
366 return __packet_get_buflet_count(ph);
367 }
368
369 buflet_t
os_packet_get_next_buflet(const packet_t ph,const buflet_t bprev)370 os_packet_get_next_buflet(const packet_t ph, const buflet_t bprev)
371 {
372 return __packet_get_next_buflet(ph, bprev);
373 }
374
375 uint32_t
os_packet_get_segment_count(const packet_t ph)376 os_packet_get_segment_count(const packet_t ph)
377 {
378 return __packet_get_segment_count(ph);
379 }
380
381 int
os_packet_finalize(const packet_t ph)382 os_packet_finalize(const packet_t ph)
383 {
384 return __packet_finalize(ph);
385 }
386
387 int
os_packet_add_buflet(const packet_t ph,const buflet_t bprev,const buflet_t bnew)388 os_packet_add_buflet(const packet_t ph, const buflet_t bprev,
389 const buflet_t bnew)
390 {
391 return __packet_add_buflet(ph, bprev, bnew);
392 }
393
394 int
os_packet_increment_use_count(const packet_t ph)395 os_packet_increment_use_count(const packet_t ph)
396 {
397 if (__improbable(QUM_ADDR(ph)->qum_usecnt == 0xFFFF)) {
398 return ERANGE;
399 }
400 QUM_ADDR(ph)->qum_usecnt++;
401 return 0;
402 }
403
404 int
os_packet_decrement_use_count(const packet_t ph,uint16_t * use_cnt)405 os_packet_decrement_use_count(const packet_t ph, uint16_t *use_cnt)
406 {
407 if (__improbable(QUM_ADDR(ph)->qum_usecnt == 0)) {
408 return ERANGE;
409 }
410 *use_cnt = --QUM_ADDR(ph)->qum_usecnt;
411 return 0;
412 }
413
414 uint8_t
os_packet_get_aggregation_type(const packet_t ph)415 os_packet_get_aggregation_type(const packet_t ph)
416 {
417 return __packet_get_aggregation_type(ph);
418 }
419
420 void
os_packet_set_tx_timestamp(const packet_t ph,const uint64_t ts)421 os_packet_set_tx_timestamp(const packet_t ph, const uint64_t ts)
422 {
423 __packet_set_tx_timestamp(ph, ts);
424 }
425
426 uint32_t
os_inet_checksum(const void * data,uint32_t len,uint32_t sum0)427 os_inet_checksum(const void *data, uint32_t len, uint32_t sum0)
428 {
429 return __packet_cksum(data, len, sum0);
430 }
431
432 uint32_t
os_copy_and_inet_checksum(const void * src,void * dst,uint32_t len,uint32_t sum0)433 os_copy_and_inet_checksum(const void *src, void *dst, uint32_t len,
434 uint32_t sum0)
435 {
436 uint32_t sum = __packet_copy_and_sum(src, dst, len, sum0);
437 return __packet_fold_sum_final(sum);
438 }
439
440 uint32_t
os_buflet_get_data_offset(const buflet_t buf)441 os_buflet_get_data_offset(const buflet_t buf)
442 {
443 return __buflet_get_data_offset(buf);
444 }
445
446 uint32_t
os_buflet_get_data_length(const buflet_t buf)447 os_buflet_get_data_length(const buflet_t buf)
448 {
449 return __buflet_get_data_length(buf);
450 }
451
452 int
os_buflet_set_data_offset(const buflet_t buf,const uint32_t doff)453 os_buflet_set_data_offset(const buflet_t buf, const uint32_t doff)
454 {
455 return __buflet_set_data_offset(buf, doff);
456 }
457
458 int
os_buflet_set_data_length(const buflet_t buf,const uint32_t dlen)459 os_buflet_set_data_length(const buflet_t buf, const uint32_t dlen)
460 {
461 return __buflet_set_data_length(buf, dlen);
462 }
463
464 void *
os_buflet_get_object_address(const buflet_t buf)465 os_buflet_get_object_address(const buflet_t buf)
466 {
467 return __buflet_get_object_address(buf);
468 }
469
470 uint32_t
os_buflet_get_object_limit(const buflet_t buf)471 os_buflet_get_object_limit(const buflet_t buf)
472 {
473 return __buflet_get_object_limit(buf);
474 }
475
476 void *
os_buflet_get_data_address(const buflet_t buf)477 os_buflet_get_data_address(const buflet_t buf)
478 {
479 return __buflet_get_data_address(buf);
480 }
481
482 uint32_t
os_buflet_get_data_limit(const buflet_t buf)483 os_buflet_get_data_limit(const buflet_t buf)
484 {
485 return __buflet_get_data_limit(buf);
486 }
487
488 packet_trace_id_t
os_packet_get_trace_id(const packet_t ph)489 os_packet_get_trace_id(const packet_t ph)
490 {
491 return __packet_get_trace_id(ph);
492 }
493
494 void
os_packet_set_trace_id(const packet_t ph,packet_trace_id_t trace_id)495 os_packet_set_trace_id(const packet_t ph, packet_trace_id_t trace_id)
496 {
497 __packet_set_trace_id(ph, trace_id);
498 }
499
500 void
os_packet_trace_event(const packet_t ph,uint32_t event)501 os_packet_trace_event(const packet_t ph, uint32_t event)
502 {
503 return __packet_trace_event(ph, event);
504 }
505
506 int
os_packet_set_protocol_segment_size(const packet_t ph,uint16_t proto_seg_sz)507 os_packet_set_protocol_segment_size(const packet_t ph, uint16_t proto_seg_sz)
508 {
509 return __packet_set_protocol_segment_size(ph, proto_seg_sz);
510 }
511
512 void
os_packet_set_tso_flags(const packet_t ph,packet_tso_flags_t flags)513 os_packet_set_tso_flags(const packet_t ph, packet_tso_flags_t flags)
514 {
515 return __packet_set_tso_flags(ph, flags);
516 }
517