1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-26 09:27:34 +00:00

Kernel+route: Support global routing table deletion

This commit is contained in:
brapru 2022-04-29 21:49:00 -04:00 committed by Andreas Kling
parent 863c14c4f4
commit 0866a0cd1e
3 changed files with 21 additions and 8 deletions

View file

@ -639,8 +639,16 @@ ErrorOr<void> IPv4Socket::ioctl(OpenFileDescription&, unsigned request, Userspac
return update_routing_table(destination, gateway, genmask, adapter, UpdateTable::Set); return update_routing_table(destination, gateway, genmask, adapter, UpdateTable::Set);
} }
case SIOCDELRT: case SIOCDELRT:
// FIXME: Support gateway deletion if (!Process::current().is_superuser())
return {}; 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; return EINVAL;

View file

@ -142,7 +142,6 @@ ErrorOr<void> update_routing_table(IPv4Address const& destination, IPv4Address c
return ENOMEM; return ENOMEM;
TRY(routing_table().with([&](auto& table) -> ErrorOr<void> { TRY(routing_table().with([&](auto& table) -> ErrorOr<void> {
// TODO: Add support for deleting routing entries
if (update == UpdateTable::Set) { if (update == UpdateTable::Set) {
for (auto const& route : table) { for (auto const& route : table) {
if (route == *route_entry) if (route == *route_entry)
@ -150,6 +149,15 @@ ErrorOr<void> update_routing_table(IPv4Address const& destination, IPv4Address c
} }
table.append(*route_entry); table.append(*route_entry);
} }
if (update == UpdateTable::Delete) {
for (auto& route : table) {
if (route == *route_entry) {
table.remove(route);
return {};
}
}
return ESRCH;
}
return {}; return {};
})); }));

View file

@ -179,11 +179,8 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
if (action_add) if (action_add)
TRY(Core::System::ioctl(fd, SIOCADDRT, &rt)); TRY(Core::System::ioctl(fd, SIOCADDRT, &rt));
// FIXME: Add support for route deletion. if (action_del)
if (action_del) { TRY(Core::System::ioctl(fd, SIOCDELRT, &rt));
warnln("Route deletion currently not implemented.");
return 1;
}
} }
return 0; return 0;