Cleanups & Implementations to allow IPStack to compile
[tpg/acess2.git] / Modules / IPStack / ipv6.c
1 /*
2  * Acess2 IP Stack
3  * - IPv6 Protcol Handling
4  */
5 #include "ipstack.h"
6 #include "link.h"
7 #include "ipv6.h"
8
9 // === IMPORTS ===
10 extern tInterface       *gIP_Interfaces;
11 extern Uint32   IPv4_Netmask(int FixedBits);
12
13 // === PROTOTYPES ===
14  int    IPv6_Initialise();
15 void    IPv6_int_GetPacket(tAdapter *Interface, tMacAddr From, int Length, void *Buffer);
16 tInterface      *IPv6_GetInterface(tAdapter *Adapter, tIPv6 Address, int Broadcast);
17
18 // === CODE ===
19 /**
20  * \fn int IPv6_Initialise()
21  */
22 int IPv6_Initialise()
23 {
24         Link_RegisterType(IPV6_ETHERNET_ID, IPv6_int_GetPacket);
25         return 1;
26 }
27
28 /**
29  * \fn void IPv6_int_GetPacket(tInterface *Interface, tMacAddr From, int Length, void *Buffer)
30  * \brief Process an IPv6 Packet
31  */
32 void IPv6_int_GetPacket(tAdapter *Interface, tMacAddr From, int Length, void *Buffer)
33 {
34         tIPv6Header     *hdr = Buffer;
35         if(Length < sizeof(tIPv6Header))        return;
36         
37         if(hdr->Version != 6)   return;
38 }
39
40 /**
41  * \fn tInterface *IPv6_GetInterface(tAdapter *Adapter, tIPv6 Address)
42  * \brief Searches an adapter for a matching address
43  */
44 tInterface *IPv6_GetInterface(tAdapter *Adapter, tIPv6 Address, int Broadcast)
45 {
46          int    i, j;
47         tInterface      *iface = NULL;
48         Uint32  netmask;
49         
50         for( iface = gIP_Interfaces; iface; iface = iface->Next)
51         {
52                 // Check for this adapter
53                 if( iface->Adapter != Adapter ) continue;
54                 
55                 // Skip non-IPv6 Interfaces
56                 if( iface->Type != 6 )  continue;
57                 
58                 // If the address is a perfect match, return this interface
59                 if( IP6_EQU(Address, iface->IP6.Address) )      return iface;
60                 
61                 // Check if we want to match broadcast addresses
62                 if( !Broadcast )        continue;
63                 
64                 // Check for broadcast
65                 if( iface->IP6.SubnetBits > 32 && Address.L[0] != iface->IP6.Address.L[0] )
66                         continue;
67                 if( iface->IP6.SubnetBits > 64 && Address.L[1] != iface->IP6.Address.L[1] )
68                         continue;
69                 if( iface->IP6.SubnetBits > 96 && Address.L[2] != iface->IP6.Address.L[2] )
70                         continue;
71                 
72                 j = iface->IP6.SubnetBits / 32;
73                 i = iface->IP6.SubnetBits % 32;
74                 netmask = IPv4_Netmask( iface->IP6.SubnetBits % 32 );
75                 
76                 // Check the last bit of the netmask
77                 if( (Address.L[j] >> i) != (iface->IP6.Address.L[j] >> i) )     continue;
78                 
79                 // Check that the host portion is one
80                 if( (Address.L[j] & ~netmask) != (0xFFFFFFFF & ~netmask) )      continue;
81                 if( j >= 2 && Address.L[3] != 0xFFFFFFFF)       continue;
82                 if( j >= 1 && Address.L[2] != 0xFFFFFFFF)       continue;
83                 if( j >= 0 && Address.L[1] != 0xFFFFFFFF)       continue;
84                 
85                 return iface;
86         }
87         return NULL;
88 }

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