From e49d2a9fa5a485c33a250ce843d44fc6dedea8b5 Mon Sep 17 00:00:00 2001 From: Anton Kling Date: Mon, 8 Jul 2024 21:37:15 +0200 Subject: Kernel/Net: Don't use kmalloc to create send buffers Current method is also really bad since it uses multiple copies when it should instead just copy to the send buffer of the network card directly. But I have other things that I want to prioritize first. --- kernel/network/ipv4.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'kernel/network/ipv4.c') diff --git a/kernel/network/ipv4.c b/kernel/network/ipv4.c index 69ceef7..6074141 100644 --- a/kernel/network/ipv4.c +++ b/kernel/network/ipv4.c @@ -26,6 +26,7 @@ static u16 ip_checksum(const u16 *data, u16 length) { return htons(~acc); } +u8 ipv4_buffer[0x1000]; void send_ipv4_packet(ipv4_t ip, u8 protocol, const u8 *payload, u16 length) { u16 header[10]; header[0] = (4 /*version*/ << 4) | (5 /*IHL*/); @@ -46,7 +47,8 @@ void send_ipv4_packet(ipv4_t ip, u8 protocol, const u8 *payload, u16 length) { header[5] = ip_checksum(header, 20); u16 packet_length = length + 20; - u8 *packet = kmalloc(packet_length); + assert(packet_length < sizeof(ipv4_buffer)); + u8 *packet = ipv4_buffer; memcpy(packet, header, 20); memcpy(packet + 20, payload, length); @@ -54,7 +56,6 @@ void send_ipv4_packet(ipv4_t ip, u8 protocol, const u8 *payload, u16 length) { for (; !get_mac_from_ip(ip, mac);) ; send_ethernet_packet(mac, 0x0800, packet, packet_length); - kfree(packet); } void handle_ipv4(const u8 *payload, u32 packet_length) { -- cgit v1.2.3