Add support for IP_MULTICAST_ALL to EpollDatagramChannel and IOUringDatagramChannel (netty 4.2)#15755
Conversation
IP multicast behaviour varies between Windows and Linux. On Windows, you only receive datagrams for the groups your socket has joined. On Linux, by default, you receive datagrams for all groups joined by the host. This behaviour can be controlled using the IP_MULTICAST_ALL (or IPV6_MULTICAST_ALL) socket option - it is set to 1 by default. OpenJDK sets this to 0 on all NIO and Net multicast channels, it is not configurable. This PR makes the option configurable for epoll socket channels, so that behaviour can be made consistent between NIO and Epoll DatagramChannel.
|
I think we also want to have this for |
|
Agreed - will add that now. |
|
@mahoestar did you sign our ical ? https://netty.io/s/icla ? |
|
Let's merge this one and then do another PR for io_uring as well |
|
Sorry for radio silence - needed to get the CLA signed. Corporate CLA has been signed by my employer now. I'll review all requested changes on this and the netty5 PR now. |
|
This PR doesn't yet set the IP_MULTICAST_ALL automatically - I can port those changes across before you merge if you would like? Then can raise io_uring support for 4.2 as a separate PR. |
|
@mahoestar can you just do the changes required here and we will port it to other branches later on ? |
|
@mahoestar also please sign our ICLA and let me know one done: https://netty.io/s/icla |
@mahoestar ping |
|
Hi, sorry for the delay. My employer has signed the CCLA - is that sufficient? I should be listed under approved contributors there. I will make the following changes in this branch now:
Is that OK? |
Yes!
Sounds good... feel free to close the other PR in the meantime. |
Adds support for the IP_MULTICAST_ALL socket option for io uring.
…g and IoUringDatagramChannelConfig
|
I've made the changes. I'm not sure what behaviour would be best from the constructor of Epoll/IOUringDatagramChannel - whether we should throw a channel exception on failing to set IP_MULTICAST_ALL, or to log an internal error. I suppose an error is possible if using an old kernel. |
Yeah I think logging might be the best bet for compat reasons. |
| import io.netty.channel.ChannelPipeline; | ||
| import io.netty.channel.ChannelPromise; | ||
| import io.netty.channel.DefaultAddressedEnvelope; | ||
| import io.netty.channel.*; |
| public final class EpollDatagramChannel extends AbstractEpollChannel implements DatagramChannel { | ||
| private static final InternalLogger logger = InternalLoggerFactory.getInstance(AbstractByteBuf.class); | ||
| private static final boolean IP_MULTICAST_ALL = | ||
| SystemPropertyUtil.getBoolean("io.netty5.transport.linux.ipMulticastAll", false); |
There was a problem hiding this comment.
| SystemPropertyUtil.getBoolean("io.netty5.transport.linux.ipMulticastAll", false); | |
| SystemPropertyUtil.getBoolean("io.netty.transport.linux.ipMulticastAll", false); |
| try { | ||
| fd.setIpMulticastAll(IP_MULTICAST_ALL); | ||
| } catch (IOException e) { | ||
| throw new ChannelException(e); |
There was a problem hiding this comment.
I think it might be better to just log
| import io.netty.channel.ChannelPromise; | ||
| import io.netty.channel.DefaultAddressedEnvelope; | ||
| import io.netty.channel.IoRegistration; | ||
| import io.netty.channel.*; |
| public final class IoUringDatagramChannel extends AbstractIoUringChannel implements DatagramChannel { | ||
| private static final InternalLogger logger = InternalLoggerFactory.getInstance(AbstractByteBuf.class); | ||
| private static final boolean IP_MULTICAST_ALL = | ||
| SystemPropertyUtil.getBoolean("io.netty5.transport.linux.ipMulticastAll", false); |
There was a problem hiding this comment.
| SystemPropertyUtil.getBoolean("io.netty5.transport.linux.ipMulticastAll", false); | |
| SystemPropertyUtil.getBoolean("io.netty.transport.linux.ipMulticastAll", false); |
| try { | ||
| fd.setIpMulticastAll(IP_MULTICAST_ALL); | ||
| } catch (IOException e) { | ||
| throw new ChannelException(e); |
- Revert wildcard imports - Correct system property names (not netty5) - Log on failure to set IP_MULTICAST_ALL when constructing datagram channels.
…pollDatagramChannel.java
…pollDatagramChannel.java
…pollDatagramChannel.java
…g/IoUringDatagramChannel.java
…g/IoUringDatagramChannel.java
…g/IoUringDatagramChannel.java
|
@mahoestar thanks a lot! |
Motivation:
IP multicast behaviour varies between Windows and Linux.
On Windows, you only receive datagrams for the groups your socket has joined.
On Linux, by default, you receive datagrams for all groups joined by the host.
This behaviour can be controlled using the IP_MULTICAST_ALL (or IPV6_MULTICAST_ALL) socket option - it is set to 1 by default.
OpenJDK sets this to 0 on all NIO and Net multicast channels, it is not configurable.
This PR makes the option configurable for epoll socket channels, so that behaviour can be made consistent between NIO and native datagram channels.
Modification:
Add IP_MULTICAST_ALL and IPV6_MULTICAST_ALL options to native epoll transport and native io uring transport.
Set IP_MULTICAST_ALL to 0 when constructing epoll and io uring datagram channels.
Result:
Fixes #15753.