mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 15:37:46 +00:00
Kernel: Convert Routing to east-const style
This commit is contained in:
parent
ad5bd209ba
commit
bad23e3f8c
2 changed files with 13 additions and 13 deletions
|
@ -28,7 +28,7 @@ public:
|
||||||
|
|
||||||
virtual void will_unblock_immediately_without_blocking(UnblockImmediatelyReason) override;
|
virtual void will_unblock_immediately_without_blocking(UnblockImmediatelyReason) override;
|
||||||
|
|
||||||
bool unblock(bool from_add_blocker, const IPv4Address& ip_addr, const MACAddress& addr)
|
bool unblock(bool from_add_blocker, IPv4Address const& ip_addr, MACAddress const& addr)
|
||||||
{
|
{
|
||||||
if (m_ip_addr != ip_addr)
|
if (m_ip_addr != ip_addr)
|
||||||
return false;
|
return false;
|
||||||
|
@ -46,17 +46,17 @@ public:
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
const IPv4Address& ip_addr() const { return m_ip_addr; }
|
IPv4Address const& ip_addr() const { return m_ip_addr; }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
const IPv4Address m_ip_addr;
|
IPv4Address const m_ip_addr;
|
||||||
Optional<MACAddress>& m_addr;
|
Optional<MACAddress>& m_addr;
|
||||||
bool m_did_unblock { false };
|
bool m_did_unblock { false };
|
||||||
};
|
};
|
||||||
|
|
||||||
class ARPTableBlockerSet final : public Thread::BlockerSet {
|
class ARPTableBlockerSet final : public Thread::BlockerSet {
|
||||||
public:
|
public:
|
||||||
void unblock(const IPv4Address& ip_addr, const MACAddress& addr)
|
void unblock(IPv4Address const& ip_addr, MACAddress const& addr)
|
||||||
{
|
{
|
||||||
BlockerSet::unblock_all_blockers_whose_conditions_are_met([&](auto& b, void*, bool&) {
|
BlockerSet::unblock_all_blockers_whose_conditions_are_met([&](auto& b, void*, bool&) {
|
||||||
VERIFY(b.blocker_type() == Thread::Blocker::Type::Routing);
|
VERIFY(b.blocker_type() == Thread::Blocker::Type::Routing);
|
||||||
|
@ -70,7 +70,7 @@ protected:
|
||||||
{
|
{
|
||||||
VERIFY(b.blocker_type() == Thread::Blocker::Type::Routing);
|
VERIFY(b.blocker_type() == Thread::Blocker::Type::Routing);
|
||||||
auto& blocker = static_cast<ARPTableBlocker&>(b);
|
auto& blocker = static_cast<ARPTableBlocker&>(b);
|
||||||
auto val = arp_table().with_shared([&](const auto& table) -> auto {
|
auto val = arp_table().with_shared([&](auto const& table) -> auto {
|
||||||
return table.get(blocker.ip_addr());
|
return table.get(blocker.ip_addr());
|
||||||
});
|
});
|
||||||
if (!val.has_value())
|
if (!val.has_value())
|
||||||
|
@ -94,7 +94,7 @@ bool ARPTableBlocker::setup_blocker()
|
||||||
|
|
||||||
void ARPTableBlocker::will_unblock_immediately_without_blocking(UnblockImmediatelyReason)
|
void ARPTableBlocker::will_unblock_immediately_without_blocking(UnblockImmediatelyReason)
|
||||||
{
|
{
|
||||||
auto addr = arp_table().with_shared([&](const auto& table) -> auto {
|
auto addr = arp_table().with_shared([&](auto const& table) -> auto {
|
||||||
return table.get(ip_addr());
|
return table.get(ip_addr());
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -110,7 +110,7 @@ MutexProtected<HashMap<IPv4Address, MACAddress>>& arp_table()
|
||||||
return *s_arp_table;
|
return *s_arp_table;
|
||||||
}
|
}
|
||||||
|
|
||||||
void update_arp_table(const IPv4Address& ip_addr, const MACAddress& addr, UpdateArp update)
|
void update_arp_table(IPv4Address const& ip_addr, MACAddress const& addr, UpdateArp update)
|
||||||
{
|
{
|
||||||
arp_table().with_exclusive([&](auto& table) {
|
arp_table().with_exclusive([&](auto& table) {
|
||||||
if (update == UpdateArp::Set)
|
if (update == UpdateArp::Set)
|
||||||
|
@ -121,7 +121,7 @@ void update_arp_table(const IPv4Address& ip_addr, const MACAddress& addr, Update
|
||||||
s_arp_table_blocker_set->unblock(ip_addr, addr);
|
s_arp_table_blocker_set->unblock(ip_addr, addr);
|
||||||
|
|
||||||
if constexpr (ARP_DEBUG) {
|
if constexpr (ARP_DEBUG) {
|
||||||
arp_table().with_shared([&](const auto& table) {
|
arp_table().with_shared([&](auto const& table) {
|
||||||
dmesgln("ARP table ({} entries):", table.size());
|
dmesgln("ARP table ({} entries):", table.size());
|
||||||
for (auto& it : table)
|
for (auto& it : table)
|
||||||
dmesgln("{} :: {}", it.value.to_string(), it.key.to_string());
|
dmesgln("{} :: {}", it.value.to_string(), it.key.to_string());
|
||||||
|
@ -139,7 +139,7 @@ static MACAddress multicast_ethernet_address(IPv4Address const& address)
|
||||||
return MACAddress { 0x01, 0x00, 0x5e, (u8)(address[1] & 0x7f), address[2], address[3] };
|
return MACAddress { 0x01, 0x00, 0x5e, (u8)(address[1] & 0x7f), address[2], address[3] };
|
||||||
}
|
}
|
||||||
|
|
||||||
RoutingDecision route_to(const IPv4Address& target, const IPv4Address& source, const RefPtr<NetworkAdapter> through)
|
RoutingDecision route_to(IPv4Address const& target, IPv4Address const& source, RefPtr<NetworkAdapter> const through)
|
||||||
{
|
{
|
||||||
auto matches = [&](auto& adapter) {
|
auto matches = [&](auto& adapter) {
|
||||||
if (!through)
|
if (!through)
|
||||||
|
@ -147,7 +147,7 @@ RoutingDecision route_to(const IPv4Address& target, const IPv4Address& source, c
|
||||||
|
|
||||||
return through == adapter;
|
return through == adapter;
|
||||||
};
|
};
|
||||||
auto if_matches = [&](auto& adapter, const auto& mac) -> RoutingDecision {
|
auto if_matches = [&](auto& adapter, auto const& mac) -> RoutingDecision {
|
||||||
if (!matches(adapter))
|
if (!matches(adapter))
|
||||||
return { nullptr, {} };
|
return { nullptr, {} };
|
||||||
return { adapter, mac };
|
return { adapter, mac };
|
||||||
|
@ -232,7 +232,7 @@ RoutingDecision route_to(const IPv4Address& target, const IPv4Address& source, c
|
||||||
return { adapter, multicast_ethernet_address(target) };
|
return { adapter, multicast_ethernet_address(target) };
|
||||||
|
|
||||||
{
|
{
|
||||||
auto addr = arp_table().with_shared([&](const auto& table) -> auto {
|
auto addr = arp_table().with_shared([&](auto const& table) -> auto {
|
||||||
return table.get(next_hop_ip);
|
return table.get(next_hop_ip);
|
||||||
});
|
});
|
||||||
if (addr.has_value()) {
|
if (addr.has_value()) {
|
||||||
|
|
|
@ -24,8 +24,8 @@ enum class UpdateArp {
|
||||||
Delete,
|
Delete,
|
||||||
};
|
};
|
||||||
|
|
||||||
void update_arp_table(const IPv4Address&, const MACAddress&, UpdateArp update);
|
void update_arp_table(IPv4Address const&, MACAddress const&, UpdateArp update);
|
||||||
RoutingDecision route_to(const IPv4Address& target, const IPv4Address& source, const RefPtr<NetworkAdapter> through = nullptr);
|
RoutingDecision route_to(IPv4Address const& target, IPv4Address const& source, RefPtr<NetworkAdapter> const through = nullptr);
|
||||||
|
|
||||||
MutexProtected<HashMap<IPv4Address, MACAddress>>& arp_table();
|
MutexProtected<HashMap<IPv4Address, MACAddress>>& arp_table();
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue