Added afd/tdiconn.c with corrections by filip navara

afd/dispatch.c fixed ptr arith + bug fix by filip
afd/tdi.c removed functions dealing with TDI_CONNECTION_INFORMATION (tdiconn)
tcpip fixes by filip

svn path=/trunk/; revision=8072
This commit is contained in:
Art Yerkes 2004-02-07 04:50:44 +00:00
parent 03aba39688
commit 24fecbb518
8 changed files with 385 additions and 294 deletions

View file

@ -211,6 +211,7 @@ NTSTATUS AfdDispListen(
{ {
AFD_DbgPrint(MIN_TRACE, ("FIXME: Status (0x%X).\n", Status)); AFD_DbgPrint(MIN_TRACE, ("FIXME: Status (0x%X).\n", Status));
} }
Status = STATUS_SUCCESS;
} }
else else
{ {
@ -311,7 +312,7 @@ NTSTATUS AfdDispSendTo(
/* FIXME: Should we handle special cases here? */ /* FIXME: Should we handle special cases here? */
if ((FCB->SocketType == SOCK_RAW) && (FCB->AddressFamily == AF_INET)) { if ((FCB->SocketType == SOCK_RAW) && (FCB->AddressFamily == AF_INET)) {
DataBufferAddress = SystemVirtualAddress + sizeof(IPv4_HEADER); DataBufferAddress = ((PCHAR)SystemVirtualAddress) + sizeof(IPv4_HEADER);
/* FIXME: Should TCP/IP driver assign source address for raw sockets? */ /* FIXME: Should TCP/IP driver assign source address for raw sockets? */
((PSOCKADDR_IN)&FCB->SocketName)->sin_addr.S_un.S_addr = 0x0100007F; ((PSOCKADDR_IN)&FCB->SocketName)->sin_addr.S_un.S_addr = 0x0100007F;

View file

@ -8,6 +8,7 @@
* CSH 01/09-2000 Created * CSH 01/09-2000 Created
*/ */
#include <afd.h> #include <afd.h>
#include "tdiconn.h"
#ifdef DBG #ifdef DBG
VOID DisplayBuffer( VOID DisplayBuffer(
@ -37,205 +38,6 @@ VOID DisplayBuffer(
} }
#endif /* DBG */ #endif /* DBG */
inline DWORD TdiAddressSizeFromType(
ULONG Type)
/*
* FUNCTION: Returns the size of a TDI style address of given address type
* ARGUMENTS:
* Type = TDI style address type
* RETURNS:
* Size of TDI style address, 0 if Type is not valid
*/
{
switch (Type) {
case TDI_ADDRESS_TYPE_IP:
return sizeof(TA_IP_ADDRESS);
/* FIXME: More to come */
}
AFD_DbgPrint(MIN_TRACE, ("Unknown TDI address type (%d).\n", Type));
return 0;
}
inline DWORD TdiAddressSizeFromName(
LPSOCKADDR Name)
/*
* FUNCTION: Returns the size of a TDI style address equivalent to a
* WinSock style name
* ARGUMENTS:
* Name = WinSock style name
* RETURNS:
* Size of TDI style address, 0 if Name is not valid
*/
{
switch (Name->sa_family) {
case AF_INET:
return sizeof(TA_IP_ADDRESS);
/* FIXME: More to come */
}
AFD_DbgPrint(MIN_TRACE, ("Unknown address family (%d).\n", Name->sa_family));
return 0;
}
VOID TdiBuildAddressIPv4(
PTA_IP_ADDRESS Address,
LPSOCKADDR Name)
/*
* FUNCTION: Builds an IPv4 TDI style address
* ARGUMENTS:
* Address = Address of buffer to place TDI style IPv4 address
* Name = Pointer to WinSock style IPv4 name
*/
{
Address->TAAddressCount = 1;
Address->Address[0].AddressLength = TDI_ADDRESS_LENGTH_IP;
Address->Address[0].AddressType = TDI_ADDRESS_TYPE_IP;
Address->Address[0].Address[0].sin_port = ((LPSOCKADDR_IN)Name)->sin_port;
Address->Address[0].Address[0].in_addr = ((LPSOCKADDR_IN)Name)->sin_addr.S_un.S_addr;
}
NTSTATUS TdiBuildAddress(
PTA_ADDRESS Address,
LPSOCKADDR Name)
/*
* FUNCTION: Builds a TDI style address
* ARGUMENTS:
* Address = Address of buffer to place TDI style address
* Name = Pointer to WinSock style name
* RETURNS:
* Status of operation
*/
{
NTSTATUS Status = STATUS_SUCCESS;
switch (Name->sa_family) {
case AF_INET:
TdiBuildAddressIPv4((PTA_IP_ADDRESS)Address, Name);
break;
/* FIXME: More to come */
default:
AFD_DbgPrint(MID_TRACE, ("Unknown address family (%d).\n", Name->sa_family));
Status = STATUS_INVALID_PARAMETER;
}
return Status;
}
NTSTATUS TdiBuildName(
LPSOCKADDR Name,
PTA_ADDRESS Address)
/*
* FUNCTION: Builds a WinSock style address
* ARGUMENTS:
* Name = Address of buffer to place WinSock style name
* Address = Pointer to TDI style address
* RETURNS:
* Status of operation
*/
{
NTSTATUS Status = STATUS_SUCCESS;
switch (Address->AddressType) {
case TDI_ADDRESS_TYPE_IP:
Name->sa_family = AF_INET;
((LPSOCKADDR_IN)Name)->sin_port =
((PTDI_ADDRESS_IP)&Address->Address[0])->sin_port;
((LPSOCKADDR_IN)Name)->sin_addr.S_un.S_addr =
((PTDI_ADDRESS_IP)&Address->Address[0])->in_addr;
break;
/* FIXME: More to come */
default:
AFD_DbgPrint(MID_TRACE, ("Unknown TDI address type (%d).\n", Address->AddressType));
Status = STATUS_INVALID_PARAMETER;
}
return Status;
}
NTSTATUS TdiBuildConnectionInfo(
PTDI_CONNECTION_INFORMATION *ConnectionInfo,
LPSOCKADDR Name)
/*
* FUNCTION: Builds a TDI connection information structure
* ARGUMENTS:
* ConnectionInfo = Address of buffer to place connection information
* Name = Pointer to WinSock style name
* RETURNS:
* Status of operation
*/
{
PTDI_CONNECTION_INFORMATION ConnInfo;
ULONG TdiAddressSize;
TdiAddressSize = TdiAddressSizeFromName(Name);
ConnInfo = (PTDI_CONNECTION_INFORMATION)
ExAllocatePool(NonPagedPool,
sizeof(TDI_CONNECTION_INFORMATION) +
TdiAddressSize);
if (!ConnInfo)
return STATUS_INSUFFICIENT_RESOURCES;
RtlZeroMemory(ConnInfo,
sizeof(TDI_CONNECTION_INFORMATION) +
TdiAddressSize);
ConnInfo->OptionsLength = sizeof(ULONG);
ConnInfo->RemoteAddressLength = TdiAddressSize;
ConnInfo->RemoteAddress = (PVOID)
(ConnInfo + sizeof(TDI_CONNECTION_INFORMATION));
TdiBuildAddress(ConnInfo->RemoteAddress, Name);
*ConnectionInfo = ConnInfo;
return STATUS_SUCCESS;
}
NTSTATUS TdiBuildNullConnectionInfo(
PTDI_CONNECTION_INFORMATION *ConnectionInfo,
ULONG Type)
/*
* FUNCTION: Builds a NULL TDI connection information structure
* ARGUMENTS:
* ConnectionInfo = Address of buffer to place connection information
* Type = TDI style address type (TDI_ADDRESS_TYPE_XXX).
* RETURNS:
* Status of operation
*/
{
PTDI_CONNECTION_INFORMATION ConnInfo;
ULONG TdiAddressSize;
TdiAddressSize = TdiAddressSizeFromType(Type);
ConnInfo = (PTDI_CONNECTION_INFORMATION)
ExAllocatePool(NonPagedPool,
sizeof(TDI_CONNECTION_INFORMATION) +
TdiAddressSize);
if (!ConnInfo)
return STATUS_INSUFFICIENT_RESOURCES;
RtlZeroMemory(ConnInfo,
sizeof(TDI_CONNECTION_INFORMATION) +
TdiAddressSize);
ConnInfo->OptionsLength = sizeof(ULONG);
ConnInfo->RemoteAddressLength = 0;
ConnInfo->RemoteAddress = NULL;
*ConnectionInfo = ConnInfo;
return STATUS_SUCCESS;
}
NTSTATUS TdiCall( NTSTATUS TdiCall(
PIRP Irp, PIRP Irp,
PDEVICE_OBJECT DeviceObject, PDEVICE_OBJECT DeviceObject,
@ -520,7 +322,8 @@ NTSTATUS TdiConnect(
DeviceObject = IoGetRelatedDeviceObject(ConnectionObject); DeviceObject = IoGetRelatedDeviceObject(ConnectionObject);
Status = TdiBuildConnectionInfo(&RequestConnectionInfo, RemoteAddress); Status = TdiBuildConnectionInfo
(&RequestConnectionInfo, RemoteAddress);
if (!NT_SUCCESS(Status)) if (!NT_SUCCESS(Status))
return Status; return Status;
@ -937,7 +740,9 @@ NTSTATUS TdiQueryAddress(
if (SnmpInfo.NumAddr != 1) { if (SnmpInfo.NumAddr != 1) {
/* Skip loopback address */ /* Skip loopback address */
*Address = DN2H(((PIPADDR_ENTRY)((ULONG)IpAddress + sizeof(IPADDR_ENTRY)))->Addr); PIPADDR_ENTRY IpAddressEntry = (PIPADDR_ENTRY)
((PCHAR)IpAddress) + sizeof(IPADDR_ENTRY);
*Address = DN2H(IpAddressEntry->Addr);
} else { } else {
/* Select the first address returned */ /* Select the first address returned */
*Address = DN2H(IpAddress->Addr); *Address = DN2H(IpAddress->Addr);
@ -990,27 +795,9 @@ NTSTATUS TdiSend(
return STATUS_INVALID_PARAMETER; return STATUS_INVALID_PARAMETER;
} }
TdiAddressSize = TdiAddressSizeFromName(Address); Status = TdiBuildConnectionInfo( &ConnectInfo, Address );
if (!NT_SUCCESS(Status))
ConnectInfo = (PTDI_CONNECTION_INFORMATION) return STATUS_INSUFFICIENT_RESOURCES;
ExAllocatePool(NonPagedPool,
sizeof(TDI_CONNECTION_INFORMATION) +
TdiAddressSize);
if (!ConnectInfo) {
AFD_DbgPrint(MIN_TRACE, ("Insufficient resources.\n"));
return STATUS_INSUFFICIENT_RESOURCES;
}
RtlZeroMemory(ConnectInfo,
sizeof(TDI_CONNECTION_INFORMATION) +
TdiAddressSize);
ConnectInfo->RemoteAddressLength = TdiAddressSize;
ConnectInfo->RemoteAddress = (PVOID)
(ConnectInfo + sizeof(TDI_CONNECTION_INFORMATION));
TdiBuildAddress(ConnectInfo->RemoteAddress, Address);
KeInitializeEvent(&Event, NotificationEvent, FALSE); KeInitializeEvent(&Event, NotificationEvent, FALSE);
@ -1105,7 +892,6 @@ NTSTATUS TdiSendDatagram(
PTDI_CONNECTION_INFORMATION ConnectInfo; PTDI_CONNECTION_INFORMATION ConnectInfo;
PDEVICE_OBJECT DeviceObject; PDEVICE_OBJECT DeviceObject;
IO_STATUS_BLOCK Iosb; IO_STATUS_BLOCK Iosb;
DWORD TdiAddressSize;
NTSTATUS Status; NTSTATUS Status;
KEVENT Event; KEVENT Event;
PIRP Irp; PIRP Irp;
@ -1121,30 +907,7 @@ NTSTATUS TdiSendDatagram(
AFD_DbgPrint(MAX_TRACE, AFD_DbgPrint(MAX_TRACE,
("TdiSendDatagram: TansportObject = %08x\n", TransportObject)); ("TdiSendDatagram: TansportObject = %08x\n", TransportObject));
TdiAddressSize = TdiAddressSizeFromName(Address); TdiBuildConnectionInfo( &ConnectInfo, Address );
ConnectInfo = (PTDI_CONNECTION_INFORMATION)
ExAllocatePool(NonPagedPool,
sizeof(TDI_CONNECTION_INFORMATION) +
TdiAddressSize);
if (!ConnectInfo)
return STATUS_INSUFFICIENT_RESOURCES;
AFD_DbgPrint(MAX_TRACE,
("TdiAddressSize = %d, sizeof(TDI_CONNECTION_INFORMATION) = %d\n",
TdiAddressSize, sizeof(TDI_CONNECTION_INFORMATION)));
RtlZeroMemory(ConnectInfo,
sizeof(TDI_CONNECTION_INFORMATION) +
TdiAddressSize);
ConnectInfo->RemoteAddressLength = TdiAddressSize;
ConnectInfo->RemoteAddress = (PVOID)
(((PCHAR)ConnectInfo) + sizeof(TDI_CONNECTION_INFORMATION));
AFD_DbgPrint(MAX_TRACE, ("Point A\n"));
TdiBuildAddress(ConnectInfo->RemoteAddress, Address);
AFD_DbgPrint(MAX_TRACE, ("Point B\n")); AFD_DbgPrint(MAX_TRACE, ("Point B\n"));
@ -1240,7 +1003,6 @@ NTSTATUS TdiReceiveDatagram(
PTDI_CONNECTION_INFORMATION ReturnInfo; PTDI_CONNECTION_INFORMATION ReturnInfo;
PDEVICE_OBJECT DeviceObject; PDEVICE_OBJECT DeviceObject;
IO_STATUS_BLOCK Iosb; IO_STATUS_BLOCK Iosb;
DWORD TdiAddressSize;
NTSTATUS Status; NTSTATUS Status;
KEVENT Event; KEVENT Event;
PIRP Irp; PIRP Irp;
@ -1256,42 +1018,8 @@ NTSTATUS TdiReceiveDatagram(
return STATUS_INVALID_PARAMETER; return STATUS_INVALID_PARAMETER;
} }
/* FIXME: Get from socket information */ TdiBuildConnectionInfoPair( &ReceiveInfo, From, Address );
TdiAddressSize = sizeof(TA_IP_ADDRESS);
ReceiveInfo = (PTDI_CONNECTION_INFORMATION)
ExAllocatePool(NonPagedPool,
sizeof(TDI_CONNECTION_INFORMATION) +
sizeof(TDI_CONNECTION_INFORMATION) +
2 * TdiAddressSize);
if (!ReceiveInfo) {
AFD_DbgPrint(MIN_TRACE, ("Insufficient resources.\n"));
return STATUS_INSUFFICIENT_RESOURCES;
}
RtlZeroMemory(ReceiveInfo,
sizeof(TDI_CONNECTION_INFORMATION) +
sizeof(TDI_CONNECTION_INFORMATION) +
2 * TdiAddressSize);
if (From != NULL) {
ReceiveInfo->RemoteAddressLength = TdiAddressSize;
ReceiveInfo->RemoteAddress = (PVOID)
(ReceiveInfo + sizeof(TDI_CONNECTION_INFORMATION));
/* Filter datagrams */
TdiBuildAddress(ReceiveInfo->RemoteAddress, From);
} else {
/* Receive from any address */
ReceiveInfo->RemoteAddressLength = 0;
ReceiveInfo->RemoteAddress = NULL;
}
ReturnInfo = (PTDI_CONNECTION_INFORMATION)
(ReceiveInfo + sizeof(TDI_CONNECTION_INFORMATION) + TdiAddressSize);
ReturnInfo->RemoteAddressLength = TdiAddressSize;
ReturnInfo->RemoteAddress = (PVOID)
(ReturnInfo + sizeof(TDI_CONNECTION_INFORMATION));
KeInitializeEvent(&Event, NotificationEvent, FALSE); KeInitializeEvent(&Event, NotificationEvent, FALSE);
Irp = TdiBuildInternalDeviceControlIrp(TDI_RECEIVE_DATAGRAM, /* Sub function */ Irp = TdiBuildInternalDeviceControlIrp(TDI_RECEIVE_DATAGRAM, /* Sub function */
@ -1344,7 +1072,7 @@ NTSTATUS TdiReceiveDatagram(
Status = TdiCall(Irp, DeviceObject, &Event, &Iosb); Status = TdiCall(Irp, DeviceObject, &Event, &Iosb);
if (NT_SUCCESS(Status)) { if (NT_SUCCESS(Status)) {
*BufferSize = Iosb.Information; *BufferSize = Iosb.Information;
TdiBuildName(Address, ReturnInfo->RemoteAddress); TdiBuildName(Address, TdiGetRemoteAddress(ReturnInfo));
} }
MmUnlockPages(Mdl); MmUnlockPages(Mdl);

View file

@ -0,0 +1,309 @@
#include <afd.h>
#include "tdiconn.h"
DWORD TdiAddressSizeFromType(
ULONG Type)
/*
* FUNCTION: Returns the size of a TDI style address of given address type
* ARGUMENTS:
* Type = TDI style address type
* RETURNS:
* Size of TDI style address, 0 if Type is not valid
*/
{
switch (Type) {
case TDI_ADDRESS_TYPE_IP:
return sizeof(TA_IP_ADDRESS);
/* FIXME: More to come */
}
AFD_DbgPrint(MIN_TRACE, ("Unknown TDI address type (%d).\n", Type));
return 0;
}
DWORD TdiAddressSizeFromName(
LPSOCKADDR Name)
/*
* FUNCTION: Returns the size of a TDI style address equivalent to a
* WinSock style name
* ARGUMENTS:
* Name = WinSock style name
* RETURNS:
* Size of TDI style address, 0 if Name is not valid
*/
{
switch (Name->sa_family) {
case AF_INET:
return sizeof(TA_IP_ADDRESS);
/* FIXME: More to come */
}
AFD_DbgPrint(MIN_TRACE, ("Unknown address family (%d).\n", Name->sa_family));
return 0;
}
VOID TdiBuildAddressIPv4(
PTA_IP_ADDRESS Address,
LPSOCKADDR Name)
/*
* FUNCTION: Builds an IPv4 TDI style address
* ARGUMENTS:
* Address = Address of buffer to place TDI style IPv4 address
* Name = Pointer to WinSock style IPv4 name
*/
{
Address->TAAddressCount = 1;
Address->Address[0].AddressLength = TDI_ADDRESS_LENGTH_IP;
Address->Address[0].AddressType = TDI_ADDRESS_TYPE_IP;
Address->Address[0].Address[0].sin_port = ((LPSOCKADDR_IN)Name)->sin_port;
Address->Address[0].Address[0].in_addr = ((LPSOCKADDR_IN)Name)->sin_addr.S_un.S_addr;
}
NTSTATUS TdiBuildAddress(
PTA_ADDRESS Address,
LPSOCKADDR Name)
/*
* FUNCTION: Builds a TDI style address
* ARGUMENTS:
* Address = Address of buffer to place TDI style address
* Name = Pointer to WinSock style name
* RETURNS:
* Status of operation
*/
{
NTSTATUS Status = STATUS_SUCCESS;
switch (Name->sa_family) {
case AF_INET:
TdiBuildAddressIPv4((PTA_IP_ADDRESS)Address,Name);
break;
/* FIXME: More to come */
default:
AFD_DbgPrint(MID_TRACE, ("Unknown address family (%d).\n", Name->sa_family));
Status = STATUS_INVALID_PARAMETER;
}
return Status;
}
NTSTATUS TdiBuildName(
LPSOCKADDR Name,
PTA_ADDRESS Address)
/*
* FUNCTION: Builds a WinSock style address
* ARGUMENTS:
* Name = Address of buffer to place WinSock style name
* Address = Pointer to TDI style address
* RETURNS:
* Status of operation
*/
{
NTSTATUS Status = STATUS_SUCCESS;
switch (Address->AddressType) {
case TDI_ADDRESS_TYPE_IP:
Name->sa_family = AF_INET;
((LPSOCKADDR_IN)Name)->sin_port =
((PTDI_ADDRESS_IP)&Address->Address[0])->sin_port;
((LPSOCKADDR_IN)Name)->sin_addr.S_un.S_addr =
((PTDI_ADDRESS_IP)&Address->Address[0])->in_addr;
break;
/* FIXME: More to come */
default:
AFD_DbgPrint(MID_TRACE, ("Unknown TDI address type (%d).\n", Address->AddressType));
Status = STATUS_INVALID_PARAMETER;
}
return Status;
}
NTSTATUS TdiBuildConnectionInfoInPlace
( PTDI_CONNECTION_INFORMATION ConnInfo,
LPSOCKADDR Name )
/*
* FUNCTION: Builds a TDI connection information structure
* ARGUMENTS:
* ConnectionInfo = Address of buffer to place connection information
* Name = Pointer to WinSock style name
* RETURNS:
* Status of operation
*/
{
ULONG TdiAddressSize;
TdiAddressSize = TdiAddressSizeFromName(Name);
RtlZeroMemory(ConnInfo,
sizeof(TDI_CONNECTION_INFORMATION) +
TdiAddressSize);
ConnInfo->OptionsLength = sizeof(ULONG);
ConnInfo->RemoteAddressLength = TdiAddressSize;
ConnInfo->RemoteAddress = (PVOID)
(((PCHAR)ConnInfo) + sizeof(TDI_CONNECTION_INFORMATION));
TdiBuildAddress(ConnInfo->RemoteAddress, Name);
return STATUS_SUCCESS;
}
NTSTATUS TdiBuildConnectionInfo(
PTDI_CONNECTION_INFORMATION *ConnectionInfo,
LPSOCKADDR Name)
/*
* FUNCTION: Builds a TDI connection information structure
* ARGUMENTS:
* ConnectionInfo = Address of buffer pointer to allocate connection
* information on
* Name = Pointer to WinSock style name
* RETURNS:
* Status of operation
*/
{
PTDI_CONNECTION_INFORMATION ConnInfo;
ULONG TdiAddressSize;
NTSTATUS Status;
TdiAddressSize = TdiAddressSizeFromName(Name);
ConnInfo = (PTDI_CONNECTION_INFORMATION)
ExAllocatePool(NonPagedPool,
sizeof(TDI_CONNECTION_INFORMATION) +
TdiAddressSize);
if (!ConnInfo)
return STATUS_INSUFFICIENT_RESOURCES;
Status = TdiBuildConnectionInfoInPlace( ConnInfo, Name );
if( !NT_SUCCESS(Status) )
ExFreePool( ConnInfo );
else
*ConnectionInfo = ConnInfo;
return Status;
}
NTSTATUS TdiBuildNullConnectionInfoInPlace
( PTDI_CONNECTION_INFORMATION ConnInfo,
ULONG Type )
/*
* FUNCTION: Builds a NULL TDI connection information structure
* ARGUMENTS:
* ConnectionInfo = Address of buffer to place connection information
* Type = TDI style address type (TDI_ADDRESS_TYPE_XXX).
* RETURNS:
* Status of operation
*/
{
ULONG TdiAddressSize;
TdiAddressSize = TdiAddressSizeFromType(Type);
RtlZeroMemory(ConnInfo,
sizeof(TDI_CONNECTION_INFORMATION) +
TdiAddressSize);
ConnInfo->OptionsLength = sizeof(ULONG);
ConnInfo->RemoteAddressLength = 0;
ConnInfo->RemoteAddress = NULL;
return STATUS_SUCCESS;
}
NTSTATUS TdiBuildNullConnectionInfo
( PTDI_CONNECTION_INFORMATION *ConnectionInfo,
ULONG Type )
/*
* FUNCTION: Builds a NULL TDI connection information structure
* ARGUMENTS:
* ConnectionInfo = Address of buffer pointer to allocate connection
* information in
* Type = TDI style address type (TDI_ADDRESS_TYPE_XXX).
* RETURNS:
* Status of operation
*/
{
PTDI_CONNECTION_INFORMATION ConnInfo;
ULONG TdiAddressSize;
NTSTATUS Status;
TdiAddressSize = TdiAddressSizeFromType(Type);
ConnInfo = (PTDI_CONNECTION_INFORMATION)
ExAllocatePool(NonPagedPool,
sizeof(TDI_CONNECTION_INFORMATION) +
TdiAddressSize);
if (!ConnInfo)
return STATUS_INSUFFICIENT_RESOURCES;
Status = TdiBuildNullConnectionInfoInPlace( ConnInfo, Type );
if (!NT_SUCCESS(Status))
ExFreePool( ConnInfo );
else
*ConnectionInfo = ConnInfo;
return Status;
}
NTSTATUS
TdiBuildConnectionInfoPair
( PTDI_CONNECTION_INFO_PAIR ConnectionInfo,
LPSOCKADDR From, LPSOCKADDR To )
/*
* FUNCTION: Fill a TDI_CONNECTION_INFO_PAIR struct will the two addresses
* given.
* ARGUMENTS:
* ConnectionInfo: The pair
* From: The from address
* To: The to address
* RETURNS:
* Status of the operation
*/
{
PCHAR LayoutFrame;
DWORD SizeOfEntry;
ULONG TdiAddressSize;
/* FIXME: Get from socket information */
TdiAddressSize = TdiAddressSizeFromName(From);
SizeOfEntry = TdiAddressSize + sizeof(TDI_CONNECTION_INFORMATION);
LayoutFrame = (PCHAR)ExAllocatePool(NonPagedPool, 2 * SizeOfEntry);
if (!LayoutFrame) {
AFD_DbgPrint(MIN_TRACE, ("Insufficient resources.\n"));
return STATUS_INSUFFICIENT_RESOURCES;
}
RtlZeroMemory( LayoutFrame, 2 * SizeOfEntry );
PTDI_CONNECTION_INFORMATION
FromTdiConn = (PTDI_CONNECTION_INFORMATION)LayoutFrame,
ToTdiConn = (PTDI_CONNECTION_INFORMATION)LayoutFrame + SizeOfEntry;
if (From != NULL) {
TdiBuildConnectionInfoInPlace( FromTdiConn, From );
} else {
TdiBuildNullConnectionInfoInPlace( FromTdiConn,
From->sa_family );
}
TdiBuildConnectionInfoInPlace( ToTdiConn, To );
return STATUS_SUCCESS;
}
PTA_ADDRESS TdiGetRemoteAddress( PTDI_CONNECTION_INFORMATION TdiConn )
/*
* Convenience function that rounds out the abstraction of
* the TDI_CONNECTION_INFORMATION struct.
*/
{
return TdiConn->RemoteAddress;
}

View file

@ -0,0 +1,28 @@
#ifndef _TDICONN_H
#define _TDICONN_H
#include <afd.h>
typedef VOID *PTDI_CONNECTION_INFO_PAIR;
DWORD TdiAddressSizeFromType( ULONG Type );
DWORD TdiAddressSizeFromName( LPSOCKADDR Name );
VOID TdiBuildAddressIPv4( PTA_IP_ADDRESS Address,
LPSOCKADDR Name );
NTSTATUS TdiBuildAddress( PTA_ADDRESS Address,
LPSOCKADDR Name );
NTSTATUS TdiBuildName( LPSOCKADDR Name,
PTA_ADDRESS Address );
NTSTATUS TdiBuildConnectionInfoInPlace
( PTDI_CONNECTION_INFORMATION ConnInfo, LPSOCKADDR Name );
NTSTATUS TdiBuildConnectionInfo
( PTDI_CONNECTION_INFORMATION *ConnectionInfo, LPSOCKADDR Name );
NTSTATUS TdiBuildNullConnectionInfoToPlace
( PTDI_CONNECTION_INFORMATION ConnInfo, ULONG Type );
NTSTATUS TdiBuildNullConnectionInfo
( PTDI_CONNECTION_INFORMATION *ConnectionInfo, ULONG Type );
NTSTATUS TdiBuildConnectionInfoPair
( PTDI_CONNECTION_INFO_PAIR ConnectionInfo, LPSOCKADDR From, LPSOCKADDR To );
PTA_ADDRESS TdiGetRemoteAddress( PTDI_CONNECTION_INFORMATION TdiConn );
#endif/*_TDICONN_H*/

View file

@ -1,4 +1,4 @@
# $Id: makefile,v 1.8 2004/01/28 20:54:18 ekohl Exp $ # $Id: makefile,v 1.9 2004/02/07 04:50:44 arty Exp $
PATH_TO_TOP = ../../.. PATH_TO_TOP = ../../..
@ -15,7 +15,8 @@ TARGET_OBJECTS = \
afd/opnclose.o \ afd/opnclose.o \
afd/rdwr.o \ afd/rdwr.o \
afd/routines.o \ afd/routines.o \
afd/tdi.o afd/tdi.o \
afd/tdiconn.o
include $(PATH_TO_TOP)/rules.mak include $(PATH_TO_TOP)/rules.mak

View file

@ -181,7 +181,7 @@ NTSTATUS AddrBuildAddress(
if (TdiAddress->AddressType != TDI_ADDRESS_TYPE_IP) if (TdiAddress->AddressType != TDI_ADDRESS_TYPE_IP)
return STATUS_INVALID_ADDRESS; return STATUS_INVALID_ADDRESS;
if (TdiAddress->AddressLength >= TDI_ADDRESS_LENGTH_IP) if (TdiAddress->AddressLength != TDI_ADDRESS_LENGTH_IP)
return STATUS_INVALID_ADDRESS; return STATUS_INVALID_ADDRESS;
ValidAddr = (PTDI_ADDRESS_IP)TdiAddress->Address; ValidAddr = (PTDI_ADDRESS_IP)TdiAddress->Address;

View file

@ -277,7 +277,7 @@ NTSTATUS FileOpenAddress(
/* Locate address entry. If specified address is 0, a random address is chosen */ /* Locate address entry. If specified address is 0, a random address is chosen */
/* FIXME: IPv4 only */ /* FIXME: IPv4 only */
IPv4Address = Address->Address[0].Address[0].in_addr; IPv4Address = ((PTDI_ADDRESS_IP)Address->Address)->in_addr;
if (IPv4Address == 0) if (IPv4Address == 0)
AddrFile->ADE = IPGetDefaultADE(ADE_UNICAST); AddrFile->ADE = IPGetDefaultADE(ADE_UNICAST);
else else
@ -296,13 +296,13 @@ NTSTATUS FileOpenAddress(
switch (Protocol) { switch (Protocol) {
case IPPROTO_TCP: case IPPROTO_TCP:
/* FIXME: If specified port is 0, a port is chosen dynamically */ /* FIXME: If specified port is 0, a port is chosen dynamically */
AddrFile->Port = Address->Address[0].Address[0].sin_port; AddrFile->Port = ((PTDI_ADDRESS_IP)Address->Address)->sin_port;
AddrFile->Send = TCPSendDatagram; AddrFile->Send = TCPSendDatagram;
break; break;
case IPPROTO_UDP: case IPPROTO_UDP:
/* FIXME: If specified port is 0, a port is chosen dynamically */ /* FIXME: If specified port is 0, a port is chosen dynamically */
AddrFile->Port = Address->Address[0].Address[0].sin_port; AddrFile->Port = ((PTDI_ADDRESS_IP)Address->Address)->sin_port;
AddrFile->Send = UDPSendDatagram; AddrFile->Send = UDPSendDatagram;
break; break;

View file

@ -182,7 +182,7 @@ NTSTATUS TCPiBuildPacket(
VOID TCPiSendRequestComplete( VOID TCPiSendRequestComplete(
PVOID Context, PVOID Context,
NTSTATUS Status, NDIS_STATUS Status,
ULONG Count) ULONG Count)
/* /*
* FUNCTION: Completion routine for datagram send requests * FUNCTION: Completion routine for datagram send requests
@ -348,6 +348,10 @@ NTSTATUS TCPConnect(
LARGE_INTEGER DueTime; LARGE_INTEGER DueTime;
NTSTATUS Status; NTSTATUS Status;
KIRQL OldIrql; KIRQL OldIrql;
PNDIS_BUFFER NdisBuffer;
NDIS_STATUS NdisStatus;
PVOID DataBuffer;
ULONG Size;
TI_DbgPrint(MID_TRACE, ("Called.\n")); TI_DbgPrint(MID_TRACE, ("Called.\n"));
@ -373,13 +377,29 @@ NTSTATUS TCPConnect(
return Status; return Status;
} }
/* Allocate NDIS buffer */
Size = sizeof(IPv4_HEADER);
DataBuffer = ExAllocatePool(NonPagedPool, Size);
if (!DataBuffer) {
return STATUS_INSUFFICIENT_RESOURCES;
}
NdisAllocateBuffer(&NdisStatus, &NdisBuffer, GlobalBufferPool,
DataBuffer, Size);
if (NdisStatus != NDIS_STATUS_SUCCESS) {
KeReleaseSpinLock(&Connection->Lock, OldIrql);
ExFreePool(Connection->RemoteAddress);
return NdisStatus;
}
/* Issue SYN segment */ /* Issue SYN segment */
Status = TCPBuildAndTransmitSendRequest( Status = TCPBuildAndTransmitSendRequest(
Connection, /* Connection endpoint */ Connection, /* Connection endpoint */
Request->RequestNotifyObject, /* Completion routine */ Request->RequestNotifyObject, /* Completion routine */
Request->RequestContext, /* Completion routine context */ Request->RequestContext, /* Completion routine context */
NULL, /* Buffer */ NdisBuffer, /* Buffer */
0, /* Size of buffer */ 0, /* Size of buffer */
SRF_SYN); /* Protocol specific flags */ SRF_SYN); /* Protocol specific flags */
if (!NT_SUCCESS(Status)) { if (!NT_SUCCESS(Status)) {
@ -388,6 +408,10 @@ NTSTATUS TCPConnect(
return Status; return Status;
} }
/* Free the NDIS buffer */
NdisFreeBuffer(NdisBuffer);
ExFreePool(DataBuffer);
KeReleaseSpinLock(&Connection->Lock, OldIrql); KeReleaseSpinLock(&Connection->Lock, OldIrql);
TI_DbgPrint(MAX_TRACE, ("Leaving. Status (0x%X)\n", Status)); TI_DbgPrint(MAX_TRACE, ("Leaving. Status (0x%X)\n", Status));