* Acess2 IP Stack
* - Routing Tables
*/
-#define DEBUG 1
+#define DEBUG 0
#define VERSION VER2(0,10)
#include <acess.h>
#include <tpl_drv_common.h>
switch(ID)
{
// --- Standard IOCtls (0-3) ---
- case DRV_IOCTL_TYPE:
- LEAVE('i', DRV_TYPE_MISC);
- return DRV_TYPE_MISC;
-
- case DRV_IOCTL_IDENT:
- tmp = ModUtil_SetIdent(Data, STR(IDENT));
- LEAVE('i', 1);
- return 1;
-
- case DRV_IOCTL_VERSION:
- LEAVE('x', VERSION);
- return VERSION;
-
- case DRV_IOCTL_LOOKUP:
- tmp = ModUtil_LookupString( (char**)casIOCtls_RouteDir, (char*)Data );
- LEAVE('i', tmp);
- return tmp;
+ BASE_IOCTLS(DRV_TYPE_MISC, STR(IDENT), VERSION, casIOCtls_RouteDir)
case 4: // Add Route
if( !CheckString(Data) ) LEAVE_RET('i', -1);
{
tRoute *rt;
tRoute *best = NULL;
+ tInterface *iface;
+ int addrSize;
ENTER("iAddressType pInterface sAddress",
AddressType, Interface, IPStack_PrintAddress(AddressType, Address));
return NULL;
}
+ // Get address size
+ addrSize = IPStack_GetAddressSize(AddressType);
+
+ // Check against explicit routes
for( rt = gIP_Routes; rt; rt = rt->Next )
{
// Check interface
best = rt;
}
+ // Check against implicit routes
+ if( !best && !Interface )
+ {
+ for( iface = gIP_Interfaces; iface; iface = iface->Next )
+ {
+ if( Interface && iface != Interface ) continue;
+ if( iface->Type != AddressType ) continue;
+
+
+ // Check if the address matches
+ if( !IPStack_CompareAddress(AddressType, iface->Address, Address, iface->SubnetBits) )
+ continue;
+
+ if( best ) {
+ // More direct routes are preferred
+ if( best->SubnetBits > rt->SubnetBits ) {
+ LOG("Skipped - less direct (%i < %i)", rt->SubnetBits, best->SubnetBits);
+ continue;
+ }
+ // If equally direct, choose the best metric
+ if( best->SubnetBits == rt->SubnetBits && best->Metric < rt->Metric ) {
+ LOG("Skipped - higher metric (%i > %i)", rt->Metric, best->Metric);
+ continue;
+ }
+ }
+
+ rt = &iface->Route;
+ memcpy(rt->Network, iface->Address, addrSize);
+ memset(rt->NextHop, 0, addrSize);
+ rt->Metric = DEFAUTL_METRIC;
+ rt->SubnetBits = iface->SubnetBits;
+
+ best = rt;
+ }
+ }
+ if( !best && Interface )
+ {
+ rt = &Interface->Route;
+ // Make sure route is up to date
+ memcpy(rt->Network, iface->Address, addrSize);
+ memset(rt->NextHop, 0, addrSize);
+ rt->Metric = DEFAUTL_METRIC;
+ rt->SubnetBits = iface->SubnetBits;
+
+ if( IPStack_CompareAddress(AddressType, rt->Network, Address, rt->SubnetBits) )
+ {
+ best = rt;
+ }
+ }
+
LEAVE('p', best);
return best;
}
*/
int IPStack_Route_IOCtl(tVFS_Node *Node, int ID, void *Data)
{
- int tmp;
int *iData = Data;
tRoute *rt = Node->ImplPtr;
int addrSize = IPStack_GetAddressSize(rt->AddressType);
switch(ID)
{
// --- Standard IOCtls (0-3) ---
- case DRV_IOCTL_TYPE:
- LEAVE('i', DRV_TYPE_MISC);
- return DRV_TYPE_MISC;
-
- case DRV_IOCTL_IDENT:
- tmp = ModUtil_SetIdent(Data, STR(IDENT));
- LEAVE('i', 1);
- return 1;
-
- case DRV_IOCTL_VERSION:
- LEAVE('x', VERSION);
- return VERSION;
-
- case DRV_IOCTL_LOOKUP:
- tmp = ModUtil_LookupString( (char**)casIOCtls_Route, (char*)Data );
- LEAVE('i', tmp);
- return tmp;
+ BASE_IOCTLS(DRV_TYPE_MISC, STR(IDENT), VERSION, casIOCtls_Route)
// Get address type
case 4: