mirror of
https://github.com/RGBCube/serenity
synced 2025-05-28 22:05:06 +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:
parent
626e176cab
commit
6d1418aa7a
6 changed files with 146 additions and 47 deletions
|
@ -125,16 +125,8 @@ int TCPSocket::protocol_send(const void* data, int data_length)
|
|||
|
||||
void TCPSocket::send_tcp_packet(u16 flags, const void* payload, int payload_size)
|
||||
{
|
||||
if (!m_adapter) {
|
||||
if (has_specific_local_address()) {
|
||||
m_adapter = NetworkAdapter::from_ipv4_address(local_address());
|
||||
} else {
|
||||
m_adapter = adapter_for_route_to(peer_address());
|
||||
if (m_adapter)
|
||||
set_local_address(m_adapter->ipv4_address());
|
||||
}
|
||||
}
|
||||
ASSERT(!!m_adapter);
|
||||
auto routing_decision = route_to(peer_address(), local_address());
|
||||
ASSERT(!!routing_decision.adapter);
|
||||
|
||||
auto buffer = ByteBuffer::create_zeroed(sizeof(TCPPacket) + payload_size);
|
||||
auto& tcp_packet = *(TCPPacket*)(buffer.pointer());
|
||||
|
@ -170,7 +162,7 @@ void TCPSocket::send_tcp_packet(u16 flags, const void* payload, int payload_size
|
|||
tcp_packet.sequence_number(),
|
||||
tcp_packet.ack_number());
|
||||
#endif
|
||||
m_adapter->send_ipv4(MACAddress(), peer_address(), IPv4Protocol::TCP, buffer.data(), buffer.size());
|
||||
routing_decision.adapter->send_ipv4(routing_decision.next_hop, peer_address(), IPv4Protocol::TCP, buffer.data(), buffer.size());
|
||||
|
||||
m_packets_out++;
|
||||
m_bytes_out += buffer.size();
|
||||
|
@ -249,19 +241,11 @@ KResult TCPSocket::protocol_listen()
|
|||
|
||||
KResult TCPSocket::protocol_connect(FileDescription& description, ShouldBlock should_block)
|
||||
{
|
||||
if (!m_adapter) {
|
||||
if (has_specific_local_address()) {
|
||||
m_adapter = NetworkAdapter::from_ipv4_address(local_address());
|
||||
if (!m_adapter)
|
||||
return KResult(-EADDRNOTAVAIL);
|
||||
} else {
|
||||
m_adapter = adapter_for_route_to(peer_address());
|
||||
if (!m_adapter)
|
||||
return KResult(-EHOSTUNREACH);
|
||||
|
||||
set_local_address(m_adapter->ipv4_address());
|
||||
}
|
||||
}
|
||||
auto routing_decision = route_to(peer_address(), local_address());
|
||||
if (!routing_decision.adapter || routing_decision.next_hop.is_zero())
|
||||
return KResult(-EHOSTUNREACH);
|
||||
if (!has_specific_local_address())
|
||||
set_local_address(routing_decision.adapter->ipv4_address());
|
||||
|
||||
allocate_local_port_if_needed();
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue