mirror of
https://github.com/espressif/openthread.git
synced 2026-10-04 23:07:37 +00:00
`MulticastRoutingManager` relies on the kernel's IPv6 multicast routing (MRT6) and does not build anywhere else. This commit adds an implementation for platforms without it (macOS, the BSDs) that forwards in userspace, behind the same public interface. - A BPF tap on the Thread interface delivers what the Thread stack hands to the host; one on the infrastructure interface delivers that link's multicast. A filter program on each keeps everything but multicast of admin-local scope or larger in the kernel. - Thread to backbone: every packet that passes the policy (routable, non-mesh-local source, hop limit above 1) is sent out in an Ethernet frame with the hop limit decremented, as the outbound forwarding cache entries do with MRT6. - Backbone to Thread: only groups in the Multicast Listener table (`HasMulticastListener()`), as the inbound forwarding cache entries do with MRT6, and only packets within the Thread MTU. The packet is written to the tunnel interface. - A packet is forwarded once: a duplicate cache covers both directions, which also keeps the forwarder from picking up its own emissions. Per-group and overall rate limits apply in each direction, tighter into the mesh, where every packet is flooded. The lifecycle (`SetUp`/`TearDown`, enabling on Primary with retries, the MLD join on the infrastructure interface for registered groups) is shared by both implementations and stays in `multicast_routing.cpp`; the MRT6 code moves under `#ifdef __linux__` unchanged. The non-Linux implementation is in `multicast_routing_bpf.cpp`, with the packet tap in `bpf_tap.*` and the per-packet checks in `multicast_forwarding.*`. The per-packet checks, duplicate cache and rate limiter have no platform dependency and are unit-tested (`ot-posix-gtest`); the BPF record parser is tested where BPF exists (`ot-posix-bpf-gtest`). `processTransmit()` in `netif.cpp` read the tunnel's 4-byte address family header into the space meant for the datagram, so a 1277..1280 byte packet from the host was truncated on BSD platforms; the buffer now has room for the header.