mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 20:27:45 +00: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
5 changed files with 12 additions and 8 deletions
|
@ -24,6 +24,7 @@ struct rtentry {
|
||||||
|
|
||||||
#define RTF_UP 0x1 /* do not delete the route */
|
#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_GATEWAY 0x2 /* the route is a gateway and not an end host */
|
||||||
|
#define RTF_HOST 0x4 /* host entry (net otherwise) */
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
|
|
|
@ -114,6 +114,7 @@ private:
|
||||||
TRY(obj.add("gateway", gateway->view()));
|
TRY(obj.add("gateway", gateway->view()));
|
||||||
auto netmask = TRY(it.netmask.to_string());
|
auto netmask = TRY(it.netmask.to_string());
|
||||||
TRY(obj.add("genmask", netmask->view()));
|
TRY(obj.add("genmask", netmask->view()));
|
||||||
|
TRY(obj.add("flags", it.flags));
|
||||||
TRY(obj.add("interface", it.adapter->name()));
|
TRY(obj.add("interface", it.adapter->name()));
|
||||||
TRY(obj.finish());
|
TRY(obj.finish());
|
||||||
}
|
}
|
||||||
|
|
|
@ -629,14 +629,14 @@ ErrorOr<void> IPv4Socket::ioctl(OpenFileDescription&, unsigned request, Userspac
|
||||||
return EPERM;
|
return EPERM;
|
||||||
if (route.rt_gateway.sa_family != AF_INET)
|
if (route.rt_gateway.sa_family != AF_INET)
|
||||||
return EAFNOSUPPORT;
|
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
|
return EINVAL; // FIXME: Find the correct value to return
|
||||||
|
|
||||||
auto destination = IPv4Address(((sockaddr_in&)route.rt_dst).sin_addr.s_addr);
|
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 gateway = IPv4Address(((sockaddr_in&)route.rt_gateway).sin_addr.s_addr);
|
||||||
auto genmask = IPv4Address(((sockaddr_in&)route.rt_genmask).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:
|
case SIOCDELRT:
|
||||||
if (!Process::current().is_superuser())
|
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 gateway = IPv4Address(((sockaddr_in&)route.rt_gateway).sin_addr.s_addr);
|
||||||
auto genmask = IPv4Address(((sockaddr_in&)route.rt_genmask).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;
|
return EINVAL;
|
||||||
|
|
|
@ -135,9 +135,9 @@ SpinlockProtected<Route::RouteList>& routing_table()
|
||||||
return *s_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)
|
if (!route_entry)
|
||||||
return ENOMEM;
|
return ENOMEM;
|
||||||
|
|
||||||
|
|
|
@ -15,22 +15,24 @@
|
||||||
namespace Kernel {
|
namespace Kernel {
|
||||||
|
|
||||||
struct Route : public RefCounted<Route> {
|
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)
|
: destination(destination)
|
||||||
, gateway(gateway)
|
, gateway(gateway)
|
||||||
, netmask(netmask)
|
, netmask(netmask)
|
||||||
|
, flags(flags)
|
||||||
, adapter(adapter)
|
, adapter(adapter)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
bool operator==(Route const& other) const
|
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 destination;
|
||||||
const IPv4Address gateway;
|
const IPv4Address gateway;
|
||||||
const IPv4Address netmask;
|
const IPv4Address netmask;
|
||||||
|
const u16 flags;
|
||||||
NonnullRefPtr<NetworkAdapter> adapter;
|
NonnullRefPtr<NetworkAdapter> adapter;
|
||||||
|
|
||||||
IntrusiveListNode<Route, RefPtr<Route>> route_list_node {};
|
IntrusiveListNode<Route, RefPtr<Route>> route_list_node {};
|
||||||
|
@ -50,7 +52,7 @@ enum class UpdateTable {
|
||||||
};
|
};
|
||||||
|
|
||||||
void update_arp_table(IPv4Address const&, MACAddress const&, UpdateTable update);
|
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 {
|
enum class AllowUsingGateway {
|
||||||
Yes,
|
Yes,
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue