From a23df2bed01bd4f09b6c9f949a52cb3d06813f22 Mon Sep 17 00:00:00 2001 From: Art Yerkes Date: Sun, 23 Jan 2005 09:51:03 +0000 Subject: [PATCH] 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 --- reactos/drivers/lib/ip/network/interface.c | 4 +--- reactos/drivers/lib/ip/network/neighbor.c | 17 +++++++++++---- reactos/drivers/lib/ip/transport/udp/udp.c | 11 +++++----- reactos/drivers/net/tcpip/datalink/lan.c | 8 +++++++ reactos/drivers/net/tcpip/tcpip/fileobjs.c | 25 ++++++++++++++++++---- 5 files changed, 49 insertions(+), 16 deletions(-) diff --git a/reactos/drivers/lib/ip/network/interface.c b/reactos/drivers/lib/ip/network/interface.c index 664d86f0e4d..8094c43050f 100644 --- a/reactos/drivers/lib/ip/network/interface.c +++ b/reactos/drivers/lib/ip/network/interface.c @@ -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: diff --git a/reactos/drivers/lib/ip/network/neighbor.c b/reactos/drivers/lib/ip/network/neighbor.c index 49f650ff276..b21f6f3df58 100644 --- a/reactos/drivers/lib/ip/network/neighbor.c +++ b/reactos/drivers/lib/ip/network/neighbor.c @@ -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; diff --git a/reactos/drivers/lib/ip/transport/udp/udp.c b/reactos/drivers/lib/ip/transport/udp/udp.c index 348458334a7..0fbb5d61545 100644 --- a/reactos/drivers/lib/ip/transport/udp/udp.c +++ b/reactos/drivers/lib/ip/transport/udp/udp.c @@ -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 ) { diff --git a/reactos/drivers/net/tcpip/datalink/lan.c b/reactos/drivers/net/tcpip/datalink/lan.c index 731706ed0c9..4633b63c543 100644 --- a/reactos/drivers/net/tcpip/datalink/lan.c +++ b/reactos/drivers/net/tcpip/datalink/lan.c @@ -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 ); diff --git a/reactos/drivers/net/tcpip/tcpip/fileobjs.c b/reactos/drivers/net/tcpip/tcpip/fileobjs.c index 55116adbed6..77a623ff00b 100644 --- a/reactos/drivers/net/tcpip/tcpip/fileobjs.c +++ b/reactos/drivers/net/tcpip/tcpip/fileobjs.c @@ -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;