diff options
author | Gunnar Beutner <gbeutner@serenityos.org> | 2021-05-12 14:43:14 +0200 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2021-05-12 16:31:29 +0200 |
commit | 790d68ac5efed1880c42fe64ae6e75da49753964 (patch) | |
tree | f722e853bb4a3d1bed857ab525e0685ce2a1eb74 /Kernel | |
parent | 2b6aa571d11dad03d5b0f02dd392f6cf10d4f70b (diff) | |
download | serenity-790d68ac5efed1880c42fe64ae6e75da49753964.zip |
Kernel: Route packets destined for us through the loopback adapter
Without this patch we'd send packets through the physical adapter
and they'd incorrectly end up on the network.
Diffstat (limited to 'Kernel')
-rw-r--r-- | Kernel/Net/Routing.cpp | 8 |
1 files changed, 8 insertions, 0 deletions
diff --git a/Kernel/Net/Routing.cpp b/Kernel/Net/Routing.cpp index 3c6a6d0aac..d3d0355654 100644 --- a/Kernel/Net/Routing.cpp +++ b/Kernel/Net/Routing.cpp @@ -156,6 +156,11 @@ RoutingDecision route_to(const IPv4Address& target, const IPv4Address& source, c auto adapter_addr = adapter.ipv4_address().to_u32(); auto adapter_mask = adapter.ipv4_netmask().to_u32(); + if (target_addr == adapter_addr) { + local_adapter = LoopbackAdapter::the(); + return; + } + if (source_addr != 0 && source_addr != adapter_addr) return; @@ -205,6 +210,9 @@ RoutingDecision route_to(const IPv4Address& target, const IPv4Address& source, c if (target_addr == 0xffffffff && matches(adapter)) return { adapter, { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff } }; + if (adapter == LoopbackAdapter::the()) + return { adapter, adapter->mac_address() }; + if ((target_addr & IPv4Address { 240, 0, 0, 0 }.to_u32()) == IPv4Address { 224, 0, 0, 0 }.to_u32()) return { adapter, multicast_ethernet_address(target) }; |