Getting multicast on a server with multiple interfaces (linux)

To receive multicast on my non-default NIC (dvb), I do the following:

  • open socket (AF_INET, SOCK_DGRAM)
  • join multicast address with IP_ADD_MEMBERSHIP on dvb interface
  • bind a multicast address (note that a common mistake is to bind "0.0.0.0" and then receive even multicast on this socket that you are not interested in) and port

at this moment, the only way to obtain the necessary multicast packets is to add a rule to the routing table to reach the network in which the sender (another network) via dvb, as if the sender should respond to multicast; let's say a kind of sender multicast mode. Does anyone know what is going on? The problem annoys me because, in principle, I do not know the sender ip.

+7
source share
2 answers

It looks like you are falling under rp_filter filtering on the return path. This discards packets if they arrive on an interface that does not have a route for the source address.

You can disable it for each interface using sysctl /proc/sys/net/ipv4/conf/<if>/rp_filter .

+9
source

associate multicast address

This is definitely wrong. You must bind to the actual IP address of the real adapter or 0.0.0.0.

note that a common mistake is the binding of "0.0.0.0"

It's not a mistake. This is the correct procedure, unless you want to listen to one IP address.

and then get even interested multicast socket

I do not know what it means.

In principle, I do not know the sender ip

The sender IP address of any UDP datagram is accessible through the socket API.

0
source

All Articles