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