/* * Copyright (c) 2018-2020, Andreas Kling * * SPDX-License-Identifier: BSD-2-Clause */ #pragma once #include #include #include #include #include namespace Kernel { struct Route : public RefCounted { Route(IPv4Address const& destination, IPv4Address const& gateway, IPv4Address const& netmask, NonnullRefPtr adapter) : destination(destination) , gateway(gateway) , netmask(netmask) , adapter(adapter) { } bool operator==(Route const& other) const { return destination == other.destination && gateway == other.gateway && netmask == other.netmask && adapter.ptr() == other.adapter.ptr(); } const IPv4Address destination; const IPv4Address gateway; const IPv4Address netmask; NonnullRefPtr adapter; IntrusiveListNode> route_list_node {}; using RouteList = IntrusiveList<&Route::route_list_node>; }; struct RoutingDecision { RefPtr adapter; MACAddress next_hop; bool is_zero() const; }; enum class UpdateTable { Set, Delete, }; void update_arp_table(IPv4Address const&, MACAddress const&, UpdateTable update); ErrorOr update_routing_table(IPv4Address const& destination, IPv4Address const& gateway, IPv4Address const& netmask, RefPtr const adapter, UpdateTable update); enum class AllowUsingGateway { Yes, No, }; RoutingDecision route_to(IPv4Address const& target, IPv4Address const& source, RefPtr const through = nullptr, AllowUsingGateway = AllowUsingGateway::Yes); SpinlockProtected>& arp_table(); SpinlockProtected& routing_table(); }