mirror of
https://github.com/SerenityOS/serenity
synced 2024-09-06 17:06:31 +00:00
IPv4: Use the UDP-to-socket map to handle incoming UDP packets.
This commit is contained in:
parent
209a16bb7f
commit
3ad9561b80
|
@ -50,8 +50,14 @@ IPv4Socket::IPv4Socket(int type, int protocol)
|
|||
|
||||
IPv4Socket::~IPv4Socket()
|
||||
{
|
||||
LOCKER(all_sockets().lock());
|
||||
all_sockets().resource().remove(this);
|
||||
{
|
||||
LOCKER(all_sockets().lock());
|
||||
all_sockets().resource().remove(this);
|
||||
}
|
||||
if (type() == SOCK_DGRAM) {
|
||||
LOCKER(sockets_by_udp_port().lock());
|
||||
sockets_by_udp_port().resource().remove(m_source_port);
|
||||
}
|
||||
}
|
||||
|
||||
bool IPv4Socket::get_address(sockaddr* address, socklen_t* address_size)
|
||||
|
@ -128,6 +134,7 @@ void IPv4Socket::allocate_source_port_if_needed()
|
|||
auto it = sockets_by_udp_port().resource().find(port);
|
||||
if (it == sockets_by_udp_port().resource().end()) {
|
||||
m_source_port = port;
|
||||
sockets_by_udp_port().resource().set(port, this);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -229,14 +229,18 @@ void handle_udp(const EthernetFrameHeader& eth, int frame_size)
|
|||
);
|
||||
#endif
|
||||
|
||||
LOCKER(IPv4Socket::all_sockets().lock());
|
||||
for (RetainPtr<IPv4Socket> socket : IPv4Socket::all_sockets().resource()) {
|
||||
LOCKER(socket->lock());
|
||||
if (socket->type() != SOCK_DGRAM)
|
||||
continue;
|
||||
if (socket->source_port() != udp_packet.destination_port())
|
||||
continue;
|
||||
socket->did_receive(ByteBuffer::copy((const byte*)&ipv4_packet, sizeof(IPv4Packet) + ipv4_packet.payload_size()));
|
||||
return;
|
||||
RetainPtr<IPv4Socket> socket;
|
||||
{
|
||||
LOCKER(IPv4Socket::sockets_by_udp_port().lock());
|
||||
auto it = IPv4Socket::sockets_by_udp_port().resource().find(udp_packet.destination_port());
|
||||
if (it == IPv4Socket::sockets_by_udp_port().resource().end())
|
||||
return;
|
||||
ASSERT((*it).value);
|
||||
socket = *(*it).value;
|
||||
}
|
||||
|
||||
LOCKER(socket->lock());
|
||||
ASSERT(socket->type() == SOCK_DGRAM);
|
||||
ASSERT(socket->source_port() == udp_packet.destination_port());
|
||||
socket->did_receive(ByteBuffer::copy((const byte*)&ipv4_packet, sizeof(IPv4Packet) + ipv4_packet.payload_size()));
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue