Kernel: Ignore interfaces without an IP address when updating ARP

For the same reason we ignore interfaces without an IP address when
choosing where to send a route, we should also ignore interfaces without
IP addresses when updating the ARP table on incoming packets from
local addresses.

On an interface with a null address, the mask checking would always
result in zero, which resulted in the system updating the ARP table on
almost every incoming packet from any address (private or public).

This patch fixes this behavior by only applying this check to interfaces
with valid addresses and now the ARP table won't get constantly
hammered.

Closes #13713
This commit is contained in:
brapru 2022-04-17 12:02:21 -04:00 committed by Linus Groh
parent a3a6ee9865
commit 1dd22582da
Notes: sideshowbarker 2024-07-17 10:33:28 +09:00

View file

@ -201,12 +201,13 @@ void handle_ipv4(EthernetFrameHeader const& eth, size_t frame_size, Time const&
dbgln_if(IPV4_DEBUG, "handle_ipv4: source={}, destination={}", packet.source(), packet.destination());
NetworkingManagement::the().for_each([&](auto& adapter) {
if (adapter.link_up()) {
auto my_net = adapter.ipv4_address().to_u32() & adapter.ipv4_netmask().to_u32();
auto their_net = packet.source().to_u32() & adapter.ipv4_netmask().to_u32();
if (my_net == their_net)
update_arp_table(packet.source(), eth.source(), UpdateTable::Set);
}
if (adapter.ipv4_address().is_zero() || !adapter.link_up())
return;
auto my_net = adapter.ipv4_address().to_u32() & adapter.ipv4_netmask().to_u32();
auto their_net = packet.source().to_u32() & adapter.ipv4_netmask().to_u32();
if (my_net == their_net)
update_arp_table(packet.source(), eth.source(), UpdateTable::Set);
});
switch ((IPv4Protocol)packet.protocol()) {