Author: cmihail
Date: Mon Aug 1 20:10:55 2011
New Revision: 53020
URL:
http://svn.reactos.org/svn/reactos?rev=53020&view=rev
Log:
[TCPIP]
- merge r53017
- do some code cleanup
[lwIP]
- do some code cleanup
Modified:
branches/GSoC_2011/TcpIpDriver/drivers/network/tcpip/include/tcp.h
branches/GSoC_2011/TcpIpDriver/drivers/network/tcpip/tcpip/dispatch.c
branches/GSoC_2011/TcpIpDriver/lib/drivers/ip/transport/tcp/event.c
branches/GSoC_2011/TcpIpDriver/lib/drivers/ip/transport/tcp/tcp.c
branches/GSoC_2011/TcpIpDriver/lib/drivers/lwip/src/core/tcp_in.c
branches/GSoC_2011/TcpIpDriver/lib/drivers/lwip/src/include/rosip.h
branches/GSoC_2011/TcpIpDriver/lib/drivers/lwip/src/rosip.c
branches/GSoC_2011/TcpIpDriver/lib/drivers/lwip/src/rosmem.c
branches/GSoC_2011/TcpIpDriver/lib/drivers/lwip/src/rostcp.c
Modified: branches/GSoC_2011/TcpIpDriver/drivers/network/tcpip/include/tcp.h
URL:
http://svn.reactos.org/svn/reactos/branches/GSoC_2011/TcpIpDriver/drivers/n…
==============================================================================
--- branches/GSoC_2011/TcpIpDriver/drivers/network/tcpip/include/tcp.h [iso-8859-1]
(original)
+++ branches/GSoC_2011/TcpIpDriver/drivers/network/tcpip/include/tcp.h [iso-8859-1] Mon
Aug 1 20:10:55 2011
@@ -166,11 +166,11 @@
NTSTATUS TCPClose( PCONNECTION_ENDPOINT Connection );
-NTSTATUS TCPTranslateError( INT8 err );
+NTSTATUS TCPTranslateError( const INT8 err );
-UINT TCPAllocatePort( UINT HintPort );
+UINT TCPAllocatePort( const UINT HintPort );
-VOID TCPFreePort( UINT Port );
+VOID TCPFreePort( const UINT Port );
NTSTATUS TCPGetSockAddress
( PCONNECTION_ENDPOINT Connection,
@@ -192,4 +192,4 @@
TCPUpdateInterfaceIPInformation(PIP_INTERFACE IF);
VOID
-FlushAllQueues(PCONNECTION_ENDPOINT Connection, NTSTATUS Status);
+FlushAllQueues(PCONNECTION_ENDPOINT Connection, const NTSTATUS Status);
Modified: branches/GSoC_2011/TcpIpDriver/drivers/network/tcpip/tcpip/dispatch.c
URL:
http://svn.reactos.org/svn/reactos/branches/GSoC_2011/TcpIpDriver/drivers/n…
==============================================================================
--- branches/GSoC_2011/TcpIpDriver/drivers/network/tcpip/tcpip/dispatch.c [iso-8859-1]
(original)
+++ branches/GSoC_2011/TcpIpDriver/drivers/network/tcpip/tcpip/dispatch.c [iso-8859-1] Mon
Aug 1 20:10:55 2011
@@ -122,6 +122,7 @@
PTRANSPORT_CONTEXT TranContext;
PFILE_OBJECT FileObject;
UCHAR MinorFunction;
+ PCONNECTION_ENDPOINT Connection;
BOOLEAN DequeuedIrp = TRUE;
IoReleaseCancelSpinLock(Irp->CancelIrql);
@@ -173,7 +174,16 @@
break;
case TDI_DISCONNECT:
+ Connection = (PCONNECTION_ENDPOINT)TranContext->Handle.ConnectionContext;
+
DequeuedIrp = TCPRemoveIRP(TranContext->Handle.ConnectionContext, Irp);
+ if (DequeuedIrp)
+ {
+ if (KeCancelTimer(&Connection->DisconnectTimer))
+ {
+ DereferenceObject(Connection);
+ }
+ }
break;
default:
Modified: branches/GSoC_2011/TcpIpDriver/lib/drivers/ip/transport/tcp/event.c
URL:
http://svn.reactos.org/svn/reactos/branches/GSoC_2011/TcpIpDriver/lib/drive…
==============================================================================
--- branches/GSoC_2011/TcpIpDriver/lib/drivers/ip/transport/tcp/event.c [iso-8859-1]
(original)
+++ branches/GSoC_2011/TcpIpDriver/lib/drivers/ip/transport/tcp/event.c [iso-8859-1] Mon
Aug 1 20:10:55 2011
@@ -46,8 +46,9 @@
ExFreePoolWithTag(Bucket, TDI_BUCKET_TAG);
}
-VOID
-CompleteBucket(PCONNECTION_ENDPOINT Connection, PTDI_BUCKET Bucket, BOOLEAN Synchronous)
+static
+VOID
+CompleteBucket(PCONNECTION_ENDPOINT Connection, PTDI_BUCKET Bucket, const BOOLEAN
Synchronous)
{
ReferenceObject(Connection);
Bucket->AssociatedEndpoint = Connection;
@@ -62,7 +63,7 @@
}
VOID
-FlushAllQueues(PCONNECTION_ENDPOINT Connection, NTSTATUS Status)
+FlushAllQueues(PCONNECTION_ENDPOINT Connection, const NTSTATUS Status)
{
PTDI_BUCKET Bucket;
PLIST_ENTRY Entry;
@@ -140,7 +141,7 @@
}
VOID
-TCPFinEventHandler(void *arg, err_t err)
+TCPFinEventHandler(void *arg, const err_t err)
{
PCONNECTION_ENDPOINT Connection = (PCONNECTION_ENDPOINT)arg;
const NTSTATUS status = TCPTranslateError(err);
@@ -148,7 +149,7 @@
DbgPrint("[IP, TCPFinEventHandler] Called for Connection( 0x%x )->
SocketContext = pcb (0x%x)\n", Connection, Connection->SocketContext);
/* Only clear the pointer if the shutdown was caused by an error */
- if ((err != ERR_OK))
+ if (err != ERR_OK)
{
/* We're already closed by the error so we don't want to call lwip_close
*/
DbgPrint("[IP, TCPFinEventHandler] MAKING Connection( 0x%x )->
SocketContext = pcb (0x%x) NULL\n", Connection, Connection->SocketContext);
@@ -162,7 +163,7 @@
}
VOID
-TCPAcceptEventHandler(void *arg, struct tcp_pcb *newpcb)
+TCPAcceptEventHandler(void *arg, PTCP_PCB newpcb)
{
PCONNECTION_ENDPOINT Connection = (PCONNECTION_ENDPOINT)arg;
PTDI_BUCKET Bucket;
@@ -200,13 +201,13 @@
{
DbgPrint("[IP, TCPAcceptEventHandler] newpcb->state = %s,
listen_pcb->state = %s, newpcb = 0x%x\n",
tcp_state_str[newpcb->state],
- tcp_state_str[((struct
tcp_pcb*)Connection->SocketContext)->state],
+ tcp_state_str[((PTCP_PCB)Connection->SocketContext)->state],
newpcb);
LockObject(Bucket->AssociatedEndpoint, &OldIrql);
/* sanity assert...this should never be in anything else but a CLOSED state
*/
- ASSERT(((struct
tcp_pcb*)Bucket->AssociatedEndpoint->SocketContext)->state == CLOSED);
+ ASSERT( ((PTCP_PCB)Bucket->AssociatedEndpoint->SocketContext)->state
== CLOSED );
/* free socket context created in FileOpenConnection, as we're using a
new one */
LibTCPClose(Bucket->AssociatedEndpoint, TRUE);
@@ -233,7 +234,7 @@
VOID
TCPSendEventHandler(void *arg, u16_t space)
{
- PCONNECTION_ENDPOINT Connection = arg;
+ PCONNECTION_ENDPOINT Connection = (PCONNECTION_ENDPOINT)arg;
PTDI_BUCKET Bucket;
PLIST_ENTRY Entry;
PIRP Irp;
Modified: branches/GSoC_2011/TcpIpDriver/lib/drivers/ip/transport/tcp/tcp.c
URL:
http://svn.reactos.org/svn/reactos/branches/GSoC_2011/TcpIpDriver/lib/drive…
==============================================================================
--- branches/GSoC_2011/TcpIpDriver/lib/drivers/ip/transport/tcp/tcp.c [iso-8859-1]
(original)
+++ branches/GSoC_2011/TcpIpDriver/lib/drivers/ip/transport/tcp/tcp.c [iso-8859-1] Mon Aug
1 20:10:55 2011
@@ -105,8 +105,7 @@
return Status;
}
-NTSTATUS TCPClose
-( PCONNECTION_ENDPOINT Connection )
+NTSTATUS TCPClose( PCONNECTION_ENDPOINT Connection )
{
KIRQL OldIrql;
PVOID Socket;
@@ -116,7 +115,6 @@
DbgPrint("[IP, TCPClose] Called for Connection( 0x%x )->SocketConext( 0x%x
)\n", Connection, Connection->SocketContext);
Socket = Connection->SocketContext;
- //Connection->SocketContext = NULL;
/* We should not be associated to an address file at this point */
ASSERT(!Connection->AddressFile);
@@ -131,7 +129,7 @@
LibTCPClose(Connection, FALSE);
}
- DbgPrint("[IP, TCPClose] Leaving. Connection->RefCount = %d\n",
Connection->RefCount);
+ DbgPrint("[IP, TCPClose] Leaving\n");
UnlockObject(Connection, OldIrql);
@@ -170,7 +168,7 @@
NTSTATUS Status;
Status = PortsStartup( &TCPPorts, 1, 0xfffe );
- if( !NT_SUCCESS(Status) )
+ if (!NT_SUCCESS(Status))
{
return Status;
}
@@ -209,7 +207,7 @@
return STATUS_SUCCESS;
}
-NTSTATUS TCPTranslateError( err_t err )
+NTSTATUS TCPTranslateError(const err_t err)
{
NTSTATUS Status;
@@ -328,7 +326,7 @@
connaddr.addr = RemoteAddress.Address.IPv4Address;
Bucket = ExAllocatePoolWithTag( NonPagedPool, sizeof(*Bucket), TDI_BUCKET_TAG
);
- if( !Bucket )
+ if (!Bucket)
{
UnlockObject(Connection, OldIrql);
return STATUS_NO_MEMORY;
@@ -427,7 +425,7 @@
LockObject(Connection, &OldIrql);
/* Freed in TCPSocketState */
- Bucket = ExAllocatePoolWithTag( NonPagedPool, sizeof(*Bucket), TDI_BUCKET_TAG );
+ Bucket = ExAllocatePoolWithTag(NonPagedPool, sizeof(*Bucket), TDI_BUCKET_TAG);
if (!Bucket)
{
TI_DbgPrint(DEBUG_TCP,("[IP, TCPReceiveData] Failed to allocate
bucket\n"));
@@ -492,11 +490,11 @@
TI_DbgPrint(DEBUG_TCP,("[IP, TCPSendData] Send: %x, %d\n", Status,
SendLength));
/* Keep this request around ... there was no data yet */
- if( Status == STATUS_PENDING )
+ if (Status == STATUS_PENDING)
{
/* Freed in TCPSocketState */
Bucket = ExAllocatePoolWithTag( NonPagedPool, sizeof(*Bucket), TDI_BUCKET_TAG );
- if( !Bucket )
+ if (!Bucket)
{
UnlockObject(Connection, OldIrql);
TI_DbgPrint(DEBUG_TCP,("[IP, TCPSendData] Failed to allocate
bucket\n"));
@@ -526,16 +524,15 @@
return Status;
}
-UINT TCPAllocatePort( UINT HintPort )
-{
- if( HintPort )
- {
- if( AllocatePort( &TCPPorts, HintPort ) )
+UINT TCPAllocatePort(const UINT HintPort)
+{
+ if (HintPort)
+ {
+ if (AllocatePort(&TCPPorts, HintPort))
return HintPort;
else
{
- TI_DbgPrint
- (MID_TRACE,("We got a hint port but couldn't allocate
it\n"));
+ TI_DbgPrint(MID_TRACE,("We got a hint port but couldn't allocate
it\n"));
return (UINT)-1;
}
}
@@ -543,9 +540,9 @@
return AllocatePortFromRange( &TCPPorts, 1024, 5000 );
}
-VOID TCPFreePort( UINT Port )
-{
- DeallocatePort( &TCPPorts, Port );
+VOID TCPFreePort(const UINT Port)
+{
+ DeallocatePort(&TCPPorts, Port);
}
NTSTATUS TCPGetSockAddress
Modified: branches/GSoC_2011/TcpIpDriver/lib/drivers/lwip/src/core/tcp_in.c
URL:
http://svn.reactos.org/svn/reactos/branches/GSoC_2011/TcpIpDriver/lib/drive…
==============================================================================
--- branches/GSoC_2011/TcpIpDriver/lib/drivers/lwip/src/core/tcp_in.c [iso-8859-1]
(original)
+++ branches/GSoC_2011/TcpIpDriver/lib/drivers/lwip/src/core/tcp_in.c [iso-8859-1] Mon Aug
1 20:10:55 2011
@@ -78,6 +78,20 @@
static err_t tcp_listen_input(struct tcp_pcb_listen *pcb);
static err_t tcp_timewait_input(struct tcp_pcb *pcb);
+
+static const char * const tcp_state_str[] = {
+ "CLOSED",
+ "LISTEN",
+ "SYN_SENT",
+ "SYN_RCVD",
+ "ESTABLISHED",
+ "FIN_WAIT_1",
+ "FIN_WAIT_2",
+ "CLOSE_WAIT",
+ "CLOSING",
+ "LAST_ACK",
+ "TIME_WAIT"
+};
/**
* The initial input processing of TCP. It verifies the TCP header, demultiplexes
@@ -325,12 +339,14 @@
end. We then call the error callback to inform the
application that the connection is dead before we
deallocate the PCB. */
+ DbgPrint("tcp_input: removing pcb = 0x%x in state %s with
TF_RESET\n", pcb, tcp_state_str[pcb->state]);
TCP_EVENT_ERR(pcb->errf, pcb->callback_arg, ERR_RST);
tcp_pcb_remove(&tcp_active_pcbs, pcb);
memp_free(MEMP_TCP_PCB, pcb);
} else if (recv_flags & TF_CLOSED) {
/* The connection has been closed and we will deallocate the
PCB. */
+ DbgPrint("tcp_input: removing pcb = 0x%x with TF_CLOSED\n", pcb);
tcp_pcb_remove(&tcp_active_pcbs, pcb);
memp_free(MEMP_TCP_PCB, pcb);
} else {
@@ -422,6 +438,7 @@
pbuf_free(p);
}
+ DbgPrint("tcp_input: done\n");
LWIP_ASSERT("tcp_input: tcp_pcbs_sane()", tcp_pcbs_sane());
PERF_STOP("tcp_input");
}
Modified: branches/GSoC_2011/TcpIpDriver/lib/drivers/lwip/src/include/rosip.h
URL:
http://svn.reactos.org/svn/reactos/branches/GSoC_2011/TcpIpDriver/lib/drive…
==============================================================================
--- branches/GSoC_2011/TcpIpDriver/lib/drivers/lwip/src/include/rosip.h [iso-8859-1]
(original)
+++ branches/GSoC_2011/TcpIpDriver/lib/drivers/lwip/src/include/rosip.h [iso-8859-1] Mon
Aug 1 20:10:55 2011
@@ -22,7 +22,7 @@
/* External TCP event handlers */
extern void TCPConnectEventHandler(void *arg, const err_t err);
-extern void TCPAcceptEventHandler(void *arg, struct tcp_pcb *newpcb);
+extern void TCPAcceptEventHandler(void *arg, PTCP_PCB newpcb);
extern void TCPSendEventHandler(void *arg, const u16_t space);
extern void TCPFinEventHandler(void *arg, const err_t err);
extern u32_t TCPRecvEventHandler(void *arg, struct pbuf *p);
Modified: branches/GSoC_2011/TcpIpDriver/lib/drivers/lwip/src/rosip.c
URL:
http://svn.reactos.org/svn/reactos/branches/GSoC_2011/TcpIpDriver/lib/drive…
==============================================================================
--- branches/GSoC_2011/TcpIpDriver/lib/drivers/lwip/src/rosip.c [iso-8859-1] (original)
+++ branches/GSoC_2011/TcpIpDriver/lib/drivers/lwip/src/rosip.c [iso-8859-1] Mon Aug 1
20:10:55 2011
@@ -4,6 +4,8 @@
#include "rosip.h"
#include <debug.h>
+
+typedef struct netif* PNETIF;
void
LibIPInsertPacket(void *ifarg,
@@ -26,9 +28,7 @@
RtlCopyMemory(p1->payload, ((PUCHAR)data) + i, p1->len);
}
- DbgPrint("LibIPInsertPacket: called 0x%x\n", *((struct netif
*)ifarg)->input);
-
- ((struct netif *)ifarg)->input(p, ifarg);
+ ((PNETIF)ifarg)->input(p, (PNETIF)ifarg);
}
}
Modified: branches/GSoC_2011/TcpIpDriver/lib/drivers/lwip/src/rosmem.c
URL:
http://svn.reactos.org/svn/reactos/branches/GSoC_2011/TcpIpDriver/lib/drive…
==============================================================================
--- branches/GSoC_2011/TcpIpDriver/lib/drivers/lwip/src/rosmem.c [iso-8859-1] (original)
+++ branches/GSoC_2011/TcpIpDriver/lib/drivers/lwip/src/rosmem.c [iso-8859-1] Mon Aug 1
20:10:55 2011
@@ -1,10 +1,11 @@
-
#include "lwip/opt.h"
#include "lwip/def.h"
#include "lwip/mem.h"
-#define LWIP_TAG 'PIwl'
+#ifndef LWIP_TAG
+ #define LWIP_TAG 'PIwl'
+#endif
void *
malloc(mem_size_t size)
@@ -27,6 +28,7 @@
void
free(void *mem)
{
+ //DbgPrint("ROSMEM: free 0x%x\n", mem);
ExFreePoolWithTag(mem, LWIP_TAG);
}
Modified: branches/GSoC_2011/TcpIpDriver/lib/drivers/lwip/src/rostcp.c
URL:
http://svn.reactos.org/svn/reactos/branches/GSoC_2011/TcpIpDriver/lib/drive…
==============================================================================
--- branches/GSoC_2011/TcpIpDriver/lib/drivers/lwip/src/rostcp.c [iso-8859-1] (original)
+++ branches/GSoC_2011/TcpIpDriver/lib/drivers/lwip/src/rostcp.c [iso-8859-1] Mon Aug 1
20:10:55 2011
@@ -45,8 +45,7 @@
Entry = RemoveHeadList(&Connection->PacketQueue);
qp = CONTAINING_RECORD(Entry, QUEUE_ENTRY, ListEntry);
-
- // reenable this later
+
pbuf_free(qp->p);
ExFreePoolWithTag(qp, LWIP_TAG);
@@ -772,7 +771,7 @@
{
tcp_arg(pcb, NULL);
/*
- if this pcb is not in LISTEN state than it has
+ if this pcb is not in LISTEN state then it has
valid recv, send and err callbacks to cancel
*/
if (pcb->state != LISTEN)
@@ -796,8 +795,6 @@
if (!msg->Connection->SocketContext)
{
DbgPrint("[lwIP, LibTCPCloseCallback] NULL pcb...bail, bail!!!\n");
-
- //ASSERT(FALSE);
msg->Error = ERR_OK;
return;