Skip to content

Commit

Permalink
Bug fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
bernardnormier committed Sep 28, 2024
1 parent 64a410d commit 5c0cad5
Show file tree
Hide file tree
Showing 8 changed files with 49 additions and 16 deletions.
6 changes: 6 additions & 0 deletions csharp/src/Ice/Internal/EndpointI.cs
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,12 @@ public virtual void streamWrite(Ice.OutputStream s)
// Used only for server endpoints.
public abstract List<EndpointI> expandHost();

// Returns true when the most underlying endpoint is an IP endpoint with a loopback address.
public abstract bool isLoopback();

// Returns a new endpoint with the specified host; returns this when this operation is not applicable.
public abstract EndpointI withPublishedHost(string host);

//
// Check whether the endpoint is equivalent to another one.
//
Expand Down
13 changes: 7 additions & 6 deletions csharp/src/Ice/Internal/IPEndpointI.cs
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,13 @@ public override List<EndpointI> expandHost()
connectionId_) as EndpointI).ToList();
}

// Empty host_ means the endpoint is a wildcard address. This method must be called only on an endpoint with an
// empty host or an IP address.
public override bool isLoopback() =>
host_.Length > 0 && IPAddress.IsLoopback(IPAddress.Parse(host_));

public override EndpointI withPublishedHost(string host) => createEndpoint(host, port_, connectionId_);

