X-Git-Url: https://git.ucc.asn.au/?a=blobdiff_plain;f=Modules%2FIPStack%2Finterface.c;h=82d1b8c43d14356550946df291599d073eaea92c;hb=57c1e8ff3a5e475ff5fe457ede46a4b3598b91f2;hp=fc7db9038c8cfd1da8439969871d87ca3ee6fa12;hpb=9d85201216cb35e1b1e051b1d7cdc38eaa5befa4;p=tpg%2Facess2.git diff --git a/Modules/IPStack/interface.c b/Modules/IPStack/interface.c index fc7db903..82d1b8c4 100644 --- a/Modules/IPStack/interface.c +++ b/Modules/IPStack/interface.c @@ -6,8 +6,8 @@ #define VERSION VER2(0,10) #include "ipstack.h" #include "link.h" -#include -#include +#include +#include // === CONSTANTS === //! Default timeout value, 30 seconds @@ -34,18 +34,18 @@ tVFS_Node *IPStack_Iface_FindDir(tVFS_Node *Node, const char *Name); // === GLOBALS === //! Loopback (127.0.0.0/8, ::1) Pseudo-Interface tInterface gIP_LoopInterface = { - Node: { - ImplPtr: &gIP_LoopInterface, - Flags: VFS_FFLAG_DIRECTORY, - Size: -1, - NumACLs: 1, - ACLs: &gVFS_ACL_EveryoneRX, - ReadDir: IPStack_Iface_ReadDir, - FindDir: IPStack_Iface_FindDir, - IOCtl: IPStack_Iface_IOCtl + .Node = { + .ImplPtr = &gIP_LoopInterface, + .Flags = VFS_FFLAG_DIRECTORY, + .Size = -1, + .NumACLs = 1, + .ACLs = &gVFS_ACL_EveryoneRX, + .ReadDir = IPStack_Iface_ReadDir, + .FindDir = IPStack_Iface_FindDir, + .IOCtl = IPStack_Iface_IOCtl }, - Adapter: NULL, - Type: 0 + .Adapter = NULL, + .Type = 0 }; tShortSpinlock glIP_Interfaces; tInterface *gIP_Interfaces = NULL; @@ -54,8 +54,8 @@ tInterface *gIP_Interfaces_Last = NULL; tSocketFile *gIP_FileTemplates; tAdapter gIP_LoopAdapter = { - DeviceLen: 8, - Device: "LOOPBACK" + .DeviceLen = 8, + .Device = "LOOPBACK" }; tMutex glIP_Adapters; tAdapter *gIP_Adapters = NULL; @@ -144,28 +144,6 @@ tVFS_Node *IPStack_Root_FindDir(tVFS_Node *Node, const char *Name) return &gIP_LoopInterface.Node; } - #if 0 - i = 0; num = 0; - while('0' <= Name[i] && Name[i] <= '9') - { - num *= 10; - num += Name[i] - '0'; - i ++; - } - if(Name[i] != '\0') { - LEAVE('n'); - return NULL; - } - - for( iface = gIP_Interfaces; iface; iface = iface->Next ) - { - if( (int)iface->Node.ImplInt == num ) - { - LEAVE('p', &iface->Node); - return &iface->Node; - } - } - #else for( iface = gIP_Interfaces; iface; iface = iface->Next ) { if( strcmp(iface->Name, Name) == 0 ) @@ -174,7 +152,6 @@ tVFS_Node *IPStack_Root_FindDir(tVFS_Node *Node, const char *Name) return &iface->Node; } } - #endif LEAVE('p', NULL); return NULL; @@ -204,6 +181,7 @@ int IPStack_Root_IOCtl(tVFS_Node *Node, int ID, void *Data) { char name[4] = ""; tInterface *iface = IPStack_AddInterface(Data, name); + if(iface == NULL) LEAVE_RET('i', -1); tmp = iface->Node.ImplInt; } LEAVE_RET('i', tmp); @@ -226,6 +204,7 @@ tInterface *IPStack_AddInterface(const char *Device, const char *Name) card = IPStack_GetAdapter(Device); if( !card ) { + Log_Debug("IPStack", "Unable to open card '%s'", Device); LEAVE('n'); return NULL; // ERR_YOURBAD } @@ -238,6 +217,7 @@ tInterface *IPStack_AddInterface(const char *Device, const char *Name) + IPStack_GetAddressSize(-1)*3 // Address, Route->Network, Route->NextHop ); if(!iface) { + Log_Warning("IPStack", "AddInterface - malloc() failed"); LEAVE('n'); return NULL; // Return ERR_MYBAD } @@ -266,17 +246,12 @@ tInterface *IPStack_AddInterface(const char *Device, const char *Name) iface->TimeoutDelay = DEFAULT_TIMEOUT; // Get adapter handle - iface->Adapter = IPStack_GetAdapter(Device); - if( !iface->Adapter ) { - free( iface ); - LEAVE('n'); - return NULL; // Return ERR_YOUFAIL - } + iface->Adapter = card; // Delay setting ImplInt until after the adapter is opened // Keeps things simple iface->Node.ImplInt = giIP_NextIfaceId++; - sprintf(iface->Name, "%i", iface->Node.ImplInt); + sprintf(iface->Name, "%i", (int)iface->Node.ImplInt); // Append to list SHORTLOCK( &glIP_Interfaces ); @@ -554,6 +529,7 @@ tAdapter *IPStack_GetAdapter(const char *Path) // Ok, so let's open it dev = malloc( sizeof(tAdapter) + strlen(Path) + 1 ); if(!dev) { + Log_Warning("IPStack", "GetAdapter - malloc() failed"); Mutex_Release( &glIP_Adapters ); LEAVE('n'); return NULL; @@ -577,7 +553,7 @@ tAdapter *IPStack_GetAdapter(const char *Path) tmp = VFS_IOCtl(dev->DeviceFD, 0, NULL); LOG("Device type = %i", tmp); if( tmp != DRV_TYPE_NETWORK ) { - Warning("IPStack_GetAdapter: '%s' is not a network interface", dev->Device); + Log_Warning("IPStack", "IPStack_GetAdapter: '%s' is not a network interface", dev->Device); VFS_Close( dev->DeviceFD ); free( dev ); Mutex_Release( &glIP_Adapters );