1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-31 10:28:10 +00:00

Kernel: Properly support the SO_BROADCAST socket option

POSIX requires that broadcast sends will only be allowed if the
SO_BROADCAST socket option was set on the socket.
Also, broadcast sends to protocols that do not support broadcast (like
TCP), should always fail.
This commit is contained in:
Idan Horowitz 2023-12-24 19:01:09 +02:00 committed by Andreas Kling
parent 8b2beb2ebe
commit 545f4b6cc1
7 changed files with 36 additions and 6 deletions

View file

@ -211,9 +211,10 @@ ErrorOr<size_t> IPv4Socket::sendto(OpenFileDescription&, UserOrKernelBuffer cons
if (!is_connected() && m_peer_address.is_zero())
return set_so_error(EPIPE);
auto allow_broadcast = m_broadcast_allowed ? AllowBroadcast::Yes : AllowBroadcast::No;
auto allow_using_gateway = ((flags & MSG_DONTROUTE) || m_routing_disabled) ? AllowUsingGateway::No : AllowUsingGateway::Yes;
auto adapter = bound_interface().with([](auto& bound_device) -> RefPtr<NetworkAdapter> { return bound_device; });
auto routing_decision = route_to(m_peer_address, m_local_address, adapter, allow_using_gateway);
auto routing_decision = route_to(m_peer_address, m_local_address, adapter, allow_broadcast, allow_using_gateway);
if (routing_decision.is_zero())
return set_so_error(EHOSTUNREACH);