mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-11-22 15:40:19 +00:00
Kernel/Net: Support removing route entries with unknown gateway
If you specify gateway as 0.0.0.0, the SIOCDELRT ioctl will remove all route entries that match all the other arguments.
This commit is contained in:
parent
36676a1604
commit
bea1668159
Notes:
sideshowbarker
2024-07-17 09:34:52 +09:00
Author: https://github.com/sppmacd Commit: https://github.com/SerenityOS/serenity/commit/bea1668159 Pull-request: https://github.com/SerenityOS/serenity/pull/13259 Reviewed-by: https://github.com/AtkinsSJ ✅ Reviewed-by: https://github.com/IdanHo
2 changed files with 11 additions and 2 deletions
|
@ -137,6 +137,8 @@ SpinlockProtected<Route::RouteList>& routing_table()
|
|||
|
||||
ErrorOr<void> update_routing_table(IPv4Address const& destination, IPv4Address const& gateway, IPv4Address const& netmask, u16 flags, RefPtr<NetworkAdapter> adapter, UpdateTable update)
|
||||
{
|
||||
dbgln_if(ROUTING_DEBUG, "update_routing_table {} {} {} {} {} {}", destination, gateway, netmask, flags, adapter, update == UpdateTable::Set ? "Set" : "Delete");
|
||||
|
||||
auto route_entry = adopt_ref_if_nonnull(new (nothrow) Route { destination, gateway, netmask, flags, adapter.release_nonnull() });
|
||||
if (!route_entry)
|
||||
return ENOMEM;
|
||||
|
@ -151,7 +153,9 @@ ErrorOr<void> update_routing_table(IPv4Address const& destination, IPv4Address c
|
|||
}
|
||||
if (update == UpdateTable::Delete) {
|
||||
for (auto& route : table) {
|
||||
if (route == *route_entry) {
|
||||
dbgln("candidate: {} {} {} {} {}", route.destination, route.gateway, route.netmask, route.flags, route.adapter);
|
||||
if (route.matches(*route_entry)) {
|
||||
// FIXME: Remove all entries, not only the first one.
|
||||
table.remove(route);
|
||||
return {};
|
||||
}
|
||||
|
|
|
@ -26,7 +26,12 @@ struct Route : public RefCounted<Route> {
|
|||
|
||||
bool operator==(Route const& other) const
|
||||
{
|
||||
return destination == other.destination && gateway == other.gateway && netmask == other.netmask && flags == other.flags && adapter.ptr() == other.adapter.ptr();
|
||||
return destination == other.destination && netmask == other.netmask && flags == other.flags && adapter.ptr() == other.adapter.ptr();
|
||||
}
|
||||
|
||||
bool matches(Route const& other) const
|
||||
{
|
||||
return destination == other.destination && (gateway == other.gateway || other.gateway.is_zero()) && netmask == other.netmask && flags == other.flags && adapter.ptr() == other.adapter.ptr();
|
||||
}
|
||||
|
||||
const IPv4Address destination;
|
||||
|
|
Loading…
Reference in a new issue