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

Treat multicast address like loopback address wrt computation of default PublishedEndpoints #3175

Merged
merged 1 commit into from
Nov 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions cpp/src/Ice/EndpointI.h
Original file line number Diff line number Diff line change
Expand Up @@ -116,8 +116,8 @@ namespace IceInternal
// Used only for server endpoints.
virtual std::vector<EndpointIPtr> expandHost() const = 0;

// Returns true when the most underlying endpoint is an IP endpoint with a loopback address.
virtual bool isLoopback() const = 0;
// Returns true when the most underlying endpoint is an IP endpoint with a loopback or multicast address.
virtual bool isLoopbackOrMulticast() const = 0;

// Returns a new endpoint with the specified host; returns this when this operation is not applicable.
virtual std::shared_ptr<EndpointI> withPublishedHost(std::string host) const = 0;
Expand Down
4 changes: 2 additions & 2 deletions cpp/src/Ice/IPEndpointI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -137,9 +137,9 @@ IceInternal::IPEndpointI::expandHost() const
}

bool
IceInternal::IPEndpointI::isLoopback() const
IceInternal::IPEndpointI::isLoopbackOrMulticast() const
{
return _host.empty() ? false : isLoopbackAddress(_host);
return _host.empty() ? false : isLoopbackOrMulticastAddress(_host);
}

shared_ptr<EndpointI>
Expand Down
2 changes: 1 addition & 1 deletion cpp/src/Ice/IPEndpointI.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ namespace IceInternal
std::function<void(std::vector<ConnectorPtr>)>,
std::function<void(std::exception_ptr)>) const override;
std::vector<EndpointIPtr> expandHost() const override;
bool isLoopback() const override;
bool isLoopbackOrMulticast() const override;
std::shared_ptr<EndpointI> withPublishedHost(std::string host) const override;
bool equivalent(const EndpointIPtr&) const override;
std::size_t hash() const noexcept override;
Expand Down
6 changes: 3 additions & 3 deletions cpp/src/Ice/Network.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2145,7 +2145,7 @@ IceInternal::isIpAddress(const string& name)
}

bool
IceInternal::isLoopbackAddress(const string& name)
IceInternal::isLoopbackOrMulticastAddress(const string& name)
{
if (name.empty())
{
Expand All @@ -2158,12 +2158,12 @@ IceInternal::isLoopbackAddress(const string& name)
if (inet_pton(AF_INET, name.c_str(), &addr) > 0)
{
// It's an IPv4 address
return addr.s_addr == htonl(INADDR_LOOPBACK);
return addr.s_addr == htonl(INADDR_LOOPBACK) || IN_MULTICAST(ntohl(addr.s_addr));
}
else if (inet_pton(AF_INET6, name.c_str(), &addr6) > 0)
{
// It's an IPv6 address
return IN6_IS_ADDR_LOOPBACK(&addr6);
return IN6_IS_ADDR_LOOPBACK(&addr6) || IN6_IS_ADDR_MULTICAST(&addr6);
}
return false;
}
Expand Down
2 changes: 1 addition & 1 deletion cpp/src/Ice/Network.h
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,7 @@ namespace IceInternal
#endif

ICE_API bool isIpAddress(const std::string&);
ICE_API bool isLoopbackAddress(const std::string&);
ICE_API bool isLoopbackOrMulticastAddress(const std::string&);

ICE_API std::string getHostName();
}
Expand Down
12 changes: 6 additions & 6 deletions cpp/src/Ice/ObjectAdapterI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1190,13 +1190,13 @@ ObjectAdapterI::computePublishedEndpoints()
endpoints.push_back(factory->endpoint());
}

// Remove all loopback endpoints
// Remove all loopback/multicast endpoints
vector<EndpointIPtr> endpointsNoLoopback;
copy_if(
endpoints.begin(),
endpoints.end(),
back_inserter(endpointsNoLoopback),
[](const EndpointIPtr& endpoint) { return !endpoint->isLoopback(); });
[](const EndpointIPtr& endpoint) { return !endpoint->isLoopbackOrMulticast(); });

