Use StandardSocketOptions#IP_MULTICAST_IF as default source when joing multicast groups (#11585)

Motivation:

We should use StandardSocketOptions#IP_MULTICAST_IF as default source when joing multicast groups and only try to use the localAddress if this returns null.

Modifications:

First check if StandardSocketOptions#IP_MULTICAST_IF was set and if so use the network interface when joining mulicast groups

Result:

Fixes https://github.com/netty/netty/issues/11541
This commit is contained in:
Norman Maurer 2021-08-18 12:11:48 +02:00 committed by GitHub
parent cafc669436
commit 228a01e268
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 15 additions and 10 deletions

View File

@ -141,9 +141,11 @@ public final class EpollDatagramChannel extends AbstractEpollChannel implements
@Override
public ChannelFuture joinGroup(InetAddress multicastAddress, ChannelPromise promise) {
try {
return joinGroup(
multicastAddress,
NetworkInterface.getByInetAddress(localAddress().getAddress()), null, promise);
NetworkInterface iface = config().getNetworkInterface();
if (iface == null) {
iface = NetworkInterface.getByInetAddress(localAddress().getAddress());
}
return joinGroup(multicastAddress, iface, null, promise);
} catch (IOException e) {
promise.setFailure(e);
}

View File

@ -99,10 +99,11 @@ public final class KQueueDatagramChannel extends AbstractKQueueDatagramChannel i
@Override
public ChannelFuture joinGroup(InetAddress multicastAddress, ChannelPromise promise) {
try {
return joinGroup(
multicastAddress,
NetworkInterface.getByInetAddress(localAddress().getAddress()),
null, promise);
NetworkInterface iface = config().getNetworkInterface();
if (iface == null) {
iface = NetworkInterface.getByInetAddress(localAddress().getAddress());
}
return joinGroup(multicastAddress, iface, null, promise);
} catch (SocketException e) {
promise.setFailure(e);
}

View File

@ -369,10 +369,12 @@ public final class NioDatagramChannel
@Override
public ChannelFuture joinGroup(InetAddress multicastAddress, ChannelPromise promise) {
try {
NetworkInterface iface = config.getNetworkInterface();
if (iface == null) {
iface = NetworkInterface.getByInetAddress(localAddress().getAddress());
}
return joinGroup(
multicastAddress,
NetworkInterface.getByInetAddress(localAddress().getAddress()),
null, promise);
multicastAddress, iface, null, promise);
} catch (SocketException e) {
promise.setFailure(e);
}