ReactOS  0.4.14-dev-57-g333b8f1
connect.c File Reference
#include <kmt_test.h>
#include <tdikrnl.h>
#include <ndk/rtlfuncs.h>
#include <sys/param.h>
#include "tcpip.h"
Include dependency graph for connect.c:

Go to the source code of this file.

Macros

#define TAG_TEST   'tseT'
 

Functions

USHORT htons (USHORT x)
 
static NTSTATUS NTAPI IrpCompletionRoutine (_In_ PDEVICE_OBJECT DeviceObject, _In_ PIRP Irp, _In_ PVOID Context)
 
static VOID TestTcpConnect (void)
 
static VOID NTAPI RunTest (_In_ PVOID Context)
 
NTSTATUS TestConnect (_In_ PDEVICE_OBJECT DeviceObject, _In_ ULONG ControlCode, _In_opt_ PVOID Buffer, _In_ SIZE_T InLength, _Inout_ PSIZE_T OutLength)
 

Variables

static KSTART_ROUTINE RunTest
 
KMT_MESSAGE_HANDLER TestConnect
 

Macro Definition Documentation

◆ TAG_TEST

#define TAG_TEST   'tseT'

Definition at line 16 of file connect.c.

Function Documentation

◆ htons()

USHORT htons ( USHORT  x)

Definition at line 20 of file connect.c.

21 {
22  return ((x & 0x00FF) << 8) | ((x & 0xFF00) >> 8);
23 }
GLint GLint GLint GLint GLint x
Definition: gl.h:1548

Referenced by TestTcpConnect().

◆ IrpCompletionRoutine()

static NTSTATUS NTAPI IrpCompletionRoutine ( _In_ PDEVICE_OBJECT  DeviceObject,
_In_ PIRP  Irp,
_In_ PVOID  Context 
)
static

Definition at line 31 of file connect.c.

35 {
38 
40 
42 }
#define STATUS_MORE_PROCESSING_REQUIRED
Definition: shellext.h:63
_In_ PIRP Irp
Definition: csq.h:116
#define UNREFERENCED_PARAMETER(P)
Definition: ntbasedef.h:323
LONG NTAPI KeSetEvent(IN PKEVENT Event, IN KPRIORITY Increment, IN BOOLEAN Wait)
Definition: eventobj.c:159
#define IO_NETWORK_INCREMENT
Definition: tcpip.h:43
IN PDEVICE_OBJECT DeviceObject
Definition: fatprocs.h:1560

Referenced by TestTcpConnect().

◆ RunTest()

static VOID NTAPI RunTest ( _In_ PVOID  Context)
static

Definition at line 249 of file connect.c.

251 {
253 
254  TestTcpConnect();
255 }
static VOID TestTcpConnect(void)
Definition: connect.c:46
#define UNREFERENCED_PARAMETER(P)
Definition: ntbasedef.h:323

◆ TestConnect()

NTSTATUS TestConnect ( _In_ PDEVICE_OBJECT  DeviceObject,
_In_ ULONG  ControlCode,
_In_opt_ PVOID  Buffer,
_In_ SIZE_T  InLength,
_Inout_ PSIZE_T  OutLength 
)

Definition at line 259 of file connect.c.

266 {
268 
271 
272  return STATUS_SUCCESS;
273 }
PKTHREAD KmtStartThread(IN PKSTART_ROUTINE StartRoutine, IN PVOID StartContext OPTIONAL)
smooth NULL
Definition: ftsmooth.c:416
_In_opt_ PFILE_OBJECT _In_opt_ PETHREAD Thread
Definition: fltkernel.h:2653
VOID KmtFinishThread(IN PKTHREAD Thread OPTIONAL, IN PKEVENT Event OPTIONAL)
return STATUS_SUCCESS
Definition: btrfs.c:2966
static KSTART_ROUTINE RunTest
Definition: connect.c:245

◆ TestTcpConnect()

static VOID TestTcpConnect ( void  )
static

Definition at line 46 of file connect.c.

