author | michaelm |
Thu, 04 May 2017 18:13:42 +0100 | |
changeset 44921 | 0672237e13c0 |
parent 44916 | 54d70322b32c |
child 45061 | 74b09ee3cd55 |
permissions | -rw-r--r-- |
2 | 1 |
/* |
44921
0672237e13c0
8179602: Backout fix for JDK-8165437 due to breakage on 32-bit Linux
michaelm
parents:
44916
diff
changeset
|
2 |
* Copyright (c) 1997, 2016, 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 |
*/ |
41771
18c9669e76ca
8167481: cleanup of headers and includes for native libnet
clanger
parents:
41578
diff
changeset
|
25 |
#include <dlfcn.h> |
2 | 26 |
#include <errno.h> |
41771
18c9669e76ca
8167481: cleanup of headers and includes for native libnet
clanger
parents:
41578
diff
changeset
|
27 |
#include <net/if.h> |
18c9669e76ca
8167481: cleanup of headers and includes for native libnet
clanger
parents:
41578
diff
changeset
|
28 |
#include <netinet/tcp.h> // defines TCP_NODELAY |
18c9669e76ca
8167481: cleanup of headers and includes for native libnet
clanger
parents:
41578
diff
changeset
|
29 |
#include <stdlib.h> |
2 | 30 |
#include <string.h> |
41771
18c9669e76ca
8167481: cleanup of headers and includes for native libnet
clanger
parents:
41578
diff
changeset
|
31 |
#include <sys/ioctl.h> |
40937
f72e61ec734b
8075484: SocketInputStream.socketRead0 can hang even with soTimeout set
vtewari
parents:
38563
diff
changeset
|
32 |
#include <sys/time.h> |
12047
320a714614e9
7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
11514
diff
changeset
|
33 |
|
41771
18c9669e76ca
8167481: cleanup of headers and includes for native libnet
clanger
parents:
41578
diff
changeset
|
34 |
#if defined(__linux__) |
2 | 35 |
#include <arpa/inet.h> |
36 |
#include <net/route.h> |
|
37 |
#include <sys/utsname.h> |
|
41771
18c9669e76ca
8167481: cleanup of headers and includes for native libnet
clanger
parents:
41578
diff
changeset
|
38 |
#endif |
2 | 39 |
|
41771
18c9669e76ca
8167481: cleanup of headers and includes for native libnet
clanger
parents:
41578
diff
changeset
|
40 |
#if defined(__solaris__) |
18c9669e76ca
8167481: cleanup of headers and includes for native libnet
clanger
parents:
41578
diff
changeset
|
41 |
#include <inet/nd.h> |
18c9669e76ca
8167481: cleanup of headers and includes for native libnet
clanger
parents:
41578
diff
changeset
|
42 |
#include <limits.h> |
18c9669e76ca
8167481: cleanup of headers and includes for native libnet
clanger
parents:
41578
diff
changeset
|
43 |
#include <stropts.h> |
18c9669e76ca
8167481: cleanup of headers and includes for native libnet
clanger
parents:
41578
diff
changeset
|
44 |
#include <sys/filio.h> |
18c9669e76ca
8167481: cleanup of headers and includes for native libnet
clanger
parents:
41578
diff
changeset
|
45 |
#include <sys/sockio.h> |
18c9669e76ca
8167481: cleanup of headers and includes for native libnet
clanger
parents:
41578
diff
changeset
|
46 |
#endif |
18c9669e76ca
8167481: cleanup of headers and includes for native libnet
clanger
parents:
41578
diff
changeset
|
47 |
|
42475
c80ab3b11401
8170920: SO_RCVBUF and SO_SNDBUF options problem for network channels on MacOS
michaelm
parents:
41834
diff
changeset
|
48 |
#if defined(MACOSX) |
c80ab3b11401
8170920: SO_RCVBUF and SO_SNDBUF options problem for network channels on MacOS
michaelm
parents:
41834
diff
changeset
|
49 |
#include <sys/sysctl.h> |
c80ab3b11401
8170920: SO_RCVBUF and SO_SNDBUF options problem for network channels on MacOS
michaelm
parents:
41834
diff
changeset
|
50 |
#endif |
c80ab3b11401
8170920: SO_RCVBUF and SO_SNDBUF options problem for network channels on MacOS
michaelm
parents:
41834
diff
changeset
|
51 |
|
41771
18c9669e76ca
8167481: cleanup of headers and includes for native libnet
clanger
parents:
41578
diff
changeset
|
52 |
#include "net_util.h" |
18c9669e76ca
8167481: cleanup of headers and includes for native libnet
clanger
parents:
41578
diff
changeset
|
53 |
|
18c9669e76ca
8167481: cleanup of headers and includes for native libnet
clanger
parents:
41578
diff
changeset
|
54 |
#include "java_net_SocketOptions.h" |
18c9669e76ca
8167481: cleanup of headers and includes for native libnet
clanger
parents:
41578
diff
changeset
|
55 |
#include "java_net_InetAddress.h" |
18c9669e76ca
8167481: cleanup of headers and includes for native libnet
clanger
parents:
41578
diff
changeset
|
56 |
|
18c9669e76ca
8167481: cleanup of headers and includes for native libnet
clanger
parents:
41578
diff
changeset
|
57 |
#if defined(__linux__) && !defined(IPV6_FLOWINFO_SEND) |
2 | 58 |
#define IPV6_FLOWINFO_SEND 33 |
59 |
#endif |
|
60 |
||
41771
18c9669e76ca
8167481: cleanup of headers and includes for native libnet
clanger
parents:
41578
diff
changeset
|
61 |
#if defined(__solaris__) && !defined(MAXINT) |
18c9669e76ca
8167481: cleanup of headers and includes for native libnet
clanger
parents:
41578
diff
changeset
|
62 |
#define MAXINT INT_MAX |
23028
0554f6183d11
8035876: AIX build issues after '8034174: Remove use of JVM_* functions from java.net code'
simonis
parents:
23015
diff
changeset
|
63 |
#endif |
0554f6183d11
8035876: AIX build issues after '8034174: Remove use of JVM_* functions from java.net code'
simonis
parents:
23015
diff
changeset
|
64 |
|
2 | 65 |
/* |
13043
10fa4f21ea0f
7123896: Unexpected behavior due to Solaris using separate IPv4 and IPv6 port spaces
coffeys
parents:
12047
diff
changeset
|
66 |
* EXCLBIND socket options only on Solaris |
2 | 67 |
*/ |
68 |
#if defined(__solaris__) && !defined(TCP_EXCLBIND) |
|
69 |
#define TCP_EXCLBIND 0x21 |
|
70 |
#endif |
|
71 |
#if defined(__solaris__) && !defined(UDP_EXCLBIND) |
|
72 |
#define UDP_EXCLBIND 0x0101 |
|
73 |
#endif |
|
74 |
||
12047
320a714614e9
7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
11514
diff
changeset
|
75 |
void setDefaultScopeID(JNIEnv *env, struct sockaddr *him) |
320a714614e9
7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
11514
diff
changeset
|
76 |
{ |
320a714614e9
7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
11514
diff
changeset
|
77 |
#ifdef MACOSX |
320a714614e9
7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
11514
diff
changeset
|
78 |
static jclass ni_class = NULL; |
320a714614e9
7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
11514
diff
changeset
|
79 |
static jfieldID ni_defaultIndexID; |
320a714614e9
7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
11514
diff
changeset
|
80 |
if (ni_class == NULL) { |
320a714614e9
7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
11514
diff
changeset
|
81 |
jclass c = (*env)->FindClass(env, "java/net/NetworkInterface"); |
320a714614e9
7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
11514
diff
changeset
|
82 |
CHECK_NULL(c); |
320a714614e9
7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
11514
diff
changeset
|
83 |
c = (*env)->NewGlobalRef(env, c); |
320a714614e9
7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
11514
diff
changeset
|
84 |
CHECK_NULL(c); |
38563
3ab5f00bd5a3
8157811: Additional minor fixes and cleanups in Networking native code
chegar
parents:
38459
diff
changeset
|
85 |
ni_defaultIndexID = (*env)->GetStaticFieldID(env, c, "defaultIndex", "I"); |
3ab5f00bd5a3
8157811: Additional minor fixes and cleanups in Networking native code
chegar
parents:
38459
diff
changeset
|
86 |
CHECK_NULL(ni_defaultIndexID); |
12047
320a714614e9
7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
11514
diff
changeset
|
87 |
ni_class = c; |
320a714614e9
7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
11514
diff
changeset
|
88 |
} |
320a714614e9
7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
11514
diff
changeset
|
89 |
int defaultIndex; |
320a714614e9
7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
11514
diff
changeset
|
90 |
struct sockaddr_in6 *sin6 = (struct sockaddr_in6 *)him; |
320a714614e9
7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
11514
diff
changeset
|
91 |
if (sin6->sin6_family == AF_INET6 && (sin6->sin6_scope_id == 0)) { |
320a714614e9
7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
11514
diff
changeset
|
92 |
defaultIndex = (*env)->GetStaticIntField(env, ni_class, |
320a714614e9
7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
11514
diff
changeset
|
93 |
ni_defaultIndexID); |
320a714614e9
7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
11514
diff
changeset
|
94 |
sin6->sin6_scope_id = defaultIndex; |
320a714614e9
7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
11514
diff
changeset
|
95 |
} |
320a714614e9
7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
11514
diff
changeset
|
96 |
#endif |
320a714614e9
7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
11514
diff
changeset
|
97 |
} |
320a714614e9
7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
11514
diff
changeset
|
98 |
|
12551
5be0a162ed89
7144274: [macosx] Default IPv6 multicast interface is not being set when calling MulticastSocket.joinGroup()
khazra
parents:
12047
diff
changeset
|
99 |
int getDefaultScopeID(JNIEnv *env) { |
23015
73b21ab36615
8034174: Remove use of JVM_* functions from java.net code
chegar
parents:
23010
diff
changeset
|
100 |
int defaultIndex = 0; |
12551
5be0a162ed89
7144274: [macosx] Default IPv6 multicast interface is not being set when calling MulticastSocket.joinGroup()
khazra
parents:
12047
diff
changeset
|
101 |
static jclass ni_class = NULL; |
5be0a162ed89
7144274: [macosx] Default IPv6 multicast interface is not being set when calling MulticastSocket.joinGroup()
khazra
parents:
12047
diff
changeset
|
102 |
static jfieldID ni_defaultIndexID; |
5be0a162ed89
7144274: [macosx] Default IPv6 multicast interface is not being set when calling MulticastSocket.joinGroup()
khazra
parents:
12047
diff
changeset
|
103 |
if (ni_class == NULL) { |
5be0a162ed89
7144274: [macosx] Default IPv6 multicast interface is not being set when calling MulticastSocket.joinGroup()
khazra
parents:
12047
diff
changeset
|
104 |
jclass c = (*env)->FindClass(env, "java/net/NetworkInterface"); |
12856
712335896cc4
7171591: getDefaultScopeID() in src/solaris/native/java/net/net_util_md.c should return a value
khazra
parents:
12688
diff
changeset
|
105 |
CHECK_NULL_RETURN(c, 0); |
12551
5be0a162ed89
7144274: [macosx] Default IPv6 multicast interface is not being set when calling MulticastSocket.joinGroup()
khazra
parents:
12047
diff
changeset
|
106 |
c = (*env)->NewGlobalRef(env, c); |
12856
712335896cc4
7171591: getDefaultScopeID() in src/solaris/native/java/net/net_util_md.c should return a value
khazra
parents:
12688
diff
changeset
|
107 |
CHECK_NULL_RETURN(c, 0); |
38563
3ab5f00bd5a3
8157811: Additional minor fixes and cleanups in Networking native code
chegar
parents:
38459
diff
changeset
|
108 |
ni_defaultIndexID = (*env)->GetStaticFieldID(env, c, "defaultIndex", "I"); |
3ab5f00bd5a3
8157811: Additional minor fixes and cleanups in Networking native code
chegar
parents:
38459
diff
changeset
|
109 |
CHECK_NULL_RETURN(ni_defaultIndexID, 0); |
12551
5be0a162ed89
7144274: [macosx] Default IPv6 multicast interface is not being set when calling MulticastSocket.joinGroup()
khazra
parents:
12047
diff
changeset
|
110 |
ni_class = c; |
5be0a162ed89
7144274: [macosx] Default IPv6 multicast interface is not being set when calling MulticastSocket.joinGroup()
khazra
parents:
12047
diff
changeset
|
111 |
} |
5be0a162ed89
7144274: [macosx] Default IPv6 multicast interface is not being set when calling MulticastSocket.joinGroup()
khazra
parents:
12047
diff
changeset
|
112 |
defaultIndex = (*env)->GetStaticIntField(env, ni_class, |
5be0a162ed89
7144274: [macosx] Default IPv6 multicast interface is not being set when calling MulticastSocket.joinGroup()
khazra
parents:
12047
diff
changeset
|
113 |
ni_defaultIndexID); |
5be0a162ed89
7144274: [macosx] Default IPv6 multicast interface is not being set when calling MulticastSocket.joinGroup()
khazra
parents:
12047
diff
changeset
|
114 |
return defaultIndex; |
5be0a162ed89
7144274: [macosx] Default IPv6 multicast interface is not being set when calling MulticastSocket.joinGroup()
khazra
parents:
12047
diff
changeset
|
115 |
} |
5be0a162ed89
7144274: [macosx] Default IPv6 multicast interface is not being set when calling MulticastSocket.joinGroup()
khazra
parents:
12047
diff
changeset
|
116 |
|
23015
73b21ab36615
8034174: Remove use of JVM_* functions from java.net code
chegar
parents:
23010
diff
changeset
|
117 |
#define RESTARTABLE(_cmd, _result) do { \ |
73b21ab36615
8034174: Remove use of JVM_* functions from java.net code
chegar
parents:
23010
diff
changeset
|
118 |
do { \ |
73b21ab36615
8034174: Remove use of JVM_* functions from java.net code
chegar
parents:
23010
diff
changeset
|
119 |
_result = _cmd; \ |
73b21ab36615
8034174: Remove use of JVM_* functions from java.net code
chegar
parents:
23010
diff
changeset
|
120 |
} while((_result == -1) && (errno == EINTR)); \ |
73b21ab36615
8034174: Remove use of JVM_* functions from java.net code
chegar
parents:
23010
diff
changeset
|
121 |
} while(0) |
73b21ab36615
8034174: Remove use of JVM_* functions from java.net code
chegar
parents:
23010
diff
changeset
|
122 |
|
73b21ab36615
8034174: Remove use of JVM_* functions from java.net code
chegar
parents:
23010
diff
changeset
|
123 |
int NET_SocketAvailable(int s, jint *pbytes) { |
73b21ab36615
8034174: Remove use of JVM_* functions from java.net code
chegar
parents:
23010
diff
changeset
|
124 |
int result; |
73b21ab36615
8034174: Remove use of JVM_* functions from java.net code
chegar
parents:
23010
diff
changeset
|
125 |
RESTARTABLE(ioctl(s, FIONREAD, pbytes), result); |
73b21ab36615
8034174: Remove use of JVM_* functions from java.net code
chegar
parents:
23010
diff
changeset
|
126 |
// note: ioctl can return 0 when successful, NET_SocketAvailable |
73b21ab36615
8034174: Remove use of JVM_* functions from java.net code
chegar
parents:
23010
diff
changeset
|
127 |
// is expected to return 0 on failure and 1 on success. |
73b21ab36615
8034174: Remove use of JVM_* functions from java.net code
chegar
parents:
23010
diff
changeset
|
128 |
return (result == -1) ? 0 : 1; |
73b21ab36615
8034174: Remove use of JVM_* functions from java.net code
chegar
parents:
23010
diff
changeset
|
129 |
} |
73b21ab36615
8034174: Remove use of JVM_* functions from java.net code
chegar
parents:
23010
diff
changeset
|
130 |
|
2 | 131 |
#ifdef __solaris__ |
7289
1352201521d9
6984182: Setting SO_RCVBUF/SO_SNDBUF to larger than tcp_max_buf fails on Solaris 11 if kernel params changed
michaelm
parents:
6696
diff
changeset
|
132 |
static int init_tcp_max_buf, init_udp_max_buf; |
2 | 133 |
static int tcp_max_buf; |
134 |
static int udp_max_buf; |
|
13043
10fa4f21ea0f
7123896: Unexpected behavior due to Solaris using separate IPv4 and IPv6 port spaces
coffeys
parents:
12047
diff
changeset
|
135 |
static int useExclBind = 0; |
2 | 136 |
|
137 |
/* |
|
138 |
* Get the specified parameter from the specified driver. The value |
|
139 |
* of the parameter is assumed to be an 'int'. If the parameter |
|
7289
1352201521d9
6984182: Setting SO_RCVBUF/SO_SNDBUF to larger than tcp_max_buf fails on Solaris 11 if kernel params changed
michaelm
parents:
6696
diff
changeset
|
140 |
* cannot be obtained return -1 |
2 | 141 |
*/ |
22341
4689530d03b9
8028293: Check local configuration for actual ephemeral port range
michaelm
parents:
20821
diff
changeset
|
142 |
int net_getParam(char *driver, char *param) |
2 | 143 |
{ |
144 |
struct strioctl stri; |
|
145 |
char buf [64]; |
|
146 |
int s; |
|
147 |
int value; |
|
148 |
||
149 |
s = open (driver, O_RDWR); |
|
150 |
if (s < 0) { |
|
7289
1352201521d9
6984182: Setting SO_RCVBUF/SO_SNDBUF to larger than tcp_max_buf fails on Solaris 11 if kernel params changed
michaelm
parents:
6696
diff
changeset
|
151 |
return -1; |
2 | 152 |
} |
153 |
strncpy (buf, param, sizeof(buf)); |
|
154 |
stri.ic_cmd = ND_GET; |
|
155 |
stri.ic_timout = 0; |
|
156 |
stri.ic_dp = buf; |
|
157 |
stri.ic_len = sizeof(buf); |
|
158 |
if (ioctl (s, I_STR, &stri) < 0) { |
|
7289
1352201521d9
6984182: Setting SO_RCVBUF/SO_SNDBUF to larger than tcp_max_buf fails on Solaris 11 if kernel params changed
michaelm
parents:
6696
diff
changeset
|
159 |
value = -1; |
2 | 160 |
} else { |
161 |
value = atoi(buf); |
|
162 |
} |
|
163 |
close (s); |
|
164 |
return value; |
|
165 |
} |
|
7289
1352201521d9
6984182: Setting SO_RCVBUF/SO_SNDBUF to larger than tcp_max_buf fails on Solaris 11 if kernel params changed
michaelm
parents:
6696
diff
changeset
|
166 |
|
1352201521d9
6984182: Setting SO_RCVBUF/SO_SNDBUF to larger than tcp_max_buf fails on Solaris 11 if kernel params changed
michaelm
parents:
6696
diff
changeset
|
167 |
/* |
1352201521d9
6984182: Setting SO_RCVBUF/SO_SNDBUF to larger than tcp_max_buf fails on Solaris 11 if kernel params changed
michaelm
parents:
6696
diff
changeset
|
168 |
* Iterative way to find the max value that SO_SNDBUF or SO_RCVBUF |
22341
4689530d03b9
8028293: Check local configuration for actual ephemeral port range
michaelm
parents:
20821
diff
changeset
|
169 |
* for Solaris versions that do not support the ioctl() in net_getParam(). |
7289
1352201521d9
6984182: Setting SO_RCVBUF/SO_SNDBUF to larger than tcp_max_buf fails on Solaris 11 if kernel params changed
michaelm
parents:
6696
diff
changeset
|
170 |
* Ugly, but only called once (for each sotype). |
1352201521d9
6984182: Setting SO_RCVBUF/SO_SNDBUF to larger than tcp_max_buf fails on Solaris 11 if kernel params changed
michaelm
parents:
6696
diff
changeset
|
171 |
* |
13999
f6a2ce6a3e40
7193520: Removed references to Linux kernel version 2.2
chegar
parents:
13048
diff
changeset
|
172 |
* As an optimization, we make a guess using the default values for Solaris |
7289
1352201521d9
6984182: Setting SO_RCVBUF/SO_SNDBUF to larger than tcp_max_buf fails on Solaris 11 if kernel params changed
michaelm
parents:
6696
diff
changeset
|
173 |
* assuming they haven't been modified with ndd. |
1352201521d9
6984182: Setting SO_RCVBUF/SO_SNDBUF to larger than tcp_max_buf fails on Solaris 11 if kernel params changed
michaelm
parents:
6696
diff
changeset
|
174 |
*/ |
1352201521d9
6984182: Setting SO_RCVBUF/SO_SNDBUF to larger than tcp_max_buf fails on Solaris 11 if kernel params changed
michaelm
parents:
6696
diff
changeset
|
175 |
|
1352201521d9
6984182: Setting SO_RCVBUF/SO_SNDBUF to larger than tcp_max_buf fails on Solaris 11 if kernel params changed
michaelm
parents:
6696
diff
changeset
|
176 |
#define MAX_TCP_GUESS 1024 * 1024 |
1352201521d9
6984182: Setting SO_RCVBUF/SO_SNDBUF to larger than tcp_max_buf fails on Solaris 11 if kernel params changed
michaelm
parents:
6696
diff
changeset
|
177 |
#define MAX_UDP_GUESS 2 * 1024 * 1024 |
1352201521d9
6984182: Setting SO_RCVBUF/SO_SNDBUF to larger than tcp_max_buf fails on Solaris 11 if kernel params changed
michaelm
parents:
6696
diff
changeset
|
178 |
|
1352201521d9
6984182: Setting SO_RCVBUF/SO_SNDBUF to larger than tcp_max_buf fails on Solaris 11 if kernel params changed
michaelm
parents:
6696
diff
changeset
|
179 |
#define FAIL_IF_NOT_ENOBUFS if (errno != ENOBUFS) return -1 |
1352201521d9
6984182: Setting SO_RCVBUF/SO_SNDBUF to larger than tcp_max_buf fails on Solaris 11 if kernel params changed
michaelm
parents:
6696
diff
changeset
|
180 |
|
1352201521d9
6984182: Setting SO_RCVBUF/SO_SNDBUF to larger than tcp_max_buf fails on Solaris 11 if kernel params changed
michaelm
parents:
6696
diff
changeset
|
181 |
static int findMaxBuf(int fd, int opt, int sotype) { |
1352201521d9
6984182: Setting SO_RCVBUF/SO_SNDBUF to larger than tcp_max_buf fails on Solaris 11 if kernel params changed
michaelm
parents:
6696
diff
changeset
|
182 |
int a = 0; |
1352201521d9
6984182: Setting SO_RCVBUF/SO_SNDBUF to larger than tcp_max_buf fails on Solaris 11 if kernel params changed
michaelm
parents:
6696
diff
changeset
|
183 |
int b = MAXINT; |
1352201521d9
6984182: Setting SO_RCVBUF/SO_SNDBUF to larger than tcp_max_buf fails on Solaris 11 if kernel params changed
michaelm
parents:
6696
diff
changeset
|
184 |
int initial_guess; |
1352201521d9
6984182: Setting SO_RCVBUF/SO_SNDBUF to larger than tcp_max_buf fails on Solaris 11 if kernel params changed
michaelm
parents:
6696
diff
changeset
|
185 |
int limit = -1; |
1352201521d9
6984182: Setting SO_RCVBUF/SO_SNDBUF to larger than tcp_max_buf fails on Solaris 11 if kernel params changed
michaelm
parents:
6696
diff
changeset
|
186 |
|
1352201521d9
6984182: Setting SO_RCVBUF/SO_SNDBUF to larger than tcp_max_buf fails on Solaris 11 if kernel params changed
michaelm
parents:
6696
diff
changeset
|
187 |
if (sotype == SOCK_DGRAM) { |
1352201521d9
6984182: Setting SO_RCVBUF/SO_SNDBUF to larger than tcp_max_buf fails on Solaris 11 if kernel params changed
michaelm
parents:
6696
diff
changeset
|
188 |
initial_guess = MAX_UDP_GUESS; |
1352201521d9
6984182: Setting SO_RCVBUF/SO_SNDBUF to larger than tcp_max_buf fails on Solaris 11 if kernel params changed
michaelm
parents:
6696
diff
changeset
|
189 |
} else { |
1352201521d9
6984182: Setting SO_RCVBUF/SO_SNDBUF to larger than tcp_max_buf fails on Solaris 11 if kernel params changed
michaelm
parents:
6696
diff
changeset
|
190 |
initial_guess = MAX_TCP_GUESS; |
1352201521d9
6984182: Setting SO_RCVBUF/SO_SNDBUF to larger than tcp_max_buf fails on Solaris 11 if kernel params changed
michaelm
parents:
6696
diff
changeset
|
191 |
} |
1352201521d9
6984182: Setting SO_RCVBUF/SO_SNDBUF to larger than tcp_max_buf fails on Solaris 11 if kernel params changed
michaelm
parents:
6696
diff
changeset
|
192 |
|
1352201521d9
6984182: Setting SO_RCVBUF/SO_SNDBUF to larger than tcp_max_buf fails on Solaris 11 if kernel params changed
michaelm
parents:
6696
diff
changeset
|
193 |
if (setsockopt(fd, SOL_SOCKET, opt, &initial_guess, sizeof(int)) == 0) { |
1352201521d9
6984182: Setting SO_RCVBUF/SO_SNDBUF to larger than tcp_max_buf fails on Solaris 11 if kernel params changed
michaelm
parents:
6696
diff
changeset
|
194 |
initial_guess++; |
1352201521d9
6984182: Setting SO_RCVBUF/SO_SNDBUF to larger than tcp_max_buf fails on Solaris 11 if kernel params changed
michaelm
parents:
6696
diff
changeset
|
195 |
if (setsockopt(fd, SOL_SOCKET, opt, &initial_guess,sizeof(int)) < 0) { |
1352201521d9
6984182: Setting SO_RCVBUF/SO_SNDBUF to larger than tcp_max_buf fails on Solaris 11 if kernel params changed
michaelm
parents:
6696
diff
changeset
|
196 |
FAIL_IF_NOT_ENOBUFS; |
1352201521d9
6984182: Setting SO_RCVBUF/SO_SNDBUF to larger than tcp_max_buf fails on Solaris 11 if kernel params changed
michaelm
parents:
6696
diff
changeset
|
197 |
return initial_guess - 1; |
1352201521d9
6984182: Setting SO_RCVBUF/SO_SNDBUF to larger than tcp_max_buf fails on Solaris 11 if kernel params changed
michaelm
parents:
6696
diff
changeset
|
198 |
} |
1352201521d9
6984182: Setting SO_RCVBUF/SO_SNDBUF to larger than tcp_max_buf fails on Solaris 11 if kernel params changed
michaelm
parents:
6696
diff
changeset
|
199 |
a = initial_guess; |
1352201521d9
6984182: Setting SO_RCVBUF/SO_SNDBUF to larger than tcp_max_buf fails on Solaris 11 if kernel params changed
michaelm
parents:
6696
diff
changeset
|
200 |
} else { |
1352201521d9
6984182: Setting SO_RCVBUF/SO_SNDBUF to larger than tcp_max_buf fails on Solaris 11 if kernel params changed
michaelm
parents:
6696
diff
changeset
|
201 |
FAIL_IF_NOT_ENOBUFS; |
1352201521d9
6984182: Setting SO_RCVBUF/SO_SNDBUF to larger than tcp_max_buf fails on Solaris 11 if kernel params changed
michaelm
parents:
6696
diff
changeset
|
202 |
b = initial_guess - 1; |
1352201521d9
6984182: Setting SO_RCVBUF/SO_SNDBUF to larger than tcp_max_buf fails on Solaris 11 if kernel params changed
michaelm
parents:
6696
diff
changeset
|
203 |
} |
1352201521d9
6984182: Setting SO_RCVBUF/SO_SNDBUF to larger than tcp_max_buf fails on Solaris 11 if kernel params changed
michaelm
parents:
6696
diff
changeset
|
204 |
do { |
1352201521d9
6984182: Setting SO_RCVBUF/SO_SNDBUF to larger than tcp_max_buf fails on Solaris 11 if kernel params changed
michaelm
parents:
6696
diff
changeset
|
205 |
int mid = a + (b-a)/2; |
1352201521d9
6984182: Setting SO_RCVBUF/SO_SNDBUF to larger than tcp_max_buf fails on Solaris 11 if kernel params changed
michaelm
parents:
6696
diff
changeset
|
206 |
if (setsockopt(fd, SOL_SOCKET, opt, &mid, sizeof(int)) == 0) { |
1352201521d9
6984182: Setting SO_RCVBUF/SO_SNDBUF to larger than tcp_max_buf fails on Solaris 11 if kernel params changed
michaelm
parents:
6696
diff
changeset
|
207 |
limit = mid; |
1352201521d9
6984182: Setting SO_RCVBUF/SO_SNDBUF to larger than tcp_max_buf fails on Solaris 11 if kernel params changed
michaelm
parents:
6696
diff
changeset
|
208 |
a = mid + 1; |
1352201521d9
6984182: Setting SO_RCVBUF/SO_SNDBUF to larger than tcp_max_buf fails on Solaris 11 if kernel params changed
michaelm
parents:
6696
diff
changeset
|
209 |
} else { |
1352201521d9
6984182: Setting SO_RCVBUF/SO_SNDBUF to larger than tcp_max_buf fails on Solaris 11 if kernel params changed
michaelm
parents:
6696
diff
changeset
|
210 |
FAIL_IF_NOT_ENOBUFS; |
1352201521d9
6984182: Setting SO_RCVBUF/SO_SNDBUF to larger than tcp_max_buf fails on Solaris 11 if kernel params changed
michaelm
parents:
6696
diff
changeset
|
211 |
b = mid - 1; |
1352201521d9
6984182: Setting SO_RCVBUF/SO_SNDBUF to larger than tcp_max_buf fails on Solaris 11 if kernel params changed
michaelm
parents:
6696
diff
changeset
|
212 |
} |
1352201521d9
6984182: Setting SO_RCVBUF/SO_SNDBUF to larger than tcp_max_buf fails on Solaris 11 if kernel params changed
michaelm
parents:
6696
diff
changeset
|
213 |
} while (b >= a); |
1352201521d9
6984182: Setting SO_RCVBUF/SO_SNDBUF to larger than tcp_max_buf fails on Solaris 11 if kernel params changed
michaelm
parents:
6696
diff
changeset
|
214 |
|
1352201521d9
6984182: Setting SO_RCVBUF/SO_SNDBUF to larger than tcp_max_buf fails on Solaris 11 if kernel params changed
michaelm
parents:
6696
diff
changeset
|
215 |
return limit; |
1352201521d9
6984182: Setting SO_RCVBUF/SO_SNDBUF to larger than tcp_max_buf fails on Solaris 11 if kernel params changed
michaelm
parents:
6696
diff
changeset
|
216 |
} |
2 | 217 |
#endif |
218 |
||
219 |
#ifdef __linux__ |
|
220 |
static int vinit = 0; |
|
221 |
static int kernelV24 = 0; |
|
222 |
static int vinit24 = 0; |
|
223 |
||
224 |
int kernelIsV24 () { |
|
225 |
if (!vinit24) { |
|
226 |
struct utsname sysinfo; |
|
227 |
if (uname(&sysinfo) == 0) { |
|
228 |
sysinfo.release[3] = '\0'; |
|
229 |
if (strcmp(sysinfo.release, "2.4") == 0) { |
|
230 |
kernelV24 = JNI_TRUE; |
|
231 |
} |
|
232 |
} |
|
233 |
vinit24 = 1; |
|
234 |
} |
|
235 |
return kernelV24; |
|
236 |
} |
|
237 |
#endif |
|
238 |
||
239 |
void |
|
240 |
NET_ThrowByNameWithLastError(JNIEnv *env, const char *name, |
|
241 |
const char *defaultDetail) { |
|
41578 | 242 |
JNU_ThrowByNameWithMessageAndLastError(env, name, defaultDetail); |
2 | 243 |
} |
244 |
||
245 |
void |
|
246 |
NET_ThrowCurrent(JNIEnv *env, char *msg) { |
|
247 |
NET_ThrowNew(env, errno, msg); |
|
248 |
} |
|
249 |
||
250 |
void |
|
251 |
NET_ThrowNew(JNIEnv *env, int errorNumber, char *msg) { |
|
252 |
char fullMsg[512]; |
|
253 |
if (!msg) { |
|
254 |
msg = "no further information"; |
|
255 |
} |
|
256 |
switch(errorNumber) { |
|
257 |
case EBADF: |
|
258 |
jio_snprintf(fullMsg, sizeof(fullMsg), "socket closed: %s", msg); |
|
259 |
JNU_ThrowByName(env, JNU_JAVANETPKG "SocketException", fullMsg); |
|
260 |
break; |
|
261 |
case EINTR: |
|
262 |
JNU_ThrowByName(env, JNU_JAVAIOPKG "InterruptedIOException", msg); |
|
263 |
break; |
|
264 |
default: |
|
265 |
errno = errorNumber; |
|
266 |
JNU_ThrowByNameWithLastError(env, JNU_JAVANETPKG "SocketException", msg); |
|
267 |
break; |
|
268 |
} |
|
269 |
} |
|
270 |
||
271 |
||
272 |
jfieldID |
|
273 |
NET_GetFileDescriptorID(JNIEnv *env) |
|
274 |
{ |
|
275 |
jclass cls = (*env)->FindClass(env, "java/io/FileDescriptor"); |
|
276 |
CHECK_NULL_RETURN(cls, NULL); |
|
277 |
return (*env)->GetFieldID(env, cls, "fd", "I"); |
|
278 |
} |
|
279 |
||
12047
320a714614e9
7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
11514
diff
changeset
|
280 |
#if defined(DONT_ENABLE_IPV6) |
320a714614e9
7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
11514
diff
changeset
|
281 |
jint IPv6_supported() |
320a714614e9
7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
11514
diff
changeset
|
282 |
{ |
320a714614e9
7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
11514
diff
changeset
|
283 |
return JNI_FALSE; |
320a714614e9
7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
11514
diff
changeset
|
284 |
} |
320a714614e9
7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
11514
diff
changeset
|
285 |
|
320a714614e9
7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
11514
diff
changeset
|
286 |
#else /* !DONT_ENABLE_IPV6 */ |
320a714614e9
7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
11514
diff
changeset
|
287 |
|
2 | 288 |
jint IPv6_supported() |
289 |
{ |
|
290 |
int fd; |
|
291 |
void *ipv6_fn; |
|
41380
c27cf95dd7e6
8167295: Further cleanup to the native parts of libnet/libnio
clanger
parents:
40937
diff
changeset
|
292 |
SOCKETADDRESS sa; |
c27cf95dd7e6
8167295: Further cleanup to the native parts of libnet/libnio
clanger
parents:
40937
diff
changeset
|
293 |
socklen_t sa_len = sizeof(SOCKETADDRESS); |
2 | 294 |
|
23015
73b21ab36615
8034174: Remove use of JVM_* functions from java.net code
chegar
parents:
23010
diff
changeset
|
295 |
fd = socket(AF_INET6, SOCK_STREAM, 0) ; |
2 | 296 |
if (fd < 0) { |
297 |
/* |
|
298 |
* TODO: We really cant tell since it may be an unrelated error |
|
299 |
* for now we will assume that AF_INET6 is not available |
|
300 |
*/ |
|
301 |
return JNI_FALSE; |
|
302 |
} |
|
303 |
||
304 |
/* |
|
305 |
* If fd 0 is a socket it means we've been launched from inetd or |
|
306 |
* xinetd. If it's a socket then check the family - if it's an |
|
307 |
* IPv4 socket then we need to disable IPv6. |
|
308 |
*/ |
|
41380
c27cf95dd7e6
8167295: Further cleanup to the native parts of libnet/libnio
clanger
parents:
40937
diff
changeset
|
309 |
if (getsockname(0, &sa.sa, &sa_len) == 0) { |
c27cf95dd7e6
8167295: Further cleanup to the native parts of libnet/libnio
clanger
parents:
40937
diff
changeset
|
310 |
if (sa.sa.sa_family != AF_INET6) { |
38459
6cf90640c38c
8048518: File Descriptor Leak in src/java.base/unix/native/libnet/net_util_md.c
chegar
parents:
36115
diff
changeset
|
311 |
close(fd); |
2 | 312 |
return JNI_FALSE; |
313 |
} |
|
314 |
} |
|
315 |
||
316 |
/** |
|
317 |
* Linux - check if any interface has an IPv6 address. |
|
318 |
* Don't need to parse the line - we just need an indication. |
|
319 |
*/ |
|
320 |
#ifdef __linux__ |
|
321 |
{ |
|
322 |
FILE *fP = fopen("/proc/net/if_inet6", "r"); |
|
323 |
char buf[255]; |
|
324 |
char *bufP; |
|
325 |
||
326 |
if (fP == NULL) { |
|
327 |
close(fd); |
|
328 |
return JNI_FALSE; |
|
329 |
} |
|
330 |
bufP = fgets(buf, sizeof(buf), fP); |
|
331 |
fclose(fP); |
|
332 |
if (bufP == NULL) { |
|
333 |
close(fd); |
|
334 |
return JNI_FALSE; |
|
335 |
} |
|
336 |
} |
|
337 |
#endif |
|
338 |
||
339 |
/** |
|
340 |
* On Solaris 8 it's possible to create INET6 sockets even |
|
341 |
* though IPv6 is not enabled on all interfaces. Thus we |
|
342 |
* query the number of IPv6 addresses to verify that IPv6 |
|
343 |
* has been configured on at least one interface. |
|
344 |
* |
|
345 |
* On Linux it doesn't matter - if IPv6 is built-in the |
|
346 |
* kernel then IPv6 addresses will be bound automatically |
|
347 |
* to all interfaces. |
|
348 |
*/ |
|
349 |
#ifdef __solaris__ |
|
350 |
||
351 |
#ifdef SIOCGLIFNUM |
|
352 |
{ |
|
353 |
struct lifnum numifs; |
|
354 |
||
355 |
numifs.lifn_family = AF_INET6; |
|
356 |
numifs.lifn_flags = 0; |
|
357 |
if (ioctl(fd, SIOCGLIFNUM, (char *)&numifs) < 0) { |
|
358 |
/** |
|
359 |
* SIOCGLIFNUM failed - assume IPv6 not configured |
|
360 |
*/ |
|
361 |
close(fd); |
|
362 |
return JNI_FALSE; |
|
363 |
} |
|
364 |
/** |
|
365 |
* If no IPv6 addresses then return false. If count > 0 |
|
366 |
* it's possible that all IPv6 addresses are "down" but |
|
367 |
* that's okay as they may be brought "up" while the |
|
368 |
* VM is running. |
|
369 |
*/ |
|
370 |
if (numifs.lifn_count == 0) { |
|
371 |
close(fd); |
|
372 |
return JNI_FALSE; |
|
373 |
} |
|
374 |
} |
|
375 |
#else |
|
376 |
/* SIOCGLIFNUM not defined in build environment ??? */ |
|
377 |
close(fd); |
|
378 |
return JNI_FALSE; |
|
379 |
#endif |
|
380 |
||
381 |
#endif /* __solaris */ |
|
382 |
||
383 |
/* |
|
384 |
* OK we may have the stack available in the kernel, |
|
385 |
* we should also check if the APIs are available. |
|
386 |
*/ |
|
387 |
ipv6_fn = JVM_FindLibraryEntry(RTLD_DEFAULT, "inet_pton"); |
|
11032
235588f77727
7112670: Inet4AddressImpl should use getaddrinfo/getnameinfo
ngmr
parents:
9035
diff
changeset
|
388 |
close(fd); |
2 | 389 |
if (ipv6_fn == NULL ) { |
390 |
return JNI_FALSE; |
|
11032
235588f77727
7112670: Inet4AddressImpl should use getaddrinfo/getnameinfo
ngmr
parents:
9035
diff
changeset
|
391 |
} else { |
235588f77727
7112670: Inet4AddressImpl should use getaddrinfo/getnameinfo
ngmr
parents:
9035
diff
changeset
|
392 |
return JNI_TRUE; |
2 | 393 |
} |
394 |
} |
|
12047
320a714614e9
7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
11514
diff
changeset
|
395 |
#endif /* DONT_ENABLE_IPV6 */ |
2 | 396 |
|
36115 | 397 |
jint reuseport_supported() |
398 |
{ |
|
399 |
/* Do a simple dummy call, and try to figure out from that */ |
|
400 |
int one = 1; |
|
401 |
int rv, s; |
|
402 |
s = socket(PF_INET, SOCK_STREAM, 0); |
|
403 |
if (s < 0) { |
|
404 |
return JNI_FALSE; |
|
405 |
} |
|
406 |
rv = setsockopt(s, SOL_SOCKET, SO_REUSEPORT, (void *)&one, sizeof(one)); |
|
407 |
if (rv != 0) { |
|
408 |
rv = JNI_FALSE; |
|
409 |
} else { |
|
410 |
rv = JNI_TRUE; |
|
411 |
} |
|
412 |
close(s); |
|
413 |
return rv; |
|
414 |
} |
|
415 |
||
23033
0cc7c83fde3c
8035949: Remove unused macro USE_SELECT and clean up Unix version of net_util_md.{c,h}
simonis
parents:
23028
diff
changeset
|
416 |
void NET_ThrowUnknownHostExceptionWithGaiError(JNIEnv *env, |
0cc7c83fde3c
8035949: Remove unused macro USE_SELECT and clean up Unix version of net_util_md.{c,h}
simonis
parents:
23028
diff
changeset
|
417 |
const char* hostname, |
0cc7c83fde3c
8035949: Remove unused macro USE_SELECT and clean up Unix version of net_util_md.{c,h}
simonis
parents:
23028
diff
changeset
|
418 |
int gai_error) |
6670
ae13809f3ce7
6981157: Improve UnknownHostException with EAI error details and other cleanups
martin
parents:
5506
diff
changeset
|
419 |
{ |
6696
7201f23dae0d
6989190: SO_SNDBUF/SO_RCVBUF limits should only be checked when setsockopt fails (sol)
alanb
parents:
6670
diff
changeset
|
420 |
int size; |
7201f23dae0d
6989190: SO_SNDBUF/SO_RCVBUF limits should only be checked when setsockopt fails (sol)
alanb
parents:
6670
diff
changeset
|
421 |
char *buf; |
6670
ae13809f3ce7
6981157: Improve UnknownHostException with EAI error details and other cleanups
martin
parents:
5506
diff
changeset
|
422 |
const char *format = "%s: %s"; |
23033
0cc7c83fde3c
8035949: Remove unused macro USE_SELECT and clean up Unix version of net_util_md.{c,h}
simonis
parents:
23028
diff
changeset
|
423 |
const char *error_string = gai_strerror(gai_error); |
6670
ae13809f3ce7
6981157: Improve UnknownHostException with EAI error details and other cleanups
martin
parents:
5506
diff
changeset
|
424 |
if (error_string == NULL) |
ae13809f3ce7
6981157: Improve UnknownHostException with EAI error details and other cleanups
martin
parents:
5506
diff
changeset
|
425 |
error_string = "unknown error"; |
ae13809f3ce7
6981157: Improve UnknownHostException with EAI error details and other cleanups
martin
parents:
5506
diff
changeset
|
426 |
|
6696
7201f23dae0d
6989190: SO_SNDBUF/SO_RCVBUF limits should only be checked when setsockopt fails (sol)
alanb
parents:
6670
diff
changeset
|
427 |
size = strlen(format) + strlen(hostname) + strlen(error_string) + 2; |
7201f23dae0d
6989190: SO_SNDBUF/SO_RCVBUF limits should only be checked when setsockopt fails (sol)
alanb
parents:
6670
diff
changeset
|
428 |
buf = (char *) malloc(size); |
6670
ae13809f3ce7
6981157: Improve UnknownHostException with EAI error details and other cleanups
martin
parents:
5506
diff
changeset
|
429 |
if (buf) { |
6696
7201f23dae0d
6989190: SO_SNDBUF/SO_RCVBUF limits should only be checked when setsockopt fails (sol)
alanb
parents:
6670
diff
changeset
|
430 |
jstring s; |
6670
ae13809f3ce7
6981157: Improve UnknownHostException with EAI error details and other cleanups
martin
parents:
5506
diff
changeset
|
431 |
sprintf(buf, format, hostname, error_string); |
6696
7201f23dae0d
6989190: SO_SNDBUF/SO_RCVBUF limits should only be checked when setsockopt fails (sol)
alanb
parents:
6670
diff
changeset
|
432 |
s = JNU_NewStringPlatform(env, buf); |
6670
ae13809f3ce7
6981157: Improve UnknownHostException with EAI error details and other cleanups
martin
parents:
5506
diff
changeset
|
433 |
if (s != NULL) { |
ae13809f3ce7
6981157: Improve UnknownHostException with EAI error details and other cleanups
martin
parents:
5506
diff
changeset
|
434 |
jobject x = JNU_NewObjectByName(env, |
ae13809f3ce7
6981157: Improve UnknownHostException with EAI error details and other cleanups
martin
parents:
5506
diff
changeset
|
435 |
"java/net/UnknownHostException", |
ae13809f3ce7
6981157: Improve UnknownHostException with EAI error details and other cleanups
martin
parents:
5506
diff
changeset
|
436 |
"(Ljava/lang/String;)V", s); |
ae13809f3ce7
6981157: Improve UnknownHostException with EAI error details and other cleanups
martin
parents:
5506
diff
changeset
|
437 |
if (x != NULL) |
ae13809f3ce7
6981157: Improve UnknownHostException with EAI error details and other cleanups
martin
parents:
5506
diff
changeset
|
438 |
(*env)->Throw(env, x); |
ae13809f3ce7
6981157: Improve UnknownHostException with EAI error details and other cleanups
martin
parents:
5506
diff
changeset
|
439 |
} |
ae13809f3ce7
6981157: Improve UnknownHostException with EAI error details and other cleanups
martin
parents:
5506
diff
changeset
|
440 |
free(buf); |
ae13809f3ce7
6981157: Improve UnknownHostException with EAI error details and other cleanups
martin
parents:
5506
diff
changeset
|
441 |
} |
ae13809f3ce7
6981157: Improve UnknownHostException with EAI error details and other cleanups
martin
parents:
5506
diff
changeset
|
442 |
} |
ae13809f3ce7
6981157: Improve UnknownHostException with EAI error details and other cleanups
martin
parents:
5506
diff
changeset
|
443 |
|
41834
99c4f72c0a91
8168771: Remove #ifdef AF_INET6 guards in libnet native coding
clanger
parents:
41771
diff
changeset
|
444 |
#if defined(__linux__) |
2 | 445 |
|
446 |
/* following code creates a list of addresses from the kernel |
|
447 |
* routing table that are routed via the loopback address. |
|
448 |
* We check all destination addresses against this table |
|
449 |
* and override the scope_id field to use the relevant value for "lo" |
|
450 |
* in order to work-around the Linux bug that prevents packets destined |
|
451 |
* for certain local addresses from being sent via a physical interface. |
|
452 |
*/ |
|
453 |
||
454 |
struct loopback_route { |
|
455 |
struct in6_addr addr; /* destination address */ |
|
456 |
int plen; /* prefix length */ |
|
457 |
}; |
|
458 |
||
459 |
static struct loopback_route *loRoutes = 0; |
|
460 |
static int nRoutes = 0; /* number of routes */ |
|
461 |
static int loRoutes_size = 16; /* initial size */ |
|
462 |
static int lo_scope_id = 0; |
|
463 |
||
464 |
static void initLoopbackRoutes(); |
|
465 |
||
466 |
void printAddr (struct in6_addr *addr) { |
|
467 |
int i; |
|
468 |
for (i=0; i<16; i++) { |
|
469 |
printf ("%02x", addr->s6_addr[i]); |
|
470 |
} |
|
471 |
printf ("\n"); |
|
472 |
} |
|
473 |
||
474 |
static jboolean needsLoopbackRoute (struct in6_addr* dest_addr) { |
|
475 |
int byte_count; |
|
476 |
int extra_bits, i; |
|
477 |
struct loopback_route *ptr; |
|
478 |
||
479 |
if (loRoutes == 0) { |
|
480 |
initLoopbackRoutes(); |
|
481 |
} |
|
482 |
||
483 |
for (ptr = loRoutes, i=0; i<nRoutes; i++, ptr++) { |
|
484 |
struct in6_addr *target_addr=&ptr->addr; |
|
485 |
int dest_plen = ptr->plen; |
|
486 |
byte_count = dest_plen >> 3; |
|
487 |
extra_bits = dest_plen & 0x3; |
|
488 |
||
489 |
if (byte_count > 0) { |
|
490 |
if (memcmp(target_addr, dest_addr, byte_count)) { |
|
491 |
continue; /* no match */ |
|
492 |
} |
|
493 |
} |
|
494 |
||
495 |
if (extra_bits > 0) { |
|
496 |
unsigned char c1 = ((unsigned char *)target_addr)[byte_count]; |
|
497 |
unsigned char c2 = ((unsigned char *)&dest_addr)[byte_count]; |
|
498 |
unsigned char mask = 0xff << (8 - extra_bits); |
|
499 |
if ((c1 & mask) != (c2 & mask)) { |
|
500 |
continue; |
|
501 |
} |
|
502 |
} |
|
503 |
return JNI_TRUE; |
|
504 |
} |
|
505 |
return JNI_FALSE; |
|
506 |
} |
|
507 |
||
508 |
||
509 |
static void initLoopbackRoutes() { |
|
510 |
FILE *f; |
|
511 |
char srcp[8][5]; |
|
512 |
char hopp[8][5]; |
|
513 |
int dest_plen, src_plen, use, refcnt, metric; |
|
514 |
unsigned long flags; |
|
515 |
char dest_str[40]; |
|
516 |
struct in6_addr dest_addr; |
|
517 |
char device[16]; |
|
14320
d5be8d19b3ec
8000203: File descriptor leak in src/solaris/native/java/net/net_util_md.c
chegar
parents:
13999
diff
changeset
|
518 |
struct loopback_route *loRoutesTemp; |
2 | 519 |
|
520 |
if (loRoutes != 0) { |
|
521 |
free (loRoutes); |
|
522 |
} |
|
523 |
loRoutes = calloc (loRoutes_size, sizeof(struct loopback_route)); |
|
524 |
if (loRoutes == 0) { |
|
525 |
return; |
|
526 |
} |
|
527 |
/* |
|
528 |
* Scan /proc/net/ipv6_route looking for a matching |
|
529 |
* route. |
|
530 |
*/ |
|
531 |
if ((f = fopen("/proc/net/ipv6_route", "r")) == NULL) { |
|
532 |
return ; |
|
533 |
} |
|
534 |
while (fscanf(f, "%4s%4s%4s%4s%4s%4s%4s%4s %02x " |
|
535 |
"%4s%4s%4s%4s%4s%4s%4s%4s %02x " |
|
536 |
"%4s%4s%4s%4s%4s%4s%4s%4s " |
|
537 |
"%08x %08x %08x %08lx %8s", |
|
538 |
dest_str, &dest_str[5], &dest_str[10], &dest_str[15], |
|
539 |
&dest_str[20], &dest_str[25], &dest_str[30], &dest_str[35], |
|
540 |
&dest_plen, |
|
541 |
srcp[0], srcp[1], srcp[2], srcp[3], |
|
542 |
srcp[4], srcp[5], srcp[6], srcp[7], |
|
543 |
&src_plen, |
|
544 |
hopp[0], hopp[1], hopp[2], hopp[3], |
|
545 |
hopp[4], hopp[5], hopp[6], hopp[7], |
|
546 |
&metric, &use, &refcnt, &flags, device) == 31) { |
|
547 |
||
548 |
/* |
|
549 |
* Some routes should be ignored |
|
550 |
*/ |
|
551 |
if ( (dest_plen < 0 || dest_plen > 128) || |
|
552 |
(src_plen != 0) || |
|
553 |
(flags & (RTF_POLICY | RTF_FLOW)) || |
|
554 |
((flags & RTF_REJECT) && dest_plen == 0) ) { |
|
555 |
continue; |
|
556 |
} |
|
557 |
||
558 |
/* |
|
559 |
* Convert the destination address |
|
560 |
*/ |
|
561 |
dest_str[4] = ':'; |
|
562 |
dest_str[9] = ':'; |
|
563 |
dest_str[14] = ':'; |
|
564 |
dest_str[19] = ':'; |
|
565 |
dest_str[24] = ':'; |
|
566 |
dest_str[29] = ':'; |
|
567 |
dest_str[34] = ':'; |
|
568 |
dest_str[39] = '\0'; |
|
569 |
||
570 |
if (inet_pton(AF_INET6, dest_str, &dest_addr) < 0) { |
|
571 |
/* not an Ipv6 address */ |
|
572 |
continue; |
|
573 |
} |
|
574 |
if (strcmp(device, "lo") != 0) { |
|
575 |
/* Not a loopback route */ |
|
576 |
continue; |
|
577 |
} else { |
|
578 |
if (nRoutes == loRoutes_size) { |
|
14320
d5be8d19b3ec
8000203: File descriptor leak in src/solaris/native/java/net/net_util_md.c
chegar
parents:
13999
diff
changeset
|
579 |
loRoutesTemp = realloc (loRoutes, loRoutes_size * |
d5be8d19b3ec
8000203: File descriptor leak in src/solaris/native/java/net/net_util_md.c
chegar
parents:
13999
diff
changeset
|
580 |
sizeof (struct loopback_route) * 2); |
d5be8d19b3ec
8000203: File descriptor leak in src/solaris/native/java/net/net_util_md.c
chegar
parents:
13999
diff
changeset
|
581 |
|
d5be8d19b3ec
8000203: File descriptor leak in src/solaris/native/java/net/net_util_md.c
chegar
parents:
13999
diff
changeset
|
582 |
if (loRoutesTemp == 0) { |
d5be8d19b3ec
8000203: File descriptor leak in src/solaris/native/java/net/net_util_md.c
chegar
parents:
13999
diff
changeset
|
583 |
free(loRoutes); |
d5be8d19b3ec
8000203: File descriptor leak in src/solaris/native/java/net/net_util_md.c
chegar
parents:
13999
diff
changeset
|
584 |
fclose (f); |
d5be8d19b3ec
8000203: File descriptor leak in src/solaris/native/java/net/net_util_md.c
chegar
parents:
13999
diff
changeset
|
585 |
return; |
2 | 586 |
} |
14320
d5be8d19b3ec
8000203: File descriptor leak in src/solaris/native/java/net/net_util_md.c
chegar
parents:
13999
diff
changeset
|
587 |
loRoutes=loRoutesTemp; |
2 | 588 |
loRoutes_size *= 2; |
589 |
} |
|
590 |
memcpy (&loRoutes[nRoutes].addr,&dest_addr,sizeof(struct in6_addr)); |
|
591 |
loRoutes[nRoutes].plen = dest_plen; |
|
592 |
nRoutes ++; |
|
593 |
} |
|
594 |
} |
|
595 |
||
596 |
fclose (f); |
|
597 |
{ |
|
598 |
/* now find the scope_id for "lo" */ |
|
599 |
||
8554
14e626e9407b
7022269: clean up fscanf usage in Linux networking native code
chegar
parents:
7668
diff
changeset
|
600 |
char devname[21]; |
2 | 601 |
char addr6p[8][5]; |
602 |
int plen, scope, dad_status, if_idx; |
|
603 |
||
604 |
if ((f = fopen("/proc/net/if_inet6", "r")) != NULL) { |
|
11514
0cefabc1c81f
7123415: Some cases of network interface indexes being read incorrectly
chegar
parents:
11032
diff
changeset
|
605 |
while (fscanf(f, "%4s%4s%4s%4s%4s%4s%4s%4s %08x %02x %02x %02x %20s\n", |
2 | 606 |
addr6p[0], addr6p[1], addr6p[2], addr6p[3], |
607 |
addr6p[4], addr6p[5], addr6p[6], addr6p[7], |
|
608 |
&if_idx, &plen, &scope, &dad_status, devname) == 13) { |
|
609 |
||
610 |
if (strcmp(devname, "lo") == 0) { |
|
611 |
/* |
|
612 |
* Found - so just return the index |
|
613 |
*/ |
|
614 |
fclose(f); |
|
615 |
lo_scope_id = if_idx; |
|
616 |
return; |
|
617 |
} |
|
618 |
} |
|
619 |
fclose(f); |
|
620 |
} |
|
621 |
} |
|
622 |
} |
|
623 |
||
624 |
/* |
|
625 |
* Following is used for binding to local addresses. Equivalent |
|
626 |
* to code above, for bind(). |
|
627 |
*/ |
|
628 |
||
629 |
struct localinterface { |
|
630 |
int index; |
|
631 |
char localaddr [16]; |
|
632 |
}; |
|
633 |
||
634 |
static struct localinterface *localifs = 0; |
|
635 |
static int localifsSize = 0; /* size of array */ |
|
636 |
static int nifs = 0; /* number of entries used in array */ |
|
637 |
||
638 |
/* not thread safe: make sure called once from one thread */ |
|
639 |
||
640 |
static void initLocalIfs () { |
|
641 |
FILE *f; |
|
642 |
unsigned char staddr [16]; |
|
8554
14e626e9407b
7022269: clean up fscanf usage in Linux networking native code
chegar
parents:
7668
diff
changeset
|
643 |
char ifname [33]; |
2 | 644 |
struct localinterface *lif=0; |
645 |
int index, x1, x2, x3; |
|
646 |
unsigned int u0,u1,u2,u3,u4,u5,u6,u7,u8,u9,ua,ub,uc,ud,ue,uf; |
|
647 |
||
648 |
if ((f = fopen("/proc/net/if_inet6", "r")) == NULL) { |
|
649 |
return ; |
|
650 |
} |
|
651 |
while (fscanf (f, "%2x%2x%2x%2x%2x%2x%2x%2x%2x%2x%2x%2x%2x%2x%2x%2x " |
|
8554
14e626e9407b
7022269: clean up fscanf usage in Linux networking native code
chegar
parents:
7668
diff
changeset
|
652 |
"%d %x %x %x %32s",&u0,&u1,&u2,&u3,&u4,&u5,&u6,&u7, |
2 | 653 |
&u8,&u9,&ua,&ub,&uc,&ud,&ue,&uf, |
654 |
&index, &x1, &x2, &x3, ifname) == 21) { |
|
655 |
staddr[0] = (unsigned char)u0; |
|
656 |
staddr[1] = (unsigned char)u1; |
|
657 |
staddr[2] = (unsigned char)u2; |
|
658 |
staddr[3] = (unsigned char)u3; |
|
659 |
staddr[4] = (unsigned char)u4; |
|
660 |
staddr[5] = (unsigned char)u5; |
|
661 |
staddr[6] = (unsigned char)u6; |
|
662 |
staddr[7] = (unsigned char)u7; |
|
663 |
staddr[8] = (unsigned char)u8; |
|
664 |
staddr[9] = (unsigned char)u9; |
|
665 |
staddr[10] = (unsigned char)ua; |
|
666 |
staddr[11] = (unsigned char)ub; |
|
667 |
staddr[12] = (unsigned char)uc; |
|
668 |
staddr[13] = (unsigned char)ud; |
|
669 |
staddr[14] = (unsigned char)ue; |
|
670 |
staddr[15] = (unsigned char)uf; |
|
671 |
nifs ++; |
|
672 |
if (nifs > localifsSize) { |
|
673 |
localifs = (struct localinterface *) realloc ( |
|
674 |
localifs, sizeof (struct localinterface)* (localifsSize+5)); |
|
675 |
if (localifs == 0) { |
|
676 |
nifs = 0; |
|
677 |
fclose (f); |
|
678 |
return; |
|
679 |
} |
|
680 |
lif = localifs + localifsSize; |
|
681 |
localifsSize += 5; |
|
682 |
} else { |
|
683 |
lif ++; |
|
684 |
} |
|
685 |
memcpy (lif->localaddr, staddr, 16); |
|
686 |
lif->index = index; |
|
687 |
} |
|
688 |
fclose (f); |
|
689 |
} |
|
690 |
||
691 |
/* return the scope_id (interface index) of the |
|
692 |
* interface corresponding to the given address |
|
693 |
* returns 0 if no match found |
|
694 |
*/ |
|
695 |
||
696 |
static int getLocalScopeID (char *addr) { |
|
697 |
struct localinterface *lif; |
|
698 |
int i; |
|
699 |
if (localifs == 0) { |
|
700 |
initLocalIfs(); |
|
701 |
} |
|
702 |
for (i=0, lif=localifs; i<nifs; i++, lif++) { |
|
703 |
if (memcmp (addr, lif->localaddr, 16) == 0) { |
|
704 |
return lif->index; |
|
705 |
} |
|
706 |
} |
|
707 |
return 0; |
|
708 |
} |
|
709 |
||
22597
7515a991bb37
8024854: PPC64: Basic changes and files to build the class library on AIX
simonis
parents:
20821
diff
changeset
|
710 |
void platformInit () { |
2 | 711 |
initLoopbackRoutes(); |
712 |
initLocalIfs(); |
|
713 |
} |
|
714 |
||
22597
7515a991bb37
8024854: PPC64: Basic changes and files to build the class library on AIX
simonis
parents:
20821
diff
changeset
|
715 |
#elif defined(_AIX) |
7515a991bb37
8024854: PPC64: Basic changes and files to build the class library on AIX
simonis
parents:
20821
diff
changeset
|
716 |
|
7515a991bb37
8024854: PPC64: Basic changes and files to build the class library on AIX
simonis
parents:
20821
diff
changeset
|
717 |
/* Initialize stubs for blocking I/O workarounds (see src/solaris/native/java/net/linux_close.c) */ |
7515a991bb37
8024854: PPC64: Basic changes and files to build the class library on AIX
simonis
parents:
20821
diff
changeset
|
718 |
extern void aix_close_init(); |
7515a991bb37
8024854: PPC64: Basic changes and files to build the class library on AIX
simonis
parents:
20821
diff
changeset
|
719 |
|
7515a991bb37
8024854: PPC64: Basic changes and files to build the class library on AIX
simonis
parents:
20821
diff
changeset
|
720 |
void platformInit () { |
7515a991bb37
8024854: PPC64: Basic changes and files to build the class library on AIX
simonis
parents:
20821
diff
changeset
|
721 |
aix_close_init(); |
7515a991bb37
8024854: PPC64: Basic changes and files to build the class library on AIX
simonis
parents:
20821
diff
changeset
|
722 |
} |
7515a991bb37
8024854: PPC64: Basic changes and files to build the class library on AIX
simonis
parents:
20821
diff
changeset
|
723 |
|
2 | 724 |
#else |
725 |
||
22597
7515a991bb37
8024854: PPC64: Basic changes and files to build the class library on AIX
simonis
parents:
20821
diff
changeset
|
726 |
void platformInit () {} |
2 | 727 |
|
728 |
#endif |
|
729 |
||
13043
10fa4f21ea0f
7123896: Unexpected behavior due to Solaris using separate IPv4 and IPv6 port spaces
coffeys
parents:
12047
diff
changeset
|
730 |
void parseExclusiveBindProperty(JNIEnv *env) { |
10fa4f21ea0f
7123896: Unexpected behavior due to Solaris using separate IPv4 and IPv6 port spaces
coffeys
parents:
12047
diff
changeset
|
731 |
#ifdef __solaris__ |
10fa4f21ea0f
7123896: Unexpected behavior due to Solaris using separate IPv4 and IPv6 port spaces
coffeys
parents:
12047
diff
changeset
|
732 |
jstring s, flagSet; |
10fa4f21ea0f
7123896: Unexpected behavior due to Solaris using separate IPv4 and IPv6 port spaces
coffeys
parents:
12047
diff
changeset
|
733 |
jclass iCls; |
10fa4f21ea0f
7123896: Unexpected behavior due to Solaris using separate IPv4 and IPv6 port spaces
coffeys
parents:
12047
diff
changeset
|
734 |
jmethodID mid; |
10fa4f21ea0f
7123896: Unexpected behavior due to Solaris using separate IPv4 and IPv6 port spaces
coffeys
parents:
12047
diff
changeset
|
735 |
|
10fa4f21ea0f
7123896: Unexpected behavior due to Solaris using separate IPv4 and IPv6 port spaces
coffeys
parents:
12047
diff
changeset
|
736 |
s = (*env)->NewStringUTF(env, "sun.net.useExclusiveBind"); |
10fa4f21ea0f
7123896: Unexpected behavior due to Solaris using separate IPv4 and IPv6 port spaces
coffeys
parents:
12047
diff
changeset
|
737 |
CHECK_NULL(s); |
10fa4f21ea0f
7123896: Unexpected behavior due to Solaris using separate IPv4 and IPv6 port spaces
coffeys
parents:
12047
diff
changeset
|
738 |
iCls = (*env)->FindClass(env, "java/lang/System"); |
10fa4f21ea0f
7123896: Unexpected behavior due to Solaris using separate IPv4 and IPv6 port spaces
coffeys
parents:
12047
diff
changeset
|
739 |
CHECK_NULL(iCls); |
10fa4f21ea0f
7123896: Unexpected behavior due to Solaris using separate IPv4 and IPv6 port spaces
coffeys
parents:
12047
diff
changeset
|
740 |
mid = (*env)->GetStaticMethodID(env, iCls, "getProperty", |
10fa4f21ea0f
7123896: Unexpected behavior due to Solaris using separate IPv4 and IPv6 port spaces
coffeys
parents:
12047
diff
changeset
|
741 |
"(Ljava/lang/String;)Ljava/lang/String;"); |
10fa4f21ea0f
7123896: Unexpected behavior due to Solaris using separate IPv4 and IPv6 port spaces
coffeys
parents:
12047
diff
changeset
|
742 |
CHECK_NULL(mid); |
10fa4f21ea0f
7123896: Unexpected behavior due to Solaris using separate IPv4 and IPv6 port spaces
coffeys
parents:
12047
diff
changeset
|
743 |
flagSet = (*env)->CallStaticObjectMethod(env, iCls, mid, s); |
10fa4f21ea0f
7123896: Unexpected behavior due to Solaris using separate IPv4 and IPv6 port spaces
coffeys
parents:
12047
diff
changeset
|
744 |
if (flagSet != NULL) { |
10fa4f21ea0f
7123896: Unexpected behavior due to Solaris using separate IPv4 and IPv6 port spaces
coffeys
parents:
12047
diff
changeset
|
745 |
useExclBind = 1; |
10fa4f21ea0f
7123896: Unexpected behavior due to Solaris using separate IPv4 and IPv6 port spaces
coffeys
parents:
12047
diff
changeset
|
746 |
} |
10fa4f21ea0f
7123896: Unexpected behavior due to Solaris using separate IPv4 and IPv6 port spaces
coffeys
parents:
12047
diff
changeset
|
747 |
#endif |
10fa4f21ea0f
7123896: Unexpected behavior due to Solaris using separate IPv4 and IPv6 port spaces
coffeys
parents:
12047
diff
changeset
|
748 |
} |
10fa4f21ea0f
7123896: Unexpected behavior due to Solaris using separate IPv4 and IPv6 port spaces
coffeys
parents:
12047
diff
changeset
|
749 |
|
27178
885f4428b501
8060170: Support SIO_LOOPBACK_FAST_PATH option on Windows
alanb
parents:
25859
diff
changeset
|
750 |
JNIEXPORT jint JNICALL |
885f4428b501
8060170: Support SIO_LOOPBACK_FAST_PATH option on Windows
alanb
parents:
25859
diff
changeset
|
751 |
NET_EnableFastTcpLoopback(int fd) { |
885f4428b501
8060170: Support SIO_LOOPBACK_FAST_PATH option on Windows
alanb
parents:
25859
diff
changeset
|
752 |
return 0; |
885f4428b501
8060170: Support SIO_LOOPBACK_FAST_PATH option on Windows
alanb
parents:
25859
diff
changeset
|
753 |
} |
885f4428b501
8060170: Support SIO_LOOPBACK_FAST_PATH option on Windows
alanb
parents:
25859
diff
changeset
|
754 |
|
43100 | 755 |
/** |
756 |
* See net_util.h for documentation |
|
757 |
*/ |
|
2 | 758 |
JNIEXPORT int JNICALL |
43100 | 759 |
NET_InetAddressToSockaddr(JNIEnv *env, jobject iaObj, int port, |
760 |
SOCKETADDRESS *sa, int *len, |
|
761 |
jboolean v4MappedAddress) |
|
762 |
{ |
|
763 |
jint family = getInetAddress_family(env, iaObj); |
|
764 |
memset((char *)sa, 0, sizeof(SOCKETADDRESS)); |
|
765 |
||
766 |
if (ipv6_available() && |
|
767 |
!(family == java_net_InetAddress_IPv4 && |
|
768 |
v4MappedAddress == JNI_FALSE)) |
|
769 |
{ |
|
2 | 770 |
jbyte caddr[16]; |
771 |
jint address; |
|
772 |
||
41771
18c9669e76ca
8167481: cleanup of headers and includes for native libnet
clanger
parents:
41578
diff
changeset
|
773 |
if (family == java_net_InetAddress_IPv4) { |
18c9669e76ca
8167481: cleanup of headers and includes for native libnet
clanger
parents:
41578
diff
changeset
|
774 |
// convert to IPv4-mapped address |
43100 | 775 |
memset((char *)caddr, 0, 16); |
16870 | 776 |
address = getInetAddress_addr(env, iaObj); |
2 | 777 |
if (address == INADDR_ANY) { |
778 |
/* we would always prefer IPv6 wildcard address |
|
43100 | 779 |
* caddr[10] = 0xff; |
780 |
* caddr[11] = 0xff; */ |
|
2 | 781 |
} else { |
782 |
caddr[10] = 0xff; |
|
783 |
caddr[11] = 0xff; |
|
784 |
caddr[12] = ((address >> 24) & 0xff); |
|
785 |
caddr[13] = ((address >> 16) & 0xff); |
|
786 |
caddr[14] = ((address >> 8) & 0xff); |
|
787 |
caddr[15] = (address & 0xff); |
|
788 |
} |
|
789 |
} else { |
|
20821 | 790 |
getInet6Address_ipaddress(env, iaObj, (char *)caddr); |
2 | 791 |
} |
43100 | 792 |
sa->sa6.sin6_port = htons(port); |
793 |
memcpy((void *)&sa->sa6.sin6_addr, caddr, sizeof(struct in6_addr)); |
|
794 |
sa->sa6.sin6_family = AF_INET6; |
|
795 |
if (len != NULL) { |
|
796 |
*len = sizeof(struct sockaddr_in6); |
|
797 |
} |
|
2 | 798 |
|
43100 | 799 |
#ifdef __linux__ |
2 | 800 |
/* |
801 |
* On Linux if we are connecting to a link-local address |
|
802 |
* we need to specify the interface in the scope_id (2.4 kernel only) |
|
803 |
* |
|
43100 | 804 |
* If the scope was cached then we use the cached value. If not cached but |
2 | 805 |
* specified in the Inet6Address we use that, but we first check if the |
806 |
* address needs to be routed via the loopback interface. In this case, |
|
807 |
* we override the specified value with that of the loopback interface. |
|
808 |
* If no cached value exists and no value was specified by user, then |
|
13999
f6a2ce6a3e40
7193520: Removed references to Linux kernel version 2.2
chegar
parents:
13048
diff
changeset
|
809 |
* we try to determine a value from the routing table. In all these |
2 | 810 |
* cases the used value is cached for further use. |
811 |
*/ |
|
43100 | 812 |
if (IN6_IS_ADDR_LINKLOCAL(&sa->sa6.sin6_addr)) { |
813 |
unsigned int cached_scope_id = 0, scope_id = 0; |
|
2 | 814 |
|
13999
f6a2ce6a3e40
7193520: Removed references to Linux kernel version 2.2
chegar
parents:
13048
diff
changeset
|
815 |
if (ia6_cachedscopeidID) { |
2 | 816 |
cached_scope_id = (int)(*env)->GetIntField(env, iaObj, ia6_cachedscopeidID); |
817 |
/* if cached value exists then use it. Otherwise, check |
|
818 |
* if scope is set in the address. |
|
819 |
*/ |
|
820 |
if (!cached_scope_id) { |
|
821 |
if (ia6_scopeidID) { |
|
20821 | 822 |
scope_id = getInet6Address_scopeid(env, iaObj); |
2 | 823 |
} |
824 |
if (scope_id != 0) { |
|
825 |
/* check user-specified value for loopback case |
|
826 |
* that needs to be overridden |
|
827 |
*/ |
|
43100 | 828 |
if (kernelIsV24() && needsLoopbackRoute(&sa->sa6.sin6_addr)) { |
2 | 829 |
cached_scope_id = lo_scope_id; |
830 |
(*env)->SetIntField(env, iaObj, ia6_cachedscopeidID, cached_scope_id); |
|
831 |
} |
|
832 |
} else { |
|
833 |
/* |
|
834 |
* Otherwise consult the IPv6 routing tables to |
|
835 |
* try determine the appropriate interface. |
|
836 |
*/ |
|
837 |
if (kernelIsV24()) { |
|
43100 | 838 |
cached_scope_id = getDefaultIPv6Interface(&sa->sa6.sin6_addr); |
2 | 839 |
} else { |
43100 | 840 |
cached_scope_id = getLocalScopeID((char *)&(sa->sa6.sin6_addr)); |
2 | 841 |
if (cached_scope_id == 0) { |
43100 | 842 |
cached_scope_id = getDefaultIPv6Interface(&sa->sa6.sin6_addr); |
2 | 843 |
} |
844 |
} |
|
845 |
(*env)->SetIntField(env, iaObj, ia6_cachedscopeidID, cached_scope_id); |
|
846 |
} |
|
847 |
} |
|
848 |
} |
|
849 |
||
850 |
/* |
|
851 |
* If we have a scope_id use the extended form |
|
852 |
* of sockaddr_in6. |
|
853 |
*/ |
|
43100 | 854 |
sa->sa6.sin6_scope_id = cached_scope_id == 0 ? scope_id : cached_scope_id; |
2 | 855 |
} |
856 |
#else |
|
43100 | 857 |
/* handle scope_id */ |
41771
18c9669e76ca
8167481: cleanup of headers and includes for native libnet
clanger
parents:
41578
diff
changeset
|
858 |
if (family != java_net_InetAddress_IPv4) { |
2 | 859 |
if (ia6_scopeidID) { |
43100 | 860 |
sa->sa6.sin6_scope_id = getInet6Address_scopeid(env, iaObj); |
2 | 861 |
} |
862 |
} |
|
863 |
#endif |
|
41834
99c4f72c0a91
8168771: Remove #ifdef AF_INET6 guards in libnet native coding
clanger
parents:
41771
diff
changeset
|
864 |
} else { |
99c4f72c0a91
8168771: Remove #ifdef AF_INET6 guards in libnet native coding
clanger
parents:
41771
diff
changeset
|
865 |
jint address; |
43100 | 866 |
if (family != java_net_InetAddress_IPv4) { |
41834
99c4f72c0a91
8168771: Remove #ifdef AF_INET6 guards in libnet native coding
clanger
parents:
41771
diff
changeset
|
867 |
JNU_ThrowByName(env, JNU_JAVANETPKG "SocketException", "Protocol family unavailable"); |
99c4f72c0a91
8168771: Remove #ifdef AF_INET6 guards in libnet native coding
clanger
parents:
41771
diff
changeset
|
868 |
return -1; |
2 | 869 |
} |
41834
99c4f72c0a91
8168771: Remove #ifdef AF_INET6 guards in libnet native coding
clanger
parents:
41771
diff
changeset
|
870 |
address = getInetAddress_addr(env, iaObj); |
43100 | 871 |
sa->sa4.sin_port = htons(port); |
872 |
sa->sa4.sin_addr.s_addr = htonl(address); |
|
873 |
sa->sa4.sin_family = AF_INET; |
|
874 |
if (len != NULL) { |
|
875 |
*len = sizeof(struct sockaddr_in); |
|
876 |
} |
|
41834
99c4f72c0a91
8168771: Remove #ifdef AF_INET6 guards in libnet native coding
clanger
parents:
41771
diff
changeset
|
877 |
} |
2 | 878 |
return 0; |
879 |
} |
|
880 |
||
881 |
void |
|
43100 | 882 |
NET_SetTrafficClass(SOCKETADDRESS *sa, int trafficClass) { |
883 |
if (sa->sa.sa_family == AF_INET6) { |
|
884 |
sa->sa6.sin6_flowinfo = htonl((trafficClass & 0xff) << 20); |
|
41834
99c4f72c0a91
8168771: Remove #ifdef AF_INET6 guards in libnet native coding
clanger
parents:
41771
diff
changeset
|
885 |
} |
2 | 886 |
} |
887 |
||
888 |
int |
|
889 |
NET_IsIPv4Mapped(jbyte* caddr) { |
|
890 |
int i; |
|
891 |
for (i = 0; i < 10; i++) { |
|
892 |
if (caddr[i] != 0x00) { |
|
893 |
return 0; /* false */ |
|
894 |
} |
|
895 |
} |
|
896 |
||
897 |
if (((caddr[10] & 0xff) == 0xff) && ((caddr[11] & 0xff) == 0xff)) { |
|
898 |
return 1; /* true */ |
|
899 |
} |
|
900 |
return 0; /* false */ |
|
901 |
} |
|
902 |
||
903 |
int |
|
904 |
NET_IPv4MappedToIPv4(jbyte* caddr) { |
|
905 |
return ((caddr[12] & 0xff) << 24) | ((caddr[13] & 0xff) << 16) | ((caddr[14] & 0xff) << 8) |
|
906 |
| (caddr[15] & 0xff); |
|
907 |
} |
|
908 |
||
909 |
int |
|
910 |
NET_IsEqual(jbyte* caddr1, jbyte* caddr2) { |
|
911 |
int i; |
|
912 |
for (i = 0; i < 16; i++) { |
|
913 |
if (caddr1[i] != caddr2[i]) { |
|
914 |
return 0; /* false */ |
|
915 |
} |
|
916 |
} |
|
917 |
return 1; |
|
918 |
} |
|
919 |
||
12688
f15fd32c975e
7163874: InetAddress.isReachable should support pinging 0.0.0.0
youdwei
parents:
12551
diff
changeset
|
920 |
int NET_IsZeroAddr(jbyte* caddr) { |
f15fd32c975e
7163874: InetAddress.isReachable should support pinging 0.0.0.0
youdwei
parents:
12551
diff
changeset
|
921 |
int i; |
f15fd32c975e
7163874: InetAddress.isReachable should support pinging 0.0.0.0
youdwei
parents:
12551
diff
changeset
|
922 |
for (i = 0; i < 16; i++) { |
f15fd32c975e
7163874: InetAddress.isReachable should support pinging 0.0.0.0
youdwei
parents:
12551
diff
changeset
|
923 |
if (caddr[i] != 0) { |
f15fd32c975e
7163874: InetAddress.isReachable should support pinging 0.0.0.0
youdwei
parents:
12551
diff
changeset
|
924 |
return 0; |
f15fd32c975e
7163874: InetAddress.isReachable should support pinging 0.0.0.0
youdwei
parents:
12551
diff
changeset
|
925 |
} |
f15fd32c975e
7163874: InetAddress.isReachable should support pinging 0.0.0.0
youdwei
parents:
12551
diff
changeset
|
926 |
} |
f15fd32c975e
7163874: InetAddress.isReachable should support pinging 0.0.0.0
youdwei
parents:
12551
diff
changeset
|
927 |
return 1; |
f15fd32c975e
7163874: InetAddress.isReachable should support pinging 0.0.0.0
youdwei
parents:
12551
diff
changeset
|
928 |
} |
f15fd32c975e
7163874: InetAddress.isReachable should support pinging 0.0.0.0
youdwei
parents:
12551
diff
changeset
|
929 |
|
2 | 930 |
/* |
931 |
* Map the Java level socket option to the platform specific |
|
932 |
* level and option name. |
|
933 |
*/ |
|
934 |
int |
|
935 |
NET_MapSocketOption(jint cmd, int *level, int *optname) { |
|
936 |
static struct { |
|
937 |
jint cmd; |
|
938 |
int level; |
|
939 |
int optname; |
|
940 |
} const opts[] = { |
|
941 |
{ java_net_SocketOptions_TCP_NODELAY, IPPROTO_TCP, TCP_NODELAY }, |
|
942 |
{ java_net_SocketOptions_SO_OOBINLINE, SOL_SOCKET, SO_OOBINLINE }, |
|
943 |
{ java_net_SocketOptions_SO_LINGER, SOL_SOCKET, SO_LINGER }, |
|
944 |
{ java_net_SocketOptions_SO_SNDBUF, SOL_SOCKET, SO_SNDBUF }, |
|
945 |
{ java_net_SocketOptions_SO_RCVBUF, SOL_SOCKET, SO_RCVBUF }, |
|
946 |
{ java_net_SocketOptions_SO_KEEPALIVE, SOL_SOCKET, SO_KEEPALIVE }, |
|
947 |
{ java_net_SocketOptions_SO_REUSEADDR, SOL_SOCKET, SO_REUSEADDR }, |
|
36115 | 948 |
{ java_net_SocketOptions_SO_REUSEPORT, SOL_SOCKET, SO_REUSEPORT }, |
2 | 949 |
{ java_net_SocketOptions_SO_BROADCAST, SOL_SOCKET, SO_BROADCAST }, |
950 |
{ java_net_SocketOptions_IP_TOS, IPPROTO_IP, IP_TOS }, |
|
951 |
{ java_net_SocketOptions_IP_MULTICAST_IF, IPPROTO_IP, IP_MULTICAST_IF }, |
|
952 |
{ java_net_SocketOptions_IP_MULTICAST_IF2, IPPROTO_IP, IP_MULTICAST_IF }, |
|
953 |
{ java_net_SocketOptions_IP_MULTICAST_LOOP, IPPROTO_IP, IP_MULTICAST_LOOP }, |
|
954 |
}; |
|
955 |
||
956 |
int i; |
|
957 |
||
958 |
if (ipv6_available()) { |
|
959 |
switch (cmd) { |
|
30963
88469d06e03f
8072384: Setting IP_TOS on java.net sockets not working on unix
coffeys
parents:
28059
diff
changeset
|
960 |
// Different multicast options if IPv6 is enabled |
2 | 961 |
case java_net_SocketOptions_IP_MULTICAST_IF: |
962 |
case java_net_SocketOptions_IP_MULTICAST_IF2: |
|
963 |
*level = IPPROTO_IPV6; |
|
964 |
*optname = IPV6_MULTICAST_IF; |
|
965 |
return 0; |
|
966 |
||
967 |
case java_net_SocketOptions_IP_MULTICAST_LOOP: |
|
968 |
*level = IPPROTO_IPV6; |
|
969 |
*optname = IPV6_MULTICAST_LOOP; |
|
970 |
return 0; |
|
30963
88469d06e03f
8072384: Setting IP_TOS on java.net sockets not working on unix
coffeys
parents:
28059
diff
changeset
|
971 |
#if (defined(__solaris__) || defined(MACOSX)) |
88469d06e03f
8072384: Setting IP_TOS on java.net sockets not working on unix
coffeys
parents:
28059
diff
changeset
|
972 |
// Map IP_TOS request to IPV6_TCLASS |
88469d06e03f
8072384: Setting IP_TOS on java.net sockets not working on unix
coffeys
parents:
28059
diff
changeset
|
973 |
case java_net_SocketOptions_IP_TOS: |
88469d06e03f
8072384: Setting IP_TOS on java.net sockets not working on unix
coffeys
parents:
28059
diff
changeset
|
974 |
*level = IPPROTO_IPV6; |
88469d06e03f
8072384: Setting IP_TOS on java.net sockets not working on unix
coffeys
parents:
28059
diff
changeset
|
975 |
*optname = IPV6_TCLASS; |
88469d06e03f
8072384: Setting IP_TOS on java.net sockets not working on unix
coffeys
parents:
28059
diff
changeset
|
976 |
return 0; |
88469d06e03f
8072384: Setting IP_TOS on java.net sockets not working on unix
coffeys
parents:
28059
diff
changeset
|
977 |
#endif |
2 | 978 |
} |
979 |
} |
|
980 |
||
981 |
/* |
|
982 |
* Map the Java level option to the native level |
|
983 |
*/ |
|
984 |
for (i=0; i<(int)(sizeof(opts) / sizeof(opts[0])); i++) { |
|
985 |
if (cmd == opts[i].cmd) { |
|
986 |
*level = opts[i].level; |
|
987 |
*optname = opts[i].optname; |
|
988 |
return 0; |
|
989 |
} |
|
990 |
} |
|
991 |
||
992 |
/* not found */ |
|
993 |
return -1; |
|
994 |
} |
|
995 |
||
996 |
/* |
|
997 |
* Determine the default interface for an IPv6 address. |
|
998 |
* |
|
999 |
* 1. Scans /proc/net/ipv6_route for a matching route |
|
1000 |
* (eg: fe80::/10 or a route for the specific address). |
|
1001 |
* This will tell us the interface to use (eg: "eth0"). |
|
1002 |
* |
|
1003 |
* 2. Lookup /proc/net/if_inet6 to map the interface |
|
1004 |
* name to an interface index. |
|
1005 |
* |
|
1006 |
* Returns :- |
|
1007 |
* -1 if error |
|
1008 |
* 0 if no matching interface |
|
1009 |
* >1 interface index to use for the link-local address. |
|
1010 |
*/ |
|
41834
99c4f72c0a91
8168771: Remove #ifdef AF_INET6 guards in libnet native coding
clanger
parents:
41771
diff
changeset
|
1011 |
#if defined(__linux__) |
2 | 1012 |
int getDefaultIPv6Interface(struct in6_addr *target_addr) { |
1013 |
FILE *f; |
|
1014 |
char srcp[8][5]; |
|
1015 |
char hopp[8][5]; |
|
1016 |
int dest_plen, src_plen, use, refcnt, metric; |
|
1017 |
unsigned long flags; |
|
1018 |
char dest_str[40]; |
|
1019 |
struct in6_addr dest_addr; |
|
1020 |
char device[16]; |
|
1021 |
jboolean match = JNI_FALSE; |
|
1022 |
||
1023 |
/* |
|
1024 |
* Scan /proc/net/ipv6_route looking for a matching |
|
1025 |
* route. |
|
1026 |
*/ |
|
1027 |
if ((f = fopen("/proc/net/ipv6_route", "r")) == NULL) { |
|
1028 |
return -1; |
|
1029 |
} |
|
1030 |
while (fscanf(f, "%4s%4s%4s%4s%4s%4s%4s%4s %02x " |
|
1031 |
"%4s%4s%4s%4s%4s%4s%4s%4s %02x " |
|
1032 |
"%4s%4s%4s%4s%4s%4s%4s%4s " |
|
1033 |
"%08x %08x %08x %08lx %8s", |
|
1034 |
dest_str, &dest_str[5], &dest_str[10], &dest_str[15], |
|
1035 |
&dest_str[20], &dest_str[25], &dest_str[30], &dest_str[35], |
|
1036 |
&dest_plen, |
|
1037 |
srcp[0], srcp[1], srcp[2], srcp[3], |
|
1038 |
srcp[4], srcp[5], srcp[6], srcp[7], |
|
1039 |
&src_plen, |
|
1040 |
hopp[0], hopp[1], hopp[2], hopp[3], |
|
1041 |
hopp[4], hopp[5], hopp[6], hopp[7], |
|
1042 |
&metric, &use, &refcnt, &flags, device) == 31) { |
|
1043 |
||
1044 |
/* |
|
1045 |
* Some routes should be ignored |
|
1046 |
*/ |
|
1047 |
if ( (dest_plen < 0 || dest_plen > 128) || |
|
1048 |
(src_plen != 0) || |
|
1049 |
(flags & (RTF_POLICY | RTF_FLOW)) || |
|
1050 |
((flags & RTF_REJECT) && dest_plen == 0) ) { |
|
1051 |
continue; |
|
1052 |
} |
|
1053 |
||
1054 |
/* |
|
1055 |
* Convert the destination address |
|
1056 |
*/ |
|
1057 |
dest_str[4] = ':'; |
|
1058 |
dest_str[9] = ':'; |
|
1059 |
dest_str[14] = ':'; |
|
1060 |
dest_str[19] = ':'; |
|
1061 |
dest_str[24] = ':'; |
|
1062 |
dest_str[29] = ':'; |
|
1063 |
dest_str[34] = ':'; |
|
1064 |
dest_str[39] = '\0'; |
|
1065 |
||
1066 |
if (inet_pton(AF_INET6, dest_str, &dest_addr) < 0) { |
|
1067 |
/* not an Ipv6 address */ |
|
1068 |
continue; |
|
1069 |
} else { |
|
1070 |
/* |
|
1071 |
* The prefix len (dest_plen) indicates the number of bits we |
|
1072 |
* need to match on. |
|
1073 |
* |
|
1074 |
* dest_plen / 8 => number of bytes to match |
|
1075 |
* dest_plen % 8 => number of additional bits to match |
|
1076 |
* |
|
1077 |
* eg: fe80::/10 => match 1 byte + 2 additional bits in the |
|
1078 |
* the next byte. |
|
1079 |
*/ |
|
1080 |
int byte_count = dest_plen >> 3; |
|
1081 |
int extra_bits = dest_plen & 0x3; |
|
1082 |
||
1083 |
if (byte_count > 0) { |
|
1084 |
if (memcmp(target_addr, &dest_addr, byte_count)) { |
|
1085 |
continue; /* no match */ |
|
1086 |
} |
|
1087 |
} |
|
1088 |
||
1089 |
if (extra_bits > 0) { |
|
1090 |
unsigned char c1 = ((unsigned char *)target_addr)[byte_count]; |
|
1091 |
unsigned char c2 = ((unsigned char *)&dest_addr)[byte_count]; |
|
1092 |
unsigned char mask = 0xff << (8 - extra_bits); |
|
1093 |
if ((c1 & mask) != (c2 & mask)) { |
|
1094 |
continue; |
|
1095 |
} |
|
1096 |
} |
|
1097 |
||
1098 |
/* |
|
1099 |
* We have a match |
|
1100 |
*/ |
|
1101 |
match = JNI_TRUE; |
|
1102 |
break; |
|
1103 |
} |
|
1104 |
} |
|
1105 |
fclose(f); |
|
1106 |
||
1107 |
/* |
|
1108 |
* If there's a match then we lookup the interface |
|
1109 |
* index. |
|
1110 |
*/ |
|
1111 |
if (match) { |
|
8554
14e626e9407b
7022269: clean up fscanf usage in Linux networking native code
chegar
parents:
7668
diff
changeset
|
1112 |
char devname[21]; |
2 | 1113 |
char addr6p[8][5]; |
1114 |
int plen, scope, dad_status, if_idx; |
|
1115 |
||
1116 |
if ((f = fopen("/proc/net/if_inet6", "r")) != NULL) { |
|
11514
0cefabc1c81f
7123415: Some cases of network interface indexes being read incorrectly
chegar
parents:
11032
diff
changeset
|
1117 |
while (fscanf(f, "%4s%4s%4s%4s%4s%4s%4s%4s %08x %02x %02x %02x %20s\n", |
2 | 1118 |
addr6p[0], addr6p[1], addr6p[2], addr6p[3], |
1119 |
addr6p[4], addr6p[5], addr6p[6], addr6p[7], |
|
1120 |
&if_idx, &plen, &scope, &dad_status, devname) == 13) { |
|
1121 |
||
1122 |
if (strcmp(devname, device) == 0) { |
|
1123 |
/* |
|
1124 |
* Found - so just return the index |
|
1125 |
*/ |
|
1126 |
fclose(f); |
|
1127 |
return if_idx; |
|
1128 |
} |
|
1129 |
} |
|
1130 |
fclose(f); |
|
1131 |
} else { |
|
1132 |
/* |
|
1133 |
* Couldn't open /proc/net/if_inet6 |
|
1134 |
*/ |
|
1135 |
return -1; |
|
1136 |
} |
|
1137 |
} |
|
1138 |
||
1139 |
/* |
|
1140 |
* If we get here it means we didn't there wasn't any |
|
1141 |
* route or we couldn't get the index of the interface. |
|
1142 |
*/ |
|
1143 |
return 0; |
|
1144 |
} |
|
1145 |
#endif |
|
1146 |
||
1147 |
||
1148 |
/* |
|
1149 |
* Wrapper for getsockopt system routine - does any necessary |
|
13999
f6a2ce6a3e40
7193520: Removed references to Linux kernel version 2.2
chegar
parents:
13048
diff
changeset
|
1150 |
* pre/post processing to deal with OS specific oddities :- |
2 | 1151 |
* |
1152 |
* On Linux the SO_SNDBUF/SO_RCVBUF values must be post-processed |
|
1153 |
* to compensate for an incorrect value returned by the kernel. |
|
1154 |
*/ |
|
1155 |
int |
|
1156 |
NET_GetSockOpt(int fd, int level, int opt, void *result, |
|
1157 |
int *len) |
|
1158 |
{ |
|
1159 |
int rv; |
|
23015
73b21ab36615
8034174: Remove use of JVM_* functions from java.net code
chegar
parents:
23010
diff
changeset
|
1160 |
socklen_t socklen = *len; |
2 | 1161 |
|
23015
73b21ab36615
8034174: Remove use of JVM_* functions from java.net code
chegar
parents:
23010
diff
changeset
|
1162 |
rv = getsockopt(fd, level, opt, result, &socklen); |
73b21ab36615
8034174: Remove use of JVM_* functions from java.net code
chegar
parents:
23010
diff
changeset
|
1163 |
*len = socklen; |
911
9edd1b9607e2
6730740: Fix for 6729881 has apparently broken several 64 bit tests: "Bad address"
chegar
parents:
910
diff
changeset
|
1164 |
|
2 | 1165 |
if (rv < 0) { |
1166 |
return rv; |
|
1167 |
} |
|
1168 |
||
1169 |
#ifdef __linux__ |
|
1170 |
/* |
|
1171 |
* On Linux SO_SNDBUF/SO_RCVBUF aren't symmetric. This |
|
1172 |
* stems from additional socket structures in the send |
|
1173 |
* and receive buffers. |
|
1174 |
*/ |
|
1175 |
if ((level == SOL_SOCKET) && ((opt == SO_SNDBUF) |
|
1176 |
|| (opt == SO_RCVBUF))) { |
|
1177 |
int n = *((int *)result); |
|
1178 |
n /= 2; |
|
1179 |
*((int *)result) = n; |
|
1180 |
} |
|
1181 |
#endif |
|
1182 |
||
12047
320a714614e9
7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
11514
diff
changeset
|
1183 |
/* Workaround for Mac OS treating linger value as |
320a714614e9
7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
11514
diff
changeset
|
1184 |
* signed integer |
320a714614e9
7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
11514
diff
changeset
|
1185 |
*/ |
320a714614e9
7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
11514
diff
changeset
|
1186 |
#ifdef MACOSX |
320a714614e9
7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
11514
diff
changeset
|
1187 |
if (level == SOL_SOCKET && opt == SO_LINGER) { |
320a714614e9
7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
11514
diff
changeset
|
1188 |
struct linger* to_cast = (struct linger*)result; |
320a714614e9
7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
11514
diff
changeset
|
1189 |
to_cast->l_linger = (unsigned short)to_cast->l_linger; |
320a714614e9
7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
11514
diff
changeset
|
1190 |
} |
320a714614e9
7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
11514
diff
changeset
|
1191 |
#endif |
2 | 1192 |
return rv; |
1193 |
} |
|
1194 |
||
1195 |
/* |
|
1196 |
* Wrapper for setsockopt system routine - performs any |
|
1197 |
* necessary pre/post processing to deal with OS specific |
|
1198 |
* issue :- |
|
1199 |
* |
|
1200 |
* On Solaris need to limit the suggested value for SO_SNDBUF |
|
1201 |
* and SO_RCVBUF to the kernel configured limit |
|
1202 |
* |
|
1203 |
* For IP_TOS socket option need to mask off bits as this |
|
1204 |
* aren't automatically masked by the kernel and results in |
|
30963
88469d06e03f
8072384: Setting IP_TOS on java.net sockets not working on unix
coffeys
parents:
28059
diff
changeset
|
1205 |
* an error. |
2 | 1206 |
*/ |
1207 |
int |
|
1208 |
NET_SetSockOpt(int fd, int level, int opt, const void *arg, |
|
1209 |
int len) |
|
1210 |
{ |
|
22605
dba3d6b22818
8031581: PPC64: Addons and fixes for AIX to pass the jdk regression tests
simonis
parents:
22597
diff
changeset
|
1211 |
|
2 | 1212 |
#ifndef IPTOS_TOS_MASK |
1213 |
#define IPTOS_TOS_MASK 0x1e |
|
1214 |
#endif |
|
1215 |
#ifndef IPTOS_PREC_MASK |
|
1216 |
#define IPTOS_PREC_MASK 0xe0 |
|
1217 |
#endif |
|
1218 |
||
12047
320a714614e9
7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
11514
diff
changeset
|
1219 |
#if defined(_ALLBSD_SOURCE) |
320a714614e9
7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
11514
diff
changeset
|
1220 |
#if defined(KIPC_MAXSOCKBUF) |
320a714614e9
7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
11514
diff
changeset
|
1221 |
int mib[3]; |
320a714614e9
7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
11514
diff
changeset
|
1222 |
size_t rlen; |
320a714614e9
7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
11514
diff
changeset
|
1223 |
#endif |
320a714614e9
7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
11514
diff
changeset
|
1224 |
|
320a714614e9
7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
11514
diff
changeset
|
1225 |
int *bufsize; |
320a714614e9
7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
11514
diff
changeset
|
1226 |
|
320a714614e9
7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
11514
diff
changeset
|
1227 |
#ifdef __APPLE__ |
320a714614e9
7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
11514
diff
changeset
|
1228 |
static int maxsockbuf = -1; |
320a714614e9
7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
11514
diff
changeset
|
1229 |
#else |
320a714614e9
7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
11514
diff
changeset
|
1230 |
static long maxsockbuf = -1; |
320a714614e9
7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
11514
diff
changeset
|
1231 |
#endif |
320a714614e9
7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
11514
diff
changeset
|
1232 |
#endif |
320a714614e9
7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
11514
diff
changeset
|
1233 |
|
2 | 1234 |
/* |
1235 |
* IPPROTO/IP_TOS :- |
|
30963
88469d06e03f
8072384: Setting IP_TOS on java.net sockets not working on unix
coffeys
parents:
28059
diff
changeset
|
1236 |
* 1. IPv6 on Solaris/Mac OS: |
88469d06e03f
8072384: Setting IP_TOS on java.net sockets not working on unix
coffeys
parents:
28059
diff
changeset
|
1237 |
* Set the TOS OR Traffic Class value to cater for |
88469d06e03f
8072384: Setting IP_TOS on java.net sockets not working on unix
coffeys
parents:
28059
diff
changeset
|
1238 |
* IPv6 and IPv4 scenarios. |
2 | 1239 |
* 2. IPv6 on Linux: By default Linux ignores flowinfo |
1240 |
* field so enable IPV6_FLOWINFO_SEND so that flowinfo |
|
25170
f58832169add
8029607: Type of Service (TOS) cannot be set in IPv6 header
michaelm
parents:
23033
diff
changeset
|
1241 |
* will be examined. We also set the IPv4 TOS option in this case. |
2 | 1242 |
* 3. IPv4: set socket option based on ToS and Precedence |
1243 |
* fields (otherwise get invalid argument) |
|
1244 |
*/ |
|
1245 |
if (level == IPPROTO_IP && opt == IP_TOS) { |
|
1246 |
int *iptos; |
|
1247 |
||
41834
99c4f72c0a91
8168771: Remove #ifdef AF_INET6 guards in libnet native coding
clanger
parents:
41771
diff
changeset
|
1248 |
#if defined(__linux__) |
2 | 1249 |
if (ipv6_available()) { |
1250 |
int optval = 1; |
|
25170
f58832169add
8029607: Type of Service (TOS) cannot be set in IPv6 header
michaelm
parents:
23033
diff
changeset
|
1251 |
if (setsockopt(fd, IPPROTO_IPV6, IPV6_FLOWINFO_SEND, |
f58832169add
8029607: Type of Service (TOS) cannot be set in IPv6 header
michaelm
parents:
23033
diff
changeset
|
1252 |
(void *)&optval, sizeof(optval)) < 0) { |
f58832169add
8029607: Type of Service (TOS) cannot be set in IPv6 header
michaelm
parents:
23033
diff
changeset
|
1253 |
return -1; |
f58832169add
8029607: Type of Service (TOS) cannot be set in IPv6 header
michaelm
parents:
23033
diff
changeset
|
1254 |
} |
30963
88469d06e03f
8072384: Setting IP_TOS on java.net sockets not working on unix
coffeys
parents:
28059
diff
changeset
|
1255 |
/* |
88469d06e03f
8072384: Setting IP_TOS on java.net sockets not working on unix
coffeys
parents:
28059
diff
changeset
|
1256 |
* Let's also set the IPV6_TCLASS flag. |
88469d06e03f
8072384: Setting IP_TOS on java.net sockets not working on unix
coffeys
parents:
28059
diff
changeset
|
1257 |
* Linux appears to allow both IP_TOS and IPV6_TCLASS to be set |
88469d06e03f
8072384: Setting IP_TOS on java.net sockets not working on unix
coffeys
parents:
28059
diff
changeset
|
1258 |
* This helps in mixed environments where IPv4 and IPv6 sockets |
88469d06e03f
8072384: Setting IP_TOS on java.net sockets not working on unix
coffeys
parents:
28059
diff
changeset
|
1259 |
* are connecting. |
88469d06e03f
8072384: Setting IP_TOS on java.net sockets not working on unix
coffeys
parents:
28059
diff
changeset
|
1260 |
*/ |
88469d06e03f
8072384: Setting IP_TOS on java.net sockets not working on unix
coffeys
parents:
28059
diff
changeset
|
1261 |
if (setsockopt(fd, IPPROTO_IPV6, IPV6_TCLASS, |
88469d06e03f
8072384: Setting IP_TOS on java.net sockets not working on unix
coffeys
parents:
28059
diff
changeset
|
1262 |
arg, len) < 0) { |
88469d06e03f
8072384: Setting IP_TOS on java.net sockets not working on unix
coffeys
parents:
28059
diff
changeset
|
1263 |
return -1; |
88469d06e03f
8072384: Setting IP_TOS on java.net sockets not working on unix
coffeys
parents:
28059
diff
changeset
|
1264 |
} |
2 | 1265 |
} |
1266 |
#endif |
|
1267 |
||
1268 |
iptos = (int *)arg; |
|
1269 |
*iptos &= (IPTOS_TOS_MASK | IPTOS_PREC_MASK); |
|
1270 |
} |
|
1271 |
||
1272 |
/* |
|
6696
7201f23dae0d
6989190: SO_SNDBUF/SO_RCVBUF limits should only be checked when setsockopt fails (sol)
alanb
parents:
6670
diff
changeset
|
1273 |
* SOL_SOCKET/{SO_SNDBUF,SO_RCVBUF} - On Solaris we may need to clamp |
7201f23dae0d
6989190: SO_SNDBUF/SO_RCVBUF limits should only be checked when setsockopt fails (sol)
alanb
parents:
6670
diff
changeset
|
1274 |
* the value when it exceeds the system limit. |
2 | 1275 |
*/ |
1276 |
#ifdef __solaris__ |
|
1277 |
if (level == SOL_SOCKET) { |
|
1278 |
if (opt == SO_SNDBUF || opt == SO_RCVBUF) { |
|
23015
73b21ab36615
8034174: Remove use of JVM_* functions from java.net code
chegar
parents:
23010
diff
changeset
|
1279 |
int sotype=0; |
73b21ab36615
8034174: Remove use of JVM_* functions from java.net code
chegar
parents:
23010
diff
changeset
|
1280 |
socklen_t arglen; |
2 | 1281 |
int *bufsize, maxbuf; |
6696
7201f23dae0d
6989190: SO_SNDBUF/SO_RCVBUF limits should only be checked when setsockopt fails (sol)
alanb
parents:
6670
diff
changeset
|
1282 |
int ret; |
7201f23dae0d
6989190: SO_SNDBUF/SO_RCVBUF limits should only be checked when setsockopt fails (sol)
alanb
parents:
6670
diff
changeset
|
1283 |
|
7201f23dae0d
6989190: SO_SNDBUF/SO_RCVBUF limits should only be checked when setsockopt fails (sol)
alanb
parents:
6670
diff
changeset
|
1284 |
/* Attempt with the original size */ |
7201f23dae0d
6989190: SO_SNDBUF/SO_RCVBUF limits should only be checked when setsockopt fails (sol)
alanb
parents:
6670
diff
changeset
|
1285 |
ret = setsockopt(fd, level, opt, arg, len); |
7201f23dae0d
6989190: SO_SNDBUF/SO_RCVBUF limits should only be checked when setsockopt fails (sol)
alanb
parents:
6670
diff
changeset
|
1286 |
if ((ret == 0) || (ret == -1 && errno != ENOBUFS)) |
7201f23dae0d
6989190: SO_SNDBUF/SO_RCVBUF limits should only be checked when setsockopt fails (sol)
alanb
parents:
6670
diff
changeset
|
1287 |
return ret; |
7201f23dae0d
6989190: SO_SNDBUF/SO_RCVBUF limits should only be checked when setsockopt fails (sol)
alanb
parents:
6670
diff
changeset
|
1288 |
|
7201f23dae0d
6989190: SO_SNDBUF/SO_RCVBUF limits should only be checked when setsockopt fails (sol)
alanb
parents:
6670
diff
changeset
|
1289 |
/* Exceeded system limit so clamp and retry */ |
2 | 1290 |
|
1291 |
arglen = sizeof(sotype); |
|
1292 |
if (getsockopt(fd, SOL_SOCKET, SO_TYPE, (void *)&sotype, |
|
1293 |
&arglen) < 0) { |
|
1294 |
return -1; |
|
1295 |
} |
|
1296 |
||
7289
1352201521d9
6984182: Setting SO_RCVBUF/SO_SNDBUF to larger than tcp_max_buf fails on Solaris 11 if kernel params changed
michaelm
parents:
6696
diff
changeset
|
1297 |
/* |
1352201521d9
6984182: Setting SO_RCVBUF/SO_SNDBUF to larger than tcp_max_buf fails on Solaris 11 if kernel params changed
michaelm
parents:
6696
diff
changeset
|
1298 |
* We try to get tcp_maxbuf (and udp_max_buf) using |
1352201521d9
6984182: Setting SO_RCVBUF/SO_SNDBUF to larger than tcp_max_buf fails on Solaris 11 if kernel params changed
michaelm
parents:
6696
diff
changeset
|
1299 |
* an ioctl() that isn't available on all versions of Solaris. |
1352201521d9
6984182: Setting SO_RCVBUF/SO_SNDBUF to larger than tcp_max_buf fails on Solaris 11 if kernel params changed
michaelm
parents:
6696
diff
changeset
|
1300 |
* If that fails, we use the search algorithm in findMaxBuf() |
1352201521d9
6984182: Setting SO_RCVBUF/SO_SNDBUF to larger than tcp_max_buf fails on Solaris 11 if kernel params changed
michaelm
parents:
6696
diff
changeset
|
1301 |
*/ |
1352201521d9
6984182: Setting SO_RCVBUF/SO_SNDBUF to larger than tcp_max_buf fails on Solaris 11 if kernel params changed
michaelm
parents:
6696
diff
changeset
|
1302 |
if (!init_tcp_max_buf && sotype == SOCK_STREAM) { |
22341
4689530d03b9
8028293: Check local configuration for actual ephemeral port range
michaelm
parents:
20821
diff
changeset
|
1303 |
tcp_max_buf = net_getParam("/dev/tcp", "tcp_max_buf"); |
7289
1352201521d9
6984182: Setting SO_RCVBUF/SO_SNDBUF to larger than tcp_max_buf fails on Solaris 11 if kernel params changed
michaelm
parents:
6696
diff
changeset
|
1304 |
if (tcp_max_buf == -1) { |
1352201521d9
6984182: Setting SO_RCVBUF/SO_SNDBUF to larger than tcp_max_buf fails on Solaris 11 if kernel params changed
michaelm
parents:
6696
diff
changeset
|
1305 |
tcp_max_buf = findMaxBuf(fd, opt, SOCK_STREAM); |
1352201521d9
6984182: Setting SO_RCVBUF/SO_SNDBUF to larger than tcp_max_buf fails on Solaris 11 if kernel params changed
michaelm
parents:
6696
diff
changeset
|
1306 |
if (tcp_max_buf == -1) { |
1352201521d9
6984182: Setting SO_RCVBUF/SO_SNDBUF to larger than tcp_max_buf fails on Solaris 11 if kernel params changed
michaelm
parents:
6696
diff
changeset
|
1307 |
return -1; |
1352201521d9
6984182: Setting SO_RCVBUF/SO_SNDBUF to larger than tcp_max_buf fails on Solaris 11 if kernel params changed
michaelm
parents:
6696
diff
changeset
|
1308 |
} |
1352201521d9
6984182: Setting SO_RCVBUF/SO_SNDBUF to larger than tcp_max_buf fails on Solaris 11 if kernel params changed
michaelm
parents:
6696
diff
changeset
|
1309 |
} |
1352201521d9
6984182: Setting SO_RCVBUF/SO_SNDBUF to larger than tcp_max_buf fails on Solaris 11 if kernel params changed
michaelm
parents:
6696
diff
changeset
|
1310 |
init_tcp_max_buf = 1; |
1352201521d9
6984182: Setting SO_RCVBUF/SO_SNDBUF to larger than tcp_max_buf fails on Solaris 11 if kernel params changed
michaelm
parents:
6696
diff
changeset
|
1311 |
} else if (!init_udp_max_buf && sotype == SOCK_DGRAM) { |
22341
4689530d03b9
8028293: Check local configuration for actual ephemeral port range
michaelm
parents:
20821
diff
changeset
|
1312 |
udp_max_buf = net_getParam("/dev/udp", "udp_max_buf"); |
7289
1352201521d9
6984182: Setting SO_RCVBUF/SO_SNDBUF to larger than tcp_max_buf fails on Solaris 11 if kernel params changed
michaelm
parents:
6696
diff
changeset
|
1313 |
if (udp_max_buf == -1) { |
1352201521d9
6984182: Setting SO_RCVBUF/SO_SNDBUF to larger than tcp_max_buf fails on Solaris 11 if kernel params changed
michaelm
parents:
6696
diff
changeset
|
1314 |
udp_max_buf = findMaxBuf(fd, opt, SOCK_DGRAM); |
1352201521d9
6984182: Setting SO_RCVBUF/SO_SNDBUF to larger than tcp_max_buf fails on Solaris 11 if kernel params changed
michaelm
parents:
6696
diff
changeset
|
1315 |
if (udp_max_buf == -1) { |
1352201521d9
6984182: Setting SO_RCVBUF/SO_SNDBUF to larger than tcp_max_buf fails on Solaris 11 if kernel params changed
michaelm
parents:
6696
diff
changeset
|
1316 |
return -1; |
1352201521d9
6984182: Setting SO_RCVBUF/SO_SNDBUF to larger than tcp_max_buf fails on Solaris 11 if kernel params changed
michaelm
parents:
6696
diff
changeset
|
1317 |
} |
1352201521d9
6984182: Setting SO_RCVBUF/SO_SNDBUF to larger than tcp_max_buf fails on Solaris 11 if kernel params changed
michaelm
parents:
6696
diff
changeset
|
1318 |
} |
1352201521d9
6984182: Setting SO_RCVBUF/SO_SNDBUF to larger than tcp_max_buf fails on Solaris 11 if kernel params changed
michaelm
parents:
6696
diff
changeset
|
1319 |
init_udp_max_buf = 1; |
1352201521d9
6984182: Setting SO_RCVBUF/SO_SNDBUF to larger than tcp_max_buf fails on Solaris 11 if kernel params changed
michaelm
parents:
6696
diff
changeset
|
1320 |
} |
1352201521d9
6984182: Setting SO_RCVBUF/SO_SNDBUF to larger than tcp_max_buf fails on Solaris 11 if kernel params changed
michaelm
parents:
6696
diff
changeset
|
1321 |
|
2 | 1322 |
maxbuf = (sotype == SOCK_STREAM) ? tcp_max_buf : udp_max_buf; |
1323 |
bufsize = (int *)arg; |
|
1324 |
if (*bufsize > maxbuf) { |
|
1325 |
*bufsize = maxbuf; |
|
1326 |
} |
|
1327 |
} |
|
1328 |
} |
|
1329 |
#endif |
|
1330 |
||
22597
7515a991bb37
8024854: PPC64: Basic changes and files to build the class library on AIX
simonis
parents:
20821
diff
changeset
|
1331 |
#ifdef _AIX |
7515a991bb37
8024854: PPC64: Basic changes and files to build the class library on AIX
simonis
parents:
20821
diff
changeset
|
1332 |
if (level == SOL_SOCKET) { |
7515a991bb37
8024854: PPC64: Basic changes and files to build the class library on AIX
simonis
parents:
20821
diff
changeset
|
1333 |
if (opt == SO_SNDBUF || opt == SO_RCVBUF) { |
7515a991bb37
8024854: PPC64: Basic changes and files to build the class library on AIX
simonis
parents:
20821
diff
changeset
|
1334 |
/* |
7515a991bb37
8024854: PPC64: Basic changes and files to build the class library on AIX
simonis
parents:
20821
diff
changeset
|
1335 |
* Just try to set the requested size. If it fails we will leave the |
7515a991bb37
8024854: PPC64: Basic changes and files to build the class library on AIX
simonis
parents:
20821
diff
changeset
|
1336 |
* socket option as is. Setting the buffer size means only a hint in |
7515a991bb37
8024854: PPC64: Basic changes and files to build the class library on AIX
simonis
parents:
20821
diff
changeset
|
1337 |
* the jse2/java software layer, see javadoc. In the previous |
7515a991bb37
8024854: PPC64: Basic changes and files to build the class library on AIX
simonis
parents:
20821
diff
changeset
|
1338 |
* solution the buffer has always been truncated to a length of |
7515a991bb37
8024854: PPC64: Basic changes and files to build the class library on AIX
simonis
parents:
20821
diff
changeset
|
1339 |
* 0x100000 Byte, even if the technical limit has not been reached. |
7515a991bb37
8024854: PPC64: Basic changes and files to build the class library on AIX
simonis
parents:
20821
diff
changeset
|
1340 |
* This kind of absolute truncation was unexpected in the jck tests. |
7515a991bb37
8024854: PPC64: Basic changes and files to build the class library on AIX
simonis
parents:
20821
diff
changeset
|
1341 |
*/ |
7515a991bb37
8024854: PPC64: Basic changes and files to build the class library on AIX
simonis
parents:
20821
diff
changeset
|
1342 |
int ret = setsockopt(fd, level, opt, arg, len); |
7515a991bb37
8024854: PPC64: Basic changes and files to build the class library on AIX
simonis
parents:
20821
diff
changeset
|
1343 |
if ((ret == 0) || (ret == -1 && errno == ENOBUFS)) { |
7515a991bb37
8024854: PPC64: Basic changes and files to build the class library on AIX
simonis
parents:
20821
diff
changeset
|
1344 |
// Accept failure because of insufficient buffer memory resources. |
7515a991bb37
8024854: PPC64: Basic changes and files to build the class library on AIX
simonis
parents:
20821
diff
changeset
|
1345 |
return 0; |
7515a991bb37
8024854: PPC64: Basic changes and files to build the class library on AIX
simonis
parents:
20821
diff
changeset
|
1346 |
} else { |
7515a991bb37
8024854: PPC64: Basic changes and files to build the class library on AIX
simonis
parents:
20821
diff
changeset
|
1347 |
// Deliver all other kinds of errors. |
7515a991bb37
8024854: PPC64: Basic changes and files to build the class library on AIX
simonis
parents:
20821
diff
changeset
|
1348 |
return ret; |
7515a991bb37
8024854: PPC64: Basic changes and files to build the class library on AIX
simonis
parents:
20821
diff
changeset
|
1349 |
} |
7515a991bb37
8024854: PPC64: Basic changes and files to build the class library on AIX
simonis
parents:
20821
diff
changeset
|
1350 |
} |
7515a991bb37
8024854: PPC64: Basic changes and files to build the class library on AIX
simonis
parents:
20821
diff
changeset
|
1351 |
} |
7515a991bb37
8024854: PPC64: Basic changes and files to build the class library on AIX
simonis
parents:
20821
diff
changeset
|
1352 |
#endif |
7515a991bb37
8024854: PPC64: Basic changes and files to build the class library on AIX
simonis
parents:
20821
diff
changeset
|
1353 |
|
2 | 1354 |
/* |
1355 |
* On Linux the receive buffer is used for both socket |
|
28059
e576535359cc
8067377: My hobby: caning, then then canning, the the can-can
martin
parents:
27178
diff
changeset
|
1356 |
* structures and the packet payload. The implication |
2 | 1357 |
* is that if SO_RCVBUF is too small then small packets |
30963
88469d06e03f
8072384: Setting IP_TOS on java.net sockets not working on unix
coffeys
parents:
28059
diff
changeset
|
1358 |
* must be discarded. |
2 | 1359 |
*/ |
1360 |
#ifdef __linux__ |
|
1361 |
if (level == SOL_SOCKET && opt == SO_RCVBUF) { |
|
1362 |
int *bufsize = (int *)arg; |
|
1363 |
if (*bufsize < 1024) { |
|
1364 |
*bufsize = 1024; |
|
1365 |
} |
|
1366 |
} |
|
1367 |
#endif |
|
1368 |
||
12047
320a714614e9
7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
11514
diff
changeset
|
1369 |
#if defined(_ALLBSD_SOURCE) |
320a714614e9
7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
11514
diff
changeset
|
1370 |
/* |
320a714614e9
7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
11514
diff
changeset
|
1371 |
* SOL_SOCKET/{SO_SNDBUF,SO_RCVBUF} - On FreeBSD need to |
320a714614e9
7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
11514
diff
changeset
|
1372 |
* ensure that value is <= kern.ipc.maxsockbuf as otherwise we get |
320a714614e9
7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
11514
diff
changeset
|
1373 |
* an ENOBUFS error. |
320a714614e9
7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
11514
diff
changeset
|
1374 |
*/ |
320a714614e9
7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
11514
diff
changeset
|
1375 |
if (level == SOL_SOCKET) { |
320a714614e9
7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
11514
diff
changeset
|
1376 |
if (opt == SO_SNDBUF || opt == SO_RCVBUF) { |
320a714614e9
7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
11514
diff
changeset
|
1377 |
#ifdef KIPC_MAXSOCKBUF |
320a714614e9
7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
11514
diff
changeset
|
1378 |
if (maxsockbuf == -1) { |
320a714614e9
7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
11514
diff
changeset
|
1379 |
mib[0] = CTL_KERN; |
320a714614e9
7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
11514
diff
changeset
|
1380 |
mib[1] = KERN_IPC; |
320a714614e9
7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
11514
diff
changeset
|
1381 |
mib[2] = KIPC_MAXSOCKBUF; |
320a714614e9
7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
11514
diff
changeset
|
1382 |
rlen = sizeof(maxsockbuf); |
320a714614e9
7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
11514
diff
changeset
|
1383 |
if (sysctl(mib, 3, &maxsockbuf, &rlen, NULL, 0) == -1) |
320a714614e9
7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
11514
diff
changeset
|
1384 |
maxsockbuf = 1024; |
320a714614e9
7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
11514
diff
changeset
|
1385 |
|
320a714614e9
7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
11514
diff
changeset
|
1386 |
#if 1 |
320a714614e9
7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
11514
diff
changeset
|
1387 |
/* XXXBSD: This is a hack to workaround mb_max/mb_max_adj |
320a714614e9
7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
11514
diff
changeset
|
1388 |
problem. It should be removed when kern.ipc.maxsockbuf |
320a714614e9
7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
11514
diff
changeset
|
1389 |
will be real value. */ |
320a714614e9
7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
11514
diff
changeset
|
1390 |
maxsockbuf = (maxsockbuf/5)*4; |
320a714614e9
7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
11514
diff
changeset
|
1391 |
#endif |
320a714614e9
7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
11514
diff
changeset
|
1392 |
} |
320a714614e9
7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
11514
diff
changeset
|
1393 |
#elif defined(__OpenBSD__) |
320a714614e9
7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
11514
diff
changeset
|
1394 |
maxsockbuf = SB_MAX; |
320a714614e9
7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
11514
diff
changeset
|
1395 |
#else |
320a714614e9
7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
11514
diff
changeset
|
1396 |
maxsockbuf = 64 * 1024; /* XXX: NetBSD */ |
320a714614e9
7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
11514
diff
changeset
|
1397 |
#endif |
320a714614e9
7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
11514
diff
changeset
|
1398 |
|
320a714614e9
7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
11514
diff
changeset
|
1399 |
bufsize = (int *)arg; |
320a714614e9
7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
11514
diff
changeset
|
1400 |
if (*bufsize > maxsockbuf) { |
320a714614e9
7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
11514
diff
changeset
|
1401 |
*bufsize = maxsockbuf; |
320a714614e9
7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
11514
diff
changeset
|
1402 |
} |
320a714614e9
7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
11514
diff
changeset
|
1403 |
|
320a714614e9
7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
11514
diff
changeset
|
1404 |
if (opt == SO_RCVBUF && *bufsize < 1024) { |
320a714614e9
7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
11514
diff
changeset
|
1405 |
*bufsize = 1024; |
320a714614e9
7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
11514
diff
changeset
|
1406 |
} |
320a714614e9
7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
11514
diff
changeset
|
1407 |
|
320a714614e9
7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
11514
diff
changeset
|
1408 |
} |
320a714614e9
7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
11514
diff
changeset
|
1409 |
} |
22605
dba3d6b22818
8031581: PPC64: Addons and fixes for AIX to pass the jdk regression tests
simonis
parents:
22597
diff
changeset
|
1410 |
#endif |
12047
320a714614e9
7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
11514
diff
changeset
|
1411 |
|
22605
dba3d6b22818
8031581: PPC64: Addons and fixes for AIX to pass the jdk regression tests
simonis
parents:
22597
diff
changeset
|
1412 |
#if defined(_ALLBSD_SOURCE) || defined(_AIX) |
12047
320a714614e9
7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
11514
diff
changeset
|
1413 |
/* |
320a714614e9
7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
11514
diff
changeset
|
1414 |
* On Solaris, SO_REUSEADDR will allow multiple datagram |
22605
dba3d6b22818
8031581: PPC64: Addons and fixes for AIX to pass the jdk regression tests
simonis
parents:
22597
diff
changeset
|
1415 |
* sockets to bind to the same port. The network jck tests check |
12047
320a714614e9
7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
11514
diff
changeset
|
1416 |
* for this "feature", so we need to emulate it by turning on |
320a714614e9
7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
11514
diff
changeset
|
1417 |
* SO_REUSEPORT as well for that combination. |
320a714614e9
7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
11514
diff
changeset
|
1418 |
*/ |
320a714614e9
7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
11514
diff
changeset
|
1419 |
if (level == SOL_SOCKET && opt == SO_REUSEADDR) { |
320a714614e9
7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
11514
diff
changeset
|
1420 |
int sotype; |
320a714614e9
7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
11514
diff
changeset
|
1421 |
socklen_t arglen; |
320a714614e9
7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
11514
diff
changeset
|
1422 |
|
320a714614e9
7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
11514
diff
changeset
|
1423 |
arglen = sizeof(sotype); |
320a714614e9
7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
11514
diff
changeset
|
1424 |
if (getsockopt(fd, SOL_SOCKET, SO_TYPE, (void *)&sotype, &arglen) < 0) { |
320a714614e9
7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
11514
diff
changeset
|
1425 |
return -1; |
320a714614e9
7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
11514
diff
changeset
|
1426 |
} |
320a714614e9
7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
11514
diff
changeset
|
1427 |
|
320a714614e9
7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
11514
diff
changeset
|
1428 |
if (sotype == SOCK_DGRAM) { |
22605
dba3d6b22818
8031581: PPC64: Addons and fixes for AIX to pass the jdk regression tests
simonis
parents:
22597
diff
changeset
|
1429 |
setsockopt(fd, level, SO_REUSEPORT, arg, len); |
12047
320a714614e9
7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
11514
diff
changeset
|
1430 |
} |
320a714614e9
7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
11514
diff
changeset
|
1431 |
} |
320a714614e9
7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
11514
diff
changeset
|
1432 |
#endif |
320a714614e9
7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
11514
diff
changeset
|
1433 |
|
2 | 1434 |
return setsockopt(fd, level, opt, arg, len); |
1435 |
} |
|
1436 |
||
1437 |
/* |
|
1438 |
* Wrapper for bind system call - performs any necessary pre/post |
|
1439 |
* processing to deal with OS specific issues :- |
|
1440 |
* |
|
1441 |
* Linux allows a socket to bind to 127.0.0.255 which must be |
|
1442 |
* caught. |
|
1443 |
* |
|
13043
10fa4f21ea0f
7123896: Unexpected behavior due to Solaris using separate IPv4 and IPv6 port spaces
coffeys
parents:
12047
diff
changeset
|
1444 |
* On Solaris with IPv6 enabled we must use an exclusive |
10fa4f21ea0f
7123896: Unexpected behavior due to Solaris using separate IPv4 and IPv6 port spaces
coffeys
parents:
12047
diff
changeset
|
1445 |
* bind to guarantee a unique port number across the IPv4 and |
2 | 1446 |
* IPv6 port spaces. |
1447 |
* |
|
1448 |
*/ |
|
1449 |
int |
|
43100 | 1450 |
NET_Bind(int fd, SOCKETADDRESS *sa, int len) |
2 | 1451 |
{ |
41834
99c4f72c0a91
8168771: Remove #ifdef AF_INET6 guards in libnet native coding
clanger
parents:
41771
diff
changeset
|
1452 |
#if defined(__solaris__) |
2 | 1453 |
int level = -1; |
1454 |
int exclbind = -1; |
|
1455 |
#endif |
|
1456 |
int rv; |
|
31711 | 1457 |
int arg, alen; |
2 | 1458 |
|
1459 |
#ifdef __linux__ |
|
1460 |
/* |
|
1461 |
* ## get bugId for this issue - goes back to 1.2.2 port ## |
|
1462 |
* ## When IPv6 is enabled this will be an IPv4-mapped |
|
1463 |
* ## with family set to AF_INET6 |
|
1464 |
*/ |
|
43100 | 1465 |
if (sa->sa.sa_family == AF_INET) { |
1466 |
if ((ntohl(sa->sa4.sin_addr.s_addr) & 0x7f0000ff) == 0x7f0000ff) { |
|
2 | 1467 |
errno = EADDRNOTAVAIL; |
1468 |
return -1; |
|
1469 |
} |
|
1470 |
} |
|
1471 |
#endif |
|
1472 |
||
31711 | 1473 |
#if defined(__solaris__) |
2 | 1474 |
/* |
13043
10fa4f21ea0f
7123896: Unexpected behavior due to Solaris using separate IPv4 and IPv6 port spaces
coffeys
parents:
12047
diff
changeset
|
1475 |
* Solaris has separate IPv4 and IPv6 port spaces so we |
2 | 1476 |
* use an exclusive bind when SO_REUSEADDR is not used to |
1477 |
* give the illusion of a unified port space. |
|
13043
10fa4f21ea0f
7123896: Unexpected behavior due to Solaris using separate IPv4 and IPv6 port spaces
coffeys
parents:
12047
diff
changeset
|
1478 |
* This also avoids problems with IPv6 sockets connecting |
2 | 1479 |
* to IPv4 mapped addresses whereby the socket conversion |
1480 |
* results in a late bind that fails because the |
|
1481 |
* corresponding IPv4 port is in use. |
|
1482 |
*/ |
|
31711 | 1483 |
alen = sizeof(arg); |
2 | 1484 |
|
43100 | 1485 |
if (useExclBind || |
1486 |
getsockopt(fd, SOL_SOCKET, SO_REUSEADDR, (char *)&arg, &alen) == 0) |
|
1487 |
{ |
|
31711 | 1488 |
if (useExclBind || arg == 0) { |
1489 |
/* |
|
1490 |
* SO_REUSEADDR is disabled or sun.net.useExclusiveBind |
|
1491 |
* property is true so enable TCP_EXCLBIND or |
|
1492 |
* UDP_EXCLBIND |
|
1493 |
*/ |
|
1494 |
alen = sizeof(arg); |
|
43100 | 1495 |
if (getsockopt(fd, SOL_SOCKET, SO_TYPE, (char *)&arg, &alen) == 0) |
1496 |
{ |
|
31711 | 1497 |
if (arg == SOCK_STREAM) { |
1498 |
level = IPPROTO_TCP; |
|
1499 |
exclbind = TCP_EXCLBIND; |
|
1500 |
} else { |
|
1501 |
level = IPPROTO_UDP; |
|
1502 |
exclbind = UDP_EXCLBIND; |
|
2 | 1503 |
} |
31711 | 1504 |
} |
2 | 1505 |
|
31711 | 1506 |
arg = 1; |
43100 | 1507 |
setsockopt(fd, level, exclbind, (char *)&arg, sizeof(arg)); |
2 | 1508 |
} |
1509 |
} |
|
1510 |
||
1511 |
#endif |
|
1512 |
||
43100 | 1513 |
rv = bind(fd, &sa->sa, len); |
2 | 1514 |
|
41834
99c4f72c0a91
8168771: Remove #ifdef AF_INET6 guards in libnet native coding
clanger
parents:
41771
diff
changeset
|
1515 |
#if defined(__solaris__) |
2 | 1516 |
if (rv < 0) { |
1517 |
int en = errno; |
|
1518 |
/* Restore *_EXCLBIND if the bind fails */ |
|
1519 |
if (exclbind != -1) { |
|
1520 |
int arg = 0; |
|
1521 |
setsockopt(fd, level, exclbind, (char *)&arg, |
|
1522 |
sizeof(arg)); |
|
1523 |
} |
|
1524 |
errno = en; |
|
1525 |
} |
|
1526 |
#endif |
|
1527 |
||
1528 |
return rv; |
|
1529 |
} |
|
1530 |
||
1531 |
/** |
|
23033
0cc7c83fde3c
8035949: Remove unused macro USE_SELECT and clean up Unix version of net_util_md.{c,h}
simonis
parents:
23028
diff
changeset
|
1532 |
* Wrapper for poll with timeout on a single file descriptor. |
2 | 1533 |
* |
1534 |
* flags (defined in net_util_md.h can be any combination of |
|
1535 |
* NET_WAIT_READ, NET_WAIT_WRITE & NET_WAIT_CONNECT. |
|
1536 |
* |
|
1537 |
* The function will return when either the socket is ready for one |
|
30963
88469d06e03f
8072384: Setting IP_TOS on java.net sockets not working on unix
coffeys
parents:
28059
diff
changeset
|
1538 |
* of the specified operations or the timeout expired. |
2 | 1539 |
* |
1540 |
* It returns the time left from the timeout (possibly 0), or -1 if it expired. |
|
1541 |
*/ |
|
1542 |
||
1543 |
jint |
|
1544 |
NET_Wait(JNIEnv *env, jint fd, jint flags, jint timeout) |
|
1545 |
{ |
|
44921
0672237e13c0
8179602: Backout fix for JDK-8165437 due to breakage on 32-bit Linux
michaelm
parents:
44916
diff
changeset
|
1546 |
jlong prevTime = JVM_CurrentTimeMillis(env, 0); |
2 | 1547 |
jint read_rv; |
1548 |
||
1549 |
while (1) { |
|
44921
0672237e13c0
8179602: Backout fix for JDK-8165437 due to breakage on 32-bit Linux
michaelm
parents:
44916
diff
changeset
|
1550 |
jlong newTime; |
23033
0cc7c83fde3c
8035949: Remove unused macro USE_SELECT and clean up Unix version of net_util_md.{c,h}
simonis
parents:
23028
diff
changeset
|
1551 |
struct pollfd pfd; |
0cc7c83fde3c
8035949: Remove unused macro USE_SELECT and clean up Unix version of net_util_md.{c,h}
simonis
parents:
23028
diff
changeset
|
1552 |
pfd.fd = fd; |
0cc7c83fde3c
8035949: Remove unused macro USE_SELECT and clean up Unix version of net_util_md.{c,h}
simonis
parents:
23028
diff
changeset
|
1553 |
pfd.events = 0; |
0cc7c83fde3c
8035949: Remove unused macro USE_SELECT and clean up Unix version of net_util_md.{c,h}
simonis
parents:
23028
diff
changeset
|
1554 |
if (flags & NET_WAIT_READ) |
0cc7c83fde3c
8035949: Remove unused macro USE_SELECT and clean up Unix version of net_util_md.{c,h}
simonis
parents:
23028
diff
changeset
|
1555 |
pfd.events |= POLLIN; |
0cc7c83fde3c
8035949: Remove unused macro USE_SELECT and clean up Unix version of net_util_md.{c,h}
simonis
parents:
23028
diff
changeset
|
1556 |
if (flags & NET_WAIT_WRITE) |
0cc7c83fde3c
8035949: Remove unused macro USE_SELECT and clean up Unix version of net_util_md.{c,h}
simonis
parents:
23028
diff
changeset
|
1557 |
pfd.events |= POLLOUT; |
0cc7c83fde3c
8035949: Remove unused macro USE_SELECT and clean up Unix version of net_util_md.{c,h}
simonis
parents:
23028
diff
changeset
|
1558 |
if (flags & NET_WAIT_CONNECT) |
0cc7c83fde3c
8035949: Remove unused macro USE_SELECT and clean up Unix version of net_util_md.{c,h}
simonis
parents:
23028
diff
changeset
|
1559 |
pfd.events |= POLLOUT; |
2 | 1560 |
|
23033
0cc7c83fde3c
8035949: Remove unused macro USE_SELECT and clean up Unix version of net_util_md.{c,h}
simonis
parents:
23028
diff
changeset
|
1561 |
errno = 0; |
44921
0672237e13c0
8179602: Backout fix for JDK-8165437 due to breakage on 32-bit Linux
michaelm
parents:
44916
diff
changeset
|
1562 |
read_rv = NET_Poll(&pfd, 1, timeout); |
2 | 1563 |
|
44921
0672237e13c0
8179602: Backout fix for JDK-8165437 due to breakage on 32-bit Linux
michaelm
parents:
44916
diff
changeset
|
1564 |
newTime = JVM_CurrentTimeMillis(env, 0); |
0672237e13c0
8179602: Backout fix for JDK-8165437 due to breakage on 32-bit Linux
michaelm
parents:
44916
diff
changeset
|
1565 |
timeout -= (newTime - prevTime); |
0672237e13c0
8179602: Backout fix for JDK-8165437 due to breakage on 32-bit Linux
michaelm
parents:
44916
diff
changeset
|
1566 |
if (timeout <= 0) { |
2 | 1567 |
return read_rv > 0 ? 0 : -1; |
1568 |
} |
|
44921
0672237e13c0
8179602: Backout fix for JDK-8165437 due to breakage on 32-bit Linux
michaelm
parents:
44916
diff
changeset
|
1569 |
prevTime = newTime; |
2 | 1570 |
|
1571 |
if (read_rv > 0) { |
|
1572 |
break; |
|
1573 |
} |
|
44921
0672237e13c0
8179602: Backout fix for JDK-8165437 due to breakage on 32-bit Linux
michaelm
parents:
44916
diff
changeset
|
1574 |
|
0672237e13c0
8179602: Backout fix for JDK-8165437 due to breakage on 32-bit Linux
michaelm
parents:
44916
diff
changeset
|
1575 |
|
2 | 1576 |
} /* while */ |
44921
0672237e13c0
8179602: Backout fix for JDK-8165437 due to breakage on 32-bit Linux
michaelm
parents:
44916
diff
changeset
|
1577 |
|
0672237e13c0
8179602: Backout fix for JDK-8165437 due to breakage on 32-bit Linux
michaelm
parents:
44916
diff
changeset
|
1578 |
return timeout; |
0672237e13c0
8179602: Backout fix for JDK-8165437 due to breakage on 32-bit Linux
michaelm
parents:
44916
diff
changeset
|
1579 |
} |
0672237e13c0
8179602: Backout fix for JDK-8165437 due to breakage on 32-bit Linux
michaelm
parents:
44916
diff
changeset
|
1580 |
|
0672237e13c0
8179602: Backout fix for JDK-8165437 due to breakage on 32-bit Linux
michaelm
parents:
44916
diff
changeset
|
1581 |
long NET_GetCurrentTime() { |
0672237e13c0
8179602: Backout fix for JDK-8165437 due to breakage on 32-bit Linux
michaelm
parents:
44916
diff
changeset
|
1582 |
struct timeval time; |
0672237e13c0
8179602: Backout fix for JDK-8165437 due to breakage on 32-bit Linux
michaelm
parents:
44916
diff
changeset
|
1583 |
gettimeofday(&time, NULL); |
0672237e13c0
8179602: Backout fix for JDK-8165437 due to breakage on 32-bit Linux
michaelm
parents:
44916
diff
changeset
|
1584 |
return (time.tv_sec * 1000 + time.tv_usec / 1000); |
2 | 1585 |
} |
44921
0672237e13c0
8179602: Backout fix for JDK-8165437 due to breakage on 32-bit Linux
michaelm
parents:
44916
diff
changeset
|
1586 |
|
0672237e13c0
8179602: Backout fix for JDK-8165437 due to breakage on 32-bit Linux
michaelm
parents:
44916
diff
changeset
|
1587 |
int NET_TimeoutWithCurrentTime(int s, long timeout, long currentTime) { |
0672237e13c0
8179602: Backout fix for JDK-8165437 due to breakage on 32-bit Linux
michaelm
parents:
44916
diff
changeset
|
1588 |
return NET_Timeout0(s, timeout, currentTime); |
0672237e13c0
8179602: Backout fix for JDK-8165437 due to breakage on 32-bit Linux
michaelm
parents:
44916
diff
changeset
|
1589 |
} |
0672237e13c0
8179602: Backout fix for JDK-8165437 due to breakage on 32-bit Linux
michaelm
parents:
44916
diff
changeset
|
1590 |
|
0672237e13c0
8179602: Backout fix for JDK-8165437 due to breakage on 32-bit Linux
michaelm
parents:
44916
diff
changeset
|
1591 |
int NET_Timeout(int s, long timeout) { |
0672237e13c0
8179602: Backout fix for JDK-8165437 due to breakage on 32-bit Linux
michaelm
parents:
44916
diff
changeset
|
1592 |
long currentTime = (timeout > 0) ? NET_GetCurrentTime() : 0; |
0672237e13c0
8179602: Backout fix for JDK-8165437 due to breakage on 32-bit Linux
michaelm
parents:
44916
diff
changeset
|
1593 |
return NET_Timeout0(s, timeout, currentTime); |
0672237e13c0
8179602: Backout fix for JDK-8165437 due to breakage on 32-bit Linux
michaelm
parents:
44916
diff
changeset
|
1594 |
} |