summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--BUGS3
-rw-r--r--src/kernel/kernel.c14
-rw-r--r--src/net/ipv4.c18
-rw-r--r--src/net/ipv4.h36
4 files changed, 69 insertions, 2 deletions
diff --git a/BUGS b/BUGS
index d2a7dcc..07eee74 100644
--- a/BUGS
+++ b/BUGS
@@ -32,3 +32,6 @@
- can only transmit one packet in parallel currently (transmitting
boolean flag. Taken from Tyndur. No queueing currently and
postponing of sending of packets)
+- networking:
+ - strict layering needed, we should really not see the MAC in IPv4
+ and UDP, only in ARP
diff --git a/src/kernel/kernel.c b/src/kernel/kernel.c
index 7796d34..e431327 100644
--- a/src/kernel/kernel.c
+++ b/src/kernel/kernel.c
@@ -479,7 +479,7 @@ void handle_network_event( network_event_t *event, void *context )
network_ipv4_address_to_string( arp->destination_protocol_address, dst_ip, NETWORK_PROTOCOL_IPV4_ADDR_STRING );
printf( "ARP: hw src: %s, dst: %s, ip src: %s, dst: %s, oper: %d\n",
- src_mac_addr, dst_mac_addr, src_ip, dst_ip, arp->operation );
+ src_mac_addr, dst_mac_addr, src_ip, dst_ip, arp->operation >> 8 );
// TODO: remember the address mapping
@@ -495,6 +495,18 @@ void handle_network_event( network_event_t *event, void *context )
event->buf.length = sizeof( network_ethernet_packet_header_t ) + sizeof( network_arp_packet_t );
((network_vtable_t *)( global_context.network->base.vtable ))->send( global_context.network, event->buf );
+ } else if( packet->header.type == NETWORK_ETHER_PROTOCOL_TYPE_IPV4 ) {
+ network_ipv4_packet_t *ip = (network_ipv4_packet_t *)&packet->data;
+ char src_ip[NETWORK_PROTOCOL_IPV4_ADDR_STRING];
+ char dst_ip[NETWORK_PROTOCOL_IPV4_ADDR_STRING];
+ char protocol[NETWORK_PROTOCOL_IPV4_PROTOCOL_STRING];
+
+ network_ipv4_address_to_string( ip->source_address, src_ip, NETWORK_PROTOCOL_IPV4_ADDR_STRING );
+ network_ipv4_address_to_string( ip->destination_address, dst_ip, NETWORK_PROTOCOL_IPV4_ADDR_STRING );
+ network_ipv4_protocol_to_string( ip->protocol, protocol, NETWORK_PROTOCOL_IPV4_PROTOCOL_STRING );
+
+ printf( "IPV4: ip src: %s, dst: %s, protocol: %s (%d)\n",
+ src_ip, dst_ip, protocol, ip->protocol );
}
// we must free the data if we no longer need it
diff --git a/src/net/ipv4.c b/src/net/ipv4.c
index 38ae7da..b30fe15 100644
--- a/src/net/ipv4.c
+++ b/src/net/ipv4.c
@@ -1,6 +1,7 @@
#include "ipv4.h"
#include "stdio.h"
+#include "string.h"
char *network_ipv4_address_to_string( network_ipv4_address_t addr, char *buf, size_t buflen )
{
@@ -11,3 +12,20 @@ char *network_ipv4_address_to_string( network_ipv4_address_t addr, char *buf, si
return buf;
}
+char *network_ipv4_protocol_to_string( network_ipv4_protocol_t protocol, char *buf, size_t buflen )
+{
+ switch( protocol ) {
+ case NETWORK_IPV4_PROTOCOL_ICMP:
+ strlcpy( buf, "ICMP", NETWORK_PROTOCOL_IPV4_PROTOCOL_STRING );
+ break;
+
+ case NETWORK_IPV4_PROTOCOL_UDP:
+ strlcpy( buf, "UDP", NETWORK_PROTOCOL_IPV4_PROTOCOL_STRING );
+ break;
+
+ default:
+ strlcpy( buf, "?", NETWORK_PROTOCOL_IPV4_PROTOCOL_STRING );
+ break;
+ }
+ return buf;
+}
diff --git a/src/net/ipv4.h b/src/net/ipv4.h
index acf7f7f..95dec18 100644
--- a/src/net/ipv4.h
+++ b/src/net/ipv4.h
@@ -9,10 +9,44 @@
// protocol_address_len
#define NETWORK_PROTOCOL_IPV4_ADDRESS_LENGTH 4
+// protocol string len
+#define NETWORK_PROTOCOL_IPV4_PROTOCOL_STRING 5
+
+#if defined( __TINYC__ )
+#pragma pack(1)
+#endif
+
typedef struct {
uint8_t byte[NETWORK_PROTOCOL_IPV4_ADDRESS_LENGTH];
-} network_ipv4_address_t;
+} __attribute__( ( packed ) ) network_ipv4_address_t;
+
+typedef uint8_t network_ipv4_protocol_t;
+
+// TODO: network order not host oder, so for now swap it
+#define NETWORK_IPV4_PROTOCOL_ICMP (network_ipv4_protocol_t)0x01
+#define NETWORK_IPV4_PROTOCOL_UDP (network_ipv4_protocol_t)0x11
+
+typedef struct {
+ uint8_t internet_header_length : 4;
+ uint8_t version : 4;
+ uint8_t explicit_congestion_notification : 2;
+ uint8_t differentiated_services_code_point : 6;
+ uint16_t total_length;
+ uint16_t identification;
+ uint16_t fragment_offset : 13;
+ uint16_t flags : 3;
+ uint8_t time_to_live;
+ network_ipv4_protocol_t protocol;
+ uint16_t checksum;
+ network_ipv4_address_t source_address;
+ network_ipv4_address_t destination_address;
+} __attribute__( ( packed ) ) network_ipv4_packet_t;
+
+#if defined( __TINYC__ )
+#pragma pack()
+#endif
char *network_ipv4_address_to_string( network_ipv4_address_t addr, char *buf, size_t buflen );
+char *network_ipv4_protocol_to_string( network_ipv4_protocol_t protocol, char *buf, size_t buflen );
#endif // IPV4_H