// Retrieve published host
string publishedHost = _communicator->getProperties()->getProperty(_name + ".PublishedHost");
Expand All @@ -1205,14 +1205,14 @@ ObjectAdapterI::computePublishedEndpoints()
{
endpoints = std::move(endpointsNoLoopback);

// For non-loopback endpoints, we use the fully qualified name of the local host as default for
// publishedHost.
// For non-loopback/multicast endpoints, we use the fully qualified name of the local host as default
// for publishedHost.
if (publishedHost.empty())
{
publishedHost = getHostName(); // fully qualified name of local host
}
}
// else keep endpoints as-is; they are all loopback.
// else keep endpoints as-is; they are all loopback or multicast

if (!publishedHost.empty())
{
Expand All @@ -1232,7 +1232,7 @@ ObjectAdapterI::computePublishedEndpoints()
}
endpoints = std::move(newEndpoints);
}
// else keep the loopback-only endpoints as-is (with IP addresses)
// else keep the loopback/multicast endpoints as-is (with IP addresses)
}
}

Expand Down
2 changes: 1 addition & 1 deletion cpp/src/Ice/OpaqueEndpointI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ IceInternal::OpaqueEndpointI::expandHost() const
}

bool
IceInternal::OpaqueEndpointI::isLoopback() const
IceInternal::OpaqueEndpointI::isLoopbackOrMulticast() const
{
return false;
}
Expand Down
2 changes: 1 addition & 1 deletion cpp/src/Ice/OpaqueEndpointI.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ namespace IceInternal
AcceptorPtr
acceptor(const std::string&, const std::optional<Ice::SSL::ServerAuthenticationOptions>&) const final;
std::vector<EndpointIPtr> expandHost() const final;
bool isLoopback() const final;
bool isLoopbackOrMulticast() const final;
std::shared_ptr<EndpointI> withPublishedHost(std::string host) const final;
bool equivalent(const EndpointIPtr&) const final;
std::size_t hash() const noexcept final;
Expand Down
4 changes: 2 additions & 2 deletions cpp/src/Ice/SSL/SSLEndpointI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -254,9 +254,9 @@ Ice::SSL::EndpointI::expandHost() const
}

bool
Ice::SSL::EndpointI::isLoopback() const
Ice::SSL::EndpointI::isLoopbackOrMulticast() const
{
return _delegate->isLoopback();
return _delegate->isLoopbackOrMulticast();
}

shared_ptr<IceInternal::EndpointI>
Expand Down
2 changes: 1 addition & 1 deletion cpp/src/Ice/SSL/SSLEndpointI.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ namespace Ice::SSL
IceInternal::AcceptorPtr
acceptor(const std::string&, const std::optional<Ice::SSL::ServerAuthenticationOptions>&) const final;
std::vector<IceInternal::EndpointIPtr> expandHost() const final;
bool isLoopback() const final;
bool isLoopbackOrMulticast() const final;
std::shared_ptr<IceInternal::EndpointI> withPublishedHost(std::string host) const final;
bool equivalent(const IceInternal::EndpointIPtr&) const final;
std::size_t hash() const noexcept final;
Expand Down
4 changes: 2 additions & 2 deletions cpp/src/Ice/WSEndpoint.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -275,9 +275,9 @@ IceInternal::WSEndpoint::expandHost() const
}

bool
IceInternal::WSEndpoint::isLoopback() const
IceInternal::WSEndpoint::isLoopbackOrMulticast() const
{
return _delegate->isLoopback();
return _delegate->isLoopbackOrMulticast();
}

shared_ptr<EndpointI>
Expand Down
2 changes: 1 addition & 1 deletion cpp/src/Ice/WSEndpoint.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ namespace IceInternal
AcceptorPtr
acceptor(const std::string&, const std::optional<Ice::SSL::ServerAuthenticationOptions>&) const final;
std::vector<EndpointIPtr> expandHost() const final;
bool isLoopback() const final;
bool isLoopbackOrMulticast() const final;
std::shared_ptr<EndpointI> withPublishedHost(std::string host) const final;
bool equivalent(const EndpointIPtr&) const final;
std::size_t hash() const noexcept final;
Expand Down
2 changes: 1 addition & 1 deletion cpp/src/Ice/ios/iAPEndpointI.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ namespace IceObjC
IceInternal::AcceptorPtr
acceptor(const std::string&, const std::optional<Ice::SSL::ServerAuthenticationOptions>&) const final;
std::vector<IceInternal::EndpointIPtr> expandHost() const final;
bool isLoopback() const final;
bool isLoopbackOrMulticast() const final;
std::shared_ptr<EndpointI> withPublishedHost(std::string host) const final;
bool equivalent(const IceInternal::EndpointIPtr&) const final;

