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,
TCPUpdateInterfaceIPInformation(PIP_INTERFACE IF);
VOID
-FlushAllQueues(PCONNECTION_ENDPOINT Connection, NTSTATUS Status);
+FlushAllQueues(PCONNECTION_ENDPOINT Connection, const NTSTATUS Status);
PTRANSPORT_CONTEXT TranContext;
PFILE_OBJECT FileObject;
UCHAR MinorFunction;
+ PCONNECTION_ENDPOINT Connection;
BOOLEAN DequeuedIrp = TRUE;
IoReleaseCancelSpinLock(Irp->CancelIrql);
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:
ExFreePoolWithTag(Bucket, TDI_BUCKET_TAG);
}
+static
VOID
-CompleteBucket(PCONNECTION_ENDPOINT Connection, PTDI_BUCKET Bucket, BOOLEAN Synchronous)
+CompleteBucket(PCONNECTION_ENDPOINT Connection, PTDI_BUCKET Bucket, const BOOLEAN Synchronous)
{
ReferenceObject(Connection);
Bucket->AssociatedEndpoint = Connection;
}
VOID
-FlushAllQueues(PCONNECTION_ENDPOINT Connection, NTSTATUS Status)
+FlushAllQueues(PCONNECTION_ENDPOINT Connection, const NTSTATUS Status)
{
PTDI_BUCKET Bucket;
PLIST_ENTRY Entry;
}
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);
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);
}
VOID
-TCPAcceptEventHandler(void *arg, struct tcp_pcb *newpcb)
+TCPAcceptEventHandler(void *arg, PTCP_PCB newpcb)
{
PCONNECTION_ENDPOINT Connection = (PCONNECTION_ENDPOINT)arg;
PTDI_BUCKET Bucket;
{
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);
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;
return Status;
}
-NTSTATUS TCPClose
-( PCONNECTION_ENDPOINT Connection )
+NTSTATUS TCPClose( PCONNECTION_ENDPOINT Connection )
{
KIRQL OldIrql;
PVOID Socket;
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);
LibTCPClose(Connection, FALSE);
}
- DbgPrint("[IP, TCPClose] Leaving. Connection->RefCount = %d\n", Connection->RefCount);
+ DbgPrint("[IP, TCPClose] Leaving\n");
UnlockObject(Connection, OldIrql);
NTSTATUS Status;
Status = PortsStartup( &TCPPorts, 1, 0xfffe );
- if( !NT_SUCCESS(Status) )
+ if (!NT_SUCCESS(Status))
{
return Status;
}
return STATUS_SUCCESS;
}
-NTSTATUS TCPTranslateError( err_t err )
+NTSTATUS TCPTranslateError(const err_t err)
{
NTSTATUS Status;
connaddr.addr = RemoteAddress.Address.IPv4Address;
Bucket = ExAllocatePoolWithTag( NonPagedPool, sizeof(*Bucket), TDI_BUCKET_TAG );
- if( !Bucket )
+ if (!Bucket)
{
UnlockObject(Connection, OldIrql);
return STATUS_NO_MEMORY;
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"));
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"));
return Status;
}
-UINT TCPAllocatePort( UINT HintPort )
+UINT TCPAllocatePort(const UINT HintPort)
{
- if( HintPort )
+ if (HintPort)
{
- if( AllocatePort( &TCPPorts, 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;
}
}
return AllocatePortFromRange( &TCPPorts, 1024, 5000 );
}
-VOID TCPFreePort( UINT Port )
+VOID TCPFreePort(const UINT Port)
{
- DeallocatePort( &TCPPorts, Port );
+ DeallocatePort(&TCPPorts, Port);
}
NTSTATUS TCPGetSockAddress
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
* the segment between the PCBs and passes it on to tcp_process(), which implements
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 {
pbuf_free(p);
}
+ DbgPrint("tcp_input: done\n");
LWIP_ASSERT("tcp_input: tcp_pcbs_sane()", tcp_pcbs_sane());
PERF_STOP("tcp_input");
}
/* 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);
#include <debug.h>
+typedef struct netif* PNETIF;
+
void
LibIPInsertPacket(void *ifarg,
const void *const data,
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);
}
}
-
#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)
void
free(void *mem)
{
+ //DbgPrint("ROSMEM: free 0x%x\n", mem);
ExFreePoolWithTag(mem, LWIP_TAG);
}
Entry = RemoveHeadList(&Connection->PacketQueue);
qp = CONTAINING_RECORD(Entry, QUEUE_ENTRY, ListEntry);
-
- // reenable this later
+
pbuf_free(qp->p);
ExFreePoolWithTag(qp, LWIP_TAG);
{
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)
if (!msg->Connection->SocketContext)
{
DbgPrint("[lwIP, LibTCPCloseCallback] NULL pcb...bail, bail!!!\n");
-
- //ASSERT(FALSE);
msg->Error = ERR_OK;
return;