From: John Hodge Date: Mon, 24 Jan 2011 15:01:35 +0000 (+0800) Subject: IPStack - Routing improvement X-Git-Tag: rel0.07~20 X-Git-Url: https://git.ucc.asn.au/?a=commitdiff_plain;h=d5822e9af597f656dccc6afe8dacabcfbb2fc0af;p=tpg%2Facess2.git IPStack - Routing improvement - 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) --- diff --git a/Kernel/arch/x86/time.c b/Kernel/arch/x86/time.c index 6a2d0399..63d4e00b 100644 --- a/Kernel/arch/x86/time.c +++ b/Kernel/arch/x86/time.c @@ -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_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)) diff --git a/Modules/IPStack/main.c b/Modules/IPStack/main.c index 6dac9382..004497db 100644 --- a/Modules/IPStack/main.c +++ b/Modules/IPStack/main.c @@ -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 tRoute *IPStack_AddRoute(const char *Interface, void *Network, int SubnetBits, void *NextHop, int Metric); // === 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; + + // Route for addrData/iBits, no next hop, default metric + IPStack_AddRoute(iface->Name, iface->Address, iBits, NULL, 0); } } diff --git a/Modules/IPStack/routing.c b/Modules/IPStack/routing.c index 7c6ab2ac..53d5c885 100644 --- a/Modules/IPStack/routing.c +++ b/Modules/IPStack/routing.c @@ -9,15 +9,20 @@ #include "ipstack.h" #include "link.h" +#define DEFAUTL_METRIC 30 + // === 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); - 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); @@ -94,6 +99,7 @@ static const char *casIOCtls_RouteDir[] = { int IPStack_RouteDir_IOCtl(tVFS_Node *Node, int ID, void *Data) { int tmp; + tRoute *rt; 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); - tmp = IPStack_Route_Create(Data); + rt = IPStack_Route_Create(Data); + if( !rt ) + tmp = -1; + else + tmp = rt->Node.Inode; 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; - tRoute *rt; 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 */ -int IPStack_Route_Create(const char *InterfaceName) +tRoute *IPStack_Route_Create(const char *InterfaceName) { 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); - return 0; + return NULL; } 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 ) { - return 0; + return NULL; } // 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->Metric = DEFAUTL_METRIC; + memset(rt->Network, 0, size); + memset(rt->NextHop, 0, size); // 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); - 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;