mirror of
https://github.com/SpigotMC/BungeeCord.git
synced 2024-11-24 03:05:49 +01:00
Remove ipv6 scope from forwarded addresses
Affects forwarding when epoll enabled
This commit is contained in:
parent
c96628b72e
commit
7ec1f487c1
@ -51,6 +51,7 @@ import net.md_5.bungee.protocol.packet.ScoreboardObjective;
|
|||||||
import net.md_5.bungee.protocol.packet.ScoreboardScore;
|
import net.md_5.bungee.protocol.packet.ScoreboardScore;
|
||||||
import net.md_5.bungee.protocol.packet.SetCompression;
|
import net.md_5.bungee.protocol.packet.SetCompression;
|
||||||
import net.md_5.bungee.protocol.packet.ViewDistance;
|
import net.md_5.bungee.protocol.packet.ViewDistance;
|
||||||
|
import net.md_5.bungee.util.AddressUtil;
|
||||||
import net.md_5.bungee.util.BufUtil;
|
import net.md_5.bungee.util.BufUtil;
|
||||||
import net.md_5.bungee.util.QuietException;
|
import net.md_5.bungee.util.QuietException;
|
||||||
|
|
||||||
@ -102,7 +103,7 @@ public class ServerConnector extends PacketHandler
|
|||||||
|
|
||||||
if ( BungeeCord.getInstance().config.isIpForward() && user.getSocketAddress() instanceof InetSocketAddress )
|
if ( BungeeCord.getInstance().config.isIpForward() && user.getSocketAddress() instanceof InetSocketAddress )
|
||||||
{
|
{
|
||||||
String newHost = copiedHandshake.getHost() + "\00" + user.getAddress().getHostString() + "\00" + user.getUUID();
|
String newHost = copiedHandshake.getHost() + "\00" + AddressUtil.sanitizeAddress( user.getAddress() ) + "\00" + user.getUUID();
|
||||||
|
|
||||||
LoginResult profile = user.getPendingConnection().getLoginProfile();
|
LoginResult profile = user.getPendingConnection().getLoginProfile();
|
||||||
if ( profile != null && profile.getProperties() != null && profile.getProperties().length > 0 )
|
if ( profile != null && profile.getProperties() != null && profile.getProperties().length > 0 )
|
||||||
|
26
proxy/src/main/java/net/md_5/bungee/util/AddressUtil.java
Normal file
26
proxy/src/main/java/net/md_5/bungee/util/AddressUtil.java
Normal file
@ -0,0 +1,26 @@
|
|||||||
|
package net.md_5.bungee.util;
|
||||||
|
|
||||||
|
import java.net.Inet6Address;
|
||||||
|
import java.net.InetSocketAddress;
|
||||||
|
import lombok.AccessLevel;
|
||||||
|
import lombok.NoArgsConstructor;
|
||||||
|
|
||||||
|
@NoArgsConstructor(access = AccessLevel.PRIVATE)
|
||||||
|
public class AddressUtil
|
||||||
|
{
|
||||||
|
|
||||||
|
public static String sanitizeAddress(InetSocketAddress addr)
|
||||||
|
{
|
||||||
|
String string = addr.getHostString();
|
||||||
|
|
||||||
|
// Remove IPv6 scope if present
|
||||||
|
if ( addr.getAddress() instanceof Inet6Address )
|
||||||
|
{
|
||||||
|
int strip = string.indexOf( '%' );
|
||||||
|
return ( strip == -1 ) ? string : string.substring( 0, strip );
|
||||||
|
} else
|
||||||
|
{
|
||||||
|
return string;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,19 @@
|
|||||||
|
package net.md_5.bungee.util;
|
||||||
|
|
||||||
|
import java.net.InetSocketAddress;
|
||||||
|
import org.junit.Assert;
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
|
public class AddressUtilTest
|
||||||
|
{
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testScope()
|
||||||
|
{
|
||||||
|
InetSocketAddress addr = new InetSocketAddress( "0:0:0:0:0:0:0:1%0", 25577 );
|
||||||
|
Assert.assertEquals( "0:0:0:0:0:0:0:1", AddressUtil.sanitizeAddress( addr ) );
|
||||||
|
|
||||||
|
InetSocketAddress addr2 = new InetSocketAddress( "0:0:0:0:0:0:0:1", 25577 );
|
||||||
|
Assert.assertEquals( "0:0:0:0:0:0:0:1", AddressUtil.sanitizeAddress( addr2 ) );
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user