Expand Down
2 changes: 1 addition & 1 deletion cpp/src/Ice/ios/iAPEndpointI.mm
Original file line number Diff line number Diff line change
Expand Up @@ -309,7 +309,7 @@ ICEIAP_API void registerIceIAP(bool loadOnInitialize)
}

bool
IceObjC::iAPEndpointI::isLoopback() const
IceObjC::iAPEndpointI::isLoopbackOrMulticast() const
{
return false;
}
Expand Down
2 changes: 1 addition & 1 deletion cpp/src/IceBT/EndpointI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ IceBT::EndpointI::expandHost() const
}

bool
IceBT::EndpointI::isLoopback() const
IceBT::EndpointI::isLoopbackOrMulticast() const
{
return false;
}
Expand Down
2 changes: 1 addition & 1 deletion cpp/src/IceBT/EndpointI.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ namespace IceBT
IceInternal::AcceptorPtr
acceptor(const std::string&, const std::optional<Ice::SSL::ServerAuthenticationOptions>&) const final;
std::vector<IceInternal::EndpointIPtr> expandHost() const final;
bool isLoopback() const final;
bool isLoopbackOrMulticast() const final;
std::shared_ptr<IceInternal::EndpointI> withPublishedHost(std::string host) const final;
bool equivalent(const IceInternal::EndpointIPtr&) const final;

Expand Down
4 changes: 2 additions & 2 deletions cpp/test/Ice/background/EndpointI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -200,9 +200,9 @@ EndpointI::expandHost() const
}

bool
EndpointI::isLoopback() const
EndpointI::isLoopbackOrMulticast() const
{
return _endpoint->isLoopback();
return _endpoint->isLoopbackOrMulticast();
}

shared_ptr<IceInternal::EndpointI>
Expand Down
2 changes: 1 addition & 1 deletion cpp/test/Ice/background/EndpointI.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ class EndpointI final : public IceInternal::EndpointI, public std::enable_shared
IceInternal::AcceptorPtr
acceptor(const std::string&, const std::optional<Ice::SSL::ServerAuthenticationOptions>&) const final;
std::vector<IceInternal::EndpointIPtr> expandHost() const final;
bool isLoopback() const final;
bool isLoopbackOrMulticast() const final;
std::shared_ptr<IceInternal::EndpointI> withPublishedHost(std::string host) const final;
bool equivalent(const IceInternal::EndpointIPtr&) const final;

Expand Down
4 changes: 2 additions & 2 deletions csharp/src/Ice/Internal/EndpointI.cs
Original file line number Diff line number Diff line change
Expand Up @@ -133,8 +133,8 @@ 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 true when the most underlying endpoint is an IP endpoint with a loopback or multicast address.
public abstract bool isLoopbackOrMulticast();

// Returns a new endpoint with the specified host; returns this when this operation is not applicable.
public abstract EndpointI withPublishedHost(string host);
Expand Down
14 changes: 12 additions & 2 deletions csharp/src/Ice/Internal/IPEndpointI.cs
Original file line number Diff line number Diff line change
Expand Up @@ -128,8 +128,18 @@ public override List<EndpointI> expandHost()

// 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 bool isLoopbackOrMulticast()
{
if (host_.Length > 0)
{
var ipEndPoint = IPEndPoint.Parse(host_);
return IPAddress.IsLoopback(ipEndPoint.Address) || Network.isMulticast(ipEndPoint);
}
else
{
return false;
}
}

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

