mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-11-10 02:54:54 +03:00
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.
This commit is contained in:
parent
210c3f24cd
commit
7a4e41f8f8
Notes:
sideshowbarker
2024-07-17 10:38:11 +09:00
Author: https://github.com/brapru Commit: https://github.com/SerenityOS/serenity/commit/7a4e41f8f8 Pull-request: https://github.com/SerenityOS/serenity/pull/13992
@ -24,6 +24,7 @@ struct rtentry {
|
||||
|
||||
#define RTF_UP 0x1 /* do not delete the route */
|
||||
#define RTF_GATEWAY 0x2 /* the route is a gateway and not an end host */
|
||||
#define RTF_HOST 0x4 /* host entry (net otherwise) */
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
@ -114,6 +114,7 @@ private:
|
||||
TRY(obj.add("gateway", gateway->view()));
|
||||
auto netmask = TRY(it.netmask.to_string());
|
||||
TRY(obj.add("genmask", netmask->view()));
|
||||
TRY(obj.add("flags", it.flags));
|
||||
TRY(obj.add("interface", it.adapter->name()));
|
||||
TRY(obj.finish());
|
||||
}
|
||||
|
@ -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;
|
||||
|
@ -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;
|
||||
|
||||
|
@ -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,
|
||||
|
Loading…
Reference in New Issue
Block a user