mirror of
https://github.com/amnezia-vpn/win-split-tunnel.git
synced 2026-05-17 08:16:00 +03:00
Move classification bit fiddling to enable reuse
This commit is contained in:
@@ -5,6 +5,7 @@
|
||||
#include "pending.h"
|
||||
#include "callouts.h"
|
||||
#include "logging.h"
|
||||
#include "classify.h"
|
||||
#include "../util.h"
|
||||
|
||||
#include "../trace.h"
|
||||
@@ -22,49 +23,6 @@ namespace firewall
|
||||
namespace
|
||||
{
|
||||
|
||||
void
|
||||
ClassificationReset
|
||||
(
|
||||
FWPS_CLASSIFY_OUT0 *ClassifyOut
|
||||
)
|
||||
{
|
||||
//
|
||||
// According to documentation, FwpsAcquireWritableLayerDataPointer0() will update the
|
||||
// `actionType` and `rights` fields with poorly chosen values:
|
||||
//
|
||||
// ```
|
||||
// classifyOut->actionType = FWP_ACTION_BLOCK
|
||||
// classifyOut->rights &= ~FWPS_RIGHT_ACTION_WRITE
|
||||
// ```
|
||||
//
|
||||
// However, in practice it seems to not make any changes to those fields.
|
||||
// But if it did we'd want to ensure the fields have sane values.
|
||||
//
|
||||
|
||||
ClassifyOut->actionType = FWP_ACTION_CONTINUE;
|
||||
ClassifyOut->rights |= FWPS_RIGHT_ACTION_WRITE;
|
||||
}
|
||||
|
||||
void
|
||||
ClassificationApplyHardPermit
|
||||
(
|
||||
FWPS_CLASSIFY_OUT0 *ClassifyOut
|
||||
)
|
||||
{
|
||||
ClassifyOut->actionType = FWP_ACTION_PERMIT;
|
||||
ClassifyOut->rights &= ~FWPS_RIGHT_ACTION_WRITE;
|
||||
}
|
||||
|
||||
void
|
||||
ClassificationApplyHardBlock
|
||||
(
|
||||
FWPS_CLASSIFY_OUT0 *ClassifyOut
|
||||
)
|
||||
{
|
||||
ClassifyOut->actionType = FWP_ACTION_BLOCK;
|
||||
ClassifyOut->rights &= ~FWPS_RIGHT_ACTION_WRITE;
|
||||
}
|
||||
|
||||
//
|
||||
// NotifyFilterAttach()
|
||||
//
|
||||
|
||||
49
src/firewall/classify.cpp
Normal file
49
src/firewall/classify.cpp
Normal file
@@ -0,0 +1,49 @@
|
||||
#include "classify.h"
|
||||
|
||||
namespace firewall
|
||||
{
|
||||
|
||||
void
|
||||
ClassificationReset
|
||||
(
|
||||
FWPS_CLASSIFY_OUT0 *ClassifyOut
|
||||
)
|
||||
{
|
||||
//
|
||||
// According to documentation, FwpsAcquireWritableLayerDataPointer0() will update the
|
||||
// `actionType` and `rights` fields with poorly chosen values:
|
||||
//
|
||||
// ```
|
||||
// classifyOut->actionType = FWP_ACTION_BLOCK
|
||||
// classifyOut->rights &= ~FWPS_RIGHT_ACTION_WRITE
|
||||
// ```
|
||||
//
|
||||
// However, in practice it seems to not make any changes to those fields.
|
||||
// But if it did we'd want to ensure the fields have sane values.
|
||||
//
|
||||
|
||||
ClassifyOut->actionType = FWP_ACTION_CONTINUE;
|
||||
ClassifyOut->rights |= FWPS_RIGHT_ACTION_WRITE;
|
||||
}
|
||||
|
||||
void
|
||||
ClassificationApplyHardPermit
|
||||
(
|
||||
FWPS_CLASSIFY_OUT0 *ClassifyOut
|
||||
)
|
||||
{
|
||||
ClassifyOut->actionType = FWP_ACTION_PERMIT;
|
||||
ClassifyOut->rights &= ~FWPS_RIGHT_ACTION_WRITE;
|
||||
}
|
||||
|
||||
void
|
||||
ClassificationApplyHardBlock
|
||||
(
|
||||
FWPS_CLASSIFY_OUT0 *ClassifyOut
|
||||
)
|
||||
{
|
||||
ClassifyOut->actionType = FWP_ACTION_BLOCK;
|
||||
ClassifyOut->rights &= ~FWPS_RIGHT_ACTION_WRITE;
|
||||
}
|
||||
|
||||
} // namespace firewall
|
||||
27
src/firewall/classify.h
Normal file
27
src/firewall/classify.h
Normal file
@@ -0,0 +1,27 @@
|
||||
#pragma once
|
||||
|
||||
#include "wfp.h"
|
||||
|
||||
namespace firewall
|
||||
{
|
||||
|
||||
void
|
||||
ClassificationReset
|
||||
(
|
||||
FWPS_CLASSIFY_OUT0 *ClassifyOut
|
||||
);
|
||||
|
||||
void
|
||||
ClassificationApplyHardPermit
|
||||
(
|
||||
FWPS_CLASSIFY_OUT0 *ClassifyOut
|
||||
)
|
||||
;
|
||||
|
||||
void
|
||||
ClassificationApplyHardBlock
|
||||
(
|
||||
FWPS_CLASSIFY_OUT0 *ClassifyOut
|
||||
);
|
||||
|
||||
} // namespace firewall
|
||||
@@ -1,4 +1,5 @@
|
||||
#include "pending.h"
|
||||
#include "classify.h"
|
||||
#include "../util.h"
|
||||
|
||||
#include "../trace.h"
|
||||
@@ -166,10 +167,7 @@ FailRequest
|
||||
}
|
||||
};
|
||||
|
||||
// TODO: replace with call to reusable function.
|
||||
ClassifyOut->actionType = FWP_ACTION_PERMIT;
|
||||
ClassifyOut->rights &= ~FWPS_RIGHT_ACTION_WRITE;
|
||||
|
||||
ClassificationApplyHardPermit(ClassifyOut);
|
||||
FwpsApplyModifiedLayerData0(ClassifyHandle, requestData, 0);
|
||||
|
||||
return STATUS_SUCCESS;
|
||||
|
||||
@@ -205,6 +205,7 @@
|
||||
<ClCompile Include="eventing\eventing.cpp" />
|
||||
<ClCompile Include="firewall\appfilters.cpp" />
|
||||
<ClCompile Include="firewall\callouts.cpp" />
|
||||
<ClCompile Include="firewall\classify.cpp" />
|
||||
<ClCompile Include="firewall\filters.cpp" />
|
||||
<ClCompile Include="firewall\firewall.cpp" />
|
||||
<ClCompile Include="firewall\logging.cpp" />
|
||||
@@ -237,6 +238,7 @@
|
||||
<ClInclude Include="eventing\eventing.h" />
|
||||
<ClInclude Include="firewall\appfilters.h" />
|
||||
<ClInclude Include="firewall\callouts.h" />
|
||||
<ClInclude Include="firewall\classify.h" />
|
||||
<ClInclude Include="firewall\constants.h" />
|
||||
<ClInclude Include="firewall\context.h" />
|
||||
<ClInclude Include="firewall\filters.h" />
|
||||
|
||||
@@ -48,6 +48,9 @@
|
||||
<ClCompile Include="firewall\pending.cpp">
|
||||
<Filter>firewall</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="firewall\classify.cpp">
|
||||
<Filter>firewall</Filter>
|
||||
</ClCompile>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Inf Include="mullvad-split-tunnel.inf" />
|
||||
@@ -153,6 +156,9 @@
|
||||
<ClInclude Include="firewall\pending.h">
|
||||
<Filter>firewall</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="firewall\classify.h">
|
||||
<Filter>firewall</Filter>
|
||||
</ClInclude>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Filter Include="firewall">
|
||||
|
||||
Reference in New Issue
Block a user