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 >
Wrap
C/C++ Source or Header
|
2004-04-22
|
9KB
|
274 lines
//
// ipkTypes.h
// IPNetSentryX
//
// Created by Peter Sichel on Thu Nov 14 2002.
// Copyright (c) 2002 Sustainable Softworks, Inc. All rights reserved.
//
// IPNetSentry_NKE and IPNetRouter_NKE shared types
// This module is designed to be tested as client code and then incorporated
// as part of our NKE
#ifndef _H_ipkTypes
#define _H_ipkTypes
#pragma once
#include <sys/types.h>
#include <sys/time.h>
#include <libkern/OSTypes.h>
#define kBSDNameLength 16
#define kServiceIDNameLength 48
// ---------------------------------------------------------------------------
// InterfaceEntry
// ---------------------------------------------------------------------------
// define interfaceEntry to represent interface attach parameters
typedef struct netNumber {
u_int32_t address;
u_int32_t mask;
} netNumber_t;
typedef struct KFT_interfaceEntry {
char bsdName[kBSDNameLength]; // corresponding interface name (CString)
char serviceID[kServiceIDNameLength];
netNumber_t ifNet;
netNumber_t natNet;
netNumber_t singleNet;
netNumber_t excludeNet;
u_int32_t exposedHost;
u_int8_t exposedHostSelection;
u_int8_t filterOn; // IP filter on this interface
u_int8_t externalOn;
u_int8_t natOn; // NAT on this interface
} KFT_interfaceEntry_t;
// ---------------------------------------------------------------------------
// Control and Attach instance
// ---------------------------------------------------------------------------
// maximum number of controllers and DLIL attachments use index values 1..n
// 0 is reserved for "not found"
#define kMaxControl 8
#define kMaxAttach 8
// controller instance
typedef struct controlE {
struct socket *ctl; // Non-null if controlled
int monitorOn; // master on/off for this controller
int nkeSends; // count packets sent upstream since last request
// so we don't flood input queue when no one is listening
u_int8_t attachMap[kMaxAttach+1]; // map of corresponding DLIL attachments if any
// map[i]>0 if attached
} control_t;
// DLIL attach instance
typedef struct attachE {
u_long attachID; // dl_tag used to identify this protocol interface pair
u_long filterID; // attached filterID needed to detach this filter
KFT_interfaceEntry_t kftInterfaceEntry;
// monitor tool
u_long sendCount; // traffic stats for instance
u_long receiveCount;
u_long sendStamp; // capture and hold previous counts for reporting
u_long receiveStamp;
} attach_t;
typedef struct KFT_stat64 {
int64_t count;
int64_t previous;
int64_t delta;
} KFT_stat64_t;
typedef struct KFT_stat {
int32_t count;
int32_t previous;
int32_t delta;
int32_t pad;
} KFT_stat_t;
// ---------------------------------------------------------------------------
// Filter Entry
// ---------------------------------------------------------------------------
#define kPropertySize 128
#define kPropertyReserve 32
// define filter table entry
typedef struct KFT_entry {
u_int16_t nodeCount;
u_int8_t enabled;
u_int8_t nodeNumber[16];
u_int8_t nodeName[32];
u_int8_t property;
u_int8_t relation;
u_int8_t filterAction;
u_int8_t expandedState;
int32_t lastTime;
KFT_stat64_t match;
KFT_stat64_t byte;
int32_t param1; // rate limit in bytes/sec
int32_t param2; // rate limit out bytes/sec
int16_t activeInCount;
int16_t activeOutCount;
u_int8_t propertyValue[kPropertySize]; // |propertyValue -> <- parameterValue|
u_int8_t pad0;
u_int8_t pad1;
u_int8_t propertyEnd;
u_int8_t parameterStart;
} KFT_entry_t;
// ---------------------------------------------------------------------------
// Trigger Entry
// ---------------------------------------------------------------------------
// define trigger table entry used to maintain triggered addresses
typedef struct KFT_triggerEntry {
u_int32_t lastTime;
u_int32_t uniqueTime;
u_int32_t address;
u_int8_t type;
u_int8_t flags;
u_int8_t pad0;
u_int8_t pad1;
KFT_stat_t match;
u_int8_t nodeNumber[16];
} KFT_triggerEntry_t;
#define kTriggerTypeTrigger 1
#define kTriggerTypeAddress 2
#define kTriggerTypeAuthorize 3
#define kTriggerFlagDelete 1
#define kTriggerFlagUpdate 2
// ---------------------------------------------------------------------------
// Connection Endpoint
// ---------------------------------------------------------------------------
// define Connection endpoint, MSB->LSB: protocol, port, address
// so that adjacent entries will be in protocol, port order.
typedef struct KFT_connectionEndpoint {
u_int16_t port;
u_int8_t pad;
u_int8_t protocol;
u_int32_t address;
} KFT_connectionEndpoint_t;
// ---------------------------------------------------------------------------
// NAT Entry
// ---------------------------------------------------------------------------
// define NAT table
typedef struct KFT_natEntry {
KFT_connectionEndpoint_t apparent;
KFT_connectionEndpoint_t actual;
u_int32_t lastTime; // NSTimeInterval since 1970
u_int32_t flags;
int32_t refCount;
// NAPT
u_int16_t portRange; // offset to last port in port range
// u_int16_t identification; // from IP header
// u_int16_t fragmentOffset;
// u_int32_t seqInitial; // used to offset seq and ack #'s
// int16_t seqOffset; // for content masquerading
// u_int32_t seqInitial2; // used to offset seq and ack #'s
// int16_t seqOffset2; // for content masquerading
// int16_t seqOffsetPrev;
} KFT_natEntry_t;
// Values for NAT entry Flags
//#define kNatFlagPermanent 1 // entry is permanent and cannot be aged out
#define kNatFlagStaticOnly 0x10 // Local NAT use static table only
//#define kNatFlagNoRestore 0x20 // Don't restore this entry
//#define kNatFlagDNSForwarding 0x40 // DNS Forwarding Entry
#define kNatFlagDelete 0x0100
#define kNatFlagUpdate 0x0200
#define kNatFlagRemoveAll 0x0400
// ---------------------------------------------------------------------------
// Fragment Entry
// ---------------------------------------------------------------------------
// define IP Fragment table
typedef struct KFT_fragmentId {
u_int16_t pad;
u_int16_t identification;
u_int32_t srcAddress;
} KFT_fragmentId_t;
typedef struct KFT_fragmentEntry {
KFT_fragmentId_t fragment;
u_int32_t lastTime; // NSTimeInterval since 1970 (in seconds)
u_int16_t srcPort; // source and dest ports needed to lookup connection entry
u_int16_t dstPort; // for subsequent fragments
} KFT_fragmentEntry_t;
// ---------------------------------------------------------------------------
// Connection Entry
// ---------------------------------------------------------------------------
// define connection table entry used to maintain connection state
#define kRttIndexMax 2
typedef struct KFT_connectionInfo {
u_int32_t ackNumber;
u_int32_t ackDelta;
u_int32_t seqNumber;
struct timeval seqTime;
u_int32_t rtt_msec[kRttIndexMax+1]; // rtt measurements
int rttIndex;
int waitForAck;
u_int16_t mss;
u_int16_t windowActual;
u_int16_t windowApparent;
} KFT_connectionInfo_t;
typedef struct KFT_connectionEntry {
KFT_connectionEndpoint_t remote;
KFT_connectionEndpoint_t local;
KFT_stat_t dataIn;
KFT_stat_t dataOut;
u_int32_t lastTime;
u_int32_t firstTime;
u_int32_t lastReport;
u_int32_t flags;
u_int16_t dropCount;
// bandwidth management
KFT_connectionInfo_t sInfo;
KFT_connectionInfo_t rInfo;
int rateLimitRule; // index of rule in filter table (for rate limit bandwidth bytes/sec)
// NAPT
KFT_natEntry_t* natEntry;
} KFT_connectionEntry_t;
// Values for NAT entry Flags
#define kConnectionFlagFINLocal 2 // Seen TCP FIN from local host
#define kConnectionFlagFINPeer 4 // Seen TCP FIN from peer
#define kConnectionFlagClosed 8 // Closed by firewall
#define kConnectionFlagNonSyn 0x80 // Sent more than a Syn
#define kConnectionFlagDelete 0x0100
#define kConnectionFlagUpdate 0x0200
// ---------------------------------------------------------------------------
// packet data
// ---------------------------------------------------------------------------
// structure used to pass around packets
typedef struct KFT_packetData {
struct ifnet **ifnet_ptr;
struct mbuf **mbuf_ptr; // pointer to mbuf chain
char **frame_ptr; // frame pointer
attach_t* myAttach; // pointer to interface attach instance for this datagram
KFT_entry_t* kftEntry; // matching filter entry
KFT_triggerEntry_t* triggerEntry; // matching trigger entry
KFT_connectionEntry_t* connectionEntry; // matching connection state entry
KFT_natEntry_t* natEntry; // matching nat entry if any
u_int8_t* datagram; // start of datagram in first mbuf
int segmentLen; // length of data segment
u_int16_t ipOffset; // integer offset to start of IP datagram within mbuf data
u_int16_t matchOffset; // base for relative data content matching
u_int16_t textOffset; // display what we found
u_int16_t textLength;
u_int8_t direction; // 0=output, 1=input (from which intercept was called)
u_int8_t ifType; // from ifnet
u_int8_t ifHeaderLen; // length of frame header
u_int8_t ipHeaderLen;
u_int8_t transportHeaderLen;
u_int8_t leafAction; // remember leaf action for children if any
u_int8_t dontLog; // mark as not to be logged (1 = dont log)
u_int8_t pad;
} KFT_packetData_t;
#endif