未验证 提交 662404ed 编写于 作者: W Walker Xia 提交者: GitHub

[ISSUE #1057]Filter out docker0 when finding a local address (#1177)

* Filter out docker0 when finding a local address

* sweep out bridge interface
Co-authored-by: Nyuanyuan.xia <yuanyuan.xia@envisioncn.com>
上级 8a2554df
...@@ -19,6 +19,7 @@ package org.apache.rocketmq.remoting.common; ...@@ -19,6 +19,7 @@ package org.apache.rocketmq.remoting.common;
import io.netty.channel.Channel; import io.netty.channel.Channel;
import io.netty.channel.ChannelFuture; import io.netty.channel.ChannelFuture;
import io.netty.channel.ChannelFutureListener; import io.netty.channel.ChannelFutureListener;
import java.io.File;
import java.io.IOException; import java.io.IOException;
import java.lang.reflect.Method; import java.lang.reflect.Method;
import java.net.Inet6Address; import java.net.Inet6Address;
...@@ -98,6 +99,10 @@ public class RemotingUtil { ...@@ -98,6 +99,10 @@ public class RemotingUtil {
ArrayList<String> ipv6Result = new ArrayList<String>(); ArrayList<String> ipv6Result = new ArrayList<String>();
while (enumeration.hasMoreElements()) { while (enumeration.hasMoreElements()) {
final NetworkInterface networkInterface = enumeration.nextElement(); final NetworkInterface networkInterface = enumeration.nextElement();
if (isBridge(networkInterface)) {
continue;
}
final Enumeration<InetAddress> en = networkInterface.getInetAddresses(); final Enumeration<InetAddress> en = networkInterface.getInetAddresses();
while (en.hasMoreElements()) { while (en.hasMoreElements()) {
final InetAddress address = en.nextElement(); final InetAddress address = en.nextElement();
...@@ -160,6 +165,19 @@ public class RemotingUtil { ...@@ -160,6 +165,19 @@ public class RemotingUtil {
return sb.toString(); return sb.toString();
} }
private static boolean isBridge(NetworkInterface networkInterface) {
try {
if (isLinuxPlatform()) {
String interfaceName = networkInterface.getName();
File file = new File("/sys/class/net/" + interfaceName + "/bridge");
return file.exists();
}
} catch (SecurityException e) {
//Ignore
}
return false;
}
public static SocketChannel connect(SocketAddress remote) { public static SocketChannel connect(SocketAddress remote) {
return connect(remote, 1000 * 5); return connect(remote, 1000 * 5);
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册