IPv4: Use the UDP-to-socket map to handle incoming UDP packets.

This commit is contained in:
Andreas Kling 2019-03-13 16:23:22 +01:00
parent 209a16bb7f
commit 3ad9561b80
Notes: sideshowbarker 2024-07-19 15:04:07 +09:00
2 changed files with 22 additions and 11 deletions

View file

@ -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()));
}