home *** CD-ROM | disk | FTP | other *** search
/ ftp.sustworks.com 2018 / ftp.sustworks.com.zip / ftp.sustworks.com / open_source_IPNetMonitor_NKE.dmg / ipkTypes.h < prev    next >
C/C++ Source or Header  |  2004-04-22  |  9KB  |  274 lines

  1. //
  2. // ipkTypes.h
  3. // IPNetSentryX
  4. //
  5. // Created by Peter Sichel on Thu Nov 14 2002.
  6. // Copyright (c) 2002 Sustainable Softworks, Inc. All rights reserved.
  7. //
  8. // IPNetSentry_NKE and IPNetRouter_NKE shared types
  9. // This module is designed to be tested as client code and then incorporated
  10. // as part of our NKE
  11.  
  12. #ifndef _H_ipkTypes
  13. #define _H_ipkTypes
  14. #pragma once
  15.  
  16. #include <sys/types.h>
  17. #include <sys/time.h>
  18. #include <libkern/OSTypes.h>
  19.  
  20. #define kBSDNameLength    16
  21. #define kServiceIDNameLength 48
  22.  
  23. // ---------------------------------------------------------------------------
  24. // InterfaceEntry
  25. // ---------------------------------------------------------------------------
  26. // define interfaceEntry to represent interface attach parameters
  27. typedef struct netNumber {
  28.     u_int32_t    address;
  29.     u_int32_t    mask;
  30. } netNumber_t;
  31.  
  32. typedef struct    KFT_interfaceEntry {
  33.     char         bsdName[kBSDNameLength];    // corresponding interface name (CString)
  34.     char        serviceID[kServiceIDNameLength];
  35.     netNumber_t ifNet;
  36.     netNumber_t natNet;
  37.     netNumber_t singleNet;
  38.     netNumber_t excludeNet;
  39.     u_int32_t    exposedHost;
  40.     u_int8_t    exposedHostSelection;
  41.     u_int8_t    filterOn;            // IP filter on this interface
  42.     u_int8_t    externalOn;
  43.     u_int8_t    natOn;                // NAT on this interface
  44. } KFT_interfaceEntry_t;
  45.  
  46. // ---------------------------------------------------------------------------
  47. // Control and Attach instance
  48. // ---------------------------------------------------------------------------
  49. // maximum number of controllers and DLIL attachments use index values 1..n
  50. // 0 is reserved for "not found"
  51. #define kMaxControl    8
  52. #define kMaxAttach 8
  53.  
  54. // controller instance
  55. typedef struct controlE {
  56.     struct socket *ctl;            // Non-null if controlled
  57.     int monitorOn;                // master on/off for this controller
  58.     int nkeSends;                // count packets sent upstream since last request
  59.                                 // so we don't flood input queue when no one is listening
  60.     u_int8_t attachMap[kMaxAttach+1]; // map of corresponding DLIL attachments if any
  61.                                 // map[i]>0 if attached
  62. } control_t;
  63.  
  64. // DLIL attach instance
  65. typedef struct attachE {
  66.     u_long attachID;        // dl_tag used to identify this protocol interface pair
  67.     u_long filterID;        // attached filterID needed to detach this filter
  68.     KFT_interfaceEntry_t kftInterfaceEntry;
  69.     // monitor tool
  70.     u_long sendCount;        // traffic stats for instance
  71.     u_long receiveCount;
  72.     u_long sendStamp;        // capture and hold previous counts for reporting
  73.     u_long receiveStamp;
  74. } attach_t;
  75.  
  76. typedef struct KFT_stat64 {
  77.     int64_t count;
  78.     int64_t previous;
  79.     int64_t delta;
  80. } KFT_stat64_t;
  81.  
  82. typedef struct KFT_stat {
  83.     int32_t count;
  84.     int32_t previous;
  85.     int32_t delta;
  86.     int32_t pad;
  87. } KFT_stat_t;
  88.  
  89. // ---------------------------------------------------------------------------
  90. // Filter Entry
  91. // ---------------------------------------------------------------------------
  92. #define kPropertySize 128
  93. #define kPropertyReserve 32
  94. // define filter table entry
  95. typedef struct KFT_entry {
  96.     u_int16_t nodeCount;
  97.     u_int8_t enabled;
  98.     u_int8_t nodeNumber[16];
  99.     u_int8_t nodeName[32];
  100.     u_int8_t property;
  101.     u_int8_t relation;
  102.     u_int8_t filterAction;
  103.     u_int8_t expandedState;
  104.     int32_t lastTime;
  105.     KFT_stat64_t match;
  106.     KFT_stat64_t byte;
  107.     int32_t param1;        // rate limit in bytes/sec
  108.     int32_t param2;        // rate limit out bytes/sec
  109.     int16_t activeInCount;
  110.     int16_t activeOutCount;
  111.     u_int8_t propertyValue[kPropertySize];    // |propertyValue ->  <- parameterValue|
  112.     u_int8_t pad0;
  113.     u_int8_t pad1;
  114.     u_int8_t propertyEnd;
  115.     u_int8_t parameterStart;
  116. } KFT_entry_t;
  117.  
  118. // ---------------------------------------------------------------------------
  119. // Trigger Entry
  120. // ---------------------------------------------------------------------------
  121. // define trigger table entry used to maintain triggered addresses
  122. typedef struct KFT_triggerEntry {
  123.     u_int32_t lastTime;
  124.     u_int32_t uniqueTime;
  125.     u_int32_t address;
  126.     u_int8_t type;
  127.     u_int8_t flags;
  128.     u_int8_t pad0;
  129.     u_int8_t pad1;
  130.     KFT_stat_t match;
  131.     u_int8_t nodeNumber[16];
  132. } KFT_triggerEntry_t;
  133. #define kTriggerTypeTrigger 1
  134. #define kTriggerTypeAddress 2
  135. #define kTriggerTypeAuthorize 3
  136. #define kTriggerFlagDelete 1
  137. #define kTriggerFlagUpdate 2
  138.  
  139. // ---------------------------------------------------------------------------
  140. // Connection Endpoint
  141. // ---------------------------------------------------------------------------
  142. // define Connection endpoint, MSB->LSB: protocol, port, address
  143. // so that adjacent entries will be in protocol, port order.
  144. typedef struct KFT_connectionEndpoint {
  145.     u_int16_t port;
  146.     u_int8_t  pad;
  147.     u_int8_t  protocol;
  148.     u_int32_t address;
  149. } KFT_connectionEndpoint_t;
  150.  
  151. // ---------------------------------------------------------------------------
  152. // NAT Entry
  153. // ---------------------------------------------------------------------------
  154. // define NAT table
  155. typedef struct KFT_natEntry {
  156.     KFT_connectionEndpoint_t apparent;
  157.     KFT_connectionEndpoint_t actual;
  158.     u_int32_t    lastTime;            // NSTimeInterval since 1970
  159.     u_int32_t    flags;
  160.     int32_t        refCount;
  161.     // NAPT
  162.     u_int16_t    portRange;            // offset to last port in port range
  163. //    u_int16_t    identification;        // from IP header
  164. //    u_int16_t    fragmentOffset;
  165. //    u_int32_t    seqInitial;            // used to offset seq and ack #'s
  166. //    int16_t        seqOffset;            //   for content masquerading
  167. //    u_int32_t    seqInitial2;        // used to offset seq and ack #'s
  168. //    int16_t        seqOffset2;            //   for content masquerading
  169. //    int16_t        seqOffsetPrev;
  170. } KFT_natEntry_t;
  171.  
  172. // Values for NAT entry Flags
  173. //#define kNatFlagPermanent        1        // entry is permanent and cannot be aged out
  174. #define kNatFlagStaticOnly        0x10    // Local NAT use static table only
  175. //#define kNatFlagNoRestore        0x20    // Don't restore this entry
  176. //#define kNatFlagDNSForwarding    0x40    // DNS Forwarding Entry
  177. #define kNatFlagDelete            0x0100
  178. #define kNatFlagUpdate             0x0200
  179. #define kNatFlagRemoveAll        0x0400
  180.  
  181. // ---------------------------------------------------------------------------
  182. // Fragment Entry
  183. // ---------------------------------------------------------------------------
  184. // define IP Fragment table
  185. typedef struct KFT_fragmentId {
  186.     u_int16_t pad;
  187.     u_int16_t identification;
  188.     u_int32_t srcAddress;
  189. } KFT_fragmentId_t;
  190.  
  191. typedef struct KFT_fragmentEntry {
  192.     KFT_fragmentId_t fragment;
  193.     u_int32_t    lastTime;            // NSTimeInterval since 1970 (in seconds)
  194.     u_int16_t    srcPort;            // source and dest ports needed to lookup connection entry
  195.     u_int16_t    dstPort;            // for subsequent fragments
  196. } KFT_fragmentEntry_t;
  197.  
  198.  
  199. // ---------------------------------------------------------------------------
  200. // Connection Entry
  201. // ---------------------------------------------------------------------------
  202. // define connection table entry used to maintain connection state
  203.  
  204. #define kRttIndexMax 2
  205. typedef struct KFT_connectionInfo {
  206.     u_int32_t ackNumber;
  207.     u_int32_t ackDelta;
  208.     u_int32_t seqNumber;
  209.     struct timeval seqTime;
  210.     u_int32_t rtt_msec[kRttIndexMax+1];    // rtt measurements
  211.     int rttIndex;
  212.     int waitForAck;
  213.     u_int16_t mss;
  214.     u_int16_t windowActual;
  215.     u_int16_t windowApparent;
  216. } KFT_connectionInfo_t;
  217.  
  218. typedef struct KFT_connectionEntry {
  219.     KFT_connectionEndpoint_t remote;
  220.     KFT_connectionEndpoint_t local;
  221.     KFT_stat_t    dataIn;
  222.     KFT_stat_t    dataOut;
  223.     u_int32_t    lastTime;
  224.     u_int32_t    firstTime;
  225.     u_int32_t    lastReport;
  226.     u_int32_t    flags;
  227.     u_int16_t    dropCount;
  228.     // bandwidth management
  229.     KFT_connectionInfo_t sInfo;
  230.     KFT_connectionInfo_t rInfo;
  231.     int rateLimitRule;        // index of rule in filter table (for rate limit bandwidth bytes/sec)
  232.     // NAPT
  233.     KFT_natEntry_t* natEntry;
  234. } KFT_connectionEntry_t;
  235.  
  236. // Values for NAT entry Flags
  237. #define kConnectionFlagFINLocal            2        // Seen TCP FIN from local host
  238. #define kConnectionFlagFINPeer            4        // Seen TCP FIN from peer
  239. #define kConnectionFlagClosed            8        // Closed by firewall
  240. #define kConnectionFlagNonSyn            0x80    // Sent more than a Syn
  241. #define kConnectionFlagDelete            0x0100
  242. #define kConnectionFlagUpdate             0x0200
  243.  
  244. // ---------------------------------------------------------------------------
  245. // packet data
  246. // ---------------------------------------------------------------------------
  247. // structure used to pass around packets
  248. typedef struct KFT_packetData {
  249.     struct ifnet **ifnet_ptr;
  250.     struct mbuf    **mbuf_ptr;    // pointer to mbuf chain
  251.     char    **frame_ptr;        // frame pointer
  252.     attach_t* myAttach;    // pointer to interface attach instance for this datagram
  253.     KFT_entry_t* kftEntry;    // matching filter entry
  254.     KFT_triggerEntry_t* triggerEntry;    // matching trigger entry
  255.     KFT_connectionEntry_t* connectionEntry;    // matching connection state entry
  256.     KFT_natEntry_t* natEntry;    // matching nat entry if any
  257.     u_int8_t* datagram;    // start of datagram in first mbuf
  258.     int segmentLen;        // length of data segment
  259.     u_int16_t    ipOffset;    // integer offset to start of IP datagram within mbuf data
  260.     u_int16_t    matchOffset;    // base for relative data content matching
  261.     u_int16_t    textOffset;        // display what we found
  262.     u_int16_t    textLength;
  263.     u_int8_t    direction;    // 0=output, 1=input (from which intercept was called)
  264.     u_int8_t ifType;        // from ifnet 
  265.     u_int8_t ifHeaderLen;    // length of frame header
  266.     u_int8_t ipHeaderLen;
  267.     u_int8_t transportHeaderLen;
  268.     u_int8_t leafAction;    // remember leaf action for children if any
  269.     u_int8_t dontLog;        // mark as not to be logged (1 = dont log)
  270.     u_int8_t pad;
  271. } KFT_packetData_t;
  272.  
  273. #endif
  274.