IPStack - Routing improvement
authorJohn Hodge <[email protected]>
Mon, 24 Jan 2011 15:01:35 +0000 (23:01 +0800)
committerJohn Hodge <[email protected]>
Mon, 24 Jan 2011 15:01:35 +0000 (23:01 +0800)
- When creating an boot config, routes are set up too
 > TODO: Implement a static route for each interface (as part of
   tInteface), removing the need to set a route when creating.
 > Problem, maintaining?
 > No real problem, just not have those in the main route list (if
   you want an interface route to be more important than another,
   just set it manually)

Kernel/arch/x86/time.c
Modules/IPStack/main.c
Modules/IPStack/routing.c

index 6a2d039..63d4e00 100644 (file)
@@ -9,7 +9,8 @@
 #define        TIMER_QUANTUM   100
 // 2^(15-rate), 15: 1HZ, 5: 1024Hz, 2: 8192Hz
 // (Max: 15, Min: 2) - 15 = 1Hz, 13 = 4Hz, 12 = 8Hz, 11 = 16Hz 10 = 32Hz, 2 = 8192Hz
 #define        TIMER_QUANTUM   100
 // 2^(15-rate), 15: 1HZ, 5: 1024Hz, 2: 8192Hz
 // (Max: 15, Min: 2) - 15 = 1Hz, 13 = 4Hz, 12 = 8Hz, 11 = 16Hz 10 = 32Hz, 2 = 8192Hz
-#define TIMER_RATE     12
+#define TIMER_RATE     10
+//#define TIMER_RATE   12
 //#define TIMER_RATE   15
 #define TIMER_FREQ     (0x8000>>TIMER_RATE)    //Hz
 #define MS_PER_TICK_WHOLE      (1000/(TIMER_FREQ))
 //#define TIMER_RATE   15
 #define TIMER_FREQ     (0x8000>>TIMER_RATE)    //Hz
 #define MS_PER_TICK_WHOLE      (1000/(TIMER_FREQ))
index 6dac938..004497d 100644 (file)
@@ -22,6 +22,7 @@ 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 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 ===
  int   IPStack_Install(char **Arguments);
 
 // === PROTOTYPES ===
  int   IPStack_Install(char **Arguments);
@@ -114,6 +115,9 @@ int IPStack_Install(char **Arguments)
                                        iface->Type = iType;
                                        memcpy(iface->Address, addrData, size);
                                        iface->SubnetBits = iBits;
                                        iface->Type = iType;
                                        memcpy(iface->Address, addrData, size);
                                        iface->SubnetBits = iBits;
+                                       
+                                       // Route for addrData/iBits, no next hop, default metric
+                                       IPStack_AddRoute(iface->Name, iface->Address, iBits, NULL, 0);
                                }
                        }
                        
                                }
                        }
                        
index 7c6ab2a..53d5c88 100644 (file)
@@ -9,15 +9,20 @@
 #include "ipstack.h"
 #include "link.h"
 
 #include "ipstack.h"
 #include "link.h"
 
+#define        DEFAUTL_METRIC  30
+
 // === IMPORTS ===
 // === IMPORTS ===
-tVFS_Node      *IPStack_Root_FindDir(tVFS_Node *Node, const char *Filename);
+extern tInterface      *gIP_Interfaces;
+extern tVFS_Node       *IPStack_Root_FindDir(tVFS_Node *Node, const char *Filename);
 
 // === PROTOTYPES ===
 // - Routes directory
 char   *IPStack_RouteDir_ReadDir(tVFS_Node *Node, int Pos);
 tVFS_Node      *IPStack_RouteDir_FindDir(tVFS_Node *Node, const char *Name);
  int   IPStack_RouteDir_IOCtl(tVFS_Node *Node, int ID, void *Data);
 
 // === PROTOTYPES ===
 // - Routes directory
 char   *IPStack_RouteDir_ReadDir(tVFS_Node *Node, int Pos);
 tVFS_Node      *IPStack_RouteDir_FindDir(tVFS_Node *Node, const char *Name);
  int   IPStack_RouteDir_IOCtl(tVFS_Node *Node, int ID, void *Data);
- int   IPStack_Route_Create(const char *InterfaceName);
+// - Route Management
+tRoute *IPStack_Route_Create(const char *InterfaceName);
+tRoute *IPStack_AddRoute(const char *Interface, void *Network, int SubnetBits, void *NextHop, int Metric);
 tRoute *IPStack_FindRoute(int AddressType, tInterface *Interface, void *Address);
 // - Individual Routes
  int   IPStack_Route_IOCtl(tVFS_Node *Node, int ID, void *Data);
 tRoute *IPStack_FindRoute(int AddressType, tInterface *Interface, void *Address);
 // - Individual Routes
  int   IPStack_Route_IOCtl(tVFS_Node *Node, int ID, void *Data);
