Fixing route determining
authorJohn Hodge <[email protected]>
Sat, 20 Nov 2010 05:59:37 +0000 (13:59 +0800)
committerJohn Hodge <[email protected]>
Sat, 20 Nov 2010 05:59:37 +0000 (13:59 +0800)
- Infinite loop due to bad memcmp implementation
- Updating ping to support the new route code

Makefile
Modules/IPStack/arp.c
Modules/IPStack/main.c
Modules/IPStack/routing.c
Usermode/Applications/ifconfig_src/main.c
Usermode/Applications/ping_src/Makefile
Usermode/Applications/ping_src/main.c

index 0db9855..bc4f148 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -11,7 +11,8 @@
 SUBMAKE = $(MAKE) --no-print-directory
 
 USRLIBS := crt0.o acess.ld ld-acess.so libacess.so libgcc.so libc.so libnet.so
-USRAPPS := init login CLIShell cat ls mount ifconfig
+USRAPPS := init login CLIShell cat ls mount
+USRAPPS += ifconfig ping
 
 ALL_DYNMODS = $(addprefix all-,$(DYNMODS))
 ALL_MODULES := $(addprefix all-,$(MODULES))
index 476557e..35532f6 100644 (file)
@@ -73,6 +73,7 @@ tMacAddr ARP_Resolve4(tInterface *Interface, tIPv4 Address)
         int    lastID;
         int    i;
        struct sArpRequest4     req;
+       Sint64  timeout;
        
        ENTER("pInterface xAddress", Interface, Address);
        
@@ -129,10 +130,16 @@ tMacAddr ARP_Resolve4(tInterface *Interface, tIPv4 Address)
        // Send Request
        Link_SendPacket(Interface->Adapter, 0x0806, req.DestMac, sizeof(struct sArpRequest4), &req);
        
+       timeout = now() + Interface->TimeoutDelay;
+       
        // Wait for a reply
        for(;;)
        {
-               while(lastID == giARP_LastUpdateID)     Threads_Yield();
+               while(lastID == giARP_LastUpdateID && now() < timeout)
+                       Threads_Yield();
+               
+               if( now() >= timeout )  break;  // Timeout
+               
                lastID = giARP_LastUpdateID;
                
                Mutex_Acquire( &glARP_Cache4 );
@@ -145,6 +152,10 @@ tMacAddr ARP_Resolve4(tInterface *Interface, tIPv4 Address)
                }
                Mutex_Release( &glARP_Cache4 );
        }
+       {
+               tMacAddr        ret = {{0,0,0,0,0,0}};
+               return ret;
+       }
 }
 
 /**
index ef1a2cd..8e3810d 100644 (file)
@@ -122,7 +122,7 @@ int IPStack_CompareAddress(int AddressType, void *Address1, void *Address2, int
        if( CheckBits < 0 )     CheckBits = 0;
        if( CheckBits > size*8 )        CheckBits = size*8;
        
-       if( CheckBits == 0 )    return 1;       // /0 matches anythin
+       if( CheckBits == 0 )    return 1;       // /0 matches anythin0
        
        // Check first bits/8 bytes
        if( memcmp(Address1, Address2, CheckBits/8) != 0 )      return 0;
index c106034..7c6ab2a 100644 (file)
@@ -2,7 +2,7 @@
  * Acess2 IP Stack
  * - Routing Tables
  */
-#define DEBUG  0
+#define DEBUG  1
 #define VERSION        VER2(0,10)
 #include <acess.h>
 #include <tpl_drv_common.h>
@@ -135,7 +135,7 @@ int IPStack_RouteDir_IOCtl(tVFS_Node *Node, int ID, void *Data)
                        if( !CheckMem(Data, sizeof(int) + IPStack_GetAddressSize(data->Type)) )
                                LEAVE_RET('i', -1);
                        
-                       Log_Debug("IPStack", "Route_RouteDir_IOCtl - FindRoute %i, %s\n",
+                       Log_Debug("IPStack", "Route_RouteDir_IOCtl - FindRoute %i, %s",
                                data->Type, IPStack_PrintAddress(data->Type, data->Addr) );
                        rt = IPStack_FindRoute(data->Type, NULL, data->Addr);
                        
@@ -205,7 +205,7 @@ int IPStack_Route_Create(const char *InterfaceName)
                gIP_Routes = gIP_RoutesEnd = rt;
        }
        
-       Log_Log("IPStack", "Route entry for '%s' created\n", InterfaceName);
+       Log_Log("IPStack", "Route entry for '%s' created", InterfaceName);
        
        return rt->Node.Inode;
 }
