- Put the correct source address in Raw IP and UDP packets
authorCameron Gutman <aicommander@gmail.com>
Tue, 30 Jun 2009 21:14:21 +0000 (21:14 +0000)
committerCameron Gutman <aicommander@gmail.com>
Tue, 30 Jun 2009 21:14:21 +0000 (21:14 +0000)
 - Remove (now unused) IPGetDefaultAddress which just broke things
 - Fixes responses from different IP addresses when trying to ping the loopback adapter
 - See issue #4573 for more details

svn path=/trunk/; revision=41720

reactos/drivers/network/tcpip/include/address.h
reactos/lib/drivers/ip/network/interface.c
reactos/lib/drivers/ip/transport/rawip/rawip.c
reactos/lib/drivers/ip/transport/udp/udp.c

index 65abace..73d5dbb 100644 (file)
@@ -58,8 +58,6 @@ BOOLEAN AddrIsEqualIPv4(
 BOOLEAN AddrLocateADEv4(
     IPv4_RAW_ADDRESS MatchAddress, PIP_ADDRESS Address);
 
-BOOLEAN IPGetDefaultAddress( PIP_ADDRESS Address );
-
 PADDRESS_FILE AddrSearchFirst(
     PIP_ADDRESS Address,
     USHORT Port,
index b122863..7e3f907 100644 (file)
@@ -112,34 +112,6 @@ BOOLEAN AddrLocateADEv4(
     return Matched;
 }
 
-BOOLEAN IPGetDefaultAddress( PIP_ADDRESS Address ) {
-    KIRQL OldIrql;
-    BOOLEAN Matched = FALSE;
-    IF_LIST_ITER(CurrentIF);
-
-    TcpipAcquireSpinLock(&InterfaceListLock, &OldIrql);
-
-    /* Find the first 'real' interface */
-    ForEachInterface(CurrentIF) {
-       if( CurrentIF->Context ) {
-           *Address = CurrentIF->Unicast;
-           Matched = TRUE; break;
-       }
-    } EndFor(CurrentIF);
-
-    /* Not matched, use the first one */
-    if( !Matched ) {
-       ForEachInterface(CurrentIF) {
-           *Address = CurrentIF->Unicast;
-           Matched = TRUE; break;
-       } EndFor(CurrentIF);
-    }
-
-    TcpipReleaseSpinLock(&InterfaceListLock, OldIrql);
-
-    return Matched;
-}
-
 BOOLEAN HasPrefix(
     PIP_ADDRESS Address,
     PIP_ADDRESS Prefix,
index 2c8b570..aeb4cf1 100644 (file)
@@ -210,11 +210,19 @@ NTSTATUS RawIPSendDatagram(
        return STATUS_UNSUCCESSFUL;
     }
 
+    TI_DbgPrint(MID_TRACE,("About to get route to destination\n"));
+
+    if(!(NCE = RouteGetRouteToDestination( &RemoteAddress )))
+       return STATUS_NETWORK_UNREACHABLE;
+
     LocalAddress = AddrFile->Address;
     if (AddrIsUnspecified(&LocalAddress))
     {
-        if (!IPGetDefaultAddress(&LocalAddress))
-            return STATUS_UNSUCCESSFUL;
+        /* If the local address is unspecified (0),
+         * then use the unicast address of the
+         * interface we're sending over
+         */
+        LocalAddress = NCE->Interface->Unicast;
     }
 
     Status = BuildRawIpPacket( &Packet,
@@ -228,13 +236,6 @@ NTSTATUS RawIPSendDatagram(
     if( !NT_SUCCESS(Status) )
        return Status;
 
-    TI_DbgPrint(MID_TRACE,("About to get route to destination\n"));
-
-    if(!(NCE = RouteGetRouteToDestination( &RemoteAddress ))) {
-        FreeNdisPacket(Packet.NdisPacket);
-       return STATUS_NETWORK_UNREACHABLE;
-    }
-
     TI_DbgPrint(MID_TRACE,("About to send datagram\n"));
 
     if (!NT_SUCCESS(Status = IPSendDatagram( &Packet, NCE, RawIpSendPacketComplete, NULL )))
index a3d3ec0..0b586b9 100644 (file)
@@ -161,7 +161,7 @@ NTSTATUS UDPSendDatagram(
     IP_PACKET Packet;
     PTA_IP_ADDRESS RemoteAddressTa = (PTA_IP_ADDRESS)ConnInfo->RemoteAddress;
     IP_ADDRESS RemoteAddress;
-       IP_ADDRESS LocalAddress;
+    IP_ADDRESS LocalAddress;
     USHORT RemotePort;
     NTSTATUS Status;
     PNEIGHBOR_CACHE_ENTRY NCE;
@@ -186,12 +186,15 @@ NTSTATUS UDPSendDatagram(
                return STATUS_NETWORK_UNREACHABLE;
     }
 
-       LocalAddress = AddrFile->Address;
-       if (AddrIsUnspecified(&LocalAddress))
-       {
-               if (!IPGetDefaultAddress(&LocalAddress))
-                       return FALSE;
-       }
+    LocalAddress = AddrFile->Address;
+    if (AddrIsUnspecified(&LocalAddress))
+    {
+        /* If the local address is unspecified (0),
+         * then use the unicast address of the
+         * interface we're sending over
+         */
+        LocalAddress = NCE->Interface->Unicast;
+    }
 
     Status = BuildUDPPacket( &Packet,
                                                         &RemoteAddress,