diff --git a/src/tests/kits/net/new_stack/Jamfile b/src/tests/kits/net/new_stack/Jamfile index ceb490b34e..cc8f0597aa 100644 --- a/src/tests/kits/net/new_stack/Jamfile +++ b/src/tests/kits/net/new_stack/Jamfile @@ -2,6 +2,8 @@ SubDir OBOS_TOP src tests kits net new_stack ; UseHeaders [ FDirName $(OBOS_TOP) src tests kits net new_stack headers ] ; +Depends new_stack_tester : userland_network_v2_modules ; + SimpleTest new_stack_tester : net_stack_server.cpp userland_modules.cpp diff --git a/src/tests/kits/net/new_stack/interfaces/loopback/loopback.c b/src/tests/kits/net/new_stack/interfaces/loopback/loopback.c index 64aa62159e..1d6836aa8b 100644 --- a/src/tests/kits/net/new_stack/interfaces/loopback/loopback.c +++ b/src/tests/kits/net/new_stack/interfaces/loopback/loopback.c @@ -18,26 +18,26 @@ static struct net_stack_module_info *g_stack = NULL; // ------------------- -status_t init(net_layer *me) +static status_t init(net_layer *me) { dprintf("%s: initing layer\n", me->name); return B_OK; } -status_t uninit(net_layer *me) +static status_t uninit(net_layer *me) { dprintf("loopback: uniniting layer\n"); return B_OK; } -status_t enable(net_layer *me, bool enable) +static status_t enable(net_layer *me, bool enable) { return B_OK; } -status_t process_output(net_layer *me, net_buffer *buffer) +static status_t process_output(net_layer *me, net_buffer *buffer) { if (!buffer) return B_ERROR; diff --git a/src/tests/kits/net/new_stack/protocols/arp/arp.c b/src/tests/kits/net/new_stack/protocols/arp/arp.c index 71f49b401f..1d71e5ba3a 100644 --- a/src/tests/kits/net/new_stack/protocols/arp/arp.c +++ b/src/tests/kits/net/new_stack/protocols/arp/arp.c @@ -69,7 +69,7 @@ static void dump_arp(net_buffer *buffer) default: pname = "unknown"; break; }; - dprintf("========== Address Resolution Protocol ==========\n"); + dprintf("========== Address Resolution Protocol (ARP) ====\n"); dprintf("Hardware : %s\n", ntohs(arp.hardware_type) == ARP_HARDWARE_TYPE_ETHERNET ? "ethernet" : "unknown"); dprintf("Protocol : 0x%04x (%s)\n", ntohs(arp.protocol_type), pname); @@ -142,7 +142,6 @@ static status_t process_input(net_layer *me, net_buffer *buffer) return B_ERROR; // TODO! - // dprintf("%s: packet %p is an ARP packet!\n", me->name, buffer); dump_arp(buffer); g_stack->delete_buffer(buffer, false); diff --git a/src/tests/kits/net/new_stack/protocols/ipv4/ipv4.c b/src/tests/kits/net/new_stack/protocols/ipv4/ipv4.c index 5d4fea72cb..94c14b722b 100644 --- a/src/tests/kits/net/new_stack/protocols/ipv4/ipv4.c +++ b/src/tests/kits/net/new_stack/protocols/ipv4/ipv4.c @@ -14,18 +14,77 @@ #include "net_stack.h" +typedef struct ipv4_addr { + uint8 byte[4]; +} ipv4_addr; + + +typedef struct ipv4_header { + uint8 version_header_length; + uint8 tos; + uint16 total_length; + uint16 identification; + uint16 flags_frag_offset; + uint8 ttl; + uint8 protocol; + uint16 header_checksum; + ipv4_addr src; + ipv4_addr dst; +} _PACKED ipv4_header; + +#define IPV4_FLAG_MORE_FRAGS 0x2000 +#define IPV4_FLAG_MAY_NOT_FRAG 0x4000 +#define IPV4_FRAG_OFFSET_MASK 0x1fff + + + status_t std_ops(int32 op, ...); struct net_layer_module_info nlmi; static struct net_stack_module_info *g_stack = NULL; - net_attribute_id ethernet_protocol_attr; +static uint32 g_next_ipv4_id = 0; + +static void dump_ipv4_header(net_buffer *buffer) +{ + ipv4_header iph; + const char *pname; + + g_stack->read_buffer(buffer, 0, &iph, sizeof(iph)); + + switch(iph.protocol) { + case 1: pname = "ICMP"; break; + case 6: pname = "TCP"; break; + case 17: pname = "UDP"; break; + default: pname = "unknown"; break; + }; + + dprintf("========== Internet Protocol (IPv4) =============\n"); + + dprintf("Station: %d.%d.%d.%d ----> %d.%d.%d.%d\n", + iph.src.byte[3], iph.src.byte[2], iph.src.byte[1], iph.src.byte[0], + iph.dst.byte[3], iph.dst.byte[2], iph.dst.byte[1], iph.dst.byte[0]); + dprintf("Protocol: %d (%s)\n", iph.protocol, pname); + dprintf("Version: %d\n", iph.version_header_length >> 4); + dprintf("Header Length (32 bit words): %d\n", iph.version_header_length & 0x0f); + // TODO: dprintf("Precedence: \n"); + dprintf("Total length: %d\n", ntohs(iph.total_length)); + dprintf("Identification: %d\n", ntohs(iph.identification)); + // TODO: dprintf("Fragmentation allowed, Last fragment\n"); + dprintf("Fragment Offset: %d\n", ntohs(iph.flags_frag_offset) & 0x1fff); + dprintf("Time to Live: %d second(s)\n", iph.ttl); + dprintf("Checksum: 0x%X (%s)\n", ntohs(iph.header_checksum), "Valid"); // TODO: check the checksum! +} + +// #pragma mark - + // ------------------- static status_t init(net_layer *me) { printf("%s: initing layer\n", me->name); + g_next_ipv4_id = system_time(); return B_OK; } @@ -57,7 +116,7 @@ static status_t process_input(net_layer *me, net_buffer *buffer) return B_ERROR; // TODO! - dprintf("%s: packet %p is an IPv4 packet!\n", me->name, buffer); + dump_ipv4_header(buffer); g_stack->delete_buffer(buffer, false); return B_OK;