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