diff options
author | Andreas Kling <kling@serenityos.org> | 2021-04-30 12:26:25 +0200 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2021-04-30 15:27:41 +0200 |
commit | 71a10eb8e79d2fad2359c39ce314b9b92a5221bf (patch) | |
tree | 562bdf56dda06d98bb1b072226c8931910c2fbf7 /Kernel/Net/TCPSocket.cpp | |
parent | 8f8fbf3487a9e28902ab9525c7c14195010a3f99 (diff) | |
download | serenity-71a10eb8e79d2fad2359c39ce314b9b92a5221bf.zip |
Kernel/IPv4: Propagate errors from local port allocation
Remove hacks and assumptions and make the EADDRINUSE propagate all
the way from the point of failure to the syscall layer.
Diffstat (limited to 'Kernel/Net/TCPSocket.cpp')
-rw-r--r-- | Kernel/Net/TCPSocket.cpp | 7 |
1 files changed, 4 insertions, 3 deletions
diff --git a/Kernel/Net/TCPSocket.cpp b/Kernel/Net/TCPSocket.cpp index ae06bffec7..58322e3199 100644 --- a/Kernel/Net/TCPSocket.cpp +++ b/Kernel/Net/TCPSocket.cpp @@ -369,7 +369,8 @@ KResult TCPSocket::protocol_connect(FileDescription& description, ShouldBlock sh if (!has_specific_local_address()) set_local_address(routing_decision.adapter->ipv4_address()); - allocate_local_port_if_needed(); + if (auto result = allocate_local_port_if_needed(); result.is_error()) + return result.error(); m_sequence_number = get_good_random<u32>(); m_ack_number = 0; @@ -401,7 +402,7 @@ KResult TCPSocket::protocol_connect(FileDescription& description, ShouldBlock sh return EINPROGRESS; } -int TCPSocket::protocol_allocate_local_port() +KResultOr<u16> TCPSocket::protocol_allocate_local_port() { static const u16 first_ephemeral_port = 32768; static const u16 last_ephemeral_port = 60999; @@ -424,7 +425,7 @@ int TCPSocket::protocol_allocate_local_port() if (port == first_scan_port) break; } - return -EADDRINUSE; + return EADDRINUSE; } bool TCPSocket::protocol_is_disconnected() const |