X-Git-Url: https://git.ucc.asn.au/?a=blobdiff_plain;f=KernelLand%2FModules%2FIPStack%2Finterface.c;h=9ab4b9ae5bb360ef5d0429fa93c5651d7553b195;hb=d0b4559f2936f6d9f06be0f7c3c51527a480ec0d;hp=9ff3f17df485003c285b6b993a68a291a63cb468;hpb=33495f1efd207f0af4f804858f247db0983fcb8f;p=tpg%2Facess2.git diff --git a/KernelLand/Modules/IPStack/interface.c b/KernelLand/Modules/IPStack/interface.c index 9ff3f17d..9ab4b9ae 100644 --- a/KernelLand/Modules/IPStack/interface.c +++ b/KernelLand/Modules/IPStack/interface.c @@ -8,10 +8,11 @@ #include "link.h" #include #include "include/adapters.h" +#include "interface.h" // === CONSTANTS === -//! Default timeout value, 30 seconds -#define DEFAULT_TIMEOUT (30*1000) +//! Default timeout value, 5 seconds +#define DEFAULT_TIMEOUT (5*1000) // === IMPORTS === extern int IPv4_Ping(tInterface *Iface, tIPv4 Addr); @@ -20,18 +21,23 @@ extern tVFS_Node gIP_RouteNode; extern tVFS_Node gIP_AdaptersNode; // === PROTOTYPES === -char *IPStack_Root_ReadDir(tVFS_Node *Node, int Pos); + int IPStack_Root_ReadDir(tVFS_Node *Node, int Pos, char Dest[FILENAME_MAX]); tVFS_Node *IPStack_Root_FindDir(tVFS_Node *Node, const char *Name); int IPStack_Root_IOCtl(tVFS_Node *Node, int ID, void *Data); int IPStack_AddFile(tSocketFile *File); tInterface *IPStack_AddInterface(const char *Device, const char *Name); -char *IPStack_Iface_ReadDir(tVFS_Node *Node, int Pos); + int IPStack_Iface_ReadDir(tVFS_Node *Node, int Pos, char Dest[FILENAME_MAX]); tVFS_Node *IPStack_Iface_FindDir(tVFS_Node *Node, const char *Name); int IPStack_Iface_IOCtl(tVFS_Node *Node, int ID, void *Data); // === GLOBALS === +tVFS_NodeType gIP_RootNodeType = { + .ReadDir = IPStack_Root_ReadDir, + .FindDir = IPStack_Root_FindDir, + .IOCtl = IPStack_Root_IOCtl +}; tVFS_NodeType gIP_InterfaceNodeType = { .ReadDir = IPStack_Iface_ReadDir, .FindDir = IPStack_Iface_FindDir, @@ -62,27 +68,26 @@ tSocketFile *gIP_FileTemplates; /** * \brief Read from the IP Stack's Device Directory */ -char *IPStack_Root_ReadDir(tVFS_Node *Node, int Pos) +int IPStack_Root_ReadDir(tVFS_Node *Node, int Pos, char Dest[FILENAME_MAX]) { tInterface *iface; - char *name; ENTER("pNode iPos", Node, Pos); // Routing Subdir if( Pos == 0 ) { - LEAVE('s', "routes"); - return strdup("routes"); + strcpy(Dest, "routes"); + return 0; } // Adapters if( Pos == 1 ) { - LEAVE('s', "adapters"); - return strdup("adapters"); + strcpy(Dest, "adapters"); + return 0; } // Pseudo Interfaces if( Pos == 2 ) { - LEAVE('s', "lo"); - return strdup("lo"); + strcpy(Dest, "lo"); + return 0; } Pos -= 3; @@ -91,38 +96,16 @@ char *IPStack_Root_ReadDir(tVFS_Node *Node, int Pos) // Did we run off the end? if(!iface) { - LEAVE('n'); - return NULL; - } - - name = malloc(4); - if(!name) { - Log_Warning("IPStack", "IPStack_Root_ReadDir - malloc error"); - LEAVE('n'); - return NULL; + LEAVE('i', -EINTERNAL); + return -EINVAL; } // Create the name Pos = iface->Node.ImplInt; - if(Pos < 10) { - name[0] = '0' + Pos; - name[1] = '\0'; - } - else if(Pos < 100) { - name[0] = '0' + Pos/10; - name[1] = '0' + Pos%10; - name[2] = '\0'; - } - else { - name[0] = '0' + Pos/100; - name[1] = '0' + (Pos/10)%10; - name[2] = '0' + Pos%10; - name[3] = '\0'; - } + snprintf(Dest, FILENAME_MAX, "%i", Pos); - LEAVE('s', name); - // Return the pre-generated name - return name; + LEAVE('i', 0); + return 0; } /** @@ -237,6 +220,7 @@ tInterface *IPStack_AddInterface(const char *Device, const char *Name) iface->Next = NULL; iface->Type = 0; // Unset type iface->Address = iface->Name + nameLen + 1; // Address + memset(&iface->Route, 0, sizeof(iface->Route)); iface->Route.Network = iface->Address + IPStack_GetAddressSize(-1); iface->Route.NextHop = iface->Route.Network + IPStack_GetAddressSize(-1); @@ -295,16 +279,18 @@ int IPStack_AddFile(tSocketFile *File) /** * \brief Read from an interface's directory */ -char *IPStack_Iface_ReadDir(tVFS_Node *Node, int Pos) +int IPStack_Iface_ReadDir(tVFS_Node *Node, int Pos, char Dest[FILENAME_MAX]) { tSocketFile *file = gIP_FileTemplates; while(Pos-- && file) { file = file->Next; } - if(!file) return NULL; + if(!file) + return -EINVAL; - return strdup(file->Name); + strncpy(Dest, file->Name, FILENAME_MAX); + return 0; } /** @@ -440,15 +426,19 @@ int IPStack_Iface_IOCtl(tVFS_Node *Node, int ID, void *Data) * - Gets the name of the attached device */ case 8: - Log_Error("IPStack", "TODO: Reimplement interface.ioctl(get_device)"); -// if( iface->Adapter == NULL ) + if( iface->Adapter == NULL ) LEAVE_RET('i', 0); -// if( Data == NULL ) -// LEAVE_RET('i', iface->Adapter->DeviceLen); -// if( !CheckMem( Data, iface->Adapter->DeviceLen+1 ) ) -// LEAVE_RET('i', -1); -// strcpy( Data, iface->Adapter->Device ); -// LEAVE_RET('i', iface->Adapter->DeviceLen); + char *name = Adapter_GetName(iface->Adapter); + int len = strlen(name); + if( Data ) { + if( !CheckMem( Data, len+1 ) ) { + free(name); + LEAVE_RET('i', -1); + } + strcpy( Data, name ); + } + free(name); + LEAVE_RET('i', len); /* * ping