Driver: fortcout: Simplify fort_callout_install()

This commit is contained in:
Nodir Temirkhodjaev 2023-01-13 18:53:30 +03:00
parent 20482773c2
commit d293fc1ba0
4 changed files with 116 additions and 312 deletions

Binary file not shown.

View File

@ -70,112 +70,13 @@
#define FORT_CALLOUT_FLOW_ASSOC_ERROR ((NTSTATUS)0xC0020001L)
//
// MessageId: FORT_CALLOUT_REGISTER_CONNECT_V4_ERROR
// MessageId: FORT_CALLOUT_REGISTER_ERROR
//
// MessageText:
//
// Register Connect V4: Error.
// Callout Register: Error.
//
#define FORT_CALLOUT_REGISTER_CONNECT_V4_ERROR ((NTSTATUS)0xC0020002L)
//
// MessageId: FORT_CALLOUT_REGISTER_CONNECT_V6_ERROR
//
// MessageText:
//
// Register Connect V6: Error.
//
#define FORT_CALLOUT_REGISTER_CONNECT_V6_ERROR ((NTSTATUS)0xC0020003L)
//
// MessageId: FORT_CALLOUT_REGISTER_ACCEPT_V4_ERROR
//
// MessageText:
//
// Register Accept V4: Error.
//
#define FORT_CALLOUT_REGISTER_ACCEPT_V4_ERROR ((NTSTATUS)0xC0020004L)
//
// MessageId: FORT_CALLOUT_REGISTER_ACCEPT_V6_ERROR
//
// MessageText:
//
// Register Accept V6: Error.
//
#define FORT_CALLOUT_REGISTER_ACCEPT_V6_ERROR ((NTSTATUS)0xC0020005L)
//
// MessageId: FORT_CALLOUT_REGISTER_STREAM_V4_ERROR
//
// MessageText:
//
// Register Stream V4: Error.
//
#define FORT_CALLOUT_REGISTER_STREAM_V4_ERROR ((NTSTATUS)0xC0020006L)
//
// MessageId: FORT_CALLOUT_REGISTER_STREAM_V6_ERROR
//
// MessageText:
//
// Register Stream V6: Error.
//
#define FORT_CALLOUT_REGISTER_STREAM_V6_ERROR ((NTSTATUS)0xC0020007L)
//
// MessageId: FORT_CALLOUT_REGISTER_DATAGRAM_V4_ERROR
//
// MessageText:
//
// Register Datagram V4: Error.
//
#define FORT_CALLOUT_REGISTER_DATAGRAM_V4_ERROR ((NTSTATUS)0xC0020008L)
//
// MessageId: FORT_CALLOUT_REGISTER_DATAGRAM_V6_ERROR
//
// MessageText:
//
// Register Datagram V6: Error.
//
#define FORT_CALLOUT_REGISTER_DATAGRAM_V6_ERROR ((NTSTATUS)0xC0020009L)
//
// MessageId: FORT_CALLOUT_REGISTER_INBOUND_TRANSPORT_V4_ERROR
//
// MessageText:
//
// Register Inbound Transport V4: Error.
//
#define FORT_CALLOUT_REGISTER_INBOUND_TRANSPORT_V4_ERROR ((NTSTATUS)0xC002000AL)
//
// MessageId: FORT_CALLOUT_REGISTER_INBOUND_TRANSPORT_V6_ERROR
//
// MessageText:
//
// Register Inbound Transport V6: Error.
//
#define FORT_CALLOUT_REGISTER_INBOUND_TRANSPORT_V6_ERROR ((NTSTATUS)0xC002000BL)
//
// MessageId: FORT_CALLOUT_REGISTER_OUTBOUND_TRANSPORT_V4_ERROR
//
// MessageText:
//
// Register Outbound Transport V4: Error.
//
#define FORT_CALLOUT_REGISTER_OUTBOUND_TRANSPORT_V4_ERROR ((NTSTATUS)0xC002000CL)
//
// MessageId: FORT_CALLOUT_REGISTER_OUTBOUND_TRANSPORT_V6_ERROR
//
// MessageText:
//
// Register Outbound Transport V6: Error.
//
#define FORT_CALLOUT_REGISTER_OUTBOUND_TRANSPORT_V6_ERROR ((NTSTATUS)0xC002000DL)
#define FORT_CALLOUT_REGISTER_ERROR ((NTSTATUS)0xC0020002L)
//
// MessageId: FORT_CALLOUT_CALLOUT_REAUTH_ERROR

