Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

receiving multicast on a server with multiple interfaces (linux)

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.

like image 667
Gaetano Mendola Avatar asked Mar 30 '11 08:03

Gaetano Mendola


People also ask

How does multicast work Linux?

A multicast packet is a network packet meant to be received by more than one host, but not by all hosts. This functionality is obtained by assigning special hardware addresses to groups of hosts. Packets directed to one of the special addresses should be received by all the hosts in that group.

How do you join a multicast group?

To join a multicast group, a host sends a join message, using the Internet Group Management Protocol (IGMP), to its first-hop router. Groups are identified by a single class D IP address (in the range 224.0. 0.0 to 239.255. 255.255).

How do you add a multicast route to a netplan?

Netplan lacks an option to add multicast routes. To route multicast out of the ens7 interface, you would add a route to 224.0. 0.0/4 tied to the Ethernet device you want to use. This is not possible with netplan; it is just missing the option to add multicast routes, i.e. with a device instead of a gateway.


1 Answers

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.

like image 103
caf Avatar answered Sep 17 '22 17:09

caf