Beispiel #1
0
NTSTATUS 
DraidStartListenAddress(
	PDRAID_GLOBALS DraidGlobals,
	PDRAID_LISTEN_CONTEXT ListenContext
) {
	NTSTATUS status;
	KIRQL	oldIrql;

	KDPrintM(DBG_LURN_INFO, ("Starting to listen address %02x:%02x:%02x:%02x:%02x:%02x\n",
		ListenContext->Addr.Node[0], ListenContext->Addr.Node[1], ListenContext->Addr.Node[2],
		ListenContext->Addr.Node[3], ListenContext->Addr.Node[4], ListenContext->Addr.Node[5]
	));

	ACQUIRE_SPIN_LOCK(&DraidGlobals->ListenContextSpinlock, &oldIrql);
	ListenContext->Started = TRUE;
	RELEASE_SPIN_LOCK(&DraidGlobals->ListenContextSpinlock, oldIrql);

	//
	// Start listen.
	//

	// 1. Open address
	status = LpxTdiOpenAddress(
				&ListenContext->AddressFileHandle,
				&ListenContext->AddressFileObject,
				&ListenContext->Addr
			);

	if(!NT_SUCCESS(status)) 
	{
		goto errout;
	}

	
	// 2. Open connection
	status = DraidListenConnection(ListenContext);

	if(!NT_SUCCESS(status)) 
	{
		goto errout;
	}

	return status;
	
errout:

	if (ListenContext->AddressFileHandle && ListenContext->AddressFileObject) {
		LpxTdiCloseAddress(ListenContext->AddressFileHandle, ListenContext->AddressFileObject);
		ListenContext->AddressFileHandle = NULL;
		ListenContext->AddressFileObject = NULL;
	}
	ACQUIRE_SPIN_LOCK(&DraidGlobals->ListenContextSpinlock, &oldIrql);
	ListenContext->Started = FALSE;
	RELEASE_SPIN_LOCK(&DraidGlobals->ListenContextSpinlock, oldIrql);
	return status;
}
Beispiel #2
0
NTSTATUS
LpxTdiOpenAddress_LSTrans(
		IN	PTA_LSTRANS_ADDRESS		Address,
		OUT	PHANDLE			AddressFileHandle,
		OUT	PFILE_OBJECT	*AddressFileObject
	)
{
	ASSERT(Address->TAAddressCount == 1);
	ASSERT(Address->Address[0].AddressType == TDI_ADDRESS_TYPE_LPX);

	return LpxTdiOpenAddress(AddressFileHandle, AddressFileObject, (PTDI_ADDRESS_LPX)Address->Address[0].Address);
}
Beispiel #3
0
static
NTSTATUS
PrimaryOpenOneListenSocket(
		PPRIMARY_LISTEN_SOCKET	listenSock,
		PLPX_ADDRESS			NICAddr
	) {
	NTSTATUS	ntStatus;
	HANDLE					addressFileHandle = NULL;
	PFILE_OBJECT			addressFileObject = NULL;
	HANDLE					listenFileHandle = NULL;
	PFILE_OBJECT			listenFileObject = NULL;
	

	SPY_LOG_PRINT( LFS_DEBUG_PRIMARY_INFO,
				("PrimaryOpenOneSocket: Entered\n"));

	listenSock->Active = FALSE;
	RtlCopyMemory(
			listenSock->NICAddress.Node,
			NICAddr->Node,
			ETHER_ADDR_LENGTH
		);

	//
	//	open a address.
	//
	ntStatus = LpxTdiOpenAddress(
						&addressFileHandle,
						&addressFileObject,
						NICAddr
					);

	if(!NT_SUCCESS(ntStatus)) 
	{
		ASSERT(LPX_BUG);
		return ntStatus;
	}

	listenSock->Active = TRUE;

	KeClearEvent(
			&listenSock->TdiListenContext.CompletionEvent
		);

	listenSock->AddressFileHandle = addressFileHandle;
	listenSock->AddressFileObject = addressFileObject;
		
	ntStatus = MakeConnectionObject(addressFileHandle, addressFileObject, &listenFileHandle, &listenFileObject);
	
	if(!NT_SUCCESS(ntStatus)) 
		{
			ASSERT(LPX_BUG);
			LpxTdiCloseAddress (addressFileHandle, addressFileObject);

			listenSock->Active = FALSE;
	
			return STATUS_UNSUCCESSFUL;
		}

	listenSock->ListenFileHandle = listenFileHandle;
	listenSock->ListenFileObject = listenFileObject;
		
	SPY_LOG_PRINT( LFS_DEBUG_PRIMARY_INFO,
				( "PrimaryOpenOneListenSocket: opened a address:'%02X:%02X:%02X:%02X:%02X:%02X 0x%04X'\n",
					NICAddr->Node[0],NICAddr->Node[1],NICAddr->Node[2],
					NICAddr->Node[3],NICAddr->Node[4],NICAddr->Node[5],
					NTOHS(NICAddr->Port)
			) );

	listenSock->Flags	= TDI_QUERY_ACCEPT;

	ntStatus = LpxTdiListenWithCompletionEvent(
					listenSock->ListenFileObject,
					&listenSock->TdiListenContext,
					&listenSock->Flags
				);

	if(!NT_SUCCESS(ntStatus)) 
	{
		ASSERT(LPX_BUG);
		LpxTdiDisassociateAddress(listenFileObject);
		LpxTdiCloseConnection(listenFileHandle, listenFileObject);
		LpxTdiCloseAddress (addressFileHandle, addressFileObject);

		listenSock->Active = FALSE;
		ntStatus = STATUS_UNSUCCESSFUL;
	}

	return ntStatus;
}
Beispiel #4
0
NTSTATUS
BindListenSockets(
	IN 	PPRIMARY	Primary
	)
{
	NTSTATUS				ntStatus;
	PSOCKETLPX_ADDRESS_LIST	socketLpxAddressList;
	LONG					idx_addr;


	SPY_LOG_PRINT( LFS_DEBUG_PRIMARY_INFO,
				("BindListenSockets: Entered\n"));

	Primary->Agent.ActiveListenSocketCount = 0;
	socketLpxAddressList = &Primary->Agent.SocketLpxAddressList;
	ntStatus = LpxTdiGetAddressList(
		socketLpxAddressList
        );

	if(!NT_SUCCESS(ntStatus)) 
	{
		//ASSERT(LPX_BUG);
		return	ntStatus;
	}
	
	if(socketLpxAddressList->iAddressCount <= 0) 
	{
		SPY_LOG_PRINT( LFS_DEBUG_PRIMARY_INFO,
					( "BindListenSockets: No NICs in the host.\n") );

		return STATUS_UNSUCCESSFUL;
	}
	
	if(socketLpxAddressList->iAddressCount > MAX_SOCKETLPX_INTERFACE)
		socketLpxAddressList->iAddressCount = MAX_SOCKETLPX_INTERFACE;

	for(idx_addr = 0; idx_addr < socketLpxAddressList->iAddressCount; idx_addr ++) 
	{
		LPX_ADDRESS		NICAddr;
	
		HANDLE			addressFileHandle = NULL;
		PFILE_OBJECT	addressFileObject = NULL;

		HANDLE			listenFileHandle = NULL;
		PFILE_OBJECT	listenFileObject = NULL;
		
		
		Primary->Agent.ListenSocket[idx_addr].Active = FALSE;

		if( (0 == socketLpxAddressList->SocketLpx[idx_addr].LpxAddress.Node[0]) &&
			(0 == socketLpxAddressList->SocketLpx[idx_addr].LpxAddress.Node[1]) &&
			(0 == socketLpxAddressList->SocketLpx[idx_addr].LpxAddress.Node[2]) &&
			(0 == socketLpxAddressList->SocketLpx[idx_addr].LpxAddress.Node[3]) &&
			(0 == socketLpxAddressList->SocketLpx[idx_addr].LpxAddress.Node[4]) &&
			(0 == socketLpxAddressList->SocketLpx[idx_addr].LpxAddress.Node[5]) ) 
		{
			SPY_LOG_PRINT( LFS_DEBUG_PRIMARY_INFO,
						( "BindListenSockets: We don't use SocketLpx device.\n"));
			continue;
		}

		RtlCopyMemory(
				&Primary->Agent.ListenSocket[idx_addr].NICAddress,
				&socketLpxAddressList->SocketLpx[idx_addr].LpxAddress, 
				sizeof(LPX_ADDRESS)
			);

		RtlCopyMemory(
				&NICAddr, 
				&socketLpxAddressList->SocketLpx[idx_addr].LpxAddress, 
				sizeof(LPX_ADDRESS)
			);

		NICAddr.Port = HTONS(Primary->Agent.ListenPort);
	
		//
		//	open a address.
		//
		ntStatus = LpxTdiOpenAddress(
						&addressFileHandle,
						&addressFileObject,
						&NICAddr
						);

		if(!NT_SUCCESS(ntStatus)) 
		{
			ASSERT(LPX_BUG);
			continue;
		}

		Primary->Agent.ListenSocket[idx_addr].Active = TRUE;

		KeInitializeEvent(&Primary->Agent.ListenSocket[idx_addr].TdiListenContext.CompletionEvent, NotificationEvent, FALSE);

		Primary->Agent.ListenSocket[idx_addr].AddressFileHandle = addressFileHandle;
		Primary->Agent.ListenSocket[idx_addr].AddressFileObject = addressFileObject;
		
		Primary->Agent.ActiveListenSocketCount ++;

		ntStatus = MakeConnectionObject(addressFileHandle, addressFileObject, &listenFileHandle, &listenFileObject);
	
		if(!NT_SUCCESS(ntStatus)) 
		{
			ASSERT(LPX_BUG);
			LpxTdiCloseAddress (addressFileHandle, addressFileObject);

			Primary->Agent.ListenSocket[idx_addr].Active = FALSE;
			Primary->Agent.ActiveListenSocketCount --;
	
			continue;
		}

		Primary->Agent.ListenSocket[idx_addr].ListenFileHandle = listenFileHandle;
		Primary->Agent.ListenSocket[idx_addr].ListenFileObject = listenFileObject;

		
		SPY_LOG_PRINT( LFS_DEBUG_PRIMARY_INFO,
					( "BindListenSockets: opened a address:'%02X:%02X:%02X:%02X:%02X:%02X 0x%04X'\n",
						NICAddr.Node[0],NICAddr.Node[1],NICAddr.Node[2],
						NICAddr.Node[3],NICAddr.Node[4],NICAddr.Node[5],
						NTOHS(NICAddr.Port)
						) );

		Primary->Agent.ListenSocket[idx_addr].Flags	= TDI_QUERY_ACCEPT;

		ntStatus = LpxTdiListenWithCompletionEvent(
						Primary->Agent.ListenSocket[idx_addr].ListenFileObject,
						&Primary->Agent.ListenSocket[idx_addr].TdiListenContext,
						&Primary->Agent.ListenSocket[idx_addr].Flags
						);

		if(!NT_SUCCESS(ntStatus)) 
		{
			ASSERT(LPX_BUG);
			LpxTdiDisassociateAddress(listenFileObject);
			LpxTdiCloseConnection(listenFileHandle, listenFileObject);
			LpxTdiCloseAddress (addressFileHandle, addressFileObject);

			Primary->Agent.ListenSocket[idx_addr].Active = FALSE;
			Primary->Agent.ActiveListenSocketCount --;
	
			continue;
		}
	}

	return STATUS_SUCCESS;
}
//
//	open a datagram socket
//
NTSTATUS
xixfs_OpenDGSocket(
	OUT PLFSDG_Socket		Socket,
	IN USHORT				PortNo
) {
	HANDLE						addressFileHandle = NULL;
	HANDLE						connectionFileHandle = NULL;
	PFILE_OBJECT					addressFileObject = NULL;
	PFILE_OBJECT					connectionFileObject = NULL;
	NTSTATUS					ntStatus ;
	SOCKETLPX_ADDRESS_LIST		socketLpxAddressList;
	LONG						idx_addr ;
	ULONG						open_addr ;

	LPX_ADDRESS				NICAddr ;

	PAGED_CODE();
	DebugTrace(DEBUG_LEVEL_TRACE, DEBUG_TARGET_HOSTCOM,
		("Enter  xixfs_OpenDGSocket \n"));
	

	Socket->SocketCnt = 0 ;

	//
	//	get addresses from LPX
	//
	ntStatus = LpxTdiGetAddressList(
				&socketLpxAddressList
   				 ) ;
	
	if(!NT_SUCCESS(ntStatus)) {
		return ntStatus;
	}
	if(0 == socketLpxAddressList.iAddressCount) {
		return STATUS_INSUFFICIENT_RESOURCES;
	}


	//
	//	open a port for each NIC.
	//
	open_addr = 0 ;

	for(idx_addr = 0 ; idx_addr < socketLpxAddressList.iAddressCount; idx_addr ++) {

		if( (0 == socketLpxAddressList.SocketLpx[idx_addr].LpxAddress.Node[0]) &&
			(0 == socketLpxAddressList.SocketLpx[idx_addr].LpxAddress.Node[1]) &&
			(0 == socketLpxAddressList.SocketLpx[idx_addr].LpxAddress.Node[2]) &&
			(0 == socketLpxAddressList.SocketLpx[idx_addr].LpxAddress.Node[3]) &&
			(0 == socketLpxAddressList.SocketLpx[idx_addr].LpxAddress.Node[4]) &&
			(0 == socketLpxAddressList.SocketLpx[idx_addr].LpxAddress.Node[5]) ) {
			continue ;
		}

		RtlCopyMemory(&NICAddr, &socketLpxAddressList.SocketLpx[idx_addr].LpxAddress, sizeof(LPX_ADDRESS)) ;
		NICAddr.Port = HTONS(PortNo) ;

		//
		//	open a connection and address.
		//	if this calling for a datagram server, don't create a connection.
		//
		ntStatus = LpxTdiOpenAddress(
				&addressFileHandle,
				&addressFileObject,
				&NICAddr
			);
		if(!NT_SUCCESS(ntStatus)) {
			DebugTrace( DEBUG_LEVEL_ERROR, DEBUG_TARGET_ALL, 
				( "[LFS] xixfs_OpenDGSocket: couldn't open a address %d:'%02X:%02X:%02X:%02X:%02X:%02X/%d'\n",
						idx_addr,
						NICAddr.Node[0],NICAddr.Node[1],NICAddr.Node[2],
						NICAddr.Node[3],NICAddr.Node[4],NICAddr.Node[5],
						(int)NTOHS(NICAddr.Port) ) );
			continue ;
		}


		DebugTrace(DEBUG_LEVEL_INFO, DEBUG_TARGET_HOSTCOM, 
			( "[LFS] xixfs_OpenDGSocket: opened a address:'%02X:%02X:%02X:%02X:%02X:%02X/%d'\n",
					NICAddr.Node[0],NICAddr.Node[1],NICAddr.Node[2],
					NICAddr.Node[3],NICAddr.Node[4],NICAddr.Node[5],
					(int)NTOHS(NICAddr.Port)
			) );
		//
		//	return values
		//	close handles, but leave objects
		//
		Socket->Sockets[open_addr].AddressFile = addressFileObject ;
		Socket->Sockets[open_addr].AddressFileHandle = addressFileHandle ;
		RtlCopyMemory(&Socket->Sockets[open_addr].NICAddr, &NICAddr, sizeof(LPX_ADDRESS)) ;

		open_addr ++ ;


	}

	Socket->SocketCnt = (USHORT)open_addr ;
	
	DebugTrace(DEBUG_LEVEL_TRACE, DEBUG_TARGET_HOSTCOM,
		("Exit  xixfs_OpenDGSocket \n"));
	return ntStatus ;
}
Beispiel #6
0
//
//	open a datagram socket
//
NTSTATUS
LfsOpenDGSocket(
	OUT PLFSDG_Socket		Socket,
	IN USHORT				PortNo
) {
    HANDLE					addressFileHandle = NULL;
	HANDLE					connectionFileHandle = NULL;
    PFILE_OBJECT			addressFileObject = NULL;
	PFILE_OBJECT			connectionFileObject = NULL;
	NTSTATUS				ntStatus ;
	SOCKETLPX_ADDRESS_LIST	socketLpxAddressList;
	LONG					idx_addr ;
	ULONG					open_addr ;

	LPX_ADDRESS				NICAddr ;

	SPY_LOG_PRINT( LFS_DEBUG_LFS_TRACE, ( "[LFS] LfsOpenDGSocket: Entered\n"));

	Socket->SocketCnt = 0 ;

	//
	//	get addresses from LPX
	//
	ntStatus = LpxTdiGetAddressList(
		&socketLpxAddressList
    ) ;
	if(!NT_SUCCESS(ntStatus)) {
		SPY_LOG_PRINT( LFS_DEBUG_LFS_TRACE, ( "[LFS] LfsOpenDGSocket: LpxTdiGetAddressList() failed.\n")) ;
		return ntStatus;
	}
	if(0 == socketLpxAddressList.iAddressCount) {
		SPY_LOG_PRINT( LFS_DEBUG_LFS_TRACE, ( "[LFS] LfsOpenDGSocket: No NICs in the host.\n") );
		return STATUS_INSUFFICIENT_RESOURCES;
	}


	//
	//	open a port for each NIC.
	//
	open_addr = 0 ;

	for(idx_addr = 0 ; idx_addr < socketLpxAddressList.iAddressCount; idx_addr ++) {

		if( (0 == socketLpxAddressList.SocketLpx[idx_addr].LpxAddress.Node[0]) &&
			(0 == socketLpxAddressList.SocketLpx[idx_addr].LpxAddress.Node[1]) &&
			(0 == socketLpxAddressList.SocketLpx[idx_addr].LpxAddress.Node[2]) &&
			(0 == socketLpxAddressList.SocketLpx[idx_addr].LpxAddress.Node[3]) &&
			(0 == socketLpxAddressList.SocketLpx[idx_addr].LpxAddress.Node[4]) &&
			(0 == socketLpxAddressList.SocketLpx[idx_addr].LpxAddress.Node[5]) ) {

			SPY_LOG_PRINT( LFS_DEBUG_LFS_TRACE, ( "[LFS] LfsOpenDGSocket: We don't use SocketLpx device.\n")) ;
			continue ;

		}

		RtlCopyMemory(&NICAddr, &socketLpxAddressList.SocketLpx[idx_addr].LpxAddress, sizeof(LPX_ADDRESS)) ;
		NICAddr.Port = HTONS(PortNo) ;

		//
		//	open a connection and address.
		//	if this calling for a datagram server, don't create a connection.
		//
		ntStatus = LpxTdiOpenAddress(
				&addressFileHandle,
				&addressFileObject,
				&NICAddr
			);
		if(!NT_SUCCESS(ntStatus)) {
			SPY_LOG_PRINT( LFS_DEBUG_LFS_TRACE, ( "[LFS] LfsOpenDGSocket: couldn't open a address %d:'%02X:%02X:%02X:%02X:%02X:%02X/%d'\n",
						idx_addr,
						NICAddr.Node[0],NICAddr.Node[1],NICAddr.Node[2],
						NICAddr.Node[3],NICAddr.Node[4],NICAddr.Node[5],
						(int)NTOHS(NICAddr.Port) ) );
			continue ;
		}


		SPY_LOG_PRINT( LFS_DEBUG_LFS_TRACE, ( "[LFS] LfsOpenDGSocket: opened a address:'%02X:%02X:%02X:%02X:%02X:%02X/%d'\n",
					NICAddr.Node[0],NICAddr.Node[1],NICAddr.Node[2],
					NICAddr.Node[3],NICAddr.Node[4],NICAddr.Node[5],
					(int)NTOHS(NICAddr.Port)
			) );
		//
		//	return values
		//	close handles, but leave objects
		//
		Socket->Sockets[open_addr].AddressFile = addressFileObject ;
		Socket->Sockets[open_addr].AddressFileHandle = addressFileHandle ;
		RtlCopyMemory(&Socket->Sockets[open_addr].NICAddr, &NICAddr, sizeof(LPX_ADDRESS)) ;

		open_addr ++ ;


	}

	Socket->SocketCnt = (USHORT)open_addr ;

	return ntStatus ;
}