You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@activemq.apache.org by cl...@apache.org on 2018/04/06 18:00:09 UTC

[1/2] activemq-artemis git commit: ARTEMIS-1701 strip zone id from IPv6 host

Repository: activemq-artemis
Updated Branches:
  refs/heads/master 619b2cb2a -> b05306dc0


ARTEMIS-1701 strip zone id from IPv6 host


Project: http://git-wip-us.apache.org/repos/asf/activemq-artemis/repo
Commit: http://git-wip-us.apache.org/repos/asf/activemq-artemis/commit/a294dc94
Tree: http://git-wip-us.apache.org/repos/asf/activemq-artemis/tree/a294dc94
Diff: http://git-wip-us.apache.org/repos/asf/activemq-artemis/diff/a294dc94

Branch: refs/heads/master
Commit: a294dc94932d7f37741903eae00f4fb634467f08
Parents: 619b2cb
Author: Justin Bertram <jb...@apache.org>
Authored: Fri Feb 23 15:05:00 2018 -0600
Committer: Clebert Suconic <cl...@apache.org>
Committed: Fri Apr 6 14:00:02 2018 -0400

----------------------------------------------------------------------
 .../apache/activemq/artemis/utils/IPV6Util.java | 15 ++++++++++
 .../activemq/artemis/utils/IPv6UtilTest.java    | 30 ++++++++++++++++++++
 .../remoting/impl/netty/NettyConnector.java     | 15 +---------
 3 files changed, 46 insertions(+), 14 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/a294dc94/artemis-commons/src/main/java/org/apache/activemq/artemis/utils/IPV6Util.java
----------------------------------------------------------------------
diff --git a/artemis-commons/src/main/java/org/apache/activemq/artemis/utils/IPV6Util.java b/artemis-commons/src/main/java/org/apache/activemq/artemis/utils/IPV6Util.java
index 395eeeb..486c699 100644
--- a/artemis-commons/src/main/java/org/apache/activemq/artemis/utils/IPV6Util.java
+++ b/artemis-commons/src/main/java/org/apache/activemq/artemis/utils/IPV6Util.java
@@ -43,4 +43,19 @@ public class IPV6Util {
 
       return host;
    }
+
+   public static String stripBracketsAndZoneID(String host) {
+      // if the host contains a ':' then we know it's not IPv4
+      if (host != null && host.length() > 2 && host.contains(":")) {
+         // Strip opening/closing brackets
+         if (host.startsWith("[") && host.endsWith("]")) {
+            host = host.substring(1, host.length() - 1);
+         }
+
+         if (host.contains("%")) {
+            return host.substring(0, host.indexOf("%"));
+         }
+      }
+      return host;
+   }
 }

http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/a294dc94/artemis-commons/src/test/java/org/apache/activemq/artemis/utils/IPv6UtilTest.java
----------------------------------------------------------------------
diff --git a/artemis-commons/src/test/java/org/apache/activemq/artemis/utils/IPv6UtilTest.java b/artemis-commons/src/test/java/org/apache/activemq/artemis/utils/IPv6UtilTest.java
new file mode 100644
index 0000000..3709731
--- /dev/null
+++ b/artemis-commons/src/test/java/org/apache/activemq/artemis/utils/IPv6UtilTest.java
@@ -0,0 +1,30 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.activemq.artemis.utils;
+
+import org.junit.Test;
+
+import static org.junit.Assert.assertEquals;
+
+public class IPv6UtilTest {
+
+   @Test
+   public void testStripBracketsAndZoneID() {
+      assertEquals("fd00::d7dc:b4cc:2e2a:ea1", IPV6Util.stripBracketsAndZoneID("[fd00::d7dc:b4cc:2e2a:ea1%enp0s3]"));
+      assertEquals("127.0.0.1", IPV6Util.stripBracketsAndZoneID("127.0.0.1"));
+   }
+}

http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/a294dc94/artemis-core-client/src/main/java/org/apache/activemq/artemis/core/remoting/impl/netty/NettyConnector.java
----------------------------------------------------------------------
diff --git a/artemis-core-client/src/main/java/org/apache/activemq/artemis/core/remoting/impl/netty/NettyConnector.java b/artemis-core-client/src/main/java/org/apache/activemq/artemis/core/remoting/impl/netty/NettyConnector.java
index 99d8447..38289ec 100644
--- a/artemis-core-client/src/main/java/org/apache/activemq/artemis/core/remoting/impl/netty/NettyConnector.java
+++ b/artemis-core-client/src/main/java/org/apache/activemq/artemis/core/remoting/impl/netty/NettyConnector.java
@@ -18,7 +18,6 @@ package org.apache.activemq.artemis.core.remoting.impl.netty;
 
 import java.io.IOException;
 import java.net.ConnectException;
-import java.net.Inet6Address;
 import java.net.InetAddress;
 import java.net.InetSocketAddress;
 import java.net.SocketAddress;
@@ -709,19 +708,7 @@ public class NettyConnector extends AbstractConnector {
          return null;
       }
 
-      // HORNETQ-907 - strip off IPv6 scope-id (if necessary)
-      SocketAddress remoteDestination = new InetSocketAddress(host, port);
-      InetAddress inetAddress = ((InetSocketAddress) remoteDestination).getAddress();
-      if (inetAddress instanceof Inet6Address) {
-         Inet6Address inet6Address = (Inet6Address) inetAddress;
-         if (inet6Address.getScopeId() != 0) {
-            try {
-               remoteDestination = new InetSocketAddress(InetAddress.getByAddress(inet6Address.getAddress()), ((InetSocketAddress) remoteDestination).getPort());
-            } catch (UnknownHostException e) {
-               throw new IllegalArgumentException(e.getMessage());
-            }
-         }
-      }
+      InetSocketAddress remoteDestination = new InetSocketAddress(IPV6Util.stripBracketsAndZoneID(host), port);
 
       logger.debug("Remote destination: " + remoteDestination);
 


[2/2] activemq-artemis git commit: This closes #1998

Posted by cl...@apache.org.
This closes #1998


Project: http://git-wip-us.apache.org/repos/asf/activemq-artemis/repo
Commit: http://git-wip-us.apache.org/repos/asf/activemq-artemis/commit/b05306dc
Tree: http://git-wip-us.apache.org/repos/asf/activemq-artemis/tree/b05306dc
Diff: http://git-wip-us.apache.org/repos/asf/activemq-artemis/diff/b05306dc

Branch: refs/heads/master
Commit: b05306dc0e62886306402360ad5c5df3211332b6
Parents: 619b2cb a294dc9
Author: Clebert Suconic <cl...@apache.org>
Authored: Fri Apr 6 14:00:03 2018 -0400
Committer: Clebert Suconic <cl...@apache.org>
Committed: Fri Apr 6 14:00:03 2018 -0400

----------------------------------------------------------------------
 .../apache/activemq/artemis/utils/IPV6Util.java | 15 ++++++++++
 .../activemq/artemis/utils/IPv6UtilTest.java    | 30 ++++++++++++++++++++
 .../remoting/impl/netty/NettyConnector.java     | 15 +---------
 3 files changed, 46 insertions(+), 14 deletions(-)
----------------------------------------------------------------------