X-Git-Url: https://git.ucc.asn.au/?a=blobdiff_plain;f=Modules%2FIPStack%2Finterface.c;h=fc7db9038c8cfd1da8439969871d87ca3ee6fa12;hb=9d85201216cb35e1b1e051b1d7cdc38eaa5befa4;hp=445e5892f9f112266c47ab57b40eed765644fa01;hpb=94ecc5441605ad5151e625457531e7f90470db31;p=tpg%2Facess2.git diff --git a/Modules/IPStack/interface.c b/Modules/IPStack/interface.c index 445e5892..fc7db903 100644 --- a/Modules/IPStack/interface.c +++ b/Modules/IPStack/interface.c @@ -23,8 +23,8 @@ char *IPStack_Root_ReadDir(tVFS_Node *Node, int Pos); tVFS_Node *IPStack_Root_FindDir(tVFS_Node *Node, const char *Name); int IPStack_Root_IOCtl(tVFS_Node *Node, int ID, void *Data); - int IPStack_AddInterface(const char *Device, const char *Name); int IPStack_AddFile(tSocketFile *File); +tInterface *IPStack_AddInterface(const char *Device, const char *Name); tAdapter *IPStack_GetAdapter(const char *Path); char *IPStack_Iface_ReadDir(tVFS_Node *Node, int Pos); @@ -52,6 +52,11 @@ tInterface *gIP_Interfaces = NULL; tInterface *gIP_Interfaces_Last = NULL; tSocketFile *gIP_FileTemplates; + +tAdapter gIP_LoopAdapter = { + DeviceLen: 8, + Device: "LOOPBACK" + }; tMutex glIP_Adapters; tAdapter *gIP_Adapters = NULL; int giIP_NextIfaceId = 1; @@ -187,34 +192,19 @@ int IPStack_Root_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, "IPStack"); - LEAVE('i', 1); - return 1; - - case DRV_IOCTL_VERSION: - LEAVE('x', VERSION); - return VERSION; - - case DRV_IOCTL_LOOKUP: - tmp = ModUtil_LookupString( (char**)casIOCtls_Root, (char*)Data ); - LEAVE('i', tmp); - return tmp; + BASE_IOCTLS(DRV_TYPE_MISC, "IPStack", VERSION, casIOCtls_Root) - /* - * add_interface - * - Adds a new IP interface and binds it to a device - */ + /* + * add_interface + * - Adds a new IP interface and binds it to a device + */ case 4: if( Threads_GetUID() != 0 ) LEAVE_RET('i', -1); if( !CheckString( Data ) ) LEAVE_RET('i', -1); { char name[4] = ""; - tmp = IPStack_AddInterface(Data, name); + tInterface *iface = IPStack_AddInterface(Data, name); + tmp = iface->Node.ImplInt; } LEAVE_RET('i', tmp); } @@ -223,10 +213,10 @@ int IPStack_Root_IOCtl(tVFS_Node *Node, int ID, void *Data) } /** - * \fn int IPStack_AddInterface(char *Device) + * \fn tInterface *IPStack_AddInterface(char *Device) * \brief Adds an interface to the list */ -int IPStack_AddInterface(const char *Device, const char *Name) +tInterface *IPStack_AddInterface(const char *Device, const char *Name) { tInterface *iface; tAdapter *card; @@ -236,8 +226,8 @@ int IPStack_AddInterface(const char *Device, const char *Name) card = IPStack_GetAdapter(Device); if( !card ) { - LEAVE('i', -1); - return -1; // ERR_YOURBAD + LEAVE('n'); + return NULL; // ERR_YOURBAD } nameLen = sprintf(NULL, "%i", giIP_NextIfaceId); @@ -245,16 +235,18 @@ int IPStack_AddInterface(const char *Device, const char *Name) iface = malloc( sizeof(tInterface) + nameLen + 1 - + IPStack_GetAddressSize(-1) + + IPStack_GetAddressSize(-1)*3 // Address, Route->Network, Route->NextHop ); if(!iface) { - LEAVE('i', -2); - return -2; // Return ERR_MYBAD + LEAVE('n'); + return NULL; // Return ERR_MYBAD } iface->Next = NULL; iface->Type = 0; // Unset type iface->Address = iface->Name + nameLen + 1; // Address + iface->Route.Network = iface->Address + IPStack_GetAddressSize(-1); + iface->Route.NextHop = iface->Route.Network + IPStack_GetAddressSize(-1); // Create Node iface->Node.ImplPtr = iface; @@ -277,8 +269,8 @@ int IPStack_AddInterface(const char *Device, const char *Name) iface->Adapter = IPStack_GetAdapter(Device); if( !iface->Adapter ) { free( iface ); - LEAVE('i', -1); - return -1; // Return ERR_YOUFAIL + LEAVE('n'); + return NULL; // Return ERR_YOUFAIL } // Delay setting ImplInt until after the adapter is opened @@ -301,8 +293,8 @@ int IPStack_AddInterface(const char *Device, const char *Name) // gIP_DriverInfo.RootNode.Size ++; // Success! - LEAVE('i', iface->Node.ImplInt); - return iface->Node.ImplInt; + LEAVE('p', iface); + return iface; } /** @@ -376,23 +368,7 @@ int IPStack_Iface_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_Iface, (char*)Data ); - LEAVE('i', tmp); - return tmp; + BASE_IOCTLS(DRV_TYPE_MISC, "IPStack", VERSION, casIOCtls_Iface) /* * getset_type @@ -531,6 +507,37 @@ tAdapter *IPStack_GetAdapter(const char *Path) ENTER("sPath", Path); + // Check for loopback + if( strcmp(Path, "LOOPBACK") == 0 ) + { + // Initialise if required + if( gIP_LoopAdapter.DeviceFD == 0 ) + { + dev = &gIP_LoopAdapter; + + dev->NRef = 1; + dev->DeviceLen = 8; + + dev->DeviceFD = VFS_Open( "/Devices/fifo/anon", VFS_OPENFLAG_READ|VFS_OPENFLAG_WRITE ); + if( dev->DeviceFD == -1 ) { + Log_Warning("IPStack", "Unable to open FIFO '/Devices/fifo/anon' for loopback"); + return NULL; + } + + dev->MacAddr.B[0] = 'A'; + dev->MacAddr.B[1] = 'c'; + dev->MacAddr.B[2] = 'e'; + dev->MacAddr.B[3] = 's'; + dev->MacAddr.B[4] = 's'; + dev->MacAddr.B[5] = '2'; + + // Start watcher + Link_WatchDevice( dev ); + } + LEAVE('p', &gIP_LoopAdapter); + return &gIP_LoopAdapter; + } + Mutex_Acquire( &glIP_Adapters ); // Check if this adapter is already open