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