diff options
author | brapru <brapru@pm.me> | 2022-05-09 07:23:02 -0400 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2022-05-26 16:33:10 +0200 |
commit | 7a4e41f8f8ab49507f549412ffc8d4042e511918 (patch) | |
tree | 326bff87493508cb5685ecf6214e55477074fed5 /Kernel/Net | |
parent | 210c3f24cda5894103a46dba44eb591be737ec14 (diff) | |
download | serenity-7a4e41f8f8ab49507f549412ffc8d4042e511918.zip |
Kernel: Add support for route flags
Previously the routing table did not store the route flags. This
adds basic support and exposes them in the /proc directory so that a
userspace caller can query the route and identify the type of each
route.
Diffstat (limited to 'Kernel/Net')
-rw-r--r-- | Kernel/Net/IPv4Socket.cpp | 6 | ||||
-rw-r--r-- | Kernel/Net/Routing.cpp | 4 | ||||
-rw-r--r-- | Kernel/Net/Routing.h | 8 |
3 files changed, 10 insertions, 8 deletions
diff --git a/Kernel/Net/IPv4Socket.cpp b/Kernel/Net/IPv4Socket.cpp index 76f851899b..e9305a5adb 100644 --- a/Kernel/Net/IPv4Socket.cpp +++ b/Kernel/Net/IPv4Socket.cpp @@ -629,14 +629,14 @@ ErrorOr<void> IPv4Socket::ioctl(OpenFileDescription&, unsigned request, Userspac return EPERM; if (route.rt_gateway.sa_family != AF_INET) return EAFNOSUPPORT; - if ((route.rt_flags & (RTF_UP | RTF_GATEWAY)) != (RTF_UP | RTF_GATEWAY)) + if (!(route.rt_flags & RTF_UP)) return EINVAL; // FIXME: Find the correct value to return auto destination = IPv4Address(((sockaddr_in&)route.rt_dst).sin_addr.s_addr); auto gateway = IPv4Address(((sockaddr_in&)route.rt_gateway).sin_addr.s_addr); auto genmask = IPv4Address(((sockaddr_in&)route.rt_genmask).sin_addr.s_addr); - return update_routing_table(destination, gateway, genmask, adapter, UpdateTable::Set); + return update_routing_table(destination, gateway, genmask, route.rt_flags, adapter, UpdateTable::Set); } case SIOCDELRT: if (!Process::current().is_superuser()) @@ -648,7 +648,7 @@ ErrorOr<void> IPv4Socket::ioctl(OpenFileDescription&, unsigned request, Userspac auto gateway = IPv4Address(((sockaddr_in&)route.rt_gateway).sin_addr.s_addr); auto genmask = IPv4Address(((sockaddr_in&)route.rt_genmask).sin_addr.s_addr); - return update_routing_table(destination, gateway, genmask, adapter, UpdateTable::Delete); + return update_routing_table(destination, gateway, genmask, route.rt_flags, adapter, UpdateTable::Delete); } return EINVAL; diff --git a/Kernel/Net/Routing.cpp b/Kernel/Net/Routing.cpp index 8c2396b3ad..a96a201a5c 100644 --- a/Kernel/Net/Routing.cpp +++ b/Kernel/Net/Routing.cpp @@ -135,9 +135,9 @@ SpinlockProtected<Route::RouteList>& routing_table() return *s_routing_table; } -ErrorOr<void> update_routing_table(IPv4Address const& destination, IPv4Address const& gateway, IPv4Address const& netmask, RefPtr<NetworkAdapter> adapter, UpdateTable update) +ErrorOr<void> update_routing_table(IPv4Address const& destination, IPv4Address const& gateway, IPv4Address const& netmask, u16 flags, RefPtr<NetworkAdapter> adapter, UpdateTable update) { - auto route_entry = adopt_ref_if_nonnull(new (nothrow) Route { destination, gateway, netmask, adapter.release_nonnull() }); + auto route_entry = adopt_ref_if_nonnull(new (nothrow) Route { destination, gateway, netmask, flags, adapter.release_nonnull() }); if (!route_entry) return ENOMEM; diff --git a/Kernel/Net/Routing.h b/Kernel/Net/Routing.h index b0db0baf2e..3d68a0f34c 100644 --- a/Kernel/Net/Routing.h +++ b/Kernel/Net/Routing.h @@ -15,22 +15,24 @@ namespace Kernel { struct Route : public RefCounted<Route> { - Route(IPv4Address const& destination, IPv4Address const& gateway, IPv4Address const& netmask, NonnullRefPtr<NetworkAdapter> adapter) + Route(IPv4Address const& destination, IPv4Address const& gateway, IPv4Address const& netmask, u16 flags, NonnullRefPtr<NetworkAdapter> adapter) : destination(destination) , gateway(gateway) , netmask(netmask) + , flags(flags) , adapter(adapter) { } bool operator==(Route const& other) const { - return destination == other.destination && gateway == other.gateway && netmask == other.netmask && adapter.ptr() == other.adapter.ptr(); + return destination == other.destination && gateway == other.gateway && netmask == other.netmask && flags == other.flags && adapter.ptr() == other.adapter.ptr(); } const IPv4Address destination; const IPv4Address gateway; const IPv4Address netmask; + const u16 flags; NonnullRefPtr<NetworkAdapter> adapter; IntrusiveListNode<Route, RefPtr<Route>> route_list_node {}; @@ -50,7 +52,7 @@ enum class UpdateTable { }; void update_arp_table(IPv4Address const&, MACAddress const&, UpdateTable update); -ErrorOr<void> update_routing_table(IPv4Address const& destination, IPv4Address const& gateway, IPv4Address const& netmask, RefPtr<NetworkAdapter> const adapter, UpdateTable update); +ErrorOr<void> update_routing_table(IPv4Address const& destination, IPv4Address const& gateway, IPv4Address const& netmask, u16 flags, RefPtr<NetworkAdapter> const adapter, UpdateTable update); enum class AllowUsingGateway { Yes, |