@@ -94,6 +99,7 @@ static const char *casIOCtls_RouteDir[] = {
 int IPStack_RouteDir_IOCtl(tVFS_Node *Node, int ID, void *Data)
 {
         int    tmp;
 int IPStack_RouteDir_IOCtl(tVFS_Node *Node, int ID, void *Data)
 {
         int    tmp;
+       tRoute  *rt;
        ENTER("pNode iID pData", Node, ID, Data);
        switch(ID)
        {
        ENTER("pNode iID pData", Node, ID, Data);
        switch(ID)
        {
@@ -118,7 +124,11 @@ int IPStack_RouteDir_IOCtl(tVFS_Node *Node, int ID, void *Data)
        
        case 4: // Add Route
                if( !CheckString(Data) )        LEAVE_RET('i', -1);
        
        case 4: // Add Route
                if( !CheckString(Data) )        LEAVE_RET('i', -1);
-               tmp = IPStack_Route_Create(Data);
+               rt = IPStack_Route_Create(Data);
+               if( !rt )
+                       tmp = -1;
+               else
+                       tmp = rt->Node.Inode;
                LEAVE('i', tmp);
                return tmp;
        
                LEAVE('i', tmp);
                return tmp;
        
@@ -128,7 +138,6 @@ int IPStack_RouteDir_IOCtl(tVFS_Node *Node, int ID, void *Data)
                                 int    Type;
                                Uint8   Addr[];
                        }       *data = Data;
                                 int    Type;
                                Uint8   Addr[];
                        }       *data = Data;
-                       tRoute  *rt;
                        
                        if( !CheckMem(Data, sizeof(int)) )
                                LEAVE_RET('i', -1);
                        
                        if( !CheckMem(Data, sizeof(int)) )
                                LEAVE_RET('i', -1);
@@ -155,7 +164,7 @@ int IPStack_RouteDir_IOCtl(tVFS_Node *Node, int ID, void *Data)
  * \brief Create a new route entry
  * \param InterfaceName        Name of the interface using this route
  */
  * \brief Create a new route entry
  * \param InterfaceName        Name of the interface using this route
  */
-int IPStack_Route_Create(const char *InterfaceName)
+tRoute *IPStack_Route_Create(const char *InterfaceName)
 {
        tRoute  *rt;
        tInterface      *iface;
 {
        tRoute  *rt;
        tInterface      *iface;
@@ -167,15 +176,16 @@ int IPStack_Route_Create(const char *InterfaceName)
                tVFS_Node       *node = IPStack_Root_FindDir(NULL, InterfaceName);
                if( !node ) {
                        Log_Debug("IPStack", "IPStack_Route_Create - Unknown interface '%s'\n", InterfaceName);
                tVFS_Node       *node = IPStack_Root_FindDir(NULL, InterfaceName);
                if( !node ) {
                        Log_Debug("IPStack", "IPStack_Route_Create - Unknown interface '%s'\n", InterfaceName);
-                       return 0;
+                       return NULL;
                }
                iface = node->ImplPtr;
                }
                iface = node->ImplPtr;
+               if(node->Close) node->Close(node);
        }
        
        // Get the size of the specified address type
        size = IPStack_GetAddressSize(iface->Type);
        if( size == 0 ) {
        }
        
        // Get the size of the specified address type
        size = IPStack_GetAddressSize(iface->Type);
        if( size == 0 ) {
-               return 0;
+               return NULL;
        }
        
        // Allocate space
        }
        
        // Allocate space
@@ -195,6 +205,9 @@ int IPStack_Route_Create(const char *InterfaceName)
        rt->SubnetBits = 0;
        rt->NextHop = (void *)( (tVAddr)rt + sizeof(tRoute) + size );
        rt->Interface = iface;
        rt->SubnetBits = 0;
        rt->NextHop = (void *)( (tVAddr)rt + sizeof(tRoute) + size );
        rt->Interface = iface;
+       rt->Metric = DEFAUTL_METRIC;
+       memset(rt->Network, 0, size);
+       memset(rt->NextHop, 0, size);
        
        // Add to list
        if( gIP_RoutesEnd ) {
        
        // Add to list
        if( gIP_RoutesEnd ) {
@@ -207,12 +220,34 @@ int IPStack_Route_Create(const char *InterfaceName)
        
        Log_Log("IPStack", "Route entry for '%s' created", InterfaceName);
        
        
        Log_Log("IPStack", "Route entry for '%s' created", InterfaceName);
        
-       return rt->Node.Inode;
+       return rt;
+}
+
+/**
+ * \brief Add and fill a route
+ */
+tRoute *IPStack_AddRoute(const char *Interface, void *Network, int SubnetBits, void *NextHop, int Metric)
+{
+       tRoute  *rt = IPStack_Route_Create(Interface);
+        int    addrSize;
+       
+       if( !rt )       return NULL;
+       
+       addrSize = IPStack_GetAddressSize(rt->Interface->Type);
+       
+       memcpy(rt->Network, Network, addrSize);
+       if( NextHop )
+               memcpy(rt->NextHop, NextHop, addrSize);
+       rt->SubnetBits = SubnetBits;
+       if( Metric )
+               rt->Metric = Metric;
+       
+       return rt;
 }
 
 /**
  */
 }
 
 /**
  */
-tRoute *IPStack_FindRoute(int AddressType, tInterface *Interface, void *Address)
+tRoute *IPStack_FindRoute(int AddressType, tInterface *Interface, void *Address)
 {
        tRoute  *rt;
        tRoute  *best = NULL;
 {
        tRoute  *rt;
        tRoute  *best = NULL;

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