Modules/IPStack - Abstract HW addr cache, IPv6 TX (no ND yet)
[tpg/acess2.git] / KernelLand / Modules / IPStack / main.c
index 5763e2d..82373ec 100644 (file)
@@ -9,19 +9,10 @@
 #include <modules.h>
 #include <fs_devfs.h>
 #include "include/adapters.h"
+#include "interface.h"
+#include "init.h"
 
 // === IMPORTS ===
-extern int     ARP_Initialise();
-extern void    UDP_Initialise();
-extern void    TCP_Initialise();
-extern int     IPv4_Initialise();
-extern int     IPv6_Initialise();
-
-extern char    *IPStack_Root_ReadDir(tVFS_Node *Node, int Pos);
-extern tVFS_Node       *IPStack_Root_FindDir(tVFS_Node *Node, const char *Name);
-extern int     IPStack_Root_IOCtl(tVFS_Node *Node, int ID, void *Data);
-extern tInterface      gIP_LoopInterface;
-extern tInterface      *IPStack_AddInterface(const char *Device, const char *Name);
 extern tRoute  *IPStack_AddRoute(const char *Interface, void *Network, int SubnetBits, void *NextHop, int Metric);
 
 // === PROTOTYPES ===
@@ -30,11 +21,6 @@ extern tRoute        *IPStack_AddRoute(const char *Interface, void *Network, int Subnet
 
 // === GLOBALS ===
 MODULE_DEFINE(0, VERSION, IPStack, IPStack_Install, NULL, NULL);
-tVFS_NodeType  gIP_RootNodeType = {
-       .ReadDir = IPStack_Root_ReadDir,
-       .FindDir = IPStack_Root_FindDir,
-       .IOCtl = IPStack_Root_IOCtl
-};
 tDevFS_Driver  gIP_DriverInfo = {
        NULL, "ip",
        {
@@ -122,6 +108,26 @@ int IPStack_CompareAddress(int AddressType, const void *Address1, const void *Ad
        return 0;
 }
 
+bool IPStack_AddressIsBroadcast(int AddrType, const void *Addr, int SubnetBits)
+{
+       const size_t    addrsize = IPStack_GetAddressSize(AddrType);
+       const Uint8     *addr = Addr;
+       
+       ASSERTC( SubnetBits, >=, 0 );
+       ASSERTC( SubnetBits, <=, addrsize * 8 );
+       const size_t    host_bits = addrsize*8 - SubnetBits;
+       
+       for( int i = 0; i < host_bits/8; i ++ )
+       {
+               if( addr[addrsize-i-1] != 0xFF )
+                       return false;
+       }
+       Uint8   mask = 0xFF >> (8-(host_bits%8));
+       if( (addr[addrsize-host_bits/8-1] & mask) != mask )
+               return false;
+       return true;
+}
+
 const char *IPStack_PrintAddress(int AddressType, const void *Address)
 {
        switch( AddressType )

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