1 /* 2 * Copyright (c) 2019-2021 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_CHANNEL_EVENT_H_ 30 #define _SKYWALK_OS_CHANNEL_EVENT_H_ 31 32 #ifdef PRIVATE 33 #include <stdint.h> 34 #include <mach/vm_types.h> 35 36 typedef enum { 37 CHANNEL_EVENT_PACKET_TRANSMIT_STATUS = 1, 38 #if defined(LIBSYSCALL_INTERFACE) || defined(BSD_KERNEL_PRIVATE) 39 CHANNEL_EVENT_MIN = CHANNEL_EVENT_PACKET_TRANSMIT_STATUS, 40 CHANNEL_EVENT_MAX = CHANNEL_EVENT_PACKET_TRANSMIT_STATUS, 41 #endif /* LIBSYSCALL_INTERFACE || BSD_KERNEL_PRIVATE */ 42 } os_channel_event_type_t; 43 44 typedef enum : int32_t { 45 CHANNEL_EVENT_SUCCESS = 0, 46 CHANNEL_EVENT_PKT_TRANSMIT_STATUS_ERR_FLUSH = 1, 47 CHANNEL_EVENT_PKT_TRANSMIT_STATUS_ERR_RETRY_FAILED = 2, 48 CHANNEL_EVENT_PKT_TRANSMIT_STATUS_ERR_TIMEOUT_EXPIRED_DROPPED = 3, 49 CHANNEL_EVENT_PKT_TRANSMIT_STATUS_ERR_TIMEOUT_EXPIRED_NODROP = 4, 50 } os_channel_event_error_t; 51 52 typedef struct os_channel_event_packet_transmit_status { 53 packet_id_t packet_id; 54 int32_t packet_status; 55 } os_channel_event_packet_transmit_status_t; 56 57 #ifndef KERNEL 58 /* 59 * opaque handles 60 */ 61 typedef uint64_t os_channel_event_handle_t; 62 typedef mach_vm_address_t os_channel_event_t; 63 64 struct os_channel_event_data { 65 os_channel_event_type_t event_type; 66 boolean_t event_more; 67 uint16_t event_data_length; 68 uint8_t *event_data; 69 }; 70 71 #if !defined(_POSIX_C_SOURCE) || defined(_DARWIN_C_SOURCE) 72 extern int 73 os_channel_event_get_next_event(const os_channel_event_handle_t event_handle, 74 const os_channel_event_t prev_event, os_channel_event_t *event); 75 extern int os_channel_event_get_event_data(const os_channel_event_t, struct os_channel_event_data *); 76 #endif /* (!_POSIX_C_SOURCE || _DARWIN_C_SOURCE) */ 77 #endif /* KERNEL */ 78 79 #if defined(LIBSYSCALL_INTERFACE) || defined(BSD_KERNEL_PRIVATE) 80 /* 81 * The metadata object is placed at the front of every batch of events. 82 */ 83 struct __kern_channel_event_metadata { 84 os_channel_event_type_t emd_etype; 85 uint32_t emd_nevents; 86 }; 87 #define __KERN_CHANNEL_EVENT_OFFSET \ 88 (sizeof(struct __kern_channel_event_metadata)) 89 90 struct __kern_channel_event { 91 os_channel_event_type_t ev_type; 92 uint32_t ev_flags; 93 uint16_t _reserved; 94 uint16_t ev_dlen; 95 uint8_t ev_data[]; 96 }; 97 98 /* event_flags */ 99 #define CHANNEL_EVENT_FLAG_MORE_EVENT 0x1 100 101 /* convenience macro */ 102 #define CHANNEL_EVENT_TX_STATUS_LEN (sizeof(struct __kern_channel_event) + \ 103 sizeof(os_channel_event_packet_transmit_status_t)) 104 #endif /* LIBSYSCALL_INTERFACE || BSD_KERNEL_PRIVATE */ 105 106 #if defined(BSD_KERNEL_PRIVATE) 107 __BEGIN_DECLS 108 extern errno_t kern_channel_event_transmit_status_with_packet( 109 const kern_packet_t, const ifnet_t); 110 extern void kern_channel_event_notify(struct __kern_channel_ring *); 111 extern int kern_channel_event_sync(struct __kern_channel_ring *, struct proc *, 112 uint32_t); 113 __END_DECLS 114 #endif /* BSD_KERNEL_PRIVATE */ 115 116 #ifdef KERNEL 117 __BEGIN_DECLS 118 extern errno_t kern_channel_event_transmit_status(const ifnet_t, 119 os_channel_event_packet_transmit_status_t *, uint32_t); 120 __END_DECLS 121 #endif /* KERNEL */ 122 123 #endif /* PRIVATE */ 124 #endif /* !_SKYWALK_OS_CHANNEL_EVENT_H_ */ 125