NetTest - Compiles, doesn't yet do much
authorJohn Hodge (sonata) <[email protected]>
Sat, 26 Jan 2013 09:40:53 +0000 (17:40 +0800)
committerJohn Hodge (sonata) <[email protected]>
Sat, 26 Jan 2013 09:40:53 +0000 (17:40 +0800)
Tools/NetTest/Makefile
Tools/NetTest/include/nettest.h [new file with mode: 0644]
Tools/NetTest/main.c
Tools/NetTest/nic.c
Tools/NetTest/tap.c
Tools/NetTest/vfs_shim.c
Tools/nativelib/Makefile
Tools/nativelib/threads.c

index 1679a28..45e76b2 100644 (file)
@@ -14,7 +14,8 @@ MODULE_SRC = ../../KernelLand/Modules/
 BIN = ../nettest
 # Kernel Sources (compiled with -ffreestanding)
 K_OBJ := lib.o adt.o
-#K_OBJ += vfs/main.o vfs/open.o vfs/acls.o vfs/io.o vfs/dir.o
+K_OBJ += vfs/acls.o vfs/io.o vfs/fs/devfs.o
+#K_OBJ += vfs/main.o vfs/open.o vfs/io.o vfs/dir.o
 #K_OBJ += vfs/nodecache.o vfs/mount.o vfs/memfile.o # vfs/select.o
 #K_OBJ += vfs/fs/root.o vfs/fs/devfs.o
 #K_OBJ += drvutil_disk.o drv/proc.o
