1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-31 05:08:13 +00:00

Kernel: Add simple ARP routing layer

This replaces the previous placeholder routing layer with a real one!
It's still very primitive, doesn't deal with things like timeouts very
well, and will probably need several more iterations to support more
normal networking things.

I haven't confirmed that this works with anything other than the QEMU
user networking layer, but I suspect that's what nearly everybody is
using at this point, so that's the important target to keep working.
This commit is contained in:
Conrad Pankoff 2019-08-28 21:58:01 +10:00 committed by Andreas Kling
parent 626e176cab
commit 6d1418aa7a
6 changed files with 146 additions and 47 deletions

View file

@ -63,8 +63,8 @@ int UDPSocket::protocol_receive(const KBuffer& packet_buffer, void* buffer, size
int UDPSocket::protocol_send(const void* data, int data_length)
{
auto adapter = adapter_for_route_to(peer_address());
if (!adapter)
auto routing_decision = route_to(peer_address(), local_address());
if (!routing_decision.adapter)
return -EHOSTUNREACH;
auto buffer = ByteBuffer::create_zeroed(sizeof(UDPPacket) + data_length);
auto& udp_packet = *(UDPPacket*)(buffer.pointer());
@ -73,11 +73,11 @@ int UDPSocket::protocol_send(const void* data, int data_length)
udp_packet.set_length(sizeof(UDPPacket) + data_length);
memcpy(udp_packet.payload(), data, data_length);
kprintf("sending as udp packet from %s:%u to %s:%u!\n",
adapter->ipv4_address().to_string().characters(),
routing_decision.adapter->ipv4_address().to_string().characters(),
local_port(),
peer_address().to_string().characters(),
peer_port());
adapter->send_ipv4(MACAddress(), peer_address(), IPv4Protocol::UDP, buffer.data(), buffer.size());
routing_decision.adapter->send_ipv4(routing_decision.next_hop, peer_address(), IPv4Protocol::UDP, buffer.data(), buffer.size());
return data_length;
}