xref: /xnu-12377.81.4/bsd/netinet/flow_divert_proto.h (revision 043036a2b3718f7f0be807e2870f8f47d3fa0796)
1 /*
2  * Copyright (c) 2012-2017, 2020, 2022, 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 #ifndef __FLOW_DIVERT_PROTO_H__
30 #define __FLOW_DIVERT_PROTO_H__
31 
32 #define FLOW_DIVERT_CONTROL_NAME                "com.apple.flow-divert"
33 
34 #define FLOW_DIVERT_TLV_LENGTH_UINT32   1
35 
36 #define FLOW_DIVERT_PKT_CONNECT                 1
37 #define FLOW_DIVERT_PKT_CONNECT_RESULT          2
38 #define FLOW_DIVERT_PKT_DATA                    3
39 #define FLOW_DIVERT_PKT_CLOSE                   4
40 #define FLOW_DIVERT_PKT_READ_NOTIFY             5
41 #define FLOW_DIVERT_PKT_GROUP_INIT              6
42 #define FLOW_DIVERT_PKT_PROPERTIES_UPDATE       7
43 #define FLOW_DIVERT_PKT_APP_MAP_CREATE          9
44 #define FLOW_DIVERT_PKT_FLOW_STATES_REQUEST     10
45 #define FLOW_DIVERT_PKT_FLOW_STATES             11
46 
47 #define FLOW_DIVERT_TLV_NIL                     0
48 #define FLOW_DIVERT_TLV_ERROR_CODE              5
49 #define FLOW_DIVERT_TLV_HOW                     7
50 #define FLOW_DIVERT_TLV_READ_COUNT              8
51 #define FLOW_DIVERT_TLV_SPACE_AVAILABLE         9
52 #define FLOW_DIVERT_TLV_CTL_UNIT                10
53 #define FLOW_DIVERT_TLV_LOCAL_ADDR              11
54 #define FLOW_DIVERT_TLV_REMOTE_ADDR             12
55 #define FLOW_DIVERT_TLV_OUT_IF_INDEX            13
56 #define FLOW_DIVERT_TLV_TRAFFIC_CLASS           14
57 #define FLOW_DIVERT_TLV_NO_CELLULAR             15
58 #define FLOW_DIVERT_TLV_FLOW_ID                 16
59 #define FLOW_DIVERT_TLV_TOKEN_KEY               17
60 #define FLOW_DIVERT_TLV_HMAC                    18
61 #define FLOW_DIVERT_TLV_KEY_UNIT                19
62 #define FLOW_DIVERT_TLV_LOG_LEVEL               20
63 #define FLOW_DIVERT_TLV_TARGET_HOSTNAME         21
64 #define FLOW_DIVERT_TLV_TARGET_ADDRESS          22
65 #define FLOW_DIVERT_TLV_TARGET_PORT             23
66 #define FLOW_DIVERT_TLV_CDHASH                  24
67 #define FLOW_DIVERT_TLV_SIGNING_ID              25
68 #define FLOW_DIVERT_TLV_AGGREGATE_UNIT          26
69 #define FLOW_DIVERT_TLV_IS_FRAGMENT             27
70 #define FLOW_DIVERT_TLV_PREFIX_COUNT            28
71 #define FLOW_DIVERT_TLV_FLAGS                   29
72 #define FLOW_DIVERT_TLV_FLOW_TYPE               30
73 #define FLOW_DIVERT_TLV_APP_DATA                31
74 #define FLOW_DIVERT_TLV_APP_AUDIT_TOKEN         32
75 #define FLOW_DIVERT_TLV_APP_REAL_SIGNING_ID     33
76 #define FLOW_DIVERT_TLV_APP_REAL_CDHASH         34
77 #define FLOW_DIVERT_TLV_APP_REAL_AUDIT_TOKEN    35
78 #define FLOW_DIVERT_TLV_CFIL_ID                 36
79 #define FLOW_DIVERT_TLV_DATAGRAM_SIZE           37
80 #define FLOW_DIVERT_TLV_ORDER                   38
81 #define FLOW_DIVERT_TLV_FLOW_STATE              39
82 
83 #define FLOW_DIVERT_FLOW_TYPE_TCP               1
84 #define FLOW_DIVERT_FLOW_TYPE_UDP               3
85 
86 #define FLOW_DIVERT_CHUNK_SIZE                  65600
87 
88 #define FLOW_DIVERT_TOKEN_GETOPT_MAX_SIZE       128
89 
90 #define FLOW_DIVERT_TOKEN_FLAG_VALIDATED        0x0000001
91 #define FLOW_DIVERT_TOKEN_FLAG_TFO              0x0000002
92 #define FLOW_DIVERT_TOKEN_FLAG_MPTCP            0x0000004
93 #define FLOW_DIVERT_TOKEN_FLAG_BOUND            0x0000008
94 
95 #define FLOW_DIVERT_GROUP_FLAG_NO_APP_MAP       0x0000001
96 #define FLOW_DIVERT_GROUP_FLAG_DEFUNCT          0x0000002
97 
98 #define FLOW_DIVERT_IS_TRANSPARENT              0x80000000
99 
100 // Used for policies as well as opening control sockets
101 #define FLOW_DIVERT_IN_PROCESS_UNIT             0x0FFFFFFF
102 
103 // Range for actual assigned control units
104 #define FLOW_DIVERT_IN_PROCESS_UNIT_MIN         0x0000FFFF
105 #define FLOW_DIVERT_IN_PROCESS_UNIT_MAX         0xFFFFFFFF
106 
107 struct flow_divert_packet_header {
108 	uint8_t             packet_type;
109 	uint32_t            conn_id;
110 };
111 
112 struct flow_divert_flow_state {
113 	uint32_t conn_id;
114 	uint64_t bytes_written_by_app;
115 	uint64_t bytes_sent;
116 	uint64_t bytes_received;
117 	uint32_t send_window;
118 	uint32_t send_buffer_bytes;
119 };
120 
121 #endif /* __FLOW_DIVERT_PROTO_H__ */
122