author | michaelm |
Thu, 13 Jun 2019 09:10:51 +0100 | |
changeset 55375 | 96c7427456f9 |
parent 54627 | 22323f20401b |
child 59243 | fb1d9bf1be2b |
permissions | -rw-r--r-- |
2 | 1 |
/* |
53349
d3aa93570779
8007606: Handle realloc() failure in unix/native/libnet/net_util_md.c correctly
igerasim
parents:
53335
diff
changeset
|
2 |
* Copyright (c) 1997, 2019, 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 |
|
45061
74b09ee3cd55
8179905: Remove the use of gettimeofday in Networking code
vtewari
parents:
44921
diff
changeset
|
52 |
#include "jvm.h" |
41771
18c9669e76ca
8167481: cleanup of headers and includes for native libnet
clanger
parents:
41578
diff
changeset
|
53 |
#include "net_util.h" |
18c9669e76ca
8167481: cleanup of headers and includes for native libnet
clanger
parents:
41578
diff
changeset
|
54 |
|
18c9669e76ca
8167481: cleanup of headers and includes for native libnet
clanger
parents:
41578
diff
changeset
|
55 |
#include "java_net_SocketOptions.h" |
18c9669e76ca
8167481: cleanup of headers and includes for native libnet
clanger
parents:
41578
diff
changeset
|
56 |
#include "java_net_InetAddress.h" |
18c9669e76ca
8167481: cleanup of headers and includes for native libnet
clanger
parents:
41578
diff
changeset
|
57 |
|
18c9669e76ca
8167481: cleanup of headers and includes for native libnet
clanger
parents:
41578
diff
changeset
|
58 |
#if defined(__linux__) && !defined(IPV6_FLOWINFO_SEND) |
2 | 59 |
#define IPV6_FLOWINFO_SEND 33 |
60 |
#endif |
|
61 |
||
41771
18c9669e76ca
8167481: cleanup of headers and includes for native libnet
clanger
parents:
41578
diff
changeset
|
62 |
#if defined(__solaris__) && !defined(MAXINT) |
18c9669e76ca
8167481: cleanup of headers and includes for native libnet
clanger
parents:
41578
diff
changeset
|
63 |
#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
|
64 |
#endif |
0554f6183d11
8035876: AIX build issues after '8034174: Remove use of JVM_* functions from java.net code'
simonis
parents:
23015
diff
changeset
|
65 |
|
2 | 66 |
/* |
13043
10fa4f21ea0f
7123896: Unexpected behavior due to Solaris using separate IPv4 and IPv6 port spaces
coffeys
parents:
12047
diff
changeset
|
67 |
* EXCLBIND socket options only on Solaris |
2 | 68 |
*/ |
69 |
#if defined(__solaris__) && !defined(TCP_EXCLBIND) |
|
70 |
#define TCP_EXCLBIND 0x21 |
|
71 |
#endif |
|
72 |
#if defined(__solaris__) && !defined(UDP_EXCLBIND) |
|
73 |
#define UDP_EXCLBIND 0x0101 |
|
74 |
#endif |
|
75 |
||
12047
320a714614e9
7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
11514
diff
changeset
|
76 |
void setDefaultScopeID(JNIEnv *env, struct sockaddr *him) |
320a714614e9
7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
11514
diff
changeset
|
77 |
{ |
320a714614e9
7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
11514
diff
changeset
|
78 |
#ifdef MACOSX |
320a714614e9
7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
11514
diff
changeset
|
79 |
static jclass ni_class = NULL; |
320a714614e9
7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
11514
diff
changeset
|
80 |
static jfieldID ni_defaultIndexID; |
320a714614e9
7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
11514
diff
changeset
|
81 |
if (ni_class == NULL) { |
320a714614e9
7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
11514
diff
changeset
|
82 |
jclass c = (*env)->FindClass(env, "java/net/NetworkInterface"); |
320a714614e9
7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
11514
diff
changeset
|
83 |
CHECK_NULL(c); |
320a714614e9
7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
11514
diff
changeset
|
84 |
c = (*env)->NewGlobalRef(env, c); |
320a714614e9
7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
11514
diff
changeset
|
85 |
CHECK_NULL(c); |
38563
3ab5f00bd5a3
8157811: Additional minor fixes and cleanups in Networking native code
chegar
parents:
38459
diff
changeset
|
86 |
ni_defaultIndexID = (*env)->GetStaticFieldID(env, c, "defaultIndex", "I"); |
3ab5f00bd5a3
8157811: Additional minor fixes and cleanups in Networking native code
chegar
parents:
38459
diff
changeset
|
87 |
CHECK_NULL(ni_defaultIndexID); |
12047
320a714614e9
7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
11514
diff
changeset
|
88 |
ni_class = c; |
320a714614e9
7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
11514
diff
changeset
|
89 |
} |
320a714614e9
7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
11514
diff
changeset
|
90 |
int defaultIndex; |
320a714614e9
7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
11514
diff
changeset
|
91 |
struct sockaddr_in6 *sin6 = (struct sockaddr_in6 *)him; |
49704
bc1c7e41e285
8200719: Cannot connect to IPv6 host when exists any active network interface without IPv6 address
clanger
parents:
49440
diff
changeset
|
92 |
if (sin6->sin6_family == AF_INET6 && (sin6->sin6_scope_id == 0) && |
bc1c7e41e285
8200719: Cannot connect to IPv6 host when exists any active network interface without IPv6 address
clanger
parents:
49440
diff
changeset
|
93 |
(IN6_IS_ADDR_LINKLOCAL(&sin6->sin6_addr) || |
bc1c7e41e285
8200719: Cannot connect to IPv6 host when exists any active network interface without IPv6 address
clanger
parents:
49440
diff
changeset
|
94 |
IN6_IS_ADDR_MULTICAST(&sin6->sin6_addr))) { |
12047
320a714614e9
7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
11514
diff
changeset
|
95 |
defaultIndex = (*env)->GetStaticIntField(env, ni_class, |
320a714614e9
7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
11514
diff
changeset
|
96 |
ni_defaultIndexID); |
320a714614e9
7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
11514
diff
changeset
|
97 |
sin6->sin6_scope_id = defaultIndex; |
320a714614e9
7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
11514
diff
changeset
|
98 |
} |
320a714614e9
7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
11514
diff
changeset
|
99 |
#endif |
320a714614e9
7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
11514
diff
changeset
|
100 |
} |
320a714614e9
7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
11514
diff
changeset
|
101 |
|
12551
5be0a162ed89
7144274: [macosx] Default IPv6 multicast interface is not being set when calling MulticastSocket.joinGroup()
khazra
parents:
12047
diff
changeset
|
102 |
int getDefaultScopeID(JNIEnv *env) { |
23015
73b21ab36615
8034174: Remove use of JVM_* functions from java.net code
chegar
parents:
23010
diff
changeset
|
103 |
int defaultIndex = 0; |
12551
5be0a162ed89
7144274: [macosx] Default IPv6 multicast interface is not being set when calling MulticastSocket.joinGroup()
khazra
parents:
12047
diff
changeset
|
104 |
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
|
105 |
static jfieldID ni_defaultIndexID; |
5be0a162ed89
7144274: [macosx] Default IPv6 multicast interface is not being set when calling MulticastSocket.joinGroup()
khazra
parents:
12047
diff
changeset
|
106 |
if (ni_class == NULL) { |
5be0a162ed89
7144274: [macosx] Default IPv6 multicast interface is not being set when calling MulticastSocket.joinGroup()
khazra
parents:
12047
diff
changeset
|
107 |
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
|
108 |
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
|
109 |
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
|
110 |
CHECK_NULL_RETURN(c, 0); |
38563
3ab5f00bd5a3
8157811: Additional minor fixes and cleanups in Networking native code
chegar
parents:
38459
diff
changeset
|
111 |
ni_defaultIndexID = (*env)->GetStaticFieldID(env, c, "defaultIndex", "I"); |
3ab5f00bd5a3
8157811: Additional minor fixes and cleanups in Networking native code
chegar
parents:
38459
diff
changeset
|
112 |
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
|
113 |
ni_class = c; |
5be0a162ed89
7144274: [macosx] Default IPv6 multicast interface is not being set when calling MulticastSocket.joinGroup()
khazra
parents:
12047
diff
changeset
|
114 |
} |
5be0a162ed89
7144274: [macosx] Default IPv6 multicast interface is not being set when calling MulticastSocket.joinGroup()
khazra
parents:
12047
diff
changeset
|
115 |
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
|
116 |
ni_defaultIndexID); |
5be0a162ed89
7144274: [macosx] Default IPv6 multicast interface is not being set when calling MulticastSocket.joinGroup()
khazra
parents:
12047
diff
changeset
|
117 |
return defaultIndex; |
5be0a162ed89
7144274: [macosx] Default IPv6 multicast interface is not being set when calling MulticastSocket.joinGroup()
khazra
parents:
12047
diff
changeset
|
118 |
} |
5be0a162ed89
7144274: [macosx] Default IPv6 multicast interface is not being set when calling MulticastSocket.joinGroup()
khazra
parents:
12047
diff
changeset
|
119 |
|
23015
73b21ab36615
8034174: Remove use of JVM_* functions from java.net code
chegar
parents:
23010
diff
changeset
|
120 |
#define RESTARTABLE(_cmd, _result) do { \ |
73b21ab36615
8034174: Remove use of JVM_* functions from java.net code
chegar
parents:
23010
diff
changeset
|
121 |
do { \ |
73b21ab36615
8034174: Remove use of JVM_* functions from java.net code
chegar
parents:
23010
diff
changeset
|
122 |
_result = _cmd; \ |
73b21ab36615
8034174: Remove use of JVM_* functions from java.net code
chegar
parents:
23010
diff
changeset
|
123 |
} while((_result == -1) && (errno == EINTR)); \ |
73b21ab36615
8034174: Remove use of JVM_* functions from java.net code
chegar
parents:
23010
diff
changeset
|
124 |
} while(0) |
73b21ab36615
8034174: Remove use of JVM_* functions from java.net code
chegar
parents:
23010
diff
changeset
|
125 |
|
53422
6f02e036630e
8217461: (ch) Add Net.available to return the number of bytes in the socket input buffer
alanb
parents:
53349
diff
changeset
|
126 |
int NET_SocketAvailable(int s, int *pbytes) { |
23015
73b21ab36615
8034174: Remove use of JVM_* functions from java.net code
chegar
parents:
23010
diff
changeset
|
127 |
int result; |
73b21ab36615
8034174: Remove use of JVM_* functions from java.net code
chegar
parents:
23010
diff
changeset
|
128 |
RESTARTABLE(ioctl(s, FIONREAD, pbytes), result); |
53422
6f02e036630e
8217461: (ch) Add Net.available to return the number of bytes in the socket input buffer
alanb
parents:
53349
diff
changeset
|
129 |
return result; |
23015
73b21ab36615
8034174: Remove use of JVM_* functions from java.net code
chegar
parents:
23010
diff
changeset
|
130 |
} |
73b21ab36615
8034174: Remove use of JVM_* functions from java.net code
chegar
parents:
23010
diff
changeset
|
131 |
|
2 | 132 |
#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
|
133 |
static int init_tcp_max_buf, init_udp_max_buf; |
2 | 134 |
static int tcp_max_buf; |
135 |
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
|
136 |
static int useExclBind = 0; |
2 | 137 |
|
138 |
/* |
|
139 |
* Get the specified parameter from the specified driver. The value |
|
140 |
* 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
|
141 |
* cannot be obtained return -1 |
2 | 142 |
*/ |
22341
4689530d03b9
8028293: Check local configuration for actual ephemeral port range
michaelm
parents:
20821
diff
changeset
|
143 |
int net_getParam(char *driver, char *param) |
2 | 144 |
{ |
145 |
struct strioctl stri; |
|
146 |
char buf [64]; |
|
147 |
int s; |
|
148 |
int value; |
|
149 |
||
150 |
s = open (driver, O_RDWR); |
|
151 |
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
|
152 |
return -1; |
2 | 153 |
} |
154 |
strncpy (buf, param, sizeof(buf)); |
|
155 |
stri.ic_cmd = ND_GET; |
|
156 |
stri.ic_timout = 0; |
|
157 |
stri.ic_dp = buf; |
|
158 |
stri.ic_len = sizeof(buf); |
|
159 |
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
|
160 |
value = -1; |
2 | 161 |
} else { |
162 |
value = atoi(buf); |
|
163 |
} |
|
164 |
close (s); |
|
165 |
return value; |
|
166 |
} |
|
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
|
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 |
/* |
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
|
169 |
* 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
|
170 |
* 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
|
171 |
* 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
|
172 |
* |
13999
f6a2ce6a3e40
7193520: Removed references to Linux kernel version 2.2
chegar
parents:
13048
diff
changeset
|
173 |
* 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
|
174 |
* 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
|
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 |
|
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_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
|
178 |
#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
|
179 |
|
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 |
#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
|
181 |
|
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 |
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
|
183 |
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
|
184 |
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
|
185 |
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
|
186 |
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
|
187 |
|
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 |
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
|
189 |
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
|
190 |
} 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
|
191 |
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
|
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 |
|
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 |
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
|
195 |
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
|
196 |
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
|
197 |
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
|
198 |
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
|
199 |
} |
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 |
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
|
201 |
} 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
|
202 |
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
|
203 |
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
|
204 |
} |
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 |
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
|
206 |
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
|
207 |
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
|
208 |
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
|
209 |
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
|
210 |
} 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
|
211 |
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
|
212 |
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
|
213 |
} |
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 |
} 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
|
215 |
|
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 |
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
|
217 |
} |
2 | 218 |
#endif |
219 |
||
220 |
#ifdef __linux__ |
|
221 |
static int vinit = 0; |
|
222 |
static int kernelV24 = 0; |
|
223 |
static int vinit24 = 0; |
|
224 |
||
225 |
int kernelIsV24 () { |
|
226 |
if (!vinit24) { |
|
227 |
struct utsname sysinfo; |
|
228 |
if (uname(&sysinfo) == 0) { |
|
229 |
sysinfo.release[3] = '\0'; |
|
230 |
if (strcmp(sysinfo.release, "2.4") == 0) { |
|
231 |
kernelV24 = JNI_TRUE; |
|
232 |
} |
|
233 |
} |
|
234 |
vinit24 = 1; |
|
235 |
} |
|
236 |
return kernelV24; |
|
237 |
} |
|
238 |
#endif |
|
239 |
||
240 |
void |
|
241 |
NET_ThrowByNameWithLastError(JNIEnv *env, const char *name, |
|
242 |
const char *defaultDetail) { |
|
41578 | 243 |
JNU_ThrowByNameWithMessageAndLastError(env, name, defaultDetail); |
2 | 244 |
} |
245 |
||
246 |
void |
|
247 |
NET_ThrowCurrent(JNIEnv *env, char *msg) { |
|
248 |
NET_ThrowNew(env, errno, msg); |
|
249 |
} |
|
250 |
||
251 |
void |
|
252 |
NET_ThrowNew(JNIEnv *env, int errorNumber, char *msg) { |
|
253 |
char fullMsg[512]; |
|
254 |
if (!msg) { |
|
255 |
msg = "no further information"; |
|
256 |
} |
|
257 |
switch(errorNumber) { |
|
258 |
case EBADF: |
|
259 |
jio_snprintf(fullMsg, sizeof(fullMsg), "socket closed: %s", msg); |
|
260 |
JNU_ThrowByName(env, JNU_JAVANETPKG "SocketException", fullMsg); |
|
261 |
break; |
|
262 |
case EINTR: |
|
263 |
JNU_ThrowByName(env, JNU_JAVAIOPKG "InterruptedIOException", msg); |
|
264 |
break; |
|
265 |
default: |
|
266 |
errno = errorNumber; |
|
267 |
JNU_ThrowByNameWithLastError(env, JNU_JAVANETPKG "SocketException", msg); |
|
268 |
break; |
|
269 |
} |
|
270 |
} |
|
271 |
||
272 |
||
273 |
jfieldID |
|
274 |
NET_GetFileDescriptorID(JNIEnv *env) |
|
275 |
{ |
|
276 |
jclass cls = (*env)->FindClass(env, "java/io/FileDescriptor"); |
|
277 |
CHECK_NULL_RETURN(cls, NULL); |
|
278 |
return (*env)->GetFieldID(env, cls, "fd", "I"); |
|
279 |
} |
|
280 |
||
54627
22323f20401b
8222562: Don't set IPV6_V6ONLY when IPv4 is not available
aeubanks
parents:
53422
diff
changeset
|
281 |
jint IPv4_supported() |
22323f20401b
8222562: Don't set IPV6_V6ONLY when IPv4 is not available
aeubanks
parents:
53422
diff
changeset
|
282 |
{ |
22323f20401b
8222562: Don't set IPV6_V6ONLY when IPv4 is not available
aeubanks
parents:
53422
diff
changeset
|
283 |
int fd = socket(AF_INET, SOCK_STREAM, 0) ; |
22323f20401b
8222562: Don't set IPV6_V6ONLY when IPv4 is not available
aeubanks
parents:
53422
diff
changeset
|
284 |
if (fd < 0) { |
22323f20401b
8222562: Don't set IPV6_V6ONLY when IPv4 is not available
aeubanks
parents:
53422
diff
changeset
|
285 |
return JNI_FALSE; |
22323f20401b
8222562: Don't set IPV6_V6ONLY when IPv4 is not available
aeubanks
parents:
53422
diff
changeset
|
286 |
} |
22323f20401b
8222562: Don't set IPV6_V6ONLY when IPv4 is not available
aeubanks
parents:
53422
diff
changeset
|
287 |
close(fd); |
22323f20401b
8222562: Don't set IPV6_V6ONLY when IPv4 is not available
aeubanks
parents:
53422
diff
changeset
|
288 |
return JNI_TRUE; |
22323f20401b
8222562: Don't set IPV6_V6ONLY when IPv4 is not available
aeubanks
parents:
53422
diff
changeset
|
289 |
} |
22323f20401b
8222562: Don't set IPV6_V6ONLY when IPv4 is not available
aeubanks
parents:
53422
diff
changeset
|
290 |
|
12047
320a714614e9
7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
11514
diff
changeset
|
291 |
#if defined(DONT_ENABLE_IPV6) |
320a714614e9
7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
11514
diff
changeset
|
292 |
jint IPv6_supported() |
320a714614e9
7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
11514
diff
changeset
|
293 |
{ |
320a714614e9
7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
11514
diff
changeset
|
294 |
return JNI_FALSE; |
320a714614e9
7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
11514
diff
changeset
|
295 |
} |
320a714614e9
7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
11514
diff
changeset
|
296 |
|
320a714614e9
7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
11514
diff
changeset
|
297 |
#else /* !DONT_ENABLE_IPV6 */ |
320a714614e9
7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
11514
diff
changeset
|
298 |
|
2 | 299 |
jint IPv6_supported() |
300 |
{ |
|
301 |
int fd; |
|
302 |
void *ipv6_fn; |
|
41380
c27cf95dd7e6
8167295: Further cleanup to the native parts of libnet/libnio
clanger
parents:
40937
diff
changeset
|
303 |
SOCKETADDRESS sa; |
c27cf95dd7e6
8167295: Further cleanup to the native parts of libnet/libnio
clanger
parents:
40937
diff
changeset
|
304 |
socklen_t sa_len = sizeof(SOCKETADDRESS); |
2 | 305 |
|
23015
73b21ab36615
8034174: Remove use of JVM_* functions from java.net code
chegar
parents:
23010
diff
changeset
|
306 |
fd = socket(AF_INET6, SOCK_STREAM, 0) ; |
2 | 307 |
if (fd < 0) { |
308 |
/* |
|
309 |
* TODO: We really cant tell since it may be an unrelated error |
|
310 |
* for now we will assume that AF_INET6 is not available |
|
311 |
*/ |
|
312 |
return JNI_FALSE; |
|
313 |
} |
|
314 |
||
315 |
/* |
|
52778
dbbf46b13d52
8211842: IPv6_supported wrongly returns false when unix domain socket is bound to fd 0
michaelm
parents:
52499
diff
changeset
|
316 |
* If fd 0 is a socket it means we may have been launched from inetd or |
2 | 317 |
* xinetd. If it's a socket then check the family - if it's an |
318 |
* IPv4 socket then we need to disable IPv6. |
|
319 |
*/ |
|
41380
c27cf95dd7e6
8167295: Further cleanup to the native parts of libnet/libnio
clanger
parents:
40937
diff
changeset
|
320 |
if (getsockname(0, &sa.sa, &sa_len) == 0) { |
52778
dbbf46b13d52
8211842: IPv6_supported wrongly returns false when unix domain socket is bound to fd 0
michaelm
parents:
52499
diff
changeset
|
321 |
if (sa.sa.sa_family == AF_INET) { |
38459
6cf90640c38c
8048518: File Descriptor Leak in src/java.base/unix/native/libnet/net_util_md.c
chegar
parents:
36115
diff
changeset
|
322 |
close(fd); |
2 | 323 |
return JNI_FALSE; |
324 |
} |
|
325 |
} |
|
326 |
||
327 |
/** |
|
328 |
* Linux - check if any interface has an IPv6 address. |
|
329 |
* Don't need to parse the line - we just need an indication. |
|
330 |
*/ |
|
331 |
#ifdef __linux__ |
|
332 |
{ |
|
333 |
FILE *fP = fopen("/proc/net/if_inet6", "r"); |
|
334 |
char buf[255]; |
|
335 |
char *bufP; |
|
336 |
||
337 |
if (fP == NULL) { |
|
338 |
close(fd); |
|
339 |
return JNI_FALSE; |
|
340 |
} |
|
341 |
bufP = fgets(buf, sizeof(buf), fP); |
|
342 |
fclose(fP); |
|
343 |
if (bufP == NULL) { |
|
344 |
close(fd); |
|
345 |
return JNI_FALSE; |
|
346 |
} |
|
347 |
} |
|
348 |
#endif |
|
349 |
||
350 |
/** |
|
351 |
* On Solaris 8 it's possible to create INET6 sockets even |
|
352 |
* though IPv6 is not enabled on all interfaces. Thus we |
|
353 |
* query the number of IPv6 addresses to verify that IPv6 |
|
354 |
* has been configured on at least one interface. |
|
355 |
* |
|
356 |
* On Linux it doesn't matter - if IPv6 is built-in the |
|
357 |
* kernel then IPv6 addresses will be bound automatically |
|
358 |
* to all interfaces. |
|
359 |
*/ |
|
360 |
#ifdef __solaris__ |
|
361 |
||
362 |
#ifdef SIOCGLIFNUM |
|
363 |
{ |
|
364 |
struct lifnum numifs; |
|
365 |
||
366 |
numifs.lifn_family = AF_INET6; |
|
367 |
numifs.lifn_flags = 0; |
|
368 |
if (ioctl(fd, SIOCGLIFNUM, (char *)&numifs) < 0) { |
|
369 |
/** |
|
370 |
* SIOCGLIFNUM failed - assume IPv6 not configured |
|
371 |
*/ |
|
372 |
close(fd); |
|
373 |
return JNI_FALSE; |
|
374 |
} |
|
375 |
/** |
|
376 |
* If no IPv6 addresses then return false. If count > 0 |
|
377 |
* it's possible that all IPv6 addresses are "down" but |
|
378 |
* that's okay as they may be brought "up" while the |
|
379 |
* VM is running. |
|
380 |
*/ |
|
381 |
if (numifs.lifn_count == 0) { |
|
382 |
close(fd); |
|
383 |
return JNI_FALSE; |
|
384 |
} |
|
385 |
} |
|
386 |
#else |
|
387 |
/* SIOCGLIFNUM not defined in build environment ??? */ |
|
388 |
close(fd); |
|
389 |
return JNI_FALSE; |
|
390 |
#endif |
|
391 |
||
392 |
#endif /* __solaris */ |
|
393 |
||
394 |
/* |
|
395 |
* OK we may have the stack available in the kernel, |
|
396 |
* we should also check if the APIs are available. |
|
397 |
*/ |
|
398 |
ipv6_fn = JVM_FindLibraryEntry(RTLD_DEFAULT, "inet_pton"); |
|
11032
235588f77727
7112670: Inet4AddressImpl should use getaddrinfo/getnameinfo
ngmr
parents:
9035
diff
changeset
|
399 |
close(fd); |
2 | 400 |
if (ipv6_fn == NULL ) { |
401 |
return JNI_FALSE; |
|
11032
235588f77727
7112670: Inet4AddressImpl should use getaddrinfo/getnameinfo
ngmr
parents:
9035
diff
changeset
|
402 |
} else { |
235588f77727
7112670: Inet4AddressImpl should use getaddrinfo/getnameinfo
ngmr
parents:
9035
diff
changeset
|
403 |
return JNI_TRUE; |
2 | 404 |
} |
405 |
} |
|
12047
320a714614e9
7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
11514
diff
changeset
|
406 |
#endif /* DONT_ENABLE_IPV6 */ |
2 | 407 |
|
36115 | 408 |
jint reuseport_supported() |
409 |
{ |
|
410 |
/* Do a simple dummy call, and try to figure out from that */ |
|
411 |
int one = 1; |
|
412 |
int rv, s; |
|
413 |
s = socket(PF_INET, SOCK_STREAM, 0); |
|
414 |
if (s < 0) { |
|
415 |
return JNI_FALSE; |
|
416 |
} |
|
417 |
rv = setsockopt(s, SOL_SOCKET, SO_REUSEPORT, (void *)&one, sizeof(one)); |
|
418 |
if (rv != 0) { |
|
419 |
rv = JNI_FALSE; |
|
420 |
} else { |
|
421 |
rv = JNI_TRUE; |
|
422 |
} |
|
423 |
close(s); |
|
424 |
return rv; |
|
425 |
} |
|
426 |
||
23033
0cc7c83fde3c
8035949: Remove unused macro USE_SELECT and clean up Unix version of net_util_md.{c,h}
simonis
parents:
23028
diff
changeset
|
427 |
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
|
428 |
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
|
429 |
int gai_error) |
6670
ae13809f3ce7
6981157: Improve UnknownHostException with EAI error details and other cleanups
martin
parents:
5506
diff
changeset
|
430 |
{ |
6696
7201f23dae0d
6989190: SO_SNDBUF/SO_RCVBUF limits should only be checked when setsockopt fails (sol)
alanb
parents:
6670
diff
changeset
|
431 |
int size; |
7201f23dae0d
6989190: SO_SNDBUF/SO_RCVBUF limits should only be checked when setsockopt fails (sol)
alanb
parents:
6670
diff
changeset
|
432 |
char *buf; |
6670
ae13809f3ce7
6981157: Improve UnknownHostException with EAI error details and other cleanups
martin
parents:
5506
diff
changeset
|
433 |
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
|
434 |
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
|
435 |
if (error_string == NULL) |
ae13809f3ce7
6981157: Improve UnknownHostException with EAI error details and other cleanups
martin
parents:
5506
diff
changeset
|
436 |
error_string = "unknown error"; |
ae13809f3ce7
6981157: Improve UnknownHostException with EAI error details and other cleanups
martin
parents:
5506
diff
changeset
|
437 |
|
6696
7201f23dae0d
6989190: SO_SNDBUF/SO_RCVBUF limits should only be checked when setsockopt fails (sol)
alanb
parents:
6670
diff
changeset
|
438 |
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
|
439 |
buf = (char *) malloc(size); |
6670
ae13809f3ce7
6981157: Improve UnknownHostException with EAI error details and other cleanups
martin
parents:
5506
diff
changeset
|
440 |
if (buf) { |
6696
7201f23dae0d
6989190: SO_SNDBUF/SO_RCVBUF limits should only be checked when setsockopt fails (sol)
alanb
parents:
6670
diff
changeset
|
441 |
jstring s; |
6670
ae13809f3ce7
6981157: Improve UnknownHostException with EAI error details and other cleanups
martin
parents:
5506
diff
changeset
|
442 |
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
|
443 |
s = JNU_NewStringPlatform(env, buf); |
6670
ae13809f3ce7
6981157: Improve UnknownHostException with EAI error details and other cleanups
martin
parents:
5506
diff
changeset
|
444 |
if (s != NULL) { |
ae13809f3ce7
6981157: Improve UnknownHostException with EAI error details and other cleanups
martin
parents:
5506
diff
changeset
|
445 |
jobject x = JNU_NewObjectByName(env, |
ae13809f3ce7
6981157: Improve UnknownHostException with EAI error details and other cleanups
martin
parents:
5506
diff
changeset
|
446 |
"java/net/UnknownHostException", |
ae13809f3ce7
6981157: Improve UnknownHostException with EAI error details and other cleanups
martin
parents:
5506
diff
changeset
|
447 |
"(Ljava/lang/String;)V", s); |
ae13809f3ce7
6981157: Improve UnknownHostException with EAI error details and other cleanups
martin
parents:
5506
diff
changeset
|
448 |
if (x != NULL) |
ae13809f3ce7
6981157: Improve UnknownHostException with EAI error details and other cleanups
martin
parents:
5506
diff
changeset
|
449 |
(*env)->Throw(env, x); |
ae13809f3ce7
6981157: Improve UnknownHostException with EAI error details and other cleanups
martin
parents:
5506
diff
changeset
|
450 |
} |
ae13809f3ce7
6981157: Improve UnknownHostException with EAI error details and other cleanups
martin
parents:
5506
diff
changeset
|
451 |
free(buf); |
ae13809f3ce7
6981157: Improve UnknownHostException with EAI error details and other cleanups
martin
parents:
5506
diff
changeset
|
452 |
} |
ae13809f3ce7
6981157: Improve UnknownHostException with EAI error details and other cleanups
martin
parents:
5506
diff
changeset
|
453 |
} |
ae13809f3ce7
6981157: Improve UnknownHostException with EAI error details and other cleanups
martin
parents:
5506
diff
changeset
|
454 |
|
55375 | 455 |
#if defined(_AIX) |
22597
7515a991bb37
8024854: PPC64: Basic changes and files to build the class library on AIX
simonis
parents:
20821
diff
changeset
|
456 |
|
7515a991bb37
8024854: PPC64: Basic changes and files to build the class library on AIX
simonis
parents:
20821
diff
changeset
|
457 |
/* 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
|
458 |
extern void aix_close_init(); |
7515a991bb37
8024854: PPC64: Basic changes and files to build the class library on AIX
simonis
parents:
20821
diff
changeset
|
459 |
|
7515a991bb37
8024854: PPC64: Basic changes and files to build the class library on AIX
simonis
parents:
20821
diff
changeset
|
460 |
void platformInit () { |
7515a991bb37
8024854: PPC64: Basic changes and files to build the class library on AIX
simonis
parents:
20821
diff
changeset
|
461 |
aix_close_init(); |
7515a991bb37
8024854: PPC64: Basic changes and files to build the class library on AIX
simonis
parents:
20821
diff
changeset
|
462 |
} |
7515a991bb37
8024854: PPC64: Basic changes and files to build the class library on AIX
simonis
parents:
20821
diff
changeset
|
463 |
|
2 | 464 |
#else |
465 |
||
22597
7515a991bb37
8024854: PPC64: Basic changes and files to build the class library on AIX
simonis
parents:
20821
diff
changeset
|
466 |
void platformInit () {} |
2 | 467 |
|
468 |
#endif |
|
469 |
||
13043
10fa4f21ea0f
7123896: Unexpected behavior due to Solaris using separate IPv4 and IPv6 port spaces
coffeys
parents:
12047
diff
changeset
|
470 |
void parseExclusiveBindProperty(JNIEnv *env) { |
10fa4f21ea0f
7123896: Unexpected behavior due to Solaris using separate IPv4 and IPv6 port spaces
coffeys
parents:
12047
diff
changeset
|
471 |
#ifdef __solaris__ |
10fa4f21ea0f
7123896: Unexpected behavior due to Solaris using separate IPv4 and IPv6 port spaces
coffeys
parents:
12047
diff
changeset
|
472 |
jstring s, flagSet; |
10fa4f21ea0f
7123896: Unexpected behavior due to Solaris using separate IPv4 and IPv6 port spaces
coffeys
parents:
12047
diff
changeset
|
473 |
jclass iCls; |
10fa4f21ea0f
7123896: Unexpected behavior due to Solaris using separate IPv4 and IPv6 port spaces
coffeys
parents:
12047
diff
changeset
|
474 |
jmethodID mid; |
10fa4f21ea0f
7123896: Unexpected behavior due to Solaris using separate IPv4 and IPv6 port spaces
coffeys
parents:
12047
diff
changeset
|
475 |
|
10fa4f21ea0f
7123896: Unexpected behavior due to Solaris using separate IPv4 and IPv6 port spaces
coffeys
parents:
12047
diff
changeset
|
476 |
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
|
477 |
CHECK_NULL(s); |
10fa4f21ea0f
7123896: Unexpected behavior due to Solaris using separate IPv4 and IPv6 port spaces
coffeys
parents:
12047
diff
changeset
|
478 |
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
|
479 |
CHECK_NULL(iCls); |
10fa4f21ea0f
7123896: Unexpected behavior due to Solaris using separate IPv4 and IPv6 port spaces
coffeys
parents:
12047
diff
changeset
|
480 |
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
|
481 |
"(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
|
482 |
CHECK_NULL(mid); |
10fa4f21ea0f
7123896: Unexpected behavior due to Solaris using separate IPv4 and IPv6 port spaces
coffeys
parents:
12047
diff
changeset
|
483 |
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
|
484 |
if (flagSet != NULL) { |
10fa4f21ea0f
7123896: Unexpected behavior due to Solaris using separate IPv4 and IPv6 port spaces
coffeys
parents:
12047
diff
changeset
|
485 |
useExclBind = 1; |
10fa4f21ea0f
7123896: Unexpected behavior due to Solaris using separate IPv4 and IPv6 port spaces
coffeys
parents:
12047
diff
changeset
|
486 |
} |
10fa4f21ea0f
7123896: Unexpected behavior due to Solaris using separate IPv4 and IPv6 port spaces
coffeys
parents:
12047
diff
changeset
|
487 |
#endif |
10fa4f21ea0f
7123896: Unexpected behavior due to Solaris using separate IPv4 and IPv6 port spaces
coffeys
parents:
12047
diff
changeset
|
488 |
} |
10fa4f21ea0f
7123896: Unexpected behavior due to Solaris using separate IPv4 and IPv6 port spaces
coffeys
parents:
12047
diff
changeset
|
489 |
|
27178
885f4428b501
8060170: Support SIO_LOOPBACK_FAST_PATH option on Windows
alanb
parents:
25859
diff
changeset
|
490 |
JNIEXPORT jint JNICALL |
885f4428b501
8060170: Support SIO_LOOPBACK_FAST_PATH option on Windows
alanb
parents:
25859
diff
changeset
|
491 |
NET_EnableFastTcpLoopback(int fd) { |
885f4428b501
8060170: Support SIO_LOOPBACK_FAST_PATH option on Windows
alanb
parents:
25859
diff
changeset
|
492 |
return 0; |
885f4428b501
8060170: Support SIO_LOOPBACK_FAST_PATH option on Windows
alanb
parents:
25859
diff
changeset
|
493 |
} |
885f4428b501
8060170: Support SIO_LOOPBACK_FAST_PATH option on Windows
alanb
parents:
25859
diff
changeset
|
494 |
|
43100 | 495 |
/** |
496 |
* See net_util.h for documentation |
|
497 |
*/ |
|
2 | 498 |
JNIEXPORT int JNICALL |
43100 | 499 |
NET_InetAddressToSockaddr(JNIEnv *env, jobject iaObj, int port, |
500 |
SOCKETADDRESS *sa, int *len, |
|
501 |
jboolean v4MappedAddress) |
|
502 |
{ |
|
503 |
jint family = getInetAddress_family(env, iaObj); |
|
51151 | 504 |
JNU_CHECK_EXCEPTION_RETURN(env, -1); |
43100 | 505 |
memset((char *)sa, 0, sizeof(SOCKETADDRESS)); |
506 |
||
507 |
if (ipv6_available() && |
|
508 |
!(family == java_net_InetAddress_IPv4 && |
|
509 |
v4MappedAddress == JNI_FALSE)) |
|
510 |
{ |
|
2 | 511 |
jbyte caddr[16]; |
512 |
jint address; |
|
513 |
||
41771
18c9669e76ca
8167481: cleanup of headers and includes for native libnet
clanger
parents:
41578
diff
changeset
|
514 |
if (family == java_net_InetAddress_IPv4) { |
18c9669e76ca
8167481: cleanup of headers and includes for native libnet
clanger
parents:
41578
diff
changeset
|
515 |
// convert to IPv4-mapped address |
43100 | 516 |
memset((char *)caddr, 0, 16); |
16870 | 517 |
address = getInetAddress_addr(env, iaObj); |
51151 | 518 |
JNU_CHECK_EXCEPTION_RETURN(env, -1); |
2 | 519 |
if (address == INADDR_ANY) { |
520 |
/* we would always prefer IPv6 wildcard address |
|
43100 | 521 |
* caddr[10] = 0xff; |
522 |
* caddr[11] = 0xff; */ |
|
2 | 523 |
} else { |
524 |
caddr[10] = 0xff; |
|
525 |
caddr[11] = 0xff; |
|
526 |
caddr[12] = ((address >> 24) & 0xff); |
|
527 |
caddr[13] = ((address >> 16) & 0xff); |
|
528 |
caddr[14] = ((address >> 8) & 0xff); |
|
529 |
caddr[15] = (address & 0xff); |
|
530 |
} |
|
531 |
} else { |
|
20821 | 532 |
getInet6Address_ipaddress(env, iaObj, (char *)caddr); |
2 | 533 |
} |
43100 | 534 |
sa->sa6.sin6_port = htons(port); |
535 |
memcpy((void *)&sa->sa6.sin6_addr, caddr, sizeof(struct in6_addr)); |
|
536 |
sa->sa6.sin6_family = AF_INET6; |
|
537 |
if (len != NULL) { |
|
538 |
*len = sizeof(struct sockaddr_in6); |
|
539 |
} |
|
2 | 540 |
|
43100 | 541 |
/* handle scope_id */ |
41771
18c9669e76ca
8167481: cleanup of headers and includes for native libnet
clanger
parents:
41578
diff
changeset
|
542 |
if (family != java_net_InetAddress_IPv4) { |
2 | 543 |
if (ia6_scopeidID) { |
43100 | 544 |
sa->sa6.sin6_scope_id = getInet6Address_scopeid(env, iaObj); |
2 | 545 |
} |
546 |
} |
|
41834
99c4f72c0a91
8168771: Remove #ifdef AF_INET6 guards in libnet native coding
clanger
parents:
41771
diff
changeset
|
547 |
} else { |
99c4f72c0a91
8168771: Remove #ifdef AF_INET6 guards in libnet native coding
clanger
parents:
41771
diff
changeset
|
548 |
jint address; |
43100 | 549 |
if (family != java_net_InetAddress_IPv4) { |
41834
99c4f72c0a91
8168771: Remove #ifdef AF_INET6 guards in libnet native coding
clanger
parents:
41771
diff
changeset
|
550 |
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
|
551 |
return -1; |
2 | 552 |
} |
41834
99c4f72c0a91
8168771: Remove #ifdef AF_INET6 guards in libnet native coding
clanger
parents:
41771
diff
changeset
|
553 |
address = getInetAddress_addr(env, iaObj); |
51151 | 554 |
JNU_CHECK_EXCEPTION_RETURN(env, -1); |
43100 | 555 |
sa->sa4.sin_port = htons(port); |
556 |
sa->sa4.sin_addr.s_addr = htonl(address); |
|
557 |
sa->sa4.sin_family = AF_INET; |
|
558 |
if (len != NULL) { |
|
559 |
*len = sizeof(struct sockaddr_in); |
|
560 |
} |
|
41834
99c4f72c0a91
8168771: Remove #ifdef AF_INET6 guards in libnet native coding
clanger
parents:
41771
diff
changeset
|
561 |
} |
2 | 562 |
return 0; |
563 |
} |
|
564 |
||
565 |
void |
|
43100 | 566 |
NET_SetTrafficClass(SOCKETADDRESS *sa, int trafficClass) { |
567 |
if (sa->sa.sa_family == AF_INET6) { |
|
568 |
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
|
569 |
} |
2 | 570 |
} |
571 |
||
572 |
int |
|
573 |
NET_IsIPv4Mapped(jbyte* caddr) { |
|
574 |
int i; |
|
575 |
for (i = 0; i < 10; i++) { |
|
576 |
if (caddr[i] != 0x00) { |
|
577 |
return 0; /* false */ |
|
578 |
} |
|
579 |
} |
|
580 |
||
581 |
if (((caddr[10] & 0xff) == 0xff) && ((caddr[11] & 0xff) == 0xff)) { |
|
582 |
return 1; /* true */ |
|
583 |
} |
|
584 |
return 0; /* false */ |
|
585 |
} |
|
586 |
||
587 |
int |
|
588 |
NET_IPv4MappedToIPv4(jbyte* caddr) { |
|
589 |
return ((caddr[12] & 0xff) << 24) | ((caddr[13] & 0xff) << 16) | ((caddr[14] & 0xff) << 8) |
|
590 |
| (caddr[15] & 0xff); |
|
591 |
} |
|
592 |
||
593 |
int |
|
594 |
NET_IsEqual(jbyte* caddr1, jbyte* caddr2) { |
|
595 |
int i; |
|
596 |
for (i = 0; i < 16; i++) { |
|
597 |
if (caddr1[i] != caddr2[i]) { |
|
598 |
return 0; /* false */ |
|
599 |
} |
|
600 |
} |
|
601 |
return 1; |
|
602 |
} |
|
603 |
||
12688
f15fd32c975e
7163874: InetAddress.isReachable should support pinging 0.0.0.0
youdwei
parents:
12551
diff
changeset
|
604 |
int NET_IsZeroAddr(jbyte* caddr) { |
f15fd32c975e
7163874: InetAddress.isReachable should support pinging 0.0.0.0
youdwei
parents:
12551
diff
changeset
|
605 |
int i; |
f15fd32c975e
7163874: InetAddress.isReachable should support pinging 0.0.0.0
youdwei
parents:
12551
diff
changeset
|
606 |
for (i = 0; i < 16; i++) { |
f15fd32c975e
7163874: InetAddress.isReachable should support pinging 0.0.0.0
youdwei
parents:
12551
diff
changeset
|
607 |
if (caddr[i] != 0) { |
f15fd32c975e
7163874: InetAddress.isReachable should support pinging 0.0.0.0
youdwei
parents:
12551
diff
changeset
|
608 |
return 0; |
f15fd32c975e
7163874: InetAddress.isReachable should support pinging 0.0.0.0
youdwei
parents:
12551
diff
changeset
|
609 |
} |
f15fd32c975e
7163874: InetAddress.isReachable should support pinging 0.0.0.0
youdwei
parents:
12551
diff
changeset
|
610 |
} |
f15fd32c975e
7163874: InetAddress.isReachable should support pinging 0.0.0.0
youdwei
parents:
12551
diff
changeset
|
611 |
return 1; |
f15fd32c975e
7163874: InetAddress.isReachable should support pinging 0.0.0.0
youdwei
parents:
12551
diff
changeset
|
612 |
} |
f15fd32c975e
7163874: InetAddress.isReachable should support pinging 0.0.0.0
youdwei
parents:
12551
diff
changeset
|
613 |
|
2 | 614 |
/* |
615 |
* Map the Java level socket option to the platform specific |
|
616 |
* level and option name. |
|
617 |
*/ |
|
618 |
int |
|
619 |
NET_MapSocketOption(jint cmd, int *level, int *optname) { |
|
620 |
static struct { |
|
621 |
jint cmd; |
|
622 |
int level; |
|
623 |
int optname; |
|
624 |
} const opts[] = { |
|
625 |
{ java_net_SocketOptions_TCP_NODELAY, IPPROTO_TCP, TCP_NODELAY }, |
|
626 |
{ java_net_SocketOptions_SO_OOBINLINE, SOL_SOCKET, SO_OOBINLINE }, |
|
627 |
{ java_net_SocketOptions_SO_LINGER, SOL_SOCKET, SO_LINGER }, |
|
628 |
{ java_net_SocketOptions_SO_SNDBUF, SOL_SOCKET, SO_SNDBUF }, |
|
629 |
{ java_net_SocketOptions_SO_RCVBUF, SOL_SOCKET, SO_RCVBUF }, |
|
630 |
{ java_net_SocketOptions_SO_KEEPALIVE, SOL_SOCKET, SO_KEEPALIVE }, |
|
631 |
{ java_net_SocketOptions_SO_REUSEADDR, SOL_SOCKET, SO_REUSEADDR }, |
|
36115 | 632 |
{ java_net_SocketOptions_SO_REUSEPORT, SOL_SOCKET, SO_REUSEPORT }, |
2 | 633 |
{ java_net_SocketOptions_SO_BROADCAST, SOL_SOCKET, SO_BROADCAST }, |
634 |
{ java_net_SocketOptions_IP_TOS, IPPROTO_IP, IP_TOS }, |
|
635 |
{ java_net_SocketOptions_IP_MULTICAST_IF, IPPROTO_IP, IP_MULTICAST_IF }, |
|
636 |
{ java_net_SocketOptions_IP_MULTICAST_IF2, IPPROTO_IP, IP_MULTICAST_IF }, |
|
637 |
{ java_net_SocketOptions_IP_MULTICAST_LOOP, IPPROTO_IP, IP_MULTICAST_LOOP }, |
|
638 |
}; |
|
639 |
||
640 |
int i; |
|
641 |
||
642 |
if (ipv6_available()) { |
|
643 |
switch (cmd) { |
|
30963
88469d06e03f
8072384: Setting IP_TOS on java.net sockets not working on unix
coffeys
parents:
28059
diff
changeset
|
644 |
// Different multicast options if IPv6 is enabled |
2 | 645 |
case java_net_SocketOptions_IP_MULTICAST_IF: |
646 |
case java_net_SocketOptions_IP_MULTICAST_IF2: |
|
647 |
*level = IPPROTO_IPV6; |
|
648 |
*optname = IPV6_MULTICAST_IF; |
|
649 |
return 0; |
|
650 |
||
651 |
case java_net_SocketOptions_IP_MULTICAST_LOOP: |
|
652 |
*level = IPPROTO_IPV6; |
|
653 |
*optname = IPV6_MULTICAST_LOOP; |
|
654 |
return 0; |
|
30963
88469d06e03f
8072384: Setting IP_TOS on java.net sockets not working on unix
coffeys
parents:
28059
diff
changeset
|
655 |
#if (defined(__solaris__) || defined(MACOSX)) |
88469d06e03f
8072384: Setting IP_TOS on java.net sockets not working on unix
coffeys
parents:
28059
diff
changeset
|
656 |
// 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
|
657 |
case java_net_SocketOptions_IP_TOS: |
88469d06e03f
8072384: Setting IP_TOS on java.net sockets not working on unix
coffeys
parents:
28059
diff
changeset
|
658 |
*level = IPPROTO_IPV6; |
88469d06e03f
8072384: Setting IP_TOS on java.net sockets not working on unix
coffeys
parents:
28059
diff
changeset
|
659 |
*optname = IPV6_TCLASS; |
88469d06e03f
8072384: Setting IP_TOS on java.net sockets not working on unix
coffeys
parents:
28059
diff
changeset
|
660 |
return 0; |
88469d06e03f
8072384: Setting IP_TOS on java.net sockets not working on unix
coffeys
parents:
28059
diff
changeset
|
661 |
#endif |
2 | 662 |
} |
663 |
} |
|
664 |
||
665 |
/* |
|
666 |
* Map the Java level option to the native level |
|
667 |
*/ |
|
668 |
for (i=0; i<(int)(sizeof(opts) / sizeof(opts[0])); i++) { |
|
669 |
if (cmd == opts[i].cmd) { |
|
670 |
*level = opts[i].level; |
|
671 |
*optname = opts[i].optname; |
|
672 |
return 0; |
|
673 |
} |
|
674 |
} |
|
675 |
||
676 |
/* not found */ |
|
677 |
return -1; |
|
678 |
} |
|
679 |
||
680 |
/* |
|
681 |
* Wrapper for getsockopt system routine - does any necessary |
|
13999
f6a2ce6a3e40
7193520: Removed references to Linux kernel version 2.2
chegar
parents:
13048
diff
changeset
|
682 |
* pre/post processing to deal with OS specific oddities :- |
2 | 683 |
* |
684 |
* On Linux the SO_SNDBUF/SO_RCVBUF values must be post-processed |
|
685 |
* to compensate for an incorrect value returned by the kernel. |
|
686 |
*/ |
|
687 |
int |
|
688 |
NET_GetSockOpt(int fd, int level, int opt, void *result, |
|
689 |
int *len) |
|
690 |
{ |
|
691 |
int rv; |
|
23015
73b21ab36615
8034174: Remove use of JVM_* functions from java.net code
chegar
parents:
23010
diff
changeset
|
692 |
socklen_t socklen = *len; |
2 | 693 |
|
23015
73b21ab36615
8034174: Remove use of JVM_* functions from java.net code
chegar
parents:
23010
diff
changeset
|
694 |
rv = getsockopt(fd, level, opt, result, &socklen); |
73b21ab36615
8034174: Remove use of JVM_* functions from java.net code
chegar
parents:
23010
diff
changeset
|
695 |
*len = socklen; |
911
9edd1b9607e2
6730740: Fix for 6729881 has apparently broken several 64 bit tests: "Bad address"
chegar
parents:
910
diff
changeset
|
696 |
|
2 | 697 |
if (rv < 0) { |
698 |
return rv; |
|
699 |
} |
|
700 |
||
701 |
#ifdef __linux__ |
|
702 |
/* |
|
703 |
* On Linux SO_SNDBUF/SO_RCVBUF aren't symmetric. This |
|
704 |
* stems from additional socket structures in the send |
|
705 |
* and receive buffers. |
|
706 |
*/ |
|
707 |
if ((level == SOL_SOCKET) && ((opt == SO_SNDBUF) |
|
708 |
|| (opt == SO_RCVBUF))) { |
|
709 |
int n = *((int *)result); |
|
710 |
n /= 2; |
|
711 |
*((int *)result) = n; |
|
712 |
} |
|
713 |
#endif |
|
714 |
||
12047
320a714614e9
7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
11514
diff
changeset
|
715 |
/* Workaround for Mac OS treating linger value as |
320a714614e9
7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
11514
diff
changeset
|
716 |
* signed integer |
320a714614e9
7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
11514
diff
changeset
|
717 |
*/ |
320a714614e9
7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
11514
diff
changeset
|
718 |
#ifdef MACOSX |
320a714614e9
7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
11514
diff
changeset
|
719 |
if (level == SOL_SOCKET && opt == SO_LINGER) { |
320a714614e9
7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
11514
diff
changeset
|
720 |
struct linger* to_cast = (struct linger*)result; |
320a714614e9
7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
11514
diff
changeset
|
721 |
to_cast->l_linger = (unsigned short)to_cast->l_linger; |
320a714614e9
7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
11514
diff
changeset
|
722 |
} |
320a714614e9
7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
11514
diff
changeset
|
723 |
#endif |
2 | 724 |
return rv; |
725 |
} |
|
726 |
||
727 |
/* |
|
728 |
* Wrapper for setsockopt system routine - performs any |
|
729 |
* necessary pre/post processing to deal with OS specific |
|
730 |
* issue :- |
|
731 |
* |
|
732 |
* On Solaris need to limit the suggested value for SO_SNDBUF |
|
733 |
* and SO_RCVBUF to the kernel configured limit |
|
734 |
* |
|
735 |
* For IP_TOS socket option need to mask off bits as this |
|
736 |
* 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
|
737 |
* an error. |
2 | 738 |
*/ |
739 |
int |
|
740 |
NET_SetSockOpt(int fd, int level, int opt, const void *arg, |
|
741 |
int len) |
|
742 |
{ |
|
22605
dba3d6b22818
8031581: PPC64: Addons and fixes for AIX to pass the jdk regression tests
simonis
parents:
22597
diff
changeset
|
743 |
|
2 | 744 |
#ifndef IPTOS_TOS_MASK |
745 |
#define IPTOS_TOS_MASK 0x1e |
|
746 |
#endif |
|
747 |
#ifndef IPTOS_PREC_MASK |
|
748 |
#define IPTOS_PREC_MASK 0xe0 |
|
749 |
#endif |
|
750 |
||
12047
320a714614e9
7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
11514
diff
changeset
|
751 |
#if defined(_ALLBSD_SOURCE) |
320a714614e9
7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
11514
diff
changeset
|
752 |
#if defined(KIPC_MAXSOCKBUF) |
320a714614e9
7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
11514
diff
changeset
|
753 |
int mib[3]; |
320a714614e9
7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
11514
diff
changeset
|
754 |
size_t rlen; |
320a714614e9
7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
11514
diff
changeset
|
755 |
#endif |
320a714614e9
7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
11514
diff
changeset
|
756 |
|
320a714614e9
7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
11514
diff
changeset
|
757 |
int *bufsize; |
320a714614e9
7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
11514
diff
changeset
|
758 |
|
320a714614e9
7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
11514
diff
changeset
|
759 |
#ifdef __APPLE__ |
320a714614e9
7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
11514
diff
changeset
|
760 |
static int maxsockbuf = -1; |
320a714614e9
7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
11514
diff
changeset
|
761 |
#else |
320a714614e9
7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
11514
diff
changeset
|
762 |
static long maxsockbuf = -1; |
320a714614e9
7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
11514
diff
changeset
|
763 |
#endif |
320a714614e9
7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
11514
diff
changeset
|
764 |
#endif |
320a714614e9
7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
11514
diff
changeset
|
765 |
|
2 | 766 |
/* |
767 |
* IPPROTO/IP_TOS :- |
|
30963
88469d06e03f
8072384: Setting IP_TOS on java.net sockets not working on unix
coffeys
parents:
28059
diff
changeset
|
768 |
* 1. IPv6 on Solaris/Mac OS: |
88469d06e03f
8072384: Setting IP_TOS on java.net sockets not working on unix
coffeys
parents:
28059
diff
changeset
|
769 |
* 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
|
770 |
* IPv6 and IPv4 scenarios. |
2 | 771 |
* 2. IPv6 on Linux: By default Linux ignores flowinfo |
772 |
* 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
|
773 |
* will be examined. We also set the IPv4 TOS option in this case. |
2 | 774 |
* 3. IPv4: set socket option based on ToS and Precedence |
775 |
* fields (otherwise get invalid argument) |
|
776 |
*/ |
|
777 |
if (level == IPPROTO_IP && opt == IP_TOS) { |
|
778 |
int *iptos; |
|
779 |
||
41834
99c4f72c0a91
8168771: Remove #ifdef AF_INET6 guards in libnet native coding
clanger
parents:
41771
diff
changeset
|
780 |
#if defined(__linux__) |
2 | 781 |
if (ipv6_available()) { |
782 |
int optval = 1; |
|
25170
f58832169add
8029607: Type of Service (TOS) cannot be set in IPv6 header
michaelm
parents:
23033
diff
changeset
|
783 |
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
|
784 |
(void *)&optval, sizeof(optval)) < 0) { |
f58832169add
8029607: Type of Service (TOS) cannot be set in IPv6 header
michaelm
parents:
23033
diff
changeset
|
785 |
return -1; |
f58832169add
8029607: Type of Service (TOS) cannot be set in IPv6 header
michaelm
parents:
23033
diff
changeset
|
786 |
} |
30963
88469d06e03f
8072384: Setting IP_TOS on java.net sockets not working on unix
coffeys
parents:
28059
diff
changeset
|
787 |
/* |
88469d06e03f
8072384: Setting IP_TOS on java.net sockets not working on unix
coffeys
parents:
28059
diff
changeset
|
788 |
* 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
|
789 |
* 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
|
790 |
* 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
|
791 |
* are connecting. |
88469d06e03f
8072384: Setting IP_TOS on java.net sockets not working on unix
coffeys
parents:
28059
diff
changeset
|
792 |
*/ |
88469d06e03f
8072384: Setting IP_TOS on java.net sockets not working on unix
coffeys
parents:
28059
diff
changeset
|
793 |
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
|
794 |
arg, len) < 0) { |
88469d06e03f
8072384: Setting IP_TOS on java.net sockets not working on unix
coffeys
parents:
28059
diff
changeset
|
795 |
return -1; |
88469d06e03f
8072384: Setting IP_TOS on java.net sockets not working on unix
coffeys
parents:
28059
diff
changeset
|
796 |
} |
2 | 797 |
} |
798 |
#endif |
|
799 |
||
800 |
iptos = (int *)arg; |
|
801 |
*iptos &= (IPTOS_TOS_MASK | IPTOS_PREC_MASK); |
|
802 |
} |
|
803 |
||
804 |
/* |
|
6696
7201f23dae0d
6989190: SO_SNDBUF/SO_RCVBUF limits should only be checked when setsockopt fails (sol)
alanb
parents:
6670
diff
changeset
|
805 |
* 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
|
806 |
* the value when it exceeds the system limit. |
2 | 807 |
*/ |
808 |
#ifdef __solaris__ |
|
809 |
if (level == SOL_SOCKET) { |
|
810 |
if (opt == SO_SNDBUF || opt == SO_RCVBUF) { |
|
23015
73b21ab36615
8034174: Remove use of JVM_* functions from java.net code
chegar
parents:
23010
diff
changeset
|
811 |
int sotype=0; |
73b21ab36615
8034174: Remove use of JVM_* functions from java.net code
chegar
parents:
23010
diff
changeset
|
812 |
socklen_t arglen; |
2 | 813 |
int *bufsize, maxbuf; |
6696
7201f23dae0d
6989190: SO_SNDBUF/SO_RCVBUF limits should only be checked when setsockopt fails (sol)
alanb
parents:
6670
diff
changeset
|
814 |
int ret; |
7201f23dae0d
6989190: SO_SNDBUF/SO_RCVBUF limits should only be checked when setsockopt fails (sol)
alanb
parents:
6670
diff
changeset
|
815 |
|
7201f23dae0d
6989190: SO_SNDBUF/SO_RCVBUF limits should only be checked when setsockopt fails (sol)
alanb
parents:
6670
diff
changeset
|
816 |
/* 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
|
817 |
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
|
818 |
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
|
819 |
return ret; |
7201f23dae0d
6989190: SO_SNDBUF/SO_RCVBUF limits should only be checked when setsockopt fails (sol)
alanb
parents:
6670
diff
changeset
|
820 |
|
7201f23dae0d
6989190: SO_SNDBUF/SO_RCVBUF limits should only be checked when setsockopt fails (sol)
alanb
parents:
6670
diff
changeset
|
821 |
/* Exceeded system limit so clamp and retry */ |
2 | 822 |
|
823 |
arglen = sizeof(sotype); |
|
824 |
if (getsockopt(fd, SOL_SOCKET, SO_TYPE, (void *)&sotype, |
|
825 |
&arglen) < 0) { |
|
826 |
return -1; |
|
827 |
} |
|
828 |
||
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
|
829 |
/* |
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
|
830 |
* 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
|
831 |
* 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
|
832 |
* 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
|
833 |
*/ |
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
|
834 |
if (!init_tcp_max_buf && sotype == SOCK_STREAM) { |
22341
4689530d03b9
8028293: Check local configuration for actual ephemeral port range
michaelm
parents:
20821
diff
changeset
|
835 |
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
|
836 |
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
|
837 |
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
|
838 |
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
|
839 |
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
|
840 |
} |
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
|
841 |
} |
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
|
842 |
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
|
843 |
} 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
|
844 |
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
|
845 |
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
|
846 |
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
|
847 |
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
|
848 |
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
|
849 |
} |
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
|
850 |
} |
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
|
851 |
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
|
852 |
} |
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
|
853 |
|
2 | 854 |
maxbuf = (sotype == SOCK_STREAM) ? tcp_max_buf : udp_max_buf; |
855 |
bufsize = (int *)arg; |
|
856 |
if (*bufsize > maxbuf) { |
|
857 |
*bufsize = maxbuf; |
|
858 |
} |
|
859 |
} |
|
860 |
} |
|
861 |
#endif |
|
862 |
||
22597
7515a991bb37
8024854: PPC64: Basic changes and files to build the class library on AIX
simonis
parents:
20821
diff
changeset
|
863 |
#ifdef _AIX |
7515a991bb37
8024854: PPC64: Basic changes and files to build the class library on AIX
simonis
parents:
20821
diff
changeset
|
864 |
if (level == SOL_SOCKET) { |
7515a991bb37
8024854: PPC64: Basic changes and files to build the class library on AIX
simonis
parents:
20821
diff
changeset
|
865 |
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
|
866 |
/* |
7515a991bb37
8024854: PPC64: Basic changes and files to build the class library on AIX
simonis
parents:
20821
diff
changeset
|
867 |
* 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
|
868 |
* 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
|
869 |
* 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
|
870 |
* 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
|
871 |
* 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
|
872 |
* 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
|
873 |
*/ |
7515a991bb37
8024854: PPC64: Basic changes and files to build the class library on AIX
simonis
parents:
20821
diff
changeset
|
874 |
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
|
875 |
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
|
876 |
// 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
|
877 |
return 0; |
7515a991bb37
8024854: PPC64: Basic changes and files to build the class library on AIX
simonis
parents:
20821
diff
changeset
|
878 |
} else { |
7515a991bb37
8024854: PPC64: Basic changes and files to build the class library on AIX
simonis
parents:
20821
diff
changeset
|
879 |
// 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
|
880 |
return ret; |
7515a991bb37
8024854: PPC64: Basic changes and files to build the class library on AIX
simonis
parents:
20821
diff
changeset
|
881 |
} |
7515a991bb37
8024854: PPC64: Basic changes and files to build the class library on AIX
simonis
parents:
20821
diff
changeset
|
882 |
} |
7515a991bb37
8024854: PPC64: Basic changes and files to build the class library on AIX
simonis
parents:
20821
diff
changeset
|
883 |
} |
7515a991bb37
8024854: PPC64: Basic changes and files to build the class library on AIX
simonis
parents:
20821
diff
changeset
|
884 |
#endif |
7515a991bb37
8024854: PPC64: Basic changes and files to build the class library on AIX
simonis
parents:
20821
diff
changeset
|
885 |
|
2 | 886 |
/* |
887 |
* 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
|
888 |
* structures and the packet payload. The implication |
2 | 889 |
* 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
|
890 |
* must be discarded. |
2 | 891 |
*/ |
892 |
#ifdef __linux__ |
|
893 |
if (level == SOL_SOCKET && opt == SO_RCVBUF) { |
|
894 |
int *bufsize = (int *)arg; |
|
895 |
if (*bufsize < 1024) { |
|
896 |
*bufsize = 1024; |
|
897 |
} |
|
898 |
} |
|
899 |
#endif |
|
900 |
||
12047
320a714614e9
7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
11514
diff
changeset
|
901 |
#if defined(_ALLBSD_SOURCE) |
320a714614e9
7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
11514
diff
changeset
|
902 |
/* |
320a714614e9
7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
11514
diff
changeset
|
903 |
* SOL_SOCKET/{SO_SNDBUF,SO_RCVBUF} - On FreeBSD need to |
320a714614e9
7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
11514
diff
changeset
|
904 |
* 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
|
905 |
* an ENOBUFS error. |
320a714614e9
7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
11514
diff
changeset
|
906 |
*/ |
320a714614e9
7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
11514
diff
changeset
|
907 |
if (level == SOL_SOCKET) { |
320a714614e9
7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
11514
diff
changeset
|
908 |
if (opt == SO_SNDBUF || opt == SO_RCVBUF) { |
320a714614e9
7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
11514
diff
changeset
|
909 |
#ifdef KIPC_MAXSOCKBUF |
320a714614e9
7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
11514
diff
changeset
|
910 |
if (maxsockbuf == -1) { |
320a714614e9
7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
11514
diff
changeset
|
911 |
mib[0] = CTL_KERN; |
320a714614e9
7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
11514
diff
changeset
|
912 |
mib[1] = KERN_IPC; |
320a714614e9
7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
11514
diff
changeset
|
913 |
mib[2] = KIPC_MAXSOCKBUF; |
320a714614e9
7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
11514
diff
changeset
|
914 |
rlen = sizeof(maxsockbuf); |
320a714614e9
7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
11514
diff
changeset
|
915 |
if (sysctl(mib, 3, &maxsockbuf, &rlen, NULL, 0) == -1) |
320a714614e9
7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
11514
diff
changeset
|
916 |
maxsockbuf = 1024; |
320a714614e9
7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
11514
diff
changeset
|
917 |
|
320a714614e9
7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
11514
diff
changeset
|
918 |
#if 1 |
320a714614e9
7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
11514
diff
changeset
|
919 |
/* 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
|
920 |
problem. It should be removed when kern.ipc.maxsockbuf |
320a714614e9
7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
11514
diff
changeset
|
921 |
will be real value. */ |
320a714614e9
7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
11514
diff
changeset
|
922 |
maxsockbuf = (maxsockbuf/5)*4; |
320a714614e9
7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
11514
diff
changeset
|
923 |
#endif |
320a714614e9
7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
11514
diff
changeset
|
924 |
} |
320a714614e9
7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
11514
diff
changeset
|
925 |
#elif defined(__OpenBSD__) |
320a714614e9
7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
11514
diff
changeset
|
926 |
maxsockbuf = SB_MAX; |
320a714614e9
7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
11514
diff
changeset
|
927 |
#else |
320a714614e9
7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
11514
diff
changeset
|
928 |
maxsockbuf = 64 * 1024; /* XXX: NetBSD */ |
320a714614e9
7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
11514
diff
changeset
|
929 |
#endif |
320a714614e9
7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
11514
diff
changeset
|
930 |
|
320a714614e9
7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
11514
diff
changeset
|
931 |
bufsize = (int *)arg; |
320a714614e9
7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
11514
diff
changeset
|
932 |
if (*bufsize > maxsockbuf) { |
320a714614e9
7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
11514
diff
changeset
|
933 |
*bufsize = maxsockbuf; |
320a714614e9
7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
11514
diff
changeset
|
934 |
} |
320a714614e9
7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
11514
diff
changeset
|
935 |
|
320a714614e9
7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
11514
diff
changeset
|
936 |
if (opt == SO_RCVBUF && *bufsize < 1024) { |
320a714614e9
7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
11514
diff
changeset
|
937 |
*bufsize = 1024; |
320a714614e9
7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
11514
diff
changeset
|
938 |
} |
320a714614e9
7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
11514
diff
changeset
|
939 |
|
320a714614e9
7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
11514
diff
changeset
|
940 |
} |
320a714614e9
7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
11514
diff
changeset
|
941 |
} |
22605
dba3d6b22818
8031581: PPC64: Addons and fixes for AIX to pass the jdk regression tests
simonis
parents:
22597
diff
changeset
|
942 |
#endif |
12047
320a714614e9
7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
11514
diff
changeset
|
943 |
|
22605
dba3d6b22818
8031581: PPC64: Addons and fixes for AIX to pass the jdk regression tests
simonis
parents:
22597
diff
changeset
|
944 |
#if defined(_ALLBSD_SOURCE) || defined(_AIX) |
12047
320a714614e9
7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
11514
diff
changeset
|
945 |
/* |
320a714614e9
7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
11514
diff
changeset
|
946 |
* 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
|
947 |
* 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
|
948 |
* 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
|
949 |
* SO_REUSEPORT as well for that combination. |
320a714614e9
7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
11514
diff
changeset
|
950 |
*/ |
320a714614e9
7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
11514
diff
changeset
|
951 |
if (level == SOL_SOCKET && opt == SO_REUSEADDR) { |
320a714614e9
7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
11514
diff
changeset
|
952 |
int sotype; |
320a714614e9
7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
11514
diff
changeset
|
953 |
socklen_t arglen; |
320a714614e9
7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
11514
diff
changeset
|
954 |
|
320a714614e9
7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
11514
diff
changeset
|
955 |
arglen = sizeof(sotype); |
320a714614e9
7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
11514
diff
changeset
|
956 |
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
|
957 |
return -1; |
320a714614e9
7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
11514
diff
changeset
|
958 |
} |
320a714614e9
7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
11514
diff
changeset
|
959 |
|
320a714614e9
7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
11514
diff
changeset
|
960 |
if (sotype == SOCK_DGRAM) { |
22605
dba3d6b22818
8031581: PPC64: Addons and fixes for AIX to pass the jdk regression tests
simonis
parents:
22597
diff
changeset
|
961 |
setsockopt(fd, level, SO_REUSEPORT, arg, len); |
12047
320a714614e9
7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
11514
diff
changeset
|
962 |
} |
320a714614e9
7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
11514
diff
changeset
|
963 |
} |
320a714614e9
7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
11514
diff
changeset
|
964 |
#endif |
320a714614e9
7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
11514
diff
changeset
|
965 |
|
2 | 966 |
return setsockopt(fd, level, opt, arg, len); |
967 |
} |
|
968 |
||
969 |
/* |
|
970 |
* Wrapper for bind system call - performs any necessary pre/post |
|
971 |
* processing to deal with OS specific issues :- |
|
972 |
* |
|
973 |
* Linux allows a socket to bind to 127.0.0.255 which must be |
|
974 |
* caught. |
|
975 |
* |
|
13043
10fa4f21ea0f
7123896: Unexpected behavior due to Solaris using separate IPv4 and IPv6 port spaces
coffeys
parents:
12047
diff
changeset
|
976 |
* 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
|
977 |
* bind to guarantee a unique port number across the IPv4 and |
2 | 978 |
* IPv6 port spaces. |
979 |
* |
|
980 |
*/ |
|
981 |
int |
|
43100 | 982 |
NET_Bind(int fd, SOCKETADDRESS *sa, int len) |
2 | 983 |
{ |
41834
99c4f72c0a91
8168771: Remove #ifdef AF_INET6 guards in libnet native coding
clanger
parents:
41771
diff
changeset
|
984 |
#if defined(__solaris__) |
2 | 985 |
int level = -1; |
986 |
int exclbind = -1; |
|
987 |
#endif |
|
988 |
int rv; |
|
31711 | 989 |
int arg, alen; |
2 | 990 |
|
991 |
#ifdef __linux__ |
|
992 |
/* |
|
993 |
* ## get bugId for this issue - goes back to 1.2.2 port ## |
|
994 |
* ## When IPv6 is enabled this will be an IPv4-mapped |
|
995 |
* ## with family set to AF_INET6 |
|
996 |
*/ |
|
43100 | 997 |
if (sa->sa.sa_family == AF_INET) { |
998 |
if ((ntohl(sa->sa4.sin_addr.s_addr) & 0x7f0000ff) == 0x7f0000ff) { |
|
2 | 999 |
errno = EADDRNOTAVAIL; |
1000 |
return -1; |
|
1001 |
} |
|
1002 |
} |
|
1003 |
#endif |
|
1004 |
||
31711 | 1005 |
#if defined(__solaris__) |
2 | 1006 |
/* |
13043
10fa4f21ea0f
7123896: Unexpected behavior due to Solaris using separate IPv4 and IPv6 port spaces
coffeys
parents:
12047
diff
changeset
|
1007 |
* Solaris has separate IPv4 and IPv6 port spaces so we |
2 | 1008 |
* use an exclusive bind when SO_REUSEADDR is not used to |
1009 |
* 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
|
1010 |
* This also avoids problems with IPv6 sockets connecting |
2 | 1011 |
* to IPv4 mapped addresses whereby the socket conversion |
1012 |
* results in a late bind that fails because the |
|
1013 |
* corresponding IPv4 port is in use. |
|
1014 |
*/ |
|
31711 | 1015 |
alen = sizeof(arg); |
2 | 1016 |
|
43100 | 1017 |
if (useExclBind || |
1018 |
getsockopt(fd, SOL_SOCKET, SO_REUSEADDR, (char *)&arg, &alen) == 0) |
|
1019 |
{ |
|
31711 | 1020 |
if (useExclBind || arg == 0) { |
1021 |
/* |
|
1022 |
* SO_REUSEADDR is disabled or sun.net.useExclusiveBind |
|
1023 |
* property is true so enable TCP_EXCLBIND or |
|
1024 |
* UDP_EXCLBIND |
|
1025 |
*/ |
|
1026 |
alen = sizeof(arg); |
|
43100 | 1027 |
if (getsockopt(fd, SOL_SOCKET, SO_TYPE, (char *)&arg, &alen) == 0) |
1028 |
{ |
|
31711 | 1029 |
if (arg == SOCK_STREAM) { |
1030 |
level = IPPROTO_TCP; |
|
1031 |
exclbind = TCP_EXCLBIND; |
|
1032 |
} else { |
|
1033 |
level = IPPROTO_UDP; |
|
1034 |
exclbind = UDP_EXCLBIND; |
|
2 | 1035 |
} |
31711 | 1036 |
} |
2 | 1037 |
|
31711 | 1038 |
arg = 1; |
43100 | 1039 |
setsockopt(fd, level, exclbind, (char *)&arg, sizeof(arg)); |
2 | 1040 |
} |
1041 |
} |
|
1042 |
||
1043 |
#endif |
|
1044 |
||
43100 | 1045 |
rv = bind(fd, &sa->sa, len); |
2 | 1046 |
|
41834
99c4f72c0a91
8168771: Remove #ifdef AF_INET6 guards in libnet native coding
clanger
parents:
41771
diff
changeset
|
1047 |
#if defined(__solaris__) |
2 | 1048 |
if (rv < 0) { |
1049 |
int en = errno; |
|
1050 |
/* Restore *_EXCLBIND if the bind fails */ |
|
1051 |
if (exclbind != -1) { |
|
1052 |
int arg = 0; |
|
1053 |
setsockopt(fd, level, exclbind, (char *)&arg, |
|
1054 |
sizeof(arg)); |
|
1055 |
} |
|
1056 |
errno = en; |
|
1057 |
} |
|
1058 |
#endif |
|
1059 |
||
1060 |
return rv; |
|
1061 |
} |
|
1062 |
||
1063 |
/** |
|
23033
0cc7c83fde3c
8035949: Remove unused macro USE_SELECT and clean up Unix version of net_util_md.{c,h}
simonis
parents:
23028
diff
changeset
|
1064 |
* Wrapper for poll with timeout on a single file descriptor. |
2 | 1065 |
* |
1066 |
* flags (defined in net_util_md.h can be any combination of |
|
1067 |
* NET_WAIT_READ, NET_WAIT_WRITE & NET_WAIT_CONNECT. |
|
1068 |
* |
|
1069 |
* 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
|
1070 |
* of the specified operations or the timeout expired. |
2 | 1071 |
* |
1072 |
* It returns the time left from the timeout (possibly 0), or -1 if it expired. |
|
1073 |
*/ |
|
1074 |
||
52073
1c8745e31fa3
8212000: Verify exported symbols in java.base (libnet, libnio/ch)
prappo
parents:
51151
diff
changeset
|
1075 |
jint |
2 | 1076 |
NET_Wait(JNIEnv *env, jint fd, jint flags, jint timeout) |
1077 |
{ |
|
45061
74b09ee3cd55
8179905: Remove the use of gettimeofday in Networking code
vtewari
parents:
44921
diff
changeset
|
1078 |
jlong prevNanoTime = JVM_NanoTime(env, 0); |
74b09ee3cd55
8179905: Remove the use of gettimeofday in Networking code
vtewari
parents:
44921
diff
changeset
|
1079 |
jlong nanoTimeout = (jlong) timeout * NET_NSEC_PER_MSEC; |
2 | 1080 |
jint read_rv; |
1081 |
||
1082 |
while (1) { |
|
45061
74b09ee3cd55
8179905: Remove the use of gettimeofday in Networking code
vtewari
parents:
44921
diff
changeset
|
1083 |
jlong newNanoTime; |
23033
0cc7c83fde3c
8035949: Remove unused macro USE_SELECT and clean up Unix version of net_util_md.{c,h}
simonis
parents:
23028
diff
changeset
|
1084 |
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
|
1085 |
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
|
1086 |
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
|
1087 |
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
|
1088 |
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
|
1089 |
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
|
1090 |
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
|
1091 |
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
|
1092 |
pfd.events |= POLLOUT; |
2 | 1093 |
|
23033
0cc7c83fde3c
8035949: Remove unused macro USE_SELECT and clean up Unix version of net_util_md.{c,h}
simonis
parents:
23028
diff
changeset
|
1094 |
errno = 0; |
45061
74b09ee3cd55
8179905: Remove the use of gettimeofday in Networking code
vtewari
parents:
44921
diff
changeset
|
1095 |
read_rv = NET_Poll(&pfd, 1, nanoTimeout / NET_NSEC_PER_MSEC); |
2 | 1096 |
|
45061
74b09ee3cd55
8179905: Remove the use of gettimeofday in Networking code
vtewari
parents:
44921
diff
changeset
|
1097 |
newNanoTime = JVM_NanoTime(env, 0); |
74b09ee3cd55
8179905: Remove the use of gettimeofday in Networking code
vtewari
parents:
44921
diff
changeset
|
1098 |
nanoTimeout -= (newNanoTime - prevNanoTime); |
74b09ee3cd55
8179905: Remove the use of gettimeofday in Networking code
vtewari
parents:
44921
diff
changeset
|
1099 |
if (nanoTimeout < NET_NSEC_PER_MSEC) { |
2 | 1100 |
return read_rv > 0 ? 0 : -1; |
1101 |
} |
|
45061
74b09ee3cd55
8179905: Remove the use of gettimeofday in Networking code
vtewari
parents:
44921
diff
changeset
|
1102 |
prevNanoTime = newNanoTime; |
2 | 1103 |
|
1104 |
if (read_rv > 0) { |
|
1105 |
break; |
|
1106 |
} |
|
1107 |
} /* while */ |
|
45061
74b09ee3cd55
8179905: Remove the use of gettimeofday in Networking code
vtewari
parents:
44921
diff
changeset
|
1108 |
return (nanoTimeout / NET_NSEC_PER_MSEC); |
44921
0672237e13c0
8179602: Backout fix for JDK-8165437 due to breakage on 32-bit Linux
michaelm
parents:
44916
diff
changeset
|
1109 |
} |