Misc changes
[tpg/acess2.git] / Modules / IPStack / arp.c
index 9e92414..e5d8a2b 100644 (file)
@@ -73,19 +73,20 @@ tMacAddr ARP_Resolve4(tInterface *Interface, tIPv4 Address)
         int    lastID;
         int    i;
        struct sArpRequest4     req;
+       Sint64  timeout;
        
        ENTER("pInterface xAddress", Interface, Address);
        
-       // Check routing tables
+       // Check routing tables if not on this subnet
+       if( IPStack_CompareAddress(4, &Address, Interface->Address, Interface->SubnetBits) == 0 )
        {
                tRoute  *route = IPStack_FindRoute(4, Interface, &Address);
-               if( route ) {
-                       // If the next hop is defined, use it
-                       // - 0.0.0.0 as the next hop means "no next hop / direct"
-                       if( ((tIPv4*)route->NextHop)->L != 0 ) {
-                               // Recursion: see /Recursion/
-                               return ARP_Resolve4(Interface, *(tIPv4*)route->NextHop);
-                       }
+               // If the next hop is defined, use it
+               // - 0.0.0.0 as the next hop means "no next hop / direct"
+               if( route && ((tIPv4*)route->NextHop)->L != 0 )
+               {
+                       // Recursion: see /Recursion/
+                       return ARP_Resolve4(Interface, *(tIPv4*)route->NextHop);
                }
        }
        
@@ -128,10 +129,18 @@ tMacAddr ARP_Resolve4(tInterface *Interface, tIPv4 Address)
        // Send Request
        Link_SendPacket(Interface->Adapter, 0x0806, req.DestMac, sizeof(struct sArpRequest4), &req);
        
+       timeout = now() + Interface->TimeoutDelay;
+       
        // Wait for a reply
        for(;;)
        {
-               while(lastID == giARP_LastUpdateID)     Threads_Yield();
+               while(lastID == giARP_LastUpdateID && now() < timeout) {
+//                     Log_Debug("ARP", "timeout = %lli", timeout);
+                       Threads_Yield();
+               }
+               
+               if( now() >= timeout )  break;  // Timeout
+               
                lastID = giARP_LastUpdateID;
                
                Mutex_Acquire( &glARP_Cache4 );
@@ -144,6 +153,10 @@ tMacAddr ARP_Resolve4(tInterface *Interface, tIPv4 Address)
                }
                Mutex_Release( &glARP_Cache4 );
        }
+       {
+               tMacAddr        ret = {{0,0,0,0,0,0}};
+               return ret;
+       }
 }
 
 /**
@@ -260,33 +273,25 @@ void ARP_int_GetPacket(tAdapter *Adapter, tMacAddr From, int Length, void *Buffe
        }
        #endif
        
-       Log_Debug("ARP", "Request ID %i", ntohs(req4->Request));
-       
        switch( ntohs(req4->Request) )
        {
        case 1: // You want my IP?
-               Log_Debug("ARP", "ARP Request Address class %i", req4->SWSize);
                // Check what type of IP it is
                switch( req4->SWSize )
                {
                case 4:
-                       Log_Debug("ARP", "From MAC %02x:%02x:%02x:%02x:%02x:%02x",
-                               req4->SourceMac.B[0], req4->SourceMac.B[1],
-                               req4->SourceMac.B[2], req4->SourceMac.B[3],
-                               req4->SourceMac.B[4], req4->SourceMac.B[5]);
-                       //Log_Debug("ARP", "to MAC %02x:%02x:%02x:%02x:%02x:%02x",
-                       //      req4->DestMac.B[0], req4->DestMac.B[1],
-                       //      req4->DestMac.B[2], req4->DestMac.B[3],
-                       //      req4->DestMac.B[4], req4->DestMac.B[5]);
                        Log_Debug("ARP", "ARP Request IPv4 Address %i.%i.%i.%i from %i.%i.%i.%i",
                                req4->DestIP.B[0], req4->DestIP.B[1], req4->DestIP.B[2],
                                req4->DestIP.B[3],
                                req4->SourceIP.B[0], req4->SourceIP.B[1],
                                req4->SourceIP.B[2], req4->SourceIP.B[3]);
+                       Log_Debug("ARP", " from MAC %02x:%02x:%02x:%02x:%02x:%02x",
+                               req4->SourceMac.B[0], req4->SourceMac.B[1],
+                               req4->SourceMac.B[2], req4->SourceMac.B[3],
+                               req4->SourceMac.B[4], req4->SourceMac.B[5]);
                        iface = IPv4_GetInterface(Adapter, req4->DestIP, 0);
                        if( iface )
                        {
-                               Log_Debug("ARP", "Caching sender's IP Address");
                                ARP_UpdateCache4(req4->SourceIP, req4->SourceMac);
                                
                                req4->DestIP = req4->SourceIP;

UCC git Repository :: git.ucc.asn.au