author | erikj |
Tue, 12 Sep 2017 19:03:39 +0200 | |
changeset 47216 | 71c04702a3d5 |
parent 47121 | jdk/src/jdk.jdwp.agent/share/native/libdt_socket/socketTransport.c@3aceb4fc0e84 |
child 48242 | 61e60548c0cf |
permissions | -rw-r--r-- |
2 | 1 |
/* |
46091
a6f2dc91ba56
8182757: JDWP: Socket Transport handshake hangs on Solaris
gthornbr
parents:
36134
diff
changeset
|
2 |
* Copyright (c) 1998, 2017, Oracle and/or its affiliates. All rights reserved. |
2 | 3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 |
* |
|
5 |
* This code is free software; you can redistribute it and/or modify it |
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
|
5506 | 7 |
* published by the Free Software Foundation. Oracle designates this |
2 | 8 |
* particular file as subject to the "Classpath" exception as provided |
5506 | 9 |
* by Oracle in the LICENSE file that accompanied this code. |
2 | 10 |
* |
11 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
|
12 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
13 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
14 |
* version 2 for more details (a copy is included in the LICENSE file that |
|
15 |
* accompanied this code). |
|
16 |
* |
|
17 |
* You should have received a copy of the GNU General Public License version |
|
18 |
* 2 along with this work; if not, write to the Free Software Foundation, |
|
19 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
|
20 |
* |
|
5506 | 21 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
22 |
* or visit www.oracle.com if you need additional information or have any |
|
23 |
* questions. |
|
2 | 24 |
*/ |
25 |
#include <stdio.h> |
|
26 |
#include <string.h> |
|
27 |
#include <errno.h> |
|
28 |
#include <stdlib.h> |
|
29 |
#include <ctype.h> |
|
30 |
||
31 |
#include "jdwpTransport.h" |
|
32 |
#include "sysSocket.h" |
|
33 |
||
24503
fe24408289d7
8041435: Make JDWP socket connector accept only local connections by default
dsamersoff
parents:
23010
diff
changeset
|
34 |
#ifdef _WIN32 |
fe24408289d7
8041435: Make JDWP socket connector accept only local connections by default
dsamersoff
parents:
23010
diff
changeset
|
35 |
#include <winsock2.h> |
fe24408289d7
8041435: Make JDWP socket connector accept only local connections by default
dsamersoff
parents:
23010
diff
changeset
|
36 |
#include <ws2tcpip.h> |
47121
3aceb4fc0e84
8061228: Allow JDWP socket connector to accept connections from certain ip addresses only
dsamersoff
parents:
46091
diff
changeset
|
37 |
#else |
3aceb4fc0e84
8061228: Allow JDWP socket connector to accept connections from certain ip addresses only
dsamersoff
parents:
46091
diff
changeset
|
38 |
#include <arpa/inet.h> |
3aceb4fc0e84
8061228: Allow JDWP socket connector to accept connections from certain ip addresses only
dsamersoff
parents:
46091
diff
changeset
|
39 |
#include <sys/socket.h> |
24503
fe24408289d7
8041435: Make JDWP socket connector accept only local connections by default
dsamersoff
parents:
23010
diff
changeset
|
40 |
#endif |
fe24408289d7
8041435: Make JDWP socket connector accept only local connections by default
dsamersoff
parents:
23010
diff
changeset
|
41 |
|
2 | 42 |
/* |
43 |
* The Socket Transport Library. |
|
44 |
* |
|
45 |
* This module is an implementation of the Java Debug Wire Protocol Transport |
|
46 |
* Service Provider Interface - see src/share/javavm/export/jdwpTransport.h. |
|
47 |
*/ |
|
48 |
||
49 |
static int serverSocketFD; |
|
50 |
static int socketFD = -1; |
|
51 |
static jdwpTransportCallback *callback; |
|
52 |
static JavaVM *jvm; |
|
53 |
static int tlsIndex; |
|
54 |
static jboolean initialized; |
|
55 |
static struct jdwpTransportNativeInterface_ interface; |
|
56 |
static jdwpTransportEnv single_env = (jdwpTransportEnv)&interface; |
|
57 |
||
58 |
#define RETURN_ERROR(err, msg) \ |
|
59 |
if (1==1) { \ |
|
60 |
setLastError(err, msg); \ |
|
61 |
return err; \ |
|
62 |
} |
|
63 |
||
64 |
#define RETURN_IO_ERROR(msg) RETURN_ERROR(JDWPTRANSPORT_ERROR_IO_ERROR, msg); |
|
65 |
||
66 |
#define RETURN_RECV_ERROR(n) \ |
|
67 |
if (n == 0) { \ |
|
68 |
RETURN_ERROR(JDWPTRANSPORT_ERROR_IO_ERROR, "premature EOF"); \ |
|
69 |
} else { \ |
|
70 |
RETURN_IO_ERROR("recv error"); \ |
|
71 |
} |
|
72 |
||
73 |
#define HEADER_SIZE 11 |
|
74 |
#define MAX_DATA_SIZE 1000 |
|
75 |
||
12047
320a714614e9
7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
5506
diff
changeset
|
76 |
static jint recv_fully(int, char *, int); |
320a714614e9
7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
5506
diff
changeset
|
77 |
static jint send_fully(int, char *, int); |
320a714614e9
7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
5506
diff
changeset
|
78 |
|
47121
3aceb4fc0e84
8061228: Allow JDWP socket connector to accept connections from certain ip addresses only
dsamersoff
parents:
46091
diff
changeset
|
79 |
/* version >= JDWPTRANSPORT_VERSION_1_1 */ |
3aceb4fc0e84
8061228: Allow JDWP socket connector to accept connections from certain ip addresses only
dsamersoff
parents:
46091
diff
changeset
|
80 |
typedef struct { |
3aceb4fc0e84
8061228: Allow JDWP socket connector to accept connections from certain ip addresses only
dsamersoff
parents:
46091
diff
changeset
|
81 |
uint32_t subnet; |
3aceb4fc0e84
8061228: Allow JDWP socket connector to accept connections from certain ip addresses only
dsamersoff
parents:
46091
diff
changeset
|
82 |
uint32_t netmask; |
3aceb4fc0e84
8061228: Allow JDWP socket connector to accept connections from certain ip addresses only
dsamersoff
parents:
46091
diff
changeset
|
83 |
} AllowedPeerInfo; |
3aceb4fc0e84
8061228: Allow JDWP socket connector to accept connections from certain ip addresses only
dsamersoff
parents:
46091
diff
changeset
|
84 |
|
3aceb4fc0e84
8061228: Allow JDWP socket connector to accept connections from certain ip addresses only
dsamersoff
parents:
46091
diff
changeset
|
85 |
#define STR(x) #x |
3aceb4fc0e84
8061228: Allow JDWP socket connector to accept connections from certain ip addresses only
dsamersoff
parents:
46091
diff
changeset
|
86 |
#define MAX_PEER_ENTRIES 32 |
3aceb4fc0e84
8061228: Allow JDWP socket connector to accept connections from certain ip addresses only
dsamersoff
parents:
46091
diff
changeset
|
87 |
#define MAX_PEERS_STR STR(MAX_PEER_ENTRIES) |
3aceb4fc0e84
8061228: Allow JDWP socket connector to accept connections from certain ip addresses only
dsamersoff
parents:
46091
diff
changeset
|
88 |
static AllowedPeerInfo _peers[MAX_PEER_ENTRIES]; |
3aceb4fc0e84
8061228: Allow JDWP socket connector to accept connections from certain ip addresses only
dsamersoff
parents:
46091
diff
changeset
|
89 |
static int _peers_cnt = 0; |
3aceb4fc0e84
8061228: Allow JDWP socket connector to accept connections from certain ip addresses only
dsamersoff
parents:
46091
diff
changeset
|
90 |
|
3aceb4fc0e84
8061228: Allow JDWP socket connector to accept connections from certain ip addresses only
dsamersoff
parents:
46091
diff
changeset
|
91 |
|
2 | 92 |
/* |
93 |
* Record the last error for this thread. |
|
94 |
*/ |
|
95 |
static void |
|
96 |
setLastError(jdwpTransportError err, char *newmsg) { |
|
97 |
char buf[255]; |
|
98 |
char *msg; |
|
99 |
||
100 |
/* get any I/O first in case any system calls override errno */ |
|
101 |
if (err == JDWPTRANSPORT_ERROR_IO_ERROR) { |
|
102 |
dbgsysGetLastIOError(buf, sizeof(buf)); |
|
103 |
} |
|
104 |
||
105 |
msg = (char *)dbgsysTlsGet(tlsIndex); |
|
106 |
if (msg != NULL) { |
|
107 |
(*callback->free)(msg); |
|
108 |
} |
|
109 |
||
110 |
if (err == JDWPTRANSPORT_ERROR_IO_ERROR) { |
|
111 |
char *join_str = ": "; |
|
896
5c02031316bf
6725543: Compiler warnings in serviceability native code
ohair
parents:
2
diff
changeset
|
112 |
int msg_len = (int)strlen(newmsg) + (int)strlen(join_str) + |
5c02031316bf
6725543: Compiler warnings in serviceability native code
ohair
parents:
2
diff
changeset
|
113 |
(int)strlen(buf) + 3; |
2 | 114 |
msg = (*callback->alloc)(msg_len); |
115 |
if (msg != NULL) { |
|
116 |
strcpy(msg, newmsg); |
|
117 |
strcat(msg, join_str); |
|
118 |
strcat(msg, buf); |
|
119 |
} |
|
120 |
} else { |
|
896
5c02031316bf
6725543: Compiler warnings in serviceability native code
ohair
parents:
2
diff
changeset
|
121 |
msg = (*callback->alloc)((int)strlen(newmsg)+1); |
2 | 122 |
if (msg != NULL) { |
123 |
strcpy(msg, newmsg); |
|
124 |
} |
|
125 |
} |
|
126 |
||
127 |
dbgsysTlsPut(tlsIndex, msg); |
|
128 |
} |
|
129 |
||
130 |
/* |
|
131 |
* Return the last error for this thread (may be NULL) |
|
132 |
*/ |
|
133 |
static char* |
|
134 |
getLastError() { |
|
135 |
return (char *)dbgsysTlsGet(tlsIndex); |
|
136 |
} |
|
137 |
||
46091
a6f2dc91ba56
8182757: JDWP: Socket Transport handshake hangs on Solaris
gthornbr
parents:
36134
diff
changeset
|
138 |
/* Set options common to client and server sides */ |
2 | 139 |
static jdwpTransportError |
46091
a6f2dc91ba56
8182757: JDWP: Socket Transport handshake hangs on Solaris
gthornbr
parents:
36134
diff
changeset
|
140 |
setOptionsCommon(int fd) |
a6f2dc91ba56
8182757: JDWP: Socket Transport handshake hangs on Solaris
gthornbr
parents:
36134
diff
changeset
|
141 |
{ |
a6f2dc91ba56
8182757: JDWP: Socket Transport handshake hangs on Solaris
gthornbr
parents:
36134
diff
changeset
|
142 |
jvalue dontcare; |
a6f2dc91ba56
8182757: JDWP: Socket Transport handshake hangs on Solaris
gthornbr
parents:
36134
diff
changeset
|
143 |
int err; |
a6f2dc91ba56
8182757: JDWP: Socket Transport handshake hangs on Solaris
gthornbr
parents:
36134
diff
changeset
|
144 |
|
a6f2dc91ba56
8182757: JDWP: Socket Transport handshake hangs on Solaris
gthornbr
parents:
36134
diff
changeset
|
145 |
dontcare.i = 0; /* keep compiler happy */ |
a6f2dc91ba56
8182757: JDWP: Socket Transport handshake hangs on Solaris
gthornbr
parents:
36134
diff
changeset
|
146 |
|
a6f2dc91ba56
8182757: JDWP: Socket Transport handshake hangs on Solaris
gthornbr
parents:
36134
diff
changeset
|
147 |
err = dbgsysSetSocketOption(fd, TCP_NODELAY, JNI_TRUE, dontcare); |
a6f2dc91ba56
8182757: JDWP: Socket Transport handshake hangs on Solaris
gthornbr
parents:
36134
diff
changeset
|
148 |
if (err < 0) { |
a6f2dc91ba56
8182757: JDWP: Socket Transport handshake hangs on Solaris
gthornbr
parents:
36134
diff
changeset
|
149 |
RETURN_IO_ERROR("setsockopt TCPNODELAY failed"); |
a6f2dc91ba56
8182757: JDWP: Socket Transport handshake hangs on Solaris
gthornbr
parents:
36134
diff
changeset
|
150 |
} |
a6f2dc91ba56
8182757: JDWP: Socket Transport handshake hangs on Solaris
gthornbr
parents:
36134
diff
changeset
|
151 |
|
a6f2dc91ba56
8182757: JDWP: Socket Transport handshake hangs on Solaris
gthornbr
parents:
36134
diff
changeset
|
152 |
return JDWPTRANSPORT_ERROR_NONE; |
a6f2dc91ba56
8182757: JDWP: Socket Transport handshake hangs on Solaris
gthornbr
parents:
36134
diff
changeset
|
153 |
} |
a6f2dc91ba56
8182757: JDWP: Socket Transport handshake hangs on Solaris
gthornbr
parents:
36134
diff
changeset
|
154 |
|
a6f2dc91ba56
8182757: JDWP: Socket Transport handshake hangs on Solaris
gthornbr
parents:
36134
diff
changeset
|
155 |
/* Set the SO_REUSEADDR option */ |
a6f2dc91ba56
8182757: JDWP: Socket Transport handshake hangs on Solaris
gthornbr
parents:
36134
diff
changeset
|
156 |
static jdwpTransportError |
a6f2dc91ba56
8182757: JDWP: Socket Transport handshake hangs on Solaris
gthornbr
parents:
36134
diff
changeset
|
157 |
setReuseAddrOption(int fd) |
2 | 158 |
{ |
159 |
jvalue dontcare; |
|
160 |
int err; |
|
161 |
||
162 |
dontcare.i = 0; /* keep compiler happy */ |
|
163 |
||
164 |
err = dbgsysSetSocketOption(fd, SO_REUSEADDR, JNI_TRUE, dontcare); |
|
165 |
if (err < 0) { |
|
166 |
RETURN_IO_ERROR("setsockopt SO_REUSEADDR failed"); |
|
167 |
} |
|
168 |
||
169 |
return JDWPTRANSPORT_ERROR_NONE; |
|
170 |
} |
|
171 |
||
172 |
static jdwpTransportError |
|
173 |
handshake(int fd, jlong timeout) { |
|
3723
a27278866f80
6432567: PIT : com/sun/jdi/BadHandshakeTest.java fails due to java.net.ConnectException
alanb
parents:
1247
diff
changeset
|
174 |
const char *hello = "JDWP-Handshake"; |
2 | 175 |
char b[16]; |
3723
a27278866f80
6432567: PIT : com/sun/jdi/BadHandshakeTest.java fails due to java.net.ConnectException
alanb
parents:
1247
diff
changeset
|
176 |
int rv, helloLen, received; |
2 | 177 |
|
178 |
if (timeout > 0) { |
|
179 |
dbgsysConfigureBlocking(fd, JNI_FALSE); |
|
180 |
} |
|
3723
a27278866f80
6432567: PIT : com/sun/jdi/BadHandshakeTest.java fails due to java.net.ConnectException
alanb
parents:
1247
diff
changeset
|
181 |
helloLen = (int)strlen(hello); |
2 | 182 |
received = 0; |
3723
a27278866f80
6432567: PIT : com/sun/jdi/BadHandshakeTest.java fails due to java.net.ConnectException
alanb
parents:
1247
diff
changeset
|
183 |
while (received < helloLen) { |
2 | 184 |
int n; |
185 |
char *buf; |
|
186 |
if (timeout > 0) { |
|
187 |
rv = dbgsysPoll(fd, JNI_TRUE, JNI_FALSE, (long)timeout); |
|
188 |
if (rv <= 0) { |
|
189 |
setLastError(0, "timeout during handshake"); |
|
190 |
return JDWPTRANSPORT_ERROR_IO_ERROR; |
|
191 |
} |
|
192 |
} |
|
193 |
buf = b; |
|
194 |
buf += received; |
|
12047
320a714614e9
7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
5506
diff
changeset
|
195 |
n = recv_fully(fd, buf, helloLen-received); |
2 | 196 |
if (n == 0) { |
197 |
setLastError(0, "handshake failed - connection prematurally closed"); |
|
198 |
return JDWPTRANSPORT_ERROR_IO_ERROR; |
|
199 |
} |
|
200 |
if (n < 0) { |
|
201 |
RETURN_IO_ERROR("recv failed during handshake"); |
|
202 |
} |
|
203 |
received += n; |
|
204 |
} |
|
205 |
if (timeout > 0) { |
|
206 |
dbgsysConfigureBlocking(fd, JNI_TRUE); |
|
207 |
} |
|
3723
a27278866f80
6432567: PIT : com/sun/jdi/BadHandshakeTest.java fails due to java.net.ConnectException
alanb
parents:
1247
diff
changeset
|
208 |
if (strncmp(b, hello, received) != 0) { |
a27278866f80
6432567: PIT : com/sun/jdi/BadHandshakeTest.java fails due to java.net.ConnectException
alanb
parents:
1247
diff
changeset
|
209 |
char msg[80+2*16]; |
a27278866f80
6432567: PIT : com/sun/jdi/BadHandshakeTest.java fails due to java.net.ConnectException
alanb
parents:
1247
diff
changeset
|
210 |
b[received] = '\0'; |
a27278866f80
6432567: PIT : com/sun/jdi/BadHandshakeTest.java fails due to java.net.ConnectException
alanb
parents:
1247
diff
changeset
|
211 |
/* |
a27278866f80
6432567: PIT : com/sun/jdi/BadHandshakeTest.java fails due to java.net.ConnectException
alanb
parents:
1247
diff
changeset
|
212 |
* We should really use snprintf here but it's not available on Windows. |
a27278866f80
6432567: PIT : com/sun/jdi/BadHandshakeTest.java fails due to java.net.ConnectException
alanb
parents:
1247
diff
changeset
|
213 |
* We can't use jio_snprintf without linking the transport against the VM. |
a27278866f80
6432567: PIT : com/sun/jdi/BadHandshakeTest.java fails due to java.net.ConnectException
alanb
parents:
1247
diff
changeset
|
214 |
*/ |
a27278866f80
6432567: PIT : com/sun/jdi/BadHandshakeTest.java fails due to java.net.ConnectException
alanb
parents:
1247
diff
changeset
|
215 |
sprintf(msg, "handshake failed - received >%s< - expected >%s<", b, hello); |
a27278866f80
6432567: PIT : com/sun/jdi/BadHandshakeTest.java fails due to java.net.ConnectException
alanb
parents:
1247
diff
changeset
|
216 |
setLastError(0, msg); |
a27278866f80
6432567: PIT : com/sun/jdi/BadHandshakeTest.java fails due to java.net.ConnectException
alanb
parents:
1247
diff
changeset
|
217 |
return JDWPTRANSPORT_ERROR_IO_ERROR; |
2 | 218 |
} |
219 |
||
12047
320a714614e9
7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
5506
diff
changeset
|
220 |
if (send_fully(fd, (char*)hello, helloLen) != helloLen) { |
2 | 221 |
RETURN_IO_ERROR("send failed during handshake"); |
222 |
} |
|
223 |
return JDWPTRANSPORT_ERROR_NONE; |
|
224 |
} |
|
225 |
||
24503
fe24408289d7
8041435: Make JDWP socket connector accept only local connections by default
dsamersoff
parents:
23010
diff
changeset
|
226 |
static uint32_t |
fe24408289d7
8041435: Make JDWP socket connector accept only local connections by default
dsamersoff
parents:
23010
diff
changeset
|
227 |
getLocalHostAddress() { |
fe24408289d7
8041435: Make JDWP socket connector accept only local connections by default
dsamersoff
parents:
23010
diff
changeset
|
228 |
// Simple routine to guess localhost address. |
fe24408289d7
8041435: Make JDWP socket connector accept only local connections by default
dsamersoff
parents:
23010
diff
changeset
|
229 |
// it looks up "localhost" and returns 127.0.0.1 if lookup |
fe24408289d7
8041435: Make JDWP socket connector accept only local connections by default
dsamersoff
parents:
23010
diff
changeset
|
230 |
// fails. |
24514
2440b44952d7
8043716: JDI test com/sun/jdi/ProcessAttachTest.sh and other 3 jdi tests failed in nightly
dsamersoff
parents:
24503
diff
changeset
|
231 |
struct addrinfo hints, *res = NULL; |
24503
fe24408289d7
8041435: Make JDWP socket connector accept only local connections by default
dsamersoff
parents:
23010
diff
changeset
|
232 |
int err; |
fe24408289d7
8041435: Make JDWP socket connector accept only local connections by default
dsamersoff
parents:
23010
diff
changeset
|
233 |
|
24514
2440b44952d7
8043716: JDI test com/sun/jdi/ProcessAttachTest.sh and other 3 jdi tests failed in nightly
dsamersoff
parents:
24503
diff
changeset
|
234 |
// Use portable way to initialize the structure |
2440b44952d7
8043716: JDI test com/sun/jdi/ProcessAttachTest.sh and other 3 jdi tests failed in nightly
dsamersoff
parents:
24503
diff
changeset
|
235 |
memset((void *)&hints, 0, sizeof(hints)); |
24503
fe24408289d7
8041435: Make JDWP socket connector accept only local connections by default
dsamersoff
parents:
23010
diff
changeset
|
236 |
hints.ai_family = AF_INET; |
fe24408289d7
8041435: Make JDWP socket connector accept only local connections by default
dsamersoff
parents:
23010
diff
changeset
|
237 |
|
fe24408289d7
8041435: Make JDWP socket connector accept only local connections by default
dsamersoff
parents:
23010
diff
changeset
|
238 |
err = getaddrinfo("localhost", NULL, &hints, &res); |
fe24408289d7
8041435: Make JDWP socket connector accept only local connections by default
dsamersoff
parents:
23010
diff
changeset
|
239 |
if (err < 0 || res == NULL) { |
fe24408289d7
8041435: Make JDWP socket connector accept only local connections by default
dsamersoff
parents:
23010
diff
changeset
|
240 |
return dbgsysHostToNetworkLong(INADDR_LOOPBACK); |
fe24408289d7
8041435: Make JDWP socket connector accept only local connections by default
dsamersoff
parents:
23010
diff
changeset
|
241 |
} |
fe24408289d7
8041435: Make JDWP socket connector accept only local connections by default
dsamersoff
parents:
23010
diff
changeset
|
242 |
|
fe24408289d7
8041435: Make JDWP socket connector accept only local connections by default
dsamersoff
parents:
23010
diff
changeset
|
243 |
// getaddrinfo might return more than one address |
fe24408289d7
8041435: Make JDWP socket connector accept only local connections by default
dsamersoff
parents:
23010
diff
changeset
|
244 |
// but we are using first one only |
fe24408289d7
8041435: Make JDWP socket connector accept only local connections by default
dsamersoff
parents:
23010
diff
changeset
|
245 |
return ((struct sockaddr_in *)(res->ai_addr))->sin_addr.s_addr; |
fe24408289d7
8041435: Make JDWP socket connector accept only local connections by default
dsamersoff
parents:
23010
diff
changeset
|
246 |
} |
fe24408289d7
8041435: Make JDWP socket connector accept only local connections by default
dsamersoff
parents:
23010
diff
changeset
|
247 |
|
fe24408289d7
8041435: Make JDWP socket connector accept only local connections by default
dsamersoff
parents:
23010
diff
changeset
|
248 |
static int |
fe24408289d7
8041435: Make JDWP socket connector accept only local connections by default
dsamersoff
parents:
23010
diff
changeset
|
249 |
getPortNumber(const char *s_port) { |
fe24408289d7
8041435: Make JDWP socket connector accept only local connections by default
dsamersoff
parents:
23010
diff
changeset
|
250 |
u_long n; |
fe24408289d7
8041435: Make JDWP socket connector accept only local connections by default
dsamersoff
parents:
23010
diff
changeset
|
251 |
char *eptr; |
fe24408289d7
8041435: Make JDWP socket connector accept only local connections by default
dsamersoff
parents:
23010
diff
changeset
|
252 |
|
fe24408289d7
8041435: Make JDWP socket connector accept only local connections by default
dsamersoff
parents:
23010
diff
changeset
|
253 |
if (*s_port == 0) { |
fe24408289d7
8041435: Make JDWP socket connector accept only local connections by default
dsamersoff
parents:
23010
diff
changeset
|
254 |
// bad address - colon with no port number in parameters |
fe24408289d7
8041435: Make JDWP socket connector accept only local connections by default
dsamersoff
parents:
23010
diff
changeset
|
255 |
return -1; |
fe24408289d7
8041435: Make JDWP socket connector accept only local connections by default
dsamersoff
parents:
23010
diff
changeset
|
256 |
} |
fe24408289d7
8041435: Make JDWP socket connector accept only local connections by default
dsamersoff
parents:
23010
diff
changeset
|
257 |
|
fe24408289d7
8041435: Make JDWP socket connector accept only local connections by default
dsamersoff
parents:
23010
diff
changeset
|
258 |
n = strtoul(s_port, &eptr, 10); |
fe24408289d7
8041435: Make JDWP socket connector accept only local connections by default
dsamersoff
parents:
23010
diff
changeset
|
259 |
if (eptr != s_port + strlen(s_port)) { |
fe24408289d7
8041435: Make JDWP socket connector accept only local connections by default
dsamersoff
parents:
23010
diff
changeset
|
260 |
// incomplete conversion - port number contains non-digit |
fe24408289d7
8041435: Make JDWP socket connector accept only local connections by default
dsamersoff
parents:
23010
diff
changeset
|
261 |
return -1; |
fe24408289d7
8041435: Make JDWP socket connector accept only local connections by default
dsamersoff
parents:
23010
diff
changeset
|
262 |
} |
fe24408289d7
8041435: Make JDWP socket connector accept only local connections by default
dsamersoff
parents:
23010
diff
changeset
|
263 |
|
fe24408289d7
8041435: Make JDWP socket connector accept only local connections by default
dsamersoff
parents:
23010
diff
changeset
|
264 |
if (n > (u_short) -1) { |
fe24408289d7
8041435: Make JDWP socket connector accept only local connections by default
dsamersoff
parents:
23010
diff
changeset
|
265 |
// check that value supplied by user is less than |
fe24408289d7
8041435: Make JDWP socket connector accept only local connections by default
dsamersoff
parents:
23010
diff
changeset
|
266 |
// maximum possible u_short value (65535) and |
fe24408289d7
8041435: Make JDWP socket connector accept only local connections by default
dsamersoff
parents:
23010
diff
changeset
|
267 |
// will not be truncated later. |
fe24408289d7
8041435: Make JDWP socket connector accept only local connections by default
dsamersoff
parents:
23010
diff
changeset
|
268 |
return -1; |
fe24408289d7
8041435: Make JDWP socket connector accept only local connections by default
dsamersoff
parents:
23010
diff
changeset
|
269 |
} |
fe24408289d7
8041435: Make JDWP socket connector accept only local connections by default
dsamersoff
parents:
23010
diff
changeset
|
270 |
|
fe24408289d7
8041435: Make JDWP socket connector accept only local connections by default
dsamersoff
parents:
23010
diff
changeset
|
271 |
return n; |
fe24408289d7
8041435: Make JDWP socket connector accept only local connections by default
dsamersoff
parents:
23010
diff
changeset
|
272 |
} |
fe24408289d7
8041435: Make JDWP socket connector accept only local connections by default
dsamersoff
parents:
23010
diff
changeset
|
273 |
|
2 | 274 |
static jdwpTransportError |
24503
fe24408289d7
8041435: Make JDWP socket connector accept only local connections by default
dsamersoff
parents:
23010
diff
changeset
|
275 |
parseAddress(const char *address, struct sockaddr_in *sa) { |
2 | 276 |
char *colon; |
24503
fe24408289d7
8041435: Make JDWP socket connector accept only local connections by default
dsamersoff
parents:
23010
diff
changeset
|
277 |
int port; |
2 | 278 |
|
47121
3aceb4fc0e84
8061228: Allow JDWP socket connector to accept connections from certain ip addresses only
dsamersoff
parents:
46091
diff
changeset
|
279 |
memset((void *)sa, 0, sizeof(struct sockaddr_in)); |
2 | 280 |
sa->sin_family = AF_INET; |
281 |
||
282 |
/* check for host:port or port */ |
|
283 |
colon = strchr(address, ':'); |
|
24503
fe24408289d7
8041435: Make JDWP socket connector accept only local connections by default
dsamersoff
parents:
23010
diff
changeset
|
284 |
port = getPortNumber((colon == NULL) ? address : colon +1); |
fe24408289d7
8041435: Make JDWP socket connector accept only local connections by default
dsamersoff
parents:
23010
diff
changeset
|
285 |
if (port < 0) { |
fe24408289d7
8041435: Make JDWP socket connector accept only local connections by default
dsamersoff
parents:
23010
diff
changeset
|
286 |
RETURN_ERROR(JDWPTRANSPORT_ERROR_ILLEGAL_ARGUMENT, "invalid port number specified"); |
fe24408289d7
8041435: Make JDWP socket connector accept only local connections by default
dsamersoff
parents:
23010
diff
changeset
|
287 |
} |
fe24408289d7
8041435: Make JDWP socket connector accept only local connections by default
dsamersoff
parents:
23010
diff
changeset
|
288 |
sa->sin_port = dbgsysHostToNetworkShort((u_short)port); |
fe24408289d7
8041435: Make JDWP socket connector accept only local connections by default
dsamersoff
parents:
23010
diff
changeset
|
289 |
|
2 | 290 |
if (colon == NULL) { |
24503
fe24408289d7
8041435: Make JDWP socket connector accept only local connections by default
dsamersoff
parents:
23010
diff
changeset
|
291 |
// bind to localhost only if no address specified |
fe24408289d7
8041435: Make JDWP socket connector accept only local connections by default
dsamersoff
parents:
23010
diff
changeset
|
292 |
sa->sin_addr.s_addr = getLocalHostAddress(); |
47121
3aceb4fc0e84
8061228: Allow JDWP socket connector to accept connections from certain ip addresses only
dsamersoff
parents:
46091
diff
changeset
|
293 |
} else if (strncmp(address, "localhost:", 10) == 0) { |
24503
fe24408289d7
8041435: Make JDWP socket connector accept only local connections by default
dsamersoff
parents:
23010
diff
changeset
|
294 |
// optimize for common case |
fe24408289d7
8041435: Make JDWP socket connector accept only local connections by default
dsamersoff
parents:
23010
diff
changeset
|
295 |
sa->sin_addr.s_addr = getLocalHostAddress(); |
fe24408289d7
8041435: Make JDWP socket connector accept only local connections by default
dsamersoff
parents:
23010
diff
changeset
|
296 |
} else if (*address == '*' && *(address+1) == ':') { |
fe24408289d7
8041435: Make JDWP socket connector accept only local connections by default
dsamersoff
parents:
23010
diff
changeset
|
297 |
// we are explicitly asked to bind server to all available IP addresses |
fe24408289d7
8041435: Make JDWP socket connector accept only local connections by default
dsamersoff
parents:
23010
diff
changeset
|
298 |
// has no meaning for client. |
fe24408289d7
8041435: Make JDWP socket connector accept only local connections by default
dsamersoff
parents:
23010
diff
changeset
|
299 |
sa->sin_addr.s_addr = dbgsysHostToNetworkLong(INADDR_ANY); |
fe24408289d7
8041435: Make JDWP socket connector accept only local connections by default
dsamersoff
parents:
23010
diff
changeset
|
300 |
} else { |
2 | 301 |
char *buf; |
302 |
char *hostname; |
|
896
5c02031316bf
6725543: Compiler warnings in serviceability native code
ohair
parents:
2
diff
changeset
|
303 |
uint32_t addr; |
2 | 304 |
|
47121
3aceb4fc0e84
8061228: Allow JDWP socket connector to accept connections from certain ip addresses only
dsamersoff
parents:
46091
diff
changeset
|
305 |
buf = (*callback->alloc)((int)strlen(address) + 1); |
2 | 306 |
if (buf == NULL) { |
307 |
RETURN_ERROR(JDWPTRANSPORT_ERROR_OUT_OF_MEMORY, "out of memory"); |
|
308 |
} |
|
309 |
strcpy(buf, address); |
|
310 |
buf[colon - address] = '\0'; |
|
311 |
hostname = buf; |
|
312 |
||
313 |
/* |
|
314 |
* First see if the host is a literal IP address. |
|
315 |
* If not then try to resolve it. |
|
316 |
*/ |
|
317 |
addr = dbgsysInetAddr(hostname); |
|
318 |
if (addr == 0xffffffff) { |
|
319 |
struct hostent *hp = dbgsysGetHostByName(hostname); |
|
320 |
if (hp == NULL) { |
|
321 |
/* don't use RETURN_IO_ERROR as unknown host is normal */ |
|
322 |
setLastError(0, "gethostbyname: unknown host"); |
|
323 |
(*callback->free)(buf); |
|
324 |
return JDWPTRANSPORT_ERROR_IO_ERROR; |
|
325 |
} |
|
326 |
||
327 |
/* lookup was successful */ |
|
328 |
memcpy(&(sa->sin_addr), hp->h_addr_list[0], hp->h_length); |
|
329 |
} else { |
|
330 |
sa->sin_addr.s_addr = addr; |
|
331 |
} |
|
332 |
||
333 |
(*callback->free)(buf); |
|
334 |
} |
|
335 |
||
336 |
return JDWPTRANSPORT_ERROR_NONE; |
|
337 |
} |
|
338 |
||
47121
3aceb4fc0e84
8061228: Allow JDWP socket connector to accept connections from certain ip addresses only
dsamersoff
parents:
46091
diff
changeset
|
339 |
static const char * |
3aceb4fc0e84
8061228: Allow JDWP socket connector to accept connections from certain ip addresses only
dsamersoff
parents:
46091
diff
changeset
|
340 |
ip_s2u(const char *instr, uint32_t *ip) { |
3aceb4fc0e84
8061228: Allow JDWP socket connector to accept connections from certain ip addresses only
dsamersoff
parents:
46091
diff
changeset
|
341 |
// Convert string representation of ip to integer |
3aceb4fc0e84
8061228: Allow JDWP socket connector to accept connections from certain ip addresses only
dsamersoff
parents:
46091
diff
changeset
|
342 |
// in network byte order (big-endian) |
3aceb4fc0e84
8061228: Allow JDWP socket connector to accept connections from certain ip addresses only
dsamersoff
parents:
46091
diff
changeset
|
343 |
char t[4] = { 0, 0, 0, 0 }; |
3aceb4fc0e84
8061228: Allow JDWP socket connector to accept connections from certain ip addresses only
dsamersoff
parents:
46091
diff
changeset
|
344 |
const char *s = instr; |
3aceb4fc0e84
8061228: Allow JDWP socket connector to accept connections from certain ip addresses only
dsamersoff
parents:
46091
diff
changeset
|
345 |
int i = 0; |
3aceb4fc0e84
8061228: Allow JDWP socket connector to accept connections from certain ip addresses only
dsamersoff
parents:
46091
diff
changeset
|
346 |
|
3aceb4fc0e84
8061228: Allow JDWP socket connector to accept connections from certain ip addresses only
dsamersoff
parents:
46091
diff
changeset
|
347 |
while (1) { |
3aceb4fc0e84
8061228: Allow JDWP socket connector to accept connections from certain ip addresses only
dsamersoff
parents:
46091
diff
changeset
|
348 |
if (*s == '.') { |
3aceb4fc0e84
8061228: Allow JDWP socket connector to accept connections from certain ip addresses only
dsamersoff
parents:
46091
diff
changeset
|
349 |
++i; |
3aceb4fc0e84
8061228: Allow JDWP socket connector to accept connections from certain ip addresses only
dsamersoff
parents:
46091
diff
changeset
|
350 |
++s; |
3aceb4fc0e84
8061228: Allow JDWP socket connector to accept connections from certain ip addresses only
dsamersoff
parents:
46091
diff
changeset
|
351 |
continue; |
3aceb4fc0e84
8061228: Allow JDWP socket connector to accept connections from certain ip addresses only
dsamersoff
parents:
46091
diff
changeset
|
352 |
} |
3aceb4fc0e84
8061228: Allow JDWP socket connector to accept connections from certain ip addresses only
dsamersoff
parents:
46091
diff
changeset
|
353 |
if (*s == 0 || *s == '+' || *s == '/') { |
3aceb4fc0e84
8061228: Allow JDWP socket connector to accept connections from certain ip addresses only
dsamersoff
parents:
46091
diff
changeset
|
354 |
break; |
3aceb4fc0e84
8061228: Allow JDWP socket connector to accept connections from certain ip addresses only
dsamersoff
parents:
46091
diff
changeset
|
355 |
} |
3aceb4fc0e84
8061228: Allow JDWP socket connector to accept connections from certain ip addresses only
dsamersoff
parents:
46091
diff
changeset
|
356 |
if (*s < '0' || *s > '9') { |
3aceb4fc0e84
8061228: Allow JDWP socket connector to accept connections from certain ip addresses only
dsamersoff
parents:
46091
diff
changeset
|
357 |
return instr; |
3aceb4fc0e84
8061228: Allow JDWP socket connector to accept connections from certain ip addresses only
dsamersoff
parents:
46091
diff
changeset
|
358 |
} |
3aceb4fc0e84
8061228: Allow JDWP socket connector to accept connections from certain ip addresses only
dsamersoff
parents:
46091
diff
changeset
|
359 |
t[i] = (t[i] * 10) + (*s - '0'); |
3aceb4fc0e84
8061228: Allow JDWP socket connector to accept connections from certain ip addresses only
dsamersoff
parents:
46091
diff
changeset
|
360 |
++s; |
3aceb4fc0e84
8061228: Allow JDWP socket connector to accept connections from certain ip addresses only
dsamersoff
parents:
46091
diff
changeset
|
361 |
} |
3aceb4fc0e84
8061228: Allow JDWP socket connector to accept connections from certain ip addresses only
dsamersoff
parents:
46091
diff
changeset
|
362 |
|
3aceb4fc0e84
8061228: Allow JDWP socket connector to accept connections from certain ip addresses only
dsamersoff
parents:
46091
diff
changeset
|
363 |
*ip = *(uint32_t*)(t); |
3aceb4fc0e84
8061228: Allow JDWP socket connector to accept connections from certain ip addresses only
dsamersoff
parents:
46091
diff
changeset
|
364 |
return s; |
3aceb4fc0e84
8061228: Allow JDWP socket connector to accept connections from certain ip addresses only
dsamersoff
parents:
46091
diff
changeset
|
365 |
} |
3aceb4fc0e84
8061228: Allow JDWP socket connector to accept connections from certain ip addresses only
dsamersoff
parents:
46091
diff
changeset
|
366 |
|
3aceb4fc0e84
8061228: Allow JDWP socket connector to accept connections from certain ip addresses only
dsamersoff
parents:
46091
diff
changeset
|
367 |
static const char * |
3aceb4fc0e84
8061228: Allow JDWP socket connector to accept connections from certain ip addresses only
dsamersoff
parents:
46091
diff
changeset
|
368 |
mask_s2u(const char *instr, uint32_t *mask) { |
3aceb4fc0e84
8061228: Allow JDWP socket connector to accept connections from certain ip addresses only
dsamersoff
parents:
46091
diff
changeset
|
369 |
// Convert the number of bits to a netmask |
3aceb4fc0e84
8061228: Allow JDWP socket connector to accept connections from certain ip addresses only
dsamersoff
parents:
46091
diff
changeset
|
370 |
// in network byte order (big-endian) |
3aceb4fc0e84
8061228: Allow JDWP socket connector to accept connections from certain ip addresses only
dsamersoff
parents:
46091
diff
changeset
|
371 |
unsigned char m = 0; |
3aceb4fc0e84
8061228: Allow JDWP socket connector to accept connections from certain ip addresses only
dsamersoff
parents:
46091
diff
changeset
|
372 |
const char *s = instr; |
3aceb4fc0e84
8061228: Allow JDWP socket connector to accept connections from certain ip addresses only
dsamersoff
parents:
46091
diff
changeset
|
373 |
|
3aceb4fc0e84
8061228: Allow JDWP socket connector to accept connections from certain ip addresses only
dsamersoff
parents:
46091
diff
changeset
|
374 |
while (1) { |
3aceb4fc0e84
8061228: Allow JDWP socket connector to accept connections from certain ip addresses only
dsamersoff
parents:
46091
diff
changeset
|
375 |
if (*s == 0 || *s == '+') { |
3aceb4fc0e84
8061228: Allow JDWP socket connector to accept connections from certain ip addresses only
dsamersoff
parents:
46091
diff
changeset
|
376 |
break; |
3aceb4fc0e84
8061228: Allow JDWP socket connector to accept connections from certain ip addresses only
dsamersoff
parents:
46091
diff
changeset
|
377 |
} |
3aceb4fc0e84
8061228: Allow JDWP socket connector to accept connections from certain ip addresses only
dsamersoff
parents:
46091
diff
changeset
|
378 |
if (*s < '0' || *s > '9') { |
3aceb4fc0e84
8061228: Allow JDWP socket connector to accept connections from certain ip addresses only
dsamersoff
parents:
46091
diff
changeset
|
379 |
return instr; |
3aceb4fc0e84
8061228: Allow JDWP socket connector to accept connections from certain ip addresses only
dsamersoff
parents:
46091
diff
changeset
|
380 |
} |
3aceb4fc0e84
8061228: Allow JDWP socket connector to accept connections from certain ip addresses only
dsamersoff
parents:
46091
diff
changeset
|
381 |
m = (m * 10) + (*s - '0'); |
3aceb4fc0e84
8061228: Allow JDWP socket connector to accept connections from certain ip addresses only
dsamersoff
parents:
46091
diff
changeset
|
382 |
++s; |
3aceb4fc0e84
8061228: Allow JDWP socket connector to accept connections from certain ip addresses only
dsamersoff
parents:
46091
diff
changeset
|
383 |
} |
3aceb4fc0e84
8061228: Allow JDWP socket connector to accept connections from certain ip addresses only
dsamersoff
parents:
46091
diff
changeset
|
384 |
|
3aceb4fc0e84
8061228: Allow JDWP socket connector to accept connections from certain ip addresses only
dsamersoff
parents:
46091
diff
changeset
|
385 |
if (m == 0 || m > 32) { |
3aceb4fc0e84
8061228: Allow JDWP socket connector to accept connections from certain ip addresses only
dsamersoff
parents:
46091
diff
changeset
|
386 |
// Drop invalid input |
3aceb4fc0e84
8061228: Allow JDWP socket connector to accept connections from certain ip addresses only
dsamersoff
parents:
46091
diff
changeset
|
387 |
return instr; |
3aceb4fc0e84
8061228: Allow JDWP socket connector to accept connections from certain ip addresses only
dsamersoff
parents:
46091
diff
changeset
|
388 |
} |
3aceb4fc0e84
8061228: Allow JDWP socket connector to accept connections from certain ip addresses only
dsamersoff
parents:
46091
diff
changeset
|
389 |
|
3aceb4fc0e84
8061228: Allow JDWP socket connector to accept connections from certain ip addresses only
dsamersoff
parents:
46091
diff
changeset
|
390 |
*mask = htonl(-1 << (32 - m)); |
3aceb4fc0e84
8061228: Allow JDWP socket connector to accept connections from certain ip addresses only
dsamersoff
parents:
46091
diff
changeset
|
391 |
return s; |
3aceb4fc0e84
8061228: Allow JDWP socket connector to accept connections from certain ip addresses only
dsamersoff
parents:
46091
diff
changeset
|
392 |
} |
3aceb4fc0e84
8061228: Allow JDWP socket connector to accept connections from certain ip addresses only
dsamersoff
parents:
46091
diff
changeset
|
393 |
|
3aceb4fc0e84
8061228: Allow JDWP socket connector to accept connections from certain ip addresses only
dsamersoff
parents:
46091
diff
changeset
|
394 |
static int |
3aceb4fc0e84
8061228: Allow JDWP socket connector to accept connections from certain ip addresses only
dsamersoff
parents:
46091
diff
changeset
|
395 |
ip_in_subnet(uint32_t subnet, uint32_t mask, uint32_t ipaddr) { |
3aceb4fc0e84
8061228: Allow JDWP socket connector to accept connections from certain ip addresses only
dsamersoff
parents:
46091
diff
changeset
|
396 |
return (ipaddr & mask) == subnet; |
3aceb4fc0e84
8061228: Allow JDWP socket connector to accept connections from certain ip addresses only
dsamersoff
parents:
46091
diff
changeset
|
397 |
} |
3aceb4fc0e84
8061228: Allow JDWP socket connector to accept connections from certain ip addresses only
dsamersoff
parents:
46091
diff
changeset
|
398 |
|
3aceb4fc0e84
8061228: Allow JDWP socket connector to accept connections from certain ip addresses only
dsamersoff
parents:
46091
diff
changeset
|
399 |
static jdwpTransportError |
3aceb4fc0e84
8061228: Allow JDWP socket connector to accept connections from certain ip addresses only
dsamersoff
parents:
46091
diff
changeset
|
400 |
parseAllowedPeers(const char *allowed_peers) { |
3aceb4fc0e84
8061228: Allow JDWP socket connector to accept connections from certain ip addresses only
dsamersoff
parents:
46091
diff
changeset
|
401 |
// Build a list of allowed peers from char string |
3aceb4fc0e84
8061228: Allow JDWP socket connector to accept connections from certain ip addresses only
dsamersoff
parents:
46091
diff
changeset
|
402 |
// of format 192.168.0.10+192.168.0.0/24 |
3aceb4fc0e84
8061228: Allow JDWP socket connector to accept connections from certain ip addresses only
dsamersoff
parents:
46091
diff
changeset
|
403 |
const char *s = NULL; |
3aceb4fc0e84
8061228: Allow JDWP socket connector to accept connections from certain ip addresses only
dsamersoff
parents:
46091
diff
changeset
|
404 |
const char *p = allowed_peers; |
3aceb4fc0e84
8061228: Allow JDWP socket connector to accept connections from certain ip addresses only
dsamersoff
parents:
46091
diff
changeset
|
405 |
uint32_t ip = 0; |
3aceb4fc0e84
8061228: Allow JDWP socket connector to accept connections from certain ip addresses only
dsamersoff
parents:
46091
diff
changeset
|
406 |
uint32_t mask = 0xFFFFFFFF; |
3aceb4fc0e84
8061228: Allow JDWP socket connector to accept connections from certain ip addresses only
dsamersoff
parents:
46091
diff
changeset
|
407 |
|
3aceb4fc0e84
8061228: Allow JDWP socket connector to accept connections from certain ip addresses only
dsamersoff
parents:
46091
diff
changeset
|
408 |
while (1) { |
3aceb4fc0e84
8061228: Allow JDWP socket connector to accept connections from certain ip addresses only
dsamersoff
parents:
46091
diff
changeset
|
409 |
s = ip_s2u(p, &ip); |
3aceb4fc0e84
8061228: Allow JDWP socket connector to accept connections from certain ip addresses only
dsamersoff
parents:
46091
diff
changeset
|
410 |
if (s == p) { |
3aceb4fc0e84
8061228: Allow JDWP socket connector to accept connections from certain ip addresses only
dsamersoff
parents:
46091
diff
changeset
|
411 |
_peers_cnt = 0; |
3aceb4fc0e84
8061228: Allow JDWP socket connector to accept connections from certain ip addresses only
dsamersoff
parents:
46091
diff
changeset
|
412 |
fprintf(stderr, "Error in allow option: '%s'\n", s); |
3aceb4fc0e84
8061228: Allow JDWP socket connector to accept connections from certain ip addresses only
dsamersoff
parents:
46091
diff
changeset
|
413 |
RETURN_ERROR(JDWPTRANSPORT_ERROR_ILLEGAL_ARGUMENT, |
3aceb4fc0e84
8061228: Allow JDWP socket connector to accept connections from certain ip addresses only
dsamersoff
parents:
46091
diff
changeset
|
414 |
"invalid IP address in allow option"); |
3aceb4fc0e84
8061228: Allow JDWP socket connector to accept connections from certain ip addresses only
dsamersoff
parents:
46091
diff
changeset
|
415 |
} |
3aceb4fc0e84
8061228: Allow JDWP socket connector to accept connections from certain ip addresses only
dsamersoff
parents:
46091
diff
changeset
|
416 |
|
3aceb4fc0e84
8061228: Allow JDWP socket connector to accept connections from certain ip addresses only
dsamersoff
parents:
46091
diff
changeset
|
417 |
if (*s == '/') { |
3aceb4fc0e84
8061228: Allow JDWP socket connector to accept connections from certain ip addresses only
dsamersoff
parents:
46091
diff
changeset
|
418 |
// netmask specified |
3aceb4fc0e84
8061228: Allow JDWP socket connector to accept connections from certain ip addresses only
dsamersoff
parents:
46091
diff
changeset
|
419 |
s = mask_s2u(s + 1, &mask); |
3aceb4fc0e84
8061228: Allow JDWP socket connector to accept connections from certain ip addresses only
dsamersoff
parents:
46091
diff
changeset
|
420 |
if (*(s - 1) == '/') { |
3aceb4fc0e84
8061228: Allow JDWP socket connector to accept connections from certain ip addresses only
dsamersoff
parents:
46091
diff
changeset
|
421 |
// Input is not consumed, something bad happened |
3aceb4fc0e84
8061228: Allow JDWP socket connector to accept connections from certain ip addresses only
dsamersoff
parents:
46091
diff
changeset
|
422 |
_peers_cnt = 0; |
3aceb4fc0e84
8061228: Allow JDWP socket connector to accept connections from certain ip addresses only
dsamersoff
parents:
46091
diff
changeset
|
423 |
fprintf(stderr, "Error in allow option: '%s'\n", s); |
3aceb4fc0e84
8061228: Allow JDWP socket connector to accept connections from certain ip addresses only
dsamersoff
parents:
46091
diff
changeset
|
424 |
RETURN_ERROR(JDWPTRANSPORT_ERROR_ILLEGAL_ARGUMENT, |
3aceb4fc0e84
8061228: Allow JDWP socket connector to accept connections from certain ip addresses only
dsamersoff
parents:
46091
diff
changeset
|
425 |
"invalid netmask in allow option"); |
3aceb4fc0e84
8061228: Allow JDWP socket connector to accept connections from certain ip addresses only
dsamersoff
parents:
46091
diff
changeset
|
426 |
} |
3aceb4fc0e84
8061228: Allow JDWP socket connector to accept connections from certain ip addresses only
dsamersoff
parents:
46091
diff
changeset
|
427 |
} else { |
3aceb4fc0e84
8061228: Allow JDWP socket connector to accept connections from certain ip addresses only
dsamersoff
parents:
46091
diff
changeset
|
428 |
// reset netmask |
3aceb4fc0e84
8061228: Allow JDWP socket connector to accept connections from certain ip addresses only
dsamersoff
parents:
46091
diff
changeset
|
429 |
mask = 0xFFFFFFFF; |
3aceb4fc0e84
8061228: Allow JDWP socket connector to accept connections from certain ip addresses only
dsamersoff
parents:
46091
diff
changeset
|
430 |
} |
3aceb4fc0e84
8061228: Allow JDWP socket connector to accept connections from certain ip addresses only
dsamersoff
parents:
46091
diff
changeset
|
431 |
|
3aceb4fc0e84
8061228: Allow JDWP socket connector to accept connections from certain ip addresses only
dsamersoff
parents:
46091
diff
changeset
|
432 |
if (*s == '+' || *s == 0) { |
3aceb4fc0e84
8061228: Allow JDWP socket connector to accept connections from certain ip addresses only
dsamersoff
parents:
46091
diff
changeset
|
433 |
if (_peers_cnt >= MAX_PEER_ENTRIES) { |
3aceb4fc0e84
8061228: Allow JDWP socket connector to accept connections from certain ip addresses only
dsamersoff
parents:
46091
diff
changeset
|
434 |
fprintf(stderr, "Error in allow option: '%s'\n", allowed_peers); |
3aceb4fc0e84
8061228: Allow JDWP socket connector to accept connections from certain ip addresses only
dsamersoff
parents:
46091
diff
changeset
|
435 |
RETURN_ERROR(JDWPTRANSPORT_ERROR_ILLEGAL_ARGUMENT, |
3aceb4fc0e84
8061228: Allow JDWP socket connector to accept connections from certain ip addresses only
dsamersoff
parents:
46091
diff
changeset
|
436 |
"exceeded max number of allowed peers: " MAX_PEERS_STR); |
3aceb4fc0e84
8061228: Allow JDWP socket connector to accept connections from certain ip addresses only
dsamersoff
parents:
46091
diff
changeset
|
437 |
} |
3aceb4fc0e84
8061228: Allow JDWP socket connector to accept connections from certain ip addresses only
dsamersoff
parents:
46091
diff
changeset
|
438 |
_peers[_peers_cnt].subnet = ip; |
3aceb4fc0e84
8061228: Allow JDWP socket connector to accept connections from certain ip addresses only
dsamersoff
parents:
46091
diff
changeset
|
439 |
_peers[_peers_cnt].netmask = mask; |
3aceb4fc0e84
8061228: Allow JDWP socket connector to accept connections from certain ip addresses only
dsamersoff
parents:
46091
diff
changeset
|
440 |
_peers_cnt++; |
3aceb4fc0e84
8061228: Allow JDWP socket connector to accept connections from certain ip addresses only
dsamersoff
parents:
46091
diff
changeset
|
441 |
if (*s == 0) { |
3aceb4fc0e84
8061228: Allow JDWP socket connector to accept connections from certain ip addresses only
dsamersoff
parents:
46091
diff
changeset
|
442 |
// end of options |
3aceb4fc0e84
8061228: Allow JDWP socket connector to accept connections from certain ip addresses only
dsamersoff
parents:
46091
diff
changeset
|
443 |
break; |
3aceb4fc0e84
8061228: Allow JDWP socket connector to accept connections from certain ip addresses only
dsamersoff
parents:
46091
diff
changeset
|
444 |
} |
3aceb4fc0e84
8061228: Allow JDWP socket connector to accept connections from certain ip addresses only
dsamersoff
parents:
46091
diff
changeset
|
445 |
// advance to next IP block |
3aceb4fc0e84
8061228: Allow JDWP socket connector to accept connections from certain ip addresses only
dsamersoff
parents:
46091
diff
changeset
|
446 |
p = s + 1; |
3aceb4fc0e84
8061228: Allow JDWP socket connector to accept connections from certain ip addresses only
dsamersoff
parents:
46091
diff
changeset
|
447 |
} |
3aceb4fc0e84
8061228: Allow JDWP socket connector to accept connections from certain ip addresses only
dsamersoff
parents:
46091
diff
changeset
|
448 |
} |
3aceb4fc0e84
8061228: Allow JDWP socket connector to accept connections from certain ip addresses only
dsamersoff
parents:
46091
diff
changeset
|
449 |
return JDWPTRANSPORT_ERROR_NONE; |
3aceb4fc0e84
8061228: Allow JDWP socket connector to accept connections from certain ip addresses only
dsamersoff
parents:
46091
diff
changeset
|
450 |
} |
3aceb4fc0e84
8061228: Allow JDWP socket connector to accept connections from certain ip addresses only
dsamersoff
parents:
46091
diff
changeset
|
451 |
|
3aceb4fc0e84
8061228: Allow JDWP socket connector to accept connections from certain ip addresses only
dsamersoff
parents:
46091
diff
changeset
|
452 |
static int |
3aceb4fc0e84
8061228: Allow JDWP socket connector to accept connections from certain ip addresses only
dsamersoff
parents:
46091
diff
changeset
|
453 |
isPeerAllowed(struct sockaddr_in *peer) { |
3aceb4fc0e84
8061228: Allow JDWP socket connector to accept connections from certain ip addresses only
dsamersoff
parents:
46091
diff
changeset
|
454 |
int i; |
3aceb4fc0e84
8061228: Allow JDWP socket connector to accept connections from certain ip addresses only
dsamersoff
parents:
46091
diff
changeset
|
455 |
for (i = 0; i < _peers_cnt; ++i) { |
3aceb4fc0e84
8061228: Allow JDWP socket connector to accept connections from certain ip addresses only
dsamersoff
parents:
46091
diff
changeset
|
456 |
int peer_ip = peer->sin_addr.s_addr; |
3aceb4fc0e84
8061228: Allow JDWP socket connector to accept connections from certain ip addresses only
dsamersoff
parents:
46091
diff
changeset
|
457 |
if (ip_in_subnet(_peers[i].subnet, _peers[i].netmask, peer_ip)) { |
3aceb4fc0e84
8061228: Allow JDWP socket connector to accept connections from certain ip addresses only
dsamersoff
parents:
46091
diff
changeset
|
458 |
return 1; |
3aceb4fc0e84
8061228: Allow JDWP socket connector to accept connections from certain ip addresses only
dsamersoff
parents:
46091
diff
changeset
|
459 |
} |
3aceb4fc0e84
8061228: Allow JDWP socket connector to accept connections from certain ip addresses only
dsamersoff
parents:
46091
diff
changeset
|
460 |
} |
3aceb4fc0e84
8061228: Allow JDWP socket connector to accept connections from certain ip addresses only
dsamersoff
parents:
46091
diff
changeset
|
461 |
|
3aceb4fc0e84
8061228: Allow JDWP socket connector to accept connections from certain ip addresses only
dsamersoff
parents:
46091
diff
changeset
|
462 |
return 0; |
3aceb4fc0e84
8061228: Allow JDWP socket connector to accept connections from certain ip addresses only
dsamersoff
parents:
46091
diff
changeset
|
463 |
} |
2 | 464 |
|
465 |
static jdwpTransportError JNICALL |
|
466 |
socketTransport_getCapabilities(jdwpTransportEnv* env, |
|
467 |
JDWPTransportCapabilities* capabilitiesPtr) |
|
468 |
{ |
|
469 |
JDWPTransportCapabilities result; |
|
470 |
||
471 |
memset(&result, 0, sizeof(result)); |
|
472 |
result.can_timeout_attach = JNI_TRUE; |
|
473 |
result.can_timeout_accept = JNI_TRUE; |
|
474 |
result.can_timeout_handshake = JNI_TRUE; |
|
475 |
||
476 |
*capabilitiesPtr = result; |
|
477 |
||
478 |
return JDWPTRANSPORT_ERROR_NONE; |
|
479 |
} |
|
480 |
||
481 |
||
482 |
static jdwpTransportError JNICALL |
|
483 |
socketTransport_startListening(jdwpTransportEnv* env, const char* address, |
|
484 |
char** actualAddress) |
|
485 |
{ |
|
486 |
struct sockaddr_in sa; |
|
487 |
int err; |
|
488 |
||
489 |
memset((void *)&sa,0,sizeof(struct sockaddr_in)); |
|
490 |
sa.sin_family = AF_INET; |
|
491 |
||
492 |
/* no address provided */ |
|
493 |
if ((address == NULL) || (address[0] == '\0')) { |
|
494 |
address = "0"; |
|
495 |
} |
|
496 |
||
24503
fe24408289d7
8041435: Make JDWP socket connector accept only local connections by default
dsamersoff
parents:
23010
diff
changeset
|
497 |
err = parseAddress(address, &sa); |
2 | 498 |
if (err != JDWPTRANSPORT_ERROR_NONE) { |
499 |
return err; |
|
500 |
} |
|
501 |
||
502 |
serverSocketFD = dbgsysSocket(AF_INET, SOCK_STREAM, 0); |
|
503 |
if (serverSocketFD < 0) { |
|
504 |
RETURN_IO_ERROR("socket creation failed"); |
|
505 |
} |
|
506 |
||
46091
a6f2dc91ba56
8182757: JDWP: Socket Transport handshake hangs on Solaris
gthornbr
parents:
36134
diff
changeset
|
507 |
err = setOptionsCommon(serverSocketFD); |
2 | 508 |
if (err) { |
509 |
return err; |
|
510 |
} |
|
46091
a6f2dc91ba56
8182757: JDWP: Socket Transport handshake hangs on Solaris
gthornbr
parents:
36134
diff
changeset
|
511 |
if (sa.sin_port != 0) { |
a6f2dc91ba56
8182757: JDWP: Socket Transport handshake hangs on Solaris
gthornbr
parents:
36134
diff
changeset
|
512 |
/* |
a6f2dc91ba56
8182757: JDWP: Socket Transport handshake hangs on Solaris
gthornbr
parents:
36134
diff
changeset
|
513 |
* Only need SO_REUSEADDR if we're using a fixed port. If we |
a6f2dc91ba56
8182757: JDWP: Socket Transport handshake hangs on Solaris
gthornbr
parents:
36134
diff
changeset
|
514 |
* start seeing EADDRINUSE due to collisions in free ports |
a6f2dc91ba56
8182757: JDWP: Socket Transport handshake hangs on Solaris
gthornbr
parents:
36134
diff
changeset
|
515 |
* then we should retry the dbgsysBind() a few times. |
a6f2dc91ba56
8182757: JDWP: Socket Transport handshake hangs on Solaris
gthornbr
parents:
36134
diff
changeset
|
516 |
*/ |
a6f2dc91ba56
8182757: JDWP: Socket Transport handshake hangs on Solaris
gthornbr
parents:
36134
diff
changeset
|
517 |
err = setReuseAddrOption(serverSocketFD); |
a6f2dc91ba56
8182757: JDWP: Socket Transport handshake hangs on Solaris
gthornbr
parents:
36134
diff
changeset
|
518 |
if (err) { |
a6f2dc91ba56
8182757: JDWP: Socket Transport handshake hangs on Solaris
gthornbr
parents:
36134
diff
changeset
|
519 |
return err; |
a6f2dc91ba56
8182757: JDWP: Socket Transport handshake hangs on Solaris
gthornbr
parents:
36134
diff
changeset
|
520 |
} |
a6f2dc91ba56
8182757: JDWP: Socket Transport handshake hangs on Solaris
gthornbr
parents:
36134
diff
changeset
|
521 |
} |
2 | 522 |
|
523 |
err = dbgsysBind(serverSocketFD, (struct sockaddr *)&sa, sizeof(sa)); |
|
524 |
if (err < 0) { |
|
525 |
RETURN_IO_ERROR("bind failed"); |
|
526 |
} |
|
527 |
||
528 |
err = dbgsysListen(serverSocketFD, 1); |
|
529 |
if (err < 0) { |
|
530 |
RETURN_IO_ERROR("listen failed"); |
|
531 |
} |
|
532 |
||
533 |
{ |
|
534 |
char buf[20]; |
|
15274
a77cdd5ea6e3
8005120: Compiler warnings in socket transport native code
jzavgren
parents:
14342
diff
changeset
|
535 |
socklen_t len = sizeof(sa); |
2 | 536 |
jint portNum; |
537 |
err = dbgsysGetSocketName(serverSocketFD, |
|
538 |
(struct sockaddr *)&sa, &len); |
|
539 |
portNum = dbgsysNetworkToHostShort(sa.sin_port); |
|
540 |
sprintf(buf, "%d", portNum); |
|
896
5c02031316bf
6725543: Compiler warnings in serviceability native code
ohair
parents:
2
diff
changeset
|
541 |
*actualAddress = (*callback->alloc)((int)strlen(buf) + 1); |
2 | 542 |
if (*actualAddress == NULL) { |
543 |
RETURN_ERROR(JDWPTRANSPORT_ERROR_OUT_OF_MEMORY, "out of memory"); |
|
544 |
} else { |
|
545 |
strcpy(*actualAddress, buf); |
|
546 |
} |
|
547 |
} |
|
548 |
||
549 |
return JDWPTRANSPORT_ERROR_NONE; |
|
550 |
} |
|
551 |
||
552 |
static jdwpTransportError JNICALL |
|
553 |
socketTransport_accept(jdwpTransportEnv* env, jlong acceptTimeout, jlong handshakeTimeout) |
|
554 |
{ |
|
15274
a77cdd5ea6e3
8005120: Compiler warnings in socket transport native code
jzavgren
parents:
14342
diff
changeset
|
555 |
socklen_t socketLen; |
47121
3aceb4fc0e84
8061228: Allow JDWP socket connector to accept connections from certain ip addresses only
dsamersoff
parents:
46091
diff
changeset
|
556 |
int err = JDWPTRANSPORT_ERROR_NONE; |
2 | 557 |
struct sockaddr_in socket; |
558 |
jlong startTime = (jlong)0; |
|
559 |
||
560 |
/* |
|
561 |
* Use a default handshake timeout if not specified - this avoids an indefinite |
|
562 |
* hang in cases where something other than a debugger connects to our port. |
|
563 |
*/ |
|
564 |
if (handshakeTimeout == 0) { |
|
565 |
handshakeTimeout = 2000; |
|
566 |
} |
|
567 |
||
568 |
do { |
|
569 |
/* |
|
570 |
* If there is an accept timeout then we put the socket in non-blocking |
|
571 |
* mode and poll for a connection. |
|
572 |
*/ |
|
573 |
if (acceptTimeout > 0) { |
|
574 |
int rv; |
|
575 |
dbgsysConfigureBlocking(serverSocketFD, JNI_FALSE); |
|
576 |
startTime = dbgsysCurrentTimeMillis(); |
|
577 |
rv = dbgsysPoll(serverSocketFD, JNI_TRUE, JNI_FALSE, (long)acceptTimeout); |
|
578 |
if (rv <= 0) { |
|
579 |
/* set the last error here as could be overridden by configureBlocking */ |
|
580 |
if (rv == 0) { |
|
581 |
setLastError(JDWPTRANSPORT_ERROR_IO_ERROR, "poll failed"); |
|
582 |
} |
|
583 |
/* restore blocking state */ |
|
584 |
dbgsysConfigureBlocking(serverSocketFD, JNI_TRUE); |
|
585 |
if (rv == 0) { |
|
586 |
RETURN_ERROR(JDWPTRANSPORT_ERROR_TIMEOUT, "timed out waiting for connection"); |
|
587 |
} else { |
|
588 |
return JDWPTRANSPORT_ERROR_IO_ERROR; |
|
589 |
} |
|
590 |
} |
|
591 |
} |
|
592 |
||
593 |
/* |
|
594 |
* Accept the connection |
|
595 |
*/ |
|
596 |
memset((void *)&socket,0,sizeof(struct sockaddr_in)); |
|
597 |
socketLen = sizeof(socket); |
|
598 |
socketFD = dbgsysAccept(serverSocketFD, |
|
599 |
(struct sockaddr *)&socket, |
|
600 |
&socketLen); |
|
601 |
/* set the last error here as could be overridden by configureBlocking */ |
|
602 |
if (socketFD < 0) { |
|
603 |
setLastError(JDWPTRANSPORT_ERROR_IO_ERROR, "accept failed"); |
|
604 |
} |
|
605 |
/* |
|
606 |
* Restore the blocking state - note that the accepted socket may be in |
|
607 |
* blocking or non-blocking mode (platform dependent). However as there |
|
608 |
* is a handshake timeout set then it will go into non-blocking mode |
|
609 |
* anyway for the handshake. |
|
610 |
*/ |
|
611 |
if (acceptTimeout > 0) { |
|
612 |
dbgsysConfigureBlocking(serverSocketFD, JNI_TRUE); |
|
613 |
} |
|
614 |
if (socketFD < 0) { |
|
615 |
return JDWPTRANSPORT_ERROR_IO_ERROR; |
|
616 |
} |
|
617 |
||
47121
3aceb4fc0e84
8061228: Allow JDWP socket connector to accept connections from certain ip addresses only
dsamersoff
parents:
46091
diff
changeset
|
618 |
/* |
3aceb4fc0e84
8061228: Allow JDWP socket connector to accept connections from certain ip addresses only
dsamersoff
parents:
46091
diff
changeset
|
619 |
* version >= JDWPTRANSPORT_VERSION_1_1: |
3aceb4fc0e84
8061228: Allow JDWP socket connector to accept connections from certain ip addresses only
dsamersoff
parents:
46091
diff
changeset
|
620 |
* Verify that peer is allowed to connect. |
3aceb4fc0e84
8061228: Allow JDWP socket connector to accept connections from certain ip addresses only
dsamersoff
parents:
46091
diff
changeset
|
621 |
*/ |
3aceb4fc0e84
8061228: Allow JDWP socket connector to accept connections from certain ip addresses only
dsamersoff
parents:
46091
diff
changeset
|
622 |
if (_peers_cnt > 0) { |
3aceb4fc0e84
8061228: Allow JDWP socket connector to accept connections from certain ip addresses only
dsamersoff
parents:
46091
diff
changeset
|
623 |
if (!isPeerAllowed(&socket)) { |
3aceb4fc0e84
8061228: Allow JDWP socket connector to accept connections from certain ip addresses only
dsamersoff
parents:
46091
diff
changeset
|
624 |
char ebuf[64] = { 0 }; |
3aceb4fc0e84
8061228: Allow JDWP socket connector to accept connections from certain ip addresses only
dsamersoff
parents:
46091
diff
changeset
|
625 |
char buf[INET_ADDRSTRLEN] = { 0 }; |
3aceb4fc0e84
8061228: Allow JDWP socket connector to accept connections from certain ip addresses only
dsamersoff
parents:
46091
diff
changeset
|
626 |
const char* addr_str = inet_ntop(AF_INET, &(socket.sin_addr), buf, INET_ADDRSTRLEN); |
3aceb4fc0e84
8061228: Allow JDWP socket connector to accept connections from certain ip addresses only
dsamersoff
parents:
46091
diff
changeset
|
627 |
sprintf(ebuf, "ERROR: Peer not allowed to connect: %s\n", |
3aceb4fc0e84
8061228: Allow JDWP socket connector to accept connections from certain ip addresses only
dsamersoff
parents:
46091
diff
changeset
|
628 |
(addr_str == NULL) ? "<bad address>" : addr_str); |
3aceb4fc0e84
8061228: Allow JDWP socket connector to accept connections from certain ip addresses only
dsamersoff
parents:
46091
diff
changeset
|
629 |
dbgsysSocketClose(socketFD); |
3aceb4fc0e84
8061228: Allow JDWP socket connector to accept connections from certain ip addresses only
dsamersoff
parents:
46091
diff
changeset
|
630 |
socketFD = -1; |
3aceb4fc0e84
8061228: Allow JDWP socket connector to accept connections from certain ip addresses only
dsamersoff
parents:
46091
diff
changeset
|
631 |
err = JDWPTRANSPORT_ERROR_ILLEGAL_ARGUMENT; |
3aceb4fc0e84
8061228: Allow JDWP socket connector to accept connections from certain ip addresses only
dsamersoff
parents:
46091
diff
changeset
|
632 |
setLastError(err, ebuf); |
3aceb4fc0e84
8061228: Allow JDWP socket connector to accept connections from certain ip addresses only
dsamersoff
parents:
46091
diff
changeset
|
633 |
} |
3aceb4fc0e84
8061228: Allow JDWP socket connector to accept connections from certain ip addresses only
dsamersoff
parents:
46091
diff
changeset
|
634 |
} |
3aceb4fc0e84
8061228: Allow JDWP socket connector to accept connections from certain ip addresses only
dsamersoff
parents:
46091
diff
changeset
|
635 |
|
3aceb4fc0e84
8061228: Allow JDWP socket connector to accept connections from certain ip addresses only
dsamersoff
parents:
46091
diff
changeset
|
636 |
if (socketFD > 0) { |
3aceb4fc0e84
8061228: Allow JDWP socket connector to accept connections from certain ip addresses only
dsamersoff
parents:
46091
diff
changeset
|
637 |
/* handshake with the debugger */ |
3aceb4fc0e84
8061228: Allow JDWP socket connector to accept connections from certain ip addresses only
dsamersoff
parents:
46091
diff
changeset
|
638 |
err = handshake(socketFD, handshakeTimeout); |
3aceb4fc0e84
8061228: Allow JDWP socket connector to accept connections from certain ip addresses only
dsamersoff
parents:
46091
diff
changeset
|
639 |
} |
2 | 640 |
|
641 |
/* |
|
642 |
* If the handshake fails then close the connection. If there if an accept |
|
643 |
* timeout then we must adjust the timeout for the next poll. |
|
644 |
*/ |
|
47121
3aceb4fc0e84
8061228: Allow JDWP socket connector to accept connections from certain ip addresses only
dsamersoff
parents:
46091
diff
changeset
|
645 |
if (err != JDWPTRANSPORT_ERROR_NONE) { |
2 | 646 |
fprintf(stderr, "Debugger failed to attach: %s\n", getLastError()); |
647 |
dbgsysSocketClose(socketFD); |
|
648 |
socketFD = -1; |
|
649 |
if (acceptTimeout > 0) { |
|
650 |
long endTime = dbgsysCurrentTimeMillis(); |
|
651 |
acceptTimeout -= (endTime - startTime); |
|
652 |
if (acceptTimeout <= 0) { |
|
653 |
setLastError(JDWPTRANSPORT_ERROR_IO_ERROR, |
|
654 |
"timeout waiting for debugger to connect"); |
|
655 |
return JDWPTRANSPORT_ERROR_IO_ERROR; |
|
656 |
} |
|
657 |
} |
|
658 |
} |
|
659 |
} while (socketFD < 0); |
|
660 |
||
661 |
return JDWPTRANSPORT_ERROR_NONE; |
|
662 |
} |
|
663 |
||
664 |
static jdwpTransportError JNICALL |
|
665 |
socketTransport_stopListening(jdwpTransportEnv *env) |
|
666 |
{ |
|
667 |
if (serverSocketFD < 0) { |
|
668 |
RETURN_ERROR(JDWPTRANSPORT_ERROR_ILLEGAL_STATE, "connection not open"); |
|
669 |
} |
|
670 |
if (dbgsysSocketClose(serverSocketFD) < 0) { |
|
671 |
RETURN_IO_ERROR("close failed"); |
|
672 |
} |
|
673 |
serverSocketFD = -1; |
|
674 |
return JDWPTRANSPORT_ERROR_NONE; |
|
675 |
} |
|
676 |
||
677 |
static jdwpTransportError JNICALL |
|
678 |
socketTransport_attach(jdwpTransportEnv* env, const char* addressString, jlong attachTimeout, |
|
679 |
jlong handshakeTimeout) |
|
680 |
{ |
|
681 |
struct sockaddr_in sa; |
|
682 |
int err; |
|
683 |
||
684 |
if (addressString == NULL || addressString[0] == '\0') { |
|
685 |
RETURN_ERROR(JDWPTRANSPORT_ERROR_ILLEGAL_ARGUMENT, "address is missing"); |
|
686 |
} |
|
687 |
||
24503
fe24408289d7
8041435: Make JDWP socket connector accept only local connections by default
dsamersoff
parents:
23010
diff
changeset
|
688 |
err = parseAddress(addressString, &sa); |
2 | 689 |
if (err != JDWPTRANSPORT_ERROR_NONE) { |
690 |
return err; |
|
691 |
} |
|
692 |
||
693 |
socketFD = dbgsysSocket(AF_INET, SOCK_STREAM, 0); |
|
694 |
if (socketFD < 0) { |
|
695 |
RETURN_IO_ERROR("unable to create socket"); |
|
696 |
} |
|
697 |
||
46091
a6f2dc91ba56
8182757: JDWP: Socket Transport handshake hangs on Solaris
gthornbr
parents:
36134
diff
changeset
|
698 |
err = setOptionsCommon(socketFD); |
2 | 699 |
if (err) { |
700 |
return err; |
|
701 |
} |
|
702 |
||
703 |
/* |
|
46091
a6f2dc91ba56
8182757: JDWP: Socket Transport handshake hangs on Solaris
gthornbr
parents:
36134
diff
changeset
|
704 |
* We don't call setReuseAddrOption() for the non-server socket |
a6f2dc91ba56
8182757: JDWP: Socket Transport handshake hangs on Solaris
gthornbr
parents:
36134
diff
changeset
|
705 |
* case. If we start seeing EADDRINUSE due to collisions in free |
a6f2dc91ba56
8182757: JDWP: Socket Transport handshake hangs on Solaris
gthornbr
parents:
36134
diff
changeset
|
706 |
* ports then we should retry the dbgsysConnect() a few times. |
a6f2dc91ba56
8182757: JDWP: Socket Transport handshake hangs on Solaris
gthornbr
parents:
36134
diff
changeset
|
707 |
*/ |
a6f2dc91ba56
8182757: JDWP: Socket Transport handshake hangs on Solaris
gthornbr
parents:
36134
diff
changeset
|
708 |
|
a6f2dc91ba56
8182757: JDWP: Socket Transport handshake hangs on Solaris
gthornbr
parents:
36134
diff
changeset
|
709 |
/* |
2 | 710 |
* To do a timed connect we make the socket non-blocking |
711 |
* and poll with a timeout; |
|
712 |
*/ |
|
713 |
if (attachTimeout > 0) { |
|
714 |
dbgsysConfigureBlocking(socketFD, JNI_FALSE); |
|
715 |
} |
|
716 |
||
717 |
err = dbgsysConnect(socketFD, (struct sockaddr *)&sa, sizeof(sa)); |
|
718 |
if (err == DBG_EINPROGRESS && attachTimeout > 0) { |
|
719 |
err = dbgsysFinishConnect(socketFD, (long)attachTimeout); |
|
720 |
||
721 |
if (err == DBG_ETIMEOUT) { |
|
722 |
dbgsysConfigureBlocking(socketFD, JNI_TRUE); |
|
723 |
RETURN_ERROR(JDWPTRANSPORT_ERROR_TIMEOUT, "connect timed out"); |
|
724 |
} |
|
725 |
} |
|
726 |
||
727 |
if (err < 0) { |
|
728 |
RETURN_IO_ERROR("connect failed"); |
|
729 |
} |
|
730 |
||
731 |
if (attachTimeout > 0) { |
|
732 |
dbgsysConfigureBlocking(socketFD, JNI_TRUE); |
|
733 |
} |
|
734 |
||
735 |
err = handshake(socketFD, handshakeTimeout); |
|
736 |
if (err) { |
|
737 |
dbgsysSocketClose(socketFD); |
|
738 |
socketFD = -1; |
|
739 |
return err; |
|
740 |
} |
|
741 |
||
742 |
return JDWPTRANSPORT_ERROR_NONE; |
|
743 |
} |
|
744 |
||
745 |
static jboolean JNICALL |
|
746 |
socketTransport_isOpen(jdwpTransportEnv* env) |
|
747 |
{ |
|
748 |
if (socketFD >= 0) { |
|
749 |
return JNI_TRUE; |
|
750 |
} else { |
|
751 |
return JNI_FALSE; |
|
752 |
} |
|
753 |
} |
|
754 |
||
755 |
static jdwpTransportError JNICALL |
|
756 |
socketTransport_close(jdwpTransportEnv* env) |
|
757 |
{ |
|
758 |
int fd = socketFD; |
|
759 |
socketFD = -1; |
|
760 |
if (fd < 0) { |
|
761 |
return JDWPTRANSPORT_ERROR_NONE; |
|
762 |
} |
|
22605
dba3d6b22818
8031581: PPC64: Addons and fixes for AIX to pass the jdk regression tests
simonis
parents:
15274
diff
changeset
|
763 |
#ifdef _AIX |
dba3d6b22818
8031581: PPC64: Addons and fixes for AIX to pass the jdk regression tests
simonis
parents:
15274
diff
changeset
|
764 |
/* |
dba3d6b22818
8031581: PPC64: Addons and fixes for AIX to pass the jdk regression tests
simonis
parents:
15274
diff
changeset
|
765 |
AIX needs a workaround for I/O cancellation, see: |
dba3d6b22818
8031581: PPC64: Addons and fixes for AIX to pass the jdk regression tests
simonis
parents:
15274
diff
changeset
|
766 |
http://publib.boulder.ibm.com/infocenter/pseries/v5r3/index.jsp?topic=/com.ibm.aix.basetechref/doc/basetrf1/close.htm |
dba3d6b22818
8031581: PPC64: Addons and fixes for AIX to pass the jdk regression tests
simonis
parents:
15274
diff
changeset
|
767 |
... |
dba3d6b22818
8031581: PPC64: Addons and fixes for AIX to pass the jdk regression tests
simonis
parents:
15274
diff
changeset
|
768 |
The close subroutine is blocked until all subroutines which use the file |
dba3d6b22818
8031581: PPC64: Addons and fixes for AIX to pass the jdk regression tests
simonis
parents:
15274
diff
changeset
|
769 |
descriptor return to usr space. For example, when a thread is calling close |
dba3d6b22818
8031581: PPC64: Addons and fixes for AIX to pass the jdk regression tests
simonis
parents:
15274
diff
changeset
|
770 |
and another thread is calling select with the same file descriptor, the |
dba3d6b22818
8031581: PPC64: Addons and fixes for AIX to pass the jdk regression tests
simonis
parents:
15274
diff
changeset
|
771 |
close subroutine does not return until the select call returns. |
dba3d6b22818
8031581: PPC64: Addons and fixes for AIX to pass the jdk regression tests
simonis
parents:
15274
diff
changeset
|
772 |
... |
dba3d6b22818
8031581: PPC64: Addons and fixes for AIX to pass the jdk regression tests
simonis
parents:
15274
diff
changeset
|
773 |
*/ |
dba3d6b22818
8031581: PPC64: Addons and fixes for AIX to pass the jdk regression tests
simonis
parents:
15274
diff
changeset
|
774 |
shutdown(fd, 2); |
dba3d6b22818
8031581: PPC64: Addons and fixes for AIX to pass the jdk regression tests
simonis
parents:
15274
diff
changeset
|
775 |
#endif |
2 | 776 |
if (dbgsysSocketClose(fd) < 0) { |
777 |
/* |
|
778 |
* close failed - it's pointless to restore socketFD here because |
|
15274
a77cdd5ea6e3
8005120: Compiler warnings in socket transport native code
jzavgren
parents:
14342
diff
changeset
|
779 |
* any subsequent close will likely fail as well. |
2 | 780 |
*/ |
781 |
RETURN_IO_ERROR("close failed"); |
|
782 |
} |
|
783 |
return JDWPTRANSPORT_ERROR_NONE; |
|
784 |
} |
|
785 |
||
786 |
static jdwpTransportError JNICALL |
|
787 |
socketTransport_writePacket(jdwpTransportEnv* env, const jdwpPacket *packet) |
|
788 |
{ |
|
789 |
jint len, data_len, id; |
|
790 |
/* |
|
791 |
* room for header and up to MAX_DATA_SIZE data bytes |
|
792 |
*/ |
|
793 |
char header[HEADER_SIZE + MAX_DATA_SIZE]; |
|
794 |
jbyte *data; |
|
795 |
||
796 |
/* packet can't be null */ |
|
797 |
if (packet == NULL) { |
|
798 |
RETURN_ERROR(JDWPTRANSPORT_ERROR_ILLEGAL_ARGUMENT, "packet is NULL"); |
|
799 |
} |
|
800 |
||
801 |
len = packet->type.cmd.len; /* includes header */ |
|
802 |
data_len = len - HEADER_SIZE; |
|
803 |
||
804 |
/* bad packet */ |
|
805 |
if (data_len < 0) { |
|
806 |
RETURN_ERROR(JDWPTRANSPORT_ERROR_ILLEGAL_ARGUMENT, "invalid length"); |
|
807 |
} |
|
808 |
||
809 |
/* prepare the header for transmission */ |
|
810 |
len = (jint)dbgsysHostToNetworkLong(len); |
|
811 |
id = (jint)dbgsysHostToNetworkLong(packet->type.cmd.id); |
|
812 |
||
813 |
memcpy(header + 0, &len, 4); |
|
814 |
memcpy(header + 4, &id, 4); |
|
815 |
header[8] = packet->type.cmd.flags; |
|
816 |
if (packet->type.cmd.flags & JDWPTRANSPORT_FLAGS_REPLY) { |
|
817 |
jshort errorCode = |
|
818 |
dbgsysHostToNetworkShort(packet->type.reply.errorCode); |
|
819 |
memcpy(header + 9, &errorCode, 2); |
|
820 |
} else { |
|
821 |
header[9] = packet->type.cmd.cmdSet; |
|
822 |
header[10] = packet->type.cmd.cmd; |
|
823 |
} |
|
824 |
||
825 |
data = packet->type.cmd.data; |
|
826 |
/* Do one send for short packets, two for longer ones */ |
|
827 |
if (data_len <= MAX_DATA_SIZE) { |
|
828 |
memcpy(header + HEADER_SIZE, data, data_len); |
|
12047
320a714614e9
7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
5506
diff
changeset
|
829 |
if (send_fully(socketFD, (char *)&header, HEADER_SIZE + data_len) != |
2 | 830 |
HEADER_SIZE + data_len) { |
831 |
RETURN_IO_ERROR("send failed"); |
|
832 |
} |
|
833 |
} else { |
|
834 |
memcpy(header + HEADER_SIZE, data, MAX_DATA_SIZE); |
|
12047
320a714614e9
7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
5506
diff
changeset
|
835 |
if (send_fully(socketFD, (char *)&header, HEADER_SIZE + MAX_DATA_SIZE) != |
2 | 836 |
HEADER_SIZE + MAX_DATA_SIZE) { |
837 |
RETURN_IO_ERROR("send failed"); |
|
838 |
} |
|
839 |
/* Send the remaining data bytes right out of the data area. */ |
|
12047
320a714614e9
7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
5506
diff
changeset
|
840 |
if (send_fully(socketFD, (char *)data + MAX_DATA_SIZE, |
320a714614e9
7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
5506
diff
changeset
|
841 |
data_len - MAX_DATA_SIZE) != data_len - MAX_DATA_SIZE) { |
2 | 842 |
RETURN_IO_ERROR("send failed"); |
843 |
} |
|
844 |
} |
|
845 |
||
846 |
return JDWPTRANSPORT_ERROR_NONE; |
|
847 |
} |
|
848 |
||
849 |
static jint |
|
850 |
recv_fully(int f, char *buf, int len) |
|
851 |
{ |
|
852 |
int nbytes = 0; |
|
853 |
while (nbytes < len) { |
|
854 |
int res = dbgsysRecv(f, buf + nbytes, len - nbytes, 0); |
|
855 |
if (res < 0) { |
|
856 |
return res; |
|
857 |
} else if (res == 0) { |
|
858 |
break; /* eof, return nbytes which is less than len */ |
|
859 |
} |
|
860 |
nbytes += res; |
|
861 |
} |
|
862 |
return nbytes; |
|
863 |
} |
|
864 |
||
12047
320a714614e9
7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
5506
diff
changeset
|
865 |
jint |
320a714614e9
7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
5506
diff
changeset
|
866 |
send_fully(int f, char *buf, int len) |
320a714614e9
7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
5506
diff
changeset
|
867 |
{ |
320a714614e9
7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
5506
diff
changeset
|
868 |
int nbytes = 0; |
320a714614e9
7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
5506
diff
changeset
|
869 |
while (nbytes < len) { |
320a714614e9
7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
5506
diff
changeset
|
870 |
int res = dbgsysSend(f, buf + nbytes, len - nbytes, 0); |
320a714614e9
7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
5506
diff
changeset
|
871 |
if (res < 0) { |
320a714614e9
7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
5506
diff
changeset
|
872 |
return res; |
320a714614e9
7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
5506
diff
changeset
|
873 |
} else if (res == 0) { |
320a714614e9
7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
5506
diff
changeset
|
874 |
break; /* eof, return nbytes which is less than len */ |
320a714614e9
7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
5506
diff
changeset
|
875 |
} |
320a714614e9
7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
5506
diff
changeset
|
876 |
nbytes += res; |
320a714614e9
7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
5506
diff
changeset
|
877 |
} |
320a714614e9
7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
5506
diff
changeset
|
878 |
return nbytes; |
320a714614e9
7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
5506
diff
changeset
|
879 |
} |
320a714614e9
7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
5506
diff
changeset
|
880 |
|
2 | 881 |
static jdwpTransportError JNICALL |
882 |
socketTransport_readPacket(jdwpTransportEnv* env, jdwpPacket* packet) { |
|
883 |
jint length, data_len; |
|
884 |
jint n; |
|
885 |
||
886 |
/* packet can't be null */ |
|
887 |
if (packet == NULL) { |
|
888 |
RETURN_ERROR(JDWPTRANSPORT_ERROR_ILLEGAL_ARGUMENT, "packet is null"); |
|
889 |
} |
|
890 |
||
891 |
/* read the length field */ |
|
892 |
n = recv_fully(socketFD, (char *)&length, sizeof(jint)); |
|
893 |
||
894 |
/* check for EOF */ |
|
895 |
if (n == 0) { |
|
896 |
packet->type.cmd.len = 0; |
|
897 |
return JDWPTRANSPORT_ERROR_NONE; |
|
898 |
} |
|
899 |
if (n != sizeof(jint)) { |
|
900 |
RETURN_RECV_ERROR(n); |
|
901 |
} |
|
902 |
||
903 |
length = (jint)dbgsysNetworkToHostLong(length); |
|
904 |
packet->type.cmd.len = length; |
|
905 |
||
906 |
||
47121
3aceb4fc0e84
8061228: Allow JDWP socket connector to accept connections from certain ip addresses only
dsamersoff
parents:
46091
diff
changeset
|
907 |
n = recv_fully(socketFD,(char *)&(packet->type.cmd.id), sizeof(jint)); |
2 | 908 |
if (n < (int)sizeof(jint)) { |
909 |
RETURN_RECV_ERROR(n); |
|
910 |
} |
|
911 |
||
912 |
packet->type.cmd.id = (jint)dbgsysNetworkToHostLong(packet->type.cmd.id); |
|
913 |
||
47121
3aceb4fc0e84
8061228: Allow JDWP socket connector to accept connections from certain ip addresses only
dsamersoff
parents:
46091
diff
changeset
|
914 |
n = recv_fully(socketFD,(char *)&(packet->type.cmd.flags), sizeof(jbyte)); |
2 | 915 |
if (n < (int)sizeof(jbyte)) { |
916 |
RETURN_RECV_ERROR(n); |
|
917 |
} |
|
918 |
||
919 |
if (packet->type.cmd.flags & JDWPTRANSPORT_FLAGS_REPLY) { |
|
47121
3aceb4fc0e84
8061228: Allow JDWP socket connector to accept connections from certain ip addresses only
dsamersoff
parents:
46091
diff
changeset
|
920 |
n = recv_fully(socketFD,(char *)&(packet->type.reply.errorCode), sizeof(jbyte)); |
2 | 921 |
if (n < (int)sizeof(jshort)) { |
922 |
RETURN_RECV_ERROR(n); |
|
923 |
} |
|
924 |
||
925 |
/* FIXME - should the error be converted to host order?? */ |
|
926 |
||
927 |
||
928 |
} else { |
|
47121
3aceb4fc0e84
8061228: Allow JDWP socket connector to accept connections from certain ip addresses only
dsamersoff
parents:
46091
diff
changeset
|
929 |
n = recv_fully(socketFD,(char *)&(packet->type.cmd.cmdSet), sizeof(jbyte)); |
2 | 930 |
if (n < (int)sizeof(jbyte)) { |
931 |
RETURN_RECV_ERROR(n); |
|
932 |
} |
|
933 |
||
47121
3aceb4fc0e84
8061228: Allow JDWP socket connector to accept connections from certain ip addresses only
dsamersoff
parents:
46091
diff
changeset
|
934 |
n = recv_fully(socketFD,(char *)&(packet->type.cmd.cmd), sizeof(jbyte)); |
2 | 935 |
if (n < (int)sizeof(jbyte)) { |
936 |
RETURN_RECV_ERROR(n); |
|
937 |
} |
|
938 |
} |
|
939 |
||
940 |
data_len = length - ((sizeof(jint) * 2) + (sizeof(jbyte) * 3)); |
|
941 |
||
942 |
if (data_len < 0) { |
|
943 |
setLastError(0, "Badly formed packet received - invalid length"); |
|
944 |
return JDWPTRANSPORT_ERROR_IO_ERROR; |
|
945 |
} else if (data_len == 0) { |
|
946 |
packet->type.cmd.data = NULL; |
|
947 |
} else { |
|
948 |
packet->type.cmd.data= (*callback->alloc)(data_len); |
|
949 |
||
950 |
if (packet->type.cmd.data == NULL) { |
|
951 |
RETURN_ERROR(JDWPTRANSPORT_ERROR_OUT_OF_MEMORY, "out of memory"); |
|
952 |
} |
|
953 |
||
954 |
n = recv_fully(socketFD,(char *)packet->type.cmd.data, data_len); |
|
955 |
if (n < data_len) { |
|
956 |
(*callback->free)(packet->type.cmd.data); |
|
957 |
RETURN_RECV_ERROR(n); |
|
958 |
} |
|
959 |
} |
|
960 |
||
961 |
return JDWPTRANSPORT_ERROR_NONE; |
|
962 |
} |
|
963 |
||
964 |
static jdwpTransportError JNICALL |
|
965 |
socketTransport_getLastError(jdwpTransportEnv* env, char** msgP) { |
|
966 |
char *msg = (char *)dbgsysTlsGet(tlsIndex); |
|
967 |
if (msg == NULL) { |
|
968 |
return JDWPTRANSPORT_ERROR_MSG_NOT_AVAILABLE; |
|
969 |
} |
|
896
5c02031316bf
6725543: Compiler warnings in serviceability native code
ohair
parents:
2
diff
changeset
|
970 |
*msgP = (*callback->alloc)((int)strlen(msg)+1); |
2 | 971 |
if (*msgP == NULL) { |
972 |
return JDWPTRANSPORT_ERROR_OUT_OF_MEMORY; |
|
973 |
} |
|
974 |
strcpy(*msgP, msg); |
|
975 |
return JDWPTRANSPORT_ERROR_NONE; |
|
976 |
} |
|
977 |
||
47121
3aceb4fc0e84
8061228: Allow JDWP socket connector to accept connections from certain ip addresses only
dsamersoff
parents:
46091
diff
changeset
|
978 |
static jdwpTransportError JNICALL |
3aceb4fc0e84
8061228: Allow JDWP socket connector to accept connections from certain ip addresses only
dsamersoff
parents:
46091
diff
changeset
|
979 |
socketTransport_setConfiguration(jdwpTransportEnv* env, jdwpTransportConfiguration* cfg) { |
3aceb4fc0e84
8061228: Allow JDWP socket connector to accept connections from certain ip addresses only
dsamersoff
parents:
46091
diff
changeset
|
980 |
const char* allowed_peers = NULL; |
3aceb4fc0e84
8061228: Allow JDWP socket connector to accept connections from certain ip addresses only
dsamersoff
parents:
46091
diff
changeset
|
981 |
|
3aceb4fc0e84
8061228: Allow JDWP socket connector to accept connections from certain ip addresses only
dsamersoff
parents:
46091
diff
changeset
|
982 |
if (cfg == NULL) { |
3aceb4fc0e84
8061228: Allow JDWP socket connector to accept connections from certain ip addresses only
dsamersoff
parents:
46091
diff
changeset
|
983 |
RETURN_ERROR(JDWPTRANSPORT_ERROR_ILLEGAL_ARGUMENT, |
3aceb4fc0e84
8061228: Allow JDWP socket connector to accept connections from certain ip addresses only
dsamersoff
parents:
46091
diff
changeset
|
984 |
"NULL pointer to transport configuration is invalid"); |
3aceb4fc0e84
8061228: Allow JDWP socket connector to accept connections from certain ip addresses only
dsamersoff
parents:
46091
diff
changeset
|
985 |
} |
3aceb4fc0e84
8061228: Allow JDWP socket connector to accept connections from certain ip addresses only
dsamersoff
parents:
46091
diff
changeset
|
986 |
allowed_peers = cfg->allowed_peers; |
3aceb4fc0e84
8061228: Allow JDWP socket connector to accept connections from certain ip addresses only
dsamersoff
parents:
46091
diff
changeset
|
987 |
_peers_cnt = 0; |
3aceb4fc0e84
8061228: Allow JDWP socket connector to accept connections from certain ip addresses only
dsamersoff
parents:
46091
diff
changeset
|
988 |
if (allowed_peers != NULL) { |
3aceb4fc0e84
8061228: Allow JDWP socket connector to accept connections from certain ip addresses only
dsamersoff
parents:
46091
diff
changeset
|
989 |
size_t len = strlen(allowed_peers); |
3aceb4fc0e84
8061228: Allow JDWP socket connector to accept connections from certain ip addresses only
dsamersoff
parents:
46091
diff
changeset
|
990 |
if (len == 0) { /* Impossible: parseOptions() would reject it */ |
3aceb4fc0e84
8061228: Allow JDWP socket connector to accept connections from certain ip addresses only
dsamersoff
parents:
46091
diff
changeset
|
991 |
fprintf(stderr, "Error in allow option: '%s'\n", allowed_peers); |
3aceb4fc0e84
8061228: Allow JDWP socket connector to accept connections from certain ip addresses only
dsamersoff
parents:
46091
diff
changeset
|
992 |
RETURN_ERROR(JDWPTRANSPORT_ERROR_ILLEGAL_ARGUMENT, |
3aceb4fc0e84
8061228: Allow JDWP socket connector to accept connections from certain ip addresses only
dsamersoff
parents:
46091
diff
changeset
|
993 |
"allow option should not be empty"); |
3aceb4fc0e84
8061228: Allow JDWP socket connector to accept connections from certain ip addresses only
dsamersoff
parents:
46091
diff
changeset
|
994 |
} else if (*allowed_peers == '*') { |
3aceb4fc0e84
8061228: Allow JDWP socket connector to accept connections from certain ip addresses only
dsamersoff
parents:
46091
diff
changeset
|
995 |
if (len != 1) { |
3aceb4fc0e84
8061228: Allow JDWP socket connector to accept connections from certain ip addresses only
dsamersoff
parents:
46091
diff
changeset
|
996 |
fprintf(stderr, "Error in allow option: '%s'\n", allowed_peers); |
3aceb4fc0e84
8061228: Allow JDWP socket connector to accept connections from certain ip addresses only
dsamersoff
parents:
46091
diff
changeset
|
997 |
RETURN_ERROR(JDWPTRANSPORT_ERROR_ILLEGAL_ARGUMENT, |
3aceb4fc0e84
8061228: Allow JDWP socket connector to accept connections from certain ip addresses only
dsamersoff
parents:
46091
diff
changeset
|
998 |
"allow option '*' cannot be expanded"); |
3aceb4fc0e84
8061228: Allow JDWP socket connector to accept connections from certain ip addresses only
dsamersoff
parents:
46091
diff
changeset
|
999 |
} |
3aceb4fc0e84
8061228: Allow JDWP socket connector to accept connections from certain ip addresses only
dsamersoff
parents:
46091
diff
changeset
|
1000 |
} else { |
3aceb4fc0e84
8061228: Allow JDWP socket connector to accept connections from certain ip addresses only
dsamersoff
parents:
46091
diff
changeset
|
1001 |
int err = parseAllowedPeers(allowed_peers); |
3aceb4fc0e84
8061228: Allow JDWP socket connector to accept connections from certain ip addresses only
dsamersoff
parents:
46091
diff
changeset
|
1002 |
if (err != JDWPTRANSPORT_ERROR_NONE) { |
3aceb4fc0e84
8061228: Allow JDWP socket connector to accept connections from certain ip addresses only
dsamersoff
parents:
46091
diff
changeset
|
1003 |
return err; |
3aceb4fc0e84
8061228: Allow JDWP socket connector to accept connections from certain ip addresses only
dsamersoff
parents:
46091
diff
changeset
|
1004 |
} |
3aceb4fc0e84
8061228: Allow JDWP socket connector to accept connections from certain ip addresses only
dsamersoff
parents:
46091
diff
changeset
|
1005 |
} |
3aceb4fc0e84
8061228: Allow JDWP socket connector to accept connections from certain ip addresses only
dsamersoff
parents:
46091
diff
changeset
|
1006 |
} |
3aceb4fc0e84
8061228: Allow JDWP socket connector to accept connections from certain ip addresses only
dsamersoff
parents:
46091
diff
changeset
|
1007 |
return JDWPTRANSPORT_ERROR_NONE; |
3aceb4fc0e84
8061228: Allow JDWP socket connector to accept connections from certain ip addresses only
dsamersoff
parents:
46091
diff
changeset
|
1008 |
} |
3aceb4fc0e84
8061228: Allow JDWP socket connector to accept connections from certain ip addresses only
dsamersoff
parents:
46091
diff
changeset
|
1009 |
|
36134 | 1010 |
jint JNICALL |
2 | 1011 |
jdwpTransport_OnLoad(JavaVM *vm, jdwpTransportCallback* cbTablePtr, |
47121
3aceb4fc0e84
8061228: Allow JDWP socket connector to accept connections from certain ip addresses only
dsamersoff
parents:
46091
diff
changeset
|
1012 |
jint version, jdwpTransportEnv** env) |
2 | 1013 |
{ |
47121
3aceb4fc0e84
8061228: Allow JDWP socket connector to accept connections from certain ip addresses only
dsamersoff
parents:
46091
diff
changeset
|
1014 |
if (version < JDWPTRANSPORT_VERSION_1_0 || |
3aceb4fc0e84
8061228: Allow JDWP socket connector to accept connections from certain ip addresses only
dsamersoff
parents:
46091
diff
changeset
|
1015 |
version > JDWPTRANSPORT_VERSION_1_1) { |
2 | 1016 |
return JNI_EVERSION; |
1017 |
} |
|
1018 |
if (initialized) { |
|
1019 |
/* |
|
1020 |
* This library doesn't support multiple environments (yet) |
|
1021 |
*/ |
|
1022 |
return JNI_EEXIST; |
|
1023 |
} |
|
1024 |
initialized = JNI_TRUE; |
|
1025 |
jvm = vm; |
|
1026 |
callback = cbTablePtr; |
|
1027 |
||
1028 |
/* initialize interface table */ |
|
1029 |
interface.GetCapabilities = &socketTransport_getCapabilities; |
|
1030 |
interface.Attach = &socketTransport_attach; |
|
1031 |
interface.StartListening = &socketTransport_startListening; |
|
1032 |
interface.StopListening = &socketTransport_stopListening; |
|
1033 |
interface.Accept = &socketTransport_accept; |
|
1034 |
interface.IsOpen = &socketTransport_isOpen; |
|
1035 |
interface.Close = &socketTransport_close; |
|
1036 |
interface.ReadPacket = &socketTransport_readPacket; |
|
1037 |
interface.WritePacket = &socketTransport_writePacket; |
|
1038 |
interface.GetLastError = &socketTransport_getLastError; |
|
47121
3aceb4fc0e84
8061228: Allow JDWP socket connector to accept connections from certain ip addresses only
dsamersoff
parents:
46091
diff
changeset
|
1039 |
if (version >= JDWPTRANSPORT_VERSION_1_1) { |
3aceb4fc0e84
8061228: Allow JDWP socket connector to accept connections from certain ip addresses only
dsamersoff
parents:
46091
diff
changeset
|
1040 |
interface.SetTransportConfiguration = &socketTransport_setConfiguration; |
3aceb4fc0e84
8061228: Allow JDWP socket connector to accept connections from certain ip addresses only
dsamersoff
parents:
46091
diff
changeset
|
1041 |
} |
3aceb4fc0e84
8061228: Allow JDWP socket connector to accept connections from certain ip addresses only
dsamersoff
parents:
46091
diff
changeset
|
1042 |
*env = &single_env; |
2 | 1043 |
|
1044 |
/* initialized TLS */ |
|
1045 |
tlsIndex = dbgsysTlsAlloc(); |
|
1046 |
return JNI_OK; |
|
1047 |
} |