diff --git a/Tools/NetTest/include/nettest.h b/Tools/NetTest/include/nettest.h
new file mode 100644 (file)
index 0000000..c8d16b8
--- /dev/null
@@ -0,0 +1,20 @@
+/*
+ * Acess2 Networking Test Suite (NetTest)
+ * - By John Hodge (thePowersGang)
+ *
+ * nettest.h
+ * - Common functions
+ */
+#ifndef _NETTEST_H_
+#define _NETTEST_H_
+
+#include <stddef.h>
+
+extern int     NativeNic_AddDev(char *Desc);
+
+extern void    *NetTest_OpenTap(const char *Name);
+extern size_t  NetTest_WritePacket(void *Handle, size_t Size, const void *Data);
+extern size_t  NetTest_ReadPacket(void *Handle, size_t MaxSize, void *Data);
+
+#endif
+
index e69de29..d614da6 100644 (file)
@@ -0,0 +1,57 @@
+/*
+ * Acess2 Networking Test Suite (NetTest)
+ * - By John Hodge (thePowersGang)
+ *
+ * main.c
+ * - Program Core
+ */
+#include <stdio.h>
+#include <acess_logging.h>
+#include <nettest.h>
+#include <string.h>
+
+extern int     IPStack_Install(char **Args);
+
+// === CODE ===
+void PrintUsage(const char *ProgramName)
+{
+       fprintf(stderr, "Usage: %s <commands...>\n", ProgramName);
+       fprintf(stderr, "\n");
+       fprintf(stderr,
+               "-dev <tapdev>:<mac>\n"
+               "-ip <dev>,<addr>,<mask>\n"
+               "-route <net>,<mask>,<nexthop>\n"
+               );
+}
+
+int main(int argc, char *argv[])
+{
+       if( argc <= 1 ) {
+               PrintUsage(argv[0]);
+               return 1;
+       }
+       
+       // Startup
+       {
+               char    *ipstack_args[] = {NULL};
+               IPStack_Install( ipstack_args );
+       }
+       
+       for( int i = 0; i < argc; i ++ )
+       {
+               if( argv[i][0] != '-' ) {
+               }
+               else if( strcmp(argv[i], "-dev") == 0 )
+               {
+                       if( ++i == argc ) { PrintUsage(argv[0]); return 1; }
+                       NativeNic_AddDev(argv[i]);
+               }
+       }
+
+       // Run suite
+       
+
+       // Teardown
+
+       return 0;
+}
index e69de29..1e736c2 100644 (file)
@@ -0,0 +1,78 @@
+/*
+ * Acess2 Networking Test Suite (NetTest)
+ * - By John Hodge (thePowersGang)
+ *
+ * nic.c
+ * - Acess -> TAP Wrapper
+ */
+#include <acess.h>
+#include <IPStack/include/adapters_api.h>
+#include <nettest.h>
+
+// === CONSTANTS ===
+static const int MTU = 1520;
+
+// === PROTOTYPES ===
+void   NativeNic_int_FreePacket(void *Ptr, size_t pkt_length, size_t Unused, const void *DataPtr);
+tIPStackBuffer *NativeNic_WaitForPacket(void *Ptr);
+ int   NativeNic_SendPacket(void *Ptr, tIPStackBuffer *Buffer);
+
+// === GLOBALS ===
+tIPStack_AdapterType   gNativeNIC_AdapterType = {
+       .Name = "NativeNIC",
+       .Type = 0,      // TODO: Differentiate differnet wire protos and speeds
+       .Flags = 0,     // TODO: IP checksum offloading, MAC checksum offloading etc
+       .SendPacket = NativeNic_SendPacket,
+       .WaitForPacket = NativeNic_WaitForPacket
+       };
+
+// === CODE ===
+int NativeNic_AddDev(char *DevDesc)
+{
+       Uint8   macaddr[6];
+       char *colonpos = strchr(DevDesc, ':');
+       if( !colonpos )
+               return -1;
+       *colonpos = 0;
+       if( UnHex(macaddr, 6, DevDesc) != 6 )
+               return -1;
+       void *ptr = NetTest_OpenTap(colonpos+1);
+       if( !ptr )
+               return 1;
+       IPStack_Adapter_Add(&gNativeNIC_AdapterType, ptr, macaddr);
+       
+       return 0;
+}
+
+void NativeNic_int_FreePacket(void *Ptr, size_t pkt_length, size_t Unused, const void *DataPtr)
+{
+       free( (void*)DataPtr );
+}
+
+tIPStackBuffer *NativeNic_WaitForPacket(void *Ptr)
+{
+       char    *buf = malloc( MTU );
+       size_t  len;
+
+       len = NetTest_ReadPacket(Ptr, MTU, buf);
+
+       tIPStackBuffer  *ret = IPStack_Buffer_CreateBuffer(1);
+       IPStack_Buffer_AppendSubBuffer(ret, len, 0, buf, NativeNic_int_FreePacket, Ptr);
+       return ret;
+}
+
+int NativeNic_SendPacket(void *Ptr, tIPStackBuffer *Buffer)
+{
+       size_t  len = IPStack_Buffer_GetLength(Buffer);
+       
+       // Check against MTU
+       if( len > MTU )
+               return -1;
+       
+       // Serialise into stack
+       char    buf[len];
+       IPStack_Buffer_GetData(Buffer, buf, len);
+       
+       NetTest_WritePacket(Ptr, len, buf);
+       return 0;
+}
index e69de29..ebacf16 100644 (file)
@@ -0,0 +1,60 @@
+/*
+ * Acess2 Networking Test Suite (NetTest)
+ * - By John Hodge (thePowersGang)
+ *
+ * tap.c
+ * - TAP Network driver
+ */
+#include <nettest.h>
+#include <sys/ioctl.h>
+#include <net/if.h>
+//#include <linux/if.h>
+#include <linux/if_tun.h>
+#include <string.h>
+#include <fcntl.h>
+#include <unistd.h>
+#include <stdio.h>
+
+// === CODE ===
+void *NetTest_OpenTap(const char *Name)
+{
+        int    rv;
+
+       struct ifreq    ifr;
+       memset(&ifr, 0, sizeof(ifr));
+       ifr.ifr_flags = IFF_TAP|IFF_NO_PI;
+       
+       if( Name[0] != '\0' )
+       {
+               if( strlen(Name) > IFNAMSIZ )
+                       return NULL;
+               strncpy(ifr.ifr_name, Name, IFNAMSIZ);
+       }
+       
+        int    fd = open("/dev/net/tun", O_RDWR);
+       if( fd < 0 )
+       {
+               perror("NetTest_OpenTap - open");
+               return NULL;
+       }
+       
+       if( (rv = ioctl(fd, TUNSETIFF, &ifr)) )
+       {
+               perror("NetTest_OpenTap - ioctl(TUNSETIFF)");
+               fprintf(stderr, "Opening TUN/TAP device '%s'\n", Name);
+               close(fd);
+               return NULL;
+       }
+
+       return (void*)(intptr_t)fd;
+}
+
+size_t NetTest_WritePacket(void *Handle, size_t Size, const void *Data)
+{
+       return write( (intptr_t)Handle, Data, Size);
+}
+
+size_t NetTest_ReadPacket(void *Handle, size_t MaxSize, void *Data)
+{
+       return read( (intptr_t)Handle, Data, MaxSize);
+}
index e69de29..bc0c67c 100644 (file)
@@ -0,0 +1,48 @@
+/*
+ * Acess2 Networking Test Suite (NetTest)
+ * - By John Hodge (thePowersGang)
+ *
+ * vfs_shim.c
+ * - VFS Layer Emulation
+ */
+#include <vfs.h>
+#include <vfs_int.h>
+#include <events.h>
+
+// === CODE ===
+int VFS_SelectNode(tVFS_Node *Node, int Type, tTime *Timeout, const char *Name)
+{
+       
+       return 0;
+}
+
+int VFS_MarkAvaliable(tVFS_Node *Node, BOOL bAvail)
+{
+       Node->DataAvaliable = bAvail;
+       if( Node->DataAvaliable && Node->ReadThreads )
+               Threads_PostEvent( (void*)Node->ReadThreads, THREAD_EVENT_VFS );
+       return 0;
+}
+
+int VFS_MarkError(tVFS_Node *Node, BOOL bError)
+{
+       Node->ErrorOccurred = bError;
+       if( Node->ErrorOccurred && Node->ErrorThreads )
+               Threads_PostEvent( (void*)Node->ErrorThreads, THREAD_EVENT_VFS );
+       return 0;
+}
+
+int VFS_Open(const char *Path, Uint Flags)
+{
+       return -1;
+}
+
+void VFS_Close(int FD)
+{
+}
+
+tVFS_Handle *VFS_GetHandle(int FD)
+{
+       return NULL;
+}
+
index 2a6eb6d..84ac328 100644 (file)
@@ -3,6 +3,9 @@ KERNEL_DIR := ../../KernelLand/Kernel
 
 NOBJ := logging.o misc.o
 KOBJ := threads.o time.o mutex.o
