mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 20:07:34 +00:00
Kernel+route: Support global routing table deletion
This commit is contained in:
parent
863c14c4f4
commit
0866a0cd1e
3 changed files with 21 additions and 8 deletions
|
@ -639,8 +639,16 @@ ErrorOr<void> IPv4Socket::ioctl(OpenFileDescription&, unsigned request, Userspac
|
|||
return update_routing_table(destination, gateway, genmask, adapter, UpdateTable::Set);
|
||||
}
|
||||
case SIOCDELRT:
|
||||
// FIXME: Support gateway deletion
|
||||
return {};
|
||||
if (!Process::current().is_superuser())
|
||||
return EPERM;
|
||||
if (route.rt_gateway.sa_family != AF_INET)
|
||||
return EAFNOSUPPORT;
|
||||
|
||||
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::Delete);
|
||||
}
|
||||
|
||||
return EINVAL;
|
||||
|
|
|
@ -142,7 +142,6 @@ ErrorOr<void> update_routing_table(IPv4Address const& destination, IPv4Address c
|
|||
return ENOMEM;
|
||||
|
||||
TRY(routing_table().with([&](auto& table) -> ErrorOr<void> {
|
||||
// TODO: Add support for deleting routing entries
|
||||
if (update == UpdateTable::Set) {
|
||||
for (auto const& route : table) {
|
||||
if (route == *route_entry)
|
||||
|
@ -150,6 +149,15 @@ ErrorOr<void> update_routing_table(IPv4Address const& destination, IPv4Address c
|
|||
}
|
||||
table.append(*route_entry);
|
||||
}
|
||||
if (update == UpdateTable::Delete) {
|
||||
for (auto& route : table) {
|
||||
if (route == *route_entry) {
|
||||
table.remove(route);
|
||||
return {};
|
||||
}
|
||||
}
|
||||
return ESRCH;
|
||||
}
|
||||
return {};
|
||||
}));
|
||||
|
||||
|
|
|
@ -179,11 +179,8 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
|
|||
if (action_add)
|
||||
TRY(Core::System::ioctl(fd, SIOCADDRT, &rt));
|
||||
|
||||
// FIXME: Add support for route deletion.
|
||||
if (action_del) {
|
||||
warnln("Route deletion currently not implemented.");
|
||||
return 1;
|
||||
}
|
||||
if (action_del)
|
||||
TRY(Core::System::ioctl(fd, SIOCDELRT, &rt));
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue