You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@trafodion.apache.org by db...@apache.org on 2018/10/16 18:09:26 UTC
[1/2] trafodion git commit: [TRAFODION-3221]support using ipv6 with
jdbct4 to connect trafodion
Repository: trafodion
Updated Branches:
refs/heads/master 9f70ab325 -> 3ee76e160
[TRAFODION-3221]support using ipv6 with jdbct4 to connect trafodion
Project: http://git-wip-us.apache.org/repos/asf/trafodion/repo
Commit: http://git-wip-us.apache.org/repos/asf/trafodion/commit/17e5c287
Tree: http://git-wip-us.apache.org/repos/asf/trafodion/tree/17e5c287
Diff: http://git-wip-us.apache.org/repos/asf/trafodion/diff/17e5c287
Branch: refs/heads/master
Commit: 17e5c2877f9f714a04ec86a962737d0e56c74c1c
Parents: 5f230e2
Author: haolin.song <ha...@esgyn.cn>
Authored: Wed Oct 10 16:20:44 2018 +0000
Committer: haolin.song <ha...@esgyn.cn>
Committed: Wed Oct 10 16:31:55 2018 +0000
----------------------------------------------------------------------
.../java/org/trafodion/jdbc/t4/T4Address.java | 72 ++++++++++++++++----
.../odbc/nsksrvr/Interface/Listener_srvr.cpp | 2 +-
2 files changed, 59 insertions(+), 15 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/trafodion/blob/17e5c287/core/conn/jdbcT4/src/main/java/org/trafodion/jdbc/t4/T4Address.java
----------------------------------------------------------------------
diff --git a/core/conn/jdbcT4/src/main/java/org/trafodion/jdbc/t4/T4Address.java b/core/conn/jdbcT4/src/main/java/org/trafodion/jdbc/t4/T4Address.java
index 2bc145c..7870d58 100644
--- a/core/conn/jdbcT4/src/main/java/org/trafodion/jdbc/t4/T4Address.java
+++ b/core/conn/jdbcT4/src/main/java/org/trafodion/jdbc/t4/T4Address.java
@@ -32,6 +32,7 @@ import java.io.IOException;
import java.sql.SQLException;
import java.util.Locale;
import java.util.Properties;
+import java.util.regex.Pattern;
final class T4Address extends Address {
@@ -140,7 +141,10 @@ final class T4Address extends Address {
// ----------------------------------------------------------
String getUrl() {
- return urlPrefix + getIPorName() + ':' + getPort().toString() + "/:";
+ if (isIPv6ForPureUrl(getIPorName())){
+ return urlPrefix + '[' + getIPorName() + ']' + ':' + getPort().toString() + "/:";
+ }else
+ return urlPrefix + getIPorName() + ':' + getPort().toString() + "/:";
} // end getProps()
// ----------------------------------------------------------
@@ -167,7 +171,8 @@ final class T4Address extends Address {
int hostStartIndex = urlPrefix.length();
int hostEndIndex = -1;
if (isIPV6(url)) {
- hostEndIndex = url.lastIndexOf(']', hostStartIndex); // IP6
+ hostStartIndex = hostStartIndex + 1;
+ hostEndIndex = url.lastIndexOf(']'); // IP6
} else {
hostEndIndex = url.indexOf(':', hostStartIndex); // IP4
@@ -201,12 +206,24 @@ final class T4Address extends Address {
* @return port string
*/
private String extractPortFromUrl(String url) throws SQLException {
- int portStartIndex = url.indexOf(':', urlPrefix.length()) + 1;
- int portEndIndex = url.indexOf('/', portStartIndex);
- if (portEndIndex < 0) {
- portEndIndex = url.length();
-
+ int portStartIndex = 0;
+ int portEndIndex = 0;
+ if (isIPV6(url)){
+ portStartIndex = url.indexOf(':', url.indexOf(']')) + 1;
+ portEndIndex = url.indexOf('/', portStartIndex);
+ if (portEndIndex < 0) {
+ portEndIndex = url.length();
+
+ }
+ }else{
+ portStartIndex = url.indexOf(':', urlPrefix.length()) + 1;
+ portEndIndex = url.indexOf('/', portStartIndex);
+ if (portEndIndex < 0) {
+ portEndIndex = url.length();
+
+ }
}
+
String port = url.substring(portStartIndex, portEndIndex);
if (port.length() < 1) {
throw new SQLException("Incorrect port value in the URL.");
@@ -303,13 +320,40 @@ final class T4Address extends Address {
* @return true if the address is a IP address
*/
private boolean isIPAddress(String IPorName) {
- // Minimum length = 7; 1.1.1.1
- if (IPorName.length() < 7)
+
+ return isIPv4(IPorName) || isIPv6ForPureUrl(IPorName);
+ }
+
+ public boolean isIPv4(String str) {
+ if (!Pattern.matches("[0-9]+[.][0-9]+[.][0-9]+[.][0-9]+", str))
return false;
- //
- // If first letter is a digit or ":" (i.e. IPv6), I'll assume it is an
- // IP address
- //
- return (Character.isDigit(IPorName.charAt(0)) || (IPorName.charAt(1) == ':'));
+ else {
+ String[] arrays = str.split("\\.");
+ if (Integer.parseInt(arrays[0]) < 256 && arrays[0].length() <= 3
+ && Integer.parseInt(arrays[1]) < 256 && arrays[1].length() <= 3
+ && Integer.parseInt(arrays[2]) < 256 && arrays[2].length() <= 3
+ && Integer.parseInt(arrays[3]) < 256 && arrays[3].length() <= 3)
+ return true;
+ else return false;
+ }
}
+
+ public boolean isIPv6ForPureUrl(String str) {
+
+ return isIPV6Std(str) || isIPV6Compress(str);
+ }
+
+ public boolean isIPV6Std(String str) {
+ if (!Pattern.matches("^(?:[0-9a-fA-F]{1,4}:){7}[0-9a-fA-F]{1,4}$", str))
+ return false;
+ return true;
+ }
+
+ public boolean isIPV6Compress(String str) {
+ if (!Pattern.matches( "^((?:[0-9A-Fa-f]{1,4}(?::[0-9A-Fa-f]{1,4})*)?)::((?:[0-9A-Fa-f]{1,4}(?::[0-9A-Fa-f]{1,4})*)?)$", str))
+ return false;
+ return true;
+ }
+
+
} // end class Address
http://git-wip-us.apache.org/repos/asf/trafodion/blob/17e5c287/core/conn/odbc/src/odbc/nsksrvr/Interface/Listener_srvr.cpp
----------------------------------------------------------------------
diff --git a/core/conn/odbc/src/odbc/nsksrvr/Interface/Listener_srvr.cpp b/core/conn/odbc/src/odbc/nsksrvr/Interface/Listener_srvr.cpp
index a31b51b..29fc422 100644
--- a/core/conn/odbc/src/odbc/nsksrvr/Interface/Listener_srvr.cpp
+++ b/core/conn/odbc/src/odbc/nsksrvr/Interface/Listener_srvr.cpp
@@ -36,7 +36,7 @@ CNSKListenerSrvr::CNSKListenerSrvr()
m_port = 0;
m_TraceCount = 0;
m_tcpip_operation = CURR_UNDEFINED;
- m_bIPv4 = true;
+ m_bIPv4 = false;
m_TcpProcessName[0] = 0;
doingRequest = new SB_Thread::Errorcheck_Mutex(true);
pipefd[0] = 0; //read fd
[2/2] trafodion git commit: Merge [TRAFODION-3221] PR 1725 Support
ipv6 in JDBC Type 4
Posted by db...@apache.org.
Merge [TRAFODION-3221] PR 1725 Support ipv6 in JDBC Type 4
Project: http://git-wip-us.apache.org/repos/asf/trafodion/repo
Commit: http://git-wip-us.apache.org/repos/asf/trafodion/commit/3ee76e16
Tree: http://git-wip-us.apache.org/repos/asf/trafodion/tree/3ee76e16
Diff: http://git-wip-us.apache.org/repos/asf/trafodion/diff/3ee76e16
Branch: refs/heads/master
Commit: 3ee76e160e86d05e4874bd7407b7aba2755d59e6
Parents: 9f70ab3 17e5c28
Author: Dave Birdsall <db...@apache.org>
Authored: Tue Oct 16 18:08:45 2018 +0000
Committer: Dave Birdsall <db...@apache.org>
Committed: Tue Oct 16 18:08:45 2018 +0000
----------------------------------------------------------------------
.../java/org/trafodion/jdbc/t4/T4Address.java | 72 ++++++++++++++++----
.../odbc/nsksrvr/Interface/Listener_srvr.cpp | 2 +-
2 files changed, 59 insertions(+), 15 deletions(-)
----------------------------------------------------------------------