X-Git-Url: https://git.ucc.asn.au/?a=blobdiff_plain;f=Modules%2FIPStack%2Frouting.c;h=c37e744148bd299bba08532face17a3298e25a56;hb=b1873b4cff47aae8ada8cc303ea01b475cc7ccc8;hp=26817b65b106e7aeaa7bb3280c506349be175782;hpb=89d57929e1e4f83a55d32a1d0084e4ed0296f521;p=tpg%2Facess2.git diff --git a/Modules/IPStack/routing.c b/Modules/IPStack/routing.c index 26817b65..c37e7441 100644 --- a/Modules/IPStack/routing.c +++ b/Modules/IPStack/routing.c @@ -2,7 +2,7 @@ * Acess2 IP Stack * - Routing Tables */ -#define DEBUG 1 +#define DEBUG 0 #define VERSION VER2(0,10) #include #include @@ -32,13 +32,13 @@ tRoute *IPStack_FindRoute(int AddressType, tInterface *Interface, void *Address) tRoute *gIP_Routes; tRoute *gIP_RoutesEnd; tVFS_Node gIP_RouteNode = { - Flags: VFS_FFLAG_DIRECTORY, - Size: -1, - NumACLs: 1, - ACLs: &gVFS_ACL_EveryoneRX, - ReadDir: IPStack_RouteDir_ReadDir, - FindDir: IPStack_RouteDir_FindDir, - IOCtl: IPStack_RouteDir_IOCtl + .Flags = VFS_FFLAG_DIRECTORY, + .Size = -1, + .NumACLs = 1, + .ACLs = &gVFS_ACL_EveryoneRX, + .ReadDir = IPStack_RouteDir_ReadDir, + .FindDir = IPStack_RouteDir_FindDir, + .IOCtl = IPStack_RouteDir_IOCtl }; // === CODE === @@ -74,10 +74,39 @@ tVFS_Node *IPStack_RouteDir_FindDir(tVFS_Node *Node, const char *Name) // Zero is invalid, sorry :) if( !num ) return NULL; + // Interpret the name as :, returning the interface for + // needed to access that address. + // E.g. '4:0A02000A' - 10.2.0.10 + // Hm... It could do with a way to have a better address type representation + if( Name[1] == ':' ) // TODO: Allow variable length type codes + { + int addrSize = IPStack_GetAddressSize(num); + Uint8 addrData[addrSize]; + + // Errof if the size is invalid + if( strlen(Name) != 2 + addrSize*2 ) + return NULL; + + // Parse the address + // - Error if the address data is not fully hex + if( UnHex(addrData, addrSize, Name + 2) != addrSize ) + return NULL; + + // Find the route + rt = IPStack_FindRoute(num, NULL, addrData); + if(!rt) return NULL; + + // Return the interface node + // - Sure it's hijacking it from inteface.c's area, but it's + // simpler this way + return &rt->Interface->Node; + } + // The list is inherently sorted, so we can do a quick search for(rt = gIP_Routes; rt && rt->Node.Inode < num; rt = rt->Next); - // Fast fail on larger number - if( rt->Node.Inode > num ) + + // Fast fail end of list / larger number + if( !rt || rt->Node.Inode > num ) return NULL; return &rt->Node; @@ -104,23 +133,7 @@ int IPStack_RouteDir_IOCtl(tVFS_Node *Node, int ID, void *Data) 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); @@ -371,7 +384,6 @@ static const char *casIOCtls_Route[] = { */ 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); @@ -379,23 +391,7 @@ int IPStack_Route_IOCtl(tVFS_Node *Node, int ID, void *Data) 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: