X-Git-Url: https://git.ucc.asn.au/?a=blobdiff_plain;f=Modules%2FIPStack%2Fmain.c;h=37caba8c81b3cc60e2253b7701b3ec522d288e84;hb=845ed09f3edef0c836200df6afbd6bfbc7b3fef6;hp=76a18f0bd5b1186f09d862547ab344be97c23ba0;hpb=35f03318dedb1b430175e8005b64896424a644ef;p=tpg%2Facess2.git diff --git a/Modules/IPStack/main.c b/Modules/IPStack/main.c index 76a18f0b..37caba8c 100644 --- a/Modules/IPStack/main.c +++ b/Modules/IPStack/main.c @@ -3,7 +3,7 @@ * - Stack Initialisation */ #define DEBUG 0 -#define VERSION ((0<<8)|10) +#define VERSION VER2(0,10) #include "ipstack.h" #include "link.h" #include @@ -17,17 +17,22 @@ // === IMPORTS === extern int ARP_Initialise(); +extern void UDP_Initialise(); +extern void TCP_Initialise(); extern int IPv4_Initialise(); extern int IPv4_Ping(tInterface *Iface, tIPv4 Addr); // === PROTOTYPES === int IPStack_Install(char **Arguments); int IPStack_IOCtlRoot(tVFS_Node *Node, int ID, void *Data); -char *IPStack_ReadDir(tVFS_Node *Node, int Pos); -tVFS_Node *IPStack_FindDir(tVFS_Node *Node, char *Name); - int IPStack_IOCtl(tVFS_Node *Node, int ID, void *Data); +char *IPStack_Root_ReadDir(tVFS_Node *Node, int Pos); +tVFS_Node *IPStack_Root_FindDir(tVFS_Node *Node, char *Name); + int IPStack_Root_IOCtl(tVFS_Node *Node, int ID, void *Data); int IPStack_AddInterface(char *Device); tAdapter *IPStack_GetAdapter(char *Path); +char *IPStack_Iface_ReadDir(tVFS_Node *Node, int Pos); +tVFS_Node *IPStack_Iface_FindDir(tVFS_Node *Node, char *Name); + int IPStack_Iface_IOCtl(tVFS_Node *Node, int ID, void *Data); // === GLOBALS === MODULE_DEFINE(0, VERSION, IPStack, IPStack_Install, NULL, NULL); @@ -38,9 +43,9 @@ tDevFS_Driver gIP_DriverInfo = { .NumACLs = 1, .ACLs = &gVFS_ACL_EveryoneRX, .Flags = VFS_FFLAG_DIRECTORY, - .ReadDir = IPStack_ReadDir, - .FindDir = IPStack_FindDir, - .IOCtl = IPStack_IOCtlRoot + .ReadDir = IPStack_Root_ReadDir, + .FindDir = IPStack_Root_FindDir, + .IOCtl = IPStack_Root_IOCtl } }; tSpinlock glIP_Interfaces = 0; @@ -49,6 +54,7 @@ tInterface *gIP_Interfaces_Last = NULL; int giIP_NextIfaceId = 1; tSpinlock glIP_Adapters = 0; tAdapter *gIP_Adapters = NULL; +tSocketFile *gIP_FileTemplates; // === CODE === /** @@ -62,6 +68,8 @@ int IPStack_Install(char **Arguments) // Install Handlers ARP_Initialise(); IPv4_Initialise(); + TCP_Initialise(); + UDP_Initialise(); if(Arguments) { @@ -79,10 +87,20 @@ int IPStack_Install(char **Arguments) return 1; } +/** + * \brief Adds a file to the socket list + */ +int IPStack_AddFile(tSocketFile *File) +{ + File->Next = gIP_FileTemplates; + gIP_FileTemplates = File; + return 0; +} + /** * \brief Read from the IP Stack's Device Directory */ -char *IPStack_ReadDir(tVFS_Node *Node, int Pos) +char *IPStack_Root_ReadDir(tVFS_Node *Node, int Pos) { tInterface *iface; char *name; @@ -97,26 +115,24 @@ char *IPStack_ReadDir(tVFS_Node *Node, int Pos) return NULL; } - name = malloc(6); - name[0] = 'i'; - name[1] = 'p'; + name = malloc(4); // Create the name Pos = iface->Node.ImplInt; if(Pos < 10) { - name[2] = '0' + Pos; - name[3] = '\0'; + name[0] = '0' + Pos; + name[1] = '\0'; } else if(Pos < 100) { - name[2] = '0' + Pos/10; - name[3] = '0' + Pos%10; - name[4] = '\0'; + name[0] = '0' + Pos/10; + name[1] = '0' + Pos%10; + name[2] = '\0'; } else { - name[2] = '0' + Pos/100; - name[3] = '0' + (Pos/10)%10; - name[4] = '0' + Pos%10; - name[5] = '\0'; + name[0] = '0' + Pos/100; + name[1] = '0' + (Pos/10)%10; + name[2] = '0' + Pos%10; + name[3] = '\0'; } LEAVE('s', name); @@ -127,19 +143,14 @@ char *IPStack_ReadDir(tVFS_Node *Node, int Pos) /** * \brief Get the node of an interface */ -tVFS_Node *IPStack_FindDir(tVFS_Node *Node, char *Name) +tVFS_Node *IPStack_Root_FindDir(tVFS_Node *Node, char *Name) { int i, num; tInterface *iface; ENTER("pNode sName", Node, Name); - if(Name[0] != 'i' || Name[1] != 'p') { - LEAVE('n'); - return NULL; - } - - i = 2; num = 0; + i = 0; num = 0; while('0' <= Name[i] && Name[i] <= '9') { num *= 10; @@ -167,7 +178,7 @@ static const char *casIOCtls_Root[] = { DRV_IOCTLNAMES, "add_interface", NULL }; /** * \brief Handles IOCtls for the IPStack root */ -int IPStack_IOCtlRoot(tVFS_Node *Node, int ID, void *Data) +int IPStack_Root_IOCtl(tVFS_Node *Node, int ID, void *Data) { int tmp; ENTER("pNode iID pData", Node, ID, Data); @@ -180,8 +191,7 @@ int IPStack_IOCtlRoot(tVFS_Node *Node, int ID, void *Data) return DRV_TYPE_MISC; case DRV_IOCTL_IDENT: - if( !CheckMem( Data, 4 ) ) LEAVE_RET('i', -1); - memcpy(Data, "IP\0\0", 4); + tmp = ModUtil_SetIdent(Data, "IPStack"); LEAVE('i', 1); return 1; @@ -190,9 +200,7 @@ int IPStack_IOCtlRoot(tVFS_Node *Node, int ID, void *Data) return VERSION; case DRV_IOCTL_LOOKUP: - if( !CheckString( Data ) ) LEAVE_RET('i', -1); - LOG("Lookup '%s'", Data); - tmp = LookupString( (char**)casIOCtls_Root, (char*)Data ); + tmp = ModUtil_LookupString( (char**)casIOCtls_Root, (char*)Data ); LEAVE('i', tmp); return tmp; @@ -210,6 +218,40 @@ int IPStack_IOCtlRoot(tVFS_Node *Node, int ID, void *Data) return 0; } +/** + * \brief Read from an interface's directory + */ +char *IPStack_Iface_ReadDir(tVFS_Node *Node, int Pos) +{ + tSocketFile *file = gIP_FileTemplates; + while(Pos-- && file) file = file->Next; + + if(!file) return NULL; + + return strdup(file->Name); +} + +/** + * \brief Gets a named node from an interface directory + */ +tVFS_Node *IPStack_Iface_FindDir(tVFS_Node *Node, char *Name) +{ + tSocketFile *file = gIP_FileTemplates; + + // Get file definition + for(;file;file = file->Next) + { + if( strcmp(file->Name, Name) == 0 ) break; + } + if(!file) return NULL; + + // Pass the buck! + return file->Init(Node->ImplPtr); +} + +/** + * \brief Names for interface IOCtl Calls + */ static const char *casIOCtls_Iface[] = { DRV_IOCTLNAMES, "getset_type", @@ -222,7 +264,7 @@ static const char *casIOCtls_Iface[] = { /** * \brief Handles IOCtls for the IPStack interfaces */ -int IPStack_IOCtl(tVFS_Node *Node, int ID, void *Data) +int IPStack_Iface_IOCtl(tVFS_Node *Node, int ID, void *Data) { int tmp; tInterface *iface = (tInterface*)Node->ImplPtr; @@ -236,8 +278,7 @@ int IPStack_IOCtl(tVFS_Node *Node, int ID, void *Data) return DRV_TYPE_MISC; case DRV_IOCTL_IDENT: - if( !CheckMem( Data, 4 ) ) LEAVE_RET('i', -1); - memcpy(Data, "IP\0\0", 4); + tmp = ModUtil_SetIdent(Data, STR(IDENT)); LEAVE('i', 1); return 1; @@ -246,9 +287,7 @@ int IPStack_IOCtl(tVFS_Node *Node, int ID, void *Data) return VERSION; case DRV_IOCTL_LOOKUP: - if( !CheckString( Data ) ) LEAVE_RET('i', -1); - LOG("Lookup '%s'", Data); - tmp = LookupString( (char**)casIOCtls_Iface, (char*)Data ); + tmp = ModUtil_LookupString( (char**)casIOCtls_Iface, (char*)Data ); LEAVE('i', tmp); return tmp; @@ -470,9 +509,9 @@ int IPStack_AddInterface(char *Device) iface->Node.Size = 0; iface->Node.NumACLs = 1; iface->Node.ACLs = &gVFS_ACL_EveryoneRX; - iface->Node.ReadDir = NULL; - iface->Node.FindDir = NULL; - iface->Node.IOCtl = IPStack_IOCtl; + iface->Node.ReadDir = IPStack_Iface_ReadDir; + iface->Node.FindDir = IPStack_Iface_FindDir; + iface->Node.IOCtl = IPStack_Iface_IOCtl; // Set Defaults iface->TimeoutDelay = DEFAULT_TIMEOUT;