1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-16 20:25:07 +00:00

Kernel: Implement IP multicast support

An IP socket can now join a multicast group by using the
IP_ADD_MEMBERSHIP sockopt, which will cause it to start receiving
packets sent to the multicast address, even though this address does
not belong to this host.
This commit is contained in:
Sergey Bugaev 2021-05-04 14:42:47 +03:00 committed by Andreas Kling
parent b9c367e13b
commit 78459b92d5
5 changed files with 77 additions and 7 deletions

View file

@ -258,12 +258,6 @@ void handle_udp(const IPv4Packet& ipv4_packet, const Time& packet_timestamp)
return;
}
auto adapter = NetworkAdapter::from_ipv4_address(ipv4_packet.destination());
if (!adapter && ipv4_packet.destination() != IPv4Address(255, 255, 255, 255)) {
dbgln_if(UDP_DEBUG, "handle_udp: this packet is not for me, it's for {}", ipv4_packet.destination());
return;
}
auto& udp_packet = *static_cast<const UDPPacket*>(ipv4_packet.payload());
dbgln_if(UDP_DEBUG, "handle_udp: source={}:{}, destination={}:{}, length={}",
ipv4_packet.source(), udp_packet.source_port(),
@ -278,7 +272,11 @@ void handle_udp(const IPv4Packet& ipv4_packet, const Time& packet_timestamp)
VERIFY(socket->type() == SOCK_DGRAM);
VERIFY(socket->local_port() == udp_packet.destination_port());
socket->did_receive(ipv4_packet.source(), udp_packet.source_port(), KBuffer::copy(&ipv4_packet, sizeof(IPv4Packet) + ipv4_packet.payload_size()), packet_timestamp);
auto& destination = ipv4_packet.destination();
if (destination == IPv4Address(255, 255, 255, 255) || NetworkAdapter::from_ipv4_address(destination) || socket->multicast_memberships().contains_slow(destination))
socket->did_receive(ipv4_packet.source(), udp_packet.source_port(), KBuffer::copy(&ipv4_packet, sizeof(IPv4Packet) + ipv4_packet.payload_size()), packet_timestamp);
}
void handle_tcp(const IPv4Packet& ipv4_packet, const Time& packet_timestamp)