ndisapi_rs/driver/constants.rs
1//! # Submodule: Basic NDISAPI Constants and flags
2//!
3//! This submodule contains various constants and bitflag structures for the NDISAPI Rust library.
4//!
5//! The NDISAPI library provides a Rust interface for interacting with the Windows Packet Filter
6//! driver. This module contains various constants and bitflag structures used to configure the
7//! packet filtering mechanism, specify filtering options for different protocols, and define
8//! the conditions for filtering at specific layers.
9
10// Import required external crates and types
11use bitflags::bitflags;
12
13/// ADAPTER_NAME_SIZE is the maximum length for the adapter name.
14pub const ADAPTER_NAME_SIZE: usize = 256;
15
16/// ADAPTER_LIST_SIZE is the maximum number of adapters in the adapter list.
17pub const ADAPTER_LIST_SIZE: usize = 32;
18
19/// ETHER_ADDR_LENGTH is the length of an Ethernet address in bytes.
20pub const ETHER_ADDR_LENGTH: usize = 6;
21
22/// MAX_ETHER_FRAME is the maximum size of an Ethernet frame in bytes. If the driver was built with
23/// the JUMBO_FRAME_SUPPORTED option, this value would be 9014 bytes instead.
24pub const MAX_ETHER_FRAME: usize = 1514;
25
26/// RAS_LINK_BUFFER_LENGTH is the length of the RAS link buffer in bytes.
27pub const RAS_LINK_BUFFER_LENGTH: usize = 2048;
28
29/// RAS_LINKS_MAX is the maximum number of RAS links.
30pub const RAS_LINKS_MAX: usize = 256;
31
32/// Constant representing the IPv4 subnet type.
33pub const IP_SUBNET_V4_TYPE: u32 = 1;
34/// Constant representing the IPv4 address range type.
35pub const IP_RANGE_V4_TYPE: u32 = 2;
36
37/// Constant representing the IPv6 subnet type.
38pub const IP_SUBNET_V6_TYPE: u32 = 1;
39/// Constant representing the IPv6 address range type.
40pub const IP_RANGE_V6_TYPE: u32 = 2;
41
42/// ETH_802_3 is a constant representing the 802.3 Ethernet standard.
43pub const ETH_802_3: u32 = 1;
44
45/// Constant representing the IPv4 network protocols.
46pub const IPV4: u32 = 1;
47/// Constant representing the IPv6 network protocols.
48pub const IPV6: u32 = 2;
49
50/// Constant representing the TCP or UDP protocols.
51pub const TCPUDP: u32 = 1;
52/// Constant representing the ICMP protocol.
53pub const ICMP: u32 = 2;
54
55/// Allows a packet to pass through the filter without any modification.
56pub const FILTER_PACKET_PASS: u32 = 1;
57/// Drops the packet and prevents it from reaching the destination.
58pub const FILTER_PACKET_DROP: u32 = 2;
59/// Redirects the packet for processing in user-mode.
60pub const FILTER_PACKET_REDIRECT: u32 = 3;
61/// Allows the packet to pass through the filter and redirects a copy of it for processing by user-mode application.
62pub const FILTER_PACKET_PASS_RDR: u32 = 4;
63/// Drops the packet and and redirects a copy of it for processing by user-mode application.
64pub const FILTER_PACKET_DROP_RDR: u32 = 5;
65
66// Define bitflag structures for filter flags, direction flags, and various protocol-specific filter flags
67bitflags! {
68 /// FilterFlags represent various flags used for packet filtering.
69 ///
70 /// These flags are used to configure the behavior of the packet filtering mechanism in different scenarios.
71 #[derive(Default, Clone, Copy, Debug, PartialEq)]
72 pub struct FilterFlags: u32 {
73 /// MSTCP_FLAG_SENT_TUNNEL: Queue all packets sent from TCP/IP to network interface. Original packet is dropped.
74 const MSTCP_FLAG_SENT_TUNNEL = 1;
75
76 /// MSTCP_FLAG_RECV_TUNNEL: Queue all packets indicated by network interface to TCP/IP. Original packet is dropped.
77 const MSTCP_FLAG_RECV_TUNNEL = 2;
78
79 /// MSTCP_FLAG_SENT_LISTEN: Queue all packets sent from TCP/IP to network interface. Original packet goes ahead.
80 const MSTCP_FLAG_SENT_LISTEN = 4;
81
82 /// MSTCP_FLAG_RECV_LISTEN: Queue all packets indicated by network interface to TCP/IP. Original packet goes ahead.
83 const MSTCP_FLAG_RECV_LISTEN = 8;
84
85 /// MSTCP_FLAG_FILTER_DIRECT: In promiscuous mode, the TCP/IP stack receives all packets in the Ethernet segment
86 /// and replies with various ICMP packets. To prevent this, set this flag. All packets with destination MAC different
87 /// from FF-FF-FF-FF-FF-FF and network interface current MAC will never reach TCP/IP.
88 const MSTCP_FLAG_FILTER_DIRECT = 16;
89
90 /// MSTCP_FLAG_LOOPBACK_FILTER: If not set, loopback packets are silently passed over. Otherwise, these packets are
91 /// passed for further processing (queued for redirecting to the application if not dropped by the MSTCP_FLAG_LOOPBACK_BLOCK below).
92 const MSTCP_FLAG_LOOPBACK_FILTER = 32;
93
94 /// MSTCP_FLAG_LOOPBACK_BLOCK: If set, loopback packets (with exception to broadcast/multicast) are silently dropped.
95 const MSTCP_FLAG_LOOPBACK_BLOCK = 64;
96
97 /// MSTCP_FLAG_SENT_RECEIVE_TUNNEL: Combination of MSTCP_FLAG_SENT_TUNNEL and MSTCP_FLAG_RECV_TUNNEL.
98 const MSTCP_FLAG_SENT_RECEIVE_TUNNEL = Self::MSTCP_FLAG_SENT_TUNNEL.bits() | Self::MSTCP_FLAG_RECV_TUNNEL.bits();
99
100 /// MSTCP_FLAG_SENT_RECEIVE_LISTEN: Combination of MSTCP_FLAG_SENT_LISTEN and MSTCP_FLAG_RECV_LISTEN.
101 const MSTCP_FLAG_SENT_RECEIVE_LISTEN = Self::MSTCP_FLAG_SENT_LISTEN.bits() | Self::MSTCP_FLAG_RECV_LISTEN.bits();
102 }
103}
104
105bitflags! {
106 /// DirectionFlags represent various direction flags for packet processing.
107 ///
108 /// These flags are used to specify the direction of packets that the filter should act upon and
109 /// to specify the packet direction in IntermediateBuffer.
110 #[derive(Default, Clone, Copy, Debug, PartialEq)]
111 pub struct DirectionFlags: u32 {
112 /// PACKET_FLAG_ON_SEND: Indicates an outgoing packet. In the context of filters, the filter should act on packets being sent from the system.
113 const PACKET_FLAG_ON_SEND = 1;
114
115 /// PACKET_FLAG_ON_RECEIVE: Indicates an incoming packet. In the context of filters, the filter should act on packets being received by the system.
116 const PACKET_FLAG_ON_RECEIVE = 2;
117
118 /// PACKET_FLAG_ON_SEND_RECEIVE: Filter should act on both sent and received packets.
119 const PACKET_FLAG_ON_SEND_RECEIVE = Self::PACKET_FLAG_ON_SEND.bits() | Self::PACKET_FLAG_ON_RECEIVE.bits();
120 }
121}
122
123bitflags! {
124 /// Eth802_3FilterFlags represent various filtering options for Ethernet 802.3 frames.
125 ///
126 /// These flags are used to specify which fields of an Ethernet 802.3 frame the filter should
127 /// consider when determining whether to process the packet.
128 #[derive(Default, Clone, Copy, Debug, PartialEq)]
129 pub struct Eth802_3FilterFlags: u32 {
130 /// ETH_802_3_SRC_ADDRESS: Filter based on the source MAC address of the Ethernet 802.3 frame.
131 const ETH_802_3_SRC_ADDRESS = 1;
132
133 /// ETH_802_3_DEST_ADDRESS: Filter based on the destination MAC address of the Ethernet 802.3 frame.
134 const ETH_802_3_DEST_ADDRESS = 2;
135
136 /// ETH_802_3_PROTOCOL: Filter based on the protocol field (EtherType) of the Ethernet 802.3 frame.
137 const ETH_802_3_PROTOCOL = 4;
138 }
139}
140
141bitflags! {
142 /// IpV4FilterFlags represent various filtering options for IPv4 packets.
143 ///
144 /// These flags are used to specify which fields of an IPv4 packet the filter should
145 /// consider when determining whether to process the packet.
146 #[derive(Default, Clone, Copy, Debug, PartialEq)]
147 pub struct IpV4FilterFlags: u32 {
148 /// IP_V4_FILTER_SRC_ADDRESS: Filter based on the source IP address of the IPv4 packet.
149 const IP_V4_FILTER_SRC_ADDRESS = 1;
150
151 /// IP_V4_FILTER_DEST_ADDRESS: Filter based on the destination IP address of the IPv4 packet.
152 const IP_V4_FILTER_DEST_ADDRESS = 2;
153
154 /// IP_V4_FILTER_PROTOCOL: Filter based on the protocol field of the IPv4 packet (e.g., TCP, UDP, ICMP).
155 const IP_V4_FILTER_PROTOCOL = 4;
156 }
157}
158
159bitflags! {
160 /// IpV6FilterFlags represent various filtering options for IPv6 packets.
161 ///
162 /// These flags are used to specify which fields of an IPv6 packet the filter should
163 /// consider when determining whether to process the packet.
164 #[derive(Default, Clone, Copy, Debug, PartialEq)]
165 pub struct IpV6FilterFlags: u32 {
166 /// IP_V6_FILTER_SRC_ADDRESS: Filter based on the source IP address of the IPv6 packet.
167 const IP_V6_FILTER_SRC_ADDRESS = 1;
168
169 /// IP_V6_FILTER_DEST_ADDRESS: Filter based on the destination IP address of the IPv6 packet.
170 const IP_V6_FILTER_DEST_ADDRESS = 2;
171
172 /// IP_V6_FILTER_PROTOCOL: Filter based on the protocol field of the IPv6 packet (e.g., TCP, UDP, ICMPv6).
173 const IP_V6_FILTER_PROTOCOL = 4;
174 }
175}
176
177bitflags! {
178 /// TcpUdpFilterFlags represent various filtering options for TCP and UDP packets.
179 ///
180 /// These flags are used to specify which fields of a TCP or UDP packet the filter should
181 /// consider when determining whether to process the packet.
182 #[derive(Default, Clone, Copy, Debug, PartialEq)]
183 pub struct TcpUdpFilterFlags: u32 {
184 /// TCPUDP_SRC_PORT: Filter based on the source port of the TCP or UDP packet.
185 const TCPUDP_SRC_PORT = 1;
186
187 /// TCPUDP_DEST_PORT: Filter based on the destination port of the TCP or UDP packet.
188 const TCPUDP_DEST_PORT = 2;
189
190 /// TCPUDP_TCP_FLAGS: Filter based on the TCP flags of a TCP packet. This flag is ignored for UDP packets.
191 const TCPUDP_TCP_FLAGS = 4;
192 }
193}
194
195bitflags! {
196 /// IcmpFilterFlags represent various filtering options for ICMP packets.
197 ///
198 /// These flags are used to specify which fields of an ICMP packet the filter should
199 /// consider when determining whether to process the packet.
200 #[derive(Default, Clone, Copy, Debug, PartialEq)]
201 pub struct IcmpFilterFlags: u32 {
202 /// ICMP_TYPE: Filter based on the ICMP type of the ICMP packet.
203 const ICMP_TYPE = 1;
204
205 /// ICMP_CODE: Filter based on the ICMP code of the ICMP packet.
206 const ICMP_CODE = 2;
207 }
208}
209
210bitflags! {
211 /// FilterLayerFlags represent the validation flags for various filter layers.
212 ///
213 /// These flags are used to specify which layers of a packet the filter should consider
214 /// when determining whether to process the packet. They are typically used in conjunction
215 /// with other filter flags to define the conditions for filtering at specific layers.
216 #[derive(Default, Clone, Copy, Debug, PartialEq)]
217 pub struct FilterLayerFlags: u32 {
218 /// DATA_LINK_LAYER_VALID: Indicates that the Data Link Layer filter fields are valid and should be considered in the filtering process.
219 const DATA_LINK_LAYER_VALID = 1;
220
221 /// NETWORK_LAYER_VALID: Indicates that the Network Layer filter fields are valid and should be considered in the filtering process.
222 const NETWORK_LAYER_VALID = 2;
223
224 /// TRANSPORT_LAYER_VALID: Indicates that the Transport Layer filter fields are valid and should be considered in the filtering process.
225 const TRANSPORT_LAYER_VALID = 4;
226 }
227}