1 /* 2 * Copyright (c) 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_NEXUS_IOCTL_H_ 30 #define _SKYWALK_NEXUS_IOCTL_H_ 31 32 #if defined(PRIVATE) || defined(BSD_KERNEL_PRIVATE) 33 /* 34 * Routines common to kernel and userland. This file is intended to be 35 * included by code implementing the nexus controller ioctl logic, 36 * in particular, the Skywalk kernel and libsyscall code. 37 */ 38 39 #include <sys/ioctl.h> 40 #include <sys/errno.h> 41 42 #ifndef KERNEL 43 #if !defined(LIBSYSCALL_INTERFACE) 44 #error "LIBSYSCALL_INTERFACE not defined" 45 #endif /* !LIBSYSCALL_INTERFACE */ 46 #else 47 extern int nxioctl(struct nxctl *, u_long, caddr_t, proc_t); 48 extern int nxioctl_kernel(struct nexus_controller *, u_long, caddr_t, proc_t); 49 extern int nxioctl_add_traffic_rule_inet(struct nxctl *, caddr_t, proc_t); 50 extern int nxioctl_add_traffic_rule_eth(struct nxctl *, caddr_t, proc_t); 51 extern int nxioctl_remove_traffic_rule(struct nxctl *, caddr_t, proc_t); 52 extern int nxioctl_get_traffic_rules(struct nxctl *, caddr_t, proc_t); 53 #endif /* !KERNEL */ 54 55 /* 56 * Naming convention: 57 * ioctl arguments (structures included in NXIOC_* definitions) have the 58 * _iocargs suffix. The code in sys_generic.c:ioctl() handles the copyin/out 59 * of these arguments. 60 */ 61 #define NXIOC_ADD_TRAFFIC_RULE_FLAG_PERSIST 0x0001 62 struct nxctl_add_traffic_rule_inet_iocargs { 63 char atri_ifname[IFNAMSIZ]; 64 struct ifnet_traffic_descriptor_inet atri_td; 65 struct ifnet_traffic_rule_action_steer atri_ra; 66 uint32_t atri_flags; 67 uuid_t atri_uuid; 68 }; 69 #define NXIOC_ADD_TRAFFIC_RULE_INET \ 70 _IOWR('n', 1, struct nxctl_add_traffic_rule_inet_iocargs) 71 72 struct nxctl_add_traffic_rule_eth_iocargs { 73 char atre_ifname[IFNAMSIZ]; 74 struct ifnet_traffic_descriptor_eth atre_td; 75 struct ifnet_traffic_rule_action_steer atre_ra; 76 uint32_t atre_flags; 77 uuid_t atre_uuid; 78 }; 79 #define NXIOC_ADD_TRAFFIC_RULE_ETH \ 80 _IOWR('n', 4, struct nxctl_add_traffic_rule_eth_iocargs) 81 82 struct nxctl_remove_traffic_rule_iocargs { 83 uuid_t rtr_uuid; 84 }; 85 #define NXIOC_REMOVE_TRAFFIC_RULE \ 86 _IOW('n', 2, struct nxctl_remove_traffic_rule_iocargs) 87 88 /* 89 * nxctl_get_traffic_rules_iocargs.gtr_buf holds an array of 90 * nxctl_traffic_rule_inet_iocinfo. This does not have the _iocargs suffix 91 * because the structure is not part of a NXIOC* definition. It has an _iocinfo 92 * suffix to denote that it is shared between kernel and userspace. 93 */ 94 #define NTR_PROCNAME_SZ 64 95 struct nxctl_traffic_rule_generic_iocinfo { 96 uuid_t trg_uuid; 97 char trg_procname[NTR_PROCNAME_SZ]; 98 char trg_ifname[IFNAMSIZ]; 99 }; 100 struct nxctl_traffic_rule_inet_iocinfo { 101 struct nxctl_traffic_rule_generic_iocinfo tri_common; 102 struct ifnet_traffic_descriptor_inet tri_td; 103 struct ifnet_traffic_rule_action_steer tri_ra; 104 }; 105 struct nxctl_traffic_rule_eth_iocinfo { 106 struct nxctl_traffic_rule_generic_iocinfo tre_common; 107 struct ifnet_traffic_descriptor_eth tre_td; 108 struct ifnet_traffic_rule_action_steer tre_ra; 109 }; 110 struct nxctl_get_traffic_rules_iocargs { 111 uint8_t gtr_type; 112 uint32_t gtr_size; 113 uint32_t gtr_count; 114 union { 115 void *gtr_buf; 116 uint64_t gtr_buf64; 117 }; 118 }; 119 #define NXIOC_GET_TRAFFIC_RULES \ 120 _IOWR('n', 3, struct nxctl_get_traffic_rules_iocargs) 121 122 #define NXCTL_TRAFFIC_RULE_READ_ENTITLEMENT "com.apple.private.skywalk.traffic_rule.read" 123 #define NXCTL_TRAFFIC_RULE_WRITE_ENTITLEMENT "com.apple.private.skywalk.traffic_rule.write" 124 125 #endif /* PRIVATE || BSD_KERNEL_PRIVATE */ 126 #endif /* !_SKYWALK_NEXUS_IOCTL_H_ */ 127