mirror of
https://github.com/openjdk/jdk.git
synced 2025-08-27 14:54:52 +02:00
8216417: cleanup of IPv6 scope-id handling
Reviewed-by: alanb, chegar, dfuchs
This commit is contained in:
parent
04ea6ae9b3
commit
247a6a2ce4
23 changed files with 761 additions and 595 deletions
|
@ -33,6 +33,7 @@ import java.util.Set;
|
|||
|
||||
import sun.net.ResourceManager;
|
||||
import sun.net.ext.ExtendedSocketOptions;
|
||||
import sun.net.util.IPAddressUtil;
|
||||
import sun.security.action.GetPropertyAction;
|
||||
|
||||
/**
|
||||
|
@ -110,6 +111,9 @@ abstract class AbstractPlainDatagramSocketImpl extends DatagramSocketImpl
|
|||
*/
|
||||
protected synchronized void bind(int lport, InetAddress laddr)
|
||||
throws SocketException {
|
||||
if (laddr.isLinkLocalAddress()) {
|
||||
laddr = IPAddressUtil.toScopedAddress(laddr);
|
||||
}
|
||||
bind0(lport, laddr);
|
||||
}
|
||||
|
||||
|
@ -121,7 +125,19 @@ abstract class AbstractPlainDatagramSocketImpl extends DatagramSocketImpl
|
|||
* destination address to send the packet to.
|
||||
* @param p the packet to be sent.
|
||||
*/
|
||||
protected abstract void send(DatagramPacket p) throws IOException;
|
||||
protected void send(DatagramPacket p) throws IOException {
|
||||
InetAddress orig = p.getAddress();
|
||||
if (orig.isLinkLocalAddress()) {
|
||||
InetAddress scoped = IPAddressUtil.toScopedAddress(orig);
|
||||
if (orig != scoped) {
|
||||
p = new DatagramPacket(p.getData(), p.getOffset(),
|
||||
p.getLength(), scoped, p.getPort());
|
||||
}
|
||||
}
|
||||
send0(p);
|
||||
}
|
||||
|
||||
protected abstract void send0(DatagramPacket p) throws IOException;
|
||||
|
||||
/**
|
||||
* Connects a datagram socket to a remote destination. This associates the remote
|
||||
|
@ -131,6 +147,9 @@ abstract class AbstractPlainDatagramSocketImpl extends DatagramSocketImpl
|
|||
* @param port the remote port number
|
||||
*/
|
||||
protected void connect(InetAddress address, int port) throws SocketException {
|
||||
if (address.isLinkLocalAddress()) {
|
||||
address = IPAddressUtil.toScopedAddress(address);
|
||||
}
|
||||
connect0(address, port);
|
||||
connectedAddress = address;
|
||||
connectedPort = port;
|
||||
|
|
|
@ -43,6 +43,7 @@ import sun.net.NetHooks;
|
|||
import sun.net.PlatformSocketImpl;
|
||||
import sun.net.ResourceManager;
|
||||
import sun.net.ext.ExtendedSocketOptions;
|
||||
import sun.net.util.IPAddressUtil;
|
||||
import sun.net.util.SocketExceptions;
|
||||
|
||||
/**
|
||||
|
@ -157,8 +158,12 @@ abstract class AbstractPlainSocketImpl extends SocketImpl implements PlatformSoc
|
|||
boolean connected = false;
|
||||
try {
|
||||
InetAddress address = InetAddress.getByName(host);
|
||||
this.port = port;
|
||||
// recording this.address as supplied by caller before calling connect
|
||||
this.address = address;
|
||||
this.port = port;
|
||||
if (address.isLinkLocalAddress()) {
|
||||
address = IPAddressUtil.toScopedAddress(address);
|
||||
}
|
||||
|
||||
connectToAddress(address, port, timeout);
|
||||
connected = true;
|
||||
|
@ -182,8 +187,12 @@ abstract class AbstractPlainSocketImpl extends SocketImpl implements PlatformSoc
|
|||
* @param port the specified port
|
||||
*/
|
||||
protected void connect(InetAddress address, int port) throws IOException {
|
||||
this.port = port;
|
||||
// recording this.address as supplied by caller before calling connect
|
||||
this.address = address;
|
||||
this.port = port;
|
||||
if (address.isLinkLocalAddress()) {
|
||||
address = IPAddressUtil.toScopedAddress(address);
|
||||
}
|
||||
|
||||
try {
|
||||
connectToAddress(address, port, timeout);
|
||||
|
@ -215,10 +224,14 @@ abstract class AbstractPlainSocketImpl extends SocketImpl implements PlatformSoc
|
|||
InetSocketAddress addr = (InetSocketAddress) address;
|
||||
if (addr.isUnresolved())
|
||||
throw new UnknownHostException(addr.getHostName());
|
||||
// recording this.address as supplied by caller before calling connect
|
||||
InetAddress ia = addr.getAddress();
|
||||
this.address = ia;
|
||||
this.port = addr.getPort();
|
||||
this.address = addr.getAddress();
|
||||
|
||||
connectToAddress(this.address, port, timeout);
|
||||
if (ia.isLinkLocalAddress()) {
|
||||
ia = IPAddressUtil.toScopedAddress(ia);
|
||||
}
|
||||
connectToAddress(ia, port, timeout);
|
||||
connected = true;
|
||||
} finally {
|
||||
if (!connected) {
|
||||
|
@ -546,6 +559,9 @@ abstract class AbstractPlainSocketImpl extends SocketImpl implements PlatformSoc
|
|||
NetHooks.beforeTcpBind(fd, address, lport);
|
||||
}
|
||||
}
|
||||
if (address.isLinkLocalAddress()) {
|
||||
address = IPAddressUtil.toScopedAddress(address);
|
||||
}
|
||||
socketBind(address, lport);
|
||||
isBound = true;
|
||||
}
|
||||
|
|
|
@ -176,11 +176,6 @@ public final
|
|||
class Inet6Address extends InetAddress {
|
||||
static final int INADDRSZ = 16;
|
||||
|
||||
/*
|
||||
* cached scope_id - for link-local address use only.
|
||||
*/
|
||||
private transient int cached_scope_id; // 0
|
||||
|
||||
private class Inet6AddressHolder {
|
||||
|
||||
private Inet6AddressHolder() {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue