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