diff options
author | Anton Kling <anton@kling.gg> | 2024-07-08 21:37:15 +0200 |
---|---|---|
committer | Anton Kling <anton@kling.gg> | 2024-07-08 21:37:15 +0200 |
commit | e49d2a9fa5a485c33a250ce843d44fc6dedea8b5 (patch) | |
tree | 4be00773adca0b6c59da6d07602338ff538a7199 /kernel/network/ipv4.c | |
parent | 35292a486c2b44862cac6887441d6fa18148b249 (diff) |
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.
Diffstat (limited to 'kernel/network/ipv4.c')
-rw-r--r-- | kernel/network/ipv4.c | 5 |
1 files changed, 3 insertions, 2 deletions
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) { |