mirror of
https://github.com/apache/rocketmq.git
synced 2026-08-30 18:10:44 +08:00
* Filter out docker0 when finding a local address * sweep out bridge interface Co-authored-by: yuanyuan.xia <yuanyuan.xia@envisioncn.com>
This commit is contained in:
@@ -19,6 +19,7 @@ package org.apache.rocketmq.remoting.common;
|
||||
import io.netty.channel.Channel;
|
||||
import io.netty.channel.ChannelFuture;
|
||||
import io.netty.channel.ChannelFutureListener;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.lang.reflect.Method;
|
||||
import java.net.Inet6Address;
|
||||
@@ -98,6 +99,10 @@ public class RemotingUtil {
|
||||
ArrayList<String> ipv6Result = new ArrayList<String>();
|
||||
while (enumeration.hasMoreElements()) {
|
||||
final NetworkInterface networkInterface = enumeration.nextElement();
|
||||
if (isBridge(networkInterface)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
final Enumeration<InetAddress> en = networkInterface.getInetAddresses();
|
||||
while (en.hasMoreElements()) {
|
||||
final InetAddress address = en.nextElement();
|
||||
@@ -160,6 +165,19 @@ public class RemotingUtil {
|
||||
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) {
|
||||
return connect(remote, 1000 * 5);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user