[SDK][IP] Fix formatting

This commit is contained in:
Victor Perevertkin 2019-11-22 22:04:56 +03:00 committed by Victor Perevertkin
parent 792b64ea46
commit cf3ab9d15a

View file

@ -49,14 +49,15 @@ BOOLEAN DGRemoveIRP(
return Found; return Found;
} }
VOID DGDeliverData( VOID
PADDRESS_FILE AddrFile, DGDeliverData(
PIP_ADDRESS SrcAddress, PADDRESS_FILE AddrFile,
PIP_ADDRESS DstAddress, PIP_ADDRESS SrcAddress,
USHORT SrcPort, PIP_ADDRESS DstAddress,
USHORT DstPort, USHORT SrcPort,
PIP_PACKET IPPacket, USHORT DstPort,
UINT DataSize) PIP_PACKET IPPacket,
UINT DataSize)
/* /*
* FUNCTION: Delivers datagram data to a user * FUNCTION: Delivers datagram data to a user
* ARGUMENTS: * ARGUMENTS:
@ -72,139 +73,140 @@ VOID DGDeliverData(
* handler if it exists, otherwise we drop the packet. * handler if it exists, otherwise we drop the packet.
*/ */
{ {
KIRQL OldIrql; KIRQL OldIrql;
PTDI_IND_RECEIVE_DATAGRAM ReceiveHandler; PTDI_IND_RECEIVE_DATAGRAM ReceiveHandler;
PVOID HandlerContext; PVOID HandlerContext;
LONG AddressLength; LONG AddressLength;
PVOID SourceAddress; PVOID SourceAddress;
ULONG BytesTaken; ULONG BytesTaken;
NTSTATUS Status; NTSTATUS Status;
PVOID DataBuffer; PVOID DataBuffer;
TI_DbgPrint(MAX_TRACE, ("Called.\n")); TI_DbgPrint(MIN_TRACE, ("Called.\n"));
LockObject(AddrFile, &OldIrql); LockObject(AddrFile, &OldIrql);
if (AddrFile->Protocol == IPPROTO_UDP) if (AddrFile->Protocol == IPPROTO_UDP)
{ {
DataBuffer = IPPacket->Data; DataBuffer = IPPacket->Data;
} }
else else if (AddrFile->HeaderIncl)
{ {
if (AddrFile->HeaderIncl) DataBuffer = IPPacket->Header;
DataBuffer = IPPacket->Header; }
else else
{ {
DataBuffer = IPPacket->Data; DataBuffer = IPPacket->Data;
DataSize -= IPPacket->HeaderSize; DataSize -= IPPacket->HeaderSize;
}
} }
if (!IsListEmpty(&AddrFile->ReceiveQueue)) if (!IsListEmpty(&AddrFile->ReceiveQueue))
{ {
PLIST_ENTRY CurrentEntry; PLIST_ENTRY CurrentEntry;
PDATAGRAM_RECEIVE_REQUEST Current = NULL; PDATAGRAM_RECEIVE_REQUEST Current = NULL;
PTA_IP_ADDRESS RTAIPAddress; PTA_IP_ADDRESS RTAIPAddress;
TI_DbgPrint(MAX_TRACE, ("There is a receive request.\n")); TI_DbgPrint(MAX_TRACE, ("There is a receive request.\n"));
/* Search receive request list to find a match */ /* Search receive request list to find a match */
CurrentEntry = AddrFile->ReceiveQueue.Flink; CurrentEntry = AddrFile->ReceiveQueue.Flink;
while(CurrentEntry != &AddrFile->ReceiveQueue) { while (CurrentEntry != &AddrFile->ReceiveQueue)
Current = CONTAINING_RECORD(CurrentEntry, DATAGRAM_RECEIVE_REQUEST, ListEntry); {
CurrentEntry = CurrentEntry->Flink; Current = CONTAINING_RECORD(CurrentEntry, DATAGRAM_RECEIVE_REQUEST, ListEntry);
if( DstPort == AddrFile->Port && CurrentEntry = CurrentEntry->Flink;
(AddrIsEqual(DstAddress, &AddrFile->Address) || if (DstPort == AddrFile->Port &&
AddrIsUnspecified(&AddrFile->Address) || (AddrIsEqual(DstAddress, &AddrFile->Address) ||
AddrIsUnspecified(DstAddress))) { AddrIsUnspecified(&AddrFile->Address) ||
AddrIsUnspecified(DstAddress)))
{
/* Remove the request from the queue */ /* Remove the request from the queue */
RemoveEntryList(&Current->ListEntry); RemoveEntryList(&Current->ListEntry);
TI_DbgPrint(MAX_TRACE, ("Suitable receive request found.\n")); TI_DbgPrint(MAX_TRACE, ("Suitable receive request found.\n"));
TI_DbgPrint(MAX_TRACE, TI_DbgPrint(MAX_TRACE,
("Target Buffer: %x, Source Buffer: %x, Size %d\n", ("Target Buffer: %x, Source Buffer: %x, Size %d\n",
Current->Buffer, DataBuffer, DataSize)); Current->Buffer, DataBuffer, DataSize));
/* Copy the data into buffer provided by the user */ /* Copy the data into buffer provided by the user */
RtlCopyMemory( Current->Buffer, RtlCopyMemory(Current->Buffer,
DataBuffer, DataBuffer,
MIN(Current->BufferSize, DataSize) ); MIN(Current->BufferSize, DataSize));
RTAIPAddress = (PTA_IP_ADDRESS)Current->ReturnInfo->RemoteAddress; RTAIPAddress = (PTA_IP_ADDRESS)Current->ReturnInfo->RemoteAddress;
RTAIPAddress->TAAddressCount = 1; RTAIPAddress->TAAddressCount = 1;
RTAIPAddress->Address->AddressType = TDI_ADDRESS_TYPE_IP; RTAIPAddress->Address->AddressType = TDI_ADDRESS_TYPE_IP;
RTAIPAddress->Address->AddressLength = TDI_ADDRESS_LENGTH_IP; RTAIPAddress->Address->AddressLength = TDI_ADDRESS_LENGTH_IP;
RTAIPAddress->Address->Address->sin_port = SrcPort; RTAIPAddress->Address->Address->sin_port = SrcPort;
RTAIPAddress->Address->Address->in_addr = SrcAddress->Address.IPv4Address; RTAIPAddress->Address->Address->in_addr = SrcAddress->Address.IPv4Address;
RtlZeroMemory(RTAIPAddress->Address->Address->sin_zero, 8); RtlZeroMemory(RTAIPAddress->Address->Address->sin_zero, 8);
TI_DbgPrint(MAX_TRACE, ("(A: %08x) Addr %08x Port %04x\n", TI_DbgPrint(MAX_TRACE, ("(A: %08x) Addr %08x Port %04x\n",
RTAIPAddress, RTAIPAddress,
SrcAddress->Address.IPv4Address, SrcPort)); SrcAddress->Address.IPv4Address, SrcPort));
ReferenceObject(AddrFile); ReferenceObject(AddrFile);
UnlockObject(AddrFile, OldIrql); UnlockObject(AddrFile, OldIrql);
/* Complete the receive request */ /* Complete the receive request */
if (Current->BufferSize < DataSize) if (Current->BufferSize < DataSize)
Current->Complete(Current->Context, STATUS_BUFFER_OVERFLOW, Current->BufferSize); Current->Complete(Current->Context, STATUS_BUFFER_OVERFLOW, Current->BufferSize);
else else
Current->Complete(Current->Context, STATUS_SUCCESS, DataSize); Current->Complete(Current->Context, STATUS_SUCCESS, DataSize);
LockObject(AddrFile, &OldIrql); LockObject(AddrFile, &OldIrql);
DereferenceObject(AddrFile); DereferenceObject(AddrFile);
} }
}
UnlockObject(AddrFile, OldIrql);
}
else if (AddrFile->RegisteredReceiveDatagramHandler)
{
TI_DbgPrint(MAX_TRACE, ("Calling receive event handler.\n"));
ReceiveHandler = AddrFile->ReceiveDatagramHandler;
HandlerContext = AddrFile->ReceiveDatagramHandlerContext;
if (SrcAddress->Type == IP_ADDRESS_V4)
{
AddressLength = sizeof(IPv4_RAW_ADDRESS);
SourceAddress = &SrcAddress->Address.IPv4Address;
}
else /* (Address->Type == IP_ADDRESS_V6) */
{
AddressLength = sizeof(IPv6_RAW_ADDRESS);
SourceAddress = SrcAddress->Address.IPv6Address;
} }
ReferenceObject(AddrFile); UnlockObject(AddrFile, OldIrql);
UnlockObject(AddrFile, OldIrql);
Status = (*ReceiveHandler)(HandlerContext,
AddressLength,
SourceAddress,
0,
NULL,
TDI_RECEIVE_ENTIRE_MESSAGE,
DataSize,
DataSize,
&BytesTaken,
DataBuffer,
NULL);
if (STATUS_SUCCESS != Status)
TI_DbgPrint(MAX_TRACE, ("receive handler signaled failure with Status 0x%x\n", Status));
DereferenceObject(AddrFile);
} }
else else if (AddrFile->RegisteredReceiveDatagramHandler)
{ {
UnlockObject(AddrFile, OldIrql); TI_DbgPrint(MAX_TRACE, ("Calling receive event handler.\n"));
TI_DbgPrint(MAX_TRACE, ("Discarding datagram.\n"));
ReceiveHandler = AddrFile->ReceiveDatagramHandler;
HandlerContext = AddrFile->ReceiveDatagramHandlerContext;
if (SrcAddress->Type == IP_ADDRESS_V4)
{
AddressLength = sizeof(IPv4_RAW_ADDRESS);
SourceAddress = &SrcAddress->Address.IPv4Address;
}
else /* (Address->Type == IP_ADDRESS_V6) */
{
AddressLength = sizeof(IPv6_RAW_ADDRESS);
SourceAddress = SrcAddress->Address.IPv6Address;
}
ReferenceObject(AddrFile);
UnlockObject(AddrFile, OldIrql);
Status = (*ReceiveHandler)(HandlerContext,
AddressLength,
SourceAddress,
0,
NULL,
TDI_RECEIVE_ENTIRE_MESSAGE,
DataSize,
DataSize,
&BytesTaken,
DataBuffer,
NULL);
if (STATUS_SUCCESS != Status)
TI_DbgPrint(MAX_TRACE, ("receive handler signaled failure with Status 0x%x\n", Status));
DereferenceObject(AddrFile);
}
else
{
UnlockObject(AddrFile, OldIrql);
TI_DbgPrint(MAX_TRACE, ("Discarding datagram.\n"));
} }
TI_DbgPrint(MAX_TRACE, ("Leaving.\n")); TI_DbgPrint(MAX_TRACE, ("Leaving.\n"));
} }