Fiddling with x86_64 and i486 builds
[tpg/acess2.git] / Modules / IPStack / main.c
index 6fe92f4..fe4bf0f 100644 (file)
@@ -28,12 +28,12 @@ extern int  IPv6_Initialise();
  int   IPStack_Install(char **Arguments);
  int   IPStack_IOCtlRoot(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);
+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(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);
+tVFS_Node      *IPStack_Iface_FindDir(tVFS_Node *Node, const char *Name);
  int   IPStack_Iface_IOCtl(tVFS_Node *Node, int ID, void *Data);
 
 // === GLOBALS ===
@@ -50,11 +50,11 @@ tDevFS_Driver       gIP_DriverInfo = {
        .IOCtl = IPStack_Root_IOCtl
        }
 };
-tSpinlock      glIP_Interfaces = 0;
+tShortSpinlock glIP_Interfaces;
 tInterface     *gIP_Interfaces = NULL;
 tInterface     *gIP_Interfaces_Last = NULL;
  int   giIP_NextIfaceId = 1;
-tSpinlock      glIP_Adapters = 0;
+tMutex glIP_Adapters;
 tAdapter       *gIP_Adapters = NULL;
 tSocketFile    *gIP_FileTemplates;
 
@@ -122,6 +122,11 @@ char *IPStack_Root_ReadDir(tVFS_Node *Node, int Pos)
        }
        
        name = malloc(4);
+       if(!name) {
+               Log_Warning("IPStack", "IPStack_Root_ReadDir - malloc error");
+               LEAVE('n');
+               return NULL;
+       }
        
        // Create the name
        Pos = iface->Node.ImplInt;
@@ -149,7 +154,7 @@ char *IPStack_Root_ReadDir(tVFS_Node *Node, int Pos)
 /**
  * \brief Get the node of an interface
  */
