home *** CD-ROM | disk | FTP | other *** search
/ PC Format (South-Africa) 2001 June / PCFJune.iso / Xenon / C++ / FreeCommandLineTools.exe / Include / fltdefs.h < prev    next >
Encoding:
C/C++ Source or Header  |  2000-01-31  |  13.8 KB  |  408 lines

  1. /*++
  2.  
  3. Copyright (c) 1995-1999  Microsoft Corporation
  4.  
  5. Module Name:
  6.  
  7.    fltdefs.h
  8.  
  9. Abstract:
  10.  
  11.     Definitions for the WIN32 filter APIs
  12.  
  13. Author:
  14.  
  15.     Arnold Miller (arnoldm) 24-Sept-1997
  16.  
  17. Revision History:
  18.  
  19. --*/
  20.  
  21. #ifndef _FLTDEFS_H
  22. #pragma option push -b -a8 -pc -A- /*P_O_Push*/
  23. #define _FLTDEFS_H
  24.  
  25. #if _MSC_VER > 1000
  26. #pragma once
  27. #endif
  28.  
  29. typedef PVOID  FILTER_HANDLE, *PFILTER_HANDLE;
  30. typedef PVOID  INTERFACE_HANDLE, *PINTERFACE_HANDLE;
  31.  
  32. #define PFEXPORT _declspec(dllexport)
  33.  
  34. #ifdef __cplusplus
  35. #define EXTERNCDECL EXTERN_C
  36. #else
  37. #define EXTERNCDECL
  38. #endif
  39.  
  40. #define PFAPIENTRY EXTERNCDECL DWORD PFEXPORT WINAPI
  41.  
  42. typedef enum _GlobalFilter
  43. {
  44.     GF_FRAGMENTS = 2,        // check consistency of fragments
  45.     GF_STRONGHOST = 8,       // check destination address of input frames
  46.     GF_FRAGCACHE = 9         // check fragments from cache
  47. } GLOBAL_FILTER, *PGLOBAL_FILTER;
  48.  
  49. typedef enum _PfForwardAction
  50. {
  51.     PF_ACTION_FORWARD = 0,
  52.     PF_ACTION_DROP
  53. } PFFORWARD_ACTION, *PPFFORWARD_ACTION;
  54.  
  55. typedef enum _PfAddresType
  56. {
  57.     PF_IPV4,
  58.     PF_IPV6
  59. } PFADDRESSTYPE, *PPFADDRESSTYPE;
  60.  
  61. //////////////////////////////////////////////////////////////////////////////
  62. //                                                                          //
  63. // The constants that should be used to set up the FILTER_INFO_STRUCTURE    //
  64. //                                                                          //
  65. //////////////////////////////////////////////////////////////////////////////
  66.  
  67. #define FILTER_PROTO(ProtoId)   MAKELONG(MAKEWORD((ProtoId),0x00),0x00000)
  68.  
  69. #define FILTER_PROTO_ANY        FILTER_PROTO(0x00)
  70. #define FILTER_PROTO_ICMP       FILTER_PROTO(0x01)
  71. #define FILTER_PROTO_TCP        FILTER_PROTO(0x06)
  72. #define FILTER_PROTO_UDP        FILTER_PROTO(0x11)
  73.  
  74. #define FILTER_TCPUDP_PORT_ANY  (WORD)0x0000
  75.  
  76. #define FILTER_ICMP_TYPE_ANY    (BYTE)0xff
  77. #define FILTER_ICMP_CODE_ANY    (BYTE)0xff
  78.  
  79. typedef struct _PF_FILTER_DESCRIPTOR
  80. {
  81.     DWORD           dwFilterFlags;    // see below
  82.     DWORD           dwRule;           // copied into the log when appropriate
  83.     PFADDRESSTYPE   pfatType;
  84.     PBYTE           SrcAddr;
  85.     PBYTE           SrcMask;
  86.     PBYTE           DstAddr;
  87.     PBYTE           DstMask;
  88.     DWORD           dwProtocol;
  89.     DWORD           fLateBound;
  90.     WORD            wSrcPort;
  91.     WORD            wDstPort;
  92.     WORD            wSrcPortHighRange;
  93.     WORD            wDstPortHighRange;
  94. }PF_FILTER_DESCRIPTOR, *PPF_FILTER_DESCRIPTOR;
  95.  
  96.  
  97. //////////////////////////////////////////////////////////////////////////////
  98. //                                                                          //
  99. // Structure for PfGetInterfaceStatistics                                   //
  100. //                                                                          //
  101. //////////////////////////////////////////////////////////////////////////////
  102.  
  103. typedef struct _PF_FILTER_STATS
  104. {
  105.     DWORD       dwNumPacketsFiltered;
  106.     PF_FILTER_DESCRIPTOR info;
  107. }PF_FILTER_STATS, *PPF_FILTER_STATS;
  108.  
  109. typedef struct _PF_INTERFACE_STATS
  110. {
  111.     PVOID               pvDriverContext;
  112.     DWORD               dwFlags;          // none as yet (28-Sept-1997)
  113.     DWORD               dwInDrops;
  114.     DWORD               dwOutDrops;
  115.     PFFORWARD_ACTION    eaInAction;
  116.     PFFORWARD_ACTION    eaOutAction;
  117.     DWORD               dwNumInFilters;
  118.     DWORD               dwNumOutFilters;
  119.     DWORD               dwFrag;
  120.     DWORD               dwSpoof;
  121.     DWORD               dwReserved1;
  122.     DWORD               dwReserved2;
  123.     LARGE_INTEGER       liSYN;
  124.     LARGE_INTEGER       liTotalLogged;
  125.     DWORD               dwLostLogEntries;
  126.     PF_FILTER_STATS     FilterInfo[1];
  127. } PF_INTERFACE_STATS, *PPF_INTERFACE_STATS;
  128.  
  129.  
  130. //////////////////////////////////////////////////////////////////////////////
  131. //                                                                          //
  132. // The number of bytes starting at SrcAddr. If you add something to the     //
  133. // structure make sure this remains valid                                   //
  134. //                                                                          //
  135. //////////////////////////////////////////////////////////////////////////////
  136.  
  137. #define FILTERSIZE                                      \
  138.     (sizeof(PF_FILTER_DESCRIPTOR) -                     \
  139.      (DWORD)(&((PPF_FILTER_DESCRIPTOR)0)->SrcAddr))
  140.  
  141.  
  142. //////////////////////////////////////////////////////////////////////////////
  143. //                                                                          //
  144. // Flags for PF_FILTER_DESCRIPTOR                                           //
  145. //                                                                          //
  146. //////////////////////////////////////////////////////////////////////////////
  147.  
  148. //
  149. // Disallows incoming SYN
  150. //
  151.  
  152. #define FD_FLAGS_NOSYN      0x1
  153.  
  154. //
  155. // All legal flags
  156. //
  157.  
  158. #define FD_FLAGS_ALLFLAGS   FD_FLAGS_NOSYN
  159.  
  160.  
  161. //////////////////////////////////////////////////////////////////////////////
  162. //                                                                          //
  163. // Late bound defs. Go in fLateBound in a PF_FILTER_DESCRIPTOR and          //
  164. // describe which other fields of the filter are affected  by a             //
  165. // PfRebindFilters call. In general such filters are on  WAN interfaces     //
  166. // where one or the other address may change as the connection is           //
  167. // reconnected.                                                             //
  168. // The assumption is that such interfaces HAVE ONLY ONE ADDRESS.            //
  169. //                                                                          //
  170. //////////////////////////////////////////////////////////////////////////////
  171.  
  172.  
  173. #define LB_SRC_ADDR_USE_SRCADDR_FLAG     0x00000001
  174. #define LB_SRC_ADDR_USE_DSTADDR_FLAG     0x00000002
  175. #define LB_DST_ADDR_USE_SRCADDR_FLAG     0x00000004
  176. #define LB_DST_ADDR_USE_DSTADDR_FLAG     0x00000008
  177. #define LB_SRC_MASK_LATE_FLAG            0x00000010
  178. #define LB_DST_MASK_LATE_FLAG            0x00000020
  179.  
  180. typedef struct _PF_LATEBIND_INFO
  181. {
  182.     PBYTE   SrcAddr;
  183.     PBYTE   DstAddr;
  184.     PBYTE   Mask;
  185. }PF_LATEBIND_INFO, *PPF_LATEBIND_INFO;
  186.  
  187. //////////////////////////////////////////////////////////////////////////////
  188. //                                                                          //
  189. // The format of a logged frame and defs for it.                            //
  190. //                                                                          //
  191. //////////////////////////////////////////////////////////////////////////////
  192.  
  193. typedef enum _PfFrameType
  194. {
  195.     PFFT_FILTER = 1,                  // a filter violation
  196.     PFFT_FRAG   = 2,                  // bad fragment
  197.     PFFT_SPOOF   = 3                  // strong host failure
  198. } PFFRAMETYPE, *PPFFRAMETYPE;
  199.  
  200. typedef struct _pfLogFrame
  201. {
  202.     LARGE_INTEGER  Timestamp;
  203.     PFFRAMETYPE    pfeTypeOfFrame;
  204.     DWORD          dwTotalSizeUsed;      // used to find the next frame
  205.     DWORD          dwFilterRule;         // from the filter
  206.     WORD           wSizeOfAdditionalData;
  207.     WORD           wSizeOfIpHeader;
  208.     DWORD          dwInterfaceName;      // the name of the interface
  209.     DWORD          dwIPIndex;
  210.     BYTE           bPacketData[1];       // the frame. wsizeOfIpHeader
  211.                                          // and wsizeOfAdditionalData
  212.                                          // describe this
  213. } PFLOGFRAME, *PPFLOGFRAME;
  214.  
  215. //////////////////////////////////////////////////////////////////////////////
  216. //                                                                          //
  217. // Error codes. These extend the WIN32 errors by having errors specific to  //
  218. // these APIs. Besides these errors, the APIs may return any of the WIN32   //
  219. // errors.                                                                  //
  220. //                                                                          //
  221. //////////////////////////////////////////////////////////////////////////////
  222.  
  223.  
  224. #define ERROR_BASE  23000
  225.  
  226. #define PFERROR_NO_PF_INTERFACE    (ERROR_BASE + 0)   // never returned.
  227. #define PFERROR_NO_FILTERS_GIVEN   (ERROR_BASE + 1)
  228. #define PFERROR_BUFFER_TOO_SMALL   (ERROR_BASE + 2)
  229. #define ERROR_IPV6_NOT_IMPLEMENTED (ERROR_BASE + 3)
  230.  
  231.  
  232. //////////////////////////////////////////////////////////////////////////////
  233. //                                                                          //
  234. // The API prototypes                                                       //
  235. //                                                                          //
  236. //////////////////////////////////////////////////////////////////////////////
  237.  
  238. PFAPIENTRY
  239. PfCreateInterface(
  240.     DWORD            dwName,
  241.     PFFORWARD_ACTION inAction,
  242.     PFFORWARD_ACTION outAction,
  243.     BOOL             bUseLog,
  244.     BOOL             bMustBeUnique,
  245.     INTERFACE_HANDLE *ppInterface
  246.     );
  247.  
  248. PFAPIENTRY
  249. PfDeleteInterface(
  250.     INTERFACE_HANDLE pInterface
  251.     );
  252.  
  253. PFAPIENTRY
  254. PfAddFiltersToInterface(
  255.     INTERFACE_HANDLE      ih,
  256.     DWORD                 cInFilters,
  257.     PPF_FILTER_DESCRIPTOR pfiltIn,
  258.     DWORD                 cOutFilters,
  259.     PPF_FILTER_DESCRIPTOR pfiltOut,
  260.     PFILTER_HANDLE        pfHandle
  261.     );
  262.  
  263. PFAPIENTRY
  264. PfRemoveFiltersFromInterface(
  265.     INTERFACE_HANDLE      ih,
  266.     DWORD                 cInFilters,
  267.     PPF_FILTER_DESCRIPTOR pfiltIn,
  268.     DWORD                 cOutFilters,
  269.     PPF_FILTER_DESCRIPTOR pfiltOut
  270.     );
  271.  
  272. PFAPIENTRY
  273. PfRemoveFilterHandles(
  274.     INTERFACE_HANDLE   pInterface,
  275.     DWORD              cFilters,
  276.     PFILTER_HANDLE     pvHandles
  277.     );
  278.  
  279.  
  280. PFAPIENTRY
  281. PfUnBindInterface(
  282.     INTERFACE_HANDLE   pInterface
  283.     );
  284.  
  285. PFAPIENTRY
  286. PfBindInterfaceToIndex(
  287.     INTERFACE_HANDLE    pInterface,
  288.     DWORD               dwIndex,
  289.     PFADDRESSTYPE       pfatLinkType,
  290.     PBYTE               LinkIPAddress
  291.     );
  292.  
  293. PFAPIENTRY
  294. PfBindInterfaceToIPAddress(
  295.     INTERFACE_HANDLE    pInterface,
  296.     PFADDRESSTYPE       pfatType,
  297.     PBYTE               IPAddress
  298.     );
  299.  
  300. PFAPIENTRY
  301. PfRebindFilters(
  302.     INTERFACE_HANDLE    pInterface,
  303.     PPF_LATEBIND_INFO   pLateBindInfo
  304.     );
  305.  
  306. PFAPIENTRY
  307. PfAddGlobalFilterToInterface(
  308.     INTERFACE_HANDLE   pInterface,
  309.     GLOBAL_FILTER      gfFilter
  310.     );
  311.  
  312. PFAPIENTRY
  313. PfRemoveGlobalFilterFromInterface(
  314.     INTERFACE_HANDLE   pInterface,
  315.     GLOBAL_FILTER      gfFilter
  316.     );
  317.  
  318.  
  319. //////////////////////////////////////////////////////////////////////////////
  320. //                                                                          //
  321. // Log APIs. Note that there is at most one log and it must be created      //
  322. // before any interface needing it is created. There is no way to set a     //
  323. // log onto an existing interface. The log can be applied to any or all of  //
  324. // the interfaces.                                                          //
  325. //                                                                          //
  326. //////////////////////////////////////////////////////////////////////////////
  327.  
  328. PFAPIENTRY
  329. PfMakeLog(
  330.     HANDLE  hEvent
  331.     );
  332.  
  333. //
  334. // Provide a buffer, and notification parameters, and get back
  335. // the old buffer and status.
  336. //
  337.  
  338. PFAPIENTRY
  339. PfSetLogBuffer(
  340.     PBYTE   pbBuffer,
  341.     DWORD   dwSize,
  342.     DWORD   dwThreshold,
  343.     DWORD   dwEntries,
  344.     PDWORD  pdwLoggedEntries,
  345.     PDWORD  pdwLostEntries,
  346.     PDWORD  pdwSizeUsed
  347.     );
  348.  
  349. //
  350. // Doing this will disable the log on any of the interfaces. But if
  351. // an interface was created with the log, the actual log will not be
  352. // completely deleted until that interface is deleted. This is a small
  353. // point, but it might explain a mystery or two.
  354. //
  355.  
  356. PFAPIENTRY
  357. PfDeleteLog(
  358.     VOID
  359.     );
  360.  
  361.  
  362. //////////////////////////////////////////////////////////////////////////////
  363. //                                                                          //
  364. // Get statistics. Note pdwBufferSize in an IN/OUT parameter. If            //
  365. // ERROR_INSUFFICIENT_BUFFER is returned, the common statistics are         //
  366. // available and the correct byte count is in *pdwBufferSize. If only the   //
  367. // interface statistics are needed, provide a buffer of size                //
  368. // PF_INTERFACE_STATS only.                                                 //
  369. // If the filter descriptions are also needed, then supply a large buffer,  //
  370. // or use the returned count from the first call to allocate a buffer of    //
  371. // sufficient size. Note that for a shared interface, this second call may  //
  372. // fail with ERROR_INSUFFICIENT_BUFFER. This can happen if the other        //
  373. // sharers add filters in the interim. This should not happen for a UNIQUE  //
  374. // interface.                                                               //
  375. //                                                                          //
  376. //////////////////////////////////////////////////////////////////////////////
  377.  
  378.  
  379. PFAPIENTRY
  380. PfGetInterfaceStatistics(
  381.     INTERFACE_HANDLE    pInterface,
  382.     PPF_INTERFACE_STATS ppfStats,
  383.     PDWORD              pdwBufferSize,
  384.     BOOL                fResetCounters
  385.     );
  386.  
  387.  
  388. //////////////////////////////////////////////////////////////////////////////
  389. //                                                                          //
  390. // Test a packet.                                                           //
  391. // This call will evaluate the packet against the given interfaces          //
  392. // and return the filtering action.                                         //
  393. //                                                                          //
  394. //////////////////////////////////////////////////////////////////////////////
  395.  
  396. PFAPIENTRY
  397. PfTestPacket(
  398.     INTERFACE_HANDLE   pInInterface  OPTIONAL,
  399.     INTERFACE_HANDLE   pOutInterface OPTIONAL,
  400.     DWORD              cBytes,
  401.     PBYTE              pbPacket,
  402.     PPFFORWARD_ACTION  ppAction
  403.     );
  404.  
  405.  
  406. #pragma option pop /*P_O_Pop*/
  407. #endif
  408.