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