Author: cgutman
Date: Sun Oct 4 21:23:53 2009
New Revision: 43287
URL:
http://svn.reactos.org/svn/reactos?rev=43287&view=rev
Log:
- Don't add the media-specific header until right before transmission
- Previously we would store the largest media-specific header size and add that value
when creating a packet
- Makes loopback packets smaller because they have no need for a media-specific header
- Would fix packet corruption if interfaces with different media-specific headers were
installed (if we supported that)
- Makes adding support for other media types easier
Modified:
trunk/reactos/drivers/network/tcpip/datalink/lan.c
trunk/reactos/drivers/network/tcpip/include/ip.h
trunk/reactos/lib/drivers/ip/network/arp.c
trunk/reactos/lib/drivers/ip/network/icmp.c
trunk/reactos/lib/drivers/ip/network/ip.c
trunk/reactos/lib/drivers/ip/network/loopback.c
trunk/reactos/lib/drivers/ip/network/neighbor.c
trunk/reactos/lib/drivers/ip/network/routines.c
trunk/reactos/lib/drivers/ip/network/transmit.c
trunk/reactos/lib/drivers/ip/transport/rawip/rawip.c
trunk/reactos/lib/drivers/ip/transport/tcp/event.c
trunk/reactos/lib/drivers/ip/transport/udp/udp.c
Modified: trunk/reactos/drivers/network/tcpip/datalink/lan.c
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/drivers/network/tcpip/data…
==============================================================================
--- trunk/reactos/drivers/network/tcpip/datalink/lan.c [iso-8859-1] (original)
+++ trunk/reactos/drivers/network/tcpip/datalink/lan.c [iso-8859-1] Sun Oct 4 21:23:53
2009
@@ -231,12 +231,7 @@
* Status = Status of the operation
*/
{
- TI_DbgPrint(DEBUG_DATALINK, ("Calling completion routine\n"));
- ASSERT_KM_POINTER(Packet);
- ASSERT_KM_POINTER(PC(Packet));
- ASSERT_KM_POINTER(PC(Packet)->DLComplete);
- (*PC(Packet)->DLComplete)( PC(Packet)->Context, Packet, Status);
- TI_DbgPrint(DEBUG_DATALINK, ("Finished\n"));
+ FreeNdisPacket(Packet);
}
VOID LanReceiveWorker( PVOID Context ) {
@@ -418,7 +413,7 @@
Adapter, Adapter->MTU));
NdisStatus = AllocatePacketWithBuffer( &NdisPacket, NULL,
- PacketSize + HeaderBufferSize );
+ PacketSize );
if( NdisStatus != NDIS_STATUS_SUCCESS ) {
return NDIS_STATUS_NOT_ACCEPTED;
}
@@ -599,18 +594,18 @@
{
NDIS_STATUS NdisStatus;
PETH_HEADER EHeader;
- PCHAR Data;
- UINT Size;
+ PCHAR Data, OldData;
+ UINT Size, OldSize;
PLAN_ADAPTER Adapter = (PLAN_ADAPTER)Context;
KIRQL OldIrql;
- UINT PacketLength;
+ PNDIS_PACKET XmitPacket;
TI_DbgPrint(DEBUG_DATALINK,
("Called( NdisPacket %x, Offset %d, Adapter %x )\n",
NdisPacket, Offset, Adapter));
if (Adapter->State != LAN_STATE_STARTED) {
- ProtocolSendComplete(Context, NdisPacket, NDIS_STATUS_NOT_ACCEPTED);
+ (*PC(NdisPacket)->DLComplete)(PC(NdisPacket)->Context, NdisPacket,
NDIS_STATUS_NOT_ACCEPTED);
return;
}
@@ -623,9 +618,19 @@
Adapter->HWAddress[4] & 0xff,
Adapter->HWAddress[5] & 0xff));
- /* XXX arty -- Handled adjustment in a saner way than before ...
- * not needed immediately */
- GetDataPtr( NdisPacket, 0, &Data, &Size );
+ GetDataPtr( NdisPacket, 0, &OldData, &OldSize );
+
+ NdisStatus = AllocatePacketWithBuffer(&XmitPacket, NULL, OldSize +
Adapter->HeaderSize);
+ if (NdisStatus != NDIS_STATUS_SUCCESS) {
+ (*PC(NdisPacket)->DLComplete)(PC(NdisPacket)->Context, NdisPacket,
NDIS_STATUS_RESOURCES);
+ return;
+ }
+
+ GetDataPtr(XmitPacket, 0, &Data, &Size);
+
+ RtlCopyMemory(Data + Adapter->HeaderSize, OldData, OldSize);
+
+ (*PC(NdisPacket)->DLComplete)(PC(NdisPacket)->Context, NdisPacket,
NDIS_STATUS_SUCCESS);
switch (Adapter->Media) {
case NdisMedium802_3:
@@ -652,14 +657,7 @@
EHeader->EType = ETYPE_IPv6;
break;
default:
-#if DBG
- /* Should not happen */
- TI_DbgPrint(MIN_TRACE, ("Unknown LAN protocol.\n"));
-
- ProtocolSendComplete((NDIS_HANDLE)Context,
- NdisPacket,
- NDIS_STATUS_FAILURE);
-#endif
+ ASSERT(FALSE);
return;
}
break;
@@ -682,9 +680,7 @@
((PCHAR)LinkAddress)[5] & 0xff));
}
- NdisQueryPacketLength(NdisPacket, &PacketLength);
-
- if (Adapter->MTU < PacketLength) {
+ if (Adapter->MTU < Size) {
/* This is NOT a pointer. MSDN explicitly says so. */
NDIS_PER_PACKET_INFO_FROM_PACKET(NdisPacket,
TcpLargeSendPacketInfo) =
(PVOID)((ULONG)Adapter->MTU);
@@ -692,7 +688,7 @@
TcpipAcquireSpinLock( &Adapter->Lock, &OldIrql );
TI_DbgPrint(MID_TRACE, ("NdisSend\n"));
- NdisSend(&NdisStatus, Adapter->NdisHandle, NdisPacket);
+ NdisSend(&NdisStatus, Adapter->NdisHandle, XmitPacket);
TI_DbgPrint(MID_TRACE, ("NdisSend %s\n",
NdisStatus == NDIS_STATUS_PENDING ?
"Pending" : "Complete"));
@@ -703,7 +699,7 @@
* status_pending is returned. Note that this is different from
* the situation with IRPs. */
if (NdisStatus != NDIS_STATUS_PENDING)
- ProtocolSendComplete((NDIS_HANDLE)Context, NdisPacket, NdisStatus);
+ ProtocolSendComplete((NDIS_HANDLE)Context, XmitPacket, NdisStatus);
}
static NTSTATUS
Modified: trunk/reactos/drivers/network/tcpip/include/ip.h
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/drivers/network/tcpip/incl…
==============================================================================
--- trunk/reactos/drivers/network/tcpip/include/ip.h [iso-8859-1] (original)
+++ trunk/reactos/drivers/network/tcpip/include/ip.h [iso-8859-1] Sun Oct 4 21:23:53
2009
@@ -208,8 +208,6 @@
extern KSPIN_LOCK InterfaceListLock;
extern LIST_ENTRY NetTableListHead;
extern KSPIN_LOCK NetTableListLock;
-extern UINT MaxLLHeaderSize;
-extern UINT MinLLFrameSize;
extern BOOLEAN IpWorkItemQueued;
PIP_PACKET IPCreatePacket(
Modified: trunk/reactos/lib/drivers/ip/network/arp.c
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/lib/drivers/ip/network/arp…
==============================================================================
--- trunk/reactos/lib/drivers/ip/network/arp.c [iso-8859-1] (original)
+++ trunk/reactos/lib/drivers/ip/network/arp.c [iso-8859-1] Sun Oct 4 21:23:53 2009
@@ -11,6 +11,7 @@
#include "precomp.h"
PNDIS_PACKET PrepareARPPacket(
+ PIP_INTERFACE IF,
USHORT HardwareType,
USHORT ProtocolType,
UCHAR LinkAddressLength,
@@ -45,11 +46,10 @@
TI_DbgPrint(DEBUG_ARP, ("Called.\n"));
/* Prepare ARP packet */
- Size = MaxLLHeaderSize +
- sizeof(ARP_HEADER) +
+ Size = sizeof(ARP_HEADER) +
2 * LinkAddressLength + /* Hardware address length */
2 * ProtoAddressLength; /* Protocol address length */
- Size = MAX(Size, MinLLFrameSize);
+ Size = MAX(Size, IF->MinFrameSize - IF->HeaderSize);
NdisStatus = AllocatePacketWithBuffer( &NdisPacket, NULL, Size );
if( !NT_SUCCESS(NdisStatus) ) return NULL;
@@ -58,7 +58,7 @@
ASSERT(DataBuffer);
RtlZeroMemory(DataBuffer, Size);
- Header = (PARP_HEADER)((ULONG_PTR)DataBuffer + MaxLLHeaderSize);
+ Header = (PARP_HEADER)((ULONG_PTR)DataBuffer);
Header->HWType = HardwareType;
Header->ProtoType = ProtocolType;
Header->HWAddrLen = LinkAddressLength;
@@ -145,6 +145,7 @@
}
NdisPacket = PrepareARPPacket(
+ Interface,
WN2H(0x0001), /* FIXME: Ethernet only */
ProtoType, /* Protocol type */
(UCHAR)Interface->AddressLength, /* Hardware address length */
@@ -164,7 +165,7 @@
TI_DbgPrint(DEBUG_ARP,("Sending ARP Packet\n"));
(*Interface->Transmit)(Interface->Context, NdisPacket,
- MaxLLHeaderSize, NULL, LAN_PROTO_ARP);
+ 0, NULL, LAN_PROTO_ARP);
return TRUE;
}
@@ -230,6 +231,7 @@
/* This is a request for our address. Swap the addresses and
send an ARP reply back to the sender */
NdisPacket = PrepareARPPacket(
+ Interface,
Header->HWType, /* Hardware type */
Header->ProtoType, /* Protocol type */
(UCHAR)Interface->AddressLength, /* Hardware address length */
@@ -243,7 +245,7 @@
PC(NdisPacket)->DLComplete = ARPTransmitComplete;
(*Interface->Transmit)(Interface->Context,
NdisPacket,
- MaxLLHeaderSize,
+ 0,
SenderHWAddress,
LAN_PROTO_ARP);
}
Modified: trunk/reactos/lib/drivers/ip/network/icmp.c
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/lib/drivers/ip/network/icm…
==============================================================================
--- trunk/reactos/lib/drivers/ip/network/icmp.c [iso-8859-1] (original)
+++ trunk/reactos/lib/drivers/ip/network/icmp.c [iso-8859-1] Sun Oct 4 21:23:53 2009
@@ -75,7 +75,7 @@
/* No special flags */
IPPacket->Flags = 0;
- Size = MaxLLHeaderSize + sizeof(IPv4_HEADER) + DataSize;
+ Size = sizeof(IPv4_HEADER) + DataSize;
/* Allocate NDIS packet */
NdisStatus = AllocatePacketWithBuffer( &NdisPacket, NULL, Size );
@@ -84,14 +84,14 @@
IPPacket->NdisPacket = NdisPacket;
- GetDataPtr( IPPacket->NdisPacket, MaxLLHeaderSize,
+ GetDataPtr( IPPacket->NdisPacket, 0,
(PCHAR *)&IPPacket->Header, &IPPacket->ContigSize );
TI_DbgPrint(DEBUG_ICMP, ("Size (%d). Data at (0x%X).\n", Size, Data));
TI_DbgPrint(DEBUG_ICMP, ("NdisPacket at (0x%X).\n", NdisPacket));
IPPacket->HeaderSize = sizeof(IPv4_HEADER);
- IPPacket->TotalSize = Size - MaxLLHeaderSize;
+ IPPacket->TotalSize = Size;
IPPacket->Data = ((PCHAR)IPPacket->Header) + IPPacket->HeaderSize;
TI_DbgPrint(DEBUG_ICMP, ("Copying Address: %x -> %x\n",
Modified: trunk/reactos/lib/drivers/ip/network/ip.c
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/lib/drivers/ip/network/ip.…
==============================================================================
--- trunk/reactos/lib/drivers/ip/network/ip.c [iso-8859-1] (original)
+++ trunk/reactos/lib/drivers/ip/network/ip.c [iso-8859-1] Sun Oct 4 21:23:53 2009
@@ -15,8 +15,6 @@
KSPIN_LOCK InterfaceListLock;
LIST_ENTRY NetTableListHead;
KSPIN_LOCK NetTableListLock;
-UINT MaxLLHeaderSize; /* Largest maximum header size */
-UINT MinLLFrameSize; /* Largest minimum frame size */
BOOLEAN IPInitialized = FALSE;
BOOLEAN IpWorkItemQueued = FALSE;
/* Work around calling timer at Dpc level */
@@ -153,13 +151,7 @@
IF->Free = FreeIF;
IF->Context = BindInfo->Context;
IF->HeaderSize = BindInfo->HeaderSize;
- if (IF->HeaderSize > MaxLLHeaderSize)
- MaxLLHeaderSize = IF->HeaderSize;
-
IF->MinFrameSize = BindInfo->MinFrameSize;
- if (IF->MinFrameSize > MinLLFrameSize)
- MinLLFrameSize = IF->MinFrameSize;
-
IF->MTU = BindInfo->MTU;
IF->Address = BindInfo->Address;
IF->AddressLength = BindInfo->AddressLength;
@@ -361,9 +353,6 @@
TI_DbgPrint(MAX_TRACE, ("Called.\n"));
- MaxLLHeaderSize = 0;
- MinLLFrameSize = 0;
-
/* Initialize lookaside lists */
ExInitializeNPagedLookasideList(
&IPDRList, /* Lookaside list */
Modified: trunk/reactos/lib/drivers/ip/network/loopback.c
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/lib/drivers/ip/network/loo…
==============================================================================
--- trunk/reactos/lib/drivers/ip/network/loopback.c [iso-8859-1] (original)
+++ trunk/reactos/lib/drivers/ip/network/loopback.c [iso-8859-1] Sun Oct 4 21:23:53 2009
@@ -41,7 +41,7 @@
TI_DbgPrint(MAX_TRACE, ("Called (NdisPacket = %x)\n", NdisPacket));
- GetDataPtr( NdisPacket, MaxLLHeaderSize, &PacketBuffer, &PacketLength );
+ GetDataPtr( NdisPacket, 0, &PacketBuffer, &PacketLength );
NdisStatus = AllocatePacketWithBuffer
( &XmitPacket, PacketBuffer, PacketLength );
Modified: trunk/reactos/lib/drivers/ip/network/neighbor.c
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/lib/drivers/ip/network/nei…
==============================================================================
--- trunk/reactos/lib/drivers/ip/network/neighbor.c [iso-8859-1] (original)
+++ trunk/reactos/lib/drivers/ip/network/neighbor.c [iso-8859-1] Sun Oct 4 21:23:53 2009
@@ -55,7 +55,7 @@
NCE->Interface->Transmit
( NCE->Interface->Context,
Packet->Packet,
- MaxLLHeaderSize,
+ 0,
NCE->LinkAddress,
LAN_PROTO_IPv4 );
}
Modified: trunk/reactos/lib/drivers/ip/network/routines.c
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/lib/drivers/ip/network/rou…
==============================================================================
--- trunk/reactos/lib/drivers/ip/network/routines.c [iso-8859-1] (original)
+++ trunk/reactos/lib/drivers/ip/network/routines.c [iso-8859-1] Sun Oct 4 21:23:53 2009
@@ -115,10 +115,9 @@
if (IPPacket->NdisPacket) {
NdisQueryPacket(IPPacket->NdisPacket, NULL, NULL, NULL, &Length);
- Length -= MaxLLHeaderSize;
Buffer = exAllocatePool(NonPagedPool, Length);
if (Buffer) {
- Length = CopyPacketToBuffer(Buffer, IPPacket->NdisPacket, MaxLLHeaderSize,
Length);
+ Length = CopyPacketToBuffer(Buffer, IPPacket->NdisPacket, 0, Length);
DisplayTCPHeader(Buffer, Length);
exFreePool(Buffer);
}
Modified: trunk/reactos/lib/drivers/ip/network/transmit.c
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/lib/drivers/ip/network/tra…
==============================================================================
--- trunk/reactos/lib/drivers/ip/network/transmit.c [iso-8859-1] (original)
+++ trunk/reactos/lib/drivers/ip/network/transmit.c [iso-8859-1] Sun Oct 4 21:23:53 2009
@@ -166,7 +166,7 @@
PIPFRAGMENT_CONTEXT IFC;
NDIS_STATUS NdisStatus;
PVOID Data;
- UINT BufferSize = MaxLLHeaderSize + PathMTU, InSize;
+ UINT BufferSize = PathMTU, InSize;
PCHAR InData;
TI_DbgPrint(MAX_TRACE, ("Called. IPPacket (0x%X) NCE (0x%X) PathMTU
(%d).\n",
@@ -193,7 +193,7 @@
GetDataPtr( IFC->NdisPacket, 0, (PCHAR *)&Data, &InSize );
- IFC->Header = ((PCHAR)Data) + MaxLLHeaderSize;
+ IFC->Header = ((PCHAR)Data);
IFC->Datagram = IPPacket->NdisPacket;
IFC->DatagramData = ((PCHAR)IPPacket->Header) + IPPacket->HeaderSize;
IFC->HeaderSize = IPPacket->HeaderSize;
Modified: trunk/reactos/lib/drivers/ip/transport/rawip/rawip.c
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/lib/drivers/ip/transport/r…
==============================================================================
--- trunk/reactos/lib/drivers/ip/transport/rawip/rawip.c [iso-8859-1] (original)
+++ trunk/reactos/lib/drivers/ip/transport/rawip/rawip.c [iso-8859-1] Sun Oct 4 21:23:53
2009
@@ -37,10 +37,10 @@
TI_DbgPrint(MID_TRACE, ("Packet: %x NdisPacket %x\n",
IPPacket, IPPacket->NdisPacket));
- BufferSize = MaxLLHeaderSize + sizeof(IPv4_HEADER) + ExtraLength;
+ BufferSize = sizeof(IPv4_HEADER) + ExtraLength;
GetDataPtr( IPPacket->NdisPacket,
- MaxLLHeaderSize,
+ 0,
(PCHAR *)&IPPacket->Header,
&IPPacket->ContigSize );
@@ -113,7 +113,7 @@
/* Prepare packet */
Status = AllocatePacketWithBuffer( &Packet->NdisPacket,
NULL,
- Packet->TotalSize + MaxLLHeaderSize );
+ Packet->TotalSize );
if( !NT_SUCCESS(Status) ) return Status;
Modified: trunk/reactos/lib/drivers/ip/transport/tcp/event.c
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/lib/drivers/ip/transport/t…
==============================================================================
--- trunk/reactos/lib/drivers/ip/transport/tcp/event.c [iso-8859-1] (original)
+++ trunk/reactos/lib/drivers/ip/transport/tcp/event.c [iso-8859-1] Sun Oct 4 21:23:53
2009
@@ -86,15 +86,14 @@
return OSK_EADDRNOTAVAIL;
}
- NdisStatus = AllocatePacketWithBuffer( &Packet.NdisPacket, NULL,
- MaxLLHeaderSize + len );
+ NdisStatus = AllocatePacketWithBuffer( &Packet.NdisPacket, NULL, len );
if (NdisStatus != NDIS_STATUS_SUCCESS) {
TI_DbgPrint(DEBUG_TCP, ("Error from NDIS: %08x\n", NdisStatus));
return OSK_ENOBUFS;
}
- GetDataPtr( Packet.NdisPacket, MaxLLHeaderSize,
+ GetDataPtr( Packet.NdisPacket, 0,
(PCHAR *)&Packet.Header, &Packet.ContigSize );
RtlCopyMemory( Packet.Header, data, len );
Modified: trunk/reactos/lib/drivers/ip/transport/udp/udp.c
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/lib/drivers/ip/transport/u…
==============================================================================
--- trunk/reactos/lib/drivers/ip/transport/udp/udp.c [iso-8859-1] (original)
+++ trunk/reactos/lib/drivers/ip/transport/udp/udp.c [iso-8859-1] Sun Oct 4 21:23:53
2009
@@ -94,7 +94,7 @@
/* Prepare packet */
Status = AllocatePacketWithBuffer( &Packet->NdisPacket,
NULL,
- Packet->TotalSize + MaxLLHeaderSize );
+ Packet->TotalSize );
if( !NT_SUCCESS(Status) ) return Status;