index c3ae316..8d97d1b 100644 (file)
@@ -348,8 +348,8 @@ int DoAutoConfig(const char *Device)
         int    tmp, fd;
        char    path[sizeof(IPSTACK_ROOT)+1+4+1];       // /0000
        uint8_t addr[4] = {10,0,2,55};
-       uint8_t gw[4] = {10,0,2,1};
-        int    subnet = 8;
+       uint8_t gw[4] = {10,0,2,2};
+        int    subnet = 24;
        
        tmp = AddInterface(Device);
        if( tmp < 0 )   return tmp;
@@ -376,7 +376,7 @@ int DoAutoConfig(const char *Device)
        // Set routes
        {
                uint8_t net[4] = {0,0,0,0};
-               AddRoute(path + sizeof(IPSTACK_ROOT), addr, 8, net);    // This interface
+               AddRoute(path + sizeof(IPSTACK_ROOT), addr, subnet, net);       // This interface
                AddRoute(path + sizeof(IPSTACK_ROOT), net, 0, gw);      // Gateway
        }
        
index 5d94dbe..4d44a33 100644 (file)
@@ -2,6 +2,8 @@
 
 -include ../Makefile.cfg
 
+LDFLAGS += -lnet
+
 OBJ = main.o
 BIN = ../ping
 
index 7920545..4c8c84d 100644 (file)
@@ -6,6 +6,7 @@
 #include <stdio.h>
 #include <string.h>
 #include <acess/sys.h>
+#include <net.h>
 
 // === CONSTANTS ===
 #define IPSTACK_ROOT   "/Devices/ip"
@@ -15,6 +16,9 @@ void  PrintUsage(char *ProgName);
 void   PrintHelp(char *ProgName);
  int   GetAddress( char *Address, uint8_t *Addr );
 
+// === GLOBALS ===
+ int   giNumberOfPings = 1;
+
 // === CODE ===
 /**
  * \fn int main(int argc, char *argv[])
@@ -27,6 +31,8 @@ int main(int argc, char *argv[])
         int    i, j;
        uint8_t addr[16];
         int    type;
+        
+        int    fd, call, ping;
        
        for(i = 1; i < argc; i++)
        {
@@ -69,7 +75,7 @@ int main(int argc, char *argv[])
        }
        
        // Read Address
-       type = GetAddress(ipStr, addr);
+       type = Net_ParseAddress(ipStr, addr);
        if( type == 0 ) {
                fprintf(stderr, "Invalid IP Address\n");
                return 1;
@@ -77,28 +83,45 @@ int main(int argc, char *argv[])
        
        if( !iface )
        {
-               fprintf(stderr, "WARNING: \"All interfaces\" is currently uniplemented");
-               return 2;
+               iface = Net_GetInterface(type, addr);
+               if( !iface ) {
+                       fprintf(stderr, "Unable to find a route to '%s'\n",
+                               Net_PrintAddress(type, addr)
+                               );
+                       return -1;
+               }
+               
+               printf("iface = '%s'\n", iface);
        }
-       else
+       
        {
-                int    fd = open(iface, OPENFLAG_EXEC);
-                int    call, ping;
-               if(fd == -1) {
-                       fprintf(stderr, "ERROR: Unable to open interface '%s'\n", iface);
-                       return 1;
-               }
+               char    *_iface = malloc( sizeof("/Devices/ip/") + strlen(iface) + 1 );
+               strcpy(_iface, "/Devices/ip/");
+               strcat(_iface, iface);
+               free(iface);    // TODO: Handle when this is not heap
+               iface = _iface;
+               printf("iface = '%s'\n", iface);
+       }
+       
+       fd = open(iface, OPENFLAG_EXEC);
+       if(fd == -1) {
+               fprintf(stderr, "ERROR: Unable to open interface '%s'\n", iface);
+               return 1;
+       }
                
-               call = ioctl(fd, 3, "ping");
-               if(call == 0) {
-                       fprintf(stderr, "ERROR: '%s' does not have a 'ping' call\n", iface);
-                       return 1;
-               }
+       call = ioctl(fd, 3, "ping");
+       if(call == 0) {
+               fprintf(stderr, "ERROR: '%s' does not have a 'ping' call\n", iface);
+               return 1;
+       }
+       
+       for( i = 0; i < giNumberOfPings; i ++ )
+       {
                ping = ioctl(fd, call, addr);
-               printf("ping = %i\n");
-               
-               close(fd);
+               printf("ping = %i\n", ping);
        }
+               
+       close(fd);
        
        return 0;
 }

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