receiving multicast on a server with multiple interfaces (linux)
Asked Answered
C

2

8

To receive a multicast on my not default NIC (dvb) I do the following:

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

at this point the only way to receive the needed multicast packets is to add in the routing table a rule to reach the network where the sender is (another network) trough the dvb, as if the dvb needs to reply to the multicast sender; let say a sort of source sender multicast mode. Anyone knows what is going on? The problem is annoying to me because in principle I don't know the ip of sender.

Cloistral answered 30/3, 2011 at 8:21 Comment(0)
P
11

You appear to be being stung by rp_filter reverse-path filtering. This drops packets if they arrive on an interface that doesn't have a route for the source address.

You can disable it on a per-interface basis with the sysctl /proc/sys/net/ipv4/conf/<if>/rp_filter.

Postilion answered 30/3, 2011 at 11:1 Comment(3)
this seems to be the solution, I also found useful information on this page ifup.org/2011/02/03/reverse-path-filter-rp_filter-by-examplePederasty
That worked, however we had to disable the rp_filter not on the interface receiving the multicast but on the interface used in the routing table as default.Cloistral
Unfortunately, @thrantir's link is no longer valid.Idioplasm
T
0

bind the multicast address

That is definitely wrong. You must bind to an actual IP address of a real adapter, or 0.0.0.0.

note that a common error is to bind "0.0.0.0"

That's not an error. THat is correct procedure unless you only want to listen to one IP address.

and then receive on that socket even multicast you are not interested in

I don't know what this means.

in principle I don't know the ip of sender

The IP address of the sender of any UDP datagram is available via the sockets API.

Teaser answered 30/3, 2011 at 9:44 Comment(4)
No you need to bind the multicast address, if you bind the ip address of the real adapter you will not receive any multicast packet, if you bind to 0.0.0.0 you are opening your IP filter to any multicast. In order to have the perfect software filtering based on the destination IP (in this case the multicast address) and then receive only "that" multicast you need to bind the multicast. I suggest you to read the multicast chapter in UNP.Cloistral
@Gaetano Mendola: I read it 13 years ago thanks. It doesn't work on Windows and it doesn't make sense w.r.t. the accepted definition of 'bind'.Teaser
The fact doesn't work on Windows doesn't mean it's wrong. Windows IP stack isn't famous to be standard, also note that I have put on my question: linux. Then again on our middleware we are aware of it and in case WIN32 is defined we bind the IP address of interface, but again that is wrong to do if you have a "good" IP stack.Cloistral
@GaetanoMendola It doesn't work on Solaris, AIX, BSD, FreeBSD, AIX, HP-UX, ... either. It's a Linux-ism. Linux != the world.Teaser

© 2022 - 2024 — McMap. All rights reserved.