#include "arp.h"
#include "link.h"
+#define ARPv6 1
#define ARP_CACHE_SIZE 64
#define ARP_MAX_AGE (60*60*1000) // 1Hr
// === IMPORTS ===
extern tInterface *IPv4_GetInterface(tAdapter *Adapter, tIPv4 Address, int Broadcast);
+#if ARPv6
extern tInterface *IPv6_GetInterface(tAdapter *Adapter, tIPv6 Address, int Broadcast);
+#endif
// === PROTOTYPES ===
int ARP_Initialise();
Sint64 LastUsed;
} *gaARP_Cache4;
int giARP_Cache4Space;
-tSpinlock glARP_Cache4;
+tMutex glARP_Cache4;
+#if ARPv6
struct sARP_Cache6 {
tIPv6 IP;
tMacAddr MAC;
Sint64 LastUsed;
} *gaARP_Cache6;
int giARP_Cache6Space;
-tSpinlock glARP_Cache6;
+tMutex glARP_Cache6;
+#endif
int giARP_LastUpdateID = 0;
// === CODE ===
memset( gaARP_Cache4, 0, ARP_CACHE_SIZE * sizeof(struct sARP_Cache4) );
giARP_Cache4Space = ARP_CACHE_SIZE;
+ #if ARPv6
gaARP_Cache6 = malloc( ARP_CACHE_SIZE * sizeof(struct sARP_Cache6) );
memset( gaARP_Cache6, 0, ARP_CACHE_SIZE * sizeof(struct sARP_Cache6) );
giARP_Cache6Space = ARP_CACHE_SIZE;
+ #endif
Link_RegisterType(0x0806, ARP_int_GetPacket);
return 1;
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;
// 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],
LEAVE('-');
return gaARP_Cache4[i].MAC;
}
- RELEASE( &glARP_Cache4 );
+ Mutex_Release( &glARP_Cache4 );
lastID = giARP_LastUpdateID;
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 );
}
}
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) {
gaARP_Cache4[i].MAC = HWAddr;
gaARP_Cache4[i].LastUpdate = now();
giARP_LastUpdateID ++;
- RELEASE(&glARP_Cache4);
+ Mutex_Release(&glARP_Cache4);
}
+#if ARPv6
/**
* \brief Updates the ARP Cache entry for an IPv6 Address
*/
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) {
gaARP_Cache6[i].IP = SWAddr;
gaARP_Cache6[i].LastUpdate = now();
giARP_LastUpdateID ++;
- RELEASE(&glARP_Cache6);
+ Mutex_Release(&glARP_Cache6);
}
+#endif
/**
* \fn void ARP_int_GetPacket(tAdapter *Adapter, tMacAddr From, int Length, void *Buffer)
void ARP_int_GetPacket(tAdapter *Adapter, tMacAddr From, int Length, void *Buffer)
{
tArpRequest4 *req4 = Buffer;
+ #if ARPv6
tArpRequest6 *req6 = Buffer;
+ #endif
tInterface *iface;
// Sanity Check Packet
Link_SendPacket(Adapter, 0x0806, req4->DestMac, sizeof(tArpRequest4), req4);
}
break;
+ #if ARPv6
case 6:
if( Length < (int)sizeof(tArpRequest6) ) {
Log_Log("ARP", "Recieved undersized packet (IPv6)");
Link_SendPacket(Adapter, 0x0806, req6->DestMac, sizeof(tArpRequest6), req6);
}
break;
+ #endif
default:
Log_Debug("ARP", "Unknown Protocol Address size (%i)", req4->SWSize);
return ;
case 4:
ARP_UpdateCache4( req4->SourceIP, From );
break;
+ #if ARPv6
case 6:
if( Length < (int)sizeof(tArpRequest6) ) {
Log_Debug("ARP", "Recieved undersized packet (IPv6)");
}
ARP_UpdateCache6( req6->SourceIP, From );
break;
+ #endif
default:
Log_Debug("ARP", "Unknown Protocol Address size (%i)", req4->SWSize);
return ;