You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@rocketmq.apache.org by vo...@apache.org on 2021/05/19 11:38:27 UTC
[rocketmq] branch develop updated: [ISSUE #1057]Filter out docker0
when finding a local address (#1177)
This is an automated email from the ASF dual-hosted git repository.
vongosling pushed a commit to branch develop
in repository https://gitbox.apache.org/repos/asf/rocketmq.git
The following commit(s) were added to refs/heads/develop by this push:
new 662404e [ISSUE #1057]Filter out docker0 when finding a local address (#1177)
662404e is described below
commit 662404edfdb4f351f8bb2fbae530b97c7a58c50f
Author: Walker Xia <yu...@envision-digital.com>
AuthorDate: Wed May 19 19:38:10 2021 +0800
[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: yuanyuan.xia <yu...@envisioncn.com>
---
.../apache/rocketmq/remoting/common/RemotingUtil.java | 18 ++++++++++++++++++
1 file changed, 18 insertions(+)
diff --git a/remoting/src/main/java/org/apache/rocketmq/remoting/common/RemotingUtil.java b/remoting/src/main/java/org/apache/rocketmq/remoting/common/RemotingUtil.java
index a16940e..d936c3b 100644
--- a/remoting/src/main/java/org/apache/rocketmq/remoting/common/RemotingUtil.java
+++ b/remoting/src/main/java/org/apache/rocketmq/remoting/common/RemotingUtil.java
@@ -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);
}