xref: /reactos/sdk/include/psdk/fltdefs.h (revision 2adbfdf6)
1 /*
2  * fltdefs.h
3  *
4  * This file is part of the ReactOS PSDK package.
5  *
6  * Contributors:
7  *   Created by Timo Kreuzer.
8  *
9  * THIS SOFTWARE IS NOT COPYRIGHTED
10  *
11  * This source code is offered for use in the public domain. You may
12  * use, modify or distribute it freely.
13  *
14  * This code is distributed in the hope that it will be useful but
15  * WITHOUT ANY WARRANTY. ALL WARRANTIES, EXPRESS OR IMPLIED ARE HEREBY
16  * DISCLAIMED. This includes but is not limited to warranties of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
18  *
19  */
20 
21 #ifndef _FLTDEFS_H
22 #define _FLTDEFS_H
23 
24 #pragma once
25 
26 #ifdef __cplusplus
27 #define EXTERNCDECL EXTERN_C
28 #else
29 #define EXTERNCDECL
30 #endif
31 
32 #ifdef _M_CEE_PURE
33 #define PFEXPORT
34 #else
35 #define PFEXPORT /* __declspec(dllexport) Native headers have this, but this breaks exports with GCC! */
36 #endif
37 
38 #define PFAPIENTRY EXTERNCDECL DWORD PFEXPORT WINAPI
39 
40 #define ERROR_BASE 23000
41 #define PFERROR_NO_PF_INTERFACE    (ERROR_BASE + 0)
42 #define PFERROR_NO_FILTERS_GIVEN   (ERROR_BASE + 1)
43 #define PFERROR_BUFFER_TOO_SMALL   (ERROR_BASE + 2)
44 #define ERROR_IPV6_NOT_IMPLEMENTED (ERROR_BASE + 3)
45 
46 #define FD_FLAGS_NOSYN        0x1
47 #define FD_FLAGS_ALLFLAGS     FD_FLAGS_NOSYN
48 
49 #define FILTER_PROTO(ProtoId)  MAKELONG(MAKEWORD((ProtoId), 0x00), 0x00000)
50 #define FILTER_PROTO_ANY       FILTER_PROTO(0x00)
51 #define FILTER_PROTO_ICMP      FILTER_PROTO(0x01)
52 #define FILTER_PROTO_TCP       FILTER_PROTO(0x06)
53 #define FILTER_PROTO_UDP       FILTER_PROTO(0x11)
54 
55 #define FILTER_TCPUDP_PORT_ANY ((WORD)0x0000)
56 #define FILTER_ICMP_TYPE_ANY   ((BYTE)0xff)
57 #define FILTER_ICMP_CODE_ANY   ((BYTE)0xff)
58 
59 #define LB_SRC_ADDR_USE_SRCADDR_FLAG 0x00000001
60 #define LB_SRC_ADDR_USE_DSTADDR_FLAG 0x00000002
61 #define LB_DST_ADDR_USE_SRCADDR_FLAG 0x00000004
62 #define LB_DST_ADDR_USE_DSTADDR_FLAG 0x00000008
63 #define LB_SRC_MASK_LATE_FLAG        0x00000010
64 #define LB_DST_MASK_LATE_FLAG        0x00000020
65 
66 typedef PVOID FILTER_HANDLE, * PFILTER_HANDLE;
67 typedef PVOID INTERFACE_HANDLE, * PINTERFACE_HANDLE;
68 
69 typedef enum _GlobalFilter
70 {
71     GF_FRAGMENTS = 2,
72     GF_STRONGHOST = 8,
73     GF_FRAGCACHE = 9
74 } GLOBAL_FILTER, *PGLOBAL_FILTER;
75 
76 typedef enum _PfAddresType
77 {
78     PF_IPV4,
79     PF_IPV6
80 } PFADDRESSTYPE, *PPFADDRESSTYPE;
81 
82 typedef enum _PfForwardAction
83 {
84     PF_ACTION_FORWARD = 0,
85     PF_ACTION_DROP
86 } PFFORWARD_ACTION, *PPFFORWARD_ACTION;
87 
88 typedef enum _PfFrameType
89 {
90     PFFT_FILTER = 1,
91     PFFT_FRAG = 2,
92     PFFT_SPOOF = 3
93 } PFFRAMETYPE, *PPFFRAMETYPE;
94 
95 typedef struct _pfLogFrame
96 {
97     LARGE_INTEGER Timestamp;
98     PFFRAMETYPE pfeTypeOfFrame;
99     DWORD dwTotalSizeUsed;
100     DWORD dwFilterRule;
101     WORD wSizeOfAdditionalData;
102     WORD wSizeOfIpHeader;
103     DWORD dwInterfaceName;
104     DWORD dwIPIndex;
105     BYTE bPacketData[1];
106 } PFLOGFRAME, *PPFLOGFRAME;
107 
108 typedef struct _PF_FILTER_DESCRIPTOR
109 {
110     DWORD dwFilterFlags;
111     DWORD dwRule;
112     PFADDRESSTYPE pfatType;
113     PBYTE SrcAddr;
114     PBYTE SrcMask;
115     PBYTE DstAddr;
116     PBYTE DstMask;
117     DWORD dwProtocol;
118     DWORD fLateBound;
119     WORD wSrcPort;
120     WORD wDstPort;
121     WORD wSrcPortHighRange;
122     WORD wDstPortHighRange;
123 } PF_FILTER_DESCRIPTOR, *PPF_FILTER_DESCRIPTOR;
124 
125 #define FILTERSIZE (sizeof(PF_FILTER_DESCRIPTOR) - (DWORD)FIELD_OFFSET(PF_FILTER_DESCRIPTOR, SrcAddr))
126 
127 typedef struct _PF_FILTER_STATS
128 {
129     DWORD dwNumPacketsFiltered;
130     PF_FILTER_DESCRIPTOR info;
131 } PF_FILTER_STATS, *PPF_FILTER_STATS;
132 
133 typedef struct _PF_INTERFACE_STATS
134 {
135     PVOID pvDriverContext;
136     DWORD dwFlags;
137     DWORD dwInDrops;
138     DWORD dwOutDrops;
139     PFFORWARD_ACTION eaInAction;
140     PFFORWARD_ACTION eaOutAction;
141     DWORD dwNumInFilters;
142     DWORD dwNumOutFilters;
143     DWORD dwFrag;
144     DWORD dwSpoof;
145     DWORD dwReserved1;
146     DWORD dwReserved2;
147     LARGE_INTEGER liSYN;
148     LARGE_INTEGER liTotalLogged;
149     DWORD dwLostLogEntries;
150     PF_FILTER_STATS FilterInfo[1];
151 } PF_INTERFACE_STATS, *PPF_INTERFACE_STATS;
152 
153 typedef struct _PF_LATEBIND_INFO
154 {
155     PBYTE SrcAddr;
156     PBYTE DstAddr;
157     PBYTE Mask;
158 } PF_LATEBIND_INFO, *PPF_LATEBIND_INFO;
159 
160 PFAPIENTRY
161 PfAddFiltersToInterface(
162     INTERFACE_HANDLE ih,
163     DWORD cInFilters,
164     PPF_FILTER_DESCRIPTOR pfiltIn,
165     DWORD cOutFilters,
166     PPF_FILTER_DESCRIPTOR pfiltOut,
167     PFILTER_HANDLE pfHandle);
168 
169 PFAPIENTRY
170 PfAddGlobalFilterToInterface(
171     INTERFACE_HANDLE pInterface,
172     GLOBAL_FILTER gfFilter);
173 
174 PFAPIENTRY
175 PfBindInterfaceToIPAddress(
176     INTERFACE_HANDLE pInterface,
177     PFADDRESSTYPE pfatType,
178     PBYTE IPAddress);
179 
180 PFAPIENTRY
181 PfBindInterfaceToIndex(
182     INTERFACE_HANDLE pInterface,
183     DWORD dwIndex,
184     PFADDRESSTYPE pfatLinkType,
185     PBYTE LinkIPAddress);
186 
187 PFAPIENTRY
188 PfCreateInterface(
189     DWORD dwName,
190     PFFORWARD_ACTION inAction,
191     PFFORWARD_ACTION outAction,
192     BOOL bUseLog,
193     BOOL bMustBeUnique,
194     INTERFACE_HANDLE* ppInterface);
195 
196 PFAPIENTRY
197 PfDeleteInterface(
198     INTERFACE_HANDLE pInterface);
199 
200 PFAPIENTRY
201 PfDeleteLog(
202     VOID);
203 
204 PFAPIENTRY
205 PfGetInterfaceStatistics(
206     INTERFACE_HANDLE pInterface,
207     PPF_INTERFACE_STATS ppfStats,
208     PDWORD pdwBufferSize,
209     BOOL fResetCounters);
210 
211 PFAPIENTRY
212 PfMakeLog(
213     HANDLE hEvent);
214 
215 PFAPIENTRY
216 PfRebindFilters(
217     INTERFACE_HANDLE pInterface,
218     PPF_LATEBIND_INFO pLateBindInfo);
219 
220 PFAPIENTRY
221 PfRemoveFilterHandles(
222     INTERFACE_HANDLE pInterface,
223     DWORD cFilters,
224     PFILTER_HANDLE pvHandles);
225 
226 PFAPIENTRY
227 PfRemoveFiltersFromInterface(
228     INTERFACE_HANDLE ih,
229     DWORD cInFilters,
230     PPF_FILTER_DESCRIPTOR pfiltIn,
231     DWORD cOutFilters,
232     PPF_FILTER_DESCRIPTOR pfiltOut);
233 
234 PFAPIENTRY
235 PfRemoveGlobalFilterFromInterface(
236     INTERFACE_HANDLE pInterface,
237     GLOBAL_FILTER gfFilter);
238 
239 PFAPIENTRY
240 PfSetLogBuffer(
241     PBYTE pbBuffer,
242     DWORD dwSize,
243     DWORD dwThreshold,
244     DWORD dwEntries,
245     PDWORD pdwLoggedEntries,
246     PDWORD pdwLostEntries,
247     PDWORD pdwSizeUsed);
248 
249 PFAPIENTRY
250 PfTestPacket(
251     INTERFACE_HANDLE pInInterface  OPTIONAL,
252     INTERFACE_HANDLE pOutInterface OPTIONAL,
253     DWORD cBytes,
254     PBYTE pbPacket,
255     PPFFORWARD_ACTION ppAction);
256 
257 PFAPIENTRY
258 PfUnBindInterface(
259     INTERFACE_HANDLE pInterface);
260 
261 #endif // _FLTDEFS_H
262