Expand Down
2 changes: 1 addition & 1 deletion csharp/src/Ice/Internal/OpaqueEndpointI.cs
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ public override Acceptor acceptor(string adapterName, SslServerAuthenticationOpt

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

public override bool isLoopback() => false;
public override bool isLoopbackOrMulticast() => false;

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

Expand Down
2 changes: 1 addition & 1 deletion csharp/src/Ice/Internal/WSEndpoint.cs
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ public WSEndpoint endpoint(EndpointI delEndp)
public override List<EndpointI> expandHost() =>
_delegate.expandHost().Select(e => endpoint(e) as EndpointI).ToList();

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

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

Expand Down
10 changes: 5 additions & 5 deletions csharp/src/Ice/ObjectAdapter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1326,8 +1326,8 @@ private EndpointI[] computePublishedEndpoints()
// endpoints.
endpoints = _incomingConnectionFactories.Select(f => f.endpoint());

// Remove all loopback endpoints.
IEnumerable<EndpointI> endpointsNoLoopback = endpoints.Where(e => !e.isLoopback());
// Remove all loopback/multicast endpoints.
IEnumerable<EndpointI> endpointsNoLoopback = endpoints.Where(e => !e.isLoopbackOrMulticast());

// Retrieve published host
string publishedHost = _instance.initializationData().properties!.getProperty($"{_name}.PublishedHost");
Expand All @@ -1336,8 +1336,8 @@ private EndpointI[] computePublishedEndpoints()
{
endpoints = endpointsNoLoopback;

// For non-loopback endpoints, we use the fully qualified name of the local host as default for
// publishedHost.
// For non-loopback & non-multicast 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
Expand All @@ -1349,7 +1349,7 @@ private EndpointI[] computePublishedEndpoints()
// Replace the host in all endpoints by publishedHost (when applicable).
endpoints = endpoints.Select(e => e.withPublishedHost(publishedHost)).Distinct();
}
// else keep the loopback-only endpoints as-is (with IP addresses)
// else keep the loopback-only/multicast endpoints as-is (with IP addresses)
}
}

Expand Down
2 changes: 1 addition & 1 deletion csharp/src/Ice/SSL/EndpointI.cs
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ public EndpointI endpoint(Ice.Internal.EndpointI del)
public override List<Internal.EndpointI> expandHost() =>
_delegate.expandHost().Select(e => endpoint(e) as Internal.EndpointI).ToList();

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

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

Expand Down
2 changes: 1 addition & 1 deletion csharp/test/Ice/background/EndpointI.cs
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ 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 bool isLoopbackOrMulticast() => _endpoint.isLoopbackOrMulticast();

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,8 +116,9 @@ public abstract Acceptor acceptor(
// Used only for server endpoints.
public abstract java.util.List<EndpointI> expandHost();

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

// Returns a new endpoint with the specified host; returns this when this operation is not
// applicable.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,11 +115,16 @@ public java.util.List<EndpointI> expandHost() {
}

@Override
public boolean isLoopback() {
try {
return !_host.isEmpty() && java.net.InetAddress.getByName(_host).isLoopbackAddress();
} catch (java.net.UnknownHostException ex) {
public boolean isLoopbackOrMulticast() {
if (_host.isEmpty()) {
return false;
} else {
try {
var address = java.net.InetAddress.getByName(_host);
return address.isLoopbackAddress() || address.isMulticastAddress();
} catch (java.net.UnknownHostException ex) {
return false;
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1398,9 +1398,9 @@ private EndpointI[] computePublishedEndpoints() {
.map(IncomingConnectionFactory::endpoint)
.toList();

// Remove all loopback endpoints.
// Remove all loopback/multicast endpoints.
var endpointsNoLoopback =
endpointsList.stream().filter(e -> !e.isLoopback()).toList();
endpointsList.stream().filter(e -> !e.isLoopbackOrMulticast()).toList();

// Retrieve published host.
String publishedHost =
Expand All @@ -1416,8 +1416,8 @@ private EndpointI[] computePublishedEndpoints() {
} else {
endpoints = endpointsNoLoopback.stream();

// For non-loopback endpoints, we use the fully qualified name of the local host
// as default for publishedHost.
// For non-loopback/multicast endpoints, we use the fully qualified name of the
// local host as default for publishedHost.
if (publishedHost.isEmpty()) {
try {
publishedHost = InetAddress.getLocalHost().getHostName();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ public java.util.List<EndpointI> expandHost() {
}

@Override
public boolean isLoopback() {
public boolean isLoopbackOrMulticast() {
return false;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -169,8 +169,8 @@ public java.util.List<com.zeroc.Ice.EndpointI> expandHost() {
}

@Override
public boolean isLoopback() {
return _delegate.isLoopback();
public boolean isLoopbackOrMulticast() {
return _delegate.isLoopbackOrMulticast();
}

@Override
Expand Down
Loading