Adding several modules to the Tree, plus some files that escaped earlier
[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 Uint32   IPv4_Netmask(int FixedBits);
11
12 // === PROTOTYPES ===
13  int    IPv6_Initialise();
14 void    IPv6_int_GetPacket(tAdapter *Interface, tMacAddr From, int Length, void *Buffer);
15 tInterface      *IPv6_GetInterface(tAdapter *Adapter, tIPv6 Address, int Broadcast);
16
17 // === CODE ===
18 /**
19  * \fn int IPv6_Initialise()
20  */
21 int IPv6_Initialise()
22 {
23         Link_RegisterType(IPV6_ETHERNET_ID, IPv6_int_GetPacket);
24         return 1;
25 }
26
27 /**
28  * \fn void IPv6_int_GetPacket(tInterface *Interface, tMacAddr From, int Length, void *Buffer)
29  * \brief Process an IPv6 Packet
30  */
31 void IPv6_int_GetPacket(tAdapter *Interface, tMacAddr From, int Length, void *Buffer)
32 {
33         tIPv6Header     *hdr = Buffer;
34         if(Length < sizeof(tIPv6Header))        return;
35         
36         if(hdr->Version != 6)   return;
37 }
38
39 /**
40  * \fn tInterface *IPv6_GetInterface(tAdapter *Adapter, tIPv6 Address)
41  * \brief Searches an adapter for a matching address
42  */
43 tInterface *IPv6_GetInterface(tAdapter *Adapter, tIPv6 Address, int Broadcast)
44 {
45          int    i, j;
46         tInterface      *iface = NULL;
47         Uint32  netmask;
48         
49         for( iface = Adapter->Interfaces; iface; iface = iface->Next)
50         {
51                 // Skip non-IPv6 Interfaces
52                 if( iface->Type != 6 )  continue;
53                 
54                 // If the address is a perfect match, return this interface
55                 if( IP6_EQU(Address, iface->IP6.Address) )      return iface;
56                 
57                 // Check if we want to match broadcast addresses
58                 if( !Broadcast )        continue;
59                 
60                 // Check for broadcast
61                 if( iface->IP6.SubnetBits > 32 && Address.L[0] != iface->IP6.Address.L[0] )
62                         continue;
63                 if( iface->IP6.SubnetBits > 64 && Address.L[1] != iface->IP6.Address.L[1] )
64                         continue;
65                 if( iface->IP6.SubnetBits > 96 && Address.L[2] != iface->IP6.Address.L[2] )
66                         continue;
67                 
68                 j = iface->IP6.SubnetBits / 32;
69                 i = iface->IP6.SubnetBits % 32;
70                 netmask = IPv4_Netmask( iface->IP6.SubnetBits % 32 );
71                 
72                 // Check the last bit of the netmask
73                 if( (Address.L[j] >> i) != (iface->IP6.Address.L[j] >> i) )     continue;
74                 
75                 // Check that the host portion is one
76                 if( (Address.L[j] & ~netmask) != (0xFFFFFFFF & ~netmask) )      continue;
77                 if( j >= 2 && Address.L[3] != 0xFFFFFFFF)       continue;
78                 if( j >= 1 && Address.L[2] != 0xFFFFFFFF)       continue;
79                 if( j >= 0 && Address.L[1] != 0xFFFFFFFF)       continue;
80                 
81                 return iface;
82         }
83         return NULL;
84 }

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