Fixed broadcast UDP.

lan: Added calculation of broadcast address.
fileobjs: Check for broadcast receive.
neighbor: Check for broadcast send.
interface: Use cached broadcast address.
udp: Fix port allocation.

svn path=/trunk/; revision=13223
This commit is contained in:
Art Yerkes 2005-01-23 09:51:03 +00:00
parent 063e4f41a5
commit a23df2bed0
5 changed files with 49 additions and 16 deletions

View file

@ -24,9 +24,7 @@ NTSTATUS GetInterfaceIPv4Address( PIP_INTERFACE Interface,
break;
case ADE_BROADCAST:
*Address =
Interface->Unicast.Address.IPv4Address |
~Interface->Netmask.Address.IPv4Address;
*Address = Interface->Broadcast.Address.IPv4Address;
break;
case ADE_POINTOPOINT:

View file

@ -407,10 +407,19 @@ PNEIGHBOR_CACHE_ENTRY NBFindOrCreateNeighbor(
NCE = NBLocateNeighbor(Address);
if (NCE == NULL)
{
NCE = NBAddNeighbor(Interface, Address, NULL,
Interface->AddressLength, NUD_INCOMPLETE);
NCE->EventTimer = 1;
NCE->EventCount = 0;
TI_DbgPrint(MID_TRACE,("BCAST: %s\n", A2S(&Interface->Broadcast)));
if( AddrIsEqual(Address, &Interface->Broadcast) ) {
TI_DbgPrint(MID_TRACE,("Packet targeted at broadcast addr\n"));
NCE = NBAddNeighbor(Interface, Address, NULL,
Interface->AddressLength, NUD_CONNECTED);
NCE->EventTimer = 0;
NCE->EventCount = 0;
} else {
NCE = NBAddNeighbor(Interface, Address, NULL,
Interface->AddressLength, NUD_INCOMPLETE);
NCE->EventTimer = 1;
NCE->EventCount = 0;
}
}
return NCE;

View file

@ -14,7 +14,6 @@
BOOLEAN UDPInitialized = FALSE;
PORT_SET UDPPorts;
NTSTATUS AddUDPHeaderIPv4(
PIP_ADDRESS RemoteAddress,
USHORT RemotePort,
@ -408,7 +407,7 @@ NTSTATUS UDPStartup(
RtlZeroMemory(&UDPStats, sizeof(UDP_STATISTICS));
#endif
PortsStartup( &UDPPorts, UDP_STARTING_PORT, UDP_DYNAMIC_PORTS );
PortsStartup( &UDPPorts, 1, 0xfffe );
/* Register this protocol with IP layer */
IPRegisterProtocol(IPPROTO_UDP, UDPReceive);
@ -440,9 +439,11 @@ NTSTATUS UDPShutdown(
UINT UDPAllocatePort( UINT HintPort ) {
if( HintPort ) {
if( AllocatePort( &UDPPorts, HintPort ) ) return HintPort;
else return (UINT)-1;
} else return AllocateAnyPort( &UDPPorts );
if( AllocatePort( &UDPPorts, HintPort ) ) return HintPort;
else return (UINT)-1;
} else return AllocatePortFromRange
( &UDPPorts, UDP_STARTING_PORT,
UDP_STARTING_PORT + UDP_DYNAMIC_PORTS );
}
VOID UDPFreePort( UINT Port ) {

View file

@ -907,6 +907,14 @@ VOID BindAdapter(
if(NT_SUCCESS(Status))
Status = ReadIPAddressFromRegistry( RegHandle, L"SubnetMask",
&IF->Netmask );
IF->Broadcast.Type = IP_ADDRESS_V4;
IF->Broadcast.Address.IPv4Address =
IF->Unicast.Address.IPv4Address |
~IF->Netmask.Address.IPv4Address;
TI_DbgPrint(MID_TRACE,("BCAST(IF) %s\n", A2S(&IF->Broadcast)));
if(NT_SUCCESS(Status)) {
Status = ReadStringFromRegistry( RegHandle, L"DeviceDesc",
&IF->Name );

View file

@ -43,6 +43,20 @@ PADDRESS_FILE AddrSearchFirst(
return AddrSearchNext(SearchContext);
}
BOOLEAN AddrIsBroadcast(
PIP_ADDRESS PossibleMatch,
PIP_ADDRESS TargetAddress ) {
IF_LIST_ITER(IF);
ForEachInterface(IF) {
if( AddrIsEqual( &IF->Unicast, PossibleMatch ) &&
AddrIsEqual( &IF->Broadcast, TargetAddress ) )
return TRUE;
} EndFor(IF);
return FALSE;
}
/*
* FUNCTION: Searches through address file entries to find next match
* ARGUMENTS:
@ -80,10 +94,11 @@ PADDRESS_FILE AddrSearchNext(
A2S(SearchContext->Address)));
/* See if this address matches the search criteria */
if (((Current->Port == SearchContext->Port) &&
if ((Current->Port == SearchContext->Port) &&
(Current->Protocol == SearchContext->Protocol) &&
(AddrIsEqual(IPAddress, SearchContext->Address))) ||
(AddrIsUnspecified(IPAddress))) {
(AddrIsEqual(IPAddress, SearchContext->Address) ||
AddrIsBroadcast(IPAddress, SearchContext->Address) ||
AddrIsUnspecified(IPAddress))) {
/* We've found a match */
Found = TRUE;
break;
@ -277,7 +292,9 @@ NTSTATUS FileOpenAddress(
TI_DbgPrint(MID_TRACE,("Allocating udp port\n"));
AddrFile->Port =
UDPAllocatePort(Address->Address[0].Address[0].sin_port);
TI_DbgPrint(MID_TRACE,("Setting port %d\n", AddrFile->Port));
TI_DbgPrint(MID_TRACE,("Setting port %d (wanted %d)\n",
AddrFile->Port,
Address->Address[0].Address[0].sin_port));
AddrFile->Send = UDPSendDatagram;
break;