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.
This commit is contained in:
Conrad Pankoff 2019-09-08 17:26:21 +10:00 committed by Andreas Kling
parent b45cfae7f4
commit b8e3c7ef01
Notes: sideshowbarker 2024-07-19 12:12:08 +09:00

View File

@ -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)