xref: /xnu-8792.81.2/bsd/net/packet_mangler.h (revision 19c3b8c28c31cb8130e034cfb5df6bf9ba342d90)
1*19c3b8c2SApple OSS Distributions /*
2*19c3b8c2SApple OSS Distributions  * Copyright (c) 2014 Apple Inc. All rights reserved.
3*19c3b8c2SApple OSS Distributions  *
4*19c3b8c2SApple OSS Distributions  * @APPLE_LICENSE_HEADER_START@
5*19c3b8c2SApple OSS Distributions  *
6*19c3b8c2SApple OSS Distributions  * This file contains Original Code and/or Modifications of Original Code
7*19c3b8c2SApple OSS Distributions  * as defined in and that are subject to the Apple Public Source License
8*19c3b8c2SApple OSS Distributions  * Version 2.0 (the 'License'). You may not use this file except in
9*19c3b8c2SApple OSS Distributions  * compliance with the License. Please obtain a copy of the License at
10*19c3b8c2SApple OSS Distributions  * http://www.opensource.apple.com/apsl/ and read it before using this
11*19c3b8c2SApple OSS Distributions  * file.
12*19c3b8c2SApple OSS Distributions  *
13*19c3b8c2SApple OSS Distributions  * The Original Code and all software distributed under the License are
14*19c3b8c2SApple OSS Distributions  * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
15*19c3b8c2SApple OSS Distributions  * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
16*19c3b8c2SApple OSS Distributions  * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
17*19c3b8c2SApple OSS Distributions  * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
18*19c3b8c2SApple OSS Distributions  * Please see the License for the specific language governing rights and
19*19c3b8c2SApple OSS Distributions  * limitations under the License.
20*19c3b8c2SApple OSS Distributions  *
21*19c3b8c2SApple OSS Distributions  * @APPLE_LICENSE_HEADER_END@
22*19c3b8c2SApple OSS Distributions  */
23*19c3b8c2SApple OSS Distributions 
24*19c3b8c2SApple OSS Distributions #ifndef __PACKET_MANGLER_H__
25*19c3b8c2SApple OSS Distributions #define __PACKET_MANGLER_H__
26*19c3b8c2SApple OSS Distributions 
27*19c3b8c2SApple OSS Distributions #include <sys/param.h>
28*19c3b8c2SApple OSS Distributions #include <sys/types.h>
29*19c3b8c2SApple OSS Distributions #include <sys/socket.h>
30*19c3b8c2SApple OSS Distributions #include <sys/syslog.h>
31*19c3b8c2SApple OSS Distributions #include <netinet/in.h>
32*19c3b8c2SApple OSS Distributions #include <stdint.h>
33*19c3b8c2SApple OSS Distributions 
34*19c3b8c2SApple OSS Distributions #ifdef BSD_KERNEL_PRIVATE
35*19c3b8c2SApple OSS Distributions #include <sys/mbuf.h>
36*19c3b8c2SApple OSS Distributions #include <sys/socketvar.h>
37*19c3b8c2SApple OSS Distributions #endif /* BSD_KERNEL_PRIVATE */
38*19c3b8c2SApple OSS Distributions 
39*19c3b8c2SApple OSS Distributions __BEGIN_DECLS
40*19c3b8c2SApple OSS Distributions 
41*19c3b8c2SApple OSS Distributions #ifdef PRIVATE
42*19c3b8c2SApple OSS Distributions 
43*19c3b8c2SApple OSS Distributions typedef enum {
44*19c3b8c2SApple OSS Distributions 	INOUT,
45*19c3b8c2SApple OSS Distributions 	IN,
46*19c3b8c2SApple OSS Distributions 	OUT
47*19c3b8c2SApple OSS Distributions } Pkt_Mnglr_Flow;
48*19c3b8c2SApple OSS Distributions 
49*19c3b8c2SApple OSS Distributions /*
50*19c3b8c2SApple OSS Distributions  * Kernel control name for an instance of a packet mangler.
51*19c3b8c2SApple OSS Distributions  * Use CTLIOCGINFO to find out the corresponding kernel control id
52*19c3b8c2SApple OSS Distributions  * to be set in the sc_id field of sockaddr_ctl for connect(2)
53*19c3b8c2SApple OSS Distributions  * Note: the sc_unit is ephemeral
54*19c3b8c2SApple OSS Distributions  */
55*19c3b8c2SApple OSS Distributions #define PACKET_MANGLER_CONTROL_NAME "com.apple.packet-mangler"
56*19c3b8c2SApple OSS Distributions 
57*19c3b8c2SApple OSS Distributions #define PKT_MNGLR_OPT_PROTO_ACT_MASK    1
58*19c3b8c2SApple OSS Distributions #define PKT_MNGLR_OPT_IP_ACT_MASK       2
59*19c3b8c2SApple OSS Distributions #define PKT_MNGLR_OPT_LOCAL_IP          3
60*19c3b8c2SApple OSS Distributions #define PKT_MNGLR_OPT_REMOTE_IP         4
61*19c3b8c2SApple OSS Distributions #define PKT_MNGLR_OPT_LOCAL_PORT        5
62*19c3b8c2SApple OSS Distributions #define PKT_MNGLR_OPT_REMOTE_PORT       6
63*19c3b8c2SApple OSS Distributions #define PKT_MNGLR_OPT_DIRECTION         7
64*19c3b8c2SApple OSS Distributions #define PKT_MNGLR_OPT_PROTOCOL          8
65*19c3b8c2SApple OSS Distributions #define PKT_MNGLR_OPT_ACTIVATE          0xFFFFFFFF
66*19c3b8c2SApple OSS Distributions 
67*19c3b8c2SApple OSS Distributions /* Packet mangler action masks */
68*19c3b8c2SApple OSS Distributions /* Packet Mangler TCP action mask */
69*19c3b8c2SApple OSS Distributions #define PKT_MNGLR_TCP_ACT_NOP_MPTCP     0x00000001
70*19c3b8c2SApple OSS Distributions #define PKT_MNGLR_TCP_ACT_SWAP_L_PORT   0x00000002
71*19c3b8c2SApple OSS Distributions #define PKT_MNGLR_TCP_ACT_SWAP_R_PORT   0x00000004
72*19c3b8c2SApple OSS Distributions #define PKT_MNGLR_TCP_ACT_DSS_DROP      0x00000008
73*19c3b8c2SApple OSS Distributions #define PKT_MNGLR_TCP_ACT_CHK_EXTENDED  0x80000000
74*19c3b8c2SApple OSS Distributions 
75*19c3b8c2SApple OSS Distributions /* Packet Mangler IP action mask */
76*19c3b8c2SApple OSS Distributions #define PKT_MNGLR_IP_ACT_FLT_L_IP       0x00000001
77*19c3b8c2SApple OSS Distributions #define PKT_MNGLR_IP_ACT_FLT_R_IP       0x00000002
78*19c3b8c2SApple OSS Distributions #define PKT_MNGLR_IP_ACT_SWAP_L_IP      0x00000004
79*19c3b8c2SApple OSS Distributions #define PKT_MNGLR_IP_ACT_SWAP_R_IP      0x00000008
80*19c3b8c2SApple OSS Distributions #define PKT_MNGLR_IP_ACT_DROP_PACKET    0x00000010
81*19c3b8c2SApple OSS Distributions #define PKT_MNGLR_IP_ACT_CHK_EXTENDED   0x80000000
82*19c3b8c2SApple OSS Distributions 
83*19c3b8c2SApple OSS Distributions /*
84*19c3b8c2SApple OSS Distributions  * How many filter may be active simultaneously
85*19c3b8c2SApple OSS Distributions  */
86*19c3b8c2SApple OSS Distributions #define PKT_MNGLR_MAX_FILTER_COUNT      1
87*19c3b8c2SApple OSS Distributions 
88*19c3b8c2SApple OSS Distributions #define PKT_MNGLR_VERSION_CURRENT 1
89*19c3b8c2SApple OSS Distributions 
90*19c3b8c2SApple OSS Distributions #endif /* PRIVATE */
91*19c3b8c2SApple OSS Distributions 
92*19c3b8c2SApple OSS Distributions #ifdef BSD_KERNEL_PRIVATE
93*19c3b8c2SApple OSS Distributions 
94*19c3b8c2SApple OSS Distributions extern int pkt_mnglr_log_level;
95*19c3b8c2SApple OSS Distributions 
96*19c3b8c2SApple OSS Distributions #define PKT_MNGLR_LOG(level, fmt, ...) \
97*19c3b8c2SApple OSS Distributions do { \
98*19c3b8c2SApple OSS Distributions 	if (pkt_mnglr_log_level >= level) \
99*19c3b8c2SApple OSS Distributions 	        printf("%s:%d " fmt "\n",\
100*19c3b8c2SApple OSS Distributions 	                __FUNCTION__, __LINE__, ##__VA_ARGS__); \
101*19c3b8c2SApple OSS Distributions } while (0)
102*19c3b8c2SApple OSS Distributions 
103*19c3b8c2SApple OSS Distributions 
104*19c3b8c2SApple OSS Distributions extern void pkt_mnglr_init(void);
105*19c3b8c2SApple OSS Distributions 
106*19c3b8c2SApple OSS Distributions __END_DECLS
107*19c3b8c2SApple OSS Distributions 
108*19c3b8c2SApple OSS Distributions #endif /* BSD_KERNEL_PRIVATE */
109*19c3b8c2SApple OSS Distributions 
110*19c3b8c2SApple OSS Distributions #endif /* __PACKET_MANGLER_H__ */
111