Kernel: Move on_close_impl from network socket to udp socket
This commit is contained in:
@@ -4,6 +4,7 @@
|
||||
#include <kernel/Networking/IPv4Layer.h>
|
||||
#include <kernel/Networking/NetworkManager.h>
|
||||
#include <kernel/Networking/UDPSocket.h>
|
||||
#include <kernel/Random.h>
|
||||
|
||||
#include <netinet/in.h>
|
||||
|
||||
@@ -89,19 +90,18 @@ namespace Kernel
|
||||
LockGuard _(m_lock);
|
||||
|
||||
uint16_t port = NetworkSocket::PORT_NONE;
|
||||
for (uint32_t temp = 0xC000; temp < 0xFFFF; temp++)
|
||||
{
|
||||
if (!m_bound_sockets.contains(temp))
|
||||
{
|
||||
for (uint32_t i = 0; i < 100 && port == NetworkSocket::PORT_NONE; i++)
|
||||
if (uint32_t temp = 0xC000 | (Random::get_u32() & 0x3FFF); !m_bound_sockets.contains(temp))
|
||||
port = temp;
|
||||
for (uint32_t temp = 0xC000; temp < 0xFFFF && port == NetworkSocket::PORT_NONE; temp++)
|
||||
if (!m_bound_sockets.contains(temp))
|
||||
port = temp;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (port == NetworkSocket::PORT_NONE)
|
||||
{
|
||||
dwarnln("No ports available");
|
||||
return BAN::Error::from_errno(EAGAIN);
|
||||
}
|
||||
dprintln_if(DEBUG_IPV4, "using port {}", port);
|
||||
|
||||
struct sockaddr_in target;
|
||||
target.sin_family = AF_INET;
|
||||
|
||||
@@ -15,16 +15,6 @@ namespace Kernel
|
||||
{
|
||||
}
|
||||
|
||||
void NetworkSocket::on_close_impl()
|
||||
{
|
||||
if (is_bound())
|
||||
{
|
||||
m_network_layer.unbind_socket(this, m_port);
|
||||
m_interface = nullptr;
|
||||
m_port = PORT_NONE;
|
||||
}
|
||||
}
|
||||
|
||||
void NetworkSocket::bind_interface_and_port(NetworkInterface* interface, uint16_t port)
|
||||
{
|
||||
ASSERT(!m_interface);
|
||||
|
||||
@@ -24,6 +24,14 @@ namespace Kernel
|
||||
: NetworkSocket(network_layer, ino, inode_info)
|
||||
{ }
|
||||
|
||||
void UDPSocket::on_close_impl()
|
||||
{
|
||||
if (is_bound())
|
||||
m_network_layer.unbind_socket(this, m_port);
|
||||
m_port = PORT_NONE;
|
||||
m_interface = nullptr;
|
||||
}
|
||||
|
||||
void UDPSocket::add_protocol_header(BAN::ByteSpan packet, uint16_t dst_port, PseudoHeader)
|
||||
{
|
||||
auto& header = packet.as<UDPHeader>();
|
||||
|
||||
Reference in New Issue
Block a user