Multicast receiver software running on OpenWRT is unable to receive multicast packets

Hi, I am writing a software to run on OpenWRT to receive and process multicast packets. However, for some reason, the software is unable to receive multicast packets. I had found old forum posts with the same issue and the solution being route add -net 224.0.0.0 netmask 224.0.0.0 <some interface>. This did not work for me.
What could possibly be causing this?
I am using OpenWRT 24.10.

Edit 1:
Added a firewall rule to mark the multicast traffic at the input chain. From the nftables page on LuCI, I can see that the traffic reaches "mangle_input".

Edit 2:
I am also seeing IGMP membership reports from the device for the multicast groups that the software is listening for.

Edit 3:
Simplified version of the code segment for socket binding:

struct sockaddr_in _addr, *paddr;
paddr = &_addr;
_addr.sin_family = AF_INET;
_addr.sin_addr.s_addr = my_intf->sin_addr.s_addr;
_addr.sin_port = my_mcdest->sin_port;
if(::bind(my_sock, (struct sockaddr*)paddr, sizeof(struct sockaddr_in)) == 0)
{
struct ip_mreqn ipmr;
ipmr.imr_multiaddr.s_addr = my_mcdest->sin_addr.s_addr;
ipmr.imr_address.s_addr = my_intf->sin_addr.s_addr;
ipmr.imr_ifindex = 0;
if(setsockopt(my_sock, IPPROTO_IP, IP_ADD_MEMBERSHIP, (char*)&ipmr, sizeof(ipmr)) == 0)
{
setsockopt(my_sock, IPPROTO_IP, IP_MULTICAST_IF, &my_intf->sin_addr, sizeof(struct in_addr));
}
}

Edit 4:
Strangly, when I bind to the multicast address instead of the interface IP address, it's able to receive. However, this also causes it to receive multicast packets on lan2, which is not desired.

Thanks in advance.

What hardware are you running and how does your network config look like?
Some chips might have issue with proper multicast handling...

Running it on Edge Router 4.

network:

config device
option name 'br-lan'
list ports 'lan0'
list ports 'lan1'
list ports 'lan3'

config interface 'lan'
option device 'br-lan'
option proto 'static'
option ipaddr '193.168.123.123'
option netmask '255.255.255.0'

firewall:

config defaults
option input 'ACCEPT'
option output 'ACCEPT'
option forward 'REJECT'
option synflood_protect '1'

I am sending it multicast traffic via lan0.

Think I found the answer.
According to many forum posts on the internet, for linux, multicast bind should be done for multicast address instead of interface address.
In order to filter based on interface, IP_PKTINFO socket option needs to be set before calling bind() and recvmsg() needs to be called when receiving to manually check and filter.
Will try this out before accepting as the solution.

1 Like