-tVFS_Node *IPStack_Root_FindDir(tVFS_Node *Node, char *Name)
+tVFS_Node *IPStack_Root_FindDir(tVFS_Node *Node, const char *Name)
 {
         int    i, num;
        tInterface      *iface;
@@ -170,7 +175,7 @@ tVFS_Node *IPStack_Root_FindDir(tVFS_Node *Node, char *Name)
        
        for( iface = gIP_Interfaces; iface; iface = iface->Next )
        {
-               if( iface->Node.ImplInt == num )
+               if( (int)iface->Node.ImplInt == num )
                {
                        LEAVE('p', &iface->Node);
                        return &iface->Node;
@@ -231,7 +236,6 @@ char *IPStack_Iface_ReadDir(tVFS_Node *Node, int Pos)
 {
        tSocketFile     *file = gIP_FileTemplates;
        while(Pos-- && file) {
-               Log("IPStack_Iface_ReadDir: %s", file->Name);
                file = file->Next;
        }
        
@@ -243,7 +247,7 @@ char *IPStack_Iface_ReadDir(tVFS_Node *Node, int Pos)
 /**
  * \brief Gets a named node from an interface directory
  */
-tVFS_Node *IPStack_Iface_FindDir(tVFS_Node *Node, char *Name)
+tVFS_Node *IPStack_Iface_FindDir(tVFS_Node *Node, const char *Name)
 {
        tSocketFile     *file = gIP_FileTemplates;
        
@@ -251,7 +255,6 @@ tVFS_Node *IPStack_Iface_FindDir(tVFS_Node *Node, char *Name)
        for(;file;file = file->Next)
        {
                if( strcmp(file->Name, Name) == 0 )     break;
-               Log("IPStack_Iface_FindDir: strcmp('%s', '%s')", file->Name, Name);
        }
        if(!file)       return NULL;
        
@@ -513,9 +516,12 @@ int IPStack_Iface_IOCtl(tVFS_Node *Node, int ID, void *Data)
 int IPStack_AddInterface(char *Device)
 {
        tInterface      *iface;
+       tAdapter        *card;
        
        ENTER("sDevice", Device);
        
+       card = IPStack_GetAdapter(Device);
+       
        iface = malloc(sizeof(tInterface));
        if(!iface) {
                LEAVE('i', -2);
@@ -527,7 +533,6 @@ int IPStack_AddInterface(char *Device)
        
        // Create Node
        iface->Node.ImplPtr = iface;
-       iface->Node.ImplInt = giIP_NextIfaceId++;
        iface->Node.Flags = VFS_FFLAG_DIRECTORY;
        iface->Node.Size = -1;
        iface->Node.NumACLs = 1;
@@ -535,6 +540,10 @@ int IPStack_AddInterface(char *Device)
        iface->Node.ReadDir = IPStack_Iface_ReadDir;
        iface->Node.FindDir = IPStack_Iface_FindDir;
        iface->Node.IOCtl = IPStack_Iface_IOCtl;
+       iface->Node.MkNod = NULL;
+       iface->Node.Link = NULL;
+       iface->Node.Relink = NULL;
+       iface->Node.Close = NULL;
        
        // Set Defaults
        iface->TimeoutDelay = DEFAULT_TIMEOUT;
@@ -547,8 +556,12 @@ int IPStack_AddInterface(char *Device)
                return -1;      // Return ERR_YOUFAIL
        }
        
+       // Delay setting ImplInt until after the adapter is opened
+       // Keeps things simple
+       iface->Node.ImplInt = giIP_NextIfaceId++;
+       
        // Append to list
-       LOCK( &glIP_Interfaces );
+       SHORTLOCK( &glIP_Interfaces );
        if( gIP_Interfaces ) {
                gIP_Interfaces_Last->Next = iface;
                gIP_Interfaces_Last = iface;
@@ -557,7 +570,7 @@ int IPStack_AddInterface(char *Device)
                gIP_Interfaces = iface;
                gIP_Interfaces_Last = iface;
        }
-       RELEASE( &glIP_Interfaces );
+       SHORTREL( &glIP_Interfaces );
        
        gIP_DriverInfo.RootNode.Size ++;
        
@@ -577,14 +590,14 @@ tAdapter *IPStack_GetAdapter(char *Path)
        
        ENTER("sPath", Path);
        
-       LOCK( &glIP_Adapters );
+       Mutex_Acquire( &glIP_Adapters );
        
        // Check if this adapter is already open
        for( dev = gIP_Adapters; dev; dev = dev->Next )
        {
                if( strcmp(dev->Device, Path) == 0 ) {
                        dev->NRef ++;
-                       RELEASE( &glIP_Adapters );
+                       Mutex_Release( &glIP_Adapters );
                        LEAVE('p', dev);
                        return dev;
                }
@@ -593,7 +606,7 @@ tAdapter *IPStack_GetAdapter(char *Path)
        // Ok, so let's open it
        dev = malloc( sizeof(tAdapter) + strlen(Path) + 1 );
        if(!dev) {
-               RELEASE( &glIP_Adapters );
+               Mutex_Release( &glIP_Adapters );
                LEAVE('n');
                return NULL;
        }
@@ -607,7 +620,7 @@ tAdapter *IPStack_GetAdapter(char *Path)
        dev->DeviceFD = VFS_Open( dev->Device, VFS_OPENFLAG_READ|VFS_OPENFLAG_WRITE );
        if( dev->DeviceFD == -1 ) {
                free( dev );
-               RELEASE( &glIP_Adapters );
+               Mutex_Release( &glIP_Adapters );
                LEAVE('n');
                return NULL;
        }
@@ -619,7 +632,7 @@ tAdapter *IPStack_GetAdapter(char *Path)
                Warning("IPStack_GetAdapter: '%s' is not a network interface", dev->Device);
                VFS_Close( dev->DeviceFD );
                free( dev );
-               RELEASE( &glIP_Adapters );
+               Mutex_Release( &glIP_Adapters );
                LEAVE('n');
                return NULL;
        }
@@ -631,7 +644,7 @@ tAdapter *IPStack_GetAdapter(char *Path)
        dev->Next = gIP_Adapters;
        gIP_Adapters = dev;
        
-       RELEASE( &glIP_Adapters );
+       Mutex_Release( &glIP_Adapters );
        
        // Start watcher
        Link_WatchDevice( dev );

UCC git Repository :: git.ucc.asn.au