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