summaryrefslogtreecommitdiff
path: root/kernel/network
diff options
context:
space:
mode:
authorAnton Kling <anton@kling.gg>2023-11-22 00:47:55 +0100
committerAnton Kling <anton@kling.gg>2023-11-22 00:47:55 +0100
commitf3c7d7fbdea1f2bac81909116ddb747a1f8abdf5 (patch)
tree62a1d998ce11bf4db4343f69dea4e8d231191e48 /kernel/network
parent24f81104f5ff9cb4ab7db766c53f77fe0e5b86cc (diff)
Meta: Cleanup of header files such that they are partially shared
The /include directory contains definitons that both the kernel and libc need to be in sync.
Diffstat (limited to 'kernel/network')
-rw-r--r--kernel/network/arp.c7
-rw-r--r--kernel/network/ethernet.c8
-rw-r--r--kernel/network/ipv4.c3
-rw-r--r--kernel/network/tcp.c18
4 files changed, 7 insertions, 29 deletions
diff --git a/kernel/network/arp.c b/kernel/network/arp.c
index dfa1131..b5825be 100644
--- a/kernel/network/arp.c
+++ b/kernel/network/arp.c
@@ -114,12 +114,6 @@ void handle_arp(const u8 *payload) {
assert(4 == data->plen);
// Assert it is a request
if (0x0001 /*arp_request*/ == ntohs(data->opcode)) {
- print_mac("srchw: ", data->srchw);
- print_ip("srcpr: ", data->srcpr);
-
- print_mac("dsthw: ", data->dsthw);
- print_ip("dstpr: ", data->dstpr);
-
struct ARP_TABLE_ENTRY *entry = find_arp_entry_to_use();
entry->is_used = 1;
memcpy(entry->mac, data->srchw, sizeof(uint8_t[6]));
@@ -148,7 +142,6 @@ void handle_arp(const u8 *payload) {
entry->is_used = 1;
memcpy(entry->mac, data->srchw, sizeof(u8[6]));
memcpy(entry->ip, data->srcpr, sizeof(u8[4]));
- print_ip("Added ip: ", entry->ip);
} else {
kprintf("GOT A ARP REQEUST WITH TYPE: %x\n", ntohs(data->opcode));
assert(0);
diff --git a/kernel/network/ethernet.c b/kernel/network/ethernet.c
index 5cf1a54..6255ecb 100644
--- a/kernel/network/ethernet.c
+++ b/kernel/network/ethernet.c
@@ -50,10 +50,6 @@ void handle_ethernet(const u8 *packet, u64 packet_length) {
packet += sizeof(struct ETHERNET_HEADER);
const u8 *payload = packet;
packet += packet_length - sizeof(struct ETHERNET_HEADER);
- u32 crc = *((u32 *)packet - 1);
- kprintf("PACKET crc: %x\n", crc);
- kprintf("OUR OWN CALCULATED crc: %x\n",
- crc32((const char *)eth_header, (packet_length - 4)));
u16 type = ntohs(eth_header->type);
switch (type) {
@@ -84,10 +80,8 @@ void send_ethernet_packet(u8 mac_dst[6], u16 type, u8 *payload,
memcpy(eth_header->mac_dst, mac_dst, sizeof(u8[6]));
get_mac_address(eth_header->mac_src);
eth_header->type = htons(type);
- *(u32 *)(buffer) =
- htonl(crc32((const char *)buffer_start, buffer_size - 4));
+ *(u32 *)(buffer) = htonl(crc32((const char *)buffer_start, buffer_size - 4));
assert(rtl8139_send_data(buffer_start, buffer_size));
kfree(buffer_start);
- kprintf("sent data\n");
}
diff --git a/kernel/network/ipv4.c b/kernel/network/ipv4.c
index 891e74f..e38ab9b 100644
--- a/kernel/network/ipv4.c
+++ b/kernel/network/ipv4.c
@@ -63,9 +63,7 @@ void send_ipv4_packet(u32 ip, u8 protocol, const u8 *payload,
memcpy(ip_copy, &ip, sizeof(u8[4]));
for (; !get_mac_from_ip(ip_copy, mac);)
;
- kprintf("pre send_ethernet: %x\n", pit_num_ms());
send_ethernet_packet(mac, 0x0800, packet, packet_length);
- kprintf("after send_ethernet: %x\n", pit_num_ms());
kfree(packet);
}
@@ -80,7 +78,6 @@ void handle_ipv4(const u8 *payload, u32 packet_length) {
u8 version = (*payload & 0xF0) >> 4;
u8 IHL = (*payload & 0xF);
- kprintf("version: %x\n", version);
assert(4 == version);
assert(5 == IHL);
u16 ipv4_total_length = ntohs(*(u16 *)(payload + 2));
diff --git a/kernel/network/tcp.c b/kernel/network/tcp.c
index 6c693cf..4b2c462 100644
--- a/kernel/network/tcp.c
+++ b/kernel/network/tcp.c
@@ -60,9 +60,8 @@ u16 tcp_checksum(u16 *buffer, int size) {
return (u16)(~cksum);
}
-void tcp_calculate_checksum(u8 src_ip[4], u8 dst_ip[4],
- const u8 *payload, u16 payload_length,
- struct TCP_HEADER *header) {
+void tcp_calculate_checksum(u8 src_ip[4], u8 dst_ip[4], const u8 *payload,
+ u16 payload_length, struct TCP_HEADER *header) {
struct PSEUDO_TCP_HEADER ps = {0};
memcpy(&ps.src_addr, src_ip, sizeof(u32));
memcpy(&ps.dst_addr, dst_ip, sizeof(u32));
@@ -135,8 +134,7 @@ void send_tcp_packet(struct INCOMING_TCP_CONNECTION *inc, u8 *payload,
}
void send_empty_tcp_message(struct INCOMING_TCP_CONNECTION *inc, u8 flags,
- u32 inc_seq_num, u16 n_dst_port,
- u16 n_src_port) {
+ u32 inc_seq_num, u16 n_dst_port, u16 n_src_port) {
struct TCP_HEADER header = {0};
header.src_port = n_dst_port;
header.dst_port = n_src_port;
@@ -148,15 +146,13 @@ void send_empty_tcp_message(struct INCOMING_TCP_CONNECTION *inc, u8 flags,
header.window_size = htons(512); // TODO: What does this actually mean?
header.urgent_pointer = 0;
char payload[0];
- tcp_calculate_checksum(ip_address, inc->ip, (const u8 *)payload, 0,
- &header);
+ tcp_calculate_checksum(ip_address, inc->ip, (const u8 *)payload, 0, &header);
u32 dst_ip;
memcpy(&dst_ip, inc->ip, sizeof(dst_ip));
send_ipv4_packet(dst_ip, 6, (const u8 *)&header, sizeof(header));
}
-void handle_tcp(u8 src_ip[4], const u8 *payload,
- u32 payload_length) {
+void handle_tcp(u8 src_ip[4], const u8 *payload, u32 payload_length) {
const struct TCP_HEADER *inc_header = (const struct TCP_HEADER *)payload;
u16 n_src_port = *(u16 *)(payload);
u16 n_dst_port = *(u16 *)(payload + 2);
@@ -225,12 +221,10 @@ void handle_tcp(u8 src_ip[4], const u8 *payload,
header.window_size = htons(512); // TODO: What does this actually mean?
header.urgent_pointer = 0;
char payload[0];
- tcp_calculate_checksum(ip_address, src_ip, (const u8 *)payload, 0,
- &header);
+ tcp_calculate_checksum(ip_address, src_ip, (const u8 *)payload, 0, &header);
u32 dst_ip;
memcpy(&dst_ip, src_ip, sizeof(dst_ip));
send_ipv4_packet(dst_ip, 6, (const u8 *)&header, sizeof(header));
- kprintf("after ipv4 packet: %x\n", pit_num_ms());
return;
}
}