mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 19:37:35 +00:00
Net: Use KBuffers for network adapter packet queues
This further reduces pressure on the kmalloc heap. :^)
This commit is contained in:
parent
b5f1a4ac07
commit
e58b734363
3 changed files with 11 additions and 9 deletions
|
@ -81,10 +81,10 @@ void NetworkAdapter::send_ipv4(const MACAddress& destination_mac, const IPv4Addr
|
||||||
void NetworkAdapter::did_receive(const u8* data, int length)
|
void NetworkAdapter::did_receive(const u8* data, int length)
|
||||||
{
|
{
|
||||||
InterruptDisabler disabler;
|
InterruptDisabler disabler;
|
||||||
m_packet_queue.append(ByteBuffer::copy(data, length));
|
m_packet_queue.append(KBuffer::copy(data, length));
|
||||||
}
|
}
|
||||||
|
|
||||||
ByteBuffer NetworkAdapter::dequeue_packet()
|
RefPtr<KBuffer> NetworkAdapter::dequeue_packet()
|
||||||
{
|
{
|
||||||
InterruptDisabler disabler;
|
InterruptDisabler disabler;
|
||||||
if (m_packet_queue.is_empty())
|
if (m_packet_queue.is_empty())
|
||||||
|
|
|
@ -4,6 +4,7 @@
|
||||||
#include <AK/Function.h>
|
#include <AK/Function.h>
|
||||||
#include <AK/SinglyLinkedList.h>
|
#include <AK/SinglyLinkedList.h>
|
||||||
#include <AK/Types.h>
|
#include <AK/Types.h>
|
||||||
|
#include <Kernel/KBuffer.h>
|
||||||
#include <Kernel/Net/ARP.h>
|
#include <Kernel/Net/ARP.h>
|
||||||
#include <Kernel/Net/ICMP.h>
|
#include <Kernel/Net/ICMP.h>
|
||||||
#include <Kernel/Net/IPv4.h>
|
#include <Kernel/Net/IPv4.h>
|
||||||
|
@ -28,7 +29,7 @@ public:
|
||||||
void send(const MACAddress&, const ARPPacket&);
|
void send(const MACAddress&, const ARPPacket&);
|
||||||
void send_ipv4(const MACAddress&, const IPv4Address&, IPv4Protocol, ByteBuffer&& payload);
|
void send_ipv4(const MACAddress&, const IPv4Address&, IPv4Protocol, ByteBuffer&& payload);
|
||||||
|
|
||||||
ByteBuffer dequeue_packet();
|
RefPtr<KBuffer> dequeue_packet();
|
||||||
|
|
||||||
bool has_queued_packets() const { return !m_packet_queue.is_empty(); }
|
bool has_queued_packets() const { return !m_packet_queue.is_empty(); }
|
||||||
|
|
||||||
|
@ -42,6 +43,6 @@ protected:
|
||||||
private:
|
private:
|
||||||
MACAddress m_mac_address;
|
MACAddress m_mac_address;
|
||||||
IPv4Address m_ipv4_address;
|
IPv4Address m_ipv4_address;
|
||||||
SinglyLinkedList<ByteBuffer> m_packet_queue;
|
SinglyLinkedList<NonnullRefPtr<KBuffer>> m_packet_queue;
|
||||||
String m_name;
|
String m_name;
|
||||||
};
|
};
|
||||||
|
|
|
@ -44,10 +44,10 @@ void NetworkTask_main()
|
||||||
if (adapter)
|
if (adapter)
|
||||||
adapter->set_ipv4_address(IPv4Address(192, 168, 5, 2));
|
adapter->set_ipv4_address(IPv4Address(192, 168, 5, 2));
|
||||||
|
|
||||||
auto dequeue_packet = [&]() -> ByteBuffer {
|
auto dequeue_packet = [&]() -> RefPtr<KBuffer> {
|
||||||
auto packet = LoopbackAdapter::the().dequeue_packet();
|
auto packet = LoopbackAdapter::the().dequeue_packet();
|
||||||
if (!packet.is_null()) {
|
if (!packet.is_null()) {
|
||||||
dbgprintf("Receive loopback packet (%d bytes)\n", packet.size());
|
dbgprintf("Receive loopback packet (%d bytes)\n", packet->size());
|
||||||
return packet;
|
return packet;
|
||||||
}
|
}
|
||||||
if (adapter && adapter->has_queued_packets())
|
if (adapter && adapter->has_queued_packets())
|
||||||
|
@ -57,8 +57,8 @@ void NetworkTask_main()
|
||||||
|
|
||||||
kprintf("NetworkTask: Enter main loop.\n");
|
kprintf("NetworkTask: Enter main loop.\n");
|
||||||
for (;;) {
|
for (;;) {
|
||||||
auto packet = dequeue_packet();
|
auto packet_maybe_null = dequeue_packet();
|
||||||
if (packet.is_null()) {
|
if (packet_maybe_null.is_null()) {
|
||||||
(void)current->block_until("Networking", [] {
|
(void)current->block_until("Networking", [] {
|
||||||
if (LoopbackAdapter::the().has_queued_packets())
|
if (LoopbackAdapter::the().has_queued_packets())
|
||||||
return true;
|
return true;
|
||||||
|
@ -70,11 +70,12 @@ void NetworkTask_main()
|
||||||
});
|
});
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
auto& packet = *packet_maybe_null;
|
||||||
if (packet.size() < (int)(sizeof(EthernetFrameHeader))) {
|
if (packet.size() < (int)(sizeof(EthernetFrameHeader))) {
|
||||||
kprintf("NetworkTask: Packet is too small to be an Ethernet packet! (%d)\n", packet.size());
|
kprintf("NetworkTask: Packet is too small to be an Ethernet packet! (%d)\n", packet.size());
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
auto& eth = *(const EthernetFrameHeader*)packet.pointer();
|
auto& eth = *(const EthernetFrameHeader*)packet.data();
|
||||||
#ifdef ETHERNET_DEBUG
|
#ifdef ETHERNET_DEBUG
|
||||||
kprintf("NetworkTask: From %s to %s, ether_type=%w, packet_length=%u\n",
|
kprintf("NetworkTask: From %s to %s, ether_type=%w, packet_length=%u\n",
|
||||||
eth.source().to_string().characters(),
|
eth.source().to_string().characters(),
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue