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_DSS_DROP 0x00000008
73#define PKT_MNGLR_TCP_ACT_CHK_EXTENDED 0x80000000
74
75/* Packet Mangler IP action mask */
76#define PKT_MNGLR_IP_ACT_FLT_L_IP 0x00000001
77#define PKT_MNGLR_IP_ACT_FLT_R_IP 0x00000002
78#define PKT_MNGLR_IP_ACT_SWAP_L_IP 0x00000004
79#define PKT_MNGLR_IP_ACT_SWAP_R_IP 0x00000008
80#define PKT_MNGLR_IP_ACT_DROP_PACKET 0x00000010
81#define PKT_MNGLR_IP_ACT_CHK_EXTENDED 0x80000000
82
83/*
84 * How many filter may be active simultaneously
85 */
86#define PKT_MNGLR_MAX_FILTER_COUNT 1
87
88#define PKT_MNGLR_VERSION_CURRENT 1
89
90#endif /* PRIVATE */
91
92#ifdef BSD_KERNEL_PRIVATE
93
94extern int pkt_mnglr_log_level;
95
96#define PKT_MNGLR_LOG(level, fmt, ...) \
97do { \
98 if (pkt_mnglr_log_level >= level) \
99 printf("%s:%d " fmt "\n",\
100 __FUNCTION__, __LINE__, ##__VA_ARGS__); \
101} while (0)
102
103
104extern void pkt_mnglr_init(void);
105
106__END_DECLS
107
108#endif /* BSD_KERNEL_PRIVATE */
109
110#endif /* __PACKET_MANGLER_H__ */
111