Skip to content

Commit 0fd1ce3

Browse files
committed
8233847: (sctp) Flx link-local IPv6 scope handling and test cleanup.
Backport-of: 76e5a32
1 parent bcce7af commit 0fd1ce3

File tree

13 files changed

+85
-72
lines changed

13 files changed

+85
-72
lines changed

src/java.base/share/classes/module-info.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -240,8 +240,9 @@
240240
jdk.naming.dns;
241241
exports sun.net.util to
242242
java.desktop,
243+
java.net.http,
243244
jdk.jconsole,
244-
java.net.http;
245+
jdk.sctp;
245246
exports sun.net.www to
246247
java.desktop,
247248
java.net.http,

src/jdk.sctp/share/classes/com/sun/nio/sctp/HandlerResult.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
*
3030
* <P> The {@code HandlerResult} is used to determine the behavior of the
3131
* channel after it handles a notification from the SCTP stack. Essentially its
32-
* value determines if the channel should try to receive another notificaiton or
32+
* value determines if the channel should try to receive another notification or
3333
* a message before returning.
3434
*
3535
* @since 1.7

src/jdk.sctp/unix/classes/sun/nio/ch/sctp/SctpChannelImpl.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@
5353
import com.sun.nio.sctp.NotificationHandler;
5454
import com.sun.nio.sctp.SctpChannel;
5555
import com.sun.nio.sctp.SctpSocketOption;
56+
import sun.net.util.IPAddressUtil;
5657
import sun.nio.ch.DirectBuffer;
5758
import sun.nio.ch.IOStatus;
5859
import sun.nio.ch.IOUtil;
@@ -1033,6 +1034,9 @@ private int sendFromNativeBuffer(int fd,
10331034
if (target != null) {
10341035
InetSocketAddress isa = Net.checkAddress(target);
10351036
addr = isa.getAddress();
1037+
if (addr.isLinkLocalAddress()) {
1038+
addr = IPAddressUtil.toScopedAddress(addr);
1039+
}
10361040
port = isa.getPort();
10371041
}
10381042

src/jdk.sctp/unix/classes/sun/nio/ch/sctp/SctpMultiChannelImpl.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@
5353
import com.sun.nio.sctp.SctpChannel;
5454
import com.sun.nio.sctp.SctpMultiChannel;
5555
import com.sun.nio.sctp.SctpSocketOption;
56+
import sun.net.util.IPAddressUtil;
5657
import sun.nio.ch.DirectBuffer;
5758
import sun.nio.ch.NativeThread;
5859
import sun.nio.ch.IOStatus;
@@ -892,6 +893,9 @@ private int sendFromNativeBuffer(int fd,
892893
if (target != null) {
893894
InetSocketAddress isa = Net.checkAddress(target);
894895
addr = isa.getAddress();
896+
if (addr.isLinkLocalAddress()) {
897+
addr = IPAddressUtil.toScopedAddress(addr);
898+
}
895899
port = isa.getPort();
896900
}
897901
int pos = bb.position();

src/jdk.sctp/unix/classes/sun/nio/ch/sctp/SctpNet.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
import java.util.HashSet;
3535
import java.security.AccessController;
3636
import java.security.PrivilegedAction;
37+
import sun.net.util.IPAddressUtil;
3738
import sun.nio.ch.IOUtil;
3839
import sun.nio.ch.Net;
3940
import com.sun.nio.sctp.SctpSocketOption;
@@ -169,9 +170,13 @@ static <T> void setSocketOption(int fd,
169170
InetSocketAddress netAddr = (InetSocketAddress)addr;
170171

171172
if (name.equals(SCTP_PRIMARY_ADDR)) {
173+
InetAddress inetAddress = netAddr.getAddress();
174+
if (inetAddress.isLinkLocalAddress()) {
175+
inetAddress = IPAddressUtil.toScopedAddress(inetAddress);
176+
}
172177
setPrimAddrOption0(fd,
173178
assocId,
174-
netAddr.getAddress(),
179+
inetAddress,
175180
netAddr.getPort());
176181
} else {
177182
setPeerPrimAddrOption0(fd,

test/jdk/com/sun/nio/sctp/SctpChannel/Bind.java

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2009, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2009, 2019, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -110,9 +110,10 @@ void testBind() {
110110
try {
111111
channel.close(); /* open a new unbound channel for test */
112112
channel = SctpChannel.open();
113-
connectChannel(channel);
114-
channel.bind(null);
115-
fail("AlreadyConnectedException expected");
113+
try (var peer = connectChannel(channel)) {
114+
channel.bind(null);
115+
fail("AlreadyConnectedException expected");
116+
}
116117
} catch (AlreadyConnectedException unused) { pass();
117118
} catch (IOException ioe) { unexpected(ioe); }
118119

@@ -264,7 +265,9 @@ void testBindUnbind(boolean connected) {
264265
} finally {
265266
try { if (channel != null) channel.close(); }
266267
catch (IOException ioe) { unexpected(ioe); }
267-
}
268+
try { if (peerChannel != null) peerChannel.close(); }
269+
catch (IOException ioe) { unexpected(ioe); }
270+
}
268271
}
269272

270273
boolean boundAddress(SctpChannel channel, InetAddress addr)

test/jdk/com/sun/nio/sctp/SctpChannel/CommUp.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2009, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2009, 2019, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -191,6 +191,9 @@ else if (sk.isReadable()) {
191191
}
192192
} //for
193193

194+
try { sc.close(); }
195+
catch (IOException ioe) { unexpected(ioe); }
196+
194197
} catch (IOException ioe) {
195198
unexpected(ioe);
196199
} catch (InterruptedException ie) {

test/jdk/com/sun/nio/sctp/SctpChannel/Connect.java

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -61,11 +61,10 @@ void test(String[] args) {
6161

6262
void doTest() {
6363
SctpChannel channel = null;
64-
SctpServerChannel ssc = null;
6564

66-
try {
65+
try (SctpServerChannel ssc = SctpServerChannel.open()) {
6766
/* Create a server channel to connect to */
68-
ssc = SctpServerChannel.open().bind(null);
67+
ssc.bind(null);
6968
Set<SocketAddress> addrs = ssc.getAllLocalAddresses();
7069
if (addrs.isEmpty())
7170
debug("addrs should not be empty");
@@ -209,8 +208,6 @@ public Void call() throws IOException {
209208
} finally {
210209
try { if (channel != null) channel.close(); }
211210
catch (IOException unused) {}
212-
try { if (ssc != null) ssc.close(); }
213-
catch (IOException unused) {}
214211
}
215212
}
216213

test/jdk/com/sun/nio/sctp/SctpChannel/SocketOptionTests.java

Lines changed: 17 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -72,8 +72,7 @@ void test(String[] args) {
7272
return;
7373
}
7474

75-
try {
76-
SctpChannel sc = SctpChannel.open();
75+
try (SctpChannel sc = SctpChannel.open()) {
7776

7877
/* check supported options */
7978
Set<SctpSocketOption<?>> options = sc.supportedOptions();
@@ -143,8 +142,6 @@ void test(String[] args) {
143142

144143
/* SCTP_PRIMARY_ADDR */
145144
void sctpPrimaryAddr() throws IOException {
146-
SocketAddress addrToSet = null;;
147-
148145
System.out.println("TESTING SCTP_PRIMARY_ADDR");
149146
SctpChannel sc = SctpChannel.open();
150147
SctpServerChannel ssc = SctpServerChannel.open().bind(null);
@@ -158,12 +155,11 @@ void sctpPrimaryAddr() throws IOException {
158155
sc.connect(serverAddr);
159156
SctpChannel peerChannel = ssc.accept();
160157
ssc.close();
161-
Set<SocketAddress> peerAddrs = peerChannel.getAllLocalAddresses();
162-
debug("Peer local Addresses: ");
163-
for (Iterator<SocketAddress> it = peerAddrs.iterator(); it.hasNext(); ) {
158+
Set<SocketAddress> remoteAddresses = sc.getRemoteAddresses();
159+
debug("Remote Addresses: ");
160+
for (Iterator<SocketAddress> it = remoteAddresses.iterator(); it.hasNext(); ) {
164161
InetSocketAddress addr = (InetSocketAddress)it.next();
165162
debug("\t" + addr);
166-
addrToSet = addr; // any of the peer addresses will do!
167163
}
168164

169165
/* retrieval of SCTP_PRIMARY_ADDR is not supported on Solaris */
@@ -176,25 +172,21 @@ void sctpPrimaryAddr() throws IOException {
176172
} else { /* Linux */
177173
SocketAddress primaryAddr = sc.getOption(SCTP_PRIMARY_ADDR);
178174
System.out.println("SCTP_PRIMARY_ADDR returned: " + primaryAddr);
179-
/* Verify that this is one of the peer addresses */
180-
boolean found = false;
181-
addrToSet = primaryAddr; // may not have more than one addr
182-
for (Iterator<SocketAddress> it = peerAddrs.iterator(); it.hasNext(); ) {
183-
InetSocketAddress addr = (InetSocketAddress)it.next();
184-
if (addr.equals(primaryAddr)) {
185-
found = true;
186-
}
187-
addrToSet = addr;
175+
/* Verify that this is one of the remote addresses */
176+
check(remoteAddresses.contains(primaryAddr), "SCTP_PRIMARY_ADDR returned bogus address!");
177+
178+
for (Iterator<SocketAddress> it = remoteAddresses.iterator(); it.hasNext(); ) {
179+
InetSocketAddress addrToSet = (InetSocketAddress) it.next();
180+
System.out.println("SCTP_PRIMARY_ADDR try set to: " + addrToSet);
181+
sc.setOption(SCTP_PRIMARY_ADDR, addrToSet);
182+
System.out.println("SCTP_PRIMARY_ADDR set to : " + addrToSet);
183+
primaryAddr = sc.getOption(SCTP_PRIMARY_ADDR);
184+
System.out.println("SCTP_PRIMARY_ADDR returned : " + primaryAddr);
185+
check(addrToSet.equals(primaryAddr), "SCTP_PRIMARY_ADDR not set correctly");
188186
}
189-
check(found, "SCTP_PRIMARY_ADDR returned bogus address!");
190-
191-
System.out.println("SCTP_PRIMARY_ADDR try set to: " + addrToSet);
192-
sc.setOption(SCTP_PRIMARY_ADDR, addrToSet);
193-
System.out.println("SCTP_PRIMARY_ADDR set to: " + addrToSet);
194-
primaryAddr = sc.getOption(SCTP_PRIMARY_ADDR);
195-
System.out.println("SCTP_PRIMARY_ADDR returned: " + primaryAddr);
196-
check(addrToSet.equals(primaryAddr),"SCTP_PRIMARY_ADDR not set correctly");
197187
}
188+
sc.close();
189+
peerChannel.close();
198190
}
199191
//--------------------- Infrastructure ---------------------------
200192
boolean debug = true;

test/jdk/com/sun/nio/sctp/SctpMultiChannel/Branch.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,8 @@ public void run() {
210210
/* echo the message */
211211
debug("Server: echoing first message");
212212
buffer.flip();
213-
int bytes = serverChannel.send(buffer, info);
213+
MessageInfo sendInfo = MessageInfo.createOutgoing(info.association(), null, 0);
214+
int bytes = serverChannel.send(buffer, sendInfo);
214215
debug("Server: sent " + bytes + "bytes");
215216

216217
clientFinishedLatch.await(10L, TimeUnit.SECONDS);

0 commit comments

Comments
 (0)