+
+NOBJ := $(NOBJ:%.o=obj/%.o)
+KOBJ := $(KOBJ:%.o=obj/%.o)
 OBJ := $(NOBJ) $(KOBJ)
 BIN := ../libnativelib.a
 
@@ -20,8 +23,12 @@ clean:
 $(BIN): $(OBJ)
        ar cru $(BIN) $(OBJ)
 
-$(NOBJ): %.o: %.c
-       $(CC) -o $@ -c $< $(CFLAGS) $(CPPFLAGS)
-$(KOBJ): %.o: %.c
-       $(CC) -o $@ -c $< $(CFLAGS) $(CPPFLAGS) -I $(KERNEL_DIR)/include
+$(NOBJ): obj/%.o: %.c
+       @echo [CC Native] $@
+       @mkdir -p $(dir $@)
+       @$(CC) -o $@ -c $< $(CFLAGS) $(CPPFLAGS)
+$(KOBJ): obj/%.o: %.c
+       @echo [CC Kernel] $@
+       @mkdir -p $(dir $@)
+       @$(CC) -o $@ -c $< $(CFLAGS) $(CPPFLAGS) -I $(KERNEL_DIR)/include
 
index 5055dc3..501954d 100644 (file)
@@ -63,3 +63,9 @@ int *Threads_GetErrno(void)// __attribute__ ((weak))
        return &a_errno;
 }
 
+struct sThread *Proc_SpawnWorker(void (*Fcn)(void*), void *Data)
+{
+       Log_Error("Threads", "TODO - Use pthreads to impliment Proc_SpawnWorker");
+       return NULL;
+}
+

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