return FALSE;
}
+PADDRESS_FILE AddrFindShared(
+ PIP_ADDRESS BindAddress,
+ USHORT Port,
+ USHORT Protocol)
+{
+ PLIST_ENTRY CurrentEntry;
+ KIRQL OldIrql;
+ PADDRESS_FILE Current = NULL;
+
+ TcpipAcquireSpinLock(&AddressFileListLock, &OldIrql);
+
+ CurrentEntry = AddressFileListHead.Flink;
+ while (CurrentEntry != &AddressFileListHead) {
+ Current = CONTAINING_RECORD(CurrentEntry, ADDRESS_FILE, ListEntry);
+
+ /* See if this address matches the search criteria */
+ if ((Current->Port == Port) &&
+ (Current->Protocol == Protocol))
+ {
+ /* Increase the sharer count */
+ ASSERT(Current->Sharers != 0);
+ InterlockedIncrement(&Current->Sharers);
+ break;
+ }
+
+ CurrentEntry = CurrentEntry->Flink;
+ Current = NULL;
+ }
+
+ TcpipReleaseSpinLock(&AddressFileListLock, OldIrql);
+
+ return Current;
+}
+
/*
* FUNCTION: Searches through address file entries to find next match
* ARGUMENTS:
* Request = Pointer to TDI request structure for this request
* Address = Pointer to address to be opened
* Protocol = Protocol on which to open the address
+ * Shared = Specifies if the address is opened for shared access
* Options = Pointer to option buffer
* RETURNS:
* Status of operation
PTDI_REQUEST Request,
PTA_IP_ADDRESS Address,
USHORT Protocol,
+ BOOLEAN Shared,
PVOID Options)
{
PADDRESS_FILE AddrFile;
TI_DbgPrint(MID_TRACE, ("Called (Proto %d).\n", Protocol));
+ /* If it's shared and has a port specified, look for a match */
+ if ((Shared != FALSE) && (Address->Address[0].Address[0].sin_port != 0))
+ {
+ AddrFile = AddrFindShared(NULL, Address->Address[0].Address[0].sin_port, Protocol);
+ if (AddrFile != NULL)
+ {
+ Request->Handle.AddressHandle = AddrFile;
+ return STATUS_SUCCESS;
+ }
+ }
+
AddrFile = ExAllocatePoolWithTag(NonPagedPool, sizeof(ADDRESS_FILE),
ADDR_FILE_TAG);
if (!AddrFile) {
AddrFile->RefCount = 1;
AddrFile->Free = AddrFileFree;
+ AddrFile->Sharers = 1;
/* Set our default options */
AddrFile->TTL = 128;
LockObject(AddrFile, &OldIrql);
+ if (InterlockedDecrement(&AddrFile->Sharers) != 0)
+ {
+ /* Still other guys have open handles to this, so keep it around */
+ UnlockObject(AddrFile, OldIrql);
+ return STATUS_SUCCESS;
+ }
+
/* We have to close this listener because we started it */
if( AddrFile->Listener )
{
PVOID ClientContext;
NTSTATUS Status;
ULONG Protocol;
+ BOOLEAN Shared;
TI_DbgPrint(DEBUG_IRP, ("Called. DeviceObject is at (0x%X), IRP is at (0x%X).\n", DeviceObject, Irp));
return STATUS_INVALID_PARAMETER;
}
- Status = FileOpenAddress(&Request, Address, Protocol, NULL);
+ Shared = (IrpSp->Parameters.Create.ShareAccess != 0);
+
+ Status = FileOpenAddress(&Request, Address, Protocol, Shared, NULL);
if (NT_SUCCESS(Status))
{
IrpSp->FileObject->FsContext2 = (PVOID)TDI_TRANSPORT_ADDRESS_FILE;
LibTCPBindCallback(void *arg)
{
struct lwip_callback_msg *msg = arg;
+ PTCP_PCB pcb = msg->Input.Bind.Connection->SocketContext;
ASSERT(msg);
goto done;
}
- msg->Output.Bind.Error = tcp_bind((PTCP_PCB)msg->Input.Bind.Connection->SocketContext,
+ /* If this address file is shared, set the SOF_REUSEADDR flag in the PCB */
+ ASSERT(msg->Input.Bind.Connection->AddressFile != NULL);
+ if (msg->Input.Bind.Connection->AddressFile->Sharers != 1)
+ {
+ pcb->so_options |= SOF_REUSEADDR;
+ }
+
+ msg->Output.Bind.Error = tcp_bind(pcb,
msg->Input.Bind.IpAddress,
ntohs(msg->Input.Bind.Port));