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