[IP]
authorCameron Gutman <aicommander@gmail.com>
Wed, 30 Dec 2009 12:46:14 +0000 (12:46 +0000)
committerCameron Gutman <aicommander@gmail.com>
Wed, 30 Dec 2009 12:46:14 +0000 (12:46 +0000)
 - Bind to the address specified in AddressFile instead of always binding to the outgoing interface's unicast address
 - Get the NCE using the local address (if specified) so we don't end up sending from one interface using another interface's  address as the source

svn path=/branches/aicom-network-branch/; revision=44810

lib/drivers/ip/network/icmp.c
lib/drivers/ip/transport/rawip/rawip.c
lib/drivers/ip/transport/tcp/tcp.c
lib/drivers/ip/transport/udp/udp.c

index 6802230..33a487d 100644 (file)
@@ -178,9 +178,6 @@ NTSTATUS ICMPSendDatagram(
 
     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))
     {
@@ -188,8 +185,16 @@ NTSTATUS ICMPSendDatagram(
          * then use the unicast address of the
          * interface we're sending over
          */
+        if(!(NCE = RouteGetRouteToDestination( &RemoteAddress )))
+            return STATUS_NETWORK_UNREACHABLE;
+
         LocalAddress = NCE->Interface->Unicast;
     }
+    else
+    {
+        if(!(NCE = NBLocateNeighbor( &LocalAddress )))
+            return STATUS_INVALID_PARAMETER;
+    }
 
     Status = PrepareICMPPacket( NCE->Interface,
                                 &Packet,
index 328337c..44c6465 100644 (file)
@@ -218,12 +218,6 @@ NTSTATUS RawIPSendDatagram(
 
     TI_DbgPrint(MID_TRACE,("About to get route to destination\n"));
 
-    if(!(NCE = RouteGetRouteToDestination( &RemoteAddress )))
-    {
-       KeReleaseSpinLock(&AddrFile->Lock, OldIrql);
-       return STATUS_NETWORK_UNREACHABLE;
-    }
-
     LocalAddress = AddrFile->Address;
     if (AddrIsUnspecified(&LocalAddress))
     {
@@ -231,8 +225,20 @@ NTSTATUS RawIPSendDatagram(
          * then use the unicast address of the
          * interface we're sending over
          */
+        if(!(NCE = RouteGetRouteToDestination( &RemoteAddress ))) {
+            KeReleaseSpinLock(&AddrFile->Lock, OldIrql);
+            return STATUS_NETWORK_UNREACHABLE;
+        }
+
         LocalAddress = NCE->Interface->Unicast;
     }
+    else
+    {
+        if(!(NCE = NBLocateNeighbor( &LocalAddress ))) {
+            KeReleaseSpinLock(&AddrFile->Lock, OldIrql);
+            return STATUS_INVALID_PARAMETER;
+        }
+    }
 
     Status = BuildRawIpPacket( AddrFile,
                                &Packet,
index fe57112..0d1710a 100644 (file)
@@ -631,11 +631,6 @@ NTSTATUS TCPConnect
         return Status;
     }
 
-    if (!(NCE = RouteGetRouteToDestination(&RemoteAddress)))
-    {
-        return STATUS_NETWORK_UNREACHABLE;
-    }
-
     /* Freed in TCPSocketState */
     TI_DbgPrint(DEBUG_TCP,
                 ("Connecting to address %x:%x\n",
@@ -644,10 +639,30 @@ NTSTATUS TCPConnect
 
     AddressToConnect.sin_family = AF_INET;
     AddressToBind = AddressToConnect;
-    AddressToBind.sin_addr.s_addr = NCE->Interface->Unicast.Address.IPv4Address;
 
     KeAcquireSpinLock(&Connection->Lock, &OldIrql);
 
+    if (!Connection->AddressFile)
+    {
+        KeReleaseSpinLock(&Connection->Lock, OldIrql);
+        return STATUS_INVALID_PARAMETER;
+    }
+
+    if (AddrIsUnspecified(&Connection->AddressFile->Address))
+    {
+        if (!(NCE = RouteGetRouteToDestination(&RemoteAddress)))
+        {
+            KeReleaseSpinLock(&Connection->Lock, OldIrql);
+            return STATUS_NETWORK_UNREACHABLE;
+        }
+
+        AddressToBind.sin_addr.s_addr = NCE->Interface->Unicast.Address.IPv4Address;
+    }
+    else
+    {
+        AddressToBind.sin_addr.s_addr = Connection->AddressFile->Address.Address.IPv4Address;
+    }
+
     Status = TCPTranslateError
         ( OskitTCPBind( Connection->SocketContext,
                         &AddressToBind,
index 125e510..510e882 100644 (file)
@@ -193,11 +193,6 @@ NTSTATUS UDPSendDatagram(
                return STATUS_UNSUCCESSFUL;
     }
 
-    if(!(NCE = RouteGetRouteToDestination( &RemoteAddress ))) {
-               KeReleaseSpinLock(&AddrFile->Lock, OldIrql);
-               return STATUS_NETWORK_UNREACHABLE;
-    }
-
     LocalAddress = AddrFile->Address;
     if (AddrIsUnspecified(&LocalAddress))
     {
@@ -205,8 +200,20 @@ NTSTATUS UDPSendDatagram(
          * then use the unicast address of the
          * interface we're sending over
          */
+        if(!(NCE = RouteGetRouteToDestination( &RemoteAddress ))) {
+            KeReleaseSpinLock(&AddrFile->Lock, OldIrql);
+            return STATUS_NETWORK_UNREACHABLE;
+        }
+
         LocalAddress = NCE->Interface->Unicast;
     }
+    else
+    {
+        if(!(NCE = NBLocateNeighbor( &LocalAddress ))) {
+            KeReleaseSpinLock(&AddrFile->Lock, OldIrql);
+            return STATUS_INVALID_PARAMETER;
+        }
+    }
 
     Status = BuildUDPPacket( AddrFile,
                                                         &Packet,