1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-02 20:22: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

@ -169,12 +169,12 @@ ssize_t IPv4Socket::sendto(FileDescription&, const void* data, size_t data_lengt
m_peer_port = ntohs(ia.sin_port);
}
auto adapter = adapter_for_route_to(m_peer_address);
if (!adapter)
auto routing_decision = route_to(m_peer_address, m_local_address);
if (!routing_decision.adapter || routing_decision.next_hop.is_zero())
return -EHOSTUNREACH;
if (m_local_address.to_u32() == 0)
m_local_address = adapter->ipv4_address();
m_local_address = routing_decision.adapter->ipv4_address();
int rc = allocate_local_port_if_needed();
if (rc < 0)
@ -183,7 +183,7 @@ ssize_t IPv4Socket::sendto(FileDescription&, const void* data, size_t data_lengt
kprintf("sendto: destination=%s:%u\n", m_peer_address.to_string().characters(), m_peer_port);
if (type() == SOCK_RAW) {
adapter->send_ipv4(MACAddress(), m_peer_address, (IPv4Protocol)protocol(), (const u8*)data, data_length);
routing_decision.adapter->send_ipv4(routing_decision.next_hop, m_peer_address, (IPv4Protocol)protocol(), (const u8*)data, data_length);
return data_length;
}