Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

UNDERTOW-652 MCMPHandler#handleRequest() does not work with IPv6 addr… #366

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -96,10 +96,10 @@ static void advertise(final ModClusterContainer container, final MCMPConfig.Adve
this.container = container;
this.protocol = config.getProtocol();
// MODCLUSTER-483 mod_cluster client does not yet support ipv6 addresses with zone indices so skip it
String host = config.getManagementHost();
String host = config.getManagementSocketAddress().getHostString();
int zoneIndex = host.indexOf("%");
this.host = (zoneIndex < 0) ? host : host.substring(0, zoneIndex);
this.port = config.getManagementPort();
this.port = config.getManagementSocketAddress().getPort();
this.path = config.getPath();
this.channel = channel;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,14 @@

package io.undertow.server.handlers.proxy.mod_cluster;

import java.net.InetAddress;
import java.net.UnknownHostException;

import io.undertow.server.HttpHandler;

import java.net.InetSocketAddress;

/**
* @author Emanuel Muckenhuber
* @author Radoslav Husar
* @version March 2016
*/
public class MCMPConfig {

Expand All @@ -36,41 +37,23 @@ public static WebBuilder webBuilder() {
return new WebBuilder();
}

private final String managementHost;
private final String managementHostIp;
private final int managementPort;
private final InetSocketAddress managementSocketAddress;
private final AdvertiseConfig advertiseConfig;

public MCMPConfig(Builder builder) {
this.managementHost = builder.managementHost;
this.managementPort = builder.managementPort;
this.managementSocketAddress = new InetSocketAddress(builder.managementHost, builder.managementPort);
if (builder.advertiseBuilder != null) {
this.advertiseConfig = new AdvertiseConfig(builder.advertiseBuilder, this);
} else {
this.advertiseConfig = null;
}
String mhip = managementHost;
try {
mhip = InetAddress.getByName(managementHost).getHostAddress();
} catch (UnknownHostException e) {

}
this.managementHostIp = mhip;
}

public String getManagementHost() {
return managementHost;
}

public int getManagementPort() {
return managementPort;
}

public String getManagementHostIp() {
return managementHostIp;
public InetSocketAddress getManagementSocketAddress() {
return managementSocketAddress;
}

AdvertiseConfig getAdvertiseConfig() {
public AdvertiseConfig getAdvertiseConfig() {
return advertiseConfig;
}

Expand Down Expand Up @@ -121,8 +104,7 @@ static class AdvertiseConfig {

private final int advertiseFrequency;

private final String managementHost;
private final int managementPort;
private final InetSocketAddress managementSocketAddress;

AdvertiseConfig(AdvertiseBuilder builder, MCMPConfig config) {
this.advertiseGroup = builder.advertiseGroup;
Expand All @@ -132,8 +114,7 @@ static class AdvertiseConfig {
this.securityKey = builder.securityKey;
this.protocol = builder.protocol;
this.path = builder.path;
this.managementHost = config.getManagementHost();
this.managementPort = config.getManagementPort();
this.managementSocketAddress = config.getManagementSocketAddress();
}

public String getAdvertiseGroup() {
Expand Down Expand Up @@ -164,20 +145,16 @@ public int getAdvertiseFrequency() {
return advertiseFrequency;
}

public String getManagementHost() {
return managementHost;
}

public int getManagementPort() {
return managementPort;
public InetSocketAddress getManagementSocketAddress() {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should not really be changing API's in a point release

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ideally yes, buts its really bad :-( and I am not sure how else to do this cleanly.. also all the getters are used internally by the implementation so there should be no harm.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess you just meant to keep them around as deprecated.. I can do that.

return managementSocketAddress;
}
}

public static class Builder {

private String managementHost;
private int managementPort;
private AdvertiseBuilder advertiseBuilder;
String managementHost;
int managementPort;
AdvertiseBuilder advertiseBuilder;

public Builder setManagementHost(String managementHost) {
this.managementHost = managementHost;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -144,8 +144,7 @@ public void handleRequest(HttpServerExchange exchange) throws Exception {
*/
// TODO maybe this should be handled outside here?
final InetSocketAddress addr = exchange.getDestinationAddress();
//we use getHostString to avoid a reverse lookup
if (addr.getPort() != config.getManagementPort() || (!addr.getHostString().equals(config.getManagementHost()) && !addr.getHostString().equals(config.getManagementHostIp()))) {
if (addr.getPort() != config.getManagementSocketAddress().getPort() || !Arrays.equals(addr.getAddress().getAddress(), config.getManagementSocketAddress().getAddress().getAddress())) {
next.handleRequest(exchange);
return;
}
Expand Down