0

I am having a boost::asio::ip::udp::endpoint on boost::asio::ip::address_v6::any() (INADDR_ANY) and some port (let's say 20000).

Two UDP sockets now get bound to that endpoint with each subsequently joining a distingct IPv6 multicast group (let's say ff02::a and ff02::b) on all external network interfaces by setting the option boost::asio::ip::multicast::join_group multiple times for the respective multicast IPv6 and interface. Also the option boost::asio::ip::udp::socket::reuse_address(true) is getting set for both sockets.

It now appears that each of the two sockets receives UDP datagrams for both of the two multicast groups. The intended behavior is, however, that socket A only receives datagrams targeted at ff02::a and socket B only datagrams targeted at ff02::a.

My first try was to create two different endpoints with IPv6 addresses matching those of the respective IPv6 multicast group of the socket later to be bound to the respective endpoints. However, this leads to both sockets not receiving any datagrams at all.

How do achieve that socket A ony receives datagrams for ff02::a and B only for ff02::b? And why does my approach do not work?

Barmar
  • 741,623
  • 53
  • 500
  • 612
Simon Fromme
  • 3,104
  • 18
  • 30
  • 1
    You can't have two separate sockets on the same port, with udp both with always receive the same packets. Why not just use a different port for each socket? – Alan Birtles Jul 10 '21 at 17:37
  • It's an existing project I am working on where this seems to be a requirement. They want to have one port and send out different responses depending on which IPv6 multicast address the datagram was targeted at. – Simon Fromme Jul 10 '21 at 17:43
  • Also, `ff02::a` is for EIGRP, and that does not use UDP or port numbers, so you should not be using permanently assigned multicast groups that are assigned to something else. You can see the assignments and rules on the IANA _[IPv6 Multicast Address Space Registry](https://www.iana.org/assignments/ipv6-multicast-addresses/ipv6-multicast-addresses.xhtml)_. – Ron Maupin Jul 10 '21 at 17:50
  • The multicast addresses were only meant to serve as an example (probably should have chosen other ones...). In the actual application two multicast groups are used that have properly been registered with IANA, I think. – Simon Fromme Jul 10 '21 at 17:59
  • Thank's for you answer though! Could you provide me with some official resource stating that all UDP datagrams always get delivered to all sockets binding to the same endpoint (i.e. using the same port)? – Simon Fromme Jul 10 '21 at 18:03
  • 1
    The registered multicast groups are on the IANA page I linked. If you are making up your own groups, you need to set the Transient flag, so you would get `ff12::a`. A clear T flag, e.g. `ff02::a` indicates a well-known, registered address that you would see on the IANA page. You are free to create any link-local groups in the `ff12::/24` range (the eight bits following the `ff12::` are reserved flag bits that must be clear), giving you `20,282,409,603,651,670,423,947,251,286,016` possible link-local multicast groups from which to choose. – Ron Maupin Jul 10 '21 at 18:15
  • I see. Thank you for the explanation! This, however, is a minor detail not too relevant for the actual question. Since a UDP connection (I know UDP is "connectionless"...) is defined by a 5-tuple `{, , , , }` it should be possible to send out different responses for different `` but the same ``. The question is: how? https://stackoverflow.com/questions/14388706/how-do-so-reuseaddr-and-so-reuseport-differ/14388707#14388707 might be relevant – Simon Fromme Jul 10 '21 at 18:24
  • @AlanBirtles I just tried it out with IPv6 unicast packages. It seems that those are getting sent to the first socket only. Only the multicast packages seem to get multiplexed to both sockets. So I think your statement about both sockets always reveiving the same packages is not true in this generality. – Simon Fromme Jul 11 '21 at 17:01

0 Answers0