You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@mina.apache.org by "Guillermo Grandes (Jira)" <ji...@apache.org> on 2020/08/27 17:31:00 UTC
[jira] [Created] (SSHD-1066) PortForwarding: Error on multiple
binding (same port, different IP).
Guillermo Grandes created SSHD-1066:
---------------------------------------
Summary: PortForwarding: Error on multiple binding (same port, different IP).
Key: SSHD-1066
URL: https://issues.apache.org/jira/browse/SSHD-1066
Project: MINA SSHD
Issue Type: Bug
Affects Versions: 2.5.1
Reporter: Guillermo Grandes
I'm trying to listen in same port on 2 IPs of same machine, _multihomed_, the equivalent in openssh is:
{noformat}
# ssh -L 127.0.0.2:8080:test.javastack.org:80 -L 127.0.0.3:8080:test.javastack.org:80 test-sshd@server -N
# sudo netstat -lntp | grep :8080
tcp 0 0 127.0.0.3:8080 0.0.0.0:* LISTEN 2650/ssh
tcp 0 0 127.0.0.2:8080 0.0.0.0:* LISTEN 2650/ssh
{noformat}
Sample code to reproduce the test case:
{code:java}
public static final int DEFAULT_TIMEOUT = 10000;
public static void test(final String username, final String password, final String host, final int port)
throws IOException {
boolean testLocal = true;
try (SshClient client = SshClient.setUpDefaultClient()) {
client.setServerKeyVerifier(AcceptAllServerKeyVerifier.INSTANCE);
client.start();
try {
ConnectFuture connect = client.connect(username, host, port);
connect.await(DEFAULT_TIMEOUT);
ClientSession session = connect.getClientSession();
session.addPasswordIdentity(password);
session.auth().verify(DEFAULT_TIMEOUT);
if (testLocal) {
System.out.println("================== Local 1 ==================");
ExplicitPortForwardingTracker localTracker1 = session.createLocalPortForwardingTracker(
new SshdSocketAddress("127.0.0.2", 8080),
new SshdSocketAddress("test.javastack.org", 80));
sleep(1000);
System.out.println("LocalPortForwarding: " //
+ localTracker1.getLocalAddress() + " -> " //
+ localTracker1.getRemoteAddress());
SshdSocketAddress localSocketAddress1 = localTracker1.getLocalAddress();
if (localSocketAddress1 != null) {
Proxy proxy = new Proxy(Proxy.Type.HTTP,
new InetSocketAddress(localSocketAddress1.getHostName(), //
localSocketAddress1.getPort()));
testRemoteURL(proxy, "http://test.javastack.org/");
}
System.out.println("================== Local 2 ==================");
ExplicitPortForwardingTracker localTracker2 = session.createLocalPortForwardingTracker(
new SshdSocketAddress("127.0.0.3", 8080),
new SshdSocketAddress("test.javastack.org", 80));
sleep(1000);
System.out.println("LocalPortForwarding: " //
+ localTracker2.getLocalAddress() + " -> " //
+ localTracker2.getRemoteAddress());
SshdSocketAddress localSocketAddress2 = localTracker2.getLocalAddress();
if (localSocketAddress2 != null) {
Proxy proxy = new Proxy(Proxy.Type.HTTP,
new InetSocketAddress(localSocketAddress2.getHostName(), //
localSocketAddress2.getPort()));
testRemoteURL(proxy, "http://test.javastack.org/");
}
}
} finally {
client.stop();
}
}
}
private static final void sleep(final long t) {
try {
Thread.sleep(t);
} catch (Exception ign) {
}
}
private static final void testRemoteURL(final Proxy proxy, final String url) throws IOException {
HttpURLConnection connection = (HttpURLConnection) new URL(url).openConnection(proxy);
connection.setConnectTimeout(DEFAULT_TIMEOUT);
connection.setReadTimeout(DEFAULT_TIMEOUT);
System.out.println("Get URL: " + connection.getURL());
try {
BufferedReader in = new BufferedReader(new InputStreamReader(connection.getInputStream()));
System.out.println("Response from server:");
String inputLine;
while ((inputLine = in.readLine()) != null) {
System.out.println(inputLine);
}
in.close();
} catch (Exception e) {
System.out.println("Failed: " + e);
}
}
public static void main(String[] args) throws Throwable {
test("test-sshd", "secret", "server", 22);
sleep(3000);
}
{code}
Error received:
{code:none}
Exception in thread "main" java.io.IOException: Multiple local port forwarding addressing on port=8080: current=test.javastack.org:80, previous=test.javastack.org:80
at org.apache.sshd.common.forward.DefaultForwardingFilter.startLocalPortForwarding(DefaultForwardingFilter.java:208)
at org.apache.sshd.client.session.AbstractClientSession.startLocalPortForwarding(AbstractClientSession.java:374)
at org.apache.sshd.client.session.ClientSession.createLocalPortForwardingTracker(ClientSession.java:316)
at org.javastack.jentunnel.sandbox.SimpleBindingTest.test(SimpleBindingTest.java:52)
{code}
Result Expected:
{noformat}
================== Local 1 ==================
LocalPortForwarding: 127.0.0.2:8080 -> test.javastack.org:80
Get URL: http://test.javastack.org/
Response from server:
OK
================== Local 2 ==================
LocalPortForwarding: 127.0.0.3:8080 -> test.javastack.org:80
Get URL: http://test.javastack.org/
Response from server:
OK
{noformat}
* Note-1: The usage of loopback addresses (127.0.0.0/8) and same destination is to simplify/reproduce easily, don't care.
* Note-2: I don't checked if startRemotePortForwarding/startDynamicPortForwarding reproduce same issue as startLocalPortForwarding. But I suppose that yes.
--
This message was sent by Atlassian Jira
(v8.3.4#803005)
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@mina.apache.org
For additional commands, e-mail: dev-help@mina.apache.org