diff options
author | brapru <brapru@pm.me> | 2022-03-12 13:56:23 -0500 |
---|---|---|
committer | Brian Gianforcaro <b.gianfo@gmail.com> | 2022-04-28 08:41:11 -0700 |
commit | 0718b20df05c730ea681db317a853cc525689617 (patch) | |
tree | d47aa0269a110fb0289aaa3038a730d3f67043a7 /Kernel | |
parent | 03d38e3ab81f9fedcf87fe5f35c30514c7fe36f3 (diff) | |
download | serenity-0718b20df05c730ea681db317a853cc525689617.zip |
Kernel: Generalize the UpdateArp table to UpdateTable
We can use the same enum cases to apply to updates on different
networking tables within the Kernel (i.e. a routing table)
Diffstat (limited to 'Kernel')
-rw-r--r-- | Kernel/Net/IPv4Socket.cpp | 4 | ||||
-rw-r--r-- | Kernel/Net/NetworkTask.cpp | 4 | ||||
-rw-r--r-- | Kernel/Net/Routing.cpp | 6 | ||||
-rw-r--r-- | Kernel/Net/Routing.h | 4 |
4 files changed, 9 insertions, 9 deletions
diff --git a/Kernel/Net/IPv4Socket.cpp b/Kernel/Net/IPv4Socket.cpp index 842e9a8f92..184b3cd0b8 100644 --- a/Kernel/Net/IPv4Socket.cpp +++ b/Kernel/Net/IPv4Socket.cpp @@ -653,7 +653,7 @@ ErrorOr<void> IPv4Socket::ioctl(OpenFileDescription&, unsigned request, Userspac return EPERM; if (arp_req.arp_pa.sa_family != AF_INET) return EAFNOSUPPORT; - update_arp_table(IPv4Address(((sockaddr_in&)arp_req.arp_pa).sin_addr.s_addr), *(MACAddress*)&arp_req.arp_ha.sa_data[0], UpdateArp::Set); + update_arp_table(IPv4Address(((sockaddr_in&)arp_req.arp_pa).sin_addr.s_addr), *(MACAddress*)&arp_req.arp_ha.sa_data[0], UpdateTable::Set); return {}; case SIOCDARP: @@ -661,7 +661,7 @@ ErrorOr<void> IPv4Socket::ioctl(OpenFileDescription&, unsigned request, Userspac return EPERM; if (arp_req.arp_pa.sa_family != AF_INET) return EAFNOSUPPORT; - update_arp_table(IPv4Address(((sockaddr_in&)arp_req.arp_pa).sin_addr.s_addr), *(MACAddress*)&arp_req.arp_ha.sa_data[0], UpdateArp::Delete); + update_arp_table(IPv4Address(((sockaddr_in&)arp_req.arp_pa).sin_addr.s_addr), *(MACAddress*)&arp_req.arp_ha.sa_data[0], UpdateTable::Delete); return {}; } diff --git a/Kernel/Net/NetworkTask.cpp b/Kernel/Net/NetworkTask.cpp index 53df9665b5..816d4e5f84 100644 --- a/Kernel/Net/NetworkTask.cpp +++ b/Kernel/Net/NetworkTask.cpp @@ -158,7 +158,7 @@ void handle_arp(EthernetFrameHeader const& eth, size_t frame_size) 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. - update_arp_table(packet.sender_protocol_address(), packet.sender_hardware_address(), UpdateArp::Set); + update_arp_table(packet.sender_protocol_address(), packet.sender_hardware_address(), UpdateTable::Set); } if (packet.operation() == ARPOperation::Request) { @@ -206,7 +206,7 @@ void handle_ipv4(EthernetFrameHeader const& eth, size_t frame_size, Time const& 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(), UpdateArp::Set); + update_arp_table(packet.source(), eth.source(), UpdateTable::Set); } }); diff --git a/Kernel/Net/Routing.cpp b/Kernel/Net/Routing.cpp index e8a0aaed86..c8b197b994 100644 --- a/Kernel/Net/Routing.cpp +++ b/Kernel/Net/Routing.cpp @@ -110,12 +110,12 @@ SpinlockProtected<HashMap<IPv4Address, MACAddress>>& arp_table() return *s_arp_table; } -void update_arp_table(IPv4Address const& ip_addr, MACAddress const& addr, UpdateArp update) +void update_arp_table(IPv4Address const& ip_addr, MACAddress const& addr, UpdateTable update) { arp_table().with([&](auto& table) { - if (update == UpdateArp::Set) + if (update == UpdateTable::Set) table.set(ip_addr, addr); - if (update == UpdateArp::Delete) + if (update == UpdateTable::Delete) table.remove(ip_addr); }); s_arp_table_blocker_set->unblock_blockers_waiting_for_ipv4_address(ip_addr, addr); diff --git a/Kernel/Net/Routing.h b/Kernel/Net/Routing.h index bbd0dae123..b08eaba1ef 100644 --- a/Kernel/Net/Routing.h +++ b/Kernel/Net/Routing.h @@ -19,12 +19,12 @@ struct RoutingDecision { bool is_zero() const; }; -enum class UpdateArp { +enum class UpdateTable { Set, Delete, }; -void update_arp_table(IPv4Address const&, MACAddress const&, UpdateArp update); +void update_arp_table(IPv4Address const&, MACAddress const&, UpdateTable update); enum class AllowUsingGateway { Yes, |