windows-filter-windivert/include/packet_filter.h

60 lines
1.4 KiB
C++

#ifndef PACKET_FILTER_H
#define PACKET_FILTER_H
#include "common.h"
#include "rule_engine.h"
#include "logger.h"
#ifdef _WIN32
#include <windows.h>
// Forward declare WINDIVERT_ADDRESS to avoid including windivert.h in header
struct WINDIVERT_ADDRESS_;
typedef struct WINDIVERT_ADDRESS_ WINDIVERT_ADDRESS;
#else
// Placeholder types for non-Windows platforms (for development)
typedef void* HANDLE;
typedef struct {} WINDIVERT_ADDRESS;
#define INVALID_HANDLE_VALUE nullptr
#endif
#include <atomic>
#include <thread>
#include <vector>
class PacketFilter {
public:
PacketFilter(RuleEngine* rule_engine, Logger* logger);
~PacketFilter();
// Initialize WinDivert
bool Initialize();
// Start packet filtering (blocking call)
void Start();
// Stop packet filtering
void Stop();
// Get statistics
const PacketStats& GetStats() const;
private:
HANDLE windivert_handle_;
RuleEngine* rule_engine_;
Logger* logger_;
PacketStats stats_;
std::atomic<bool> running_;
// Packet processing
void ProcessPackets();
void HandlePacket(uint8_t* packet,
unsigned int packet_len,
WINDIVERT_ADDRESS* addr);
// Extract source IP for logging
std::string ExtractSourceIP(const uint8_t* packet,
const WINDIVERT_ADDRESS* addr);
};
#endif // PACKET_FILTER_H