X-Git-Url: https://git.ucc.asn.au/?a=blobdiff_plain;f=Modules%2FIPStack%2Farp.c;h=f96c2d85a6f8788eda4fe76b02914762dec16d7a;hb=25f7e9ab0f31ca486c0c981a406d381e160637a4;hp=cedc0b31eb5bdc9c02b5eff75c1d83049bf678a6;hpb=46a4b5e282c7c37f2091e7ced4db0190248a5d28;p=tpg%2Facess2.git diff --git a/Modules/IPStack/arp.c b/Modules/IPStack/arp.c index cedc0b31..f96c2d85 100644 --- a/Modules/IPStack/arp.c +++ b/Modules/IPStack/arp.c @@ -27,7 +27,7 @@ struct sARP_Cache4 { Sint64 LastUsed; } *gaARP_Cache4; int giARP_Cache4Space; -tSpinlock glARP_Cache4; +tMutex glARP_Cache4; struct sARP_Cache6 { tIPv6 IP; tMacAddr MAC; @@ -35,7 +35,7 @@ struct sARP_Cache6 { Sint64 LastUsed; } *gaARP_Cache6; int giARP_Cache6Space; -tSpinlock glARP_Cache6; +tMutex glARP_Cache6; int giARP_LastUpdateID = 0; // === CODE === @@ -68,7 +68,7 @@ tMacAddr ARP_Resolve4(tInterface *Interface, tIPv4 Address) ENTER("pInterface xAddress", Interface, Address); - LOCK( &glARP_Cache4 ); + Mutex_Acquire( &glARP_Cache4 ); for( i = 0; i < giARP_Cache4Space; i++ ) { if(gaARP_Cache4[i].IP.L != Address.L) continue; @@ -76,7 +76,7 @@ tMacAddr ARP_Resolve4(tInterface *Interface, tIPv4 Address) // Check if the entry needs to be refreshed if( now() - gaARP_Cache4[i].LastUpdate > ARP_MAX_AGE ) break; - RELEASE( &glARP_Cache4 ); + Mutex_Release( &glARP_Cache4 ); LOG("Return %x:%x:%x:%x:%x:%x", gaARP_Cache4[i].MAC.B[0], gaARP_Cache4[i].MAC.B[1], gaARP_Cache4[i].MAC.B[2], gaARP_Cache4[i].MAC.B[3], @@ -85,7 +85,7 @@ tMacAddr ARP_Resolve4(tInterface *Interface, tIPv4 Address) LEAVE('-'); return gaARP_Cache4[i].MAC; } - RELEASE( &glARP_Cache4 ); + Mutex_Release( &glARP_Cache4 ); lastID = giARP_LastUpdateID; @@ -112,15 +112,15 @@ tMacAddr ARP_Resolve4(tInterface *Interface, tIPv4 Address) while(lastID == giARP_LastUpdateID) Threads_Yield(); lastID = giARP_LastUpdateID; - LOCK( &glARP_Cache4 ); + Mutex_Acquire( &glARP_Cache4 ); for( i = 0; i < giARP_Cache4Space; i++ ) { if(gaARP_Cache4[i].IP.L != Address.L) continue; - RELEASE( &glARP_Cache4 ); + Mutex_Release( &glARP_Cache4 ); return gaARP_Cache4[i].MAC; } - RELEASE( &glARP_Cache4 ); + Mutex_Release( &glARP_Cache4 ); } } @@ -134,7 +134,7 @@ void ARP_UpdateCache4(tIPv4 SWAddr, tMacAddr HWAddr) int oldest = 0; // Find an entry for the IP address in the cache - LOCK(&glARP_Cache4); + Mutex_Acquire(&glARP_Cache4); for( i = giARP_Cache4Space; i--; ) { if(gaARP_Cache4[oldest].LastUpdate > gaARP_Cache4[i].LastUpdate) { @@ -161,7 +161,7 @@ void ARP_UpdateCache4(tIPv4 SWAddr, tMacAddr HWAddr) gaARP_Cache4[i].MAC = HWAddr; gaARP_Cache4[i].LastUpdate = now(); giARP_LastUpdateID ++; - RELEASE(&glARP_Cache4); + Mutex_Release(&glARP_Cache4); } /** @@ -174,7 +174,7 @@ void ARP_UpdateCache6(tIPv6 SWAddr, tMacAddr HWAddr) int oldest = 0; // Find an entry for the MAC address in the cache - LOCK(&glARP_Cache6); + Mutex_Acquire(&glARP_Cache6); for( i = giARP_Cache6Space; i--; ) { if(gaARP_Cache6[oldest].LastUpdate > gaARP_Cache6[i].LastUpdate) { @@ -195,7 +195,7 @@ void ARP_UpdateCache6(tIPv6 SWAddr, tMacAddr HWAddr) gaARP_Cache6[i].IP = SWAddr; gaARP_Cache6[i].LastUpdate = now(); giARP_LastUpdateID ++; - RELEASE(&glARP_Cache6); + Mutex_Release(&glARP_Cache6); } /** @@ -209,18 +209,19 @@ void ARP_int_GetPacket(tAdapter *Adapter, tMacAddr From, int Length, void *Buffe tInterface *iface; // Sanity Check Packet - if( Length < sizeof(tArpRequest4) ) { + if( Length < (int)sizeof(tArpRequest4) ) { Log_Log("ARP", "Recieved undersized packet"); return ; } if( ntohs(req4->Type) != 0x0800 ) { - Log_Log("ARP", "Recieved a packet with a bad type 0x%x", ntohs(req4->Type)); + Log_Log("ARP", "Recieved a packet with a bad type (0x%x)", ntohs(req4->Type)); return ; } if( req4->HWSize != 6 ) { Log_Log("ARP", "Recieved a packet with HWSize != 6 (%i)", req4->HWSize); return; } + #if ARP_DETECT_SPOOFS if( !MAC_EQU(req4->SourceMac, From) ) { Log_Log("ARP", "ARP spoofing detected " "(%02x%02x:%02x%02x:%02x%02x != %02x%02x:%02x%02x:%02x%02x)", @@ -231,35 +232,35 @@ void ARP_int_GetPacket(tAdapter *Adapter, tMacAddr From, int Length, void *Buffe ); return; } + #endif - Log("[ARP ] Request ID %i", ntohs(req4->Request)); + Log_Debug("ARP", "Request ID %i", ntohs(req4->Request)); switch( ntohs(req4->Request) ) { case 1: // You want my IP? - Log("[ARP ] ARP Request Address class %i", req4->SWSize); + Log_Debug("ARP", "ARP Request Address class %i", req4->SWSize); // Check what type of IP it is switch( req4->SWSize ) { case 4: - Log("[ARP ] From MAC %02x:%02x:%02x:%02x:%02x:%02x", + 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("[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("[ARP ] ARP Request IPv4 Address %i.%i.%i.%i", + //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]); - Log("[ARP ] from %i.%i.%i.%i", + req4->DestIP.B[3], req4->SourceIP.B[0], req4->SourceIP.B[1], req4->SourceIP.B[2], req4->SourceIP.B[3]); iface = IPv4_GetInterface(Adapter, req4->DestIP, 0); if( iface ) { - Log("[ARP ] Caching sender's IP Address"); + Log_Debug("ARP", "Caching sender's IP Address"); ARP_UpdateCache4(req4->SourceIP, req4->SourceMac); req4->DestIP = req4->SourceIP; @@ -267,8 +268,7 @@ void ARP_int_GetPacket(tAdapter *Adapter, tMacAddr From, int Length, void *Buffe req4->SourceIP = iface->IP4.Address; req4->SourceMac = Adapter->MacAddr; req4->Request = htons(2); - Log("[ARP ] Hey, That's us!"); - Log("[ARP ] Sending back %02x:%02x:%02x:%02x:%02x:%02x", + Log_Debug("ARP", "Sending back us (%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]); @@ -276,10 +276,14 @@ void ARP_int_GetPacket(tAdapter *Adapter, tMacAddr From, int Length, void *Buffe } break; case 6: - if( Length < sizeof(tArpRequest6) ) { - Log("[ARP ] Recieved undersized packet (IPv6)"); + if( Length < (int)sizeof(tArpRequest6) ) { + Log_Log("ARP", "Recieved undersized packet (IPv6)"); return ; } + Log_Debug("ARP", "ARP Request IPv6 Address %08x:%08x:%08x:%08x", + ntohl(req6->DestIP.L[0]), ntohl(req6->DestIP.L[1]), + ntohl(req6->DestIP.L[2]), ntohl(req6->DestIP.L[3]) + ); iface = IPv6_GetInterface(Adapter, req6->DestIP, 0); if( iface ) { @@ -288,11 +292,15 @@ void ARP_int_GetPacket(tAdapter *Adapter, tMacAddr From, int Length, void *Buffe req6->SourceIP = iface->IP6.Address; req6->SourceMac = Adapter->MacAddr; req6->Request = htons(2); + Log_Debug("ARP", "Sending back us (%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]); Link_SendPacket(Adapter, 0x0806, req6->DestMac, sizeof(tArpRequest6), req6); } break; default: - Log("[ARP ] Unknown Protocol Address size (%i)", req4->SWSize); + Log_Debug("ARP", "Unknown Protocol Address size (%i)", req4->SWSize); return ; } @@ -306,21 +314,21 @@ void ARP_int_GetPacket(tAdapter *Adapter, tMacAddr From, int Length, void *Buffe ARP_UpdateCache4( req4->SourceIP, From ); break; case 6: - if( Length < sizeof(tArpRequest6) ) { - Log("[ARP ] Recieved undersized packet (IPv6)"); + if( Length < (int)sizeof(tArpRequest6) ) { + Log_Debug("ARP", "Recieved undersized packet (IPv6)"); return ; } ARP_UpdateCache6( req6->SourceIP, From ); break; default: - Log("[ARP ] Unknown Protocol Address size (%i)", req4->SWSize); + Log_Debug("ARP", "Unknown Protocol Address size (%i)", req4->SWSize); return ; } break; default: - Warning("[ARP ] Unknown Request ID %i", ntohs(req4->Request)); + Log_Warning("ARP", "Unknown Request ID %i", ntohs(req4->Request)); break; } }