public override bool equivalent(EndpointI endpoint)
{
if (!(endpoint is IPEndpointI))
Expand Down Expand Up @@ -356,12 +363,6 @@ protected override bool checkOption(string option, string argument, string endpo

protected abstract IPEndpointI createEndpoint(string host, int port, string connectionId);

internal IPEndpointI withHost(string host) => createEndpoint(host, port_, connectionId_);

// Empty host_ means the endpoint is a wildcard address.
internal bool isLoopback() =>
host_.Length > 0 && IPAddress.IsLoopback(IPAddress.Parse(host_));

protected ProtocolInstance instance_;
protected string host_;
protected int port_;
Expand Down
4 changes: 4 additions & 0 deletions csharp/src/Ice/Internal/OpaqueEndpointI.cs
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,10 @@ public override Acceptor acceptor(string adapterName, SslServerAuthenticationOpt

public override List<EndpointI> expandHost() => [this];

public override bool isLoopback() => false;

public override EndpointI withPublishedHost(string host) => this;

//
// Check whether the endpoint is equivalent to another one.
//
Expand Down
4 changes: 4 additions & 0 deletions csharp/src/Ice/Internal/WSEndpoint.cs
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,10 @@ public WSEndpoint endpoint(EndpointI delEndp)
public override List<EndpointI> expandHost() =>
_delegate.expandHost().Select(e => new WSEndpoint(_instance, e, _resource) as EndpointI).ToList();

public override bool isLoopback() => _delegate.isLoopback();

public override EndpointI withPublishedHost(string host) => endpoint(_delegate.withPublishedHost(host));

public override bool equivalent(EndpointI endpoint)
{
if (!(endpoint is WSEndpoint))
Expand Down
23 changes: 13 additions & 10 deletions csharp/src/Ice/ObjectAdapter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1406,27 +1406,29 @@ private EndpointI[] computePublishedEndpoints()
endpoints = _incomingConnectionFactories.Select(f => f.endpoint());

// Remove all loopback endpoints.
IEnumerable<EndpointI> endpointsNoLoopback =
endpoints.Where(e => e is IPEndpointI ipEndpoint && !ipEndpoint.isLoopback());
IEnumerable<EndpointI> endpointsNoLoopback = endpoints.Where(e => !e.isLoopback());

// Retrieve published host
string publishedHost = _instance.initializationData().properties!.getProperty($"{_name}.PublishedHost");

if (endpointsNoLoopback.Any())
{
endpoints = endpointsNoLoopback;

// Retrieve published host
string publishedHost =
_instance.initializationData().properties!.getProperty($"{_name}.PublishedHost");
// For non-loopback endpoints, we use the fully qualified name of the local host as default for
// publishedHost.
if (publishedHost.Length == 0)
{
publishedHost = Dns.GetHostEntry("").HostName; // fully qualified name of local host
}
}

// Replace the host in IP endpoints by publishedHost.
endpoints = endpoints
.Select(e => e is IPEndpointI ipEndpoint ? ipEndpoint.withHost(publishedHost) : e)
.Distinct();
if (publishedHost.Length > 0)
{
// Replace the host in all endpoints by publishedHost (when applicable).
endpoints = endpoints.Select(e => e.withPublishedHost(publishedHost)).Distinct();
}
// else all the published endpoints are IP loopback endpoints: we just keep them as-is
// else keep the loopback-only endpoints as-is (with IP addresses)
}
}

Expand Down Expand Up @@ -1587,6 +1589,7 @@ private Object createDispatchPipeline()
"MaxConnections",
"MessageSizeMax",
"PublishedEndpoints",
"PublishedHost",
"ReplicaGroupId",
"Router",
"Router.EncodingVersion",
Expand Down
4 changes: 4 additions & 0 deletions csharp/src/Ice/SSL/EndpointI.cs
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,10 @@ public EndpointI endpoint(Ice.Internal.EndpointI del)
public override List<Ice.Internal.EndpointI> expandHost() =>
_delegate.expandHost().Select(e => new EndpointI(_instance, e) as Internal.EndpointI).ToList();

public override bool isLoopback() => _delegate.isLoopback();

public override EndpointI withPublishedHost(string host) => endpoint(_delegate.withPublishedHost(host));

public override bool equivalent(Ice.Internal.EndpointI endpoint)
{
if (endpoint is not EndpointI)
Expand Down
4 changes: 4 additions & 0 deletions csharp/test/Ice/background/EndpointI.cs
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,10 @@ public EndpointI endpoint(Ice.Internal.EndpointI delEndp)
public override List<Ice.Internal.EndpointI> expandHost() =>
_endpoint.expandHost().Select(e => new EndpointI(e) as Ice.Internal.EndpointI).ToList();

public override bool isLoopback() => _endpoint.isLoopback();

public override EndpointI withPublishedHost(string host) => endpoint(_endpoint.withPublishedHost(host));

public override bool equivalent(Ice.Internal.EndpointI endpoint)
{
EndpointI testEndpoint = null;
Expand Down
7 changes: 7 additions & 0 deletions csharp/test/IceSSL/configuration/AllTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ private static Dictionary<string, string>
Dictionary<string, string> result = new Dictionary<string, string>();
result["IceSSL.DefaultDir"] = defaultProperties.getProperty("IceSSL.DefaultDir");
result["Ice.Default.Host"] = defaultProperties.getProperty("Ice.Default.Host");

if (defaultProperties.getProperty("Ice.IPv6").Length > 0)
{
result["Ice.IPv6"] = defaultProperties.getProperty("Ice.IPv6");
Expand Down Expand Up @@ -483,6 +484,7 @@ public static Test.ServerFactoryPrx allTests(Test.TestHelper helper, string test
test(fact != null);
d = createServerProps(props, "s_rsa_ca1_cn1", "cacert1");
d["IceSSL.CheckCertName"] = "1";
d["ServerAdapter.PublishedHost"] = "localhost";
server = fact.createServer(d);
try
{
Expand Down Expand Up @@ -512,6 +514,7 @@ public static Test.ServerFactoryPrx allTests(Test.TestHelper helper, string test
test(fact != null);
d = createServerProps(props, "s_rsa_ca1_cn2", "cacert1");
d["IceSSL.CheckCertName"] = "1";
d["ServerAdapter.PublishedHost"] = "localhost";
server = fact.createServer(d);
try
{
Expand All @@ -538,6 +541,7 @@ public static Test.ServerFactoryPrx allTests(Test.TestHelper helper, string test
test(fact != null);
d = createServerProps(props, "s_rsa_ca1_cn3", "cacert1");
d["IceSSL.CheckCertName"] = "1";
d["ServerAdapter.PublishedHost"] = "localhost";
server = fact.createServer(d);
try
{
Expand All @@ -564,6 +568,7 @@ public static Test.ServerFactoryPrx allTests(Test.TestHelper helper, string test
test(fact != null);
d = createServerProps(props, "s_rsa_ca1_cn4", "cacert1");
d["IceSSL.CheckCertName"] = "1";
d["ServerAdapter.PublishedHost"] = "localhost";
server = fact.createServer(d);
try
{
Expand All @@ -590,6 +595,7 @@ public static Test.ServerFactoryPrx allTests(Test.TestHelper helper, string test
test(fact != null);
d = createServerProps(props, "s_rsa_ca1_cn5", "cacert1");
d["IceSSL.CheckCertName"] = "1";
d["ServerAdapter.PublishedHost"] = "localhost";
server = fact.createServer(d);
try
{
Expand Down Expand Up @@ -644,6 +650,7 @@ public static Test.ServerFactoryPrx allTests(Test.TestHelper helper, string test
test(fact != null);
d = createServerProps(defaultProperties, "s_rsa_ca1_cn7", "cacert1");
d["IceSSL.CheckCertName"] = "1";
d["ServerAdapter.PublishedHost"] = "localhost";
server = fact.createServer(d);
try
{
Expand Down

0 comments on commit 5c0cad5

Please sign in to comment.