From: John Hodge Date: Tue, 13 Jul 2010 14:38:53 +0000 (+0800) Subject: Cleaning up some debug, fixing cosmetic bugs in usermode apps X-Git-Tag: rel0.06~111 X-Git-Url: https://git.ucc.asn.au/?a=commitdiff_plain;h=c0078bf13fa69e05235341a2863c873b7a76180a;p=tpg%2Facess2.git Cleaning up some debug, fixing cosmetic bugs in usermode apps --- diff --git a/Modules/IPStack/arp.c b/Modules/IPStack/arp.c index cedc0b31..d9f837cf 100644 --- a/Modules/IPStack/arp.c +++ b/Modules/IPStack/arp.c @@ -221,6 +221,7 @@ void ARP_int_GetPacket(tAdapter *Adapter, tMacAddr From, int Length, void *Buffe Log_Log("ARP", "Recieved a packet with HWSize != 6 (%i)", req4->HWSize); return; } + #if ARP_DETECT_SPOOFS if( !MAC_EQU(req4->SourceMac, From) ) { Log_Log("ARP", "ARP spoofing detected " "(%02x%02x:%02x%02x:%02x%02x != %02x%02x:%02x%02x:%02x%02x)", @@ -231,35 +232,36 @@ void ARP_int_GetPacket(tAdapter *Adapter, tMacAddr From, int Length, void *Buffe ); return; } + #endif - Log("[ARP ] Request ID %i", ntohs(req4->Request)); + Log_Debug("ARP", "Request ID %i", ntohs(req4->Request)); switch( ntohs(req4->Request) ) { case 1: // You want my IP? - Log("[ARP ] ARP Request Address class %i", req4->SWSize); + Log_Debug("ARP", "ARP Request Address class %i", req4->SWSize); // Check what type of IP it is switch( req4->SWSize ) { case 4: - Log("[ARP ] From MAC %02x:%02x:%02x:%02x:%02x:%02x", + Log_Debug("ARP", "From MAC %02x:%02x:%02x:%02x:%02x:%02x", req4->SourceMac.B[0], req4->SourceMac.B[1], req4->SourceMac.B[2], req4->SourceMac.B[3], req4->SourceMac.B[4], req4->SourceMac.B[5]); - Log("[ARP ] to MAC %02x:%02x:%02x:%02x:%02x:%02x", + Log_Debug("ARP", "to MAC %02x:%02x:%02x:%02x:%02x:%02x", req4->DestMac.B[0], req4->DestMac.B[1], req4->DestMac.B[2], req4->DestMac.B[3], req4->DestMac.B[4], req4->DestMac.B[5]); - Log("[ARP ] ARP Request IPv4 Address %i.%i.%i.%i", + Log_Debug("ARP", "ARP Request IPv4 Address %i.%i.%i.%i", req4->DestIP.B[0], req4->DestIP.B[1], req4->DestIP.B[2], req4->DestIP.B[3]); - Log("[ARP ] from %i.%i.%i.%i", + Log_Debug("ARP", "from %i.%i.%i.%i", req4->SourceIP.B[0], req4->SourceIP.B[1], req4->SourceIP.B[2], req4->SourceIP.B[3]); iface = IPv4_GetInterface(Adapter, req4->DestIP, 0); if( iface ) { - Log("[ARP ] Caching sender's IP Address"); + Log_Debug("ARP", "Caching sender's IP Address"); ARP_UpdateCache4(req4->SourceIP, req4->SourceMac); req4->DestIP = req4->SourceIP; @@ -267,8 +269,8 @@ void ARP_int_GetPacket(tAdapter *Adapter, tMacAddr From, int Length, void *Buffe req4->SourceIP = iface->IP4.Address; req4->SourceMac = Adapter->MacAddr; req4->Request = htons(2); - Log("[ARP ] Hey, That's us!"); - Log("[ARP ] Sending back %02x:%02x:%02x:%02x:%02x:%02x", + Log_Debug("ARP", "Hey, That's us!"); + Log_Debug("ARP", "Sending back %02x:%02x:%02x:%02x:%02x:%02x", req4->SourceMac.B[0], req4->SourceMac.B[1], req4->SourceMac.B[2], req4->SourceMac.B[3], req4->SourceMac.B[4], req4->SourceMac.B[5]); @@ -277,7 +279,7 @@ void ARP_int_GetPacket(tAdapter *Adapter, tMacAddr From, int Length, void *Buffe break; case 6: if( Length < sizeof(tArpRequest6) ) { - Log("[ARP ] Recieved undersized packet (IPv6)"); + Log_Debug("ARP", "Recieved undersized packet (IPv6)"); return ; } iface = IPv6_GetInterface(Adapter, req6->DestIP, 0); @@ -292,7 +294,7 @@ void ARP_int_GetPacket(tAdapter *Adapter, tMacAddr From, int Length, void *Buffe } break; default: - Log("[ARP ] Unknown Protocol Address size (%i)", req4->SWSize); + Log_Debug("ARP", "Unknown Protocol Address size (%i)", req4->SWSize); return ; } @@ -307,13 +309,13 @@ void ARP_int_GetPacket(tAdapter *Adapter, tMacAddr From, int Length, void *Buffe break; case 6: if( Length < sizeof(tArpRequest6) ) { - Log("[ARP ] Recieved undersized packet (IPv6)"); + Log_Debug("ARP", "Recieved undersized packet (IPv6)"); return ; } ARP_UpdateCache6( req6->SourceIP, From ); break; default: - Log("[ARP ] Unknown Protocol Address size (%i)", req4->SWSize); + Log_Debug("ARP", "Unknown Protocol Address size (%i)", req4->SWSize); return ; } diff --git a/Modules/IPStack/ipv4.c b/Modules/IPStack/ipv4.c index a1b9178b..aff593a6 100644 --- a/Modules/IPStack/ipv4.c +++ b/Modules/IPStack/ipv4.c @@ -217,8 +217,6 @@ Uint16 IPv4_Checksum(void *Buf, int Size) Uint16 *arr = Buf; int i; - Log("IPv4_Checksum: (%p, %i)", Buf, Size); - Size = (Size + 1) >> 1; for(i = 0; i < Size; i++ ) { diff --git a/Modules/IPStack/link.c b/Modules/IPStack/link.c index d9145704..ef17c937 100644 --- a/Modules/IPStack/link.c +++ b/Modules/IPStack/link.c @@ -162,6 +162,8 @@ void Link_WatchDevice(tAdapter *Adapter) } Log_Log("NET", "Watcher terminated (file closed)"); + + Threads_Exit(0, 0); } // From http://www.cl.cam.ac.uk/research/srg/bluebook/21/crc/node6.html diff --git a/Usermode/Applications/Makefile.tpl b/Usermode/Applications/Makefile.tpl index 530054b4..aadfbdba 100644 --- a/Usermode/Applications/Makefile.tpl +++ b/Usermode/Applications/Makefile.tpl @@ -2,7 +2,7 @@ # # -CFLAGS += -Wall -fno-builtin -fno-stack-protector -g +CFLAGS += -Wall -Werror -fno-builtin -fno-stack-protector -g LDFLAGS += DEPFILES := $(OBJ:%.o=%.d) diff --git a/Usermode/Applications/ifconfig_src/main.c b/Usermode/Applications/ifconfig_src/main.c index 1047ca34..ca9b73be 100644 --- a/Usermode/Applications/ifconfig_src/main.c +++ b/Usermode/Applications/ifconfig_src/main.c @@ -11,125 +11,168 @@ #define IPSTACK_ROOT "/Devices/ip" // === PROTOTYPES === -void PrintUsage(char *ProgName); -void DumpInterfaces( int DumpAll ); - int AddInterface( char *Address ); - int DoAutoConfig( char *Device ); +void PrintUsage(const char *ProgName); +void DumpInterfaces(void); +void DumpInterface(const char *Name); + int AddInterface(const char *Device); + int DoAutoConfig(const char *Device); // === CODE === /** - * \fn int main(int argc, char *argv[]) - * \brief Entrypoint + * \brief Program entrypoint */ int main(int argc, char *argv[]) { + // No args, dump interfaces if(argc == 1) { - DumpInterfaces(0); + DumpInterfaces(); return 0; } + // Add a new interface if( strcmp(argv[1], "add") == 0 ) { - if( argc < 3 ) { - fprintf(stderr, "ERROR: `add` requires an argument\n"); + if( argc < 4 ) { + fprintf(stderr, "ERROR: %s add require two arguments, %i passed\n", argv[0], argc-2); PrintUsage(argv[0]); return 0; } + // TODO: Also set the IP address as the usage says it does return AddInterface( argv[2] ); } + // Autoconfigure an interface + // NOTE: Debugging hack (see the function for more details) if( strcmp(argv[1], "autoconf") == 0 ) { DoAutoConfig(argv[2]); return 0; } + // Print usage instructions PrintUsage(argv[0]); return 0; } -void PrintUsage(char *ProgName) +/** + * \brief Print usage instructions + */ +void PrintUsage(const char *ProgName) { - fprintf(stderr, "Usage: %s [add ]\n", ProgName); + fprintf(stderr, "Usage:\n"); + fprintf(stderr, " %s add /\n", ProgName); + fprintf(stderr, " Add a new interface listening on with the specified\n"); + fprintf(stderr, " address.\n"); + fprintf(stderr, " %s del \n", ProgName); + fprintf(stderr, " %s set