From b8e3c7ef015b0a888742e1d6973756aebfdf8bc2 Mon Sep 17 00:00:00 2001 From: Conrad Pankoff Date: Sun, 8 Sep 2019 17:26:21 +1000 Subject: [PATCH] Kernel: Remember all ARP replies, even ones we didn't request This allows us to take advantage of unsolicited ARP replies, such as those that are emitted by many systems after their network interfaces are enabled, or after their DHCP client sets their IP. This also makes us a bit more vulnerable to ARP flooding, but we need some kind of eviction strategy anyway, so we can deal with that later. --- Kernel/Net/NetworkTask.cpp | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/Kernel/Net/NetworkTask.cpp b/Kernel/Net/NetworkTask.cpp index cb14243c5f..68b1751bc2 100644 --- a/Kernel/Net/NetworkTask.cpp +++ b/Kernel/Net/NetworkTask.cpp @@ -160,6 +160,19 @@ void handle_arp(const EthernetFrameHeader& eth, size_t frame_size) packet.target_protocol_address().to_string().characters()); #endif + if (!packet.sender_hardware_address().is_zero() && !packet.sender_protocol_address().is_zero()) { + // Someone has this IPv4 address. I guess we can try to remember that. + // FIXME: Protect against ARP spamming. + // FIXME: Support static ARP table entries. + LOCKER(arp_table().lock()); + arp_table().resource().set(packet.sender_protocol_address(), packet.sender_hardware_address()); + + kprintf("ARP table (%d entries):\n", arp_table().resource().size()); + for (auto& it : arp_table().resource()) { + kprintf("%s :: %s\n", it.value.to_string().characters(), it.key.to_string().characters()); + } + } + if (packet.operation() == ARPOperation::Request) { // Who has this IP address? if (auto adapter = NetworkAdapter::from_ipv4_address(packet.target_protocol_address())) { @@ -177,19 +190,6 @@ void handle_arp(const EthernetFrameHeader& eth, size_t frame_size) } return; } - - if (packet.operation() == ARPOperation::Response) { - // Someone has this IPv4 address. I guess we can try to remember that. - // FIXME: Protect against ARP spamming. - // FIXME: Support static ARP table entries. - LOCKER(arp_table().lock()); - arp_table().resource().set(packet.sender_protocol_address(), packet.sender_hardware_address()); - - kprintf("ARP table (%d entries):\n", arp_table().resource().size()); - for (auto& it : arp_table().resource()) { - kprintf("%s :: %s\n", it.value.to_string().characters(), it.key.to_string().characters()); - } - } } void handle_ipv4(const EthernetFrameHeader& eth, size_t frame_size)