- 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)
#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 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))
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);
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);
#include "ipstack.h"
#include "link.h"
#include "ipstack.h"
#include "link.h"
+#define DEFAUTL_METRIC 30
+
-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);
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;
ENTER("pNode iID pData", Node, ID, Data);
switch(ID)
{
ENTER("pNode iID pData", Node, ID, Data);
switch(ID)
{
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;
int Type;
Uint8 Addr[];
} *data = Data;
int Type;
Uint8 Addr[];
} *data = Data;
if( !CheckMem(Data, sizeof(int)) )
LEAVE_RET('i', -1);
if( !CheckMem(Data, sizeof(int)) )
LEAVE_RET('i', -1);
* \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;
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);
+ 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 ) {
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 ) {
Log_Log("IPStack", "Route entry for '%s' created", InterfaceName);
Log_Log("IPStack", "Route entry for '%s' created", InterfaceName);
+ 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;