View File

@ -37,64 +37,9 @@ Language=English
Classify v4: Flow assoc. error.
.
MessageId=2 Facility=Callout Severity=Error SymbolicName=FORT_CALLOUT_REGISTER_CONNECT_V4_ERROR
MessageId=2 Facility=Callout Severity=Error SymbolicName=FORT_CALLOUT_REGISTER_ERROR
Language=English
Register Connect V4: Error.
.
MessageId=3 Facility=Callout Severity=Error SymbolicName=FORT_CALLOUT_REGISTER_CONNECT_V6_ERROR
Language=English
Register Connect V6: Error.
.
MessageId=4 Facility=Callout Severity=Error SymbolicName=FORT_CALLOUT_REGISTER_ACCEPT_V4_ERROR
Language=English
Register Accept V4: Error.
.
MessageId=5 Facility=Callout Severity=Error SymbolicName=FORT_CALLOUT_REGISTER_ACCEPT_V6_ERROR
Language=English
Register Accept V6: Error.
.
MessageId=6 Facility=Callout Severity=Error SymbolicName=FORT_CALLOUT_REGISTER_STREAM_V4_ERROR
Language=English
Register Stream V4: Error.
.
MessageId=7 Facility=Callout Severity=Error SymbolicName=FORT_CALLOUT_REGISTER_STREAM_V6_ERROR
Language=English
Register Stream V6: Error.
.
MessageId=8 Facility=Callout Severity=Error SymbolicName=FORT_CALLOUT_REGISTER_DATAGRAM_V4_ERROR
Language=English
Register Datagram V4: Error.
.
MessageId=9 Facility=Callout Severity=Error SymbolicName=FORT_CALLOUT_REGISTER_DATAGRAM_V6_ERROR
Language=English
Register Datagram V6: Error.
.
MessageId=10 Facility=Callout Severity=Error SymbolicName=FORT_CALLOUT_REGISTER_INBOUND_TRANSPORT_V4_ERROR
Language=English
Register Inbound Transport V4: Error.
.
MessageId=11 Facility=Callout Severity=Error SymbolicName=FORT_CALLOUT_REGISTER_INBOUND_TRANSPORT_V6_ERROR
Language=English
Register Inbound Transport V6: Error.
.
MessageId=12 Facility=Callout Severity=Error SymbolicName=FORT_CALLOUT_REGISTER_OUTBOUND_TRANSPORT_V4_ERROR
Language=English
Register Outbound Transport V4: Error.
.
MessageId=13 Facility=Callout Severity=Error SymbolicName=FORT_CALLOUT_REGISTER_OUTBOUND_TRANSPORT_V6_ERROR
Language=English
Register Outbound Transport V6: Error.
Callout Register: Error.
.
MessageId=14 Facility=Callout Severity=Error SymbolicName=FORT_CALLOUT_CALLOUT_REAUTH_ERROR

View File

