Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] Use shared locks #13

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 10 additions & 10 deletions sys/pm_callouts.c
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,10 @@
* Global (static) data structures
******************************************************************/
static verdict_cache_t* verdictCacheV4;
static KSPIN_LOCK verdictCacheV4Lock;
static EX_SPIN_LOCK verdictCacheV4Lock = 0;

static verdict_cache_t* verdictCacheV6;
static KSPIN_LOCK verdictCacheV6Lock;
static EX_SPIN_LOCK verdictCacheV6Lock = 0;

packet_cache_t* packetCache; //Not static anymore, because it is also used in pm_kernel.c
KSPIN_LOCK packetCacheLock;
Expand All @@ -52,13 +52,11 @@ NTSTATUS initCalloutStructure() {
if (rc != 0) {
return STATUS_INTERNAL_ERROR;
}
KeInitializeSpinLock(&verdictCacheV4Lock);

rc = create_verdict_cache(PM_VERDICT_CACHE_SIZE, &verdictCacheV6);
if (rc != 0) {
return STATUS_INTERNAL_ERROR;
}
KeInitializeSpinLock(&verdictCacheV6Lock);

rc = create_packet_cache(PM_PACKET_CACHE_SIZE, &packetCache);
if (rc != 0) {
Expand Down Expand Up @@ -670,15 +668,16 @@ void copy_and_inject(portmaster_packet_info* packetInfo, PNET_BUFFER nb, UINT32
FWP_ACTION_TYPE classifySingle(
portmaster_packet_info* packetInfo,
verdict_cache_t* verdictCache,
KSPIN_LOCK* verdictCacheLock,
PEX_SPIN_LOCK verdictCacheLock,
const FWPS_INCOMING_METADATA_VALUES* inMetaValues,
PNET_BUFFER nb,
UINT32 ipHeaderSize
) {
int offset;
verdict_t verdict;
int rc;
KLOCK_QUEUE_HANDLE lock_handle_vc, lock_handle_pc;
KIRQl irql;
KLOCK_QUEUE_HANDLE lock_handle;
pportmaster_packet_info copiedPacketInfo, redirInfo;
PPM_IPHDR ip_header;
UINT16 srcPort, dstPort;
Expand Down Expand Up @@ -800,8 +799,8 @@ FWP_ACTION_TYPE classifySingle(
// Set default verdict.
verdict = PORTMASTER_VERDICT_GET;

// Lock to check verdict cache.
KeAcquireInStackQueuedSpinLock(verdictCacheLock, &lock_handle_vc);
// Acquire shared lock, as we are just reading the verdict cache.
irql = ExAcquireSpinLockShared(verdictCacheLock);

// First check if the packet is a DNAT response.
if (packetInfo->direction == 1 &&
Expand All @@ -824,7 +823,8 @@ FWP_ACTION_TYPE classifySingle(
redirInfo = packetInfo;
}
}
KeReleaseInStackQueuedSpinLock(&lock_handle_vc);

ExReleaseSpinLockShared(verdictCacheLock, irql);

switch (verdict) {
case PORTMASTER_VERDICT_DROP:
Expand Down Expand Up @@ -995,7 +995,7 @@ FWP_ACTION_TYPE classifySingle(
void classifyMultiple(
portmaster_packet_info* packetInfo,
verdict_cache_t* verdictCache,
KSPIN_LOCK* verdictCacheLock,
PEX_SPIN_LOCK verdictCacheLock,
const FWPS_INCOMING_METADATA_VALUES* inMetaValues,
void* layerData,
FWPS_CLASSIFY_OUT* classifyOut
Expand Down