bltavares / multicast-socket

A single-socket designed to multicast across multiple interfaces
Apache License 2.0
13 stars 6 forks source link

How best to implement IPv6? #20

Open mon opened 5 months ago

mon commented 5 months ago

I've been wanting to poke around with IPv6 multicast for a while, and I've collected some thoughts that might turn into an implementation at some point...

The first thing is that dual-stack sockets aren't really feasible, because OpenBSD disables them for security reasons. The second is that the multicast address is of course different when in the IPv6 space (unless you use the "IPv4 mapped into the IPv6 space" address, but I'm not sure if that's allowed on OpenBSD).

So either we accept all address types and have 2 sockets internally, or just bump the work down to the user and have a MulticastSocketV4 and MulticastSocketV6. I think this is probably best, I've never seen any use for both V4 and V6 at the same time.

Then, the question is whether to have a generic MulticastSocket<T> where T is either Ipv4Addr or Ipv6Addr, or actually split the implementation... somehow. Macros? Just repeat the code and have some helper functions?

I'm not really sure of the best way to do it and would appreciate any input! On a technical level, it seems like both the unix and windows APIs can happily work with ipv6.

bltavares commented 5 months ago

I'm personally not much familiar with the IPv6 multicast world. I've designed this library mostly to cover the usecase of IPv4 Broadcast across all interfaces, for things such as MDNS and p2p applications to find each other.

As IPv6 Multicast does not have a broadcast address anymore, I'm unsure what is the usecase for it.

Could you share more about usecases of ipv6 multicast so I can learn more about, and reason around it, please?

mon commented 5 months ago

I'm also quite unfamiliar with IPv6 multicast, so I hope it's not "blind leading the blind"...

Basically, my main use of this library is connecting to a CAN->Ethernet bridge like this one. It emits and receives packets exclusively over UDP multicast. No broadcast at all! So you basically just add yourself to its multicast group and start receiving packets (and my reason for using this library: from potentially many devices attached to multiple adapters).

IPv4 link local works, kind of, but it's a bit painful. I really like the idea of IPv6 link local, because then you can have a local network setup where a bunch of separate devices can talk to each other without needing static IPs or for someone to act as a DHCP server.