47 {
48  PIRP Irp;
49  HANDLE AddressHandle, ConnectionHandle;
50  FILE_OBJECT* ConnectionFileObject;
52  UNICODE_STRING TcpDeviceName = RTL_CONSTANT_STRING(L"\\Device\\Tcp");
55  TA_IP_ADDRESS* IpAddress;
56  TA_IP_ADDRESS ConnectAddress, ReturnAddress;
58  IO_STATUS_BLOCK StatusBlock;
59  ULONG FileInfoSize;
60  IN_ADDR InAddr;
61  LPCWSTR AddressTerminator;
62  CONNECTION_CONTEXT ConnectionContext = (CONNECTION_CONTEXT)(ULONG_PTR)0xC0CAC01AC0CAC01AULL;
63  KEVENT Event;
64  TDI_CONNECTION_INFORMATION RequestInfo, ReturnInfo;
65 
66  /* Create a TCP address file */
69  FileInfoSize,
70  TAG_TEST);
71  ok(FileInfo != NULL, "FileInfo is NULL!\n");
72  RtlZeroMemory(FileInfo, FileInfoSize);
73 
74  FileInfo->EaNameLength = TDI_TRANSPORT_ADDRESS_LENGTH;
75  FileInfo->EaValueLength = sizeof(TA_IP_ADDRESS);
77 
78  IpAddress = (PTA_IP_ADDRESS)(&FileInfo->EaName[TDI_TRANSPORT_ADDRESS_LENGTH + 1]);
79  IpAddress->TAAddressCount = 1;
80  IpAddress->Address[0].AddressType = TDI_ADDRESS_TYPE_IP;
81  IpAddress->Address[0].AddressLength = TDI_ADDRESS_LENGTH_IP;
82  IpAddress->Address[0].Address[0].sin_port = htons(TEST_CONNECT_CLIENT_PORT);
83  Status = RtlIpv4StringToAddressW(L"127.0.0.1", TRUE, &AddressTerminator, &InAddr);
85  IpAddress->Address[0].Address[0].in_addr = InAddr.S_un.S_addr;
86 
88  &TcpDeviceName,
90  NULL,
91  NULL);
92 
93  Status = ZwCreateFile(
94  &AddressHandle,
97  &StatusBlock,
98  0,
101  FILE_OPEN_IF,
102  0L,
103  FileInfo,
104  FileInfoSize);
106 
108 
109  /* Create a TCP connection file */
112  FileInfoSize,
113  TAG_TEST);
114  ok(FileInfo != NULL, "FileInfo is NULL!\n");
115  RtlZeroMemory(FileInfo, FileInfoSize);
116 
117  FileInfo->EaNameLength = TDI_CONNECTION_CONTEXT_LENGTH;
118  FileInfo->EaValueLength = sizeof(CONNECTION_CONTEXT);
120  *((CONNECTION_CONTEXT*)&FileInfo->EaName[TDI_CONNECTION_CONTEXT_LENGTH + 1]) = ConnectionContext;
121 
122  Status = ZwCreateFile(
126  &StatusBlock,
127  0,
130  FILE_OPEN_IF,
131  0L,
132  FileInfo,
133  FileInfoSize);
135 
137 
138  /* Get the file and device object for the upcoming IRPs */
141  GENERIC_READ,
143  KernelMode,
144  (PVOID*)&ConnectionFileObject,
145  NULL);
147  DeviceObject = IoGetRelatedDeviceObject(ConnectionFileObject);
148  ok(DeviceObject != NULL, "Device object is NULL!\n");
149 
150  /* Associate the connection file and the address */
153  ok(Irp != NULL, "IoAllocateIrp failed.\n");
154 
155  TdiBuildAssociateAddress(Irp, DeviceObject, ConnectionFileObject, NULL, NULL, AddressHandle);
157 
159  if (Status == STATUS_PENDING)
160  {
161  trace("Associate address IRP is pending.\n");
163  &Event,
164  Executive,
165  KernelMode,
166  FALSE,
167  NULL);
168  Status = Irp->IoStatus.Status;
169  trace("Associate address IRP completed.\n");
170  }
172  IoFreeIrp(Irp);
173 
174 
176 
177  /* Build the connect IRP. */
179  ok(Irp != NULL, "IoAllocateIrp failed.\n");
180 
181  /* Prepare the request */
182  RtlZeroMemory(&RequestInfo, sizeof(RequestInfo));
183  RtlZeroMemory(&ConnectAddress, sizeof(ConnectAddress));
184  RequestInfo.RemoteAddressLength = sizeof(TA_IP_ADDRESS);
185  RequestInfo.RemoteAddress = &ConnectAddress;
186  ConnectAddress.TAAddressCount = 1;
187  ConnectAddress.Address[0].AddressType = TDI_ADDRESS_TYPE_IP;
188  ConnectAddress.Address[0].AddressLength = TDI_ADDRESS_LENGTH_IP;
189  ConnectAddress.Address[0].Address[0].sin_port = htons(TEST_CONNECT_SERVER_PORT);
190  Status = RtlIpv4StringToAddressW(L"127.0.0.1", TRUE, &AddressTerminator, &InAddr);
191  ConnectAddress.Address[0].Address[0].in_addr = InAddr.S_un.S_addr;
192 
193  /* See what we will get in exchange */
194  RtlZeroMemory(&ReturnInfo, sizeof(ReturnInfo));
195  RtlZeroMemory(&ReturnAddress, sizeof(ReturnAddress));
196  ReturnInfo.RemoteAddressLength = sizeof(TA_IP_ADDRESS);
197  ReturnInfo.RemoteAddress = &ReturnAddress;
198 
200  DeviceObject,
201  ConnectionFileObject,
202  NULL,
203  NULL,
204  NULL,
205  &RequestInfo,
206  &ReturnInfo);
208 
210  if (Status == STATUS_PENDING)
211  {
212  trace("Connect IRP is pending.\n");
214  &Event,
215  Executive,
216  KernelMode,
217  FALSE,
218  NULL);
219  Status = Irp->IoStatus.Status;
220  trace("Connect IRP completed.\n");
221  }
223  IoFreeIrp(Irp);
224 
225  /* The IRP doesn't touch the return info */
226  ok_eq_long(ReturnInfo.RemoteAddressLength, sizeof(TA_IP_ADDRESS));
227  ok_eq_pointer(ReturnInfo.RemoteAddress, &ReturnAddress);
228  ok_eq_long(ReturnInfo.OptionsLength, 0);
229  ok_eq_pointer(ReturnInfo.Options, NULL);
230  ok_eq_long(ReturnInfo.UserDataLength, 0);
231  ok_eq_pointer(ReturnInfo.UserData, NULL);
232 
233  ok_eq_long(ReturnAddress.TAAddressCount, 1);
234  ok_eq_hex(ReturnAddress.Address[0].AddressType, TDI_ADDRESS_TYPE_IP);
235  ok_eq_hex(ReturnAddress.Address[0].AddressLength, TDI_ADDRESS_LENGTH_IP);
236  ok_eq_hex(ReturnAddress.Address[0].Address[0].sin_port, htons(TEST_CONNECT_SERVER_PORT));
237  ok_eq_hex(ReturnAddress.Address[0].Address[0].in_addr, InAddr.S_un.S_addr);
238 
239  ObDereferenceObject(ConnectionFileObject);
240 
242  ZwClose(AddressHandle);
243 }
LONG TAAddressCount
Definition: tdi.h:523
IN PUNICODE_STRING IN POBJECT_ATTRIBUTES ObjectAttributes
Definition: conport.c:35
#define TRUE
Definition: types.h:120
NTSYSAPI VOID NTAPI RtlCopyMemory(VOID UNALIGNED *Destination, CONST VOID UNALIGNED *Source, ULONG Length)
#define FILE_OPEN_IF
Definition: from_kernel.h:56
const WCHAR * LPCWSTR
Definition: xmlstorage.h:185
static NTSTATUS NTAPI IrpCompletionRoutine(_In_ PDEVICE_OBJECT DeviceObject, _In_ PIRP Irp, _In_ PVOID Context)
Definition: connect.c:31
_In_ PIRP Irp
Definition: csq.h:116
NTSYSAPI NTSTATUS NTAPI ZwClose(_In_ HANDLE Handle)
#define ok_eq_pointer(value, expected)
struct _TA_ADDRESS_IP * PTA_IP_ADDRESS
LONG NTSTATUS
Definition: precomp.h:26
VOID NTAPI ObDereferenceObject(IN PVOID Object)
Definition: obref.c:375
#define TDI_CONNECTION_CONTEXT_LENGTH
Definition: tdi.h:373
PDEVICE_OBJECT NTAPI IoGetRelatedDeviceObject(IN PFILE_OBJECT FileObject)
Definition: device.c:1539
#define FILE_SHARE_WRITE
Definition: nt_native.h:681
NTSTATUS NTAPI KeWaitForSingleObject(IN PVOID Object, IN KWAIT_REASON WaitReason, IN KPROCESSOR_MODE WaitMode, IN BOOLEAN Alertable, IN PLARGE_INTEGER Timeout OPTIONAL)
Definition: wait.c:416
#define TEST_CONNECT_CLIENT_PORT
Definition: tcpip.h:7
#define FILE_SHARE_READ
Definition: compat.h:125
#define IoSetCompletionRoutine(_Irp, _CompletionRoutine, _Context, _InvokeOnSuccess, _InvokeOnError, _InvokeOnCancel)
Definition: irp.cpp:515
uint32_t ULONG_PTR
Definition: typedefs.h:63
#define TAG_TEST
Definition: connect.c:16
NTSTATUS NTAPI ObReferenceObjectByHandle(IN HANDLE Handle, IN ACCESS_MASK DesiredAccess, IN POBJECT_TYPE ObjectType, IN KPROCESSOR_MODE AccessMode, OUT PVOID *Object, OUT POBJECT_HANDLE_INFORMATION HandleInformation OPTIONAL)
Definition: obref.c:496
#define GENERIC_WRITE
Definition: nt_native.h:90
PVOID CONNECTION_CONTEXT
Definition: tdi.h:37
_In_ PVOID _In_ ULONG Event
Definition: iotypes.h:435
smooth NULL
Definition: ftsmooth.c:416
struct _TA_ADDRESS_IP::_AddrIp Address[1]
#define ULL(a, b)
Definition: format_msg.c:27
#define trace
Definition: atltest.h:70
#define STATUS_PENDING
Definition: ntstatus.h:82
Definition: tcpip.h:125
struct _TA_ADDRESS_IP TA_IP_ADDRESS
#define OBJ_CASE_INSENSITIVE
Definition: winternl.h:228
#define ExAllocatePoolWithTag(hernya, size, tag)
Definition: env_spec_w32.h:350
#define FILE_ATTRIBUTE_NORMAL
Definition: compat.h:126
static const WCHAR L[]
Definition: oid.c:1250
#define TDI_ADDRESS_TYPE_IP
Definition: tdi.h:345
USHORT htons(USHORT x)
Definition: connect.c:20
#define GENERIC_READ
Definition: compat.h:124
POBJECT_TYPE IoFileObjectType
Definition: iomgr.c:36
Status
Definition: gdiplustypes.h:24
#define TdiBuildConnect( Irp, DevObj, FileObj, CompRoutine, Contxt, Time, RequestConnectionInfo, ReturnConnectionInfo)
Definition: tdikrnl.h:494
u_long S_addr
Definition: tcpip.h:131
IN PDEVICE_OBJECT DeviceObject
Definition: fatprocs.h:1560
#define KeInitializeEvent(pEvt, foo, foo2)
Definition: env_spec_w32.h:477
#define TEST_CONNECT_SERVER_PORT
Definition: tcpip.h:6
#define ok(value,...)
Definition: atltest.h:57
#define FIELD_OFFSET(t, f)
Definition: typedefs.h:254
#define TdiTransportAddress
Definition: tdi.h:370
NTSTATUS NTAPI IoCallDriver(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
Definition: irp.c:1218
#define TdiConnectionContext
Definition: tdi.h:371
#define TDI_TRANSPORT_ADDRESS_LENGTH
Definition: tdi.h:372
VOID NTAPI IoFreeIrp(IN PIRP Irp)
Definition: irp.c:1666
struct FileInfo FileInfo
unsigned int ULONG
Definition: retypes.h:1
union in_addr::@990 S_un
#define RtlZeroMemory(Destination, Length)
Definition: typedefs.h:261
#define TdiBuildAssociateAddress( Irp, DevObj, FileObj, CompRoutine, Contxt, AddrHandle)
Definition: tdikrnl.h:467
#define InitializeObjectAttributes(p, n, a, r, s)
Definition: reg.c:106
PIRP NTAPI IoAllocateIrp(IN CCHAR StackSize, IN BOOLEAN ChargeQuota)
Definition: irp.c:615
#define ok_eq_hex(value, expected)
#define ExFreePoolWithTag(_P, _T)
Definition: module.h:1099
#define TDI_ADDRESS_LENGTH_IP
Definition: tdi.h:413
_In_ PKSPIN_CONNECT _In_ ACCESS_MASK _Out_ PHANDLE ConnectionHandle
Definition: ks.h:4536
VOID NTAPI KeClearEvent(IN PKEVENT Event)
Definition: eventobj.c:22
NTSYSAPI NTSTATUS NTAPI RtlIpv4StringToAddressW(_In_ PCWSTR String, _In_ BOOLEAN Strict, _Out_ PCWSTR *Terminator, _Out_ struct in_addr *Addr)
Definition: network.c:405
return STATUS_SUCCESS
Definition: btrfs.c:2966
#define OBJ_KERNEL_HANDLE
Definition: winternl.h:231
#define ok_eq_long(value, expected)
Definition: kmt_test.h:240
#define RTL_CONSTANT_STRING(s)
Definition: tunneltest.c:14

Referenced by RunTest().

Variable Documentation

◆ RunTest

KSTART_ROUTINE RunTest
static

Definition at line 245 of file connect.c.

Referenced by TestConnect().

◆ TestConnect

KMT_MESSAGE_HANDLER TestConnect

Definition at line 257 of file connect.c.