xref: /xnu-11215.41.3/bsd/skywalk/nexus/nexus_ioctl.h (revision 33de042d024d46de5ff4e89f2471de6608e37fa4)
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 #include <skywalk/os_nexus_private.h>
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_add_traffic_rule_inet(struct nxctl *, caddr_t, proc_t);
49 extern int nxioctl_remove_traffic_rule(struct nxctl *, caddr_t, proc_t);
50 extern int nxioctl_get_traffic_rules(struct nxctl *, caddr_t, proc_t);
51 #endif /* !KERNEL */
52 
53 /*
54  * Naming convention:
55  * ioctl arguments (structures included in NXIOC_* definitions) have the
56  * _iocargs suffix. The code in sys_generic.c:ioctl() handles the copyin/out
57  * of these arguments.
58  */
59 #define NXIOC_ADD_TRAFFIC_RULE_FLAG_PERSIST 0x0001
60 struct nxctl_add_traffic_rule_inet_iocargs {
61 	char atri_ifname[IFNAMSIZ];
62 	struct ifnet_traffic_descriptor_inet atri_td;
63 	struct ifnet_traffic_rule_action_steer atri_ra;
64 	uint32_t atri_flags;
65 	uuid_t atri_uuid;
66 };
67 #define NXIOC_ADD_TRAFFIC_RULE_INET \
68     _IOWR('n', 1, struct nxctl_add_traffic_rule_inet_iocargs)
69 
70 struct nxctl_remove_traffic_rule_iocargs {
71 	uuid_t rtr_uuid;
72 };
73 #define NXIOC_REMOVE_TRAFFIC_RULE \
74     _IOW('n', 2, struct nxctl_remove_traffic_rule_iocargs)
75 
76 /*
77  * nxctl_get_traffic_rules_iocargs.gtr_buf holds an array of
78  * nxctl_traffic_rule_inet_iocinfo. This does not have the _iocargs suffix
79  * because the structure is not part of a NXIOC* definition. It has an _iocinfo
80  * suffix to denote that it is shared between kernel and userspace.
81  */
82 #define NTR_PROCNAME_SZ 64
83 struct nxctl_traffic_rule_generic_iocinfo {
84 	uuid_t trg_uuid;
85 	char trg_procname[NTR_PROCNAME_SZ];
86 	char trg_ifname[IFNAMSIZ];
87 };
88 struct nxctl_traffic_rule_inet_iocinfo {
89 	struct nxctl_traffic_rule_generic_iocinfo tri_common;
90 	struct ifnet_traffic_descriptor_inet tri_td;
91 	struct ifnet_traffic_rule_action_steer tri_ra;
92 };
93 struct nxctl_get_traffic_rules_iocargs {
94 	uint8_t gtr_type;
95 	uint32_t gtr_size;
96 	uint32_t gtr_count;
97 	union {
98 		void *gtr_buf;
99 		uint64_t gtr_buf64;
100 	};
101 };
102 #define NXIOC_GET_TRAFFIC_RULES \
103     _IOWR('n', 3, struct nxctl_get_traffic_rules_iocargs)
104 
105 #define NXCTL_TRAFFIC_RULE_READ_ENTITLEMENT  "com.apple.private.skywalk.traffic_rule.read"
106 #define NXCTL_TRAFFIC_RULE_WRITE_ENTITLEMENT "com.apple.private.skywalk.traffic_rule.write"
107 
108 #endif /* PRIVATE || BSD_KERNEL_PRIVATE */
109 #endif /* !_SKYWALK_NEXUS_IOCTL_H_ */
110