Author: cmihail
Date: Mon Jun 20 21:37:32 2011
New Revision: 52395
URL:
http://svn.reactos.org/svn/reactos?rev=52395&view=rev
Log:
[lwIP]
- Abort the connection if the socket is not in LISTEN state, instead of closing it
[TCPIP]
- move redundant socket closure where so we don't try to free uninitialized variable
- in case our socket got closed or for some reason doesn't exist return a default
success
Modified:
branches/GSoC_2011/TcpIpDriver/drivers/network/afd/afd/connect.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/rostcp.c
Modified: branches/GSoC_2011/TcpIpDriver/drivers/network/afd/afd/connect.c
URL:
http://svn.reactos.org/svn/reactos/branches/GSoC_2011/TcpIpDriver/drivers/n…
==============================================================================
--- branches/GSoC_2011/TcpIpDriver/drivers/network/afd/afd/connect.c [iso-8859-1]
(original)
+++ branches/GSoC_2011/TcpIpDriver/drivers/network/afd/afd/connect.c [iso-8859-1] Mon Jun
20 21:37:32 2011
@@ -281,7 +281,7 @@
AFD_DbgPrint(MID_TRACE,("Called: FCB %x, FO %x\n",
Context, FCB->FileObject));
- DbgPrint("[StreamSocketConnectComplete] Called: FCB %x, FO %x\n",
+ DbgPrint("[AFD, StreamSocketConnectComplete] Called: FCB 0x%x, FO 0x%x\n",
Context, FCB->FileObject);
/* I was wrong about this before as we can have pending writes to a not
@@ -333,7 +333,7 @@
NextIrp = CONTAINING_RECORD(NextIrpEntry, IRP, Tail.Overlay.ListEntry);
AFD_DbgPrint(MID_TRACE,("Completing connect %x\n", NextIrp));
- DbgPrint("[StreamSocketConnectComplete] Completing connect %x\n",
NextIrp);
+ DbgPrint("[AFD, StreamSocketConnectComplete] Completing connect
0x%x\n", NextIrp);
NextIrp->IoStatus.Status = Status;
NextIrp->IoStatus.Information = NT_SUCCESS(Status) ?
((ULONG_PTR)FCB->Connection.Handle) : 0;
@@ -410,7 +410,7 @@
0 );
AFD_DbgPrint(MID_TRACE,("Connect request:\n"));
- DbgPrint("[AfdStreamSocketConnect] Connect request:\n");
+ DbgPrint("[AFD, AfdStreamSocketConnect] Connect request:\n");
#if 0
OskitDumpBuffer
( (PCHAR)ConnectReq,
@@ -420,8 +420,7 @@
if( FCB->Flags & AFD_ENDPOINT_CONNECTIONLESS )
{
if( FCB->RemoteAddress ) ExFreePool( FCB->RemoteAddress );
- FCB->RemoteAddress =
- TaCopyTransportAddress( &ConnectReq->RemoteAddress );
+ FCB->RemoteAddress = TaCopyTransportAddress(
&ConnectReq->RemoteAddress );
if( !FCB->RemoteAddress )
Status = STATUS_NO_MEMORY;
@@ -440,10 +439,10 @@
case SOCKET_STATE_CONNECTING:
return LeaveIrpUntilLater( FCB, Irp, FUNCTION_CONNECT );
- case SOCKET_STATE_CREATED:
- if( FCB->LocalAddress ) ExFreePool( FCB->LocalAddress );
- FCB->LocalAddress =
- TaBuildNullTransportAddress( ConnectReq->RemoteAddress.Address[0].AddressType );
+ case SOCKET_STATE_CREATED:
+ if( FCB->LocalAddress ) ExFreePool( FCB->LocalAddress );
+ FCB->LocalAddress = TaBuildNullTransportAddress(
+ ConnectReq->RemoteAddress.Address[0].AddressType);
if( FCB->LocalAddress )
{
@@ -460,9 +459,10 @@
/* Drop through to SOCKET_STATE_BOUND */
case SOCKET_STATE_BOUND:
- if( FCB->RemoteAddress ) ExFreePool( FCB->RemoteAddress );
- FCB->RemoteAddress =
- TaCopyTransportAddress( &ConnectReq->RemoteAddress );
+ if( FCB->RemoteAddress )
+ ExFreePool( FCB->RemoteAddress );
+
+ FCB->RemoteAddress = TaCopyTransportAddress(
&ConnectReq->RemoteAddress );
if( !FCB->RemoteAddress )
{
@@ -475,13 +475,10 @@
if( !NT_SUCCESS(Status) )
break;
- Status = TdiBuildConnectionInfo
- ( &FCB->ConnectInfo,
- &ConnectReq->RemoteAddress );
+ Status = TdiBuildConnectionInfo(&FCB->ConnectInfo,
&ConnectReq->RemoteAddress);
if( NT_SUCCESS(Status) )
- Status = TdiBuildConnectionInfo(&TargetAddress,
- &ConnectReq->RemoteAddress);
+ Status = TdiBuildConnectionInfo(&TargetAddress,
&ConnectReq->RemoteAddress);
else break;
if( NT_SUCCESS(Status) )
@@ -502,7 +499,7 @@
ExFreePool(TargetAddress);
AFD_DbgPrint(MID_TRACE,("Queueing IRP %x\n", Irp));
- DbgPrint("[AfdStreamSocketConnect] Queueing IRP %x\n", Irp);
+ DbgPrint("[AFD, AfdStreamSocketConnect] Queueing IRP %x\n",
Irp);
if( Status == STATUS_PENDING )
{
@@ -515,7 +512,7 @@
default:
AFD_DbgPrint(MID_TRACE,("Inappropriate socket state %d for
connect\n",
FCB->State));
- DbgPrint("[AfdStreamSocketConnect] Inappropriate socket state %d for
connect\n",
+ DbgPrint("[AFD, AfdStreamSocketConnect] Inappropriate socket state %d
for connect\n",
FCB->State);
break;
}
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
Jun 20 21:37:32 2011
@@ -202,6 +202,10 @@
DbgPrint("[IP, TCPAcceptEventHandler] Trying to unlock
Bucket->AssociatedEndpoint\n");
UnlockObject(Bucket->AssociatedEndpoint, OldIrql);
+
+ /* free socket context created in FileOpenConnection, as we're using a
new
+ one; we free it asynchornously because otherwise we create a dedlock */
+ ChewCreate(SocketContextCloseWorker, OldSocketContext);
}
DereferenceObject(Bucket->AssociatedEndpoint);
@@ -212,10 +216,6 @@
}
DereferenceObject(Connection);
-
- /* free socket context created in FileOpenConnection, as we're using a new
- one; we free it asynchornously because otherwise we create a dedlock */
- ChewCreate(SocketContextCloseWorker, OldSocketContext);
}
VOID
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 Jun
20 21:37:32 2011
@@ -347,14 +347,23 @@
LockObject(Connection, &OldIrql);
- if (Flags & TDI_DISCONNECT_RELEASE)
- {
- Status = LibTCPShutdown(Connection->SocketContext, 0, 1);
- }
-
- if ((Flags & TDI_DISCONNECT_ABORT) || !Flags)
- {
- Status = LibTCPShutdown(Connection->SocketContext, 1, 1);
+ if (Connection->SocketContext)
+ {
+ if (Flags & TDI_DISCONNECT_RELEASE)
+ {
+ Status = TCPTranslateError(LibTCPShutdown(Connection->SocketContext, 0,
1));
+ }
+
+ if ((Flags & TDI_DISCONNECT_ABORT) || !Flags)
+ {
+ Status = TCPTranslateError(LibTCPShutdown(Connection->SocketContext, 1,
1));
+ }
+ }
+ else
+ {
+ /* We already got closed by the other side so just return success */
+ DbgPrint("[IP, TCPDisconnect] Socket was alraedy clsoed on the other
side\n");
+ Status = STATUS_SUCCESS;
}
DbgPrint("LibTCPShutdown: %x\n", Status);
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 Jun 20
21:37:32 2011
@@ -612,7 +612,17 @@
{
struct close_callback_msg *msg = arg;
- msg->Error = tcp_close(msg->Pcb);
+ if (msg->Pcb->state == LISTEN)
+ {
+ DbgPrint("[lwIP, LibTCPCloseCallback] Closing a listener\n");
+ msg->Error = tcp_close(msg->Pcb);
+ }
+ else
+ {
+ DbgPrint("[lwIP, LibTCPCloseCallback] Aborting a connection\n");
+ tcp_abort(msg->Pcb);
+ msg->Error = ERR_OK;
+ }
KeSetEvent(&msg->Event, IO_NO_INCREMENT, FALSE);
}