NetSim Source Code Help
Loading...
Searching...
No Matches
windivert_device.h
Go to the documentation of this file.
1/*
2 * windivert_device.h
3 * (C) 2014, all rights reserved,
4 *
5 * This program is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU Lesser General Public License as published by
7 * the Free Software Foundation, either version 3 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU Lesser General Public License for more details.
14 *
15 * You should have received a copy of the GNU Lesser General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17 */
18
19#ifndef __WINDIVERT_DEVICE_H
20#define __WINDIVERT_DEVICE_H
21
22/*
23 * NOTE: This is the low-level interface to the divert device driver.
24 * This interface should not be used directly, instead use the high-level
25 * interface provided by the divert API.
26 */
27
28#define WINDIVERT_KERNEL
29#include "windivert.h"
30
31#define WINDIVERT_VERSION 1
32#define WINDIVERT_VERSION_MINOR 1
33
34#define WINDIVERT_STR2(s) #s
35#define WINDIVERT_STR(s) WINDIVERT_STR2(s)
36#define WINDIVERT_LSTR2(s) L ## #s
37#define WINDIVERT_LSTR(s) WINDIVERT_LSTR2(s)
38
39#define WINDIVERT_VERSION_LSTR \
40 WINDIVERT_LSTR(WINDIVERT_VERSION) L"." \
41 WINDIVERT_LSTR(WINDIVERT_VERSION_MINOR)
42
43#define WINDIVERT_DEVICE_NAME \
44 L"WinDivert" WINDIVERT_VERSION_LSTR
45
46#define WINDIVERT_IOCTL_VERSION 3
47#define WINDIVERT_IOCTL_MAGIC 0xE8D3
48
49#define WINDIVERT_FILTER_FIELD_ZERO 0
50#define WINDIVERT_FILTER_FIELD_INBOUND 1
51#define WINDIVERT_FILTER_FIELD_OUTBOUND 2
52#define WINDIVERT_FILTER_FIELD_IFIDX 3
53#define WINDIVERT_FILTER_FIELD_SUBIFIDX 4
54#define WINDIVERT_FILTER_FIELD_IP 5
55#define WINDIVERT_FILTER_FIELD_IPV6 6
56#define WINDIVERT_FILTER_FIELD_ICMP 7
57#define WINDIVERT_FILTER_FIELD_TCP 8
58#define WINDIVERT_FILTER_FIELD_UDP 9
59#define WINDIVERT_FILTER_FIELD_ICMPV6 10
60#define WINDIVERT_FILTER_FIELD_IP_HDRLENGTH 11
61#define WINDIVERT_FILTER_FIELD_IP_TOS 12
62#define WINDIVERT_FILTER_FIELD_IP_LENGTH 13
63#define WINDIVERT_FILTER_FIELD_IP_ID 14
64#define WINDIVERT_FILTER_FIELD_IP_DF 15
65#define WINDIVERT_FILTER_FIELD_IP_MF 16
66#define WINDIVERT_FILTER_FIELD_IP_FRAGOFF 17
67#define WINDIVERT_FILTER_FIELD_IP_TTL 18
68#define WINDIVERT_FILTER_FIELD_IP_PROTOCOL 19
69#define WINDIVERT_FILTER_FIELD_IP_CHECKSUM 20
70#define WINDIVERT_FILTER_FIELD_IP_SRCADDR 21
71#define WINDIVERT_FILTER_FIELD_IP_DSTADDR 22
72#define WINDIVERT_FILTER_FIELD_IPV6_TRAFFICCLASS 23
73#define WINDIVERT_FILTER_FIELD_IPV6_FLOWLABEL 24
74#define WINDIVERT_FILTER_FIELD_IPV6_LENGTH 25
75#define WINDIVERT_FILTER_FIELD_IPV6_NEXTHDR 26
76#define WINDIVERT_FILTER_FIELD_IPV6_HOPLIMIT 27
77#define WINDIVERT_FILTER_FIELD_IPV6_SRCADDR 28
78#define WINDIVERT_FILTER_FIELD_IPV6_DSTADDR 29
79#define WINDIVERT_FILTER_FIELD_ICMP_TYPE 30
80#define WINDIVERT_FILTER_FIELD_ICMP_CODE 31
81#define WINDIVERT_FILTER_FIELD_ICMP_CHECKSUM 32
82#define WINDIVERT_FILTER_FIELD_ICMP_BODY 33
83#define WINDIVERT_FILTER_FIELD_ICMPV6_TYPE 34
84#define WINDIVERT_FILTER_FIELD_ICMPV6_CODE 35
85#define WINDIVERT_FILTER_FIELD_ICMPV6_CHECKSUM 36
86#define WINDIVERT_FILTER_FIELD_ICMPV6_BODY 37
87#define WINDIVERT_FILTER_FIELD_TCP_SRCPORT 38
88#define WINDIVERT_FILTER_FIELD_TCP_DSTPORT 39
89#define WINDIVERT_FILTER_FIELD_TCP_SEQNUM 40
90#define WINDIVERT_FILTER_FIELD_TCP_ACKNUM 41
91#define WINDIVERT_FILTER_FIELD_TCP_HDRLENGTH 42
92#define WINDIVERT_FILTER_FIELD_TCP_URG 43
93#define WINDIVERT_FILTER_FIELD_TCP_ACK 44
94#define WINDIVERT_FILTER_FIELD_TCP_PSH 45
95#define WINDIVERT_FILTER_FIELD_TCP_RST 46
96#define WINDIVERT_FILTER_FIELD_TCP_SYN 47
97#define WINDIVERT_FILTER_FIELD_TCP_FIN 48
98#define WINDIVERT_FILTER_FIELD_TCP_WINDOW 49
99#define WINDIVERT_FILTER_FIELD_TCP_CHECKSUM 50
100#define WINDIVERT_FILTER_FIELD_TCP_URGPTR 51
101#define WINDIVERT_FILTER_FIELD_TCP_PAYLOADLENGTH 52
102#define WINDIVERT_FILTER_FIELD_UDP_SRCPORT 53
103#define WINDIVERT_FILTER_FIELD_UDP_DSTPORT 54
104#define WINDIVERT_FILTER_FIELD_UDP_LENGTH 55
105#define WINDIVERT_FILTER_FIELD_UDP_CHECKSUM 56
106#define WINDIVERT_FILTER_FIELD_UDP_PAYLOADLENGTH 57
107#define WINDIVERT_FILTER_FIELD_MAX \
108 WINDIVERT_FILTER_FIELD_UDP_PAYLOADLENGTH
109
110#define WINDIVERT_FILTER_TEST_EQ 0
111#define WINDIVERT_FILTER_TEST_NEQ 1
112#define WINDIVERT_FILTER_TEST_LT 2
113#define WINDIVERT_FILTER_TEST_LEQ 3
114#define WINDIVERT_FILTER_TEST_GT 4
115#define WINDIVERT_FILTER_TEST_GEQ 5
116#define WINDIVERT_FILTER_TEST_MAX WINDIVERT_FILTER_TEST_GEQ
117
118#define WINDIVERT_FILTER_MAXLEN 128
119
120#define WINDIVERT_FILTER_RESULT_ACCEPT (WINDIVERT_FILTER_MAXLEN+1)
121#define WINDIVERT_FILTER_RESULT_REJECT (WINDIVERT_FILTER_MAXLEN+2)
122
123/*
124 * WinDivert layers.
125 */
126#define WINDIVERT_LAYER_DEFAULT WINDIVERT_LAYER_NETWORK
127#define WINDIVERT_LAYER_MAX \
128 WINDIVERT_LAYER_NETWORK_FORWARD
129
130/*
131 * WinDivert flags.
132 */
133#define WINDIVERT_FLAGS_ALL \
134 (WINDIVERT_FLAG_SNIFF | WINDIVERT_FLAG_DROP | \
135 WINDIVERT_FLAG_NO_CHECKSUM)
136#define WINDIVERT_FLAGS_EXCLUDE(flags, flag1, flag2) \
137 (((flags) & ((flag1) | (flag2))) != ((flag1) | (flag2)))
138#define WINDIVERT_FLAGS_VALID(flags) \
139 ((((flags) & ~WINDIVERT_FLAGS_ALL) == 0) && \
140 WINDIVERT_FLAGS_EXCLUDE(flags, WINDIVERT_FLAG_SNIFF, \
141 WINDIVERT_FLAG_DROP))
142/*
143 * WinDivert priorities.
144 */
145#define WINDIVERT_PRIORITY(priority16) \
146 ((UINT32)((INT32)(priority16) + 0x7FFF + 1))
147#define WINDIVERT_PRIORITY_DEFAULT WINDIVERT_PRIORITY(0)
148#define WINDIVERT_PRIORITY_MAX WINDIVERT_PRIORITY(1000)
149#define WINDIVERT_PRIORITY_MIN WINDIVERT_PRIORITY(-1000)
150
151/*
152 * WinDivert parameters.
153 */
154#define WINDIVERT_PARAM_QUEUE_LEN_DEFAULT 1024
155#define WINDIVERT_PARAM_QUEUE_LEN_MIN 1
156#define WINDIVERT_PARAM_QUEUE_LEN_MAX 8192
157#define WINDIVERT_PARAM_QUEUE_TIME_DEFAULT 512
158#define WINDIVERT_PARAM_QUEUE_TIME_MIN 128
159#define WINDIVERT_PARAM_QUEUE_TIME_MAX 2048
160
161/*
162 * WinDivert message definitions.
163 */
164#pragma pack(push, 1)
166{
167 UINT16 magic; // WINDIVERT_IOCTL_MAGIC
168 UINT8 version; // WINDIVERT_IOCTL_VERSION
169 UINT8 arg8; // 8-bit argument
170 UINT64 arg; // 64-bit argument
171};
173
174/*
175 * WinDivert IOCTL structures.
176 */
178{
179 UINT8 field; // WINDIVERT_FILTER_FIELD_IP_*
180 UINT8 test; // WINDIVERT_FILTER_TEST_*
181 UINT16 success; // Success continuation.
182 UINT16 failure; // Fail continuation.
183 UINT32 arg[4]; // Argument.
184};
186#pragma pack(pop)
187
188/*
189 * IOCTL codes.
190 */
191#define IOCTL_WINDIVERT_RECV \
192 CTL_CODE(FILE_DEVICE_NETWORK, 0x908, METHOD_OUT_DIRECT, FILE_ANY_ACCESS)
193#define IOCTL_WINDIVERT_SEND \
194 CTL_CODE(FILE_DEVICE_NETWORK, 0x909, METHOD_IN_DIRECT, FILE_ANY_ACCESS)
195#define IOCTL_WINDIVERT_START_FILTER \
196 CTL_CODE(FILE_DEVICE_NETWORK, 0x90A, METHOD_IN_DIRECT, FILE_ANY_ACCESS)
197#define IOCTL_WINDIVERT_SET_LAYER \
198 CTL_CODE(FILE_DEVICE_NETWORK, 0x90B, METHOD_IN_DIRECT, FILE_ANY_ACCESS)
199#define IOCTL_WINDIVERT_SET_PRIORITY \
200 CTL_CODE(FILE_DEVICE_NETWORK, 0x90C, METHOD_IN_DIRECT, FILE_ANY_ACCESS)
201#define IOCTL_WINDIVERT_SET_FLAGS \
202 CTL_CODE(FILE_DEVICE_NETWORK, 0x90D, METHOD_IN_DIRECT, FILE_ANY_ACCESS)
203#define IOCTL_WINDIVERT_SET_PARAM \
204 CTL_CODE(FILE_DEVICE_NETWORK, 0x90E, METHOD_IN_DIRECT, FILE_ANY_ACCESS)
205#define IOCTL_WINDIVERT_GET_PARAM \
206 CTL_CODE(FILE_DEVICE_NETWORK, 0x90F, METHOD_OUT_DIRECT, FILE_ANY_ACCESS)
207
208#endif /* __WINDIVERT_DEVICE_H */
#define UINT64
Definition: Linux.h:37
#define UINT32
Definition: Linux.h:35
#define UINT16
Definition: Linux.h:33
#define UINT8
Definition: Linux.h:31
struct windivert_ioctl_s * windivert_ioctl_t
struct windivert_ioctl_filter_s * windivert_ioctl_filter_t