@ -486,161 +486,119 @@ FORT_API NTSTATUS fort_callout_install(PDEVICE_OBJECT device)
{
PFORT_STAT stat = &fort_device()->stat;
FWPS_CALLOUT0 c;
NTSTATUS status;
RtlZeroMemory(&c, sizeof(FWPS_CALLOUT0));
c.notifyFn = (FWPS_CALLOUT_NOTIFY_FN0) fort_callout_notify;
UINT32 *const calloutIds[] = {
&stat->connect4_id,
&stat->connect6_id,
&stat->accept4_id,
&stat->accept6_id,
&stat->stream4_id,
&stat->stream6_id,
&stat->datagram4_id,
&stat->datagram6_id,
&stat->in_transport4_id,
&stat->in_transport6_id,
&stat->out_transport4_id,
&stat->out_transport6_id,
};
const FWPS_CALLOUT0 callouts[] = {
/* IPv4 connect callout */
c.calloutKey = FORT_GUID_CALLOUT_CONNECT_V4;
c.classifyFn = (FWPS_CALLOUT_CLASSIFY_FN0) fort_callout_connect_v4;
status = FwpsCalloutRegister0(device, &c, &stat->connect4_id);
if (!NT_SUCCESS(status)) {
LOG("Register Connect V4: Error: %x\n", status);
TRACE(FORT_CALLOUT_REGISTER_CONNECT_V4_ERROR, status, 0, 0);
return status;
}
{
.calloutKey = FORT_GUID_CALLOUT_CONNECT_V4,
.classifyFn = (FWPS_CALLOUT_CLASSIFY_FN0) &fort_callout_connect_v4,
.notifyFn = (FWPS_CALLOUT_NOTIFY_FN0) &fort_callout_notify,
},
/* IPv6 connect callout */
c.calloutKey = FORT_GUID_CALLOUT_CONNECT_V6;
c.classifyFn = (FWPS_CALLOUT_CLASSIFY_FN0) fort_callout_connect_v6;
status = FwpsCalloutRegister0(device, &c, &stat->connect6_id);
if (!NT_SUCCESS(status)) {
LOG("Register Connect V6: Error: %x\n", status);
TRACE(FORT_CALLOUT_REGISTER_CONNECT_V6_ERROR, status, 0, 0);
return status;
}
{
.calloutKey = FORT_GUID_CALLOUT_CONNECT_V6,
.classifyFn = (FWPS_CALLOUT_CLASSIFY_FN0) &fort_callout_connect_v6,
.notifyFn = (FWPS_CALLOUT_NOTIFY_FN0) &fort_callout_notify,
},
/* IPv4 accept callout */
c.calloutKey = FORT_GUID_CALLOUT_ACCEPT_V4;
c.classifyFn = (FWPS_CALLOUT_CLASSIFY_FN0) fort_callout_accept_v4;
status = FwpsCalloutRegister0(device, &c, &stat->accept4_id);
if (!NT_SUCCESS(status)) {
LOG("Register Accept V4: Error: %x\n", status);
TRACE(FORT_CALLOUT_REGISTER_ACCEPT_V4_ERROR, status, 0, 0);
return status;
}
{
.calloutKey = FORT_GUID_CALLOUT_ACCEPT_V4,
.classifyFn = (FWPS_CALLOUT_CLASSIFY_FN0) &fort_callout_accept_v4,
.notifyFn = (FWPS_CALLOUT_NOTIFY_FN0) &fort_callout_notify,
},
/* IPv6 accept callout */
c.calloutKey = FORT_GUID_CALLOUT_ACCEPT_V6;
c.classifyFn = (FWPS_CALLOUT_CLASSIFY_FN0) fort_callout_accept_v6;
status = FwpsCalloutRegister0(device, &c, &stat->accept6_id);
if (!NT_SUCCESS(status)) {
LOG("Register Accept V6: Error: %x\n", status);
TRACE(FORT_CALLOUT_REGISTER_ACCEPT_V6_ERROR, status, 0, 0);
return status;
}
{
.calloutKey = FORT_GUID_CALLOUT_ACCEPT_V6,
.classifyFn = (FWPS_CALLOUT_CLASSIFY_FN0) &fort_callout_accept_v6,
.notifyFn = (FWPS_CALLOUT_NOTIFY_FN0) &fort_callout_notify,
},
/* IPv4 stream callout */
c.calloutKey = FORT_GUID_CALLOUT_STREAM_V4;
c.classifyFn = (FWPS_CALLOUT_CLASSIFY_FN0) fort_callout_stream_classify;
c.flowDeleteFn = fort_callout_flow_delete;
c.flags = FWP_CALLOUT_FLAG_CONDITIONAL_ON_FLOW;
status = FwpsCalloutRegister0(device, &c, &stat->stream4_id);
if (!NT_SUCCESS(status)) {
LOG("Register Stream V4: Error: %x\n", status);
TRACE(FORT_CALLOUT_REGISTER_STREAM_V4_ERROR, status, 0, 0);
return status;
}
{
.calloutKey = FORT_GUID_CALLOUT_STREAM_V4,
.classifyFn = (FWPS_CALLOUT_CLASSIFY_FN0) &fort_callout_stream_classify,
.notifyFn = (FWPS_CALLOUT_NOTIFY_FN0) &fort_callout_notify,
.flowDeleteFn = &fort_callout_flow_delete,
.flags = FWP_CALLOUT_FLAG_CONDITIONAL_ON_FLOW,
},
/* IPv6 stream callout */
c.calloutKey = FORT_GUID_CALLOUT_STREAM_V6;
c.classifyFn = (FWPS_CALLOUT_CLASSIFY_FN0) fort_callout_stream_classify;
/* reuse c.flowDeleteFn & c.flags */
status = FwpsCalloutRegister0(device, &c, &stat->stream6_id);
if (!NT_SUCCESS(status)) {
LOG("Register Stream V6: Error: %x\n", status);
TRACE(FORT_CALLOUT_REGISTER_STREAM_V6_ERROR, status, 0, 0);
return status;
}
{
.calloutKey = FORT_GUID_CALLOUT_STREAM_V6,
.classifyFn = (FWPS_CALLOUT_CLASSIFY_FN0) &fort_callout_stream_classify,
.notifyFn = (FWPS_CALLOUT_NOTIFY_FN0) &fort_callout_notify,
.flowDeleteFn = &fort_callout_flow_delete,
.flags = FWP_CALLOUT_FLAG_CONDITIONAL_ON_FLOW,
},
/* IPv4 datagram callout */
c.calloutKey = FORT_GUID_CALLOUT_DATAGRAM_V4;
c.classifyFn = (FWPS_CALLOUT_CLASSIFY_FN0) fort_callout_datagram_classify_v4;
/* reuse c.flowDeleteFn & c.flags */
status = FwpsCalloutRegister0(device, &c, &stat->datagram4_id);
if (!NT_SUCCESS(status)) {
LOG("Register Datagram V4: Error: %x\n", status);
TRACE(FORT_CALLOUT_REGISTER_DATAGRAM_V4_ERROR, status, 0, 0);
return status;
}
{
.calloutKey = FORT_GUID_CALLOUT_DATAGRAM_V4,
.classifyFn = (FWPS_CALLOUT_CLASSIFY_FN0) &fort_callout_datagram_classify_v4,
.notifyFn = (FWPS_CALLOUT_NOTIFY_FN0) &fort_callout_notify,
.flowDeleteFn = &fort_callout_flow_delete,
.flags = FWP_CALLOUT_FLAG_CONDITIONAL_ON_FLOW,
},
/* IPv6 datagram callout */
c.calloutKey = FORT_GUID_CALLOUT_DATAGRAM_V6;
c.classifyFn = (FWPS_CALLOUT_CLASSIFY_FN0) fort_callout_datagram_classify_v6;
/* reuse c.flowDeleteFn & c.flags */
status = FwpsCalloutRegister0(device, &c, &stat->datagram6_id);
if (!NT_SUCCESS(status)) {
LOG("Register Datagram V6: Error: %x\n", status);
TRACE(FORT_CALLOUT_REGISTER_DATAGRAM_V6_ERROR, status, 0, 0);
return status;
}
{
.calloutKey = FORT_GUID_CALLOUT_DATAGRAM_V6,
.classifyFn = (FWPS_CALLOUT_CLASSIFY_FN0) &fort_callout_datagram_classify_v6,
.notifyFn = (FWPS_CALLOUT_NOTIFY_FN0) &fort_callout_notify,
.flowDeleteFn = &fort_callout_flow_delete,
.flags = FWP_CALLOUT_FLAG_CONDITIONAL_ON_FLOW,
},
/* IPv4 inbound transport callout */
c.calloutKey = FORT_GUID_CALLOUT_IN_TRANSPORT_V4;
c.classifyFn = (FWPS_CALLOUT_CLASSIFY_FN0) fort_callout_transport_classify_in;
c.flowDeleteFn = fort_callout_transport_delete;
/* reuse c.flags */
status = FwpsCalloutRegister0(device, &c, &stat->in_transport4_id);
if (!NT_SUCCESS(status)) {
LOG("Register Inbound Transport V4: Error: %x\n", status);
TRACE(FORT_CALLOUT_REGISTER_INBOUND_TRANSPORT_V4_ERROR, status, 0, 0);
return status;
}
{
.calloutKey = FORT_GUID_CALLOUT_IN_TRANSPORT_V4,
.classifyFn = (FWPS_CALLOUT_CLASSIFY_FN0) &fort_callout_transport_classify_in,
.notifyFn = (FWPS_CALLOUT_NOTIFY_FN0) &fort_callout_notify,
.flowDeleteFn = &fort_callout_transport_delete,
.flags = FWP_CALLOUT_FLAG_CONDITIONAL_ON_FLOW,
},
/* IPv6 inbound transport callout */
c.calloutKey = FORT_GUID_CALLOUT_IN_TRANSPORT_V6;
c.classifyFn = (FWPS_CALLOUT_CLASSIFY_FN0) fort_callout_transport_classify_in;
/* reuse c.flowDeleteFn & c.flags */
status = FwpsCalloutRegister0(device, &c, &stat->in_transport6_id);
if (!NT_SUCCESS(status)) {
LOG("Register Inbound Transport V6: Error: %x\n", status);
TRACE(FORT_CALLOUT_REGISTER_INBOUND_TRANSPORT_V6_ERROR, status, 0, 0);
return status;
}
{
.calloutKey = FORT_GUID_CALLOUT_IN_TRANSPORT_V6,
.classifyFn = (FWPS_CALLOUT_CLASSIFY_FN0) &fort_callout_transport_classify_in,
.notifyFn = (FWPS_CALLOUT_NOTIFY_FN0) &fort_callout_notify,
.flowDeleteFn = &fort_callout_transport_delete,
.flags = FWP_CALLOUT_FLAG_CONDITIONAL_ON_FLOW,
},
/* IPv4 outbound transport callout */
c.calloutKey = FORT_GUID_CALLOUT_OUT_TRANSPORT_V4;
c.classifyFn = (FWPS_CALLOUT_CLASSIFY_FN0) fort_callout_transport_classify_out;
{
.calloutKey = FORT_GUID_CALLOUT_OUT_TRANSPORT_V4,
.classifyFn = (FWPS_CALLOUT_CLASSIFY_FN0) &fort_callout_transport_classify_out,
.notifyFn = (FWPS_CALLOUT_NOTIFY_FN0) &fort_callout_notify,
.flowDeleteFn = &fort_callout_transport_delete,
.flags = FWP_CALLOUT_FLAG_CONDITIONAL_ON_FLOW,
},
/* IPv6 outbound transport callout */
{
.calloutKey = FORT_GUID_CALLOUT_OUT_TRANSPORT_V6,
.classifyFn = (FWPS_CALLOUT_CLASSIFY_FN0) &fort_callout_transport_classify_out,
.notifyFn = (FWPS_CALLOUT_NOTIFY_FN0) &fort_callout_notify,
.flowDeleteFn = &fort_callout_transport_delete,
.flags = FWP_CALLOUT_FLAG_CONDITIONAL_ON_FLOW,
},
};
/* reuse c.flowDeleteFn & c.flags */
status = FwpsCalloutRegister0(device, &c, &stat->out_transport4_id);
for (int i = 0; i < sizeof(callouts) / sizeof(callouts[0]); ++i) {
const NTSTATUS status = FwpsCalloutRegister0(device, &callouts[i], calloutIds[i]);
if (!NT_SUCCESS(status)) {
LOG("Register Outbound Transport V4: Error: %x\n", status);
TRACE(FORT_CALLOUT_REGISTER_OUTBOUND_TRANSPORT_V4_ERROR, status, 0, 0);
LOG("Callout Register: Error: %x\n", status);
TRACE(FORT_CALLOUT_REGISTER_ERROR, status, i, 0);
return status;
}
/* IPv6 outbound transport callout */
c.calloutKey = FORT_GUID_CALLOUT_OUT_TRANSPORT_V6;
c.classifyFn = (FWPS_CALLOUT_CLASSIFY_FN0) fort_callout_transport_classify_out;
/* reuse c.flowDeleteFn & c.flags */
status = FwpsCalloutRegister0(device, &c, &stat->out_transport6_id);
if (!NT_SUCCESS(status)) {
LOG("Register Outbound Transport V6: Error: %x\n", status);
TRACE(FORT_CALLOUT_REGISTER_OUTBOUND_TRANSPORT_V6_ERROR, status, 0, 0);
return status;
}
return STATUS_SUCCESS;